@heyramzi/ui 2.9.0 → 2.10.1

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 (313) hide show
  1. package/dist/agents/helpers.js +52 -0
  2. package/dist/agents/index.js +3 -0
  3. package/dist/agents/page-state.js +65 -0
  4. package/dist/agents/types.js +1 -0
  5. package/dist/agents/vendor/color.js +149 -0
  6. package/dist/agents/vendor/draw.js +548 -0
  7. package/dist/agents/vendor/engine.js +632 -0
  8. package/dist/agents/vendor/mesh.js +727 -0
  9. package/dist/agents/vendor/plastic.js +3273 -0
  10. package/dist/agents/vendor/presets.js +171 -0
  11. package/dist/agents/vendor/shapes.js +24 -0
  12. package/dist/agents/vendor/ticker.js +56 -0
  13. package/dist/agents/vendor/types.js +0 -0
  14. package/dist/agents/vendor/wear.js +1525 -0
  15. package/dist/ai/ai-button/index.js +2 -0
  16. package/dist/ai/confirmation/confirmation-context.svelte.js +12 -0
  17. package/dist/ai/confirmation/index.js +9 -0
  18. package/dist/ai/generation-progress/index.js +2 -0
  19. package/dist/ai/index.js +11 -0
  20. package/dist/ai/loading-state/index.js +3 -0
  21. package/dist/ai/prompt-input/index.js +6 -0
  22. package/dist/ai/reasoning/index.js +4 -0
  23. package/dist/ai/reasoning/reasoning-context.svelte.js +12 -0
  24. package/dist/ai/response/index.js +3 -0
  25. package/dist/ai/suggestion/index.js +3 -0
  26. package/dist/ai/thinking-dots/index.js +3 -0
  27. package/dist/ai/typing-dots/index.js +2 -0
  28. package/dist/ai/voice-waveform/index.js +3 -0
  29. package/dist/animations/text-swap.js +30 -0
  30. package/dist/brand/index.js +65 -0
  31. package/dist/canvas/card/resize.js +10 -0
  32. package/dist/canvas/edges/edge-path.js +284 -0
  33. package/dist/canvas/editor/context-menu.js +42 -0
  34. package/dist/canvas/editor/dispatch.svelte.js +157 -0
  35. package/dist/canvas/editor/editor-context.js +8 -0
  36. package/dist/canvas/editor/editor-mode.js +0 -0
  37. package/dist/canvas/editor/frame.js +87 -0
  38. package/dist/canvas/editor/hand-context.js +8 -0
  39. package/dist/canvas/editor/history-core.js +221 -0
  40. package/dist/canvas/editor/keymap.js +193 -0
  41. package/dist/canvas/editor/layout-actions.js +170 -0
  42. package/dist/canvas/editor/lock.js +65 -0
  43. package/dist/canvas/editor/rebase.js +279 -0
  44. package/dist/canvas/editor/style.js +174 -0
  45. package/dist/canvas/editor/text-field-context.js +8 -0
  46. package/dist/canvas/editor/z-order.js +82 -0
  47. package/dist/canvas/headless/alignment.js +20 -0
  48. package/dist/canvas/headless/break-apart-find.js +324 -0
  49. package/dist/canvas/headless/break-apart-pieces.js +74 -0
  50. package/dist/canvas/headless/break-apart-plan.js +378 -0
  51. package/dist/canvas/headless/break-apart-style.js +93 -0
  52. package/dist/canvas/headless/break-apart.js +206 -0
  53. package/dist/canvas/headless/canvas-cleanup.js +70 -0
  54. package/dist/canvas/headless/edge-anchors.js +134 -0
  55. package/dist/canvas/headless/edge-memo.js +28 -0
  56. package/dist/canvas/headless/edge-serialization.js +31 -0
  57. package/dist/canvas/headless/figure-geometry.js +331 -0
  58. package/dist/canvas/headless/fit-viewport.js +82 -0
  59. package/dist/canvas/headless/grid.js +96 -0
  60. package/dist/canvas/headless/icon-node.js +45 -0
  61. package/dist/canvas/headless/index.js +1 -0
  62. package/dist/canvas/headless/linkify.js +25 -0
  63. package/dist/canvas/headless/pen-marks.js +115 -0
  64. package/dist/canvas/headless/sketch.js +250 -0
  65. package/dist/canvas/headless/snap-guides.js +100 -0
  66. package/dist/canvas/headless/svg-figure.js +137 -0
  67. package/dist/canvas/headless/table-layout.js +161 -0
  68. package/dist/canvas/index.js +25 -0
  69. package/dist/canvas/lod/lod-mode.svelte.js +22 -0
  70. package/dist/canvas/lod/render-all.svelte.js +45 -0
  71. package/dist/canvas/ops/arrange.js +83 -0
  72. package/dist/canvas/ops/ops.js +318 -0
  73. package/dist/canvas/pen/colors.js +41 -0
  74. package/dist/canvas/pen/eraser.js +35 -0
  75. package/dist/canvas/pen/geometry.js +143 -0
  76. package/dist/canvas/pen/index.js +9 -0
  77. package/dist/canvas/pen/ops.js +15 -0
  78. package/dist/canvas/pen/pen-session.js +171 -0
  79. package/dist/canvas/pen/plugin.js +129 -0
  80. package/dist/canvas/pen/shapes.js +80 -0
  81. package/dist/canvas/pen/stroke-path.js +37 -0
  82. package/dist/canvas/pen/types.js +30 -0
  83. package/dist/canvas/pen/ui.js +20 -0
  84. package/dist/canvas/plugin.js +51 -0
  85. package/dist/canvas/screen/glyphs.js +24 -0
  86. package/dist/canvas/screen/labels.js +24 -0
  87. package/dist/canvas/screen/parts.js +140 -0
  88. package/dist/canvas/screen/plugin.js +71 -0
  89. package/dist/canvas/screen/types.js +44 -0
  90. package/dist/canvas/screen/ui.js +13 -0
  91. package/dist/canvas/test-utils.js +18 -0
  92. package/dist/canvas/types.js +0 -0
  93. package/dist/canvas/ui/forward-wheel.js +27 -0
  94. package/dist/canvas/ui/icons.js +133 -0
  95. package/dist/canvas/ui/place-panel.js +57 -0
  96. package/dist/canvas/ui/shortcut-tip.js +18 -0
  97. package/dist/canvas/ui/tools.js +411 -0
  98. package/dist/charts/dashboard/chart.js +1 -0
  99. package/dist/charts/dashboard/data-table.js +7 -0
  100. package/dist/charts/dashboard/index.js +13 -0
  101. package/dist/charts/dashboard/windows.js +5 -0
  102. package/dist/charts/edge-fade.js +7 -0
  103. package/dist/charts/hover-band.js +13 -0
  104. package/dist/charts/index.js +19 -0
  105. package/dist/charts/motion.js +15 -0
  106. package/dist/charts/primitives/chart-utils.js +22 -0
  107. package/dist/charts/primitives/index.js +4 -0
  108. package/dist/components/copy/clipboard.js +38 -0
  109. package/dist/components/copy/copied.svelte.js +26 -0
  110. package/dist/components/copy/index.js +3 -0
  111. package/dist/components/data-table/data-table.js +55 -0
  112. package/dist/components/data-table/index.js +7 -0
  113. package/dist/components/docs/index.js +3 -0
  114. package/dist/components/docs/scroll-spy.svelte.js +71 -0
  115. package/dist/components/field-row/index.js +1 -0
  116. package/dist/components/hold-to-confirm/index.js +1 -0
  117. package/dist/components/icon/index.js +1 -0
  118. package/dist/components/language-flag/index.js +1 -0
  119. package/dist/components/list-page/filter-section.js +4 -0
  120. package/dist/components/list-page/index.js +25 -0
  121. package/dist/components/list-page/list-table.js +5 -0
  122. package/dist/components/list-page/queue-rail.js +3 -0
  123. package/dist/components/list-page/section-host.js +8 -0
  124. package/dist/components/list-page/step.js +5 -0
  125. package/dist/components/list-page/types.js +0 -0
  126. package/dist/components/locale-switch/index.js +1 -0
  127. package/dist/components/mark/index.js +1 -0
  128. package/dist/components/open-in/index.js +1 -0
  129. package/dist/components/picker/index.js +3 -0
  130. package/dist/components/picker/trigger.js +33 -0
  131. package/dist/components/picker/types.js +0 -0
  132. package/dist/components/section-card/index.js +1 -0
  133. package/dist/components/section-header/index.js +2 -0
  134. package/dist/components/segmented/collapse.js +32 -0
  135. package/dist/components/segmented/index.js +8 -0
  136. package/dist/components/segmented/segmented.js +50 -0
  137. package/dist/components/star-rating-input/index.js +2 -0
  138. package/dist/components/svg/index.js +1 -0
  139. package/dist/components/table-view/index.js +1 -0
  140. package/dist/components/table-view/types.js +0 -0
  141. package/dist/components/tags-input/index.js +2 -0
  142. package/dist/components/tags-input/tags.js +90 -0
  143. package/dist/components/theme/index.js +3 -0
  144. package/dist/components/toolbar/index.js +3 -0
  145. package/dist/components/toolbar/toolbar-trigger.js +4 -0
  146. package/dist/editor/anchors.js +17 -0
  147. package/dist/editor/block-id.js +62 -0
  148. package/dist/editor/block-ops.js +105 -0
  149. package/dist/editor/doc-blocks.js +181 -0
  150. package/dist/editor/extensions.js +200 -0
  151. package/dist/editor/index.js +4 -0
  152. package/dist/editor/markdown-test-helpers.js +6 -0
  153. package/dist/editor/markdown.js +486 -0
  154. package/dist/editor/serializer.js +268 -0
  155. package/dist/editor/slash-items.js +104 -0
  156. package/dist/editor/youtube-url.js +27 -0
  157. package/dist/effects/animated-beam/index.js +1 -0
  158. package/dist/effects/animated-beam/path-calculator.svelte.js +42 -0
  159. package/dist/effects/animated-beam/types.js +0 -0
  160. package/dist/effects/border-beam/css.js +420 -0
  161. package/dist/effects/border-beam/presets.js +1792 -0
  162. package/dist/effects/border-beam/register-properties.js +39 -0
  163. package/dist/effects/border-beam/types.js +0 -0
  164. package/dist/effects/image-comparison/compare.js +4 -0
  165. package/dist/effects/image-reveal/index.js +1 -0
  166. package/dist/effects/image-reveal/types.js +0 -0
  167. package/dist/effects/magnetic/magnetic.js +54 -0
  168. package/dist/effects/reveal/index.js +4 -0
  169. package/dist/effects/reveal/observe.js +43 -0
  170. package/dist/effects/reveal/types.js +0 -0
  171. package/dist/effects/shader-gradient/color.js +34 -0
  172. package/dist/effects/shader-gradient/index.js +1 -0
  173. package/dist/effects/shader-gradient/renderer.js +320 -0
  174. package/dist/effects/shader-gradient/shaders.js +280 -0
  175. package/dist/effects/shader-gradient/types.js +0 -0
  176. package/dist/icons/apple-symbol-exports.js +126 -0
  177. package/dist/icons/sf-symbols.js +465 -0
  178. package/dist/icons/trades.js +34 -0
  179. package/dist/inbox/index.js +4 -0
  180. package/dist/inbox/logic.js +156 -0
  181. package/dist/inbox/types.js +46 -0
  182. package/dist/index.js +18 -0
  183. package/dist/lib/arrive.js +13 -0
  184. package/dist/lib/icon-types.js +0 -0
  185. package/dist/lib/initials.js +17 -0
  186. package/dist/lib/layout.js +1 -0
  187. package/dist/lib/panel.js +3 -0
  188. package/dist/lib/result.js +26 -0
  189. package/dist/lib/sliding-pill.js +45 -0
  190. package/dist/lib/theme-transition.js +53 -0
  191. package/dist/lib/tone.js +32 -0
  192. package/dist/lib/utils.js +5 -0
  193. package/dist/onboarding/define-tours.js +28 -0
  194. package/dist/onboarding/index.js +4 -0
  195. package/dist/onboarding/onboarding.svelte.js +15 -0
  196. package/dist/onboarding/pick.js +16 -0
  197. package/dist/onboarding/stores.js +50 -0
  198. package/dist/onboarding/types.js +1 -0
  199. package/dist/onboarding/wait.js +25 -0
  200. package/dist/panel/index.js +1 -0
  201. package/dist/panel/side-panel-types.js +0 -0
  202. package/dist/record/demo-data.js +512 -0
  203. package/dist/record/fields.js +148 -0
  204. package/dist/record/format.js +97 -0
  205. package/dist/record/gutter.js +1 -0
  206. package/dist/record/index.js +15 -0
  207. package/dist/record/kinds.js +110 -0
  208. package/dist/record/logic.js +255 -0
  209. package/dist/record/types.js +52 -0
  210. package/dist/shadcn/accordion/index.js +5 -0
  211. package/dist/shadcn/alert/index.js +5 -0
  212. package/dist/shadcn/alert-dialog/index.js +12 -0
  213. package/dist/shadcn/attachment/index.js +10 -0
  214. package/dist/shadcn/avatar/index.js +7 -0
  215. package/dist/shadcn/badge/index.js +2 -0
  216. package/dist/shadcn/breadcrumb/index.js +8 -0
  217. package/dist/shadcn/bubble/index.js +5 -0
  218. package/dist/shadcn/button/index.js +2 -0
  219. package/dist/shadcn/calendar/index.js +19 -0
  220. package/dist/shadcn/card/index.js +8 -0
  221. package/dist/shadcn/checkbox/index.js +2 -0
  222. package/dist/shadcn/code-block/index.js +9 -0
  223. package/dist/shadcn/collapsible/index.js +4 -0
  224. package/dist/shadcn/command/index.js +13 -0
  225. package/dist/shadcn/context-menu/index.js +17 -0
  226. package/dist/shadcn/dialog/index.js +11 -0
  227. package/dist/shadcn/dropdown-menu/index.js +19 -0
  228. package/dist/shadcn/dropdown-menu/menu-item.js +23 -0
  229. package/dist/shadcn/empty/index.js +7 -0
  230. package/dist/shadcn/field/index.js +12 -0
  231. package/dist/shadcn/hooks/highlighter.js +92 -0
  232. package/dist/shadcn/hooks/is-mobile.svelte.js +7 -0
  233. package/dist/shadcn/hooks/use-highlighted-code.svelte.js +65 -0
  234. package/dist/shadcn/hover-card/index.js +5 -0
  235. package/dist/shadcn/input/index.js +3 -0
  236. package/dist/shadcn/input-otp/index.js +5 -0
  237. package/dist/shadcn/kbd/index.js +3 -0
  238. package/dist/shadcn/label/index.js +2 -0
  239. package/dist/shadcn/marker/index.js +4 -0
  240. package/dist/shadcn/message/index.js +7 -0
  241. package/dist/shadcn/message-scroller/index.js +8 -0
  242. package/dist/shadcn/popover/index.js +9 -0
  243. package/dist/shadcn/progress/index.js +2 -0
  244. package/dist/shadcn/progress/tone.js +11 -0
  245. package/dist/shadcn/radio-group/index.js +3 -0
  246. package/dist/shadcn/scroll-area/index.js +3 -0
  247. package/dist/shadcn/select/index.js +12 -0
  248. package/dist/shadcn/separator/index.js +2 -0
  249. package/dist/shadcn/sheet/index.js +11 -0
  250. package/dist/shadcn/sidebar/constants.js +6 -0
  251. package/dist/shadcn/sidebar/context.svelte.js +38 -0
  252. package/dist/shadcn/sidebar/index.js +25 -0
  253. package/dist/shadcn/skeleton/index.js +2 -0
  254. package/dist/shadcn/slider/index.js +2 -0
  255. package/dist/shadcn/sonner/index.js +1 -0
  256. package/dist/shadcn/spinner/index.js +1 -0
  257. package/dist/shadcn/switch/index.js +2 -0
  258. package/dist/shadcn/table/index.js +9 -0
  259. package/dist/shadcn/tabs/index.js +5 -0
  260. package/dist/shadcn/textarea/index.js +2 -0
  261. package/dist/shadcn/toggle/index.js +3 -0
  262. package/dist/shadcn/toggle-group/index.js +3 -0
  263. package/dist/shadcn/tooltip/context.js +8 -0
  264. package/dist/shadcn/tooltip/index.js +6 -0
  265. package/dist/shadcn/trace/index.js +9 -0
  266. package/dist/slides/bridges.js +66 -0
  267. package/dist/slides/deck-controller.svelte.js +221 -0
  268. package/dist/slides/export/capture.js +81 -0
  269. package/dist/slides/export/ffmpeg.js +85 -0
  270. package/dist/slides/export/index.js +4 -0
  271. package/dist/slides/export/launch.js +8 -0
  272. package/dist/slides/export/pdf.js +78 -0
  273. package/dist/slides/export/types.js +0 -0
  274. package/dist/slides/index.js +7 -0
  275. package/dist/slides/labels.js +26 -0
  276. package/dist/slides/layout.js +47 -0
  277. package/dist/slides/model.js +9 -0
  278. package/dist/slides/navigation.js +89 -0
  279. package/dist/slides/types.js +6 -0
  280. package/dist/status/define-statuses.js +16 -0
  281. package/dist/status/index.js +4 -0
  282. package/dist/status/status-types.js +0 -0
  283. package/dist/test-setup.js +26 -0
  284. package/dist/thread/index.js +3 -0
  285. package/dist/thread/logic.js +94 -0
  286. package/dist/thread/types.js +23 -0
  287. package/dist/work/board-order.js +109 -0
  288. package/dist/work/dates.js +19 -0
  289. package/dist/work/detail/detail-types.js +20 -0
  290. package/dist/work/docs/edited.js +39 -0
  291. package/dist/work/docs/index.js +7 -0
  292. package/dist/work/docs/labels.js +38 -0
  293. package/dist/work/docs/menu.js +121 -0
  294. package/dist/work/docs/outline.js +39 -0
  295. package/dist/work/gantt/logic.js +260 -0
  296. package/dist/work/inbox/inbox-logic.js +94 -0
  297. package/dist/work/inbox/inbox-statuses.js +86 -0
  298. package/dist/work/inbox/inbox-types.js +0 -0
  299. package/dist/work/inbox/index.js +1 -0
  300. package/dist/work/index.js +21 -0
  301. package/dist/work/kanban-drag.js +25 -0
  302. package/dist/work/kanban-types.js +0 -0
  303. package/dist/work/presets/sales.js +35 -0
  304. package/dist/work/reorder.js +10 -0
  305. package/dist/work/task-types.js +0 -0
  306. package/dist/work/time/duration.js +60 -0
  307. package/dist/work/time/time-types.js +25 -0
  308. package/dist/work/use-kanban-dnd.svelte.js +128 -0
  309. package/package.json +45 -3
  310. package/src/components/toolbar/toolbar-trigger.ts +8 -2
  311. package/src/record/demo-data.ts +4 -4
  312. package/src/record/record-demo.svelte +2 -2
  313. package/src/status/status-dot.svelte +0 -2
