@grida/svg-editor 1.0.0-alpha.4 → 1.0.0

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.
Files changed (41) hide show
  1. package/README.md +365 -384
  2. package/dist/dom-BEjG2bSw.d.mts +320 -0
  3. package/dist/dom-DYD1BHTo.js +6050 -0
  4. package/dist/dom-Y2QR7QSi.d.ts +318 -0
  5. package/dist/dom-tM3Dr1EK.mjs +5971 -0
  6. package/dist/dom.d.mts +3 -2
  7. package/dist/dom.d.ts +3 -2
  8. package/dist/dom.js +13 -1
  9. package/dist/dom.mjs +2 -2
  10. package/dist/editor-CWNtt1vu.mjs +2998 -0
  11. package/dist/editor-CZgwg8BK.d.mts +2537 -0
  12. package/dist/editor-CesShk9o.js +3004 -0
  13. package/dist/editor-kFTYSb_8.d.ts +2537 -0
  14. package/dist/index.d.mts +2 -2
  15. package/dist/index.d.ts +2 -2
  16. package/dist/index.js +5 -2
  17. package/dist/index.mjs +3 -2
  18. package/dist/model-D0iEDcg3.mjs +5451 -0
  19. package/dist/model-tywvTGZv.js +5640 -0
  20. package/dist/presets.d.mts +17 -2
  21. package/dist/presets.d.ts +17 -2
  22. package/dist/presets.js +20 -15
  23. package/dist/presets.mjs +19 -15
  24. package/dist/react.d.mts +88 -10
  25. package/dist/react.d.ts +88 -10
  26. package/dist/react.js +169 -14
  27. package/dist/react.mjs +159 -16
  28. package/package.json +35 -9
  29. package/dist/dom-CmOu0HvI.mjs +0 -1623
  30. package/dist/dom-Cn-RtjRL.d.ts +0 -48
  31. package/dist/dom-CoVZzFqy.js +0 -1672
  32. package/dist/dom-DJnZhtOd.d.mts +0 -48
  33. package/dist/editor-CjK56cgb.mjs +0 -1823
  34. package/dist/editor-D2l_CDr0.d.ts +0 -818
  35. package/dist/editor-D2zZAyny.js +0 -1835
  36. package/dist/editor-Uu6dZX4y.d.mts +0 -818
  37. package/dist/index-CHiXYO9-.d.ts +0 -1
  38. package/dist/index-ThDLM4Am.d.mts +0 -1
  39. package/dist/paint-Cfiw4g_J.mjs +0 -477
  40. package/dist/paint-dDV-Trt9.js +0 -531
  41. /package/dist/{chunk-CfYAbeIz.mjs → chunk-D7D4PA-g.mjs} +0 -0
