Compare commits

...

48 Commits

Author SHA1 Message Date
Zsolt Viczian
08528d9a88 1.4.8-beta-2 2021-11-14 23:13:06 +01:00
Zsolt Viczian
3e9ef99226 Reworked recursive image loading 2021-11-14 20:12:11 +01:00
Zsolt Viczian
f50ecd95c3 removed SVG snapshot 2021-11-14 12:08:19 +01:00
Zsolt Viczian
8b477a0e16 Added missing scale to createPNG interface 2021-11-14 09:41:53 +01:00
Zsolt Viczian
78891a1065 1.4.8-beta 2021-11-10 23:05:13 +01:00
Zsolt Viczian
b428cb7eed 1.4.7 (embed Excalidraw into Excalidraw fixed) 2021-11-08 19:44:45 +01:00
Zsolt Viczian
b20c1bed5a 1.4.6 2021-11-02 21:51:04 +01:00
Zsolt Viczian
f24c41eace 1.4.5 2021-11-02 21:33:11 +01:00
Zsolt Viczian
d33cf5ddd5 1.4.4 - basic copy/paste for equations & images 2021-11-01 17:41:12 +01:00
Zsolt Viczian
41491079be minapp version 12.16 2021-11-01 14:17:37 +01:00
Zsolt Viczian
5345c63672 updated versions 2021-11-01 14:17:05 +01:00
Zsolt Viczian
06acf09a85 1.4.3 2021-11-01 14:12:44 +01:00
Zsolt Viczian
ce6d983b38 LaTex MVP ready 2021-11-01 10:27:58 +01:00
zsviczian
bb6c0b54ff added Excalidraw files to filter 2021-10-30 21:54:51 +02:00
zsviczian
571dae52d3 Update Utils.ts 2021-10-29 19:51:00 +02:00
Zsolt Viczian
e6b5b0d125 latex WIP 2021-10-29 11:01:08 +02:00
Zsolt Viczian
8a1cf72095 1.4.2 2021-10-28 23:55:03 +02:00
Zsolt Viczian
f02425dcac 1.4.1 2021-10-26 23:06:00 +02:00
Zsolt Viczian
6e3cf60eab 1.4.0 2021-10-24 20:40:36 +02:00
zsviczian
32fdbf9dc2 Update README.md 2021-10-24 20:29:43 +02:00
Zsolt Viczian
1aed684ebe Fixed Mac CTRL vs. CMD button issue 2021-10-24 20:07:22 +02:00
Zsolt Viczian
1ad791d9bc 1.4.0 pre-release 2 2021-10-24 13:40:11 +02:00
zsviczian
bb9925024d Merge pull request #209 from zsviczian/Image-Element
Image element
2021-10-24 06:56:12 +02:00
Zsolt Viczian
e676255d69 switched excalidraw package to: 0.10.0-obsidian-2 2021-10-24 06:52:09 +02:00
Zsolt Viczian
691c60be24 1.4.0 pre-release 2021-10-23 19:35:40 +02:00
Zsolt Viczian
f4a458061a Image click navigation. Image embeds finalized. 2021-10-23 14:32:05 +02:00
Zsolt Viczian
c88c898f4a ExcalidrawRef readypromise 2021-10-23 09:14:07 +02:00
Zsolt Viczian
d2da408a59 Before implementing readyPromise for excalidrawRef 2021-10-23 08:56:51 +02:00
Zsolt Viczian
3b9a6404c5 integrate image element mid way 2021-10-22 20:34:27 +02:00
Zsolt Viczian
d9306922c3 save image to vault 2021-10-19 22:59:31 +02:00
zsviczian
578cc7a99c Merge pull request #201 from zsviczian/tmp
minor performance tweek
2021-10-19 20:03:36 +02:00
zsviczian
aa9f9ba91f Merge branch 'Image-Element' into tmp 2021-10-19 20:03:29 +02:00
Zsolt Viczian
b9251d4f1d minor performance tweek 2021-10-19 19:45:32 +02:00
Zsolt Viczian
13a980afed added mimetype 2021-10-19 18:40:20 +02:00
zsviczian
c911e0118f Merge pull request #199 from zsviczian/tmp
1.3.20
2021-10-18 20:33:43 +02:00
zsviczian
eca02a5941 Merge branch 'Image-Element' into tmp 2021-10-18 20:33:36 +02:00
Zsolt Viczian
f6b65ac3e9 bump image-support version 2021-10-18 18:50:16 +02:00
zsviczian
929348b390 Merge pull request #190 from zsviczian/temp
1.3.19
2021-10-12 20:50:48 +02:00
zsviczian
57f1b9f8da Merge branch 'Image-Element' into temp 2021-10-12 20:50:39 +02:00
Zsolt Viczian
739e919a43 mid way - adding Embedded files 2021-10-12 18:15:14 +02:00
zsviczian
e85cf4e196 Merge pull request #186 from zsviczian/temp-master
merge master into image-element
2021-10-11 19:59:18 +02:00
zsviczian
0c42353fce Merge branch 'Image-Element' into temp-master 2021-10-11 19:59:10 +02:00
Zsolt Viczian
3100e2d70f update en.ts 2021-10-10 18:04:57 +02:00
zsviczian
7712cd49b6 Merge pull request #174 from zsviczian/temp-master
fetch upstream
2021-10-04 21:43:40 +02:00
zsviczian
856573763e Merge branch 'Image-Element' into temp-master 2021-10-04 21:43:28 +02:00
zsviczian
48fd854944 Merge pull request #173 from zsviczian/tempmaster
updated package json with new libraries
2021-10-04 19:06:56 +02:00
zsviczian
8f9746393f Merge branch 'Image-Element' into tempmaster 2021-10-04 19:06:28 +02:00
Zsolt Viczian
627775c6c3 re-applied image element changes 2021-10-04 18:47:49 +02:00
24 changed files with 2124 additions and 845 deletions

View File

