@kirana-ui/web 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +233 -4
  3. package/src/accordion.d.ts +8 -0
  4. package/src/accordion.js +67 -0
  5. package/src/accordion.js.map +1 -0
  6. package/src/alert-dialog.d.ts +6 -0
  7. package/src/alert-dialog.js +36 -0
  8. package/src/alert-dialog.js.map +1 -0
  9. package/src/around.d.ts +30 -0
  10. package/src/around.js +53 -0
  11. package/src/around.js.map +1 -0
  12. package/src/autocomplete.d.ts +8 -0
  13. package/src/autocomplete.js +42 -0
  14. package/src/autocomplete.js.map +1 -0
  15. package/src/autosize.d.ts +6 -0
  16. package/src/autosize.js +18 -0
  17. package/src/autosize.js.map +1 -0
  18. package/src/avatar.d.ts +7 -0
  19. package/src/avatar.js +38 -0
  20. package/src/avatar.js.map +1 -0
  21. package/src/button.d.ts +6 -0
  22. package/src/button.js +21 -0
  23. package/src/button.js.map +1 -0
  24. package/src/calendar.d.ts +12 -0
  25. package/src/calendar.js +60 -0
  26. package/src/calendar.js.map +1 -0
  27. package/src/carousel.d.ts +7 -0
  28. package/src/carousel.js +34 -0
  29. package/src/carousel.js.map +1 -0
  30. package/src/checkbox.d.ts +8 -0
  31. package/src/checkbox.js +42 -0
  32. package/src/checkbox.js.map +1 -0
  33. package/src/collapsible.d.ts +7 -0
  34. package/src/collapsible.js +32 -0
  35. package/src/collapsible.js.map +1 -0
  36. package/src/combobox.d.ts +27 -0
  37. package/src/combobox.js +125 -0
  38. package/src/combobox.js.map +1 -0
  39. package/src/command.d.ts +10 -0
  40. package/src/command.js +61 -0
  41. package/src/command.js.map +1 -0
  42. package/src/context-menu.d.ts +7 -0
  43. package/src/context-menu.js +11 -0
  44. package/src/context-menu.js.map +1 -0
  45. package/src/date-field.d.ts +9 -0
  46. package/src/date-field.js +41 -0
  47. package/src/date-field.js.map +1 -0
  48. package/src/date-picker.d.ts +11 -0
  49. package/src/date-picker.js +75 -0
  50. package/src/date-picker.js.map +1 -0
  51. package/src/dates.d.ts +19 -0
  52. package/src/dates.js +70 -0
  53. package/src/dates.js.map +1 -0
  54. package/src/dialog.d.ts +8 -0
  55. package/src/dialog.js +40 -0
  56. package/src/dialog.js.map +1 -0
  57. package/src/drawer.d.ts +8 -0
  58. package/src/drawer.js +62 -0
  59. package/src/drawer.js.map +1 -0
  60. package/src/field.d.ts +9 -0
  61. package/src/field.js +47 -0
  62. package/src/field.js.map +1 -0
  63. package/src/fieldset.d.ts +3 -0
  64. package/src/fieldset.js +17 -0
  65. package/src/fieldset.js.map +1 -0
  66. package/src/form.d.ts +7 -0
  67. package/src/form.js +30 -0
  68. package/src/form.js.map +1 -0
  69. package/src/hover-card.d.ts +7 -0
  70. package/src/hover-card.js +12 -0
  71. package/src/hover-card.js.map +1 -0
  72. package/src/hover-popup.d.ts +5 -0
  73. package/src/hover-popup.js +43 -0
  74. package/src/hover-popup.js.map +1 -0
  75. package/src/index.d.ts +5 -0
  76. package/src/index.js +49 -0
  77. package/src/input.d.ts +6 -0
  78. package/src/input.js +22 -0
  79. package/src/input.js.map +1 -0
  80. package/src/label.d.ts +3 -0
  81. package/src/label.js +15 -0
  82. package/src/label.js.map +1 -0
  83. package/src/listbox.d.ts +8 -0
  84. package/src/listbox.js +54 -0
  85. package/src/listbox.js.map +1 -0
  86. package/src/menu.d.ts +16 -0
  87. package/src/menu.js +139 -0
  88. package/src/menu.js.map +1 -0
  89. package/src/menubar.d.ts +7 -0
  90. package/src/menubar.js +22 -0
  91. package/src/menubar.js.map +1 -0
  92. package/src/message-scroller.d.ts +7 -0
  93. package/src/message-scroller.js +30 -0
  94. package/src/message-scroller.js.map +1 -0
  95. package/src/meter.d.ts +7 -0
  96. package/src/meter.js +40 -0
  97. package/src/meter.js.map +1 -0
  98. package/src/navigation-menu.d.ts +10 -0
  99. package/src/navigation-menu.js +77 -0
  100. package/src/navigation-menu.js.map +1 -0
  101. package/src/number-field.d.ts +9 -0
  102. package/src/number-field.js +57 -0
  103. package/src/number-field.js.map +1 -0
  104. package/src/otp.d.ts +9 -0
  105. package/src/otp.js +64 -0
  106. package/src/otp.js.map +1 -0
  107. package/src/pagination.d.ts +9 -0
  108. package/src/pagination.js +45 -0
  109. package/src/pagination.js.map +1 -0
  110. package/src/popover.d.ts +8 -0
  111. package/src/popover.js +39 -0
  112. package/src/popover.js.map +1 -0
  113. package/src/progress.d.ts +7 -0
  114. package/src/progress.js +40 -0
  115. package/src/progress.js.map +1 -0
  116. package/src/qr-code.d.ts +6 -0
  117. package/src/qr-code.js +24 -0
  118. package/src/qr-code.js.map +1 -0
  119. package/src/radio-group.d.ts +8 -0
  120. package/src/radio-group.js +40 -0
  121. package/src/radio-group.js.map +1 -0
  122. package/src/resizable.d.ts +7 -0
  123. package/src/resizable.js +38 -0
  124. package/src/resizable.js.map +1 -0
  125. package/src/runtime.d.ts +124 -0
  126. package/src/runtime.js +452 -0
  127. package/src/runtime.js.map +1 -0
  128. package/src/scroll-area.d.ts +7 -0
  129. package/src/scroll-area.js +35 -0
  130. package/src/scroll-area.js.map +1 -0
  131. package/src/select.d.ts +13 -0
  132. package/src/select.js +83 -0
  133. package/src/select.js.map +1 -0
  134. package/src/separator.d.ts +3 -0
  135. package/src/separator.js +14 -0
  136. package/src/separator.js.map +1 -0
  137. package/src/slider.d.ts +10 -0
  138. package/src/slider.js +71 -0
  139. package/src/slider.js.map +1 -0
  140. package/src/switch.d.ts +7 -0
  141. package/src/switch.js +37 -0
  142. package/src/switch.js.map +1 -0
  143. package/src/tabs.d.ts +7 -0
  144. package/src/tabs.js +31 -0
  145. package/src/tabs.js.map +1 -0
  146. package/src/toast.d.ts +17 -0
  147. package/src/toast.js +72 -0
  148. package/src/toast.js.map +1 -0
  149. package/src/toggle-group.d.ts +7 -0
  150. package/src/toggle-group.js +37 -0
  151. package/src/toggle-group.js.map +1 -0
  152. package/src/toggle.d.ts +7 -0
  153. package/src/toggle.js +32 -0
  154. package/src/toggle.js.map +1 -0
  155. package/src/toolbar.d.ts +8 -0
  156. package/src/toolbar.js +31 -0
  157. package/src/toolbar.js.map +1 -0
  158. package/src/tooltip.d.ts +7 -0
  159. package/src/tooltip.js +12 -0
  160. package/src/tooltip.js.map +1 -0
  161. package/README.md +0 -3
