@web-canvas-ui/angular 0.0.0-stage → 0.3.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 (99) hide show
  1. package/README.md +1198 -2
  2. package/index.js +5349 -0
  3. package/package.json +40 -5
  4. package/theme.css +327 -0
  5. package/types/angular/Canvas.d.ts +42 -0
  6. package/types/angular/index.d.ts +5 -0
  7. package/types/angular/node-directives.d.ts +367 -0
  8. package/types/canvas-handle.d.ts +22 -0
  9. package/types/components/Button/button.d.ts +22 -0
  10. package/types/components/Button/index.d.ts +3 -0
  11. package/types/components/Button/logic.d.ts +3 -0
  12. package/types/components/CanvasView/canvasView.d.ts +28 -0
  13. package/types/components/CanvasView/index.d.ts +2 -0
  14. package/types/components/Carousel/carousel.d.ts +31 -0
  15. package/types/components/Carousel/index.d.ts +3 -0
  16. package/types/components/Carousel/logic.d.ts +2 -0
  17. package/types/components/Checkbox/checkbox.d.ts +8 -0
  18. package/types/components/Checkbox/index.d.ts +2 -0
  19. package/types/components/ChoiceGroup/choiceGroup.d.ts +38 -0
  20. package/types/components/ChoiceGroup/index.d.ts +3 -0
  21. package/types/components/ChoiceGroup/logic.d.ts +3 -0
  22. package/types/components/Circle/circle.d.ts +9 -0
  23. package/types/components/Circle/index.d.ts +2 -0
  24. package/types/components/Collapse/collapse.d.ts +32 -0
  25. package/types/components/Collapse/index.d.ts +3 -0
  26. package/types/components/Collapse/logic.d.ts +1 -0
  27. package/types/components/CustomDraw/customDraw.d.ts +22 -0
  28. package/types/components/CustomDraw/index.d.ts +2 -0
  29. package/types/components/DatePicker/datePicker.d.ts +24 -0
  30. package/types/components/DatePicker/index.d.ts +2 -0
  31. package/types/components/Dialog/dialog.d.ts +20 -0
  32. package/types/components/Dialog/index.d.ts +2 -0
  33. package/types/components/Dropdown/dropdown.d.ts +30 -0
  34. package/types/components/Dropdown/index.d.ts +3 -0
  35. package/types/components/Dropdown/logic.d.ts +5 -0
  36. package/types/components/Form/form.d.ts +42 -0
  37. package/types/components/Form/index.d.ts +2 -0
  38. package/types/components/Grid/grid.d.ts +14 -0
  39. package/types/components/Grid/index.d.ts +2 -0
  40. package/types/components/GridItem/gridItem.d.ts +8 -0
  41. package/types/components/GridItem/index.d.ts +2 -0
  42. package/types/components/Group/group.d.ts +5 -0
  43. package/types/components/Group/index.d.ts +2 -0
  44. package/types/components/Icon/icon.d.ts +14 -0
  45. package/types/components/Icon/index.d.ts +2 -0
  46. package/types/components/Image/image.d.ts +12 -0
  47. package/types/components/Image/index.d.ts +2 -0
  48. package/types/components/Input/index.d.ts +2 -0
  49. package/types/components/Input/input.d.ts +32 -0
  50. package/types/components/Progress/index.d.ts +2 -0
  51. package/types/components/Progress/progress.d.ts +15 -0
  52. package/types/components/Radio/index.d.ts +2 -0
  53. package/types/components/Radio/radio.d.ts +8 -0
  54. package/types/components/Rect/index.d.ts +2 -0
  55. package/types/components/Rect/rect.d.ts +11 -0
  56. package/types/components/Slider/index.d.ts +3 -0
  57. package/types/components/Slider/logic.d.ts +1 -0
  58. package/types/components/Slider/slider.d.ts +17 -0
  59. package/types/components/Switch/index.d.ts +3 -0
  60. package/types/components/Switch/logic.d.ts +2 -0
  61. package/types/components/Switch/switch.d.ts +14 -0
  62. package/types/components/Tabs/index.d.ts +3 -0
  63. package/types/components/Tabs/logic.d.ts +2 -0
  64. package/types/components/Tabs/tabs.d.ts +35 -0
  65. package/types/components/Text/index.d.ts +2 -0
  66. package/types/components/Text/text.d.ts +39 -0
  67. package/types/components/Textarea/index.d.ts +2 -0
  68. package/types/components/Textarea/textarea.d.ts +10 -0
  69. package/types/components/Upload/index.d.ts +2 -0
  70. package/types/components/Upload/upload.d.ts +30 -0
  71. package/types/components/Video/index.d.ts +4 -0
  72. package/types/components/Video/logic.d.ts +56 -0
  73. package/types/components/Video/video.d.ts +54 -0
  74. package/types/components/draw-utils.d.ts +48 -0
  75. package/types/components/shared.d.ts +7 -0
  76. package/types/components/size.d.ts +6 -0
  77. package/types/components/types.d.ts +29 -0
  78. package/types/engine/accessibility.d.ts +5 -0
  79. package/types/engine/carousel.d.ts +10 -0
  80. package/types/engine/events.d.ts +14 -0
  81. package/types/engine/forms.d.ts +21 -0
  82. package/types/engine/hit-test.d.ts +31 -0
  83. package/types/engine/images.d.ts +8 -0
  84. package/types/engine/interaction.d.ts +12 -0
  85. package/types/engine/layout.d.ts +6 -0
  86. package/types/engine/nodes.d.ts +19 -0
  87. package/types/engine/state.d.ts +91 -0
  88. package/types/engine/text-controls.d.ts +10 -0
  89. package/types/engine/transform.d.ts +13 -0
  90. package/types/engine/uploads.d.ts +5 -0
  91. package/types/engine/videos.d.ts +28 -0
  92. package/types/engine/vnodes.d.ts +36 -0
  93. package/types/engine.d.ts +38 -0
  94. package/types/image-assets.d.ts +2 -0
  95. package/types/input-bridge.d.ts +54 -0
  96. package/types/renderer.d.ts +20 -0
  97. package/types/scene.d.ts +15 -0
  98. package/types/types.d.ts +162 -0
  99. package/types/video-assets.d.ts +28 -0
