mirror of
https://github.com/zsviczian/obsidian-excalidraw-plugin.git
synced 2025-08-06 05:46:28 +00:00
Compare commits
26 Commits
1.9.19-mer
...
1.9.23
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eaf3b7f7d7 | ||
|
|
03edbaf545 | ||
|
|
c3edf23023 | ||
|
|
5f765609f9 | ||
|
|
3c1beac822 | ||
|
|
f30f66969c | ||
|
|
4e6fb48bf0 | ||
|
|
53225ba5a7 | ||
|
|
c04967d775 | ||
|
|
6bb7a3c0e5 | ||
|
|
2c85191671 | ||
|
|
637235eb9d | ||
|
|
13e4203c44 | ||
|
|
d04b628d55 | ||
|
|
2eab13661d | ||
|
|
6eefb49eb0 | ||
|
|
6878b1f969 | ||
|
|
0ba784564f | ||
|
|
62804cdc63 | ||
|
|
ff900b4b61 | ||
|
|
e34f03c0d1 | ||
|
|
2a9cf1cf6b | ||
|
|
d4159dbe75 | ||
|
|
7cd68304c3 | ||
|
|
0d7a76310c | ||
|
|
7b178ce2c8 |
270
README.md
270
README.md
@@ -62,51 +62,46 @@ The Obsidian-Excalidraw plugin integrates [Excalidraw](https://excalidraw.com/),
|
||||
|
||||
## Features
|
||||
|
||||
- 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.
|
||||
- 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
|
||||
|
||||
Settings will allow you to customize Excalidraw to your needs. The plugin comes with tons of settings. I tried adding meaningful explanations to these settings, so please be patient and look for the setting, for most requests a setting already exists.
|
||||
Settings will allow you to customize Excalidraw to your needs. The plugin comes with tons of settings. I tried adding meaningful explanations to these settings, so please be patient and look for the setting, for most requests, a setting already exists.
|
||||
|
||||
Plugin settings are grouped into the following sections:
|
||||
- **Basic settings**: such as default folders to use
|
||||
- **Saving**: compression and autosave timer
|
||||
- **Filename**: configure the automatically created Excalidraw filename
|
||||
- **Display**: settings that effect the handling of Excalidraw (e.g.: left-handed mode, theme settings, mouse wheel and pinch zoom settings, zoom to fit settings)
|
||||
- **Links and transclusions**: Settings that effect how links and embedded items behave on the Excalidraw canvas
|
||||
- **Markdown-embed settings**: These settings control how markdown documents from your Vault embedded into Excalidraw drawings will behave
|
||||
- **Embed & Export**: Settings that control how Excalidraw images are displayed when embedding them into markdown documents
|
||||
- **Auto-export Settings**: You can configure Excalidraw to create a PNG or SVG copy of your drawing each time it gets saved
|
||||
- **Compatibility features**: Check these settings if you edit the Excalidraw drawings outside Obsidian (e.g. in LogSeq, Visual Studio, on the web, etc.)
|
||||
- **Basic settings**: such as default folders to use.
|
||||
- **Saving**: compression and autosave timer.
|
||||
- **Filename**: configure the automatically created Excalidraw filename.
|
||||
- **Display**: settings that effect the handling of Excalidraw (e.g.: left-handed mode, theme settings, mouse wheel and pinch zoom settings, zoom to fit settings).
|
||||
- **Links and transclusions**: Settings that effect how links and embedded items behave on the Excalidraw canvas.
|
||||
- **Markdown-embed settings**: These settings control how markdown documents from your Vault embedded into Excalidraw drawings will behave.
|
||||
- **Embed & Export**: Settings that control how Excalidraw images are displayed when embedding them into markdown documents.
|
||||
- **Auto-export Settings**: You can configure Excalidraw to create a PNG or SVG copy of your drawing each time it gets saved.
|
||||
- **Compatibility features**: Check these settings if you edit the Excalidraw drawings outside Obsidian (e.g. in LogSeq, Visual Studio, on the web, etc.).
|
||||
- **Experimental features**: There are advanced features that are implemented as "clever" hacks. Features include defining a fourth font, adding a custom icon to distinguish Exalidraw files in the Obsidian file explorer, OCR settings, and more.
|
||||
- **Settings for installed Scripts**: Some of the scripts you install from the Script Library come with settings. Script settings are installed the first time you run the script. So to access settings for a script, install the script, run it for the first time, then look for the settings in plugin settings.
|
||||
- **Settings for installed Scripts**: Some of the scripts you install from the Script Library come with settings. Script settings are installed the first time you run the script. So to access settings for a script, install the script, run it for the first time and then look for the settings in plugin settings.
|
||||
|
||||
#### Templates
|
||||
|
||||
- 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.
|
||||
- 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.
|
||||
|
||||
#### Export
|
||||
|
||||
- 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`.
|
||||
- Auto-export SVG and/or PNG files, including the 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.
|
||||
@@ -114,137 +109,144 @@ Plugin settings are grouped into the following sections:
|
||||
- Enable / disable autosave.
|
||||
|
||||
### Embedding your drawings into markdown documents
|
||||
|
||||
- You can customize the size and position of the embedded images using the
|
||||
- `![[image.excalidraw|100]]`,
|
||||
- `![[image.excalidraw|100x100]]`,
|
||||
- `![[image.excalidraw|100|left]]`,
|
||||
- `![[image.excalidraw|right-wrap]]`, formatting options.
|
||||
- `![[<filename.excalidraw>|<width>x<height>|<alignment>]]`.
|
||||
- You can add your custom [alignment via CSS](https://www.scaler.com/topics/align-image-in-html/).
|
||||
- Any text that appears in `<alignment>` will be added to the rendered SVG element style and to the wrapper DIV element.
|
||||
- See [styles.css](https://github.com/zsviczian/obsidian-excalidraw-plugin/blob/master/styles.css) for more insight.
|
||||
- `![[image.excalidraw|100]]`,
|
||||
- `![[image.excalidraw|100x100]]`,
|
||||
- `![[image.excalidraw|100|left]]`,
|
||||
- `![[image.excalidraw|right-wrap]]`, formatting options.
|
||||
- `![[<filename.excalidraw>|<width>x<height>|<alignment>]]`.
|
||||
- You can add your custom [alignment via CSS](https://www.scaler.com/topics/align-image-in-html/).
|
||||
- Any text that appears in `<alignment>` will be added to the rendered SVG element style and to the wrapper DIV element.
|
||||
- See [styles.css](https://github.com/zsviczian/obsidian-excalidraw-plugin/blob/master/styles.css) for more insight.
|
||||
- Excalidraw drawings do not display in Obsidian Publish. If you want to use Excalidraw in your published documents, you can configure in plugin settings, under `Embed & Export`, to automatically insert a PNG or SVG version of the drawing in your document when creating a new file. See `type of file to insert into document`
|
||||
- Under `Export settings` you can also configure to automatically export a dark and light version of the image, in case your published site supports dark and light mode.
|
||||
- Under `Export settings`, you can also configure to automatically export a dark and light version of the image, in case your published site supports dark and light modes.
|
||||
|
||||
### Hyperlinks and Drag & Drop support
|
||||
|
||||

|
||||
|
||||
#### Hyperlinks
|
||||
- Supports hyperlinks e.g.
|
||||
- `https://zsolt.blog`,
|
||||
- `[Obsidian](https://obsidian.md)`, and
|
||||
- internal links e.g. `[[My file in vault|Alias]]` in drawing text.
|
||||
- Links will update when files are moved or renamed, if you have the Obsidian
|
||||
setting Files & Links/Automatically Update Internal Links enabled.
|
||||
- Links in drawings will show up in backlinks of documents
|
||||
- Transclusions are supported
|
||||
- `![[myfile#^blockref]]` will convert in the drawing into the transcluded text of the block
|
||||
- `![[myfile#section]]` also works, this will transclude the section
|
||||
- you can also specify word wrapping for transcluded text by adding the max character count
|
||||
in curly brackets right after the transclusion e.g. `![[myfile#^blockref]]{40}` will wrap text at 40 characters.
|
||||
- For convenience you can also use the command palette to insert links into drawings
|
||||
- <kbd>CTRL/CMD + hover</kbd> to bring up the Obsidian quick preview for the link. (On Mac it is <kbd>CTRL+CMD+hover</kbd>).
|
||||
- Using the block reference you can also reference & transclude text that appears on drawings, in other documents
|
||||
|
||||
- Supports hyperlinks, e.g.
|
||||
- `https://zsolt.blog`,
|
||||
- `[Obsidian](https://obsidian.md)`, and
|
||||
- Internal links, e.g. `[[My file in vault|Alias]]` in drawing text.
|
||||
- Links will update when files are moved or renamed, if you have the Obsidian setting Files & Links/Automatically Update Internal Links enabled.
|
||||
- Links in drawings will show up in the backlinks of documents.
|
||||
- Transclusions are supported:
|
||||
- `![[myfile#^blockref]]` will convert the drawing into the transcluded text of the block
|
||||
- `![[myfile#section]]` also works, this will transclude the section.
|
||||
- You can also specify word wrapping for transcluded text by adding the max character count:
|
||||
in curly brackets right after the transclusion e.g. `![[myfile#^blockref]]{40}` will wrap text at 40 characters.
|
||||
- For convenience, you can also use the command palette to insert links into drawings.
|
||||
- <kbd>CTRL/CMD + hover</kbd> to bring up the Obsidian quick preview for the link. (On Mac, it is <kbd>CTRL+CMD+hover</kbd>).
|
||||
- Using the block reference, you can also reference & transclude text that appears on drawings, in other documents.
|
||||
|
||||
#### Drag & Drop support
|
||||
- You can drag files from the Obsidian file explorer and they will become links to those files in Excalidraw. See table above for the varios modifier key combinations.
|
||||
- Note: anchoring an image to 100% of its size 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 files from the Obsidian file explorer, and they will become links to those files in Excalidraw. See the table above for the various modifier key combinations.
|
||||
- Note: Anchoring an image to 100% of its size 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.
|
||||
- You can drag and drop YouTube links and thumbnails and they will be YouTube links with thumbnails in Excalidraw
|
||||
- You can drag and drop web addresses from your browser, and they will become links.
|
||||
- You can drag and drop YouTube links and thumbnails, and they will be YouTube links with thumbnails in Excalidraw.
|
||||
|
||||
### LaTeX
|
||||
|
||||
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.
|
||||
You can edit formulas either in Markdown view or by <kbd>CTRL/CMD + Click</kbd> on the formula.
|
||||
|
||||
### Image support
|
||||
- On iOS and Android you can add images from your camera by pressing the add image button in Excalidraw.
|
||||
|
||||
- On iOS and Android, you can add images from your camera by pressing the add image button in Excalidraw.
|
||||
- You can copy/paste images into your drawing. Images will be saved in your vault.
|
||||
- You can drag and drop images as explained above.
|
||||
- URL link to images on the web: You can drag images from a webpage to Excalidraw. If you hold down the CTRL button while dropping the image to Excalidraw, the image will not be saved to your vault. Excalidraw will load the image from the URL. Note, that if you do not have internet access, or these images are deleted from the internet, they will also disappear from your drawing.
|
||||
- If you page an image URL to excalidraw (simply click copy on the url, then click paste on the excalidraw canvas), the image will be inserted with a link to the image on the web. Again, the image won't be save to your vault, only the link.
|
||||
- If you drop a YouTube video link it will be convereted into a thumbnail photo with an element link pointing to the video.
|
||||
- URL link to images on the web: You can drag images from a webpage to Excalidraw. If you hold down the CTRL button while dropping the image to Excalidraw, the image will not be saved to your vault. Excalidraw will load the image from the URL. Note that if you do not have internet access or if these images are deleted from the internet, they will also disappear from your drawing.
|
||||
- If you page an image URL to excalidraw (simply click copy on the url, then click paste on the excalidraw canvas), the image will be inserted with a link to the image on the web. Again, the image won't be saved to your vault, only the link.
|
||||
- If you drop a YouTube video link, it will be converted into a thumbnail photo with an element link pointing to the video.
|
||||
|
||||
### Block referencing parts of images
|
||||
For more details see this [video](https://youtu.be/yZQoJg2RCKI)
|
||||
|
||||
For more details, see this [video](https://youtu.be/yZQoJg2RCKI)
|
||||
- When referencing an element on the canvas in a link pointing to an Excalidraw file using
|
||||
- the elementId or the section header (i.e. a Text Element containing the `# <Section title>`)
|
||||
- e.g. `[[file#^elementID]]`,
|
||||
- you can add the `group=` prefix,
|
||||
- e.g. `[[file#^group=elementID]]` or
|
||||
- the `area=` prefix,
|
||||
- e.g. `[[file#area=Section heading]]`.
|
||||
- If the `group=` prefix is found Excalidraw will select the group of elements in the
|
||||
same group as the element referenced by the elementID (block reference) or the section heading.
|
||||
- If the `area=` prefix is found Excalidraw will insert a cutout of the image around the referenced element.
|
||||
- Note that the `area=` selector is not supported when embedding Excalidraw as PNG into your markdown documents.
|
||||
- Referencing the elementID of a text element without the `group=` or `area=` prefix will
|
||||
transclude the element as plain text. Referencing a non-Text Element (e.g. rectangle,
|
||||
ellipse, etc.) without the `group=` or `area=` prefix will result in an Obsidian error
|
||||
since these elementIds are not present in the Excalidraw markdown file as block
|
||||
references.
|
||||
- The elementId or the section header (i.e. a Text Element containing the `# <Section title>`)
|
||||
- e.g. `[[file#^elementID]]`,
|
||||
- You can add the `group=` prefix,
|
||||
- e.g. `[[file#^group=elementID]]` or
|
||||
- The `area=` prefix,
|
||||
- e.g. `[[file#area=Section heading]]`.
|
||||
- If the `group=` prefix is found, Excalidraw will select the group of elements in the
|
||||
same group as the element referenced by the elementID (block reference) or the section heading.
|
||||
- If the `area=` prefix is found, Excalidraw will insert a cutout of the image around the referenced element.
|
||||
- Note that the `area=` selector is not supported when embedding Excalidraw as a PNG into your markdown documents.
|
||||
- Referencing the elementID of a text element without the `group=` or `area=` prefix will
|
||||
transclude the element as plain text. Referencing a non-Text Element (e.g. rectangle,
|
||||
ellipse, etc.) without the `group=` or `area=` prefix will result in an Obsidian error.
|
||||
since these elementIds are not present in the Excalidraw markdown file as block
|
||||
references.
|
||||
|
||||
### Markdown
|
||||
- Since 1.2.0 Drawing files are stored in Markdown files
|
||||
- You can add tags to drawings
|
||||
- You can add metadata to the YAML front matter of drawings
|
||||
- Anything you add between the frontmatter and the `# Text Elements` heading will be ignored by Excalidraw, i.e. you can add whatever you like here, it will be preserved as part of the document.
|
||||
- Excalidraw documents now show in graph view.
|
||||
- The following front matter keys will customize how the drawing is displayed - overriding general settings:
|
||||
- `excalidraw-link-prefix: "📍"` preview prefix for internal links
|
||||
- `excalidraw-url-prefix: "🌐"` preview prefix for external links
|
||||
- `excalidraw-link-brackets: true|false` whether or not to display brackets around links in preview
|
||||
- `excalidraw-default-mode: view|zen` Open this document in view mode or zen mode by defult. Default view mode is excellent for presentation slides.
|
||||
- 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-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.
|
||||
|
||||
- Since 1.2.0, drawing files are stored in Markdown files.
|
||||
- You can add tags to drawings.
|
||||
- You can add metadata to the YAML front matter of drawings.
|
||||
- Anything you add between the frontmatter and the `# Text Elements` heading will be ignored by Excalidraw, i.e. you can add whatever you like here, and it will be preserved as part of the document.
|
||||
- Excalidraw documents now show up in graph view.
|
||||
- The following front matter keys will customize how the drawing is displayed - overriding general settings:
|
||||
- `excalidraw-link-prefix: "📍"` preview prefix for internal links
|
||||
- `excalidraw-url-prefix: "🌐"` preview prefix for external links
|
||||
- `excalidraw-link-brackets: true|false` whether or not to display brackets around links in preview
|
||||
- `excalidraw-default-mode: view|zen` Open this document in view mode or zen mode by defult. The default view mode is excellent for presentation slides.
|
||||
- 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-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>SHIFT</kbd> while dropping the file onto the canvas.
|
||||
|
||||
Drag the desired file from the Obsidian file explorer and hold down <kbd>SHIFT</kbd> while dropping the file onto the canvas.
|
||||
- Use the command palette action: `Insert markdown file from vault`
|
||||
- Use custom woff, woff2 or TTF font to display the document, you can set the default font to use under Excalidraw Settings.
|
||||
- You can set a custom css for rendering the snapshot image of your markdown document.
|
||||
Only operating system standard fonts are supported as the font-family (
|
||||
[Win10](https://docs.microsoft.com/en-us/typography/fonts/windows_10_font_list),
|
||||
[Mac & iOS](https://developer.apple.com/fonts/system-fonts/)
|
||||
), plus you can set one additional custom font using the setting explained above.
|
||||
- (for a demonstration watch this [video](https://youtu.be/K6qZkTz8GHs) and check out this
|
||||
- [sample css](https://github.com/zsviczian/obsidian-excalidraw-plugin/discussions/281)).
|
||||
- To help with styling you can observe the SVG snapshot of the markdown document created by Excalidraw.
|
||||
- Open Obsidian Developer Console (<kbd>CTRL+Shift+i</kbd>/<kbd>CMD+OPT+i</kbd>) and
|
||||
- execute the following command: `ExcalidrawAutomate.mostRecentMarkdownSVG`
|
||||
- You can control appearance of the embedded markdown file on a file by file
|
||||
bases by adding the following front matter keys to your markdown document:
|
||||
- `excalidraw-font: Virgil|Cascadia|font_file_name.extension`
|
||||
- `excalidraw-font-color: css-color-name|#HEXcolor|any-other-html-standard-format`,
|
||||
- you can find css color names [here](https://www.w3schools.com/colors/colors_names.asp).
|
||||
- `excalidraw-border-color: css-color-name|#HEXcolor|any-other-html-standard-format`
|
||||
- `excalidraw-css: "css-filename|css snippet"`
|
||||
- Switch to markdown view or use <kbd>WIN+CTRL</kbd>/<kbd>CMD+CTRL</kbd> click on the image to edit properties of the embed:
|
||||
- `[[filename#^blockref|WIDTHxMAXHEIGHT]]`
|
||||
- Use custom woff, woff2, or TTF font to display the document, you can set the default font to use under Excalidraw Settings.
|
||||
- You can set a custom CSS for rendering the snapshot image of your markdown document. Only operating system-standard fonts are supported as the font-family ([Win10](https://docs.microsoft.com/en-us/typography/fonts/windows_10_font_list), [Mac & iOS](https://developer.apple.com/fonts/system-fonts/)), plus you can set one additional custom font using the setting explained above.
|
||||
- (for a demonstration, watch this [video](https://youtu.be/K6qZkTz8GHs) and check out this
|
||||
- [sample css](https://github.com/zsviczian/obsidian-excalidraw-plugin/discussions/281)).
|
||||
- To help with styling, you can observe the SVG snapshot of the markdown document created by Excalidraw.
|
||||
- Open Obsidian Developer Console (<kbd>CTRL+Shift+i</kbd>/<kbd>CMD+OPT+i</kbd>) and
|
||||
- Execute the following command: `ExcalidrawAutomate.mostRecentMarkdownSVG`
|
||||
- You can control the appearance of the embedded markdown file on a file by file
|
||||
bases by adding the following front matter keys to your markdown document:
|
||||
- `excalidraw-font: Virgil|Cascadia|font_file_name.extension`
|
||||
- `excalidraw-font-color: css-color-name|#HEXcolor|any-other-html-standard-format`,
|
||||
- You can find css color names [here](https://www.w3schools.com/colors/colors_names.asp).
|
||||
- `excalidraw-border-color: css-color-name|#HEXcolor|any-other-html-standard-format`
|
||||
- `excalidraw-css: "css-filename|css snippet"`
|
||||
- Switch to markdown view or use <kbd>WIN+CTRL</kbd>/<kbd>CMD+CTRL</kbd> click on the image to edit the properties of the embed:
|
||||
- `[[filename#^blockref|WIDTHxMAXHEIGHT]]`
|
||||
|
||||
### Custom Font, Custom Pen, OCR support, SVG import
|
||||
- In plugin settings you can add a custom 4th font. For more details see this [video](https://youtu.be/eKFmrSQhFA4)
|
||||
- The plugin includes OCR support using Taskbone OCR. For more details see this [video](https://youtu.be/7gu4ETx7zro)
|
||||
- You can convert SVG files into Excalidraw drawings (with some limitation). For more details see this [video](https://youtu.be/vlC1-iBvIfo)
|
||||
- You can define custom freedraw pens. See documentation [here](https://github.com/zsviczian/obsidian-excalidraw-plugin/blob/master/ea-scripts/Alternative%20Pens.md), [video](https://youtu.be/uZz5MgzWXiM)
|
||||
|
||||
- In plugin settings, you can add a custom fourth font. For more details, see this [video](https://youtu.be/eKFmrSQhFA4)
|
||||
- The plugin includes OCR support using Taskbone OCR. For more details, see this [video](https://youtu.be/7gu4ETx7zro)
|
||||
- You can convert SVG files into Excalidraw drawings (with some limitation). For more details, see this [video](https://youtu.be/vlC1-iBvIfo)
|
||||
- You can define custom freedraw pens. See documentation [here].(https://github.com/zsviczian/obsidian-excalidraw-plugin/blob/master/ea-scripts/Alternative%20Pens.md), [video](https://youtu.be/uZz5MgzWXiM)
|
||||
|
||||
### Script Engine
|
||||
- Since 1.5.0 you can easily execute ExcalidrawAutomate macros and assign command palette shortcuts to them, using the ScriptEngine. You will find an intro video and a growing library of ready to install scripts [here](https://github.com/zsviczian/obsidian-excalidraw-plugin/tree/master/ea-scripts).
|
||||
- You can organize scripts into groups on the Obsidian Tools Panel in Excalidraw by moving scripts and accompanying SVG icon files to folders. See demo [video](https://youtu.be/wTtaXmRJ7wg?t=16).
|
||||
|
||||
- Since 1.5.0, you can easily execute ExcalidrawAutomate macros and assign command palette shortcuts to them, using the ScriptEngine. You will find an intro video and a growing library of ready to install scripts [here](https://github.com/zsviczian/obsidian-excalidraw-plugin/tree/master/ea-scripts).
|
||||
- You can organize scripts into groups on the Obsidian Tools Panel in Excalidraw by moving scripts and accompanying SVG icon files to folders. See the demo [video](https://youtu.be/wTtaXmRJ7wg?t=16).
|
||||
|
||||
### Other
|
||||
|
||||
- Left-handed mode
|
||||
- Includes full
|
||||
- [QuickAdd](https://github.com/chhoumann/quickadd),
|
||||
@@ -269,7 +271,7 @@ report a bug or request an enhancement.
|
||||
|
||||
## Say Thank You
|
||||
|
||||
If you are enjoying Excalidraw then please support my work and enthusiasm by buying me a coffee on
|
||||
If you are enjoying Excalidraw, then please support my work and enthusiasm by buying me a coffee on
|
||||
[https://ko-fi/zsolt](https://ko-fi.com/zsolt).
|
||||
|
||||
Please also help spread the word by sharing about the Obsidian Excalidraw Plugin on Twitter, Reddit,
|
||||
@@ -284,4 +286,4 @@ You can find me on Twitter [@zsviczian](https://twitter.com/zsviczian), and on m
|
||||
## Friends of Excalidraw
|
||||
If you enjoy Excalidraw, consider giving [ExcaliBrain](https://github.com/zsviczian/excalibrain) a try (also available via Obsidian Community Plugins).
|
||||
|
||||
<a href="https://youtu.be/gOkniMkDPyM" target="_blank"><img src="https://user-images.githubusercontent.com/14358394/169708346-9e41289d-9536-43ec-8f70-2d2ad2d369d6.png" width="300"/></a>
|
||||
<a href="https://youtu.be/gOkniMkDPyM" target="_blank"><img src="https://user-images.githubusercontent.com/14358394/169708346-9e41289d-9536-43ec-8f70-2d2ad2d369d6.png" width="300"/></a>
|
||||
|
||||
@@ -21,7 +21,7 @@ The second line resets ExcalidrawAutomate to defaults. This is important as you
|
||||
|
||||
You can change the styling between adding different elements. My logic for separating element styling and creation is based on the assumption that you will probably set a stroke color, stroke style, stroke roughness, etc. and draw most of your elements using that. There would be no point in setting all these parameters each time you add an element.
|
||||
|
||||
### Before we dive deeper, here are three a simple example [Templater](https://github.com/SilentVoid13/Templater) scripts
|
||||
### Before we dive deeper, here are three simple example [Templater](https://github.com/SilentVoid13/Templater) scripts
|
||||
#### Create a new drawing with custom name, in a custom folder, using a template
|
||||
This simple script gives you significant additional flexibility over Excalidraw Plugin settings to name your drawings, place them into folders, and to apply templates.
|
||||
|
||||
|
||||
369
ea-scripts/Boolean Operations.md
Normal file
369
ea-scripts/Boolean Operations.md
Normal file
@@ -0,0 +1,369 @@
|
||||
/*
|
||||
With This Script it is possible to make boolean Operations on Shapes.
|
||||
The style of the resulting shape will be the style of the highest ranking Element that was used.
|
||||
The ranking of the elemtns is based on their background. The "denser" the background, the higher the ranking (the order of backgroundstyles is shown below). If they have the same background the opacity will decide. If thats also the same its decided by the order they were created.
|
||||
The ranking is also important for the diffrence operation, so a tranparent object for example will cut a hole into a solid object.
|
||||

|
||||

|
||||
|
||||
|
||||
See documentation for more details:
|
||||
https://zsviczian.github.io/obsidian-excalidraw-plugin/ExcalidrawScriptsEngine.html
|
||||
|
||||
```javascript
|
||||
*/
|
||||
if(!ea.verifyMinimumPluginVersion || !ea.verifyMinimumPluginVersion("1.9.20")) {
|
||||
new Notice("This script requires a newer version of Excalidraw. Please install the latest version.");
|
||||
return;
|
||||
}
|
||||
const ShadowGroupMarker = "ShadowCloneOf-";
|
||||
|
||||
const elements = ea.getViewSelectedElements().filter(
|
||||
el=>["ellipse", "rectangle", "diamond"].includes(el.type) ||
|
||||
el.groupIds.some(id => id.startsWith(ShadowGroupMarker)) ||
|
||||
(["line", "arrow"].includes(el.type) && el.roundness === null)
|
||||
);
|
||||
if(elements.length === 0) {
|
||||
new Notice ("Select ellipses, rectangles or diamonds");
|
||||
return;
|
||||
}
|
||||
|
||||
const PolyBool = ea.getPolyBool();
|
||||
const polyboolAction = await utils.suggester(["union (a + b)", "intersect (a && b)", "diffrence (a - b)", "reversed diffrence (b - a)", "xor"], [
|
||||
PolyBool.union, PolyBool.intersect, PolyBool.difference, PolyBool.differenceRev, PolyBool.xor
|
||||
], "What would you like todo with the object");
|
||||
|
||||
const shadowClones = elements.filter(element => element.groupIds.some(id => id.startsWith(ShadowGroupMarker)));
|
||||
shadowClones.forEach(shadowClone => {
|
||||
let parentId = shadowClone.groupIds
|
||||
.filter(id => id.startsWith(ShadowGroupMarker))[0]
|
||||
.slice(ShadowGroupMarker.length);
|
||||
const shadowCloneIndex = elements.findIndex(element => element.id == parentId);
|
||||
if (shadowCloneIndex == -1) return;
|
||||
elements[shadowCloneIndex].backgroundColor = shadowClone.backgroundColor;
|
||||
elements[shadowCloneIndex].fillStyle = shadowClone.fillStyle;
|
||||
})
|
||||
const borderElements = elements.filter(element => !element.groupIds.some(id => id.startsWith(ShadowGroupMarker)));
|
||||
groups = ea.getMaximumGroups(borderElements);
|
||||
groups = groups.map((group) => group.sort((a, b) => RankElement(b) - RankElement(a)));
|
||||
groups.sort((a, b) => RankElement(b[0]) - RankElement(a[0]));
|
||||
|
||||
ea.style.strokeColor = groups[0][0].strokeColor;
|
||||
ea.style.backgroundColor = groups[0][0].backgroundColor;
|
||||
ea.style.fillStyle = groups[0][0].fillStyle;
|
||||
ea.style.strokeWidth = groups[0][0].strokeWidth;
|
||||
ea.style.strokeStyle = groups[0][0].strokeStyle;
|
||||
ea.style.roughness = groups[0][0].roughness;
|
||||
ea.style.opacity = groups[0][0].opacity;
|
||||
|
||||
const basePolygons = groups.shift().map(element => traceElement(element));
|
||||
const toolPolygons = groups.flatMap(group => group.map(element => traceElement(element)));
|
||||
|
||||
const result = polyboolAction({
|
||||
regions: basePolygons,
|
||||
inverted: false
|
||||
}, {
|
||||
regions: toolPolygons,
|
||||
inverted: false
|
||||
});
|
||||
const polygonHierachy = subordinateInnerPolygons(result.regions);
|
||||
drawPolygonHierachy(polygonHierachy);
|
||||
ea.deleteViewElements(elements);
|
||||
ea.addElementsToView(false,false,true);
|
||||
return;
|
||||
|
||||
|
||||
|
||||
function traceElement(element) {
|
||||
const diamondPath = (diamond) => [
|
||||
SxVEC(1/2, [0, diamond.height]),
|
||||
SxVEC(1/2, [diamond.width, 0]),
|
||||
addVec([SxVEC(1/2, [0, diamond.height]), ([diamond.width, 0])]),
|
||||
addVec([SxVEC(1/2, [diamond.width, 0]), ([0, diamond.height])]),
|
||||
SxVEC(1/2, [0, diamond.height])
|
||||
];
|
||||
const rectanglePath = (rectangle) => [
|
||||
[0,0],
|
||||
[0, rectangle.height],
|
||||
[rectangle.width, rectangle.height],
|
||||
[rectangle.width, 0],
|
||||
[0, 0]
|
||||
]
|
||||
const ellipsePath = (ellipse) => {
|
||||
const angle = ellipse.angle;
|
||||
const width = ellipse.width;
|
||||
const height = ellipse.height;
|
||||
const ellipseAtPoint = (t) => {
|
||||
const spanningVector = [width/2*Math.cos(t), height/2*Math.sin(t)];
|
||||
const baseVector = [width/2, height/2];
|
||||
return addVec([spanningVector, baseVector]);
|
||||
}
|
||||
let points = [];
|
||||
step = (2*Math.PI)/64
|
||||
for (let t = 0; t < 2*Math.PI; t = t + step) {
|
||||
points.push(ellipseAtPoint(t));
|
||||
}
|
||||
return points;
|
||||
}
|
||||
let polygon;
|
||||
let correctForPolygon = [0, 0];
|
||||
switch (element.type) {
|
||||
case "diamond":
|
||||
polygon = diamondPath(element);
|
||||
break;
|
||||
case "rectangle":
|
||||
polygon = rectanglePath(element);
|
||||
break;
|
||||
case "ellipse":
|
||||
polygon = ellipsePath(element);
|
||||
break;
|
||||
case "line":
|
||||
case "arrow":
|
||||
if (element.angle != 0) {
|
||||
let smallestX = 0;
|
||||
let smallestY = 0;
|
||||
element.points.forEach(point => {
|
||||
if (point[0] < smallestX) smallestX = point[0];
|
||||
if (point[1] < smallestY) smallestY = point[1];
|
||||
});
|
||||
polygon = element.points.map(point => {
|
||||
return [
|
||||
point[0] -= smallestX,
|
||||
point[1] -= smallestY
|
||||
];
|
||||
});
|
||||
correctForPolygon = [smallestX, smallestY];
|
||||
break;
|
||||
}
|
||||
if (element.roundness) {
|
||||
new Notice("This script does not work with curved lines or arrows yet!");
|
||||
return [];
|
||||
}
|
||||
polygon = element.points;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (element.angle == 0) return polygon.map(v => addVec([v, [element.x, element.y]]));
|
||||
|
||||
polygon = polygon.map(v => addVec([v, SxVEC(-1/2, [element.width, element.height])]));
|
||||
polygon = rotateVectorsByAngle(polygon, element.angle);
|
||||
return polygon.map(v => addVec([v, [element.x, element.y], SxVEC(1/2, [element.width, element.height]), correctForPolygon]));
|
||||
}
|
||||
|
||||
function RankElement(element) {
|
||||
let score = 0;
|
||||
const backgroundRank = [
|
||||
"dashed",
|
||||
"none",
|
||||
"hachure",
|
||||
"zigzag",
|
||||
"zigzag-line",
|
||||
"cross-hatch",
|
||||
"solid"
|
||||
]
|
||||
score += (backgroundRank.findIndex((fillStyle) => fillStyle == element.fillStyle) + 1) * 10;
|
||||
if (element.backgroundColor == "transparent") score -= 100;
|
||||
if (element.points && getVectorLength(element.points[element.points.length - 1]) > 8) score -= 100;
|
||||
if (score < 0) score = 0;
|
||||
score += element.opacity / 100;
|
||||
return score;
|
||||
}
|
||||
|
||||
function drawPolygonHierachy(polygonHierachy) {
|
||||
const backgroundColor = ea.style.backgroundColor;
|
||||
const strokeColor = ea.style.strokeColor;
|
||||
const setInnerStyle = () => {
|
||||
ea.style.backgroundColor = backgroundColor;
|
||||
ea.style.strokeColor = "transparent";
|
||||
}
|
||||
const setBorderStyle = () => {
|
||||
ea.style.backgroundColor = "transparent";
|
||||
ea.style.strokeColor = strokeColor;
|
||||
}
|
||||
const setFilledStyle = () => {
|
||||
ea.style.backgroundColor = backgroundColor;
|
||||
ea.style.strokeColor = strokeColor;
|
||||
}
|
||||
|
||||
polygonHierachy.forEach(polygon => {
|
||||
setFilledStyle();
|
||||
let path = polygon.path;
|
||||
path.push(polygon.path[0]);
|
||||
if (polygon.innerPolygons.length === 0) {
|
||||
ea.addLine(path);
|
||||
return;
|
||||
}
|
||||
const outerBorder = path;
|
||||
const innerPolygons = addInnerPolygons(polygon.innerPolygons);
|
||||
path = path.concat(innerPolygons.backgroundPath);
|
||||
path.push(polygon.path[0]);
|
||||
setInnerStyle();
|
||||
const backgroundId = ea.addLine(path);
|
||||
setBorderStyle();
|
||||
const outerBorderId = ea.addLine(outerBorder)
|
||||
const innerBorderIds = innerPolygons.borderPaths.map(path => ea.addLine(path));
|
||||
const allIds = [innerBorderIds, outerBorderId, backgroundId].flat();
|
||||
ea.addToGroup(allIds);
|
||||
const background = ea.getElement(backgroundId);
|
||||
background.groupIds.push(ShadowGroupMarker + outerBorderId);
|
||||
});
|
||||
}
|
||||
|
||||
function addInnerPolygons(polygonHierachy) {
|
||||
let firstPath = [];
|
||||
let secondPath = [];
|
||||
let borderPaths = [];
|
||||
polygonHierachy.forEach(polygon => {
|
||||
let path = polygon.path;
|
||||
path.push(polygon.path[0]);
|
||||
borderPaths.push(path);
|
||||
firstPath = firstPath.concat(path);
|
||||
secondPath.push(polygon.path[0]);
|
||||
drawPolygonHierachy(polygon.innerPolygons);
|
||||
});
|
||||
return {
|
||||
backgroundPath: firstPath.concat(secondPath.reverse()),
|
||||
borderPaths: borderPaths
|
||||
};
|
||||
}
|
||||
|
||||
function subordinateInnerPolygons(polygons) {
|
||||
const polygonObjectPrototype = (polygon) => {
|
||||
return {
|
||||
path: polygon,
|
||||
innerPolygons: []
|
||||
};
|
||||
}
|
||||
|
||||
const insertPolygonIntoHierachy = (polygon, hierarchy) => {
|
||||
for (let i = 0; i < hierarchy.length; i++) {
|
||||
const polygonObject = hierarchy[i];
|
||||
let inside = null;
|
||||
let pointIndex = 0;
|
||||
do {
|
||||
inside = pointInPolygon(polygon[pointIndex], polygonObject.path);
|
||||
pointIndex++
|
||||
} while (inside === null);
|
||||
if (inside) {
|
||||
hierarchy[i].innerPolygons = insertPolygonIntoHierachy(polygon, hierarchy[i].innerPolygons);
|
||||
return hierarchy;
|
||||
}
|
||||
}
|
||||
polygon = polygonObjectPrototype(polygon);
|
||||
for (let i = 0; i < hierarchy.length; i++) {
|
||||
const polygonObject = hierarchy[i];
|
||||
let inside = null;
|
||||
let pointIndex = 0;
|
||||
do {
|
||||
inside = pointInPolygon(polygonObject.path[pointIndex], polygon.path);
|
||||
pointIndex++
|
||||
} while (inside === null);
|
||||
if (inside) {
|
||||
polygon.innerPolygons.push(hierarchy.splice(i, 1)[0]);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
hierarchy.push(polygon);
|
||||
return hierarchy;
|
||||
}
|
||||
|
||||
let polygonHierachy = [];
|
||||
polygons.forEach(polygon => {
|
||||
polygonHierachy = insertPolygonIntoHierachy(polygon, polygonHierachy);
|
||||
})
|
||||
|
||||
return polygonHierachy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given point lays in the polygon
|
||||
* @param point array [x, y]
|
||||
* @param polygon array [[x, y], ...]
|
||||
* @returns true if inside, false if not, null if the point is on one of the polygons vertecies
|
||||
*/
|
||||
function pointInPolygon(point, polygon) {
|
||||
const x = point[0];
|
||||
const y = point[1];
|
||||
let inside = false;
|
||||
|
||||
// odd even test if point is in polygon
|
||||
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
|
||||
const xi = polygon[i][0];
|
||||
const yi = polygon[i][1];
|
||||
const xj = polygon[j][0];
|
||||
const yj = polygon[j][1];
|
||||
|
||||
const intersect =
|
||||
yi > y !== yj > y &&
|
||||
x < ((xj - xi) * (y - yi)) / (yj - yi) + xi;
|
||||
|
||||
if (intersect) {
|
||||
inside = !inside;
|
||||
}
|
||||
|
||||
if ((x === xi && y === yi) || (x === xj && y === yj)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return inside;
|
||||
}
|
||||
|
||||
|
||||
function getVectorLength(vector) {
|
||||
return Math.sqrt(vector[0]**2+vector[1]**2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds two Vectors together
|
||||
*/
|
||||
function addVec(vectors) {
|
||||
return vectors.reduce((acc, vec) => [acc[0] + vec[0], acc[1] + vec[1]], [0, 0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the negative of the vector
|
||||
*/
|
||||
function negVec(vector) {
|
||||
return [-vector[0], -vector[1]];
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiplies Vector with a scalar
|
||||
*/
|
||||
function SxVEC(scalar, vector) {
|
||||
return [vector[0] * scalar, vector[1] * scalar];
|
||||
}
|
||||
|
||||
function rotateVector (vec, ang) {
|
||||
var cos = Math.cos(ang);
|
||||
var sin = Math.sin(ang);
|
||||
return [vec[0] * cos - vec[1] * sin, vec[0] * sin + vec[1] * cos];
|
||||
}
|
||||
|
||||
function rotateVectorsByAngle(vectors, angle) {
|
||||
const cosAngle = Math.cos(angle);
|
||||
const sinAngle = Math.sin(angle);
|
||||
|
||||
const rotationMatrix = [
|
||||
[cosAngle, -sinAngle],
|
||||
[sinAngle, cosAngle]
|
||||
];
|
||||
|
||||
return applyTranformationMatrix(vectors, rotationMatrix);
|
||||
}
|
||||
|
||||
function applyTranformationMatrix(vectors, transformationMatrix) {
|
||||
const result = [];
|
||||
for (const vector of vectors) {
|
||||
const x = vector[0];
|
||||
const y = vector[1];
|
||||
|
||||
const newX = transformationMatrix[0][0] * x + transformationMatrix[0][1] * y;
|
||||
const newY = transformationMatrix[1][0] * x + transformationMatrix[1][1] * y;
|
||||
|
||||
result.push([newX, newY]);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
5
ea-scripts/Boolean Operations.svg
Normal file
5
ea-scripts/Boolean Operations.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 17 KiB |
102
ea-scripts/Concatenate lines.md
Normal file
102
ea-scripts/Concatenate lines.md
Normal file
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
Connects two lines. Lines may be type of arrow or line. The resulting line will carry the style of the line higher in the drawing layers (bring to front the one you want to control the look and feel). Arrows are connected intelligently.
|
||||

|
||||
```js*/
|
||||
const lines = ea.getViewSelectedElements().filter(el=>el.type==="line" || el.type==="arrow");
|
||||
if(lines.length !== 2) {
|
||||
new Notice ("Select two lines or arrows");
|
||||
return;
|
||||
}
|
||||
|
||||
// https://math.stackexchange.com/questions/2204520/how-do-i-rotate-a-line-segment-in-a-specific-point-on-the-line
|
||||
const rotate = (point, element) => {
|
||||
const [x1, y1] = point;
|
||||
const x2 = element.x + element.width/2;
|
||||
const y2 = element.y - element.height/2;
|
||||
const angle = element.angle;
|
||||
return [
|
||||
(x1 - x2) * Math.cos(angle) - (y1 - y2) * Math.sin(angle) + x2,
|
||||
(x1 - x2) * Math.sin(angle) + (y1 - y2) * Math.cos(angle) + y2,
|
||||
];
|
||||
}
|
||||
|
||||
const points = lines.map(
|
||||
el=>el.points.map(p=>rotate([p[0]+el.x, p[1]+el.y],el))
|
||||
);
|
||||
|
||||
const last = (p) => p[p.length-1];
|
||||
const first = (p) => p[0];
|
||||
const distance = (p1,p2) => Math.sqrt((p1[0]-p2[0])**2+(p1[1]-p2[1])**2);
|
||||
|
||||
const distances = [
|
||||
distance(first(points[0]),first(points[1])),
|
||||
distance(first(points[0]),last (points[1])),
|
||||
distance(last (points[0]),first(points[1])),
|
||||
distance(last (points[0]),last (points[1]))
|
||||
];
|
||||
|
||||
const connectDirection = distances.indexOf(Math.min(...distances));
|
||||
|
||||
let newPoints = [];
|
||||
switch(connectDirection) {
|
||||
case 0: //first-first
|
||||
newPoints = [...points[0].reverse(),...points[1].slice(1)];
|
||||
break;
|
||||
case 1: //first-last
|
||||
newPoints = [...points[0].reverse(),...points[1].reverse().slice(1)];
|
||||
break;
|
||||
case 2: //last-first
|
||||
newPoints = [...points[0],...points[1].slice(1)];
|
||||
break;
|
||||
case 3: //last-last
|
||||
newPoints = [...points[0],...points[1].reverse().slice(1)];
|
||||
break;
|
||||
}
|
||||
|
||||
["strokeColor", "backgrounColor", "fillStyle", "roundness", "roughness", "strokeWidth", "strokeStyle", "opacity"].forEach(prop=>{
|
||||
ea.style[prop] = lines[1][prop];
|
||||
})
|
||||
|
||||
ea.style.startArrowHead = null;
|
||||
ea.style.endArrowHead = null;
|
||||
|
||||
ea.copyViewElementsToEAforEditing(lines);
|
||||
ea.getElements().forEach(el=>{el.isDeleted = true});
|
||||
|
||||
const lineTypes = parseInt(lines.map(line => line.type === "line" ? '1' : '0').join(''),2);
|
||||
|
||||
switch (lineTypes) {
|
||||
case 0: //arrow - arrow
|
||||
ea.addArrow(
|
||||
newPoints,
|
||||
connectDirection === 0 //first-first
|
||||
? { startArrowHead: lines[0].endArrowhead, endArrowHead: lines[1].endArrowhead }
|
||||
: connectDirection === 1 //first-last
|
||||
? { startArrowHead: lines[0].endArrowhead, endArrowHead: lines[1].startArrowhead }
|
||||
: connectDirection === 2 //last-first
|
||||
? { startArrowHead: lines[0].startArrowhead, endArrowHead: lines[1].endArrowhead }
|
||||
//3: last-last
|
||||
: { startArrowHead: lines[0].startArrowhead, endArrowHead: lines[1].startArrowhead }
|
||||
);
|
||||
break;
|
||||
case 1: //arrow - line
|
||||
reverse = connectDirection === 0 || connectDirection === 1;
|
||||
ea.addArrow(newPoints,{
|
||||
startArrowHead: reverse ? lines[0].endArrowhead : lines[0].startArrowhead,
|
||||
endArrowHead: reverse ? lines[0].startArrowhead : lines[0].endArrowhead
|
||||
});
|
||||
break;
|
||||
case 2: //line - arrow
|
||||
reverse = connectDirection === 1 || connectDirection === 3;
|
||||
ea.addArrow(newPoints,{
|
||||
startArrowHead: reverse ? lines[1].endArrowhead : lines[1].startArrowhead,
|
||||
endArrowHead: reverse ? lines[1].startArrowhead : lines[1].endArrowhead
|
||||
});
|
||||
break;
|
||||
case 3: //line - line
|
||||
ea.addLine(newPoints);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
ea.addElementsToView();
|
||||
17
ea-scripts/Concatenate lines.svg
Normal file
17
ea-scripts/Concatenate lines.svg
Normal file
@@ -0,0 +1,17 @@
|
||||
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 72.75819749055177 80.03703336574608" width="72.75819749055177" height="80.03703336574608">
|
||||
<!-- svg-source:excalidraw -->
|
||||
|
||||
<defs>
|
||||
<style class="style-fonts">
|
||||
@font-face {
|
||||
font-family: "Virgil";
|
||||
src: url("https://excalidraw.com/Virgil.woff2");
|
||||
}
|
||||
@font-face {
|
||||
font-family: "Cascadia";
|
||||
src: url("https://excalidraw.com/Cascadia.woff2");
|
||||
}
|
||||
</style>
|
||||
|
||||
</defs>
|
||||
<g stroke-linecap="round"><g transform="translate(4 4) rotate(0 12.71901889991409 17.183109917454658)"><path d="M0 0 C0 7.02, 0 14.05, 0 34.37 M0 34.37 C7.62 34.37, 15.24 34.37, 25.44 34.37" stroke="black" stroke-width="4.5" fill="none" stroke-dasharray="1.5 10"></path></g></g><mask></mask><g stroke-linecap="round"><g transform="translate(51.379765518092086 61.93633577499986) rotate(0 5.684341886080802e-14 7.050348795373111)"><path d="M0 0 C0 4.06, 0 8.11, 0 14.1" stroke="black" stroke-width="4.5" fill="none" stroke-dasharray="1.5 10"></path></g></g><mask></mask><g stroke-linecap="round" transform="translate(34.0013341989918 20.987787610339183) rotate(0 17.378431645779926 17.378431645779983)"><path d="M34.76 17.38 C34.76 18.38, 34.67 19.41, 34.49 20.4 C34.32 21.39, 34.05 22.38, 33.71 23.32 C33.36 24.27, 32.93 25.2, 32.43 26.07 C31.93 26.94, 31.34 27.78, 30.69 28.55 C30.04 29.32, 29.32 30.04, 28.55 30.69 C27.78 31.34, 26.94 31.93, 26.07 32.43 C25.2 32.93, 24.27 33.36, 23.32 33.71 C22.38 34.05, 21.39 34.32, 20.4 34.49 C19.41 34.67, 18.38 34.76, 17.38 34.76 C16.37 34.76, 15.35 34.67, 14.36 34.49 C13.37 34.32, 12.38 34.05, 11.43 33.71 C10.49 33.36, 9.56 32.93, 8.69 32.43 C7.82 31.93, 6.98 31.34, 6.21 30.69 C5.44 30.04, 4.71 29.32, 4.07 28.55 C3.42 27.78, 2.83 26.94, 2.33 26.07 C1.83 25.2, 1.39 24.27, 1.05 23.32 C0.7 22.38, 0.44 21.39, 0.26 20.4 C0.09 19.41, 0 18.38, 0 17.38 C0 16.37, 0.09 15.35, 0.26 14.36 C0.44 13.37, 0.7 12.38, 1.05 11.43 C1.39 10.49, 1.83 9.56, 2.33 8.69 C2.83 7.82, 3.42 6.98, 4.07 6.21 C4.71 5.44, 5.44 4.71, 6.21 4.07 C6.98 3.42, 7.82 2.83, 8.69 2.33 C9.56 1.83, 10.49 1.39, 11.43 1.05 C12.38 0.7, 13.37 0.44, 14.36 0.26 C15.35 0.09, 16.37 0, 17.38 0 C18.38 0, 19.41 0.09, 20.4 0.26 C21.39 0.44, 22.38 0.7, 23.32 1.05 C24.27 1.39, 25.2 1.83, 26.07 2.33 C26.94 2.83, 27.78 3.42, 28.55 4.07 C29.32 4.71, 30.04 5.44, 30.69 6.21 C31.34 6.98, 31.93 7.82, 32.43 8.69 C32.93 9.56, 33.36 10.49, 33.71 11.43 C34.05 12.38, 34.32 13.37, 34.49 14.36 C34.67 15.35, 34.71 16.88, 34.76 17.38 C34.8 17.88, 34.8 16.88, 34.76 17.38" stroke="black" stroke-width="4" fill="none"></path></g><g stroke-linecap="round"><g transform="translate(41.72257566145686 38.36621939788711) rotate(0 9.65718949485347 0)"><path d="M0 0 C4.11 0, 8.22 0, 19.31 0 M0 0 C6.95 0, 13.9 0, 19.31 0" stroke="black" stroke-width="4" fill="none"></path></g></g><mask></mask><g stroke-linecap="round"><g transform="translate(41.72257587602678 38.36622004108449) rotate(89.99999999999994 9.65718949485347 0)"><path d="M0 0 C5.31 0, 10.62 0, 19.31 0 M0 0 C4.56 0, 9.13 0, 19.31 0" stroke="black" stroke-width="4" fill="none"></path></g></g><mask></mask></svg>
|
||||
|
After Width: | Height: | Size: 3.1 KiB |
@@ -33,6 +33,7 @@ Open the script you are interested in and save it to your Obsidian Vault includi
|
||||
|[Add Link to Existing File and Open](Add%20Link%20to%20Existing%20File%20and%20Open.md)|Prompts for a file from the vault. Adds a link to the selected element pointing to the selected file. You can control in settings to open the file in the current active pane or an adjacent pane.||[@zsviczian](https://github.com/zsviczian)|
|
||||
|[Add Link to New Page and Open](Add%20Link%20and%20Open%20Page.md)|Prompts for filename. Offers option to create and open a new Markdown or Excalidraw document. Adds link pointing to the new file, to the selected objects in the drawing. You can control in settings to open the file in the current active pane or an adjacent pane.||[@zsviczian](https://github.com/zsviczian)|
|
||||
|[Add Next Step in Process](Add%20Link%20to%20New%20Page%20and%20Open.md)|This script will prompt you for the title of the process step, then will create a stick note with the text. If an element is selected then the script will connect this new step with an arrow to the previous step (the selected element). If no element is selected, then the script assumes this is the first step in the process and will only output the sticky note with the text that was entered.||[@zsviczian](https://github.com/zsviczian)|
|
||||
|[Split Ellipse](Boolean%20Operations.md)|With This Script it is possible to make boolean Operations on Shapes.||[@GColoy](https://github.com/GColoy)|
|
||||
|[Box Each Selected Groups](Box%20Each%20Selected%20Groups.md)|This script will add encapsulating boxes around each of the currently selected groups in Excalidraw.||[@1-2-3](https://github.com/1-2-3)|
|
||||
|[Box Selected Elements](Box%20Selected%20Elements.md)|This script will add an encapsulating box around the currently selected elements in Excalidraw.||[@zsviczian](https://github.com/zsviczian)|
|
||||
|[Change shape of selected elements](Change%20shape%20of%20selected%20elements.md)|The script allows you to change the shape of selected Rectangles, Diamonds and Ellipses||[@zsviczian](https://github.com/zsviczian)|
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -54,6 +54,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/Add%20Connector%20Point.svg"></div>|[[#Add Connector Point]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Concatenate%20lines.svg"></div>|[[#Concatenate lines]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Connect%20elements.svg"/></div>|[[#Connect elements]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Elbow%20connectors.svg"/></div>|[[#Elbow connectors]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Mindmap%20connector.svg"/></div>|[[#Mindmap connector]]|
|
||||
@@ -112,6 +113,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/Auto%20Draw%20for%20Pen.svg"/></div>|[[#Auto Draw for Pen]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Boolean%20Operations.svg"/></div>|[[#Boolean Operations]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Copy%20Selected%20Element%20Styles%20to%20Global.svg"/></div>|[[#Copy Selected Element Styles to Global]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Hardware%20Eraser%20Support.svg"/></div>|[[#Hardware Eraser Support]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Palette%20loader.svg"/></div>|[[#Palette Loader]]|
|
||||
@@ -179,6 +181,13 @@ https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea
|
||||
```
|
||||
<table><tr valign='top'><td class="label">Author</td><td class="data"><a href='https://github.com/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/Auto%20Layout.md'>File on GitHub</a></td></tr><tr valign='top'><td class="label">Description</td><td class="data">This script performs automatic layout for the selected top-level grouping objects. It is powered by <a href='https://github.com/kieler/elkjs'>elkjs</a> and needs to be connected to the Internet.<br><img src='https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/images/scripts-auto-layout.png'></td></tr></table>
|
||||
|
||||
## Boolean Operations
|
||||
```excalidraw-script-install
|
||||
https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Boolean%20Operations.md
|
||||
```
|
||||
<table><tr valign='top'><td class="label">Author</td><td class="data"><a href='https://github.com/GColoy'>@GColoy</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/Boolean%20Operations.md'>File on GitHub</a></td></tr><tr valign='top'><td class="label">Description</td><td class="data">With This Script it is possible to make boolean Operations on Shapes.<br>The style of the resulting shape will be the style of the highest ranking Element that was used.<br>The ranking of the elemtns is based on their background. The "denser" the background, the higher the ranking (the order of backgroundstyles is shown below). If they have the same background the opacity will decide. If thats also the same its decided by the order they were created.<br>The ranking is also important for the diffrence operation, so a tranparent object for example will cut a hole into a solid object.<br><img src='https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/images/scripts-boolean-operations-showcase.png'><br><img src='https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/images/scripts-boolean-operations-element-ranking.png'></td></tr></table>
|
||||
|
||||
|
||||
## Box Each Selected Groups
|
||||
```excalidraw-script-install
|
||||
https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Box%20Each%20Selected%20Groups.md
|
||||
@@ -197,6 +206,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/Change%20shape%20of%20selected%20elements.md'>File on GitHub</a></td></tr><tr valign='top'><td class="label">Description</td><td class="data">The script allows you to change the shape and fill style of selected Rectangles, Diamonds, Ellipses, Lines, Arrows and Freedraw.<br><img src='https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/images/scripts-change-shape.jpg'></td></tr></table>
|
||||
|
||||
## Concatenate lines
|
||||
```excalidraw-script-install
|
||||
https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Concatenate%20lines.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/Concatenate%20lines.md'>File on GitHub</a></td></tr><tr valign='top'><td class="label">Description</td><td class="data">This script will connect two objects with an arrow. If either of the objects are a set of grouped elements (e.g. a text element grouped with an encapsulating rectangle), the script will identify these groups, and connect the arrow to the largest object in the group (assuming you want to connect the arrow to the box around the text element).<br><img src='https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/images/scripts-concatenate-lines.png'></td></tr></table>
|
||||
|
||||
## Connect elements
|
||||
```excalidraw-script-install
|
||||
https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Connect%20elements.md
|
||||
|
||||
BIN
images/scripts-boolean-operations-element-ranking.png
Normal file
BIN
images/scripts-boolean-operations-element-ranking.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 44 KiB |
BIN
images/scripts-boolean-operations-showcase.png
Normal file
BIN
images/scripts-boolean-operations-showcase.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
BIN
images/scripts-concatenate-lines.png
Normal file
BIN
images/scripts-concatenate-lines.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "obsidian-excalidraw-plugin",
|
||||
"name": "Excalidraw",
|
||||
"version": "1.9.19-mermaid",
|
||||
"version": "1.9.19.2",
|
||||
"minAppVersion": "1.1.6",
|
||||
"description": "An Obsidian plugin to edit and view Excalidraw drawings",
|
||||
"author": "Zsolt Viczian",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "obsidian-excalidraw-plugin",
|
||||
"name": "Excalidraw",
|
||||
"version": "1.9.19",
|
||||
"version": "1.9.23",
|
||||
"minAppVersion": "1.1.6",
|
||||
"description": "An Obsidian plugin to edit and view Excalidraw drawings",
|
||||
"author": "Zsolt Viczian",
|
||||
|
||||
@@ -18,13 +18,14 @@
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@zsviczian/excalidraw": "0.15.3-obsidian-1",
|
||||
"@zsviczian/excalidraw": "0.16.1-obsidian-3",
|
||||
"chroma-js": "^2.4.2",
|
||||
"clsx": "^2.0.0",
|
||||
"colormaster": "^1.2.1",
|
||||
"gl-matrix": "^3.4.3",
|
||||
"lz-string": "^1.5.0",
|
||||
"monkey-around": "^2.3.0",
|
||||
"polybooljs": "^1.2.0",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"roughjs": "^4.5.2",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//https://stackoverflow.com/questions/2068344/how-do-i-get-a-youtube-video-thumbnail-from-the-youtube-api
|
||||
//https://img.youtube.com/vi/uZz5MgzWXiM/maxresdefault.jpg
|
||||
|
||||
import { ExcalidrawImageElement, FileId } from "@zsviczian/excalidraw/types/element/types";
|
||||
import { ExcalidrawElement, ExcalidrawImageElement, FileId } from "@zsviczian/excalidraw/types/element/types";
|
||||
import { BinaryFileData, DataURL } from "@zsviczian/excalidraw/types/types";
|
||||
import { App, MarkdownRenderer, Notice, TFile } from "obsidian";
|
||||
import {
|
||||
@@ -40,6 +40,8 @@ import {
|
||||
} from "./utils/Utils";
|
||||
import { ValueOf } from "./types";
|
||||
import { has } from "./svgToExcalidraw/attributes";
|
||||
import { getMermaidImageElements, getMermaidText, shouldRenderMermaid } from "./utils/MermaidUtils";
|
||||
import { mermaidToExcalidraw } from "src/constants";
|
||||
|
||||
//An ugly workaround for the following situation.
|
||||
//File A is a markdown file that has an embedded Excalidraw file B
|
||||
@@ -317,6 +319,70 @@ export class EmbeddedFilesLoader {
|
||||
return result;
|
||||
}
|
||||
|
||||
private async getExcalidrawSVG ({
|
||||
isDark,
|
||||
file,
|
||||
depth,
|
||||
inFile,
|
||||
hasSVGwithBitmap,
|
||||
elements = [],
|
||||
}: {
|
||||
isDark: boolean;
|
||||
file: TFile;
|
||||
depth: number;
|
||||
inFile: TFile | EmbeddedFile;
|
||||
hasSVGwithBitmap: boolean;
|
||||
elements?: ExcalidrawElement[];
|
||||
}) : Promise<{dataURL: DataURL, hasSVGwithBitmap:boolean}> {
|
||||
//debug({where:"EmbeddedFileLoader.getExcalidrawSVG",uid:this.uid,file:file.name});
|
||||
const forceTheme = hasExportTheme(this.plugin, file)
|
||||
? getExportTheme(this.plugin, file, "light")
|
||||
: undefined;
|
||||
const exportSettings: ExportSettings = {
|
||||
withBackground: hasExportBackground(this.plugin, file)
|
||||
? getWithBackground(this.plugin, file)
|
||||
: false,
|
||||
withTheme: !!forceTheme,
|
||||
};
|
||||
const svg = replaceSVGColors(
|
||||
await createSVG(
|
||||
file?.path,
|
||||
true,
|
||||
exportSettings,
|
||||
this,
|
||||
forceTheme,
|
||||
null,
|
||||
null,
|
||||
elements,
|
||||
this.plugin,
|
||||
depth+1,
|
||||
getExportPadding(this.plugin, file),
|
||||
),
|
||||
inFile instanceof EmbeddedFile ? inFile.colorMap : null
|
||||
) as SVGSVGElement;
|
||||
|
||||
//https://stackoverflow.com/questions/51154171/remove-css-filter-on-child-elements
|
||||
const imageList = svg.querySelectorAll(
|
||||
"image:not([href^='data:image/svg'])",
|
||||
);
|
||||
if (imageList.length > 0) {
|
||||
hasSVGwithBitmap = true;
|
||||
}
|
||||
if (hasSVGwithBitmap && isDark) {
|
||||
imageList.forEach((i) => {
|
||||
const id = i.parentElement?.id;
|
||||
svg.querySelectorAll(`use[href='#${id}']`).forEach((u) => {
|
||||
u.setAttribute("filter", THEME_FILTER);
|
||||
});
|
||||
});
|
||||
}
|
||||
if (!hasSVGwithBitmap && svg.getAttribute("hasbitmap")) {
|
||||
hasSVGwithBitmap = true;
|
||||
}
|
||||
const dURL = svgToBase64(svg.outerHTML) as DataURL;
|
||||
return {dataURL: dURL as DataURL, hasSVGwithBitmap};
|
||||
};
|
||||
|
||||
private async _getObsidianImage(inFile: TFile | EmbeddedFile, depth: number): Promise<ImgData> {
|
||||
if (!this.plugin || !inFile) {
|
||||
return null;
|
||||
@@ -363,59 +429,20 @@ export class EmbeddedFilesLoader {
|
||||
? null
|
||||
: await app.vault.readBinary(file);
|
||||
|
||||
const getExcalidrawSVG = async (isDark: boolean) => {
|
||||
//debug({where:"EmbeddedFileLoader.getExcalidrawSVG",uid:this.uid,file:file.name});
|
||||
const forceTheme = hasExportTheme(this.plugin, file)
|
||||
? getExportTheme(this.plugin, file, "light")
|
||||
: undefined;
|
||||
const exportSettings: ExportSettings = {
|
||||
withBackground: hasExportBackground(this.plugin, file)
|
||||
? getWithBackground(this.plugin, file)
|
||||
: false,
|
||||
withTheme: !!forceTheme,
|
||||
};
|
||||
const svg = replaceSVGColors(
|
||||
await createSVG(
|
||||
file.path,
|
||||
true,
|
||||
exportSettings,
|
||||
this,
|
||||
forceTheme,
|
||||
null,
|
||||
null,
|
||||
[],
|
||||
this.plugin,
|
||||
depth+1,
|
||||
getExportPadding(this.plugin, file),
|
||||
),
|
||||
inFile instanceof EmbeddedFile ? inFile.colorMap : null
|
||||
) as SVGSVGElement;
|
||||
let dURL: DataURL = null;
|
||||
if (isExcalidrawFile) {
|
||||
const res = await this.getExcalidrawSVG({
|
||||
isDark: this.isDark,
|
||||
file,
|
||||
depth,
|
||||
inFile,
|
||||
hasSVGwithBitmap,
|
||||
});
|
||||
dURL = res.dataURL;
|
||||
hasSVGwithBitmap = res.hasSVGwithBitmap;
|
||||
}
|
||||
|
||||
//https://stackoverflow.com/questions/51154171/remove-css-filter-on-child-elements
|
||||
const imageList = svg.querySelectorAll(
|
||||
"image:not([href^='data:image/svg'])",
|
||||
);
|
||||
if (imageList.length > 0) {
|
||||
hasSVGwithBitmap = true;
|
||||
}
|
||||
if (hasSVGwithBitmap && isDark) {
|
||||
imageList.forEach((i) => {
|
||||
const id = i.parentElement?.id;
|
||||
svg.querySelectorAll(`use[href='#${id}']`).forEach((u) => {
|
||||
u.setAttribute("filter", THEME_FILTER);
|
||||
});
|
||||
});
|
||||
}
|
||||
if (!hasSVGwithBitmap && svg.getAttribute("hasbitmap")) {
|
||||
hasSVGwithBitmap = true;
|
||||
}
|
||||
const dURL = svgToBase64(svg.outerHTML) as DataURL;
|
||||
return dURL as DataURL;
|
||||
};
|
||||
|
||||
const excalidrawSVG = isExcalidrawFile
|
||||
? await getExcalidrawSVG(this.isDark)
|
||||
: null;
|
||||
const excalidrawSVG = isExcalidrawFile ? dURL : null;
|
||||
|
||||
const [pdfDataURL, pdfSize] = isPDF
|
||||
? await this.pdfToDataURL(file,linkParts)
|
||||
@@ -550,6 +577,59 @@ export class EmbeddedFilesLoader {
|
||||
}
|
||||
}
|
||||
|
||||
if(shouldRenderMermaid()) {
|
||||
const mermaidElements = getMermaidImageElements(excalidrawData.scene.elements);
|
||||
for(const element of mermaidElements) {
|
||||
if(this.terminate) {
|
||||
continue;
|
||||
}
|
||||
const data = getMermaidText(element);
|
||||
const result = await mermaidToExcalidraw(data, {fontSize: 20});
|
||||
if(!result) {
|
||||
continue;
|
||||
}
|
||||
if(result?.files) {
|
||||
for (const key in result.files) {
|
||||
const fileData = {
|
||||
...result.files[key],
|
||||
id: element.fileId,
|
||||
created: Date.now(),
|
||||
hasSVGwithBitmap: false,
|
||||
shouldScale: true,
|
||||
size: await getImageSize(result.files[key].dataURL),
|
||||
};
|
||||
files.push(fileData);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if(result?.elements) {
|
||||
//handle case that mermaidToExcalidraw has implemented this type of diagram in the mean time
|
||||
const res = await this.getExcalidrawSVG({
|
||||
isDark: this.isDark,
|
||||
file: null,
|
||||
depth,
|
||||
inFile: null,
|
||||
hasSVGwithBitmap: false,
|
||||
elements: result.elements
|
||||
});
|
||||
if(res?.dataURL) {
|
||||
const size = await getImageSize(res.dataURL);
|
||||
const fileData:FileData = {
|
||||
mimeType: "image/svg+xml",
|
||||
id: element.fileId,
|
||||
dataURL: res.dataURL,
|
||||
created: Date.now(),
|
||||
hasSVGwithBitmap: res.hasSVGwithBitmap,
|
||||
size,
|
||||
shouldScale: true,
|
||||
};
|
||||
files.push(fileData);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.emptyPDFDocsMap();
|
||||
if (this.terminate) {
|
||||
return;
|
||||
|
||||
@@ -78,6 +78,7 @@ import { ROUNDNESS } from "src/constants";
|
||||
import { ClipboardData } from "@zsviczian/excalidraw/types/clipboard";
|
||||
import { emulateKeysForLinkClick, KeyEvent, PaneTarget } from "src/utils/ModifierkeyHelper";
|
||||
import { Mutable } from "@zsviczian/excalidraw/types/utility-types";
|
||||
import PolyBool from "polybooljs";
|
||||
|
||||
extendPlugins([
|
||||
HarmonyPlugin,
|
||||
@@ -2307,6 +2308,16 @@ export class ExcalidrawAutomate {
|
||||
return CM(color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the class PolyBool from https://github.com/velipso/polybooljs
|
||||
* @returns
|
||||
*/
|
||||
getPolyBool() {
|
||||
const defaultEpsilon = 0.0000000001;
|
||||
PolyBool.epsilon(defaultEpsilon);
|
||||
return PolyBool;
|
||||
}
|
||||
|
||||
importSVG(svgString:string):boolean {
|
||||
const res:ConversionResult = svgToExcalidraw(svgString);
|
||||
if(res.hasErrors) {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
originalText: this is the text without added linebreaks for wrapping. This will be parsed or markup depending on view mode
|
||||
rawText: text with original markdown markup and without the added linebreaks for wrapping
|
||||
*/
|
||||
import { App, TFile } from "obsidian";
|
||||
import { App, Notice, TFile } from "obsidian";
|
||||
import {
|
||||
nanoid,
|
||||
FRONTMATTER_KEY_CUSTOM_PREFIX,
|
||||
@@ -52,7 +52,8 @@ import {
|
||||
} from "@zsviczian/excalidraw/types/element/types";
|
||||
import { BinaryFiles, DataURL, SceneData } from "@zsviczian/excalidraw/types/types";
|
||||
import { EmbeddedFile, MimeType } from "./EmbeddedFileLoader";
|
||||
import { ConfirmationPrompt, Prompt } from "./dialogs/Prompt";
|
||||
import { ConfirmationPrompt } from "./dialogs/Prompt";
|
||||
import { getMermaidImageElements, getMermaidText, shouldRenderMermaid } from "./utils/MermaidUtils";
|
||||
|
||||
type SceneDataWithFiles = SceneData & { files: BinaryFiles };
|
||||
|
||||
@@ -261,6 +262,7 @@ export class ExcalidrawData {
|
||||
public loaded: boolean = false;
|
||||
public files: Map<FileId, EmbeddedFile> = null; //fileId, path
|
||||
private equations: Map<FileId, { latex: string; isLoaded: boolean }> = null; //fileId, path
|
||||
private mermaids: Map<FileId, { mermaid: string; isLoaded: boolean }> = null; //fileId, path
|
||||
private compatibilityMode: boolean = false;
|
||||
selectedElementIds: {[key:string]:boolean} = {}; //https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/609
|
||||
|
||||
@@ -270,6 +272,7 @@ export class ExcalidrawData {
|
||||
this.app = plugin.app;
|
||||
this.files = new Map<FileId, EmbeddedFile>();
|
||||
this.equations = new Map<FileId, { latex: string; isLoaded: boolean }>();
|
||||
this.mermaids = new Map<FileId, { mermaid: string; isLoaded: boolean }>();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -434,9 +437,10 @@ export class ExcalidrawData {
|
||||
>();
|
||||
this.elementLinks = new Map<string, string>();
|
||||
if (this.file != file) {
|
||||
//this is a reload - files and equations will take care of reloading when needed
|
||||
//this is a reload - files, equations and mermaids will take care of reloading when needed
|
||||
this.files.clear();
|
||||
this.equations.clear();
|
||||
this.mermaids.clear();
|
||||
}
|
||||
this.file = file;
|
||||
this.compatibilityMode = false;
|
||||
@@ -621,6 +625,16 @@ export class ExcalidrawData {
|
||||
});
|
||||
}
|
||||
|
||||
//Load Mermaids
|
||||
const mermaidElements = getMermaidImageElements(this.scene.elements);
|
||||
if(mermaidElements.length>0 && !shouldRenderMermaid()) {
|
||||
new Notice ("Mermaid images are only supported in Obsidian 1.4.14 and above. Please update Obsidian to see the mermaid images in this drawing. Obsidian mobile 1.4.14 currently only avaiable to Obsidian insiders", 5000);
|
||||
} else {
|
||||
mermaidElements.forEach(el =>
|
||||
this.setMermaid(el.fileId, {mermaid: getMermaidText(el), isLoaded: false})
|
||||
);
|
||||
}
|
||||
|
||||
//Check to see if there are text elements in the JSON that were missed from the # Text Elements section
|
||||
//e.g. if the entire text elements section was deleted.
|
||||
this.findNewTextElementsInScene();
|
||||
@@ -657,6 +671,7 @@ export class ExcalidrawData {
|
||||
}
|
||||
this.files.clear();
|
||||
this.equations.clear();
|
||||
this.mermaids.clear();
|
||||
this.findNewTextElementsInScene();
|
||||
this.findNewElementLinksInScene();
|
||||
await this.setTextMode(TextMode.raw, true); //legacy files are always displayed in raw mode.
|
||||
@@ -1103,6 +1118,7 @@ export class ExcalidrawData {
|
||||
outString += `${this.elementLinks.get(key)} ^${key}\n\n`;
|
||||
}
|
||||
|
||||
// deliberately not adding mermaids to here. It is enough to have the mermaidText in the image element's customData
|
||||
outString +=
|
||||
this.equations.size > 0 || this.files.size > 0
|
||||
? "\n# Embedded files\n"
|
||||
@@ -1226,6 +1242,13 @@ export class ExcalidrawData {
|
||||
}
|
||||
});
|
||||
|
||||
this.mermaids.forEach((value, key) => {
|
||||
if (!fileIds.contains(key)) {
|
||||
this.mermaids.delete(key);
|
||||
dirty = true;
|
||||
}
|
||||
});
|
||||
|
||||
//check if there are any images that need to be processed in the new scene
|
||||
if (!scene.files || Object.keys(scene.files).length === 0) {
|
||||
return false;
|
||||
@@ -1239,25 +1262,25 @@ export class ExcalidrawData {
|
||||
fileIds.forEach(fileId=>{
|
||||
if(processedIds.has(fileId)) {
|
||||
const file = this.getFile(fileId);
|
||||
//const file = this.files.get(fileId as FileId);
|
||||
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
|
||||
const mermaid = this.getMermaid(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.isHyperlink || (file.file && (file.file.extension !== "md" || this.plugin.isExcalidrawFile(file.file))))) {
|
||||
return;
|
||||
}
|
||||
if(mermaid) {
|
||||
return;
|
||||
}
|
||||
const newId = fileid();
|
||||
//scene.files[newId] = {...scene.files[fileId]};
|
||||
(scene.elements.filter((el:ExcalidrawImageElement)=>el.fileId === fileId)[0] as any).fileId = newId;
|
||||
dirty = true;
|
||||
processedIds.add(newId);
|
||||
if(file) {
|
||||
this.setFile(newId as FileId,new EmbeddedFile(this.plugin,this.file.path,file.linkParts.original));
|
||||
//this.files.set(newId as FileId,new EmbeddedFile(this.plugin,this.file.path,file.linkParts.original))
|
||||
}
|
||||
if(equation) {
|
||||
this.setEquation(newId as FileId, {latex:equation.latex, isLoaded:false});
|
||||
//this.equations.set(newId as FileId, equation);
|
||||
}
|
||||
}
|
||||
processedIds.add(fileId);
|
||||
@@ -1265,7 +1288,8 @@ export class ExcalidrawData {
|
||||
|
||||
|
||||
for (const key of Object.keys(scene.files)) {
|
||||
if (!(this.hasFile(key as FileId) || this.hasEquation(key as FileId))) {
|
||||
const mermaidElements = getMermaidImageElements(scene.elements.filter((el:ExcalidrawImageElement)=>el.fileId === key));
|
||||
if (!(this.hasFile(key as FileId) || this.hasEquation(key as FileId) || this.hasMermaid(key as FileId) || mermaidElements.length > 0)) {
|
||||
dirty = true;
|
||||
await this.saveDataURLtoVault(
|
||||
scene.files[key].dataURL,
|
||||
@@ -1275,35 +1299,6 @@ export class ExcalidrawData {
|
||||
}
|
||||
}
|
||||
|
||||
//https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/297
|
||||
/*const equations = new Set<string>();
|
||||
const duplicateEqs = new Set<string>();
|
||||
for (const key of fileIds) {
|
||||
if (this.hasEquation(key as FileId)) {
|
||||
if (equations.has(key)) {
|
||||
duplicateEqs.add(key);
|
||||
} else {
|
||||
equations.add(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (duplicateEqs.size > 0) {
|
||||
for (const key of duplicateEqs.keys()) {
|
||||
const elements = this.scene.elements.filter(
|
||||
(el: ExcalidrawElement) => el.type === "image" && el.fileId === key,
|
||||
);
|
||||
for (let i = 1; i < elements.length; i++) {
|
||||
const newFileId = fileid() as FileId;
|
||||
this.setEquation(newFileId, {
|
||||
latex: this.getEquation(key as FileId).latex,
|
||||
isLoaded: false,
|
||||
});
|
||||
elements[i].fileId = newFileId;
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
return dirty;
|
||||
}
|
||||
|
||||
@@ -1558,7 +1553,7 @@ export class ExcalidrawData {
|
||||
}
|
||||
|
||||
/**
|
||||
Files and equations copy/paste support
|
||||
Files, equations and mermaid copy/paste support
|
||||
This is not a complete solution, it assumes the source document is opened first
|
||||
at that time the fileId is stored in the master files/equations map
|
||||
when pasted the map is checked if the file already exists
|
||||
@@ -1663,6 +1658,9 @@ export class ExcalidrawData {
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------
|
||||
//Equations
|
||||
//--------------
|
||||
public setEquation(
|
||||
fileId: FileId,
|
||||
data: { latex: string; isLoaded: boolean },
|
||||
@@ -1704,6 +1702,51 @@ export class ExcalidrawData {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------
|
||||
//Mermaids
|
||||
//--------------
|
||||
public setMermaid(
|
||||
fileId: FileId,
|
||||
data: { mermaid: string; isLoaded: boolean },
|
||||
) {
|
||||
this.mermaids.set(fileId, { mermaid: data.mermaid, isLoaded: data.isLoaded });
|
||||
this.plugin.mermaidsMaster.set(fileId, data.mermaid);
|
||||
}
|
||||
|
||||
public getMermaid(fileId: FileId): { mermaid: string; isLoaded: boolean } {
|
||||
let result = this.mermaids.get(fileId);
|
||||
if(result) return result;
|
||||
const mermaid = this.plugin.mermaidsMaster.get(fileId);
|
||||
if(!mermaid) return result;
|
||||
this.mermaids.set(fileId, {mermaid, isLoaded: false});
|
||||
return {mermaid, isLoaded: false};
|
||||
}
|
||||
|
||||
public getMermaidEntries() {
|
||||
return this.mermaids.entries();
|
||||
}
|
||||
|
||||
public deleteMermaid(fileId: FileId) {
|
||||
this.mermaids.delete(fileId);
|
||||
//deliberately not deleting from plugin.mermaidsMaster
|
||||
//could be present in other drawings as well
|
||||
}
|
||||
|
||||
//Image copy/paste support
|
||||
public hasMermaid(fileId: FileId): boolean {
|
||||
if (this.mermaids.has(fileId)) {
|
||||
return true;
|
||||
}
|
||||
if (this.plugin.mermaidsMaster.has(fileId)) {
|
||||
this.mermaids.set(fileId, {
|
||||
mermaid: this.plugin.mermaidsMaster.get(fileId),
|
||||
isLoaded: false,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export const getTransclusion = async (
|
||||
|
||||
@@ -15,7 +15,6 @@ import {
|
||||
//import Excalidraw from "@zsviczian/excalidraw";
|
||||
import {
|
||||
ExcalidrawElement,
|
||||
ExcalidrawEmbeddableElement,
|
||||
ExcalidrawTextElement,
|
||||
FileId,
|
||||
NonDeletedExcalidrawElement,
|
||||
@@ -116,7 +115,7 @@ import { getTextElementAtPointer, getImageElementAtPointer, getElementWithLinkAt
|
||||
import { ICONS, LogoWrapper, saveIcon } from "./menu/ActionIcons";
|
||||
import { ExportDialog } from "./dialogs/ExportDialog";
|
||||
import { getEA } from "src"
|
||||
import { anyModifierKeysPressed, emulateCTRLClickForLinks, emulateKeysForLinkClick, externalDragModifierType, internalDragModifierType, isALT, isCTRL, isMETA, isSHIFT, linkClickModifierType, mdPropModifier, ModifierKeys } from "./utils/ModifierkeyHelper";
|
||||
import { anyModifierKeysPressed, emulateKeysForLinkClick, externalDragModifierType, internalDragModifierType, isALT, isCTRL, isMETA, isSHIFT, linkClickModifierType, ModifierKeys } from "./utils/ModifierkeyHelper";
|
||||
import { setDynamicStyle } from "./utils/DynamicStyling";
|
||||
import { InsertPDFModal } from "./dialogs/InsertPDFModal";
|
||||
import { CustomEmbeddable, renderWebView } from "./customEmbeddable";
|
||||
@@ -127,6 +126,7 @@ import { EmbeddableMenu } from "./menu/EmbeddableActionsMenu";
|
||||
import { useDefaultExcalidrawFrame } from "./utils/CustomEmbeddableUtils";
|
||||
import { UniversalInsertFileModal } from "./dialogs/UniversalInsertFileModal";
|
||||
import { moment } from "obsidian";
|
||||
import { shouldRenderMermaid } from "./utils/MermaidUtils";
|
||||
|
||||
declare const PLUGIN_VERSION:string;
|
||||
|
||||
@@ -997,6 +997,13 @@ export default class ExcalidrawView extends TextFileView {
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (this.excalidrawData.hasMermaid(selectedImage.fileId)) {
|
||||
if(shouldRenderMermaid) {
|
||||
const api = this.excalidrawAPI as ExcalidrawImperativeAPI;
|
||||
api.setActiveTool({type: "mermaid"});
|
||||
}
|
||||
return;
|
||||
}
|
||||
await this.save(false); //in case pasted images haven't been saved yet
|
||||
if (this.excalidrawData.hasFile(selectedImage.fileId)) {
|
||||
const ef = this.excalidrawData.getFile(selectedImage.fileId);
|
||||
@@ -1021,7 +1028,7 @@ export default class ExcalidrawView extends TextFileView {
|
||||
GenericInputPrompt.Prompt(
|
||||
this,
|
||||
this.plugin,
|
||||
app,
|
||||
this.app,
|
||||
"Customize the link",
|
||||
undefined,
|
||||
ef.linkParts.original,
|
||||
@@ -2037,7 +2044,7 @@ export default class ExcalidrawView extends TextFileView {
|
||||
//justloaded,
|
||||
);
|
||||
if (
|
||||
app.workspace.getActiveViewOfType(ExcalidrawView) === this.leaf.view &&
|
||||
this.app.workspace.getActiveViewOfType(ExcalidrawView) === this.leaf.view &&
|
||||
this.excalidrawWrapperRef
|
||||
) {
|
||||
//.firstElmentChild solves this issue: https://github.com/zsviczian/obsidian-excalidraw-plugin/pull/346
|
||||
@@ -2896,7 +2903,8 @@ export default class ExcalidrawView extends TextFileView {
|
||||
|
||||
const showHoverPreview = (linktext?: string, element?: ExcalidrawElement) => {
|
||||
if(!mouseEvent) return;
|
||||
if(this.excalidrawAPI?.getAppState()?.editingElement) return; //should not activate hover preview when element is being edited
|
||||
const st = this.excalidrawAPI?.getAppState();
|
||||
if(st?.editingElement || st?.draggingElement) return; //should not activate hover preview when element is being edited or dragged
|
||||
if(this.semaphores.wheelTimeout) return;
|
||||
//if link text is not provided, try to get it from the element
|
||||
if (!linktext) {
|
||||
@@ -3269,6 +3277,9 @@ export default class ExcalidrawView extends TextFileView {
|
||||
await this.plugin.saveSettings();
|
||||
})();
|
||||
},
|
||||
|
||||
// TODO: Potentially better way to block middle mouse paste on linux:
|
||||
//! onauxclick: (e: any) => {e.preventDefault()},
|
||||
renderTopRightUI: (isMobile: boolean, appState: AppState) => this.obsidianMenu.renderButton (isMobile, appState),
|
||||
renderEmbeddableMenu: (appState: AppState) => this.embeddableMenu.renderButtons(appState),
|
||||
onPaste: (
|
||||
@@ -3287,6 +3298,18 @@ export default class ExcalidrawView extends TextFileView {
|
||||
});
|
||||
if(typeof res === "boolean" && res === false) return false;
|
||||
}
|
||||
|
||||
// Disables Middle Mouse Button Paste Functionality on Linux
|
||||
if(
|
||||
!this.modifierKeyDown.ctrlKey
|
||||
&& typeof event !== "undefined"
|
||||
&& event !== null
|
||||
&& DEVICE.isLinux
|
||||
) {
|
||||
console.debug("Prevented what is likely middle mouse button paste.")
|
||||
return false
|
||||
};
|
||||
|
||||
if(data && data.text && hyperlinkIsImage(data.text)) {
|
||||
this.addImageWithURL(data.text);
|
||||
return false;
|
||||
@@ -3325,6 +3348,9 @@ export default class ExcalidrawView extends TextFileView {
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
|
||||
|
||||
onThemeChange: async (newTheme: string) => {
|
||||
//debug({where:"ExcalidrawView.onThemeChange",file:this.file.name,before:"this.loadSceneFiles",newTheme});
|
||||
this.excalidrawData.scene.appState.theme = newTheme;
|
||||
@@ -3976,7 +4002,8 @@ export default class ExcalidrawView extends TextFileView {
|
||||
} catch(e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
},
|
||||
renderMermaid: shouldRenderMermaid()
|
||||
|
||||
},//,React.createElement(Footer,{},React.createElement(customTextEditor.render)),
|
||||
React.createElement (
|
||||
|
||||
@@ -177,7 +177,7 @@ const _getSVGIMG = async ({filenameParts,theme,cacheReady,img,file,exportSetting
|
||||
return null;
|
||||
}
|
||||
|
||||
svg = embedFontsInSVG(svg, plugin);
|
||||
svg = embedFontsInSVG(svg, plugin, false);
|
||||
//need to remove width and height attributes to support area= embeds
|
||||
svg.removeAttribute("width");
|
||||
svg.removeAttribute("height");
|
||||
@@ -199,7 +199,7 @@ const _getSVGNative = async ({filenameParts,theme,cacheReady,containerElement,fi
|
||||
maybeSVG = await imageCache.getImageFromCache(cacheKey);
|
||||
}
|
||||
|
||||
const svg = maybeSVG && (maybeSVG instanceof SVGSVGElement)
|
||||
let svg = maybeSVG && (maybeSVG instanceof SVGSVGElement)
|
||||
? maybeSVG
|
||||
: convertSVGStringToElement((await createSVG(
|
||||
filenameParts.hasGroupref || filenameParts.hasBlockref || filenameParts.hasSectionref || filenameParts.hasFrameref
|
||||
@@ -223,6 +223,7 @@ const _getSVGNative = async ({filenameParts,theme,cacheReady,containerElement,fi
|
||||
return null;
|
||||
}
|
||||
|
||||
svg = embedFontsInSVG(svg, plugin, true);
|
||||
svg.removeAttribute("width");
|
||||
svg.removeAttribute("height");
|
||||
containerElement.append(svg);
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -17,6 +17,62 @@ I develop this plugin as a hobby, spending my free time doing this. If you find
|
||||
|
||||
<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.9.23":`
|
||||
## Fixed
|
||||
- Link navigation error in view mode introduced with 1.9.21 [#7120](https://github.com/excalidraw/excalidraw/pull/7120)
|
||||
`,
|
||||
"1.9.21":`
|
||||
## Fixed:
|
||||
- When moving a group of objects on the grid, each object snapped separately resulting in a jumbled-up image [#7082](https://github.com/excalidraw/excalidraw/issues/7082)
|
||||
|
||||
## New from Excalidraw.com:
|
||||
- 🎉 Laser Pointer. Press "K" to activate the laser pointer, or find it under more tools. In View-Mode double click/tap the canvas to toggle the laser pointer
|
||||
|
||||

|
||||
`,
|
||||
"1.9.20":`
|
||||
<div class="excalidraw-videoWrapper"><div>
|
||||
<iframe src="https://www.youtube.com/embed/QB2rKRxxYlg" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
|
||||
</div></div>
|
||||
|
||||
## Fixed
|
||||
- Fourth Font displays correctly in SVG embeds mode
|
||||
- The re-colorMap map (see [1.9.19](https://github.com/zsviczian/obsidian-excalidraw-plugin/releases/tag/1.9.19) for more info) did not work when either of the fill or stroke color properties of the image was missing.
|
||||
- Excalidraw Pasting with middle mouse button on Linux [#1338](https://github.com/zsviczian/obsidian-excalidraw-plugin/pull/1338) 🙏@Aeases
|
||||
|
||||
### Fixed by excalidraw.com
|
||||
- Excalidraw's native eyedropper fixes [#7019](https://github.com/excalidraw/excalidraw/pull/7019)
|
||||
|
||||
## New
|
||||
- Now you can insert [Mermaid](https://mermaid.live/) diagrams as Excalidraw elements into your drawings (currently only the [Flowchart](https://mermaid.js.org/syntax/flowchart.html) type is supported, [other diagram types](https://mermaid.js.org/intro/#diagram-types) are inserted as Mermaid native images.
|
||||
- ⚠️**This feature requires Obsidian API v1.4.14 (the latest desktop version). On Obsidian mobile API v1.4.14 is only available to Obsidian insiders currently**
|
||||
- If you want to contribute to the project please head over to [mermaid-to-excalidraw](https://github.com/excalidraw/mermaid-to-excalidraw) and help create the converters for the other diagram types.
|
||||
- The Fourth Font now also supports the OTF format
|
||||
- Disable snap-to-grid in grid mode by holding down the CTRL/CMD while drawing or moving an element [#6983](https://github.com/excalidraw/excalidraw/pull/6983)
|
||||
- I updated the Excalidraw logo in Obsidian. This affects the logo on the tab and the ribbon.
|
||||
|
||||
### New from excalidraw.com
|
||||
- Elements alignment snapping. Hold down the CTRL/CMD button while moving an element to snap it to other objects. [#6256](https://github.com/excalidraw/excalidraw/pull/6256)
|
||||
|
||||
### New in the script library
|
||||
- The amazing shape [Boolean Operations](https://github.com/zsviczian/obsidian-excalidraw-plugin/blob/master/ea-scripts/Boolean%20Operations.md) script created by 🙏@GColoy is available in the script library.
|
||||
|
||||
### New in Excalidraw Automate
|
||||
- ${String.fromCharCode(96)}getPolyBool()${String.fromCharCode(96)} returns a [PolyBool](https://github.com/velipso/polybooljs) object
|
||||
- sample mermaid code:
|
||||
${String.fromCharCode(96,96,96)}js
|
||||
ea = ExcalidrawAutomate();
|
||||
ea.setView();
|
||||
await ea.addMermaid(
|
||||
${String.fromCharCode(96)}flowchart TD
|
||||
A[Christmas] -->|Get money| B(Go shopping)
|
||||
B --> C{Let me think}
|
||||
C -->|One| D[Laptop]
|
||||
C -->|Two| E[iPhone]
|
||||
C -->|Three| F[fa:fa-car Car]${String.fromCharCode(96)}
|
||||
);
|
||||
ea.addElementsToView();
|
||||
${String.fromCharCode(96,96,96)}`,
|
||||
"1.9.19":`
|
||||
## New
|
||||
- I added new features to the [Deconstruct Selected Elements](https://github.com/zsviczian/obsidian-excalidraw-plugin/blob/master/ea-scripts/Deconstruct%20selected%20elements%20into%20new%20drawing.md) script
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
Workspace,
|
||||
Editor,
|
||||
MarkdownFileInfo,
|
||||
loadMermaid,
|
||||
} from "obsidian";
|
||||
import {
|
||||
BLANK_DRAWING,
|
||||
@@ -146,6 +147,7 @@ export default class ExcalidrawPlugin extends Plugin {
|
||||
public filesMaster: Map<FileId, { isHyperlink: boolean; path: string; hasSVGwithBitmap: boolean; blockrefData: string, colorMapJSON?: string}> =
|
||||
null; //fileId, path
|
||||
public equationsMaster: Map<FileId, string> = null; //fileId, formula
|
||||
public mermaidsMaster: Map<FileId, string> = null; //fileId, mermaidText
|
||||
public mathjax: any = null;
|
||||
private mathjaxDiv: HTMLDivElement = null;
|
||||
public mathjaxLoaderFinished: boolean = false;
|
||||
@@ -164,6 +166,7 @@ export default class ExcalidrawPlugin extends Plugin {
|
||||
{ isHyperlink: boolean; path: string; hasSVGwithBitmap: boolean; blockrefData: string; colorMapJSON?: string }
|
||||
>();
|
||||
this.equationsMaster = new Map<FileId, string>();
|
||||
this.mermaidsMaster = new Map<FileId, string>();
|
||||
}
|
||||
|
||||
public getPackage(win:Window):Packages {
|
||||
@@ -190,6 +193,7 @@ export default class ExcalidrawPlugin extends Plugin {
|
||||
addIcon(EXPORT_IMG_ICON_NAME, EXPORT_IMG_ICON);
|
||||
|
||||
await this.loadSettings({reEnableAutosave:true});
|
||||
await loadMermaid();
|
||||
imageCache.plugin = this;
|
||||
|
||||
this.addSettingTab(new ExcalidrawSettingTab(this.app, this));
|
||||
|
||||
1
src/polybooljs.d.ts
vendored
Normal file
1
src/polybooljs.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
declare module "polybooljs";
|
||||
14
src/utils/MermaidUtils.ts
Normal file
14
src/utils/MermaidUtils.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { ExcalidrawElement, ExcalidrawImageElement } from "@zsviczian/excalidraw/types/element/types";
|
||||
import { requireApiVersion } from "obsidian";
|
||||
|
||||
export const getMermaidImageElements = (elements: ExcalidrawElement[]):ExcalidrawImageElement[] =>
|
||||
elements
|
||||
? elements.filter((element) =>
|
||||
element.type === "image" && element.customData?.mermaidText
|
||||
) as ExcalidrawImageElement[]
|
||||
: [];
|
||||
|
||||
export const getMermaidText = (element: ExcalidrawElement):string =>
|
||||
element.customData?.mermaidText;
|
||||
|
||||
export const shouldRenderMermaid = ():boolean => requireApiVersion("1.4.14");
|
||||
@@ -211,9 +211,8 @@ export const getFontDataURL = async (
|
||||
: "font/truetype";
|
||||
fontName = name ?? f.basename;
|
||||
dataURL = await getDataURL(ab, mimeType);
|
||||
fontDef = ` @font-face {font-family: "${fontName}";src: url("${dataURL}") format("${
|
||||
f.extension === "ttf" ? "truetype" : f.extension
|
||||
}");}`;
|
||||
fontDef = ` @font-face {font-family: "${fontName}";src: url("${dataURL}")}`;
|
||||
//format("${f.extension === "ttf" ? "truetype" : f.extension}");}`;
|
||||
const split = fontDef.split(";base64,", 2);
|
||||
fontDef = `${split[0]};charset=utf-8;base64,${split[1]}`;
|
||||
}
|
||||
@@ -352,11 +351,12 @@ export const getQuickImagePreview = async (
|
||||
export const embedFontsInSVG = (
|
||||
svg: SVGSVGElement,
|
||||
plugin: ExcalidrawPlugin,
|
||||
localOnly: boolean = false,
|
||||
): SVGSVGElement => {
|
||||
//replace font references with base64 fonts
|
||||
const includesVirgil =
|
||||
//replace font references with base64 fonts)
|
||||
const includesVirgil = !localOnly &&
|
||||
svg.querySelector("text[font-family^='Virgil']") != null;
|
||||
const includesCascadia =
|
||||
const includesCascadia = !localOnly &&
|
||||
svg.querySelector("text[font-family^='Cascadia']") != null;
|
||||
const includesLocalFont =
|
||||
svg.querySelector("text[font-family^='LocalFont']") != null;
|
||||
|
||||
@@ -414,4 +414,13 @@ div.excalidraw-draginfo {
|
||||
|
||||
.excalidraw-svg svg a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.excalidraw .Modal {
|
||||
background-color: initial;
|
||||
border: initial;
|
||||
max-width: initial;
|
||||
max-height: initial;
|
||||
width: initial;
|
||||
height: initial;
|
||||
}
|
||||
Reference in New Issue
Block a user