@excalidraw/common 0.18.0-4ce38fb → 0.18.0-4ce8305
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dev/index.js +25 -17
- package/dist/dev/index.js.map +3 -3
- package/dist/prod/index.js +3 -3
- package/dist/types/common/src/utils.d.ts +7 -1
- package/dist/types/element/src/align.d.ts +4 -1
- package/dist/types/element/src/binding.d.ts +36 -0
- package/dist/types/element/src/bounds.d.ts +10 -2
- package/dist/types/element/src/collision.d.ts +7 -0
- package/dist/types/element/src/cropElement.d.ts +36 -4
- package/dist/types/element/src/delta.d.ts +7 -1
- package/dist/types/element/src/distribute.d.ts +4 -1
- package/dist/types/element/src/dragElements.d.ts +8 -3
- package/dist/types/element/src/elbowArrow.d.ts +5 -0
- package/dist/types/element/src/embeddable.d.ts +2 -1
- package/dist/types/element/src/groups.d.ts +1 -6
- package/dist/types/element/src/image.d.ts +5 -2
- package/dist/types/element/src/index.d.ts +1 -0
- package/dist/types/element/src/linearElementEditor.d.ts +4 -1
- package/dist/types/element/src/listMarker.d.ts +7 -2
- package/dist/types/element/src/newElement.d.ts +3 -1
- package/dist/types/element/src/renderElement.d.ts +10 -0
- package/dist/types/element/src/renderEnvironment.d.ts +66 -0
- package/dist/types/element/src/resizeElements.d.ts +15 -5
- package/dist/types/element/src/selection.d.ts +1 -7
- package/dist/types/element/src/shape.d.ts +2 -0
- package/dist/types/element/src/stickyNote.d.ts +8 -0
- package/dist/types/element/src/textElement.d.ts +3 -2
- package/dist/types/element/src/textMeasurements.d.ts +15 -11
- package/dist/types/element/src/textWrapping.d.ts +3 -2
- package/dist/types/element/src/transform.d.ts +5 -1
- package/dist/types/excalidraw/actions/actionBoundText.d.ts +46 -221
- package/dist/types/excalidraw/actions/actionCanvas.d.ts +2 -2
- package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +4 -588
- package/dist/types/excalidraw/actions/actionExport.d.ts +2 -2
- package/dist/types/excalidraw/actions/actionFrame.d.ts +41 -525
- package/dist/types/excalidraw/actions/actionToggleWrap.d.ts +12 -0
- package/dist/types/excalidraw/actions/index.d.ts +1 -0
- package/dist/types/excalidraw/actions/shortcuts.d.ts +1 -1
- package/dist/types/excalidraw/actions/types.d.ts +1 -1
- package/dist/types/excalidraw/appState.d.ts +2 -2
- package/dist/types/excalidraw/charts/charts.bar.d.ts +2 -1
- package/dist/types/excalidraw/charts/charts.helpers.d.ts +6 -5
- package/dist/types/excalidraw/charts/charts.line.d.ts +2 -1
- package/dist/types/excalidraw/charts/charts.radar.d.ts +2 -1
- package/dist/types/excalidraw/charts/index.d.ts +2 -1
- package/dist/types/excalidraw/components/App.d.ts +34 -20
- package/dist/types/excalidraw/components/App.host.d.ts +102 -0
- package/dist/types/excalidraw/components/App.modifiers.d.ts +38 -0
- package/dist/types/excalidraw/components/App.selection.d.ts +265 -0
- package/dist/types/excalidraw/components/App.selectionTool.d.ts +93 -0
- package/dist/types/excalidraw/components/App.viewport.d.ts +13 -3
- package/dist/types/excalidraw/components/App.wrap.d.ts +31 -0
- package/dist/types/excalidraw/components/ConvertElementTypePopup.d.ts +2 -1
- package/dist/types/excalidraw/components/Stats/utils.d.ts +4 -2
- package/dist/types/excalidraw/components/TTDDialog/MermaidToExcalidraw.d.ts +2 -1
- package/dist/types/excalidraw/components/TTDDialog/TTDDialogOutput.d.ts +5 -2
- package/dist/types/excalidraw/components/TTDDialog/TTDPreviewPanel.d.ts +5 -2
- package/dist/types/excalidraw/components/TTDDialog/TextToDiagram.d.ts +2 -1
- package/dist/types/excalidraw/components/TTDDialog/common.d.ts +4 -1
- package/dist/types/excalidraw/components/TTDDialog/hooks/useTextGeneration.d.ts +3 -2
- package/dist/types/excalidraw/components/TTDDialog/types.d.ts +14 -1
- package/dist/types/excalidraw/components/TTDDialog/utils/mermaidError.d.ts +27 -1
- package/dist/types/excalidraw/components/Tooltip.d.ts +11 -1
- package/dist/types/excalidraw/components/TopPicksDnD/topPicksDnD.d.ts +1 -1
- package/dist/types/excalidraw/components/canvases/InteractiveCanvas.d.ts +0 -1
- package/dist/types/excalidraw/components/hyperlink/Hyperlink.d.ts +3 -2
- package/dist/types/excalidraw/components/hyperlink/helpers.d.ts +13 -2
- package/dist/types/excalidraw/data/blob.d.ts +4 -4
- package/dist/types/excalidraw/data/index.d.ts +3 -3
- package/dist/types/excalidraw/data/json.d.ts +2 -2
- package/dist/types/excalidraw/fonts/Fonts.d.ts +9 -6
- package/dist/types/excalidraw/history.d.ts +10 -4
- package/dist/types/excalidraw/reactUtils.d.ts +1 -1
- package/dist/types/excalidraw/renderer/animation.d.ts +11 -4
- package/dist/types/excalidraw/renderer/staticScene.d.ts +11 -6
- package/dist/types/excalidraw/scene/Renderer.d.ts +1 -1
- package/dist/types/excalidraw/scene/export.d.ts +343 -20
- package/dist/types/excalidraw/scene/types.d.ts +23 -1
- package/dist/types/excalidraw/types.d.ts +49 -1
- package/dist/types/utils/src/index.d.ts +3 -1
- package/package.json +1 -1
- package/dist/types/utils/src/export.d.ts +0 -36
|
@@ -16,4 +16,9 @@ export declare const updateElbowArrowPoints: (arrow: Readonly<ExcalidrawElbowArr
|
|
|
16
16
|
isBindingEnabled?: boolean;
|
|
17
17
|
isMidpointSnappingEnabled?: boolean;
|
|
18
18
|
}) => ElementUpdate<ExcalidrawElbowArrowElement>;
|
|
19
|
+
/**
|
|
20
|
+
* The update routing an elbow arrow again where it is, e.g. once its
|
|
21
|
+
* arrowheads change, as its route makes room for them
|
|
22
|
+
*/
|
|
23
|
+
export declare const updateElbowArrowRoute: <T extends ExcalidrawElbowArrowElement>(arrow: Readonly<T>, elementsMap: NonDeletedSceneElementsMap) => ElementUpdate<T>;
|
|
19
24
|
export declare const validateElbowPoints: <P extends GlobalPoint | LocalPoint>(points: readonly P[], tolerance?: number) => boolean;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { ExcalidrawProps } from "@excalidraw/excalidraw/types";
|
|
2
2
|
import type { MarkRequired } from "@excalidraw/common/utility-types";
|
|
3
|
+
import type { RenderEnvironment } from "./renderEnvironment";
|
|
3
4
|
import type { ExcalidrawIframeLikeElement, IframeData, NonDeletedExcalidrawElement } from "./types";
|
|
4
5
|
type IframeDataWithSandbox = MarkRequired<IframeData, "sandbox">;
|
|
5
6
|
export declare const createSrcDoc: (body: string) => string;
|
|
6
7
|
export declare const getEmbedLink: (link: string | null | undefined) => IframeDataWithSandbox | null;
|
|
7
|
-
export declare const createPlaceholderEmbeddableLabel: (element: ExcalidrawIframeLikeElement) => NonDeletedExcalidrawElement;
|
|
8
|
+
export declare const createPlaceholderEmbeddableLabel: (element: ExcalidrawIframeLikeElement, renderEnvironment?: RenderEnvironment) => NonDeletedExcalidrawElement;
|
|
8
9
|
export declare const maybeParseEmbedSrc: (str: string) => string;
|
|
9
10
|
export declare const embeddableURLValidator: (url: string | null | undefined, validateEmbeddable: ExcalidrawProps["validateEmbeddable"]) => boolean;
|
|
10
11
|
export {};
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { Mutable } from "@excalidraw/common/utility-types";
|
|
1
|
+
import type { AppState, InteractiveCanvasAppState } from "@excalidraw/excalidraw/types";
|
|
3
2
|
import type { GroupId, ExcalidrawElement, NonDeleted, ElementsMapOrArray, ElementsMap, NonDeletedExcalidrawElement, NonDeletedElementsMapOrArray } from "./types";
|
|
4
3
|
export declare const selectGroup: (groupId: GroupId, appState: InteractiveCanvasAppState, elements: readonly NonDeletedExcalidrawElement[]) => Pick<InteractiveCanvasAppState, "selectedGroupIds" | "selectedElementIds" | "editingGroupId">;
|
|
5
|
-
export declare const selectGroupsForSelectedElements: {
|
|
6
|
-
(appState: Pick<AppState, "selectedElementIds" | "editingGroupId">, elements: readonly NonDeletedExcalidrawElement[], prevAppState: InteractiveCanvasAppState, app: AppClassProperties | null): Mutable<Pick<InteractiveCanvasAppState, "selectedGroupIds" | "editingGroupId" | "selectedElementIds">>;
|
|
7
|
-
clearCache(): void;
|
|
8
|
-
};
|
|
9
4
|
/**
|
|
10
5
|
* If the element's group is selected, don't render an individual
|
|
11
6
|
* selection border around it.
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import type { AppClassProperties, DataURL, BinaryFiles } from "@excalidraw/excalidraw/types";
|
|
2
2
|
import type { ExcalidrawElement, FileId, InitializedExcalidrawImageElement } from "./types";
|
|
3
|
-
export declare const loadHTMLImageElement: (dataURL: DataURL) => Promise<HTMLImageElement>;
|
|
3
|
+
export declare const loadHTMLImageElement: (dataURL: DataURL, createImage?: () => HTMLImageElement) => Promise<HTMLImageElement>;
|
|
4
4
|
/** NOTE: updates cache even if already populated with given image. Thus,
|
|
5
5
|
* you should filter out the images upstream if you want to optimize this. */
|
|
6
|
-
export declare const updateImageCache: ({ fileIds, files, imageCache, }: {
|
|
6
|
+
export declare const updateImageCache: ({ fileIds, files, imageCache, createImage, }: {
|
|
7
7
|
fileIds: FileId[];
|
|
8
8
|
files: BinaryFiles;
|
|
9
9
|
imageCache: AppClassProperties["imageCache"];
|
|
10
|
+
/** creates images in the owner window so cross-document scenes keep
|
|
11
|
+
* runtime ownership of their HTMLImageElements */
|
|
12
|
+
createImage?: () => HTMLImageElement;
|
|
10
13
|
}) => Promise<{
|
|
11
14
|
imageCache: Map<FileId, {
|
|
12
15
|
image: HTMLImageElement | Promise<HTMLImageElement>;
|
|
@@ -41,6 +41,7 @@ export * from "./mutateElement";
|
|
|
41
41
|
export * from "./newElement";
|
|
42
42
|
export * from "./positionElementsOnGrid";
|
|
43
43
|
export * from "./renderElement";
|
|
44
|
+
export * from "./renderEnvironment";
|
|
44
45
|
export * from "./resizeElements";
|
|
45
46
|
export * from "./resizeTest";
|
|
46
47
|
export * from "./Scene";
|
|
@@ -103,10 +103,10 @@ export declare class LinearElementEditor {
|
|
|
103
103
|
static movePoints(element: NonDeleted<ExcalidrawLinearElement>, scene: Scene, pointUpdates: PointsPositionUpdates, otherUpdates?: {
|
|
104
104
|
startBinding?: FixedPointBinding | null;
|
|
105
105
|
endBinding?: FixedPointBinding | null;
|
|
106
|
-
moveMidPointsWithElement?: boolean | null;
|
|
107
106
|
}, options?: {
|
|
108
107
|
isBindingEnabled?: boolean;
|
|
109
108
|
isMidpointSnappingEnabled?: boolean;
|
|
109
|
+
moveMidPointsWithElement?: boolean;
|
|
110
110
|
}): void;
|
|
111
111
|
static shouldAddMidpoint(linearElementEditor: LinearElementEditor, pointerCoords: PointerCoords, appState: AppState, elementsMap: ElementsMap): boolean;
|
|
112
112
|
static addMidpoint(linearElementEditor: LinearElementEditor, pointerCoords: PointerCoords, app: AppClassProperties, snapToGrid: boolean, scene: Scene): {
|
|
@@ -122,6 +122,9 @@ export declare class LinearElementEditor {
|
|
|
122
122
|
*/
|
|
123
123
|
static getBoundTextElementCenter: (element: ExcalidrawLinearElement, elementsMap: ElementsMap) => GlobalPoint;
|
|
124
124
|
static handleBoundTextDragging(linearElementEditor: LinearElementEditor, scene: Scene, pointerX: number, pointerY: number): LinearElementEditor | null;
|
|
125
|
+
static getPathLength(element: ExcalidrawLinearElement, elementsMap: ElementsMap): number;
|
|
126
|
+
/** the path parameter (0-1) of the point on the path closest to `point` */
|
|
127
|
+
static getPathParameterAtPoint(element: ExcalidrawLinearElement, point: GlobalPoint, elementsMap: ElementsMap): number | null;
|
|
125
128
|
static getPointAtPathParameter(container: ExcalidrawLinearElement, pathParameter: number, elementsMap: ElementsMap): GlobalPoint | null;
|
|
126
129
|
static getBoundTextElementPosition: (element: ExcalidrawLinearElement, boundTextElement: ExcalidrawTextElementWithContainer, elementsMap: ElementsMap) => {
|
|
127
130
|
x: number;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RenderEnvironment } from "./renderEnvironment";
|
|
1
2
|
import type { Scene } from "./Scene";
|
|
2
3
|
import type { ExcalidrawElement, ExcalidrawTextElement } from "./types";
|
|
3
4
|
/** a list marker advanced by duplication, to go back and forth */
|
|
@@ -27,8 +28,12 @@ export type ListMarkerAdvance = {
|
|
|
27
28
|
* Only if nothing but list items (texts, or containers with list item labels)
|
|
28
29
|
* is duplicated.
|
|
29
30
|
*/
|
|
30
|
-
export declare const advanceDuplicatedListMarkers: (duplicatedElements: readonly ExcalidrawElement[], scene: Scene
|
|
31
|
+
export declare const advanceDuplicatedListMarkers: (duplicatedElements: readonly ExcalidrawElement[], scene: Scene,
|
|
32
|
+
/** measures the re-numbered texts */
|
|
33
|
+
renderEnvironment?: RenderEnvironment) => ListMarkerAdvance[];
|
|
31
34
|
/**
|
|
32
35
|
* Sets the advanced list markers back (`"prev"`), or forth again (`"next"`).
|
|
33
36
|
*/
|
|
34
|
-
export declare const applyListMarkerAdvances: (advances: readonly ListMarkerAdvance[], direction: "prev" | "next", scene: Scene
|
|
37
|
+
export declare const applyListMarkerAdvances: (advances: readonly ListMarkerAdvance[], direction: "prev" | "next", scene: Scene,
|
|
38
|
+
/** measures the re-numbered texts */
|
|
39
|
+
renderEnvironment?: RenderEnvironment) => void;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { MarkOptional } from "@excalidraw/common/utility-types";
|
|
2
|
+
import type { RenderEnvironment } from "./renderEnvironment";
|
|
2
3
|
import type { ExcalidrawImageElement, ExcalidrawTextElement, ExcalidrawLinearElement, ExcalidrawGenericElement, NonDeleted, TextAlign, VerticalAlign, Arrowhead, ExcalidrawFreeDrawElement, FontFamilyValues, ExcalidrawTextContainer, ExcalidrawFrameElement, ExcalidrawEmbeddableElement, ExcalidrawMagicFrameElement, ExcalidrawIframeElement, ElementsMap, ExcalidrawArrowElement, ExcalidrawElbowArrowElement, ExcalidrawLineElement, ExcalidrawStickyNoteElement } from "./types";
|
|
3
4
|
export type ElementConstructorOpts = MarkOptional<Omit<ExcalidrawGenericElement, "id" | "type" | "isDeleted" | "updated">, "width" | "height" | "angle" | "groupIds" | "frameId" | "index" | "boundElements" | "seed" | "version" | "versionNonce" | "link" | "strokeStyle" | "fillStyle" | "strokeColor" | "backgroundColor" | "roughness" | "strokeWidth" | "roundness" | "locked" | "opacity" | "customData" | "created">;
|
|
4
5
|
export declare const newElement: (opts: {
|
|
@@ -61,6 +62,7 @@ export declare const newTextElement: (opts: {
|
|
|
61
62
|
autoResize?: ExcalidrawTextElement["autoResize"];
|
|
62
63
|
labelPosition?: ExcalidrawTextElement["labelPosition"];
|
|
63
64
|
baseFontSize?: ExcalidrawTextElement["baseFontSize"];
|
|
65
|
+
renderEnvironment?: RenderEnvironment;
|
|
64
66
|
} & ElementConstructorOpts) => NonDeleted<ExcalidrawTextElement>;
|
|
65
67
|
export declare const refreshTextDimensions: (textElement: ExcalidrawTextElement, container: ExcalidrawTextContainer | null, elementsMap: ElementsMap, text?: string,
|
|
66
68
|
/**
|
|
@@ -69,7 +71,7 @@ export declare const refreshTextDimensions: (textElement: ExcalidrawTextElement,
|
|
|
69
71
|
* width from then on (`autoResize: false`), anchored as its growth was. A
|
|
70
72
|
* text that is already wider keeps growing.
|
|
71
73
|
*/
|
|
72
|
-
maxWidth?: number) => {
|
|
74
|
+
maxWidth?: number, renderEnvironment?: RenderEnvironment) => {
|
|
73
75
|
x: number;
|
|
74
76
|
y: number;
|
|
75
77
|
width: number;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type GlobalPoint } from "@excalidraw/math";
|
|
2
2
|
import type { AppState, StaticCanvasAppState, InteractiveCanvasAppState, ElementRenderOverrides } from "@excalidraw/excalidraw/types";
|
|
3
3
|
import type { StaticCanvasRenderConfig, RenderableElementsMap, InteractiveCanvasRenderConfig } from "@excalidraw/excalidraw/scene/types";
|
|
4
|
+
import type { RenderEnvironment } from "./renderEnvironment";
|
|
4
5
|
import type { ExcalidrawElement, ExcalidrawTextElement, NonDeletedExcalidrawElement, ExcalidrawFreeDrawElement, ExcalidrawImageElement, NonDeletedSceneElementsMap, ElementsMap } from "./types";
|
|
5
6
|
import type { RoughCanvas } from "roughjs/bin/canvas";
|
|
6
7
|
export type RenderPositionOffset = Readonly<{
|
|
@@ -22,6 +23,9 @@ export interface ExcalidrawElementWithCanvas {
|
|
|
22
23
|
canvas: HTMLCanvasElement;
|
|
23
24
|
theme: AppState["theme"];
|
|
24
25
|
scale: number;
|
|
26
|
+
/** backing-store scale the bitmap was rasterized at, see StaticCanvasRenderConfig["scale"] */
|
|
27
|
+
deviceScale: number;
|
|
28
|
+
environment: RenderEnvironment;
|
|
25
29
|
zoomValue: AppState["zoom"]["value"];
|
|
26
30
|
canvasOffsetX: number;
|
|
27
31
|
canvasOffsetY: number;
|
|
@@ -29,6 +33,12 @@ export interface ExcalidrawElementWithCanvas {
|
|
|
29
33
|
containingFrameOpacity: number;
|
|
30
34
|
}
|
|
31
35
|
export declare const DEFAULT_LINK_SIZE = 14;
|
|
36
|
+
/**
|
|
37
|
+
* `save()`s the context around `draw`, restoring it even when `draw` throws:
|
|
38
|
+
* the scene renderer logs a failing element and carries on, and the element
|
|
39
|
+
* mustn't leave its transforms and clips behind for the next one.
|
|
40
|
+
*/
|
|
41
|
+
export declare const withSavedContext: (context: CanvasRenderingContext2D, draw: () => void) => void;
|
|
32
42
|
export declare const elementWithCanvasCache: WeakMap<ExcalidrawElement, ExcalidrawElementWithCanvas>;
|
|
33
43
|
export declare const renderSelectionElement: (element: NonDeletedExcalidrawElement, context: CanvasRenderingContext2D, appState: InteractiveCanvasAppState, selectionColor: InteractiveCanvasRenderConfig["selectionColor"]) => void;
|
|
34
44
|
export declare const renderElement: (element: NonDeletedExcalidrawElement, elementsMap: RenderableElementsMap, allElementsMap: NonDeletedSceneElementsMap, rc: RoughCanvas, context: CanvasRenderingContext2D, renderConfig: StaticCanvasRenderConfig, appState: StaticCanvasAppState | InteractiveCanvasAppState, renderState?: Readonly<{
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host environment used by the renderer and export pipeline.
|
|
3
|
+
*
|
|
4
|
+
* The default is the browser's. An explicit environment (see
|
|
5
|
+
* `StaticCanvasRenderConfig["renderEnvironment"]`) scopes canvas and image
|
|
6
|
+
* creation to one render target -- e.g. the editor's owner window, so that
|
|
7
|
+
* one process can host editors in multiple realms (popouts, multi-tenant
|
|
8
|
+
* embeds), or an export running where `document`/`window` don't exist (Node
|
|
9
|
+
* with `node-canvas` / `@napi-rs/canvas`, passed in `config.environment`).
|
|
10
|
+
* There is deliberately no process-wide override: every render and export
|
|
11
|
+
* takes its environment explicitly.
|
|
12
|
+
*
|
|
13
|
+
* `document` is the DOM side of the same host: what SVG exports are built in
|
|
14
|
+
* (a DOM implementation such as `linkedom` under Node).
|
|
15
|
+
*/
|
|
16
|
+
import type { TextMetricsProvider } from "./textMeasurements";
|
|
17
|
+
export type RenderEnvironment = {
|
|
18
|
+
/** Creates a blank canvas. Callers set `width`/`height` themselves. */
|
|
19
|
+
createCanvas: () => HTMLCanvasElement;
|
|
20
|
+
/**
|
|
21
|
+
* Creates an image to be decoded from a data URL and later used as a
|
|
22
|
+
* `drawImage` source.
|
|
23
|
+
*
|
|
24
|
+
* NOTE: typed as `HTMLImageElement` because the renderer is typed against
|
|
25
|
+
* the DOM lib throughout. Non-DOM implementations (node-canvas et al) need
|
|
26
|
+
* to cast; they must support `src`, `onload`, `onerror`, `naturalWidth`,
|
|
27
|
+
* `naturalHeight` and be accepted by their canvas' `drawImage`.
|
|
28
|
+
*/
|
|
29
|
+
createImage: () => HTMLImageElement;
|
|
30
|
+
/**
|
|
31
|
+
* Creates a fillable path from an SVG path string -- freedraw elements are
|
|
32
|
+
* filled through one.
|
|
33
|
+
*
|
|
34
|
+
* Optional, because browsers always have the global `Path2D` this falls back
|
|
35
|
+
* to. A Node host MUST supply it (e.g. `@napi-rs/canvas`'s `Path2D`) or
|
|
36
|
+
* install `globalThis.Path2D` itself: Node has no such global, and without
|
|
37
|
+
* one every freedraw element fails to render.
|
|
38
|
+
*/
|
|
39
|
+
createPath?: (svgPath: string) => Path2D;
|
|
40
|
+
/**
|
|
41
|
+
* The document SVG exports are built in: the editor's owner document, or
|
|
42
|
+
* outside the browser a DOM implementation's (e.g. `linkedom`).
|
|
43
|
+
*
|
|
44
|
+
* Optional; falls back to the global `document`.
|
|
45
|
+
*/
|
|
46
|
+
document?: Document;
|
|
47
|
+
/**
|
|
48
|
+
* Measures text (line widths, for wrapping and layout).
|
|
49
|
+
*
|
|
50
|
+
* Optional; falls back to the global provider set with
|
|
51
|
+
* `setCustomTextMetricsProvider`, else to measuring on a canvas from
|
|
52
|
+
* `createCanvas`.
|
|
53
|
+
*/
|
|
54
|
+
textMetrics?: TextMetricsProvider;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Resolves the host environment for a render: the explicitly scoped one (e.g.
|
|
58
|
+
* the editor's owner window, or an export's), else the browser default.
|
|
59
|
+
*/
|
|
60
|
+
export declare const getRenderEnvironment: (env?: RenderEnvironment) => RenderEnvironment;
|
|
61
|
+
/**
|
|
62
|
+
* Resolves the path factory for a render. `createPath` is the one optional
|
|
63
|
+
* member of the contract, so this fills in the global-`Path2D` default for
|
|
64
|
+
* environments that omit it.
|
|
65
|
+
*/
|
|
66
|
+
export declare const getCreatePath: (env?: RenderEnvironment) => ((svgPath: string) => Path2D);
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { type LocalPoint } from "@excalidraw/math";
|
|
2
2
|
import type { PointerDownState } from "@excalidraw/excalidraw/types";
|
|
3
|
+
import type { RenderEnvironment } from "./renderEnvironment";
|
|
3
4
|
import type { Scene } from "./Scene";
|
|
4
5
|
import type { BoundingBox } from "./bounds";
|
|
5
6
|
import type { MaybeTransformHandleType, TransformHandleDirection } from "./transformHandles";
|
|
6
|
-
import type { ExcalidrawLinearElement, ExcalidrawTextElement, NonDeletedExcalidrawElement, NonDeleted, ElementsMap } from "./types";
|
|
7
|
-
export declare const transformElements: (originalElements: PointerDownState["originalElements"], transformHandleType: MaybeTransformHandleType, selectedElements: readonly NonDeletedExcalidrawElement[], scene: Scene, shouldRotateWithDiscreteAngle: boolean, shouldResizeFromCenter: boolean, shouldMaintainAspectRatio: boolean, pointerX: number, pointerY: number, centerX: number, centerY: number) => boolean;
|
|
7
|
+
import type { ExcalidrawLinearElement, ExcalidrawTextElement, NonDeletedExcalidrawElement, NonDeleted, ExcalidrawElement, ElementsMap } from "./types";
|
|
8
|
+
export declare const transformElements: (originalElements: PointerDownState["originalElements"], transformHandleType: MaybeTransformHandleType, selectedElements: readonly NonDeletedExcalidrawElement[], scene: Scene, shouldRotateWithDiscreteAngle: boolean, shouldResizeFromCenter: boolean, shouldMaintainAspectRatio: boolean, pointerX: number, pointerY: number, centerX: number, centerY: number, renderEnvironment?: RenderEnvironment) => boolean;
|
|
8
9
|
export declare const rescalePointsInElement: (element: NonDeletedExcalidrawElement, width: number, height: number, normalizePoints: boolean) => {
|
|
9
10
|
points: LocalPoint[];
|
|
10
11
|
} | {
|
|
@@ -13,15 +14,23 @@ export declare const rescalePointsInElement: (element: NonDeletedExcalidrawEleme
|
|
|
13
14
|
export declare const measureFontSizeFromWidth: (element: NonDeleted<ExcalidrawTextElement>, elementsMap: ElementsMap, nextWidth: number) => {
|
|
14
15
|
size: number;
|
|
15
16
|
} | null;
|
|
16
|
-
export declare const resizeSingleTextElement: (origElement: NonDeleted<ExcalidrawTextElement>, element: NonDeleted<ExcalidrawTextElement>, scene: Scene, transformHandleType: TransformHandleDirection, shouldResizeFromCenter: boolean, nextWidth: number, nextHeight: number) => void;
|
|
17
|
+
export declare const resizeSingleTextElement: (origElement: NonDeleted<ExcalidrawTextElement>, element: NonDeleted<ExcalidrawTextElement>, scene: Scene, transformHandleType: TransformHandleDirection, shouldResizeFromCenter: boolean, nextWidth: number, nextHeight: number, renderEnvironment?: RenderEnvironment) => void;
|
|
17
18
|
export declare const getResizeOffsetXY: (transformHandleType: MaybeTransformHandleType, selectedElements: NonDeletedExcalidrawElement[], elementsMap: ElementsMap, x: number, y: number) => [number, number];
|
|
18
19
|
export declare const getResizeArrowDirection: (transformHandleType: MaybeTransformHandleType, element: NonDeleted<ExcalidrawLinearElement>) => "origin" | "end";
|
|
19
|
-
export declare const resizeSingleElement: (nextWidth: number, nextHeight: number, latestElement: NonDeletedExcalidrawElement, origElement: NonDeletedExcalidrawElement, originalElementsMap: ElementsMap, scene: Scene, handleDirection: TransformHandleDirection, { shouldInformMutation, shouldMaintainAspectRatio, shouldResizeFromCenter, }?: {
|
|
20
|
+
export declare const resizeSingleElement: (nextWidth: number, nextHeight: number, latestElement: NonDeletedExcalidrawElement, origElement: NonDeletedExcalidrawElement, originalElementsMap: ElementsMap, scene: Scene, handleDirection: TransformHandleDirection, { shouldInformMutation, shouldMaintainAspectRatio, shouldResizeFromCenter, renderEnvironment, }?: {
|
|
20
21
|
shouldMaintainAspectRatio?: boolean;
|
|
21
22
|
shouldResizeFromCenter?: boolean;
|
|
22
23
|
shouldInformMutation?: boolean;
|
|
24
|
+
renderEnvironment?: RenderEnvironment;
|
|
23
25
|
}) => void;
|
|
24
|
-
export declare const
|
|
26
|
+
export declare const getNextSingleWidthAndHeightFromPointer: (latestElement: ExcalidrawElement, origElement: ExcalidrawElement, handleDirection: TransformHandleDirection, pointerX: number, pointerY: number, { shouldMaintainAspectRatio, shouldResizeFromCenter, }?: {
|
|
27
|
+
shouldMaintainAspectRatio?: boolean;
|
|
28
|
+
shouldResizeFromCenter?: boolean;
|
|
29
|
+
}) => {
|
|
30
|
+
nextWidth: number;
|
|
31
|
+
nextHeight: number;
|
|
32
|
+
};
|
|
33
|
+
export declare const resizeMultipleElements: (selectedElements: readonly NonDeletedExcalidrawElement[], elementsMap: ElementsMap, handleDirection: TransformHandleDirection, scene: Scene, originalElementsMap: ElementsMap, { shouldMaintainAspectRatio, shouldResizeFromCenter, flipByX, flipByY, nextHeight, nextWidth, originalBoundingBox, renderEnvironment, }?: {
|
|
25
34
|
nextWidth?: number;
|
|
26
35
|
nextHeight?: number;
|
|
27
36
|
shouldMaintainAspectRatio?: boolean;
|
|
@@ -29,4 +38,5 @@ export declare const resizeMultipleElements: (selectedElements: readonly NonDele
|
|
|
29
38
|
flipByX?: boolean;
|
|
30
39
|
flipByY?: boolean;
|
|
31
40
|
originalBoundingBox?: BoundingBox;
|
|
41
|
+
renderEnvironment?: RenderEnvironment;
|
|
32
42
|
}) => void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AppState, BoxSelectionMode, InteractiveCanvasAppState } from "@excalidraw/excalidraw/types";
|
|
2
|
-
import { LinearElementEditor } from "./linearElementEditor";
|
|
3
2
|
import type { ElementsMap, ElementsMapOrArray, ExcalidrawElement, NonDeleted, NonDeletedExcalidrawElement } from "./types";
|
|
3
|
+
export declare const shouldIgnoreElementFromSelection: (element: ExcalidrawElement) => boolean;
|
|
4
4
|
/**
|
|
5
5
|
* Frames and their containing elements are not to be selected at the same time.
|
|
6
6
|
* Given an array of selected elements, if there are frames and their containing elements
|
|
@@ -26,12 +26,6 @@ export declare const getTargetElements: (elements: ElementsMapOrArray, appState:
|
|
|
26
26
|
export declare const makeNextSelectedElementIds: (nextSelectedElementIds: AppState["selectedElementIds"], prevState: Pick<AppState, "selectedElementIds">) => Readonly<{
|
|
27
27
|
[id: string]: true;
|
|
28
28
|
}>;
|
|
29
|
-
export declare const getSelectionStateForElements: (targetElements: readonly NonDeletedExcalidrawElement[], allElements: readonly NonDeletedExcalidrawElement[], appState: AppState) => {
|
|
30
|
-
selectedElementIds: AppState["selectedElementIds"];
|
|
31
|
-
selectedGroupIds: AppState["selectedGroupIds"];
|
|
32
|
-
editingGroupId: AppState["editingGroupId"];
|
|
33
|
-
selectedLinearElement: LinearElementEditor | null;
|
|
34
|
-
};
|
|
35
29
|
/**
|
|
36
30
|
* Returns editing or single-selected text element, if any.
|
|
37
31
|
*/
|
|
@@ -36,6 +36,8 @@ export declare const generateLinearCollisionShape: (element: ExcalidrawLinearEle
|
|
|
36
36
|
op: string;
|
|
37
37
|
data: number[];
|
|
38
38
|
}[];
|
|
39
|
+
export declare const ELBOW_ARROW_CORNER_RADIUS = 16;
|
|
40
|
+
export declare const generateElbowArrowShape: (routePoints: readonly LocalPoint[], radius: number) => string;
|
|
39
41
|
/**
|
|
40
42
|
* get the pure geometric shape of an excalidraw elementw
|
|
41
43
|
* which is then used for hit detection
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RenderEnvironment } from "./renderEnvironment";
|
|
1
2
|
import type { Scene } from "./Scene";
|
|
2
3
|
import type { VerticalResizeAnchor } from "./sizeHelpers";
|
|
3
4
|
import type { TransformHandleDirection } from "./transformHandles";
|
|
@@ -124,6 +125,12 @@ export type StickyNoteLayoutOpts = {
|
|
|
124
125
|
baseFontSize?: number;
|
|
125
126
|
/** the edge that stays put when the content correction changes the height */
|
|
126
127
|
anchor?: StickyNoteLayoutAnchor;
|
|
128
|
+
/**
|
|
129
|
+
* the host whose text metrics the fit measures with; omitted = the global
|
|
130
|
+
* environment. An editor passes its own so a note laid out in one window
|
|
131
|
+
* (or headlessly) is measured with that realm's fonts and canvas.
|
|
132
|
+
*/
|
|
133
|
+
renderEnvironment?: RenderEnvironment;
|
|
127
134
|
};
|
|
128
135
|
export type StickyNoteLayout = {
|
|
129
136
|
container: Pick<ExcalidrawStickyNoteElement, "x" | "y" | "width" | "height" | "baseHeight">;
|
|
@@ -180,4 +187,5 @@ export declare const updateStickyNoteLayout: (container: ExcalidrawStickyNoteEle
|
|
|
180
187
|
*/
|
|
181
188
|
export declare const relayoutStickyNotes: <T extends ExcalidrawElement>(elements: readonly T[], affectedIds: ReadonlySet<ExcalidrawElement["id"]>, opts?: {
|
|
182
189
|
prevElementsMap?: ElementsMap;
|
|
190
|
+
renderEnvironment?: RenderEnvironment;
|
|
183
191
|
}) => readonly T[];
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { type Radians } from "@excalidraw/math";
|
|
2
2
|
import type { ExtractSetType } from "@excalidraw/common/utility-types";
|
|
3
|
+
import type { RenderEnvironment } from "./renderEnvironment";
|
|
3
4
|
import type { Scene } from "./Scene";
|
|
4
5
|
import type { MaybeTransformHandleType } from "./transformHandles";
|
|
5
6
|
import type { ElementsMap, ExcalidrawElement, ExcalidrawElementType, ExcalidrawTextContainer, ExcalidrawTextElement, ExcalidrawTextElementWithContainer, NonDeleted } from "./types";
|
|
6
|
-
export declare const redrawTextBoundingBox: (textElement: ExcalidrawTextElement, container: ExcalidrawElement | null, scene: Scene) => void;
|
|
7
|
-
export declare const handleBindTextResize: (container: ExcalidrawElement, scene: Scene, transformHandleType: MaybeTransformHandleType, shouldMaintainAspectRatio?: boolean, shouldResizeFromCenter?: boolean, flipByY?: boolean) => void;
|
|
7
|
+
export declare const redrawTextBoundingBox: (textElement: ExcalidrawTextElement, container: ExcalidrawElement | null, scene: Scene, renderEnvironment?: RenderEnvironment) => void;
|
|
8
|
+
export declare const handleBindTextResize: (container: ExcalidrawElement, scene: Scene, transformHandleType: MaybeTransformHandleType, shouldMaintainAspectRatio?: boolean, shouldResizeFromCenter?: boolean, flipByY?: boolean, renderEnvironment?: RenderEnvironment) => void;
|
|
8
9
|
export declare const computeBoundTextPosition: (container: ExcalidrawElement, boundTextElement: ExcalidrawTextElementWithContainer, elementsMap: ElementsMap) => {
|
|
9
10
|
x: number;
|
|
10
11
|
y: number;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import type { RenderEnvironment } from "./renderEnvironment";
|
|
1
2
|
import type { FontString, ExcalidrawTextElement } from "./types";
|
|
2
|
-
export declare const measureText: (text: string, font: FontString, lineHeight: ExcalidrawTextElement["lineHeight"]) => {
|
|
3
|
+
export declare const measureText: (text: string, font: FontString, lineHeight: ExcalidrawTextElement["lineHeight"], env?: RenderEnvironment) => {
|
|
3
4
|
width: number;
|
|
4
5
|
height: number;
|
|
5
6
|
};
|
|
6
|
-
export declare const getApproxMinLineWidth: (font: FontString, lineHeight: ExcalidrawTextElement["lineHeight"]) => number;
|
|
7
|
-
export declare const getMinTextElementWidth: (font: FontString, lineHeight: ExcalidrawTextElement["lineHeight"]) => number;
|
|
7
|
+
export declare const getApproxMinLineWidth: (font: FontString, lineHeight: ExcalidrawTextElement["lineHeight"], env?: RenderEnvironment) => number;
|
|
8
|
+
export declare const getMinTextElementWidth: (font: FontString, lineHeight: ExcalidrawTextElement["lineHeight"], env?: RenderEnvironment) => number;
|
|
8
9
|
export declare const isMeasureTextSupported: () => boolean;
|
|
9
10
|
export declare const normalizeText: (text: string) => string;
|
|
10
11
|
/**
|
|
@@ -19,21 +20,24 @@ export declare const detectLineHeight: (textElement: ExcalidrawTextElement) => E
|
|
|
19
20
|
export declare const getLineHeightInPx: (fontSize: ExcalidrawTextElement["fontSize"], lineHeight: ExcalidrawTextElement["lineHeight"]) => number;
|
|
20
21
|
export declare const getApproxMinLineHeight: (fontSize: ExcalidrawTextElement["fontSize"], lineHeight: ExcalidrawTextElement["lineHeight"]) => number;
|
|
21
22
|
/**
|
|
22
|
-
* Set a custom text metrics provider
|
|
23
|
+
* Set a custom text metrics provider, for all text measured in an environment
|
|
24
|
+
* without its own (`RenderEnvironment["textMetrics"]`) -- e.g. elements
|
|
25
|
+
* created outside the editor, on a server. Pass `undefined` to go back to
|
|
26
|
+
* measuring on a canvas.
|
|
23
27
|
*
|
|
24
28
|
* Useful for overriding the width calculation algorithm where canvas API is not available / desired.
|
|
25
29
|
*/
|
|
26
|
-
export declare const setCustomTextMetricsProvider: (provider: TextMetricsProvider) => void;
|
|
30
|
+
export declare const setCustomTextMetricsProvider: (provider: TextMetricsProvider | undefined) => void;
|
|
27
31
|
export interface TextMetricsProvider {
|
|
28
32
|
getLineWidth(text: string, fontString: FontString): number;
|
|
29
33
|
}
|
|
30
|
-
export declare const getLineWidth: (text: string, font: FontString) => number;
|
|
31
|
-
export declare const getTextWidth: (text: string, font: FontString) => number;
|
|
34
|
+
export declare const getLineWidth: (text: string, font: FontString, env?: RenderEnvironment) => number;
|
|
35
|
+
export declare const getTextWidth: (text: string, font: FontString, env?: RenderEnvironment) => number;
|
|
32
36
|
export declare const getTextHeight: (text: string, fontSize: number, lineHeight: ExcalidrawTextElement["lineHeight"]) => number;
|
|
33
37
|
export declare const charWidth: {
|
|
34
|
-
calculate: (char: string, font: FontString) => number;
|
|
35
|
-
getCache: (font: FontString) => number[];
|
|
38
|
+
calculate: (char: string, font: FontString, env?: RenderEnvironment) => number;
|
|
39
|
+
getCache: (font: FontString, env?: RenderEnvironment) => number[] | undefined;
|
|
36
40
|
clearCache: (font: FontString) => void;
|
|
37
41
|
};
|
|
38
|
-
export declare const getMinCharWidth: (font: FontString) => number;
|
|
39
|
-
export declare const getMaxCharWidth: (font: FontString) => number;
|
|
42
|
+
export declare const getMinCharWidth: (font: FontString, env?: RenderEnvironment) => number;
|
|
43
|
+
export declare const getMaxCharWidth: (font: FontString, env?: RenderEnvironment) => number;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RenderEnvironment } from "./renderEnvironment";
|
|
1
2
|
import type { FontString } from "./types";
|
|
2
3
|
/**
|
|
3
4
|
* Test if a given text contains any CJK characters (including symbols, punctuation, etc,).
|
|
@@ -17,7 +18,7 @@ export declare const parseTokens: (line: string) => string[];
|
|
|
17
18
|
* This is a convenience adapter over `getWrappedTextLines()` for call sites
|
|
18
19
|
* that only need the rendered wrapped string and not the source offsets.
|
|
19
20
|
*/
|
|
20
|
-
export declare const wrapText: (text: string, font: FontString, maxWidth: number) => string;
|
|
21
|
+
export declare const wrapText: (text: string, font: FontString, maxWidth: number, env?: RenderEnvironment) => string;
|
|
21
22
|
/**
|
|
22
23
|
* A single rendered visual line produced from the original text.
|
|
23
24
|
*
|
|
@@ -36,4 +37,4 @@ export type WrappedTextLine = {
|
|
|
36
37
|
* This is the source-of-truth wrapping pipeline for callers that need more than the
|
|
37
38
|
* final wrapped string, for example caret placement or future editor/rich-text mapping.
|
|
38
39
|
*/
|
|
39
|
-
export declare const getWrappedTextLines: (text: string, font: FontString, maxWidth: number) => WrappedTextLine[];
|
|
40
|
+
export declare const getWrappedTextLines: (text: string, font: FontString, maxWidth: number, env?: RenderEnvironment) => WrappedTextLine[];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { MarkOptional } from "@excalidraw/common/utility-types";
|
|
2
2
|
import { type ElementConstructorOpts } from "./newElement";
|
|
3
|
+
import type { RenderEnvironment } from "./renderEnvironment";
|
|
3
4
|
import type { ExcalidrawBindableElement, ExcalidrawElement, ExcalidrawFrameElement, ExcalidrawFreeDrawElement, ExcalidrawGenericElement, ExcalidrawIframeLikeElement, ExcalidrawImageElement, ExcalidrawLinearElement, ExcalidrawMagicFrameElement, ExcalidrawSelectionElement, ExcalidrawTextElement, FileId, FontFamilyValues, NonDeletedExcalidrawElement, Ordered, TextAlign, VerticalAlign, ExcalidrawStickyNoteElement } from "./types";
|
|
4
5
|
/**
|
|
5
6
|
* Options for elements generated from a skeleton fragment (bound labels and
|
|
@@ -17,6 +18,8 @@ export type ValidLinearElement = {
|
|
|
17
18
|
fontFamily?: FontFamilyValues;
|
|
18
19
|
textAlign?: TextAlign;
|
|
19
20
|
verticalAlign?: VerticalAlign;
|
|
21
|
+
/** where along an arrow's path (0-1) the label is centered */
|
|
22
|
+
labelPosition?: ExcalidrawTextElement["labelPosition"];
|
|
20
23
|
} & FragmentConstructorOpts;
|
|
21
24
|
end?: (({
|
|
22
25
|
type: Exclude<ExcalidrawBindableElement["type"], "image" | "text" | "frame" | "magicframe" | "embeddable" | "iframe">;
|
|
@@ -95,6 +98,7 @@ export type ExcalidrawElementSkeleton = Extract<Exclude<ExcalidrawElement, Excal
|
|
|
95
98
|
name?: string;
|
|
96
99
|
} & Partial<ExcalidrawMagicFrameElement>);
|
|
97
100
|
export declare const convertToExcalidrawElements: (elementsSkeleton: ExcalidrawElementSkeleton[] | null, opts?: {
|
|
98
|
-
regenerateIds
|
|
101
|
+
regenerateIds?: boolean;
|
|
102
|
+
renderEnvironment?: RenderEnvironment;
|
|
99
103
|
}) => Ordered<NonDeletedExcalidrawElement>[];
|
|
100
104
|
export {};
|