@@ -1,34 +1,20 @@
The Obsidian-Excalidraw plugin integrates [Excalidraw](https://excalidraw.com/), a feature rich sketching tool, into Obsidian. You can store and edit Excalidraw files in your vault, you can embed drawings into your documents, and you can link to documents and other drawings to/and from Excalidraw. For a showcase of Excalidraw features, please read my blog post [here](https://www.zsolt.blog/2021/03/showcasing-excalidraw.html) and/or watch the videos below.
Please upgrade to Obsidian v0.12.19 or higher to get the latest release.
![image](https://user-images.githubusercontent.com/14358394/125159831-336d6880-e17a-11eb-8a3d-ceabc2555a08.png)
# Important notice to the 1.2.0 update
This version comes with tons of new features and possibilities.
Drawings you've created with version 1.1.x need to be converted to take advantage of the new features. If you want, you can also continue to use your exisiting drawings in compatibility mode (e.g. if you use Logseq and Obsidian in parallel). During conversion your existing `*.excalidraw` files will be replaced with new `*.excalidraw.md` files.
## Conversion and compatibility
To convert files you have the following options:
- Click `CONVERT FILES` in the migration dialog when installing 1.2.0
- In the Command Palette select `Excalidraw: Convert *.excalidraw files to *.excalidraw.md files` to convert all `*.excalidraw` files to `*.excalidraw.md` files.
- To convert files individually:
- Right click an `*.excalidraw` file in File Explorer and select one of the following options:
- `*.excalidraw => *.excalidraw.md`
- `*.excalidraw => *.md (Logseq compatibility)`: This option will retain the original *.excalidraw file next to the new Obsidian format. Make sure you also enable additional `Compatibility features` in `Settings` for a full solution.
- Open a legacy `*.excalidraw` file and select `Convert to new format` from the `Options Menu` in the Excalidraw view.
# Video walkthrough
| | | |
|----|----|----|
|[![Obsidian-Excalidraw 1.2.0 update - Major IMPROVEMENTS](https://user-images.githubusercontent.com/14358394/124356817-7b3f3d80-dc18-11eb-932d-363bb373c5ab.jpg)](https://youtu.be/UxJLLYtgDKE)|[![1 Getting Started](https://user-images.githubusercontent.com/14358394/125160304-7f211180-e17c-11eb-8363-c52723de1ffd.jpg)](https://youtu.be/sY4FoflGaiM)|[![2 Basic shapes and features](https://user-images.githubusercontent.com/14358394/125160312-8a743d00-e17c-11eb-9fa2-490ef4cbd59e.jpg)](https://youtu.be/Iy_oVTq12Gw)|
|[![3 Groups](https://user-images.githubusercontent.com/14358394/125160323-96f89580-e17c-11eb-9bce-8eb1067a51bb.jpg)](https://youtu.be/QOL1KF7-kdc)|[![4 Stencil](https://user-images.githubusercontent.com/14358394/125160332-9f50d080-e17c-11eb-98e9-fec60fe147d9.jpg)](https://youtu.be/aSgcbfspvfo)|[![5 embedding](https://user-images.githubusercontent.com/14358394/125160341-a546b180-e17c-11eb-9de8-d87fdc844c9c.jpg)](https://youtu.be/MaJ5jJwBRWs)|
|[![6 Links](https://user-images.githubusercontent.com/14358394/125160346-aa0b6580-e17c-11eb-930b-4024807040d1.jpg)](https://youtu.be/MXzeCOEExNo)|[![7 Markdown](https://user-images.githubusercontent.com/14358394/125160354-b2fc3700-e17c-11eb-81af-9e71e461f6dd.jpg)](https://youtu.be/R0IAg0s-wQE)|[![8 Templates](https://user-images.githubusercontent.com/14358394/125160360-b8f21800-e17c-11eb-8bd8-79d4e3f6e92d.jpg)](https://youtu.be/ibdS7ykwpW4)|
|[![9 Excalidraw Automate](https://user-images.githubusercontent.com/14358394/125160367-bdb6cc00-e17c-11eb-92f1-6f59faea85fd.jpg)](https://youtu.be/VRZVujfVab0)|[![10 Miscellaneous](https://user-images.githubusercontent.com/14358394/125160374-c3141680-e17c-11eb-8cc2-dfaffd903d15.jpg)](https://youtu.be/D1iBYo1_jjc)||
|[![9 Excalidraw Automate](https://user-images.githubusercontent.com/14358394/125160367-bdb6cc00-e17c-11eb-92f1-6f59faea85fd.jpg)](https://youtu.be/VRZVujfVab0)|[![10 Miscellaneous](https://user-images.githubusercontent.com/14358394/125160374-c3141680-e17c-11eb-8cc2-dfaffd903d15.jpg)](https://youtu.be/D1iBYo1_jjc)|[![Image Elements](https://user-images.githubusercontent.com/14358394/138607067-ccb62f92-48a4-4880-ac6e-68c1bf86ac2c.png)](https://www.youtube.com/watch?v=_c_0zpBJ4Xc&)|
# Key features
- The plugin aims to integrate Excalidraw seemlessly into Obsidian including Command Palette actions, File Explorer features, Option Menu commands, and the Ribbon Button.
- CTRL+Click on the ribbon button, or in the file explorer to create / open drawings in a new pane.
- CTRL/CMD+Click on the ribbon button, or in the file explorer to create / open drawings in a new pane.
- Settings will allow you to customzie Excalidraw to your needs:
- Default folder for new drawings and define custom filename pattern for new drawings.
- Template for new drawings. The template will restore stroke properties. This means you can set up defaults in your template for stroke color, stroke width, opacity, font family, font size, fill style, stroke style, etc. This also applies to ExcalidrawAutomate.
@@ -46,13 +32,23 @@ To convert files you have the following options:
- `![[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
- CTRL/META + hover to bring up the Obsidian quick preview for the link. (On Mac it is CTRL+CMD+hover).
- CTRL/META + CLICK a text element to open it as a link.
- CTRL/META + ALT + CLICK to create the file (if it does not yet exist) and open it
- CTRL/META + SHIFT + CLICK to open the file in a new pane
- CTRL/META + ALT + SHIFT + CLICK to create the file (if it does not yet exist) and open it in a new pane
- CTRL/CMD + hover to bring up the Obsidian quick preview for the link. (On Mac it is CTRL+CMD+hover).
- CTRL/CMD + CLICK a text element to open it as a link.
- CTRL/CMD + ALT + CLICK to create the file (if it does not yet exist) and open it
- CTRL/CMD + SHIFT + CLICK to open the file in a new pane
- CTRL/CMD + ALT + SHIFT + CLICK to create the file (if it does not yet exist) and open it in a new pane
- Using the block reference you can also reference & transclude text that appears on drawings, in other documents
- Insert LaTex symbols and simple formulas using the Command Palette action "Insert LaTeX-symbol". Some symbols may not display properly using the "Hand-drawn" font. If that is the case try using the "Normal" or "Code" fonts.
- Insert LaTex formulas using the Command Palette action "Insert LaTeX formula". You can edit formulas either in Markdown view, or by CTRL/CMD + Click on the formula.
- Drag & Drop support
- You can drag files from the Obsidian file explorer and they will become links to those files in Excalidraw.
- Dragging image files (PNG, SVG, JPG, Excalidraw) from obsidian files explorer while pressing the CTRL/CMD button will embed the image into your drawing.
- You can drag and drop images from outside obsidian onto Excalidraw. These images will be embedded into your drawing and saved to Obsidian.
- You can drag and drop text from Markdown views onto Excalidraw.
- You can drag and drop web addresses from your browser and they will become links.
- Image support
- 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.
- 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
@@ -62,18 +58,17 @@ To convert files you have the following options:
- `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
- Includes full [Templater](https://silentvoid13.github.io/Templater/) and [Dataview](https://blacksmithgu.github.io/obsidian-dataview/docs/api/intro/) support through ExcalidrawAutomate. Check out the [detailed help + examples](https://zsviczian.github.io/obsidian-excalidraw-plugin/)
- Includes full [QuickAdd](https://github.com/chhoumann/quickadd), [Templater](https://silentvoid13.github.io/Templater/) and [Dataview](https://blacksmithgu.github.io/obsidian-dataview/docs/api/intro/) support through ExcalidrawAutomate. Check out the [detailed help + examples](https://zsviczian.github.io/obsidian-excalidraw-plugin/). I also have a [YouTube ExcalidrawAutomate Playlist](https://www.youtube.com/playlist?list=PL6mqgtMZ4NP1IR4nXxSlMA4PA5E-qpyHZ) with lots of examples.
- REQUIRES AN OBSIDIAN SYNC SUBSCRIPTION: Full drawing file history and synchronization between devices
- Multilanguage support: if you'd like to help out by translating the plugin, please get in contact with me.
# Known issues
- Mobile support
- Positioning of the pen gets misaligned after you open the command palette.
- Partially mitigated in 1.0.10 by the introduction of autosave: Your drawing will not be saved when you terminate the mobile app by closing the Obsidian task.
- Text elements "jumps off screen" when editing, if drawing is zoomed in and text element does not fit the visible screen area. I am working on a resolution.
# Tips and tricks
- If you want to sketch in fullscreen, I recommend installing the [Fullscreen Focus Mode](https://github.com/razumihin/obsidian-fullscreen-plugin) plugin.
- [Ozan's Image in Editor Plugin](https://github.com/ozntel/oz-image-in-editor-obsidian). In a nice collaboration with Ozan, his Image-in-Editor plugin now supports Excalidraw. I recommend installing his plugin to display drawings also in Edit mode. Note that Ozan's plugin will only display Excalidraw drawings if the link ends with `.md` or `.excalidraw`. i.e. the following drawing will show in Edit Mode `![[My Drawing.md]]`, but wiki links such as `[[My Drawing]]` will not.
- [Ozan's Image in Editor Plugin](https://github.com/ozntel/oz-image-in-editor-obsidian). In a nice collaboration with Ozan, his Image-in-Editor plugin now supports Excalidraw. I recommend installing his plugin to display drawings also in Edit mode.
# Feedback, questions, ideas, problems
Join the conversation about the Excalidraw plugin on [forum.obsidian.md](https://forum.obsidian.md/t/excalidraw-full-featured-sketching-plugin-in-obsidian)

14
TODO.md Normal file
View File

@@ -0,0 +1,14 @@
[x] do not embed font into SVG when embedding Excalidraw into other Excalidraw
[x] add ```html <SVG>...</SVG> ``` codeblock to excalidraw markdown
[x] read pre-saved `<SVG>` when generating image preview
[x] update code to adopt change files moving from AppState to App
- Add "files" to legacy excalidraw export
[x] PNG preview
[x] markdown embed SVG 190
[x] markdown embed PNG
[x] embed Excalidraw into other Excalidraw

View File

@@ -3,136 +3,137 @@
Here's the interface implemented by ExcalidrawAutomate:
```typescript
export interface ExcalidrawAutomate extends Window {
ExcalidrawAutomate: {
plugin: ExcalidrawPlugin;
elementsDict: {};
style: {
strokeColor: string;
backgroundColor: string;
angle: number;
fillStyle: FillStyle;
strokeWidth: number;
storkeStyle: StrokeStyle;
roughness: number;
opacity: number;
strokeSharpness: StrokeSharpness;
fontFamily: number;
fontSize: number;
textAlign: string;
verticalAlign: string;
startArrowHead: string;
endArrowHead: string;
}
canvas: {
theme: string,
viewBackgroundColor: string,
gridSize: number
};
setFillStyle (val:number): void;
setStrokeStyle (val:number): void;
setStrokeSharpness (val:number): void;
setFontFamily (val:number): void;
setTheme (val:number): void;
addToGroup (objectIds:[]):string;
toClipboard (templatePath?:string): void;
getElements ():ExcalidrawElement[];
getElement (id:string):ExcalidrawElement;
create (
params?: {
filename?: string,
foldername?:string,
templatePath?:string,
onNewPane?: boolean,
frontmatterKeys?:{
"excalidraw-plugin"?: "raw"|"parsed",
"excalidraw-link-prefix"?: string,
"excalidraw-link-brackets"?: boolean,
"excalidraw-url-prefix"?: string
}
}
):Promise<string>;
createSVG (templatePath?:string):Promise<SVGSVGElement>;
createPNG (templatePath?:string):Promise<any>;
wrapText (text:string, lineLen:number):string;
addRect (topX:number, topY:number, width:number, height:number):string;
addDiamond (topX:number, topY:number, width:number, height:number):string;
addEllipse (topX:number, topY:number, width:number, height:number):string;
addBlob (topX:number, topY:number, width:number, height:number):string;
addText (
topX:number,
topY:number,
text:string,
formatting?: {
wrapAt?:number,
width?:number,
height?:number,
textAlign?: string,
box?: "box"|"blob"|"ellipse"|"diamond",
boxPadding?: number
},
id?:string
):string;
addLine(points: [[x:number,y:number]]):string;
addArrow (
points: [[x:number,y:number]],
formatting?: {
startArrowHead?:string,
endArrowHead?:string,
startObjectId?:string,
endObjectId?:string
}
):string ;
connectObjects (
objectA: string,
connectionA: ConnectionPoint,
objectB: string,
connectionB: ConnectionPoint,
formatting?: {
numberOfPoints?: number,
startArrowHead?:string,
endArrowHead?:string,
padding?: number
}
):void;
clear (): void;
reset (): void;
isExcalidrawFile (f:TFile): boolean;
//view manipulation
targetView: ExcalidrawView;
setView (view:ExcalidrawView|"first"|"active"):ExcalidrawView;
getExcalidrawAPI ():any;
getViewElements ():ExcalidrawElement[];
deleteViewElements (el: ExcalidrawElement[]):boolean;
getViewSelectedElement( ):ExcalidrawElement;
getViewSelectedElements ():ExcalidrawElement[];
viewToggleFullScreen (forceViewMode?:boolean):void;
connectObjectWithViewSelectedElement (
objectA:string,
connectionA: ConnectionPoint,
connectionB: ConnectionPoint,
formatting?: {
numberOfPoints?: number,
startArrowHead?:string,
endArrowHead?:string,
padding?: number
}
):boolean;
addElementsToView (repositionToCursor:boolean, save:boolean):Promise<boolean>;
onDropHook (data: {
ea: ExcalidrawAutomate,
event: React.DragEvent<HTMLDivElement>,
draggable: any, //Obsidian draggable object
type: "file"|"text"|"unknown",
payload: {
files: TFile[], //TFile[] array of dropped files
text: string, //string
},
excalidrawFile: TFile, //the file receiving the drop event
view: ExcalidrawView, //the excalidraw view receiving the drop
pointerPosition: {x:number, y:number} //the pointer position on canvas at the time of drop
}):boolean;
export interface ExcalidrawAutomate {
plugin: ExcalidrawPlugin;
elementsDict: {};
imagesDict: {};
style: {
strokeColor: string;
backgroundColor: string;
angle: number;
fillStyle: FillStyle;
strokeWidth: number;
storkeStyle: StrokeStyle;
roughness: number;
opacity: number;
strokeSharpness: StrokeSharpness;
fontFamily: number;
fontSize: number;
textAlign: string;
verticalAlign: string;
startArrowHead: string;
endArrowHead: string;
}
canvas: {
theme: string,
viewBackgroundColor: string,
gridSize: number
};
setFillStyle (val:number): void;
setStrokeStyle (val:number): void;
setStrokeSharpness (val:number): void;
setFontFamily (val:number): void;
setTheme (val:number): void;
addToGroup (objectIds:[]):string;
toClipboard (templatePath?:string): void;
getElements ():ExcalidrawElement[];
getElement (id:string):ExcalidrawElement;
create (
params?: {
filename?: string,
foldername?:string,
templatePath?:string,
onNewPane?: boolean,
frontmatterKeys?:{
"excalidraw-plugin"?: "raw"|"parsed",
"excalidraw-link-prefix"?: string,
"excalidraw-link-brackets"?: boolean,
"excalidraw-url-prefix"?: string
}
}
):Promise<string>;
createSVG (templatePath?:string, embedFont?:boolean):Promise<SVGSVGElement>;
createPNG (templatePath?:string):Promise<any>;
wrapText (text:string, lineLen:number):string;
addRect (topX:number, topY:number, width:number, height:number):string;
addDiamond (topX:number, topY:number, width:number, height:number):string;
addEllipse (topX:number, topY:number, width:number, height:number):string;
addBlob (topX:number, topY:number, width:number, height:number):string;
addText (
topX:number,
topY:number,
text:string,
formatting?: {
wrapAt?:number,
width?:number,
height?:number,
textAlign?: string,
box?: boolean|"box"|"blob"|"ellipse"|"diamond",
boxPadding?: number
},
id?:string
):string;
addLine(points: [[x:number,y:number]]):string;
addArrow (
points: [[x:number,y:number]],
formatting?: {
startArrowHead?:string,
endArrowHead?:string,
startObjectId?:string,
endObjectId?:string
}
):string ;
addImage(topX:number, topY:number, imageFile: TFile):Promise<string>;
addLaTex(topX:number, topY:number, tex: string, color?:string):Promise<string>;
connectObjects (
objectA: string,
connectionA: ConnectionPoint,
objectB: string,
connectionB: ConnectionPoint,
formatting?: {
numberOfPoints?: number,
startArrowHead?:string,
endArrowHead?:string,
padding?: number
}
):void;
clear (): void;
reset (): void;
isExcalidrawFile (f:TFile): boolean;
//view manipulation
targetView: ExcalidrawView;
setView (view:ExcalidrawView|"first"|"active"):ExcalidrawView;
getExcalidrawAPI ():any;
getViewElements ():ExcalidrawElement[];
deleteViewElements (el: ExcalidrawElement[]):boolean;
getViewSelectedElement ():ExcalidrawElement;
getViewSelectedElements ():ExcalidrawElement[];
viewToggleFullScreen (forceViewMode?:boolean):void;
connectObjectWithViewSelectedElement (
objectA:string,
connectionA: ConnectionPoint,
connectionB: ConnectionPoint,
formatting?: {
numberOfPoints?: number,
startArrowHead?:string,
endArrowHead?:string,
padding?: number
}
):boolean;
addElementsToView (repositionToCursor:boolean, save:boolean):Promise<boolean>;
onDropHook (data: {
ea: ExcalidrawAutomate,
event: React.DragEvent<HTMLDivElement>,
draggable: any, //Obsidian draggable object
type: "file"|"text"|"unknown",
payload: {
files: TFile[], //TFile[] array of dropped files
text: string, //string
},
excalidrawFile: TFile, //the file receiving the drop event
view: ExcalidrawView, //the excalidraw view receiving the drop
pointerPosition: {x:number, y:number} //the pointer position on canvas at the time of drop
}):boolean;
}
```

View File

@@ -1,8 +1,8 @@
{
"id": "obsidian-excalidraw-plugin",
"name": "Excalidraw",
"version": "1.3.20",
"minAppVersion": "0.12.0",
"version": "1.4.7",
"minAppVersion": "0.12.16",
"description": "An Obsidian plugin to edit and view Excalidraw drawings",
"author": "Zsolt Viczian",
"authorUrl": "https://zsolt.blog",

View File

@@ -1,6 +1,6 @@
{
"name": "obsidian-excalidraw-plugin",
"version": "1.1.10",
"version": "1.3.21",
"description": "This is an Obsidian.md plugin that lets you view and edit Excalidraw drawings",
"main": "main.js",
"scripts": {
@@ -11,7 +11,7 @@
"author": "",
"license": "MIT",
"dependencies": {
"@zsviczian/excalidraw": "0.9.0-obsidian-13",
"@zsviczian/excalidraw": "0.10.0-obsidian-8",
"monkey-around": "^2.2.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
@@ -27,9 +27,11 @@
"@rollup/plugin-node-resolve": "^13.0.5",
"@rollup/plugin-replace": "^2.4.2",
"@rollup/plugin-typescript": "^8.2.5",
"@types/js-beautify": "^1.13.3",
"@types/node": "^15.12.4",
"@types/react-dom": "^17.0.9",
"cross-env": "^7.0.3",
"html2canvas": "^1.3.2",
"nanoid": "^3.1.23",
"obsidian": "^0.12.16",
"rollup": "^2.52.3",

165
src/EmbeddedFileLoader.ts Normal file
View File

@@ -0,0 +1,165 @@
import { FileId } from "@zsviczian/excalidraw/types/element/types";
import { BinaryFileData, DataURL } from "@zsviczian/excalidraw/types/types";
import { App, Notice, TFile } from "obsidian";
import { fileid, IMAGE_TYPES } from "./constants";
import { ExcalidrawData } from "./ExcalidrawData";
import ExcalidrawView, { ExportSettings } from "./ExcalidrawView";
import { tex2dataURL } from "./LaTeX";
import ExcalidrawPlugin from "./main";
import {getImageSize, svgToBase64 } from "./Utils";
export declare type MimeType = "image/svg+xml" | "image/png" | "image/jpeg" | "image/gif" | "application/octet-stream";
export class EmbeddedFilesLoader {
private plugin:ExcalidrawPlugin;
private processedFiles: Set<string> = new Set<string>();
constructor(plugin: ExcalidrawPlugin) {
this.plugin = plugin;
}
public async getObsidianImage (file: TFile)
:Promise<{
mimeType: MimeType,
fileId: FileId,
dataURL: DataURL,
created: number,
size: {height: number, width: number},
}> {
if(!this.plugin || !file) return null;
//to block infinite loop of recursive loading of images
if((file.extension==="md" || file.extension === "excalidraw") && this.processedFiles.has(file.path)) {
new Notice("Stopped loading infinite image embed loop at repeated instance of " + file.path,6000);
return null;
}
this.processedFiles.add(file.path);
const app = this.plugin.app;
const isExcalidrawFile = this.plugin.ea.isExcalidrawFile(file);
if (!(IMAGE_TYPES.contains(file.extension) || isExcalidrawFile)) {
return null;
}
const ab = await app.vault.readBinary(file);
const getExcalidrawSVG = async () => {
const exportSettings:ExportSettings = {
withBackground: false,
withTheme: false
};
this.plugin.ea.reset();
const svg = await this.plugin.ea.createSVG(file.path,true,exportSettings,this);
const dURL = svgToBase64(svg.outerHTML) as DataURL;
return dURL as DataURL;
}
const excalidrawSVG = isExcalidrawFile
? await getExcalidrawSVG()
: null;
let mimeType:MimeType = "image/svg+xml";
if (!isExcalidrawFile) {
switch (file.extension) {
case "png": mimeType = "image/png";break;
case "jpeg":mimeType = "image/jpeg";break;
case "jpg": mimeType = "image/jpeg";break;
case "gif": mimeType = "image/gif";break;
case "svg": mimeType = "image/svg+xml";break;
default: mimeType = "application/octet-stream";
}
}
const dataURL = excalidrawSVG ?? (file.extension==="svg" ? await getSVGData(app,file) : await getDataURL(ab,mimeType));
const size = await getImageSize(excalidrawSVG??app.vault.getResourcePath(file));
return {
mimeType: mimeType,
fileId: await generateIdFromFile(ab),
dataURL: dataURL,
created: file.stat.mtime,
size: size
}
}
public async loadSceneFiles (
excalidrawData: ExcalidrawData,
view: ExcalidrawView,
addFiles:Function,
sourcePath:string
) {
const app = this.plugin.app;
let entries = excalidrawData.getFileEntries();
let entry;
let files:BinaryFileData[] = [];
while(!(entry = entries.next()).done) {
const file = app.metadataCache.getFirstLinkpathDest(entry.value[1],sourcePath);
if(file && file instanceof TFile) {
const data = await this.getObsidianImage(file);
if(data) {
files.push({
mimeType : data.mimeType,
id: entry.value[0],
dataURL: data.dataURL,
created: data.created,
//@ts-ignore
size: data.size,
});
}
}
}
entries = excalidrawData.getEquationEntries();
while(!(entry = entries.next()).done) {
const tex = entry.value[1];
const data = await tex2dataURL(tex, this.plugin);
if(data) {
files.push({
mimeType : data.mimeType,
id: entry.value[0],
dataURL: data.dataURL,
created: data.created,
//@ts-ignore
size: data.size,
});
}
}
try { //in try block because by the time files are loaded the user may have closed the view
addFiles(files,view);
} catch(e) {
}
}
}
const getSVGData = async (app: App, file: TFile): Promise<DataURL> => {
const svg = await app.vault.read(file);
return svgToBase64(svg) as DataURL;
}
const getDataURL = async (file: ArrayBuffer,mimeType: string): Promise<DataURL> => {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => {
const dataURL = reader.result as DataURL;
resolve(dataURL);
};
reader.onerror = (error) => reject(error);
reader.readAsDataURL(new Blob([new Uint8Array(file)],{type:'mimeType'}));
});
};
const generateIdFromFile = async (file: ArrayBuffer):Promise<FileId> => {
let id: FileId;
try {
const hashBuffer = await window.crypto.subtle.digest(
"SHA-1",
file,
);
id =
// convert buffer to byte array
Array.from(new Uint8Array(hashBuffer))
// convert to hex string
.map((byte) => byte.toString(16).padStart(2, "0"))
.join("") as FileId;
} catch (error) {
console.error(error);
id = fileid() as FileId;
}
return id;
};

View File

@@ -9,157 +9,161 @@ import {
normalizePath,
TFile
} from "obsidian"
import ExcalidrawView from "./ExcalidrawView";
import { getJSON } from "./ExcalidrawData";
import ExcalidrawView, { ExportSettings, TextMode } from "./ExcalidrawView";
import { ExcalidrawData} from "./ExcalidrawData";
import {
FRONTMATTER,
nanoid,
JSON_parse,
VIEW_TYPE_EXCALIDRAW
VIEW_TYPE_EXCALIDRAW,
MAX_IMAGE_SIZE,
} from "./constants";
import { wrapText } from "./Utils";
import { embedFontsInSVG, getPNG, getSVG, scaleLoadedImage, wrapText } from "./Utils";
import { AppState } from "@zsviczian/excalidraw/types/types";
import { EmbeddedFilesLoader } from "./EmbeddedFileLoader";
import { tex2dataURL } from "./LaTeX";
declare type ConnectionPoint = "top"|"bottom"|"left"|"right";
export interface ExcalidrawAutomate extends Window {
ExcalidrawAutomate: {
plugin: ExcalidrawPlugin;
elementsDict: {};
style: {
strokeColor: string;
backgroundColor: string;
angle: number;
fillStyle: FillStyle;
strokeWidth: number;
storkeStyle: StrokeStyle;
roughness: number;
opacity: number;
strokeSharpness: StrokeSharpness;
fontFamily: number;
fontSize: number;
textAlign: string;
verticalAlign: string;
startArrowHead: string;
endArrowHead: string;
}
canvas: {
theme: string,
viewBackgroundColor: string,
gridSize: number
};
setFillStyle (val:number): void;
setStrokeStyle (val:number): void;
setStrokeSharpness (val:number): void;
setFontFamily (val:number): void;
setTheme (val:number): void;
addToGroup (objectIds:[]):string;
toClipboard (templatePath?:string): void;
getElements ():ExcalidrawElement[];
getElement (id:string):ExcalidrawElement;
create (
params?: {
filename?: string,
foldername?:string,
templatePath?:string,
onNewPane?: boolean,
frontmatterKeys?:{
"excalidraw-plugin"?: "raw"|"parsed",
"excalidraw-link-prefix"?: string,
"excalidraw-link-brackets"?: boolean,
"excalidraw-url-prefix"?: string
}
}
):Promise<string>;
createSVG (templatePath?:string):Promise<SVGSVGElement>;
createPNG (templatePath?:string):Promise<any>;
wrapText (text:string, lineLen:number):string;
addRect (topX:number, topY:number, width:number, height:number):string;
addDiamond (topX:number, topY:number, width:number, height:number):string;
addEllipse (topX:number, topY:number, width:number, height:number):string;
addBlob (topX:number, topY:number, width:number, height:number):string;
addText (
topX:number,
topY:number,
text:string,
formatting?: {
wrapAt?:number,
width?:number,
height?:number,
textAlign?: string,
box?: boolean|"box"|"blob"|"ellipse"|"diamond",
boxPadding?: number
},
id?:string
):string;
addLine(points: [[x:number,y:number]]):string;
addArrow (
points: [[x:number,y:number]],
formatting?: {
startArrowHead?:string,
endArrowHead?:string,
startObjectId?:string,
endObjectId?:string
}
):string ;
connectObjects (
objectA: string,
connectionA: ConnectionPoint,
objectB: string,
connectionB: ConnectionPoint,
formatting?: {
numberOfPoints?: number,
startArrowHead?:string,
endArrowHead?:string,
padding?: number
}
):void;
clear (): void;
reset (): void;
isExcalidrawFile (f:TFile): boolean;
//view manipulation
targetView: ExcalidrawView;
setView (view:ExcalidrawView|"first"|"active"):ExcalidrawView;
getExcalidrawAPI ():any;
getViewElements ():ExcalidrawElement[];
deleteViewElements (el: ExcalidrawElement[]):boolean;
getViewSelectedElement ():ExcalidrawElement;
getViewSelectedElements ():ExcalidrawElement[];
viewToggleFullScreen (forceViewMode?:boolean):void;
connectObjectWithViewSelectedElement (
objectA:string,
connectionA: ConnectionPoint,
connectionB: ConnectionPoint,
formatting?: {
numberOfPoints?: number,
startArrowHead?:string,
endArrowHead?:string,
padding?: number
}
):boolean;
addElementsToView (repositionToCursor:boolean, save:boolean):Promise<boolean>;
onDropHook (data: {
ea: ExcalidrawAutomate,
event: React.DragEvent<HTMLDivElement>,
draggable: any, //Obsidian draggable object
type: "file"|"text"|"unknown",
payload: {
files: TFile[], //TFile[] array of dropped files
text: string, //string
},
excalidrawFile: TFile, //the file receiving the drop event
view: ExcalidrawView, //the excalidraw view receiving the drop
pointerPosition: {x:number, y:number} //the pointer position on canvas at the time of drop
}):boolean;
export interface ExcalidrawAutomate {
plugin: ExcalidrawPlugin;
elementsDict: {};
imagesDict: {};
style: {
strokeColor: string;
backgroundColor: string;
angle: number;
fillStyle: FillStyle;
strokeWidth: number;
storkeStyle: StrokeStyle;
roughness: number;
opacity: number;
strokeSharpness: StrokeSharpness;
fontFamily: number;
fontSize: number;
textAlign: string;
verticalAlign: string;
startArrowHead: string;
endArrowHead: string;
}
canvas: {
theme: string,
viewBackgroundColor: string,
gridSize: number
};
setFillStyle (val:number): void;
setStrokeStyle (val:number): void;
setStrokeSharpness (val:number): void;
setFontFamily (val:number): void;
setTheme (val:number): void;
addToGroup (objectIds:[]):string;
toClipboard (templatePath?:string): void;
getElements ():ExcalidrawElement[];
getElement (id:string):ExcalidrawElement;
create (
params?: {
filename?: string,
foldername?:string,
templatePath?:string,
onNewPane?: boolean,
frontmatterKeys?:{
"excalidraw-plugin"?: "raw"|"parsed",
"excalidraw-link-prefix"?: string,
"excalidraw-link-brackets"?: boolean,
"excalidraw-url-prefix"?: string
}
}
):Promise<string>;
createSVG (templatePath?:string, embedFont?:boolean, exportSettings?:ExportSettings, loader?:EmbeddedFilesLoader):Promise<SVGSVGElement>;
createPNG (templatePath?:string, scale?:number, loader?:EmbeddedFilesLoader):Promise<any>;
wrapText (text:string, lineLen:number):string;
addRect (topX:number, topY:number, width:number, height:number):string;
addDiamond (topX:number, topY:number, width:number, height:number):string;
addEllipse (topX:number, topY:number, width:number, height:number):string;
addBlob (topX:number, topY:number, width:number, height:number):string;
addText (
topX:number,
topY:number,
text:string,
formatting?: {
wrapAt?:number,
width?:number,
height?:number,
textAlign?: string,
box?: boolean|"box"|"blob"|"ellipse"|"diamond",
boxPadding?: number
},
id?:string
):string;
addLine(points: [[x:number,y:number]]):string;
addArrow (
points: [[x:number,y:number]],
formatting?: {
startArrowHead?:string,
endArrowHead?:string,
startObjectId?:string,
endObjectId?:string
}
):string ;
addImage(topX:number, topY:number, imageFile: TFile):Promise<string>;
addLaTex(topX:number, topY:number, tex: string):Promise<string>;
connectObjects (
objectA: string,
connectionA: ConnectionPoint,
objectB: string,
connectionB: ConnectionPoint,
formatting?: {
numberOfPoints?: number,
startArrowHead?:string,
endArrowHead?:string,
padding?: number
}
):void;
clear (): void;
reset (): void;
isExcalidrawFile (f:TFile): boolean;
//view manipulation
targetView: ExcalidrawView;
setView (view:ExcalidrawView|"first"|"active"):ExcalidrawView;
getExcalidrawAPI ():any;
getViewElements ():ExcalidrawElement[];
deleteViewElements (el: ExcalidrawElement[]):boolean;
getViewSelectedElement ():ExcalidrawElement;
getViewSelectedElements ():ExcalidrawElement[];
viewToggleFullScreen (forceViewMode?:boolean):void;
connectObjectWithViewSelectedElement (
objectA:string,
connectionA: ConnectionPoint,
connectionB: ConnectionPoint,
formatting?: {
numberOfPoints?: number,
startArrowHead?:string,
endArrowHead?:string,
padding?: number
}
):boolean;
addElementsToView (repositionToCursor:boolean, save:boolean):Promise<boolean>;
onDropHook (data: {
ea: ExcalidrawAutomate,
event: React.DragEvent<HTMLDivElement>,
draggable: any, //Obsidian draggable object
type: "file"|"text"|"unknown",
payload: {
files: TFile[], //TFile[] array of dropped files
text: string, //string
},
excalidrawFile: TFile, //the file receiving the drop event
view: ExcalidrawView, //the excalidraw view receiving the drop
pointerPosition: {x:number, y:number} //the pointer position on canvas at the time of drop
}):boolean;
}
declare let window: ExcalidrawAutomate;
declare let window: any;
export async function initExcalidrawAutomate(plugin: ExcalidrawPlugin) {
export async function initExcalidrawAutomate(plugin: ExcalidrawPlugin):Promise<ExcalidrawAutomate> {
window.ExcalidrawAutomate = {
plugin: plugin,
elementsDict: {},
imagesDict: {},
style: {
strokeColor: "#000000",
backgroundColor: "transparent",
@@ -245,7 +249,7 @@ export async function initExcalidrawAutomate(plugin: ExcalidrawPlugin) {
return id;
},
async toClipboard(templatePath?:string) {
const template = templatePath ? (await getTemplate(templatePath)) : null;
const template = templatePath ? (await getTemplate(this.plugin,templatePath, false, new EmbeddedFilesLoader(this.plugin) )) : null;
let elements = template ? template.elements : [];
elements = elements.concat(this.getElements());
navigator.clipboard.writeText(
@@ -279,7 +283,9 @@ export async function initExcalidrawAutomate(plugin: ExcalidrawPlugin) {
}
}
):Promise<string> {
const template = params?.templatePath ? (await getTemplate(params.templatePath)) : null;
const template = params?.templatePath
? (await getTemplate(this.plugin,params.templatePath,true, new EmbeddedFilesLoader(this.plugin)))
: null;
let elements = template ? template.elements : [];
elements = elements.concat(this.getElements());
let frontmatter:string;
@@ -297,73 +303,92 @@ export async function initExcalidrawAutomate(plugin: ExcalidrawPlugin) {
} else {
frontmatter = template?.frontmatter ? template.frontmatter : FRONTMATTER;
}
const scene = {
type: "excalidraw",
version: 2,
source: "https://excalidraw.com",
elements: elements,
appState: {
theme: template?.appState?.theme ?? this.canvas.theme,
viewBackgroundColor: template?.appState?.viewBackgroundColor ?? this.canvas.viewBackgroundColor,
currentItemStrokeColor: template?.appState?.currentItemStrokeColor ?? this.style.strokeColor,
currentItemBackgroundColor: template?.appState?.currentItemBackgroundColor ?? this.style.backgroundColor,
currentItemFillStyle: template?.appState?.currentItemFillStyle ?? this.style.fillStyle,
currentItemStrokeWidth: template?.appState?.currentItemStrokeWidth ?? this.style.strokeWidth,
currentItemStrokeStyle: template?.appState?.currentItemStrokeStyle ?? this.style.strokeStyle,
currentItemRoughness: template?.appState?.currentItemRoughness ?? this.style.roughness,
currentItemOpacity: template?.appState?.currentItemOpacity ?? this.style.opacity,
currentItemFontFamily: template?.appState?.currentItemFontFamily ?? this.style.fontFamily,
currentItemFontSize: template?.appState?.currentItemFontSize ?? this.style.fontSize,
currentItemTextAlign: template?.appState?.currentItemTextAlign ?? this.style.textAlign,
currentItemStrokeSharpness: template?.appState?.currentItemStrokeSharpness ?? this.style.strokeSharpness,
currentItemStartArrowhead: template?.appState?.currentItemStartArrowhead ?? this.style.startArrowHead,
currentItemEndArrowhead: template?.appState?.currentItemEndArrowhead ?? this.style.endArrowHead,
currentItemLinearStrokeSharpness: template?.appState?.currentItemLinearStrokeSharpness ?? this.style.strokeSharpness,
gridSize: template?.appState?.gridSize ?? this.canvas.gridSize,
},
files: template?.files ?? {},
};
return plugin.createDrawing(
params?.filename ? params.filename + '.excalidraw.md' : this.plugin.getNextDefaultFilename(),
params?.onNewPane ? params.onNewPane : false,
params?.foldername ? params.foldername : this.plugin.settings.folder,
frontmatter + plugin.exportSceneToMD(
JSON.stringify({
this.plugin.settings.compatibilityMode
? JSON.stringify(scene,null,"\t")
: frontmatter + await plugin.exportSceneToMD(JSON.stringify(scene,null,"\t"))
);
},
async createSVG(
templatePath?:string,
embedFont:boolean = false,
exportSettings?:ExportSettings,
loader:EmbeddedFilesLoader = new EmbeddedFilesLoader(this.plugin)
):Promise<SVGSVGElement> {
const automateElements = this.getElements();
const template = templatePath ? (await getTemplate(this.plugin,templatePath,true,loader)) : null;
let elements = template ? template.elements : [];
elements = elements.concat(automateElements);
const svg = await getSVG(
{//createDrawing
type: "excalidraw",
version: 2,
source: "https://excalidraw.com",
elements: elements,
appState: {
theme: template ? template.appState.theme : this.canvas.theme,
viewBackgroundColor: template? template.appState.viewBackgroundColor : this.canvas.viewBackgroundColor,
currentItemStrokeColor: template? template.appState.currentItemStrokeColor : this.style.strokeColor,
currentItemBackgroundColor: template? template.appState.currentItemBackgroundColor : this.style.backgroundColor,
currentItemFillStyle: template? template.appState.currentItemFillStyle : this.style.fillStyle,
currentItemStrokeWidth: template? template.appState.currentItemStrokeWidth : this.style.strokeWidth,
currentItemStrokeStyle: template? template.appState.currentItemStrokeStyle : this.style.strokeStyle,
currentItemRoughness: template? template.appState.currentItemRoughness : this.style.roughness,
currentItemOpacity: template? template.appState.currentItemOpacity : this.style.opacity,
currentItemFontFamily: template? template.appState.currentItemFontFamily : this.style.fontFamily,
currentItemFontSize: template? template.appState.currentItemFontSize : this.style.fontSize,
currentItemTextAlign: template? template.appState.currentItemTextAlign : this.style.textAlign,
currentItemStrokeSharpness: template? template.appState.currentItemStrokeSharpness : this.style.strokeSharpness,
currentItemStartArrowhead: template? template.appState.currentItemStartArrowhead: this.style.startArrowHead,
currentItemEndArrowhead: template? template.appState.currentItemEndArrowhead : this.style.endArrowHead,
currentItemLinearStrokeSharpness: template? template.appState.currentItemLinearStrokeSharpness : this.style.strokeSharpness,
gridSize: template ? template.appState.gridSize : this.canvas.gridSize
}
},null,"\t"))
);
},
async createSVG(templatePath?:string):Promise<SVGSVGElement> {
const template = templatePath ? (await getTemplate(templatePath)) : null;
let elements = template ? template.elements : [];
elements = elements.concat(this.getElements());
return await ExcalidrawView.getSVG(
{//createDrawing
"type": "excalidraw",
"version": 2,
"source": "https://excalidraw.com",
"elements": elements,
"appState": {
"theme": template ? template.appState.theme : this.canvas.theme,
"viewBackgroundColor": template? template.appState.viewBackgroundColor : this.canvas.viewBackgroundColor
}
},//),
theme: template?.appState?.theme ?? this.canvas.theme,
viewBackgroundColor: template?.appState?.viewBackgroundColor ?? this.canvas.viewBackgroundColor,
},
files: template?.files ?? {}
},
{
withBackground: plugin.settings.exportWithBackground,
withTheme: plugin.settings.exportWithTheme
withBackground: (exportSettings === undefined) ? plugin.settings.exportWithBackground : exportSettings.withBackground,
withTheme: (exportSettings === undefined) ? plugin.settings.exportWithTheme : exportSettings.withTheme
}
)
)
return embedFont ? embedFontsInSVG(svg) : svg;
},
async createPNG(templatePath?:string, scale:number=1) {
const template = templatePath ? (await getTemplate(templatePath)) : null;
async createPNG(
templatePath?:string,
scale:number=1,
loader:EmbeddedFilesLoader = new EmbeddedFilesLoader(this.plugin)
) {
const automateElements = this.getElements();
const template = templatePath ? (await getTemplate(this.plugin,templatePath,true,loader)) : null;
let elements = template ? template.elements : [];
elements = elements.concat(this.getElements());
return ExcalidrawView.getPNG(
elements = elements.concat(automateElements);
return await getPNG(
{
"type": "excalidraw",
"version": 2,
"source": "https://excalidraw.com",
"elements": elements,
"appState": {
"theme": template ? template.appState.theme : this.canvas.theme,
"viewBackgroundColor": template? template.appState.viewBackgroundColor : this.canvas.viewBackgroundColor
}
type: "excalidraw",
version: 2,
source: "https://excalidraw.com",
elements: elements,
appState: {
theme: template?.appState?.theme ?? this.canvas.theme,
viewBackgroundColor: template?.appState?.viewBackgroundColor ?? this.canvas.viewBackgroundColor,
},
files: template?.files ?? {}
},
{
withBackground: plugin.settings.exportWithBackground,
@@ -463,12 +488,13 @@ export async function initExcalidrawAutomate(plugin: ExcalidrawPlugin) {
boxId = this.addRect(topX-boxPadding,topY-boxPadding,width+2*boxPadding,height+2*boxPadding);
}
}
const ea = window.ExcalidrawAutomate;
this.elementsDict[id] = {
text: text,
fontSize: window.ExcalidrawAutomate.style.fontSize,
fontFamily: window.ExcalidrawAutomate.style.fontFamily,
textAlign: formatting?.textAlign ? formatting.textAlign : window.ExcalidrawAutomate.style.textAlign,
verticalAlign: window.ExcalidrawAutomate.style.verticalAlign,
fontSize: ea.style.fontSize,
fontFamily: ea.style.fontFamily,
textAlign: formatting?.textAlign ? formatting.textAlign : ea.style.textAlign,
verticalAlign: ea.style.verticalAlign,
baseline: baseline,
... boxedElement(id,"text",topX,topY,width,height)
};
@@ -513,6 +539,46 @@ export async function initExcalidrawAutomate(plugin: ExcalidrawPlugin) {
}
return id;
},
async addImage(topX:number, topY:number, imageFile: TFile):Promise<string> {
const id = nanoid();
const loader = new EmbeddedFilesLoader(this.plugin)
const image = await loader.getObsidianImage(imageFile);
if(!image) return null;
this.imagesDict[image.fileId] = {
mimeType: image.mimeType,
id: image.fileId,
dataURL: image.dataURL,
created: image.created,
file: imageFile.path,
tex: null
}
if (Math.max(image.size.width,image.size.height) > MAX_IMAGE_SIZE) {
const scale = MAX_IMAGE_SIZE/Math.max(image.size.width,image.size.height);
image.size.width = scale*image.size.width;
image.size.height = scale*image.size.height;
}
this.elementsDict[id] = boxedElement(id,"image",topX,topY,image.size.width,image.size.height);
this.elementsDict[id].fileId = image.fileId;
this.elementsDict[id].scale = [1,1];
return id;
},
async addLaTex(topX:number, topY:number, tex:string):Promise<string> {
const id = nanoid();
const image = await tex2dataURL(tex, this.plugin);
if(!image) return null;
this.imagesDict[image.fileId] = {
mimeType: image.mimeType,
id: image.fileId,
dataURL: image.dataURL,
created: image.created,
file: null,
tex: tex
}
this.elementsDict[id] = boxedElement(id,"image",topX,topY,image.size.width,image.size.height);
this.elementsDict[id].fileId = image.fileId;
this.elementsDict[id].scale = [1,1];
return id;
},
connectObjects(objectA: string, connectionA: ConnectionPoint, objectB: string, connectionB: ConnectionPoint, formatting?:{numberOfPoints?: number,startArrowHead?:string,endArrowHead?:string, padding?: number}):void {
if(!(this.elementsDict[objectA] && this.elementsDict[objectB])) {
return;
@@ -552,6 +618,7 @@ export async function initExcalidrawAutomate(plugin: ExcalidrawPlugin) {
},
clear() {
this.elementsDict = {};
this.imagesDict = {};
},
reset() {
this.clear();
@@ -597,7 +664,7 @@ export async function initExcalidrawAutomate(plugin: ExcalidrawPlugin) {
errorMessage("targetView not set", "getExcalidrawAPI()");
return null;
}
return (this.targetView as ExcalidrawView).excalidrawRef.current;
return (this.targetView as ExcalidrawView).excalidrawAPI;
},
getViewElements ():ExcalidrawElement[] {
if (!this.targetView || !this.targetView?._loaded) {
@@ -682,11 +749,12 @@ export async function initExcalidrawAutomate(plugin: ExcalidrawPlugin) {
return false;
}
const elements = this.getElements();
return await this.targetView.addElements(elements,repositionToCursor,save);
return await this.targetView.addElements(elements,repositionToCursor,save,this.imagesDict);
},
onDropHook:null,
};
await initFonts();
return window.ExcalidrawAutomate;
}
export function destroyExcalidrawAutomate() {
@@ -702,6 +770,7 @@ function normalizeLinePoints(points:[[x:number,y:number]],box:{x:number,y:number
}
function boxedElement(id:string,eltype:any,x:number,y:number,w:number,h:number) {
const ea = window.ExcalidrawAutomate;
return {
id: id,
type: eltype,
@@ -709,15 +778,15 @@ function boxedElement(id:string,eltype:any,x:number,y:number,w:number,h:number)
y: y,
width: w,
height: h,
angle: window.ExcalidrawAutomate.style.angle,
strokeColor: window.ExcalidrawAutomate.style.strokeColor,
backgroundColor: window.ExcalidrawAutomate.style.backgroundColor,
fillStyle: window.ExcalidrawAutomate.style.fillStyle,
strokeWidth: window.ExcalidrawAutomate.style.strokeWidth,
storkeStyle: window.ExcalidrawAutomate.style.storkeStyle,
roughness: window.ExcalidrawAutomate.style.roughness,
opacity: window.ExcalidrawAutomate.style.opacity,
strokeSharpness: window.ExcalidrawAutomate.style.strokeSharpness,
angle: ea.style.angle,
strokeColor: ea.style.strokeColor,
backgroundColor: ea.style.backgroundColor,
fillStyle: ea.style.fillStyle,
strokeWidth: ea.style.strokeWidth,
storkeStyle: ea.style.storkeStyle,
roughness: ea.style.roughness,
opacity: ea.style.opacity,
strokeSharpness: ea.style.strokeSharpness,
seed: Math.floor(Math.random() * 100000),
version: 1,
versionNounce: 1,
@@ -780,27 +849,65 @@ export function measureText (newText:string, fontSize:number, fontFamily:number)
return {w: width, h: height, baseline: baseline };
};
async function getTemplate(fileWithPath: string):Promise<{elements: any,appState: any, frontmatter: string}> {
const app = window.ExcalidrawAutomate.plugin.app;
async function getTemplate(
plugin: ExcalidrawPlugin,
fileWithPath:string,
loadFiles:boolean = false,
loader:EmbeddedFilesLoader
):Promise<{
elements: any,
appState: any,
frontmatter: string,
files: any,
}> {
const app = plugin.app;
const vault = app.vault;
const file = app.metadataCache.getFirstLinkpathDest(normalizePath(fileWithPath),'');
const templatePath = normalizePath(fileWithPath);
const file = app.metadataCache.getFirstLinkpathDest(templatePath,'');
if(file && file instanceof TFile) {
const data = await vault.read(file);
const data = (await vault.read(file)).replaceAll("\r\n","\n").replaceAll("\r","\n");
let excalidrawData:ExcalidrawData = new ExcalidrawData(plugin);
if(file.extension === "excalidraw") {
await excalidrawData.loadLegacyData(data,file);
return {
elements: excalidrawData.scene.elements,
appState: excalidrawData.scene.appState,
frontmatter: "",
files: excalidrawData.scene.files,
};
}
const parsed = data.search("excalidraw-plugin: parsed\n")>-1 || data.search("excalidraw-plugin: locked\n")>-1; //locked for backward compatibility
await excalidrawData.loadData(data,file,parsed ? TextMode.parsed : TextMode.raw)
let trimLocation = data.search("# Text Elements\n");
if(trimLocation == -1) trimLocation = data.search("# Drawing\n");
const excalidrawData = JSON_parse(getJSON(data)[0]);
let scene = excalidrawData.scene;
if(loadFiles) {
await loader.loadSceneFiles(excalidrawData, null, (fileArray:any, view:any)=>{
if(!fileArray) return;
for(const f of fileArray) {
excalidrawData.scene.files[f.id] = f;
}
let foo;
[foo,scene] = scaleLoadedImage(excalidrawData.scene,fileArray);
},templatePath);
}
return {
elements: excalidrawData.elements,
appState: excalidrawData.appState,
frontmatter: data.substring(0,trimLocation)
elements: scene.elements,
appState: scene.appState,
frontmatter: data.substring(0,trimLocation),
files: scene.files,
};
};
return {
elements: [],
appState: {},
frontmatter: null
frontmatter: null,
files: [],
}
}

View File

@@ -1,4 +1,4 @@
import { App, normalizePath, TFile } from "obsidian";
import { App, TFile } from "obsidian";
import {
nanoid,
FRONTMATTER_KEY_CUSTOM_PREFIX,
@@ -11,8 +11,11 @@ import {
JSON_parse
} from "./constants";
import { TextMode } from "./ExcalidrawView";
import { wrapText } from "./Utils";
import { getAttachmentsFolderAndFilePath, getBinaryFileFromDataURL, getIMGFilename, isObsidianThemeDark, wrapText } from "./Utils";
import { ExcalidrawImageElement, FileId } from "@zsviczian/excalidraw/types/element/types";
import { BinaryFiles, SceneData } from "@zsviczian/excalidraw/types/types";
type SceneDataWithFiles = SceneData & { files: BinaryFiles};
declare module "obsidian" {
interface MetadataCache {
@@ -51,7 +54,7 @@ export const REGEX_LINK = {
export const REG_LINKINDEX_HYPERLINK = /^\w+:\/\//;
const DRAWING_REG = /\n%%\n# Drawing\n[^`]*(```json\n)([\s\S]*?)```/gm; //https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/182
const DRAWING_REG = /\n# Drawing\n[^`]*(```json\n)([\s\S]*?)```/gm; //https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/182
const DRAWING_REG_FALLBACK = /\n# Drawing\n(```json\n)?(.*)(```)?(%%)?/gm;
export function getJSON(data:string):[string,number] {
let res = data.matchAll(DRAWING_REG);
@@ -67,7 +70,14 @@ export function getJSON(data:string):[string,number] {
const result = parts.value[2];
return [result.substr(0,result.lastIndexOf("}")+1),parts.value.index]; //this is a workaround in case sync merges two files together and one version is still an old version without the ```codeblock
}
return [data,parts.value.index];
return [data,parts.value ? parts.value.index : 0];
}
export function getMarkdownDrawingSection(jsonString: string) {
return '%%\n# Drawing\n'
+ String.fromCharCode(96)+String.fromCharCode(96)+String.fromCharCode(96)+'json\n'
+ jsonString + '\n'
+ String.fromCharCode(96)+String.fromCharCode(96)+String.fromCharCode(96)+'\n%%';
}
export class ExcalidrawData {
@@ -81,10 +91,15 @@ export class ExcalidrawData {
private textMode: TextMode = TextMode.raw;
private plugin: ExcalidrawPlugin;
public loaded: boolean = false;
private files:Map<FileId,string> = null; //fileId, path
private equations:Map<FileId,string> = null; //fileId, path
private compatibilityMode:boolean = false;
constructor(plugin: ExcalidrawPlugin) {
this.plugin = plugin;
this.app = plugin.app;
this.files = new Map<FileId,string>();
this.equations = new Map<FileId,string>();
}
/**
@@ -96,6 +111,9 @@ export class ExcalidrawData {
this.loaded = false;
this.file = file;
this.textElements = new Map<string,{raw:string, parsed:string}>();
this.files.clear();
this.equations.clear();
this.compatibilityMode = false;
//I am storing these because if the settings change while a drawing is open parsing will run into errors during save
//The drawing will use these values until next drawing is loaded or this drawing is re-loaded
@@ -126,6 +144,15 @@ export class ExcalidrawData {
if (!this.scene) {
this.scene = JSON_parse(scene); //this is a workaround to address when files are mereged by sync and one version is still an old markdown without the codeblock ```
}
if(!this.scene.files) {
this.scene.files = {}; //loading legacy scenes that do not yet have the files attribute.
}
if(this.plugin.settings.matchThemeAlways) {
this.scene.appState.theme = isObsidianThemeDark() ? "dark" : "light";
}
data = data.substring(0,pos);
//The Markdown # Text Elements take priority over the JSON text elements. Assuming the scenario in which the link was updated due to filename changes
@@ -145,7 +172,7 @@ export class ExcalidrawData {
//iterating through all the text elements in .md
//Text elements always contain the raw value
const BLOCKREF_LEN:number = " ^12345678\n\n".length;
const res = data.matchAll(/\s\^(.{8})[\n]+/g);
let res = data.matchAll(/\s\^(.{8})[\n]+/g);
let parts;
while(!(parts = res.next()).done) {
const text = data.substring(position,parts.value.index);
@@ -158,6 +185,22 @@ export class ExcalidrawData {
position = parts.value.index + BLOCKREF_LEN;
}
data = data.substring(data.indexOf("# Embedded files\n")+"# Embedded files\n".length);
//Load Embedded files
const REG_FILEID_FILEPATH = /([\w\d]*):\s*\[\[([^\]]*)]]\n/gm;
res = data.matchAll(REG_FILEID_FILEPATH);
while(!(parts = res.next()).done) {
this.setFile(parts.value[1] as FileId,parts.value[2]);
}
//Load Equations
const REG_FILEID_EQUATION = /([\w\d]*):\s*\$\$(.*)(\$\$\s*\n)/gm;
res = data.matchAll(REG_FILEID_EQUATION);
while(!(parts = res.next()).done) {
this.setEquation(parts.value[1] as FileId,parts.value[2]);
}
//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();
@@ -167,12 +210,21 @@ export class ExcalidrawData {
}
public async loadLegacyData(data: string,file: TFile):Promise<boolean> {
this.compatibilityMode = true;
this.file = file;
this.textElements = new Map<string,{raw:string, parsed:string}>();
this.setShowLinkBrackets();
this.setLinkPrefix();
this.setUrlPrefix();
this.scene = JSON.parse(data);
if(!this.scene.files) {
this.scene.files = {}; //loading legacy scenes without the files element
}
if(this.plugin.settings.matchThemeAlways) {
this.scene.appState.theme = isObsidianThemeDark() ? "dark" : "light";
}
this.files.clear();
this.equations.clear();
this.findNewTextElementsInScene();
await this.setTextMode(TextMode.raw,true); //legacy files are always displayed in raw mode.
return true;
@@ -438,13 +490,74 @@ export class ExcalidrawData {
for(const key of this.textElements.keys()){
outString += this.textElements.get(key).raw+' ^'+key+'\n\n';
}
return outString + this.plugin.getMarkdownDrawingSection(JSON.stringify(this.scene,null,"\t"));
outString += (this.equations.size>0 || this.files.size>0) ? '\n# Embedded files\n' : '';
if(this.equations.size>0) {
for(const key of this.equations.keys()) {
outString += key +': $$'+this.equations.get(key) + '$$\n';
}
}
if(this.files.size>0) {
for(const key of this.files.keys()) {
outString += key +': [['+this.files.get(key) + ']]\n';
}
}
outString += (this.equations.size>0 || this.files.size>0) ? '\n' : '';
const sceneJSONstring = JSON.stringify(this.scene,null,"\t");
return outString + getMarkdownDrawingSection(sceneJSONstring);
}
private async syncFiles(scene:SceneDataWithFiles):Promise<boolean> {
let dirty = false;
//remove files and equations that no longer have a corresponding image element
const fileIds = (scene.elements.filter((e)=>e.type==="image") as ExcalidrawImageElement[]).map((e)=>e.fileId);
this.files.forEach((value,key)=>{
if(!fileIds.contains(key)) {
this.files.delete(key);
dirty = true;
}
});
this.equations.forEach((value,key)=>{
if(!fileIds.contains(key)) {
this.equations.delete(key);
dirty = true;
}
});
//check if there are any images that need to be processed in the new scene
if(!scene.files || scene.files == {}) return false;
for(const key of Object.keys(scene.files)) {
if(!(this.hasFile(key as FileId) || this.hasEquation(key as FileId))) {
dirty = true;
let fname = "Pasted Image "+window.moment().format("YYYYMMDDHHmmss_SSS");
switch(scene.files[key].mimeType) {
case "image/png": fname += ".png"; break;
case "image/jpeg": fname += ".jpg"; break;
case "image/svg+xml": fname += ".svg"; break;
case "image/gif": fname += ".gif"; break;
default: fname += ".png";
}
const [folder,filepath] = await getAttachmentsFolderAndFilePath(this.app,this.file.path,fname);
await this.app.vault.createBinary(filepath,getBinaryFileFromDataURL(scene.files[key].dataURL));
this.setFile(key as FileId,filepath);
}
}
return dirty;
}
public async syncElements(newScene:any):Promise<boolean> {
//console.log("Excalidraw.Data.syncElements()");
this.scene = newScene;//JSON_parse(newScene);
const result = this.setLinkPrefix() || this.setUrlPrefix() || this.setShowLinkBrackets();
this.scene = newScene;
let result = false;
if(!this.compatibilityMode) {
result = await this.syncFiles(newScene);
this.scene.files = {};
}
result = result || this.setLinkPrefix() || this.setUrlPrefix() || this.setShowLinkBrackets();
await this.updateTextElementsFromScene();
return result || this.findNewTextElementsInScene();
}
@@ -526,6 +639,74 @@ export class ExcalidrawData {
return showLinkBrackets != this.showLinkBrackets;
}
}
/*
// Files and equations 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
// This will not work if pasting from one vault to another, but for the most common usecase
// of copying an image or equation from one drawing to another within the same vault
// this is going to do the job
*/
public setFile(fileId:FileId, path:string) {
//always store absolute path because in case of paste, relative path may not resolve ok
const file = this.app.metadataCache.getFirstLinkpathDest(path,this.file.path);
const p = file?.path ?? path;
this.files.set(fileId,p);
this.plugin.filesMaster.set(fileId,p);
}
public getFile(fileId:FileId) {
return this.files.get(fileId);
}
public getFileEntries() {
return this.files.entries();
}
public deleteFile(fileId:FileId) {
this.files.delete(fileId);
//deliberately not deleting from plugin.filesMaster
//could be present in other drawings as well
}
//Image copy/paste support
public hasFile(fileId:FileId):boolean {
if(this.files.has(fileId)) return true;
if(this.plugin.filesMaster.has(fileId)) {
this.files.set(fileId,this.plugin.filesMaster.get(fileId));
return true;
}
return false;
}
public setEquation(fileId:FileId, equation:string) {
this.equations.set(fileId,equation);
this.plugin.equationsMaster.set(fileId,equation);
}
public getEquation(fileId: FileId) {
return this.equations.get(fileId);
}
public getEquationEntries() {
return this.equations.entries();
}
public deleteEquation(fileId:FileId) {
this.equations.delete(fileId);
//deliberately not deleting from plugin.equationsMaster
//could be present in other drawings as well
}
//Image copy/paste support
public hasEquation(fileId:FileId):boolean {
if(this.equations.has(fileId)) return true;
if(this.plugin.equationsMaster.has(fileId)) {
this.equations.set(fileId,this.plugin.equationsMaster.get(fileId));
return true;
}
return false;
}
}

View File

@@ -10,17 +10,16 @@ import {
import * as React from "react";
import * as ReactDOM from "react-dom";
import Excalidraw, {exportToSvg, getSceneVersion} from "@zsviczian/excalidraw";
import { ExcalidrawElement,ExcalidrawTextElement } from "@zsviczian/excalidraw/types/element/types";
import { ExcalidrawElement,ExcalidrawImageElement,ExcalidrawTextElement, FileId } from "@zsviczian/excalidraw/types/element/types";
import {
AppState,
BinaryFileData,
LibraryItems
} from "@zsviczian/excalidraw/types/types";
import {
VIEW_TYPE_EXCALIDRAW,
ICON_NAME,
EXCALIDRAW_LIB_HEADER,
VIRGIL_FONT,
CASCADIA_FONT,
DISK_ICON_NAME,
PNG_ICON_NAME,
SVG_ICON_NAME,
@@ -28,17 +27,18 @@ import {
TEXT_DISPLAY_RAW_ICON_NAME,
TEXT_DISPLAY_PARSED_ICON_NAME,
FULLSCREEN_ICON_NAME,
JSON_parse
JSON_parse,
IMAGE_TYPES
} from './constants';
import ExcalidrawPlugin from './main';
import {estimateBounds, ExcalidrawAutomate, repositionElementsToCursor} from './ExcalidrawAutomate';
import { repositionElementsToCursor} from './ExcalidrawAutomate';
import { t } from "./lang/helpers";
import { ExcalidrawData, REG_LINKINDEX_HYPERLINK, REGEX_LINK } from "./ExcalidrawData";
import { checkAndCreateFolder, download, getNewOrAdjacentLeaf, getNewUniqueFilepath, rotatedDimensions, splitFolderAndFilename, viewportCoordsToSceneCoords } from "./Utils";
import { checkAndCreateFolder, download, embedFontsInSVG, getIMGFilename, getNewOrAdjacentLeaf, getNewUniqueFilepath, getPNG, getSVG, rotatedDimensions, scaleLoadedImage, splitFolderAndFilename, svgToBase64, viewportCoordsToSceneCoords } from "./Utils";
import { Prompt } from "./Prompt";
import { ClipboardData } from "@zsviczian/excalidraw/types/clipboard";
declare let window: ExcalidrawAutomate;
import { updateEquation } from "./LaTeX";
import { EmbeddedFilesLoader } from "./EmbeddedFileLoader";
export enum TextMode {
parsed,
@@ -56,14 +56,32 @@ export interface ExportSettings {
const REG_LINKINDEX_INVALIDCHARS = /[<>:"\\|?*]/g;
export const addFiles = (files:any, view: ExcalidrawView) => {
if(files.length === 0) return;
const [dirty, scene] = scaleLoadedImage(view.getScene(),files);
if(dirty) {
view.excalidrawAPI.updateScene({
elements: scene.elements,
appState: scene.appState,
commitToHistory: false,
});
}
view.excalidrawAPI.addFiles(files);
}
export default class ExcalidrawView extends TextFileView {
private excalidrawData: ExcalidrawData;
private getScene: Function = null;
public getScene: Function = null;
public addElements: Function = null; //add elements to the active Excalidraw drawing
private getSelectedTextElement: Function = null;
private getSelectedImageElement: Function = null;
public addText:Function = null;
private refresh: Function = null;
public excalidrawRef: React.MutableRefObject<any> = null;
public excalidrawAPI: any = null;
private excalidrawWrapperRef: React.MutableRefObject<any> = null;
private justLoaded: boolean = false;
private plugin: ExcalidrawPlugin;
@@ -79,7 +97,6 @@ export default class ExcalidrawView extends TextFileView {
private ctrlKeyDown = false;
private shiftKeyDown = false;
private altKeyDown = false;
private mouseEvent:any = null;
id: string = (this.leaf as any).id;
@@ -105,40 +122,29 @@ export default class ExcalidrawView extends TextFileView {
if (!this.getScene) return false;
scene = this.getScene();
}
const filepath = this.file.path.substring(0,this.file.path.lastIndexOf(this.compatibilityMode ? '.excalidraw':'.md')) + '.svg';
const filepath = getIMGFilename(this.file.path,'svg'); //.substring(0,this.file.path.lastIndexOf(this.compatibilityMode ? '.excalidraw':'.md')) + '.svg';
const file = this.app.vault.getAbstractFileByPath(normalizePath(filepath));
(async () => {
const exportSettings: ExportSettings = {
withBackground: this.plugin.settings.exportWithBackground,
withTheme: this.plugin.settings.exportWithTheme
}
const svg = await ExcalidrawView.getSVG(scene,exportSettings);
const svg = await getSVG(scene,exportSettings);
if(!svg) return;
let serializer =new XMLSerializer();
const svgString = serializer.serializeToString(ExcalidrawView.embedFontsInSVG(svg));
const svgString = serializer.serializeToString(embedFontsInSVG(svg));
if(file && file instanceof TFile) await this.app.vault.modify(file,svgString);
else await this.app.vault.create(filepath,svgString);
})();
}
public static embedFontsInSVG(svg:SVGSVGElement):SVGSVGElement {
//replace font references with base64 fonts
const includesVirgil = svg.querySelector("text[font-family^='Virgil']") != null;
const includesCascadia = svg.querySelector("text[font-family^='Cascadia']") != null;
const defs = svg.querySelector("defs");
if (defs && (includesCascadia || includesVirgil)) {
defs.innerHTML = "<style>" + (includesVirgil ? VIRGIL_FONT : "") + (includesCascadia ? CASCADIA_FONT : "")+"</style>";
}
return svg;
}
public savePNG(scene?: any) {
if(!scene) {
if (!this.getScene) return false;
scene = this.getScene();
}
const filepath = this.file.path.substring(0,this.file.path.lastIndexOf(this.compatibilityMode ? '.excalidraw':'.md')) + '.png';
const filepath = getIMGFilename(this.file.path,'png'); //this.file.path.substring(0,this.file.path.lastIndexOf(this.compatibilityMode ? '.excalidraw':'.md')) + '.png';
const file = this.app.vault.getAbstractFileByPath(normalizePath(filepath));
(async () => {
@@ -146,7 +152,7 @@ export default class ExcalidrawView extends TextFileView {
withBackground: this.plugin.settings.exportWithBackground,
withTheme: this.plugin.settings.exportWithTheme
}
const png = await ExcalidrawView.getPNG(scene,exportSettings,this.plugin.settings.pngExportScale);
const png = await getPNG(scene,exportSettings,this.plugin.settings.pngExportScale);
if(!png) return;
if(file && file instanceof TFile) await this.app.vault.modifyBinary(file,await png.arrayBuffer());
else await this.app.vault.createBinary(filepath,await png.arrayBuffer());
@@ -157,11 +163,12 @@ export default class ExcalidrawView extends TextFileView {
if(!this.getScene) return;
this.preventReload = preventReload;
this.dirty = null;
const scene = this.getScene();
if(this.compatibilityMode) {
await this.excalidrawData.syncElements(this.getScene());
await this.excalidrawData.syncElements(scene);
} else {
if(await this.excalidrawData.syncElements(this.getScene()) && !this.autosaving) {
if(await this.excalidrawData.syncElements(scene) && !this.autosaving) {
await this.loadDrawing(false);
}
}
@@ -175,24 +182,42 @@ export default class ExcalidrawView extends TextFileView {
//console.log("ExcalidrawView.getViewData()");
if(!this.getScene) return this.data;
if(!this.excalidrawData.loaded) return this.data;
const scene = this.getScene();
if(!this.compatibilityMode) {
let trimLocation = this.data.search(/(^%%\n)?# Text Elements\n/m);
if(trimLocation == -1) trimLocation = this.data.search(/(%%\n)?# Drawing\n/);
if(trimLocation == -1) return this.data;
const scene = this.excalidrawData.scene;
if(!this.autosaving) {
if(this.plugin.settings.autoexportSVG) this.saveSVG(scene);
if(this.plugin.settings.autoexportPNG) this.savePNG(scene);
if(this.plugin.settings.autoexportExcalidraw) this.saveExcalidraw(scene);
}
const header = this.data.substring(0,trimLocation)
let header = this.data.substring(0,trimLocation)
.replace(/excalidraw-plugin:\s.*\n/,FRONTMATTER_KEY+": " + ( (this.textMode == TextMode.raw) ? "raw\n" : "parsed\n"));
if (header.search(/cssclass:[\s]*excalidraw-hide-preview-text/) === -1) {
header = header.replace(/(excalidraw-plugin:\s.*\n)/,"$1cssclass: excalidraw-hide-preview-text\n");
}
const ext = this.plugin.settings.autoexportSVG
? "svg"
: ( this.plugin.settings.autoexportPNG
? "png"
: null);
if(ext) {
const REG_IMG = /(^---[\w\W]*?---\n)(!\[\[.*?]]\n(%%\n)?)/m; //(%%\n)? because of 1.4.8-beta... to be backward compatible with anyone who installed that version
if(header.match(REG_IMG)) {
header = header.replace(REG_IMG,"$1![["+getIMGFilename(this.file.path,ext)+"]]\n");
} else {
header = header.replace(/(^---[\w\W]*?---\n)/m, "$1![["+getIMGFilename(this.file.path,ext)+"]]\n");
}
}
return header + this.excalidrawData.generateMD();
}
if(this.compatibilityMode) {
const scene = this.excalidrawData.scene;
if(!this.autosaving) {
if(this.plugin.settings.autoexportSVG) this.saveSVG(scene);
if(this.plugin.settings.autoexportPNG) this.savePNG(scene);
@@ -203,61 +228,90 @@ export default class ExcalidrawView extends TextFileView {
}
async handleLinkClick(view: ExcalidrawView, ev:MouseEvent) {
let text:string = (this.textMode == TextMode.parsed)
? this.excalidrawData.getRawText(this.getSelectedTextElement().id)
: this.getSelectedTextElement().text;
if(!text) {
const selectedText = this.getSelectedTextElement();
let file = null;
let lineNum = 0;
let linkText:string = null;
if(selectedText?.id) {
linkText = (this.textMode == TextMode.parsed)
? this.excalidrawData.getRawText(selectedText.id)
: selectedText.text;
linkText = linkText.replaceAll("\n",""); //https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/187
if(linkText.match(REG_LINKINDEX_HYPERLINK)) {
window.open(linkText,"_blank");
return;
}
const parts = REGEX_LINK.getRes(linkText).next();
if(!parts.value) {
const tags = linkText.matchAll(/#([\p{Letter}\p{Emoji_Presentation}\p{Number}\/_-]+)/ug).next();
if(!tags.value || tags.value.length<2) {
new Notice(t("TEXT_ELEMENT_EMPTY"),4000);
return;
}
const search=this.app.workspace.getLeavesOfType("search");
if(search.length==0) return;
//@ts-ignore
search[0].view.setQuery("tag:"+tags.value[1]);
this.app.workspace.revealLeaf(search[0]);
if(document.fullscreenElement === this.contentEl) {
document.exitFullscreen();
this.zoomToFit();
}
return;
}
linkText = REGEX_LINK.getLink(parts);
if(linkText.match(REG_LINKINDEX_HYPERLINK)) {
window.open(linkText,"_blank");
return;
}
if(linkText.search("#")>-1) {
let t;
[t,lineNum] = await this.excalidrawData.getTransclusion(linkText);
linkText = linkText.substring(0,linkText.search("#"));
}
if(linkText.match(REG_LINKINDEX_INVALIDCHARS)) {
new Notice(t("FILENAME_INVALID_CHARS"),4000);
return;
}
file = view.app.metadataCache.getFirstLinkpathDest(linkText,view.file.path);
if (!ev.altKey && !file) {
new Notice(t("FILE_DOES_NOT_EXIST"), 4000);
return;
}
} else {
const selectedImage = this.getSelectedImageElement();
if(selectedImage?.id) {
if(this.excalidrawData.hasEquation(selectedImage.fileId)) {
const equation = this.excalidrawData.getEquation(selectedImage.fileId);
const prompt = new Prompt(this.app, t("ENTER_LATEX"),equation,'');
prompt.openAndGetValue( async (formula:string)=> {
if(!formula) return;
this.excalidrawData.setEquation(selectedImage.fileId,formula);
await this.save(true);
await updateEquation(formula,selectedImage.fileId,this,addFiles,this.plugin);
});
return;
}
await this.save(true); //in case pasted images haven't been saved yet
if(this.excalidrawData.hasFile(selectedImage.fileId)) {
linkText = this.excalidrawData.getFile(selectedImage.fileId);
}
}
}
if(!linkText) {
new Notice(t("LINK_BUTTON_CLICK_NO_TEXT"),20000);
return;
}
text = text.replaceAll("\n",""); //https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/187
if(text.match(REG_LINKINDEX_HYPERLINK)) {
window.open(text,"_blank");
return;
}
const parts = REGEX_LINK.getRes(text).next();
if(!parts.value) {
const tags = text.matchAll(/#([\p{Letter}\p{Emoji_Presentation}\p{Number}\/_-]+)/ug).next();
if(!tags.value || tags.value.length<2) {
new Notice(t("TEXT_ELEMENT_EMPTY"),4000);
return;
}
const search=this.app.workspace.getLeavesOfType("search");
if(search.length==0) return;
//@ts-ignore
search[0].view.setQuery("tag:"+tags.value[1]);
this.app.workspace.revealLeaf(search[0]);
if(document.fullscreenElement === this.contentEl) {
document.exitFullscreen();
this.zoomToFit();
}
return;
}
text = REGEX_LINK.getLink(parts);
if(text.match(REG_LINKINDEX_HYPERLINK)) {
window.open(text,"_blank");
return;
}
let lineNum = null;
if(text.search("#")>-1) {
let t;
[t,lineNum] = await this.excalidrawData.getTransclusion(text);
text = text.substring(0,text.search("#"));
}
if(text.match(REG_LINKINDEX_INVALIDCHARS)) {
new Notice(t("FILENAME_INVALID_CHARS"),4000);
return;
}
const file = view.app.metadataCache.getFirstLinkpathDest(text,view.file.path);
if (!ev.altKey && !file) {
new Notice(t("FILE_DOES_NOT_EXIST"), 4000);
return;
}
try {
const f = view.file;
if(ev.shiftKey && document.fullscreenElement === this.contentEl) {
@@ -266,7 +320,11 @@ export default class ExcalidrawView extends TextFileView {
}
const leaf = ev.shiftKey ? getNewOrAdjacentLeaf(this.plugin,view.leaf) : view.leaf;
view.app.workspace.setActiveLeaf(leaf);
leaf.view.app.workspace.openLinkText(text,view.file.path);
if(file) {
leaf.openFile(file,{eState: {line: lineNum-1}}); //if file exists open file and jump to reference
} else {
leaf.view.app.workspace.openLinkText(linkText,view.file.path);
}
} catch (e) {
new Notice(e,4000);
}
@@ -322,7 +380,7 @@ export default class ExcalidrawView extends TextFileView {
}
if(reload) {
await this.save(false);
this.excalidrawRef.current.history.clear(); //to avoid undo replacing links with parsed text
this.excalidrawAPI.history.clear(); //to avoid undo replacing links with parsed text
}
}
@@ -352,6 +410,10 @@ export default class ExcalidrawView extends TextFileView {
this.preventReload = false;
return;
}
if(this.compatibilityMode) {
this.dirty = null;
return;
}
if(!this.excalidrawRef) return;
if(!this.file) return;
if(file) this.data = await this.app.vault.cachedRead(file);
@@ -364,8 +426,8 @@ export default class ExcalidrawView extends TextFileView {
// clear the view content
clear() {
if(!this.excalidrawRef) return;
this.excalidrawRef.current.resetScene();
this.excalidrawRef.current.history.clear();
this.excalidrawAPI.resetScene();
this.excalidrawAPI.history.clear();
}
async setViewData (data: string, clear: boolean = false) {
@@ -373,7 +435,7 @@ export default class ExcalidrawView extends TextFileView {
data = this.data = data.replaceAll("\r\n","\n").replaceAll("\r","\n");
this.app.workspace.onLayoutReady(async ()=>{
this.dirty = null;
this.compatibilityMode = this.file.extension == "excalidraw";
this.compatibilityMode = this.file.extension === "excalidraw";
await this.plugin.loadSettings();
this.plugin.opencount++;
if(this.compatibilityMode) {
@@ -407,31 +469,41 @@ export default class ExcalidrawView extends TextFileView {
*
* @param justloaded - a flag to trigger zoom to fit after the drawing has been loaded
*/
private async loadDrawing(justloaded:boolean) {
private async loadDrawing(justloaded:boolean) {
const excalidrawData = this.excalidrawData.scene;
this.justLoaded = justloaded;
if(this.excalidrawRef) {
const viewModeEnabled = this.excalidrawRef.current.getAppState().viewModeEnabled;
const zenModeEnabled = this.excalidrawRef.current.getAppState().zenModeEnabled;
this.excalidrawRef.current.updateScene({
const viewModeEnabled = this.excalidrawAPI.getAppState().viewModeEnabled;
const zenModeEnabled = this.excalidrawAPI.getAppState().zenModeEnabled;
this.excalidrawAPI.updateScene({
elements: excalidrawData.elements,
appState: {
zenModeEnabled: zenModeEnabled,
viewModeEnabled: viewModeEnabled,
... excalidrawData.appState,
},
files: excalidrawData.files,
commitToHistory: true,
});
if((this.app.workspace.activeLeaf === this.leaf) && this.excalidrawWrapperRef) {
this.excalidrawWrapperRef.current.focus();
}
const loader = new EmbeddedFilesLoader(this.plugin);
loader.loadSceneFiles(
this.excalidrawData,
this,
(files:any, view:ExcalidrawView) => addFiles(files,view),
this.file?.path
);
} else {
this.instantiateExcalidraw({
elements: excalidrawData.elements,
appState: excalidrawData.appState,
files: excalidrawData.files,
libraryItems: await this.getLibrary(),
});
}
//files are loaded on excalidrawRef readyPromise
}
}
//Compatibility mode with .excalidraw files
@@ -513,12 +585,12 @@ export default class ExcalidrawView extends TextFileView {
.setIcon(PNG_ICON_NAME)
.onClick( async (ev)=> {
if(!this.getScene || !this.file) return;
if(ev.ctrlKey || ev.metaKey) {
if(ev.ctrlKey||ev.metaKey) {
const exportSettings: ExportSettings = {
withBackground: this.plugin.settings.exportWithBackground,
withTheme: this.plugin.settings.exportWithTheme
}
const png = await ExcalidrawView.getPNG(this.getScene(),exportSettings,this.plugin.settings.pngExportScale);
const png = await getPNG(this.getScene(),exportSettings,this.plugin.settings.pngExportScale);
if(!png) return;
let reader = new FileReader();
reader.readAsDataURL(png);
@@ -538,15 +610,15 @@ export default class ExcalidrawView extends TextFileView {
.setIcon(SVG_ICON_NAME)
.onClick(async (ev)=> {
if(!this.getScene || !this.file) return;
if(ev.ctrlKey || ev.metaKey) {
if(ev.ctrlKey||ev.metaKey) {
const exportSettings: ExportSettings = {
withBackground: this.plugin.settings.exportWithBackground,
withTheme: this.plugin.settings.exportWithTheme
}
let svg = await ExcalidrawView.getSVG(this.getScene(),exportSettings);
let svg = await getSVG(this.getScene(),exportSettings);
if(!svg) return null;
svg = ExcalidrawView.embedFontsInSVG(svg);
download("data:image/svg+xml;base64",btoa(unescape(encodeURIComponent(svg.outerHTML))),this.file.basename+'.svg');
svg = embedFontsInSVG(svg);
download(null,svgToBase64(svg.outerHTML),this.file.basename+'.svg');
return;
}
this.saveSVG()
@@ -568,13 +640,51 @@ export default class ExcalidrawView extends TextFileView {
const reactElement = React.createElement(() => {
let previousSceneVersion = 0;
let currentPosition = {x:0, y:0};
const excalidrawRef = React.useRef(null);
const excalidrawWrapperRef = React.useRef(null);
const [dimensions, setDimensions] = React.useState({
width: undefined,
height: undefined
});
//excalidrawRef readypromise based on
//https://codesandbox.io/s/eexcalidraw-resolvable-promise-d0qg3?file=/src/App.js:167-760
const resolvablePromise = () => {
let resolve;
let reject;
const promise = new Promise((_resolve, _reject) => {
resolve = _resolve;
reject = _reject;
});
//@ts-ignore
promise.resolve = resolve;
//@ts-ignore
promise.reject = reject;
return promise;
};
// To memoize value between rerenders
const excalidrawRef = React.useMemo(
() => ({
current: {
readyPromise: resolvablePromise()
}
}),
[]
);
React.useEffect(() => {
excalidrawRef.current.readyPromise.then((api) => {
this.excalidrawAPI = api;
const loader = new EmbeddedFilesLoader(this.plugin);
loader.loadSceneFiles(
this.excalidrawData,
this,
(files:any, view:ExcalidrawView)=>addFiles(files,view),
this.file?.path
);
});
}, [excalidrawRef]);
this.excalidrawRef = excalidrawRef;
this.excalidrawWrapperRef = excalidrawWrapperRef;
@@ -596,24 +706,23 @@ export default class ExcalidrawView extends TextFileView {
return () => window.removeEventListener("resize", onResize);
}, [excalidrawWrapperRef]);
this.getSelectedTextElement = ():{id: string, text:string} => {
if(!excalidrawRef?.current) return {id:null,text:null};
if(this.excalidrawRef.current.getAppState().viewModeEnabled) {
if(this.excalidrawAPI.getAppState().viewModeEnabled) {
if(selectedTextElement) {
const retval = selectedTextElement;
selectedTextElement == null;
selectedTextElement = null;
return retval;
}
return {id:null,text:null};
}
const selectedElement = excalidrawRef.current.getSceneElements().filter((el:any)=>el.id==Object.keys(excalidrawRef.current.getAppState().selectedElementIds)[0]);
const selectedElement = this.excalidrawAPI.getSceneElements().filter((el:any)=>el.id==Object.keys(this.excalidrawAPI.getAppState().selectedElementIds)[0]);
if(selectedElement.length==0) return {id:null,text:null};
if(selectedElement[0].type == "text") return {id:selectedElement[0].id, text:selectedElement[0].text}; //a text element was selected. Return text
if(selectedElement[0].groupIds.length == 0) return {id:null,text:null}; //is the selected element part of a group?
const group = selectedElement[0].groupIds[0]; //if yes, take the first group it is part of
const textElement = excalidrawRef
.current
const textElement = this
.excalidrawAPI
.getSceneElements()
.filter((el:any)=>el.groupIds?.includes(group))
.filter((el:any)=>el.type=="text"); //filter for text elements of the group
@@ -621,23 +730,48 @@ export default class ExcalidrawView extends TextFileView {
return {id:selectedElement[0].id, text:selectedElement[0].text}; //return text element text
};
this.getSelectedImageElement = ():{id: string, fileId:string} => {
if(!excalidrawRef?.current) return {id:null,fileId:null};
if(this.excalidrawAPI.getAppState().viewModeEnabled) {
if(selectedImageElement) {
const retval = selectedImageElement;
selectedImageElement = null;
return retval;
}
return {id:null,fileId:null};
}
const selectedElement = this.excalidrawAPI.getSceneElements().filter((el:any)=>el.id==Object.keys(this.excalidrawAPI.getAppState().selectedElementIds)[0]);
if(selectedElement.length===0) return {id:null,fileId:null};
if(selectedElement[0].type == "image") return {id:selectedElement[0].id, fileId:selectedElement[0].fileId}; //an image element was selected. Return fileId
if(selectedElement[0].groupIds.length === 0) return {id:null,fileId:null}; //is the selected element part of a group?
const group = selectedElement[0].groupIds[0]; //if yes, take the first group it is part of
const imageElement = this
.excalidrawAPI
.getSceneElements()
.filter((el:any)=>el.groupIds?.includes(group))
.filter((el:any)=>el.type=="image"); //filter for Image elements of the group
if(imageElement.length===0) return {id:null,fileId:null}; //the group had no image element member
return {id:selectedElement[0].id, fileId:selectedElement[0].fileId}; //return image element fileId
};
this.addText = (text:string, fontFamily?:1|2|3) => {
if(!excalidrawRef?.current) {
return;
}
const el: ExcalidrawElement[] = excalidrawRef.current.getSceneElements();
const st: AppState = excalidrawRef.current.getAppState();
window.ExcalidrawAutomate.reset();
window.ExcalidrawAutomate.style.strokeColor = st.currentItemStrokeColor;
window.ExcalidrawAutomate.style.opacity = st.currentItemOpacity;
window.ExcalidrawAutomate.style.fontFamily = fontFamily ? fontFamily: st.currentItemFontFamily;
window.ExcalidrawAutomate.style.fontSize = st.currentItemFontSize;
window.ExcalidrawAutomate.style.textAlign = st.currentItemTextAlign;
const id:string = window.ExcalidrawAutomate.addText(currentPosition.x, currentPosition.y, text);
this.addElements(window.ExcalidrawAutomate.getElements(),false,true);
const el: ExcalidrawElement[] = this.excalidrawAPI.getSceneElements();
const st: AppState = this.excalidrawAPI.getAppState();
const ea = this.plugin.ea;
ea.reset();
ea.style.strokeColor = st.currentItemStrokeColor;
ea.style.opacity = st.currentItemOpacity;
ea.style.fontFamily = fontFamily ? fontFamily: st.currentItemFontFamily;
ea.style.fontSize = st.currentItemFontSize;
ea.style.textAlign = st.currentItemTextAlign;
const id:string = ea.addText(currentPosition.x, currentPosition.y, text);
this.addElements(ea.getElements(),false,true);
}
this.addElements = async (newElements:ExcalidrawElement[],repositionToCursor:boolean = false, save:boolean=false):Promise<boolean> => {
this.addElements = async (newElements:ExcalidrawElement[],repositionToCursor:boolean = false, save:boolean=false, images:any):Promise<boolean> => {
if(!excalidrawRef?.current) return false;
const textElements = newElements.filter((el)=>el.type=="text");
@@ -649,14 +783,33 @@ export default class ExcalidrawView extends TextFileView {
}
};
const el: ExcalidrawElement[] = excalidrawRef.current.getSceneElements();
const st: AppState = excalidrawRef.current.getAppState();
const el: ExcalidrawElement[] = this.excalidrawAPI.getSceneElements();
let st: AppState = this.excalidrawAPI.getAppState();
if(repositionToCursor) newElements = repositionElementsToCursor(newElements,currentPosition,true);
this.excalidrawRef.current.updateScene({
this.excalidrawAPI.updateScene({
elements: el.concat(newElements),
appState: st,
commitToHistory: true,
});
if(images) {
let files:BinaryFileData[] = [];
Object.keys(images).forEach((k)=>{
files.push({
mimeType :images[k].mimeType,
id: images[k].id,
dataURL: images[k].dataURL,
created: images[k].created
});
if(images[k].file) {
this.excalidrawData.setFile(images[k].id,images[k].file);
}
if(images[k].tex) {
this.excalidrawData.setEquation(images[k].id,images[k].tex);
}
});
this.excalidrawAPI.addFiles(files);
}
if(save) this.save(); else this.dirty = this.file?.path;
return true;
};
@@ -665,8 +818,16 @@ export default class ExcalidrawView extends TextFileView {
if(!excalidrawRef?.current) {
return null;
}
const el: ExcalidrawElement[] = excalidrawRef.current.getSceneElements();
const st: AppState = excalidrawRef.current.getAppState();
const el: ExcalidrawElement[] = this.excalidrawAPI.getSceneElements();
const st: AppState = this.excalidrawAPI.getAppState();
const files = this.excalidrawAPI.getFiles();
if(files) {
const imgIds = el.filter((e)=>e.type==="image").map((e:any)=>e.fileId);
const toDelete = Object.keys(files).filter((k)=>!imgIds.contains(k));
toDelete.forEach((k)=>delete files[k]);
}
return {
type: "excalidraw",
version: 2,
@@ -690,29 +851,34 @@ export default class ExcalidrawView extends TextFileView {
currentItemEndArrowhead: st.currentItemEndArrowhead,
currentItemLinearStrokeSharpness: st.currentItemLinearStrokeSharpness,
gridSize: st.gridSize,
}
},
files: files,
};
};
this.refresh = () => {
if(!excalidrawRef?.current) return;
excalidrawRef.current.refresh();
this.excalidrawAPI.refresh();
};
//variables used to handle click events in view mode
let selectedTextElement:{id:string,text:string} = null;
let selectedImageElement:{id:string,fileId:string} = null;
let timestamp = 0;
let blockOnMouseButtonDown = false;
const getElementsAtPointer = (pointer:any, elements:ExcalidrawElement[], type:string):ExcalidrawElement[] => {
return elements.filter((e:ExcalidrawElement)=>{
if (e.type !== type) return false;
const [x,y,w,h] = rotatedDimensions(e);
return x<=pointer.x && x+w>=pointer.x
&& y<=pointer.y && y+h>=pointer.y;
});
}
const getTextElementAtPointer = (pointer:any) => {
const elements = this.excalidrawRef.current.getSceneElements()
.filter((e:ExcalidrawElement)=>{
if (e.type !== "text") return false;
const [x,y,w,h] = rotatedDimensions(e);
return x<=pointer.x && x+w>=pointer.x
&& y<=pointer.y && y+h>=pointer.y;
});
if(elements.length==0) return null;
const elements = getElementsAtPointer(pointer,this.excalidrawAPI.getSceneElements(),'text') as ExcalidrawTextElement[];
if(elements.length==0) return {id:null, text:null};
if(elements.length===1) return {id:elements[0].id,text:elements[0].text};
//if more than 1 text elements are at the location, look for one that has a link
const elementsWithLinks = elements.filter((e:ExcalidrawTextElement)=> {
@@ -730,6 +896,13 @@ export default class ExcalidrawView extends TextFileView {
//if there are still multiple text elements with links on top of each other, return the first
return {id:elementsWithLinks[0].id,text:elementsWithLinks[0].text};
}
const getImageElementAtPointer = (pointer:any) => {
const elements = getElementsAtPointer(pointer,this.excalidrawAPI.getSceneElements(),'image') as ExcalidrawImageElement[];
if(elements.length===0) return {id:null, fileId:null};
if(elements.length>=1) return {id:elements[0].id,fileId:elements[0].fileId};
//if more than 1 image elements are at the location, return the first
}
let hoverPoint = {x:0,y:0};
let hoverPreviewTarget:EventTarget = null;
@@ -747,8 +920,6 @@ export default class ExcalidrawView extends TextFileView {
const dropAction = (transfer: DataTransfer) => {
// Return a 'copy' or 'link' action according to the content types, or undefined if no recognized type
//if (transfer.types.includes('text/uri-list')) return 'link';
let files = (this.app as any).dragManager.draggable?.files;
if(files) {
if(files[0] == this.file) {
@@ -757,9 +928,30 @@ export default class ExcalidrawView extends TextFileView {
}
}
if (['file', 'files'].includes((this.app as any).dragManager.draggable?.type)) return 'link';
if (transfer.types?.includes('text/html') || transfer.types?.includes('text/plain')) return 'copy';
if ( transfer.types?.includes('text/html')
|| transfer.types?.includes('text/plain')
|| transfer.types?.includes('Files')
) return 'copy';
}
let viewModeEnabled = false;
const handleLinkClick = () => {
selectedTextElement = getTextElementAtPointer(currentPosition);
if(selectedTextElement && selectedTextElement.id) {
const event = new MouseEvent("click", {ctrlKey:true, metaKey:true, shiftKey:this.shiftKeyDown, altKey:this.altKeyDown});
this.handleLinkClick(this,event);
selectedTextElement = null;
}
selectedImageElement = getImageElementAtPointer(currentPosition);
if(selectedImageElement && selectedImageElement.id) {
const event = new MouseEvent("click", {ctrlKey:true, metaKey:true, shiftKey:this.shiftKeyDown, altKey:this.altKeyDown});
this.handleLinkClick(this,event);
selectedImageElement = null;
}
}
let mouseEvent:any = null;
const excalidrawDiv = React.createElement(
"div",
{
@@ -769,16 +961,17 @@ export default class ExcalidrawView extends TextFileView {
tabIndex: 0,
onKeyDown: (e:any) => {
//@ts-ignore
if(e.target === excalidrawDiv.ref.current) return; //event should originate from the canvas
if(e.target === excalidrawDiv.ref.current) return; //event should originate from the canvas
if(document.fullscreenEnabled && document.fullscreenElement == this.contentEl && e.keyCode==27) {
document.exitFullscreen();
this.zoomToFit();
}
this.ctrlKeyDown = e.ctrlKey || e.metaKey;
this.ctrlKeyDown = e.ctrlKey||e.metaKey;
this.shiftKeyDown = e.shiftKey;
this.altKeyDown = e.altKey;
if(e.ctrlKey && !e.shiftKey && !e.altKey) { // && !e.metaKey) {
if((e.ctrlKey||e.metaKey) && !e.shiftKey && !e.altKey) {
const selectedElement = getTextElementAtPointer(currentPosition);
if(!selectedElement) return;
@@ -789,7 +982,7 @@ export default class ExcalidrawView extends TextFileView {
if(!text) return;
if(text.match(REG_LINKINDEX_HYPERLINK)) return;
const parts = REGEX_LINK.getRes(text).next();
const parts = REGEX_LINK.getRes(text).next();
if(!parts.value) return;
let linktext = REGEX_LINK.getLink(parts); //parts.value[2] ? parts.value[2]:parts.value[6];
@@ -799,7 +992,7 @@ export default class ExcalidrawView extends TextFileView {
this.plugin.hover.sourcePath = this.file.path;
hoverPreviewTarget = this.contentEl; //e.target;
this.app.workspace.trigger('hover-link', {
event: this.mouseEvent,
event: mouseEvent,
source: VIEW_TYPE_EXCALIDRAW,
hoverParent: hoverPreviewTarget,
targetEl: hoverPreviewTarget,
@@ -817,20 +1010,19 @@ export default class ExcalidrawView extends TextFileView {
}
},
onKeyUp: (e:any) => {
this.ctrlKeyDown = e.ctrlKey || e.metaKey;
this.ctrlKeyDown = e.ctrlKey||e.metaKey;
this.shiftKeyDown = e.shiftKey;
this.altKeyDown = e.altKey;
},
onClick: (e:MouseEvent):any => {
//@ts-ignore
if(!(e.ctrlKey||e.metaKey)) return;
if(!(this.plugin.settings.allowCtrlClick)) return;
if(!this.getSelectedTextElement().id) return;
if(!(this.getSelectedTextElement().id || this.getSelectedImageElement().id)) return;
this.handleLinkClick(this,e);
},
onMouseMove: (e:MouseEvent) => {
//@ts-ignore
this.mouseEvent = e.nativeEvent;
mouseEvent = e.nativeEvent;
},
onMouseOver: (e:MouseEvent) => {
clearHoverPreview();
@@ -864,17 +1056,9 @@ export default class ExcalidrawView extends TextFileView {
onPointerUpdate: (p:any) => {
currentPosition = p.pointer;
if(hoverPreviewTarget && (Math.abs(hoverPoint.x-p.pointer.x)>50 || Math.abs(hoverPoint.y-p.pointer.y)>50)) clearHoverPreview();
if(!this.excalidrawRef.current.getAppState().viewModeEnabled) return;
const handleLinkClick = () => {
selectedTextElement = getTextElementAtPointer(p.pointer);
if(selectedTextElement) {
const event = new MouseEvent("click", {ctrlKey: true, shiftKey: this.shiftKeyDown, altKey:this.altKeyDown});
this.handleLinkClick(this,event);
selectedTextElement = null;
}
}
const buttonDown = !blockOnMouseButtonDown && p.button=="down";
if(!viewModeEnabled) return;
const buttonDown = !blockOnMouseButtonDown && p.button === "down";
if(buttonDown) {
blockOnMouseButtonDown = true;
@@ -892,11 +1076,12 @@ export default class ExcalidrawView extends TextFileView {
timestamp = now;
return;
}
if (p.button=="up") {
if (p.button === "up") {
blockOnMouseButtonDown=false;
}
},
onChange: (et:ExcalidrawElement[],st:AppState) => {
viewModeEnabled = st.viewModeEnabled;
if(this.justLoaded) {
this.justLoaded = false;
this.zoomToFit(false);
@@ -927,16 +1112,16 @@ export default class ExcalidrawView extends TextFileView {
return true;
},
onDrop: (event: React.DragEvent<HTMLDivElement>):boolean => {
const st: AppState = excalidrawRef.current.getAppState();
const st: AppState = this.excalidrawAPI.getAppState();
currentPosition = viewportCoordsToSceneCoords({ clientX: event.clientX, clientY: event.clientY },st);
const draggable = (this.app as any).dragManager.draggable;
const onDropHook = (type:"file"|"text"|"unknown", files:TFile[], text:string):boolean => {
if (window.ExcalidrawAutomate.onDropHook) {
if (this.plugin.ea.onDropHook) {
try {
return window.ExcalidrawAutomate.onDropHook({
return this.plugin.ea.onDropHook({
//@ts-ignore
ea: window.ExcalidrawAutomate, //the Excalidraw Automate object
ea: this.plugin.ea, //the Excalidraw Automate object
event: event, //React.DragEvent<HTMLDivElement>
draggable: draggable, //Obsidian draggable object
type: type, //"file"|"text"
@@ -962,6 +1147,21 @@ export default class ExcalidrawView extends TextFileView {
switch(draggable?.type) {
case "file":
if (!onDropHook("file",[draggable.file],null)) {
if((event.ctrlKey||event.metaKey)
&& (IMAGE_TYPES.contains(draggable.file.extension)
|| this.plugin.isExcalidrawFile(draggable.file))) {
const f = draggable.file;
const topX = currentPosition.x;
const topY = currentPosition.y;
const ea = this.plugin.ea;
ea.reset();
ea.setView(this);
(async () => {
await ea.addImage(currentPosition.x,currentPosition.y,draggable.file);
ea.addElementsToView(false,false);
})();
return false;
}
this.addText(`[[${this.app.metadataCache.fileToLinktext(draggable.file,this.file.path,true)}]]`);
}
return false;
@@ -978,6 +1178,33 @@ export default class ExcalidrawView extends TextFileView {
const text:string = event.dataTransfer.getData("text");
if(!text) return true;
if (!onDropHook("text",null,text)) {
if(this.plugin.settings.iframelyAllowed && text.match(/^https?:\/\/\S*$/)) {
let linkAdded = false;
const self = this;
ajaxPromise({
url: `http://iframely.server.crestify.com/iframely?url=${text}`
}).then((res) => {
if(!res || linkAdded) return false;
linkAdded = true;
const data = JSON.parse(res);
if(!data || !(data.meta?.title)) {
this.addText(text);
return false;
}
this.addText(`[${data.meta.title}](${text})`);
return false;
},()=>{
if(linkAdded) return false;
linkAdded = true;
self.addText(text)
});
setTimeout(()=>{
if(linkAdded) return;
linkAdded = true;
self.addText(text)
},600);
return false;
}
this.addText(text.replace(/(!\[\[.*#[^\]]*\]\])/g,"$1{40}"));
}
return false;
@@ -1012,14 +1239,14 @@ export default class ExcalidrawView extends TextFileView {
await this.save(false);
//this callback function will only be invoked if quick parse fails, i.e. there is a transclusion in the raw text
//thus I only check if TextMode.parsed, text is always != with parseResult
if(this.textMode == TextMode.parsed) this.excalidrawRef.current.history.clear();
if(this.textMode == TextMode.parsed) this.excalidrawAPI.history.clear();
this.setupAutosaveTimer();
});
if(parseResult) { //there were no transclusions in the raw text, quick parse was successful
this.setupAutosaveTimer();
if(this.textMode == TextMode.raw) return; //text is displayed in raw, no need to clear the history, undo will not create problems
if(text == parseResult) return; //There were no links to parse, raw text and parsed text are equivalent
this.excalidrawRef.current.history.clear();
this.excalidrawAPI.history.clear();
return parseResult;
}
return;
@@ -1037,51 +1264,22 @@ export default class ExcalidrawView extends TextFileView {
);
});
ReactDOM.render(reactElement,this.contentEl,()=>this.excalidrawWrapperRef.current.focus());
ReactDOM.render(reactElement,this.contentEl,()=>{
this.excalidrawWrapperRef.current.focus();
});
}
public zoomToFit(delay:boolean = true) {
if(!this.excalidrawRef) return;
const current = this.excalidrawRef.current;
const maxZoom = this.plugin.settings.zoomToFitMaxLevel;
const current = this.excalidrawAPI;
const fullscreen = (document.fullscreenElement==this.contentEl);
const elements = current.getSceneElements();
if(delay) { //time for the DOM to render, I am sure there is a more elegant solution
setTimeout(() => current.zoomToFit(elements,2,fullscreen?0:0.05),100);
setTimeout(() => current.zoomToFit(elements,maxZoom,fullscreen?0:0.05),100);
} else {
current.zoomToFit(elements,2,fullscreen?0:0.05);
current.zoomToFit(elements,maxZoom,fullscreen?0:0.05);
}
}
public static async getSVG(scene:any, exportSettings:ExportSettings):Promise<SVGSVGElement> {
try {
return exportToSvg({
elements: scene.elements,
appState: {
exportBackground: exportSettings.withBackground,
exportWithDarkMode: exportSettings.withTheme ? (scene.appState?.theme=="light" ? false : true) : false,
... scene.appState,},
exportPadding:10,
});
} catch (error) {
return null;
}
}
public static async getPNG(scene:any, exportSettings:ExportSettings, scale:number = 1) {
try {
return await Excalidraw.exportToBlob({
elements: scene.elements,
appState: {
exportBackground: exportSettings.withBackground,
exportWithDarkMode: exportSettings.withTheme ? (scene.appState?.theme=="light" ? false : true) : false,
... scene.appState,},
mimeType: "image/png",
exportWithDarkMode: "true",
metadata: "Generated by Excalidraw-Obsidian plugin",
getDimensions: (width:number, height:number) => ({ width:width*scale, height:height*scale, scale:scale })
});
} catch (error) {
return null;
}
}
}
}

55
src/InsertImageDialog.ts Normal file
View File

@@ -0,0 +1,55 @@
import {
App,
FuzzySuggestModal,
TFile
} from "obsidian";
import { IMAGE_TYPES } from "./constants";
import { ExcalidrawAutomate } from "./ExcalidrawAutomate";
import ExcalidrawView from "./ExcalidrawView";
import {t} from './lang/helpers'
import ExcalidrawPlugin from "./main";
export class InsertImageDialog extends FuzzySuggestModal<TFile> {
public app: App;
public plugin: ExcalidrawPlugin;
private view: ExcalidrawView;
constructor(plugin: ExcalidrawPlugin) {
super(plugin.app);
this.plugin = plugin;
this.app = plugin.app;
this.limit = 20;
this.setInstructions([{
command: t("SELECT_FILE"),
purpose: "",
}]);
this.setPlaceholder(t("SELECT_DRAWING"));
this.emptyStateText = t("NO_MATCH");
}
getItems(): TFile[] {
return (this.app.vault.getFiles() || []).filter((f:TFile) => IMAGE_TYPES.contains(f.extension) || this.plugin.isExcalidrawFile(f));
}
getItemText(item: TFile): string {
return item.path;
}
onChooseItem(item: TFile, _evt: MouseEvent | KeyboardEvent): void {
const ea = this.plugin.ea;
ea.reset();
ea.setView(this.view);
(async () => {
await ea.addImage(0,0,item);
ea.addElementsToView(true,false);
})();
}
public start(view: ExcalidrawView) {
this.view = view;
this.open();
}
}

103
src/LaTeX.ts Normal file
View File

@@ -0,0 +1,103 @@
import { BinaryFileData, DataURL } from "@zsviczian/excalidraw/types/types";
import ExcalidrawView from "./ExcalidrawView";
import ExcalidrawPlugin from "./main";
import {MimeType} from "./EmbeddedFileLoader";
import { FileId } from "@zsviczian/excalidraw/types/element/types";
import { getImageSize, svgToBase64 } from "./Utils";
import { fileid } from "./constants";
import html2canvas from "html2canvas";
declare let window: any;
export const updateEquation = async (
equation: string,
fileId: string,
view: ExcalidrawView,
addFiles:Function,
plugin: ExcalidrawPlugin
) => {
const data = await tex2dataURL(equation, plugin);
if(data) {
let files:BinaryFileData[] = [];
files.push({
mimeType : data.mimeType,
id: fileId as FileId,
dataURL: data.dataURL,
created: data.created,
//@ts-ignore
size: data.size,
});
addFiles(files,view);
}
}
export async function tex2dataURL(tex:string, plugin:ExcalidrawPlugin):Promise<{
mimeType: MimeType,
fileId: FileId,
dataURL: DataURL,
created: number,
size: {height: number, width: number},
}> {
//if network is slow, or not available, or mathjax has not yet fully loaded
try {
return await mathjaxSVG(tex, plugin);
} catch(e) {
//fallback
return await mathjaxImage2html(tex);
}
}
async function mathjaxSVG (tex:string, plugin:ExcalidrawPlugin):Promise<{
mimeType: MimeType,
fileId: FileId,
dataURL: DataURL,
created: number,
size: {height: number, width: number},
}> {
const eq = plugin.mathjax.tex2svg(tex,{display: true, scale: 4});
const svg = eq.querySelector("svg");
if(svg) {
const dataURL = svgToBase64(svg.outerHTML);
return {
mimeType: "image/svg+xml",
fileId: fileid() as FileId,
dataURL: dataURL as DataURL,
created: Date.now(),
size: await getImageSize(dataURL)
}
}
return null;
}
async function mathjaxImage2html(tex:string):Promise<{
mimeType: MimeType,
fileId: FileId,
dataURL: DataURL,
created: number,
size: {height: number, width: number},
}> {
const div = document.body.createDiv();
div.style.display = "table"; //this will ensure div fits width of formula exactly
//@ts-ignore
const eq = window.MathJax.tex2chtml(tex,{display: true, scale: 4}); //scale to ensure good resolution
eq.style.margin = "3px";
eq.style.color = "black";
//ipad support - removing mml as that was causing phantom double-image blur.
const el = eq.querySelector("mjx-assistive-mml");
if(el) {
el.parentElement.removeChild(el);
}
div.appendChild(eq);
window.MathJax.typeset();
const canvas = await html2canvas(div, {backgroundColor:null}); //transparent
document.body.removeChild(div);
return {
mimeType: "image/png",
fileId: fileid() as FileId,
dataURL: canvas.toDataURL() as DataURL,
created: Date.now(),
size: {height: canvas.height, width: canvas.width}
}
}

View File

@@ -1,54 +0,0 @@
import { App, Modal } from "obsidian";
import { t } from "./lang/helpers";
import ExcalidrawPlugin from "./main";
export class MigrationPrompt extends Modal {
private plugin: ExcalidrawPlugin;
constructor(app: App, plugin:ExcalidrawPlugin) {
super(app);
this.plugin = plugin;
}
onOpen(): void {
this.titleEl.setText("Welcome to Excalidraw 1.2");
this.createForm();
}
onClose(): void {
this.contentEl.empty();
}
createForm(): void {
const div = this.contentEl.createDiv();
div.addClass("excalidraw-prompt-div");
div.style.maxWidth = "600px";
div.createEl('p',{text: "This version comes with tons of new features and possibilities. Please read the description in Community Plugins to find out more."});
div.createEl('p',{text: ""} , (el) => {
el.innerHTML = "Drawings you've created with version 1.1.x need to be converted to take advantage of the new features. You can also continue to use them in compatibility mode. "+
"During conversion your old *.excalidraw files will be replaced with new *.excalidraw.md files.";
});
div.createEl('p',{text: ""}, (el) => {//files manually follow one of two options:
el.innerHTML = "To convert your drawings you have the following options:<br><ul>" +
"<li>Click <code>CONVERT FILES</code> now to convert all of your *.excalidraw files, or if you prefer to make a backup first, then click <code>CANCEL</code>.</li>" +
"<li>In the Command Palette select <code>Excalidraw: Convert *.excalidraw files to *.excalidraw.md files</code></li>" +
"<li>Right click an <code>*.excalidraw</code> file in File Explorer and select one of the following options to convert files one by one: <ul>"+
"<li><code>*.excalidraw => *.excalidraw.md</code></li>"+
"<li><code>*.excalidraw => *.md (Logseq compatibility)</code>. This option will retain the original *.excalidraw file next to the new Obsidian format. " +
"Make sure you also enable <code>Compatibility features</code> in Settings for a full solution.</li></ul></li>" +
"<li>Open a drawing in compatibility mode and select <code>Convert to new format</code> from the <code>Options Menu</code></li></ul>";
});
div.createEl('p',{text: "This message will only appear maximum 3 times in case you have *.excalidraw files in your Vault."});
const bConvert = div.createEl('button', {text: "CONVERT FILES"});
bConvert.onclick = (ev)=>{
this.plugin.convertExcalidrawToMD();
this.close();
};
const bCancel = div.createEl('button', {text: "CANCEL"});
bCancel.onclick = (ev)=>{
this.close();
};
}
}

203
src/OneOffs.ts Normal file
View File

@@ -0,0 +1,203 @@
import { App, Modal, Notice, TFile } from "obsidian";
import { getJSON } from "./ExcalidrawData";
import ExcalidrawPlugin from "./main";
export class OneOffs {
private plugin:ExcalidrawPlugin
constructor(plugin: ExcalidrawPlugin) {
this.plugin = plugin;
}
public patchCommentBlock() {
//This is a once off cleanup process to remediate incorrectly placed comment %% before # Text Elements
if(!this.plugin.settings.patchCommentBlock) return;
const plugin = this.plugin;
console.log(window.moment().format("HH:mm:ss") + ": Excalidraw will patch drawings in 5 minutes");
setTimeout(async ()=>{
await plugin.loadSettings();
if (!plugin.settings.patchCommentBlock) {
console.log(window.moment().format("HH:mm:ss") + ": Excalidraw patching aborted because synched data.json is already patched");
return;
}
console.log(window.moment().format("HH:mm:ss") + ": Excalidraw is starting the patching process");
let i = 0;
const excalidrawFiles = plugin.app.vault.getFiles();
for (const f of (excalidrawFiles || []).filter((f:TFile) => plugin.isExcalidrawFile(f))) {
if ( (f.extension !== "excalidraw") //legacy files do not need to be touched
&& (plugin.app.workspace.getActiveFile() !== f)) { //file is currently being edited
let drawing = await plugin.app.vault.read(f);
const orig_drawing = drawing;
drawing = drawing.replaceAll("\r\n","\n").replaceAll("\r","\n"); //Win, Mac, Linux compatibility
drawing = drawing.replace("\n%%\n# Text Elements\n","\n# Text Elements\n");
if (drawing.search("\n%%\n# Drawing\n") === -1) {
const [json,pos] = getJSON(drawing);
drawing = drawing.substr(0,pos)+"\n%%\n# Drawing\n```json\n"+json+"\n```%%";
};
if (drawing !== orig_drawing) {
i++;
console.log("Excalidraw patched: " + f.path);
await plugin.app.vault.modify(f,drawing);
}
}
}
plugin.settings.patchCommentBlock = false;
plugin.saveSettings();
console.log(window.moment().format("HH:mm:ss") + ": Excalidraw patched in total " + i + " files");
},300000) //5 minutes
}
public migrationNotice () {
if(this.plugin.settings.loadCount>0) return;
const plugin = this.plugin;
plugin.app.workspace.onLayoutReady(async () => {
plugin.settings.loadCount++;
plugin.saveSettings();
const files = plugin.app.vault.getFiles().filter((f)=>f.extension==="excalidraw");
if(files.length>0) {
const prompt = new MigrationPrompt(plugin.app, plugin);
prompt.open();
}
});
}
public imageElementLaunchNotice () {
if(!this.plugin.settings.imageElementNotice) return;
const plugin = this.plugin;
plugin.app.workspace.onLayoutReady(async () => {
const prompt = new ImageElementNotice(plugin.app, plugin);
prompt.open();
});
}
}
class MigrationPrompt extends Modal {
private plugin: ExcalidrawPlugin;
constructor(app: App, plugin:ExcalidrawPlugin) {
super(app);
this.plugin = plugin;
}
onOpen(): void {
this.titleEl.setText("Welcome to Excalidraw 1.2");
this.createForm();
}
onClose(): void {
this.contentEl.empty();
}
createForm(): void {
const div = this.contentEl.createDiv();
// div.addClass("excalidraw-prompt-div");
// div.style.maxWidth = "600px";
div.createEl('p',{text: "This version comes with tons of new features and possibilities. Please read the description in Community Plugins to find out more."});
div.createEl('p',{text: ""} , (el) => {
el.innerHTML = "Drawings you've created with version 1.1.x need to be converted to take advantage of the new features. You can also continue to use them in compatibility mode. "+
"During conversion your old *.excalidraw files will be replaced with new *.excalidraw.md files.";
});
div.createEl('p',{text: ""}, (el) => {//files manually follow one of two options:
el.innerHTML = "To convert your drawings you have the following options:<br><ul>" +
"<li>Click <code>CONVERT FILES</code> now to convert all of your *.excalidraw files, or if you prefer to make a backup first, then click <code>CANCEL</code>.</li>" +
"<li>In the Command Palette select <code>Excalidraw: Convert *.excalidraw files to *.excalidraw.md files</code></li>" +
"<li>Right click an <code>*.excalidraw</code> file in File Explorer and select one of the following options to convert files one by one: <ul>"+
"<li><code>*.excalidraw => *.excalidraw.md</code></li>"+
"<li><code>*.excalidraw => *.md (Logseq compatibility)</code>. This option will retain the original *.excalidraw file next to the new Obsidian format. " +
"Make sure you also enable <code>Compatibility features</code> in Settings for a full solution.</li></ul></li>" +
"<li>Open a drawing in compatibility mode and select <code>Convert to new format</code> from the <code>Options Menu</code></li></ul>";
});
div.createEl('p',{text: "This message will only appear maximum 3 times in case you have *.excalidraw files in your Vault."});
const bConvert = div.createEl('button', {text: "CONVERT FILES"});
bConvert.onclick = (ev)=>{
this.plugin.convertExcalidrawToMD();
this.close();
};
const bCancel = div.createEl('button', {text: "CANCEL"});
bCancel.onclick = (ev)=>{
this.close();
};
}
}
class ImageElementNotice extends Modal {
private plugin: ExcalidrawPlugin;
private saveChanges: boolean = false;
constructor(app: App, plugin:ExcalidrawPlugin) {
super(app);
this.plugin = plugin;
}
onOpen(): void {
this.titleEl.setText("Image Elements have arrived!");
this.createForm();
}
async onClose() {
this.contentEl.empty();
if(!this.saveChanges) return;
await this.plugin.loadSettings();
this.plugin.settings.imageElementNotice = false;
this.plugin.saveSettings();
}
createForm(): void {
const div = this.contentEl.createDiv();
//div.addClass("excalidraw-prompt-div");
//div.style.maxWidth = "600px";
div.createEl('p',{text: ""},(el) => {
el.innerHTML = "Welcome to Obsidian-Excalidraw 1.4! I've added Image Elements. "
+ "Please watch the video below to learn how to use this new feature.";
});
div.createEl('p',{text: ""}, (el) => {
el.innerHTML = "<u>⚠ WARNING:</u> Opening new drawings with an older version of the plugin will lead to loss of images. "
+ "Update the plugin on all your devices.";
});
div.createEl('p',{text: ""}, (el) => {
el.innerHTML = "Since March, I have spent most of my free time building this plugin. Close to 75 workdays worth of my time (assuming 8-hour days). "
+ "Some of you have already bought me a coffee. THANK YOU! Your support really means a lot to me! If you have not yet done so, please consider clicking the button below.";
});
const coffeeDiv = div.createDiv('coffee');
coffeeDiv.addClass('ex-coffee-div');
const coffeeLink = coffeeDiv.createEl('a', { href: 'https://ko-fi.com/zsolt' });
const coffeeImg = coffeeLink.createEl('img', {
attr: {
src: 'https://cdn.ko-fi.com/cdn/kofi3.png?v=3',
},
});
coffeeImg.height = 45;
div.createEl('p',{text: ""}, (el) => {//files manually follow one of two options:
el.style.textAlign = "center";
el.innerHTML = '<iframe width="560" height="315" src="https://www.youtube.com/embed/_c_0zpBJ4Xc?start=20" title="YouTube video player" '
+'frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" '
+ 'allowfullscreen></iframe>';
});
div.createEl('p',{text: ""}, (el) => {//files manually follow one of two options:
el.style.textAlign = "right";
const bOk = el.createEl('button', {text: "OK - Don't show this again"});
bOk.onclick = (ev)=>{
this.saveChanges = true;
this.close();
}
const bCancel = el.createEl('button', {text: "CANCEL - Read next time"});
bCancel.onclick = (ev)=>{
this.saveChanges = false;
this.close();
};
});
}
}

View File

@@ -19,7 +19,7 @@ export class Prompt extends Modal {
createForm(): void {
const div = this.contentEl.createDiv();
div.addClass("excalidarw-prompt-div");
div.addClass("excalidraw-prompt-div");
const form = div.createEl("form");
form.addClass("excalidraw-prompt-form");

View File

@@ -1,13 +1,20 @@
import { normalizePath, TAbstractFile, TFolder, Vault, WorkspaceLeaf } from "obsidian";
import Excalidraw,{exportToSvg} from "@zsviczian/excalidraw";
import { App, normalizePath, TAbstractFile, TFile, TFolder, Vault, WorkspaceLeaf } from "obsidian";
import { Random } from "roughjs/bin/math";
import { Zoom } from "@zsviczian/excalidraw/types/types";
import { CASCADIA_FONT, VIRGIL_FONT } from "./constants";
import ExcalidrawPlugin from "./main";
import { ExcalidrawElement } from "@zsviczian/excalidraw/types/element/types";
import { ExcalidrawElement, FileId } from "@zsviczian/excalidraw/types/element/types";
import { ExportSettings } from "./ExcalidrawView";
declare module "obsidian" {
interface Workspace {
getAdjacentLeafInDirection(leaf: WorkspaceLeaf, direction: string): WorkspaceLeaf;
}
interface Vault {
getConfig(option:"attachmentFolderPath"): string;
}
}
/**
@@ -15,7 +22,6 @@ declare module "obsidian" {
* @param filepath
*/
export function splitFolderAndFilename(filepath: string):{folderpath: string, filename: string} {
let folderpath: string, filename:string;
const lastIndex = filepath.lastIndexOf("/");
return {
folderpath: normalizePath(filepath.substr(0,lastIndex)),
@@ -141,7 +147,6 @@ export const rotatedDimensions = (
];
}
export const viewportCoordsToSceneCoords = (
{ clientX, clientY }: { clientX: number; clientY: number },
{
@@ -174,4 +179,124 @@ export const getNewOrAdjacentLeaf = (plugin: ExcalidrawPlugin, leaf: WorkspaceLe
return leafToUse;
}
return plugin.app.workspace.createLeafBySplit(leaf);
}
}
export const svgToBase64 = (svg:string):string => {
return "data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(svg.replaceAll("&nbsp;"," "))));
}
export const getBinaryFileFromDataURL = (dataURL:string):ArrayBuffer => {
if(!dataURL) return null;
const parts = dataURL.matchAll(/base64,(.*)/g).next();
const binary_string = window.atob(parts.value[1]);
const len = binary_string.length;
const bytes = new Uint8Array(len);
for (var i = 0; i < len; i++) {
bytes[i] = binary_string.charCodeAt(i);
}
return bytes.buffer;
}
export const getAttachmentsFolderAndFilePath = async (app:App, activeViewFilePath:string, newFileName:string):Promise<[string,string]> => {
let folder = app.vault.getConfig("attachmentFolderPath");
// folder == null: save to vault root
// folder == "./" save to same folder as current file
// folder == "folder" save to specific folder in vault
// folder == "./folder" save to specific subfolder of current active folder
if(folder && folder.startsWith("./")) { // folder relative to current file
const activeFileFolder = splitFolderAndFilename(activeViewFilePath).folderpath + "/";
folder = normalizePath(activeFileFolder + folder.substring(2));
}
if(!folder) folder = "";
await checkAndCreateFolder(app.vault,folder);
return [folder,normalizePath(folder + "/" + newFileName)];
}
export const getSVG = async (scene:any, exportSettings:ExportSettings):Promise<SVGSVGElement> => {
try {
return await exportToSvg({
elements: scene.elements,
appState: {
exportBackground: exportSettings.withBackground,
exportWithDarkMode: exportSettings.withTheme ? (scene.appState?.theme=="light" ? false : true) : false,
... scene.appState,},
files: scene.files,
exportPadding:10,
});
} catch (error) {
return null;
}
}
export const getPNG = async (scene:any, exportSettings:ExportSettings, scale:number = 1) => {
try {
return await Excalidraw.exportToBlob({
elements: scene.elements,
appState: {
exportBackground: exportSettings.withBackground,
exportWithDarkMode: exportSettings.withTheme ? (scene.appState?.theme=="light" ? false : true) : false,
... scene.appState,},
files: scene.files,
mimeType: "image/png",
exportWithDarkMode: "true",
metadata: "Generated by Excalidraw-Obsidian plugin",
getDimensions: (width:number, height:number) => ({ width:width*scale, height:height*scale, scale:scale })
});
} catch (error) {
return null;
}
}
export const embedFontsInSVG = (svg:SVGSVGElement):SVGSVGElement => {
//replace font references with base64 fonts
const includesVirgil = svg.querySelector("text[font-family^='Virgil']") != null;
const includesCascadia = svg.querySelector("text[font-family^='Cascadia']") != null;
const defs = svg.querySelector("defs");
if (defs && (includesCascadia || includesVirgil)) {
defs.innerHTML = "<style>" + (includesVirgil ? VIRGIL_FONT : "") + (includesCascadia ? CASCADIA_FONT : "")+"</style>";
}
return svg;
}
export const getImageSize = async (src:string):Promise<{height:number, width:number}> => {
return new Promise((resolve, reject) => {
let img = new Image()
img.onload = () => resolve({height: img.height, width:img.width});
img.onerror = reject;
img.src = src;
})
}
export const scaleLoadedImage = (scene:any, files:any):[boolean,any] => {
let dirty = false;
for(const f of files) {
const [w_image,h_image] = [f.size.width,f.size.height];
const imageAspectRatio = f.size.width/f.size.height;
scene
.elements
.filter((e:any)=>(e.type === "image" && e.fileId === f.id))
.forEach((el:any)=>{
const [w_old,h_old] = [el.width,el.height];
const elementAspectRatio = w_old/h_old;
if(imageAspectRatio != elementAspectRatio) {
dirty = true;
const h_new = Math.sqrt(w_old*h_old*h_image/w_image);
const w_new = Math.sqrt(w_old*h_old*w_image/h_image);
el.height = h_new;
el.width = w_new;
el.y += (h_old-h_new)/2;
el.x += (w_old-w_new)/2;
}
});
return [dirty,scene];
}
}
export const isObsidianThemeDark = () => document.body.classList.contains("theme-dark");
export function getIMGFilename(path:string,extension:string):string {
return path.substring(0,path.lastIndexOf('.')) + '.' + extension;
}
//export const debug = console.log.bind(window.console);
//export const debug = function(){};

View File

@@ -1,8 +1,12 @@
//This is only for backward compatibility because an early version of obsidian included an encoding to avoid fantom links from littering Obsidian graph view
export function JSON_parse(x:string):any {return JSON.parse(x.replaceAll("&#91;","["));}
import { FileId } from "@zsviczian/excalidraw/types/element/types";
import {customAlphabet} from "nanoid";
export const nanoid = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',8);
export const fileid = customAlphabet('1234567890abcdef',40);
export const IMAGE_TYPES = ['jpeg', 'jpg', 'png', 'gif', 'svg'];
export const MAX_IMAGE_SIZE = 500;
export const FRONTMATTER_KEY = "excalidraw-plugin";
export const FRONTMATTER_KEY_CUSTOM_PREFIX = "excalidraw-link-prefix";
export const FRONTMATTER_KEY_CUSTOM_URL_PREFIX = "excalidraw-url-prefix";

View File

@@ -23,19 +23,20 @@ export default {
EXPORT_PNG: "Save as PNG next to the current file",
TOGGLE_LOCK: "Toggle Text Element edit RAW/PREVIEW",
INSERT_LINK: "Insert link to file",
INSERT_LATEX: "Insert LaTeX-symbol (e.g. $\\theta$)",
INSERT_IMAGE: "Insert image from vault",
INSERT_LATEX: "Insert LaTeX formula (e.g. \\binom{n}{k} = \\frac{n!}{k!(n-k)!})",
ENTER_LATEX: "Enter a valid LaTeX expression",
//ExcalidrawView.ts
OPEN_AS_MD: "Open as Markdown",
SAVE_AS_PNG: "Save as PNG into Vault (CTRL/META+CLICK to export)",
SAVE_AS_SVG: "Save as SVG into Vault (CTRL/META+CLICK to export)",
SAVE_AS_PNG: "Save as PNG into Vault (CTRL/CMD+CLICK to export)",
SAVE_AS_SVG: "Save as SVG into Vault (CTRL/CMD+CLICK to export)",
OPEN_LINK: "Open selected text as link\n(SHIFT+CLICK to open in a new pane)",
EXPORT_EXCALIDRAW: "Export to an .Excalidraw file",
LINK_BUTTON_CLICK_NO_TEXT: 'Select a Text Element containing an internal or external link.\n'+
LINK_BUTTON_CLICK_NO_TEXT: 'Select a an ImageElement, or select a TextElement that contains an internal or external link.\n'+
'SHIFT CLICK this button to open the link in a new pane.\n'+
'CTRL/META CLICK the Text Element on the canvas has the same effect!',
TEXT_ELEMENT_EMPTY: "Text Element is empty, or [[valid-link|alias]] or [alias](valid-link) is not found",
'CTRL/CMD CLICK the Image or TextElement on the canvas has the same effect!',
TEXT_ELEMENT_EMPTY: "No ImageElement is selected or TextElement is empty, or [[valid-link|alias]] or [alias](valid-link) is not found",
FILENAME_INVALID_CHARS: 'File name cannot contain any of the following characters: * " \\  < > : | ?',
FILE_DOES_NOT_EXIST: "File does not exist. Hold down ALT (or ALT+SHIFT) and CLICK link button to create a new file.",
FORCE_SAVE: "Force-save to update transclusions in adjacent panes.\n(Please note, that autosave is always on)",
@@ -69,21 +70,30 @@ export default {
FILENAME_PREFIX_DESC: "The first part of the filename",
FILENAME_DATE_NAME: "Filename date",
FILENAME_DATE_DESC: "The second part of the filename",
/*SVG_IN_MD_NAME: "SVG Snapshot to markdown file",
SVG_IN_MD_DESC: "If the switch is 'on' Excalidraw will include an SVG snapshot in the markdown file. "+
"When SVG snapshots are saved to the Excalidraw.md file, drawings that include large png, jpg, gif images may take extreme long time to open in markdown view. " +
"On the other hand, SVG snapshots provide some level of platform independence and longevity to your drawings. Even if Excalidraw will no longer exist, the snapshot " +
"can be opened with an app that reads SVGs. In addition hover previews will be less resource intensive if SVG snapshots are enabled.",*/
DISPLAY_HEAD: "Display",
MATCH_THEME_NAME: "New drawing to match Obsidian theme",
MATCH_THEME_DESC: "If theme is dark, new drawing will be created in dark mode. This does not apply when you use a template for new drawings. " +
"Also this will not effect when you open an existing drawing. Those will follow the theme of the template/drawing respectively.",
MATCH_THEME_ALWAYS_NAME: "Existing drawings to match Obsidian theme",
MATCH_THEME_ALWAYS_DESC: "If theme is dark, drawings will be opened in dark mode. If your theme is light, they will be opened in light mode. ",
ZOOM_TO_FIT_NAME: "Zoom to fit on view resize",
ZOOM_TO_FIT_DESC: "Zoom to fit drawing when the pane is resized",
ZOOM_TO_FIT_MAX_LEVEL_NAME: "Zoom to fit max ZOOM level",
ZOOM_TO_FIT_MAX_LEVEL_DESC: "Set the maximum level to which zoom to fit will enlarge the drawing. Minimum is 0.5 (50%) and maximum is 10 (1000%).",
LINKS_HEAD: "Links and transclusion",
LINKS_DESC: "CTRL/META + CLICK on Text Elements to open them as links. " +
LINKS_DESC: "CTRL/CMD + CLICK on Text Elements to open them as links. " +
"If the selected text has more than one [[valid Obsidian links]], only the first will be opened. " +
"If the text starts as a valid web link (i.e. https:// or http://), then " +
"the plugin will open it in a browser. " +
"When Obsidian files change, the matching [[link]] in your drawings will also change. " +
"If you don't want text accidentally changing in your drawings use [[links|with aliases]].",
ADJACENT_PANE_NAME: "Open in adjacent pane",
ADJACENT_PANE_DESC: "When CTRL+SHIFT clicking a link in Excalidraw by default the plugin will open the link in a new pane. " +
ADJACENT_PANE_DESC: "When CTRL/CMD+SHIFT clicking a link in Excalidraw by default the plugin will open the link in a new pane. " +
"Turning this setting on, Excalidraw will first look for an existing adjacent pane, and try to open the link there. " +
"Excalidraw will first look too the right, then to the left, then down, then up. If no pane is found, Excalidraw will open " +
"a new pane.",
@@ -99,16 +109,18 @@ export default {
URL_PREFIX_DESC:"In PREVIEW mode, if the Text Element contains a URL link, precede the text with these characters. " +
"You can override this setting for a specific drawing by adding \'" + FRONTMATTER_KEY_CUSTOM_URL_PREFIX +
': "🌐 "\' to the file\'s frontmatter.',
LINK_CTRL_CLICK_NAME: "CTRL + CLICK on text to open them as links",
LINK_CTRL_CLICK_NAME: "CTRL/CMD + CLICK on text to open them as links",
LINK_CTRL_CLICK_DESC: "You can turn this feature off if it interferes with default Excalidraw features you want to use. If " +
"this is turned off, only the link button in the title bar of the drawing pane will open links.",
TRANSCLUSION_WRAP_NAME: "Overflow wrap behavior of transcluded text",
TRANSCLUSION_WRAP_DESC: "Number specifies the character count where the text should be wrapped. " +
"Set the text wrapping behavior of transcluded text. Turn this ON to force-wrap " +
"text (i.e. no overflow), or OFF to soft-warp text (at the nearest whitespace).",
"text (i.e. no overflow), or OFF to soft-wrap text (at the nearest whitespace).",
PAGE_TRANSCLUSION_CHARCOUNT_NAME: "Page transclusion max char count",
PAGE_TRANSCLUSION_CHARCOUNT_DESC: "The maximum number of characters to display from the page when transcluding an entire page with the "+
"![[markdown page]] format.",
GET_URL_TITLE_NAME: "Use iframely to resolve page title",
GET_URL_TITLE_DESC: "Use the http://iframely.server.crestify.com/iframely?url= to get title of page when dropping a link into Excalidraw",
EMBED_HEAD: "Embed & Export",
EMBED_PREVIEW_SVG_NAME: "Display SVG in markdown preview",
EMBED_PREVIEW_SVG_DESC: "The default is to display drawings as SVG images in the markdown preview. Turning this feature off, the markdown preview will display the drawing as an embedded PNG image.",
@@ -161,7 +173,8 @@ export default {
//openDrawings.ts
SELECT_FILE: "Select a file then press enter.",
NO_MATCH: "No file matches your query.",
SELECT_FILE_TO_LINK: "Select the file you want to insert the link for.",
SELECT_FILE_TO_LINK: "Select the file you want to insert the link for.",
SELECT_DRAWING: "Select the drawing you want to insert",
TYPE_FILENAME: "Type name of drawing to select.",
SELECT_FILE_OR_TYPE_NEW: "Select existing drawing or type name of a new drawing then press Enter.",
SELECT_TO_EMBED: "Select the drawing to insert into active document.",

View File

@@ -29,13 +29,13 @@ export default {
//ExcalidrawView.ts
OPEN_AS_MD: "打开为 Markdown 文件",
SAVE_AS_PNG: "保存成 PNG 文件到库里CTRL/META 加左键点击来指定导出位置)",
SAVE_AS_SVG: "保存成 SVG 文件到库里CTRL/META 加左键点击来指定导出位置)",
SAVE_AS_PNG: "保存成 PNG 文件到库里CTRL/CMD 加左键点击来指定导出位置)",
SAVE_AS_SVG: "保存成 SVG 文件到库里CTRL/CMD 加左键点击来指定导出位置)",
OPEN_LINK: "以链接的方式打开文本 \n按住 SHIFT 来在新面板中打开)",
EXPORT_EXCALIDRAW: "导出为 .Excalidraw 文件",
LINK_BUTTON_CLICK_NO_TEXT: '选择带有外部链接或内部链接的文本。\n'+
'SHIFT 加左键点击按钮来在新面板中打开链接。\n'+
'CTRL/META 加左键在画布中点击文本元素也可以打开对应的链接。',
'CTRL/CMD 加左键在画布中点击文本元素也可以打开对应的链接。',
TEXT_ELEMENT_EMPTY: "文本元素没有链接任何东西.",
FILENAME_INVALID_CHARS: '文件名不能包含以下符号: * " \\ < > : | ?',
FILE_DOES_NOT_EXIST: "文件不存在。按住 ALT或者 ALT + SHIFT加左键点击来创建新文件。",
@@ -71,7 +71,7 @@ export default {
FILENAME_DATE_NAME: "文件名日期",
FILENAME_DATE_DESC: "文件名的第二部分",
LINKS_HEAD: "链接",
LINKS_DESC: "CTRL/META 加左键点击文本元素来打开链接。" +
LINKS_DESC: "CTRL/CMD 加左键点击文本元素来打开链接。" +
"如果选中的文本指向多个双链,只会打开其中第一个。" +
"如果选中的文本为超链接 (i.e. https:// or http://),然后" +
"插件会在浏览器中打开超链接。" +
@@ -85,7 +85,7 @@ export default {
LINK_PREFIX_DESC:"在预览(锁定)模式,如果文本元素包含链接,在文本之前加上这些字符。" +
"你可以在文件的 Frontmatter 中加入 \'" + FRONTMATTER_KEY_CUSTOM_PREFIX +
': "👉 "\' 单独更改',
LINK_CTRL_CLICK_NAME: "CTRL 加左键点击文本来打开链接",
LINK_CTRL_CLICK_NAME: "CTRL/CMD 加左键点击文本来打开链接",
LINK_CTRL_CLICK_DESC: "如果此功能干扰了您要使用的 Excalidraw 功能,您可以将其关闭。 如果" +
"关闭此选项,则只有绘图标题栏中的链接按钮可以让你打开链接。",
EMBED_HEAD: "嵌入 & 导出",

View File

@@ -12,9 +12,10 @@ import {
MenuItem,
TAbstractFile,
Tasks,
MarkdownRenderer,
ViewState,
Notice,
loadMathJax,
MarkdownRenderer,
} from "obsidian";
import {
BLANK_DRAWING,
@@ -35,7 +36,7 @@ import {
DARK_BLANK_DRAWING
} from "./constants";
import ExcalidrawView, {ExportSettings, TextMode} from "./ExcalidrawView";
import {getJSON} from "./ExcalidrawData";
import {getJSON, getMarkdownDrawingSection} from "./ExcalidrawData";
import {
ExcalidrawSettings,
DEFAULT_SETTINGS,
@@ -48,23 +49,27 @@ import {
import {
InsertLinkDialog
} from "./InsertLinkDialog";
import {
InsertImageDialog
} from "./InsertImageDialog";
import {
initExcalidrawAutomate,
destroyExcalidrawAutomate
destroyExcalidrawAutomate,
ExcalidrawAutomate
} from "./ExcalidrawAutomate";
import { Prompt } from "./Prompt";
import { around } from "monkey-around";
import { t } from "./lang/helpers";
import { MigrationPrompt } from "./MigrationPrompt";
import { checkAndCreateFolder, download, getIMGPathFromExcalidrawFile, getNewUniqueFilepath, splitFolderAndFilename } from "./Utils";
import { checkAndCreateFolder, download, embedFontsInSVG, getAttachmentsFolderAndFilePath, getIMGFilename, getIMGPathFromExcalidrawFile, getNewUniqueFilepath, getPNG, getSVG, isObsidianThemeDark, splitFolderAndFilename, svgToBase64 } from "./Utils";
import { OneOffs } from "./OneOffs";
import { FileId } from "@zsviczian/excalidraw/types/element/types";
import { MATHJAX_DATAURL } from "./mathjax";
import { config, disconnect } from "process";
declare module "obsidian" {
interface App {
isMobile():boolean;
}
interface Vault {
getConfig(option:"attachmentFolderPath"): string;
}
interface Workspace {
on(name: 'hover-link', callback: (e:MouseEvent) => any, ctx?: any): EventRef;
}
@@ -76,15 +81,24 @@ export default class ExcalidrawPlugin extends Plugin {
public settings: ExcalidrawSettings;
private openDialog: OpenFileDialog;
private insertLinkDialog: InsertLinkDialog;
private insertImageDialog: InsertImageDialog;
private activeExcalidrawView: ExcalidrawView = null;
public lastActiveExcalidrawFilePath: string = null;
public hover: {linkText: string, sourcePath: string} = {linkText: null, sourcePath: null};
private observer: MutationObserver;
private fileExplorerObserver: MutationObserver;
public opencount:number = 0;
public ea:ExcalidrawAutomate;
//A master list of fileIds to facilitate copy / paste
public filesMaster:Map<FileId,string> = null; //fileId, path
public equationsMaster:Map<FileId,string> = null; //fileId, formula
public mathjax: any = null;
private mathjaxDiv: HTMLDivElement = null;
constructor(app: App, manifest: PluginManifest) {
super(app, manifest);
this.filesMaster = new Map<FileId,string>();
this.equationsMaster = new Map<FileId,string>();
}
async onload() {
@@ -95,8 +109,8 @@ export default class ExcalidrawPlugin extends Plugin {
await this.loadSettings();
this.addSettingTab(new ExcalidrawSettingTab(this.app, this));
await initExcalidrawAutomate(this);
this.ea = await initExcalidrawAutomate(this);
this.registerView(
VIEW_TYPE_EXCALIDRAW,
(leaf: WorkspaceLeaf) => new ExcalidrawView(leaf, this)
@@ -109,54 +123,55 @@ export default class ExcalidrawPlugin extends Plugin {
this.experimentalFileTypeDisplayToggle(this.settings.experimentalFileType);
this.registerCommands();
this.registerEventListeners();
//inspiration taken from kanban:
//https://github.com/mgmeyers/obsidian-kanban/blob/44118e25661bff9ebfe54f71ae33805dc88ffa53/src/main.ts#L267
this.registerMonkeyPatches();
new Notice("Excalidraw was updated. Files opened with this version will not open with the older version. Please update plugin on all your devices.\n\nI will remove this message with next update.",8000);
if(this.settings.loadCount<1) this.migrationNotice();
const electron:string = process.versions.electron;
if(electron.startsWith("8.")) {
new Notice(`You are running an older version of the electron Browser (${electron}). If Excalidraw does not start up, please reinstall Obsidian with the latest installer and try again.`,10000);
if(!this.app.isMobile) {
const electron:string = process?.versions?.electron;
if(electron && electron?.startsWith("8.")) {
new Notice(`You are running an older version of the electron Browser (${electron}). If Excalidraw does not start up, please reinstall Obsidian with the latest installer and try again.`,10000);
}
}
const patches = new OneOffs(this);
patches.migrationNotice();
patches.patchCommentBlock();
patches.imageElementLaunchNotice();
this.switchToExcalidarwAfterLoad()
//This is a once off cleanup process to remediate incorrectly placed comment %% before # Text Elements
if(this.settings.patchCommentBlock) {
const self = this;
console.log(window.moment().format("HH:mm:ss") + ": Excalidraw will patch drawings in 5 minutes");
setTimeout(async ()=>{
await self.loadSettings();
if (!self.settings.patchCommentBlock) {
console.log(window.moment().format("HH:mm:ss") + ": Excalidraw patching aborted because synched data.json is already patched");
return;
}
console.log(window.moment().format("HH:mm:ss") + ": Excalidraw is starting the patching process");
let i = 0;
const excalidrawFiles = this.app.vault.getFiles();
for (const f of (excalidrawFiles || []).filter((f:TFile) => self.isExcalidrawFile(f))) {
if ( (f.extension !== "excalidraw") //legacy files do not need to be touched
&& (self.app.workspace.getActiveFile() !== f)) { //file is currently being edited
let drawing = await self.app.vault.read(f);
const orig_drawing = drawing;
drawing = drawing.replaceAll("\r\n","\n").replaceAll("\r","\n"); //Win, Mac, Linux compatibility
drawing = drawing.replace("\n%%\n# Text Elements\n","\n# Text Elements\n");
if (drawing.search("\n%%\n# Drawing\n") === -1) {
const [json,pos] = getJSON(drawing);
drawing = drawing.substr(0,pos)+"\n%%\n# Drawing\n```json\n"+json+"\n```%%";
};
if (drawing !== orig_drawing) {
i++;
console.log("Excalidraw patched: " + f.path);
await self.app.vault.modify(f,drawing);
}
}
}
self.settings.patchCommentBlock = false;
self.saveSettings();
console.log(window.moment().format("HH:mm:ss") + ": Excalidraw patched in total " + i + " files");
},300000) //5 minutes
}
const self = this;
this.loadMathJax();
}
private loadMathJax() {
//loading Obsidian MathJax as fallback
this.app.workspace.onLayoutReady(()=>{
loadMathJax();
});
this.mathjaxDiv = document.body.createDiv();
this.mathjaxDiv.title = "Excalidraw MathJax Support";
this.mathjaxDiv.style.display = "none";
const iframe = this.mathjaxDiv.createEl("iframe");
const doc = iframe.contentWindow.document;
const script = doc.createElement("script");
script.type = "text/javascript";
const self = this;
script.onload = () => {
const win = iframe.contentWindow;
//@ts-ignore
win.MathJax.startup.pagePromise.then(() => {
//@ts-ignore
this.mathjax = win.MathJax;
});
};
script.src = 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js';
//script.src = MATHJAX_DATAURL;
doc.head.appendChild(script);
}
private switchToExcalidarwAfterLoad() {
@@ -173,19 +188,6 @@ export default class ExcalidrawPlugin extends Plugin {
});
}
private migrationNotice(){
const self = this;
this.app.workspace.onLayoutReady(async () => {
self.settings.loadCount++;
self.saveSettings();
const files = this.app.vault.getFiles().filter((f)=>f.extension=="excalidraw");
if(files.length>0) {
const prompt = new MigrationPrompt(self.app, self);
prompt.open();
}
});
}
/**
* Displays a transcluded .excalidraw image in markdown preview mode
*/
@@ -224,6 +226,9 @@ export default class ExcalidrawPlugin extends Plugin {
if(imgAttributes.fheight) img.setAttribute("height",imgAttributes.fheight);
img.addClass(imgAttributes.style);
const [scene,pos] = getJSON(content);
this.ea.reset();
if(!this.settings.displaySVGInPreview) {
const width = parseInt(imgAttributes.fwidth);
@@ -231,17 +236,25 @@ export default class ExcalidrawPlugin extends Plugin {
if(width>=800) scale = 2;
if(width>=1600) scale = 3;
if(width>=2400) scale = 4;
const png = await ExcalidrawView.getPNG(JSON_parse(getJSON(content)[0]),exportSettings, scale);
const png = await this.ea.createPNG(file.path,scale);
//const png = await getPNG(JSON_parse(scene),exportSettings, scale);
if(!png) return null;
img.src = URL.createObjectURL(png);
return img;
}
let svg = await ExcalidrawView.getSVG(JSON_parse(getJSON(content)[0]),exportSettings);
const svgSnapshot = (await this.ea.createSVG(file.path,true,exportSettings)).outerHTML;
let svg:SVGSVGElement = null;
const el = document.createElement('div');
el.innerHTML = svgSnapshot;
const firstChild = el.firstChild;
if(firstChild instanceof SVGSVGElement) {
svg=firstChild;
}
if(!svg) return null;
svg = ExcalidrawView.embedFontsInSVG(svg);
svg = embedFontsInSVG(svg);
svg.removeAttribute('width');
svg.removeAttribute('height');
img.setAttribute("src","data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(svg.outerHTML.replaceAll("&nbsp;"," ")))));
img.setAttribute("src",svgToBase64(svg.outerHTML));
return img;
}
@@ -330,9 +343,17 @@ export default class ExcalidrawPlugin extends Plugin {
if(m.length == 0) return;
if(!this.hover.linkText) return;
const file = this.app.metadataCache.getFirstLinkpathDest(this.hover.linkText, this.hover.sourcePath?this.hover.sourcePath:"");
if(!file || !(file instanceof TFile) || !this.isExcalidrawFile(file)) return
if(!file || !(file instanceof TFile) || !this.isExcalidrawFile(file)) return;
if(file.extension == "excalidraw") {
const svgFileName = getIMGFilename(file.path,"svg");
const svgFile = this.app.vault.getAbstractFileByPath(svgFileName);
if(svgFile && svgFile instanceof TFile) return; //If auto export SVG or PNG is enabled it will be inserted at the top of the excalidraw file. No need to manually insert hover preview
const pngFileName = getIMGFilename(file.path,"png");
const pngFile = this.app.vault.getAbstractFileByPath(pngFileName);
if(pngFile && pngFile instanceof TFile) return; //If auto export SVG or PNG is enabled it will be inserted at the top of the excalidraw file. No need to manually insert hover preview
if(file.extension === "excalidraw") {
observerForLegacyFileFormat(m,file);
return;
}
@@ -442,6 +463,7 @@ export default class ExcalidrawPlugin extends Plugin {
private registerCommands() {
this.openDialog = new OpenFileDialog(this.app, this);
this.insertLinkDialog = new InsertLinkDialog(this.app);
this.insertImageDialog = new InsertImageDialog(this);
this.addRibbonIcon(ICON_NAME, t("CREATE_NEW"), async (e) => {
this.createDrawing(this.getNextDefaultFilename(), e.ctrlKey||e.metaKey);
@@ -577,21 +599,11 @@ export default class ExcalidrawPlugin extends Plugin {
const insertDrawingToDoc = async (inNewPane:boolean) => {
const activeView = this.app.workspace.getActiveViewOfType(MarkdownView);
if(!activeView) return;
let folder = this.app.vault.getConfig("attachmentFolderPath");
// folder == null: save to vault root
// folder == "./" save to same folder as current file
// folder == "folder" save to specific folder in vault
// folder == "./folder" save to specific subfolder of current active folder
if(folder && folder.startsWith("./")) { // folder relative to current file
const activeFileFolder = splitFolderAndFilename(activeView.file.path).folderpath + "/";
folder = normalizePath(activeFileFolder + folder.substring(2));
}
if(!folder) folder = "";
await checkAndCreateFolder(this.app.vault,folder);
const filename = activeView.file.basename + "_" + window.moment().format(this.settings.drawingFilenameDateTime)
+ (this.settings.compatibilityMode ? '.excalidraw' : '.excalidraw.md');
this.embedDrawing(normalizePath(folder + "/" + filename));
this.createDrawing(filename, inNewPane,folder==""?null:folder);
const [folder, filepath] = await getAttachmentsFolderAndFilePath(this.app,activeView.file.path,filename);
this.embedDrawing(filepath);
this.createDrawing(filename, inNewPane, folder===""?null:folder);
}
this.addCommand({
@@ -694,6 +706,24 @@ export default class ExcalidrawPlugin extends Plugin {
},
});
this.addCommand({
id: "insert-image",
name: t("INSERT_IMAGE"),
checkCallback: (checking: boolean) => {
if (checking) {
const view = this.app.workspace.activeLeaf.view;
return (view instanceof ExcalidrawView);
} else {
const view = this.app.workspace.activeLeaf.view;
if (view instanceof ExcalidrawView) {
this.insertImageDialog.start(view);
return true;
}
else return false;
}
},
});
this.addCommand({
id: "insert-LaTeX-symbol",
name: t("INSERT_LATEX"),
@@ -703,13 +733,14 @@ export default class ExcalidrawPlugin extends Plugin {
} else {
const view = this.app.workspace.activeLeaf.view;
if (view instanceof ExcalidrawView) {
const prompt = new Prompt(this.app, t("ENTER_LATEX"),'','$\\theta$');
const prompt = new Prompt(this.app, t("ENTER_LATEX"),'','\\color{red}\\oint_S {E_n dA = \\frac{1}{{\\varepsilon _0 }}} Q_{inside}');
prompt.openAndGetValue( async (formula:string)=> {
if(!formula) return;
const el = createEl('p');
await MarkdownRenderer.renderMarkdown(formula,el,'',this)
view.addText(el.getText());
el.empty();
const ea = this.ea;
ea.reset();
await ea.addLaTex(0,0,formula);
ea.setView(view);
ea.addElementsToView(true,true);
});
return true;
}
@@ -787,7 +818,7 @@ export default class ExcalidrawPlugin extends Plugin {
const filename = file.name.substr(0,file.name.lastIndexOf(".excalidraw")) + (replaceExtension ? ".md" : ".excalidraw.md");
const fname = getNewUniqueFilepath(this.app.vault,filename,normalizePath(file.path.substr(0,file.path.lastIndexOf(file.name))));
console.log(fname);
const result = await this.app.vault.create(fname,FRONTMATTER + this.exportSceneToMD(data));
const result = await this.app.vault.create(fname,FRONTMATTER + await this.exportSceneToMD(data));
if (this.settings.keepInSync) {
['.svg','.png'].forEach( (ext:string)=>{
const oldIMGpath = file.path.substring(0,file.path.lastIndexOf(".excalidraw")) + ext;
@@ -986,17 +1017,22 @@ export default class ExcalidrawPlugin extends Plugin {
//save Excalidraw leaf and update embeds when switching to another leaf
const activeLeafChangeEventHandler = async (leaf:WorkspaceLeaf) => {
const activeExcalidrawView = self.activeExcalidrawView;
const newActiveview:ExcalidrawView = (leaf.view instanceof ExcalidrawView) ? leaf.view as ExcalidrawView : null;
if(activeExcalidrawView && activeExcalidrawView != newActiveview) {
await activeExcalidrawView.save(false);
if(activeExcalidrawView.file) {
self.triggerEmbedUpdates(activeExcalidrawView.file.path);
}
}
const newActiveview:ExcalidrawView = (leaf.view instanceof ExcalidrawView) ? leaf.view : null;
self.activeExcalidrawView = newActiveview;
if(newActiveview) {
self.lastActiveExcalidrawFilePath = newActiveview.file?.path;
}
if(activeExcalidrawView && activeExcalidrawView != newActiveview) {
if(activeExcalidrawView.leaf != leaf) {
//if loading new view to same leaf then don't save. Excalidarw view will take care of saving anyway.
//avoid double saving
await activeExcalidrawView.save(false);
}
if(activeExcalidrawView.file) {
self.triggerEmbedUpdates(activeExcalidrawView.file.path);
}
}
};
self.registerEvent(
self.app.workspace.on("active-leaf-change",activeLeafChangeEventHandler)
@@ -1012,8 +1048,9 @@ export default class ExcalidrawPlugin extends Plugin {
excalidrawLeaves.forEach((leaf) => {
this.setMarkdownView(leaf);
});
this.settings.drawingOpenCount += this.opencount;
this.settings.loadCount++;
if(this.mathjaxDiv) document.body.removeChild(this.mathjaxDiv);
//this.settings.drawingOpenCount += this.opencount;
//this.settings.loadCount++;
//this.saveSettings();
}
@@ -1103,17 +1140,10 @@ export default class ExcalidrawPlugin extends Plugin {
}
}
if (this.settings.compatibilityMode) {
return this.settings.matchTheme && document.body.classList.contains("theme-dark") ? DARK_BLANK_DRAWING : BLANK_DRAWING;
return this.settings.matchTheme && isObsidianThemeDark() ? DARK_BLANK_DRAWING : BLANK_DRAWING;
}
const blank = this.settings.matchTheme && document.body.classList.contains("theme-dark") ? DARK_BLANK_DRAWING : BLANK_DRAWING;
return FRONTMATTER + '\n' + this.getMarkdownDrawingSection(blank);
}
public getMarkdownDrawingSection(jsonString: string) {
return '%%\n# Drawing\n'
+ String.fromCharCode(96)+String.fromCharCode(96)+String.fromCharCode(96)+'json\n'
+ jsonString + '\n'
+ String.fromCharCode(96)+String.fromCharCode(96)+String.fromCharCode(96) + '\n%%';
const blank = this.settings.matchTheme && isObsidianThemeDark() ? DARK_BLANK_DRAWING : BLANK_DRAWING;
return FRONTMATTER + '\n' + getMarkdownDrawingSection(blank);
}
/**
@@ -1121,7 +1151,7 @@ export default class ExcalidrawPlugin extends Plugin {
* @param {string} data - Excalidraw scene JSON string
* @returns {string} - Text starting with the "# Text Elements" header and followed by each "## id-value" and text
*/
public exportSceneToMD(data:string): string {
public async exportSceneToMD(data:string): Promise<string> {
if(!data) return "";
const excalidrawData = JSON_parse(data);
const textElements = excalidrawData.elements?.filter((el:any)=> el.type=="text")
@@ -1138,7 +1168,7 @@ export default class ExcalidrawPlugin extends Plugin {
}
outString += te.text+' ^'+id+'\n\n';
}
return outString + this.getMarkdownDrawingSection(JSON.stringify(JSON_parse(data),null,"\t"));
return outString + getMarkdownDrawingSection(JSON.stringify(JSON_parse(data),null,"\t"));
}
public async createDrawing(filename: string, onNewPane: boolean, foldername?: string, initData?:string):Promise<string> {
@@ -1157,10 +1187,17 @@ export default class ExcalidrawPlugin extends Plugin {
}
public async setMarkdownView(leaf: WorkspaceLeaf) {
const state=leaf.view.getState();
await leaf.setViewState({
type:VIEW_TYPE_EXCALIDRAW,
state: {file:null}
});
await leaf.setViewState(
{
type: "markdown",
state: leaf.view.getState(),
state: state,
popstate: true,
} as ViewState,
{ focus: true }
@@ -1182,3 +1219,4 @@ export default class ExcalidrawPlugin extends Plugin {
}
}

5
src/mathjax.ts Normal file

File diff suppressed because one or more lines are too long

View File

@@ -3,7 +3,6 @@ import {
DropdownComponent,
PluginSettingTab,
Setting,
TFile
} from 'obsidian';
import { VIEW_TYPE_EXCALIDRAW } from './constants';
import ExcalidrawView from './ExcalidrawView';
@@ -18,7 +17,9 @@ export interface ExcalidrawSettings {
displaySVGInPreview: boolean,
width: string,
matchTheme: boolean,
matchThemeAlways: boolean,
zoomToFitOnResize: boolean,
zoomToFitMaxLevel: number,
openInAdjacentPane: boolean,
showLinkBrackets: boolean,
linkPrefix: string,
@@ -26,6 +27,7 @@ export interface ExcalidrawSettings {
allowCtrlClick: boolean, //if disabled only the link button in the view header will open links
forceWrap: boolean,
pageTransclusionCharLimit: number,
iframelyAllowed: boolean,
pngExportScale: number,
exportWithTheme: boolean,
exportWithBackground: boolean,
@@ -42,6 +44,7 @@ export interface ExcalidrawSettings {
drawingOpenCount: number,
library: string,
patchCommentBlock: boolean, //1.3.12
imageElementNotice: boolean, //1.4.0
}
export const DEFAULT_SETTINGS: ExcalidrawSettings = {
@@ -52,7 +55,9 @@ export const DEFAULT_SETTINGS: ExcalidrawSettings = {
displaySVGInPreview: true,
width: '400',
matchTheme: false,
matchThemeAlways: false,
zoomToFitOnResize: true,
zoomToFitMaxLevel: 2,
linkPrefix: "📍",
urlPrefix: "🌐",
openInAdjacentPane: false,
@@ -60,6 +65,7 @@ export const DEFAULT_SETTINGS: ExcalidrawSettings = {
allowCtrlClick: true,
forceWrap: false,
pageTransclusionCharLimit: 200,
iframelyAllowed: true,
pngExportScale: 1,
exportWithTheme: true,
exportWithBackground: true,
@@ -76,6 +82,7 @@ export const DEFAULT_SETTINGS: ExcalidrawSettings = {
drawingOpenCount: 0,
library: `{"type":"excalidrawlib","version":1,"library":[]}`,
patchCommentBlock: true,
imageElementNotice: true,
}
export class ExcalidrawSettingTab extends PluginSettingTab {
@@ -190,7 +197,7 @@ export class ExcalidrawSettingTab extends PluginSettingTab {
text.setValue(this.plugin.settings.drawingFilenameDateTime);
filenameEl.innerHTML = getFilenameSample();
this.applySettingsUpdate();
}));
}));
this.containerEl.createEl('h1', {text: t("DISPLAY_HEAD")});
@@ -204,6 +211,16 @@ export class ExcalidrawSettingTab extends PluginSettingTab {
this.applySettingsUpdate();
}));
new Setting(containerEl)
.setName(t("MATCH_THEME_ALWAYS_NAME"))
.setDesc(t("MATCH_THEME_ALWAYS_DESC"))
.addToggle(toggle => toggle
.setValue(this.plugin.settings.matchThemeAlways)
.onChange(async (value) => {
this.plugin.settings.matchThemeAlways = value;
this.applySettingsUpdate();
}));
new Setting(containerEl)
.setName(t("ZOOM_TO_FIT_NAME"))
.setDesc(t("ZOOM_TO_FIT_DESC"))
@@ -214,6 +231,27 @@ export class ExcalidrawSettingTab extends PluginSettingTab {
this.applySettingsUpdate();
}));
let zoomText:HTMLDivElement;
new Setting(containerEl)
.setName(t("ZOOM_TO_FIT_MAX_LEVEL_NAME"))
.setDesc(t("ZOOM_TO_FIT_MAX_LEVEL_DESC"))
.addSlider(slider => slider
.setLimits(0.5,10,0.5)
.setValue(this.plugin.settings.zoomToFitMaxLevel)
.onChange(async (value)=> {
zoomText.innerText = " " + value.toString();
this.plugin.settings.zoomToFitMaxLevel = value;
this.applySettingsUpdate();
}))
.settingEl.createDiv('',(el)=>{
zoomText = el;
el.style.minWidth = "2.3em";
el.style.textAlign = "right";
el.innerText = " " + this.plugin.settings.zoomToFitMaxLevel.toString();
});
this.containerEl.createEl('h1', {text: t("LINKS_HEAD")});
this.containerEl.createEl('p',{
text: t("LINKS_DESC")});
@@ -245,7 +283,6 @@ export class ExcalidrawSettingTab extends PluginSettingTab {
.setPlaceholder(t("INSERT_EMOJI"))
.setValue(this.plugin.settings.linkPrefix)
.onChange((value) => {
console.log(value);
this.plugin.settings.linkPrefix = value;
this.applySettingsUpdate(true);
}));
@@ -305,6 +342,16 @@ export class ExcalidrawSettingTab extends PluginSettingTab {
this.applySettingsUpdate(true);
}));
new Setting(containerEl)
.setName(t("GET_URL_TITLE_NAME"))
.setDesc(t("GET_URL_TITLE_DESC"))
.addToggle(toggle => toggle
.setValue(this.plugin.settings.iframelyAllowed)
.onChange(async (value) => {
this.plugin.settings.iframelyAllowed = value;
this.applySettingsUpdate();
}));
this.containerEl.createEl('h1', {text: t("EMBED_HEAD")});
@@ -318,7 +365,6 @@ export class ExcalidrawSettingTab extends PluginSettingTab {
this.applySettingsUpdate();
}));
new Setting(containerEl)
.setName(t("EMBED_WIDTH_NAME"))
.setDesc(t("EMBED_WIDTH_DESC"))

View File

@@ -51,7 +51,7 @@ button.ToolIcon_type_button[title="Export"] {
.excalidraw-prompt-div {
display: flex;
max-width: 600px;
max-width: 800px;
}
.excalidraw-prompt-form {
@@ -95,3 +95,19 @@ li[data-testid] {
margin-bottom: 20px;
}
/*hide text elements in markdown preview*/
.markdown-preview-view.excalidraw-hide-preview-text {
font-size: 0px;
}
.markdown-preview-view mark,
.markdown-preview-view.excalidraw-hide-preview-text span:not(.image-embed),
.markdown-preview-view.excalidraw-hide-preview-text h1,
.markdown-preview-view.excalidraw-hide-preview-text h2,
.markdown-preview-view.excalidraw-hide-preview-text h3,
.markdown-preview-view.excalidraw-hide-preview-text h4,
.markdown-preview-view.excalidraw-hide-preview-text h5 {
display: none;
}

View File

@@ -1,3 +1,4 @@
{
"1.3.20": "0.11.13"
"1.4.7": "0.12.16",
"1.4.2": "0.11.13"
}

191
yarn.lock
View File

@@ -1023,6 +1023,11 @@
"resolved" "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz"
"version" "0.0.39"
"@types/js-beautify@^1.13.3":
"integrity" "sha512-ucIPw5gmNyvRKi6mpeojlqp+T+6ZBJeU+kqMDnIEDlijEU4QhLTon90sZ3cz9HZr+QTwXILjNsMZImzA7+zuJA=="
"resolved" "https://registry.npmjs.org/@types/js-beautify/-/js-beautify-1.13.3.tgz"
"version" "1.13.3"
"@types/node@*", "@types/node@^15.12.4":
"integrity" "sha512-zrNj1+yqYF4WskCMOHwN+w9iuD12+dGm0rQ35HLl9/Ouuq52cEtd0CH9qMgrdNmi5ejC1/V7vKEXYubB+65DkA=="
"resolved" "https://registry.npmjs.org/@types/node/-/node-15.12.4.tgz"
@@ -1062,10 +1067,10 @@
dependencies:
"@types/estree" "*"
"@zsviczian/excalidraw@0.9.0-obsidian-13":
"integrity" "sha512-oHXNHsdtbFsKJDeibsJi6DFeqTgb0OrZjE0W1ZgE3VN3CeqC0Ad9okzHMXQgPicpw/XFx1IOtCqZtpQ2Cch/Sw=="
"resolved" "https://registry.npmjs.org/@zsviczian/excalidraw/-/excalidraw-0.9.0-obsidian-13.tgz"
"version" "0.9.0-obsidian-13"
"@zsviczian/excalidraw@0.10.0-obsidian-8":
"integrity" "sha512-GLyOdnA2yH+acXjTaIuy6oeUz9JL8Wj8n/qzdTfqGhAWz6wPoXXEewTvZIsW4pij/0MC0A+unvHNK/k+YDbpBA=="
"resolved" "https://registry.npmjs.org/@zsviczian/excalidraw/-/excalidraw-0.10.0-obsidian-8.tgz"
"version" "0.10.0-obsidian-8"
"abab@^1.0.3":
"integrity" "sha1-X6rZwsB/YN12dw9xzwJbYqY8/U4="
@@ -2265,6 +2270,16 @@
"mixin-deep" "^1.2.0"
"pascalcase" "^0.1.1"
"base64-arraybuffer@^0.2.0":
"integrity" "sha512-7emyCsu1/xiBXgQZrscw/8KPRT44I4Yq9Pe6EGs3aPRTsWuggML1/1DTuZUuIaJPIm1FTDUVXl4x/yW8s0kQDQ=="
"resolved" "https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-0.2.0.tgz"
"version" "0.2.0"
"base64-arraybuffer@^1.0.1":
"integrity" "sha512-vFIUq7FdLtjZMhATwDul5RZWv2jpXQ09Pd6jcVEOvIsqCWTRFD/ONHNfyOS8dA/Ippi5dsIgpyKWKZaAKZltbA=="
"resolved" "https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-1.0.1.tgz"
"version" "1.0.1"
"base64-js@^1.0.2":
"integrity" "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA=="
"resolved" "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz"
@@ -2740,34 +2755,7 @@
"strip-ansi" "^3.0.0"
"supports-color" "^2.0.0"
"chalk@^2.0.0":
"integrity" "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ=="
"resolved" "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz"
"version" "2.4.2"
dependencies:
"ansi-styles" "^3.2.1"
"escape-string-regexp" "^1.0.5"
"supports-color" "^5.3.0"
"chalk@^2.0.1":
"integrity" "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ=="
"resolved" "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz"
"version" "2.4.2"
dependencies:
"ansi-styles" "^3.2.1"
"escape-string-regexp" "^1.0.5"
"supports-color" "^5.3.0"
"chalk@^2.1.0":
"integrity" "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ=="
"resolved" "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz"
"version" "2.4.2"
dependencies:
"ansi-styles" "^3.2.1"
"escape-string-regexp" "^1.0.5"
"supports-color" "^5.3.0"
"chalk@^2.4.1":
"chalk@^2.0.0", "chalk@^2.0.1", "chalk@^2.1.0", "chalk@^2.4.1":
"integrity" "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ=="
"resolved" "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz"
"version" "2.4.2"
@@ -3287,6 +3275,13 @@
"resolved" "https://registry.npmjs.org/css-color-names/-/css-color-names-0.0.4.tgz"
"version" "0.0.4"
"css-line-break@2.0.1":
"integrity" "sha512-gwKYIMUn7xodIcb346wgUhE2Dt5O1Kmrc16PWi8sL4FTfyDj8P5095rzH7+O8CTZudJr+uw2GCI/hwEkDJFI2w=="
"resolved" "https://registry.npmjs.org/css-line-break/-/css-line-break-2.0.1.tgz"
"version" "2.0.1"
dependencies:
"base64-arraybuffer" "^0.2.0"
"css-loader@0.28.7":
"integrity" "sha512-GxMpax8a/VgcfRrVy0gXD6yLd5ePYbXX/5zGgTVYp4wXtJklS8Z2VaUArJgc//f6/Dzil7BaJObdSv8eKKCPgg=="
"resolved" "https://registry.npmjs.org/css-loader/-/css-loader-0.28.7.tgz"
@@ -3860,21 +3855,25 @@
"is-arrayish" "^0.2.1"
"es-abstract@^1.18.0-next.2":
"integrity" "sha512-nQIr12dxV7SSxE6r6f1l3DtAeEYdsGpps13dR0TwJg1S8gyp4ZPgy3FZcHBgbiQqnoqSTb+oC+kO4UQ0C/J8vw=="
"resolved" "https://registry.npmjs.org/es-abstract/-/es-abstract-1.18.3.tgz"
"version" "1.18.3"
"integrity" "sha512-2vJ6tjA/UfqLm2MPs7jxVybLoB8i1t1Jd9R3kISld20sIxPcTbLuggQOUxeWeAvIUkduv/CfMjuh4WmiXr2v9w=="
"resolved" "https://registry.npmjs.org/es-abstract/-/es-abstract-1.19.1.tgz"
"version" "1.19.1"
dependencies:
"call-bind" "^1.0.2"
"es-to-primitive" "^1.2.1"
"function-bind" "^1.1.1"
"get-intrinsic" "^1.1.1"
"get-symbol-description" "^1.0.0"
"has" "^1.0.3"
"has-symbols" "^1.0.2"
"is-callable" "^1.2.3"
"internal-slot" "^1.0.3"
"is-callable" "^1.2.4"
"is-negative-zero" "^2.0.1"
"is-regex" "^1.1.3"
"is-string" "^1.0.6"
"object-inspect" "^1.10.3"
"is-regex" "^1.1.4"
"is-shared-array-buffer" "^1.0.1"
"is-string" "^1.0.7"
"is-weakref" "^1.0.1"
"object-inspect" "^1.11.0"
"object-keys" "^1.1.1"
"object.assign" "^4.1.2"
"string.prototype.trimend" "^1.0.4"
@@ -4684,7 +4683,7 @@
"resolved" "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz"
"version" "2.0.5"
"get-intrinsic@^1.0.2", "get-intrinsic@^1.1.1":
"get-intrinsic@^1.0.2", "get-intrinsic@^1.1.0", "get-intrinsic@^1.1.1":
"integrity" "sha512-kWZrnVM42QCiEA2Ig1bG8zjoIMOgxWwYCEeNdwY6Tv/cOSeGpcoX4pXHfKUxNKVoArnrEr2e9srnAxxGIraS9Q=="
"resolved" "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.1.tgz"
"version" "1.1.1"
@@ -4703,6 +4702,14 @@
"resolved" "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz"
"version" "3.0.0"
"get-symbol-description@^1.0.0":
"integrity" "sha512-2EmdH1YvIQiZpltCNgkuiUnyukzxM/R6NDJX31Ke3BG1Nq5b0S2PhX59UKi9vZpPDQVdqn+1IcaAwnzTT5vCjw=="
"resolved" "https://registry.npmjs.org/get-symbol-description/-/get-symbol-description-1.0.0.tgz"
"version" "1.0.0"
dependencies:
"call-bind" "^1.0.2"
"get-intrinsic" "^1.1.1"
"get-value@^2.0.3", "get-value@^2.0.6":
"integrity" "sha1-3BXKHGcjh8p2vTesCjlbogQqLCg="
"resolved" "https://registry.npmjs.org/get-value/-/get-value-2.0.6.tgz"
@@ -4918,6 +4925,13 @@
"resolved" "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.2.tgz"
"version" "1.0.2"
"has-tostringtag@^1.0.0":
"integrity" "sha512-kFjcSNhnlGV1kyoGk7OXKSawH5JOb/LzUc5w9B02hOTO0dfFRjbHQKvg1d6cf3HbeUmtU9VbbV3qzZ2Teh97WQ=="
"resolved" "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.0.tgz"
"version" "1.0.0"
dependencies:
"has-symbols" "^1.0.2"
"has-value@^0.3.1":
"integrity" "sha1-ex9YutpiyoJ+wKIHgCVlSEWZXh8="
"resolved" "https://registry.npmjs.org/has-value/-/has-value-0.3.1.tgz"
@@ -5059,6 +5073,14 @@
"pretty-error" "^2.0.2"
"toposort" "^1.0.0"
"html2canvas@^1.3.2":
"integrity" "sha512-4+zqv87/a1LsaCrINV69wVLGG8GBZcYBboz1JPWEgiXcWoD9kroLzccsBRU/L9UlfV2MAZ+3J92U9IQPVMDeSQ=="
"resolved" "https://registry.npmjs.org/html2canvas/-/html2canvas-1.3.2.tgz"
"version" "1.3.2"
dependencies:
"css-line-break" "2.0.1"
"text-segmentation" "^1.0.2"
"htmlparser2@^6.1.0":
"integrity" "sha512-gyyPk6rgonLFEDGoeRgQNaEUvdJ4ktTmmUh/h2t7s+M8oPpIPxgNACWa+6ESR57kXstwqPiCut0V8NRpcwgU7A=="
"resolved" "https://registry.npmjs.org/htmlparser2/-/htmlparser2-6.1.0.tgz"
@@ -5247,6 +5269,15 @@
dependencies:
"meow" "^3.3.0"
"internal-slot@^1.0.3":
"integrity" "sha512-O0DB1JC/sPyZl7cIo78n5dR7eUSwwpYPiXRhTzNxZVAMUuB8vlnRFyLxdrVToks6XPLVnFfbzaVd5WLjhgg+vA=="
"resolved" "https://registry.npmjs.org/internal-slot/-/internal-slot-1.0.3.tgz"
"version" "1.0.3"
dependencies:
"get-intrinsic" "^1.1.0"
"has" "^1.0.3"
"side-channel" "^1.0.4"
"interpret@^1.0.0":
"integrity" "sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA=="
"resolved" "https://registry.npmjs.org/interpret/-/interpret-1.4.0.tgz"
@@ -5343,10 +5374,10 @@
dependencies:
"builtin-modules" "^1.0.0"
"is-callable@^1.1.4", "is-callable@^1.2.3":
"integrity" "sha512-J1DcMe8UYTBSrKezuIUTUwjXsho29693unXM2YhJUTR2txK/eG47bvNa/wipPFmZFgr/N6f1GA66dv0mEyTIyQ=="
"resolved" "https://registry.npmjs.org/is-callable/-/is-callable-1.2.3.tgz"
"version" "1.2.3"
"is-callable@^1.1.4", "is-callable@^1.2.4":
"integrity" "sha512-nsuwtxZfMX67Oryl9LCQ+upnC0Z0BgpwntpS89m1H/TLF0zNfzfLMV/9Wa/6MZsj0acpEjAO0KF1xT6ZdLl95w=="
"resolved" "https://registry.npmjs.org/is-callable/-/is-callable-1.2.4.tgz"
"version" "1.2.4"
"is-ci@^1.0.10":
"integrity" "sha512-s6tfsaQaQi3JNciBH6shVqEDvhGut0SUXr31ag8Pd8BBbVVlcGfWhpPmEOoM6RJ5TFhbypvf5yyRw/VXW1IiWg=="
@@ -5603,13 +5634,13 @@
dependencies:
"@types/estree" "*"
"is-regex@^1.0.4", "is-regex@^1.1.3":
"integrity" "sha512-qSVXFz28HM7y+IWX6vLCsexdlvzT1PJNFSBuaQLQ5o0IEw8UDYW6/2+eCMVyIsbM8CNLX2a/QWmSpyxYEHY7CQ=="
"resolved" "https://registry.npmjs.org/is-regex/-/is-regex-1.1.3.tgz"
"version" "1.1.3"
"is-regex@^1.0.4", "is-regex@^1.1.4":
"integrity" "sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg=="
"resolved" "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz"
"version" "1.1.4"
dependencies:
"call-bind" "^1.0.2"
"has-symbols" "^1.0.2"
"has-tostringtag" "^1.0.0"
"is-resolvable@^1.0.0":
"integrity" "sha512-qgDYXFSR5WvEfuS5dMj6oTMEbrrSaM0CrFk2Yiq/gXnBvD9pMa2jGXxyhGLfvhZpuMZe18CJpFxAt3CRs42NMg=="
@@ -5626,15 +5657,22 @@
"resolved" "https://registry.npmjs.org/is-root/-/is-root-1.0.0.tgz"
"version" "1.0.0"
"is-shared-array-buffer@^1.0.1":
"integrity" "sha512-IU0NmyknYZN0rChcKhRO1X8LYz5Isj/Fsqh8NJOSf+N/hCOTwy29F32Ik7a+QszE63IdvmwdTPDd6cZ5pg4cwA=="
"resolved" "https://registry.npmjs.org/is-shared-array-buffer/-/is-shared-array-buffer-1.0.1.tgz"
"version" "1.0.1"
"is-stream@^1.0.0", "is-stream@^1.1.0":
"integrity" "sha1-EtSj3U5o4Lec6428hBc66A2RykQ="
"resolved" "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz"
"version" "1.1.0"
"is-string@^1.0.5", "is-string@^1.0.6":
"integrity" "sha512-2gdzbKUuqtQ3lYNrUTQYoClPhm7oQu4UdpSZMp1/DGgkHBT8E2Z1l0yMdb6D4zNAxwDiMv8MdulKROJGNl0Q0w=="
"resolved" "https://registry.npmjs.org/is-string/-/is-string-1.0.6.tgz"
"version" "1.0.6"
"is-string@^1.0.5", "is-string@^1.0.7":
"integrity" "sha512-tE2UXzivje6ofPW7l23cjDOMa09gb7xlAqG6jG5ej6uPV32TlWP3NKPigtaGeHNu9fohccRYvIiZMfOOnOYUtg=="
"resolved" "https://registry.npmjs.org/is-string/-/is-string-1.0.7.tgz"
"version" "1.0.7"
dependencies:
"has-tostringtag" "^1.0.0"
"is-svg@^2.0.0":
"integrity" "sha1-z2EJDaDZ77yrhyLeum8DIgjbsOk="
@@ -5660,6 +5698,13 @@
"resolved" "https://registry.npmjs.org/is-utf8/-/is-utf8-0.2.1.tgz"
"version" "0.2.1"
"is-weakref@^1.0.1":
"integrity" "sha512-b2jKc2pQZjaeFYWEf7ScFj+Be1I+PXmlu572Q8coTXZ+LD/QQZ7ShPMst8h16riVgyXTQwUsFEl74mDvc/3MHQ=="
"resolved" "https://registry.npmjs.org/is-weakref/-/is-weakref-1.0.1.tgz"
"version" "1.0.1"
dependencies:
"call-bind" "^1.0.0"
"is-windows@^1.0.1", "is-windows@^1.0.2":
"integrity" "sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA=="
"resolved" "https://registry.npmjs.org/is-windows/-/is-windows-1.0.2.tgz"
@@ -6879,10 +6924,10 @@
"resolved" "https://registry.npmjs.org/object-hash/-/object-hash-1.3.1.tgz"
"version" "1.3.1"
"object-inspect@^1.10.3":
"integrity" "sha512-e5mCJlSH7poANfC8z8S9s9S2IN5/4Zb3aZ33f5s8YqoazCFzNLloLU8r5VCG+G7WoqLvAAZoVMcy3tp/3X0Plw=="
"resolved" "https://registry.npmjs.org/object-inspect/-/object-inspect-1.10.3.tgz"
"version" "1.10.3"
"object-inspect@^1.11.0", "object-inspect@^1.9.0":
"integrity" "sha512-jp7ikS6Sd3GxQfZJPyH3cjcbJF6GZPClgdV+EFygjFLQ5FmW/dRUnTd9PQ9k0JhoNDabWFbpF1yCdSWCC6gexg=="
"resolved" "https://registry.npmjs.org/object-inspect/-/object-inspect-1.11.0.tgz"
"version" "1.11.0"
"object-is@^1.0.1":
"integrity" "sha512-3cyDsyHgtmi7I7DfSSI2LDp6SK2lwvtbg0p0R1e0RvTqF5ceGx+K2dfSjm1bKDMVCFEDAQvy+o8c6a7VujOddw=="
@@ -8710,6 +8755,15 @@
"resolved" "https://registry.npmjs.org/shellwords/-/shellwords-0.1.1.tgz"
"version" "0.1.1"
"side-channel@^1.0.4":
"integrity" "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw=="
"resolved" "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz"
"version" "1.0.4"
dependencies:
"call-bind" "^1.0.0"
"get-intrinsic" "^1.0.2"
"object-inspect" "^1.9.0"
"signal-exit@^3.0.0", "signal-exit@^3.0.2":
"integrity" "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA=="
"resolved" "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.3.tgz"
@@ -9137,14 +9191,7 @@
dependencies:
"has-flag" "^2.0.0"
"supports-color@^5.1.0":
"integrity" "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow=="
"resolved" "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz"
"version" "5.5.0"
dependencies:
"has-flag" "^3.0.0"
"supports-color@^5.3.0", "supports-color@^5.4.0":
"supports-color@^5.1.0", "supports-color@^5.3.0", "supports-color@^5.4.0":
"integrity" "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow=="
"resolved" "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz"
"version" "5.5.0"
@@ -9237,6 +9284,13 @@
"read-pkg-up" "^1.0.1"
"require-main-filename" "^1.0.1"
"text-segmentation@^1.0.2":
"integrity" "sha512-uTqvLxdBrVnx/CFQOtnf8tfzSXFm+1Qxau7Xi54j4OPTZokuDOX8qncQzrg2G8ZicAMOM8TgzFAYTb+AqNO4Cw=="
"resolved" "https://registry.npmjs.org/text-segmentation/-/text-segmentation-1.0.2.tgz"
"version" "1.0.2"
dependencies:
"utrie" "^1.0.1"
"text-table@~0.2.0", "text-table@0.2.0":
"integrity" "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ="
"resolved" "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz"
@@ -9657,6 +9711,13 @@
"resolved" "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz"
"version" "1.0.1"
"utrie@^1.0.1":
"integrity" "sha512-JPaDXF3vzgZxfeEwutdGzlrNoVFL5UvZcbO6Qo9D4GoahrieUPoMU8GCpVpR7MQqcKhmShIh8VlbEN3PLM3EBg=="
"resolved" "https://registry.npmjs.org/utrie/-/utrie-1.0.1.tgz"
"version" "1.0.1"
dependencies:
"base64-arraybuffer" "^1.0.1"
"uuid@^3.0.1", "uuid@^3.3.2":
"integrity" "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A=="
"resolved" "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz"