@voidable/ui 0.6.1 → 0.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 (250) hide show
  1. package/README.md +168 -9
  2. package/dist/angular/index.d.ts +20 -0
  3. package/dist/angular/index.js +78 -0
  4. package/dist/autoloader-core.d.ts +45 -0
  5. package/dist/autoloader-table.generated.d.ts +5 -0
  6. package/dist/autoloader.d.ts +13 -0
  7. package/dist/autoloader.js +229 -0
  8. package/dist/base.d.ts +173 -2
  9. package/dist/base.js +2 -9
  10. package/dist/chunks/base-CMruMbxC.js +824 -0
  11. package/dist/chunks/disclosure-Bj_49GcC.js +23 -0
  12. package/dist/chunks/dismiss-Drsy_dE5.js +37 -0
  13. package/dist/chunks/form-control-C0vH6gii.js +300 -0
  14. package/dist/chunks/keyboard-MQpfTX5I.js +46 -0
  15. package/dist/chunks/keyboard-activation-CV0m4hkn.js +29 -0
  16. package/dist/chunks/modal-D_YVy2vg.js +71 -0
  17. package/dist/chunks/overlay-BywGMcDW.js +467 -0
  18. package/dist/chunks/parts-D30c8OoG.js +229 -0
  19. package/dist/chunks/{shape-FJvZa8FW.js → shape-C_LW7EjG.js} +12 -4
  20. package/dist/components/accordion.d.ts +38 -10
  21. package/dist/components/accordion.js +51 -53
  22. package/dist/components/action-input.d.ts +64 -6
  23. package/dist/components/action-input.js +84 -41
  24. package/dist/components/alert.d.ts +24 -10
  25. package/dist/components/alert.js +26 -27
  26. package/dist/components/avatar.d.ts +8 -2
  27. package/dist/components/avatar.js +3 -3
  28. package/dist/components/badge.d.ts +8 -3
  29. package/dist/components/badge.js +2 -2
  30. package/dist/components/banner.d.ts +21 -10
  31. package/dist/components/banner.js +27 -27
  32. package/dist/components/bar-chart.d.ts +30 -6
  33. package/dist/components/bar-chart.js +29 -39
  34. package/dist/components/breadcrumbs.d.ts +19 -6
  35. package/dist/components/breadcrumbs.js +16 -22
  36. package/dist/components/button.d.ts +64 -10
  37. package/dist/components/button.js +70 -26
  38. package/dist/components/calendar.d.ts +65 -10
  39. package/dist/components/calendar.js +157 -106
  40. package/dist/components/card.d.ts +14 -9
  41. package/dist/components/card.js +8 -22
  42. package/dist/components/carousel.d.ts +65 -14
  43. package/dist/components/carousel.js +84 -93
  44. package/dist/components/charts/scale.d.ts +0 -1
  45. package/dist/components/charts/shape.d.ts +0 -1
  46. package/dist/components/checkbox-group.d.ts +38 -5
  47. package/dist/components/checkbox-group.js +61 -20
  48. package/dist/components/checkbox.d.ts +53 -7
  49. package/dist/components/checkbox.js +66 -29
  50. package/dist/components/collapsible.d.ts +29 -9
  51. package/dist/components/collapsible.js +42 -44
  52. package/dist/components/color-picker.d.ts +20 -4
  53. package/dist/components/color-picker.js +35 -29
  54. package/dist/components/combobox.d.ts +84 -10
  55. package/dist/components/combobox.js +142 -45
  56. package/dist/components/compose-input.d.ts +8 -1
  57. package/dist/components/compose-input.js +9 -3
  58. package/dist/components/dialog.d.ts +24 -20
  59. package/dist/components/dialog.js +8 -57
  60. package/dist/components/divider.d.ts +8 -1
  61. package/dist/components/divider.js +3 -3
  62. package/dist/components/donut-chart.d.ts +28 -5
  63. package/dist/components/donut-chart.js +55 -54
  64. package/dist/components/drawer.d.ts +19 -18
  65. package/dist/components/drawer.js +9 -53
  66. package/dist/components/dropdown-menu.d.ts +62 -7
  67. package/dist/components/dropdown-menu.js +124 -33
  68. package/dist/components/editable.d.ts +37 -3
  69. package/dist/components/editable.js +45 -24
  70. package/dist/components/error-fallback.d.ts +36 -5
  71. package/dist/components/error-fallback.js +73 -23
  72. package/dist/components/field.d.ts +38 -4
  73. package/dist/components/field.js +63 -21
  74. package/dist/components/file-upload.d.ts +23 -2
  75. package/dist/components/file-upload.js +47 -24
  76. package/dist/components/gauge.d.ts +48 -9
  77. package/dist/components/gauge.js +57 -55
  78. package/dist/components/hamburger.d.ts +19 -4
  79. package/dist/components/hamburger.js +28 -19
  80. package/dist/components/hover-card.d.ts +40 -14
  81. package/dist/components/hover-card.js +76 -59
  82. package/dist/components/indicator.d.ts +18 -7
  83. package/dist/components/indicator.js +16 -18
  84. package/dist/components/input.d.ts +70 -5
  85. package/dist/components/input.js +83 -20
  86. package/dist/components/line-chart.d.ts +27 -5
  87. package/dist/components/line-chart.js +19 -21
  88. package/dist/components/list.d.ts +10 -1
  89. package/dist/components/list.js +3 -3
  90. package/dist/components/menu.d.ts +67 -21
  91. package/dist/components/menu.js +116 -115
  92. package/dist/components/multiselect.d.ts +108 -13
  93. package/dist/components/multiselect.js +207 -70
  94. package/dist/components/nav-bar.d.ts +12 -7
  95. package/dist/components/nav-bar.js +11 -21
  96. package/dist/components/nav-menu.d.ts +52 -12
  97. package/dist/components/nav-menu.js +68 -70
  98. package/dist/components/number-input.d.ts +76 -8
  99. package/dist/components/number-input.js +117 -51
  100. package/dist/components/pagination.d.ts +19 -1
  101. package/dist/components/pagination.js +68 -7
  102. package/dist/components/panel.d.ts +16 -8
  103. package/dist/components/panel.js +20 -20
  104. package/dist/components/pin-input.d.ts +41 -4
  105. package/dist/components/pin-input.js +45 -27
  106. package/dist/components/popover.d.ts +29 -11
  107. package/dist/components/popover.js +47 -35
  108. package/dist/components/progress.d.ts +7 -3
  109. package/dist/components/progress.js +3 -3
  110. package/dist/components/radio-group.d.ts +30 -5
  111. package/dist/components/radio-group.js +56 -19
  112. package/dist/components/radio.d.ts +47 -7
  113. package/dist/components/radio.js +68 -29
  114. package/dist/components/scroll-area.d.ts +8 -5
  115. package/dist/components/scroll-area.js +19 -20
  116. package/dist/components/segmented-control.d.ts +52 -8
  117. package/dist/components/segmented-control.js +66 -36
  118. package/dist/components/select.d.ts +59 -12
  119. package/dist/components/select.js +96 -46
  120. package/dist/components/sidebar.d.ts +22 -3
  121. package/dist/components/sidebar.js +20 -10
  122. package/dist/components/skeleton.d.ts +5 -2
  123. package/dist/components/skeleton.js +4 -4
  124. package/dist/components/slider.d.ts +27 -5
  125. package/dist/components/slider.js +29 -17
  126. package/dist/components/spinner.d.ts +6 -2
  127. package/dist/components/spinner.js +3 -3
  128. package/dist/components/stat.d.ts +21 -4
  129. package/dist/components/stat.js +7 -3
  130. package/dist/components/status-dot.d.ts +4 -1
  131. package/dist/components/status-dot.js +3 -3
  132. package/dist/components/stepper.d.ts +5 -1
  133. package/dist/components/stepper.js +2 -2
  134. package/dist/components/switch.d.ts +24 -5
  135. package/dist/components/switch.js +37 -19
  136. package/dist/components/table.d.ts +51 -2
  137. package/dist/components/table.js +157 -8
  138. package/dist/components/tabs.d.ts +49 -17
  139. package/dist/components/tabs.js +85 -54
  140. package/dist/components/tag.d.ts +17 -7
  141. package/dist/components/tag.js +19 -21
  142. package/dist/components/tags-input.d.ts +33 -4
  143. package/dist/components/tags-input.js +40 -30
  144. package/dist/components/textarea.d.ts +61 -5
  145. package/dist/components/textarea.js +58 -21
  146. package/dist/components/toast.d.ts +89 -15
  147. package/dist/components/toast.js +105 -30
  148. package/dist/components/toggle-group.d.ts +30 -3
  149. package/dist/components/toggle-group.js +43 -16
  150. package/dist/components/toggle.d.ts +25 -4
  151. package/dist/components/toggle.js +28 -18
  152. package/dist/components/tooltip.d.ts +31 -12
  153. package/dist/components/tooltip.js +62 -28
  154. package/dist/components.json +1518 -0
  155. package/dist/custom-elements.json +31817 -0
  156. package/dist/dev/index.d.ts +40 -0
  157. package/dist/dev/rules.d.ts +46 -0
  158. package/dist/dev/table.generated.d.ts +8 -0
  159. package/dist/dev/types.d.ts +113 -0
  160. package/dist/dev.js +3364 -0
  161. package/dist/disclosure.d.ts +30 -0
  162. package/dist/dismiss.d.ts +20 -0
  163. package/dist/form-control.d.ts +92 -0
  164. package/dist/index.d.ts +5 -4
  165. package/dist/index.js +24 -24
  166. package/dist/keyboard-activation.d.ts +31 -0
  167. package/dist/keyboard.d.ts +32 -0
  168. package/dist/modal.d.ts +44 -0
  169. package/dist/overlay.d.ts +249 -0
  170. package/dist/parts.d.ts +171 -0
  171. package/dist/projection.d.ts +370 -0
  172. package/dist/types/elements.d.ts +648 -0
  173. package/dist/types/react.d.ts +163 -0
  174. package/dist/types/solid.d.ts +164 -0
  175. package/dist/types/solid2.d.ts +161 -0
  176. package/dist/types/svelte.d.ts +154 -0
  177. package/dist/types/vue.d.ts +156 -0
  178. package/dist/vscode.html-custom-data.json +6004 -0
  179. package/dist/web-types.json +8365 -0
  180. package/package.json +113 -21
  181. package/dist/base.d.ts.map +0 -1
  182. package/dist/components/accordion.d.ts.map +0 -1
  183. package/dist/components/action-input.d.ts.map +0 -1
  184. package/dist/components/alert.d.ts.map +0 -1
  185. package/dist/components/avatar.d.ts.map +0 -1
  186. package/dist/components/badge.d.ts.map +0 -1
  187. package/dist/components/banner.d.ts.map +0 -1
  188. package/dist/components/bar-chart.d.ts.map +0 -1
  189. package/dist/components/breadcrumbs.d.ts.map +0 -1
  190. package/dist/components/button.d.ts.map +0 -1
  191. package/dist/components/calendar.d.ts.map +0 -1
  192. package/dist/components/card.d.ts.map +0 -1
  193. package/dist/components/carousel.d.ts.map +0 -1
  194. package/dist/components/charts/scale.d.ts.map +0 -1
  195. package/dist/components/charts/shape.d.ts.map +0 -1
  196. package/dist/components/checkbox-group.d.ts.map +0 -1
  197. package/dist/components/checkbox.d.ts.map +0 -1
  198. package/dist/components/collapsible.d.ts.map +0 -1
  199. package/dist/components/color-picker.d.ts.map +0 -1
  200. package/dist/components/combobox.d.ts.map +0 -1
  201. package/dist/components/compose-input.d.ts.map +0 -1
  202. package/dist/components/dialog.d.ts.map +0 -1
  203. package/dist/components/divider.d.ts.map +0 -1
  204. package/dist/components/donut-chart.d.ts.map +0 -1
  205. package/dist/components/drawer.d.ts.map +0 -1
  206. package/dist/components/dropdown-menu.d.ts.map +0 -1
  207. package/dist/components/editable.d.ts.map +0 -1
  208. package/dist/components/error-fallback.d.ts.map +0 -1
  209. package/dist/components/field.d.ts.map +0 -1
  210. package/dist/components/file-upload.d.ts.map +0 -1
  211. package/dist/components/gauge.d.ts.map +0 -1
  212. package/dist/components/hamburger.d.ts.map +0 -1
  213. package/dist/components/hover-card.d.ts.map +0 -1
  214. package/dist/components/indicator.d.ts.map +0 -1
  215. package/dist/components/input.d.ts.map +0 -1
  216. package/dist/components/line-chart.d.ts.map +0 -1
  217. package/dist/components/list.d.ts.map +0 -1
  218. package/dist/components/menu.d.ts.map +0 -1
  219. package/dist/components/multiselect.d.ts.map +0 -1
  220. package/dist/components/nav-bar.d.ts.map +0 -1
  221. package/dist/components/nav-menu.d.ts.map +0 -1
  222. package/dist/components/number-input.d.ts.map +0 -1
  223. package/dist/components/pagination.d.ts.map +0 -1
  224. package/dist/components/panel.d.ts.map +0 -1
  225. package/dist/components/pin-input.d.ts.map +0 -1
  226. package/dist/components/popover.d.ts.map +0 -1
  227. package/dist/components/progress.d.ts.map +0 -1
  228. package/dist/components/radio-group.d.ts.map +0 -1
  229. package/dist/components/radio.d.ts.map +0 -1
  230. package/dist/components/scroll-area.d.ts.map +0 -1
  231. package/dist/components/segmented-control.d.ts.map +0 -1
  232. package/dist/components/select.d.ts.map +0 -1
  233. package/dist/components/sidebar.d.ts.map +0 -1
  234. package/dist/components/skeleton.d.ts.map +0 -1
  235. package/dist/components/slider.d.ts.map +0 -1
  236. package/dist/components/spinner.d.ts.map +0 -1
  237. package/dist/components/stat.d.ts.map +0 -1
  238. package/dist/components/status-dot.d.ts.map +0 -1
  239. package/dist/components/stepper.d.ts.map +0 -1
  240. package/dist/components/switch.d.ts.map +0 -1
  241. package/dist/components/table.d.ts.map +0 -1
  242. package/dist/components/tabs.d.ts.map +0 -1
  243. package/dist/components/tag.d.ts.map +0 -1
  244. package/dist/components/tags-input.d.ts.map +0 -1
  245. package/dist/components/textarea.d.ts.map +0 -1
  246. package/dist/components/toast.d.ts.map +0 -1
  247. package/dist/components/toggle-group.d.ts.map +0 -1
  248. package/dist/components/toggle.d.ts.map +0 -1
  249. package/dist/components/tooltip.d.ts.map +0 -1
  250. package/dist/index.d.ts.map +0 -1
