@dudko.dev/agent-web-ui 0.0.0 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (283) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +316 -5
  3. package/dist/canvas.cjs +266 -0
  4. package/dist/canvas.cjs.map +1 -0
  5. package/dist/canvas.d.cts +105 -0
  6. package/dist/canvas.d.ts +105 -0
  7. package/dist/canvas.js +200 -0
  8. package/dist/canvas.js.map +1 -0
  9. package/dist/chunk-7O64ZI6Z.js +125 -0
  10. package/dist/chunk-7O64ZI6Z.js.map +1 -0
  11. package/dist/chunk-EL2YCROY.js +127 -0
  12. package/dist/chunk-EL2YCROY.js.map +1 -0
  13. package/dist/chunk-GB7RZJMG.js +98 -0
  14. package/dist/chunk-GB7RZJMG.js.map +1 -0
  15. package/dist/chunk-KZQB35LS.js +22 -0
  16. package/dist/chunk-KZQB35LS.js.map +1 -0
  17. package/dist/chunk-SVYHDLAZ.js +348 -0
  18. package/dist/chunk-SVYHDLAZ.js.map +1 -0
  19. package/dist/chunk-VCR7LU7J.js +348 -0
  20. package/dist/chunk-VCR7LU7J.js.map +1 -0
  21. package/dist/chunk-WFM6B7CL.js +406 -0
  22. package/dist/chunk-WFM6B7CL.js.map +1 -0
  23. package/dist/chunk-WZ7K7JIP.js +348 -0
  24. package/dist/chunk-WZ7K7JIP.js.map +1 -0
  25. package/dist/chunk-ZBHESK6V.js +1440 -0
  26. package/dist/chunk-ZBHESK6V.js.map +1 -0
  27. package/dist/controller.cjs +1891 -0
  28. package/dist/controller.cjs.map +1 -0
  29. package/dist/controller.d.cts +253 -0
  30. package/dist/controller.d.ts +253 -0
  31. package/dist/controller.js +482 -0
  32. package/dist/controller.js.map +1 -0
  33. package/dist/en-Dg2MtzcJ.d.cts +348 -0
  34. package/dist/en-Dg2MtzcJ.d.ts +348 -0
  35. package/dist/index.cjs +4276 -0
  36. package/dist/index.cjs.map +1 -0
  37. package/dist/index.d.cts +997 -0
  38. package/dist/index.d.ts +997 -0
  39. package/dist/index.js +2494 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/labels-B5xpIGf_.d.cts +25 -0
  42. package/dist/labels-B5xpIGf_.d.ts +25 -0
  43. package/dist/labels-CmiTBLWD.d.cts +1176 -0
  44. package/dist/labels-DH1ESUtm.d.ts +1176 -0
  45. package/dist/locales/be.cjs +806 -0
  46. package/dist/locales/be.cjs.map +1 -0
  47. package/dist/locales/be.d.cts +16 -0
  48. package/dist/locales/be.d.ts +16 -0
  49. package/dist/locales/be.js +380 -0
  50. package/dist/locales/be.js.map +1 -0
  51. package/dist/locales/bg.cjs +759 -0
  52. package/dist/locales/bg.cjs.map +1 -0
  53. package/dist/locales/bg.d.cts +16 -0
  54. package/dist/locales/bg.d.ts +16 -0
  55. package/dist/locales/bg.js +333 -0
  56. package/dist/locales/bg.js.map +1 -0
  57. package/dist/locales/ca.cjs +785 -0
  58. package/dist/locales/ca.cjs.map +1 -0
  59. package/dist/locales/ca.d.cts +16 -0
  60. package/dist/locales/ca.d.ts +16 -0
  61. package/dist/locales/ca.js +359 -0
  62. package/dist/locales/ca.js.map +1 -0
  63. package/dist/locales/cs.cjs +806 -0
  64. package/dist/locales/cs.cjs.map +1 -0
  65. package/dist/locales/cs.d.cts +16 -0
  66. package/dist/locales/cs.d.ts +16 -0
  67. package/dist/locales/cs.js +380 -0
  68. package/dist/locales/cs.js.map +1 -0
  69. package/dist/locales/da.cjs +759 -0
  70. package/dist/locales/da.cjs.map +1 -0
  71. package/dist/locales/da.d.cts +16 -0
  72. package/dist/locales/da.d.ts +16 -0
  73. package/dist/locales/da.js +333 -0
  74. package/dist/locales/da.js.map +1 -0
  75. package/dist/locales/de.cjs +768 -0
  76. package/dist/locales/de.cjs.map +1 -0
  77. package/dist/locales/de.d.cts +16 -0
  78. package/dist/locales/de.d.ts +16 -0
  79. package/dist/locales/de.js +342 -0
  80. package/dist/locales/de.js.map +1 -0
  81. package/dist/locales/el.cjs +768 -0
  82. package/dist/locales/el.cjs.map +1 -0
  83. package/dist/locales/el.d.cts +16 -0
  84. package/dist/locales/el.d.ts +16 -0
  85. package/dist/locales/el.js +342 -0
  86. package/dist/locales/el.js.map +1 -0
  87. package/dist/locales/en.cjs +765 -0
  88. package/dist/locales/en.cjs.map +1 -0
  89. package/dist/locales/en.d.cts +12 -0
  90. package/dist/locales/en.d.ts +12 -0
  91. package/dist/locales/en.js +339 -0
  92. package/dist/locales/en.js.map +1 -0
  93. package/dist/locales/es-419.cjs +793 -0
  94. package/dist/locales/es-419.cjs.map +1 -0
  95. package/dist/locales/es-419.d.cts +18 -0
  96. package/dist/locales/es-419.d.ts +18 -0
  97. package/dist/locales/es-419.js +26 -0
  98. package/dist/locales/es-419.js.map +1 -0
  99. package/dist/locales/es.cjs +781 -0
  100. package/dist/locales/es.cjs.map +1 -0
  101. package/dist/locales/es.d.cts +16 -0
  102. package/dist/locales/es.d.ts +16 -0
  103. package/dist/locales/es.js +14 -0
  104. package/dist/locales/es.js.map +1 -0
  105. package/dist/locales/fi.cjs +765 -0
  106. package/dist/locales/fi.cjs.map +1 -0
  107. package/dist/locales/fi.d.cts +16 -0
  108. package/dist/locales/fi.d.ts +16 -0
  109. package/dist/locales/fi.js +339 -0
  110. package/dist/locales/fi.js.map +1 -0
  111. package/dist/locales/fr-CA.cjs +789 -0
  112. package/dist/locales/fr-CA.cjs.map +1 -0
  113. package/dist/locales/fr-CA.d.cts +19 -0
  114. package/dist/locales/fr-CA.d.ts +19 -0
  115. package/dist/locales/fr-CA.js +22 -0
  116. package/dist/locales/fr-CA.js.map +1 -0
  117. package/dist/locales/fr.cjs +781 -0
  118. package/dist/locales/fr.cjs.map +1 -0
  119. package/dist/locales/fr.d.cts +16 -0
  120. package/dist/locales/fr.d.ts +16 -0
  121. package/dist/locales/fr.js +14 -0
  122. package/dist/locales/fr.js.map +1 -0
  123. package/dist/locales/gn.cjs +762 -0
  124. package/dist/locales/gn.cjs.map +1 -0
  125. package/dist/locales/gn.d.cts +18 -0
  126. package/dist/locales/gn.d.ts +18 -0
  127. package/dist/locales/gn.js +336 -0
  128. package/dist/locales/gn.js.map +1 -0
  129. package/dist/locales/hr.cjs +781 -0
  130. package/dist/locales/hr.cjs.map +1 -0
  131. package/dist/locales/hr.d.cts +16 -0
  132. package/dist/locales/hr.d.ts +16 -0
  133. package/dist/locales/hr.js +355 -0
  134. package/dist/locales/hr.js.map +1 -0
  135. package/dist/locales/ht.cjs +762 -0
  136. package/dist/locales/ht.cjs.map +1 -0
  137. package/dist/locales/ht.d.cts +18 -0
  138. package/dist/locales/ht.d.ts +18 -0
  139. package/dist/locales/ht.js +336 -0
  140. package/dist/locales/ht.js.map +1 -0
  141. package/dist/locales/hu.cjs +765 -0
  142. package/dist/locales/hu.cjs.map +1 -0
  143. package/dist/locales/hu.d.cts +16 -0
  144. package/dist/locales/hu.d.ts +16 -0
  145. package/dist/locales/hu.js +339 -0
  146. package/dist/locales/hu.js.map +1 -0
  147. package/dist/locales/index.cjs +543 -0
  148. package/dist/locales/index.cjs.map +1 -0
  149. package/dist/locales/index.d.cts +40 -0
  150. package/dist/locales/index.d.ts +40 -0
  151. package/dist/locales/index.js +105 -0
  152. package/dist/locales/index.js.map +1 -0
  153. package/dist/locales/it.cjs +789 -0
  154. package/dist/locales/it.cjs.map +1 -0
  155. package/dist/locales/it.d.cts +16 -0
  156. package/dist/locales/it.d.ts +16 -0
  157. package/dist/locales/it.js +363 -0
  158. package/dist/locales/it.js.map +1 -0
  159. package/dist/locales/nb.cjs +759 -0
  160. package/dist/locales/nb.cjs.map +1 -0
  161. package/dist/locales/nb.d.cts +16 -0
  162. package/dist/locales/nb.d.ts +16 -0
  163. package/dist/locales/nb.js +333 -0
  164. package/dist/locales/nb.js.map +1 -0
  165. package/dist/locales/nl.cjs +765 -0
  166. package/dist/locales/nl.cjs.map +1 -0
  167. package/dist/locales/nl.d.cts +16 -0
  168. package/dist/locales/nl.d.ts +16 -0
  169. package/dist/locales/nl.js +339 -0
  170. package/dist/locales/nl.js.map +1 -0
  171. package/dist/locales/pl.cjs +806 -0
  172. package/dist/locales/pl.cjs.map +1 -0
  173. package/dist/locales/pl.d.cts +16 -0
  174. package/dist/locales/pl.d.ts +16 -0
  175. package/dist/locales/pl.js +380 -0
  176. package/dist/locales/pl.js.map +1 -0
  177. package/dist/locales/pt-BR.cjs +785 -0
  178. package/dist/locales/pt-BR.cjs.map +1 -0
  179. package/dist/locales/pt-BR.d.cts +16 -0
  180. package/dist/locales/pt-BR.d.ts +16 -0
  181. package/dist/locales/pt-BR.js +359 -0
  182. package/dist/locales/pt-BR.js.map +1 -0
  183. package/dist/locales/pt.cjs +789 -0
  184. package/dist/locales/pt.cjs.map +1 -0
  185. package/dist/locales/pt.d.cts +16 -0
  186. package/dist/locales/pt.d.ts +16 -0
  187. package/dist/locales/pt.js +363 -0
  188. package/dist/locales/pt.js.map +1 -0
  189. package/dist/locales/qu.cjs +768 -0
  190. package/dist/locales/qu.cjs.map +1 -0
  191. package/dist/locales/qu.d.cts +18 -0
  192. package/dist/locales/qu.d.ts +18 -0
  193. package/dist/locales/qu.js +342 -0
  194. package/dist/locales/qu.js.map +1 -0
  195. package/dist/locales/ro.cjs +781 -0
  196. package/dist/locales/ro.cjs.map +1 -0
  197. package/dist/locales/ro.d.cts +16 -0
  198. package/dist/locales/ro.d.ts +16 -0
  199. package/dist/locales/ro.js +355 -0
  200. package/dist/locales/ro.js.map +1 -0
  201. package/dist/locales/ru.cjs +801 -0
  202. package/dist/locales/ru.cjs.map +1 -0
  203. package/dist/locales/ru.d.cts +16 -0
  204. package/dist/locales/ru.d.ts +16 -0
  205. package/dist/locales/ru.js +375 -0
  206. package/dist/locales/ru.js.map +1 -0
  207. package/dist/locales/sk.cjs +806 -0
  208. package/dist/locales/sk.cjs.map +1 -0
  209. package/dist/locales/sk.d.cts +16 -0
  210. package/dist/locales/sk.d.ts +16 -0
  211. package/dist/locales/sk.js +380 -0
  212. package/dist/locales/sk.js.map +1 -0
  213. package/dist/locales/sq.cjs +765 -0
  214. package/dist/locales/sq.cjs.map +1 -0
  215. package/dist/locales/sq.d.cts +16 -0
  216. package/dist/locales/sq.d.ts +16 -0
  217. package/dist/locales/sq.js +339 -0
  218. package/dist/locales/sq.js.map +1 -0
  219. package/dist/locales/sr-Latn.cjs +853 -0
  220. package/dist/locales/sr-Latn.cjs.map +1 -0
  221. package/dist/locales/sr-Latn.d.cts +19 -0
  222. package/dist/locales/sr-Latn.d.ts +19 -0
  223. package/dist/locales/sr-Latn.js +86 -0
  224. package/dist/locales/sr-Latn.js.map +1 -0
  225. package/dist/locales/sr.cjs +781 -0
  226. package/dist/locales/sr.cjs.map +1 -0
  227. package/dist/locales/sr.d.cts +16 -0
  228. package/dist/locales/sr.d.ts +16 -0
  229. package/dist/locales/sr.js +14 -0
  230. package/dist/locales/sr.js.map +1 -0
  231. package/dist/locales/sv.cjs +765 -0
  232. package/dist/locales/sv.cjs.map +1 -0
  233. package/dist/locales/sv.d.cts +16 -0
  234. package/dist/locales/sv.d.ts +16 -0
  235. package/dist/locales/sv.js +339 -0
  236. package/dist/locales/sv.js.map +1 -0
  237. package/dist/locales/tr.cjs +762 -0
  238. package/dist/locales/tr.cjs.map +1 -0
  239. package/dist/locales/tr.d.cts +16 -0
  240. package/dist/locales/tr.d.ts +16 -0
  241. package/dist/locales/tr.js +336 -0
  242. package/dist/locales/tr.js.map +1 -0
  243. package/dist/locales/uk.cjs +806 -0
  244. package/dist/locales/uk.cjs.map +1 -0
  245. package/dist/locales/uk.d.cts +16 -0
  246. package/dist/locales/uk.d.ts +16 -0
  247. package/dist/locales/uk.js +380 -0
  248. package/dist/locales/uk.js.map +1 -0
  249. package/dist/markdown.cjs +620 -0
  250. package/dist/markdown.cjs.map +1 -0
  251. package/dist/markdown.d.cts +153 -0
  252. package/dist/markdown.d.ts +153 -0
  253. package/dist/markdown.js +573 -0
  254. package/dist/markdown.js.map +1 -0
  255. package/dist/mcp-app-policy-DXKQ2jjM.d.cts +73 -0
  256. package/dist/mcp-app-policy-DXKQ2jjM.d.ts +73 -0
  257. package/dist/mcp-app-sandbox.cjs +323 -0
  258. package/dist/mcp-app-sandbox.cjs.map +1 -0
  259. package/dist/mcp-app-sandbox.d.cts +70 -0
  260. package/dist/mcp-app-sandbox.d.ts +70 -0
  261. package/dist/mcp-app-sandbox.js +209 -0
  262. package/dist/mcp-app-sandbox.js.map +1 -0
  263. package/dist/mcp-app.cjs +980 -0
  264. package/dist/mcp-app.cjs.map +1 -0
  265. package/dist/mcp-app.d.cts +491 -0
  266. package/dist/mcp-app.d.ts +491 -0
  267. package/dist/mcp-app.js +816 -0
  268. package/dist/mcp-app.js.map +1 -0
  269. package/dist/pipeline.cjs +845 -0
  270. package/dist/pipeline.cjs.map +1 -0
  271. package/dist/pipeline.css +1407 -0
  272. package/dist/pipeline.d.cts +348 -0
  273. package/dist/pipeline.d.ts +348 -0
  274. package/dist/pipeline.js +778 -0
  275. package/dist/pipeline.js.map +1 -0
  276. package/dist/questions-Dw--IEjT.d.cts +100 -0
  277. package/dist/questions-Dw--IEjT.d.ts +100 -0
  278. package/dist/styles.css +4109 -0
  279. package/dist/types-CQquuZpl.d.cts +19 -0
  280. package/dist/types-CXZfZVP5.d.ts +19 -0
  281. package/dist/types-DnBCok3z.d.cts +994 -0
  282. package/dist/types-DnBCok3z.d.ts +994 -0
  283. package/package.json +165 -8
