@fieldnotes/core 0.61.0 → 0.62.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.
package/dist/index.d.cts CHANGED
@@ -450,7 +450,7 @@ declare class HistoryStack {
450
450
  }
451
451
 
452
452
  type HtmlExportRenderer = (element: HtmlElement) => CanvasImageSource | null | Promise<CanvasImageSource | null>;
453
- type HtmlExportErrorReason = 'unsupported' | 'timeout' | 'render' | 'encode';
453
+ type HtmlExportErrorReason = 'unsupported' | 'timeout' | 'render' | 'encode' | 'missing-painter' | 'painter-threw' | 'degenerate-size';
454
454
  interface HtmlExportError {
455
455
  elementId: string;
456
456
  htmlType?: string;
@@ -466,6 +466,51 @@ interface HtmlExportOptions {
466
466
  onHtmlError?: (error: HtmlExportError) => void;
467
467
  }
468
468
 
469
+ interface HtmlPaintContext {
470
+ /** Translated to the element origin, rotated about its centre, clipped, save()d.
471
+ * Layer opacity is NOT applied here — each surface owns that boundary. */
472
+ ctx: CanvasRenderingContext2D;
473
+ element: Readonly<HtmlElement>;
474
+ size: Readonly<Size>;
475
+ /** CSS pixels per world unit for THIS surface (screen | minimap | export). */
476
+ zoom: number;
477
+ }
478
+ type HtmlPainter = (paint: HtmlPaintContext) => void;
479
+ type HtmlRouting = 'dom' | 'canvas' | 'missing';
480
+ declare class HtmlPainterMissingError extends Error {
481
+ readonly elementId: string;
482
+ readonly htmlType: string | undefined;
483
+ constructor(elementId: string, htmlType: string | undefined);
484
+ }
485
+ declare class HtmlPainterRegistry {
486
+ private readonly painters;
487
+ private readonly declared;
488
+ private readonly listeners;
489
+ private _version;
490
+ private canvasTypesCache;
491
+ get version(): number;
492
+ /**
493
+ * Memoized: this is the hottest read in the feature — `isDomElement` consults it several
494
+ * times per element per frame, and every html-element store update re-reconciles every
495
+ * html element. The cache is dropped in `bump()`, which is called on exactly the
496
+ * transitions that can change the membership of this set (first `expect` of a type, last
497
+ * release of a type, any `register`, and any unregister that empties a type's stack).
498
+ *
499
+ * The returned `Set` is the LIVE memoized instance, not a copy: callers must not mutate
500
+ * it, and a caller that holds it across a `bump()` holds a stale snapshot. Nothing in the
501
+ * codebase does either — `withHtmlDefaults` passes it straight through to the exporters
502
+ * unless the caller supplied `expectedCanvasTypes`, in which case it builds a fresh union
503
+ * — and holding it across a change was already a stale snapshot before memoization.
504
+ */
505
+ get canvasTypes(): ReadonlySet<string>;
506
+ expect(htmlTypes: Iterable<string>): () => void;
507
+ register(htmlType: string, painter: HtmlPainter): () => void;
508
+ getActivePainter(htmlType: string): HtmlPainter | undefined;
509
+ onChange(listener: () => void): () => void;
510
+ private bump;
511
+ }
512
+ declare function resolveHtmlRouting(el: Readonly<HtmlElement>, registry: HtmlPainterRegistry | null, expectedCanvasTypes?: ReadonlySet<string>): HtmlRouting;
513
+
469
514
  interface ExportImageOptions extends ExportResourceOptions, HtmlExportOptions {
470
515
  scale?: number;
471
516
  padding?: number;
@@ -497,6 +542,20 @@ interface ExportImageOptions extends ExportResourceOptions, HtmlExportOptions {
497
542
  * caps (never above the requested scale).
498
543
  */
499
544
  scaleMode?: 'exact' | 'fit';
545
+ /** Registry of canvas-backed html painters, keyed by `htmlType`. When absent (or when
546
+ * an element's `htmlType` isn't claimed), html elements fall back to the legacy
547
+ * DOM-raster path (`renderHtml`). */
548
+ htmlPainters?: HtmlPainterRegistry;
549
+ /** `htmlType`s that must route to canvas even before a painter for them is
550
+ * registered — lets a host declare intent up front (mirrors `HtmlPainterRegistry.expect`). */
551
+ expectedCanvasTypes?: ReadonlySet<string>;
552
+ /**
553
+ * When true, a canvas-routed html element with no active painter throws
554
+ * `HtmlPainterMissingError` instead of reporting `onHtmlError` and continuing.
555
+ * DOM-routed html elements are never affected — a missing `renderHtml` stays
556
+ * a non-fatal `'unsupported'` diagnostic regardless of this flag.
557
+ */
558
+ strictMissingCanvasHtml?: boolean;
500
559
  }
501
560
  type ExportAssetErrorReason = 'load' | 'timeout' | 'encode';
502
561
  interface ExportAssetError {
@@ -522,9 +581,32 @@ interface ExportSvgOptions extends ExportResourceOptions, HtmlExportOptions {
522
581
  background?: string;
523
582
  filter?: (el: CanvasElement) => boolean;
524
583
  rasterScale?: number;
584
+ /** Registry of canvas-backed html painters, keyed by `htmlType`. When absent (or when
585
+ * an element's `htmlType` isn't claimed), html elements fall back to the legacy
586
+ * DOM-raster path (`renderHtml`). */
587
+ htmlPainters?: HtmlPainterRegistry;
588
+ /** `htmlType`s that must route to canvas even before a painter for them is
589
+ * registered — lets a host declare intent up front (mirrors `HtmlPainterRegistry.expect`). */
590
+ expectedCanvasTypes?: ReadonlySet<string>;
591
+ /**
592
+ * When true, a canvas-routed html element with no active painter throws
593
+ * `HtmlPainterMissingError` instead of reporting `onHtmlError` and continuing.
594
+ * DOM-routed html elements are never affected — a missing `renderHtml` stays
595
+ * a non-fatal `'unsupported'` diagnostic regardless of this flag.
596
+ */
597
+ strictMissingCanvasHtml?: boolean;
525
598
  }
526
599
  declare function exportSvg(store: ElementStore, options?: ExportSvgOptions, layerManager?: LayerManager): Promise<string>;
527
600
 
601
+ type HtmlRenderTarget = 'screen' | 'minimap' | 'export';
602
+ interface HtmlPaintDiagnostic {
603
+ kind: 'missing-painter' | 'painter-threw' | 'degenerate-size';
604
+ elementId: string;
605
+ htmlType?: string;
606
+ target: HtmlRenderTarget;
607
+ error?: unknown;
608
+ }
609
+
528
610
  interface RenderStatsSnapshot {
529
611
  fps: number;
530
612
  avgFrameMs: number;
@@ -575,6 +657,30 @@ interface GridInfo {
575
657
  cellRadius: number;
576
658
  }
577
659
 
660
+ interface ElementActivationEvent {
661
+ element: Readonly<CanvasElement>;
662
+ /** Pointerup location converted through the pointerup camera snapshot. */
663
+ world: Point;
664
+ /**
665
+ * Raw `PointerEvent.pointerType`. Usually `'mouse' | 'touch' | 'pen'`, but the
666
+ * spec permits vendor-defined and empty strings, so this is NOT narrowed and
667
+ * NOT normalised.
668
+ */
669
+ pointerType: string;
670
+ gesture: 'single' | 'double';
671
+ }
672
+ interface ActivationOptions {
673
+ gesture: 'single' | 'double';
674
+ /** Additional host filter, applied on top of the core canvas-routing gate. */
675
+ isActivatable?: (el: Readonly<CanvasElement>) => boolean;
676
+ /** Host-owned camera animators the viewport cannot see. */
677
+ isCameraBusy?: () => boolean;
678
+ /** Maximum pointer travel between down and up. Default `8` (PingInput parity). */
679
+ slopPx?: number;
680
+ /** Maximum gap between the halves of a double tap. Default `300`. */
681
+ doubleDelayMs?: number;
682
+ }
683
+
578
684
  interface ViewportOptions {
579
685
  camera?: CameraOptions;
580
686
  background?: BackgroundOptions;
@@ -643,6 +749,14 @@ declare class Viewport {
643
749
  private contextMenu;
644
750
  private minimap;
645
751
  private readonly htmlRenderers;
752
+ private readonly htmlPainters;
753
+ private readonly htmlDiagnosticListeners;
754
+ private readonly htmlDiagnostics;
755
+ private readonly resolveRouting;
756
+ private readonly unsubHtmlPainters;
757
+ private activation;
758
+ private activationGeneration;
759
+ private readonly activationListeners;
646
760
  private readonly resizeListeners;
647
761
  private readonly selectionListeners;
648
762
  private detachSelectionSource;
@@ -690,6 +804,15 @@ declare class Viewport {
690
804
  registerOverlay(draw: OverlayRenderer): () => void;
691
805
  exportState(): CanvasState;
692
806
  exportJSON(): string;
807
+ /**
808
+ * Injects this viewport's own html painter registry into export options so a host
809
+ * that registered painters via `registerHtmlPainter`/`expectCanvasHtmlTypes` gets
810
+ * markers in exports without passing anything. An explicitly passed `htmlPainters`
811
+ * REPLACES the viewport's registry rather than merging with it. `expectedCanvasTypes`
812
+ * is always UNIONED with the resolved registry's own declarations — a caller's set
813
+ * can only add expectations, never shrink the registry's own.
814
+ */
815
+ private withHtmlDefaults;
693
816
  exportImage(options?: ExportImageOptions): Promise<Blob | null>;
694
817
  exportSVG(options?: ExportSvgOptions): Promise<string>;
695
818
  loadState(state: CanvasState): void;
@@ -741,6 +864,74 @@ declare class Viewport {
741
864
  removeLayer(id: string): void;
742
865
  registerHtmlRenderer(htmlType: string, factory: (el: HtmlElement) => HTMLElement): void;
743
866
  updateHtmlElement(id: string, newContent: HTMLElement): void;
867
+ /**
868
+ * Declares htmlTypes that route to canvas painters even before a painter for
869
+ * them registers, so the element renderer never treats them as DOM-backed
870
+ * (avoiding a DOM-mount flash while a host is still loading its painter).
871
+ * Returns an idempotent release; each `expect` call is independently reference
872
+ * counted by the registry.
873
+ */
874
+ expectCanvasHtmlTypes(htmlTypes: Iterable<string>): () => void;
875
+ /**
876
+ * Direct access to the viewport's live html-painter registry — the same
877
+ * instance the viewport itself uses to route canvas-backed html elements.
878
+ * Beyond `register`/`expectCanvasHtmlTypes` (already exposed above), this
879
+ * hands out `getActivePainter`, `canvasTypes`, `onChange`, and `version`,
880
+ * so a surface such as the minimap that needs to read routing state or
881
+ * react to registry changes can do so without the viewport re-deriving or
882
+ * proxying each capability individually.
883
+ */
884
+ getHtmlPainters(): HtmlPainterRegistry;
885
+ /**
886
+ * Registers the canvas painter for `htmlType`. Later registrations for the
887
+ * same type shadow earlier ones (LIFO); unregistering restores the previous
888
+ * entry. Existing elements of this type reconcile synchronously — DOM nodes
889
+ * detach and the render loop repaints on the next frame.
890
+ */
891
+ registerHtmlPainter(htmlType: string, painter: HtmlPainter): () => void;
892
+ /**
893
+ * Subscribes to diagnostics emitted while painting canvas-routed html
894
+ * elements (missing painter, painter threw, degenerate size). Deduped per
895
+ * element/target/kind against the current registry and element versions, so
896
+ * a fail -> repair -> fail-again sequence reports twice rather than being
897
+ * suppressed forever. Returns an idempotent unsubscribe.
898
+ */
899
+ onHtmlPaintDiagnostic(listener: (d: HtmlPaintDiagnostic) => void): () => void;
900
+ /**
901
+ * Enables (or replaces, or with `null` disables) pointer activation of
902
+ * canvas-painted elements — the bridge for elements that are drawn rather than
903
+ * mounted and so cannot receive DOM events. **Default off**, so every existing
904
+ * consumer behaves identically.
905
+ *
906
+ * The controller is a passive observer: listeners are `{ passive: true }` and
907
+ * it never calls `preventDefault`, `stopPropagation`, or takes pointer capture.
908
+ * Changing or disabling activation resets all active and pending gestures.
909
+ * Throws `RangeError` for a non-finite/negative `slopPx` or a non-positive
910
+ * `doubleDelayMs`, leaving any existing activation untouched.
911
+ *
912
+ * The returned disposer clears **only its own generation**, so a stale
913
+ * Strict-Mode cleanup cannot tear down a newer registration.
914
+ */
915
+ setActivation(options: ActivationOptions | null): () => void;
916
+ /**
917
+ * Subscribes to element activations. Persistent and independent of
918
+ * `setActivation`: subscribing before activation is enabled, or across a
919
+ * replacement, keeps working. Emission iterates a snapshot with per-listener
920
+ * try/catch. Returns an idempotent unsubscribe.
921
+ */
922
+ onElementActivate(listener: (e: ElementActivationEvent) => void): () => void;
923
+ private emitActivation;
924
+ /**
925
+ * Fires whenever the html painter registry's active-painter set changes
926
+ * (declare, register, or their release). Reconciliation is synchronous —
927
+ * routing flips (and any DOM detach/remount) happen before this returns —
928
+ * while the actual repaint of newly canvas-routed elements is deferred to
929
+ * the next render frame via markAllLayersDirty + requestRender. Does NOT
930
+ * touch a minimap: Viewport does not own a MinimapController, and the
931
+ * built-in wrapper / React <Minimap /> each subscribe to the registry
932
+ * directly.
933
+ */
934
+ private onHtmlRegistryChanged;
744
935
  addGrid(input: {
745
936
  gridType?: 'square' | 'hex';
746
937
  hexOrientation?: 'pointy' | 'flat';
@@ -1368,6 +1559,7 @@ declare class MinimapController {
1368
1559
  private readonly requestFrame;
1369
1560
  private readonly cancelFrame;
1370
1561
  private readonly renderer;
1562
+ private readonly htmlPainters;
1371
1563
  private scene;
1372
1564
  private frameId;
1373
1565
  private debounceTimer;
@@ -1377,6 +1569,19 @@ declare class MinimapController {
1377
1569
  constructor(viewport: Viewport, canvas: HTMLCanvasElement, options?: MinimapControllerOptions);
1378
1570
  setSize(width: number, height: number): void;
1379
1571
  requestDraw(): void;
1572
+ /**
1573
+ * Invalidates the cached scene bitmap in response to html-painter registry
1574
+ * changes (a painter registering/unregistering, or an `expect` declaration
1575
+ * changing) and schedules the same debounced rebuild `markSceneDirty` uses
1576
+ * for every other invalidation source. Unlike those other sources — which
1577
+ * deliberately keep compositing the OLD bitmap until the rebuild lands, so
1578
+ * camera motion and content edits never stall on a render — painter
1579
+ * availability has no "old bitmap is still valid" reading: an element that
1580
+ * was falling back to a neutral fillRect (no painter yet) or a stale
1581
+ * painter's output is not a safe thing to keep showing, so the cached
1582
+ * bitmap is dropped immediately instead of composited a further time.
1583
+ */
1584
+ invalidateScene(): void;
1380
1585
  dispose(): void;
1381
1586
  private clearDebounce;
1382
1587
  private dpr;
@@ -1649,6 +1854,7 @@ interface HtmlInput extends BaseDefaults {
1649
1854
  interactive?: boolean;
1650
1855
  htmlType?: string;
1651
1856
  data?: Record<string, unknown>;
1857
+ rotation?: number;
1652
1858
  }
1653
1859
  interface TextInput extends BaseDefaults {
1654
1860
  position: Point;
@@ -1996,6 +2202,6 @@ declare class TemplateTool implements Tool {
1996
2202
  private notifyOptionsChange;
1997
2203
  }
1998
2204
 
1999
- declare const VERSION = "0.61.0";
2205
+ declare const VERSION = "0.62.0";
2000
2206
 
2001
- export { type ActiveFormats, type AlignEdge, type ArrowElement, type ArrowStrokeStyle, ArrowTool, type ArrowToolOptions, AutoSave, type AutoSaveOptions, type BackgroundOptions, type BackgroundPattern, type Binding, type Bounds, Camera, type CameraAnimationEndReason, CameraAnimator, type CameraAnimatorOptions, type CameraChangeInfo, type CameraOptions, type CameraView, type CanvasElement, type CanvasState, type Command, DEFAULT_NOTE_FONT_SIZE, type DistributeAxis, type ElementChangeMeta, ElementStore, type ElementStyle, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, type ExportAssetError, type ExportAssetErrorReason, type ExportImageOptions, type ExportResourceOptions, type ExportSvgOptions, FOCUS_PRESENCE_KIND, type FocusAudience, type FocusPresence, type FocusRole, type FontSizePreset, type FrameScheduler, type GridElement, type GridInfo, HandTool, type HexOrientation, HistoryStack, type HistoryStackOptions, type HtmlElement, type HtmlExportError, type HtmlExportErrorReason, type HtmlExportOptions, type HtmlExportRenderer, type ImageElement, ImageTool, type ImageToolOptions, IndexedDBAdapter, type IndexedDBAdapterOptions, LASER_TRAIL_PRESENCE_KIND, LaserTool, type LaserToolOptions, type LaserTrailEmission, type LaserTrailPresence, type Layer, LayerManager, LocalStorageAdapter, MEASURE_PRESENCE_KIND, type MeasureEmission, type MeasurePresence, MeasureTool, type MeasureToolOptions, type Measurement, MemoryAdapter, MinimapController, type MinimapControllerOptions, type NoteElement, NoteTool, type NoteToolOptions, type OverlayRenderer, PING_PRESENCE_KIND, PencilTool, type PencilToolOptions, type PingEmission, PingInput, type PingInputHost, type PingInputOptions, type PingPresence, PingTool, type PingToolOptions, type Point, type PointerState, RemoteFocusReceiver, type RemoteFocusReceiverHost, type RemoteFocusReceiverOptions, RemoteLaserOverlay, type RemoteLaserOverlayHost, type RemoteLaserOverlayOptions, RemoteMeasureOverlay, type RemoteMeasureOverlayHost, type RemoteMeasureOverlayOptions, RemotePingOverlay, type RemotePingOverlayHost, type RemotePingOverlayOptions, type RenderStatsSnapshot, type RotateDirection, SelectTool, type SelectionStyleDetails, type ShapeElement, type ShapeKind, ShapeTool, type ShapeToolOptions, type ShortcutBindings, type ShortcutOptions, type ShortcutsApi, type Size, type StorageAdapter, type StrokeElement, type StrokePoint, type TemplateElement, type TemplateRenderStyle, type TemplateShape, TemplateTool, type TemplateToolOptions, type TextElement, TextTool, type TextToolOptions, type Tool, type ToolContext, ToolManager, type ToolName, VERSION, Viewport, type ViewportOptions, applyCameraView, boundsIntersect, cameraOriginForView, captureCameraView, createArrow, createGrid, createHtmlElement, createImage, createNote, createShape, createStroke, createTemplate, createText, drawHexPath, exportImage, exportSvg, fitZoomForView, getActiveFormats, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, getElementBounds, getElementStyle, getElementsBoundingBox, getHexCellsInCone, getHexCellsInLine, getHexCellsInRadius, getHexCellsInRectangle, getHexCellsInSquare, getHexDistance, isFocusPresence, isLaserTrailPresence, isMeasurePresence, isNearBezier, isPingPresence, setFontSize, smartSnap, snapPoint, snapToHexCenter, styleToPatch, toFocusPresence, toLaserTrailPresence, toMeasurePresence, toPingPresence, toggleBold, toggleItalic, toggleStrikethrough, toggleUnderline };
2207
+ export { type ActivationOptions, type ActiveFormats, type AlignEdge, type ArrowElement, type ArrowStrokeStyle, ArrowTool, type ArrowToolOptions, AutoSave, type AutoSaveOptions, type BackgroundOptions, type BackgroundPattern, type Binding, type Bounds, Camera, type CameraAnimationEndReason, CameraAnimator, type CameraAnimatorOptions, type CameraChangeInfo, type CameraOptions, type CameraView, type CanvasElement, type CanvasState, type Command, DEFAULT_NOTE_FONT_SIZE, type DistributeAxis, type ElementActivationEvent, type ElementChangeMeta, ElementStore, type ElementStyle, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, type ExportAssetError, type ExportAssetErrorReason, type ExportImageOptions, type ExportResourceOptions, type ExportSvgOptions, FOCUS_PRESENCE_KIND, type FocusAudience, type FocusPresence, type FocusRole, type FontSizePreset, type FrameScheduler, type GridElement, type GridInfo, HandTool, type HexOrientation, HistoryStack, type HistoryStackOptions, type HtmlElement, type HtmlExportError, type HtmlExportErrorReason, type HtmlExportOptions, type HtmlExportRenderer, type HtmlPaintContext, type HtmlPaintDiagnostic, type HtmlPainter, HtmlPainterMissingError, HtmlPainterRegistry, type HtmlRenderTarget, type HtmlRouting, type ImageElement, ImageTool, type ImageToolOptions, IndexedDBAdapter, type IndexedDBAdapterOptions, LASER_TRAIL_PRESENCE_KIND, LaserTool, type LaserToolOptions, type LaserTrailEmission, type LaserTrailPresence, type Layer, LayerManager, LocalStorageAdapter, MEASURE_PRESENCE_KIND, type MeasureEmission, type MeasurePresence, MeasureTool, type MeasureToolOptions, type Measurement, MemoryAdapter, MinimapController, type MinimapControllerOptions, type NoteElement, NoteTool, type NoteToolOptions, type OverlayRenderer, PING_PRESENCE_KIND, PencilTool, type PencilToolOptions, type PingEmission, PingInput, type PingInputHost, type PingInputOptions, type PingPresence, PingTool, type PingToolOptions, type Point, type PointerState, RemoteFocusReceiver, type RemoteFocusReceiverHost, type RemoteFocusReceiverOptions, RemoteLaserOverlay, type RemoteLaserOverlayHost, type RemoteLaserOverlayOptions, RemoteMeasureOverlay, type RemoteMeasureOverlayHost, type RemoteMeasureOverlayOptions, RemotePingOverlay, type RemotePingOverlayHost, type RemotePingOverlayOptions, type RenderStatsSnapshot, type RotateDirection, SelectTool, type SelectionStyleDetails, type ShapeElement, type ShapeKind, ShapeTool, type ShapeToolOptions, type ShortcutBindings, type ShortcutOptions, type ShortcutsApi, type Size, type StorageAdapter, type StrokeElement, type StrokePoint, type TemplateElement, type TemplateRenderStyle, type TemplateShape, TemplateTool, type TemplateToolOptions, type TextElement, TextTool, type TextToolOptions, type Tool, type ToolContext, ToolManager, type ToolName, VERSION, Viewport, type ViewportOptions, applyCameraView, boundsIntersect, cameraOriginForView, captureCameraView, createArrow, createGrid, createHtmlElement, createImage, createNote, createShape, createStroke, createTemplate, createText, drawHexPath, exportImage, exportSvg, fitZoomForView, getActiveFormats, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, getElementBounds, getElementStyle, getElementsBoundingBox, getHexCellsInCone, getHexCellsInLine, getHexCellsInRadius, getHexCellsInRectangle, getHexCellsInSquare, getHexDistance, isFocusPresence, isLaserTrailPresence, isMeasurePresence, isNearBezier, isPingPresence, resolveHtmlRouting, setFontSize, smartSnap, snapPoint, snapToHexCenter, styleToPatch, toFocusPresence, toLaserTrailPresence, toMeasurePresence, toPingPresence, toggleBold, toggleItalic, toggleStrikethrough, toggleUnderline };
package/dist/index.d.ts CHANGED
@@ -450,7 +450,7 @@ declare class HistoryStack {
450
450
  }
451
451
 
452
452
  type HtmlExportRenderer = (element: HtmlElement) => CanvasImageSource | null | Promise<CanvasImageSource | null>;
453
- type HtmlExportErrorReason = 'unsupported' | 'timeout' | 'render' | 'encode';
453
+ type HtmlExportErrorReason = 'unsupported' | 'timeout' | 'render' | 'encode' | 'missing-painter' | 'painter-threw' | 'degenerate-size';
454
454
  interface HtmlExportError {
455
455
  elementId: string;
456
456
  htmlType?: string;
@@ -466,6 +466,51 @@ interface HtmlExportOptions {
466
466
  onHtmlError?: (error: HtmlExportError) => void;
467
467
  }
468
468
 
469
+ interface HtmlPaintContext {
470
+ /** Translated to the element origin, rotated about its centre, clipped, save()d.
471
+ * Layer opacity is NOT applied here — each surface owns that boundary. */
472
+ ctx: CanvasRenderingContext2D;
473
+ element: Readonly<HtmlElement>;
474
+ size: Readonly<Size>;
475
+ /** CSS pixels per world unit for THIS surface (screen | minimap | export). */
476
+ zoom: number;
477
+ }
478
+ type HtmlPainter = (paint: HtmlPaintContext) => void;
479
+ type HtmlRouting = 'dom' | 'canvas' | 'missing';
480
+ declare class HtmlPainterMissingError extends Error {
481
+ readonly elementId: string;
482
+ readonly htmlType: string | undefined;
483
+ constructor(elementId: string, htmlType: string | undefined);
484
+ }
485
+ declare class HtmlPainterRegistry {
486
+ private readonly painters;
487
+ private readonly declared;
488
+ private readonly listeners;
489
+ private _version;
490
+ private canvasTypesCache;
491
+ get version(): number;
492
+ /**
493
+ * Memoized: this is the hottest read in the feature — `isDomElement` consults it several
494
+ * times per element per frame, and every html-element store update re-reconciles every
495
+ * html element. The cache is dropped in `bump()`, which is called on exactly the
496
+ * transitions that can change the membership of this set (first `expect` of a type, last
497
+ * release of a type, any `register`, and any unregister that empties a type's stack).
498
+ *
499
+ * The returned `Set` is the LIVE memoized instance, not a copy: callers must not mutate
500
+ * it, and a caller that holds it across a `bump()` holds a stale snapshot. Nothing in the
501
+ * codebase does either — `withHtmlDefaults` passes it straight through to the exporters
502
+ * unless the caller supplied `expectedCanvasTypes`, in which case it builds a fresh union
503
+ * — and holding it across a change was already a stale snapshot before memoization.
504
+ */
505
+ get canvasTypes(): ReadonlySet<string>;
506
+ expect(htmlTypes: Iterable<string>): () => void;
507
+ register(htmlType: string, painter: HtmlPainter): () => void;
508
+ getActivePainter(htmlType: string): HtmlPainter | undefined;
509
+ onChange(listener: () => void): () => void;
510
+ private bump;
511
+ }
512
+ declare function resolveHtmlRouting(el: Readonly<HtmlElement>, registry: HtmlPainterRegistry | null, expectedCanvasTypes?: ReadonlySet<string>): HtmlRouting;
513
+
469
514
  interface ExportImageOptions extends ExportResourceOptions, HtmlExportOptions {
470
515
  scale?: number;
471
516
  padding?: number;
@@ -497,6 +542,20 @@ interface ExportImageOptions extends ExportResourceOptions, HtmlExportOptions {
497
542
  * caps (never above the requested scale).
498
543
  */
499
544
  scaleMode?: 'exact' | 'fit';
545
+ /** Registry of canvas-backed html painters, keyed by `htmlType`. When absent (or when
546
+ * an element's `htmlType` isn't claimed), html elements fall back to the legacy
547
+ * DOM-raster path (`renderHtml`). */
548
+ htmlPainters?: HtmlPainterRegistry;
549
+ /** `htmlType`s that must route to canvas even before a painter for them is
550
+ * registered — lets a host declare intent up front (mirrors `HtmlPainterRegistry.expect`). */
551
+ expectedCanvasTypes?: ReadonlySet<string>;
552
+ /**
553
+ * When true, a canvas-routed html element with no active painter throws
554
+ * `HtmlPainterMissingError` instead of reporting `onHtmlError` and continuing.
555
+ * DOM-routed html elements are never affected — a missing `renderHtml` stays
556
+ * a non-fatal `'unsupported'` diagnostic regardless of this flag.
557
+ */
558
+ strictMissingCanvasHtml?: boolean;
500
559
  }
501
560
  type ExportAssetErrorReason = 'load' | 'timeout' | 'encode';
502
561
  interface ExportAssetError {
@@ -522,9 +581,32 @@ interface ExportSvgOptions extends ExportResourceOptions, HtmlExportOptions {
522
581
  background?: string;
523
582
  filter?: (el: CanvasElement) => boolean;
524
583
  rasterScale?: number;
584
+ /** Registry of canvas-backed html painters, keyed by `htmlType`. When absent (or when
585
+ * an element's `htmlType` isn't claimed), html elements fall back to the legacy
586
+ * DOM-raster path (`renderHtml`). */
587
+ htmlPainters?: HtmlPainterRegistry;
588
+ /** `htmlType`s that must route to canvas even before a painter for them is
589
+ * registered — lets a host declare intent up front (mirrors `HtmlPainterRegistry.expect`). */
590
+ expectedCanvasTypes?: ReadonlySet<string>;
591
+ /**
592
+ * When true, a canvas-routed html element with no active painter throws
593
+ * `HtmlPainterMissingError` instead of reporting `onHtmlError` and continuing.
594
+ * DOM-routed html elements are never affected — a missing `renderHtml` stays
595
+ * a non-fatal `'unsupported'` diagnostic regardless of this flag.
596
+ */
597
+ strictMissingCanvasHtml?: boolean;
525
598
  }
526
599
  declare function exportSvg(store: ElementStore, options?: ExportSvgOptions, layerManager?: LayerManager): Promise<string>;
527
600
 
601
+ type HtmlRenderTarget = 'screen' | 'minimap' | 'export';
602
+ interface HtmlPaintDiagnostic {
603
+ kind: 'missing-painter' | 'painter-threw' | 'degenerate-size';
604
+ elementId: string;
605
+ htmlType?: string;
606
+ target: HtmlRenderTarget;
607
+ error?: unknown;
608
+ }
609
+
528
610
  interface RenderStatsSnapshot {
529
611
  fps: number;
530
612
  avgFrameMs: number;
@@ -575,6 +657,30 @@ interface GridInfo {
575
657
  cellRadius: number;
576
658
  }
577
659
 
660
+ interface ElementActivationEvent {
661
+ element: Readonly<CanvasElement>;
662
+ /** Pointerup location converted through the pointerup camera snapshot. */
663
+ world: Point;
664
+ /**
665
+ * Raw `PointerEvent.pointerType`. Usually `'mouse' | 'touch' | 'pen'`, but the
666
+ * spec permits vendor-defined and empty strings, so this is NOT narrowed and
667
+ * NOT normalised.
668
+ */
669
+ pointerType: string;
670
+ gesture: 'single' | 'double';
671
+ }
672
+ interface ActivationOptions {
673
+ gesture: 'single' | 'double';
674
+ /** Additional host filter, applied on top of the core canvas-routing gate. */
675
+ isActivatable?: (el: Readonly<CanvasElement>) => boolean;
676
+ /** Host-owned camera animators the viewport cannot see. */
677
+ isCameraBusy?: () => boolean;
678
+ /** Maximum pointer travel between down and up. Default `8` (PingInput parity). */
679
+ slopPx?: number;
680
+ /** Maximum gap between the halves of a double tap. Default `300`. */
681
+ doubleDelayMs?: number;
682
+ }
683
+
578
684
  interface ViewportOptions {
579
685
  camera?: CameraOptions;
580
686
  background?: BackgroundOptions;
@@ -643,6 +749,14 @@ declare class Viewport {
643
749
  private contextMenu;
644
750
  private minimap;
645
751
  private readonly htmlRenderers;
752
+ private readonly htmlPainters;
753
+ private readonly htmlDiagnosticListeners;
754
+ private readonly htmlDiagnostics;
755
+ private readonly resolveRouting;
756
+ private readonly unsubHtmlPainters;
757
+ private activation;
758
+ private activationGeneration;
759
+ private readonly activationListeners;
646
760
  private readonly resizeListeners;
647
761
  private readonly selectionListeners;
648
762
  private detachSelectionSource;
@@ -690,6 +804,15 @@ declare class Viewport {
690
804
  registerOverlay(draw: OverlayRenderer): () => void;
691
805
  exportState(): CanvasState;
692
806
  exportJSON(): string;
807
+ /**
808
+ * Injects this viewport's own html painter registry into export options so a host
809
+ * that registered painters via `registerHtmlPainter`/`expectCanvasHtmlTypes` gets
810
+ * markers in exports without passing anything. An explicitly passed `htmlPainters`
811
+ * REPLACES the viewport's registry rather than merging with it. `expectedCanvasTypes`
812
+ * is always UNIONED with the resolved registry's own declarations — a caller's set
813
+ * can only add expectations, never shrink the registry's own.
814
+ */
815
+ private withHtmlDefaults;
693
816
  exportImage(options?: ExportImageOptions): Promise<Blob | null>;
694
817
  exportSVG(options?: ExportSvgOptions): Promise<string>;
695
818
  loadState(state: CanvasState): void;
@@ -741,6 +864,74 @@ declare class Viewport {
741
864
  removeLayer(id: string): void;
742
865
  registerHtmlRenderer(htmlType: string, factory: (el: HtmlElement) => HTMLElement): void;
743
866
  updateHtmlElement(id: string, newContent: HTMLElement): void;
867
+ /**
868
+ * Declares htmlTypes that route to canvas painters even before a painter for
869
+ * them registers, so the element renderer never treats them as DOM-backed
870
+ * (avoiding a DOM-mount flash while a host is still loading its painter).
871
+ * Returns an idempotent release; each `expect` call is independently reference
872
+ * counted by the registry.
873
+ */
874
+ expectCanvasHtmlTypes(htmlTypes: Iterable<string>): () => void;
875
+ /**
876
+ * Direct access to the viewport's live html-painter registry — the same
877
+ * instance the viewport itself uses to route canvas-backed html elements.
878
+ * Beyond `register`/`expectCanvasHtmlTypes` (already exposed above), this
879
+ * hands out `getActivePainter`, `canvasTypes`, `onChange`, and `version`,
880
+ * so a surface such as the minimap that needs to read routing state or
881
+ * react to registry changes can do so without the viewport re-deriving or
882
+ * proxying each capability individually.
883
+ */
884
+ getHtmlPainters(): HtmlPainterRegistry;
885
+ /**
886
+ * Registers the canvas painter for `htmlType`. Later registrations for the
887
+ * same type shadow earlier ones (LIFO); unregistering restores the previous
888
+ * entry. Existing elements of this type reconcile synchronously — DOM nodes
889
+ * detach and the render loop repaints on the next frame.
890
+ */
891
+ registerHtmlPainter(htmlType: string, painter: HtmlPainter): () => void;
892
+ /**
893
+ * Subscribes to diagnostics emitted while painting canvas-routed html
894
+ * elements (missing painter, painter threw, degenerate size). Deduped per
895
+ * element/target/kind against the current registry and element versions, so
896
+ * a fail -> repair -> fail-again sequence reports twice rather than being
897
+ * suppressed forever. Returns an idempotent unsubscribe.
898
+ */
899
+ onHtmlPaintDiagnostic(listener: (d: HtmlPaintDiagnostic) => void): () => void;
900
+ /**
901
+ * Enables (or replaces, or with `null` disables) pointer activation of
902
+ * canvas-painted elements — the bridge for elements that are drawn rather than
903
+ * mounted and so cannot receive DOM events. **Default off**, so every existing
904
+ * consumer behaves identically.
905
+ *
906
+ * The controller is a passive observer: listeners are `{ passive: true }` and
907
+ * it never calls `preventDefault`, `stopPropagation`, or takes pointer capture.
908
+ * Changing or disabling activation resets all active and pending gestures.
909
+ * Throws `RangeError` for a non-finite/negative `slopPx` or a non-positive
910
+ * `doubleDelayMs`, leaving any existing activation untouched.
911
+ *
912
+ * The returned disposer clears **only its own generation**, so a stale
913
+ * Strict-Mode cleanup cannot tear down a newer registration.
914
+ */
915
+ setActivation(options: ActivationOptions | null): () => void;
916
+ /**
917
+ * Subscribes to element activations. Persistent and independent of
918
+ * `setActivation`: subscribing before activation is enabled, or across a
919
+ * replacement, keeps working. Emission iterates a snapshot with per-listener
920
+ * try/catch. Returns an idempotent unsubscribe.
921
+ */
922
+ onElementActivate(listener: (e: ElementActivationEvent) => void): () => void;
923
+ private emitActivation;
924
+ /**
925
+ * Fires whenever the html painter registry's active-painter set changes
926
+ * (declare, register, or their release). Reconciliation is synchronous —
927
+ * routing flips (and any DOM detach/remount) happen before this returns —
928
+ * while the actual repaint of newly canvas-routed elements is deferred to
929
+ * the next render frame via markAllLayersDirty + requestRender. Does NOT
930
+ * touch a minimap: Viewport does not own a MinimapController, and the
931
+ * built-in wrapper / React <Minimap /> each subscribe to the registry
932
+ * directly.
933
+ */
934
+ private onHtmlRegistryChanged;
744
935
  addGrid(input: {
745
936
  gridType?: 'square' | 'hex';
746
937
  hexOrientation?: 'pointy' | 'flat';
@@ -1368,6 +1559,7 @@ declare class MinimapController {
1368
1559
  private readonly requestFrame;
1369
1560
  private readonly cancelFrame;
1370
1561
  private readonly renderer;
1562
+ private readonly htmlPainters;
1371
1563
  private scene;
1372
1564
  private frameId;
1373
1565
  private debounceTimer;
@@ -1377,6 +1569,19 @@ declare class MinimapController {
1377
1569
  constructor(viewport: Viewport, canvas: HTMLCanvasElement, options?: MinimapControllerOptions);
1378
1570
  setSize(width: number, height: number): void;
1379
1571
  requestDraw(): void;
1572
+ /**
1573
+ * Invalidates the cached scene bitmap in response to html-painter registry
1574
+ * changes (a painter registering/unregistering, or an `expect` declaration
1575
+ * changing) and schedules the same debounced rebuild `markSceneDirty` uses
1576
+ * for every other invalidation source. Unlike those other sources — which
1577
+ * deliberately keep compositing the OLD bitmap until the rebuild lands, so
1578
+ * camera motion and content edits never stall on a render — painter
1579
+ * availability has no "old bitmap is still valid" reading: an element that
1580
+ * was falling back to a neutral fillRect (no painter yet) or a stale
1581
+ * painter's output is not a safe thing to keep showing, so the cached
1582
+ * bitmap is dropped immediately instead of composited a further time.
1583
+ */
1584
+ invalidateScene(): void;
1380
1585
  dispose(): void;
1381
1586
  private clearDebounce;
1382
1587
  private dpr;
@@ -1649,6 +1854,7 @@ interface HtmlInput extends BaseDefaults {
1649
1854
  interactive?: boolean;
1650
1855
  htmlType?: string;
1651
1856
  data?: Record<string, unknown>;
1857
+ rotation?: number;
1652
1858
  }
1653
1859
  interface TextInput extends BaseDefaults {
1654
1860
  position: Point;
@@ -1996,6 +2202,6 @@ declare class TemplateTool implements Tool {
1996
2202
  private notifyOptionsChange;
1997
2203
  }
1998
2204
 
1999
- declare const VERSION = "0.61.0";
2205
+ declare const VERSION = "0.62.0";
2000
2206
 
2001
- export { type ActiveFormats, type AlignEdge, type ArrowElement, type ArrowStrokeStyle, ArrowTool, type ArrowToolOptions, AutoSave, type AutoSaveOptions, type BackgroundOptions, type BackgroundPattern, type Binding, type Bounds, Camera, type CameraAnimationEndReason, CameraAnimator, type CameraAnimatorOptions, type CameraChangeInfo, type CameraOptions, type CameraView, type CanvasElement, type CanvasState, type Command, DEFAULT_NOTE_FONT_SIZE, type DistributeAxis, type ElementChangeMeta, ElementStore, type ElementStyle, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, type ExportAssetError, type ExportAssetErrorReason, type ExportImageOptions, type ExportResourceOptions, type ExportSvgOptions, FOCUS_PRESENCE_KIND, type FocusAudience, type FocusPresence, type FocusRole, type FontSizePreset, type FrameScheduler, type GridElement, type GridInfo, HandTool, type HexOrientation, HistoryStack, type HistoryStackOptions, type HtmlElement, type HtmlExportError, type HtmlExportErrorReason, type HtmlExportOptions, type HtmlExportRenderer, type ImageElement, ImageTool, type ImageToolOptions, IndexedDBAdapter, type IndexedDBAdapterOptions, LASER_TRAIL_PRESENCE_KIND, LaserTool, type LaserToolOptions, type LaserTrailEmission, type LaserTrailPresence, type Layer, LayerManager, LocalStorageAdapter, MEASURE_PRESENCE_KIND, type MeasureEmission, type MeasurePresence, MeasureTool, type MeasureToolOptions, type Measurement, MemoryAdapter, MinimapController, type MinimapControllerOptions, type NoteElement, NoteTool, type NoteToolOptions, type OverlayRenderer, PING_PRESENCE_KIND, PencilTool, type PencilToolOptions, type PingEmission, PingInput, type PingInputHost, type PingInputOptions, type PingPresence, PingTool, type PingToolOptions, type Point, type PointerState, RemoteFocusReceiver, type RemoteFocusReceiverHost, type RemoteFocusReceiverOptions, RemoteLaserOverlay, type RemoteLaserOverlayHost, type RemoteLaserOverlayOptions, RemoteMeasureOverlay, type RemoteMeasureOverlayHost, type RemoteMeasureOverlayOptions, RemotePingOverlay, type RemotePingOverlayHost, type RemotePingOverlayOptions, type RenderStatsSnapshot, type RotateDirection, SelectTool, type SelectionStyleDetails, type ShapeElement, type ShapeKind, ShapeTool, type ShapeToolOptions, type ShortcutBindings, type ShortcutOptions, type ShortcutsApi, type Size, type StorageAdapter, type StrokeElement, type StrokePoint, type TemplateElement, type TemplateRenderStyle, type TemplateShape, TemplateTool, type TemplateToolOptions, type TextElement, TextTool, type TextToolOptions, type Tool, type ToolContext, ToolManager, type ToolName, VERSION, Viewport, type ViewportOptions, applyCameraView, boundsIntersect, cameraOriginForView, captureCameraView, createArrow, createGrid, createHtmlElement, createImage, createNote, createShape, createStroke, createTemplate, createText, drawHexPath, exportImage, exportSvg, fitZoomForView, getActiveFormats, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, getElementBounds, getElementStyle, getElementsBoundingBox, getHexCellsInCone, getHexCellsInLine, getHexCellsInRadius, getHexCellsInRectangle, getHexCellsInSquare, getHexDistance, isFocusPresence, isLaserTrailPresence, isMeasurePresence, isNearBezier, isPingPresence, setFontSize, smartSnap, snapPoint, snapToHexCenter, styleToPatch, toFocusPresence, toLaserTrailPresence, toMeasurePresence, toPingPresence, toggleBold, toggleItalic, toggleStrikethrough, toggleUnderline };
2207
+ export { type ActivationOptions, type ActiveFormats, type AlignEdge, type ArrowElement, type ArrowStrokeStyle, ArrowTool, type ArrowToolOptions, AutoSave, type AutoSaveOptions, type BackgroundOptions, type BackgroundPattern, type Binding, type Bounds, Camera, type CameraAnimationEndReason, CameraAnimator, type CameraAnimatorOptions, type CameraChangeInfo, type CameraOptions, type CameraView, type CanvasElement, type CanvasState, type Command, DEFAULT_NOTE_FONT_SIZE, type DistributeAxis, type ElementActivationEvent, type ElementChangeMeta, ElementStore, type ElementStyle, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, type ExportAssetError, type ExportAssetErrorReason, type ExportImageOptions, type ExportResourceOptions, type ExportSvgOptions, FOCUS_PRESENCE_KIND, type FocusAudience, type FocusPresence, type FocusRole, type FontSizePreset, type FrameScheduler, type GridElement, type GridInfo, HandTool, type HexOrientation, HistoryStack, type HistoryStackOptions, type HtmlElement, type HtmlExportError, type HtmlExportErrorReason, type HtmlExportOptions, type HtmlExportRenderer, type HtmlPaintContext, type HtmlPaintDiagnostic, type HtmlPainter, HtmlPainterMissingError, HtmlPainterRegistry, type HtmlRenderTarget, type HtmlRouting, type ImageElement, ImageTool, type ImageToolOptions, IndexedDBAdapter, type IndexedDBAdapterOptions, LASER_TRAIL_PRESENCE_KIND, LaserTool, type LaserToolOptions, type LaserTrailEmission, type LaserTrailPresence, type Layer, LayerManager, LocalStorageAdapter, MEASURE_PRESENCE_KIND, type MeasureEmission, type MeasurePresence, MeasureTool, type MeasureToolOptions, type Measurement, MemoryAdapter, MinimapController, type MinimapControllerOptions, type NoteElement, NoteTool, type NoteToolOptions, type OverlayRenderer, PING_PRESENCE_KIND, PencilTool, type PencilToolOptions, type PingEmission, PingInput, type PingInputHost, type PingInputOptions, type PingPresence, PingTool, type PingToolOptions, type Point, type PointerState, RemoteFocusReceiver, type RemoteFocusReceiverHost, type RemoteFocusReceiverOptions, RemoteLaserOverlay, type RemoteLaserOverlayHost, type RemoteLaserOverlayOptions, RemoteMeasureOverlay, type RemoteMeasureOverlayHost, type RemoteMeasureOverlayOptions, RemotePingOverlay, type RemotePingOverlayHost, type RemotePingOverlayOptions, type RenderStatsSnapshot, type RotateDirection, SelectTool, type SelectionStyleDetails, type ShapeElement, type ShapeKind, ShapeTool, type ShapeToolOptions, type ShortcutBindings, type ShortcutOptions, type ShortcutsApi, type Size, type StorageAdapter, type StrokeElement, type StrokePoint, type TemplateElement, type TemplateRenderStyle, type TemplateShape, TemplateTool, type TemplateToolOptions, type TextElement, TextTool, type TextToolOptions, type Tool, type ToolContext, ToolManager, type ToolName, VERSION, Viewport, type ViewportOptions, applyCameraView, boundsIntersect, cameraOriginForView, captureCameraView, createArrow, createGrid, createHtmlElement, createImage, createNote, createShape, createStroke, createTemplate, createText, drawHexPath, exportImage, exportSvg, fitZoomForView, getActiveFormats, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, getElementBounds, getElementStyle, getElementsBoundingBox, getHexCellsInCone, getHexCellsInLine, getHexCellsInRadius, getHexCellsInRectangle, getHexCellsInSquare, getHexDistance, isFocusPresence, isLaserTrailPresence, isMeasurePresence, isNearBezier, isPingPresence, resolveHtmlRouting, setFontSize, smartSnap, snapPoint, snapToHexCenter, styleToPatch, toFocusPresence, toLaserTrailPresence, toMeasurePresence, toPingPresence, toggleBold, toggleItalic, toggleStrikethrough, toggleUnderline };