@web-canvas-ui/react 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/README.md +172 -76
  2. package/index.js +2682 -0
  3. package/package.json +36 -27
  4. package/types/canvas-handle.d.ts +22 -0
  5. package/types/components/Button/button.d.ts +20 -0
  6. package/types/components/Button/logic.d.ts +3 -0
  7. package/types/components/CanvasView/canvasView.d.ts +28 -0
  8. package/types/components/CanvasView/index.d.ts +2 -0
  9. package/types/components/Carousel/carousel.d.ts +31 -0
  10. package/types/components/Carousel/logic.d.ts +2 -0
  11. package/types/components/Checkbox/checkbox.d.ts +8 -0
  12. package/types/components/ChoiceGroup/choiceGroup.d.ts +33 -0
  13. package/types/components/ChoiceGroup/logic.d.ts +3 -0
  14. package/types/components/Circle/circle.d.ts +9 -0
  15. package/types/components/Collapse/collapse.d.ts +32 -0
  16. package/types/components/Collapse/logic.d.ts +1 -0
  17. package/types/components/CustomDraw/customDraw.d.ts +22 -0
  18. package/types/components/CustomDraw/index.d.ts +2 -0
  19. package/types/components/DatePicker/datePicker.d.ts +24 -0
  20. package/types/components/Dialog/dialog.d.ts +20 -0
  21. package/types/components/Dropdown/dropdown.d.ts +30 -0
  22. package/types/components/Dropdown/logic.d.ts +5 -0
  23. package/{components/Grid/grid.ts → types/components/Grid/grid.d.ts} +3 -4
  24. package/{components/GridItem/gridItem.ts → types/components/GridItem/gridItem.d.ts} +1 -4
  25. package/{components/Group/group.ts → types/components/Group/group.d.ts} +1 -4
  26. package/types/components/Icon/icon.d.ts +14 -0
  27. package/types/components/Image/image.d.ts +12 -0
  28. package/types/components/Input/input.d.ts +32 -0
  29. package/types/components/Progress/progress.d.ts +15 -0
  30. package/types/components/Radio/radio.d.ts +8 -0
  31. package/types/components/Rect/rect.d.ts +11 -0
  32. package/types/components/Slider/logic.d.ts +1 -0
  33. package/types/components/Slider/slider.d.ts +17 -0
  34. package/types/components/Switch/logic.d.ts +2 -0
  35. package/types/components/Switch/switch.d.ts +14 -0
  36. package/types/components/Tabs/logic.d.ts +2 -0
  37. package/types/components/Tabs/tabs.d.ts +35 -0
  38. package/types/components/Text/text.d.ts +39 -0
  39. package/types/components/Textarea/textarea.d.ts +10 -0
  40. package/types/components/Upload/upload.d.ts +20 -0
  41. package/types/components/Video/index.d.ts +2 -0
  42. package/types/components/Video/video.d.ts +20 -0
  43. package/types/components/draw-utils.d.ts +48 -0
  44. package/types/components/shared.d.ts +7 -0
  45. package/types/components/size.d.ts +6 -0
  46. package/{components/types.ts → types/components/types.d.ts} +3 -12
  47. package/types/engine/carousel.d.ts +10 -0
  48. package/types/engine/events.d.ts +14 -0
  49. package/types/engine/hit-test.d.ts +31 -0
  50. package/types/engine/images.d.ts +8 -0
  51. package/types/engine/interaction.d.ts +11 -0
  52. package/types/engine/layout.d.ts +6 -0
  53. package/types/engine/nodes.d.ts +18 -0
  54. package/{engine/state.ts → types/engine/state.d.ts} +27 -22
  55. package/types/engine/text-controls.d.ts +10 -0
  56. package/types/engine/transform.d.ts +13 -0
  57. package/types/engine/videos.d.ts +14 -0
  58. package/types/engine/vnodes.d.ts +36 -0
  59. package/types/engine.d.ts +36 -0
  60. package/types/image-assets.d.ts +2 -0
  61. package/types/input-bridge.d.ts +40 -0
  62. package/types/react/Canvas.d.ts +4 -0
  63. package/types/react/components.d.ts +30 -0
  64. package/types/react/index.d.ts +4 -0
  65. package/types/renderer.d.ts +20 -0
  66. package/types/scene.d.ts +15 -0
  67. package/{types.ts → types/types.d.ts} +10 -142
  68. package/types/video-assets.d.ts +11 -0
  69. package/Canvas.tsx +0 -142
  70. package/__tests__/pure-logic.test.ts +0 -153
  71. package/__tests__/scene-and-node.test.ts +0 -131
  72. package/__tests__/scratch-space.test.ts +0 -30
  73. package/__tests__/textarea-caret.test.ts +0 -96
  74. package/__tests__/utils.test.ts +0 -114
  75. package/canvas-handle.ts +0 -114
  76. package/components/Button/button.ts +0 -57
  77. package/components/Button/logic.ts +0 -11
  78. package/components/CanvasView/canvasView.ts +0 -103
  79. package/components/CanvasView/index.ts +0 -7
  80. package/components/Carousel/carousel.ts +0 -107
  81. package/components/Carousel/logic.ts +0 -36
  82. package/components/Checkbox/checkbox.ts +0 -14
  83. package/components/ChoiceGroup/choiceGroup.ts +0 -172
  84. package/components/ChoiceGroup/logic.ts +0 -14
  85. package/components/Circle/circle.ts +0 -31
  86. package/components/Collapse/collapse.ts +0 -69
  87. package/components/Collapse/logic.ts +0 -14
  88. package/components/CustomDraw/customDraw.ts +0 -50
  89. package/components/CustomDraw/index.ts +0 -7
  90. package/components/DatePicker/datePicker.ts +0 -70
  91. package/components/Dialog/dialog.ts +0 -102
  92. package/components/Dropdown/dropdown.ts +0 -125
  93. package/components/Dropdown/logic.ts +0 -29
  94. package/components/Icon/icon.ts +0 -669
  95. package/components/Image/image.ts +0 -69
  96. package/components/Input/input.ts +0 -139
  97. package/components/Progress/progress.ts +0 -59
  98. package/components/Radio/radio.ts +0 -14
  99. package/components/Rect/rect.ts +0 -35
  100. package/components/Slider/logic.ts +0 -19
  101. package/components/Slider/slider.ts +0 -58
  102. package/components/Switch/logic.ts +0 -8
  103. package/components/Switch/switch.ts +0 -37
  104. package/components/Tabs/logic.ts +0 -14
  105. package/components/Tabs/tabs.ts +0 -78
  106. package/components/Text/text.ts +0 -95
  107. package/components/Textarea/textarea.ts +0 -16
  108. package/components/Upload/upload.ts +0 -66
  109. package/components/draw-utils.ts +0 -230
  110. package/components/shared.ts +0 -15
  111. package/components/size.ts +0 -20
  112. package/components.ts +0 -98
  113. package/engine/__tests__/carousel.test.ts +0 -218
  114. package/engine/__tests__/hit-test.test.ts +0 -282
  115. package/engine/__tests__/layout.test.ts +0 -474
  116. package/engine/carousel.ts +0 -150
  117. package/engine/events.ts +0 -73
  118. package/engine/hit-test.ts +0 -321
  119. package/engine/images.ts +0 -41
  120. package/engine/interaction.ts +0 -442
  121. package/engine/layout.ts +0 -355
  122. package/engine/nodes.ts +0 -166
  123. package/engine/text-controls.ts +0 -122
  124. package/engine/transform.ts +0 -61
  125. package/engine/vnodes.ts +0 -204
  126. package/engine.ts +0 -162
  127. package/image-assets.ts +0 -37
  128. package/index.ts +0 -78
  129. package/input-bridge.ts +0 -285
  130. package/renderer.ts +0 -303
  131. package/scene.ts +0 -122
  132. package/theme.scss +0 -234
  133. package/web-canvas-ui-react-0.1.1.tgz +0 -0
  134. /package/{components/Button/index.ts → types/components/Button/index.d.ts} +0 -0
  135. /package/{components/Carousel/index.ts → types/components/Carousel/index.d.ts} +0 -0
  136. /package/{components/Checkbox/index.ts → types/components/Checkbox/index.d.ts} +0 -0
  137. /package/{components/ChoiceGroup/index.ts → types/components/ChoiceGroup/index.d.ts} +0 -0
  138. /package/{components/Circle/index.ts → types/components/Circle/index.d.ts} +0 -0
  139. /package/{components/Collapse/index.ts → types/components/Collapse/index.d.ts} +0 -0
  140. /package/{components/DatePicker/index.ts → types/components/DatePicker/index.d.ts} +0 -0
  141. /package/{components/Dialog/index.ts → types/components/Dialog/index.d.ts} +0 -0
  142. /package/{components/Dropdown/index.ts → types/components/Dropdown/index.d.ts} +0 -0
  143. /package/{components/Grid/index.ts → types/components/Grid/index.d.ts} +0 -0
  144. /package/{components/GridItem/index.ts → types/components/GridItem/index.d.ts} +0 -0
  145. /package/{components/Group/index.ts → types/components/Group/index.d.ts} +0 -0
  146. /package/{components/Icon/index.ts → types/components/Icon/index.d.ts} +0 -0
  147. /package/{components/Image/index.ts → types/components/Image/index.d.ts} +0 -0
  148. /package/{components/Input/index.ts → types/components/Input/index.d.ts} +0 -0
  149. /package/{components/Progress/index.ts → types/components/Progress/index.d.ts} +0 -0
  150. /package/{components/Radio/index.ts → types/components/Radio/index.d.ts} +0 -0
  151. /package/{components/Rect/index.ts → types/components/Rect/index.d.ts} +0 -0
  152. /package/{components/Slider/index.ts → types/components/Slider/index.d.ts} +0 -0
  153. /package/{components/Switch/index.ts → types/components/Switch/index.d.ts} +0 -0
  154. /package/{components/Tabs/index.ts → types/components/Tabs/index.d.ts} +0 -0
  155. /package/{components/Text/index.ts → types/components/Text/index.d.ts} +0 -0
  156. /package/{components/Textarea/index.ts → types/components/Textarea/index.d.ts} +0 -0
  157. /package/{components/Upload/index.ts → types/components/Upload/index.d.ts} +0 -0
