Compare commits
74 Commits
1.7.15
...
1.7.28-bet
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e0111e264c | ||
|
|
c6196a86a9 | ||
|
|
3926e5c30b | ||
|
|
a1256422fa | ||
|
|
eeb47d4912 | ||
|
|
8ceac4ab31 | ||
|
|
225c6305d1 | ||
|
|
ba9ab61cc9 | ||
|
|
0940a8628a | ||
|
|
46ee9e9524 | ||
|
|
c044278a4a | ||
|
|
aa9118cdae | ||
|
|
d19b32d0c4 | ||
|
|
dd7f0750fd | ||
|
|
e1330cd8bb | ||
|
|
04367bd3cd | ||
|
|
7d139462bf | ||
|
|
d8e429d815 | ||
|
|
4685a6f014 | ||
|
|
03b389a2b5 | ||
|
|
024f7979a7 | ||
|
|
f9e9ac0728 | ||
|
|
c6eb5859b5 | ||
|
|
377268f30c | ||
|
|
b23afc9621 | ||
|
|
d92c95c3fd | ||
|
|
98b39ab2b0 | ||
|
|
431d5e1104 | ||
|
|
adaf6ee0ae | ||
|
|
3d7d6df2ec | ||
|
|
71d00e0c8d | ||
|
|
ed316fc2c4 | ||
|
|
83f12a8fc5 | ||
|
|
2b7253168e | ||
|
|
70a869fa05 | ||
|
|
e66c31618b | ||
|
|
91298190dc | ||
|
|
11b4091d34 | ||
|
|
78287ab5f3 | ||
|
|
f632c709a5 | ||
|
|
2499629f17 | ||
|
|
16f2240c5b | ||
|
|
f670e3db9d | ||
|
|
b5710033bc | ||
|
|
2117844fc2 | ||
|
|
650956054f | ||
|
|
5d24e4f063 | ||
|
|
994ed375b2 | ||
|
|
3acbe2c1bd | ||
|
|
8594fbc490 | ||
|
|
8b9aa8ccc4 | ||
|
|
b0bb5a00fb | ||
|
|
9bf3e899c2 | ||
|
|
db1f989f49 | ||
|
|
4c45a54ddd | ||
|
|
64d48ed867 | ||
|
|
e2d70687c1 | ||
|
|
1aac4ffdf3 | ||
|
|
b9e154330b | ||
|
|
56ae6baf2b | ||
|
|
64fd43abb8 | ||
|
|
31ae51a421 | ||
|
|
0d879b7a7e | ||
|
|
d8166bbf8c | ||
|
|
82bde38a4b | ||
|
|
36b679434f | ||
|
|
6fa90662b3 | ||
|
|
7f45dad610 | ||
|
|
0e1ee0dde2 | ||
|
|
6c7b63cbdf | ||
|
|
bca7010394 | ||
|
|
3565a5bf94 | ||
|
|
f85fc124d9 | ||
|
|
96dcaf38c1 |
62
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -1,32 +1,30 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Environment (please complete the following information):**
|
||||
- OS including version: [e.g. iOS 15.1, Android 9, Windows 11, etc]
|
||||
- Plugin version:
|
||||
- Obsidian version:
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help me improve Excalidraw
|
||||
title: 'BUG: '
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Your environment**
|
||||
Please run `Command Palette/Show Debug info` in Obsidian and paste the result here.
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
|
||||
40
.github/ISSUE_TEMPLATE/feature_request.md
vendored
@@ -1,20 +1,20 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: 'FR: '
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
|
||||
3
.gitignore
vendored
@@ -15,4 +15,5 @@ data.json
|
||||
lib
|
||||
|
||||
#VSCode
|
||||
.vscode
|
||||
.vscode
|
||||
yarn.lock
|
||||
|
||||
14
README.md
@@ -17,15 +17,19 @@ Please upgrade to Obsidian v0.12.19 or higher to get the latest release.
|
||||
|[](https://youtu.be/eKFmrSQhFA4)|[](https://youtu.be/qbPIAZguJeo)|[](https://youtu.be/2Y8OhkGiTHg)|
|
||||
|[](https://youtu.be/2v9TZmQNO8c)|[](https://youtu.be/xHPGWR3m0c8)|[](https://youtu.be/gMIKXyhS-dM)|
|
||||
|[](https://youtu.be/Etskjw7a5zo)|[](https://youtu.be/4N6efq1DtH0)|[](https://youtu.be/U2LkBRBk4LY)|
|
||||
| [](https://youtu.be/qiKuqMcNWgU)|[](https://youtu.be/yZQoJg2RCKI)| |
|
||||
| [](https://youtu.be/qiKuqMcNWgU)|[](https://youtu.be/yZQoJg2RCKI)|[](https://youtu.be/6PLGHBH9VZ4) |
|
||||
|[](https://youtu.be/epYNx2FSf2w) | [](https://youtu.be/Amhlv6r9WvM) | [](https://youtu.be/r9oB1SlK1GU) |
|
||||
|[](https://youtu.be/7gJDwNgQ6NU) | [](https://youtu.be/vlC1-iBvIfo) | |
|
||||
|
||||
|
||||
|
||||
# Key features
|
||||
- The plugin aims to integrate Excalidraw seamlessly into Obsidian including Command Palette actions, File Explorer features, Option Menu commands, and the Ribbon Button.
|
||||
- The plugin integrates Excalidraw seamlessly into Obsidian including Command Palette actions, File Explorer features, Option Menu commands, and the Ribbon Button.
|
||||
- <kbd>CTRL/CMD+Click</kbd> on the ribbon button, or in the file explorer to create / open drawings in a new pane.
|
||||
- Settings will allow you to customize Excalidraw to your needs:
|
||||
- Default folder for new drawings and define custom filename pattern for new drawings.
|
||||
- Template for new drawings. The template will restore stroke properties. This means you can set up defaults in your template for stroke color, stroke width, opacity, font family, font size, fill style, stroke style, etc. This also applies to ExcalidrawAutomate.
|
||||
- Via the template you can customize the color palette used by Excalidraw. Switch to Markdown view. Scroll down to the bottom of the file and find `"AppState": {`. Find `"customColorPalette": {` at the end of the AppState section. You may specify the 3 palettes used in Excalidraw by adding any or all of the following 3 variables: `"canvasBackground":[], "elementBackground":[], "elementStroke": []`. Add a comma separated list of valid HTML colors (e.g. `#FF0000` for red) in the array for each of the variables. See my videos above for further help.
|
||||
- If portability is important to you: Auto-export SVG and/or PNG files including keep-in-sync feature so you can embed SVG/PNG into your documents instead of embedding excalidraw files. You can override export settings for an individual file by adding the `excalidraw-autoexport` frontmatter key. Valid values for this key are `none`, `both`, `png` and `svg`.
|
||||
- Specify the default width of embedded drawings.
|
||||
- Compatibility features to auto-export and keep in sync markdown excalidraw files and legacy .excalidraw files.
|
||||
@@ -49,8 +53,8 @@ Please upgrade to Obsidian v0.12.19 or higher to get the latest release.
|
||||
- Insert LaTeX formulas using the Command Palette action "Insert LaTeX formula". You can edit formulas either in Markdown view, or by <kbd>CTRL/CMD + Click</kbd> on the formula.
|
||||
- Drag & Drop support
|
||||
- You can drag files from the Obsidian file explorer and they will become links to those files in Excalidraw.
|
||||
- Dragging image files (PNG, SVG, JPG, Excalidraw) from Obsidian's file explorer while pressing the <kbd>CTRL/CMD</kbd> button will embed the image into your drawing.
|
||||
- You can drag and drop images from outside Obsidian onto Excalidraw. These images will be embedded into your drawing and saved to Obsidian.
|
||||
- Dragging image files (PNG, SVG, JPG, ICO, GIF, WEBP, Excalidraw) from Obsidian's file explorer while pressing the <kbd>CTRL</kbd> (<kbd>SHIFT</kbd> on Mac) button will embed the image into your drawing.
|
||||
- If in addition to <kbd>CTRL</kbd> or <kbd>SHIFT</kbd> you also hold down <kbd>ALT<kbd>, the image will be inserted at 100% of its size. ⚠ Note: this is a very niche feature with a very particular behavior that I built primarily for myself (even more so than other features in Excalidraw Obsidian - also built primarily for myself 😉)... This will reset your embedded image to 100% size every time you open the Excalidraw drawing, or in case you have embedded an Excalidraw drawing on your canvas inserted using this function, every time you update the embedded drawing, it will be scaled back to 100% size. This means that even if you resize the image on the drawing, it will reset to 100% the next time you open the file or you modify the original embedded object. This feature is useful when you decompose a drawing into separate Excalidraw files, but when combined onto a single canvas you want the individual pieces to maintain their actual sizes. I use this feature to construct Book-on-a-Page summaries from atomic drawings.
|
||||
- You can drag and drop text from Markdown views onto Excalidraw.
|
||||
- You can drag and drop web addresses from your browser and they will become links.
|
||||
- Image support
|
||||
@@ -76,7 +80,7 @@ Please upgrade to Obsidian v0.12.19 or higher to get the latest release.
|
||||
- Frontmatter tags to customize image export at a file level [519](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/519). If these keys are present they will override the default excalidraw embed and export settings.
|
||||
- `excalidraw-export-transparent: true`: true == Transparent / false == with background.
|
||||
- `excalidraw-export-dark`: true == Dark mode / false == light mode.
|
||||
- `excalidraw-export-svgpadding`: This only affects export to SVG. Specify the export padding for the image
|
||||
- `excalidraw-export-padding`: Specify the export padding for the image
|
||||
- `excalidraw-export-pngscale`: This only affects export to PNG. Specify the export scale for the image. The typical range is between 0.5 and 5, but you can experiment with other values as well.
|
||||
- Embed complete markdown files into your drawings
|
||||
- Drag from the desired file from the Obsidian file explorer and hold down <kbd>CTRL/CMD</kbd> while dropping the file onto the canvas.
|
||||
|
||||
@@ -3,10 +3,12 @@
|
||||
Here's the interface implemented by ExcalidrawAutomate:
|
||||
|
||||
```typescript
|
||||
export interface ExcalidrawAutomate {
|
||||
export declare class ExcalidrawAutomate implements ExcalidrawAutomateInterface {
|
||||
plugin: ExcalidrawPlugin;
|
||||
elementsDict: {}; //contains the ExcalidrawElements currently edited in Automate indexed by el.id
|
||||
imagesDict: {}; //the images files including DataURL, indexed by fileId
|
||||
targetView: ExcalidrawView = null; //the view currently edited
|
||||
elementsDict: {[key:string]:any}; //contains the ExcalidrawElements currently edited in Automate indexed by el.id
|
||||
imagesDict: {[key: FileId]: any}; //the images files including DataURL, indexed by fileId
|
||||
mostRecentMarkdownSVG:SVGSVGElement = null; //Markdown renderer will drop a copy of the most recent SVG here for debugging purposes
|
||||
style: {
|
||||
strokeColor: string; //https://www.w3schools.com/colors/default.asp
|
||||
backgroundColor: string;
|
||||
@@ -29,178 +31,521 @@ export interface ExcalidrawAutomate {
|
||||
viewBackgroundColor: string;
|
||||
gridSize: number;
|
||||
};
|
||||
setFillStyle(val: number): void; //0:"hachure", 1:"cross-hatch" 2:"solid"
|
||||
setStrokeStyle(val: number): void; //0:"solid", 1:"dashed", 2:"dotted"
|
||||
setStrokeSharpness(val: number): void; //0:"round", 1:"sharp"
|
||||
setFontFamily(val: number): void; //1: Virgil, 2:Helvetica, 3:Cascadia
|
||||
setTheme(val: number): void; //0:"light", 1:"dark"
|
||||
addToGroup(objectIds: []): string;
|
||||
toClipboard(templatePath?: string): void;
|
||||
getElements(): ExcalidrawElement[]; //get all elements from ExcalidrawAutomate elementsDict
|
||||
getElement(id: string): ExcalidrawElement; //get single element from ExcalidrawAutomate elementsDict
|
||||
create(params?: {
|
||||
//create a drawing and save it to filename
|
||||
filename?: string; //if null: default filename as defined in Excalidraw settings
|
||||
foldername?: string; //if null: default folder as defined in Excalidraw settings
|
||||
templatePath?: string;
|
||||
onNewPane?: boolean;
|
||||
frontmatterKeys?: {
|
||||
"excalidraw-plugin"?: "raw" | "parsed";
|
||||
"excalidraw-link-prefix"?: string;
|
||||
"excalidraw-link-brackets"?: boolean;
|
||||
"excalidraw-url-prefix"?: string;
|
||||
constructor(plugin: ExcalidrawPlugin, view?: ExcalidrawView);
|
||||
/**
|
||||
*
|
||||
* @returns
|
||||
*/
|
||||
getAPI(view?: ExcalidrawView): ExcalidrawAutomate;
|
||||
/**
|
||||
* @param val //0:"hachure", 1:"cross-hatch" 2:"solid"
|
||||
* @returns
|
||||
*/
|
||||
setFillStyle(val: number): "hachure" | "cross-hatch" | "solid";
|
||||
/**
|
||||
* @param val //0:"solid", 1:"dashed", 2:"dotted"
|
||||
* @returns
|
||||
*/
|
||||
setStrokeStyle(val: number): "solid" | "dashed" | "dotted";
|
||||
/**
|
||||
* @param val //0:"round", 1:"sharp"
|
||||
* @returns
|
||||
*/
|
||||
setStrokeSharpness(val: number): "round" | "sharp";
|
||||
/**
|
||||
* @param val //1: Virgil, 2:Helvetica, 3:Cascadia
|
||||
* @returns
|
||||
*/
|
||||
setFontFamily(val: number): "Virgil, Segoe UI Emoji" | "Helvetica, Segoe UI Emoji" | "Cascadia, Segoe UI Emoji" | "LocalFont";
|
||||
/**
|
||||
* @param val //0:"light", 1:"dark"
|
||||
* @returns
|
||||
*/
|
||||
setTheme(val: number): "light" | "dark";
|
||||
/**
|
||||
* @param objectIds
|
||||
* @returns
|
||||
*/
|
||||
addToGroup(objectIds: string[]): string;
|
||||
/**
|
||||
* @param templatePath
|
||||
*/
|
||||
toClipboard(templatePath?: string): Promise<void>;
|
||||
/**
|
||||
* get all elements from ExcalidrawAutomate elementsDict
|
||||
* @returns elements from elemenetsDict
|
||||
*/
|
||||
getElements(): ExcalidrawElement[];
|
||||
/**
|
||||
* get single element from ExcalidrawAutomate elementsDict
|
||||
* @param id
|
||||
* @returns
|
||||
*/
|
||||
getElement(id: string): ExcalidrawElement;
|
||||
/**
|
||||
* create a drawing and save it to filename
|
||||
* @param params
|
||||
* filename: if null, default filename as defined in Excalidraw settings
|
||||
* foldername: if null, default folder as defined in Excalidraw settings
|
||||
* @returns
|
||||
*/
|
||||
create(params?: {
|
||||
filename?: string;
|
||||
foldername?: string;
|
||||
templatePath?: string;
|
||||
onNewPane?: boolean;
|
||||
frontmatterKeys?: {
|
||||
"excalidraw-plugin"?: "raw" | "parsed";
|
||||
"excalidraw-link-prefix"?: string;
|
||||
"excalidraw-link-brackets"?: boolean;
|
||||
"excalidraw-url-prefix"?: string;
|
||||
"excalidraw-export-transparent"?: boolean;
|
||||
"excalidraw-export-dark"?: boolean;
|
||||
"excalidraw-export-svgpadding"?: number;
|
||||
"excalidraw-export-pngscale"?: number;
|
||||
"excalidraw-default-mode"?: "view" | "zen";
|
||||
};
|
||||
}): Promise<string>;
|
||||
/**
|
||||
*
|
||||
* @param templatePath
|
||||
* @param embedFont
|
||||
* @param exportSettings use ExcalidrawAutomate.getExportSettings(boolean,boolean)
|
||||
* @param loader use ExcalidrawAutomate.getEmbeddedFilesLoader(boolean?)
|
||||
* @param theme
|
||||
* @returns
|
||||
*/
|
||||
createSVG(templatePath?: string, embedFont?: boolean, exportSettings?: ExportSettings, loader?: EmbeddedFilesLoader, theme?: string, padding?: number): Promise<SVGSVGElement>;
|
||||
/**
|
||||
*
|
||||
* @param templatePath
|
||||
* @param scale
|
||||
* @param exportSettings use ExcalidrawAutomate.getExportSettings(boolean,boolean)
|
||||
* @param loader use ExcalidrawAutomate.getEmbeddedFilesLoader(boolean?)
|
||||
* @param theme
|
||||
* @returns
|
||||
*/
|
||||
createPNG(templatePath?: string, scale?: number, exportSettings?: ExportSettings, loader?: EmbeddedFilesLoader, theme?: string, padding?: number): Promise<any>;
|
||||
/**
|
||||
*
|
||||
* @param text
|
||||
* @param lineLen
|
||||
* @returns
|
||||
*/
|
||||
wrapText(text: string, lineLen: number): string;
|
||||
private boxedElement;
|
||||
/**
|
||||
*
|
||||
* @param topX
|
||||
* @param topY
|
||||
* @param width
|
||||
* @param height
|
||||
* @returns
|
||||
*/
|
||||
addRect(topX: number, topY: number, width: number, height: number): string;
|
||||
/**
|
||||
*
|
||||
* @param topX
|
||||
* @param topY
|
||||
* @param width
|
||||
* @param height
|
||||
* @returns
|
||||
*/
|
||||
addDiamond(topX: number, topY: number, width: number, height: number): string;
|
||||
/**
|
||||
*
|
||||
* @param topX
|
||||
* @param topY
|
||||
* @param width
|
||||
* @param height
|
||||
* @returns
|
||||
*/
|
||||
addEllipse(topX: number, topY: number, width: number, height: number): string;
|
||||
/**
|
||||
*
|
||||
* @param topX
|
||||
* @param topY
|
||||
* @param width
|
||||
* @param height
|
||||
* @returns
|
||||
*/
|
||||
addBlob(topX: number, topY: number, width: number, height: number): string;
|
||||
/**
|
||||
*
|
||||
* @param topX
|
||||
* @param topY
|
||||
* @param text
|
||||
* @param formatting
|
||||
* box: if !null, text will be boxed
|
||||
* @param id
|
||||
* @returns
|
||||
*/
|
||||
addText(topX: number, topY: number, text: string, formatting?: {
|
||||
wrapAt?: number;
|
||||
width?: number;
|
||||
height?: number;
|
||||
textAlign?: string;
|
||||
box?: boolean | "box" | "blob" | "ellipse" | "diamond";
|
||||
boxPadding?: number;
|
||||
}, id?: string): string;
|
||||
/**
|
||||
*
|
||||
* @param points
|
||||
* @returns
|
||||
*/
|
||||
addLine(points: [[x: number, y: number]]): string;
|
||||
/**
|
||||
*
|
||||
* @param points
|
||||
* @param formatting
|
||||
* @returns
|
||||
*/
|
||||
addArrow(points: [x: number, y: number][], formatting?: {
|
||||
startArrowHead?: string;
|
||||
endArrowHead?: string;
|
||||
startObjectId?: string;
|
||||
endObjectId?: string;
|
||||
}): string;
|
||||
/**
|
||||
*
|
||||
* @param topX
|
||||
* @param topY
|
||||
* @param imageFile
|
||||
* @returns
|
||||
*/
|
||||
addImage(topX: number, topY: number, imageFile: TFile): Promise<string>;
|
||||
/**
|
||||
*
|
||||
* @param topX
|
||||
* @param topY
|
||||
* @param tex
|
||||
* @returns
|
||||
*/
|
||||
addLaTex(topX: number, topY: number, tex: string): Promise<string>;
|
||||
/**
|
||||
*
|
||||
* @param objectA
|
||||
* @param connectionA type ConnectionPoint = "top" | "bottom" | "left" | "right" | null
|
||||
* @param objectB
|
||||
* @param connectionB when passed null, Excalidraw will automatically decide
|
||||
* @param formatting
|
||||
* numberOfPoints: points on the line. Default is 0 ie. line will only have a start and end point
|
||||
* startArrowHead: "triangle"|"dot"|"arrow"|"bar"|null
|
||||
* endArrowHead: "triangle"|"dot"|"arrow"|"bar"|null
|
||||
* padding:
|
||||
* @returns
|
||||
*/
|
||||
connectObjects(objectA: string, connectionA: ConnectionPoint | null, objectB: string, connectionB: ConnectionPoint | null, formatting?: {
|
||||
numberOfPoints?: number;
|
||||
startArrowHead?: "triangle" | "dot" | "arrow" | "bar" | null;
|
||||
endArrowHead?: "triangle" | "dot" | "arrow" | "bar" | null;
|
||||
padding?: number;
|
||||
}): string;
|
||||
/**
|
||||
* Adds a text label to a line or arrow. Currently only works with a straight (2 point - start & end - line)
|
||||
* @param lineId id of the line or arrow object in elementsDict
|
||||
* @param label the label text
|
||||
* @returns undefined (if unsuccessful) or the id of the new text element
|
||||
*/
|
||||
addLabelToLine(lineId: string, label: string): string;
|
||||
/**
|
||||
* clear elementsDict and imagesDict only
|
||||
*/
|
||||
clear(): void;
|
||||
/**
|
||||
* clear() + reset all style values to default
|
||||
*/
|
||||
reset(): void;
|
||||
/**
|
||||
* returns true if MD file is an Excalidraw file
|
||||
* @param f
|
||||
* @returns
|
||||
*/
|
||||
isExcalidrawFile(f: TFile): boolean;
|
||||
/**
|
||||
*
|
||||
* @param view
|
||||
* @returns
|
||||
*/
|
||||
setView(view: ExcalidrawView | "first" | "active"): ExcalidrawView;
|
||||
/**
|
||||
*
|
||||
* @returns https://github.com/excalidraw/excalidraw/tree/master/src/packages/excalidraw#ref
|
||||
*/
|
||||
getExcalidrawAPI(): any;
|
||||
/**
|
||||
* get elements in View
|
||||
* @returns
|
||||
*/
|
||||
getViewElements(): ExcalidrawElement[];
|
||||
/**
|
||||
*
|
||||
* @param elToDelete
|
||||
* @returns
|
||||
*/
|
||||
deleteViewElements(elToDelete: ExcalidrawElement[]): boolean;
|
||||
/**
|
||||
* get the selected element in the view, if more are selected, get the first
|
||||
* @returns
|
||||
*/
|
||||
getViewSelectedElement(): any;
|
||||
/**
|
||||
*
|
||||
* @returns
|
||||
*/
|
||||
getViewSelectedElements(): any[];
|
||||
/**
|
||||
*
|
||||
* @param el
|
||||
* @returns TFile file handle for the image element
|
||||
*/
|
||||
getViewFileForImageElement(el: ExcalidrawElement): TFile | null;
|
||||
/**
|
||||
* copies elements from view to elementsDict for editing
|
||||
* @param elements
|
||||
*/
|
||||
copyViewElementsToEAforEditing(elements: ExcalidrawElement[]): void;
|
||||
/**
|
||||
*
|
||||
* @param forceViewMode
|
||||
* @returns
|
||||
*/
|
||||
viewToggleFullScreen(forceViewMode?: boolean): void;
|
||||
/**
|
||||
* connect an object to the selected element in the view
|
||||
* @param objectA ID of the element
|
||||
* @param connectionA
|
||||
* @param connectionB
|
||||
* @param formatting
|
||||
* @returns
|
||||
*/
|
||||
connectObjectWithViewSelectedElement(objectA: string, connectionA: ConnectionPoint | null, connectionB: ConnectionPoint | null, formatting?: {
|
||||
numberOfPoints?: number;
|
||||
startArrowHead?: "triangle" | "dot" | "arrow" | "bar" | null;
|
||||
endArrowHead?: "triangle" | "dot" | "arrow" | "bar" | null;
|
||||
padding?: number;
|
||||
}): boolean;
|
||||
/**
|
||||
* Adds elements from elementsDict to the current view
|
||||
* @param repositionToCursor default is false
|
||||
* @param save default is true
|
||||
* @param newElementsOnTop controls whether elements created with ExcalidrawAutomate
|
||||
* are added at the bottom of the stack or the top of the stack of elements already in the view
|
||||
* Note that elements copied to the view with copyViewElementsToEAforEditing retain their
|
||||
* position in the stack of elements in the view even if modified using EA
|
||||
* default is false, i.e. the new elements get to the bottom of the stack
|
||||
* @returns
|
||||
*/
|
||||
addElementsToView(repositionToCursor?: boolean, save?: boolean, newElementsOnTop?: boolean): Promise<boolean>;
|
||||
/**
|
||||
* Register instance of EA to use for hooks with TargetView
|
||||
* By default ExcalidrawViews will check window.ExcalidrawAutomate for event hooks.
|
||||
* Using this event you can set a different instance of Excalidraw Automate for hooks
|
||||
* @returns true if successful
|
||||
*/
|
||||
registerThisAsViewEA(): boolean;
|
||||
/**
|
||||
* Sets the targetView EA to window.ExcalidrawAutomate
|
||||
* @returns true if successful
|
||||
*/
|
||||
deregisterThisAsViewEA(): boolean;
|
||||
/**
|
||||
* If set, this callback is triggered when the user closes an Excalidraw view.
|
||||
*/
|
||||
onViewUnloadHook: (view: ExcalidrawView) => void;
|
||||
/**
|
||||
* If set, this callback is triggered, when the user changes the view mode.
|
||||
* You can use this callback in case you want to do something additional when the user switches to view mode and back.
|
||||
*/
|
||||
onViewModeChangeHook: (isViewModeEnabled: boolean, view: ExcalidrawView, ea: ExcalidrawAutomate) => void;
|
||||
/**
|
||||
* If set, this callback is triggered, when the user hovers a link in the scene.
|
||||
* You can use this callback in case you want to do something additional when the onLinkHover event occurs.
|
||||
* This callback must return a boolean value.
|
||||
* In case you want to prevent the excalidraw onLinkHover action you must return true, it will stop the native excalidraw onLinkHover management flow.
|
||||
*/
|
||||
onLinkHoverHook: (element: NonDeletedExcalidrawElement, linkText: string, view: ExcalidrawView, ea: ExcalidrawAutomate) => boolean;
|
||||
/**
|
||||
* If set, this callback is triggered, when the user clicks a link in the scene.
|
||||
* You can use this callback in case you want to do something additional when the onLinkClick event occurs.
|
||||
* This callback must return a boolean value.
|
||||
* In case you want to prevent the excalidraw onLinkClick action you must return false, it will stop the native excalidraw onLinkClick management flow.
|
||||
*/
|
||||
onLinkClickHook: (element: ExcalidrawElement, linkText: string, event: MouseEvent, view: ExcalidrawView, ea: ExcalidrawAutomate) => boolean;
|
||||
/**
|
||||
* If set, this callback is triggered, when Excalidraw receives an onDrop event.
|
||||
* You can use this callback in case you want to do something additional when the onDrop event occurs.
|
||||
* This callback must return a boolean value.
|
||||
* In case you want to prevent the excalidraw onDrop action you must return false, it will stop the native excalidraw onDrop management flow.
|
||||
*/
|
||||
onDropHook: (data: {
|
||||
ea: ExcalidrawAutomate;
|
||||
event: React.DragEvent<HTMLDivElement>;
|
||||
draggable: any;
|
||||
type: "file" | "text" | "unknown";
|
||||
payload: {
|
||||
files: TFile[];
|
||||
text: string;
|
||||
};
|
||||
excalidrawFile: TFile;
|
||||
view: ExcalidrawView;
|
||||
pointerPosition: {
|
||||
x: number;
|
||||
y: number;
|
||||
};
|
||||
}) => boolean;
|
||||
/**
|
||||
* utility function to generate EmbeddedFilesLoader object
|
||||
* @param isDark
|
||||
* @returns
|
||||
*/
|
||||
getEmbeddedFilesLoader(isDark?: boolean): EmbeddedFilesLoader;
|
||||
/**
|
||||
* utility function to generate ExportSettings object
|
||||
* @param withBackground
|
||||
* @param withTheme
|
||||
* @returns
|
||||
*/
|
||||
getExportSettings(withBackground: boolean, withTheme: boolean): ExportSettings;
|
||||
/**
|
||||
* get bounding box of elements
|
||||
* bounding box is the box encapsulating all of the elements completely
|
||||
* @param elements
|
||||
* @returns
|
||||
*/
|
||||
getBoundingBox(elements: ExcalidrawElement[]): {
|
||||
topX: number;
|
||||
topY: number;
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
}): Promise<string>;
|
||||
createSVG(
|
||||
templatePath?: string,
|
||||
embedFont?: boolean,
|
||||
exportSettings?: ExportSettings, //use ExcalidrawAutomate.getExportSettings(boolean,boolean)
|
||||
loader?: EmbeddedFilesLoader, //use ExcalidrawAutomate.getEmbeddedFilesLoader(boolean?)
|
||||
theme?: string,
|
||||
): Promise<SVGSVGElement>;
|
||||
createPNG(
|
||||
templatePath?: string,
|
||||
scale?: number,
|
||||
exportSettings?: ExportSettings, //use ExcalidrawAutomate.getExportSettings(boolean,boolean)
|
||||
loader?: EmbeddedFilesLoader, //use ExcalidrawAutomate.getEmbeddedFilesLoader(boolean?)
|
||||
theme?: string,
|
||||
): Promise<any>;
|
||||
wrapText(text: string, lineLen: number): string;
|
||||
addRect(topX: number, topY: number, width: number, height: number): string;
|
||||
addDiamond(topX: number, topY: number, width: number, height: number): string;
|
||||
addEllipse(topX: number, topY: number, width: number, height: number): string;
|
||||
addBlob(topX: number, topY: number, width: number, height: number): string;
|
||||
addText(
|
||||
topX: number,
|
||||
topY: number,
|
||||
text: string,
|
||||
formatting?: {
|
||||
wrapAt?: number;
|
||||
width?: number;
|
||||
height?: number;
|
||||
textAlign?: string;
|
||||
box?: boolean | "box" | "blob" | "ellipse" | "diamond"; //if !null, text will be boxed
|
||||
boxPadding?: number;
|
||||
},
|
||||
id?: string,
|
||||
): string;
|
||||
addLine(points: [[x: number, y: number]]): string;
|
||||
addArrow(
|
||||
points: [[x: number, y: number]],
|
||||
formatting?: {
|
||||
startArrowHead?: string;
|
||||
endArrowHead?: string;
|
||||
startObjectId?: string;
|
||||
endObjectId?: string;
|
||||
},
|
||||
): string;
|
||||
addImage(topX: number, topY: number, imageFile: TFile): Promise<string>;
|
||||
addLaTex(topX: number, topY: number, tex: string): Promise<string>;
|
||||
connectObjects(
|
||||
objectA: string,
|
||||
connectionA: ConnectionPoint, //type ConnectionPoint = "top" | "bottom" | "left" | "right" | null
|
||||
objectB: string,
|
||||
connectionB: ConnectionPoint, //when passed null, Excalidraw will automatically decide
|
||||
formatting?: {
|
||||
numberOfPoints?: number; //points on the line. Default is 0 ie. line will only have a start and end point
|
||||
startArrowHead?: string; //"triangle"|"dot"|"arrow"|"bar"|null
|
||||
endArrowHead?: string; //"triangle"|"dot"|"arrow"|"bar"|null
|
||||
padding?: number;
|
||||
},
|
||||
): void;
|
||||
clear(): void; //clear elementsDict and imagesDict only
|
||||
reset(): void; //clear() + reset all style values to default
|
||||
isExcalidrawFile(f: TFile): boolean; //returns true if MD file is an Excalidraw file
|
||||
//view manipulation
|
||||
targetView: ExcalidrawView; //the view currently edited
|
||||
setView(view: ExcalidrawView | "first" | "active"): ExcalidrawView;
|
||||
getExcalidrawAPI(): any; //https://github.com/excalidraw/excalidraw/tree/master/src/packages/excalidraw#ref
|
||||
getViewElements(): ExcalidrawElement[]; //get elements in View
|
||||
deleteViewElements(el: ExcalidrawElement[]): boolean;
|
||||
getViewSelectedElement(): ExcalidrawElement; //get the selected element in the view, if more are selected, get the first
|
||||
getViewSelectedElements(): ExcalidrawElement[];
|
||||
getViewFileForImageElement(el: ExcalidrawElement): TFile | null; //Returns the TFile file handle for the image element
|
||||
copyViewElementsToEAforEditing(elements: ExcalidrawElement[]): void; //copies elements from view to elementsDict for editing
|
||||
viewToggleFullScreen(forceViewMode?: boolean): void;
|
||||
connectObjectWithViewSelectedElement( //connect an object to the selected element in the view
|
||||
objectA: string, //see connectObjects
|
||||
connectionA: ConnectionPoint,
|
||||
connectionB: ConnectionPoint,
|
||||
formatting?: {
|
||||
numberOfPoints?: number;
|
||||
startArrowHead?: string;
|
||||
endArrowHead?: string;
|
||||
padding?: number;
|
||||
},
|
||||
): boolean;
|
||||
addElementsToView( //Adds elements from elementsDict to the current view
|
||||
repositionToCursor?: boolean, //default is false
|
||||
save?: boolean, //default is true
|
||||
//newElementsOnTop controls whether elements created with ExcalidrawAutomate
|
||||
//are added at the bottom of the stack or the top of the stack of elements already in the view
|
||||
//Note that elements copied to the view with copyViewElementsToEAforEditing retain their
|
||||
//position in the stack of elements in the view even if modified using EA
|
||||
newElementsOnTop?: boolean, //default is false, i.e. the new elements get to the bottom of the stack
|
||||
): Promise<boolean>;
|
||||
onDropHook(data: {
|
||||
//if set Excalidraw will call this function onDrop events
|
||||
ea: ExcalidrawAutomate;
|
||||
event: React.DragEvent<HTMLDivElement>;
|
||||
draggable: any; //Obsidian draggable object
|
||||
type: "file" | "text" | "unknown";
|
||||
payload: {
|
||||
files: TFile[]; //TFile[] array of dropped files
|
||||
text: string; //string
|
||||
/**
|
||||
* elements grouped by the highest level groups
|
||||
* @param elements
|
||||
* @returns
|
||||
*/
|
||||
getMaximumGroups(elements: ExcalidrawElement[]): ExcalidrawElement[][];
|
||||
/**
|
||||
* gets the largest element from a group. useful when a text element is grouped with a box, and you want to connect an arrow to the box
|
||||
* @param elements
|
||||
* @returns
|
||||
*/
|
||||
getLargestElement(elements: ExcalidrawElement[]): ExcalidrawElement;
|
||||
/**
|
||||
* Gets the groupId for the group that contains all the elements, or null if such a group does not exist
|
||||
* @param elements
|
||||
* @returns null or the groupId
|
||||
*/
|
||||
getCommonGroupForElements(elements: ExcalidrawElement[]): string;
|
||||
/**
|
||||
* Gets all the elements from elements[] that share one or more groupIds with element.
|
||||
* @param element
|
||||
* @param elements - typically all the non-deleted elements in the scene
|
||||
* @returns
|
||||
*/
|
||||
getElementsInTheSameGroupWithElement(element: ExcalidrawElement, elements: ExcalidrawElement[]): ExcalidrawElement[];
|
||||
/**
|
||||
* @param element
|
||||
* @param a
|
||||
* @param b
|
||||
* @param gap
|
||||
* @returns 2 or 0 intersection points between line going through `a` and `b`
|
||||
* and the `element`, in ascending order of distance from `a`.
|
||||
*/
|
||||
intersectElementWithLine(element: ExcalidrawBindableElement, a: readonly [number, number], b: readonly [number, number], gap?: number): Point[];
|
||||
/**
|
||||
* See OCR plugin for example on how to use scriptSettings
|
||||
* Set by the ScriptEngine
|
||||
*/
|
||||
activeScript: string;
|
||||
/**
|
||||
*
|
||||
* @returns script settings. Saves settings in plugin settings, under the activeScript key
|
||||
*/
|
||||
getScriptSettings(): {};
|
||||
/**
|
||||
* sets script settings.
|
||||
* @param settings
|
||||
* @returns
|
||||
*/
|
||||
setScriptSettings(settings: any): Promise<void>;
|
||||
/**
|
||||
* Open a file in a new workspaceleaf or reuse an existing adjacent leaf depending on Excalidraw Plugin Settings
|
||||
* @param file
|
||||
* @returns
|
||||
*/
|
||||
openFileInNewOrAdjacentLeaf(file: TFile): WorkspaceLeaf;
|
||||
/**
|
||||
* measure text size based on current style settings
|
||||
* @param text
|
||||
* @returns
|
||||
*/
|
||||
measureText(text: string): {
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
excalidrawFile: TFile; //the file receiving the drop event
|
||||
view: ExcalidrawView; //the excalidraw view receiving the drop
|
||||
pointerPosition: { x: number; y: number }; //the pointer position on canvas at the time of drop
|
||||
}): boolean; //a return of true will stop the default onDrop processing in Excalidraw
|
||||
mostRecentMarkdownSVG: SVGSVGElement; //Markdown renderer will drop a copy of the most recent SVG here for debugging purposes
|
||||
getEmbeddedFilesLoader(isDark?: boolean): EmbeddedFilesLoader; //utility function to generate EmbeddedFilesLoader object
|
||||
getExportSettings( //utility function to generate ExportSettings object
|
||||
withBackground: boolean,
|
||||
withTheme: boolean,
|
||||
): ExportSettings;
|
||||
getBoundingBox(elements: ExcalidrawElement[]): {
|
||||
//get bounding box of elements
|
||||
topX: number; //bounding box is the box encapsulating all of the elements completely
|
||||
topY: number;
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
//elements grouped by the highest level groups
|
||||
getMaximumGroups(elements: ExcalidrawElement[]): ExcalidrawElement[][];
|
||||
//gets the largest element from a group. useful when a text element is grouped with a box, and you want to connect an arrow to the box
|
||||
getLargestElement(elements: ExcalidrawElement[]): ExcalidrawElement;
|
||||
// Returns 2 or 0 intersection points between line going through `a` and `b`
|
||||
// and the `element`, in ascending order of distance from `a`.
|
||||
intersectElementWithLine(
|
||||
element: ExcalidrawBindableElement,
|
||||
a: readonly [number, number],
|
||||
b: readonly [number, number],
|
||||
gap?: number, //if given, element is inflated by this value
|
||||
): Point[];
|
||||
|
||||
//See OCR plugin for example on how to use scriptSettings
|
||||
activeScript: string; //Set automatically by the ScriptEngine
|
||||
getScriptSettings(): {}; //Returns script settings. Saves settings in plugin settings, under the activeScript key
|
||||
setScriptSettings(settings: any): Promise<void>; //sets script settings.
|
||||
openFileInNewOrAdjacentLeaf(file: TFile): WorkspaceLeaf; //Open a file in a new workspaceleaf or reuse an existing adjacent leaf depending on Excalidraw Plugin Settings
|
||||
measureText(text: string): { width: number; height: number }; //measure text size based on current style settings
|
||||
//verifyMinimumPluginVersion returns true if plugin version is >= than required
|
||||
//recommended use:
|
||||
//if(!ea.verifyMinimumPluginVersion || !ea.verifyMinimumPluginVersion("1.5.20")) {new Notice("message");return;}
|
||||
verifyMinimumPluginVersion(requiredVersion: string): boolean;
|
||||
selectElementsInView(elements: ExcalidrawElement[]): void; //sets selection in view
|
||||
generateElementId(): string; //returns an 8 character long random id
|
||||
cloneElement(element: ExcalidrawElement): ExcalidrawElement; //Returns a clone of the element with a new id
|
||||
moveViewElementToZIndex(elementId:number, newZIndex:number): void; //Moves the element to a specific position in the z-index
|
||||
hexStringToRgb(color: string):number[];
|
||||
rgbToHexString(color: number[]):string;
|
||||
hslToRgb(color: number[]):number[];
|
||||
rgbToHsl(color:number[]):number[];
|
||||
colorNameToHex(color:string):string;
|
||||
}
|
||||
```
|
||||
/**
|
||||
* verifyMinimumPluginVersion returns true if plugin version is >= than required
|
||||
* recommended use:
|
||||
* if(!ea.verifyMinimumPluginVersion || !ea.verifyMinimumPluginVersion("1.5.20")) {new Notice("message");return;}
|
||||
* @param requiredVersion
|
||||
* @returns
|
||||
*/
|
||||
verifyMinimumPluginVersion(requiredVersion: string): boolean;
|
||||
/**
|
||||
* Check if view is instance of ExcalidrawView
|
||||
* @param view
|
||||
* @returns
|
||||
*/
|
||||
isExcalidrawView(view: any): boolean;
|
||||
/**
|
||||
* sets selection in view
|
||||
* @param elements
|
||||
* @returns
|
||||
*/
|
||||
selectElementsInView(elements: ExcalidrawElement[]): void;
|
||||
/**
|
||||
* @returns an 8 character long random id
|
||||
*/
|
||||
generateElementId(): string;
|
||||
/**
|
||||
* @param element
|
||||
* @returns a clone of the element with a new id
|
||||
*/
|
||||
cloneElement(element: ExcalidrawElement): ExcalidrawElement;
|
||||
/**
|
||||
* Moves the element to a specific position in the z-index
|
||||
*/
|
||||
moveViewElementToZIndex(elementId: number, newZIndex: number): void;
|
||||
/**
|
||||
*
|
||||
* @param color
|
||||
* @returns
|
||||
*/
|
||||
hexStringToRgb(color: string): number[];
|
||||
/**
|
||||
*
|
||||
* @param color
|
||||
* @returns
|
||||
*/
|
||||
rgbToHexString(color: number[]): string;
|
||||
/**
|
||||
*
|
||||
* @param color
|
||||
* @returns
|
||||
*/
|
||||
hslToRgb(color: number[]): number[];
|
||||
/**
|
||||
*
|
||||
* @param color
|
||||
* @returns
|
||||
*/
|
||||
rgbToHsl(color: number[]): number[];
|
||||
/**
|
||||
*
|
||||
* @param color
|
||||
* @returns
|
||||
*/
|
||||
colorNameToHex(color: string): string;
|
||||
}```
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ settings = ea.getScriptSettings();
|
||||
if(!settings["Border color"]) {
|
||||
settings = {
|
||||
"Border color" : {
|
||||
value: "#000000",
|
||||
value: "transparent",
|
||||
description: "Any legal HTML color (#000000, rgb, color-name, etc.). Set to 'transparent' for transparent color."
|
||||
},
|
||||
"Background color" : {
|
||||
|
||||
@@ -16,274 +16,37 @@ The color conversion method was copied from [color-convert](https://github.com/Q
|
||||
```javascript
|
||||
*/
|
||||
|
||||
if(!ea.verifyMinimumPluginVersion || !ea.verifyMinimumPluginVersion("1.7.19")) {
|
||||
new Notice("This script requires a newer version of Excalidraw. Please install the latest version.");
|
||||
return;
|
||||
}
|
||||
|
||||
let settings = ea.getScriptSettings();
|
||||
//set default values on first run
|
||||
if(!settings["Step size"]) {
|
||||
settings = {
|
||||
"Step size" : {
|
||||
value: 2,
|
||||
description: "Step size in percentage for making the color darker"
|
||||
}
|
||||
};
|
||||
ea.setScriptSettings(settings);
|
||||
}
|
||||
|
||||
const step = settings["Step size"].value;
|
||||
|
||||
const elements = ea
|
||||
.getViewSelectedElements()
|
||||
.filter((el) =>
|
||||
["rectangle", "ellipse", "diamond", "image", "line"].includes(el.type)
|
||||
["rectangle", "ellipse", "diamond", "image", "line", "freedraw"].includes(el.type)
|
||||
);
|
||||
ea.copyViewElementsToEAforEditing(elements);
|
||||
for (const el of ea.getElements()) {
|
||||
const color = colorNameToHex(el.backgroundColor);
|
||||
const rgbColor = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(color);
|
||||
if (rgbColor) {
|
||||
const r = parseInt(rgbColor[1], 16);
|
||||
const g = parseInt(rgbColor[2], 16);
|
||||
const b = parseInt(rgbColor[3], 16);
|
||||
const originalRgb = [r, g, b];
|
||||
const hsl = rgbToHsl(originalRgb);
|
||||
const step = 2;
|
||||
const newLightness = hsl[2] - step;
|
||||
if (newLightness > 0) {
|
||||
hsl[2] = newLightness;
|
||||
}
|
||||
const newRgb = hslToRgb(hsl);
|
||||
el.backgroundColor = "#" + rgbToHexString(newRgb);
|
||||
const color = ea.colorNameToHex(el.backgroundColor);
|
||||
const cm = ea.getCM(color);
|
||||
if (cm) {
|
||||
const darker = cm.darkerBy(step);
|
||||
if(Math.floor(darker.lightness)>0) el.backgroundColor = darker.stringHSL();
|
||||
}
|
||||
}
|
||||
await ea.addElementsToView(false, false);
|
||||
|
||||
function rgbToHexString(args) {
|
||||
const integer =
|
||||
((Math.round(args[0]) & 0xff) << 16) +
|
||||
((Math.round(args[1]) & 0xff) << 8) +
|
||||
(Math.round(args[2]) & 0xff);
|
||||
|
||||
const string = integer.toString(16).toUpperCase();
|
||||
return "000000".substring(string.length) + string;
|
||||
}
|
||||
|
||||
function hslToRgb(hsl) {
|
||||
const h = hsl[0] / 360;
|
||||
const s = hsl[1] / 100;
|
||||
const l = hsl[2] / 100;
|
||||
let t2;
|
||||
let t3;
|
||||
let val;
|
||||
|
||||
if (s === 0) {
|
||||
val = l * 255;
|
||||
return [val, val, val];
|
||||
}
|
||||
|
||||
if (l < 0.5) {
|
||||
t2 = l * (1 + s);
|
||||
} else {
|
||||
t2 = l + s - l * s;
|
||||
}
|
||||
|
||||
const t1 = 2 * l - t2;
|
||||
|
||||
const rgb = [0, 0, 0];
|
||||
for (let i = 0; i < 3; i++) {
|
||||
t3 = h + (1 / 3) * -(i - 1);
|
||||
if (t3 < 0) {
|
||||
t3++;
|
||||
}
|
||||
|
||||
if (t3 > 1) {
|
||||
t3--;
|
||||
}
|
||||
|
||||
if (6 * t3 < 1) {
|
||||
val = t1 + (t2 - t1) * 6 * t3;
|
||||
} else if (2 * t3 < 1) {
|
||||
val = t2;
|
||||
} else if (3 * t3 < 2) {
|
||||
val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
|
||||
} else {
|
||||
val = t1;
|
||||
}
|
||||
|
||||
rgb[i] = val * 255;
|
||||
}
|
||||
|
||||
return rgb;
|
||||
}
|
||||
|
||||
function rgbToHsl(rgb) {
|
||||
const r = rgb[0] / 255;
|
||||
const g = rgb[1] / 255;
|
||||
const b = rgb[2] / 255;
|
||||
const min = Math.min(r, g, b);
|
||||
const max = Math.max(r, g, b);
|
||||
const delta = max - min;
|
||||
let h;
|
||||
let s;
|
||||
|
||||
if (max === min) {
|
||||
h = 0;
|
||||
} else if (r === max) {
|
||||
h = (g - b) / delta;
|
||||
} else if (g === max) {
|
||||
h = 2 + (b - r) / delta;
|
||||
} else if (b === max) {
|
||||
h = 4 + (r - g) / delta;
|
||||
}
|
||||
|
||||
h = Math.min(h * 60, 360);
|
||||
|
||||
if (h < 0) {
|
||||
h += 360;
|
||||
}
|
||||
|
||||
const l = (min + max) / 2;
|
||||
|
||||
if (max === min) {
|
||||
s = 0;
|
||||
} else if (l <= 0.5) {
|
||||
s = delta / (max + min);
|
||||
} else {
|
||||
s = delta / (2 - max - min);
|
||||
}
|
||||
|
||||
return [h, s * 100, l * 100];
|
||||
}
|
||||
|
||||
function colorNameToHex(color) {
|
||||
const colors = {
|
||||
aliceblue: "#f0f8ff",
|
||||
antiquewhite: "#faebd7",
|
||||
aqua: "#00ffff",
|
||||
aquamarine: "#7fffd4",
|
||||
azure: "#f0ffff",
|
||||
beige: "#f5f5dc",
|
||||
bisque: "#ffe4c4",
|
||||
black: "#000000",
|
||||
blanchedalmond: "#ffebcd",
|
||||
blue: "#0000ff",
|
||||
blueviolet: "#8a2be2",
|
||||
brown: "#a52a2a",
|
||||
burlywood: "#deb887",
|
||||
cadetblue: "#5f9ea0",
|
||||
chartreuse: "#7fff00",
|
||||
chocolate: "#d2691e",
|
||||
coral: "#ff7f50",
|
||||
cornflowerblue: "#6495ed",
|
||||
cornsilk: "#fff8dc",
|
||||
crimson: "#dc143c",
|
||||
cyan: "#00ffff",
|
||||
darkblue: "#00008b",
|
||||
darkcyan: "#008b8b",
|
||||
darkgoldenrod: "#b8860b",
|
||||
darkgray: "#a9a9a9",
|
||||
darkgreen: "#006400",
|
||||
darkkhaki: "#bdb76b",
|
||||
darkmagenta: "#8b008b",
|
||||
darkolivegreen: "#556b2f",
|
||||
darkorange: "#ff8c00",
|
||||
darkorchid: "#9932cc",
|
||||
darkred: "#8b0000",
|
||||
darksalmon: "#e9967a",
|
||||
darkseagreen: "#8fbc8f",
|
||||
darkslateblue: "#483d8b",
|
||||
darkslategray: "#2f4f4f",
|
||||
darkturquoise: "#00ced1",
|
||||
darkviolet: "#9400d3",
|
||||
deeppink: "#ff1493",
|
||||
deepskyblue: "#00bfff",
|
||||
dimgray: "#696969",
|
||||
dodgerblue: "#1e90ff",
|
||||
firebrick: "#b22222",
|
||||
floralwhite: "#fffaf0",
|
||||
forestgreen: "#228b22",
|
||||
fuchsia: "#ff00ff",
|
||||
gainsboro: "#dcdcdc",
|
||||
ghostwhite: "#f8f8ff",
|
||||
gold: "#ffd700",
|
||||
goldenrod: "#daa520",
|
||||
gray: "#808080",
|
||||
green: "#008000",
|
||||
greenyellow: "#adff2f",
|
||||
honeydew: "#f0fff0",
|
||||
hotpink: "#ff69b4",
|
||||
"indianred ": "#cd5c5c",
|
||||
indigo: "#4b0082",
|
||||
ivory: "#fffff0",
|
||||
khaki: "#f0e68c",
|
||||
lavender: "#e6e6fa",
|
||||
lavenderblush: "#fff0f5",
|
||||
lawngreen: "#7cfc00",
|
||||
lemonchiffon: "#fffacd",
|
||||
lightblue: "#add8e6",
|
||||
lightcoral: "#f08080",
|
||||
lightcyan: "#e0ffff",
|
||||
lightgoldenrodyellow: "#fafad2",
|
||||
lightgrey: "#d3d3d3",
|
||||
lightgreen: "#90ee90",
|
||||
lightpink: "#ffb6c1",
|
||||
lightsalmon: "#ffa07a",
|
||||
lightseagreen: "#20b2aa",
|
||||
lightskyblue: "#87cefa",
|
||||
lightslategray: "#778899",
|
||||
lightsteelblue: "#b0c4de",
|
||||
lightyellow: "#ffffe0",
|
||||
lime: "#00ff00",
|
||||
limegreen: "#32cd32",
|
||||
linen: "#faf0e6",
|
||||
magenta: "#ff00ff",
|
||||
maroon: "#800000",
|
||||
mediumaquamarine: "#66cdaa",
|
||||
mediumblue: "#0000cd",
|
||||
mediumorchid: "#ba55d3",
|
||||
mediumpurple: "#9370d8",
|
||||
mediumseagreen: "#3cb371",
|
||||
mediumslateblue: "#7b68ee",
|
||||
mediumspringgreen: "#00fa9a",
|
||||
mediumturquoise: "#48d1cc",
|
||||
mediumvioletred: "#c71585",
|
||||
midnightblue: "#191970",
|
||||
mintcream: "#f5fffa",
|
||||
mistyrose: "#ffe4e1",
|
||||
moccasin: "#ffe4b5",
|
||||
navajowhite: "#ffdead",
|
||||
navy: "#000080",
|
||||
oldlace: "#fdf5e6",
|
||||
olive: "#808000",
|
||||
olivedrab: "#6b8e23",
|
||||
orange: "#ffa500",
|
||||
orangered: "#ff4500",
|
||||
orchid: "#da70d6",
|
||||
palegoldenrod: "#eee8aa",
|
||||
palegreen: "#98fb98",
|
||||
paleturquoise: "#afeeee",
|
||||
palevioletred: "#d87093",
|
||||
papayawhip: "#ffefd5",
|
||||
peachpuff: "#ffdab9",
|
||||
peru: "#cd853f",
|
||||
pink: "#ffc0cb",
|
||||
plum: "#dda0dd",
|
||||
powderblue: "#b0e0e6",
|
||||
purple: "#800080",
|
||||
rebeccapurple: "#663399",
|
||||
red: "#ff0000",
|
||||
rosybrown: "#bc8f8f",
|
||||
royalblue: "#4169e1",
|
||||
saddlebrown: "#8b4513",
|
||||
salmon: "#fa8072",
|
||||
sandybrown: "#f4a460",
|
||||
seagreen: "#2e8b57",
|
||||
seashell: "#fff5ee",
|
||||
sienna: "#a0522d",
|
||||
silver: "#c0c0c0",
|
||||
skyblue: "#87ceeb",
|
||||
slateblue: "#6a5acd",
|
||||
slategray: "#708090",
|
||||
snow: "#fffafa",
|
||||
springgreen: "#00ff7f",
|
||||
steelblue: "#4682b4",
|
||||
tan: "#d2b48c",
|
||||
teal: "#008080",
|
||||
thistle: "#d8bfd8",
|
||||
tomato: "#ff6347",
|
||||
turquoise: "#40e0d0",
|
||||
violet: "#ee82ee",
|
||||
wheat: "#f5deb3",
|
||||
white: "#ffffff",
|
||||
whitesmoke: "#f5f5f5",
|
||||
yellow: "#ffff00",
|
||||
yellowgreen: "#9acd32",
|
||||
};
|
||||
if (typeof colors[color.toLowerCase()] != "undefined")
|
||||
return colors[color.toLowerCase()];
|
||||
return color;
|
||||
}
|
||||
|
||||
67
ea-scripts/Grid Selected Images.md
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||

|
||||
|
||||
This script arranges selected images into compact grid view, removing gaps in-between, resizing when necessary and breaking into multiple rows/columns.
|
||||
|
||||
```javascript
|
||||
*/
|
||||
|
||||
try {
|
||||
let els = ea.getViewSelectedElements().filter(el => el.type == 'image');
|
||||
|
||||
new Notice(els.length);
|
||||
|
||||
if (els.length == 0) throw new Error('No image elements selected');
|
||||
|
||||
const bounds = ea.getBoundingBox(els);
|
||||
const { topX, topY, width, height } = bounds;
|
||||
|
||||
els.sort((a, b) => a.x + a.y < b.x + b.y);
|
||||
|
||||
const areaAvailable = width * height;
|
||||
|
||||
let elWidth = els[0].width;
|
||||
let elHeight = els[0].height;
|
||||
|
||||
if (elWidth * elHeight > areaAvailable) {
|
||||
while (elWidth * elHeight > areaAvailable) {
|
||||
elWidth /= 1.1;
|
||||
elHeight /= 1.1;
|
||||
}
|
||||
} else if (elWidth * elHeight < areaAvailable) {
|
||||
while (elWidth * elHeight > areaAvailable) {
|
||||
elWidth *= 1.1;
|
||||
elHeight *= 1.1;
|
||||
}
|
||||
}
|
||||
|
||||
const rows = (width - elWidth) / elWidth;
|
||||
|
||||
let row = 0, column = 0;
|
||||
for (const element of els) {
|
||||
element.x = topX + (elWidth * row);
|
||||
element.y = topY + (elHeight * column);
|
||||
|
||||
if (element.width > elWidth) {
|
||||
while (element.width >= elWidth) {
|
||||
element.width /= 1.1;
|
||||
element.height /= 1.1;
|
||||
}
|
||||
} else if (element.width < elWidth) {
|
||||
while (element.width <= elWidth) {
|
||||
element.width *= 1.1;
|
||||
element.height *= 1.1;
|
||||
}
|
||||
}
|
||||
|
||||
row++;
|
||||
if (row > rows) {
|
||||
row = 0;
|
||||
column++;
|
||||
}
|
||||
}
|
||||
|
||||
ea.addElementsToView(false, true, true);
|
||||
} catch (err) {
|
||||
_ = new Notice(err.toString())
|
||||
}
|
||||
2
ea-scripts/Grid Selected Images.svg
Normal file
@@ -0,0 +1,2 @@
|
||||
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 376.3492303436433 256.64929991179815" stroke="#000">
|
||||
<g stroke-linecap="round" transform="translate(10 10) rotate(0 58.5858154296875 58.5858154296875)"><path d="M-1.64 1.57 C38.67 2.87, 77.63 0.2, 117.31 1.14 M-0.05 -0.5 C40.75 0.3, 82.48 0.12, 118.09 0.99 M116.67 0.11 C118.02 47.69, 116.43 92.18, 118.63 118.15 M117.41 0.39 C116.57 38.93, 117.51 79.53, 116.57 116.49 M118.65 117.22 C92.96 119.01, 66.56 117.46, -0.42 117.17 M117.21 116.56 C91.43 117.53, 63.4 117.03, -0.23 117.71 M1.5 116.9 C-2.3 91.83, 1.37 68.12, -0.05 -0.85 M-0.84 116.86 C-1.03 87.92, -0.86 61.1, 0.54 0.72" stroke-width="2" fill="none"></path></g><g stroke-linecap="round" transform="translate(128.96603337932902 10.2586194164669) rotate(0 58.5858154296875 58.5858154296875)"><path d="M0.05 1.78 C24.68 -1.8, 48.73 0.22, 118.17 0.33 M-0.27 0.22 C34.72 0.61, 69.52 1.58, 118.12 0.36 M117.6 1.43 C115.71 34.53, 118.33 70.74, 117.89 116.98 M116.68 -0.46 C117.9 41.7, 116.85 81.21, 116.34 117.29 M118.4 119.11 C83.22 117.59, 48.31 117.2, -1.44 117.99 M118.15 116.77 C74.14 115.56, 31.55 116.99, -0.96 117.69 M-1.69 115.77 C1.1 78.33, -0.93 41, -1.14 1.03 M-0.43 116.37 C0.72 90.14, 1.52 62.17, 0.55 -0.66" stroke-width="2" fill="none"></path></g><g stroke-linecap="round" transform="translate(248.3020093440573 10.465294492851172) rotate(0 58.5858154296875 58.5858154296875)"><path d="M0.39 -0.88 C44.51 0.1, 89.74 -0.71, 117.03 -0.11 M0.42 0.03 C30.22 0.74, 59.56 0.11, 117.15 -0.25 M116 -0.35 C118.88 36.78, 118.14 71.41, 118.16 117.65 M117.62 0.75 C115.99 39.07, 115.76 79.63, 117.09 117.91 M117.44 117.56 C81.29 118.3, 44.81 119.12, 1.29 117.25 M116.84 116.27 C88.98 117.24, 60.29 117.22, 0.21 117.92 M1.97 115.99 C0.94 82.75, -0.15 51.05, -1.24 -1.67 M-0.26 118 C1.05 86.36, 1.06 53.45, 0.95 0.65" stroke-width="2" fill="none"></path></g><g stroke-linecap="round" transform="translate(10.875590140210988 129.01237455957016) rotate(0 58.5858154296875 58.5858154296875)"><path d="M0.24 -0.16 C29.59 1.02, 57.45 2.91, 117.44 0.38 M0.41 0.64 C32.74 0.23, 66.39 0.45, 116.84 -0.9 M118.21 0.43 C119.3 32.21, 116.11 63.55, 119.15 115.99 M117.68 -0.62 C115.84 34.54, 116.24 68.9, 116.91 118 M115.86 119.08 C76.96 118.61, 32.48 117.59, -1.75 116.45 M117.39 116.77 C85.7 116.42, 54.91 116.16, 0.1 118.13 M-0.18 118.45 C-0.52 71.18, -0.96 24.41, 1.23 0.16 M0.3 117.66 C0.57 92.18, 0.07 65.33, -0.4 0.17" stroke-width="2" fill="none"></path></g><g stroke-linecap="round" transform="translate(129.84162351954 129.27099397603888) rotate(0 58.5858154296875 58.5858154296875)"><path d="M-0.16 1.48 C27.24 1.09, 56.31 0.13, 117.56 -0.42 M0.64 0.04 C34.52 0.5, 69.88 -0.81, 116.27 -0.23 M117.6 1.5 C115.78 39.75, 114.64 84.85, 115.99 117.12 M116.55 -0.84 C116.19 29.74, 115.7 60.09, 118 117.71 M119.08 118.46 C74.37 114.72, 29.76 114.66, -0.72 116.45 M116.77 116.64 C81.73 117.03, 46.47 117.52, 0.96 118.05 M1.28 117.07 C0.37 77.34, -0.95 39.83, 0.16 -1.64 M0.49 117.63 C0.17 83.07, -1.11 48.64, 0.17 0.23" stroke-width="2" fill="none"></path></g><g stroke-linecap="round" transform="translate(249.17759948426828 129.47766905242315) rotate(0 58.5858154296875 58.5858154296875)"><path d="M1.48 0.05 C26.67 2.03, 51.16 0.48, 116.75 0 M0.04 -0.61 C27.7 -1.15, 53.12 -1.65, 116.94 0.54 M118.67 -0.27 C116.09 22.53, 119.75 46.69, 117.12 116.32 M116.34 -0.31 C117.34 27.65, 117.51 57.73, 117.71 117.89 M118.46 117.96 C73.87 118.06, 32.19 117.57, -0.72 117.14 M116.64 116.71 C84.55 115.98, 52.82 117.66, 0.88 117.52 M-0.11 116.63 C-0.44 89.26, 1.33 65.24, -1.64 -0.19 M0.46 117.75 C-0.38 77.25, -0.75 38.91, 0.23 0.69" stroke-width="2" fill="none"></path></g></svg>
|
||||
|
After Width: | Height: | Size: 3.6 KiB |
@@ -16,274 +16,37 @@ The color conversion method was copied from [color-convert](https://github.com/Q
|
||||
```javascript
|
||||
*/
|
||||
|
||||
if(!ea.verifyMinimumPluginVersion || !ea.verifyMinimumPluginVersion("1.7.19")) {
|
||||
new Notice("This script requires a newer version of Excalidraw. Please install the latest version.");
|
||||
return;
|
||||
}
|
||||
|
||||
let settings = ea.getScriptSettings();
|
||||
//set default values on first run
|
||||
if(!settings["Step size"]) {
|
||||
settings = {
|
||||
"Step size" : {
|
||||
value: 2,
|
||||
description: "Step size in percentage for making the color lighter"
|
||||
}
|
||||
};
|
||||
ea.setScriptSettings(settings);
|
||||
}
|
||||
|
||||
const step = settings["Step size"].value;
|
||||
|
||||
const elements = ea
|
||||
.getViewSelectedElements()
|
||||
.filter((el) =>
|
||||
["rectangle", "ellipse", "diamond", "image", "line"].includes(el.type)
|
||||
["rectangle", "ellipse", "diamond", "image", "line", "freedraw"].includes(el.type)
|
||||
);
|
||||
ea.copyViewElementsToEAforEditing(elements);
|
||||
for (const el of ea.getElements()) {
|
||||
const color = colorNameToHex(el.backgroundColor);
|
||||
const rgbColor = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(color);
|
||||
if (rgbColor) {
|
||||
const r = parseInt(rgbColor[1], 16);
|
||||
const g = parseInt(rgbColor[2], 16);
|
||||
const b = parseInt(rgbColor[3], 16);
|
||||
const originalRgb = [r, g, b];
|
||||
const hsl = rgbToHsl(originalRgb);
|
||||
const step = 2;
|
||||
const newLightness = hsl[2] + step;
|
||||
if (newLightness < 100) {
|
||||
hsl[2] = newLightness;
|
||||
}
|
||||
const newRgb = hslToRgb(hsl);
|
||||
el.backgroundColor = "#" + rgbToHexString(newRgb);
|
||||
const color = ea.colorNameToHex(el.backgroundColor);
|
||||
const cm = ea.getCM(color);
|
||||
if (cm) {
|
||||
const lighter = cm.lighterBy(step);
|
||||
if(Math.ceil(lighter.lightness)<100) el.backgroundColor = lighter.stringHSL();
|
||||
}
|
||||
}
|
||||
await ea.addElementsToView(false, false);
|
||||
|
||||
function rgbToHexString(args) {
|
||||
const integer =
|
||||
((Math.round(args[0]) & 0xff) << 16) +
|
||||
((Math.round(args[1]) & 0xff) << 8) +
|
||||
(Math.round(args[2]) & 0xff);
|
||||
|
||||
const string = integer.toString(16).toUpperCase();
|
||||
return "000000".substring(string.length) + string;
|
||||
}
|
||||
|
||||
function hslToRgb(hsl) {
|
||||
const h = hsl[0] / 360;
|
||||
const s = hsl[1] / 100;
|
||||
const l = hsl[2] / 100;
|
||||
let t2;
|
||||
let t3;
|
||||
let val;
|
||||
|
||||
if (s === 0) {
|
||||
val = l * 255;
|
||||
return [val, val, val];
|
||||
}
|
||||
|
||||
if (l < 0.5) {
|
||||
t2 = l * (1 + s);
|
||||
} else {
|
||||
t2 = l + s - l * s;
|
||||
}
|
||||
|
||||
const t1 = 2 * l - t2;
|
||||
|
||||
const rgb = [0, 0, 0];
|
||||
for (let i = 0; i < 3; i++) {
|
||||
t3 = h + (1 / 3) * -(i - 1);
|
||||
if (t3 < 0) {
|
||||
t3++;
|
||||
}
|
||||
|
||||
if (t3 > 1) {
|
||||
t3--;
|
||||
}
|
||||
|
||||
if (6 * t3 < 1) {
|
||||
val = t1 + (t2 - t1) * 6 * t3;
|
||||
} else if (2 * t3 < 1) {
|
||||
val = t2;
|
||||
} else if (3 * t3 < 2) {
|
||||
val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
|
||||
} else {
|
||||
val = t1;
|
||||
}
|
||||
|
||||
rgb[i] = val * 255;
|
||||
}
|
||||
|
||||
return rgb;
|
||||
}
|
||||
|
||||
function rgbToHsl(rgb) {
|
||||
const r = rgb[0] / 255;
|
||||
const g = rgb[1] / 255;
|
||||
const b = rgb[2] / 255;
|
||||
const min = Math.min(r, g, b);
|
||||
const max = Math.max(r, g, b);
|
||||
const delta = max - min;
|
||||
let h;
|
||||
let s;
|
||||
|
||||
if (max === min) {
|
||||
h = 0;
|
||||
} else if (r === max) {
|
||||
h = (g - b) / delta;
|
||||
} else if (g === max) {
|
||||
h = 2 + (b - r) / delta;
|
||||
} else if (b === max) {
|
||||
h = 4 + (r - g) / delta;
|
||||
}
|
||||
|
||||
h = Math.min(h * 60, 360);
|
||||
|
||||
if (h < 0) {
|
||||
h += 360;
|
||||
}
|
||||
|
||||
const l = (min + max) / 2;
|
||||
|
||||
if (max === min) {
|
||||
s = 0;
|
||||
} else if (l <= 0.5) {
|
||||
s = delta / (max + min);
|
||||
} else {
|
||||
s = delta / (2 - max - min);
|
||||
}
|
||||
|
||||
return [h, s * 100, l * 100];
|
||||
}
|
||||
|
||||
function colorNameToHex(color) {
|
||||
const colors = {
|
||||
aliceblue: "#f0f8ff",
|
||||
antiquewhite: "#faebd7",
|
||||
aqua: "#00ffff",
|
||||
aquamarine: "#7fffd4",
|
||||
azure: "#f0ffff",
|
||||
beige: "#f5f5dc",
|
||||
bisque: "#ffe4c4",
|
||||
black: "#000000",
|
||||
blanchedalmond: "#ffebcd",
|
||||
blue: "#0000ff",
|
||||
blueviolet: "#8a2be2",
|
||||
brown: "#a52a2a",
|
||||
burlywood: "#deb887",
|
||||
cadetblue: "#5f9ea0",
|
||||
chartreuse: "#7fff00",
|
||||
chocolate: "#d2691e",
|
||||
coral: "#ff7f50",
|
||||
cornflowerblue: "#6495ed",
|
||||
cornsilk: "#fff8dc",
|
||||
crimson: "#dc143c",
|
||||
cyan: "#00ffff",
|
||||
darkblue: "#00008b",
|
||||
darkcyan: "#008b8b",
|
||||
darkgoldenrod: "#b8860b",
|
||||
darkgray: "#a9a9a9",
|
||||
darkgreen: "#006400",
|
||||
darkkhaki: "#bdb76b",
|
||||
darkmagenta: "#8b008b",
|
||||
darkolivegreen: "#556b2f",
|
||||
darkorange: "#ff8c00",
|
||||
darkorchid: "#9932cc",
|
||||
darkred: "#8b0000",
|
||||
darksalmon: "#e9967a",
|
||||
darkseagreen: "#8fbc8f",
|
||||
darkslateblue: "#483d8b",
|
||||
darkslategray: "#2f4f4f",
|
||||
darkturquoise: "#00ced1",
|
||||
darkviolet: "#9400d3",
|
||||
deeppink: "#ff1493",
|
||||
deepskyblue: "#00bfff",
|
||||
dimgray: "#696969",
|
||||
dodgerblue: "#1e90ff",
|
||||
firebrick: "#b22222",
|
||||
floralwhite: "#fffaf0",
|
||||
forestgreen: "#228b22",
|
||||
fuchsia: "#ff00ff",
|
||||
gainsboro: "#dcdcdc",
|
||||
ghostwhite: "#f8f8ff",
|
||||
gold: "#ffd700",
|
||||
goldenrod: "#daa520",
|
||||
gray: "#808080",
|
||||
green: "#008000",
|
||||
greenyellow: "#adff2f",
|
||||
honeydew: "#f0fff0",
|
||||
hotpink: "#ff69b4",
|
||||
"indianred ": "#cd5c5c",
|
||||
indigo: "#4b0082",
|
||||
ivory: "#fffff0",
|
||||
khaki: "#f0e68c",
|
||||
lavender: "#e6e6fa",
|
||||
lavenderblush: "#fff0f5",
|
||||
lawngreen: "#7cfc00",
|
||||
lemonchiffon: "#fffacd",
|
||||
lightblue: "#add8e6",
|
||||
lightcoral: "#f08080",
|
||||
lightcyan: "#e0ffff",
|
||||
lightgoldenrodyellow: "#fafad2",
|
||||
lightgrey: "#d3d3d3",
|
||||
lightgreen: "#90ee90",
|
||||
lightpink: "#ffb6c1",
|
||||
lightsalmon: "#ffa07a",
|
||||
lightseagreen: "#20b2aa",
|
||||
lightskyblue: "#87cefa",
|
||||
lightslategray: "#778899",
|
||||
lightsteelblue: "#b0c4de",
|
||||
lightyellow: "#ffffe0",
|
||||
lime: "#00ff00",
|
||||
limegreen: "#32cd32",
|
||||
linen: "#faf0e6",
|
||||
magenta: "#ff00ff",
|
||||
maroon: "#800000",
|
||||
mediumaquamarine: "#66cdaa",
|
||||
mediumblue: "#0000cd",
|
||||
mediumorchid: "#ba55d3",
|
||||
mediumpurple: "#9370d8",
|
||||
mediumseagreen: "#3cb371",
|
||||
mediumslateblue: "#7b68ee",
|
||||
mediumspringgreen: "#00fa9a",
|
||||
mediumturquoise: "#48d1cc",
|
||||
mediumvioletred: "#c71585",
|
||||
midnightblue: "#191970",
|
||||
mintcream: "#f5fffa",
|
||||
mistyrose: "#ffe4e1",
|
||||
moccasin: "#ffe4b5",
|
||||
navajowhite: "#ffdead",
|
||||
navy: "#000080",
|
||||
oldlace: "#fdf5e6",
|
||||
olive: "#808000",
|
||||
olivedrab: "#6b8e23",
|
||||
orange: "#ffa500",
|
||||
orangered: "#ff4500",
|
||||
orchid: "#da70d6",
|
||||
palegoldenrod: "#eee8aa",
|
||||
palegreen: "#98fb98",
|
||||
paleturquoise: "#afeeee",
|
||||
palevioletred: "#d87093",
|
||||
papayawhip: "#ffefd5",
|
||||
peachpuff: "#ffdab9",
|
||||
peru: "#cd853f",
|
||||
pink: "#ffc0cb",
|
||||
plum: "#dda0dd",
|
||||
powderblue: "#b0e0e6",
|
||||
purple: "#800080",
|
||||
rebeccapurple: "#663399",
|
||||
red: "#ff0000",
|
||||
rosybrown: "#bc8f8f",
|
||||
royalblue: "#4169e1",
|
||||
saddlebrown: "#8b4513",
|
||||
salmon: "#fa8072",
|
||||
sandybrown: "#f4a460",
|
||||
seagreen: "#2e8b57",
|
||||
seashell: "#fff5ee",
|
||||
sienna: "#a0522d",
|
||||
silver: "#c0c0c0",
|
||||
skyblue: "#87ceeb",
|
||||
slateblue: "#6a5acd",
|
||||
slategray: "#708090",
|
||||
snow: "#fffafa",
|
||||
springgreen: "#00ff7f",
|
||||
steelblue: "#4682b4",
|
||||
tan: "#d2b48c",
|
||||
teal: "#008080",
|
||||
thistle: "#d8bfd8",
|
||||
tomato: "#ff6347",
|
||||
turquoise: "#40e0d0",
|
||||
violet: "#ee82ee",
|
||||
wheat: "#f5deb3",
|
||||
white: "#ffffff",
|
||||
whitesmoke: "#f5f5f5",
|
||||
yellow: "#ffff00",
|
||||
yellowgreen: "#9acd32",
|
||||
};
|
||||
if (typeof colors[color.toLowerCase()] != "undefined")
|
||||
return colors[color.toLowerCase()];
|
||||
return color;
|
||||
}
|
||||
|
||||
188
ea-scripts/Palette loader.md
Normal file
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
Design your palette at http://paletton.com/
|
||||
Once you are happy with your colors, click Tables/Export in the bottom right of the screen:
|
||||

|
||||
Then click "Color swatches/as Sketch Palette"
|
||||

|
||||
Copy the contents of the page to a markdown file in your vault. Place the file in the Excalidraw/Palettes folder (you can change this folder in settings).
|
||||

|
||||

|
||||
|
||||
```javascript
|
||||
*/
|
||||
//--------------------------
|
||||
// Load settings
|
||||
//--------------------------
|
||||
if(!ea.verifyMinimumPluginVersion || !ea.verifyMinimumPluginVersion("1.7.19")) {
|
||||
new Notice("This script requires a newer version of Excalidraw. Please install the latest version.");
|
||||
return;
|
||||
}
|
||||
|
||||
const api = ea.getExcalidrawAPI();
|
||||
let settings = ea.getScriptSettings();
|
||||
//set default values on first run
|
||||
if(!settings["Palette folder"]) {
|
||||
settings = {
|
||||
"Palette folder" : {
|
||||
value: "Excalidraw/Palettes",
|
||||
description: "The path to the folder where you store the Excalidraw Palettes"
|
||||
},
|
||||
"Light-gray" : {
|
||||
value: "#505050",
|
||||
description: "Base light-gray used for mixing with the accent color to generate the palette light-gray"
|
||||
},
|
||||
"Dark-gray" : {
|
||||
value: "#e0e0e0",
|
||||
description: "Base dark-gray used for mixing with the accent color to generate the palette dark-gray"
|
||||
}
|
||||
};
|
||||
ea.setScriptSettings(settings);
|
||||
}
|
||||
|
||||
const lightGray = settings["Light-gray"].value;
|
||||
const darkGray = settings["Dark-gray"].value;
|
||||
|
||||
let paletteFolder = settings["Palette folder"].value.toLowerCase();
|
||||
if(paletteFolder === "" || paletteFolder === "/") {
|
||||
new Notice("The palette folder cannot be the root folder of your vault");
|
||||
return;
|
||||
}
|
||||
|
||||
if(!paletteFolder.endsWith("/")) paletteFolder += "/";
|
||||
|
||||
|
||||
//--------------------------
|
||||
// Select palette
|
||||
//--------------------------
|
||||
const palettes = app.vault.getFiles()
|
||||
.filter(f=>f.extension === "md" && f.path.toLowerCase() === paletteFolder + f.name.toLowerCase())
|
||||
.sort((a,b)=>a.basename.toLowerCase()<b.basename.toLowerCase()?-1:1);
|
||||
const file = await utils.suggester(["Excalidraw Default"].concat(palettes.map(f=>f.name)),["Default"].concat(palettes), "Choose a palette, press ESC to abort");
|
||||
if(!file) return;
|
||||
|
||||
if(file === "Default") {
|
||||
api.updateScene({
|
||||
appState: {
|
||||
colorPalette: {}
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
//--------------------------
|
||||
// Load palette
|
||||
//--------------------------
|
||||
const sketchPalette = await app.vault.read(file);
|
||||
|
||||
const parseJSON = (data) => {
|
||||
try {
|
||||
return JSON.parse(data);
|
||||
} catch(e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const loadPaletteFromPlainText = (data) => {
|
||||
const colors = [];
|
||||
data.replaceAll("\r","").split("\n").forEach(c=>{
|
||||
c = c.trim();
|
||||
if(c==="") return;
|
||||
if(c.match(/[^hslrga-fA-F\(\d\.\,\%\s)#]/)) return;
|
||||
const cm = ea.getCM(c);
|
||||
if(cm) colors.push(cm.stringHEX({alpha: false}));
|
||||
})
|
||||
return colors;
|
||||
}
|
||||
|
||||
const paletteJSON = parseJSON(sketchPalette);
|
||||
|
||||
const colors = paletteJSON
|
||||
? paletteJSON.colors.map(c=>ea.getCM({r:c.red*255,g:c.green*255,b:c.blue*255,a:c.alpha}).stringHEX({alpha: false}))
|
||||
: loadPaletteFromPlainText(sketchPalette);
|
||||
const baseColor = ea.getCM(colors[0]);
|
||||
|
||||
// Add black, white, transparent, gary
|
||||
const palette = [[
|
||||
"transparent",
|
||||
"black",
|
||||
baseColor.mix({color: lightGray, ratio:0.95}).stringHEX({alpha: false}),
|
||||
baseColor.mix({color: darkGray, ratio:0.95}).stringHEX({alpha: false}),
|
||||
"white"
|
||||
]];
|
||||
|
||||
// Create Excalidraw palette
|
||||
for(i=0;i<Math.floor(colors.length/5);i++) {
|
||||
palette.push([
|
||||
colors[i*5+1],
|
||||
colors[i*5+2],
|
||||
colors[i*5],
|
||||
colors[i*5+3],
|
||||
colors[i*5+4]
|
||||
]);
|
||||
}
|
||||
|
||||
const paletteSize = palette.flat().length;
|
||||
const newPalette = {
|
||||
canvasBackground: palette.flat(),
|
||||
elementStroke: palette.flat(),
|
||||
elementBackground: palette.flat()
|
||||
};
|
||||
|
||||
|
||||
//--------------------------
|
||||
// Check if palette has the same size as the current. Is re-paint possible?
|
||||
//--------------------------
|
||||
const oldPalette = api.getAppState().colorPalette;
|
||||
|
||||
//You can only switch and repaint equal size palettes
|
||||
let canRepaint = Object.keys(oldPalette).length === 3 &&
|
||||
oldPalette.canvasBackground.length === paletteSize &&
|
||||
oldPalette.elementBackground.length === paletteSize &&
|
||||
oldPalette.elementStroke.length === paletteSize;
|
||||
|
||||
//Check that the palette for canvas background, element stroke and element background are the same
|
||||
for(i=0;canRepaint && i<paletteSize;i++) {
|
||||
if(
|
||||
oldPalette.canvasBackground[i] !== oldPalette.elementBackground[i] ||
|
||||
oldPalette.canvasBackground[i] !== oldPalette.elementStroke[i]
|
||||
) {
|
||||
canRepaint = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const shouldRepaint = canRepaint && await utils.suggester(["Try repainting the drawing with the new palette","Just load the new palette"], [true, false],"ESC will load the palette without repainting");
|
||||
|
||||
|
||||
//--------------------------
|
||||
// Apply palette
|
||||
//--------------------------
|
||||
if(shouldRepaint) {
|
||||
const map = new Map();
|
||||
for(i=0;i<paletteSize;i++) {
|
||||
map.set(oldPalette.canvasBackground[i],newPalette.canvasBackground[i])
|
||||
}
|
||||
|
||||
ea.copyViewElementsToEAforEditing(ea.getViewElements());
|
||||
ea.getElements().forEach(el=>{
|
||||
el.strokeColor = map.get(el.strokeColor)??el.strokeColor;
|
||||
el.backgroundColor = map.get(el.backgroundColor)??el.backgroundColor;
|
||||
})
|
||||
|
||||
const canvasColor = api.getAppState().viewBackgroundColor;
|
||||
|
||||
await api.updateScene({
|
||||
appState: {
|
||||
colorPalette: newPalette,
|
||||
viewBackgroundColor: map.get(canvasColor)??canvasColor
|
||||
}
|
||||
});
|
||||
|
||||
ea.addElementsToView();
|
||||
} else {
|
||||
api.updateScene({
|
||||
appState: {
|
||||
colorPalette: newPalette
|
||||
}
|
||||
});
|
||||
}
|
||||
1
ea-scripts/Palette loader.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Pro 6.1.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2022 Fonticons, Inc. --><path d="M512 255.1C512 256.9 511.1 257.8 511.1 258.7C511.6 295.2 478.4 319.1 441.9 319.1H344C317.5 319.1 296 341.5 296 368C296 371.4 296.4 374.7 297 377.9C299.2 388.1 303.5 397.1 307.9 407.8C313.9 421.6 320 435.3 320 449.8C320 481.7 298.4 510.5 266.6 511.8C263.1 511.9 259.5 512 256 512C114.6 512 0 397.4 0 256C0 114.6 114.6 0 256 0C397.4 0 512 114.6 512 256V255.1zM96 255.1C78.33 255.1 64 270.3 64 287.1C64 305.7 78.33 319.1 96 319.1C113.7 319.1 128 305.7 128 287.1C128 270.3 113.7 255.1 96 255.1zM128 191.1C145.7 191.1 160 177.7 160 159.1C160 142.3 145.7 127.1 128 127.1C110.3 127.1 96 142.3 96 159.1C96 177.7 110.3 191.1 128 191.1zM256 63.1C238.3 63.1 224 78.33 224 95.1C224 113.7 238.3 127.1 256 127.1C273.7 127.1 288 113.7 288 95.1C288 78.33 273.7 63.1 256 63.1zM384 191.1C401.7 191.1 416 177.7 416 159.1C416 142.3 401.7 127.1 384 127.1C366.3 127.1 352 142.3 352 159.1C352 177.7 366.3 191.1 384 191.1z"/></svg>
|
||||
|
After Width: | Height: | Size: 1.1 KiB |
@@ -3,13 +3,28 @@ Click to watch the intro video:
|
||||
|
||||
[](https://youtu.be/hePJcObHIso)
|
||||
|
||||
> **Warning**
|
||||
> There is an easier way to install/manage scripts than what is shown in this video
|
||||
|
||||
See the [Excalidraw Script Engine](https://zsviczian.github.io/obsidian-excalidraw-plugin/ExcalidrawScriptsEngine.html) documentation for more details.
|
||||
|
||||
## How to install scripts into your Obsidian Vault
|
||||
To install one of the built-in scripts:
|
||||
- Open up an excalidraw drawing in Obsidian
|
||||
- In the pane dropdown menu select "Install or update Excalidraw Scripts"
|
||||
- Click on one of the available scripts
|
||||
- Click on "Install this script" (note if the script is already installed you will instead see an option to update it)
|
||||
- Restart Obsidian so the script will be picked up
|
||||
|
||||
Note: By default this will install the script into your vault in the `Excalidraw/Scripts/Downloaded` folder
|
||||
|
||||
<details><summary>Manual installation of scripts</summary>
|
||||
|
||||
Open the script you are interested in and save it to your Obsidian Vault including the first line `/*`, or open it in "Raw" and copy the entire contents to Obsidian.
|
||||
|
||||

|
||||
|
||||
</details>
|
||||
|
||||
## List of available scripts
|
||||
|Title|Description|Icon|Contributor|
|
||||
|
||||
29
ea-scripts/Rename Image.md
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
|
||||

|
||||
|
||||
Select an image on the canvas and run the script. You will be prompted to provide a new filename / filepath. This cuts down the time to name images you paste from the web or drag and drop from your file system.
|
||||
|
||||
```javascript
|
||||
*/
|
||||
await ea.addElementsToView(); //to ensure all images are saved into the file
|
||||
|
||||
const img = ea.getViewSelectedElements().filter(el=>el.type === "image");
|
||||
if(img.length === 0) {
|
||||
new Notice("No image is selected");
|
||||
return;
|
||||
}
|
||||
|
||||
for(i of img) {
|
||||
const currentPath = ea.plugin.filesMaster.get(i.fileId).path;
|
||||
const file = app.vault.getAbstractFileByPath(currentPath);
|
||||
if(!file) {
|
||||
new Notice("Can't find file: " + currentPath);
|
||||
continue;
|
||||
}
|
||||
const pathNoExtension = file.path.substring(0,file.path.length-file.extension.length-1);
|
||||
const newPath = await utils.inputPrompt("Please provide the filename","file path",pathNoExtension);
|
||||
if(newPath && newPath !== pathNoExtension) {
|
||||
await app.fileManager.renameFile(file,`${newPath}.${file.extension}`);
|
||||
}
|
||||
}
|
||||
1
ea-scripts/Rename Image.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" stroke="#000" viewBox="0 0 122.88 102.06"><path stroke-linecap="round" stroke-width="4" d="M8.18,23.12h67.09v5.39H8.18c-0.77,0-1.47,0.31-1.98,0.82c-0.5,0.51-0.82,1.21-0.82,1.98v39.46c0,0.77,0.31,1.47,0.82,1.98 c0.51,0.5,1.21,0.82,1.98,0.82h67.09v5.39H8.18c-2.24,0-4.29-0.92-5.77-2.4L2.4,76.53C0.92,75.05,0,73.01,0,70.76V31.3 c0-2.24,0.92-4.29,2.4-5.77l0.01-0.01C3.89,24.04,5.94,23.12,8.18,23.12L8.18,23.12z M71.77,53.85c-1.52,0-2.75-1.23-2.75-2.75 c0-1.52,1.23-2.75,2.75-2.75h12.78V18.04c-0.39-3.8-1.56-6.62-3.34-8.6c-1.93-2.16-4.67-3.43-7.99-3.98 c-1.49-0.24-2.51-1.65-2.26-3.15c0.24-1.49,1.65-2.51,3.15-2.26c4.54,0.75,8.37,2.57,11.19,5.74c0.72,0.8,1.37,1.69,1.94,2.66 c0.72-1.25,1.58-2.35,2.56-3.32c2.94-2.92,6.88-4.51,11.59-5.1c1.51-0.18,2.88,0.89,3.06,2.4c0.18,1.51-0.89,2.88-2.4,3.06 c-3.52,0.44-6.38,1.54-8.39,3.53c-1.99,1.97-3.25,4.91-3.61,9.04v5.07h24.65c2.24,0,4.29,0.92,5.77,2.4l0.01,0.01 c1.48,1.48,2.4,3.53,2.4,5.77v39.46c0,2.24-0.92,4.29-2.4,5.77l-0.01,0.01c-1.48,1.48-3.53,2.4-5.77,2.4H90.05v5.07 c0.36,4.13,1.62,7.08,3.61,9.04c2,1.98,4.86,3.09,8.39,3.53c1.51,0.18,2.58,1.56,2.4,3.06c-0.18,1.51-1.55,2.58-3.06,2.4 c-4.7-0.59-8.65-2.18-11.59-5.1c-0.98-0.97-1.84-2.07-2.56-3.32c-0.57,0.97-1.22,1.85-1.94,2.66c-2.83,3.16-6.66,4.99-11.19,5.74 c-1.49,0.24-2.9-0.77-3.15-2.26c-0.24-1.49,0.77-2.9,2.26-3.15c3.32-0.55,6.06-1.81,7.99-3.98c1.78-1.99,2.94-4.81,3.34-8.6 l0-30.17H71.77L71.77,53.85L71.77,53.85z M90.05,28.5v19.84h12.98c1.52,0,2.75,1.23,2.75,2.75c0,1.52-1.23,2.75-2.75,2.75H90.05 v19.71h24.65c0.77,0,1.47-0.31,1.98-0.82c0.5-0.51,0.82-1.21,0.82-1.98V31.3c0-0.77-0.31-1.47-0.82-1.98 c-0.51-0.5-1.21-0.82-1.98-0.82H90.05L90.05,28.5z"/></svg>
|
||||
|
After Width: | Height: | Size: 1.7 KiB |
@@ -14,6 +14,11 @@ https://zsviczian.github.io/obsidian-excalidraw-plugin/ExcalidrawScriptsEngine.h
|
||||
```javascript
|
||||
*/
|
||||
|
||||
if(!ea.verifyMinimumPluginVersion || !ea.verifyMinimumPluginVersion("1.7.19")) {
|
||||
new Notice("This script requires a newer version of Excalidraw. Please install the latest version.");
|
||||
return;
|
||||
}
|
||||
|
||||
let repeatNum = parseInt(await utils.inputPrompt("repeat times?","number","5"));
|
||||
if(!repeatNum) {
|
||||
new Notice("Please enter a number.");
|
||||
@@ -43,38 +48,25 @@ const heightDistance = selectedElements[1].height - selectedElements[0].height;
|
||||
const angleDistance = selectedElements[1].angle - selectedElements[0].angle;
|
||||
|
||||
const bgColor1 = ea.colorNameToHex(selectedElements[0].backgroundColor);
|
||||
const rgbBgColor1 = parseColorString(bgColor1);
|
||||
const cmBgColor1 = ea.getCM(bgColor1);
|
||||
const bgColor2 = ea.colorNameToHex(selectedElements[1].backgroundColor);
|
||||
const rgbBgColor2 = parseColorString(bgColor2);
|
||||
let bgHDistance = 0;
|
||||
let bgSDistance = 0;
|
||||
let bgLDistance = 0;
|
||||
|
||||
if(rgbBgColor1 && rgbBgColor2) {
|
||||
const bgHsl1 = ea.rgbToHsl([rgbBgColor1.value[0], rgbBgColor1.value[1], rgbBgColor1.value[2]]);
|
||||
const bgHsl2 = ea.rgbToHsl([rgbBgColor2.value[0], rgbBgColor2.value[1], rgbBgColor2.value[2]]);
|
||||
|
||||
bgHDistance = bgHsl2[0] - bgHsl1[0];
|
||||
bgSDistance = bgHsl2[1] - bgHsl1[1];
|
||||
bgLDistance = bgHsl2[2] - bgHsl1[2];
|
||||
}
|
||||
let cmBgColor2 = ea.getCM(bgColor2);
|
||||
const isBgTransparent = cmBgColor1.alpha === 0 || cmBgColor2.alpha === 0;
|
||||
const bgHDistance = cmBgColor2.hue - cmBgColor1.hue;
|
||||
const bgSDistance = cmBgColor2.saturation - cmBgColor1.saturation;
|
||||
const bgLDistance = cmBgColor2.lightness - cmBgColor1.lightness;
|
||||
const bgADistance = cmBgColor2.alpha - cmBgColor1.alpha;
|
||||
|
||||
const strokeColor1 = ea.colorNameToHex(selectedElements[0].strokeColor);
|
||||
const rgbStrokeColor1 = parseColorString(strokeColor1);
|
||||
const cmStrokeColor1 = ea.getCM(strokeColor1);
|
||||
const strokeColor2 = ea.colorNameToHex(selectedElements[1].strokeColor);
|
||||
const rgbStrokeColor2 = parseColorString(strokeColor2);
|
||||
let strokeHDistance = 0;
|
||||
let strokeSDistance = 0;
|
||||
let strokeLDistance = 0;
|
||||
let cmStrokeColor2 = ea.getCM(strokeColor2);
|
||||
const isStrokeTransparent = cmStrokeColor1.alpha === 0 || cmStrokeColor2.alpha ===0;
|
||||
const strokeHDistance = cmStrokeColor2.hue - cmStrokeColor1.hue;
|
||||
const strokeSDistance = cmStrokeColor2.saturation - cmStrokeColor1.saturation;
|
||||
const strokeLDistance = cmStrokeColor2.lightness - cmStrokeColor1.lightness;
|
||||
const strokeADistance = cmStrokeColor2.alpha - cmStrokeColor1.alpha;
|
||||
|
||||
if(rgbStrokeColor1 && rgbStrokeColor2) {
|
||||
const strokeHsl1 = ea.rgbToHsl([rgbStrokeColor1.value[0], rgbStrokeColor1.value[1], rgbStrokeColor1.value[2]]);
|
||||
const strokeHsl2 = ea.rgbToHsl([rgbStrokeColor2.value[0], rgbStrokeColor2.value[1], rgbStrokeColor2.value[2]]);
|
||||
|
||||
strokeHDistance = strokeHsl2[0] - strokeHsl1[0];
|
||||
strokeSDistance = strokeHsl2[1] - strokeHsl1[1];
|
||||
strokeLDistance = strokeHsl2[2] - strokeHsl1[2];
|
||||
}
|
||||
|
||||
ea.copyViewElementsToEAforEditing(selectedElements);
|
||||
for(let i=0; i<repeatNum; i++) {
|
||||
@@ -106,262 +98,19 @@ for(let i=0; i<repeatNum; i++) {
|
||||
}
|
||||
}
|
||||
|
||||
if(rgbBgColor1 && rgbBgColor2) {
|
||||
const bgHsl2 = ea.rgbToHsl([rgbBgColor2.value[0], rgbBgColor2.value[1], rgbBgColor2.value[2]]);
|
||||
const newBgH = bgHsl2[0] + bgHDistance * (i + 1);
|
||||
const newBgS = bgHsl2[1] + bgSDistance * (i + 1);
|
||||
const newBgL = bgHsl2[2] + bgLDistance * (i + 1);
|
||||
|
||||
if(newBgH >= 0 && newBgH <= 360 && newBgS >= 0 && newBgS <= 100 && newBgL >= 0 && newBgL <= 100) {
|
||||
const newBgRgb = ea.hslToRgb([newBgH, newBgS, newBgL]);
|
||||
newEl.backgroundColor = rgbColorToString(newBgRgb, rgbBgColor1.model);
|
||||
}
|
||||
if(!isBgTransparent) {
|
||||
cmBgColor2 = cmBgColor2.hueBy(bgHDistance).saturateBy(bgSDistance).lighterBy(bgLDistance).alphaBy(bgADistance);
|
||||
newEl.backgroundColor = cmBgColor2.stringHEX();
|
||||
} else {
|
||||
newEl.backgroundColor = "transparent";
|
||||
}
|
||||
|
||||
if(rgbStrokeColor1 && rgbStrokeColor2) {
|
||||
const strokeHsl2 = ea.rgbToHsl([rgbStrokeColor2.value[0], rgbStrokeColor2.value[1], rgbStrokeColor2.value[2]]);
|
||||
const newStrokeH = strokeHsl2[0] + strokeHDistance * (i + 1);
|
||||
const newStrokeS = strokeHsl2[1] + strokeSDistance * (i + 1);
|
||||
const newStrokeL = strokeHsl2[2] + strokeLDistance * (i + 1);
|
||||
|
||||
if(newStrokeH >= 0 && newStrokeH <= 360 && newStrokeS >= 0 && newStrokeS <= 100 && newStrokeL >= 0 && newStrokeL <= 100) {
|
||||
const newStrokeRgb = ea.hslToRgb([newStrokeH, newStrokeS, newStrokeL]);
|
||||
newEl.strokeColor = rgbColorToString(newStrokeRgb, rgbStrokeColor1.model);
|
||||
}
|
||||
if(!isStrokeTransparent) {
|
||||
cmStrokeColor2 = cmStrokeColor2.hueBy(strokeHDistance).saturateBy(strokeSDistance).lighterBy(strokeLDistance).alphaBy(strokeADistance);
|
||||
newEl.strokeColor = cmStrokeColor2.stringHEX();
|
||||
} else {
|
||||
newEl.strokeColor = "transparent";
|
||||
}
|
||||
}
|
||||
|
||||
await ea.addElementsToView(false, false, true);
|
||||
|
||||
function parseColorString(string) {
|
||||
var prefix = string.substring(0, 3).toLowerCase();
|
||||
var val;
|
||||
var model;
|
||||
switch (prefix) {
|
||||
case 'hsl':
|
||||
val = ea.hslToRgb(parseHslColorString(string));
|
||||
model = 'hsl';
|
||||
break;
|
||||
case 'hwb':
|
||||
val = hwbToRgb(parseHwbColorString(string));
|
||||
model = 'hwb';
|
||||
break;
|
||||
default:
|
||||
val = parseRgbColorString(string);
|
||||
model = 'rgb';
|
||||
break;
|
||||
}
|
||||
|
||||
if (!val) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {model: model, value: val};
|
||||
};
|
||||
|
||||
function parseRgbColorString(string) {
|
||||
if (!string) {
|
||||
return null;
|
||||
}
|
||||
var colorNames={};
|
||||
|
||||
var abbr = /^#([a-f0-9]{3,4})$/i;
|
||||
var hex = /^#([a-f0-9]{6})([a-f0-9]{2})?$/i;
|
||||
var rgba = /^rgba?\(\s*([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
|
||||
var per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
|
||||
var keyword = /^(\w+)$/;
|
||||
|
||||
var rgb = [0, 0, 0, 1];
|
||||
var match;
|
||||
var i;
|
||||
var hexAlpha;
|
||||
|
||||
if (match = string.match(hex)) {
|
||||
hexAlpha = match[2];
|
||||
match = match[1];
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
var i2 = i * 2;
|
||||
rgb[i] = parseInt(match.slice(i2, i2 + 2), 16);
|
||||
}
|
||||
|
||||
if (hexAlpha) {
|
||||
rgb[3] = parseInt(hexAlpha, 16) / 255;
|
||||
}
|
||||
} else if (match = string.match(abbr)) {
|
||||
match = match[1];
|
||||
hexAlpha = match[3];
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
rgb[i] = parseInt(match[i] + match[i], 16);
|
||||
}
|
||||
|
||||
if (hexAlpha) {
|
||||
rgb[3] = parseInt(hexAlpha + hexAlpha, 16) / 255;
|
||||
}
|
||||
} else if (match = string.match(rgba)) {
|
||||
for (i = 0; i < 3; i++) {
|
||||
rgb[i] = parseInt(match[i + 1], 0);
|
||||
}
|
||||
|
||||
if (match[4]) {
|
||||
if (match[5]) {
|
||||
rgb[3] = parseFloat(match[4]) * 0.01;
|
||||
} else {
|
||||
rgb[3] = parseFloat(match[4]);
|
||||
}
|
||||
}
|
||||
} else if (match = string.match(per)) {
|
||||
for (i = 0; i < 3; i++) {
|
||||
rgb[i] = Math.round(parseFloat(match[i + 1]) * 2.55);
|
||||
}
|
||||
|
||||
if (match[4]) {
|
||||
if (match[5]) {
|
||||
rgb[3] = parseFloat(match[4]) * 0.01;
|
||||
} else {
|
||||
rgb[3] = parseFloat(match[4]);
|
||||
}
|
||||
}
|
||||
} else if (match = string.match(keyword)) {
|
||||
if (match[1] === 'transparent') {
|
||||
return [0, 0, 0, 0];
|
||||
}
|
||||
|
||||
if (!hasOwnProperty.call(colorNames, match[1])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
rgb = colorNames[match[1]];
|
||||
rgb[3] = 1;
|
||||
|
||||
return rgb;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
rgb[i] = clamp(rgb[i], 0, 255);
|
||||
}
|
||||
rgb[3] = clamp(rgb[3], 0, 1);
|
||||
|
||||
return rgb;
|
||||
}
|
||||
|
||||
function parseHslColorString(string) {
|
||||
if (!string) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var hsl = /^hsla?\(\s*([+-]?(?:\d{0,3}\.)?\d+)(?:deg)?\s*,?\s*([+-]?[\d\.]+)%\s*,?\s*([+-]?[\d\.]+)%\s*(?:[,|\/]\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/;
|
||||
var match = string.match(hsl);
|
||||
|
||||
if (match) {
|
||||
var alpha = parseFloat(match[4]);
|
||||
var h = ((parseFloat(match[1]) % 360) + 360) % 360;
|
||||
var s = clamp(parseFloat(match[2]), 0, 100);
|
||||
var l = clamp(parseFloat(match[3]), 0, 100);
|
||||
var a = clamp(isNaN(alpha) ? 1 : alpha, 0, 1);
|
||||
|
||||
return [h, s, l, a];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function parseHwbColorString(string) {
|
||||
if (!string) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var hwb = /^hwb\(\s*([+-]?\d{0,3}(?:\.\d+)?)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/;
|
||||
var match = string.match(hwb);
|
||||
|
||||
if (match) {
|
||||
var alpha = parseFloat(match[4]);
|
||||
var h = ((parseFloat(match[1]) % 360) + 360) % 360;
|
||||
var w = clamp(parseFloat(match[2]), 0, 100);
|
||||
var b = clamp(parseFloat(match[3]), 0, 100);
|
||||
var a = clamp(isNaN(alpha) ? 1 : alpha, 0, 1);
|
||||
return [h, w, b, a];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function rgbColorToString(color, model) {
|
||||
switch (model) {
|
||||
case 'hsl':
|
||||
return rgbColorToHslString(color);
|
||||
case 'hwb':
|
||||
return rgbColorToHwbString(color);
|
||||
default:
|
||||
return ea.rgbToHexString(color);
|
||||
}
|
||||
}
|
||||
|
||||
function rgbColorToHslString(rgb) {
|
||||
var hsl = ea.rgbToHsl(rgb);
|
||||
return 'hsl(' + hsl[0] + ', ' + hsl[1] + '%, ' + hsl[2] + '%)'
|
||||
};
|
||||
|
||||
function rgbColorToHwbString(rgb) {
|
||||
var hwb = rgbToHwb(rgb);
|
||||
|
||||
return 'hwb(' + hwb[0] + ', ' + hwb[1] + '%, ' + hwb[2] + '%)';
|
||||
};
|
||||
|
||||
function rgbToHwb(rgb) {
|
||||
const r = rgb[0];
|
||||
const g = rgb[1];
|
||||
let b = rgb[2];
|
||||
const h = convert.rgb.hsl(rgb)[0];
|
||||
const w = 1 / 255 * Math.min(r, Math.min(g, b));
|
||||
|
||||
b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
|
||||
|
||||
return [h, w * 100, b * 100];
|
||||
};
|
||||
|
||||
function hwbToRgb(hwb) {
|
||||
const h = hwb[0] / 360;
|
||||
let wh = hwb[1] / 100;
|
||||
let bl = hwb[2] / 100;
|
||||
const ratio = wh + bl;
|
||||
let f;
|
||||
|
||||
// Wh + bl cant be > 1
|
||||
if (ratio > 1) {
|
||||
wh /= ratio;
|
||||
bl /= ratio;
|
||||
}
|
||||
|
||||
const i = Math.floor(6 * h);
|
||||
const v = 1 - bl;
|
||||
f = 6 * h - i;
|
||||
|
||||
if ((i & 0x01) !== 0) {
|
||||
f = 1 - f;
|
||||
}
|
||||
|
||||
const n = wh + f * (v - wh);
|
||||
let r;
|
||||
let g;
|
||||
let b;
|
||||
switch (i) {
|
||||
default:
|
||||
case 6:
|
||||
case 0: r = v; g = n; b = wh; break;
|
||||
case 1: r = n; g = v; b = wh; break;
|
||||
case 2: r = wh; g = v; b = n; break;
|
||||
case 3: r = wh; g = n; b = v; break;
|
||||
case 4: r = n; g = wh; b = v; break;
|
||||
case 5: r = v; g = wh; b = n; break;
|
||||
}
|
||||
|
||||
return [r * 255, g * 255, b * 255];
|
||||
}
|
||||
|
||||
function clamp(num, min, max) {
|
||||
return Math.min(Math.max(min, num), max);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||

|
||||
|
||||
Use this script to set the background color of unclosed (i.e. open) line objects by creating a clone of the object. The script will set the stroke color of the clone to transparent and will add a straight line to close the object. Use settings to define the default background color, the fill style, and the strokeWidth of the clone. By default the clone will be grouped with the original object, you can disable this also in settings.
|
||||
Use this script to set the background color of unclosed (i.e. open) line and freedraw objects by creating a clone of the object. The script will set the stroke color of the clone to transparent and will add a straight line to close the object. Use settings to define the default background color, the fill style, and the strokeWidth of the clone. By default the clone will be grouped with the original object, you can disable this also in settings.
|
||||
|
||||
```javascript
|
||||
*/
|
||||
@@ -41,9 +41,9 @@ const backgroundColor = settings["Background Color"].value;
|
||||
const fillStyle = settings["Fill Style"].value;
|
||||
const shouldGroup = settings["Group 'shadow' with original"].value;
|
||||
|
||||
const elements = ea.getViewSelectedElements().filter(el=>el.type==="line");
|
||||
const elements = ea.getViewSelectedElements().filter(el=>el.type==="line" || el.type==="freedraw");
|
||||
if(elements.length === 0) {
|
||||
new Notice("No line object is selected");
|
||||
new Notice("No line or freedraw object is selected");
|
||||
}
|
||||
|
||||
ea.copyViewElementsToEAforEditing(elements);
|
||||
|
||||
49
ea-scripts/Text Arch.md
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||

|
||||
|
||||
Fit a text to the arch of a circle. The script will prompt you for the radius of the circle and then split your text to individual letters and place each letter to the arch defined by the radius. Setting a lower radius value will increase the arching of the text. Note that the arched-text will no longer be editable as a text element and it will no longer function as a markdown link. Emojis are currently not supported.
|
||||
|
||||
```javascript
|
||||
*/
|
||||
el = ea.getViewSelectedElement();
|
||||
if(!el || el.type!=="text") {
|
||||
new Notice("Please select a text element");
|
||||
return;
|
||||
}
|
||||
|
||||
ea.style.fontSize = el.fontSize;
|
||||
ea.style.fontFamily = el.fontFamily;
|
||||
ea.style.strokeColor = el.strokeColor;
|
||||
ea.style.opacity = el.opacity;
|
||||
|
||||
const r = parseInt (await utils.inputPrompt("The radius of the arch you'd like to fit the text to","number","150"));
|
||||
const archAbove = await utils.suggester(["Arch above","Arch below"],[true,false]);
|
||||
|
||||
if(isNaN(r)) {
|
||||
new Notice("The radius is not a number");
|
||||
return;
|
||||
}
|
||||
|
||||
circlePoint = (angle) => archAbove
|
||||
? [
|
||||
r * Math.sin(angle),
|
||||
-r * Math.cos(angle)
|
||||
]
|
||||
: [
|
||||
-r * Math.sin(angle),
|
||||
r * Math.cos(angle)
|
||||
];
|
||||
|
||||
let rot = (archAbove ? -0.5 : 0.5) * ea.measureText(el.text).width/r;
|
||||
|
||||
let objectIDs = [];
|
||||
for(i=0;i<el.text.length;i++) {
|
||||
const character = el.text.substring(i,i+1);
|
||||
const width = ea.measureText(character).width;
|
||||
ea.style.angle = rot;
|
||||
const [x,y] = circlePoint(rot);
|
||||
rot += (archAbove ? 1 : -1) *width / r;
|
||||
objectIDs.push(ea.addText(x,y,character));
|
||||
}
|
||||
ea.addToGroup(objectIDs);
|
||||
ea.addElementsToView(true);
|
||||
1
ea-scripts/Text Arch.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" stroke="#000" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><g fill="none"><circle cx="12" cy="12" r="10"></circle><path d="M17 12h.01"></path><path d="M12 12h.01"></path><path d="M7 12h.01"></path></g></svg>
|
||||
|
After Width: | Height: | Size: 309 B |
@@ -51,12 +51,15 @@ I would love to include your contribution in the script library. If you have a s
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Fixed%20spacing.svg"/></div>|[[#Fixed spacing]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Fixed%20vertical%20distance%20between%20centers.svg"/></div>|[[#Fixed vertical distance between centers]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Fixed%20vertical%20distance.svg"/></div>|[[#Fixed vertical distance]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Grid%20Selected%20Images.svg"/></div>|[[#Grid selected images]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Lighten%20background%20color.svg"/></div>|[[#Lighten background color]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Mindmap%20connector.svg"/></div>|[[#Mindmap connector]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Modify%20background%20color%20opacity.svg"/></div>|[[#Modify background color opacity]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Normalize%20Selected%20Arrows.svg"/></div>|[[#Normalize Selected Arrows]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/OCR%20-%20Optical%20Character%20Recognition.svg"/></div>|[[#OCR - Optical Character Recognition]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Organic%20Line.svg"/></div>|[[#Organic Line]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Palette%20loader.svg"/></div>|[[#Palette Loader]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Rename%20Image.svg"/></div>|[[#Rename Image]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Repeat%20Elements.svg"/></div>|[[#Repeat Elements]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Reverse%20arrows.svg"/></div>|[[#Reverse arrows]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Scribble%20Helper.svg"/></div>|[[#Scribble Helper]]|
|
||||
@@ -69,6 +72,7 @@ I would love to include your contribution in the script library. If you have a s
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Set%20Stroke%20Width%20of%20Selected%20Elements.svg"/></div>|[[#Set Stroke Width of Selected Elements]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Set%20Text%20Alignment.svg"/></div>|[[#Set Text Alignment]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Split%20text%20by%20lines.svg"/></div>|[[#Split text by lines]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Text%20Arch.svg"/></div>|[[#Text Arch]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Transfer%20TextElements%20to%20Excalidraw%20markdown%20metadata.svg"/></div>|[[#Transfer TextElements to Excalidraw markdown metadata]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Zoom%20to%20Fit%20Selected%20Elements.svg"/></div>|[[#Zoom to Fit Selected Elements]]|
|
||||
|
||||
@@ -216,6 +220,12 @@ 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/1-2-3'>@1-2-3</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/Fixed%20vertical%20distance.md'>File on GitHub</a></td></tr><tr valign='top'><td class="label">Description</td><td class="data">The script arranges the selected elements vertically with a fixed spacing. When we create an architecture diagram or mind map, we often need to arrange a large number of elements in a fixed spacing. `Fixed spacing` and `Fixed vertical Distance` scripts can save us a lot of time.<br><img src='https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/images/scripts-fixed-vertical-distance.png'></td></tr></table>
|
||||
|
||||
## Grid selected images
|
||||
```excalidraw-script-install
|
||||
https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Grid%20Selected%20Images.md
|
||||
```
|
||||
<table><tr valign='top'><td class="label">Author</td><td class="data"><a href='https://github.com/7flash'>@7flash</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/Grid%20Selected%20Images.md'>File on GitHub</a></td></tr><tr valign='top'><td class="label">Description</td><td class="data">This script arranges selected images into compact grid view, removing gaps in-between, resizing when necessary and breaking into multiple rows/columns.<br><img src='https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/images/scripts-grid-selected-images.png'></td></tr></table>
|
||||
|
||||
## Lighten background color
|
||||
```excalidraw-script-install
|
||||
https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Lighten%20background%20color.md
|
||||
@@ -252,6 +262,18 @@ 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/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/Organic%20Line.md'>File on GitHub</a></td></tr><tr valign='top'><td class="label">Description</td><td class="data">Converts selected freedraw lines such that pencil pressure will decrease from maximum to minimum from the beginning of the line to its end. The resulting line is placed at the back of the layers, under all other items. Helpful when drawing organic mindmaps.<br><img src='https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/images/scripts-organic-line.jpg'></td></tr></table>
|
||||
|
||||
## Palette Loader
|
||||
```excalidraw-script-install
|
||||
https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Palette%20loader.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/Palette%20loader.md'>File on GitHub</a></td></tr><tr valign='top'><td class="label">Description</td><td class="data">Design your palette at <a href="http://paletton.com/" target="_blank">paletton.com</a> Once you are happy with your colors, click Tables/Export in the bottom right of the screen. Then click "Color swatches/as Sketch Palette", and copy the contents of the page to a markdown file in the palette folder of your vault (default is Excalidraw/Palette)<br><img src='https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/images/scripts-sketch-palette-loader-1.jpg'></td></tr></table>
|
||||
|
||||
## Rename Image
|
||||
```excalidraw-script-install
|
||||
https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Rename%20Image.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/Rename%20Image.md'>File on GitHub</a></td></tr><tr valign='top'><td class="label">Description</td><td class="data">Select an image on the canvas and run the script. You will be prompted to provide a new filename / filepath. This cuts down the time to name images you paste from the web or drag and drop from your file system.<br><img src='https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/images/rename-image.png'></td></tr></table>
|
||||
|
||||
## Repeat Elements
|
||||
```excalidraw-script-install
|
||||
https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Repeat%20Elements.md
|
||||
@@ -280,7 +302,7 @@ https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea
|
||||
```excalidraw-script-install
|
||||
https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Set%20background%20color%20of%20unclosed%20line%20object%20by%20adding%20a%20shadow%20clone.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/Set%20background%20color%20of%20unclosed%20line%20object%20by%20adding%20a%20shadow%20clone.md'>File on GitHub</a></td></tr><tr valign='top'><td class="label">Description</td><td class="data">Use this script to set the background color of unclosed (i.e. open) line objects by creating a clone of the object. The script will set the stroke color of the clone to transparent and will add a straight line to close the object. Use settings to define the default background color, the fill style, and the strokeWidth of the clone. By default the clone will be grouped with the original object, you can disable this also in settings.<br><img src='https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/images/scripts-set-background-color-of-unclosed-line.jpg'></td></tr></table>
|
||||
<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/Set%20background%20color%20of%20unclosed%20line%20object%20by%20adding%20a%20shadow%20clone.md'>File on GitHub</a></td></tr><tr valign='top'><td class="label">Description</td><td class="data">Use this script to set the background color of unclosed (i.e. open) line and freedraw objects by creating a clone of the object. The script will set the stroke color of the clone to transparent and will add a straight line to close the object. Use settings to define the default background color, the fill style, and the strokeWidth of the clone. By default the clone will be grouped with the original object, you can disable this also in settings.<br><img src='https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/images/scripts-set-background-color-of-unclosed-line.jpg'></td></tr></table>
|
||||
|
||||
## Set Dimensions
|
||||
```excalidraw-script-install
|
||||
@@ -324,6 +346,12 @@ 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/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/Split%20text%20by%20lines.md'>File on GitHub</a></td></tr><tr valign='top'><td class="label">Description</td><td class="data">Split lines of text into separate text elements for easier reorganization<br><img src='https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/images/scripts-split-lines.jpg'></td></tr></table>
|
||||
|
||||
## Text Arch
|
||||
```excalidraw-script-install
|
||||
https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Text%20Arch.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/Text%20Arch.md'>File on GitHub</a></td></tr><tr valign='top'><td class="label">Description</td><td class="data">Fit a text to the arch of a circle. The script will prompt you for the radius of the circle and then split your text to individual letters and place each letter to the arch defined by the radius. Setting a lower radius value will increase the arching of the text. Note that the arched-text will no longer be editable as a text element and it will no longer function as a markdown link. Emojis are currently not supported.<br><img src='https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/images/text-arch.jpg'></td></tr></table>
|
||||
|
||||
## Transfer TextElements to Excalidraw markdown metadata
|
||||
```excalidraw-script-install
|
||||
https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Transfer%20TextElements%20to%20Excalidraw%20markdown%20metadata.md
|
||||
|
||||
BIN
images/rename-image.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
images/scripts-grid-selected-images.png
Normal file
|
After Width: | Height: | Size: 113 KiB |
BIN
images/scripts-sketch-palette-loader-1.jpg
Normal file
|
After Width: | Height: | Size: 62 KiB |
BIN
images/scripts-sketch-palette-loader-2.jpg
Normal file
|
After Width: | Height: | Size: 41 KiB |
BIN
images/scripts-sketch-palette-loader-3.jpg
Normal file
|
After Width: | Height: | Size: 156 KiB |
BIN
images/scripts-sketch-palette-loader-4.jpg
Normal file
|
After Width: | Height: | Size: 247 KiB |
BIN
images/text-arch.jpg
Normal file
|
After Width: | Height: | Size: 95 KiB |
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "obsidian-excalidraw-plugin",
|
||||
"name": "Excalidraw",
|
||||
"version": "1.7.15",
|
||||
"version": "1.7.27",
|
||||
"minAppVersion": "0.15.6",
|
||||
"description": "An Obsidian plugin to edit and view Excalidraw drawings",
|
||||
"author": "Zsolt Viczian",
|
||||
|
||||
12
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "obsidian-excalidraw-plugin",
|
||||
"version": "1.7.11",
|
||||
"version": "1.7.26",
|
||||
"description": "This is an Obsidian.md plugin that lets you view and edit Excalidraw drawings",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/index.d.ts",
|
||||
@@ -18,14 +18,17 @@
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/lz-string": "^1.3.34",
|
||||
"@zsviczian/excalidraw": "0.12.0-obsidian-5",
|
||||
"@zsviczian/excalidraw": "0.13.0-obsidian-1",
|
||||
"clsx": "^1.1.1",
|
||||
"lz-string": "^1.4.4",
|
||||
"monkey-around": "^2.3.0",
|
||||
"react": "^17.0.2",
|
||||
"react-dom": "^17.0.2",
|
||||
"react-scripts": "^5.0.1",
|
||||
"roughjs": "^4.5.2"
|
||||
"roughjs": "^4.5.2",
|
||||
"colormaster": "1.2.1",
|
||||
"chroma-js": "^2.4.2",
|
||||
"gl-matrix": "^3.4.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.16.12",
|
||||
@@ -40,6 +43,7 @@
|
||||
"@rollup/plugin-replace": "^3.0.1",
|
||||
"@rollup/plugin-typescript": "^8.3.0",
|
||||
"@types/js-beautify": "^1.13.3",
|
||||
"@types/chroma-js": "^2.1.4",
|
||||
"@types/node": "^15.12.4",
|
||||
"@types/react-dom": "^17.0.2",
|
||||
"@zerollup/ts-transform-paths": "^1.7.18",
|
||||
@@ -48,7 +52,7 @@
|
||||
"eslint-plugin-prettier": "^4.0.0",
|
||||
"html2canvas": "^1.4.0",
|
||||
"nanoid": "^4.0.0",
|
||||
"obsidian": "^0.15.4",
|
||||
"obsidian": "^0.16.3",
|
||||
"prettier": "^2.5.1",
|
||||
"rollup": "^2.70.1",
|
||||
"rollup-plugin-copy": "^3.4.0",
|
||||
|
||||
@@ -27,11 +27,12 @@ import {
|
||||
decompress,
|
||||
//getBakPath,
|
||||
getBinaryFileFromDataURL,
|
||||
getContainerElement,
|
||||
getExportTheme,
|
||||
getLinkParts,
|
||||
hasExportTheme,
|
||||
LinkParts,
|
||||
wrapText,
|
||||
wrapTextAtCharLength,
|
||||
} from "./utils/Utils";
|
||||
import { getAttachmentsFolderAndFilePath, isObsidianThemeDark } from "./utils/ObsidianUtils";
|
||||
import {
|
||||
@@ -52,6 +53,13 @@ declare module "obsidian" {
|
||||
}
|
||||
}
|
||||
|
||||
const {
|
||||
wrapText,
|
||||
getFontString,
|
||||
getMaxContainerWidth,
|
||||
//@ts-ignore
|
||||
} = excalidrawLib;
|
||||
|
||||
export enum AutoexportPreference {
|
||||
none,
|
||||
both,
|
||||
@@ -210,15 +218,16 @@ const estimateMaxLineLen = (text: string, originalText: string): number => {
|
||||
return null;
|
||||
}
|
||||
for (const line of splitText) {
|
||||
if (line.length > maxLineLen) {
|
||||
maxLineLen = line.length;
|
||||
const l = line.trim();
|
||||
if (l.length > maxLineLen) {
|
||||
maxLineLen = l.length;
|
||||
}
|
||||
}
|
||||
return maxLineLen;
|
||||
};
|
||||
|
||||
const wrap = (text: string, lineLen: number) =>
|
||||
lineLen ? wrapText(text, lineLen, false, 0) : text;
|
||||
lineLen ? wrapTextAtCharLength(text, lineLen, false, 0) : text;
|
||||
|
||||
export class ExcalidrawData {
|
||||
public textElements: Map<
|
||||
@@ -488,7 +497,7 @@ export class ExcalidrawData {
|
||||
let res = data.matchAll(/\s\^(.{8})[\n]+/g);
|
||||
let parts;
|
||||
while (!(parts = res.next()).done) {
|
||||
const text = data.substring(position, parts.value.index);
|
||||
let text = data.substring(position, parts.value.index);
|
||||
const id: string = parts.value[1];
|
||||
const textEl = this.scene.elements.filter((el: any) => el.id === id)[0];
|
||||
if (textEl) {
|
||||
@@ -502,6 +511,13 @@ export class ExcalidrawData {
|
||||
this.elementLinks.set(id, text);
|
||||
} else {
|
||||
const wrapAt = estimateMaxLineLen(textEl.text, textEl.originalText);
|
||||
//https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/566
|
||||
const elementLinkRes = text.matchAll(/^%%\*\*\*>>>text element-link:(\[\[[^<*\]]*]])<<<\*\*\*%%/gm);
|
||||
const elementLink = elementLinkRes.next();
|
||||
if(!elementLink.done) {
|
||||
text = text.replace(/^%%\*\*\*>>>text element-link:\[\[[^<*\]]*]]<<<\*\*\*%%/gm,"");
|
||||
textEl.link = elementLink.value[1];
|
||||
}
|
||||
const parseRes = await this.parse(text);
|
||||
this.textElements.set(id, {
|
||||
raw: text,
|
||||
@@ -588,6 +604,7 @@ export class ExcalidrawData {
|
||||
}
|
||||
|
||||
public async setTextMode(textMode: TextMode, forceupdate: boolean = false) {
|
||||
if(!this.scene) return;
|
||||
this.textMode = textMode;
|
||||
await this.updateSceneTextElements(forceupdate);
|
||||
}
|
||||
@@ -630,12 +647,17 @@ export class ExcalidrawData {
|
||||
//first get scene text elements
|
||||
const texts = this.scene.elements?.filter((el: any) => el.type === "text");
|
||||
for (const te of texts) {
|
||||
const container = getContainerElement(te,this.scene);
|
||||
const originalText =
|
||||
(await this.getText(te.id, false)) ?? te.originalText ?? te.text;
|
||||
(await this.getText(te.id)) ?? te.originalText ?? te.text;
|
||||
const wrapAt = this.textElements.get(te.id)?.wrapAt;
|
||||
this.updateTextElement(
|
||||
te,
|
||||
wrap(originalText, wrapAt),
|
||||
wrapAt ? wrapText(
|
||||
originalText,
|
||||
getFontString(te.fontSize,te.fontFamily),
|
||||
getMaxContainerWidth(container)
|
||||
) : originalText,
|
||||
originalText,
|
||||
forceupdate,
|
||||
); //(await this.getText(te.id))??te.text serves the case when the whole #Text Elements section is deleted by accident
|
||||
@@ -644,7 +666,6 @@ export class ExcalidrawData {
|
||||
|
||||
private async getText(
|
||||
id: string,
|
||||
wrapResult: boolean = true,
|
||||
): Promise<string> {
|
||||
const text = this.textElements.get(id);
|
||||
if (!text) {
|
||||
@@ -659,7 +680,7 @@ export class ExcalidrawData {
|
||||
});
|
||||
}
|
||||
//console.log("parsed",this.textElements.get(id).parsed);
|
||||
return wrapResult ? wrap(text.parsed, text.wrapAt) : text.parsed;
|
||||
return text.parsed;
|
||||
}
|
||||
//console.log("raw",this.textElements.get(id).raw);
|
||||
return text.raw;
|
||||
@@ -739,7 +760,13 @@ export class ExcalidrawData {
|
||||
this.textElements.set(id, { raw, parsed: null, wrapAt });
|
||||
this.parseasync(id, raw, wrapAt);
|
||||
}
|
||||
} else if (!this.textElements.has(te.id)) {
|
||||
const raw = te.rawText && te.rawText !== "" ? te.rawText : te.text; //this is for compatibility with drawings created before the rawText change on ExcalidrawTextElement
|
||||
const wrapAt = estimateMaxLineLen(te.text, te.originalText);
|
||||
this.textElements.set(id, { raw, parsed: null, wrapAt });
|
||||
this.parseasync(id, raw, wrapAt);
|
||||
}
|
||||
|
||||
}
|
||||
if (dirty) {
|
||||
//reload scene json in case it has changed
|
||||
@@ -780,12 +807,15 @@ export class ExcalidrawData {
|
||||
if (el.length === 0) {
|
||||
this.textElements.delete(key); //if no longer in the scene, delete the text element
|
||||
} else {
|
||||
const text = await this.getText(key, false);
|
||||
const text = await this.getText(key);
|
||||
const raw = this.scene.prevTextMode === TextMode.parsed
|
||||
? el[0].rawText
|
||||
: (el[0].originalText ?? el[0].text);
|
||||
if (text !== (el[0].originalText ?? el[0].text)) {
|
||||
const wrapAt = estimateMaxLineLen(el[0].text, el[0].originalText);
|
||||
this.textElements.set(key, {
|
||||
raw: el[0].originalText ?? el[0].text,
|
||||
parsed: (await this.parse(el[0].originalText ?? el[0].text)).parsed,
|
||||
raw,
|
||||
parsed: (await this.parse(raw)).parsed,
|
||||
wrapAt,
|
||||
});
|
||||
}
|
||||
@@ -837,6 +867,7 @@ export class ExcalidrawData {
|
||||
* @returns
|
||||
*/
|
||||
private async parse(text: string): Promise<{ parsed: string; link: string }> {
|
||||
text = this.parseCheckbox(text);
|
||||
let outString = "";
|
||||
let link = null;
|
||||
let position = 0;
|
||||
@@ -859,11 +890,17 @@ export class ExcalidrawData {
|
||||
}
|
||||
if (REGEX_LINK.isTransclusion(parts)) {
|
||||
//transclusion //parts.value[1] || parts.value[4]
|
||||
const contents = (await this.getTransclusion(REGEX_LINK.getLink(parts)))
|
||||
.contents;
|
||||
let contents = this
|
||||
.parseCheckbox((await this.getTransclusion(REGEX_LINK.getLink(parts))).contents)
|
||||
.replaceAll(/%%[^%]*%%/gm,""); //remove comments, consequence of https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/566
|
||||
if(this.plugin.settings.removeTransclusionQuoteSigns) {
|
||||
//remove leading > signs from transcluded quotations; the first > sign is not explicitlyl removed becuse
|
||||
//Obsidian app.metadataCache.blockCache returns the block position already discarding the first '> '
|
||||
contents = contents.replaceAll(/\n\s*>\s?/gm,"\n");
|
||||
}
|
||||
outString +=
|
||||
text.substring(position, parts.value.index) +
|
||||
wrapText(
|
||||
wrapTextAtCharLength(
|
||||
contents,
|
||||
REGEX_LINK.getWrapLength(
|
||||
parts,
|
||||
@@ -897,6 +934,16 @@ export class ExcalidrawData {
|
||||
return { parsed: outString, link };
|
||||
}
|
||||
|
||||
private parseCheckbox(text:string):string {
|
||||
return this.plugin.settings.parseTODO
|
||||
? text
|
||||
.replaceAll(/^- \[\s] /g,`${this.plugin.settings.todo} `)
|
||||
.replaceAll(/\n- \[\s] /g,`\n${this.plugin.settings.todo} `)
|
||||
.replaceAll(/^- \[[^\s]] /g,`${this.plugin.settings.done} `)
|
||||
.replaceAll(/\n- \[[^\s]] /g,`\n${this.plugin.settings.done} `)
|
||||
: text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does a quick parse of the raw text. Returns the parsed string if raw text does not include a transclusion.
|
||||
* Return null if raw text includes a transclusion.
|
||||
@@ -918,7 +965,7 @@ export class ExcalidrawData {
|
||||
if (hasTransclusion(text)) {
|
||||
return [null, null];
|
||||
}
|
||||
|
||||
text = this.parseCheckbox(text);
|
||||
let outString = "";
|
||||
let link = null;
|
||||
let position = 0;
|
||||
@@ -970,7 +1017,15 @@ export class ExcalidrawData {
|
||||
generateMD(deletedElements: ExcalidrawElement[] = []): string {
|
||||
let outString = "# Text Elements\n";
|
||||
for (const key of this.textElements.keys()) {
|
||||
outString += `${this.textElements.get(key).raw} ^${key}\n\n`;
|
||||
//https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/566
|
||||
const element = this.scene.elements.filter((el:any)=>el.id===key);
|
||||
let elementString = this.textElements.get(key).raw;
|
||||
if(element && element.length===1 && element[0].link && element[0].rawText === element[0].originalText) {
|
||||
if(element[0].link.match(/^\[\[[^\]]*]]$/g)) { //apply this only to markdown links
|
||||
elementString = `%%***>>>text element-link:${element[0].link}<<<***%%` + elementString;
|
||||
}
|
||||
}
|
||||
outString += `${elementString} ^${key}\n\n`;
|
||||
}
|
||||
|
||||
for (const key of this.elementLinks.keys()) {
|
||||
@@ -988,7 +1043,13 @@ export class ExcalidrawData {
|
||||
}
|
||||
if (this.files.size > 0) {
|
||||
for (const key of this.files.keys()) {
|
||||
outString += `${key}: [[${this.files.get(key).linkParts.original}]]\n`;
|
||||
const PATHREG = /(^[^#\|]*)/;
|
||||
const ef = this.files.get(key);
|
||||
//https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/829
|
||||
const path = ef.file
|
||||
? ef.linkParts.original.replace(PATHREG,app.metadataCache.fileToLinktext(ef.file,this.file.path))
|
||||
: ef.linkParts.original;
|
||||
outString += `${key}: [[${path}]]\n`;
|
||||
}
|
||||
}
|
||||
outString += this.equations.size > 0 || this.files.size > 0 ? "\n" : "";
|
||||
@@ -1039,7 +1100,7 @@ export class ExcalidrawData {
|
||||
});
|
||||
|
||||
//check if there are any images that need to be processed in the new scene
|
||||
if (!scene.files || scene.files == {}) {
|
||||
if (!scene.files || Object.keys(scene.files).length === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1055,7 +1116,7 @@ export class ExcalidrawData {
|
||||
const equation = this.getEquation(fileId);
|
||||
//const equation = this.equations.get(fileId as FileId);
|
||||
//images should have a single reference, but equations and markdown embeds should have as many as instances of the file in the scene
|
||||
if(file && (file.file.extension !== "md" || this.plugin.isExcalidrawFile(file.file))) {
|
||||
if(file && file.file && (file.file.extension !== "md" || this.plugin.isExcalidrawFile(file.file))) {
|
||||
return;
|
||||
}
|
||||
const newId = fileid();
|
||||
@@ -1386,7 +1447,7 @@ export class ExcalidrawData {
|
||||
|
||||
const parts = data.linkParts.original.split("#");
|
||||
this.plugin.filesMaster.set(fileId, {
|
||||
path:data.file.path,
|
||||
path:data.file.path + (data.shouldScale()?"":"|100%"),
|
||||
blockrefData: parts.length === 1
|
||||
? null
|
||||
: parts[1],
|
||||
@@ -1431,16 +1492,18 @@ export class ExcalidrawData {
|
||||
}
|
||||
if (this.plugin.filesMaster.has(fileId)) {
|
||||
const masterFile = this.plugin.filesMaster.get(fileId);
|
||||
if (!this.app.vault.getAbstractFileByPath(masterFile.path)) {
|
||||
const path = masterFile.path.split("|")[0].split("#")[0];
|
||||
if (!this.app.vault.getAbstractFileByPath(path)) {
|
||||
this.plugin.filesMaster.delete(fileId);
|
||||
return true;
|
||||
} // the file no longer exists
|
||||
const fixScale = masterFile.path.endsWith("100%");
|
||||
const embeddedFile = new EmbeddedFile(
|
||||
this.plugin,
|
||||
this.file.path,
|
||||
masterFile.blockrefData
|
||||
? masterFile.path + "#" + masterFile.blockrefData
|
||||
: masterFile.path
|
||||
(masterFile.blockrefData
|
||||
? path + "#" + masterFile.blockrefData
|
||||
: path) + (fixScale?"|100%":"")
|
||||
);
|
||||
this.files.set(fileId, embeddedFile);
|
||||
return true;
|
||||
@@ -1531,15 +1594,15 @@ export const getTransclusion = async (
|
||||
if (!para) {
|
||||
return { contents: linkParts.original.trim(), lineNum: 0 };
|
||||
}
|
||||
if (["blockquote", "listItem"].includes(para.type)) {
|
||||
if (["blockquote"].includes(para.type)) {
|
||||
para = para.children[0];
|
||||
} //blockquotes are special, they have one child, which has the paragraph
|
||||
const startPos = para.position.start.offset;
|
||||
const lineNum = para.position.start.line;
|
||||
const endPos =
|
||||
para.children[para.children.length - 1]?.position.start.offset - 1; //alternative: filter((c:any)=>c.type=="blockid")[0]
|
||||
const endPos = para.position.end.offset; //https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/853
|
||||
//para.children[para.children.length - 1]?.position.start.offset - 1; //!not clear what the side effect of the #853 change is
|
||||
return {
|
||||
contents: contents.substring(startPos, endPos).trim(),
|
||||
contents: contents.substring(startPos, endPos).replaceAll(/ \^\S*$|^\^\S*$/gm,"").trim(), //remove the block reference from the end of the line, or from the beginning of a new line
|
||||
lineNum,
|
||||
};
|
||||
}
|
||||
@@ -1590,7 +1653,7 @@ export const getTransclusion = async (
|
||||
return {
|
||||
leadingHashes: "#".repeat(depth) + " ",
|
||||
contents: contents.substring(startPos).trim(),
|
||||
lineNum
|
||||
lineNum
|
||||
};
|
||||
}
|
||||
return { contents: linkParts.original.trim(), lineNum: 0 };
|
||||
|
||||
@@ -27,6 +27,7 @@ export const updateEquation = async (
|
||||
created: data.created,
|
||||
size: data.size,
|
||||
hasSVGwithBitmap: false,
|
||||
shouldScale: true,
|
||||
});
|
||||
addFiles(files, view);
|
||||
}
|
||||
|
||||
@@ -20,13 +20,15 @@ export const REG_LINKINDEX_INVALIDCHARS = /[<>:"\\|?*#]/g;
|
||||
export const REG_BLOCK_REF_CLEAN =
|
||||
/[!"#$%&()*+,.:;<=>?@^`{|}~\/\[\]\\]/g; //https://discord.com/channels/686053708261228577/989603365606531104/1000128926619816048
|
||||
// /\+|\/|~|=|%|\(|\)|{|}|,|&|\.|\$|!|\?|;|\[|]|\^|#|\*|<|>|&|@|\||\\|"|:|\s/g;
|
||||
export const IMAGE_TYPES = ["jpeg", "jpg", "png", "gif", "svg"];
|
||||
export const IMAGE_TYPES = ["jpeg", "jpg", "png", "gif", "svg", "webp", "bmp", "ico"];
|
||||
export const EXPORT_TYPES = ["svg", "dark.svg", "light.svg", "png", "dark.png", "light.png"];
|
||||
export const MAX_IMAGE_SIZE = 500;
|
||||
export const FRONTMATTER_KEY = "excalidraw-plugin";
|
||||
export const FRONTMATTER_KEY_EXPORT_TRANSPARENT =
|
||||
"excalidraw-export-transparent";
|
||||
export const FRONTMATTER_KEY_EXPORT_DARK = "excalidraw-export-dark";
|
||||
export const FRONTMATTER_KEY_EXPORT_SVGPADDING = "excalidraw-export-svgpadding";
|
||||
export const FRONTMATTER_KEY_EXPORT_SVGPADDING = "excalidraw-export-svgpadding"; //depricated
|
||||
export const FRONTMATTER_KEY_EXPORT_PADDING = "excalidraw-export-padding";
|
||||
export const FRONTMATTER_KEY_EXPORT_PNGSCALE = "excalidraw-export-pngscale";
|
||||
export const FRONTMATTER_KEY_CUSTOM_PREFIX = "excalidraw-link-prefix";
|
||||
export const FRONTMATTER_KEY_CUSTOM_URL_PREFIX = "excalidraw-url-prefix";
|
||||
@@ -208,7 +210,7 @@ COLOR_NAMES.set("white", "#ffffff");
|
||||
COLOR_NAMES.set("whitesmoke", "#f5f5f5");
|
||||
COLOR_NAMES.set("yellow", "#ffff00");
|
||||
COLOR_NAMES.set("yellowgreen", "#9acd32");
|
||||
export const DEFAULT_MD_EMBED_CSS = `.excalidraw-md-host{padding:0px 10px}.excalidraw-md-footer{height:5px}foreignObject{background-color:transparent}p{display:block;margin-block-start:1em;margin-block-end:1em;margin-inline-start:0px;margin-inline-end:0px;color:inherit}table,tr,th,td{color:inherit;border:1px solid;border-collapse:collapse;padding:3px}th{font-weight:bold;border-bottom:double;background-color:silver}.copy-code-button{display:none}code[class*=language-],pre[class*=language-]{color:#393a34;font-family:"Consolas","Bitstream Vera Sans Mono","Courier New",Courier,monospace;direction:ltr;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;font-size:.9em;line-height:1.2em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}pre>code[class*=language-]{font-size:1em}pre[class*=language-]::-moz-selection,pre[class*=language-] ::-moz-selection,code[class*=language-]::-moz-selection,code[class*=language-] ::-moz-selection{background:#C1DEF1}pre[class*=language-]::selection,pre[class*=language-] ::selection,code[class*=language-]::selection,code[class*=language-] ::selection{background:#C1DEF1}pre[class*=language-]{padding:1em;margin:.5em 0;overflow:auto;background-color:#0000001a}:not(pre)>code[class*=language-]{padding:.2em;padding-top:1px;padding-bottom:1px;background:#f8f8f8;border:1px solid #dddddd}.token.comment,.token.prolog,.token.doctype,.token.cdata{color:green;font-style:italic}.token.namespace{opacity:.7}.token.string{color:#a31515}.token.punctuation,.token.operator{color:#393a34}.token.url,.token.symbol,.token.number,.token.boolean,.token.variable,.token.constant,.token.inserted{color:#36acaa}.token.atrule,.token.keyword,.token.attr-value,.language-autohotkey .token.selector,.language-json .token.boolean,.language-json .token.number,code[class*=language-css]{color:#00f}.token.function{color:#393a34}.token.deleted,.language-autohotkey .token.tag{color:#9a050f}.token.selector,.language-autohotkey .token.keyword{color:#00009f}.token.important{color:#e90}.token.important,.token.bold{font-weight:bold}.token.italic{font-style:italic}.token.class-name,.language-json .token.property{color:#2b91af}.token.tag,.token.selector{color:maroon}.token.attr-name,.token.property,.token.regex,.token.entity{color:red}.token.directive.tag .tag{background:#ffff00;color:#393a34}.line-numbers.line-numbers .line-numbers-rows{border-right-color:#a5a5a5}.line-numbers .line-numbers-rows>span:before{color:#2b91af}.line-highlight.line-highlight{background:rgba(193,222,241,.2);background:-webkit-linear-gradient(left,rgba(193,222,241,.2) 70%,rgba(221,222,241,0));background:linear-gradient(to right,rgba(193,222,241,.2) 70%,rgba(221,222,241,0))}blockquote{ font-style:italic;background-color:rgb(46,43,42,0.1);margin:0;margin-left:1em;border-radius:0 4px 4px 0;border:1px solid hsl(0,80%,32%);border-left-width:8px;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;padding:10px 20px;margin-inline-start:30px;margin-inline-end:30px;}`;
|
||||
export const DEFAULT_MD_EMBED_CSS = `.snw-reference{display: none;}.excalidraw-md-host{padding:0px 10px}.excalidraw-md-footer{height:5px}foreignObject{background-color:transparent}p{display:block;margin-block-start:1em;margin-block-end:1em;margin-inline-start:0px;margin-inline-end:0px;color:inherit}table,tr,th,td{color:inherit;border:1px solid;border-collapse:collapse;padding:3px}th{font-weight:bold;border-bottom:double;background-color:silver}.copy-code-button{display:none}code[class*=language-],pre[class*=language-]{color:#393a34;font-family:"Consolas","Bitstream Vera Sans Mono","Courier New",Courier,monospace;direction:ltr;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;font-size:.9em;line-height:1.2em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}pre>code[class*=language-]{font-size:1em}pre[class*=language-]::-moz-selection,pre[class*=language-] ::-moz-selection,code[class*=language-]::-moz-selection,code[class*=language-] ::-moz-selection{background:#C1DEF1}pre[class*=language-]::selection,pre[class*=language-] ::selection,code[class*=language-]::selection,code[class*=language-] ::selection{background:#C1DEF1}pre[class*=language-]{padding:1em;margin:.5em 0;overflow:auto;background-color:#0000001a}:not(pre)>code[class*=language-]{padding:.2em;padding-top:1px;padding-bottom:1px;background:#f8f8f8;border:1px solid #dddddd}.token.comment,.token.prolog,.token.doctype,.token.cdata{color:green;font-style:italic}.token.namespace{opacity:.7}.token.string{color:#a31515}.token.punctuation,.token.operator{color:#393a34}.token.url,.token.symbol,.token.number,.token.boolean,.token.variable,.token.constant,.token.inserted{color:#36acaa}.token.atrule,.token.keyword,.token.attr-value,.language-autohotkey .token.selector,.language-json .token.boolean,.language-json .token.number,code[class*=language-css]{color:#00f}.token.function{color:#393a34}.token.deleted,.language-autohotkey .token.tag{color:#9a050f}.token.selector,.language-autohotkey .token.keyword{color:#00009f}.token.important{color:#e90}.token.important,.token.bold{font-weight:bold}.token.italic{font-style:italic}.token.class-name,.language-json .token.property{color:#2b91af}.token.tag,.token.selector{color:maroon}.token.attr-name,.token.property,.token.regex,.token.entity{color:red}.token.directive.tag .tag{background:#ffff00;color:#393a34}.line-numbers.line-numbers .line-numbers-rows{border-right-color:#a5a5a5}.line-numbers .line-numbers-rows>span:before{color:#2b91af}.line-highlight.line-highlight{background:rgba(193,222,241,.2);background:-webkit-linear-gradient(left,rgba(193,222,241,.2) 70%,rgba(221,222,241,0));background:linear-gradient(to right,rgba(193,222,241,.2) 70%,rgba(221,222,241,0))}blockquote{ font-style:italic;background-color:rgb(46,43,42,0.1);margin:0;margin-left:1em;border-radius:0 4px 4px 0;border:1px solid hsl(0,80%,32%);border-left-width:8px;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;padding:10px 20px;margin-inline-start:30px;margin-inline-end:30px;}`;
|
||||
export const SCRIPTENGINE_ICON = `<g transform="translate(-8,-8)"><path d="M24.318 37.983c-1.234-1.232-8.433-3.903-7.401-7.387 1.057-3.484 9.893-12.443 13.669-13.517 3.776-1.074 6.142 6.523 9.012 7.073 2.87.55 6.797-1.572 8.207-3.694 1.384-2.148-3.147-7.413.15-9.168 3.298-1.755 16.389-2.646 19.611-1.284 3.247 1.363-1.611 7.335-.151 9.483 1.46 2.148 6.067 3.746 8.836 3.38 2.769-.368 4.154-6.733 7.728-5.633 3.575 1.1 12.36 8.828 13.67 12.233 1.308 3.406-5.186 5.423-5.79 8.2-.58 2.75-.026 6.705 2.265 8.355 2.266 1.65 9.642-1.78 11.404 1.598 1.762 3.38 1.007 15.35-.806 18.651-1.787 3.353-7.753-.367-9.969 1.31-2.215 1.65-3.901 5.92-3.373 8.67.504 2.777 7.754 4.48 6.445 7.885C96.49 87.543 87.15 95.454 83.5 96.685c-3.65 1.231-4.96-4.741-7.577-5.16-2.593-.393-6.57.707-8.03 2.75-1.436 2.017 2.668 7.806-.63 9.483-3.323 1.676-15.759 2.226-19.157.655-3.373-1.598.554-7.964-1.108-10.138-1.687-2.174-6.394-3.431-9.012-2.907-2.643.55-3.273 7.282-6.747 6.103-3.499-1.126-12.788-9.535-14.172-13.019-1.36-3.484 5.437-5.108 5.966-7.858.529-2.777-.68-7.073-2.744-8.697-2.064-1.624-7.93 2.41-9.642-1.126-1.737-3.537-2.441-16.765-.654-20.118 1.787-3.3 9.062 1.598 11.429.183 2.366-1.44 2.316-7.282 2.769-8.749m.126-.104c-1.234-1.232-8.433-3.903-7.401-7.387 1.057-3.484 9.893-12.443 13.669-13.517 3.776-1.074 6.142 6.523 9.012 7.073 2.87.55 6.797-1.572 8.207-3.694 1.384-2.148-3.147-7.413.15-9.168 3.298-1.755 16.389-2.646 19.611-1.284 3.247 1.363-1.611 7.335-.151 9.483 1.46 2.148 6.067 3.746 8.836 3.38 2.769-.368 4.154-6.733 7.728-5.633 3.575 1.1 12.36 8.828 13.67 12.233 1.308 3.406-5.186 5.423-5.79 8.2-.58 2.75-.026 6.705 2.265 8.355 2.266 1.65 9.642-1.78 11.404 1.598 1.762 3.38 1.007 15.35-.806 18.651-1.787 3.353-7.753-.367-9.969 1.31-2.215 1.65-3.901 5.92-3.373 8.67.504 2.777 7.754 4.48 6.445 7.885C96.49 87.543 87.15 95.454 83.5 96.685c-3.65 1.231-4.96-4.741-7.577-5.16-2.593-.393-6.57.707-8.03 2.75-1.436 2.017 2.668 7.806-.63 9.483-3.323 1.676-15.759 2.226-19.157.655-3.373-1.598.554-7.964-1.108-10.138-1.687-2.174-6.394-3.431-9.012-2.907-2.643.55-3.273 7.282-6.747 6.103-3.499-1.126-12.788-9.535-14.172-13.019-1.36-3.484 5.437-5.108 5.966-7.858.529-2.777-.68-7.073-2.744-8.697-2.064-1.624-7.93 2.41-9.642-1.126-1.737-3.537-2.441-16.765-.654-20.118 1.787-3.3 9.062 1.598 11.429.183 2.366-1.44 2.316-7.282 2.769-8.749" fill="none" stroke-width="2" stroke-linecap="round" stroke="currentColor"/><path d="M81.235 56.502a23.3 23.3 0 0 1-1.46 8.068 20.785 20.785 0 0 1-1.762 3.72 24.068 24.068 0 0 1-5.337 6.26 22.575 22.575 0 0 1-3.449 2.358 23.726 23.726 0 0 1-7.803 2.803 24.719 24.719 0 0 1-8.333 0 24.102 24.102 0 0 1-4.028-1.074 23.71 23.71 0 0 1-3.776-1.729 23.259 23.259 0 0 1-6.369-5.265 23.775 23.775 0 0 1-2.416-3.353 24.935 24.935 0 0 1-1.762-3.72 23.765 23.765 0 0 1-1.083-3.981 23.454 23.454 0 0 1 0-8.173c.252-1.336.604-2.698 1.083-3.956a24.935 24.935 0 0 1 1.762-3.72 22.587 22.587 0 0 1 2.416-3.378c.881-1.048 1.888-2.017 2.946-2.908a24.38 24.38 0 0 1 3.423-2.357 23.71 23.71 0 0 1 3.776-1.73 21.74 21.74 0 0 1 4.028-1.047 23.437 23.437 0 0 1 8.333 0 24.282 24.282 0 0 1 7.803 2.777 26.198 26.198 0 0 1 3.45 2.357 24.62 24.62 0 0 1 5.336 6.287 20.785 20.785 0 0 1 1.762 3.72 21.32 21.32 0 0 1 1.083 3.955c.251 1.336.302 3.405.377 4.086.05.681.05-.68 0 0" fill="none" stroke-width="4" stroke-linecap="round" stroke="currentColor"/><path d="M69.404 56.633c-6.596-3.3-13.216-6.6-19.51-9.744m19.51 9.744c-6.747-3.379-13.493-6.758-19.51-9.744m0 0v19.489m0-19.49v19.49m0 0c4.355-2.148 8.71-4.322 19.51-9.745m-19.51 9.745c3.978-1.965 7.93-3.956 19.51-9.745m0 0h0m0 0h0" fill="currentColor" stroke-linecap="round" stroke="currentColor" stroke-width="4"/></g>`;
|
||||
export const DISK_ICON_NAME = "disk";
|
||||
export const DISK_ICON = `<path fill="none" stroke="currentColor" fill="#fff" d="M0 0h100v100H0z"/><path fill="none" stroke="currentColor" d="M20.832 4.168c21.824.145 43.645.289 74.68.5m-74.68-.5c17.09.113 34.176.227 74.68.5m0 0c.094 27.3.191 54.602.32 91.164m-.32-91.164c.113 32.633.23 65.27.32 91.164m0 0H4.168m91.664 0H4.168m0 0v-75m0 75v-75m0 0L20.832 4.168M4.168 20.832L20.832 4.168M20.832 4.168h58.336m-58.336 0h58.336m0 0v25m0-25v25m0 0H20.832m58.336 0H20.832m0 0v-25m0 25v-25" stroke-width="1.66668" /><path fill="none" stroke="currentColor" d="M29.168 4.168h16.664v16.664H29.168"/><path fill="none" stroke="currentColor" d="M29.168 4.168h16.664m-16.664 0h16.664m0 0v16.664m0-16.664v16.664m0 0H29.168m16.664 0H29.168m0 0V4.168m0 16.664V4.168M12.5 54.168h75m-75 0h75m0 0v41.664m0-41.664v41.664m0 0h-75m75 0h-75m0 0V54.168m0 41.664V54.168M20.832 62.5c20.11-.18 40.219-.36 55.68-.5m-55.68.5c14.656-.133 29.313-.262 55.68-.5M20.832 71.332c13.098-.117 26.2-.234 55.68-.5m-55.68.5l55.68-.5M21.117 79.582c20.645-.184 41.285-.371 55.68-.5m-55.68.5c18.153-.16 36.301-.324 55.68-.5" stroke-width="1.66668"/>`;
|
||||
|
||||
54
src/dialogs/ImportSVGDialog.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { App, FuzzySuggestModal, TFile } from "obsidian";
|
||||
import { REG_LINKINDEX_INVALIDCHARS } from "../Constants";
|
||||
import ExcalidrawView from "../ExcalidrawView";
|
||||
import { t } from "../lang/helpers";
|
||||
import ExcalidrawPlugin from "../main";
|
||||
|
||||
export class ImportSVGDialog extends FuzzySuggestModal<TFile> {
|
||||
public app: App;
|
||||
public plugin: ExcalidrawPlugin;
|
||||
private view: ExcalidrawView;
|
||||
|
||||
constructor(plugin: ExcalidrawPlugin) {
|
||||
super(plugin.app);
|
||||
this.plugin = plugin;
|
||||
this.app = plugin.app;
|
||||
this.limit = 20;
|
||||
this.setInstructions([
|
||||
{
|
||||
command: t("SELECT_FILE"),
|
||||
purpose: "",
|
||||
},
|
||||
]);
|
||||
this.setPlaceholder(t("SELECT_DRAWING"));
|
||||
this.emptyStateText = t("NO_MATCH");
|
||||
}
|
||||
|
||||
getItems(): TFile[] {
|
||||
return (this.app.vault.getFiles() || []).filter(
|
||||
(f: TFile) => f.extension === "svg" &&
|
||||
//https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/422
|
||||
!f.path.match(REG_LINKINDEX_INVALIDCHARS),
|
||||
);
|
||||
}
|
||||
|
||||
getItemText(item: TFile): string {
|
||||
return item.path;
|
||||
}
|
||||
|
||||
async onChooseItem(item: TFile, event: KeyboardEvent): Promise<void> {
|
||||
if(!item) return;
|
||||
const ea = this.plugin.ea;
|
||||
ea.reset();
|
||||
ea.setView(this.view);
|
||||
const svg = await app.vault.read(item);
|
||||
if(!svg || svg === "") return;
|
||||
ea.importSVG(svg);
|
||||
ea.addElementsToView(true, true, true);
|
||||
}
|
||||
|
||||
public start(view: ExcalidrawView) {
|
||||
this.view = view;
|
||||
this.open();
|
||||
}
|
||||
}
|
||||
@@ -17,12 +17,23 @@ export class InsertImageDialog extends FuzzySuggestModal<TFile> {
|
||||
this.limit = 20;
|
||||
this.setInstructions([
|
||||
{
|
||||
command: t("SELECT_FILE"),
|
||||
command: t("SELECT_FILE_WITH_OPTION_TO_SCALE"),
|
||||
purpose: "",
|
||||
},
|
||||
]);
|
||||
this.setPlaceholder(t("SELECT_DRAWING"));
|
||||
this.emptyStateText = t("NO_MATCH");
|
||||
this.inputEl.onkeyup = (e) => {
|
||||
//@ts-ignore
|
||||
if (e.key === "Enter" && e.altKey && this.chooser.values) {
|
||||
this.onChooseItem(
|
||||
//@ts-ignore
|
||||
this.chooser.values[this.chooser.selectedItem].item,
|
||||
new KeyboardEvent("keypress",{altKey: true})
|
||||
);
|
||||
this.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getItems(): TFile[] {
|
||||
@@ -39,13 +50,13 @@ export class InsertImageDialog extends FuzzySuggestModal<TFile> {
|
||||
return item.path;
|
||||
}
|
||||
|
||||
onChooseItem(item: TFile): void {
|
||||
onChooseItem(item: TFile, event: KeyboardEvent): void {
|
||||
const ea = this.plugin.ea;
|
||||
ea.reset();
|
||||
ea.setView(this.view);
|
||||
ea.canvas.theme = this.view.excalidrawAPI.getAppState().theme;
|
||||
(async () => {
|
||||
await ea.addImage(0, 0, item);
|
||||
await ea.addImage(0, 0, item, !event.altKey);
|
||||
ea.addElementsToView(true, false, true);
|
||||
})();
|
||||
}
|
||||
|
||||
@@ -11,14 +11,162 @@ Thank you & Enjoy!
|
||||
`;
|
||||
|
||||
export const RELEASE_NOTES: { [k: string]: string } = {
|
||||
Intro: `I want to help you keep up with all the updates. After installing each release, you'll be prompted with a summary of new features and fixes. You can disable these popup messages in plugin settings.
|
||||
Intro: `After each update you'll be prompted with the release notes. You can disable this in plugin settings.
|
||||
|
||||
I develop this plugin as a hobby, spending most of my free time doing this. If you'd like to contribute to the on-going work, I have a simple membership scheme with Bronze, Silver and Gold tiers. Many of you have already bought me a coffee. THANK YOU! It really means a lot to me! If you find this plugin valuable, please consider supporting me.
|
||||
I develop this plugin as a hobby, spending my free time doing this. If you find it valuable, then please say THANK YOU or...
|
||||
|
||||
<div class="ex-coffee-div"><a href="https://ko-fi.com/zsolt"><img src="https://cdn.ko-fi.com/cdn/kofi3.png?v=3" height=45></a></div>
|
||||
`,
|
||||
"1.7.15":`
|
||||
"1.7.27":`## New
|
||||
- Import SVG drawing as an Excalidraw object. [#679](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/679)
|
||||
|
||||
<div class="excalidraw-videoWrapper"><div>
|
||||
<iframe src="https://www.youtube.com/embed/vlC1-iBvIfo" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
|
||||
</div></div>
|
||||
|
||||
## Fixed
|
||||
- Large drawings freeze on the iPad when opening the file. I implemented a workaround whereby Excalidraw will avoid zoom-to-fit drawings with over 1000 elements. [#863](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/863)
|
||||
- Reintroduced copy/paste to the context menu
|
||||
`,
|
||||
"1.7.26":`## Fixed
|
||||
- Transcluded block with a parent bullet does not embed sub-bullet [#853](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/853)
|
||||
- Transcluded text will now exclude ^block-references at end of lines
|
||||
- Phantom duplicates of the drawing appear when "zoom to fit" results in a zoom value below 10% and there are many objects on the canvas [#850](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/850)
|
||||
- CTRL+Wheel will increase/decrease zoom in steps of 5% matching the behavior of the "+" & "-" zoom buttons.
|
||||
- Latest updates from Excalidarw.com
|
||||
- Freedraw flip not scaling correctly [#5752](https://github.com/excalidraw/excalidraw/pull/5752)
|
||||
- Multiple elements resizing regressions [#5586](https://github.com/excalidraw/excalidraw/pull/5586)
|
||||
|
||||
## New - power user features
|
||||
- Force the embedded image to always scale to 100%. Note: this is a very niche feature with a very particular behavior that I built primarily for myself (even more so than other features in Excalidraw Obsidian - also built primarily for myself 😉)... This will reset your embedded image to 100% size every time you open the Excalidraw drawing, or in case you have embedded an Excalidraw drawing on your canvas inserted using this function, every time you update the embedded drawing, it will be scaled back to 100% size. This means that even if you resize the image on the drawing, it will reset to 100% the next time you open the file or you modify the original embedded object. This feature is useful when you decompose a drawing into separate Excalidraw files, but when combined onto a single canvas you want the individual pieces to maintain their actual sizes. I use this feature to construct Book-on-a-Page summaries from atomic drawings.
|
||||
- I added an action to the command palette to temporarily disable/enable Excalidraw autosave. When autosave is disabled, Excalidraw will still save your drawing when changing to another Obsidian window, but it will not save every 10 seconds. On a mobile device (but also on a desktop) this can lead to data loss if you terminate Obsidian abruptly (i.e. swipe the application away, or close Obsidian without first closing the drawing). Use this feature if you find Excalidraw laggy.`,
|
||||
"1.7.25":`## Fixed
|
||||
- Tool buttons did not "stick" the first time you clicked them.
|
||||
- Tray (in tray mode) was higher when the help button was visible. The tray in tablet mode was too large and the help button was missing.
|
||||
- ExcalidrawAutomate ${String.fromCharCode(96)}getCM(color:TInput): ColorMaster;${String.fromCharCode(96)} function will now properly convert valid [css color names](https://www.w3schools.com/colors/colors_names.asp) to ColorMaster objects.
|
||||
- The downloaded script icons in the Excalidraw-Obsidian menu were not always correct
|
||||
- The obsidian mobile navigation bar at the bottom overlapped with Excalidraw
|
||||
|
||||
## New
|
||||
- Created ExcalidrawAutomate hook for styling script when the canvas color changes. See sample [onCanvasColorChangeHook](https://gist.github.com/zsviczian/c7223c5b4af30d5c88a0cae05300305c) implementation following the link.
|
||||
|
||||
<div class="excalidraw-videoWrapper"><div>
|
||||
<iframe src="https://www.youtube.com/embed/LtR04fNTKTM" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
|
||||
</div></div>
|
||||
|
||||
${String.fromCharCode(96, 96, 96)}typescript
|
||||
/**
|
||||
* If set, this callback is triggered whenever the active canvas color changes
|
||||
*/
|
||||
onCanvasColorChangeHook: (
|
||||
ea: ExcalidrawAutomate,
|
||||
view: ExcalidrawView, //the Excalidraw view
|
||||
color: string,
|
||||
) => void = null;
|
||||
${String.fromCharCode(96, 96, 96)}
|
||||
`,
|
||||
"1.7.24":`
|
||||
# New and improved
|
||||
- **Updated Chinese translation**. Thanks, @tswwe!
|
||||
- **Improved update for TextElement links**: Until now, when you attached a link to a file to a TextElement using the "Create Link" command, this link did not get updated when the file was renamed or moved. Only links created as markdown links in the TextElement text were updated. Now both approaches work. Keep in mind however, that if you have a link in the TextElemenet text, it will override the link attached to the text element using the create link command. [#566](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/566)
|
||||
- **Transclusion filters markdown comments**: Text transclusion in a TextElement using the ${String.fromCharCode(96)}![[file]]${String.fromCharCode(96)} or ${String.fromCharCode(96)}![[file#section]]${String.fromCharCode(96)} format did not filter out markdown comments in the file placed ${String.fromCharCode(96)}%% inside a comment block %%${String.fromCharCode(96)}. Now they do.
|
||||
- **Remove leading '>' from trancluded quotes**: Added a new option in settings under **Links and Transclusion** to remove the leading ${String.fromCharCode(96)}> ${String.fromCharCode(96)} characters from quotes you transclude as a text element in your drawing.
|
||||

|
||||
- **Added support for ${String.fromCharCode(96)}webp${String.fromCharCode(96)}, ${String.fromCharCode(96)}bmp${String.fromCharCode(96)}, and ${String.fromCharCode(96)}ico${String.fromCharCode(96)} images**. This extends the already supported formats (${String.fromCharCode(96)}jpg${String.fromCharCode(96)}, ${String.fromCharCode(96)}gif${String.fromCharCode(96)}, ${String.fromCharCode(96)}png${String.fromCharCode(96)}, ${String.fromCharCode(96)}svg${String.fromCharCode(96)}).
|
||||
- **Added command palette action to reset images to original size**. Select a single image or embedded Excalidraw drawing on your canvas and choose ${String.fromCharCode(96)}Set selected image element size to 100% of original${String.fromCharCode(96)} from the command palette. This function is especially helpful when you combine atomic drawings on a single canvas, keeping each atomic piece in its original excalidraw file (i.e. the way I create [book on a page summaries](https://www.youtube.com/playlist?list=PL6mqgtMZ4NP1-mbCYc3T7mr-unmsIXpEG))
|
||||
- The ${String.fromCharCode(96)}async getOriginalImageSize(imageElement: ExcalidrawImageElement): Promise<{width: number; height: number}>${String.fromCharCode(96)} function is also avaiable via ExcalidrawAutomate. You may use this function to resize images to custom scales (e.g. 50% size, or to fit a certain bounding rectangle).
|
||||
|
||||
# Fixed
|
||||
- **Upgraded perfect freehand package to resolve unwanted dots on end of lines** [#5727](https://github.com/excalidraw/excalidraw/pull/5727)
|
||||
- **Pinch zoom in View mode opens images** resulting in a very annoying behavior [#837](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/837)
|
||||
- **Embedded files** such as transcluded markdown documents and images **did not honor the Obsidian "New Link Format" setting** (shortest path, relative path, absolute path). [#829](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/829)
|
||||
- **Fixed error with dataview queries involving Excalidraw files**: In case you created a task on an Excalidraw canvas (${String.fromCharCode(96)}docA.md${String.fromCharCode(96)}) by typing ${String.fromCharCode(96)}- [ ] Task [[owner]] #tag${String.fromCharCode(96)}, and then you created a Dataview tasklist in another document (${String.fromCharCode(96)}docB.md${String.fromCharCode(96)}) such that the query criteria matched the task in ${String.fromCharCode(96)}docA.md${String.fromCharCode(96)}, then the task from ${String.fromCharCode(96)}docA.md${String.fromCharCode(96)} only appeared as an empty line when viewing ${String.fromCharCode(96)}docB.md${String.fromCharCode(96)}. If you now embedded ${String.fromCharCode(96)}docB.md${String.fromCharCode(96)} into a third markdown document (${String.fromCharCode(96)}docC.md${String.fromCharCode(96)}), then instead of the contents of ${String.fromCharCode(96)}docB.md${String.fromCharCode(96)} Obsidian rendered ${String.fromCharCode(96)}docA.md${String.fromCharCode(96)}. [#835](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/835)
|
||||
`,
|
||||
"1.7.22":`
|
||||
# Fixed
|
||||
- Text size in sticky notes increased when opening the drawing and when editing a sticky note [#824](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/824)
|
||||
- ToDo rendering did not work properly when there were parsed links in the text
|
||||
- Horizontal text alignment in sticky notes did not honor text alignment setting when resizing text. The text was always aligned center even when text alignment was left or right. [#5720](https://github.com/excalidraw/excalidraw/issues/5720)
|
||||
`,
|
||||
"1.7.21":`
|
||||
# New from Excalidraw.com
|
||||
- Image-mirroring in export preview and in exported SVG [#5700](https://github.com/excalidraw/excalidraw/pull/5700), [#811](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/811), [#617](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/617)
|
||||
|
||||
# New
|
||||
- Ctrl+s will force-save your drawing and update all your transclusions
|
||||
- Added setting to parse ${String.fromCharCode(96)}- [ ] ${String.fromCharCode(96)} and ${String.fromCharCode(96)}- [x] ${String.fromCharCode(96)} todo items. Parsing is disabled by default. This feature can be found under "Links and Transclusions" in Plugin Settings. [#819](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/819)
|
||||
|
||||

|
||||
|
||||
<iframe src="https://user-images.githubusercontent.com/14358394/192151120-3c61c822-0352-4ba7-9900-b38078fb373c.mp4" title="Demo" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
|
||||
</div></div>
|
||||
|
||||
- Added new scripts to the script library
|
||||
- [Rename Image](https://github.com/zsviczian/obsidian-excalidraw-plugin/blob/master/ea-scripts/Rename%20Image.md)
|
||||
- [Text Arch](https://github.com/zsviczian/obsidian-excalidraw-plugin/blob/master/ea-scripts/Text%20Arch.md)
|
||||
|
||||
<iframe src="https://user-images.githubusercontent.com/14358394/192151105-78c0115b-4e30-4296-b647-e3c05851a48f.mp4" title="Demo" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
|
||||
</div></div>
|
||||
|
||||
# Fixed
|
||||
- Fixed toast message to display script name on press and hold on mobile and iPad.
|
||||
- Fixed save error when the embedded image file is not found (i.e. it was moved, renamed, or deleted)
|
||||
|
||||
`,
|
||||
"1.7.20":`
|
||||
# New from Excalidraw.com
|
||||
- support segment midpoints in line editor [#5641](https://github.com/excalidraw/excalidraw/pull/5641)
|
||||
<div class="excalidraw-videoWrapper"><div>
|
||||
<iframe src="https://user-images.githubusercontent.com/11256141/187417807-3efeb673-6c96-4744-be0e-70119b0c6839.mp4" title="Demo" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
|
||||
</div></div>
|
||||
|
||||
# Fixed
|
||||
- When editing a line or arrow and selecting a tool on the toolbar, the tool jumps back to the selection tool and you need to click again to select the tool [#5703](https://github.com/excalidraw/excalidraw/issues/5703)
|
||||
- Minor improvement of autosave, hopefully decreasing occasional lagging
|
||||
`,
|
||||
"1.7.19":`
|
||||
# QoL improvements
|
||||
- Reintroduced the help button. I also added the help button to the Tray (in Tray Mode) and moved help to the canvas action panel (in non-TrayMode) because in Obsidian 0.16.0 the status bar hides the help icon.
|
||||
- Resetting the canvas with the "Reset Canvas" button will now preserve your custom color palette.
|
||||
- I updated the [Set background color of unlclosed line object](https://github.com/zsviczian/obsidian-excalidraw-plugin/blob/master/ea-scripts/Set%20background%20color%20of%20unclosed%20line%20object%20by%20adding%20a%20shadow%20clone.md) script. The script will now add background color to open freedraw objects as well. You no longer need to convert freedraw objects to lines before setting the background color. Check the Script Engine library to download the update.
|
||||
|
||||
# New in Excalidraw Automate
|
||||
- I added the [ColorMaster](https://github.com/lbragile/ColorMaster#readme) library to ExcalidrawAutomate. You can get a CM object by calling ${String.fromCharCode(96)}ExcalidrawAutomate.getCM(<your color comes here>)${String.fromCharCode(96)}. Color master introduces many new ways to manipulate colors from script. I will publish scripts that make use of this new functionality including supporting videos on my YouTube channel in the coming days.
|
||||
`,
|
||||
"1.7.18":`
|
||||
## Critical fix
|
||||
- duplicating text elements, adding text elements from the library, and pasting excalidraw text elements results in a corrupted file!!`,
|
||||
"1.7.17":`
|
||||
## Fixed
|
||||
- Block transclusions sometimes got lost when switching between RAW mode and PREVIEW mode. [#769](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/769)
|
||||
|
||||
## New
|
||||
- Added feature to disable "new Excalidraw version" notification [#770](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/770)
|
||||
- Added option to export both light- and dark-themed images at the same time. If this is enabled Excalidraw will create two files "filename.dark.png" and "filename.light.png" (or .svg depending on your other settings). See practical use case here: [Aadam's Notes](https://notes.aadam.dev/SBYNtPHqsTW9Ck1Kuoxsu/)
|
||||
- Added custom export padding for PNG images. Use the frontmatter key ${String.fromCharCode(96)}excalidraw-export-padding${String.fromCharCode(96)} to set the padding at a file level, or set padding for all your files in plugin settings. The new feature replaces the old "SVG Padding" option and applies to both SVG and PNG exports.
|
||||
|
||||
## ExcalidrawAutomate
|
||||
- Added ${String.fromCharCode(96)}padding${String.fromCharCode(96)} to the createPNG function call.
|
||||
${String.fromCharCode(96, 96, 96)}typescript
|
||||
async createPNG(
|
||||
templatePath?: string,
|
||||
scale: number = 1,
|
||||
exportSettings?: ExportSettings,
|
||||
loader?: EmbeddedFilesLoader,
|
||||
theme?: string,
|
||||
padding?: number,
|
||||
)
|
||||
${String.fromCharCode(96, 96, 96)}
|
||||
`,
|
||||
"1.7.16":`
|
||||
## Fixed
|
||||
- Excalidraw canvas is empty after saving the drawing and re-opening it at a later time. If you accidentally paste Excalidraw elements from the clipboard as the contents of a text element, in certain situations this can corrupt the Excalidraw file and as a result, Excalidraw will load an empty-looking drawing the next time. Changing to markdown view, these files can be repaired, however, to avoid accidental data loss, I have prevented pasting of excalidraw clipboard contents as text elements. [#768](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/768)
|
||||
|
||||
## New
|
||||
- Add zoom % display in tray-mode [737](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/737)
|
||||
`,
|
||||
"1.7.15":`
|
||||
## Fixed
|
||||
- Canvas turns white when adding point for curved line [#760](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/760), [#738](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/738), [#5602](https://github.com/excalidraw/excalidraw/issues/5602)
|
||||
`,
|
||||
"1.7.14": `
|
||||
@@ -41,7 +189,7 @@ I develop this plugin as a hobby, spending most of my free time doing this. If y
|
||||
- Create a new folder not working when clicking on a link in Erxcalidraw that points to a file that is in a folder that does not yet exist. [741](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/741)
|
||||
- Downgraded to React 17 due to various stability issues, including [#738](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/738) and [#747](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/747)
|
||||
|
||||
# New in Excalidraw Automate
|
||||
## New in Excalidraw Automate
|
||||
- I added two new Excalidraw Automate functions
|
||||
${String.fromCharCode(96, 96, 96)}typescript
|
||||
/**
|
||||
@@ -69,46 +217,46 @@ ${String.fromCharCode(96, 96, 96)}`,
|
||||
- ${String.fromCharCode(96)}Open in Adjacent Pane${String.fromCharCode(96)} and ${String.fromCharCode(96)}Open in Main Workspace${String.fromCharCode(96)} Excalidraw plugin settings is fixed
|
||||
`,
|
||||
"1.7.12": `
|
||||
# New from Excalidraw.com:
|
||||
## New from Excalidraw.com:
|
||||
- Showing a mid-point for lines and arrows. By touching the mid-point you can easily add an additional point to a two-point line. This is especially helpful when working on a tablet with touch input. ([#5534](https://github.com/excalidraw/excalidraw/pull/5534))
|
||||
- Lock angle when editing a line or an arrow with SHIFT pressed. Pressing SHIFT will restrict the edited point to snap to certain discrete angles. ([#5527](https://github.com/excalidraw/excalidraw/pull/5527))
|
||||
|
||||
# Fixed:
|
||||
## Fixed:
|
||||
- Clicking Obsidian search-results pointing to an element on the canvas works again ([#734](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/734))
|
||||
- The feature to allow resizing and rotation of lines and arrows consisting of 3 or more points by showing the bounding box when selected is back ([#5554](https://github.com/excalidraw/excalidraw/pull/5554))
|
||||
|
||||
# New
|
||||
## New
|
||||
- You can now use the following frontmatter key to allow/prevent automatic export of PNG/SVG images at a file level. This frontmatter will override export settings for the given file. ([#732](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/732)
|
||||
${String.fromCharCode(96)}excalidraw-autoexport: none|both|svg|png${String.fromCharCode(96)}
|
||||
`,
|
||||
"1.7.11": `
|
||||
# Fixed
|
||||
## Fixed
|
||||
- Markdown files embed into the Excalidraw canvas crashed when the embedded markdown file included a nested Markdown embed with a block reference (i.e. the markdown document you are dropping into Excalidraw included a quote you referenced from another file using a ${String.fromCharCode(96)}[[other-file#^blockref]]${String.fromCharCode(96)} block or section reference.
|
||||
- Horizontal flipping of arrows and lines broke in 1.7.10. ([#726](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/726))
|
||||
`,
|
||||
"1.7.10": `
|
||||
# New from Excalidraw.com
|
||||
## New from Excalidraw.com
|
||||
- Improved handling of arrows and lines. ([#5501](https://github.com/excalidraw/excalidraw/pull/5501))
|
||||
|
||||
# Fixed
|
||||
## Fixed
|
||||
- When opening a document in view-mode or zen-mode the panel buttons no longer flash up for a moment before switching to the desired mode. ([#479](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/479))
|
||||
- The "blinding white screen" no longer flashes up while loading the scene if the scene is dark ([#241](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/241))
|
||||
|
||||
# Under the hood
|
||||
## Under the hood
|
||||
- Finalized migration to React 18 (no longer showing an error about React 17 compatibility mode in console log)
|
||||
`,
|
||||
"1.7.9": `
|
||||
# New features and fixes from Excalidraw.com:
|
||||
## New features and fixes from Excalidraw.com:
|
||||
- The right-click context menu is now scrollable on smaller screens ([#4030](https://github.com/excalidraw/excalidraw/pull/4030), [#5520](https://github.com/excalidraw/excalidraw/pull/5520))
|
||||
- Holding down the shift key while rotating an object will rotate it at discrete angles. Rotation is continuous without the SHIFT key. ([#5500](https://github.com/excalidraw/excalidraw/pull/5500))
|
||||
- Improved cursor alignment when resizing an element proportionally (maintain aspect ratio) by holding SHIFT during resizing. ([#5513](https://github.com/excalidraw/excalidraw/pull/5515))
|
||||
- Improved freedraw performance during editing (now has proper canvas caching), and no more blurry freedraw shapes when exporting on a higher scale. ([#5481](https://github.com/excalidraw/excalidraw/pull/5481))
|
||||
- Sidebar stencil library now correctly scrolls vertically ([#5459](https://github.com/excalidraw/excalidraw/pull/5459))
|
||||
|
||||
# New in Obsidian:
|
||||
## New in Obsidian:
|
||||
- Fullscreen mode on iPad. When there are multiple work panes open, clicking the fullscreen action in the Excalidraw Obsidian menu will hide the other work panes and make Excalidraw fullscreen.
|
||||
|
||||
# Fixes in Obsidian:
|
||||
## Fixes in Obsidian:
|
||||
- Drag&Drop an image from a web browser into Excalidraw ([#697](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/697))
|
||||
- On Obsidian Mobile 1.3.0, when the drawing included an embedded image, switching from markdown-view to Excalidraw-view caused the drawing to disappear (it had to be recovered from backup or synchronization history). ([#715](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/715))
|
||||
- When working on a mobile device (tablet and phone) and using two work panes (one for drawing and the other for editing a markdown document) if you switched focus from the drawing to the markdown document auto-zoom changed the zoom level of the drawing. ([#723](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/723)), ([#705](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/705))
|
||||
|
||||
@@ -35,7 +35,7 @@ export class ReleaseNotes extends Modal {
|
||||
const message = this.version
|
||||
? Object.keys(RELEASE_NOTES)
|
||||
.filter((key) => key === "Intro" || isVersionNewerThanOther(key,prevRelease))
|
||||
.map((key: string) => `# ${key}\n${RELEASE_NOTES[key]}`)
|
||||
.map((key: string) => `${key==="Intro" ? "" : `# ${key}\n`}${RELEASE_NOTES[key]}`)
|
||||
.slice(0, 10)
|
||||
.join("\n\n---\n")
|
||||
: FIRST_RUN;
|
||||
|
||||
@@ -224,8 +224,8 @@ export const EXCALIDRAW_AUTOMATE_INFO: SuggesterInfo[] = [
|
||||
},
|
||||
{
|
||||
field: "addImage",
|
||||
code: "addImage(topX: number, topY: number, imageFile: TFile): Promise<string>;",
|
||||
desc: null,
|
||||
code: "addImage(topX: number, topY: number, imageFile: TFile, scale: boolean): Promise<string>;",
|
||||
desc: "set scale to false if you want to embed the image at 100% of its original size. Default is true which will insert a scaled image",
|
||||
after: "",
|
||||
},
|
||||
{
|
||||
@@ -587,9 +587,9 @@ export const FRONTMATTER_KEYS_INFO: SuggesterInfo[] = [
|
||||
after: ": true",
|
||||
},
|
||||
{
|
||||
field: "export-svgpadding",
|
||||
field: "export-padding",
|
||||
code: null,
|
||||
desc: "If this key is present it will override the default excalidraw embed and export setting. This only affects export to SVG. Specify the export padding for the image.",
|
||||
desc: "If this key is present it will override the default excalidraw embed and export setting. This only affects both SVG and PNG export. Specify the export padding for the image.",
|
||||
after: ": 5",
|
||||
},
|
||||
{
|
||||
|
||||
@@ -36,7 +36,7 @@ export default {
|
||||
"Create a new drawing - IN A NEW PANE - and embed into active document",
|
||||
NEW_IN_ACTIVE_PANE_EMBED:
|
||||
"Create a new drawing - IN THE CURRENT ACTIVE PANE - and embed into active document",
|
||||
NEW_IN_POPOUT_WINDOW_EMBED: "Create a new drawing - IN A POPOUT WINDOW - and embedd into active document",
|
||||
NEW_IN_POPOUT_WINDOW_EMBED: "Create a new drawing - IN A POPOUT WINDOW - and embed into active document",
|
||||
EXPORT_SVG: "Save as SVG next to the current file",
|
||||
EXPORT_PNG: "Save as PNG next to the current file",
|
||||
TOGGLE_LOCK: "Toggle Text Element edit RAW/PREVIEW",
|
||||
@@ -52,7 +52,8 @@ export default {
|
||||
INSERT_LINK_TO_ELEMENT_ERROR: "Select a single element in the scene",
|
||||
INSERT_LINK_TO_ELEMENT_READY: "Link is READY and available on the clipboard",
|
||||
INSERT_LINK: "Insert link to file",
|
||||
INSERT_IMAGE: "Insert image from vault",
|
||||
INSERT_IMAGE: "Insert image or Excalidraw drawing from your vault",
|
||||
IMPORT_SVG: "Import an SVG file as Excalidraw strokes (limited SVG support, TEXT currently not supported)",
|
||||
INSERT_MD: "Insert markdown file from vault",
|
||||
INSERT_LATEX:
|
||||
"Insert LaTeX formula (e.g. \\binom{n}{k} = \\frac{n!}{k!(n-k)!})",
|
||||
@@ -60,6 +61,9 @@ export default {
|
||||
READ_RELEASE_NOTES: "Read latest release notes",
|
||||
TRAY_MODE: "Toggle property-panel tray-mode",
|
||||
SEARCH: "Search for text in drawing",
|
||||
RESET_IMG_TO_100: "Set selected image element size to 100% of original",
|
||||
TEMPORARY_DISABLE_AUTOSAVE: "Disable autosave until next time Obsidian starts (only set this if you know what you are doing)",
|
||||
TEMPORARY_ENABLE_AUTOSAVE: "Enable autosave",
|
||||
|
||||
//ExcalidrawView.ts
|
||||
INSTALL_SCRIPT_BUTTON: "Install or update Excalidraw Scripts",
|
||||
@@ -77,7 +81,7 @@ export default {
|
||||
FILE_DOES_NOT_EXIST:
|
||||
"File does not exist. Hold down ALT (or ALT+SHIFT) and CLICK link button to create a new file.",
|
||||
FORCE_SAVE:
|
||||
"Force-save to update transclusions in adjacent panes.\n(Check autosave settings in plugin settings.)",
|
||||
"Save (will also update transclusions)",
|
||||
RAW: "Change to PREVIEW mode (only effects text-elements with links or transclusions)",
|
||||
PARSED:
|
||||
"Change to RAW mode (only effects text-elements with links or transclusions)",
|
||||
@@ -91,6 +95,11 @@ export default {
|
||||
RELEASE_NOTES_DESC:
|
||||
"<b>Toggle ON:</b> Display release notes each time you update Excalidraw to a newer version.<br>" +
|
||||
"<b>Toggle OFF:</b> Silent mode. You can still read release notes on <a href='https://github.com/zsviczian/obsidian-excalidraw-plugin/releases'>GitHub</a>.",
|
||||
NEWVERSION_NOTIFICATION_NAME: "Plugin update notification",
|
||||
NEWVERSION_NOTIFICATION_DESC:
|
||||
"<b>Toggle ON:</b> Show a notification when a new version of the plugin is avaiable.<br>" +
|
||||
"<b>Toggle OFF:</b> Silent mode. You need to check for plugin updates in Community Plugins.",
|
||||
|
||||
FOLDER_NAME: "Excalidraw folder",
|
||||
FOLDER_DESC:
|
||||
"Default location for new drawings. If empty, drawings will be created in the Vault root.",
|
||||
@@ -98,8 +107,8 @@ export default {
|
||||
"Use Excalidraw folder when embedding a drawing into the active document",
|
||||
FOLDER_EMBED_DESC:
|
||||
"Define which folder to place the newly inserted drawing into " +
|
||||
"when using the command palette action: 'Create a new drawing and embed into active document'. " +
|
||||
"ON: Use Excalidraw folder; OFF: use attachments folder defined in Obsidian settings",
|
||||
"when using the command palette action: 'Create a new drawing and embed into active document'.<br>" +
|
||||
"<b>Toggle ON:</b> Use Excalidraw folder<br><b>Toggle OFF:</b> use the attachments folder defined in Obsidian settings.",
|
||||
TEMPLATE_NAME: "Excalidraw template file",
|
||||
TEMPLATE_DESC:
|
||||
"Full filepath to the Excalidraw template. " +
|
||||
@@ -107,7 +116,7 @@ export default {
|
||||
"Template.md, the setting would be: Excalidraw/Template.md (or just Excalidraw/Template - you may omit the .md file extension). " +
|
||||
"If you are using Excalidraw in compatibility mode, then your template must be a legacy Excalidraw file as well " +
|
||||
"such as Excalidraw/Template.excalidraw.",
|
||||
SCRIPT_FOLDER_NAME: "Excalidraw Automate script folder",
|
||||
SCRIPT_FOLDER_NAME: "Excalidraw Automate script folder (CASE SeNSitiVE!)",
|
||||
SCRIPT_FOLDER_DESC:
|
||||
"The files you place in this folder will be treated as Excalidraw Automate scripts. " +
|
||||
"You can access your scripts from Excalidraw via the Obsidian Command Palette. Assign " +
|
||||
@@ -123,7 +132,7 @@ export default {
|
||||
"be saved without compression, so that you can read and edit the JSON string. The drawing will be compressed again " +
|
||||
"once you switch back to Excalidraw view. " +
|
||||
"The setting only has effect 'point forward', meaning, existing drawings will not be effected by the setting " +
|
||||
"until you open them and save them. ",
|
||||
"until you open them and save them.<br><b>Toggle ON:</b> Compress drawing JSON<br><b>Toggle OFF:</b> Leave drawing JSON uncompressed",
|
||||
AUTOSAVE_NAME: "Enable Autosave",
|
||||
AUTOSAVE_DESC:
|
||||
"Automatically save the active drawing, in case there are changes, every 15, 30 seconds, or 1, 2, 3, 4, or 5 minute. Save normally happens when you close Excalidraw or Obsidian, or move " +
|
||||
@@ -144,8 +153,8 @@ export default {
|
||||
"Filename prefix when embedding a new drawing into a markdown note",
|
||||
FILENAME_PREFIX_EMBED_DESC:
|
||||
"Should the filename of the newly inserted drawing start with the name of the active markdown note " +
|
||||
"when using the command palette action: <code>Create a new drawing and embed into active document</code>? " +
|
||||
"ON: Yes, OFF: Not",
|
||||
"when using the command palette action: <code>Create a new drawing and embed into active document</code>?<br>" +
|
||||
"<b>Toggle ON:</b> Yes, the filename of a new drawing should start with filename of the active document<br><b>Toggle OFF:</b> No, filename of a new drawing should not include the filename of the active document",
|
||||
FILENAME_POSTFIX_NAME:
|
||||
"Custom text after markdown Note's name when embedding",
|
||||
FILENAME_POSTFIX_DESC:
|
||||
@@ -156,26 +165,25 @@ export default {
|
||||
FILENAME_EXCALIDRAW_EXTENSION_NAME: ".excalidraw.md or .md",
|
||||
FILENAME_EXCALIDRAW_EXTENSION_DESC:
|
||||
"This setting does not apply if you use Excalidraw in compatibility mode, " +
|
||||
"i.e. you are not using Excalidraw markdown files. Toggle ON = filename ends with .excalidraw.md, Toggle OFF = filename ends with .md",
|
||||
/*SVG_IN_MD_NAME: "SVG Snapshot to markdown file",
|
||||
SVG_IN_MD_DESC: "If the switch is 'on' Excalidraw will include an SVG snapshot in the markdown file. "+
|
||||
"When SVG snapshots are saved to the Excalidraw.md file, drawings that include large png, jpg, gif images may take extreme long time to open in markdown view. " +
|
||||
"On the other hand, SVG snapshots provide some level of platform independence and longevity to your drawings. Even if Excalidraw will no longer exist, the snapshot " +
|
||||
"can be opened with an app that reads SVGs. In addition hover previews will be less resource intensive if SVG snapshots are enabled.",*/
|
||||
"i.e. you are not using Excalidraw markdown files.<br><b>Toggle ON:</b> filename ends with .excalidraw.md<br><b>Toggle OFF:</b> filename ends with .md",
|
||||
DISPLAY_HEAD: "Display",
|
||||
LEFTHANDED_MODE_NAME: "Left-handed mode",
|
||||
LEFTHANDED_MODE_DESC:
|
||||
"Currently only has effect in tray-mode. If turned on, the tray will be on the right side.",
|
||||
"Currently only has effect in tray-mode. If turned on, the tray will be on the right side." +
|
||||
"<br><b>Toggle ON:</b> Left-handed mode.<br><b>Toggle OFF:</b> Right-handed moded",
|
||||
MATCH_THEME_NAME: "New drawing to match Obsidian theme",
|
||||
MATCH_THEME_DESC:
|
||||
"If theme is dark, new drawing will be created in dark mode. This does not apply when you use a template for new drawings. " +
|
||||
"Also this will not effect when you open an existing drawing. Those will follow the theme of the template/drawing respectively.",
|
||||
"Also this will not effect when you open an existing drawing. Those will follow the theme of the template/drawing respectively." +
|
||||
"<br><b>Toggle ON:</b> Follow Obsidian Theme<br><b>Toggle OFF:</b>Follow theme defined in your template",
|
||||
MATCH_THEME_ALWAYS_NAME: "Existing drawings to match Obsidian theme",
|
||||
MATCH_THEME_ALWAYS_DESC:
|
||||
"If theme is dark, drawings will be opened in dark mode. If your theme is light, they will be opened in light mode. ",
|
||||
"If theme is dark, drawings will be opened in dark mode. If your theme is light, they will be opened in light mode. " +
|
||||
"<br><b>Toggle ON:</b> Match Obsidian theme<br><b>Toggle OFF:</b> Open with the same theme as last saved",
|
||||
MATCH_THEME_TRIGGER_NAME: "Excalidraw to follow when Obsidian Theme changes",
|
||||
MATCH_THEME_TRIGGER_DESC:
|
||||
"If this option is enabled open Excalidraw pane will switch to light/dark mode when Obsidian theme changes. ",
|
||||
"If this option is enabled open Excalidraw pane will switch to light/dark mode when Obsidian theme changes. " +
|
||||
"<br><b>Toggle ON:</b> Follow theme changes<br><b>Toggle OFF:</b> Drawings are not effected by Obsidian theme changes",
|
||||
DEFAULT_OPEN_MODE_NAME: "Default mode when opening Excalidraw",
|
||||
DEFAULT_OPEN_MODE_DESC:
|
||||
"Specifies the mode how Excalidraw opens: Normal, Zen, or View mode. You may also set this behavior on a file level by " +
|
||||
@@ -184,7 +192,8 @@ export default {
|
||||
DEFAULT_PEN_MODE_DESC:
|
||||
"Should pen mode be automatically enabled when opening Excalidraw?",
|
||||
ZOOM_TO_FIT_NAME: "Zoom to fit on view resize",
|
||||
ZOOM_TO_FIT_DESC: "Zoom to fit drawing when the pane is resized",
|
||||
ZOOM_TO_FIT_DESC: "Zoom to fit drawing when the pane is resized" +
|
||||
"<br><b>Toggle ON:</b> Zoom to fit<br><b>Toggle OFF:</b> Auto zoom disabled",
|
||||
ZOOM_TO_FIT_MAX_LEVEL_NAME: "Zoom to fit max ZOOM level",
|
||||
ZOOM_TO_FIT_MAX_LEVEL_DESC:
|
||||
"Set the maximum level to which zoom to fit will enlarge the drawing. Minimum is 0.5 (50%) and maximum is 10 (1000%).",
|
||||
@@ -221,6 +230,12 @@ export default {
|
||||
"In PREVIEW mode, if the Text Element contains a URL link, precede the text with these characters. " +
|
||||
"You can override this setting for a specific drawing by adding <code>"
|
||||
}${FRONTMATTER_KEY_CUSTOM_URL_PREFIX}: "🌐 "</code> to the file's frontmatter.`,
|
||||
PARSE_TODO_NAME: "Parse todo",
|
||||
PARSE_TODO_DESC: "Convert '- [ ] ' and '- [x] ' to checkpox and tick in the box.",
|
||||
TODO_NAME: "Open TODO icon",
|
||||
TODO_DESC: "Icon to use for open TODO items",
|
||||
DONE_NAME: "Completed TODO icon",
|
||||
DONE_DESC: "Icon to use for completed TODO items",
|
||||
HOVERPREVIEW_NAME: "Hover preview without CTRL/CMD key",
|
||||
HOVERPREVIEW_DESC:
|
||||
"<b>Toggle On</b>: In Exalidraw <u>view mode</u> the hover preview for [[wiki links]] will be shown immediately, without the need to hold the CTRL/CMD key. " +
|
||||
@@ -248,6 +263,9 @@ export default {
|
||||
PAGE_TRANSCLUSION_CHARCOUNT_DESC:
|
||||
"The maximum number of characters to display from the page when transcluding an entire page with the " +
|
||||
"![[markdown page]] format.",
|
||||
QUOTE_TRANSCLUSION_REMOVE_NAME: "Quote translusion: remove leading '> ' from each line",
|
||||
QUOTE_TRANSCLUSION_REMOVE_DESC: "Remove the leading '> ' from each line of the transclusion. This will improve readibility of quotes in text only transclusions<br>" +
|
||||
"<b>Toggle ON:</b> Remove leading '> '<br><b>Toggle OFF:</b> Do not remove leading '> ' (note it will still be removed from the first row due to Obsidian API functionality)",
|
||||
GET_URL_TITLE_NAME: "Use iframely to resolve page title",
|
||||
GET_URL_TITLE_DESC:
|
||||
"Use the <code>http://iframely.server.crestify.com/iframely?url=</code> to get title of page when dropping a link into Excalidraw",
|
||||
@@ -301,7 +319,8 @@ export default {
|
||||
"For a number of reasons, the same approach cannot be used to expedite the loading of drawings with many embedded objects. See demonstration <a href='https://github.com/zsviczian/obsidian-excalidraw-plugin/releases/tag/1.6.23' target='_blank'>here</a>.",
|
||||
EMBED_PREVIEW_SVG_NAME: "Display SVG in markdown preview",
|
||||
EMBED_PREVIEW_SVG_DESC:
|
||||
"The default is to display drawings as SVG images in the markdown preview. Turning this feature off, the markdown preview will display the drawing as an embedded PNG image.",
|
||||
"<b>Toggle ON</b>: Embed drawing as an <a href='https://en.wikipedia.org/wiki/Scalable_Vector_Graphics' target='_blank'>SVG</a> image into the markdown preview.<br>" +
|
||||
"<b>Toggle OFF</b>: Embedd drawing as a <a href='' target='_blank'>PNG</a> image. Note, that some of the <a href='https://www.youtube.com/watch?v=yZQoJg2RCKI&t=633s' target='_blank'>image block referencing features</a> do not work with PNG embeds.",
|
||||
PREVIEW_MATCH_OBSIDIAN_NAME: "Excalidraw preview to match Obsidian theme",
|
||||
PREVIEW_MATCH_OBSIDIAN_DESC:
|
||||
"Image preview in documents should match the Obsidian theme. If enabled, when Obsidian is in dark mode, Excalidraw images will render in dark mode. " +
|
||||
@@ -325,9 +344,11 @@ export default {
|
||||
EXPORT_BACKGROUND_NAME: "Export image with background",
|
||||
EXPORT_BACKGROUND_DESC:
|
||||
"If turned off, the exported image will be transparent.",
|
||||
EXPORT_SVG_PADDING_NAME: "SVG Padding",
|
||||
EXPORT_SVG_PADDING_DESC:
|
||||
"The padding (in pixels) around the exported SVG image. If you have curved lines close to the edge of the image they might get cropped during SVG export. You can increase this value to avoid cropping.",
|
||||
EXPORT_PADDING_NAME: "Image Padding",
|
||||
EXPORT_PADDING_DESC:
|
||||
"The padding (in pixels) around the exported SVG or PNG image. " +
|
||||
"If you have curved lines close to the edge of the image they might get cropped during image export. You can increase this value to avoid cropping. " +
|
||||
"You can also override this setting at a file level by adding the <code>excalidraw-export-padding: 5<code> frontmatter key.",
|
||||
EXPORT_THEME_NAME: "Export image with theme",
|
||||
EXPORT_THEME_DESC:
|
||||
"Export the image matching the dark/light theme of your drawing. If turned off, " +
|
||||
@@ -348,6 +369,9 @@ export default {
|
||||
"<code>none</code>,<code>both</code>,<code>svg</code>, and <code>png</code>",
|
||||
EXPORT_PNG_NAME: "Auto-export PNG",
|
||||
EXPORT_PNG_DESC: "Same as the auto-export SVG, but for *.PNG",
|
||||
EXPORT_BOTH_DARK_AND_LIGHT_NAME: "Export both dark- and light-themed image",
|
||||
EXPORT_BOTH_DARK_AND_LIGHT_DESC: "When enabled, Excalidraw will export two files instead of one: filename.dark.png, filename.light.png and/or filename.dark.svg and filename.light.svg<br>"+
|
||||
"Double files will be exported both if auto-export SVG or PNG (or both) are enabled, as well as when clicking export on a single image.",
|
||||
COMPATIBILITY_HEAD: "Compatibility features",
|
||||
EXPORT_EXCALIDRAW_NAME: "Auto-export Excalidraw",
|
||||
EXPORT_EXCALIDRAW_DESC: "Same as the auto-export SVG, but for *.Excalidraw",
|
||||
@@ -397,9 +421,10 @@ export default {
|
||||
|
||||
//openDrawings.ts
|
||||
SELECT_FILE: "Select a file then press enter.",
|
||||
SELECT_FILE_WITH_OPTION_TO_SCALE: "Select a file then press ENTER, or ALT+ENTER to insert at 100% scale.",
|
||||
NO_MATCH: "No file matches your query.",
|
||||
SELECT_FILE_TO_LINK: "Select the file you want to insert the link for.",
|
||||
SELECT_DRAWING: "Select the drawing you want to insert",
|
||||
SELECT_DRAWING: "Select the image or drawing you want to insert",
|
||||
TYPE_FILENAME: "Type name of drawing to select.",
|
||||
SELECT_FILE_OR_TYPE_NEW:
|
||||
"Select existing drawing or type name of a new drawing then press Enter.",
|
||||
|
||||
@@ -9,10 +9,13 @@ export default {
|
||||
// main.ts
|
||||
INSTALL_SCRIPT: "安装此脚本",
|
||||
UPDATE_SCRIPT: "发现可用更新 - 点击安装",
|
||||
CHECKING_SCRIPT: "检查脚本更新 - 点击重新安装",
|
||||
UNABLETOCHECK_SCRIPT: "检查更新失败 - 点击重新安装",
|
||||
UPTODATE_SCRIPT: "已安装最新脚本 - 点击重新安装",
|
||||
OPEN_AS_EXCALIDRAW: "打开为 Excalidraw 绘图(Excalidraw 模式)",
|
||||
CHECKING_SCRIPT:
|
||||
"检查脚本更新 - 点击重新安装",
|
||||
UNABLETOCHECK_SCRIPT:
|
||||
"检查更新失败 - 点击重新安装",
|
||||
UPTODATE_SCRIPT:
|
||||
"已安装最新脚本 - 点击重新安装",
|
||||
OPEN_AS_EXCALIDRAW: "打开为 Excalidraw 绘图",
|
||||
TOGGLE_MODE: "在 Excalidraw 和 Markdown 模式之间切换",
|
||||
CONVERT_NOTE_TO_EXCALIDRAW: "转换空白笔记为 Excalidraw 绘图",
|
||||
CONVERT_EXCALIDRAW: "转换 *.excalidraw 为 *.md 文件",
|
||||
@@ -20,33 +23,47 @@ export default {
|
||||
CONVERT_FILE_KEEP_EXT: "*.excalidraw => *.excalidraw.md",
|
||||
CONVERT_FILE_REPLACE_EXT: "*.excalidraw => *.md (兼容 Logseq)",
|
||||
DOWNLOAD_LIBRARY: "导出 stencil 库为 *.excalidrawlib 文件",
|
||||
OPEN_EXISTING_NEW_PANE: "打开已有的绘图(在新面板)",
|
||||
OPEN_EXISTING_ACTIVE_PANE: "打开已有的绘图(在当前面板)",
|
||||
TRANSCLUDE: "插入(嵌入)绘图到当前文档",
|
||||
TRANSCLUDE_MOST_RECENT: "插入(嵌入)最近编辑的绘图到当前文档",
|
||||
NEW_IN_NEW_PANE: "新建绘图(在新面板)",
|
||||
NEW_IN_ACTIVE_PANE: "新建绘图(在当前面板)",
|
||||
NEW_IN_NEW_PANE_EMBED: "新建绘图(在新面板),并插入(嵌入)到当前文档",
|
||||
NEW_IN_ACTIVE_PANE_EMBED: "新建绘图(在当前面板),并插入(嵌入)到当前文档",
|
||||
OPEN_EXISTING_NEW_PANE: "打开已有的绘图 - 于新面板",
|
||||
OPEN_EXISTING_ACTIVE_PANE:
|
||||
"打开已有的绘图 - 于当前面板",
|
||||
TRANSCLUDE: "嵌入绘图(形如 ![[drawing]])到当前文档",
|
||||
TRANSCLUDE_MOST_RECENT: "嵌入最近编辑过的绘图(形如 ![[drawing]])到当前文档",
|
||||
TOGGLE_LEFTHANDED_MODE: "切换为左手模式",
|
||||
NEW_IN_NEW_PANE: "新建绘图 - 于新面板",
|
||||
NEW_IN_ACTIVE_PANE: "新建绘图 - 于当前面板",
|
||||
NEW_IN_POPOUT_WINDOW: "新建绘图 - 于新窗口",
|
||||
NEW_IN_NEW_PANE_EMBED:
|
||||
"新建绘图 - 于新面板 - 并将其嵌入(形如 ![[drawing]])到当前文档",
|
||||
NEW_IN_ACTIVE_PANE_EMBED:
|
||||
"新建绘图 - 于当前面板 - 并将其嵌入(形如 ![[drawing]])到当前文档",
|
||||
NEW_IN_POPOUT_WINDOW_EMBED: "新建绘图 - 于新窗口 - 并将其嵌入(形如 ![[drawing]])到当前文档",
|
||||
EXPORT_SVG: "导出 SVG 文件到当前目录",
|
||||
EXPORT_PNG: "导出 PNG 文件到当前目录",
|
||||
TOGGLE_LOCK: "切换文本元素的原文/预览模式",
|
||||
DELETE_FILE: "删除所选的图像或以图像形式嵌入的 Markdown 文档(包括其源文件)",
|
||||
INSERT_LINK_TO_ELEMENT: "复制所选元素(以链接形式)",
|
||||
TOGGLE_LOCK: "切换文本元素为原文模式(RAW)/预览模式(PREVIEW)",
|
||||
DELETE_FILE: "从库中删除所选图像(或 MD-Embed)的源文件",
|
||||
INSERT_LINK_TO_ELEMENT:
|
||||
"复制所选元素的内部链接。按住 CTRL/CMD 可复制元素所在分组的内部链接。按住 SHIFT 可复制元素周围区域的内部链接。",
|
||||
INSERT_LINK_TO_ELEMENT_GROUP:
|
||||
"复制所选元素所在分组的内部链接(形如 [[file#^group=elementID]])",
|
||||
INSERT_LINK_TO_ELEMENT_AREA:
|
||||
"复制所选元素周围区域的内部链接(形如 [[file#^area=elementID]])",
|
||||
INSERT_LINK_TO_ELEMENT_NORMAL:
|
||||
"复制所选元素的引用链接(形如 [[file#^elementID]])",
|
||||
INSERT_LINK_TO_ELEMENT_ERROR: "未选择画布里的单个元素",
|
||||
INSERT_LINK_TO_ELEMENT_READY: "链接已生成并复制到剪贴板",
|
||||
INSERT_LINK: "插入(链接)文件到当前绘图",
|
||||
INSERT_IMAGE: "插入(以图像形式嵌入)图像到当前绘图",
|
||||
INSERT_MD: "插入(以图像形式嵌入) Markdown 文档到当前绘图",
|
||||
INSERT_LATEX: "插入 LaTeX 公式",
|
||||
INSERT_LINK: "插入文件的内部链接(形如 [[drawing]])到当前绘图",
|
||||
INSERT_IMAGE: "插入图像(以图像形式嵌入)到当前绘图",
|
||||
INSERT_MD: "插入 Markdown 文档(以图像形式嵌入)到当前绘图",
|
||||
INSERT_LATEX:
|
||||
"插入 LaTeX 公式到当前绘图",
|
||||
ENTER_LATEX: "输入 LaTeX 表达式",
|
||||
READ_RELEASE_NOTES: "阅读本插件的最新发行版本说明",
|
||||
TRAY_MODE: "切换绘图工具属性页的面板(Panel)/托盘(Tray)模式",
|
||||
TRAY_MODE: "切换绘图工具属性页为面板模式(Panel)/托盘模式(Tray)",
|
||||
SEARCH: "搜索文本",
|
||||
|
||||
//ExcalidrawView.ts
|
||||
INSTALL_SCRIPT_BUTTON: "安装或更新 Excalidraw 自动化脚本",
|
||||
OPEN_AS_MD: "打开为 Markdown 文件(Markdown 模式)",
|
||||
OPEN_AS_MD: "打开为 Markdown 文件",
|
||||
SAVE_AS_PNG: "导出 PNG 到当前目录(按住 CTRL/CMD 设定导出路径)",
|
||||
SAVE_AS_SVG: "导出 SVG 到当前目录(按住 CTRL/CMD 设定导出路径)",
|
||||
OPEN_LINK: "打开所选元素里的链接 \n(按住 SHIFT 在新面板打开)",
|
||||
@@ -55,13 +72,12 @@ export default {
|
||||
"请选择一个含有链接的图形或文本元素。\n" +
|
||||
"按住 SHIFT 并点击此按钮可在新面板中打开链接。\n" +
|
||||
"您也可以直接在画布中按住 CTRL/CMD 并点击图形或文本元素来打开链接。",
|
||||
TEXT_ELEMENT_EMPTY:
|
||||
"未选中图形或文本元素,或者元素不包含有效的链接([[链接|别名]] 或 [别名](链接))",
|
||||
FILENAME_INVALID_CHARS: '文件名不能含有以下符号: * " \\ < > : | ? #',
|
||||
FILENAME_INVALID_CHARS:
|
||||
'文件名不能含有以下符号: * " \\ < > : | ? #',
|
||||
FILE_DOES_NOT_EXIST:
|
||||
"文件不存在。按住 ALT(或 ALT + SHIFT)并点击链接来创建新文件。",
|
||||
FORCE_SAVE:
|
||||
"立刻保存该绘图,并更新其他嵌入了该绘图的面板。\n(详见插件设置中的定期保存选项)",
|
||||
"立刻保存该绘图(并更新嵌入了该绘图的面板)。\n详见插件设置中的定期保存选项",
|
||||
RAW: "文本元素正以原文(RAW)模式显示链接。\n点击切换到预览(PREVIEW)模式",
|
||||
PARSED:
|
||||
"文本元素正以预览(PREVIEW)模式显示链接。\n点击切换到原文(RAW)模式",
|
||||
@@ -75,13 +91,20 @@ export default {
|
||||
RELEASE_NOTES_DESC:
|
||||
"<b>开启:</b>每次更新本插件后,显示最新发行版本的说明。<br>" +
|
||||
"<b>关闭:</b>您仍可以在 <a href='https://github.com/zsviczian/obsidian-excalidraw-plugin/releases'>GitHub</a> 上阅读更新说明。",
|
||||
NEWVERSION_NOTIFICATION_NAME: "通知插件更新",
|
||||
NEWVERSION_NOTIFICATION_DESC:
|
||||
"<b>开启:</b>当本插件存在可用更新时,显示通知。<br>" +
|
||||
"<b>关闭:</b>您需要手动检查本插件的更新(设置 - 第三方插件 - 检查更新)。",
|
||||
|
||||
FOLDER_NAME: "Excalidraw 文件夹",
|
||||
FOLDER_DESC: "新绘图的默认存储路径。若为空,将在库的根目录中创建新绘图。",
|
||||
FOLDER_EMBED_NAME: "将 Excalidraw 文件夹用于“新建绘图”命令创建的绘图",
|
||||
FOLDER_DESC:
|
||||
"新绘图的默认存储路径。若为空,将在库的根目录中创建新绘图。",
|
||||
FOLDER_EMBED_NAME:
|
||||
"将 Excalidraw 文件夹用于“新建绘图”命令创建的绘图",
|
||||
FOLDER_EMBED_DESC:
|
||||
"在命令面板中执行“新建绘图,并插入(嵌入)到当前文档”之类命令时," +
|
||||
"在命令面板中执行“新建绘图”系列命令时," +
|
||||
"新绘图的存储路径。<br>" +
|
||||
"<b>开启:</b>使用 Excalidraw 文件夹。 <b>关闭:</b>使用 Obsidian 设置的新附件默认位置。",
|
||||
"<b>开启:</b>使用 Excalidraw 文件夹。 <br><b>关闭:</b>使用 Obsidian 设置的新附件默认位置。",
|
||||
TEMPLATE_NAME: "Excalidraw 模板文件",
|
||||
TEMPLATE_DESC:
|
||||
"Excalidraw 模板文件的完整路径。<br>" +
|
||||
@@ -113,89 +136,107 @@ export default {
|
||||
"但是在手机或平板上通过滑动手势退出 Obsidian 时,可能无法顺利触发自动保存。因此我添加了定期保存功能作为弥补。",
|
||||
AUTOSAVE_INTERVAL_NAME: "定期保存的时间间隔",
|
||||
AUTOSAVE_INTERVAL_DESC:
|
||||
"每隔多长时间执行一次保存。如果当前绘图没有发生改变,将不会进行定期保存。",
|
||||
"每隔多长时间执行一次保存。如果当前绘图没有发生改变,将不会触发保存。",
|
||||
FILENAME_HEAD: "文件名",
|
||||
FILENAME_DESC:
|
||||
"<p>点击阅读" +
|
||||
"<a href='https://momentjs.com/docs/#/displaying/format/'>日期和时间格式参考</a>。</p>",
|
||||
FILENAME_SAMPLE: "当前设置下,新绘图的文件名形如:",
|
||||
FILENAME_EMBED_SAMPLE: "“新建绘图”命令创建的绘图的文件名形如:",
|
||||
FILENAME_PREFIX_NAME: "文件名前缀",
|
||||
FILENAME_PREFIX_DESC: "文件名的第一部分",
|
||||
FILENAME_PREFIX_EMBED_NAME: "“新建绘图”命令创建的绘图的文件名前缀",
|
||||
FILENAME_SAMPLE: "“新建绘图”系列命令创建的文件名形如:",
|
||||
FILENAME_EMBED_SAMPLE: "“新建绘图并嵌入到当前文档”系列命令创建的文件名形如:",
|
||||
FILENAME_PREFIX_NAME: "“新建绘图”系列命令创建的文件名前缀",
|
||||
FILENAME_PREFIX_DESC: "执行“新建绘图”系列命令时,创建的绘图文件名的第一部分",
|
||||
FILENAME_PREFIX_EMBED_NAME:
|
||||
"“新建绘图并嵌入到当前文档”系列命令创建的文件名前缀",
|
||||
FILENAME_PREFIX_EMBED_DESC:
|
||||
"若开启此项," +
|
||||
"则在命令面板中执行“新建绘图,并插入(嵌入)到当前文档”之类命令时," +
|
||||
"创建的绘图文件名将以当前文档名作为开头。",
|
||||
FILENAME_POSTFIX_NAME: "“新建绘图”命令创建的绘图的文件名后缀",
|
||||
"执行“新建绘图并嵌入到当前文档”系列命令时," +
|
||||
"创建的绘图文件名是否以当前文档名作为前缀?<br>" +
|
||||
"<b>开启:</b>是<br><b>关闭:</b>否",
|
||||
FILENAME_POSTFIX_NAME:
|
||||
"“新建绘图并嵌入到当前文档”系列命令创建的文件名的中间部分",
|
||||
FILENAME_POSTFIX_DESC:
|
||||
"介于文件名前缀和文件名日期之间的文本。仅对“新建绘图”命令创建的绘图生效。",
|
||||
FILENAME_DATE_NAME: "文件名日期",
|
||||
FILENAME_DATE_DESC: "文件名的最后一部分",
|
||||
"介于文件名前缀和日期时间之间的文本。仅对“新建绘图并嵌入到当前文档”系列命令创建的绘图生效。",
|
||||
FILENAME_DATE_NAME: "文件名里的日期时间",
|
||||
FILENAME_DATE_DESC:
|
||||
"文件名的最后一部分。允许留空。",
|
||||
FILENAME_EXCALIDRAW_EXTENSION_NAME: "文件扩展名(.excalidraw.md 或 .md)",
|
||||
FILENAME_EXCALIDRAW_EXTENSION_DESC:
|
||||
"该选项在兼容模式(即非 Excalidraw 专用 Markdown 文件)下不会生效。<br>" +
|
||||
"<b>开启:</b>使用 .excalidraw.md 作为扩展名;<b>关闭:</b>使用 .md 作为扩展名。",
|
||||
/*SVG_IN_MD_NAME: "SVG Snapshot to markdown file",
|
||||
SVG_IN_MD_DESC: "If the switch is 'on' Excalidraw will include an SVG snapshot in the markdown file. "+
|
||||
"When SVG snapshots are saved to the Excalidraw.md file, drawings that include large png, jpg, gif images may take extreme long time to open in markdown view. " +
|
||||
"On the other hand, SVG snapshots provide some level of platform independence and longevity to your drawings. Even if Excalidraw will no longer exist, the snapshot " +
|
||||
"can be opened with an app that reads SVGs. In addition hover previews will be less resource intensive if SVG snapshots are enabled.",*/
|
||||
"<b>开启:</b>使用 .excalidraw.md 作为扩展名。<br><b>关闭:</b>使用 .md 作为扩展名。",
|
||||
DISPLAY_HEAD: "显示",
|
||||
LEFTHANDED_MODE_NAME: "左手模式",
|
||||
LEFTHANDED_MODE_DESC:
|
||||
"目前只影响托盘模式下,绘图工具属性页的位置。若开启此项,则托盘处于右侧。",
|
||||
"目前只在托盘模式下生效。若开启此项,则托盘(绘图工具属性页)将位于右侧。" +
|
||||
"<br><b>开启:</b>左手模式。<br><b>关闭:</b>右手模式。",
|
||||
MATCH_THEME_NAME: "使新建的绘图匹配 Obsidian 主题",
|
||||
MATCH_THEME_DESC:
|
||||
"如果 Obsidian 使用黑暗主题,新建的绘图文件也将使用黑暗主题。<br>" +
|
||||
"但是若设置了模板,新建的绘图文件将跟随模板主题;另外,此功能不会作用于已有的绘图。",
|
||||
"但是若设置了模板,新建的绘图文件将跟随模板主题;另外,此功能不会作用于已有的绘图。" +
|
||||
"<br><b>开启:</b>跟随 Obsidian 主题风格。<br><b>关闭:</b>跟随模板主题风格。",
|
||||
MATCH_THEME_ALWAYS_NAME: "使已有的绘图匹配 Obsidian 主题",
|
||||
MATCH_THEME_ALWAYS_DESC:
|
||||
"如果 Obsidian 使用黑暗主题,则绘图文件也将以黑暗主题打开;反之亦然。",
|
||||
"如果 Obsidian 使用黑暗主题,则绘图文件也将以黑暗主题打开;反之亦然。" +
|
||||
"<br><b>开启:</b>匹配 Obsidian 主题风格。<br><b>关闭:</b>采用上次保存时的主题风格。",
|
||||
MATCH_THEME_TRIGGER_NAME: "Excalidraw 主题跟随 Obsidian 主题变化",
|
||||
MATCH_THEME_TRIGGER_DESC:
|
||||
"开启此项,则切换 Obsidian 的黑暗/明亮主题时,当前活动的 Excalidraw 面板的主题会随之改变。",
|
||||
"开启此项,则切换 Obsidian 的黑暗/明亮主题时,已打开的 Excalidraw 面板的主题会随之改变。" +
|
||||
"<br><b>开启:</b>跟随主题变化。<br><b>关闭:</b>不跟随主题变化。",
|
||||
DEFAULT_OPEN_MODE_NAME: "Excalidraw 的默认运行模式",
|
||||
DEFAULT_OPEN_MODE_DESC:
|
||||
"设置 Excalidraw 的运行模式:普通模式,禅模式,或者阅读模式。<br>" +
|
||||
"您可为某个绘图单独设置此项,方法是在其 Frontmatter 中添加形如 <code>excalidraw-default-mode: normal/zen/view</code> 的键值对。",
|
||||
"设置 Excalidraw 的运行模式:普通模式(Normal)/禅模式(Zen)/阅读模式(View)。<br>" +
|
||||
"您可为某个绘图单独设置此项,方法是在其 frontmatter 中添加形如 <code>excalidraw-default-mode: normal/zen/view</code> 的键值对。",
|
||||
DEFAULT_PEN_MODE_NAME: "触控笔模式(Pen mode)",
|
||||
DEFAULT_PEN_MODE_DESC:
|
||||
"打开绘图时,是否自动开启触控笔模式?",
|
||||
ZOOM_TO_FIT_NAME: "自动缩放以适应面板调整",
|
||||
ZOOM_TO_FIT_DESC: "调整面板大小时,自适应地缩放画布",
|
||||
ZOOM_TO_FIT_DESC: "调整面板大小时,自适应地缩放画布" +
|
||||
"<br><b>开启:</b>自动缩放。<br><b>关闭:</b>禁用自动缩放。",
|
||||
ZOOM_TO_FIT_MAX_LEVEL_NAME: "自动缩放的最高级别",
|
||||
ZOOM_TO_FIT_MAX_LEVEL_DESC:
|
||||
"自动缩放画布时,允许放大的最高级别。该值不能低于 0.5(50%)且不能超过 10(1000%)。",
|
||||
LINKS_HEAD: "链接(Links) & 嵌入到绘图中的文档(Transclusion)",
|
||||
LINKS_HEAD: "链接(Links) & 以文本形式嵌入到绘图中的文档(Transclusion)",
|
||||
LINKS_DESC:
|
||||
"按住 CTRL/CMD 并点击包含 <code>[[链接]]</code> 的文本元素可以打开其中的链接。" +
|
||||
"如果所选文本元素包含多个 <code>[[有效的 Obsidian 链接]]</code> ,只会打开第一个链接;" +
|
||||
"按住 CTRL/CMD 并点击包含 <code>[[链接]]</code> 的文本元素可以打开其中的链接。<br>" +
|
||||
"如果所选文本元素包含多个 <code>[[有效的内部链接]]</code> ,只会打开第一个链接;" +
|
||||
"如果所选文本元素包含有效的 URL 链接 (如 <code>https://</code> 或 <code>http://</code>)," +
|
||||
"插件会在浏览器中打开 URL 链接。<br>" +
|
||||
"链接的源文件被重命名时,绘图中相应的 <code>[[链接]]</code> 也会同步更新。" +
|
||||
"若您不愿绘图中的链接文本因此而变化,可用 <code>[[链接|别名]]</code> 来使用别名。",
|
||||
"插件会在浏览器中打开链接。<br>" +
|
||||
"链接的源文件被重命名时,绘图中相应的 <code>[[内部链接]]</code> 也会同步更新。" +
|
||||
"若您不愿绘图中的链接外观因此而变化,可使用 <code>[[内部链接|别名]]</code>。",
|
||||
ADJACENT_PANE_NAME: "在相邻面板中打开",
|
||||
ADJACENT_PANE_DESC:
|
||||
"按住 CTRL/CMD + SHIFT 并点击链接时,插件默认会在新面板中打开该链接。<br>" +
|
||||
"按住 CTRL/CMD + SHIFT 并点击绘图里的内部链接时,插件默认会在新面板中打开该链接。<br>" +
|
||||
"若开启此项,Excalidraw 会先尝试寻找已有的相邻面板(按照右侧、左侧、上方、下方的顺序)," +
|
||||
"并在其中打开链接。如果找不到," +
|
||||
"再在新面板中打开链接。",
|
||||
"并在其中打开该链接。如果找不到," +
|
||||
"再在新面板中打开。",
|
||||
MAINWORKSPACE_PANE_NAME: "在主工作区中打开",
|
||||
MAINWORKSPACE_PANE_DESC:
|
||||
"按住 CTRL/CMD + SHIFT 并点击绘图里的内部链接时,插件默认会在当前窗口的新面板中打开该链接。<br>" +
|
||||
"若开启此项,Excalidraw 会在主工作区的面板中打开该链接。",
|
||||
LINK_BRACKETS_NAME: "在链接的两侧显示 [[中括号]]",
|
||||
LINK_BRACKETS_DESC: `${
|
||||
"文本元素处于预览模式时,在链接的两侧显示中括号。<br>" +
|
||||
"您可为某个绘图单独设置此项,方法是在其 Frontmatter 中添加形如 <code>"
|
||||
"文本元素处于预览模式时,在内部链接的两侧显示中括号。<br>" +
|
||||
"您可为某个绘图单独设置此项,方法是在其 frontmatter 中添加形如 <code>"
|
||||
}${FRONTMATTER_KEY_CUSTOM_LINK_BRACKETS}: true/false</code> 的键值对。`,
|
||||
LINK_PREFIX_NAME: "链接的前缀",
|
||||
LINK_PREFIX_NAME: "内部链接的前缀",
|
||||
LINK_PREFIX_DESC: `${
|
||||
"文本元素处于预览模式时,如果其中包含链接,则添加此前缀。<br>" +
|
||||
"您可为某个绘图单独设置此项,方法是在其 Frontmatter 中添加形如 <code>"
|
||||
"您可为某个绘图单独设置此项,方法是在其 frontmatter 中添加形如 <code>"
|
||||
}${FRONTMATTER_KEY_CUSTOM_PREFIX}: "📍 "</code> 的键值对。`,
|
||||
URL_PREFIX_NAME: "URL 的前缀",
|
||||
URL_PREFIX_NAME: "外部链接的前缀",
|
||||
URL_PREFIX_DESC: `${
|
||||
"预览模式下,如果文本元素包含 URL 链接,则添加此前缀。<br>" +
|
||||
"您可为某个绘图单独设置此项,方法是在其 Frontmatter 中添加形如 <code>"
|
||||
"文本元素处于预览模式时,如果其中包含外部链接,则添加此前缀。<br>" +
|
||||
"您可为某个绘图单独设置此项,方法是在其 frontmatter 中添加形如 <code>"
|
||||
}${FRONTMATTER_KEY_CUSTOM_URL_PREFIX}: "🌐 "</code> 的键值对。`,
|
||||
HOVERPREVIEW_NAME: "鼠标悬停预览链接",
|
||||
PARSE_TODO_NAME: "解析任务列表(Todo)",
|
||||
PARSE_TODO_DESC: "将文本元素中的 <code>- [ ]</code> 和 <code>- [x]</code> 前缀显示为方框。",
|
||||
TODO_NAME: "未完成的 Todo 项目",
|
||||
TODO_DESC: "未完成的 Todo 项目的符号",
|
||||
DONE_NAME: "已完成的 Todo 项目",
|
||||
DONE_DESC: "已完成的 Todo 项目的符号",
|
||||
HOVERPREVIEW_NAME: "鼠标悬停预览内部链接",
|
||||
HOVERPREVIEW_DESC:
|
||||
"<b>开启:</b>鼠标悬停在 <code>[[链接]]</code> 上即可预览。<br><b>关闭:</b>鼠标悬停在 <code>[[链接]]</code> 上,并且按住 CTRL/CMD 时进行预览。",
|
||||
"<b>开启:</b>在 Excalidraw <u>阅读模式(View)</u>下,鼠标悬停在 <code>[[内部链接]]</code> 上即可预览;" +
|
||||
"而在<u>普通模式(Normal)</u>下, 鼠标悬停在内部链接右上角的蓝色标识上即可预览。<br> " +
|
||||
"<b>关闭:</b>鼠标悬停在 <code>[[内部链接]]</code> 上,并且按住 CTRL/CMD 时进行预览。",
|
||||
LINKOPACITY_NAME: "链接标识的透明度",
|
||||
LINKOPACITY_DESC:
|
||||
"含有链接的元素,其右上角的链接标识的透明度。介于 0(全透明)到 1(不透明)之间。",
|
||||
@@ -204,48 +245,52 @@ export default {
|
||||
LINK_CTRL_CLICK_DESC:
|
||||
"如果此功能影响到您使用某些原版 Excalidraw 功能,可将其关闭。" +
|
||||
"关闭后,您只能通过绘图面板标题栏中的链接按钮来打开链接。",
|
||||
TRANSCLUSION_WRAP_NAME: "嵌入文档(Translusion)的折行方式",
|
||||
TRANSCLUSION_WRAP_NAME: "Transclusion 的折行方式",
|
||||
TRANSCLUSION_WRAP_DESC:
|
||||
"中的 number 表示嵌入的文本溢出时,在第几个字符处进行折行。<br>" +
|
||||
"此开关控制具体的折行方式。若开启,则严格在 number 处折行,禁止溢出;" +
|
||||
"若关闭,则允许在 number 位置后最近的空格处折行。",
|
||||
TRANSCLUSION_DEFAULT_WRAP_NAME: "嵌入文档(Translusion)的默认折行位置",
|
||||
TRANSCLUSION_DEFAULT_WRAP_NAME: "Transclusion 的默认折行位置",
|
||||
TRANSCLUSION_DEFAULT_WRAP_DESC:
|
||||
"除了通过 <code>![[doc#^block]]{number}</code> 中的 number 来控制折行位置,您也可以在此设置 number 的默认值。<br>" +
|
||||
"一般设为 0 即可,表示不设置固定的默认值,这样当您需要嵌入文档到便签中时," +
|
||||
"Excalidraw 能更好地帮您自动处理。",
|
||||
PAGE_TRANSCLUSION_CHARCOUNT_NAME: "嵌入文档(Translusion)的最大显示字符数",
|
||||
PAGE_TRANSCLUSION_CHARCOUNT_NAME: "Transclusion 的最大显示字符数",
|
||||
PAGE_TRANSCLUSION_CHARCOUNT_DESC:
|
||||
"以 <code>![[Markdown 文档]]</code> 的形式将文档嵌入到绘图中时," +
|
||||
"以 <code>![[内部链接]]</code> 或 <code></code> 的形式将文档以文本形式嵌入到绘图中时," +
|
||||
"该文档在绘图中可显示的最大字符数量。",
|
||||
GET_URL_TITLE_NAME: "使用 iframly 获取页面标题",
|
||||
GET_URL_TITLE_DESC:
|
||||
"拖放链接到 Excalidraw 时,使用 <code>http://iframely.server.crestify.com/iframely?url=</code> 来获取页面的标题。",
|
||||
MD_HEAD: "以图像形式嵌入到绘图中的 Markdown 文档(MD-Embed)",
|
||||
MD_HEAD_DESC:
|
||||
"您可以将 Markdown 文档以图像(而非链接)的形式嵌入到绘图中," +
|
||||
"方法是按住 CTRL/CMD 并从文件管理器中把文档拖入绘图,或者使用命令面板里的相关命令。",
|
||||
"您还可以将 Markdown 文档以图像形式(而非文本形式)嵌入到绘图中。" +
|
||||
"方法是按住 CTRL/CMD 并从文件管理器中把文档拖入绘图,或者执行“以图像形式嵌入”系列命令。",
|
||||
MD_TRANSCLUDE_WIDTH_NAME: "MD-Embed 的默认宽度",
|
||||
MD_TRANSCLUDE_WIDTH_DESC:
|
||||
"MD-Embed 图像的宽度。该选项会影响到折行,以及图像元素的宽度。<br>" +
|
||||
"MD-Embed 的宽度。该选项会影响到折行,以及图像元素的宽度。<br>" +
|
||||
"您可为绘图中的某个 MD-Embed 单独设置此项,方法是将绘图切换至 Markdown 模式," +
|
||||
"并修改相应的 <code>[[Embed文件名#标题|宽度x最大高度]]</code>。",
|
||||
MD_TRANSCLUDE_HEIGHT_NAME: "MD-Embed 的默认最大高度",
|
||||
MD_TRANSCLUDE_HEIGHT_NAME:
|
||||
"MD-Embed 的默认最大高度",
|
||||
MD_TRANSCLUDE_HEIGHT_DESC:
|
||||
"MD-Embed 图像的高度取决于文档内容的多少,但最大不会超过该值。<br>" +
|
||||
"MD-Embed 的高度取决于 Markdown 文档内容的多少,但最大不会超过该值。<br>" +
|
||||
"您可为绘图中的某个 MD-Embed 单独设置此项,方法是将绘图切换至 Markdown 模式,并修改相应的 <code>[[Embed文件名#^块引ID|宽度x最大高度]]</code>。",
|
||||
MD_DEFAULT_FONT_NAME: "MD-Embed 的默认字体",
|
||||
MD_DEFAULT_FONT_NAME:
|
||||
"MD-Embed 的默认字体",
|
||||
MD_DEFAULT_FONT_DESC:
|
||||
"可以设为 <code>Virgil</code>,<code>Casadia</code> 或其他有效的 .ttf/.woff/.woff2 字体文件(如 <code>我的字体.woff2</code>)。<br>" +
|
||||
"您可为某个 MD-Embed 单独设置此项,方法是在其源文件的 Frontmatter 中添加形如 <code>excalidraw-font: 字体名或文件名</code> 的键值对。",
|
||||
MD_DEFAULT_COLOR_NAME: "MD-Embed 的默认文本颜色",
|
||||
"您可为某个 MD-Embed 单独设置此项,方法是在其源文件的 frontmatter 中添加形如 <code>excalidraw-font: 字体名或文件名</code> 的键值对。",
|
||||
MD_DEFAULT_COLOR_NAME:
|
||||
"MD-Embed 的默认文本颜色",
|
||||
MD_DEFAULT_COLOR_DESC:
|
||||
"可以填写 HTML 颜色名,如 steelblue(参考 <a href='https://www.w3schools.com/colors/colors_names.asp'>HTML Color Names</a>),或者有效的 16 进制颜色值,例如 #e67700,或者任何其他有效的 CSS 颜色。<br>" +
|
||||
"您可为某个 MD-Embed 单独设置此项,方法是在其源文件的 Frontmatter 中添加形如 <code>excalidraw-font-color: steelblue</code> 的键值对。",
|
||||
MD_DEFAULT_BORDER_COLOR_NAME: "MD-Embed 的默认边框颜色",
|
||||
"您可为某个 MD-Embed 单独设置此项,方法是在其源文件的 frontmatter 中添加形如 <code>excalidraw-font-color: steelblue</code> 的键值对。",
|
||||
MD_DEFAULT_BORDER_COLOR_NAME:
|
||||
"MD-Embed 的默认边框颜色",
|
||||
MD_DEFAULT_BORDER_COLOR_DESC:
|
||||
"可以填写 HTML 颜色名,如 steelblue(参考 <a href='https://www.w3schools.com/colors/colors_names.asp'>HTML Color Names</a>),或者有效的 16 进制颜色值,例如 #e67700,或者任何其他有效的 CSS 颜色。<br>" +
|
||||
"您可为某个 MD-Embed 单独设置此项,方法是在其源文件的 Frontmatter 中添加形如 <code>excalidraw-border-color: gray</code> 的键值对。<br>" +
|
||||
"您可为某个 MD-Embed 单独设置此项,方法是在其源文件的 frontmatter 中添加形如 <code>excalidraw-border-color: gray</code> 的键值对。<br>" +
|
||||
"如果您不想要边框,请留空。",
|
||||
MD_CSS_NAME: "MD-Embed 的默认 CSS 样式表",
|
||||
MD_CSS_DESC:
|
||||
@@ -255,58 +300,76 @@ export default {
|
||||
"<code>ExcalidrawAutomate.mostRecentMarkdownSVG</code> —— 这将显示 Excalidraw 最近生成的 SVG。<br>" +
|
||||
"此外,在 CSS 中不能任意地设置字体,您一般只能使用系统默认的标准字体(详见 README)," +
|
||||
"但可以通过上面的设置来额外添加一个自定义字体。<br>" +
|
||||
"您可为某个 MD-Embed 单独设置此项,方法是在其源文件的 Frontmatter 中添加形如 <code>excalidraw-css: 库中的CSS文件或CSS片段</code> 的键值对。",
|
||||
"您可为某个 MD-Embed 单独设置此项,方法是在其源文件的 frontmatter 中添加形如 <code>excalidraw-css: 库中的CSS文件或CSS片段</code> 的键值对。",
|
||||
EMBED_HEAD: "嵌入到文档中的绘图(Embed) & 导出",
|
||||
EMBED_PREVIEW_SVG_NAME: "在 Markdown 阅读视图下显示 SVG 格式的预览图",
|
||||
EMBED_REUSE_EXPORTED_IMAGE_NAME:
|
||||
"将之前已导出的图像作为 Embed 的预览图(如果存在的话)",
|
||||
EMBED_REUSE_EXPORTED_IMAGE_DESC:
|
||||
"该选项与“自动导出 SVG/PNG 副本”选项配合使用。如果存在文件名相匹配的 SVG/PNG 副本,则将其作为 Embed 的预览图,而不再重新生成预览图。<br>" +
|
||||
"该选项能够提高性能,尤其是当 Embed 中含有大量图像或 MD-Embed 时。" +
|
||||
"但是,该选项也可能导致预览图无法立即响应你最新的修改,或者你对 Obsidian 主题风格的改变。<br>" +
|
||||
"该选项仅作用于嵌入到文档中的绘图。" +
|
||||
"由于种种原因,该技术无法用于加快绘图文件的打开速度。详见<a href='https://github.com/zsviczian/obsidian-excalidraw-plugin/releases/tag/1.6.23' target='_blank'>此说明</a>。",
|
||||
EMBED_PREVIEW_SVG_NAME: "生成 SVG 格式的 Embed 预览图",
|
||||
EMBED_PREVIEW_SVG_DESC:
|
||||
"Obsidian 的 Markdown 阅读视图默认会将嵌入的绘图显示为 SVG 格式的预览图。若关闭此项,则显示为 PNG 格式。",
|
||||
PREVIEW_MATCH_OBSIDIAN_NAME: "预览图匹配 Obsidian 主题",
|
||||
"<b>开启:</b>在 Markdown 预览模式下,为 Embed 生成 <a href='https://en.wikipedia.org/wiki/Scalable_Vector_Graphics' target='_blank'>SVG</a> 格式的预览图。<br>" +
|
||||
"<b>关闭:</b>为 Embed 生成 <a href='' target='_blank'>PNG</a> 格式的预览图。注意:PNG 格式预览图不支持某些 <a href='https://www.youtube.com/watch?v=yZQoJg2RCKI&t=633s' target='_blank'>绘图元素的块引用特性</a>。",
|
||||
PREVIEW_MATCH_OBSIDIAN_NAME: "Embed 预览图匹配 Obsidian 主题",
|
||||
PREVIEW_MATCH_OBSIDIAN_DESC:
|
||||
"开启此项,则当 Obsidian 处于黑暗模式时,预览图也会以黑暗模式渲染;" +
|
||||
"当 Obsidian 处于明亮模式时,的预览图也会以明亮模式渲染。<br>您可能还需要关闭“导出的图像包含背景”开关,来获得与 Obsidian 更加协调的观感。",
|
||||
EMBED_WIDTH_NAME: "预览图的默认宽度",
|
||||
"开启此项,则当 Obsidian 处于黑暗模式时,Embed 的预览图也会以黑暗模式渲染;当 Obsidian 处于明亮模式时,预览图也会以明亮模式渲染。<br>" +
|
||||
"您可能还需要关闭“导出的图像包含背景”开关,来获得与 Obsidian 更加协调的观感。",
|
||||
EMBED_WIDTH_NAME: "Embed 预览图的默认宽度",
|
||||
EMBED_WIDTH_DESC:
|
||||
"该选项同时作用于 Obsidian 实时预览模式下的编辑视图和阅读视图,以及鼠标悬停时的预览图。<br>" +
|
||||
"您可为嵌入到文档中的某个绘图单独设置此项," +
|
||||
"该选项同时作用于 Obsidian 实时预览模式下的编辑视图和阅读视图,以及鼠标悬停时浮现的预览图。<br>" +
|
||||
"您可为某个要嵌入到文档中的绘图(Embed)单独设置此项," +
|
||||
"方法是修改相应的链接格式为形如 <code>![[drawing.excalidraw|100]]</code> 或 <code>[[drawing.excalidraw|100x100]]</code> 的格式。",
|
||||
EMBED_TYPE_NAME: "“嵌入绘图到当前文档”命令的源文件类型",
|
||||
EMBED_TYPE_NAME: "“嵌入绘图到当前文档”系列命令的源文件类型",
|
||||
EMBED_TYPE_DESC:
|
||||
"在命令面板中执行“嵌入绘图到当前文档”之类命令时,要嵌入绘图文件,还是嵌入其 PNG 或 SVG 副本。<br>" +
|
||||
"如果您想在该下拉框中选择 PNG 或 SVG 副本,需要先开启下方的“自动导出 PNG 格式副本”或“自动导出 SVG 格式副本”开关。" +
|
||||
"若您选择了嵌入 PNG 或 SVG 副本,当绘图缺少对应的 PNG 或 SVG 副本时,该命令将会插入一条损坏的链接,您需要打开绘图文件并手动导出副本才能修复 —— " +
|
||||
"该选项不会帮您自动生成 PNG/SVG 副本,而只会引用已经存在的 PNG/SVG 副本。",
|
||||
EMBED_WIKILINK_NAME: "“嵌入绘图到当前文档”命令产生的链接类型",
|
||||
"在命令面板中执行“嵌入绘图到当前文档”系列命令时,要嵌入绘图文件本身,还是嵌入其 PNG 或 SVG 副本。<br>" +
|
||||
"如果您想选择 PNG 或 SVG 副本,需要先开启下方的“自动导出 PNG 副本”或“自动导出 SVG 副本”开关。<br>" +
|
||||
"如果您选择了 PNG 或 SVG 副本,当副本不存在时,该命令将会插入一条损坏的链接,您需要打开绘图文件并手动导出副本才能修复 —— " +
|
||||
"也就是说,该选项不会自动帮您生成 PNG/SVG 副本,而只会引用已有的 PNG/SVG 副本。",
|
||||
EMBED_WIKILINK_NAME: "“嵌入绘图到当前文档”命令产生的内部链接类型",
|
||||
EMBED_WIKILINK_DESC:
|
||||
"<b>开启:</b>将产生 <code>![[Wiki 链接]]</code>。<b>关闭:</b>将产生 <code></code>。",
|
||||
EXPORT_PNG_SCALE_NAME: "导出 PNG 图像的比例",
|
||||
EXPORT_PNG_SCALE_NAME: "导出的 PNG 图像的比例",
|
||||
EXPORT_PNG_SCALE_DESC: "导出的 PNG 图像的大小比例",
|
||||
EXPORT_BACKGROUND_NAME: "导出的图像包含背景",
|
||||
EXPORT_BACKGROUND_DESC: "如果关闭,将导出透明背景的图像。",
|
||||
EXPORT_SVG_PADDING_NAME: "导出 SVG 图像的边距",
|
||||
EXPORT_SVG_PADDING_DESC:
|
||||
"导出的 PNG 图像的空白边距(像素)。增加该值,可以避免在导出 SVG 图像时,过于靠近画布边缘的图形被裁掉。",
|
||||
EXPORT_BACKGROUND_DESC:
|
||||
"如果关闭,将导出透明背景的图像。",
|
||||
EXPORT_PADDING_NAME: "导出的图像的空白边距",
|
||||
EXPORT_PADDING_DESC:
|
||||
"导出的 SVG/PNG 图像四周的空白边距(单位:像素)。<br>" +
|
||||
"增加该值,可以避免在导出图像时,靠近图像边缘的图形被裁掉。<br>" +
|
||||
"您可为某个绘图单独设置此项,方法是在其 frontmatter 中添加形如 <code>excalidraw-export-padding: 5<code> 的键值对。",
|
||||
EXPORT_THEME_NAME: "导出的图像包含主题",
|
||||
EXPORT_THEME_DESC:
|
||||
"导出与绘图的黑暗/明亮主题匹配的图像。" +
|
||||
"如果关闭,在黑暗主题下导出的图像将和明亮主题一样。",
|
||||
EXPORT_HEAD: "导出设置",
|
||||
EXPORT_SYNC_NAME: "保持 .SVG 和 .PNG 文件名与绘图文件同步",
|
||||
EXPORT_SYNC_NAME:
|
||||
"保持 SVG/PNG 文件名与绘图文件同步",
|
||||
EXPORT_SYNC_DESC:
|
||||
"打开后,当绘图文件被重命名时,插件将同步更新同文件夹下的同名 .SVG 和 .PNG 文件。" +
|
||||
"当绘图文件被删除时,插件将自动删除同文件夹下的同名 .SVG 和 .PNG 文件。",
|
||||
EXPORT_SVG_NAME: "自动导出 SVG 格式副本",
|
||||
EXPORT_SVG_NAME: "自动导出 SVG 副本",
|
||||
EXPORT_SVG_DESC:
|
||||
"自动导出和绘图文件同名的 SVG 格式副本。" +
|
||||
"自动导出和绘图文件同名的 SVG 副本。" +
|
||||
"插件会将副本保存到绘图文件所在的文件夹中。" +
|
||||
"在文档中嵌入这个 SVG 文件,相比直接嵌入绘图文件,具有更强的跨平台能力。<br>" +
|
||||
"此开关开启时,每次您编辑 Excalidraw 绘图,其 SVG 文件副本都会同步更新。",
|
||||
EXPORT_PNG_NAME: "自动导出 PNG 格式副本",
|
||||
EXPORT_PNG_DESC: "和“自动导出 SVG 格式副本”类似,但是导出格式为 *.PNG。",
|
||||
"此开关开启时,每次您编辑 Excalidraw 绘图,其 SVG 文件副本都会同步更新。<br>" +
|
||||
"您可为某个绘图单独设置此项,方法是在其 frontmatter 中添加形如 <code>excalidraw-autoexport: none/both/svg/png</code>" +
|
||||
"的键值对",
|
||||
EXPORT_PNG_NAME: "自动导出 PNG 副本",
|
||||
EXPORT_PNG_DESC: "和“自动导出 SVG 副本”类似,但是导出格式为 *.PNG。",
|
||||
EXPORT_BOTH_DARK_AND_LIGHT_NAME: "同时导出黑暗和明亮风格的图像",
|
||||
EXPORT_BOTH_DARK_AND_LIGHT_DESC: "若开启,Excalidraw 将导出两个文件:filename.dark.png(或 filename.dark.svg)和 filename.light.png(或 filename.light.svg)。<br>"+
|
||||
"该选项可作用于“自动导出 SVG 副本”、“自动导出 PNG 副本”,以及其他的手动的导出命令。",
|
||||
COMPATIBILITY_HEAD: "兼容性设置",
|
||||
EXPORT_EXCALIDRAW_NAME: "自动导出 Excalidraw 格式副本",
|
||||
EXPORT_EXCALIDRAW_DESC:
|
||||
"和“自动导出 SVG 格式副本”类似,但是导出格式为 *.excalidraw。",
|
||||
SYNC_EXCALIDRAW_NAME: "保持同一绘图的新旧格式文件内容一致",
|
||||
EXPORT_EXCALIDRAW_NAME: "自动导出 Excalidraw 旧格式副本",
|
||||
EXPORT_EXCALIDRAW_DESC: "和“自动导出 SVG 副本”类似,但是导出格式为 *.excalidraw。",
|
||||
SYNC_EXCALIDRAW_NAME:
|
||||
"新旧格式绘图文件的内容保持同步",
|
||||
SYNC_EXCALIDRAW_DESC:
|
||||
"如果旧格式(*.excalidraw)绘图文件的修改日期比新格式(*.md)更新," +
|
||||
"则根据旧格式文件的内容来更新新格式文件。",
|
||||
@@ -315,15 +378,20 @@ export default {
|
||||
"开启此功能后,您通过功能区按钮、命令面板、" +
|
||||
"文件浏览器等创建的绘图都将是旧格式(*.excalidraw)。" +
|
||||
"此外,您打开旧格式绘图文件时将不再收到提醒消息。",
|
||||
MATHJAX_NAME: "MathJax (LaTeX) 的 javascript 库服务器",
|
||||
MATHJAX_DESC: "如果您在绘图中使用 LaTeX,插件需要从服务器获取并加载一个 javascript 库。" +
|
||||
"如果您的网络无法访问某些库服务器,可以尝试通过此选项更换库服务器。"+
|
||||
"更改此选项后,您可能需要重启 Obsidian 来使其生效。",
|
||||
EXPERIMENTAL_HEAD: "实验性功能",
|
||||
EXPERIMENTAL_DESC:
|
||||
"以下部分设置不会立即生效,需要刷新文件资源管理器或者重启 Obsidian 才会生效。",
|
||||
FIELD_SUGGESTER_NAME: "开启 Field Suggester",
|
||||
FIELD_SUGGESTER_NAME: "开启字段建议",
|
||||
FIELD_SUGGESTER_DESC:
|
||||
"开启后,当您在编辑器中输入 <code>excalidraw-</code> 或者 <code>ea.</code> 时,会弹出一个带有函数说明的自动补全提示菜单。<br>" +
|
||||
"该功能借鉴了 Breadcrumbs 和 Templater 插件。",
|
||||
FILETYPE_NAME: "在文件浏览器中为 excalidraw.md 文件添加类型标识符(如 ✏️)",
|
||||
FILETYPE_DESC: "可通过下一项设置来自定义类型标识符。",
|
||||
FILETYPE_DESC:
|
||||
"可通过下一项设置来自定义类型标识符。",
|
||||
FILETAG_NAME: "excalidraw.md 文件的类型标识符",
|
||||
FILETAG_DESC: "要显示为类型标识符的 emoji 或文本。",
|
||||
INSERT_EMOJI: "插入 emoji",
|
||||
@@ -350,7 +418,8 @@ export default {
|
||||
SELECT_FILE_TO_LINK: "选择要插入(链接)到当前绘图中的文件。",
|
||||
SELECT_DRAWING: "选择要插入(以图像形式嵌入)到当前绘图中的图像。",
|
||||
TYPE_FILENAME: "键入要选择的绘图名称。",
|
||||
SELECT_FILE_OR_TYPE_NEW: "选择已有绘图,或者新绘图的类型,然后按回车。",
|
||||
SELECT_FILE_OR_TYPE_NEW:
|
||||
"选择已有绘图,或者新绘图的类型,然后按回车。",
|
||||
SELECT_TO_EMBED: "选择要插入(嵌入)到当前文档中的绘图。",
|
||||
SELECT_MD: "选择要插入(以图像形式嵌入)到当前绘图中的 Markdown 文档。",
|
||||
|
||||
@@ -359,7 +428,8 @@ export default {
|
||||
"EXCALIDRAW 警告\n停止加载嵌入的图像,因为此文件中存在死循环:\n",
|
||||
|
||||
//Scripts.ts
|
||||
SCRIPT_EXECUTION_ERROR: "脚本运行错误。请在开发者控制台中查看错误信息。",
|
||||
SCRIPT_EXECUTION_ERROR:
|
||||
"脚本运行错误。请在开发者控制台中查看错误信息。",
|
||||
|
||||
//ExcalidrawData.ts
|
||||
LOAD_FROM_BACKUP: "Excalidraw 文件已损坏。尝试从备份文件中加载。",
|
||||
|
||||
4393
src/main.ts
@@ -26,9 +26,9 @@ export class ActionButton extends React.Component<ButtonProps, ButtonState> {
|
||||
return (
|
||||
<button
|
||||
style={{
|
||||
width: "fit-content",
|
||||
padding: "2px",
|
||||
margin: "4px",
|
||||
//width: "fit-content",
|
||||
//padding: "2px",
|
||||
//margin: "4px",
|
||||
}}
|
||||
className="ToolIcon_type_button ToolIcon_size_small ToolIcon_type_button--show ToolIcon"
|
||||
title={this.props.title}
|
||||
@@ -42,7 +42,7 @@ export class ActionButton extends React.Component<ButtonProps, ButtonState> {
|
||||
onPointerDown={() => {
|
||||
this.toastMessageTimeout = window.setTimeout(
|
||||
() =>
|
||||
this.props.view.excalidrawAPI?.setToastMessage(this.props.title),
|
||||
this.props.view.excalidrawAPI?.setToast({message:this.props.title}),
|
||||
300,
|
||||
);
|
||||
}}
|
||||
|
||||
21
src/menu/MenuLinks.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import { AppState } from "@zsviczian/excalidraw/types/types";
|
||||
import clsx from "clsx";
|
||||
import * as React from "react";
|
||||
import ExcalidrawPlugin from "../main";
|
||||
|
||||
|
||||
export class MenuLinks {
|
||||
plugin: ExcalidrawPlugin;
|
||||
ref: React.MutableRefObject<any>;
|
||||
|
||||
constructor(plugin: ExcalidrawPlugin, ref: React.MutableRefObject<any>) {
|
||||
this.plugin = plugin;
|
||||
this.ref = ref;
|
||||
}
|
||||
|
||||
render = (isMobile: boolean, appState: AppState) => {
|
||||
return (
|
||||
<div>Hello</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
115
src/settings.ts
@@ -4,6 +4,7 @@ import {
|
||||
normalizePath,
|
||||
PluginSettingTab,
|
||||
Setting,
|
||||
TextComponent,
|
||||
TFile,
|
||||
} from "obsidian";
|
||||
import { VIEW_TYPE_EXCALIDRAW } from "./Constants";
|
||||
@@ -15,6 +16,7 @@ import {
|
||||
getEmbedFilename,
|
||||
} from "./utils/FileUtils";
|
||||
import {
|
||||
fragWithHTML,
|
||||
setLeftHandedMode,
|
||||
} from "./utils/Utils";
|
||||
|
||||
@@ -48,12 +50,16 @@ export interface ExcalidrawSettings {
|
||||
showLinkBrackets: boolean;
|
||||
linkPrefix: string;
|
||||
urlPrefix: string;
|
||||
parseTODO: boolean;
|
||||
todo: string;
|
||||
done: string;
|
||||
hoverPreviewWithoutCTRL: boolean;
|
||||
linkOpacity: number;
|
||||
allowCtrlClick: boolean; //if disabled only the link button in the view header will open links
|
||||
forceWrap: boolean;
|
||||
pageTransclusionCharLimit: number;
|
||||
wordWrappingDefault: number;
|
||||
removeTransclusionQuoteSigns: boolean;
|
||||
iframelyAllowed: boolean;
|
||||
pngExportScale: number;
|
||||
exportWithTheme: boolean;
|
||||
@@ -62,6 +68,7 @@ export interface ExcalidrawSettings {
|
||||
keepInSync: boolean;
|
||||
autoexportSVG: boolean;
|
||||
autoexportPNG: boolean;
|
||||
autoExportLightAndDark: boolean;
|
||||
autoexportExcalidraw: boolean;
|
||||
embedType: "excalidraw" | "PNG" | "SVG";
|
||||
embedWikiLink: boolean;
|
||||
@@ -101,6 +108,7 @@ export interface ExcalidrawSettings {
|
||||
defaultTrayMode: boolean;
|
||||
previousRelease: string;
|
||||
showReleaseNotes: boolean;
|
||||
showNewVersionNotification: boolean;
|
||||
mathjaxSourceURL: string;
|
||||
}
|
||||
|
||||
@@ -131,6 +139,9 @@ export const DEFAULT_SETTINGS: ExcalidrawSettings = {
|
||||
zoomToFitMaxLevel: 2,
|
||||
linkPrefix: "📍",
|
||||
urlPrefix: "🌐",
|
||||
parseTODO: false,
|
||||
todo: "☐",
|
||||
done: "🗹",
|
||||
hoverPreviewWithoutCTRL: false,
|
||||
linkOpacity: 1,
|
||||
openInAdjacentPane: false,
|
||||
@@ -140,14 +151,16 @@ export const DEFAULT_SETTINGS: ExcalidrawSettings = {
|
||||
forceWrap: false,
|
||||
pageTransclusionCharLimit: 200,
|
||||
wordWrappingDefault: 0,
|
||||
removeTransclusionQuoteSigns: true,
|
||||
iframelyAllowed: true,
|
||||
pngExportScale: 1,
|
||||
exportWithTheme: true,
|
||||
exportWithBackground: true,
|
||||
exportPaddingSVG: 10,
|
||||
exportPaddingSVG: 10, //since 1.6.17, not only SVG but also PNG
|
||||
keepInSync: false,
|
||||
autoexportSVG: false,
|
||||
autoexportPNG: false,
|
||||
autoExportLightAndDark: false,
|
||||
autoexportExcalidraw: false,
|
||||
embedType: "excalidraw",
|
||||
embedWikiLink: true,
|
||||
@@ -182,12 +195,10 @@ export const DEFAULT_SETTINGS: ExcalidrawSettings = {
|
||||
defaultTrayMode: false,
|
||||
previousRelease: "1.6.13",
|
||||
showReleaseNotes: true,
|
||||
showNewVersionNotification: true,
|
||||
mathjaxSourceURL: "https://cdn.jsdelivr.net/npm/mathjax@3.2.1/es5/tex-svg.js"
|
||||
};
|
||||
|
||||
const fragWithHTML = (html: string) =>
|
||||
createFragment((frag) => (frag.createDiv().innerHTML = html));
|
||||
|
||||
export class ExcalidrawSettingTab extends PluginSettingTab {
|
||||
plugin: ExcalidrawPlugin;
|
||||
private requestEmbedUpdate: boolean = false;
|
||||
@@ -269,6 +280,18 @@ export class ExcalidrawSettingTab extends PluginSettingTab {
|
||||
}),
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(t("NEWVERSION_NOTIFICATION_NAME"))
|
||||
.setDesc(fragWithHTML(t("NEWVERSION_NOTIFICATION_DESC")))
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(this.plugin.settings.showNewVersionNotification)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.showNewVersionNotification = value;
|
||||
this.applySettingsUpdate();
|
||||
}),
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(t("FOLDER_NAME"))
|
||||
.setDesc(fragWithHTML(t("FOLDER_DESC")))
|
||||
@@ -589,7 +612,7 @@ export class ExcalidrawSettingTab extends PluginSettingTab {
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(this.plugin.settings.showLinkBrackets)
|
||||
.onChange(async (value) => {
|
||||
.onChange(value => {
|
||||
this.plugin.settings.showLinkBrackets = value;
|
||||
this.applySettingsUpdate(true);
|
||||
}),
|
||||
@@ -602,7 +625,7 @@ export class ExcalidrawSettingTab extends PluginSettingTab {
|
||||
text
|
||||
.setPlaceholder(t("INSERT_EMOJI"))
|
||||
.setValue(this.plugin.settings.linkPrefix)
|
||||
.onChange((value) => {
|
||||
.onChange(value => {
|
||||
this.plugin.settings.linkPrefix = value;
|
||||
this.applySettingsUpdate(true);
|
||||
}),
|
||||
@@ -615,12 +638,61 @@ export class ExcalidrawSettingTab extends PluginSettingTab {
|
||||
text
|
||||
.setPlaceholder(t("INSERT_EMOJI"))
|
||||
.setValue(this.plugin.settings.urlPrefix)
|
||||
.onChange(async (value) => {
|
||||
.onChange(value => {
|
||||
this.plugin.settings.urlPrefix = value;
|
||||
this.applySettingsUpdate(true);
|
||||
}),
|
||||
);
|
||||
|
||||
let todoPrefixSetting:TextComponent, donePrefixSetting:TextComponent;
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(t("PARSE_TODO_NAME"))
|
||||
.setDesc(fragWithHTML(t("PARSE_TODO_DESC")))
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(this.plugin.settings.parseTODO)
|
||||
.onChange(value => {
|
||||
this.plugin.settings.parseTODO = value;
|
||||
todoPrefixSetting.setDisabled(!value);
|
||||
donePrefixSetting.setDisabled(!value);
|
||||
this.applySettingsUpdate(true);
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(t("TODO_NAME"))
|
||||
.setDesc(fragWithHTML(t("TODO_DESC")))
|
||||
.addText((text) => {
|
||||
todoPrefixSetting = text;
|
||||
text
|
||||
.setPlaceholder(t("INSERT_EMOJI"))
|
||||
.setValue(this.plugin.settings.todo)
|
||||
.onChange(value => {
|
||||
this.plugin.settings.todo = value;
|
||||
this.applySettingsUpdate(true);
|
||||
})
|
||||
}
|
||||
);
|
||||
todoPrefixSetting.setDisabled(!this.plugin.settings.parseTODO);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(t("DONE_NAME"))
|
||||
.setDesc(fragWithHTML(t("DONE_DESC")))
|
||||
.setDisabled(!this.plugin.settings.parseTODO)
|
||||
.addText((text) => {
|
||||
donePrefixSetting = text;
|
||||
text
|
||||
.setPlaceholder(t("INSERT_EMOJI"))
|
||||
.setValue(this.plugin.settings.done)
|
||||
.onChange(value => {
|
||||
this.plugin.settings.done = value;
|
||||
this.applySettingsUpdate(true);
|
||||
})
|
||||
}
|
||||
);
|
||||
donePrefixSetting.setDisabled(!this.plugin.settings.parseTODO);
|
||||
|
||||
let opacityText: HTMLDivElement;
|
||||
new Setting(containerEl)
|
||||
.setName(t("LINKOPACITY_NAME"))
|
||||
@@ -737,6 +809,19 @@ export class ExcalidrawSettingTab extends PluginSettingTab {
|
||||
}),
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(t("QUOTE_TRANSCLUSION_REMOVE_NAME"))
|
||||
.setDesc(fragWithHTML(t("QUOTE_TRANSCLUSION_REMOVE_DESC")))
|
||||
.addToggle(toggle =>
|
||||
toggle
|
||||
.setValue(this.plugin.settings.removeTransclusionQuoteSigns)
|
||||
.onChange(value => {
|
||||
this.plugin.settings.removeTransclusionQuoteSigns = value;
|
||||
this.requestEmbedUpdate = true;
|
||||
this.applySettingsUpdate(true);
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(t("GET_URL_TITLE_NAME"))
|
||||
.setDesc(fragWithHTML(t("GET_URL_TITLE_DESC")))
|
||||
@@ -996,8 +1081,8 @@ export class ExcalidrawSettingTab extends PluginSettingTab {
|
||||
let exportPadding: HTMLDivElement;
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(t("EXPORT_SVG_PADDING_NAME"))
|
||||
.setDesc(fragWithHTML(t("EXPORT_SVG_PADDING_DESC")))
|
||||
.setName(t("EXPORT_PADDING_NAME"))
|
||||
.setDesc(fragWithHTML(t("EXPORT_PADDING_DESC")))
|
||||
.addSlider((slider) =>
|
||||
slider
|
||||
.setLimits(0, 50, 5)
|
||||
@@ -1093,6 +1178,18 @@ export class ExcalidrawSettingTab extends PluginSettingTab {
|
||||
}),
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(t("EXPORT_BOTH_DARK_AND_LIGHT_NAME"))
|
||||
.setDesc(fragWithHTML(t("EXPORT_BOTH_DARK_AND_LIGHT_DESC")))
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(this.plugin.settings.autoExportLightAndDark)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.autoExportLightAndDark = value;
|
||||
this.applySettingsUpdate();
|
||||
}),
|
||||
);
|
||||
|
||||
this.containerEl.createEl("h1", { text: t("COMPATIBILITY_HEAD") });
|
||||
|
||||
new Setting(containerEl)
|
||||
|
||||
133
src/svgToExcalidraw/attributes.ts
Normal file
@@ -0,0 +1,133 @@
|
||||
import chroma from "chroma-js";
|
||||
import { ExcalidrawElementBase } from "./elements/ExcalidrawElement";
|
||||
|
||||
export function hexWithAlpha(color: string, alpha: number): string {
|
||||
return chroma(color).alpha(alpha).css();
|
||||
}
|
||||
|
||||
export function has(el: Element, attr: string): boolean {
|
||||
return el.hasAttribute(attr);
|
||||
}
|
||||
|
||||
export function get(el: Element, attr: string, backup?: string): string {
|
||||
return el.getAttribute(attr) || backup || "";
|
||||
}
|
||||
|
||||
export function getNum(el: Element, attr: string, backup?: number): number {
|
||||
const numVal = Number(get(el, attr));
|
||||
return numVal === NaN ? backup || 0 : numVal;
|
||||
}
|
||||
|
||||
const presAttrs = {
|
||||
stroke: "stroke",
|
||||
"stroke-opacity": "stroke-opacity",
|
||||
"stroke-width": "stroke-width",
|
||||
fill: "fill",
|
||||
"fill-opacity": "fill-opacity",
|
||||
opacity: "opacity",
|
||||
} as const;
|
||||
|
||||
type ExPartialElement = Partial<ExcalidrawElementBase>;
|
||||
|
||||
type AttrHandlerArgs = {
|
||||
el: Element;
|
||||
exVals: ExPartialElement;
|
||||
};
|
||||
|
||||
type PresAttrHandlers = {
|
||||
[key in keyof typeof presAttrs]: (args: AttrHandlerArgs) => void;
|
||||
};
|
||||
|
||||
const attrHandlers: PresAttrHandlers = {
|
||||
stroke: ({ el, exVals }) => {
|
||||
const strokeColor = get(el, "stroke");
|
||||
|
||||
exVals.strokeColor = has(el, "stroke-opacity")
|
||||
? hexWithAlpha(strokeColor, getNum(el, "stroke-opacity"))
|
||||
: strokeColor;
|
||||
},
|
||||
|
||||
"stroke-opacity": ({ el, exVals }) => {
|
||||
exVals.strokeColor = hexWithAlpha(
|
||||
get(el, "stroke", "#000000"),
|
||||
getNum(el, "stroke-opacity"),
|
||||
);
|
||||
},
|
||||
|
||||
"stroke-width": ({ el, exVals }) => {
|
||||
exVals.strokeWidth = getNum(el, "stroke-width");
|
||||
},
|
||||
|
||||
fill: ({ el, exVals }) => {
|
||||
const fill = get(el, `fill`);
|
||||
|
||||
exVals.backgroundColor = fill === "none" ? "#00000000" : fill;
|
||||
},
|
||||
|
||||
"fill-opacity": ({ el, exVals }) => {
|
||||
exVals.backgroundColor = hexWithAlpha(
|
||||
get(el, "fill", "#000000"),
|
||||
getNum(el, "fill-opacity"),
|
||||
);
|
||||
},
|
||||
|
||||
opacity: ({ el, exVals }) => {
|
||||
exVals.opacity = getNum(el, "opacity", 100);
|
||||
},
|
||||
};
|
||||
|
||||
// Presentation Attributes for SVG Elements:
|
||||
// https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/Presentation
|
||||
export function presAttrsToElementValues(
|
||||
el: Element,
|
||||
): Partial<ExcalidrawElementBase> {
|
||||
const exVals = [...el.attributes].reduce((exVals, attr) => {
|
||||
const name = attr.name;
|
||||
|
||||
if (Object.keys(attrHandlers).includes(name)) {
|
||||
attrHandlers[name as keyof PresAttrHandlers]({ el, exVals });
|
||||
}
|
||||
|
||||
return exVals;
|
||||
}, {} as ExPartialElement);
|
||||
|
||||
return exVals;
|
||||
}
|
||||
|
||||
type FilterAttrs = Partial<
|
||||
Pick<ExcalidrawElementBase, "x" | "y" | "width" | "height">
|
||||
>;
|
||||
|
||||
export function filterAttrsToElementValues(el: Element): FilterAttrs {
|
||||
const filterVals: FilterAttrs = {};
|
||||
|
||||
if (has(el, "x")) {
|
||||
filterVals.x = getNum(el, "x");
|
||||
}
|
||||
|
||||
if (has(el, "y")) {
|
||||
filterVals.y = getNum(el, "y");
|
||||
}
|
||||
|
||||
if (has(el, "width")) {
|
||||
filterVals.width = getNum(el, "width");
|
||||
}
|
||||
|
||||
if (has(el, "height")) {
|
||||
filterVals.height = getNum(el, "height");
|
||||
}
|
||||
|
||||
return filterVals;
|
||||
}
|
||||
|
||||
export function pointsAttrToPoints(el: Element): number[][] {
|
||||
let points: number[][] = [];
|
||||
|
||||
if (has(el, "points")) {
|
||||
points = get(el, "points")
|
||||
.split(" ")
|
||||
.map((p) => p.split(",").map(parseFloat));
|
||||
}
|
||||
|
||||
return points;
|
||||
}
|
||||
117
src/svgToExcalidraw/elements/ExcalidrawElement.ts
Normal file
@@ -0,0 +1,117 @@
|
||||
import { randomId, randomInteger } from "../utils";
|
||||
|
||||
import { ExcalidrawLinearElement, FillStyle, GroupId, StrokeSharpness, StrokeStyle } from "@zsviczian/excalidraw/types/element/types";
|
||||
|
||||
export type Point = [number, number];
|
||||
|
||||
export type ExcalidrawElementBase = {
|
||||
id: string;
|
||||
x: number;
|
||||
y: number;
|
||||
strokeColor: string;
|
||||
backgroundColor: string;
|
||||
fillStyle: FillStyle;
|
||||
strokeWidth: number;
|
||||
strokeStyle: StrokeStyle;
|
||||
strokeSharpness: StrokeSharpness;
|
||||
roughness: number;
|
||||
opacity: number;
|
||||
width: number;
|
||||
height: number;
|
||||
angle: number;
|
||||
/** Random integer used to seed shape generation so that the roughjs shape
|
||||
doesn't differ across renders. */
|
||||
seed: number;
|
||||
/** Integer that is sequentially incremented on each change. Used to reconcile
|
||||
elements during collaboration or when saving to server. */
|
||||
version: number;
|
||||
/** Random integer that is regenerated on each change.
|
||||
Used for deterministic reconciliation of updates during collaboration,
|
||||
in case the versions (see above) are identical. */
|
||||
versionNonce: number;
|
||||
isDeleted: boolean;
|
||||
/** List of groups the element belongs to.
|
||||
Ordered from deepest to shallowest. */
|
||||
groupIds: GroupId[];
|
||||
/** Ids of (linear) elements that are bound to this element. */
|
||||
boundElementIds: ExcalidrawLinearElement["id"][] | null;
|
||||
};
|
||||
|
||||
export type ExcalidrawRectangle = ExcalidrawElementBase & {
|
||||
type: "rectangle";
|
||||
};
|
||||
|
||||
export type ExcalidrawLine = ExcalidrawElementBase & {
|
||||
type: "line";
|
||||
points: readonly Point[];
|
||||
};
|
||||
|
||||
export type ExcalidrawEllipse = ExcalidrawElementBase & {
|
||||
type: "ellipse";
|
||||
};
|
||||
|
||||
export type ExcalidrawGenericElement =
|
||||
| ExcalidrawRectangle
|
||||
| ExcalidrawEllipse
|
||||
| ExcalidrawLine
|
||||
| ExcalidrawDraw;
|
||||
|
||||
export type ExcalidrawDraw = ExcalidrawElementBase & {
|
||||
type: "line";
|
||||
points: readonly Point[];
|
||||
};
|
||||
|
||||
export function createExElement(): ExcalidrawElementBase {
|
||||
return {
|
||||
id: randomId(),
|
||||
x: 0,
|
||||
y: 0,
|
||||
strokeColor: "#000000",
|
||||
backgroundColor: "#000000",
|
||||
fillStyle: "solid",
|
||||
strokeWidth: 1,
|
||||
strokeStyle: "solid",
|
||||
strokeSharpness: "sharp",
|
||||
roughness: 0,
|
||||
opacity: 100,
|
||||
width: 0,
|
||||
height: 0,
|
||||
angle: 0,
|
||||
seed: randomInteger(),
|
||||
version: 0,
|
||||
versionNonce: 0,
|
||||
isDeleted: false,
|
||||
groupIds: [],
|
||||
boundElementIds: null,
|
||||
};
|
||||
}
|
||||
|
||||
export function createExRect(): ExcalidrawRectangle {
|
||||
return {
|
||||
...createExElement(),
|
||||
type: "rectangle",
|
||||
};
|
||||
}
|
||||
|
||||
export function createExLine(): ExcalidrawLine {
|
||||
return {
|
||||
...createExElement(),
|
||||
type: "line",
|
||||
points: [],
|
||||
};
|
||||
}
|
||||
|
||||
export function createExEllipse(): ExcalidrawEllipse {
|
||||
return {
|
||||
...createExElement(),
|
||||
type: "ellipse",
|
||||
};
|
||||
}
|
||||
|
||||
export function createExDraw(): ExcalidrawDraw {
|
||||
return {
|
||||
...createExElement(),
|
||||
type: "line",
|
||||
points: [],
|
||||
};
|
||||
}
|
||||
21
src/svgToExcalidraw/elements/ExcalidrawScene.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { ExcalidrawGenericElement } from "./ExcalidrawElement";
|
||||
|
||||
class ExcalidrawScene {
|
||||
type = "excalidraw";
|
||||
version = 2;
|
||||
source = "https://excalidraw.com";
|
||||
elements: ExcalidrawGenericElement[] = [];
|
||||
|
||||
constructor(elements:any = []) {
|
||||
this.elements = elements;
|
||||
}
|
||||
|
||||
toExJSON(): any {
|
||||
return {
|
||||
...this,
|
||||
elements: this.elements.map((el) => ({ ...el })),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default ExcalidrawScene;
|
||||
23
src/svgToExcalidraw/elements/Group.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { randomId } from "../utils";
|
||||
import { presAttrsToElementValues } from "../attributes";
|
||||
import { ExcalidrawElementBase } from "../elements/ExcalidrawElement";
|
||||
|
||||
export function getGroupAttrs(groups: Group[]): any {
|
||||
return groups.reduce((acc, { element }) => {
|
||||
const elVals = presAttrsToElementValues(element);
|
||||
|
||||
return { ...acc, ...elVals };
|
||||
}, {} as Partial<ExcalidrawElementBase>);
|
||||
}
|
||||
|
||||
class Group {
|
||||
id = randomId();
|
||||
|
||||
element: Element;
|
||||
|
||||
constructor(element: Element) {
|
||||
this.element = element;
|
||||
}
|
||||
}
|
||||
|
||||
export default Group;
|
||||
5
src/svgToExcalidraw/elements/index.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import * as path from "./path";
|
||||
|
||||
export default {
|
||||
path,
|
||||
};
|
||||
35
src/svgToExcalidraw/elements/path/index.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { RawElement } from "../../types";
|
||||
import { getElementBoundaries } from "../utils";
|
||||
import pathToPoints from "./utils/path-to-points";
|
||||
|
||||
const parse = (node: Element) => {
|
||||
const data = node.getAttribute("d");
|
||||
const backgroundColor = node.getAttribute("fill");
|
||||
const strokeColor = node.getAttribute("stroke");
|
||||
|
||||
return {
|
||||
data: data || "",
|
||||
backgroundColor:
|
||||
(backgroundColor !== "currentColor" && backgroundColor) || "transparent",
|
||||
strokeColor: (strokeColor !== "currentColor" && strokeColor) || "#000000",
|
||||
};
|
||||
};
|
||||
|
||||
export const convert = (node: Element): RawElement[] => {
|
||||
const { data, backgroundColor, strokeColor } = parse(node);
|
||||
const elementsPoints = pathToPoints(data);
|
||||
|
||||
return elementsPoints.map((points) => {
|
||||
const boundaries = getElementBoundaries(points);
|
||||
|
||||
return {
|
||||
type: "line",
|
||||
roughness: 0,
|
||||
strokeSharpness: "sharp",
|
||||
points,
|
||||
backgroundColor,
|
||||
strokeColor,
|
||||
...boundaries,
|
||||
};
|
||||
});
|
||||
};
|
||||
66
src/svgToExcalidraw/elements/path/utils/bezier.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import { safeNumber } from "../../../utils";
|
||||
|
||||
/**
|
||||
* Get a point at a given section of a cubic bezier curve.
|
||||
* This function only supports two dimensions curves
|
||||
* @see https://en.wikipedia.org/wiki/B%C3%A9zier_curve#Cubic_B%C3%A9zier_curves
|
||||
*/
|
||||
const getPointOfCubicCurve = (
|
||||
controlPoints: number[][],
|
||||
section: number,
|
||||
): number[] =>
|
||||
Array.from({ length: 2 }).map((v, i) => {
|
||||
const point =
|
||||
controlPoints[0][i] * (1 - section) ** 3 +
|
||||
3 * controlPoints[1][i] * section * (1 - section) ** 2 +
|
||||
3 * controlPoints[2][i] * section ** 2 * (1 - section) +
|
||||
controlPoints[3][i] * section ** 3;
|
||||
|
||||
return safeNumber(point);
|
||||
});
|
||||
|
||||
/**
|
||||
* Get a point at a given section of a quadratic bezier curve.
|
||||
* This function only supports two dimensions curves
|
||||
* @see https://en.wikipedia.org/wiki/B%C3%A9zier_curve#Quadratic_B%C3%A9zier_curves
|
||||
*/
|
||||
const getPointOfQuadraticCurve = (
|
||||
controlPoints: number[][],
|
||||
section: number,
|
||||
): number[] =>
|
||||
Array.from({ length: 2 }).map((v, i) => {
|
||||
const point =
|
||||
controlPoints[0][i] * (1 - section) ** 2 +
|
||||
2 * controlPoints[1][i] * section * (1 - section) +
|
||||
controlPoints[2][i] * section ** 2;
|
||||
|
||||
return safeNumber(point);
|
||||
});
|
||||
|
||||
/**
|
||||
* Get list of points for a cubic bézier curve.
|
||||
* Starting point is not returned
|
||||
*/
|
||||
export const curveToPoints = (
|
||||
type: "cubic" | "quadratic",
|
||||
controlPoints: number[][],
|
||||
nbPoints = 10,
|
||||
): number[][] => {
|
||||
if (nbPoints <= 0) {
|
||||
throw new Error("Requested amount of points must be positive");
|
||||
} else if (nbPoints > 100) {
|
||||
nbPoints = 100;
|
||||
}
|
||||
|
||||
return Array.from({ length: nbPoints }, (value, index) => {
|
||||
const section = safeNumber(((100 / nbPoints) * (index + 1)) / 100);
|
||||
|
||||
if (type === "cubic") {
|
||||
return getPointOfCubicCurve(controlPoints, section);
|
||||
} else if (type === "quadratic") {
|
||||
return getPointOfQuadraticCurve(controlPoints, section);
|
||||
}
|
||||
|
||||
throw new Error("Invalid bézier curve type requested");
|
||||
});
|
||||
};
|
||||
133
src/svgToExcalidraw/elements/path/utils/ellipse.ts
Normal file
@@ -0,0 +1,133 @@
|
||||
const degreeToRadian = (degree: number): number => (degree * Math.PI) / 180;
|
||||
|
||||
/**
|
||||
* Get each possible ellipses center points given two points and ellipse radius
|
||||
* @see https://math.stackexchange.com/questions/2240031/solving-an-equation-for-an-ellipse
|
||||
*/
|
||||
export const getEllipsesCenter = (
|
||||
curX: number,
|
||||
curY: number,
|
||||
destX: number,
|
||||
destY: number,
|
||||
radiusX: number,
|
||||
radiusY: number,
|
||||
): number[][] => [
|
||||
[
|
||||
(curX + destX) / 2 +
|
||||
((radiusX * (curY - destY)) / (2 * radiusY)) *
|
||||
Math.sqrt(
|
||||
4 /
|
||||
((curX - destX) ** 2 / radiusX ** 2 +
|
||||
(curY - destY) ** 2 / radiusY ** 2) -
|
||||
1,
|
||||
),
|
||||
(curY + destY) / 2 -
|
||||
((radiusY * (curX - destX)) / (2 * radiusX)) *
|
||||
Math.sqrt(
|
||||
4 /
|
||||
((curX - destX) ** 2 / radiusX ** 2 +
|
||||
(curY - destY) ** 2 / radiusY ** 2) -
|
||||
1,
|
||||
),
|
||||
],
|
||||
[
|
||||
(curX + destX) / 2 -
|
||||
((radiusX * (curY - destY)) / (2 * radiusY)) *
|
||||
Math.sqrt(
|
||||
4 /
|
||||
((curX - destX) ** 2 / radiusX ** 2 +
|
||||
(curY - destY) ** 2 / radiusY ** 2) -
|
||||
1,
|
||||
),
|
||||
(curY + destY) / 2 +
|
||||
((radiusY * (curX - destX)) / (2 * radiusX)) *
|
||||
Math.sqrt(
|
||||
4 /
|
||||
((curX - destX) ** 2 / radiusX ** 2 +
|
||||
(curY - destY) ** 2 / radiusY ** 2) -
|
||||
1,
|
||||
),
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Get point of ellipse at given degree
|
||||
*/
|
||||
const getPointAtDegree = (
|
||||
centerX: number,
|
||||
centerY: number,
|
||||
radiusX: number,
|
||||
radiusY: number,
|
||||
degree: number,
|
||||
): number[] => [
|
||||
Math.round(radiusX * Math.cos(degreeToRadian(degree)) + centerX),
|
||||
Math.round(radiusY * Math.sin(degreeToRadian(degree)) + centerY),
|
||||
];
|
||||
|
||||
/**
|
||||
* Get all points of a given ellipse
|
||||
*/
|
||||
export const getEllipsePoints = (
|
||||
centerX: number,
|
||||
centerY: number,
|
||||
radiusX: number,
|
||||
radiusY: number,
|
||||
): number[][] => {
|
||||
const points: number[][] = [];
|
||||
|
||||
for (let i = 0; i < 360; i += 1) {
|
||||
const pointAtDegree = getPointAtDegree(
|
||||
centerX,
|
||||
centerY,
|
||||
radiusX,
|
||||
radiusY,
|
||||
i,
|
||||
);
|
||||
const existingPoint = points.find(
|
||||
([x, y]) => x === pointAtDegree[0] && y === pointAtDegree[1],
|
||||
);
|
||||
|
||||
if (!existingPoint) {
|
||||
points.push(pointAtDegree);
|
||||
}
|
||||
}
|
||||
|
||||
return points;
|
||||
};
|
||||
|
||||
/**
|
||||
* Find ellipse arc given sweep parameter
|
||||
*/
|
||||
export const findArc = (
|
||||
points: number[][],
|
||||
sweep: boolean,
|
||||
curX: number,
|
||||
curY: number,
|
||||
destX: number,
|
||||
destY: number,
|
||||
): number[][] => {
|
||||
const indexCur = points.findIndex(
|
||||
([x, y]) => x === Math.round(curX) && y === Math.round(curY),
|
||||
);
|
||||
const indexDest = points.findIndex(
|
||||
([x, y]) => x === Math.round(destX) && y === Math.round(destY),
|
||||
);
|
||||
const arc = [];
|
||||
const step = sweep ? -1 : 1;
|
||||
|
||||
for (let i = indexDest; true; i += step) {
|
||||
arc.push(points[i]);
|
||||
|
||||
if (i === indexCur) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (sweep && i === 0) {
|
||||
i = points.length;
|
||||
} else if (!sweep && i === points.length - 1) {
|
||||
i = -1;
|
||||
}
|
||||
}
|
||||
|
||||
return arc.reverse();
|
||||
};
|
||||
313
src/svgToExcalidraw/elements/path/utils/path-to-points.ts
Normal file
@@ -0,0 +1,313 @@
|
||||
import { PathCommand } from "../../../types";
|
||||
import { safeNumber } from "../../../utils";
|
||||
import { curveToPoints } from "./bezier";
|
||||
import { findArc, getEllipsePoints, getEllipsesCenter } from "./ellipse";
|
||||
|
||||
const PATH_COMMANDS_REGEX =
|
||||
/(?:([HhVv] *-?\d*(?:\.\d+)?)|([MmLlTt](?: *-?\d*(?:\.\d+)?(?:,| *)?){2})|([Cc](?: *-?\d*(?:\.\d+)?(?:,| *)?){6})|([QqSs](?: *-?\d*(?:\.\d+)?(?:,| *)?){4})|([Aa](?: *-?\d*(?:\.\d+)?(?:,| *)?){7})|(z|Z))/g;
|
||||
const COMMAND_REGEX = /(?:[MmLlHhVvCcSsQqTtAaZz]|(-?\d+(?:\.\d+)?))/g;
|
||||
|
||||
const handleMoveToAndLineTo = (
|
||||
currentPosition: number[],
|
||||
parameters: number[],
|
||||
isRelative: boolean,
|
||||
): number[] => {
|
||||
if (isRelative) {
|
||||
return [
|
||||
currentPosition[0] + parameters[0],
|
||||
currentPosition[1] + parameters[1],
|
||||
];
|
||||
}
|
||||
|
||||
return parameters;
|
||||
};
|
||||
|
||||
const handleHorizontalLineTo = (
|
||||
currentPosition: number[],
|
||||
x: number,
|
||||
isRelative: boolean,
|
||||
): number[] => {
|
||||
if (isRelative) {
|
||||
return [currentPosition[0] + x, currentPosition[1]];
|
||||
}
|
||||
|
||||
return [x, currentPosition[1]];
|
||||
};
|
||||
|
||||
const handleVerticalLineTo = (
|
||||
currentPosition: number[],
|
||||
y: number,
|
||||
isRelative: boolean,
|
||||
): number[] => {
|
||||
if (isRelative) {
|
||||
return [currentPosition[0], currentPosition[1] + y];
|
||||
}
|
||||
|
||||
return [currentPosition[0], y];
|
||||
};
|
||||
|
||||
const handleCubicCurveTo = (
|
||||
currentPosition: number[],
|
||||
parameters: number[],
|
||||
lastCommand: PathCommand,
|
||||
isSimpleForm: boolean,
|
||||
isRelative: boolean,
|
||||
): number[][] => {
|
||||
const controlPoints = [currentPosition];
|
||||
let inferredControlPoint;
|
||||
|
||||
if (isSimpleForm) {
|
||||
inferredControlPoint = ["C", "c"].includes(lastCommand?.type)
|
||||
? [
|
||||
currentPosition[0] - (lastCommand.parameters[2] - currentPosition[0]),
|
||||
currentPosition[1] - (lastCommand.parameters[3] - currentPosition[1]),
|
||||
]
|
||||
: currentPosition;
|
||||
}
|
||||
|
||||
if (isRelative) {
|
||||
controlPoints.push(
|
||||
inferredControlPoint || [
|
||||
currentPosition[0] + parameters[0],
|
||||
currentPosition[1] + parameters[1],
|
||||
],
|
||||
[currentPosition[0] + parameters[2], currentPosition[1] + parameters[3]],
|
||||
[currentPosition[0] + parameters[4], currentPosition[1] + parameters[5]],
|
||||
);
|
||||
} else {
|
||||
controlPoints.push(
|
||||
inferredControlPoint || [parameters[0], parameters[1]],
|
||||
[parameters[2], parameters[3]],
|
||||
[parameters[4], parameters[5]],
|
||||
);
|
||||
}
|
||||
|
||||
return curveToPoints("cubic", controlPoints);
|
||||
};
|
||||
|
||||
const handleQuadraticCurveTo = (
|
||||
currentPosition: number[],
|
||||
parameters: number[],
|
||||
lastCommand: PathCommand,
|
||||
isSimpleForm: boolean,
|
||||
isRelative: boolean,
|
||||
): number[][] => {
|
||||
const controlPoints = [currentPosition];
|
||||
let inferredControlPoint;
|
||||
|
||||
if (isSimpleForm) {
|
||||
inferredControlPoint = ["Q", "q"].includes(lastCommand?.type)
|
||||
? [
|
||||
currentPosition[0] - (lastCommand.parameters[0] - currentPosition[0]),
|
||||
currentPosition[1] - (lastCommand.parameters[1] - currentPosition[1]),
|
||||
]
|
||||
: currentPosition;
|
||||
}
|
||||
|
||||
if (isRelative) {
|
||||
controlPoints.push(
|
||||
inferredControlPoint || [
|
||||
currentPosition[0] + parameters[0],
|
||||
currentPosition[1] + parameters[1],
|
||||
],
|
||||
[currentPosition[0] + parameters[2], currentPosition[1] + parameters[3]],
|
||||
);
|
||||
} else {
|
||||
controlPoints.push(inferredControlPoint || [parameters[0], parameters[1]], [
|
||||
parameters[2],
|
||||
parameters[3],
|
||||
]);
|
||||
}
|
||||
|
||||
return curveToPoints("quadratic", controlPoints);
|
||||
};
|
||||
|
||||
/**
|
||||
* @todo handle arcs rotation
|
||||
* @todo handle specific cases where only one ellipse can exist
|
||||
*/
|
||||
const handleArcTo = (
|
||||
currentPosition: number[],
|
||||
[radiusX, radiusY, , large, sweep, destX, destY]: number[],
|
||||
isRelative: boolean,
|
||||
): number[][] => {
|
||||
destX = isRelative ? currentPosition[0] + destX : destX;
|
||||
destY = isRelative ? currentPosition[1] + destY : destY;
|
||||
|
||||
const ellipsesCenter = getEllipsesCenter(
|
||||
currentPosition[0],
|
||||
currentPosition[1],
|
||||
destX,
|
||||
destY,
|
||||
radiusX,
|
||||
radiusY,
|
||||
);
|
||||
|
||||
const ellipsesPoints = [
|
||||
getEllipsePoints(
|
||||
ellipsesCenter[0][0],
|
||||
ellipsesCenter[0][1],
|
||||
radiusX,
|
||||
radiusY,
|
||||
),
|
||||
getEllipsePoints(
|
||||
ellipsesCenter[1][0],
|
||||
ellipsesCenter[1][1],
|
||||
radiusX,
|
||||
radiusY,
|
||||
),
|
||||
];
|
||||
|
||||
const arcs = [
|
||||
findArc(
|
||||
ellipsesPoints[0],
|
||||
!!sweep,
|
||||
currentPosition[0],
|
||||
currentPosition[1],
|
||||
destX,
|
||||
destY,
|
||||
),
|
||||
findArc(
|
||||
ellipsesPoints[1],
|
||||
!!sweep,
|
||||
currentPosition[0],
|
||||
currentPosition[1],
|
||||
destX,
|
||||
destY,
|
||||
),
|
||||
];
|
||||
|
||||
const finalArc = arcs.reduce(
|
||||
(arc, curArc) =>
|
||||
(large && curArc.length > arc.length) ||
|
||||
(!large && (!arc.length || curArc.length < arc.length))
|
||||
? curArc
|
||||
: arc,
|
||||
[],
|
||||
);
|
||||
|
||||
return finalArc;
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a SVG path data to list of points
|
||||
*/
|
||||
const pathToPoints = (path: string): number[][][] => {
|
||||
const commands = path.match(PATH_COMMANDS_REGEX);
|
||||
const elements = [];
|
||||
const commandsHistory = [];
|
||||
let currentPosition = [0, 0];
|
||||
let points = [];
|
||||
|
||||
if (!commands?.length) {
|
||||
throw new Error("No commands found in given path");
|
||||
}
|
||||
|
||||
for (const command of commands) {
|
||||
const lastCommand = commandsHistory[commandsHistory.length - 2];
|
||||
const commandMatch = command.match(COMMAND_REGEX);
|
||||
|
||||
currentPosition = points[points.length - 1] || currentPosition;
|
||||
|
||||
if (commandMatch?.length) {
|
||||
const commandType = commandMatch[0];
|
||||
const parameters = commandMatch
|
||||
.slice(1, commandMatch.length)
|
||||
.map((parameter) => safeNumber(Number(parameter)));
|
||||
const isRelative = commandType.toLowerCase() === commandType;
|
||||
|
||||
commandsHistory.push({
|
||||
type: commandType,
|
||||
parameters,
|
||||
isRelative,
|
||||
});
|
||||
|
||||
switch (commandType) {
|
||||
case "M":
|
||||
case "m":
|
||||
case "L":
|
||||
case "l":
|
||||
points.push(
|
||||
handleMoveToAndLineTo(currentPosition, parameters, isRelative),
|
||||
);
|
||||
|
||||
break;
|
||||
case "H":
|
||||
case "h":
|
||||
points.push(
|
||||
handleHorizontalLineTo(currentPosition, parameters[0], isRelative),
|
||||
);
|
||||
|
||||
break;
|
||||
case "V":
|
||||
case "v":
|
||||
points.push(
|
||||
handleVerticalLineTo(currentPosition, parameters[0], isRelative),
|
||||
);
|
||||
|
||||
break;
|
||||
case "C":
|
||||
case "c":
|
||||
case "S":
|
||||
case "s":
|
||||
points.push(
|
||||
...handleCubicCurveTo(
|
||||
currentPosition,
|
||||
parameters,
|
||||
lastCommand,
|
||||
["S", "s"].includes(commandType),
|
||||
isRelative,
|
||||
),
|
||||
);
|
||||
|
||||
break;
|
||||
case "Q":
|
||||
case "q":
|
||||
case "T":
|
||||
case "t":
|
||||
points.push(
|
||||
...handleQuadraticCurveTo(
|
||||
currentPosition,
|
||||
parameters,
|
||||
lastCommand,
|
||||
["T", "t"].includes(commandType),
|
||||
isRelative,
|
||||
),
|
||||
);
|
||||
|
||||
break;
|
||||
case "A":
|
||||
case "a":
|
||||
points.push(...handleArcTo(currentPosition, parameters, isRelative));
|
||||
|
||||
break;
|
||||
case "Z":
|
||||
case "z":
|
||||
if (points.length) {
|
||||
if (
|
||||
currentPosition[0] !== points[0][0] ||
|
||||
currentPosition[1] !== points[0][1]
|
||||
) {
|
||||
points.push(points[0]);
|
||||
}
|
||||
|
||||
elements.push(points);
|
||||
}
|
||||
|
||||
points = [];
|
||||
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// console.error("Unsupported command provided will be ignored:", command);
|
||||
}
|
||||
}
|
||||
|
||||
if (elements.length === 0 && points.length) {
|
||||
elements.push(points);
|
||||
}
|
||||
|
||||
return elements;
|
||||
};
|
||||
|
||||
export default pathToPoints;
|
||||
39
src/svgToExcalidraw/elements/utils.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { ElementBoundaries } from "../types";
|
||||
|
||||
export const getElementBoundaries = (points: number[][]): ElementBoundaries => {
|
||||
const { x, y } = points.reduce(
|
||||
(boundaries, [x, y]) => {
|
||||
if (x < boundaries.x.min) {
|
||||
boundaries.x.min = x;
|
||||
}
|
||||
if (x > boundaries.x.max) {
|
||||
boundaries.x.max = x;
|
||||
}
|
||||
if (y < boundaries.y.min) {
|
||||
boundaries.y.min = y;
|
||||
}
|
||||
if (y > boundaries.y.max) {
|
||||
boundaries.y.max = y;
|
||||
}
|
||||
|
||||
return boundaries;
|
||||
},
|
||||
{
|
||||
x: {
|
||||
min: Infinity,
|
||||
max: 0,
|
||||
},
|
||||
y: {
|
||||
min: Infinity,
|
||||
max: 0,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
x: x.min,
|
||||
y: y.min,
|
||||
width: x.max - x.min,
|
||||
height: y.max - y.min,
|
||||
};
|
||||
};
|
||||
40
src/svgToExcalidraw/parser.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import ExcalidrawScene from "./elements/ExcalidrawScene";
|
||||
import Group from "./elements/Group";
|
||||
import { createTreeWalker, walk } from "./walker";
|
||||
|
||||
export type ConversionResult = {
|
||||
hasErrors: boolean;
|
||||
errors: NodeListOf<Element> | null;
|
||||
content: any; // Serialized Excalidraw JSON
|
||||
};
|
||||
|
||||
export const svgToExcalidraw = (svgString: string): ConversionResult => {
|
||||
const parser = new DOMParser();
|
||||
const svgDOM = parser.parseFromString(svgString, "image/svg+xml");
|
||||
|
||||
// was there a parsing error?
|
||||
const errorsElements = svgDOM.querySelectorAll("parsererror");
|
||||
const hasErrors = errorsElements.length > 0;
|
||||
let content = null;
|
||||
|
||||
if (hasErrors) {
|
||||
console.error(
|
||||
"There were errors while parsing the given SVG: ",
|
||||
[...errorsElements].map((el) => el.innerHTML),
|
||||
);
|
||||
} else {
|
||||
const tw = createTreeWalker(svgDOM);
|
||||
const scene = new ExcalidrawScene();
|
||||
const groups: Group[] = [];
|
||||
|
||||
walk({ tw, scene, groups, root: svgDOM }, tw.nextNode());
|
||||
|
||||
content = scene.elements; //scene.toExJSON();
|
||||
}
|
||||
|
||||
return {
|
||||
hasErrors,
|
||||
errors: hasErrors ? errorsElements : null,
|
||||
content,
|
||||
};
|
||||
};
|
||||
2
src/svgToExcalidraw/readme.md
Normal file
@@ -0,0 +1,2 @@
|
||||
Original source https://github.com/excalidraw/svg-to-excalidraw. Last commit: https://github.com/excalidraw/svg-to-excalidraw/commit/6f6e4b7269c4194b56cf7517a8357ba73be12a3a
|
||||
Embedded into the project instead of using an import because compiled file size difference (smaller this way). Also the svg-to-excalidraw package has not been maintained for over a year, thus I don't expect to miss out on frequent updates
|
||||
173
src/svgToExcalidraw/transform.ts
Normal file
@@ -0,0 +1,173 @@
|
||||
import Group from "./elements/Group";
|
||||
import { vec3, mat4 } from "gl-matrix";
|
||||
|
||||
/*
|
||||
SVG transform attr is a bit strange in that it can accept traditional
|
||||
css transform string (at least per spec) as well as a it's own "unitless"
|
||||
version of transform functions.
|
||||
|
||||
https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/transform
|
||||
*/
|
||||
|
||||
const transformFunctions = {
|
||||
matrix: "matrix",
|
||||
matrix3d: "matrix3d",
|
||||
perspective: "perspective",
|
||||
rotate: "rotate",
|
||||
rotate3d: "rotate3d",
|
||||
rotateX: "rotateX",
|
||||
rotateY: "rotateY",
|
||||
rotateZ: "rotateZ",
|
||||
scale: "scale",
|
||||
scale3d: "scale3d",
|
||||
scaleX: "scaleX",
|
||||
scaleY: "scaleY",
|
||||
scaleZ: "scaleZ",
|
||||
skew: "skew",
|
||||
skewX: "skewX",
|
||||
skewY: "skewY",
|
||||
translate: "translate",
|
||||
translate3d: "translate3d",
|
||||
translateX: "translateX",
|
||||
translateY: "translateY",
|
||||
translateZ: "translateZ",
|
||||
} as const;
|
||||
|
||||
const transformFunctionsArr = Object.keys(transformFunctions);
|
||||
|
||||
// type Transform
|
||||
|
||||
type TransformFuncValue = {
|
||||
value: string;
|
||||
unit: string;
|
||||
};
|
||||
|
||||
type TransformFunc = {
|
||||
type: keyof typeof transformFunctions;
|
||||
values: TransformFuncValue[];
|
||||
};
|
||||
|
||||
const defaultUnits = {
|
||||
matrix: "",
|
||||
matrix3d: "",
|
||||
perspective: "perspective",
|
||||
rotate: "deg",
|
||||
rotate3d: "deg",
|
||||
rotateX: "deg",
|
||||
rotateY: "deg",
|
||||
rotateZ: "deg",
|
||||
scale: "",
|
||||
scale3d: "",
|
||||
scaleX: "",
|
||||
scaleY: "",
|
||||
scaleZ: "",
|
||||
skew: "skew",
|
||||
skewX: "deg",
|
||||
skewY: "deg",
|
||||
translate: "px",
|
||||
translate3d: "px",
|
||||
translateX: "px",
|
||||
translateY: "px",
|
||||
translateZ: "px",
|
||||
};
|
||||
|
||||
// Convert between possible svg transform attribute values to css transform attribute values.
|
||||
const svgTransformToCSSTransform = (svgTransformStr: string): string => {
|
||||
// Create transform function string "chunks", e.g "rotate(90deg)"
|
||||
const tFuncs = svgTransformStr.match(/(\w+)\(([^)]*)\)/g);
|
||||
if (!tFuncs) {
|
||||
return "";
|
||||
}
|
||||
|
||||
const tFuncValues: TransformFunc[] = tFuncs.map((tFuncStr): TransformFunc => {
|
||||
const type = tFuncStr.split("(")[0] as keyof typeof transformFunctions;
|
||||
if (!type) {
|
||||
throw new Error("Unable to find transform name");
|
||||
}
|
||||
if (!transformFunctionsArr.includes(type)) {
|
||||
throw new Error(`transform function name "${type}" is not valid`);
|
||||
}
|
||||
|
||||
// get the arg/props of the transform function, e.g "90deg".
|
||||
const tFuncParts = tFuncStr.match(/([-+]?[0-9]*\.?[0-9]+)([a-z])*/g);
|
||||
if (!tFuncParts) {
|
||||
return { type, values: [] };
|
||||
}
|
||||
|
||||
let values = tFuncParts.map((a): TransformFuncValue => {
|
||||
// Separate the arg value and unit. e.g ["90", "deg"]
|
||||
const [value, unit] = a.matchAll(/([-+]?[0-9]*\.?[0-9]+)|([a-z])*/g);
|
||||
|
||||
return {
|
||||
unit: unit[0] || defaultUnits[type],
|
||||
value: value[0],
|
||||
};
|
||||
});
|
||||
|
||||
// Not supporting x, y args of svg rotate transform yet...
|
||||
if (values && type === "rotate" && values?.length > 1) {
|
||||
values = [values[0]];
|
||||
}
|
||||
|
||||
return {
|
||||
type,
|
||||
values,
|
||||
};
|
||||
});
|
||||
|
||||
// Generate a string of transform functions that can be set as a CSS Transform.
|
||||
const csstransformStr = tFuncValues
|
||||
.map(({ type, values }) => {
|
||||
const valStr = values
|
||||
.map(({ unit, value }) => `${value}${unit}`)
|
||||
.join(", ");
|
||||
return `${type}(${valStr})`;
|
||||
})
|
||||
.join(" ");
|
||||
|
||||
return csstransformStr;
|
||||
};
|
||||
|
||||
export const createDOMMatrixFromSVGStr = (
|
||||
svgTransformStr: string,
|
||||
): DOMMatrix => {
|
||||
const cssTransformStr = svgTransformToCSSTransform(svgTransformStr);
|
||||
|
||||
return new DOMMatrix(cssTransformStr);
|
||||
};
|
||||
|
||||
export function getElementMatrix(el: Element): mat4 {
|
||||
if (el.hasAttribute("transform")) {
|
||||
const elMat = new DOMMatrix(
|
||||
svgTransformToCSSTransform(el.getAttribute("transform") || ""),
|
||||
);
|
||||
|
||||
return mat4.multiply(mat4.create(), mat4.create(), elMat.toFloat32Array());
|
||||
}
|
||||
|
||||
return mat4.create();
|
||||
}
|
||||
|
||||
export function getTransformMatrix(el: Element, groups: Group[]): mat4 {
|
||||
const accumMat = groups
|
||||
.map(({ element }) => getElementMatrix(element))
|
||||
.concat([getElementMatrix(el)])
|
||||
.reduce((acc, mat) => mat4.multiply(acc, acc, mat), mat4.create());
|
||||
|
||||
return accumMat;
|
||||
}
|
||||
|
||||
export function transformPoints(
|
||||
points: number[][],
|
||||
transform: mat4,
|
||||
): [number, number][] {
|
||||
return points.map(([x, y]) => {
|
||||
const [newX, newY] = vec3.transformMat4(
|
||||
vec3.create(),
|
||||
vec3.fromValues(x, y, 1),
|
||||
transform,
|
||||
);
|
||||
|
||||
return [newX, newY];
|
||||
});
|
||||
}
|
||||
118
src/svgToExcalidraw/types.ts
Normal file
@@ -0,0 +1,118 @@
|
||||
import { ExcalidrawElement, ExcalidrawLinearElement, ExcalidrawTextElement, FillStyle, GroupId, StrokeSharpness, StrokeStyle } from "@zsviczian/excalidraw/types/element/types";
|
||||
|
||||
export type PathCommand = {
|
||||
type: string;
|
||||
parameters: number[];
|
||||
isRelative: boolean;
|
||||
};
|
||||
|
||||
export type RawElement = {
|
||||
type: string;
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
points: number[][];
|
||||
backgroundColor: string;
|
||||
strokeColor: string;
|
||||
};
|
||||
|
||||
export type ElementBoundaries = {
|
||||
x: number;
|
||||
y: number;
|
||||
height: number;
|
||||
width: number;
|
||||
};
|
||||
|
||||
/* from Excalidraw codebase */
|
||||
|
||||
// 1-based in case we ever do `if(element.fontFamily)`
|
||||
export const FONT_FAMILY = {
|
||||
1: "Virgil",
|
||||
2: "Helvetica",
|
||||
3: "Cascadia",
|
||||
} as const;
|
||||
|
||||
export declare type RoughPoint = [number, number];
|
||||
export type Point = Readonly<RoughPoint>;
|
||||
|
||||
export declare type Line = [Point, Point];
|
||||
export interface Rectangle {
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
type _ExcalidrawElementBase = Readonly<{
|
||||
id: string;
|
||||
x: number;
|
||||
y: number;
|
||||
strokeColor: string;
|
||||
backgroundColor: string;
|
||||
fillStyle: FillStyle;
|
||||
strokeWidth: number;
|
||||
strokeStyle: StrokeStyle;
|
||||
strokeSharpness: StrokeSharpness;
|
||||
roughness: number;
|
||||
opacity: number;
|
||||
width: number;
|
||||
height: number;
|
||||
angle: number;
|
||||
/** Random integer used to seed shape generation so that the roughjs shape
|
||||
doesn't differ across renders. */
|
||||
seed: number;
|
||||
/** Integer that is sequentially incremented on each change. Used to reconcile
|
||||
elements during collaboration or when saving to server. */
|
||||
version: number;
|
||||
/** Random integer that is regenerated on each change.
|
||||
Used for deterministic reconciliation of updates during collaboration,
|
||||
in case the versions (see above) are identical. */
|
||||
versionNonce: number;
|
||||
isDeleted: boolean;
|
||||
/** List of groups the element belongs to.
|
||||
Ordered from deepest to shallowest. */
|
||||
groupIds: readonly GroupId[];
|
||||
/** Ids of (linear) elements that are bound to this element. */
|
||||
boundElementIds: readonly ExcalidrawLinearElement["id"][] | null;
|
||||
}>;
|
||||
|
||||
export type ExcalidrawSelectionElement = _ExcalidrawElementBase & {
|
||||
type: "selection";
|
||||
};
|
||||
|
||||
export type ExcalidrawRectangleElement = _ExcalidrawElementBase & {
|
||||
type: "rectangle";
|
||||
};
|
||||
|
||||
export type ExcalidrawDiamondElement = _ExcalidrawElementBase & {
|
||||
type: "diamond";
|
||||
};
|
||||
|
||||
export type ExcalidrawEllipseElement = _ExcalidrawElementBase & {
|
||||
type: "ellipse";
|
||||
};
|
||||
|
||||
/**
|
||||
* These are elements that don't have any additional properties.
|
||||
*/
|
||||
export type ExcalidrawGenericElement =
|
||||
| ExcalidrawSelectionElement
|
||||
| ExcalidrawRectangleElement
|
||||
| ExcalidrawDiamondElement
|
||||
| ExcalidrawEllipseElement;
|
||||
|
||||
/**
|
||||
* ExcalidrawElement should be JSON serializable and (eventually) contain
|
||||
* no computed data. The list of all ExcalidrawElements should be shareable
|
||||
* between peers and contain no state local to the peer.
|
||||
*/
|
||||
export type _ExcalidrawElement =
|
||||
| ExcalidrawGenericElement
|
||||
| ExcalidrawTextElement
|
||||
| ExcalidrawLinearElement;
|
||||
|
||||
export type NonDeleted<TElement extends ExcalidrawElement> = TElement & {
|
||||
isDeleted: false;
|
||||
};
|
||||
|
||||
40
src/svgToExcalidraw/utils.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { Random } from "roughjs/bin/math";
|
||||
import { nanoid } from "nanoid";
|
||||
import { Point } from "./elements/ExcalidrawElement";
|
||||
|
||||
const random = new Random(Date.now());
|
||||
|
||||
export const randomInteger = (): number => Math.floor(random.next() * 2 ** 31);
|
||||
|
||||
export const randomId = (): string => nanoid();
|
||||
|
||||
export const safeNumber = (number: number): number => Number(number.toFixed(2));
|
||||
|
||||
export function dimensionsFromPoints(points: number[][]): number[] {
|
||||
const xCoords = points.map(([x]) => x);
|
||||
const yCoords = points.map(([, y]) => y);
|
||||
|
||||
const minX = Math.min(...xCoords);
|
||||
const minY = Math.min(...yCoords);
|
||||
const maxX = Math.max(...xCoords);
|
||||
const maxY = Math.max(...yCoords);
|
||||
|
||||
return [maxX - minX, maxY - minY];
|
||||
}
|
||||
|
||||
// winding order is clockwise values is positive, counter clockwise if negative.
|
||||
export function getWindingOrder(
|
||||
points: Point[],
|
||||
): "clockwise" | "counterclockwise" {
|
||||
const total = points.reduce((acc, [x1, y1], idx, arr) => {
|
||||
const p2 = arr[idx + 1];
|
||||
const x2 = p2 ? p2[0] : 0;
|
||||
const y2 = p2 ? p2[1] : 0;
|
||||
|
||||
const e = (x2 - x1) * (y2 + y1);
|
||||
|
||||
return e + acc;
|
||||
}, 0);
|
||||
|
||||
return total > 0 ? "clockwise" : "counterclockwise";
|
||||
}
|
||||
463
src/svgToExcalidraw/walker.ts
Normal file
@@ -0,0 +1,463 @@
|
||||
import { mat4 } from "gl-matrix";
|
||||
import { dimensionsFromPoints } from "./utils";
|
||||
import ExcalidrawScene from "./elements/ExcalidrawScene";
|
||||
import Group, { getGroupAttrs } from "./elements/Group";
|
||||
import {
|
||||
ExcalidrawElementBase,
|
||||
ExcalidrawRectangle,
|
||||
ExcalidrawEllipse,
|
||||
ExcalidrawLine,
|
||||
ExcalidrawDraw,
|
||||
createExRect,
|
||||
createExEllipse,
|
||||
createExLine,
|
||||
createExDraw,
|
||||
Point,
|
||||
} from "./elements/ExcalidrawElement";
|
||||
import {
|
||||
presAttrsToElementValues,
|
||||
filterAttrsToElementValues,
|
||||
pointsAttrToPoints,
|
||||
has,
|
||||
get,
|
||||
getNum,
|
||||
} from "./attributes";
|
||||
import { getTransformMatrix, transformPoints } from "./transform";
|
||||
import { pointsOnPath } from "points-on-path";
|
||||
import { randomId, getWindingOrder } from "./utils";
|
||||
|
||||
const SUPPORTED_TAGS = [
|
||||
"svg",
|
||||
"path",
|
||||
"g",
|
||||
"use",
|
||||
"circle",
|
||||
"ellipse",
|
||||
"rect",
|
||||
"polyline",
|
||||
"polygon",
|
||||
];
|
||||
|
||||
const nodeValidator = (node: Element): number => {
|
||||
if (SUPPORTED_TAGS.includes(node.tagName)) {
|
||||
return NodeFilter.FILTER_ACCEPT;
|
||||
}
|
||||
|
||||
return NodeFilter.FILTER_REJECT;
|
||||
};
|
||||
|
||||
export function createTreeWalker(dom: Node): TreeWalker {
|
||||
return document.createTreeWalker(dom, NodeFilter.SHOW_ALL, {
|
||||
acceptNode: nodeValidator,
|
||||
});
|
||||
}
|
||||
|
||||
type WalkerArgs = {
|
||||
root: Document;
|
||||
tw: TreeWalker;
|
||||
scene: ExcalidrawScene;
|
||||
groups: Group[];
|
||||
};
|
||||
|
||||
const presAttrs = (
|
||||
el: Element,
|
||||
groups: Group[],
|
||||
): Partial<ExcalidrawElementBase> => {
|
||||
return {
|
||||
...getGroupAttrs(groups),
|
||||
...presAttrsToElementValues(el),
|
||||
...filterAttrsToElementValues(el),
|
||||
};
|
||||
};
|
||||
|
||||
const skippedUseAttrs = ["id"];
|
||||
const allwaysPassedUseAttrs = [
|
||||
"x",
|
||||
"y",
|
||||
"width",
|
||||
"height",
|
||||
"href",
|
||||
"xlink:href",
|
||||
];
|
||||
|
||||
/*
|
||||
"Most attributes on use do not override those already on the element
|
||||
referenced by use. (This differs from how CSS style attributes override
|
||||
those set 'earlier' in the cascade). Only the attributes x, y, width,
|
||||
height and href on the use element will override those set on the
|
||||
referenced element. However, any other attributes not set on the referenced
|
||||
element will be applied to the use element."
|
||||
|
||||
Situation 1: Attr is set on defEl, NOT on useEl
|
||||
- result: use defEl attr
|
||||
Situation 2: Attr is on useEl, NOT on defEl
|
||||
- result: use the useEl attr
|
||||
Situation 3: Attr is on both useEl and defEl
|
||||
- result: use the defEl attr (Unless x, y, width, height, href, xlink:href)
|
||||
*/
|
||||
const getDefElWithCorrectAttrs = (defEl: Element, useEl: Element): Element => {
|
||||
const finalEl = [...useEl.attributes].reduce((el, attr) => {
|
||||
if (skippedUseAttrs.includes(attr.value)) {
|
||||
return el;
|
||||
}
|
||||
|
||||
// Does defEl have the attr? If so, use it, else use the useEl attr
|
||||
if (
|
||||
!defEl.hasAttribute(attr.name) ||
|
||||
allwaysPassedUseAttrs.includes(attr.name)
|
||||
) {
|
||||
el.setAttribute(attr.name, useEl.getAttribute(attr.name) || "");
|
||||
}
|
||||
return el;
|
||||
}, defEl.cloneNode() as Element);
|
||||
|
||||
return finalEl;
|
||||
};
|
||||
|
||||
const walkers = {
|
||||
svg: (args: WalkerArgs) => {
|
||||
walk(args, args.tw.nextNode());
|
||||
},
|
||||
|
||||
g: (args: WalkerArgs) => {
|
||||
const nextArgs = {
|
||||
...args,
|
||||
tw: createTreeWalker(args.tw.currentNode),
|
||||
groups: [...args.groups, new Group(args.tw.currentNode as Element)],
|
||||
};
|
||||
|
||||
walk(nextArgs, nextArgs.tw.nextNode());
|
||||
|
||||
walk(args, args.tw.nextSibling());
|
||||
},
|
||||
|
||||
use: (args: WalkerArgs) => {
|
||||
const { root, tw, scene } = args;
|
||||
const useEl = tw.currentNode as Element;
|
||||
|
||||
const id = useEl.getAttribute("href") || useEl.getAttribute("xlink:href");
|
||||
|
||||
if (!id) {
|
||||
throw new Error("unable to get id of use element");
|
||||
}
|
||||
|
||||
const defEl = root.querySelector(id);
|
||||
|
||||
if (!defEl) {
|
||||
throw new Error(`unable to find def element with id: ${id}`);
|
||||
}
|
||||
|
||||
const tempScene = new ExcalidrawScene();
|
||||
|
||||
const finalEl = getDefElWithCorrectAttrs(defEl, useEl);
|
||||
|
||||
walk(
|
||||
{
|
||||
...args,
|
||||
scene: tempScene,
|
||||
tw: createTreeWalker(finalEl),
|
||||
},
|
||||
finalEl,
|
||||
);
|
||||
|
||||
const exEl = tempScene.elements.pop();
|
||||
|
||||
if (exEl) {
|
||||
scene.elements.push(exEl);
|
||||
//throw new Error("Unable to create ex element");
|
||||
}
|
||||
|
||||
|
||||
|
||||
walk(args, args.tw.nextNode());
|
||||
},
|
||||
|
||||
circle: (args: WalkerArgs): void => {
|
||||
const { tw, scene, groups } = args;
|
||||
const el = tw.currentNode as Element;
|
||||
|
||||
const r = getNum(el, "r", 0);
|
||||
const d = r * 2;
|
||||
const x = getNum(el, "x", 0) + getNum(el, "cx", 0) - r;
|
||||
const y = getNum(el, "y", 0) + getNum(el, "cy", 0) - r;
|
||||
|
||||
const mat = getTransformMatrix(el, groups);
|
||||
|
||||
// @ts-ignore
|
||||
const m = mat4.fromValues(d, 0, 0, 0, 0, d, 0, 0, 0, 0, 1, 0, x, y, 0, 1);
|
||||
|
||||
const result = mat4.multiply(mat4.create(), mat, m);
|
||||
|
||||
const circle: ExcalidrawEllipse = {
|
||||
...createExEllipse(),
|
||||
...presAttrs(el, groups),
|
||||
x: result[12],
|
||||
y: result[13],
|
||||
width: result[0],
|
||||
height: result[5],
|
||||
groupIds: groups.map((g) => g.id),
|
||||
};
|
||||
|
||||
scene.elements.push(circle);
|
||||
|
||||
walk(args, tw.nextNode());
|
||||
},
|
||||
|
||||
ellipse: (args: WalkerArgs): void => {
|
||||
const { tw, scene, groups } = args;
|
||||
const el = tw.currentNode as Element;
|
||||
|
||||
const rx = getNum(el, "rx", 0);
|
||||
const ry = getNum(el, "ry", 0);
|
||||
const cx = getNum(el, "cx", 0);
|
||||
const cy = getNum(el, "cy", 0);
|
||||
const x = getNum(el, "x", 0) + cx - rx;
|
||||
const y = getNum(el, "y", 0) + cy - ry;
|
||||
const w = rx * 2;
|
||||
const h = ry * 2;
|
||||
|
||||
const mat = getTransformMatrix(el, groups);
|
||||
|
||||
const m = mat4.fromValues(w, 0, 0, 0, 0, h, 0, 0, 0, 0, 1, 0, x, y, 0, 1);
|
||||
|
||||
const result = mat4.multiply(mat4.create(), mat, m);
|
||||
|
||||
const ellipse: ExcalidrawEllipse = {
|
||||
...createExEllipse(),
|
||||
...presAttrs(el, groups),
|
||||
x: result[12],
|
||||
y: result[13],
|
||||
width: result[0],
|
||||
height: result[5],
|
||||
groupIds: groups.map((g) => g.id),
|
||||
};
|
||||
|
||||
scene.elements.push(ellipse);
|
||||
|
||||
walk(args, tw.nextNode());
|
||||
},
|
||||
|
||||
line: (args: WalkerArgs) => {
|
||||
// unimplemented
|
||||
walk(args, args.tw.nextNode());
|
||||
},
|
||||
|
||||
polygon: (args: WalkerArgs) => {
|
||||
const { tw, scene, groups } = args;
|
||||
const el = tw.currentNode as Element;
|
||||
|
||||
const points = pointsAttrToPoints(el);
|
||||
|
||||
const mat = getTransformMatrix(el, groups);
|
||||
|
||||
const transformedPoints = transformPoints(points, mat);
|
||||
|
||||
// The first point needs to be 0, 0, and all following points
|
||||
// are relative to the first point.
|
||||
const x = transformedPoints[0][0];
|
||||
const y = transformedPoints[0][1];
|
||||
|
||||
const relativePoints = transformedPoints.map(([_x, _y]) => [
|
||||
_x - x,
|
||||
_y - y,
|
||||
]);
|
||||
|
||||
const [width, height] = dimensionsFromPoints(relativePoints);
|
||||
|
||||
const line: ExcalidrawLine = {
|
||||
...createExLine(),
|
||||
...getGroupAttrs(groups),
|
||||
...presAttrsToElementValues(el),
|
||||
points: relativePoints.concat([[0, 0]]),
|
||||
x,
|
||||
y,
|
||||
width,
|
||||
height,
|
||||
};
|
||||
|
||||
scene.elements.push(line);
|
||||
|
||||
walk(args, args.tw.nextNode());
|
||||
},
|
||||
|
||||
polyline: (args: WalkerArgs) => {
|
||||
const { tw, scene, groups } = args;
|
||||
const el = tw.currentNode as Element;
|
||||
|
||||
const mat = getTransformMatrix(el, groups);
|
||||
|
||||
const points = pointsAttrToPoints(el);
|
||||
const transformedPoints = transformPoints(points, mat);
|
||||
|
||||
// The first point needs to be 0, 0, and all following points
|
||||
// are relative to the first point.
|
||||
const x = transformedPoints[0][0];
|
||||
const y = transformedPoints[0][1];
|
||||
|
||||
const relativePoints = transformedPoints.map(([_x, _y]) => [
|
||||
_x - x,
|
||||
_y - y,
|
||||
]);
|
||||
|
||||
const [width, height] = dimensionsFromPoints(relativePoints);
|
||||
|
||||
const hasFill = has(el, "fill");
|
||||
const fill = get(el, "fill");
|
||||
|
||||
const shouldFill = !hasFill || (hasFill && fill !== "none");
|
||||
|
||||
const line: ExcalidrawLine = {
|
||||
...createExLine(),
|
||||
...getGroupAttrs(groups),
|
||||
...presAttrsToElementValues(el),
|
||||
points: relativePoints.concat(shouldFill ? [[0, 0]] : []),
|
||||
x,
|
||||
y,
|
||||
width,
|
||||
height,
|
||||
};
|
||||
|
||||
scene.elements.push(line);
|
||||
|
||||
walk(args, args.tw.nextNode());
|
||||
},
|
||||
|
||||
rect: (args: WalkerArgs) => {
|
||||
const { tw, scene, groups } = args;
|
||||
const el = tw.currentNode as Element;
|
||||
|
||||
const x = getNum(el, "x", 0);
|
||||
const y = getNum(el, "y", 0);
|
||||
const w = getNum(el, "width", 0);
|
||||
const h = getNum(el, "height", 0);
|
||||
|
||||
const mat = getTransformMatrix(el, groups);
|
||||
|
||||
// @ts-ignore
|
||||
const m = mat4.fromValues(w, 0, 0, 0, 0, h, 0, 0, 0, 0, 1, 0, x, y, 0, 1);
|
||||
|
||||
const result = mat4.multiply(mat4.create(), mat, m);
|
||||
|
||||
/*
|
||||
NOTE: Currently there doesn't seem to be a way to specify the border
|
||||
radius of a rect within Excalidraw. This means that attributes
|
||||
rx and ry can't be used.
|
||||
*/
|
||||
const isRound = el.hasAttribute("rx") || el.hasAttribute("ry");
|
||||
|
||||
const rect: ExcalidrawRectangle = {
|
||||
...createExRect(),
|
||||
...presAttrs(el, groups),
|
||||
x: result[12],
|
||||
y: result[13],
|
||||
width: result[0],
|
||||
height: result[5],
|
||||
strokeSharpness: isRound ? "round" : "sharp",
|
||||
};
|
||||
|
||||
scene.elements.push(rect);
|
||||
|
||||
walk(args, args.tw.nextNode());
|
||||
},
|
||||
|
||||
path: (args: WalkerArgs) => {
|
||||
const { tw, scene, groups } = args;
|
||||
const el = tw.currentNode as Element;
|
||||
|
||||
const mat = getTransformMatrix(el, groups);
|
||||
|
||||
const points = pointsOnPath(get(el, "d"));
|
||||
|
||||
const fillColor = get(el, "fill", "black");
|
||||
const fillRule = get(el, "fill-rule", "nonzero");
|
||||
|
||||
let elements: ExcalidrawDraw[] = [];
|
||||
let localGroup = randomId();
|
||||
|
||||
switch (fillRule) {
|
||||
case "nonzero":
|
||||
let initialWindingOrder = "clockwise";
|
||||
|
||||
elements = points.map((pointArr, idx): ExcalidrawDraw => {
|
||||
const tPoints: Point[] = transformPoints(pointArr, mat4.clone(mat));
|
||||
const x = tPoints[0][0];
|
||||
const y = tPoints[0][1];
|
||||
|
||||
const [width, height] = dimensionsFromPoints(tPoints);
|
||||
|
||||
const relativePoints = tPoints.map(
|
||||
([_x, _y]): Point => [_x - x, _y - y],
|
||||
);
|
||||
|
||||
const windingOrder = getWindingOrder(relativePoints);
|
||||
if (idx === 0) {
|
||||
initialWindingOrder = windingOrder;
|
||||
localGroup = randomId();
|
||||
}
|
||||
|
||||
let backgroundColor = fillColor;
|
||||
if (initialWindingOrder !== windingOrder) {
|
||||
backgroundColor = "#FFFFFF";
|
||||
}
|
||||
|
||||
return {
|
||||
...createExDraw(),
|
||||
strokeWidth: 0,
|
||||
strokeColor: "#00000000",
|
||||
...presAttrs(el, groups),
|
||||
points: relativePoints,
|
||||
backgroundColor,
|
||||
width,
|
||||
height,
|
||||
x: x + getNum(el, "x", 0),
|
||||
y: y + getNum(el, "y", 0),
|
||||
groupIds: [localGroup],
|
||||
};
|
||||
});
|
||||
break;
|
||||
case "evenodd":
|
||||
elements = points.map((pointArr, idx): ExcalidrawDraw => {
|
||||
const tPoints: Point[] = transformPoints(pointArr, mat4.clone(mat));
|
||||
const x = tPoints[0][0];
|
||||
const y = tPoints[0][1];
|
||||
|
||||
const [width, height] = dimensionsFromPoints(tPoints);
|
||||
|
||||
const relativePoints = tPoints.map(
|
||||
([_x, _y]): Point => [_x - x, _y - y],
|
||||
);
|
||||
|
||||
if (idx === 0) {
|
||||
localGroup = randomId();
|
||||
}
|
||||
|
||||
return {
|
||||
...createExDraw(),
|
||||
...presAttrs(el, groups),
|
||||
points: relativePoints,
|
||||
width,
|
||||
height,
|
||||
x: x + getNum(el, "x", 0),
|
||||
y: y + getNum(el, "y", 0),
|
||||
};
|
||||
});
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
scene.elements = scene.elements.concat(elements);
|
||||
|
||||
walk(args, tw.nextNode());
|
||||
},
|
||||
};
|
||||
|
||||
export function walk(args: WalkerArgs, nextNode: Node | null): void {
|
||||
if (!nextNode) {
|
||||
return;
|
||||
}
|
||||
|
||||
const nodeName = nextNode.nodeName as keyof typeof walkers;
|
||||
if (walkers[nodeName]) {
|
||||
walkers[nodeName](args);
|
||||
}
|
||||
}
|
||||
3
src/types.d.ts
vendored
@@ -1,4 +1,4 @@
|
||||
import { ExcalidrawBindableElement, ExcalidrawElement, FileId, FillStyle, NonDeletedExcalidrawElement, StrokeSharpness, StrokeStyle } from "@zsviczian/excalidraw/types/element/types";
|
||||
import { ExcalidrawBindableElement, ExcalidrawElement, ExcalidrawImageElement, FileId, FillStyle, NonDeletedExcalidrawElement, StrokeSharpness, StrokeStyle } from "@zsviczian/excalidraw/types/element/types";
|
||||
import { Point } from "@zsviczian/excalidraw/types/types";
|
||||
import { TFile, WorkspaceLeaf } from "obsidian";
|
||||
import { EmbeddedFilesLoader } from "./EmbeddedFileLoader";
|
||||
@@ -223,6 +223,7 @@ export interface ExcalidrawAutomateInterface {
|
||||
//verifyMinimumPluginVersion returns true if plugin version is >= than required
|
||||
//recommended use:
|
||||
//if(!ea.verifyMinimumPluginVersion || !ea.verifyMinimumPluginVersion("1.5.20")) {new Notice("message");return;}
|
||||
getOriginalImageSize(imageElement: ExcalidrawImageElement): Promise<{width: number; height: number}>;
|
||||
verifyMinimumPluginVersion(requiredVersion: string): boolean;
|
||||
isExcalidrawView(view: any): boolean;
|
||||
selectElementsInView(elements: ExcalidrawElement[]): void; //sets selection in view
|
||||
|
||||
@@ -42,7 +42,7 @@ export function splitFolderAndFilename(filepath: string): {
|
||||
* @param newExtension - extension of IMG file in ".extension" format
|
||||
* @returns
|
||||
*/
|
||||
export function getIMGPathFromExcalidrawFile(
|
||||
/*export function getIMGPathFromExcalidrawFile(
|
||||
excalidrawPath: string,
|
||||
newExtension: string,
|
||||
): string {
|
||||
@@ -52,6 +52,16 @@ export function getIMGPathFromExcalidrawFile(
|
||||
excalidrawPath.substring(0, excalidrawPath.lastIndexOf(replaceExtension)) +
|
||||
newExtension
|
||||
);
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Generates the image filename based on the excalidraw filename
|
||||
* @param path - path to the excalidraw file
|
||||
* @param extension - extension without the preceeding "."
|
||||
* @returns
|
||||
*/
|
||||
export function getIMGFilename(path: string, extension: string): string {
|
||||
return `${path.substring(0, path.lastIndexOf("."))}.${extension}`;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,6 +145,3 @@ export async function checkAndCreateFolder(folderpath: string) {
|
||||
await vault.createFolder(folderpath);
|
||||
}
|
||||
|
||||
export function getIMGFilename(path: string, extension: string): string {
|
||||
return `${path.substring(0, path.lastIndexOf("."))}.${extension}`;
|
||||
}
|
||||
1294
src/utils/Utils.ts
71
styles.css
@@ -96,8 +96,7 @@ li[data-testid] {
|
||||
|
||||
.ex-coffee-div {
|
||||
text-align: center;
|
||||
margin-bottom: 20px;
|
||||
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.excalidraw-scriptengine-install td>img {
|
||||
@@ -184,9 +183,8 @@ li[data-testid] {
|
||||
}
|
||||
|
||||
.excalidraw-release .modal {
|
||||
max-height: 90%;
|
||||
width: auto;
|
||||
max-width: 130ch;
|
||||
max-height: 80%;
|
||||
max-width: 100ch;
|
||||
}
|
||||
|
||||
.excalidraw .Island .scrollbar {
|
||||
@@ -223,4 +221,67 @@ textarea.excalidraw-wysiwyg {
|
||||
-moz-box-shadow: none;
|
||||
box-shadow: none;
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.is-tablet .excalidraw button,
|
||||
.is-mobile .excalidraw button {
|
||||
padding: initial;
|
||||
height: 1.8rem;
|
||||
}
|
||||
|
||||
.excalidraw button,
|
||||
.ToolIcon button {
|
||||
box-shadow: none;
|
||||
justify-content: initial;
|
||||
}
|
||||
|
||||
.excalidraw {
|
||||
--default-button-size: 2rem !important;
|
||||
--default-icon-size: 1rem !important;
|
||||
--lg-button-size: 1.8rem !important;
|
||||
--lg-icon-size: 1rem !important;
|
||||
}
|
||||
|
||||
.excalidraw .tray-zoom {
|
||||
pointer-events: initial;
|
||||
padding-bottom: 0.05rem;
|
||||
padding-top: 0.05rem;
|
||||
}
|
||||
|
||||
.excalidraw-container.theme--dark {
|
||||
background-color: #121212;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
/* https://discordapp.com/channels/686053708261228577/989603365606531104/1041266507256184863 */
|
||||
/*.workspace-leaf {
|
||||
contain: none !important;
|
||||
}*/
|
||||
|
||||
.color-picker-content {
|
||||
overflow-y: auto;
|
||||
max-height: 10rem;
|
||||
}
|
||||
|
||||
.excalidraw .FixedSideContainer_side_top {
|
||||
top: 0.3rem;
|
||||
}
|
||||
|
||||
.excalidraw .ToolIcon__keybinding {
|
||||
font-size: 0.5rem;
|
||||
}
|
||||
|
||||
.Island > .Stack > .Stack {
|
||||
padding:0.2rem;
|
||||
}
|
||||
|
||||
label.color-input-container > input {
|
||||
max-width: 8rem;
|
||||
}
|
||||
|
||||
.excalidraw .FixedSideContainer_side_top {
|
||||
left: 10px !important;
|
||||
top: 10px !important;
|
||||
right: 10px !important;
|
||||
bottom: 10px !important;
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
"allowJs": true,
|
||||
"noImplicitAny": true,
|
||||
"moduleResolution": "node",
|
||||
"esModuleInterop": true,
|
||||
"importHelpers": true,
|
||||
"lib": [
|
||||
"dom",
|
||||
|
||||
46
yarn.lock
@@ -1676,6 +1676,11 @@
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/chroma-js@^2.1.4":
|
||||
"integrity" "sha512-l9hWzP7cp7yleJUI7P2acmpllTJNYf5uU6wh50JzSIZt3fFHe+w2FM6w9oZGBTYzjjm2qHdnQvI+fF/JF/E5jQ=="
|
||||
"resolved" "https://registry.npmjs.org/@types/chroma-js/-/chroma-js-2.1.4.tgz"
|
||||
"version" "2.1.4"
|
||||
|
||||
"@types/codemirror@0.0.108":
|
||||
"integrity" "sha512-3FGFcus0P7C2UOGCNUVENqObEb4SFk+S8Dnxq7K6aIsLVs/vDtlangl3PEO0ykaKXyK56swVF6Nho7VsA44uhw=="
|
||||
"resolved" "https://registry.npmjs.org/@types/codemirror/-/codemirror-0.0.108.tgz"
|
||||
@@ -2216,10 +2221,10 @@
|
||||
dependencies:
|
||||
"@zerollup/ts-helpers" "^1.7.18"
|
||||
|
||||
"@zsviczian/excalidraw@0.12.0-obsidian-5":
|
||||
"integrity" "sha512-AZQzqlxNbwk+BoKn3R10Xo/V+JoYwJ1mJ9+khUTSsavS7s41xRmA+6k+tKAPa+ce4PSEzZnXg8ZrxTUuNQBxxA=="
|
||||
"resolved" "https://registry.npmjs.org/@zsviczian/excalidraw/-/excalidraw-0.12.0-obsidian-5.tgz"
|
||||
"version" "0.12.0-obsidian-5"
|
||||
"@zsviczian/excalidraw@0.13.0-obsidian-1":
|
||||
"integrity" "sha512-gHfuEX/qrBa+4kolxEkQ/3W5hGfSLoJSXDpuhb8Mvvyyl148hsuWmhUQGFWcNee73YbuQ0arb3hXqwnMUgK0Ig=="
|
||||
"resolved" "https://registry.npmjs.org/@zsviczian/excalidraw/-/excalidraw-0.13.0-obsidian-1.tgz"
|
||||
"version" "0.13.0-obsidian-1"
|
||||
|
||||
"abab@^2.0.3", "abab@^2.0.5":
|
||||
"integrity" "sha512-9IK9EadsbHo6jLWIpxpR6pL0sazTXV6+SQv25ZB+F7Bj9mJNaOc4nCRabwd5M/JwmUa8idz6Eci6eKfJryPs6Q=="
|
||||
@@ -2964,6 +2969,11 @@
|
||||
optionalDependencies:
|
||||
"fsevents" "~2.3.2"
|
||||
|
||||
"chroma-js@^2.4.2":
|
||||
"integrity" "sha512-U9eDw6+wt7V8z5NncY2jJfZa+hUH8XEj8FQHgFJTrUFnJfXYf4Ml4adI2vXZOjqRDpFWtYVWypDfZwnJ+HIR4A=="
|
||||
"resolved" "https://registry.npmjs.org/chroma-js/-/chroma-js-2.4.2.tgz"
|
||||
"version" "2.4.2"
|
||||
|
||||
"chrome-trace-event@^1.0.2":
|
||||
"integrity" "sha512-p3KULyQg4S7NIHixdwbGX+nFHkoBiA4YQmyWtjb8XngSKV124nJmRysgAeujbUVb15vh+RvFUfCPqU7rXk+hZg=="
|
||||
"resolved" "https://registry.npmjs.org/chrome-trace-event/-/chrome-trace-event-1.0.3.tgz"
|
||||
@@ -3063,6 +3073,11 @@
|
||||
"resolved" "https://registry.npmjs.org/colorette/-/colorette-2.0.16.tgz"
|
||||
"version" "2.0.16"
|
||||
|
||||
"colormaster@1.2.1":
|
||||
"integrity" "sha512-+G9g1fOW+TC4+y5IWYI4f7mb+l+oEto/N3qJTFrJNaayFpidZUWhZJGxoSJjhNMIiTttcU1kf4XSyfxHyHkQYw=="
|
||||
"resolved" "https://registry.npmjs.org/colormaster/-/colormaster-1.2.1.tgz"
|
||||
"version" "1.2.1"
|
||||
|
||||
"combined-stream@^1.0.8":
|
||||
"integrity" "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg=="
|
||||
"resolved" "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz"
|
||||
@@ -4623,6 +4638,11 @@
|
||||
"call-bind" "^1.0.2"
|
||||
"get-intrinsic" "^1.1.1"
|
||||
|
||||
"gl-matrix@^3.4.3":
|
||||
"integrity" "sha512-wcCp8vu8FT22BnvKVPjXa/ICBWRq/zjFfdofZy1WSpQZpphblv12/bOQLBC1rMM7SGOFS9ltVmKOHil5+Ml7gA=="
|
||||
"resolved" "https://registry.npmjs.org/gl-matrix/-/gl-matrix-3.4.3.tgz"
|
||||
"version" "3.4.3"
|
||||
|
||||
"glob-parent@^5.1.2", "glob-parent@~5.1.2":
|
||||
"integrity" "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow=="
|
||||
"resolved" "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz"
|
||||
@@ -6201,10 +6221,10 @@
|
||||
dependencies:
|
||||
"minimist" "^1.2.5"
|
||||
|
||||
"moment@2.29.3":
|
||||
"integrity" "sha512-c6YRvhEo//6T2Jz/vVtYzqBzwvPT95JBQ+smCytzf7c50oMZRsR/a4w88aD34I+/QVSfnoAnSBFPJHItlOMJVw=="
|
||||
"resolved" "https://registry.npmjs.org/moment/-/moment-2.29.3.tgz"
|
||||
"version" "2.29.3"
|
||||
"moment@2.29.4":
|
||||
"integrity" "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w=="
|
||||
"resolved" "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz"
|
||||
"version" "2.29.4"
|
||||
|
||||
"monkey-around@^2.3.0":
|
||||
"integrity" "sha512-QWcCUWjqE/MCk9cXlSKZ1Qc486LD439xw/Ak8Nt6l2PuL9+yrc9TJakt7OHDuOqPRYY4nTWBAEFKn32PE/SfXA=="
|
||||
@@ -6415,13 +6435,13 @@
|
||||
"define-properties" "^1.1.3"
|
||||
"es-abstract" "^1.19.1"
|
||||
|
||||
"obsidian@^0.15.4":
|
||||
"integrity" "sha512-FE11CxxpVD6t/DBvjLvlT7q7YYW91ubTqPKIIp286LdnyLipS8Xi3Tif8i8ALPv87Vg9obKM43aWcPsYLxLllQ=="
|
||||
"resolved" "https://registry.npmjs.org/obsidian/-/obsidian-0.15.4.tgz"
|
||||
"version" "0.15.4"
|
||||
"obsidian@^0.16.3":
|
||||
"integrity" "sha512-hal9qk1A0GMhHSeLr2/+o3OpLmImiP+Y+sx2ewP13ds76KXsziG96n+IPFT0mSkup1zSwhEu+DeRhmbcyCCXWw=="
|
||||
"resolved" "https://registry.npmjs.org/obsidian/-/obsidian-0.16.3.tgz"
|
||||
"version" "0.16.3"
|
||||
dependencies:
|
||||
"@types/codemirror" "0.0.108"
|
||||
"moment" "2.29.3"
|
||||
"moment" "2.29.4"
|
||||
|
||||
"obuf@^1.0.0", "obuf@^1.1.2":
|
||||
"integrity" "sha512-PX1wu0AmAdPqOL1mWhqmlOd8kOIZQwGZw6rh7uby9fTc5lhaOWFLX3I6R1hrF9k3zUY40e6igsLGkDXK92LJNg=="
|
||||
|
||||