@tachui/core 0.8.11 → 0.8.12

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,79 +1,75 @@
1
1
  import { A as g } from "../index-JQ1sW1SK.js";
2
- import { L as se, R as ne, k as ae } from "../index-JQ1sW1SK.js";
3
- import { J as A, K as _, k as R } from "../theme-CRLPHryV.js";
2
+ import { L as rt, R as st, k as nt } from "../index-JQ1sW1SK.js";
3
+ import { J as S, K as C, k as N } from "../theme-CRLPHryV.js";
4
4
  export * from "@tachui/types/assets";
5
- var V = Object.defineProperty, E = (n, e, t) => e in n ? V(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, x = (n, e, t) => E(n, typeof e != "symbol" ? e + "" : e, t);
6
- class i extends g {
7
- constructor(e) {
8
- if (super(e.name), x(this, "default"), x(this, "light"), x(this, "dark"), !e.default)
5
+ var G = Object.defineProperty, H = (i, t, e) => t in i ? G(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e, b = (i, t, e) => H(i, typeof t != "symbol" ? t + "" : t, e);
6
+ const E = class a extends g {
7
+ constructor(t) {
8
+ if (super(t.name), b(this, "default"), b(this, "light"), b(this, "dark"), !t.default)
9
9
  throw new Error(
10
- `ColorAsset "${e.name}" must specify a default color`
10
+ `ColorAsset "${t.name}" must specify a default color`
11
11
  );
12
- const t = i.validateColor(e.default);
13
- if (!t.isValid)
12
+ const e = a.validateColor(t.default);
13
+ if (!e.isValid)
14
14
  throw new Error(
15
- `Invalid default color format for asset "${e.name}": ${t.error}`
15
+ `Invalid default color format for asset "${t.name}": ${e.error}`
16
16
  );
17
- if (e.light) {
18
- const a = i.validateColor(e.light);
19
- if (!a.isValid)
17
+ if (t.light) {
18
+ const s = a.validateColor(t.light);
19
+ if (!s.isValid)
20
20
  throw new Error(
21
- `Invalid light color format for asset "${e.name}": ${a.error}`
21
+ `Invalid light color format for asset "${t.name}": ${s.error}`
22
22
  );
23
23
  }
24
- if (e.dark) {
25
- const a = i.validateColor(e.dark);
26
- if (!a.isValid)
24
+ if (t.dark) {
25
+ const s = a.validateColor(t.dark);
26
+ if (!s.isValid)
27
27
  throw new Error(
28
- `Invalid dark color format for asset "${e.name}": ${a.error}`
28
+ `Invalid dark color format for asset "${t.name}": ${s.error}`
29
29
  );
30
30
  }
31
- this.default = e.default, this.light = e.light, this.dark = e.dark;
31
+ this.default = t.default, this.light = t.light, this.dark = t.dark;
32
32
  }
33
- static init(e) {
34
- return new i(e);
33
+ static init(t) {
34
+ return new a(t);
35
35
  }
36
36
  /**
37
37
  * Validates a color string format
38
38
  * Supports: hex, rgb, rgba, hsl, hsla, and named colors
39
39
  */
40
- static validateColor(e) {
41
- if (!e || typeof e != "string")
40
+ static validateColor(t) {
41
+ if (!t || typeof t != "string")
42
42
  return {
43
43
  isValid: !1,
44
44
  error: "Color must be a non-empty string"
45
45
  };
46
- const t = e.trim();
47
- if (/^#([A-Fa-f0-9]{3}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/.test(t))
46
+ const e = t.trim();
47
+ if (a.HEX_REGEX.test(e))
48
48
  return { isValid: !0, format: "hex" };
49
- const s = /^rgb\s*\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)$/;
50
- if (s.test(t)) {
51
- const l = t.match(s), [, c, h, m] = l.map(Number);
52
- return c <= 255 && h <= 255 && m <= 255 ? { isValid: !0, format: "rgb" } : {
49
+ if (a.RGB_REGEX.test(e)) {
50
+ const n = e.match(a.RGB_REGEX), [, r, o, u] = n.map(Number);
51
+ return r <= 255 && o <= 255 && u <= 255 ? { isValid: !0, format: "rgb" } : {
53
52
  isValid: !1,
54
53
  error: "RGB values must be between 0 and 255"
55
54
  };
56
55
  }
57
- const r = /^rgba\s*\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]*\.?[0-9]+)\s*\)$/;
58
- if (r.test(t)) {
59
- const l = t.match(r), [, c, h, m, S] = l, p = Number(c), C = Number(h), k = Number(m), w = Number(S);
60
- return p <= 255 && C <= 255 && k <= 255 && w >= 0 && w <= 1 ? { isValid: !0, format: "rgba" } : {
56
+ if (a.RGBA_REGEX.test(e)) {
57
+ const n = e.match(a.RGBA_REGEX), [, r, o, u, l] = n, f = Number(r), c = Number(o), h = Number(u), m = Number(l);
58
+ return f <= 255 && c <= 255 && h <= 255 && m >= 0 && m <= 1 ? { isValid: !0, format: "rgba" } : {
61
59
  isValid: !1,
62
60
  error: "RGBA values must be: RGB 0-255, alpha 0-1"
63
61
  };
64
62
  }
65
- const o = /^hsl\s*\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})%\s*,\s*([0-9]{1,3})%\s*\)$/;
66
- if (o.test(t)) {
67
- const l = t.match(o), [, c, h, m] = l.map(Number);
68
- return c <= 360 && h <= 100 && m <= 100 ? { isValid: !0, format: "hsl" } : {
63
+ if (a.HSL_REGEX.test(e)) {
64
+ const n = e.match(a.HSL_REGEX), [, r, o, u] = n.map(Number);
65
+ return r <= 360 && o <= 100 && u <= 100 ? { isValid: !0, format: "hsl" } : {
69
66
  isValid: !1,
70
67
  error: "HSL values must be: H 0-360, S/L 0-100%"
71
68
  };
72
69
  }
73
- const d = /^hsla\s*\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})%\s*,\s*([0-9]{1,3})%\s*,\s*([0-9]*\.?[0-9]+)\s*\)$/;
74
- if (d.test(t)) {
75
- const l = t.match(d), [, c, h, m, S] = l, p = Number(c), C = Number(h), k = Number(m), w = Number(S);
76
- return p <= 360 && C <= 100 && k <= 100 && w >= 0 && w <= 1 ? { isValid: !0, format: "hsla" } : {
70
+ if (a.HSLA_REGEX.test(e)) {
71
+ const n = e.match(a.HSLA_REGEX), [, r, o, u, l] = n, f = Number(r), c = Number(o), h = Number(u), m = Number(l);
72
+ return f <= 360 && c <= 100 && h <= 100 && m >= 0 && m <= 1 ? { isValid: !0, format: "hsla" } : {
77
73
  isValid: !1,
78
74
  error: "HSLA values must be: H 0-360, S/L 0-100%, alpha 0-1"
79
75
  };
@@ -106,37 +102,262 @@ class i extends g {
106
102
  "silver",
107
103
  "aqua",
108
104
  "fuchsia"
109
- ].includes(t.toLowerCase()) ? { isValid: !0, format: "named" } : t.startsWith("var(--") && t.endsWith(")") ? { isValid: !0, format: "named" } : {
105
+ ].includes(e.toLowerCase()) ? { isValid: !0, format: "named" } : e.startsWith("var(--") && e.endsWith(")") ? { isValid: !0, format: "named" } : {
110
106
  isValid: !1,
111
107
  error: "Unsupported color format. Supported: hex, rgb, rgba, hsl, hsla, named colors, CSS custom properties"
112
108
  };
113
109
  }
114
110
  static getCurrentTheme() {
115
- return A();
111
+ return S();
112
+ }
113
+ opacity(t) {
114
+ if (!this.isFiniteInput(t, "opacity(alpha)"))
115
+ return this.resolve();
116
+ const e = a.clamp(t, 0, 1);
117
+ return a.applyAlpha(this.resolve(), e);
118
+ }
119
+ saturate(t) {
120
+ if (!this.isFiniteInput(t, "saturate(amount)"))
121
+ return this.resolve();
122
+ const e = a.clamp(t, -1, 1);
123
+ return a.applySaturation(this.resolve(), e);
124
+ }
125
+ brighten(t) {
126
+ if (!this.isFiniteInput(t, "brighten(amount)"))
127
+ return this.resolve();
128
+ const e = a.clamp(t, -1, 1);
129
+ return a.applyBrightness(this.resolve(), e);
130
+ }
131
+ contrast(t) {
132
+ if (!this.isFiniteInput(t, "contrast(amount)"))
133
+ return this.resolve();
134
+ const e = a.clamp(t, -1, 1);
135
+ return a.applyContrast(this.resolve(), e);
136
+ }
137
+ rotateHue(t) {
138
+ if (!this.isFiniteInput(t, "rotateHue(degrees)"))
139
+ return this.resolve();
140
+ const e = (t % 360 + 360) % 360;
141
+ return a.applyHueRotation(this.resolve(), e);
116
142
  }
117
143
  resolve() {
118
- const e = R() !== null;
119
- let t;
120
- return e ? t = _()() : t = i.getCurrentTheme(), t === "dark" ? this.dark || this.default : this.light || this.default;
144
+ const t = N() !== null;
145
+ let e;
146
+ return t ? e = C()() : e = a.getCurrentTheme(), e === "dark" ? this.dark || this.default : this.light || this.default;
121
147
  }
122
- }
123
- var N = Object.defineProperty, L = (n, e, t) => e in n ? N(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, b = (n, e, t) => L(n, typeof e != "symbol" ? e + "" : e, t);
148
+ isFiniteInput(t, e) {
149
+ if (Number.isFinite(t))
150
+ return !0;
151
+ const s = `ColorAsset.${e} requires a finite number for asset "${this.name}"`;
152
+ if (process.env.NODE_ENV === "development")
153
+ throw new Error(s);
154
+ return !1;
155
+ }
156
+ static clamp(t, e, s) {
157
+ return Math.min(s, Math.max(e, t));
158
+ }
159
+ static formatAlpha(t) {
160
+ return t === 0 || t === 1 ? String(t) : Number(t.toFixed(4)).toString();
161
+ }
162
+ static toColorMix(t, e) {
163
+ const s = Number((e * 100).toFixed(2)).toString();
164
+ return `color-mix(in srgb, ${t} ${s}%, transparent)`;
165
+ }
166
+ static applyAlpha(t, e) {
167
+ const s = t.trim(), n = a.formatAlpha(e);
168
+ if (s.match(a.HEX_REGEX)) {
169
+ const [c, h, m] = a.parseHex(s);
170
+ return `rgba(${c}, ${h}, ${m}, ${n})`;
171
+ }
172
+ const o = s.match(a.RGB_REGEX);
173
+ if (o) {
174
+ const [, c, h, m] = o.map(Number);
175
+ return `rgba(${c}, ${h}, ${m}, ${n})`;
176
+ }
177
+ const u = s.match(a.RGBA_REGEX);
178
+ if (u) {
179
+ const [, c, h, m] = u.map(Number);
180
+ return `rgba(${c}, ${h}, ${m}, ${n})`;
181
+ }
182
+ const l = s.match(a.HSL_REGEX);
183
+ if (l) {
184
+ const [, c, h, m] = l.map(Number);
185
+ return `hsla(${c}, ${h}%, ${m}%, ${n})`;
186
+ }
187
+ const f = s.match(a.HSLA_REGEX);
188
+ if (f) {
189
+ const [, c, h, m] = f.map(Number);
190
+ return `hsla(${c}, ${h}%, ${m}%, ${n})`;
191
+ }
192
+ return a.toColorMix(s, e);
193
+ }
194
+ static parseHex(t) {
195
+ const [e, s, n] = a.parseHexWithAlpha(t);
196
+ return [e, s, n];
197
+ }
198
+ static parseHexWithAlpha(t) {
199
+ const e = t.slice(1), s = e.length === 3 ? e.split("").map((l) => `${l}${l}`).join("") : e.length === 8 ? e.slice(0, 6) : e, n = e.length === 8 ? Number.parseInt(e.slice(6, 8), 16) / 255 : 1, r = Number.parseInt(s.slice(0, 2), 16), o = Number.parseInt(s.slice(2, 4), 16), u = Number.parseInt(s.slice(4, 6), 16);
200
+ return [r, o, u, n];
201
+ }
202
+ static applySaturation(t, e) {
203
+ const s = a.parseColorToHsla(t);
204
+ if (!s)
205
+ return t;
206
+ const n = e >= 0 ? s.s + (1 - s.s) * e : s.s * (1 + e), r = a.clamp(n, 0, 1), [o, u, l] = a.hslToRgb(s.h, r, s.l);
207
+ return s.a < 1 ? `rgba(${o}, ${u}, ${l}, ${a.formatAlpha(s.a)})` : a.rgbToHex(o, u, l);
208
+ }
209
+ static applyBrightness(t, e) {
210
+ const s = a.parseColorToRgba(t);
211
+ if (!s)
212
+ return t;
213
+ const n = (l) => {
214
+ const f = e >= 0 ? l + (255 - l) * e : l * (1 + e);
215
+ return Math.round(a.clamp(f, 0, 255));
216
+ }, r = n(s.r), o = n(s.g), u = n(s.b);
217
+ return s.a < 1 ? `rgba(${r}, ${o}, ${u}, ${a.formatAlpha(s.a)})` : a.rgbToHex(r, o, u);
218
+ }
219
+ static applyContrast(t, e) {
220
+ const s = a.parseColorToRgba(t);
221
+ if (!s)
222
+ return t;
223
+ const n = 1 + e, r = (f) => {
224
+ const h = (f / 255 - 0.5) * n + 0.5;
225
+ return Math.round(a.clamp(h, 0, 1) * 255);
226
+ }, o = r(s.r), u = r(s.g), l = r(s.b);
227
+ return s.a < 1 ? `rgba(${o}, ${u}, ${l}, ${a.formatAlpha(s.a)})` : a.rgbToHex(o, u, l);
228
+ }
229
+ static applyHueRotation(t, e) {
230
+ const s = a.parseColorToHsla(t);
231
+ if (!s)
232
+ return t;
233
+ const n = (s.h + e) % 360, [r, o, u] = a.hslToRgb(n, s.s, s.l);
234
+ return s.a < 1 ? `rgba(${r}, ${o}, ${u}, ${a.formatAlpha(s.a)})` : a.rgbToHex(r, o, u);
235
+ }
236
+ static parseColorToRgba(t) {
237
+ const e = t.trim();
238
+ if (a.HEX_REGEX.test(e)) {
239
+ const [l, f, c, h] = a.parseHexWithAlpha(e);
240
+ return { r: l, g: f, b: c, a: h };
241
+ }
242
+ const s = e.match(a.RGB_REGEX);
243
+ if (s) {
244
+ const [, l, f, c] = s.map(Number);
245
+ return { r: l, g: f, b: c, a: 1 };
246
+ }
247
+ const n = e.match(a.RGBA_REGEX);
248
+ if (n) {
249
+ const [, l, f, c, h] = n;
250
+ return { r: Number(l), g: Number(f), b: Number(c), a: Number(h) };
251
+ }
252
+ const r = e.match(a.HSL_REGEX);
253
+ if (r) {
254
+ const [, l, f, c] = r.map(Number), [h, m, w] = a.hslToRgb(l, f / 100, c / 100);
255
+ return { r: h, g: m, b: w, a: 1 };
256
+ }
257
+ const o = e.match(a.HSLA_REGEX);
258
+ if (o) {
259
+ const [, l, f, c, h] = o, [m, w, x] = a.hslToRgb(
260
+ Number(l),
261
+ Number(f) / 100,
262
+ Number(c) / 100
263
+ );
264
+ return { r: m, g: w, b: x, a: Number(h) };
265
+ }
266
+ const u = a.NAMED_COLOR_RGB[e.toLowerCase()];
267
+ if (u) {
268
+ const [l, f, c, h] = u;
269
+ return { r: l, g: f, b: c, a: h };
270
+ }
271
+ return null;
272
+ }
273
+ static parseColorToHsla(t) {
274
+ const e = t.trim(), s = e.match(a.HSL_REGEX);
275
+ if (s) {
276
+ const [, f, c, h] = s.map(Number);
277
+ return { h: f, s: c / 100, l: h / 100, a: 1 };
278
+ }
279
+ const n = e.match(a.HSLA_REGEX);
280
+ if (n) {
281
+ const [, f, c, h, m] = n;
282
+ return {
283
+ h: Number(f),
284
+ s: Number(c) / 100,
285
+ l: Number(h) / 100,
286
+ a: Number(m)
287
+ };
288
+ }
289
+ const r = a.parseColorToRgba(e);
290
+ if (!r)
291
+ return null;
292
+ const [o, u, l] = a.rgbToHsl(r.r, r.g, r.b);
293
+ return { h: o, s: u, l, a: r.a };
294
+ }
295
+ static rgbToHsl(t, e, s) {
296
+ const n = t / 255, r = e / 255, o = s / 255, u = Math.max(n, r, o), l = Math.min(n, r, o), f = u - l;
297
+ let c = 0;
298
+ const h = (u + l) / 2, m = f === 0 ? 0 : f / (1 - Math.abs(2 * h - 1));
299
+ return f !== 0 && (u === n ? c = (r - o) / f % 6 : u === r ? c = (o - n) / f + 2 : c = (n - r) / f + 4, c *= 60, c < 0 && (c += 360)), [c, m, h];
300
+ }
301
+ static hslToRgb(t, e, s) {
302
+ const n = (t % 360 + 360) % 360, r = (1 - Math.abs(2 * s - 1)) * e, o = r * (1 - Math.abs(n / 60 % 2 - 1)), u = s - r / 2;
303
+ let l = 0, f = 0, c = 0;
304
+ n < 60 ? (l = r, f = o) : n < 120 ? (l = o, f = r) : n < 180 ? (f = r, c = o) : n < 240 ? (f = o, c = r) : n < 300 ? (l = o, c = r) : (l = r, c = o);
305
+ const h = Math.round((l + u) * 255), m = Math.round((f + u) * 255), w = Math.round((c + u) * 255);
306
+ return [h, m, w];
307
+ }
308
+ static rgbToHex(t, e, s) {
309
+ const n = (r) => r.toString(16).padStart(2, "0");
310
+ return `#${n(t)}${n(e)}${n(s)}`.toUpperCase();
311
+ }
312
+ };
313
+ b(E, "HEX_REGEX", /^#([A-Fa-f0-9]{3}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/);
314
+ b(E, "RGB_REGEX", /^rgb\s*\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)$/i);
315
+ b(E, "RGBA_REGEX", /^rgba\s*\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]*\.?[0-9]+)\s*\)$/i);
316
+ b(E, "HSL_REGEX", /^hsl\s*\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})%\s*,\s*([0-9]{1,3})%\s*\)$/i);
317
+ b(E, "HSLA_REGEX", /^hsla\s*\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})%\s*,\s*([0-9]{1,3})%\s*,\s*([0-9]*\.?[0-9]+)\s*\)$/i);
318
+ b(E, "NAMED_COLOR_RGB", {
319
+ transparent: [0, 0, 0, 0],
320
+ black: [0, 0, 0, 1],
321
+ white: [255, 255, 255, 1],
322
+ red: [255, 0, 0, 1],
323
+ green: [0, 128, 0, 1],
324
+ blue: [0, 0, 255, 1],
325
+ yellow: [255, 255, 0, 1],
326
+ cyan: [0, 255, 255, 1],
327
+ magenta: [255, 0, 255, 1],
328
+ gray: [128, 128, 128, 1],
329
+ grey: [128, 128, 128, 1],
330
+ orange: [255, 165, 0, 1],
331
+ purple: [128, 0, 128, 1],
332
+ pink: [255, 192, 203, 1],
333
+ brown: [165, 42, 42, 1],
334
+ navy: [0, 0, 128, 1],
335
+ teal: [0, 128, 128, 1],
336
+ lime: [0, 255, 0, 1],
337
+ olive: [128, 128, 0, 1],
338
+ maroon: [128, 0, 0, 1],
339
+ silver: [192, 192, 192, 1],
340
+ aqua: [0, 255, 255, 1],
341
+ fuchsia: [255, 0, 255, 1]
342
+ });
343
+ let d = E;
344
+ var k = Object.defineProperty, M = (i, t, e) => t in i ? k(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e, v = (i, t, e) => M(i, typeof t != "symbol" ? t + "" : t, e);
124
345
  class F extends g {
125
- constructor(e) {
126
- if (super(e.name), b(this, "default"), b(this, "light"), b(this, "dark"), b(this, "alt"), b(this, "placeholder"), !e.default)
127
- throw new Error(`ImageAsset "${e.name}" must specify a default image path`);
128
- this.default = e.default, this.light = e.light, this.dark = e.dark, this.alt = e.options?.alt, this.placeholder = e.options?.placeholder;
346
+ constructor(t) {
347
+ if (super(t.name), v(this, "default"), v(this, "light"), v(this, "dark"), v(this, "alt"), v(this, "placeholder"), !t.default)
348
+ throw new Error(`ImageAsset "${t.name}" must specify a default image path`);
349
+ this.default = t.default, this.light = t.light, this.dark = t.dark, this.alt = t.options?.alt, this.placeholder = t.options?.placeholder;
129
350
  }
130
- static init(e) {
131
- return new F(e);
351
+ static init(t) {
352
+ return new F(t);
132
353
  }
133
354
  static getCurrentTheme() {
134
- return A();
355
+ return S();
135
356
  }
136
357
  resolve() {
137
- const e = R() !== null;
138
- let t;
139
- return e ? t = _()() : t = F.getCurrentTheme(), t === "dark" ? this.dark || this.default : this.light || this.default;
358
+ const t = N() !== null;
359
+ let e;
360
+ return t ? e = C()() : e = F.getCurrentTheme(), e === "dark" ? this.dark || this.default : this.light || this.default;
140
361
  }
141
362
  // Additional accessors
142
363
  get src() {
@@ -152,27 +373,27 @@ class F extends g {
152
373
  return this.default;
153
374
  }
154
375
  }
155
- var G = Object.defineProperty, T = (n, e, t) => e in n ? G(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, v = (n, e, t) => T(n, typeof e != "symbol" ? e + "" : e, t);
156
- class f extends g {
157
- constructor(e, t = [], a = "", s = {}) {
158
- super(a || e), v(this, "family"), v(this, "fallbacks"), v(this, "options"), v(this, "loaded", !1), v(this, "loadPromise", null), this.family = e, this.fallbacks = t, this.options = {
376
+ var P = Object.defineProperty, L = (i, t, e) => t in i ? P(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e, A = (i, t, e) => L(i, typeof t != "symbol" ? t + "" : t, e);
377
+ class y extends g {
378
+ constructor(t, e = [], s = "", n = {}) {
379
+ super(s || t), A(this, "family"), A(this, "fallbacks"), A(this, "options"), A(this, "loaded", !1), A(this, "loadPromise", null), this.family = t, this.fallbacks = e, this.options = {
159
380
  loading: "lazy",
160
381
  fontDisplay: "swap",
161
382
  preconnect: !0,
162
- ...s
383
+ ...n
163
384
  }, this.options.loading === "eager" && this.load();
164
385
  }
165
386
  /**
166
387
  * Static factory method for SwiftUI-style initialization
167
388
  */
168
- static init(e, t = [], a, s = {}) {
169
- return new f(e, t, a, s);
389
+ static init(t, e = [], s, n = {}) {
390
+ return new y(t, e, s, n);
170
391
  }
171
392
  /**
172
393
  * Get the full font-family CSS value including fallbacks
173
394
  */
174
395
  get value() {
175
- return [this.family, ...this.fallbacks].map((t) => t.includes(" ") ? `"${t}"` : t).join(", ");
396
+ return [this.family, ...this.fallbacks].map((e) => e.includes(" ") ? `"${e}"` : e).join(", ");
176
397
  }
177
398
  /**
178
399
  * Load the font if not already loaded
@@ -188,22 +409,22 @@ class f extends g {
188
409
  * Internal font loading implementation
189
410
  */
190
411
  async loadFont() {
191
- const { fontUrl: e, preconnect: t } = this.options;
192
- if (e) {
193
- if (t && typeof document < "u" && document.querySelector)
412
+ const { fontUrl: t, preconnect: e } = this.options;
413
+ if (t) {
414
+ if (e && typeof document < "u" && document.querySelector)
194
415
  try {
195
- const s = new URL(e).origin;
196
- if (!document.querySelector(`link[rel="preconnect"][href="${s}"]`)) {
416
+ const n = new URL(t).origin;
417
+ if (!document.querySelector(`link[rel="preconnect"][href="${n}"]`)) {
197
418
  const r = document.createElement("link");
198
- r.rel = "preconnect", r.href = s, r.crossOrigin = "anonymous", document.head.appendChild(r);
419
+ r.rel = "preconnect", r.href = n, r.crossOrigin = "anonymous", document.head.appendChild(r);
199
420
  }
200
421
  } catch {
201
422
  }
202
- if (e.endsWith(".css") || e.includes("fonts.googleapis.com") ? await this.loadFontCSS(e) : await this.loadFontFile(e), "fonts" in document)
423
+ if (t.endsWith(".css") || t.includes("fonts.googleapis.com") ? await this.loadFontCSS(t) : await this.loadFontFile(t), "fonts" in document)
203
424
  try {
204
425
  await document.fonts.ready;
205
- const s = `16px ${this.family.includes(" ") ? `"${this.family}"` : this.family}`;
206
- document.fonts.check(s) || console.warn(`⚠️ Font "${this.family}" may not have loaded correctly`);
426
+ const n = `16px ${this.family.includes(" ") ? `"${this.family}"` : this.family}`;
427
+ document.fonts.check(n) || console.warn(`⚠️ Font "${this.family}" may not have loaded correctly`);
207
428
  } catch {
208
429
  }
209
430
  }
@@ -211,53 +432,53 @@ class f extends g {
211
432
  /**
212
433
  * Load a CSS file containing @font-face rules
213
434
  */
214
- async loadFontCSS(e) {
215
- return new Promise((t, a) => {
216
- if (document.querySelector(`link[href="${e}"]`)) {
217
- t();
435
+ async loadFontCSS(t) {
436
+ return new Promise((e, s) => {
437
+ if (document.querySelector(`link[href="${t}"]`)) {
438
+ e();
218
439
  return;
219
440
  }
220
441
  const r = document.createElement("link");
221
- r.rel = "stylesheet", r.href = e, r.onload = () => {
222
- t();
442
+ r.rel = "stylesheet", r.href = t, r.onload = () => {
443
+ e();
223
444
  }, r.onerror = (o) => {
224
- console.warn(`⚠️ Failed to load font CSS for ${this.family}:`, e), t();
445
+ console.warn(`⚠️ Failed to load font CSS for ${this.family}:`, t), e();
225
446
  }, document.head.appendChild(r);
226
447
  });
227
448
  }
228
449
  /**
229
450
  * Load a font file directly and create @font-face rule
230
451
  */
231
- async loadFontFile(e) {
232
- const { fontFormat: t, fontDisplay: a, weightRange: s, widthRange: r } = this.options;
452
+ async loadFontFile(t) {
453
+ const { fontFormat: e, fontDisplay: s, weightRange: n, widthRange: r } = this.options;
233
454
  let o = "";
234
- t ? o = `format('${t}')` : e.endsWith(".woff2") ? o = "format('woff2')" : e.endsWith(".woff") ? o = "format('woff')" : e.endsWith(".ttf") && (o = "format('truetype')");
235
- let d = `
455
+ e ? o = `format('${e}')` : t.endsWith(".woff2") ? o = "format('woff2')" : t.endsWith(".woff") ? o = "format('woff')" : t.endsWith(".ttf") && (o = "format('truetype')");
456
+ let u = `
236
457
  @font-face {
237
458
  font-family: "${this.family}";
238
- src: url("${e}") ${o};
239
- font-display: ${a || "swap"};
459
+ src: url("${t}") ${o};
460
+ font-display: ${s || "swap"};
240
461
  `;
241
- s && (d += `font-weight: ${s[0]} ${s[1]};
242
- `), r && (d += `font-stretch: ${r[0]}% ${r[1]}%;
243
- `), d += "}";
244
- const $ = document.createElement("style");
245
- if ($.textContent = d, document.head.appendChild($), "FontFace" in window)
462
+ n && (u += `font-weight: ${n[0]} ${n[1]};
463
+ `), r && (u += `font-stretch: ${r[0]}% ${r[1]}%;
464
+ `), u += "}";
465
+ const l = document.createElement("style");
466
+ if (l.textContent = u, document.head.appendChild(l), "FontFace" in window)
246
467
  try {
247
- const l = new FontFace(this.family, `url(${e})`, {
248
- display: a || "swap",
249
- weight: s ? `${s[0]} ${s[1]}` : void 0,
468
+ const f = new FontFace(this.family, `url(${t})`, {
469
+ display: s || "swap",
470
+ weight: n ? `${n[0]} ${n[1]}` : void 0,
250
471
  stretch: r ? `${r[0]}% ${r[1]}%` : void 0
251
472
  });
252
- await l.load(), document.fonts.add(l);
473
+ await f.load(), document.fonts.add(f);
253
474
  } catch {
254
475
  }
255
476
  }
256
477
  /**
257
478
  * Create a CSS variable for this font
258
479
  */
259
- toCSSVariable(e) {
260
- return `${e || `--font-${this.name.toLowerCase().replace(/\s+/g, "-")}`}: ${this.value};`;
480
+ toCSSVariable(t) {
481
+ return `${t || `--font-${this.name.toLowerCase().replace(/\s+/g, "-")}`}: ${this.value};`;
261
482
  }
262
483
  /**
263
484
  * Get debug information
@@ -272,7 +493,7 @@ class f extends g {
272
493
  return this.options.loading === "lazy" && !this.loaded && this.options.fontUrl && this.load(), this.value;
273
494
  }
274
495
  }
275
- const H = {
496
+ const D = {
276
497
  ultraLight: 100,
277
498
  thin: 200,
278
499
  light: 300,
@@ -282,7 +503,7 @@ const H = {
282
503
  bold: 700,
283
504
  heavy: 800,
284
505
  black: 900
285
- }, z = {
506
+ }, q = {
286
507
  ultraCondensed: 50,
287
508
  extraCondensed: 62.5,
288
509
  condensed: 75,
@@ -292,49 +513,49 @@ const H = {
292
513
  expanded: 125,
293
514
  extraExpanded: 150,
294
515
  ultraExpanded: 200
295
- }, P = {
516
+ }, R = {
296
517
  sansSerif: ["system-ui", "-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica Neue", "Arial", "sans-serif"],
297
518
  serif: ["Georgia", "Cambria", "Times New Roman", "Times", "serif"],
298
519
  monospace: ["ui-monospace", "SFMono-Regular", "SF Mono", "Consolas", "Liberation Mono", "Menlo", "Courier", "monospace"],
299
520
  cursive: ["cursive"],
300
521
  fantasy: ["fantasy"]
301
522
  };
302
- function j(n = "sansSerif", e) {
303
- return new f("", [...P[n]], e || `system-${n}`);
523
+ function z(i = "sansSerif", t) {
524
+ return new y("", [...R[i]], t || `system-${i}`);
304
525
  }
305
- function K(n, e = [400], t, a = {}) {
306
- const s = e.join(";"), o = `https://fonts.googleapis.com/css2?family=${n.replace(/\s+/g, "+")}:wght@${s}&display=swap`;
307
- return new f(
308
- n,
309
- [...P.sansSerif],
310
- t || n.toLowerCase().replace(/\s+/g, "-"),
526
+ function U(i, t = [400], e, s = {}) {
527
+ const n = t.join(";"), o = `https://fonts.googleapis.com/css2?family=${i.replace(/\s+/g, "+")}:wght@${n}&display=swap`;
528
+ return new y(
529
+ i,
530
+ [...R.sansSerif],
531
+ e || i.toLowerCase().replace(/\s+/g, "-"),
311
532
  {
312
- ...a,
533
+ ...s,
313
534
  fontUrl: o,
314
535
  preconnect: !0
315
536
  }
316
537
  );
317
538
  }
318
- function O(n, e, t, a = [...P.sansSerif], s) {
539
+ function j(i, t, e, s = [...R.sansSerif], n) {
319
540
  const r = {};
320
- return t.slant && (r.slnt = t.slant), t.optical && (r.opsz = t.optical), t.custom && Object.assign(r, t.custom), new f(n, a, s, {
321
- fontUrl: e,
322
- weightRange: t.weight,
323
- widthRange: t.width,
541
+ return e.slant && (r.slnt = e.slant), e.optical && (r.opsz = e.optical), e.custom && Object.assign(r, e.custom), new y(i, s, n, {
542
+ fontUrl: t,
543
+ weightRange: e.weight,
544
+ widthRange: e.width,
324
545
  variableAxes: r,
325
546
  fontDisplay: "swap"
326
547
  });
327
548
  }
328
- var W = Object.defineProperty, B = (n, e, t) => e in n ? W(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, I = (n, e, t) => B(n, e + "", t);
329
- class D {
549
+ var X = Object.defineProperty, T = (i, t, e) => t in i ? X(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e, V = (i, t, e) => T(i, t + "", e);
550
+ class B {
330
551
  constructor() {
331
- I(this, "assets", /* @__PURE__ */ new Map());
552
+ V(this, "assets", /* @__PURE__ */ new Map());
332
553
  }
333
- add(e, t) {
334
- this.assets.set(e, t);
554
+ add(t, e) {
555
+ this.assets.set(t, e);
335
556
  }
336
- get(e) {
337
- return this.assets.get(e);
557
+ get(t) {
558
+ return this.assets.get(t);
338
559
  }
339
560
  getAll() {
340
561
  return new Map(this.assets);
@@ -344,143 +565,161 @@ class D {
344
565
  return new Proxy(
345
566
  {},
346
567
  {
347
- get: (e, t) => {
348
- if (t === "toString" || t === "valueOf")
568
+ get: (t, e) => {
569
+ if (e === "toString" || e === "valueOf")
349
570
  return () => "[Assets]";
350
- const a = this.assets.get(t);
351
- if (a)
352
- return a instanceof i ? new Proxy(a, {
353
- get: (s, r) => r === "light" || r === "dark" ? s[r] : r === "resolve" ? () => s.resolve() : r === "toString" || r === "valueOf" ? () => s.resolve() : s[r],
354
- has: (s, r) => r === "resolve" ? !0 : r in s
355
- }) : a instanceof F ? new Proxy(a, {
356
- get: (s, r) => r === "lightSrc" || r === "darkSrc" || r === "src" || r === "defaultSrc" ? s[r] : r === "resolve" ? () => s.resolve() : r === "toString" || r === "valueOf" ? () => s.resolve() : s[r],
357
- has: (s, r) => r === "resolve" ? !0 : r in s
358
- }) : a instanceof f ? new Proxy(a, {
359
- get: (s, r) => r === "family" || r === "fallbacks" || r === "options" ? s[r] : r === "resolve" ? () => s.resolve() : r === "toString" || r === "valueOf" ? () => s.resolve() : s[r],
360
- has: (s, r) => r === "resolve" ? !0 : r in s
361
- }) : a;
571
+ const s = this.assets.get(e);
572
+ if (s)
573
+ return s instanceof d ? new Proxy(s, {
574
+ get: (n, r) => r === "light" || r === "dark" ? n[r] : r === "resolve" ? () => n.resolve() : r === "toString" || r === "valueOf" ? () => n.resolve() : n[r],
575
+ has: (n, r) => r === "resolve" ? !0 : r in n
576
+ }) : s instanceof F ? new Proxy(s, {
577
+ get: (n, r) => r === "lightSrc" || r === "darkSrc" || r === "src" || r === "defaultSrc" ? n[r] : r === "resolve" ? () => n.resolve() : r === "toString" || r === "valueOf" ? () => n.resolve() : n[r],
578
+ has: (n, r) => r === "resolve" ? !0 : r in n
579
+ }) : s instanceof y ? new Proxy(s, {
580
+ get: (n, r) => r === "family" || r === "fallbacks" || r === "options" ? n[r] : r === "resolve" ? () => n.resolve() : r === "toString" || r === "valueOf" ? () => n.resolve() : n[r],
581
+ has: (n, r) => r === "resolve" ? !0 : r in n
582
+ }) : s;
362
583
  },
363
584
  // Add ownKeys handler to support Object.keys() enumeration
364
- ownKeys: (e) => Array.from(this.assets.keys()),
585
+ ownKeys: (t) => Array.from(this.assets.keys()),
365
586
  // Add has handler to support 'in' operator
366
- has: (e, t) => this.assets.has(t)
587
+ has: (t, e) => this.assets.has(e)
367
588
  }
368
589
  );
369
590
  }
370
591
  }
371
- const y = new D(), q = y.asProxy(), J = q;
372
- function u(n, e) {
373
- if (typeof n == "string" && e instanceof g)
374
- y.add(n, e);
375
- else if (n instanceof g && typeof e == "string")
376
- y.add(e, n);
377
- else if (n instanceof g && e === void 0)
378
- y.add(n.name, n);
379
- else
380
- throw new Error("registerAsset requires either (name, asset), (asset), or (asset, overrideName)");
592
+ const $ = new B(), I = $.asProxy(), K = I;
593
+ function p(...i) {
594
+ if (i.length === 0)
595
+ throw new Error("registerAsset requires at least one argument");
596
+ const t = i[0], e = i[1];
597
+ if (typeof t == "string" && e instanceof g && i.length === 2)
598
+ $.add(t, e);
599
+ else if (t instanceof g && typeof e == "string" && i.length === 2)
600
+ $.add(e, t);
601
+ else if (t instanceof g && i.length === 1)
602
+ $.add(t.name, t);
603
+ else if (t instanceof g && e === void 0 && i.length === 2)
604
+ $.add(t.name, t);
605
+ else if (t instanceof g && i.length > 1) {
606
+ const s = [];
607
+ i.forEach((n, r) => {
608
+ if (!(n instanceof g))
609
+ throw new Error(
610
+ `registerAsset variadic argument at index ${r} must be an Asset`
611
+ );
612
+ s.push(n);
613
+ }), s.forEach((n) => {
614
+ $.add(n.name, n);
615
+ });
616
+ } else
617
+ throw new Error(
618
+ "registerAsset requires either (name, asset), (asset), (asset, overrideName), or (...assets)"
619
+ );
381
620
  }
382
- function Q(n, e, t = "") {
383
- return i.init({
384
- default: n,
385
- light: n,
386
- dark: e,
387
- name: t
621
+ function J(i, t, e = "") {
622
+ return d.init({
623
+ default: i,
624
+ light: i,
625
+ dark: t,
626
+ name: e
388
627
  });
389
628
  }
390
- function X(n, e, t, a = "", s) {
629
+ function Q(i, t, e, s = "", n) {
391
630
  return F.init({
392
- default: n,
393
- light: e,
394
- dark: t,
395
- name: a,
396
- options: s
631
+ default: i,
632
+ light: t,
633
+ dark: e,
634
+ name: s,
635
+ options: n
397
636
  });
398
637
  }
399
- function Y(n, e = [], t = "", a) {
400
- return f.init(n, e, t, a);
638
+ function Y(i, t = [], e = "", s) {
639
+ return y.init(i, t, e, s);
401
640
  }
402
641
  function Z() {
403
- const n = y.getAll(), e = [];
404
- for (const [t, a] of n) {
405
- let s = "custom";
406
- a instanceof i ? s = "color" : a instanceof F ? s = "image" : a instanceof f && (s = "font"), e.push({
407
- name: t,
408
- type: s,
409
- asset: a
642
+ const i = $.getAll(), t = [];
643
+ for (const [e, s] of i) {
644
+ let n = "custom";
645
+ s instanceof d ? n = "color" : s instanceof F ? n = "image" : s instanceof y && (n = "font"), t.push({
646
+ name: e,
647
+ type: n,
648
+ asset: s
410
649
  });
411
650
  }
412
- return e.sort((t, a) => t.name.localeCompare(a.name));
651
+ return t.sort((e, s) => e.name.localeCompare(s.name));
413
652
  }
414
- function ee() {
415
- return Array.from(y.getAll().keys()).sort();
653
+ function _() {
654
+ return Array.from($.getAll().keys()).sort();
416
655
  }
417
- u(i.init({
656
+ p(d.init({
418
657
  default: "#007AFF",
419
658
  light: "#007AFF",
420
659
  dark: "#0A84FF",
421
660
  name: "systemBlue"
422
661
  }));
423
- u(i.init({
662
+ p(d.init({
424
663
  default: "#34C759",
425
664
  light: "#34C759",
426
665
  dark: "#30D158",
427
666
  name: "systemGreen"
428
667
  }));
429
- u(i.init({
668
+ p(d.init({
430
669
  default: "#FF3B30",
431
670
  light: "#FF3B30",
432
671
  dark: "#FF453A",
433
672
  name: "systemRed"
434
673
  }));
435
- u(i.init({
674
+ p(d.init({
436
675
  default: "#FF9500",
437
676
  light: "#FF9500",
438
677
  dark: "#FF9F0A",
439
678
  name: "systemOrange"
440
679
  }));
441
- u(i.init({
680
+ p(d.init({
442
681
  default: "#5856D6",
443
682
  light: "#5856D6",
444
683
  dark: "#5E5CE6",
445
684
  name: "systemPurple"
446
685
  }));
447
- u(i.init({
686
+ p(d.init({
448
687
  default: "#FF2D55",
449
688
  light: "#FF2D55",
450
689
  dark: "#FF375F",
451
690
  name: "systemPink"
452
691
  }));
453
- u(i.init({
692
+ p(d.init({
454
693
  default: "#8E8E93",
455
694
  name: "systemGray"
456
695
  }));
457
- u(i.init({
696
+ p(d.init({
458
697
  default: "#000000",
459
698
  name: "systemBlack"
460
699
  }));
461
- u(i.init({
700
+ p(d.init({
462
701
  default: "#FFFFFF",
463
702
  name: "systemWhite"
464
703
  }));
465
704
  export {
466
705
  g as Asset,
467
- J as Assets,
468
- i as ColorAsset,
469
- f as FontAsset,
470
- H as FontWeight,
471
- z as FontWidth,
706
+ K as Assets,
707
+ d as ColorAsset,
708
+ y as FontAsset,
709
+ D as FontWeight,
710
+ q as FontWidth,
472
711
  F as ImageAsset,
473
- se as LinearGradient,
474
- ne as RadialGradient,
475
- ae as StateGradient,
476
- P as SystemFonts,
477
- Q as createColorAsset,
712
+ rt as LinearGradient,
713
+ st as RadialGradient,
714
+ nt as StateGradient,
715
+ R as SystemFonts,
716
+ J as createColorAsset,
478
717
  Y as createFontAsset,
479
- K as createGoogleFont,
480
- X as createImageAsset,
481
- j as createSystemFont,
482
- O as createVariableFont,
718
+ U as createGoogleFont,
719
+ Q as createImageAsset,
720
+ z as createSystemFont,
721
+ j as createVariableFont,
483
722
  Z as getAssetInfo,
484
- ee as listAssetNames,
485
- u as registerAsset
723
+ _ as listAssetNames,
724
+ p as registerAsset
486
725
  };