@@ -1,669 +0,0 @@
1
- import type { TransformProps } from '../../types';
2
- import { number, string, themeColor } from '../draw-utils';
3
- import { createComponent } from '../shared';
4
-
5
- export const ICON_NAMES = [
6
- 'home',
7
- 'house',
8
- 'building',
9
- 'apartment',
10
- 'store',
11
- 'mapPin',
12
- 'map',
13
- 'globe',
14
- 'compass',
15
- 'navigation',
16
- 'flag',
17
- 'mountain',
18
- 'tree',
19
- 'leaf',
20
- 'flower',
21
- 'sun',
22
- 'moon',
23
- 'cloud',
24
- 'rain',
25
- 'snow',
26
- 'fire',
27
- 'water',
28
- 'wind',
29
- 'car',
30
- 'bus',
31
- 'train',
32
- 'plane',
33
- 'bicycle',
34
- 'ship',
35
- 'rocket',
36
- 'truck',
37
- 'walk',
38
- 'phone',
39
- 'message',
40
- 'mail',
41
- 'bell',
42
- 'calendar',
43
- 'clock',
44
- 'alarm',
45
- 'camera',
46
- 'image',
47
- 'video',
48
- 'music',
49
- 'microphone',
50
- 'headphones',
51
- 'play',
52
- 'pause',
53
- 'stop',
54
- 'record',
55
- 'volume',
56
- 'wifi',
57
- 'bluetooth',
58
- 'battery',
59
- 'signal',
60
- 'power',
61
- 'monitor',
62
- 'laptop',
63
- 'tablet',
64
- 'keyboard',
65
- 'mouse',
66
- 'printer',
67
- 'folder',
68
- 'file',
69
- 'document',
70
- 'download',
71
- 'upload',
72
- 'share',
73
- 'link',
74
- 'search',
75
- 'settings',
76
- 'sliders',
77
- 'menu',
78
- 'close',
79
- 'check',
80
- 'plus',
81
- 'minus',
82
- 'edit',
83
- 'trash',
84
- 'copy',
85
- 'save',
86
- 'lock',
87
- 'unlock',
88
- 'key',
89
- 'user',
90
- 'users',
91
- 'heart',
92
- 'star',
93
- 'bookmark',
94
- 'cart',
95
- 'bag',
96
- 'gift',
97
- 'creditCard',
98
- 'wallet',
99
- 'chart',
100
- 'pieChart',
101
- 'barChart',
102
- 'analytics',
103
- 'shield',
104
- 'warning',
105
- 'info',
106
- 'help',
107
- 'question',
108
- 'tag',
109
- 'puzzle',
110
- 'code',
111
- 'database',
112
- 'cloudDownload',
113
- ] as const;
114
-
115
- export type IconName = (typeof ICON_NAMES)[number];
116
- export type IconVariant = 'outline' | 'solid';
117
-
118
- export interface IconProps extends TransformProps {
119
- name: IconName;
120
- size?: number;
121
- color?: string;
122
- variant?: IconVariant;
123
- strokeWidth?: number;
124
- }
125
-
126
- interface IconGlyph {
127
- paths: readonly string[];
128
- circles?: readonly (readonly [number, number, number])[];
129
- filled?: readonly number[];
130
- }
131
-
132
- const ICON_GLYPHS: Record<IconName, IconGlyph> = {
133
- home: { paths: ['M3 10 L12 3 L21 10 M5 9 V21 H19 V9 M9 21 V14 H15 V21'] },
134
- house: {
135
- paths: ['M2 11 L12 2 L22 11 M4 10 V21 H20 V10 M9 21 V14 H15 V21', 'M3 11 H6 M18 11 H21'],
136
- },
137
- building: {
138
- paths: [
139
- 'M4 21 V4 H16 V21 M16 9 H21 V21 M2 21 H22',
140
- 'M7 7 H9 M12 7 H14 M7 11 H9 M12 11 H14 M7 15 H9 M12 15 H14 M18 12 H19 M18 16 H19',
141
- ],
142
- },
143
- apartment: {
144
- paths: [
145
- 'M3 21 V3 H21 V21 M2 21 H22',
146
- 'M7 7 H9 M15 7 H17 M7 11 H9 M15 11 H17 M7 15 H9 M15 15 H17 M10 21 V18 H14 V21',
147
- ],
148
- },
149
- store: {
150
- paths: [
151
- 'M4 10 V21 H20 V10 M2 10 L4 3 H20 L22 10 M2 10 Q5 14 8 10 Q11 14 14 10 Q17 14 22 10',
152
- 'M8 21 V14 H16 V21',
153
- ],
154
- },
155
- mapPin: {
156
- paths: ['M12 22 C9 18 4 13 4 9 A8 8 0 0 1 20 9 C20 13 15 18 12 22 Z'],
157
- circles: [[12, 9, 2.5]],
158
- },
159
- map: { paths: ['M3 6 L9 3 L15 6 L21 3 V18 L15 21 L9 18 L3 21 Z', 'M9 3 V18 M15 6 V21'] },
160
- globe: {
161
- paths: [
162
- 'M12 22 A10 10 0 1 0 12 2 A10 10 0 1 0 12 22 Z',
163
- 'M2 12 H22 M12 2 C7 7 7 17 12 22 M12 2 C17 7 17 17 12 22 M4 7 H20 M4 17 H20',
164
- ],
165
- },
166
- compass: {
167
- paths: [
168
- 'M12 22 A10 10 0 1 0 12 2 A10 10 0 1 0 12 22 Z',
169
- 'M15.5 8.5 L13 13 L8.5 15.5 L11 11 Z M12 2 V4 M22 12 H20',
170
- ],
171
- },
172
- navigation: { paths: ['M12 2 L21 21 L12 17 L3 21 Z M12 17 V9'] },
173
- flag: { paths: ['M5 22 V3 M5 4 C10 1 14 8 20 4 V15 C14 19 10 12 5 15'] },
174
- mountain: { paths: ['M2 21 L8 9 L11 14 L16 5 L22 21 Z M6 21 L10 14 M13 11 L16 15'] },
175
- tree: { paths: ['M12 22 V15 M5 15 L12 4 L19 15 Z M7 10 L12 2 L17 10 Z M8 22 H16'] },
176
- leaf: {
177
- paths: [
178
- 'M21 3 C10 3 4 6 4 14 C4 18 7 21 11 20 C19 18 21 11 21 3 Z M3 21 L14 10 M8 16 L8 12 M12 12 L16 12',
179
- ],
180
- },
181
- flower: {
182
- paths: ['M12 13 V22 M12 18 C8 16 7 19 6 21 M12 18 C16 16 17 19 18 21'],
183
- circles: [
184
- [12, 7, 2],
185
- [12, 3, 2],
186
- [16, 7, 2],
187
- [12, 11, 2],
188
- [8, 7, 2],
189
- ],
190
- },
191
- sun: {
192
- paths: [
193
- 'M12 7 A5 5 0 1 0 12 17 A5 5 0 1 0 12 7 Z',
194
- 'M12 2 V4 M12 20 V22 M2 12 H4 M20 12 H22 M5 5 L6.5 6.5 M17.5 17.5 L19 19 M19 5 L17.5 6.5 M6.5 17.5 L5 19',
195
- ],
196
- },
197
- moon: { paths: ['M20 15 A8 8 0 0 1 9 4 A9 9 0 1 0 20 15 Z'] },
198
- cloud: { paths: ['M7 18 H18 A4 4 0 0 0 18 10 A7 7 0 0 0 5 11 A3.5 3.5 0 0 0 7 18 Z'] },
199
- rain: {
200
- paths: [
201
- 'M7 14 H18 A4 4 0 0 0 18 6 A7 7 0 0 0 5 7 A3.5 3.5 0 0 0 7 14 Z',
202
- 'M8 17 L7 20 M13 17 L12 20 M18 17 L17 20',
203
- ],
204
- },
205
- snow: {
206
- paths: [
207
- 'M12 2 V22 M3.3 7 L20.7 17 M3.3 17 L20.7 7',
208
- 'M9 4 L12 7 L15 4 M9 20 L12 17 L15 20 M4 10 L8 9 L7 5 M20 14 L16 15 L17 19 M4 14 L8 15 L7 19 M20 10 L16 9 L17 5',
209
- ],
210
- },
211
- fire: {
212
- paths: [
213
- 'M12 22 C5 22 4 16 7 11 C8 9 9 7 9 4 C13 7 14 10 13 12 C16 11 17 8 17 7 C23 15 19 22 12 22 Z',
214
- 'M12 19 C9 19 9 16 11 14 C12 13 13 12 13 11 C17 14 16 19 12 19 Z',
215
- ],
216
- },
217
- water: {
218
- paths: [
219
- 'M12 2 C9 7 4 12 4 16 A8 8 0 0 0 20 16 C20 12 15 7 12 2 Z',
220
- 'M8 17 C9 19 11 20 13 20',
221
- ],
222
- },
223
- wind: {
224
- paths: [
225
- 'M3 8 H16 C20 8 20 3 17 3 C15 3 14 4 14 5 M2 12 H20 C23 12 23 17 20 17 C18 17 17 16 17 15 M4 16 H11',
226
- ],
227
- },
228
- car: {
229
- paths: [
230
- 'M3 16 L5 8 H19 L21 16 V20 H3 Z M5 8 L7 4 H17 L19 8 M3 13 H21 M6 20 V22 M18 20 V22',
231
- ],
232
- circles: [
233
- [7, 17, 1],
234
- [17, 17, 1],
235
- ],
236
- },
237
- bus: {
238
- paths: [
239
- 'M5 3 H19 A2 2 0 0 1 21 5 V19 H3 V5 A2 2 0 0 1 5 3 Z M3 12 H21 M6 6 H10 V10 H6 Z M14 6 H18 V10 H14 Z M6 19 V22 M18 19 V22',
240
- ],
241
- circles: [
242
- [7, 16, 1],
243
- [17, 16, 1],
244
- ],
245
- },
246
- train: {
247
- paths: [
248
- 'M7 3 H17 A3 3 0 0 1 20 6 V16 A3 3 0 0 1 17 19 H7 A3 3 0 0 1 4 16 V6 A3 3 0 0 1 7 3 Z M4 12 H20 M8 22 L10 19 M16 22 L14 19',
249
- ],
250
- circles: [
251
- [8, 7, 1],
252
- [16, 7, 1],
253
- ],
254
- },
255
- plane: {
256
- paths: [
257
- 'M2 13 L10 11 L14 3 L17 3 L16 10 L22 12 L22 14 L15 14 L12 21 L10 21 L10 14 L3 16 Z',
258
- ],
259
- },
260
- bicycle: {
261
- paths: [
262
- 'M5 18 A3 3 0 1 0 5 24 A3 3 0 1 0 5 18 Z M19 18 A3 3 0 1 0 19 24 A3 3 0 1 0 19 18 Z M5 21 L9 13 L13 21 H5 L11 16 L15 11 L19 21 M13 11 H17 M9 13 H6',
263
- ],
264
- },
265
- ship: {
266
- paths: [
267
- 'M3 14 L6 8 H18 L21 14 L19 19 H5 Z M8 8 V4 H15 V8 M2 21 Q6 19 10 21 Q14 19 18 21 Q20 20 22 21',
268
- ],
269
- },
270
- rocket: {
271
- paths: [
272
- 'M12 2 C17 5 19 10 19 16 L12 21 L5 16 C5 10 7 5 12 2 Z M8 16 L4 20 V14 M16 16 L20 20 V14 M9 22 H15',
273
- ],
274
- circles: [[12, 9, 2]],
275
- },
276
- truck: {
277
- paths: ['M2 6 H15 V18 H2 Z M15 11 H19 L22 14 V18 H15 Z M5 18 V21 M19 18 V21 M15 14 H21'],
278
- circles: [
279
- [6, 18, 1.5],
280
- [18, 18, 1.5],
281
- ],
282
- },
283
- walk: {
284
- paths: [
285
- 'M12 3 A2 2 0 1 0 12 7 A2 2 0 1 0 12 3 Z M11 9 L8 14 L4 16 M10 12 L15 14 L18 19 M8 14 L10 18 L8 22 M15 14 L14 18 L17 22',
286
- ],
287
- },
288
- phone: {
289
- paths: [
290
- 'M7 2 H17 A2 2 0 0 1 19 4 V20 A2 2 0 0 1 17 22 H7 A2 2 0 0 1 5 20 V4 A2 2 0 0 1 7 2 Z M5 18 H19 M10 5 H14',
291
- ],
292
- circles: [[12, 20, 0.6]],
293
- },
294
- message: { paths: ['M3 4 H21 V17 H11 L5 21 V17 H3 Z M7 9 H17 M7 13 H14'] },
295
- mail: { paths: ['M3 5 H21 V19 H3 Z M3 6 L12 13 L21 6'] },
296
- bell: { paths: ['M5 17 H19 L17 14 V9 A5 5 0 0 0 7 9 V14 Z M10 20 H14'], circles: [[12, 3, 1]] },
297
- calendar: {
298
- paths: [
299
- 'M3 5 H21 V21 H3 Z M3 9 H21 M7 2 V7 M17 2 V7 M7 13 H9 M12 13 H14 M17 13 H19 M7 17 H9 M12 17 H14',
300
- ],
301
- },
302
- clock: { paths: ['M12 22 A10 10 0 1 0 12 2 A10 10 0 1 0 12 22 Z M12 6 V12 L16 14'] },
303
- alarm: {
304
- paths: [
305
- 'M12 22 A8 8 0 1 0 12 6 A8 8 0 1 0 12 22 Z M12 10 V14 L15 16 M4 3 L2 6 M20 3 L22 6 M8 22 L6 24 M16 22 L18 24',
306
- ],
307
- },
308
- camera: {
309
- paths: ['M3 7 H7 L9 4 H15 L17 7 H21 V20 H3 Z'],
310
- circles: [
311
- [12, 13, 4],
312
- [12, 13, 2],
313
- ],
314
- },
315
- image: {
316
- paths: ['M3 4 H21 V20 H3 Z M4 18 L10 11 L14 15 L17 12 L21 17'],
317
- circles: [[8, 8, 1.5]],
318
- },
319
- video: { paths: ['M3 6 H15 V18 H3 Z M15 10 L21 7 V17 L15 14 Z'] },
320
- music: {
321
- paths: ['M10 17 V5 L21 3 V15 M10 8 L21 6'],
322
- circles: [
323
- [7, 18, 3],
324
- [18, 16, 3],
325
- ],
326
- },
327
- microphone: {
328
- paths: [
329
- 'M12 15 A3 3 0 0 0 15 12 V5 A3 3 0 0 0 9 5 V12 A3 3 0 0 0 12 15 Z M5 11 A7 7 0 0 0 19 11 M12 18 V22 M8 22 H16',
330
- ],
331
- },
332
- headphones: {
333
- paths: [
334
- 'M3 13 V11 A9 9 0 0 1 21 11 V13 M3 13 H7 V20 H5 A2 2 0 0 1 3 18 Z M21 13 H17 V20 H19 A2 2 0 0 0 21 18 Z',
335
- ],
336
- },
337
- play: { paths: ['M6 3 L21 12 L6 21 Z'], filled: [0] },
338
- pause: { paths: ['M6 4 H10 V20 H6 Z M14 4 H18 V20 H14 Z'], filled: [0, 1] },
339
- stop: { paths: ['M5 5 H19 V19 H5 Z'], filled: [0] },
340
- record: { paths: ['M3 12 A9 9 0 1 0 21 12 A9 9 0 1 0 3 12 Z'], circles: [[12, 12, 3]] },
341
- volume: { paths: ['M3 9 H7 L13 4 V20 L7 15 H3 Z M17 9 Q21 12 17 15 M19 6 Q25 12 19 18'] },
342
- wifi: {
343
- paths: ['M2 8 Q12 0 22 8 M5 12 Q12 6 19 12 M8 16 Q12 12 16 16'],
344
- circles: [[12, 20, 1]],
345
- },
346
- bluetooth: { paths: ['M12 2 L18 7 L12 12 L18 17 L12 22 V2 M5 7 L18 17 M5 17 L18 7'] },
347
- battery: { paths: ['M3 7 H20 V19 H3 Z M20 10 H22 V16 H20 M6 10 V16 M10 10 V16 M14 10 V16'] },
348
- signal: {
349
- paths: ['M3 20 V16 H6 V20 Z M9 20 V12 H12 V20 Z M15 20 V8 H18 V20 Z M21 20 V4 H24 V20 Z'],
350
- },
351
- power: { paths: ['M12 2 V12 M6 5 A9 9 0 1 0 18 5'] },
352
- monitor: { paths: ['M2 4 H22 V18 H2 Z M8 22 H16 M12 18 V22'] },
353
- laptop: { paths: ['M4 4 H20 V16 H4 Z M2 20 H22 L20 17 H4 Z'] },
354
- tablet: {
355
- paths: [
356
- 'M6 2 H18 A2 2 0 0 1 20 4 V20 A2 2 0 0 1 18 22 H6 A2 2 0 0 1 4 20 V4 A2 2 0 0 1 6 2 Z M4 18 H20',
357
- ],
358
- circles: [[12, 20, 0.6]],
359
- },
360
- keyboard: {
361
- paths: [
362
- 'M2 6 H22 V18 H2 Z M5 9 H6 M9 9 H10 M13 9 H14 M17 9 H18 M5 12 H6 M9 12 H10 M13 12 H14 M17 12 H18 M7 15 H17',
363
- ],
364
- },
365
- mouse: {
366
- paths: ['M12 22 A8 8 0 0 0 20 14 V10 A8 8 0 0 0 4 10 V14 A8 8 0 0 0 12 22 Z M12 3 V11'],
367
- },
368
- printer: {
369
- paths: [
370
- 'M6 8 V3 H18 V8 M6 17 H4 A2 2 0 0 1 2 15 V10 A2 2 0 0 1 4 8 H20 A2 2 0 0 1 22 10 V15 A2 2 0 0 1 20 17 H18 M6 14 H18 V21 H6 Z',
371
- ],
372
- circles: [[18, 11, 0.8]],
373
- },
374
- folder: { paths: ['M2 6 H10 L12 9 H22 V20 H2 Z M2 9 H22'] },
375
- file: { paths: ['M5 2 H15 L20 7 V22 H5 Z M15 2 V7 H20 M8 12 H17 M8 16 H17'] },
376
- document: { paths: ['M4 3 H17 L21 7 V21 H4 Z M17 3 V7 H21 M8 11 H17 M8 15 H17 M8 18 H14'] },
377
- download: { paths: ['M12 2 V16 M6 10 L12 16 L18 10 M4 20 H20'] },
378
- upload: { paths: ['M12 16 V2 M6 8 L12 2 L18 8 M4 20 H20'] },
379
- share: {
380
- paths: ['M6 12 L18 5 M6 12 L18 19'],
381
- circles: [
382
- [5, 12, 3],
383
- [19, 4, 3],
384
- [19, 20, 3],
385
- ],
386
- },
387
- link: {
388
- paths: [
389
- 'M9 15 L15 9 M7 17 L5 19 A4 4 0 0 1 2 13 L7 8 A4 4 0 0 1 13 8 M17 7 L19 5 A4 4 0 0 1 22 11 L17 16 A4 4 0 0 1 11 16',
390
- ],
391
- },
392
- search: { paths: ['M15 15 L22 22'], circles: [[10, 10, 7]] },
393
- settings: {
394
- paths: [
395
- 'M12 2 L14 4 L17 4 L18 7 L21 9 L20 12 L21 15 L18 17 L17 20 L14 20 L12 22 L10 20 L7 20 L6 17 L3 15 L4 12 L3 9 L6 7 L7 4 L10 4 Z',
396
- ],
397
- circles: [[12, 12, 3]],
398
- },
399
- sliders: {
400
- paths: ['M3 6 H21 M3 12 H21 M3 18 H21'],
401
- circles: [
402
- [8, 6, 2],
403
- [15, 12, 2],
404
- [10, 18, 2],
405
- ],
406
- },
407
- menu: { paths: ['M3 6 H21 M3 12 H21 M3 18 H21'] },
408
- close: { paths: ['M5 5 L19 19 M19 5 L5 19'] },
409
- check: { paths: ['M3 12 L9 18 L21 5'] },
410
- plus: { paths: ['M12 3 V21 M3 12 H21'] },
411
- minus: { paths: ['M3 12 H21'] },
412
- edit: { paths: ['M4 16 L15 5 L19 9 L8 20 L3 21 Z M13 7 L17 11 M3 21 L4 16'] },
413
- trash: { paths: ['M4 7 H20 M10 3 H14 M6 7 L7 21 H17 L18 7 M10 11 V17 M14 11 V17'] },
414
- copy: { paths: ['M8 8 H20 V21 H8 Z M5 16 H3 V3 H15 V5'] },
415
- save: { paths: ['M3 3 H18 L21 6 V21 H3 Z M7 3 V9 H16 V3 M7 21 V14 H17 V21'] },
416
- lock: { paths: ['M5 11 H19 V21 H5 Z M8 11 V7 A4 4 0 0 1 16 7 V11'] },
417
- unlock: { paths: ['M5 11 H19 V21 H5 Z M8 11 V7 A4 4 0 0 1 15 4'] },
418
- key: { paths: ['M14 10 L22 2 M18 6 L21 9 M15 9 L18 12'], circles: [[8, 14, 6]] },
419
- user: { paths: ['M4 21 C4 16 8 14 12 14 C16 14 20 16 20 21'], circles: [[12, 7, 4]] },
420
- users: {
421
- paths: [
422
- 'M2 21 C2 17 5 15 9 15 M22 21 C22 17 19 15 15 15 M8 21 C8 16 11 14 15 14 C19 14 22 16 22 21',
423
- ],
424
- circles: [
425
- [8, 7, 3],
426
- [17, 7, 3],
427
- ],
428
- },
429
- heart: { paths: ['M12 21 L4 13 C-1 7 7 1 12 7 C17 1 25 7 20 13 Z'], filled: [0] },
430
- star: {
431
- paths: ['M12 2 L15 9 L22 10 L17 15 L18 22 L12 18 L6 22 L7 15 L2 10 L9 9 Z'],
432
- filled: [0],
433
- },
434
- bookmark: { paths: ['M6 3 H18 V22 L12 18 L6 22 Z'] },
435
- cart: {
436
- paths: ['M2 3 H5 L8 17 H19 L22 7 H6 M9 21 H9.1 M18 21 H18.1'],
437
- circles: [
438
- [10, 21, 1.5],
439
- [18, 21, 1.5],
440
- ],
441
- },
442
- bag: { paths: ['M3 8 H21 L19 21 H5 Z M8 8 V6 A4 4 0 0 1 16 6 V8'] },
443
- gift: {
444
- paths: [
445
- 'M3 10 H21 V21 H3 Z M2 6 H22 V10 H2 Z M12 6 V21 M12 6 C5 7 5 2 8 2 C11 2 12 6 12 6 C12 6 13 2 16 2 C19 2 19 7 12 6 Z',
446
- ],
447
- },
448
- creditCard: { paths: ['M2 5 H22 V19 H2 Z M2 10 H22 M6 15 H11'] },
449
- wallet: {
450
- paths: [
451
- 'M3 6 H19 A2 2 0 0 1 21 8 V20 H3 A2 2 0 0 1 1 18 V6 A3 3 0 0 1 4 3 H18 V6 M15 12 H21 V17 H15 A2 2 0 0 1 15 12 Z',
452
- ],
453
- circles: [[17, 14.5, 0.7]],
454
- },
455
- chart: { paths: ['M3 21 V3 M3 21 H22 M7 17 L11 12 L15 15 L21 7'] },
456
- pieChart: { paths: ['M12 2 V12 H22 A10 10 0 1 1 12 2 Z M14 2 A8 8 0 0 1 22 10 H14 Z'] },
457
- barChart: { paths: ['M3 21 H22 M5 18 V11 H9 V18 Z M12 18 V5 H16 V18 Z M19 18 V8 H22 V18 Z'] },
458
- analytics: { paths: ['M3 21 V3 M3 21 H22 M6 17 L10 13 L13 15 L19 7 M16 7 H19 V10'] },
459
- shield: {
460
- paths: ['M12 2 L21 6 V12 C21 17 17 20 12 22 C7 20 3 17 3 12 V6 Z M8 12 L11 15 L17 9'],
461
- },
462
- warning: { paths: ['M12 3 L22 21 H2 Z M12 9 V14'], circles: [[12, 18, 0.8]] },
463
- info: {
464
- paths: ['M12 22 A10 10 0 1 0 12 2 A10 10 0 1 0 12 22 M12 11 V17'],
465
- circles: [[12, 7, 0.8]],
466
- },
467
- help: {
468
- paths: [
469
- 'M12 22 A10 10 0 1 0 12 2 A10 10 0 1 0 12 22 M9 9 A3 3 0 1 1 14 12 C12 13 12 14 12 15',
470
- ],
471
- circles: [[12, 18, 0.7]],
472
- },
473
- question: {
474
- paths: [
475
- 'M12 22 A10 10 0 1 0 12 2 A10 10 0 1 0 12 22 M9 9 A3 3 0 1 1 14 12 C12 13 12 14 12 15',
476
- ],
477
- circles: [[12, 18, 0.7]],
478
- },
479
- tag: { paths: ['M3 4 H13 L22 13 L13 22 L3 12 Z'], circles: [[8, 9, 1]] },
480
- puzzle: {
481
- paths: [
482
- 'M3 3 H9 A3 3 0 1 0 15 3 H21 V9 A3 3 0 1 1 21 15 V21 H15 A3 3 0 1 0 9 21 H3 V15 A3 3 0 1 1 3 9 Z',
483
- ],
484
- },
485
- code: { paths: ['M8 5 L2 12 L8 19 M16 5 L22 12 L16 19 M14 3 L10 21'] },
486
- database: {
487
- paths: [
488
- 'M3 5 C3 1 21 1 21 5 V19 C21 23 3 23 3 19 Z M3 5 C3 9 21 9 21 5 M3 12 C3 16 21 16 21 12',
489
- ],
490
- },
491
- cloudDownload: {
492
- paths: [
493
- 'M7 15 H17 A4 4 0 0 0 17 7 A7 7 0 0 0 4 8 A3.5 3.5 0 0 0 7 15 Z M12 12 V21 M8 17 L12 21 L16 17',
494
- ],
495
- },
496
- };
497
-
498
- export const Icon = createComponent<IconProps>('icon');
499
-
500
- export function drawIcon(context: CanvasRenderingContext2D, props: IconProps): void {
501
- const name = props.name;
502
- if (typeof name !== 'string' || !Object.prototype.hasOwnProperty.call(ICON_GLYPHS, name)) {
503
- throw new Error(`Unknown Canvas UI icon: ${String(name)}.`);
504
- }
505
-
506
- const glyph = ICON_GLYPHS[name as IconName];
507
- const size = number(props.size, 24);
508
- if (size <= 0) throw new RangeError('Icon size must be greater than zero.');
509
- if (props.variant !== undefined && props.variant !== 'outline' && props.variant !== 'solid') {
510
- throw new TypeError(`Unknown Canvas UI icon variant: ${String(props.variant)}.`);
511
- }
512
- const variant: IconVariant = props.variant === 'solid' ? 'solid' : 'outline';
513
- const baseWidth = number(props.strokeWidth, 2);
514
- if (baseWidth <= 0) throw new RangeError('Icon strokeWidth must be greater than zero.');
515
- context.save();
516
- context.translate(size / 2, size / 2);
517
- context.scale(size / 24, size / 24);
518
- context.translate(-12, -12);
519
- context.strokeStyle = string(
520
- props.color,
521
- themeColor(context, '--canvas-ui-icon-color', '#333'),
522
- );
523
- context.fillStyle = context.strokeStyle;
524
- context.lineWidth = ((variant === 'solid' ? Math.max(baseWidth, 4) : baseWidth) * 24) / size;
525
- context.lineCap = 'round';
526
- context.lineJoin = 'round';
527
- for (let index = 0; index < glyph.paths.length; index++) {
528
- context.beginPath();
529
- tracePath(context, glyph.paths[index]);
530
- if (variant === 'solid' && glyph.filled?.includes(index)) context.fill();
531
- context.stroke();
532
- }
533
- for (const [x, y, radius] of glyph.circles ?? []) {
534
- context.beginPath();
535
- context.arc(x, y, radius, 0, Math.PI * 2);
536
- if (variant === 'solid') context.fill();
537
- else context.stroke();
538
- }
539
- context.restore();
540
- }
541
-
542
- function tracePath(context: CanvasRenderingContext2D, path: string): void {
543
- const tokens = path.match(/[A-Z]|-?(?:\d+\.?\d*|\.\d+)/g) ?? [];
544
- let x = 0;
545
- let y = 0;
546
- let startX = 0;
547
- let startY = 0;
548
- for (let index = 0; index < tokens.length;) {
549
- const command = tokens[index++];
550
- const read = (): number => Number(tokens[index++]);
551
- switch (command) {
552
- case 'M':
553
- x = read();
554
- y = read();
555
- startX = x;
556
- startY = y;
557
- context.moveTo(x, y);
558
- break;
559
- case 'L':
560
- x = read();
561
- y = read();
562
- context.lineTo(x, y);
563
- break;
564
- case 'H':
565
- x = read();
566
- context.lineTo(x, y);
567
- break;
568
- case 'V':
569
- y = read();
570
- context.lineTo(x, y);
571
- break;
572
- case 'C': {
573
- const controlX1 = read();
574
- const controlY1 = read();
575
- const controlX2 = read();
576
- const controlY2 = read();
577
- x = read();
578
- y = read();
579
- context.bezierCurveTo(controlX1, controlY1, controlX2, controlY2, x, y);
580
- break;
581
- }
582
- case 'Q': {
583
- const controlX = read();
584
- const controlY = read();
585
- x = read();
586
- y = read();
587
- context.quadraticCurveTo(controlX, controlY, x, y);
588
- break;
589
- }
590
- case 'A': {
591
- const radiusX = read();
592
- const radiusY = read();
593
- const rotation = read();
594
- const largeArc = read() !== 0;
595
- const sweep = read() !== 0;
596
- const endX = read();
597
- const endY = read();
598
- traceArc(context, x, y, radiusX, radiusY, rotation, largeArc, sweep, endX, endY);
599
- x = endX;
600
- y = endY;
601
- break;
602
- }
603
- case 'Z':
604
- context.closePath();
605
- x = startX;
606
- y = startY;
607
- break;
608
- default:
609
- throw new Error(`Unsupported path command: ${command}.`);
610
- }
611
- }
612
- }
613
-
614
- function traceArc(
615
- context: CanvasRenderingContext2D,
616
- startX: number,
617
- startY: number,
618
- radiusX: number,
619
- radiusY: number,
620
- rotation: number,
621
- largeArc: boolean,
622
- sweep: boolean,
623
- endX: number,
624
- endY: number,
625
- ): void {
626
- let rx = Math.abs(radiusX);
627
- let ry = Math.abs(radiusY);
628
- if (rx === 0 || ry === 0 || (startX === endX && startY === endY)) {
629
- context.lineTo(endX, endY);
630
- return;
631
- }
632
-
633
- const angle = (rotation * Math.PI) / 180;
634
- const cos = Math.cos(angle);
635
- const sin = Math.sin(angle);
636
- const halfX = (startX - endX) / 2;
637
- const halfY = (startY - endY) / 2;
638
- const primeX = cos * halfX + sin * halfY;
639
- const primeY = -sin * halfX + cos * halfY;
640
- const scale = primeX ** 2 / rx ** 2 + primeY ** 2 / ry ** 2;
641
- if (scale > 1) {
642
- const factor = Math.sqrt(scale);
643
- rx *= factor;
644
- ry *= factor;
645
- }
646
-
647
- const numerator = Math.max(
648
- 0,
649
- rx ** 2 * ry ** 2 - rx ** 2 * primeY ** 2 - ry ** 2 * primeX ** 2,
650
- );
651
- const denominator = rx ** 2 * primeY ** 2 + ry ** 2 * primeX ** 2;
652
- const direction = largeArc === sweep ? -1 : 1;
653
- const coefficient = denominator === 0 ? 0 : direction * Math.sqrt(numerator / denominator);
654
- const centerPrimeX = (coefficient * rx * primeY) / ry;
655
- const centerPrimeY = (coefficient * -ry * primeX) / rx;
656
- const centerX = cos * centerPrimeX - sin * centerPrimeY + (startX + endX) / 2;
657
- const centerY = sin * centerPrimeX + cos * centerPrimeY + (startY + endY) / 2;
658
- const startVectorX = (primeX - centerPrimeX) / rx;
659
- const startVectorY = (primeY - centerPrimeY) / ry;
660
- const endVectorX = (-primeX - centerPrimeX) / rx;
661
- const endVectorY = (-primeY - centerPrimeY) / ry;
662
- const startAngle = Math.atan2(startVectorY, startVectorX);
663
- const cross = startVectorX * endVectorY - startVectorY * endVectorX;
664
- const dot = startVectorX * endVectorX + startVectorY * endVectorY;
665
- let delta = Math.atan2(cross, dot);
666
- if (sweep && delta < 0) delta += Math.PI * 2;
667
- if (!sweep && delta > 0) delta -= Math.PI * 2;
668
- context.ellipse(centerX, centerY, rx, ry, angle, startAngle, startAngle + delta, !sweep);
669
- }