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

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,113 +1,7 @@
1
1
  import * as _$_grida_history0 from "@grida/history";
2
2
  import { Keybinding, Platform } from "@grida/keybinding";
3
+ import cmath from "@grida/cmath";
3
4
 
4
- //#region src/commands/registry.d.ts
5
- /**
6
- * Command registry.
7
- *
8
- * A passive id-keyed registry of handlers. Built so that:
9
- *
10
- * - keybindings (in `src/keymap`) can address commands by stable id;
11
- * - new commands can be added in ONE place (`src/commands/defaults.ts`)
12
- * without growing the public surface of the editor;
13
- * - "one key, many meanings" can be expressed via chain semantics: a
14
- * handler returns `true` if it consumed, `false`/`void` otherwise,
15
- * and the dispatcher tries the next candidate in the chain.
16
- *
17
- * Handlers are plain closures — they capture whatever editor reference
18
- * they need. The registry itself stays unaware of the editor's type,
19
- * which avoids a circular type dependency between editor and registry.
20
- */
21
- /** Stable, dotted id for a command, e.g. `"history.undo"`. */
22
- type CommandId = string;
23
- /**
24
- * A command handler.
25
- *
26
- * Return `true` if the handler consumed the invocation. Return `false`
27
- * or `undefined` to signal "did not apply" — the dispatcher will try
28
- * the next candidate registered for the same key.
29
- *
30
- * Handlers are closures: they capture their editor reference. No
31
- * editor parameter is passed — keep handlers self-contained.
32
- */
33
- type CommandHandler = (args?: unknown) => boolean | void;
34
- declare class CommandRegistry {
35
- private readonly map;
36
- /**
37
- * Register a command. Returns an unregister function. Re-registering
38
- * the same id replaces the previous handler (last writer wins).
39
- */
40
- register(id: CommandId, handler: CommandHandler): () => void;
41
- /**
42
- * Invoke a command by id. Returns `true` if the handler consumed,
43
- * `false` otherwise (including unknown ids and handlers that returned
44
- * `false`/`undefined`).
45
- */
46
- invoke(id: CommandId, args?: unknown): boolean;
47
- has(id: CommandId): boolean;
48
- /** All registered ids, for debugging / introspection. */
49
- ids(): readonly CommandId[];
50
- }
51
- //#endregion
52
- //#region src/keymap/keymap.d.ts
53
- type KeymapBinding = {
54
- /** Declarative key combination. Build with `kb()` / `c()` / `seq()`. */keybinding: Keybinding; /** Command id to invoke on match. */
55
- command: CommandId; /** Forwarded as the `args` parameter to the command handler. */
56
- args?: unknown; /** Higher priorities run first in the chain. Default 0. */
57
- priority?: number;
58
- /**
59
- * Reserved for V2; not honored by the V1 dispatcher. When added, this
60
- * will be evaluated before the handler runs; if false, the binding is
61
- * skipped without invoking the handler.
62
- */
63
- when?: (ctx: unknown) => boolean;
64
- };
65
- declare class Keymap {
66
- private readonly commands;
67
- private readonly platformGetter;
68
- /**
69
- * Bindings bucketed by canonical chunk-key hash, computed per
70
- * `@grida/keybinding`'s `chunkKey`. Each list is the chain for that
71
- * key, sorted in dispatch order (priority desc, then registration
72
- * order).
73
- */
74
- private readonly buckets;
75
- /** Insert order, so ties on priority are deterministic. */
76
- private seq;
77
- constructor(commands: CommandRegistry, platformGetter?: () => Platform);
78
- /**
79
- * Bind a key combination to a command. Returns an unbind function.
80
- * The same `Keybinding` can be bound to multiple commands — they will
81
- * all be tried in chain order on dispatch.
82
- */
83
- bind(binding: KeymapBinding): () => void;
84
- /**
85
- * Remove bindings matching the spec. If both filters are passed, only
86
- * bindings that match BOTH are removed.
87
- */
88
- unbind(spec: {
89
- keybinding?: Keybinding;
90
- command?: CommandId;
91
- }): void;
92
- /** All registered bindings, for introspection. Order is not guaranteed. */
93
- bindings(): readonly KeymapBinding[];
94
- /**
95
- * Match the event against bound chunks, then run candidates in chain
96
- * order. Returns `true` and calls `preventDefault()` on the first
97
- * handler that consumes; returns `false` if nothing matched or all
98
- * matches fell through.
99
- */
100
- dispatch(event: KeyboardEvent): boolean;
101
- /**
102
- * Compute the set of canonical hashes a `Keybinding` lights up. A
103
- * binding with aliases (multiple sequences) contributes one hash per
104
- * single-chunk alias; multi-chunk sequences (chords) are skipped in
105
- * V1.
106
- */
107
- private chunkKeysFor;
108
- private has_safe_mod;
109
- }
110
- //#endregion
111
5
  //#region src/types.d.ts
