Files
obsidian-excalidraw-plugin/docs/API/attributes_functions_overview.md

207 lines
10 KiB
Markdown
Raw Normal View History

2021-05-08 20:42:11 +02:00
# [◀ Excalidraw Automate How To](../readme.md)
2021-05-29 06:27:47 +02:00
## Attributes and functions overview
2021-05-08 20:26:09 +02:00
Here's the interface implemented by ExcalidrawAutomate:
```typescript
2021-11-01 14:12:44 +01:00
export interface ExcalidrawAutomate {
plugin: ExcalidrawPlugin;
2021-12-11 11:23:37 +01:00
elementsDict: {}; //contains the ExcalidrawElements currently edited in Automate indexed by el.id
imagesDict: {}; //the images files including DataURL, indexed by fileId
2021-11-01 14:12:44 +01:00
style: {
2021-12-11 11:23:37 +01:00
strokeColor: string; //https://www.w3schools.com/colors/default.asp
2021-11-01 14:12:44 +01:00
backgroundColor: string;
2021-12-11 11:23:37 +01:00
angle: number; //radian
fillStyle: FillStyle; //type FillStyle = "hachure" | "cross-hatch" | "solid"
2021-11-01 14:12:44 +01:00
strokeWidth: number;
2021-12-25 18:05:00 +01:00
strokeStyle: StrokeStyle; //type StrokeStyle = "solid" | "dashed" | "dotted"
2021-11-01 14:12:44 +01:00
roughness: number;
opacity: number;
2021-12-11 11:23:37 +01:00
strokeSharpness: StrokeSharpness; //type StrokeSharpness = "round" | "sharp"
2022-01-16 13:19:04 +01:00
fontFamily: number; //1: Virgil, 2:Helvetica, 3:Cascadia, 4:LocalFont
2021-11-01 14:12:44 +01:00
fontSize: number;
2021-12-11 11:23:37 +01:00
textAlign: string; //"left"|"right"|"center"
verticalAlign: string; //"top"|"bottom"|"middle" :for future use, has no effect currently
startArrowHead: string; //"triangle"|"dot"|"arrow"|"bar"|null
2021-11-01 14:12:44 +01:00
endArrowHead: string;
2021-12-11 11:23:37 +01:00
};
2021-11-01 14:12:44 +01:00
canvas: {
2021-12-11 11:23:37 +01:00
theme: string; //"dark"|"light"
viewBackgroundColor: string;
gridSize: number;
2021-09-16 20:39:04 +02:00
};
2021-12-11 11:23:37 +01:00
setFillStyle(val: number): void; //0:"hachure", 1:"cross-hatch" 2:"solid"
setStrokeStyle(val: number): void; //0:"solid", 1:"dashed", 2:"dotted"
setStrokeSharpness(val: number): void; //0:"round", 1:"sharp"
setFontFamily(val: number): void; //1: Virgil, 2:Helvetica, 3:Cascadia
setTheme(val: number): void; //0:"light", 1:"dark"
addToGroup(objectIds: []): string;
toClipboard(templatePath?: string): void;
getElements(): ExcalidrawElement[]; //get all elements from ExcalidrawAutomate elementsDict
getElement(id: string): ExcalidrawElement; //get single element from ExcalidrawAutomate elementsDict
2021-12-25 18:05:00 +01:00
create(params?: {
//create a drawing and save it to filename
2021-12-11 11:23:37 +01:00
filename?: string; //if null: default filename as defined in Excalidraw settings
foldername?: string; //if null: default folder as defined in Excalidraw settings
templatePath?: string;
onNewPane?: boolean;
frontmatterKeys?: {
"excalidraw-plugin"?: "raw" | "parsed";
"excalidraw-link-prefix"?: string;
"excalidraw-link-brackets"?: boolean;
"excalidraw-url-prefix"?: string;
};
}): Promise<string>;
createSVG(
templatePath?: string,
embedFont?: boolean,
exportSettings?: ExportSettings, //use ExcalidrawAutomate.getExportSettings(boolean,boolean)
loader?: EmbeddedFilesLoader, //use ExcalidrawAutomate.getEmbeddedFilesLoader(boolean?)
theme?: string,
): Promise<SVGSVGElement>;
createPNG(
templatePath?: string,
scale?: number,
exportSettings?: ExportSettings, //use ExcalidrawAutomate.getExportSettings(boolean,boolean)
loader?: EmbeddedFilesLoader, //use ExcalidrawAutomate.getEmbeddedFilesLoader(boolean?)
theme?: string,
): Promise<any>;
wrapText(text: string, lineLen: number): string;
addRect(topX: number, topY: number, width: number, height: number): string;
addDiamond(topX: number, topY: number, width: number, height: number): string;
addEllipse(topX: number, topY: number, width: number, height: number): string;
addBlob(topX: number, topY: number, width: number, height: number): string;
addText(
topX: number,
topY: number,
text: string,
2021-11-01 14:12:44 +01:00
formatting?: {
2021-12-11 11:23:37 +01:00
wrapAt?: number;
width?: number;
height?: number;
textAlign?: string;
box?: boolean | "box" | "blob" | "ellipse" | "diamond"; //if !null, text will be boxed
boxPadding?: number;
2021-11-01 14:12:44 +01:00
},
2021-12-11 11:23:37 +01:00
id?: string,
): string;
addLine(points: [[x: number, y: number]]): string;
addArrow(
points: [[x: number, y: number]],
2021-11-01 14:12:44 +01:00
formatting?: {
2021-12-11 11:23:37 +01:00
startArrowHead?: string;
endArrowHead?: string;
startObjectId?: string;
endObjectId?: string;
},
): string;
addImage(topX: number, topY: number, imageFile: TFile): Promise<string>;
addLaTex(topX: number, topY: number, tex: string): Promise<string>;
connectObjects(
objectA: string,
connectionA: ConnectionPoint, //type ConnectionPoint = "top" | "bottom" | "left" | "right" | null
objectB: string,
2021-12-25 18:05:00 +01:00
connectionB: ConnectionPoint, //when passed null, Excalidraw will automatically decide
2021-11-01 14:12:44 +01:00
formatting?: {
2021-12-11 11:23:37 +01:00
numberOfPoints?: number; //points on the line. Default is 0 ie. line will only have a start and end point
startArrowHead?: string; //"triangle"|"dot"|"arrow"|"bar"|null
endArrowHead?: string; //"triangle"|"dot"|"arrow"|"bar"|null
padding?: number;
},
): void;
clear(): void; //clear elementsDict and imagesDict only
reset(): void; //clear() + reset all style values to default
isExcalidrawFile(f: TFile): boolean; //returns true if MD file is an Excalidraw file
2021-11-01 14:12:44 +01:00
//view manipulation
2021-12-11 11:23:37 +01:00
targetView: ExcalidrawView; //the view currently edited
2021-12-25 18:05:00 +01:00
setView(view: ExcalidrawView | "first" | "active"): ExcalidrawView;
2021-12-11 11:23:37 +01:00
getExcalidrawAPI(): any; //https://github.com/excalidraw/excalidraw/tree/master/src/packages/excalidraw#ref
getViewElements(): ExcalidrawElement[]; //get elements in View
deleteViewElements(el: ExcalidrawElement[]): boolean;
getViewSelectedElement(): ExcalidrawElement; //get the selected element in the view, if more are selected, get the first
getViewSelectedElements(): ExcalidrawElement[];
2021-12-25 18:05:00 +01:00
getViewFileForImageElement(el: ExcalidrawElement): TFile | null; //Returns the TFile file handle for the image element
2021-12-11 11:23:37 +01:00
copyViewElementsToEAforEditing(elements: ExcalidrawElement[]): void; //copies elements from view to elementsDict for editing
viewToggleFullScreen(forceViewMode?: boolean): void;
connectObjectWithViewSelectedElement( //connect an object to the selected element in the view
objectA: string, //see connectObjects
2021-12-25 18:05:00 +01:00
connectionA: ConnectionPoint,
2021-12-11 11:23:37 +01:00
connectionB: ConnectionPoint,
2021-11-01 14:12:44 +01:00
formatting?: {
2021-12-11 11:23:37 +01:00
numberOfPoints?: number;
startArrowHead?: string;
endArrowHead?: string;
padding?: number;
2021-11-01 14:12:44 +01:00
},
2021-12-11 11:23:37 +01:00
): boolean;
addElementsToView( //Adds elements from elementsDict to the current view
2022-01-29 14:20:34 +01:00
repositionToCursor?: boolean, //default is false
2022-01-10 22:13:27 +01:00
save?: boolean, //default is true
//newElementsOnTop controls whether elements created with ExcalidrawAutomate
//are added at the bottom of the stack or the top of the stack of elements already in the view
//Note that elements copied to the view with copyViewElementsToEAforEditing retain their
//position in the stack of elements in the view even if modified using EA
newElementsOnTop?: boolean, //default is false, i.e. the new elements get to the bottom of the stack
2021-12-11 11:23:37 +01:00
): Promise<boolean>;
2021-12-25 18:05:00 +01:00
onDropHook(data: {
//if set Excalidraw will call this function onDrop events
2021-12-11 11:23:37 +01:00
ea: ExcalidrawAutomate;
event: React.DragEvent<HTMLDivElement>;
draggable: any; //Obsidian draggable object
type: "file" | "text" | "unknown";
payload: {
files: TFile[]; //TFile[] array of dropped files
text: string; //string
};
excalidrawFile: TFile; //the file receiving the drop event
view: ExcalidrawView; //the excalidraw view receiving the drop
pointerPosition: { x: number; y: number }; //the pointer position on canvas at the time of drop
}): boolean; //a return of true will stop the default onDrop processing in Excalidraw
mostRecentMarkdownSVG: SVGSVGElement; //Markdown renderer will drop a copy of the most recent SVG here for debugging purposes
getEmbeddedFilesLoader(isDark?: boolean): EmbeddedFilesLoader; //utility function to generate EmbeddedFilesLoader object
getExportSettings( //utility function to generate ExportSettings object
withBackground: boolean,
withTheme: boolean,
): ExportSettings;
2021-12-25 18:05:00 +01:00
getBoundingBox(elements: ExcalidrawElement[]): {
//get bounding box of elements
2021-12-11 11:23:37 +01:00
topX: number; //bounding box is the box encapsulating all of the elements completely
topY: number;
width: number;
height: number;
};
//elements grouped by the highest level groups
2021-12-25 18:05:00 +01:00
getMaximumGroups(elements: ExcalidrawElement[]): ExcalidrawElement[][];
2021-12-11 11:23:37 +01:00
//gets the largest element from a group. useful when a text element is grouped with a box, and you want to connect an arrow to the box
getLargestElement(elements: ExcalidrawElement[]): ExcalidrawElement;
// Returns 2 or 0 intersection points between line going through `a` and `b`
// and the `element`, in ascending order of distance from `a`.
2021-12-25 18:05:00 +01:00
intersectElementWithLine(
2021-12-11 11:23:37 +01:00
element: ExcalidrawBindableElement,
a: readonly [number, number],
b: readonly [number, number],
gap?: number, //if given, element is inflated by this value
): Point[];
2022-01-10 22:13:27 +01:00
2022-01-07 19:34:24 +01:00
//See OCR plugin for example on how to use scriptSettings
activeScript: string; //Set automatically by the ScriptEngine
getScriptSettings(): {}; //Returns script settings. Saves settings in plugin settings, under the activeScript key
2022-01-29 14:20:34 +01:00
setScriptSettings(settings: any): Promise<void>; //sets script settings.
openFileInNewOrAdjacentLeaf(file: TFile): WorkspaceLeaf; //Open a file in a new workspaceleaf or reuse an existing adjacent leaf depending on Excalidraw Plugin Settings
measureText(text: string): { width: number; height: number }; //measure text size based on current style settings
//verifyMinimumPluginVersion returns true if plugin version is >= than required
2022-01-29 14:20:34 +01:00
//recommended use:
//if(!ea.verifyMinimumPluginVersion || !ea.verifyMinimumPluginVersion("1.5.20")) {new Notice("message");return;}
verifyMinimumPluginVersion(requiredVersion: string): boolean;
selectElementsInView(elements: ExcalidrawElement[]): void; //sets selection in view
generateElementId(): string; //returns an 8 character long random id
cloneElement(element: ExcalidrawElement): ExcalidrawElement; //Returns a clone of the element with a new id
2022-02-19 18:16:00 +01:00
moveViewElementToZIndex(elementId:number, newZIndex:number): void; //Moves the element to a specific position in the z-index
hexStringToRgb(color: string):number[];
rgbToHexString(color: number[]):string;
hslToRgb(color: number[]):number[];
rgbToHsl(color:number[]):number[];
colorNameToHex(color:string):string;
2021-09-03 18:47:25 +02:00
}
```