@web-canvas-ui/react 0.0.0-stage → 0.1.2

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 (98) hide show
  1. package/Canvas.tsx +142 -0
  2. package/README.md +988 -2
  3. package/__tests__/pure-logic.test.ts +153 -0
  4. package/__tests__/scene-and-node.test.ts +131 -0
  5. package/__tests__/scratch-space.test.ts +30 -0
  6. package/__tests__/textarea-caret.test.ts +96 -0
  7. package/__tests__/utils.test.ts +114 -0
  8. package/canvas-handle.ts +114 -0
  9. package/components/Button/button.ts +57 -0
  10. package/components/Button/index.ts +3 -0
  11. package/components/Button/logic.ts +11 -0
  12. package/components/CanvasView/canvasView.ts +103 -0
  13. package/components/CanvasView/index.ts +7 -0
  14. package/components/Carousel/carousel.ts +107 -0
  15. package/components/Carousel/index.ts +3 -0
  16. package/components/Carousel/logic.ts +36 -0
  17. package/components/Checkbox/checkbox.ts +14 -0
  18. package/components/Checkbox/index.ts +2 -0
  19. package/components/ChoiceGroup/choiceGroup.ts +172 -0
  20. package/components/ChoiceGroup/index.ts +3 -0
  21. package/components/ChoiceGroup/logic.ts +14 -0
  22. package/components/Circle/circle.ts +31 -0
  23. package/components/Circle/index.ts +2 -0
  24. package/components/Collapse/collapse.ts +69 -0
  25. package/components/Collapse/index.ts +3 -0
  26. package/components/Collapse/logic.ts +14 -0
  27. package/components/CustomDraw/customDraw.ts +50 -0
  28. package/components/CustomDraw/index.ts +7 -0
  29. package/components/DatePicker/datePicker.ts +70 -0
  30. package/components/DatePicker/index.ts +2 -0
  31. package/components/Dialog/dialog.ts +102 -0
  32. package/components/Dialog/index.ts +2 -0
  33. package/components/Dropdown/dropdown.ts +125 -0
  34. package/components/Dropdown/index.ts +3 -0
  35. package/components/Dropdown/logic.ts +29 -0
  36. package/components/Grid/grid.ts +15 -0
  37. package/components/Grid/index.ts +2 -0
  38. package/components/GridItem/gridItem.ts +11 -0
  39. package/components/GridItem/index.ts +2 -0
  40. package/components/Group/group.ts +8 -0
  41. package/components/Group/index.ts +2 -0
  42. package/components/Icon/icon.ts +669 -0
  43. package/components/Icon/index.ts +2 -0
  44. package/components/Image/image.ts +69 -0
  45. package/components/Image/index.ts +2 -0
  46. package/components/Input/index.ts +2 -0
  47. package/components/Input/input.ts +139 -0
  48. package/components/Progress/index.ts +2 -0
  49. package/components/Progress/progress.ts +59 -0
  50. package/components/Radio/index.ts +2 -0
  51. package/components/Radio/radio.ts +14 -0
  52. package/components/Rect/index.ts +2 -0
  53. package/components/Rect/rect.ts +35 -0
  54. package/components/Slider/index.ts +3 -0
  55. package/components/Slider/logic.ts +19 -0
  56. package/components/Slider/slider.ts +58 -0
  57. package/components/Switch/index.ts +3 -0
  58. package/components/Switch/logic.ts +8 -0
  59. package/components/Switch/switch.ts +37 -0
  60. package/components/Tabs/index.ts +3 -0
  61. package/components/Tabs/logic.ts +14 -0
  62. package/components/Tabs/tabs.ts +78 -0
  63. package/components/Text/index.ts +2 -0
  64. package/components/Text/text.ts +95 -0
  65. package/components/Textarea/index.ts +2 -0
  66. package/components/Textarea/textarea.ts +16 -0
  67. package/components/Upload/index.ts +2 -0
  68. package/components/Upload/upload.ts +66 -0
  69. package/components/draw-utils.ts +230 -0
  70. package/components/shared.ts +15 -0
  71. package/components/size.ts +20 -0
  72. package/components/types.ts +37 -0
  73. package/components.ts +98 -0
  74. package/engine/__tests__/carousel.test.ts +218 -0
  75. package/engine/__tests__/hit-test.test.ts +282 -0
  76. package/engine/__tests__/layout.test.ts +474 -0
  77. package/engine/carousel.ts +150 -0
  78. package/engine/events.ts +73 -0
  79. package/engine/hit-test.ts +321 -0
  80. package/engine/images.ts +41 -0
  81. package/engine/interaction.ts +442 -0
  82. package/engine/layout.ts +355 -0
  83. package/engine/nodes.ts +166 -0
  84. package/engine/state.ts +75 -0
  85. package/engine/text-controls.ts +122 -0
  86. package/engine/transform.ts +61 -0
  87. package/engine/vnodes.ts +204 -0
  88. package/engine.ts +162 -0
  89. package/image-assets.ts +37 -0
  90. package/index.ts +78 -0
  91. package/input-bridge.ts +285 -0
  92. package/package.json +27 -4
  93. package/renderer.ts +303 -0
  94. package/scene.ts +122 -0
  95. package/theme.css +327 -0
  96. package/theme.scss +234 -0
  97. package/types.ts +256 -0
  98. package/web-canvas-ui-react-0.1.1.tgz +0 -0
