diff --git a/ea-scripts/Deconstruct selected elements into new drawing.md b/ea-scripts/Deconstruct selected elements into new drawing.md index 337ce20c..633f8b12 100644 --- a/ea-scripts/Deconstruct selected elements into new drawing.md +++ b/ea-scripts/Deconstruct selected elements into new drawing.md @@ -3,13 +3,60 @@ Select some elements in the scene. The script will take these elements and move them into a new Excalidraw file, and open that file. The selected elements will also be replaced in your original drawing with the embedded Excalidraw file (the one that was just created). You will be prompted for the file name of the new deconstructed image. The script is useful if you want to break a larger drawing into smaller reusable parts that you want to reference in multiple drawings. + + + + ```javascript */ -if(!ea.verifyMinimumPluginVersion || !ea.verifyMinimumPluginVersion("1.7.29")) { +if(!ea.verifyMinimumPluginVersion || !ea.verifyMinimumPluginVersion("1.9.19")) { new Notice("This script requires a newer version of Excalidraw. Please install the latest version."); return; } +// ------------------------------- +// Utility variables and functions +// ------------------------------- +const excalidrawTemplate = app.metadataCache.getFirstLinkpathDest(ea.plugin.settings.templateFilePath,""); +if(typeof window.ExcalidrawDeconstructElements === "undefined") { + window.ExcalidrawDeconstructElements = { + openDeconstructedImage: true, + templatePath: excalidrawTemplate?.path??"" + }; +} + +const splitFolderAndFilename = (filepath) => { + const lastIndex = filepath.lastIndexOf("/"); + return { + foldername: ea.obsidian.normalizePath(filepath.substring(0, lastIndex)), + filename: (lastIndex == -1 ? filepath : filepath.substring(lastIndex + 1)) + ".md" + }; +} + +let settings = ea.getScriptSettings(); +//set default values on first run +if(!settings["Templates"]) { + settings = { + "Templates" : { + value: "", + description: "Comma-separated list of template filepaths" + } + }; + await ea.setScriptSettings(settings); +} + +const templates = settings["Templates"] + .value + .split(",") + .map(p=>app.metadataCache.getFirstLinkpathDest(p.trim(),"")) + .concat(excalidrawTemplate) + .filter(f=>Boolean(f)) + .sort((a,b) => a.basename.localeCompare(b.basename)); + + +// ------------------------------------ +// Prepare elements to be deconstructed +// ------------------------------------ const els = ea.getViewSelectedElements(); if (els.length === 0) { new Notice("You must select elements first") @@ -20,53 +67,114 @@ const bb = ea.getBoundingBox(els); ea.copyViewElementsToEAforEditing(els); ea.getElements().filter(el=>el.type==="image").forEach(el=>{ - const img = ea.targetView.excalidrawData.getFile(el.fileId); - const path = (img?.linkParts?.original)??(img?.file?.path); - if(img && path) { - ea.imagesDict[el.fileId] = { - mimeType: img.mimeType, - id: el.fileId, - dataURL: img.img, - created: img.mtime, - file: path, - hasSVGwithBitmap: img.isSVGwithBitmap, - latex: null, - }; - return; + const img = ea.targetView.excalidrawData.getFile(el.fileId); + const path = (img?.linkParts?.original)??(img?.file?.path); + if(img && path) { + ea.imagesDict[el.fileId] = { + mimeType: img.mimeType, + id: el.fileId, + dataURL: img.img, + created: img.mtime, + file: path, + hasSVGwithBitmap: img.isSVGwithBitmap, + latex: null, + }; + return; } const equation = ea.targetView.excalidrawData.getEquation(el.fileId); eqImg = ea.targetView.getScene()?.files[el.fileId] if(equation && eqImg) { - ea.imagesDict[el.fileId] = { - mimeType: eqImg.mimeType, - id: el.fileId, - dataURL: eqImg.dataURL, - created: eqImg.created, - file: null, - hasSVGwithBitmap: null, - latex: equation.latex, - }; - return; + ea.imagesDict[el.fileId] = { + mimeType: eqImg.mimeType, + id: el.fileId, + dataURL: eqImg.dataURL, + created: eqImg.created, + file: null, + hasSVGwithBitmap: null, + latex: equation.latex, + }; + return; } }); -let folder = ea.targetView.file.path; -folder = folder.lastIndexOf("/")===-1?"":folder.substring(0,folder.lastIndexOf("/"))+"/"; -const fname = await utils.inputPrompt("Filename for new file","Filename",""); -const template = app.metadataCache.getFirstLinkpathDest(ea.plugin.settings.templateFilePath,""); + +// ------------ +// Input prompt +// ------------ +let shouldAnchor = false; +const actionButtons = [ + { + caption: "Insert @100%", + tooltip: "Anchor to 100% size", + action: () => { + shouldAnchor = true; + } + }, + { + caption: "Insert", + tooltip: "Insert without anchoring", + action: () => { + shouldAnchor = false; + } + }]; + +const customControls = (container) => { + new ea.obsidian.Setting(container) + .setName(`Select template`) + .addDropdown(dropdown => { + templates.forEach(file => dropdown.addOption(file.path, file.basename)); + if(templates.length === 0) dropdown.addOption(null, "none"); + dropdown + .setValue(window.ExcalidrawDeconstructElements.templatePath) + .onChange(value => { + window.ExcalidrawDeconstructElements.templatePath = value; + }) + }) + + new ea.obsidian.Setting(container) + .setName(`Open deconstructed image`) + .addToggle((toggle) => toggle + .setValue(window.ExcalidrawDeconstructElements.openDeconstructedImage) + .onChange(value => { + window.ExcalidrawDeconstructElements.openDeconstructedImage = value; + }) + ) +} + +const path = await utils.inputPrompt( + "Filename for new file", + "Filename", + await ea.getAttachmentFilepath("deconstructed"), + actionButtons, + 2, + false, + customControls +); + +if(!path) return; + +// ---------------------- +// Execute deconstruction +// ---------------------- +const {foldername, filename} = splitFolderAndFilename(path); const newPath = await ea.create ({ - filename: fname + ".md", - foldername: folder, - templatePath: template?.path, - onNewPane: true + filename, + foldername, + templatePath: window.ExcalidrawDeconstructElements.templatePath, + onNewPane: true, + silent: !window.ExcalidrawDeconstructElements.openDeconstructedImage }); setTimeout(async ()=>{ - const file = app.metadataCache.getFirstLinkpathDest(newPath,"") + const file = app.metadataCache.getFirstLinkpathDest(newPath,""); ea.deleteViewElements(els); ea.clear(); - await ea.addImage(bb.topX,bb.topY,file,false); + await ea.addImage(bb.topX,bb.topY,file,false, shouldAnchor); await ea.addElementsToView(false, true, true); ea.getExcalidrawAPI().history.clear(); //to avoid undo/redo messing up the decomposition },1000); + +if(!window.ExcalidrawDeconstructElements.openDeconstructedImage) { + new Notice("Deconstruction ready"); +} \ No newline at end of file diff --git a/ea-scripts/Set Grid.md b/ea-scripts/Set Grid.md index 4243ff89..337049a0 100644 --- a/ea-scripts/Set Grid.md +++ b/ea-scripts/Set Grid.md @@ -8,18 +8,44 @@ https://zsviczian.github.io/obsidian-excalidraw-plugin/ExcalidrawScriptsEngine.h ```javascript */ -if(!ea.verifyMinimumPluginVersion || !ea.verifyMinimumPluginVersion("1.8.11")) { +if(!ea.verifyMinimumPluginVersion || !ea.verifyMinimumPluginVersion("1.9.19")) { new Notice("This script requires a newer version of Excalidraw. Please install the latest version."); return; } const api = ea.getExcalidrawAPI(); let appState = api.getAppState(); -const grid = parseInt(await utils.inputPrompt("Grid size?",null,appState.previousGridSize?.toString()??"20")); +const gridColor = appState.gridColor; +let gridFrequency = gridColor?.MajorGridFrequency ?? 5; + +const customControls = (container) => { + new ea.obsidian.Setting(container) + .setName(`Major grid frequency`) + .addDropdown(dropdown => { + [2,3,4,5,6,7,8,9,10].forEach(grid=>dropdown.addOption(grid,grid)); + dropdown + .setValue(gridFrequency) + .onChange(value => { + gridFrequency = value; + }) + }) +} + +const grid = parseInt(await utils.inputPrompt( + "Grid size?", + null, + appState.previousGridSize?.toString()??"20", + null, + 1, + false, + customControls +)); if(isNaN(grid)) return; //this is to avoid passing an illegal value to Excalidraw + appState.gridSize = grid; appState.previousGridSize = grid; +if(gridColor) gridColor.MajorGridFrequency = parseInt(gridFrequency); api.updateScene({ - appState, + appState : {gridSize: grid, previousGridSize: grid, gridColor}, commitToHistory:false }); \ No newline at end of file diff --git a/ea-scripts/directory-info.json b/ea-scripts/directory-info.json index 478489cb..0591bab2 100644 --- a/ea-scripts/directory-info.json +++ b/ea-scripts/directory-info.json @@ -1 +1 @@ -[{"fname":"Mindmap connector.md","mtime":1658686599427},{"fname":"Mindmap connector.svg","mtime":1658686599427},{"fname":"Add Connector Point.md","mtime":1645305706000},{"fname":"Add Connector Point.svg","mtime":1645944722000},{"fname":"Add Link to Existing File and Open.md","mtime":1647807918345},{"fname":"Add Link to Existing File and Open.svg","mtime":1645964261000},{"fname":"Add Link to New Page and Open.md","mtime":1654168862138},{"fname":"Add Link to New Page and Open.svg","mtime":1645960639000},{"fname":"Add Next Step in Process.md","mtime":1688304760357},{"fname":"Add Next Step in Process.svg","mtime":1645960639000},{"fname":"Box Each Selected Groups.md","mtime":1645305706000},{"fname":"Box Each Selected Groups.svg","mtime":1645967510000},{"fname":"Box Selected Elements.md","mtime":1645305706000},{"fname":"Box Selected Elements.svg","mtime":1645960639000},{"fname":"Change shape of selected elements.md","mtime":1652701169236},{"fname":"Change shape of selected elements.svg","mtime":1645960775000},{"fname":"Connect elements.md","mtime":1645305706000},{"fname":"Connect elements.svg","mtime":1645960639000},{"fname":"Convert freedraw to line.md","mtime":1645305706000},{"fname":"Convert freedraw to line.svg","mtime":1645960639000},{"fname":"Convert selected text elements to sticky notes.md","mtime":1670169501383},{"fname":"Convert selected text elements to sticky notes.svg","mtime":1645960639000},{"fname":"Convert text to link with folder and alias.md","mtime":1641639819000},{"fname":"Convert text to link with folder and alias.svg","mtime":1645960639000},{"fname":"Copy Selected Element Styles to Global.md","mtime":1642232088000},{"fname":"Copy Selected Element Styles to Global.svg","mtime":1645960639000},{"fname":"Create new markdown file and embed into active drawing.md","mtime":1640866935000},{"fname":"Create new markdown file and embed into active drawing.svg","mtime":1645960639000},{"fname":"Darken background color.md","mtime":1663059051059},{"fname":"Darken background color.svg","mtime":1645960639000},{"fname":"Elbow connectors.md","mtime":1671126911490},{"fname":"Elbow connectors.svg","mtime":1645960639000},{"fname":"Expand rectangles horizontally keep text centered.md","mtime":1646563692000},{"fname":"Expand rectangles horizontally keep text centered.svg","mtime":1645967510000},{"fname":"Expand rectangles horizontally.md","mtime":1644950235000},{"fname":"Expand rectangles horizontally.svg","mtime":1645967510000},{"fname":"Expand rectangles vertically keep text centered.md","mtime":1646563692000},{"fname":"Expand rectangles vertically keep text centered.svg","mtime":1645967510000},{"fname":"Expand rectangles vertically.md","mtime":1658686599427},{"fname":"Expand rectangles vertically.svg","mtime":1645967510000},{"fname":"Fixed horizontal distance between centers.md","mtime":1646743234000},{"fname":"Fixed horizontal distance between centers.svg","mtime":1645960639000},{"fname":"Fixed inner distance.md","mtime":1646743234000},{"fname":"Fixed inner distance.svg","mtime":1645960639000},{"fname":"Fixed spacing.md","mtime":1646743234000},{"fname":"Fixed spacing.svg","mtime":1645967510000},{"fname":"Fixed vertical distance between centers.md","mtime":1646743234000},{"fname":"Fixed vertical distance between centers.svg","mtime":1645967510000},{"fname":"Fixed vertical distance.md","mtime":1646743234000},{"fname":"Fixed vertical distance.svg","mtime":1645967510000},{"fname":"Lighten background color.md","mtime":1663059051059},{"fname":"Lighten background color.svg","mtime":1645959546000},{"fname":"Modify background color opacity.md","mtime":1644924415000},{"fname":"Modify background color opacity.svg","mtime":1645944722000},{"fname":"Normalize Selected Arrows.md","mtime":1670403743278},{"fname":"Normalize Selected Arrows.svg","mtime":1645960639000},{"fname":"Organic Line.md","mtime":1672920172531},{"fname":"Organic Line.svg","mtime":1645964261000},{"fname":"Organic Line Legacy.md","mtime":1690607372668},{"fname":"Organic Line Legacy.svg","mtime":1690607372668},{"fname":"README.md","mtime":1645175700000},{"fname":"Repeat Elements.md","mtime":1663059051059},{"fname":"Repeat Elements.svg","mtime":1645960639000},{"fname":"Reverse arrows.md","mtime":1645305706000},{"fname":"Reverse arrows.svg","mtime":1645960639000},{"fname":"Scribble Helper.md","mtime":1682228345043},{"fname":"Scribble Helper.svg","mtime":1645944722000},{"fname":"Select Elements of Type.md","mtime":1643464321000},{"fname":"Select Elements of Type.svg","mtime":1645960639000},{"fname":"Set Dimensions.md","mtime":1645305706000},{"fname":"Set Dimensions.svg","mtime":1645944722000},{"fname":"Set Font Family.md","mtime":1645305706000},{"fname":"Set Font Family.svg","mtime":1645944722000},{"fname":"Set Grid.md","mtime":1674326971324},{"fname":"Set Grid.svg","mtime":1645960639000},{"fname":"Set Link Alias.md","mtime":1645305706000},{"fname":"Set Link Alias.svg","mtime":1645960639000},{"fname":"Set Stroke Width of Selected Elements.md","mtime":1645305706000},{"fname":"Set Stroke Width of Selected Elements.svg","mtime":1645960639000},{"fname":"Set Text Alignment.md","mtime":1645305706000},{"fname":"Set Text Alignment.svg","mtime":1645960639000},{"fname":"Set background color of unclosed line object by adding a shadow clone.md","mtime":1681665030892},{"fname":"Set background color of unclosed line object by adding a shadow clone.svg","mtime":1645960639000},{"fname":"Split text by lines.md","mtime":1645305706000},{"fname":"Split text by lines.svg","mtime":1645944722000},{"fname":"Zoom to Fit Selected Elements.md","mtime":1640770602000},{"fname":"Zoom to Fit Selected Elements.svg","mtime":1645960639000},{"fname":"directory-info.json","mtime":1646583437000},{"fname":"index-new.md","mtime":1645986149000},{"fname":"index.md","mtime":1645175700000},{"fname":"Grid Selected Images.md","mtime":1649614401982},{"fname":"Grid Selected Images.svg","mtime":1649614401982},{"fname":"Palette loader.md","mtime":1686511890942},{"fname":"Palette loader.svg","mtime":1649614401982},{"fname":"Rename Image.md","mtime":1663678478785},{"fname":"Rename Image.svg","mtime":1663678478785},{"fname":"Text Arch.md","mtime":1664095143846},{"fname":"Text Arch.svg","mtime":1670403743278},{"fname":"Deconstruct selected elements into new drawing.md","mtime":1672672112439},{"fname":"Deconstruct selected elements into new drawing.svg","mtime":1668541145255},{"fname":"Slideshow.md","mtime":1690490924618},{"fname":"Slideshow.svg","mtime":1670017348333},{"fname":"Auto Layout.md","mtime":1670403743278},{"fname":"Auto Layout.svg","mtime":1670175947081},{"fname":"Uniform size.md","mtime":1670175947081},{"fname":"Uniform size.svg","mtime":1670175947081},{"fname":"Mindmap format.md","mtime":1684484694228},{"fname":"Mindmap format.svg","mtime":1674944958059},{"fname":"Text to Sticky Notes.md","mtime":1678537561724},{"fname":"Text to Sticky Notes.svg","mtime":1678537561724},{"fname":"Folder Note Core - Make Current Drawing a Folder.md","mtime":1678973697470},{"fname":"Folder Note Core - Make Current Drawing a Folder.svg","mtime":1678973697470},{"fname":"Invert colors.md","mtime":1678973697470},{"fname":"Invert colors.svg","mtime":1678973697470},{"fname":"Auto Draw for Pen.md","mtime":1680418321236},{"fname":"Auto Draw for Pen.svg","mtime":1680418321236},{"fname":"Hardware Eraser Support.md","mtime":1680418321236},{"fname":"Hardware Eraser Support.svg","mtime":1680418321236},{"fname":"PDF Page Text to Clipboard.md","mtime":1683984041712},{"fname":"PDF Page Text to Clipboard.svg","mtime":1680418321236},{"fname":"Excalidraw Collaboration Frame.md","mtime":1687881495985},{"fname":"Excalidraw Collaboration Frame.svg","mtime":1687881495985},{"fname":"Create DrawIO file.md","mtime":1688243858267},{"fname":"Create DrawIO file.svg","mtime":1688243858267},{"fname":"Ellipse Selected Elements.md","mtime":1690131476331},{"fname":"Ellipse Selected Elements.svg","mtime":1690131476331},{"fname":"Select Similar Elements.md","mtime":1691270949338},{"fname":"Select Similar Elements.svg","mtime":1691270949338},{"fname":"Toggle Grid.md","mtime":1692125382945},{"fname":"Toggle Grid.svg","mtime":1692124753386},{"fname":"Split Ellipse.md","mtime":1693134104356},{"fname":"Split Ellipse.svg","mtime":1693134104356}] \ No newline at end of file +[{"fname":"Mindmap connector.md","mtime":1658686599427},{"fname":"Mindmap connector.svg","mtime":1658686599427},{"fname":"Add Connector Point.md","mtime":1645305706000},{"fname":"Add Connector Point.svg","mtime":1645944722000},{"fname":"Add Link to Existing File and Open.md","mtime":1647807918345},{"fname":"Add Link to Existing File and Open.svg","mtime":1645964261000},{"fname":"Add Link to New Page and Open.md","mtime":1654168862138},{"fname":"Add Link to New Page and Open.svg","mtime":1645960639000},{"fname":"Add Next Step in Process.md","mtime":1688304760357},{"fname":"Add Next Step in Process.svg","mtime":1645960639000},{"fname":"Box Each Selected Groups.md","mtime":1645305706000},{"fname":"Box Each Selected Groups.svg","mtime":1645967510000},{"fname":"Box Selected Elements.md","mtime":1645305706000},{"fname":"Box Selected Elements.svg","mtime":1645960639000},{"fname":"Change shape of selected elements.md","mtime":1652701169236},{"fname":"Change shape of selected elements.svg","mtime":1645960775000},{"fname":"Connect elements.md","mtime":1645305706000},{"fname":"Connect elements.svg","mtime":1645960639000},{"fname":"Convert freedraw to line.md","mtime":1645305706000},{"fname":"Convert freedraw to line.svg","mtime":1645960639000},{"fname":"Convert selected text elements to sticky notes.md","mtime":1670169501383},{"fname":"Convert selected text elements to sticky notes.svg","mtime":1645960639000},{"fname":"Convert text to link with folder and alias.md","mtime":1641639819000},{"fname":"Convert text to link with folder and alias.svg","mtime":1645960639000},{"fname":"Copy Selected Element Styles to Global.md","mtime":1642232088000},{"fname":"Copy Selected Element Styles to Global.svg","mtime":1645960639000},{"fname":"Create new markdown file and embed into active drawing.md","mtime":1640866935000},{"fname":"Create new markdown file and embed into active drawing.svg","mtime":1645960639000},{"fname":"Darken background color.md","mtime":1663059051059},{"fname":"Darken background color.svg","mtime":1645960639000},{"fname":"Elbow connectors.md","mtime":1671126911490},{"fname":"Elbow connectors.svg","mtime":1645960639000},{"fname":"Expand rectangles horizontally keep text centered.md","mtime":1646563692000},{"fname":"Expand rectangles horizontally keep text centered.svg","mtime":1645967510000},{"fname":"Expand rectangles horizontally.md","mtime":1644950235000},{"fname":"Expand rectangles horizontally.svg","mtime":1645967510000},{"fname":"Expand rectangles vertically keep text centered.md","mtime":1646563692000},{"fname":"Expand rectangles vertically keep text centered.svg","mtime":1645967510000},{"fname":"Expand rectangles vertically.md","mtime":1658686599427},{"fname":"Expand rectangles vertically.svg","mtime":1645967510000},{"fname":"Fixed horizontal distance between centers.md","mtime":1646743234000},{"fname":"Fixed horizontal distance between centers.svg","mtime":1645960639000},{"fname":"Fixed inner distance.md","mtime":1646743234000},{"fname":"Fixed inner distance.svg","mtime":1645960639000},{"fname":"Fixed spacing.md","mtime":1646743234000},{"fname":"Fixed spacing.svg","mtime":1645967510000},{"fname":"Fixed vertical distance between centers.md","mtime":1646743234000},{"fname":"Fixed vertical distance between centers.svg","mtime":1645967510000},{"fname":"Fixed vertical distance.md","mtime":1646743234000},{"fname":"Fixed vertical distance.svg","mtime":1645967510000},{"fname":"Lighten background color.md","mtime":1663059051059},{"fname":"Lighten background color.svg","mtime":1645959546000},{"fname":"Modify background color opacity.md","mtime":1644924415000},{"fname":"Modify background color opacity.svg","mtime":1645944722000},{"fname":"Normalize Selected Arrows.md","mtime":1670403743278},{"fname":"Normalize Selected Arrows.svg","mtime":1645960639000},{"fname":"Organic Line.md","mtime":1672920172531},{"fname":"Organic Line.svg","mtime":1645964261000},{"fname":"Organic Line Legacy.md","mtime":1690607372668},{"fname":"Organic Line Legacy.svg","mtime":1690607372668},{"fname":"README.md","mtime":1645175700000},{"fname":"Repeat Elements.md","mtime":1663059051059},{"fname":"Repeat Elements.svg","mtime":1645960639000},{"fname":"Reverse arrows.md","mtime":1645305706000},{"fname":"Reverse arrows.svg","mtime":1645960639000},{"fname":"Scribble Helper.md","mtime":1682228345043},{"fname":"Scribble Helper.svg","mtime":1645944722000},{"fname":"Select Elements of Type.md","mtime":1643464321000},{"fname":"Select Elements of Type.svg","mtime":1645960639000},{"fname":"Set Dimensions.md","mtime":1645305706000},{"fname":"Set Dimensions.svg","mtime":1645944722000},{"fname":"Set Font Family.md","mtime":1645305706000},{"fname":"Set Font Family.svg","mtime":1645944722000},{"fname":"Set Grid.md","mtime":1693725826368},{"fname":"Set Grid.svg","mtime":1645960639000},{"fname":"Set Link Alias.md","mtime":1645305706000},{"fname":"Set Link Alias.svg","mtime":1645960639000},{"fname":"Set Stroke Width of Selected Elements.md","mtime":1645305706000},{"fname":"Set Stroke Width of Selected Elements.svg","mtime":1645960639000},{"fname":"Set Text Alignment.md","mtime":1645305706000},{"fname":"Set Text Alignment.svg","mtime":1645960639000},{"fname":"Set background color of unclosed line object by adding a shadow clone.md","mtime":1681665030892},{"fname":"Set background color of unclosed line object by adding a shadow clone.svg","mtime":1645960639000},{"fname":"Split text by lines.md","mtime":1645305706000},{"fname":"Split text by lines.svg","mtime":1645944722000},{"fname":"Zoom to Fit Selected Elements.md","mtime":1640770602000},{"fname":"Zoom to Fit Selected Elements.svg","mtime":1645960639000},{"fname":"directory-info.json","mtime":1646583437000},{"fname":"index-new.md","mtime":1645986149000},{"fname":"index.md","mtime":1645175700000},{"fname":"Grid Selected Images.md","mtime":1649614401982},{"fname":"Grid Selected Images.svg","mtime":1649614401982},{"fname":"Palette loader.md","mtime":1686511890942},{"fname":"Palette loader.svg","mtime":1649614401982},{"fname":"Rename Image.md","mtime":1663678478785},{"fname":"Rename Image.svg","mtime":1663678478785},{"fname":"Text Arch.md","mtime":1664095143846},{"fname":"Text Arch.svg","mtime":1670403743278},{"fname":"Deconstruct selected elements into new drawing.md","mtime":1693733190088},{"fname":"Deconstruct selected elements into new drawing.svg","mtime":1668541145255},{"fname":"Slideshow.md","mtime":1690490924618},{"fname":"Slideshow.svg","mtime":1670017348333},{"fname":"Auto Layout.md","mtime":1670403743278},{"fname":"Auto Layout.svg","mtime":1670175947081},{"fname":"Uniform size.md","mtime":1670175947081},{"fname":"Uniform size.svg","mtime":1670175947081},{"fname":"Mindmap format.md","mtime":1684484694228},{"fname":"Mindmap format.svg","mtime":1674944958059},{"fname":"Text to Sticky Notes.md","mtime":1678537561724},{"fname":"Text to Sticky Notes.svg","mtime":1678537561724},{"fname":"Folder Note Core - Make Current Drawing a Folder.md","mtime":1678973697470},{"fname":"Folder Note Core - Make Current Drawing a Folder.svg","mtime":1678973697470},{"fname":"Invert colors.md","mtime":1678973697470},{"fname":"Invert colors.svg","mtime":1678973697470},{"fname":"Auto Draw for Pen.md","mtime":1680418321236},{"fname":"Auto Draw for Pen.svg","mtime":1680418321236},{"fname":"Hardware Eraser Support.md","mtime":1680418321236},{"fname":"Hardware Eraser Support.svg","mtime":1680418321236},{"fname":"PDF Page Text to Clipboard.md","mtime":1683984041712},{"fname":"PDF Page Text to Clipboard.svg","mtime":1680418321236},{"fname":"Excalidraw Collaboration Frame.md","mtime":1687881495985},{"fname":"Excalidraw Collaboration Frame.svg","mtime":1687881495985},{"fname":"Create DrawIO file.md","mtime":1688243858267},{"fname":"Create DrawIO file.svg","mtime":1688243858267},{"fname":"Ellipse Selected Elements.md","mtime":1690131476331},{"fname":"Ellipse Selected Elements.svg","mtime":1690131476331},{"fname":"Select Similar Elements.md","mtime":1691270949338},{"fname":"Select Similar Elements.svg","mtime":1691270949338},{"fname":"Toggle Grid.md","mtime":1692125382945},{"fname":"Toggle Grid.svg","mtime":1692124753386},{"fname":"Split Ellipse.md","mtime":1693134104356},{"fname":"Split Ellipse.svg","mtime":1693134104356},{"fname":"Text Aura.md","mtime":1693731979540},{"fname":"Text Aura.svg","mtime":1693731979540}] \ No newline at end of file diff --git a/ea-scripts/index-new.md b/ea-scripts/index-new.md index 1cdb7035..7decb5eb 100644 --- a/ea-scripts/index-new.md +++ b/ea-scripts/index-new.md @@ -71,6 +71,7 @@ I would love to include your contribution in the script library. If you have a s |
|[[#Set Text Alignment]]| |
|[[#Split text by lines]]| |
|[[#Text Arch]]| +|
|[[#Text Aura]]| |
|[[#Text to Sticky Notes]]| ## Styling and Appearance @@ -502,6 +503,12 @@ https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea ```
Author@zsviczian
SourceFile on GitHub
DescriptionFit a text to the arch of a circle. The script will prompt you for the radius of the circle and then split your text to individual letters and place each letter to the arch defined by the radius. Setting a lower radius value will increase the arching of the text. Note that the arched-text will no longer be editable as a text element and it will no longer function as a markdown link. Emojis are currently not supported.
+## Text Aura +```excalidraw-script-install +https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Text%20Aura.md +``` +
Author@zsviczian
SourceFile on GitHub
DescriptionSelect a single text element, or a text element in a container. The container must have a transparent background.
The script will add an aura to the text by adding 4 copies of the text each with the inverted stroke color of the original text element and with a very small X and Y offset. The resulting 4 + 1 (original) text elements or containers will be grouped.
If you copy a color string on the clipboard before running the script, the script will use that color instead of the inverted color.
+ ## Toggle Grid ```excalidraw-script-install https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Toggle%20Grid.md diff --git a/manifest.json b/manifest.json index 40be5000..a9fb31bf 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-excalidraw-plugin", "name": "Excalidraw", - "version": "1.9.18", + "version": "1.9.19", "minAppVersion": "1.1.6", "description": "An Obsidian plugin to edit and view Excalidraw drawings", "author": "Zsolt Viczian", diff --git a/package.json b/package.json index b26e52df..0295293b 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "author": "", "license": "MIT", "dependencies": { - "@zsviczian/excalidraw": "0.15.2-obsidian-13", + "@zsviczian/excalidraw": "0.15.3-obsidian-1", "chroma-js": "^2.4.2", "clsx": "^2.0.0", "colormaster": "^1.2.1", diff --git a/src/EmbeddedFileLoader.ts b/src/EmbeddedFileLoader.ts index 2e352465..69c2b148 100644 --- a/src/EmbeddedFileLoader.ts +++ b/src/EmbeddedFileLoader.ts @@ -102,9 +102,9 @@ const replaceSVGColors = (svg: SVGSVGElement | string, colorMap: ColorMap | null if(typeof svg === 'string') { // Replace colors in the SVG string for (const [oldColor, newColor] of Object.entries(colorMap)) { - const fillRegex = new RegExp(`fill="${oldColor}"`, 'g'); + const fillRegex = new RegExp(`fill="${oldColor}"`, 'gi'); svg = svg.replaceAll(fillRegex, `fill="${newColor}"`); - const strokeRegex = new RegExp(`stroke="${oldColor}"`, 'g'); + const strokeRegex = new RegExp(`stroke="${oldColor}"`, 'gi'); svg = svg.replaceAll(strokeRegex, `stroke="${newColor}"`); } return svg; @@ -113,8 +113,8 @@ const replaceSVGColors = (svg: SVGSVGElement | string, colorMap: ColorMap | null // Modify the fill and stroke attributes of child nodes const childNodes = (node: ChildNode) => { if (node instanceof SVGElement) { - const oldFill = node.getAttribute('fill'); - const oldStroke = node.getAttribute('stroke'); + const oldFill = node.getAttribute('fill').toLocaleLowerCase(); + const oldStroke = node.getAttribute('stroke').toLocaleLowerCase(); if (oldFill && colorMap[oldFill]) { node.setAttribute('fill', colorMap[oldFill]); @@ -158,7 +158,7 @@ export class EmbeddedFile { this.resetImage(hostPath, imgPath); if(this.file && (this.plugin.ea.isExcalidrawFile(this.file) || this.file.extension.toLowerCase() === "svg")) { try { - this.colorMap = colorMapJSON ? JSON.parse(colorMapJSON) : null; + this.colorMap = colorMapJSON ? JSON.parse(colorMapJSON.toLocaleLowerCase()) : null; } catch (error) { this.colorMap = null; } diff --git a/src/ExcalidrawView.ts b/src/ExcalidrawView.ts index fc921f2c..dff6eb16 100644 --- a/src/ExcalidrawView.ts +++ b/src/ExcalidrawView.ts @@ -1784,12 +1784,12 @@ export default class ExcalidrawView extends TextFileView { }); } - private getGridColor(bgColor: string):{Bold: string, Regular: string} { + private getGridColor(bgColor: string, st: AppState):{Bold: string, Regular: string, MajorGridFrequency: number} { const cm = this.plugin.ea.getCM(bgColor); const isDark = cm.isDark(); - const Regular = (isDark ? cm.lighterBy(5) : cm.darkerBy(5)).stringHEX(); - const Bold = (isDark ? cm.lighterBy(10) : cm.darkerBy(10)).stringHEX(); - return {Bold, Regular}; + const Regular = (isDark ? cm.lighterBy(7) : cm.darkerBy(7)).stringHEX(); + const Bold = (isDark ? cm.lighterBy(14) : cm.darkerBy(14)).stringHEX(); + return {Bold, Regular, MajorGridFrequency:st.gridColor.MajorGridFrequency}; } public activeLoader: EmbeddedFilesLoader = null; @@ -2790,6 +2790,7 @@ export default class ExcalidrawView extends TextFileView { zoom: st.zoom, currentItemRoundness: st.currentItemRoundness, gridSize: st.gridSize, + gridColor: st.gridColor, colorPalette: st.colorPalette, currentStrokeOptions: st.currentStrokeOptions, previousGridSize: st.previousGridSize, @@ -3185,7 +3186,7 @@ export default class ExcalidrawView extends TextFileView { onChange: (et: ExcalidrawElement[], st: AppState) => { const canvasColorChangeHook = () => { const canvasColor = st.viewBackgroundColor === "transparent" ? "white" : st.viewBackgroundColor; - setTimeout(()=>this.updateScene({appState:{gridColor: this.getGridColor(canvasColor)}})); + setTimeout(()=>this.updateScene({appState:{gridColor: this.getGridColor(canvasColor, st)}})); setDynamicStyle(this.plugin.ea,this,canvasColor,this.plugin.settings.dynamicStyling); if(this.plugin.ea.onCanvasColorChangeHook) { try { diff --git a/src/dialogs/Messages.ts b/src/dialogs/Messages.ts index 56b8af99..8ab13ef3 100644 --- a/src/dialogs/Messages.ts +++ b/src/dialogs/Messages.ts @@ -17,6 +17,41 @@ I develop this plugin as a hobby, spending my free time doing this. If you find
`, +"1.9.19":` +## New +- I added new features to the [Deconstruct Selected Elements](https://github.com/zsviczian/obsidian-excalidraw-plugin/blob/master/ea-scripts/Deconstruct%20selected%20elements%20into%20new%20drawing.md) script +- I added a new script: [Text Aura](https://github.com/zsviczian/obsidian-excalidraw-plugin/blob/master/ea-scripts/Text%20Aura.md) +- I updated the [Set Grid](https://github.com/zsviczian/obsidian-excalidraw-plugin/blob/master/ea-scripts/Set%20Grid.md) script. You can now set the Major/Minor tick frequency. [#1305](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/1305) +- The re-colorMap is now case-insensitive. The color map is a hidden feature. In Markdown View mode you can add a JSON map after the embedded SVG or Excalidraw image filename with a mapping of current colors to new colors. + + +## New in ExcalidrawAutomate +- I added the ${String.fromCharCode(96)}silent${String.fromCharCode(96)} switch. If this is true, the created file will not be opened. +${String.fromCharCode(96,96,96)}typescript + async create(params?: { + filename?: string; + foldername?: string; + templatePath?: string; + onNewPane?: boolean; + silent?: boolean; + frontmatterKeys?: { + "excalidraw-plugin"?: "raw" | "parsed"; + "excalidraw-link-prefix"?: string; + "excalidraw-link-brackets"?: boolean; + "excalidraw-url-prefix"?: string; + "excalidraw-export-transparent"?: boolean; + "excalidraw-export-dark"?: boolean; + "excalidraw-export-padding"?: number; + "excalidraw-export-pngscale"?: number; + "excalidraw-default-mode"?: "view" | "zen"; + "excalidraw-onload-script"?: string; + "excalidraw-linkbutton-opacity"?: number; + "excalidraw-autoexport"?: boolean; + }; + plaintext?: string; //text to insert above the ${String.fromCharCode(96)}# Text Elements${String.fromCharCode(96)} section + }): Promise +${String.fromCharCode(96,96,96)} +`, "1.9.18":` ## New - Excalidraw now syncs with Obsidian's language settings, provided translations are available. [#1297](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/1297) diff --git a/src/main.ts b/src/main.ts index e41e7a1e..ca9287e1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2263,7 +2263,7 @@ export default class ExcalidrawPlugin extends Plugin { this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData()); if(!this.settings.previewImageType) { //migration 1.9.13 if(typeof this.settings.displaySVGInPreview === "undefined") { - this.settings.previewImageType = PreviewImageType.SVG; + this.settings.previewImageType = PreviewImageType.SVGIMG; } else { this.settings.previewImageType = this.settings.displaySVGInPreview ? PreviewImageType.SVGIMG