@web-canvas-ui/angular 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1198 -2
- package/index.js +5349 -0
- package/package.json +40 -5
- package/theme.css +327 -0
- package/types/angular/Canvas.d.ts +42 -0
- package/types/angular/index.d.ts +5 -0
- package/types/angular/node-directives.d.ts +367 -0
- package/types/canvas-handle.d.ts +22 -0
- package/types/components/Button/button.d.ts +22 -0
- package/types/components/Button/index.d.ts +3 -0
- package/types/components/Button/logic.d.ts +3 -0
- package/types/components/CanvasView/canvasView.d.ts +28 -0
- package/types/components/CanvasView/index.d.ts +2 -0
- package/types/components/Carousel/carousel.d.ts +31 -0
- package/types/components/Carousel/index.d.ts +3 -0
- package/types/components/Carousel/logic.d.ts +2 -0
- package/types/components/Checkbox/checkbox.d.ts +8 -0
- package/types/components/Checkbox/index.d.ts +2 -0
- package/types/components/ChoiceGroup/choiceGroup.d.ts +38 -0
- package/types/components/ChoiceGroup/index.d.ts +3 -0
- package/types/components/ChoiceGroup/logic.d.ts +3 -0
- package/types/components/Circle/circle.d.ts +9 -0
- package/types/components/Circle/index.d.ts +2 -0
- package/types/components/Collapse/collapse.d.ts +32 -0
- package/types/components/Collapse/index.d.ts +3 -0
- package/types/components/Collapse/logic.d.ts +1 -0
- package/types/components/CustomDraw/customDraw.d.ts +22 -0
- package/types/components/CustomDraw/index.d.ts +2 -0
- package/types/components/DatePicker/datePicker.d.ts +24 -0
- package/types/components/DatePicker/index.d.ts +2 -0
- package/types/components/Dialog/dialog.d.ts +20 -0
- package/types/components/Dialog/index.d.ts +2 -0
- package/types/components/Dropdown/dropdown.d.ts +30 -0
- package/types/components/Dropdown/index.d.ts +3 -0
- package/types/components/Dropdown/logic.d.ts +5 -0
- package/types/components/Form/form.d.ts +42 -0
- package/types/components/Form/index.d.ts +2 -0
- package/types/components/Grid/grid.d.ts +14 -0
- package/types/components/Grid/index.d.ts +2 -0
- package/types/components/GridItem/gridItem.d.ts +8 -0
- package/types/components/GridItem/index.d.ts +2 -0
- package/types/components/Group/group.d.ts +5 -0
- package/types/components/Group/index.d.ts +2 -0
- package/types/components/Icon/icon.d.ts +14 -0
- package/types/components/Icon/index.d.ts +2 -0
- package/types/components/Image/image.d.ts +12 -0
- package/types/components/Image/index.d.ts +2 -0
- package/types/components/Input/index.d.ts +2 -0
- package/types/components/Input/input.d.ts +32 -0
- package/types/components/Progress/index.d.ts +2 -0
- package/types/components/Progress/progress.d.ts +15 -0
- package/types/components/Radio/index.d.ts +2 -0
- package/types/components/Radio/radio.d.ts +8 -0
- package/types/components/Rect/index.d.ts +2 -0
- package/types/components/Rect/rect.d.ts +11 -0
- package/types/components/Slider/index.d.ts +3 -0
- package/types/components/Slider/logic.d.ts +1 -0
- package/types/components/Slider/slider.d.ts +17 -0
- package/types/components/Switch/index.d.ts +3 -0
- package/types/components/Switch/logic.d.ts +2 -0
- package/types/components/Switch/switch.d.ts +14 -0
- package/types/components/Tabs/index.d.ts +3 -0
- package/types/components/Tabs/logic.d.ts +2 -0
- package/types/components/Tabs/tabs.d.ts +35 -0
- package/types/components/Text/index.d.ts +2 -0
- package/types/components/Text/text.d.ts +39 -0
- package/types/components/Textarea/index.d.ts +2 -0
- package/types/components/Textarea/textarea.d.ts +10 -0
- package/types/components/Upload/index.d.ts +2 -0
- package/types/components/Upload/upload.d.ts +30 -0
- package/types/components/Video/index.d.ts +4 -0
- package/types/components/Video/logic.d.ts +56 -0
- package/types/components/Video/video.d.ts +54 -0
- package/types/components/draw-utils.d.ts +48 -0
- package/types/components/shared.d.ts +7 -0
- package/types/components/size.d.ts +6 -0
- package/types/components/types.d.ts +29 -0
- package/types/engine/accessibility.d.ts +5 -0
- package/types/engine/carousel.d.ts +10 -0
- package/types/engine/events.d.ts +14 -0
- package/types/engine/forms.d.ts +21 -0
- package/types/engine/hit-test.d.ts +31 -0
- package/types/engine/images.d.ts +8 -0
- package/types/engine/interaction.d.ts +12 -0
- package/types/engine/layout.d.ts +6 -0
- package/types/engine/nodes.d.ts +19 -0
- package/types/engine/state.d.ts +91 -0
- package/types/engine/text-controls.d.ts +10 -0
- package/types/engine/transform.d.ts +13 -0
- package/types/engine/uploads.d.ts +5 -0
- package/types/engine/videos.d.ts +28 -0
- package/types/engine/vnodes.d.ts +36 -0
- package/types/engine.d.ts +38 -0
- package/types/image-assets.d.ts +2 -0
- package/types/input-bridge.d.ts +54 -0
- package/types/renderer.d.ts +20 -0
- package/types/scene.d.ts +15 -0
- package/types/types.d.ts +162 -0
- package/types/video-assets.d.ts +28 -0
package/README.md
CHANGED
|
@@ -1,3 +1,1199 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="./src/assets/web-canvas-ui-logo-bright.svg" alt="Project Logo" />
|
|
3
|
+
</div>
|
|
2
4
|
|
|
3
|
-
|
|
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 `src/canvas-ui/components/<Component>/`. `<component>.ts` defines the Props type and Canvas drawing function, and `logic.ts` (when needed) holds control-specific interaction and business logic. Public types are aggregated in `components/types.ts` and re-exported through `src/canvas-ui/types.ts` and each framework entry. The React, Vue, Svelte, and Angular adapters share this type contract. See the [component development guide](./COMPONENT-DEVELOPMENT.zh-CN.md) (in Chinese) for the full procedure.
|
|
14
|
+
|
|
15
|
+
### Clone the Repository
|
|
16
|
+
|
|
17
|
+
Clone the project to your local machine and navigate into the directory:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
git clone https://github.com/web-canvas-ui/web-canvas-ui.git
|
|
21
|
+
cd web-canvas-ui
|
|
22
|
+
npm install
|
|
23
|
+
npm run dev
|
|
24
|
+
|
|
25
|
+
OR
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
[▶️ ui-demo](https://codesandbox.io/p/sandbox/web-canvas-ui-demo-2jhwsn)
|
|
29
|
+
|
|
30
|
+
[▶️ form-demo](https://codesandbox.io/p/sandbox/form-demo-drvqqk)
|
|
31
|
+
|
|
32
|
+
## Global Theme Colors
|
|
33
|
+
|
|
34
|
+
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:
|
|
35
|
+
|
|
36
|
+
```css
|
|
37
|
+
@import '@web-canvas-ui/react/theme.css';
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Replace `react` with `vue`, `svelte`, or `angular` for the other packages. 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.
|
|
41
|
+
|
|
42
|
+
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:
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
<div className="theme-green">
|
|
46
|
+
<Canvas width={400} height={240}>
|
|
47
|
+
<Button>Green theme</Button>
|
|
48
|
+
</Canvas>
|
|
49
|
+
</div>
|
|
50
|
+
<p>--OR--</p>
|
|
51
|
+
<Canvas width={400} height={240} className="theme-green">
|
|
52
|
+
<Button>Green theme</Button>
|
|
53
|
+
</Canvas>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
| Palette | class | Primary |
|
|
57
|
+
| -------------- | -------------- | --------- |
|
|
58
|
+
| Blue (default) | `theme-blue` | `#1668dc` |
|
|
59
|
+
| Green | `theme-green` | `#389e0d` |
|
|
60
|
+
| Purple | `theme-purple` | `#722ed1` |
|
|
61
|
+
| Orange | `theme-orange` | `#d46b08` |
|
|
62
|
+
| Red | `theme-red` | `#cf1322` |
|
|
63
|
+
|
|
64
|
+
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.
|
|
65
|
+
|
|
66
|
+
| Component | CSS custom properties |
|
|
67
|
+
| ----------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
68
|
+
| Button / Upload | `--canvas-ui-button-background`, `--canvas-ui-button-color`, `--canvas-ui-button-border`, `--canvas-ui-button-pressed-background` |
|
|
69
|
+
| Carousel | `--canvas-ui-carousel-arrow`, `--canvas-ui-carousel-dot`, `--canvas-ui-carousel-active-dot` |
|
|
70
|
+
| Radio / Checkbox | `--canvas-ui-choice-active`, `--canvas-ui-choice-border`, `--canvas-ui-choice-color`, `--canvas-ui-choice-disabled`, `--canvas-ui-choice-disabled-background` |
|
|
71
|
+
| Collapse | `--canvas-ui-collapse-header-background`, `--canvas-ui-collapse-border`, `--canvas-ui-collapse-color`, `--canvas-ui-collapse-disabled-color` |
|
|
72
|
+
| 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` |
|
|
73
|
+
| 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` |
|
|
74
|
+
| 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` |
|
|
75
|
+
| Progress | `--canvas-ui-progress-track`, `--canvas-ui-progress-active`, `--canvas-ui-progress-text` |
|
|
76
|
+
| 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` |
|
|
77
|
+
| Slider | `--canvas-ui-slider-track`, `--canvas-ui-slider-active`, `--canvas-ui-slider-thumb` |
|
|
78
|
+
| Switch | `--canvas-ui-switch-on`, `--canvas-ui-switch-off`, `--canvas-ui-switch-thumb` |
|
|
79
|
+
| Tabs | `--canvas-ui-tabs-background`, `--canvas-ui-tabs-color`, `--canvas-ui-tabs-active-color`, `--canvas-ui-tabs-indicator`, `--canvas-ui-tabs-disabled-color` |
|
|
80
|
+
|
|
81
|
+
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.
|
|
82
|
+
|
|
83
|
+
## Environment and Imports
|
|
84
|
+
|
|
85
|
+
Install the package for your framework: React 19+, Vue 3, Svelte 5+, or Angular 17+. Framework dependencies are supplied by the host project.
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
npm install @web-canvas-ui/react
|
|
89
|
+
|
|
90
|
+
npm install @web-canvas-ui/vue
|
|
91
|
+
|
|
92
|
+
npm install @web-canvas-ui/svelte
|
|
93
|
+
|
|
94
|
+
npm install @web-canvas-ui/angular
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
| Framework | Entry |
|
|
98
|
+
| ----------- | ------------------------ |
|
|
99
|
+
| React | `@web-canvas-ui/react` |
|
|
100
|
+
| Vue 3 | `@web-canvas-ui/vue` |
|
|
101
|
+
| Svelte 5+ | `@web-canvas-ui/svelte` |
|
|
102
|
+
| Angular 17+ | `@web-canvas-ui/angular` |
|
|
103
|
+
|
|
104
|
+
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.
|
|
105
|
+
|
|
106
|
+
## Quick Start (React)
|
|
107
|
+
|
|
108
|
+
```tsx
|
|
109
|
+
import { useRef, useState } from 'react';
|
|
110
|
+
import { Canvas, Group, Rect, Text, Input, Button } from '@web-canvas-ui/react';
|
|
111
|
+
import type { CanvasHandle } from '@web-canvas-ui/react';
|
|
112
|
+
import './theme.css';
|
|
113
|
+
|
|
114
|
+
export function ProfileCanvas() {
|
|
115
|
+
const [name, setName] = useState('');
|
|
116
|
+
const canvasRef = useRef<CanvasHandle>(null);
|
|
117
|
+
|
|
118
|
+
const exportPng = () => {
|
|
119
|
+
const dataUrl = canvasRef.current?.toDataURL({
|
|
120
|
+
type: 'image/png',
|
|
121
|
+
pixelRatio: 2,
|
|
122
|
+
});
|
|
123
|
+
if (!dataUrl) return;
|
|
124
|
+
|
|
125
|
+
const link = document.createElement('a');
|
|
126
|
+
link.href = dataUrl;
|
|
127
|
+
link.download = 'profile.png';
|
|
128
|
+
link.click();
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<section>
|
|
133
|
+
<Canvas ref={canvasRef} width={420} height={220}>
|
|
134
|
+
<Group x={24} y={24}>
|
|
135
|
+
<Rect width={340} height={170} color="#f5f8fc" radius={12} />
|
|
136
|
+
<Text x={16} y={16} fontSize={20} color="#222" text="Profile" />
|
|
137
|
+
<Input
|
|
138
|
+
x={16}
|
|
139
|
+
y={54}
|
|
140
|
+
width={280}
|
|
141
|
+
height={38}
|
|
142
|
+
value={name}
|
|
143
|
+
placeholder="Your name"
|
|
144
|
+
onChange={setName}
|
|
145
|
+
/>
|
|
146
|
+
<Text
|
|
147
|
+
x={16}
|
|
148
|
+
y={108}
|
|
149
|
+
width={280}
|
|
150
|
+
fontSize={16}
|
|
151
|
+
text={name ? `Hello, ${name}` : 'Type your name'}
|
|
152
|
+
/>
|
|
153
|
+
<Button
|
|
154
|
+
x={16}
|
|
155
|
+
y={136}
|
|
156
|
+
width={120}
|
|
157
|
+
height={36}
|
|
158
|
+
backgroundColor="#3478f6"
|
|
159
|
+
fontColor="#fff"
|
|
160
|
+
onClick={exportPng}
|
|
161
|
+
>
|
|
162
|
+
Export Image
|
|
163
|
+
</Button>
|
|
164
|
+
</Group>
|
|
165
|
+
</Canvas>
|
|
166
|
+
</section>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
`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.
|
|
172
|
+
|
|
173
|
+
## Quick Start (Vue 3 Single-File Component)
|
|
174
|
+
|
|
175
|
+
The Vue adapter lives in `@web-canvas-ui/vue`. Nest Canvas UI components directly in a `.vue` template — no TSX, no JSX plugin, no manual Canvas node arrays:
|
|
176
|
+
|
|
177
|
+
```vue
|
|
178
|
+
<script setup lang="ts">
|
|
179
|
+
import { ref } from 'vue';
|
|
180
|
+
import { Canvas, Group, Rect, Text, Input, Button } from '@web-canvas-ui/vue';
|
|
181
|
+
import type { CanvasHandle } from '@web-canvas-ui/vue';
|
|
182
|
+
import './theme.css';
|
|
183
|
+
|
|
184
|
+
const name = ref('');
|
|
185
|
+
const canvasRef = ref<CanvasHandle | null>(null);
|
|
186
|
+
|
|
187
|
+
function exportPng() {
|
|
188
|
+
const dataUrl = canvasRef.value?.toDataURL({
|
|
189
|
+
type: 'image/png',
|
|
190
|
+
pixelRatio: 2,
|
|
191
|
+
});
|
|
192
|
+
if (!dataUrl) return;
|
|
193
|
+
|
|
194
|
+
const link = document.createElement('a');
|
|
195
|
+
link.href = dataUrl;
|
|
196
|
+
link.download = 'profile.png';
|
|
197
|
+
link.click();
|
|
198
|
+
}
|
|
199
|
+
</script>
|
|
200
|
+
|
|
201
|
+
<template>
|
|
202
|
+
<Canvas ref="canvasRef" :width="420" :height="220">
|
|
203
|
+
<Group :x="24" :y="24">
|
|
204
|
+
<Rect :width="340" :height="170" color="#f5f8fc" :radius="12" />
|
|
205
|
+
<Text :x="16" :y="16" :font-size="20" text="Vue 3 Canvas" />
|
|
206
|
+
<Input
|
|
207
|
+
:x="16"
|
|
208
|
+
:y="54"
|
|
209
|
+
:width="280"
|
|
210
|
+
:height="38"
|
|
211
|
+
:value="name"
|
|
212
|
+
placeholder="Your name"
|
|
213
|
+
@change="name = $event"
|
|
214
|
+
/>
|
|
215
|
+
<Text
|
|
216
|
+
:x="16"
|
|
217
|
+
:y="104"
|
|
218
|
+
:width="280"
|
|
219
|
+
:text="name ? `Hello, ${name}` : 'Type your name'"
|
|
220
|
+
/>
|
|
221
|
+
<Button :x="16" :y="142" :width="120" :height="36" @click="exportPng">
|
|
222
|
+
Export Image
|
|
223
|
+
</Button>
|
|
224
|
+
</Group>
|
|
225
|
+
</Canvas>
|
|
226
|
+
</template>
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
In the Vue template, bind reactive state with `:value` and update it via `@change`; Canvas components sync the scene after Vue updates.
|
|
230
|
+
|
|
231
|
+
## Quick Start (Svelte 5+)
|
|
232
|
+
|
|
233
|
+
Use the Svelte entry's components inside a Svelte 5 template. `Canvas` exposes imperative methods through `bind:this`:
|
|
234
|
+
|
|
235
|
+
```svelte
|
|
236
|
+
<script lang="ts">
|
|
237
|
+
import { Canvas, Group, Rect, Text, Input, Button } from '@web-canvas-ui/svelte';
|
|
238
|
+
import type { CanvasHandle } from '@web-canvas-ui/svelte';
|
|
239
|
+
import './theme.css';
|
|
240
|
+
|
|
241
|
+
let name = $state('');
|
|
242
|
+
let canvas = $state<CanvasHandle>();
|
|
243
|
+
|
|
244
|
+
function exportPng() {
|
|
245
|
+
const dataUrl = canvas?.toDataURL({ type: 'image/png', pixelRatio: 2 });
|
|
246
|
+
if (!dataUrl) return;
|
|
247
|
+
const link = document.createElement('a');
|
|
248
|
+
link.href = dataUrl;
|
|
249
|
+
link.download = 'profile.png';
|
|
250
|
+
link.click();
|
|
251
|
+
}
|
|
252
|
+
</script>
|
|
253
|
+
|
|
254
|
+
<Canvas bind:this={canvas} width={420} height={180}>
|
|
255
|
+
<Group x={16} y={16}>
|
|
256
|
+
<Rect width={340} height={140} color="#f5f8fc" radius={12} />
|
|
257
|
+
<Text x={16} y={16} text="Svelte Canvas" />
|
|
258
|
+
<Input
|
|
259
|
+
x={16}
|
|
260
|
+
y={48}
|
|
261
|
+
value={name}
|
|
262
|
+
placeholder="Your name"
|
|
263
|
+
onChange={(value) => name = value}
|
|
264
|
+
/>
|
|
265
|
+
<Text x={16} y={92} text={name ? `Hello, ${name}` : 'Type your name'} />
|
|
266
|
+
<Button x={220} y={48} text="Export" onClick={exportPng} />
|
|
267
|
+
</Group>
|
|
268
|
+
</Canvas>
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
Changes to Svelte control props are synced to the Canvas scene;
|
|
272
|
+
|
|
273
|
+
## Quick Start (Angular 17+)
|
|
274
|
+
|
|
275
|
+
The Angular entry provides a standalone `Canvas` component and scene directives. Import the required symbols in whichever standalone component uses them:
|
|
276
|
+
|
|
277
|
+
```ts
|
|
278
|
+
import { Component, ViewChild } from '@angular/core';
|
|
279
|
+
import { Button, Canvas, Group, Input, Rect, Text } from '@web-canvas-ui/angular';
|
|
280
|
+
|
|
281
|
+
@Component({
|
|
282
|
+
selector: 'app-root',
|
|
283
|
+
styleUrl: './theme.css',
|
|
284
|
+
standalone: true,
|
|
285
|
+
imports: [Canvas, Group, Rect, Text, Input, Button],
|
|
286
|
+
template: `
|
|
287
|
+
<canvas-ui #canvas="canvasUi" [width]="420" [height]="180">
|
|
288
|
+
<canvas-group [x]="16" [y]="16">
|
|
289
|
+
<canvas-rect
|
|
290
|
+
[width]="340"
|
|
291
|
+
[height]="140"
|
|
292
|
+
color="#f5f8fc"
|
|
293
|
+
[radius]="12"
|
|
294
|
+
></canvas-rect>
|
|
295
|
+
<canvas-text [x]="16" [y]="16" text="Angular Canvas"></canvas-text>
|
|
296
|
+
<canvas-input
|
|
297
|
+
[x]="16"
|
|
298
|
+
[y]="48"
|
|
299
|
+
[value]="name"
|
|
300
|
+
placeholder="Your name"
|
|
301
|
+
(valueChange)="onInputChange($event)"
|
|
302
|
+
></canvas-input>
|
|
303
|
+
<canvas-text
|
|
304
|
+
[x]="16"
|
|
305
|
+
[y]="92"
|
|
306
|
+
[text]="name ? 'Hello, ' + name : 'Type your name'"
|
|
307
|
+
></canvas-text>
|
|
308
|
+
<canvas-button
|
|
309
|
+
[x]="220"
|
|
310
|
+
[y]="48"
|
|
311
|
+
text="Export"
|
|
312
|
+
(click)="exportPng()"
|
|
313
|
+
></canvas-button>
|
|
314
|
+
</canvas-group>
|
|
315
|
+
</canvas-ui>
|
|
316
|
+
`,
|
|
317
|
+
})
|
|
318
|
+
export class ProfileCanvas {
|
|
319
|
+
name = '';
|
|
320
|
+
@ViewChild('canvas') canvas?: Canvas;
|
|
321
|
+
|
|
322
|
+
exportPng() {
|
|
323
|
+
const dataUrl = this.canvas?.toDataURL({ type: 'image/png', pixelRatio: 2 });
|
|
324
|
+
if (!dataUrl) return;
|
|
325
|
+
const link = document.createElement('a');
|
|
326
|
+
link.href = dataUrl;
|
|
327
|
+
link.download = 'profile.png';
|
|
328
|
+
link.click();
|
|
329
|
+
}
|
|
330
|
+
onInputChange(e: any) {
|
|
331
|
+
this.name = e;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
Angular uses `<canvas-...>` directive selectors to declare Canvas scene nodes. Inputs, dropdowns, and sliders emit through `(valueChange)`, switches through `(checkedChange)`, and buttons through `(click)`.
|
|
337
|
+
|
|
338
|
+
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.
|
|
339
|
+
|
|
340
|
+
## Common Props
|
|
341
|
+
|
|
342
|
+
Every visible component except `<Canvas>` supports the following transform props:
|
|
343
|
+
|
|
344
|
+
| Prop | Type | Default | Description |
|
|
345
|
+
| ---------- | --------- | ------: | -------------------------------------------------------------------------------------------------------- |
|
|
346
|
+
| `x` | `number` | `0` | Horizontal position relative to the parent. |
|
|
347
|
+
| `y` | `number` | `0` | Vertical position relative to the parent. |
|
|
348
|
+
| `rotation` | `number` | `0` | Rotation in radians. |
|
|
349
|
+
| `scaleX` | `number` | `1` | Horizontal transform scale. |
|
|
350
|
+
| `scaleY` | `number` | `1` | Vertical transform scale. |
|
|
351
|
+
| `visible` | `boolean` | `true` | Whether the component is drawn; when `false`, its children are also hidden and do not respond to clicks. |
|
|
352
|
+
|
|
353
|
+
### Keyboard and accessibility
|
|
354
|
+
|
|
355
|
+
`Input`, `Textarea`, `DatePicker`, `Button`, `Upload`, `Switch`, `Radio`, `Checkbox`, `Slider`, and `Dropdown` support keyboard focus and native accessibility semantics. Use Tab to move between controls, Enter/Space for buttons and switches, and the browser's native keys for choices and sliders. Keyboard operation of Dropdown uses a native selection list. Set `ariaLabel` on interactive components for a meaningful name, for example `<Switch ariaLabel="Notifications" />`; text inputs fall back to their placeholder. Form errors are associated with their fields for assistive technology.
|
|
356
|
+
|
|
357
|
+
Keyboard support for Tabs, Collapse, Carousel, Video, and custom-drawn controls is not yet included. Test keyboard and screen-reader behavior in your application.
|
|
358
|
+
|
|
359
|
+
### Sizing Rules
|
|
360
|
+
|
|
361
|
+
- `Rect`, `Input`, `Textarea`, `Upload`, `Dropdown`, `DatePicker`, `Slider`, `Switch`, and `Button` use `width` and `height` to set their size.
|
|
362
|
+
- `Circle` uses `radius` (default `10`); the diameter is twice the radius.
|
|
363
|
+
- `Text` uses `fontSize` for the type size and `width` for the wrap width.
|
|
364
|
+
- 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.
|
|
365
|
+
- `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.
|
|
366
|
+
|
|
367
|
+
## Component Props
|
|
368
|
+
|
|
369
|
+
### `<Canvas>`
|
|
370
|
+
|
|
371
|
+
Creates a Canvas scene. Sizes are in logical pixels; the underlying bitmap is multiplied by the pixel ratio.
|
|
372
|
+
|
|
373
|
+
| Prop | Type | Required | Default | Description |
|
|
374
|
+
| -------------------------------------------------- | -------------------------------------------------------------------------------- | -------: | ----------------------------------------------------------------------: | ------------------------------------------------------------------------------------------------------------------------------------- |
|
|
375
|
+
| `width` | `number` | Yes | — | Logical Canvas width. |
|
|
376
|
+
| `height` | `number` | Yes | — | Logical Canvas height. |
|
|
377
|
+
| Pixel ratio | Automatic | — | Reads `window.devicePixelRatio` with a floor of `1`; no prop is needed. | Canvas rendering resolution ratio. |
|
|
378
|
+
| `className` (React/Angular) / `class` (Vue/Svelte) | `string` | No | — | CSS class for the outer container. |
|
|
379
|
+
| `style` | Framework-specific style object or string | No | — | Style for the outer container; `position`, `width`, and `height` are managed by the component. |
|
|
380
|
+
| `ariaLabel` | `string` | No | `"Canvas"` | Accessibility label for the Canvas element. |
|
|
381
|
+
| `onFrame` | `(time: number) => void` | No | — | Per-frame callback; `time` is the browser animation-frame timestamp. |
|
|
382
|
+
| `onEvent` | `(event: CanvasUIEvent) => void` | No | — | Unified event entry point for the Canvas, receiving `pointerdown`, `pointermove`, `pointerup`, `pointercancel`, `click`, and `wheel`. |
|
|
383
|
+
| Children | React children / Vue default slot / Svelte children / Angular content projection | No | — | Canvas UI component tree. |
|
|
384
|
+
|
|
385
|
+
`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.
|
|
386
|
+
|
|
387
|
+
```tsx
|
|
388
|
+
<Canvas
|
|
389
|
+
width={420}
|
|
390
|
+
height={220}
|
|
391
|
+
onEvent={(event) => {
|
|
392
|
+
if (event.type === 'click' && event.target?.type === 'button') {
|
|
393
|
+
console.log('button clicked:', event.target.key);
|
|
394
|
+
}
|
|
395
|
+
}}
|
|
396
|
+
>
|
|
397
|
+
{/* canvas components */}
|
|
398
|
+
</Canvas>
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
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.
|
|
402
|
+
|
|
403
|
+
### `<CanvasView>`
|
|
404
|
+
|
|
405
|
+
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.
|
|
406
|
+
|
|
407
|
+
| Prop | Type | Required | Default | Description |
|
|
408
|
+
| ------------------ | ----------------------------------------- | -------: | ----------: | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
409
|
+
| `source` | `HTMLCanvasElement` | Yes | — | The source Canvas instance to display. |
|
|
410
|
+
| `width` / `height` | `number` | Yes | — | Logical size occupied in the current Canvas. |
|
|
411
|
+
| `fit` | `'contain' \| 'cover' \| 'fill'` | No | `'contain'` | Preserve aspect and fit fully, preserve aspect and crop to fill, or stretch to fill. |
|
|
412
|
+
| `onPointerEvent` | `(event: CanvasViewPointerEvent) => void` | No | — | Provides mapped `pointerdown`, `pointermove`, `pointerup`, `pointercancel`, and `click` events; synthetic events are not dispatched to the source Canvas automatically. |
|
|
413
|
+
|
|
414
|
+
```tsx
|
|
415
|
+
import { Canvas, CanvasView } from '@web-canvas-ui/react';
|
|
416
|
+
|
|
417
|
+
<Canvas ref={canvasRef} width={640} height={360}>
|
|
418
|
+
<CanvasView
|
|
419
|
+
x={20}
|
|
420
|
+
y={20}
|
|
421
|
+
source={thirdPartyCanvas}
|
|
422
|
+
width={320}
|
|
423
|
+
height={180}
|
|
424
|
+
fit="contain"
|
|
425
|
+
onPointerEvent={(event) => {
|
|
426
|
+
thirdPartyApi.handlePointer({
|
|
427
|
+
type: event.type,
|
|
428
|
+
x: event.sourceX,
|
|
429
|
+
y: event.sourceY,
|
|
430
|
+
pointerId: event.pointerId,
|
|
431
|
+
});
|
|
432
|
+
}}
|
|
433
|
+
/>
|
|
434
|
+
</Canvas>;
|
|
435
|
+
|
|
436
|
+
// After the third-party Canvas updates its content, request a redraw of the host Canvas:
|
|
437
|
+
canvasRef.current?.requestRender();
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
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.
|
|
441
|
+
|
|
442
|
+
### `<CustomDraw>`
|
|
443
|
+
|
|
444
|
+
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.
|
|
445
|
+
|
|
446
|
+
| Prop | Type | Required | Description |
|
|
447
|
+
| ------------------ | -------------------------------------------------------------------------------------- | -------: | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
448
|
+
| `width` / `height` | `number` | Yes | Size of the custom drawing region; must be non-negative finite numbers. |
|
|
449
|
+
| `draw` | `(context: CanvasRenderingContext2D, size: { width: number; height: number }) => void` | Yes | Executes synchronous drawing inside the region; `size` provides the corresponding width and height. |
|
|
450
|
+
| `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. |
|
|
451
|
+
| `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. |
|
|
452
|
+
|
|
453
|
+
```tsx
|
|
454
|
+
import { Canvas, CustomDraw } from '@web-canvas-ui/react';
|
|
455
|
+
|
|
456
|
+
<Canvas width={320} height={180}>
|
|
457
|
+
<CustomDraw
|
|
458
|
+
x={20}
|
|
459
|
+
y={20}
|
|
460
|
+
width={160}
|
|
461
|
+
height={100}
|
|
462
|
+
hitTest={(x, y) => Math.abs(y - (x * 100) / 160) < 6}
|
|
463
|
+
onClick={({ x, y }) => console.log('local position:', x, y)}
|
|
464
|
+
draw={(ctx, { width, height }) => {
|
|
465
|
+
ctx.strokeStyle = '#1668dc';
|
|
466
|
+
ctx.lineWidth = 3;
|
|
467
|
+
ctx.beginPath();
|
|
468
|
+
ctx.moveTo(0, 0);
|
|
469
|
+
ctx.lineTo(width, height);
|
|
470
|
+
ctx.stroke();
|
|
471
|
+
}}
|
|
472
|
+
/>
|
|
473
|
+
</Canvas>;
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
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. The renderer logs drawing errors to the console, skips the affected node, and continues drawing other nodes.
|
|
477
|
+
|
|
478
|
+
### `<Group>`
|
|
479
|
+
|
|
480
|
+
Used to group, position, and transform children. Supports [Common Props](#common-props), plus:
|
|
481
|
+
|
|
482
|
+
| Prop | Type | Description |
|
|
483
|
+
| -------- | ------------------------------------------------------------- | --------------------------- |
|
|
484
|
+
| Children | React children / Vue/Svelte slot / Angular content projection | Child Canvas UI components. |
|
|
485
|
+
|
|
486
|
+
```tsx
|
|
487
|
+
<Group x={20} y={30} scaleX={1.2}>
|
|
488
|
+
<Text x={10} y={10} text="Text inside a group" />
|
|
489
|
+
</Group>
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
### `<Form>` and `<FormItem>`
|
|
493
|
+
|
|
494
|
+
`Form` manages field values, validation, and submission. Each `FormItem` needs a unique `name` and exactly one direct `Input`, `Textarea`, `DatePicker`, `Radio`, `Checkbox`, `Dropdown`, `Slider`, `Switch`, or `Upload`. Child positions are relative to the item; nested forms are not supported.
|
|
495
|
+
|
|
496
|
+
```tsx
|
|
497
|
+
<Form
|
|
498
|
+
initialValues={{ email: '', role: 'Individual' }}
|
|
499
|
+
onSubmit={(values) => console.log(values)}
|
|
500
|
+
onInvalid={(errors) => console.log(errors)}
|
|
501
|
+
>
|
|
502
|
+
<FormItem
|
|
503
|
+
x={20}
|
|
504
|
+
y={20}
|
|
505
|
+
name="email"
|
|
506
|
+
rules={[
|
|
507
|
+
{ required: true, message: 'Enter an email' },
|
|
508
|
+
{ pattern: /^[^\s@]+@[^\s@]+\.[^\s@]+$/, message: 'Invalid email' },
|
|
509
|
+
]}
|
|
510
|
+
>
|
|
511
|
+
<Input placeholder="Email" />
|
|
512
|
+
</FormItem>
|
|
513
|
+
<FormItem x={20} y={90} name="role">
|
|
514
|
+
<Radio options={['Individual', 'Team']} />
|
|
515
|
+
</FormItem>
|
|
516
|
+
<Button x={20} y={140} text="Submit" formAction="submit" />
|
|
517
|
+
<Button x={160} y={140} text="Reset" formAction="reset" />
|
|
518
|
+
</Form>
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
`Form` and `FormItem` also support [Common Props](#common-props). Field value types depend on the control: `Checkbox` uses `string[]`, `Upload` uses `File[]`, `Switch` uses `boolean`, `Slider` uses `number`, and the other supported controls use `string`. The exported types include `FormValue`, `FormValues` (field names to values), and `FormErrors` (field names to error messages).
|
|
522
|
+
|
|
523
|
+
**Form props**
|
|
524
|
+
|
|
525
|
+
| Prop | Type | Required | Description |
|
|
526
|
+
| ---------------- | ------------------------------------------------- | -------- | ----------- |
|
|
527
|
+
| `children` | Child components | No | Form items, buttons, and layout components. |
|
|
528
|
+
| `initialValues` | `FormValues` | No | Initial values by field name; takes precedence over control initial values. |
|
|
529
|
+
| `controller` | `FormController` | No | Created by `createFormController()` to read or set fields. |
|
|
530
|
+
| `onSubmit` | `(values: FormValues) => void` | No | Called when submission passes validation. |
|
|
531
|
+
| `onInvalid` | `(errors: FormErrors, values: FormValues) => void` | No | Called when submission fails validation. |
|
|
532
|
+
| `onValuesChange` | `(values: FormValues) => void` | No | Called with all current field values when a field changes. |
|
|
533
|
+
| `onReset` | `() => void` | No | Called after a reset. |
|
|
534
|
+
|
|
535
|
+
**FormItem props**
|
|
536
|
+
|
|
537
|
+
| Prop | Type | Required | Default | Description |
|
|
538
|
+
| --------------- | ------------ | -------- | ----------- | ----------- |
|
|
539
|
+
| `children` | Child component | Yes | — | Must contain exactly one direct supported form control. |
|
|
540
|
+
| `name` | `string` | Yes | — | Nonempty field name, unique within the form. |
|
|
541
|
+
| `rules` | `FormRule[]` | No | `[]` | Validation rules evaluated in order. |
|
|
542
|
+
| `errorY` | `number` | No | control height + 4 | Error text's vertical position relative to the item; its horizontal position is `0`. |
|
|
543
|
+
| `errorColor` | `string` | No | `'#d93025'` | Error text color. |
|
|
544
|
+
| `errorFontSize` | `number` | No | `12` | Error text font size. |
|
|
545
|
+
|
|
546
|
+
**FormRule properties**
|
|
547
|
+
|
|
548
|
+
| Property | Type | Description |
|
|
549
|
+
| ----------- | ----------------------------------------------------------------------- | ----------- |
|
|
550
|
+
| `required` | `boolean` | When `true`, whitespace-only strings, empty arrays, and `false` fail validation; `0` is not empty. |
|
|
551
|
+
| `minLength` | `number` | Minimum length for nonempty strings or arrays. |
|
|
552
|
+
| `maxLength` | `number` | Maximum length for nonempty strings or arrays. |
|
|
553
|
+
| `pattern` | `RegExp` | Pattern that a nonempty string must match. |
|
|
554
|
+
| `validator` | `(value: FormValue, values: Readonly<FormValues>) => string \| undefined \| Promise<string \| undefined>` | Synchronous or asynchronous validation; return an error string to fail, or `undefined` or an empty string to pass. |
|
|
555
|
+
| `message` | `string` | Overrides the rule's default or custom validation error message. |
|
|
556
|
+
|
|
557
|
+
- `initialValues` supplies initial field values; otherwise the control's `value` / `defaultValue` (or `checked` / `defaultChecked` for Switch) or its default is used. Form owns these values, but the control's original `onChange` still fires.
|
|
558
|
+
- Rules run in order; validators may return a Promise, and rejections appear as `Validation failed: ...`. Required treats whitespace-only strings, empty arrays and `false` as empty. Length applies to strings and arrays; patterns apply to strings.
|
|
559
|
+
- Text inputs validate on blur, other controls when their keyboard focus leaves, and all fields on submit. After the first submit, edits revalidate the form. Submission waits for async validation; stale results after edits, reset or unmount are ignored. Errors default to 4 pixels below the control; reserve room for errors and upload lists or override `errorY`.
|
|
560
|
+
- `onValuesChange(values)` fires for field edits. A reset button restores the current `initialValues` / control defaults, clears errors and calls `onReset()`. Removed fields are omitted from submission.
|
|
561
|
+
- All four adapters export `Form`, `FormItem`, and their types. Angular uses `<canvas-form>` and `<canvas-form-item>` with `(formSubmit)`, `(formInvalid)`, `(valuesChange)`, and `(formReset)` events.
|
|
562
|
+
|
|
563
|
+
Create a controller with `createFormController()` from the framework entry point and pass it as `controller`. Once mounted, use `controller.getValues()`, `controller.getFieldValue('email')`, or `controller.setFieldValue('email', 'a@example.com')`. Setting a field fires `onValuesChange` and revalidates after a submit, but does not fire the control's `onChange`; arrays returned by the getters are copies. Unknown fields, invalid types, use while unmounted, and sharing a controller between mounted forms throw errors. Angular uses `[controller]`.
|
|
564
|
+
|
|
565
|
+
### `<Grid>`
|
|
566
|
+
|
|
567
|
+
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`.
|
|
568
|
+
|
|
569
|
+
| Prop | Type | Required | Default | Description |
|
|
570
|
+
| ------------ | ----------------------------- | -------: | ------: | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
571
|
+
| `columns` | `number` | Yes | — | Columns per row; must be a positive integer. |
|
|
572
|
+
| `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. |
|
|
573
|
+
| `height` | `number` | No | — | Fixed visible height. Overflow is clipped and a scrollbar appears; wheel scrolling works inside the Grid. |
|
|
574
|
+
| `cellWidth` | `number` | No | — | Fixed logical cell width; takes precedence over `width` auto-distribution. Must be positive. |
|
|
575
|
+
| `cellHeight` | `number` | Yes | — | Logical cell height; must be positive. |
|
|
576
|
+
| `gap` | `number` | No | `0` | Equal row and column spacing; must not be negative. |
|
|
577
|
+
| `virtual` | `boolean` | No | `false` | Mount only items near the viewport; requires `height`. |
|
|
578
|
+
| `onScroll` | `(scrollTop: number) => void` | No | — | Scroll position change callback, in logical pixels. |
|
|
579
|
+
|
|
580
|
+
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.
|
|
581
|
+
|
|
582
|
+
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.
|
|
583
|
+
|
|
584
|
+
```tsx
|
|
585
|
+
<Grid columns={3} cellWidth={100} cellHeight={50} gap={8}>
|
|
586
|
+
<Rect width={80} height={40} color="#f5f8fc" />
|
|
587
|
+
<Rect width={80} height={40} color="#e5efff" />
|
|
588
|
+
<Rect width={80} height={40} color="#d5e5ff" />
|
|
589
|
+
</Grid>
|
|
590
|
+
```
|
|
591
|
+
|
|
592
|
+
To split the total width evenly across columns, omit `cellWidth`:
|
|
593
|
+
|
|
594
|
+
```tsx
|
|
595
|
+
<Grid columns={3} width={316} cellHeight={50} gap={8}>
|
|
596
|
+
<Rect width={80} height={40} color="#f5f8fc" />
|
|
597
|
+
<Rect width={80} height={40} color="#e5efff" />
|
|
598
|
+
<Rect width={80} height={40} color="#d5e5ff" />
|
|
599
|
+
</Grid>
|
|
600
|
+
```
|
|
601
|
+
|
|
602
|
+
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.
|
|
603
|
+
|
|
604
|
+
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:
|
|
605
|
+
|
|
606
|
+
```tsx
|
|
607
|
+
<Grid columns={1} width={280} height={180} cellHeight={44} gap={4}>
|
|
608
|
+
{items.map((item) => (
|
|
609
|
+
<GridItem key={item.id}>
|
|
610
|
+
<Text text={item.label} />
|
|
611
|
+
</GridItem>
|
|
612
|
+
))}
|
|
613
|
+
</Grid>
|
|
614
|
+
```
|
|
615
|
+
|
|
616
|
+
For large data sets, use `<Grid ... height={180} virtual>` (Angular: `[virtual]="true"`). Only items within the viewport and approximately one row above and below it are mounted; the window updates as you scroll, and row and column spans still affect layout. Offscreen items are unmounted, so store uncontrolled input and other state externally using controlled values and stable keys. Visibility is based on the cell area, not overflow caused by drawing, rotation, or scaling. Initial layout and framework child creation still process all supplied items.
|
|
617
|
+
|
|
618
|
+
Where possible, unchanged static virtual grids reuse their drawing when other components repaint. Scrolling, content changes, and theme changes invalidate it. Grids containing videos, images, `CustomDraw`, or `CanvasView` are drawn normally to keep dynamic content current. In React, memoize the whole Grid element with `useMemo` to avoid recreating and compiling its children when unrelated state changes; include the data and all values affecting the list in the dependency array:
|
|
619
|
+
|
|
620
|
+
```tsx
|
|
621
|
+
const grid = useMemo(
|
|
622
|
+
() => (
|
|
623
|
+
<Grid columns={1} width={280} height={180} cellHeight={44} virtual>
|
|
624
|
+
{items.map((item) => (
|
|
625
|
+
<GridItem key={item.id}>
|
|
626
|
+
<Text text={item.label} />
|
|
627
|
+
</GridItem>
|
|
628
|
+
))}
|
|
629
|
+
</Grid>
|
|
630
|
+
),
|
|
631
|
+
[items],
|
|
632
|
+
);
|
|
633
|
+
```
|
|
634
|
+
|
|
635
|
+
### `<GridItem>`
|
|
636
|
+
|
|
637
|
+
`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.
|
|
638
|
+
|
|
639
|
+
| Prop | Type | Default | Description |
|
|
640
|
+
| -------------------------------------------- | -------- | ------: | ----------------------------------------------------------------------------- |
|
|
641
|
+
| `columnSpan` | `number` | `1` | Number of columns to span; a positive integer not exceeding Grid's `columns`. |
|
|
642
|
+
| `rowSpan` | `number` | `1` | Number of rows to span; positive integer. |
|
|
643
|
+
| `backgroundColor` | `string` | — | Draws a grid-item background covering its spanned cells. |
|
|
644
|
+
| `x` / `y` | `number` | `0` | Offset from the cell's origin. |
|
|
645
|
+
| `rotation` / `scaleX` / `scaleY` / `visible` | — | — | Same transform and visibility props as `Group`. |
|
|
646
|
+
|
|
647
|
+
Grid places items row by row, skipping cells already occupied by spanning items:
|
|
648
|
+
|
|
649
|
+
```tsx
|
|
650
|
+
<Grid columns={3} width={316} cellHeight={50} gap={8}>
|
|
651
|
+
<GridItem columnSpan={2}>
|
|
652
|
+
<Rect width={180} height={40} color="#f5f8fc" />
|
|
653
|
+
<Text x={8} y={8} text="Group spanning two columns" />
|
|
654
|
+
</GridItem>
|
|
655
|
+
<Rect width={80} height={40} color="#e5efff" />
|
|
656
|
+
</Grid>
|
|
657
|
+
```
|
|
658
|
+
|
|
659
|
+
Vue and Svelte use the same `<GridItem>`; Angular uses `<canvas-grid-item [columnSpan]="2">...</canvas-grid-item>` and imports `GridItem` from the corresponding module.
|
|
660
|
+
|
|
661
|
+
### `<Image>`
|
|
662
|
+
|
|
663
|
+
`Image`, `Text`, and `Icon` accept an optional `onClick: () => void`. Only nodes with a click listener participate in hit testing; the clickable area is the component's bounding box. Angular uses `(click)`; Vue uses `@click`; React and Svelte use `onClick`.
|
|
664
|
+
|
|
665
|
+
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.
|
|
666
|
+
|
|
667
|
+
| Prop | Type | Required | Default | Description |
|
|
668
|
+
| ------------------ | ---------------------------------------------------------- | -------: | ----------- | ----------------------------------- |
|
|
669
|
+
| `src` | `string` | Yes | — | Image URL. |
|
|
670
|
+
| `width` / `height` | `number` | Yes | — | Canvas logical size. |
|
|
671
|
+
| `objectFit` | `"contain" \| "cover" \| "fill" \| "none" \| "scale-down"` | No | `"contain"` | Image scaling and cropping mode. |
|
|
672
|
+
| `onError` | `(error: Error) => void` | No | — | Fires when the image fails to load. |
|
|
673
|
+
| `onClick` | `() => void` | No | — | Click callback. |
|
|
674
|
+
|
|
675
|
+
```tsx
|
|
676
|
+
<Image x={16} y={16} src="/avatar.png" width={96} height={96} objectFit="cover" />
|
|
677
|
+
```
|
|
678
|
+
|
|
679
|
+
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.
|
|
680
|
+
|
|
681
|
+
### `<Video>`
|
|
682
|
+
|
|
683
|
+
Loads a video from `src` and paints its frames into the Canvas through the engine's render loop — no extra animation loop is created. Every `<Video>` node owns a dedicated `<video>` element: nodes sharing the same `src` can still be played, paused and seeked independently, and the element is released automatically when the node leaves the scene. `objectFit` supports the same modes as `<Image>`. Set `controls` to draw the built-in controls bar — a play/pause toggle, a seekable progress track and the time text — and to make the bar's regions pointer-interactive.
|
|
684
|
+
|
|
685
|
+
| Prop | Type | Required | Default | Description |
|
|
686
|
+
| -------------------- | ---------------------------------------------------------- | -------: | -------------------------- | ------------------------------------------------------------------------------------------- |
|
|
687
|
+
| `src` | `string` | Yes | — | Video URL. |
|
|
688
|
+
| `width` / `height` | `number` | No | Video's native | Canvas logical size; defaults to the video's intrinsic size. |
|
|
689
|
+
| `objectFit` | `"contain" \| "cover" \| "fill" \| "none" \| "scale-down"` | No | `"contain"` | Video scaling and cropping mode, identical to `<Image>`. |
|
|
690
|
+
| `autoplay` | `boolean` | No | `false` | Start playback automatically; browsers require `muted` for autoplay to succeed. |
|
|
691
|
+
| `loop` | `boolean` | No | `false` | Restart from the beginning when playback ends. |
|
|
692
|
+
| `muted` | `boolean` | No | `false` | Mute the audio track. |
|
|
693
|
+
| `paused` | `boolean` | No | — | Declarative play/pause: `false` plays, `true` pauses; omitted leaves control to `autoplay`. |
|
|
694
|
+
| `currentTime` | `number` | No | — | Seek target in seconds; set it once to jump, not on every frame. |
|
|
695
|
+
| `controls` | `boolean` | No | `false` | Show the built-in controls bar and accept pointer input on its toggle and track. |
|
|
696
|
+
| `controlsOnHover` | `boolean` | No | `false` | Show controls on hover; on touch devices, tap the video to show or hide them. |
|
|
697
|
+
| `controlsBarColor` | `string` | No | `"rgba(0,0,0,0.55)"` | Background of the controls bar. |
|
|
698
|
+
| `controlsColor` | `string` | No | `"#fff"` | Play/pause icon, played track, thumb and time text color. |
|
|
699
|
+
| `controlsTrackColor` | `string` | No | `"rgba(255,255,255,0.35)"` | Idle part of the seek track. |
|
|
700
|
+
| `onError` | `(error: Error) => void` | No | — | Fires when the video fails to load. |
|
|
701
|
+
| `onTimeUpdate` | `(currentTime: number, duration: number) => void` | No | — | Fires on playback progress, driven by the video's native `timeupdate` event. |
|
|
702
|
+
| `onPausedChange` | `(paused: boolean) => void` | No | — | Fires when the user toggles playback through the controls bar. |
|
|
703
|
+
| `onSeek` | `(currentTime: number) => void` | No | — | Fires when the user seeks through the controls bar (press or drag on the track). |
|
|
704
|
+
|
|
705
|
+
```tsx
|
|
706
|
+
<Video
|
|
707
|
+
x={16}
|
|
708
|
+
y={16}
|
|
709
|
+
src="/clip.mp4"
|
|
710
|
+
width={320}
|
|
711
|
+
height={180}
|
|
712
|
+
objectFit="cover"
|
|
713
|
+
muted
|
|
714
|
+
autoplay
|
|
715
|
+
loop
|
|
716
|
+
controls
|
|
717
|
+
controlsOnHover
|
|
718
|
+
onSeek={(currentTime) => console.log(currentTime)}
|
|
719
|
+
/>
|
|
720
|
+
```
|
|
721
|
+
|
|
722
|
+
During a seek, the previous frame stays visible until the target frame can be drawn. Seeking to unbuffered content may still require the browser to load data. When controlling `paused`, update its state in `onPausedChange` so the next update does not undo a controls-bar action.
|
|
723
|
+
|
|
724
|
+
The fullscreen button opens the current video in the browser's native fullscreen player. Native play, pause, and seek actions also trigger `onPausedChange` and `onSeek`. Native controls take precedence while fullscreen is active: `paused`, `autoplay`, and `currentTime` are not applied to the player until fullscreen exits. Fullscreen errors are reported through `onError`, or logged if no handler is provided.
|
|
725
|
+
|
|
726
|
+
Browser autoplay policies apply: without `muted`, playback only starts after a user gesture. Videos are first loaded with CORS; on failure, loading is retried without CORS, although the browser may still report the initial error in its console. A cross-origin video loaded without CORS can play, but drawing it taints the Canvas and prevents pixel reads and PNG export. For export, use a same-origin video or configure the video server to return an `Access-Control-Allow-Origin` header permitting the current site. Angular uses `<canvas-video>`, with `(videoError)`, `(timeUpdate)`, `(pausedChange)` and `(seek)` event bindings.
|
|
727
|
+
|
|
728
|
+
### `<Progress>`
|
|
729
|
+
|
|
730
|
+
Draws a non-interactive progress bar. `value` is clamped between `min` and `max`.
|
|
731
|
+
|
|
732
|
+
| Prop | Type | Default | Description |
|
|
733
|
+
| ------------------------------------ | --------- | -------------: | --------------------------------------------------------- |
|
|
734
|
+
| `value` | `number` | Required | Current progress value. |
|
|
735
|
+
| `min` / `max` | `number` | `0` / `100` | Progress range. |
|
|
736
|
+
| `width` / `height` | `number` | `200` / `12` | Track size. |
|
|
737
|
+
| `color` / `trackColor` / `textColor` | `string` | Theme colors | Progress, track, and text colors; explicit props win. |
|
|
738
|
+
| `borderRadius` | `number` | Half of height | Corner radius. |
|
|
739
|
+
| `showText` | `boolean` | `false` | Whether to draw the percentage to the right of the track. |
|
|
740
|
+
|
|
741
|
+
### `<Carousel>` and `<CarouselItem>`
|
|
742
|
+
|
|
743
|
+
`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.
|
|
744
|
+
|
|
745
|
+
| Component | Prop | Type | Default | Description |
|
|
746
|
+
| -------------- | -------------------------------------------- | ------------------------- | ----------------------------------------------------------- | --------------------------------------------------------------------------- |
|
|
747
|
+
| `Carousel` | `width` / `height` | `number` | Required | Viewport size; content overflowing the bounds is clipped. |
|
|
748
|
+
| `Carousel` | `activeIndex` | `number` | — | Controlled current index; combine with `onChange` to update. |
|
|
749
|
+
| `Carousel` | `defaultActiveIndex` | `number` | `0` | Uncontrolled initial index. |
|
|
750
|
+
| `Carousel` | `autoplay` | `boolean` | `true` | Whether to auto-advance; disabled when there are fewer than two items. |
|
|
751
|
+
| `Carousel` | `interval` | `number` | `3000` | Autoplay interval in ms; treated as a minimum of `250`. |
|
|
752
|
+
| `Carousel` | `transitionDuration` | `number` | `450` | Horizontal slide transition duration in ms; set `0` to switch instantly. |
|
|
753
|
+
| `Carousel` | `loop` | `boolean` | `true` | Whether to loop back to the first item at the end. |
|
|
754
|
+
| `Carousel` | `showArrows` / `showDots` | `boolean` | `true` | Whether to show the prev/next arrows and bottom indicator dots. |
|
|
755
|
+
| `Carousel` | `backgroundColor` | `string` | `"transparent"` | Viewport background color. |
|
|
756
|
+
| `Carousel` | `arrowColor` / `dotColor` / `activeDotColor` | `string` | theme / `"#fff"` / `"rgba(255,255,255,0.65)"` / `"#1677ff"` | Arrow, inactive dot and active dot colors; the listed colors are fallbacks. |
|
|
757
|
+
| `Carousel` | `onChange` | `(index: number) => void` | — | Fires when the active index changes. |
|
|
758
|
+
| `CarouselItem` | Children | Canvas UI components | — | Content shown for this slide. |
|
|
759
|
+
|
|
760
|
+
```tsx
|
|
761
|
+
<Carousel width={320} height={180} interval={4000} onChange={setActiveIndex}>
|
|
762
|
+
<CarouselItem>
|
|
763
|
+
<Image width={320} height={180} src="/banner-one.jpg" objectFit="cover" />
|
|
764
|
+
</CarouselItem>
|
|
765
|
+
<CarouselItem>
|
|
766
|
+
<Image width={320} height={180} src="/banner-two.jpg" objectFit="cover" />
|
|
767
|
+
</CarouselItem>
|
|
768
|
+
</Carousel>
|
|
769
|
+
```
|
|
770
|
+
|
|
771
|
+
Angular uses `<canvas-carousel>` and `<canvas-carousel-item>`; controlled index changes use `(activeIndexChange)`.
|
|
772
|
+
|
|
773
|
+
### `<Tabs>` and `<TabItem>`
|
|
774
|
+
|
|
775
|
+
`Tabs` uses `TabItem` to declare tabs and their corresponding Canvas subtrees. The first `TabItem` is selected by default.
|
|
776
|
+
|
|
777
|
+
| Component | Prop | Type | Description |
|
|
778
|
+
| --------- | ------------------------------------------------------------------ | ------------------------------------- | ------------------------------------------------------------------------------------------------------- |
|
|
779
|
+
| `Tabs` | `width` / `height` | `number` | Size of the tab container; required. Content is drawn below the header and clipped to the content area. |
|
|
780
|
+
| `Tabs` | `activeKey` / `defaultActiveKey` | `string` | Controlled selected key / uncontrolled initial key. |
|
|
781
|
+
| `Tabs` | `headerHeight` | `number` | Header bar height; default `40`. |
|
|
782
|
+
| `Tabs` | `backgroundColor` / `textColor` / `activeColor` / `indicatorColor` | `string` | Colors for the tab bar, text, active state, and indicator line. |
|
|
783
|
+
| `Tabs` | `onChange` | `(key: string) => void` | Fires when the selected tab changes. |
|
|
784
|
+
| `TabItem` | `id` / `title` | `string` | Unique identifier and label; required. |
|
|
785
|
+
| `TabItem` | `disabled` | `boolean` | Disables clicking on this tab. |
|
|
786
|
+
| `TabItem` | `size` | `{ width?: number; height?: number }` | Optional in the public type; currently does not determine the header or content area size. |
|
|
787
|
+
| `TabItem` | Children | Canvas UI components | Canvas content for this tab. |
|
|
788
|
+
|
|
789
|
+
```tsx
|
|
790
|
+
<Tabs width={320} height={180} defaultActiveKey="profile">
|
|
791
|
+
<TabItem id="profile" title="Profile">
|
|
792
|
+
<Text x={12} y={12} text="Profile content" />
|
|
793
|
+
</TabItem>
|
|
794
|
+
<TabItem id="settings" title="Settings">
|
|
795
|
+
<Text x={12} y={12} text="Settings content" />
|
|
796
|
+
</TabItem>
|
|
797
|
+
</Tabs>
|
|
798
|
+
```
|
|
799
|
+
|
|
800
|
+
Angular counterparts are `<canvas-tabs>` and `<canvas-tab-item>`; selection changes use `(activeKeyChange)`.
|
|
801
|
+
|
|
802
|
+
### `<Collapse>` and `<CollapseItem>`
|
|
803
|
+
|
|
804
|
+
Each `CollapseItem` header toggles its panel; children serve as panel content.
|
|
805
|
+
|
|
806
|
+
| Component | Prop | Type | Description |
|
|
807
|
+
| -------------- | ----------------------------------------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------- |
|
|
808
|
+
| `Collapse` | `width` | `number` | Panel width; required. |
|
|
809
|
+
| `Collapse` | `activeKeys` / `defaultActiveKeys` | `string[]` | Controlled expanded items / uncontrolled initial expanded items. |
|
|
810
|
+
| `Collapse` | `accordion` | `boolean` | Default `false`; when `true` only one item can be expanded at a time. |
|
|
811
|
+
| `Collapse` | `headerHeight` | `number` | Header bar height; default `40`. |
|
|
812
|
+
| `Collapse` | `backgroundColor` / `textColor` / `borderColor` | `string` | Default background, text, and border colors for all headers. |
|
|
813
|
+
| `Collapse` | `onChange` | `(keys: string[]) => void` | Fires when the expanded set changes. |
|
|
814
|
+
| `CollapseItem` | `id` / `title` | `string` | Unique panel identifier and title; required. |
|
|
815
|
+
| `CollapseItem` | `height` | `number` | Expanded content height. Defaults to the space its children need, never below `100`; an explicit value always wins. |
|
|
816
|
+
| `CollapseItem` | `disabled` | `boolean` | Blocks expand/collapse. |
|
|
817
|
+
| `CollapseItem` | `backgroundColor` / `textColor` / `borderColor` | `string` | Overrides the corresponding colors for this item's header. |
|
|
818
|
+
|
|
819
|
+
```tsx
|
|
820
|
+
<Collapse width={320} defaultActiveKeys={['details']} accordion>
|
|
821
|
+
<CollapseItem id="details" title="Details" height={72}>
|
|
822
|
+
<Text x={12} y={8} text="Panel content" />
|
|
823
|
+
</CollapseItem>
|
|
824
|
+
<CollapseItem id="more" title="More">
|
|
825
|
+
<Text x={12} y={8} text="Another panel" />
|
|
826
|
+
</CollapseItem>
|
|
827
|
+
</Collapse>
|
|
828
|
+
```
|
|
829
|
+
|
|
830
|
+
Angular counterparts are `<canvas-collapse>` and `<canvas-collapse-item>`; expansion changes use `(activeKeysChange)`.
|
|
831
|
+
|
|
832
|
+
### `<Dialog>`
|
|
833
|
+
|
|
834
|
+
The confirmation dialog overlays the Canvas centered by default, painting a mask, title, content area, and built-in Cancel/Confirm buttons. Only inputs in the topmost dialog are editable while it is open; background inputs are blocked and dialog inputs are clipped to the content area. Focus cycles within the dialog, Escape invokes `onCancel`, and closing restores the previous focus. The mask and focus restriction apply to this Canvas; applications must manage page content outside it.
|
|
835
|
+
|
|
836
|
+
| Prop | Type | Default | Description |
|
|
837
|
+
| ---------------------------- | -------------------- | ------------------: | -------------------------------------------------------- |
|
|
838
|
+
| `open` | `boolean` | Required | Whether the dialog is shown. |
|
|
839
|
+
| `width` / `height` | `number` | `420` / `240` | Dialog size. |
|
|
840
|
+
| `title` | `string` | `"Confirm"` | Title. |
|
|
841
|
+
| `confirmText` / `cancelText` | `string` | `"OK"` / `"Cancel"` | Built-in button labels. |
|
|
842
|
+
| `closeOnBackdrop` | `boolean` | `true` | Whether clicking the mask triggers the cancel callback. |
|
|
843
|
+
| `onConfirm` / `onCancel` | `() => void` | — | Confirm and cancel callbacks. |
|
|
844
|
+
| Children | Canvas UI components | — | Dialog content area; any Canvas UI component is allowed. |
|
|
845
|
+
|
|
846
|
+
```tsx
|
|
847
|
+
<Dialog
|
|
848
|
+
open={open}
|
|
849
|
+
title="Delete item?"
|
|
850
|
+
onConfirm={() => {
|
|
851
|
+
deleteItem();
|
|
852
|
+
setOpen(false);
|
|
853
|
+
}}
|
|
854
|
+
onCancel={() => setOpen(false)}
|
|
855
|
+
>
|
|
856
|
+
<Text width={340} text="This action cannot be undone." />
|
|
857
|
+
</Dialog>
|
|
858
|
+
```
|
|
859
|
+
|
|
860
|
+
Angular uses `<canvas-dialog>`, with the `open` input and `(confirm)` / `(cancel)` outputs.
|
|
861
|
+
|
|
862
|
+
### `<Rect>`
|
|
863
|
+
|
|
864
|
+
Draws a rectangle. Supports [Common Props](#common-props).
|
|
865
|
+
|
|
866
|
+
| Prop | Type | Default | Description |
|
|
867
|
+
| ------------- | -------- | ----------------------: | -------------------------------------- |
|
|
868
|
+
| `width` | `number` | `100` | Width. |
|
|
869
|
+
| `height` | `number` | `40` | Height. |
|
|
870
|
+
| `color` | `string` | theme / `"transparent"` | Fill color. |
|
|
871
|
+
| `radius` | `number` | `0` | Corner radius. |
|
|
872
|
+
| `stroke` | `string` | — | Stroke color; omitted means no stroke. |
|
|
873
|
+
| `strokeWidth` | `number` | `1` | Stroke width. |
|
|
874
|
+
|
|
875
|
+
### `<Circle>`
|
|
876
|
+
|
|
877
|
+
Draws a circle. Supports [Common Props](#common-props).
|
|
878
|
+
|
|
879
|
+
| Prop | Type | Default | Description |
|
|
880
|
+
| ------------- | -------- | ------------------: | -------------------------------------- |
|
|
881
|
+
| `radius` | `number` | `10` | Circle radius. |
|
|
882
|
+
| `color` | `string` | theme / `"#e74c3c"` | Fill color. |
|
|
883
|
+
| `stroke` | `string` | — | Stroke color; omitted means no stroke. |
|
|
884
|
+
| `strokeWidth` | `number` | `1` | Stroke width. |
|
|
885
|
+
|
|
886
|
+
### `<Text>`
|
|
887
|
+
|
|
888
|
+
Draws single-line or auto-wrapped text. Pass content through `text`; `<Text>` does not accept children. Other non-container components also reject child components; `<Button>` accepts plain text children only. 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).
|
|
889
|
+
|
|
890
|
+
| Prop | Type | Default | Description |
|
|
891
|
+
| ------------ | -------------------- | ---------------: | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
892
|
+
| `text` | `string` | — | Text content. |
|
|
893
|
+
| `fontSize` | `number` | `16` | Font size, in logical pixels. |
|
|
894
|
+
| `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. |
|
|
895
|
+
| `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. |
|
|
896
|
+
| `fontFamily` | `string` | `"sans-serif"` | Font family. |
|
|
897
|
+
| `color` | `string` | theme / `"#333"` | Font color. |
|
|
898
|
+
| `baseline` | `CanvasTextBaseline` | `"top"` | Canvas text baseline. |
|
|
899
|
+
| `textAlign` | `CanvasTextAlign` | `"left"` | Horizontal alignment within the text box; only `center` and `right` are special, other values render as `left`. |
|
|
900
|
+
| `onClick` | `() => void` | — | Click callback. |
|
|
901
|
+
|
|
902
|
+
### `<Icon>`
|
|
903
|
+
|
|
904
|
+
Original vector icons with no dependency on icon fonts or external images. Supports [Common Props](#common-props).
|
|
905
|
+
|
|
906
|
+
| Prop | Type | Default | Description |
|
|
907
|
+
| ------------- | ---------------------- | ---------------: | ---------------------------------------------------------------------------------------- |
|
|
908
|
+
| `name` | `IconName` | Required | Icon name; see the list below. |
|
|
909
|
+
| `size` | `number` | `24` | Icon width and height. |
|
|
910
|
+
| `color` | `string` | theme / `"#333"` | Icon color; can be set via `--canvas-ui-icon-color`. |
|
|
911
|
+
| `variant` | `"outline" \| "solid"` | `"outline"` | `outline` for stroked shapes; `solid` uses thicker strokes and fills the primary shapes. |
|
|
912
|
+
| `strokeWidth` | `number` | `2` | Outline stroke width; solid style uses at least `4`. |
|
|
913
|
+
| `onClick` | `() => void` | — | Click callback. |
|
|
914
|
+
|
|
915
|
+
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`.
|
|
916
|
+
|
|
917
|
+
```tsx
|
|
918
|
+
<Icon name="search" x={16} y={16} size={28} color="#1677ff" />
|
|
919
|
+
<Icon name="heart" x={56} y={16} variant="solid" color="#e74c3c" />
|
|
920
|
+
```
|
|
921
|
+
|
|
922
|
+
### `<Input>`
|
|
923
|
+
|
|
924
|
+
Single-line input. The control's appearance is painted onto the Canvas; a transparent HTML input handles keyboard, IME, and selection.
|
|
925
|
+
|
|
926
|
+
| Prop | Type | Default | Description |
|
|
927
|
+
| ------------------ | ---------------------------------- | ------------------: | ------------------------------------------------------------ |
|
|
928
|
+
| `width` / `height` | `number` | `200` / `36` | Control size. |
|
|
929
|
+
| `value` | `string` | — | Controlled input value; pair with `onChange` to update. |
|
|
930
|
+
| `defaultValue` | `string` | `""` | Uncontrolled initial value. |
|
|
931
|
+
| `placeholder` | `string` | `""` | Placeholder text. |
|
|
932
|
+
| `type` | `"text" \| "password" \| "number"` | `"text"` | Input type. Password content is shown as dots on the Canvas. |
|
|
933
|
+
| `fontSize` | `number` | `14` | Font size. |
|
|
934
|
+
| `fontFamily` | `string` | `"sans-serif"` | Font family. |
|
|
935
|
+
| `color` | `string` | theme / `"#333"` | Input text color. |
|
|
936
|
+
| `bgColor` | `string` | theme / `"#fff"` | Background color. |
|
|
937
|
+
| `borderColor` | `string` | theme / `"#d9d9d9"` | Normal border color. |
|
|
938
|
+
| `focusBorderColor` | `string` | theme / `"#1677ff"` | Focused border color. |
|
|
939
|
+
| `borderRadius` | `number` | `4` | Corner radius. |
|
|
940
|
+
| `padding` | `number` | `8` | Text padding. |
|
|
941
|
+
| `disabled` | `boolean` | `false` | Disables input. |
|
|
942
|
+
| `maxLength` | `number` | — | Max character count; a non-negative integer takes effect. |
|
|
943
|
+
| `onChange` | `(value: string) => void` | — | Fires when the input changes. |
|
|
944
|
+
| `onFocus` | `() => void` | — | Fires when focused. |
|
|
945
|
+
| `onBlur` | `() => void` | — | Fires when blurred. |
|
|
946
|
+
|
|
947
|
+
### `<Textarea>`
|
|
948
|
+
|
|
949
|
+
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:
|
|
950
|
+
|
|
951
|
+
| Prop | Type | Description |
|
|
952
|
+
| ------ | -------- | ----------------------------------------------------------------------------------------------------- |
|
|
953
|
+
| `rows` | `number` | Can express the expected number of lines; the actual rendered height is still controlled by `height`. |
|
|
954
|
+
|
|
955
|
+
```tsx
|
|
956
|
+
<Textarea
|
|
957
|
+
width={300}
|
|
958
|
+
height={120}
|
|
959
|
+
value={notes}
|
|
960
|
+
placeholder="Enter multi-line content"
|
|
961
|
+
onChange={setNotes}
|
|
962
|
+
/>
|
|
963
|
+
```
|
|
964
|
+
|
|
965
|
+
### `<Upload>`
|
|
966
|
+
|
|
967
|
+
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. Supports [Common Props](#common-props).
|
|
968
|
+
|
|
969
|
+
| Prop | Type | Default | Description |
|
|
970
|
+
| ------------------ | ------------------------- | ----------------------: | -------------------------------------------------------------------------- |
|
|
971
|
+
| `width` / `height` | `number` | `120` / `40` | Button size. |
|
|
972
|
+
| `text` | `string` | `"Choose File"` | Button label. |
|
|
973
|
+
| `icon` | `IconName` | `"upload"` | Built-in icon drawn before the label; use any name from [`<Icon>`](#icon). |
|
|
974
|
+
| `iconSize` | `number` | `round(fontSize × 1.1)` | Icon size. |
|
|
975
|
+
| `accept` | `string` | — | File type filter, e.g. `"image/*,.pdf"`. |
|
|
976
|
+
| `multiple` | `boolean` | `false` | Allow multi-selection. |
|
|
977
|
+
| `value` / `defaultValue` | `File[]` | `[]` | Controlled file list / uncontrolled initial list. |
|
|
978
|
+
| `maxSize` | `number` | — | Maximum size per file, in bytes. |
|
|
979
|
+
| `disabled` | `boolean` | `false` | Disables file selection. |
|
|
980
|
+
| `backgroundColor` | `string` | theme / `"#1677ff"` | Button background color. |
|
|
981
|
+
| `textColor` | `string` | theme / `"#fff"` | Label and icon color. |
|
|
982
|
+
| `borderColor` | `string` | — | Border color; omitted means no border. |
|
|
983
|
+
| `borderRadius` | `number` | `6` | Corner radius. |
|
|
984
|
+
| `fontSize` | `number` | `15` | Label font size. |
|
|
985
|
+
| `onChange` | `(files: File[]) => void` | — | Receives the complete list after selection or removal; canceled picks do not fire. |
|
|
986
|
+
| `onReject` | `(files: UploadRejection[]) => void` | — | Rejected files and their reasons (`type` or `size`). |
|
|
987
|
+
|
|
988
|
+
```tsx
|
|
989
|
+
<Upload accept="image/*" multiple onChange={(files) => console.log(files)} />
|
|
990
|
+
<Upload icon="cloud" text="Upload Photos" />
|
|
991
|
+
```
|
|
992
|
+
|
|
993
|
+
Files and removal buttons appear below the picker. Single selection replaces the file; multiple selection appends. `accept` and `maxSize` are checked locally; validate files on the server too. Angular uses `<canvas-upload>`, `(change)` and `(reject)`.
|
|
994
|
+
|
|
995
|
+
### `<Dropdown>`
|
|
996
|
+
|
|
997
|
+
Canvas-drawn dropdown select. Supports [Common Props](#common-props).
|
|
998
|
+
|
|
999
|
+
| Prop | Type | Default | Description |
|
|
1000
|
+
| ------------------ | --------------------------------- | ------------------: | ------------------------------------------------------------------- |
|
|
1001
|
+
| `width` / `height` | `number` | `200` / `36` | Control size. |
|
|
1002
|
+
| `options` | `Array<string \| DropdownOption>` | Required | Option list; string options use the same value for label and value. |
|
|
1003
|
+
| `value` | `string` | — | Controlled selected value. |
|
|
1004
|
+
| `defaultValue` | `string` | — | Uncontrolled initial value. |
|
|
1005
|
+
| `placeholder` | `string` | `"Select..."` | Text shown when nothing is selected. |
|
|
1006
|
+
| `disabled` | `boolean` | `false` | Disables interaction. |
|
|
1007
|
+
| `fontSize` | `number` | `14` | Font size. |
|
|
1008
|
+
| `color` | `string` | theme / `"#333"` | Text color; the arrow fallback is `"#555"`. |
|
|
1009
|
+
| `bgColor` | `string` | theme / `"#fff"` | Control background. |
|
|
1010
|
+
| `borderColor` | `string` | theme / `"#d9d9d9"` | Normal border color. |
|
|
1011
|
+
| `focusBorderColor` | `string` | theme / `"#1677ff"` | Opened border color. |
|
|
1012
|
+
| `borderRadius` | `number` | `4` | Corner radius. |
|
|
1013
|
+
| `onChange` | `(value: string) => void` | — | Selection change callback. |
|
|
1014
|
+
|
|
1015
|
+
`DropdownOption` type:
|
|
1016
|
+
|
|
1017
|
+
| Prop | Type | Description |
|
|
1018
|
+
| ---------- | --------- | ------------------------------- |
|
|
1019
|
+
| `label` | `string` | Display text. |
|
|
1020
|
+
| `value` | `string` | Option value. |
|
|
1021
|
+
| `disabled` | `boolean` | Whether the option is disabled. |
|
|
1022
|
+
|
|
1023
|
+
```tsx
|
|
1024
|
+
<Dropdown
|
|
1025
|
+
value={role}
|
|
1026
|
+
options={['Admin', { label: 'readOnly', value: 'reader', disabled: false }]}
|
|
1027
|
+
onChange={setRole}
|
|
1028
|
+
/>
|
|
1029
|
+
```
|
|
1030
|
+
|
|
1031
|
+
### `<DatePicker>`
|
|
1032
|
+
|
|
1033
|
+
Canvas-drawn date input; clicking opens the browser's native date picker.
|
|
1034
|
+
|
|
1035
|
+
| Prop | Type | Default | Description |
|
|
1036
|
+
| ---------------------------------- | ------------------------- | --------------------------------: | -------------------------------------------------------------- |
|
|
1037
|
+
| `width` / `height` | `number` | `200` / `36` | Control size. |
|
|
1038
|
+
| `value` | `string` | — | Controlled date value, format `YYYY-MM-DD`. |
|
|
1039
|
+
| `defaultValue` | `string` | `""` | Uncontrolled initial date value. |
|
|
1040
|
+
| `placeholder` | `string` | `"Select date"` | Text shown when nothing is selected. |
|
|
1041
|
+
| `disabled` | `boolean` | `false` | Disables date selection. |
|
|
1042
|
+
| `fontSize` | `number` | `14` | Text font size. |
|
|
1043
|
+
| `color` | `string` | theme / `"#333"` | Date text color; icon fallback is `"#666"`. |
|
|
1044
|
+
| `bgColor` | `string` | theme / `"#fff"` | Background color. |
|
|
1045
|
+
| `borderColor` / `focusBorderColor` | `string` | theme / `"#d9d9d9"` / `"#1677ff"` | Normal and focused border colors; listed colors are fallbacks. |
|
|
1046
|
+
| `borderRadius` | `number` | `4` | Corner radius. |
|
|
1047
|
+
| `onChange` | `(value: string) => void` | — | Fires when the date changes. |
|
|
1048
|
+
| `onFocus` / `onBlur` | `() => void` | — | Called when focus is gained / lost. |
|
|
1049
|
+
|
|
1050
|
+
### `<Radio>` and `<Checkbox>`
|
|
1051
|
+
|
|
1052
|
+
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.
|
|
1053
|
+
|
|
1054
|
+
| Prop | Type | Default | Description |
|
|
1055
|
+
| --------------------------------------------------------- | ----------------------------------------------------------------------- | ---------------------------------------------------------: | -------------------------------------------------------------------------------- |
|
|
1056
|
+
| `options` | `Array<string \| ChoiceOption>` | Required | Option list. |
|
|
1057
|
+
| `value` | Radio: `string`; Checkbox: `string[]` | — | Controlled selected value. |
|
|
1058
|
+
| `defaultValue` | Radio: `string`; Checkbox: `string[]` | — | Uncontrolled initial value. |
|
|
1059
|
+
| `direction` | `"horizontal" \| "vertical"` | `"horizontal"` | Option layout direction. |
|
|
1060
|
+
| `width` / `height` | `number` | Auto | Control size. |
|
|
1061
|
+
| `size` | `{ width?: number; height?: number }` | — | Each dimension takes precedence over `width` / `height`. |
|
|
1062
|
+
| `disabled` | `boolean` | `false` | Disables the whole group. |
|
|
1063
|
+
| `gap` / `optionHeight` | `number` | `12` / `28` | Spacing between options and option height. |
|
|
1064
|
+
| `fontSize` | `number` | `14` | Option label font size. |
|
|
1065
|
+
| `color` / `activeColor` / `disabledColor` / `borderColor` | `string` | theme / `"#333"` / `"#1677ff"` / `"#bfbfbf"` / `"#d9d9d9"` | Label, selected, disabled option and border colors; listed colors are fallbacks. |
|
|
1066
|
+
| `onChange` | Radio: `(value: string) => void`; Checkbox: `(value: string[]) => void` | — | Fires when the selection changes. |
|
|
1067
|
+
|
|
1068
|
+
```tsx
|
|
1069
|
+
<Radio options={['Small', 'Medium', 'Large']} value={size} onChange={setSize} />
|
|
1070
|
+
<Checkbox options={['Email', 'SMS']} value={channels} onChange={setChannels} />
|
|
1071
|
+
```
|
|
1072
|
+
|
|
1073
|
+
Angular uses `<canvas-date-picker>`, `<canvas-radio>`, and `<canvas-checkbox>`; date selection listens via `(valueChange)` or `(change)`, and Radio/Checkbox use `(change)`.
|
|
1074
|
+
|
|
1075
|
+
### `<Slider>`
|
|
1076
|
+
|
|
1077
|
+
Draggable slider. Supports [Common Props](#common-props).
|
|
1078
|
+
|
|
1079
|
+
| Prop | Type | Default | Description |
|
|
1080
|
+
| ------------------ | ------------------------- | ------------------: | ------------------------------ |
|
|
1081
|
+
| `width` / `height` | `number` | `160` / `32` | Slider size. |
|
|
1082
|
+
| `min` / `max` | `number` | `0` / `100` | Min and max values. |
|
|
1083
|
+
| `step` | `number` | `1` | Step size. |
|
|
1084
|
+
| `value` | `number` | — | Controlled value. |
|
|
1085
|
+
| `defaultValue` | `number` | `min` | Uncontrolled initial value. |
|
|
1086
|
+
| `disabled` | `boolean` | `false` | Disables dragging. |
|
|
1087
|
+
| `trackColor` | `string` | theme / `"#f0f0f0"` | Track color. |
|
|
1088
|
+
| `activeColor` | `string` | theme / `"#1677ff"` | Filled track and border color. |
|
|
1089
|
+
| `thumbColor` | `string` | theme / `"#fff"` | Thumb color. |
|
|
1090
|
+
| `onChange` | `(value: number) => void` | — | Fires when the value changes. |
|
|
1091
|
+
|
|
1092
|
+
### `<Switch>`
|
|
1093
|
+
|
|
1094
|
+
Toggle switch. Supports [Common Props](#common-props).
|
|
1095
|
+
|
|
1096
|
+
| Prop | Type | Default | Description |
|
|
1097
|
+
| ------------------ | ---------------------------- | ------------------: | ----------------------------- |
|
|
1098
|
+
| `width` / `height` | `number` | `44` / `24` | Switch size. |
|
|
1099
|
+
| `checked` | `boolean` | — | Controlled checked state. |
|
|
1100
|
+
| `defaultChecked` | `boolean` | `false` | Uncontrolled initial state. |
|
|
1101
|
+
| `disabled` | `boolean` | `false` | Blocks toggling. |
|
|
1102
|
+
| `onColor` | `string` | theme / `"#1677ff"` | Track color when on. |
|
|
1103
|
+
| `offColor` | `string` | theme / `"#d9d9d9"` | Track color when off. |
|
|
1104
|
+
| `thumbColor` | `string` | theme / `"#fff"` | Thumb color. |
|
|
1105
|
+
| `onChange` | `(checked: boolean) => void` | — | Fires when the state changes. |
|
|
1106
|
+
|
|
1107
|
+
### `<Button>`
|
|
1108
|
+
|
|
1109
|
+
Canvas-drawn button. Supports [Common Props](#common-props).
|
|
1110
|
+
|
|
1111
|
+
| Prop | Type | Default | Description |
|
|
1112
|
+
| ------------------ | ------------------ | ------------------: | ---------------------------------------------------------- |
|
|
1113
|
+
| `width` / `height` | `number` | `120` / `40` | Button size. |
|
|
1114
|
+
| Children | `string \| number` | — | Button label; can be replaced by `text`. |
|
|
1115
|
+
| `text` | `string` | — | Button label; wins over `children` when both are provided. |
|
|
1116
|
+
| `fontSize` | `number` | `15` | Font size. |
|
|
1117
|
+
| `fontColor` | `string` | theme / `"#fff"` | Text color. |
|
|
1118
|
+
| `backgroundColor` | `string` | theme / `"#1677ff"` | Background color. |
|
|
1119
|
+
| `borderColor` | `string` | — | Stroke color. |
|
|
1120
|
+
| `borderRadius` | `number` | `6` | Corner radius. |
|
|
1121
|
+
| `disabled` | `boolean` | `false` | Disables the button. |
|
|
1122
|
+
| `onClick` | `() => void` | — | Click callback. |
|
|
1123
|
+
|
|
1124
|
+
## Image Export
|
|
1125
|
+
|
|
1126
|
+
Export the image through a `ref` provided by `CanvasHandle`:
|
|
1127
|
+
|
|
1128
|
+
```tsx
|
|
1129
|
+
const canvasRef = useRef<CanvasHandle>(null);
|
|
1130
|
+
|
|
1131
|
+
// PNG Data URL — assign directly to img.src
|
|
1132
|
+
const dataUrl = canvasRef.current?.toDataURL({
|
|
1133
|
+
type: 'image/png',
|
|
1134
|
+
width: 840,
|
|
1135
|
+
height: 600,
|
|
1136
|
+
pixelRatio: 2,
|
|
1137
|
+
});
|
|
1138
|
+
|
|
1139
|
+
// JPEG Blob — create a download link or upload
|
|
1140
|
+
const blob = await canvasRef.current?.toBlob({
|
|
1141
|
+
type: 'image/jpeg',
|
|
1142
|
+
quality: 0.9,
|
|
1143
|
+
pixelRatio: 2,
|
|
1144
|
+
});
|
|
1145
|
+
|
|
1146
|
+
// Get the underlying HTMLCanvasElement
|
|
1147
|
+
const canvasElement = canvasRef.current?.getCanvas();
|
|
1148
|
+
```
|
|
1149
|
+
|
|
1150
|
+
`CanvasExportOptions`:
|
|
1151
|
+
|
|
1152
|
+
| Prop | Type | Default | Description |
|
|
1153
|
+
| ------------ | -------- | ----------------------------: | ---------------------------------------------------------------------------------------------------------------- |
|
|
1154
|
+
| `width` | `number` | Current Canvas logical width | Logical export width. |
|
|
1155
|
+
| `height` | `number` | Current Canvas logical height | Logical export height. |
|
|
1156
|
+
| `pixelRatio` | `number` | Canvas's pixel ratio | Output pixels per logical pixel; the final bitmap size is roughly `width × pixelRatio` by `height × pixelRatio`. |
|
|
1157
|
+
| `type` | `string` | `"image/png"` | Image MIME type such as `image/png`, `image/jpeg`, `image/webp`. Unsupported formats fall back to PNG. |
|
|
1158
|
+
| `quality` | `number` | Browser default | Quality for lossy formats, range `0` to `1`; usually unused by PNG. |
|
|
1159
|
+
|
|
1160
|
+
Short-form calls are still supported:
|
|
1161
|
+
|
|
1162
|
+
```tsx
|
|
1163
|
+
canvasRef.current?.toDataURL('image/png');
|
|
1164
|
+
const jpegBlob = await canvasRef.current?.toBlob('image/jpeg', 0.9);
|
|
1165
|
+
```
|
|
1166
|
+
|
|
1167
|
+
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.
|
|
1168
|
+
|
|
1169
|
+
## File Structure
|
|
1170
|
+
|
|
1171
|
+
Paths below are relative to `src/canvas-ui/`.
|
|
1172
|
+
|
|
1173
|
+
| File | Purpose |
|
|
1174
|
+
| ------------------------- | ------------------------------------------------------------------------------------------------------------------- |
|
|
1175
|
+
| `react/` | React components and Canvas container adapter. |
|
|
1176
|
+
| `vue/` | Vue 3 components and Canvas container adapter. |
|
|
1177
|
+
| `svelte/` | Svelte 5+ adapter and template components. |
|
|
1178
|
+
| `angular/` | Angular standalone Canvas component and scene directives. |
|
|
1179
|
+
| `components/` | Shared implementations, each with its own directory, entry, Props and drawing code, and optional interaction logic. |
|
|
1180
|
+
| `components/types.ts` | Aggregates public component Props types. |
|
|
1181
|
+
| `theme.css` | Light and dark CSS theme variables for Canvas components. |
|
|
1182
|
+
| `types.ts` | Component Props, scene, Canvas, and input-bridge types. |
|
|
1183
|
+
| `renderer.ts` | Drawing registration, scene traversal, and Canvas rendering. |
|
|
1184
|
+
| `scene.ts` | Scene nodes and child reconciliation. |
|
|
1185
|
+
| `input-bridge.ts` | Transparent HTML input bridge for Input and Textarea. |
|
|
1186
|
+
| `engine.ts` | Orchestrates scene updates, rendering, input, and interaction. |
|
|
1187
|
+
| `engine/transform.ts` | Pure matrix math. |
|
|
1188
|
+
| `engine/interaction.ts` | Pointer and wheel interactions and state changes. |
|
|
1189
|
+
| `engine/layout.ts` | Declarative tree preparation and layout. |
|
|
1190
|
+
| `engine/carousel.ts` | Carousel state and animation timing. |
|
|
1191
|
+
| `engine/images.ts` | Image subscription lifecycle. |
|
|
1192
|
+
| `engine/text-controls.ts` | DOM input bridge synchronization. |
|
|
1193
|
+
| `engine/events.ts` | Public and CanvasView event dispatch. |
|
|
1194
|
+
| `engine/hit-test.ts` | Coordinate resolution and hit testing. |
|
|
1195
|
+
| `engine/vnodes.ts` | VNode tree and Grid layout helpers. |
|
|
1196
|
+
| `engine/nodes.ts` | SceneNode predicates and derived values. |
|
|
1197
|
+
| `engine/state.ts` | Internal types, EngineCore interface, and EngineState container. |
|
|
1198
|
+
|
|
1199
|
+
For appearance changes, edit the drawing function in `components/<Component>/<component>.ts`; place component-specific interaction logic in `logic.ts` in the same directory. For shared layout, event, or export behavior, edit the relevant adapter, `engine.ts`, or `renderer.ts`.
|