@@ -0,0 +1,171 @@
1
+ import { strokesAlong } from "./eraser.js";
2
+ import { buildStrokeNode } from "./geometry.js";
3
+ import { addPenNode, removePenNode } from "./ops.js";
4
+ import { buildShapeNode, buildTextNode, dragBox } from "./shapes.js";
5
+ import { strokePath } from "./stroke-path.js";
6
+ import { PEN_DEFAULTS } from "./types.js";
7
+ const ERASER_RADIUS = 10;
8
+ const MIN_SAMPLE = 1;
9
+ function isShapeTool(tool) {
10
+ return tool === "rectangle" || tool === "ellipse" || tool === "diamond";
11
+ }
12
+ export function createPenSession(host, getSettings) {
13
+ let endGesture = null;
14
+ let start = null;
15
+ let last = null;
16
+ let samples = [];
17
+ const erased = new Set();
18
+ function settingsNow() {
19
+ const settings = getSettings();
20
+ const fallback = settings.tool === "highlighter" ? PEN_DEFAULTS.highlighter.size : PEN_DEFAULTS.pen.size;
21
+ return {
22
+ ...settings,
23
+ size: settings.size ?? fallback
24
+ };
25
+ }
26
+ function reset() {
27
+ endGesture = null;
28
+ start = null;
29
+ last = null;
30
+ samples = [];
31
+ erased.clear();
32
+ host.onPreview?.(null);
33
+ }
34
+ function erase(from, to, radius) {
35
+ const remaining = host.getNodes().filter((node)=>!erased.has(node.id));
36
+ const ids = strokesAlong(remaining, from, to, radius);
37
+ if (ids.length === 0) return;
38
+ for (const id of ids)erased.add(id);
39
+ host.commit(ids.map(removePenNode));
40
+ }
41
+ function placeText(at, color) {
42
+ const op = addPenNode(buildTextNode(at, {
43
+ color
44
+ }));
45
+ host.commit([
46
+ op
47
+ ]);
48
+ if (op.kind === "addNode" && op.node.id) host.onTextPlaced?.(op.node.id);
49
+ }
50
+ function sampleOf(at, pressure) {
51
+ return pressure === undefined ? [
52
+ at.x,
53
+ at.y
54
+ ] : [
55
+ at.x,
56
+ at.y,
57
+ pressure
58
+ ];
59
+ }
60
+ function previewStroke(pointerDown) {
61
+ const { tool, color, size } = settingsNow();
62
+ if (tool !== "pen" && tool !== "highlighter") return;
63
+ const hasPressure = samples.some((point)=>point[2] !== undefined);
64
+ const d = strokePath(samples, {
65
+ size,
66
+ tool,
67
+ simulatePressure: !hasPressure
68
+ }, !pointerDown);
69
+ host.onPreview?.({
70
+ kind: "stroke",
71
+ d,
72
+ color,
73
+ tool
74
+ });
75
+ }
76
+ return {
77
+ get active () {
78
+ return start !== null;
79
+ },
80
+ down (at, pressure) {
81
+ if (start) return;
82
+ const { tool, color, zoom } = settingsNow();
83
+ if (tool === "text") {
84
+ placeText(at, color);
85
+ return;
86
+ }
87
+ endGesture = host.startGesture();
88
+ start = at;
89
+ last = at;
90
+ if (tool === "eraser") {
91
+ const radius = ERASER_RADIUS / zoom;
92
+ host.onPreview?.({
93
+ kind: "eraser",
94
+ at,
95
+ radius
96
+ });
97
+ erase(at, at, radius);
98
+ return;
99
+ }
100
+ if (tool === "pen" || tool === "highlighter") {
101
+ samples = [
102
+ sampleOf(at, pressure)
103
+ ];
104
+ previewStroke(true);
105
+ }
106
+ },
107
+ move (at, pressure) {
108
+ if (!start || !last) return;
109
+ const { tool, color, zoom } = settingsNow();
110
+ if (tool === "eraser") {
111
+ const radius = ERASER_RADIUS / zoom;
112
+ host.onPreview?.({
113
+ kind: "eraser",
114
+ at,
115
+ radius
116
+ });
117
+ erase(last, at, radius);
118
+ last = at;
119
+ return;
120
+ }
121
+ if (isShapeTool(tool)) {
122
+ host.onPreview?.({
123
+ kind: "shape",
124
+ shape: tool,
125
+ box: dragBox(start, at),
126
+ color
127
+ });
128
+ last = at;
129
+ return;
130
+ }
131
+ if (Math.hypot(at.x - last.x, at.y - last.y) * zoom < MIN_SAMPLE) return;
132
+ samples.push(sampleOf(at, pressure));
133
+ last = at;
134
+ previewStroke(true);
135
+ },
136
+ up (at, options = {}) {
137
+ if (!start || !endGesture) return;
138
+ const { tool, color, size, zoom } = settingsNow();
139
+ const close = endGesture;
140
+ try {
141
+ if (tool === "pen" || tool === "highlighter") {
142
+ const node = buildStrokeNode(samples, {
143
+ color,
144
+ size,
145
+ tool,
146
+ zoom
147
+ });
148
+ if (node) host.commit([
149
+ addPenNode(node)
150
+ ]);
151
+ } else if (isShapeTool(tool)) {
152
+ const box = dragBox(start, at, options.square);
153
+ host.commit([
154
+ addPenNode(buildShapeNode(tool, box, {
155
+ color
156
+ }))
157
+ ]);
158
+ }
159
+ } finally{
160
+ close();
161
+ reset();
162
+ }
163
+ },
164
+ cancel () {
165
+ if (!endGesture) return;
166
+ const close = endGesture;
167
+ close();
168
+ reset();
169
+ }
170
+ };
171
+ }
@@ -0,0 +1,129 @@
1
+ import { z } from "zod";
2
+ import { CanvasOpError } from "../ops/ops.js";
3
+ import { definePlugin } from "../plugin.js";
4
+ import { buildStrokeNode } from "./geometry.js";
5
+ import { buildShapeNode, buildTextNode } from "./shapes.js";
6
+ import { PEN_COLORS, SHAPE_KINDS, SHAPE_NODE, STROKE_NODE, TEXT_NODE } from "./types.js";
7
+ const colorSchema = z.enum(PEN_COLORS);
8
+ const pointSchema = z.object({
9
+ x: z.number(),
10
+ y: z.number()
11
+ });
12
+ const MAX_POINTS = 5000;
13
+ const addStrokeOp = z.object({
14
+ kind: z.literal("addStroke"),
15
+ id: z.string().min(1).optional(),
16
+ points: z.array(z.tuple([
17
+ z.number(),
18
+ z.number()
19
+ ]).rest(z.number())).min(1).max(MAX_POINTS),
20
+ color: colorSchema.optional(),
21
+ size: z.number().positive().optional(),
22
+ tool: z.enum([
23
+ "pen",
24
+ "highlighter"
25
+ ]).optional()
26
+ });
27
+ const addTextOp = z.object({
28
+ kind: z.literal("addText"),
29
+ id: z.string().min(1).optional(),
30
+ at: pointSchema,
31
+ text: z.string(),
32
+ color: colorSchema.optional(),
33
+ fontSize: z.number().positive().optional()
34
+ });
35
+ const addShapeOp = z.object({
36
+ kind: z.literal("addShape"),
37
+ id: z.string().min(1).optional(),
38
+ shape: z.enum(SHAPE_KINDS),
39
+ box: z.object({
40
+ x: z.number(),
41
+ y: z.number(),
42
+ width: z.number().nonnegative(),
43
+ height: z.number().nonnegative()
44
+ }),
45
+ color: colorSchema.optional(),
46
+ filled: z.boolean().optional(),
47
+ label: z.string().optional()
48
+ });
49
+ function appendNode(state, node, opIndex) {
50
+ const id = node.id ?? crypto.randomUUID();
51
+ if (state.nodes.some((existing)=>existing.id === id)) {
52
+ throw new CanvasOpError(`Node id already exists: ${id}`, opIndex);
53
+ }
54
+ state.nodes = [
55
+ ...state.nodes,
56
+ {
57
+ ...node,
58
+ id
59
+ }
60
+ ];
61
+ }
62
+ function applyAddStroke(state, op, opIndex) {
63
+ const node = buildStrokeNode(op.points, {
64
+ id: op.id,
65
+ color: op.color,
66
+ size: op.size,
67
+ tool: op.tool
68
+ });
69
+ if (!node) throw new CanvasOpError("addStroke needs at least one point", opIndex);
70
+ appendNode(state, node, opIndex);
71
+ }
72
+ function applyAddText(state, op, opIndex) {
73
+ appendNode(state, buildTextNode(op.at, {
74
+ id: op.id,
75
+ text: op.text,
76
+ color: op.color,
77
+ fontSize: op.fontSize
78
+ }), opIndex);
79
+ }
80
+ function applyAddShape(state, op, opIndex) {
81
+ appendNode(state, buildShapeNode(op.shape, op.box, {
82
+ id: op.id,
83
+ color: op.color,
84
+ filled: op.filled,
85
+ label: op.label
86
+ }), opIndex);
87
+ }
88
+ export const penPlugin = definePlugin({
89
+ id: "pen",
90
+ nodes: [
91
+ {
92
+ type: STROKE_NODE,
93
+ label: "Stroke"
94
+ },
95
+ {
96
+ type: TEXT_NODE,
97
+ label: "Text",
98
+ sizing: "content-sized",
99
+ size: {
100
+ width: 120
101
+ }
102
+ },
103
+ {
104
+ type: SHAPE_NODE,
105
+ label: "Shape",
106
+ size: {
107
+ width: 160,
108
+ height: 100
109
+ }
110
+ }
111
+ ],
112
+ ops: [
113
+ {
114
+ kind: "addStroke",
115
+ schema: addStrokeOp,
116
+ apply: applyAddStroke
117
+ },
118
+ {
119
+ kind: "addText",
120
+ schema: addTextOp,
121
+ apply: applyAddText
122
+ },
123
+ {
124
+ kind: "addShape",
125
+ schema: addShapeOp,
126
+ apply: applyAddShape
127
+ }
128
+ ]
129
+ });
@@ -0,0 +1,80 @@
1
+ import { PEN_DEFAULTS, SHAPE_NODE, TEXT_NODE } from "./types.js";
2
+ const MIN_DRAG = 6;
3
+ const DEFAULT_SHAPE = {
4
+ width: 160,
5
+ height: 100
6
+ };
7
+ export function dragBox(from, to, square = false) {
8
+ let dx = to.x - from.x;
9
+ let dy = to.y - from.y;
10
+ if (square) {
11
+ const side = Math.max(Math.abs(dx), Math.abs(dy));
12
+ dx = Math.sign(dx || 1) * side;
13
+ dy = Math.sign(dy || 1) * side;
14
+ }
15
+ return {
16
+ x: Math.min(from.x, from.x + dx),
17
+ y: Math.min(from.y, from.y + dy),
18
+ width: Math.abs(dx),
19
+ height: Math.abs(dy)
20
+ };
21
+ }
22
+ export function buildShapeNode(shape, box, options = {}) {
23
+ const click = box.width < MIN_DRAG && box.height < MIN_DRAG;
24
+ const width = Math.round(click ? DEFAULT_SHAPE.width : Math.max(box.width, MIN_DRAG));
25
+ const height = Math.round(click ? DEFAULT_SHAPE.height : Math.max(box.height, MIN_DRAG));
26
+ const x = click ? box.x - width / 2 : box.x;
27
+ const y = click ? box.y - height / 2 : box.y;
28
+ return {
29
+ id: options.id,
30
+ type: SHAPE_NODE,
31
+ position: {
32
+ x: Math.round(x),
33
+ y: Math.round(y)
34
+ },
35
+ data: {
36
+ shape,
37
+ color: options.color ?? PEN_DEFAULTS.color,
38
+ strokeWidth: PEN_DEFAULTS.strokeWidth,
39
+ filled: options.filled ?? false,
40
+ label: options.label ?? ""
41
+ },
42
+ width,
43
+ height
44
+ };
45
+ }
46
+ export function buildTextNode(at, options = {}) {
47
+ return {
48
+ id: options.id,
49
+ type: TEXT_NODE,
50
+ position: {
51
+ x: Math.round(at.x),
52
+ y: Math.round(at.y)
53
+ },
54
+ data: {
55
+ text: options.text ?? "",
56
+ color: options.color ?? PEN_DEFAULTS.color,
57
+ fontSize: options.fontSize ?? PEN_DEFAULTS.fontSize
58
+ },
59
+ width: 120,
60
+ height: Math.round((options.fontSize ?? PEN_DEFAULTS.fontSize) * 1.4)
61
+ };
62
+ }
63
+ export function shapeOutline(shape, width, height, inset) {
64
+ const left = inset;
65
+ const top = inset;
66
+ const right = Math.max(width - inset, left);
67
+ const bottom = Math.max(height - inset, top);
68
+ if (shape === "diamond") {
69
+ const midX = (left + right) / 2;
70
+ const midY = (top + bottom) / 2;
71
+ return `M${midX},${top} L${right},${midY} L${midX},${bottom} L${left},${midY} Z`;
72
+ }
73
+ if (shape === "ellipse") {
74
+ const rx = (right - left) / 2;
75
+ const ry = (bottom - top) / 2;
76
+ const cy = (top + bottom) / 2;
77
+ return `M${left},${cy} a${rx},${ry} 0 1,0 ${rx * 2},0 a${rx},${ry} 0 1,0 ${-rx * 2},0 Z`;
78
+ }
79
+ return `M${left},${top} H${right} V${bottom} H${left} Z`;
80
+ }
@@ -0,0 +1,37 @@
1
+ import { getStroke } from "perfect-freehand";
2
+ function average(a, b) {
3
+ return (a + b) / 2;
4
+ }
5
+ export function outlineToPath(outline) {
6
+ if (outline.length < 4) return "";
7
+ const first = outline[0];
8
+ const second = outline[1];
9
+ const third = outline[2];
10
+ let path = `M${first[0].toFixed(2)},${first[1].toFixed(2)} ` + `Q${second[0].toFixed(2)},${second[1].toFixed(2)} ` + `${average(second[0], third[0]).toFixed(2)},${average(second[1], third[1]).toFixed(2)} T`;
11
+ for(let i = 2; i < outline.length - 1; i++){
12
+ const a = outline[i];
13
+ const b = outline[i + 1];
14
+ path += `${average(a[0], b[0]).toFixed(2)},${average(a[1], b[1]).toFixed(2)} `;
15
+ }
16
+ return `${path}Z`;
17
+ }
18
+ export function strokePath(points, shape, last = true) {
19
+ if (points.length === 0) return "";
20
+ const highlighter = shape.tool === "highlighter";
21
+ const outline = getStroke(points.map((point)=>point[2] === undefined ? [
22
+ point[0],
23
+ point[1]
24
+ ] : [
25
+ point[0],
26
+ point[1],
27
+ point[2]
28
+ ]), {
29
+ size: shape.size,
30
+ thinning: highlighter ? 0 : 0.55,
31
+ smoothing: 0.6,
32
+ streamline: highlighter ? 0.7 : 0.5,
33
+ simulatePressure: shape.simulatePressure && !highlighter,
34
+ last
35
+ });
36
+ return outlineToPath(outline);
37
+ }
@@ -0,0 +1,30 @@
1
+ export const STROKE_NODE = "stroke";
2
+ export const TEXT_NODE = "text";
3
+ export const SHAPE_NODE = "shape";
4
+ export const PEN_COLORS = [
5
+ "ink",
6
+ "red",
7
+ "blue",
8
+ "green",
9
+ "amber",
10
+ "violet",
11
+ "indigo",
12
+ "terra"
13
+ ];
14
+ export const SHAPE_KINDS = [
15
+ "rectangle",
16
+ "ellipse",
17
+ "diamond"
18
+ ];
19
+ export const PEN_DEFAULTS = {
20
+ pen: {
21
+ size: 4
22
+ },
23
+ highlighter: {
24
+ size: 20
25
+ },
26
+ strokeWidth: 3,
27
+ fontSize: 20,
28
+ color: "ink"
29
+ };
30
+ export const HIGHLIGHTER_OPACITY = 0.38;
@@ -0,0 +1,20 @@
1
+ import { definePlugin } from "../plugin.js";
2
+ import PenOverlay from "../../../src/canvas/pen/PenOverlay.svelte";
3
+ import { penPlugin } from "./plugin.js";
4
+ import ShapeNode from "../../../src/canvas/pen/ShapeNode.svelte";
5
+ import StrokeNode from "../../../src/canvas/components/shared/svg/StrokeNode.svelte";
6
+ import TextNode from "../../../src/canvas/pen/TextNode.svelte";
7
+ import { SHAPE_NODE, STROKE_NODE, TEXT_NODE } from "./types.js";
8
+ export { PenOverlay, ShapeNode, StrokeNode, TextNode };
9
+ const components = {
10
+ [STROKE_NODE]: StrokeNode,
11
+ [TEXT_NODE]: TextNode,
12
+ [SHAPE_NODE]: ShapeNode
13
+ };
14
+ export const penUiPlugin = definePlugin({
15
+ ...penPlugin,
16
+ nodes: (penPlugin.nodes ?? []).map((kind)=>({
17
+ ...kind,
18
+ component: components[kind.type]
19
+ }))
20
+ });
@@ -0,0 +1,51 @@
1
+ import { z } from "zod";
2
+ export function definePlugin(plugin) {
3
+ return plugin;
4
+ }
5
+ export function createRegistry(plugins) {
6
+ const nodes = new Map();
7
+ const ops = new Map();
8
+ const layouts = [];
9
+ const owner = new Map();
10
+ const claim = (key, pluginId)=>{
11
+ const first = owner.get(key);
12
+ if (first) throw new Error(`"${key}" is claimed by both "${first}" and "${pluginId}"`);
13
+ owner.set(key, pluginId);
14
+ };
15
+ for (const plugin of plugins){
16
+ for (const kind of plugin.nodes ?? []){
17
+ claim(`node:${kind.type}`, plugin.id);
18
+ nodes.set(kind.type, kind);
19
+ }
20
+ for (const op of plugin.ops ?? []){
21
+ claim(`op:${op.kind}`, plugin.id);
22
+ ops.set(op.kind, op);
23
+ }
24
+ layouts.push(...plugin.layouts ?? []);
25
+ }
26
+ const typesWhere = (sizing)=>new Set([
27
+ ...nodes.values()
28
+ ].filter((k)=>k.sizing === sizing).map((k)=>k.type));
29
+ return {
30
+ plugins,
31
+ nodes,
32
+ ops,
33
+ layouts,
34
+ nodeTypes () {
35
+ const out = {};
36
+ for (const kind of nodes.values())if (kind.component) out[kind.type] = kind.component;
37
+ return out;
38
+ },
39
+ contentSizedTypes: ()=>typesWhere("content-sized"),
40
+ layoutOwnedTypes: ()=>typesWhere("layout-owned"),
41
+ parseOp (input) {
42
+ const kind = input?.kind;
43
+ const def = typeof kind === "string" ? ops.get(kind) : undefined;
44
+ if (!def) throw new Error(`Unknown op kind: ${String(kind)}`);
45
+ return def.schema.parse(input);
46
+ },
47
+ pickLayout (data, options = {}) {
48
+ return layouts.find((pass)=>pass.matches(data, options)) ?? null;
49
+ }
50
+ };
51
+ }
@@ -0,0 +1,24 @@
1
+ import header from "../../../src/canvas/screen/glyphs/header.svg";
2
+ import button from "../../../src/canvas/screen/glyphs/button.svg";
3
+ import input from "../../../src/canvas/screen/glyphs/input.svg";
4
+ import image from "../../../src/canvas/screen/glyphs/image.svg";
5
+ import list from "../../../src/canvas/screen/glyphs/list.svg";
6
+ import modal from "../../../src/canvas/screen/glyphs/modal.svg";
7
+ import up from "../../../src/canvas/screen/glyphs/up.svg";
8
+ import down from "../../../src/canvas/screen/glyphs/down.svg";
9
+ import close from "../../../src/canvas/screen/glyphs/close.svg";
10
+ import plus from "../../../src/canvas/screen/glyphs/plus.svg";
11
+ import hills from "../../../src/canvas/screen/glyphs/hills.svg";
12
+ export const GLYPHS = {
13
+ header,
14
+ button,
15
+ input,
16
+ image,
17
+ list,
18
+ modal,
19
+ up,
20
+ down,
21
+ close,
22
+ plus,
23
+ hills
24
+ };
@@ -0,0 +1,24 @@
1
+ export const DEFAULT_SCREEN_LABELS = {
2
+ name: "Screen",
3
+ mode: "Mode",
4
+ modes: {
5
+ wireframe: "Wireframe",
6
+ mockup: "Mockup"
7
+ },
8
+ kinds: {
9
+ header: "Header",
10
+ button: "Button",
11
+ input: "Input",
12
+ image: "Image",
13
+ list: "List",
14
+ modal: "Modal"
15
+ },
16
+ addPart: "Add part",
17
+ moveUp: "Move up",
18
+ moveDown: "Move down",
19
+ remove: "Remove",
20
+ primary: "Primary",
21
+ secondary: "Secondary",
22
+ addItem: "Add item",
23
+ removeItem: "Remove item"
24
+ };