@grida/svg-editor 1.0.0-alpha.13 → 1.0.0-alpha.15

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.
@@ -1,5 +1,5 @@
1
- import { c as SvgEditor } from "./editor-BH03X8cX.mjs";
2
- import { n as DomSurfaceOptions, t as DomSurfaceHandle } from "./dom-DgB4f-TE.mjs";
1
+ import { c as SvgEditor } from "./editor-Dl7c0q5A.mjs";
2
+ import { n as DomSurfaceOptions, t as DomSurfaceHandle } from "./dom-CK6GlgFF.mjs";
3
3
 
4
4
  //#region src/presets/keynote.d.ts
5
5
  declare namespace keynote_d_exports {
package/dist/presets.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { c as SvgEditor } from "./editor-Bd4-VCEJ.js";
2
- import { n as DomSurfaceOptions, t as DomSurfaceHandle } from "./dom-DCX-a8Kr.js";
1
+ import { c as SvgEditor } from "./editor-BKoo9SPL.js";
2
+ import { n as DomSurfaceOptions, t as DomSurfaceHandle } from "./dom-CsKXTaNw.js";
3
3
 
4
4
  //#region \0rolldown/runtime.js
5
5
  declare namespace keynote_d_exports {
package/dist/presets.js CHANGED
@@ -1,8 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_insertions = require("./insertions-BJ-6o6o5.js");
3
- const require_dom = require("./dom-Cvm9Towu.js");
2
+ const require_model = require("./model-CJ1Ctq14.js");
3
+ const require_dom = require("./dom-Dee6FtgZ.js");
4
4
  //#region src/presets/keynote.ts
5
- var keynote_exports = /* @__PURE__ */ require_insertions.__exportAll({ attach: () => attach });
5
+ var keynote_exports = /* @__PURE__ */ require_model.__exportAll({ attach: () => attach });
6
6
  /**
7
7
  * Attach a keynote-shaped DOM surface:
8
8
  * - Mounts via `attach_dom_surface` with `fit: true` (slide is visible on
package/dist/presets.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { t as __exportAll } from "./chunk-CfYAbeIz.mjs";
2
- import { t as attach_dom_surface } from "./dom-BlMk07oX.mjs";
1
+ import { t as __exportAll } from "./chunk-D7D4PA-g.mjs";
2
+ import { t as attach_dom_surface } from "./dom-DILY80j7.mjs";
3
3
  //#region src/presets/keynote.ts
4
4
  var keynote_exports = /* @__PURE__ */ __exportAll({ attach: () => attach });
5
5
  /**
package/dist/react.d.mts CHANGED
@@ -1,8 +1,7 @@
1
- import { B as PaintPreviewSession, E as EditorStyle, G as Providers, H as PreviewSession, I as Mode, L as NodeId, T as EditorState, X as Tool, c as SvgEditor, t as Commands } from "./editor-BH03X8cX.mjs";
2
- import { t as DomSurfaceHandle } from "./dom-DgB4f-TE.mjs";
1
+ import { A as EditorState, G as PaintPreviewSession, H as NodeId, V as Mode, X as Providers, c as SvgEditor, j as EditorStyle, q as PreviewSession, t as Commands, tt as Tool } from "./editor-Dl7c0q5A.mjs";
2
+ import { t as DomSurfaceHandle } from "./dom-CK6GlgFF.mjs";
3
3
  import cmath from "@grida/cmath";
4
4
  import { ReactNode } from "react";
5
- import * as _$react_jsx_runtime0 from "react/jsx-runtime";
6
5
 
7
6
  //#region src/react.d.ts
8
7
  type SvgEditorProviderProps = {
@@ -35,7 +34,7 @@ declare function SvgEditorProvider({
35
34
  providers,
36
35
  style,
37
36
  children
38
- }: SvgEditorProviderProps): _$react_jsx_runtime0.JSX.Element;
37
+ }: SvgEditorProviderProps): import("react/jsx-runtime").JSX.Element;
39
38
  type SvgEditorCanvasProps = {
40
39
  className?: string;
41
40
  style?: React.CSSProperties;
@@ -73,7 +72,7 @@ declare function SvgEditorCanvas({
73
72
  fit,
74
73
  initial_camera,
75
74
  onAttach
76
- }: SvgEditorCanvasProps): _$react_jsx_runtime0.JSX.Element;
75
+ }: SvgEditorCanvasProps): import("react/jsx-runtime").JSX.Element;
77
76
  declare function useSvgEditor(): SvgEditor;
78
77
  /**
79
78
  * Subscribe to a slice of `editor.state`. Re-renders when the selected slice
@@ -109,6 +108,19 @@ declare function useSelection(): readonly NodeId[];
109
108
  declare function useTool(): Tool;
110
109
  /** Current mode (`"select"` | `"edit-content"`). */
111
110
  declare function useMode(): Mode;
111
+ /**
112
+ * What kind of content-edit is active, or `null` when not in content-edit.
113
+ *
114
+ * Symmetric with `useMode()` but at a finer grain — resolves whether the
115
+ * single selected node is a path or a text node so consumers (e.g. the
116
+ * vector-edit toolbar) can render the right affordances. Mirrors the
117
+ * dispatch logic in the host's `enter_content_edit` router which checks
118
+ * `tag_of(id) === "path"` vs `"text" / "tspan"`.
119
+ *
120
+ * Returns `null` for the (defensive) case of `edit-content` with no
121
+ * selection, and for any tag that's neither path nor text.
122
+ */
123
+ declare function useContentEditKind(): "path" | "text" | null;
112
124
  /** Whether the history stack has an undoable entry. */
113
125
  declare function useCanUndo(): boolean;
114
126
  /** Whether the history stack has a redoable entry. */
@@ -131,4 +143,4 @@ declare function useEditorSerialize(): () => string;
131
143
  */
132
144
  declare function useHoverOverride(): (id: NodeId | null) => void;
133
145
  //#endregion
134
- export { SvgEditorCanvas, SvgEditorCanvasProps, SvgEditorProvider, SvgEditorProviderProps, useCameraSnapshot, useCanRedo, useCanUndo, useCommands, useEditorLoad, useEditorSerialize, useEditorState, useHoverOverride, useMode, usePaintPreview, usePropertyPreview, useSelection, useSvgEditor, useTool };
146
+ export { SvgEditorCanvas, SvgEditorCanvasProps, SvgEditorProvider, SvgEditorProviderProps, useCameraSnapshot, useCanRedo, useCanUndo, useCommands, useContentEditKind, useEditorLoad, useEditorSerialize, useEditorState, useHoverOverride, useMode, usePaintPreview, usePropertyPreview, useSelection, useSvgEditor, useTool };
package/dist/react.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- import { B as PaintPreviewSession, E as EditorStyle, G as Providers, H as PreviewSession, I as Mode, L as NodeId, T as EditorState, X as Tool, c as SvgEditor, t as Commands } from "./editor-Bd4-VCEJ.js";
2
- import { t as DomSurfaceHandle } from "./dom-DCX-a8Kr.js";
1
+ import { A as EditorState, G as PaintPreviewSession, H as NodeId, V as Mode, X as Providers, c as SvgEditor, j as EditorStyle, q as PreviewSession, t as Commands, tt as Tool } from "./editor-BKoo9SPL.js";
2
+ import { t as DomSurfaceHandle } from "./dom-CsKXTaNw.js";
3
3
  import cmath from "@grida/cmath";
4
- import * as _$react_jsx_runtime0 from "react/jsx-runtime";
5
4
  import { ReactNode } from "react";
6
5
 
7
6
  //#region src/react.d.ts
@@ -35,7 +34,7 @@ declare function SvgEditorProvider({
35
34
  providers,
36
35
  style,
37
36
  children
38
- }: SvgEditorProviderProps): _$react_jsx_runtime0.JSX.Element;
37
+ }: SvgEditorProviderProps): import("react/jsx-runtime").JSX.Element;
39
38
  type SvgEditorCanvasProps = {
40
39
  className?: string;
41
40
  style?: React.CSSProperties;
@@ -73,7 +72,7 @@ declare function SvgEditorCanvas({
73
72
  fit,
74
73
  initial_camera,
75
74
  onAttach
76
- }: SvgEditorCanvasProps): _$react_jsx_runtime0.JSX.Element;
75
+ }: SvgEditorCanvasProps): import("react/jsx-runtime").JSX.Element;
77
76
  declare function useSvgEditor(): SvgEditor;
