@zeyos/zx 5.7.1 → 5.8.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 (326) hide show
  1. package/CHANGELOG.md +296 -0
  2. package/README.md +47 -9
  3. package/dist/types/components/activity-item/activity-item.d.ts +14 -3
  4. package/dist/types/components/agent-avatar/agent-avatar.d.ts +165 -0
  5. package/dist/types/components/agent-avatar/agent-face.d.ts +93 -0
  6. package/dist/types/components/agent-thread/ag-ui.d.ts +21 -9
  7. package/dist/types/components/agent-thread/agent-thread.d.ts +26 -0
  8. package/dist/types/components/agent-thread/ui-message-stream.d.ts +3 -1
  9. package/dist/types/components/approval-card/approval-card.d.ts +31 -2
  10. package/dist/types/components/aurora/aurora.d.ts +31 -5
  11. package/dist/types/components/calendar/calendar.d.ts +39 -26
  12. package/dist/types/components/chart/chart.d.ts +250 -20
  13. package/dist/types/components/chart/color.d.ts +66 -0
  14. package/dist/types/components/chart/svg-adapter.d.ts +103 -0
  15. package/dist/types/components/chart/svg-geometry.d.ts +203 -0
  16. package/dist/types/components/check-button/check-button.d.ts +1 -4
  17. package/dist/types/components/checklist/checklist.d.ts +19 -5
  18. package/dist/types/components/code-editor/code-editor.d.ts +55 -1
  19. package/dist/types/components/composer/composer.d.ts +41 -6
  20. package/dist/types/components/context-menu/context-menu.d.ts +36 -8
  21. package/dist/types/components/copy/copy-button.d.ts +6 -0
  22. package/dist/types/components/copy/copy-input.d.ts +1 -0
  23. package/dist/types/components/date-picker/date-picker.d.ts +14 -0
  24. package/dist/types/components/date-picker/time-picker.d.ts +26 -17
  25. package/dist/types/components/datebox/datebox.d.ts +8 -4
  26. package/dist/types/components/dialog/dialog.d.ts +13 -2
  27. package/dist/types/components/empty-state/empty-state.d.ts +10 -1
  28. package/dist/types/components/field/field.d.ts +4 -2
  29. package/dist/types/components/form/form.d.ts +2 -1
  30. package/dist/types/components/kanban-view/kanban-card.d.ts +7 -0
  31. package/dist/types/components/kanban-view/kanban-view.d.ts +15 -3
  32. package/dist/types/components/launcher/launcher.d.ts +26 -0
  33. package/dist/types/components/master-panel/master-panel.d.ts +9 -4
  34. package/dist/types/components/menu-button/menu-button.d.ts +29 -5
  35. package/dist/types/components/message/message.d.ts +308 -5
  36. package/dist/types/components/modal/modal.d.ts +11 -0
  37. package/dist/types/components/modal/native-dialog.d.ts +40 -0
  38. package/dist/types/components/module-bar/module-bar.d.ts +9 -2
  39. package/dist/types/components/multi-value-editor/multi-value-editor.d.ts +5 -4
  40. package/dist/types/components/number-field/number-field.d.ts +7 -0
  41. package/dist/types/components/pagination/pagination.d.ts +341 -19
  42. package/dist/types/components/run-status/run-status.d.ts +26 -0
  43. package/dist/types/components/run-trace/run-trace.d.ts +10 -6
  44. package/dist/types/components/search/search.d.ts +16 -4
  45. package/dist/types/components/select/select.d.ts +19 -1
  46. package/dist/types/components/sheet/sheet.d.ts +18 -4
  47. package/dist/types/components/slider/slider.d.ts +2 -1
  48. package/dist/types/components/stat-tile/stat-tile.d.ts +20 -3
  49. package/dist/types/components/stepper/stepper.d.ts +17 -4
  50. package/dist/types/components/surface/catalog.d.ts +61 -17
  51. package/dist/types/components/surface/surface.d.ts +6 -4
  52. package/dist/types/components/table/table.d.ts +207 -5
  53. package/dist/types/components/table/window.d.ts +25 -1
  54. package/dist/types/components/toggle/toggle.d.ts +38 -6
  55. package/dist/types/components/tooltip/tooltip.d.ts +5 -4
  56. package/dist/types/components/tree/tree.d.ts +43 -6
  57. package/dist/types/components/truncate/truncate.d.ts +4 -2
  58. package/dist/types/components/value-list/value-list.d.ts +9 -2
  59. package/dist/types/core/date.d.ts +2 -1
  60. package/dist/types/core/drag-axis.d.ts +10 -5
  61. package/dist/types/core/export.d.ts +2 -2
  62. package/dist/types/core/format.d.ts +3 -1
  63. package/dist/types/core/icons.d.ts +36 -3
  64. package/dist/types/core/keyboard.d.ts +7 -3
  65. package/dist/types/core/messages.d.ts +3 -0
  66. package/dist/types/core/storage.d.ts +4 -3
  67. package/dist/types/core/util.d.ts +3 -1
  68. package/dist/types/elements/define.d.ts +5 -2
  69. package/dist/types/index.d.ts +6 -4
  70. package/dist/types/internal/agent-model.d.ts +99 -0
  71. package/dist/types/internal/app-rail.d.ts +37 -2
  72. package/dist/types/internal/collections.d.ts +18 -0
  73. package/dist/types/internal/menu-items.d.ts +27 -0
  74. package/dist/types/internal/overlay-content.d.ts +23 -0
  75. package/dist/types/internal/presence-loop.d.ts +5 -2
  76. package/dist/types/locales/index.d.ts +3 -0
  77. package/dist/types/zeyos/calendar.d.ts +43 -7
  78. package/dist/types/zeyos/connect.d.ts +4 -0
  79. package/dist/types/zeyos/form.d.ts +13 -5
  80. package/dist/types/zeyos/select.d.ts +5 -2
  81. package/dist/types/zeyos/table.d.ts +16 -8
  82. package/dist/types/zeyos/view.d.ts +2 -1
  83. package/dist/zx-zeyos.esm.js +2998 -451
  84. package/dist/zx-zeyos.esm.min.js +4 -4
  85. package/dist/zx.core.css +4 -0
  86. package/dist/zx.core.min.css +1 -1
  87. package/dist/zx.css +948 -48
  88. package/dist/zx.esm.js +7432 -3408
  89. package/dist/zx.esm.min.js +26 -26
  90. package/dist/zx.global.js +7432 -3408
  91. package/dist/zx.global.min.js +26 -26
  92. package/dist/zx.layered.css +950 -48
  93. package/dist/zx.layered.min.css +1 -1
  94. package/dist/zx.min.css +1 -1
  95. package/docs/agent-catalog.json +159 -1
  96. package/docs/agent-surfaces.md +21 -21
  97. package/docs/api.json +3122 -528
  98. package/docs/components/account-menu.md +24 -0
  99. package/docs/components/activity-item.md +23 -0
  100. package/docs/components/activity-list.md +28 -0
  101. package/docs/components/agent-avatar.md +59 -0
  102. package/docs/components/agent-thread.md +275 -0
  103. package/docs/components/app-icon.md +36 -0
  104. package/docs/components/app-sidebar.md +92 -0
  105. package/docs/components/approval-card.md +71 -0
  106. package/docs/components/aurora.md +34 -0
  107. package/docs/components/avatar.md +37 -0
  108. package/docs/components/badge.md +36 -0
  109. package/docs/components/block-view.md +34 -0
  110. package/docs/components/breadcrumb.md +20 -0
  111. package/docs/components/button.md +23 -0
  112. package/docs/components/calendar.md +68 -0
  113. package/docs/components/card-view.md +73 -0
  114. package/docs/components/card.md +25 -0
  115. package/docs/components/chart.md +109 -0
  116. package/docs/components/check-button.md +16 -0
  117. package/docs/components/checklist.md +19 -0
  118. package/docs/components/code-editor.md +38 -0
  119. package/docs/components/composer.md +107 -0
  120. package/docs/components/context-menu.md +32 -0
  121. package/docs/components/copy.md +37 -0
  122. package/docs/components/data-filter.md +16 -0
  123. package/docs/components/date-picker.md +31 -0
  124. package/docs/components/date-range.md +21 -0
  125. package/docs/components/datebox.md +31 -0
  126. package/docs/components/dialog.md +25 -0
  127. package/docs/components/dock.md +57 -0
  128. package/docs/components/dropdown.md +39 -0
  129. package/docs/components/elements.md +63 -0
  130. package/docs/components/empty-state.md +17 -0
  131. package/docs/components/entity-ref.md +26 -0
  132. package/docs/components/field-upload.md +18 -0
  133. package/docs/components/file-item.md +27 -0
  134. package/docs/components/file-list.md +23 -0
  135. package/docs/components/filter-panel.md +45 -0
  136. package/docs/components/filter.md +47 -0
  137. package/docs/components/finder.md +25 -0
  138. package/docs/components/form-widgets.md +42 -0
  139. package/docs/components/form.md +80 -0
  140. package/docs/components/grid.md +26 -0
  141. package/docs/components/groupbox.md +11 -0
  142. package/docs/components/helpers.md +359 -0
  143. package/docs/components/icons.md +87 -0
  144. package/docs/components/index.md +99 -0
  145. package/docs/components/kanban-view.md +42 -0
  146. package/docs/components/kbd.md +23 -0
  147. package/docs/components/kernel.md +41 -0
  148. package/docs/components/launcher.md +66 -0
  149. package/docs/components/layout.md +33 -0
  150. package/docs/components/list-toolbar.md +38 -0
  151. package/docs/components/loading.md +48 -0
  152. package/docs/components/menu-button.md +47 -0
  153. package/docs/components/message.md +76 -0
  154. package/docs/components/modal.md +27 -0
  155. package/docs/components/module-bar.md +71 -0
  156. package/docs/components/multi-value-editor.md +16 -0
  157. package/docs/components/navigation-bar.md +22 -0
  158. package/docs/components/number-field.md +34 -0
  159. package/docs/components/pagination.md +73 -0
  160. package/docs/components/panel.md +28 -0
  161. package/docs/components/prompt-starters.md +40 -0
  162. package/docs/components/prose.md +38 -0
  163. package/docs/components/questionnaire.md +115 -0
  164. package/docs/components/rating.md +19 -0
  165. package/docs/components/run-status.md +50 -0
  166. package/docs/components/run-trace.md +72 -0
  167. package/docs/components/search.md +11 -0
  168. package/docs/components/select.md +129 -0
  169. package/docs/components/sheet-stack.md +39 -0
  170. package/docs/components/sheet.md +77 -0
  171. package/docs/components/skeleton.md +27 -0
  172. package/docs/components/slider.md +29 -0
  173. package/docs/components/sort-control.md +21 -0
  174. package/docs/components/source-list.md +30 -0
  175. package/docs/components/split-view.md +12 -0
  176. package/docs/components/stat-tile.md +49 -0
  177. package/docs/components/stepper.md +27 -0
  178. package/docs/components/surface.md +152 -0
  179. package/docs/components/tabbox.md +33 -0
  180. package/docs/components/table-view.md +43 -0
  181. package/docs/components/table.md +232 -0
  182. package/docs/components/tag-picker.md +39 -0
  183. package/docs/components/timebox.md +16 -0
  184. package/docs/components/toggle.md +21 -0
  185. package/docs/components/tokens.md +82 -0
  186. package/docs/components/toolbar.md +26 -0
  187. package/docs/components/tooltip.md +16 -0
  188. package/docs/components/tree.md +48 -0
  189. package/docs/components/truncate.md +21 -0
  190. package/docs/components/value-list.md +14 -0
  191. package/docs/components/view-settings.md +56 -0
  192. package/docs/components/workspace-switcher.md +42 -0
  193. package/docs/components/zeyos.md +196 -0
  194. package/docs/llms-small.txt +299 -0
  195. package/docs/llms.md +697 -100
  196. package/docs/llms.txt +46 -19
  197. package/package.json +9 -4
  198. package/src/components/activity-item/activity-item.js +21 -2
  199. package/src/components/agent-avatar/agent-avatar.css +195 -0
  200. package/src/components/agent-avatar/agent-avatar.js +333 -0
  201. package/src/components/agent-avatar/agent-face.js +292 -0
  202. package/src/components/agent-thread/ag-ui.js +44 -11
  203. package/src/components/agent-thread/agent-thread.js +103 -11
  204. package/src/components/agent-thread/ui-message-stream.js +3 -1
  205. package/src/components/app-rail/app-rail.css +5 -0
  206. package/src/components/app-sidebar/app-sidebar.css +3 -0
  207. package/src/components/app-sidebar/app-sidebar.js +4 -3
  208. package/src/components/approval-card/approval-card.css +6 -0
  209. package/src/components/approval-card/approval-card.js +55 -7
  210. package/src/components/aurora/aurora.css +149 -14
  211. package/src/components/aurora/aurora.js +49 -6
  212. package/src/components/calendar/calendar.css +6 -2
  213. package/src/components/calendar/calendar.js +127 -47
  214. package/src/components/card-view/card-view.js +5 -6
  215. package/src/components/chart/chart.css +159 -1
  216. package/src/components/chart/chart.js +450 -62
  217. package/src/components/chart/color.js +297 -0
  218. package/src/components/chart/svg-adapter.js +576 -0
  219. package/src/components/chart/svg-geometry.js +323 -0
  220. package/src/components/check-button/check-button.js +3 -18
  221. package/src/components/checklist/checklist.js +46 -17
  222. package/src/components/checklist/field-adapter.js +4 -1
  223. package/src/components/code-editor/code-editor.css +33 -0
  224. package/src/components/code-editor/code-editor.js +97 -8
  225. package/src/components/code-editor/field-adapter.js +3 -0
  226. package/src/components/composer/composer.css +3 -0
  227. package/src/components/composer/composer.js +100 -22
  228. package/src/components/context-menu/context-menu.js +41 -5
  229. package/src/components/copy/copy-button.js +9 -1
  230. package/src/components/copy/copy-input.js +5 -0
  231. package/src/components/data-filter/filter-core.js +0 -1
  232. package/src/components/date-picker/date-picker.css +8 -0
  233. package/src/components/date-picker/date-picker.js +47 -8
  234. package/src/components/date-picker/date-range-picker.js +1 -1
  235. package/src/components/date-picker/month-picker.js +19 -3
  236. package/src/components/date-picker/time-picker.js +54 -19
  237. package/src/components/datebox/date-range-box.js +7 -3
  238. package/src/components/datebox/datebox.js +32 -6
  239. package/src/components/dialog/dialog.css +6 -0
  240. package/src/components/dialog/dialog.js +22 -30
  241. package/src/components/dropdown/dropdown.js +1 -18
  242. package/src/components/empty-state/empty-state.js +21 -2
  243. package/src/components/field/field.js +19 -3
  244. package/src/components/fieldset/fieldset.js +3 -1
  245. package/src/components/filter/filter.js +9 -0
  246. package/src/components/form/form.js +19 -2
  247. package/src/components/kanban-view/kanban-card.js +15 -2
  248. package/src/components/kanban-view/kanban-view.css +21 -0
  249. package/src/components/kanban-view/kanban-view.js +29 -16
  250. package/src/components/launcher/launcher.css +14 -0
  251. package/src/components/launcher/launcher.js +54 -9
  252. package/src/components/master-panel/master-panel.js +24 -22
  253. package/src/components/menu-button/menu-button.js +26 -4
  254. package/src/components/message/message.css +228 -29
  255. package/src/components/message/message.js +664 -30
  256. package/src/components/modal/modal.js +70 -25
  257. package/src/components/modal/native-dialog.js +91 -0
  258. package/src/components/module-bar/module-bar.css +3 -0
  259. package/src/components/module-bar/module-bar.js +17 -4
  260. package/src/components/multi-value-editor/multi-value-editor.css +7 -2
  261. package/src/components/multi-value-editor/multi-value-editor.js +3 -2
  262. package/src/components/navigation-bar/navigation-bar.js +13 -1
  263. package/src/components/number-field/field-adapter.js +3 -0
  264. package/src/components/number-field/number-field.js +2 -1
  265. package/src/components/pagination/pagination.css +26 -2
  266. package/src/components/pagination/pagination.js +551 -65
  267. package/src/components/prose/prose.js +7 -1
  268. package/src/components/rating/field-adapter.js +3 -0
  269. package/src/components/run-status/run-status.js +43 -3
  270. package/src/components/run-trace/run-trace.js +15 -7
  271. package/src/components/search/search.js +3 -18
  272. package/src/components/select/field-adapter.js +8 -1
  273. package/src/components/select/select.js +68 -13
  274. package/src/components/sheet/sheet.js +27 -8
  275. package/src/components/slider/field-adapter.js +3 -0
  276. package/src/components/slider/slider.js +4 -6
  277. package/src/components/stat-tile/stat-tile.js +24 -9
  278. package/src/components/stepper/stepper.css +15 -0
  279. package/src/components/stepper/stepper.js +34 -2
  280. package/src/components/surface/catalog.js +185 -28
  281. package/src/components/surface/surface.js +10 -5
  282. package/src/components/tabbox/tabbox.js +13 -1
  283. package/src/components/table/table.css +160 -2
  284. package/src/components/table/table.js +479 -52
  285. package/src/components/table/window.js +46 -4
  286. package/src/components/table-view/table-view.js +1 -10
  287. package/src/components/tag-picker/field-adapter.js +3 -0
  288. package/src/components/tag-picker/tag-picker.js +2 -0
  289. package/src/components/timebox/field-adapter.js +3 -0
  290. package/src/components/toggle/toggle.js +51 -27
  291. package/src/components/tooltip/tooltip.js +21 -14
  292. package/src/components/tree/tree.js +87 -14
  293. package/src/components/truncate/truncate.js +21 -5
  294. package/src/components/value-list/value-list.js +37 -9
  295. package/src/components/view-settings/view-settings.js +1 -5
  296. package/src/core/component.js +34 -2
  297. package/src/core/date.js +5 -4
  298. package/src/core/drag-axis.js +24 -7
  299. package/src/core/export.js +4 -4
  300. package/src/core/fontawesome.js +34 -3
  301. package/src/core/format.js +3 -1
  302. package/src/core/http.js +23 -11
  303. package/src/core/icons.js +51 -10
  304. package/src/core/keyboard.js +83 -9
  305. package/src/core/messages.js +3 -0
  306. package/src/core/position.js +2 -2
  307. package/src/core/storage.js +80 -31
  308. package/src/core/util.js +16 -5
  309. package/src/elements/define.js +82 -47
  310. package/src/elements/kit.js +46 -35
  311. package/src/index.js +8 -4
  312. package/src/internal/agent-model.js +152 -0
  313. package/src/internal/app-rail.js +53 -2
  314. package/src/internal/collections.js +25 -0
  315. package/src/internal/menu-items.js +59 -0
  316. package/src/internal/overlay-content.js +35 -0
  317. package/src/internal/presence-loop.js +61 -14
  318. package/src/locales/de.js +3 -0
  319. package/src/zeyos/calendar.js +81 -19
  320. package/src/zeyos/connect.js +5 -1
  321. package/src/zeyos/form.js +29 -10
  322. package/src/zeyos/select.js +36 -12
  323. package/src/zeyos/table.js +43 -11
  324. package/src/zeyos/view.js +2 -1
  325. package/styles/tokens/semantic.css +7 -1
  326. package/styles/zx.css +1 -0
