@nonoun/native-tokens 0.4.2 → 0.5.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.
@@ -1,5 +1,5 @@
1
- import { NButton as e, NIcon as t, NListbox as n, NOption as r, NRange as i, NSelect as a, NativeElement as o, define as s, uid as c } from "@nonoun/native-ui";
2
- var l = class extends o {
1
+ import { NButton as e, NIcon as t, NListbox as n, NOption as r, NRange as i, NSelect as a, NativeElement as o, define as s, registerIcon as c, uid as l } from "@nonoun/native-ui";
2
+ var u = class extends o {
3
3
  static observedAttributes = ["data"];
4
4
  #e = null;
5
5
  #t = null;
@@ -62,7 +62,7 @@ var l = class extends o {
62
62
  }));
63
63
  })), this.#t = r, this.#n = s, t.append(n, r, s), this.appendChild(t);
64
64
  }
65
- }, u = class extends o {
65
+ }, d = class extends o {
66
66
  static observedAttributes = ["data"];
67
67
  #e = [];
68
68
  attributeChangedCallback(e, t, n) {
@@ -105,7 +105,7 @@ var l = class extends o {
105
105
  }
106
106
  };
107
107
  /** Parse a computed `rgb(...)` / `rgba(...)` string into [r, g, b, a] (0–255, 0–1). */
108
- function d(e) {
108
+ function f(e) {
109
109
  let t = e.match(/[\d.]+/g);
110
110
  return !t || t.length < 3 ? [
111
111
  0,
@@ -120,7 +120,7 @@ function d(e) {
120
120
  ];
121
121
  }
122
122
  /** Relative luminance (ITU-R BT.709). Returns true if light. */
123
- function f(e, t, n) {
123
+ function p(e, t, n) {
124
124
  let r = [
125
125
  e,
126
126
  t,
@@ -129,16 +129,16 @@ function f(e, t, n) {
129
129
  return .2126 * r[0] + .7152 * r[1] + .0722 * r[2] > .4;
130
130
  }
131
131
  /** Convert 0–255 component to 2-digit hex. */
132
- function p(e) {
132
+ function m(e) {
133
133
  return Math.round(e).toString(16).padStart(2, "0");
134
134
  }
135
135
  /** sRGB → linear. */
136
- function m(e) {
136
+ function h(e) {
137
137
  return e /= 255, e <= .04045 ? e / 12.92 : ((e + .055) / 1.055) ** 2.4;
138
138
  }
139
139
  /** sRGB (0–255) → OKLCH via OKLab. Returns [L (0–1), C, H (degrees)]. */
140
- function h(e, t, n) {
141
- let r = m(e), i = m(t), a = m(n), o = .4122214708 * r + .5363325363 * i + .0514459929 * a, s = .2119034982 * r + .6806995451 * i + .1073969566 * a, c = .0883024619 * r + .2817188376 * i + .6299787005 * a, l = Math.cbrt(o), u = Math.cbrt(s), d = Math.cbrt(c), f = .2104542553 * l + .793617785 * u - .0040720468 * d, p = 1.9779984951 * l - 2.428592205 * u + .4505937099 * d, h = .0259040371 * l + .7827717662 * u - .808675766 * d, g = Math.sqrt(p * p + h * h), _ = Math.atan2(h, p) * (180 / Math.PI);
140
+ function g(e, t, n) {
141
+ let r = h(e), i = h(t), a = h(n), o = .4122214708 * r + .5363325363 * i + .0514459929 * a, s = .2119034982 * r + .6806995451 * i + .1073969566 * a, c = .0883024619 * r + .2817188376 * i + .6299787005 * a, l = Math.cbrt(o), u = Math.cbrt(s), d = Math.cbrt(c), f = .2104542553 * l + .793617785 * u - .0040720468 * d, p = 1.9779984951 * l - 2.428592205 * u + .4505937099 * d, m = .0259040371 * l + .7827717662 * u - .808675766 * d, g = Math.sqrt(p * p + m * m), _ = Math.atan2(m, p) * (180 / Math.PI);
142
142
  return _ < 0 && (_ += 360), [
143
143
  f,
144
144
  g,
@@ -146,7 +146,7 @@ function h(e, t, n) {
146
146
  ];
147
147
  }
148
148
  /** sRGB (0–255) → HSL. Returns [H (0–360), S (0–100), L (0–100)]. */
149
- function g(e, t, n) {
149
+ function _(e, t, n) {
150
150
  e /= 255, t /= 255, n /= 255;
151
151
  let r = Math.max(e, t, n), i = Math.min(e, t, n), a = r - i, o = (r + i) / 2;
152
152
  if (a === 0) return [
@@ -162,7 +162,7 @@ function g(e, t, n) {
162
162
  ];
163
163
  }
164
164
  /** sRGB (0–255) → HSB/HSV. Returns [H (0–360), S (0–100), B (0–100)]. */
165
- function _(e, t, n) {
165
+ function v(e, t, n) {
166
166
  e /= 255, t /= 255, n /= 255;
167
167
  let r = Math.max(e, t, n), i = r - Math.min(e, t, n), a = r * 100;
168
168
  if (r === 0) return [
@@ -177,47 +177,47 @@ function _(e, t, n) {
177
177
  a
178
178
  ];
179
179
  }
180
- function v(e, t, n, r) {
181
- let [i, a, o] = h(e, t, n), s = `oklch(${(i * 100).toFixed(1)}% ${a.toFixed(4)} ${o.toFixed(1)})`;
182
- return r < 1 ? `oklch(${(i * 100).toFixed(1)}% ${a.toFixed(4)} ${o.toFixed(1)} / ${r.toFixed(2)})` : s;
183
- }
184
180
  function y(e, t, n, r) {
185
- let i = `#${p(e)}${p(t)}${p(n)}`;
186
- return r < 1 ? `${i}${p(Math.round(r * 255))}` : i;
181
+ let [i, a, o] = g(e, t, n), s = `oklch(${(i * 100).toFixed(1)}% ${a.toFixed(4)} ${o.toFixed(1)})`;
182
+ return r < 1 ? `oklch(${(i * 100).toFixed(1)}% ${a.toFixed(4)} ${o.toFixed(1)} / ${r.toFixed(2)})` : s;
187
183
  }
188
184
  function b(e, t, n, r) {
189
- return r < 1 ? `rgba(${Math.round(e)}, ${Math.round(t)}, ${Math.round(n)}, ${r.toFixed(2)})` : `rgb(${Math.round(e)}, ${Math.round(t)}, ${Math.round(n)})`;
185
+ let i = `#${m(e)}${m(t)}${m(n)}`;
186
+ return r < 1 ? `${i}${m(Math.round(r * 255))}` : i;
190
187
  }
191
188
  function x(e, t, n, r) {
192
- let [i, a, o] = g(e, t, n);
193
- return r < 1 ? `hsla(${i.toFixed(0)}, ${a.toFixed(1)}%, ${o.toFixed(1)}%, ${r.toFixed(2)})` : `hsl(${i.toFixed(0)}, ${a.toFixed(1)}%, ${o.toFixed(1)}%)`;
189
+ return r < 1 ? `rgba(${Math.round(e)}, ${Math.round(t)}, ${Math.round(n)}, ${r.toFixed(2)})` : `rgb(${Math.round(e)}, ${Math.round(t)}, ${Math.round(n)})`;
194
190
  }
195
191
  function S(e, t, n, r) {
196
192
  let [i, a, o] = _(e, t, n);
193
+ return r < 1 ? `hsla(${i.toFixed(0)}, ${a.toFixed(1)}%, ${o.toFixed(1)}%, ${r.toFixed(2)})` : `hsl(${i.toFixed(0)}, ${a.toFixed(1)}%, ${o.toFixed(1)}%)`;
194
+ }
195
+ function C(e, t, n, r) {
196
+ let [i, a, o] = v(e, t, n);
197
197
  return `hsb(${i.toFixed(0)}, ${a.toFixed(1)}%, ${o.toFixed(1)}%)`;
198
198
  }
199
- var C = [
199
+ var w = [
200
200
  {
201
201
  label: "OKLCH",
202
- fn: v
202
+ fn: y
203
203
  },
204
204
  {
205
205
  label: "HEX",
206
- fn: y
206
+ fn: b
207
207
  },
208
208
  {
209
209
  label: "RGB",
210
- fn: b
210
+ fn: x
211
211
  },
212
212
  {
213
213
  label: "HSL",
214
- fn: x
214
+ fn: S
215
215
  },
216
216
  {
217
217
  label: "HSB",
218
- fn: S
218
+ fn: C
219
219
  }
220
- ], w = class extends o {
220
+ ], T = class extends o {
221
221
  static observedAttributes = ["token", "name"];
222
222
  #e = null;
223
223
  #t = null;
@@ -240,7 +240,7 @@ var C = [
240
240
  setup() {
241
241
  super.setup(), this.token && (this.style.background = `var(${this.token})`, this.title = `${this.name}\n${this.token}`);
242
242
  let e = document.createElement("span");
243
- e.className = "native-tokens-swatch-label", e.textContent = this.name, this.#t = e, this.appendChild(e), this.#n = c("swatch"), this.style.setProperty("anchor-name", `--${this.#n}`);
243
+ e.className = "native-tokens-swatch-label", e.textContent = this.name, this.#t = e, this.appendChild(e), this.#n = l("swatch"), this.style.setProperty("anchor-name", `--${this.#n}`);
244
244
  let t = document.createElement("div");
245
245
  t.className = "native-tokens-swatch-popover", t.setAttribute("popover", "auto"), t.style.setProperty("position-anchor", `--${this.#n}`), this.#e = t, this.appendChild(t), this.addEventListener("click", this.#i), this.addEventListener("native-tokens-change", this.#r), this.addEventListener("native-tokens-theme-change", this.#r), requestAnimationFrame(() => this.#a());
246
246
  }
@@ -263,15 +263,15 @@ var C = [
263
263
  }
264
264
  };
265
265
  #a() {
266
- let e = getComputedStyle(this).backgroundColor, [t, n, r] = d(e);
267
- this.#t && (this.#t.style.color = f(t, n, r) ? "rgba(0,0,0,0.55)" : "rgba(255,255,255,0.7)");
266
+ let e = getComputedStyle(this).backgroundColor, [t, n, r] = f(e);
267
+ this.#t && (this.#t.style.color = p(t, n, r) ? "rgba(0,0,0,0.55)" : "rgba(255,255,255,0.7)");
268
268
  }
269
269
  #o() {
270
270
  if (!this.#e) return;
271
271
  this.#e.innerHTML = "";
272
- let e = getComputedStyle(this).backgroundColor, [t, n, r, i] = d(e), a = document.createElement("div");
272
+ let e = getComputedStyle(this).backgroundColor, [t, n, r, i] = f(e), a = document.createElement("div");
273
273
  a.className = "native-tokens-swatch-popover-header", a.textContent = this.token, this.#e.appendChild(a);
274
- for (let e of C) {
274
+ for (let e of w) {
275
275
  let a = e.fn(t, n, r, i), o = document.createElement("button");
276
276
  o.className = "native-tokens-swatch-popover-row", o.type = "button";
277
277
  let s = document.createElement("span");
@@ -286,7 +286,7 @@ var C = [
286
286
  }), this.#e.appendChild(o);
287
287
  }
288
288
  }
289
- }, T = /* @__PURE__ */ "n-env-lightness-min.n-env-lightness-max.n-env-lightness-delta.n-env-chroma.n-env-chroma-k-muted.n-env-chroma-k-vivid.n-env-chroma-k-edge.n-env-alpha.n-env-alpha-delta.n-env-hue-neutral.n-env-chroma-neutral.n-env-lightness-neutral.n-env-hue-accent.n-env-chroma-accent.n-env-lightness-accent.n-env-hue-info.n-env-chroma-info.n-env-lightness-info.n-env-hue-success.n-env-chroma-success.n-env-lightness-success.n-env-hue-warning.n-env-chroma-warning.n-env-lightness-warning.n-env-hue-danger.n-env-chroma-danger.n-env-lightness-danger".split("."), E = class extends o {
289
+ }, E = /* @__PURE__ */ "n-env-lightness-min.n-env-lightness-max.n-env-lightness-delta.n-env-chroma.n-env-chroma-k-muted.n-env-chroma-k-vivid.n-env-chroma-k-edge.n-env-alpha.n-env-alpha-delta.n-env-hue-neutral.n-env-chroma-neutral.n-env-lightness-neutral.n-env-hue-accent.n-env-chroma-accent.n-env-lightness-accent.n-env-hue-info.n-env-chroma-info.n-env-lightness-info.n-env-hue-success.n-env-chroma-success.n-env-lightness-success.n-env-hue-warning.n-env-chroma-warning.n-env-lightness-warning.n-env-hue-danger.n-env-chroma-danger.n-env-lightness-danger".split("."), D = class extends o {
290
290
  static observedAttributes = ["data"];
291
291
  #e = [];
292
292
  attributeChangedCallback(e, t, n) {
@@ -320,13 +320,15 @@ var C = [
320
320
  }
321
321
  #n(e) {
322
322
  let t = document.documentElement;
323
- for (let e of T) t.style.removeProperty("--" + e);
323
+ for (let e of E) t.style.removeProperty("--" + e);
324
324
  e ? t.setAttribute("theme", e) : t.removeAttribute("theme"), this.dispatchEvent(new CustomEvent("native-tokens-theme-change", {
325
325
  bubbles: !0,
326
326
  detail: { theme: e }
327
327
  }));
328
328
  }
329
- }, D = [
329
+ };
330
+ /** Available theme presets. */
331
+ const O = [
330
332
  {
331
333
  name: "Default",
332
334
  value: ""
@@ -343,96 +345,103 @@ var C = [
343
345
  name: "Zinc",
344
346
  value: "zinc"
345
347
  }
346
- ], O = [
348
+ ], k = [
349
+ "neutral",
350
+ "accent",
351
+ "info",
352
+ "success",
353
+ "warning",
354
+ "danger"
355
+ ], A = [{
356
+ value: "all",
357
+ label: "All Families"
358
+ }, ...k.map((e) => ({
359
+ value: e,
360
+ label: e.charAt(0).toUpperCase() + e.slice(1)
361
+ }))];
362
+ var j = [
347
363
  {
364
+ type: "variable",
348
365
  name: "L min",
349
366
  token: "--n-env-lightness-min",
350
367
  value: .15,
351
368
  step: .01,
352
369
  min: 0,
353
- max: 1,
354
- group: "Lightness"
370
+ max: 1
355
371
  },
356
372
  {
373
+ type: "variable",
357
374
  name: "L max",
358
375
  token: "--n-env-lightness-max",
359
376
  value: 1,
360
377
  step: .01,
361
378
  min: 0,
362
- max: 1,
363
- group: "Lightness"
379
+ max: 1
364
380
  },
365
381
  {
382
+ type: "variable",
366
383
  name: "L delta",
367
384
  token: "--n-env-lightness-delta",
368
385
  value: .015,
369
386
  step: .005,
370
387
  min: 0,
371
- max: .15,
372
- group: "Lightness"
388
+ max: .15
373
389
  },
374
390
  {
391
+ type: "variable",
375
392
  name: "Chroma",
376
393
  token: "--n-env-chroma",
377
394
  value: .2,
378
395
  step: .005,
379
396
  min: 0,
380
- max: .5,
381
- group: "Chroma"
397
+ max: .5
382
398
  },
383
399
  {
400
+ type: "variable",
384
401
  name: "C muted",
385
402
  token: "--n-env-chroma-k-muted",
386
403
  value: .125,
387
404
  step: .01,
388
405
  min: 0,
389
- max: 1,
390
- group: "Chroma"
406
+ max: 1
391
407
  },
392
408
  {
409
+ type: "variable",
393
410
  name: "C vivid",
394
411
  token: "--n-env-chroma-k-vivid",
395
412
  value: 1,
396
413
  step: .01,
397
414
  min: 0,
398
- max: 1,
399
- group: "Chroma"
415
+ max: 1
400
416
  },
401
417
  {
418
+ type: "variable",
402
419
  name: "C edge",
403
420
  token: "--n-env-chroma-k-edge",
404
421
  value: .05,
405
422
  step: .01,
406
423
  min: 0,
407
- max: 1,
408
- group: "Chroma"
424
+ max: 1
409
425
  },
410
426
  {
427
+ type: "variable",
411
428
  name: "Alpha",
412
429
  token: "--n-env-alpha",
413
430
  value: .85,
414
431
  step: .01,
415
432
  min: 0,
416
- max: 1,
417
- group: "Alpha"
433
+ max: 1
418
434
  },
419
435
  {
436
+ type: "variable",
420
437
  name: "A delta",
421
438
  token: "--n-env-alpha-delta",
422
439
  value: .02,
423
440
  step: .005,
424
441
  min: 0,
425
- max: .15,
426
- group: "Alpha"
442
+ max: .15
427
443
  }
428
- ], k = [
429
- "neutral",
430
- "accent",
431
- "info",
432
- "success",
433
- "warning",
434
- "danger"
435
- ], A = [
444
+ ], M = [
436
445
  "lowest",
437
446
  "lower",
438
447
  "low",
@@ -440,7 +449,7 @@ var C = [
440
449
  "high",
441
450
  "higher",
442
451
  "highest"
443
- ], j = [
452
+ ], N = [
444
453
  "brightest",
445
454
  "brighter",
446
455
  "bright",
@@ -448,7 +457,7 @@ var C = [
448
457
  "dim",
449
458
  "dimmer",
450
459
  "dimmest"
451
- ], M = [
460
+ ], P = [
452
461
  "1",
453
462
  "2",
454
463
  "3",
@@ -460,7 +469,7 @@ var C = [
460
469
  "9",
461
470
  "10",
462
471
  "11"
463
- ], N = [
472
+ ], F = [
464
473
  "050",
465
474
  "100",
466
475
  "200",
@@ -472,7 +481,7 @@ var C = [
472
481
  "800",
473
482
  "900",
474
483
  "950"
475
- ], P = [
484
+ ], I = [
476
485
  "strongest",
477
486
  "stronger",
478
487
  "strong",
@@ -481,21 +490,144 @@ var C = [
481
490
  "weaker",
482
491
  "weakest"
483
492
  ];
484
- function F(e, t) {
493
+ /** Group env params into titled sections by their logical group. */
494
+ function L() {
495
+ let e = {};
496
+ for (let t of j) {
497
+ let n = t.token.startsWith("--n-env-lightness") ? "Lightness" : t.token.startsWith("--n-env-chroma") ? "Chroma" : "Alpha";
498
+ (e[n] ??= []).push(t);
499
+ }
500
+ return Object.entries(e).map(([e, t]) => ({
501
+ title: e,
502
+ family: "env",
503
+ items: t
504
+ }));
505
+ }
506
+ /** Build the items array for a single color family. */
507
+ function R(e) {
508
+ return [
509
+ {
510
+ type: "variable",
511
+ name: "Hue",
512
+ token: `--n-env-hue-${e}`,
513
+ value: 230,
514
+ step: 1,
515
+ min: 0,
516
+ max: 360
517
+ },
518
+ {
519
+ type: "variable",
520
+ name: "Chroma",
521
+ token: `--n-env-chroma-${e}`,
522
+ value: .5,
523
+ step: .01,
524
+ min: 0,
525
+ max: 1
526
+ },
527
+ {
528
+ type: "variable",
529
+ name: "Lightness",
530
+ token: `--n-env-lightness-${e}`,
531
+ value: .5,
532
+ step: .01,
533
+ min: 0,
534
+ max: 1
535
+ },
536
+ {
537
+ type: "strip",
538
+ label: "Elevation",
539
+ colors: M.map((t) => ({
540
+ name: t,
541
+ token: `--n-color-${e}-${t}`
542
+ }))
543
+ },
544
+ {
545
+ type: "strip",
546
+ label: "Brightness",
547
+ colors: N.map((t) => ({
548
+ name: t,
549
+ token: `--n-color-${e}-${t}`
550
+ }))
551
+ },
552
+ {
553
+ type: "strip",
554
+ label: "Solid",
555
+ colors: P.map((t) => ({
556
+ name: t,
557
+ token: `--n-color-${e}-${t}`
558
+ }))
559
+ },
560
+ {
561
+ type: "strip",
562
+ label: "Scrim",
563
+ colors: P.map((t) => ({
564
+ name: t,
565
+ token: `--n-color-${e}-${t}-scrim`
566
+ }))
567
+ },
568
+ {
569
+ type: "strip",
570
+ label: "Semantic",
571
+ colors: F.map((t) => ({
572
+ name: t,
573
+ token: `--n-color-${e}-${t}`
574
+ }))
575
+ },
576
+ {
577
+ type: "strip",
578
+ label: "Semantic Scrim",
579
+ colors: F.map((t) => ({
580
+ name: t,
581
+ token: `--n-color-${e}-${t}-scrim`
582
+ }))
583
+ },
584
+ {
585
+ type: "strip",
586
+ label: "Tint",
587
+ colors: I.map((t) => ({
588
+ name: t,
589
+ token: `--n-color-${e}-scrim-tint-${t}`
590
+ }))
591
+ },
592
+ {
593
+ type: "strip",
594
+ label: "Shade",
595
+ colors: I.map((t) => ({
596
+ name: t,
597
+ token: `--n-color-${e}-scrim-shade-${t}`
598
+ }))
599
+ }
600
+ ];
601
+ }
602
+ /**
603
+ * Returns the default token schema — all env params + all 6 color families
604
+ * with their full ramp of surfaces, solids, semantics, and scrims.
605
+ *
606
+ * Hosts can call this, mutate the result (drop sections, reorder, add custom
607
+ * tokens), and pass the modified schema to `<native-tokens>`.
608
+ */
609
+ function z() {
610
+ return { sections: [...L(), ...k.map((e) => ({
611
+ title: e.charAt(0).toUpperCase() + e.slice(1),
612
+ family: e,
613
+ items: R(e)
614
+ }))] };
615
+ }
616
+ function B(e, t) {
485
617
  let n = document.createElement("div");
486
618
  n.className = "native-tokens-section", t && (n.dataset.family = t);
487
619
  let r = document.createElement("h3");
488
620
  return r.className = "native-tokens-heading", r.textContent = e, n.appendChild(r), n;
489
621
  }
490
- function I(e) {
622
+ function V(e) {
491
623
  let t = document.createElement("h4");
492
624
  return t.className = "native-tokens-subheading", t.textContent = e, t;
493
625
  }
494
- function L(e) {
626
+ function H(e) {
495
627
  let t = document.createElement("native-tokens-colors");
496
628
  return t.setAttribute("data", JSON.stringify(e)), t;
497
629
  }
498
- function R(e) {
630
+ function U(e) {
499
631
  let t = document.createElement("native-tokens-variable");
500
632
  return t.setAttribute("data", JSON.stringify({
501
633
  name: e.name,
@@ -507,101 +639,115 @@ function R(e) {
507
639
  max: e.max
508
640
  })), t;
509
641
  }
510
- function z(e) {
511
- let t = document.createElement("div");
512
- t.className = "native-tokens-toolbar";
513
- let n = document.createElement("native-tokens-themes");
514
- n.setAttribute("data", JSON.stringify(D)), t.appendChild(n);
515
- let r = [{
516
- value: "all",
517
- label: "All Families"
518
- }, ...k.map((e) => ({
519
- value: e,
520
- label: e.charAt(0).toUpperCase() + e.slice(1)
521
- }))], i = document.createElement("n-select");
522
- i.setAttribute("size", "xs"), i.setAttribute("placeholder", "Family..."), i.setAttribute("options", JSON.stringify(r)), i.setAttribute("value", "all"), t.appendChild(i), e.appendChild(t);
523
- let a = "", o = null;
524
- for (let t of O) t.group !== a && (a = t.group, o = F(t.group, "env"), e.appendChild(o)), o.appendChild(R(t));
525
- for (let t of k) {
526
- let n = F(t.charAt(0).toUpperCase() + t.slice(1), t);
527
- n.appendChild(R({
528
- name: "Hue",
529
- token: `--n-env-hue-${t}`,
530
- value: 230,
531
- step: 1,
532
- min: 0,
533
- max: 360
534
- })), n.appendChild(R({
535
- name: "Chroma",
536
- token: `--n-env-chroma-${t}`,
537
- value: .5,
538
- step: .01,
539
- min: 0,
540
- max: 1
541
- })), n.appendChild(R({
542
- name: "Lightness",
543
- token: `--n-env-lightness-${t}`,
544
- value: .5,
545
- step: .01,
546
- min: 0,
547
- max: 1
548
- })), n.appendChild(I("Elevation")), n.appendChild(L(A.map((e) => ({
549
- name: e,
550
- token: `--n-color-${t}-${e}`
551
- })))), n.appendChild(I("Brightness")), n.appendChild(L(j.map((e) => ({
552
- name: e,
553
- token: `--n-color-${t}-${e}`
554
- })))), n.appendChild(I("Solid")), n.appendChild(L(M.map((e) => ({
555
- name: e,
556
- token: `--n-color-${t}-${e}`
557
- })))), n.appendChild(I("Scrim")), n.appendChild(L(M.map((e) => ({
558
- name: e,
559
- token: `--n-color-${t}-${e}-scrim`
560
- })))), n.appendChild(I("Semantic")), n.appendChild(L(N.map((e) => ({
561
- name: e,
562
- token: `--n-color-${t}-${e}`
563
- })))), n.appendChild(I("Semantic Scrim")), n.appendChild(L(N.map((e) => ({
564
- name: e,
565
- token: `--n-color-${t}-${e}-scrim`
566
- })))), n.appendChild(I("Tint")), n.appendChild(L(P.map((e) => ({
567
- name: e,
568
- token: `--n-color-${t}-scrim-tint-${e}`
569
- })))), n.appendChild(I("Shade")), n.appendChild(L(P.map((e) => ({
570
- name: e,
571
- token: `--n-color-${t}-scrim-shade-${e}`
572
- })))), e.appendChild(n);
573
- }
574
- i.addEventListener("native:change", ((t) => {
575
- let n = t.detail.value, r = e.querySelectorAll(".native-tokens-section[data-family]");
576
- for (let e of r) {
577
- let t = e.dataset.family;
578
- n === "all" || t === "env" ? e.hidden = !1 : e.hidden = t !== n;
579
- }
580
- requestAnimationFrame(() => {
581
- e.querySelectorAll("native-tokens-colors").forEach((e) => e.refresh());
582
- });
583
- })), e.addEventListener("native-tokens-theme-change", () => {
584
- requestAnimationFrame(() => {
585
- e.querySelectorAll("native-tokens-variable").forEach((e) => e.sync());
586
- });
587
- });
642
+ /**
643
+ * Stamps token sections into `container` from the given schema.
644
+ * Falls back to `createDefaultSchema()` when no schema is provided.
645
+ *
646
+ * This is a pure renderer — no header, filter, or theme controls.
647
+ * The host provides those and wires them to the `<native-tokens>` element's
648
+ * `family` attribute and the `native-tokens-theme-change` event.
649
+ */
650
+ function W(e, t) {
651
+ let { sections: n } = t ?? z();
652
+ for (let t of n) {
653
+ let n = B(t.title, t.family);
654
+ for (let e of t.items) e.type === "variable" ? n.appendChild(U(e)) : (n.appendChild(V(e.label)), n.appendChild(H(e.colors)));
655
+ e.appendChild(n);
656
+ }
588
657
  }
589
658
  /**
590
- * Self-contained design system token inspector.
659
+ * Design system token inspector — renders token sections from a schema.
660
+ *
661
+ * - `schema` property — JSON-serializable `TokenSchema` describing what to
662
+ * render. Falls back to `createDefaultSchema()` when unset.
663
+ * - `family` attribute — filters visible sections ("all" or a family name).
664
+ * - `native-tokens-theme-change` event (document-level) — syncs variable sliders.
591
665
  *
592
- * Stamps the full color/variable inspector UI on connection.
593
- * Consumer usage: `<native-tokens></native-tokens>`.
666
+ * Minimal usage (default schema, host provides layout):
667
+ * ```html
668
+ * <native-tokens></native-tokens>
669
+ * ```
594
670
  *
595
- * All `native-tokens-*` sub-elements are registered by the `@nonoun/native-tokens`
596
- * entry point as a side effect of import.
671
+ * Custom schema (host decides what to show):
672
+ * ```js
673
+ * const el = document.querySelector('native-tokens');
674
+ * el.schema = myCustomSchema;
675
+ * ```
597
676
  */
598
- var B = class extends o {
677
+ var G = class extends o {
678
+ static observedAttributes = ["family"];
679
+ #e;
680
+ /** JSON-serializable schema describing what to render. */
681
+ get schema() {
682
+ return this.#e;
683
+ }
684
+ set schema(e) {
685
+ this.#e = e, this.isConnected && this.#t();
686
+ }
687
+ attributeChangedCallback(e, t, n) {
688
+ t !== n && e === "family" && this.#n(n || "all");
689
+ }
599
690
  setup() {
600
- super.setup(), z(this);
691
+ super.setup(), W(this, this.#e);
692
+ let e = this.getAttribute("family");
693
+ e && this.#n(e), document.addEventListener("native-tokens-theme-change", this.#r);
601
694
  }
602
695
  teardown() {
603
- this.innerHTML = "", super.teardown();
696
+ document.removeEventListener("native-tokens-theme-change", this.#r), this.innerHTML = "", super.teardown();
697
+ }
698
+ #t() {
699
+ this.innerHTML = "", W(this, this.#e);
700
+ let e = this.getAttribute("family");
701
+ e && this.#n(e);
702
+ }
703
+ #n(e) {
704
+ let t = this.querySelectorAll(".native-tokens-section[data-family]");
705
+ for (let n of t) {
706
+ let t = n.dataset.family;
707
+ e === "all" || t === "env" ? n.hidden = !1 : n.hidden = t !== e;
708
+ }
709
+ requestAnimationFrame(() => {
710
+ this.querySelectorAll("native-tokens-colors").forEach((e) => e.refresh());
711
+ });
712
+ }
713
+ #r = () => {
714
+ requestAnimationFrame(() => {
715
+ this.querySelectorAll("native-tokens-variable").forEach((e) => e.sync());
716
+ });
717
+ };
718
+ }, K = class extends o {
719
+ #e = null;
720
+ #t;
721
+ /** Pass-through to the inner `<native-tokens>` schema. */
722
+ get schema() {
723
+ return this.#t;
724
+ }
725
+ set schema(e) {
726
+ this.#t = e, this.#e && (this.#e.schema = e);
727
+ }
728
+ setup() {
729
+ super.setup();
730
+ let e = document.createElement("n-header");
731
+ e.setAttribute("sticky", "");
732
+ let t = document.createElement("n-icon");
733
+ t.setAttribute("name", "palette"), t.setAttribute("slot", "leading"), e.appendChild(t);
734
+ let n = document.createElement("span");
735
+ n.setAttribute("slot", "label"), n.textContent = "Design Tokens", e.appendChild(n);
736
+ let r = document.createElement("div");
737
+ r.setAttribute("slot", "content");
738
+ let i = document.createElement("native-tokens-themes");
739
+ i.setAttribute("data", JSON.stringify(O));
740
+ let a = document.createElement("n-select");
741
+ a.setAttribute("size", "xs"), a.setAttribute("placeholder", "Family..."), a.setAttribute("options", JSON.stringify(A)), a.setAttribute("value", "all"), r.append(i, a), e.appendChild(r);
742
+ let o = document.createElement("n-body"), s = document.createElement("native-tokens");
743
+ this.#t && (s.schema = this.#t), o.appendChild(s), this.#e = s, this.append(e, o), a.addEventListener("native:change", ((e) => {
744
+ let t = e.detail.value;
745
+ s.setAttribute("family", t);
746
+ }));
747
+ }
748
+ teardown() {
749
+ this.innerHTML = "", this.#e = null, super.teardown();
604
750
  }
605
751
  };
606
- s("native-tokens", B), s("native-tokens-variable", l), s("native-tokens-colors", u), s("native-tokens-color-swatch", w), s("native-tokens-themes", E), s("n-range", i), s("n-select", a), s("n-button", e), s("n-icon", t), s("n-listbox", n), s("n-option", r);
607
- export { B as NTokens, w as NTokensColorSwatch, u as NTokensColors, E as NTokensThemes, l as NTokensVariable, z as buildTokens };
752
+ s("native-tokens", G), s("native-tokens-variable", u), s("native-tokens-colors", d), s("native-tokens-color-swatch", T), s("native-tokens-themes", D), s("native-tokens-panel", K), s("n-range", i), s("n-select", a), s("n-button", e), s("n-icon", t), s("n-listbox", n), s("n-option", r), c("palette", "<svg viewBox=\"0 0 256 256\" fill=\"currentColor\"><path d=\"M200.77,53.89A103.27,103.27,0,0,0,128,24h-1.07A104,104,0,0,0,24,128c0,43,26.58,79.06,69.36,94.17A32,32,0,0,0,136,192a16,16,0,0,1,16-16h46.21a31.81,31.81,0,0,0,31.2-24.88,104.43,104.43,0,0,0,2.59-24A103.28,103.28,0,0,0,200.77,53.89Zm13,93.71A15.89,15.89,0,0,1,198.21,160H152a32,32,0,0,0-32,32,16,16,0,0,1-21.31,15.07C62.49,194.3,40,164,40,128a88,88,0,0,1,87.09-88h.9a88.35,88.35,0,0,1,88,87.25A88.86,88.86,0,0,1,213.81,147.6ZM140,76a12,12,0,1,1-12-12A12,12,0,0,1,140,76ZM96,100A12,12,0,1,1,84,88,12,12,0,0,1,96,100Zm0,56a12,12,0,1,1-12-12A12,12,0,0,1,96,156Zm88-56a12,12,0,1,1-12-12A12,12,0,0,1,184,100Z\"/></svg>");
753
+ export { G as NTokens, T as NTokensColorSwatch, d as NTokensColors, K as NTokensPanel, D as NTokensThemes, u as NTokensVariable, W as buildTokens, z as createDefaultSchema, k as families, A as familyFilterOptions, O as themes };