78
77
  /**
79
78
  * Subscribe to a slice of `editor.state`. Re-renders when the selected slice
@@ -109,6 +108,19 @@ declare function useSelection(): readonly NodeId[];
109
108
  declare function useTool(): Tool;
110
109
  /** Current mode (`"select"` | `"edit-content"`). */
111
110
  declare function useMode(): Mode;
111
+ /**
112
+ * What kind of content-edit is active, or `null` when not in content-edit.
113
+ *
114
+ * Symmetric with `useMode()` but at a finer grain — resolves whether the
115
+ * single selected node is a path or a text node so consumers (e.g. the
116
+ * vector-edit toolbar) can render the right affordances. Mirrors the
117
+ * dispatch logic in the host's `enter_content_edit` router which checks
118
+ * `tag_of(id) === "path"` vs `"text" / "tspan"`.
119
+ *
120
+ * Returns `null` for the (defensive) case of `edit-content` with no
121
+ * selection, and for any tag that's neither path nor text.
122
+ */
123
+ declare function useContentEditKind(): "path" | "text" | null;
112
124
  /** Whether the history stack has an undoable entry. */
113
125
  declare function useCanUndo(): boolean;
114
126
  /** Whether the history stack has a redoable entry. */
@@ -131,4 +143,4 @@ declare function useEditorSerialize(): () => string;
131
143
  */
