@web-canvas-ui/react 0.1.2 → 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 (165) hide show
  1. package/README.md +415 -205
  2. package/index.js +3660 -0
  3. package/package.json +36 -27
  4. package/types/canvas-handle.d.ts +22 -0
  5. package/types/components/Button/button.d.ts +22 -0
  6. package/types/components/Button/logic.d.ts +3 -0
  7. package/types/components/CanvasView/canvasView.d.ts +28 -0
  8. package/types/components/CanvasView/index.d.ts +2 -0
  9. package/types/components/Carousel/carousel.d.ts +31 -0
  10. package/types/components/Carousel/logic.d.ts +2 -0
  11. package/types/components/Checkbox/checkbox.d.ts +8 -0
  12. package/types/components/ChoiceGroup/choiceGroup.d.ts +38 -0
  13. package/{components/ChoiceGroup/index.ts → types/components/ChoiceGroup/index.d.ts} +1 -1
  14. package/types/components/ChoiceGroup/logic.d.ts +3 -0
  15. package/types/components/Circle/circle.d.ts +9 -0
  16. package/types/components/Collapse/collapse.d.ts +32 -0
  17. package/types/components/Collapse/logic.d.ts +1 -0
  18. package/types/components/CustomDraw/customDraw.d.ts +22 -0
  19. package/types/components/CustomDraw/index.d.ts +2 -0
  20. package/types/components/DatePicker/datePicker.d.ts +24 -0
  21. package/types/components/Dialog/dialog.d.ts +20 -0
  22. package/types/components/Dropdown/dropdown.d.ts +30 -0
  23. package/types/components/Dropdown/logic.d.ts +5 -0
  24. package/types/components/Form/form.d.ts +42 -0
  25. package/types/components/Form/index.d.ts +2 -0
  26. package/{components/Grid/grid.ts → types/components/Grid/grid.d.ts} +3 -4
  27. package/{components/GridItem/gridItem.ts → types/components/GridItem/gridItem.d.ts} +1 -4
  28. package/{components/Group/group.ts → types/components/Group/group.d.ts} +1 -4
  29. package/types/components/Icon/icon.d.ts +14 -0
  30. package/types/components/Image/image.d.ts +12 -0
  31. package/types/components/Input/input.d.ts +32 -0
  32. package/types/components/Progress/progress.d.ts +15 -0
  33. package/types/components/Radio/radio.d.ts +8 -0
  34. package/types/components/Rect/rect.d.ts +11 -0
  35. package/types/components/Slider/logic.d.ts +1 -0
  36. package/types/components/Slider/slider.d.ts +17 -0
  37. package/types/components/Switch/logic.d.ts +2 -0
  38. package/types/components/Switch/switch.d.ts +14 -0
  39. package/types/components/Tabs/logic.d.ts +2 -0
  40. package/types/components/Tabs/tabs.d.ts +35 -0
  41. package/types/components/Text/text.d.ts +39 -0
  42. package/types/components/Textarea/textarea.d.ts +10 -0
  43. package/types/components/Upload/index.d.ts +2 -0
  44. package/types/components/Upload/upload.d.ts +30 -0
  45. package/types/components/Video/index.d.ts +4 -0
  46. package/types/components/Video/logic.d.ts +56 -0
  47. package/types/components/Video/video.d.ts +54 -0
  48. package/types/components/draw-utils.d.ts +48 -0
  49. package/types/components/shared.d.ts +7 -0
  50. package/types/components/size.d.ts +6 -0
  51. package/{components/types.ts → types/components/types.d.ts} +5 -13
  52. package/types/engine/accessibility.d.ts +5 -0
  53. package/types/engine/carousel.d.ts +10 -0
  54. package/types/engine/events.d.ts +14 -0
  55. package/types/engine/forms.d.ts +21 -0
  56. package/types/engine/hit-test.d.ts +31 -0
  57. package/types/engine/images.d.ts +8 -0
  58. package/types/engine/interaction.d.ts +12 -0
  59. package/types/engine/layout.d.ts +6 -0
  60. package/types/engine/nodes.d.ts +19 -0
  61. package/types/engine/state.d.ts +91 -0
  62. package/types/engine/text-controls.d.ts +10 -0
  63. package/types/engine/transform.d.ts +13 -0
  64. package/types/engine/uploads.d.ts +5 -0
  65. package/types/engine/videos.d.ts +28 -0
  66. package/types/engine/vnodes.d.ts +36 -0
  67. package/types/engine.d.ts +38 -0
  68. package/types/image-assets.d.ts +2 -0
  69. package/types/input-bridge.d.ts +54 -0
  70. package/types/react/Canvas.d.ts +4 -0
  71. package/types/react/components.d.ts +31 -0
  72. package/types/react/index.d.ts +5 -0
  73. package/types/renderer.d.ts +20 -0
  74. package/types/scene.d.ts +15 -0
  75. package/{types.ts → types/types.d.ts} +48 -142
  76. package/types/video-assets.d.ts +28 -0
  77. package/Canvas.tsx +0 -142
  78. package/__tests__/pure-logic.test.ts +0 -153
  79. package/__tests__/scene-and-node.test.ts +0 -131
  80. package/__tests__/scratch-space.test.ts +0 -30
  81. package/__tests__/textarea-caret.test.ts +0 -96
  82. package/__tests__/utils.test.ts +0 -114
  83. package/canvas-handle.ts +0 -114
  84. package/components/Button/button.ts +0 -57
  85. package/components/Button/logic.ts +0 -11
  86. package/components/CanvasView/canvasView.ts +0 -103
  87. package/components/CanvasView/index.ts +0 -7
  88. package/components/Carousel/carousel.ts +0 -107
  89. package/components/Carousel/logic.ts +0 -36
  90. package/components/Checkbox/checkbox.ts +0 -14
  91. package/components/ChoiceGroup/choiceGroup.ts +0 -172
  92. package/components/ChoiceGroup/logic.ts +0 -14
  93. package/components/Circle/circle.ts +0 -31
  94. package/components/Collapse/collapse.ts +0 -69
  95. package/components/Collapse/logic.ts +0 -14
  96. package/components/CustomDraw/customDraw.ts +0 -50
  97. package/components/CustomDraw/index.ts +0 -7
  98. package/components/DatePicker/datePicker.ts +0 -70
  99. package/components/Dialog/dialog.ts +0 -102
  100. package/components/Dropdown/dropdown.ts +0 -125
  101. package/components/Dropdown/logic.ts +0 -29
  102. package/components/Icon/icon.ts +0 -669
  103. package/components/Image/image.ts +0 -69
  104. package/components/Input/input.ts +0 -139
  105. package/components/Progress/progress.ts +0 -59
  106. package/components/Radio/radio.ts +0 -14
  107. package/components/Rect/rect.ts +0 -35
  108. package/components/Slider/logic.ts +0 -19
  109. package/components/Slider/slider.ts +0 -58
  110. package/components/Switch/logic.ts +0 -8
  111. package/components/Switch/switch.ts +0 -37
  112. package/components/Tabs/logic.ts +0 -14
  113. package/components/Tabs/tabs.ts +0 -78
  114. package/components/Text/text.ts +0 -95
  115. package/components/Textarea/textarea.ts +0 -16
  116. package/components/Upload/index.ts +0 -2
  117. package/components/Upload/upload.ts +0 -66
  118. package/components/draw-utils.ts +0 -230
  119. package/components/shared.ts +0 -15
  120. package/components/size.ts +0 -20
  121. package/components.ts +0 -98
  122. package/engine/__tests__/carousel.test.ts +0 -218
  123. package/engine/__tests__/hit-test.test.ts +0 -282
  124. package/engine/__tests__/layout.test.ts +0 -474
  125. package/engine/carousel.ts +0 -150
  126. package/engine/events.ts +0 -73
  127. package/engine/hit-test.ts +0 -321
  128. package/engine/images.ts +0 -41
  129. package/engine/interaction.ts +0 -442
  130. package/engine/layout.ts +0 -355
  131. package/engine/nodes.ts +0 -166
  132. package/engine/state.ts +0 -75
  133. package/engine/text-controls.ts +0 -122
  134. package/engine/transform.ts +0 -61
  135. package/engine/vnodes.ts +0 -204
  136. package/engine.ts +0 -162
  137. package/image-assets.ts +0 -37
  138. package/index.ts +0 -78
  139. package/input-bridge.ts +0 -285
  140. package/renderer.ts +0 -303
  141. package/scene.ts +0 -122
  142. package/theme.scss +0 -234
  143. package/web-canvas-ui-react-0.1.1.tgz +0 -0
  144. /package/{components/Button/index.ts → types/components/Button/index.d.ts} +0 -0
  145. /package/{components/Carousel/index.ts → types/components/Carousel/index.d.ts} +0 -0
  146. /package/{components/Checkbox/index.ts → types/components/Checkbox/index.d.ts} +0 -0
  147. /package/{components/Circle/index.ts → types/components/Circle/index.d.ts} +0 -0
  148. /package/{components/Collapse/index.ts → types/components/Collapse/index.d.ts} +0 -0
  149. /package/{components/DatePicker/index.ts → types/components/DatePicker/index.d.ts} +0 -0
  150. /package/{components/Dialog/index.ts → types/components/Dialog/index.d.ts} +0 -0
  151. /package/{components/Dropdown/index.ts → types/components/Dropdown/index.d.ts} +0 -0
  152. /package/{components/Grid/index.ts → types/components/Grid/index.d.ts} +0 -0
  153. /package/{components/GridItem/index.ts → types/components/GridItem/index.d.ts} +0 -0
  154. /package/{components/Group/index.ts → types/components/Group/index.d.ts} +0 -0
  155. /package/{components/Icon/index.ts → types/components/Icon/index.d.ts} +0 -0
  156. /package/{components/Image/index.ts → types/components/Image/index.d.ts} +0 -0
  157. /package/{components/Input/index.ts → types/components/Input/index.d.ts} +0 -0
  158. /package/{components/Progress/index.ts → types/components/Progress/index.d.ts} +0 -0
  159. /package/{components/Radio/index.ts → types/components/Radio/index.d.ts} +0 -0
  160. /package/{components/Rect/index.ts → types/components/Rect/index.d.ts} +0 -0
  161. /package/{components/Slider/index.ts → types/components/Slider/index.d.ts} +0 -0
  162. /package/{components/Switch/index.ts → types/components/Switch/index.d.ts} +0 -0
  163. /package/{components/Tabs/index.ts → types/components/Tabs/index.d.ts} +0 -0
  164. /package/{components/Text/index.ts → types/components/Text/index.d.ts} +0 -0
  165. /package/{components/Textarea/index.ts → types/components/Textarea/index.d.ts} +0 -0
