@fluid-app/portal-core 0.1.16

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 (195) hide show
  1. package/dist/chunk-CKQMccvm.cjs +28 -0
  2. package/dist/data-sources/DataAwareWidget.cjs +50 -0
  3. package/dist/data-sources/DataAwareWidget.cjs.map +1 -0
  4. package/dist/data-sources/DataAwareWidget.d.cts +24 -0
  5. package/dist/data-sources/DataAwareWidget.d.cts.map +1 -0
  6. package/dist/data-sources/DataAwareWidget.d.mts +24 -0
  7. package/dist/data-sources/DataAwareWidget.d.mts.map +1 -0
  8. package/dist/data-sources/DataAwareWidget.mjs +48 -0
  9. package/dist/data-sources/DataAwareWidget.mjs.map +1 -0
  10. package/dist/data-sources/ErrorState.cjs +20 -0
  11. package/dist/data-sources/ErrorState.cjs.map +1 -0
  12. package/dist/data-sources/ErrorState.d.cts +7 -0
  13. package/dist/data-sources/ErrorState.d.cts.map +1 -0
  14. package/dist/data-sources/ErrorState.d.mts +7 -0
  15. package/dist/data-sources/ErrorState.d.mts.map +1 -0
  16. package/dist/data-sources/ErrorState.mjs +18 -0
  17. package/dist/data-sources/ErrorState.mjs.map +1 -0
  18. package/dist/data-sources/context.cjs +24 -0
  19. package/dist/data-sources/context.cjs.map +1 -0
  20. package/dist/data-sources/context.d.cts +21 -0
  21. package/dist/data-sources/context.d.cts.map +1 -0
  22. package/dist/data-sources/context.d.mts +21 -0
  23. package/dist/data-sources/context.d.mts.map +1 -0
  24. package/dist/data-sources/context.mjs +21 -0
  25. package/dist/data-sources/context.mjs.map +1 -0
  26. package/dist/data-sources/fetchers/api.cjs +65 -0
  27. package/dist/data-sources/fetchers/api.cjs.map +1 -0
  28. package/dist/data-sources/fetchers/api.d.cts +10 -0
  29. package/dist/data-sources/fetchers/api.d.cts.map +1 -0
  30. package/dist/data-sources/fetchers/api.d.mts +10 -0
  31. package/dist/data-sources/fetchers/api.d.mts.map +1 -0
  32. package/dist/data-sources/fetchers/api.mjs +64 -0
  33. package/dist/data-sources/fetchers/api.mjs.map +1 -0
  34. package/dist/data-sources/fetchers/custom.cjs +108 -0
  35. package/dist/data-sources/fetchers/custom.cjs.map +1 -0
  36. package/dist/data-sources/fetchers/custom.d.cts +17 -0
  37. package/dist/data-sources/fetchers/custom.d.cts.map +1 -0
  38. package/dist/data-sources/fetchers/custom.d.mts +17 -0
  39. package/dist/data-sources/fetchers/custom.d.mts.map +1 -0
  40. package/dist/data-sources/fetchers/custom.mjs +107 -0
  41. package/dist/data-sources/fetchers/custom.mjs.map +1 -0
  42. package/dist/data-sources/fetchers/static.cjs +161 -0
  43. package/dist/data-sources/fetchers/static.cjs.map +1 -0
  44. package/dist/data-sources/fetchers/static.d.cts +40 -0
  45. package/dist/data-sources/fetchers/static.d.cts.map +1 -0
  46. package/dist/data-sources/fetchers/static.d.mts +40 -0
  47. package/dist/data-sources/fetchers/static.d.mts.map +1 -0
  48. package/dist/data-sources/fetchers/static.mjs +158 -0
  49. package/dist/data-sources/fetchers/static.mjs.map +1 -0
  50. package/dist/data-sources/preview-context.cjs +21 -0
  51. package/dist/data-sources/preview-context.cjs.map +1 -0
  52. package/dist/data-sources/preview-context.d.cts +13 -0
  53. package/dist/data-sources/preview-context.d.cts.map +1 -0
  54. package/dist/data-sources/preview-context.d.mts +13 -0
  55. package/dist/data-sources/preview-context.d.mts.map +1 -0
  56. package/dist/data-sources/preview-context.mjs +18 -0
  57. package/dist/data-sources/preview-context.mjs.map +1 -0
  58. package/dist/data-sources/registry-context.cjs +53 -0
  59. package/dist/data-sources/registry-context.cjs.map +1 -0
  60. package/dist/data-sources/registry-context.d.cts +48 -0
  61. package/dist/data-sources/registry-context.d.cts.map +1 -0
  62. package/dist/data-sources/registry-context.d.mts +48 -0
  63. package/dist/data-sources/registry-context.d.mts.map +1 -0
  64. package/dist/data-sources/registry-context.mjs +49 -0
  65. package/dist/data-sources/registry-context.mjs.map +1 -0
  66. package/dist/data-sources/registry.cjs +31 -0
  67. package/dist/data-sources/registry.cjs.map +1 -0
  68. package/dist/data-sources/registry.d.cts +19 -0
  69. package/dist/data-sources/registry.d.cts.map +1 -0
  70. package/dist/data-sources/registry.d.mts +19 -0
  71. package/dist/data-sources/registry.d.mts.map +1 -0
  72. package/dist/data-sources/registry.mjs +29 -0
  73. package/dist/data-sources/registry.mjs.map +1 -0
  74. package/dist/data-sources/transformers.cjs +154 -0
  75. package/dist/data-sources/transformers.cjs.map +1 -0
  76. package/dist/data-sources/transformers.d.cts +10 -0
  77. package/dist/data-sources/transformers.d.cts.map +1 -0
  78. package/dist/data-sources/transformers.d.mts +10 -0
  79. package/dist/data-sources/transformers.d.mts.map +1 -0
  80. package/dist/data-sources/transformers.mjs +153 -0
  81. package/dist/data-sources/transformers.mjs.map +1 -0
  82. package/dist/data-sources/types.cjs +0 -0
  83. package/dist/data-sources/types.d.cts +2 -0
  84. package/dist/data-sources/types.d.mts +2 -0
  85. package/dist/data-sources/types.mjs +1 -0
  86. package/dist/data-sources/use-widget-data.cjs +111 -0
  87. package/dist/data-sources/use-widget-data.cjs.map +1 -0
  88. package/dist/data-sources/use-widget-data.d.cts +17 -0
  89. package/dist/data-sources/use-widget-data.d.cts.map +1 -0
  90. package/dist/data-sources/use-widget-data.d.mts +17 -0
  91. package/dist/data-sources/use-widget-data.d.mts.map +1 -0
  92. package/dist/data-sources/use-widget-data.mjs +109 -0
  93. package/dist/data-sources/use-widget-data.mjs.map +1 -0
  94. package/dist/index-B5cTNde-.d.cts +246 -0
  95. package/dist/index-B5cTNde-.d.cts.map +1 -0
  96. package/dist/index-Cqt2JzkQ.d.mts +246 -0
  97. package/dist/index-Cqt2JzkQ.d.mts.map +1 -0
  98. package/dist/registries/index.cjs +243 -0
  99. package/dist/registries/index.cjs.map +1 -0
  100. package/dist/registries/index.d.cts +338 -0
  101. package/dist/registries/index.d.cts.map +1 -0
  102. package/dist/registries/index.d.mts +338 -0
  103. package/dist/registries/index.d.mts.map +1 -0
  104. package/dist/registries/index.mjs +229 -0
  105. package/dist/registries/index.mjs.map +1 -0
  106. package/dist/shell/AppShellLayout.cjs +49 -0
  107. package/dist/shell/AppShellLayout.cjs.map +1 -0
  108. package/dist/shell/AppShellLayout.d.cts +39 -0
  109. package/dist/shell/AppShellLayout.d.cts.map +1 -0
  110. package/dist/shell/AppShellLayout.d.mts +39 -0
  111. package/dist/shell/AppShellLayout.d.mts.map +1 -0
  112. package/dist/shell/AppShellLayout.mjs +46 -0
  113. package/dist/shell/AppShellLayout.mjs.map +1 -0
  114. package/dist/shell/ScreenHeader.cjs +44 -0
  115. package/dist/shell/ScreenHeader.cjs.map +1 -0
  116. package/dist/shell/ScreenHeader.d.cts +12 -0
  117. package/dist/shell/ScreenHeader.d.cts.map +1 -0
  118. package/dist/shell/ScreenHeader.d.mts +12 -0
  119. package/dist/shell/ScreenHeader.d.mts.map +1 -0
  120. package/dist/shell/ScreenHeader.mjs +42 -0
  121. package/dist/shell/ScreenHeader.mjs.map +1 -0
  122. package/dist/shell/ScreenHeaderContext.cjs +91 -0
  123. package/dist/shell/ScreenHeaderContext.cjs.map +1 -0
  124. package/dist/shell/ScreenHeaderContext.d.cts +35 -0
  125. package/dist/shell/ScreenHeaderContext.d.cts.map +1 -0
  126. package/dist/shell/ScreenHeaderContext.d.mts +35 -0
  127. package/dist/shell/ScreenHeaderContext.d.mts.map +1 -0
  128. package/dist/shell/ScreenHeaderContext.mjs +86 -0
  129. package/dist/shell/ScreenHeaderContext.mjs.map +1 -0
  130. package/dist/shell/ThemeModeContext.cjs +70 -0
  131. package/dist/shell/ThemeModeContext.cjs.map +1 -0
  132. package/dist/shell/ThemeModeContext.d.cts +33 -0
  133. package/dist/shell/ThemeModeContext.d.cts.map +1 -0
  134. package/dist/shell/ThemeModeContext.d.mts +33 -0
  135. package/dist/shell/ThemeModeContext.d.mts.map +1 -0
  136. package/dist/shell/ThemeModeContext.mjs +66 -0
  137. package/dist/shell/ThemeModeContext.mjs.map +1 -0
  138. package/dist/shell/index.cjs +43 -0
  139. package/dist/shell/index.d.cts +7 -0
  140. package/dist/shell/index.d.mts +7 -0
  141. package/dist/shell/index.mjs +7 -0
  142. package/dist/shell/sidebar.cjs +390 -0
  143. package/dist/shell/sidebar.cjs.map +1 -0
  144. package/dist/shell/sidebar.d.cts +85 -0
  145. package/dist/shell/sidebar.d.cts.map +1 -0
  146. package/dist/shell/sidebar.d.mts +85 -0
  147. package/dist/shell/sidebar.d.mts.map +1 -0
  148. package/dist/shell/sidebar.mjs +364 -0
  149. package/dist/shell/sidebar.mjs.map +1 -0
  150. package/dist/shell/use-mobile.cjs +51 -0
  151. package/dist/shell/use-mobile.cjs.map +1 -0
  152. package/dist/shell/use-mobile.d.cts +7 -0
  153. package/dist/shell/use-mobile.d.cts.map +1 -0
  154. package/dist/shell/use-mobile.d.mts +7 -0
  155. package/dist/shell/use-mobile.d.mts.map +1 -0
  156. package/dist/shell/use-mobile.mjs +47 -0
  157. package/dist/shell/use-mobile.mjs.map +1 -0
  158. package/dist/theme/index.cjs +758 -0
  159. package/dist/theme/index.cjs.map +1 -0
  160. package/dist/theme/index.d.cts +131 -0
  161. package/dist/theme/index.d.cts.map +1 -0
  162. package/dist/theme/index.d.mts +131 -0
  163. package/dist/theme/index.d.mts.map +1 -0
  164. package/dist/theme/index.mjs +728 -0
  165. package/dist/theme/index.mjs.map +1 -0
  166. package/dist/types/index.cjs +18 -0
  167. package/dist/types/index.d.cts +4 -0
  168. package/dist/types/index.d.mts +4 -0
  169. package/dist/types/index.mjs +2 -0
  170. package/dist/types-27AHMek-.d.cts +85 -0
  171. package/dist/types-27AHMek-.d.cts.map +1 -0
  172. package/dist/types-BXFX9bXp.cjs +303 -0
  173. package/dist/types-BXFX9bXp.cjs.map +1 -0
  174. package/dist/types-Bjmd7Fdx.mjs +208 -0
  175. package/dist/types-Bjmd7Fdx.mjs.map +1 -0
  176. package/dist/types-C5Zs5V3E.d.mts +155 -0
  177. package/dist/types-C5Zs5V3E.d.mts.map +1 -0
  178. package/dist/types-CeCPKvOv.d.mts +85 -0
  179. package/dist/types-CeCPKvOv.d.mts.map +1 -0
  180. package/dist/types-DrzvahW8.d.cts +155 -0
  181. package/dist/types-DrzvahW8.d.cts.map +1 -0
  182. package/dist/widget-schema-BKZgsNG7.d.mts +119 -0
  183. package/dist/widget-schema-BKZgsNG7.d.mts.map +1 -0
  184. package/dist/widget-schema-BSX2fVhW.d.cts +119 -0
  185. package/dist/widget-schema-BSX2fVhW.d.cts.map +1 -0
  186. package/dist/widget-utils/index.cjs +130 -0
  187. package/dist/widget-utils/index.cjs.map +1 -0
  188. package/dist/widget-utils/index.d.cts +47 -0
  189. package/dist/widget-utils/index.d.cts.map +1 -0
  190. package/dist/widget-utils/index.d.mts +47 -0
  191. package/dist/widget-utils/index.d.mts.map +1 -0
  192. package/dist/widget-utils/index.mjs +119 -0
  193. package/dist/widget-utils/index.mjs.map +1 -0
  194. package/package.json +200 -0
  195. package/src/styles/globals.css +1 -0
