@kirana-ui/web 0.0.0 → 0.2.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 (168) hide show
  1. package/LICENSE +1 -1
  2. package/llms.txt +3000 -0
  3. package/package.json +231 -6
  4. package/skills/kirana-ui-primitives/SKILL.md +142 -0
  5. package/src/accordion.d.ts +23 -0
  6. package/src/accordion.js +68 -0
  7. package/src/accordion.js.map +1 -0
  8. package/src/agent.d.ts +1 -0
  9. package/src/agent.js +1 -0
  10. package/src/alert-dialog.d.ts +17 -0
  11. package/src/alert-dialog.js +36 -0
  12. package/src/alert-dialog.js.map +1 -0
  13. package/src/around.d.ts +46 -0
  14. package/src/around.js +95 -0
  15. package/src/around.js.map +1 -0
  16. package/src/autocomplete.d.ts +19 -0
  17. package/src/autocomplete.js +43 -0
  18. package/src/autocomplete.js.map +1 -0
  19. package/src/autosize.d.ts +15 -0
  20. package/src/autosize.js +18 -0
  21. package/src/autosize.js.map +1 -0
  22. package/src/avatar.d.ts +19 -0
  23. package/src/avatar.js +38 -0
  24. package/src/avatar.js.map +1 -0
  25. package/src/button.d.ts +15 -0
  26. package/src/button.js +21 -0
  27. package/src/button.js.map +1 -0
  28. package/src/calendar.d.ts +22 -0
  29. package/src/calendar.js +60 -0
  30. package/src/calendar.js.map +1 -0
  31. package/src/carousel.d.ts +16 -0
  32. package/src/carousel.js +34 -0
  33. package/src/carousel.js.map +1 -0
  34. package/src/checkbox.d.ts +19 -0
  35. package/src/checkbox.js +42 -0
  36. package/src/checkbox.js.map +1 -0
  37. package/src/collapsible.d.ts +16 -0
  38. package/src/collapsible.js +32 -0
  39. package/src/collapsible.js.map +1 -0
  40. package/src/combobox.d.ts +44 -0
  41. package/src/combobox.js +124 -0
  42. package/src/combobox.js.map +1 -0
  43. package/src/command.d.ts +20 -0
  44. package/src/command.js +61 -0
  45. package/src/command.js.map +1 -0
  46. package/src/context-menu.d.ts +18 -0
  47. package/src/context-menu.js +11 -0
  48. package/src/context-menu.js.map +1 -0
  49. package/src/date-field.d.ts +18 -0
  50. package/src/date-field.js +41 -0
  51. package/src/date-field.js.map +1 -0
  52. package/src/date-picker.d.ts +23 -0
  53. package/src/date-picker.js +69 -0
  54. package/src/date-picker.js.map +1 -0
  55. package/src/dates.d.ts +19 -0
  56. package/src/dates.js +70 -0
  57. package/src/dates.js.map +1 -0
  58. package/src/dialog.d.ts +19 -0
  59. package/src/dialog.js +40 -0
  60. package/src/dialog.js.map +1 -0
  61. package/src/drawer.d.ts +24 -0
  62. package/src/drawer.js +62 -0
  63. package/src/drawer.js.map +1 -0
  64. package/src/field.d.ts +16 -0
  65. package/src/field.js +47 -0
  66. package/src/field.js.map +1 -0
  67. package/src/fieldset.d.ts +12 -0
  68. package/src/fieldset.js +17 -0
  69. package/src/fieldset.js.map +1 -0
  70. package/src/form.d.ts +19 -0
  71. package/src/form.js +30 -0
  72. package/src/form.js.map +1 -0
  73. package/src/hover-card.d.ts +15 -0
  74. package/src/hover-card.js +12 -0
  75. package/src/hover-card.js.map +1 -0
  76. package/src/hover-popup.d.ts +6 -0
  77. package/src/hover-popup.js +37 -0
  78. package/src/hover-popup.js.map +1 -0
  79. package/src/index.d.ts +60 -0
  80. package/src/index.js +49 -0
  81. package/src/input.d.ts +17 -0
  82. package/src/input.js +22 -0
  83. package/src/input.js.map +1 -0
  84. package/src/label.d.ts +11 -0
  85. package/src/label.js +15 -0
  86. package/src/label.js.map +1 -0
  87. package/src/listbox.d.ts +22 -0
  88. package/src/listbox.js +54 -0
  89. package/src/listbox.js.map +1 -0
  90. package/src/menu.d.ts +26 -0
  91. package/src/menu.js +133 -0
  92. package/src/menu.js.map +1 -0
  93. package/src/menubar.d.ts +16 -0
  94. package/src/menubar.js +22 -0
  95. package/src/menubar.js.map +1 -0
  96. package/src/message-scroller.d.ts +16 -0
  97. package/src/message-scroller.js +30 -0
  98. package/src/message-scroller.js.map +1 -0
  99. package/src/meter.d.ts +16 -0
  100. package/src/meter.js +40 -0
  101. package/src/meter.js.map +1 -0
  102. package/src/navigation-menu.d.ts +20 -0
  103. package/src/navigation-menu.js +71 -0
  104. package/src/navigation-menu.js.map +1 -0
  105. package/src/number-field.d.ts +21 -0
  106. package/src/number-field.js +57 -0
  107. package/src/number-field.js.map +1 -0
  108. package/src/otp.d.ts +19 -0
  109. package/src/otp.js +64 -0
  110. package/src/otp.js.map +1 -0
  111. package/src/pagination.d.ts +18 -0
  112. package/src/pagination.js +45 -0
  113. package/src/pagination.js.map +1 -0
  114. package/src/popover.d.ts +20 -0
  115. package/src/popover.js +34 -0
  116. package/src/popover.js.map +1 -0
  117. package/src/progress.d.ts +16 -0
  118. package/src/progress.js +40 -0
  119. package/src/progress.js.map +1 -0
  120. package/src/qr-code.d.ts +13 -0
  121. package/src/qr-code.js +24 -0
  122. package/src/qr-code.js.map +1 -0
  123. package/src/radio-group.d.ts +17 -0
  124. package/src/radio-group.js +40 -0
  125. package/src/radio-group.js.map +1 -0
  126. package/src/resizable.d.ts +16 -0
  127. package/src/resizable.js +38 -0
  128. package/src/resizable.js.map +1 -0
  129. package/src/runtime.d.ts +157 -0
  130. package/src/runtime.js +477 -0
  131. package/src/runtime.js.map +1 -0
  132. package/src/scroll-area.d.ts +18 -0
  133. package/src/scroll-area.js +37 -0
  134. package/src/scroll-area.js.map +1 -0
  135. package/src/select.d.ts +33 -0
  136. package/src/select.js +107 -0
  137. package/src/select.js.map +1 -0
  138. package/src/separator.d.ts +12 -0
  139. package/src/separator.js +14 -0
  140. package/src/separator.js.map +1 -0
  141. package/src/slider.d.ts +25 -0
  142. package/src/slider.js +71 -0
  143. package/src/slider.js.map +1 -0
  144. package/src/switch.d.ts +18 -0
  145. package/src/switch.js +37 -0
  146. package/src/switch.js.map +1 -0
  147. package/src/tabs.d.ts +16 -0
  148. package/src/tabs.js +31 -0
  149. package/src/tabs.js.map +1 -0
  150. package/src/testing.d.ts +1 -0
  151. package/src/testing.js +1 -0
  152. package/src/toast.d.ts +30 -0
  153. package/src/toast.js +93 -0
  154. package/src/toast.js.map +1 -0
  155. package/src/toggle-group.d.ts +22 -0
  156. package/src/toggle-group.js +37 -0
  157. package/src/toggle-group.js.map +1 -0
  158. package/src/toggle.d.ts +18 -0
  159. package/src/toggle.js +32 -0
  160. package/src/toggle.js.map +1 -0
  161. package/src/toolbar.d.ts +17 -0
  162. package/src/toolbar.js +31 -0
  163. package/src/toolbar.js.map +1 -0
  164. package/src/tooltip.d.ts +15 -0
  165. package/src/tooltip.js +12 -0
  166. package/src/tooltip.js.map +1 -0
  167. package/README.md +0 -7
  168. package/index.js +0 -5