@@ -0,0 +1,2 @@
1
+ import type { SceneNode } from '../../scene';
2
+ export declare function tabKeyAt(items: readonly SceneNode[], x: number, y: number, width: number, headerHeight: number): string | undefined;
@@ -0,0 +1,35 @@
1
+ import type { TransformProps } from '../../types';
2
+ import type { ComponentSize } from '../size';
3
+ export interface TabsProps extends TransformProps {
4
+ width: number;
5
+ height: number;
6
+ activeKey?: string;
7
+ defaultActiveKey?: string;
8
+ headerHeight?: number;
9
+ backgroundColor?: string;
10
+ textColor?: string;
11
+ activeColor?: string;
12
+ indicatorColor?: string;
13
+ children?: unknown;
14
+ onChange?: (key: string) => void;
15
+ }
16
+ export interface TabItemProps extends TransformProps {
17
+ id: string;
18
+ title: string;
19
+ disabled?: boolean;
20
+ size?: ComponentSize;
21
+ children?: unknown;
22
+ }
23
+ export declare const Tabs: import("../shared").MarkedComponent<TabsProps>;
24
+ export declare const TabItem: import("../shared").MarkedComponent<TabItemProps>;
25
+ /** A tab header entry injected by the engine for the draw layer. */
26
+ export interface TabItemView {
27
+ title: string;
28
+ disabled?: boolean;
29
+ selected?: boolean;
30
+ }
31
+ /** Public props plus the engine-injected header model consumed by the draw layer. */
32
+ export type TabsDrawProps = TabsProps & {
33
+ _tabItems?: TabItemView[];
34
+ };
35
+ export declare function drawTabs(context: CanvasRenderingContext2D, props: TabsDrawProps): void;
@@ -0,0 +1,39 @@
1
+ import type { TransformProps } from '../../types';
2
+ export interface TextProps extends TransformProps {
3
+ text?: string;
4
+ children?: never;
5
+ fontSize?: number;
6
+ /** Wrap width. Falls back to the box the parent container hands down when unset. */
7
+ width?: number;
8
+ /**
9
+ * Maximum number of wrapped lines; the last one is cut with an ellipsis. Falls back to the number
10
+ * of lines that fit the container's box, and to "no limit" when neither is declared.
11
+ */
12
+ maxLines?: number;
13
+ fontFamily?: string;
14
+ color?: string;
15
+ baseline?: CanvasTextBaseline;
16
+ textAlign?: CanvasTextAlign;
17
+ onClick?: () => void;
18
+ }
19
+ export interface TextBox {
20
+ lines: string[];
21
+ width: number;
22
+ height: number;
23
+ }
24
+ /** Public props plus the content box a parent container hands down to this node. */
25
+ export type TextDrawProps = TextProps & {
26
+ _availableWidth?: number;
27
+ _availableHeight?: number;
28
+ };
29
+ export declare const Text: import("../shared").MarkedComponent<TextProps>;
30
+ /**
31
+ * Resolves `props` into the lines it renders and the box they occupy. {@link drawText} paints these
32
+ * lines and the layout pass sizes the node from the same result, so a Text node's reported height can
33
+ * never disagree with the glyphs it actually draws.
34
+ *
35
+ * A box handed down by the container is the fallback, not the override: declaring `width` or
36
+ * `maxLines` keeps the author in charge, so a node can stay narrower than its cell on purpose.
37
+ */
38
+ export declare function measureTextBox(props: TextDrawProps): TextBox;
39
+ export declare function drawText(context: CanvasRenderingContext2D, props: TextDrawProps): void;
@@ -0,0 +1,10 @@
1
+ import type { InputProps, InputDrawProps } from '../Input';
2
+ export interface TextareaProps extends Omit<InputProps, 'type'> {
3
+ rows?: number;
4
+ }
5
+ export declare const Textarea: import("../shared").MarkedComponent<TextareaProps>;
6
+ /** Public props plus the engine-injected caret/scroll state consumed by the draw layer. */
7
+ export type TextareaDrawProps = Omit<InputDrawProps, 'type'> & {
8
+ rows?: number;
9
+ };
10
+ export declare function drawTextarea(context: CanvasRenderingContext2D, props: TextareaDrawProps): void;
@@ -0,0 +1,2 @@
1
+ export { Upload, drawUpload, uploadHeight, UPLOAD_ROW_HEIGHT } from './upload';
2
+ export type { UploadProps, UploadRejection } from './upload';
@@ -0,0 +1,30 @@
1
+ import type { TransformProps } from '../../types';
2
+ import { type IconName } from '../Icon';
3
+ export interface UploadProps extends TransformProps {
4
+ width?: number;
5
+ height?: number;
6
+ text?: string;
7
+ icon?: IconName;
8
+ iconSize?: number;
9
+ accept?: string;
10
+ multiple?: boolean;
11
+ value?: File[];
12
+ defaultValue?: File[];
13
+ maxSize?: number;
14
+ disabled?: boolean;
15
+ backgroundColor?: string;
16
+ textColor?: string;
17
+ borderColor?: string;
18
+ borderRadius?: number;
19
+ fontSize?: number;
20
+ onChange?: (files: File[]) => void;
21
+ onReject?: (files: UploadRejection[]) => void;
22
+ }
23
+ export interface UploadRejection {
24
+ file: File;
25
+ reason: 'type' | 'size';
26
+ }
27
+ export declare const UPLOAD_ROW_HEIGHT = 28;
28
+ export declare function uploadHeight(props: Record<string, unknown>): number;
29
+ export declare const Upload: import("../shared").MarkedComponent<UploadProps>;
30
+ export declare function drawUpload(context: CanvasRenderingContext2D, props: UploadProps): void;
@@ -0,0 +1,4 @@
1
+ export { Video, drawVideo, applyVideoControl } from './video';
2
+ export { formatVideoTime, seekVideoTime, toggleVideoPlayback, videoControlsLayout, videoControlsRegion, videoSeekRatio, VIDEO_CONTROLS_FONT, } from './logic';
3
+ export type { VideoProps, VideoDrawProps } from './video';
4
+ export type { VideoControlsLayout } from './logic';
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Pure geometry and playback helpers for the `<Video>` controls bar. Drawing, hit testing and
3
+ * pointer handling all resolve the same rectangles from here, so what the user sees is exactly
4
+ * what the user clicks.
5
+ */
6
+ /** Font of the controls bar's time text; every pass that measures it must share this string so
7
+ * the text width (and therefore the seek track extent) is identical in draw and hit-test. */
8
+ export declare const VIDEO_CONTROLS_FONT = "11px sans-serif";
9
+ export interface VideoControlsLayout {
10
+ /** Bottom-aligned bar the controls sit on, in node-local coordinates. */
11
+ bar: {
12
+ y: number;
13
+ height: number;
14
+ };
15
+ /** Hit rectangle of the play/pause toggle. */
16
+ play: {
17
+ x: number;
18
+ y: number;
19
+ width: number;
20
+ height: number;
21
+ };
22
+ /** Fullscreen toggle at the right edge of the bar. */
23
+ fullscreen: {
24
+ x: number;
25
+ y: number;
26
+ width: number;
27
+ height: number;
28
+ };
29
+ /** Visual rectangle of the seek track; its x extent doubles as the seek hit range. */
30
+ track: {
31
+ x: number;
32
+ y: number;
33
+ width: number;
34
+ height: number;
35
+ };
36
+ }
37
+ /** Formats seconds as `M:SS`, growing to `H:MM:SS` once an hour is reached. */
38
+ export declare function formatVideoTime(seconds: number): string;
39
+ /**
40
+ * Layout of the controls bar for a `width` x `height` video, given the measured width of its
41
+ * time text. The bar height follows the video height between 24 and 32 pixels, and the track
42
+ * fills whatever the play toggle and the time text leave free.
43
+ */
44
+ export declare function videoControlsLayout(width: number, height: number, textWidth: number): VideoControlsLayout;
45
+ /** Which interactive controls region (if any) a node-local point lands on. */
46
+ export declare function videoControlsRegion(layout: VideoControlsLayout, x: number, y: number): 'play' | 'track' | 'fullscreen' | null;
47
+ /** Seek ratio (0..1) a node-local x maps to on the track. */
48
+ export declare function videoSeekRatio(layout: VideoControlsLayout, x: number): number;
49
+ /**
50
+ * Toggles playback of a dedicated element and reports the resulting state, mirroring how the
51
+ * declarative `paused` prop reads. `play()` rejects under autoplay policies; the rejection just
52
+ * leaves the element paused and is swallowed like in {@link applyVideoControl}.
53
+ */
54
+ export declare function toggleVideoPlayback(video: HTMLVideoElement, onPausedChange?: (paused: boolean) => void): void;
55
+ /** Seeks an element to `ratio` of its duration and reports the resulting time. */
56
+ export declare function seekVideoTime(video: HTMLVideoElement, ratio: number, onSeek?: (currentTime: number) => void, beforeSeek?: () => void): void;
@@ -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;
@@ -1,21 +1,12 @@
1
1
  export type { ButtonProps } from './Button';
