mirror of
https://github.com/zsviczian/obsidian-excalidraw-plugin.git
synced 2026-12-03 06:43:35 +00:00
Compare commits
20
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
97da7c680f | ||
|
|
5696a33e60 | ||
|
|
b68e8c0b20 | ||
|
|
3a43571f3e | ||
|
|
65c3a11fba | ||
|
|
010fd5c624 | ||
|
|
8ddf03cdd3 | ||
|
|
a5fd91a33c | ||
|
|
d8de0db423 | ||
|
|
b5d9fa4625 | ||
|
|
fcc0f94974 | ||
|
|
6b7d8c8b69 | ||
|
|
259e6277ed | ||
|
|
88405af417 | ||
|
|
8fecb75f97 | ||
|
|
bd1b13b58c | ||
|
|
d8cac4eacd | ||
|
|
8379f9315e | ||
|
|
123fa12122 | ||
|
|
46a41feaf3 |
No files matched your search
@@ -38,7 +38,8 @@
|
||||
* you may access this object via the variable `ea`. e.g. ea.addImage(); This ea object is already set to the targetView.
|
||||
* Through ea.obsidian all of the Obsidian API is available to the script. Thus you can create modal views, open files, etc.
|
||||
* You can access Obsidian type definitions here: https://github.com/obsidianmd/obsidian-api/blob/master/obsidian.d.ts
|
||||
* In addition to the ea object, the script also receives the `utils` object. utils includes to utility functions: suggester and inputPrompt
|
||||
* In addition to the ea instance, the script also receives the `utils` object. utils includes to utility functions: suggester and inputPrompt.
|
||||
* You may access these via the variable `utils`. e.g. utils.suggester(...);
|
||||
* - inputPrompt(inputPrompt: (
|
||||
* header: string,
|
||||
* placeholder?: string,
|
||||
@@ -2270,7 +2271,6 @@ export interface AppState {
|
||||
};
|
||||
showHyperlinkPopup: false | "info" | "editor";
|
||||
linkOpacity: number;
|
||||
trayModeEnabled: boolean;
|
||||
colorPalette?: {
|
||||
canvasBackground: ColorPaletteCustom;
|
||||
elementBackground: ColorPaletteCustom;
|
||||
@@ -2630,6 +2630,8 @@ export interface ExcalidrawImperativeAPI {
|
||||
setForceRenderAllEmbeddables: InstanceType<typeof App>["setForceRenderAllEmbeddables"];
|
||||
zoomToFit: InstanceType<typeof App>["zoomToFit"];
|
||||
refreshEditorBreakpoints: InstanceType<typeof App>["refreshEditorBreakpoints"];
|
||||
setTrayModeEnabled: InstanceType<typeof App>["setTrayModeEnabled"];
|
||||
isTrayModeEnabled: InstanceType<typeof App>["isTrayModeEnabled"];
|
||||
getColorAtScenePoint: InstanceType<typeof App>["getColorAtScenePoint"];
|
||||
startLineEditor: InstanceType<typeof App>["startLineEditor"];
|
||||
getSceneElements: InstanceType<typeof App>["getSceneElements"];
|
||||
@@ -2677,6 +2679,7 @@ export type Device = Readonly<{
|
||||
canFitSidebar: boolean;
|
||||
};
|
||||
isTouchScreen: boolean;
|
||||
isTrayMode: boolean;
|
||||
}>;
|
||||
export type FrameNameBounds = {
|
||||
x: number;
|
||||
|
||||
@@ -12,7 +12,7 @@ Content structure:
|
||||
2. The curated script overview (index-new.md)
|
||||
3. Raw source of every *.md script in /ea-scripts (each fenced code block is auto-closed to ensure well-formed aggregation)
|
||||
|
||||
Generated on: 2025-10-24T11:36:13.143Z
|
||||
Generated on: 2025-11-03T18:33:17.385Z
|
||||
|
||||
---
|
||||
|
||||
@@ -9639,6 +9639,7 @@ async function run() {
|
||||
// Initialize state
|
||||
let uiHidden = true;
|
||||
let currentIcon = "eye";
|
||||
let layerUIWrapper = ea.targetView.contentEl.querySelector(".excalidraw.excalidraw-container > .layer-ui__wrapper");
|
||||
const toolbar = ea.targetView.contentEl.querySelector(".excalidraw > .Island");
|
||||
let toolbarActive = toolbar?.style.display === "block";
|
||||
let prevHiddenState = false;
|
||||
@@ -9647,30 +9648,40 @@ async function run() {
|
||||
const toggleUIVisibility = (hidden) => {
|
||||
if(hidden === prevHiddenState) return hidden;
|
||||
prevHiddenState = hidden;
|
||||
try{
|
||||
const topBar = ea.targetView.containerEl.querySelector(".App-top-bar");
|
||||
const bottomBar = ea.targetView.containerEl.querySelector(".App-bottom-bar");
|
||||
const sidebarToggle = ea.targetView.containerEl.querySelector(".sidebar-toggle");
|
||||
const plugins = ea.targetView.containerEl.querySelector(".plugins-container");
|
||||
|
||||
if(hidden) {
|
||||
if (toolbarActive && (toolbar?.style.display === "none")) {
|
||||
toolbarActive = false;
|
||||
if (!!layerUIWrapper) {
|
||||
try {
|
||||
if(hidden) {
|
||||
layerUIWrapper.style.display = "none";
|
||||
} else {
|
||||
layerUIWrapper.style.display = "block";
|
||||
}
|
||||
} catch {};
|
||||
} else {
|
||||
try{
|
||||
const topBar = ea.targetView.containerEl.querySelector(".App-top-bar");
|
||||
const bottomBar = ea.targetView.containerEl.querySelector(".App-bottom-bar");
|
||||
const sidebarToggle = ea.targetView.containerEl.querySelector(".sidebar-toggle");
|
||||
const plugins = ea.targetView.containerEl.querySelector(".plugins-container");
|
||||
|
||||
if(hidden) {
|
||||
if (toolbarActive && (toolbar?.style.display === "none")) {
|
||||
toolbarActive = false;
|
||||
}
|
||||
if (toolbarActive = toolbar?.style.display === "block") {
|
||||
toolbarActive = true;
|
||||
};
|
||||
}
|
||||
if (toolbarActive = toolbar?.style.display === "block") {
|
||||
toolbarActive = true;
|
||||
};
|
||||
}
|
||||
|
||||
const display = hidden ? "none" : "";
|
||||
|
||||
if (topBar) topBar.style.display = display;
|
||||
if (bottomBar) bottomBar.style.display = display;
|
||||
if (sidebarToggle) sidebarToggle.style.display = display;
|
||||
if (plugins) plugins.style.display = display;
|
||||
if (toolbarActive) toolbar.style.display = hidden ? "none" : "block";
|
||||
modal.modalEl.style.opacity = hidden ? "0.4" : "0.8";
|
||||
} catch {};
|
||||
|
||||
const display = hidden ? "none" : "";
|
||||
|
||||
if (topBar) topBar.style.display = display;
|
||||
if (bottomBar) bottomBar.style.display = display;
|
||||
if (sidebarToggle) sidebarToggle.style.display = display;
|
||||
if (plugins) plugins.style.display = display;
|
||||
if (toolbarActive) toolbar.style.display = hidden ? "none" : "block";
|
||||
modal.modalEl.style.opacity = hidden ? "0.4" : "0.8";
|
||||
} catch {};
|
||||
};
|
||||
return hidden;
|
||||
};
|
||||
|
||||
|
||||
@@ -4,9 +4,163 @@ Excalidraw-Obsidian is an Obsidian.md plugins that is built on the open source E
|
||||
|
||||
Read the information below and respond with I'm ready. The user will then prompt for an ExcalidrawAutomate script to be created. Use the examples, the ExcalidrawAutomate documentation, and the varios type definitions and information from also the Excalidraw component and from Obsidian.md to generate the script based on the user's requirements.
|
||||
|
||||
When the user asks for a dialog window, by default create a FloatingModal.
|
||||
In addition to ExcalidrawAutomate, you can also use two other sources of functions:
|
||||
- The Excalidraw API available via ea.getExcalidrawAPI(). Note: the API is only available if ea.targetView is set. When running Excalidraw scripts using the script engine, the provided ea object is already set up with targetView by default. Otherwise you need to first run ea.setView().
|
||||
- window.ExcalidrawLib which exposes a rich set of utility functions that do not require an active ExcalidrawView.
|
||||
|
||||
The Obsidian.md module is available on ea.obsidian.
|
||||
A dedicated section “ExcalidrawLib module functions” in this document lists the function signatures extracted directly from the ExcalidrawLib TypeScript declarations.
|
||||
|
||||
- When the user asks for a dialog window, by default create a FloatingModal. Do not extend the FloatingModal class. Instead, define the modal's behavior by creating a new instance (e.g., const modal = new ea.FloatingModal(...)) and then assigning functions directly to the onOpen and onClose properties of that instance.
|
||||
For a reference, follow the implementation pattern used in the "Printable Layout Wizard.md" script.
|
||||
- Elements have a customData property that can be used to store arbitrary data. To ensure the data the script adds to elements use the ea.addAppendUpdateCustomData function. This function ensures that existing customData is preserved when adding new data.
|
||||
- Elements can be hidden by setting their opacity to 0. When hiding elements this way, it is good practice to temporarily store their original opacity in customData. This allows for easy restoration of the original opacity later.
|
||||
- Elements can be deleted from the scene by setting their isDeleted property to true.
|
||||
- The Obsidian.md module is available on ea.obsidian.
|
||||
|
||||
#### **1. The Core Workflow: Handling Element Immutability**
|
||||
|
||||
* **Central Rule:** Elements in the Excalidraw scene are immutable and should never be modified directly. Always use the ExcalidrawAutomate (EA) "workbench" pattern for modifications.
|
||||
* **The Workflow:**
|
||||
1. Get elements from the current view using `ea.getViewElements()` or `ea.getViewSelectedElements()`.
|
||||
2. Copy these elements into the EA workbench for editing using `ea.copyViewElementsToEAforEditing(elements)`.
|
||||
3. Modify the properties of the element copies that are now in the EA workbench (e.g., `ea.getElement(id).locked = true;`).
|
||||
4. Commit the changes back to the scene using `await ea.addElementsToView()`.
|
||||
* **Deletion:** To delete an element, set its `isDeleted` property to `true` on the workbench copy (`ea.getElement(id).isDeleted = true;`) and then commit with `await ea.addElementsToView()`.
|
||||
* **Cleanup:** Use `ea.clear()` at the beginning of a script if you are creating a completely new set of elements, to ensure the EA workbench is empty and doesn't contain artifacts from a previous run.
|
||||
|
||||
#### **2. User Interaction: Prompts and Dialogs**
|
||||
|
||||
* **Simple Input:** For straightforward user input, use the `utils` object provided to the script.
|
||||
* `await utils.inputPrompt()`: To get a string or number from the user.
|
||||
* `await utils.suggester()`: To let the user select from a predefined list of options.
|
||||
* **Complex Dialogs:** When a more complex UI with multiple controls is needed, create a floating dialog window.
|
||||
* **Use `FloatingModal`:** Always create a new instance: `const modal = new ea.FloatingModal(ea.plugin.app);`.
|
||||
* **Do Not Extend:** Do not use `class MyModal extends ea.FloatingModal`.
|
||||
* **Define Behavior:** Assign functions directly to the `onOpen` and `onClose` properties of the instance. Inside `onOpen`, use the `modal.contentEl` property to build your UI.
|
||||
* **Reference Implementation:** The script "Printable Layout Wizard.md" is the canonical example for this pattern. Use `ea.obsidian.Setting` to add controls like toggles and dropdowns within the modal.
|
||||
|
||||
#### **3. Element Manipulation and Querying**
|
||||
|
||||
* **Finding Elements:** The most common starting point is to get the user's selection with `ea.getViewSelectedElements()`. Use standard JavaScript array methods like `.filter()` to narrow down the selection (e.g., `elements.filter(el => el.type === "text")`).
|
||||
* **Geometric Calculations:**
|
||||
* Before performing layout or positioning tasks, use `ea.getBoundingBox(elements)` to get the collective dimensions and position of a group of elements.
|
||||
* Use `ea.measureText(text)` to determine the width and height of a string based on the current `ea.style` settings before creating a text element or a container for it.
|
||||
* **Grouping:**
|
||||
* To create a group, use `ea.addToGroup([elementId1, elementId2, ...])`.
|
||||
* To operate on existing groups within a selection, use `ea.getMaximumGroups(selectedElements)` which correctly identifies the top-level groups. Use `ea.getLargestElement(group)` to find the primary container within a group (e.g., the box around a text element).
|
||||
|
||||
#### **4. Styling: Creation vs. Modification**
|
||||
|
||||
* **For New Elements:** Set the properties on the global `ea.style` object *before* you call a creation function like `ea.addText()` or `ea.addRect()`. This acts like setting the active color/style on a paintbrush.
|
||||
* **For Existing Elements:** To change the style of an existing element, modify the properties directly on the element's copy in the EA workbench (after `copyViewElementsToEAforEditing`). For example: `const myElement = ea.getElement(id); myElement.strokeColor = '#FF0000';`.
|
||||
|
||||
#### **5. Data Persistence and Customization**
|
||||
|
||||
* **Storing Custom Data:** Elements have a `customData` property for arbitrary data.
|
||||
* **Always Use `ea.addAppendUpdateCustomData(id, newData)`:** This is crucial. It safely adds or updates your key-value pairs without overwriting data that might have been stored by other scripts or the Excalidraw plugin itself.
|
||||
* **Creating Configurable Scripts:** To make your script's behavior customizable by the user:
|
||||
* Use `ea.getScriptSettings()` to retrieve saved settings.
|
||||
* Check if settings exist, and if not, define the default structure.
|
||||
* Use `await ea.setScriptSettings(settings)` to save any changes. This allows users to configure your script in the Excalidraw plugin settings pane.
|
||||
|
||||
#### **6. Best Practices and Advanced Techniques**
|
||||
|
||||
* **Embrace `await`:** Many EA functions are asynchronous and return a `Promise` (e.g., `ea.addElementsToView()`, `ea.createSVG()`, `utils.inputPrompt()`). **Always** use `await` when calling these functions to ensure your script executes in the correct order.
|
||||
* **Version Checking:** At the beginning of your script, include a check like `if(!ea.verifyMinimumPluginVersion("1.X.X")) { new Notice(...); return; }` to ensure the user has a compatible version of the Excalidraw plugin, preventing errors from missing API functions.
|
||||
* **Accessing Obsidian API:** The full Obsidian API is available via `ea.obsidian`. For example, use `new ea.obsidian.Notice("message")` or `ea.obsidian.normalizePath(filepath)`.
|
||||
* **Visibility vs. Deletion:**
|
||||
* To temporarily hide an element, set `element.opacity = 0`. It's good practice to store the original opacity in `customData` so it can be restored. It is also recommended to lock hidden elements so they do not get accidentally selected or moved around.
|
||||
* To permanently remove an element from the scene, set `element.isDeleted = true`.
|
||||
* **Image Handling:** When dealing with image elements, use `ea.getViewFileForImageElement(imageElement)` to get the corresponding `TFile` from the Obsidian vault. This is necessary for any logic that needs to read or manipulate the source image file.
|
||||
|
||||
#### **7. Custom Pens and Perfect Freehand**
|
||||
|
||||
Excalidraw's freehand tool is powered by the open-source Perfect Freehand library. The plugin exposes “custom pens” that bundle:
|
||||
- Canvas style for the next strokes (colors, width, fillStyle, roughness).
|
||||
- Perfect Freehand stroke geometry and behavior (pressure simulation, outline, tapering, easing, etc.).
|
||||
|
||||
Key concepts:
|
||||
- AppState-driven drawing: When `appState.currentStrokeOptions` is set, the freedraw tool renders new strokes using those Perfect Freehand options.
|
||||
- Element-level persistence: If a freedraw element has `element.customData.strokeOptions`, it is rendered with those options regardless of the current tool state.
|
||||
- Types reference: See `src/types/penTypes.ts`. The `PenOptions` shape is:
|
||||
```ts
|
||||
interface PenOptions {
|
||||
highlighter: boolean; // if true the pen is drawn at the lowest layer, behind all other elements
|
||||
constantPressure: boolean;
|
||||
hasOutline: boolean;
|
||||
outlineWidth: number;
|
||||
options: {
|
||||
thinning: number;
|
||||
smoothing: number;
|
||||
streamline: number;
|
||||
easing: string; // see supported names below
|
||||
start: { cap: boolean; taper: number | boolean; easing: string; };
|
||||
end: { cap: boolean; taper: number | boolean; easing: string; };
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
Using custom pens from scripts:
|
||||
- Activate a custom pen for drawing:
|
||||
```ts
|
||||
// obtain the Excalidraw API
|
||||
const api = ea.getExcalidrawAPI();
|
||||
|
||||
// define Perfect Freehand options (example similar to "finetip")
|
||||
const penOptions = {
|
||||
highlighter: false,
|
||||
constantPressure: true,
|
||||
hasOutline: false,
|
||||
outlineWidth: 1,
|
||||
options: {
|
||||
thinning: -0.5,
|
||||
smoothing: 0.4,
|
||||
streamline: 0.4,
|
||||
easing: "linear",
|
||||
start: { taper: 5, cap: false, easing: "linear" },
|
||||
end: { taper: 5, cap: false, easing: "linear" },
|
||||
},
|
||||
};
|
||||
|
||||
// apply stroke options + canvas style, then switch to freedraw (strokeWidth, color, background, fillStyle are optional)
|
||||
ea.viewUpdateScene({
|
||||
appState: {
|
||||
currentStrokeOptions: penOptions,
|
||||
currentItemStrokeWidth: 0.5,
|
||||
currentItemStrokeColor: "#3E6F8D",
|
||||
currentItemBackgroundColor: "transparent",
|
||||
currentItemFillStyle: "hachure",
|
||||
},
|
||||
});
|
||||
api.setActiveTool({ type: "freedraw" });
|
||||
```
|
||||
|
||||
- Clear custom pen (revert to default freedraw behavior):
|
||||
```ts
|
||||
ea.viewUpdateScene({ appState: { currentStrokeOptions: null } });
|
||||
```
|
||||
|
||||
- Persist custom strokeOptions onto existing freedraw elements:
|
||||
```ts
|
||||
const selected = ea.getViewSelectedElements().filter(el => el.type === "freedraw");
|
||||
ea.copyViewElementsToEAforEditing(selected);
|
||||
for (const el of selected) {
|
||||
ea.addAppendUpdateCustomData(el.id, { strokeOptions: penOptions });
|
||||
}
|
||||
await ea.addElementsToView();
|
||||
```
|
||||
|
||||
Notes:
|
||||
- New strokes respect `appState.currentStrokeOptions` at draw time. Existing elements only change if you update their `customData.strokeOptions`.
|
||||
- For pens that should behave like real markers/highlighters, set `highlighter: true` and often `constantPressure: true` with an `outlineWidth` for the edge.
|
||||
|
||||
Supported easing names (string values for `options.easing`, `options.start.easing`, `options.end.easing`):
|
||||
linear, easeInQuad, easeOutQuad, easeInOutQuad, easeInCubic, easeOutCubic, easeInOutCubic, easeInQuart, easeOutQuart, easeInOutQuart, easeInQuint, easeOutQuint, easeInOutQuint, easeInSine, easeOutSine, easeInOutSine, easeInExpo, easeOutExpo, easeInOutExpo, easeInCirc, easeOutCirc, easeInOutCirc, easeInBack, easeOutBack, easeInOutBack, easeInElastic, easeOutElastic, easeInOutElastic, easeInBounce, easeOutBounce, easeInOutBounce.
|
||||
|
||||
Example freedraw element carrying `customData.strokeOptions`:
|
||||
```json
|
||||
{"type":"excalidraw/clipboard","elements":[{"id":"...","type":"freedraw","strokeColor":"#3E6F8D","backgroundColor":"transparent","fillStyle":"hachure","strokeWidth":0.5,"roughness":0,"customData":{"strokeOptions":{"highlighter":false,"hasOutline":false,"outlineWidth":0,"constantPressure":true,"options":{"smoothing":0.4,"thinning":-0.5,"streamline":0.4,"easing":"linear","start":{"taper":5,"cap":false,"easing":"linear"},"end":{"taper":5,"cap":false,"easing":"linear"}}}}}],"files":{}}
|
||||
```
|
||||
|
||||
|
||||
---
|
||||
@@ -51,7 +205,8 @@ The Obsidian.md module is available on ea.obsidian.
|
||||
* you may access this object via the variable `ea`. e.g. ea.addImage(); This ea object is already set to the targetView.
|
||||
* Through ea.obsidian all of the Obsidian API is available to the script. Thus you can create modal views, open files, etc.
|
||||
* You can access Obsidian type definitions here: https://github.com/obsidianmd/obsidian-api/blob/master/obsidian.d.ts
|
||||
* In addition to the ea object, the script also receives the `utils` object. utils includes to utility functions: suggester and inputPrompt
|
||||
* In addition to the ea instance, the script also receives the `utils` object. utils includes to utility functions: suggester and inputPrompt.
|
||||
* You may access these via the variable `utils`. e.g. utils.suggester(...);
|
||||
* - inputPrompt(inputPrompt: (
|
||||
* header: string,
|
||||
* placeholder?: string,
|
||||
@@ -2283,7 +2438,6 @@ export interface AppState {
|
||||
};
|
||||
showHyperlinkPopup: false | "info" | "editor";
|
||||
linkOpacity: number;
|
||||
trayModeEnabled: boolean;
|
||||
colorPalette?: {
|
||||
canvasBackground: ColorPaletteCustom;
|
||||
elementBackground: ColorPaletteCustom;
|
||||
@@ -2643,6 +2797,8 @@ export interface ExcalidrawImperativeAPI {
|
||||
setForceRenderAllEmbeddables: InstanceType<typeof App>["setForceRenderAllEmbeddables"];
|
||||
zoomToFit: InstanceType<typeof App>["zoomToFit"];
|
||||
refreshEditorBreakpoints: InstanceType<typeof App>["refreshEditorBreakpoints"];
|
||||
setTrayModeEnabled: InstanceType<typeof App>["setTrayModeEnabled"];
|
||||
isTrayModeEnabled: InstanceType<typeof App>["isTrayModeEnabled"];
|
||||
getColorAtScenePoint: InstanceType<typeof App>["getColorAtScenePoint"];
|
||||
startLineEditor: InstanceType<typeof App>["startLineEditor"];
|
||||
getSceneElements: InstanceType<typeof App>["getSceneElements"];
|
||||
@@ -2690,6 +2846,7 @@ export type Device = Readonly<{
|
||||
canFitSidebar: boolean;
|
||||
};
|
||||
isTouchScreen: boolean;
|
||||
isTrayMode: boolean;
|
||||
}>;
|
||||
export type FrameNameBounds = {
|
||||
x: number;
|
||||
@@ -9791,6 +9948,276 @@ export type IconName = string;
|
||||
```
|
||||
|
||||
|
||||
---
|
||||
|
||||
# ExcalidrawLib module functions
|
||||
|
||||
The following functions are exposed via window.ExcalidrawLib. Signatures are extracted from TypeScript declarations.
|
||||
|
||||
```ts
|
||||
/* ************************************** */
|
||||
/* @excalidraw/element -> node_modules/@zsviczian/excalidraw/types/element/src/index.d.ts */
|
||||
/* ************************************** */
|
||||
export declare const getNonDeletedElements: <T extends ExcalidrawElement>(elements: readonly T[]) => readonly NonDeleted<T>[];
|
||||
export declare const getSceneVersion: (elements: readonly ExcalidrawElement[]) => number;
|
||||
export declare const hashElementsVersion: (elements: ElementsMapOrArray) => number;
|
||||
export declare const hashString: (s: string) => number;
|
||||
|
||||
/* ************************************** */
|
||||
/* ./i18n -> node_modules/@zsviczian/excalidraw/types/excalidraw/i18n.d.ts */
|
||||
/* ************************************** */
|
||||
export declare const defaultLang: {
|
||||
code: string;
|
||||
label: string;
|
||||
};
|
||||
export declare const languages: Language[];
|
||||
export declare const setLanguage: (lang: Language) => Promise<void>;
|
||||
export declare const languages: Language[];
|
||||
export declare const setLanguage: (lang: Language) => Promise<void>;
|
||||
export declare const useI18n: () => {
|
||||
t: (path: NestedKeyOf<typeof fallbackLangData>, replacement?: {
|
||||
[key: string]: string | number;
|
||||
|
||||
/* ************************************** */
|
||||
/* ./data/restore -> node_modules/@zsviczian/excalidraw/types/excalidraw/data/restore.d.ts */
|
||||
/* ************************************** */
|
||||
export declare const restore: (data: Pick<ImportedDataState, "appState" | "elements" | "files"> | null, localAppState: Partial<AppState> | null | undefined, localElements: readonly ExcalidrawElement[] | null | undefined, elementsConfig?: {
|
||||
refreshDimensions?: boolean;
|
||||
repairBindings?: boolean;
|
||||
deleteInvisibleElements?: boolean;
|
||||
}) => RestoredDataState;
|
||||
export declare const restoreAppState: (appState: ImportedDataState["appState"], localAppState: Partial<AppState> | null | undefined) => RestoredAppState;
|
||||
export declare const restoreElement: (element: Exclude<ExcalidrawElement, ExcalidrawSelectionElement>, opts?: {
|
||||
deleteInvisibleElements?: boolean;
|
||||
}) => ExcalidrawLinearElement | import("@excalidraw/element/types").ExcalidrawRectangleElement | import("@excalidraw/element/types").ExcalidrawDiamondElement | import("@excalidraw/element/types").ExcalidrawEllipseElement | import("@excalidraw/element/types").ExcalidrawEmbeddableElement | import("@excalidraw/element/types").ExcalidrawIframeElement | import("@excalidraw/element/types").ExcalidrawImageElement | import("@excalidraw/element/types").ExcalidrawFrameElement | import("@excalidraw/element/types").ExcalidrawMagicFrameElement | ExcalidrawTextElement | import("@excalidraw/element/types").ExcalidrawFreeDrawElement | ExcalidrawArrowElement | null;
|
||||
export declare const restoreElements: (elements: ImportedDataState["elements"], localElements: readonly ExcalidrawElement[] | null | undefined, opts?: {
|
||||
refreshDimensions?: boolean;
|
||||
repairBindings?: boolean;
|
||||
deleteInvisibleElements?: boolean;
|
||||
} | undefined) => OrderedExcalidrawElement[];
|
||||
export declare const restoreLibraryItems: (libraryItems: ImportedDataState["libraryItems"], defaultStatus: LibraryItem["status"]) => LibraryItem[];
|
||||
|
||||
/* ************************************** */
|
||||
/* ./data/reconcile -> node_modules/@zsviczian/excalidraw/types/excalidraw/data/reconcile.d.ts */
|
||||
/* ************************************** */
|
||||
export declare const reconcileElements: (localElements: readonly OrderedExcalidrawElement[], remoteElements: readonly RemoteExcalidrawElement[], localAppState: AppState) => ReconciledExcalidrawElement[];
|
||||
|
||||
/* ************************************** */
|
||||
/* @excalidraw/utils/export -> node_modules/@zsviczian/excalidraw/types/utils/src/export.d.ts */
|
||||
/* ************************************** */
|
||||
export declare const exportToBlob: (opts: ExportOpts & {
|
||||
mimeType?: string;
|
||||
quality?: number;
|
||||
exportPadding?: number;
|
||||
}) => Promise<Blob>;
|
||||
export declare const exportToCanvas: ({ elements, appState, files, maxWidthOrHeight, getDimensions, exportPadding, exportingFrame, }: ExportOpts & {
|
||||
exportPadding?: number | undefined;
|
||||
}) => Promise<HTMLCanvasElement>;
|
||||
export declare const exportToClipboard: (opts: ExportOpts & {
|
||||
mimeType?: string;
|
||||
quality?: number;
|
||||
type: "png" | "svg" | "json";
|
||||
}) => Promise<void>;
|
||||
export declare const exportToSvg: ({ elements, appState, files, exportPadding, renderEmbeddables, exportingFrame, skipInliningFonts, reuseImages, }: Omit<ExportOpts, "getDimensions"> & {
|
||||
exportPadding?: number | undefined;
|
||||
renderEmbeddables?: boolean | undefined;
|
||||
skipInliningFonts?: true | undefined;
|
||||
reuseImages?: boolean | undefined;
|
||||
}) => Promise<SVGSVGElement>;
|
||||
|
||||
/* ************************************** */
|
||||
/* @excalidraw/element/bounds -> node_modules/@zsviczian/excalidraw/types/element/src/bounds.d.ts */
|
||||
/* ************************************** */
|
||||
export declare const getCommonBoundingBox: (elements: readonly ExcalidrawElement[] | readonly NonDeleted<ExcalidrawElement>[]) => BoundingBox;
|
||||
|
||||
/* ************************************** */
|
||||
/* @excalidraw/element/groups -> node_modules/@zsviczian/excalidraw/types/element/src/groups.d.ts */
|
||||
/* ************************************** */
|
||||
export declare const getMaximumGroups: (elements: ExcalidrawElement[], elementsMap: ElementsMap) => ExcalidrawElement[][];
|
||||
|
||||
/* ************************************** */
|
||||
/* @excalidraw/element/binding -> node_modules/@zsviczian/excalidraw/types/element/src/binding.d.ts */
|
||||
/* ************************************** */
|
||||
export declare const determineFocusDistance: (element: ExcalidrawBindableElement, elementsMap: ElementsMap, a: GlobalPoint, b: GlobalPoint) => number;
|
||||
|
||||
/* ************************************** */
|
||||
/* @excalidraw/element/textMeasurements -> node_modules/@zsviczian/excalidraw/types/element/src/textMeasurements.d.ts */
|
||||
/* ************************************** */
|
||||
export declare const measureText: (text: string, font: FontString, lineHeight: ExcalidrawTextElement["lineHeight"]) => {
|
||||
width: number;
|
||||
|
||||
/* ************************************** */
|
||||
/* @excalidraw/element/textWrapping -> node_modules/@zsviczian/excalidraw/types/element/src/textWrapping.d.ts */
|
||||
/* ************************************** */
|
||||
export declare const wrapText: (text: string, font: FontString, maxWidth: number) => string;
|
||||
|
||||
/* ************************************** */
|
||||
/* @excalidraw/element/textElement -> node_modules/@zsviczian/excalidraw/types/element/src/textElement.d.ts */
|
||||
/* ************************************** */
|
||||
export declare const getBoundTextMaxWidth: (container: ExcalidrawElement, boundTextElement: ExcalidrawTextElement | null) => number;
|
||||
export declare const getContainerElement: (element: ExcalidrawTextElement | null, elementsMap: ElementsMap) => ExcalidrawTextContainer | null;
|
||||
|
||||
/* ************************************** */
|
||||
/* ./components/TTDDialog/MermaidToExcalidrawLib -> node_modules/@zsviczian/excalidraw/types/excalidraw/components/TTDDialog/MermaidToExcalidrawLib.d.ts */
|
||||
/* ************************************** */
|
||||
export declare const mermaidToExcalidraw: (mermaidDefinition: string, opts: MermaidConfig, forceSVG?: boolean) => Promise<{
|
||||
elements?: ExcalidrawElement[];
|
||||
|
||||
/* ************************************** */
|
||||
/* ../excalidraw/obsidianUtils -> node_modules/@zsviczian/excalidraw/types/excalidraw/obsidianUtils.d.ts */
|
||||
/* ************************************** */
|
||||
export declare function destroyObsidianUtils(): void;
|
||||
export declare function getCSSFontDefinition(fontFamily: number): Promise<string>;
|
||||
export declare function getFontFamilies(): string[];
|
||||
export declare function getFontMetrics(fontFamily: ExcalidrawTextElement["fontFamily"], fontSize?: number): {
|
||||
unitsPerEm: number;
|
||||
export declare function getSharedMermaidInstance(): Promise<MermaidToExcalidrawLibProps>;
|
||||
export declare const intersectElementWithLine: (element: ExcalidrawElement, a: GlobalPoint, b: GlobalPoint, gap: number | undefined, elementsMap: ElementsMap) => GlobalPoint[] | undefined;
|
||||
export declare function loadMermaid(): Promise<MermaidToExcalidrawLibProps>;
|
||||
export declare function loadSceneFonts(elements: NonDeletedExcalidrawElement[]): Promise<FontFace[]>;
|
||||
export declare function registerFontsInCSS(): Promise<void>;
|
||||
export declare function registerLocalFont(fontMetrics: FontMetadata & {
|
||||
name: string;
|
||||
|
||||
/* ************************************** */
|
||||
/* @excalidraw/element/newElement -> node_modules/@zsviczian/excalidraw/types/element/src/newElement.d.ts */
|
||||
/* ************************************** */
|
||||
export declare const refreshTextDimensions: (textElement: ExcalidrawTextElement, container: ExcalidrawTextContainer | null, elementsMap: ElementsMap, text?: string) => {
|
||||
x: number;
|
||||
|
||||
/* ************************************** */
|
||||
/* ./data/json -> node_modules/@zsviczian/excalidraw/types/excalidraw/data/json.d.ts */
|
||||
/* ************************************** */
|
||||
export declare const serializeAsJSON: (elements: readonly ExcalidrawElement[], appState: Partial<AppState>, files: BinaryFiles, type: "local" | "database") => string;
|
||||
export declare const serializeLibraryAsJSON: (libraryItems: LibraryItems) => string;
|
||||
|
||||
/* ************************************** */
|
||||
/* ./data/blob -> node_modules/@zsviczian/excalidraw/types/excalidraw/data/blob.d.ts */
|
||||
/* ************************************** */
|
||||
export declare const getDataURL: (file: Blob | File) => Promise<DataURL>;
|
||||
export declare const loadFromBlob: (blob: Blob, localAppState: AppState | null, localElements: readonly ExcalidrawElement[] | null, fileHandle?: FileSystemHandle | null) => Promise<import("./restore").RestoredDataState>;
|
||||
export declare const loadLibraryFromBlob: (blob: Blob, defaultStatus?: LibraryItem["status"]) => Promise<LibraryItem[]>;
|
||||
export declare const loadSceneOrLibraryFromBlob: (blob: Blob | File, localAppState: AppState | null, localElements: readonly ExcalidrawElement[] | null, fileHandle?: FileSystemHandle | null) => Promise<{
|
||||
type: "application/vnd.excalidraw+json";
|
||||
|
||||
/* ************************************** */
|
||||
/* ./data/library -> node_modules/@zsviczian/excalidraw/types/excalidraw/data/library.d.ts */
|
||||
/* ************************************** */
|
||||
export declare const getLibraryItemsHash: (items: LibraryItems) => number;
|
||||
export declare const mergeLibraryItems: (localItems: LibraryItems, otherItems: LibraryItems) => LibraryItems;
|
||||
export declare const parseLibraryTokensFromUrl: () => {
|
||||
libraryUrl: string;
|
||||
export declare const useHandleLibrary: (opts: {
|
||||
excalidrawAPI: ExcalidrawImperativeAPI | null;
|
||||
/**
|
||||
* Return `true` if the library install url should be allowed.
|
||||
* If not supplied, only the excalidraw.com base domain is allowed.
|
||||
*/
|
||||
validateLibraryUrl?: ((libraryUrl: string) => boolean) | undefined;
|
||||
|
||||
/* ************************************** */
|
||||
/* @excalidraw/element/embeddable -> node_modules/@zsviczian/excalidraw/types/element/src/embeddable.d.ts */
|
||||
/* ************************************** */
|
||||
export declare const getEmbedLink: (link: string | null | undefined) => IframeDataWithSandbox | null;
|
||||
|
||||
/* ************************************** */
|
||||
/* ./components/Sidebar/Sidebar -> node_modules/@zsviczian/excalidraw/types/excalidraw/components/Sidebar/Sidebar.d.ts */
|
||||
/* ************************************** */
|
||||
export declare const Sidebar: React.ForwardRefExoticComponent<{
|
||||
name: string;
|
||||
children: React.ReactNode;
|
||||
onStateChange?: ((state: {
|
||||
name: string;
|
||||
tab?: string | undefined;
|
||||
} | null) => void) | undefined;
|
||||
|
||||
/* ************************************** */
|
||||
/* ./components/Button -> node_modules/@zsviczian/excalidraw/types/excalidraw/components/Button.d.ts */
|
||||
/* ************************************** */
|
||||
export declare const Button: ({ type, onSelect, selected, children, className, ...rest }: ButtonProps) => import("react/jsx-runtime").JSX.Element;
|
||||
|
||||
/* ************************************** */
|
||||
/* ./components/App -> node_modules/@zsviczian/excalidraw/types/excalidraw/components/App.d.ts */
|
||||
/* ************************************** */
|
||||
export declare const useDevice: () => Readonly<{
|
||||
viewport: {
|
||||
isMobile: boolean;
|
||||
|
||||
/* ************************************** */
|
||||
/* ./components/DefaultSidebar -> node_modules/@zsviczian/excalidraw/types/excalidraw/components/DefaultSidebar.d.ts */
|
||||
/* ************************************** */
|
||||
export declare const DefaultSidebar: import("react").FC<Omit<MarkOptional<Omit<{
|
||||
name: string;
|
||||
children: import("react").ReactNode;
|
||||
onStateChange?: ((state: {
|
||||
name: string;
|
||||
tab?: string | undefined;
|
||||
} | null) => void) | undefined;
|
||||
|
||||
/* ************************************** */
|
||||
/* ./components/TTDDialog/TTDDialog -> node_modules/@zsviczian/excalidraw/types/excalidraw/components/TTDDialog/TTDDialog.d.ts */
|
||||
/* ************************************** */
|
||||
export declare const TTDDialog: (props: {
|
||||
onTextSubmit(value: string): Promise<OnTestSubmitRetValue>;
|
||||
} | {
|
||||
__fallback: true;
|
||||
}) => import("react/jsx-runtime").JSX.Element | null;
|
||||
|
||||
/* ************************************** */
|
||||
/* ./actions/actionCanvas -> node_modules/@zsviczian/excalidraw/types/excalidraw/actions/actionCanvas.d.ts */
|
||||
/* ************************************** */
|
||||
export declare const zoomToFitBounds: ({ bounds, appState, canvasOffsets, fitToViewport, viewportZoomFactor, minZoom, maxZoom, }: {
|
||||
bounds: SceneBounds;
|
||||
canvasOffsets?: Partial<{
|
||||
top: number;
|
||||
right: number;
|
||||
bottom: number;
|
||||
left: number;
|
||||
}> | undefined;
|
||||
appState: Readonly<AppState>;
|
||||
/** whether to fit content to viewport (beyond >100%) */
|
||||
fitToViewport: boolean;
|
||||
/** zoom content to cover X of the viewport, when fitToViewport=true */
|
||||
viewportZoomFactor?: number | undefined;
|
||||
minZoom?: number | undefined;
|
||||
maxZoom?: number | undefined;
|
||||
}) => {
|
||||
appState: {
|
||||
scrollX: number;
|
||||
|
||||
/* ************************************** */
|
||||
/* ./data/transform -> node_modules/@zsviczian/excalidraw/types/excalidraw/data/transform.d.ts */
|
||||
/* ************************************** */
|
||||
export declare const convertToExcalidrawElements: (elementsSkeleton: ExcalidrawElementSkeleton[] | null, opts?: {
|
||||
regenerateIds: boolean;
|
||||
}) => import("@excalidraw/element/types").OrderedExcalidrawElement[];
|
||||
|
||||
/* ************************************** */
|
||||
/* @excalidraw/utils/withinBounds -> node_modules/@zsviczian/excalidraw/types/utils/src/withinBounds.d.ts */
|
||||
/* ************************************** */
|
||||
export declare const elementPartiallyOverlapsWithOrContainsBBox: (element: Element, bbox: Bounds) => boolean;
|
||||
export declare const elementsOverlappingBBox: ({ elements, bounds, type, errorMargin, }: {
|
||||
elements: Elements;
|
||||
bounds: Bounds | ExcalidrawElement;
|
||||
/** safety offset. Defaults to 0. */
|
||||
errorMargin?: number | undefined;
|
||||
/**
|
||||
* - overlap: elements overlapping or inside bounds
|
||||
* - contain: elements inside bounds or bounds inside elements
|
||||
* - inside: elements inside bounds
|
||||
**/
|
||||
type: "overlap" | "contain" | "inside";
|
||||
}) => NonDeletedExcalidrawElement[];
|
||||
export declare const isElementInsideBBox: (element: Element, bbox: Bounds, eitherDirection?: boolean) => boolean;
|
||||
|
||||
/* ************************************** */
|
||||
/* ./components/DiagramToCodePlugin/DiagramToCodePlugin -> node_modules/@zsviczian/excalidraw/types/excalidraw/components/DiagramToCodePlugin/DiagramToCodePlugin.d.ts */
|
||||
/* ************************************** */
|
||||
export declare const DiagramToCodePlugin: (props: {
|
||||
generate: GenerateDiagramToCode;
|
||||
}) => null;
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# Excalidraw Script Library Examples
|
||||
@@ -9807,7 +10234,7 @@ Content structure:
|
||||
2. The curated script overview (index-new.md)
|
||||
3. Raw source of every *.md script in /ea-scripts (each fenced code block is auto-closed to ensure well-formed aggregation)
|
||||
|
||||
Generated on: 2025-10-24T11:36:13.143Z
|
||||
Generated on: 2025-11-03T18:33:17.385Z
|
||||
|
||||
---
|
||||
|
||||
@@ -19434,6 +19861,7 @@ async function run() {
|
||||
// Initialize state
|
||||
let uiHidden = true;
|
||||
let currentIcon = "eye";
|
||||
let layerUIWrapper = ea.targetView.contentEl.querySelector(".excalidraw.excalidraw-container > .layer-ui__wrapper");
|
||||
const toolbar = ea.targetView.contentEl.querySelector(".excalidraw > .Island");
|
||||
let toolbarActive = toolbar?.style.display === "block";
|
||||
let prevHiddenState = false;
|
||||
@@ -19442,30 +19870,40 @@ async function run() {
|
||||
const toggleUIVisibility = (hidden) => {
|
||||
if(hidden === prevHiddenState) return hidden;
|
||||
prevHiddenState = hidden;
|
||||
try{
|
||||
const topBar = ea.targetView.containerEl.querySelector(".App-top-bar");
|
||||
const bottomBar = ea.targetView.containerEl.querySelector(".App-bottom-bar");
|
||||
const sidebarToggle = ea.targetView.containerEl.querySelector(".sidebar-toggle");
|
||||
const plugins = ea.targetView.containerEl.querySelector(".plugins-container");
|
||||
|
||||
if(hidden) {
|
||||
if (toolbarActive && (toolbar?.style.display === "none")) {
|
||||
toolbarActive = false;
|
||||
if (!!layerUIWrapper) {
|
||||
try {
|
||||
if(hidden) {
|
||||
layerUIWrapper.style.display = "none";
|
||||
} else {
|
||||
layerUIWrapper.style.display = "block";
|
||||
}
|
||||
} catch {};
|
||||
} else {
|
||||
try{
|
||||
const topBar = ea.targetView.containerEl.querySelector(".App-top-bar");
|
||||
const bottomBar = ea.targetView.containerEl.querySelector(".App-bottom-bar");
|
||||
const sidebarToggle = ea.targetView.containerEl.querySelector(".sidebar-toggle");
|
||||
const plugins = ea.targetView.containerEl.querySelector(".plugins-container");
|
||||
|
||||
if(hidden) {
|
||||
if (toolbarActive && (toolbar?.style.display === "none")) {
|
||||
toolbarActive = false;
|
||||
}
|
||||
if (toolbarActive = toolbar?.style.display === "block") {
|
||||
toolbarActive = true;
|
||||
};
|
||||
}
|
||||
if (toolbarActive = toolbar?.style.display === "block") {
|
||||
toolbarActive = true;
|
||||
};
|
||||
}
|
||||
|
||||
const display = hidden ? "none" : "";
|
||||
|
||||
if (topBar) topBar.style.display = display;
|
||||
if (bottomBar) bottomBar.style.display = display;
|
||||
if (sidebarToggle) sidebarToggle.style.display = display;
|
||||
if (plugins) plugins.style.display = display;
|
||||
if (toolbarActive) toolbar.style.display = hidden ? "none" : "block";
|
||||
modal.modalEl.style.opacity = hidden ? "0.4" : "0.8";
|
||||
} catch {};
|
||||
|
||||
const display = hidden ? "none" : "";
|
||||
|
||||
if (topBar) topBar.style.display = display;
|
||||
if (bottomBar) bottomBar.style.display = display;
|
||||
if (sidebarToggle) sidebarToggle.style.display = display;
|
||||
if (plugins) plugins.style.display = display;
|
||||
if (toolbarActive) toolbar.style.display = hidden ? "none" : "block";
|
||||
modal.modalEl.style.opacity = hidden ? "0.4" : "0.8";
|
||||
} catch {};
|
||||
};
|
||||
return hidden;
|
||||
};
|
||||
|
||||
|
||||
@@ -3011,7 +3011,7 @@ Fix:
|
||||
- Transcluded text will now exclude ^block-references at end of lines
|
||||
- Phantom duplicates of the drawing appear when "zoom to fit" results in a zoom value below 10% and there are many objects on the canvas [#850](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/850)
|
||||
- CTRL+Wheel will increase/decrease zoom in steps of 5% matching the behavior of the "+" & "-" zoom buttons.
|
||||
- Latest updates from Excalidarw.com
|
||||
- Latest updates from Excalidraw.com
|
||||
- Freedraw flip not scaling correctly [#5752](https://github.com/excalidraw/excalidraw/pull/5752)
|
||||
- Multiple elements resizing regressions [#5586](https://github.com/excalidraw/excalidraw/pull/5586)
|
||||
|
||||
@@ -4339,7 +4339,7 @@ Fixed:
|
||||
|
||||
# 1.5.8
|
||||
|
||||
- minor fix to ExcalidarwAutomate addText to handle non-container bound text wrapping correctly.
|
||||
- minor fix to ExcalidrawAutomate addText to handle non-container bound text wrapping correctly.
|
||||
|
||||
# 1.5.7
|
||||
|
||||
|
||||
@@ -3011,7 +3011,7 @@ Fix:
|
||||
- Transcluded text will now exclude ^block-references at end of lines
|
||||
- Phantom duplicates of the drawing appear when "zoom to fit" results in a zoom value below 10% and there are many objects on the canvas [#850](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/850)
|
||||
- CTRL+Wheel will increase/decrease zoom in steps of 5% matching the behavior of the "+" & "-" zoom buttons.
|
||||
- Latest updates from Excalidarw.com
|
||||
- Latest updates from Excalidraw.com
|
||||
- Freedraw flip not scaling correctly [#5752](https://github.com/excalidraw/excalidraw/pull/5752)
|
||||
- Multiple elements resizing regressions [#5586](https://github.com/excalidraw/excalidraw/pull/5586)
|
||||
|
||||
@@ -4339,7 +4339,7 @@ Fixed:
|
||||
|
||||
# 1.5.8
|
||||
|
||||
- minor fix to ExcalidarwAutomate addText to handle non-container bound text wrapping correctly.
|
||||
- minor fix to ExcalidrawAutomate addText to handle non-container bound text wrapping correctly.
|
||||
|
||||
# 1.5.7
|
||||
|
||||
|
||||
+34
-23
@@ -47,6 +47,7 @@ async function run() {
|
||||
// Initialize state
|
||||
let uiHidden = true;
|
||||
let currentIcon = "eye";
|
||||
let layerUIWrapper = ea.targetView.contentEl.querySelector(".excalidraw.excalidraw-container > .layer-ui__wrapper");
|
||||
const toolbar = ea.targetView.contentEl.querySelector(".excalidraw > .Island");
|
||||
let toolbarActive = toolbar?.style.display === "block";
|
||||
let prevHiddenState = false;
|
||||
@@ -55,30 +56,40 @@ async function run() {
|
||||
const toggleUIVisibility = (hidden) => {
|
||||
if(hidden === prevHiddenState) return hidden;
|
||||
prevHiddenState = hidden;
|
||||
try{
|
||||
const topBar = ea.targetView.containerEl.querySelector(".App-top-bar");
|
||||
const bottomBar = ea.targetView.containerEl.querySelector(".App-bottom-bar");
|
||||
const sidebarToggle = ea.targetView.containerEl.querySelector(".sidebar-toggle");
|
||||
const plugins = ea.targetView.containerEl.querySelector(".plugins-container");
|
||||
|
||||
if(hidden) {
|
||||
if (toolbarActive && (toolbar?.style.display === "none")) {
|
||||
toolbarActive = false;
|
||||
if (!!layerUIWrapper) {
|
||||
try {
|
||||
if(hidden) {
|
||||
layerUIWrapper.style.display = "none";
|
||||
} else {
|
||||
layerUIWrapper.style.display = "block";
|
||||
}
|
||||
} catch {};
|
||||
} else {
|
||||
try{
|
||||
const topBar = ea.targetView.containerEl.querySelector(".App-top-bar");
|
||||
const bottomBar = ea.targetView.containerEl.querySelector(".App-bottom-bar");
|
||||
const sidebarToggle = ea.targetView.containerEl.querySelector(".sidebar-toggle");
|
||||
const plugins = ea.targetView.containerEl.querySelector(".plugins-container");
|
||||
|
||||
if(hidden) {
|
||||
if (toolbarActive && (toolbar?.style.display === "none")) {
|
||||
toolbarActive = false;
|
||||
}
|
||||
if (toolbarActive = toolbar?.style.display === "block") {
|
||||
toolbarActive = true;
|
||||
};
|
||||
}
|
||||
if (toolbarActive = toolbar?.style.display === "block") {
|
||||
toolbarActive = true;
|
||||
};
|
||||
}
|
||||
|
||||
const display = hidden ? "none" : "";
|
||||
|
||||
if (topBar) topBar.style.display = display;
|
||||
if (bottomBar) bottomBar.style.display = display;
|
||||
if (sidebarToggle) sidebarToggle.style.display = display;
|
||||
if (plugins) plugins.style.display = display;
|
||||
if (toolbarActive) toolbar.style.display = hidden ? "none" : "block";
|
||||
modal.modalEl.style.opacity = hidden ? "0.4" : "0.8";
|
||||
} catch {};
|
||||
|
||||
const display = hidden ? "none" : "";
|
||||
|
||||
if (topBar) topBar.style.display = display;
|
||||
if (bottomBar) bottomBar.style.display = display;
|
||||
if (sidebarToggle) sidebarToggle.style.display = display;
|
||||
if (plugins) plugins.style.display = display;
|
||||
if (toolbarActive) toolbar.style.display = hidden ? "none" : "block";
|
||||
modal.modalEl.style.opacity = hidden ? "0.4" : "0.8";
|
||||
} catch {};
|
||||
};
|
||||
return hidden;
|
||||
};
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
[{"fname":"Mindmap connector.md","mtime":1658686599427},{"fname":"Mindmap connector.svg","mtime":1658686599427},{"fname":"Add Connector Point.md","mtime":1735420748564},{"fname":"Add Connector Point.svg","mtime":1645944722000},{"fname":"Add Link to Existing File and Open.md","mtime":1647807918345},{"fname":"Add Link to Existing File and Open.svg","mtime":1645964261000},{"fname":"Add Link to New Page and Open.md","mtime":1654168862138},{"fname":"Add Link to New Page and Open.svg","mtime":1645960639000},{"fname":"Add Next Step in Process.md","mtime":1688304760357},{"fname":"Add Next Step in Process.svg","mtime":1645960639000},{"fname":"Box Each Selected Groups.md","mtime":1645305706000},{"fname":"Box Each Selected Groups.svg","mtime":1645967510000},{"fname":"Box Selected Elements.md","mtime":1645305706000},{"fname":"Box Selected Elements.svg","mtime":1645960639000},{"fname":"Change shape of selected elements.md","mtime":1652701169236},{"fname":"Change shape of selected elements.svg","mtime":1645960775000},{"fname":"Connect elements.md","mtime":1645305706000},{"fname":"Connect elements.svg","mtime":1645960639000},{"fname":"Convert freedraw to line.md","mtime":1645305706000},{"fname":"Convert freedraw to line.svg","mtime":1645960639000},{"fname":"Convert selected text elements to sticky notes.md","mtime":1670169501383},{"fname":"Convert selected text elements to sticky notes.svg","mtime":1645960639000},{"fname":"Convert text to link with folder and alias.md","mtime":1641639819000},{"fname":"Convert text to link with folder and alias.svg","mtime":1645960639000},{"fname":"Copy Selected Element Styles to Global.md","mtime":1642232088000},{"fname":"Copy Selected Element Styles to Global.svg","mtime":1645960639000},{"fname":"Create new markdown file and embed into active drawing.md","mtime":1640866935000},{"fname":"Create new markdown file and embed into active drawing.svg","mtime":1645960639000},{"fname":"Darken background color.md","mtime":1663059051059},{"fname":"Darken background color.svg","mtime":1645960639000},{"fname":"Elbow connectors.md","mtime":1671126911490},{"fname":"Elbow connectors.svg","mtime":1645960639000},{"fname":"Expand rectangles horizontally keep text centered.md","mtime":1646563692000},{"fname":"Expand rectangles horizontally keep text centered.svg","mtime":1645967510000},{"fname":"Expand rectangles horizontally.md","mtime":1644950235000},{"fname":"Expand rectangles horizontally.svg","mtime":1645967510000},{"fname":"Expand rectangles vertically keep text centered.md","mtime":1646563692000},{"fname":"Expand rectangles vertically keep text centered.svg","mtime":1645967510000},{"fname":"Expand rectangles vertically.md","mtime":1658686599427},{"fname":"Expand rectangles vertically.svg","mtime":1645967510000},{"fname":"Fixed horizontal distance between centers.md","mtime":1646743234000},{"fname":"Fixed horizontal distance between centers.svg","mtime":1645960639000},{"fname":"Fixed inner distance.md","mtime":1646743234000},{"fname":"Fixed inner distance.svg","mtime":1645960639000},{"fname":"Fixed spacing.md","mtime":1646743234000},{"fname":"Fixed spacing.svg","mtime":1645967510000},{"fname":"Fixed vertical distance between centers.md","mtime":1646743234000},{"fname":"Fixed vertical distance between centers.svg","mtime":1645967510000},{"fname":"Fixed vertical distance.md","mtime":1646743234000},{"fname":"Fixed vertical distance.svg","mtime":1645967510000},{"fname":"Lighten background color.md","mtime":1663059051059},{"fname":"Lighten background color.svg","mtime":1645959546000},{"fname":"Modify background color opacity.md","mtime":1644924415000},{"fname":"Modify background color opacity.svg","mtime":1645944722000},{"fname":"Normalize Selected Arrows.md","mtime":1670403743278},{"fname":"Normalize Selected Arrows.svg","mtime":1645960639000},{"fname":"Organic Line.md","mtime":1672920172531},{"fname":"Organic Line.svg","mtime":1645964261000},{"fname":"Organic Line Legacy.md","mtime":1690607372668},{"fname":"Organic Line Legacy.svg","mtime":1690607372668},{"fname":"README.md","mtime":1645175700000},{"fname":"Repeat Elements.md","mtime":1663059051059},{"fname":"Repeat Elements.svg","mtime":1645960639000},{"fname":"Reverse arrows.md","mtime":1645305706000},{"fname":"Reverse arrows.svg","mtime":1645960639000},{"fname":"Scribble Helper.md","mtime":1747585400113},{"fname":"Scribble Helper.svg","mtime":1645944722000},{"fname":"Select Elements of Type.md","mtime":1643464321000},{"fname":"Select Elements of Type.svg","mtime":1645960639000},{"fname":"Set Dimensions.md","mtime":1645305706000},{"fname":"Set Dimensions.svg","mtime":1645944722000},{"fname":"Set Font Family.md","mtime":1645305706000},{"fname":"Set Font Family.svg","mtime":1645944722000},{"fname":"Set Grid.md","mtime":1693725826368},{"fname":"Set Grid.svg","mtime":1645960639000},{"fname":"Set Link Alias.md","mtime":1645305706000},{"fname":"Set Link Alias.svg","mtime":1645960639000},{"fname":"Set Stroke Width of Selected Elements.md","mtime":1748189277Line truncated
|
||||
[{"fname":"Mindmap connector.md","mtime":1658686599427},{"fname":"Mindmap connector.svg","mtime":1658686599427},{"fname":"Add Connector Point.md","mtime":1735420748564},{"fname":"Add Connector Point.svg","mtime":1645944722000},{"fname":"Add Link to Existing File and Open.md","mtime":1647807918345},{"fname":"Add Link to Existing File and Open.svg","mtime":1645964261000},{"fname":"Add Link to New Page and Open.md","mtime":1654168862138},{"fname":"Add Link to New Page and Open.svg","mtime":1645960639000},{"fname":"Add Next Step in Process.md","mtime":1688304760357},{"fname":"Add Next Step in Process.svg","mtime":1645960639000},{"fname":"Box Each Selected Groups.md","mtime":1645305706000},{"fname":"Box Each Selected Groups.svg","mtime":1645967510000},{"fname":"Box Selected Elements.md","mtime":1645305706000},{"fname":"Box Selected Elements.svg","mtime":1645960639000},{"fname":"Change shape of selected elements.md","mtime":1652701169236},{"fname":"Change shape of selected elements.svg","mtime":1645960775000},{"fname":"Connect elements.md","mtime":1645305706000},{"fname":"Connect elements.svg","mtime":1645960639000},{"fname":"Convert freedraw to line.md","mtime":1645305706000},{"fname":"Convert freedraw to line.svg","mtime":1645960639000},{"fname":"Convert selected text elements to sticky notes.md","mtime":1670169501383},{"fname":"Convert selected text elements to sticky notes.svg","mtime":1645960639000},{"fname":"Convert text to link with folder and alias.md","mtime":1641639819000},{"fname":"Convert text to link with folder and alias.svg","mtime":1645960639000},{"fname":"Copy Selected Element Styles to Global.md","mtime":1642232088000},{"fname":"Copy Selected Element Styles to Global.svg","mtime":1645960639000},{"fname":"Create new markdown file and embed into active drawing.md","mtime":1640866935000},{"fname":"Create new markdown file and embed into active drawing.svg","mtime":1645960639000},{"fname":"Darken background color.md","mtime":1663059051059},{"fname":"Darken background color.svg","mtime":1645960639000},{"fname":"Elbow connectors.md","mtime":1671126911490},{"fname":"Elbow connectors.svg","mtime":1645960639000},{"fname":"Expand rectangles horizontally keep text centered.md","mtime":1646563692000},{"fname":"Expand rectangles horizontally keep text centered.svg","mtime":1645967510000},{"fname":"Expand rectangles horizontally.md","mtime":1644950235000},{"fname":"Expand rectangles horizontally.svg","mtime":1645967510000},{"fname":"Expand rectangles vertically keep text centered.md","mtime":1646563692000},{"fname":"Expand rectangles vertically keep text centered.svg","mtime":1645967510000},{"fname":"Expand rectangles vertically.md","mtime":1658686599427},{"fname":"Expand rectangles vertically.svg","mtime":1645967510000},{"fname":"Fixed horizontal distance between centers.md","mtime":1646743234000},{"fname":"Fixed horizontal distance between centers.svg","mtime":1645960639000},{"fname":"Fixed inner distance.md","mtime":1646743234000},{"fname":"Fixed inner distance.svg","mtime":1645960639000},{"fname":"Fixed spacing.md","mtime":1646743234000},{"fname":"Fixed spacing.svg","mtime":1645967510000},{"fname":"Fixed vertical distance between centers.md","mtime":1646743234000},{"fname":"Fixed vertical distance between centers.svg","mtime":1645967510000},{"fname":"Fixed vertical distance.md","mtime":1646743234000},{"fname":"Fixed vertical distance.svg","mtime":1645967510000},{"fname":"Lighten background color.md","mtime":1663059051059},{"fname":"Lighten background color.svg","mtime":1645959546000},{"fname":"Modify background color opacity.md","mtime":1644924415000},{"fname":"Modify background color opacity.svg","mtime":1645944722000},{"fname":"Normalize Selected Arrows.md","mtime":1670403743278},{"fname":"Normalize Selected Arrows.svg","mtime":1645960639000},{"fname":"Organic Line.md","mtime":1672920172531},{"fname":"Organic Line.svg","mtime":1645964261000},{"fname":"Organic Line Legacy.md","mtime":1690607372668},{"fname":"Organic Line Legacy.svg","mtime":1690607372668},{"fname":"README.md","mtime":1645175700000},{"fname":"Repeat Elements.md","mtime":1663059051059},{"fname":"Repeat Elements.svg","mtime":1645960639000},{"fname":"Reverse arrows.md","mtime":1645305706000},{"fname":"Reverse arrows.svg","mtime":1645960639000},{"fname":"Scribble Helper.md","mtime":1747585400113},{"fname":"Scribble Helper.svg","mtime":1645944722000},{"fname":"Select Elements of Type.md","mtime":1643464321000},{"fname":"Select Elements of Type.svg","mtime":1645960639000},{"fname":"Set Dimensions.md","mtime":1645305706000},{"fname":"Set Dimensions.svg","mtime":1645944722000},{"fname":"Set Font Family.md","mtime":1645305706000},{"fname":"Set Font Family.svg","mtime":1645944722000},{"fname":"Set Grid.md","mtime":1693725826368},{"fname":"Set Grid.svg","mtime":1645960639000},{"fname":"Set Link Alias.md","mtime":1645305706000},{"fname":"Set Link Alias.svg","mtime":1645960639000},{"fname":"Set Stroke Width of Selected Elements.md","mtime":1748189277Line truncated
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "obsidian-excalidraw-plugin",
|
||||
"name": "Excalidraw",
|
||||
"version": "2.17.0-beta-1",
|
||||
"version": "2.17.0-beta-6",
|
||||
"minAppVersion": "1.5.7",
|
||||
"description": "An Obsidian plugin to edit and view Excalidraw drawings",
|
||||
"author": "Zsolt Viczian",
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@popperjs/core": "^2.11.8",
|
||||
"@zsviczian/excalidraw": "0.18.0-42",
|
||||
"@zsviczian/excalidraw": "0.18.0-48",
|
||||
"chroma-js": "^3.1.2",
|
||||
"clsx": "^2.0.0",
|
||||
"@zsviczian/colormaster": "^1.2.2",
|
||||
|
||||
@@ -17,9 +17,163 @@ Excalidraw-Obsidian is an Obsidian.md plugins that is built on the open source E
|
||||
|
||||
Read the information below and respond with I'm ready. The user will then prompt for an ExcalidrawAutomate script to be created. Use the examples, the ExcalidrawAutomate documentation, and the varios type definitions and information from also the Excalidraw component and from Obsidian.md to generate the script based on the user's requirements.
|
||||
|
||||
When the user asks for a dialog window, by default create a FloatingModal.
|
||||
In addition to ExcalidrawAutomate, you can also use two other sources of functions:
|
||||
- The Excalidraw API available via ea.getExcalidrawAPI(). Note: the API is only available if ea.targetView is set. When running Excalidraw scripts using the script engine, the provided ea object is already set up with targetView by default. Otherwise you need to first run ea.setView().
|
||||
- window.ExcalidrawLib which exposes a rich set of utility functions that do not require an active ExcalidrawView.
|
||||
|
||||
The Obsidian.md module is available on ea.obsidian.
|
||||
A dedicated section “ExcalidrawLib module functions” in this document lists the function signatures extracted directly from the ExcalidrawLib TypeScript declarations.
|
||||
|
||||
- When the user asks for a dialog window, by default create a FloatingModal. Do not extend the FloatingModal class. Instead, define the modal's behavior by creating a new instance (e.g., const modal = new ea.FloatingModal(...)) and then assigning functions directly to the onOpen and onClose properties of that instance.
|
||||
For a reference, follow the implementation pattern used in the "Printable Layout Wizard.md" script.
|
||||
- Elements have a customData property that can be used to store arbitrary data. To ensure the data the script adds to elements use the ea.addAppendUpdateCustomData function. This function ensures that existing customData is preserved when adding new data.
|
||||
- Elements can be hidden by setting their opacity to 0. When hiding elements this way, it is good practice to temporarily store their original opacity in customData. This allows for easy restoration of the original opacity later.
|
||||
- Elements can be deleted from the scene by setting their isDeleted property to true.
|
||||
- The Obsidian.md module is available on ea.obsidian.
|
||||
|
||||
#### **1. The Core Workflow: Handling Element Immutability**
|
||||
|
||||
* **Central Rule:** Elements in the Excalidraw scene are immutable and should never be modified directly. Always use the ExcalidrawAutomate (EA) "workbench" pattern for modifications.
|
||||
* **The Workflow:**
|
||||
1. Get elements from the current view using \`ea.getViewElements()\` or \`ea.getViewSelectedElements()\`.
|
||||
2. Copy these elements into the EA workbench for editing using \`ea.copyViewElementsToEAforEditing(elements)\`.
|
||||
3. Modify the properties of the element copies that are now in the EA workbench (e.g., \`ea.getElement(id).locked = true;\`).
|
||||
4. Commit the changes back to the scene using \`await ea.addElementsToView()\`.
|
||||
* **Deletion:** To delete an element, set its \`isDeleted\` property to \`true\` on the workbench copy (\`ea.getElement(id).isDeleted = true;\`) and then commit with \`await ea.addElementsToView()\`.
|
||||
* **Cleanup:** Use \`ea.clear()\` at the beginning of a script if you are creating a completely new set of elements, to ensure the EA workbench is empty and doesn't contain artifacts from a previous run.
|
||||
|
||||
#### **2. User Interaction: Prompts and Dialogs**
|
||||
|
||||
* **Simple Input:** For straightforward user input, use the \`utils\` object provided to the script.
|
||||
* \`await utils.inputPrompt()\`: To get a string or number from the user.
|
||||
* \`await utils.suggester()\`: To let the user select from a predefined list of options.
|
||||
* **Complex Dialogs:** When a more complex UI with multiple controls is needed, create a floating dialog window.
|
||||
* **Use \`FloatingModal\`:** Always create a new instance: \`const modal = new ea.FloatingModal(ea.plugin.app);\`.
|
||||
* **Do Not Extend:** Do not use \`class MyModal extends ea.FloatingModal\`.
|
||||
* **Define Behavior:** Assign functions directly to the \`onOpen\` and \`onClose\` properties of the instance. Inside \`onOpen\`, use the \`modal.contentEl\` property to build your UI.
|
||||
* **Reference Implementation:** The script "Printable Layout Wizard.md" is the canonical example for this pattern. Use \`ea.obsidian.Setting\` to add controls like toggles and dropdowns within the modal.
|
||||
|
||||
#### **3. Element Manipulation and Querying**
|
||||
|
||||
* **Finding Elements:** The most common starting point is to get the user's selection with \`ea.getViewSelectedElements()\`. Use standard JavaScript array methods like \`.filter()\` to narrow down the selection (e.g., \`elements.filter(el => el.type === "text")\`).
|
||||
* **Geometric Calculations:**
|
||||
* Before performing layout or positioning tasks, use \`ea.getBoundingBox(elements)\` to get the collective dimensions and position of a group of elements.
|
||||
* Use \`ea.measureText(text)\` to determine the width and height of a string based on the current \`ea.style\` settings before creating a text element or a container for it.
|
||||
* **Grouping:**
|
||||
* To create a group, use \`ea.addToGroup([elementId1, elementId2, ...])\`.
|
||||
* To operate on existing groups within a selection, use \`ea.getMaximumGroups(selectedElements)\` which correctly identifies the top-level groups. Use \`ea.getLargestElement(group)\` to find the primary container within a group (e.g., the box around a text element).
|
||||
|
||||
#### **4. Styling: Creation vs. Modification**
|
||||
|
||||
* **For New Elements:** Set the properties on the global \`ea.style\` object *before* you call a creation function like \`ea.addText()\` or \`ea.addRect()\`. This acts like setting the active color/style on a paintbrush.
|
||||
* **For Existing Elements:** To change the style of an existing element, modify the properties directly on the element's copy in the EA workbench (after \`copyViewElementsToEAforEditing\`). For example: \`const myElement = ea.getElement(id); myElement.strokeColor = '#FF0000';\`.
|
||||
|
||||
#### **5. Data Persistence and Customization**
|
||||
|
||||
* **Storing Custom Data:** Elements have a \`customData\` property for arbitrary data.
|
||||
* **Always Use \`ea.addAppendUpdateCustomData(id, newData)\`:** This is crucial. It safely adds or updates your key-value pairs without overwriting data that might have been stored by other scripts or the Excalidraw plugin itself.
|
||||
* **Creating Configurable Scripts:** To make your script's behavior customizable by the user:
|
||||
* Use \`ea.getScriptSettings()\` to retrieve saved settings.
|
||||
* Check if settings exist, and if not, define the default structure.
|
||||
* Use \`await ea.setScriptSettings(settings)\` to save any changes. This allows users to configure your script in the Excalidraw plugin settings pane.
|
||||
|
||||
#### **6. Best Practices and Advanced Techniques**
|
||||
|
||||
* **Embrace \`await\`:** Many EA functions are asynchronous and return a \`Promise\` (e.g., \`ea.addElementsToView()\`, \`ea.createSVG()\`, \`utils.inputPrompt()\`). **Always** use \`await\` when calling these functions to ensure your script executes in the correct order.
|
||||
* **Version Checking:** At the beginning of your script, include a check like \`if(!ea.verifyMinimumPluginVersion("1.X.X")) { new Notice(...); return; }\` to ensure the user has a compatible version of the Excalidraw plugin, preventing errors from missing API functions.
|
||||
* **Accessing Obsidian API:** The full Obsidian API is available via \`ea.obsidian\`. For example, use \`new ea.obsidian.Notice("message")\` or \`ea.obsidian.normalizePath(filepath)\`.
|
||||
* **Visibility vs. Deletion:**
|
||||
* To temporarily hide an element, set \`element.opacity = 0\`. It's good practice to store the original opacity in \`customData\` so it can be restored. It is also recommended to lock hidden elements so they do not get accidentally selected or moved around.
|
||||
* To permanently remove an element from the scene, set \`element.isDeleted = true\`.
|
||||
* **Image Handling:** When dealing with image elements, use \`ea.getViewFileForImageElement(imageElement)\` to get the corresponding \`TFile\` from the Obsidian vault. This is necessary for any logic that needs to read or manipulate the source image file.
|
||||
|
||||
#### **7. Custom Pens and Perfect Freehand**
|
||||
|
||||
Excalidraw's freehand tool is powered by the open-source Perfect Freehand library. The plugin exposes “custom pens” that bundle:
|
||||
- Canvas style for the next strokes (colors, width, fillStyle, roughness).
|
||||
- Perfect Freehand stroke geometry and behavior (pressure simulation, outline, tapering, easing, etc.).
|
||||
|
||||
Key concepts:
|
||||
- AppState-driven drawing: When \`appState.currentStrokeOptions\` is set, the freedraw tool renders new strokes using those Perfect Freehand options.
|
||||
- Element-level persistence: If a freedraw element has \`element.customData.strokeOptions\`, it is rendered with those options regardless of the current tool state.
|
||||
- Types reference: See \`src/types/penTypes.ts\`. The \`PenOptions\` shape is:
|
||||
\`\`\`ts
|
||||
interface PenOptions {
|
||||
highlighter: boolean; // if true the pen is drawn at the lowest layer, behind all other elements
|
||||
constantPressure: boolean;
|
||||
hasOutline: boolean;
|
||||
outlineWidth: number;
|
||||
options: {
|
||||
thinning: number;
|
||||
smoothing: number;
|
||||
streamline: number;
|
||||
easing: string; // see supported names below
|
||||
start: { cap: boolean; taper: number | boolean; easing: string; };
|
||||
end: { cap: boolean; taper: number | boolean; easing: string; };
|
||||
};
|
||||
}
|
||||
\`\`\`
|
||||
|
||||
Using custom pens from scripts:
|
||||
- Activate a custom pen for drawing:
|
||||
\`\`\`ts
|
||||
// obtain the Excalidraw API
|
||||
const api = ea.getExcalidrawAPI();
|
||||
|
||||
// define Perfect Freehand options (example similar to "finetip")
|
||||
const penOptions = {
|
||||
highlighter: false,
|
||||
constantPressure: true,
|
||||
hasOutline: false,
|
||||
outlineWidth: 1,
|
||||
options: {
|
||||
thinning: -0.5,
|
||||
smoothing: 0.4,
|
||||
streamline: 0.4,
|
||||
easing: "linear",
|
||||
start: { taper: 5, cap: false, easing: "linear" },
|
||||
end: { taper: 5, cap: false, easing: "linear" },
|
||||
},
|
||||
};
|
||||
|
||||
// apply stroke options + canvas style, then switch to freedraw (strokeWidth, color, background, fillStyle are optional)
|
||||
ea.viewUpdateScene({
|
||||
appState: {
|
||||
currentStrokeOptions: penOptions,
|
||||
currentItemStrokeWidth: 0.5,
|
||||
currentItemStrokeColor: "#3E6F8D",
|
||||
currentItemBackgroundColor: "transparent",
|
||||
currentItemFillStyle: "hachure",
|
||||
},
|
||||
});
|
||||
api.setActiveTool({ type: "freedraw" });
|
||||
\`\`\`
|
||||
|
||||
- Clear custom pen (revert to default freedraw behavior):
|
||||
\`\`\`ts
|
||||
ea.viewUpdateScene({ appState: { currentStrokeOptions: null } });
|
||||
\`\`\`
|
||||
|
||||
- Persist custom strokeOptions onto existing freedraw elements:
|
||||
\`\`\`ts
|
||||
const selected = ea.getViewSelectedElements().filter(el => el.type === "freedraw");
|
||||
ea.copyViewElementsToEAforEditing(selected);
|
||||
for (const el of selected) {
|
||||
ea.addAppendUpdateCustomData(el.id, { strokeOptions: penOptions });
|
||||
}
|
||||
await ea.addElementsToView();
|
||||
\`\`\`
|
||||
|
||||
Notes:
|
||||
- New strokes respect \`appState.currentStrokeOptions\` at draw time. Existing elements only change if you update their \`customData.strokeOptions\`.
|
||||
- For pens that should behave like real markers/highlighters, set \`highlighter: true\` and often \`constantPressure: true\` with an \`outlineWidth\` for the edge.
|
||||
|
||||
Supported easing names (string values for \`options.easing\`, \`options.start.easing\`, \`options.end.easing\`):
|
||||
linear, easeInQuad, easeOutQuad, easeInOutQuad, easeInCubic, easeOutCubic, easeInOutCubic, easeInQuart, easeOutQuart, easeInOutQuart, easeInQuint, easeOutQuint, easeInOutQuint, easeInSine, easeOutSine, easeInOutSine, easeInExpo, easeOutExpo, easeInOutExpo, easeInCirc, easeOutCirc, easeInOutCirc, easeInBack, easeOutBack, easeInOutBack, easeInElastic, easeOutElastic, easeInOutElastic, easeInBounce, easeOutBounce, easeInOutBounce.
|
||||
|
||||
Example freedraw element carrying \`customData.strokeOptions\`:
|
||||
\`\`\`json
|
||||
{"type":"excalidraw/clipboard","elements":[{"id":"...","type":"freedraw","strokeColor":"#3E6F8D","backgroundColor":"transparent","fillStyle":"hachure","strokeWidth":0.5,"roughness":0,"customData":{"strokeOptions":{"highlighter":false,"hasOutline":false,"outlineWidth":0,"constantPressure":true,"options":{"smoothing":0.4,"thinning":-0.5,"streamline":0.4,"easing":"linear","start":{"taper":5,"cap":false,"easing":"linear"},"end":{"taper":5,"cap":false,"easing":"linear"}}}}}],"files":{}}
|
||||
\`\`\`
|
||||
|
||||
`;
|
||||
|
||||
@@ -197,6 +351,143 @@ function buildAdditionalTypeDefsMarkdown() {
|
||||
return body;
|
||||
}
|
||||
|
||||
// NEW: Resolve module specifiers from types/excalidraw/index.d.ts to absolute .d.ts paths
|
||||
function resolveExcalModulePath(spec, excalIndexAbs) {
|
||||
const baseTypesRoot = path.join(ROOT, 'node_modules', '@zsviczian', 'excalidraw', 'types');
|
||||
if (spec.startsWith('@excalidraw/')) {
|
||||
const sub = spec.slice('@excalidraw/'.length); // e.g. 'element', 'element/bounds'
|
||||
const parts = sub.split('/');
|
||||
const pkg = parts.shift(); // 'element' | 'common' | 'utils'
|
||||
const rest = parts;
|
||||
if (!pkg) return null;
|
||||
const base = path.join(baseTypesRoot, pkg);
|
||||
if (rest.length === 0) {
|
||||
return path.join(base, 'src', 'index.d.ts');
|
||||
}
|
||||
return path.join(base, 'src', ...rest) + '.d.ts';
|
||||
}
|
||||
// relative to the excalidraw index.d.ts
|
||||
if (spec.startsWith('.')) {
|
||||
const dir = path.dirname(excalIndexAbs);
|
||||
return path.resolve(dir, spec) + '.d.ts';
|
||||
}
|
||||
// anything else is not expected
|
||||
return null;
|
||||
}
|
||||
|
||||
// NEW: Extract function signatures for a set of names from a .d.ts file
|
||||
function extractFunctionSignaturesFromModule(absPath, names) {
|
||||
const out = {};
|
||||
if (!absPath || !fs.existsSync(absPath)) {
|
||||
return out;
|
||||
}
|
||||
const content = fs.readFileSync(absPath, 'utf8');
|
||||
|
||||
for (const rawName of names) {
|
||||
const name = rawName.trim();
|
||||
if (!name) continue;
|
||||
|
||||
// Try "export declare function NAME ..."
|
||||
let m = content.match(new RegExp(`export\\s+declare\\s+function\\s+${name}[\\s\\S]*?;`, 'm'));
|
||||
if (m) {
|
||||
out[name] = m[0].trim();
|
||||
continue;
|
||||
}
|
||||
|
||||
// Try "declare function NAME ..." (re-exported later)
|
||||
m = content.match(new RegExp(`(^|\\n)declare\\s+function\\s+${name}[\\s\\S]*?;`, 'm'));
|
||||
if (m) {
|
||||
// Ensure it starts with export for readability
|
||||
out[name] = m[0].replace(/^\s*declare\s+/, 'export declare ').trim();
|
||||
continue;
|
||||
}
|
||||
|
||||
// Try "export declare const NAME: (...args) => ...;"
|
||||
m = content.match(new RegExp(`export\\s+declare\\s+const\\s+${name}\\s*:\\s*[\\s\\S]*?=>[\\s\\S]*?;`, 'm'));
|
||||
if (m) {
|
||||
out[name] = m[0].trim();
|
||||
continue;
|
||||
}
|
||||
|
||||
// Try "export declare function-type via type alias" (rare) - fallback to any const function shape
|
||||
m = content.match(new RegExp(`export\\s+declare\\s+(?:var|let|const)\\s+${name}\\s*:\\s*[\\s\\S]*?;`, 'm'));
|
||||
if (m && /=>/.test(m[0])) {
|
||||
out[name] = m[0].trim();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// NEW: Build "ExcalidrawLib module functions" section from index.d.ts
|
||||
function buildExcalidrawLibFunctionsSection() {
|
||||
const excalIndexRel = 'node_modules/@zsviczian/excalidraw/types/excalidraw/index.d.ts';
|
||||
const excalIndexAbs = path.join(ROOT, ...excalIndexRel.split('/'));
|
||||
if (!fs.existsSync(excalIndexAbs)) {
|
||||
console.warn('[script-library] Missing Excalidraw index.d.ts:', excalIndexRel);
|
||||
return '';
|
||||
}
|
||||
|
||||
const content = fs.readFileSync(excalIndexAbs, 'utf8');
|
||||
const reExport = /export\s*\{\s*([\s\S]*?)\s*\}\s*from\s*["']([^"']+)["'];/g;
|
||||
|
||||
// Collect names by source module
|
||||
const moduleToNames = new Map();
|
||||
for (const match of content.matchAll(reExport)) {
|
||||
const namesChunk = match[1];
|
||||
const spec = match[2];
|
||||
// skip if the export list contains only types we know we shouldn't include? We'll filter later by signature detection.
|
||||
const names = namesChunk
|
||||
.split(',')
|
||||
.map((s) => s.trim())
|
||||
.filter(Boolean);
|
||||
if (!names.length) continue;
|
||||
const abs = resolveExcalModulePath(spec, excalIndexAbs);
|
||||
if (!abs) continue;
|
||||
const key = spec;
|
||||
const curr = moduleToNames.get(key) || { abs, names: new Set() };
|
||||
for (const n of names) curr.names.add(n);
|
||||
moduleToNames.set(key, curr);
|
||||
}
|
||||
|
||||
// Extract signatures
|
||||
const seen = new Set();
|
||||
const sections = [];
|
||||
let functionsFound = 0;
|
||||
|
||||
for (const [spec, { abs, names }] of moduleToNames) {
|
||||
const sigs = extractFunctionSignaturesFromModule(abs, Array.from(names));
|
||||
const sigEntries = Object.entries(sigs)
|
||||
.filter(([name]) => {
|
||||
if (seen.has(name)) return false;
|
||||
seen.add(name);
|
||||
return true;
|
||||
})
|
||||
.sort(([a], [b]) => a.localeCompare(b, 'en', { sensitivity: 'base' }));
|
||||
|
||||
if (!sigEntries.length) continue;
|
||||
|
||||
const rel = path.relative(ROOT, abs).replace(/\\/g, '/');
|
||||
const header = makeSectionHeader(`${spec} -> ${rel}`).replace(/\*\/\n\/\*/g, '*\/\n/*'); // keep style
|
||||
sections.push(header + sigEntries.map(([, s]) => s).join('\n') + '\n');
|
||||
functionsFound += sigEntries.length;
|
||||
}
|
||||
|
||||
if (!sections.length) {
|
||||
console.warn('[script-library] No function signatures found in ExcalidrawLib exports.');
|
||||
}
|
||||
|
||||
const body =
|
||||
'# ExcalidrawLib module functions\n\n' +
|
||||
'The following functions are exposed via window.ExcalidrawLib. Signatures are extracted from TypeScript declarations.\n\n' +
|
||||
'```ts\n' +
|
||||
sections.join('\n') +
|
||||
'```\n';
|
||||
|
||||
console.log(`[script-library] Collected ${functionsFound} ExcalidrawLib function signatures`);
|
||||
return body;
|
||||
}
|
||||
|
||||
function main() {
|
||||
console.log('[script-library] Generating Excalidraw Script Library...');
|
||||
if (!fs.existsSync(EA_SCRIPTS_DIR)) {
|
||||
@@ -295,6 +586,9 @@ function main() {
|
||||
? `<!-- ${EXCALIDRAW_STARTUP_EXAMPLE} -->\n${startupExample}\n`
|
||||
: '');
|
||||
|
||||
// NEW: Build ExcalidrawLib functions section
|
||||
const excalidrawLibFunctionsSection = buildExcalidrawLibFunctionsSection();
|
||||
|
||||
const combined =
|
||||
AI_TRAINING_INTRO +
|
||||
'\n---\n\n' +
|
||||
@@ -302,8 +596,10 @@ function main() {
|
||||
'\n\n---\n\n' +
|
||||
additionalTypeDefs +
|
||||
'\n\n---\n\n' +
|
||||
excalidrawLibFunctionsSection +
|
||||
'\n---\n\n' +
|
||||
scriptLibContent.trim() +
|
||||
startupSection + // NEW: append startup message + files
|
||||
startupSection +
|
||||
'\n';
|
||||
|
||||
fs.writeFileSync(AI_TRAINING_OUT, combined, 'utf8');
|
||||
|
||||
+9
-5
@@ -66,7 +66,7 @@ import { ScriptEngine } from "../shared/Scripts";
|
||||
import { hoverEvent, initializeMarkdownPostProcessor, markdownPostProcessor, legacyExcalidrawPopoverObserver } from "./managers/MarkdownPostProcessor";
|
||||
import { FieldSuggester } from "../shared/Suggesters/FieldSuggester";
|
||||
import { ReleaseNotes } from "../shared/Dialogs/ReleaseNotes";
|
||||
import { Packages } from "../types/types";
|
||||
import { DeviceType, Packages } from "../types/types";
|
||||
import { PreviewImageType } from "../types/utilTypes";
|
||||
import { emulateCTRLClickForLinks, linkClickModifierType, PaneTarget } from "../utils/modifierkeyHelper";
|
||||
import { imageCache } from "../shared/ImageCache";
|
||||
@@ -415,7 +415,7 @@ export default class ExcalidrawPlugin extends Plugin {
|
||||
try {
|
||||
this.isReady = true;
|
||||
await switchToExcalidraw(this.app);
|
||||
this.switchToExcalidarwAfterLoad();
|
||||
this.switchToExcalidrawAfterLoad();
|
||||
} catch (e) {
|
||||
new Notice("Error switching views to Excalidraw", 6000);
|
||||
console.error("Error switching views to Excalidraw", e);
|
||||
@@ -620,8 +620,8 @@ export default class ExcalidrawPlugin extends Plugin {
|
||||
/**
|
||||
* Must be called after the workspace is ready
|
||||
*/
|
||||
private switchToExcalidarwAfterLoad() {
|
||||
(process.env.NODE_ENV === 'development') && DEBUGGING && debug(this.switchToExcalidarwAfterLoad, `ExcalidrawPlugin.switchToExcalidarwAfterLoad`);
|
||||
private switchToExcalidrawAfterLoad() {
|
||||
(process.env.NODE_ENV === 'development') && DEBUGGING && debug(this.switchToExcalidrawAfterLoad, `ExcalidrawPlugin.switchToExcalidrawAfterLoad`);
|
||||
let leaf: WorkspaceLeaf;
|
||||
for (leaf of this.app.workspace.getLeavesOfType("markdown")) {
|
||||
if ( leaf.view instanceof MarkdownView && this.isExcalidrawFile(leaf.view.file)) {
|
||||
@@ -1482,4 +1482,8 @@ export default class ExcalidrawPlugin extends Plugin {
|
||||
public getLabel(key: keyof typeof en): string {
|
||||
return t(key);
|
||||
}
|
||||
}
|
||||
|
||||
public getObsidianDevice(): DeviceType {
|
||||
return DEVICE;
|
||||
}
|
||||
}
|
||||
@@ -989,10 +989,8 @@ export class CommandManager {
|
||||
if (checking) {
|
||||
if(this.app.workspace.getActiveViewOfType(ExcalidrawView)) {
|
||||
const view = this.app.workspace.getActiveViewOfType(ExcalidrawView);
|
||||
const api = view?.excalidrawAPI;
|
||||
if(!api) return false;
|
||||
const st = api.getAppState();
|
||||
if(!st.trayModeEnabled) return false;
|
||||
const api = view?.excalidrawAPI as ExcalidrawImperativeAPI;
|
||||
if(!api.isTrayModeEnabled()) return false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -242,7 +242,7 @@ export class EventManager {
|
||||
|
||||
if (previouslyActiveEV && previouslyActiveEV !== newActiveviewEV) {
|
||||
if (previouslyActiveEV.leaf !== leaf) {
|
||||
//if loading new view to same leaf then don't save. Excalidarw view will take care of saving anyway.
|
||||
//if loading new view to same leaf then don't save. Excalidraw view will take care of saving anyway.
|
||||
//avoid double saving
|
||||
if(previouslyActiveEV?.isDirty() && !previouslyActiveEV.semaphores?.viewunload) {
|
||||
await previouslyActiveEV.save(true); //this will update transclusions in the drawing
|
||||
@@ -364,4 +364,4 @@ export class EventManager {
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -562,9 +562,9 @@ export class PluginFileManager {
|
||||
return;
|
||||
}
|
||||
|
||||
const isExcalidarwFile = this.getExcalidrawFiles().has(file);
|
||||
const isExcalidrawFile = this.getExcalidrawFiles().has(file);
|
||||
this.updateFileCache(file, undefined, true);
|
||||
if (!isExcalidarwFile) {
|
||||
if (!isExcalidrawFile) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -614,4 +614,4 @@ export class PluginFileManager {
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@ import { PENS } from "src/utils/pens";
|
||||
import {
|
||||
addYouTubeThumbnail,
|
||||
fragWithHTML,
|
||||
setDesktopUIMode,
|
||||
setLeftHandedMode,
|
||||
setTrayMode,
|
||||
} from "src/utils/utils";
|
||||
@@ -179,6 +180,7 @@ export interface ExcalidrawSettings {
|
||||
};
|
||||
defaultTrayMode: boolean;
|
||||
compactModeOnTablets: boolean;
|
||||
compactModeOnDesktops: boolean;
|
||||
previousRelease: string;
|
||||
showReleaseNotes: boolean;
|
||||
compareManifestToPluginVersion: boolean;
|
||||
@@ -234,6 +236,7 @@ export interface ExcalidrawSettings {
|
||||
modifierKeyOverrides: {modifiers: Modifier[], key: string}[];
|
||||
showSplashscreen: boolean;
|
||||
pdfSettings: PDFExportSettings;
|
||||
disableContextMenu: boolean;
|
||||
}
|
||||
|
||||
declare const PLUGIN_VERSION:string;
|
||||
@@ -365,6 +368,7 @@ export const DEFAULT_SETTINGS: ExcalidrawSettings = {
|
||||
scriptEngineSettings: {},
|
||||
defaultTrayMode: true,
|
||||
compactModeOnTablets: true,
|
||||
compactModeOnDesktops: false,
|
||||
previousRelease: "0.0.0",
|
||||
showReleaseNotes: true,
|
||||
compareManifestToPluginVersion: true,
|
||||
@@ -534,6 +538,7 @@ export const DEFAULT_SETTINGS: ExcalidrawSettings = {
|
||||
alignment: "center",
|
||||
margin: "normal",
|
||||
},
|
||||
disableContextMenu: false,
|
||||
};
|
||||
|
||||
export class ExcalidrawSettingTab extends PluginSettingTab {
|
||||
@@ -1218,6 +1223,18 @@ export class ExcalidrawSettingTab extends PluginSettingTab {
|
||||
this.applySettingsUpdate();
|
||||
}),
|
||||
);
|
||||
|
||||
new Setting(detailsEl)
|
||||
.setName(t("DISABLE_CONTEXT_MENU_NAME"))
|
||||
.setDesc(t("DISABLE_CONTEXT_MENU_DESC"))
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(!this.plugin.settings.disableContextMenu)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.disableContextMenu = !value;
|
||||
this.applySettingsUpdate();
|
||||
}),
|
||||
);
|
||||
|
||||
const readingModeEl = new Setting(detailsEl)
|
||||
.setName(t("SHOW_DRAWING_OR_MD_IN_READING_MODE_NAME"))
|
||||
@@ -1263,6 +1280,19 @@ export class ExcalidrawSettingTab extends PluginSettingTab {
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(detailsEl)
|
||||
.setName(t("PREFER_COMPACT_MODE_DESKTOP_NAME"))
|
||||
.setDesc(fragWithHTML(t("PREFER_COMPACT_MODE_DESKTOP_DESC")))
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(this.plugin.settings.compactModeOnDesktops)
|
||||
.onChange((value) => {
|
||||
this.plugin.settings.compactModeOnDesktops = value;
|
||||
setDesktopUIMode(this.app, this.plugin.settings);
|
||||
this.applySettingsUpdate();
|
||||
}),
|
||||
);
|
||||
|
||||
new Setting(detailsEl)
|
||||
.setName(t("COMPACT_MODE_NAME"))
|
||||
.setDesc(fragWithHTML(t("COMPACT_MODE_DESC")))
|
||||
|
||||
@@ -215,6 +215,8 @@ export default {
|
||||
|
||||
|
||||
//settings.ts
|
||||
DISABLE_CONTEXT_MENU_NAME: "Disable Excalidraw context menu",
|
||||
DISABLE_CONTEXT_MENU_DESC: "Disables the Excalidraw context menu. This can be useful on Mobile devices where the context menu pops up in unwanted moments.",
|
||||
NOTEBOOKLM_LINK_ARIA: "Ask NotebookLM for help about the plugin. This model is pre-loaded with all my video transcripts, release notes and other helpful content. Chat with NotebookLM to explore my 250+ videos and the Excalidraw documentation.",
|
||||
NOTEBOOKLM_LINK_TEXT: "Learn the Plugin. Access the NotebookLM knowledgebase.",
|
||||
LINKS_BUGS_ARIA: "Report bugs and raise feature requsts on the plugin's GitHub page",
|
||||
@@ -452,8 +454,11 @@ export default {
|
||||
"⚠️ You must close and reopen the Excalidraw/markdown file for changes to take effect. ⚠️",
|
||||
MODES_HEAD: "Modes",
|
||||
TRAY_MODE_NAME: "Enable tray-mode",
|
||||
COMPACT_MODE_NAME: "Compact-mode on Tablets",
|
||||
COMPACT_MODE_DESC: "Overrides tray-mode on tablets, allowing the native Excalidraw compact-mode to be used instead.",
|
||||
PREFER_COMPACT_MODE_DESKTOP_NAME: "Prefer compact-mode on Desktop",
|
||||
PREFER_COMPACT_MODE_DESKTOP_DESC: "When toggling tray-mode on a desktop, if this option is enabled, Excalidraw will toggle between compact-mode and tray-mode. " +
|
||||
"If this setting is off, it will toggle betweeen full-mode and tray-mode.",
|
||||
COMPACT_MODE_NAME: "Prefer compact-mode on Tablets",
|
||||
COMPACT_MODE_DESC: "This setting allows you to have a different default mode on tablets, then on desktops. You can default to compact mode on tablets, and to tray-mode on desktops with the help of this setting.",
|
||||
HOTKEY_OVERRIDE_HEAD: "Hotkey overrides",
|
||||
HOTKEY_OVERRIDE_DESC: `Some of the Excalidraw hotkeys such as <code>${labelCTRL()}+Enter</code> to edit text or <code>${labelCTRL()}+K</code> to create an element link ` +
|
||||
"conflict with Obsidian hotkey settings. The hotkey combinations you add below will override Obsidian's hotkey settings while using Excalidraw, thus " +
|
||||
|
||||
@@ -86,7 +86,7 @@ export default {
|
||||
INSERT_MD: "以图像形式嵌入 Markdown 文档到当前绘图中",
|
||||
INSERT_PDF: "以图像形式嵌入 PDF 到当前绘图中",
|
||||
INSERT_LAST_ACTIVE_PDF_PAGE_AS_IMAGE: "以图像形式嵌入最后激活的 PDF 页面",
|
||||
UNIVERSAL_ADD_FILE: "以交互或图像形式嵌入文件",
|
||||
UNIVERSAL_ADD_FILE: "嵌入文件 (Insert ANY file)",
|
||||
INSERT_CARD: "插入“背景笔记”卡片",
|
||||
CONVERT_CARD_TO_FILE: "将“背景笔记”卡片保存到文件",
|
||||
ERROR_TRY_AGAIN: "请重试。",
|
||||
@@ -169,7 +169,7 @@ export default {
|
||||
COMPATIBILITY_MODE:
|
||||
"*.excalidraw 是兼容旧版的绘图文件格式。需要转换为新格式才能解锁本插件的全部功能。",
|
||||
CONVERT_FILE: "转换为新格式",
|
||||
BACKUP_AVAILABLE: "加载绘图文件时出错,可能是由于 Obsidian 在上次保存时意外退出了(手机上更容易发生这种意外)。<br><br><b>好消息:</b>这台设备上存在备份。您是否想要恢复本设备上的备份?<br><br>(我建议您先尝试在最近使用过的其他设备上打开该绘图,以检查是否有更新的备份。)",
|
||||
BACKUP_AVAILABLE: "加载绘图文件时出错,可能是由于 Obsidian 在上次保存时意外退出了(移动设备上更容易发生这种意外)。<br><br><b>好消息:</b>这台设备上存在备份。您是否想要恢复本设备上的备份?<br><br>(我建议您先尝试在最近使用过的其他设备上打开该绘图,以检查是否有更新的备份。)",
|
||||
BACKUP_RESTORED: "已恢复备份",
|
||||
BACKUP_SAVE_AS_FILE: "此绘图为空。但有一个非空的备份可用。您想将其恢复为新文件并在新标签页中打开吗?",
|
||||
BACKUP_SAVE: "恢复",
|
||||
@@ -215,6 +215,8 @@ export default {
|
||||
|
||||
|
||||
//settings.ts
|
||||
DISABLE_CONTEXT_MENU_NAME: "禁用 Excalidraw 上下文菜单",
|
||||
DISABLE_CONTEXT_MENU_DESC: "禁用 Excalidraw 的上下文菜单。这在移动设备上非常有用,因为上下文菜单有时会在不需要的时候弹出。",
|
||||
NOTEBOOKLM_LINK_ARIA: "向 NotebookLM 咨询有关插件的帮助。此模型已预加载了我所有的视频转录稿、发布说明和其他帮助内容。与 NotebookLM 聊天,浏览我的 250+ 视频和 Excalidraw 文件。",
|
||||
NOTEBOOKLM_LINK_TEXT: "学习插件。访问 NotebookLM 知识库。",
|
||||
LINKS_BUGS_ARIA: "在插件的 GitHub 页面报告错误和提交功能请求",
|
||||
|
||||
@@ -20,12 +20,18 @@ I build this plugin in my free time, as a labor of love. Curious about the philo
|
||||
"2.17.0":`
|
||||
## New
|
||||
- Phone UI from Excalidraw.com [#9996](https://github.com/excalidraw/excalidraw/pull/9996)
|
||||
- Custom pen settings now allow pen width to be set at 0.1 increments from 0.1 to 8.0
|
||||
- Updated the "Palm Guard" script to support the change UI configurations.
|
||||
- Setting under Modes in Plugin Settings to prefer "compact-mode" on desktops when toggling tray mode.
|
||||
|
||||
## Fixed
|
||||
- side panel does not attach correctly when library is pinned [#2510](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/2510)
|
||||
- Fixed print area when using marker frames and printing Slideshow to PDF
|
||||
- The Invert Colors script and ExcalidrawAutomate bugs that resulted in broken colors and Excalidarw crash in some cases after color inversion.
|
||||
- The "Invert Colors" script and ExcalidrawAutomate bugs that resulted in broken colors and Excalidraw crashes in some cases after color inversion.
|
||||
- Fixed duplicated PDF elements after copy-pasting from scene to scene.
|
||||
- Resolved the large gap at the top on iOS devices. As it turns out, Apple adds additional padding automatically to avoid collision with the notch.
|
||||
- Fixed the positioning of the "Canvas and Shape Properties" window.
|
||||
- Attempt to fix mobile keyboard popup distorting the view.
|
||||
`,
|
||||
"2.16.1":`
|
||||
## Fixed
|
||||
|
||||
@@ -66,8 +66,8 @@ export class PenSettingsModal extends Modal {
|
||||
|
||||
async onClose() {
|
||||
if(this.dirty) {
|
||||
await this.plugin.saveSettings();
|
||||
getExcalidrawViews(this.app).forEach(excalidrawView=>excalidrawView.updatePinnedCustomPens());
|
||||
this.plugin.saveSettings();
|
||||
const pen = this.plugin.settings.customPens[this.pen]
|
||||
const api = this.view.excalidrawAPI;
|
||||
setPen(pen,api);
|
||||
@@ -369,7 +369,7 @@ export class PenSettingsModal extends Modal {
|
||||
.setName(fragWithHTML(`Stroke Width <b>${ps.strokeWidth === 0 ? "Not Set" : ps.strokeWidth}</b>`))
|
||||
.addSlider(slider =>
|
||||
slider
|
||||
.setLimits(0,5,0.1)
|
||||
.setLimits(0.1,8,0.1)
|
||||
.setValue(ps.strokeWidth)
|
||||
.onChange(value => {
|
||||
this.dirty = true;
|
||||
|
||||
@@ -979,7 +979,7 @@ export const FRONTMATTER_KEYS_INFO: SuggesterInfo[] = [
|
||||
{
|
||||
field: "plugin",
|
||||
code: null,
|
||||
desc: "Denotes an excalidraw file. If key is not present, the file will not be recognized as an Excalidarw file. Valid values are 'parsed' and 'raw'",
|
||||
desc: "Denotes an excalidraw file. If key is not present, the file will not be recognized as an Excalidraw file. Valid values are 'parsed' and 'raw'",
|
||||
after: ": parsed",
|
||||
},
|
||||
{
|
||||
|
||||
@@ -148,7 +148,8 @@ const GAP = 4;
|
||||
* you may access this object via the variable `ea`. e.g. ea.addImage(); This ea object is already set to the targetView.
|
||||
* Through ea.obsidian all of the Obsidian API is available to the script. Thus you can create modal views, open files, etc.
|
||||
* You can access Obsidian type definitions here: https://github.com/obsidianmd/obsidian-api/blob/master/obsidian.d.ts
|
||||
* In addition to the ea object, the script also receives the `utils` object. utils includes to utility functions: suggester and inputPrompt
|
||||
* In addition to the ea instance, the script also receives the `utils` object. utils includes to utility functions: suggester and inputPrompt.
|
||||
* You may access these via the variable `utils`. e.g. utils.suggester(...);
|
||||
* - inputPrompt(inputPrompt: (
|
||||
* header: string,
|
||||
* placeholder?: string,
|
||||
|
||||
+14
-1
@@ -6,7 +6,7 @@ import {
|
||||
TFolder,
|
||||
} from "obsidian";
|
||||
import { Random } from "roughjs/bin/math";
|
||||
import { BinaryFileData, DataURL} from "@zsviczian/excalidraw/types/excalidraw/types";
|
||||
import { BinaryFileData, DataURL, ExcalidrawImperativeAPI} from "@zsviczian/excalidraw/types/excalidraw/types";
|
||||
import {
|
||||
exportToSvg,
|
||||
exportToBlob,
|
||||
@@ -639,6 +639,19 @@ export function setTrayMode(app: App, settings: ExcalidrawSettings) {
|
||||
getExcalidrawViews(app).forEach((view) => view.setTrayMode(isTrayMode));
|
||||
}
|
||||
|
||||
export function setDesktopUIMode(app: App, settings: ExcalidrawSettings) {
|
||||
const isTrayMode = settings.defaultTrayMode;
|
||||
getExcalidrawViews(app).forEach((view) => view
|
||||
.setDesktopUIMode(
|
||||
isTrayMode
|
||||
? "tray"
|
||||
: settings.compactModeOnDesktops
|
||||
? "compact"
|
||||
: "full"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export type LinkParts = {
|
||||
original: string;
|
||||
path: string;
|
||||
|
||||
+104
-57
@@ -112,6 +112,7 @@ import {
|
||||
checkVersionMismatch,
|
||||
calculateTrayModeValue,
|
||||
setTrayMode,
|
||||
setDesktopUIMode,
|
||||
} from "../utils/utils";
|
||||
import { cleanBlockRef, cleanSectionHeading, closeLeafView, getAttachmentsFolderAndFilePath, getExcalidraAndMarkdowViewsForFile, getLeaf, getParentOfClass, obsidianPDFQuoteWithRef, openLeaf, setExcalidrawView } from "../utils/obsidianUtils";
|
||||
import { splitFolderAndFilename } from "../utils/fileUtils";
|
||||
@@ -278,7 +279,7 @@ const warningUnknowSeriousError = () => {
|
||||
new Notice(t("WARNING_SERIOUS_ERROR"),60000);
|
||||
};
|
||||
|
||||
type ActionButtons = "save" | "isParsed" | "isRaw" | "link" | "scriptInstall";
|
||||
type ActionButtons = "save" | "isRaw" | "link" | "scriptInstall";
|
||||
|
||||
let windowMigratedDisableZoomOnce = false;
|
||||
|
||||
@@ -335,6 +336,10 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{
|
||||
private obsidianMenu: ObsidianMenu;
|
||||
private embeddableMenu: EmbeddableMenu;
|
||||
private destroyers: Function[] = [];
|
||||
private previousContentElHeight: number = 0;
|
||||
private resizeBatchTimer: number = null;
|
||||
private lastAggregatedDh = 0;
|
||||
private oldKeyboardScroll:{scrollY:number, scrollX:number}|null = null;
|
||||
|
||||
//https://stackoverflow.com/questions/27132796/is-there-any-javascript-event-fired-when-the-on-screen-keyboard-on-mobile-safari
|
||||
private isEditingTextResetTimer: number = null;
|
||||
@@ -1630,32 +1635,40 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{
|
||||
|
||||
this.registerDomEvent(this.containerEl,"wheel",wheelEvent, {passive: false});
|
||||
|
||||
this.actionButtons['scriptInstall'] = this.addAction(SCRIPTENGINE_ICON_NAME, t("INSTALL_SCRIPT_BUTTON"), () => {
|
||||
new ScriptInstallPrompt(this.plugin).open();
|
||||
});
|
||||
|
||||
this.actionButtons['save'] = this.addAction(
|
||||
DISK_ICON_NAME,
|
||||
t("FORCE_SAVE"),
|
||||
async () => this.forceSave(),
|
||||
);
|
||||
|
||||
this.actionButtons['isRaw'] = this.addAction(
|
||||
TEXT_DISPLAY_RAW_ICON_NAME,
|
||||
t("RAW"),
|
||||
() => this.changeTextMode(TextMode.parsed),
|
||||
);
|
||||
this.actionButtons = {
|
||||
scriptInstall: this.addAction(SCRIPTENGINE_ICON_NAME, t("INSTALL_SCRIPT_BUTTON"), () => {
|
||||
new ScriptInstallPrompt(this.plugin).open();
|
||||
}),
|
||||
save: this.addAction(
|
||||
DISK_ICON_NAME,
|
||||
t("FORCE_SAVE"),
|
||||
async () => this.forceSave(),
|
||||
),
|
||||
isRaw: this.addAction(
|
||||
TEXT_DISPLAY_RAW_ICON_NAME,
|
||||
t("RAW"),
|
||||
() => this.changeTextMode(TextMode.parsed),
|
||||
),
|
||||
link: this.addAction("link", t("OPEN_LINK"), (ev) =>
|
||||
this.handleLinkClick(ev),
|
||||
),
|
||||
}
|
||||
/*this.actionButtons['isParsed'] = this.addAction(
|
||||
TEXT_DISPLAY_PARSED_ICON_NAME,
|
||||
t("PARSED"),
|
||||
() => this.changeTextMode(TextMode.raw),
|
||||
);*/
|
||||
|
||||
this.actionButtons['link'] = this.addAction("link", t("OPEN_LINK"), (ev) =>
|
||||
this.handleLinkClick(ev),
|
||||
);
|
||||
|
||||
this.registerDomEvent(this.ownerWindow, "resize", this.onExcalidrawResize.bind(this));
|
||||
const ro = new ResizeObserver(() => {
|
||||
const height = this.contentEl.clientHeight;
|
||||
const prevHeight = this.previousContentElHeight;
|
||||
const dh = prevHeight ? height - prevHeight : 0;
|
||||
this.previousContentElHeight = height;
|
||||
this.scheduleBatchedResize(dh);
|
||||
});
|
||||
this.previousContentElHeight = this.contentEl.clientHeight;
|
||||
ro.observe(this.contentEl);
|
||||
this.destroyers.push(() => ro.disconnect());
|
||||
|
||||
this.app.workspace.onLayoutReady(async () => {
|
||||
(process.env.NODE_ENV === 'development') && DEBUGGING && debug(this.onload,`ExcalidrawView.onload > app.workspace.onLayoutReady, file:${this.file?.name}, isActiveLeaf:${this?.app?.workspace?.activeLeaf === this.leaf}, is activeExcalidrawView set:${Boolean(this?.plugin?.activeExcalidrawView)}`);
|
||||
@@ -2397,7 +2410,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{
|
||||
if (this.compatibilityMode) {
|
||||
this.plugin.enableLegacyFilePopoverObserver();
|
||||
this.actionButtons['isRaw'].hide();
|
||||
this.actionButtons['isParsed'].hide();
|
||||
// this.actionButtons['isParsed'].hide();
|
||||
this.actionButtons['link'].hide();
|
||||
this.textMode = TextMode.raw;
|
||||
await this.excalidrawData.loadLegacyData(data, this.file);
|
||||
@@ -2828,7 +2841,6 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{
|
||||
zenModeEnabled,
|
||||
viewModeEnabled,
|
||||
linkOpacity: this.excalidrawData.getLinkOpacity(),
|
||||
trayModeEnabled: calculateTrayModeValue(this.plugin.settings),
|
||||
penMode: penEnabled,
|
||||
penDetected: penEnabled,
|
||||
allowPinchZoom: this.plugin.settings.allowPinchZoom,
|
||||
@@ -2862,7 +2874,6 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{
|
||||
zenModeEnabled: om.zenModeEnabled,
|
||||
viewModeEnabled: excalidrawData.elements.length > 0 ? om.viewModeEnabled : false,
|
||||
linkOpacity: this.excalidrawData.getLinkOpacity(),
|
||||
trayModeEnabled: calculateTrayModeValue(this.plugin.settings),
|
||||
penMode: penEnabled,
|
||||
penDetected: penEnabled,
|
||||
allowPinchZoom: this.plugin.settings.allowPinchZoom,
|
||||
@@ -2902,6 +2913,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{
|
||||
this.loadSceneFiles();
|
||||
this.updateContainerSize(null, true, justloaded);
|
||||
this.initializeToolsIconPanelAfterLoading();
|
||||
this.setTrayMode(calculateTrayModeValue(this.plugin.settings));
|
||||
}
|
||||
|
||||
public setDirty(location?:number) {
|
||||
@@ -5463,7 +5475,25 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{
|
||||
return this.obsidianMenu?.renderButton (isMobile, appState);
|
||||
}
|
||||
|
||||
private onExcalidrawResize () {
|
||||
private scheduleBatchedResize(currentDeltaHeight: number) {
|
||||
const api = this.excalidrawAPI as ExcalidrawImperativeAPI;
|
||||
if(!api || !api.isTouchScreen) return;
|
||||
if (!this.resizeBatchTimer) {
|
||||
this.lastAggregatedDh = 0;
|
||||
}
|
||||
this.lastAggregatedDh += currentDeltaHeight;
|
||||
if (this.resizeBatchTimer) window.clearTimeout(this.resizeBatchTimer);
|
||||
this.resizeBatchTimer = window.setTimeout(() => {
|
||||
const dh = this.lastAggregatedDh;
|
||||
this.resizeBatchTimer = null;
|
||||
this.lastAggregatedDh = 0;
|
||||
if (Math.abs(dh) > 120) {
|
||||
this.onExcalidrawResize();
|
||||
}
|
||||
}, Math.abs(currentDeltaHeight) < 120 ? 700 : 20);
|
||||
}
|
||||
|
||||
private onExcalidrawResize() {
|
||||
try {
|
||||
const api = this.excalidrawAPI as ExcalidrawImperativeAPI;
|
||||
if(!api) return;
|
||||
@@ -5488,30 +5518,38 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{
|
||||
const isKeyboardOutEvent:Boolean = st.editingTextElement && !isEventOnSameElement;
|
||||
const isKeyboardBackEvent:Boolean = (this.semaphores.isEditingText || isEventOnSameElement) && !isKeyboardOutEvent;
|
||||
this.editingTextElementId = isKeyboardOutEvent ? st.editingTextElement.id : null;
|
||||
|
||||
if(isKeyboardOutEvent) {
|
||||
const appToolHeight = (this.contentEl.querySelector(".Island.App-toolbar") as HTMLElement)?.clientHeight ?? 0;
|
||||
const editingElViewY = sceneCoordsToViewportCoords({sceneX:0, sceneY:st.editingTextElement.y}, st).y;
|
||||
const scrollViewY = sceneCoordsToViewportCoords({sceneX:0, sceneY:-st.scrollY}, st).y;
|
||||
const delta = editingElViewY - scrollViewY;
|
||||
const isElementAboveKeyboard = height > (delta + appToolHeight*2)
|
||||
const excalidrawWrapper = this.excalidrawWrapperRef.current;
|
||||
//console.log({isElementAboveKeyboard});
|
||||
if(excalidrawWrapper && !isElementAboveKeyboard) {
|
||||
excalidrawWrapper.style.top = `${-(st.height - height)}px`;
|
||||
excalidrawWrapper.style.height = `${st.height}px`;
|
||||
this.excalidrawContainer?.querySelector(".App-bottom-bar")?.scrollIntoView();
|
||||
this.headerEl?.scrollIntoView();
|
||||
}
|
||||
const elTop = st.editingTextElement.y;
|
||||
const elHeight = (st.editingTextElement as any).height ?? 0;
|
||||
const elCenterY = elTop + elHeight / 2;
|
||||
|
||||
const visibleHeight = st.height / st.zoom.value;
|
||||
// visibleTop is -scrollY in scene coords
|
||||
const visibleTop = -st.scrollY;
|
||||
const topThreeQuarterThreshold = visibleTop + visibleHeight * 0.75;
|
||||
|
||||
// If the editing text element is in the top 3/4 of the visible screen, do not change scroll
|
||||
if (!(elCenterY >= visibleTop && elCenterY <= topThreeQuarterThreshold)) {
|
||||
// Otherwise, vertically center the editing text element in the visible area
|
||||
const desiredVisibleTop = elCenterY - visibleHeight / 2;
|
||||
const newScrollY = -desiredVisibleTop;
|
||||
|
||||
this.oldKeyboardScroll = {scrollY: st.scrollY, scrollX: st.scrollX};
|
||||
this.updateScene({appState: {scrollY: newScrollY}, captureUpdate: CaptureUpdateAction.NEVER});
|
||||
}
|
||||
|
||||
this.containerEl.scrollIntoView();
|
||||
}
|
||||
if(isKeyboardBackEvent) {
|
||||
const excalidrawWrapper = this.excalidrawWrapperRef.current;
|
||||
const appButtonBar = this.excalidrawContainer?.querySelector(".App-bottom-bar");
|
||||
const headerEl = this.headerEl;
|
||||
if(excalidrawWrapper) {
|
||||
excalidrawWrapper.style.top = "";
|
||||
excalidrawWrapper.style.height = "";
|
||||
appButtonBar?.scrollIntoView();
|
||||
headerEl?.scrollIntoView();
|
||||
if (isKeyboardBackEvent) {
|
||||
if(this.oldKeyboardScroll != null) {
|
||||
// Restore only vertical scroll; remove horizontal scroll completely
|
||||
this.updateScene({
|
||||
appState: {scrollY: this.oldKeyboardScroll.scrollY},
|
||||
captureUpdate: CaptureUpdateAction.NEVER
|
||||
});
|
||||
this.oldKeyboardScroll = null;
|
||||
this.containerEl.scrollIntoView();
|
||||
}
|
||||
}
|
||||
//end of aweful hack
|
||||
@@ -5647,6 +5685,12 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{
|
||||
saveAsImage: false,
|
||||
saveToActiveFile: false,
|
||||
},
|
||||
desktopUIMode: this.plugin.settings.defaultTrayMode
|
||||
? "tray"
|
||||
: this.plugin.settings.compactModeOnDesktops
|
||||
? "compact"
|
||||
: "full",
|
||||
//formFactor: DEVICE.isMobile ? "phone" : DEVICE.isTablet ? "tablet" : "desktop",
|
||||
},
|
||||
initState: initdata?.appState,
|
||||
initialData: initdata,
|
||||
@@ -5829,8 +5873,8 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{
|
||||
const newCompactMode = !this.plugin.settings.compactModeOnTablets;
|
||||
await this.plugin.loadSettings();
|
||||
this.plugin.settings.compactModeOnTablets = newCompactMode;
|
||||
setTrayMode(this.app, this.plugin.settings);
|
||||
await this.plugin.saveSettings();
|
||||
setTrayMode(this.app, this.plugin.settings);
|
||||
}
|
||||
|
||||
public async toggleTrayMode(compactMode?: boolean) {
|
||||
@@ -5842,21 +5886,24 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{
|
||||
if(compactMode!==undefined) {
|
||||
this.plugin.settings.compactModeOnTablets = compactMode;
|
||||
}
|
||||
setTrayMode(this.app, this.plugin.settings);
|
||||
await this.plugin.saveSettings();
|
||||
setTrayMode(this.app, this.plugin.settings);
|
||||
if(!newTrayMode) {
|
||||
setDesktopUIMode(this.app, this.plugin.settings);
|
||||
}
|
||||
}
|
||||
|
||||
public setTrayMode(on: boolean) {
|
||||
(process.env.NODE_ENV === 'development') && DEBUGGING && debug(this.toggleTrayMode, "ExcalidrawView.setTrayMode");
|
||||
const api = this.excalidrawAPI as ExcalidrawImperativeAPI;
|
||||
if (!api) {
|
||||
return false;
|
||||
}
|
||||
api.updateScene({
|
||||
appState: { trayModeEnabled: on },
|
||||
captureUpdate: CaptureUpdateAction.NEVER,
|
||||
});
|
||||
setTimeout(()=>api.refreshEditorBreakpoints());
|
||||
api.setTrayModeEnabled(on);
|
||||
//setTimeout(()=>api.refreshEditorBreakpoints());
|
||||
}
|
||||
|
||||
public setDesktopUIMode(mode: "full" | "compact" | "tray") {
|
||||
(process.env.NODE_ENV === 'development') && DEBUGGING && debug(this.setDesktopUIMode, "ExcalidrawView.setDesktopUIMode");
|
||||
const api = this.excalidrawAPI as ExcalidrawImperativeAPI;
|
||||
api.setDesktopUIMode(mode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -349,7 +349,7 @@ export class DropManager {
|
||||
}
|
||||
if(!path) {
|
||||
new Notice(t("ERROR_CANT_READ_FILEPATH"),6000);
|
||||
return true; //excalidarw to continue processing
|
||||
return true; //excalidraw to continue processing
|
||||
}
|
||||
const link = getInternalLinkOrFileURLLink(path, this.plugin, event.dataTransfer.files[i].name, this.file);
|
||||
const {x,y} = this.currentPosition;
|
||||
@@ -414,7 +414,7 @@ export class DropManager {
|
||||
ea.destroy();
|
||||
})();
|
||||
} else if(extension === "excalidraw") {
|
||||
return true; //excalidarw to continue processing
|
||||
return true; //excalidraw to continue processing
|
||||
} else {
|
||||
(async () => {
|
||||
const file = await importFileToVault(
|
||||
@@ -460,7 +460,7 @@ export class DropManager {
|
||||
if(!path || !name) {
|
||||
new Notice(t("ERROR_CANT_READ_FILEPATH"),6000);
|
||||
ea.destroy();
|
||||
return true; //excalidarw to continue processing
|
||||
return true; //excalidraw to continue processing
|
||||
}
|
||||
const link = getInternalLinkOrFileURLLink(path, this.plugin, name, this.file);
|
||||
const id = ea.addText(
|
||||
@@ -635,4 +635,4 @@ export class DropManager {
|
||||
return "copy";
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -904,4 +904,8 @@ textarea.excalidraw-wysiwyg, .excalidraw input {
|
||||
.ExcalidrawObsidianMenu {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.excalidraw .FixedSideContainer_side_top {
|
||||
padding-top: 0 !important;
|
||||
}
|
||||
Reference in new issue
Block a user