@kitlangton/knobs 0.4.0-next.0 → 0.4.0-next.2

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 (47) hide show
  1. package/README.md +351 -43
  2. package/dist/dev/{chunk-stbcgz1y.js → chunk-1qzffbpa.js} +443 -451
  3. package/dist/dev/{chunk-7xgkerd2.js → chunk-3ygqgy1x.js} +23 -1
  4. package/dist/dev/{chunk-pmkvb9ep.js → chunk-8mabjeyk.js} +1920 -507
  5. package/dist/dev/{chunk-t68smqkc.js → chunk-ayb292zj.js} +13 -11
  6. package/dist/dev/index.js +10 -5
  7. package/dist/index.js +25 -1
  8. package/dist/panel.js +2900 -1320
  9. package/dist/react.js +294 -6
  10. package/dist/solid.js +292 -4
  11. package/dist/themes.js +1509 -7
  12. package/dist/types/core/adapter.d.ts +6 -2
  13. package/dist/types/core/appearance.d.ts +44 -0
  14. package/dist/types/core/glide.d.ts +7 -0
  15. package/dist/types/core/motion.d.ts +66 -0
  16. package/dist/types/core/root.d.ts +13 -0
  17. package/dist/types/core/store.d.ts +18 -5
  18. package/dist/types/core/theme.d.ts +10 -3
  19. package/dist/types/index.d.ts +2 -1
  20. package/dist/types/panel/gpu/color.d.ts +6 -0
  21. package/dist/types/panel/motion.d.ts +1 -1
  22. package/dist/types/panel/styles.d.ts +2 -3
  23. package/dist/types/themes/define.d.ts +104 -0
  24. package/dist/types/themes/index.d.ts +11 -0
  25. package/dist/types/themes/knobs.d.ts +5 -0
  26. package/dist/types/themes/void.d.ts +8 -0
  27. package/dist/types/tokens/color.d.ts +42 -0
  28. package/dist/types/tokens/css.d.ts +13 -0
  29. package/dist/types/tokens/evaluate.d.ts +8 -0
  30. package/dist/types/tokens/index.d.ts +4 -0
  31. package/dist/types/tokens/schema.d.ts +1100 -0
  32. package/dist/types/ui/bento-css.d.ts +1 -1
  33. package/dist/types/ui/compare-css.d.ts +1 -1
  34. package/dist/types/ui/index.d.ts +3 -3
  35. package/dist/types/ui/look.d.ts +18 -13
  36. package/dist/types/ui/overlay-css.d.ts +1 -1
  37. package/dist/types/ui/readout-css.d.ts +1 -1
  38. package/dist/types/ui/readout-model.d.ts +5 -1
  39. package/dist/types/ui/rgba.d.ts +11 -0
  40. package/dist/types/ui/walkthrough-blocks.d.ts +43 -0
  41. package/dist/types/ui/walkthrough-media.d.ts +4 -0
  42. package/dist/types/ui/walkthrough-model.d.ts +237 -3
  43. package/dist/types/ui/walkthrough.d.ts +3 -1
  44. package/dist/ui-react.js +3193 -791
  45. package/dist/ui-solid.js +3193 -791
  46. package/dist/ui.js +3340 -935
  47. package/package.json +1 -1
@@ -1,13 +1,15 @@
1
1
  import {
2
2
  __preload
3
- } from "./chunk-7xgkerd2.js";
3
+ } from "./chunk-3ygqgy1x.js";
4
4
  import {
5
+ applyLook,
6
+ panelLook,
5
7
  iconSvg,
6
8
  readSession,
7
9
  writeSession,
8
10
  injectStyles,
9
11
  toggleLayer
10
- } from "./chunk-pmkvb9ep.js";
12
+ } from "./chunk-8mabjeyk.js";
11
13
 
12
14
  // src/panel/attach.ts