@@ -0,0 +1,54 @@
1
+ import type { TransformProps } from '../../types';
2
+ import { type MediaObjectFit } from '../draw-utils';
3
+ export interface VideoProps extends TransformProps {
4
+ src: string;
5
+ width?: number;
6
+ height?: number;
7
+ objectFit?: MediaObjectFit;
8
+ /** Start playback as soon as the frame draws; browsers still require `muted` for autoplay. */
9
+ autoplay?: boolean;
10
+ loop?: boolean;
11
+ muted?: boolean;
12
+ /** Declarative play/pause: `false` plays, `true` pauses; native fullscreen controls take precedence. */
13
+ paused?: boolean;
14
+ /** Seek target in seconds; set once, not every frame. Native fullscreen controls take precedence. */
15
+ currentTime?: number;
16
+ /** Shows playback, seek and fullscreen controls. */
17
+ controls?: boolean;
18
+ /** Show controls on hover, or after a tap on touch devices. */
19
+ controlsOnHover?: boolean;
20
+ /** Background of the controls bar. Default: a translucent dark scrim over the frames. */
21
+ controlsBarColor?: string;
22
+ /** Foreground of the controls bar: play/pause icon, played track, thumb and time text. */
23
+ controlsColor?: string;
24
+ /** Idle (not yet played) part of the seek track. */
25
+ controlsTrackColor?: string;
26
+ onError?: (error: Error) => void;
27
+ onTimeUpdate?: (currentTime: number, duration: number) => void;
28
+ /** Fires when the user toggles playback through the controls bar. */
29
+ onPausedChange?: (paused: boolean) => void;
30
+ /** Fires when the user seeks through the controls bar (press or drag on the track). */
31
+ onSeek?: (currentTime: number) => void;
32
+ }
33
+ export declare const Video: import("../shared").MarkedComponent<VideoProps>;
34
+ /**
35
+ * Scene-private draw prop injected by `syncVideos`: the node's dedicated element, so each
36
+ * `<Video>` paints (and is controlled) independently of other same-src nodes. Absent when
37
+ * `drawVideo` runs outside the engine, which then falls back to the shared src pool.
38
+ */
39
+ export interface VideoDrawProps extends VideoProps {
40
+ _videoElement?: HTMLVideoElement;
41
+ _videoFrame?: HTMLCanvasElement;
42
+ _videoControlsVisible?: boolean;
43
+ /** Pending seek ratio while the user drags the track: the bar previews this position and
44
+ * the element is only seeked once, on pointer release. Written by the engine's seek
45
+ * gesture handlers; absent outside a gesture. */
46
+ _videoScrubRatio?: number;
47
+ }
48
+ /**
49
+ * Applies the declarative playback control (`muted`/`loop`/`currentTime`/`paused`/`autoplay`)
50
+ * to the pooled element. Runs in the engine's per-frame advance pass — never in the draw path —
51
+ * so painting (including image export through `renderTo`) cannot mutate playback state.
52
+ */
53
+ export declare function applyVideoControl(video: HTMLVideoElement, props: VideoProps, beforeSeek?: () => void): void;
54
+ export declare function drawVideo(context: CanvasRenderingContext2D, props: VideoDrawProps): void;
@@ -0,0 +1,48 @@
1
+ export declare function number(value: unknown, fallback: number): number;
2
+ export declare function string(value: unknown, fallback: string): string;
3
+ /** Measures rendered text width; drawing passes a context, layout passes `measureTextWidth`. */
4
+ export type TextMeasurer = (text: string) => number;
5
+ /** Baseline-to-baseline multiplier, shared by Text drawing and the pass that sizes it. */
6
+ export declare const TEXT_LINE_HEIGHT = 1.2;
7
+ /**
8
+ * Wraps `text` into lines at most `width` wide, keeping at most `maxLines` of them; a clamped
9
+ * block ends with an ellipsis instead of silently losing the rest. `maxLines` <= 0 means "no
10
+ * limit"; any positive limit keeps at least one line. Callers supply the measurer so that drawing
11
+ * (live context) and layout ({@link measureTextWidth}) share one algorithm and therefore one result.
12
+ */
13
+ export declare function measureLines(measure: TextMeasurer, text: string, width: number, maxLines?: number): string[];
14
+ export declare function wrapText(context: CanvasRenderingContext2D, text: string, width: number): string[];
15
+ /**
16
+ * Truncates `text` with a trailing ellipsis so it fits within `maxWidth` for the
17
+ * context's current font. Display-only labels (buttons, tabs, dropdown rows…) use
18
+ * this to stay inside their box; editable controls clip instead.
19
+ */
20
+ export declare function fitText(context: CanvasRenderingContext2D, text: string, maxWidth: number): string;
21
+ /**
22
+ * Measures the rendered width of `text` for a given CSS `font` string using a
23
+ * shared offscreen context. Draw, hit-test and layout code must all go through
24
+ * this helper so their width calculations stay byte-for-byte identical.
25
+ * Falls back to a deterministic estimate when no canvas is available (SSR/tests).
26
+ */
27
+ export declare function measureTextWidth(text: string, font: string): number;
28
+ /** How a media source is fitted into its box; shared by the `<Image>` and `<Video>` draw paths. */
29
+ export type MediaObjectFit = 'contain' | 'cover' | 'fill' | 'none' | 'scale-down';
30
+ /**
31
+ * Draws a raster source (image or video frame) into the `width`x`height` box at the current
32
+ * origin under the CSS `objectFit` semantics, clipping to the box. Shared so `<Image>` and
33
+ * `<Video>` scale identically; the caller saves/restores the context around the clip.
34
+ */
35
+ export declare function drawFitMedia(context: CanvasRenderingContext2D, source: CanvasImageSource, sourceWidth: number, sourceHeight: number, width: number, height: number, fit: MediaObjectFit): void;
36
+ /**
37
+ * Width a classic vertical scrollbar occupies, 0 on platforms that float scrollbars over the
38
+ * content. Measured once from a throwaway scroller and cached, the same way the measurement context
39
+ * is; without a document (SSR, unit tests) there is nothing to reserve.
40
+ */
41
+ export declare function verticalScrollbarWidth(): number;
42
+ export declare function setThemeCanvasSource(canvas: HTMLCanvasElement, source: HTMLCanvasElement): void;
43
+ /**
44
+ * Drops every cached theme colour so the next read recomputes it. Call this whenever the theme can
45
+ * change (for example from a MutationObserver watching the canvas / ancestor `class` or `style`).
46
+ */
47
+ export declare function invalidateThemeColors(): void;
48
+ export declare function themeColor(context: CanvasRenderingContext2D, token: string, fallback: string): string;
@@ -0,0 +1,7 @@
1
+ import type { ComponentKind } from '../types';
2
+ export declare const kindSymbol: unique symbol;
3
+ export type MarkedComponent<Props = Record<string, unknown>> = ((props: Props) => null) & {
4
+ displayName?: string;
5
+ [kindSymbol]?: ComponentKind;
6
+ };
7
+ export declare function createComponent<Props>(kind: ComponentKind): MarkedComponent<Props>;
@@ -0,0 +1,6 @@
1
+ export interface ComponentSize {
2
+ width?: number;
3
+ height?: number;
4
+ }
5
+ export declare function componentWidth(props: Record<string, unknown>, fallback: number): number;
6
+ export declare function componentHeight(props: Record<string, unknown>, fallback: number): number;
@@ -0,0 +1,29 @@
1
+ export type { ButtonProps } from './Button';
2
+ export type { CanvasViewFit, CanvasViewPointerEvent, CanvasViewPointerEventHandler, CanvasViewProps, } from './CanvasView';
3
+ export type { CarouselItemProps, CarouselProps } from './Carousel';
4
+ export type { CheckboxProps } from './Checkbox';
5
+ export type { FormProps, FormItemProps, FormRule, FormValue, FormValues, FormErrors, FormController, } from './Form';
6
+ export type { ChoiceGroupProps, ChoiceOption } from './ChoiceGroup';
7
+ export type { CircleProps } from './Circle';
8
+ export type { CollapseItemProps, CollapseProps } from './Collapse';
9
+ export type { CustomDrawClickEvent, CustomDrawHitTest, CustomDrawProps, CustomDrawSize, } from './CustomDraw';
10
+ export type { DatePickerProps } from './DatePicker';
11
+ export type { DialogProps } from './Dialog';
12
+ export type { DropdownOption, DropdownProps } from './Dropdown';
13
+ export type { GridItemProps } from './GridItem';
14
+ export type { GridProps } from './Grid';
15
+ export type { GroupProps } from './Group';
16
+ export type { ImageProps } from './Image';
17
+ export type { IconName, IconProps, IconVariant } from './Icon';
18
+ export type { InputProps } from './Input';
19
+ export type { ProgressProps } from './Progress';
20
+ export type { RadioProps } from './Radio';
21
+ export type { RectProps } from './Rect';
22
+ export type { SliderProps } from './Slider';
23
+ export type { SwitchProps } from './Switch';
24
+ export type { TabItemProps, TabsProps } from './Tabs';
25
+ export type { TextProps } from './Text';
26
+ export type { TextareaProps } from './Textarea';
27
+ export type { UploadProps, UploadRejection } from './Upload';
28
+ export type { VideoProps } from './Video';
29
+ export type { ComponentSize } from './size';
@@ -0,0 +1,5 @@
1
+ import type { SceneNode } from '../scene';
2
+ import type { AccessibilitySnapshot } from '../types';
3
+ import type { EngineCore } from './state';
4
+ export declare function accessibilityId(node: SceneNode): string;
5
+ export declare function accessibilitySnapshot(core: EngineCore, changed: () => void): AccessibilitySnapshot;
@@ -0,0 +1,10 @@
1
+ import type { SceneNode } from '../scene';
2
+ import type { CarouselTransition, EngineCore, EngineState } from './state';
3
+ /**
4
+ * The carousel state machine: autoplay timing, index transitions and the
5
+ * per-frame easing that slides items. Driven by {@link advanceCarousels} from the
6
+ * render loop and {@link changeCarousel} from pointer interaction.
7
+ */
8
+ export declare function transitionProgress(transition: CarouselTransition, time: number): number;
9
+ export declare function changeCarousel(core: EngineCore, state: EngineState, node: SceneNode, requestedIndex: number): void;
10
+ export declare function advanceCarousels(core: EngineCore, state: EngineState, time: number): boolean;
@@ -0,0 +1,14 @@
1
+ import type { SceneNode } from '../scene';
2
+ import type { CanvasPointerEvent } from '../types';
3
+ import type { CanvasViewPointerEvent } from '../components/CanvasView';
4
+ import type { HitResult } from './hit-test';
5
+ import type { EngineCore } from './state';
6
+ /**
7
+ * Translates resolved pointer geometry into the public {@link CanvasUIEvent}
8
+ * stream and the per-node `canvasView` pointer callbacks.
9
+ */
10
+ export declare function emitPointerEvent(core: EngineCore, type: 'pointerdown' | 'pointermove' | 'pointerup' | 'pointercancel', event: CanvasPointerEvent, hit: HitResult | null, point: {
11
+ x: number;
12
+ y: number;
13
+ }): void;
14
+ export declare function emitCanvasViewPointerEvent(type: CanvasViewPointerEvent['type'], node: SceneNode, x: number, y: number, event: CanvasPointerEvent): void;
@@ -0,0 +1,21 @@
1
+ import type { FormController, FormErrors, FormRule, FormValue, FormValues } from '../components/Form';
2
+ import { type FormBinding } from '../components/Form/form';
3
+ import type { VNode } from '../types';
4
+ import type { EngineCore, EngineState } from './state';
5
+ export interface FormState {
6
+ values: FormValues;
7
+ errors: FormErrors;
8
+ attempted: boolean;
9
+ revision: number;
10
+ submission: number;
11
+ resetVersion: number;
12
+ validationEpoch: number;
13
+ fieldValidations: Map<string, number>;
14
+ controller?: FormController;
15
+ attachedController?: FormController;
16
+ binding?: FormBinding;
17
+ }
18
+ export declare function disposeForm(form: FormState): void;
19
+ export declare function attachForm(form: FormState): void;
20
+ export declare function validateFormField(value: FormValue, rules: FormRule[], values: Readonly<FormValues>): string | undefined | Promise<string | undefined>;
21
+ export declare function prepareForm(core: EngineCore, state: EngineState, vnode: VNode, path: string): VNode[];
@@ -0,0 +1,31 @@
1
+ import type { SceneNode } from '../scene';
2
+ import type { EngineCore } from './state';
3
+ /**
4
+ * Geometry: resolve client (viewport) coordinates to canvas / node-local space and
5
+ * determine which interactive node, if any, is under a pointer, honouring modal
6
+ * dialogs and grid/carousel clipping. Pure apart from reading the live scene graph.
7
+ */
8
+ export interface HitResult {
9
+ node: SceneNode;
10
+ x: number;
11
+ y: number;
12
+ }
13
+ export declare function canvasPoint(core: EngineCore, canvas: HTMLCanvasElement, clientX: number, clientY: number): {
14
+ x: number;
15
+ y: number;
16
+ } | null;
17
+ export declare function localPoint(core: EngineCore, canvas: HTMLCanvasElement, clientX: number, clientY: number, target: SceneNode): {
18
+ x: number;
19
+ y: number;
20
+ } | null;
21
+ export declare function isWithinClip(core: EngineCore, canvas: HTMLCanvasElement, clientX: number, clientY: number, node: SceneNode): boolean;
22
+ export declare function findHit(core: EngineCore, canvas: HTMLCanvasElement, clientX: number, clientY: number): HitResult | null;
23
+ export declare function findCarouselControlHit(core: EngineCore, canvas: HTMLCanvasElement, clientX: number, clientY: number): {
24
+ node: SceneNode;
25
+ index: number;
26
+ } | null;
27
+ export declare function findGridScrollbarHit(core: EngineCore, canvas: HTMLCanvasElement, clientX: number, clientY: number): {
28
+ node: SceneNode;
29
+ pointerY: number;
30
+ scrollTop: number;
31
+ } | null;
@@ -0,0 +1,8 @@
1
+ import type { VNode } from '../types';
2
+ import type { EngineCore, EngineState } from './state';
3
+ /**
4
+ * Subscribes the engine to the shared image cache for every `image` source in the
5
+ * tree, tearing down subscriptions for sources that disappear. Load errors mark the
6
+ * scene dirty and forward to each image node's `onError` callback.
7
+ */
8
+ export declare function syncImages(core: EngineCore, state: EngineState, tree: VNode[]): void;
@@ -0,0 +1,12 @@
1
+ import type { CanvasPointerEvent, CanvasWheelEvent } from '../types';
2
+ import type { EngineCore, EngineState } from './state';
3
+ /**
4
+ * Turns raw pointer/wheel events into state mutations on the scene graph: routes a
5
+ * press to the correct component, drives sliders, buttons, tabs, collapses, dropdowns,
6
+ * dialogs and grid scrolling, and emits the public event stream.
7
+ */
8
+ export declare function pointerDown(core: EngineCore, state: EngineState, event: CanvasPointerEvent): void;
9
+ export declare function pointerMove(core: EngineCore, state: EngineState, event: CanvasPointerEvent): void;
10
+ export declare function pointerUp(core: EngineCore, state: EngineState, event: CanvasPointerEvent, cancelled?: boolean): void;
11
+ export declare function pointerLeave(state: EngineState, pointerType: string): void;
12
+ export declare function wheel(core: EngineCore, state: EngineState, event: CanvasWheelEvent): void;
@@ -0,0 +1,6 @@
1
+ import type { SceneNode } from '../scene';
2
+ import { type Transform, type VNode } from '../types';
3
+ import type { EngineCore, EngineState, TextControlDescription } from './state';
4
+ export declare function activeCollapseKeys(state: EngineState, stateKey: string, props: Record<string, unknown>): Set<string>;
5
+ export declare function layoutCollapseNodes(parent: SceneNode, active: Set<string>): void;
6
+ export declare function prepare(core: EngineCore, state: EngineState, vnodes: VNode[], parentTransform: Transform, parentVisible: boolean, parentPath: string, descriptions: TextControlDescription[]): VNode[];
@@ -0,0 +1,19 @@
1
+ import type { SceneNode } from '../scene';
2
+ import type { CanvasUIEventTarget, InputLayout } from '../types';
3
+ /**
4
+ * Pure predicates and derived getters over a {@link SceneNode} subtree.
5
+ * None of these read engine-level mutable state — they only inspect nodes.
6
+ */
7
+ export declare function hasVisibleAncestors(node: SceneNode): boolean;
8
+ export declare function activeDialog(root: SceneNode): SceneNode | null;
9
+ export declare function eventTarget(node: SceneNode): CanvasUIEventTarget;
10
+ export declare function isCanvasElement(value: unknown): value is HTMLCanvasElement;
11
+ export declare function isInteractive(type: string): boolean;
12
+ export declare function isDescendantOf(node: SceneNode, ancestor: SceneNode): boolean;
13
+ export declare function setTreeVisibility(node: SceneNode, visible: boolean): void;
14
+ export declare function controlSize(node: SceneNode): {
15
+ width: number;
16
+ height: number;
17
+ };
18
+ export declare function isTextControlVisible(node: SceneNode, layout: InputLayout, modal?: SceneNode | null): boolean;
19
+ export declare function textControlLayout(node: SceneNode, layout: InputLayout, modal: SceneNode | null): InputLayout;
@@ -0,0 +1,91 @@
1
+ import type { SceneNode } from '../scene';
2
+ import type { CanvasRenderer } from '../renderer';
3
+ import type { CanvasUIEvent, InputLayout, TextControlProps, WebInputBridge } from '../types';
4
+ import type { ManagedVideo } from '../video-assets';
5
+ import type { VirtualGridLayout } from './vnodes';
6
+ import type { FormState } from './forms';
7
+ /** A text input/date/textarea currently mirrored into the DOM overlay bridge. */
8
+ export interface MountedTextControl {
9
+ node: SceneNode;
10
+ dispose: () => void;
11
+ layout: InputLayout;
12
+ }
13
+ /** A text control discovered during the `prepare` pass, awaiting sync. */
14
+ export interface TextControlDescription {
15
+ id: string;
16
+ props: TextControlProps;
17
+ layout: InputLayout;
18
+ }
19
+ export interface CarouselTransition {
20
+ from: number;
21
+ to: number;
22
+ direction: -1 | 1;
23
+ startedAt: number;
24
+ duration: number;
25
+ }
26
+ export interface PointerSequence {
27
+ target: SceneNode | null;
28
+ x: number;
29
+ y: number;
30
+ eligible: boolean;
31
+ }
32
+ export interface GridScrollGesture {
33
+ node: SceneNode;
34
+ pointerY: number;
35
+ scrollTop: number;
36
+ }
37
+ /** Per-video-node tracker of the last observed playback position, for dirty scheduling. */
38
+ export interface VideoFrameTracker {
39
+ src: string;
40
+ time: number;
41
+ playing: boolean;
42
+ }
43
+ /**
44
+ * Immutable services and configuration shared by every engine behaviour module:
45
+ * the scene graph, renderer, canvas context, DOM input bridge and callbacks.
46
+ * {@link CanvasEngine} owns exactly one of these for its lifetime.
47
+ */
48
+ export interface EngineCore {
49
+ readonly scene: SceneNode;
50
+ readonly renderer: CanvasRenderer;
51
+ readonly context: CanvasRenderingContext2D;
52
+ readonly inputBridge: WebInputBridge;
53
+ readonly pixelRatio: number;
54
+ readonly onFrame?: (time: number) => void;
55
+ readonly onEvent?: (event: CanvasUIEvent) => void;
56
+ readonly refreshVirtualGrids: () => void;
57
+ }
58
+ /**
59
+ * All engine-mutable state that survives across frames and pointer events.
60
+ * Extracted from the former {@link CanvasEngine} private fields so behaviour
61
+ * modules can operate on it explicitly instead of via a God-class `this`.
62
+ */
63
+ export declare class EngineState {
64
+ readonly textControls: Map<string, MountedTextControl>;
65
+ readonly inputValues: Map<string, string>;
66
+ readonly imageSubscriptions: Map<string, () => void>;
67
+ /** Dedicated video element per scene node, so same-src nodes stay independently controllable. */
68
+ readonly videoElements: Map<SceneNode, ManagedVideo>;
69
+ readonly videoFrames: Map<SceneNode, VideoFrameTracker>;
70
+ /** Video nodes with a usable `src`, collected by the last `syncVideos` pass, so the
71
+ * per-frame advance loop walks this cache instead of traversing the whole scene. */
72
+ readonly videoNodes: SceneNode[];
73
+ readonly tabSelections: Map<string, string>;
74
+ readonly carouselSelections: Map<string, number>;
75
+ readonly carouselFrameTimes: Map<string, number>;
76
+ readonly carouselTransitions: Map<string, CarouselTransition>;
77
+ readonly collapseSelections: Map<string, Set<string>>;
78
+ readonly gridScrollPositions: Map<string, number>;
79
+ readonly virtualGridLayouts: Map<string, VirtualGridLayout>;
80
+ readonly activeVirtualGridKeys: Set<string>;
81
+ readonly forms: Map<string, FormState>;
82
+ readonly activeFormKeys: Set<string>;
83
+ readonly pointerSequences: Map<number, PointerSequence>;
84
+ activeSlider: SceneNode | null;
85
+ activeButton: SceneNode | null;
86
+ activeGridScroll: GridScrollGesture | null;
87
+ /** The video node whose seek track is being scrubbed, mirroring the slider drag gesture. */
88
+ activeVideo: SceneNode | null;
89
+ hoveredVideo: SceneNode | null;
90
+ currentFrameTime: number;
91
+ }
@@ -0,0 +1,10 @@
1
+ import type { SceneNode } from '../scene';
2
+ import type { EngineCore, EngineState, TextControlDescription } from './state';
3
+ /**
4
+ * Keeps the off-canvas DOM input overlay (text inputs / textareas / date pickers)
5
+ * in sync with the scene graph: mount/update/teardown bridges and push value,
6
+ * focus and scroll state back into the corresponding {@link SceneNode}s.
7
+ */
8
+ export declare function syncTextControls(core: EngineCore, state: EngineState, descriptions: TextControlDescription[]): void;
9
+ export declare function updateTextControlVisibility(core: EngineCore, state: EngineState): void;
10
+ export declare function removeTextControls(state: EngineState, node: SceneNode): void;
@@ -0,0 +1,13 @@
1
+ import type { SceneNode } from '../scene';
2
+ import type { Transform } from '../types';
3
+ /**
4
+ * Pure 2D affine-transform math shared by hit-testing, layout and input routing.
5
+ * A transform is the `[a, b, c, d, e, f]` matrix tuple used by the Canvas API.
6
+ */
7
+ export declare function multiplyTransform(parent: Transform, props: Record<string, unknown>): Transform;
8
+ export declare function invertPoint(x: number, y: number, transform: Transform): {
9
+ x: number;
10
+ y: number;
11
+ } | null;
12
+ /** Accumulated world transform of a node from the scene root down to it. */
13
+ export declare function nodeTransform(node: SceneNode): Transform;
@@ -0,0 +1,5 @@
1
+ import type { SceneNode } from '../scene';
2
+ import type { EngineCore } from './state';
3
+ export declare function chooseUploadFiles(node: SceneNode, core: EngineCore): void;
4
+ export declare function removeUploadFile(node: SceneNode, core: EngineCore, index: number): void;
5
+ export declare function uploadRowAt(node: SceneNode, x: number, y: number): number | undefined;
@@ -0,0 +1,28 @@
1
+ import type { ManagedVideo } from '../video-assets';
2
+ import type { SceneNode } from '../scene';
3
+ import type { EngineCore, EngineState } from './state';
4
+ export declare function enterVideoFullscreen(managed: ManagedVideo, node: SceneNode): void;
5
+ /**
6
+ * Rebuilds the cached list of `video` scene nodes and gives every node a dedicated
7
+ * `<video>` element, tearing down (and unloading) elements for nodes that leave the scene or
8
+ * switch `src`. Each element reports load errors and `timeupdate` directly to its own node's
9
+ * callbacks, and is injected as the `_videoElement` draw prop so the draw path paints the node's
10
+ * element — same-src nodes therefore never share playback state.
11
+ *
12
+ * <p>Called from `reconcile()` after the scene children synced, so the cache stays accurate:
13
+ * nodes only enter or leave the scene during a reconcile, which always runs this pass.</p>
14
+ */
15
+ export declare function syncVideos(core: EngineCore, state: EngineState): void;
16
+ /**
17
+ * Keeps the scene dirty exactly while a video advances: a drawn frame is worth one repaint,
18
+ * so a new frame (or a video that just started playing) dirties the scene once. Paused, ended
19
+ * and hidden videos cost nothing, and the loop survives seeks and playback-rate changes
20
+ * because it watches `currentTime` rather than a paused flag.
21
+ *
22
+ * <p>Walks the node list cached by {@link syncVideos} instead of traversing the scene, so this
23
+ * per-frame pass costs O(video nodes) rather than O(scene nodes); recycling of trackers for
24
+ * removed nodes also happens once per reconcile instead of once per frame. Each node's
25
+ * declarative playback control is applied to its own dedicated element here — the draw path
26
+ * (including image export via `renderTo`) never mutates playback state.</p>
27
+ */
28
+ export declare function advanceVideos(core: EngineCore, state: EngineState): void;
@@ -0,0 +1,36 @@
1
+ import type { VNode } from '../types';
2
+ import type { CarouselTransition } from './state';
3
+ export interface VirtualGridLayout {
4
+ token: unknown;
5
+ width: number;
6
+ contentHeight: number;
7
+ entries: {
8
+ child: VNode;
9
+ index: number;
10
+ top: number;
11
+ bottom: number;
12
+ maxBottom: number;
13
+ }[];
14
+ }
15
+ export declare function createVirtualGridLayout(vnode: VNode): VirtualGridLayout;
16
+ export declare function visibleGridChildren(layout: VirtualGridLayout, scrollTop: number, height: number, overscan: number): VNode[];
17
+ /**
18
+ * Pure helpers that rewrite a VNode tree during the `prepare` normalization pass,
19
+ * plus metrics used by grid scrolling. They never touch engine state.
20
+ */
21
+ export declare function layoutGridChildren(vnode: VNode): {
22
+ children: VNode[];
23
+ contentHeight: number;
24
+ width: number;
25
+ };
26
+ export declare function translateChildren(children: VNode[], offsetX: number, offsetY: number): VNode[];
27
+ export declare function setVNodeVisibility(children: VNode[], parentVisible: boolean): VNode[];
28
+ export declare function carouselItemOffset(index: number, transition: CarouselTransition | undefined | null, progress: number, width: number): number;
29
+ export declare function gridScrollbarMetrics(props: Record<string, unknown>): {
30
+ width: number;
31
+ height: number;
32
+ maxScroll: number;
33
+ thumbHeight: number;
34
+ trackX: number;
35
+ thumbY: number;
36
+ };
@@ -0,0 +1,38 @@
1
+ import { SceneNode } from './scene';
2
+ import { CanvasRenderer } from './renderer';
3
+ import type { CanvasPointerEvent, CanvasUIEvent, CanvasWheelEvent, VNode, WebInputBridge } from './types';
4
+ /**
5
+ * Public entry point of the canvas rendering engine.
6
+ *
7
+ * <p>{@code CanvasEngine} is intentionally a thin orchestrator: it owns the
8
+ * {@link EngineCore} services and the {@link EngineState} container, wires them into
9
+ * a render loop, and delegates every concrete behaviour to a cohesive module under
10
+ * {@code ./engine} (layout normalization, hit-testing, interaction, carousel,
11
+ * text controls, images, videos, events). The public surface is unchanged from when this
12
+ * was a single God class.</p>
13
+ */
14
+ export declare class CanvasEngine {
15
+ readonly scene: SceneNode;
16
+ readonly renderer: CanvasRenderer;
17
+ private readonly state;
18
+ private readonly context;
19
+ private readonly core;
20
+ private animationFrame;
21
+ private themeObserver;
22
+ private running;
23
+ private tree;
24
+ constructor(context: CanvasRenderingContext2D, inputBridge: WebInputBridge, onFrame?: (time: number) => void, pixelRatio?: number, onEvent?: (event: CanvasUIEvent) => void);
25
+ update(tree: VNode[]): void;
26
+ private reconcile;
27
+ render(): void;
28
+ private syncAccessibility;
29
+ requestRender(): void;
30
+ renderTo(context: CanvasRenderingContext2D, scaleX: number, scaleY: number): void;
31
+ start(): void;
32
+ pointerDown(event: CanvasPointerEvent): void;
33
+ pointerMove(event: CanvasPointerEvent): void;
34
+ pointerLeave(pointerType: string): void;
35
+ pointerUp(event: CanvasPointerEvent, cancelled?: boolean): void;
36
+ wheel(event: CanvasWheelEvent): void;
37
+ destroy(): void;
38
+ }
@@ -0,0 +1,2 @@
1
+ export declare function getCanvasImage(src: string): HTMLImageElement | null;
2
+ export declare function subscribeCanvasImage(src: string, listener: (error: Error | null) => void): () => void;
@@ -0,0 +1,54 @@
1
+ import type { AccessibilitySnapshot, InputEvents, InputLayout, TextControlProps, WebInputBridge as WebInputBridgeContract } from './types';
2
+ /**
3
+ * The CSS that makes the transparent element lay its text out where the Canvas drawing puts it: same
4
+ * font metrics, same horizontal inset. Left to the browser default font, a click is converted into a
5
+ * character index for one layout while the caret is painted for another, so the caret lands on the
6
+ * wrong glyph (and typing looks one character behind). Pure so it can be checked without a DOM.
7
+ */
8
+ export declare function overlayTextStyle(props: TextControlProps, multiline: boolean): Record<string, string>;
9
+ export declare class WebInputBridge implements WebInputBridgeContract {
10
+ private readonly mounted;
11
+ private readonly accessible;
12
+ private readonly errors;
13
+ private readonly fileInputs;
14
+ private readonly originalDisplay;
15
+ private overlayHidden;
16
+ private selectionTracked;
17
+ private readonly overlay;
18
+ private dialogElement;
19
+ private dialogId;
20
+ private returnFocus;
21
+ private returnFocusId;
22
+ private dialogCancel;
23
+ constructor(overlay: HTMLElement);
24
+ mount(id: string, props: TextControlProps, layout: InputLayout, events: InputEvents): () => void;
25
+ update(id: string, props: TextControlProps, layout: InputLayout): void;
26
+ pickFiles(accept: string | undefined, multiple: boolean, onChange: (files: File[]) => void): void;
27
+ focus(id: string): void;
28
+ setOverlayVisible(visible: boolean): void;
29
+ prepareAccessibility(dialogId: string | undefined): void;
30
+ syncAccessibility(snapshot: AccessibilitySnapshot): void;
31
+ private updateAccessible;
32
+ private setError;
33
+ private removeError;
34
+ private dialogFocusable;
35
+ private readonly handleDialogKey;
36
+ private unmount;
37
+ destroy(): void;
38
+ private find;
39
+ private readonly handleInput;
40
+ private readonly handleSelection;
41
+ /**
42
+ * `select` only fires when a range is created, so the interactions that just move the caret —
43
+ * clicking into the text, arrow keys, Home/End — report nothing, and the drawn caret stays pinned
44
+ * to wherever the last edit left it. `selectionchange` is the event that actually tracks the
45
+ * caret; it is document-scoped, hence one shared listener refcounted over the mounted controls
46
+ * (re-adding the same callback would be a no-op, and unmounting one must not stop the others).
47
+ */
48
+ private trackSelections;
49
+ private untrackSelections;
50
+ private readonly handleSelectionChange;
51
+ private readonly handleFocus;
52
+ private readonly handleBlur;
53
+ private readonly handleTextareaScroll;
54
+ }
@@ -0,0 +1,20 @@
1
+ import { SceneNode } from './scene';
2
+ export declare class CanvasRenderer {
3
+ private gridCaches;
4
+ private cacheEnabled;
5
+ invalidateGridCache(): void;
6
+ render(context: CanvasRenderingContext2D, root: SceneNode, cacheEnabled?: boolean): void;
7
+ /**
8
+ * Runs a single node's draw function behind a save/restore pair and a try/catch so that a
9
+ * throwing draw (an `<Icon>` with an unknown name, a `<CustomDraw>`/`<CanvasView>` with invalid
10
+ * props, or a faulty user draw callback) only skips that one node instead of aborting the whole
11
+ * frame. The save/restore also contains any partial context mutation the draw made before it
12
+ * threw, so sibling nodes and later overlays still render from a clean state.
13
+ */
14
+ private safeDraw;
15
+ private drawNode;
16
+ private drawGrid;
17
+ private drawCachedGrid;
18
+ private drawDialogs;
19
+ private drawDropdownOverlays;
20
+ }
@@ -0,0 +1,15 @@
1
+ import type { ComponentKind, VNode } from './types';
2
+ export declare class SceneNode {
3
+ readonly children: SceneNode[];
4
+ parent: SceneNode | null;
5
+ dirty: boolean;
6
+ readonly type: ComponentKind | 'root';
7
+ props: Record<string, unknown>;
8
+ constructor(type: ComponentKind | 'root', props?: Record<string, unknown>);
9
+ setProps(props: Record<string, unknown>): void;
10
+ replaceProps(props: Record<string, unknown>): void;
11
+ markDirty(): void;
12
+ syncChildren(vnodes: VNode[], onRemove: (node: SceneNode) => void): void;
13
+ traverse(visitor: (node: SceneNode) => void): void;
14
+ }
15
+ export declare function descriptorKey(vnode: VNode, index: number, parentPath: string): string;