package/src/runtime.js ADDED
@@ -0,0 +1,452 @@
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
+ /**
49
+ * Puts a part on an element, and takes it off whole: what the part wrote is gone with it. A
50
+ * framework draws a new element each time a part comes back; here the same element is the
51
+ * part again, and must not still say what it said before (`data-closed`, `aria-controls`).
52
+ */
53
+ function put(element, part) {
54
+ const before = new Map(Array.from(element.attributes, (each) => [each.name, each.value]));
55
+ const unbind = bind(element, part);
56
+ return () => {
57
+ unbind();
58
+ for (const { name } of Array.from(element.attributes)) if (!before.has(name) && name !== "class") element.removeAttribute(name);
59
+ for (const [name, value] of before) if (name !== "class" && element.getAttribute(name) !== value) element.setAttribute(name, value);
60
+ };
61
+ }
62
+ /**
63
+ * The props of something inside a component that has props of its own (a menu's checkbox
64
+ * item, its radio group), read from its element's `kui-` attributes: `kui-checked`,
65
+ * `kui-default-value`. What it tells is told from that element, and may be refused; a value
66
+ * its element was given is held there, and one the page writes later is followed.
67
+ */
68
+ function partProps(element, kinds, changes) {
69
+ const attribute = (name) => `kui-${name}`;
70
+ const told = {};
71
+ const all = () => {
72
+ const next = { ...told };
73
+ for (const [name, kind] of Object.entries(kinds)) {
74
+ const text = element.getAttribute(attribute(name));
75
+ if (text !== null) next[camel(name)] = read(kind, text);
76
+ }
77
+ return next;
78
+ };
79
+ const source = signal({}, sameProps);
80
+ for (const [callback, { event, prop }] of Object.entries(changes)) told[callback] = (value, details) => {
81
+ const heard = new CustomEvent(event, {
82
+ detail: {
83
+ [prop]: value,
84
+ details
85
+ },
86
+ bubbles: true,
87
+ cancelable: true
88
+ });
89
+ if (!element.dispatchEvent(heard)) return details?.cancel();
90
+ const held = attribute(prop.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`));
91
+ if (element.hasAttribute(held)) element.setAttribute(held, String(value));
92
+ source.set(all());
93
+ };
94
+ source.set(all());
95
+ return {
96
+ props: source,
97
+ mount() {
98
+ const observer = new MutationObserver(() => source.set(all()));
99
+ observer.observe(element, {
100
+ attributes: true,
101
+ attributeFilter: Object.keys(kinds).map(attribute)
102
+ });
103
+ return () => observer.disconnect();
104
+ }
105
+ };
106
+ }
107
+ function read(kind, text) {
108
+ if (kind === "boolean") return text !== null && text !== "false";
109
+ if (text === null) return void 0;
110
+ return kind === "number" ? Number(text) : text;
111
+ }
112
+ const waiting = /* @__PURE__ */ new Set();
113
+ /** Whether a component around `element` has yet to begin: what is inside it reads it. */
114
+ function early(element) {
115
+ for (let each = element.parentElement; each; each = each.parentElement) {
116
+ const moved = each[OWNER];
117
+ if (moved) return early(moved);
118
+ if (ours(each) && !each.controller) return true;
119
+ }
120
+ return false;
121
+ }
122
+ /** What can be a part: an element of the page, one of a drawing (`<svg>`, `<path>`) too. */
123
+ const drawable = (node) => node instanceof Element;
124
+ /**
125
+ * Defines a component's custom element, and gives its name (for
126
+ * `customElements.whenDefined`). Where there are no custom elements (a server) it defines
127
+ * nothing.
128
+ */
129
+ function defineElement(spec) {
130
+ if (typeof customElements === "undefined" || customElements.get(spec.tag)) return spec.tag;
131
+ hosts.add(spec.tag);
132
+ const names = Object.keys(spec.props);
133
+ class KuiElement extends HTMLElement {
134
+ static observedAttributes = names;
135
+ controller;
136
+ #props;
137
+ #given = {};
138
+ #held = /* @__PURE__ */ new Map();
139
+ #stops = [];
140
+ #leaving = false;
141
+ #watch = () => {};
142
+ connectedCallback() {
143
+ this.#leaving = false;
144
+ this.begin();
145
+ }
146
+ /** Begins, unless a component around it has not: then it waits for that one. */
147
+ begin() {
148
+ if (this.controller || !this.isConnected) return;
149
+ if (early(this)) return void waiting.add(this);
150
+ waiting.delete(this);
151
+ if (!this.style.display) this.style.display = "contents";
152
+ const initial = { id: this.getAttribute("kui-id") || `kui-${++made}` };
153
+ for (const name of names) {
154
+ const text = this.getAttribute(name);
155
+ if (text !== null) initial[camel(name)] = read(spec.props[name], text);
156
+ }
157
+ Object.assign(initial, this.#given);
158
+ for (const [callback, { event, prop, hold }] of Object.entries(spec.changes)) initial[callback] = (value, details) => {
159
+ const told = new CustomEvent(event, {
160
+ detail: {
161
+ [prop]: value,
162
+ details
163
+ },
164
+ bubbles: true,
165
+ cancelable: true
166
+ });
167
+ if (!this.dispatchEvent(told)) return details?.cancel();
168
+ if (hold !== false && this.given(prop) !== void 0) this.give(prop, value);
169
+ };
170
+ this.#props = signal(initial, sameProps);
171
+ this.controller = spec.create(this.#props, this);
172
+ const unmount = this.controller.mount?.();
173
+ if (unmount) this.#stops.push(unmount);
174
+ const observer = new MutationObserver((records) => {
175
+ for (const record of records) {
176
+ for (const node of record.removedNodes) if (drawable(node)) this.#release(node);
177
+ for (const node of record.addedNodes) if (drawable(node)) this.#scan(node);
178
+ }
179
+ });
180
+ observer.observe(this, {
181
+ childList: true,
182
+ subtree: true
183
+ });
184
+ this.#watch = (element) => observer.observe(element, {
185
+ childList: true,
186
+ subtree: true
187
+ });
188
+ this.#stops.push(() => observer.disconnect());
189
+ for (const each of Array.from(this.children)) if (drawable(each)) this.#scan(each);
190
+ const inner = spec.inner?.(this.controller);
191
+ if (inner) {
192
+ const input = this.ownerDocument.createElement("input");
193
+ let unbind;
194
+ const drawn = effect(() => {
195
+ const wanted = inner.mounted?.get() ?? true;
196
+ if (wanted && !unbind) {
197
+ this.append(input);
198
+ unbind = bind(input, inner.part);
199
+ } else if (!wanted && unbind) {
200
+ unbind();
201
+ unbind = void 0;
202
+ input.remove();
203
+ }
204
+ });
205
+ this.#stops.push(() => {
206
+ drawn();
207
+ unbind?.();
208
+ input.remove();
209
+ });
210
+ }
211
+ for (const each of Array.from(waiting)) each.begin();
212
+ }
213
+ disconnectedCallback() {
214
+ this.#leaving = true;
215
+ queueMicrotask(() => {
216
+ if (!this.#leaving || this.isConnected) return;
217
+ waiting.delete(this);
218
+ for (const held of this.#held.values()) held.stop();
219
+ this.#held.clear();
220
+ for (const stop of this.#stops.splice(0).reverse()) stop();
221
+ delete this.controller;
222
+ this.#props = void 0;
223
+ });
224
+ }
225
+ attributeChangedCallback(name, _before, text) {
226
+ this.give(camel(name), read(spec.props[name], text));
227
+ }
228
+ /** A prop as it was last given: by an attribute, or as a property. */
229
+ given(prop) {
230
+ return this.#props ? this.#props.peek()[prop] : this.#given[prop];
231
+ }
232
+ give(prop, value) {
233
+ if (!this.#props) return void (this.#given[prop] = value);
234
+ if (!Object.is(this.#props.peek()[prop], value)) this.#props.set({
235
+ ...this.#props.peek(),
236
+ [prop]: value
237
+ });
238
+ }
239
+ /** Takes the parts in a subtree, in the page's order: one that leaves takes its own with it. */
240
+ #scan(element) {
241
+ if (!element.isConnected) return;
242
+ if (element instanceof HTMLTemplateElement) {
243
+ if (element.hasAttribute("kui-each") && ownerOf(element) === this) this.#each(element);
244
+ return;
245
+ }
246
+ if (element.hasAttribute("kui-part")) this.#adopt(element);
247
+ for (const each of Array.from(element.children)) if (drawable(each)) this.#scan(each);
248
+ }
249
+ /** Draws a list from its template: a copy for each entry, where the template was. */
250
+ #each(template) {
251
+ const list = spec.lists?.[template.getAttribute("kui-each")]?.(this.controller, entryAround(template));
252
+ if (!list) return;
253
+ const mark = this.ownerDocument.createComment("");
254
+ if (ENTRY.has(template)) ENTRY.set(mark, ENTRY.get(template));
255
+ template.replaceWith(mark);
256
+ const rows = /* @__PURE__ */ new Map();
257
+ const stamp = (entry) => {
258
+ const type = list.type?.(entry);
259
+ const copy = template.content.cloneNode(true);
260
+ for (const node of Array.from(copy.childNodes)) {
261
+ const blank = node.nodeType === Node.TEXT_NODE && !node.textContent.trim();
262
+ const other = node instanceof Element && node.hasAttribute("kui-when") && node.getAttribute("kui-when") !== type;
263
+ if (blank || other || node.nodeType === Node.COMMENT_NODE) node.remove();
264
+ }
265
+ const written = [];
266
+ const walker = this.ownerDocument.createTreeWalker(copy, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT);
267
+ for (let node = walker.nextNode(); node; node = walker.nextNode()) if (node instanceof Text) {
268
+ if (node.data.includes("{")) written.push([node, node.data]);
269
+ } else if (!(node instanceof HTMLTemplateElement)) {
270
+ for (const attribute of Array.from(node.attributes)) if (attribute.value.includes("{")) written.push([attribute, attribute.value]);
271
+ }
272
+ const nodes = Array.from(copy.childNodes);
273
+ for (const node of nodes) ENTRY.set(node, entry);
274
+ return {
275
+ entry,
276
+ nodes,
277
+ written
278
+ };
279
+ };
280
+ const write = (row) => {
281
+ const values = list.values?.(row.entry) ?? row.entry ?? {};
282
+ for (const [node, text] of row.written) {
283
+ const next = fill(text, values);
284
+ if (node instanceof Text) {
285
+ if (node.data !== next) node.data = next;
286
+ } else if (node.value !== next) node.value = next;
287
+ }
288
+ };
289
+ const draw = () => {
290
+ const { entries } = list;
291
+ const next = "get" in entries ? entries.get() : entries;
292
+ const parent = mark.parentNode;
293
+ if (!parent) return;
294
+ const kept = /* @__PURE__ */ new Set();
295
+ const fresh = [];
296
+ const ordered = next.map((entry) => {
297
+ const key = list.key(entry);
298
+ kept.add(key);
299
+ let row = rows.get(key);
300
+ if (!row) {
301
+ rows.set(key, row = stamp(entry));
302
+ fresh.push(row);
303
+ write(row);
304
+ } else if (row.entry !== entry) {
305
+ row.entry = entry;
306
+ for (const node of row.nodes) ENTRY.set(node, entry);
307
+ write(row);
308
+ }
309
+ return row;
310
+ });
311
+ for (const [key, row] of rows) {
312
+ if (kept.has(key)) continue;
313
+ rows.delete(key);
314
+ for (const node of row.nodes) node.remove();
315
+ }
316
+ let before = mark;
317
+ for (const row of ordered.reverse()) for (const node of row.nodes.toReversed()) {
318
+ if (node.nextSibling !== before || node.parentNode !== parent) parent.insertBefore(node, before);
319
+ before = node;
320
+ }
321
+ for (const row of fresh) for (const node of row.nodes) if (drawable(node)) this.#scan(node);
322
+ };
323
+ const stop = effect(draw);
324
+ this.#stops.push(() => {
325
+ stop();
326
+ for (const row of rows.values()) for (const node of row.nodes) node.remove();
327
+ rows.clear();
328
+ mark.replaceWith(template);
329
+ });
330
+ }
331
+ #adopt(element) {
332
+ if (this.#held.has(element) || ownerOf(element) !== this || !this.controller) return;
333
+ const name = element.getAttribute("kui-part");
334
+ if (name === "portal") return this.#portal(element);
335
+ const given = spec.parts[name]?.(this.controller, element);
336
+ if (!given) return;
337
+ const drawn = "attach" in given ? { part: given } : given;
338
+ const stops = [];
339
+ const held = {
340
+ parked: false,
341
+ stop: () => {
342
+ for (const stop of stops.splice(0).reverse()) stop();
343
+ }
344
+ };
345
+ this.#held.set(element, held);
346
+ const unmount = drawn.mount?.();
347
+ if (unmount) stops.push(unmount);
348
+ if (drawn.inner) {
349
+ const last = element.lastElementChild;
350
+ const taken = last instanceof HTMLInputElement && last.type === "hidden" ? last : void 0;
351
+ const input = taken ?? this.ownerDocument.createElement("input");
352
+ if (!taken) element.append(input);
353
+ stops.push(bind(input, drawn.inner), () => {
354
+ if (!taken) input.remove();
355
+ });
356
+ }
357
+ if (drawn.text && element.childNodes.length === 0) {
358
+ const { text } = drawn;
359
+ stops.push(effect(() => void (element.textContent = text.get() ?? "")), () => void (element.textContent = ""));
360
+ }
361
+ const mounted = element.hasAttribute("kui-keep-mounted") ? void 0 : drawn.mounted;
362
+ if (!mounted) return void stops.push(put(element, drawn.part));
363
+ const home = this.ownerDocument.createComment("");
364
+ let unbind;
365
+ stops.push(effect(() => {
366
+ const elsewhere = drawn.into?.get();
367
+ if (mounted.get() && (!drawn.into || elsewhere)) {
368
+ if (elsewhere) {
369
+ if (!held.parked && element.parentNode) element.replaceWith(home);
370
+ held.parked = true;
371
+ if (element.parentNode !== elsewhere) elsewhere.append(element);
372
+ } else if (held.parked) {
373
+ held.parked = false;
374
+ home.replaceWith(element);
375
+ }
376
+ unbind ??= put(element, drawn.part);
377
+ } else {
378
+ unbind?.();
379
+ unbind = void 0;
380
+ if (!held.parked && element.parentNode) {
381
+ held.parked = true;
382
+ element.replaceWith(home);
383
+ } else if (drawn.into) element.remove();
384
+ }
385
+ }), () => {
386
+ unbind?.();
387
+ if (held.parked) home.replaceWith(element);
388
+ });
389
+ }
390
+ /** What is inside is drawn at the end of the page while the component is mounted. */
391
+ #portal(element) {
392
+ const mounted = this.controller.mounted;
393
+ if (!mounted) return;
394
+ element[OWNER] = this;
395
+ const home = this.ownerDocument.createComment("");
396
+ const held = {
397
+ parked: false,
398
+ stop: () => {}
399
+ };
400
+ this.#held.set(element, held);
401
+ this.#watch(element);
402
+ const body = this.ownerDocument.body;
403
+ const stop = effect(() => {
404
+ if (mounted.get()) {
405
+ if (element.parentNode === body) return;
406
+ if (!home.parentNode && element.parentNode) element.replaceWith(home);
407
+ held.parked = false;
408
+ element.setAttribute("data-kirana-portal", "");
409
+ body.append(element);
410
+ this.#scan(element);
411
+ } else if (!held.parked) {
412
+ held.parked = true;
413
+ if (!home.parentNode && element.parentNode) element.replaceWith(home);
414
+ else element.remove();
415
+ }
416
+ });
417
+ held.stop = () => {
418
+ stop();
419
+ element.removeAttribute("data-kirana-portal");
420
+ if (home.parentNode) home.replaceWith(element);
421
+ else element.remove();
422
+ };
423
+ }
424
+ #release(element) {
425
+ if (element.isConnected) return;
426
+ for (const [each, held] of this.#held) {
427
+ if (each !== element && !element.contains(each)) continue;
428
+ if (each === element && held.parked) continue;
429
+ held.stop();
430
+ this.#held.delete(each);
431
+ }
432
+ }
433
+ }
434
+ for (const name of [...names, ...spec.properties ?? []]) {
435
+ const prop = camel(name);
436
+ Object.defineProperty(KuiElement.prototype, prop, {
437
+ configurable: true,
438
+ get() {
439
+ const state = this.controller?.[prop];
440
+ return typeof state?.peek === "function" ? state.peek() : this.given(prop);
441
+ },
442
+ set(value) {
443
+ this.give(prop, value);
444
+ }
445
+ });
446
+ }
447
+ customElements.define(spec.tag, KuiElement);
448
+ return spec.tag;
449
+ }
450
+ export { controllerAround, defineElement, entryAround, hostAround, partAround, partProps };
451
+
452
+ //# 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\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/**\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): () => void {\n const before = new Map(Array.from(element.attributes, (each) => [each.name, each.value]))\n const unbind = bind(element, part)\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): string {\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 #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 for (const each of Array.from(this.children)) if (drawable(each)) this.#scan(each)\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 if (!mounted) return void stops.push(put(element, drawn.part))\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 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)\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,KAChD;AAwCF,MAAM,SAAS,SACb,KAAK,QAAQ,cAAc,MAAM,WAAmB,OAAO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AAI,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,7 @@
1
+ /**
2
+ * `<kui-scroll-area>` around `kui-part="root"`, a `viewport` with its `content`, a `scrollbar`
3
+ * for each way (`kui-orientation="horizontal"` for the one across) with its `thumb`, and a
4
+ * `corner`. A scrollbar is in the page while there is something to scroll its way.
5
+ */
6
+ export declare const tag: string;
7
+ //# sourceMappingURL=scroll-area.d.ts.map
@@ -0,0 +1,35 @@
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.
9
+ */
10
+ const tag = defineElement({
11
+ tag: "kui-scroll-area",
12
+ props: {},
13
+ create: (props) => createScrollArea(props),
14
+ changes: {},
15
+ parts: {
16
+ root: (controller) => controller.root,
17
+ viewport: (controller) => controller.viewport,
18
+ content: (controller) => controller.content,
19
+ scrollbar(controller, element) {
20
+ const bar = controller.scrollbar(way(element));
21
+ return {
22
+ part: bar.part,
23
+ mounted: bar.shown
24
+ };
25
+ },
26
+ thumb: (controller, element) => controller.scrollbar(way(partAround(element, "scrollbar"))).thumb,
27
+ corner: (controller) => ({
28
+ part: controller.corner.part,
29
+ mounted: controller.corner.shown
30
+ })
31
+ }
32
+ });
33
+ export { tag };
34
+
35
+ //# 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\"\n\nimport { defineElement, partAround } 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.\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"],"mappings":";;;AAKA,MAAM,OAAO,YACX,SAAS,aAAa,iBAAiB,MAAM,eAAe,eAAe;;;;;;AAO7E,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"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * `<kui-select>` around a `kui-part="trigger"` button holding a `value` (it says the chosen
3
+ * item's text, or its `kui-placeholder`), and a `portal` with a `positioner` (its `kui-side`
4
+ * and the like, and `kui-align-item-with-trigger`) around the `popup`. The popup holds an
5
+ * `item` for each `kui-value` (`kui-disabled`, `kui-label`), each with an `item-text` and an
6
+ * `item-indicator`; items may be in a `group` with a `group-label`, with `separator`s
7
+ * between, and in a `list` between a `scroll-up-arrow` and a `scroll-down-arrow`. With a name
8
+ * it draws the hidden input a form reads. `value`, `default-value`, `open`, `default-open`,
9
+ * `disabled`, `required`, `name`, `form`; `items` as a property; it tells `value-change` and
10
+ * `open-change`.
11
+ */
12
+ export declare const tag: string;
13
+ //# sourceMappingURL=select.d.ts.map