112
6
  /**
113
7
  * Stable identifier for a node in the editor's document model.
@@ -264,6 +158,17 @@ type EditorState = {
264
158
  * `structure_version` so a drag doesn't invalidate the tree view.
265
159
  */
266
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;
267
172
  };
268
173
  type Unsubscribe = () => void;
269
174
  type ReorderDirection = "bring_forward" | "send_backward" | "bring_to_front" | "send_to_back";
@@ -278,6 +183,251 @@ type PaintPreviewSession = {
278
183
  discard(): void;
279
184
  };
280
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
281
431
  //#region src/core/parser.d.ts
282
432
  type AttrToken = {
283
433
  /** Verbatim source name including any prefix, e.g. "xlink:href". */raw_name: string; /** Prefix or null. */
@@ -439,6 +589,62 @@ type Defs = {
439
589
  //#region src/core/properties.d.ts
440
590
  declare function read_property(doc: SvgDocument, id: NodeId, property: string): PropertyValue;
441
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
442
648
  //#region src/core/editor.d.ts
443
649
  /** Resolved paint from the DOM-attached cascade. `resolved_paint` mirrors the
444
650
  * shape of `PaintValue.computed` so consumers can treat it uniformly with
@@ -609,4 +815,4 @@ declare function createSvgEditor(opts: CreateSvgEditorOptions): {
609
815
  keymap: Keymap;
610
816
  };
611
817
  //#endregion
612
- export { RadialGradientDefinition as A, PaintFallback as C, PropertyValue as D, PreviewSession as E, KeymapBinding as F, CommandHandler as I, CommandId as L, ReorderDirection as M, Unsubscribe as N, Provenance as O, Vec2 as P, Paint as S, PaintValue as T, GradientStop as _, SurfaceHandle as a, Mode as b, ClipboardProvider as c, EditorState as d, EditorStyle as f, GradientEntry as g, GradientDefinition as h, DomComputedResolver as i, Rect as j, Providers as k, Color as l, FontResolver as m, CreateSvgEditorOptions as n, SvgEditor as o, FileIOProvider as p, DomComputedPaint as r, createSvgEditor as s, Commands as t, DEFAULT_STYLE as u, InvalidComputedValue as v, PaintPreviewSession as w, NodeId as x, LinearGradientDefinition as y };
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 };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
package/dist/index.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { A as RadialGradientDefinition, C as PaintFallback, D as PropertyValue, E as PreviewSession, F as KeymapBinding, I as CommandHandler, L as CommandId, M as ReorderDirection, N as Unsubscribe, O as Provenance, P as Vec2, S as Paint, T as PaintValue, _ as GradientStop, a as SurfaceHandle, b as Mode, c as ClipboardProvider, d as EditorState, f as EditorStyle, g as GradientEntry, h as GradientDefinition, i as DomComputedResolver, j as Rect, k as Providers, l as Color, m as FontResolver, n as CreateSvgEditorOptions, o as SvgEditor, p as FileIOProvider, r as DomComputedPaint, s as createSvgEditor, t as Commands, u as DEFAULT_STYLE, v as InvalidComputedValue, w as PaintPreviewSession, x as NodeId, y as LinearGradientDefinition } from "./editor-BryibVvr.mjs";
2
- export { type ClipboardProvider, type Color, type CommandHandler, type CommandId, type Commands, type CreateSvgEditorOptions, DEFAULT_STYLE, type DomComputedPaint, type DomComputedResolver, type EditorState, type EditorStyle, type FileIOProvider, type FontResolver, type GradientDefinition, type GradientEntry, type GradientStop, type InvalidComputedValue, type KeymapBinding, type LinearGradientDefinition, type Mode, type NodeId, type Paint, type PaintFallback, type PaintPreviewSession, type PaintValue, type PreviewSession, type PropertyValue, type Provenance, type Providers, type RadialGradientDefinition, type Rect, type ReorderDirection, type SurfaceHandle, type SvgEditor, type Unsubscribe, type Vec2, createSvgEditor };
1
+ import { A as LinearGradientDefinition, B as Providers, C as EditorStyle, D as GradientEntry, E as GradientDefinition, F as PaintPreviewSession, G as Vec2, H as Rect, I as PaintValue, L as PreviewSession, M as NodeId, N as Paint, O as GradientStop, P as PaintFallback, R as PropertyValue, S as EditorState, T as FontResolver, U as ReorderDirection, V as RadialGradientDefinition, W as Unsubscribe, _ as CameraConstraints, a as SurfaceHandle, b as Color, c as GestureBinding, d as Gestures, f as KeymapBinding, g as Camera, h as BoundsResolver, i as DomComputedResolver, j as Mode, k as InvalidComputedValue, l as GestureContext, m as CommandId, n as CreateSvgEditorOptions, o as SvgEditor, p as CommandHandler, r as DomComputedPaint, s as createSvgEditor, t as Commands, u as GestureId, v as CameraOptions, w as FileIOProvider, x as DEFAULT_STYLE, y as ClipboardProvider, z as Provenance } from "./editor-Uu6dZX4y.mjs";
2
+ export { BoundsResolver, Camera, CameraConstraints, CameraOptions, ClipboardProvider, Color, CommandHandler, CommandId, Commands, CreateSvgEditorOptions, DEFAULT_STYLE, DomComputedPaint, DomComputedResolver, EditorState, EditorStyle, FileIOProvider, FontResolver, GestureBinding, GestureContext, GestureId, Gestures, GradientDefinition, GradientEntry, GradientStop, InvalidComputedValue, KeymapBinding, LinearGradientDefinition, Mode, NodeId, Paint, PaintFallback, PaintPreviewSession, PaintValue, PreviewSession, PropertyValue, Provenance, Providers, RadialGradientDefinition, Rect, ReorderDirection, SurfaceHandle, SvgEditor, Unsubscribe, Vec2, createSvgEditor };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { A as RadialGradientDefinition, C as PaintFallback, D as PropertyValue, E as PreviewSession, F as KeymapBinding, I as CommandHandler, L as CommandId, M as ReorderDirection, N as Unsubscribe, O as Provenance, P as Vec2, S as Paint, T as PaintValue, _ as GradientStop, a as SurfaceHandle, b as Mode, c as ClipboardProvider, d as EditorState, f as EditorStyle, g as GradientEntry, h as GradientDefinition, i as DomComputedResolver, j as Rect, k as Providers, l as Color, m as FontResolver, n as CreateSvgEditorOptions, o as SvgEditor, p as FileIOProvider, r as DomComputedPaint, s as createSvgEditor, t as Commands, u as DEFAULT_STYLE, v as InvalidComputedValue, w as PaintPreviewSession, x as NodeId, y as LinearGradientDefinition } from "./editor-klT8wu-x.js";
2
- export { type ClipboardProvider, type Color, type CommandHandler, type CommandId, type Commands, type CreateSvgEditorOptions, DEFAULT_STYLE, type DomComputedPaint, type DomComputedResolver, type EditorState, type EditorStyle, type FileIOProvider, type FontResolver, type GradientDefinition, type GradientEntry, type GradientStop, type InvalidComputedValue, type KeymapBinding, type LinearGradientDefinition, type Mode, type NodeId, type Paint, type PaintFallback, type PaintPreviewSession, type PaintValue, type PreviewSession, type PropertyValue, type Provenance, type Providers, type RadialGradientDefinition, type Rect, type ReorderDirection, type SurfaceHandle, type SvgEditor, type Unsubscribe, type Vec2, createSvgEditor };
1
+ import { A as LinearGradientDefinition, B as Providers, C as EditorStyle, D as GradientEntry, E as GradientDefinition, F as PaintPreviewSession, G as Vec2, H as Rect, I as PaintValue, L as PreviewSession, M as NodeId, N as Paint, O as GradientStop, P as PaintFallback, R as PropertyValue, S as EditorState, T as FontResolver, U as ReorderDirection, V as RadialGradientDefinition, W as Unsubscribe, _ as CameraConstraints, a as SurfaceHandle, b as Color, c as GestureBinding, d as Gestures, f as KeymapBinding, g as Camera, h as BoundsResolver, i as DomComputedResolver, j as Mode, k as InvalidComputedValue, l as GestureContext, m as CommandId, n as CreateSvgEditorOptions, o as SvgEditor, p as CommandHandler, r as DomComputedPaint, s as createSvgEditor, t as Commands, u as GestureId, v as CameraOptions, w as FileIOProvider, x as DEFAULT_STYLE, y as ClipboardProvider, z as Provenance } from "./editor-D2l_CDr0.js";
2
+ export { BoundsResolver, Camera, CameraConstraints, CameraOptions, ClipboardProvider, Color, CommandHandler, CommandId, Commands, CreateSvgEditorOptions, DEFAULT_STYLE, DomComputedPaint, DomComputedResolver, EditorState, EditorStyle, FileIOProvider, FontResolver, GestureBinding, GestureContext, GestureId, Gestures, GradientDefinition, GradientEntry, GradientStop, InvalidComputedValue, KeymapBinding, LinearGradientDefinition, Mode, NodeId, Paint, PaintFallback, PaintPreviewSession, PaintValue, PreviewSession, PropertyValue, Provenance, Providers, RadialGradientDefinition, Rect, ReorderDirection, SurfaceHandle, SvgEditor, Unsubscribe, Vec2, createSvgEditor };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_editor = require("./editor-DllAMsDu.js");
2
+ const require_editor = require("./editor-D2zZAyny.js");
3
3
  exports.DEFAULT_STYLE = require_editor.DEFAULT_STYLE;
4
4
  exports.createSvgEditor = require_editor.createSvgEditor;
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { n as DEFAULT_STYLE, t as createSvgEditor } from "./editor-M6j8XGO5.mjs";
1
+ import { n as DEFAULT_STYLE, t as createSvgEditor } from "./editor-CjK56cgb.mjs";
2
2
  export { DEFAULT_STYLE, createSvgEditor };
@@ -1,4 +1,20 @@
1
1
  import { SVGPathData, SVGPathDataTransformer } from "svg-pathdata";
2
+ //#region src/util/dom.ts
3
+ /**
4
+ * `true` when the document's active element is a text-input-like control
5
+ * (input / textarea / contentEditable). Used by keymap + gesture defaults
6
+ * to avoid hijacking keystrokes while the user is typing.
7
+ */
8
+ function is_text_input_focused() {
9
+ if (typeof document === "undefined") return false;
10
+ const el = document.activeElement;
11
+ if (!el) return false;
12
+ const tag = el.tagName;
13
+ if (tag === "INPUT" || tag === "TEXTAREA") return true;
14
+ if (el.isContentEditable) return true;
15
+ return false;
16
+ }
17
+ //#endregion
2
18
  //#region src/core/intents.ts
3
19
  function num(doc, id, name, fallback = 0) {
4
20
  const v = doc.get_attr(id, name);
@@ -458,4 +474,4 @@ function serialize_paint(paint) {
458
474
  }
459
475
  }
460
476
  //#endregion
461
- export { capture_resize_baseline as a, is_resizable as c, apply_translate as i, serialize_paint as n, capture_translate_baseline as o, apply_resize as r, compute_resize_factors as s, parse_paint as t };
477
+ export { capture_resize_baseline as a, is_resizable as c, apply_translate as i, is_text_input_focused as l, serialize_paint as n, capture_translate_baseline as o, apply_resize as r, compute_resize_factors as s, parse_paint as t };
@@ -1,5 +1,21 @@
1
- require("./dom-CfP_ZURh.js");
1
+ require("./dom-CoVZzFqy.js");
2
2
  let svg_pathdata = require("svg-pathdata");
3
+ //#region src/util/dom.ts
4
+ /**
5
+ * `true` when the document's active element is a text-input-like control
6
+ * (input / textarea / contentEditable). Used by keymap + gesture defaults
7
+ * to avoid hijacking keystrokes while the user is typing.
8
+ */
9
+ function is_text_input_focused() {
10
+ if (typeof document === "undefined") return false;
11
+ const el = document.activeElement;
12
+ if (!el) return false;
13
+ const tag = el.tagName;
14
+ if (tag === "INPUT" || tag === "TEXTAREA") return true;
15
+ if (el.isContentEditable) return true;
16
+ return false;
17
+ }
18
+ //#endregion
3
19
  //#region src/core/intents.ts
4
20
  function num(doc, id, name, fallback = 0) {
5
21
  const v = doc.get_attr(id, name);
@@ -495,6 +511,12 @@ Object.defineProperty(exports, "is_resizable", {
495
511
  return is_resizable;
496
512
  }
497
513
  });
514
+ Object.defineProperty(exports, "is_text_input_focused", {
515
+ enumerable: true,
516
+ get: function() {
517
+ return is_text_input_focused;
518
+ }
519
+ });
498
520
  Object.defineProperty(exports, "parse_paint", {
499
521
  enumerable: true,
500
522
  get: function() {
@@ -0,0 +1,46 @@
1
+ import { o as SvgEditor } from "./editor-Uu6dZX4y.mjs";
2
+ import { n as DomSurfaceOptions, t as DomSurfaceHandle } from "./dom-DJnZhtOd.mjs";
3
+ declare namespace keynote_d_exports {
4
+ export { KeynoteAttachOptions, KeynoteSurfaceHandle, attach };
5
+ }
6
+ type KeynoteAttachOptions = {
7
+ /** Container to mount the SVG into. */container: HTMLElement;
8
+ /**
9
+ * Screen-pixel breathing room between the slide and the viewport edge.
10
+ * Used for both initial fit and the cover-constraint clamp. Default 80.
11
+ */
12
+ padding?: number;
13
+ /**
14
+ * Forward additional surface options (e.g. `gestures: false`). `container`,
15
+ * `fit`, and `initial_camera` are owned by the preset.
16
+ */
17
+ surface?: Omit<DomSurfaceOptions, "container" | "fit" | "initial_camera">;
18
+ };
19
+ /**
20
+ * Surface handle returned by `keynote.attach`. Extends `DomSurfaceHandle`
21
+ * with `set_padding` so hosts can vary the slide breathing room at runtime
22
+ * (e.g. on a "present mode" toggle that wants margin: 0 vs the default 80).
23
+ */
24
+ type KeynoteSurfaceHandle = DomSurfaceHandle & {
25
+ /**
26
+ * Update the slide padding and re-fit. Mutates the live constraint AND
27
+ * the captured padding used by load-triggered refits.
28
+ */
29
+ set_padding(p: number): void;
30
+ };
31
+ /**
32
+ * Attach a keynote-shaped DOM surface:
33
+ * - Mounts via `attach_dom_surface` with `fit: true` (slide is visible on
34
+ * first frame).
35
+ * - Installs a `'cover'` camera constraint bound to the document root, so
36
+ * the user can't zoom out past the slide or pan past its edges.
37
+ * - Subscribes to `editor.state.load_version` so every `editor.load(svg)`
38
+ * re-fits the camera to the new document.
39
+ *
40
+ * Returns a `KeynoteSurfaceHandle` — same shape as `DomSurfaceHandle` plus
41
+ * `set_padding` for present-mode toggles. The returned `detach()`
42
+ * additionally tears down the load subscription.
43
+ */
44
+ declare function attach(editor: SvgEditor, opts: KeynoteAttachOptions): KeynoteSurfaceHandle;
45
+ //#endregion
46
+ export { type KeynoteAttachOptions, type KeynoteSurfaceHandle, keynote_d_exports as keynote };
@@ -0,0 +1,46 @@
1
+ import { o as SvgEditor } from "./editor-D2l_CDr0.js";
2
+ import { n as DomSurfaceOptions, t as DomSurfaceHandle } from "./dom-Cn-RtjRL.js";
3
+ declare namespace keynote_d_exports {
4
+ export { KeynoteAttachOptions, KeynoteSurfaceHandle, attach };
5
+ }
6
+ type KeynoteAttachOptions = {
7
+ /** Container to mount the SVG into. */container: HTMLElement;
8
+ /**
9
+ * Screen-pixel breathing room between the slide and the viewport edge.
10
+ * Used for both initial fit and the cover-constraint clamp. Default 80.
11
+ */
12
+ padding?: number;
13
+ /**
14
+ * Forward additional surface options (e.g. `gestures: false`). `container`,
15
+ * `fit`, and `initial_camera` are owned by the preset.
16
+ */
17
+ surface?: Omit<DomSurfaceOptions, "container" | "fit" | "initial_camera">;
18
+ };
19
+ /**
20
+ * Surface handle returned by `keynote.attach`. Extends `DomSurfaceHandle`
21
+ * with `set_padding` so hosts can vary the slide breathing room at runtime
22
+ * (e.g. on a "present mode" toggle that wants margin: 0 vs the default 80).
23
+ */
24
+ type KeynoteSurfaceHandle = DomSurfaceHandle & {
25
+ /**
26
+ * Update the slide padding and re-fit. Mutates the live constraint AND
27
+ * the captured padding used by load-triggered refits.
28
+ */
29
+ set_padding(p: number): void;
30
+ };
31
+ /**
32
+ * Attach a keynote-shaped DOM surface:
33
+ * - Mounts via `attach_dom_surface` with `fit: true` (slide is visible on
34
+ * first frame).
35
+ * - Installs a `'cover'` camera constraint bound to the document root, so
36
+ * the user can't zoom out past the slide or pan past its edges.
37
+ * - Subscribes to `editor.state.load_version` so every `editor.load(svg)`
38
+ * re-fits the camera to the new document.
39
+ *
40
+ * Returns a `KeynoteSurfaceHandle` — same shape as `DomSurfaceHandle` plus
41
+ * `set_padding` for present-mode toggles. The returned `detach()`
42
+ * additionally tears down the load subscription.
43
+ */
44
+ declare function attach(editor: SvgEditor, opts: KeynoteAttachOptions): KeynoteSurfaceHandle;
45
+ //#endregion
46
+ export { type KeynoteAttachOptions, type KeynoteSurfaceHandle, keynote_d_exports as keynote };