@grafctory/clay-widgets 0.0.0-stage → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +46 -2
  3. package/dist/content/empty.css +107 -0
  4. package/dist/content/empty.d.ts +40 -0
  5. package/dist/content/empty.d.ts.map +1 -0
  6. package/dist/content/empty.js +42 -0
  7. package/dist/content/empty.js.map +1 -0
  8. package/dist/content/heading.css +34 -0
  9. package/dist/content/heading.d.ts +45 -0
  10. package/dist/content/heading.d.ts.map +1 -0
  11. package/dist/content/heading.js +49 -0
  12. package/dist/content/heading.js.map +1 -0
  13. package/dist/content/image.css +176 -0
  14. package/dist/content/image.d.ts +71 -0
  15. package/dist/content/image.d.ts.map +1 -0
  16. package/dist/content/image.js +63 -0
  17. package/dist/content/image.js.map +1 -0
  18. package/dist/content/infobox.css +186 -0
  19. package/dist/content/infobox.d.ts +72 -0
  20. package/dist/content/infobox.d.ts.map +1 -0
  21. package/dist/content/infobox.js +63 -0
  22. package/dist/content/infobox.js.map +1 -0
  23. package/dist/content/pill.css +76 -0
  24. package/dist/content/pill.d.ts +57 -0
  25. package/dist/content/pill.d.ts.map +1 -0
  26. package/dist/content/pill.js +48 -0
  27. package/dist/content/pill.js.map +1 -0
  28. package/dist/content/text.css +44 -0
  29. package/dist/content/text.d.ts +30 -0
  30. package/dist/content/text.d.ts.map +1 -0
  31. package/dist/content/text.js +42 -0
  32. package/dist/content/text.js.map +1 -0
  33. package/dist/controls/button.css +469 -0
  34. package/dist/controls/button.d.ts +116 -0
  35. package/dist/controls/button.d.ts.map +1 -0
  36. package/dist/controls/button.js +61 -0
  37. package/dist/controls/button.js.map +1 -0
  38. package/dist/controls/checkbox.css +23 -0
  39. package/dist/controls/checkbox.d.ts +54 -0
  40. package/dist/controls/checkbox.d.ts.map +1 -0
  41. package/dist/controls/checkbox.js +49 -0
  42. package/dist/controls/checkbox.js.map +1 -0
  43. package/dist/controls/choice.css +288 -0
  44. package/dist/controls/choice.d.ts +63 -0
  45. package/dist/controls/choice.d.ts.map +1 -0
  46. package/dist/controls/choice.js +52 -0
  47. package/dist/controls/choice.js.map +1 -0
  48. package/dist/controls/fieldset.css +37 -0
  49. package/dist/controls/fieldset.d.ts +49 -0
  50. package/dist/controls/fieldset.d.ts.map +1 -0
  51. package/dist/controls/fieldset.js +51 -0
  52. package/dist/controls/fieldset.js.map +1 -0
  53. package/dist/controls/form.css +50 -0
  54. package/dist/controls/form.d.ts +64 -0
  55. package/dist/controls/form.d.ts.map +1 -0
  56. package/dist/controls/form.js +62 -0
  57. package/dist/controls/form.js.map +1 -0
  58. package/dist/controls/input.css +57 -0
  59. package/dist/controls/input.d.ts +120 -0
  60. package/dist/controls/input.d.ts.map +1 -0
  61. package/dist/controls/input.js +78 -0
  62. package/dist/controls/input.js.map +1 -0
  63. package/dist/controls/label.css +73 -0
  64. package/dist/controls/label.d.ts +76 -0
  65. package/dist/controls/label.d.ts.map +1 -0
  66. package/dist/controls/label.js +73 -0
  67. package/dist/controls/label.js.map +1 -0
  68. package/dist/controls/radio.css +23 -0
  69. package/dist/controls/radio.d.ts +60 -0
  70. package/dist/controls/radio.d.ts.map +1 -0
  71. package/dist/controls/radio.js +50 -0
  72. package/dist/controls/radio.js.map +1 -0
  73. package/dist/controls/select.css +37 -0
  74. package/dist/controls/select.d.ts +62 -0
  75. package/dist/controls/select.d.ts.map +1 -0
  76. package/dist/controls/select.js +59 -0
  77. package/dist/controls/select.js.map +1 -0
  78. package/dist/controls/switch.css +154 -0
  79. package/dist/controls/switch.d.ts +44 -0
  80. package/dist/controls/switch.d.ts.map +1 -0
  81. package/dist/controls/switch.js +48 -0
  82. package/dist/controls/switch.js.map +1 -0
  83. package/dist/controls/textarea.css +50 -0
  84. package/dist/controls/textarea.d.ts +97 -0
  85. package/dist/controls/textarea.d.ts.map +1 -0
  86. package/dist/controls/textarea.js +75 -0
  87. package/dist/controls/textarea.js.map +1 -0
  88. package/dist/glyphs/icon.core.d.ts +52 -0
  89. package/dist/glyphs/icon.core.d.ts.map +1 -0
  90. package/dist/glyphs/icon.core.js +67 -0
  91. package/dist/glyphs/icon.core.js.map +1 -0
  92. package/dist/glyphs/icon.css +32 -0
  93. package/dist/glyphs/icon.d.ts +152 -0
  94. package/dist/glyphs/icon.d.ts.map +1 -0
  95. package/dist/glyphs/icon.js +167 -0
  96. package/dist/glyphs/icon.js.map +1 -0
  97. package/dist/glyphs/icon.md +76 -0
  98. package/dist/glyphs/logo.css +73 -0
  99. package/dist/glyphs/logo.d.ts +27 -0
  100. package/dist/glyphs/logo.d.ts.map +1 -0
  101. package/dist/glyphs/logo.js +49 -0
  102. package/dist/glyphs/logo.js.map +1 -0
  103. package/dist/index.d.ts +65 -0
  104. package/dist/index.d.ts.map +1 -0
  105. package/dist/index.js +95 -0
  106. package/dist/index.js.map +1 -0
  107. package/dist/layouts/card.css +166 -0
  108. package/dist/layouts/card.d.ts +69 -0
  109. package/dist/layouts/card.d.ts.map +1 -0
  110. package/dist/layouts/card.js +57 -0
  111. package/dist/layouts/card.js.map +1 -0
  112. package/dist/layouts/stack.css +58 -0
  113. package/dist/layouts/stack.d.ts +64 -0
  114. package/dist/layouts/stack.d.ts.map +1 -0
  115. package/dist/layouts/stack.js +69 -0
  116. package/dist/layouts/stack.js.map +1 -0
  117. package/dist/layouts/strip.css +58 -0
  118. package/dist/layouts/strip.d.ts +72 -0
  119. package/dist/layouts/strip.d.ts.map +1 -0
  120. package/dist/layouts/strip.js +73 -0
  121. package/dist/layouts/strip.js.map +1 -0
  122. package/dist/layouts/tabs.core.d.ts +73 -0
  123. package/dist/layouts/tabs.core.d.ts.map +1 -0
  124. package/dist/layouts/tabs.core.js +65 -0
  125. package/dist/layouts/tabs.core.js.map +1 -0
  126. package/dist/layouts/tabs.css +260 -0
  127. package/dist/layouts/tabs.d.ts +57 -0
  128. package/dist/layouts/tabs.d.ts.map +1 -0
  129. package/dist/layouts/tabs.js +128 -0
  130. package/dist/layouts/tabs.js.map +1 -0
  131. package/dist/layouts/tree.css +138 -0
  132. package/dist/layouts/tree.d.ts +46 -0
  133. package/dist/layouts/tree.d.ts.map +1 -0
  134. package/dist/layouts/tree.js +69 -0
  135. package/dist/layouts/tree.js.map +1 -0
  136. package/dist/navigation/link.css +229 -0
  137. package/dist/navigation/link.d.ts +89 -0
  138. package/dist/navigation/link.d.ts.map +1 -0
  139. package/dist/navigation/link.js +91 -0
  140. package/dist/navigation/link.js.map +1 -0
  141. package/dist/navigation/path.css +122 -0
  142. package/dist/navigation/path.d.ts +42 -0
  143. package/dist/navigation/path.d.ts.map +1 -0
  144. package/dist/navigation/path.js +49 -0
  145. package/dist/navigation/path.js.map +1 -0
  146. package/dist/navigation/toc.core.d.ts +111 -0
  147. package/dist/navigation/toc.core.d.ts.map +1 -0
  148. package/dist/navigation/toc.core.js +60 -0
  149. package/dist/navigation/toc.core.js.map +1 -0
  150. package/dist/navigation/toc.css +53 -0
  151. package/dist/navigation/toc.d.ts +112 -0
  152. package/dist/navigation/toc.d.ts.map +1 -0
  153. package/dist/navigation/toc.js +321 -0
  154. package/dist/navigation/toc.js.map +1 -0
  155. package/dist/scopes/guard.css +26 -0
  156. package/dist/scopes/guard.d.ts +37 -0
  157. package/dist/scopes/guard.d.ts.map +1 -0
  158. package/dist/scopes/guard.js +60 -0
  159. package/dist/scopes/guard.js.map +1 -0
  160. package/dist/scopes/style.css +26 -0
  161. package/dist/scopes/style.d.ts +68 -0
  162. package/dist/scopes/style.d.ts.map +1 -0
  163. package/dist/scopes/style.js +108 -0
  164. package/dist/scopes/style.js.map +1 -0
  165. package/dist/shells/tool.css +778 -0
  166. package/dist/shells/tool.d.ts +164 -0
  167. package/dist/shells/tool.d.ts.map +1 -0
  168. package/dist/shells/tool.js +251 -0
  169. package/dist/shells/tool.js.map +1 -0
  170. package/dist/signals/more.css +42 -0
  171. package/dist/signals/more.d.ts +28 -0
  172. package/dist/signals/more.d.ts.map +1 -0
  173. package/dist/signals/more.js +61 -0
  174. package/dist/signals/more.js.map +1 -0
  175. package/dist/signals/note.css +221 -0
  176. package/dist/signals/note.d.ts +83 -0
  177. package/dist/signals/note.d.ts.map +1 -0
  178. package/dist/signals/note.js +72 -0
  179. package/dist/signals/note.js.map +1 -0
  180. package/dist/signals/toasts.css +463 -0
  181. package/dist/signals/toasts.d.ts +68 -0
  182. package/dist/signals/toasts.d.ts.map +1 -0
  183. package/dist/signals/toasts.js +160 -0
  184. package/dist/signals/toasts.js.map +1 -0
  185. package/package.json +331 -4
