@just-web/toolkits 1.0.0 → 2.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 (315) hide show
  1. package/dist/react/hooks/use-theme-by-class-name.cjs +1 -5
  2. package/dist/react/hooks/use-theme-by-class-name.cjs.map +1 -1
  3. package/dist/react/hooks/use-theme-by-class-name.d.cts.map +1 -1
  4. package/dist/react/hooks/use-theme-by-class-name.d.mts.map +1 -1
  5. package/dist/react/hooks/use-theme-by-class-name.mjs +1 -5
  6. package/dist/react/hooks/use-theme-by-class-name.mjs.map +1 -1
  7. package/dist/react/hooks/use-theme-by-data-attribute.cjs +1 -6
  8. package/dist/react/hooks/use-theme-by-data-attribute.cjs.map +1 -1
  9. package/dist/react/hooks/use-theme-by-data-attribute.d.cts.map +1 -1
  10. package/dist/react/hooks/use-theme-by-data-attribute.d.mts.map +1 -1
  11. package/dist/react/hooks/use-theme-by-data-attribute.mjs +1 -6
  12. package/dist/react/hooks/use-theme-by-data-attribute.mjs.map +1 -1
  13. package/dist/react/hooks/use-theme-by-local-storage.cjs +1 -5
  14. package/dist/react/hooks/use-theme-by-local-storage.cjs.map +1 -1
  15. package/dist/react/hooks/use-theme-by-local-storage.d.cts.map +1 -1
  16. package/dist/react/hooks/use-theme-by-local-storage.d.mts.map +1 -1
  17. package/dist/react/hooks/use-theme-by-local-storage.mjs +1 -5
  18. package/dist/react/hooks/use-theme-by-local-storage.mjs.map +1 -1
  19. package/dist/theme/_utils/match-attribute-value-to-theme.cjs +29 -0
  20. package/dist/theme/_utils/match-attribute-value-to-theme.cjs.map +1 -0
  21. package/dist/theme/_utils/match-attribute-value-to-theme.mjs +28 -0
  22. package/dist/theme/_utils/match-attribute-value-to-theme.mjs.map +1 -0
  23. package/dist/theme/_utils/parse-stored-theme.cjs +61 -7
  24. package/dist/theme/_utils/parse-stored-theme.cjs.map +1 -1
  25. package/dist/theme/_utils/parse-stored-theme.mjs +61 -7
  26. package/dist/theme/_utils/parse-stored-theme.mjs.map +1 -1
  27. package/dist/theme/_utils/resolve-theme-map-value.cjs +19 -0
  28. package/dist/theme/_utils/resolve-theme-map-value.cjs.map +1 -0
  29. package/dist/theme/_utils/resolve-theme-map-value.mjs +17 -0
  30. package/dist/theme/_utils/resolve-theme-map-value.mjs.map +1 -0
  31. package/dist/theme/class-name/parse-class-name.cjs +32 -0
  32. package/dist/theme/class-name/parse-class-name.cjs.map +1 -0
  33. package/dist/theme/class-name/parse-class-name.d.cts +20 -0
  34. package/dist/theme/class-name/parse-class-name.d.cts.map +1 -0
  35. package/dist/theme/class-name/parse-class-name.d.mts +20 -0
  36. package/dist/theme/class-name/parse-class-name.d.mts.map +1 -0
  37. package/dist/theme/class-name/parse-class-name.mjs +31 -0
  38. package/dist/theme/class-name/parse-class-name.mjs.map +1 -0
  39. package/dist/theme/class-name/read-class-name.cjs +20 -0
  40. package/dist/theme/class-name/read-class-name.cjs.map +1 -0
  41. package/dist/theme/class-name/read-class-name.d.cts +20 -0
  42. package/dist/theme/class-name/read-class-name.d.cts.map +1 -0
  43. package/dist/theme/class-name/read-class-name.d.mts +20 -0
  44. package/dist/theme/class-name/read-class-name.d.mts.map +1 -0
  45. package/dist/theme/class-name/read-class-name.mjs +20 -0
  46. package/dist/theme/class-name/read-class-name.mjs.map +1 -0
  47. package/dist/theme/class-name/stringify-class-name.cjs +31 -0
  48. package/dist/theme/class-name/stringify-class-name.cjs.map +1 -0
  49. package/dist/theme/class-name/stringify-class-name.d.cts +21 -0
  50. package/dist/theme/class-name/stringify-class-name.d.cts.map +1 -0
  51. package/dist/theme/class-name/stringify-class-name.d.mts +21 -0
  52. package/dist/theme/class-name/stringify-class-name.d.mts.map +1 -0
  53. package/dist/theme/class-name/stringify-class-name.mjs +31 -0
  54. package/dist/theme/class-name/stringify-class-name.mjs.map +1 -0
  55. package/dist/theme/class-name/subscribe-class-name.cjs +31 -0
  56. package/dist/theme/class-name/subscribe-class-name.cjs.map +1 -0
  57. package/dist/theme/class-name/subscribe-class-name.d.cts +21 -0
  58. package/dist/theme/class-name/subscribe-class-name.d.cts.map +1 -0
  59. package/dist/theme/class-name/subscribe-class-name.d.mts +21 -0
  60. package/dist/theme/class-name/subscribe-class-name.d.mts.map +1 -0
  61. package/dist/theme/class-name/subscribe-class-name.mjs +31 -0
  62. package/dist/theme/class-name/subscribe-class-name.mjs.map +1 -0
  63. package/dist/theme/class-name/write-class-name.cjs +20 -0
  64. package/dist/theme/class-name/write-class-name.cjs.map +1 -0
  65. package/dist/theme/class-name/write-class-name.d.cts +20 -0
  66. package/dist/theme/class-name/write-class-name.d.cts.map +1 -0
  67. package/dist/theme/class-name/write-class-name.d.mts +20 -0
  68. package/dist/theme/class-name/write-class-name.d.mts.map +1 -0
  69. package/dist/theme/class-name/write-class-name.mjs +20 -0
  70. package/dist/theme/class-name/write-class-name.mjs.map +1 -0
  71. package/dist/theme/cookie/_cookie-utils.cjs +37 -0
  72. package/dist/theme/cookie/_cookie-utils.cjs.map +1 -0
  73. package/dist/theme/cookie/_cookie-utils.mjs +33 -0
  74. package/dist/theme/cookie/_cookie-utils.mjs.map +1 -0
  75. package/dist/theme/cookie/read-cookie-theme.cjs +22 -0
  76. package/dist/theme/cookie/read-cookie-theme.cjs.map +1 -0
  77. package/dist/theme/cookie/read-cookie-theme.d.cts +22 -0
  78. package/dist/theme/cookie/read-cookie-theme.d.cts.map +1 -0
  79. package/dist/theme/cookie/read-cookie-theme.d.mts +22 -0
  80. package/dist/theme/cookie/read-cookie-theme.d.mts.map +1 -0
  81. package/dist/theme/cookie/read-cookie-theme.mjs +22 -0
  82. package/dist/theme/cookie/read-cookie-theme.mjs.map +1 -0
  83. package/dist/theme/cookie/write-cookie-theme.cjs +29 -0
  84. package/dist/theme/cookie/write-cookie-theme.cjs.map +1 -0
  85. package/dist/theme/cookie/write-cookie-theme.d.cts +24 -0
  86. package/dist/theme/cookie/write-cookie-theme.d.cts.map +1 -0
  87. package/dist/theme/cookie/write-cookie-theme.d.mts +24 -0
  88. package/dist/theme/cookie/write-cookie-theme.d.mts.map +1 -0
  89. package/dist/theme/cookie/write-cookie-theme.mjs +29 -0
  90. package/dist/theme/cookie/write-cookie-theme.mjs.map +1 -0
  91. package/dist/theme/data-attribute/_constant.cjs +7 -0
  92. package/dist/theme/data-attribute/_constant.cjs.map +1 -0
  93. package/dist/theme/data-attribute/_constant.mjs +6 -0
  94. package/dist/theme/data-attribute/_constant.mjs.map +1 -0
  95. package/dist/theme/data-attribute/parse-data-attribute.cjs +24 -0
  96. package/dist/theme/data-attribute/parse-data-attribute.cjs.map +1 -0
  97. package/dist/theme/data-attribute/parse-data-attribute.d.cts +21 -0
  98. package/dist/theme/data-attribute/parse-data-attribute.d.cts.map +1 -0
  99. package/dist/theme/data-attribute/parse-data-attribute.d.mts +21 -0
  100. package/dist/theme/data-attribute/parse-data-attribute.d.mts.map +1 -0
  101. package/dist/theme/data-attribute/parse-data-attribute.mjs +24 -0
  102. package/dist/theme/data-attribute/parse-data-attribute.mjs.map +1 -0
  103. package/dist/theme/data-attribute/read-data-attribute.cjs +23 -0
  104. package/dist/theme/data-attribute/read-data-attribute.cjs.map +1 -0
  105. package/dist/theme/data-attribute/read-data-attribute.d.cts +21 -0
  106. package/dist/theme/data-attribute/read-data-attribute.d.cts.map +1 -0
  107. package/dist/theme/data-attribute/read-data-attribute.d.mts +21 -0
  108. package/dist/theme/data-attribute/read-data-attribute.d.mts.map +1 -0
  109. package/dist/theme/data-attribute/read-data-attribute.mjs +23 -0
  110. package/dist/theme/data-attribute/read-data-attribute.mjs.map +1 -0
  111. package/dist/theme/data-attribute/stringify-data-attribute.cjs +33 -0
  112. package/dist/theme/data-attribute/stringify-data-attribute.cjs.map +1 -0
  113. package/dist/theme/data-attribute/stringify-data-attribute.d.cts +23 -0
  114. package/dist/theme/data-attribute/stringify-data-attribute.d.cts.map +1 -0
  115. package/dist/theme/data-attribute/stringify-data-attribute.d.mts +23 -0
  116. package/dist/theme/data-attribute/stringify-data-attribute.d.mts.map +1 -0
  117. package/dist/theme/data-attribute/stringify-data-attribute.mjs +33 -0
  118. package/dist/theme/data-attribute/stringify-data-attribute.mjs.map +1 -0
  119. package/dist/theme/data-attribute/subscribe-data-attribute.cjs +28 -0
  120. package/dist/theme/data-attribute/subscribe-data-attribute.cjs.map +1 -0
  121. package/dist/theme/data-attribute/subscribe-data-attribute.d.cts +22 -0
  122. package/dist/theme/data-attribute/subscribe-data-attribute.d.cts.map +1 -0
  123. package/dist/theme/data-attribute/subscribe-data-attribute.d.mts +22 -0
  124. package/dist/theme/data-attribute/subscribe-data-attribute.d.mts.map +1 -0
  125. package/dist/theme/data-attribute/subscribe-data-attribute.mjs +28 -0
  126. package/dist/theme/data-attribute/subscribe-data-attribute.mjs.map +1 -0
  127. package/dist/theme/data-attribute/write-data-attribute.cjs +30 -0
  128. package/dist/theme/data-attribute/write-data-attribute.cjs.map +1 -0
  129. package/dist/theme/data-attribute/write-data-attribute.d.cts +21 -0
  130. package/dist/theme/data-attribute/write-data-attribute.d.cts.map +1 -0
  131. package/dist/theme/data-attribute/write-data-attribute.d.mts +21 -0
  132. package/dist/theme/data-attribute/write-data-attribute.d.mts.map +1 -0
  133. package/dist/theme/data-attribute/write-data-attribute.mjs +30 -0
  134. package/dist/theme/data-attribute/write-data-attribute.mjs.map +1 -0
  135. package/dist/theme/local-storage/read-local-storage.cjs +22 -0
  136. package/dist/theme/local-storage/read-local-storage.cjs.map +1 -0
  137. package/dist/theme/local-storage/read-local-storage.d.cts +19 -0
  138. package/dist/theme/local-storage/read-local-storage.d.cts.map +1 -0
  139. package/dist/theme/local-storage/read-local-storage.d.mts +19 -0
  140. package/dist/theme/local-storage/read-local-storage.d.mts.map +1 -0
  141. package/dist/theme/local-storage/read-local-storage.mjs +22 -0
  142. package/dist/theme/local-storage/read-local-storage.mjs.map +1 -0
  143. package/dist/theme/local-storage/write-local-storage.cjs +26 -0
  144. package/dist/theme/local-storage/write-local-storage.cjs.map +1 -0
  145. package/dist/theme/local-storage/write-local-storage.d.cts +23 -0
  146. package/dist/theme/local-storage/write-local-storage.d.cts.map +1 -0
  147. package/dist/theme/local-storage/write-local-storage.d.mts +23 -0
  148. package/dist/theme/local-storage/write-local-storage.d.mts.map +1 -0
  149. package/dist/theme/local-storage/write-local-storage.mjs +26 -0
  150. package/dist/theme/local-storage/write-local-storage.mjs.map +1 -0
  151. package/dist/theme/prefers-color-scheme-theme/read-prefers-color-scheme-theme.cjs +20 -0
  152. package/dist/theme/prefers-color-scheme-theme/read-prefers-color-scheme-theme.cjs.map +1 -0
  153. package/dist/theme/prefers-color-scheme-theme/read-prefers-color-scheme-theme.d.cts +23 -0
  154. package/dist/theme/prefers-color-scheme-theme/read-prefers-color-scheme-theme.d.cts.map +1 -0
  155. package/dist/theme/prefers-color-scheme-theme/read-prefers-color-scheme-theme.d.mts +23 -0
  156. package/dist/theme/prefers-color-scheme-theme/read-prefers-color-scheme-theme.d.mts.map +1 -0
  157. package/dist/theme/prefers-color-scheme-theme/read-prefers-color-scheme-theme.mjs +20 -0
  158. package/dist/theme/prefers-color-scheme-theme/read-prefers-color-scheme-theme.mjs.map +1 -0
  159. package/dist/theme/prefers-color-scheme-theme/subscribe-prefers-color-scheme-theme.cjs +20 -0
  160. package/dist/theme/prefers-color-scheme-theme/subscribe-prefers-color-scheme-theme.cjs.map +1 -0
  161. package/dist/theme/prefers-color-scheme-theme/subscribe-prefers-color-scheme-theme.d.cts +20 -0
  162. package/dist/theme/prefers-color-scheme-theme/subscribe-prefers-color-scheme-theme.d.cts.map +1 -0
  163. package/dist/theme/prefers-color-scheme-theme/subscribe-prefers-color-scheme-theme.d.mts +20 -0
  164. package/dist/theme/prefers-color-scheme-theme/subscribe-prefers-color-scheme-theme.d.mts.map +1 -0
  165. package/dist/theme/prefers-color-scheme-theme/subscribe-prefers-color-scheme-theme.mjs +20 -0
  166. package/dist/theme/prefers-color-scheme-theme/subscribe-prefers-color-scheme-theme.mjs.map +1 -0
  167. package/dist/theme/session-storage/read-session-storage.cjs +22 -0
  168. package/dist/theme/session-storage/read-session-storage.cjs.map +1 -0
  169. package/dist/theme/session-storage/read-session-storage.d.cts +19 -0
  170. package/dist/theme/session-storage/read-session-storage.d.cts.map +1 -0
  171. package/dist/theme/session-storage/read-session-storage.d.mts +19 -0
  172. package/dist/theme/session-storage/read-session-storage.d.mts.map +1 -0
  173. package/dist/theme/session-storage/read-session-storage.mjs +22 -0
  174. package/dist/theme/session-storage/read-session-storage.mjs.map +1 -0
  175. package/dist/theme/session-storage/write-session-storage.cjs +26 -0
  176. package/dist/theme/session-storage/write-session-storage.cjs.map +1 -0
  177. package/dist/theme/session-storage/write-session-storage.d.cts +23 -0
  178. package/dist/theme/session-storage/write-session-storage.d.cts.map +1 -0
  179. package/dist/theme/session-storage/write-session-storage.d.mts +23 -0
  180. package/dist/theme/session-storage/write-session-storage.d.mts.map +1 -0
  181. package/dist/theme/session-storage/write-session-storage.mjs +26 -0
  182. package/dist/theme/session-storage/write-session-storage.mjs.map +1 -0
  183. package/dist/theme/theme-entry.types.d.cts +11 -1
  184. package/dist/theme/theme-entry.types.d.cts.map +1 -1
  185. package/dist/theme/theme-entry.types.d.mts +11 -1
  186. package/dist/theme/theme-entry.types.d.mts.map +1 -1
  187. package/dist/theme/theme-map.types.d.cts +11 -3
  188. package/dist/theme/theme-map.types.d.cts.map +1 -1
  189. package/dist/theme/theme-map.types.d.mts +11 -3
  190. package/dist/theme/theme-map.types.d.mts.map +1 -1
  191. package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.cjs +21 -18
  192. package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.cjs.map +1 -1
  193. package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.d.cts +5 -0
  194. package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.d.cts.map +1 -1
  195. package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.d.mts +5 -0
  196. package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.d.mts.map +1 -1
  197. package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.mjs +21 -18
  198. package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.mjs.map +1 -1
  199. package/dist/theme/theme-store/cookie-theme-store/cookie-theme-store.cjs +18 -36
  200. package/dist/theme/theme-store/cookie-theme-store/cookie-theme-store.cjs.map +1 -1
  201. package/dist/theme/theme-store/cookie-theme-store/cookie-theme-store.d.cts +5 -3
  202. package/dist/theme/theme-store/cookie-theme-store/cookie-theme-store.d.cts.map +1 -1
  203. package/dist/theme/theme-store/cookie-theme-store/cookie-theme-store.d.mts +5 -3
  204. package/dist/theme/theme-store/cookie-theme-store/cookie-theme-store.d.mts.map +1 -1
  205. package/dist/theme/theme-store/cookie-theme-store/cookie-theme-store.mjs +18 -36
  206. package/dist/theme/theme-store/cookie-theme-store/cookie-theme-store.mjs.map +1 -1
  207. package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.cjs +39 -19
  208. package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.cjs.map +1 -1
  209. package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.d.cts +28 -5
  210. package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.d.cts.map +1 -1
  211. package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.d.mts +28 -5
  212. package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.d.mts.map +1 -1
  213. package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.mjs +39 -19
  214. package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.mjs.map +1 -1
  215. package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.cjs +13 -12
  216. package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.cjs.map +1 -1
  217. package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.d.cts +7 -1
  218. package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.d.cts.map +1 -1
  219. package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.d.mts +7 -1
  220. package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.d.mts.map +1 -1
  221. package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.mjs +13 -12
  222. package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.mjs.map +1 -1
  223. package/dist/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.cjs +4 -5
  224. package/dist/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.cjs.map +1 -1
  225. package/dist/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.d.cts.map +1 -1
  226. package/dist/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.d.mts.map +1 -1
  227. package/dist/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.mjs +4 -5
  228. package/dist/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.mjs.map +1 -1
  229. package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.cjs +13 -12
  230. package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.cjs.map +1 -1
  231. package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.d.cts +7 -1
  232. package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.d.cts.map +1 -1
  233. package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.d.mts +7 -1
  234. package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.d.mts.map +1 -1
  235. package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.mjs +13 -12
  236. package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.mjs.map +1 -1
  237. package/dist/theme/web-storage/read-web-storage.cjs +20 -0
  238. package/dist/theme/web-storage/read-web-storage.cjs.map +1 -0
  239. package/dist/theme/web-storage/read-web-storage.d.cts +21 -0
  240. package/dist/theme/web-storage/read-web-storage.d.cts.map +1 -0
  241. package/dist/theme/web-storage/read-web-storage.d.mts +21 -0
  242. package/dist/theme/web-storage/read-web-storage.d.mts.map +1 -0
  243. package/dist/theme/web-storage/read-web-storage.mjs +20 -0
  244. package/dist/theme/web-storage/read-web-storage.mjs.map +1 -0
  245. package/dist/theme/web-storage/write-web-storage.cjs +33 -0
  246. package/dist/theme/web-storage/write-web-storage.cjs.map +1 -0
  247. package/dist/theme/web-storage/write-web-storage.d.cts +25 -0
  248. package/dist/theme/web-storage/write-web-storage.d.cts.map +1 -0
  249. package/dist/theme/web-storage/write-web-storage.d.mts +25 -0
  250. package/dist/theme/web-storage/write-web-storage.d.mts.map +1 -0
  251. package/dist/theme/web-storage/write-web-storage.mjs +32 -0
  252. package/dist/theme/web-storage/write-web-storage.mjs.map +1 -0
  253. package/dist/theme.cjs +41 -1
  254. package/dist/theme.d.cts +23 -3
  255. package/dist/theme.d.mts +23 -3
  256. package/dist/theme.mjs +21 -1
  257. package/package.json +1 -1
  258. package/src/react/hooks/use-theme-by-class-name.ts +3 -8
  259. package/src/react/hooks/use-theme-by-data-attribute.ts +3 -10
  260. package/src/react/hooks/use-theme-by-local-storage.ts +3 -9
  261. package/src/testing/theme/theme-result-card.tsx +1 -0
  262. package/src/theme/_utils/match-attribute-value-to-theme.ts +36 -0
  263. package/src/theme/_utils/parse-stored-theme.ts +52 -12
  264. package/src/theme/_utils/resolve-theme-map-value.ts +15 -0
  265. package/src/theme/class-name/parse-class-name.ts +31 -0
  266. package/src/theme/class-name/read-class-name.ts +24 -0
  267. package/src/theme/class-name/stringify-class-name.ts +36 -0
  268. package/src/theme/class-name/subscribe-class-name.ts +39 -0
  269. package/src/theme/class-name/write-class-name.ts +24 -0
  270. package/src/theme/cookie/_cookie-utils.ts +45 -0
  271. package/src/theme/cookie/read-cookie-theme.ts +33 -0
  272. package/src/theme/cookie/write-cookie-theme.ts +48 -0
  273. package/src/theme/data-attribute/_constant.ts +1 -0
  274. package/src/theme/data-attribute/parse-data-attribute.ts +25 -0
  275. package/src/theme/data-attribute/read-data-attribute.ts +29 -0
  276. package/src/theme/data-attribute/stringify-data-attribute.ts +39 -0
  277. package/src/theme/data-attribute/subscribe-data-attribute.ts +39 -0
  278. package/src/theme/data-attribute/write-data-attribute.ts +40 -0
  279. package/src/theme/local-storage/read-local-storage.ts +23 -0
  280. package/src/theme/local-storage/write-local-storage.ts +31 -0
  281. package/src/theme/prefers-color-scheme-theme/read-prefers-color-scheme-theme.ts +30 -0
  282. package/src/theme/prefers-color-scheme-theme/subscribe-prefers-color-scheme-theme.ts +24 -0
  283. package/src/theme/session-storage/read-session-storage.ts +23 -0
  284. package/src/theme/session-storage/write-session-storage.ts +31 -0
  285. package/src/theme/theme-entry.types.ts +19 -0
  286. package/src/theme/theme-map.types.ts +9 -2
  287. package/src/theme/theme-store/class-name-theme-store/class-name-theme-store.ts +19 -25
  288. package/src/theme/theme-store/cookie-theme-store/cookie-theme-store.ts +18 -63
  289. package/src/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.ts +41 -28
  290. package/src/theme/theme-store/local-storage-theme-store/local-storage-theme-store.ts +17 -20
  291. package/src/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.ts +4 -5
  292. package/src/theme/theme-store/session-storage-theme-store/session-storage-theme-store.ts +17 -20
  293. package/src/theme/web-storage/read-web-storage.ts +22 -0
  294. package/src/theme/web-storage/write-web-storage.ts +46 -0
  295. package/src/theme.ts +20 -0
  296. package/dist/theme/class-name/apply-theme-to-class-name.cjs +0 -23
  297. package/dist/theme/class-name/apply-theme-to-class-name.cjs.map +0 -1
  298. package/dist/theme/class-name/apply-theme-to-class-name.mjs +0 -22
  299. package/dist/theme/class-name/apply-theme-to-class-name.mjs.map +0 -1
  300. package/dist/theme/class-name/resolve-theme-from-class-name.cjs +0 -23
  301. package/dist/theme/class-name/resolve-theme-from-class-name.cjs.map +0 -1
  302. package/dist/theme/class-name/resolve-theme-from-class-name.mjs +0 -22
  303. package/dist/theme/class-name/resolve-theme-from-class-name.mjs.map +0 -1
  304. package/dist/theme/data-attribute/apply-theme-to-data-attribute.cjs +0 -23
  305. package/dist/theme/data-attribute/apply-theme-to-data-attribute.cjs.map +0 -1
  306. package/dist/theme/data-attribute/apply-theme-to-data-attribute.mjs +0 -22
  307. package/dist/theme/data-attribute/apply-theme-to-data-attribute.mjs.map +0 -1
  308. package/dist/theme/data-attribute/resolve-theme-from-data-attribute.cjs +0 -23
  309. package/dist/theme/data-attribute/resolve-theme-from-data-attribute.cjs.map +0 -1
  310. package/dist/theme/data-attribute/resolve-theme-from-data-attribute.mjs +0 -22
  311. package/dist/theme/data-attribute/resolve-theme-from-data-attribute.mjs.map +0 -1
  312. package/src/theme/class-name/apply-theme-to-class-name.ts +0 -26
  313. package/src/theme/class-name/resolve-theme-from-class-name.ts +0 -22
  314. package/src/theme/data-attribute/apply-theme-to-data-attribute.ts +0 -27
  315. package/src/theme/data-attribute/resolve-theme-from-data-attribute.ts +0 -23