@@ -0,0 +1,105 @@
1
+ export { C as CanvasLabels, d as defaultCanvasLabels } from './labels-B5xpIGf_.cjs';
2
+
3
+ interface Point {
4
+ x: number;
5
+ y: number;
6
+ }
7
+ interface Size {
8
+ width: number;
9
+ height: number;
10
+ }
11
+ interface Rect extends Point, Size {
12
+ }
13
+ /**
14
+ * Where the world sits on the screen: a world point `p` is drawn at
15
+ * `p * zoom + (x, y)`, in pixels from the canvas's top-left corner.
16
+ */
17
+ interface Viewport {
18
+ x: number;
19
+ y: number;
20
+ zoom: number;
21
+ }
22
+ /** The four control points of a cubic Bezier curve. */
23
+ interface Curve {
24
+ p0: Point;
25
+ p1: Point;
26
+ p2: Point;
27
+ p3: Point;
28
+ }
29
+ declare const DEFAULT_MIN_ZOOM = 0.25;
30
+ declare const DEFAULT_MAX_ZOOM = 2;
31
+ declare const IDENTITY_VIEWPORT: Viewport;
32
+ declare const clamp: (value: number, min: number, max: number) => number;
33
+ declare const screenToWorld: (point: Point, viewport: Viewport) => Point;
34
+ declare const worldToScreen: (point: Point, viewport: Viewport) => Point;
35
+ declare const panBy: (viewport: Viewport, dx: number, dy: number) => Viewport;
36
+ /** Set the zoom, keeping the world point under `anchor` (a screen point) where it is. */
37
+ declare const zoomAt: (viewport: Viewport, zoom: number, anchor: Point, minZoom?: number, maxZoom?: number) => Viewport;
38
+ /**
39
+ * Two fingers moved from `before` to `after` (screen points): zoom by how far apart they went,
40
+ * and keep the world point that was between them under the point that is between them now.
41
+ */
42
+ declare const pinchViewport: (viewport: Viewport, before: [Point, Point], after: [Point, Point], minZoom?: number, maxZoom?: number) => Viewport;
43
+ /** The smallest rectangle around all of `rects`; undefined when there are none. */
44
+ declare const boundsOf: (rects: Rect[]) => Rect | undefined;
45
+ interface FitOptions {
46
+ /** Free space kept around the content, in screen pixels (default 48). */
47
+ padding?: number;
48
+ minZoom?: number;
49
+ /** Fitting never zooms in past this (default 1: a small graph is not blown up). */
50
+ maxZoom?: number;
51
+ }
52
+ /**
53
+ * The viewport that shows all of `rects` centred in a canvas of `size`. When they do not fit at
54
+ * `minZoom`, it shows them from their top-left corner at that zoom instead.
55
+ */
56
+ declare const fitViewport: (rects: Rect[], size: Size, options?: FitOptions) => Viewport;
57
+ /** The viewport with `rect` in the middle of a canvas of `size`, at the zoom given. */
58
+ declare const centerOn: (rect: Rect, size: Size, zoom: number) => Viewport;
59
+ /** Is any part of `rect` (world) inside a canvas of `size` under `viewport`? */
60
+ declare const isRectVisible: (rect: Rect, size: Size, viewport: Viewport) => boolean;
61
+ declare const snapTo: (value: number, grid: number) => number;
62
+ declare const snapPoint: (point: Point, grid: number) => Point;
63
+ declare const rectContains: (rect: Rect, point: Point) => boolean;
64
+ /** The id of the node under `point` (world). Later nodes are drawn on top, so they win. */
65
+ declare const hitNode: <T extends Rect & {
66
+ id: string;
67
+ }>(nodes: T[], point: Point) => string | undefined;
68
+ /** Where an edge enters a node: the middle of its left side. */
69
+ declare const inputAnchor: (rect: Rect) => Point;
70
+ /** Where an edge leaves a node that has `count` output ports: spread down its right side. */
71
+ declare const outputAnchor: (rect: Rect, index?: number, count?: number) => Point;
72
+ interface EdgeCurveOptions {
73
+ /**
74
+ * How far an edge that runs backwards (its target is to the left of its source) swings below
75
+ * the two nodes so that it does not cross them (default 90).
76
+ */
77
+ clearance?: number;
78
+ }
79
+ /**
80
+ * The curve of an edge that leaves `from` to the right and enters `to` from the left. A forward
81
+ * edge is a plain S; a backward one (a loop) swings out and around.
82
+ */
83
+ declare const edgeCurve: (from: Point, to: Point, options?: EdgeCurveOptions) => Curve;
84
+ /** The SVG path data of a curve. */
85
+ declare const curvePath: ({ p0, p1, p2, p3 }: Curve) => string;
86
+ /** The point of a curve at `t` in 0..1. */
87
+ declare const curvePoint: ({ p0, p1, p2, p3 }: Curve, t: number) => Point;
88
+ /** How far `point` is from a curve (the curve is walked in `samples` straight pieces). */
89
+ declare const distanceToCurve: (curve: Curve, point: Point, samples?: number) => number;
90
+ /** The id of the edge within `tolerance` of `point`, the nearest one when several are. */
91
+ declare const hitEdge: (edges: {
92
+ id: string;
93
+ curve: Curve;
94
+ }[], point: Point, tolerance?: number) => string | undefined;
95
+ /**
96
+ * The order a keyboard walks the nodes in: left to right, then top to bottom - the direction a
97
+ * graph that flows from its entry to its end is read in. Nodes in the same column (within
98
+ * `column` pixels) count as level.
99
+ */
100
+ declare const readingOrder: <T extends Point & {
101
+ id: string;
102
+ }>(nodes: T[], column?: number) => string[];
103
+
104
+ export { DEFAULT_MAX_ZOOM, DEFAULT_MIN_ZOOM, IDENTITY_VIEWPORT, boundsOf, centerOn, clamp, curvePath, curvePoint, distanceToCurve, edgeCurve, fitViewport, hitEdge, hitNode, inputAnchor, isRectVisible, outputAnchor, panBy, pinchViewport, readingOrder, rectContains, screenToWorld, snapPoint, snapTo, worldToScreen, zoomAt };
105
+ export type { Curve, EdgeCurveOptions, FitOptions, Point, Rect, Size, Viewport };
@@ -0,0 +1,105 @@
1
+ export { C as CanvasLabels, d as defaultCanvasLabels } from './labels-B5xpIGf_.js';
2
+
3
+ interface Point {
4
+ x: number;
5
+ y: number;
6
+ }
7
+ interface Size {
8
+ width: number;
9
+ height: number;
10
+ }
11
+ interface Rect extends Point, Size {
12
+ }
13
+ /**
14
+ * Where the world sits on the screen: a world point `p` is drawn at
15
+ * `p * zoom + (x, y)`, in pixels from the canvas's top-left corner.
16
+ */
17
+ interface Viewport {
18
+ x: number;
19
+ y: number;
20
+ zoom: number;
21
+ }
22
+ /** The four control points of a cubic Bezier curve. */
23
+ interface Curve {
24
+ p0: Point;
25
+ p1: Point;
26
+ p2: Point;
27
+ p3: Point;
28
+ }
29
+ declare const DEFAULT_MIN_ZOOM = 0.25;
30
+ declare const DEFAULT_MAX_ZOOM = 2;
31
+ declare const IDENTITY_VIEWPORT: Viewport;
32
+ declare const clamp: (value: number, min: number, max: number) => number;
33
+ declare const screenToWorld: (point: Point, viewport: Viewport) => Point;
34
+ declare const worldToScreen: (point: Point, viewport: Viewport) => Point;
35
+ declare const panBy: (viewport: Viewport, dx: number, dy: number) => Viewport;
36
+ /** Set the zoom, keeping the world point under `anchor` (a screen point) where it is. */
37
+ declare const zoomAt: (viewport: Viewport, zoom: number, anchor: Point, minZoom?: number, maxZoom?: number) => Viewport;
38
+ /**
39
+ * Two fingers moved from `before` to `after` (screen points): zoom by how far apart they went,
40
+ * and keep the world point that was between them under the point that is between them now.
41
+ */
42
+ declare const pinchViewport: (viewport: Viewport, before: [Point, Point], after: [Point, Point], minZoom?: number, maxZoom?: number) => Viewport;
43
+ /** The smallest rectangle around all of `rects`; undefined when there are none. */
44
+ declare const boundsOf: (rects: Rect[]) => Rect | undefined;
45
+ interface FitOptions {
46
+ /** Free space kept around the content, in screen pixels (default 48). */
47
+ padding?: number;
48
+ minZoom?: number;
49
+ /** Fitting never zooms in past this (default 1: a small graph is not blown up). */
50
+ maxZoom?: number;
51
+ }
52
+ /**
53
+ * The viewport that shows all of `rects` centred in a canvas of `size`. When they do not fit at
54
+ * `minZoom`, it shows them from their top-left corner at that zoom instead.
55
+ */
56
+ declare const fitViewport: (rects: Rect[], size: Size, options?: FitOptions) => Viewport;
57
+ /** The viewport with `rect` in the middle of a canvas of `size`, at the zoom given. */
58
+ declare const centerOn: (rect: Rect, size: Size, zoom: number) => Viewport;
59
+ /** Is any part of `rect` (world) inside a canvas of `size` under `viewport`? */
60
+ declare const isRectVisible: (rect: Rect, size: Size, viewport: Viewport) => boolean;
61
+ declare const snapTo: (value: number, grid: number) => number;
62
+ declare const snapPoint: (point: Point, grid: number) => Point;
63
+ declare const rectContains: (rect: Rect, point: Point) => boolean;
64
+ /** The id of the node under `point` (world). Later nodes are drawn on top, so they win. */
65
+ declare const hitNode: <T extends Rect & {
66
+ id: string;
67
+ }>(nodes: T[], point: Point) => string | undefined;
68
+ /** Where an edge enters a node: the middle of its left side. */
69
+ declare const inputAnchor: (rect: Rect) => Point;
70
+ /** Where an edge leaves a node that has `count` output ports: spread down its right side. */
71
+ declare const outputAnchor: (rect: Rect, index?: number, count?: number) => Point;
72
+ interface EdgeCurveOptions {
73
+ /**
74
+ * How far an edge that runs backwards (its target is to the left of its source) swings below
75
+ * the two nodes so that it does not cross them (default 90).
76
+ */
77
+ clearance?: number;
78
+ }
79
+ /**
80
+ * The curve of an edge that leaves `from` to the right and enters `to` from the left. A forward
81
+ * edge is a plain S; a backward one (a loop) swings out and around.
82
+ */
83
+ declare const edgeCurve: (from: Point, to: Point, options?: EdgeCurveOptions) => Curve;
84
+ /** The SVG path data of a curve. */
85
+ declare const curvePath: ({ p0, p1, p2, p3 }: Curve) => string;
86
+ /** The point of a curve at `t` in 0..1. */
87
+ declare const curvePoint: ({ p0, p1, p2, p3 }: Curve, t: number) => Point;
88
+ /** How far `point` is from a curve (the curve is walked in `samples` straight pieces). */
89
+ declare const distanceToCurve: (curve: Curve, point: Point, samples?: number) => number;
90
+ /** The id of the edge within `tolerance` of `point`, the nearest one when several are. */
91
+ declare const hitEdge: (edges: {
92
+ id: string;
93
+ curve: Curve;
94
+ }[], point: Point, tolerance?: number) => string | undefined;
95
+ /**
96
+ * The order a keyboard walks the nodes in: left to right, then top to bottom - the direction a
97
+ * graph that flows from its entry to its end is read in. Nodes in the same column (within
98
+ * `column` pixels) count as level.
99
+ */
100
+ declare const readingOrder: <T extends Point & {
101
+ id: string;
102
+ }>(nodes: T[], column?: number) => string[];
103
+
104
+ export { DEFAULT_MAX_ZOOM, DEFAULT_MIN_ZOOM, IDENTITY_VIEWPORT, boundsOf, centerOn, clamp, curvePath, curvePoint, distanceToCurve, edgeCurve, fitViewport, hitEdge, hitNode, inputAnchor, isRectVisible, outputAnchor, panBy, pinchViewport, readingOrder, rectContains, screenToWorld, snapPoint, snapTo, worldToScreen, zoomAt };
105
+ export type { Curve, EdgeCurveOptions, FitOptions, Point, Rect, Size, Viewport };
package/dist/canvas.js ADDED
@@ -0,0 +1,200 @@
1
+ import {
2
+ defaultCanvasLabels
3
+ } from "./chunk-KZQB35LS.js";
4
+
5
+ // src/canvas/geometry.ts
6
+ var DEFAULT_MIN_ZOOM = 0.25;
7
+ var DEFAULT_MAX_ZOOM = 2;
8
+ var IDENTITY_VIEWPORT = { x: 0, y: 0, zoom: 1 };
9
+ var clamp = (value, min, max) => Math.min(max, Math.max(min, value));
10
+ var screenToWorld = (point, viewport) => ({
11
+ x: (point.x - viewport.x) / viewport.zoom,
12
+ y: (point.y - viewport.y) / viewport.zoom
13
+ });
14
+ var worldToScreen = (point, viewport) => ({
15
+ x: point.x * viewport.zoom + viewport.x,
16
+ y: point.y * viewport.zoom + viewport.y
17
+ });
18
+ var panBy = (viewport, dx, dy) => ({
19
+ ...viewport,
20
+ x: viewport.x + dx,
21
+ y: viewport.y + dy
22
+ });
23
+ var zoomAt = (viewport, zoom, anchor, minZoom = DEFAULT_MIN_ZOOM, maxZoom = DEFAULT_MAX_ZOOM) => {
24
+ const next = clamp(zoom, minZoom, maxZoom);
25
+ if (next === viewport.zoom) return viewport;
26
+ const world = screenToWorld(anchor, viewport);
27
+ return { zoom: next, x: anchor.x - world.x * next, y: anchor.y - world.y * next };
28
+ };
29
+ var pinchViewport = (viewport, before, after, minZoom = DEFAULT_MIN_ZOOM, maxZoom = DEFAULT_MAX_ZOOM) => {
30
+ const distance = (a, b) => Math.hypot(a.x - b.x, a.y - b.y);
31
+ const middle = (a, b) => ({ x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 });
32
+ const was = distance(before[0], before[1]);
33
+ const is = distance(after[0], after[1]);
34
+ const zoom = clamp(was > 0 ? viewport.zoom * is / was : viewport.zoom, minZoom, maxZoom);
35
+ const world = screenToWorld(middle(before[0], before[1]), viewport);
36
+ const at = middle(after[0], after[1]);
37
+ return { zoom, x: at.x - world.x * zoom, y: at.y - world.y * zoom };
38
+ };
39
+ var boundsOf = (rects) => {
40
+ if (rects.length === 0) return void 0;
41
+ let left = Infinity;
42
+ let top = Infinity;
43
+ let right = -Infinity;
44
+ let bottom = -Infinity;
45
+ for (const r of rects) {
46
+ left = Math.min(left, r.x);
47
+ top = Math.min(top, r.y);
48
+ right = Math.max(right, r.x + r.width);
49
+ bottom = Math.max(bottom, r.y + r.height);
50
+ }
51
+ return { x: left, y: top, width: right - left, height: bottom - top };
52
+ };
53
+ var fitAxis = (start, length, room, zoom, padding) => length * zoom <= room - padding * 2 + 0.5 ? (room - length * zoom) / 2 - start * zoom : padding - start * zoom;
54
+ var fitViewport = (rects, size, options = {}) => {
55
+ const bounds = boundsOf(rects);
56
+ if (!bounds || size.width <= 0 || size.height <= 0) return IDENTITY_VIEWPORT;
57
+ const { minZoom = DEFAULT_MIN_ZOOM, maxZoom = 1 } = options;
58
+ const padding = Math.min(options.padding ?? 48, size.width / 8, size.height / 8);
59
+ const zoom = clamp(
60
+ Math.min(
61
+ (size.width - padding * 2) / Math.max(bounds.width, 1),
62
+ (size.height - padding * 2) / Math.max(bounds.height, 1)
63
+ ),
64
+ minZoom,
65
+ maxZoom
66
+ );
67
+ return {
68
+ zoom,
69
+ x: fitAxis(bounds.x, bounds.width, size.width, zoom, padding),
70
+ y: fitAxis(bounds.y, bounds.height, size.height, zoom, padding)
71
+ };
72
+ };
73
+ var centerOn = (rect, size, zoom) => ({
74
+ zoom,
75
+ x: size.width / 2 - (rect.x + rect.width / 2) * zoom,
76
+ y: size.height / 2 - (rect.y + rect.height / 2) * zoom
77
+ });
78
+ var isRectVisible = (rect, size, viewport) => {
79
+ const a = worldToScreen(rect, viewport);
80
+ const b = worldToScreen({ x: rect.x + rect.width, y: rect.y + rect.height }, viewport);
81
+ return b.x > 0 && b.y > 0 && a.x < size.width && a.y < size.height;
82
+ };
83
+ var snapTo = (value, grid) => (
84
+ // `+ 0`: a rounded-away negative is 0, not -0.
85
+ grid > 0 ? Math.round(value / grid) * grid + 0 : value
86
+ );
87
+ var snapPoint = (point, grid) => ({
88
+ x: snapTo(point.x, grid),
89
+ y: snapTo(point.y, grid)
90
+ });
91
+ var rectContains = (rect, point) => point.x >= rect.x && point.x <= rect.x + rect.width && point.y >= rect.y && point.y <= rect.y + rect.height;
92
+ var hitNode = (nodes, point) => {
93
+ for (let i = nodes.length - 1; i >= 0; i--) {
94
+ if (rectContains(nodes[i], point)) return nodes[i].id;
95
+ }
96
+ return void 0;
97
+ };
98
+ var inputAnchor = (rect) => ({ x: rect.x, y: rect.y + rect.height / 2 });
99
+ var outputAnchor = (rect, index = 0, count = 1) => ({
100
+ x: rect.x + rect.width,
101
+ y: rect.y + rect.height * (index + 1) / (Math.max(count, 1) + 1)
102
+ });
103
+ var edgeCurve = (from, to, options = {}) => {
104
+ const dx = to.x - from.x;
105
+ const dy = to.y - from.y;
106
+ if (dx >= 40) {
107
+ const reach2 = Math.max(dx / 2, 40);
108
+ return {
109
+ p0: from,
110
+ p1: { x: from.x + reach2, y: from.y },
111
+ p2: { x: to.x - reach2, y: to.y },
112
+ p3: to
113
+ };
114
+ }
115
+ const reach = clamp(60 + Math.abs(dx) / 4, 60, 220);
116
+ const clearance = options.clearance ?? 90;
117
+ const swing = Math.abs(dy) < clearance ? clearance + Math.abs(dy) / 2 : 0;
118
+ return {
119
+ p0: from,
120
+ p1: { x: from.x + reach, y: from.y + swing },
121
+ p2: { x: to.x - reach, y: to.y + swing },
122
+ p3: to
123
+ };
124
+ };
125
+ var round = (n) => Math.round(n * 100) / 100;
126
+ var curvePath = ({ p0, p1, p2, p3 }) => `M ${round(p0.x)} ${round(p0.y)} C ${round(p1.x)} ${round(p1.y)}, ${round(p2.x)} ${round(p2.y)}, ${round(p3.x)} ${round(p3.y)}`;
127
+ var curvePoint = ({ p0, p1, p2, p3 }, t) => {
128
+ const u = 1 - t;
129
+ const a = u * u * u;
130
+ const b = 3 * u * u * t;
131
+ const c = 3 * u * t * t;
132
+ const d = t * t * t;
133
+ return {
134
+ x: a * p0.x + b * p1.x + c * p2.x + d * p3.x,
135
+ y: a * p0.y + b * p1.y + c * p2.y + d * p3.y
136
+ };
137
+ };
138
+ var distanceToSegment = (p, a, b) => {
139
+ const dx = b.x - a.x;
140
+ const dy = b.y - a.y;
141
+ const length = dx * dx + dy * dy;
142
+ const t = length === 0 ? 0 : clamp(((p.x - a.x) * dx + (p.y - a.y) * dy) / length, 0, 1);
143
+ return Math.hypot(p.x - (a.x + t * dx), p.y - (a.y + t * dy));
144
+ };
145
+ var distanceToCurve = (curve, point, samples = 24) => {
146
+ let best = Infinity;
147
+ let previous = curve.p0;
148
+ for (let i = 1; i <= samples; i++) {
149
+ const next = curvePoint(curve, i / samples);
150
+ best = Math.min(best, distanceToSegment(point, previous, next));
151
+ previous = next;
152
+ }
153
+ return best;
154
+ };
155
+ var hitEdge = (edges, point, tolerance = 8) => {
156
+ let best;
157
+ let bestDistance = Infinity;
158
+ for (const edge of edges) {
159
+ const distance = distanceToCurve(edge.curve, point);
160
+ if (distance <= tolerance && distance < bestDistance) {
161
+ best = edge.id;
162
+ bestDistance = distance;
163
+ }
164
+ }
165
+ return best;
166
+ };
167
+ var readingOrder = (nodes, column = 40) => nodes.map((node, index) => ({ node, index })).sort((a, b) => {
168
+ const ax = Math.round(a.node.x / column);
169
+ const bx = Math.round(b.node.x / column);
170
+ return ax - bx || a.node.y - b.node.y || a.index - b.index;
171
+ }).map(({ node }) => node.id);
172
+ export {
173
+ DEFAULT_MAX_ZOOM,
174
+ DEFAULT_MIN_ZOOM,
175
+ IDENTITY_VIEWPORT,
176
+ boundsOf,
177
+ centerOn,
178
+ clamp,
179
+ curvePath,
180
+ curvePoint,
181
+ defaultCanvasLabels,
182
+ distanceToCurve,
183
+ edgeCurve,
184
+ fitViewport,
185
+ hitEdge,
186
+ hitNode,
187
+ inputAnchor,
188
+ isRectVisible,
189
+ outputAnchor,
190
+ panBy,
191
+ pinchViewport,
192
+ readingOrder,
193
+ rectContains,
194
+ screenToWorld,
195
+ snapPoint,
196
+ snapTo,
197
+ worldToScreen,
198
+ zoomAt
199
+ };
200
+ //# sourceMappingURL=canvas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/canvas/geometry.ts"],"sourcesContent":["// The canvas's maths: viewport transforms, fitting, hit testing and the shape of an edge.\n// Pure functions over plain numbers - no DOM, no React - so they are unit-tested as they are.\n\nexport interface Point {\n x: number\n y: number\n}\n\nexport interface Size {\n width: number\n height: number\n}\n\nexport interface Rect extends Point, Size {}\n\n/**\n * Where the world sits on the screen: a world point `p` is drawn at\n * `p * zoom + (x, y)`, in pixels from the canvas's top-left corner.\n */\nexport interface Viewport {\n x: number\n y: number\n zoom: number\n}\n\n/** The four control points of a cubic Bezier curve. */\nexport interface Curve {\n p0: Point\n p1: Point\n p2: Point\n p3: Point\n}\n\nexport const DEFAULT_MIN_ZOOM = 0.25\nexport const DEFAULT_MAX_ZOOM = 2\nexport const IDENTITY_VIEWPORT: Viewport = { x: 0, y: 0, zoom: 1 }\n\nexport const clamp = (value: number, min: number, max: number): number =>\n Math.min(max, Math.max(min, value))\n\nexport const screenToWorld = (point: Point, viewport: Viewport): Point => ({\n x: (point.x - viewport.x) / viewport.zoom,\n y: (point.y - viewport.y) / viewport.zoom,\n})\n\nexport const worldToScreen = (point: Point, viewport: Viewport): Point => ({\n x: point.x * viewport.zoom + viewport.x,\n y: point.y * viewport.zoom + viewport.y,\n})\n\nexport const panBy = (viewport: Viewport, dx: number, dy: number): Viewport => ({\n ...viewport,\n x: viewport.x + dx,\n y: viewport.y + dy,\n})\n\n/** Set the zoom, keeping the world point under `anchor` (a screen point) where it is. */\nexport const zoomAt = (\n viewport: Viewport,\n zoom: number,\n anchor: Point,\n minZoom = DEFAULT_MIN_ZOOM,\n maxZoom = DEFAULT_MAX_ZOOM,\n): Viewport => {\n const next = clamp(zoom, minZoom, maxZoom)\n if (next === viewport.zoom) return viewport\n const world = screenToWorld(anchor, viewport)\n return { zoom: next, x: anchor.x - world.x * next, y: anchor.y - world.y * next }\n}\n\n/**\n * Two fingers moved from `before` to `after` (screen points): zoom by how far apart they went,\n * and keep the world point that was between them under the point that is between them now.\n */\nexport const pinchViewport = (\n viewport: Viewport,\n before: [Point, Point],\n after: [Point, Point],\n minZoom = DEFAULT_MIN_ZOOM,\n maxZoom = DEFAULT_MAX_ZOOM,\n): Viewport => {\n const distance = (a: Point, b: Point) => Math.hypot(a.x - b.x, a.y - b.y)\n const middle = (a: Point, b: Point): Point => ({ x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 })\n const was = distance(before[0], before[1])\n const is = distance(after[0], after[1])\n const zoom = clamp(was > 0 ? (viewport.zoom * is) / was : viewport.zoom, minZoom, maxZoom)\n const world = screenToWorld(middle(before[0], before[1]), viewport)\n const at = middle(after[0], after[1])\n return { zoom, x: at.x - world.x * zoom, y: at.y - world.y * zoom }\n}\n\n/** The smallest rectangle around all of `rects`; undefined when there are none. */\nexport const boundsOf = (rects: Rect[]): Rect | undefined => {\n if (rects.length === 0) return undefined\n let left = Infinity\n let top = Infinity\n let right = -Infinity\n let bottom = -Infinity\n for (const r of rects) {\n left = Math.min(left, r.x)\n top = Math.min(top, r.y)\n right = Math.max(right, r.x + r.width)\n bottom = Math.max(bottom, r.y + r.height)\n }\n return { x: left, y: top, width: right - left, height: bottom - top }\n}\n\nexport interface FitOptions {\n /** Free space kept around the content, in screen pixels (default 48). */\n padding?: number\n minZoom?: number\n /** Fitting never zooms in past this (default 1: a small graph is not blown up). */\n maxZoom?: number\n}\n\n// One axis of a fit: centred when the content fits, from its start (the padding kept) when it\n// does not - a graph too large for the canvas at the smallest zoom shows where it begins.\nconst fitAxis = (start: number, length: number, room: number, zoom: number, padding: number) =>\n length * zoom <= room - padding * 2 + 0.5\n ? (room - length * zoom) / 2 - start * zoom\n : padding - start * zoom\n\n/**\n * The viewport that shows all of `rects` centred in a canvas of `size`. When they do not fit at\n * `minZoom`, it shows them from their top-left corner at that zoom instead.\n */\nexport const fitViewport = (rects: Rect[], size: Size, options: FitOptions = {}): Viewport => {\n const bounds = boundsOf(rects)\n if (!bounds || size.width <= 0 || size.height <= 0) return IDENTITY_VIEWPORT\n const { minZoom = DEFAULT_MIN_ZOOM, maxZoom = 1 } = options\n // A narrow canvas cannot afford the padding a wide one has.\n const padding = Math.min(options.padding ?? 48, size.width / 8, size.height / 8)\n const zoom = clamp(\n Math.min(\n (size.width - padding * 2) / Math.max(bounds.width, 1),\n (size.height - padding * 2) / Math.max(bounds.height, 1),\n ),\n minZoom,\n maxZoom,\n )\n return {\n zoom,\n x: fitAxis(bounds.x, bounds.width, size.width, zoom, padding),\n y: fitAxis(bounds.y, bounds.height, size.height, zoom, padding),\n }\n}\n\n/** The viewport with `rect` in the middle of a canvas of `size`, at the zoom given. */\nexport const centerOn = (rect: Rect, size: Size, zoom: number): Viewport => ({\n zoom,\n x: size.width / 2 - (rect.x + rect.width / 2) * zoom,\n y: size.height / 2 - (rect.y + rect.height / 2) * zoom,\n})\n\n/** Is any part of `rect` (world) inside a canvas of `size` under `viewport`? */\nexport const isRectVisible = (rect: Rect, size: Size, viewport: Viewport): boolean => {\n const a = worldToScreen(rect, viewport)\n const b = worldToScreen({ x: rect.x + rect.width, y: rect.y + rect.height }, viewport)\n return b.x > 0 && b.y > 0 && a.x < size.width && a.y < size.height\n}\n\nexport const snapTo = (value: number, grid: number): number =>\n // `+ 0`: a rounded-away negative is 0, not -0.\n grid > 0 ? Math.round(value / grid) * grid + 0 : value\n\nexport const snapPoint = (point: Point, grid: number): Point => ({\n x: snapTo(point.x, grid),\n y: snapTo(point.y, grid),\n})\n\nexport const rectContains = (rect: Rect, point: Point): boolean =>\n point.x >= rect.x &&\n point.x <= rect.x + rect.width &&\n point.y >= rect.y &&\n point.y <= rect.y + rect.height\n\n/** The id of the node under `point` (world). Later nodes are drawn on top, so they win. */\nexport const hitNode = <T extends Rect & { id: string }>(\n nodes: T[],\n point: Point,\n): string | undefined => {\n for (let i = nodes.length - 1; i >= 0; i--) {\n if (rectContains(nodes[i], point)) return nodes[i].id\n }\n return undefined\n}\n\n/** Where an edge enters a node: the middle of its left side. */\nexport const inputAnchor = (rect: Rect): Point => ({ x: rect.x, y: rect.y + rect.height / 2 })\n\n/** Where an edge leaves a node that has `count` output ports: spread down its right side. */\nexport const outputAnchor = (rect: Rect, index = 0, count = 1): Point => ({\n x: rect.x + rect.width,\n y: rect.y + (rect.height * (index + 1)) / (Math.max(count, 1) + 1),\n})\n\nexport interface EdgeCurveOptions {\n /**\n * How far an edge that runs backwards (its target is to the left of its source) swings below\n * the two nodes so that it does not cross them (default 90).\n */\n clearance?: number\n}\n\n/**\n * The curve of an edge that leaves `from` to the right and enters `to` from the left. A forward\n * edge is a plain S; a backward one (a loop) swings out and around.\n */\nexport const edgeCurve = (from: Point, to: Point, options: EdgeCurveOptions = {}): Curve => {\n const dx = to.x - from.x\n const dy = to.y - from.y\n if (dx >= 40) {\n const reach = Math.max(dx / 2, 40)\n return {\n p0: from,\n p1: { x: from.x + reach, y: from.y },\n p2: { x: to.x - reach, y: to.y },\n p3: to,\n }\n }\n const reach = clamp(60 + Math.abs(dx) / 4, 60, 220)\n const clearance = options.clearance ?? 90\n // Nearly level: go around below. Otherwise the height difference already keeps it clear.\n const swing = Math.abs(dy) < clearance ? clearance + Math.abs(dy) / 2 : 0\n return {\n p0: from,\n p1: { x: from.x + reach, y: from.y + swing },\n p2: { x: to.x - reach, y: to.y + swing },\n p3: to,\n }\n}\n\nconst round = (n: number): number => Math.round(n * 100) / 100\n\n/** The SVG path data of a curve. */\nexport const curvePath = ({ p0, p1, p2, p3 }: Curve): string =>\n `M ${round(p0.x)} ${round(p0.y)} C ${round(p1.x)} ${round(p1.y)}, ${round(p2.x)} ${round(p2.y)}, ${round(p3.x)} ${round(p3.y)}`\n\n/** The point of a curve at `t` in 0..1. */\nexport const curvePoint = ({ p0, p1, p2, p3 }: Curve, t: number): Point => {\n const u = 1 - t\n const a = u * u * u\n const b = 3 * u * u * t\n const c = 3 * u * t * t\n const d = t * t * t\n return {\n x: a * p0.x + b * p1.x + c * p2.x + d * p3.x,\n y: a * p0.y + b * p1.y + c * p2.y + d * p3.y,\n }\n}\n\nconst distanceToSegment = (p: Point, a: Point, b: Point): number => {\n const dx = b.x - a.x\n const dy = b.y - a.y\n const length = dx * dx + dy * dy\n const t = length === 0 ? 0 : clamp(((p.x - a.x) * dx + (p.y - a.y) * dy) / length, 0, 1)\n return Math.hypot(p.x - (a.x + t * dx), p.y - (a.y + t * dy))\n}\n\n/** How far `point` is from a curve (the curve is walked in `samples` straight pieces). */\nexport const distanceToCurve = (curve: Curve, point: Point, samples = 24): number => {\n let best = Infinity\n let previous = curve.p0\n for (let i = 1; i <= samples; i++) {\n const next = curvePoint(curve, i / samples)\n best = Math.min(best, distanceToSegment(point, previous, next))\n previous = next\n }\n return best\n}\n\n/** The id of the edge within `tolerance` of `point`, the nearest one when several are. */\nexport const hitEdge = (\n edges: { id: string; curve: Curve }[],\n point: Point,\n tolerance = 8,\n): string | undefined => {\n let best: string | undefined\n let bestDistance = Infinity\n for (const edge of edges) {\n const distance = distanceToCurve(edge.curve, point)\n if (distance <= tolerance && distance < bestDistance) {\n best = edge.id\n bestDistance = distance\n }\n }\n return best\n}\n\n/**\n * The order a keyboard walks the nodes in: left to right, then top to bottom - the direction a\n * graph that flows from its entry to its end is read in. Nodes in the same column (within\n * `column` pixels) count as level.\n */\nexport const readingOrder = <T extends Point & { id: string }>(nodes: T[], column = 40): string[] =>\n nodes\n .map((node, index) => ({ node, index }))\n .sort((a, b) => {\n const ax = Math.round(a.node.x / column)\n const bx = Math.round(b.node.x / column)\n return ax - bx || a.node.y - b.node.y || a.index - b.index\n })\n .map(({ node }) => node.id)\n"],"mappings":";;;;;AAiCO,IAAM,mBAAmB;AACzB,IAAM,mBAAmB;AACzB,IAAM,oBAA8B,EAAE,GAAG,GAAG,GAAG,GAAG,MAAM,EAAE;AAE1D,IAAM,QAAQ,CAAC,OAAe,KAAa,QAChD,KAAK,IAAI,KAAK,KAAK,IAAI,KAAK,KAAK,CAAC;AAE7B,IAAM,gBAAgB,CAAC,OAAc,cAA+B;AAAA,EACzE,IAAI,MAAM,IAAI,SAAS,KAAK,SAAS;AAAA,EACrC,IAAI,MAAM,IAAI,SAAS,KAAK,SAAS;AACvC;AAEO,IAAM,gBAAgB,CAAC,OAAc,cAA+B;AAAA,EACzE,GAAG,MAAM,IAAI,SAAS,OAAO,SAAS;AAAA,EACtC,GAAG,MAAM,IAAI,SAAS,OAAO,SAAS;AACxC;AAEO,IAAM,QAAQ,CAAC,UAAoB,IAAY,QAA0B;AAAA,EAC9E,GAAG;AAAA,EACH,GAAG,SAAS,IAAI;AAAA,EAChB,GAAG,SAAS,IAAI;AAClB;AAGO,IAAM,SAAS,CACpB,UACA,MACA,QACA,UAAU,kBACV,UAAU,qBACG;AACb,QAAM,O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MAAM,MAAM,EAAE,EACtC,KAAK,CAAC,GAAG,MAAM;AACd,QAAM,KAAK,KAAK,MAAM,EAAE,KAAK,IAAI,MAAM;AACvC,QAAM,KAAK,KAAK,MAAM,EAAE,KAAK,IAAI,MAAM;AACvC,SAAO,KAAK,MAAM,EAAE,KAAK,IAAI,EAAE,KAAK,KAAK,EAAE,QAAQ,EAAE;AACvD,CAAC,EACA,IAAI,CAAC,EAAE,KAAK,MAAM,KAAK,EAAE;","names":["reach"]}
@@ -0,0 +1,125 @@
1
+ // src/named-files.ts
2
+ var NAMED_FILES_MAX = 12;
3
+ var NAMED_FILES_SCAN_MAX = 200;
4
+ var NAMED_FILES_TEXT_MAX = 1e5;
5
+ var PATH_MAX = 512;
6
+ var workspacePathOf = (raw) => {
7
+ if (raw.length < 2 || raw.length > PATH_MAX) return void 0;
8
+ if (raw[0] !== "/" || raw[1] === "/") return void 0;
9
+ if (/[\u0000-\u001f\u007f\\]/.test(raw)) return void 0;
10
+ const segments = raw.slice(1).split("/");
11
+ for (const s of segments) {
12
+ if (!s || s === "." || s === ".." || s.trim() !== s) return void 0;
13
+ }
14
+ return raw;
15
+ };
16
+ var withoutFences = (text) => {
17
+ const lines = text.split("\n");
18
+ let fence;
19
+ for (let i = 0; i < lines.length; i++) {
20
+ const open = /^ {0,3}(`{3,}|~{3,})/.exec(lines[i]);
21
+ if (!fence) {
22
+ if (open && !(open[1][0] === "`" && lines[i].slice(open[0].length).includes("`"))) {
23
+ fence = { char: open[1][0], size: open[1].length };
24
+ lines[i] = " ".repeat(lines[i].length);
25
+ }
26
+ continue;
27
+ }
28
+ const close = /^ {0,3}(`{3,}|~{3,})\s*$/.exec(lines[i]);
29
+ if (close && close[1][0] === fence.char && close[1].length >= fence.size) fence = void 0;
30
+ lines[i] = " ".repeat(lines[i].length);
31
+ }
32
+ return lines.join("\n");
33
+ };
34
+ var decoded = (s) => {
35
+ if (!s.includes("%")) return s;
36
+ try {
37
+ return decodeURIComponent(s);
38
+ } catch {
39
+ return s;
40
+ }
41
+ };
42
+ var codeSpansOf = (text) => {
43
+ const runs = [];
44
+ for (let i = text.indexOf("`"); i >= 0; i = text.indexOf("`", i)) {
45
+ let j = i + 1;
46
+ while (j < text.length && text.charCodeAt(j) === 96) j++;
47
+ runs.push({ at: i, size: j - i });
48
+ i = j;
49
+ }
50
+ const next = new Array(runs.length);
51
+ const later = /* @__PURE__ */ new Map();
52
+ for (let k = runs.length - 1; k >= 0; k--) {
53
+ next[k] = later.get(runs[k].size) ?? -1;
54
+ later.set(runs[k].size, k);
55
+ }
56
+ const spans = [];
57
+ for (let k = 0; k < runs.length; ) {
58
+ const close = next[k];
59
+ if (close < 0) {
60
+ k++;
61
+ continue;
62
+ }
63
+ const open = runs[k];
64
+ const end = runs[close].at + runs[close].size;
65
+ spans.push({ at: open.at, end, inner: text.slice(open.at + open.size, runs[close].at) });
66
+ k = close + 1;
67
+ }
68
+ return spans;
69
+ };
70
+ var LINK = /!?\[[^[\]\n]*\]\(\s*(<[^<>\n]+>|[^\s()<>]+)(?:\s+(?:"[^"\n]*"|'[^'\n]*'|\([^()\n]*\)))?\s*\)/g;
71
+ var pathsNamedIn = (text) => {
72
+ if (!text) return [];
73
+ const head = text.length > NAMED_FILES_TEXT_MAX ? text.slice(0, NAMED_FILES_TEXT_MAX) : text;
74
+ if (!head.includes("/")) return [];
75
+ const found = [];
76
+ let masked = withoutFences(head);
77
+ const spans = codeSpansOf(masked);
78
+ const parts = [];
79
+ let from = 0;
80
+ for (const span of spans) {
81
+ let inner = span.inner;
82
+ if (inner.length > 2 && inner.startsWith(" ") && inner.endsWith(" ")) inner = inner.slice(1, -1);
83
+ const path = workspacePathOf(inner);
84
+ if (path) found.push({ at: span.at, path });
85
+ parts.push(masked.slice(from, span.at), " ".repeat(span.end - span.at));
86
+ from = span.end;
87
+ }
88
+ masked = parts.join("") + masked.slice(from);
89
+ for (const m of masked.matchAll(LINK)) {
90
+ const dest = m[1].startsWith("<") ? m[1].slice(1, -1) : m[1];
91
+ const path = workspacePathOf(decoded(dest));
92
+ if (path) found.push({ at: m.index, path });
93
+ }
94
+ found.sort((a, b) => a.at - b.at);
95
+ const out = [];
96
+ const seen = /* @__PURE__ */ new Set();
97
+ for (const { path } of found) {
98
+ if (seen.has(path)) continue;
99
+ seen.add(path);
100
+ out.push(path);
101
+ if (out.length >= NAMED_FILES_SCAN_MAX) break;
102
+ }
103
+ return out;
104
+ };
105
+ var namedFilesOf = (named, exists, { exclude, max = NAMED_FILES_MAX } = {}) => {
106
+ const skip = new Set(exclude ?? []);
107
+ const out = [];
108
+ for (const path of named) {
109
+ if (out.length >= max) break;
110
+ if (skip.has(path) || !exists(path)) continue;
111
+ skip.add(path);
112
+ out.push(path);
113
+ }
114
+ return out;
115
+ };
116
+
117
+ export {
118
+ NAMED_FILES_MAX,
119
+ NAMED_FILES_SCAN_MAX,
120
+ NAMED_FILES_TEXT_MAX,
121
+ workspacePathOf,
122
+ pathsNamedIn,
123
+ namedFilesOf
124
+ };
125
+ //# sourceMappingURL=chunk-7O64ZI6Z.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/named-files.ts"],"sourcesContent":["/**\n * The workspace files an answer NAMES in its text (`<MessageList showNamedFiles>`): pure, no\n * React, no DOM, no import. What it reads as a path, exactly:\n *\n * - an inline code span whose whole content is an absolute path - `` `/attachments/a.png` ``\n * (one or more backticks, CommonMark's rule: closed by a run of the same length; the one space\n * inside each end is dropped);\n * - the destination of a Markdown link or image - `[a](/media/a.jpg)`, `![a](/media/a.jpg \"t\")`,\n * `[a](</notes/my notes.md>)` - percent-decoded.\n *\n * Nothing else: a path in plain words (`see /notes.md`), in a fenced code block (``` or ~~~ - a\n * listing, a command, an example: not something the answer hands over), in an indented block or\n * in a URL (`https://…`, `//host/…`) is not read. A path is absolute, one line, at most 512\n * characters, with no empty, `.` or `..` segment, no backslash or control character and no\n * trailing slash (a folder) - it is never normalised into another path: what is looked up is what\n * the answer wrote. Then {@link namedFilesOf} keeps only the paths that EXIST in the workspace's\n * listing - the one check that matters: a path that is not a file of the workspace is nothing.\n *\n * The scan is linear in the text, whatever the text holds (it runs while a message is drawn,\n * and the text is the model's - which a fetched page can steer): code spans by one pass over the\n * runs of backticks, links by a pattern that cannot backtrack across brackets, and no more than\n * {@link NAMED_FILES_TEXT_MAX} characters of it.\n */\n\n/** The most files an answer is shown with (see {@link namedFilesOf}). */\nexport const NAMED_FILES_MAX = 12\n\n/** The most distinct paths kept from one text (a bound on what is looked up, not on the scan). */\nexport const NAMED_FILES_SCAN_MAX = 200\n\n/**\n * The most of a text that is scanned: the first 100,000 characters. That is about 25,000 tokens -\n * more than an answer that hands files over is (above most models' default output limit for one\n * answer); past it, the text is a dump (a file pasted back, a runaway answer), whose paths are a\n * listing, not files handed over. It bounds the scan's (linear) work to a few milliseconds.\n */\nexport const NAMED_FILES_TEXT_MAX = 100_000\n\nconst PATH_MAX = 512\n\n/** `raw` as a workspace path, or `undefined` when it is not one (see the module's rules). */\nexport const workspacePathOf = (raw: string): string | undefined => {\n if (raw.length < 2 || raw.length > PATH_MAX) return undefined\n if (raw[0] !== '/' || raw[1] === '/') return undefined\n // Control characters (a line break among them), DEL, a backslash.\n // eslint-disable-next-line no-control-regex\n if (/[\\u0000-\\u001f\\u007f\\\\]/.test(raw)) return undefined\n const segments = raw.slice(1).split('/')\n for (const s of segments) {\n if (!s || s === '.' || s === '..' || s.trim() !== s) return undefined\n }\n return raw\n}\n\n/** The text with its fenced code blocks blanked out (the same length, line breaks kept). */\nconst withoutFences = (text: string): string => {\n const lines = text.split('\\n')\n let fence: { char: string; size: number } | undefined\n for (let i = 0; i < lines.length; i++) {\n const open = /^ {0,3}(`{3,}|~{3,})/.exec(lines[i])\n if (!fence) {\n if (open && !(open[1][0] === '`' && lines[i].slice(open[0].length).includes('`'))) {\n fence = { char: open[1][0], size: open[1].length }\n lines[i] = ' '.repeat(lines[i].length)\n }\n continue\n }\n const close = /^ {0,3}(`{3,}|~{3,})\\s*$/.exec(lines[i])\n if (close && close[1][0] === fence.char && close[1].length >= fence.size) fence = undefined\n lines[i] = ' '.repeat(lines[i].length)\n }\n return lines.join('\\n')\n}\n\nconst decoded = (s: string): string => {\n if (!s.includes('%')) return s\n try {\n return decodeURIComponent(s)\n } catch {\n return s\n }\n}\n\n/**\n * The code spans of a text, as CommonMark reads them: a run of backticks opens a span that the\n * next run of the SAME length closes (a run with no such run after it is just backticks). One\n * pass over the runs, and the closer of each found from a map of the next run of each length -\n * linear, where a regex with a back-reference tried every closer for every opener (a run of 300\n * backticks before 20,000 characters took seconds).\n */\nconst codeSpansOf = (text: string): { at: number; end: number; inner: string }[] => {\n const runs: { at: number; size: number }[] = []\n for (let i = text.indexOf('`'); i >= 0; i = text.indexOf('`', i)) {\n let j = i + 1\n while (j < text.length && text.charCodeAt(j) === 96) j++\n runs.push({ at: i, size: j - i })\n i = j\n }\n const next = new Array<number>(runs.length)\n const later = new Map<number, number>()\n for (let k = runs.length - 1; k >= 0; k--) {\n next[k] = later.get(runs[k].size) ?? -1\n later.set(runs[k].size, k)\n }\n const spans: { at: number; end: number; inner: string }[] = []\n for (let k = 0; k < runs.length;) {\n const close = next[k]\n if (close < 0) {\n k++\n continue\n }\n const open = runs[k]\n const end = runs[close].at + runs[close].size\n spans.push({ at: open.at, end, inner: text.slice(open.at + open.size, runs[close].at) })\n // The runs between the two are the span's content.\n k = close + 1\n }\n return spans\n}\n\n/**\n * A link or image: `[text](dest \"title\")`, the destination bare or in `<…>`. The text holds no\n * bracket at all - so a line of `[` is read once, not once from every `[` to the line's end.\n */\nconst LINK =\n /!?\\[[^[\\]\\n]*\\]\\(\\s*(<[^<>\\n]+>|[^\\s()<>]+)(?:\\s+(?:\"[^\"\\n]*\"|'[^'\\n]*'|\\([^()\\n]*\\)))?\\s*\\)/g\n\n/**\n * The workspace paths a text names, in the order they appear, each once, at most\n * {@link NAMED_FILES_SCAN_MAX}. Whether they exist is {@link namedFilesOf}'s question.\n */\nexport const pathsNamedIn = (text: string): string[] => {\n if (!text) return []\n const head = text.length > NAMED_FILES_TEXT_MAX ? text.slice(0, NAMED_FILES_TEXT_MAX) : text\n if (!head.includes('/')) return []\n const found: { at: number; path: string }[] = []\n let masked = withoutFences(head)\n // Code spans first, then blanked: a link written inside one is code, not a link.\n const spans = codeSpansOf(masked)\n const parts: string[] = []\n let from = 0\n for (const span of spans) {\n let inner = span.inner\n if (inner.length > 2 && inner.startsWith(' ') && inner.endsWith(' ')) inner = inner.slice(1, -1)\n const path = workspacePathOf(inner)\n if (path) found.push({ at: span.at, path })\n parts.push(masked.slice(from, span.at), ' '.repeat(span.end - span.at))\n from = span.end\n }\n masked = parts.join('') + masked.slice(from)\n for (const m of masked.matchAll(LINK)) {\n const dest = m[1].startsWith('<') ? m[1].slice(1, -1) : m[1]\n const path = workspacePathOf(decoded(dest))\n if (path) found.push({ at: m.index, path })\n }\n found.sort((a, b) => a.at - b.at)\n const out: string[] = []\n const seen = new Set<string>()\n for (const { path } of found) {\n if (seen.has(path)) continue\n seen.add(path)\n out.push(path)\n if (out.length >= NAMED_FILES_SCAN_MAX) break\n }\n return out\n}\n\nexport interface NamedFilesOptions {\n /** Paths left out - the files the answer wrote, the media it made: they have chips already. */\n exclude?: Iterable<string>\n /** At most this many (default {@link NAMED_FILES_MAX}). */\n max?: number\n}\n\n/**\n * The paths of `named` (from {@link pathsNamedIn}) that are files of the workspace - `exists`\n * answers from its listing, never by reading or fetching anything -, without `exclude`, in order,\n * at most `max` (default 12: each chip of a picture reads its bytes for the thumbnail, and an\n * answer that lists a folder of two hundred files would otherwise read them all - the chips are\n * for the files the answer hands over, not a second file browser; the Files panel has them all).\n */\nexport const namedFilesOf = (\n named: readonly string[],\n exists: (path: string) => boolean,\n { exclude, max = NAMED_FILES_MAX }: NamedFilesOptions = {},\n): string[] => {\n const skip = new Set(exclude ?? [])\n const out: string[] = []\n for (const path of named) {\n if (out.length >= max) break\n if (skip.has(path) || !exists(path)) continue\n skip.add(path)\n out.push(path)\n }\n return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