@fluid-app/rep-core 0.1.14 → 0.1.15

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