@nonoun/native-ui 0.2.9 → 0.3.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 (41) hide show
  1. package/dist/{ui-layout-inspector-element.js → components.js} +2279 -386
  2. package/dist/{register-all2.js → core.js} +78 -35
  3. package/dist/custom-elements.json +1999 -1999
  4. package/dist/kernel.js +175 -174
  5. package/dist/native-ui.js +4 -49
  6. package/dist/register-all.js +4 -4
  7. package/dist/traits.js +3 -5
  8. package/dist/ui-icon.js +56 -0
  9. package/package.json +6 -9
  10. package/dist/dialog-controller.js +0 -391
  11. package/dist/inspector/build-inspector.d.ts +0 -8
  12. package/dist/inspector/build-inspector.d.ts.map +0 -1
  13. package/dist/inspector/ds-color-swatch-element.d.ts +0 -15
  14. package/dist/inspector/ds-color-swatch-element.d.ts.map +0 -1
  15. package/dist/inspector/ds-color-swatch.d.ts +0 -3
  16. package/dist/inspector/ds-color-swatch.d.ts.map +0 -1
  17. package/dist/inspector/ds-colors-element.d.ts +0 -14
  18. package/dist/inspector/ds-colors-element.d.ts.map +0 -1
  19. package/dist/inspector/ds-colors.d.ts +0 -4
  20. package/dist/inspector/ds-colors.d.ts.map +0 -1
  21. package/dist/inspector/ds-inspector-element.d.ts +0 -15
  22. package/dist/inspector/ds-inspector-element.d.ts.map +0 -1
  23. package/dist/inspector/ds-inspector.d.ts +0 -3
  24. package/dist/inspector/ds-inspector.d.ts.map +0 -1
  25. package/dist/inspector/ds-themes-element.d.ts +0 -13
  26. package/dist/inspector/ds-themes-element.d.ts.map +0 -1
  27. package/dist/inspector/ds-themes.d.ts +0 -4
  28. package/dist/inspector/ds-themes.d.ts.map +0 -1
  29. package/dist/inspector/ds-variable-element.d.ts +0 -19
  30. package/dist/inspector/ds-variable-element.d.ts.map +0 -1
  31. package/dist/inspector/ds-variable.d.ts +0 -4
  32. package/dist/inspector/ds-variable.d.ts.map +0 -1
  33. package/dist/inspector/index.d.ts +0 -10
  34. package/dist/inspector/index.d.ts.map +0 -1
  35. package/dist/inspector.css +0 -231
  36. package/dist/inspector.d.ts +0 -11
  37. package/dist/inspector.d.ts.map +0 -1
  38. package/dist/inspector.js +0 -610
  39. package/dist/list-navigate-controller.js +0 -457
  40. package/dist/ui-icon-element.js +0 -986
  41. package/dist/uid.js +0 -147
