mirror of
https://github.com/zsviczian/obsidian-excalidraw-plugin.git
synced 2025-08-06 05:46:28 +00:00
36 lines
1.3 KiB
Markdown
36 lines
1.3 KiB
Markdown
/*
|
|
|
|

|
|
|
|
Download this file and save to your Obsidian Vault including the first line, or open it in "Raw" and copy the entire contents to Obsidian.
|
|
|
|

|
|
|
|
This script will add an encapsulating box around the currently selected elements in Excalidraw.
|
|
|
|
See documentation for more details:
|
|
https://zsviczian.github.io/obsidian-excalidraw-plugin/ExcalidrawScriptsEngine.html
|
|
|
|
```javascript
|
|
*/
|
|
//uncomment if you want a prompt for custom padding
|
|
//const padding = parseInt (await utils.inputPrompt("padding?","number","10"));
|
|
const padding = 10
|
|
elements = ea.getViewSelectedElements();
|
|
const box = ea.getBoundingBox(elements);
|
|
color = ea
|
|
.getExcalidrawAPI()
|
|
.getAppState()
|
|
.currentItemStrokeColor;
|
|
//uncomment for random color:
|
|
//color = '#'+(Math.random()*0xFFFFFF<<0).toString(16).padStart(6,"0");
|
|
ea.style.strokeColor = color;
|
|
id = ea.addRect(
|
|
box.topX - padding,
|
|
box.topY - padding,
|
|
box.width + 2*padding,
|
|
box.height + 2*padding
|
|
);
|
|
ea.copyViewElementsToEAforEditing(elements);
|
|
ea.addToGroup([id].concat(elements.map((el)=>el.id)));
|
|
ea.addElementsToView(false); |