@@ -1,818 +0,0 @@
1
- import * as _$_grida_history0 from "@grida/history";
2
- import { Keybinding, Platform } from "@grida/keybinding";
3
- import cmath from "@grida/cmath";
4
-
5
- //#region src/types.d.ts
6
- /**
7
- * Stable identifier for a node in the editor's document model.
8
- *
9
- * Independent of any backing representation. Generated when the document is
10
- * parsed.
11
- */
12
- type NodeId = string;
13
- type Vec2 = {
14
- x: number;
15
- y: number;
16
- };
17
- type Rect = {
18
- x: number;
19
- y: number;
20
- width: number;
21
- height: number;
22
- };
23
- type Mode = "select" | "edit-content";
24
- type Provenance = {
25
- /** CSS cascade origin (css-cascade-5 §6.2). */origin: "author" | "user_agent"; /** Editor metadata — where in the file the winning declaration lives. */
26
- carrier: "presentation_attribute" | "inline_style" | "stylesheet" | "inherited" | "defaulted";
27
- };
28
- type InvalidComputedValue = {
29
- error: "invalid_at_computed_value_time";
30
- reason: string;
31
- };
32
- type PropertyValue<T = string | number> = {
33
- declared: string | null;
34
- computed: T | InvalidComputedValue | null;
35
- provenance: Provenance;
36
- };
37
- type Color = {
38
- kind: "rgb";
39
- value: string;
40
- } | {
41
- kind: "current_color";
42
- };
43
- type PaintFallback = {
44
- kind: "none";
45
- } | {
46
- kind: "color";
47
- value: Color;
48
- };
49
- type Paint = {
50
- kind: "none";
51
- } | {
52
- kind: "color";
53
- value: Color;
54
- } | {
55
- kind: "ref";
56
- id: string;
57
- fallback?: PaintFallback;
58
- } | {
59
- kind: "context_fill";
60
- } | {
61
- kind: "context_stroke";
62
- };
63
- type PaintValue = {
64
- declared: string | null;
65
- computed: Paint | InvalidComputedValue | null;
66
- provenance: Provenance;
67
- };
68
- type GradientStop = {
69
- offset: number;
70
- color: string;
71
- opacity?: number;
72
- };
73
- type LinearGradientDefinition = {
74
- kind: "linear";
75
- stops: GradientStop[];
76
- x1?: number;
77
- y1?: number;
78
- x2?: number;
79
- y2?: number;
80
- gradient_units?: "user_space_on_use" | "object_bounding_box";
81
- spread_method?: "pad" | "reflect" | "repeat";
82
- };
83
- type RadialGradientDefinition = {
84
- kind: "radial";
85
- stops: GradientStop[];
86
- cx?: number;
87
- cy?: number;
88
- r?: number;
89
- fx?: number;
90
- fy?: number;
91
- gradient_units?: "user_space_on_use" | "object_bounding_box";
92
- spread_method?: "pad" | "reflect" | "repeat";
93
- };
94
- type GradientDefinition = LinearGradientDefinition | RadialGradientDefinition;
95
- type GradientEntry = {
96
- id: string;
97
- definition: GradientDefinition;
98
- ref_count: number;
99
- };
100
- type EditorStyle = {
101
- chrome_color: string;
102
- handle_size: number;
103
- handle_fill: string;
104
- handle_stroke: string;
105
- endpoint_dot_radius: number;
106
- selection_outline_width: number;
107
- /**
108
- * Color for measurement guides (distance lines + numeric pills). Distinct
109
- * from `chrome_color` so the user can tell at a glance whether something
110
- * is selection chrome or a measurement readout.
111
- */
112
- measurement_color: string;
113
- };
114
- declare const DEFAULT_STYLE: EditorStyle;
115
- type ClipboardProvider = {
116
- read(): Promise<string | null>;
117
- write(text: string): Promise<void>;
118
- };
119
- type FontResolver = {
120
- resolve(family: string): Promise<{
121
- available: boolean;
122
- metrics?: {
123
- ascent: number;
124
- descent: number;
125
- unitsPerEm: number;
126
- };
127
- }>;
128
- };
129
- type FileIOProvider = {
130
- openSvg(): Promise<string | null>;
131
- saveSvg(svg: string, suggestedName?: string): Promise<void>;
132
- };
133
- type Providers = {
134
- clipboard?: ClipboardProvider;
135
- fonts?: FontResolver;
136
- file_io?: FileIOProvider;
137
- };
138
- type EditorState = {
139
- readonly selection: ReadonlyArray<NodeId>;
140
- readonly scope: NodeId | null;
141
- readonly mode: Mode;
142
- readonly dirty: boolean;
143
- readonly can_undo: boolean;
144
- readonly can_redo: boolean;
145
- /**
146
- * Bumps on every editor emission. Use this when you need to react to
147
- * any change — selection, history, mutation. NOT a good cache key for
148
- * tree-shape views because it fires on attribute writes too (e.g. x/y
149
- * during a drag).
150
- */
151
- readonly version: number;
152
- /**
153
- * Bumps only when the document's tree shape or display-label-affecting
154
- * data changes — node added/removed/reordered, text content, or the
155
- * `id` attribute. Stable across pure presentation-attribute writes.
156
- *
157
- * The right cache key for hierarchy / layers panels: snapshot once per
158
- * `structure_version` so a drag doesn't invalidate the tree view.
159
- */
160
- readonly structure_version: number;
161
- /**
162
- * Bumps once per `editor.load(svg)` call. Distinct from
163
- * `structure_version` (which bumps on edits too). Starts at 0; the
164
- * constructor's initial SVG does NOT count as a load. Use this when
165
- * you want to react to "a new document was loaded" — e.g. refit
166
- * camera to the new root, reset host-side UI state, clear per-file
167
- * scratch — without firing on text edits, reorders, or deletes.
168
- *
169
- * Monotonic, never resets.
170
- */
171
- readonly load_version: number;
172
- };
173
- type Unsubscribe = () => void;
174
- type ReorderDirection = "bring_forward" | "send_backward" | "bring_to_front" | "send_to_back";
175
- type PreviewSession = {
176
- update(value: string): void;
177
- commit(): void;
178
- discard(): void;
179
- };
180
- type PaintPreviewSession = {
181
- update(paint: Paint): void;
182
- commit(): void;
183
- discard(): void;
184
- };
185
- //#endregion
186
- //#region src/core/camera.d.ts
187
- /**
188
- * Returns world-space bounds for the given target, or `null` when
189
- * unresolvable (e.g. empty selection, unknown node id). Implemented by the
190
- * surface — the camera itself has no view into the document.
191
- *
192
- * Only string targets are passed to the resolver — `Rect` targets are
193
- * handled by the camera as identity (the rect IS its own bounds).
194
- */
195
- type BoundsResolver = (target: "<root>" | "<selection>" | NodeId) => Rect | null;
196
- type CameraOptions = {
197
- resolve_bounds: BoundsResolver;
198
- initial?: cmath.Transform;
199
- };
200
- /**
201
- * Camera viewport constraint. Discriminated union with `type` so future
202
- * variants (`'contain'`, `'pan-region'`) can be added without breaking
203
- * existing call sites — each future variant has its own payload shape.
204
- *
205
- * v1.1 ships only `'cover'`. CSS analogy: `object-fit: cover` — the
206
- * bounds rect covers the viewport edge-to-edge. Zoom is lower-bounded
207
- * at fit-with-padding; pan is clamped so the bounds always covers the
208
- * viewport. Use for slide / page / kiosk UX where the user should
209
- * never see past the artwork.
210
- */
211
- type CameraConstraints = {
212
- /** Bounds cover viewport (viewport ⊆ bounds). Keynote / slide UX. */type: "cover"; /** World-space rect, or `"<root>"` to resolve via BoundsResolver. */
213
- bounds: Rect | "<root>"; /** Screen-pixel breathing room between bounds and viewport edge. */
214
- padding?: number;
215
- };
216
- /**
217
- * Surface-scoped pan/zoom state.
218
- *
219
- * The public shape leads with the peer convention (`center` / `zoom` /
220
- * `bounds`) and keeps the matrix as an advanced read. Methods mirror
221
- * Figma/Penpot where they overlap.
222
- */
223
- declare class Camera {
224
- private _transform;
225
- private viewport_w;
226
- private viewport_h;
227
- private listeners;
228
- private resolve_bounds;
229
- private _constraints;
230
- constructor(opts: CameraOptions);
231
- /**
232
- * Current viewport constraint, or `null` for free pan/zoom. Set with
233
- * `camera.constraints = { type: 'cover', bounds: '<root>', padding: 80 }`
234
- * to clamp zoom + pan; assign `null` to clear.
235
- *
236
- * Constraints are applied synchronously inside `set_transform` (and
237
- * `_set_viewport_size`), so every public mutation respects them
238
- * automatically — the host never needs to subscribe-and-clamp itself.
239
- */
240
- get constraints(): CameraConstraints | null;
241
- set constraints(c: CameraConstraints | null);
242
- /** Underlying 2D affine. World→screen. */
243
- get transform(): cmath.Transform;
244
- /** Uniform scale factor. 1 = 100 %. */
245
- get zoom(): number;
246
- /** World-space point currently at viewport center. */
247
- get center(): Vec2;
248
- /** World-space rectangle visible in the viewport. */
249
- get bounds(): Rect;
250
- /** Translate the camera by a screen-space delta. */
251
- pan(delta_screen: Vec2): void;
252
- /**
253
- * Multiply zoom by `factor` keeping `origin_screen` fixed in world space.
254
- * Used by wheel-zoom-at-cursor and pinch-zoom.
255
- */
256
- zoom_at(factor: number, origin_screen: Vec2): void;
257
- /** Pan so `c` lands at the viewport center. Zoom unchanged. */
258
- set_center(c: Vec2): void;
259
- /** Set zoom directly; pivot defaults to viewport center. */
260
- set_zoom(z: number, pivot_screen?: Vec2): void;
261
- /**
262
- * Replace the entire transform.
263
- *
264
- * Idempotent: when the new transform is element-wise equal to the current
265
- * one, this is a no-op (no notification fires). This is the seam that
266
- * makes external constraint loops (e.g. "subscribe → compute clamped →
267
- * set_transform") terminate: the clamp re-emits the same transform on
268
- * the second pass, set_transform short-circuits, no recursion.
269
- *
270
- * When `camera.constraints` is non-null, the input transform is clamped
271
- * synchronously before being stored — every public mutation respects the
272
- * constraint automatically.
273
- */
274
- set_transform(t: cmath.Transform): void;
275
- /** Viewport size in screen pixels. Read by host code computing constraints. */
276
- get viewport_size(): {
277
- width: number;
278
- height: number;
279
- };
280
- /**
281
- * Fit a target into the viewport.
282
- *
283
- * - `"<root>"` — the document root's content bounds (host-resolved).
284
- * - `"<selection>"` — current editor.state.selection's union bounds.
285
- * - `NodeId` — that node's content bounds.
286
- * - `Rect` — an explicit world-space rectangle.
287
- *
288
- * No-ops if the target resolves to `null` (e.g. empty selection) or if
289
- * the viewport size is 0 (no container).
290
- */
291
- fit(target: "<root>" | "<selection>" | NodeId | Rect, opts?: {
292
- margin?: number;
293
- }): void;
294
- /** Snap back to identity. */
295
- reset(): void;
296
- /**
297
- * Subscribe to camera changes. Fires on every mutation. Cheap channel —
298
- * does NOT bump `editor.state.version`. Same pattern as
299
- * `editor.subscribe_surface_hover`.
300
- */
301
- subscribe(cb: () => void): Unsubscribe;
302
- /** @internal Surface drives this on container resize. */
303
- _set_viewport_size(w: number, h: number): void;
304
- /** Convert a screen-space point to world-space. */
305
- screen_to_world(p: Vec2): Vec2;
306
- /** Convert a world-space point to screen-space. */
307
- world_to_screen(p: Vec2): Vec2;
308
- /**
309
- * Apply the current constraint (if any) to a candidate transform.
310
- * Pure: returns the clamped result, never mutates state. Returns the
311
- * input unchanged when constraints are null / bounds are unresolvable /
312
- * viewport is 0.
313
- */
314
- private apply_constraints;
315
- /**
316
- * Re-clamp the stored transform against the current constraint. Called
317
- * from the `constraints` setter; `_set_viewport_size` has its own
318
- * notify-inclusive path.
319
- */
320
- private reenforce;
321
- private notify;
322
- }
323
- //#endregion
324
- //#region src/commands/registry.d.ts
325
- /**
326
- * Command registry.
327
- *
328
- * A passive id-keyed registry of handlers. Built so that:
329
- *
330
- * - keybindings (in `src/keymap`) can address commands by stable id;
331
- * - new commands can be added in ONE place (`src/commands/defaults.ts`)
332
- * without growing the public surface of the editor;
333
- * - "one key, many meanings" can be expressed via chain semantics: a
334
- * handler returns `true` if it consumed, `false`/`void` otherwise,
335
- * and the dispatcher tries the next candidate in the chain.
336
- *
337
- * Handlers are plain closures — they capture whatever editor reference
338
- * they need. The registry itself stays unaware of the editor's type,
339
- * which avoids a circular type dependency between editor and registry.
340
- */
341
- /** Stable, dotted id for a command, e.g. `"history.undo"`. */
342
- type CommandId = string;
343
- /**
344
- * A command handler.
345
- *
346
- * Return `true` if the handler consumed the invocation. Return `false`
347
- * or `undefined` to signal "did not apply" — the dispatcher will try
348
- * the next candidate registered for the same key.
349
- *
350
- * Handlers are closures: they capture their editor reference. No
351
- * editor parameter is passed — keep handlers self-contained.
352
- */
353
- type CommandHandler = (args?: unknown) => boolean | void;
354
- declare class CommandRegistry {
355
- private readonly map;
356
- /**
357
- * Register a command. Returns an unregister function. Re-registering
358
- * the same id replaces the previous handler (last writer wins).
359
- */
360
- register(id: CommandId, handler: CommandHandler): () => void;
361
- /**
362
- * Invoke a command by id. Returns `true` if the handler consumed,
363
- * `false` otherwise (including unknown ids and handlers that returned
364
- * `false`/`undefined`).
365
- */
366
- invoke(id: CommandId, args?: unknown): boolean;
367
- has(id: CommandId): boolean;
368
- /** All registered ids, for debugging / introspection. */
369
- ids(): readonly CommandId[];
370
- }
371
- //#endregion
372
- //#region src/keymap/keymap.d.ts
373
- type KeymapBinding = {
374
- /** Declarative key combination. Build with `kb()` / `c()` / `seq()`. */keybinding: Keybinding; /** Command id to invoke on match. */
375
- command: CommandId; /** Forwarded as the `args` parameter to the command handler. */
376
- args?: unknown; /** Higher priorities run first in the chain. Default 0. */
377
- priority?: number;
378
- /**
379
- * Reserved for V2; not honored by the V1 dispatcher. When added, this
380
- * will be evaluated before the handler runs; if false, the binding is
381
- * skipped without invoking the handler.
382
- */
383
- when?: (ctx: unknown) => boolean;
384
- };
385
- declare class Keymap {
386
- private readonly commands;
387
- private readonly platformGetter;
388
- /**
389
- * Bindings bucketed by canonical chunk-key hash, computed per
390
- * `@grida/keybinding`'s `chunkKey`. Each list is the chain for that
391
- * key, sorted in dispatch order (priority desc, then registration
392
- * order).
393
- */
394
- private readonly buckets;
395
- /** Insert order, so ties on priority are deterministic. */
396
- private seq;
397
- constructor(commands: CommandRegistry, platformGetter?: () => Platform);
398
- /**
399
- * Bind a key combination to a command. Returns an unbind function.
400
- * The same `Keybinding` can be bound to multiple commands — they will
401
- * all be tried in chain order on dispatch.
402
- */
403
- bind(binding: KeymapBinding): () => void;
404
- /**
405
- * Remove bindings matching the spec. If both filters are passed, only
406
- * bindings that match BOTH are removed.
407
- */
408
- unbind(spec: {
409
- keybinding?: Keybinding;
410
- command?: CommandId;
411
- }): void;
412
- /** All registered bindings, for introspection. Order is not guaranteed. */
413
- bindings(): readonly KeymapBinding[];
414
- /**
415
- * Match the event against bound chunks, then run candidates in chain
416
- * order. Returns `true` and calls `preventDefault()` on the first
417
- * handler that consumes; returns `false` if nothing matched or all
418
- * matches fell through.
419
- */
420
- dispatch(event: KeyboardEvent): boolean;
421
- /**
422
- * Compute the set of canonical hashes a `Keybinding` lights up. A
423
- * binding with aliases (multiple sequences) contributes one hash per
424
- * single-chunk alias; multi-chunk sequences (chords) are skipped in
425
- * V1.
426
- */
427
- private chunkKeysFor;
428
- private has_safe_mod;
429
- }
430
- //#endregion
431
- //#region src/core/parser.d.ts
432
- type AttrToken = {
433
- /** Verbatim source name including any prefix, e.g. "xlink:href". */raw_name: string; /** Prefix or null. */
434
- prefix: string | null; /** Local name. */
435
- local: string; /** Resolved namespace URI, or null if unprefixed and no default ns. */
436
- ns: string | null; /** Raw attribute value string (entity-decoded). */
437
- value: string; /** Trivia before the attribute name (whitespace, usually `" "`). */
438
- pre: string; /** Trivia between `=` and the value (usually empty). */
439
- eq_trivia: string; /** Quote character (`"` or `'`). */
440
- quote: '"' | "'";
441
- };
442
- type ElementNode = {
443
- kind: "element";
444
- id: NodeId;
445
- parent: NodeId | null; /** Verbatim tag name with prefix. */
446
- raw_tag: string;
447
- prefix: string | null;
448
- local: string;
449
- ns: string | null;
450
- attrs: AttrToken[];
451
- children: NodeId[]; /** True if the source wrote `<tag/>` (no children). */
452
- self_closing: boolean; /** Trivia inside the tag before `>` or `/>` (e.g. `" "` in `<tag />`). */
453
- open_tag_trailing: string; /** Trivia between `</` and tag name in the close, e.g. usually empty. */
454
- close_tag_leading: string; /** Trivia after the closing tag name before `>`, usually empty. */
455
- close_tag_trailing: string;
456
- };
457
- type TextNode = {
458
- kind: "text";
459
- id: NodeId;
460
- parent: NodeId | null; /** Verbatim text, entity-decoded. */
461
- value: string;
462
- };
463
- type CommentNode = {
464
- kind: "comment";
465
- id: NodeId;
466
- parent: NodeId | null; /** Comment body (between `<!--` and `-->`). */
467
- value: string;
468
- };
469
- type CDataNode = {
470
- kind: "cdata";
471
- id: NodeId;
472
- parent: NodeId | null;
473
- value: string;
474
- };
475
- type PiNode = {
476
- kind: "pi";
477
- id: NodeId;
478
- parent: NodeId | null; /** PI target, e.g. "xml" for `<?xml ... ?>`. */
479
- target: string;
480
- value: string;
481
- };
482
- type DoctypeNode = {
483
- kind: "doctype";
484
- id: NodeId;
485
- parent: NodeId | null; /** Full doctype declaration body, e.g. `svg PUBLIC "..." "..."`. */
486
- value: string;
487
- };
488
- type AnyNode = ElementNode | TextNode | CommentNode | CDataNode | PiNode | DoctypeNode;
489
- //#endregion
490
- //#region src/core/document.d.ts
491
- interface DocumentEvents {
492
- /** Fires after any structural mutation. */
493
- on_change(fn: () => void): () => void;
494
- }
495
- declare class SvgDocument implements DocumentEvents {
496
- private nodes;
497
- private prolog;
498
- private epilog;
499
- /** Snapshot of the input string, used for `reset()`. */
500
- private source;
501
- /** Original parse result, for `reset()`. */
502
- private original;
503
- readonly root: NodeId;
504
- private listeners;
505
- /**
506
- * Counter that bumps ONLY when something the hierarchy view cares about
507
- * changes — tree topology (`insert`/`remove`), text-node content
508
- * (`set_text`), or the `id` attribute (which feeds display labels). Pure
509
- * presentation-attribute writes (x, y, fill, …) do NOT bump it.
510
- *
511
- * Why a separate counter: consumers like the layers panel cache snapshots
512
- * keyed on this. During a drag, x/y writes fire `emit()` repeatedly but
513
- * `structure_version` stays stable, so the panel's snapshot reference
514
- * stays the same and React skips the re-render of the whole tree.
515
- */
516
- private _structure_version;
517
- constructor(svg: string);
518
- static parse(svg: string): SvgDocument;
519
- /** Reload from the original parse, discarding all edits. */
520
- reset_to_original(): void;
521
- /** Replace document with new svg source (clears edits + history-owned state). */
522
- load(svg: string): void;
523
- on_change(fn: () => void): () => void;
524
- /** See `_structure_version` for what this counter signals. */
525
- get structure_version(): number;
526
- private emit;
527
- /** Notify subscribers — for callers that mutate directly via setAttr/etc. */
528
- notify(): void;
529
- get(id: NodeId): AnyNode | null;
530
- is_element(id: NodeId): boolean;
531
- parent_of(id: NodeId): NodeId | null;
532
- children_of(id: NodeId): readonly NodeId[];
533
- /** Element children only — text/comment/cdata filtered out. */
534
- element_children_of(id: NodeId): readonly NodeId[];
535
- next_sibling_of(id: NodeId): NodeId | null;
536
- next_element_sibling_of(id: NodeId): NodeId | null;
537
- tag_of(id: NodeId): string;
538
- contains(ancestor: NodeId, descendant: NodeId): boolean;
539
- all_nodes(): readonly NodeId[];
540
- all_elements(): readonly NodeId[];
541
- find_by_tag(ancestor: NodeId, tag: string): readonly NodeId[];
542
- /** Read attribute by local name, optionally namespace-filtered. */
543
- get_attr(id: NodeId, name: string, ns?: string | null): string | null;
544
- /**
545
- * Set / remove an attribute. If the attribute exists, it is mutated in place
546
- * (preserving source position). If it doesn't, it's appended.
547
- */
548
- set_attr(id: NodeId, name: string, value: string | null, ns?: string | null): void;
549
- attributes_of(id: NodeId): {
550
- name: string;
551
- ns: string | null;
552
- value: string;
553
- }[];
554
- get_style(id: NodeId, property: string): string | null;
555
- set_style(id: NodeId, property: string, value: string | null): void;
556
- get_all_styles(id: NodeId): Array<{
557
- property: string;
558
- value: string;
559
- }>;
560
- text_of(id: NodeId): string;
561
- /** Replace all direct text children with a single text node carrying `value`. */
562
- set_text(id: NodeId, value: string): void;
563
- insert(id: NodeId, parent: NodeId, before: NodeId | null): void;
564
- remove(id: NodeId): void;
565
- /** Create a new element node and register it (not yet inserted). */
566
- create_element(local: string, opts?: {
567
- prefix?: string | null;
568
- ns?: string | null;
569
- }): NodeId;
570
- serialize(): string;
571
- private emit_node;
572
- private emit_attr;
573
- }
574
- //#endregion
575
- //#region src/core/defs.d.ts
576
- interface GradientsApi {
577
- list(): ReadonlyArray<GradientEntry>;
578
- get(id: string): GradientEntry | null;
579
- upsert(definition: GradientDefinition, opts?: {
580
- id?: string;
581
- }): string;
582
- remove(id: string): void;
583
- subscribe(fn: (entries: ReadonlyArray<GradientEntry>) => void): Unsubscribe;
584
- }
585
- type Defs = {
586
- gradients: GradientsApi;
587
- };
588
- //#endregion
589
- //#region src/core/properties.d.ts
590
- declare function read_property(doc: SvgDocument, id: NodeId, property: string): PropertyValue;
591
- //#endregion
592
- //#region src/gestures/gestures.d.ts
593
- /** Stable identifier for a gesture binding. Used by `unbind({ id })`. */
594
- type GestureId = string;
595
- /**
596
- * Context passed to every installer. Exposes the seams a gesture needs:
597
- * the container element to listen on, the camera to mutate, and the
598
- * editor for keymap dispatch / state reads.
599
- *
600
- * Surface authors construct this once at attach; bindings receive it on
601
- * every `install(...)` call.
602
- */
603
- type GestureContext = {
604
- /** Container element listeners attach to. */container: HTMLElement; /** SVG element being framed by the camera. Useful for hit-testing. */
605
- svg_root: () => SVGSVGElement | null; /** HUD canvas overlay; sits on top of the SVG. */
606
- hud_canvas: HTMLCanvasElement; /** Camera the binding mutates. */
607
- camera: Camera; /** Editor for keymap dispatch / state reads. */
608
- editor: SvgEditor; /** Handle for advanced bindings (e.g. wanting `camera.fit("<selection>")`). */
609
- handle: SurfaceHandle;
610
- };
611
- type GestureBinding = {
612
- /** Stable id used by `unbind` / `bindings()`. */id: GestureId;
613
- /**
614
- * Wire DOM listeners (or any side-effect) needed for this gesture.
615
- * Returns the uninstaller — called on `unbind` or surface detach.
616
- */
617
- install(ctx: GestureContext): () => void;
618
- };
619
- /**
620
- * Sibling to `Keymap`. Owns a list of installed gesture bindings; each
621
- * binding's `install(ctx)` is called eagerly when bound and uninstalled
622
- * on `unbind` or surface detach.
623
- */
624
- declare class Gestures {
625
- private readonly ctx;
626
- private entries;
627
- constructor(ctx: GestureContext);
628
- /**
629
- * Install a gesture binding. Returns an unbind function.
630
- * Re-binding the same `id` does NOT replace — both will be active.
631
- * Use `unbind({ id })` first if you want a clean swap.
632
- */
633
- bind(binding: GestureBinding): () => void;
634
- /**
635
- * Remove bindings matching the spec. With `{ id }`, all bindings with
636
- * that id are uninstalled. With no spec, this is a no-op (use
637
- * `dispose()` to nuke everything).
638
- */
639
- unbind(spec: {
640
- id?: GestureId;
641
- }): void;
642
- /** All currently installed bindings. Order is registration order. */
643
- bindings(): readonly GestureBinding[];
644
- /** @internal Uninstall every binding. Surface calls on detach. */
645
- _dispose(): void;
646
- }
647
- //#endregion
648
- //#region src/core/editor.d.ts
649
- /** Resolved paint from the DOM-attached cascade. `resolved_paint` mirrors the
650
- * shape of `PaintValue.computed` so consumers can treat it uniformly with
651
- * the headless cascade. */
652
- type DomComputedPaint = {
653
- computed: string;
654
- resolved_paint: Paint | InvalidComputedValue | null;
655
- };
656
- /** Contract the DOM surface implements to delegate cascade resolution to
657
- * `getComputedStyle()`. Registered via `editor._internal.set_computed_resolver`
658
- * on attach. */
659
- type DomComputedResolver = {
660
- computed_property(id: NodeId, name: string): string | null;
661
- computed_paint(id: NodeId, channel: "fill" | "stroke"): DomComputedPaint | null;
662
- };
663
- type CreateSvgEditorOptions = {
664
- svg: string;
665
- providers?: Providers;
666
- style?: Partial<EditorStyle>;
667
- };
668
- type SvgEditor = ReturnType<typeof createSvgEditor>;
669
- type Surface = {
670
- paint(snapshot: unknown): void;
671
- hit_test(x: number, y: number): NodeId | null;
672
- on_input(listener: (event: unknown) => void): Unsubscribe;
673
- dispose(): void;
674
- };
675
- type SurfaceHandle = {
676
- detach(): void;
677
- };
678
- type Commands = {
679
- select(target: NodeId | ReadonlyArray<NodeId>, opts?: {
680
- additive?: boolean;
681
- }): void;
682
- deselect(): void;
683
- enter_scope(group: NodeId): void;
684
- exit_scope(): void;
685
- set_mode(mode: Mode): void;
686
- set_property(name: string, value: string | null): void;
687
- preview_property(name: string): PreviewSession;
688
- set_paint(channel: "fill" | "stroke", paint: Paint): void;
689
- preview_paint(channel: "fill" | "stroke"): PaintPreviewSession;
690
- set_paint_from_gradient(channel: "fill" | "stroke", definition: GradientDefinition, opts?: {
691
- reuse_existing?: boolean;
692
- }): {
693
- gradient_id: string;
694
- };
695
- translate(delta: {
696
- dx: number;
697
- dy: number;
698
- }): void;
699
- reorder(direction: ReorderDirection): void;
700
- remove(): void;
701
- set_text(value: string): void;
702
- load_svg(svg: string): void;
703
- serialize_svg(): string;
704
- undo(): void;
705
- redo(): void;
706
- /**
707
- * Register a command handler under a stable id. Returns an unregister
708
- * function. Re-registering the same id replaces the previous handler.
709
- *
710
- * Handlers return `true` if they consumed the invocation; `false` or
711
- * `undefined` signal "did not apply" — the keymap dispatcher will try
712
- * the next candidate in the chain.
713
- */
714
- register(id: CommandId, handler: CommandHandler): () => void;
715
- /**
716
- * Invoke a registered command by id. Returns `true` if a handler
717
- * consumed the invocation, `false` otherwise (including unknown ids).
718
- */
719
- invoke(id: CommandId, args?: unknown): boolean; /** Whether an id has a registered handler. */
720
- has(id: CommandId): boolean;
721
- };
722
- declare function createSvgEditor(opts: CreateSvgEditorOptions): {
723
- /**
724
- * Low-level IR handle. Mutating directly bypasses history; prefer
725
- * `editor.commands` for app code.
726
- */
727
- document: SvgDocument;
728
- readonly state: EditorState;
729
- subscribe: (fn: (state: EditorState) => void) => Unsubscribe;
730
- subscribe_with_selector: <T>(selector: (s: EditorState) => T, fn: (value: T, prev: T) => void, equals?: (a: T, b: T) => boolean) => Unsubscribe;
731
- node_properties: (id: NodeId, names: ReadonlyArray<string>) => {
732
- readonly [name: string]: ReturnType<typeof read_property>;
733
- };
734
- node_paint: (id: NodeId, channel: "fill" | "stroke") => PaintValue;
735
- dom_computed_property: (id: NodeId, name: string) => string | null;
736
- dom_computed_paint: (id: NodeId, channel: "fill" | "stroke") => DomComputedPaint | null;
737
- /**
738
- * Enter content-edit mode on a `<text>` node. Returns `false` (no-op)
739
- * when no DOM surface is attached.
740
- */
741
- enter_content_edit: (target?: NodeId) => boolean;
742
- defs: Defs;
743
- commands: Commands;
744
- /**
745
- * Human-readable label for hierarchy panels. SVG has no native "name";
746
- * this is the package's single source of truth so panels don't reinvent
747
- * the rule.
748
- *
749
- * Rule:
750
- * - `<text>` → text content, whitespace-collapsed and truncated at
751
- * ~40 chars (falls back to `"text"` for empty content).
752
- * - Otherwise → tag name, suffixed with `#id` when the `id` attribute
753
- * is present (e.g. `"rect #sun"`).
754
- *
755
- * `opts.tagLabel` lets callers substitute a friendlier or localized
756
- * term for the raw tag (e.g. `"rect"` → `"Rectangle"`). Only invoked
757
- * on the non-text branch.
758
- */
759
- display_label(id: NodeId, opts?: {
760
- tagLabel?: (tag: string) => string;
761
- }): string;
762
- tree(): {
763
- root: NodeId;
764
- nodes: ReadonlyMap<NodeId, {
765
- id: NodeId;
766
- tag: string;
767
- name?: string;
768
- parent: NodeId | null;
769
- children: ReadonlyArray<NodeId>;
770
- }>;
771
- };
772
- /**
773
- * The effective hover from the attached HUD surface — what's under the
774
- * pointer, OR whatever `set_surface_hover_override` last pushed. Used
775
- * by out-of-canvas UI (layers panel, breadcrumbs) to mirror the canvas
776
- * highlight. Returns `null` when nothing is hovered.
777
- */
778
- surface_hover(): NodeId | null;
779
- /**
780
- * Push a hover override into the HUD surface — e.g. when the user
781
- * hovers a row in a layers panel. The HUD will render the override's
782
- * outline and (when applicable) drive measurement to that node.
783
- * Pass `null` to clear and let the pointer pick take over again.
784
- */
785
- set_surface_hover_override(id: NodeId | null): void;
786
- /**
787
- * Subscribe to changes in the effective surface hover. Fires when the
788
- * HUD reports a new pointer pick AND when an override is set/cleared.
789
- * Cheap channel — does NOT bump `state.version`.
790
- */
791
- subscribe_surface_hover(cb: () => void): () => void;
792
- modes: readonly Mode[];
793
- readonly style: Readonly<EditorStyle>;
794
- set_style: (partial: Partial<EditorStyle>) => void;
795
- load: (svg: string) => void;
796
- serialize: () => string;
797
- reset: () => void;
798
- attach: (surface: Surface) => SurfaceHandle;
799
- detach: () => void;
800
- dispose: () => void;
801
- providers: Providers;
802
- _internal: {
803
- doc: SvgDocument;
804
- history: {
805
- preview: (label: string) => _$_grida_history0.Preview;
806
- };
807
- emit: () => void;
808
- set_content_edit_driver(fn: ((target: NodeId) => boolean) | null): void;
809
- /** Fires the driver immediately with the current override so the
810
- * surface can sync state on attach. */
811
- set_surface_hover_override_driver(fn: ((id: NodeId | null) => void) | null): void;
812
- push_surface_hover(id: NodeId | null): void;
813
- set_computed_resolver(fn: DomComputedResolver | null): void;
814
- };
815
- keymap: Keymap;
816
- };
817
- //#endregion
818
- export { LinearGradientDefinition as A, Providers as B, EditorStyle as C, GradientEntry as D, GradientDefinition as E, PaintPreviewSession as F, Vec2 as G, Rect as H, PaintValue as I, PreviewSession as L, NodeId as M, Paint as N, GradientStop as O, PaintFallback as P, PropertyValue as R, EditorState as S, FontResolver as T, ReorderDirection as U, RadialGradientDefinition as V, Unsubscribe as W, CameraConstraints as _, SurfaceHandle as a, Color as b, GestureBinding as c, Gestures as d, KeymapBinding as f, Camera as g, BoundsResolver as h, DomComputedResolver as i, Mode as j, InvalidComputedValue as k, GestureContext as l, CommandId as m, CreateSvgEditorOptions as n, SvgEditor as o, CommandHandler as p, DomComputedPaint as r, createSvgEditor as s, Commands as t, GestureId as u, CameraOptions as v, FileIOProvider as w, DEFAULT_STYLE as x, ClipboardProvider as y, Provenance as z };