@@ -1,457 +0,0 @@
1
- import { i as e, o as t, t as n } from "./uid.js";
2
- var r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Set();
3
- function a(e) {
4
- if (r.has(e.name)) {
5
- console.warn(`[native-ui] Trait "${e.name}" is already registered.`);
6
- return;
7
- }
8
- r.set(e.name, e);
9
- for (let t of i) t(e.name);
10
- }
11
- /** Subscribe to trait registration events. Returns unsubscribe function. */
12
- function o(e) {
13
- return i.add(e), () => i.delete(e);
14
- }
15
- function s(e) {
16
- return r.get(e);
17
- }
18
- function c() {
19
- return new Set(r.keys());
20
- }
21
- /**
22
- * Parse a namespaced trait attribute like "draggable-axis" into
23
- * { trait: "draggable", key: "axis" }. Returns null if the attribute
24
- * doesn't match any registered trait name prefix.
25
- */
26
- function l(e) {
27
- let t = c();
28
- for (let n of t) if (e.startsWith(n + "-")) return {
29
- trait: n,
30
- key: e.slice(n.length + 1)
31
- };
32
- return null;
33
- }
34
- /**
35
- * Collect all `{traitName}-*` attributes from an element for a given trait.
36
- * Returns a plain object mapping option keys to string values.
37
- *
38
- * Example: element has `draggable-axis="x"` and `draggable-mode="slot"`
39
- * → collectTraitOptions(el, 'draggable') returns { axis: 'x', mode: 'slot' }
40
- */
41
- function u(e, t) {
42
- let n = t + "-", r = {};
43
- for (let t of e.attributes) t.name.startsWith(n) && (r[t.name.slice(n.length)] = t.value);
44
- return r;
45
- }
46
- /** Base custom element class with reactive effect lifecycle, child deferral, and trait protocol. */
47
- var d = class extends HTMLElement {
48
- #e = [];
49
- #t = /* @__PURE__ */ new Map();
50
- #n = null;
51
- #r = /* @__PURE__ */ new Set();
52
- #i = null;
53
- #a = !1;
54
- #o = null;
55
- /** Resolves after setup() and any deferChildren microtask have completed. */
56
- ready = new Promise((e) => {
57
- this.#o = e;
58
- });
59
- addEffect(t) {
60
- this.#e.push(e(t));
61
- }
62
- connectedCallback() {
63
- if (this.#a) return;
64
- this.#a = !0, this.setup();
65
- let e = this.getAttribute("traits");
66
- e !== null && this.#s(e), queueMicrotask(() => this.#o?.());
67
- }
68
- disconnectedCallback() {
69
- this.#a = !1, this.#l(), this.#n?.disconnect(), this.#n = null, this.#i?.(), this.#i = null, this.#r.clear(), this.teardown();
70
- for (let e of this.#e) e();
71
- this.#e = [];
72
- }
73
- setup() {}
74
- teardown() {}
75
- deferChildren(e) {
76
- this.firstChild ? e() : queueMicrotask(() => {
77
- this.isConnected && e();
78
- });
79
- }
80
- attributeChangedCallback(e, t, n) {}
81
- /**
82
- * Get a trait controller instance by name.
83
- * Returns null if no controller with that name is active.
84
- */
85
- getTraitController(e) {
86
- return this.#t.get(e) ?? null;
87
- }
88
- #s(e) {
89
- this.#c(e), this.#n = new MutationObserver((e) => {
90
- for (let t of e) if (t.attributeName === "traits") this.#c(this.getAttribute("traits") ?? "");
91
- else if (t.attributeName) {
92
- let e = l(t.attributeName);
93
- if (e) {
94
- let t = s(e.trait), n = this.#t.get(e.trait);
95
- t && n && t.update && t.update(n, u(this, e.trait));
96
- }
97
- }
98
- }), this.#n.observe(this, { attributes: !0 });
99
- }
100
- #c(e) {
101
- let t = new Set(e.split(/\s+/).filter(Boolean));
102
- for (let [e, n] of this.#t) if (!t.has(e)) {
103
- let t = s(e);
104
- t && t.destroy(n), this.#t.delete(e);
105
- }
106
- this.#r.clear();
107
- for (let e of t) {
108
- if (this.#t.has(e)) continue;
109
- let t = s(e);
110
- if (!t) {
111
- this.#r.add(e);
112
- continue;
113
- }
114
- for (let [n] of this.#t) if (s(n)?.conflicts?.includes(e) || t.conflicts?.includes(n)) {
115
- let t = `[native-ui] Trait conflict: "${e}" and "${n}" are incompatible.`;
116
- console.warn(t);
117
- }
118
- let n = u(this, e), r = t.create(this, n);
119
- this.#t.set(e, r);
120
- }
121
- this.#r.size > 0 && !this.#i ? this.#i = o((e) => {
122
- this.#r.has(e) && (this.#r.delete(e), this.#c(this.getAttribute("traits") ?? ""), this.#r.size === 0 && (this.#i?.(), this.#i = null));
123
- }) : this.#r.size === 0 && this.#i && (this.#i(), this.#i = null);
124
- }
125
- #l() {
126
- for (let [e, t] of this.#t) {
127
- let n = s(e);
128
- n && n.destroy(t);
129
- }
130
- this.#t.clear();
131
- }
132
- }, f = class {
133
- #e = /* @__PURE__ */ new Set();
134
- #t = null;
135
- #n = !1;
136
- register(e) {
137
- this.#e.add(e), this.#a();
138
- }
139
- unregister(e) {
140
- this.#e.delete(e), this.#t === e && (this.#t = null), this.#e.size === 0 && this.#o();
141
- }
142
- /** Release the current claim (e.g. on pointerup). */
143
- release() {
144
- this.#t = null;
145
- }
146
- /** Get the currently active (claiming) participant, if any. */
147
- get activeParticipant() {
148
- return this.#t;
149
- }
150
- #r = (e) => {
151
- if (this.#t) return;
152
- let t = e.target, n = [];
153
- for (let e of this.#e) e.host.contains(t) && n.push(e);
154
- if (n.length !== 0) {
155
- n.sort((e, t) => e.priority - t.priority);
156
- for (let t of n) if (t.onGestureStart(e) === "claim") {
157
- this.#t = t;
158
- for (let e of n) e !== t && e.onGestureCancel?.();
159
- return;
160
- }
161
- }
162
- };
163
- #i = () => {
164
- this.release();
165
- };
166
- #a() {
167
- this.#n ||= (document.addEventListener("pointerdown", this.#r, !0), document.addEventListener("pointerup", this.#i, !0), document.addEventListener("pointercancel", this.#i, !0), !0);
168
- }
169
- #o() {
170
- this.#n &&= (document.removeEventListener("pointerdown", this.#r, !0), document.removeEventListener("pointerup", this.#i, !0), document.removeEventListener("pointercancel", this.#i, !0), !1);
171
- }
172
- }, p = class {
173
- #e = [];
174
- #t = !1;
175
- #n = (e) => {
176
- let t = this.#e[this.#e.length - 1];
177
- t && (e.composedPath().includes(t) || t.dispatchEvent(new CustomEvent("ui-dismiss", {
178
- bubbles: !0,
179
- composed: !0
180
- })));
181
- };
182
- #r = (e) => {
183
- if (e.key !== "Escape") return;
184
- let t = this.#e[this.#e.length - 1];
185
- t && (e.preventDefault(), t.dispatchEvent(new CustomEvent("ui-dismiss", {
186
- bubbles: !0,
187
- composed: !0
188
- })));
189
- };
190
- push(e) {
191
- let t = this.#e.indexOf(e);
192
- t !== -1 && this.#e.splice(t, 1), this.#e.push(e), this.#i();
193
- }
194
- remove(e) {
195
- let t = this.#e.indexOf(e);
196
- t !== -1 && this.#e.splice(t, 1), this.#a();
197
- }
198
- #i() {
199
- this.#t ||= (document.addEventListener("pointerdown", this.#n, !0), document.addEventListener("keydown", this.#r), !0);
200
- }
201
- #a() {
202
- this.#e.length > 0 || (document.removeEventListener("pointerdown", this.#n, !0), document.removeEventListener("keydown", this.#r), this.#t = !1);
203
- }
204
- }, m = class {
205
- #e = null;
206
- #t = 0;
207
- #n = [];
208
- #r() {
209
- return this.#e && this.#e.isConnected ? this.#e : (this.#e = document.createElement("div"), this.#e.className = "ui-toast-container", this.#e.setAttribute("role", "status"), this.#e.setAttribute("aria-live", "polite"), this.#e.setAttribute("aria-atomic", "false"), this.#e.style.cssText = "\n position: fixed;\n top: 1rem;\n right: 1rem;\n display: flex;\n flex-direction: column;\n gap: 0.5rem;\n z-index: 10000;\n pointer-events: none;\n ", document.body.appendChild(this.#e), this.#e);
210
- }
211
- toast(e, t) {
212
- let { message: n, intent: r = "info", duration: i = 4e3, dismissible: a = !0 } = t, o = this.#t++, s = this.#r(), c = document.createElement("div");
213
- c.className = "ui-toast", c.setAttribute("intent", r), c.setAttribute("role", "alert"), c.style.cssText = "pointer-events: auto;";
214
- let l = document.createElement("span");
215
- if (l.className = "ui-toast-message", l.textContent = n, c.appendChild(l), a) {
216
- let e = document.createElement("button");
217
- e.className = "ui-toast-close", e.setAttribute("aria-label", "Dismiss"), e.textContent = "×", e.addEventListener("click", () => this.dismiss(o)), c.appendChild(e);
218
- }
219
- s.appendChild(c);
220
- let u = i > 0 ? setTimeout(() => this.dismiss(o), i) : null;
221
- return this.#n.push({
222
- id: o,
223
- el: c,
224
- timer: u
225
- }), e.dispatchEvent(new CustomEvent("ui-toast", {
226
- bubbles: !0,
227
- composed: !0,
228
- detail: {
229
- id: o,
230
- message: n,
231
- intent: r
232
- }
233
- })), o;
234
- }
235
- dismiss(e) {
236
- let t = this.#n.findIndex((t) => t.id === e);
237
- if (t === -1) return;
238
- let n = this.#n[t];
239
- n.timer && clearTimeout(n.timer), n.el.remove(), this.#n.splice(t, 1), this.#n.length === 0 && this.#e && (this.#e.remove(), this.#e = null);
240
- }
241
- dismissAll() {
242
- for (let e of [...this.#n]) this.dismiss(e.id);
243
- }
244
- }, h = null;
245
- function g() {
246
- return h ||= {
247
- dismissStack: new p(),
248
- toastManager: new m(),
249
- gestureRouter: new f()
250
- }, h;
251
- }
252
- /** Handles pointer and keyboard press interactions, dispatching `ui-press` events. */
253
- var _ = class {
254
- host;
255
- disabled;
256
- #e = !1;
257
- #t = "mouse";
258
- #n = !1;
259
- constructor(e, t = {}) {
260
- this.host = e, this.disabled = t.disabled ?? !1, this.attach();
261
- }
262
- #r() {
263
- return typeof this.disabled == "function" ? this.disabled() : this.disabled ? !0 : this.host.disabled === !0;
264
- }
265
- attach() {
266
- this.#n || (this.#n = !0, this.host.addEventListener("pointerdown", this.#i), this.host.addEventListener("pointerup", this.#a), this.host.addEventListener("pointercancel", this.#o), this.host.addEventListener("lostpointercapture", this.#s), this.host.addEventListener("keydown", this.#c), this.host.addEventListener("keyup", this.#l));
267
- }
268
- detach() {
269
- this.#n && (this.#n = !1, this.host.removeEventListener("pointerdown", this.#i), this.host.removeEventListener("pointerup", this.#a), this.host.removeEventListener("pointercancel", this.#o), this.host.removeEventListener("lostpointercapture", this.#s), this.host.removeEventListener("keydown", this.#c), this.host.removeEventListener("keyup", this.#l), this.host.removeAttribute("pressed"));
270
- }
271
- destroy() {
272
- this.detach();
273
- }
274
- #i = (e) => {
275
- e.button === 0 && (this.#r() || (this.#t = e.pointerType, this.host.setPointerCapture(e.pointerId), this.#e = !0, this.host.toggleAttribute("pressed", !0)));
276
- };
277
- #a = (e) => {
278
- this.#e && (this.#e = !1, this.host.removeAttribute("pressed"), this.host.dispatchEvent(new CustomEvent("ui-press", {
279
- bubbles: !0,
280
- composed: !0,
281
- detail: { pointerType: this.#t }
282
- })));
283
- };
284
- #o = () => {
285
- this.#e = !1, this.host.removeAttribute("pressed");
286
- };
287
- #s = () => {
288
- this.#e = !1, this.host.removeAttribute("pressed");
289
- };
290
- #c = (e) => {
291
- e.repeat || this.#r() || e.key !== "Enter" && e.key !== " " || (e.key === " " && e.preventDefault(), this.host.toggleAttribute("pressed", !0));
292
- };
293
- #l = (e) => {
294
- e.key !== "Enter" && e.key !== " " || (this.host.removeAttribute("pressed"), !this.#r() && this.host.dispatchEvent(new CustomEvent("ui-press", {
295
- bubbles: !0,
296
- composed: !0,
297
- detail: { pointerType: "keyboard" }
298
- })));
299
- };
300
- }, v = class {
301
- host;
302
- selector;
303
- orientation;
304
- wrap;
305
- disabled;
306
- #e = 0;
307
- #t = !1;
308
- constructor(e, t = {}) {
309
- this.host = e, this.selector = t.selector ?? ":scope > [role]", this.orientation = t.orientation ?? "vertical", this.wrap = t.wrap ?? !0, this.disabled = t.disabled ?? !1, this.attach();
310
- }
311
- attach() {
312
- if (this.#t || this.disabled) return;
313
- this.#t = !0, this.host.addEventListener("keydown", this.#r), this.host.addEventListener("focusin", this.#i);
314
- let e = this.#n();
315
- for (let t = 0; t < e.length; t++) e[t].setAttribute("tabindex", t === 0 ? "0" : "-1");
316
- }
317
- detach() {
318
- this.#t && (this.#t = !1, this.host.removeEventListener("keydown", this.#r), this.host.removeEventListener("focusin", this.#i));
319
- }
320
- destroy() {
321
- this.detach();
322
- }
323
- #n() {
324
- return [...this.host.querySelectorAll(this.selector)].filter((e) => !e.hasAttribute("disabled") && e.getAttribute("aria-disabled") !== "true");
325
- }
326
- #r = (e) => {
327
- let t = this.#n();
328
- if (t.length === 0) return;
329
- let n = 0, r = this.orientation === "vertical" || this.orientation === "both", i = this.orientation === "horizontal" || this.orientation === "both";
330
- if (e.key === "ArrowDown" && r) n = 1;
331
- else if (e.key === "ArrowUp" && r) n = -1;
332
- else if (e.key === "ArrowRight" && i) n = 1;
333
- else if (e.key === "ArrowLeft" && i) n = -1;
334
- else if (e.key === "Home") {
335
- this.#a(t, 0), e.preventDefault();
336
- return;
337
- } else if (e.key === "End") {
338
- this.#a(t, t.length - 1), e.preventDefault();
339
- return;
340
- } else return;
341
- e.preventDefault();
342
- let a = this.#e + n;
343
- a = this.wrap ? (a + t.length) % t.length : Math.max(0, Math.min(t.length - 1, a)), this.#a(t, a);
344
- };
345
- #i = (e) => {
346
- e.target === this.host && this.#n()[this.#e]?.focus();
347
- };
348
- #a(e, t) {
349
- let n = e[this.#e];
350
- n && n.setAttribute("tabindex", "-1"), this.#e = t;
351
- let r = e[t];
352
- r && (r.setAttribute("tabindex", "0"), r.focus());
353
- }
354
- }, y = class {
355
- host;
356
- #e = 0;
357
- constructor(e) {
358
- this.host = e;
359
- }
360
- enable() {
361
- this.#e = requestAnimationFrame(() => {
362
- this.#e = 0, g().dismissStack.push(this.host);
363
- });
364
- }
365
- disable() {
366
- this.#e &&= (cancelAnimationFrame(this.#e), 0), g().dismissStack.remove(this.host);
367
- }
368
- destroy() {
369
- this.#e &&= (cancelAnimationFrame(this.#e), 0), g().dismissStack.remove(this.host);
370
- }
371
- }, b = class {
372
- host;
373
- #e;
374
- #t = null;
375
- #n = null;
376
- constructor(e) {
377
- this.host = e, this.#e = new y(e);
378
- }
379
- wirePopover(e, t) {
380
- this.#t = e, this.#n = t;
381
- let r = n("anchor");
382
- e.style.setProperty("anchor-name", `--${r}`), t.style.setProperty("position-anchor", `--${r}`);
383
- }
384
- syncPopover(e) {
385
- if (e) {
386
- try {
387
- this.#n?.showPopover();
388
- } catch {}
389
- this.#e.enable();
390
- } else {
391
- try {
392
- this.#n?.hidePopover();
393
- } catch {}
394
- this.#e.disable();
395
- }
396
- }
397
- destroy() {
398
- this.#e.destroy(), this.#t?.style.removeProperty("anchor-name"), this.#t = null, this.#n?.style.removeProperty("position-anchor"), this.#n = null;
399
- }
400
- }, x = class {
401
- host;
402
- listValue = t(null);
403
- itemSelector;
404
- ariaAttr;
405
- autoSync;
406
- onChildSelect;
407
- #e;
408
- #t = !1;
409
- constructor(e, t = {}) {
410
- if (this.host = e, this.itemSelector = t.itemSelector ?? ":scope > [role]", this.ariaAttr = t.ariaAttr ?? "aria-selected", this.autoSync = t.autoSync ?? !0, this.onChildSelect = t.onChildSelect ?? ((t) => {
411
- this.listValue.value = t.value, e.dispatchEvent(new CustomEvent("ui-change", {
412
- bubbles: !0,
413
- composed: !0,
414
- cancelable: !0,
415
- detail: t
416
- }));
417
- }), this.#e = new v(e, {
418
- selector: this.itemSelector,
419
- orientation: t.orientation ?? "vertical",
420
- wrap: t.wrap ?? !0,
421
- disabled: t.disabled ?? !1
422
- }), this.attach(), this.autoSync && t.addEffect && t.deferChildren) {
423
- let n = t.addEffect;
424
- t.deferChildren(() => {
425
- n(() => {
426
- let t = this.listValue.value, n = e.querySelectorAll(this.itemSelector), r = this.ariaAttr === "aria-current";
427
- for (let e of n) {
428
- let n = e.getAttribute("value") ?? e.value;
429
- if (n !== void 0) {
430
- let i = n === t;
431
- r ? i ? e.setAttribute("aria-current", "page") : e.removeAttribute("aria-current") : e.setAttribute(this.ariaAttr, i ? "true" : "false");
432
- }
433
- }
434
- });
435
- });
436
- }
437
- }
438
- attach() {
439
- this.#t || (this.#t = !0, this.host.addEventListener("ui-select", this.#n));
440
- }
441
- detach() {
442
- this.#t && (this.#t = !1, this.host.removeEventListener("ui-select", this.#n));
443
- }
444
- destroy() {
445
- this.detach(), this.#e.destroy();
446
- }
447
- /** Access the underlying roving focus controller for direct configuration. */
448
- get rovingFocus() {
449
- return this.#e;
450
- }
451
- #n = (e) => {
452
- if (this.host.disabled === !0) return;
453
- let t = e.detail;
454
- this.onChildSelect(t);
455
- };
456
- };
457
- export { _ as a, g as c, u as d, l as f, a as g, o as h, v as i, f as l, s as m, b as n, p as o, c as p, y as r, m as s, x as t, d as u };