package/src/runtime.js ADDED
@@ -0,0 +1,477 @@
1
+ import { bind, effect, sameProps, signal } from "@kirana-ui/core";
2
+ // src/runtime.ts
3
+ const ENTRY = /* @__PURE__ */ new WeakMap();
4
+ /** The entry an element was stamped for, or the nearest around it: a part reads its own. */
5
+ function entryAround(element) {
6
+ for (let each = element; each; each = each.parentNode) if (ENTRY.has(each)) return ENTRY.get(each);
7
+ }
8
+ /** `{name}` in a text, for each name there is a value for; another brace is the page's own. */
9
+ const fill = (text, values) => text.replace(/\{([A-Za-z_][\w-]*)\}/g, (whole, name) => name in values ? String(values[name] ?? "") : whole);
10
+ const camel = (name) => name.replace(/-([a-z])/g, (_all, letter) => letter.toUpperCase());
11
+ const hosts = /* @__PURE__ */ new Set();
12
+ const OWNER = Symbol("kui-owner");
13
+ let made = 0;
14
+ /**
15
+ * Whether an element is a component's: one that was defined, or a `kui-` one that is yet to
16
+ * be (its entry is imported later). What is inside it is its own from the start, and not a
17
+ * part of the component around it that happens to have a part of the same name.
18
+ */
19
+ const ours = (element) => hosts.has(element.localName) || element.localName.startsWith("kui-");
20
+ /** The component a part belongs to: the nearest around it, or the one that moved it to the page's end. */
21
+ function ownerOf(element) {
22
+ for (let each = element.parentElement; each; each = each.parentElement) {
23
+ if (ours(each)) return each;
24
+ const moved = each[OWNER];
25
+ if (moved) return moved;
26
+ }
27
+ return null;
28
+ }
29
+ /**
30
+ * The controller of the component around a custom element: the field a control is in, the
31
+ * group a toggle is one of. Through a portal too: what was moved to the page's end is still
32
+ * inside what it was written in.
33
+ */
34
+ function controllerAround(host, tag) {
35
+ return hostAround(host, [tag])?.controller;
36
+ }
37
+ /** The nearest component around a custom element that is one of `tags`: which, and its controller. */
38
+ function hostAround(host, tags) {
39
+ for (let each = ownerOf(host); each; each = ownerOf(each)) if (tags.includes(each.localName)) return {
40
+ tag: each.localName,
41
+ controller: each.controller
42
+ };
43
+ }
44
+ /** The nearest element around `element` (or itself) that is the part called `name`. */
45
+ function partAround(element, name) {
46
+ return element.closest(`[kui-part="${name}"]`);
47
+ }
48
+ let settling;
49
+ /**
50
+ * A page's markup is drawn before its components begin, so a part's style (a slider thumb's
51
+ * place) reaches an element the browser has already styled, and a design's `transition` on it
52
+ * would run as the page begins: each thumb gliding to where it was all along. A framework's
53
+ * element has its style before it is first drawn; here what the first style started is ended
54
+ * before the page is drawn again, once for all the parts of a pass.
55
+ */
56
+ function settle(element) {
57
+ if (typeof element.getAnimations !== "function") return;
58
+ if (!settling) {
59
+ const written = settling = [];
60
+ queueMicrotask(() => {
61
+ settling = void 0;
62
+ for (const each of written) for (const animation of each.getAnimations()) if (animation instanceof CSSTransition) animation.cancel();
63
+ });
64
+ }
65
+ settling.push(element);
66
+ }
67
+ /**
68
+ * Puts a part on an element, and takes it off whole: what the part wrote is gone with it. A
69
+ * framework draws a new element each time a part comes back; here the same element is the
70
+ * part again, and must not still say what it said before (`data-closed`, `aria-controls`).
71
+ */
72
+ function put(element, part, drawn = false) {
73
+ const before = new Map(Array.from(element.attributes, (each) => [each.name, each.value]));
74
+ const unbind = bind(element, part);
75
+ if (drawn && part.props.peek().style) settle(element);
76
+ return () => {
77
+ unbind();
78
+ for (const { name } of Array.from(element.attributes)) if (!before.has(name) && name !== "class") element.removeAttribute(name);
79
+ for (const [name, value] of before) if (name !== "class" && element.getAttribute(name) !== value) element.setAttribute(name, value);
80
+ };
81
+ }
82
+ /**
83
+ * The props of something inside a component that has props of its own (a menu's checkbox
84
+ * item, its radio group), read from its element's `kui-` attributes: `kui-checked`,
85
+ * `kui-default-value`. What it tells is told from that element, and may be refused; a value
86
+ * its element was given is held there, and one the page writes later is followed.
87
+ */
88
+ function partProps(element, kinds, changes) {
89
+ const attribute = (name) => `kui-${name}`;
90
+ const told = {};
91
+ const all = () => {
92
+ const next = { ...told };
93
+ for (const [name, kind] of Object.entries(kinds)) {
94
+ const text = element.getAttribute(attribute(name));
95
+ if (text !== null) next[camel(name)] = read(kind, text);
96
+ }
97
+ return next;
98
+ };
99
+ const source = signal({}, sameProps);
100
+ for (const [callback, { event, prop }] of Object.entries(changes)) told[callback] = (value, details) => {
101
+ const heard = new CustomEvent(event, {
102
+ detail: {
103
+ [prop]: value,
104
+ details
105
+ },
106
+ bubbles: true,
107
+ cancelable: true
108
+ });
109
+ if (!element.dispatchEvent(heard)) return details?.cancel();
110
+ const held = attribute(prop.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`));
111
+ if (element.hasAttribute(held)) element.setAttribute(held, String(value));
112
+ source.set(all());
113
+ };
114
+ source.set(all());
115
+ return {
116
+ props: source,
117
+ mount() {
118
+ const observer = new MutationObserver(() => source.set(all()));
119
+ observer.observe(element, {
120
+ attributes: true,
121
+ attributeFilter: Object.keys(kinds).map(attribute)
122
+ });
123
+ return () => observer.disconnect();
124
+ }
125
+ };
126
+ }
127
+ function read(kind, text) {
128
+ if (kind === "boolean") return text !== null && text !== "false";
129
+ if (text === null) return void 0;
130
+ return kind === "number" ? Number(text) : text;
131
+ }
132
+ const waiting = /* @__PURE__ */ new Set();
133
+ /** Whether a component around `element` has yet to begin: what is inside it reads it. */
134
+ function early(element) {
135
+ for (let each = element.parentElement; each; each = each.parentElement) {
136
+ const moved = each[OWNER];
137
+ if (moved) return early(moved);
138
+ if (ours(each) && !each.controller) return true;
139
+ }
140
+ return false;
141
+ }
142
+ /** What can be a part: an element of the page, one of a drawing (`<svg>`, `<path>`) too. */
143
+ const drawable = (node) => node instanceof Element;
144
+ /**
145
+ * Defines a component's custom element, and gives its name (for
146
+ * `customElements.whenDefined`). Where there are no custom elements (a server) it defines
147
+ * nothing.
148
+ */
149
+ function defineElement(spec) {
150
+ if (typeof customElements === "undefined" || customElements.get(spec.tag)) return spec.tag;
151
+ hosts.add(spec.tag);
152
+ const names = Object.keys(spec.props);
153
+ class KuiElement extends HTMLElement {
154
+ static observedAttributes = names;
155
+ controller;
156
+ #props;
157
+ #given = {};
158
+ #held = /* @__PURE__ */ new Map();
159
+ #stops = [];
160
+ #leaving = false;
161
+ #first = false;
162
+ #watch = () => {};
163
+ connectedCallback() {
164
+ this.#leaving = false;
165
+ this.begin();
166
+ }
167
+ /** Begins, unless a component around it has not: then it waits for that one. */
168
+ begin() {
169
+ if (this.controller || !this.isConnected) return;
170
+ if (early(this)) return void waiting.add(this);
171
+ waiting.delete(this);
172
+ if (!this.style.display) this.style.display = "contents";
173
+ const initial = { id: this.getAttribute("kui-id") || `kui-${++made}` };
174
+ for (const name of names) {
175
+ const text = this.getAttribute(name);
176
+ if (text !== null) initial[camel(name)] = read(spec.props[name], text);
177
+ }
178
+ Object.assign(initial, this.#given);
179
+ for (const [callback, { event, prop, hold }] of Object.entries(spec.changes)) initial[callback] = (value, details) => {
180
+ const told = new CustomEvent(event, {
181
+ detail: {
182
+ [prop]: value,
183
+ details
184
+ },
185
+ bubbles: true,
186
+ cancelable: true
187
+ });
188
+ if (!this.dispatchEvent(told)) return details?.cancel();
189
+ if (hold !== false && this.given(prop) !== void 0) this.give(prop, value);
190
+ };
191
+ this.#props = signal(initial, sameProps);
192
+ this.controller = spec.create(this.#props, this);
193
+ const unmount = this.controller.mount?.();
194
+ if (unmount) this.#stops.push(unmount);
195
+ const observer = new MutationObserver((records) => {
196
+ for (const record of records) {
197
+ for (const node of record.removedNodes) if (drawable(node)) this.#release(node);
198
+ for (const node of record.addedNodes) if (drawable(node)) this.#scan(node);
199
+ }
200
+ });
201
+ observer.observe(this, {
202
+ childList: true,
203
+ subtree: true
204
+ });
205
+ this.#watch = (element) => observer.observe(element, {
206
+ childList: true,
207
+ subtree: true
208
+ });
209
+ this.#stops.push(() => observer.disconnect());
210
+ this.#first = true;
211
+ for (const each of Array.from(this.children)) if (drawable(each)) this.#scan(each);
212
+ this.#first = false;
213
+ const inner = spec.inner?.(this.controller);
214
+ if (inner) {
215
+ const input = this.ownerDocument.createElement("input");
216
+ let unbind;
217
+ const drawn = effect(() => {
218
+ const wanted = inner.mounted?.get() ?? true;
219
+ if (wanted && !unbind) {
220
+ this.append(input);
221
+ unbind = bind(input, inner.part);
222
+ } else if (!wanted && unbind) {
223
+ unbind();
224
+ unbind = void 0;
225
+ input.remove();
226
+ }
227
+ });
228
+ this.#stops.push(() => {
229
+ drawn();
230
+ unbind?.();
231
+ input.remove();
232
+ });
233
+ }
234
+ for (const each of Array.from(waiting)) each.begin();
235
+ }
236
+ disconnectedCallback() {
237
+ this.#leaving = true;
238
+ queueMicrotask(() => {
239
+ if (!this.#leaving || this.isConnected) return;
240
+ waiting.delete(this);
241
+ for (const held of this.#held.values()) held.stop();
242
+ this.#held.clear();
243
+ for (const stop of this.#stops.splice(0).reverse()) stop();
244
+ delete this.controller;
245
+ this.#props = void 0;
246
+ });
247
+ }
248
+ attributeChangedCallback(name, _before, text) {
249
+ this.give(camel(name), read(spec.props[name], text));
250
+ }
251
+ /** A prop as it was last given: by an attribute, or as a property. */
252
+ given(prop) {
253
+ return this.#props ? this.#props.peek()[prop] : this.#given[prop];
254
+ }
255
+ give(prop, value) {
256
+ if (!this.#props) return void (this.#given[prop] = value);
257
+ if (!Object.is(this.#props.peek()[prop], value)) this.#props.set({
258
+ ...this.#props.peek(),
259
+ [prop]: value
260
+ });
261
+ }
262
+ /** Takes the parts in a subtree, in the page's order: one that leaves takes its own with it. */
263
+ #scan(element) {
264
+ if (!element.isConnected) return;
265
+ if (element instanceof HTMLTemplateElement) {
266
+ if (element.hasAttribute("kui-each") && ownerOf(element) === this) this.#each(element);
267
+ return;
268
+ }
269
+ if (element.hasAttribute("kui-part")) this.#adopt(element);
270
+ for (const each of Array.from(element.children)) if (drawable(each)) this.#scan(each);
271
+ }
272
+ /** Draws a list from its template: a copy for each entry, where the template was. */
273
+ #each(template) {
274
+ const list = spec.lists?.[template.getAttribute("kui-each")]?.(this.controller, entryAround(template));
275
+ if (!list) return;
276
+ const mark = this.ownerDocument.createComment("");
277
+ if (ENTRY.has(template)) ENTRY.set(mark, ENTRY.get(template));
278
+ template.replaceWith(mark);
279
+ const rows = /* @__PURE__ */ new Map();
280
+ const stamp = (entry) => {
281
+ const type = list.type?.(entry);
282
+ const copy = template.content.cloneNode(true);
283
+ for (const node of Array.from(copy.childNodes)) {
284
+ const blank = node.nodeType === Node.TEXT_NODE && !node.textContent.trim();
285
+ const other = node instanceof Element && node.hasAttribute("kui-when") && node.getAttribute("kui-when") !== type;
286
+ if (blank || other || node.nodeType === Node.COMMENT_NODE) node.remove();
287
+ }
288
+ const written = [];
289
+ const walker = this.ownerDocument.createTreeWalker(copy, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT);
290
+ for (let node = walker.nextNode(); node; node = walker.nextNode()) if (node instanceof Text) {
291
+ if (node.data.includes("{")) written.push([node, node.data]);
292
+ } else if (!(node instanceof HTMLTemplateElement)) {
293
+ for (const attribute of Array.from(node.attributes)) if (attribute.value.includes("{")) written.push([attribute, attribute.value]);
294
+ }
295
+ const nodes = Array.from(copy.childNodes);
296
+ for (const node of nodes) ENTRY.set(node, entry);
297
+ return {
298
+ entry,
299
+ nodes,
300
+ written
301
+ };
302
+ };
303
+ const write = (row) => {
304
+ const values = list.values?.(row.entry) ?? row.entry ?? {};
305
+ for (const [node, text] of row.written) {
306
+ const next = fill(text, values);
307
+ if (node instanceof Text) {
308
+ if (node.data !== next) node.data = next;
309
+ } else if (node.value !== next) node.value = next;
310
+ }
311
+ };
312
+ const draw = () => {
313
+ const { entries } = list;
314
+ const next = "get" in entries ? entries.get() : entries;
315
+ const parent = mark.parentNode;
316
+ if (!parent) return;
317
+ const kept = /* @__PURE__ */ new Set();
318
+ const fresh = [];
319
+ const ordered = next.map((entry) => {
320
+ const key = list.key(entry);
321
+ kept.add(key);
322
+ let row = rows.get(key);
323
+ if (!row) {
324
+ rows.set(key, row = stamp(entry));
325
+ fresh.push(row);
326
+ write(row);
327
+ } else if (row.entry !== entry) {
328
+ row.entry = entry;
329
+ for (const node of row.nodes) ENTRY.set(node, entry);
330
+ write(row);
331
+ }
332
+ return row;
333
+ });
334
+ for (const [key, row] of rows) {
335
+ if (kept.has(key)) continue;
336
+ rows.delete(key);
337
+ for (const node of row.nodes) node.remove();
338
+ }
339
+ let before = mark;
340
+ for (const row of ordered.reverse()) for (const node of row.nodes.toReversed()) {
341
+ if (node.nextSibling !== before || node.parentNode !== parent) parent.insertBefore(node, before);
342
+ before = node;
343
+ }
344
+ for (const row of fresh) for (const node of row.nodes) if (drawable(node)) this.#scan(node);
345
+ };
346
+ const stop = effect(draw);
347
+ this.#stops.push(() => {
348
+ stop();
349
+ for (const row of rows.values()) for (const node of row.nodes) node.remove();
350
+ rows.clear();
351
+ mark.replaceWith(template);
352
+ });
353
+ }
354
+ #adopt(element) {
355
+ if (this.#held.has(element) || ownerOf(element) !== this || !this.controller) return;
356
+ const name = element.getAttribute("kui-part");
357
+ if (name === "portal") return this.#portal(element);
358
+ const given = spec.parts[name]?.(this.controller, element);
359
+ if (!given) return;
360
+ const drawn = "attach" in given ? { part: given } : given;
361
+ const stops = [];
362
+ const held = {
363
+ parked: false,
364
+ stop: () => {
365
+ for (const stop of stops.splice(0).reverse()) stop();
366
+ }
367
+ };
368
+ this.#held.set(element, held);
369
+ const unmount = drawn.mount?.();
370
+ if (unmount) stops.push(unmount);
371
+ if (drawn.inner) {
372
+ const last = element.lastElementChild;
373
+ const taken = last instanceof HTMLInputElement && last.type === "hidden" ? last : void 0;
374
+ const input = taken ?? this.ownerDocument.createElement("input");
375
+ if (!taken) element.append(input);
376
+ stops.push(bind(input, drawn.inner), () => {
377
+ if (!taken) input.remove();
378
+ });
379
+ }
380
+ if (drawn.text && element.childNodes.length === 0) {
381
+ const { text } = drawn;
382
+ stops.push(effect(() => void (element.textContent = text.get() ?? "")), () => void (element.textContent = ""));
383
+ }
384
+ const mounted = element.hasAttribute("kui-keep-mounted") ? void 0 : drawn.mounted;
385
+ const first = this.#first;
386
+ if (!mounted) return void stops.push(put(element, drawn.part, first));
387
+ const home = this.ownerDocument.createComment("");
388
+ let unbind;
389
+ stops.push(effect(() => {
390
+ const elsewhere = drawn.into?.get();
391
+ const own = first && !elsewhere && !held.parked && !unbind;
392
+ if (mounted.get() && (!drawn.into || elsewhere)) {
393
+ if (elsewhere) {
394
+ if (!held.parked && element.parentNode) element.replaceWith(home);
395
+ held.parked = true;
396
+ if (element.parentNode !== elsewhere) elsewhere.append(element);
397
+ } else if (held.parked) {
398
+ held.parked = false;
399
+ home.replaceWith(element);
400
+ }
401
+ unbind ??= put(element, drawn.part, own);
402
+ } else {
403
+ unbind?.();
404
+ unbind = void 0;
405
+ if (!held.parked && element.parentNode) {
406
+ held.parked = true;
407
+ element.replaceWith(home);
408
+ } else if (drawn.into) element.remove();
409
+ }
410
+ }), () => {
411
+ unbind?.();
412
+ if (held.parked) home.replaceWith(element);
413
+ });
414
+ }
415
+ /** What is inside is drawn at the end of the page while the component is mounted. */
416
+ #portal(element) {
417
+ const mounted = this.controller.mounted;
418
+ if (!mounted) return;
419
+ element[OWNER] = this;
420
+ const home = this.ownerDocument.createComment("");
421
+ const held = {
422
+ parked: false,
423
+ stop: () => {}
424
+ };
425
+ this.#held.set(element, held);
426
+ this.#watch(element);
427
+ const body = this.ownerDocument.body;
428
+ const stop = effect(() => {
429
+ if (mounted.get()) {
430
+ if (element.parentNode === body) return;
431
+ if (!home.parentNode && element.parentNode) element.replaceWith(home);
432
+ held.parked = false;
433
+ element.setAttribute("data-kirana-portal", "");
434
+ body.append(element);
435
+ this.#scan(element);
436
+ } else if (!held.parked) {
437
+ held.parked = true;
438
+ if (!home.parentNode && element.parentNode) element.replaceWith(home);
439
+ else element.remove();
440
+ }
441
+ });
442
+ held.stop = () => {
443
+ stop();
444
+ element.removeAttribute("data-kirana-portal");
445
+ if (home.parentNode) home.replaceWith(element);
446
+ else element.remove();
447
+ };
448
+ }
449
+ #release(element) {
450
+ if (element.isConnected) return;
451
+ for (const [each, held] of this.#held) {
452
+ if (each !== element && !element.contains(each)) continue;
453
+ if (each === element && held.parked) continue;
454
+ held.stop();
455
+ this.#held.delete(each);
456
+ }
457
+ }
458
+ }
459
+ for (const name of [...names, ...spec.properties ?? []]) {
460
+ const prop = camel(name);
461
+ Object.defineProperty(KuiElement.prototype, prop, {
462
+ configurable: true,
463
+ get() {
464
+ const state = this.controller?.[prop];
465
+ return typeof state?.peek === "function" ? state.peek() : this.given(prop);
466
+ },
467
+ set(value) {
468
+ this.give(prop, value);
469
+ }
470
+ });
471
+ }
472
+ customElements.define(spec.tag, KuiElement);
473
+ return spec.tag;
474
+ }
475
+ export { controllerAround, defineElement, entryAround, hostAround, partAround, partProps };
476
+
477
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.js","names":[],"sources":["../../../../packages/web/src/runtime.ts"],"sourcesContent":["import { bind, effect, sameProps, signal } from \"@kirana-ui/core\"\nimport type { ChangeDetails, Part, ReadonlySignal, Signal } from \"@kirana-ui/core\"\n\n/**\n * A component as a custom element, for a page with no framework.\n *\n * The custom element (`<kui-dialog>`) holds the component and draws nothing: it takes no room\n * (`display: contents`) and no attribute of the component's. Its parts are the page's own\n * elements, named by `kui-part` (`<button kui-part=\"trigger\">`), the root among them. So a\n * trigger is a real button and a switch a real button, and the page is the page the other\n * adapters draw: nothing is wrapped, and there is no shadow root for a design to reach into.\n *\n * A part that is in the page only some of the time (a closed panel, a popup) is taken out of\n * the page while it is not, and put back where it was; `kui-keep-mounted` keeps it.\n */\n\n/** What a part's name gives: the part, and what comes with it. */\nexport interface Drawn {\n readonly part: Part\n /** In the page only while this holds. */\n readonly mounted?: ReadonlySignal<boolean> | undefined\n /** Runs while the part is the component's. Returns the stop. */\n mount?(): () => void\n /** A hidden native input the part draws itself, as its last child. */\n readonly inner?: Part | undefined\n /**\n * Where the part is drawn while it is mounted, when that is not where it was written: a\n * navigation menu's content, in the menu's one viewport. Out of the page while there is none.\n */\n readonly into?: ReadonlySignal<HTMLElement | undefined> | undefined\n /** What the part's element says, when the page gave it nothing to say. */\n readonly text?: ReadonlySignal<string | undefined> | undefined\n}\n\ntype Kind = \"boolean\" | \"string\" | \"number\"\n\n/** A list a component draws from a `<template kui-each>`. */\nexport interface Each<Entry = any> {\n readonly entries: ReadonlySignal<readonly Entry[]> | readonly Entry[]\n /** What an entry is known by from one drawing to the next. */\n key(entry: Entry): string | number\n /**\n * Which of the template's elements an entry is drawn with, when they differ: the ones\n * whose `kui-when` says so (a page, an ellipsis). Elements without `kui-when` are for all.\n */\n type?(entry: Entry): string\n /**\n * What `{name}` stands for in the template's text and attributes\n * (`data-testid=\"row-{id}\"`). Left out: the entry's own fields.\n */\n values?(entry: Entry): Record<string, unknown>\n}\n\nconst ENTRY = new WeakMap<Node, unknown>()\n\n/** The entry an element was stamped for, or the nearest around it: a part reads its own. */\nexport function entryAround<Entry>(element: Node): Entry | undefined {\n for (let each: Node | null = element; each; each = each.parentNode) {\n if (ENTRY.has(each)) return ENTRY.get(each) as Entry\n }\n return undefined\n}\n\n/** `{name}` in a text, for each name there is a value for; another brace is the page's own. */\nconst fill = (text: string, values: Record<string, unknown>) =>\n text.replace(/\\{([A-Za-z_][\\w-]*)\\}/g, (whole, name: string) =>\n name in values ? String(values[name] ?? \"\") : whole\n )\n\ninterface Row {\n entry: unknown\n nodes: ChildNode[]\n /** Where a `{name}` was written: read again when the entry changes. */\n written: (readonly [Attr | Text, string])[]\n}\n\nexport interface ElementSpec<Props extends { id: string }, Controller> {\n /** The custom element's name: `kui-dialog`. */\n tag: string\n /** Its props by attribute name, each with how an attribute's text is read. */\n props: Record<string, Kind>\n /** Props that are only properties: a function, an object. By their names as properties. */\n properties?: readonly string[] | undefined\n /**\n * What the component draws a list of, by name: a calendar's weeks, a toast for each\n * message. The page writes one of an entry as a `<template kui-each=\"name\">` where the\n * list goes, and the element stamps it for each entry, keyed, so an entry that stays keeps\n * its elements. `around` is the entry of the list this one is written in (a week, for its\n * days).\n */\n lists?: Record<string, (controller: Controller, around: unknown) => Each | undefined>\n /**\n * The hidden native input a form reads, for a component with no part to hold it: drawn as\n * the element's last child, while `mounted` (a select with a name).\n */\n inner?(controller: Controller): { part: Part; mounted?: ReadonlySignal<boolean> | undefined }\n /** `host` is the custom element: what is around it (a field, a group) is found from it. */\n create(props: ReadonlySignal<Props>, host: HTMLElement): Controller\n /**\n * Its change callbacks: the event each is told as, and the prop the element then holds\n * (`open`). The event is cancelable: `preventDefault()` keeps the value as it was.\n */\n changes: Record<string, { event: string; prop: string; hold?: boolean }>\n /** Each part by its `kui-part` name. */\n parts: Record<string, (controller: Controller, element: HTMLElement) => Part | Drawn | undefined>\n}\n\ndeclare const DEFINED: unique symbol\n\n/**\n * A custom element's name as `defineElement` gives it. For TypeScript it also says what the\n * element was defined from, which `ElementOf` reads back; in the page it is the name alone.\n */\nexport type Tag<Props = unknown, Controller = unknown> = string & {\n readonly [DEFINED]?: readonly [Props, Controller]\n}\n\n/**\n * What a component tells: an event whose `detail` holds the value under its prop's name\n * (`detail.open`, `detail.values`) and why it changed (`detail.details.reason`).\n * `preventDefault()` keeps the value as it was.\n */\nexport type Told<Prop extends string, Value> = CustomEvent<\n { readonly [Name in Prop]: Value } & { readonly details: ChangeDetails }\n>\n\n/** A tag with its props said, where `defineElement` was left to work them out. */\nexport type As<Defined, Props> =\n Defined extends Tag<unknown, infer Controller> ? Tag<Props, Controller> : never\n\ntype Callback<Props, Name> = Name extends keyof Props\n ? Extract<Props[Name], (...given: never[]) => unknown>\n : never\n\ninterface Listens<Events> {\n addEventListener<Type extends keyof Events>(\n type: Type,\n listener: (this: HTMLElement, event: Events[Type]) => void,\n options?: boolean | AddEventListenerOptions\n ): void\n removeEventListener<Type extends keyof Events>(\n type: Type,\n listener: (this: HTMLElement, event: Events[Type]) => void,\n options?: boolean | EventListenerOptions\n ): void\n}\n\n/**\n * A component's custom element as TypeScript knows it, from its `tag`: its props as properties\n * (`element.open = true`), its controller once it has begun, and its events with their\n * `detail`. `Changes` names each event with the callback it tells and the prop it holds\n * (`{ \"open-change\": [\"onOpenChange\", \"open\"] }`), as the element's `changes` do; `More` is\n * for events its parts tell from their own elements, which reach it too.\n */\nexport type ElementOf<Defined, Changes = {}, More = {}> =\n Defined extends Tag<infer Props, infer Controller>\n ? Listens<\n {\n readonly [Event in keyof Changes]: Changes[Event] extends readonly [\n infer Name,\n infer Prop extends string,\n ]\n ? Told<Prop, Parameters<Callback<Props, Name>>[0]>\n : never\n } & More\n > & {\n -readonly [\n Name in keyof Props as Name extends \"id\" | `on${Capitalize<string>}` ? never : Name\n ]?: Props[Name]\n } & { controller?: Controller } & HTMLElement\n : never\n\nconst camel = (name: string) =>\n name.replace(/-([a-z])/g, (_all, letter: string) => letter.toUpperCase())\nconst hosts = new Set<string>()\nconst OWNER = Symbol(\"kui-owner\")\nlet made = 0\n\ntype Owned = HTMLElement & { [OWNER]?: HTMLElement }\n\n/**\n * Whether an element is a component's: one that was defined, or a `kui-` one that is yet to\n * be (its entry is imported later). What is inside it is its own from the start, and not a\n * part of the component around it that happens to have a part of the same name.\n */\nconst ours = (element: Element) =>\n hosts.has(element.localName) || element.localName.startsWith(\"kui-\")\n\n/** The component a part belongs to: the nearest around it, or the one that moved it to the page's end. */\nfunction ownerOf(element: Element): HTMLElement | null {\n for (let each: Element | null = element.parentElement; each; each = each.parentElement) {\n if (ours(each)) return each as HTMLElement\n const moved = (each as Owned)[OWNER]\n if (moved) return moved\n }\n return null\n}\n\n/**\n * The controller of the component around a custom element: the field a control is in, the\n * group a toggle is one of. Through a portal too: what was moved to the page's end is still\n * inside what it was written in.\n */\nexport function controllerAround<Controller>(host: Element, tag: string): Controller | undefined {\n return hostAround(host, [tag])?.controller as Controller | undefined\n}\n\n/** The nearest component around a custom element that is one of `tags`: which, and its controller. */\nexport function hostAround(\n host: Element,\n tags: readonly string[]\n): { tag: string; controller: unknown } | undefined {\n for (let each: Element | null = ownerOf(host); each; each = ownerOf(each)) {\n if (tags.includes(each.localName))\n return { tag: each.localName, controller: (each as { controller?: unknown }).controller }\n }\n return undefined\n}\n\n/** The nearest element around `element` (or itself) that is the part called `name`. */\nexport function partAround(element: Element, name: string): HTMLElement | null {\n return element.closest<HTMLElement>(`[kui-part=\"${name}\"]`)\n}\n\n// Elements the page had drawn before their part gave them a style of its own.\nlet settling: HTMLElement[] | undefined\n\n/**\n * A page's markup is drawn before its components begin, so a part's style (a slider thumb's\n * place) reaches an element the browser has already styled, and a design's `transition` on it\n * would run as the page begins: each thumb gliding to where it was all along. A framework's\n * element has its style before it is first drawn; here what the first style started is ended\n * before the page is drawn again, once for all the parts of a pass.\n */\nfunction settle(element: HTMLElement): void {\n if (typeof element.getAnimations !== \"function\") return\n if (!settling) {\n const written: HTMLElement[] = (settling = [])\n queueMicrotask(() => {\n settling = undefined\n for (const each of written) {\n for (const animation of each.getAnimations()) {\n if (animation instanceof CSSTransition) animation.cancel()\n }\n }\n })\n }\n settling.push(element)\n}\n\n/**\n * Puts a part on an element, and takes it off whole: what the part wrote is gone with it. A\n * framework draws a new element each time a part comes back; here the same element is the\n * part again, and must not still say what it said before (`data-closed`, `aria-controls`).\n */\nfunction put(element: HTMLElement, part: Part, drawn = false): () => void {\n const before = new Map(Array.from(element.attributes, (each) => [each.name, each.value]))\n const unbind = bind(element, part)\n if (drawn && part.props.peek().style) settle(element)\n return () => {\n unbind()\n for (const { name } of Array.from(element.attributes)) {\n // Its classes are the page's own, whatever was added to them since.\n if (!before.has(name) && name !== \"class\") element.removeAttribute(name)\n }\n for (const [name, value] of before) {\n if (name !== \"class\" && element.getAttribute(name) !== value)\n element.setAttribute(name, value)\n }\n }\n}\n\n/**\n * The props of something inside a component that has props of its own (a menu's checkbox\n * item, its radio group), read from its element's `kui-` attributes: `kui-checked`,\n * `kui-default-value`. What it tells is told from that element, and may be refused; a value\n * its element was given is held there, and one the page writes later is followed.\n */\nexport function partProps<Props>(\n element: HTMLElement,\n kinds: Record<string, Kind>,\n changes: Record<string, { event: string; prop: string }>\n): { props: ReadonlySignal<Props>; mount(): () => void } {\n const attribute = (name: string) => `kui-${name}`\n const told: Record<string, unknown> = {}\n const all = () => {\n const next: Record<string, unknown> = { ...told }\n for (const [name, kind] of Object.entries(kinds)) {\n const text = element.getAttribute(attribute(name))\n if (text !== null) next[camel(name)] = read(kind, text)\n }\n return next as Props\n }\n const source = signal<Props>({} as Props, sameProps as (a: Props, b: Props) => boolean)\n for (const [callback, { event, prop }] of Object.entries(changes)) {\n told[callback] = (value: unknown, details?: ChangeDetails) => {\n const heard = new CustomEvent(event, {\n detail: { [prop]: value, details },\n bubbles: true,\n cancelable: true,\n })\n if (!element.dispatchEvent(heard)) return details?.cancel()\n const held = attribute(prop.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`))\n if (element.hasAttribute(held)) element.setAttribute(held, String(value))\n source.set(all())\n }\n }\n source.set(all())\n return {\n props: source,\n mount() {\n const observer = new MutationObserver(() => source.set(all()))\n observer.observe(element, {\n attributes: true,\n attributeFilter: Object.keys(kinds).map(attribute),\n })\n return () => observer.disconnect()\n },\n }\n}\n\nfunction read(kind: Kind, text: string | null): unknown {\n if (kind === \"boolean\") return text !== null && text !== \"false\"\n if (text === null) return undefined\n return kind === \"number\" ? Number(text) : text\n}\n\n// Components written inside one that has not begun: its element is not defined yet (its\n// entry is imported later), or it waits itself. They begin when it has.\nconst waiting = new Set<{ begin(): void }>()\n\n/** Whether a component around `element` has yet to begin: what is inside it reads it. */\nfunction early(element: Element): boolean {\n for (let each: Element | null = element.parentElement; each; each = each.parentElement) {\n // Moved to the page's end by a component that had begun: on from that one.\n const moved = (each as Owned)[OWNER]\n if (moved) return early(moved)\n if (ours(each) && !(each as { controller?: unknown }).controller) return true\n }\n return false\n}\n\n/** What can be a part: an element of the page, one of a drawing (`<svg>`, `<path>`) too. */\nconst drawable = (node: Node): node is HTMLElement => node instanceof Element\n\ninterface Held {\n stop(): void\n /** Taken out of the page by the component itself: still its part. */\n parked: boolean\n}\n\n/**\n * Defines a component's custom element, and gives its name (for\n * `customElements.whenDefined`). Where there are no custom elements (a server) it defines\n * nothing.\n */\nexport function defineElement<Props extends { id: string }, Controller extends object>(\n spec: ElementSpec<Props, Controller>\n): Tag<Props, Controller> {\n if (typeof customElements === \"undefined\" || customElements.get(spec.tag)) return spec.tag\n hosts.add(spec.tag)\n const names = Object.keys(spec.props)\n\n class KuiElement extends HTMLElement {\n static observedAttributes = names\n controller?: Controller\n #props?: Signal<Props> | undefined\n // Set as properties before the element was upgraded, or before it joined the page.\n #given: Record<string, unknown> = {}\n #held = new Map<HTMLElement, Held>()\n #stops: (() => void)[] = []\n #leaving = false\n // While the parts the page wrote are first taken: they were drawn before they were parts.\n #first = false\n #watch: (element: HTMLElement) => void = () => {}\n\n connectedCallback() {\n this.#leaving = false\n this.begin()\n }\n\n /** Begins, unless a component around it has not: then it waits for that one. */\n begin() {\n if (this.controller || !this.isConnected) return\n if (early(this)) return void waiting.add(this)\n waiting.delete(this)\n // It holds its parts and draws nothing: no box of its own between them and the page.\n if (!this.style.display) this.style.display = \"contents\"\n const initial: Record<string, unknown> = {\n id: this.getAttribute(\"kui-id\") || `kui-${++made}`,\n }\n for (const name of names) {\n const text = this.getAttribute(name)\n // An attribute that is not there says nothing: the component's own default holds.\n if (text !== null) initial[camel(name)] = read(spec.props[name]!, text)\n }\n Object.assign(initial, this.#given)\n for (const [callback, { event, prop, hold }] of Object.entries(spec.changes)) {\n initial[callback] = (value: unknown, details?: ChangeDetails) => {\n const told = new CustomEvent(event, {\n detail: { [prop]: value, details },\n bubbles: true,\n cancelable: true,\n })\n if (!this.dispatchEvent(told)) return details?.cancel()\n // A value that was given is held by the element from then on, as `<details open>`\n // holds its own: it follows what happens to it.\n if (hold !== false && this.given(prop) !== undefined) this.give(prop, value)\n }\n }\n this.#props = signal(initial as Props, sameProps as (a: Props, b: Props) => boolean)\n this.controller = spec.create(this.#props, this)\n const unmount = (this.controller as { mount?(): () => void }).mount?.()\n if (unmount) this.#stops.push(unmount)\n // Parts that come and go: a page that draws its rows later, a list that changes.\n const observer = new MutationObserver((records) => {\n for (const record of records) {\n for (const node of record.removedNodes) {\n if (drawable(node)) this.#release(node)\n }\n for (const node of record.addedNodes) if (drawable(node)) this.#scan(node)\n }\n })\n observer.observe(this, { childList: true, subtree: true })\n this.#watch = (element) => observer.observe(element, { childList: true, subtree: true })\n this.#stops.push(() => observer.disconnect())\n // A copy: a part that is not in the page yet is taken out as it is met.\n this.#first = true\n for (const each of Array.from(this.children)) if (drawable(each)) this.#scan(each)\n this.#first = false\n const inner = spec.inner?.(this.controller)\n if (inner) {\n const input = this.ownerDocument.createElement(\"input\")\n let unbind: (() => void) | undefined\n const drawn = effect(() => {\n const wanted = inner.mounted?.get() ?? true\n if (wanted && !unbind) {\n this.append(input)\n unbind = bind(input, inner.part)\n } else if (!wanted && unbind) {\n unbind()\n unbind = undefined\n input.remove()\n }\n })\n this.#stops.push(() => {\n drawn()\n unbind?.()\n input.remove()\n })\n }\n for (const each of Array.from(waiting)) each.begin()\n }\n\n disconnectedCallback() {\n // Moved, it comes straight back: only an element that has left is taken apart.\n this.#leaving = true\n queueMicrotask(() => {\n if (!this.#leaving || this.isConnected) return\n waiting.delete(this)\n for (const held of this.#held.values()) held.stop()\n this.#held.clear()\n for (const stop of this.#stops.splice(0).reverse()) stop()\n delete this.controller\n this.#props = undefined\n })\n }\n\n attributeChangedCallback(name: string, _before: string | null, text: string | null) {\n this.give(camel(name), read(spec.props[name]!, text))\n }\n\n /** A prop as it was last given: by an attribute, or as a property. */\n given(prop: string): unknown {\n return this.#props ? (this.#props.peek() as Record<string, unknown>)[prop] : this.#given[prop]\n }\n\n give(prop: string, value: unknown) {\n if (!this.#props) return void (this.#given[prop] = value)\n if (!Object.is((this.#props.peek() as Record<string, unknown>)[prop], value))\n this.#props.set({ ...this.#props.peek(), [prop]: value })\n }\n\n /** Takes the parts in a subtree, in the page's order: one that leaves takes its own with it. */\n #scan(element: HTMLElement) {\n if (!element.isConnected) return\n if (element instanceof HTMLTemplateElement) {\n if (element.hasAttribute(\"kui-each\") && ownerOf(element) === this) this.#each(element)\n return\n }\n if (element.hasAttribute(\"kui-part\")) this.#adopt(element)\n for (const each of Array.from(element.children)) if (drawable(each)) this.#scan(each)\n }\n\n /** Draws a list from its template: a copy for each entry, where the template was. */\n #each(template: HTMLTemplateElement) {\n const list = spec.lists?.[template.getAttribute(\"kui-each\")!]?.(\n this.controller!,\n entryAround(template)\n )\n if (!list) return\n // The template leaves the page for a mark: what is drawn is the page a framework draws.\n const mark = this.ownerDocument.createComment(\"\")\n if (ENTRY.has(template)) ENTRY.set(mark, ENTRY.get(template))\n template.replaceWith(mark)\n const rows = new Map<string | number, Row>()\n const stamp = (entry: unknown): Row => {\n const type = list.type?.(entry)\n const copy = template.content.cloneNode(true) as DocumentFragment\n for (const node of Array.from(copy.childNodes)) {\n const blank = node.nodeType === Node.TEXT_NODE && !node.textContent!.trim()\n const other =\n node instanceof Element &&\n node.hasAttribute(\"kui-when\") &&\n node.getAttribute(\"kui-when\") !== type\n if (blank || other || node.nodeType === Node.COMMENT_NODE) node.remove()\n }\n const written: (readonly [Attr | Text, string])[] = []\n const walker = this.ownerDocument.createTreeWalker(\n copy,\n NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT\n )\n for (let node = walker.nextNode(); node; node = walker.nextNode()) {\n // A list written in this one is filled when it is drawn, for its own entries.\n if (node instanceof Text) {\n if (node.data.includes(\"{\")) written.push([node, node.data])\n } else if (!(node instanceof HTMLTemplateElement)) {\n for (const attribute of Array.from((node as Element).attributes))\n if (attribute.value.includes(\"{\")) written.push([attribute, attribute.value])\n }\n }\n const nodes = Array.from(copy.childNodes)\n for (const node of nodes) ENTRY.set(node, entry)\n return { entry, nodes, written }\n }\n const write = (row: Row) => {\n const values =\n list.values?.(row.entry) ?? (row.entry as Record<string, unknown> | undefined) ?? {}\n for (const [node, text] of row.written) {\n const next = fill(text, values)\n if (node instanceof Text) {\n if (node.data !== next) node.data = next\n } else if (node.value !== next) node.value = next\n }\n }\n const draw = () => {\n const { entries } = list\n const next = \"get\" in entries ? entries.get() : entries\n const parent = mark.parentNode\n if (!parent) return\n const kept = new Set<string | number>()\n const fresh: Row[] = []\n const ordered = next.map((entry) => {\n const key = list.key(entry)\n kept.add(key)\n let row = rows.get(key)\n if (!row) {\n rows.set(key, (row = stamp(entry)))\n fresh.push(row)\n write(row)\n } else if (row.entry !== entry) {\n row.entry = entry\n for (const node of row.nodes) ENTRY.set(node, entry)\n write(row)\n }\n return row\n })\n for (const [key, row] of rows) {\n if (kept.has(key)) continue\n rows.delete(key)\n for (const node of row.nodes) node.remove()\n }\n // From the end: a copy that is where it belongs is not moved, and keeps focus.\n let before: ChildNode = mark\n for (const row of ordered.reverse()) {\n for (const node of row.nodes.toReversed()) {\n if (node.nextSibling !== before || node.parentNode !== parent)\n parent.insertBefore(node, before)\n before = node\n }\n }\n for (const row of fresh) for (const node of row.nodes) if (drawable(node)) this.#scan(node)\n }\n const stop = effect(draw)\n this.#stops.push(() => {\n stop()\n for (const row of rows.values()) for (const node of row.nodes) node.remove()\n rows.clear()\n mark.replaceWith(template)\n })\n }\n\n #adopt(element: HTMLElement) {\n if (this.#held.has(element) || ownerOf(element) !== this || !this.controller) return\n const name = element.getAttribute(\"kui-part\")!\n if (name === \"portal\") return this.#portal(element)\n const given = spec.parts[name]?.(this.controller, element)\n if (!given) return\n const drawn: Drawn = \"attach\" in given ? { part: given } : given\n const stops: (() => void)[] = []\n const held: Held = {\n parked: false,\n stop: () => {\n for (const stop of stops.splice(0).reverse()) stop()\n },\n }\n this.#held.set(element, held)\n const unmount = drawn.mount?.()\n if (unmount) stops.push(unmount)\n if (drawn.inner) {\n // One a server wrote there is taken over.\n const last = element.lastElementChild\n const taken = last instanceof HTMLInputElement && last.type === \"hidden\" ? last : undefined\n const input = taken ?? this.ownerDocument.createElement(\"input\")\n if (!taken) element.append(input)\n stops.push(bind(input, drawn.inner), () => {\n if (!taken) input.remove()\n })\n }\n if (drawn.text && element.childNodes.length === 0) {\n const { text } = drawn\n // Taken off, the element says nothing again: put back on (a popup opened a second\n // time), the text is the part's to write still, and not taken for the page's.\n stops.push(\n effect(() => void (element.textContent = text.get() ?? \"\")),\n () => void (element.textContent = \"\")\n )\n }\n const mounted = element.hasAttribute(\"kui-keep-mounted\") ? undefined : drawn.mounted\n const first = this.#first\n if (!mounted) return void stops.push(put(element, drawn.part, first))\n // In the page only while it is mounted: out of it otherwise, its place kept by a mark.\n const home = this.ownerDocument.createComment(\"\")\n let unbind: (() => void) | undefined\n stops.push(\n effect(() => {\n const elsewhere = drawn.into?.get()\n // Still where the page drew it: not moved, and never yet taken out.\n const own = first && !elsewhere && !held.parked && !unbind\n if (mounted.get() && (!drawn.into || elsewhere)) {\n if (elsewhere) {\n // Its place where it was written is kept by the mark all the while.\n if (!held.parked && element.parentNode) element.replaceWith(home)\n held.parked = true\n if (element.parentNode !== elsewhere) elsewhere.append(element)\n } else if (held.parked) {\n held.parked = false\n home.replaceWith(element)\n }\n unbind ??= put(element, drawn.part, own)\n } else {\n unbind?.()\n unbind = undefined\n if (!held.parked && element.parentNode) {\n held.parked = true\n element.replaceWith(home)\n } else if (drawn.into) element.remove()\n }\n }),\n () => {\n unbind?.()\n if (held.parked) home.replaceWith(element)\n }\n )\n }\n\n /** What is inside is drawn at the end of the page while the component is mounted. */\n #portal(element: HTMLElement) {\n const mounted = (this.controller as { mounted?: ReadonlySignal<boolean> }).mounted\n if (!mounted) return\n ;(element as Owned)[OWNER] = this\n const home = this.ownerDocument.createComment(\"\")\n const held: Held = { parked: false, stop: () => {} }\n this.#held.set(element, held)\n this.#watch(element)\n const body = this.ownerDocument.body\n const stop = effect(() => {\n if (mounted.get()) {\n if (element.parentNode === body) return\n // Its place in the page is kept by a mark, for when the component leaves.\n if (!home.parentNode && element.parentNode) element.replaceWith(home)\n held.parked = false\n element.setAttribute(\"data-kirana-portal\", \"\")\n body.append(element)\n this.#scan(element)\n } else if (!held.parked) {\n held.parked = true\n if (!home.parentNode && element.parentNode) element.replaceWith(home)\n else element.remove()\n }\n })\n held.stop = () => {\n stop()\n element.removeAttribute(\"data-kirana-portal\")\n if (home.parentNode) home.replaceWith(element)\n else element.remove()\n }\n }\n\n #release(element: HTMLElement) {\n // Moved to the page's end by its own portal, or put back: still this component's.\n if (element.isConnected) return\n for (const [each, held] of this.#held) {\n if (each !== element && !element.contains(each)) continue\n // Taken out by the component itself: it is still the component's, to be put back.\n if (each === element && held.parked) continue\n held.stop()\n this.#held.delete(each)\n }\n }\n }\n\n // Each prop as a property too: `element.open = true`, and what the element holds read back.\n for (const name of [...names, ...(spec.properties ?? [])]) {\n const prop = camel(name)\n Object.defineProperty(KuiElement.prototype, prop, {\n configurable: true,\n get(this: KuiElement) {\n const state = (this.controller as Record<string, unknown> | undefined)?.[prop] as\n | ReadonlySignal<unknown>\n | undefined\n return typeof state?.peek === \"function\" ? state.peek() : this.given(prop)\n },\n set(this: KuiElement, value: unknown) {\n this.give(prop, value)\n },\n })\n }\n customElements.define(spec.tag, KuiElement)\n return spec.tag\n}\n"],"mappings":";;AAqDA,MAAM,wBAAQ,IAAI,QAAuB;;AAGzC,SAAgB,YAAmB,SAAkC;CACnE,KAAK,IAAI,OAAoB,SAAS,MAAM,OAAO,KAAK,YACtD,IAAI,MAAM,IAAI,IAAI,GAAG,OAAO,MAAM,IAAI,IAAI;AAG9C;;AAGA,MAAM,QAAQ,MAAc,WAC1B,KAAK,QAAQ,2BAA2B,OAAO,SAC7C,QAAQ,SAAS,OAAO,OAAO,SAAS,EAAE,IAAI,K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OAAO;KACnB,KAAK,MAAM,OAAO;IACpB,OAAO,IAAI,CAAC,KAAK,QAAQ;KACvB,KAAK,SAAS;KACd,IAAI,CAAC,KAAK,cAAc,QAAQ,YAAY,QAAQ,YAAY,IAAI;UAC/D,QAAQ,OAAO;IACtB;GACF,CAAC;GACD,KAAK,aAAa;IAChB,KAAK;IACL,QAAQ,gBAAgB,oBAAoB;IAC5C,IAAI,KAAK,YAAY,KAAK,YAAY,OAAO;SACxC,QAAQ,OAAO;GACtB;EACF;EAEA,SAAS,SAAsB;GAE7B,IAAI,QAAQ,aAAa;GACzB,KAAK,MAAM,CAAC,MAAM,SAAS,KAAK,OAAO;IACrC,IAAI,SAAS,WAAW,CAAC,QAAQ,SAAS,IAAI,GAAG;IAEjD,IAAI,SAAS,WAAW,KAAK,QAAQ;IACrC,KAAK,KAAK;IACV,KAAK,MAAM,OAAO,IAAI;GACxB;EACF;CACF;CAGA,KAAK,MAAM,QAAQ,CAAC,GAAG,OAAO,GAAI,KAAK,cAAc,CAAC,CAAE,GAAG;EACzD,MAAM,OAAO,MAAM,IAAI;EACvB,OAAO,eAAe,WAAW,WAAW,MAAM;GAChD,cAAc;GACd,MAAsB;IACpB,MAAM,QAAS,KAAK,aAAqD;IAGzE,OAAO,OAAO,OAAO,SAAS,aAAa,MAAM,KAAK,IAAI,KAAK,MAAM,IAAI;GAC3E;GACA,IAAsB,OAAgB;IACpC,KAAK,KAAK,MAAM,KAAK;GACvB;EACF,CAAC;CACH;CACA,eAAe,OAAO,KAAK,KAAK,UAAU;CAC1C,OAAO,KAAK;AACd"}
@@ -0,0 +1,18 @@
1
+ import { As, ElementOf, Tag } from "./runtime.js";
2
+ import { ScrollAreaProps } from "@kirana-ui/core/scroll-area";
3
+ /**
4
+ * `<kui-scroll-area>` around `kui-part="root"`, a `viewport` with its `content`, a `scrollbar`
5
+ * for each way (`kui-orientation="horizontal"` for the one across) with its `thumb`, and a
6
+ * `corner`. A scrollbar is in the page while there is something to scroll its way. The
7
+ * library places the scrollbars and the corner against the root; the page gives a scrollbar
8
+ * its thickness and draws it.
9
+ */
10
+ export declare const tag: Tag<{
11
+ id: string;
12
+ }, import("@kirana-ui/core/scroll-area").ScrollArea>;
13
+ declare global {
14
+ interface HTMLElementTagNameMap {
15
+ "kui-scroll-area": ElementOf<As<typeof tag, ScrollAreaProps>>;
16
+ }
17
+ }
18
+ //# sourceMappingURL=scroll-area.d.ts.map
@@ -0,0 +1,37 @@
1
+ import { defineElement, partAround } from "./runtime.js";
2
+ import { createScrollArea } from "@kirana-ui/core/scroll-area";
3
+ // src/scroll-area.ts
4
+ const way = (element) => element?.getAttribute("kui-orientation") === "horizontal" ? "horizontal" : "vertical";
5
+ /**
6
+ * `<kui-scroll-area>` around `kui-part="root"`, a `viewport` with its `content`, a `scrollbar`
7
+ * for each way (`kui-orientation="horizontal"` for the one across) with its `thumb`, and a
8
+ * `corner`. A scrollbar is in the page while there is something to scroll its way. The
9
+ * library places the scrollbars and the corner against the root; the page gives a scrollbar
10
+ * its thickness and draws it.
11
+ */
12
+ const tag = defineElement({
13
+ tag: "kui-scroll-area",
14
+ props: {},
15
+ create: (props) => createScrollArea(props),
16
+ changes: {},
17
+ parts: {
18
+ root: (controller) => controller.root,
19
+ viewport: (controller) => controller.viewport,
20
+ content: (controller) => controller.content,
21
+ scrollbar(controller, element) {
22
+ const bar = controller.scrollbar(way(element));
23
+ return {
24
+ part: bar.part,
25
+ mounted: bar.shown
26
+ };
27
+ },
28
+ thumb: (controller, element) => controller.scrollbar(way(partAround(element, "scrollbar"))).thumb,
29
+ corner: (controller) => ({
30
+ part: controller.corner.part,
31
+ mounted: controller.corner.shown
32
+ })
33
+ }
34
+ });
35
+ export { tag };
36
+
37
+ //# sourceMappingURL=scroll-area.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scroll-area.js","names":[],"sources":["../../../../packages/web/src/scroll-area.ts"],"sourcesContent":["import type { Orientation } from \"@kirana-ui/core\"\nimport { createScrollArea } from \"@kirana-ui/core/scroll-area\"\nimport type { ScrollAreaProps } from \"@kirana-ui/core/scroll-area\"\n\nimport { defineElement, partAround } from \"./runtime.ts\"\nimport type { As, ElementOf } from \"./runtime.ts\"\n\nconst way = (element: HTMLElement | null): Orientation =>\n element?.getAttribute(\"kui-orientation\") === \"horizontal\" ? \"horizontal\" : \"vertical\"\n\n/**\n * `<kui-scroll-area>` around `kui-part=\"root\"`, a `viewport` with its `content`, a `scrollbar`\n * for each way (`kui-orientation=\"horizontal\"` for the one across) with its `thumb`, and a\n * `corner`. A scrollbar is in the page while there is something to scroll its way. The\n * library places the scrollbars and the corner against the root; the page gives a scrollbar\n * its thickness and draws it.\n */\nexport const tag = defineElement({\n tag: \"kui-scroll-area\",\n props: {},\n create: (props) => createScrollArea(props as never),\n changes: {},\n parts: {\n root: (controller) => controller.root,\n viewport: (controller) => controller.viewport,\n content: (controller) => controller.content,\n scrollbar(controller, element) {\n const bar = controller.scrollbar(way(element))\n return { part: bar.part, mounted: bar.shown }\n },\n thumb: (controller, element) =>\n controller.scrollbar(way(partAround(element, \"scrollbar\"))).thumb,\n corner: (controller) => ({ part: controller.corner.part, mounted: controller.corner.shown }),\n },\n})\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"kui-scroll-area\": ElementOf<As<typeof tag, ScrollAreaProps>>\n }\n}\n"],"mappings":";;;AAOA,MAAM,OAAO,YACX,SAAS,aAAa,iBAAiB,MAAM,eAAe,eAAe;;;;;;;;AAS7E,MAAa,MAAM,cAAc;CAC/B,KAAK;CACL,OAAO,CAAC;CACR,SAAS,UAAU,iBAAiB,KAAc;CAClD,SAAS,CAAC;CACV,OAAO;EACL,OAAO,eAAe,WAAW;EACjC,WAAW,eAAe,WAAW;EACrC,UAAU,eAAe,WAAW;EACpC,UAAU,YAAY,SAAS;GAC7B,MAAM,MAAM,WAAW,UAAU,IAAI,OAAO,CAAC;GAC7C,OAAO;IAAE,MAAM,IAAI;IAAM,SAAS,IAAI;GAAM;EAC9C;EACA,QAAQ,YAAY,YAClB,WAAW,UAAU,IAAI,WAAW,SAAS,WAAW,CAAC,CAAC,CAAC,CAAC;EAC9D,SAAS,gBAAgB;GAAE,MAAM,WAAW,OAAO;GAAM,SAAS,WAAW,OAAO;EAAM;CAC5F;AACF,CAAC"}