@@ -0,0 +1,728 @@
1
+ import Color from "colorjs.io";
2
+ //#region src/theme/types.ts
3
+ const SEMANTIC_COLOR_NAMES = [
4
+ "background",
5
+ "foreground",
6
+ "primary",
7
+ "secondary",
8
+ "accent",
9
+ "muted",
10
+ "destructive"
11
+ ];
12
+ const SHADE_STEPS = [
13
+ 100,
14
+ 200,
15
+ 300,
16
+ 400,
17
+ 500,
18
+ 600,
19
+ 700,
20
+ 800,
21
+ 900
22
+ ];
23
+ const FONT_SIZE_KEYS = [
24
+ "extraSmall",
25
+ "small",
26
+ "regular",
27
+ "large",
28
+ "extraLarge",
29
+ "giant"
30
+ ];
31
+ const FONT_FAMILY_KEYS = ["header", "body"];
32
+ const RADIUS_KEYS = [
33
+ "small",
34
+ "medium",
35
+ "large",
36
+ "extraLarge"
37
+ ];
38
+ //#endregion
39
+ //#region src/theme/color-engine.ts
40
+ /**
41
+ * Attempt to convert any string into a Color using colorjs.io.
42
+ * If the string is exactly 6 characters it is assumed to be a bare hex value
43
+ * (e.g. "3b82f6") and a "#" prefix is added before parsing.
44
+ *
45
+ * @returns the parsed Color, or a neutral gray (`oklch(0.5 0 0)`) on failure
46
+ */
47
+ function parseColor(value) {
48
+ if (value.length === 6) value = `#${value}`;
49
+ try {
50
+ return new Color(value);
51
+ } catch (error) {
52
+ console.warn("[theme] Failed to parse color:", value, error);
53
+ return new Color("oklch", [
54
+ .5,
55
+ 0,
56
+ 0
57
+ ]);
58
+ }
59
+ }
60
+ /**
61
+ * Returns either the original foreground or a corrected lightness variant,
62
+ * whichever provides better contrast against `color`.
63
+ * Inversion triggers when the APCA contrast is below 50.
64
+ */
65
+ function getForegroundColor(foreground, color) {
66
+ if (foreground.oklch.l == null || color.oklch.l == null) return foreground;
67
+ if (color.contrastAPCA(foreground) < 50) return new Color("oklch", [
68
+ color.oklch.l < .7 ? .95 : .15,
69
+ foreground.oklch.c || 0,
70
+ foreground.oklch.h || 0
71
+ ]);
72
+ return foreground;
73
+ }
74
+ /**
75
+ * Generate a 100–900 shade ramp from a base color.
76
+ * Base anchors at 500. Light shades (100–400) step toward white,
77
+ * dark shades (600–900) step toward black. Dark steps use an asymmetric
78
+ * multiplier (1.6×, 1.875×, 3×, 4× of `darkStep`) for a more gradual
79
+ * initial descent. Chroma is nudged per step for perceptually natural ramps.
80
+ */
81
+ function generateShades(base) {
82
+ const l = base.oklch.l ?? 0;
83
+ const c = base.oklch.c ?? 0;
84
+ const h = base.oklch.h ?? 0;
85
+ const safeMax = l >= .885 ? .995 : .97;
86
+ const safeMin = l <= .33 ? 0 : .21;
87
+ const lightStep = (safeMax - l) / 5;
88
+ const darkStep = -(l - safeMin) / 8;
89
+ const shade = (lDelta, cDelta) => {
90
+ return new Color("oklch", [
91
+ Math.max(0, Math.min(1, l + lDelta)),
92
+ c <= .001 ? c : Math.max(0, c + cDelta),
93
+ h
94
+ ]);
95
+ };
96
+ return {
97
+ 100: shade(5 * lightStep, -.00375),
98
+ 200: shade(4 * lightStep, -.00375),
99
+ 300: shade(3 * lightStep, -.00375),
100
+ 400: shade(2 * lightStep, -.00375),
101
+ 500: new Color("oklch", [
102
+ l,
103
+ c,
104
+ h
105
+ ]),
106
+ 600: shade(1.6 * darkStep, .025),
107
+ 700: shade(1.875 * 2 * darkStep, .05),
108
+ 800: shade(6 * darkStep, .075),
109
+ 900: shade(8 * darkStep, .1)
110
+ };
111
+ }
112
+ const DARK_DERIVATION_CONFIG = {
113
+ background: {
114
+ baseLightness: .15,
115
+ fgLightness: .93
116
+ },
117
+ foreground: {
118
+ baseLightness: .93,
119
+ fgLightness: .15
120
+ },
121
+ muted: {
122
+ baseLightness: .22,
123
+ fgLightness: .75
124
+ },
125
+ primary: {
126
+ baseLightness: "invert",
127
+ fgLightness: .95,
128
+ chromaScale: .9
129
+ },
130
+ secondary: {
131
+ baseLightness: "invert",
132
+ fgLightness: .93,
133
+ chromaScale: .85
134
+ },
135
+ accent: {
136
+ baseLightness: "invert",
137
+ fgLightness: .95,
138
+ chromaScale: .9
139
+ },
140
+ destructive: {
141
+ baseLightness: "invert",
142
+ fgLightness: .95,
143
+ chromaScale: .95
144
+ }
145
+ };
146
+ /** Invert OKLCH lightness (1 - l), clamped to [0.35, 0.75] to avoid extremes. */
147
+ function invertLightness(l) {
148
+ const inverted = 1 - l;
149
+ return Math.max(.35, Math.min(.75, inverted));
150
+ }
151
+ /**
152
+ * Derive a dark-mode ThemeColorInput from its light-mode counterpart.
153
+ */
154
+ function deriveDarkVariant(name, light) {
155
+ const config = DARK_DERIVATION_CONFIG[name];
156
+ const chromaScale = config.chromaScale ?? 1;
157
+ const baseLightness = config.baseLightness === "invert" ? invertLightness(light.base.oklch.l ?? 0) : config.baseLightness;
158
+ const fgLightness = config.fgLightness === "invert" ? invertLightness(light.foreground.oklch.l ?? 0) : config.fgLightness;
159
+ return {
160
+ base: new Color("oklch", [
161
+ baseLightness,
162
+ (light.base.oklch.c || 0) * chromaScale,
163
+ light.base.oklch.h || 0
164
+ ]),
165
+ foreground: new Color("oklch", [
166
+ fgLightness,
167
+ (light.foreground.oklch.c || 0) * chromaScale,
168
+ light.foreground.oklch.h || 0
169
+ ])
170
+ };
171
+ }
172
+ /**
173
+ * Merge auto-derived dark colors with any user-specified overrides.
174
+ * For each semantic color, if the user has fully overridden both base and
175
+ * foreground those are used; otherwise the missing channels are derived.
176
+ */
177
+ function mergeDarkOverrides(def) {
178
+ const darkColors = {};
179
+ for (const name of SEMANTIC_COLOR_NAMES) {
180
+ const lightInput = def.light[name];
181
+ const darkOverride = def.dark[name];
182
+ if (darkOverride?.base && darkOverride?.foreground) darkColors[name] = darkOverride;
183
+ else if (darkOverride) {
184
+ const base = darkOverride.base ?? deriveDarkVariant(name, lightInput).base;
185
+ darkColors[name] = {
186
+ base,
187
+ foreground: darkOverride.foreground ?? getForegroundColor(def.light.foreground.base, base)
188
+ };
189
+ } else darkColors[name] = deriveDarkVariant(name, lightInput);
190
+ }
191
+ return darkColors;
192
+ }
193
+ function resolveColorSet(colors) {
194
+ const resolved = {};
195
+ for (const name of SEMANTIC_COLOR_NAMES) {
196
+ const input = colors[name];
197
+ const shades = generateShades(input.base);
198
+ const resolvedShades = {};
199
+ for (const step of SHADE_STEPS) resolvedShades[step] = shades[step];
200
+ resolved[name] = {
201
+ base: input.base.clone(),
202
+ foreground: input.foreground.clone(),
203
+ shades: resolvedShades
204
+ };
205
+ }
206
+ return resolved;
207
+ }
208
+ /**
209
+ * Resolve a ThemeDefinition into a complete ResolvedTheme.
210
+ * Dark mode colors are derived from light where not overridden.
211
+ */
212
+ function resolveTheme(def) {
213
+ return {
214
+ id: def.id,
215
+ name: def.name,
216
+ light: resolveColorSet(def.light),
217
+ dark: resolveColorSet(mergeDarkOverrides(def)),
218
+ fontSizes: { ...def.fontSizes },
219
+ fontFamilies: { ...def.fontFamilies },
220
+ spacing: def.spacing,
221
+ radii: { ...def.radii }
222
+ };
223
+ }
224
+ //#endregion
225
+ //#region src/theme/tailwind-overrides.ts
226
+ /**
227
+ * Specific overrides, otherwise all the overrides are generated using emitTailwindOverrides
228
+ */
229
+ const OVERRIDES = {
230
+ "--color-gray-50": "var(--color-muted)",
231
+ "--color-gray-100": "var(--color-muted-600)",
232
+ "--color-gray-200": "var(--color-border)"
233
+ };
234
+ /**
235
+ * Returns the inverted shade for dark mode foreground colors.
236
+ * In dark mode, light shades (50, 100) should map to dark values (950, 900) and vice versa.
237
+ */
238
+ function getInvertedStep(shade) {
239
+ const shadeIndex = SHADE_STEPS.indexOf(shade);
240
+ return SHADE_STEPS[SHADE_STEPS.length - 1 - shadeIndex] || 500;
241
+ }
242
+ /**
243
+ * Map semantic colors to Tailwind built-in color names.
244
+ */
245
+ function emitTailwindOverrides(darkMode = false) {
246
+ const TAILWIND_COLOR_MAP = {
247
+ gray: "foreground",
248
+ red: "destructive",
249
+ blue: "primary",
250
+ green: "accent"
251
+ };
252
+ const TAILWIND_SHADES = [
253
+ 50,
254
+ 100,
255
+ 200,
256
+ 300,
257
+ 400,
258
+ 500,
259
+ 600,
260
+ 700,
261
+ 800,
262
+ 900,
263
+ 950
264
+ ];
265
+ const SHADE_REMAP = {
266
+ 50: 100,
267
+ 950: 900
268
+ };
269
+ const lines = [];
270
+ for (const [twName, semantic] of Object.entries(TAILWIND_COLOR_MAP)) for (const shade of TAILWIND_SHADES) {
271
+ const step = SHADE_REMAP[shade] ?? shade;
272
+ const override = OVERRIDES[`--color-${twName}-${shade}`];
273
+ lines.push(`--color-${twName}-${shade}: ${override ? override : `var(--color-${semantic}-${semantic === "foreground" && darkMode === true ? getInvertedStep(step) : step})`};`);
274
+ }
275
+ lines.push("--color-white: var(--color-background);");
276
+ lines.push("--color-black: var(--color-foreground);");
277
+ return lines;
278
+ }
279
+ //#endregion
280
+ //#region src/theme/css-generator.ts
281
+ function colorToCSS(color) {
282
+ const result = color.toString({ format: "oklch" });
283
+ if (result.includes("NaN")) {
284
+ console.warn("[theme] colorToCSS produced NaN, using neutral fallback:", result);
285
+ return "oklch(0.5 0 0)";
286
+ }
287
+ return result;
288
+ }
289
+ function camelToKebab(str) {
290
+ return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
291
+ }
292
+ /**
293
+ * Emit --color-{name}, --color-{name}-foreground, --color-{name}-{shade} vars.
294
+ * Uses --color- prefix to match portal-widgets/tailwind.config.ts.
295
+ */
296
+ function emitColorVars(colors) {
297
+ const lines = [];
298
+ for (const name of SEMANTIC_COLOR_NAMES) {
299
+ const color = colors[name];
300
+ lines.push(`--color-${name}: ${colorToCSS(color.base)};`);
301
+ lines.push(`--color-${name}-foreground: ${colorToCSS(color.foreground)};`);
302
+ for (const step of SHADE_STEPS) lines.push(`--color-${name}-${step}: ${colorToCSS(color.shades[step])};`);
303
+ }
304
+ return lines;
305
+ }
306
+ /**
307
+ * Emit non-color CSS variables (font sizes, families, spacing, radii).
308
+ */
309
+ function emitNonColorVars(theme) {
310
+ const lines = [];
311
+ for (const key of FONT_SIZE_KEYS) lines.push(`--font-size-${camelToKebab(key)}: ${theme.fontSizes[key]};`);
312
+ for (const key of FONT_FAMILY_KEYS) lines.push(`--font-${key}: ${theme.fontFamilies[key]};`);
313
+ lines.push(`--spacing: ${theme.spacing};`);
314
+ for (const key of RADIUS_KEYS) lines.push(`--radius-${camelToKebab(key)}: ${theme.radii[key]};`);
315
+ return lines;
316
+ }
317
+ /**
318
+ * Static CSS alias variables that bridge theme var names to Tailwind/component conventions.
319
+ * These are always emitted and not mode-dependent.
320
+ */
321
+ const globalCSSOverride = [
322
+ "--color-background-foreground: var(--color-foreground);",
323
+ "--color-foreground-foreground: var(--color-background);",
324
+ "--color-contrast: var(--color-foreground);",
325
+ ...SEMANTIC_COLOR_NAMES.map((value) => `--${value}: var(--color-${value});`),
326
+ ...SEMANTIC_COLOR_NAMES.map((value) => `--${value}-foreground: var(--color-${value}-foreground);`),
327
+ "--sidebar-ring: var(--color-primary);",
328
+ "--sidebar-border: var(--color-border);",
329
+ "--sidebar-accent-foreground: var(--color-accent-foreground);",
330
+ "--sidebar-accent: var(--color-accent);",
331
+ "--sidebar-primary-foreground: var(--color-primary-foreground);",
332
+ "--sidebar-primary: var(--color-primary);",
333
+ "--sidebar-foreground: var(--color-muted-foreground);",
334
+ "--sidebar: var(--color-muted);",
335
+ "--border: var(--color-background-600);",
336
+ "--ring: var(--color-primary);",
337
+ "--popover: var(--color-background);",
338
+ "--popover-foreground: var(--color-foreground);",
339
+ "--card: var(--color-muted);",
340
+ "--card-foreground: var(--color-muted-foreground);",
341
+ "--radius-sm: var(--radius-small);",
342
+ "--radius-md: var(--radius-medium);",
343
+ "--radius-lg: var(--radius-large);",
344
+ "--radius-xl: var(--radius-extra-large);",
345
+ "--text-xs: var(--font-size-extra-small);",
346
+ "--text-sm: var(--font-size-small);",
347
+ "--text-base: var(--font-size-regular);",
348
+ "--text-lg: var(--font-size-large);",
349
+ "--text-xl: var(--font-size-extra-large);",
350
+ "--text-2xl: var(--font-size-giant);",
351
+ "--font-sans: var(--font-body);",
352
+ "--font-mono: var(--font-header);"
353
+ ];
354
+ /**
355
+ * Overrides for global tailwindcss for specifically dark mode.
356
+ */
357
+ const globalDarkCSSOverride = ["--border: var(--color-background-400);"];
358
+ /**
359
+ * Generate a complete CSS string for a resolved theme.
360
+ * Outputs 2–3 blocks: light default, dark explicit via `[data-theme-mode="dark"]`,
361
+ * and (unless `disableAutoTheme`) a `prefers-color-scheme: dark` media query block.
362
+ */
363
+ function generateThemeCSS(theme, options = {}) {
364
+ const sel = `[data-theme="${theme.id}"]`;
365
+ const tw = options.mapTailwindColors ?? true;
366
+ const blocks = [];
367
+ blocks.push(`${sel} {`);
368
+ blocks.push(...globalCSSOverride);
369
+ blocks.push(...emitNonColorVars(theme));
370
+ blocks.push(...emitColorVars(theme.light));
371
+ if (tw) blocks.push(...emitTailwindOverrides());
372
+ blocks.push(`}`);
373
+ blocks.push(`${sel}[data-theme-mode="dark"] {`);
374
+ blocks.push(...globalDarkCSSOverride);
375
+ blocks.push(...emitColorVars(theme.dark));
376
+ if (tw) blocks.push(...emitTailwindOverrides(true));
377
+ blocks.push(`}`);
378
+ if (!options.disableAutoTheme) {
379
+ blocks.push(`@media (prefers-color-scheme: dark) {`);
380
+ blocks.push(`${sel}:not([data-theme-mode]) {`);
381
+ blocks.push(...globalDarkCSSOverride);
382
+ blocks.push(...emitColorVars(theme.dark).map((l) => `${l}`));
383
+ if (tw) blocks.push(...emitTailwindOverrides(true).map((l) => `${l}`));
384
+ blocks.push(`}`);
385
+ blocks.push(`}`);
386
+ }
387
+ return blocks.join("\n");
388
+ }
389
+ //#endregion
390
+ //#region src/theme/defaults.ts
391
+ const DEFAULT_FONT_SIZES = {
392
+ extraSmall: "0.75rem",
393
+ small: "0.875rem",
394
+ regular: "1rem",
395
+ large: "1.125rem",
396
+ extraLarge: "1.25rem",
397
+ giant: "1.5rem"
398
+ };
399
+ const DEFAULT_FONT_FAMILIES = {
400
+ header: "var(--font-inter)",
401
+ body: "var(--font-inter)"
402
+ };
403
+ const DEFAULT_SPACING = "0.25rem";
404
+ const DEFAULT_RADII = {
405
+ small: "0.25rem",
406
+ medium: "0.5rem",
407
+ large: "0.75rem",
408
+ extraLarge: "1rem"
409
+ };
410
+ const DEFAULT_COLORS = {
411
+ background: "#ffffff",
412
+ foreground: "#1a1a1a",
413
+ primary: "#3b82f6",
414
+ secondary: "#6b7280",
415
+ accent: "#10b981",
416
+ muted: "#f3f4f6",
417
+ destructive: "#ef4444",
418
+ mutedForeground: "#6b7280"
419
+ };
420
+ const DEFAULT_THEME_ID = "default";
421
+ const DEFAULT_THEME_NAME = "Default Theme";
422
+ /**
423
+ * Build a fresh ThemeDefinition populated with all defaults.
424
+ * Returns a new object each call because Color instances are mutable — do not cache the result.
425
+ */
426
+ function getDefaultThemeDefinition() {
427
+ const bg = new Color(DEFAULT_COLORS.background);
428
+ const fg = new Color(DEFAULT_COLORS.foreground);
429
+ const primary = new Color(DEFAULT_COLORS.primary);
430
+ const secondary = new Color(DEFAULT_COLORS.secondary);
431
+ const accent = new Color(DEFAULT_COLORS.accent);
432
+ const muted = new Color(DEFAULT_COLORS.muted);
433
+ const destructive = new Color(DEFAULT_COLORS.destructive);
434
+ const mutedFg = new Color(DEFAULT_COLORS.mutedForeground);
435
+ const darkBg = new Color("#0a0a0a");
436
+ const darkFg = new Color("#fafafa");
437
+ const darkMuted = new Color("#171717");
438
+ const darkMutedForeground = new Color("#dddddd");
439
+ return {
440
+ id: DEFAULT_THEME_ID,
441
+ name: DEFAULT_THEME_NAME,
442
+ light: {
443
+ background: {
444
+ base: bg,
445
+ foreground: fg
446
+ },
447
+ foreground: {
448
+ base: fg,
449
+ foreground: bg
450
+ },
451
+ primary: {
452
+ base: primary,
453
+ foreground: getForegroundColor(fg, primary)
454
+ },
455
+ secondary: {
456
+ base: secondary,
457
+ foreground: getForegroundColor(fg, secondary)
458
+ },
459
+ accent: {
460
+ base: accent,
461
+ foreground: getForegroundColor(fg, accent)
462
+ },
463
+ muted: {
464
+ base: muted,
465
+ foreground: mutedFg
466
+ },
467
+ destructive: {
468
+ base: destructive,
469
+ foreground: getForegroundColor(fg, destructive)
470
+ }
471
+ },
472
+ dark: {
473
+ background: {
474
+ base: darkBg,
475
+ foreground: darkFg
476
+ },
477
+ foreground: {
478
+ base: darkFg,
479
+ foreground: darkBg
480
+ },
481
+ muted: {
482
+ base: darkMuted,
483
+ foreground: darkMutedForeground
484
+ }
485
+ },
486
+ fontSizes: { ...DEFAULT_FONT_SIZES },
487
+ fontFamilies: { ...DEFAULT_FONT_FAMILIES },
488
+ spacing: DEFAULT_SPACING,
489
+ radii: { ...DEFAULT_RADII }
490
+ };
491
+ }
492
+ //#endregion
493
+ //#region src/theme/serialisation.ts
494
+ function colorToPlain(color) {
495
+ return {
496
+ l: color.oklch.l ?? 0,
497
+ c: color.oklch.c ?? 0,
498
+ h: color.oklch.h ?? 0
499
+ };
500
+ }
501
+ function plainToColor(plain) {
502
+ return new Color("oklch", [
503
+ plain.l,
504
+ plain.c,
505
+ plain.h
506
+ ]);
507
+ }
508
+ /**
509
+ * Serialise a ThemeDefinition (with Color objects) to a plain JSON payload
510
+ * suitable for backend storage.
511
+ */
512
+ function serialiseTheme(def) {
513
+ const light = {};
514
+ for (const name of SEMANTIC_COLOR_NAMES) light[name] = {
515
+ base: colorToPlain(def.light[name].base),
516
+ foreground: colorToPlain(def.light[name].foreground)
517
+ };
518
+ const dark = {};
519
+ for (const [name, value] of Object.entries(def.dark)) {
520
+ if (!value) continue;
521
+ dark[name] = {
522
+ ...value.base ? { base: colorToPlain(value.base) } : {},
523
+ ...value.foreground ? { foreground: colorToPlain(value.foreground) } : {}
524
+ };
525
+ }
526
+ return {
527
+ id: def.id,
528
+ name: def.name,
529
+ light,
530
+ dark,
531
+ fontSizes: { ...def.fontSizes },
532
+ fontFamilies: { ...def.fontFamilies },
533
+ spacing: def.spacing,
534
+ radii: { ...def.radii },
535
+ ...def.syncWithBrandColors ? { syncWithBrandColors: true } : {}
536
+ };
537
+ }
538
+ /**
539
+ * Deserialise a backend payload into a ThemeDefinition with Color objects.
540
+ * Accepts `Record<string, unknown>` because API data is untyped at the boundary.
541
+ * Falls back to default colors for any missing light-mode entries.
542
+ */
543
+ function deserialiseTheme(payload) {
544
+ const lightRaw = payload.light ?? {};
545
+ const darkRaw = payload.dark ?? {};
546
+ const defaults = getDefaultThemeDefinition();
547
+ const light = {};
548
+ for (const name of SEMANTIC_COLOR_NAMES) {
549
+ const entry = lightRaw[name];
550
+ if (entry) light[name] = {
551
+ base: plainToColor(entry.base),
552
+ foreground: plainToColor(entry.foreground)
553
+ };
554
+ else {
555
+ console.warn(`[theme] deserialiseTheme: missing light color "${name}", using default`);
556
+ light[name] = defaults.light[name];
557
+ }
558
+ }
559
+ const dark = {};
560
+ for (const [name, value] of Object.entries(darkRaw)) {
561
+ if (!value) continue;
562
+ dark[name] = {
563
+ ...value.base ? { base: plainToColor(value.base) } : {},
564
+ ...value.foreground ? { foreground: plainToColor(value.foreground) } : {}
565
+ };
566
+ }
567
+ return {
568
+ id: payload.id,
569
+ name: payload.name,
570
+ light,
571
+ dark,
572
+ fontSizes: payload.fontSizes ?? DEFAULT_FONT_SIZES,
573
+ fontFamilies: payload.fontFamilies ?? DEFAULT_FONT_FAMILIES,
574
+ spacing: payload.spacing ?? "0.25rem",
575
+ radii: payload.radii ?? DEFAULT_RADII,
576
+ ...payload.syncWithBrandColors === true ? { syncWithBrandColors: true } : {}
577
+ };
578
+ }
579
+ //#endregion
580
+ //#region src/theme/transforms.ts
581
+ /**
582
+ * Check if a theme config uses the new structured format (has a `light` key
583
+ * that is an object) vs the legacy flat format.
584
+ */
585
+ function isNewThemeFormat(config) {
586
+ return config.light != null && typeof config.light === "object";
587
+ }
588
+ /**
589
+ * Convert a legacy flat config to a ThemeDefinition.
590
+ * Legacy format: { base: "#fff", text: "#000", primary: "oklch(0.6 0.2 250)", ... }
591
+ */
592
+ function legacyConfigToDefinition(id, name, config) {
593
+ const bg = parseColor(config.base ?? config.background ?? DEFAULT_COLORS.background);
594
+ const fg = parseColor(config.text ?? config.foreground ?? DEFAULT_COLORS.foreground);
595
+ const primary = parseColor(config.primary ?? DEFAULT_COLORS.primary);
596
+ const secondary = parseColor(config.secondary ?? DEFAULT_COLORS.secondary);
597
+ const accent = parseColor(config.accent ?? DEFAULT_COLORS.accent);
598
+ const muted = parseColor(config.muted ?? DEFAULT_COLORS.muted);
599
+ const destructive = parseColor(config.destructive ?? DEFAULT_COLORS.destructive);
600
+ const mutedFg = parseColor(config.mutedForeground ?? DEFAULT_COLORS.mutedForeground);
601
+ return {
602
+ id: String(id),
603
+ name,
604
+ light: {
605
+ background: {
606
+ base: bg,
607
+ foreground: fg
608
+ },
609
+ foreground: {
610
+ base: fg,
611
+ foreground: bg
612
+ },
613
+ primary: {
614
+ base: primary,
615
+ foreground: getForegroundColor(fg, primary)
616
+ },
617
+ secondary: {
618
+ base: secondary,
619
+ foreground: getForegroundColor(fg, secondary)
620
+ },
621
+ accent: {
622
+ base: accent,
623
+ foreground: getForegroundColor(fg, accent)
624
+ },
625
+ muted: {
626
+ base: muted,
627
+ foreground: mutedFg
628
+ },
629
+ destructive: {
630
+ base: destructive,
631
+ foreground: getForegroundColor(fg, destructive)
632
+ }
633
+ },
634
+ dark: {},
635
+ fontSizes: {
636
+ extraSmall: config.extraSmall ?? DEFAULT_FONT_SIZES.extraSmall,
637
+ small: config.small ?? DEFAULT_FONT_SIZES.small,
638
+ regular: config.regular ?? DEFAULT_FONT_SIZES.regular,
639
+ large: config.large ?? DEFAULT_FONT_SIZES.large,
640
+ extraLarge: config.extraLarge ?? DEFAULT_FONT_SIZES.extraLarge,
641
+ giant: config.giant ?? DEFAULT_FONT_SIZES.giant
642
+ },
643
+ fontFamilies: {
644
+ header: config.headerFont ?? DEFAULT_FONT_FAMILIES.header,
645
+ body: config.bodyFont ?? DEFAULT_FONT_FAMILIES.body
646
+ },
647
+ spacing: config.globalSpacing ?? "0.25rem",
648
+ radii: {
649
+ small: config.radiusSmall ?? DEFAULT_RADII.small,
650
+ medium: config.radiusMedium ?? DEFAULT_RADII.medium,
651
+ large: config.radiusLarge ?? DEFAULT_RADII.large,
652
+ extraLarge: config.radiusExtraLarge ?? DEFAULT_RADII.extraLarge
653
+ }
654
+ };
655
+ }
656
+ /**
657
+ * Build a ThemeDefinition from a single API theme object.
658
+ * Handles both new structured format and legacy flat format.
659
+ */
660
+ function buildThemeDefinition(theme) {
661
+ const config = theme.config ?? {};
662
+ if (isNewThemeFormat(config)) return deserialiseTheme({
663
+ ...config,
664
+ id: String(theme.id),
665
+ name: theme.name ?? "Untitled Theme"
666
+ });
667
+ return legacyConfigToDefinition(theme.id, theme.name ?? "Untitled Theme", config);
668
+ }
669
+ /**
670
+ * Transform raw API themes to ThemeDefinition[].
671
+ * Catches and logs errors per theme (graceful degradation).
672
+ */
673
+ function transformThemes(themes) {
674
+ return themes.flatMap((theme) => {
675
+ try {
676
+ return [buildThemeDefinition(theme)];
677
+ } catch (error) {
678
+ console.error(`[theme] Failed to build theme id=${theme.id}:`, error);
679
+ return [];
680
+ }
681
+ });
682
+ }
683
+ /**
684
+ * Get the active theme ID from a list of raw API themes.
685
+ * Falls back to the first theme if none is marked active.
686
+ */
687
+ function getActiveThemeId(themes) {
688
+ const active = themes.find((t) => t.active) ?? themes[0];
689
+ return active ? String(active.id) : void 0;
690
+ }
691
+ //#endregion
692
+ //#region src/theme/theme-applicator.ts
693
+ const STYLE_PREFIX = "theme-style-";
694
+ /**
695
+ * Inject or update a `<style>` element in `<head>` for the given theme.
696
+ * The element ID is deterministic (`theme-style-{themeId}`) so repeated calls
697
+ * for the same theme are idempotent — the existing element is updated in place.
698
+ * No-op when `document` is unavailable (SSR).
699
+ */
700
+ function applyTheme(theme, options) {
701
+ if (typeof document === "undefined") return;
702
+ try {
703
+ const styleId = `${STYLE_PREFIX}${theme.id}`;
704
+ let el = document.getElementById(styleId);
705
+ if (!el) {
706
+ el = document.createElement("style");
707
+ el.id = styleId;
708
+ document.head.appendChild(el);
709
+ }
710
+ el.textContent = generateThemeCSS(theme, options);
711
+ } catch (error) {
712
+ console.error(`[theme] applyTheme failed for "${theme.id}":`, error);
713
+ }
714
+ }
715
+ /** Remove an injected theme stylesheet. No-op during SSR. */
716
+ function removeTheme(themeId) {
717
+ if (typeof document === "undefined") return;
718
+ document.getElementById(`${STYLE_PREFIX}${themeId}`)?.remove();
719
+ }
720
+ /** Remove all injected theme stylesheets. No-op during SSR. */
721
+ function removeAllThemes() {
722
+ if (typeof document === "undefined") return;
723
+ document.querySelectorAll(`style[id^="${STYLE_PREFIX}"]`).forEach((el) => el.remove());
724
+ }
725
+ //#endregion
726
+ export { DEFAULT_COLORS, DEFAULT_FONT_FAMILIES, DEFAULT_FONT_SIZES, DEFAULT_RADII, DEFAULT_SPACING, DEFAULT_THEME_ID, DEFAULT_THEME_NAME, FONT_FAMILY_KEYS, FONT_SIZE_KEYS, RADIUS_KEYS, SEMANTIC_COLOR_NAMES, SHADE_STEPS, applyTheme, buildThemeDefinition, deriveDarkVariant, deserialiseTheme, generateShades, generateThemeCSS, getActiveThemeId, getDefaultThemeDefinition, getForegroundColor, mergeDarkOverrides, parseColor, removeAllThemes, removeTheme, resolveTheme, serialiseTheme, transformThemes };
727
+
728
+ //# sourceMappingURL=index.mjs.map