@heyramzi/ui 2.9.0 → 2.10.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 (312) 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
@@ -0,0 +1,82 @@
1
+ export const INK_TYPES = new Set([
2
+ "stroke",
3
+ "text",
4
+ "shape"
5
+ ]);
6
+ function layerOf(node) {
7
+ return typeof node.zIndex === "number" ? node.zIndex : 0;
8
+ }
9
+ function stacks(nodes) {
10
+ const byParent = new Map();
11
+ nodes.forEach((node, index)=>{
12
+ if (INK_TYPES.has(node.type ?? "")) return;
13
+ const key = node.parentId ?? "";
14
+ const stack = byParent.get(key) ?? [];
15
+ stack.push({
16
+ node,
17
+ index
18
+ });
19
+ byParent.set(key, stack);
20
+ });
21
+ for (const stack of byParent.values()){
22
+ stack.sort((a, b)=>layerOf(a.node) - layerOf(b.node) || a.index - b.index);
23
+ }
24
+ return byParent;
25
+ }
26
+ function moved(stack, picked, move) {
27
+ const isPicked = (slot)=>picked.has(slot.node.id);
28
+ if (move === "front") return [
29
+ ...stack.filter((s)=>!isPicked(s)),
30
+ ...stack.filter(isPicked)
31
+ ];
32
+ if (move === "back") return [
33
+ ...stack.filter(isPicked),
34
+ ...stack.filter((s)=>!isPicked(s))
35
+ ];
36
+ const next = [
37
+ ...stack
38
+ ];
39
+ if (move === "forward") {
40
+ for(let i = next.length - 2; i >= 0; i--){
41
+ if (isPicked(next[i]) && !isPicked(next[i + 1])) [next[i], next[i + 1]] = [
42
+ next[i + 1],
43
+ next[i]
44
+ ];
45
+ }
46
+ } else {
47
+ for(let i = 1; i < next.length; i++){
48
+ if (isPicked(next[i]) && !isPicked(next[i - 1])) [next[i], next[i - 1]] = [
49
+ next[i - 1],
50
+ next[i]
51
+ ];
52
+ }
53
+ }
54
+ return next;
55
+ }
56
+ export function reorderStack(nodes, picked, move) {
57
+ const layers = new Map();
58
+ for (const stack of stacks(nodes).values()){
59
+ if (!stack.some((slot)=>picked.has(slot.node.id))) continue;
60
+ const next = moved(stack, picked, move);
61
+ if (next.every((slot, i)=>slot === stack[i])) continue;
62
+ next.forEach((slot, rank)=>{
63
+ if (layerOf(slot.node) !== rank) layers.set(slot.node.id, rank);
64
+ });
65
+ }
66
+ if (layers.size === 0) return null;
67
+ return nodes.map((node)=>{
68
+ const layer = layers.get(node.id);
69
+ return layer === undefined ? node : {
70
+ ...node,
71
+ zIndex: layer
72
+ };
73
+ });
74
+ }
75
+ export function topLayer(nodes, parentId) {
76
+ let top = 0;
77
+ for (const node of nodes){
78
+ if (INK_TYPES.has(node.type ?? "") || (node.parentId ?? "") !== (parentId ?? "")) continue;
79
+ top = Math.max(top, layerOf(node));
80
+ }
81
+ return top > 0 ? top + 1 : undefined;
82
+ }
@@ -0,0 +1,20 @@
1
+ export function alignNodesHorizontally(nodes) {
2
+ if (nodes.length < 2) return;
3
+ const targetY = Math.min(...nodes.map((n)=>n.position.y));
4
+ for (const node of nodes){
5
+ node.position = {
6
+ ...node.position,
7
+ y: targetY
8
+ };
9
+ }
10
+ }
11
+ export function alignNodesVertically(nodes) {
12
+ if (nodes.length < 2) return;
13
+ const targetX = Math.min(...nodes.map((n)=>n.position.x));
14
+ for (const node of nodes){
15
+ node.position = {
16
+ ...node.position,
17
+ x: targetX
18
+ };
19
+ }
20
+ }
@@ -0,0 +1,324 @@
1
+ import { areaOf, boxOfEl, centerOf, contains, fontSize, hasText, isBold, isEl, num, plus, solid, strokeEnds, textLines, translateOf, visible, within } from "./figure-geometry.js";
2
+ const MAX_CARD_TEXTS = 8;
3
+ const MAX_CARD_AREA = 0.4;
4
+ export const LAND_TOLERANCE = 8;
5
+ export const ARROWHEAD_MAX = 20;
6
+ const BADGE_MAX_CHARS = 2;
7
+ const BADGE_MAX_R = 30;
8
+ const MIN_SIDE = 4;
9
+ const ORIGIN = {
10
+ x: 0,
11
+ y: 0
12
+ };
13
+ const anchorOf = (el, offset)=>({
14
+ x: num(el.attrs.x) + offset.x,
15
+ y: num(el.attrs.y) + offset.y
16
+ });
17
+ function holdsText(rect, texts, offset) {
18
+ if (rect.tag !== "rect" || !visible(rect) || rect.attrs.fill === "none") return null;
19
+ const box = boxOfEl(rect, offset);
20
+ if (!box) return null;
21
+ return texts.some((t)=>contains(box, anchorOf(t, offset), 3)) ? box : null;
22
+ }
23
+ function splitBadge(inside, kids) {
24
+ let badge;
25
+ const words = [];
26
+ const badgeParts = [];
27
+ for (const t of inside){
28
+ const line = textLines(t).join(" ");
29
+ const dot = kids.find((k)=>k.tag === "circle" && Math.hypot(num(k.attrs.cx) - num(t.attrs.x), num(k.attrs.cy) - num(t.attrs.y)) <= num(k.attrs.r) + 2);
30
+ if (dot && line.length <= 2) {
31
+ badge = line;
32
+ badgeParts.push(dot, t);
33
+ } else words.push(t);
34
+ }
35
+ return {
36
+ badge,
37
+ words,
38
+ badgeParts
39
+ };
40
+ }
41
+ function headlineOf(ordered) {
42
+ const titleEl = ordered.find((t)=>isBold(t) && t.attrs["text-anchor"] !== "end") ?? [
43
+ ...ordered
44
+ ].sort((a, b)=>Number(isBold(b)) - Number(isBold(a)) || fontSize(b) - fontSize(a))[0];
45
+ const tag = ordered.find((t)=>t !== titleEl && t.attrs["text-anchor"] === "end" && Math.abs(num(t.attrs.y) - num(titleEl.attrs.y)) < 8);
46
+ const titleEls = [
47
+ titleEl
48
+ ];
49
+ const sameFace = (t)=>fontSize(t) === fontSize(titleEl) && isBold(t) === isBold(titleEl) && t.attrs["text-anchor"] === titleEl.attrs["text-anchor"];
50
+ for (const t of ordered.slice(ordered.indexOf(titleEl) + 1)){
51
+ if (t === tag || !sameFace(t)) break;
52
+ titleEls.push(t);
53
+ }
54
+ const bodyEls = ordered.filter((t)=>!titleEls.includes(t) && t !== tag);
55
+ return {
56
+ titleEls,
57
+ tag,
58
+ bodyEls
59
+ };
60
+ }
61
+ function bodyLines(bodyEls) {
62
+ const body = [];
63
+ let lastY = Number.NaN;
64
+ for (const t of bodyEls){
65
+ const text = textLines(t).join(" ");
66
+ if (Math.abs(num(t.attrs.y) - lastY) < 3 && body.length > 0) body[body.length - 1] += ` ${text}`;
67
+ else body.push(text);
68
+ lastY = num(t.attrs.y);
69
+ }
70
+ return body;
71
+ }
72
+ function chromeOf(req, claimed) {
73
+ const { kids, box, offset, taken } = req;
74
+ return kids.filter((k)=>{
75
+ if (claimed.has(k) || taken.has(k) || k.attrs.fill === "none") return false;
76
+ const kb = boxOfEl(k, offset);
77
+ return kb !== null && within(kb, box);
78
+ });
79
+ }
80
+ const readingOrder = (a, b)=>num(a.attrs.y) - num(b.attrs.y) || num(a.attrs.x) - num(b.attrs.x);
81
+ function cardFromRect(req) {
82
+ const { group, kids, rect, box, offset, taken } = req;
83
+ const inside = kids.filter((k)=>hasText(k) && !taken.has(k) && contains(box, anchorOf(k, offset), 3));
84
+ if (inside.length === 0 || inside.length > MAX_CARD_TEXTS) return null;
85
+ const { badge, words, badgeParts } = splitBadge(inside, kids);
86
+ if (words.length === 0) return null;
87
+ const { titleEls, tag, bodyEls } = headlineOf([
88
+ ...words
89
+ ].sort(readingOrder));
90
+ const claimed = new Set([
91
+ rect,
92
+ ...badgeParts,
93
+ ...titleEls,
94
+ ...tag ? [
95
+ tag
96
+ ] : [],
97
+ ...bodyEls
98
+ ]);
99
+ for (const k of chromeOf(req, claimed))claimed.add(k);
100
+ return {
101
+ group,
102
+ offset,
103
+ rect,
104
+ box,
105
+ claimed,
106
+ title: titleEls.map((t)=>textLines(t).join(" ")).join(" "),
107
+ titleSize: fontSize(titleEls[0]),
108
+ kicker: [
109
+ badge,
110
+ tag ? textLines(tag).join(" ") : undefined
111
+ ].filter(Boolean).join(" · ") || undefined,
112
+ body: bodyLines(bodyEls)
113
+ };
114
+ }
115
+ function readPinCards({ group, kids, texts, offset }) {
116
+ const taken = new Set();
117
+ const out = [];
118
+ for (const rect of kids){
119
+ const box = holdsText(rect, texts, offset);
120
+ const found = box && cardFromRect({
121
+ group,
122
+ kids,
123
+ rect,
124
+ box,
125
+ offset,
126
+ taken
127
+ });
128
+ if (!found) continue;
129
+ for (const part of found.claimed)taken.add(part);
130
+ out.push(found);
131
+ }
132
+ return out;
133
+ }
134
+ function readOneCard({ group, kids, texts, offset }, drawing) {
135
+ if (texts.length > MAX_CARD_TEXTS || kids.some((k)=>k.tag === "g")) return [];
136
+ for (const rect of kids){
137
+ const box = holdsText(rect, texts, offset);
138
+ if (!box) continue;
139
+ if (areaOf(box) > areaOf(drawing) * MAX_CARD_AREA) return [];
140
+ const found = cardFromRect({
141
+ group,
142
+ kids,
143
+ rect,
144
+ box,
145
+ offset,
146
+ taken: new Set()
147
+ });
148
+ return found ? [
149
+ found
150
+ ] : [];
151
+ }
152
+ return [];
153
+ }
154
+ function readCards(group, offset, drawing) {
155
+ const kids = group.children.filter(isEl);
156
+ const texts = kids.filter(hasText);
157
+ if (texts.length === 0) return [];
158
+ const read = {
159
+ group,
160
+ kids,
161
+ texts,
162
+ offset
163
+ };
164
+ return "data-pins" in group.attrs ? readPinCards(read) : readOneCard(read, drawing);
165
+ }
166
+ export function findCards(el, offset, drawing, out) {
167
+ for (const child of el.children){
168
+ if (!isEl(child) || child.tag !== "g") continue;
169
+ const shift = translateOf(child);
170
+ if (!shift) continue;
171
+ const at = plus(offset, shift);
172
+ const found = readCards(child, at, drawing);
173
+ if (found.length > 0) out.push(...found);
174
+ else findCards(child, at, drawing, out);
175
+ }
176
+ }
177
+ function flatten(container, offset, pins, out) {
178
+ const kids = container.children.filter(isEl);
179
+ for (const el of kids){
180
+ if (el.tag === "g") {
181
+ const shift = translateOf(el);
182
+ if (shift) flatten(el, plus(offset, shift), pins || "data-pins" in el.attrs, out);
183
+ continue;
184
+ }
185
+ if (el.tag === "defs" || el.tag === "title" || el.tag === "desc") continue;
186
+ out.push({
187
+ el,
188
+ box: boxOfEl(el, offset),
189
+ offset,
190
+ kids,
191
+ container,
192
+ pins
193
+ });
194
+ }
195
+ }
196
+ function numbersDot(a, center, r) {
197
+ const at = anchorOf(a.el, a.offset);
198
+ return textLines(a.el).join(" ").length <= BADGE_MAX_CHARS && Math.hypot(at.x - center.x, at.y - center.y) <= r + 2;
199
+ }
200
+ function findBadges(free, texts) {
201
+ const parts = new Set();
202
+ const badges = [];
203
+ for (const c of free.filter((a)=>a.el.tag === "circle")){
204
+ const r = num(c.el.attrs.r);
205
+ if (!c.box || r <= 0 || r > BADGE_MAX_R) continue;
206
+ const center = centerOf(c.box);
207
+ const t = texts.find((a)=>!parts.has(a.el) && numbersDot(a, center, r));
208
+ if (!t) continue;
209
+ parts.add(c.el);
210
+ parts.add(t.el);
211
+ badges.push({
212
+ circle: c.el,
213
+ text: t.el,
214
+ center,
215
+ r,
216
+ label: textLines(t.el).join(" ")
217
+ });
218
+ }
219
+ return {
220
+ badges,
221
+ parts
222
+ };
223
+ }
224
+ const isTip = (box)=>box !== null && box.x2 - box.x1 <= ARROWHEAD_MAX && box.y2 - box.y1 <= ARROWHEAD_MAX;
225
+ function isConnector(a, itemBoxes) {
226
+ if (![
227
+ "line",
228
+ "polyline",
229
+ "path"
230
+ ].includes(a.el.tag)) return false;
231
+ if (solid(a.el.attrs.fill)) return isTip(a.box);
232
+ const ends = strokeEnds(a.el, a.offset);
233
+ return ends !== null && ends.every((p)=>itemBoxes.some((b)=>contains(b, p, LAND_TOLERANCE)));
234
+ }
235
+ function leafRect(sweep, x, hasWords, out) {
236
+ if (!hasWords) {
237
+ out.shapes.push({
238
+ el: x.el,
239
+ box: x.box
240
+ });
241
+ return;
242
+ }
243
+ if (areaOf(x.box) > areaOf(sweep.drawing) * MAX_CARD_AREA) return;
244
+ const found = cardFromRect({
245
+ group: x.container,
246
+ kids: x.kids,
247
+ rect: x.el,
248
+ box: x.box,
249
+ offset: x.offset,
250
+ taken: sweep.taken
251
+ });
252
+ if (!found) return;
253
+ for (const part of found.claimed)sweep.taken.add(part);
254
+ out.cards.push(found);
255
+ }
256
+ function classifyRect(sweep, x, dropped, out) {
257
+ const { box } = x;
258
+ const inner = sweep.rects.filter((o)=>o !== x && !dropped.has(o) && within(o.box, box, 1) && areaOf(o.box) < areaOf(box));
259
+ const innerBoxes = [
260
+ ...inner.map((o)=>o.box),
261
+ ...sweep.groupCards.filter((c)=>within(c.box, box, 1)).map((c)=>c.box)
262
+ ];
263
+ const held = (point)=>innerBoxes.some((b)=>contains(b, point, 3)) ? false : contains(box, point, 3);
264
+ const own = sweep.words.filter((w)=>held(anchorOf(w.el, w.offset)));
265
+ if (innerBoxes.length === 0) {
266
+ leafRect(sweep, x, own.length > 0, out);
267
+ return;
268
+ }
269
+ const stray = sweep.strays.some(({ box: sb })=>sb !== null && within(sb, box, 1) && !innerBoxes.some((b)=>within(sb, b, 1)));
270
+ if (own.length > 0 || stray) {
271
+ out.panels.push(box);
272
+ for (const o of inner)dropped.add(o);
273
+ return;
274
+ }
275
+ if (innerBoxes.length >= 2) out.frames.push({
276
+ el: x.el,
277
+ box
278
+ });
279
+ else out.shapes.push({
280
+ el: x.el,
281
+ box
282
+ });
283
+ }
284
+ function sweepRects(sweep, out) {
285
+ const dropped = new Set();
286
+ for (const x of sweep.rects){
287
+ if (!dropped.has(x)) classifyRect(sweep, x, dropped, out);
288
+ }
289
+ }
290
+ export function findLoose(tree, drawing, taken, groupCards) {
291
+ const atoms = [];
292
+ flatten(tree, ORIGIN, false, atoms);
293
+ const free = atoms.filter((a)=>!a.pins && a.box && !taken.has(a.el));
294
+ const texts = free.filter((a)=>hasText(a.el));
295
+ const { badges, parts } = findBadges(free, texts);
296
+ const rects = free.filter((a)=>a.el.tag === "rect" && visible(a.el) && a.box !== null).filter((a)=>a.box.x2 - a.box.x1 >= MIN_SIDE && a.box.y2 - a.box.y1 >= MIN_SIDE).sort((a, b)=>areaOf(b.box) - areaOf(a.box));
297
+ const itemBoxes = [
298
+ ...rects.map((a)=>a.box),
299
+ ...groupCards.map((c)=>c.box)
300
+ ];
301
+ const strays = free.filter((a)=>![
302
+ "rect",
303
+ "text"
304
+ ].includes(a.el.tag) && !parts.has(a.el) && !isConnector(a, itemBoxes));
305
+ const out = {
306
+ cards: [],
307
+ shapes: [],
308
+ frames: [],
309
+ badges,
310
+ panels: []
311
+ };
312
+ const words = texts.filter((a)=>!parts.has(a.el));
313
+ sweepRects({
314
+ rects,
315
+ words,
316
+ strays,
317
+ groupCards,
318
+ drawing,
319
+ taken
320
+ }, out);
321
+ out.badges = out.badges.filter((b)=>!taken.has(b.circle) && !taken.has(b.text));
322
+ out.badges = out.badges.filter((b)=>!out.panels.some((p)=>contains(p, b.center, 0)));
323
+ return out;
324
+ }
@@ -0,0 +1,74 @@
1
+ import { boxOfEl, centerOf, isEl, plus, solid, strokeEnds, translateOf } from "./figure-geometry.js";
2
+ import { ARROWHEAD_MAX, findCards, findLoose } from "./break-apart-find.js";
3
+ const ORIGIN = {
4
+ x: 0,
5
+ y: 0
6
+ };
7
+ function isTipPath(el) {
8
+ return el.tag === "path" && /z\s*$/i.test(el.attrs.d ?? "") && solid(el.attrs.fill);
9
+ }
10
+ function headNear(siblings, from, ends, offset) {
11
+ const next = siblings.slice(from + 1).find(isEl);
12
+ if (!next || !isTipPath(next)) return null;
13
+ const box = boxOfEl(next, offset);
14
+ if (!box || box.x2 - box.x1 > ARROWHEAD_MAX || box.y2 - box.y1 > ARROWHEAD_MAX) return null;
15
+ const middle = centerOf(box);
16
+ const d0 = Math.hypot(middle.x - ends[0].x, middle.y - ends[0].y);
17
+ const d1 = Math.hypot(middle.x - ends[1].x, middle.y - ends[1].y);
18
+ if (Math.min(d0, d1) > ARROWHEAD_MAX) return null;
19
+ return {
20
+ el: next,
21
+ end: d1 <= d0 ? 1 : 0
22
+ };
23
+ }
24
+ function isStrokeOnly(el) {
25
+ if (el.tag !== "path" && el.tag !== "line" && el.tag !== "polyline") return false;
26
+ return solid(el.attrs.stroke) && !solid(el.attrs.fill);
27
+ }
28
+ function arrowOf(parent, child, index, offset) {
29
+ if (!isStrokeOnly(child)) return null;
30
+ const ends = strokeEnds(child, offset);
31
+ if (!ends) return null;
32
+ const head = headNear(parent.children, index, ends, offset);
33
+ const startArrow = Boolean(child.attrs["marker-start"]) || head?.end === 0;
34
+ const endArrow = Boolean(child.attrs["marker-end"]) || head?.end === 1;
35
+ return {
36
+ el: child,
37
+ head: head?.el,
38
+ from: ends[0],
39
+ to: ends[1],
40
+ startArrow,
41
+ endArrow
42
+ };
43
+ }
44
+ function collectArrows(el, offset, out) {
45
+ el.children.forEach((child, index)=>{
46
+ if (!isEl(child)) return;
47
+ if (child.tag !== "g") {
48
+ const arrow = arrowOf(el, child, index, offset);
49
+ if (arrow) out.push(arrow);
50
+ return;
51
+ }
52
+ const shift = translateOf(child);
53
+ if (shift) collectArrows(child, plus(offset, shift), out);
54
+ });
55
+ }
56
+ export function findPieces(tree, drawing) {
57
+ const groupCards = [];
58
+ findCards(tree, ORIGIN, drawing, groupCards);
59
+ const claimed = new Set();
60
+ for (const card of groupCards)for (const part of card.claimed)claimed.add(part);
61
+ const loose = findLoose(tree, drawing, claimed, groupCards);
62
+ const cards = [
63
+ ...groupCards,
64
+ ...loose.cards
65
+ ];
66
+ if (cards.length + loose.shapes.length + loose.frames.length === 0) return null;
67
+ const arrows = [];
68
+ collectArrows(tree, ORIGIN, arrows);
69
+ return {
70
+ cards,
71
+ loose,
72
+ arrows
73
+ };
74
+ }