@gryt/theme 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -16,17 +16,17 @@ function x(r) {
16
16
  ];
17
17
  }
18
18
  function N([r, a, t]) {
19
- const e = (s) => Math.round(p(s) * 255).toString(16).padStart(2, "0");
19
+ const e = (o) => Math.round(p(o) * 255).toString(16).padStart(2, "0");
20
20
  return `#${e(r)}${e(a)}${e(t)}`;
21
21
  }
22
- function R(r) {
23
- const [a, t, e] = x(r).map(G), s = Math.cbrt(
22
+ function S(r) {
23
+ const [a, t, e] = x(r).map(G), o = Math.cbrt(
24
24
  0.4122214708 * a + 0.5363325363 * t + 0.0514459929 * e
25
25
  ), c = Math.cbrt(
26
26
  0.2119034982 * a + 0.6806995451 * t + 0.1073969566 * e
27
27
  ), n = Math.cbrt(
28
28
  0.0883024619 * a + 0.2817188376 * t + 0.6299787005 * e
29
- ), f = 0.2104542553 * s + 0.793617785 * c - 0.0040720468 * n, d = 1.9779984951 * s - 2.428592205 * c + 0.4505937099 * n, g = 0.0259040371 * s + 0.7827717662 * c - 0.808675766 * n;
29
+ ), f = 0.2104542553 * o + 0.793617785 * c - 0.0040720468 * n, d = 1.9779984951 * o - 2.428592205 * c + 0.4505937099 * n, g = 0.0259040371 * o + 0.7827717662 * c - 0.808675766 * n;
30
30
  return {
31
31
  l: f,
32
32
  c: Math.hypot(d, g),
@@ -34,7 +34,7 @@ function R(r) {
34
34
  };
35
35
  }
36
36
  function y({ l: r, c: a, h: t }) {
37
- const e = a * Math.cos(t * Math.PI / 180), s = a * Math.sin(t * Math.PI / 180), c = (r + 0.3963377774 * e + 0.2158037573 * s) ** 3, n = (r - 0.1055613458 * e - 0.0638541728 * s) ** 3, f = (r - 0.0894841775 * e - 1.291485548 * s) ** 3;
37
+ const e = a * Math.cos(t * Math.PI / 180), o = a * Math.sin(t * Math.PI / 180), c = (r + 0.3963377774 * e + 0.2158037573 * o) ** 3, n = (r - 0.1055613458 * e - 0.0638541728 * o) ** 3, f = (r - 0.0894841775 * e - 1.291485548 * o) ** 3;
38
38
  return N([
39
39
  k(p(4.0767416621 * c - 3.3077115913 * n + 0.2309699292 * f)),
40
40
  k(p(-1.2684380046 * c + 2.6097574011 * n - 0.3413193965 * f)),
@@ -43,9 +43,9 @@ function y({ l: r, c: a, h: t }) {
43
43
  }
44
44
  const F = [0.195, 0.24, 0.27, 0.3, 0.33, 0.37, 0.43, 0.52], W = [0.014, 0.026, 0.04, 0.052, 0.062, 0.072, 0.084, 0.1];
45
45
  function h(r, a) {
46
- const { h: t } = R(r), e = F.map((f, d) => y({ l: f, c: W[d], h: t }));
46
+ const { h: t } = S(r), e = F.map((f, d) => y({ l: f, c: W[d], h: t }));
47
47
  e.push(r, a);
48
- const s = R(a).l, c = Math.min(0.95, Math.max(0.84, s + 0.04)), n = Math.min(0.98, Math.max(c + 0.06, 0.93));
48
+ const o = S(a).l, c = Math.min(0.95, Math.max(0.84, o + 0.04)), n = Math.min(0.98, Math.max(c + 0.06, 0.93));
49
49
  return e.push(y({ l: c, c: 0.11, h: t })), e.push(y({ l: n, c: 0.055, h: t })), e;
50
50
  }
51
51
  const B = [
@@ -83,23 +83,23 @@ function I(r) {
83
83
  5: r.border,
84
84
  10: r.muted,
85
85
  11: r.text
86
- }, t = R(r.border).h;
86
+ }, t = S(r.border).h;
87
87
  return B.map(
88
- (e, s) => a[s] ?? y({ l: e, c: K[s], h: t })
88
+ (e, o) => a[o] ?? y({ l: e, c: K[o], h: t })
89
89
  );
90
90
  }
91
- function w(r, a) {
91
+ function R(r, a) {
92
92
  const t = x(a);
93
93
  return r.map((e) => {
94
- const s = x(e);
94
+ const o = x(e);
95
95
  let c = 0;
96
96
  for (let u = 0; u < 3; u++) {
97
- const i = s[u], m = t[u];
97
+ const i = o[u], m = t[u];
98
98
  i > m ? c = Math.max(c, m < 1 ? (i - m) / (1 - m) : 0) : i < m && (c = Math.max(c, m > 0 ? (m - i) / m : 0));
99
99
  }
100
100
  if (c < 1e-6) return "transparent";
101
101
  const n = N(
102
- s.map((u, i) => p(t[i] + (u - t[i]) / c))
102
+ o.map((u, i) => p(t[i] + (u - t[i]) / c))
103
103
  ), [f, d, g] = x(n).map((u) => Math.round(u * 255));
104
104
  return `rgb(${f} ${d} ${g} / ${(c * 100).toFixed(1)}%)`;
105
105
  });
@@ -139,16 +139,16 @@ function U(r) {
139
139
  5: r.border,
140
140
  10: r.muted,
141
141
  11: r.text
142
- }, t = R(r.border).h;
142
+ }, t = S(r.border).h;
143
143
  return q.map(
144
- (e, s) => a[s] ?? y({ l: e, c: J[s], h: t })
144
+ (e, o) => a[o] ?? y({ l: e, c: J[o], h: t })
145
145
  );
146
146
  }
147
147
  function b(r) {
148
- const { l: a, c: t, h: e } = R(r), s = X.map(
148
+ const { l: a, c: t, h: e } = S(r), o = X.map(
149
149
  (c, n) => y({ l: c, c: Q[n], h: e })
150
150
  );
151
- return s.push(r), s.push(y({ l: Math.max(0, a - 0.07), c: t, h: e })), s.push(y({ l: 0.46, c: 0.15, h: e })), s.push(y({ l: 0.33, c: 0.1, h: e })), s;
151
+ return o.push(r), o.push(y({ l: Math.max(0, a - 0.07), c: t, h: e })), o.push(y({ l: 0.46, c: 0.15, h: e })), o.push(y({ l: 0.33, c: 0.1, h: e })), o;
152
152
  }
153
153
  function E(r) {
154
154
  const [a, t, e] = x(r).map(G);
@@ -158,7 +158,7 @@ function oe(r, a) {
158
158
  const t = E(r), e = E(a);
159
159
  return (Math.max(t, e) + 0.05) / (Math.min(t, e) + 0.05);
160
160
  }
161
- const o = {
161
+ const s = {
162
162
  color: {
163
163
  bg: "#111318",
164
164
  surface: "#1a1d24",
@@ -198,41 +198,41 @@ const o = {
198
198
  text: "#1f2129"
199
199
  }, _ = {
200
200
  neutral: I({
201
- bg: o.color.bg,
202
- surface: o.color.surface,
203
- surfaceRaised: o.color.surfaceRaised,
204
- border: o.color.border,
205
- muted: o.color.muted,
206
- text: o.color.text
201
+ bg: s.color.bg,
202
+ surface: s.color.surface,
203
+ surfaceRaised: s.color.surfaceRaised,
204
+ border: s.color.border,
205
+ muted: s.color.muted,
206
+ text: s.color.text
207
207
  }),
208
- accent: h(o.color.accent, o.color.accentLight),
208
+ accent: h(s.color.accent, s.color.accentLight),
209
209
  secondary: h(
210
- o.color.secondary,
211
- o.color.secondaryLight
210
+ s.color.secondary,
211
+ s.color.secondaryLight
212
212
  ),
213
- success: h(o.color.success, o.color.success),
214
- danger: h(o.color.danger, o.color.dangerLight),
215
- warning: h(o.color.warning, o.color.warning)
213
+ success: h(s.color.success, s.color.success),
214
+ danger: h(s.color.danger, s.color.dangerLight),
215
+ warning: h(s.color.warning, s.color.warning)
216
216
  }, T = {
217
217
  neutral: U(l),
218
- accent: b(o.color.accent),
219
- secondary: b(o.color.secondary),
220
- success: b(o.color.success),
221
- danger: b(o.color.danger),
222
- warning: b(o.color.warning)
218
+ accent: b(s.color.accent),
219
+ secondary: b(s.color.secondary),
220
+ success: b(s.color.success),
221
+ danger: b(s.color.danger),
222
+ warning: b(s.color.warning)
223
223
  }, C = T.neutral[3], se = {
224
- neutral: w(_.neutral, o.color.bg),
225
- accent: w(_.accent, o.color.bg)
224
+ neutral: R(_.neutral, s.color.bg),
225
+ accent: R(_.accent, s.color.bg)
226
226
  }, fe = {
227
- neutral: w(T.neutral, l.bg),
228
- accent: w(T.accent, l.bg)
227
+ neutral: R(T.neutral, l.bg),
228
+ accent: R(T.accent, l.bg)
229
229
  };
230
230
  function de(r = {}) {
231
231
  const a = r.appearance === "light", e = { ...a ? {
232
- ...o.color,
232
+ ...s.color,
233
233
  ...l,
234
234
  surfaceHover: C
235
- } : o.color, ...r.color }, s = { ...o.radius, ...r.radius }, c = {
235
+ } : s.color, ...r.color }, o = { ...s.radius, ...r.radius }, c = {
236
236
  bg: e.bg,
237
237
  surface: e.surface,
238
238
  surfaceRaised: e.surfaceRaised,
@@ -259,7 +259,7 @@ function de(r = {}) {
259
259
  f[`--gryt-${d}-${i + 1}`] = u, f[`--color-gryt-${d}-${i + 1}`] = u;
260
260
  });
261
261
  for (const d of ["neutral", "accent"])
262
- w(n[d], e.bg).forEach((g, u) => {
262
+ R(n[d], e.bg).forEach((g, u) => {
263
263
  f[`--gryt-${d}-a${u + 1}`] = g, f[`--color-gryt-${d}-a${u + 1}`] = g;
264
264
  });
265
265
  return {
@@ -303,14 +303,14 @@ function de(r = {}) {
303
303
  "--color-gryt-on-accent": e.onAccent,
304
304
  "--color-gryt-on-secondary": e.onSecondary,
305
305
  "--color-gryt-on-danger": e.onDanger,
306
- "--gryt-radius-sm": `${s.sm}px`,
307
- "--gryt-radius-md": `${s.md}px`,
308
- "--gryt-radius-lg": `${s.lg}px`,
309
- "--gryt-radius-xl": `${s.xl}px`,
310
- "--gryt-radius-full": `${s.full}px`
306
+ "--gryt-radius-sm": `${o.sm}px`,
307
+ "--gryt-radius-md": `${o.md}px`,
308
+ "--gryt-radius-lg": `${o.lg}px`,
309
+ "--gryt-radius-xl": `${o.xl}px`,
310
+ "--gryt-radius-full": `${o.full}px`
311
311
  };
312
312
  }
313
- const S = [
313
+ const w = [
314
314
  "accent",
315
315
  "accentLight",
316
316
  "secondary",
@@ -336,27 +336,27 @@ function $(r) {
336
336
  }
337
337
  const L = {
338
338
  hue: {
339
- accent: o.color.accent,
340
- accentLight: o.color.accentLight,
341
- secondary: o.color.secondary,
342
- secondaryLight: o.color.secondaryLight,
343
- success: o.color.success,
344
- danger: o.color.danger,
345
- dangerLight: o.color.dangerLight,
346
- warning: o.color.warning,
347
- onAccent: o.color.onAccent,
348
- onSecondary: o.color.onSecondary,
349
- onDanger: o.color.onDanger
339
+ accent: s.color.accent,
340
+ accentLight: s.color.accentLight,
341
+ secondary: s.color.secondary,
342
+ secondaryLight: s.color.secondaryLight,
343
+ success: s.color.success,
344
+ danger: s.color.danger,
345
+ dangerLight: s.color.dangerLight,
346
+ warning: s.color.warning,
347
+ onAccent: s.color.onAccent,
348
+ onSecondary: s.color.onSecondary,
349
+ onDanger: s.color.onDanger
350
350
  },
351
351
  lightHue: null,
352
352
  dark: {
353
- bg: o.color.bg,
354
- surface: o.color.surface,
355
- surfaceRaised: o.color.surfaceRaised,
356
- surfaceHover: o.color.surfaceHover,
357
- border: o.color.border,
358
- muted: o.color.muted,
359
- text: o.color.text
353
+ bg: s.color.bg,
354
+ surface: s.color.surface,
355
+ surfaceRaised: s.color.surfaceRaised,
356
+ surfaceHover: s.color.surfaceHover,
357
+ border: s.color.border,
358
+ muted: s.color.muted,
359
+ text: s.color.text
360
360
  },
361
361
  light: {
362
362
  bg: l.bg,
@@ -367,7 +367,7 @@ const L = {
367
367
  muted: l.muted,
368
368
  text: l.text
369
369
  },
370
- radius: { ...o.radius }
370
+ radius: { ...s.radius }
371
371
  };
372
372
  function j(r) {
373
373
  return {
@@ -418,12 +418,12 @@ function D(r) {
418
418
  return a.length === 4 ? `#${a[1]}${a[1]}${a[2]}${a[2]}${a[3]}${a[3]}` : a;
419
419
  }
420
420
  function ge(r, a) {
421
- const t = new URLSearchParams(), e = (c) => D(c).slice(1), s = $(r.name ?? "");
422
- s !== "" && t.set("name", s);
423
- for (const c of S)
421
+ const t = new URLSearchParams(), e = (c) => D(c).slice(1), o = $(r.name ?? "");
422
+ o !== "" && t.set("name", o);
423
+ for (const c of w)
424
424
  r.hue[c] !== L.hue[c] && t.set(H[c], e(r.hue[c]));
425
425
  if (r.lightHue !== null)
426
- for (const c of S)
426
+ for (const c of w)
427
427
  t.set(`lh-${H[c]}`, e(r.lightHue[c]));
428
428
  for (const c of ["dark", "light"]) {
429
429
  const n = c === "dark" ? "d" : "l";
@@ -449,15 +449,15 @@ function re(r) {
449
449
  if (n === null) return null;
450
450
  const f = n.startsWith("#") ? n : `#${n}`;
451
451
  return z(f) ? (t = !0, D(f)) : null;
452
- }, s = $(r.get("name") ?? "");
453
- s !== "" && (a.name = s, t = !0);
454
- for (const c of S) {
452
+ }, o = $(r.get("name") ?? "");
453
+ o !== "" && (a.name = o, t = !0);
454
+ for (const c of w) {
455
455
  const n = e(H[c]);
456
456
  n !== null && (a.hue[c] = n);
457
457
  }
458
458
  if (r.has(`lh-${H.accent}`)) {
459
459
  const c = { ...a.hue };
460
- for (const n of S) {
460
+ for (const n of w) {
461
461
  const f = e(`lh-${H[n]}`);
462
462
  f !== null && (c[n] = f);
463
463
  }
@@ -488,15 +488,15 @@ function ae(r) {
488
488
  }
489
489
  if (typeof a != "object" || a === null) return null;
490
490
  const t = a, e = j(L);
491
- let s = !1;
491
+ let o = !1;
492
492
  const c = (n, f) => {
493
493
  if (!(typeof n != "object" || n === null))
494
494
  for (const [d, g] of Object.entries(n))
495
- typeof g == "string" && z(g) && d in f && (f[d] = D(g), s = !0);
495
+ typeof g == "string" && z(g) && d in f && (f[d] = D(g), o = !0);
496
496
  };
497
497
  if (typeof t.name == "string") {
498
498
  const n = $(t.name);
499
- n !== "" && (e.name = n, s = !0);
499
+ n !== "" && (e.name = n, o = !0);
500
500
  }
501
501
  if (c(t.hue, e.hue), c(t.dark, e.dark), c(t.light, e.light), typeof t.lightHue == "object" && t.lightHue !== null) {
502
502
  const n = { ...e.hue };
@@ -507,11 +507,11 @@ function ae(r) {
507
507
  t.radius
508
508
  )) {
509
509
  const d = Number(f);
510
- M.includes(n) && Number.isFinite(d) && d >= 0 && d <= 999 && (e.radius[n] = Math.round(d), s = !0);
510
+ M.includes(n) && Number.isFinite(d) && d >= 0 && d <= 999 && (e.radius[n] = Math.round(d), o = !0);
511
511
  }
512
- return s ? { theme: e, appearance: "dark" } : null;
512
+ return o ? { theme: e, appearance: "dark" } : null;
513
513
  }
514
- const A = { sm: 8, md: 12, lg: 20, xl: 28, full: 999 }, v = { sm: 6, md: 8, lg: 14, xl: 18, full: 999 }, ce = { sm: 4, md: 6, lg: 10, xl: 14, full: 6 }, te = { sm: 6, md: 8, lg: 10, xl: 14, full: 10 }, P = { sm: 2, md: 4, lg: 6, xl: 8, full: 4 }, ne = [
514
+ const v = { sm: 8, md: 12, lg: 20, xl: 28, full: 999 }, A = { sm: 6, md: 8, lg: 14, xl: 18, full: 999 }, ce = { sm: 4, md: 6, lg: 10, xl: 14, full: 6 }, te = { sm: 6, md: 8, lg: 10, xl: 14, full: 10 }, P = { sm: 2, md: 4, lg: 6, xl: 8, full: 4 }, ne = [
515
515
  {
516
516
  id: "gryt",
517
517
  name: "Gryt",
@@ -559,7 +559,7 @@ const A = { sm: 8, md: 12, lg: 20, xl: 28, full: 999 }, v = { sm: 6, md: 8, lg:
559
559
  muted: "#6b5b50",
560
560
  text: "#241a14"
561
561
  },
562
- radius: A
562
+ radius: v
563
563
  }
564
564
  },
565
565
  {
@@ -601,7 +601,7 @@ const A = { sm: 8, md: 12, lg: 20, xl: 28, full: 999 }, v = { sm: 6, md: 8, lg:
601
601
  muted: "#5b5b63",
602
602
  text: "#17171a"
603
603
  },
604
- radius: v
604
+ radius: A
605
605
  }
606
606
  },
607
607
  {
@@ -702,7 +702,7 @@ const A = { sm: 8, md: 12, lg: 20, xl: 28, full: 999 }, v = { sm: 6, md: 8, lg:
702
702
  muted: "#6c664b",
703
703
  text: "#1f1f1f"
704
704
  },
705
- radius: v
705
+ radius: A
706
706
  }
707
707
  },
708
708
  {
@@ -760,7 +760,7 @@ const A = { sm: 8, md: 12, lg: 20, xl: 28, full: 999 }, v = { sm: 6, md: 8, lg:
760
760
  muted: "#4c566a",
761
761
  text: "#2e3440"
762
762
  },
763
- radius: v
763
+ radius: A
764
764
  }
765
765
  },
766
766
  {
@@ -819,7 +819,7 @@ const A = { sm: 8, md: 12, lg: 20, xl: 28, full: 999 }, v = { sm: 6, md: 8, lg:
819
819
  muted: "#6c6f85",
820
820
  text: "#4c4f69"
821
821
  },
822
- radius: A
822
+ radius: v
823
823
  }
824
824
  },
825
825
  {
@@ -927,7 +927,7 @@ const A = { sm: 8, md: 12, lg: 20, xl: 28, full: 999 }, v = { sm: 6, md: 8, lg:
927
927
  muted: "#87867f",
928
928
  text: "#141413"
929
929
  },
930
- radius: A
930
+ radius: v
931
931
  }
932
932
  },
933
933
  {
@@ -1040,13 +1040,87 @@ const A = { sm: 8, md: 12, lg: 20, xl: 28, full: 999 }, v = { sm: 6, md: 8, lg:
1040
1040
  }
1041
1041
  ], le = new Map(
1042
1042
  ne.map((r) => [r.id, r])
1043
- );
1043
+ ), he = [
1044
+ 0,
1045
+ 0.1217,
1046
+ 0.3812,
1047
+ 0.6579,
1048
+ 0.883,
1049
+ 1.0304,
1050
+ 1.1034,
1051
+ 1.12,
1052
+ 1.1025,
1053
+ 1.0705,
1054
+ 1.0376,
1055
+ 1.0115,
1056
+ 0.9949,
1057
+ 0.987,
1058
+ 0.9857,
1059
+ 0.9881,
1060
+ 0.992,
1061
+ 0.9959,
1062
+ 0.9989,
1063
+ 1.0008,
1064
+ 1.0016,
1065
+ 1.0017,
1066
+ 1.0014,
1067
+ 1.0009,
1068
+ 1.0004,
1069
+ 1.0001,
1070
+ 1
1071
+ ], be = [
1072
+ 0,
1073
+ 0.0496,
1074
+ 0.1585,
1075
+ 0.2869,
1076
+ 0.4135,
1077
+ 0.5279,
1078
+ 0.6263,
1079
+ 0.7079,
1080
+ 0.7741,
1081
+ 0.8268,
1082
+ 0.8681,
1083
+ 0.9002,
1084
+ 0.9249,
1085
+ 0.9437,
1086
+ 0.958,
1087
+ 0.9688,
1088
+ 0.9768,
1089
+ 0.9829,
1090
+ 0.9874,
1091
+ 0.9907,
1092
+ 0.9932,
1093
+ 0.995,
1094
+ 0.9963,
1095
+ 0.9973,
1096
+ 0.9981,
1097
+ 0.9986,
1098
+ 1
1099
+ ], ye = {
1100
+ /** Most interactions. */
1101
+ spring: 500,
1102
+ /** Drawer, where the travel is the width of a panel. */
1103
+ springSoft: 700,
1104
+ /** Colour changes, which should not feel sprung. */
1105
+ fast: 150
1106
+ }, me = {
1107
+ button: { hover: 1.03, press: 0.96 },
1108
+ toast: { hover: 1.04, press: 0.96 },
1109
+ sliderThumb: { hover: 1.12, press: 0.94 }
1110
+ };
1111
+ function Le(r, a) {
1112
+ if (r.length === 0) return a;
1113
+ if (a <= 0) return r[0];
1114
+ if (a >= 1) return r[r.length - 1];
1115
+ const t = (r.length - 1) * a, e = Math.floor(t), o = t - e, c = r[e], n = r[e + 1] ?? c;
1116
+ return c + (n - c) * o;
1117
+ }
1044
1118
  export {
1045
- S as GRYT_HUE_KEYS,
1119
+ w as GRYT_HUE_KEYS,
1046
1120
  O as GRYT_NEUTRAL_KEYS,
1047
1121
  M as GRYT_RADIUS_KEYS,
1048
1122
  V as GRYT_THEME_NAME_MAX,
1049
- w as alphaScale,
1123
+ R as alphaScale,
1050
1124
  j as cloneGrytTheme,
1051
1125
  oe as contrast,
1052
1126
  de as createGrytTheme,
@@ -1054,16 +1128,18 @@ export {
1054
1128
  ge as encodeGrytTheme,
1055
1129
  se as grytAlphaScales,
1056
1130
  fe as grytAlphaScalesLight,
1131
+ ye as grytDurations,
1057
1132
  l as grytLightTokens,
1058
1133
  ne as grytPresets,
1059
1134
  le as grytPresetsById,
1135
+ me as grytScaleSteps,
1060
1136
  _ as grytScales,
1061
1137
  T as grytScalesLight,
1062
1138
  L as grytTheme,
1063
1139
  Z as grytThemeHues,
1064
1140
  ue as grytThemeToOptions,
1065
- o as grytTokens,
1066
- R as hexToOklch,
1141
+ s as grytTokens,
1142
+ S as hexToOklch,
1067
1143
  x as hexToRgb,
1068
1144
  h as hueScale,
1069
1145
  b as hueScaleLight,
@@ -1073,6 +1149,9 @@ export {
1073
1149
  D as normalizeHexColor,
1074
1150
  $ as normalizeThemeName,
1075
1151
  y as oklchToHex,
1076
- N as rgbToHex
1152
+ N as rgbToHex,
1153
+ Le as sampleCurve,
1154
+ he as springSamples,
1155
+ be as springTightSamples
1077
1156
  };
1078
1157
  //# sourceMappingURL=index.js.map