@fluid-app/portal-sdk 0.1.199 → 0.1.201

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 (81) hide show
  1. package/dist/{ContactsScreen-DvohvoOE.cjs → ContactsScreen-BQ6pvYOa.cjs} +291 -281
  2. package/dist/ContactsScreen-BQ6pvYOa.cjs.map +1 -0
  3. package/dist/{ContactsScreen-Cheiwaxn.cjs → ContactsScreen-Bw2GcYtk.cjs} +2 -2
  4. package/dist/{ContactsScreen-BtBNMZzG.mjs → ContactsScreen-BzRFTCBS.mjs} +17 -7
  5. package/dist/ContactsScreen-BzRFTCBS.mjs.map +1 -0
  6. package/dist/{FluidProvider-D177ez3m.cjs → FluidProvider-BRkRo8Wl.cjs} +12 -992
  7. package/dist/FluidProvider-BRkRo8Wl.cjs.map +1 -0
  8. package/dist/{FluidProvider-DiJy4Zve.mjs → FluidProvider-BTZAiT69.mjs} +9 -820
  9. package/dist/FluidProvider-BTZAiT69.mjs.map +1 -0
  10. package/dist/{MessagingScreen-Cu3tcpPs.mjs → MessagingScreen-Bk3Eh1dN.mjs} +2 -2
  11. package/dist/{MessagingScreen-Cu3tcpPs.mjs.map → MessagingScreen-Bk3Eh1dN.mjs.map} +1 -1
  12. package/dist/{MessagingScreen-Ysi48svi.cjs → MessagingScreen-DN2eQRxF.cjs} +6 -6
  13. package/dist/{MessagingScreen-gKidMcrr.cjs → MessagingScreen-DtDbS3VZ.cjs} +2 -2
  14. package/dist/{MessagingScreen-gKidMcrr.cjs.map → MessagingScreen-DtDbS3VZ.cjs.map} +1 -1
  15. package/dist/{PortalContentApiProvider-CPnqELEX.cjs → PortalContentApiProvider-BDbrZCyI.cjs} +115 -89
  16. package/dist/PortalContentApiProvider-BDbrZCyI.cjs.map +1 -0
  17. package/dist/{PortalContentApiProvider-CWRAw9kL.mjs → PortalContentApiProvider-CzLqEN5C.mjs} +116 -90
  18. package/dist/PortalContentApiProvider-CzLqEN5C.mjs.map +1 -0
  19. package/dist/{ProductsScreen-CQ5-A8AL.cjs → ProductsScreen-68jB202M.cjs} +2 -2
  20. package/dist/{ProductsScreen-CQ5-A8AL.cjs.map → ProductsScreen-68jB202M.cjs.map} +1 -1
  21. package/dist/{ProductsScreen-CexZ0gx9.mjs → ProductsScreen-BeNUsjh1.mjs} +2 -2
  22. package/dist/{ProductsScreen-Al6H4ujs.mjs → ProductsScreen-BidL3ZF5.mjs} +2 -2
  23. package/dist/{ProductsScreen-Al6H4ujs.mjs.map → ProductsScreen-BidL3ZF5.mjs.map} +1 -1
  24. package/dist/{ProductsScreen-BnwMOZ4-.cjs → ProductsScreen-Bq0f4pQL.cjs} +2 -2
  25. package/dist/{ProfileScreen-CGS7YkcT.cjs → ProfileScreen-BMNq0NEB.cjs} +6 -6
  26. package/dist/{ProfileScreen-hE1S_99P.mjs → ProfileScreen-D-pTegtY.mjs} +3 -3
  27. package/dist/{ProfileScreen-hE1S_99P.mjs.map → ProfileScreen-D-pTegtY.mjs.map} +1 -1
  28. package/dist/{ProfileScreen-DJZoMzE6.cjs → ProfileScreen-D5OxmzhM.cjs} +101 -101
  29. package/dist/{ProfileScreen-DJZoMzE6.cjs.map → ProfileScreen-D5OxmzhM.cjs.map} +1 -1
  30. package/dist/{QuickShareWidget-0GD4KWAr.cjs → QuickShareWidget-C_p3tPs5.cjs} +2 -2
  31. package/dist/QuickShareWidget-C_p3tPs5.cjs.map +1 -0
  32. package/dist/{QuickShareWidget-DZzrQjOx.mjs → QuickShareWidget-xKcV3ZQ5.mjs} +2 -2
  33. package/dist/QuickShareWidget-xKcV3ZQ5.mjs.map +1 -0
  34. package/dist/{ShareablesScreen-CzTU7e0l.mjs → ShareablesScreen-BRfgOnpL.mjs} +2 -2
  35. package/dist/{ShareablesScreen-CzTU7e0l.mjs.map → ShareablesScreen-BRfgOnpL.mjs.map} +1 -1
  36. package/dist/{ShareablesScreen-DujtMoAi.cjs → ShareablesScreen-BYP65ZnU.cjs} +2 -2
  37. package/dist/{ShareablesScreen-CmZ5CX99.cjs → ShareablesScreen-CCqADUXE.cjs} +2 -2
  38. package/dist/{ShareablesScreen-CmZ5CX99.cjs.map → ShareablesScreen-CCqADUXE.cjs.map} +1 -1
  39. package/dist/{ShareablesScreen-yscAsNpq.mjs → ShareablesScreen-YnNF0dD6.mjs} +2 -2
  40. package/dist/{ShopScreen-Bdo59te-.mjs → ShopScreen-BOJGcSyG.mjs} +3 -3
  41. package/dist/{ShopScreen-Bdo59te-.mjs.map → ShopScreen-BOJGcSyG.mjs.map} +1 -1
  42. package/dist/{ShopScreen-R9zk7d5d.cjs → ShopScreen-BzyBZ24D.cjs} +6 -6
  43. package/dist/{ShopScreen-DKlDKNom.cjs → ShopScreen-DeLp93hN.cjs} +3 -3
  44. package/dist/{ShopScreen-DKlDKNom.cjs.map → ShopScreen-DeLp93hN.cjs.map} +1 -1
  45. package/dist/{SpacerWidget-Da_sNa_X.mjs → SpacerWidget-BJFO-Xyh.mjs} +2 -2
  46. package/dist/SpacerWidget-BJFO-Xyh.mjs.map +1 -0
  47. package/dist/{SpacerWidget-CLFbkgoz.cjs → SpacerWidget-D9lOLPr5.cjs} +2 -2
  48. package/dist/SpacerWidget-D9lOLPr5.cjs.map +1 -0
  49. package/dist/{TableWidget-lKjTu7Go.cjs → TableWidget-C7qiWZc3.cjs} +1 -1
  50. package/dist/{TableWidget-B65hwjKS.mjs → TableWidget-DRByd9ig.mjs} +9 -9
  51. package/dist/TableWidget-DRByd9ig.mjs.map +1 -0
  52. package/dist/{TableWidget-FDbnEYZb.cjs → TableWidget-DUnz9hrD.cjs} +9 -9
  53. package/dist/TableWidget-DUnz9hrD.cjs.map +1 -0
  54. package/dist/index.cjs +68 -70
  55. package/dist/index.cjs.map +1 -1
  56. package/dist/index.d.cts +126 -133
  57. package/dist/index.d.cts.map +1 -1
  58. package/dist/index.d.mts +126 -133
  59. package/dist/index.d.mts.map +1 -1
  60. package/dist/index.mjs +25 -25
  61. package/dist/src-BNcNh8fM.cjs +963 -0
  62. package/dist/src-BNcNh8fM.cjs.map +1 -0
  63. package/dist/src-BjCPR0aG.mjs +788 -0
  64. package/dist/src-BjCPR0aG.mjs.map +1 -0
  65. package/package.json +16 -16
  66. package/dist/ContactsScreen-BtBNMZzG.mjs.map +0 -1
  67. package/dist/ContactsScreen-DvohvoOE.cjs.map +0 -1
  68. package/dist/FluidProvider-D177ez3m.cjs.map +0 -1
  69. package/dist/FluidProvider-DiJy4Zve.mjs.map +0 -1
  70. package/dist/PortalContentApiProvider-CPnqELEX.cjs.map +0 -1
  71. package/dist/PortalContentApiProvider-CWRAw9kL.mjs.map +0 -1
  72. package/dist/QuickShareWidget-0GD4KWAr.cjs.map +0 -1
  73. package/dist/QuickShareWidget-DZzrQjOx.mjs.map +0 -1
  74. package/dist/SpacerWidget-CLFbkgoz.cjs.map +0 -1
  75. package/dist/SpacerWidget-Da_sNa_X.mjs.map +0 -1
  76. package/dist/TableWidget-B65hwjKS.mjs.map +0 -1
  77. package/dist/TableWidget-FDbnEYZb.cjs.map +0 -1
  78. package/dist/countries-api-context-Dob_AzPO.mjs +0 -13
  79. package/dist/countries-api-context-Dob_AzPO.mjs.map +0 -1
  80. package/dist/countries-api-context-G-NW4BoH.cjs +0 -25
  81. package/dist/countries-api-context-G-NW4BoH.cjs.map +0 -1
