mirror of
https://github.com/zsviczian/obsidian-excalidraw-plugin.git
synced 2025-08-06 05:46:28 +00:00
text aura
This commit is contained in:
70
ea-scripts/Text Aura.md
Normal file
70
ea-scripts/Text Aura.md
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||

|
||||
Select 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.
|
||||
|
||||
```js*/
|
||||
els = ea.getViewSelectedElements();
|
||||
const isText = (els.length === 1) && els[0].type === "text";
|
||||
const isContainer = (els.length === 2) &&
|
||||
((els[0].type === "text" && els[1].id === els[0].containerId && els[1].backgroundColor.toLowerCase() === "transparent") ||
|
||||
(els[1].type === "text" && els[0].id === els[1].containerId && els[0].backgroundColor.toLowerCase() === "transparent"));
|
||||
|
||||
if (!(isText || isContainer)) {
|
||||
new Notice ("Select a single text element, or a container with a text element and with transparent background color",10000);
|
||||
return;
|
||||
}
|
||||
|
||||
let strokeColor = ea
|
||||
.getCM(els.filter(el=>el.type === "text")[0].strokeColor)
|
||||
.invert({alpha: false})
|
||||
.stringHEX({alpha: false});
|
||||
clipboardText = await navigator.clipboard.readText();
|
||||
if(clipboardText) {
|
||||
const cm1 = ea.getCM(clipboardText);
|
||||
if(cm1.format !== "invalid") {
|
||||
strokeColor = cm1.stringHEX();
|
||||
} else {
|
||||
const cm2 = ea.getCM("#"+clipboardText);
|
||||
if(cm2.format !== "invalid") {
|
||||
strokeColor = cm2.stringHEX();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const offset = els.filter(el=>el.type === "text")[0].fontSize/24;
|
||||
|
||||
let ids = [];
|
||||
|
||||
const addClone = (offsetX, offsetY) => {
|
||||
els.forEach(el=>{
|
||||
const clone = ea.cloneElement(el);
|
||||
ids.push(clone.id);
|
||||
clone.x += offsetX;
|
||||
clone.y += offsetY;
|
||||
if(offsetX!==0 || offsetY!==0) {
|
||||
switch (clone.type) {
|
||||
case "text":
|
||||
clone.strokeColor = strokeColor;
|
||||
break;
|
||||
default:
|
||||
clone.strokeColor = "transparent";
|
||||
break;
|
||||
}
|
||||
}
|
||||
ea.elementsDict[clone.id] = clone;
|
||||
})
|
||||
}
|
||||
|
||||
addClone(-offset,0);
|
||||
addClone(offset,0);
|
||||
addClone(0,offset);
|
||||
addClone(0,-offset);
|
||||
addClone(0,0);
|
||||
ea.copyViewElementsToEAforEditing(els);
|
||||
els.forEach(el=>ea.elementsDict[el.id].isDeleted = true);
|
||||
|
||||
ea.addToGroup(ids);
|
||||
ea.addElementsToView(false, true, true);
|
||||
17
ea-scripts/Text Aura.svg
Normal file
17
ea-scripts/Text Aura.svg
Normal file
@@ -0,0 +1,17 @@
|
||||
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 120" width="120" height="120">
|
||||
<!-- svg-source:excalidraw -->
|
||||
|
||||
<defs>
|
||||
<style class="style-fonts">
|
||||
@font-face {
|
||||
font-family: "Virgil";
|
||||
src: url("https://excalidraw.com/Virgil.woff2");
|
||||
}
|
||||
@font-face {
|
||||
font-family: "Cascadia";
|
||||
src: url("https://excalidraw.com/Cascadia.woff2");
|
||||
}
|
||||
</style>
|
||||
|
||||
</defs>
|
||||
<g stroke-linecap="round"><g transform="translate(0 0) rotate(0 60 60)" fill-rule="evenodd"><path d="M0 0 L120 0 L120 40 L80 40 L80 120 L40 120 L40 40 L0 40 L0 0" stroke="none" stroke-width="0" fill="red" fill-rule="evenodd"></path><path d="M0 0 C41.51 0, 83.02 0, 120 0 M0 0 C30.58 0, 61.16 0, 120 0 M120 0 C120 12.11, 120 24.22, 120 40 M120 0 C120 13.92, 120 27.84, 120 40 M120 40 C108.75 40, 97.49 40, 80 40 M120 40 C107.65 40, 95.29 40, 80 40 M80 40 C80 66.51, 80 93.01, 80 120 M80 40 C80 70.33, 80 100.66, 80 120 M80 120 C66.08 120, 52.16 120, 40 120 M80 120 C70.07 120, 60.13 120, 40 120 M40 120 C40 89.21, 40 58.42, 40 40 M40 120 C40 92.66, 40 65.33, 40 40 M40 40 C25.35 40, 10.71 40, 0 40 M40 40 C27.7 40, 15.4 40, 0 40 M0 40 C0 24.03, 0 8.05, 0 0 M0 40 C0 27.82, 0 15.65, 0 0 M0 0 C0 0, 0 0, 0 0 M0 0 C0 0, 0 0, 0 0" stroke="transparent" stroke-width="0.5" fill="none"></path></g></g><mask></mask><g stroke-linecap="round"><g transform="translate(110 10) rotate(0 -50 50)" fill-rule="evenodd"><path d="M0 0 L-100 0 L-100 20 L-60 20 L-60 100 L-40 100 L-40 20 L0 20 L0 0" stroke="none" stroke-width="0" fill="currentColor" fill-rule="evenodd"></path><path d="M0 0 C-23.27 0, -46.54 0, -100 0 M0 0 C-23.31 0, -46.62 0, -100 0 M-100 0 C-100 6.13, -100 12.26, -100 20 M-100 0 C-100 5.84, -100 11.69, -100 20 M-100 20 C-87.37 20, -74.74 20, -60 20 M-100 20 C-88.34 20, -76.68 20, -60 20 M-60 20 C-60 37.78, -60 55.56, -60 100 M-60 20 C-60 39.34, -60 58.68, -60 100 M-60 100 C-52.58 100, -45.17 100, -40 100 M-60 100 C-54.72 100, -49.43 100, -40 100 M-40 100 C-40 83.83, -40 67.67, -40 20 M-40 100 C-40 77.76, -40 55.51, -40 20 M-40 20 C-25.4 20, -10.8 20, 0 20 M-40 20 C-28.47 20, -16.93 20, 0 20 M0 20 C0 15.42, 0 10.84, 0 0 M0 20 C0 14.54, 0 9.08, 0 0 M0 0 C0 0, 0 0, 0 0 M0 0 C0 0, 0 0, 0 0" stroke="currentColor" stroke-width="0.5" fill="none"></path></g></g><mask></mask></svg>
|
||||
|
After Width: | Height: | Size: 2.3 KiB |
Reference in New Issue
Block a user