132
144
  declare function useHoverOverride(): (id: NodeId | null) => void;
133
145
  //#endregion
134
- export { SvgEditorCanvas, SvgEditorCanvasProps, SvgEditorProvider, SvgEditorProviderProps, useCameraSnapshot, useCanRedo, useCanUndo, useCommands, useEditorLoad, useEditorSerialize, useEditorState, useHoverOverride, useMode, usePaintPreview, usePropertyPreview, useSelection, useSvgEditor, useTool };
146
+ export { SvgEditorCanvas, SvgEditorCanvasProps, SvgEditorProvider, SvgEditorProviderProps, useCameraSnapshot, useCanRedo, useCanUndo, useCommands, useContentEditKind, useEditorLoad, useEditorSerialize, useEditorState, useHoverOverride, useMode, usePaintPreview, usePropertyPreview, useSelection, useSvgEditor, useTool };
package/dist/react.js CHANGED
@@ -1,8 +1,7 @@
1
1
  "use client";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- require("./insertions-BJ-6o6o5.js");
4
- const require_editor = require("./editor-CdyC3uAe.js");
5
- const require_dom = require("./dom-Cvm9Towu.js");
3
+ const require_editor = require("./editor-F8ckj9X1.js");
4
+ const require_dom = require("./dom-Dee6FtgZ.js");
6
5
  let react = require("react");
7
6
  let react_jsx_runtime = require("react/jsx-runtime");
8
7
  //#region src/react.tsx