@@ -0,0 +1,171 @@
1
+ import { ReactiveController, ReactiveControllerHost } from 'lit';
2
+ /**
3
+ * Explicit parts (#52): every region of a component is an element the author
4
+ * writes (`<void-popover-trigger>`, `<void-popover-content>`), and the author's
5
+ * markup is the final DOM. The component never moves, wraps or clones its
6
+ * children; it finds them, adds behaviour, and writes the ARIA and state
7
+ * attributes that wire them together.
8
+ *
9
+ * Parts are CSS-only: undefined `void-*` tags styled by the theme, costing no
10
+ * JavaScript. The parent does all the work, so it does not matter whether a part
11
+ * exists before the parent upgrades, arrives later (streamed HTML, a framework
12
+ * render), is reordered by a keyed list, or is replaced by a server morph.
13
+ *
14
+ * This controller is that work, shared by every parent:
15
+ *
16
+ * - **Finding parts.** {@link all} and {@link one} look parts up in the DOM when
17
+ * asked: a part belongs to the nearest enclosing element of the parent's tag,
18
+ * so the same component nested inside itself keeps its own parts, and a
19
+ * `<form>` (or any other non-part element) between parent and part is fine.
20
+ * Nothing is cached, so a lookup is never stale.
21
+ * - **Noticing changes.** One MutationObserver per connected parent (childList
22
+ * over its subtree, plus the attributes it owns) calls `onChange` once per
23
+ * microtask when a part was added, removed or moved, or when something removed
24
+ * an attribute the parent wrote. It does no layout work and nothing on a
25
+ * timer; mutations that touch no part (typing, a list re-rendered inside a
26
+ * body) are filtered by tag name.
27
+ * - **Owned attributes.** The attributes the parent writes onto parts and onto
28
+ * the controls inside them (`id`, `role`, `aria-*`, `popover`, `tabindex`,
29
+ * state flags, overlay placement) are recorded per element:
30
+ * - {@link set} *controls* an attribute: the parent decides its value, and it
31
+ * follows the parent's state (`aria-selected`, `active`, `tabindex`);
32
+ * - {@link provide} only fills an attribute that is absent and never
33
+ * overwrites what the author or the server wrote (`id`, `role` for a title);
34
+ * - {@link token} adds one token to a list attribute (`aria-describedby`)
35
+ * and leaves the author's other tokens alone.
36
+ * When an element stops being a part (removed, or moved out of the parent),
37
+ * what the parent wrote on it is taken off again.
38
+ * - **Morphs.** The adapters call the parent's `voidBeforeMorph(incoming)`, which
39
+ * copies every owned attribute and style property onto the matching element of
40
+ * the server's markup (same tag and position among its same-tag siblings, or
41
+ * same server id) before the morph compares them, so the morph keeps them: an
42
+ * open popover stays in the top layer, generated ids keep morphers pairing the
43
+ * same nodes, and nothing is moved, parked or rebuilt.
44
+ *
45
+ * Generated ids use a random suffix (no module state, safe across copies of the
46
+ * library) and are created only when an element has none.
47
+ */
48
+ /** Instance key of the objects `VoidElement.voidBeforeMorph` hands the incoming element to. */
49
+ export declare const MORPH_PARTICIPANTS: unique symbol;
50
+ export interface MorphParticipant {
51
+ voidBeforeMorph(incoming: Element): void;
52
+ /** Whether `incoming` is a copy of the live element rather than server markup. */
53
+ isCopy?(incoming: Element): boolean;
54
+ }
55
+ type Host = ReactiveControllerHost & HTMLElement & {
56
+ [MORPH_PARTICIPANTS]?: MorphParticipant[];
57
+ };
58
+ export interface PartsOptions {
59
+ /** Every part tag of the component, at either level. */
60
+ tags: readonly string[];
61
+ /**
62
+ * Re-wires the parts (looks them up and writes their attributes). Called when
63
+ * the parent connects and, coalesced to one call per microtask, whenever a
64
+ * part is added, removed or moved, or an owned attribute was changed by
65
+ * someone else. Must be idempotent: it runs again on its own writes' echo.
66
+ */
67
+ onChange: () => void;
68
+ }
69
+ /** A unique id: `prefix-xxxxxxxx`. */
70
+ export declare function partId(prefix: string): string;
71
+ export declare class PartsController implements ReactiveController, MorphParticipant {
72
+ readonly host: Host;
73
+ private readonly _tags;
74
+ private readonly _selector;
75
+ private readonly _onChange;
76
+ private _observer;
77
+ private _queued;
78
+ /** Owned attributes per element (an element may be a part or a control inside one). */
79
+ private readonly _attrs;
80
+ /** Owned inline style properties per element. */
81
+ private readonly _styles;
82
+ /** Attribute names the observer watches: every name ever owned. */
83
+ private readonly _names;
84
+ private _syncing;
85
+ /** Counts sync passes, so a pass can sweep what the previous one wrote and this one did not. */
86
+ private _pass;
87
+ constructor(host: ReactiveControllerHost & HTMLElement, options: PartsOptions);
88
+ /** Whether `el` is this parent's part (or inside one): its nearest parent of this tag is this host. */
89
+ owns(el: Element): boolean;
90
+ /** This parent's parts of `tag`, in document order. */
91
+ all<T extends HTMLElement = HTMLElement>(tag: string): T[];
92
+ /** This parent's first part of `tag`. */
93
+ one<T extends HTMLElement = HTMLElement>(tag: string): T | null;
94
+ /** Parts of `tag` inside `part` (a level-2 lookup: triggers inside a tab list). */
95
+ within<T extends HTMLElement = HTMLElement>(part: Element | null, tag: string): T[];
96
+ private _own;
97
+ /**
98
+ * Controls `name` on `el`: writes `value` (`true` for an empty value), or
99
+ * removes it for `null` / `false` / `undefined`.
100
+ */
101
+ set(el: Element, name: string, value: string | boolean | null | undefined): void;
102
+ /**
103
+ * Fills `name` on `el` with `value` when the element has no such attribute;
104
+ * an attribute the author or the server wrote is left alone. Returns the
105
+ * attribute's value afterwards.
106
+ */
107
+ provide(el: Element, name: string, value: string): string;
108
+ /** The element's id, generating `prefix-xxxxxxxx` when it has none (an author or server id is never replaced). */
109
+ id(el: Element, prefix: string): string;
110
+ /** Adds (`on`) or removes `token` in the list attribute `name` of `el`, keeping every other token. */
111
+ token(el: Element, name: string, token: string, on?: boolean): void;
112
+ /** Controls an inline style property on `el` (`null` removes it). */
113
+ style(el: HTMLElement, property: string, value: string | null): void;
114
+ /** Takes one owned attribute (or token) back off `el`, leaving a value someone else wrote since. */
115
+ private _drop;
116
+ /** Takes off everything this parent wrote on `el`. */
117
+ release(el: Element): void;
118
+ hostConnected(): void;
119
+ hostDisconnected(): void;
120
+ /** Re-wires now (normally it happens on its own). */
121
+ sync(): void;
122
+ /** Re-wires in a microtask (several requests in one task make one call). */
123
+ requestSync(): void;
124
+ private _observe;
125
+ private _tokenNames;
126
+ private _onMutations;
127
+ /** An owned attribute of `el` no longer has the value the parent wrote. */
128
+ private _lostOwned;
129
+ /**
130
+ * Copies every owned attribute and style property onto the element of the
131
+ * server's markup (`incoming`, the server's version of the host) that the
132
+ * morph will pair with each owned element, so the morph keeps them. An
133
+ * attribute the server sends is kept as the server sends it, except a
134
+ * controlled (`set`) one, which follows the live element: it is state the
135
+ * parent derives from its own reflected attributes.
136
+ */
137
+ /**
138
+ * Whether `incoming` is a copy of the live element (`cloneNode`, LiveView's
139
+ * clone of a locked element) rather than server markup: one of its parts
140
+ * already carries an attribute this parent filled in because the author left
141
+ * it out (a generated id, a role), which server markup does not have. Call it
142
+ * before `voidBeforeMorph`, which writes those attributes onto the incoming
143
+ * element.
144
+ */
145
+ isCopy(incoming: Element): boolean;
146
+ voidBeforeMorph(incoming: Element): void;
147
+ /**
148
+ * The element of `incoming` a morph pairs with `el`: the one with the same
149
+ * server id, else the one at the same path (tag and index among same-tag
150
+ * siblings at each level), which is how morphers pair elements without ids.
151
+ */
152
+ private _counterpart;
153
+ }
154
+ /**
155
+ * The control inside an overlay trigger part: the first element child of
156
+ * `<void-popover-trigger>` (a `<void-button>`, a `<button>`, a link), which gets
157
+ * the trigger ARIA. Null when the trigger holds no element.
158
+ */
159
+ export declare function triggerControl(trigger: Element | null): HTMLElement | null;
160
+ /**
161
+ * Gives `host` an open shadow root holding `markup` (static, trusted), once,
162
+ * and returns it: the internal structure of a component that needs a native
163
+ * element of its own around the author's children (the `<dialog>` of a modal)
164
+ * or a control the author does not write (a close button). The author's
165
+ * children stay light-DOM children of the host, unmoved, and are shown through
166
+ * the `<slot>` in `markup`; the theme styles the internal elements through
167
+ * `::part()`. Morphers and frameworks never see a shadow root, so it survives
168
+ * them by construction.
169
+ */
170
+ export declare function attachChrome(host: HTMLElement, markup: string): ShadowRoot;
171
+ export {};
@@ -0,0 +1,370 @@
1
+ import { LitElement, ReactiveController } from 'lit';
2
+ /**
3
+ * Where a projection region puts its nodes.
4
+ *
5
+ * - `'before'`: stay a direct child of the host, before the Lit-rendered content.
6
+ * - `'after'`: stay a direct child of the host, after the Lit-rendered content.
7
+ * - a function: return a container element that the host's own template
8
+ * renders (looked up after each render, e.g. `() => this.querySelector(':scope > .x-body')`).
9
+ */
10
+ export type ProjectionTarget = 'before' | 'after' | (() => Element | null | undefined);
11
+ /** What a region's `accepts` is told about the node being routed. */
12
+ export interface ProjectionContext {
13
+ /**
14
+ * True until the first consumer element has been projected since the controller
15
+ * (re)initialised. Covers both children present at connect and children the
16
+ * parser appends after an early upgrade.
17
+ */
18
+ initial: boolean;
19
+ /**
20
+ * Where the consumer put the node: `'before'` if it sits on the host ahead of the
21
+ * Lit-rendered content (e.g. `host.prepend(x)`, or a framework inserting next to
22
+ * a trigger), `'after'` if it was appended, `'insert'` if it was inserted next to
23
+ * a node that had already been projected into a container.
24
+ */
25
+ zone: 'before' | 'after' | 'insert';
26
+ }
27
+ /** A named destination for consumer children: the light-DOM equivalent of a named slot. */
28
+ export interface ProjectionRegion {
29
+ /** Region name, used with {@link ProjectionController.nodes}. */
30
+ name: string;
31
+ /** Where the region's nodes live. */
32
+ target: ProjectionTarget;
33
+ /**
34
+ * Whether a consumer node belongs to this region. Regions are tried in order and
35
+ * the first one that accepts a node wins; a region without `accepts` takes
36
+ * everything that reaches it. A node no region accepts stays where the consumer
37
+ * put it, after the Lit-rendered content.
38
+ */
39
+ accepts?: (node: Node, context: ProjectionContext) => boolean;
40
+ /**
41
+ * Development-only hint: if, after projection, this region holds no element while
42
+ * another region does, warn once per host with the message this returns (return
43
+ * null to stay quiet). Silent in production builds (when Lit's development build
44
+ * is not in use).
45
+ */
46
+ required?: () => string | null;
47
+ /**
48
+ * Gives each node of a container region a wrapper element of its own (for
49
+ * example an `<li>` per item of a list): called once per node, the wrapper is
50
+ * kept for that node while it stays in the region and removed once it leaves.
51
+ * Wrappers belong to the component (it may set attributes on them) and are
52
+ * parked and restored with the container. Only for function targets.
53
+ */
54
+ wrap?: (node: Node) => Element;
55
+ /**
56
+ * The container is itself a scroll viewport (a scroll area): its offsets are
57
+ * read when it is parked, even if no scroll event has reported them yet (a
58
+ * `scrollTop` set in code just before a morph). Other scrolled elements are
59
+ * found through scroll events, which costs nothing at park time.
60
+ */
61
+ scrolls?: boolean;
62
+ }
63
+ export interface ProjectionOptions {
64
+ /** Destinations for consumer children. Empty (the default) for components that only render chrome. */
65
+ regions?: ProjectionRegion[];
66
+ /**
67
+ * Where the rendered chrome sits among consumer nodes that no region takes:
68
+ * `'start'` (before them) or `'end'` (after them, where Lit puts a plain
69
+ * render). Defaults to `'start'` with regions and `'end'` without.
70
+ */
71
+ placement?: 'start' | 'end';
72
+ /**
73
+ * Called when the set or order of consumer nodes in any region changes after the
74
+ * first render (children added, removed or reordered by the consumer), and after
75
+ * the controller re-projected following recovery or `unproject()` (see the class
76
+ * docs). Not called for the initial projection. Typical use: `() => this.requestUpdate()`.
77
+ */
78
+ onChange?: () => void;
79
+ }
80
+ /** @internal Instance key under which a host's controller is stored (read by VoidElement's DOM overrides). */
81
+ export declare const PROJECTION_KEY = "__voidProjection";
82
+ /**
83
+ * @internal True while a morph holds the focus of
84
+ * an element inside `host` (from just before it is moved out until it is
85
+ * focused again). Blur and focus handlers use it to ignore the blur and focus
86
+ * events that moving the element causes, so the morph does not commit, close
87
+ * or reset anything the user is doing.
88
+ */
89
+ export declare function isFocusParked(host: Element): boolean;
90
+ /**
91
+ * @internal Puts back focus a morph is still holding (see keepFocus), for a
92
+ * surface that could not take it when its host re-projected: an open
93
+ * popover that leaving the document closed takes focus only once its
94
+ * overlay shows it again (WebKit, and anywhere without Element.moveBefore).
95
+ */
96
+ export declare function restoreParkedFocus(doc: Document): void;
97
+ /**
98
+ * @internal True when `host` carries serialised chrome of its own among its
99
+ * direct children: the markers, or a top-level element marked as chrome. That
100
+ * happens only to a copy of a rendered host (`cloneNode(true)`, an `outerHTML`
101
+ * round trip) and never to server markup. Reads the direct children only.
102
+ */
103
+ export declare function hasSerializedChrome(host: Element): boolean;
104
+ /**
105
+ * @internal Puts a copy of a rendered host that no controller manages (a
106
+ * detached clone, which a morpher may hand over as the "incoming" element:
107
+ * LiveView patches a clone of a locked element and later morphs the live
108
+ * element to it) back into the shape of its server markup: the contents of its
109
+ * region containers and per-node wrappers are lifted onto the host in place,
110
+ * and the markers, everything between them and every element marked as chrome
111
+ * are removed. Containers of nested components are left to those components.
112
+ * Returns true when `host` is such a copy (now or on an earlier call), false
113
+ * for an element without serialised chrome, which is left alone.
114
+ */
115
+ export declare function stripSerializedChrome(host: Element): boolean;
116
+ /**
117
+ * @internal Experimental: the API may change before it is made public.
118
+ *
119
+ * Light-DOM content projection for {@link VoidElement} components.
120
+ *
121
+ * Every VoidElement that renders gets one with no regions from the base class:
122
+ * its chrome is confined between the markers (placed after the consumer content),
123
+ * tracked, parked around morphs, recovered and cleaned up in clones as described
124
+ * below, and consumer children simply stay on the host. Components that also host
125
+ * consumer children in rendered containers (text, elements, framework-managed
126
+ * nodes) declare their own, with regions, instead of snapshotting `childNodes` in
127
+ * `connectedCallback`; it replaces the default one. Construct it in a field
128
+ * initializer so it exists before the first connect:
129
+ *
130
+ * ```ts
131
+ * protected readonly _projection = new ProjectionController(this, {
132
+ * regions: [{ name: 'body', target: () => this.querySelector(':scope .x-body') }],
133
+ * });
134
+ * ```
135
+ *
136
+ * ## Contract between Lit and consumer nodes
137
+ *
138
+ * Lit and the consumer share the host element, so the two must never own the same
139
+ * positions:
140
+ *
141
+ * 1. On connect the controller inserts two comment markers into the host and points
142
+ * the host's `renderOptions.renderBefore` at the second one. Lit's root part
143
+ * therefore lives strictly between the markers; nothing Lit does (including
144
+ * clearing its part when the top-level template changes) can touch a node before
145
+ * the first marker or after the second. Consumer nodes only ever live outside the
146
+ * markers or inside region containers.
147
+ * 2. A region container must be a static element of the host's template: rendered
148
+ * on every render path (never behind a condition or `nothing`) and with no Lit
149
+ * child bindings inside it. Lit never adds, removes or reorders children of an
150
+ * element that has no child parts, so consumer nodes moved inside are safe.
151
+ * Hide closed overlays with `hidden` / an attribute instead of not rendering.
152
+ * 3. Consumer nodes are moved exactly once, never cloned, so identity, listeners
153
+ * and framework references survive (moves use `moveBefore` where available, so
154
+ * focus survives too). Nodes the consumer adds later land outside the markers and
155
+ * are routed by a MutationObserver, keeping their position relative to the
156
+ * region's other nodes; removals and reorders inside containers are observed
157
+ * too. This also covers elements upgraded before the parser appended their
158
+ * children.
159
+ * 4. Disconnecting stops observing; nothing is torn down or rebuilt, so moving the
160
+ * element in the DOM or reconnecting it never duplicates wrappers.
161
+ * 5. `VoidElement` redirects `insertBefore` / `removeChild` / `replaceChild` calls
162
+ * on the host whose reference node has been projected into a container, and
163
+ * makes the `textContent` setter and `replaceChildren` replace only consumer
164
+ * content, so frameworks that keep treating the host as the parent of their
165
+ * children (React, Solid, Vue) keep working.
166
+ * 6. Morphing: {@link unproject} (behind `VoidElement.voidBeforeMorph()`, the
167
+ * supported pre-morph hook for adapters) puts the host back into its
168
+ * server-markup shape so a DOM morph never sees chrome. The chrome is parked (in
169
+ * one shared hidden holder per document while `moveBefore` exists) and put back
170
+ * afterwards with its scroll offsets, so nothing is rebuilt.
171
+ * 7. Recovery, for morphs that skip that hook: if a marker or a top-level chrome
172
+ * element leaves the host (idiomorph, `host.innerHTML = …`, `innerText`), the
173
+ * controller discards what is left of the old chrome, inserts fresh markers (Lit
174
+ * keys its root part on the `renderBefore` node, so this yields a clean part), and
175
+ * re-renders, projecting the host's current children as if they were initial
176
+ * content. Chrome elements are tracked by identity, so one a morph recycled as
177
+ * consumer content (stripping its class) is replaced by a plain copy without
178
+ * Lit's event listeners. A host created by `cloneNode(true)` or an `outerHTML`
179
+ * round-trip of a rendered host is cleaned up the same way on first connect:
180
+ * container contents are lifted back onto the host and the stale chrome dropped.
181
+ *
182
+ * Consequences for consumers: after projection, `host.children` lists the rendered
183
+ * chrome rather than the consumer's children, and `child.parentNode === host` no
184
+ * longer holds for projected children. Use `child.closest('void-…')` or keep your
185
+ * own references.
186
+ */
187
+ export declare class ProjectionController implements ReactiveController {
188
+ private readonly _host;
189
+ private readonly _regions;
190
+ private readonly _placement;
191
+ private readonly _onChange?;
192
+ private _start;
193
+ private _end;
194
+ private _observer;
195
+ private _observedContainers;
196
+ private _placed;
197
+ /** Top-level elements of the current render, in order. */
198
+ private _chromeTop;
199
+ /** Every element Lit rendered for this host (outside container contents), by identity. */
200
+ private _chromeAll;
201
+ /** Region containers, by identity. */
202
+ private _containers;
203
+ /** Per-node wrappers of `wrap` regions: node -> wrapper, and the set of wrappers. */
204
+ private _wrapperOf;
205
+ private _wrappers;
206
+ /** Top-level text/comment nodes Lit rendered, with their data at render time. */
207
+ private _litText;
208
+ private _signature;
209
+ private _rendered;
210
+ private _recovered;
211
+ private _initialPass;
212
+ private _sawElement;
213
+ /**
214
+ * Set by unproject(): the markers and chrome are parked here until re-projection,
215
+ * in a hidden holder outside the morph target when `moveBefore` can keep them
216
+ * connected (so focus inside the chrome survives), else in a fragment.
217
+ */
218
+ private _parked;
219
+ private _warned;
220
+ constructor(host: LitElement, options?: ProjectionOptions);
221
+ hostConnected(): void;
222
+ /**
223
+ * Watches the start marker's data. Solid updates a text-only child with
224
+ * `parent.firstChild.data = text`; on a host whose chrome comes first that
225
+ * first child is this marker, so the text lands here (see _redirectMarkerText).
226
+ */
227
+ private _observeMarker;
228
+ /**
229
+ * Text written into a marker was meant for the host's first consumer text:
230
+ * put the marker back and give the text to that node (creating one, routed
231
+ * like any new child, if there is none).
232
+ */
233
+ private _redirectMarkerText;
234
+ /**
235
+ * Elements inside the host that have been scrolled, so their scroll position
236
+ * can be put back after parking (a parked element has no layout box, which
237
+ * resets its scroll offsets). Recorded from scroll events rather than read
238
+ * from every element at park time, which would force layouts mid-morph.
239
+ */
240
+ private _scrolled;
241
+ private readonly _onScroll;
242
+ hostDisconnected(): void;
243
+ hostUpdate(): void;
244
+ hostUpdated(): void;
245
+ /** True between {@link unproject} and re-projection. */
246
+ get parked(): boolean;
247
+ /** Consumer nodes currently in the named region, in document order. */
248
+ nodes(name: string): Node[];
249
+ /** The region a consumer node was projected into, if any. */
250
+ regionOf(node: Node): string | undefined;
251
+ /** True if `node` is a consumer node that was moved into a region container. */
252
+ isProjected(node: Node): boolean;
253
+ /**
254
+ * `host.insertBefore(element, null)` (or appendChild) on a rendered host:
255
+ * places the element at the end of its region right away, as the next
256
+ * mutation pass would, so a framework that goes on to read `nextSibling` of
257
+ * the items in that region (Solid reorders keyed lists so) sees it where it
258
+ * belongs. Returns false, leaving the append to the caller, for anything
259
+ * else: fragments, text, a parked or not yet rendered host, an element no
260
+ * container region takes.
261
+ */
262
+ append(node: Node): boolean;
263
+ /** `host.insertBefore(node, ref)` where `ref` has been projected into a container. */
264
+ insertBefore<T extends Node>(node: T, ref: Node): T;
265
+ /**
266
+ * Replaces all consumer content (every region, plus anything not yet routed) with
267
+ * `nodes`, leaving the rendered chrome alone. Backs `textContent = …` and
268
+ * `replaceChildren(…)` on the host. Returns false if the projection is not
269
+ * intact, in which case the caller should fall back to the native operation.
270
+ * Callers validate `nodes` first.
271
+ */
272
+ replaceContent(nodes: Node[]): boolean;
273
+ /**
274
+ * Returns the host to the shape of its original markup so a DOM morph (Turbo,
275
+ * idiomorph, morphdom/LiveView, Livewire) compares like with like: each region
276
+ * container's consumer nodes are moved back onto the host (before-region nodes,
277
+ * then container contents in document order, then after-region nodes), and the
278
+ * markers and all rendered chrome are taken out of the document. The chrome is
279
+ * parked, not destroyed: on re-projection the same nodes go back, Lit's part stays
280
+ * valid, and no element is rebuilt (the native select, tab list and inputs keep
281
+ * their identity). Component state (properties) is untouched.
282
+ *
283
+ * Re-projection happens on its own once the morph has run: the update requested
284
+ * here and the observer both fire in a microtask, after a synchronous morph. Call
285
+ * {@link reproject} to force it. If the morph left stale chrome behind, the
286
+ * controller falls back to recovery (fresh chrome). Returns false if there was
287
+ * nothing to unproject.
288
+ */
289
+ unproject(): boolean;
290
+ /** Re-projects now after {@link unproject}; resolves when the host has rendered. */
291
+ reproject(): Promise<boolean>;
292
+ /** Puts parked chrome back after a morph and re-projects the host's current children. */
293
+ private _restore;
294
+ private _needsInit;
295
+ private _intact;
296
+ /**
297
+ * Inserts fresh markers and points Lit at them. Any stale markers and chrome
298
+ * (left by a morph, by `innerHTML`, or copied by `cloneNode`) are removed first,
299
+ * with the contents of stale region containers lifted back onto the host so they
300
+ * are projected again.
301
+ */
302
+ private _init;
303
+ /**
304
+ * Removes stale markers and chrome from the host (never the live markers or
305
+ * anything between them), lifting the contents of stale containers back onto the
306
+ * host in their place. Stale nodes come from a clone or serialisation of a
307
+ * rendered host, or are what is left of this host's own chrome after its markers
308
+ * were removed. Chrome elements a morph recycled as consumer content are replaced
309
+ * with plain copies so Lit's listeners do not come along.
310
+ */
311
+ private _purgeStale;
312
+ /**
313
+ * After a morph, an element this host rendered may survive as consumer content
314
+ * (the morph matched it to a server node by tag and rewrote its attributes and
315
+ * children in place). It still carries Lit's event listeners, so swap it for a
316
+ * shallow copy that keeps its current attributes and children.
317
+ */
318
+ private _replaceRecycledChrome;
319
+ /** Region containers inside a stale chrome node that belong to this host, outermost first. */
320
+ private _staleContainers;
321
+ /** Records Lit's nodes by identity (and tags top-level ones) so stale chrome can be recognised later. */
322
+ private _markChrome;
323
+ private _trackChrome;
324
+ private _onMutation;
325
+ private _route;
326
+ /**
327
+ * Moves `node` into `region`, before `ref` (a node of that region) or appending.
328
+ * Returns false if the container is not rendered yet.
329
+ */
330
+ private _place;
331
+ /** Nodes the component itself put into a container (a placeholder option); never consumer content. */
332
+ private _owned;
333
+ /**
334
+ * @internal Marks a node the component inserts into one of its containers
335
+ * itself, so it is never taken for consumer content.
336
+ */
337
+ own(node: Node): void;
338
+ /**
339
+ * Consumer nodes a framework put straight into a container, next to projected
340
+ * ones (Svelte's `item.before(x)`), become region nodes like any other, so
341
+ * they are counted, parked and reported to onChange.
342
+ */
343
+ private _adoptForeign;
344
+ /** Per wrap end anchor used as an insert reference since the last mutation pass: the wrapper inserted last. */
345
+ private _anchorAfter;
346
+ /** The wrapper of `node` in a `wrap` region, created (with its end anchor) on first use. */
347
+ private _wrapperFor;
348
+ /** The anchor that ends `wrapper`, created or moved back to the end if needed. */
349
+ private _wrapEnd;
350
+ /**
351
+ * Keeps a `wrap` region one node per wrapper, whatever the consumer did to the
352
+ * wrapped nodes directly (`node.before(x)`, `node.replaceWith(y)`, `remove()`,
353
+ * as Svelte and Solid do): a node the region accepts that sits inside a wrapper
354
+ * without being its node gets a wrapper of its own at the same position, and
355
+ * wrappers whose node left are removed.
356
+ */
357
+ private _normalizeWrappers;
358
+ /**
359
+ * `host.insertBefore(node, ref)` where `ref` is the end anchor of a wrapper:
360
+ * a framework that looked up `previousItem.nextSibling` inserts right after
361
+ * that item, so the node goes into a wrapper of its own after that one.
362
+ */
363
+ isWrapEnd(node: Node): boolean;
364
+ private _isAfterEnd;
365
+ private _observeContainer;
366
+ private _regionNodes;
367
+ private _reconcile;
368
+ /** Development builds only (Lit's dev build defines `enabledWarnings`); once per host. */
369
+ private _warnIfRequiredMissing;
370
+ }