@just-web/toolkits 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (263) hide show
  1. package/dist/attributes/get-attribute.cjs +1 -1
  2. package/dist/attributes/get-attribute.cjs.map +1 -1
  3. package/dist/attributes/get-attribute.d.cts +2 -2
  4. package/dist/attributes/get-attribute.d.cts.map +1 -1
  5. package/dist/attributes/get-attribute.d.mts +2 -2
  6. package/dist/attributes/get-attribute.d.mts.map +1 -1
  7. package/dist/attributes/get-attribute.mjs +1 -1
  8. package/dist/attributes/get-attribute.mjs.map +1 -1
  9. package/dist/attributes/get-data-attribute.cjs +1 -1
  10. package/dist/attributes/get-data-attribute.cjs.map +1 -1
  11. package/dist/attributes/get-data-attribute.d.cts +2 -2
  12. package/dist/attributes/get-data-attribute.d.cts.map +1 -1
  13. package/dist/attributes/get-data-attribute.d.mts +2 -2
  14. package/dist/attributes/get-data-attribute.d.mts.map +1 -1
  15. package/dist/attributes/get-data-attribute.mjs +1 -1
  16. package/dist/attributes/get-data-attribute.mjs.map +1 -1
  17. package/dist/attributes/observe-attribute.cjs +11 -8
  18. package/dist/attributes/observe-attribute.cjs.map +1 -1
  19. package/dist/attributes/observe-attribute.d.cts +7 -7
  20. package/dist/attributes/observe-attribute.d.cts.map +1 -1
  21. package/dist/attributes/observe-attribute.d.mts +7 -7
  22. package/dist/attributes/observe-attribute.d.mts.map +1 -1
  23. package/dist/attributes/observe-attribute.mjs +11 -8
  24. package/dist/attributes/observe-attribute.mjs.map +1 -1
  25. package/dist/attributes/observe-data-attribute.cjs +7 -10
  26. package/dist/attributes/observe-data-attribute.cjs.map +1 -1
  27. package/dist/attributes/observe-data-attribute.d.cts +8 -11
  28. package/dist/attributes/observe-data-attribute.d.cts.map +1 -1
  29. package/dist/attributes/observe-data-attribute.d.mts +8 -11
  30. package/dist/attributes/observe-data-attribute.d.mts.map +1 -1
  31. package/dist/attributes/observe-data-attribute.mjs +7 -10
  32. package/dist/attributes/observe-data-attribute.mjs.map +1 -1
  33. package/dist/color-scheme/color-scheme.types.d.cts +11 -0
  34. package/dist/color-scheme/color-scheme.types.d.cts.map +1 -0
  35. package/dist/color-scheme/color-scheme.types.d.mts +11 -0
  36. package/dist/color-scheme/color-scheme.types.d.mts.map +1 -0
  37. package/dist/color-scheme/get-prefers-color-scheme.cjs +3 -1
  38. package/dist/color-scheme/get-prefers-color-scheme.cjs.map +1 -1
  39. package/dist/color-scheme/get-prefers-color-scheme.d.cts +7 -2
  40. package/dist/color-scheme/get-prefers-color-scheme.d.cts.map +1 -1
  41. package/dist/color-scheme/get-prefers-color-scheme.d.mts +7 -2
  42. package/dist/color-scheme/get-prefers-color-scheme.d.mts.map +1 -1
  43. package/dist/color-scheme/get-prefers-color-scheme.mjs +3 -1
  44. package/dist/color-scheme/get-prefers-color-scheme.mjs.map +1 -1
  45. package/dist/color-scheme/observe-prefers-color-scheme.cjs.map +1 -1
  46. package/dist/color-scheme/observe-prefers-color-scheme.d.cts +4 -1
  47. package/dist/color-scheme/observe-prefers-color-scheme.d.cts.map +1 -1
  48. package/dist/color-scheme/observe-prefers-color-scheme.d.mts +4 -1
  49. package/dist/color-scheme/observe-prefers-color-scheme.d.mts.map +1 -1
  50. package/dist/color-scheme/observe-prefers-color-scheme.mjs.map +1 -1
  51. package/dist/index.d.cts +2 -1
  52. package/dist/index.d.mts +2 -1
  53. package/dist/react/hooks/use-attribute.cjs +8 -9
  54. package/dist/react/hooks/use-attribute.cjs.map +1 -1
  55. package/dist/react/hooks/use-attribute.d.cts +4 -4
  56. package/dist/react/hooks/use-attribute.d.mts +4 -4
  57. package/dist/react/hooks/use-attribute.mjs +8 -9
  58. package/dist/react/hooks/use-attribute.mjs.map +1 -1
  59. package/dist/react/hooks/use-theme-by-class-name.cjs +1 -1
  60. package/dist/react/hooks/use-theme-by-class-name.cjs.map +1 -1
  61. package/dist/react/hooks/use-theme-by-class-name.d.cts +2 -2
  62. package/dist/react/hooks/use-theme-by-class-name.d.mts +2 -2
  63. package/dist/react/hooks/use-theme-by-class-name.mjs +1 -1
  64. package/dist/react/hooks/use-theme-by-class-name.mjs.map +1 -1
  65. package/dist/react/hooks/use-theme-by-data-attribute.cjs +1 -1
  66. package/dist/react/hooks/use-theme-by-data-attribute.cjs.map +1 -1
  67. package/dist/react/hooks/use-theme-by-data-attribute.d.cts +2 -2
  68. package/dist/react/hooks/use-theme-by-data-attribute.d.mts +2 -2
  69. package/dist/react/hooks/use-theme-by-data-attribute.mjs +1 -1
  70. package/dist/react/hooks/use-theme-by-data-attribute.mjs.map +1 -1
  71. package/dist/react/theme/create-theme-hook.cjs.map +1 -1
  72. package/dist/react/theme/create-theme-hook.mjs.map +1 -1
  73. package/dist/theme/_utils/parse-stored-theme.cjs +1 -1
  74. package/dist/theme/_utils/parse-stored-theme.cjs.map +1 -1
  75. package/dist/theme/_utils/parse-stored-theme.mjs +1 -1
  76. package/dist/theme/_utils/parse-stored-theme.mjs.map +1 -1
  77. package/dist/theme/_utils/set-theme-to-stores.cjs +1 -1
  78. package/dist/theme/_utils/set-theme-to-stores.cjs.map +1 -1
  79. package/dist/theme/_utils/set-theme-to-stores.mjs +1 -1
  80. package/dist/theme/_utils/set-theme-to-stores.mjs.map +1 -1
  81. package/dist/theme/class-name/parse-class-name.cjs +1 -1
  82. package/dist/theme/class-name/parse-class-name.cjs.map +1 -1
  83. package/dist/theme/class-name/parse-class-name.d.cts +2 -2
  84. package/dist/theme/class-name/parse-class-name.d.cts.map +1 -1
  85. package/dist/theme/class-name/parse-class-name.d.mts +2 -2
  86. package/dist/theme/class-name/parse-class-name.d.mts.map +1 -1
  87. package/dist/theme/class-name/parse-class-name.mjs +1 -1
  88. package/dist/theme/class-name/parse-class-name.mjs.map +1 -1
  89. package/dist/theme/class-name/read-class-name.cjs +1 -1
  90. package/dist/theme/class-name/read-class-name.cjs.map +1 -1
  91. package/dist/theme/class-name/read-class-name.d.cts +2 -2
  92. package/dist/theme/class-name/read-class-name.d.cts.map +1 -1
  93. package/dist/theme/class-name/read-class-name.d.mts +2 -2
  94. package/dist/theme/class-name/read-class-name.d.mts.map +1 -1
  95. package/dist/theme/class-name/read-class-name.mjs +1 -1
  96. package/dist/theme/class-name/read-class-name.mjs.map +1 -1
  97. package/dist/theme/class-name/stringify-class-name.cjs +4 -4
  98. package/dist/theme/class-name/stringify-class-name.cjs.map +1 -1
  99. package/dist/theme/class-name/stringify-class-name.d.cts +3 -3
  100. package/dist/theme/class-name/stringify-class-name.d.cts.map +1 -1
  101. package/dist/theme/class-name/stringify-class-name.d.mts +3 -3
  102. package/dist/theme/class-name/stringify-class-name.d.mts.map +1 -1
  103. package/dist/theme/class-name/stringify-class-name.mjs +4 -4
  104. package/dist/theme/class-name/stringify-class-name.mjs.map +1 -1
  105. package/dist/theme/class-name/subscribe-class-name.cjs +2 -3
  106. package/dist/theme/class-name/subscribe-class-name.cjs.map +1 -1
  107. package/dist/theme/class-name/subscribe-class-name.d.cts +2 -2
  108. package/dist/theme/class-name/subscribe-class-name.d.cts.map +1 -1
  109. package/dist/theme/class-name/subscribe-class-name.d.mts +2 -2
  110. package/dist/theme/class-name/subscribe-class-name.d.mts.map +1 -1
  111. package/dist/theme/class-name/subscribe-class-name.mjs +2 -3
  112. package/dist/theme/class-name/subscribe-class-name.mjs.map +1 -1
  113. package/dist/theme/class-name/write-class-name.cjs +2 -2
  114. package/dist/theme/class-name/write-class-name.cjs.map +1 -1
  115. package/dist/theme/class-name/write-class-name.d.cts +4 -4
  116. package/dist/theme/class-name/write-class-name.d.cts.map +1 -1
  117. package/dist/theme/class-name/write-class-name.d.mts +4 -4
  118. package/dist/theme/class-name/write-class-name.d.mts.map +1 -1
  119. package/dist/theme/class-name/write-class-name.mjs +2 -2
  120. package/dist/theme/class-name/write-class-name.mjs.map +1 -1
  121. package/dist/theme/compose-theme-stores.cjs.map +1 -1
  122. package/dist/theme/compose-theme-stores.mjs.map +1 -1
  123. package/dist/theme/cookie/write-cookie-theme.cjs +2 -2
  124. package/dist/theme/cookie/write-cookie-theme.cjs.map +1 -1
  125. package/dist/theme/cookie/write-cookie-theme.d.cts +2 -2
  126. package/dist/theme/cookie/write-cookie-theme.d.cts.map +1 -1
  127. package/dist/theme/cookie/write-cookie-theme.d.mts +2 -2
  128. package/dist/theme/cookie/write-cookie-theme.d.mts.map +1 -1
  129. package/dist/theme/cookie/write-cookie-theme.mjs +2 -2
  130. package/dist/theme/cookie/write-cookie-theme.mjs.map +1 -1
  131. package/dist/theme/data-attribute/parse-data-attribute.cjs +1 -1
  132. package/dist/theme/data-attribute/parse-data-attribute.cjs.map +1 -1
  133. package/dist/theme/data-attribute/parse-data-attribute.d.cts +2 -2
  134. package/dist/theme/data-attribute/parse-data-attribute.d.mts +2 -2
  135. package/dist/theme/data-attribute/parse-data-attribute.mjs +1 -1
  136. package/dist/theme/data-attribute/parse-data-attribute.mjs.map +1 -1
  137. package/dist/theme/data-attribute/read-data-attribute.cjs +1 -1
  138. package/dist/theme/data-attribute/read-data-attribute.cjs.map +1 -1
  139. package/dist/theme/data-attribute/read-data-attribute.d.cts +2 -2
  140. package/dist/theme/data-attribute/read-data-attribute.d.cts.map +1 -1
  141. package/dist/theme/data-attribute/read-data-attribute.d.mts +2 -2
  142. package/dist/theme/data-attribute/read-data-attribute.d.mts.map +1 -1
  143. package/dist/theme/data-attribute/read-data-attribute.mjs +1 -1
  144. package/dist/theme/data-attribute/read-data-attribute.mjs.map +1 -1
  145. package/dist/theme/data-attribute/stringify-data-attribute.cjs +4 -4
  146. package/dist/theme/data-attribute/stringify-data-attribute.cjs.map +1 -1
  147. package/dist/theme/data-attribute/stringify-data-attribute.d.cts +3 -3
  148. package/dist/theme/data-attribute/stringify-data-attribute.d.cts.map +1 -1
  149. package/dist/theme/data-attribute/stringify-data-attribute.d.mts +3 -3
  150. package/dist/theme/data-attribute/stringify-data-attribute.d.mts.map +1 -1
  151. package/dist/theme/data-attribute/stringify-data-attribute.mjs +4 -4
  152. package/dist/theme/data-attribute/stringify-data-attribute.mjs.map +1 -1
  153. package/dist/theme/data-attribute/subscribe-data-attribute.cjs +2 -3
  154. package/dist/theme/data-attribute/subscribe-data-attribute.cjs.map +1 -1
  155. package/dist/theme/data-attribute/subscribe-data-attribute.d.cts +2 -2
  156. package/dist/theme/data-attribute/subscribe-data-attribute.d.cts.map +1 -1
  157. package/dist/theme/data-attribute/subscribe-data-attribute.d.mts +2 -2
  158. package/dist/theme/data-attribute/subscribe-data-attribute.d.mts.map +1 -1
  159. package/dist/theme/data-attribute/subscribe-data-attribute.mjs +2 -3
  160. package/dist/theme/data-attribute/subscribe-data-attribute.mjs.map +1 -1
  161. package/dist/theme/data-attribute/write-data-attribute.cjs +3 -3
  162. package/dist/theme/data-attribute/write-data-attribute.cjs.map +1 -1
  163. package/dist/theme/data-attribute/write-data-attribute.d.cts +4 -4
  164. package/dist/theme/data-attribute/write-data-attribute.d.cts.map +1 -1
  165. package/dist/theme/data-attribute/write-data-attribute.d.mts +4 -4
  166. package/dist/theme/data-attribute/write-data-attribute.d.mts.map +1 -1
  167. package/dist/theme/data-attribute/write-data-attribute.mjs +3 -3
  168. package/dist/theme/data-attribute/write-data-attribute.mjs.map +1 -1
  169. package/dist/theme/local-storage/write-local-storage.cjs +1 -1
  170. package/dist/theme/local-storage/write-local-storage.cjs.map +1 -1
  171. package/dist/theme/local-storage/write-local-storage.d.cts +2 -2
  172. package/dist/theme/local-storage/write-local-storage.d.mts +2 -2
  173. package/dist/theme/local-storage/write-local-storage.mjs +1 -1
  174. package/dist/theme/local-storage/write-local-storage.mjs.map +1 -1
  175. package/dist/theme/session-storage/write-session-storage.cjs +1 -1
  176. package/dist/theme/session-storage/write-session-storage.cjs.map +1 -1
  177. package/dist/theme/session-storage/write-session-storage.d.cts +2 -2
  178. package/dist/theme/session-storage/write-session-storage.d.mts +2 -2
  179. package/dist/theme/session-storage/write-session-storage.mjs +1 -1
  180. package/dist/theme/session-storage/write-session-storage.mjs.map +1 -1
  181. package/dist/theme/theme-entry.types.d.cts +4 -2
  182. package/dist/theme/theme-entry.types.d.cts.map +1 -1
  183. package/dist/theme/theme-entry.types.d.mts +4 -2
  184. package/dist/theme/theme-entry.types.d.mts.map +1 -1
  185. package/dist/theme/theme-store/async-theme-store.types.d.cts +1 -1
  186. package/dist/theme/theme-store/async-theme-store.types.d.cts.map +1 -1
  187. package/dist/theme/theme-store/async-theme-store.types.d.mts +1 -1
  188. package/dist/theme/theme-store/async-theme-store.types.d.mts.map +1 -1
  189. package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.cjs +1 -1
  190. package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.cjs.map +1 -1
  191. package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.d.cts +2 -2
  192. package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.d.mts +2 -2
  193. package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.mjs +1 -1
  194. package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.mjs.map +1 -1
  195. package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.cjs +1 -1
  196. package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.cjs.map +1 -1
  197. package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.d.cts +3 -3
  198. package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.d.mts +3 -3
  199. package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.mjs +1 -1
  200. package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.mjs.map +1 -1
  201. package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.cjs +1 -1
  202. package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.cjs.map +1 -1
  203. package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.d.cts +1 -1
  204. package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.d.mts +1 -1
  205. package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.mjs +1 -1
  206. package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.mjs.map +1 -1
  207. package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.d.cts +1 -1
  208. package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.d.mts +1 -1
  209. package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.d.cts +1 -1
  210. package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.d.mts +1 -1
  211. package/dist/theme/theme-store/theme-store.types.d.cts +1 -1
  212. package/dist/theme/theme-store/theme-store.types.d.cts.map +1 -1
  213. package/dist/theme/theme-store/theme-store.types.d.mts +1 -1
  214. package/dist/theme/theme-store/theme-store.types.d.mts.map +1 -1
  215. package/dist/theme/web-storage/write-web-storage.cjs +3 -3
  216. package/dist/theme/web-storage/write-web-storage.cjs.map +1 -1
  217. package/dist/theme/web-storage/write-web-storage.d.cts +2 -2
  218. package/dist/theme/web-storage/write-web-storage.d.mts +2 -2
  219. package/dist/theme/web-storage/write-web-storage.mjs +3 -3
  220. package/dist/theme/web-storage/write-web-storage.mjs.map +1 -1
  221. package/dist/utils/append-id.cjs +2 -2
  222. package/dist/utils/append-id.cjs.map +1 -1
  223. package/dist/utils/append-id.d.cts +3 -3
  224. package/dist/utils/append-id.d.mts +3 -3
  225. package/dist/utils/append-id.mjs +2 -2
  226. package/dist/utils/append-id.mjs.map +1 -1
  227. package/package.json +1 -1
  228. package/src/attributes/get-attribute.ts +5 -2
  229. package/src/attributes/get-data-attribute.ts +5 -2
  230. package/src/attributes/observe-attribute.ts +15 -10
  231. package/src/attributes/observe-data-attribute.ts +8 -11
  232. package/src/color-scheme/color-scheme.types.ts +7 -0
  233. package/src/color-scheme/get-prefers-color-scheme.ts +6 -4
  234. package/src/color-scheme/observe-prefers-color-scheme.ts +3 -1
  235. package/src/index.ts +1 -0
  236. package/src/react/hooks/use-attribute.ts +12 -13
  237. package/src/react/hooks/use-theme-by-class-name.ts +2 -2
  238. package/src/react/hooks/use-theme-by-data-attribute.ts +2 -2
  239. package/src/react/theme/create-theme-hook.ts +4 -6
  240. package/src/theme/_utils/parse-stored-theme.ts +2 -2
  241. package/src/theme/_utils/set-theme-to-stores.ts +3 -3
  242. package/src/theme/class-name/parse-class-name.ts +2 -2
  243. package/src/theme/class-name/read-class-name.ts +2 -2
  244. package/src/theme/class-name/stringify-class-name.ts +6 -6
  245. package/src/theme/class-name/subscribe-class-name.ts +3 -4
  246. package/src/theme/class-name/write-class-name.ts +4 -4
  247. package/src/theme/compose-theme-stores.ts +1 -1
  248. package/src/theme/cookie/write-cookie-theme.ts +3 -3
  249. package/src/theme/data-attribute/parse-data-attribute.ts +2 -2
  250. package/src/theme/data-attribute/read-data-attribute.ts +2 -2
  251. package/src/theme/data-attribute/stringify-data-attribute.ts +6 -6
  252. package/src/theme/data-attribute/subscribe-data-attribute.ts +3 -4
  253. package/src/theme/data-attribute/write-data-attribute.ts +5 -5
  254. package/src/theme/local-storage/write-local-storage.ts +2 -2
  255. package/src/theme/session-storage/write-session-storage.ts +2 -2
  256. package/src/theme/theme-entry.types.ts +5 -3
  257. package/src/theme/theme-store/async-theme-store.types.ts +1 -3
  258. package/src/theme/theme-store/class-name-theme-store/class-name-theme-store.ts +2 -2
  259. package/src/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.ts +2 -2
  260. package/src/theme/theme-store/in-memory-theme-store/in-memory-theme-store.ts +1 -1
  261. package/src/theme/theme-store/theme-store.types.ts +1 -3
  262. package/src/theme/web-storage/write-web-storage.ts +5 -5
  263. package/src/utils/append-id.ts +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"create-theme-hook.mjs","names":["lastTheme: keyof Themes | undefined","unobserve: () => void"],"sources":["../../../src/react/theme/create-theme-hook.ts"],"sourcesContent":["import { useCallback, useSyncExternalStore } from 'react'\nimport type { Required } from 'type-plus'\nimport {\n\ttype ComposeThemeStoreEntry,\n\ttype ComposeThemeStoresOptions,\n\tcomposeThemeStores\n} from '../../theme/compose-theme-stores.ts'\nimport { themeEntry } from '../../theme/theme-entry.ts'\nimport type { ThemeEntry } from '../../theme/theme-entry.types.ts'\nimport type { ThemeMap } from '../../theme/theme-map.types.ts'\nimport type { AsyncThemeStore } from '../../theme/theme-store/async-theme-store.types.ts'\nimport type { ThemeStoreFactory } from '../../theme/theme-store/theme-store-factory.types.ts'\n\n/**\n * Creates a React hook for theme selection that reads from and writes to composed theme stores.\n *\n * The returned hook subscribes to store changes via `useSyncExternalStore`, supports SSR\n * (uses `defaultTheme` for server snapshot), and returns a `[theme, setTheme]` tuple.\n * Channels are cached per store configuration and default theme for efficient reuse.\n *\n * @param themes - ThemeMap mapping theme keys to their values (e.g. CSS class names)\n * @param stores - Array of 1–8 theme stores or factory configs (see ComposeThemeStoreEntry)\n * @param options.defaultTheme - Fallback theme key when stores return empty; also used for SSR\n * @returns A `useTheme` hook that returns `[currentTheme, setTheme]` tuple\n *\n * @example\n * ```ts\n * const useTheme = createThemeHook(themes, [localStorageStore], { defaultTheme: 'light' })\n * const [theme, setTheme] = useTheme()\n * setTheme('dark')\n * ```\n */\nexport function createThemeHook<\n\tThemes extends ThemeMap,\n\tA extends ThemeStoreFactory<Themes> = never,\n\tB extends ThemeStoreFactory<Themes> = never,\n\tC extends ThemeStoreFactory<Themes> = never,\n\tD extends ThemeStoreFactory<Themes> = never,\n\tE extends ThemeStoreFactory<Themes> = never,\n\tF extends ThemeStoreFactory<Themes> = never,\n\tG extends ThemeStoreFactory<Themes> = never,\n\tH extends ThemeStoreFactory<Themes> = never\n>(\n\tthemes: Themes,\n\tstores: readonly [\n\t\tstore1: ComposeThemeStoreEntry<Themes, A>,\n\t\tstore2?: ComposeThemeStoreEntry<Themes, B>,\n\t\tstore3?: ComposeThemeStoreEntry<Themes, C>,\n\t\tstore4?: ComposeThemeStoreEntry<Themes, D>,\n\t\tstore5?: ComposeThemeStoreEntry<Themes, E>,\n\t\tstore6?: ComposeThemeStoreEntry<Themes, F>,\n\t\tstore7?: ComposeThemeStoreEntry<Themes, G>,\n\t\tstore8?: ComposeThemeStoreEntry<Themes, H>\n\t],\n\toptions?: ComposeThemeStoresOptions<Themes>\n): (\n\toverrideDefaultTheme?: keyof Themes | undefined\n) => [keyof Themes | undefined, (theme: keyof Themes) => void] {\n\tconst { defaultTheme } = options ?? {}\n\treturn function useTheme(overrideDefaultTheme?: keyof Themes | undefined) {\n\t\tconst effectiveDefault = overrideDefaultTheme ?? defaultTheme\n\t\tconst channel = getOrCreateChannel<Themes, A, B, C, D, E, F, G, H>(themes, stores, {\n\t\t\tdefaultTheme: effectiveDefault\n\t\t})\n\n\t\tconst theme = useSyncExternalStore<keyof Themes | undefined>(\n\t\t\tchannel.subscribe,\n\t\t\tchannel.getSnapshot,\n\t\t\tchannel.getServerSnapshot\n\t\t)\n\n\t\tconst setTheme = useCallback(\n\t\t\tasync (newTheme: keyof Themes) => {\n\t\t\t\tawait channel.setTheme(newTheme)\n\t\t\t},\n\t\t\t[channel]\n\t\t)\n\n\t\treturn [theme, setTheme]\n\t}\n}\n\n/**\n * Creates a subscription channel bridging a composed theme store to React's useSyncExternalStore.\n * Manages listeners, initial async read from store, and delegates setTheme to store.write.\n *\n * @internal\n */\nfunction createSharedChannel<Themes extends ThemeMap>(\n\tthemes: Themes,\n\tcomposedStore: Required<AsyncThemeStore<Themes>>,\n\tdefaultTheme: keyof Themes | undefined\n) {\n\tlet lastTheme: keyof Themes | undefined = defaultTheme\n\tconst listeners = new Set<(theme: keyof Themes | undefined) => void>()\n\n\tconst notify = (theme: keyof Themes | undefined) => {\n\t\tlastTheme = theme\n\t\tfor (const fn of listeners) {\n\t\t\tfn(theme)\n\t\t}\n\t}\n\n\tconst handleStoreUpdate = (entry: ThemeEntry<Themes> | undefined | null) => {\n\t\tnotify(entry?.theme ?? defaultTheme)\n\t}\n\n\t// Initial read to populate lastTheme (compose store subscribe has no initial notify)\n\tvoid Promise.resolve(composedStore.read()).then(\n\t\t(entry: ThemeEntry<Themes> | undefined | null) => {\n\t\t\tnotify(entry?.theme ?? defaultTheme)\n\t\t}\n\t)\n\n\tlet unobserve: () => void = composedStore.subscribe(handleStoreUpdate)\n\tlet isSubscribedToStore = true\n\n\tconst subscribe = (listener: (theme: keyof Themes | undefined) => void) => {\n\t\tif (!isSubscribedToStore) {\n\t\t\tunobserve = composedStore.subscribe(handleStoreUpdate)\n\t\t\tisSubscribedToStore = true\n\t\t}\n\t\tlisteners.add(listener)\n\t\tlistener(lastTheme)\n\t\treturn () => {\n\t\t\tlisteners.delete(listener)\n\t\t\tif (listeners.size === 0) {\n\t\t\t\tunobserve()\n\t\t\t\tisSubscribedToStore = false\n\t\t\t}\n\t\t}\n\t}\n\n\tconst getSnapshot = (): keyof Themes | undefined => lastTheme\n\tconst getServerSnapshot = (): keyof Themes | undefined => defaultTheme\n\n\treturn {\n\t\tsubscribe,\n\t\tgetSnapshot,\n\t\tgetServerSnapshot,\n\t\tsetTheme: (theme: keyof Themes) => composedStore.write(themeEntry(themes, theme))\n\t}\n}\n\nconst channelsByStores = new WeakMap<\n\tobject,\n\tMap<string | undefined, ReturnType<typeof createSharedChannel<any>>>\n>()\n\n/**\n * Returns a cached shared channel for the given themes, stores, and defaultTheme.\n * Channels are keyed by stores (WeakMap) and defaultTheme to avoid duplicate subscriptions.\n *\n * @internal\n */\nfunction getOrCreateChannel<\n\tThemes extends ThemeMap,\n\tA extends ThemeStoreFactory<Themes> = never,\n\tB extends ThemeStoreFactory<Themes> = never,\n\tC extends ThemeStoreFactory<Themes> = never,\n\tD extends ThemeStoreFactory<Themes> = never,\n\tE extends ThemeStoreFactory<Themes> = never,\n\tF extends ThemeStoreFactory<Themes> = never,\n\tG extends ThemeStoreFactory<Themes> = never,\n\tH extends ThemeStoreFactory<Themes> = never\n>(\n\tthemes: Themes,\n\tstores: readonly [\n\t\tstore1: ComposeThemeStoreEntry<Themes, A>,\n\t\tstore2?: ComposeThemeStoreEntry<Themes, B>,\n\t\tstore3?: ComposeThemeStoreEntry<Themes, C>,\n\t\tstore4?: ComposeThemeStoreEntry<Themes, D>,\n\t\tstore5?: ComposeThemeStoreEntry<Themes, E>,\n\t\tstore6?: ComposeThemeStoreEntry<Themes, F>,\n\t\tstore7?: ComposeThemeStoreEntry<Themes, G>,\n\t\tstore8?: ComposeThemeStoreEntry<Themes, H>\n\t],\n\toptions?: ComposeThemeStoresOptions<Themes> | undefined\n) {\n\tconst { defaultTheme } = options ?? {}\n\tconst storesKey = stores as unknown as object\n\tlet byDefault = channelsByStores.get(storesKey) as Map<\n\t\tkeyof Themes | undefined,\n\t\tReturnType<typeof createSharedChannel<Themes>>\n\t>\n\tif (!byDefault) {\n\t\tbyDefault = new Map<keyof Themes | undefined, ReturnType<typeof createSharedChannel<Themes>>>()\n\t\tchannelsByStores.set(storesKey, byDefault as any)\n\t}\n\tlet channel = byDefault.get(defaultTheme) as ReturnType<typeof createSharedChannel<Themes>>\n\tif (!channel) {\n\t\tconst composedStore = composeThemeStores(themes, stores, { defaultTheme })\n\t\tchannel = createSharedChannel<Themes>(themes, composedStore, defaultTheme)\n\t\tbyDefault.set(defaultTheme, channel)\n\t}\n\treturn channel\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAgCA,SAAgB,gBAWf,QACA,QAUA,SAG8D;CAC9D,MAAM,EAAE,iBAAiB,WAAW,EAAE;AACtC,QAAO,SAAS,SAAS,sBAAiD;EAEzE,MAAM,UAAU,mBAAmD,QAAQ,QAAQ,EAClF,cAFwB,wBAAwB,cAGhD,CAAC;AAeF,SAAO,CAbO,qBACb,QAAQ,WACR,QAAQ,aACR,QAAQ,kBACR,EAEgB,YAChB,OAAO,aAA2B;AACjC,SAAM,QAAQ,SAAS,SAAS;KAEjC,CAAC,QAAQ,CACT,CAEuB;;;;;;;;;AAU1B,SAAS,oBACR,QACA,eACA,cACC;CACD,IAAIA,YAAsC;CAC1C,MAAM,4BAAY,IAAI,KAAgD;CAEtE,MAAM,UAAU,UAAoC;AACnD,cAAY;AACZ,OAAK,MAAM,MAAM,UAChB,IAAG,MAAM;;CAIX,MAAM,qBAAqB,UAAiD;AAC3E,SAAO,OAAO,SAAS,aAAa;;AAIrC,CAAK,QAAQ,QAAQ,cAAc,MAAM,CAAC,CAAC,MACzC,UAAiD;AACjD,SAAO,OAAO,SAAS,aAAa;GAErC;CAED,IAAIC,YAAwB,cAAc,UAAU,kBAAkB;CACtE,IAAI,sBAAsB;CAE1B,MAAM,aAAa,aAAwD;AAC1E,MAAI,CAAC,qBAAqB;AACzB,eAAY,cAAc,UAAU,kBAAkB;AACtD,yBAAsB;;AAEvB,YAAU,IAAI,SAAS;AACvB,WAAS,UAAU;AACnB,eAAa;AACZ,aAAU,OAAO,SAAS;AAC1B,OAAI,UAAU,SAAS,GAAG;AACzB,eAAW;AACX,0BAAsB;;;;CAKzB,MAAM,oBAA8C;CACpD,MAAM,0BAAoD;AAE1D,QAAO;EACN;EACA;EACA;EACA,WAAW,UAAwB,cAAc,MAAM,WAAW,QAAQ,MAAM,CAAC;EACjF;;AAGF,MAAM,mCAAmB,IAAI,SAG1B;;;;;;;AAQH,SAAS,mBAWR,QACA,QAUA,SACC;CACD,MAAM,EAAE,iBAAiB,WAAW,EAAE;CACtC,MAAM,YAAY;CAClB,IAAI,YAAY,iBAAiB,IAAI,UAAU;AAI/C,KAAI,CAAC,WAAW;AACf,8BAAY,IAAI,KAA+E;AAC/F,mBAAiB,IAAI,WAAW,UAAiB;;CAElD,IAAI,UAAU,UAAU,IAAI,aAAa;AACzC,KAAI,CAAC,SAAS;AAEb,YAAU,oBAA4B,QADhB,mBAAmB,QAAQ,QAAQ,EAAE,cAAc,CAAC,EACb,aAAa;AAC1E,YAAU,IAAI,cAAc,QAAQ;;AAErC,QAAO"}