@@ -137,6 +136,27 @@ function useTool() {
137
136
  function useMode() {
138
137
  return useEditorState((s) => s.mode);
139
138
  }
139
+ /**
140
+ * What kind of content-edit is active, or `null` when not in content-edit.
141
+ *
142
+ * Symmetric with `useMode()` but at a finer grain — resolves whether the
143
+ * single selected node is a path or a text node so consumers (e.g. the
144
+ * vector-edit toolbar) can render the right affordances. Mirrors the
145
+ * dispatch logic in the host's `enter_content_edit` router which checks
146
+ * `tag_of(id) === "path"` vs `"text" / "tspan"`.
147
+ *
148
+ * Returns `null` for the (defensive) case of `edit-content` with no
149
+ * selection, and for any tag that's neither path nor text.
150
+ */
151
+ function useContentEditKind() {
152
+ const editor = useSvgEditor();
153
+ const [mode, id] = useEditorState((s) => `${s.mode}::${s.selection[0] ?? ""}`, (a, b) => a === b).split("::");
154
+ if (mode !== "edit-content" || !id) return null;
155
+ const tag = editor.tree().nodes.get(id)?.tag;
156
+ if (tag === "path") return "path";
157
+ if (tag === "text" || tag === "tspan") return "text";
158
+ return null;
159
+ }
140
160
  /** Whether the history stack has an undoable entry. */
141
161
  function useCanUndo() {
142
162
  return useEditorState((s) => s.can_undo);
@@ -223,6 +243,7 @@ exports.useCameraSnapshot = useCameraSnapshot;
223
243
  exports.useCanRedo = useCanRedo;
224
244
  exports.useCanUndo = useCanUndo;
225
245
  exports.useCommands = useCommands;
246
+ exports.useContentEditKind = useContentEditKind;
226
247
  exports.useEditorLoad = useEditorLoad;
227
248
  exports.useEditorSerialize = useEditorSerialize;
228
249
  exports.useEditorState = useEditorState;
package/dist/react.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use client";
2
- import { t as createSvgEditor } from "./editor-DtuRIs-Q.mjs";
3
- import { t as attach_dom_surface } from "./dom-BlMk07oX.mjs";
2
+ import { t as createSvgEditor } from "./editor-CvWpD5mu.mjs";
3
+ import { t as attach_dom_surface } from "./dom-DILY80j7.mjs";
4
4
  import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useSyncExternalStore } from "react";
5
5
  import { jsx } from "react/jsx-runtime";
6
6
  //#region src/react.tsx
@@ -135,6 +135,27 @@ function useTool() {
135
135
  function useMode() {
136
136
  return useEditorState((s) => s.mode);
137
137
  }
138
+ /**
139
+ * What kind of content-edit is active, or `null` when not in content-edit.
140
+ *
141
+ * Symmetric with `useMode()` but at a finer grain — resolves whether the
142
+ * single selected node is a path or a text node so consumers (e.g. the
143
+ * vector-edit toolbar) can render the right affordances. Mirrors the
144
+ * dispatch logic in the host's `enter_content_edit` router which checks
145
+ * `tag_of(id) === "path"` vs `"text" / "tspan"`.
146
+ *
147
+ * Returns `null` for the (defensive) case of `edit-content` with no
148
+ * selection, and for any tag that's neither path nor text.
149
+ */
150
+ function useContentEditKind() {
151
+ const editor = useSvgEditor();
152
+ const [mode, id] = useEditorState((s) => `${s.mode}::${s.selection[0] ?? ""}`, (a, b) => a === b).split("::");
153
+ if (mode !== "edit-content" || !id) return null;
154
+ const tag = editor.tree().nodes.get(id)?.tag;
155
+ if (tag === "path") return "path";
156
+ if (tag === "text" || tag === "tspan") return "text";
157
+ return null;
158
+ }
138
159
  /** Whether the history stack has an undoable entry. */
139
160
  function useCanUndo() {
140
161
  return useEditorState((s) => s.can_undo);
@@ -215,4 +236,4 @@ function useHoverOverride() {
215
236
  }, [editor]);
216
237
  }
217
238
  //#endregion
218
- export { SvgEditorCanvas, SvgEditorProvider, useCameraSnapshot, useCanRedo, useCanUndo, useCommands, useEditorLoad, useEditorSerialize, useEditorState, useHoverOverride, useMode, usePaintPreview, usePropertyPreview, useSelection, useSvgEditor, useTool };
239
+ export { SvgEditorCanvas, SvgEditorProvider, useCameraSnapshot, useCanRedo, useCanUndo, useCommands, useContentEditKind, useEditorLoad, useEditorSerialize, useEditorState, useHoverOverride, useMode, usePaintPreview, usePropertyPreview, useSelection, useSvgEditor, useTool };
package/package.json CHANGED
@@ -1,7 +1,24 @@
1
1
  {
2
2
  "name": "@grida/svg-editor",
3
- "version": "1.0.0-alpha.13",
3
+ "version": "1.0.0-alpha.15",
4
4
  "description": "Headless SVG editor (experimental).",
5
+ "keywords": [
6
+ "bezier",
7
+ "design-tool",
8
+ "editor",
9
+ "grida",
10
+ "headless",
11
+ "path-editor",
12
+ "pen-tool",
13
+ "react",
14
+ "svg",
15
+ "svg-editor",
16
+ "typescript",
17
+ "vector",
18
+ "vector-editor",
19
+ "vector-graphics"
20
+ ],
21
+ "homepage": "https://grida.co/packages/@grida/svg-editor",
5
22
  "license": "MIT",
6
23
  "author": "Grida",
7
24
  "repository": "https://github.com/gridaco/grida",
@@ -38,17 +55,21 @@
38
55
  "tag": "alpha"
39
56
  },
40
57
  "dependencies": {
41
- "@grida/cmath": "0.2.2",
42
- "@grida/history": "0.1.0",
43
- "@grida/hud": "0.2.0",
44
- "@grida/keybinding": "0.2.0",
45
- "@grida/svg": "0.1.0",
46
- "@grida/text-editor": "0.1.1"
58
+ "@grida/cmath": "0.2.3",
59
+ "@grida/keybinding": "0.2.1",
60
+ "@grida/svg": "0.1.1",
61
+ "@grida/history": "0.1.1",
62
+ "@grida/hud": "0.2.1",
63
+ "@grida/text-editor": "0.1.2",
64
+ "@grida/vn": "0.1.0"
47
65
  },
48
66
  "devDependencies": {
49
67
  "@types/react": "^19",
68
+ "@vitest/browser": "4.0.18",
69
+ "@vitest/browser-playwright": "^4.0.18",
70
+ "playwright": "^1.58.2",
50
71
  "react": "^19",
51
- "tsdown": "^0.21.9",
72
+ "tsdown": "^0.22.1",
52
73
  "typescript": "^6",
53
74
  "vitest": "^4"
54
75
  },
@@ -65,6 +86,7 @@
65
86
  "build": "tsdown",
66
87
  "dev": "tsdown --watch",
67
88
  "test": "vitest run",
89
+ "test:browser": "vitest run --config vitest.browser.config.ts",
68
90
  "test:watch": "vitest",
69
91
  "typecheck": "tsc --noEmit"
70
92
  }