13
15
  function attach(controls, element, options = {}) {
@@ -16,7 +18,7 @@ function attach(controls, element, options = {}) {
16
18
  let doc = element.ownerDocument, win = doc.defaultView;
17
19
  injectStyles(doc);
18
20
  let label = options.label ?? controls.chip.label, reveal = options.reveal ?? controls.chip.reveal, shortcut = options.shortcut ?? controls.chip.shortcut, chip = doc.createElement("button");
19
- chip.className = "knobs-chip", chip.dataset.theme = controls.theme, chip.type = "button";
21
+ chip.className = "knobs-root knobs-chip", applyLook(chip, panelLook(controls)), chip.type = "button";
20
22
  let renderFace = (text) => {
21
23
  let face = [iconSvg(doc, "gear")];
22
24
  if (text) {
@@ -83,7 +85,7 @@ function attach(controls, element, options = {}) {
83
85
  return;
84
86
  loading = !0;
85
87
  try {
86
- let { createPanel } = await (__preload("stbcgz1y"), import("./chunk-stbcgz1y.js"));
88
+ let { createPanel } = await (__preload("1qzffbpa"), import("./chunk-1qzffbpa.js"));
87
89
  if (disposed || !controls.enabled || panel)
88
90
  return;
89
91
  if (panel = createPanel(controls, element, close, { restored, chip }), remember)
@@ -104,7 +106,7 @@ function attach(controls, element, options = {}) {
104
106
  if (!revealed())
105
107
  close(!1);
106
108
  update();
107
- }, offShortcut = reveal === "shortcut" ? listenForShortcut(win, shortcut, controls.theme) : void 0;
109
+ }, offShortcut = reveal === "shortcut" ? listenForShortcut(win, shortcut, panelLook(controls)) : void 0;
108
110
  win.addEventListener(MODE_EVENT, onMode);
109
111
  let toggled = controls.toggleKey ? toggleLayer(doc).register({
110
112
  id: controls.id,
@@ -137,7 +139,7 @@ function matchShortcut(shortcut) {
137
139
  let parts = shortcut.split("+").map((p) => p.trim().toLowerCase()), key = parts.pop() ?? "", has = (...names) => parts.some((p) => names.includes(p)), alt = has("alt", "option", "opt", "⌥"), shift = has("shift", "⇧"), ctrl = has("ctrl", "control", "⌃"), meta = has("meta", "cmd", "command", "⌘"), code = /^[a-z]$/.test(key) ? `Key${key.toUpperCase()}` : /^\d$/.test(key) ? `Digit${key}` : "";
138
140
  return (event) => event.altKey === alt && event.shiftKey === shift && event.ctrlKey === ctrl && event.metaKey === meta && (code ? event.code === code : event.key.toLowerCase() === key);
139
141
  }
140
- function listenForShortcut(win, shortcut, theme) {
142
+ function listenForShortcut(win, shortcut, look) {
141
143
  let matches = matchShortcut(shortcut), onKey = (event) => {
142
144
  if (event.defaultPrevented || event.repeat || !matches(event))
143
145
  return;
@@ -148,16 +150,16 @@ function listenForShortcut(win, shortcut, theme) {
148
150
  try {
149
151
  win.sessionStorage.setItem(MODE_KEY, on ? "on" : "off");
150
152
  } catch {}
151
- showStatus(win.document, on ? "knobs on" : "knobs off", theme), win.dispatchEvent(new CustomEvent(MODE_EVENT));
153
+ showStatus(win.document, on ? "knobs on" : "knobs off", look), win.dispatchEvent(new CustomEvent(MODE_EVENT));
152
154
  };
153
155
  return win.addEventListener("keydown", onKey, !0), () => win.removeEventListener("keydown", onKey, !0);
154
156
  }
155
157
  var statusTimers = /* @__PURE__ */ new WeakMap;
156
- function showStatus(doc, text, theme) {
157
- let toast = doc.querySelector(".knobs-toast");
158
+ function showStatus(doc, text, look) {
159
+ let toast = doc.querySelector(".knobs-notice");
158
160
  if (!toast)
159
- toast = doc.createElement("div"), toast.className = "knobs-toast", toast.setAttribute("role", "status"), toast.dataset.shown = "false", doc.body.append(toast), toast.getBoundingClientRect();
160
- toast.dataset.theme = theme, toast.textContent = text, toast.dataset.shown = "true", clearTimeout(statusTimers.get(doc));
161
+ toast = doc.createElement("div"), toast.className = "knobs-root knobs-notice", toast.setAttribute("role", "status"), toast.dataset.shown = "false", doc.body.append(toast), toast.getBoundingClientRect();
162
+ applyLook(toast, look), toast.textContent = text, toast.dataset.shown = "true", clearTimeout(statusTimers.get(doc));
161
163
  let el = toast;
162
164
  statusTimers.set(doc, setTimeout(() => el.dataset.shown = "false", 1200));
163
165
  }
package/dist/dev/index.js CHANGED
@@ -63,6 +63,8 @@ import {
63
63
  equal,
64
64
  springMotion2,
65
65
  springCss2,
66
+ SPRINGS2,
67
+ reducedSpring2,
66
68
  RESHAPE,
67
69
  RESET_KEYS,
68
70
  REFRESHES,
@@ -73,8 +75,8 @@ import {
73
75
  browserStorage,
74
76
  urlFlag2,
75
77
  storageKey
76
- } from "./chunk-7xgkerd2.js";
77
- __chunks(import.meta.url,["freshcfm","stbcgz1y","t68smqkc","7xgkerd2","pmkvb9ep"],[["./index.js",3],["./chunk-stbcgz1y.js",3,4],["./chunk-t68smqkc.js",3,4],["./chunk-7xgkerd2.js"],["./chunk-pmkvb9ep.js",3]],0);
78
+ } from "./chunk-3ygqgy1x.js";
79
+ __chunks(import.meta.url,["kd01pt6y","1qzffbpa","ayb292zj","3ygqgy1x","8mabjeyk"],[["./index.js",3],["./chunk-1qzffbpa.js",3,4],["./chunk-ayb292zj.js",3,4],["./chunk-3ygqgy1x.js"],["./chunk-8mabjeyk.js",3]],0);
78
80
  // src/core/random.ts
79
81
  var lattice = (min, max, step, r) => min + Math.floor(r * (Math.floor((max - min) / step + 0.000000001) + 1)) * step, between = (min, max, r) => min + (max - min) * r;
80
82
  function pick(field, random) {
@@ -589,7 +591,7 @@ function sameField(a, b) {
589
591
  function defineControls(id, input, options = {}) {
590
592
  if (!id.trim())
591
593
  throw Error("Controls need a stable, nonempty id.");
592
- let schema = Object.freeze({ ...input }), locked = normalize(schema, {}), actions = Object.freeze([...options.actions ?? []]), theme = options.theme ?? "dark", density = options.density ?? "default", renderer = options.renderer ?? "auto", enabled = () => typeof options.enabled === "function" ? options.enabled() : options.enabled ?? (Boolean(options.ship) || isUnlocked() || typeof location < "u" && ["localhost", "127.0.0.1", "[::1]"].includes(location.hostname)), storage = () => options.storage === void 0 ? browserStorage() : options.storage, persistMode = options.persist ?? "all", valueStorage = () => persistMode === "all" ? storage() : null, variantStorage = () => persistMode === "none" ? null : storage(), draw = options.random ?? Math.random, hostHistory = options.history, unsubscribeHistory, unsubscribeUnlock, listeners = /* @__PURE__ */ new Set, refreshes = 0, notify = () => {
594
+ let schema = Object.freeze({ ...input }), locked = normalize(schema, {}), actions = Object.freeze([...options.actions ?? []]), { theme, appearance } = options, density = options.density ?? "default", renderer = options.renderer ?? "auto", enabled = () => typeof options.enabled === "function" ? options.enabled() : options.enabled ?? (Boolean(options.ship) || isUnlocked() || typeof location < "u" && ["localhost", "127.0.0.1", "[::1]"].includes(location.hostname)), storage = () => options.storage === void 0 ? browserStorage() : options.storage, persistMode = options.persist ?? "all", valueStorage = () => persistMode === "all" ? storage() : null, variantStorage = () => persistMode === "none" ? null : storage(), draw = options.random ?? Math.random, hostHistory = options.history, unsubscribeHistory, unsubscribeUnlock, listeners = /* @__PURE__ */ new Set, refreshes = 0, notify = () => {
593
595
  for (let cb of [...listeners])
594
596
  cb();
595
597
  }, mixed = /* @__PURE__ */ new Set, current = locked, read = !1, error = null, locks = /* @__PURE__ */ new Set, bindings = /* @__PURE__ */ new Map, comparing = null, landing = !1, echo = Math.max(0, options.echo ?? 0), grabbed = /* @__PURE__ */ new Set, changedAt = /* @__PURE__ */ new Map, sent = /* @__PURE__ */ new Map, pending = /* @__PURE__ */ new Map, echoTimer, now = () => typeof performance < "u" ? performance.now() : Date.now(), isHeld = (key) => grabbed.has(key) || echo > 0 && now() - (changedAt.get(key) ?? -1 / 0) < echo, NO_BASE = Object.freeze({ preset: null, groups: Object.freeze({}) }), base = NO_BASE, past = [], future = [], HISTORY = 100, stateKey = storageKey(id, "state"), buildPresets = () => Object.freeze(Object.fromEntries([
@@ -1050,6 +1052,7 @@ function defineControls(id, input, options = {}) {
1050
1052
  },
1051
1053
  actions,
1052
1054
  theme,
1055
+ appearance,
1053
1056
  density,
1054
1057
  renderer,
1055
1058
  keys: options.keys,
@@ -1375,11 +1378,11 @@ function defineControls(id, input, options = {}) {
1375
1378
  code: (format, values) => formatCode(values ?? get(), format),
1376
1379
  variants,
1377
1380
  attach(element, chip) {
1378
- let load = options.ship ? () => options.ship().then((m) => m.attach) : () => (__preload("t68smqkc"), import("./chunk-t68smqkc.js")).then((m) => m.attach);
1381
+ let load = options.ship ? () => options.ship().then((m) => m.attach) : () => (__preload("ayb292zj"), import("./chunk-ayb292zj.js")).then((m) => m.attach);
1379
1382
  return live(load, (attach) => attach(controls, element, chip), (detach) => detach());
1380
1383
  },
1381
1384
  mount(container, mountOptions) {
1382
- let load = options.ship ? () => options.ship().then((m) => m.mountPanel) : () => (__preload("stbcgz1y"), import("./chunk-stbcgz1y.js")).then((m) => m.mountPanel);
1385
+ let load = options.ship ? () => options.ship().then((m) => m.mountPanel) : () => (__preload("1qzffbpa"), import("./chunk-1qzffbpa.js")).then((m) => m.mountPanel);
1383
1386
  return live(load, (mountPanel) => {
1384
1387
  let panel = mountPanel(controls, container, mountOptions);
1385
1388
  return mountOptions?.onReady?.(panel), panel;
@@ -1759,6 +1762,7 @@ export {
1759
1762
  EASINGS2 as EASINGS,
1760
1763
  KONAMI,
1761
1764
  SPRING2 as SPRING,
1765
+ SPRINGS2 as SPRINGS,
1762
1766
  action2 as action,
1763
1767
  actionShortcut2 as actionShortcut,
1764
1768
  angle2 as angle,
@@ -1796,6 +1800,7 @@ export {
1796
1800
  parseColor2 as parseColor,
1797
1801
  point2 as point,
1798
1802
  range2 as range,
1803
+ reducedSpring2 as reducedSpring,
1799
1804
  sampleCurve2 as sampleCurve,
1800
1805
  sampleGradient2 as sampleGradient,
1801
1806
  seed2 as seed,
package/dist/index.js CHANGED
@@ -933,6 +933,27 @@ function springCss(value) {
933
933
  let { omega, zeta } = springMotion(value), { easing, ms } = springEasing(omega, zeta);
934
934
  return { easing, duration: ms };
935
935
  }
936
+ // src/core/motion.ts
937
+ var SPRINGS = {
938
+ instant: { duration: 0.1, bounce: 0 },
939
+ snappy: { duration: 0.25, bounce: 0 },
940
+ default: { duration: 0.3, bounce: 0 },
941
+ calm: { duration: 0.4, bounce: 0 },
942
+ smooth: { duration: 0.45, bounce: 0 }
943
+ }, FADE = { duration: 0.16, bounce: 0 };
944
+ var MOTION = Object.fromEntries(Object.entries(SPRINGS).map(([name, spring]) => [name, springMotion(spring)]));
945
+ function reducedSpring(spring, kind, reduced) {
946
+ if (!reduced)
947
+ return spring;
948
+ if (kind === "move")
949
+ return null;
950
+ return spring.duration <= FADE.duration ? spring : FADE;
951
+ }
952
+ var springLinear = (spring) => {
953
+ let { omega, zeta } = springMotion(spring);
954
+ return springEasing(omega, zeta);
955
+ }, names = Object.keys(SPRINGS), linear2 = Object.fromEntries(names.map((n) => [n, springLinear(SPRINGS[n])])), SPRING_TOKEN = `${SPRINGS.default.duration} ${SPRINGS.default.bounce}`, DEFAULT_LINEAR = linear2.default, motionCss = `:where(:root,:host){${names.map((n) => `--_k-motion-${n}:${linear2[n].easing};--_k-motion-${n}-ms:${linear2[n].ms}`).join(";")}}
956
+ @media(prefers-reduced-motion:reduce){:where(:root,:host){${names.map((n) => `--_k-motion-${n}-ms:0`).join(";")}}}`;
936
957
  // src/core/random.ts
937
958
  var lattice = (min, max, step, r) => min + Math.floor(r * (Math.floor((max - min) / step + 0.000000001) + 1)) * step, between2 = (min, max, r) => min + (max - min) * r;
938
959
  function pick(field, random) {
@@ -1588,7 +1609,7 @@ function sameField(a, b) {
1588
1609
  function defineControls(id, input, options = {}) {
1589
1610
  if (!id.trim())
1590
1611
  throw Error("Controls need a stable, nonempty id.");
1591
- let schema = Object.freeze({ ...input }), locked = normalize(schema, {}), actions = Object.freeze([...options.actions ?? []]), theme = options.theme ?? "dark", density = options.density ?? "default", renderer = options.renderer ?? "auto", enabled = () => (Boolean(options.ship) || isUnlocked()) && (typeof options.enabled === "function" ? options.enabled() : options.enabled ?? (Boolean(options.ship) || isUnlocked() || typeof location < "u" && ["localhost", "127.0.0.1", "[::1]"].includes(location.hostname))), storage = () => options.storage === void 0 ? browserStorage() : options.storage, persistMode = options.persist ?? "all", valueStorage = () => persistMode === "all" ? storage() : null, variantStorage = () => persistMode === "none" ? null : storage(), draw = options.random ?? Math.random, hostHistory = options.history, unsubscribeHistory, unsubscribeUnlock, listeners = /* @__PURE__ */ new Set, refreshes = 0, notify = () => {
1612
+ let schema = Object.freeze({ ...input }), locked = normalize(schema, {}), actions = Object.freeze([...options.actions ?? []]), { theme, appearance } = options, density = options.density ?? "default", renderer = options.renderer ?? "auto", enabled = () => (Boolean(options.ship) || isUnlocked()) && (typeof options.enabled === "function" ? options.enabled() : options.enabled ?? (Boolean(options.ship) || isUnlocked() || typeof location < "u" && ["localhost", "127.0.0.1", "[::1]"].includes(location.hostname))), storage = () => options.storage === void 0 ? browserStorage() : options.storage, persistMode = options.persist ?? "all", valueStorage = () => persistMode === "all" ? storage() : null, variantStorage = () => persistMode === "none" ? null : storage(), draw = options.random ?? Math.random, hostHistory = options.history, unsubscribeHistory, unsubscribeUnlock, listeners = /* @__PURE__ */ new Set, refreshes = 0, notify = () => {
1592
1613
  for (let cb of [...listeners])
1593
1614
  cb();
1594
1615
  }, mixed = /* @__PURE__ */ new Set, current = locked, read = !1, error = null, locks = /* @__PURE__ */ new Set, bindings = /* @__PURE__ */ new Map, comparing = null, landing = !1, echo = Math.max(0, options.echo ?? 0), grabbed = /* @__PURE__ */ new Set, changedAt = /* @__PURE__ */ new Map, sent = /* @__PURE__ */ new Map, pending = /* @__PURE__ */ new Map, echoTimer, now = () => typeof performance < "u" ? performance.now() : Date.now(), isHeld = (key) => grabbed.has(key) || echo > 0 && now() - (changedAt.get(key) ?? -1 / 0) < echo, NO_BASE = Object.freeze({ preset: null, groups: Object.freeze({}) }), base = NO_BASE, past = [], future = [], HISTORY = 100, stateKey = storageKey(id, "state"), buildPresets = () => Object.freeze(Object.fromEntries([
@@ -2049,6 +2070,7 @@ function defineControls(id, input, options = {}) {
2049
2070
  },
2050
2071
  actions,
2051
2072
  theme,
2073
+ appearance,
2052
2074
  density,
2053
2075
  renderer,
2054
2076
  keys: options.keys,
@@ -2758,6 +2780,7 @@ export {
2758
2780
  EASINGS,
2759
2781
  KONAMI,
2760
2782
  SPRING,
2783
+ SPRINGS,
2761
2784
  action,
2762
2785
  actionShortcut,
2763
2786
  angle,
@@ -2795,6 +2818,7 @@ export {
2795
2818
  parseColor,
2796
2819
  point,
2797
2820
  range,
2821
+ reducedSpring,
2798
2822
  sampleCurve,
2799
2823
  sampleGradient,
2800
2824
  seed,