@@ -0,0 +1,323 @@
1
+ /**
2
+ * Geometry for `SvgChartAdapter`: a value scale with round ticks, the bars of a category, how
3
+ * often a category label fits, a line with gaps, and the slices and rings of a pie.
4
+ *
5
+ * Plain numbers in, plain numbers and SVG path strings out — no DOM — so the arithmetic is tested
6
+ * on its own (`tests/unit/chart-svg.test.js`). Angles are radians clockwise from twelve o'clock,
7
+ * the way a pie is read; coordinates are SVG user units, y growing downwards. Path coordinates are
8
+ * rounded to two decimals, which is finer than any screen draws and keeps the markup short.
9
+ * @module zx/components/chart/svg-geometry
10
+ */
11
+
12
+ const TAU = Math.PI * 2;
13
+ /** Tolerance for a quotient that should be a whole number but is not, by float noise. */
14
+ const EPSILON = 1e-9;
15
+ /**
16
+ * The finest step a scale takes, relative to its largest value: sixteen units in the last place
17
+ * of a double, so that consecutive ticks stay distinct numbers (1e16 + 0.5 is 1e16) and rounding a
18
+ * tick to its step's digits cannot land on a neighbour.
19
+ */
20
+ const PRECISION = 2 ** -48;
21
+ /** The most intervals a scale is asked for; whatever the input, a scale has a handful of ticks. */
22
+ const MAX_INTERVALS = 50;
23
+ /** A bound on the tick loop, well above what `MAX_INTERVALS` produces: it can never run away. */
24
+ const MAX_TICKS = 200;
25
+ /** The largest round step a double holds: 2 × 10³⁰⁸ is beyond it. */
26
+ const LARGEST_STEP = 1e308;
27
+
28
+ /**
29
+ * @typedef {Object} NiceScale
30
+ * @property {number} min The lowest tick, at or below the lowest value.
31
+ * @property {number} max The highest tick, at or above the highest value.
32
+ * @property {number} step The distance between ticks: 1, 2 or 5 × 10ⁿ.
33
+ * @property {number[]} ticks Every tick from `min` to `max`, distinct and free of float noise
34
+ * (0.3, not 0.30000000000000004).
35
+ */
36
+
37
+ /**
38
+ * A linear scale over `[min, max]`, widened outwards to round ticks. A range of one value is
39
+ * widened to zero (or to one when the value is zero), so a flat series still sits on an axis;
40
+ * values that are not finite count as zero. Any finite bounds give a few distinct ticks: the step
41
+ * is never finer than the values can tell apart, and an outer tick a double cannot hold is the
42
+ * largest one it can.
43
+ * @param {number} min Lowest value.
44
+ * @param {number} max Highest value.
45
+ * @param {number} [count=5] About how many intervals the scale should have, 1 to 50.
46
+ * @returns {NiceScale}
47
+ */
48
+ export function niceScale(min, max, count = 5) {
49
+ let low = Number.isFinite(min) ? min : 0;
50
+ let high = Number.isFinite(max) ? max : 0;
51
+ if (low > high) [low, high] = [high, low];
52
+ if (low === high) {
53
+ if (low > 0) low = 0;
54
+ else if (low < 0) high = 0;
55
+ else high = 1;
56
+ }
57
+ const intervals = Math.min(MAX_INTERVALS, Math.max(1, Math.round(count) || 1));
58
+ // Halved, the span stays finite whatever the bounds: -1e308 to 1e308 is wider than a double.
59
+ // Neither can the step round away to nothing between two of the tiniest doubles.
60
+ const raw = Math.max(Number.MIN_VALUE, Math.min(Number.MAX_VALUE, ((high / 2 - low / 2) / intervals) * 2));
61
+ const finest = Math.max(Math.abs(low), Math.abs(high)) * PRECISION;
62
+ const step = niceStep(Math.max(raw, finest));
63
+ const exponent = Math.floor(Math.log10(step) + EPSILON);
64
+ /** @param {number} index @returns {number} */
65
+ const tickAt = (index) => tickValue(index * step, exponent);
66
+ let first = Math.floor(low / step + EPSILON);
67
+ let last = Math.ceil(high / step - EPSILON);
68
+ // The quotients of very large values are rounded: the outer ticks must still enclose the data.
69
+ if (tickAt(first) - low > step * EPSILON) first -= 1;
70
+ if (high - tickAt(last) > step * EPSILON) last += 1;
71
+ if (last <= first) last = first + 1;
72
+ const ticks = [];
73
+ // A small counter, not the tick index itself: at 2e16 adding one no longer changes a double.
74
+ for (let offset = 0; offset <= last - first && offset < MAX_TICKS; offset += 1) {
75
+ const tick = tickAt(first + offset);
76
+ if (tick !== ticks[ticks.length - 1]) ticks.push(tick);
77
+ }
78
+ return { min: ticks[0], max: ticks[ticks.length - 1], step, ticks };
79
+ }
80
+
81
+ /**
82
+ * The round step nearest `raw`: 1, 2 or 5 × 10ⁿ, choosing at the geometric midpoints between
83
+ * them, as most axis libraries do.
84
+ * @param {number} raw Unrounded step, positive.
85
+ * @returns {number}
86
+ */
87
+ export function niceStep(raw) {
88
+ if (!(raw > 0) || !Number.isFinite(raw)) return 1;
89
+ const power = 10 ** Math.floor(Math.log10(raw));
90
+ if (!(power > 0)) return Number.MIN_VALUE;
91
+ const fraction = raw / power;
92
+ const factor = fraction >= Math.SQRT2 * 5 ? 10 : fraction >= Math.sqrt(10) ? 5 : fraction >= Math.SQRT2 ? 2 : 1;
93
+ const step = clean(factor * power);
94
+ return Number.isFinite(step) ? step : LARGEST_STEP;
95
+ }
96
+
97
+ /**
98
+ * Maps a value of `[min, max]` to a position of `[from, to]`; the range may run backwards, as a
99
+ * vertical axis does.
100
+ * @param {number} min Domain start.
101
+ * @param {number} max Domain end.
102
+ * @param {number} from Position of `min`.
103
+ * @param {number} to Position of `max`.
104
+ * @returns {(value: number) => number}
105
+ */
106
+ export function linearScale(min, max, from, to) {
107
+ const span = max - min || 1;
108
+ if (Number.isFinite(span)) return (value) => from + ((value - min) / span) * (to - from);
109
+ // A domain wider than a double holds (-1e308 to 1e308) is measured in halves.
110
+ const half = max / 2 - min / 2;
111
+ return (value) => from + ((value / 2 - min / 2) / half) * (to - from);
112
+ }
113
+
114
+ /**
115
+ * @typedef {Object} BarSlot
116
+ * @property {number} x Left edge.
117
+ * @property {number} width Width, never more than its slot.
118
+ */
119
+
120
+ /**
121
+ * Where the bars of one category go: `count` series side by side across the middle 80% of the
122
+ * band, each bar 90% of its slot (at least one unit where the slot has room) and at most
123
+ * `maxWidth` wide, the group centred in the band. A bar never leaves its slot, so in a band too
124
+ * narrow for whole pixels the bars grow thin rather than paint over each other.
125
+ * @param {number} start Left edge of the band.
126
+ * @param {number} band Width of the band.
127
+ * @param {number} count Series in the group, at least 1.
128
+ * @param {number} [maxWidth=Infinity] Widest a bar may be.
129
+ * @returns {BarSlot[]}
130
+ */
131
+ export function barSlots(start, band, count, maxWidth = Infinity) {
132
+ const series = Math.max(1, Math.floor(count) || 1);
133
+ const slot = Math.min((band * 0.8) / series, maxWidth / 0.9);
134
+ const width = Math.max(0, Math.min(slot, Math.max(1, slot * 0.9)));
135
+ const left = start + (band - slot * series) / 2;
136
+ return Array.from({ length: series }, (_, index) => ({ x: left + index * slot + (slot - width) / 2, width }));
137
+ }
138
+
139
+ /**
140
+ * Every how many categories a label is written so that none overlaps the next: 1 when the
141
+ * widest label and a gap fit in one band, more as bands get narrow.
142
+ * @param {number} widest Width of the widest label.
143
+ * @param {number} band Width of one category.
144
+ * @param {number} [gap=0] Least space between two labels.
145
+ * @returns {number} A whole number, at least 1.
146
+ */
147
+ export function labelStep(widest, band, gap = 0) {
148
+ if (!(band > 0)) return 1;
149
+ return Math.max(1, Math.ceil((Math.max(0, widest) + Math.max(0, gap)) / band - EPSILON));
150
+ }
151
+
152
+ /**
153
+ * A polyline through the points, broken where a point is missing: each run of points starts a
154
+ * new subpath, so a gap in the data is a gap in the line.
155
+ * @param {Array<[number, number]|null>} points Positions in order; null where there is no value.
156
+ * @returns {string} SVG path data; empty for no points.
157
+ */
158
+ export function linePath(points) {
159
+ let path = '';
160
+ let open = false;
161
+ for (const point of points) {
162
+ if (!point) {
163
+ open = false;
164
+ continue;
165
+ }
166
+ path += `${open ? 'L' : 'M'}${num(point[0])} ${num(point[1])}`;
167
+ open = true;
168
+ }
169
+ return path;
170
+ }
171
+
172
+ /**
173
+ * @typedef {Object} ArcSlice
174
+ * @property {number} index Position of the value in the list.
175
+ * @property {number} value The value.
176
+ * @property {number} share The value's part of the whole, 0 to 1.
177
+ * @property {number} start Start angle.
178
+ * @property {number} end End angle.
179
+ */
180
+
181
+ /**
182
+ * The slices of a pie: one per positive value, in order clockwise from twelve o'clock, each
183
+ * sweeping its share of the circle. Zero, negative and non-finite values have no slice. With two
184
+ * slices or more, each gives up `padAngle` (half at either edge, never more than half its sweep)
185
+ * so neighbours stand apart whatever lies behind the chart. Shares are taken relative to the
186
+ * largest value, so values whose sum a double cannot hold (1e308 twice) still divide the circle.
187
+ * @param {unknown[]} values Values.
188
+ * @param {number} [padAngle=0] Gap between slices.
189
+ * @returns {ArcSlice[]} Empty when no value is positive.
190
+ */
191
+ export function arcSlices(values, padAngle = 0) {
192
+ const shown = values
193
+ .map((value, index) => ({ index, value: typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : 0 }))
194
+ .filter((entry) => entry.value > 0);
195
+ const largest = shown.reduce((most, entry) => Math.max(most, entry.value), 0);
196
+ if (!(largest > 0)) return [];
197
+ const total = shown.reduce((sum, entry) => sum + entry.value / largest, 0);
198
+ const pad = shown.length > 1 ? Math.max(0, padAngle) : 0;
199
+ let angle = 0;
200
+ return shown.map(({ index, value }) => {
201
+ const share = value / largest / total;
202
+ const sweep = share * TAU;
203
+ const start = angle;
204
+ angle += sweep;
205
+ const inset = Math.min(pad, sweep / 2) / 2;
206
+ return { index, value, share, start: start + inset, end: angle - inset };
207
+ });
208
+ }
209
+
210
+ /**
211
+ * @typedef {Object} Ring
212
+ * @property {number} outer Outer radius.
213
+ * @property {number} inner Inner radius; 0 for the centre of a pie.
214
+ */
215
+
216
+ /**
217
+ * The rings of a pie or doughnut with several datasets, outermost first: equal thickness between
218
+ * `radius` and the hole, `gap` apart. The gap gives up at most half a ring's share of the radius,
219
+ * so however many datasets there are, each keeps a ring of its own.
220
+ * @param {number} count Rings, at least 1.
221
+ * @param {number} radius Outer radius of the outermost ring.
222
+ * @param {number} [hole=0] Radius of the hole as a fraction of `radius`: 0 for a pie.
223
+ * @param {number} [gap=0] Space between neighbouring rings.
224
+ * @returns {Ring[]}
225
+ */
226
+ export function ringRadii(count, radius, hole = 0, gap = 0) {
227
+ const rings = Math.max(1, Math.floor(count) || 1);
228
+ const outermost = Math.max(0, radius);
229
+ const innermost = outermost * Math.min(1, Math.max(0, hole));
230
+ const thickness = (outermost - innermost) / rings;
231
+ const space = Math.min(Math.max(0, gap), thickness / 2);
232
+ return Array.from({ length: rings }, (_, index) => {
233
+ const outer = outermost - index * thickness;
234
+ const inner = index === rings - 1 ? innermost : outer - thickness + space;
235
+ return { outer, inner };
236
+ });
237
+ }
238
+
239
+ /**
240
+ * The outline of a slice: a wedge from the centre when `inner` is 0, a band of a ring otherwise.
241
+ * A sweep of the whole circle is drawn as two half circles (an arc command cannot close on its
242
+ * own start), the hole of a ring the other way round so the default fill rule leaves it empty.
243
+ * @param {number} cx Centre x.
244
+ * @param {number} cy Centre y.
245
+ * @param {number} outer Outer radius.
246
+ * @param {number} inner Inner radius.
247
+ * @param {number} start Start angle.
248
+ * @param {number} end End angle.
249
+ * @returns {string} SVG path data; empty when there is nothing to draw.
250
+ */
251
+ export function arcPath(cx, cy, outer, inner, start, end) {
252
+ const sweep = end - start;
253
+ if (!(sweep > 0) || !(outer > 0)) return '';
254
+ const hole = Math.max(0, Math.min(inner, outer));
255
+ if (sweep >= TAU - EPSILON) {
256
+ const circle = (radius, clockwise) => {
257
+ const r = num(radius);
258
+ return `M${num(cx)} ${num(cy - radius)}A${r} ${r} 0 1 ${clockwise} ${num(cx)} ${num(cy + radius)}`
259
+ + `A${r} ${r} 0 1 ${clockwise} ${num(cx)} ${num(cy - radius)}Z`;
260
+ };
261
+ return circle(outer, 1) + (hole > 0 ? circle(hole, 0) : '');
262
+ }
263
+ const large = sweep > Math.PI ? 1 : 0;
264
+ const [x0, y0] = polar(cx, cy, outer, start);
265
+ const [x1, y1] = polar(cx, cy, outer, end);
266
+ let path = `M${num(x0)} ${num(y0)}A${num(outer)} ${num(outer)} 0 ${large} 1 ${num(x1)} ${num(y1)}`;
267
+ if (hole > 0) {
268
+ const [x2, y2] = polar(cx, cy, hole, end);
269
+ const [x3, y3] = polar(cx, cy, hole, start);
270
+ path += `L${num(x2)} ${num(y2)}A${num(hole)} ${num(hole)} 0 ${large} 0 ${num(x3)} ${num(y3)}`;
271
+ } else {
272
+ path += `L${num(cx)} ${num(cy)}`;
273
+ }
274
+ return `${path}Z`;
275
+ }
276
+
277
+ /**
278
+ * The point at `radius` from the centre, `angle` clockwise from twelve o'clock.
279
+ * @param {number} cx @param {number} cy @param {number} radius @param {number} angle
280
+ * @returns {[number, number]}
281
+ */
282
+ export function polar(cx, cy, radius, angle) {
283
+ return [cx + radius * Math.sin(angle), cy - radius * Math.cos(angle)];
284
+ }
285
+
286
+ /**
287
+ * Significant digits a tick label needs so that no two ticks read alike: enough for the largest
288
+ * tick's magnitude down to the step's, whatever unit a compact number format abbreviates to.
289
+ * @param {number[]} ticks Ticks of a `niceScale()`.
290
+ * @param {number} step Its step.
291
+ * @returns {number} 1 to 21.
292
+ */
293
+ export function tickPrecision(ticks, step) {
294
+ const largest = ticks.reduce((most, tick) => Math.max(most, Math.abs(tick)), 0);
295
+ if (!(largest > 0) || !(step > 0)) return 1;
296
+ const digits = Math.floor(Math.log10(largest) + EPSILON) - Math.floor(Math.log10(step) + EPSILON) + 1;
297
+ return Math.min(21, Math.max(1, digits));
298
+ }
299
+
300
+ /** @param {number} value @returns {number} The value without float noise. */
301
+ function clean(value) {
302
+ return Number(value.toPrecision(12));
303
+ }
304
+
305
+ /**
306
+ * A tick rounded to the digits its step has, and no further: 1e12 + 0.2 keeps its fraction, 0.1 × 3
307
+ * loses its noise. A tick past the largest double is the largest double.
308
+ * @param {number} value The tick as multiplied out.
309
+ * @param {number} exponent The power of ten of the step's one significant digit.
310
+ * @returns {number}
311
+ */
312
+ function tickValue(value, exponent) {
313
+ if (value === 0) return 0;
314
+ if (!Number.isFinite(value)) return value > 0 ? Number.MAX_VALUE : -Number.MAX_VALUE;
315
+ const digits = Math.floor(Math.log10(Math.abs(value)) + EPSILON) - exponent + 1;
316
+ return Number(value.toPrecision(Math.min(100, Math.max(1, digits))));
317
+ }
318
+
319
+ /** @param {number} value @returns {string} The value to two decimals, as short as it goes. */
320
+ function num(value) {
321
+ const rounded = Math.round(value * 100) / 100;
322
+ return String(rounded === 0 ? 0 : rounded);
323
+ }
@@ -1,5 +1,5 @@
1
1
  import { Component } from '../../core/component.js';