@@ -0,0 +1,112 @@
1
+ import { type ComponentChildren } from "preact";
2
+ import "./toc.css";
3
+ /**
4
+ * An entry of a table of contents.
5
+ *
6
+ * Either a link to a section, or a group label gathering the entries under it without leading anywhere itself.
7
+ */
8
+ export interface TOCEntry {
9
+ /**
10
+ * What the entry reads as. A plain string label offers its full wording as a tooltip, for a reader of an outline
11
+ * whose labels are clipped, while a label given as markup has to carry a tooltip of its own where one is needed.
12
+ */
13
+ readonly label: ComponentChildren;
14
+ /**
15
+ * The location the entry links to; a fragment naming an element on the page (`#colours`) makes the entry one the
16
+ * outline marks while the reader is in its section. A group label leading nowhere if omitted.
17
+ */
18
+ readonly href?: string;
19
+ /**
20
+ * The browsing context the entry opens its location in, such as `_blank` for a screen of its own in a new tab,
21
+ * which leaves the page holding the outline in place; the current one if omitted.
22
+ */
23
+ readonly target?: string;
24
+ /**
25
+ * The entries nested under this one, in page order, as an array of entries or keyed by labels; none if omitted.
26
+ */
27
+ readonly entries?: readonly TOCEntry[] | TOCEntries;
28
+ }
29
+ /**
30
+ * Table of contents entries keyed by labels.
31
+ *
32
+ * Maps each plain string label to the location it links to, or to the entries gathered under it for a group label
33
+ * leading nowhere, so an outline is written as a single object literal. Entries are listed in the order their labels
34
+ * appear in the object, but labels reading as non-negative integers, such as `2026`, always come first in ascending
35
+ * order. An outline needing them elsewhere, labels that are not plain strings, or links opening in another browsing
36
+ * context take {@link TOCEntry} values instead, which mix freely with keyed entries at any depth.
37
+ */
38
+ export type TOCEntries = {
39
+ readonly [label: string]: string | TOCEntries;
40
+ };
41
+ /**
42
+ * Creates a table of contents.
43
+ *
44
+ * Lists the entries given, in order, as a navigation landmark of nested lists, styled and highlighted by the outline
45
+ * rules of the design system alone, so it reads as every other outline an app built on it shows. Nothing at all is
46
+ * rendered for an empty outline, leaving no empty landmark behind for assistive technology.
47
+ *
48
+ * Unless told to wrap, every label, folded groups included, stays on a single line, so a long identifier never breaks
49
+ * midway or widens the column: a label running past the column is cut short with an ellipsis. Its full wording is
50
+ * still read out by assistive technology, and a plain string label shows it as a tooltip too.
51
+ *
52
+ * While the page scrolls, the link whose section the reader is in is marked as the current location, which the design
53
+ * system sets in the strong accent and weight and assistive technology reads as such. The section marked is the one
54
+ * at the top of the view: the first starting in its top third, or failing that the last scrolled past the top edge.
55
+ * Once the page is scrolled to its end, it is the last one in view, so a short closing section is still reached. No
56
+ * link is marked while the first section starts below the view, and short of the end of the page the mark moves only
57
+ * as a section start crosses the top edge of the view or the bottom of its top third, so reading on holds it steady.
58
+ * Only links naming an element on the page by fragment take part. Any other link is listed but never marked, as it
59
+ * leads away from the page, to no section the reader could ever scroll into from where they are.
60
+ *
61
+ * A section the reader asks for, by following a link to it or by arriving with a fragment naming it, is marked at once
62
+ * and stays marked while the page scrolls to it, smoothly or at once, until the reader scrolls on their own with the
63
+ * wheel, by touch, with the pointer or from the keyboard; after that, it stays marked for as long as its start is in
64
+ * view, and once its start has left the view, the scroll position alone decides the mark, even when the section comes
65
+ * back into view later on. Any link to a section counts, in the outline or elsewhere on the page, shadow trees
66
+ * included. A link opening a new browsing context or a download, a click with a modifier key, and a click cancelled by
67
+ * a handler on the page all leave the page where it stands, so they leave the mark alone as well.
68
+ *
69
+ * A section named on arrival is scrolled into view by the outline, even where the page renders its sections after
70
+ * loading or scrolls them in a box of its own. The fragment stays in the location while the mark is on the section it
71
+ * names, or on the section holding the element it names, such as a table or a figure: the last section starting before
72
+ * that element. Once the mark leaves that section, for another one or for none, the outline drops the fragment. The
73
+ * rest of the address is kept and no history entry is added, so an address shared or bookmarked later never names a
74
+ * place the reader has left. A fragment naming no element, or an element ahead of every section, is left alone.
75
+ *
76
+ * The outline follows the box its sections scroll in, whatever lays the page out: the nearest scrolling ancestor of
77
+ * the first section on the page, such as the main column of a {@link @grafctory/clay-widgets!tool.Tool tool}, or
78
+ * the document where no ancestor scrolls. The view is measured on the part of that box left in view, short of its
79
+ * scroll padding, so a header standing over the box is not counted as room to read in.
80
+ *
81
+ * @param options The widget configuration
82
+ *
83
+ * @returns The table of contents, or nothing for an empty outline
84
+ */
85
+ export declare function TOC({ compact, wrap, name, entries }: {
86
+ /**
87
+ * Whether top-level groups fold like an accordion, keeping a long outline down to the group the reader is in.
88
+ *
89
+ * Each top-level group without a link of its own folds behind its label, and only one group is open at a time. The
90
+ * group holding the section the reader is in opens as they reach it, and any other opens on demand. A group with a
91
+ * link stays listed in full, since its label already leads somewhere. Every group is listed in full if omitted.
92
+ */
93
+ compact?: boolean;
94
+ /**
95
+ * Whether long labels wrap across lines, so each is shown in full, as fits an outline of prose headings. A word too
96
+ * long for the column breaks wherever needed. By default each label is clipped to a single line with an ellipsis,
97
+ * so a long identifier never breaks midway or widens the column, as fits a narrow sidebar of reference links.
98
+ */
99
+ wrap?: boolean;
100
+ /**
101
+ * The accessible name of the outline, such as `Contents`, telling it apart from other navigation landmarks on the
102
+ * page, as in a sidebar holding several outlines; unnamed if omitted, for a page with no other such landmark.
103
+ */
104
+ name?: string;
105
+ /**
106
+ * The entries of the outline, in page order, either as an array of entries or as entries keyed by their labels.
107
+ */
108
+ entries: readonly TOCEntry[] | TOCEntries;
109
+ }): import("preact").VNode<{
110
+ wrap: boolean;
111
+ }> | null;
112
+ //# sourceMappingURL=toc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toc.d.ts","sourceRoot":"","sources":["../../src/navigation/toc.tsx"],"names":[],"mappings":"AA2BA,OAAO,EAAE,KAAK,iBAAiB,EAAiB,MAAM,QAAQ,CAAC;AAG/D,OAAO,WAAW,CAAC;AAGnB;;;;GAIG;AACH,MAAM,WAAW,QAAQ;IAExB;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,iBAAiB,CAAC;IAElC;;;OAGG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAEvB;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,QAAQ,EAAE,GAAG,UAAU,CAAC;CAEpD;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,UAAU,GAAG;IAExB,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,UAAU,CAAA;CAE7C,CAAA;AAKD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,GAAG,CAAC,EAEnB,OAAe,EACf,IAAY,EAEZ,IAAI,EAEJ,OAAO,EAEP,EAAE;IAEF;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IAEjB;;;;OAIG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;IAEd;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb;;OAEG;IACH,OAAO,EAAE,SAAS,QAAQ,EAAE,GAAG,UAAU,CAAA;CAEzC;;UAwGA"}
@@ -0,0 +1,321 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "preact/jsx-runtime";
2
+ /*
3
+ * Copyright © 2026 Metreeca srl
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ /**
18
+ * Table of contents.
19
+ *
20
+ * Presents the outline of a long page as quiet navigation beside it, marking the section the reader is in as the page
21
+ * scrolls, so a reader sees where they stand and moves to any other section in one gesture.
22
+ *
23
+ * @module toc
24
+ */
25
+ import { useModel } from "@grafctory/clay/model";
26
+ import { isArray, isString, opt } from "@grafctory/core";
27
+ import { createElement } from "preact";
28
+ import { useEffect, useId } from "preact/hooks";
29
+ import { createTOC } from "./toc.core.js";
30
+ import "./toc.css";
31
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
32
+ /**
33
+ * Creates a table of contents.
34
+ *
35
+ * Lists the entries given, in order, as a navigation landmark of nested lists, styled and highlighted by the outline
36
+ * rules of the design system alone, so it reads as every other outline an app built on it shows. Nothing at all is
37
+ * rendered for an empty outline, leaving no empty landmark behind for assistive technology.
38
+ *
39
+ * Unless told to wrap, every label, folded groups included, stays on a single line, so a long identifier never breaks
40
+ * midway or widens the column: a label running past the column is cut short with an ellipsis. Its full wording is
41
+ * still read out by assistive technology, and a plain string label shows it as a tooltip too.
42
+ *
43
+ * While the page scrolls, the link whose section the reader is in is marked as the current location, which the design
44
+ * system sets in the strong accent and weight and assistive technology reads as such. The section marked is the one
45
+ * at the top of the view: the first starting in its top third, or failing that the last scrolled past the top edge.
46
+ * Once the page is scrolled to its end, it is the last one in view, so a short closing section is still reached. No
47
+ * link is marked while the first section starts below the view, and short of the end of the page the mark moves only
48
+ * as a section start crosses the top edge of the view or the bottom of its top third, so reading on holds it steady.
49
+ * Only links naming an element on the page by fragment take part. Any other link is listed but never marked, as it
50
+ * leads away from the page, to no section the reader could ever scroll into from where they are.
51
+ *
52
+ * A section the reader asks for, by following a link to it or by arriving with a fragment naming it, is marked at once
53
+ * and stays marked while the page scrolls to it, smoothly or at once, until the reader scrolls on their own with the
54
+ * wheel, by touch, with the pointer or from the keyboard; after that, it stays marked for as long as its start is in
55
+ * view, and once its start has left the view, the scroll position alone decides the mark, even when the section comes
56
+ * back into view later on. Any link to a section counts, in the outline or elsewhere on the page, shadow trees
57
+ * included. A link opening a new browsing context or a download, a click with a modifier key, and a click cancelled by
58
+ * a handler on the page all leave the page where it stands, so they leave the mark alone as well.
59
+ *
60
+ * A section named on arrival is scrolled into view by the outline, even where the page renders its sections after
61
+ * loading or scrolls them in a box of its own. The fragment stays in the location while the mark is on the section it
62
+ * names, or on the section holding the element it names, such as a table or a figure: the last section starting before
63
+ * that element. Once the mark leaves that section, for another one or for none, the outline drops the fragment. The
64
+ * rest of the address is kept and no history entry is added, so an address shared or bookmarked later never names a
65
+ * place the reader has left. A fragment naming no element, or an element ahead of every section, is left alone.
66
+ *
67
+ * The outline follows the box its sections scroll in, whatever lays the page out: the nearest scrolling ancestor of
68
+ * the first section on the page, such as the main column of a {@link @grafctory/clay-widgets!tool.Tool tool}, or
69
+ * the document where no ancestor scrolls. The view is measured on the part of that box left in view, short of its
70
+ * scroll padding, so a header standing over the box is not counted as room to read in.
71
+ *
72
+ * @param options The widget configuration
73
+ *
74
+ * @returns The table of contents, or nothing for an empty outline
75
+ */
76
+ export function TOC({ compact = false, wrap = false, name, entries }) {
77
+ const $entries = normalise(entries);
78
+ const sections = targets($entries);
79
+ const key = sections.join(" ");
80
+ const outline = useModel(() => createTOC({ sections }), [key]);
81
+ const group = useId(); // the name gathering the folded groups of this outline alone into one accordion
82
+ /*
83
+ * The section in view follows the scroll position and the location of the document, which no render owns, so the
84
+ * outline measures where each section stands as it mounts and whenever the page scrolls or the viewport is
85
+ * resized, takes the section the fragment names on arrival and whenever it changes, and lets a chosen section go as
86
+ * soon as the reader scrolls on their own. Once the mark leaves the section holding the element the fragment names,
87
+ * the fragment is dropped from the location. The model renders again only once the current section changes, so
88
+ * scrolling within a section costs nothing beyond measuring where the section starts stand.
89
+ */
90
+ useEffect(() => {
91
+ /*
92
+ * Events arrive between renders, and a transition starts from the state the render it was read from saw, so a
93
+ * scroll landing before the render a choice brought would follow the page from before the choice and undo it.
94
+ * Each event takes its transition on the outline the previous event left instead, which is the state the next
95
+ * render will show, so a choice and the scroll it sets off land in the order they happened.
96
+ */
97
+ let latest = outline; // ;(let) the outline as the events of this subscription have left it
98
+ // a fragment naming no section is left alone, as it may lead anywhere else on the page
99
+ const select = () => opt(fragment(location.hash), id => {
100
+ latest = latest.select(id);
101
+ });
102
+ const follow = (event) => opt(followed(event), id => setTimeout(() => {
103
+ latest = event.defaultPrevented ? latest : latest.select(id);
104
+ }));
105
+ const scroll = () => {
106
+ const { current } = latest;
107
+ latest = latest.scroll(metrics(latest.sections));
108
+ forget(latest.sections, current, latest.current);
109
+ };
110
+ const release = () => {
111
+ latest = latest.release();
112
+ };
113
+ /*
114
+ * A section the fragment names on arrival is pinned, and following the page leaves a pinned section alone. The
115
+ * browser looks for it before the page is rendered, and never in a box scrolling of its own, so it is brought
116
+ * into view here; a link followed later is left to the browser, which finds its section already on the page.
117
+ */
118
+ select();
119
+ reveal(latest);
120
+ scroll();
121
+ /*
122
+ * A box scrolling sends its event to itself alone, which the capture phase on the document hears on the way
123
+ * down; the document scrolling sends its own on to the window, where it is heard as well. Following twice lands
124
+ * where following once does, so the page scrolling heard on both costs nothing.
125
+ *
126
+ * Sections moving without a scroll, as the page settles its styles, fonts and images after mounting or grows
127
+ * under the reader, move them across the top edge all the same, so the outline follows their sizes too.
128
+ *
129
+ * The reader scrolling on their own, with the wheel, by touch, with the pointer or from the keyboard, as opposed
130
+ * to the scroll a followed link sets off, releases the section chosen.
131
+ *
132
+ * A link to the fragment the location already names changes nothing the window could hear, while the browser
133
+ * still scrolls to its section. Links are therefore heard as they are clicked, before anything on the page can
134
+ * hide the click, but settled only once every handler has had its say: a click a handler cancels is left to it.
135
+ */
136
+ const stops = [
137
+ listen(document, "scroll", scroll, { passive: true, capture: true }),
138
+ listen(window, "scroll", scroll, { passive: true }),
139
+ listen(window, "resize", scroll, { passive: true }),
140
+ observe(latest.sections, scroll),
141
+ listen(window, "hashchange", select),
142
+ listen(document, "click", follow, { capture: true }),
143
+ ...["wheel", "touchmove", "pointerdown", "keydown"].map(gesture => listen(window, gesture, release, { passive: true, capture: true }))
144
+ ];
145
+ return () => stops.forEach(stop => stop());
146
+ }, [key]); // the outline the subscription starts from is the one created for these sections
147
+ return $entries.length === 0 ? null : createElement("clay-toc", { wrap }, _jsx("nav", { "aria-label": name, children: list($entries, outline.current, compact ? group : undefined) }));
148
+ }
149
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
150
+ /**
151
+ * Measures where the sections stand in the part of their scrolling box left in view, and whether the box has been
152
+ * scrolled to its end, leaving the sections starting low in its last screenful no way to reach the top third.
153
+ *
154
+ * The box is the nearest scrolling ancestor of the first section on the page, or the document where none scrolls; the
155
+ * part left in view stops short of its scroll padding, which is where whatever stands over the box is accounted for.
156
+ */
157
+ function metrics(sections) {
158
+ const elements = sections.flatMap(id => opt(document.getElementById(id) ?? undefined, element => [{
159
+ id,
160
+ element
161
+ }], []));
162
+ const box = opt(elements[0]?.element, scroller);
163
+ const root = document.documentElement;
164
+ const style = getComputedStyle(box ?? root);
165
+ const paddingTop = parseFloat(style.scrollPaddingTop) || 0; // ;(NaN) `auto` pads nothing
166
+ const paddingBottom = parseFloat(style.scrollPaddingBottom) || 0;
167
+ const { offset, client, scrolled, total } = box
168
+ ? {
169
+ offset: box.getBoundingClientRect().top,
170
+ client: box.clientHeight,
171
+ scrolled: box.scrollTop,
172
+ total: box.scrollHeight
173
+ }
174
+ : { offset: 0, client: window.innerHeight, scrolled: window.scrollY, total: root.scrollHeight };
175
+ const origin = offset + paddingTop;
176
+ const height = client - paddingTop - paddingBottom;
177
+ return {
178
+ tops: Object.fromEntries(elements.map(({ id, element }) => [id, element.getBoundingClientRect().top - origin])),
179
+ height,
180
+ // a box with nothing to scroll is at its start as much as at its end, and is read from its top
181
+ end: scrolled > 0 && scrolled + client >= total - 1
182
+ };
183
+ }
184
+ /**
185
+ * Locates the box an element scrolls in.
186
+ *
187
+ * A box letting its content scroll across computes as scrolling down as well, whether or not its content runs past its
188
+ * height, so a box counts only once it has more content than height: a body scrolling a wide table across while the
189
+ * column around it scrolls down is passed over for the column, which is what the reader actually scrolls.
190
+ *
191
+ * @returns The nearest ancestor of `element` scrolling its content vertically, or `undefined` if the document does
192
+ */
193
+ function scroller(element) {
194
+ const parent = element.parentElement;
195
+ return parent === null || parent === document.body || parent === document.documentElement ? undefined
196
+ : /^(auto|scroll|overlay)$/.test(getComputedStyle(parent).overflowY) && parent.scrollHeight > parent.clientHeight ? parent
197
+ : scroller(parent);
198
+ }
199
+ /**
200
+ * Subscribes a listener to an event target.
201
+ *
202
+ * @returns A function unsubscribing `listener`
203
+ */
204
+ function listen(target, type, listener, options) {
205
+ target.addEventListener(type, listener, options);
206
+ return () => target.removeEventListener(type, listener, options);
207
+ }
208
+ /**
209
+ * Subscribes a listener to the resizing of the sections on the page, where the platform reports it.
210
+ *
211
+ * @returns A function unsubscribing `listener`
212
+ */
213
+ function observe(sections, listener) {
214
+ const observer = typeof ResizeObserver === "undefined" ? undefined : new ResizeObserver(listener);
215
+ sections.forEach(id => opt(document.getElementById(id) ?? undefined, element => observer?.observe(element)));
216
+ return () => observer?.disconnect();
217
+ }
218
+ /**
219
+ * Brings the section chosen into view, leaving the page where it stands if no section is chosen.
220
+ */
221
+ function reveal({ current, pinned }) {
222
+ opt(pinned ? current : undefined, id => document.getElementById(id)?.scrollIntoView());
223
+ }
224
+ /**
225
+ * Drops the fragment from the location once the mark leaves the section holding the element it names.
226
+ *
227
+ * Only a move away from the section holding the element the current fragment names counts. A link just followed
228
+ * changes the fragment at once, but its `hashchange` may arrive after the scroll it sets off: the mark then leaves the
229
+ * section the reader came from, which no longer holds the element named, so the new fragment is kept.
230
+ *
231
+ * @param sections The ids of the sections in the outline, in page order
232
+ * @param from The section marked before the move, if any
233
+ * @param to The section marked after the move, if any
234
+ */
235
+ function forget(sections, from, to) {
236
+ if (from !== undefined && from !== to && opt(fragment(location.hash), id => holder(sections, id)) === from) {
237
+ history.replaceState(history.state, "", location.pathname + location.search);
238
+ }
239
+ }
240
+ /**
241
+ * Identifies the section holding an element: the section the element starts, or else the last one starting before it.
242
+ *
243
+ * @returns The id of the section holding the element `id` names, or `undefined` if no section starts at or before it
244
+ */
245
+ function holder(sections, id) {
246
+ return opt(document.getElementById(id) ?? undefined, element => sections.filter(section => opt(document.getElementById(section) ?? undefined, start => precedes(start, element))).at(-1));
247
+ }
248
+ /**
249
+ * Checks whether an element is, or starts before, another one on the page.
250
+ */
251
+ function precedes(start, element) {
252
+ return start === element || (start.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_FOLLOWING) !== 0;
253
+ }
254
+ /**
255
+ * Settles entries given either as an array of entries or keyed by their labels into an array of entries, at any depth.
256
+ */
257
+ function normalise(entries) {
258
+ return isArray(entries)
259
+ ? entries.map(({ entries = [], ...entry }) => ({ ...entry, entries: normalise(entries) }))
260
+ : Object.entries(entries).map(([label, value]) => isString(value)
261
+ ? { label, href: value, entries: [] }
262
+ : { label, entries: normalise(value) });
263
+ }
264
+ /**
265
+ * Collects the ids of the sections an outline links to by fragment, in page order.
266
+ */
267
+ function targets(entries) {
268
+ return entries.flatMap(({ href, entries }) => [fragment(href), ...targets(entries)]).filter(id => id !== undefined);
269
+ }
270
+ /**
271
+ * Identifies the element a click follows a link to on this page, as a plain click with the main button does, wherever
272
+ * the link stands, shadow trees included. A click with a modifier, or on a link opening a new browsing context or a
273
+ * download, is left to the browser, which opens the link elsewhere and leaves this page where it stands.
274
+ *
275
+ * @returns The id the clicked link names by fragment, or `undefined` for a click following no link on this page
276
+ */
277
+ function followed(event) {
278
+ const link = event.composedPath().find(node => node instanceof HTMLAnchorElement && node.hasAttribute("href"));
279
+ return event instanceof MouseEvent && event.button === 0
280
+ && !(event.metaKey || event.ctrlKey || event.shiftKey || event.altKey)
281
+ && link instanceof HTMLAnchorElement && /^(_self)?$/i.test(link.target) && !link.hasAttribute("download")
282
+ && link.pathname === location.pathname && link.search === location.search
283
+ ? fragment(link.hash)
284
+ : undefined;
285
+ }
286
+ /**
287
+ * Extracts the id a link names by fragment, or `undefined` for a link leading elsewhere or nowhere.
288
+ */
289
+ function fragment(href) {
290
+ return href?.startsWith("#") && href.length > 1 ? decodeURIComponent(href.slice(1)) : undefined;
291
+ }
292
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
293
+ /**
294
+ * Renders entries as a nested list of links, and an entry with no link as plain text. The link to the section the
295
+ * reader is in is marked as the current location.
296
+ *
297
+ * Given an accordion name, each entry with nested entries and no link of its own folds behind its label instead. The
298
+ * folds share that name, so only one is open at a time, and a fold opens while it holds the section the reader is in.
299
+ */
300
+ function list(entries, current, accordion) {
301
+ return _jsx("ul", { children: entries.map(({ label, href, target, entries }, index) => _jsx("li", { children: accordion !== undefined && href === undefined && entries.length > 0
302
+ ? _jsxs("details", { name: accordion, open: current !== undefined && holds(entries, current), children: [_jsx("summary", { children: wording(label) }), list(entries, current)] })
303
+ : _jsxs(_Fragment, { children: [href === undefined
304
+ ? wording(label)
305
+ :
306
+ _jsx("a", { href: href, target: target, "aria-current": current !== undefined && fragment(href) === current ? "location" : undefined, children: wording(label) }), entries.length > 0 && list(entries, current)] }) }, href ?? index)) });
307
+ }
308
+ /**
309
+ * Renders the wording of a label as the line the outline clips, offering a plain string as a tooltip. The tooltip sits
310
+ * on the line rather than on the link around it, where it would be announced again as a description of the link.
311
+ */
312
+ function wording(label) {
313
+ return _jsx("span", { title: isString(label) ? label : undefined, children: label });
314
+ }
315
+ /**
316
+ * Checks whether entries link to a section, at any depth.
317
+ */
318
+ function holds(entries, id) {
319
+ return entries.some(entry => fragment(entry.href) === id || holds(entry.entries, id));
320
+ }
321
+ //# sourceMappingURL=toc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toc.js","sourceRoot":"","sources":["../../src/navigation/toc.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;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AC;gCACD,YAAG,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,kBAAgB,OAAO,KAAK,SAAS,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,YACvH,OAAO,CAAC,KAAK,CAAC,GAAK,EAGrB,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,IAE3C,IApByE,IAAI,IAAI,KAAK,CAuBtF,CAAC,GAAM,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,SAAS,OAAO,CAAC,KAAwB;IACxC,OAAO,eAAM,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,YAAG,KAAK,GAAQ,CAAC;AACzE,CAAC;AAED;;GAEG;AACH,SAAS,KAAK,CAAC,OAAyB,EAAE,EAAU;IACnD,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AACvF,CAAC"}
@@ -0,0 +1,26 @@
1
+ /*
2
+ * Copyright © 2026 Metreeca srl
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /*
18
+ * The guard decides what is shown and nothing else: the element is erased, so what it holds or the fallback sits in the
19
+ * row, the grid or the flow around it exactly as it would if the guard were not there at all.
20
+ */
21
+
22
+ clay-guard {
23
+
24
+ display: contents;
25
+
26
+ }
@@ -0,0 +1,37 @@
1
+ import { type ComponentChildren } from "preact";
2
+ import "./guard.css";
3
+ /**
4
+ * Creates a guarded area.
5
+ *
6
+ * Renders what it holds until a component inside it fails while rendering, updating or running an effect, then shows
7
+ * the fallback in its place and raises the failure on the {@link @grafctory/clay!board.Board board} enclosing the
8
+ * guard, so a reader learns what went wrong while the screen around the guard keeps working. Guards nest: the innermost
9
+ * one around the failing component takes the failure up, and a guard further out keeps rendering what it holds, the
10
+ * inner guard showing its fallback among the rest, so a failure is confined as narrowly as guards are placed.
11
+ *
12
+ * The failure is raised as a `defect` of the interface, or as a `failure` where the component threw problem details,
13
+ * and logged to the console as caught, so whoever fixes the defect finds the stack the post leaves out.
14
+ *
15
+ * A failure in an event handler or in asynchronous work happens outside rendering and never reaches a guard: the board
16
+ * takes it up among the issues the page raises on its own account. A fallback failing in turn is taken up by the guard
17
+ * enclosing this one, or left to the board where no other guard encloses it, so no failure goes unseen.
18
+ *
19
+ * The guard keeps to its fallback for as long as it stays mounted. It takes no box of its own, so what it holds and
20
+ * the fallback alike sit in the row, the grid or the flow around it as they would without the wrapper, and it carries
21
+ * no semantics: a fallback telling assistive technology what went missing states it itself.
22
+ *
23
+ * @param options The widget configuration
24
+ *
25
+ * @returns The guarded area
26
+ */
27
+ export declare function Guard({ fallback, children }: {
28
+ /**
29
+ * What stands in place of what the guard holds once it failed; nothing if omitted, leaving the area empty.
30
+ */
31
+ fallback?: ComponentChildren;
32
+ /**
33
+ * What the guard holds, rendered until it fails.
34
+ */
35
+ children: ComponentChildren;
36
+ }): import("preact").VNode<import("preact").ClassAttributes<HTMLElement> & import("preact").HTMLAttributes<EventTarget> & import("preact").SVGAttributes<SVGElement>>;
37
+ //# sourceMappingURL=guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guard.d.ts","sourceRoot":"","sources":["../../src/scopes/guard.tsx"],"names":[],"mappings":"AA0BA,OAAO,EAAE,KAAK,iBAAiB,EAAiB,MAAM,QAAQ,CAAC;AAE/D,OAAO,aAAa,CAAC;AAGrB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,KAAK,CAAC,EAErB,QAAQ,EAER,QAAQ,EAER,EAAE;IAEF;;OAEG;IACH,QAAQ,CAAC,EAAE,iBAAiB,CAAA;IAE5B;;OAEG;IACH,QAAQ,EAAE,iBAAiB,CAAA;CAE3B,qKAcA"}
@@ -0,0 +1,60 @@
1
+ /*
2
+ * Copyright © 2026 Metreeca srl
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * Failure boundary.
18
+ *
19
+ * Confines a failure to the part of a screen it broke: what a guard holds gives way to a fallback once it fails, the
20
+ * rest of the screen goes on working, and the failure is raised for a reader to see rather than lost to the console.
21
+ *
22
+ * @module guard
23
+ */
24
+ import { useBoard } from "@grafctory/clay/board";
25
+ import { createElement } from "preact";
26
+ import { useErrorBoundary } from "preact/hooks";
27
+ import "./guard.css";
28
+ /**
29
+ * Creates a guarded area.
30
+ *
31
+ * Renders what it holds until a component inside it fails while rendering, updating or running an effect, then shows
32
+ * the fallback in its place and raises the failure on the {@link @grafctory/clay!board.Board board} enclosing the
33
+ * guard, so a reader learns what went wrong while the screen around the guard keeps working. Guards nest: the innermost
34
+ * one around the failing component takes the failure up, and a guard further out keeps rendering what it holds, the
35
+ * inner guard showing its fallback among the rest, so a failure is confined as narrowly as guards are placed.
36
+ *
37
+ * The failure is raised as a `defect` of the interface, or as a `failure` where the component threw problem details,
38
+ * and logged to the console as caught, so whoever fixes the defect finds the stack the post leaves out.
39
+ *
40
+ * A failure in an event handler or in asynchronous work happens outside rendering and never reaches a guard: the board
41
+ * takes it up among the issues the page raises on its own account. A fallback failing in turn is taken up by the guard
42
+ * enclosing this one, or left to the board where no other guard encloses it, so no failure goes unseen.
43
+ *
44
+ * The guard keeps to its fallback for as long as it stays mounted. It takes no box of its own, so what it holds and
45
+ * the fallback alike sit in the row, the grid or the flow around it as they would without the wrapper, and it carries
46
+ * no semantics: a fallback telling assistive technology what went missing states it itself.
47
+ *
48
+ * @param options The widget configuration
49
+ *
50
+ * @returns The guarded area
51
+ */
52
+ export function Guard({ fallback, children }) {
53
+ const { raise } = useBoard();
54
+ const [error] = useErrorBoundary(error => {
55
+ console.error(error); // the post leaves the stack out, so the console keeps it for whoever fixes the defect
56
+ raise(error);
57
+ });
58
+ return createElement("clay-guard", {}, error === undefined ? children : fallback);
59
+ }
60
+ //# sourceMappingURL=guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guard.js","sourceRoot":"","sources":["../../src/scopes/guard.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;GAOG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAA0B,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,aAAa,CAAC;AAGrB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,KAAK,CAAC,EAErB,QAAQ,EAER,QAAQ,EAcR;IAEA,MAAM,EAAE,KAAK,EAAE,GAAG,QAAQ,EAAE,CAAC;IAE7B,MAAM,CAAC,KAAK,CAAC,GAAG,gBAAgB,CAAC,KAAK,CAAC,EAAE;QAExC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,sFAAsF;QAE5G,KAAK,CAAC,KAAK,CAAC,CAAC;IAEd,CAAC,CAAC,CAAC;IAEH,OAAO,aAAa,CAAC,YAAY,EAAE,EAAE,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;AAEnF,CAAC"}
@@ -0,0 +1,26 @@
1
+ /*
2
+ * Copyright © 2026 Metreeca srl
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /*
18
+ * The area carries the tokens it was given and the text they set: the element is erased, so what it holds sits in
19
+ * the row, the grid or the flow around it as it would without the wrapper, and the assignment inherits all the same.
20
+ */
21
+
22
+ clay-style {
23
+
24
+ display: contents;
25
+
26
+ }