@@ -1,7 +1,6 @@
1
1
  const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
2
  const require_observe_theme_from_stores = require('../../theme/_utils/observe-theme-from-stores.cjs');
3
3
  const require_set_theme_to_stores = require('../../theme/_utils/set-theme-to-stores.cjs');
4
- const require_resolve_theme_from_class_name = require('../../theme/class-name/resolve-theme-from-class-name.cjs');
5
4
  const require_theme_entry = require('../../theme/theme-entry.cjs');
6
5
  const require_class_name_theme_store = require('../../theme/theme-store/class-name-theme-store/class-name-theme-store.cjs');
7
6
  let react = require("react");
@@ -34,10 +33,7 @@ function useThemeByClassName(themes, options) {
34
33
  const element = options?.element ?? (typeof document !== "undefined" ? document.documentElement : void 0);
35
34
  const defaultTheme = options?.defaultTheme;
36
35
  const store = (0, react.useMemo)(() => require_class_name_theme_store.classNameThemeStore(themes, { element }), [element, themes]);
37
- const [theme, setThemeState] = (0, react.useState)(() => {
38
- if (element) return require_resolve_theme_from_class_name.resolveThemeFromClassName(themes, element.className) ?? defaultTheme;
39
- return defaultTheme;
40
- });
36
+ const [theme, setThemeState] = (0, react.useState)(() => store.read()?.theme ?? defaultTheme);
41
37
  (0, react.useEffect)(() => {
42
38
  if (!element) return;
43
39
  return require_observe_theme_from_stores.observeThemeFromStores([store], defaultTheme, setThemeState);
@@ -1 +1 @@
1
- {"version":3,"file":"use-theme-by-class-name.cjs","names":["classNameThemeStore","resolveThemeFromClassName","observeThemeFromStores","themeEntry"],"sources":["../../../src/react/hooks/use-theme-by-class-name.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useState } from 'react'\nimport { observeThemeFromStores } from '../../theme/_utils/observe-theme-from-stores.ts'\nimport { setThemeToStores } from '../../theme/_utils/set-theme-to-stores.ts'\nimport { resolveThemeFromClassName } from '../../theme/class-name/resolve-theme-from-class-name.ts'\nimport { themeEntry } from '../../theme/theme-entry.ts'\nimport type { ThemeMap } from '../../theme/theme-map.types.ts'\nimport { classNameThemeStore } from '../../theme/theme-store/class-name-theme-store/class-name-theme-store.ts'\n\n/**\n * React hook that returns the current theme (from element class) and a setter.\n * Subscribes to class changes on the element so the returned theme stays in sync.\n *\n * @param themes - Record mapping theme keys to their class name values\n * @param options.theme - Fallback theme key when no matching class is found\n * @param options.element - Element to read/set theme on (defaults to document.documentElement)\n * @returns Tuple of [currentTheme, setTheme]\n *\n * @example\n * ```tsx\n * const themes = { light: 'theme-light', dark: 'theme-dark' }\n * const [theme, setTheme] = useThemeByClassName(themes, { theme: 'light' })\n *\n * return (\n * <>\n * <span>Current: {theme}</span>\n * <button onClick={() => setTheme('dark')}>Dark</button>\n * <button onClick={() => setTheme('light')}>Light</button>\n * </>\n * )\n * ```\n */\nexport function useThemeByClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\toptions?: {\n\t\tdefaultTheme?: keyof Themes | undefined\n\t\telement?: Element | undefined\n\t}\n): [keyof Themes | undefined, (theme: keyof Themes) => void] {\n\tconst element =\n\t\toptions?.element ?? (typeof document !== 'undefined' ? document.documentElement : undefined)\n\tconst defaultTheme = options?.defaultTheme\n\n\tconst store = useMemo(() => classNameThemeStore(themes, { element }), [element, themes])\n\n\tconst [theme, setThemeState] = useState<keyof Themes | undefined>(() => {\n\t\tif (element) {\n\t\t\tconst resolved = resolveThemeFromClassName(themes, element.className)\n\t\t\treturn resolved ?? defaultTheme\n\t\t}\n\t\treturn defaultTheme\n\t})\n\n\tuseEffect(() => {\n\t\tif (!element) return\n\t\tconst unobserve = observeThemeFromStores([store], defaultTheme, setThemeState)\n\t\treturn unobserve\n\t}, [element, store, defaultTheme])\n\n\tconst setTheme = useCallback(\n\t\t(themeKey: keyof Themes) => {\n\t\t\tif (element) {\n\t\t\t\tsetThemeToStores([store], themeEntry(themes, themeKey))\n\t\t\t}\n\t\t},\n\t\t[element, store, themes]\n\t)\n\n\treturn [theme, setTheme]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,SAAgB,oBACf,QACA,SAI4D;CAC5D,MAAM,UACL,SAAS,YAAY,OAAO,aAAa,cAAc,SAAS,kBAAkB;CACnF,MAAM,eAAe,SAAS;CAE9B,MAAM,iCAAsBA,mDAAoB,QAAQ,EAAE,SAAS,CAAC,EAAE,CAAC,SAAS,OAAO,CAAC;CAExF,MAAM,CAAC,OAAO,2CAA0D;AACvE,MAAI,QAEH,QADiBC,gEAA0B,QAAQ,QAAQ,UAAU,IAClD;AAEpB,SAAO;GACN;AAEF,4BAAgB;AACf,MAAI,CAAC,QAAS;AAEd,SADkBC,yDAAuB,CAAC,MAAM,EAAE,cAAc,cAAc;IAE5E;EAAC;EAAS;EAAO;EAAa,CAAC;AAWlC,QAAO,CAAC,+BARN,aAA2B;AAC3B,MAAI,QACH,8CAAiB,CAAC,MAAM,EAAEC,+BAAW,QAAQ,SAAS,CAAC;IAGzD;EAAC;EAAS;EAAO;EAAO,CACxB,CAEuB"}
1
+ {"version":3,"file":"use-theme-by-class-name.cjs","names":["classNameThemeStore","observeThemeFromStores","themeEntry"],"sources":["../../../src/react/hooks/use-theme-by-class-name.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useState } from 'react'\nimport { observeThemeFromStores } from '../../theme/_utils/observe-theme-from-stores.ts'\nimport { setThemeToStores } from '../../theme/_utils/set-theme-to-stores.ts'\nimport { themeEntry } from '../../theme/theme-entry.ts'\nimport type { ThemeMap } from '../../theme/theme-map.types.ts'\nimport { classNameThemeStore } from '../../theme/theme-store/class-name-theme-store/class-name-theme-store.ts'\n\n/**\n * React hook that returns the current theme (from element class) and a setter.\n * Subscribes to class changes on the element so the returned theme stays in sync.\n *\n * @param themes - Record mapping theme keys to their class name values\n * @param options.theme - Fallback theme key when no matching class is found\n * @param options.element - Element to read/set theme on (defaults to document.documentElement)\n * @returns Tuple of [currentTheme, setTheme]\n *\n * @example\n * ```tsx\n * const themes = { light: 'theme-light', dark: 'theme-dark' }\n * const [theme, setTheme] = useThemeByClassName(themes, { theme: 'light' })\n *\n * return (\n * <>\n * <span>Current: {theme}</span>\n * <button onClick={() => setTheme('dark')}>Dark</button>\n * <button onClick={() => setTheme('light')}>Light</button>\n * </>\n * )\n * ```\n */\nexport function useThemeByClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\toptions?: {\n\t\tdefaultTheme?: keyof Themes | undefined\n\t\telement?: Element | undefined\n\t}\n): [keyof Themes | undefined, (theme: keyof Themes) => void] {\n\tconst element =\n\t\toptions?.element ?? (typeof document !== 'undefined' ? document.documentElement : undefined)\n\tconst defaultTheme = options?.defaultTheme\n\n\tconst store = useMemo(() => classNameThemeStore(themes, { element }), [element, themes])\n\n\tconst [theme, setThemeState] = useState<keyof Themes | undefined>(\n\t\t() => store.read()?.theme ?? defaultTheme\n\t)\n\n\tuseEffect(() => {\n\t\tif (!element) return\n\t\tconst unobserve = observeThemeFromStores([store], defaultTheme, setThemeState)\n\t\treturn unobserve\n\t}, [element, store, defaultTheme])\n\n\tconst setTheme = useCallback(\n\t\t(themeKey: keyof Themes) => {\n\t\t\tif (element) {\n\t\t\t\tsetThemeToStores([store], themeEntry(themes, themeKey))\n\t\t\t}\n\t\t},\n\t\t[element, store, themes]\n\t)\n\n\treturn [theme, setTheme]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,SAAgB,oBACf,QACA,SAI4D;CAC5D,MAAM,UACL,SAAS,YAAY,OAAO,aAAa,cAAc,SAAS,kBAAkB;CACnF,MAAM,eAAe,SAAS;CAE9B,MAAM,iCAAsBA,mDAAoB,QAAQ,EAAE,SAAS,CAAC,EAAE,CAAC,SAAS,OAAO,CAAC;CAExF,MAAM,CAAC,OAAO,2CACP,MAAM,MAAM,EAAE,SAAS,aAC7B;AAED,4BAAgB;AACf,MAAI,CAAC,QAAS;AAEd,SADkBC,yDAAuB,CAAC,MAAM,EAAE,cAAc,cAAc;IAE5E;EAAC;EAAS;EAAO;EAAa,CAAC;AAWlC,QAAO,CAAC,+BARN,aAA2B;AAC3B,MAAI,QACH,8CAAiB,CAAC,MAAM,EAAEC,+BAAW,QAAQ,SAAS,CAAC;IAGzD;EAAC;EAAS;EAAO;EAAO,CACxB,CAEuB"}
@@ -1 +1 @@
1
- {"version":3,"file":"use-theme-by-class-name.d.cts","names":[],"sources":["../../../src/react/hooks/use-theme-by-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;AA+BA;;;;;;;;;;;;;;;;;;;;;iBAAgB,mCAAmC,kBAC1C;uBAEc;YACX;WAEF,kCAAkC"}
1
+ {"version":3,"file":"use-theme-by-class-name.d.cts","names":[],"sources":["../../../src/react/hooks/use-theme-by-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;AA8BA;;;;;;;;;;;;;;;;;;;;;iBAAgB,mCAAmC,kBAC1C;uBAEc;YACX;WAEF,kCAAkC"}
@@ -1 +1 @@
1
- {"version":3,"file":"use-theme-by-class-name.d.mts","names":[],"sources":["../../../src/react/hooks/use-theme-by-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;AA+BA;;;;;;;;;;;;;;;;;;;;;iBAAgB,mCAAmC,kBAC1C;uBAEc;YACX;WAEF,kCAAkC"}
1
+ {"version":3,"file":"use-theme-by-class-name.d.mts","names":[],"sources":["../../../src/react/hooks/use-theme-by-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;AA8BA;;;;;;;;;;;;;;;;;;;;;iBAAgB,mCAAmC,kBAC1C;uBAEc;YACX;WAEF,kCAAkC"}
@@ -1,6 +1,5 @@
1
1
  import { observeThemeFromStores } from "../../theme/_utils/observe-theme-from-stores.mjs";
2
2
  import { setThemeToStores } from "../../theme/_utils/set-theme-to-stores.mjs";
3
- import { resolveThemeFromClassName } from "../../theme/class-name/resolve-theme-from-class-name.mjs";
4
3
  import { themeEntry } from "../../theme/theme-entry.mjs";
5
4
  import { classNameThemeStore } from "../../theme/theme-store/class-name-theme-store/class-name-theme-store.mjs";
6
5
  import { useCallback, useEffect, useMemo, useState } from "react";
@@ -33,10 +32,7 @@ function useThemeByClassName(themes, options) {
33
32
  const element = options?.element ?? (typeof document !== "undefined" ? document.documentElement : void 0);
34
33
  const defaultTheme = options?.defaultTheme;
35
34
  const store = useMemo(() => classNameThemeStore(themes, { element }), [element, themes]);
36
- const [theme, setThemeState] = useState(() => {
37
- if (element) return resolveThemeFromClassName(themes, element.className) ?? defaultTheme;
38
- return defaultTheme;
39
- });
35
+ const [theme, setThemeState] = useState(() => store.read()?.theme ?? defaultTheme);
40
36
  useEffect(() => {
41
37
  if (!element) return;
42
38
  return observeThemeFromStores([store], defaultTheme, setThemeState);
@@ -1 +1 @@
1
- {"version":3,"file":"use-theme-by-class-name.mjs","names":[],"sources":["../../../src/react/hooks/use-theme-by-class-name.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useState } from 'react'\nimport { observeThemeFromStores } from '../../theme/_utils/observe-theme-from-stores.ts'\nimport { setThemeToStores } from '../../theme/_utils/set-theme-to-stores.ts'\nimport { resolveThemeFromClassName } from '../../theme/class-name/resolve-theme-from-class-name.ts'\nimport { themeEntry } from '../../theme/theme-entry.ts'\nimport type { ThemeMap } from '../../theme/theme-map.types.ts'\nimport { classNameThemeStore } from '../../theme/theme-store/class-name-theme-store/class-name-theme-store.ts'\n\n/**\n * React hook that returns the current theme (from element class) and a setter.\n * Subscribes to class changes on the element so the returned theme stays in sync.\n *\n * @param themes - Record mapping theme keys to their class name values\n * @param options.theme - Fallback theme key when no matching class is found\n * @param options.element - Element to read/set theme on (defaults to document.documentElement)\n * @returns Tuple of [currentTheme, setTheme]\n *\n * @example\n * ```tsx\n * const themes = { light: 'theme-light', dark: 'theme-dark' }\n * const [theme, setTheme] = useThemeByClassName(themes, { theme: 'light' })\n *\n * return (\n * <>\n * <span>Current: {theme}</span>\n * <button onClick={() => setTheme('dark')}>Dark</button>\n * <button onClick={() => setTheme('light')}>Light</button>\n * </>\n * )\n * ```\n */\nexport function useThemeByClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\toptions?: {\n\t\tdefaultTheme?: keyof Themes | undefined\n\t\telement?: Element | undefined\n\t}\n): [keyof Themes | undefined, (theme: keyof Themes) => void] {\n\tconst element =\n\t\toptions?.element ?? (typeof document !== 'undefined' ? document.documentElement : undefined)\n\tconst defaultTheme = options?.defaultTheme\n\n\tconst store = useMemo(() => classNameThemeStore(themes, { element }), [element, themes])\n\n\tconst [theme, setThemeState] = useState<keyof Themes | undefined>(() => {\n\t\tif (element) {\n\t\t\tconst resolved = resolveThemeFromClassName(themes, element.className)\n\t\t\treturn resolved ?? defaultTheme\n\t\t}\n\t\treturn defaultTheme\n\t})\n\n\tuseEffect(() => {\n\t\tif (!element) return\n\t\tconst unobserve = observeThemeFromStores([store], defaultTheme, setThemeState)\n\t\treturn unobserve\n\t}, [element, store, defaultTheme])\n\n\tconst setTheme = useCallback(\n\t\t(themeKey: keyof Themes) => {\n\t\t\tif (element) {\n\t\t\t\tsetThemeToStores([store], themeEntry(themes, themeKey))\n\t\t\t}\n\t\t},\n\t\t[element, store, themes]\n\t)\n\n\treturn [theme, setTheme]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,SAAgB,oBACf,QACA,SAI4D;CAC5D,MAAM,UACL,SAAS,YAAY,OAAO,aAAa,cAAc,SAAS,kBAAkB;CACnF,MAAM,eAAe,SAAS;CAE9B,MAAM,QAAQ,cAAc,oBAAoB,QAAQ,EAAE,SAAS,CAAC,EAAE,CAAC,SAAS,OAAO,CAAC;CAExF,MAAM,CAAC,OAAO,iBAAiB,eAAyC;AACvE,MAAI,QAEH,QADiB,0BAA0B,QAAQ,QAAQ,UAAU,IAClD;AAEpB,SAAO;GACN;AAEF,iBAAgB;AACf,MAAI,CAAC,QAAS;AAEd,SADkB,uBAAuB,CAAC,MAAM,EAAE,cAAc,cAAc;IAE5E;EAAC;EAAS;EAAO;EAAa,CAAC;AAWlC,QAAO,CAAC,OATS,aACf,aAA2B;AAC3B,MAAI,QACH,kBAAiB,CAAC,MAAM,EAAE,WAAW,QAAQ,SAAS,CAAC;IAGzD;EAAC;EAAS;EAAO;EAAO,CACxB,CAEuB"}
1
+ {"version":3,"file":"use-theme-by-class-name.mjs","names":[],"sources":["../../../src/react/hooks/use-theme-by-class-name.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useState } from 'react'\nimport { observeThemeFromStores } from '../../theme/_utils/observe-theme-from-stores.ts'\nimport { setThemeToStores } from '../../theme/_utils/set-theme-to-stores.ts'\nimport { themeEntry } from '../../theme/theme-entry.ts'\nimport type { ThemeMap } from '../../theme/theme-map.types.ts'\nimport { classNameThemeStore } from '../../theme/theme-store/class-name-theme-store/class-name-theme-store.ts'\n\n/**\n * React hook that returns the current theme (from element class) and a setter.\n * Subscribes to class changes on the element so the returned theme stays in sync.\n *\n * @param themes - Record mapping theme keys to their class name values\n * @param options.theme - Fallback theme key when no matching class is found\n * @param options.element - Element to read/set theme on (defaults to document.documentElement)\n * @returns Tuple of [currentTheme, setTheme]\n *\n * @example\n * ```tsx\n * const themes = { light: 'theme-light', dark: 'theme-dark' }\n * const [theme, setTheme] = useThemeByClassName(themes, { theme: 'light' })\n *\n * return (\n * <>\n * <span>Current: {theme}</span>\n * <button onClick={() => setTheme('dark')}>Dark</button>\n * <button onClick={() => setTheme('light')}>Light</button>\n * </>\n * )\n * ```\n */\nexport function useThemeByClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\toptions?: {\n\t\tdefaultTheme?: keyof Themes | undefined\n\t\telement?: Element | undefined\n\t}\n): [keyof Themes | undefined, (theme: keyof Themes) => void] {\n\tconst element =\n\t\toptions?.element ?? (typeof document !== 'undefined' ? document.documentElement : undefined)\n\tconst defaultTheme = options?.defaultTheme\n\n\tconst store = useMemo(() => classNameThemeStore(themes, { element }), [element, themes])\n\n\tconst [theme, setThemeState] = useState<keyof Themes | undefined>(\n\t\t() => store.read()?.theme ?? defaultTheme\n\t)\n\n\tuseEffect(() => {\n\t\tif (!element) return\n\t\tconst unobserve = observeThemeFromStores([store], defaultTheme, setThemeState)\n\t\treturn unobserve\n\t}, [element, store, defaultTheme])\n\n\tconst setTheme = useCallback(\n\t\t(themeKey: keyof Themes) => {\n\t\t\tif (element) {\n\t\t\t\tsetThemeToStores([store], themeEntry(themes, themeKey))\n\t\t\t}\n\t\t},\n\t\t[element, store, themes]\n\t)\n\n\treturn [theme, setTheme]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,SAAgB,oBACf,QACA,SAI4D;CAC5D,MAAM,UACL,SAAS,YAAY,OAAO,aAAa,cAAc,SAAS,kBAAkB;CACnF,MAAM,eAAe,SAAS;CAE9B,MAAM,QAAQ,cAAc,oBAAoB,QAAQ,EAAE,SAAS,CAAC,EAAE,CAAC,SAAS,OAAO,CAAC;CAExF,MAAM,CAAC,OAAO,iBAAiB,eACxB,MAAM,MAAM,EAAE,SAAS,aAC7B;AAED,iBAAgB;AACf,MAAI,CAAC,QAAS;AAEd,SADkB,uBAAuB,CAAC,MAAM,EAAE,cAAc,cAAc;IAE5E;EAAC;EAAS;EAAO;EAAa,CAAC;AAWlC,QAAO,CAAC,OATS,aACf,aAA2B;AAC3B,MAAI,QACH,kBAAiB,CAAC,MAAM,EAAE,WAAW,QAAQ,SAAS,CAAC;IAGzD;EAAC;EAAS;EAAO;EAAO,CACxB,CAEuB"}
@@ -1,9 +1,7 @@
1
1
  const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
- const require_get_data_attribute = require('../../attributes/get-data-attribute.cjs');
3
2
  const require_observe_theme_from_stores = require('../../theme/_utils/observe-theme-from-stores.cjs');
4
3
  const require_set_theme_to_stores = require('../../theme/_utils/set-theme-to-stores.cjs');
5
4
  const require_theme_entry = require('../../theme/theme-entry.cjs');
6
- const require_resolve_theme_from_data_attribute = require('../../theme/data-attribute/resolve-theme-from-data-attribute.cjs');
7
5
  const require_data_attribute_theme_store = require('../../theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.cjs');
8
6
  let react = require("react");
9
7
 
@@ -47,10 +45,7 @@ function useThemeByDataAttribute(themes, options) {
47
45
  themes,
48
46
  attributeName
49
47
  ]);
50
- const [theme, setThemeState] = (0, react.useState)(() => {
51
- if (element) return require_resolve_theme_from_data_attribute.resolveThemeFromDataAttribute(themes, require_get_data_attribute.getDataAttribute(attributeName, element)) ?? defaultTheme;
52
- return defaultTheme;
53
- });
48
+ const [theme, setThemeState] = (0, react.useState)(() => store.read()?.theme ?? defaultTheme);
54
49
  (0, react.useEffect)(() => {
55
50
  if (!element) return;
56
51
  return require_observe_theme_from_stores.observeThemeFromStores([store], defaultTheme, setThemeState);
@@ -1 +1 @@
1
- {"version":3,"file":"use-theme-by-data-attribute.cjs","names":["dataAttributeThemeStore","resolveThemeFromDataAttribute","getDataAttribute","observeThemeFromStores","themeEntry"],"sources":["../../../src/react/hooks/use-theme-by-data-attribute.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useState } from 'react'\nimport { getDataAttribute } from '../../attributes/get-data-attribute.ts'\nimport { observeThemeFromStores } from '../../theme/_utils/observe-theme-from-stores.ts'\nimport { setThemeToStores } from '../../theme/_utils/set-theme-to-stores.ts'\nimport { resolveThemeFromDataAttribute } from '../../theme/data-attribute/resolve-theme-from-data-attribute.ts'\nimport { themeEntry } from '../../theme/theme-entry.ts'\nimport type { ThemeMap } from '../../theme/theme-map.types.ts'\nimport { dataAttributeThemeStore } from '../../theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.ts'\n\n/**\n * React hook that returns the current theme (from element data attribute) and a setter.\n * Subscribes to data attribute changes on the element so the returned theme stays in sync.\n *\n * @param themes - Record mapping theme keys to their data attribute values\n * @param options.attributeName - Data attribute name (e.g. `data-theme`)\n * @param options.defaultTheme - Fallback theme key when no matching attribute value is found\n * @param options.element - Element to read/set theme on (defaults to document.documentElement)\n * @returns Tuple of [currentTheme, setTheme]\n *\n * @example\n * ```tsx\n * const themes = { light: 'theme-light', dark: 'theme-dark' }\n * const [theme, setTheme] = useThemeByDataAttribute(themes, {\n * attributeName: 'data-theme',\n * defaultTheme: 'light'\n * })\n *\n * return (\n * <>\n * <span>Current: {theme}</span>\n * <button onClick={() => setTheme('dark')}>Dark</button>\n * <button onClick={() => setTheme('light')}>Light</button>\n * </>\n * )\n * ```\n */\nexport function useThemeByDataAttribute<Themes extends ThemeMap>(\n\tthemes: Themes,\n\toptions: {\n\t\tattributeName: `data-${string}`\n\t\tdefaultTheme?: keyof Themes | undefined\n\t\telement?: Element | undefined\n\t}\n): [keyof Themes | undefined, (theme: keyof Themes) => void] {\n\tconst element =\n\t\toptions.element ?? (typeof document !== 'undefined' ? document.documentElement : undefined)\n\tconst defaultTheme = options.defaultTheme\n\tconst attributeName = options.attributeName\n\n\tconst store = useMemo(\n\t\t() =>\n\t\t\tdataAttributeThemeStore(themes, {\n\t\t\t\tattributeName,\n\t\t\t\telement\n\t\t\t}),\n\t\t[element, themes, attributeName]\n\t)\n\n\tconst [theme, setThemeState] = useState<keyof Themes | undefined>(() => {\n\t\tif (element) {\n\t\t\tconst attrValue = getDataAttribute(attributeName, element)\n\t\t\tconst resolved = resolveThemeFromDataAttribute(themes, attrValue)\n\t\t\treturn resolved ?? defaultTheme\n\t\t}\n\t\treturn defaultTheme\n\t})\n\n\tuseEffect(() => {\n\t\tif (!element) return\n\t\tconst unobserve = observeThemeFromStores([store], defaultTheme, setThemeState)\n\t\treturn unobserve\n\t}, [element, store, defaultTheme])\n\n\tconst setTheme = useCallback(\n\t\t(themeKey: keyof Themes) => {\n\t\t\tif (element) {\n\t\t\t\tsetThemeToStores([store], themeEntry(themes, themeKey))\n\t\t\t}\n\t\t},\n\t\t[element, store, themes]\n\t)\n\n\treturn [theme, setTheme]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,SAAgB,wBACf,QACA,SAK4D;CAC5D,MAAM,UACL,QAAQ,YAAY,OAAO,aAAa,cAAc,SAAS,kBAAkB;CAClF,MAAM,eAAe,QAAQ;CAC7B,MAAM,gBAAgB,QAAQ;CAE9B,MAAM,iCAEJA,2DAAwB,QAAQ;EAC/B;EACA;EACA,CAAC,EACH;EAAC;EAAS;EAAQ;EAAc,CAChC;CAED,MAAM,CAAC,OAAO,2CAA0D;AACvE,MAAI,QAGH,QADiBC,wEAA8B,QAD7BC,4CAAiB,eAAe,QAAQ,CACO,IAC9C;AAEpB,SAAO;GACN;AAEF,4BAAgB;AACf,MAAI,CAAC,QAAS;AAEd,SADkBC,yDAAuB,CAAC,MAAM,EAAE,cAAc,cAAc;IAE5E;EAAC;EAAS;EAAO;EAAa,CAAC;AAWlC,QAAO,CAAC,+BARN,aAA2B;AAC3B,MAAI,QACH,8CAAiB,CAAC,MAAM,EAAEC,+BAAW,QAAQ,SAAS,CAAC;IAGzD;EAAC;EAAS;EAAO;EAAO,CACxB,CAEuB"}
1
+ {"version":3,"file":"use-theme-by-data-attribute.cjs","names":["dataAttributeThemeStore","observeThemeFromStores","themeEntry"],"sources":["../../../src/react/hooks/use-theme-by-data-attribute.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useState } from 'react'\nimport { observeThemeFromStores } from '../../theme/_utils/observe-theme-from-stores.ts'\nimport { setThemeToStores } from '../../theme/_utils/set-theme-to-stores.ts'\nimport { themeEntry } from '../../theme/theme-entry.ts'\nimport type { ThemeMap } from '../../theme/theme-map.types.ts'\nimport { dataAttributeThemeStore } from '../../theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.ts'\n\n/**\n * React hook that returns the current theme (from element data attribute) and a setter.\n * Subscribes to data attribute changes on the element so the returned theme stays in sync.\n *\n * @param themes - Record mapping theme keys to their data attribute values\n * @param options.attributeName - Data attribute name (e.g. `data-theme`)\n * @param options.defaultTheme - Fallback theme key when no matching attribute value is found\n * @param options.element - Element to read/set theme on (defaults to document.documentElement)\n * @returns Tuple of [currentTheme, setTheme]\n *\n * @example\n * ```tsx\n * const themes = { light: 'theme-light', dark: 'theme-dark' }\n * const [theme, setTheme] = useThemeByDataAttribute(themes, {\n * attributeName: 'data-theme',\n * defaultTheme: 'light'\n * })\n *\n * return (\n * <>\n * <span>Current: {theme}</span>\n * <button onClick={() => setTheme('dark')}>Dark</button>\n * <button onClick={() => setTheme('light')}>Light</button>\n * </>\n * )\n * ```\n */\nexport function useThemeByDataAttribute<Themes extends ThemeMap>(\n\tthemes: Themes,\n\toptions: {\n\t\tattributeName: `data-${string}`\n\t\tdefaultTheme?: keyof Themes | undefined\n\t\telement?: Element | undefined\n\t}\n): [keyof Themes | undefined, (theme: keyof Themes) => void] {\n\tconst element =\n\t\toptions.element ?? (typeof document !== 'undefined' ? document.documentElement : undefined)\n\tconst defaultTheme = options.defaultTheme\n\tconst attributeName = options.attributeName\n\n\tconst store = useMemo(\n\t\t() =>\n\t\t\tdataAttributeThemeStore(themes, {\n\t\t\t\tattributeName,\n\t\t\t\telement\n\t\t\t}),\n\t\t[element, themes, attributeName]\n\t)\n\n\tconst [theme, setThemeState] = useState<keyof Themes | undefined>(\n\t\t() => store.read()?.theme ?? defaultTheme\n\t)\n\n\tuseEffect(() => {\n\t\tif (!element) return\n\t\tconst unobserve = observeThemeFromStores([store], defaultTheme, setThemeState)\n\t\treturn unobserve\n\t}, [element, store, defaultTheme])\n\n\tconst setTheme = useCallback(\n\t\t(themeKey: keyof Themes) => {\n\t\t\tif (element) {\n\t\t\t\tsetThemeToStores([store], themeEntry(themes, themeKey))\n\t\t\t}\n\t\t},\n\t\t[element, store, themes]\n\t)\n\n\treturn [theme, setTheme]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,SAAgB,wBACf,QACA,SAK4D;CAC5D,MAAM,UACL,QAAQ,YAAY,OAAO,aAAa,cAAc,SAAS,kBAAkB;CAClF,MAAM,eAAe,QAAQ;CAC7B,MAAM,gBAAgB,QAAQ;CAE9B,MAAM,iCAEJA,2DAAwB,QAAQ;EAC/B;EACA;EACA,CAAC,EACH;EAAC;EAAS;EAAQ;EAAc,CAChC;CAED,MAAM,CAAC,OAAO,2CACP,MAAM,MAAM,EAAE,SAAS,aAC7B;AAED,4BAAgB;AACf,MAAI,CAAC,QAAS;AAEd,SADkBC,yDAAuB,CAAC,MAAM,EAAE,cAAc,cAAc;IAE5E;EAAC;EAAS;EAAO;EAAa,CAAC;AAWlC,QAAO,CAAC,+BARN,aAA2B;AAC3B,MAAI,QACH,8CAAiB,CAAC,MAAM,EAAEC,+BAAW,QAAQ,SAAS,CAAC;IAGzD;EAAC;EAAS;EAAO;EAAO,CACxB,CAEuB"}
@@ -1 +1 @@
1
- {"version":3,"file":"use-theme-by-data-attribute.d.cts","names":[],"sources":["../../../src/react/hooks/use-theme-by-data-attribute.ts"],"sourcesContent":[],"mappings":";;;;;;AAoCA;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,uCAAuC,kBAC9C;;uBAGc;YACX;WAEF,kCAAkC"}
1
+ {"version":3,"file":"use-theme-by-data-attribute.d.cts","names":[],"sources":["../../../src/react/hooks/use-theme-by-data-attribute.ts"],"sourcesContent":[],"mappings":";;;;;;AAkCA;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,uCAAuC,kBAC9C;;uBAGc;YACX;WAEF,kCAAkC"}
@@ -1 +1 @@
1
- {"version":3,"file":"use-theme-by-data-attribute.d.mts","names":[],"sources":["../../../src/react/hooks/use-theme-by-data-attribute.ts"],"sourcesContent":[],"mappings":";;;;;;AAoCA;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,uCAAuC,kBAC9C;;uBAGc;YACX;WAEF,kCAAkC"}
1
+ {"version":3,"file":"use-theme-by-data-attribute.d.mts","names":[],"sources":["../../../src/react/hooks/use-theme-by-data-attribute.ts"],"sourcesContent":[],"mappings":";;;;;;AAkCA;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,uCAAuC,kBAC9C;;uBAGc;YACX;WAEF,kCAAkC"}
@@ -1,8 +1,6 @@
1
- import { getDataAttribute } from "../../attributes/get-data-attribute.mjs";
2
1
  import { observeThemeFromStores } from "../../theme/_utils/observe-theme-from-stores.mjs";
3
2
  import { setThemeToStores } from "../../theme/_utils/set-theme-to-stores.mjs";
4
3
  import { themeEntry } from "../../theme/theme-entry.mjs";
5
- import { resolveThemeFromDataAttribute } from "../../theme/data-attribute/resolve-theme-from-data-attribute.mjs";
6
4
  import { dataAttributeThemeStore } from "../../theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.mjs";
7
5
  import { useCallback, useEffect, useMemo, useState } from "react";
8
6
 
@@ -46,10 +44,7 @@ function useThemeByDataAttribute(themes, options) {
46
44
  themes,
47
45
  attributeName
48
46
  ]);
49
- const [theme, setThemeState] = useState(() => {
50
- if (element) return resolveThemeFromDataAttribute(themes, getDataAttribute(attributeName, element)) ?? defaultTheme;
51
- return defaultTheme;
52
- });
47
+ const [theme, setThemeState] = useState(() => store.read()?.theme ?? defaultTheme);
53
48
  useEffect(() => {
54
49
  if (!element) return;
55
50
  return observeThemeFromStores([store], defaultTheme, setThemeState);
@@ -1 +1 @@
1
- {"version":3,"file":"use-theme-by-data-attribute.mjs","names":[],"sources":["../../../src/react/hooks/use-theme-by-data-attribute.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useState } from 'react'\nimport { getDataAttribute } from '../../attributes/get-data-attribute.ts'\nimport { observeThemeFromStores } from '../../theme/_utils/observe-theme-from-stores.ts'\nimport { setThemeToStores } from '../../theme/_utils/set-theme-to-stores.ts'\nimport { resolveThemeFromDataAttribute } from '../../theme/data-attribute/resolve-theme-from-data-attribute.ts'\nimport { themeEntry } from '../../theme/theme-entry.ts'\nimport type { ThemeMap } from '../../theme/theme-map.types.ts'\nimport { dataAttributeThemeStore } from '../../theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.ts'\n\n/**\n * React hook that returns the current theme (from element data attribute) and a setter.\n * Subscribes to data attribute changes on the element so the returned theme stays in sync.\n *\n * @param themes - Record mapping theme keys to their data attribute values\n * @param options.attributeName - Data attribute name (e.g. `data-theme`)\n * @param options.defaultTheme - Fallback theme key when no matching attribute value is found\n * @param options.element - Element to read/set theme on (defaults to document.documentElement)\n * @returns Tuple of [currentTheme, setTheme]\n *\n * @example\n * ```tsx\n * const themes = { light: 'theme-light', dark: 'theme-dark' }\n * const [theme, setTheme] = useThemeByDataAttribute(themes, {\n * attributeName: 'data-theme',\n * defaultTheme: 'light'\n * })\n *\n * return (\n * <>\n * <span>Current: {theme}</span>\n * <button onClick={() => setTheme('dark')}>Dark</button>\n * <button onClick={() => setTheme('light')}>Light</button>\n * </>\n * )\n * ```\n */\nexport function useThemeByDataAttribute<Themes extends ThemeMap>(\n\tthemes: Themes,\n\toptions: {\n\t\tattributeName: `data-${string}`\n\t\tdefaultTheme?: keyof Themes | undefined\n\t\telement?: Element | undefined\n\t}\n): [keyof Themes | undefined, (theme: keyof Themes) => void] {\n\tconst element =\n\t\toptions.element ?? (typeof document !== 'undefined' ? document.documentElement : undefined)\n\tconst defaultTheme = options.defaultTheme\n\tconst attributeName = options.attributeName\n\n\tconst store = useMemo(\n\t\t() =>\n\t\t\tdataAttributeThemeStore(themes, {\n\t\t\t\tattributeName,\n\t\t\t\telement\n\t\t\t}),\n\t\t[element, themes, attributeName]\n\t)\n\n\tconst [theme, setThemeState] = useState<keyof Themes | undefined>(() => {\n\t\tif (element) {\n\t\t\tconst attrValue = getDataAttribute(attributeName, element)\n\t\t\tconst resolved = resolveThemeFromDataAttribute(themes, attrValue)\n\t\t\treturn resolved ?? defaultTheme\n\t\t}\n\t\treturn defaultTheme\n\t})\n\n\tuseEffect(() => {\n\t\tif (!element) return\n\t\tconst unobserve = observeThemeFromStores([store], defaultTheme, setThemeState)\n\t\treturn unobserve\n\t}, [element, store, defaultTheme])\n\n\tconst setTheme = useCallback(\n\t\t(themeKey: keyof Themes) => {\n\t\t\tif (element) {\n\t\t\t\tsetThemeToStores([store], themeEntry(themes, themeKey))\n\t\t\t}\n\t\t},\n\t\t[element, store, themes]\n\t)\n\n\treturn [theme, setTheme]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,SAAgB,wBACf,QACA,SAK4D;CAC5D,MAAM,UACL,QAAQ,YAAY,OAAO,aAAa,cAAc,SAAS,kBAAkB;CAClF,MAAM,eAAe,QAAQ;CAC7B,MAAM,gBAAgB,QAAQ;CAE9B,MAAM,QAAQ,cAEZ,wBAAwB,QAAQ;EAC/B;EACA;EACA,CAAC,EACH;EAAC;EAAS;EAAQ;EAAc,CAChC;CAED,MAAM,CAAC,OAAO,iBAAiB,eAAyC;AACvE,MAAI,QAGH,QADiB,8BAA8B,QAD7B,iBAAiB,eAAe,QAAQ,CACO,IAC9C;AAEpB,SAAO;GACN;AAEF,iBAAgB;AACf,MAAI,CAAC,QAAS;AAEd,SADkB,uBAAuB,CAAC,MAAM,EAAE,cAAc,cAAc;IAE5E;EAAC;EAAS;EAAO;EAAa,CAAC;AAWlC,QAAO,CAAC,OATS,aACf,aAA2B;AAC3B,MAAI,QACH,kBAAiB,CAAC,MAAM,EAAE,WAAW,QAAQ,SAAS,CAAC;IAGzD;EAAC;EAAS;EAAO;EAAO,CACxB,CAEuB"}
1
+ {"version":3,"file":"use-theme-by-data-attribute.mjs","names":[],"sources":["../../../src/react/hooks/use-theme-by-data-attribute.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useState } from 'react'\nimport { observeThemeFromStores } from '../../theme/_utils/observe-theme-from-stores.ts'\nimport { setThemeToStores } from '../../theme/_utils/set-theme-to-stores.ts'\nimport { themeEntry } from '../../theme/theme-entry.ts'\nimport type { ThemeMap } from '../../theme/theme-map.types.ts'\nimport { dataAttributeThemeStore } from '../../theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.ts'\n\n/**\n * React hook that returns the current theme (from element data attribute) and a setter.\n * Subscribes to data attribute changes on the element so the returned theme stays in sync.\n *\n * @param themes - Record mapping theme keys to their data attribute values\n * @param options.attributeName - Data attribute name (e.g. `data-theme`)\n * @param options.defaultTheme - Fallback theme key when no matching attribute value is found\n * @param options.element - Element to read/set theme on (defaults to document.documentElement)\n * @returns Tuple of [currentTheme, setTheme]\n *\n * @example\n * ```tsx\n * const themes = { light: 'theme-light', dark: 'theme-dark' }\n * const [theme, setTheme] = useThemeByDataAttribute(themes, {\n * attributeName: 'data-theme',\n * defaultTheme: 'light'\n * })\n *\n * return (\n * <>\n * <span>Current: {theme}</span>\n * <button onClick={() => setTheme('dark')}>Dark</button>\n * <button onClick={() => setTheme('light')}>Light</button>\n * </>\n * )\n * ```\n */\nexport function useThemeByDataAttribute<Themes extends ThemeMap>(\n\tthemes: Themes,\n\toptions: {\n\t\tattributeName: `data-${string}`\n\t\tdefaultTheme?: keyof Themes | undefined\n\t\telement?: Element | undefined\n\t}\n): [keyof Themes | undefined, (theme: keyof Themes) => void] {\n\tconst element =\n\t\toptions.element ?? (typeof document !== 'undefined' ? document.documentElement : undefined)\n\tconst defaultTheme = options.defaultTheme\n\tconst attributeName = options.attributeName\n\n\tconst store = useMemo(\n\t\t() =>\n\t\t\tdataAttributeThemeStore(themes, {\n\t\t\t\tattributeName,\n\t\t\t\telement\n\t\t\t}),\n\t\t[element, themes, attributeName]\n\t)\n\n\tconst [theme, setThemeState] = useState<keyof Themes | undefined>(\n\t\t() => store.read()?.theme ?? defaultTheme\n\t)\n\n\tuseEffect(() => {\n\t\tif (!element) return\n\t\tconst unobserve = observeThemeFromStores([store], defaultTheme, setThemeState)\n\t\treturn unobserve\n\t}, [element, store, defaultTheme])\n\n\tconst setTheme = useCallback(\n\t\t(themeKey: keyof Themes) => {\n\t\t\tif (element) {\n\t\t\t\tsetThemeToStores([store], themeEntry(themes, themeKey))\n\t\t\t}\n\t\t},\n\t\t[element, store, themes]\n\t)\n\n\treturn [theme, setTheme]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,SAAgB,wBACf,QACA,SAK4D;CAC5D,MAAM,UACL,QAAQ,YAAY,OAAO,aAAa,cAAc,SAAS,kBAAkB;CAClF,MAAM,eAAe,QAAQ;CAC7B,MAAM,gBAAgB,QAAQ;CAE9B,MAAM,QAAQ,cAEZ,wBAAwB,QAAQ;EAC/B;EACA;EACA,CAAC,EACH;EAAC;EAAS;EAAQ;EAAc,CAChC;CAED,MAAM,CAAC,OAAO,iBAAiB,eACxB,MAAM,MAAM,EAAE,SAAS,aAC7B;AAED,iBAAgB;AACf,MAAI,CAAC,QAAS;AAEd,SADkB,uBAAuB,CAAC,MAAM,EAAE,cAAc,cAAc;IAE5E;EAAC;EAAS;EAAO;EAAa,CAAC;AAWlC,QAAO,CAAC,OATS,aACf,aAA2B;AAC3B,MAAI,QACH,kBAAiB,CAAC,MAAM,EAAE,WAAW,QAAQ,SAAS,CAAC;IAGzD;EAAC;EAAS;EAAO;EAAO,CACxB,CAEuB"}
@@ -2,7 +2,6 @@ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
2
  const require_observe_theme_from_stores = require('../../theme/_utils/observe-theme-from-stores.cjs');
3
3
  const require_set_theme_to_stores = require('../../theme/_utils/set-theme-to-stores.cjs');
4
4
  const require_theme_entry = require('../../theme/theme-entry.cjs');
5
- const require_parse_stored_theme = require('../../theme/_utils/parse-stored-theme.cjs');
6
5
  const require_local_storage_theme_store = require('../../theme/theme-store/local-storage-theme-store/local-storage-theme-store.cjs');
7
6
  let react = require("react");
8
7
 
@@ -36,10 +35,7 @@ let react = require("react");
36
35
  function useThemeByLocalStorage(themes, options) {
37
36
  const { storageKey, defaultTheme } = options;
38
37
  const store = (0, react.useMemo)(() => require_local_storage_theme_store.localStorageThemeStore(themes, { storageKey }), [themes, storageKey]);
39
- const [theme, setThemeState] = (0, react.useState)(() => {
40
- if (typeof window !== "undefined" && window.localStorage) return require_parse_stored_theme.parseStoredTheme(themes, window.localStorage.getItem(storageKey)) ?? defaultTheme;
41
- return defaultTheme;
42
- });
38
+ const [theme, setThemeState] = (0, react.useState)(() => store.read()?.theme ?? defaultTheme);
43
39
  (0, react.useEffect)(() => {
44
40
  return require_observe_theme_from_stores.observeThemeFromStores([store], defaultTheme, setThemeState);
45
41
  }, [store, defaultTheme]);
@@ -1 +1 @@
1
- {"version":3,"file":"use-theme-by-local-storage.cjs","names":["localStorageThemeStore","parseStoredTheme","observeThemeFromStores","themeEntry"],"sources":["../../../src/react/hooks/use-theme-by-local-storage.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useState } from 'react'\nimport { observeThemeFromStores } from '../../theme/_utils/observe-theme-from-stores.ts'\nimport { parseStoredTheme } from '../../theme/_utils/parse-stored-theme.ts'\nimport { setThemeToStores } from '../../theme/_utils/set-theme-to-stores.ts'\nimport { themeEntry } from '../../theme/theme-entry.ts'\nimport type { ThemeMap } from '../../theme/theme-map.types.ts'\nimport { localStorageThemeStore } from '../../theme/theme-store/local-storage-theme-store/local-storage-theme-store.ts'\n\n/**\n * React hook that returns the current theme (from localStorage) and a setter.\n * Subscribes to storage changes so the returned theme stays in sync across tabs.\n *\n * @param themes - Record mapping theme keys to their values\n * @param options.storageKey - localStorage key to persist the theme\n * @param options.defaultTheme - Fallback theme key when no stored value is found\n * @returns Tuple of [currentTheme, setTheme]\n *\n * @example\n * ```tsx\n * const themes = { light: 'theme-light', dark: 'theme-dark' }\n * const [theme, setTheme] = useThemeByLocalStorage(themes, {\n * storageKey: 'app-theme',\n * defaultTheme: 'light'\n * })\n *\n * return (\n * <>\n * <span>Current: {theme}</span>\n * <button onClick={() => setTheme('dark')}>Dark</button>\n * <button onClick={() => setTheme('light')}>Light</button>\n * </>\n * )\n * ```\n */\nexport function useThemeByLocalStorage<Themes extends ThemeMap>(\n\tthemes: Themes,\n\toptions: {\n\t\tstorageKey: string\n\t\tdefaultTheme?: keyof Themes | undefined\n\t}\n): [keyof Themes | undefined, (theme: keyof Themes) => void] {\n\tconst { storageKey, defaultTheme } = options\n\n\tconst store = useMemo(() => localStorageThemeStore(themes, { storageKey }), [themes, storageKey])\n\n\tconst [theme, setThemeState] = useState<keyof Themes | undefined>(() => {\n\t\tif (typeof window !== 'undefined' && window.localStorage) {\n\t\t\tconst stored = window.localStorage.getItem(storageKey)\n\t\t\tconst resolved = parseStoredTheme(themes, stored)\n\t\t\treturn resolved ?? defaultTheme\n\t\t}\n\t\treturn defaultTheme\n\t})\n\n\tuseEffect(() => {\n\t\tconst unobserve = observeThemeFromStores([store], defaultTheme, setThemeState)\n\t\treturn unobserve\n\t}, [store, defaultTheme])\n\n\tconst setTheme = useCallback(\n\t\t(themeKey: keyof Themes) => {\n\t\t\tsetThemeToStores([store], themeEntry(themes, themeKey))\n\t\t},\n\t\t[store, themes]\n\t)\n\n\treturn [theme, setTheme]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,SAAgB,uBACf,QACA,SAI4D;CAC5D,MAAM,EAAE,YAAY,iBAAiB;CAErC,MAAM,iCAAsBA,yDAAuB,QAAQ,EAAE,YAAY,CAAC,EAAE,CAAC,QAAQ,WAAW,CAAC;CAEjG,MAAM,CAAC,OAAO,2CAA0D;AACvE,MAAI,OAAO,WAAW,eAAe,OAAO,aAG3C,QADiBC,4CAAiB,QADnB,OAAO,aAAa,QAAQ,WAAW,CACL,IAC9B;AAEpB,SAAO;GACN;AAEF,4BAAgB;AAEf,SADkBC,yDAAuB,CAAC,MAAM,EAAE,cAAc,cAAc;IAE5E,CAAC,OAAO,aAAa,CAAC;AASzB,QAAO,CAAC,+BANN,aAA2B;AAC3B,+CAAiB,CAAC,MAAM,EAAEC,+BAAW,QAAQ,SAAS,CAAC;IAExD,CAAC,OAAO,OAAO,CACf,CAEuB"}
1
+ {"version":3,"file":"use-theme-by-local-storage.cjs","names":["localStorageThemeStore","observeThemeFromStores","themeEntry"],"sources":["../../../src/react/hooks/use-theme-by-local-storage.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useState } from 'react'\nimport { observeThemeFromStores } from '../../theme/_utils/observe-theme-from-stores.ts'\nimport { setThemeToStores } from '../../theme/_utils/set-theme-to-stores.ts'\nimport { themeEntry } from '../../theme/theme-entry.ts'\nimport type { ThemeMap } from '../../theme/theme-map.types.ts'\nimport { localStorageThemeStore } from '../../theme/theme-store/local-storage-theme-store/local-storage-theme-store.ts'\n\n/**\n * React hook that returns the current theme (from localStorage) and a setter.\n * Subscribes to storage changes so the returned theme stays in sync across tabs.\n *\n * @param themes - Record mapping theme keys to their values\n * @param options.storageKey - localStorage key to persist the theme\n * @param options.defaultTheme - Fallback theme key when no stored value is found\n * @returns Tuple of [currentTheme, setTheme]\n *\n * @example\n * ```tsx\n * const themes = { light: 'theme-light', dark: 'theme-dark' }\n * const [theme, setTheme] = useThemeByLocalStorage(themes, {\n * storageKey: 'app-theme',\n * defaultTheme: 'light'\n * })\n *\n * return (\n * <>\n * <span>Current: {theme}</span>\n * <button onClick={() => setTheme('dark')}>Dark</button>\n * <button onClick={() => setTheme('light')}>Light</button>\n * </>\n * )\n * ```\n */\nexport function useThemeByLocalStorage<Themes extends ThemeMap>(\n\tthemes: Themes,\n\toptions: {\n\t\tstorageKey: string\n\t\tdefaultTheme?: keyof Themes | undefined\n\t}\n): [keyof Themes | undefined, (theme: keyof Themes) => void] {\n\tconst { storageKey, defaultTheme } = options\n\n\tconst store = useMemo(() => localStorageThemeStore(themes, { storageKey }), [themes, storageKey])\n\n\tconst [theme, setThemeState] = useState<keyof Themes | undefined>(\n\t\t() => store.read()?.theme ?? defaultTheme\n\t)\n\n\tuseEffect(() => {\n\t\tconst unobserve = observeThemeFromStores([store], defaultTheme, setThemeState)\n\t\treturn unobserve\n\t}, [store, defaultTheme])\n\n\tconst setTheme = useCallback(\n\t\t(themeKey: keyof Themes) => {\n\t\t\tsetThemeToStores([store], themeEntry(themes, themeKey))\n\t\t},\n\t\t[store, themes]\n\t)\n\n\treturn [theme, setTheme]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,SAAgB,uBACf,QACA,SAI4D;CAC5D,MAAM,EAAE,YAAY,iBAAiB;CAErC,MAAM,iCAAsBA,yDAAuB,QAAQ,EAAE,YAAY,CAAC,EAAE,CAAC,QAAQ,WAAW,CAAC;CAEjG,MAAM,CAAC,OAAO,2CACP,MAAM,MAAM,EAAE,SAAS,aAC7B;AAED,4BAAgB;AAEf,SADkBC,yDAAuB,CAAC,MAAM,EAAE,cAAc,cAAc;IAE5E,CAAC,OAAO,aAAa,CAAC;AASzB,QAAO,CAAC,+BANN,aAA2B;AAC3B,+CAAiB,CAAC,MAAM,EAAEC,+BAAW,QAAQ,SAAS,CAAC;IAExD,CAAC,OAAO,OAAO,CACf,CAEuB"}
@@ -1 +1 @@
1
- {"version":3,"file":"use-theme-by-local-storage.d.cts","names":[],"sources":["../../../src/react/hooks/use-theme-by-local-storage.ts"],"sourcesContent":[],"mappings":";;;;;;AAkCA;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,sCAAsC,kBAC7C;;uBAGc;WAEb,kCAAkC"}
1
+ {"version":3,"file":"use-theme-by-local-storage.d.cts","names":[],"sources":["../../../src/react/hooks/use-theme-by-local-storage.ts"],"sourcesContent":[],"mappings":";;;;;;AAiCA;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,sCAAsC,kBAC7C;;uBAGc;WAEb,kCAAkC"}
@@ -1 +1 @@
1
- {"version":3,"file":"use-theme-by-local-storage.d.mts","names":[],"sources":["../../../src/react/hooks/use-theme-by-local-storage.ts"],"sourcesContent":[],"mappings":";;;;;;AAkCA;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,sCAAsC,kBAC7C;;uBAGc;WAEb,kCAAkC"}
1
+ {"version":3,"file":"use-theme-by-local-storage.d.mts","names":[],"sources":["../../../src/react/hooks/use-theme-by-local-storage.ts"],"sourcesContent":[],"mappings":";;;;;;AAiCA;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,sCAAsC,kBAC7C;;uBAGc;WAEb,kCAAkC"}
@@ -1,7 +1,6 @@
1
1
  import { observeThemeFromStores } from "../../theme/_utils/observe-theme-from-stores.mjs";
2
2
  import { setThemeToStores } from "../../theme/_utils/set-theme-to-stores.mjs";
3
3
  import { themeEntry } from "../../theme/theme-entry.mjs";
4
- import { parseStoredTheme } from "../../theme/_utils/parse-stored-theme.mjs";
5
4
  import { localStorageThemeStore } from "../../theme/theme-store/local-storage-theme-store/local-storage-theme-store.mjs";
6
5
  import { useCallback, useEffect, useMemo, useState } from "react";
7
6
 
@@ -35,10 +34,7 @@ import { useCallback, useEffect, useMemo, useState } from "react";
35
34
  function useThemeByLocalStorage(themes, options) {
36
35
  const { storageKey, defaultTheme } = options;
37
36
  const store = useMemo(() => localStorageThemeStore(themes, { storageKey }), [themes, storageKey]);
38
- const [theme, setThemeState] = useState(() => {
39
- if (typeof window !== "undefined" && window.localStorage) return parseStoredTheme(themes, window.localStorage.getItem(storageKey)) ?? defaultTheme;
40
- return defaultTheme;
41
- });
37
+ const [theme, setThemeState] = useState(() => store.read()?.theme ?? defaultTheme);
42
38
  useEffect(() => {
43
39
  return observeThemeFromStores([store], defaultTheme, setThemeState);
44
40
  }, [store, defaultTheme]);
@@ -1 +1 @@
1
- {"version":3,"file":"use-theme-by-local-storage.mjs","names":[],"sources":["../../../src/react/hooks/use-theme-by-local-storage.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useState } from 'react'\nimport { observeThemeFromStores } from '../../theme/_utils/observe-theme-from-stores.ts'\nimport { parseStoredTheme } from '../../theme/_utils/parse-stored-theme.ts'\nimport { setThemeToStores } from '../../theme/_utils/set-theme-to-stores.ts'\nimport { themeEntry } from '../../theme/theme-entry.ts'\nimport type { ThemeMap } from '../../theme/theme-map.types.ts'\nimport { localStorageThemeStore } from '../../theme/theme-store/local-storage-theme-store/local-storage-theme-store.ts'\n\n/**\n * React hook that returns the current theme (from localStorage) and a setter.\n * Subscribes to storage changes so the returned theme stays in sync across tabs.\n *\n * @param themes - Record mapping theme keys to their values\n * @param options.storageKey - localStorage key to persist the theme\n * @param options.defaultTheme - Fallback theme key when no stored value is found\n * @returns Tuple of [currentTheme, setTheme]\n *\n * @example\n * ```tsx\n * const themes = { light: 'theme-light', dark: 'theme-dark' }\n * const [theme, setTheme] = useThemeByLocalStorage(themes, {\n * storageKey: 'app-theme',\n * defaultTheme: 'light'\n * })\n *\n * return (\n * <>\n * <span>Current: {theme}</span>\n * <button onClick={() => setTheme('dark')}>Dark</button>\n * <button onClick={() => setTheme('light')}>Light</button>\n * </>\n * )\n * ```\n */\nexport function useThemeByLocalStorage<Themes extends ThemeMap>(\n\tthemes: Themes,\n\toptions: {\n\t\tstorageKey: string\n\t\tdefaultTheme?: keyof Themes | undefined\n\t}\n): [keyof Themes | undefined, (theme: keyof Themes) => void] {\n\tconst { storageKey, defaultTheme } = options\n\n\tconst store = useMemo(() => localStorageThemeStore(themes, { storageKey }), [themes, storageKey])\n\n\tconst [theme, setThemeState] = useState<keyof Themes | undefined>(() => {\n\t\tif (typeof window !== 'undefined' && window.localStorage) {\n\t\t\tconst stored = window.localStorage.getItem(storageKey)\n\t\t\tconst resolved = parseStoredTheme(themes, stored)\n\t\t\treturn resolved ?? defaultTheme\n\t\t}\n\t\treturn defaultTheme\n\t})\n\n\tuseEffect(() => {\n\t\tconst unobserve = observeThemeFromStores([store], defaultTheme, setThemeState)\n\t\treturn unobserve\n\t}, [store, defaultTheme])\n\n\tconst setTheme = useCallback(\n\t\t(themeKey: keyof Themes) => {\n\t\t\tsetThemeToStores([store], themeEntry(themes, themeKey))\n\t\t},\n\t\t[store, themes]\n\t)\n\n\treturn [theme, setTheme]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,SAAgB,uBACf,QACA,SAI4D;CAC5D,MAAM,EAAE,YAAY,iBAAiB;CAErC,MAAM,QAAQ,cAAc,uBAAuB,QAAQ,EAAE,YAAY,CAAC,EAAE,CAAC,QAAQ,WAAW,CAAC;CAEjG,MAAM,CAAC,OAAO,iBAAiB,eAAyC;AACvE,MAAI,OAAO,WAAW,eAAe,OAAO,aAG3C,QADiB,iBAAiB,QADnB,OAAO,aAAa,QAAQ,WAAW,CACL,IAC9B;AAEpB,SAAO;GACN;AAEF,iBAAgB;AAEf,SADkB,uBAAuB,CAAC,MAAM,EAAE,cAAc,cAAc;IAE5E,CAAC,OAAO,aAAa,CAAC;AASzB,QAAO,CAAC,OAPS,aACf,aAA2B;AAC3B,mBAAiB,CAAC,MAAM,EAAE,WAAW,QAAQ,SAAS,CAAC;IAExD,CAAC,OAAO,OAAO,CACf,CAEuB"}
1
+ {"version":3,"file":"use-theme-by-local-storage.mjs","names":[],"sources":["../../../src/react/hooks/use-theme-by-local-storage.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useState } from 'react'\nimport { observeThemeFromStores } from '../../theme/_utils/observe-theme-from-stores.ts'\nimport { setThemeToStores } from '../../theme/_utils/set-theme-to-stores.ts'\nimport { themeEntry } from '../../theme/theme-entry.ts'\nimport type { ThemeMap } from '../../theme/theme-map.types.ts'\nimport { localStorageThemeStore } from '../../theme/theme-store/local-storage-theme-store/local-storage-theme-store.ts'\n\n/**\n * React hook that returns the current theme (from localStorage) and a setter.\n * Subscribes to storage changes so the returned theme stays in sync across tabs.\n *\n * @param themes - Record mapping theme keys to their values\n * @param options.storageKey - localStorage key to persist the theme\n * @param options.defaultTheme - Fallback theme key when no stored value is found\n * @returns Tuple of [currentTheme, setTheme]\n *\n * @example\n * ```tsx\n * const themes = { light: 'theme-light', dark: 'theme-dark' }\n * const [theme, setTheme] = useThemeByLocalStorage(themes, {\n * storageKey: 'app-theme',\n * defaultTheme: 'light'\n * })\n *\n * return (\n * <>\n * <span>Current: {theme}</span>\n * <button onClick={() => setTheme('dark')}>Dark</button>\n * <button onClick={() => setTheme('light')}>Light</button>\n * </>\n * )\n * ```\n */\nexport function useThemeByLocalStorage<Themes extends ThemeMap>(\n\tthemes: Themes,\n\toptions: {\n\t\tstorageKey: string\n\t\tdefaultTheme?: keyof Themes | undefined\n\t}\n): [keyof Themes | undefined, (theme: keyof Themes) => void] {\n\tconst { storageKey, defaultTheme } = options\n\n\tconst store = useMemo(() => localStorageThemeStore(themes, { storageKey }), [themes, storageKey])\n\n\tconst [theme, setThemeState] = useState<keyof Themes | undefined>(\n\t\t() => store.read()?.theme ?? defaultTheme\n\t)\n\n\tuseEffect(() => {\n\t\tconst unobserve = observeThemeFromStores([store], defaultTheme, setThemeState)\n\t\treturn unobserve\n\t}, [store, defaultTheme])\n\n\tconst setTheme = useCallback(\n\t\t(themeKey: keyof Themes) => {\n\t\t\tsetThemeToStores([store], themeEntry(themes, themeKey))\n\t\t},\n\t\t[store, themes]\n\t)\n\n\treturn [theme, setTheme]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,SAAgB,uBACf,QACA,SAI4D;CAC5D,MAAM,EAAE,YAAY,iBAAiB;CAErC,MAAM,QAAQ,cAAc,uBAAuB,QAAQ,EAAE,YAAY,CAAC,EAAE,CAAC,QAAQ,WAAW,CAAC;CAEjG,MAAM,CAAC,OAAO,iBAAiB,eACxB,MAAM,MAAM,EAAE,SAAS,aAC7B;AAED,iBAAgB;AAEf,SADkB,uBAAuB,CAAC,MAAM,EAAE,cAAc,cAAc;IAE5E,CAAC,OAAO,aAAa,CAAC;AASzB,QAAO,CAAC,OAPS,aACf,aAA2B;AAC3B,mBAAiB,CAAC,MAAM,EAAE,WAAW,QAAQ,SAAS,CAAC;IAExD,CAAC,OAAO,OAAO,CACf,CAEuB"}
@@ -0,0 +1,29 @@
1
+ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
+ const require_resolve_theme_map_value = require('./resolve-theme-map-value.cjs');
3
+ let type_plus = require("type-plus");
4
+
5
+ //#region src/theme/_utils/match-attribute-value-to-theme.ts
6
+ /**
7
+ * Matches an attribute value string against the theme map and returns the theme key.
8
+ * Pure function: no DOM access. Used by parseDataAttribute and custom parse paths.
9
+ *
10
+ * @param themes - Record mapping theme keys to attribute values
11
+ * @param attrValue - Attribute value string (e.g. from getAttribute)
12
+ * @param options.separator - When defined, split by separator and use first token
13
+ * @returns Theme key if a match is found, otherwise undefined
14
+ */
15
+ function matchAttributeValueToTheme(themes, attrValue, options) {
16
+ if (attrValue === null || attrValue === "") return void 0;
17
+ const valueToMatch = options?.separator !== void 0 ? attrValue.trim().split(options.separator).find((s) => s.trim() !== "") : attrValue;
18
+ if (valueToMatch === void 0) return void 0;
19
+ return (0, type_plus.findKey)(themes, (key) => {
20
+ const value = themes[key];
21
+ if (value === void 0) return false;
22
+ const resolved = require_resolve_theme_map_value.resolveThemeMapValue(value);
23
+ return (Array.isArray(resolved) ? resolved[0] : resolved) === valueToMatch;
24
+ });
25
+ }
26
+
27
+ //#endregion
28
+ exports.matchAttributeValueToTheme = matchAttributeValueToTheme;
29
+ //# sourceMappingURL=match-attribute-value-to-theme.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"match-attribute-value-to-theme.cjs","names":["resolveThemeMapValue"],"sources":["../../../src/theme/_utils/match-attribute-value-to-theme.ts"],"sourcesContent":["import { findKey } from 'type-plus'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport { resolveThemeMapValue } from './resolve-theme-map-value.ts'\n\n/**\n * Matches an attribute value string against the theme map and returns the theme key.\n * Pure function: no DOM access. Used by parseDataAttribute and custom parse paths.\n *\n * @param themes - Record mapping theme keys to attribute values\n * @param attrValue - Attribute value string (e.g. from getAttribute)\n * @param options.separator - When defined, split by separator and use first token\n * @returns Theme key if a match is found, otherwise undefined\n */\nexport function matchAttributeValueToTheme<Theme extends string>(\n\tthemes: ThemeMap<Theme>,\n\tattrValue: string | null,\n\toptions?: { separator?: string | undefined } | undefined\n): Theme | undefined {\n\tif (attrValue === null || attrValue === '') return undefined\n\tconst valueToMatch =\n\t\toptions?.separator !== undefined\n\t\t\t? attrValue\n\t\t\t\t\t.trim()\n\t\t\t\t\t.split(options.separator)\n\t\t\t\t\t.find((s) => s.trim() !== '')\n\t\t\t: attrValue\n\tif (valueToMatch === undefined) return undefined\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 === valueToMatch\n\t})\n\treturn theme\n}\n"],"mappings":";;;;;;;;;;;;;;AAaA,SAAgB,2BACf,QACA,WACA,SACoB;AACpB,KAAI,cAAc,QAAQ,cAAc,GAAI,QAAO;CACnD,MAAM,eACL,SAAS,cAAc,SACpB,UACC,MAAM,CACN,MAAM,QAAQ,UAAU,CACxB,MAAM,MAAM,EAAE,MAAM,KAAK,GAAG,GAC7B;AACJ,KAAI,iBAAiB,OAAW,QAAO;AAQvC,+BAPsB,SAAS,QAAQ;EACtC,MAAM,QAAQ,OAAO;AACrB,MAAI,UAAU,OAAW,QAAO;EAChC,MAAM,WAAWA,qDAAqB,MAAM;AAE5C,UADU,MAAM,QAAQ,SAAS,GAAG,SAAS,KAAK,cACrC;GACZ"}
@@ -0,0 +1,28 @@
1
+ import { resolveThemeMapValue } from "./resolve-theme-map-value.mjs";
2
+ import { findKey } from "type-plus";
3
+
4
+ //#region src/theme/_utils/match-attribute-value-to-theme.ts
5
+ /**
6
+ * Matches an attribute value string against the theme map and returns the theme key.
7
+ * Pure function: no DOM access. Used by parseDataAttribute and custom parse paths.
8
+ *
9
+ * @param themes - Record mapping theme keys to attribute values
10
+ * @param attrValue - Attribute value string (e.g. from getAttribute)
11
+ * @param options.separator - When defined, split by separator and use first token
12
+ * @returns Theme key if a match is found, otherwise undefined
13
+ */
14
+ function matchAttributeValueToTheme(themes, attrValue, options) {
15
+ if (attrValue === null || attrValue === "") return void 0;
16
+ const valueToMatch = options?.separator !== void 0 ? attrValue.trim().split(options.separator).find((s) => s.trim() !== "") : attrValue;
17
+ if (valueToMatch === void 0) return void 0;
18
+ return findKey(themes, (key) => {
19
+ const value = themes[key];
20
+ if (value === void 0) return false;
21
+ const resolved = resolveThemeMapValue(value);
22
+ return (Array.isArray(resolved) ? resolved[0] : resolved) === valueToMatch;
23
+ });
24
+ }
25
+
26
+ //#endregion
27
+ export { matchAttributeValueToTheme };
28
+ //# sourceMappingURL=match-attribute-value-to-theme.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"match-attribute-value-to-theme.mjs","names":[],"sources":["../../../src/theme/_utils/match-attribute-value-to-theme.ts"],"sourcesContent":["import { findKey } from 'type-plus'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport { resolveThemeMapValue } from './resolve-theme-map-value.ts'\n\n/**\n * Matches an attribute value string against the theme map and returns the theme key.\n * Pure function: no DOM access. Used by parseDataAttribute and custom parse paths.\n *\n * @param themes - Record mapping theme keys to attribute values\n * @param attrValue - Attribute value string (e.g. from getAttribute)\n * @param options.separator - When defined, split by separator and use first token\n * @returns Theme key if a match is found, otherwise undefined\n */\nexport function matchAttributeValueToTheme<Theme extends string>(\n\tthemes: ThemeMap<Theme>,\n\tattrValue: string | null,\n\toptions?: { separator?: string | undefined } | undefined\n): Theme | undefined {\n\tif (attrValue === null || attrValue === '') return undefined\n\tconst valueToMatch =\n\t\toptions?.separator !== undefined\n\t\t\t? attrValue\n\t\t\t\t\t.trim()\n\t\t\t\t\t.split(options.separator)\n\t\t\t\t\t.find((s) => s.trim() !== '')\n\t\t\t: attrValue\n\tif (valueToMatch === undefined) return undefined\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 === valueToMatch\n\t})\n\treturn theme\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,2BACf,QACA,WACA,SACoB;AACpB,KAAI,cAAc,QAAQ,cAAc,GAAI,QAAO;CACnD,MAAM,eACL,SAAS,cAAc,SACpB,UACC,MAAM,CACN,MAAM,QAAQ,UAAU,CACxB,MAAM,MAAM,EAAE,MAAM,KAAK,GAAG,GAC7B;AACJ,KAAI,iBAAiB,OAAW,QAAO;AAQvC,QAPc,QAAQ,SAAS,QAAQ;EACtC,MAAM,QAAQ,OAAO;AACrB,MAAI,UAAU,OAAW,QAAO;EAChC,MAAM,WAAW,qBAAqB,MAAM;AAE5C,UADU,MAAM,QAAQ,SAAS,GAAG,SAAS,KAAK,cACrC;GACZ"}
@@ -1,20 +1,74 @@
1
+ const require_resolve_theme_map_value = require('./resolve-theme-map-value.cjs');
1
2
  const require_try_parse_json = require('../../_internal/utils/try-parse-json.cjs');
2
3
 
3
4
  //#region src/theme/_utils/parse-stored-theme.ts
5
+ function getShapeAndComparable(v) {
6
+ if (typeof v === "string") return {
7
+ shape: "string",
8
+ comparable: v
9
+ };
10
+ if (Array.isArray(v)) return {
11
+ shape: "array",
12
+ comparable: v[0]
13
+ };
14
+ if (v !== null && typeof v === "object" && "themeValue" in v) {
15
+ const tv = v.themeValue;
16
+ if (typeof tv === "string") return {
17
+ shape: "object-string",
18
+ comparable: tv
19
+ };
20
+ if (Array.isArray(tv)) return {
21
+ shape: "object-array",
22
+ comparable: tv[0]
23
+ };
24
+ }
25
+ return null;
26
+ }
27
+ function getCanonicalShapeAndComparable(v) {
28
+ if (typeof v === "string") return {
29
+ shape: "string",
30
+ comparable: v
31
+ };
32
+ if (require_resolve_theme_map_value.isReadonlyStringArray(v)) return {
33
+ shape: "array",
34
+ comparable: v[0]
35
+ };
36
+ const tv = v.themeValue;
37
+ if (typeof tv === "string") return {
38
+ shape: "object-string",
39
+ comparable: tv
40
+ };
41
+ return {
42
+ shape: "object-array",
43
+ comparable: tv[0]
44
+ };
45
+ }
4
46
  /**
5
- * Parses stored JSON theme and validates the theme key against theme map.
47
+ * Parses stored JSON theme and validates against theme map with strict shape and comparable matching.
6
48
  *
7
49
  * Expects stored shape: { theme: string, value?: unknown }
8
50
  *
9
- * @param themes - Record of valid theme keys (optional; if omitted, any theme string is accepted)
10
- * @param value - Raw string from localStorage/sessionStorage
11
- * @returns Theme key if valid, otherwise undefined
51
+ * When shape matches AND comparable value (string or [0]) matches themes[theme]:
52
+ * returns { theme, value: stored.value }. Else returns undefined.
53
+ *
54
+ * @param themes - Record of valid theme keys and values (required for validation)
55
+ * @param value - Raw string from localStorage/sessionStorage/cookie
56
+ * @returns ThemeEntry when valid, otherwise undefined
12
57
  */
13
58
  function parseStoredTheme(themes, value) {
14
- const parsed = require_try_parse_json.tryParseJSON(value);
59
+ const parsed = require_try_parse_json.tryParseJSON(value ?? null);
15
60
  if (!parsed?.theme || typeof parsed.theme !== "string") return void 0;
16
- if (themes && !(parsed.theme in themes)) return void 0;
17
- return parsed.theme;
61
+ if (!themes || !(parsed.theme in themes)) return void 0;
62
+ if (parsed.value === void 0) return void 0;
63
+ const storedInfo = getShapeAndComparable(parsed.value);
64
+ if (!storedInfo) return void 0;
65
+ const canonical = getCanonicalShapeAndComparable(themes[parsed.theme]);
66
+ if (storedInfo.shape !== canonical.shape) return void 0;
67
+ if (storedInfo.comparable !== canonical.comparable) return void 0;
68
+ return {
69
+ theme: parsed.theme,
70
+ value: parsed.value
71
+ };
18
72
  }
19
73
 
20
74
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"parse-stored-theme.cjs","names":["tryParseJSON"],"sources":["../../../src/theme/_utils/parse-stored-theme.ts"],"sourcesContent":["import { tryParseJSON } from '../../_internal/utils/try-parse-json.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\n\n/**\n * Parses stored JSON theme and validates the theme key against theme map.\n *\n * Expects stored shape: { theme: string, value?: unknown }\n *\n * @param themes - Record of valid theme keys (optional; if omitted, any theme string is accepted)\n * @param value - Raw string from localStorage/sessionStorage\n * @returns Theme key if valid, otherwise undefined\n */\nexport function parseStoredTheme<Theme extends string>(\n\tthemes: ThemeMap<Theme> | undefined,\n\tvalue: string | null | undefined\n): Theme | undefined {\n\tconst parsed = tryParseJSON<{ theme: string }>(value)\n\tif (!parsed?.theme || typeof parsed.theme !== 'string') return undefined\n\tif (themes && !(parsed.theme in themes)) return undefined\n\treturn parsed.theme as Theme\n}\n"],"mappings":";;;;;;;;;;;;AAYA,SAAgB,iBACf,QACA,OACoB;CACpB,MAAM,SAASA,oCAAgC,MAAM;AACrD,KAAI,CAAC,QAAQ,SAAS,OAAO,OAAO,UAAU,SAAU,QAAO;AAC/D,KAAI,UAAU,EAAE,OAAO,SAAS,QAAS,QAAO;AAChD,QAAO,OAAO"}
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,20 +1,74 @@
1
+ import { isReadonlyStringArray } from "./resolve-theme-map-value.mjs";
1
2
  import { tryParseJSON } from "../../_internal/utils/try-parse-json.mjs";
2
3
 
3
4
  //#region src/theme/_utils/parse-stored-theme.ts
5
+ function getShapeAndComparable(v) {
6
+ if (typeof v === "string") return {
7
+ shape: "string",
8
+ comparable: v
9
+ };
10
+ if (Array.isArray(v)) return {
11
+ shape: "array",
12
+ comparable: v[0]
13
+ };
14
+ if (v !== null && typeof v === "object" && "themeValue" in v) {
15
+ const tv = v.themeValue;
16
+ if (typeof tv === "string") return {
17
+ shape: "object-string",
18
+ comparable: tv
19
+ };
20
+ if (Array.isArray(tv)) return {
21
+ shape: "object-array",
22
+ comparable: tv[0]
23
+ };
24
+ }
25
+ return null;
26
+ }
27
+ function getCanonicalShapeAndComparable(v) {
28
+ if (typeof v === "string") return {
29
+ shape: "string",
30
+ comparable: v
31
+ };
32
+ if (isReadonlyStringArray(v)) return {
33
+ shape: "array",
34
+ comparable: v[0]
35
+ };
36
+ const tv = v.themeValue;
37
+ if (typeof tv === "string") return {
38
+ shape: "object-string",
39
+ comparable: tv
40
+ };
41
+ return {
42
+ shape: "object-array",
43
+ comparable: tv[0]
44
+ };
45
+ }
4
46
  /**
5
- * Parses stored JSON theme and validates the theme key against theme map.
47
+ * Parses stored JSON theme and validates against theme map with strict shape and comparable matching.
6
48
  *
7
49
  * Expects stored shape: { theme: string, value?: unknown }
8
50
  *
9
- * @param themes - Record of valid theme keys (optional; if omitted, any theme string is accepted)
10
- * @param value - Raw string from localStorage/sessionStorage
11
- * @returns Theme key if valid, otherwise undefined
51
+ * When shape matches AND comparable value (string or [0]) matches themes[theme]:
52
+ * returns { theme, value: stored.value }. Else returns undefined.
53
+ *
54
+ * @param themes - Record of valid theme keys and values (required for validation)
55
+ * @param value - Raw string from localStorage/sessionStorage/cookie
56
+ * @returns ThemeEntry when valid, otherwise undefined
12
57
  */
13
58
  function parseStoredTheme(themes, value) {
14
- const parsed = tryParseJSON(value);
59
+ const parsed = tryParseJSON(value ?? null);
15
60
  if (!parsed?.theme || typeof parsed.theme !== "string") return void 0;
16
- if (themes && !(parsed.theme in themes)) return void 0;
17
- return parsed.theme;
61
+ if (!themes || !(parsed.theme in themes)) return void 0;
62
+ if (parsed.value === void 0) return void 0;
63
+ const storedInfo = getShapeAndComparable(parsed.value);
64
+ if (!storedInfo) return void 0;
65
+ const canonical = getCanonicalShapeAndComparable(themes[parsed.theme]);
66
+ if (storedInfo.shape !== canonical.shape) return void 0;
67
+ if (storedInfo.comparable !== canonical.comparable) return void 0;
68
+ return {
69
+ theme: parsed.theme,
70
+ value: parsed.value
71
+ };
18
72
  }
19
73
 
20
74
  //#endregion
@@ -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 { ThemeMap } from '../theme-map.types.ts'\n\n/**\n * Parses stored JSON theme and validates the theme key against theme map.\n *\n * Expects stored shape: { theme: string, value?: unknown }\n *\n * @param themes - Record of valid theme keys (optional; if omitted, any theme string is accepted)\n * @param value - Raw string from localStorage/sessionStorage\n * @returns Theme key if valid, otherwise undefined\n */\nexport function parseStoredTheme<Theme extends string>(\n\tthemes: ThemeMap<Theme> | undefined,\n\tvalue: string | null | undefined\n): Theme | undefined {\n\tconst parsed = tryParseJSON<{ theme: string }>(value)\n\tif (!parsed?.theme || typeof parsed.theme !== 'string') return undefined\n\tif (themes && !(parsed.theme in themes)) return undefined\n\treturn parsed.theme as Theme\n}\n"],"mappings":";;;;;;;;;;;;AAYA,SAAgB,iBACf,QACA,OACoB;CACpB,MAAM,SAAS,aAAgC,MAAM;AACrD,KAAI,CAAC,QAAQ,SAAS,OAAO,OAAO,UAAU,SAAU,QAAO;AAC/D,KAAI,UAAU,EAAE,OAAO,SAAS,QAAS,QAAO;AAChD,QAAO,OAAO"}
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"}
@@ -0,0 +1,19 @@
1
+
2
+ //#region src/theme/_utils/resolve-theme-map-value.ts
3
+ function isReadonlyStringArray(v) {
4
+ return Array.isArray(v);
5
+ }
6
+ /**
7
+ * Resolves ThemeMapValue to its underlying string or string[] for DOM application and matching.
8
+ * Used when applying themes to className, data attributes, or when resolving theme from DOM.
9
+ */
10
+ function resolveThemeMapValue(v) {
11
+ if (typeof v === "string") return v;
12
+ if (isReadonlyStringArray(v)) return v;
13
+ return v.themeValue;
14
+ }
15
+
16
+ //#endregion
17
+ exports.isReadonlyStringArray = isReadonlyStringArray;
18
+ exports.resolveThemeMapValue = resolveThemeMapValue;
19
+ //# sourceMappingURL=resolve-theme-map-value.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-theme-map-value.cjs","names":[],"sources":["../../../src/theme/_utils/resolve-theme-map-value.ts"],"sourcesContent":["import type { ThemeMapValue } from '../theme-map.types.ts'\n\nexport function isReadonlyStringArray(v: ThemeMapValue): v is readonly string[] {\n\treturn Array.isArray(v)\n}\n\n/**\n * Resolves ThemeMapValue to its underlying string or string[] for DOM application and matching.\n * Used when applying themes to className, data attributes, or when resolving theme from DOM.\n */\nexport function resolveThemeMapValue(v: ThemeMapValue): string | readonly string[] {\n\tif (typeof v === 'string') return v\n\tif (isReadonlyStringArray(v)) return v\n\treturn v.themeValue\n}\n"],"mappings":";;AAEA,SAAgB,sBAAsB,GAA0C;AAC/E,QAAO,MAAM,QAAQ,EAAE;;;;;;AAOxB,SAAgB,qBAAqB,GAA8C;AAClF,KAAI,OAAO,MAAM,SAAU,QAAO;AAClC,KAAI,sBAAsB,EAAE,CAAE,QAAO;AACrC,QAAO,EAAE"}
@@ -0,0 +1,17 @@
1
+ //#region src/theme/_utils/resolve-theme-map-value.ts
2
+ function isReadonlyStringArray(v) {
3
+ return Array.isArray(v);
4
+ }
5
+ /**
6
+ * Resolves ThemeMapValue to its underlying string or string[] for DOM application and matching.
7
+ * Used when applying themes to className, data attributes, or when resolving theme from DOM.
8
+ */
9
+ function resolveThemeMapValue(v) {
10
+ if (typeof v === "string") return v;
11
+ if (isReadonlyStringArray(v)) return v;
12
+ return v.themeValue;
13
+ }
14
+
15
+ //#endregion
16
+ export { isReadonlyStringArray, resolveThemeMapValue };
17
+ //# sourceMappingURL=resolve-theme-map-value.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-theme-map-value.mjs","names":[],"sources":["../../../src/theme/_utils/resolve-theme-map-value.ts"],"sourcesContent":["import type { ThemeMapValue } from '../theme-map.types.ts'\n\nexport function isReadonlyStringArray(v: ThemeMapValue): v is readonly string[] {\n\treturn Array.isArray(v)\n}\n\n/**\n * Resolves ThemeMapValue to its underlying string or string[] for DOM application and matching.\n * Used when applying themes to className, data attributes, or when resolving theme from DOM.\n */\nexport function resolveThemeMapValue(v: ThemeMapValue): string | readonly string[] {\n\tif (typeof v === 'string') return v\n\tif (isReadonlyStringArray(v)) return v\n\treturn v.themeValue\n}\n"],"mappings":";AAEA,SAAgB,sBAAsB,GAA0C;AAC/E,QAAO,MAAM,QAAQ,EAAE;;;;;;AAOxB,SAAgB,qBAAqB,GAA8C;AAClF,KAAI,OAAO,MAAM,SAAU,QAAO;AAClC,KAAI,sBAAsB,EAAE,CAAE,QAAO;AACrC,QAAO,EAAE"}