@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.
- package/dist/react/hooks/use-theme-by-class-name.cjs +1 -5
- package/dist/react/hooks/use-theme-by-class-name.cjs.map +1 -1
- package/dist/react/hooks/use-theme-by-class-name.d.cts.map +1 -1
- package/dist/react/hooks/use-theme-by-class-name.d.mts.map +1 -1
- package/dist/react/hooks/use-theme-by-class-name.mjs +1 -5
- package/dist/react/hooks/use-theme-by-class-name.mjs.map +1 -1
- package/dist/react/hooks/use-theme-by-data-attribute.cjs +1 -6
- package/dist/react/hooks/use-theme-by-data-attribute.cjs.map +1 -1
- package/dist/react/hooks/use-theme-by-data-attribute.d.cts.map +1 -1
- package/dist/react/hooks/use-theme-by-data-attribute.d.mts.map +1 -1
- package/dist/react/hooks/use-theme-by-data-attribute.mjs +1 -6
- package/dist/react/hooks/use-theme-by-data-attribute.mjs.map +1 -1
- package/dist/react/hooks/use-theme-by-local-storage.cjs +1 -5
- package/dist/react/hooks/use-theme-by-local-storage.cjs.map +1 -1
- package/dist/react/hooks/use-theme-by-local-storage.d.cts.map +1 -1
- package/dist/react/hooks/use-theme-by-local-storage.d.mts.map +1 -1
- package/dist/react/hooks/use-theme-by-local-storage.mjs +1 -5
- package/dist/react/hooks/use-theme-by-local-storage.mjs.map +1 -1
- package/dist/theme/_utils/match-attribute-value-to-theme.cjs +29 -0
- package/dist/theme/_utils/match-attribute-value-to-theme.cjs.map +1 -0
- package/dist/theme/_utils/match-attribute-value-to-theme.mjs +28 -0
- package/dist/theme/_utils/match-attribute-value-to-theme.mjs.map +1 -0
- package/dist/theme/_utils/parse-stored-theme.cjs +61 -7
- package/dist/theme/_utils/parse-stored-theme.cjs.map +1 -1
- package/dist/theme/_utils/parse-stored-theme.mjs +61 -7
- package/dist/theme/_utils/parse-stored-theme.mjs.map +1 -1
- package/dist/theme/_utils/resolve-theme-map-value.cjs +19 -0
- package/dist/theme/_utils/resolve-theme-map-value.cjs.map +1 -0
- package/dist/theme/_utils/resolve-theme-map-value.mjs +17 -0
- package/dist/theme/_utils/resolve-theme-map-value.mjs.map +1 -0
- package/dist/theme/class-name/parse-class-name.cjs +32 -0
- package/dist/theme/class-name/parse-class-name.cjs.map +1 -0
- package/dist/theme/class-name/parse-class-name.d.cts +20 -0
- package/dist/theme/class-name/parse-class-name.d.cts.map +1 -0
- package/dist/theme/class-name/parse-class-name.d.mts +20 -0
- package/dist/theme/class-name/parse-class-name.d.mts.map +1 -0
- package/dist/theme/class-name/parse-class-name.mjs +31 -0
- package/dist/theme/class-name/parse-class-name.mjs.map +1 -0
- package/dist/theme/class-name/read-class-name.cjs +20 -0
- package/dist/theme/class-name/read-class-name.cjs.map +1 -0
- package/dist/theme/class-name/read-class-name.d.cts +20 -0
- package/dist/theme/class-name/read-class-name.d.cts.map +1 -0
- package/dist/theme/class-name/read-class-name.d.mts +20 -0
- package/dist/theme/class-name/read-class-name.d.mts.map +1 -0
- package/dist/theme/class-name/read-class-name.mjs +20 -0
- package/dist/theme/class-name/read-class-name.mjs.map +1 -0
- package/dist/theme/class-name/stringify-class-name.cjs +31 -0
- package/dist/theme/class-name/stringify-class-name.cjs.map +1 -0
- package/dist/theme/class-name/stringify-class-name.d.cts +21 -0
- package/dist/theme/class-name/stringify-class-name.d.cts.map +1 -0
- package/dist/theme/class-name/stringify-class-name.d.mts +21 -0
- package/dist/theme/class-name/stringify-class-name.d.mts.map +1 -0
- package/dist/theme/class-name/stringify-class-name.mjs +31 -0
- package/dist/theme/class-name/stringify-class-name.mjs.map +1 -0
- package/dist/theme/class-name/subscribe-class-name.cjs +31 -0
- package/dist/theme/class-name/subscribe-class-name.cjs.map +1 -0
- package/dist/theme/class-name/subscribe-class-name.d.cts +21 -0
- package/dist/theme/class-name/subscribe-class-name.d.cts.map +1 -0
- package/dist/theme/class-name/subscribe-class-name.d.mts +21 -0
- package/dist/theme/class-name/subscribe-class-name.d.mts.map +1 -0
- package/dist/theme/class-name/subscribe-class-name.mjs +31 -0
- package/dist/theme/class-name/subscribe-class-name.mjs.map +1 -0
- package/dist/theme/class-name/write-class-name.cjs +20 -0
- package/dist/theme/class-name/write-class-name.cjs.map +1 -0
- package/dist/theme/class-name/write-class-name.d.cts +20 -0
- package/dist/theme/class-name/write-class-name.d.cts.map +1 -0
- package/dist/theme/class-name/write-class-name.d.mts +20 -0
- package/dist/theme/class-name/write-class-name.d.mts.map +1 -0
- package/dist/theme/class-name/write-class-name.mjs +20 -0
- package/dist/theme/class-name/write-class-name.mjs.map +1 -0
- package/dist/theme/cookie/_cookie-utils.cjs +37 -0
- package/dist/theme/cookie/_cookie-utils.cjs.map +1 -0
- package/dist/theme/cookie/_cookie-utils.mjs +33 -0
- package/dist/theme/cookie/_cookie-utils.mjs.map +1 -0
- package/dist/theme/cookie/read-cookie-theme.cjs +22 -0
- package/dist/theme/cookie/read-cookie-theme.cjs.map +1 -0
- package/dist/theme/cookie/read-cookie-theme.d.cts +22 -0
- package/dist/theme/cookie/read-cookie-theme.d.cts.map +1 -0
- package/dist/theme/cookie/read-cookie-theme.d.mts +22 -0
- package/dist/theme/cookie/read-cookie-theme.d.mts.map +1 -0
- package/dist/theme/cookie/read-cookie-theme.mjs +22 -0
- package/dist/theme/cookie/read-cookie-theme.mjs.map +1 -0
- package/dist/theme/cookie/write-cookie-theme.cjs +29 -0
- package/dist/theme/cookie/write-cookie-theme.cjs.map +1 -0
- package/dist/theme/cookie/write-cookie-theme.d.cts +24 -0
- package/dist/theme/cookie/write-cookie-theme.d.cts.map +1 -0
- package/dist/theme/cookie/write-cookie-theme.d.mts +24 -0
- package/dist/theme/cookie/write-cookie-theme.d.mts.map +1 -0
- package/dist/theme/cookie/write-cookie-theme.mjs +29 -0
- package/dist/theme/cookie/write-cookie-theme.mjs.map +1 -0
- package/dist/theme/data-attribute/_constant.cjs +7 -0
- package/dist/theme/data-attribute/_constant.cjs.map +1 -0
- package/dist/theme/data-attribute/_constant.mjs +6 -0
- package/dist/theme/data-attribute/_constant.mjs.map +1 -0
- package/dist/theme/data-attribute/parse-data-attribute.cjs +24 -0
- package/dist/theme/data-attribute/parse-data-attribute.cjs.map +1 -0
- package/dist/theme/data-attribute/parse-data-attribute.d.cts +21 -0
- package/dist/theme/data-attribute/parse-data-attribute.d.cts.map +1 -0
- package/dist/theme/data-attribute/parse-data-attribute.d.mts +21 -0
- package/dist/theme/data-attribute/parse-data-attribute.d.mts.map +1 -0
- package/dist/theme/data-attribute/parse-data-attribute.mjs +24 -0
- package/dist/theme/data-attribute/parse-data-attribute.mjs.map +1 -0
- package/dist/theme/data-attribute/read-data-attribute.cjs +23 -0
- package/dist/theme/data-attribute/read-data-attribute.cjs.map +1 -0
- package/dist/theme/data-attribute/read-data-attribute.d.cts +21 -0
- package/dist/theme/data-attribute/read-data-attribute.d.cts.map +1 -0
- package/dist/theme/data-attribute/read-data-attribute.d.mts +21 -0
- package/dist/theme/data-attribute/read-data-attribute.d.mts.map +1 -0
- package/dist/theme/data-attribute/read-data-attribute.mjs +23 -0
- package/dist/theme/data-attribute/read-data-attribute.mjs.map +1 -0
- package/dist/theme/data-attribute/stringify-data-attribute.cjs +33 -0
- package/dist/theme/data-attribute/stringify-data-attribute.cjs.map +1 -0
- package/dist/theme/data-attribute/stringify-data-attribute.d.cts +23 -0
- package/dist/theme/data-attribute/stringify-data-attribute.d.cts.map +1 -0
- package/dist/theme/data-attribute/stringify-data-attribute.d.mts +23 -0
- package/dist/theme/data-attribute/stringify-data-attribute.d.mts.map +1 -0
- package/dist/theme/data-attribute/stringify-data-attribute.mjs +33 -0
- package/dist/theme/data-attribute/stringify-data-attribute.mjs.map +1 -0
- package/dist/theme/data-attribute/subscribe-data-attribute.cjs +28 -0
- package/dist/theme/data-attribute/subscribe-data-attribute.cjs.map +1 -0
- package/dist/theme/data-attribute/subscribe-data-attribute.d.cts +22 -0
- package/dist/theme/data-attribute/subscribe-data-attribute.d.cts.map +1 -0
- package/dist/theme/data-attribute/subscribe-data-attribute.d.mts +22 -0
- package/dist/theme/data-attribute/subscribe-data-attribute.d.mts.map +1 -0
- package/dist/theme/data-attribute/subscribe-data-attribute.mjs +28 -0
- package/dist/theme/data-attribute/subscribe-data-attribute.mjs.map +1 -0
- package/dist/theme/data-attribute/write-data-attribute.cjs +30 -0
- package/dist/theme/data-attribute/write-data-attribute.cjs.map +1 -0
- package/dist/theme/data-attribute/write-data-attribute.d.cts +21 -0
- package/dist/theme/data-attribute/write-data-attribute.d.cts.map +1 -0
- package/dist/theme/data-attribute/write-data-attribute.d.mts +21 -0
- package/dist/theme/data-attribute/write-data-attribute.d.mts.map +1 -0
- package/dist/theme/data-attribute/write-data-attribute.mjs +30 -0
- package/dist/theme/data-attribute/write-data-attribute.mjs.map +1 -0
- package/dist/theme/local-storage/read-local-storage.cjs +22 -0
- package/dist/theme/local-storage/read-local-storage.cjs.map +1 -0
- package/dist/theme/local-storage/read-local-storage.d.cts +19 -0
- package/dist/theme/local-storage/read-local-storage.d.cts.map +1 -0
- package/dist/theme/local-storage/read-local-storage.d.mts +19 -0
- package/dist/theme/local-storage/read-local-storage.d.mts.map +1 -0
- package/dist/theme/local-storage/read-local-storage.mjs +22 -0
- package/dist/theme/local-storage/read-local-storage.mjs.map +1 -0
- package/dist/theme/local-storage/write-local-storage.cjs +26 -0
- package/dist/theme/local-storage/write-local-storage.cjs.map +1 -0
- package/dist/theme/local-storage/write-local-storage.d.cts +23 -0
- package/dist/theme/local-storage/write-local-storage.d.cts.map +1 -0
- package/dist/theme/local-storage/write-local-storage.d.mts +23 -0
- package/dist/theme/local-storage/write-local-storage.d.mts.map +1 -0
- package/dist/theme/local-storage/write-local-storage.mjs +26 -0
- package/dist/theme/local-storage/write-local-storage.mjs.map +1 -0
- package/dist/theme/prefers-color-scheme-theme/read-prefers-color-scheme-theme.cjs +20 -0
- package/dist/theme/prefers-color-scheme-theme/read-prefers-color-scheme-theme.cjs.map +1 -0
- package/dist/theme/prefers-color-scheme-theme/read-prefers-color-scheme-theme.d.cts +23 -0
- package/dist/theme/prefers-color-scheme-theme/read-prefers-color-scheme-theme.d.cts.map +1 -0
- package/dist/theme/prefers-color-scheme-theme/read-prefers-color-scheme-theme.d.mts +23 -0
- package/dist/theme/prefers-color-scheme-theme/read-prefers-color-scheme-theme.d.mts.map +1 -0
- package/dist/theme/prefers-color-scheme-theme/read-prefers-color-scheme-theme.mjs +20 -0
- package/dist/theme/prefers-color-scheme-theme/read-prefers-color-scheme-theme.mjs.map +1 -0
- package/dist/theme/prefers-color-scheme-theme/subscribe-prefers-color-scheme-theme.cjs +20 -0
- package/dist/theme/prefers-color-scheme-theme/subscribe-prefers-color-scheme-theme.cjs.map +1 -0
- package/dist/theme/prefers-color-scheme-theme/subscribe-prefers-color-scheme-theme.d.cts +20 -0
- package/dist/theme/prefers-color-scheme-theme/subscribe-prefers-color-scheme-theme.d.cts.map +1 -0
- package/dist/theme/prefers-color-scheme-theme/subscribe-prefers-color-scheme-theme.d.mts +20 -0
- package/dist/theme/prefers-color-scheme-theme/subscribe-prefers-color-scheme-theme.d.mts.map +1 -0
- package/dist/theme/prefers-color-scheme-theme/subscribe-prefers-color-scheme-theme.mjs +20 -0
- package/dist/theme/prefers-color-scheme-theme/subscribe-prefers-color-scheme-theme.mjs.map +1 -0
- package/dist/theme/session-storage/read-session-storage.cjs +22 -0
- package/dist/theme/session-storage/read-session-storage.cjs.map +1 -0
- package/dist/theme/session-storage/read-session-storage.d.cts +19 -0
- package/dist/theme/session-storage/read-session-storage.d.cts.map +1 -0
- package/dist/theme/session-storage/read-session-storage.d.mts +19 -0
- package/dist/theme/session-storage/read-session-storage.d.mts.map +1 -0
- package/dist/theme/session-storage/read-session-storage.mjs +22 -0
- package/dist/theme/session-storage/read-session-storage.mjs.map +1 -0
- package/dist/theme/session-storage/write-session-storage.cjs +26 -0
- package/dist/theme/session-storage/write-session-storage.cjs.map +1 -0
- package/dist/theme/session-storage/write-session-storage.d.cts +23 -0
- package/dist/theme/session-storage/write-session-storage.d.cts.map +1 -0
- package/dist/theme/session-storage/write-session-storage.d.mts +23 -0
- package/dist/theme/session-storage/write-session-storage.d.mts.map +1 -0
- package/dist/theme/session-storage/write-session-storage.mjs +26 -0
- package/dist/theme/session-storage/write-session-storage.mjs.map +1 -0
- package/dist/theme/theme-entry.types.d.cts +11 -1
- package/dist/theme/theme-entry.types.d.cts.map +1 -1
- package/dist/theme/theme-entry.types.d.mts +11 -1
- package/dist/theme/theme-entry.types.d.mts.map +1 -1
- package/dist/theme/theme-map.types.d.cts +11 -3
- package/dist/theme/theme-map.types.d.cts.map +1 -1
- package/dist/theme/theme-map.types.d.mts +11 -3
- package/dist/theme/theme-map.types.d.mts.map +1 -1
- package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.cjs +21 -18
- package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.cjs.map +1 -1
- package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.d.cts +5 -0
- package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.d.cts.map +1 -1
- package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.d.mts +5 -0
- package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.d.mts.map +1 -1
- package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.mjs +21 -18
- package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.mjs.map +1 -1
- package/dist/theme/theme-store/cookie-theme-store/cookie-theme-store.cjs +18 -36
- package/dist/theme/theme-store/cookie-theme-store/cookie-theme-store.cjs.map +1 -1
- package/dist/theme/theme-store/cookie-theme-store/cookie-theme-store.d.cts +5 -3
- package/dist/theme/theme-store/cookie-theme-store/cookie-theme-store.d.cts.map +1 -1
- package/dist/theme/theme-store/cookie-theme-store/cookie-theme-store.d.mts +5 -3
- package/dist/theme/theme-store/cookie-theme-store/cookie-theme-store.d.mts.map +1 -1
- package/dist/theme/theme-store/cookie-theme-store/cookie-theme-store.mjs +18 -36
- package/dist/theme/theme-store/cookie-theme-store/cookie-theme-store.mjs.map +1 -1
- package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.cjs +39 -19
- package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.cjs.map +1 -1
- package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.d.cts +28 -5
- package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.d.cts.map +1 -1
- package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.d.mts +28 -5
- package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.d.mts.map +1 -1
- package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.mjs +39 -19
- package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.mjs.map +1 -1
- package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.cjs +13 -12
- package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.cjs.map +1 -1
- package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.d.cts +7 -1
- package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.d.cts.map +1 -1
- package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.d.mts +7 -1
- package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.d.mts.map +1 -1
- package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.mjs +13 -12
- package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.mjs.map +1 -1
- package/dist/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.cjs +4 -5
- package/dist/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.cjs.map +1 -1
- package/dist/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.d.cts.map +1 -1
- package/dist/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.d.mts.map +1 -1
- package/dist/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.mjs +4 -5
- package/dist/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.mjs.map +1 -1
- package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.cjs +13 -12
- package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.cjs.map +1 -1
- package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.d.cts +7 -1
- package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.d.cts.map +1 -1
- package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.d.mts +7 -1
- package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.d.mts.map +1 -1
- package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.mjs +13 -12
- package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.mjs.map +1 -1
- package/dist/theme/web-storage/read-web-storage.cjs +20 -0
- package/dist/theme/web-storage/read-web-storage.cjs.map +1 -0
- package/dist/theme/web-storage/read-web-storage.d.cts +21 -0
- package/dist/theme/web-storage/read-web-storage.d.cts.map +1 -0
- package/dist/theme/web-storage/read-web-storage.d.mts +21 -0
- package/dist/theme/web-storage/read-web-storage.d.mts.map +1 -0
- package/dist/theme/web-storage/read-web-storage.mjs +20 -0
- package/dist/theme/web-storage/read-web-storage.mjs.map +1 -0
- package/dist/theme/web-storage/write-web-storage.cjs +33 -0
- package/dist/theme/web-storage/write-web-storage.cjs.map +1 -0
- package/dist/theme/web-storage/write-web-storage.d.cts +25 -0
- package/dist/theme/web-storage/write-web-storage.d.cts.map +1 -0
- package/dist/theme/web-storage/write-web-storage.d.mts +25 -0
- package/dist/theme/web-storage/write-web-storage.d.mts.map +1 -0
- package/dist/theme/web-storage/write-web-storage.mjs +32 -0
- package/dist/theme/web-storage/write-web-storage.mjs.map +1 -0
- package/dist/theme.cjs +41 -1
- package/dist/theme.d.cts +23 -3
- package/dist/theme.d.mts +23 -3
- package/dist/theme.mjs +21 -1
- package/package.json +1 -1
- package/src/react/hooks/use-theme-by-class-name.ts +3 -8
- package/src/react/hooks/use-theme-by-data-attribute.ts +3 -10
- package/src/react/hooks/use-theme-by-local-storage.ts +3 -9
- package/src/testing/theme/theme-result-card.tsx +1 -0
- package/src/theme/_utils/match-attribute-value-to-theme.ts +36 -0
- package/src/theme/_utils/parse-stored-theme.ts +52 -12
- package/src/theme/_utils/resolve-theme-map-value.ts +15 -0
- package/src/theme/class-name/parse-class-name.ts +31 -0
- package/src/theme/class-name/read-class-name.ts +24 -0
- package/src/theme/class-name/stringify-class-name.ts +36 -0
- package/src/theme/class-name/subscribe-class-name.ts +39 -0
- package/src/theme/class-name/write-class-name.ts +24 -0
- package/src/theme/cookie/_cookie-utils.ts +45 -0
- package/src/theme/cookie/read-cookie-theme.ts +33 -0
- package/src/theme/cookie/write-cookie-theme.ts +48 -0
- package/src/theme/data-attribute/_constant.ts +1 -0
- package/src/theme/data-attribute/parse-data-attribute.ts +25 -0
- package/src/theme/data-attribute/read-data-attribute.ts +29 -0
- package/src/theme/data-attribute/stringify-data-attribute.ts +39 -0
- package/src/theme/data-attribute/subscribe-data-attribute.ts +39 -0
- package/src/theme/data-attribute/write-data-attribute.ts +40 -0
- package/src/theme/local-storage/read-local-storage.ts +23 -0
- package/src/theme/local-storage/write-local-storage.ts +31 -0
- package/src/theme/prefers-color-scheme-theme/read-prefers-color-scheme-theme.ts +30 -0
- package/src/theme/prefers-color-scheme-theme/subscribe-prefers-color-scheme-theme.ts +24 -0
- package/src/theme/session-storage/read-session-storage.ts +23 -0
- package/src/theme/session-storage/write-session-storage.ts +31 -0
- package/src/theme/theme-entry.types.ts +19 -0
- package/src/theme/theme-map.types.ts +9 -2
- package/src/theme/theme-store/class-name-theme-store/class-name-theme-store.ts +19 -25
- package/src/theme/theme-store/cookie-theme-store/cookie-theme-store.ts +18 -63
- package/src/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.ts +41 -28
- package/src/theme/theme-store/local-storage-theme-store/local-storage-theme-store.ts +17 -20
- package/src/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.ts +4 -5
- package/src/theme/theme-store/session-storage-theme-store/session-storage-theme-store.ts +17 -20
- package/src/theme/web-storage/read-web-storage.ts +22 -0
- package/src/theme/web-storage/write-web-storage.ts +46 -0
- package/src/theme.ts +20 -0
- package/dist/theme/class-name/apply-theme-to-class-name.cjs +0 -23
- package/dist/theme/class-name/apply-theme-to-class-name.cjs.map +0 -1
- package/dist/theme/class-name/apply-theme-to-class-name.mjs +0 -22
- package/dist/theme/class-name/apply-theme-to-class-name.mjs.map +0 -1
- package/dist/theme/class-name/resolve-theme-from-class-name.cjs +0 -23
- package/dist/theme/class-name/resolve-theme-from-class-name.cjs.map +0 -1
- package/dist/theme/class-name/resolve-theme-from-class-name.mjs +0 -22
- package/dist/theme/class-name/resolve-theme-from-class-name.mjs.map +0 -1
- package/dist/theme/data-attribute/apply-theme-to-data-attribute.cjs +0 -23
- package/dist/theme/data-attribute/apply-theme-to-data-attribute.cjs.map +0 -1
- package/dist/theme/data-attribute/apply-theme-to-data-attribute.mjs +0 -22
- package/dist/theme/data-attribute/apply-theme-to-data-attribute.mjs.map +0 -1
- package/dist/theme/data-attribute/resolve-theme-from-data-attribute.cjs +0 -23
- package/dist/theme/data-attribute/resolve-theme-from-data-attribute.cjs.map +0 -1
- package/dist/theme/data-attribute/resolve-theme-from-data-attribute.mjs +0 -22
- package/dist/theme/data-attribute/resolve-theme-from-data-attribute.mjs.map +0 -1
- package/src/theme/class-name/apply-theme-to-class-name.ts +0 -26
- package/src/theme/class-name/resolve-theme-from-class-name.ts +0 -22
- package/src/theme/data-attribute/apply-theme-to-data-attribute.ts +0 -27
- 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","
|
|
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":";;;;;;
|
|
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":";;;;;;
|
|
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 {
|
|
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","
|
|
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":";;;;;;
|
|
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":";;;;;;
|
|
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 {
|
|
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","
|
|
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":";;;;;;
|
|
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":";;;;;;
|
|
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 {
|
|
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
|
|
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
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
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
|
|
17
|
-
|
|
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
|
|
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
|
|
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
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
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
|
|
17
|
-
|
|
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
|
|
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"}
|