mirror of
https://github.com/zsviczian/obsidian-excalidraw-plugin.git
synced 2026-12-03 06:43:35 +00:00
Compare commits
37
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
54c80aab3d | ||
|
|
52a0ee2d8c | ||
|
|
fa3174001d | ||
|
|
905bb12dc4 | ||
|
|
4ce53ade6c | ||
|
|
0479eca6dc | ||
|
|
d374ca96d8 | ||
|
|
4c2a3c249a | ||
|
|
eb5298dad5 | ||
|
|
93a205bb70 | ||
|
|
0320307324 | ||
|
|
90928f9905 | ||
|
|
f4668f2b35 | ||
|
|
1d8b5d9942 | ||
|
|
4f880120b7 | ||
|
|
4269c78fc3 | ||
|
|
d82c558daf | ||
|
|
a6009a5c49 | ||
|
|
0b1fb8a443 | ||
|
|
fde2f117d3 | ||
|
|
106340efc5 | ||
|
|
ab9463c0a5 | ||
|
|
288cfe6013 | ||
|
|
33acdb5d29 | ||
|
|
620e397947 | ||
|
|
9fa9394592 | ||
|
|
e989e64fd6 | ||
|
|
779e413ed8 | ||
|
|
73a90fda05 | ||
|
|
8d9efe1e38 | ||
|
|
1136ebc88a | ||
|
|
40a0694a0f | ||
|
|
123cac8e00 | ||
|
|
c140f24473 | ||
|
|
f2a911c47c | ||
|
|
30eb992484 | ||
|
|
bb3eb684c0 |
No files matched your search
@@ -1,9 +1,9 @@
|
||||
{
|
||||
"name": "Node.js 20",
|
||||
"image": "mcr.microsoft.com/devcontainers/javascript-node:20",
|
||||
"name": "Node.js 22",
|
||||
"image": "mcr.microsoft.com/devcontainers/javascript-node:22",
|
||||
"features": {
|
||||
"ghcr.io/devcontainers/features/node:1": {
|
||||
"version": "20"
|
||||
"version": "22"
|
||||
}
|
||||
},
|
||||
"postCreateCommand": "npm install",
|
||||
@@ -14,4 +14,4 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,11 +20,11 @@ jobs:
|
||||
steps:
|
||||
# 1. Pull down your repository code
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v5
|
||||
|
||||
# 2. Tell the server to install Node 22
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
uses: actions/setup-node@v5
|
||||
with:
|
||||
node-version: '22'
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-message-square-heart-icon lucide-message-square-heart"><path d="M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z"/><path d="M7.5 9.5c0 .687.265 1.383.697 1.844l3.009 3.264a1.14 1.14 0 0 0 .407.314 1 1 0 0 0 .783-.004 1.14 1.14 0 0 0 .398-.31l3.008-3.264A2.77 2.77 0 0 0 16.5 9.5 2.5 2.5 0 0 0 12 8a2.5 2.5 0 0 0-4.5 1.5"/></svg>
|
||||
|
After Width: | Height: | Size: 597 B |
@@ -678,5 +678,13 @@
|
||||
{
|
||||
"fname": "Color Scheme Manager.svg",
|
||||
"mtime": 1780595297314
|
||||
},
|
||||
{
|
||||
"fname": "Comicbook Callout Editor.md",
|
||||
"mtime": 1782550477836
|
||||
},
|
||||
{
|
||||
"fname": "Comicbook Callout Editor.svg",
|
||||
"mtime": 1781961241320
|
||||
}
|
||||
]
|
||||
@@ -74,6 +74,7 @@ These are the scripts I use most often. I tried to order them by importance, but
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Crop%20Vintage%20Mask.svg"/></div>|[[#Crop Vintage Mask]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Mindmap%20Builder.svg"/></div>|[[#Mindmap Builder]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Capture%20Note.svg"/></div>|[[#Capture Note]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Comicbook%20Callout%20Editor.svg"/></div>|[[#Comicbook Callout Editor]]|
|
||||
|
||||
## Layout and Organization
|
||||
**Keywords**: Design, Placement, Arrangement, Structure, Formatting, Alignment
|
||||
@@ -118,6 +119,7 @@ These are the scripts I use most often. I tried to order them by importance, but
|
||||
|
||||
| | |
|
||||
|----|-----|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Comicbook%20Callout%20Editor.svg"/></div>|[[#Comicbook Callout Editor]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Convert%20selected%20text%20elements%20to%20sticky%20notes.svg"/></div>|[[#Convert selected text elements to sticky notes]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Relative%20Font%20Size%20Cycle.svg"/></div>|[[#Relative Font Size Cycle]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Scribble%20Helper.svg"/></div>|[[#Scribble Helper]]|
|
||||
@@ -284,6 +286,13 @@ https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea
|
||||
```
|
||||
<table><tr valign='top'><td class="label">Author</td><td class="data"><a href='https://github.com/iwanhoogendoorn'>@iwanhoogendoorn</a></td></tr><tr valign='top'><td class="label">Source</td><td class="data"><a href='https://github.com/zsviczian/obsidian-excalidraw-plugin/blob/master/ea-scripts/Color%20Scheme%20Manager.md'>File on GitHub</a></td></tr><tr valign='top'><td class="label">Description</td><td class="data">Swap the entire Stroke and Background/Fill colour palettes between named, categorized themes (Cloud Providers, Code Editors, Tech Brands, Design Systems, Nature, and more) from a docked side panel. Applying a theme recolours your selection (or sets the active colour) and repaints the native picker — both the quick-pick rows and the extended 3×5 grid with shades. Create your own schemes, import from a flat hex list, a labelled STROKE/FILL text format, or a raw appState colorPalette JSON (paste or .txt/.json file), hand-pick a custom picker, and export the current palette. When the MindMap Builder script is installed, an optional toggle recolours mind maps branch-by-branch. The canvas background is always left white.<br><img src='https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/images/color-scheme-manager.gif' style="width:560px;"></td></tr></table>
|
||||
|
||||
## Comicbook Callout Editor
|
||||
```excalidraw-script-install
|
||||
https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Comicbook%20Callout%20Editor.md
|
||||
```
|
||||
<table><tr valign='top'><td class="label">Author</td><td class="data"><a href='https://github.com/zsviczian'>@zsviczian</a></td></tr><tr valign='top'><td class="label">Source</td><td class="data"><a href='https://github.com/zsviczian/obsidian-excalidraw-plugin/blob/master/ea-scripts/Comicbook%20Callout%20Editor.md'>File on GitHub</a></td></tr><tr valign='top'><td class="label">Description</td><td class="data"><img src='https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/images/scripts-comicbook-callout-editor.jpg'></td></tr></table>
|
||||
|
||||
|
||||
## Concatenate lines
|
||||
```excalidraw-script-install
|
||||
https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Concatenate%20lines.md
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 564 KiB |
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "obsidian-excalidraw-plugin",
|
||||
"name": "Excalidraw",
|
||||
"version": "2.24.1",
|
||||
"version": "2.25.0-beta.2",
|
||||
"minAppVersion": "1.8.7",
|
||||
"description": "Sketch Your Mind. Edit and view Excalidraw drawings. Enter the world of 4D Visual PKM.",
|
||||
"author": "Zsolt Viczian",
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "obsidian-excalidraw-plugin",
|
||||
"name": "Excalidraw",
|
||||
"version": "2.24.1",
|
||||
"version": "2.24.2",
|
||||
"minAppVersion": "1.8.7",
|
||||
"description": "Sketch Your Mind. Edit and view Excalidraw drawings. Enter the world of 4D Visual PKM.",
|
||||
"author": "Zsolt Viczian",
|
||||
|
||||
Generated
+4
-4
@@ -13,7 +13,7 @@
|
||||
"@popperjs/core": "^2.11.8",
|
||||
"@radix-ui/number": "^1.1.2",
|
||||
"@zsviczian/colormaster": "^1.2.2",
|
||||
"@zsviczian/excalidraw": "0.18.105",
|
||||
"@zsviczian/excalidraw": "0.18.110",
|
||||
"chroma-js": "^3.1.2",
|
||||
"clsx": "^2.0.0",
|
||||
"es6-promise-pool": "2.5.0",
|
||||
@@ -5232,9 +5232,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@zsviczian/excalidraw": {
|
||||
"version": "0.18.105",
|
||||
"resolved": "https://registry.npmjs.org/@zsviczian/excalidraw/-/excalidraw-0.18.105.tgz",
|
||||
"integrity": "sha512-SOwKicgUPuz2rgOGGmAK3uuespob7knGoriHo82dfVrPT4eM1WhFNiDbGpnWql+PdkhwHrLG4ZcGpiXxAv/kRw==",
|
||||
"version": "0.18.110",
|
||||
"resolved": "https://registry.npmjs.org/@zsviczian/excalidraw/-/excalidraw-0.18.110.tgz",
|
||||
"integrity": "sha512-R/5aZ/6Sbk3O/TI0O28kA/KzyeXC61NDXFVjIi5857Lmx2Gvf1Xva3APKoqsnBwiR2aNjB92qBE86AiUyvxmhA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@braintree/sanitize-url": "6.0.2",
|
||||
|
||||
+3
-3
@@ -16,8 +16,8 @@
|
||||
"code:unused": "eslint --max-warnings=0 --ext .ts,.tsx ./src --quiet --format json | node -e \"let d='';process.stdin.on('data',c=>d+=c).on('end',()=>{const r=JSON.parse(d);for(const f of r){for(const m of f.messages||[]){if(m.ruleId==='@typescript-eslint/no-unused-vars'||m.ruleId==='no-unused-vars'){console.log(f.filePath+':'+m.line+':'+m.column+' '+m.ruleId+' '+m.message);}}}})\"",
|
||||
"code:escape": "eslint --max-warnings=0 --ext .ts,.tsx ./src --quiet --format json | node -e \"let d='';process.stdin.on('data',c=>d+=c).on('end',()=>{const r=JSON.parse(d);for(const f of r){for(const m of f.messages||[]){if(m.ruleId==='no-useless-escape'){console.log(f.filePath+':'+m.line+':'+m.column+' '+m.ruleId+' '+m.message);}}}})\"",
|
||||
"madge": "madge --circular .",
|
||||
"doc": "npm run lib && node scripts/generate-script-library.js",
|
||||
"mindmap": "node scripts/deploy-mindmap-builder.js",
|
||||
"doc": "npm run lib && node scripts/generate-script-library.mjs",
|
||||
"mindmap": "node scripts/deploy-mindmap-builder.mjs",
|
||||
"lint": "eslint .",
|
||||
"lint:fix": "npx prettier --write \"src/**/*.{ts,tsx}\" && eslint --max-warnings=0 --ext .ts,.tsx ./src --fix"
|
||||
},
|
||||
@@ -29,7 +29,7 @@
|
||||
"@popperjs/core": "^2.11.8",
|
||||
"@radix-ui/number": "^1.1.2",
|
||||
"@zsviczian/colormaster": "^1.2.2",
|
||||
"@zsviczian/excalidraw": "0.18.105",
|
||||
"@zsviczian/excalidraw": "0.18.110",
|
||||
"chroma-js": "^3.1.2",
|
||||
"clsx": "^2.0.0",
|
||||
"es6-promise-pool": "2.5.0",
|
||||
|
||||
@@ -151,6 +151,7 @@ const packageString = isLib
|
||||
' for (let i = 0; i < len; i++) bytes[i] = binStr.charCodeAt(i);\n' +
|
||||
' return new TextDecoder().decode(pako.inflate(bytes));\n' +
|
||||
'};\n' +
|
||||
'window.unpackBase64Deflate = unpackBase64Deflate;\n' +
|
||||
'const unpackExcalidraw = () => unpackBase64Deflate("' + compressDeflateBase64(excalidraw_pkg) + '");\n' +
|
||||
'let {react, reactDOM } = new Function(`${REACT_PACKAGES}; return {react: React, reactDOM: ReactDOM};`)();\n' +
|
||||
'let excalidrawLib = {};\n' +
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
const path = require("path");
|
||||
const fs = require("fs/promises");
|
||||
const { minify } = require("terser");
|
||||
const LZString = require("lz-string");
|
||||
import path from "path";
|
||||
import fs from "fs/promises";
|
||||
import { minify } from "terser";
|
||||
import LZString from "lz-string";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
// Construct __dirname for ES Modules
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
const CHUNK_SIZE = 256;
|
||||
const NEEDLE = "const removeKeydownHandlers";
|
||||
@@ -1,5 +1,5 @@
|
||||
const fs = require('fs');
|
||||
const { execSync } = require('child_process');
|
||||
import fs from 'fs';
|
||||
import { execSync } from 'child_process';
|
||||
|
||||
const content = fs.readFileSync('src/lang/locale/en.ts', 'utf8');
|
||||
const lines = content.split('\n');
|
||||
@@ -29,4 +29,4 @@ for (const key of keys) {
|
||||
}
|
||||
|
||||
unusedKeys.sort().forEach(k => console.log(k));
|
||||
console.log('Total: ' + unusedKeys.length);
|
||||
console.log('Total: ' + unusedKeys.length);
|
||||
@@ -1,7 +1,12 @@
|
||||
/* eslint-disable no-console */
|
||||
// to run: npm run doc
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
// to run: node generate-script-library.mjs
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
// Reconstruct __dirname for ES Modules
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
const ROOT = path.resolve(__dirname, '..');
|
||||
const EA_SCRIPTS_DIR = path.join(ROOT, 'ea-scripts');
|
||||
@@ -116,15 +121,18 @@ To keep this training file concise, large external type definitions are not incl
|
||||
|
||||
#### **6. Best Practices and Advanced Techniques**
|
||||
|
||||
* **Script Overview Block:** Create, and consistently maintain with each update, a comprehensive comment block at the very beginning of the script. This block must explain the purpose of the script, its key features, and the high-level solution logic or architecture.
|
||||
* **Strictly Modular Architecture (No loose code):** Avoid creating large monolithic blocks of code or leaving logic loose at the root level of the script. Instead, organize *everything* into relatively small, atomic functions. This includes UI components as well, if for example the UI includes sections, tabs, or panels, these should be rendered in sub functions. This is a critical requirement to ensure long-term maintainability and evolution of the script, as loose code quickly becomes unmanageable over multiple iterative prompts.
|
||||
* **Evergreen JSDoc Headers and Comments:** Every function must have a proper JSDoc/Javadoc-style header containing parameter names, types, and a clear description of the function's purpose. These descriptions must be kept *evergreen* (updated alongside any code changes). Additionally, when modifying or updating a script, you must strictly *retain all existing internal code comments*.
|
||||
* **Isolate Constants and User-Facing Strings:** *Do not embed hardcoded magic values, config parameters, or UI strings deep inside the logic.* You must separate all constants and language strings and collect them at the very top of the file. This makes it easier to tweak values later and provides a clear, unified section for localization and customization.
|
||||
* **Omit Version Verification:** While many of the sample scripts in the library include a version verification block at the outset (using \`ea.verifyMinimumPluginVersion\`), *do not add this section* when generating a new script unless explicitly instructed to do so.
|
||||
* **Embrace \`await\`:** Many EA functions are asynchronous and return a \`Promise\` (e.g., \`ea.addElementsToView()\`, \`ea.createSVG()\`, \`utils.inputPrompt()\`). **Always** use \`await\` when calling these functions to ensure your script executes in the correct order.
|
||||
* **Accessing Obsidian API:** The full Obsidian API is available via \`ea.obsidian\`. For example, use \`new ea.obsidian.Notice("message")\` or \`ea.obsidian.normalizePath(filepath)\`.
|
||||
* **Accessing Excalidraw API:** The full Excalidraw API is available on ea.getExcalidrawAPI(), these API functions are Scene dependent. Additional support functions are avalable on ExcalidrawLib.
|
||||
* **Accessing Excalidraw API:** The full Excalidraw API is available on \`ea.getExcalidrawAPI()\`, these API functions are Scene dependent. Additional support functions are available on \`window.ExcalidrawLib\`.
|
||||
* **Visibility vs. Deletion:**
|
||||
* To temporarily hide an element, set \`element.opacity = 0\`. It's good practice to store the original opacity in \`customData\` so it can be restored. It is also recommended to lock hidden elements so they do not get accidentally selected or moved around.
|
||||
* To permanently remove an element from the scene, set \`element.isDeleted = true\`.
|
||||
* **Image Handling:** When dealing with image elements, use \`ea.getViewFileForImageElement(imageElement)\` to get the corresponding \`TFile\` from the Obsidian vault. This is necessary for any logic that needs to read or manipulate the source image file.
|
||||
* **Break the code into helper functions:** Avoid creating large monolithic blocks of code in your scripts. Instead, break your code into smaller, reusable helper functions. This improves readability and maintainability. For example, if you have a block of code that creates a specific type of element with certain styles, consider creating a helper function like \`createStyledRect(x, y, width, height)\` that encapsulates that logic.
|
||||
* **Separate out constants and language strings to the top of the file:** Avoid hard coded values and strings embedded in the code. Instead the script file should start with a set of constants and language strings. Consistently collect these at the top of the file to make it easier to find and modify them later. This also makes it easier for translators to localize the script by providing a clear section for all user-facing text.
|
||||
|
||||
#### **9. Text Element**
|
||||
* There are three text properties.
|
||||
@@ -617,17 +625,17 @@ function main() {
|
||||
|
||||
const combined =
|
||||
(AI_TRAINING_INTRO +
|
||||
'\n---\n\n' +
|
||||
typeDefContent.trim() +
|
||||
'\n\n---\n\n' +
|
||||
excalidrawLibFunctionsSection +
|
||||
'\n---\n\n' +
|
||||
scriptLibContent.trim() +
|
||||
startupSection +
|
||||
'\n')
|
||||
.replaceAll("https://youtu.be/", "YouTube: ")
|
||||
.replaceAll("https://www.youtube.com/watch?v=", "YouTube: ")
|
||||
.replaceAll("https://www.youtube.com/", "YouTube: "); // prevent accidental link triggering
|
||||
'\n---\n\n' +
|
||||
typeDefContent.trim() +
|
||||
'\n\n---\n\n' +
|
||||
excalidrawLibFunctionsSection +
|
||||
'\n---\n\n' +
|
||||
scriptLibContent.trim() +
|
||||
startupSection +
|
||||
'\n')
|
||||
.replaceAll("https://youtu.be/", "YouTube: ")
|
||||
.replaceAll("https://www.youtube.com/watch?v=", "YouTube: ")
|
||||
.replaceAll("https://www.youtube.com/", "YouTube: "); // prevent accidental link triggering
|
||||
|
||||
fs.writeFileSync(AI_TRAINING_OUT, combined, 'utf8');
|
||||
console.log('[script-library] Wrote:', AI_TRAINING_OUT);
|
||||
@@ -638,11 +646,12 @@ function main() {
|
||||
console.log('[script-library] Done.');
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
// ESM equivalent of `if (require.main === module)`
|
||||
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
||||
try {
|
||||
main();
|
||||
} catch (e) {
|
||||
console.error('[script-library] Failed:', e);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -213,11 +213,15 @@ export const ICONS = {
|
||||
</text>
|
||||
</svg>
|
||||
),
|
||||
Edit: getIconAsJSX("pen-line"),
|
||||
Read: getIconAsJSX("book-open"),
|
||||
Learn: getIconAsJSX("graduation-cap"),
|
||||
Github: getIconAsJSX("github"),
|
||||
YouTube: getIconAsJSX("youtube"),
|
||||
heart: getIconAsJSX("heart"),
|
||||
twitter: getIconAsJSX("twitter"),
|
||||
FileCodeCorner: getIconAsJSX("file-code-corner"),
|
||||
File: getIconAsJSX("file"),
|
||||
exportLibrary: (
|
||||
<svg
|
||||
aria-hidden="true"
|
||||
|
||||
@@ -412,7 +412,7 @@ export const FRONTMATTER_KEYS = {
|
||||
type: "checkbox",
|
||||
depricated: false,
|
||||
},
|
||||
};
|
||||
} as const;
|
||||
|
||||
export const CaptureUpdateAction = {
|
||||
/**
|
||||
|
||||
+1
-2
@@ -1029,9 +1029,8 @@ export default class ExcalidrawPlugin extends Plugin {
|
||||
|
||||
public async awaitInit() {
|
||||
let counter = 0;
|
||||
while ((!this.isReady || !this.fontsReady) && counter < 200) {
|
||||
while ((!this.isReady || !this.fontsReady) && counter++ < 200) {
|
||||
await sleep(50);
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import {
|
||||
getParentOfClass,
|
||||
isObsidianThemeDark,
|
||||
getFileCSSClasses,
|
||||
getSafeFrontmatter,
|
||||
} from "../../utils/obsidianUtils";
|
||||
import { linkClickModifierType } from "../../utils/modifierkeyHelper";
|
||||
import { ImageKey, getImageCache } from "../../shared/ImageCache";
|
||||
@@ -39,10 +40,12 @@ import { linkPrompt } from "../../shared/Dialogs/Prompt";
|
||||
import {
|
||||
isInstanceOfHTMLElement,
|
||||
isInstanceOfHTMLImageElement,
|
||||
isInstanceOfSVGElement,
|
||||
} from "../../utils/typechecks";
|
||||
import { ExportSettings } from "src/types/exportUtilTypes";
|
||||
import { setElementDisplay } from "src/utils/htmlUtils";
|
||||
import { setStyle } from "src/utils/styleUtils";
|
||||
import { getGlobalTaskQueue } from "src/shared/GlobalTaskQueue";
|
||||
|
||||
interface imgElementAttributes {
|
||||
file?: TFile;
|
||||
@@ -76,6 +79,26 @@ const getDefaultHeight = (plugin: ExcalidrawPlugin): string => {
|
||||
return plugin.settings.height;
|
||||
};
|
||||
|
||||
/**
|
||||
* Utility to aggressively halt background image decoding and free Blob memory
|
||||
* when an element is discarded without being attached to the DOM.
|
||||
*/
|
||||
const discardImage = (el: Element | null) => {
|
||||
if (!el) {
|
||||
return;
|
||||
}
|
||||
const images = isInstanceOfHTMLImageElement(el)
|
||||
? [el]
|
||||
: Array.from(el.querySelectorAll("img"));
|
||||
images.forEach((img) => {
|
||||
if (img.src.startsWith("blob:")) {
|
||||
URL.revokeObjectURL(img.src);
|
||||
}
|
||||
// Instantly aborts the browser's background V8 image decoder task
|
||||
img.src = "";
|
||||
});
|
||||
};
|
||||
|
||||
export const initializeMarkdownPostProcessor = (p: ExcalidrawPlugin) => {
|
||||
plugin = p;
|
||||
app = plugin.app;
|
||||
@@ -428,6 +451,7 @@ const _getSVGNative = async ({
|
||||
const getIMG = async (
|
||||
imgAttributes: imgElementAttributes,
|
||||
onCanvas: boolean = false,
|
||||
embedEl?: Node,
|
||||
): Promise<HTMLImageElement | HTMLDivElement> => {
|
||||
let file = imgAttributes.file;
|
||||
if (!imgAttributes.file) {
|
||||
@@ -472,66 +496,92 @@ const getIMG = async (
|
||||
theme ? theme === "dark" : undefined,
|
||||
);
|
||||
|
||||
let terminationTimer: number;
|
||||
if (embedEl) {
|
||||
terminationTimer = window.setInterval(() => {
|
||||
if (!embedEl.isConnected) {
|
||||
loader.terminate = true;
|
||||
window.clearInterval(terminationTimer);
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
|
||||
const cacheReady = getImageCache().isReady();
|
||||
|
||||
await plugin.awaitInit();
|
||||
switch (plugin.settings.previewImageType) {
|
||||
case PreviewImageType.PNG: {
|
||||
const img = createEl("img");
|
||||
setImgStyle({
|
||||
element: img,
|
||||
imgAttributes,
|
||||
onCanvas,
|
||||
isNativeSVG: false,
|
||||
});
|
||||
return await _getPNG({
|
||||
imgAttributes,
|
||||
filenameParts,
|
||||
theme,
|
||||
cacheReady,
|
||||
img,
|
||||
file,
|
||||
exportSettings,
|
||||
loader,
|
||||
});
|
||||
let resultElement: HTMLImageElement | HTMLDivElement = null;
|
||||
try {
|
||||
await plugin.awaitInit();
|
||||
switch (plugin.settings.previewImageType) {
|
||||
case PreviewImageType.PNG: {
|
||||
const img = createEl("img");
|
||||
setImgStyle({
|
||||
element: img,
|
||||
imgAttributes,
|
||||
onCanvas,
|
||||
isNativeSVG: false,
|
||||
});
|
||||
resultElement = await _getPNG({
|
||||
imgAttributes,
|
||||
filenameParts,
|
||||
theme,
|
||||
cacheReady,
|
||||
img,
|
||||
file,
|
||||
exportSettings,
|
||||
loader,
|
||||
});
|
||||
break;
|
||||
}
|
||||
case PreviewImageType.SVGIMG: {
|
||||
const img = createEl("img");
|
||||
setImgStyle({
|
||||
element: img,
|
||||
imgAttributes,
|
||||
onCanvas,
|
||||
isNativeSVG: false,
|
||||
});
|
||||
resultElement = await _getSVGIMG({
|
||||
filenameParts,
|
||||
theme,
|
||||
cacheReady,
|
||||
img,
|
||||
file,
|
||||
exportSettings,
|
||||
loader,
|
||||
});
|
||||
break;
|
||||
}
|
||||
case PreviewImageType.SVG: {
|
||||
const img = createEl("div");
|
||||
setImgStyle({
|
||||
element: img,
|
||||
imgAttributes,
|
||||
onCanvas,
|
||||
isNativeSVG: true,
|
||||
});
|
||||
resultElement = await _getSVGNative({
|
||||
filenameParts,
|
||||
theme,
|
||||
cacheReady,
|
||||
containerElement: img,
|
||||
file,
|
||||
exportSettings,
|
||||
loader,
|
||||
width: imgAttributes.fwidth
|
||||
? !imgAttributes.fwidth.endsWith("%")
|
||||
? parseInt(imgAttributes.fwidth)
|
||||
: 6000
|
||||
: undefined,
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
case PreviewImageType.SVGIMG: {
|
||||
const img = createEl("img");
|
||||
setImgStyle({
|
||||
element: img,
|
||||
imgAttributes,
|
||||
onCanvas,
|
||||
isNativeSVG: false,
|
||||
});
|
||||
return await _getSVGIMG({
|
||||
filenameParts,
|
||||
theme,
|
||||
cacheReady,
|
||||
img,
|
||||
file,
|
||||
exportSettings,
|
||||
loader,
|
||||
});
|
||||
}
|
||||
case PreviewImageType.SVG: {
|
||||
const img = createEl("div");
|
||||
setImgStyle({ element: img, imgAttributes, onCanvas, isNativeSVG: true });
|
||||
return await _getSVGNative({
|
||||
filenameParts,
|
||||
theme,
|
||||
cacheReady,
|
||||
containerElement: img,
|
||||
file,
|
||||
exportSettings,
|
||||
loader,
|
||||
width: imgAttributes.fwidth
|
||||
? !imgAttributes.fwidth.endsWith("%")
|
||||
? parseInt(imgAttributes.fwidth)
|
||||
: 6000
|
||||
: undefined,
|
||||
});
|
||||
} finally {
|
||||
if (terminationTimer) {
|
||||
window.clearInterval(terminationTimer);
|
||||
}
|
||||
}
|
||||
return resultElement;
|
||||
};
|
||||
|
||||
const addSVGToImgSrc = (
|
||||
@@ -563,8 +613,9 @@ const addSVGToImgSrc = (
|
||||
const createImgElement = async (
|
||||
attr: imgElementAttributes,
|
||||
onCanvas: boolean = false,
|
||||
embedEl?: Element,
|
||||
): Promise<HTMLElement> => {
|
||||
const imgOrDiv = await getIMG(attr, onCanvas);
|
||||
const imgOrDiv = await getIMG(attr, onCanvas, embedEl);
|
||||
if (!imgOrDiv) {
|
||||
return null;
|
||||
}
|
||||
@@ -580,7 +631,9 @@ const createImgElement = async (
|
||||
|
||||
let timer: number;
|
||||
const clickEvent = (ev: PointerEvent) => {
|
||||
if (!isInstanceOfHTMLElement(ev.target)) {
|
||||
if (
|
||||
!(isInstanceOfHTMLElement(ev.target) || isInstanceOfSVGElement(ev.target))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const targetElement = ev.target;
|
||||
@@ -682,8 +735,11 @@ const createImgElement = async (
|
||||
eventElement.addEventListener("dblclick", clickEvent);
|
||||
eventElement.addEventListener(RERENDER_EVENT, (e) => {
|
||||
e.stopPropagation();
|
||||
void (async () => {
|
||||
void getGlobalTaskQueue(plugin).addTask(async () => {
|
||||
const parent = imgOrDiv.parentElement;
|
||||
if (!parent || !parent.isConnected) {
|
||||
return;
|
||||
}
|
||||
const imgMaxWidth = imgOrDiv.style.maxWidth;
|
||||
const imgMaxHeigth = imgOrDiv.style.maxHeight;
|
||||
const fileSource = imgOrDiv.getAttribute("fileSource");
|
||||
@@ -696,10 +752,17 @@ const createImgElement = async (
|
||||
imgstyle: [...Array.from(imgOrDiv.classList)],
|
||||
},
|
||||
onCanvas,
|
||||
parent,
|
||||
);
|
||||
if (!newImg) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!parent.isConnected) {
|
||||
discardImage(newImg);
|
||||
return;
|
||||
}
|
||||
|
||||
parent.empty();
|
||||
if (!onCanvas) {
|
||||
setStyle(newImg, {
|
||||
@@ -709,7 +772,7 @@ const createImgElement = async (
|
||||
}
|
||||
newImg.setAttribute("fileSource", fileSource);
|
||||
parent.append(newImg);
|
||||
})();
|
||||
});
|
||||
});
|
||||
const cssClasses = getFileCSSClasses(attr.file);
|
||||
cssClasses.forEach((cssClass) => {
|
||||
@@ -731,8 +794,12 @@ const createImgElement = async (
|
||||
const createImageDiv = async (
|
||||
attr: imgElementAttributes,
|
||||
onCanvas: boolean = false,
|
||||
embedEl?: Element,
|
||||
): Promise<HTMLDivElement> => {
|
||||
const img = await createImgElement(attr, onCanvas);
|
||||
const img = await createImgElement(attr, onCanvas, embedEl);
|
||||
if (!img) {
|
||||
return null;
|
||||
}
|
||||
return createDiv(attr.imgstyle.join(" "), (el) => el.append(img));
|
||||
};
|
||||
|
||||
@@ -746,7 +813,14 @@ const processReadingMode = async (
|
||||
//Iterating all the containers in the file to check which one is an excalidraw drawing
|
||||
//This is a for loop instead of embeddedItems.forEach() because processInternalEmbed at the end
|
||||
//is awaited, otherwise excalidraw images would not display in the Kanban plugin
|
||||
const promises: Promise<void>[] = [];
|
||||
|
||||
for (const maybeDrawing of embeddedItems) {
|
||||
// If the node is detached from the DOM, the user has closed the note or navigated away.
|
||||
if (!maybeDrawing.isConnected) {
|
||||
break;
|
||||
}
|
||||
|
||||
//check to see if the file in the src attribute exists
|
||||
const fname = maybeDrawing.getAttribute("src")?.split("#")[0];
|
||||
if (!fname) {
|
||||
@@ -764,12 +838,31 @@ const processReadingMode = async (
|
||||
continue;
|
||||
}
|
||||
|
||||
maybeDrawing.parentElement.replaceChild(
|
||||
await processInternalEmbed(maybeDrawing, file),
|
||||
maybeDrawing,
|
||||
promises.push(
|
||||
getGlobalTaskQueue(plugin).addTask(async () => {
|
||||
if (!maybeDrawing.isConnected) {
|
||||
return;
|
||||
}
|
||||
|
||||
const imgDiv = await processInternalEmbed(maybeDrawing, file);
|
||||
if (!imgDiv) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ensure we don't attempt to append onto a detached DOM tree
|
||||
if (!maybeDrawing.isConnected) {
|
||||
discardImage(imgDiv);
|
||||
return;
|
||||
}
|
||||
|
||||
maybeDrawing.parentElement.replaceChild(imgDiv, maybeDrawing);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Await the completion of all generated jobs allowing concurrent processing via the Global Task Queue
|
||||
await Promise.all(promises);
|
||||
};
|
||||
|
||||
const processInternalEmbed = async (
|
||||
@@ -785,7 +878,7 @@ const processInternalEmbed = async (
|
||||
|
||||
const src = internalEmbedEl.getAttribute("src");
|
||||
if (!src) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
//https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/1059
|
||||
@@ -810,7 +903,7 @@ const processInternalEmbed = async (
|
||||
? fnameParts.linkpartReference
|
||||
: "");
|
||||
attr.file = file;
|
||||
return await createImageDiv(attr);
|
||||
return await createImageDiv(attr, false, internalEmbedEl);
|
||||
};
|
||||
|
||||
function getDimensionsFromAliasString(data: string) {
|
||||
@@ -967,7 +1060,8 @@ const tmpObsidianWYSIWYG = async (
|
||||
if (!plugin.isExcalidrawFile(file)) {
|
||||
return;
|
||||
}
|
||||
if (ctx.frontmatter?.["excalidraw-embed-md"]) {
|
||||
const safeFrontmatter = getSafeFrontmatter(ctx.frontmatter);
|
||||
if (safeFrontmatter["excalidraw-open-md"]) {
|
||||
return;
|
||||
}
|
||||
if (ctx.remainingNestLevel < 4) {
|
||||
@@ -1017,7 +1111,8 @@ const tmpObsidianWYSIWYG = async (
|
||||
|
||||
if (!plugin.settings.renderImageInHoverPreviewForMDNotes) {
|
||||
//const isHoverPopover = internalEmbedDiv.parentElement?.hasClass("hover-popover");
|
||||
const shouldOpenMD = Boolean(ctx.frontmatter?.["excalidraw-open-md"]);
|
||||
const safeFrontmatter = getSafeFrontmatter(ctx.frontmatter);
|
||||
const shouldOpenMD = Boolean(safeFrontmatter["excalidraw-open-md"]);
|
||||
if (isHoverPopover && shouldOpenMD) {
|
||||
return;
|
||||
}
|
||||
@@ -1081,42 +1176,63 @@ const tmpObsidianWYSIWYG = async (
|
||||
}
|
||||
internalEmbedDiv.empty();
|
||||
const onCanvas = internalEmbedDiv.hasClass("canvas-node-content");
|
||||
const imgDiv = await createImageDiv(attr, onCanvas);
|
||||
if (markdownEmbed) {
|
||||
//display image on canvas without markdown frame
|
||||
internalEmbedDiv.removeClass("markdown-embed");
|
||||
internalEmbedDiv.removeClass("inline-embed");
|
||||
internalEmbedDiv.addClass("media-embed");
|
||||
internalEmbedDiv.addClass("image-embed");
|
||||
if (!onCanvas && isInstanceOfHTMLElement(imgDiv.firstChild)) {
|
||||
setStyle(imgDiv.firstChild, {
|
||||
maxHeight: "100%",
|
||||
maxWidth: null,
|
||||
});
|
||||
|
||||
await getGlobalTaskQueue(plugin).addTask(async () => {
|
||||
if (!internalEmbedDiv.isConnected) {
|
||||
return;
|
||||
}
|
||||
// Resolve the cyclic size dependency by applying a CSS width and/or height
|
||||
if (
|
||||
!onCanvas &&
|
||||
isHoverPopover &&
|
||||
isInstanceOfHTMLImageElement(imgDiv.firstChild)
|
||||
) {
|
||||
internalEmbedDiv.style.setProperty(
|
||||
"--popover-width",
|
||||
`${attr.fwidth}px`,
|
||||
);
|
||||
internalEmbedDiv.style.setProperty(
|
||||
"--popover-height",
|
||||
`${attr.fheight}px`,
|
||||
);
|
||||
setStyle(internalEmbedDiv, {
|
||||
width: "var(--popover-width)",
|
||||
height: "var(--popover-height)",
|
||||
});
|
||||
|
||||
const imgDiv = await createImageDiv(attr, onCanvas, internalEmbedDiv);
|
||||
if (!imgDiv) {
|
||||
return;
|
||||
}
|
||||
internalEmbedDiv.appendChild(imgDiv.firstChild);
|
||||
return;
|
||||
}
|
||||
internalEmbedDiv.appendChild(imgDiv);
|
||||
|
||||
// Check if the user navigated away while the image was generating
|
||||
if (!internalEmbedDiv.isConnected) {
|
||||
discardImage(imgDiv);
|
||||
return;
|
||||
}
|
||||
|
||||
if (markdownEmbed) {
|
||||
//display image on canvas without markdown frame
|
||||
internalEmbedDiv.removeClass("markdown-embed");
|
||||
internalEmbedDiv.removeClass("inline-embed");
|
||||
internalEmbedDiv.addClass("media-embed");
|
||||
internalEmbedDiv.addClass("image-embed");
|
||||
if (
|
||||
!onCanvas &&
|
||||
(isInstanceOfHTMLElement(imgDiv.firstChild) ||
|
||||
isInstanceOfSVGElement(imgDiv.firstChild))
|
||||
) {
|
||||
setStyle(imgDiv.firstChild, {
|
||||
maxHeight: "100%",
|
||||
maxWidth: null,
|
||||
});
|
||||
}
|
||||
// Resolve the cyclic size dependency by applying a CSS width and/or height
|
||||
if (
|
||||
!onCanvas &&
|
||||
isHoverPopover &&
|
||||
isInstanceOfHTMLImageElement(imgDiv.firstChild)
|
||||
) {
|
||||
internalEmbedDiv.style.setProperty(
|
||||
"--popover-width",
|
||||
`${attr.fwidth}px`,
|
||||
);
|
||||
internalEmbedDiv.style.setProperty(
|
||||
"--popover-height",
|
||||
`${attr.fheight}px`,
|
||||
);
|
||||
setStyle(internalEmbedDiv, {
|
||||
width: "var(--popover-width)",
|
||||
height: "var(--popover-height)",
|
||||
});
|
||||
}
|
||||
internalEmbedDiv.appendChild(imgDiv.firstChild);
|
||||
return;
|
||||
}
|
||||
internalEmbedDiv.appendChild(imgDiv);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1134,8 +1250,25 @@ const tmpObsidianWYSIWYG = async (
|
||||
internalEmbedDiv.setAttribute("ready", "");
|
||||
|
||||
internalEmbedDiv.empty();
|
||||
const imgDiv = await processInternalEmbed(internalEmbedDiv, file);
|
||||
internalEmbedDiv.appendChild(imgDiv);
|
||||
|
||||
await getGlobalTaskQueue(plugin).addTask(async () => {
|
||||
if (!internalEmbedDiv.isConnected) {
|
||||
return;
|
||||
}
|
||||
|
||||
const imgDiv = await processInternalEmbed(internalEmbedDiv, file);
|
||||
if (!imgDiv) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Abort insertion if the container is no longer connected
|
||||
if (!internalEmbedDiv.isConnected) {
|
||||
discardImage(imgDiv);
|
||||
return;
|
||||
}
|
||||
|
||||
internalEmbedDiv.appendChild(imgDiv);
|
||||
});
|
||||
|
||||
//timer to avoid the image flickering when the user is typing
|
||||
let timer: number = null;
|
||||
@@ -1149,10 +1282,23 @@ const tmpObsidianWYSIWYG = async (
|
||||
timer = window.setTimeout(() => {
|
||||
timer = null;
|
||||
internalEmbedDiv.empty();
|
||||
void (async () => {
|
||||
void getGlobalTaskQueue(plugin).addTask(async () => {
|
||||
if (!internalEmbedDiv.isConnected) {
|
||||
observer.disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
const imgDiv = await processInternalEmbed(internalEmbedDiv, file);
|
||||
internalEmbedDiv.appendChild(imgDiv);
|
||||
})();
|
||||
if (!imgDiv) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (internalEmbedDiv.isConnected) {
|
||||
internalEmbedDiv.appendChild(imgDiv);
|
||||
} else {
|
||||
discardImage(imgDiv);
|
||||
}
|
||||
});
|
||||
}, 500);
|
||||
};
|
||||
const observer = DEBUGGING
|
||||
@@ -1204,9 +1350,10 @@ export const markdownPostProcessor = async (
|
||||
const isHoverPopover = Boolean(
|
||||
containerEl && getParentOfClass(containerEl, "hover-popover"),
|
||||
);
|
||||
const safeFrontmatter = getSafeFrontmatter(ctx.frontmatter);
|
||||
const isPreview =
|
||||
isHoverPopover &&
|
||||
Boolean(ctx?.frontmatter?.["excalidraw-open-md"]) &&
|
||||
Boolean(safeFrontmatter["excalidraw-open-md"]) &&
|
||||
!plugin.settings.renderImageInHoverPreviewForMDNotes;
|
||||
const embeddedItems = el.querySelectorAll(".internal-embed");
|
||||
|
||||
@@ -1248,9 +1395,7 @@ export const markdownPostProcessor = async (
|
||||
//then I want to hide all embedded items as these will be
|
||||
//transcluded text element or some other transcluded content inside the Excalidraw file
|
||||
//in reading mode these elements should be hidden
|
||||
const excalidrawFile = Boolean(
|
||||
ctx.frontmatter && "excalidraw-plugin" in ctx.frontmatter,
|
||||
);
|
||||
const excalidrawFile = Boolean(safeFrontmatter["excalidraw-plugin"]);
|
||||
if (!(isPreview || isMarkdownReadingMode || isPrinting) && excalidrawFile) {
|
||||
setElementDisplay(el, "none");
|
||||
return;
|
||||
@@ -1331,14 +1476,32 @@ const legacyExcalidrawPopoverObserverFn: MutationCallback = (m) => {
|
||||
|
||||
//this div will be on top of original DIV. By stopping the propagation of the click
|
||||
//I prevent the default Obsidian feature of opening the link in the native app
|
||||
void (async () => {
|
||||
const img = await getIMG({
|
||||
file,
|
||||
fname: file.path,
|
||||
fwidth: "300",
|
||||
fheight: null,
|
||||
imgstyle: ["excalidraw-svg"],
|
||||
});
|
||||
void getGlobalTaskQueue(plugin).addTask(async () => {
|
||||
if (!node.isConnected) {
|
||||
return;
|
||||
}
|
||||
|
||||
const img = await getIMG(
|
||||
{
|
||||
file,
|
||||
fname: file.path,
|
||||
fwidth: "300",
|
||||
fheight: null,
|
||||
imgstyle: ["excalidraw-svg"],
|
||||
},
|
||||
false,
|
||||
node,
|
||||
);
|
||||
|
||||
if (!img) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!node.isConnected) {
|
||||
discardImage(img);
|
||||
return;
|
||||
}
|
||||
|
||||
const div = createDiv("", (el) => {
|
||||
el.appendChild(img);
|
||||
el.setAttribute("src", file.path);
|
||||
@@ -1354,7 +1517,7 @@ const legacyExcalidrawPopoverObserverFn: MutationCallback = (m) => {
|
||||
});
|
||||
});
|
||||
node.appendChild(div);
|
||||
})();
|
||||
});
|
||||
};
|
||||
|
||||
export const legacyExcalidrawPopoverObserver = DEBUGGING
|
||||
|
||||
@@ -748,6 +748,7 @@ export const DEFAULT_SETTINGS: ExcalidrawSettings = {
|
||||
borderColor: "#fff",
|
||||
borderOpacity: 0,
|
||||
filenameVisible: false,
|
||||
lockedReadingMode: false,
|
||||
},
|
||||
markdownNodeOneClickEditing: false,
|
||||
canvasImmersiveEmbed: true,
|
||||
|
||||
@@ -1290,6 +1290,11 @@ export default {
|
||||
ES_YOUTUBE_START_INVALID:
|
||||
"The YouTube Start Time is invalid. Please check the format and try again",
|
||||
ES_FILENAME_VISIBLE: "Filename Visible",
|
||||
ES_LOCKED_READING_MODE_HEAD: "Locked Reading Mode",
|
||||
ES_LOCKED_READING_MODE_DESC:
|
||||
"When enabled, interacting with the markdown embeddable will not switch it to edit mode. This is useful for checklists and habit trackers.",
|
||||
LOCK_READING_MODE: "Lock Reading Mode",
|
||||
UNLOCK_READING_MODE: "Unlock Reading Mode",
|
||||
ES_BACKGROUND_HEAD: "Embedded note background color",
|
||||
ES_BACKGROUND_DESC_INFO: "Click here for more info on colors",
|
||||
ES_BACKGROUND_DESC_DETAIL:
|
||||
@@ -1307,6 +1312,13 @@ export default {
|
||||
ES_ZOOM_100_RELATIVE_DESC:
|
||||
"The button will adjust the element scale so it will show the content at 100% relative to the current zoom level of your canvas",
|
||||
ES_ZOOM_100: "Relative 100%",
|
||||
ES_PROPERTIES_VISIBLE_HEAD: "Properties visible",
|
||||
ES_PROPERTIES_VISIBLE_DESC:
|
||||
"Show document properties (YAML frontmatter) at the top of the embedded file.",
|
||||
ES_PROPERTIES_VISIBLE_WARNING:
|
||||
"Global Obsidian settings are hiding document properties. This setting cannot reveal them. Please change your Obsidian settings to 'Visible' or 'Source' first.",
|
||||
SHOW_PROPERTIES: "Show properties",
|
||||
HIDE_PROPERTIES: "Hide properties",
|
||||
|
||||
//Prompts.ts
|
||||
PROMPT_FILE_DOES_NOT_EXIST: "File does not exist. Do you want to create it?",
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Setting, ToggleComponent } from "obsidian";
|
||||
import { App, Setting, ToggleComponent } from "obsidian";
|
||||
import { EmbeddableMDCustomProps } from "./EmbeddableSettings";
|
||||
import { fragWithHTML } from "src/utils/utils";
|
||||
import { t } from "src/lang/helpers";
|
||||
import { hideElement, showElement } from "src/utils/styleUtils";
|
||||
import { hideElement, setStyle, showElement } from "src/utils/styleUtils";
|
||||
|
||||
export class EmbeddalbeMDFileCustomDataSettingsComponent {
|
||||
constructor(
|
||||
@@ -10,6 +10,8 @@ export class EmbeddalbeMDFileCustomDataSettingsComponent {
|
||||
private mdCustomData: EmbeddableMDCustomProps,
|
||||
private update?: () => void,
|
||||
private isMDFile: boolean = true,
|
||||
private isFullFile: boolean = true,
|
||||
private app?: App,
|
||||
) {
|
||||
if (!update) {
|
||||
this.update = () => {};
|
||||
@@ -53,7 +55,46 @@ export class EmbeddalbeMDFileCustomDataSettingsComponent {
|
||||
this.mdCustomData.filenameVisible = value;
|
||||
}),
|
||||
);
|
||||
|
||||
const isGlobalHidden = this.app
|
||||
? this.app.vault.getConfig("propertiesInDocument") === "hidden"
|
||||
: false;
|
||||
|
||||
const propertiesSetting = new Setting(contentEl)
|
||||
.setName(t("ES_PROPERTIES_VISIBLE_HEAD"))
|
||||
.setDesc(
|
||||
isGlobalHidden
|
||||
? t("ES_PROPERTIES_VISIBLE_WARNING")
|
||||
: t("ES_PROPERTIES_VISIBLE_DESC"),
|
||||
)
|
||||
.addToggle((toggle) => {
|
||||
toggle
|
||||
.setValue(this.mdCustomData.propertiesVisible ?? true)
|
||||
.onChange((value) => {
|
||||
this.mdCustomData.propertiesVisible = value;
|
||||
});
|
||||
if (!this.isFullFile || isGlobalHidden) {
|
||||
toggle.setDisabled(true);
|
||||
setStyle(toggle.toggleEl, { opacity: "0.5" });
|
||||
}
|
||||
});
|
||||
|
||||
if (isGlobalHidden) {
|
||||
propertiesSetting.descEl.addClass("mod-warning");
|
||||
}
|
||||
|
||||
new Setting(contentEl)
|
||||
.setName(t("ES_LOCKED_READING_MODE_HEAD"))
|
||||
.setDesc(t("ES_LOCKED_READING_MODE_DESC"))
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(!!this.mdCustomData.lockedReadingMode)
|
||||
.onChange((value) => {
|
||||
this.mdCustomData.lockedReadingMode = value;
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
contentEl.createEl("h4", { text: t("ES_BACKGROUND_HEAD") });
|
||||
const descDiv = contentEl.createDiv({ cls: "excalidraw-setting-desc" });
|
||||
descDiv.textContent = t("ES_BACKGROUND_DESC_INFO");
|
||||
|
||||
@@ -32,6 +32,8 @@ export type EmbeddableMDCustomProps = {
|
||||
borderColor: string;
|
||||
borderOpacity: number;
|
||||
filenameVisible: boolean;
|
||||
propertiesVisible?: boolean;
|
||||
lockedReadingMode?: boolean;
|
||||
};
|
||||
|
||||
export class EmbeddableSettings extends Modal {
|
||||
@@ -66,9 +68,9 @@ export class EmbeddableSettings extends Modal {
|
||||
this.youtubeStart = getYouTubeStartAt(this.element.link);
|
||||
}
|
||||
|
||||
this.mdCustomData =
|
||||
element.customData?.mdProps ??
|
||||
view.plugin.settings.embeddableMarkdownDefaults;
|
||||
this.mdCustomData = (element.customData?.mdProps ??
|
||||
view.plugin.settings
|
||||
.embeddableMarkdownDefaults) as EmbeddableMDCustomProps;
|
||||
if (!element.customData?.mdProps) {
|
||||
const bgCM = this.plugin.ea.getCM(element.backgroundColor);
|
||||
this.mdCustomData.backgroundColor = bgCM.stringHEX({ alpha: false });
|
||||
@@ -151,11 +153,14 @@ export class EmbeddableSettings extends Modal {
|
||||
|
||||
if (this.isMDFile || this.notExcalidrawIsInternal) {
|
||||
this.contentEl.createEl("h3", { text: t("ES_EMBEDDABLE_SETTINGS") });
|
||||
const isFullFile = this.element ? !this.element.link.includes("#") : true;
|
||||
new EmbeddalbeMDFileCustomDataSettingsComponent(
|
||||
this.contentEl,
|
||||
this.mdCustomData,
|
||||
undefined,
|
||||
this.isMDFile,
|
||||
isFullFile,
|
||||
this.app,
|
||||
).render();
|
||||
}
|
||||
|
||||
@@ -248,6 +253,9 @@ export class EmbeddableSettings extends Modal {
|
||||
this.element.customData?.backgroundOpacity ||
|
||||
this.mdCustomData.borderOpacity !==
|
||||
this.element.customData?.borderOpacity ||
|
||||
this.mdCustomData.propertiesVisible !==
|
||||
(this.element.customData?.mdProps as EmbeddableMDCustomProps)
|
||||
?.propertiesVisible ||
|
||||
this.mdCustomData.filenameVisible !==
|
||||
this.element.customData?.filenameVisible)
|
||||
) {
|
||||
|
||||
@@ -16,6 +16,26 @@ export const RELEASE_NOTES: { [k: string]: string } = {
|
||||
I build this plugin as a labor of love. Curious about the philosophy behind it? Check out [📕 Sketch Your Mind](${URLs.COMMUNITY_SKETCH_YOUR_MIND_COM_SYM}). Want to master Excalidraw? Join [Excalidraw Mastery](${URLs.COMMUNITY_SKETCH_YOUR_MIND_COM_EM}). If you find it valuable, say "Thank you", and
|
||||
|
||||
<div class="ex-coffee-div"><a href="${URLs.KO_FI_COM_ZSOLT}"><img src="${URLs.CDN_KO_FI_COM_CDN_KOFI3_PNG}" border="0" alt="Buy Me a Coffee at ko-fi.com" height=45></a></div>
|
||||
`,
|
||||
"2.25.0": `
|
||||
## New from Excalidraw.com
|
||||
- Significantly improved ink flow for freedraw pen. You can now toggle between pressure sensitive and constant mode for the default excalidraw.com freedraw pen. [#11507](${URLs.GITHUB_COM_EXCALIDRAW_EXCALIDRAW_PULL}/11507), [#11551](${URLs.GITHUB_COM_EXCALIDRAW_EXCALIDRAW_PULL}/11551)
|
||||
|
||||
## New in the Plugin
|
||||
- Added the ability to show or hide document properties for embedded full Markdown files. This feature was requested by @Rolf during a Sketch Your Mind community monthly call discussion. [Join the community!](${URLs.COMMUNITY_SKETCH_YOUR_MIND_COM}/welcome)
|
||||
- Comic book Callout Editor script available in the Script Library
|
||||
- Added new ExtraBold line width option, and XS font option
|
||||
|
||||
## Fixed
|
||||
- BUG: Double Click to edit from Obsidian in Live preview doesn't work anymore [#2813](${URLs.GITHUB_COM_ZSVICZIAN_OBSIDIAN_EXCALIDRAW_PLUGIN_ISSUES}/2813)
|
||||
- Edge cases leading to memory leak and CPU overload when closing a markdown preview while embedded Excalidraw drawings are loading, or closing an ExcalidrawView, while nested images are still loading.
|
||||
`,
|
||||
"2.24.2": `
|
||||
## Fixed
|
||||
- High impact regression in 2.24.0: Translations were not loading correctly. 🙏[@Lumintian](${URLs.GITHUB_COM}/Lumintian) [#2809](${URLs.GITHUB_COM_ZSVICZIAN_OBSIDIAN_EXCALIDRAW_PLUGIN_PULL}/2809)
|
||||
|
||||
## New
|
||||
- Added lock reading mode to markdown embeddables. If reading mode is locked, clicking the embeddable will not switch to the editor. This is useful for interacting with todo lists, links, and other interactive elements in the embeddables. Based on feedback from the Sketch Your Mind Community. 🙏[@robb3r](${URLs.COMMUNITY_SKETCH_YOUR_MIND_COM}/u/robb3r)
|
||||
`,
|
||||
"2.24.1": `
|
||||
To keep Excalidraw lightweight, improve startup performance, reduce plugin size, and address Obsidian's high-risk code scanner findings, several advanced features have been moved to the new **Excalidraw Extras** companion plugin in 2.24.0.
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
mainDocument,
|
||||
} from "../constants/constants";
|
||||
import { createSVG } from "src/utils/excalidrawAutomateUtils";
|
||||
import { ExcalidrawData, getTransclusion } from "./ExcalidrawData";
|
||||
import { EquationItem, ExcalidrawData, getTransclusion } from "./ExcalidrawData";
|
||||
import { t } from "../lang/helpers";
|
||||
import { tex2dataURL } from "./LaTeX";
|
||||
import ExcalidrawPlugin from "../core/main";
|
||||
@@ -214,15 +214,15 @@ export class EmbeddedFile {
|
||||
this.file.extension.toLowerCase() === "svg")
|
||||
) {
|
||||
try {
|
||||
this.colorMap = colorMapJSON
|
||||
? JSON.parse(colorMapJSON.toLocaleLowerCase())
|
||||
: null;
|
||||
} catch (error) {
|
||||
console.log(
|
||||
`Error parsing colorMap for file ${imgPath}`,
|
||||
this.constructor,
|
||||
this.colorMap = (
|
||||
colorMapJSON ? JSON.parse(colorMapJSON.toLocaleLowerCase()) : null
|
||||
) as ColorMap | null;
|
||||
} catch (error: unknown) {
|
||||
errorlog({
|
||||
message: `Error parsing colorMap for file ${imgPath}`,
|
||||
context: this.constructor,
|
||||
error,
|
||||
);
|
||||
});
|
||||
this.colorMap = null;
|
||||
}
|
||||
}
|
||||
@@ -429,7 +429,7 @@ export class EmbeddedFilesLoader {
|
||||
this.pdfDocs.forEach((pdfDoc) => {
|
||||
try {
|
||||
pdfDoc.destroy();
|
||||
} catch (e) {
|
||||
} catch (e: unknown) {
|
||||
errorlog({ where: "EmbeddedFileLoader.emptyPDFDocsMap", error: e });
|
||||
}
|
||||
});
|
||||
@@ -479,6 +479,9 @@ export class EmbeddedFilesLoader {
|
||||
hasSVGwithBitmap: boolean;
|
||||
loadedFromCache?: boolean;
|
||||
}> {
|
||||
if (this.terminate) {
|
||||
return { dataURL: "" as DataURL, hasSVGwithBitmap: false };
|
||||
}
|
||||
//debug({where:"EmbeddedFileLoader.getExcalidrawSVG",uid:this.uid,file:file.name});
|
||||
const isMask = isMaskFile(this.plugin, file);
|
||||
const forceTheme = hasExportTheme(this.plugin, file)
|
||||
@@ -540,6 +543,10 @@ export class EmbeddedFilesLoader {
|
||||
})
|
||||
: undefined;
|
||||
|
||||
if (this.terminate) {
|
||||
return { dataURL: "" as DataURL, hasSVGwithBitmap: false };
|
||||
}
|
||||
|
||||
if (maybeSVG && cacheValidation === "stale-first") {
|
||||
onStaleCacheHit?.();
|
||||
}
|
||||
@@ -582,6 +589,10 @@ export class EmbeddedFilesLoader {
|
||||
inFile instanceof EmbeddedFile ? inFile.colorMap : null,
|
||||
) as SVGSVGElement);
|
||||
|
||||
if (this.terminate) {
|
||||
return { dataURL: "" as DataURL, hasSVGwithBitmap: false };
|
||||
}
|
||||
|
||||
//https://stackoverflow.com/questions/51154171/remove-css-filter-on-child-elements
|
||||
const imageList = svg.querySelectorAll(
|
||||
"image:not([href^='data:image/svg'])",
|
||||
@@ -726,6 +737,10 @@ export class EmbeddedFilesLoader {
|
||||
)
|
||||
: await app.vault.readBinary(file);
|
||||
|
||||
if (this.terminate) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let dURL: DataURL = null;
|
||||
let excalidrawLoadedFromCache = false;
|
||||
if (isExcalidrawFile) {
|
||||
@@ -738,6 +753,10 @@ export class EmbeddedFilesLoader {
|
||||
cacheValidation: options?.cacheValidation,
|
||||
onStaleCacheHit: options?.onStaleCacheHit,
|
||||
});
|
||||
|
||||
if (this.terminate) {
|
||||
return null;
|
||||
}
|
||||
dURL = res.dataURL;
|
||||
hasSVGwithBitmap = res.hasSVGwithBitmap;
|
||||
excalidrawLoadedFromCache = !!res.loadedFromCache;
|
||||
@@ -755,6 +774,10 @@ export class EmbeddedFilesLoader {
|
||||
? await this.pdfToDataURL(file, linkParts, options)
|
||||
: [null, null, null, null, false];
|
||||
|
||||
if (this.terminate) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let mimeType: MimeType = isPDF ? "image/png" : "image/svg+xml";
|
||||
|
||||
const extension =
|
||||
@@ -781,6 +804,10 @@ export class EmbeddedFilesLoader {
|
||||
? null
|
||||
: await getDataURL(ab, mimeType)));
|
||||
|
||||
if (this.terminate) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!isHyperLink && !dataURL && !isLocalLink) {
|
||||
markdownRendererRecursionWatcthdog.add(file);
|
||||
try {
|
||||
@@ -797,6 +824,11 @@ export class EmbeddedFilesLoader {
|
||||
}
|
||||
|
||||
const size = isPDF ? pdfSize : await getImageSize(dataURL);
|
||||
|
||||
if (this.terminate) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
mimeType,
|
||||
fileId: await generateIdFromFile(
|
||||
@@ -817,7 +849,7 @@ export class EmbeddedFilesLoader {
|
||||
pdfPageViewProps,
|
||||
renderScale: pdfRenderScale,
|
||||
};
|
||||
} catch (error) {
|
||||
} catch (error: unknown) {
|
||||
errorlog({
|
||||
where: "EmbeddedFileLoader._getObsidianImage",
|
||||
uid: this.uid,
|
||||
@@ -874,7 +906,7 @@ export class EmbeddedFilesLoader {
|
||||
promiseTry(async () => {
|
||||
try {
|
||||
await task();
|
||||
} catch (error) {
|
||||
} catch (error: unknown) {
|
||||
errorlog({
|
||||
where: "EmbeddedFileLoader.loadSceneFiles",
|
||||
uid: this.uid,
|
||||
@@ -913,6 +945,10 @@ export class EmbeddedFilesLoader {
|
||||
? () => deferredValidationFileIds.add(id)
|
||||
: undefined,
|
||||
});
|
||||
if (this.terminate) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (data) {
|
||||
const fileData: FileData = {
|
||||
mimeType: data.mimeType,
|
||||
@@ -959,11 +995,15 @@ export class EmbeddedFilesLoader {
|
||||
let equationItem;
|
||||
const equations = excalidrawData.getEquationEntries();
|
||||
while (!(equationItem = equations.next()).done) {
|
||||
if (fileIDWhiteList && !fileIDWhiteList.has(equationItem.value[0])) {
|
||||
const eiValue = equationItem.value as [FileId, EquationItem];
|
||||
if (
|
||||
fileIDWhiteList &&
|
||||
!fileIDWhiteList.has(eiValue[0])
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
const equation = equationItem.value[1];
|
||||
const id = equationItem.value[0];
|
||||
const equation = eiValue[1];
|
||||
const id = eiValue[0];
|
||||
yield createSafeLoadTask(
|
||||
async () => {
|
||||
if (this.terminate) {
|
||||
@@ -972,6 +1012,9 @@ export class EmbeddedFilesLoader {
|
||||
if (!excalidrawData.getEquation(id).isLoaded) {
|
||||
const latex = equation.latex;
|
||||
const data = await tex2dataURL(latex, 4, this.plugin);
|
||||
if (this.terminate) {
|
||||
return null;
|
||||
}
|
||||
if (data) {
|
||||
const fileData = {
|
||||
mimeType: data.mimeType,
|
||||
@@ -1008,7 +1051,7 @@ export class EmbeddedFilesLoader {
|
||||
const result = await mermaidToExcalidraw(data, {
|
||||
themeVariables: { fontSize: "20" },
|
||||
});
|
||||
if (!result) {
|
||||
if (!result || this.terminate) {
|
||||
return;
|
||||
}
|
||||
if (result?.files) {
|
||||
@@ -1020,7 +1063,7 @@ export class EmbeddedFilesLoader {
|
||||
hasSVGwithBitmap: false,
|
||||
shouldScale: true,
|
||||
size: await getImageSize(result.files[key].dataURL),
|
||||
};
|
||||
} as FileData;
|
||||
files[batch].push(fileData);
|
||||
}
|
||||
return;
|
||||
@@ -1038,6 +1081,9 @@ export class EmbeddedFilesLoader {
|
||||
hasSVGwithBitmap: false,
|
||||
elements: result.elements,
|
||||
});
|
||||
if (this.terminate) {
|
||||
return;
|
||||
}
|
||||
if (res?.dataURL) {
|
||||
const size = await getImageSize(res.dataURL);
|
||||
const fileData: FileData = {
|
||||
@@ -1328,6 +1374,9 @@ export class EmbeddedFilesLoader {
|
||||
};
|
||||
|
||||
const canvas = await renderPage(pageNum);
|
||||
if (this.terminate) {
|
||||
return [null, null, null, null, false];
|
||||
}
|
||||
if (canvas) {
|
||||
const blob = await new Promise<Blob>((resolve, reject) => {
|
||||
canvas.toBlob((pngBlob) => {
|
||||
@@ -1368,10 +1417,16 @@ export class EmbeddedFilesLoader {
|
||||
file: TFile,
|
||||
linkParts: LinkParts,
|
||||
): Promise<{ dataURL: DataURL; hasSVGwithBitmap: boolean }> {
|
||||
if (this.terminate) {
|
||||
return { dataURL: "" as DataURL, hasSVGwithBitmap: false };
|
||||
}
|
||||
//1.
|
||||
//get the markdown text
|
||||
let hasSVGwithBitmap = false;
|
||||
const transclusion = await getTransclusion(linkParts, plugin.app, file);
|
||||
if (this.terminate) {
|
||||
return { dataURL: "" as DataURL, hasSVGwithBitmap: false };
|
||||
}
|
||||
let text = (transclusion.leadingHashes ?? "") + transclusion.contents;
|
||||
if (text === "") {
|
||||
text =
|
||||
@@ -1499,25 +1554,37 @@ export class EmbeddedFilesLoader {
|
||||
|
||||
const renderComponent = new Component();
|
||||
renderComponent.load();
|
||||
//await MarkdownRenderer.renderMarkdown(text, mdDIV, file.path, plugin);
|
||||
await MarkdownRenderer.render(
|
||||
this.plugin.app,
|
||||
text,
|
||||
mdDIV,
|
||||
file.path,
|
||||
renderComponent,
|
||||
);
|
||||
renderComponent.unload();
|
||||
try {
|
||||
//await MarkdownRenderer.renderMarkdown(text, mdDIV, file.path, plugin);
|
||||
await MarkdownRenderer.render(
|
||||
this.plugin.app,
|
||||
text,
|
||||
mdDIV,
|
||||
file.path,
|
||||
renderComponent,
|
||||
);
|
||||
} finally {
|
||||
renderComponent.unload();
|
||||
}
|
||||
if (this.terminate) {
|
||||
return { dataURL: "" as DataURL, hasSVGwithBitmap: false };
|
||||
}
|
||||
|
||||
mdDIV
|
||||
.querySelectorAll(":scope > *[class^='frontmatter']")
|
||||
.forEach((el) => mdDIV.removeChild(el));
|
||||
|
||||
await replaceBlobWithBase64(mdDIV); //because image cache returns a blob
|
||||
if (this.terminate) {
|
||||
return { dataURL: "" as DataURL, hasSVGwithBitmap: false };
|
||||
}
|
||||
const internalEmbeds = Array.from(
|
||||
mdDIV.querySelectorAll("span[class='internal-embed']"),
|
||||
);
|
||||
for (let i = 0; i < internalEmbeds.length; i++) {
|
||||
if (this.terminate) {
|
||||
return { dataURL: "" as DataURL, hasSVGwithBitmap: false };
|
||||
}
|
||||
const el = internalEmbeds[i];
|
||||
const src = el.getAttribute("src");
|
||||
if (!src) {
|
||||
@@ -1531,6 +1598,9 @@ export class EmbeddedFilesLoader {
|
||||
continue;
|
||||
}
|
||||
const embeddedFile = await this._getObsidianImage(ef, 1);
|
||||
if (this.terminate) {
|
||||
return { dataURL: "" as DataURL, hasSVGwithBitmap: false };
|
||||
}
|
||||
const img = createEl("img");
|
||||
if (width) {
|
||||
img.setAttribute("width", width);
|
||||
@@ -1548,36 +1618,43 @@ export class EmbeddedFilesLoader {
|
||||
//blank styles into inline styles using computedStyle
|
||||
const iframeHost = mainDocument.body.createDiv();
|
||||
hideElement(iframeHost);
|
||||
const iframe = iframeHost.createEl("iframe");
|
||||
const iframeDoc = iframe.contentWindow.document;
|
||||
if (style) {
|
||||
const styleEl = iframeDoc.createElement("style");
|
||||
styleEl.type = "text/css";
|
||||
setStyleText(styleEl, style);
|
||||
iframeDoc.head.appendChild(styleEl);
|
||||
}
|
||||
const stylingDIV = iframeDoc.importNode(mdDIV, true);
|
||||
iframeDoc.body.appendChild(stylingDIV);
|
||||
const footerDIV = createDiv();
|
||||
footerDIV.setAttribute("class", "excalidraw-md-footer");
|
||||
iframeDoc.body.appendChild(footerDIV);
|
||||
|
||||
iframeDoc.body.querySelectorAll("*").forEach((el: HTMLElement) => {
|
||||
const elementStyle = el.style;
|
||||
const computedStyle = window.getComputedStyle(el);
|
||||
let style = "";
|
||||
for (const [prop] of Object.entries(elementStyle)) {
|
||||
if (Object.hasOwn(elementStyle ?? {}, prop)) {
|
||||
const value = computedStyle.getPropertyValue(prop);
|
||||
style += `${prop}: ${value};`;
|
||||
}
|
||||
let xmlINiframe = "";
|
||||
let xmlFooter = "";
|
||||
try {
|
||||
const iframe = iframeHost.createEl("iframe");
|
||||
const iframeDoc = iframe.contentWindow.document;
|
||||
if (style) {
|
||||
const styleEl = iframeDoc.createElement("style");
|
||||
styleEl.type = "text/css";
|
||||
setStyleText(styleEl, style);
|
||||
iframeDoc.head.appendChild(styleEl);
|
||||
}
|
||||
el.setAttribute("style", style);
|
||||
});
|
||||
const stylingDIV = iframeDoc.importNode(mdDIV, true);
|
||||
iframeDoc.body.appendChild(stylingDIV);
|
||||
const footerDIV = createDiv();
|
||||
footerDIV.setAttribute("class", "excalidraw-md-footer");
|
||||
iframeDoc.body.appendChild(footerDIV);
|
||||
|
||||
const xmlINiframe = new XMLSerializer().serializeToString(stylingDIV);
|
||||
const xmlFooter = new XMLSerializer().serializeToString(footerDIV);
|
||||
mainDocument.body.removeChild(iframeHost);
|
||||
iframeDoc.body.querySelectorAll("*").forEach((el: HTMLElement) => {
|
||||
const elementStyle = el.style;
|
||||
const computedStyle = window.getComputedStyle(el);
|
||||
let style = "";
|
||||
for (const [prop] of Object.entries(elementStyle)) {
|
||||
if (Object.hasOwn(elementStyle ?? {}, prop)) {
|
||||
const value = computedStyle.getPropertyValue(prop);
|
||||
style += `${prop}: ${value};`;
|
||||
}
|
||||
}
|
||||
el.setAttribute("style", style);
|
||||
});
|
||||
|
||||
xmlINiframe = new XMLSerializer().serializeToString(stylingDIV);
|
||||
xmlFooter = new XMLSerializer().serializeToString(footerDIV);
|
||||
} finally {
|
||||
if (iframeHost.parentElement) {
|
||||
mainDocument.body.removeChild(iframeHost);
|
||||
}
|
||||
}
|
||||
|
||||
//5.2
|
||||
//get SVG size
|
||||
@@ -1588,15 +1665,20 @@ export class EmbeddedFilesLoader {
|
||||
);
|
||||
const svgEl = doc.firstElementChild;
|
||||
const host = createDiv();
|
||||
host.appendChild(svgEl);
|
||||
mainDocument.body.appendChild(host);
|
||||
const footerHeight = svgEl.querySelector(
|
||||
".excalidraw-md-footer",
|
||||
).scrollHeight;
|
||||
const height =
|
||||
svgEl.querySelector(".excalidraw-md-host").scrollHeight + footerHeight;
|
||||
const svgHeight = height <= linkParts.height ? height : linkParts.height;
|
||||
mainDocument.body.removeChild(host);
|
||||
let svgHeight = 0;
|
||||
let footerHeight = 0;
|
||||
try {
|
||||
host.appendChild(svgEl);
|
||||
mainDocument.body.appendChild(host);
|
||||
footerHeight = svgEl.querySelector(".excalidraw-md-footer").scrollHeight;
|
||||
const height =
|
||||
svgEl.querySelector(".excalidraw-md-host").scrollHeight + footerHeight;
|
||||
svgHeight = height <= linkParts.height ? height : linkParts.height;
|
||||
} finally {
|
||||
if (host.parentElement) {
|
||||
mainDocument.body.removeChild(host);
|
||||
}
|
||||
}
|
||||
|
||||
//finalize SVG
|
||||
svgStyle = ` width="${linkParts.width}px" height="${svgHeight}px"`;
|
||||
|
||||
@@ -160,6 +160,7 @@ import {
|
||||
ensureActiveScriptSettingsObject,
|
||||
errorMessage,
|
||||
filterColorMap,
|
||||
getAppStateStrokeWidthEntry,
|
||||
getEmbeddedFileForImageElment,
|
||||
getLineBox,
|
||||
getTemplate,
|
||||
@@ -1446,8 +1447,10 @@ export class ExcalidrawAutomate {
|
||||
this.style.backgroundColor,
|
||||
currentItemFillStyle:
|
||||
templateAppstate.currentItemFillStyle ?? this.style.fillStyle,
|
||||
currentItemStrokeWidth:
|
||||
...getAppStateStrokeWidthEntry(
|
||||
templateAppstate.currentItemStrokeWidthKey,
|
||||
templateAppstate.currentItemStrokeWidth ?? this.style.strokeWidth,
|
||||
),
|
||||
currentItemStrokeStyle:
|
||||
templateAppstate.currentItemStrokeStyle ?? this.style.strokeStyle,
|
||||
currentItemRoughness:
|
||||
@@ -4838,6 +4841,10 @@ export class ExcalidrawAutomate {
|
||||
getPolyBool(): typeof PolyBool {
|
||||
const defaultEpsilon = 0.0000000001;
|
||||
PolyBool.epsilon(defaultEpsilon);
|
||||
|
||||
if ("buildLog" in PolyBool) {
|
||||
PolyBool.buildLog(false);
|
||||
}
|
||||
return PolyBool;
|
||||
}
|
||||
|
||||
|
||||
@@ -500,6 +500,9 @@ export const getExcalidrawMarkdownHeaderSection = (
|
||||
: `${header}\n`;
|
||||
};
|
||||
|
||||
export type EquationItem = { latex: string; isLoaded: boolean };
|
||||
export type MermaidItem = { mermaid: string; isLoaded: boolean };
|
||||
|
||||
export class ExcalidrawData {
|
||||
public textElements: Map<
|
||||
string,
|
||||
@@ -519,8 +522,8 @@ export class ExcalidrawData {
|
||||
public loaded: boolean = false;
|
||||
public elementLinks: Map<string, string> = null;
|
||||
public files: Map<FileId, EmbeddedFile> = null; //fileId, path
|
||||
private equations: Map<FileId, { latex: string; isLoaded: boolean }> = null; //fileId, path
|
||||
private mermaids: Map<FileId, { mermaid: string; isLoaded: boolean }> = null; //fileId, path
|
||||
private equations: Map<FileId, EquationItem> = null; //fileId, path
|
||||
private mermaids: Map<FileId, MermaidItem> = null; //fileId, path
|
||||
private compatibilityMode: boolean = false;
|
||||
private textElementCommentedOut: boolean = false;
|
||||
selectedElementIds: { [key: string]: boolean } = {}; //https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/609
|
||||
@@ -531,8 +534,8 @@ export class ExcalidrawData {
|
||||
) {
|
||||
this.app = this.plugin.app;
|
||||
this.files = new Map<FileId, EmbeddedFile>();
|
||||
this.equations = new Map<FileId, { latex: string; isLoaded: boolean }>();
|
||||
this.mermaids = new Map<FileId, { mermaid: string; isLoaded: boolean }>();
|
||||
this.equations = new Map<FileId, EquationItem>();
|
||||
this.mermaids = new Map<FileId, MermaidItem>();
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
@@ -768,8 +771,11 @@ export class ExcalidrawData {
|
||||
.forEach((textEl: Mutable<ExcalidrawTextElement>) => {
|
||||
textEl.containerId = null;
|
||||
}); // log({message:"cleanup",textEl})});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
} catch (error: unknown) {
|
||||
errorlog({
|
||||
message: "unexpected error in loadData",
|
||||
error,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import ExcalidrawPlugin from "src/core/main";
|
||||
|
||||
export class GlobalTaskQueue {
|
||||
private queue: {
|
||||
task: () => Promise<void>;
|
||||
resolve: (value: void | PromiseLike<void>) => void;
|
||||
reject: (err: unknown) => void;
|
||||
}[] = [];
|
||||
private activeCount = 0;
|
||||
|
||||
constructor(private plugin: ExcalidrawPlugin) {}
|
||||
|
||||
public async addTask(task: () => Promise<void>): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.queue.push({ task, resolve, reject });
|
||||
void this.processNext();
|
||||
});
|
||||
}
|
||||
|
||||
private async processNext() {
|
||||
const concurrencyLimit = this.plugin?.settings?.renderingConcurrency ?? 4;
|
||||
if (this.activeCount >= concurrencyLimit || this.queue.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.activeCount++;
|
||||
const { task, resolve, reject } = this.queue.shift();
|
||||
|
||||
try {
|
||||
await task();
|
||||
resolve();
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
} finally {
|
||||
this.activeCount--;
|
||||
void this.processNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let globalTaskQueue: GlobalTaskQueue = null;
|
||||
|
||||
export const getGlobalTaskQueue = (
|
||||
plugin: ExcalidrawPlugin,
|
||||
): GlobalTaskQueue => {
|
||||
if (!globalTaskQueue) {
|
||||
globalTaskQueue = new GlobalTaskQueue(plugin);
|
||||
}
|
||||
return globalTaskQueue;
|
||||
};
|
||||
Vendored
+1
@@ -1,6 +1,7 @@
|
||||
declare module "polybooljs" {
|
||||
interface PolyBoolStatic {
|
||||
epsilon(value: number): void;
|
||||
buildLog(value: boolean): void;
|
||||
}
|
||||
|
||||
const PolyBool: PolyBoolStatic;
|
||||
|
||||
Vendored
+1
@@ -203,6 +203,7 @@ declare module "obsidian" {
|
||||
}
|
||||
interface Vault {
|
||||
getAbstractFileByPathInsensitive(path: string): TAbstractFile | null;
|
||||
getConfig(name: string): unknown;
|
||||
}
|
||||
interface FileView {
|
||||
_loaded: boolean;
|
||||
|
||||
@@ -13,7 +13,7 @@ const REQUIRED_EXTRAS_VERSIONS: Record<
|
||||
string,
|
||||
{ min?: string; exact?: string }
|
||||
> = {
|
||||
plugin: { min: "0.0.13" },
|
||||
plugin: { min: "0.0.14" },
|
||||
mathjax: { min: "1.0.0" },
|
||||
mermaid: { exact: "2.2.2" },
|
||||
pdf: { min: "1.0.0" },
|
||||
|
||||
@@ -14,6 +14,7 @@ export const setDynamicStyle = (
|
||||
dynamicStyle: DynamicStyle,
|
||||
textBackgroundColor?: string,
|
||||
) => {
|
||||
color = color ?? "white";
|
||||
if (dynamicStyle === "none") {
|
||||
//view.excalidrawContainer?.removeAttribute("style");
|
||||
window.setTimeout(() =>
|
||||
@@ -24,7 +25,8 @@ export const setDynamicStyle = (
|
||||
);
|
||||
const toolspanel = view.toolsPanelRef?.current?.containerRef?.current;
|
||||
if (toolspanel) {
|
||||
let toolsStyle = toolspanel.getAttribute("style");
|
||||
//https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/2810
|
||||
let toolsStyle = toolspanel.getAttribute("style") ?? "";
|
||||
toolsStyle = toolsStyle.replace(/--color-primary.*/, "");
|
||||
toolspanel.setAttribute("style", toolsStyle);
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ import {
|
||||
import { ScriptEngine } from "src/shared/Scripts";
|
||||
import { ColorMap, FileData } from "src/types/embeddedFileLoaderTypes";
|
||||
import { ExportSettings } from "src/types/exportUtilTypes";
|
||||
import type { StrokeWidthKey } from "@zsviczian/excalidraw/types/common/src/constants";
|
||||
|
||||
declare const PLUGIN_VERSION: string;
|
||||
|
||||
@@ -1108,3 +1109,62 @@ export function ensureActiveScriptSettingsObject(
|
||||
ScriptSettingValue
|
||||
>;
|
||||
}
|
||||
|
||||
export const getStrokeKeyFormLegacyWidth = (
|
||||
strokeWidth: number,
|
||||
): StrokeWidthKey => {
|
||||
switch (strokeWidth) {
|
||||
case 0.5:
|
||||
return "thin";
|
||||
case 1:
|
||||
return "medium";
|
||||
case 2:
|
||||
return "bold";
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
// Returns an appState key for the stroke width
|
||||
// excalidraw.com deprected and removed currentItemStrokeWidth from appState
|
||||
// but the plugin still supports it to allow custom line width settings for scripts and custom pens
|
||||
// if the legacy stroke width is provided, it will be converted to the corresponding stroke width key
|
||||
// if there is a matching key, the key will be preferred over the legacy stroke width value
|
||||
// if there is no matching key, the legacy stroke width value will be used
|
||||
export const getAppStateStrokeWidthEntry = (
|
||||
strokeWidthKey: StrokeWidthKey,
|
||||
legacyStrokeWidth: number,
|
||||
) => {
|
||||
if (legacyStrokeWidth !== undefined) {
|
||||
strokeWidthKey = getStrokeKeyFormLegacyWidth(legacyStrokeWidth);
|
||||
}
|
||||
if (!!legacyStrokeWidth && !strokeWidthKey) {
|
||||
return { currentItemStrokeWidth: legacyStrokeWidth };
|
||||
}
|
||||
if (!strokeWidthKey) {
|
||||
return {};
|
||||
}
|
||||
return { currentItemStrokeWidthKey: strokeWidthKey };
|
||||
};
|
||||
|
||||
//replicated from excalidraw constants.ts
|
||||
const FREEDRAW_STROKE_WIDTH: Readonly<
|
||||
Record<StrokeWidthKey | "extraBold", ExcalidrawElement["strokeWidth"]>
|
||||
> = {
|
||||
extraThin: 0.25,
|
||||
thin: 0.5,
|
||||
medium: 1,
|
||||
bold: 2,
|
||||
extraBold: 4, // legacy (may be used again in the future)
|
||||
};
|
||||
|
||||
//based on excalidraw constants.ts getStrokeWidthByKey
|
||||
export const getFreedrawStrokeWidthByKey = (
|
||||
strokeWidthKey: StrokeWidthKey,
|
||||
strokeWidth?: number,
|
||||
): ExcalidrawElement["strokeWidth"] => {
|
||||
if (strokeWidth) {
|
||||
return strokeWidth;
|
||||
}
|
||||
return FREEDRAW_STROKE_WIDTH[strokeWidthKey];
|
||||
};
|
||||
@@ -18,6 +18,7 @@ import { linkClickModifierType, ModifierKeys } from "./modifierkeyHelper";
|
||||
import {
|
||||
DEVICE,
|
||||
EXCALIDRAW_PLUGIN,
|
||||
FRONTMATTER_KEYS,
|
||||
mainDocument,
|
||||
VIEW_TYPE_EXCALIDRAW,
|
||||
} from "src/constants/constants";
|
||||
@@ -321,7 +322,9 @@ export const getFileCSSClasses = (file: TFile): string[] => {
|
||||
if (!fileCache?.frontmatter) {
|
||||
return [];
|
||||
}
|
||||
const x = parseFrontMatterEntry(fileCache.frontmatter, "cssclasses");
|
||||
const x = parseFrontMatterEntry(fileCache.frontmatter, "cssclasses") as
|
||||
| string
|
||||
| string[];
|
||||
if (Array.isArray(x)) {
|
||||
return x;
|
||||
}
|
||||
@@ -381,8 +384,8 @@ export function mergeMarkdownFiles(template: string, target: string): string {
|
||||
.substring(4, templateFrontmatterEnd)
|
||||
.trim();
|
||||
const templateContent = template.substring(templateFrontmatterEnd + 3);
|
||||
const templateFrontmatterObj: FrontMatterCache =
|
||||
parse(templateFrontmatterRaw) || {};
|
||||
const templateFrontmatterObj = (parse(templateFrontmatterRaw) ||
|
||||
{}) as FrontMatterCache;
|
||||
|
||||
const hasTargetFM =
|
||||
target.startsWith("---\n") && target.indexOf("---\n", 4) > 0;
|
||||
@@ -393,8 +396,9 @@ export function mergeMarkdownFiles(template: string, target: string): string {
|
||||
.replace(/\s+$/, ""); // keep as-is
|
||||
const targetContent = target.substring(targetFrontmatterEnd + 3);
|
||||
|
||||
const targetFrontmatterObj: FrontMatterCache =
|
||||
parse(targetFrontmatterRaw) || {};
|
||||
const targetFrontmatterObj: FrontMatterCache = (parse(
|
||||
targetFrontmatterRaw,
|
||||
) || {}) as FrontMatterCache;
|
||||
|
||||
// 1. Merge array keys present in both (target has precedence for ordering)
|
||||
const mergeArrayKeys = Object.keys(templateFrontmatterObj).filter(
|
||||
@@ -662,3 +666,29 @@ export function strictArrayBuffer(
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// 1. Map your custom 'type' strings to actual TypeScript types
|
||||
type FrontmatterTypeMap = {
|
||||
text: string;
|
||||
checkbox: boolean;
|
||||
number: number;
|
||||
};
|
||||
|
||||
// 2. Automatically infer the shape of your valid frontmatter keys from the object
|
||||
type FrontmatterValueType<T extends keyof typeof FRONTMATTER_KEYS> =
|
||||
FrontmatterTypeMap[(typeof FRONTMATTER_KEYS)[T]["type"]];
|
||||
|
||||
// 3. Construct a fully typed Record where keys are the true names (e.g., "excalidraw-open-md")
|
||||
export type ValidFrontmatter = {
|
||||
[K in keyof typeof FRONTMATTER_KEYS as (typeof FRONTMATTER_KEYS)[K]["name"]]?: FrontmatterValueType<K>;
|
||||
};
|
||||
|
||||
// 4. Create a reusable type guard function
|
||||
export function getSafeFrontmatter(frontmatter: unknown): ValidFrontmatter {
|
||||
if (typeof frontmatter !== "object" || frontmatter === null) {
|
||||
return {};
|
||||
}
|
||||
|
||||
// Cast safely inside the boundary helper function
|
||||
return frontmatter;
|
||||
}
|
||||
@@ -32,7 +32,7 @@ type StyleObject = Partial<CSSStyleDeclaration> & {
|
||||
};
|
||||
|
||||
export const setStyle = (
|
||||
element: HTMLElement | SVGSVGElement | null | undefined,
|
||||
element: HTMLElement | SVGElement | null | undefined,
|
||||
styles: StyleObject,
|
||||
): void => {
|
||||
if (!element) {
|
||||
|
||||
@@ -267,6 +267,7 @@ import {
|
||||
getFrameElementsMatchingQuery,
|
||||
getElementsWithLinkMatchingQuery,
|
||||
getImagesMatchingQuery,
|
||||
getAppStateStrokeWidthEntry,
|
||||
} from "src/utils/excalidrawAutomateUtils";
|
||||
import { getYouTubeUrl, URLs } from "src/constants/safeUrls";
|
||||
import { setStyle } from "src/utils/styleUtils";
|
||||
@@ -479,6 +480,7 @@ export default class ExcalidrawView
|
||||
private previousSceneVersion = 0;
|
||||
public previousBackgroundColor = "";
|
||||
public previousTheme = "";
|
||||
private pendingUIMode: UIMode | null = null;
|
||||
|
||||
//variables used to handle click events in view mode
|
||||
private selectedTextElement: SelectedElementWithLink | null = null;
|
||||
@@ -1674,6 +1676,9 @@ export default class ExcalidrawView
|
||||
}
|
||||
|
||||
exitFullscreen() {
|
||||
if (!this.isFullscreen()) {
|
||||
return;
|
||||
}
|
||||
if (this.toolsPanelRef && this.toolsPanelRef.current) {
|
||||
this.toolsPanelRef.current.setFullscreen(false);
|
||||
}
|
||||
@@ -2731,6 +2736,8 @@ export default class ExcalidrawView
|
||||
//I noticed Obsidian calls this function twice when disabling the plugin
|
||||
//once from "unregisterView"
|
||||
//the from "detachLeavesOfType"
|
||||
this.clearPreventReloadTimer();
|
||||
this.clearEmbeddableNodeIsEditingTimer();
|
||||
if (!this.dropManager && !this.excalidrawRoot) {
|
||||
return;
|
||||
} //the view is already closed
|
||||
@@ -2750,8 +2757,6 @@ export default class ExcalidrawView
|
||||
this.excalidrawRoot = null;
|
||||
}
|
||||
|
||||
this.clearPreventReloadTimer();
|
||||
this.clearEmbeddableNodeIsEditingTimer();
|
||||
this.cancelDeferredSceneFileValidation();
|
||||
if (this.activeLoader) {
|
||||
this.activeLoader.terminate = true;
|
||||
@@ -3235,11 +3240,16 @@ export default class ExcalidrawView
|
||||
this.cancelDeferredSceneFileValidation();
|
||||
if (this.activeLoader) {
|
||||
this.activeLoader.terminate = true;
|
||||
this.activeLoader.emptyPDFDocsMap();
|
||||
this.activeLoader = null;
|
||||
}
|
||||
this.nextLoader = null;
|
||||
if (this.nextLoader) {
|
||||
this.nextLoader.terminate = true;
|
||||
this.nextLoader.emptyPDFDocsMap();
|
||||
this.nextLoader = null;
|
||||
}
|
||||
this.lastSceneLoadTime = 0;
|
||||
api.resetScene();
|
||||
(api.resetScene as () => void)();
|
||||
this.previousSceneVersion = 0;
|
||||
}
|
||||
|
||||
@@ -5016,7 +5026,11 @@ export default class ExcalidrawView
|
||||
currentItemStrokeColor: st.currentItemStrokeColor,
|
||||
currentItemBackgroundColor: st.currentItemBackgroundColor,
|
||||
currentItemFillStyle: st.currentItemFillStyle,
|
||||
currentItemStrokeWidth: st.currentItemStrokeWidth,
|
||||
...getAppStateStrokeWidthEntry(
|
||||
st.currentItemStrokeWidthKey,
|
||||
st.currentItemStrokeWidth,
|
||||
),
|
||||
currentItemStrokeVariability: st.currentItemStrokeVariability,
|
||||
currentItemStrokeStyle: st.currentItemStrokeStyle,
|
||||
currentItemRoughness: st.currentItemRoughness,
|
||||
currentItemOpacity: st.currentItemOpacity,
|
||||
@@ -7139,8 +7153,14 @@ export default class ExcalidrawView
|
||||
this.exportDialog.open();
|
||||
}
|
||||
|
||||
private setExcalidrawAPI(api: ExcalidrawImperativeAPI) {
|
||||
private setExcalidrawAPI(api: ExcalidrawImperativeAPI | null) {
|
||||
this.excalidrawAPI = api;
|
||||
// Chasing ghosts: https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/2810
|
||||
if (!api || this.pendingUIMode === null) {
|
||||
return;
|
||||
}
|
||||
api.setDesktopUIMode(this.pendingUIMode);
|
||||
this.pendingUIMode = null;
|
||||
//api.setLocalFont(this.plugin.settings.experimentalEnableFourthFont);
|
||||
}
|
||||
|
||||
@@ -8046,7 +8066,12 @@ export default class ExcalidrawView
|
||||
|
||||
public setUIMode(mode: UIMode) {
|
||||
const api = this.excalidrawAPI;
|
||||
if (!api) {
|
||||
this.pendingUIMode = mode;
|
||||
return;
|
||||
}
|
||||
api.setDesktopUIMode(mode);
|
||||
this.pendingUIMode = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -552,7 +552,7 @@ function RenderObsidianView({
|
||||
canvasColor: string;
|
||||
selectedElementId: string;
|
||||
sceneZoom: number;
|
||||
}): JSX.Element {
|
||||
}): React.JSX.Element {
|
||||
const { subpath, file } = processLinkText(linkText, view);
|
||||
|
||||
if (!file) {
|
||||
@@ -572,12 +572,20 @@ function RenderObsidianView({
|
||||
const pdfObserverDisabledRef = React.useRef(false);
|
||||
const mobilePatchCleanupRef = React.useRef(null);
|
||||
const initialViewFileRef = React.useRef(view.file);
|
||||
const mdPropsRef = React.useRef(mdProps);
|
||||
const fileRef = React.useRef(file);
|
||||
const prevLockRef = React.useRef(mdProps?.lockedReadingMode);
|
||||
|
||||
// Update themeRef when theme changes
|
||||
React.useEffect(() => {
|
||||
themeRef.current = theme;
|
||||
}, [theme]);
|
||||
|
||||
React.useEffect(() => {
|
||||
mdPropsRef.current = mdProps;
|
||||
fileRef.current = file;
|
||||
}, [mdProps, file]);
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
//block propagation of events to the parent if the embeddable element is active
|
||||
//--------------------------------------------------------------------------------
|
||||
@@ -590,6 +598,104 @@ function RenderObsidianView({
|
||||
[isActiveRef.current],
|
||||
);
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// Handle hiding properties dynamically in both the host container and the editing iframe
|
||||
//--------------------------------------------------------------------------------
|
||||
React.useEffect(() => {
|
||||
if (!containerRef.current || file.extension !== "md") {
|
||||
return;
|
||||
}
|
||||
|
||||
const isPropertiesVisible =
|
||||
mdProps?.propertiesVisible !== false || mdProps?.useObsidianDefaults;
|
||||
|
||||
const hostStyleId = `excalidraw-hide-properties-style-host-${element.id}`;
|
||||
let hostStyle = containerRef.current.querySelector(`#${hostStyleId}`);
|
||||
|
||||
if (!isPropertiesVisible) {
|
||||
if (!hostStyle) {
|
||||
hostStyle = view.ownerDocument.createElement("style");
|
||||
hostStyle.id = hostStyleId;
|
||||
hostStyle.textContent = `
|
||||
#embed-${element.id} .metadata-container { display: none; }
|
||||
#embed-${element.id} .cm-line:has(.cm-hmd-frontmatter) { display: none; }
|
||||
`;
|
||||
containerRef.current.appendChild(hostStyle);
|
||||
}
|
||||
} else {
|
||||
if (hostStyle) {
|
||||
hostStyle.remove();
|
||||
}
|
||||
}
|
||||
|
||||
const updateIframe = () => {
|
||||
const iframe: HTMLIFrameElement = containerRef.current?.querySelector(
|
||||
"iframe.embed-iframe",
|
||||
);
|
||||
if (iframe && iframe.contentDocument && iframe.contentDocument.head) {
|
||||
const iframeStyleId = "excalidraw-hide-properties-style-iframe";
|
||||
let iframeStyle = iframe.contentDocument.getElementById(iframeStyleId);
|
||||
if (!isPropertiesVisible) {
|
||||
if (!iframeStyle) {
|
||||
iframeStyle = iframe.contentDocument.createElement("style");
|
||||
iframeStyle.id = iframeStyleId;
|
||||
iframeStyle.textContent = `
|
||||
.metadata-container { display: none !important; }
|
||||
.cm-line:has(.cm-hmd-frontmatter) { display: none !important; }
|
||||
`;
|
||||
iframe.contentDocument.head.appendChild(iframeStyle);
|
||||
}
|
||||
} else {
|
||||
if (iframeStyle) {
|
||||
iframeStyle.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Run immediately just in case the iframe is already present
|
||||
updateIframe();
|
||||
|
||||
let iframeLoadHandler: () => void;
|
||||
|
||||
// Observe changes so when Obsidian mounts the editor iframe we style it immediately
|
||||
const mo = new MutationObserver((mutations) => {
|
||||
for (const mutation of mutations) {
|
||||
if (mutation.addedNodes.length > 0) {
|
||||
updateIframe();
|
||||
const iframe: HTMLIFrameElement = containerRef.current?.querySelector(
|
||||
"iframe.embed-iframe",
|
||||
);
|
||||
if (iframe) {
|
||||
if (iframeLoadHandler) {
|
||||
iframe.removeEventListener("load", iframeLoadHandler);
|
||||
}
|
||||
iframeLoadHandler = () => updateIframe();
|
||||
// Wait for the blank document inside to complete loading
|
||||
iframe.addEventListener("load", iframeLoadHandler, { once: true });
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
mo.observe(containerRef.current, { childList: true, subtree: true });
|
||||
|
||||
return () => {
|
||||
mo.disconnect();
|
||||
const iframe = containerRef.current?.querySelector("iframe.embed-iframe");
|
||||
if (iframe && iframeLoadHandler) {
|
||||
iframe.removeEventListener("load", iframeLoadHandler);
|
||||
}
|
||||
};
|
||||
}, [
|
||||
containerRef,
|
||||
mdProps?.propertiesVisible,
|
||||
mdProps?.useObsidianDefaults,
|
||||
element.id,
|
||||
file.extension,
|
||||
view.ownerDocument,
|
||||
]);
|
||||
|
||||
//runs once after mounting of the component and when the component is unmounted
|
||||
React.useEffect(() => {
|
||||
if (!containerRef?.current) {
|
||||
@@ -695,6 +801,22 @@ function RenderObsidianView({
|
||||
containerRef.current,
|
||||
element.id,
|
||||
);
|
||||
|
||||
// --- PATCH NATIVE OBSIDIAN CANVAS NODE ---
|
||||
// Obsidian's native canvas event listeners will force the node into edit mode
|
||||
// on certain clicks/double-clicks. This intercepts Obsidian's core method.
|
||||
const node = leafRef.current.node;
|
||||
if (node && typeof node.startEditing === "function") {
|
||||
const originalStartEditing = node.startEditing;
|
||||
node.startEditing = function (...args: unknown[]) {
|
||||
// Read directly from the ref to ensure dynamic lock toggling works
|
||||
if (mdPropsRef.current?.lockedReadingMode) {
|
||||
return;
|
||||
}
|
||||
return originalStartEditing.apply(this, args) as unknown;
|
||||
};
|
||||
}
|
||||
|
||||
setColors(containerRef.current, element, mdProps, canvasColor, viewType);
|
||||
view.updateEmbeddableLeafRef(element.id, leafRef.current);
|
||||
viewTypeRef.current = "markdown";
|
||||
@@ -1061,6 +1183,19 @@ function RenderObsidianView({
|
||||
return;
|
||||
}
|
||||
|
||||
const currentMdProps = mdPropsRef.current;
|
||||
const currentFile = fileRef.current;
|
||||
|
||||
if (currentMdProps?.lockedReadingMode) {
|
||||
// Special case: if the card is a back-of-the-note card, ticking a checkbox in
|
||||
// reading mode triggers a change to the open file which would result in a view update.
|
||||
if (currentFile?.path === view.file.path) {
|
||||
view.setPreventReload();
|
||||
void view.setEmbeddableNodeIsEditing();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*if(isActiveRef.current && leafRef.current?.leaf) {
|
||||
setKeepOnTop();
|
||||
view.app.workspace.setActiveLeaf(leafRef.current.leaf, { focus: true });
|
||||
@@ -1174,7 +1309,10 @@ function RenderObsidianView({
|
||||
activeEmbeddable?.element.id === element.id &&
|
||||
activeEmbeddable?.state === "active";
|
||||
|
||||
if (previousIsActive === isActiveRef.current) {
|
||||
const lockChanged = prevLockRef.current !== mdProps?.lockedReadingMode;
|
||||
prevLockRef.current = !!mdProps?.lockedReadingMode;
|
||||
|
||||
if (previousIsActive === isActiveRef.current && !lockChanged) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1190,13 +1328,21 @@ function RenderObsidianView({
|
||||
view.plugin.settings.markdownNodeOneClickEditing &&
|
||||
!containerRef.current?.hasClass("is-editing")
|
||||
) {
|
||||
//!node.isEditing
|
||||
const newTheme = getTheme(view, themeRef.current);
|
||||
containerRef.current?.addClasses(["is-editing", "is-focused"]);
|
||||
void view.canvasNodeFactory.startEditing(node, newTheme);
|
||||
if (mdPropsRef.current?.lockedReadingMode) {
|
||||
if (fileRef.current?.path === view.file.path) {
|
||||
view.setPreventReload();
|
||||
void view.setEmbeddableNodeIsEditing();
|
||||
}
|
||||
} else {
|
||||
//!node.isEditing
|
||||
const newTheme = getTheme(view, themeRef.current);
|
||||
containerRef.current?.addClasses(["is-editing", "is-focused"]);
|
||||
void view.canvasNodeFactory.startEditing(node, newTheme);
|
||||
}
|
||||
} else {
|
||||
containerRef.current?.removeClasses(["is-editing", "is-focused"]);
|
||||
view.canvasNodeFactory.stopEditing(node);
|
||||
view.clearEmbeddableNodeIsEditing();
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -1245,12 +1391,13 @@ function RenderObsidianView({
|
||||
activeEmbeddable?.state,
|
||||
isActiveRef,
|
||||
activeEmbeddable?.element,
|
||||
activeEmbeddable?.state,
|
||||
element,
|
||||
view,
|
||||
isEditingRef,
|
||||
view.canvasNodeFactory,
|
||||
themeRef.current,
|
||||
mdProps?.lockedReadingMode,
|
||||
file.path,
|
||||
]);
|
||||
|
||||
return null;
|
||||
@@ -1264,11 +1411,13 @@ export const CustomEmbeddable: React.FC<{
|
||||
}> = ({ element, view, appState, linkText }) => {
|
||||
const React = view.packages.react;
|
||||
const containerRef: React.RefObject<HTMLDivElement> = React.useRef(null);
|
||||
const theme = getTheme(view, appState.theme);
|
||||
const mdProps: EmbeddableMDCustomProps = element.customData?.mdProps || null;
|
||||
const theme = getTheme(view, appState.theme as string);
|
||||
const mdProps: EmbeddableMDCustomProps =
|
||||
(element.customData?.mdProps as EmbeddableMDCustomProps) || null;
|
||||
const selectedElementIds = Object.keys(appState.selectedElementIds);
|
||||
return (
|
||||
<div
|
||||
id={`embed-${element.id}`}
|
||||
ref={containerRef}
|
||||
style={{
|
||||
width: `100%`,
|
||||
@@ -1290,7 +1439,7 @@ export const CustomEmbeddable: React.FC<{
|
||||
view={view}
|
||||
containerRef={containerRef}
|
||||
activeEmbeddable={appState.activeEmbeddable}
|
||||
theme={appState.theme}
|
||||
theme={appState.theme as string}
|
||||
canvasColor={appState.viewBackgroundColor}
|
||||
selectedElementId={
|
||||
selectedElementIds.length === 1 ? selectedElementIds[0] : null
|
||||
|
||||
@@ -26,7 +26,10 @@ import {
|
||||
} from "src/utils/customEmbeddableUtils";
|
||||
import { getActivePDFPageNumberFromPDFView } from "src/utils/obsidianUtils";
|
||||
import { cleanSectionHeading } from "src/utils/pathUtils";
|
||||
import { EmbeddableSettings } from "src/shared/Dialogs/EmbeddableSettings";
|
||||
import {
|
||||
EmbeddableSettings,
|
||||
EmbeddableMDCustomProps,
|
||||
} from "src/shared/Dialogs/EmbeddableSettings";
|
||||
import {
|
||||
insertImageToView,
|
||||
openExternalLink,
|
||||
@@ -35,6 +38,7 @@ import { getEA } from "src/core";
|
||||
import { CaptureUpdateAction } from "src/constants/constants";
|
||||
import { URLs } from "src/constants/safeUrls";
|
||||
import { setStyle } from "src/utils/styleUtils";
|
||||
import { addAppendUpdateCustomData } from "src/utils/elementCustomDataUtils";
|
||||
|
||||
type BlockCacheEntry = Awaited<
|
||||
ReturnType<ExcalidrawView["app"]["metadataCache"]["blockCache"]["getForFile"]>
|
||||
@@ -109,7 +113,9 @@ export class EmbeddableMenu {
|
||||
const app = view.app;
|
||||
element = view.excalidrawAPI
|
||||
.getSceneElements()
|
||||
.find((e: ExcalidrawElement) => e.id === element.id);
|
||||
.find(
|
||||
(e: ExcalidrawElement) => e.id === element.id,
|
||||
) as ExcalidrawEmbeddableElement;
|
||||
if (!element) {
|
||||
return;
|
||||
}
|
||||
@@ -364,6 +370,86 @@ export class EmbeddableMenu {
|
||||
);
|
||||
}
|
||||
|
||||
private async actionTogglePropertiesVisible(
|
||||
element: ExcalidrawEmbeddableElement,
|
||||
) {
|
||||
if (!element) {
|
||||
return;
|
||||
}
|
||||
const mdProps =
|
||||
(element.customData?.mdProps as EmbeddableMDCustomProps) ??
|
||||
this.view.plugin.settings.embeddableMarkdownDefaults;
|
||||
const isVisible = mdProps.propertiesVisible !== false;
|
||||
mdProps.propertiesVisible = !isVisible;
|
||||
|
||||
const ea = getEA(this.view);
|
||||
ea.copyViewElementsToEAforEditing([element]);
|
||||
const eaEl = ea.getElement(element.id);
|
||||
addAppendUpdateCustomData(eaEl, { mdProps });
|
||||
await ea.addElementsToView();
|
||||
ea.destroy();
|
||||
|
||||
// Fetch the updated element reference from the scene
|
||||
const api = this.view.excalidrawAPI;
|
||||
const updatedElement = api
|
||||
.getSceneElements()
|
||||
.find(
|
||||
(e: ExcalidrawElement) => e.id === element.id,
|
||||
) as ExcalidrawEmbeddableElement;
|
||||
|
||||
// Force an appState update so the React menu component re-renders
|
||||
if (updatedElement) {
|
||||
this.view.updateScene({
|
||||
appState: {
|
||||
activeEmbeddable: {
|
||||
element: updatedElement,
|
||||
state: "active",
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private async actionToggleLockReadingMode(
|
||||
element: ExcalidrawEmbeddableElement,
|
||||
) {
|
||||
if (!element) {
|
||||
return;
|
||||
}
|
||||
const mdProps =
|
||||
(element.customData?.mdProps as EmbeddableMDCustomProps) ??
|
||||
this.view.plugin.settings.embeddableMarkdownDefaults;
|
||||
const isLocked = !!mdProps.lockedReadingMode;
|
||||
mdProps.lockedReadingMode = !isLocked;
|
||||
|
||||
const ea = getEA(this.view);
|
||||
ea.copyViewElementsToEAforEditing([element]);
|
||||
const eaEl = ea.getElement(element.id);
|
||||
addAppendUpdateCustomData(eaEl, mdProps);
|
||||
await ea.addElementsToView();
|
||||
ea.destroy();
|
||||
|
||||
// Fetch the updated element reference from the scene
|
||||
const api = this.view.excalidrawAPI;
|
||||
const updatedElement = api
|
||||
.getSceneElements()
|
||||
.find(
|
||||
(e: ExcalidrawElement) => e.id === element.id,
|
||||
) as ExcalidrawEmbeddableElement;
|
||||
|
||||
// Force an appState update so the React menu component re-renders
|
||||
if (updatedElement) {
|
||||
this.view.updateScene({
|
||||
appState: {
|
||||
activeEmbeddable: {
|
||||
element: updatedElement,
|
||||
state: "active",
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private actionProperties(element: ExcalidrawEmbeddableElement, file: TFile) {
|
||||
if (!element) {
|
||||
return;
|
||||
@@ -472,6 +558,13 @@ export class EmbeddableMenu {
|
||||
);
|
||||
const top = `${y - 2.5 * ROOTELEMENTSIZE - appState.offsetTop}px`;
|
||||
const left = `${x - appState.offsetLeft}px`;
|
||||
const mdProps =
|
||||
(element.customData?.mdProps as EmbeddableMDCustomProps) ??
|
||||
view.plugin.settings.embeddableMarkdownDefaults;
|
||||
const isLockedReadingMode = !!mdProps.lockedReadingMode;
|
||||
const isPropertiesVisible = mdProps.propertiesVisible !== false;
|
||||
const isGlobalPropertiesHidden =
|
||||
view.app.vault.getConfig("propertiesInDocument") === "hidden";
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -528,6 +621,37 @@ export class EmbeddableMenu {
|
||||
icon={ICONS.ZoomToBlock}
|
||||
/>
|
||||
)}
|
||||
{isMD &&
|
||||
!isExcalidrawFile &&
|
||||
!subpath &&
|
||||
!isGlobalPropertiesHidden && (
|
||||
<ActionButton
|
||||
key="TogglePropertiesVisible"
|
||||
title={
|
||||
isPropertiesVisible
|
||||
? t("HIDE_PROPERTIES")
|
||||
: t("SHOW_PROPERTIES")
|
||||
}
|
||||
action={() =>
|
||||
void this.actionTogglePropertiesVisible(element)
|
||||
}
|
||||
icon={
|
||||
isPropertiesVisible ? ICONS.File : ICONS.FileCodeCorner
|
||||
}
|
||||
/>
|
||||
)}
|
||||
{isMD && (
|
||||
<ActionButton
|
||||
key="LockReadingMode"
|
||||
title={
|
||||
isLockedReadingMode
|
||||
? t("UNLOCK_READING_MODE")
|
||||
: t("LOCK_READING_MODE")
|
||||
}
|
||||
action={() => void this.actionToggleLockReadingMode(element)}
|
||||
icon={isLockedReadingMode ? ICONS.Edit : ICONS.Read}
|
||||
/>
|
||||
)}
|
||||
<ActionButton
|
||||
key={"ZoomToElement"}
|
||||
title={t("ZOOM_TO_FIT")}
|
||||
@@ -570,9 +694,13 @@ export class EmbeddableMenu {
|
||||
}
|
||||
}
|
||||
if (isObsidianiFrame || isExcalidrawiFrame) {
|
||||
const iframe = isExcalidrawiFrame
|
||||
? api.getHTMLIFrameElement(element.id)
|
||||
: view.getEmbeddableElementById(element.id);
|
||||
const iframe = (
|
||||
isExcalidrawiFrame
|
||||
? (api.getHTMLIFrameElement as (id: string) => HTMLIFrameElement)(
|
||||
element.id,
|
||||
)
|
||||
: view.getEmbeddableElementById(element.id)
|
||||
) as HTMLIFrameElement;
|
||||
if (!iframe || !iframe.contentWindow) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -16,15 +16,33 @@ import { UniversalInsertFileModal } from "src/shared/Dialogs/UniversalInsertFile
|
||||
import { t } from "src/lang/helpers";
|
||||
import { getExcalidrawViews } from "src/utils/obsidianUtils";
|
||||
import { CaptureUpdateAction } from "src/constants/constants";
|
||||
import {
|
||||
getAppStateStrokeWidthEntry,
|
||||
getFreedrawStrokeWidthByKey,
|
||||
} from "src/utils/excalidrawAutomateUtils";
|
||||
|
||||
export function setPen(pen: PenStyle, api: ExcalidrawImperativeAPI) {
|
||||
const st = api.getAppState();
|
||||
const strokeWidthEntry =
|
||||
!pen.strokeWidth || pen.strokeWidth === 0
|
||||
? {}
|
||||
: getAppStateStrokeWidthEntry(undefined, pen.strokeWidth);
|
||||
const currentItemStrokeWidthKey =
|
||||
"currentItemStrokeWidthKey" in strokeWidthEntry
|
||||
? strokeWidthEntry.currentItemStrokeWidthKey
|
||||
: null;
|
||||
const currentItemStrokeWidth =
|
||||
"currentItemStrokeWidth" in strokeWidthEntry
|
||||
? strokeWidthEntry.currentItemStrokeWidth
|
||||
: null;
|
||||
api.updateScene({
|
||||
appState: {
|
||||
currentStrokeOptions: pen.penOptions,
|
||||
...(!pen.strokeWidth || pen.strokeWidth === 0
|
||||
? null
|
||||
: { currentItemStrokeWidth: pen.strokeWidth }),
|
||||
currentItemStrokeWidthKey,
|
||||
currentItemStrokeWidth,
|
||||
currentItemStrokeVariability: pen.penOptions.constantPressure
|
||||
? "constant"
|
||||
: "variable",
|
||||
...(pen.backgroundColor
|
||||
? { currentItemBackgroundColor: pen.backgroundColor }
|
||||
: null),
|
||||
@@ -38,7 +56,9 @@ export function setPen(pen: PenStyle, api: ExcalidrawImperativeAPI) {
|
||||
...(pen.freedrawOnly && !st.resetCustomPen //switching from custom pen to next custom pen
|
||||
? {
|
||||
resetCustomPen: {
|
||||
currentItemStrokeWidthKey: st.currentItemStrokeWidthKey,
|
||||
currentItemStrokeWidth: st.currentItemStrokeWidth,
|
||||
currentItemStrokeVariability: st.currentItemStrokeVariability,
|
||||
currentItemBackgroundColor: st.currentItemBackgroundColor,
|
||||
currentItemStrokeColor: st.currentItemStrokeColor,
|
||||
currentItemFillStyle: st.currentItemFillStyle,
|
||||
@@ -56,16 +76,20 @@ export function resetStrokeOptions(
|
||||
api: ExcalidrawImperativeAPI,
|
||||
clearCurrentStrokeOptions: boolean,
|
||||
) {
|
||||
const appState = api.getAppState();
|
||||
api.updateScene({
|
||||
appState: {
|
||||
...(resetCustomPen
|
||||
? {
|
||||
currentItemStrokeWidthKey: resetCustomPen.currentItemStrokeWidthKey,
|
||||
currentItemStrokeWidth: resetCustomPen.currentItemStrokeWidth,
|
||||
currentItemBackgroundColor:
|
||||
resetCustomPen.currentItemBackgroundColor,
|
||||
currentItemStrokeColor: resetCustomPen.currentItemStrokeColor,
|
||||
currentItemFillStyle: resetCustomPen.currentItemFillStyle,
|
||||
currentItemRoughness: resetCustomPen.currentItemRoughness,
|
||||
currentItemStrokeVariability:
|
||||
resetCustomPen.currentItemStrokeVariability,
|
||||
}
|
||||
: null),
|
||||
resetCustomPen: null,
|
||||
@@ -234,7 +258,10 @@ export class ObsidianMenu {
|
||||
pen.freedrawOnly
|
||||
) {
|
||||
const activePen = this.activePens[index] ?? { ...pen };
|
||||
activePen.strokeWidth = appState.currentItemStrokeWidth;
|
||||
activePen.strokeWidth = getFreedrawStrokeWidthByKey(
|
||||
appState.currentItemStrokeWidthKey,
|
||||
appState.currentItemStrokeWidth,
|
||||
);
|
||||
activePen.backgroundColor = appState.currentItemBackgroundColor;
|
||||
activePen.strokeColor = appState.currentItemStrokeColor;
|
||||
activePen.fillStyle = appState.currentItemFillStyle;
|
||||
|
||||
+83
-129
@@ -2,15 +2,15 @@
|
||||
height: 100%;
|
||||
margin: 0px;
|
||||
background-color: var(--background-primary);
|
||||
position:relative;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.block-language-excalidraw {
|
||||
text-align:center;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
svg.excalidraw-svg {
|
||||
width: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.excalidraw-embedded-img {
|
||||
@@ -50,7 +50,7 @@ div.excalidraw-svg-left {
|
||||
}
|
||||
|
||||
button.ToolIcon_type_button[title="Export"] {
|
||||
display:none;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.excalidraw-prompt-div {
|
||||
@@ -104,8 +104,8 @@ button.ToolIcon_type_button[title="Export"] {
|
||||
}
|
||||
|
||||
.ex-coffee-div {
|
||||
text-align: center;
|
||||
margin-bottom: 10px;
|
||||
text-align: center;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.excalidraw-mastery-promo {
|
||||
@@ -196,7 +196,7 @@ button.ToolIcon_type_button[title="Export"] {
|
||||
|
||||
.excalidraw-scriptengine-install td>img {
|
||||
width: 100%;
|
||||
max-width:800px;
|
||||
max-width: 800px;
|
||||
}
|
||||
|
||||
.excalidraw-scriptengine-install img.coffee {
|
||||
@@ -227,7 +227,7 @@ button.ToolIcon_type_button[title="Export"] {
|
||||
}
|
||||
|
||||
.excalidraw-scriptengine-install .modal {
|
||||
max-height:90%;
|
||||
max-height: 90%;
|
||||
width: auto;
|
||||
}
|
||||
|
||||
@@ -250,18 +250,20 @@ button.ToolIcon_type_button[title="Export"] {
|
||||
}
|
||||
|
||||
.workspace-leaf-content .excalidraw-view {
|
||||
padding: 0px 1px; /*1px so on ipad swipe in from left and right still works*/
|
||||
padding: 0px 1px;
|
||||
/*1px so on ipad swipe in from left and right still works*/
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.excalidraw-videoWrapper {
|
||||
max-width:600px;
|
||||
}
|
||||
.excalidraw-videoWrapper.settings {
|
||||
max-width:340px;
|
||||
max-width: 600px;
|
||||
}
|
||||
|
||||
.excalidraw-videoWrapper div{
|
||||
.excalidraw-videoWrapper.settings {
|
||||
max-width: 340px;
|
||||
}
|
||||
|
||||
.excalidraw-videoWrapper div {
|
||||
position: relative;
|
||||
padding-bottom: 56.25%;
|
||||
height: 0;
|
||||
@@ -281,7 +283,7 @@ button.ToolIcon_type_button[title="Export"] {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.excalidraw-release .modal-content{
|
||||
.excalidraw-release .modal-content {
|
||||
padding-right: 5px;
|
||||
margin-right: -5px;
|
||||
user-select: text;
|
||||
@@ -293,7 +295,7 @@ button.ToolIcon_type_button[title="Export"] {
|
||||
}
|
||||
|
||||
.excalidraw-scriptengine-install tbody>tr>td>div>img {
|
||||
height:20px;
|
||||
height: 20px;
|
||||
background-color: silver;
|
||||
padding: 2px;
|
||||
}
|
||||
@@ -318,7 +320,7 @@ button.ToolIcon_type_button[title="Export"] {
|
||||
position: absolute;
|
||||
padding: 12px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 8px 24px rgba(0,0,0,0.25);
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
|
||||
background-color: var(--background-primary);
|
||||
border: 1px solid var(--background-modifier-border);
|
||||
z-index: 9999;
|
||||
@@ -347,7 +349,7 @@ textarea.excalidraw-wysiwyg {
|
||||
-webkit-box-shadow: none;
|
||||
-moz-box-shadow: none;
|
||||
box-shadow: none;
|
||||
border-radius: 0;
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.is-tablet .excalidraw button,
|
||||
@@ -356,11 +358,6 @@ textarea.excalidraw-wysiwyg {
|
||||
height: 1.8rem;
|
||||
}
|
||||
|
||||
.excalidraw-hidden,
|
||||
.excalidraw-display-none {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.excalidraw-display-flex {
|
||||
display: flex;
|
||||
}
|
||||
@@ -378,7 +375,7 @@ textarea.excalidraw-wysiwyg {
|
||||
background: var(--background-primary-alt);
|
||||
}
|
||||
|
||||
.excalidraw-ai-provider-table > .setting-item {
|
||||
.excalidraw-ai-provider-table>.setting-item {
|
||||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
padding-bottom: 0.5rem;
|
||||
@@ -396,7 +393,7 @@ textarea.excalidraw-wysiwyg {
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.excalidraw-ai-provider-table__row + .excalidraw-ai-provider-table__row {
|
||||
.excalidraw-ai-provider-table__row+.excalidraw-ai-provider-table__row {
|
||||
border-top: 1px solid var(--background-modifier-border);
|
||||
}
|
||||
|
||||
@@ -506,7 +503,8 @@ div.excalidraw-draginfo {
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
.excalidraw-sidepanel-tab__button { /* probably unused */
|
||||
.excalidraw-sidepanel-tab__button {
|
||||
/* probably unused */
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
@@ -680,7 +678,7 @@ img.excalidraw-cropped-pdfpage,
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.popover .excalidraw-svg {
|
||||
.popover .excalidraw-svg {
|
||||
width: 100%;
|
||||
max-width: inherit;
|
||||
height: 100%;
|
||||
@@ -688,24 +686,26 @@ img.excalidraw-cropped-pdfpage,
|
||||
}
|
||||
|
||||
root {
|
||||
--excalidraw-caret-color: initial;
|
||||
--excalidraw-caret-color: initial;
|
||||
}
|
||||
|
||||
.excalidraw-settings-links-container {
|
||||
align-items: center;
|
||||
color: inherit;
|
||||
display: flex;
|
||||
gap: .3em;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
color: inherit;
|
||||
display: flex;
|
||||
gap: .3em;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
.excalidraw-settings-links-container a {
|
||||
display: flex; /* Align children horizontally */
|
||||
align-items: center; /* Center items vertically */
|
||||
display: flex;
|
||||
/* Align children horizontally */
|
||||
align-items: center;
|
||||
/* Center items vertically */
|
||||
text-align: left;
|
||||
margin-right: 4px;
|
||||
margin-left: 4px;
|
||||
@@ -761,19 +761,14 @@ root {
|
||||
margin-bottom: -2px;
|
||||
}
|
||||
|
||||
.is-mobile .modal-container.excalidraw-modal .modal.excalidraw-modal {
|
||||
align-self: flex-start;
|
||||
transform: none !important;
|
||||
margin-top: calc(var(--safe-area-inset-top) + var(--header-height) + var(--size-4-2));
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.excalidraw-prompt-buttonbar-top,
|
||||
.excalidraw-prompt-buttonbar-bottom {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: flex-start; /* keep both rows top‐aligned */
|
||||
row-gap: 0.5em; /* vertical space when wrapped */
|
||||
align-items: flex-start;
|
||||
/* keep both rows top‐aligned */
|
||||
row-gap: 0.5em;
|
||||
/* vertical space when wrapped */
|
||||
}
|
||||
|
||||
/* top bar specifics */
|
||||
@@ -788,20 +783,20 @@ root {
|
||||
}
|
||||
|
||||
/* make each child a flex row */
|
||||
.excalidraw-prompt-buttonbar-top > div,
|
||||
.excalidraw-prompt-buttonbar-bottom > div {
|
||||
.excalidraw-prompt-buttonbar-top>div,
|
||||
.excalidraw-prompt-buttonbar-bottom>div {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
/* push the first group to the left */
|
||||
.excalidraw-prompt-buttonbar-top > div:first-child,
|
||||
.excalidraw-prompt-buttonbar-bottom > div:first-child {
|
||||
.excalidraw-prompt-buttonbar-top>div:first-child,
|
||||
.excalidraw-prompt-buttonbar-bottom>div:first-child {
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
/* push the second group to the right */
|
||||
.excalidraw-prompt-buttonbar-top > div:last-child,
|
||||
.excalidraw-prompt-buttonbar-bottom > div:last-child {
|
||||
.excalidraw-prompt-buttonbar-top>div:last-child,
|
||||
.excalidraw-prompt-buttonbar-bottom>div:last-child {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
@@ -810,7 +805,7 @@ root {
|
||||
flex-direction: column;
|
||||
background: var(--background-secondary);
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 1px 4px 0 rgba(0,0,0,0.10);
|
||||
box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.10);
|
||||
padding: 0.5em 0.8em;
|
||||
margin-bottom: 0.5em;
|
||||
max-width: calc(100% - 1.6em);
|
||||
@@ -885,7 +880,8 @@ root {
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.excalidraw-search .document-search-button:hover, .excalidraw-search .document-search-button:focus {
|
||||
.excalidraw-search .document-search-button:hover,
|
||||
.excalidraw-search .document-search-button:focus {
|
||||
background: var(--background-modifier-hover);
|
||||
color: var(--text-accent);
|
||||
}
|
||||
@@ -898,69 +894,8 @@ root {
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.excalidraw-LatexPrompt {
|
||||
.cm-editor {
|
||||
margin-top: var(--size-4-2);
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
/* this is safe, if unsupported, will be ignored */
|
||||
anchor-name: --latex-editor;
|
||||
|
||||
& > .cm-scroller, & > .cm-announcment {
|
||||
align-self: start;
|
||||
width: 100%
|
||||
}
|
||||
|
||||
/* taken from Obsidian, doesn't apply automatically,
|
||||
because the rule does not have :focus-within */
|
||||
&.cm-focused {
|
||||
border-color: var(--background-modifier-border-focus);
|
||||
transition: box-shadow 0.15s ease-in-out, border 0.15s ease-in-out;
|
||||
box-shadow: 0 0 0 var(--input-border-width-focus) var(--background-modifier-border-focus);
|
||||
}
|
||||
|
||||
/* centering the popup */
|
||||
& .cm-tooltip-cursor.cm-tooltip {
|
||||
left: unset !important;
|
||||
|
||||
& .cm-tooltip-arrow {
|
||||
left: 50% !important;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
}
|
||||
|
||||
[jax="CHTML"][display="true"] {
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.cm-content {
|
||||
caret-color: var(--caret-color);
|
||||
}
|
||||
}
|
||||
|
||||
@supports (anchor-name: --test) {
|
||||
.excalidraw-LatexPrompt .cm-editor .cm-tooltip-cursor.cm-tooltip {
|
||||
position: fixed !important;
|
||||
position-anchor: --latex-editor;
|
||||
top: unset !important;
|
||||
max-width: calc(100vw - var(--size-4-4));
|
||||
margin: var(--size-4-2) 0;
|
||||
overflow-x: clip;
|
||||
|
||||
&.cm-tooltip-above {
|
||||
bottom: anchor(top);
|
||||
}
|
||||
|
||||
&.cm-tooltip-below {
|
||||
top: anchor(bottom) !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.excalidraw-filetype-tag {
|
||||
order: 99;
|
||||
order: 99;
|
||||
}
|
||||
|
||||
.excalidraw-mobile-navbar-docked {
|
||||
@@ -975,16 +910,16 @@ root {
|
||||
Obsidian Sheets Plus support
|
||||
*/
|
||||
.excalidraw__embeddable__outer .lj-content-view {
|
||||
width: var(--embeddable-width);
|
||||
height: var(--embeddable-height);
|
||||
width: var(--embeddable-width);
|
||||
height: var(--embeddable-height);
|
||||
}
|
||||
|
||||
.excalidraw__embeddable__outer #sheet-box {
|
||||
height: calc(var(--embeddable-height) - var(--lj-toolbar-height) + 40px);
|
||||
height: calc(var(--embeddable-height) - var(--lj-toolbar-height) + 40px);
|
||||
}
|
||||
|
||||
.excalidraw__embeddable__outer .lj-univer .univer-relative.univer-grid {
|
||||
width: var(--embeddable-width);
|
||||
width: var(--embeddable-width);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -997,16 +932,18 @@ End Obsidian Sheets Plus support
|
||||
}
|
||||
|
||||
.excalidraw-button-bgcolor {
|
||||
&-normal {
|
||||
background-color: var(--interactive-normal);
|
||||
&-normal {
|
||||
background-color: var(--interactive-normal);
|
||||
color: var(--text-normal);
|
||||
}
|
||||
&-accent {
|
||||
background-color: var(--interactive-accent);
|
||||
|
||||
&-accent {
|
||||
background-color: var(--interactive-accent);
|
||||
color: var(--text-on-accent);
|
||||
}
|
||||
&-success {
|
||||
background-color: var(--interactive-success);
|
||||
|
||||
&-success {
|
||||
background-color: var(--interactive-success);
|
||||
color: var(--text-on-success);
|
||||
}
|
||||
}
|
||||
@@ -1095,7 +1032,7 @@ End Obsidian Sheets Plus support
|
||||
}
|
||||
|
||||
.excalidraw-toolsPanel-island {
|
||||
width: 16em;
|
||||
width: 14.5rem;
|
||||
height: fit-content;
|
||||
max-height: 400px;
|
||||
z-index: 5;
|
||||
@@ -1106,3 +1043,20 @@ End Obsidian Sheets Plus support
|
||||
width: 100%;
|
||||
cursor: move;
|
||||
}
|
||||
|
||||
.excalidraw .App-bottom-bar .App-toolbar {
|
||||
min-width: 12.8em;
|
||||
}
|
||||
|
||||
.excalidraw .Island.App-menu__left {
|
||||
scrollbar-width: none;
|
||||
}
|
||||
|
||||
.excalidraw .Island.excalidraw-toolsPanel-island .buttonList Button.ToolIcon_type_button {
|
||||
flex: 0 0 18%;
|
||||
}
|
||||
|
||||
.excalidraw .Island.excalidraw-toolsPanel-island .selected-shape-actions .buttonList {
|
||||
justify-content: space-between;
|
||||
column-gap: unset;
|
||||
}
|
||||
Reference in new issue
Block a user