@@ -1,57 +0,0 @@
1
- import { c as SvgEditor, p as Gestures, s as SurfaceHandle, y as Camera } from "./editor-Bd4-VCEJ.js";
2
- import cmath from "@grida/cmath";
3
- //#region src/core/snap/options.d.ts
4
- type SnapOptions = {
5
- /** When false, snap behavior and snap-guide rendering are both off. */enabled: boolean;
6
- /** Snap threshold in HUD canvas pixels (container CSS px in svg-editor;
7
- * whatever space the consumer feeds in). Constant across zoom because
8
- * the input rects are already in screen-equivalent units. */
9
- threshold_px: number;
10
- };
11
- declare const DEFAULT_SNAP_OPTIONS: SnapOptions;
12
- //#endregion
13
- //#region src/dom.d.ts
14
- type DomSurfaceOptions = {
15
- /** Mount the SVG inside this container. */container: HTMLElement;
16
- /**
17
- * Install the default gesture set (wheel-pan/zoom, space-drag, middle-mouse,
18
- * keyboard zoom). Default `true`. Pass `false` to start blank and bind à la
19
- * carte via `handle.gestures.bind(...)`.
20
- */
21
- gestures?: boolean;
22
- /**
23
- * Auto-fit the document into the viewport on initial attach. Default
24
- * `false`. Mirrors Excalidraw's `initialData.scrollToContent`.
25
- * Subsequent `editor.load()` calls do NOT re-fit — call
26
- * `handle.camera.fit("<root>")` yourself if you want that behavior.
27
- */
28
- fit?: boolean;
29
- /**
30
- * Initial camera transform. Default `cmath.transform.identity`. Ignored
31
- * when `fit: true`.
32
- */
33
- initial_camera?: cmath.Transform;
34
- };
35
- /**
36
- * Surface handle for the DOM surface. Extends the editor's core
37
- * `SurfaceHandle` with the viewport-scoped concerns: pan/zoom (`camera`)
38
- * and pointer/wheel/keyboard gesture bindings (`gestures`).
39
- *
40
- * Camera + gestures are **surface-scoped**: detaching the surface drops
41
- * both. They never appear on the headless `SvgEditor`.
42
- */
43
- type DomSurfaceHandle = SurfaceHandle & {
44
- camera: Camera;
45
- gestures: Gestures;
46
- };
47
- /**
48
- * Attach a DOM surface to a headless editor. Returns a `DomSurfaceHandle`
49
- * whose `detach()` is the inverse — DOM cleared, listeners removed,
50
- * gestures uninstalled.
51
- *
52
- * Usage is one-shot per container: the surface owns the container's children
53
- * for its lifetime, and `detach()` restores it to empty.
54
- */
55
- declare function attach_dom_surface(editor: SvgEditor, options: DomSurfaceOptions): DomSurfaceHandle;
56
- //#endregion
57
- export { SnapOptions as a, DEFAULT_SNAP_OPTIONS as i, DomSurfaceOptions as n, attach_dom_surface as r, DomSurfaceHandle as t };
@@ -1,59 +0,0 @@
1
- import { c as SvgEditor, p as Gestures, s as SurfaceHandle, y as Camera } from "./editor-BH03X8cX.mjs";
2
- import cmath from "@grida/cmath";
3
- import { guide } from "@grida/cmath/_snap";
4
-
5
- //#region src/core/snap/options.d.ts
6
- type SnapOptions = {
7
- /** When false, snap behavior and snap-guide rendering are both off. */enabled: boolean;
8
- /** Snap threshold in HUD canvas pixels (container CSS px in svg-editor;
9
- * whatever space the consumer feeds in). Constant across zoom because
10
- * the input rects are already in screen-equivalent units. */
11
- threshold_px: number;
12
- };
13
- declare const DEFAULT_SNAP_OPTIONS: SnapOptions;
14
- //#endregion
15
- //#region src/dom.d.ts
16
- type DomSurfaceOptions = {
17
- /** Mount the SVG inside this container. */container: HTMLElement;
18
- /**
19
- * Install the default gesture set (wheel-pan/zoom, space-drag, middle-mouse,
20
- * keyboard zoom). Default `true`. Pass `false` to start blank and bind à la
21
- * carte via `handle.gestures.bind(...)`.
22
- */
23
- gestures?: boolean;
24
- /**
25
- * Auto-fit the document into the viewport on initial attach. Default
26
- * `false`. Mirrors Excalidraw's `initialData.scrollToContent`.
27
- * Subsequent `editor.load()` calls do NOT re-fit — call
28
- * `handle.camera.fit("<root>")` yourself if you want that behavior.
29
- */
30
- fit?: boolean;
31
- /**
32
- * Initial camera transform. Default `cmath.transform.identity`. Ignored
33
- * when `fit: true`.
34
- */
35
- initial_camera?: cmath.Transform;
36
- };
37
- /**
38
- * Surface handle for the DOM surface. Extends the editor's core
39
- * `SurfaceHandle` with the viewport-scoped concerns: pan/zoom (`camera`)
40
- * and pointer/wheel/keyboard gesture bindings (`gestures`).
41
- *
42
- * Camera + gestures are **surface-scoped**: detaching the surface drops
43
- * both. They never appear on the headless `SvgEditor`.
44
- */
45
- type DomSurfaceHandle = SurfaceHandle & {
46
- camera: Camera;
47
- gestures: Gestures;
48
- };
49
- /**
50
- * Attach a DOM surface to a headless editor. Returns a `DomSurfaceHandle`
51
- * whose `detach()` is the inverse — DOM cleared, listeners removed,
52
- * gestures uninstalled.
53
- *
54
- * Usage is one-shot per container: the surface owns the container's children
55
- * for its lifetime, and `detach()` restores it to empty.
56
- */
57
- declare function attach_dom_surface(editor: SvgEditor, options: DomSurfaceOptions): DomSurfaceHandle;
58
- //#endregion
59
- export { SnapOptions as a, DEFAULT_SNAP_OPTIONS as i, DomSurfaceOptions as n, attach_dom_surface as r, DomSurfaceHandle as t };