1
+ {"version":3,"file":"create-theme-hook.mjs","names":["lastTheme: keyof Themes | undefined","unobserve: () => void"],"sources":["../../../src/react/theme/create-theme-hook.ts"],"sourcesContent":["import { useCallback, useSyncExternalStore } from 'react'\nimport type { Required } from 'type-plus'\nimport {\n\ttype ComposeThemeStoreEntry,\n\ttype ComposeThemeStoresOptions,\n\tcomposeThemeStores\n} from '../../theme/compose-theme-stores.ts'\nimport { themeEntry } from '../../theme/theme-entry.ts'\nimport type { ThemeEntry } from '../../theme/theme-entry.types.ts'\nimport type { ThemeMap } from '../../theme/theme-map.types.ts'\nimport type { AsyncThemeStore } from '../../theme/theme-store/async-theme-store.types.ts'\nimport type { ThemeStoreFactory } from '../../theme/theme-store/theme-store-factory.types.ts'\n\n/**\n * Creates a React hook for theme selection that reads from and writes to composed theme stores.\n *\n * The returned hook subscribes to store changes via `useSyncExternalStore`, supports SSR\n * (uses `defaultTheme` for server snapshot), and returns a `[theme, setTheme]` tuple.\n * Channels are cached per store configuration and default theme for efficient reuse.\n *\n * @param themes - ThemeMap mapping theme keys to their values (e.g. CSS class names)\n * @param stores - Array of 1–8 theme stores or factory configs (see ComposeThemeStoreEntry)\n * @param options.defaultTheme - Fallback theme key when stores return empty; also used for SSR\n * @returns A `useTheme` hook that returns `[currentTheme, setTheme]` tuple\n *\n * @example\n * ```ts\n * const useTheme = createThemeHook(themes, [localStorageStore], { defaultTheme: 'light' })\n * const [theme, setTheme] = useTheme()\n * setTheme('dark')\n * ```\n */\nexport function createThemeHook<\n\tThemes extends ThemeMap,\n\tA extends ThemeStoreFactory<Themes> = never,\n\tB extends ThemeStoreFactory<Themes> = never,\n\tC extends ThemeStoreFactory<Themes> = never,\n\tD extends ThemeStoreFactory<Themes> = never,\n\tE extends ThemeStoreFactory<Themes> = never,\n\tF extends ThemeStoreFactory<Themes> = never,\n\tG extends ThemeStoreFactory<Themes> = never,\n\tH extends ThemeStoreFactory<Themes> = never\n>(\n\tthemes: Themes,\n\tstores: readonly [\n\t\tstore1: ComposeThemeStoreEntry<Themes, A>,\n\t\tstore2?: ComposeThemeStoreEntry<Themes, B>,\n\t\tstore3?: ComposeThemeStoreEntry<Themes, C>,\n\t\tstore4?: ComposeThemeStoreEntry<Themes, D>,\n\t\tstore5?: ComposeThemeStoreEntry<Themes, E>,\n\t\tstore6?: ComposeThemeStoreEntry<Themes, F>,\n\t\tstore7?: ComposeThemeStoreEntry<Themes, G>,\n\t\tstore8?: ComposeThemeStoreEntry<Themes, H>\n\t],\n\toptions?: ComposeThemeStoresOptions<Themes>\n): (\n\toverrideDefaultTheme?: keyof Themes | undefined\n) => [keyof Themes | undefined, (theme: keyof Themes) => void] {\n\tconst { defaultTheme } = options ?? {}\n\treturn function useTheme(overrideDefaultTheme?: keyof Themes | undefined) {\n\t\tconst effectiveDefault = overrideDefaultTheme ?? defaultTheme\n\t\tconst channel = getOrCreateChannel<Themes, A, B, C, D, E, F, G, H>(themes, stores, {\n\t\t\tdefaultTheme: effectiveDefault\n\t\t})\n\n\t\tconst theme = useSyncExternalStore<keyof Themes | undefined>(\n\t\t\tchannel.subscribe,\n\t\t\tchannel.getSnapshot,\n\t\t\tchannel.getServerSnapshot\n\t\t)\n\n\t\tconst setTheme = useCallback(\n\t\t\tasync (newTheme: keyof Themes) => {\n\t\t\t\tawait channel.setTheme(newTheme)\n\t\t\t},\n\t\t\t[channel]\n\t\t)\n\n\t\treturn [theme, setTheme]\n\t}\n}\n\n/**\n * Creates a subscription channel bridging a composed theme store to React's useSyncExternalStore.\n * Manages listeners, initial async read from store, and delegates setTheme to store.write.\n *\n * @internal\n */\nfunction createSharedChannel<Themes extends ThemeMap>(\n\tthemes: Themes,\n\tcomposedStore: Required<AsyncThemeStore<Themes>>,\n\tdefaultTheme: keyof Themes | undefined\n) {\n\tlet lastTheme: keyof Themes | undefined = defaultTheme\n\tconst listeners = new Set<(theme: keyof Themes | undefined) => void>()\n\n\tconst notify = (theme: keyof Themes | undefined) => {\n\t\tlastTheme = theme\n\t\tfor (const fn of listeners) {\n\t\t\tfn(theme)\n\t\t}\n\t}\n\n\tconst handleStoreUpdate = (entry: ThemeEntry<Themes> | undefined) => {\n\t\tnotify(entry?.theme ?? defaultTheme)\n\t}\n\n\t// Initial read to populate lastTheme (compose store subscribe has no initial notify)\n\tvoid Promise.resolve(composedStore.read()).then((entry: ThemeEntry<Themes> | undefined) => {\n\t\tnotify(entry?.theme ?? defaultTheme)\n\t})\n\n\tlet unobserve: () => void = composedStore.subscribe(handleStoreUpdate)\n\tlet isSubscribedToStore = true\n\n\tconst subscribe = (listener: (theme: keyof Themes | undefined) => void) => {\n\t\tif (!isSubscribedToStore) {\n\t\t\tunobserve = composedStore.subscribe(handleStoreUpdate)\n\t\t\tisSubscribedToStore = true\n\t\t}\n\t\tlisteners.add(listener)\n\t\tlistener(lastTheme)\n\t\treturn () => {\n\t\t\tlisteners.delete(listener)\n\t\t\tif (listeners.size === 0) {\n\t\t\t\tunobserve()\n\t\t\t\tisSubscribedToStore = false\n\t\t\t}\n\t\t}\n\t}\n\n\tconst getSnapshot = (): keyof Themes | undefined => lastTheme\n\tconst getServerSnapshot = (): keyof Themes | undefined => defaultTheme\n\n\treturn {\n\t\tsubscribe,\n\t\tgetSnapshot,\n\t\tgetServerSnapshot,\n\t\tsetTheme: (theme: keyof Themes) => composedStore.write(themeEntry(themes, theme))\n\t}\n}\n\nconst channelsByStores = new WeakMap<\n\tobject,\n\tMap<string | undefined, ReturnType<typeof createSharedChannel<any>>>\n>()\n\n/**\n * Returns a cached shared channel for the given themes, stores, and defaultTheme.\n * Channels are keyed by stores (WeakMap) and defaultTheme to avoid duplicate subscriptions.\n *\n * @internal\n */\nfunction getOrCreateChannel<\n\tThemes extends ThemeMap,\n\tA extends ThemeStoreFactory<Themes> = never,\n\tB extends ThemeStoreFactory<Themes> = never,\n\tC extends ThemeStoreFactory<Themes> = never,\n\tD extends ThemeStoreFactory<Themes> = never,\n\tE extends ThemeStoreFactory<Themes> = never,\n\tF extends ThemeStoreFactory<Themes> = never,\n\tG extends ThemeStoreFactory<Themes> = never,\n\tH extends ThemeStoreFactory<Themes> = never\n>(\n\tthemes: Themes,\n\tstores: readonly [\n\t\tstore1: ComposeThemeStoreEntry<Themes, A>,\n\t\tstore2?: ComposeThemeStoreEntry<Themes, B>,\n\t\tstore3?: ComposeThemeStoreEntry<Themes, C>,\n\t\tstore4?: ComposeThemeStoreEntry<Themes, D>,\n\t\tstore5?: ComposeThemeStoreEntry<Themes, E>,\n\t\tstore6?: ComposeThemeStoreEntry<Themes, F>,\n\t\tstore7?: ComposeThemeStoreEntry<Themes, G>,\n\t\tstore8?: ComposeThemeStoreEntry<Themes, H>\n\t],\n\toptions?: ComposeThemeStoresOptions<Themes> | undefined\n) {\n\tconst { defaultTheme } = options ?? {}\n\tconst storesKey = stores as unknown as object\n\tlet byDefault = channelsByStores.get(storesKey) as Map<\n\t\tkeyof Themes | undefined,\n\t\tReturnType<typeof createSharedChannel<Themes>>\n\t>\n\tif (!byDefault) {\n\t\tbyDefault = new Map<keyof Themes | undefined, ReturnType<typeof createSharedChannel<Themes>>>()\n\t\tchannelsByStores.set(storesKey, byDefault as any)\n\t}\n\tlet channel = byDefault.get(defaultTheme) as ReturnType<typeof createSharedChannel<Themes>>\n\tif (!channel) {\n\t\tconst composedStore = composeThemeStores(themes, stores, { defaultTheme })\n\t\tchannel = createSharedChannel<Themes>(themes, composedStore, defaultTheme)\n\t\tbyDefault.set(defaultTheme, channel)\n\t}\n\treturn channel\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAgCA,SAAgB,gBAWf,QACA,QAUA,SAG8D;CAC9D,MAAM,EAAE,iBAAiB,WAAW,EAAE;AACtC,QAAO,SAAS,SAAS,sBAAiD;EAEzE,MAAM,UAAU,mBAAmD,QAAQ,QAAQ,EAClF,cAFwB,wBAAwB,cAGhD,CAAC;AAeF,SAAO,CAbO,qBACb,QAAQ,WACR,QAAQ,aACR,QAAQ,kBACR,EAEgB,YAChB,OAAO,aAA2B;AACjC,SAAM,QAAQ,SAAS,SAAS;KAEjC,CAAC,QAAQ,CACT,CAEuB;;;;;;;;;AAU1B,SAAS,oBACR,QACA,eACA,cACC;CACD,IAAIA,YAAsC;CAC1C,MAAM,4BAAY,IAAI,KAAgD;CAEtE,MAAM,UAAU,UAAoC;AACnD,cAAY;AACZ,OAAK,MAAM,MAAM,UAChB,IAAG,MAAM;;CAIX,MAAM,qBAAqB,UAA0C;AACpE,SAAO,OAAO,SAAS,aAAa;;AAIrC,CAAK,QAAQ,QAAQ,cAAc,MAAM,CAAC,CAAC,MAAM,UAA0C;AAC1F,SAAO,OAAO,SAAS,aAAa;GACnC;CAEF,IAAIC,YAAwB,cAAc,UAAU,kBAAkB;CACtE,IAAI,sBAAsB;CAE1B,MAAM,aAAa,aAAwD;AAC1E,MAAI,CAAC,qBAAqB;AACzB,eAAY,cAAc,UAAU,kBAAkB;AACtD,yBAAsB;;AAEvB,YAAU,IAAI,SAAS;AACvB,WAAS,UAAU;AACnB,eAAa;AACZ,aAAU,OAAO,SAAS;AAC1B,OAAI,UAAU,SAAS,GAAG;AACzB,eAAW;AACX,0BAAsB;;;;CAKzB,MAAM,oBAA8C;CACpD,MAAM,0BAAoD;AAE1D,QAAO;EACN;EACA;EACA;EACA,WAAW,UAAwB,cAAc,MAAM,WAAW,QAAQ,MAAM,CAAC;EACjF;;AAGF,MAAM,mCAAmB,IAAI,SAG1B;;;;;;;AAQH,SAAS,mBAWR,QACA,QAUA,SACC;CACD,MAAM,EAAE,iBAAiB,WAAW,EAAE;CACtC,MAAM,YAAY;CAClB,IAAI,YAAY,iBAAiB,IAAI,UAAU;AAI/C,KAAI,CAAC,WAAW;AACf,8BAAY,IAAI,KAA+E;AAC/F,mBAAiB,IAAI,WAAW,UAAiB;;CAElD,IAAI,UAAU,UAAU,IAAI,aAAa;AACzC,KAAI,CAAC,SAAS;AAEb,YAAU,oBAA4B,QADhB,mBAAmB,QAAQ,QAAQ,EAAE,cAAc,CAAC,EACb,aAAa;AAC1E,YAAU,IAAI,cAAc,QAAQ;;AAErC,QAAO"}
@@ -52,7 +52,7 @@ function getCanonicalShapeAndComparable(v) {
52
52
  * returns { theme, value: stored.value }. Else returns undefined.
53
53
  *
54
54
  * @param themes - Record of valid theme keys and values (required for validation)
55
- * @param value - Raw string from localStorage/sessionStorage/cookie
55
+ * @param value - Raw string from localStorage/sessionStorage/cookie (accepts null)
56
56
  * @returns ThemeEntry when valid, otherwise undefined
57
57
  */
58
58
  function parseStoredTheme(themes, value) {
@@ -1 +1 @@
1
- {"version":3,"file":"parse-stored-theme.cjs","names":["isReadonlyStringArray","tryParseJSON"],"sources":["../../../src/theme/_utils/parse-stored-theme.ts"],"sourcesContent":["import { tryParseJSON } from '../../_internal/utils/try-parse-json.ts'\nimport type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap, ThemeMapValue } from '../theme-map.types.ts'\nimport { isReadonlyStringArray } from './resolve-theme-map-value.ts'\n\ntype Shape = 'string' | 'array' | 'object-string' | 'object-array'\n\nfunction getShapeAndComparable(\n\tv: unknown\n): { shape: Shape; comparable: string | undefined } | null {\n\tif (typeof v === 'string') return { shape: 'string', comparable: v }\n\tif (Array.isArray(v)) return { shape: 'array', comparable: v[0] }\n\tif (v !== null && typeof v === 'object' && 'themeValue' in v) {\n\t\tconst tv = (v as { themeValue: string | string[] }).themeValue\n\t\tif (typeof tv === 'string') return { shape: 'object-string', comparable: tv }\n\t\tif (Array.isArray(tv)) return { shape: 'object-array', comparable: tv[0] }\n\t}\n\treturn null\n}\n\nfunction getCanonicalShapeAndComparable(v: ThemeMapValue): {\n\tshape: Shape\n\tcomparable: string | undefined\n} {\n\tif (typeof v === 'string') return { shape: 'string', comparable: v }\n\tif (isReadonlyStringArray(v)) return { shape: 'array', comparable: v[0] }\n\tconst tv = v.themeValue\n\tif (typeof tv === 'string') return { shape: 'object-string', comparable: tv }\n\treturn { shape: 'object-array', comparable: tv[0] }\n}\n\n/**\n * Parses stored JSON theme and validates against theme map with strict shape and comparable matching.\n *\n * Expects stored shape: { theme: string, value?: unknown }\n *\n * When shape matches AND comparable value (string or [0]) matches themes[theme]:\n * returns { theme, value: stored.value }. Else returns undefined.\n *\n * @param themes - Record of valid theme keys and values (required for validation)\n * @param value - Raw string from localStorage/sessionStorage/cookie\n * @returns ThemeEntry when valid, otherwise undefined\n */\nexport function parseStoredTheme<Themes extends ThemeMap>(\n\tthemes: Themes | undefined,\n\tvalue: string | undefined\n): ThemeEntry<Themes> | undefined {\n\tconst parsed = tryParseJSON<{ theme: string; value?: unknown }>(value ?? null)\n\tif (!parsed?.theme || typeof parsed.theme !== 'string') return undefined\n\tif (!themes || !(parsed.theme in themes)) return undefined\n\tif (parsed.value === undefined) return undefined\n\n\tconst storedInfo = getShapeAndComparable(parsed.value)\n\tif (!storedInfo) return undefined\n\n\tconst canonical = getCanonicalShapeAndComparable(themes[parsed.theme] as ThemeMapValue)\n\tif (storedInfo.shape !== canonical.shape) return undefined\n\tif (storedInfo.comparable !== canonical.comparable) return undefined\n\n\treturn { theme: parsed.theme as keyof Themes, value: parsed.value as Themes[keyof Themes] }\n}\n"],"mappings":";;;;AAOA,SAAS,sBACR,GAC0D;AAC1D,KAAI,OAAO,MAAM,SAAU,QAAO;EAAE,OAAO;EAAU,YAAY;EAAG;AACpE,KAAI,MAAM,QAAQ,EAAE,CAAE,QAAO;EAAE,OAAO;EAAS,YAAY,EAAE;EAAI;AACjE,KAAI,MAAM,QAAQ,OAAO,MAAM,YAAY,gBAAgB,GAAG;EAC7D,MAAM,KAAM,EAAwC;AACpD,MAAI,OAAO,OAAO,SAAU,QAAO;GAAE,OAAO;GAAiB,YAAY;GAAI;AAC7E,MAAI,MAAM,QAAQ,GAAG,CAAE,QAAO;GAAE,OAAO;GAAgB,YAAY,GAAG;GAAI;;AAE3E,QAAO;;AAGR,SAAS,+BAA+B,GAGtC;AACD,KAAI,OAAO,MAAM,SAAU,QAAO;EAAE,OAAO;EAAU,YAAY;EAAG;AACpE,KAAIA,sDAAsB,EAAE,CAAE,QAAO;EAAE,OAAO;EAAS,YAAY,EAAE;EAAI;CACzE,MAAM,KAAK,EAAE;AACb,KAAI,OAAO,OAAO,SAAU,QAAO;EAAE,OAAO;EAAiB,YAAY;EAAI;AAC7E,QAAO;EAAE,OAAO;EAAgB,YAAY,GAAG;EAAI;;;;;;;;;;;;;;AAepD,SAAgB,iBACf,QACA,OACiC;CACjC,MAAM,SAASC,oCAAiD,SAAS,KAAK;AAC9E,KAAI,CAAC,QAAQ,SAAS,OAAO,OAAO,UAAU,SAAU,QAAO;AAC/D,KAAI,CAAC,UAAU,EAAE,OAAO,SAAS,QAAS,QAAO;AACjD,KAAI,OAAO,UAAU,OAAW,QAAO;CAEvC,MAAM,aAAa,sBAAsB,OAAO,MAAM;AACtD,KAAI,CAAC,WAAY,QAAO;CAExB,MAAM,YAAY,+BAA+B,OAAO,OAAO,OAAwB;AACvF,KAAI,WAAW,UAAU,UAAU,MAAO,QAAO;AACjD,KAAI,WAAW,eAAe,UAAU,WAAY,QAAO;AAE3D,QAAO;EAAE,OAAO,OAAO;EAAuB,OAAO,OAAO;EAA+B"}
1
+ {"version":3,"file":"parse-stored-theme.cjs","names":["isReadonlyStringArray","tryParseJSON"],"sources":["../../../src/theme/_utils/parse-stored-theme.ts"],"sourcesContent":["import { tryParseJSON } from '../../_internal/utils/try-parse-json.ts'\nimport type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap, ThemeMapValue } from '../theme-map.types.ts'\nimport { isReadonlyStringArray } from './resolve-theme-map-value.ts'\n\ntype Shape = 'string' | 'array' | 'object-string' | 'object-array'\n\nfunction getShapeAndComparable(\n\tv: unknown\n): { shape: Shape; comparable: string | undefined } | null {\n\tif (typeof v === 'string') return { shape: 'string', comparable: v }\n\tif (Array.isArray(v)) return { shape: 'array', comparable: v[0] }\n\tif (v !== null && typeof v === 'object' && 'themeValue' in v) {\n\t\tconst tv = (v as { themeValue: string | string[] }).themeValue\n\t\tif (typeof tv === 'string') return { shape: 'object-string', comparable: tv }\n\t\tif (Array.isArray(tv)) return { shape: 'object-array', comparable: tv[0] }\n\t}\n\treturn null\n}\n\nfunction getCanonicalShapeAndComparable(v: ThemeMapValue): {\n\tshape: Shape\n\tcomparable: string | undefined\n} {\n\tif (typeof v === 'string') return { shape: 'string', comparable: v }\n\tif (isReadonlyStringArray(v)) return { shape: 'array', comparable: v[0] }\n\tconst tv = v.themeValue\n\tif (typeof tv === 'string') return { shape: 'object-string', comparable: tv }\n\treturn { shape: 'object-array', comparable: tv[0] }\n}\n\n/**\n * Parses stored JSON theme and validates against theme map with strict shape and comparable matching.\n *\n * Expects stored shape: { theme: string, value?: unknown }\n *\n * When shape matches AND comparable value (string or [0]) matches themes[theme]:\n * returns { theme, value: stored.value }. Else returns undefined.\n *\n * @param themes - Record of valid theme keys and values (required for validation)\n * @param value - Raw string from localStorage/sessionStorage/cookie (accepts null)\n * @returns ThemeEntry when valid, otherwise undefined\n */\nexport function parseStoredTheme<Themes extends ThemeMap>(\n\tthemes: Themes | undefined,\n\tvalue: string | null | undefined\n): ThemeEntry<Themes> | undefined {\n\tconst parsed = tryParseJSON<{ theme: string; value?: unknown }>(value ?? null)\n\tif (!parsed?.theme || typeof parsed.theme !== 'string') return undefined\n\tif (!themes || !(parsed.theme in themes)) return undefined\n\tif (parsed.value === undefined) return undefined\n\n\tconst storedInfo = getShapeAndComparable(parsed.value)\n\tif (!storedInfo) return undefined\n\n\tconst canonical = getCanonicalShapeAndComparable(themes[parsed.theme] as ThemeMapValue)\n\tif (storedInfo.shape !== canonical.shape) return undefined\n\tif (storedInfo.comparable !== canonical.comparable) return undefined\n\n\treturn { theme: parsed.theme as keyof Themes, value: parsed.value as Themes[keyof Themes] }\n}\n"],"mappings":";;;;AAOA,SAAS,sBACR,GAC0D;AAC1D,KAAI,OAAO,MAAM,SAAU,QAAO;EAAE,OAAO;EAAU,YAAY;EAAG;AACpE,KAAI,MAAM,QAAQ,EAAE,CAAE,QAAO;EAAE,OAAO;EAAS,YAAY,EAAE;EAAI;AACjE,KAAI,MAAM,QAAQ,OAAO,MAAM,YAAY,gBAAgB,GAAG;EAC7D,MAAM,KAAM,EAAwC;AACpD,MAAI,OAAO,OAAO,SAAU,QAAO;GAAE,OAAO;GAAiB,YAAY;GAAI;AAC7E,MAAI,MAAM,QAAQ,GAAG,CAAE,QAAO;GAAE,OAAO;GAAgB,YAAY,GAAG;GAAI;;AAE3E,QAAO;;AAGR,SAAS,+BAA+B,GAGtC;AACD,KAAI,OAAO,MAAM,SAAU,QAAO;EAAE,OAAO;EAAU,YAAY;EAAG;AACpE,KAAIA,sDAAsB,EAAE,CAAE,QAAO;EAAE,OAAO;EAAS,YAAY,EAAE;EAAI;CACzE,MAAM,KAAK,EAAE;AACb,KAAI,OAAO,OAAO,SAAU,QAAO;EAAE,OAAO;EAAiB,YAAY;EAAI;AAC7E,QAAO;EAAE,OAAO;EAAgB,YAAY,GAAG;EAAI;;;;;;;;;;;;;;AAepD,SAAgB,iBACf,QACA,OACiC;CACjC,MAAM,SAASC,oCAAiD,SAAS,KAAK;AAC9E,KAAI,CAAC,QAAQ,SAAS,OAAO,OAAO,UAAU,SAAU,QAAO;AAC/D,KAAI,CAAC,UAAU,EAAE,OAAO,SAAS,QAAS,QAAO;AACjD,KAAI,OAAO,UAAU,OAAW,QAAO;CAEvC,MAAM,aAAa,sBAAsB,OAAO,MAAM;AACtD,KAAI,CAAC,WAAY,QAAO;CAExB,MAAM,YAAY,+BAA+B,OAAO,OAAO,OAAwB;AACvF,KAAI,WAAW,UAAU,UAAU,MAAO,QAAO;AACjD,KAAI,WAAW,eAAe,UAAU,WAAY,QAAO;AAE3D,QAAO;EAAE,OAAO,OAAO;EAAuB,OAAO,OAAO;EAA+B"}
@@ -52,7 +52,7 @@ function getCanonicalShapeAndComparable(v) {
52
52
  * returns { theme, value: stored.value }. Else returns undefined.
53
53
  *
54
54
  * @param themes - Record of valid theme keys and values (required for validation)
55
- * @param value - Raw string from localStorage/sessionStorage/cookie
55
+ * @param value - Raw string from localStorage/sessionStorage/cookie (accepts null)
56
56
  * @returns ThemeEntry when valid, otherwise undefined
57
57
  */
58
58
  function parseStoredTheme(themes, value) {
@@ -1 +1 @@
1
- {"version":3,"file":"parse-stored-theme.mjs","names":[],"sources":["../../../src/theme/_utils/parse-stored-theme.ts"],"sourcesContent":["import { tryParseJSON } from '../../_internal/utils/try-parse-json.ts'\nimport type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap, ThemeMapValue } from '../theme-map.types.ts'\nimport { isReadonlyStringArray } from './resolve-theme-map-value.ts'\n\ntype Shape = 'string' | 'array' | 'object-string' | 'object-array'\n\nfunction getShapeAndComparable(\n\tv: unknown\n): { shape: Shape; comparable: string | undefined } | null {\n\tif (typeof v === 'string') return { shape: 'string', comparable: v }\n\tif (Array.isArray(v)) return { shape: 'array', comparable: v[0] }\n\tif (v !== null && typeof v === 'object' && 'themeValue' in v) {\n\t\tconst tv = (v as { themeValue: string | string[] }).themeValue\n\t\tif (typeof tv === 'string') return { shape: 'object-string', comparable: tv }\n\t\tif (Array.isArray(tv)) return { shape: 'object-array', comparable: tv[0] }\n\t}\n\treturn null\n}\n\nfunction getCanonicalShapeAndComparable(v: ThemeMapValue): {\n\tshape: Shape\n\tcomparable: string | undefined\n} {\n\tif (typeof v === 'string') return { shape: 'string', comparable: v }\n\tif (isReadonlyStringArray(v)) return { shape: 'array', comparable: v[0] }\n\tconst tv = v.themeValue\n\tif (typeof tv === 'string') return { shape: 'object-string', comparable: tv }\n\treturn { shape: 'object-array', comparable: tv[0] }\n}\n\n/**\n * Parses stored JSON theme and validates against theme map with strict shape and comparable matching.\n *\n * Expects stored shape: { theme: string, value?: unknown }\n *\n * When shape matches AND comparable value (string or [0]) matches themes[theme]:\n * returns { theme, value: stored.value }. Else returns undefined.\n *\n * @param themes - Record of valid theme keys and values (required for validation)\n * @param value - Raw string from localStorage/sessionStorage/cookie\n * @returns ThemeEntry when valid, otherwise undefined\n */\nexport function parseStoredTheme<Themes extends ThemeMap>(\n\tthemes: Themes | undefined,\n\tvalue: string | undefined\n): ThemeEntry<Themes> | undefined {\n\tconst parsed = tryParseJSON<{ theme: string; value?: unknown }>(value ?? null)\n\tif (!parsed?.theme || typeof parsed.theme !== 'string') return undefined\n\tif (!themes || !(parsed.theme in themes)) return undefined\n\tif (parsed.value === undefined) return undefined\n\n\tconst storedInfo = getShapeAndComparable(parsed.value)\n\tif (!storedInfo) return undefined\n\n\tconst canonical = getCanonicalShapeAndComparable(themes[parsed.theme] as ThemeMapValue)\n\tif (storedInfo.shape !== canonical.shape) return undefined\n\tif (storedInfo.comparable !== canonical.comparable) return undefined\n\n\treturn { theme: parsed.theme as keyof Themes, value: parsed.value as Themes[keyof Themes] }\n}\n"],"mappings":";;;;AAOA,SAAS,sBACR,GAC0D;AAC1D,KAAI,OAAO,MAAM,SAAU,QAAO;EAAE,OAAO;EAAU,YAAY;EAAG;AACpE,KAAI,MAAM,QAAQ,EAAE,CAAE,QAAO;EAAE,OAAO;EAAS,YAAY,EAAE;EAAI;AACjE,KAAI,MAAM,QAAQ,OAAO,MAAM,YAAY,gBAAgB,GAAG;EAC7D,MAAM,KAAM,EAAwC;AACpD,MAAI,OAAO,OAAO,SAAU,QAAO;GAAE,OAAO;GAAiB,YAAY;GAAI;AAC7E,MAAI,MAAM,QAAQ,GAAG,CAAE,QAAO;GAAE,OAAO;GAAgB,YAAY,GAAG;GAAI;;AAE3E,QAAO;;AAGR,SAAS,+BAA+B,GAGtC;AACD,KAAI,OAAO,MAAM,SAAU,QAAO;EAAE,OAAO;EAAU,YAAY;EAAG;AACpE,KAAI,sBAAsB,EAAE,CAAE,QAAO;EAAE,OAAO;EAAS,YAAY,EAAE;EAAI;CACzE,MAAM,KAAK,EAAE;AACb,KAAI,OAAO,OAAO,SAAU,QAAO;EAAE,OAAO;EAAiB,YAAY;EAAI;AAC7E,QAAO;EAAE,OAAO;EAAgB,YAAY,GAAG;EAAI;;;;;;;;;;;;;;AAepD,SAAgB,iBACf,QACA,OACiC;CACjC,MAAM,SAAS,aAAiD,SAAS,KAAK;AAC9E,KAAI,CAAC,QAAQ,SAAS,OAAO,OAAO,UAAU,SAAU,QAAO;AAC/D,KAAI,CAAC,UAAU,EAAE,OAAO,SAAS,QAAS,QAAO;AACjD,KAAI,OAAO,UAAU,OAAW,QAAO;CAEvC,MAAM,aAAa,sBAAsB,OAAO,MAAM;AACtD,KAAI,CAAC,WAAY,QAAO;CAExB,MAAM,YAAY,+BAA+B,OAAO,OAAO,OAAwB;AACvF,KAAI,WAAW,UAAU,UAAU,MAAO,QAAO;AACjD,KAAI,WAAW,eAAe,UAAU,WAAY,QAAO;AAE3D,QAAO;EAAE,OAAO,OAAO;EAAuB,OAAO,OAAO;EAA+B"}
1
+ {"version":3,"file":"parse-stored-theme.mjs","names":[],"sources":["../../../src/theme/_utils/parse-stored-theme.ts"],"sourcesContent":["import { tryParseJSON } from '../../_internal/utils/try-parse-json.ts'\nimport type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap, ThemeMapValue } from '../theme-map.types.ts'\nimport { isReadonlyStringArray } from './resolve-theme-map-value.ts'\n\ntype Shape = 'string' | 'array' | 'object-string' | 'object-array'\n\nfunction getShapeAndComparable(\n\tv: unknown\n): { shape: Shape; comparable: string | undefined } | null {\n\tif (typeof v === 'string') return { shape: 'string', comparable: v }\n\tif (Array.isArray(v)) return { shape: 'array', comparable: v[0] }\n\tif (v !== null && typeof v === 'object' && 'themeValue' in v) {\n\t\tconst tv = (v as { themeValue: string | string[] }).themeValue\n\t\tif (typeof tv === 'string') return { shape: 'object-string', comparable: tv }\n\t\tif (Array.isArray(tv)) return { shape: 'object-array', comparable: tv[0] }\n\t}\n\treturn null\n}\n\nfunction getCanonicalShapeAndComparable(v: ThemeMapValue): {\n\tshape: Shape\n\tcomparable: string | undefined\n} {\n\tif (typeof v === 'string') return { shape: 'string', comparable: v }\n\tif (isReadonlyStringArray(v)) return { shape: 'array', comparable: v[0] }\n\tconst tv = v.themeValue\n\tif (typeof tv === 'string') return { shape: 'object-string', comparable: tv }\n\treturn { shape: 'object-array', comparable: tv[0] }\n}\n\n/**\n * Parses stored JSON theme and validates against theme map with strict shape and comparable matching.\n *\n * Expects stored shape: { theme: string, value?: unknown }\n *\n * When shape matches AND comparable value (string or [0]) matches themes[theme]:\n * returns { theme, value: stored.value }. Else returns undefined.\n *\n * @param themes - Record of valid theme keys and values (required for validation)\n * @param value - Raw string from localStorage/sessionStorage/cookie (accepts null)\n * @returns ThemeEntry when valid, otherwise undefined\n */\nexport function parseStoredTheme<Themes extends ThemeMap>(\n\tthemes: Themes | undefined,\n\tvalue: string | null | undefined\n): ThemeEntry<Themes> | undefined {\n\tconst parsed = tryParseJSON<{ theme: string; value?: unknown }>(value ?? null)\n\tif (!parsed?.theme || typeof parsed.theme !== 'string') return undefined\n\tif (!themes || !(parsed.theme in themes)) return undefined\n\tif (parsed.value === undefined) return undefined\n\n\tconst storedInfo = getShapeAndComparable(parsed.value)\n\tif (!storedInfo) return undefined\n\n\tconst canonical = getCanonicalShapeAndComparable(themes[parsed.theme] as ThemeMapValue)\n\tif (storedInfo.shape !== canonical.shape) return undefined\n\tif (storedInfo.comparable !== canonical.comparable) return undefined\n\n\treturn { theme: parsed.theme as keyof Themes, value: parsed.value as Themes[keyof Themes] }\n}\n"],"mappings":";;;;AAOA,SAAS,sBACR,GAC0D;AAC1D,KAAI,OAAO,MAAM,SAAU,QAAO;EAAE,OAAO;EAAU,YAAY;EAAG;AACpE,KAAI,MAAM,QAAQ,EAAE,CAAE,QAAO;EAAE,OAAO;EAAS,YAAY,EAAE;EAAI;AACjE,KAAI,MAAM,QAAQ,OAAO,MAAM,YAAY,gBAAgB,GAAG;EAC7D,MAAM,KAAM,EAAwC;AACpD,MAAI,OAAO,OAAO,SAAU,QAAO;GAAE,OAAO;GAAiB,YAAY;GAAI;AAC7E,MAAI,MAAM,QAAQ,GAAG,CAAE,QAAO;GAAE,OAAO;GAAgB,YAAY,GAAG;GAAI;;AAE3E,QAAO;;AAGR,SAAS,+BAA+B,GAGtC;AACD,KAAI,OAAO,MAAM,SAAU,QAAO;EAAE,OAAO;EAAU,YAAY;EAAG;AACpE,KAAI,sBAAsB,EAAE,CAAE,QAAO;EAAE,OAAO;EAAS,YAAY,EAAE;EAAI;CACzE,MAAM,KAAK,EAAE;AACb,KAAI,OAAO,OAAO,SAAU,QAAO;EAAE,OAAO;EAAiB,YAAY;EAAI;AAC7E,QAAO;EAAE,OAAO;EAAgB,YAAY,GAAG;EAAI;;;;;;;;;;;;;;AAepD,SAAgB,iBACf,QACA,OACiC;CACjC,MAAM,SAAS,aAAiD,SAAS,KAAK;AAC9E,KAAI,CAAC,QAAQ,SAAS,OAAO,OAAO,UAAU,SAAU,QAAO;AAC/D,KAAI,CAAC,UAAU,EAAE,OAAO,SAAS,QAAS,QAAO;AACjD,KAAI,OAAO,UAAU,OAAW,QAAO;CAEvC,MAAM,aAAa,sBAAsB,OAAO,MAAM;AACtD,KAAI,CAAC,WAAY,QAAO;CAExB,MAAM,YAAY,+BAA+B,OAAO,OAAO,OAAwB;AACvF,KAAI,WAAW,UAAU,UAAU,MAAO,QAAO;AACjD,KAAI,WAAW,eAAe,UAAU,WAAY,QAAO;AAE3D,QAAO;EAAE,OAAO,OAAO;EAAuB,OAAO,OAAO;EAA+B"}
@@ -4,7 +4,7 @@
4
4
  * Writes theme entry to all stores that have a write method.
5
5
  *
6
6
  * @param stores - Array of theme stores
7
- * @param entry - Theme entry to write, or undefined to clear
7
+ * @param entry - Theme entry to write, or null/undefined to clear
8
8
  */
9
9
  async function setThemeToStores(stores, entry) {
10
10
  const withWrite = stores.filter((s) => typeof s.write === "function");
@@ -1 +1 @@
1
- {"version":3,"file":"set-theme-to-stores.cjs","names":[],"sources":["../../../src/theme/_utils/set-theme-to-stores.ts"],"sourcesContent":["import type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport type { AsyncThemeStore } from '../theme-store/async-theme-store.types.ts'\nimport type { ThemeStore } from '../theme-store/theme-store.types.ts'\n\ntype StoreWithWrite<Themes extends ThemeMap> = (ThemeStore<Themes> | AsyncThemeStore<Themes>) & {\n\twrite: (entry: ThemeEntry<Themes> | undefined) => void | Promise<void>\n}\n\n/**\n * Writes theme entry to all stores that have a write method.\n *\n * @param stores - Array of theme stores\n * @param entry - Theme entry to write, or undefined to clear\n */\nexport async function setThemeToStores<Themes extends ThemeMap>(\n\tstores: (ThemeStore<Themes> | AsyncThemeStore<Themes>)[],\n\tentry: ThemeEntry<Themes> | undefined\n): Promise<void> {\n\tconst withWrite = stores.filter((s): s is StoreWithWrite<Themes> => typeof s.write === 'function')\n\n\tawait Promise.all(withWrite.map((store) => Promise.resolve(store.write!(entry))))\n}\n"],"mappings":";;;;;;;;AAeA,eAAsB,iBACrB,QACA,OACgB;CAChB,MAAM,YAAY,OAAO,QAAQ,MAAmC,OAAO,EAAE,UAAU,WAAW;AAElG,OAAM,QAAQ,IAAI,UAAU,KAAK,UAAU,QAAQ,QAAQ,MAAM,MAAO,MAAM,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"set-theme-to-stores.cjs","names":[],"sources":["../../../src/theme/_utils/set-theme-to-stores.ts"],"sourcesContent":["import type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport type { AsyncThemeStore } from '../theme-store/async-theme-store.types.ts'\nimport type { ThemeStore } from '../theme-store/theme-store.types.ts'\n\ntype StoreWithWrite<Themes extends ThemeMap> = (ThemeStore<Themes> | AsyncThemeStore<Themes>) & {\n\twrite: (entry: ThemeEntry<Themes> | null | undefined) => void | Promise<void>\n}\n\n/**\n * Writes theme entry to all stores that have a write method.\n *\n * @param stores - Array of theme stores\n * @param entry - Theme entry to write, or null/undefined to clear\n */\nexport async function setThemeToStores<Themes extends ThemeMap>(\n\tstores: (ThemeStore<Themes> | AsyncThemeStore<Themes>)[],\n\tentry: ThemeEntry<Themes> | null | undefined\n): Promise<void> {\n\tconst withWrite = stores.filter((s): s is StoreWithWrite<Themes> => typeof s.write === 'function')\n\n\tawait Promise.all(withWrite.map((store) => Promise.resolve(store.write!(entry))))\n}\n"],"mappings":";;;;;;;;AAeA,eAAsB,iBACrB,QACA,OACgB;CAChB,MAAM,YAAY,OAAO,QAAQ,MAAmC,OAAO,EAAE,UAAU,WAAW;AAElG,OAAM,QAAQ,IAAI,UAAU,KAAK,UAAU,QAAQ,QAAQ,MAAM,MAAO,MAAM,CAAC,CAAC,CAAC"}
@@ -3,7 +3,7 @@
3
3
  * Writes theme entry to all stores that have a write method.
4
4
  *
5
5
  * @param stores - Array of theme stores
6
- * @param entry - Theme entry to write, or undefined to clear
6
+ * @param entry - Theme entry to write, or null/undefined to clear
7
7
  */
8
8
  async function setThemeToStores(stores, entry) {
9
9
  const withWrite = stores.filter((s) => typeof s.write === "function");
@@ -1 +1 @@
1
- {"version":3,"file":"set-theme-to-stores.mjs","names":[],"sources":["../../../src/theme/_utils/set-theme-to-stores.ts"],"sourcesContent":["import type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport type { AsyncThemeStore } from '../theme-store/async-theme-store.types.ts'\nimport type { ThemeStore } from '../theme-store/theme-store.types.ts'\n\ntype StoreWithWrite<Themes extends ThemeMap> = (ThemeStore<Themes> | AsyncThemeStore<Themes>) & {\n\twrite: (entry: ThemeEntry<Themes> | undefined) => void | Promise<void>\n}\n\n/**\n * Writes theme entry to all stores that have a write method.\n *\n * @param stores - Array of theme stores\n * @param entry - Theme entry to write, or undefined to clear\n */\nexport async function setThemeToStores<Themes extends ThemeMap>(\n\tstores: (ThemeStore<Themes> | AsyncThemeStore<Themes>)[],\n\tentry: ThemeEntry<Themes> | undefined\n): Promise<void> {\n\tconst withWrite = stores.filter((s): s is StoreWithWrite<Themes> => typeof s.write === 'function')\n\n\tawait Promise.all(withWrite.map((store) => Promise.resolve(store.write!(entry))))\n}\n"],"mappings":";;;;;;;AAeA,eAAsB,iBACrB,QACA,OACgB;CAChB,MAAM,YAAY,OAAO,QAAQ,MAAmC,OAAO,EAAE,UAAU,WAAW;AAElG,OAAM,QAAQ,IAAI,UAAU,KAAK,UAAU,QAAQ,QAAQ,MAAM,MAAO,MAAM,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"set-theme-to-stores.mjs","names":[],"sources":["../../../src/theme/_utils/set-theme-to-stores.ts"],"sourcesContent":["import type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport type { AsyncThemeStore } from '../theme-store/async-theme-store.types.ts'\nimport type { ThemeStore } from '../theme-store/theme-store.types.ts'\n\ntype StoreWithWrite<Themes extends ThemeMap> = (ThemeStore<Themes> | AsyncThemeStore<Themes>) & {\n\twrite: (entry: ThemeEntry<Themes> | null | undefined) => void | Promise<void>\n}\n\n/**\n * Writes theme entry to all stores that have a write method.\n *\n * @param stores - Array of theme stores\n * @param entry - Theme entry to write, or null/undefined to clear\n */\nexport async function setThemeToStores<Themes extends ThemeMap>(\n\tstores: (ThemeStore<Themes> | AsyncThemeStore<Themes>)[],\n\tentry: ThemeEntry<Themes> | null | undefined\n): Promise<void> {\n\tconst withWrite = stores.filter((s): s is StoreWithWrite<Themes> => typeof s.write === 'function')\n\n\tawait Promise.all(withWrite.map((store) => Promise.resolve(store.write!(entry))))\n}\n"],"mappings":";;;;;;;AAeA,eAAsB,iBACrB,QACA,OACgB;CAChB,MAAM,YAAY,OAAO,QAAQ,MAAmC,OAAO,EAAE,UAAU,WAAW;AAElG,OAAM,QAAQ,IAAI,UAAU,KAAK,UAAU,QAAQ,QAAQ,MAAM,MAAO,MAAM,CAAC,CAAC,CAAC"}
@@ -12,7 +12,7 @@ let type_plus = require("type-plus");
12
12
  * Arrays in theme map use first value for matching.
13
13
  *
14
14
  * @param themes - Record mapping theme keys to class name(s)
15
- * @param className - Raw class attribute value (e.g. from element.className)
15
+ * @param className - Raw class attribute value (e.g. from element.className; accepts null)
16
16
  * @returns ThemeEntry if a match is found, otherwise undefined
17
17
  */
18
18
  function parseClassName(themes, className) {
@@ -1 +1 @@
1
- {"version":3,"file":"parse-class-name.cjs","names":["resolveThemeMapValue","themeEntry"],"sources":["../../../src/theme/class-name/parse-class-name.ts"],"sourcesContent":["import { findKey } from 'type-plus'\nimport { resolveThemeMapValue } from '../_utils/resolve-theme-map-value.ts'\nimport { themeEntry } from '../theme-entry.ts'\nimport type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\n\n/**\n * Parses a class name string into a ThemeEntry.\n *\n * Pure function: no DOM access. Matches class strings by checking if any theme\n * class is included in the className (e.g. `className.includes(themeClass)`).\n * Arrays in theme map use first value for matching.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param className - Raw class attribute value (e.g. from element.className)\n * @returns ThemeEntry if a match is found, otherwise undefined\n */\nexport function parseClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\tclassName: string | undefined\n): ThemeEntry<Themes> | undefined {\n\tconst cls = className ?? ''\n\tconst theme = findKey(themes, (key) => {\n\t\tconst value = themes[key]\n\t\tif (value === undefined) return false\n\t\tconst resolved = resolveThemeMapValue(value)\n\t\tconst v = Array.isArray(resolved) ? resolved[0] : resolved\n\t\treturn !!v && cls.includes(v)\n\t})\n\treturn theme !== undefined ? themeEntry(themes, theme) : undefined\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,SAAgB,eACf,QACA,WACiC;CACjC,MAAM,MAAM,aAAa;CACzB,MAAM,+BAAgB,SAAS,QAAQ;EACtC,MAAM,QAAQ,OAAO;AACrB,MAAI,UAAU,OAAW,QAAO;EAChC,MAAM,WAAWA,qDAAqB,MAAM;EAC5C,MAAM,IAAI,MAAM,QAAQ,SAAS,GAAG,SAAS,KAAK;AAClD,SAAO,CAAC,CAAC,KAAK,IAAI,SAAS,EAAE;GAC5B;AACF,QAAO,UAAU,SAAYC,+BAAW,QAAQ,MAAM,GAAG"}
1
+ {"version":3,"file":"parse-class-name.cjs","names":["resolveThemeMapValue","themeEntry"],"sources":["../../../src/theme/class-name/parse-class-name.ts"],"sourcesContent":["import { findKey } from 'type-plus'\nimport { resolveThemeMapValue } from '../_utils/resolve-theme-map-value.ts'\nimport { themeEntry } from '../theme-entry.ts'\nimport type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\n\n/**\n * Parses a class name string into a ThemeEntry.\n *\n * Pure function: no DOM access. Matches class strings by checking if any theme\n * class is included in the className (e.g. `className.includes(themeClass)`).\n * Arrays in theme map use first value for matching.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param className - Raw class attribute value (e.g. from element.className; accepts null)\n * @returns ThemeEntry if a match is found, otherwise undefined\n */\nexport function parseClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\tclassName: string | null | undefined\n): ThemeEntry<Themes> | undefined {\n\tconst cls = className ?? ''\n\tconst theme = findKey(themes, (key) => {\n\t\tconst value = themes[key]\n\t\tif (value === undefined) return false\n\t\tconst resolved = resolveThemeMapValue(value)\n\t\tconst v = Array.isArray(resolved) ? resolved[0] : resolved\n\t\treturn !!v && cls.includes(v)\n\t})\n\treturn theme !== undefined ? themeEntry(themes, theme) : undefined\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,SAAgB,eACf,QACA,WACiC;CACjC,MAAM,MAAM,aAAa;CACzB,MAAM,+BAAgB,SAAS,QAAQ;EACtC,MAAM,QAAQ,OAAO;AACrB,MAAI,UAAU,OAAW,QAAO;EAChC,MAAM,WAAWA,qDAAqB,MAAM;EAC5C,MAAM,IAAI,MAAM,QAAQ,SAAS,GAAG,SAAS,KAAK;AAClD,SAAO,CAAC,CAAC,KAAK,IAAI,SAAS,EAAE;GAC5B;AACF,QAAO,UAAU,SAAYC,+BAAW,QAAQ,MAAM,GAAG"}
@@ -11,10 +11,10 @@ import { ThemeEntry } from "../theme-entry.types.cjs";
11
11
  * Arrays in theme map use first value for matching.
12
12
  *
13
13
  * @param themes - Record mapping theme keys to class name(s)
14
- * @param className - Raw class attribute value (e.g. from element.className)
14
+ * @param className - Raw class attribute value (e.g. from element.className; accepts null)
15
15
  * @returns ThemeEntry if a match is found, otherwise undefined
16
16
  */
17
- declare function parseClassName<Themes extends ThemeMap>(themes: Themes, className: string | undefined): ThemeEntry<Themes> | undefined;
17
+ declare function parseClassName<Themes extends ThemeMap>(themes: Themes, className: string | null | undefined): ThemeEntry<Themes> | undefined;
18
18
  //#endregion
19
19
  export { parseClassName };
20
20
  //# sourceMappingURL=parse-class-name.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parse-class-name.d.cts","names":[],"sources":["../../../src/theme/class-name/parse-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAiBA;;;;;;;;;iBAAgB,8BAA8B,kBACrC,wCAEN,WAAW"}
1
+ {"version":3,"file":"parse-class-name.d.cts","names":[],"sources":["../../../src/theme/class-name/parse-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAiBA;;;;;;;;;iBAAgB,8BAA8B,kBACrC,+CAEN,WAAW"}
@@ -11,10 +11,10 @@ import { ThemeEntry } from "../theme-entry.types.mjs";
11
11
  * Arrays in theme map use first value for matching.
12
12
  *
13
13
  * @param themes - Record mapping theme keys to class name(s)
14
- * @param className - Raw class attribute value (e.g. from element.className)
14
+ * @param className - Raw class attribute value (e.g. from element.className; accepts null)
15
15
  * @returns ThemeEntry if a match is found, otherwise undefined
16
16
  */
17
- declare function parseClassName<Themes extends ThemeMap>(themes: Themes, className: string | undefined): ThemeEntry<Themes> | undefined;
17
+ declare function parseClassName<Themes extends ThemeMap>(themes: Themes, className: string | null | undefined): ThemeEntry<Themes> | undefined;
18
18
  //#endregion
19
19
  export { parseClassName };
20
20
  //# sourceMappingURL=parse-class-name.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parse-class-name.d.mts","names":[],"sources":["../../../src/theme/class-name/parse-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAiBA;;;;;;;;;iBAAgB,8BAA8B,kBACrC,wCAEN,WAAW"}
1
+ {"version":3,"file":"parse-class-name.d.mts","names":[],"sources":["../../../src/theme/class-name/parse-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAiBA;;;;;;;;;iBAAgB,8BAA8B,kBACrC,+CAEN,WAAW"}
@@ -11,7 +11,7 @@ import { findKey } from "type-plus";
11
11
  * Arrays in theme map use first value for matching.
12
12
  *
13
13
  * @param themes - Record mapping theme keys to class name(s)
14
- * @param className - Raw class attribute value (e.g. from element.className)
14
+ * @param className - Raw class attribute value (e.g. from element.className; accepts null)
15
15
  * @returns ThemeEntry if a match is found, otherwise undefined
16
16
  */
17
17
  function parseClassName(themes, className) {
@@ -1 +1 @@
1
- {"version":3,"file":"parse-class-name.mjs","names":[],"sources":["../../../src/theme/class-name/parse-class-name.ts"],"sourcesContent":["import { findKey } from 'type-plus'\nimport { resolveThemeMapValue } from '../_utils/resolve-theme-map-value.ts'\nimport { themeEntry } from '../theme-entry.ts'\nimport type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\n\n/**\n * Parses a class name string into a ThemeEntry.\n *\n * Pure function: no DOM access. Matches class strings by checking if any theme\n * class is included in the className (e.g. `className.includes(themeClass)`).\n * Arrays in theme map use first value for matching.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param className - Raw class attribute value (e.g. from element.className)\n * @returns ThemeEntry if a match is found, otherwise undefined\n */\nexport function parseClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\tclassName: string | undefined\n): ThemeEntry<Themes> | undefined {\n\tconst cls = className ?? ''\n\tconst theme = findKey(themes, (key) => {\n\t\tconst value = themes[key]\n\t\tif (value === undefined) return false\n\t\tconst resolved = resolveThemeMapValue(value)\n\t\tconst v = Array.isArray(resolved) ? resolved[0] : resolved\n\t\treturn !!v && cls.includes(v)\n\t})\n\treturn theme !== undefined ? themeEntry(themes, theme) : undefined\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAiBA,SAAgB,eACf,QACA,WACiC;CACjC,MAAM,MAAM,aAAa;CACzB,MAAM,QAAQ,QAAQ,SAAS,QAAQ;EACtC,MAAM,QAAQ,OAAO;AACrB,MAAI,UAAU,OAAW,QAAO;EAChC,MAAM,WAAW,qBAAqB,MAAM;EAC5C,MAAM,IAAI,MAAM,QAAQ,SAAS,GAAG,SAAS,KAAK;AAClD,SAAO,CAAC,CAAC,KAAK,IAAI,SAAS,EAAE;GAC5B;AACF,QAAO,UAAU,SAAY,WAAW,QAAQ,MAAM,GAAG"}
1
+ {"version":3,"file":"parse-class-name.mjs","names":[],"sources":["../../../src/theme/class-name/parse-class-name.ts"],"sourcesContent":["import { findKey } from 'type-plus'\nimport { resolveThemeMapValue } from '../_utils/resolve-theme-map-value.ts'\nimport { themeEntry } from '../theme-entry.ts'\nimport type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\n\n/**\n * Parses a class name string into a ThemeEntry.\n *\n * Pure function: no DOM access. Matches class strings by checking if any theme\n * class is included in the className (e.g. `className.includes(themeClass)`).\n * Arrays in theme map use first value for matching.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param className - Raw class attribute value (e.g. from element.className; accepts null)\n * @returns ThemeEntry if a match is found, otherwise undefined\n */\nexport function parseClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\tclassName: string | null | undefined\n): ThemeEntry<Themes> | undefined {\n\tconst cls = className ?? ''\n\tconst theme = findKey(themes, (key) => {\n\t\tconst value = themes[key]\n\t\tif (value === undefined) return false\n\t\tconst resolved = resolveThemeMapValue(value)\n\t\tconst v = Array.isArray(resolved) ? resolved[0] : resolved\n\t\treturn !!v && cls.includes(v)\n\t})\n\treturn theme !== undefined ? themeEntry(themes, theme) : undefined\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAiBA,SAAgB,eACf,QACA,WACiC;CACjC,MAAM,MAAM,aAAa;CACzB,MAAM,QAAQ,QAAQ,SAAS,QAAQ;EACtC,MAAM,QAAQ,OAAO;AACrB,MAAI,UAAU,OAAW,QAAO;EAChC,MAAM,WAAW,qBAAqB,MAAM;EAC5C,MAAM,IAAI,MAAM,QAAQ,SAAS,GAAG,SAAS,KAAK;AAClD,SAAO,CAAC,CAAC,KAAK,IAAI,SAAS,EAAE;GAC5B;AACF,QAAO,UAAU,SAAY,WAAW,QAAQ,MAAM,GAAG"}
@@ -5,7 +5,7 @@ const require_parse_class_name = require('./parse-class-name.cjs');
5
5
  * Reads a theme entry from the class attribute on an element.
6
6
  *
7
7
  * @param themes - Record mapping theme keys to class name(s)
8
- * @param options.element - Element to read from (defaults to document.documentElement)
8
+ * @param options.element - Element to read from (accepts null e.g. from refs). Defaults to document.documentElement.
9
9
  * @param options.parse - Custom parser (default: parseClassName)
10
10
  * @returns ThemeEntry if found, undefined otherwise. Returns undefined when element is not available (e.g. SSR).
11
11
  */
@@ -1 +1 @@
1
- {"version":3,"file":"read-class-name.cjs","names":["parseClassName"],"sources":["../../../src/theme/class-name/read-class-name.ts"],"sourcesContent":["import type { ParseStoredTheme, ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport { parseClassName } from './parse-class-name.ts'\n\n/**\n * Reads a theme entry from the class attribute on an element.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param options.element - Element to read from (defaults to document.documentElement)\n * @param options.parse - Custom parser (default: parseClassName)\n * @returns ThemeEntry if found, undefined otherwise. Returns undefined when element is not available (e.g. SSR).\n */\nexport function readClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\toptions?:\n\t\t| { element?: Element | undefined; parse?: ParseStoredTheme<Themes> | undefined }\n\t\t| undefined\n): ThemeEntry<Themes> | undefined {\n\tconst element = options?.element ?? document?.documentElement\n\tif (!element) return undefined\n\tconst parse = options?.parse ?? parseClassName\n\tconst raw = element.className ?? undefined\n\treturn parse(themes, raw)\n}\n"],"mappings":";;;;;;;;;;;AAYA,SAAgB,cACf,QACA,SAGiC;CACjC,MAAM,UAAU,SAAS,WAAW,UAAU;AAC9C,KAAI,CAAC,QAAS,QAAO;AAGrB,SAFc,SAAS,SAASA,yCAEnB,QADD,QAAQ,aAAa,OACR"}
1
+ {"version":3,"file":"read-class-name.cjs","names":["parseClassName"],"sources":["../../../src/theme/class-name/read-class-name.ts"],"sourcesContent":["import type { ParseStoredTheme, ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport { parseClassName } from './parse-class-name.ts'\n\n/**\n * Reads a theme entry from the class attribute on an element.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param options.element - Element to read from (accepts null e.g. from refs). Defaults to document.documentElement.\n * @param options.parse - Custom parser (default: parseClassName)\n * @returns ThemeEntry if found, undefined otherwise. Returns undefined when element is not available (e.g. SSR).\n */\nexport function readClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\toptions?:\n\t\t| { element?: Element | null | undefined; parse?: ParseStoredTheme<Themes> | undefined }\n\t\t| undefined\n): ThemeEntry<Themes> | undefined {\n\tconst element = options?.element ?? document?.documentElement\n\tif (!element) return undefined\n\tconst parse = options?.parse ?? parseClassName\n\tconst raw = element.className ?? undefined\n\treturn parse(themes, raw)\n}\n"],"mappings":";;;;;;;;;;;AAYA,SAAgB,cACf,QACA,SAGiC;CACjC,MAAM,UAAU,SAAS,WAAW,UAAU;AAC9C,KAAI,CAAC,QAAS,QAAO;AAGrB,SAFc,SAAS,SAASA,yCAEnB,QADD,QAAQ,aAAa,OACR"}
@@ -7,12 +7,12 @@ import { ParseStoredTheme, ThemeEntry } from "../theme-entry.types.cjs";
7
7
  * Reads a theme entry from the class attribute on an element.
8
8
  *
9
9
  * @param themes - Record mapping theme keys to class name(s)
10
- * @param options.element - Element to read from (defaults to document.documentElement)
10
+ * @param options.element - Element to read from (accepts null e.g. from refs). Defaults to document.documentElement.
11
11
  * @param options.parse - Custom parser (default: parseClassName)
12
12
  * @returns ThemeEntry if found, undefined otherwise. Returns undefined when element is not available (e.g. SSR).
13
13
  */
14
14
  declare function readClassName<Themes extends ThemeMap>(themes: Themes, options?: {
15
- element?: Element | undefined;
15
+ element?: Element | null | undefined;
16
16
  parse?: ParseStoredTheme<Themes> | undefined;
17
17
  } | undefined): ThemeEntry<Themes> | undefined;
18
18
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"read-class-name.d.cts","names":[],"sources":["../../../src/theme/class-name/read-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAYA;;;;;;AAKc,iBALE,aAKF,CAAA,eAL+B,QAK/B,CAAA,CAAA,MAAA,EAJL,MAIK,EAAA,QAAA,EAAA;EAAX,OAAA,CAAA,EAFa,OAEb,GAAA,SAAA;EAAU,KAAA,CAAA,EAFgC,gBAEhC,CAFiD,MAEjD,CAAA,GAAA,SAAA;gBAAV,WAAW"}
1
+ {"version":3,"file":"read-class-name.d.cts","names":[],"sources":["../../../src/theme/class-name/read-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAYA;;;;;;AAKc,iBALE,aAKF,CAAA,eAL+B,QAK/B,CAAA,CAAA,MAAA,EAJL,MAIK,EAAA,QAAA,EAAA;EAAX,OAAA,CAAA,EAFa,OAEb,GAAA,IAAA,GAAA,SAAA;EAAU,KAAA,CAAA,EAFuC,gBAEvC,CAFwD,MAExD,CAAA,GAAA,SAAA;gBAAV,WAAW"}
@@ -7,12 +7,12 @@ import { ParseStoredTheme, ThemeEntry } from "../theme-entry.types.mjs";
7
7
  * Reads a theme entry from the class attribute on an element.
8
8
  *
9
9
  * @param themes - Record mapping theme keys to class name(s)
10
- * @param options.element - Element to read from (defaults to document.documentElement)
10
+ * @param options.element - Element to read from (accepts null e.g. from refs). Defaults to document.documentElement.
11
11
  * @param options.parse - Custom parser (default: parseClassName)
12
12
  * @returns ThemeEntry if found, undefined otherwise. Returns undefined when element is not available (e.g. SSR).
13
13
  */
14
14
  declare function readClassName<Themes extends ThemeMap>(themes: Themes, options?: {
15
- element?: Element | undefined;
15
+ element?: Element | null | undefined;
16
16
  parse?: ParseStoredTheme<Themes> | undefined;
17
17
  } | undefined): ThemeEntry<Themes> | undefined;
18
18
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"read-class-name.d.mts","names":[],"sources":["../../../src/theme/class-name/read-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAYA;;;;;;AAKc,iBALE,aAKF,CAAA,eAL+B,QAK/B,CAAA,CAAA,MAAA,EAJL,MAIK,EAAA,QAAA,EAAA;EAAX,OAAA,CAAA,EAFa,OAEb,GAAA,SAAA;EAAU,KAAA,CAAA,EAFgC,gBAEhC,CAFiD,MAEjD,CAAA,GAAA,SAAA;gBAAV,WAAW"}
1
+ {"version":3,"file":"read-class-name.d.mts","names":[],"sources":["../../../src/theme/class-name/read-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAYA;;;;;;AAKc,iBALE,aAKF,CAAA,eAL+B,QAK/B,CAAA,CAAA,MAAA,EAJL,MAIK,EAAA,QAAA,EAAA;EAAX,OAAA,CAAA,EAFa,OAEb,GAAA,IAAA,GAAA,SAAA;EAAU,KAAA,CAAA,EAFuC,gBAEvC,CAFwD,MAExD,CAAA,GAAA,SAAA;gBAAV,WAAW"}
@@ -5,7 +5,7 @@ import { parseClassName } from "./parse-class-name.mjs";
5
5
  * Reads a theme entry from the class attribute on an element.
6
6
  *
7
7
  * @param themes - Record mapping theme keys to class name(s)
8
- * @param options.element - Element to read from (defaults to document.documentElement)
8
+ * @param options.element - Element to read from (accepts null e.g. from refs). Defaults to document.documentElement.
9
9
  * @param options.parse - Custom parser (default: parseClassName)
10
10
  * @returns ThemeEntry if found, undefined otherwise. Returns undefined when element is not available (e.g. SSR).
11
11
  */
@@ -1 +1 @@
1
- {"version":3,"file":"read-class-name.mjs","names":[],"sources":["../../../src/theme/class-name/read-class-name.ts"],"sourcesContent":["import type { ParseStoredTheme, ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport { parseClassName } from './parse-class-name.ts'\n\n/**\n * Reads a theme entry from the class attribute on an element.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param options.element - Element to read from (defaults to document.documentElement)\n * @param options.parse - Custom parser (default: parseClassName)\n * @returns ThemeEntry if found, undefined otherwise. Returns undefined when element is not available (e.g. SSR).\n */\nexport function readClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\toptions?:\n\t\t| { element?: Element | undefined; parse?: ParseStoredTheme<Themes> | undefined }\n\t\t| undefined\n): ThemeEntry<Themes> | undefined {\n\tconst element = options?.element ?? document?.documentElement\n\tif (!element) return undefined\n\tconst parse = options?.parse ?? parseClassName\n\tconst raw = element.className ?? undefined\n\treturn parse(themes, raw)\n}\n"],"mappings":";;;;;;;;;;;AAYA,SAAgB,cACf,QACA,SAGiC;CACjC,MAAM,UAAU,SAAS,WAAW,UAAU;AAC9C,KAAI,CAAC,QAAS,QAAO;AAGrB,SAFc,SAAS,SAAS,gBAEnB,QADD,QAAQ,aAAa,OACR"}
1
+ {"version":3,"file":"read-class-name.mjs","names":[],"sources":["../../../src/theme/class-name/read-class-name.ts"],"sourcesContent":["import type { ParseStoredTheme, ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport { parseClassName } from './parse-class-name.ts'\n\n/**\n * Reads a theme entry from the class attribute on an element.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param options.element - Element to read from (accepts null e.g. from refs). Defaults to document.documentElement.\n * @param options.parse - Custom parser (default: parseClassName)\n * @returns ThemeEntry if found, undefined otherwise. Returns undefined when element is not available (e.g. SSR).\n */\nexport function readClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\toptions?:\n\t\t| { element?: Element | null | undefined; parse?: ParseStoredTheme<Themes> | undefined }\n\t\t| undefined\n): ThemeEntry<Themes> | undefined {\n\tconst element = options?.element ?? document?.documentElement\n\tif (!element) return undefined\n\tconst parse = options?.parse ?? parseClassName\n\tconst raw = element.className ?? undefined\n\treturn parse(themes, raw)\n}\n"],"mappings":";;;;;;;;;;;AAYA,SAAgB,cACf,QACA,SAGiC;CACjC,MAAM,UAAU,SAAS,WAAW,UAAU;AAC9C,KAAI,CAAC,QAAS,QAAO;AAGrB,SAFc,SAAS,SAAS,gBAEnB,QADD,QAAQ,aAAa,OACR"}
@@ -9,8 +9,8 @@ const require_resolve_theme_map_value = require('../_utils/resolve-theme-map-val
9
9
  * (unlike stringifyDataAttribute which uses first only).
10
10
  *
11
11
  * @param themes - Record mapping theme keys to class names (used to identify theme tokens)
12
- * @param existing - Current class attribute value string
13
- * @param entry - Theme entry to stringify, or undefined to clear theme (keeps non-theme classes)
12
+ * @param existing - Current class attribute value string (accepts null)
13
+ * @param entry - Theme entry to stringify, or null/undefined to clear theme (keeps non-theme classes)
14
14
  * @returns Class attribute value string
15
15
  */
16
16
  function stringifyClassName(themes, existing, entry) {
@@ -18,8 +18,8 @@ function stringifyClassName(themes, existing, entry) {
18
18
  const resolved = require_resolve_theme_map_value.resolveThemeMapValue(v);
19
19
  return Array.isArray(resolved) ? [...resolved] : [resolved];
20
20
  });
21
- const withoutThemes = (existing?.trim() ? existing.trim().split(/\s+/) : []).filter((c) => !allThemeClasses.includes(c));
22
- const activeClasses = entry !== void 0 ? (() => {
21
+ const withoutThemes = ((existing ?? "")?.trim() ? (existing ?? "").trim().split(/\s+/) : []).filter((c) => !allThemeClasses.includes(c));
22
+ const activeClasses = entry != null ? (() => {
23
23
  const resolved = require_resolve_theme_map_value.resolveThemeMapValue(entry.value);
24
24
  return Array.isArray(resolved) ? [...resolved] : [resolved];
25
25
  })() : [];
@@ -1 +1 @@
1
- {"version":3,"file":"stringify-class-name.cjs","names":["resolveThemeMapValue"],"sources":["../../../src/theme/class-name/stringify-class-name.ts"],"sourcesContent":["import { resolveThemeMapValue } from '../_utils/resolve-theme-map-value.ts'\nimport type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\n\n/**\n * Stringifies a ThemeEntry for a class attribute value.\n *\n * Pure function: no DOM access. Removes all theme classes from existing, then\n * adds entry's class(es). Applies all classes from entry when value is an array\n * (unlike stringifyDataAttribute which uses first only).\n *\n * @param themes - Record mapping theme keys to class names (used to identify theme tokens)\n * @param existing - Current class attribute value string\n * @param entry - Theme entry to stringify, or undefined to clear theme (keeps non-theme classes)\n * @returns Class attribute value string\n */\nexport function stringifyClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\texisting: string | undefined,\n\tentry: ThemeEntry<Themes> | undefined\n): string {\n\tconst allThemeClasses = Object.values(themes).flatMap((v) => {\n\t\tconst resolved = resolveThemeMapValue(v)\n\t\treturn Array.isArray(resolved) ? [...resolved] : [resolved]\n\t})\n\tconst existingClasses = existing?.trim() ? existing.trim().split(/\\s+/) : []\n\tconst withoutThemes = existingClasses.filter((c) => !allThemeClasses.includes(c))\n\tconst activeClasses =\n\t\tentry !== undefined\n\t\t\t? (() => {\n\t\t\t\t\tconst resolved = resolveThemeMapValue(entry.value)\n\t\t\t\t\treturn Array.isArray(resolved) ? [...resolved] : [resolved]\n\t\t\t\t})()\n\t\t\t: []\n\treturn [...withoutThemes, ...activeClasses].filter(Boolean).join(' ')\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,SAAgB,mBACf,QACA,UACA,OACS;CACT,MAAM,kBAAkB,OAAO,OAAO,OAAO,CAAC,SAAS,MAAM;EAC5D,MAAM,WAAWA,qDAAqB,EAAE;AACxC,SAAO,MAAM,QAAQ,SAAS,GAAG,CAAC,GAAG,SAAS,GAAG,CAAC,SAAS;GAC1D;CAEF,MAAM,iBADkB,UAAU,MAAM,GAAG,SAAS,MAAM,CAAC,MAAM,MAAM,GAAG,EAAE,EACtC,QAAQ,MAAM,CAAC,gBAAgB,SAAS,EAAE,CAAC;CACjF,MAAM,gBACL,UAAU,gBACA;EACP,MAAM,WAAWA,qDAAqB,MAAM,MAAM;AAClD,SAAO,MAAM,QAAQ,SAAS,GAAG,CAAC,GAAG,SAAS,GAAG,CAAC,SAAS;KACxD,GACH,EAAE;AACN,QAAO,CAAC,GAAG,eAAe,GAAG,cAAc,CAAC,OAAO,QAAQ,CAAC,KAAK,IAAI"}
1
+ {"version":3,"file":"stringify-class-name.cjs","names":["resolveThemeMapValue"],"sources":["../../../src/theme/class-name/stringify-class-name.ts"],"sourcesContent":["import { resolveThemeMapValue } from '../_utils/resolve-theme-map-value.ts'\nimport type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\n\n/**\n * Stringifies a ThemeEntry for a class attribute value.\n *\n * Pure function: no DOM access. Removes all theme classes from existing, then\n * adds entry's class(es). Applies all classes from entry when value is an array\n * (unlike stringifyDataAttribute which uses first only).\n *\n * @param themes - Record mapping theme keys to class names (used to identify theme tokens)\n * @param existing - Current class attribute value string (accepts null)\n * @param entry - Theme entry to stringify, or null/undefined to clear theme (keeps non-theme classes)\n * @returns Class attribute value string\n */\nexport function stringifyClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\texisting: string | null | undefined,\n\tentry: ThemeEntry<Themes> | null | undefined\n): string {\n\tconst allThemeClasses = Object.values(themes).flatMap((v) => {\n\t\tconst resolved = resolveThemeMapValue(v)\n\t\treturn Array.isArray(resolved) ? [...resolved] : [resolved]\n\t})\n\tconst existingClasses = (existing ?? '')?.trim() ? (existing ?? '').trim().split(/\\s+/) : []\n\tconst withoutThemes = existingClasses.filter((c) => !allThemeClasses.includes(c))\n\tconst activeClasses =\n\t\tentry != null\n\t\t\t? (() => {\n\t\t\t\t\tconst resolved = resolveThemeMapValue(entry.value)\n\t\t\t\t\treturn Array.isArray(resolved) ? [...resolved] : [resolved]\n\t\t\t\t})()\n\t\t\t: []\n\treturn [...withoutThemes, ...activeClasses].filter(Boolean).join(' ')\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,SAAgB,mBACf,QACA,UACA,OACS;CACT,MAAM,kBAAkB,OAAO,OAAO,OAAO,CAAC,SAAS,MAAM;EAC5D,MAAM,WAAWA,qDAAqB,EAAE;AACxC,SAAO,MAAM,QAAQ,SAAS,GAAG,CAAC,GAAG,SAAS,GAAG,CAAC,SAAS;GAC1D;CAEF,MAAM,kBADmB,YAAY,KAAK,MAAM,IAAI,YAAY,IAAI,MAAM,CAAC,MAAM,MAAM,GAAG,EAAE,EACtD,QAAQ,MAAM,CAAC,gBAAgB,SAAS,EAAE,CAAC;CACjF,MAAM,gBACL,SAAS,cACC;EACP,MAAM,WAAWA,qDAAqB,MAAM,MAAM;AAClD,SAAO,MAAM,QAAQ,SAAS,GAAG,CAAC,GAAG,SAAS,GAAG,CAAC,SAAS;KACxD,GACH,EAAE;AACN,QAAO,CAAC,GAAG,eAAe,GAAG,cAAc,CAAC,OAAO,QAAQ,CAAC,KAAK,IAAI"}
@@ -11,11 +11,11 @@ import { ThemeEntry } from "../theme-entry.types.cjs";
11
11
  * (unlike stringifyDataAttribute which uses first only).
12
12
  *
13
13
  * @param themes - Record mapping theme keys to class names (used to identify theme tokens)
14
- * @param existing - Current class attribute value string
15
- * @param entry - Theme entry to stringify, or undefined to clear theme (keeps non-theme classes)
14
+ * @param existing - Current class attribute value string (accepts null)
15
+ * @param entry - Theme entry to stringify, or null/undefined to clear theme (keeps non-theme classes)
16
16
  * @returns Class attribute value string
17
17
  */
18
- declare function stringifyClassName<Themes extends ThemeMap>(themes: Themes, existing: string | undefined, entry: ThemeEntry<Themes> | undefined): string;
18
+ declare function stringifyClassName<Themes extends ThemeMap>(themes: Themes, existing: string | null | undefined, entry: ThemeEntry<Themes> | null | undefined): string;
19
19
  //#endregion
20
20
  export { stringifyClassName };
21
21
  //# sourceMappingURL=stringify-class-name.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stringify-class-name.d.cts","names":[],"sources":["../../../src/theme/class-name/stringify-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAgBA;;;;;;;;;;iBAAgB,kCAAkC,kBACzC,6CAED,WAAW"}
1
+ {"version":3,"file":"stringify-class-name.d.cts","names":[],"sources":["../../../src/theme/class-name/stringify-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAgBA;;;;;;;;;;iBAAgB,kCAAkC,kBACzC,oDAED,WAAW"}
@@ -11,11 +11,11 @@ import { ThemeEntry } from "../theme-entry.types.mjs";
11
11
  * (unlike stringifyDataAttribute which uses first only).
12
12
  *
13
13
  * @param themes - Record mapping theme keys to class names (used to identify theme tokens)
14
- * @param existing - Current class attribute value string
15
- * @param entry - Theme entry to stringify, or undefined to clear theme (keeps non-theme classes)
14
+ * @param existing - Current class attribute value string (accepts null)
15
+ * @param entry - Theme entry to stringify, or null/undefined to clear theme (keeps non-theme classes)
16
16
  * @returns Class attribute value string
17
17
  */
18
- declare function stringifyClassName<Themes extends ThemeMap>(themes: Themes, existing: string | undefined, entry: ThemeEntry<Themes> | undefined): string;
18
+ declare function stringifyClassName<Themes extends ThemeMap>(themes: Themes, existing: string | null | undefined, entry: ThemeEntry<Themes> | null | undefined): string;
19
19
  //#endregion
20
20
  export { stringifyClassName };
21
21
  //# sourceMappingURL=stringify-class-name.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stringify-class-name.d.mts","names":[],"sources":["../../../src/theme/class-name/stringify-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAgBA;;;;;;;;;;iBAAgB,kCAAkC,kBACzC,6CAED,WAAW"}
1
+ {"version":3,"file":"stringify-class-name.d.mts","names":[],"sources":["../../../src/theme/class-name/stringify-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAgBA;;;;;;;;;;iBAAgB,kCAAkC,kBACzC,oDAED,WAAW"}
@@ -9,8 +9,8 @@ import { resolveThemeMapValue } from "../_utils/resolve-theme-map-value.mjs";
9
9
  * (unlike stringifyDataAttribute which uses first only).
10
10
  *
11
11
  * @param themes - Record mapping theme keys to class names (used to identify theme tokens)
12
- * @param existing - Current class attribute value string
13
- * @param entry - Theme entry to stringify, or undefined to clear theme (keeps non-theme classes)
12
+ * @param existing - Current class attribute value string (accepts null)
13
+ * @param entry - Theme entry to stringify, or null/undefined to clear theme (keeps non-theme classes)
14
14
  * @returns Class attribute value string
15
15
  */
16
16
  function stringifyClassName(themes, existing, entry) {
@@ -18,8 +18,8 @@ function stringifyClassName(themes, existing, entry) {
18
18
  const resolved = resolveThemeMapValue(v);
19
19
  return Array.isArray(resolved) ? [...resolved] : [resolved];
20
20
  });
21
- const withoutThemes = (existing?.trim() ? existing.trim().split(/\s+/) : []).filter((c) => !allThemeClasses.includes(c));
22
- const activeClasses = entry !== void 0 ? (() => {
21
+ const withoutThemes = ((existing ?? "")?.trim() ? (existing ?? "").trim().split(/\s+/) : []).filter((c) => !allThemeClasses.includes(c));
22
+ const activeClasses = entry != null ? (() => {
23
23
  const resolved = resolveThemeMapValue(entry.value);
24
24
  return Array.isArray(resolved) ? [...resolved] : [resolved];
25
25
  })() : [];
@@ -1 +1 @@
1
- {"version":3,"file":"stringify-class-name.mjs","names":[],"sources":["../../../src/theme/class-name/stringify-class-name.ts"],"sourcesContent":["import { resolveThemeMapValue } from '../_utils/resolve-theme-map-value.ts'\nimport type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\n\n/**\n * Stringifies a ThemeEntry for a class attribute value.\n *\n * Pure function: no DOM access. Removes all theme classes from existing, then\n * adds entry's class(es). Applies all classes from entry when value is an array\n * (unlike stringifyDataAttribute which uses first only).\n *\n * @param themes - Record mapping theme keys to class names (used to identify theme tokens)\n * @param existing - Current class attribute value string\n * @param entry - Theme entry to stringify, or undefined to clear theme (keeps non-theme classes)\n * @returns Class attribute value string\n */\nexport function stringifyClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\texisting: string | undefined,\n\tentry: ThemeEntry<Themes> | undefined\n): string {\n\tconst allThemeClasses = Object.values(themes).flatMap((v) => {\n\t\tconst resolved = resolveThemeMapValue(v)\n\t\treturn Array.isArray(resolved) ? [...resolved] : [resolved]\n\t})\n\tconst existingClasses = existing?.trim() ? existing.trim().split(/\\s+/) : []\n\tconst withoutThemes = existingClasses.filter((c) => !allThemeClasses.includes(c))\n\tconst activeClasses =\n\t\tentry !== undefined\n\t\t\t? (() => {\n\t\t\t\t\tconst resolved = resolveThemeMapValue(entry.value)\n\t\t\t\t\treturn Array.isArray(resolved) ? [...resolved] : [resolved]\n\t\t\t\t})()\n\t\t\t: []\n\treturn [...withoutThemes, ...activeClasses].filter(Boolean).join(' ')\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,SAAgB,mBACf,QACA,UACA,OACS;CACT,MAAM,kBAAkB,OAAO,OAAO,OAAO,CAAC,SAAS,MAAM;EAC5D,MAAM,WAAW,qBAAqB,EAAE;AACxC,SAAO,MAAM,QAAQ,SAAS,GAAG,CAAC,GAAG,SAAS,GAAG,CAAC,SAAS;GAC1D;CAEF,MAAM,iBADkB,UAAU,MAAM,GAAG,SAAS,MAAM,CAAC,MAAM,MAAM,GAAG,EAAE,EACtC,QAAQ,MAAM,CAAC,gBAAgB,SAAS,EAAE,CAAC;CACjF,MAAM,gBACL,UAAU,gBACA;EACP,MAAM,WAAW,qBAAqB,MAAM,MAAM;AAClD,SAAO,MAAM,QAAQ,SAAS,GAAG,CAAC,GAAG,SAAS,GAAG,CAAC,SAAS;KACxD,GACH,EAAE;AACN,QAAO,CAAC,GAAG,eAAe,GAAG,cAAc,CAAC,OAAO,QAAQ,CAAC,KAAK,IAAI"}
1
+ {"version":3,"file":"stringify-class-name.mjs","names":[],"sources":["../../../src/theme/class-name/stringify-class-name.ts"],"sourcesContent":["import { resolveThemeMapValue } from '../_utils/resolve-theme-map-value.ts'\nimport type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\n\n/**\n * Stringifies a ThemeEntry for a class attribute value.\n *\n * Pure function: no DOM access. Removes all theme classes from existing, then\n * adds entry's class(es). Applies all classes from entry when value is an array\n * (unlike stringifyDataAttribute which uses first only).\n *\n * @param themes - Record mapping theme keys to class names (used to identify theme tokens)\n * @param existing - Current class attribute value string (accepts null)\n * @param entry - Theme entry to stringify, or null/undefined to clear theme (keeps non-theme classes)\n * @returns Class attribute value string\n */\nexport function stringifyClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\texisting: string | null | undefined,\n\tentry: ThemeEntry<Themes> | null | undefined\n): string {\n\tconst allThemeClasses = Object.values(themes).flatMap((v) => {\n\t\tconst resolved = resolveThemeMapValue(v)\n\t\treturn Array.isArray(resolved) ? [...resolved] : [resolved]\n\t})\n\tconst existingClasses = (existing ?? '')?.trim() ? (existing ?? '').trim().split(/\\s+/) : []\n\tconst withoutThemes = existingClasses.filter((c) => !allThemeClasses.includes(c))\n\tconst activeClasses =\n\t\tentry != null\n\t\t\t? (() => {\n\t\t\t\t\tconst resolved = resolveThemeMapValue(entry.value)\n\t\t\t\t\treturn Array.isArray(resolved) ? [...resolved] : [resolved]\n\t\t\t\t})()\n\t\t\t: []\n\treturn [...withoutThemes, ...activeClasses].filter(Boolean).join(' ')\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,SAAgB,mBACf,QACA,UACA,OACS;CACT,MAAM,kBAAkB,OAAO,OAAO,OAAO,CAAC,SAAS,MAAM;EAC5D,MAAM,WAAW,qBAAqB,EAAE;AACxC,SAAO,MAAM,QAAQ,SAAS,GAAG,CAAC,GAAG,SAAS,GAAG,CAAC,SAAS;GAC1D;CAEF,MAAM,kBADmB,YAAY,KAAK,MAAM,IAAI,YAAY,IAAI,MAAM,CAAC,MAAM,MAAM,GAAG,EAAE,EACtD,QAAQ,MAAM,CAAC,gBAAgB,SAAS,EAAE,CAAC;CACjF,MAAM,gBACL,SAAS,cACC;EACP,MAAM,WAAW,qBAAqB,MAAM,MAAM;AAClD,SAAO,MAAM,QAAQ,SAAS,GAAG,CAAC,GAAG,SAAS,GAAG,CAAC,SAAS;KACxD,GACH,EAAE;AACN,QAAO,CAAC,GAAG,eAAe,GAAG,cAAc,CAAC,OAAO,QAAQ,CAAC,KAAK,IAAI"}
@@ -7,7 +7,7 @@ const require_parse_class_name = require('./parse-class-name.cjs');
7
7
  *
8
8
  * @param themes - Record mapping theme keys to class name(s)
9
9
  * @param handler - Callback invoked when the class attribute changes
10
- * @param options.element - Element to observe (defaults to document.documentElement)
10
+ * @param options.element - Element to observe (accepts null e.g. from refs). Defaults to document.documentElement.
11
11
  * @param options.parse - Custom parser (default: parseClassName)
12
12
  * @returns Unsubscribe function. Returns a no-op function when element is not available (e.g. SSR).
13
13
  */
@@ -16,14 +16,13 @@ function subscribeClassName(themes, handler, options) {
16
16
  if (!element) return () => {};
17
17
  const parse = options?.parse ?? require_parse_class_name.parseClassName;
18
18
  let lastEmitted = null;
19
- const observer = require_observe_attribute.observeAttributes({ class: (value) => {
19
+ return require_observe_attribute.observeAttributes({ class: (value) => {
20
20
  const entry = parse(themes, value ?? void 0);
21
21
  const key = entry?.theme ?? void 0;
22
22
  if (lastEmitted === key) return;
23
23
  lastEmitted = key;
24
24
  handler(entry);
25
25
  } }, element);
26
- return () => observer.disconnect();
27
26
  }
28
27
 
29
28
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"subscribe-class-name.cjs","names":["parseClassName","lastEmitted: keyof Themes | undefined | null","observeAttributes"],"sources":["../../../src/theme/class-name/subscribe-class-name.ts"],"sourcesContent":["import { observeAttributes } from '../../attributes/observe-attribute.ts'\nimport type { ParseStoredTheme, ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport { parseClassName } from './parse-class-name.ts'\n\n/**\n * Subscribes to changes on the class attribute and invokes the handler with parsed theme entries.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param handler - Callback invoked when the class attribute changes\n * @param options.element - Element to observe (defaults to document.documentElement)\n * @param options.parse - Custom parser (default: parseClassName)\n * @returns Unsubscribe function. Returns a no-op function when element is not available (e.g. SSR).\n */\nexport function subscribeClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\thandler: (entry: ThemeEntry<Themes> | undefined) => void,\n\toptions?:\n\t\t| { element?: Element | undefined; parse?: ParseStoredTheme<Themes> | undefined }\n\t\t| undefined\n): () => void {\n\tconst element = options?.element ?? document?.documentElement\n\tif (!element) return () => {}\n\tconst parse = options?.parse ?? parseClassName\n\tlet lastEmitted: keyof Themes | undefined | null = null\n\tconst observer = observeAttributes(\n\t\t{\n\t\t\tclass: (value) => {\n\t\t\t\tconst entry = parse(themes, value ?? undefined)\n\t\t\t\tconst key = entry?.theme ?? undefined\n\t\t\t\tif (lastEmitted === key) return\n\t\t\t\tlastEmitted = key\n\t\t\t\thandler(entry)\n\t\t\t}\n\t\t},\n\t\telement\n\t)\n\treturn () => observer.disconnect()\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,SAAgB,mBACf,QACA,SACA,SAGa;CACb,MAAM,UAAU,SAAS,WAAW,UAAU;AAC9C,KAAI,CAAC,QAAS,cAAa;CAC3B,MAAM,QAAQ,SAAS,SAASA;CAChC,IAAIC,cAA+C;CACnD,MAAM,WAAWC,4CAChB,EACC,QAAQ,UAAU;EACjB,MAAM,QAAQ,MAAM,QAAQ,SAAS,OAAU;EAC/C,MAAM,MAAM,OAAO,SAAS;AAC5B,MAAI,gBAAgB,IAAK;AACzB,gBAAc;AACd,UAAQ,MAAM;IAEf,EACD,QACA;AACD,cAAa,SAAS,YAAY"}
1
+ {"version":3,"file":"subscribe-class-name.cjs","names":["parseClassName","lastEmitted: keyof Themes | undefined | null","observeAttributes"],"sources":["../../../src/theme/class-name/subscribe-class-name.ts"],"sourcesContent":["import { observeAttributes } from '../../attributes/observe-attribute.ts'\nimport type { ParseStoredTheme, ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport { parseClassName } from './parse-class-name.ts'\n\n/**\n * Subscribes to changes on the class attribute and invokes the handler with parsed theme entries.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param handler - Callback invoked when the class attribute changes\n * @param options.element - Element to observe (accepts null e.g. from refs). Defaults to document.documentElement.\n * @param options.parse - Custom parser (default: parseClassName)\n * @returns Unsubscribe function. Returns a no-op function when element is not available (e.g. SSR).\n */\nexport function subscribeClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\thandler: (entry: ThemeEntry<Themes> | undefined) => void,\n\toptions?:\n\t\t| { element?: Element | null | undefined; parse?: ParseStoredTheme<Themes> | undefined }\n\t\t| undefined\n): () => void {\n\tconst element = options?.element ?? document?.documentElement\n\tif (!element) return () => {}\n\tconst parse = options?.parse ?? parseClassName\n\tlet lastEmitted: keyof Themes | undefined | null = null\n\treturn observeAttributes(\n\t\t{\n\t\t\tclass: (value) => {\n\t\t\t\tconst entry = parse(themes, value ?? undefined)\n\t\t\t\tconst key = entry?.theme ?? undefined\n\t\t\t\tif (lastEmitted === key) return\n\t\t\t\tlastEmitted = key\n\t\t\t\thandler(entry)\n\t\t\t}\n\t\t},\n\t\telement\n\t)\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,SAAgB,mBACf,QACA,SACA,SAGa;CACb,MAAM,UAAU,SAAS,WAAW,UAAU;AAC9C,KAAI,CAAC,QAAS,cAAa;CAC3B,MAAM,QAAQ,SAAS,SAASA;CAChC,IAAIC,cAA+C;AACnD,QAAOC,4CACN,EACC,QAAQ,UAAU;EACjB,MAAM,QAAQ,MAAM,QAAQ,SAAS,OAAU;EAC/C,MAAM,MAAM,OAAO,SAAS;AAC5B,MAAI,gBAAgB,IAAK;AACzB,gBAAc;AACd,UAAQ,MAAM;IAEf,EACD,QACA"}
@@ -8,12 +8,12 @@ import { ParseStoredTheme, ThemeEntry } from "../theme-entry.types.cjs";
8
8
  *
9
9
  * @param themes - Record mapping theme keys to class name(s)
10
10
  * @param handler - Callback invoked when the class attribute changes
11
- * @param options.element - Element to observe (defaults to document.documentElement)
11
+ * @param options.element - Element to observe (accepts null e.g. from refs). Defaults to document.documentElement.
12
12
  * @param options.parse - Custom parser (default: parseClassName)
13
13
  * @returns Unsubscribe function. Returns a no-op function when element is not available (e.g. SSR).
14
14
  */
15
15
  declare function subscribeClassName<Themes extends ThemeMap>(themes: Themes, handler: (entry: ThemeEntry<Themes> | undefined) => void, options?: {
16
- element?: Element | undefined;
16
+ element?: Element | null | undefined;
17
17
  parse?: ParseStoredTheme<Themes> | undefined;
18
18
  } | undefined): () => void;
19
19
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"subscribe-class-name.d.cts","names":[],"sources":["../../../src/theme/class-name/subscribe-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAcA;;;;;;;AAI6C,iBAJ7B,kBAI6B,CAAA,eAJK,QAIL,CAAA,CAAA,MAAA,EAHpC,MAGoC,EAAA,OAAA,EAAA,CAAA,KAAA,EAF3B,UAE2B,CAFhB,MAEgB,CAAA,GAAA,SAAA,EAAA,GAAA,IAAA,EAAA,QAAA,EAAA;EAAgB,OAAA,CAAA,EAA7C,OAA6C,GAAA,SAAA;UAAhB,iBAAiB"}
1
+ {"version":3,"file":"subscribe-class-name.d.cts","names":[],"sources":["../../../src/theme/class-name/subscribe-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAcA;;;;;;;AAIoD,iBAJpC,kBAIoC,CAAA,eAJF,QAIE,CAAA,CAAA,MAAA,EAH3C,MAG2C,EAAA,OAAA,EAAA,CAAA,KAAA,EAFlC,UAEkC,CAFvB,MAEuB,CAAA,GAAA,SAAA,EAAA,GAAA,IAAA,EAAA,QAAA,EAAA;EAAgB,OAAA,CAAA,EAApD,OAAoD,GAAA,IAAA,GAAA,SAAA;UAAhB,iBAAiB"}
@@ -8,12 +8,12 @@ import { ParseStoredTheme, ThemeEntry } from "../theme-entry.types.mjs";
8
8
  *
9
9
  * @param themes - Record mapping theme keys to class name(s)
10
10
  * @param handler - Callback invoked when the class attribute changes
11
- * @param options.element - Element to observe (defaults to document.documentElement)
11
+ * @param options.element - Element to observe (accepts null e.g. from refs). Defaults to document.documentElement.
12
12
  * @param options.parse - Custom parser (default: parseClassName)
13
13
  * @returns Unsubscribe function. Returns a no-op function when element is not available (e.g. SSR).
14
14
  */
15
15
  declare function subscribeClassName<Themes extends ThemeMap>(themes: Themes, handler: (entry: ThemeEntry<Themes> | undefined) => void, options?: {
16
- element?: Element | undefined;
16
+ element?: Element | null | undefined;
17
17
  parse?: ParseStoredTheme<Themes> | undefined;
18
18
  } | undefined): () => void;
19
19
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"subscribe-class-name.d.mts","names":[],"sources":["../../../src/theme/class-name/subscribe-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAcA;;;;;;;AAI6C,iBAJ7B,kBAI6B,CAAA,eAJK,QAIL,CAAA,CAAA,MAAA,EAHpC,MAGoC,EAAA,OAAA,EAAA,CAAA,KAAA,EAF3B,UAE2B,CAFhB,MAEgB,CAAA,GAAA,SAAA,EAAA,GAAA,IAAA,EAAA,QAAA,EAAA;EAAgB,OAAA,CAAA,EAA7C,OAA6C,GAAA,SAAA;UAAhB,iBAAiB"}
1
+ {"version":3,"file":"subscribe-class-name.d.mts","names":[],"sources":["../../../src/theme/class-name/subscribe-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAcA;;;;;;;AAIoD,iBAJpC,kBAIoC,CAAA,eAJF,QAIE,CAAA,CAAA,MAAA,EAH3C,MAG2C,EAAA,OAAA,EAAA,CAAA,KAAA,EAFlC,UAEkC,CAFvB,MAEuB,CAAA,GAAA,SAAA,EAAA,GAAA,IAAA,EAAA,QAAA,EAAA;EAAgB,OAAA,CAAA,EAApD,OAAoD,GAAA,IAAA,GAAA,SAAA;UAAhB,iBAAiB"}
@@ -7,7 +7,7 @@ import { parseClassName } from "./parse-class-name.mjs";
7
7
  *
8
8
  * @param themes - Record mapping theme keys to class name(s)
9
9
  * @param handler - Callback invoked when the class attribute changes
10
- * @param options.element - Element to observe (defaults to document.documentElement)
10
+ * @param options.element - Element to observe (accepts null e.g. from refs). Defaults to document.documentElement.
11
11
  * @param options.parse - Custom parser (default: parseClassName)
12
12
  * @returns Unsubscribe function. Returns a no-op function when element is not available (e.g. SSR).
13
13
  */
@@ -16,14 +16,13 @@ function subscribeClassName(themes, handler, options) {
16
16
  if (!element) return () => {};
17
17
  const parse = options?.parse ?? parseClassName;
18
18
  let lastEmitted = null;
19
- const observer = observeAttributes({ class: (value) => {
19
+ return observeAttributes({ class: (value) => {
20
20
  const entry = parse(themes, value ?? void 0);
21
21
  const key = entry?.theme ?? void 0;
22
22
  if (lastEmitted === key) return;
23
23
  lastEmitted = key;
24
24
  handler(entry);
25
25
  } }, element);
26
- return () => observer.disconnect();
27
26
  }
28
27
 
29
28
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"subscribe-class-name.mjs","names":["lastEmitted: keyof Themes | undefined | null"],"sources":["../../../src/theme/class-name/subscribe-class-name.ts"],"sourcesContent":["import { observeAttributes } from '../../attributes/observe-attribute.ts'\nimport type { ParseStoredTheme, ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport { parseClassName } from './parse-class-name.ts'\n\n/**\n * Subscribes to changes on the class attribute and invokes the handler with parsed theme entries.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param handler - Callback invoked when the class attribute changes\n * @param options.element - Element to observe (defaults to document.documentElement)\n * @param options.parse - Custom parser (default: parseClassName)\n * @returns Unsubscribe function. Returns a no-op function when element is not available (e.g. SSR).\n */\nexport function subscribeClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\thandler: (entry: ThemeEntry<Themes> | undefined) => void,\n\toptions?:\n\t\t| { element?: Element | undefined; parse?: ParseStoredTheme<Themes> | undefined }\n\t\t| undefined\n): () => void {\n\tconst element = options?.element ?? document?.documentElement\n\tif (!element) return () => {}\n\tconst parse = options?.parse ?? parseClassName\n\tlet lastEmitted: keyof Themes | undefined | null = null\n\tconst observer = observeAttributes(\n\t\t{\n\t\t\tclass: (value) => {\n\t\t\t\tconst entry = parse(themes, value ?? undefined)\n\t\t\t\tconst key = entry?.theme ?? undefined\n\t\t\t\tif (lastEmitted === key) return\n\t\t\t\tlastEmitted = key\n\t\t\t\thandler(entry)\n\t\t\t}\n\t\t},\n\t\telement\n\t)\n\treturn () => observer.disconnect()\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,SAAgB,mBACf,QACA,SACA,SAGa;CACb,MAAM,UAAU,SAAS,WAAW,UAAU;AAC9C,KAAI,CAAC,QAAS,cAAa;CAC3B,MAAM,QAAQ,SAAS,SAAS;CAChC,IAAIA,cAA+C;CACnD,MAAM,WAAW,kBAChB,EACC,QAAQ,UAAU;EACjB,MAAM,QAAQ,MAAM,QAAQ,SAAS,OAAU;EAC/C,MAAM,MAAM,OAAO,SAAS;AAC5B,MAAI,gBAAgB,IAAK;AACzB,gBAAc;AACd,UAAQ,MAAM;IAEf,EACD,QACA;AACD,cAAa,SAAS,YAAY"}
1
+ {"version":3,"file":"subscribe-class-name.mjs","names":["lastEmitted: keyof Themes | undefined | null"],"sources":["../../../src/theme/class-name/subscribe-class-name.ts"],"sourcesContent":["import { observeAttributes } from '../../attributes/observe-attribute.ts'\nimport type { ParseStoredTheme, ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport { parseClassName } from './parse-class-name.ts'\n\n/**\n * Subscribes to changes on the class attribute and invokes the handler with parsed theme entries.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param handler - Callback invoked when the class attribute changes\n * @param options.element - Element to observe (accepts null e.g. from refs). Defaults to document.documentElement.\n * @param options.parse - Custom parser (default: parseClassName)\n * @returns Unsubscribe function. Returns a no-op function when element is not available (e.g. SSR).\n */\nexport function subscribeClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\thandler: (entry: ThemeEntry<Themes> | undefined) => void,\n\toptions?:\n\t\t| { element?: Element | null | undefined; parse?: ParseStoredTheme<Themes> | undefined }\n\t\t| undefined\n): () => void {\n\tconst element = options?.element ?? document?.documentElement\n\tif (!element) return () => {}\n\tconst parse = options?.parse ?? parseClassName\n\tlet lastEmitted: keyof Themes | undefined | null = null\n\treturn observeAttributes(\n\t\t{\n\t\t\tclass: (value) => {\n\t\t\t\tconst entry = parse(themes, value ?? undefined)\n\t\t\t\tconst key = entry?.theme ?? undefined\n\t\t\t\tif (lastEmitted === key) return\n\t\t\t\tlastEmitted = key\n\t\t\t\thandler(entry)\n\t\t\t}\n\t\t},\n\t\telement\n\t)\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,SAAgB,mBACf,QACA,SACA,SAGa;CACb,MAAM,UAAU,SAAS,WAAW,UAAU;AAC9C,KAAI,CAAC,QAAS,cAAa;CAC3B,MAAM,QAAQ,SAAS,SAAS;CAChC,IAAIA,cAA+C;AACnD,QAAO,kBACN,EACC,QAAQ,UAAU;EACjB,MAAM,QAAQ,MAAM,QAAQ,SAAS,OAAU;EAC/C,MAAM,MAAM,OAAO,SAAS;AAC5B,MAAI,gBAAgB,IAAK;AACzB,gBAAc;AACd,UAAQ,MAAM;IAEf,EACD,QACA"}
@@ -5,8 +5,8 @@ const require_stringify_class_name = require('./stringify-class-name.cjs');
5
5
  * Writes a theme entry to the class attribute on an element.
6
6
  *
7
7
  * @param themes - Record mapping theme keys to class name(s)
8
- * @param entry - Theme entry to write, or undefined to remove the theme
9
- * @param options.element - Element to write to (defaults to document.documentElement)
8
+ * @param entry - Theme entry to write, or null/undefined to remove the theme
9
+ * @param options.element - Element to write to (accepts null e.g. from refs). Defaults to document.documentElement.
10
10
  * @param options.stringify - Custom serializer (default: stringifyClassName)
11
11
  */
12
12
  function writeClassName(themes, entry, options) {