@@ -0,0 +1,963 @@
1
+ const require_chunk = require("./chunk-9hOWP6kD.cjs");
2
+ let react = require("react");
3
+ let colorjs_io = require("colorjs.io");
4
+ colorjs_io = require_chunk.__toESM(colorjs_io);
5
+ //#region ../../store/core/src/countries-api-context.ts
6
+ const CountriesApiContext = (0, react.createContext)(null);
7
+ const CountriesApiProvider = CountriesApiContext.Provider;
8
+ function useCountriesApi() {
9
+ const api = (0, react.useContext)(CountriesApiContext);
10
+ if (!api) throw new Error("useCountriesApi must be used within a CountriesApiProvider");
11
+ return api;
12
+ }
13
+ //#endregion
14
+ //#region ../../platform/theme-engine/src/types.ts
15
+ const SEMANTIC_COLOR_NAMES = [
16
+ "background",
17
+ "foreground",
18
+ "primary",
19
+ "secondary",
20
+ "accent",
21
+ "muted",
22
+ "destructive"
23
+ ];
24
+ const FONT_SIZE_KEYS = [
25
+ "extraSmall",
26
+ "small",
27
+ "regular",
28
+ "large",
29
+ "extraLarge",
30
+ "giant"
31
+ ];
32
+ const FONT_FAMILY_KEYS = ["header", "body"];
33
+ const RADIUS_KEYS = [
34
+ "small",
35
+ "medium",
36
+ "large",
37
+ "extraLarge"
38
+ ];
39
+ //#endregion
40
+ //#region ../../platform/theme-engine/src/color-engine.ts
41
+ const BARE_HEX_RE = /^[0-9a-fA-F]{6}$/;
42
+ /**
43
+ * Attempt to convert any string into a Color using colorjs.io.
44
+ * If the string is exactly 6 hex digits it is assumed to be a bare hex value
45
+ * (e.g. "3b82f6") and a "#" prefix is added before parsing. Six-letter
46
+ * named colours like "orange" or "maroon" are left untouched.
47
+ *
48
+ * @returns the parsed Color, or a neutral gray (`oklch(0.5 0 0)`) on failure
49
+ */
50
+ function parseColor(value) {
51
+ if (BARE_HEX_RE.test(value)) value = `#${value}`;
52
+ try {
53
+ return new colorjs_io.default(value);
54
+ } catch (error) {
55
+ console.warn("[theme] Failed to parse color:", value, error);
56
+ return new colorjs_io.default("oklch", [
57
+ .5,
58
+ 0,
59
+ 0
60
+ ]);
61
+ }
62
+ }
63
+ /**
64
+ * Returns either the original foreground or a corrected lightness variant,
65
+ * whichever provides better contrast against `color`.
66
+ * Inversion triggers when the |APCA contrast| is below 50 — APCA is signed
67
+ * (negative for dark-on-light, positive for light-on-dark), so comparing the
68
+ * absolute value avoids flipping dark text that already contrasts well on a
69
+ * medium background.
70
+ */
71
+ function getForegroundColor(foreground, color) {
72
+ if (foreground.oklch.l == null || color.oklch.l == null) return foreground;
73
+ const contrast = color.contrastAPCA(foreground);
74
+ if (Math.abs(contrast) < 50) return new colorjs_io.default("oklch", [
75
+ color.oklch.l < .7 ? .95 : .15,
76
+ foreground.oklch.c || 0,
77
+ foreground.oklch.h || 0
78
+ ]);
79
+ return foreground;
80
+ }
81
+ /**
82
+ * Convenience helper: given a background color string, return a CSS color
83
+ * string for text overlaid on it. Uses APCA contrast to pick between
84
+ * near-black and near-white. Returns `null` when the background cannot be
85
+ * parsed (e.g. a CSS custom property reference like `var(--color-muted)` or
86
+ * a malformed value), so callers can fall back to their theme foreground.
87
+ */
88
+ function getContrastingTextColor(background) {
89
+ const normalised = BARE_HEX_RE.test(background) ? `#${background}` : background;
90
+ let bg;
91
+ try {
92
+ bg = new colorjs_io.default(normalised);
93
+ } catch {
94
+ return null;
95
+ }
96
+ return getForegroundColor(new colorjs_io.default("oklch", [
97
+ .15,
98
+ 0,
99
+ 0
100
+ ]), bg).toString({ format: "oklch" });
101
+ }
102
+ const DARK_DERIVATION_CONFIG = {
103
+ background: {
104
+ baseLightness: .15,
105
+ fgLightness: .93
106
+ },
107
+ foreground: {
108
+ baseLightness: .93,
109
+ fgLightness: .15
110
+ },
111
+ muted: {
112
+ baseLightness: .22,
113
+ fgLightness: .75
114
+ },
115
+ primary: {
116
+ baseLightness: "invert",
117
+ fgLightness: .95,
118
+ chromaScale: .9
119
+ },
120
+ secondary: {
121
+ baseLightness: "invert",
122
+ fgLightness: .93,
123
+ chromaScale: .85
124
+ },
125
+ accent: {
126
+ baseLightness: "invert",
127
+ fgLightness: .95,
128
+ chromaScale: .9
129
+ },
130
+ destructive: {
131
+ baseLightness: "invert",
132
+ fgLightness: .95,
133
+ chromaScale: .95
134
+ }
135
+ };
136
+ /** Invert OKLCH lightness (1 - l), clamped to [0.35, 0.75] to avoid extremes. */
137
+ function invertLightness(l) {
138
+ const inverted = 1 - l;
139
+ return Math.max(.35, Math.min(.75, inverted));
140
+ }
141
+ /**
142
+ * Derive a dark-mode ThemeColorInput from its light-mode counterpart.
143
+ */
144
+ function deriveDarkVariant(name, light) {
145
+ const config = DARK_DERIVATION_CONFIG[name];
146
+ const chromaScale = config.chromaScale ?? 1;
147
+ const baseLightness = config.baseLightness === "invert" ? invertLightness(light.base.oklch.l ?? 0) : config.baseLightness;
148
+ const fgLightness = config.fgLightness === "invert" ? invertLightness(light.foreground.oklch.l ?? 0) : config.fgLightness;
149
+ return {
150
+ base: new colorjs_io.default("oklch", [
151
+ baseLightness,
152
+ (light.base.oklch.c || 0) * chromaScale,
153
+ light.base.oklch.h || 0
154
+ ]),
155
+ foreground: new colorjs_io.default("oklch", [
156
+ fgLightness,
157
+ (light.foreground.oklch.c || 0) * chromaScale,
158
+ light.foreground.oklch.h || 0
159
+ ])
160
+ };
161
+ }
162
+ /**
163
+ * Merge auto-derived dark colors with any user-specified overrides.
164
+ * For each semantic color, if the user has fully overridden both base and
165
+ * foreground those are used; otherwise the missing channels are derived.
166
+ */
167
+ function mergeDarkOverrides(def) {
168
+ const darkColors = {};
169
+ for (const name of SEMANTIC_COLOR_NAMES) {
170
+ const lightInput = def.light[name];
171
+ const darkOverride = def.dark[name];
172
+ if (darkOverride?.base && darkOverride?.foreground) darkColors[name] = darkOverride;
173
+ else if (darkOverride) {
174
+ const base = darkOverride.base ?? deriveDarkVariant(name, lightInput).base;
175
+ darkColors[name] = {
176
+ base,
177
+ foreground: darkOverride.foreground ?? getForegroundColor(def.light.foreground.base, base)
178
+ };
179
+ } else darkColors[name] = deriveDarkVariant(name, lightInput);
180
+ }
181
+ return darkColors;
182
+ }
183
+ function resolveColorSet(colors) {
184
+ const resolved = {};
185
+ for (const name of SEMANTIC_COLOR_NAMES) {
186
+ const input = colors[name];
187
+ resolved[name] = {
188
+ base: input.base.clone(),
189
+ foreground: input.foreground.clone()
190
+ };
191
+ }
192
+ return resolved;
193
+ }
194
+ /**
195
+ * Resolve a ThemeDefinition into a complete ResolvedTheme.
196
+ * Dark mode colors are derived from light where not overridden.
197
+ */
198
+ function resolveTheme(def) {
199
+ return {
200
+ id: def.id,
201
+ name: def.name,
202
+ light: resolveColorSet(def.light),
203
+ dark: resolveColorSet(mergeDarkOverrides(def)),
204
+ fontSizes: { ...def.fontSizes },
205
+ fontFamilies: { ...def.fontFamilies },
206
+ spacing: def.spacing,
207
+ radii: { ...def.radii }
208
+ };
209
+ }
210
+ //#endregion
211
+ //#region ../../platform/theme-engine/src/tailwind-overrides.ts
212
+ const OVERRIDES = {
213
+ "--color-gray-50": "var(--color-muted)",
214
+ "--color-gray-100": "color-mix(in oklch, var(--color-muted), var(--color-foreground) 15%)",
215
+ "--color-gray-200": "var(--color-border)"
216
+ };
217
+ /**
218
+ * Map Tailwind built-in color names to semantic theme colors using color-mix
219
+ * for shade interpolation. Each shade maps to a percentage of the semantic
220
+ * color mixed with transparent, so shades naturally adapt to both light and
221
+ * dark modes without inversion logic.
222
+ */
223
+ function emitTailwindOverrides() {
224
+ const TAILWIND_COLOR_MAP = {
225
+ gray: "foreground",
226
+ red: "destructive",
227
+ blue: "primary",
228
+ green: "accent"
229
+ };
230
+ const TAILWIND_SHADES = [
231
+ 50,
232
+ 100,
233
+ 200,
234
+ 300,
235
+ 400,
236
+ 500,
237
+ 600,
238
+ 700,
239
+ 800,
240
+ 900,
241
+ 950
242
+ ];
243
+ const lines = [];
244
+ for (const [twName, semantic] of Object.entries(TAILWIND_COLOR_MAP)) for (const shade of TAILWIND_SHADES) {
245
+ const override = OVERRIDES[`--color-${twName}-${shade}`];
246
+ if (override) lines.push(`--color-${twName}-${shade}: ${override};`);
247
+ else {
248
+ const percent = Math.max(10, Math.min(Math.round(shade / 10), 100));
249
+ lines.push(`--color-${twName}-${shade}: color-mix(in oklch, var(--color-${semantic}) ${percent}%, transparent);`);
250
+ }
251
+ }
252
+ lines.push("--color-white: var(--color-background);");
253
+ lines.push("--color-black: var(--color-foreground);");
254
+ return lines;
255
+ }
256
+ //#endregion
257
+ //#region ../../platform/theme-engine/src/css-generator.ts
258
+ function colorToCSS(color) {
259
+ const result = color.toString({ format: "oklch" });
260
+ if (result.includes("NaN")) {
261
+ console.warn("[theme] colorToCSS produced NaN, using neutral fallback:", result);
262
+ return "oklch(0.5 0 0)";
263
+ }
264
+ return result;
265
+ }
266
+ function camelToKebab(str) {
267
+ return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
268
+ }
269
+ /**
270
+ * Emit --color-{name} and --color-{name}-foreground vars.
271
+ * Uses --color- prefix to match portal-widgets/tailwind.config.ts.
272
+ */
273
+ function emitColorVars(colors) {
274
+ const lines = [];
275
+ for (const name of SEMANTIC_COLOR_NAMES) {
276
+ const color = colors[name];
277
+ lines.push(`--color-${name}: ${colorToCSS(color.base)};`);
278
+ lines.push(`--color-${name}-foreground: ${colorToCSS(color.foreground)};`);
279
+ }
280
+ return lines;
281
+ }
282
+ /**
283
+ * Format a font family value for CSS output.
284
+ * - If the value starts with "var(" (legacy), pass through as-is
285
+ * - If the value already contains a comma (has fallback), pass through as-is
286
+ * - Otherwise, wrap in quotes and append a generic sans-serif fallback
287
+ */
288
+ function formatFontFamily(value) {
289
+ if (value.startsWith("var(")) return value;
290
+ if (value.includes(",")) return value;
291
+ return `'${value}', sans-serif`;
292
+ }
293
+ /**
294
+ * Emit non-color CSS variables (font sizes, families, spacing, radii).
295
+ */
296
+ function emitNonColorVars(theme) {
297
+ const lines = [];
298
+ for (const key of FONT_SIZE_KEYS) lines.push(`--font-size-${camelToKebab(key)}: ${theme.fontSizes[key]};`);
299
+ for (const key of FONT_FAMILY_KEYS) lines.push(`--font-${key}: ${formatFontFamily(theme.fontFamilies[key])};`);
300
+ lines.push(`--spacing: ${theme.spacing};`);
301
+ for (const key of RADIUS_KEYS) lines.push(`--radius-${camelToKebab(key)}: ${theme.radii[key]};`);
302
+ return lines;
303
+ }
304
+ /**
305
+ * Static CSS alias variables that bridge theme var names to Tailwind/component conventions.
306
+ * These are always emitted and not mode-dependent.
307
+ */
308
+ const globalCSSOverride = [
309
+ "--color-background-foreground: var(--color-foreground);",
310
+ "--color-foreground-foreground: var(--color-background);",
311
+ "--color-contrast: var(--color-foreground);",
312
+ ...SEMANTIC_COLOR_NAMES.map((value) => `--${value}: var(--color-${value});`),
313
+ ...SEMANTIC_COLOR_NAMES.map((value) => `--${value}-foreground: var(--color-${value}-foreground);`),
314
+ "--sidebar-ring: var(--color-primary);",
315
+ "--sidebar-border: var(--color-border);",
316
+ "--sidebar-accent-foreground: var(--color-accent-foreground);",
317
+ "--sidebar-accent: var(--color-accent);",
318
+ "--sidebar-primary-foreground: var(--color-primary-foreground);",
319
+ "--sidebar-primary: var(--color-primary);",
320
+ "--sidebar-foreground: var(--color-muted-foreground);",
321
+ "--sidebar: var(--color-muted);",
322
+ "--border: color-mix(in oklch, var(--color-background), var(--color-foreground) 15%);",
323
+ "--ring: var(--color-primary);",
324
+ "--popover: var(--color-background);",
325
+ "--popover-foreground: var(--color-foreground);",
326
+ "--card: var(--color-muted);",
327
+ "--card-foreground: var(--color-muted-foreground);",
328
+ "--radius-sm: var(--radius-small);",
329
+ "--radius-md: var(--radius-medium);",
330
+ "--radius-lg: var(--radius-large);",
331
+ "--radius-xl: var(--radius-extra-large);",
332
+ "--text-xs: var(--font-size-extra-small);",
333
+ "--text-sm: var(--font-size-small);",
334
+ "--text-base: var(--font-size-regular);",
335
+ "--text-lg: var(--font-size-large);",
336
+ "--text-xl: var(--font-size-extra-large);",
337
+ "--text-2xl: var(--font-size-giant);"
338
+ ];
339
+ /**
340
+ * Overrides for global tailwindcss for specifically dark mode.
341
+ */
342
+ const globalDarkCSSOverride = ["--border: color-mix(in oklch, var(--color-background), var(--color-foreground) 15%);"];
343
+ /**
344
+ * Generate a complete CSS string for a resolved theme.
345
+ * Outputs 2–3 blocks: light default, dark explicit via `[data-theme-mode="dark"]`,
346
+ * and (unless `disableAutoTheme`) a `prefers-color-scheme: dark` media query block.
347
+ */
348
+ function generateThemeCSS(theme, options = {}) {
349
+ const sel = `[data-theme="${theme.id}"]`;
350
+ const tw = options.mapTailwindColors ?? true;
351
+ const blocks = [];
352
+ blocks.push(`${sel} {`);
353
+ blocks.push(...globalCSSOverride);
354
+ blocks.push(...emitNonColorVars(theme));
355
+ blocks.push(...emitColorVars(theme.light));
356
+ if (tw) blocks.push(...emitTailwindOverrides());
357
+ blocks.push(`}`);
358
+ blocks.push(`${sel}[data-theme-mode="dark"] {`);
359
+ blocks.push(...globalDarkCSSOverride);
360
+ blocks.push(...emitColorVars(theme.dark));
361
+ if (tw) blocks.push(...emitTailwindOverrides());
362
+ blocks.push(`}`);
363
+ if (!options.disableAutoTheme) {
364
+ blocks.push(`@media (prefers-color-scheme: dark) {`);
365
+ blocks.push(`${sel}:not([data-theme-mode]) {`);
366
+ blocks.push(...globalDarkCSSOverride);
367
+ blocks.push(...emitColorVars(theme.dark).map((l) => `${l}`));
368
+ if (tw) blocks.push(...emitTailwindOverrides().map((l) => `${l}`));
369
+ blocks.push(`}`);
370
+ blocks.push(`}`);
371
+ }
372
+ return blocks.join("\n");
373
+ }
374
+ //#endregion
375
+ //#region ../../platform/theme-engine/src/defaults.ts
376
+ const DEFAULT_FONT_SIZES = {
377
+ extraSmall: "0.75rem",
378
+ small: "0.875rem",
379
+ regular: "1rem",
380
+ large: "1.125rem",
381
+ extraLarge: "1.25rem",
382
+ giant: "1.5rem"
383
+ };
384
+ const DEFAULT_FONT_FAMILIES = {
385
+ header: "Inter",
386
+ body: "Inter"
387
+ };
388
+ const DEFAULT_SPACING = "0.25rem";
389
+ const DEFAULT_RADII = {
390
+ small: "0.25rem",
391
+ medium: "0.5rem",
392
+ large: "0.75rem",
393
+ extraLarge: "1rem"
394
+ };
395
+ const DEFAULT_COLORS = {
396
+ background: "#ffffff",
397
+ foreground: "#1a1a1a",
398
+ primary: "#3b82f6",
399
+ secondary: "#6b7280",
400
+ accent: "#10b981",
401
+ muted: "#f3f4f6",
402
+ destructive: "#ef4444",
403
+ mutedForeground: "#6b7280"
404
+ };
405
+ const DEFAULT_THEME_ID = "default";
406
+ const DEFAULT_THEME_NAME = "Default Theme";
407
+ /**
408
+ * Build a fresh ThemeDefinition populated with all defaults.
409
+ * Returns a new object each call because Color instances are mutable — do not cache the result.
410
+ */
411
+ function getDefaultThemeDefinition() {
412
+ const bg = new colorjs_io.default(DEFAULT_COLORS.background);
413
+ const fg = new colorjs_io.default(DEFAULT_COLORS.foreground);
414
+ const primary = new colorjs_io.default(DEFAULT_COLORS.primary);
415
+ const secondary = new colorjs_io.default(DEFAULT_COLORS.secondary);
416
+ const accent = new colorjs_io.default(DEFAULT_COLORS.accent);
417
+ const muted = new colorjs_io.default(DEFAULT_COLORS.muted);
418
+ const destructive = new colorjs_io.default(DEFAULT_COLORS.destructive);
419
+ const mutedFg = new colorjs_io.default(DEFAULT_COLORS.mutedForeground);
420
+ const darkBg = new colorjs_io.default("#0a0a0a");
421
+ const darkFg = new colorjs_io.default("#fafafa");
422
+ const darkMuted = new colorjs_io.default("#171717");
423
+ const darkMutedForeground = new colorjs_io.default("#dddddd");
424
+ return {
425
+ id: DEFAULT_THEME_ID,
426
+ name: DEFAULT_THEME_NAME,
427
+ light: {
428
+ background: {
429
+ base: bg,
430
+ foreground: fg
431
+ },
432
+ foreground: {
433
+ base: fg,
434
+ foreground: bg
435
+ },
436
+ primary: {
437
+ base: primary,
438
+ foreground: getForegroundColor(fg, primary)
439
+ },
440
+ secondary: {
441
+ base: secondary,
442
+ foreground: getForegroundColor(fg, secondary)
443
+ },
444
+ accent: {
445
+ base: accent,
446
+ foreground: getForegroundColor(fg, accent)
447
+ },
448
+ muted: {
449
+ base: muted,
450
+ foreground: mutedFg
451
+ },
452
+ destructive: {
453
+ base: destructive,
454
+ foreground: getForegroundColor(fg, destructive)
455
+ }
456
+ },
457
+ dark: {
458
+ background: {
459
+ base: darkBg,
460
+ foreground: darkFg
461
+ },
462
+ foreground: {
463
+ base: darkFg,
464
+ foreground: darkBg
465
+ },
466
+ muted: {
467
+ base: darkMuted,
468
+ foreground: darkMutedForeground
469
+ }
470
+ },
471
+ fontSizes: { ...DEFAULT_FONT_SIZES },
472
+ fontFamilies: { ...DEFAULT_FONT_FAMILIES },
473
+ spacing: DEFAULT_SPACING,
474
+ radii: { ...DEFAULT_RADII }
475
+ };
476
+ }
477
+ //#endregion
478
+ //#region ../../platform/theme-engine/src/serialisation.ts
479
+ function colorToPlain(color) {
480
+ return {
481
+ l: color.oklch.l ?? 0,
482
+ c: color.oklch.c ?? 0,
483
+ h: color.oklch.h ?? 0
484
+ };
485
+ }
486
+ function plainToColor(plain) {
487
+ return new colorjs_io.default("oklch", [
488
+ plain.l,
489
+ plain.c,
490
+ plain.h
491
+ ]);
492
+ }
493
+ /**
494
+ * Serialise a ThemeDefinition (with Color objects) to a plain JSON payload
495
+ * suitable for backend storage.
496
+ */
497
+ function serialiseTheme(def) {
498
+ const light = {};
499
+ for (const name of SEMANTIC_COLOR_NAMES) light[name] = {
500
+ base: colorToPlain(def.light[name].base),
501
+ foreground: colorToPlain(def.light[name].foreground)
502
+ };
503
+ const dark = {};
504
+ for (const [name, value] of Object.entries(def.dark)) {
505
+ if (!value) continue;
506
+ dark[name] = {
507
+ ...value.base ? { base: colorToPlain(value.base) } : {},
508
+ ...value.foreground ? { foreground: colorToPlain(value.foreground) } : {}
509
+ };
510
+ }
511
+ return {
512
+ id: def.id,
513
+ name: def.name,
514
+ light,
515
+ dark,
516
+ fontSizes: { ...def.fontSizes },
517
+ fontFamilies: { ...def.fontFamilies },
518
+ spacing: def.spacing,
519
+ radii: { ...def.radii },
520
+ ...def.syncWithBrandColors ? { syncWithBrandColors: true } : {}
521
+ };
522
+ }
523
+ /**
524
+ * Deserialise a backend payload into a ThemeDefinition with Color objects.
525
+ * Accepts `Record<string, unknown>` because API data is untyped at the boundary.
526
+ * Falls back to default colors for any missing light-mode entries.
527
+ */
528
+ function deserialiseTheme(payload) {
529
+ const lightRaw = payload.light ?? {};
530
+ const darkRaw = payload.dark ?? {};
531
+ const defaults = getDefaultThemeDefinition();
532
+ const light = {};
533
+ for (const name of SEMANTIC_COLOR_NAMES) {
534
+ const entry = lightRaw[name];
535
+ if (entry) light[name] = {
536
+ base: plainToColor(entry.base),
537
+ foreground: plainToColor(entry.foreground)
538
+ };
539
+ else {
540
+ console.warn(`[theme] deserialiseTheme: missing light color "${name}", using default`);
541
+ light[name] = defaults.light[name];
542
+ }
543
+ }
544
+ const dark = {};
545
+ for (const [name, value] of Object.entries(darkRaw)) {
546
+ if (!value) continue;
547
+ dark[name] = {
548
+ ...value.base ? { base: plainToColor(value.base) } : {},
549
+ ...value.foreground ? { foreground: plainToColor(value.foreground) } : {}
550
+ };
551
+ }
552
+ return {
553
+ id: payload.id,
554
+ name: payload.name,
555
+ light,
556
+ dark,
557
+ fontSizes: payload.fontSizes ?? DEFAULT_FONT_SIZES,
558
+ fontFamilies: payload.fontFamilies ?? DEFAULT_FONT_FAMILIES,
559
+ spacing: payload.spacing ?? "0.25rem",
560
+ radii: payload.radii ?? DEFAULT_RADII,
561
+ ...payload.syncWithBrandColors === true ? { syncWithBrandColors: true } : {}
562
+ };
563
+ }
564
+ //#endregion
565
+ //#region ../../platform/theme-engine/src/transforms.ts
566
+ /**
567
+ * Check if a theme config uses the new structured format (has a `light` key
568
+ * that is an object) vs the legacy flat format.
569
+ */
570
+ function isNewThemeFormat(config) {
571
+ return config.light != null && typeof config.light === "object";
572
+ }
573
+ /**
574
+ * Convert a legacy flat config to a ThemeDefinition.
575
+ * Legacy format: { base: "#fff", text: "#000", primary: "oklch(0.6 0.2 250)", ... }
576
+ */
577
+ function legacyConfigToDefinition(id, name, config) {
578
+ const bg = parseColor(config.base ?? config.background ?? DEFAULT_COLORS.background);
579
+ const fg = parseColor(config.text ?? config.foreground ?? DEFAULT_COLORS.foreground);
580
+ const primary = parseColor(config.primary ?? DEFAULT_COLORS.primary);
581
+ const secondary = parseColor(config.secondary ?? DEFAULT_COLORS.secondary);
582
+ const accent = parseColor(config.accent ?? DEFAULT_COLORS.accent);
583
+ const muted = parseColor(config.muted ?? DEFAULT_COLORS.muted);
584
+ const destructive = parseColor(config.destructive ?? DEFAULT_COLORS.destructive);
585
+ const mutedFg = parseColor(config.mutedForeground ?? DEFAULT_COLORS.mutedForeground);
586
+ return {
587
+ id: String(id),
588
+ name,
589
+ light: {
590
+ background: {
591
+ base: bg,
592
+ foreground: fg
593
+ },
594
+ foreground: {
595
+ base: fg,
596
+ foreground: bg
597
+ },
598
+ primary: {
599
+ base: primary,
600
+ foreground: getForegroundColor(fg, primary)
601
+ },
602
+ secondary: {
603
+ base: secondary,
604
+ foreground: getForegroundColor(fg, secondary)
605
+ },
606
+ accent: {
607
+ base: accent,
608
+ foreground: getForegroundColor(fg, accent)
609
+ },
610
+ muted: {
611
+ base: muted,
612
+ foreground: mutedFg
613
+ },
614
+ destructive: {
615
+ base: destructive,
616
+ foreground: getForegroundColor(fg, destructive)
617
+ }
618
+ },
619
+ dark: {},
620
+ fontSizes: {
621
+ extraSmall: config.extraSmall ?? DEFAULT_FONT_SIZES.extraSmall,
622
+ small: config.small ?? DEFAULT_FONT_SIZES.small,
623
+ regular: config.regular ?? DEFAULT_FONT_SIZES.regular,
624
+ large: config.large ?? DEFAULT_FONT_SIZES.large,
625
+ extraLarge: config.extraLarge ?? DEFAULT_FONT_SIZES.extraLarge,
626
+ giant: config.giant ?? DEFAULT_FONT_SIZES.giant
627
+ },
628
+ fontFamilies: {
629
+ header: config.headerFont ?? DEFAULT_FONT_FAMILIES.header,
630
+ body: config.bodyFont ?? DEFAULT_FONT_FAMILIES.body
631
+ },
632
+ spacing: config.globalSpacing ?? "0.25rem",
633
+ radii: {
634
+ small: config.radiusSmall ?? DEFAULT_RADII.small,
635
+ medium: config.radiusMedium ?? DEFAULT_RADII.medium,
636
+ large: config.radiusLarge ?? DEFAULT_RADII.large,
637
+ extraLarge: config.radiusExtraLarge ?? DEFAULT_RADII.extraLarge
638
+ }
639
+ };
640
+ }
641
+ /**
642
+ * Build a ThemeDefinition from a single API theme object.
643
+ * Handles both new structured format and legacy flat format.
644
+ */
645
+ function buildThemeDefinition(theme) {
646
+ const config = theme.config ?? {};
647
+ if (isNewThemeFormat(config)) return deserialiseTheme({
648
+ ...config,
649
+ id: String(theme.id),
650
+ name: theme.name ?? "Untitled Theme"
651
+ });
652
+ return legacyConfigToDefinition(theme.id, theme.name ?? "Untitled Theme", config);
653
+ }
654
+ /**
655
+ * Transform raw API themes to ThemeDefinition[].
656
+ * Catches and logs errors per theme (graceful degradation).
657
+ */
658
+ function transformThemes(themes) {
659
+ return themes.flatMap((theme) => {
660
+ try {
661
+ return [buildThemeDefinition(theme)];
662
+ } catch (error) {
663
+ console.error(`[theme] Failed to build theme id=${theme.id}:`, error);
664
+ return [];
665
+ }
666
+ });
667
+ }
668
+ /**
669
+ * Get the active theme ID from a list of raw API themes.
670
+ * Falls back to the first theme if none is marked active.
671
+ */
672
+ function getActiveThemeId(themes) {
673
+ const active = themes.find((t) => t.active) ?? themes[0];
674
+ return active ? String(active.id) : void 0;
675
+ }
676
+ //#endregion
677
+ //#region ../../platform/theme-engine/src/theme-applicator.ts
678
+ const STYLE_PREFIX = "theme-style-";
679
+ const FONT_LINK_PREFIX = "theme-font-";
680
+ const SYSTEM_FONTS = new Set([
681
+ "sans-serif",
682
+ "serif",
683
+ "monospace",
684
+ "cursive",
685
+ "fantasy",
686
+ "system-ui",
687
+ "ui-sans-serif",
688
+ "ui-serif",
689
+ "ui-monospace"
690
+ ]);
691
+ /** Build a Google Fonts CSS2 URL for a given font family with all weights. */
692
+ function buildGoogleFontUrl(family) {
693
+ return `https://fonts.googleapis.com/css2?family=${encodeURIComponent(family).replace(/%20/g, "+")}:wght@100;200;300;400;500;600;700;800;900&display=swap`;
694
+ }
695
+ /** Check if a font family value needs to be loaded (i.e. is not a CSS var or system font). */
696
+ function isLoadableFont(value) {
697
+ if (!value) return false;
698
+ if (value.startsWith("var(")) return false;
699
+ return !SYSTEM_FONTS.has(value.toLowerCase());
700
+ }
701
+ /** Deterministic link element ID for a font family. */
702
+ function fontLinkId(family) {
703
+ return `${FONT_LINK_PREFIX}${family.replace(/\s+/g, "-").toLowerCase()}`;
704
+ }
705
+ /**
706
+ * Inject or update `<link>` elements for Google Fonts used by the theme.
707
+ * Removes links for fonts that are no longer referenced.
708
+ */
709
+ function loadThemeFonts(theme) {
710
+ if (typeof document === "undefined") return;
711
+ const fontsToLoad = /* @__PURE__ */ new Set();
712
+ for (const key of FONT_FAMILY_KEYS) {
713
+ const value = theme.fontFamilies[key];
714
+ if (isLoadableFont(value)) fontsToLoad.add(value);
715
+ }
716
+ document.querySelectorAll(`link[id^="${FONT_LINK_PREFIX}"]`).forEach((link) => {
717
+ const owners = link.getAttribute("data-font-theme-ids")?.split(",") ?? [];
718
+ if (!owners.includes(theme.id)) return;
719
+ const fontName = link.getAttribute("data-font-family");
720
+ if (fontName && !fontsToLoad.has(fontName)) {
721
+ const remaining = owners.filter((id) => id !== theme.id);
722
+ if (remaining.length === 0) link.remove();
723
+ else link.setAttribute("data-font-theme-ids", remaining.join(","));
724
+ }
725
+ });
726
+ for (const family of fontsToLoad) {
727
+ const id = fontLinkId(family);
728
+ const existing = document.getElementById(id);
729
+ if (existing) {
730
+ const owners = existing.getAttribute("data-font-theme-ids")?.split(",") ?? [];
731
+ if (!owners.includes(theme.id)) existing.setAttribute("data-font-theme-ids", [...owners, theme.id].join(","));
732
+ } else {
733
+ const link = document.createElement("link");
734
+ link.id = id;
735
+ link.rel = "stylesheet";
736
+ link.href = buildGoogleFontUrl(family);
737
+ link.setAttribute("data-font-family", family);
738
+ link.setAttribute("data-font-theme-ids", theme.id);
739
+ document.head.appendChild(link);
740
+ }
741
+ }
742
+ }
743
+ /** Remove all font `<link>` elements injected by the theme system. */
744
+ function removeAllFontLinks() {
745
+ if (typeof document === "undefined") return;
746
+ document.querySelectorAll(`link[id^="${FONT_LINK_PREFIX}"]`).forEach((el) => el.remove());
747
+ }
748
+ /**
749
+ * Inject or update a `<style>` element in `<head>` for the given theme.
750
+ * The element ID is deterministic (`theme-style-{themeId}`) so repeated calls
751
+ * for the same theme are idempotent — the existing element is updated in place.
752
+ * Also loads Google Fonts referenced by the theme's font families.
753
+ * No-op when `document` is unavailable (SSR).
754
+ */
755
+ function applyTheme(theme, options) {
756
+ if (typeof document === "undefined") return;
757
+ try {
758
+ loadThemeFonts(theme);
759
+ const styleId = `${STYLE_PREFIX}${theme.id}`;
760
+ let el = document.getElementById(styleId);
761
+ if (!el) {
762
+ el = document.createElement("style");
763
+ el.id = styleId;
764
+ document.head.appendChild(el);
765
+ }
766
+ el.textContent = generateThemeCSS(theme, options);
767
+ } catch (error) {
768
+ console.error(`[theme] applyTheme failed for "${theme.id}":`, error);
769
+ }
770
+ }
771
+ /** Remove an injected theme stylesheet and clean up font link ownership. No-op during SSR. */
772
+ function removeTheme(themeId) {
773
+ if (typeof document === "undefined") return;
774
+ document.getElementById(`${STYLE_PREFIX}${themeId}`)?.remove();
775
+ document.querySelectorAll(`link[id^="${FONT_LINK_PREFIX}"]`).forEach((link) => {
776
+ const remaining = (link.getAttribute("data-font-theme-ids")?.split(",") ?? []).filter((id) => id !== themeId);
777
+ if (remaining.length === 0) link.remove();
778
+ else link.setAttribute("data-font-theme-ids", remaining.join(","));
779
+ });
780
+ }
781
+ /** Remove all injected theme stylesheets and font links. No-op during SSR. */
782
+ function removeAllThemes() {
783
+ if (typeof document === "undefined") return;
784
+ document.querySelectorAll(`style[id^="${STYLE_PREFIX}"]`).forEach((el) => el.remove());
785
+ removeAllFontLinks();
786
+ }
787
+ //#endregion
788
+ Object.defineProperty(exports, "CountriesApiProvider", {
789
+ enumerable: true,
790
+ get: function() {
791
+ return CountriesApiProvider;
792
+ }
793
+ });
794
+ Object.defineProperty(exports, "DEFAULT_COLORS", {
795
+ enumerable: true,
796
+ get: function() {
797
+ return DEFAULT_COLORS;
798
+ }
799
+ });
800
+ Object.defineProperty(exports, "DEFAULT_FONT_FAMILIES", {
801
+ enumerable: true,
802
+ get: function() {
803
+ return DEFAULT_FONT_FAMILIES;
804
+ }
805
+ });
806
+ Object.defineProperty(exports, "DEFAULT_FONT_SIZES", {
807
+ enumerable: true,
808
+ get: function() {
809
+ return DEFAULT_FONT_SIZES;
810
+ }
811
+ });
812
+ Object.defineProperty(exports, "DEFAULT_RADII", {
813
+ enumerable: true,
814
+ get: function() {
815
+ return DEFAULT_RADII;
816
+ }
817
+ });
818
+ Object.defineProperty(exports, "DEFAULT_SPACING", {
819
+ enumerable: true,
820
+ get: function() {
821
+ return DEFAULT_SPACING;
822
+ }
823
+ });
824
+ Object.defineProperty(exports, "DEFAULT_THEME_ID", {
825
+ enumerable: true,
826
+ get: function() {
827
+ return DEFAULT_THEME_ID;
828
+ }
829
+ });
830
+ Object.defineProperty(exports, "DEFAULT_THEME_NAME", {
831
+ enumerable: true,
832
+ get: function() {
833
+ return DEFAULT_THEME_NAME;
834
+ }
835
+ });
836
+ Object.defineProperty(exports, "FONT_FAMILY_KEYS", {
837
+ enumerable: true,
838
+ get: function() {
839
+ return FONT_FAMILY_KEYS;
840
+ }
841
+ });
842
+ Object.defineProperty(exports, "FONT_SIZE_KEYS", {
843
+ enumerable: true,
844
+ get: function() {
845
+ return FONT_SIZE_KEYS;
846
+ }
847
+ });
848
+ Object.defineProperty(exports, "RADIUS_KEYS", {
849
+ enumerable: true,
850
+ get: function() {
851
+ return RADIUS_KEYS;
852
+ }
853
+ });
854
+ Object.defineProperty(exports, "SEMANTIC_COLOR_NAMES", {
855
+ enumerable: true,
856
+ get: function() {
857
+ return SEMANTIC_COLOR_NAMES;
858
+ }
859
+ });
860
+ Object.defineProperty(exports, "applyTheme", {
861
+ enumerable: true,
862
+ get: function() {
863
+ return applyTheme;
864
+ }
865
+ });
866
+ Object.defineProperty(exports, "buildThemeDefinition", {
867
+ enumerable: true,
868
+ get: function() {
869
+ return buildThemeDefinition;
870
+ }
871
+ });
872
+ Object.defineProperty(exports, "deriveDarkVariant", {
873
+ enumerable: true,
874
+ get: function() {
875
+ return deriveDarkVariant;
876
+ }
877
+ });
878
+ Object.defineProperty(exports, "deserialiseTheme", {
879
+ enumerable: true,
880
+ get: function() {
881
+ return deserialiseTheme;
882
+ }
883
+ });
884
+ Object.defineProperty(exports, "generateThemeCSS", {
885
+ enumerable: true,
886
+ get: function() {
887
+ return generateThemeCSS;
888
+ }
889
+ });
890
+ Object.defineProperty(exports, "getActiveThemeId", {
891
+ enumerable: true,
892
+ get: function() {
893
+ return getActiveThemeId;
894
+ }
895
+ });
896
+ Object.defineProperty(exports, "getContrastingTextColor", {
897
+ enumerable: true,
898
+ get: function() {
899
+ return getContrastingTextColor;
900
+ }
901
+ });
902
+ Object.defineProperty(exports, "getDefaultThemeDefinition", {
903
+ enumerable: true,
904
+ get: function() {
905
+ return getDefaultThemeDefinition;
906
+ }
907
+ });
908
+ Object.defineProperty(exports, "getForegroundColor", {
909
+ enumerable: true,
910
+ get: function() {
911
+ return getForegroundColor;
912
+ }
913
+ });
914
+ Object.defineProperty(exports, "mergeDarkOverrides", {
915
+ enumerable: true,
916
+ get: function() {
917
+ return mergeDarkOverrides;
918
+ }
919
+ });
920
+ Object.defineProperty(exports, "parseColor", {
921
+ enumerable: true,
922
+ get: function() {
923
+ return parseColor;
924
+ }
925
+ });
926
+ Object.defineProperty(exports, "removeAllThemes", {
927
+ enumerable: true,
928
+ get: function() {
929
+ return removeAllThemes;
930
+ }
931
+ });
932
+ Object.defineProperty(exports, "removeTheme", {
933
+ enumerable: true,
934
+ get: function() {
935
+ return removeTheme;
936
+ }
937
+ });
938
+ Object.defineProperty(exports, "resolveTheme", {
939
+ enumerable: true,
940
+ get: function() {
941
+ return resolveTheme;
942
+ }
943
+ });
944
+ Object.defineProperty(exports, "serialiseTheme", {
945
+ enumerable: true,
946
+ get: function() {
947
+ return serialiseTheme;
948
+ }
949
+ });
950
+ Object.defineProperty(exports, "transformThemes", {
951
+ enumerable: true,
952
+ get: function() {
953
+ return transformThemes;
954
+ }
955
+ });
956
+ Object.defineProperty(exports, "useCountriesApi", {
957
+ enumerable: true,
958
+ get: function() {
959
+ return useCountriesApi;
960
+ }
961
+ });
962
+
963
+ //# sourceMappingURL=src-BNcNh8fM.cjs.map