2
- export type {
3
- CanvasViewFit,
4
- CanvasViewPointerEvent,
5
- CanvasViewPointerEventHandler,
6
- CanvasViewProps,
7
- } from './CanvasView';
2
+ export type { CanvasViewFit, CanvasViewPointerEvent, CanvasViewPointerEventHandler, CanvasViewProps, } from './CanvasView';
8
3
  export type { CarouselItemProps, CarouselProps } from './Carousel';
9
4
  export type { CheckboxProps } from './Checkbox';
5
+ export type { FormProps, FormItemProps, FormRule, FormValue, FormValues, FormErrors, FormController, } from './Form';
10
6
  export type { ChoiceGroupProps, ChoiceOption } from './ChoiceGroup';
11
7
  export type { CircleProps } from './Circle';
12
8
  export type { CollapseItemProps, CollapseProps } from './Collapse';
13
- export type {
14
- CustomDrawClickEvent,
15
- CustomDrawHitTest,
16
- CustomDrawProps,
17
- CustomDrawSize,
18
- } from './CustomDraw';
9
+ export type { CustomDrawClickEvent, CustomDrawHitTest, CustomDrawProps, CustomDrawSize, } from './CustomDraw';
19
10
  export type { DatePickerProps } from './DatePicker';
20
11
  export type { DialogProps } from './Dialog';
21
12
  export type { DropdownOption, DropdownProps } from './Dropdown';
@@ -33,5 +24,6 @@ export type { SwitchProps } from './Switch';
33
24
  export type { TabItemProps, TabsProps } from './Tabs';
34
25
  export type { TextProps } from './Text';
35
26
  export type { TextareaProps } from './Textarea';
36
- export type { UploadProps } from './Upload';
27
+ export type { UploadProps, UploadRejection } from './Upload';
28
+ export type { VideoProps } from './Video';
37
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;