package/README.md CHANGED
@@ -1,3 +1,989 @@
1
- # Temporary Holding Version
1
+ <div align="center">
2
+ <img src="./src/assets/web-canvas-ui-logo-bright.svg" alt="Project Logo" />
3
+ </div>
2
4
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
5
+ # Web Canvas UI (React, Vue 3, Svelte, Angular)
6
+
7
+ [English](./README.md) · [日本語](./README.ja.md) · [한국어](./README.ko.md) · [繁體中文](./README.zh-TW.md) · [Русский](./README.ru.md) · [简体中文](./README.zh-CN.md)
8
+
9
+ A declarative component library built on Canvas 2D, with **React**, **Vue 3**, **Svelte 5+**, and **Angular 17+** adapters. Each framework imports from its own entry and uses native component/template syntax, while the underlying Canvas engine and control drawing logic are shared. Every control's appearance is painted by Canvas itself.
10
+
11
+ > **Adapters:** React, Vue, Svelte, and Angular import from `@web-canvas-ui/react`, `@web-canvas-ui/vue`, `@web-canvas-ui/svelte`, and `@web-canvas-ui/angular` respectively. Pick the entry that matches your host Canvas framework and do not mix components across adapters — they all reuse the same engine and control drawing implementation.
12
+
13
+ > **Shared component contract:** Each control lives under `components/<Component>/`. The `components.ts` entry exposes the public API, `<component>.ts` defines the Props type and the Canvas draw function, and `logic.ts` (when needed) holds interaction/business logic specific to that control. Common types are aggregated in `components/types.ts` and re-exported through `web-canvas-ui/types.ts`. React, Vue, Svelte, and Angular adapters share this type contract.
14
+
15
+ ### Packages
16
+ - [web-canvas-ui](https://www.npmjs.com/package/web-canvas-ui)
17
+
18
+ ## Global Theme Colors
19
+
20
+ Theme colors are centralized in [`theme.scss`](src/canvas-ui/theme.scss) as `$primary: #1668dc`. Changing this single variable updates the accent color for buttons, selected states, focus borders, progress bars, and more. Light variants are mixed with white, and pressed variants darken the primary; the shared scales are also emitted as `--canvas-ui-primary*` CSS variables. `theme.css` is a build artifact — import it as global CSS and do not edit the generated file directly:
21
+
22
+ ```css
23
+ @import 'web-canvas-ui/theme.css';
24
+ ```
25
+
26
+ After editing `theme.scss`, run `npm run build:theme` to regenerate the CSS. The compiled CSS custom properties apply to React, Vue, Svelte, and Angular, and provide `.dark` and `[data-theme="dark"]` dark themes. Colors passed explicitly to a component take precedence over theme variables.
27
+
28
+ Five built-in primary palettes are provided: blue, green, purple, orange, and red. Add the corresponding class to the outer Canvas container to switch palettes; they also combine with the dark theme:
29
+
30
+ ```tsx
31
+ <div className="theme-green">
32
+ <Canvas width={400} height={240}>
33
+ <Button>Green theme</Button>
34
+ </Canvas>
35
+ </div>
36
+ <p>--OR--</p>
37
+ <Canvas width={400} height={240} className="theme-green">
38
+ <Button>Green theme</Button>
39
+ </Canvas>
40
+ ```
41
+
42
+ | Palette | class | Primary |
43
+ | -------------- | -------------- | --------- |
44
+ | Blue (default) | `theme-blue` | `#1668dc` |
45
+ | Green | `theme-green` | `#389e0d` |
46
+ | Purple | `theme-purple` | `#722ed1` |
47
+ | Orange | `theme-orange` | `#d46b08` |
48
+ | Red | `theme-red` | `#cf1322` |
49
+
50
+ For example, adding both `dark` and `theme-purple` — or `data-theme="dark"` and `theme-purple` — enables the purple dark theme. In every palette, the light / pressed / dark accent variants are derived from the corresponding primary color by Sass.
51
+
52
+ | Component | CSS custom properties |
53
+ | ----------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
54
+ | Button / Upload | `--canvas-ui-button-background`, `--canvas-ui-button-color`, `--canvas-ui-button-border`, `--canvas-ui-button-pressed-background` |
55
+ | Carousel | `--canvas-ui-carousel-arrow`, `--canvas-ui-carousel-dot`, `--canvas-ui-carousel-active-dot` |
56
+ | Radio / Checkbox | `--canvas-ui-choice-active`, `--canvas-ui-choice-border`, `--canvas-ui-choice-color`, `--canvas-ui-choice-disabled`, `--canvas-ui-choice-disabled-background` |
57
+ | Collapse | `--canvas-ui-collapse-header-background`, `--canvas-ui-collapse-border`, `--canvas-ui-collapse-color`, `--canvas-ui-collapse-disabled-color` |
58
+ | Dialog | `--canvas-ui-dialog-mask`, `--canvas-ui-dialog-background`, `--canvas-ui-dialog-title-color`, `--canvas-ui-dialog-border`, `--canvas-ui-dialog-confirm-background`, `--canvas-ui-dialog-cancel-background`, `--canvas-ui-dialog-confirm-color`, `--canvas-ui-dialog-cancel-color` |
59
+ | Dropdown | `--canvas-ui-dropdown-background`, `--canvas-ui-dropdown-color`, `--canvas-ui-dropdown-placeholder-color`, `--canvas-ui-dropdown-border`, `--canvas-ui-dropdown-focus-border`, `--canvas-ui-dropdown-option-background`, `--canvas-ui-dropdown-option-border`, `--canvas-ui-dropdown-disabled-color` |
60
+ | Input / Textarea / DatePicker | `--canvas-ui-input-background`, `--canvas-ui-input-color`, `--canvas-ui-input-placeholder-color`, `--canvas-ui-input-border`, `--canvas-ui-input-focus-border` |
61
+ | Progress | `--canvas-ui-progress-track`, `--canvas-ui-progress-active`, `--canvas-ui-progress-text` |
62
+ | Rect / Circle / Text / Icon | `--canvas-ui-rect-background`, `--canvas-ui-rect-border`, `--canvas-ui-circle-background`, `--canvas-ui-circle-border`, `--canvas-ui-text-color`, `--canvas-ui-icon-color` |
63
+ | Slider | `--canvas-ui-slider-track`, `--canvas-ui-slider-active`, `--canvas-ui-slider-thumb` |
64
+ | Switch | `--canvas-ui-switch-on`, `--canvas-ui-switch-off`, `--canvas-ui-switch-thumb` |
65
+ | Tabs | `--canvas-ui-tabs-background`, `--canvas-ui-tabs-color`, `--canvas-ui-tabs-active-color`, `--canvas-ui-tabs-indicator`, `--canvas-ui-tabs-disabled-color` |
66
+
67
+ To customize the theme for a specific application, override only the variables you need in your own CSS, e.g. `.brand { --canvas-ui-button-background: #6d4aff; }`. The table above lists every theme variable each component actually reads.
68
+
69
+ ## Environment and Imports
70
+
71
+ Place the `web-canvas-ui` directory into your project and make sure the host Canvas project is already configured for the chosen framework: React 19+, Vue 3, Svelte 5+, or Angular 17+. Vue uses single-file component templates and does not require a JSX plugin or `jsxImportSource`. Svelte projects need the Svelte compiler and its matching build plugin. Angular projects need `@angular/core` and the Angular build setup. Framework dependencies are provided by the host Canvas project — this directory does not enforce dependencies on any particular framework.
72
+
73
+ ```
74
+ npm install web-canvas-ui
75
+ ```
76
+ OR
77
+ ```
78
+ npm install @web-canvas-ui/react
79
+
80
+ npm install @web-canvas-ui/vue
81
+
82
+ npm install @web-canvas-ui/svelte
83
+
84
+ npm install @web-canvas-ui/angular
85
+ ```
86
+
87
+ | Framework | Entry |
88
+ | ----------- |-------------------------|
89
+ | React | `web-canvas-ui/react \ @web-canvas-ui/react` |
90
+ | Vue 3 | `web-canvas-ui/vue \ @web-canvas-ui/vue` |
91
+ | Svelte 5+ | `web-canvas-ui/svelte \ @web-canvas-ui/svelte` |
92
+ | Angular 17+ | `web-canvas-ui/angular \ @web-canvas-ui/angular` |
93
+
94
+ Components must be placed inside the corresponding adapter's Canvas container and use the scene components exported by that framework's entry. Do not place plain DOM elements inside a Canvas scene.
95
+
96
+ ## Quick Start (React)
97
+
98
+ ```tsx
99
+ import { useRef, useState } from 'react';
100
+ import { Canvas, Group, Rect, Text, Input, Button } from '@web-canvas-ui/react';
101
+ import type { CanvasHandle } from '@web-canvas-ui/react';
102
+ import './theme.css';
103
+
104
+ export function ProfileCanvas() {
105
+ const [name, setName] = useState('');
106
+ const canvasRef = useRef<CanvasHandle>(null);
107
+
108
+ const exportPng = () => {
109
+ const dataUrl = canvasRef.current?.toDataURL({
110
+ type: 'image/png',
111
+ pixelRatio: 2,
112
+ });
113
+ if (!dataUrl) return;
114
+
115
+ const link = document.createElement('a');
116
+ link.href = dataUrl;
117
+ link.download = 'profile.png';
118
+ link.click();
119
+ };
120
+
121
+ return (
122
+ <section>
123
+ <Canvas ref={canvasRef} width={420} height={220}>
124
+ <Group x={24} y={24}>
125
+ <Rect width={340} height={170} color="#f5f8fc" radius={12} />
126
+ <Text x={16} y={16} fontSize={20} color="#222">
127
+ Profile
128
+ </Text>
129
+ <Input
130
+ x={16}
131
+ y={54}
132
+ width={280}
133
+ height={38}
134
+ value={name}
135
+ placeholder="Your name"
136
+ onChange={setName}
137
+ />
138
+ <Text x={16} y={108} width={280} fontSize={16}>
139
+ {name ? `Hello, ${name}` : 'Type your name'}
140
+ </Text>
141
+ <Button
142
+ x={16}
143
+ y={136}
144
+ width={120}
145
+ height={36}
146
+ backgroundColor="#3478f6"
147
+ fontColor="#fff"
148
+ onClick={exportPng}
149
+ >
150
+ Export Image
151
+ </Button>
152
+ </Group>
153
+ </Canvas>
154
+ </section>
155
+ );
156
+ }
157
+ ```
158
+
159
+ `x` and `y` are the component's position relative to its parent, in Canvas logical pixels. `Group` can be nested; child coordinates accumulate the parent's position, scale, and rotation.
160
+
161
+ ## Quick Start (Vue 3 Single-File Component)
162
+
163
+ The Vue adapter lives at the dedicated `web-canvas-ui/vue` entry. Nest Canvas UI components directly in a `.vue` template — no TSX, no JSX plugin, no manual Canvas node arrays:
164
+
165
+ ```vue
166
+ <script setup lang="ts">
167
+ import { ref } from 'vue';
168
+ import { Canvas, Group, Rect, Text, Input, Button } from '@web-canvas-ui/vue';
169
+ import type { CanvasHandle } from '@web-canvas-ui/vue';
170
+ import './theme.css';
171
+
172
+ const name = ref('');
173
+ const canvasRef = ref<CanvasHandle | null>(null);
174
+
175
+ function exportPng() {
176
+ const dataUrl = canvasRef.value?.toDataURL({
177
+ type: 'image/png',
178
+ pixelRatio: 2,
179
+ });
180
+ if (!dataUrl) return;
181
+
182
+ const link = document.createElement('a');
183
+ link.href = dataUrl;
184
+ link.download = 'profile.png';
185
+ link.click();
186
+ }
187
+ </script>
188
+
189
+ <template>
190
+ <Canvas ref="canvasRef" :width="420" :height="220">
191
+ <Group :x="24" :y="24">
192
+ <Rect :width="340" :height="170" color="#f5f8fc" :radius="12" />
193
+ <Text :x="16" :y="16" :font-size="20">Vue 3 Canvas</Text>
194
+ <Input
195
+ :x="16"
196
+ :y="54"
197
+ :width="280"
198
+ :height="38"
199
+ :value="name"
200
+ placeholder="Your name"
201
+ @change="name = $event"
202
+ />
203
+ <Text :x="16" :y="104" :width="280">
204
+ {{ name ? `Hello, ${name}` : 'Type your name' }}
205
+ </Text>
206
+ <Button :x="16" :y="142" :width="120" :height="36" @click="exportPng">
207
+ Export Image
208
+ </Button>
209
+ </Group>
210
+ </Canvas>
211
+ </template>
212
+ ```
213
+
214
+ In the Vue template, bind reactive state with `:value` and update it via `@change`; Canvas components sync the scene after Vue updates.
215
+
216
+ ## Quick Start (Svelte 5+)
217
+
218
+ Use the Svelte entry's components inside a Svelte 5 template. `Canvas` exposes imperative methods through `bind:this`:
219
+
220
+ ```svelte
221
+ <script lang="ts">
222
+ import { Canvas, Group, Rect, Text, Input, Button } from '@web-canvas-ui/svelte';
223
+ import type { CanvasHandle } from '@web-canvas-ui/svelte';
224
+ import './theme.css';
225
+
226
+ let name = $state('');
227
+ let canvas = $state<CanvasHandle>();
228
+
229
+ function exportPng() {
230
+ const dataUrl = canvas?.toDataURL({ type: 'image/png', pixelRatio: 2 });
231
+ if (!dataUrl) return;
232
+ const link = document.createElement('a');
233
+ link.href = dataUrl;
234
+ link.download = 'profile.png';
235
+ link.click();
236
+ }
237
+ </script>
238
+
239
+ <Canvas bind:this={canvas} width={420} height={180}>
240
+ <Group x={16} y={16}>
241
+ <Rect width={340} height={140} color="#f5f8fc" radius={12} />
242
+ <Text x={16} y={16} text="Svelte Canvas" />
243
+ <Input
244
+ x={16}
245
+ y={48}
246
+ value={name}
247
+ placeholder="Your name"
248
+ onChange={(value) => name = value}
249
+ />
250
+ <Text x={16} y={92} text={name ? `Hello, ${name}` : 'Type your name'} />
251
+ <Button x={220} y={48} text="Export" onClick={exportPng} />
252
+ </Group>
253
+ </Canvas>
254
+ ```
255
+
256
+ Changes to Svelte control props are synced to the Canvas scene;
257
+
258
+ ## Quick Start (Angular 17+)
259
+
260
+ The Angular entry provides a standalone `Canvas` component and scene directives. Import the required symbols in whichever standalone component uses them:
261
+
262
+ ```ts
263
+ import { Component, ViewChild } from '@angular/core';
264
+ import { Button, Canvas, Group, Input, Rect, Text } from '@web-canvas-ui/angular';
265
+ import './theme.css';
266
+
267
+ @Component({
268
+ selector: 'profile-canvas',
269
+ standalone: true,
270
+ imports: [Canvas, Group, Rect, Text, Input, Button],
271
+ template: `
272
+ <canvas-ui #canvas="canvasUi" [width]="420" [height]="180">
273
+ <canvas-group [x]="16" [y]="16">
274
+ <canvas-rect
275
+ [width]="340"
276
+ [height]="140"
277
+ color="#f5f8fc"
278
+ [radius]="12"
279
+ ></canvas-rect>
280
+ <canvas-text [x]="16" [y]="16" text="Angular Canvas"></canvas-text>
281
+ <canvas-input
282
+ [x]="16"
283
+ [y]="48"
284
+ [value]="name"
285
+ placeholder="Your name"
286
+ (valueChange)="name = $event"
287
+ ></canvas-input>
288
+ <canvas-text
289
+ [x]="16"
290
+ [y]="92"
291
+ [text]="name ? 'Hello, ' + name : 'Type your name'"
292
+ ></canvas-text>
293
+ <canvas-button
294
+ [x]="220"
295
+ [y]="48"
296
+ text="Export"
297
+ (click)="exportPng()"
298
+ ></canvas-button>
299
+ </canvas-group>
300
+ </canvas-ui>
301
+ `,
302
+ })
303
+ export class ProfileCanvas {
304
+ name = '';
305
+ @ViewChild('canvas') canvas?: Canvas;
306
+
307
+ exportPng() {
308
+ const dataUrl = this.canvas?.toDataURL({ type: 'image/png', pixelRatio: 2 });
309
+ if (!dataUrl) return;
310
+ const link = document.createElement('a');
311
+ link.href = dataUrl;
312
+ link.download = 'profile.png';
313
+ link.click();
314
+ }
315
+ }
316
+ ```
317
+
318
+ Angular uses `<canvas-...>` directive selectors to declare Canvas scene nodes. Inputs, dropdowns, and sliders emit through `(valueChange)`, switches through `(checkedChange)`, and buttons through `(click)`.
319
+
320
+ Interaction props follow each framework's convention: React uses `onChange`/`onClick` props, Vue uses `@change`/`@click`, Svelte uses `onChange`/`onClick` callback props, and Angular uses `(valueChange)`, `(checkedChange)`, and `(click)` output bindings.
321
+
322
+ ## Common Props
323
+
324
+ Every visible component except `<Canvas>` supports the following transform props:
325
+
326
+ | Prop | Type | Default | Description |
327
+ | ---------- | --------- | ------: | -------------------------------------------------------------------------------------------------------- |
328
+ | `x` | `number` | `0` | Horizontal position relative to the parent. |
329
+ | `y` | `number` | `0` | Vertical position relative to the parent. |
330
+ | `rotation` | `number` | `0` | Rotation in radians. |
331
+ | `scaleX` | `number` | `1` | Horizontal transform scale. |
332
+ | `scaleY` | `number` | `1` | Vertical transform scale. |
333
+ | `visible` | `boolean` | `true` | Whether the component is drawn; when `false`, its children are also hidden and do not respond to clicks. |
334
+
335
+ ### Sizing Rules
336
+
337
+ - `Rect`, `Input`, `Textarea`, `Upload`, `Dropdown`, `DatePicker`, `Slider`, `Switch`, and `Button` use `width` and `height` to set their size.
338
+ - `Circle` uses `radius` (default `10`); the diameter is twice the radius.
339
+ - `Text` uses `fontSize` for the type size and `width` for the wrap width.
340
+ - When `width`/`height` are omitted, each component falls back to the default listed in its documentation. `Group` is a container and has no intrinsic width or height; `Grid` lays out based on column count and cell props.
341
+ - `Grid` arranges children in order; specify `columns`, `cellHeight`, and an optional `gap`. Cell width can be fixed via `cellWidth` or distributed evenly via `width`. Direct children occupy one cell by default; `GridItem` groups multiple controls and sets col/row spans — sizes of children inside a group remain governed by their own props.
342
+
343
+ ## Component Props
344
+
345
+ ### `<Canvas>`
346
+
347
+ Creates a Canvas scene. Sizes are in logical pixels; the underlying bitmap is multiplied by the pixel ratio.
348
+
349
+ | Prop | Type | Required | Default | Description |
350
+ | -------------------------------------------------- | -------------------------------------------------------------------------------- | -------: | ----------------------------------------------------------------------: | ------------------------------------------------------------------------------------------------------------------------------------- |
351
+ | `width` | `number` | Yes | — | Logical Canvas width. |
352
+ | `height` | `number` | Yes | — | Logical Canvas height. |
353
+ | Pixel ratio | Automatic | — | Reads `window.devicePixelRatio` with a floor of `1`; no prop is needed. | Canvas rendering resolution ratio. |
354
+ | `className` (React/Angular) / `class` (Vue/Svelte) | `string` | No | — | CSS class for the outer container. |
355
+ | `style` | Framework-specific style object or string | No | — | Style for the outer container; `position`, `width`, and `height` are managed by the component. |
356
+ | `ariaLabel` | `string` | No | `"Canvas"` | Accessibility label for the Canvas element. |
357
+ | `onFrame` | `(time: number) => void` | No | — | Per-frame callback; `time` is the browser animation-frame timestamp. |
358
+ | `onEvent` | `(event: CanvasUIEvent) => void` | No | — | Unified event entry point for the Canvas, receiving `pointerdown`, `pointermove`, `pointerup`, `pointercancel`, `click`, and `wheel`. |
359
+ | Children | React children / Vue default slot / Svelte children / Angular content projection | No | — | Canvas UI component tree. |
360
+
361
+ `onEvent` payloads include the Canvas logical coordinates `x`/`y`, the hit `target` (the component's `type` and user `key`; `null` on empty space), and the hit component's local coordinates `localX`/`localY`. `wheel` events additionally expose `deltaY`, and pointer events expose `pointerId`. The unified `click` fires only when the same target is pressed and released with movement no greater than 8 logical pixels; drags or cancellations do not emit `click`. Existing per-component callbacks such as `onClick` and `onChange` still run as usual; `onEvent` is best suited for cross-component logic or unified analytics.
362
+
363
+ ```tsx
364
+ <Canvas
365
+ width={420}
366
+ height={220}
367
+ onEvent={(event) => {
368
+ if (event.type === 'click' && event.target?.type === 'button') {
369
+ console.log('button clicked:', event.target.key);
370
+ }
371
+ }}
372
+ >
373
+ {/* canvas components */}
374
+ </Canvas>
375
+ ```
376
+
377
+ Screenshot APIs are available through React ref, Vue template ref, Svelte `bind:this`, or Angular template references — see [Image Export](#image-export). `CanvasHandle` also exposes `requestRender()`, used to schedule a redraw of the host Canvas after a source Canvas updates.
378
+
379
+ ### `<CanvasView>`
380
+
381
+ Renders the picture of an `HTMLCanvasElement` — from a third-party module or elsewhere in the same page — inside the current Canvas. Only the pixel content is embedded; the source Canvas's DOM or event handlers are not brought into the current Canvas.
382
+
383
+ | Prop | Type | Required | Default | Description |
384
+ | ------------------ | ----------------------------------------- | -------: | ----------: | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
385
+ | `source` | `HTMLCanvasElement` | Yes | — | The source Canvas instance to display. |
386
+ | `width` / `height` | `number` | Yes | — | Logical size occupied in the current Canvas. |
387
+ | `fit` | `'contain' \| 'cover' \| 'fill'` | No | `'contain'` | Preserve aspect and fit fully, preserve aspect and crop to fill, or stretch to fill. |
388
+ | `onPointerEvent` | `(event: CanvasViewPointerEvent) => void` | No | — | Provides mapped `pointerdown`, `pointermove`, `pointerup`, `pointercancel`, and `click` events; synthetic events are not dispatched to the source Canvas automatically. |
389
+
390
+ ```tsx
391
+ import { Canvas, CanvasView } from '@web-canvas-ui/react';
392
+
393
+ <Canvas ref={canvasRef} width={640} height={360}>
394
+ <CanvasView
395
+ x={20}
396
+ y={20}
397
+ source={thirdPartyCanvas}
398
+ width={320}
399
+ height={180}
400
+ fit="contain"
401
+ onPointerEvent={(event) => {
402
+ thirdPartyApi.handlePointer({
403
+ type: event.type,
404
+ x: event.sourceX,
405
+ y: event.sourceY,
406
+ pointerId: event.pointerId,
407
+ });
408
+ }}
409
+ />
410
+ </Canvas>;
411
+
412
+ // After the third-party Canvas updates its content, request a redraw of the host Canvas:
413
+ canvasRef.current?.requestRender();
414
+ ```
415
+
416
+ Events include `x`/`y` (CanvasView-local logical coordinates), `sourceX`/`sourceY` (source Canvas bitmap pixel coordinates), source canvas size, button state, `pointerId`, `pointerType`, `pressure`, and `isPrimary`. `contain` letterbox areas do not register hits. During drags, events keep reporting source canvas coordinates even when the pointer briefly leaves the component's bounds. Use this data to call the third-party library's interaction APIs. The source Canvas does not automatically notify the host Canvas of content changes — call the host's `requestRender()` after updating the source, or update the source inside an animation frame and call `requestRender()` there. If the source Canvas contains images without proper CORS authorization, the host Canvas becomes tainted and export will fail — Canvas cross-origin restrictions cannot be bypassed by this component.
417
+
418
+ ### `<CustomDraw>`
419
+
420
+ When built-in components cannot cover your drawing needs, use `CustomDraw` to provide a Canvas 2D drawing callback. It runs on every scene redraw (including image export); the callback's origin is the component's top-left corner, and it can use all common position/rotation/scale props.
421
+
422
+ | Prop | Type | Required | Description |
423
+ | ------------------ | -------------------------------------------------------------------------------------- | -------: | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
424
+ | `width` / `height` | `number` | Yes | Size of the custom drawing region; must be non-negative finite numbers. |
425
+ | `draw` | `(context: CanvasRenderingContext2D, size: { width: number; height: number }) => void` | Yes | Executes synchronous drawing inside the region; `size` provides the corresponding width and height. |
426
+ | `onClick` | `(event: CustomDrawClickEvent) => void` | No | Click callback; `x`/`y` are component-local coordinates, `canvasX`/`canvasY` are Canvas logical coordinates, and size plus `pointerId` are also provided. |
427
+ | `hitTest` | `(x: number, y: number, size: CustomDrawSize) => boolean` | No | Custom hit testing for the shape; falls back to the full width/height rectangle when omitted. Returning `false` allows lower components to receive the hit. |
428
+
429
+ ```tsx
430
+ import { Canvas, CustomDraw } from '@web-canvas-ui/react';
431
+
432
+ <Canvas width={320} height={180}>
433
+ <CustomDraw
434
+ x={20}
435
+ y={20}
436
+ width={160}
437
+ height={100}
438
+ hitTest={(x, y) => Math.abs(y - (x * 100) / 160) < 6}
439
+ onClick={({ x, y }) => console.log('local position:', x, y)}
440
+ draw={(ctx, { width, height }) => {
441
+ ctx.strokeStyle = '#1668dc';
442
+ ctx.lineWidth = 3;
443
+ ctx.beginPath();
444
+ ctx.moveTo(0, 0);
445
+ ctx.lineTo(width, height);
446
+ ctx.stroke();
447
+ }}
448
+ />
449
+ </Canvas>;
450
+ ```
451
+
452
+ Each invocation is isolated from the rest of the Canvas drawing state — colors, line widths, and transforms set inside the callback do not leak to other components. Only draw inside the callback; do not update UI state or perform side effects. Drawing errors are re-thrown as-is.
453
+
454
+ ### `<Group>`
455
+
456
+ Used to group, position, and transform children. Supports [Common Props](#common-props), plus:
457
+
458
+ | Prop | Type | Description |
459
+ | -------- | ------------------------------------------------------------- | --------------------------- |
460
+ | Children | React children / Vue/Svelte slot / Angular content projection | Child Canvas UI components. |
461
+
462
+ ```tsx
463
+ <Group x={20} y={30} scaleX={1.2}>
464
+ <Text x={10} y={10}>
465
+ Text inside a group
466
+ </Text>
467
+ </Group>
468
+ ```
469
+
470
+ ### `<Grid>`
471
+
472
+ Places children in order into fixed-size cells, wrapping to the next row once a row fills the specified column count. `Grid` does not draw a background; it is a layout container and can use transform props like `Group`.
473
+
474
+ | Prop | Type | Required | Default | Description |
475
+ | ------------ | ----------------------------- | -------: | ------: | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
476
+ | `columns` | `number` | Yes | — | Columns per row; must be a positive integer. |
477
+ | `width` | `number` | No | — | Total Grid width. Required when `cellWidth` is not passed; distributed evenly across columns after subtracting inter-column gaps. Can be omitted when `cellWidth` is set — width is then derived from the column count. |
478
+ | `height` | `number` | No | — | Fixed visible height. Overflow is clipped and a scrollbar appears; wheel scrolling works inside the Grid. |
479
+ | `cellWidth` | `number` | No | — | Fixed logical cell width; takes precedence over `width` auto-distribution. Must be positive. |
480
+ | `cellHeight` | `number` | Yes | — | Logical cell height; must be positive. |
481
+ | `gap` | `number` | No | `0` | Equal row and column spacing; must not be negative. |
482
+ | `onScroll` | `(scrollTop: number) => void` | No | — | Scroll position change callback, in logical pixels. |
483
+
484
+ Direct children keep their own `x` and `y`, plus the offset of the cell they fall into. When `cellWidth` is not passed, columns are equal-width: `(width - gap * (columns - 1)) / columns`. A child's own size is not automatically stretched.
485
+
486
+ Every child is also handed the box of the cell it occupies: a `<Text>` that declares neither `width` nor `maxLines` wraps to the cell width and stops with an ellipsis once the lines no longer fit `cellHeight`. A `<GridItem>` passes its span-expanded area down to the controls it groups. Declaring either prop overrides the cell box, so a node can stay deliberately narrower than its cell.
487
+
488
+ ```tsx
489
+ <Grid columns={3} cellWidth={100} cellHeight={50} gap={8}>
490
+ <Rect width={80} height={40} color="#f5f8fc" />
491
+ <Rect width={80} height={40} color="#e5efff" />
492
+ <Rect width={80} height={40} color="#d5e5ff" />
493
+ </Grid>
494
+ ```
495
+
496
+ To split the total width evenly across columns, omit `cellWidth`:
497
+
498
+ ```tsx
499
+ <Grid columns={3} width={316} cellHeight={50} gap={8}>
500
+ <Rect width={80} height={40} color="#f5f8fc" />
501
+ <Rect width={80} height={40} color="#e5efff" />
502
+ <Rect width={80} height={40} color="#d5e5ff" />
503
+ </Grid>
504
+ ```
505
+
506
+ Vue and Svelte use the same prop names; Angular uses `<canvas-grid [columns]="3" [width]="316" [cellHeight]="50" [gap]="8">` and imports `Grid` from the corresponding module.
507
+
508
+ Once a Grid has a `height`, content beyond the visible area is scrollable via the mouse wheel and children are clipped inside the fixed height:
509
+
510
+ ```tsx
511
+ <Grid columns={1} width={280} height={180} cellHeight={44} gap={4}>
512
+ {items.map((item) => (
513
+ <GridItem key={item.id}>
514
+ <Text>{item.label}</Text>
515
+ </GridItem>
516
+ ))}
517
+ </Grid>
518
+ ```
519
+
520
+ ### `<GridItem>`
521
+
522
+ `GridItem` is a grouping/layout node inside a Grid and does not draw anything itself. It can contain multiple controls, positioning them together as one grid entry; children inside the group still use their own sizes and local coordinates. Placing ordinary controls directly under `Grid` also works — they each occupy one cell by default.
523
+
524
+ | Prop | Type | Default | Description |
525
+ | -------------------------------------------- | -------- | ------: | ----------------------------------------------------------------------------- |
526
+ | `columnSpan` | `number` | `1` | Number of columns to span; a positive integer not exceeding Grid's `columns`. |
527
+ | `rowSpan` | `number` | `1` | Number of rows to span; positive integer. |
528
+ | `backgroundColor` | `string` | — | Draws a grid-item background covering its spanned cells. |
529
+ | `x` / `y` | `number` | `0` | Offset from the cell's origin. |
530
+ | `rotation` / `scaleX` / `scaleY` / `visible` | — | — | Same transform and visibility props as `Group`. |
531
+
532
+ Grid places items row by row, skipping cells already occupied by spanning items:
533
+
534
+ ```tsx
535
+ <Grid columns={3} width={316} cellHeight={50} gap={8}>
536
+ <GridItem columnSpan={2}>
537
+ <Rect width={180} height={40} color="#f5f8fc" />
538
+ <Text x={8} y={8}>
539
+ Group spanning two columns
540
+ </Text>
541
+ </GridItem>
542
+ <Rect width={80} height={40} color="#e5efff" />
543
+ </Grid>
544
+ ```
545
+
546
+ Vue and Svelte use the same `<GridItem>`; Angular uses `<canvas-grid-item [columnSpan]="2">...</canvas-grid-item>` and imports `GridItem` from the corresponding module.
547
+
548
+ ### `<Image>`
549
+
550
+ Loads an image from `src` and draws it into the Canvas at the specified size. `objectFit` supports `contain` (default), `cover`, `fill`, `none`, and `scale-down`; `onError(error)` fires on load failure. Angular uses the `(imageError)` event binding for the error callback.
551
+
552
+ | Prop | Type | Required | Default | Description |
553
+ | ------------------ | ---------------------------------------------------------- | -------: | ----------- | ----------------------------------- |
554
+ | `src` | `string` | Yes | — | Image URL. |
555
+ | `width` / `height` | `number` | Yes | — | Canvas logical size. |
556
+ | `objectFit` | `"contain" \| "cover" \| "fill" \| "none" \| "scale-down"` | No | `"contain"` | Image scaling and cropping mode. |
557
+ | `onError` | `(error: Error) => void` | No | — | Fires when the image fails to load. |
558
+
559
+ ```tsx
560
+ <Image x={16} y={16} src="/avatar.png" width={96} height={96} objectFit="cover" />
561
+ ```
562
+
563
+ Remote images draw correctly, but browser CORS rules still apply to Canvas export: if the image server does not authorize cross-origin reads, a Canvas containing that image may fail to export as PNG.
564
+
565
+ ### `<Progress>`
566
+
567
+ Draws a non-interactive progress bar. `value` is clamped between `min` and `max`.
568
+
569
+ | Prop | Type | Default | Description |
570
+ | ------------------------------------ | --------- | -------------: | --------------------------------------------------------- |
571
+ | `value` | `number` | Required | Current progress value. |
572
+ | `min` / `max` | `number` | `0` / `100` | Progress range. |
573
+ | `width` / `height` | `number` | `200` / `12` | Track size. |
574
+ | `color` / `trackColor` / `textColor` | `string` | Theme colors | Progress, track, and text colors; explicit props win. |
575
+ | `borderRadius` | `number` | Half of height | Corner radius. |
576
+ | `showText` | `boolean` | `false` | Whether to draw the percentage to the right of the track. |
577
+
578
+ ### `<Carousel>` and `<CarouselItem>`
579
+
580
+ `Carousel` shows one `CarouselItem` at a time in child order, with optional autoplay, looping, prev/next arrows, and bottom indicator dots. Item content supports any Canvas UI component; when `activeIndex` is not passed explicitly, the carousel runs uncontrolled starting at index 0.
581
+
582
+ | Component | Prop | Type | Default | Description |
583
+ | -------------- | ------------------------- | ------------------------- | -------- | ------------------------------------------------------------------------ |
584
+ | `Carousel` | `width` / `height` | `number` | Required | Viewport size; content overflowing the bounds is clipped. |
585
+ | `Carousel` | `activeIndex` | `number` | — | Controlled current index; combine with `onChange` to update. |
586
+ | `Carousel` | `defaultActiveIndex` | `number` | `0` | Uncontrolled initial index. |
587
+ | `Carousel` | `autoplay` | `boolean` | `true` | Whether to auto-advance; disabled when there are fewer than two items. |
588
+ | `Carousel` | `interval` | `number` | `3000` | Autoplay interval in ms; treated as a minimum of `250`. |
589
+ | `Carousel` | `transitionDuration` | `number` | `450` | Horizontal slide transition duration in ms; set `0` to switch instantly. |
590
+ | `Carousel` | `loop` | `boolean` | `true` | Whether to loop back to the first item at the end. |
591
+ | `Carousel` | `showArrows` / `showDots` | `boolean` | `true` | Whether to show the prev/next arrows and bottom indicator dots. |
592
+ | `Carousel` | `onChange` | `(index: number) => void` | — | Fires when the active index changes. |
593
+ | `CarouselItem` | Children | Canvas UI components | — | Content shown for this slide. |
594
+
595
+ ```tsx
596
+ <Carousel width={320} height={180} interval={4000} onChange={setActiveIndex}>
597
+ <CarouselItem>
598
+ <Image width={320} height={180} src="/banner-one.jpg" objectFit="cover" />
599
+ </CarouselItem>
600
+ <CarouselItem>
601
+ <Image width={320} height={180} src="/banner-two.jpg" objectFit="cover" />
602
+ </CarouselItem>
603
+ </Carousel>
604
+ ```
605
+
606
+ Angular uses `<canvas-carousel>` and `<canvas-carousel-item>`; controlled index changes use `(activeIndexChange)`.
607
+
608
+ ### `<Tabs>` and `<TabItem>`
609
+
610
+ `Tabs` uses `TabItem` to declare tabs and their corresponding Canvas subtrees. The first `TabItem` is selected by default.
611
+
612
+ | Component | Prop | Type | Description |
613
+ | --------- | ------------------------------------------------------------------ | ----------------------- | ------------------------------------------------------------------------------------------------------- |
614
+ | `Tabs` | `width` / `height` | `number` | Size of the tab container; required. Content is drawn below the header and clipped to the content area. |
615
+ | `Tabs` | `activeKey` / `defaultActiveKey` | `string` | Controlled selected key / uncontrolled initial key. |
616
+ | `Tabs` | `headerHeight` | `number` | Header bar height; default `40`. |
617
+ | `Tabs` | `backgroundColor` / `textColor` / `activeColor` / `indicatorColor` | `string` | Colors for the tab bar, text, active state, and indicator line. |
618
+ | `Tabs` | `onChange` | `(key: string) => void` | Fires when the selected tab changes. |
619
+ | `TabItem` | `id` / `title` | `string` | Unique identifier and label; required. |
620
+ | `TabItem` | `disabled` | `boolean` | Disables clicking on this tab. |
621
+ | `TabItem` | Children | Canvas UI components | Canvas content for this tab. |
622
+
623
+ ```tsx
624
+ <Tabs width={320} height={180} defaultActiveKey="profile">
625
+ <TabItem id="profile" title="Profile">
626
+ <Text x={12} y={12}>
627
+ Profile content
628
+ </Text>
629
+ </TabItem>
630
+ <TabItem id="settings" title="Settings">
631
+ <Text x={12} y={12}>
632
+ Settings content
633
+ </Text>
634
+ </TabItem>
635
+ </Tabs>
636
+ ```
637
+
638
+ Angular counterparts are `<canvas-tabs>` and `<canvas-tab-item>`; selection changes use `(activeKeyChange)`.
639
+
640
+ ### `<Collapse>` and `<CollapseItem>`
641
+
642
+ Each `CollapseItem` header toggles its panel; children serve as panel content.
643
+
644
+ | Component | Prop | Type | Description |
645
+ | -------------- | ----------------------------------------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------- |
646
+ | `Collapse` | `width` | `number` | Panel width; required. |
647
+ | `Collapse` | `activeKeys` / `defaultActiveKeys` | `string[]` | Controlled expanded items / uncontrolled initial expanded items. |
648
+ | `Collapse` | `accordion` | `boolean` | Default `false`; when `true` only one item can be expanded at a time. |
649
+ | `Collapse` | `headerHeight` | `number` | Header bar height; default `40`. |
650
+ | `Collapse` | `backgroundColor` / `textColor` / `borderColor` | `string` | Default background, text, and border colors for all headers. |
651
+ | `Collapse` | `onChange` | `(keys: string[]) => void` | Fires when the expanded set changes. |
652
+ | `CollapseItem` | `id` / `title` | `string` | Unique panel identifier and title; required. |
653
+ | `CollapseItem` | `height` | `number` | Expanded content height. Defaults to the space its children need, never below `100`; an explicit value always wins. |
654
+ | `CollapseItem` | `disabled` | `boolean` | Blocks expand/collapse. |
655
+ | `CollapseItem` | `backgroundColor` / `textColor` / `borderColor` | `string` | Overrides the corresponding colors for this item's header. |
656
+
657
+ ```tsx
658
+ <Collapse width={320} defaultActiveKeys={['details']} accordion>
659
+ <CollapseItem id="details" title="Details" height={72}>
660
+ <Text x={12} y={8}>
661
+ Panel content
662
+ </Text>
663
+ </CollapseItem>
664
+ <CollapseItem id="more" title="More">
665
+ <Text x={12} y={8}>
666
+ Another panel
667
+ </Text>
668
+ </CollapseItem>
669
+ </Collapse>
670
+ ```
671
+
672
+ Angular counterparts are `<canvas-collapse>` and `<canvas-collapse-item>`; expansion changes use `(activeKeysChange)`.
673
+
674
+ ### `<Dialog>`
675
+
676
+ The confirmation dialog overlays the Canvas centered by default, painting a mask, title, content area, and built-in Cancel/Confirm buttons. The content area accepts any Canvas UI component. While the dialog is open, `Input`/`Textarea` inside it cannot accept text — this prevents mask click-through.
677
+
678
+ | Prop | Type | Default | Description |
679
+ | ---------------------------- | -------------------- | ------------------: | -------------------------------------------------------- |
680
+ | `open` | `boolean` | Required | Whether the dialog is shown. |
681
+ | `width` / `height` | `number` | `420` / `240` | Dialog size. |
682
+ | `title` | `string` | `"Confirm"` | Title. |
683
+ | `confirmText` / `cancelText` | `string` | `"OK"` / `"Cancel"` | Built-in button labels. |
684
+ | `closeOnBackdrop` | `boolean` | `true` | Whether clicking the mask triggers the cancel callback. |
685
+ | `onConfirm` / `onCancel` | `() => void` | — | Confirm and cancel callbacks. |
686
+ | Children | Canvas UI components | — | Dialog content area; any Canvas UI component is allowed. |
687
+
688
+ ```tsx
689
+ <Dialog
690
+ open={open}
691
+ title="Delete item?"
692
+ onConfirm={() => {
693
+ deleteItem();
694
+ setOpen(false);
695
+ }}
696
+ onCancel={() => setOpen(false)}
697
+ >
698
+ <Text width={340}>This action cannot be undone.</Text>
699
+ </Dialog>
700
+ ```
701
+
702
+ Angular uses `<canvas-dialog>`, with the `open` input and `(confirm)` / `(cancel)` outputs.
703
+
704
+ ### `<Rect>`
705
+
706
+ Draws a rectangle. Supports [Common Props](#common-props).
707
+
708
+ | Prop | Type | Default | Description |
709
+ | ------------- | -------- | --------------: | -------------------------------------- |
710
+ | `width` | `number` | `100` | Width. |
711
+ | `height` | `number` | `40` | Height. |
712
+ | `color` | `string` | `"transparent"` | Fill color. |
713
+ | `radius` | `number` | `0` | Corner radius. |
714
+ | `stroke` | `string` | — | Stroke color; omitted means no stroke. |
715
+ | `strokeWidth` | `number` | `1` | Stroke width. |
716
+
717
+ ### `<Circle>`
718
+
719
+ Draws a circle. Supports [Common Props](#common-props).
720
+
721
+ | Prop | Type | Default | Description |
722
+ | ------------- | -------- | ----------: | -------------------------------------- |
723
+ | `radius` | `number` | `10` | Circle radius. |
724
+ | `color` | `string` | `"#e74c3c"` | Fill color. |
725
+ | `stroke` | `string` | — | Stroke color; omitted means no stroke. |
726
+ | `strokeWidth` | `number` | `1` | Stroke width. |
727
+
728
+ ### `<Text>`
729
+
730
+ Draws single-line or auto-wrapped text. The node reports the box its rendered lines actually need, so containers such as `<CollapseItem>` can size themselves to it. Supports [Common Props](#common-props).
731
+
732
+ | Prop | Type | Default | Description |
733
+ | ------------ | ------------------------------- | -------------: | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
734
+ | `text` | `string` | — | Text content. |
735
+ | Children | `string \| number` | — | Each framework can supply text via native template children in place of `text`. |
736
+ | `fontSize` | `number` | `16` | Font size, in logical pixels. |
737
+ | `width` | `number` | — | Max line width; content wraps beyond it. Monospaced CJK characters also wrap based on measured width. Inside a `<Grid>`, defaults to the cell's width. |
738
+ | `maxLines` | `number` | — | Maximum lines to show; the last visible line is cut with an ellipsis. Inside a `<Grid>`, defaults to the lines that fit the cell; unlimited when neither is set. |
739
+ | `fontFamily` | `string` | `"sans-serif"` | Font family. |
740
+ | `color` | `string` | `"#333"` | Font color. |
741
+ | `baseline` | `CanvasTextBaseline` | `"top"` | Canvas text baseline. |
742
+ | `textAlign` | `"left" \| "center" \| "right"` | `"left"` | Horizontal text alignment; when `width` is set, alignment is relative to the text box. |
743
+
744
+ ### `<Icon>`
745
+
746
+ Original vector icons with no dependency on icon fonts or external images. Supports [Common Props](#common-props).
747
+
748
+ | Prop | Type | Default | Description |
749
+ | ------------- | ---------------------- | ----------: | ---------------------------------------------------------------------------------------- |
750
+ | `name` | `IconName` | Required | Icon name; see the list below. |
751
+ | `size` | `number` | `24` | Icon width and height. |
752
+ | `color` | `string` | `"#333"` | Icon color; can be set via `--canvas-ui-icon-color`. |
753
+ | `variant` | `"outline" \| "solid"` | `"outline"` | `outline` for stroked shapes; `solid` uses thicker strokes and fills the primary shapes. |
754
+ | `strokeWidth` | `number` | `2` | Outline stroke width; solid style uses at least `4`. |
755
+
756
+ Supported: `home`, `house`, `building`, `apartment`, `store`, `mapPin`, `map`, `globe`, `compass`, `navigation`, `flag`, `mountain`, `tree`, `leaf`, `flower`, `sun`, `moon`, `cloud`, `rain`, `snow`, `fire`, `water`, `wind`, `car`, `bus`, `train`, `plane`, `bicycle`, `ship`, `rocket`, `truck`, `walk`, `phone`, `message`, `mail`, `bell`, `calendar`, `clock`, `alarm`, `camera`, `image`, `video`, `music`, `microphone`, `headphones`, `play`, `pause`, `stop`, `record`, `volume`, `wifi`, `bluetooth`, `battery`, `signal`, `power`, `monitor`, `laptop`, `tablet`, `keyboard`, `mouse`, `printer`, `folder`, `file`, `document`, `download`, `upload`, `share`, `link`, `search`, `settings`, `sliders`, `menu`, `close`, `check`, `plus`, `minus`, `edit`, `trash`, `copy`, `save`, `lock`, `unlock`, `key`, `user`, `users`, `heart`, `star`, `bookmark`, `cart`, `bag`, `gift`, `creditCard`, `wallet`, `chart`, `pieChart`, `barChart`, `analytics`, `shield`, `warning`, `info`, `help`, `question`, `tag`, `puzzle`, `code`, `database`, and `cloudDownload`.
757
+
758
+ ```tsx
759
+ <Icon name="search" x={16} y={16} size={28} color="#1677ff" />
760
+ <Icon name="heart" x={56} y={16} variant="solid" color="#e74c3c" />
761
+ ```
762
+
763
+ ### `<Input>`
764
+
765
+ Single-line input. The control's appearance is painted onto the Canvas; a transparent HTML input handles keyboard, IME, and selection.
766
+
767
+ | Prop | Type | Default | Description |
768
+ | ------------------ | ---------------------------------- | -------------: | ------------------------------------------------------------ |
769
+ | `width` / `height` | `number` | `200` / `36` | Control size. |
770
+ | `value` | `string` | — | Controlled input value; pair with `onChange` to update. |
771
+ | `defaultValue` | `string` | `""` | Uncontrolled initial value. |
772
+ | `placeholder` | `string` | `""` | Placeholder text. |
773
+ | `type` | `"text" \| "password" \| "number"` | `"text"` | Input type. Password content is shown as dots on the Canvas. |
774
+ | `fontSize` | `number` | `14` | Font size. |
775
+ | `fontFamily` | `string` | `"sans-serif"` | Font family. |
776
+ | `color` | `string` | `"#333"` | Input text color. |
777
+ | `bgColor` | `string` | `"#fff"` | Background color. |
778
+ | `borderColor` | `string` | `"#ccc"` | Normal border color. |
779
+ | `focusBorderColor` | `string` | `"#3498db"` | Focused border color. |
780
+ | `borderRadius` | `number` | `4` | Corner radius. |
781
+ | `padding` | `number` | `8` | Text padding. |
782
+ | `disabled` | `boolean` | `false` | Disables input. |
783
+ | `maxLength` | `number` | — | Max character count; a non-negative integer takes effect. |
784
+ | `onChange` | `(value: string) => void` | — | Fires when the input changes. |
785
+ | `onFocus` | `() => void` | — | Fires when focused. |
786
+ | `onBlur` | `() => void` | — | Fires when blurred. |
787
+
788
+ ### `<Textarea>`
789
+
790
+ Multi-line text input; inherits value, size, style, and callback props from `<Input>`. Content scrolls inside the box with a visible scrollbar when overflowing; `type` is not supported. Additional prop:
791
+
792
+ | Prop | Type | Description |
793
+ | ------ | -------- | ----------------------------------------------------------------------------------------------------- |
794
+ | `rows` | `number` | Can express the expected number of lines; the actual rendered height is still controlled by `height`. |
795
+
796
+ ```tsx
797
+ <Textarea
798
+ width={300}
799
+ height={120}
800
+ value={notes}
801
+ placeholder="Enter multi-line content"
802
+ onChange={setNotes}
803
+ />
804
+ ```
805
+
806
+ ### `<Upload>`
807
+
808
+ Draws a file-picker button. A built-in vector icon and the label are drawn together as one horizontally centered group. Clicking opens the browser's native file picker; this component does not upload to a server.
809
+
810
+ | Prop | Type | Default | Description |
811
+ | ------------------ | ------------------------- | ---------------: | -------------------------------------------------------------------------- |
812
+ | `width` / `height` | `number` | `120` / `40` | Button size. |
813
+ | `text` | `string` | `"Choose File"` | Button label. |
814
+ | `icon` | `IconName` | `"upload"` | Built-in icon drawn before the label; use any name from [`<Icon>`](#icon). |
815
+ | `iconSize` | `number` | `fontSize × 1.1` | Icon size. |
816
+ | `accept` | `string` | — | File type filter, e.g. `"image/*,.pdf"`. |
817
+ | `multiple` | `boolean` | `false` | Allow multi-selection. |
818
+ | `disabled` | `boolean` | `false` | Disables file selection. |
819
+ | `onChange` | `(files: File[]) => void` | — | Fires after files are selected; canceled picks do not fire. |
820
+
821
+ ```tsx
822
+ <Upload accept="image/*" multiple onChange={(files) => console.log(files)} />
823
+ <Upload icon="cloud" text="Upload Photos" />
824
+ ```
825
+
826
+ Angular uses `<canvas-upload>` and receives `File[]` via `(change)`.
827
+
828
+ ### `<Dropdown>`
829
+
830
+ Canvas-drawn dropdown select. Supports [Common Props](#common-props).
831
+
832
+ | Prop | Type | Default | Description |
833
+ | ------------------ | --------------------------------- | ------------: | ------------------------------------------------------------------- |
834
+ | `width` / `height` | `number` | `200` / `36` | Control size. |
835
+ | `options` | `Array<string \| DropdownOption>` | Required | Option list; string options use the same value for label and value. |
836
+ | `value` | `string` | — | Controlled selected value. |
837
+ | `defaultValue` | `string` | — | Uncontrolled initial value. |
838
+ | `placeholder` | `string` | `"Select..."` | Text shown when nothing is selected. |
839
+ | `disabled` | `boolean` | `false` | Disables interaction. |
840
+ | `fontSize` | `number` | `14` | Font size. |
841
+ | `color` | `string` | `"#333"` | Text color. |
842
+ | `bgColor` | `string` | `"#fff"` | Control background. |
843
+ | `borderColor` | `string` | `"#c7ccd3"` | Normal border color. |
844
+ | `focusBorderColor` | `string` | `"#3478f6"` | Opened border color. |
845
+ | `borderRadius` | `number` | `4` | Corner radius. |
846
+ | `onChange` | `(value: string) => void` | — | Selection change callback. |
847
+
848
+ `DropdownOption` type:
849
+
850
+ | Prop | Type | Description |
851
+ | ---------- | --------- | ------------------------------- |
852
+ | `label` | `string` | Display text. |
853
+ | `value` | `string` | Option value. |
854
+ | `disabled` | `boolean` | Whether the option is disabled. |
855
+
856
+ ```tsx
857
+ <Dropdown
858
+ value={role}
859
+ options={['Admin', { label: 'readOnly', value: 'reader', disabled: false }]}
860
+ onChange={setRole}
861
+ />
862
+ ```
863
+
864
+ ### `<DatePicker>`
865
+
866
+ Canvas-drawn date input; clicking opens the browser's native date picker.
867
+
868
+ | Prop | Type | Default | Description |
869
+ | ------------------ | ------------------------- | --------------: | ------------------------------------------- |
870
+ | `width` / `height` | `number` | `200` / `36` | Control size. |
871
+ | `value` | `string` | — | Controlled date value, format `YYYY-MM-DD`. |
872
+ | `defaultValue` | `string` | `""` | Uncontrolled initial date value. |
873
+ | `placeholder` | `string` | `"Select date"` | Text shown when nothing is selected. |
874
+ | `disabled` | `boolean` | `false` | Disables date selection. |
875
+ | `onChange` | `(value: string) => void` | — | Fires when the date changes. |
876
+
877
+ ### `<Radio>` and `<Checkbox>`
878
+
879
+ Both accept an `options` array; Radio is single-select and Checkbox is multi-select. String options use the same value for label and value; you may also pass `{ label, value, disabled }` objects.
880
+
881
+ | Prop | Type | Default | Description |
882
+ | ------------------ | ----------------------------------------------------------------------- | -------------: | --------------------------------- |
883
+ | `options` | `Array<string \| ChoiceOption>` | Required | Option list. |
884
+ | `value` | Radio: `string`; Checkbox: `string[]` | — | Controlled selected value. |
885
+ | `defaultValue` | Radio: `string`; Checkbox: `string[]` | — | Uncontrolled initial value. |
886
+ | `direction` | `"horizontal" \| "vertical"` | `"horizontal"` | Option layout direction. |
887
+ | `width` / `height` | `number` | Auto | Control size. |
888
+ | `onChange` | Radio: `(value: string) => void`; Checkbox: `(value: string[]) => void` | — | Fires when the selection changes. |
889
+
890
+ ```tsx
891
+ <Radio options={['Small', 'Medium', 'Large']} value={size} onChange={setSize} />
892
+ <Checkbox options={['Email', 'SMS']} value={channels} onChange={setChannels} />
893
+ ```
894
+
895
+ Angular uses `<canvas-date-picker>`, `<canvas-radio>`, and `<canvas-checkbox>`; date selection listens via `(valueChange)` or `(change)`, and Radio/Checkbox use `(change)`.
896
+
897
+ ### `<Slider>`
898
+
899
+ Draggable slider. Supports [Common Props](#common-props).
900
+
901
+ | Prop | Type | Default | Description |
902
+ | ------------------ | ------------------------- | -----------: | ------------------------------ |
903
+ | `width` / `height` | `number` | `160` / `32` | Slider size. |
904
+ | `min` / `max` | `number` | `0` / `100` | Min and max values. |
905
+ | `step` | `number` | `1` | Step size. |
906
+ | `value` | `number` | — | Controlled value. |
907
+ | `defaultValue` | `number` | `min` | Uncontrolled initial value. |
908
+ | `disabled` | `boolean` | `false` | Disables dragging. |
909
+ | `trackColor` | `string` | `"#d7dde5"` | Track color. |
910
+ | `activeColor` | `string` | `"#3478f6"` | Filled track and border color. |
911
+ | `thumbColor` | `string` | `"#fff"` | Thumb color. |
912
+ | `onChange` | `(value: number) => void` | — | Fires when the value changes. |
913
+
914
+ ### `<Switch>`
915
+
916
+ Toggle switch. Supports [Common Props](#common-props).
917
+
918
+ | Prop | Type | Default | Description |
919
+ | ------------------ | ---------------------------- | ----------: | ----------------------------- |
920
+ | `width` / `height` | `number` | `44` / `24` | Switch size. |
921
+ | `checked` | `boolean` | — | Controlled checked state. |
922
+ | `defaultChecked` | `boolean` | `false` | Uncontrolled initial state. |
923
+ | `disabled` | `boolean` | `false` | Blocks toggling. |
924
+ | `onColor` | `string` | `"#3478f6"` | Track color when on. |
925
+ | `offColor` | `string` | `"#c7ccd3"` | Track color when off. |
926
+ | `thumbColor` | `string` | `"#fff"` | Thumb color. |
927
+ | `onChange` | `(checked: boolean) => void` | — | Fires when the state changes. |
928
+
929
+ ### `<Button>`
930
+
931
+ Canvas-drawn button. Supports [Common Props](#common-props).
932
+
933
+ | Prop | Type | Default | Description |
934
+ | ------------------ | ------------------ | -----------: | ---------------------------------------------------------- |
935
+ | `width` / `height` | `number` | `120` / `40` | Button size. |
936
+ | Children | `string \| number` | — | Button label; can be replaced by `text`. |
937
+ | `text` | `string` | — | Button label; wins over `children` when both are provided. |
938
+ | `fontSize` | `number` | `15` | Font size. |
939
+ | `fontColor` | `string` | `"#fff"` | Text color. |
940
+ | `backgroundColor` | `string` | `"#3478f6"` | Background color. |
941
+ | `borderColor` | `string` | — | Stroke color. |
942
+ | `borderRadius` | `number` | `6` | Corner radius. |
943
+ | `disabled` | `boolean` | `false` | Disables the button. |
944
+ | `onClick` | `() => void` | — | Click callback. |
945
+
946
+ ## Image Export
947
+
948
+ Export the image through a `ref` provided by `CanvasHandle`:
949
+
950
+ ```tsx
951
+ const canvasRef = useRef<CanvasHandle>(null);
952
+
953
+ // PNG Data URL — assign directly to img.src
954
+ const dataUrl = canvasRef.current?.toDataURL({
955
+ type: 'image/png',
956
+ width: 840,
957
+ height: 600,
958
+ pixelRatio: 2,
959
+ });
960
+
961
+ // JPEG Blob — create a download link or upload
962
+ const blob = await canvasRef.current?.toBlob({
963
+ type: 'image/jpeg',
964
+ quality: 0.9,
965
+ pixelRatio: 2,
966
+ });
967
+
968
+ // Get the underlying HTMLCanvasElement
969
+ const canvasElement = canvasRef.current?.getCanvas();
970
+ ```
971
+
972
+ `CanvasExportOptions`:
973
+
974
+ | Prop | Type | Default | Description |
975
+ | ------------ | -------- | ----------------------------: | ---------------------------------------------------------------------------------------------------------------- |
976
+ | `width` | `number` | Current Canvas logical width | Logical export width. |
977
+ | `height` | `number` | Current Canvas logical height | Logical export height. |
978
+ | `pixelRatio` | `number` | Canvas's pixel ratio | Output pixels per logical pixel; the final bitmap size is roughly `width × pixelRatio` by `height × pixelRatio`. |
979
+ | `type` | `string` | `"image/png"` | Image MIME type such as `image/png`, `image/jpeg`, `image/webp`. Unsupported formats fall back to PNG. |
980
+ | `quality` | `number` | Browser default | Quality for lossy formats, range `0` to `1`; usually unused by PNG. |
981
+
982
+ Short-form calls are still supported:
983
+
984
+ ```tsx
985
+ canvasRef.current?.toDataURL('image/png');
986
+ const jpegBlob = await canvasRef.current?.toBlob('image/jpeg', 0.9);
987
+ ```
988
+
989
+ Export size and pixel ratio must be positive numbers. If the scene contains a cross-origin image without server-side CORS authorization, `toDataURL()` throws an error explaining the reason and `toBlob()` rejects with the same error. Configure the image server to return an `Access-Control-Allow-Origin` header that permits the current site, or remove the image before exporting.