2
- import { h } from '../../core/dom.js';
2
+ import { h, restoreTarget, snapshotTarget } from '../../core/dom.js';
3
3
  import { ICON_SIZE, icon } from '../../core/icons.js';
4
4
 
5
5
  /**
@@ -37,7 +37,7 @@ export class CheckButton extends Component {
37
37
  }
38
38
 
39
39
  this._createdRoot = created;
40
- this._original = created ? null : snapshot(root);
40
+ this._original = created ? null : snapshotTarget(root);
41
41
  this._checked = Boolean(this.options.checked);
42
42
  this._disabled = Boolean(this.options.disabled);
43
43
  this._labels = normalizeLabels(this.options.label);
@@ -126,7 +126,7 @@ export class CheckButton extends Component {
126
126
  if (this._cleaned) return;
127
127
  this._cleaned = true;
128
128
  super.destroy();
129
- if (!this._createdRoot && this._original) restore(this.el, this._original);
129
+ if (!this._createdRoot && this._original) restoreTarget(this.el, this._original);
130
130
  }
131
131
 
132
132
  /** @returns {void} */
@@ -150,18 +150,3 @@ function normalizeLabels(label) {
150
150
  }
151
151
  return { on: String(label ?? ''), off: String(label ?? '') };
152
152
  }
