mirror of
https://github.com/zsviczian/obsidian-excalidraw-plugin.git
synced 2025-08-06 05:46:28 +00:00
2.4.0-beta-10
This commit is contained in:
@@ -5,7 +5,7 @@ import { ExcalidrawAutomate } from "src/ExcalidrawAutomate";
|
||||
import { REGEX_LINK, REG_LINKINDEX_HYPERLINK, getExcalidrawMarkdownHeaderSection, REGEX_TAGS } from "src/ExcalidrawData";
|
||||
import ExcalidrawView from "src/ExcalidrawView";
|
||||
import { ExcalidrawElement, ExcalidrawFrameElement } from "@zsviczian/excalidraw/types/excalidraw/element/types";
|
||||
import { getLinkParts } from "./Utils";
|
||||
import { getEmbeddedFilenameParts, getLinkParts, isImagePartRef } from "./Utils";
|
||||
import { cleanSectionHeading } from "./ObsidianUtils";
|
||||
import { getEA } from "src";
|
||||
import { ExcalidrawImperativeAPI } from "@zsviczian/excalidraw/types/excalidraw/types";
|
||||
@@ -18,8 +18,9 @@ export async function insertImageToView(
|
||||
position: { x: number, y: number },
|
||||
file: TFile | string,
|
||||
scale?: boolean,
|
||||
shouldInsertToView: boolean = true,
|
||||
):Promise<string> {
|
||||
ea.clear();
|
||||
if(shouldInsertToView) {ea.clear();}
|
||||
ea.style.strokeColor = "transparent";
|
||||
ea.style.backgroundColor = "transparent";
|
||||
const api = ea.getExcalidrawAPI();
|
||||
@@ -30,7 +31,7 @@ export async function insertImageToView(
|
||||
file,
|
||||
scale,
|
||||
);
|
||||
await ea.addElementsToView(false, true, true);
|
||||
if(shouldInsertToView) {await ea.addElementsToView(false, true, true);}
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -39,12 +40,13 @@ export async function insertEmbeddableToView (
|
||||
position: { x: number, y: number },
|
||||
file?: TFile,
|
||||
link?: string,
|
||||
shouldInsertToView: boolean = true,
|
||||
):Promise<string> {
|
||||
ea.clear();
|
||||
if(shouldInsertToView) {ea.clear();}
|
||||
ea.style.strokeColor = "transparent";
|
||||
ea.style.backgroundColor = "transparent";
|
||||
if(file && (IMAGE_TYPES.contains(file.extension) || ea.isExcalidrawFile(file)) && !ANIMATED_IMAGE_TYPES.contains(file.extension)) {
|
||||
return await insertImageToView(ea, position, link??file);
|
||||
return await insertImageToView(ea, position, link??file, undefined, shouldInsertToView);
|
||||
} else {
|
||||
const id = ea.addEmbeddable(
|
||||
position.x,
|
||||
@@ -54,7 +56,7 @@ export async function insertEmbeddableToView (
|
||||
link,
|
||||
file,
|
||||
);
|
||||
await ea.addElementsToView(false, true, true);
|
||||
if(shouldInsertToView) {await ea.addElementsToView(false, true, true);}
|
||||
return id;
|
||||
}
|
||||
}
|
||||
@@ -369,6 +371,9 @@ export function isTextImageTransclusion (
|
||||
const link = match.value[1] ?? match.value[2];
|
||||
const file = view.app.metadataCache.getFirstLinkpathDest(link?.split("#")[0], view.file.path);
|
||||
if(view.file === file) {
|
||||
if(link?.split("#")[1] && !isImagePartRef(getEmbeddedFilenameParts(link))) {
|
||||
return false;
|
||||
}
|
||||
new Notice(t("RECURSIVE_INSERT_ERROR"));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import { cleanBlockRef, cleanSectionHeading, getFileCSSClasses } from "./Obsidia
|
||||
import { updateElementLinksToObsidianLinks } from "src/ExcalidrawAutomate";
|
||||
import { CropImage } from "./CropImage";
|
||||
import opentype from 'opentype.js';
|
||||
import { runCompressionWorker } from "src/workers/compression-worker";
|
||||
|
||||
declare const PLUGIN_VERSION:string;
|
||||
declare var LZString: any;
|
||||
@@ -528,9 +529,12 @@ export function getLinkParts (fname: string, file?: TFile): LinkParts {
|
||||
};
|
||||
};
|
||||
|
||||
export async function compressAsync (data: string): Promise<string> {
|
||||
return await runCompressionWorker(data, "compress");
|
||||
}
|
||||
|
||||
export function compress (data: string): string {
|
||||
const compressed = LZString.compressToBase64(data);
|
||||
|
||||
let result = '';
|
||||
const chunkSize = 256;
|
||||
for (let i = 0; i < compressed.length; i += chunkSize) {
|
||||
@@ -540,7 +544,11 @@ export function compress (data: string): string {
|
||||
return result.trim();
|
||||
};
|
||||
|
||||
export function decompress (data: string): string {
|
||||
export async function decompressAsync (data: string): Promise<string> {
|
||||
return await runCompressionWorker(data, "decompress");
|
||||
};
|
||||
|
||||
export function decompress (data: string, isAsync:boolean = false): string {
|
||||
let cleanedData = '';
|
||||
const length = data.length;
|
||||
|
||||
@@ -765,6 +773,10 @@ export function getEmbeddedFilenameParts (fname:string): FILENAMEPARTS {
|
||||
}
|
||||
}
|
||||
|
||||
export function isImagePartRef (parts: FILENAMEPARTS): boolean {
|
||||
return (parts.hasGroupref || parts.hasArearef || parts.hasFrameref || parts.hasClippedFrameref);
|
||||
}
|
||||
|
||||
export function fragWithHTML (html: string) {
|
||||
return createFragment((frag) => (frag.createDiv().innerHTML = html));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user