153
-
154
- /** @param {Element} element @returns {{attributes: [string, string][], children: Node[]}} */
155
- function snapshot(element) {
156
- return {
157
- attributes: Array.from(element.attributes, (attribute) => [attribute.name, attribute.value]),
158
- children: Array.from(element.childNodes)
159
- };
160
- }
161
-
162
- /** @param {Element} element @param {{attributes: [string, string][], children: Node[]}} state */
163
- function restore(element, state) {
164
- for (const attribute of Array.from(element.attributes)) element.removeAttribute(attribute.name);
165
- for (const [name, value] of state.attributes) element.setAttribute(name, value);
166
- element.replaceChildren(...state.children);
167
- }
@@ -57,7 +57,7 @@ export class Checklist extends Component {
57
57
  render() {
58
58
  // Instance state initialized here because render() runs inside the base
59
59
  // constructor, before class-field initializers would run (and clobber it).
60
- this._items = []; this._visibleItems = []; this._checked = new Set(); this._query = ''; this._loadSequence = 0; this._createdRoot = false; this._active = true; this._originalChildren = []; this._originalAttributes = new Map();
60
+ this._items = []; this._visibleItems = []; this._checked = new Set(); this._pending = null; this._query = ''; this._loadSequence = 0; this._createdRoot = false; this._active = true; this._originalChildren = []; this._originalAttributes = new Map();
61
61
  this._createdRoot = this.el === null;
62
62
  const root = /** @type {HTMLElement} */ (this.el ?? h('div'));
63
63
  this.el = root;
@@ -117,7 +117,9 @@ export class Checklist extends Component {
117
117
  }
118
118
 
119
119
  /**
120
- * Replaces items and derives checked state from `checkedKey` and `defaultChecked`.
120
+ * Replaces items and derives checked state from `checkedKey` and `defaultChecked` — unless
121
+ * `setValues()` asked for IDs the earlier items did not have yet, in which case the requested
122
+ * values are checked instead.
121
123
  * @param {ChecklistItem[]} items New items.
122
124
  * @returns {this}
123
125
  */
@@ -157,37 +159,46 @@ export class Checklist extends Component {
157
159
  return this._disabled;
158
160
  }
159
161
 
160
- /** Returns checked IDs in item order. @returns {unknown[]} */
162
+ /**
163
+ * Returns checked IDs in item order, followed by requested IDs whose items have not been loaded
164
+ * yet (see `setValues()`).
165
+ * @returns {unknown[]}
166
+ */
161
167
  getValues() {
162
- return this._items
168
+ const checked = this._items
163
169
  .map((item) => this._itemValue(item))
164
170
  .filter((value) => this._checked.has(value));
171
+ return this._pending ? [...checked, ...this._pending] : checked;
165
172
  }
166
173
 
167
174
  /**
168
- * Replaces the checked IDs.
175
+ * Replaces the checked IDs. IDs that none of the current items carries are kept as requested,
176
+ * and checked as soon as items carrying them arrive — through `setItems()` or the `load`
177
+ * loader — so a value set before the items load is not lost.
169
178
  * @param {Iterable<unknown>|unknown[]} ids Checked item IDs.
170
179
  * @returns {this}
171
180
  * @fires Checklist#change
172
181
  */
173
182
  setValues(ids) {
174
183
  const requested = new Set(ids == null ? [] : Array.from(ids));
175
- const next = new Set(this._items
176
- .map((item) => this._itemValue(item))
177
- .filter((value) => requested.has(value)));
178
- this._replaceChecked(next);
184
+ const known = new Set(this._items.map((item) => this._itemValue(item)));
185
+ const next = new Set([...known].filter((value) => requested.has(value)));
186
+ const missing = [...requested].filter((value) => !known.has(value));
187
+ // Before any item exists the request stands for the items still to come — an empty one too —
188
+ // in place of their own checked flags.
189
+ this._replaceChecked(next, missing.length || this._items.length === 0 ? missing : null);
179
190
  return this;
180
191
  }
181
192
 
182
193
  /** Checks every item. @returns {this} @fires Checklist#change */
183
194
  checkAll() {
184
- this._replaceChecked(new Set(this._items.map((item) => this._itemValue(item))));
195
+ this._replaceChecked(new Set(this._items.map((item) => this._itemValue(item))), null);
185
196
  return this;
186
197
  }
187
198
 
188
199
  /** Unchecks every item. @returns {this} @fires Checklist#change */
189
200
  uncheckAll() {
190
- this._replaceChecked(new Set());
201
+ this._replaceChecked(new Set(), null);
191
202
  return this;
192
203
  }
193
204
 
@@ -247,9 +258,18 @@ export class Checklist extends Component {
247
258
  /** @param {ChecklistItem[]} items @returns {void} */
248
259
  _replaceItems(items) {
249
260
  this._items = Array.isArray(items) ? items.slice() : [];
250
- this._checked = new Set(this._items
251
- .filter((item) => Boolean(this._initialChecked(item)))
252
- .map((item) => this._itemValue(item)));
261
+ if (this._pending !== null) {
262
+ // A value requested before its items existed: it decides what is checked, not checkedKey.
263
+ const wanted = new Set([...this._checked, ...this._pending]);
264
+ const known = new Set(this._items.map((item) => this._itemValue(item)));
265
+ this._checked = new Set([...known].filter((value) => wanted.has(value)));
266
+ const pending = this._pending.filter((value) => !known.has(value));
267
+ this._pending = pending.length ? pending : null;
268
+ } else {
269
+ this._checked = new Set(this._items
270
+ .filter((item) => Boolean(this._initialChecked(item)))
271
+ .map((item) => this._itemValue(item)));
272
+ }
253
273
  this._visibleItems = matchItems(this._items, this._query, [this.options.labelKey]);
254
274
  this._renderItems();
255
275
  }
@@ -295,9 +315,18 @@ export class Checklist extends Component {
295
315
  return label == null || label === '' ? this._message('checklist.label', 'Checklist') : String(label);
296
316
  }
297
317
 
298
- /** @param {Set<unknown>} next @returns {void} */
299
- _replaceChecked(next) {
300
- if (setsEqual(this._checked, next)) return;
318
+ /**
319
+ * @param {Set<unknown>} next
320
+ * @param {unknown[]|null} pending Requested IDs no item carries yet, or null when no request waits
321
+ * for items; an empty array is a request made before any item existed.
322
+ * @returns {void}
323
+ */
324
+ _replaceChecked(next, pending) {
325
+ const nextPending = pending;
326
+ const pendingChanged = !setsEqual(new Set(this._pending ?? []), new Set(nextPending ?? []));
327
+ const unchanged = setsEqual(this._checked, next) && !pendingChanged;
328
+ this._pending = nextPending;
329
+ if (unchanged) return;
301
330
  this._checked = next;
302
331
  this._renderItems();
303
332
  this.emit('change', { values: this.getValues() });
@@ -21,7 +21,10 @@ export function registerChecklistFieldAdapter() {
21
21
  set: (value) => {
22
22
  setting = true;
23
23
  try {
24
- checklist.setValues(Array.isArray(value) ? value : []);
24
+ // An array is the value, an empty one included; anything else — the Field's '' when no
25
+ // value was given — clears what is shown and leaves items still to load their own flags.
26
+ if (Array.isArray(value)) checklist.setValues(value);
27
+ else checklist.uncheckAll();
25
28
  } finally {
26
29
  setting = false;
27
30
  }
@@ -66,3 +66,36 @@
66
66
  .zx-code-editor[data-disabled="true"] {
67
67
  opacity: 0.6;
68
68
  }
69
+
70
+ /* The error state, whoever declares it: a standalone editor through setHighlight(), or a Field
71
+ marking the textarea it labels. Either way the frame says so, as a field's control does. */
72
+ .zx-code-editor[data-state="danger"],
73
+ .zx-code-editor:has(.zx-code-editor__input[aria-invalid="true"]) {
74
+ border-color: var(--zx-color-danger);
75
+ }
76
+
77
+ /* The message of a standalone editor: a Field's highlight text, set under the source. */
78
+ .zx-code-editor__highlight {
79
+ padding: var(--zx-space-2) var(--zx-space-3);
80
+ border-block-start: 1px solid var(--zx-color-border);
81
+ color: var(--zx-color-text-muted);
82
+ font-size: var(--zx-text-sm);
83
+ overflow-wrap: anywhere;
84
+ }
85
+
86
+ .zx-code-editor__highlight[hidden] {
87
+ display: none;
88
+ }
89
+
90
+ .zx-code-editor[data-state="danger"] .zx-code-editor__highlight {
91
+ border-block-start-color: var(--zx-color-danger);
92
+ color: var(--zx-color-danger);
93
+ }
94
+
95
+ .zx-code-editor[data-state="warning"] .zx-code-editor__highlight {
96
+ color: var(--zx-color-warning);
97
+ }
98
+
99
+ .zx-code-editor[data-state="success"] .zx-code-editor__highlight {
100
+ color: var(--zx-color-success);
101
+ }