@just-web/toolkits 1.0.0 → 2.1.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/attributes/get-attribute.cjs +1 -1
- package/dist/attributes/get-attribute.cjs.map +1 -1
- package/dist/attributes/get-attribute.d.cts +2 -2
- package/dist/attributes/get-attribute.d.cts.map +1 -1
- package/dist/attributes/get-attribute.d.mts +2 -2
- package/dist/attributes/get-attribute.d.mts.map +1 -1
- package/dist/attributes/get-attribute.mjs +1 -1
- package/dist/attributes/get-attribute.mjs.map +1 -1
- package/dist/attributes/get-data-attribute.cjs +1 -1
- package/dist/attributes/get-data-attribute.cjs.map +1 -1
- package/dist/attributes/get-data-attribute.d.cts +2 -2
- package/dist/attributes/get-data-attribute.d.cts.map +1 -1
- package/dist/attributes/get-data-attribute.d.mts +2 -2
- package/dist/attributes/get-data-attribute.d.mts.map +1 -1
- package/dist/attributes/get-data-attribute.mjs +1 -1
- package/dist/attributes/get-data-attribute.mjs.map +1 -1
- package/dist/attributes/observe-attribute.cjs +1 -1
- package/dist/attributes/observe-attribute.cjs.map +1 -1
- package/dist/attributes/observe-attribute.d.cts +2 -2
- package/dist/attributes/observe-attribute.d.cts.map +1 -1
- package/dist/attributes/observe-attribute.d.mts +2 -2
- package/dist/attributes/observe-attribute.d.mts.map +1 -1
- package/dist/attributes/observe-attribute.mjs +1 -1
- package/dist/attributes/observe-attribute.mjs.map +1 -1
- package/dist/attributes/observe-data-attribute.cjs +1 -1
- package/dist/attributes/observe-data-attribute.cjs.map +1 -1
- package/dist/attributes/observe-data-attribute.d.cts +2 -2
- package/dist/attributes/observe-data-attribute.d.cts.map +1 -1
- package/dist/attributes/observe-data-attribute.d.mts +2 -2
- package/dist/attributes/observe-data-attribute.d.mts.map +1 -1
- package/dist/attributes/observe-data-attribute.mjs +1 -1
- package/dist/attributes/observe-data-attribute.mjs.map +1 -1
- package/dist/color-scheme/color-scheme.types.d.cts +11 -0
- package/dist/color-scheme/color-scheme.types.d.cts.map +1 -0
- package/dist/color-scheme/color-scheme.types.d.mts +11 -0
- package/dist/color-scheme/color-scheme.types.d.mts.map +1 -0
- package/dist/color-scheme/get-prefers-color-scheme.cjs +3 -1
- package/dist/color-scheme/get-prefers-color-scheme.cjs.map +1 -1
- package/dist/color-scheme/get-prefers-color-scheme.d.cts +7 -2
- package/dist/color-scheme/get-prefers-color-scheme.d.cts.map +1 -1
- package/dist/color-scheme/get-prefers-color-scheme.d.mts +7 -2
- package/dist/color-scheme/get-prefers-color-scheme.d.mts.map +1 -1
- package/dist/color-scheme/get-prefers-color-scheme.mjs +3 -1
- package/dist/color-scheme/get-prefers-color-scheme.mjs.map +1 -1
- package/dist/color-scheme/observe-prefers-color-scheme.cjs.map +1 -1
- package/dist/color-scheme/observe-prefers-color-scheme.d.cts +4 -1
- package/dist/color-scheme/observe-prefers-color-scheme.d.cts.map +1 -1
- package/dist/color-scheme/observe-prefers-color-scheme.d.mts +4 -1
- package/dist/color-scheme/observe-prefers-color-scheme.d.mts.map +1 -1
- package/dist/color-scheme/observe-prefers-color-scheme.mjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.mts +2 -1
- package/dist/react/hooks/use-attribute.cjs +7 -7
- package/dist/react/hooks/use-attribute.cjs.map +1 -1
- package/dist/react/hooks/use-attribute.d.cts +4 -4
- package/dist/react/hooks/use-attribute.d.mts +4 -4
- package/dist/react/hooks/use-attribute.mjs +7 -7
- package/dist/react/hooks/use-attribute.mjs.map +1 -1
- package/dist/react/hooks/use-theme-by-class-name.cjs +2 -6
- package/dist/react/hooks/use-theme-by-class-name.cjs.map +1 -1
- package/dist/react/hooks/use-theme-by-class-name.d.cts +2 -2
- 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 +2 -2
- package/dist/react/hooks/use-theme-by-class-name.d.mts.map +1 -1
- package/dist/react/hooks/use-theme-by-class-name.mjs +2 -6
- package/dist/react/hooks/use-theme-by-class-name.mjs.map +1 -1
- package/dist/react/hooks/use-theme-by-data-attribute.cjs +2 -7
- package/dist/react/hooks/use-theme-by-data-attribute.cjs.map +1 -1
- package/dist/react/hooks/use-theme-by-data-attribute.d.cts +2 -2
- 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 +2 -2
- package/dist/react/hooks/use-theme-by-data-attribute.d.mts.map +1 -1
- package/dist/react/hooks/use-theme-by-data-attribute.mjs +2 -7
- 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/react/theme/create-theme-hook.cjs.map +1 -1
- package/dist/react/theme/create-theme-hook.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/_utils/set-theme-to-stores.cjs +1 -1
- package/dist/theme/_utils/set-theme-to-stores.cjs.map +1 -1
- package/dist/theme/_utils/set-theme-to-stores.mjs +1 -1
- package/dist/theme/_utils/set-theme-to-stores.mjs.map +1 -1
- 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/compose-theme-stores.cjs.map +1 -1
- package/dist/theme/compose-theme-stores.mjs.map +1 -1
- 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 +13 -1
- package/dist/theme/theme-entry.types.d.cts.map +1 -1
- package/dist/theme/theme-entry.types.d.mts +13 -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/async-theme-store.types.d.cts +1 -1
- package/dist/theme/theme-store/async-theme-store.types.d.cts.map +1 -1
- package/dist/theme/theme-store/async-theme-store.types.d.mts +1 -1
- package/dist/theme/theme-store/async-theme-store.types.d.mts.map +1 -1
- package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.cjs +22 -19
- 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 +7 -2
- 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 +7 -2
- 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 +22 -19
- 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 +40 -20
- 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 +30 -7
- 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 +30 -7
- 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 +40 -20
- package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.mjs.map +1 -1
- package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.cjs +1 -1
- package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.cjs.map +1 -1
- package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.d.cts +1 -1
- package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.d.mts +1 -1
- package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.mjs +1 -1
- package/dist/theme/theme-store/in-memory-theme-store/in-memory-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 +8 -2
- 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 +8 -2
- 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 +8 -2
- 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 +8 -2
- 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/theme-store/theme-store.types.d.cts +1 -1
- package/dist/theme/theme-store/theme-store.types.d.cts.map +1 -1
- package/dist/theme/theme-store/theme-store.types.d.mts +1 -1
- package/dist/theme/theme-store/theme-store.types.d.mts.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/dist/utils/append-id.cjs +2 -2
- package/dist/utils/append-id.cjs.map +1 -1
- package/dist/utils/append-id.d.cts +3 -3
- package/dist/utils/append-id.d.mts +3 -3
- package/dist/utils/append-id.mjs +2 -2
- package/dist/utils/append-id.mjs.map +1 -1
- package/package.json +1 -1
- package/src/attributes/get-attribute.ts +5 -2
- package/src/attributes/get-data-attribute.ts +5 -2
- package/src/attributes/observe-attribute.ts +2 -2
- package/src/attributes/observe-data-attribute.ts +2 -2
- package/src/color-scheme/color-scheme.types.ts +7 -0
- package/src/color-scheme/get-prefers-color-scheme.ts +6 -4
- package/src/color-scheme/observe-prefers-color-scheme.ts +3 -1
- package/src/index.ts +1 -0
- package/src/react/hooks/use-attribute.ts +11 -11
- package/src/react/hooks/use-theme-by-class-name.ts +5 -10
- package/src/react/hooks/use-theme-by-data-attribute.ts +5 -12
- package/src/react/hooks/use-theme-by-local-storage.ts +3 -9
- package/src/react/theme/create-theme-hook.ts +4 -6
- 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 +51 -11
- package/src/theme/_utils/resolve-theme-map-value.ts +15 -0
- package/src/theme/_utils/set-theme-to-stores.ts +3 -3
- 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/compose-theme-stores.ts +1 -1
- 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 +21 -0
- package/src/theme/theme-map.types.ts +9 -2
- package/src/theme/theme-store/async-theme-store.types.ts +1 -3
- package/src/theme/theme-store/class-name-theme-store/class-name-theme-store.ts +20 -26
- 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 +42 -29
- package/src/theme/theme-store/in-memory-theme-store/in-memory-theme-store.ts +1 -1
- 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/theme-store/theme-store.types.ts +1 -3
- 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/src/utils/append-id.ts +3 -3
- 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
|
@@ -8,30 +8,30 @@ let react = require("react");
|
|
|
8
8
|
* and a setter to update it. Stays in sync when the attribute changes (e.g. from elsewhere).
|
|
9
9
|
*
|
|
10
10
|
* @param attributeName - The attribute to observe (e.g. `'class'`, `'data-theme'`).
|
|
11
|
-
* @param element - The element to observe. Defaults to `document.documentElement` when omitted.
|
|
12
|
-
* @returns Tuple of [value, setValue]. Pass null to setValue to remove the attribute.
|
|
11
|
+
* @param element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement` when omitted.
|
|
12
|
+
* @returns Tuple of [value, setValue]. Pass null or undefined to setValue to remove the attribute.
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* ```tsx
|
|
16
16
|
* const [className, setClassName] = useAttribute('class')
|
|
17
17
|
* const [theme, setTheme] = useAttribute('data-theme', myElement)
|
|
18
18
|
* setTheme('dark')
|
|
19
|
-
* setClassName(
|
|
19
|
+
* setClassName(undefined) // removes class attribute
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
22
|
function useAttribute(attributeName, element = typeof document !== "undefined" ? document.documentElement : void 0) {
|
|
23
|
-
const [value, setValueState] = (0, react.useState)(() => element?.getAttribute(attributeName) ??
|
|
23
|
+
const [value, setValueState] = (0, react.useState)(() => element?.getAttribute(attributeName) ?? void 0);
|
|
24
24
|
(0, react.useEffect)(() => {
|
|
25
25
|
if (!element) return;
|
|
26
|
-
setValueState(element.getAttribute(attributeName));
|
|
26
|
+
setValueState(element.getAttribute(attributeName) ?? void 0);
|
|
27
27
|
const observer = require_observe_attribute.observeAttributes({ [attributeName]: (next) => {
|
|
28
|
-
setValueState(next);
|
|
28
|
+
setValueState(next ?? void 0);
|
|
29
29
|
} }, element);
|
|
30
30
|
return () => observer.disconnect();
|
|
31
31
|
}, [element, attributeName]);
|
|
32
32
|
return [value, (0, react.useCallback)((next) => {
|
|
33
33
|
if (!element) return;
|
|
34
|
-
if (next
|
|
34
|
+
if (next == null) element.removeAttribute(attributeName);
|
|
35
35
|
else element.setAttribute(attributeName, next);
|
|
36
36
|
}, [element, attributeName])];
|
|
37
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-attribute.cjs","names":["observeAttributes"],"sources":["../../../src/react/hooks/use-attribute.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from 'react'\nimport { observeAttributes } from '../../attributes/observe-attribute.ts'\n\n/**\n * React hook that returns the current value of an attribute on a target element\n * and a setter to update it. Stays in sync when the attribute changes (e.g. from elsewhere).\n *\n * @param attributeName - The attribute to observe (e.g. `'class'`, `'data-theme'`).\n * @param element - The element to observe. Defaults to `document.documentElement` when omitted.\n * @returns Tuple of [value, setValue]. Pass null to setValue to remove the attribute.\n *\n * @example\n * ```tsx\n * const [className, setClassName] = useAttribute('class')\n * const [theme, setTheme] = useAttribute('data-theme', myElement)\n * setTheme('dark')\n * setClassName(
|
|
1
|
+
{"version":3,"file":"use-attribute.cjs","names":["observeAttributes"],"sources":["../../../src/react/hooks/use-attribute.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from 'react'\nimport { observeAttributes } from '../../attributes/observe-attribute.ts'\n\n/**\n * React hook that returns the current value of an attribute on a target element\n * and a setter to update it. Stays in sync when the attribute changes (e.g. from elsewhere).\n *\n * @param attributeName - The attribute to observe (e.g. `'class'`, `'data-theme'`).\n * @param element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement` when omitted.\n * @returns Tuple of [value, setValue]. Pass null or undefined to setValue to remove the attribute.\n *\n * @example\n * ```tsx\n * const [className, setClassName] = useAttribute('class')\n * const [theme, setTheme] = useAttribute('data-theme', myElement)\n * setTheme('dark')\n * setClassName(undefined) // removes class attribute\n * ```\n */\nexport function useAttribute(\n\tattributeName: string,\n\telement: Element | null | undefined = typeof document !== 'undefined'\n\t\t? document.documentElement\n\t\t: undefined\n): [string | undefined, (value: string | null | undefined) => void] {\n\tconst [value, setValueState] = useState<string | undefined>(\n\t\t() => element?.getAttribute(attributeName) ?? undefined\n\t)\n\n\tuseEffect(() => {\n\t\tif (!element) return\n\n\t\tsetValueState(element.getAttribute(attributeName) ?? undefined)\n\n\t\tconst observer = observeAttributes(\n\t\t\t{\n\t\t\t\t[attributeName]: (next) => {\n\t\t\t\t\tsetValueState(next ?? undefined)\n\t\t\t\t}\n\t\t\t},\n\t\t\telement\n\t\t)\n\t\treturn () => observer.disconnect()\n\t}, [element, attributeName])\n\n\tconst setValue = useCallback(\n\t\t(next: string | null | undefined) => {\n\t\t\tif (!element) return\n\t\t\tif (next == null) {\n\t\t\t\telement.removeAttribute(attributeName)\n\t\t\t} else {\n\t\t\t\telement.setAttribute(attributeName, next)\n\t\t\t}\n\t\t},\n\t\t[element, attributeName]\n\t)\n\n\treturn [value, setValue]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,aACf,eACA,UAAsC,OAAO,aAAa,cACvD,SAAS,kBACT,QACgE;CACnE,MAAM,CAAC,OAAO,2CACP,SAAS,aAAa,cAAc,IAAI,OAC9C;AAED,4BAAgB;AACf,MAAI,CAAC,QAAS;AAEd,gBAAc,QAAQ,aAAa,cAAc,IAAI,OAAU;EAE/D,MAAM,WAAWA,4CAChB,GACE,iBAAiB,SAAS;AAC1B,iBAAc,QAAQ,OAAU;KAEjC,EACD,QACA;AACD,eAAa,SAAS,YAAY;IAChC,CAAC,SAAS,cAAc,CAAC;AAc5B,QAAO,CAAC,+BAXN,SAAoC;AACpC,MAAI,CAAC,QAAS;AACd,MAAI,QAAQ,KACX,SAAQ,gBAAgB,cAAc;MAEtC,SAAQ,aAAa,eAAe,KAAK;IAG3C,CAAC,SAAS,cAAc,CACxB,CAEuB"}
|
|
@@ -4,18 +4,18 @@
|
|
|
4
4
|
* and a setter to update it. Stays in sync when the attribute changes (e.g. from elsewhere).
|
|
5
5
|
*
|
|
6
6
|
* @param attributeName - The attribute to observe (e.g. `'class'`, `'data-theme'`).
|
|
7
|
-
* @param element - The element to observe. Defaults to `document.documentElement` when omitted.
|
|
8
|
-
* @returns Tuple of [value, setValue]. Pass null to setValue to remove the attribute.
|
|
7
|
+
* @param element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement` when omitted.
|
|
8
|
+
* @returns Tuple of [value, setValue]. Pass null or undefined to setValue to remove the attribute.
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* ```tsx
|
|
12
12
|
* const [className, setClassName] = useAttribute('class')
|
|
13
13
|
* const [theme, setTheme] = useAttribute('data-theme', myElement)
|
|
14
14
|
* setTheme('dark')
|
|
15
|
-
* setClassName(
|
|
15
|
+
* setClassName(undefined) // removes class attribute
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
|
-
declare function useAttribute(attributeName: string, element?: Element | undefined): [string |
|
|
18
|
+
declare function useAttribute(attributeName: string, element?: Element | null | undefined): [string | undefined, (value: string | null | undefined) => void];
|
|
19
19
|
//#endregion
|
|
20
20
|
export { useAttribute };
|
|
21
21
|
//# sourceMappingURL=use-attribute.d.cts.map
|
|
@@ -4,18 +4,18 @@
|
|
|
4
4
|
* and a setter to update it. Stays in sync when the attribute changes (e.g. from elsewhere).
|
|
5
5
|
*
|
|
6
6
|
* @param attributeName - The attribute to observe (e.g. `'class'`, `'data-theme'`).
|
|
7
|
-
* @param element - The element to observe. Defaults to `document.documentElement` when omitted.
|
|
8
|
-
* @returns Tuple of [value, setValue]. Pass null to setValue to remove the attribute.
|
|
7
|
+
* @param element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement` when omitted.
|
|
8
|
+
* @returns Tuple of [value, setValue]. Pass null or undefined to setValue to remove the attribute.
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* ```tsx
|
|
12
12
|
* const [className, setClassName] = useAttribute('class')
|
|
13
13
|
* const [theme, setTheme] = useAttribute('data-theme', myElement)
|
|
14
14
|
* setTheme('dark')
|
|
15
|
-
* setClassName(
|
|
15
|
+
* setClassName(undefined) // removes class attribute
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
|
-
declare function useAttribute(attributeName: string, element?: Element | undefined): [string |
|
|
18
|
+
declare function useAttribute(attributeName: string, element?: Element | null | undefined): [string | undefined, (value: string | null | undefined) => void];
|
|
19
19
|
//#endregion
|
|
20
20
|
export { useAttribute };
|
|
21
21
|
//# sourceMappingURL=use-attribute.d.mts.map
|
|
@@ -7,30 +7,30 @@ import { useCallback, useEffect, useState } from "react";
|
|
|
7
7
|
* and a setter to update it. Stays in sync when the attribute changes (e.g. from elsewhere).
|
|
8
8
|
*
|
|
9
9
|
* @param attributeName - The attribute to observe (e.g. `'class'`, `'data-theme'`).
|
|
10
|
-
* @param element - The element to observe. Defaults to `document.documentElement` when omitted.
|
|
11
|
-
* @returns Tuple of [value, setValue]. Pass null to setValue to remove the attribute.
|
|
10
|
+
* @param element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement` when omitted.
|
|
11
|
+
* @returns Tuple of [value, setValue]. Pass null or undefined to setValue to remove the attribute.
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
14
|
* ```tsx
|
|
15
15
|
* const [className, setClassName] = useAttribute('class')
|
|
16
16
|
* const [theme, setTheme] = useAttribute('data-theme', myElement)
|
|
17
17
|
* setTheme('dark')
|
|
18
|
-
* setClassName(
|
|
18
|
+
* setClassName(undefined) // removes class attribute
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
21
21
|
function useAttribute(attributeName, element = typeof document !== "undefined" ? document.documentElement : void 0) {
|
|
22
|
-
const [value, setValueState] = useState(() => element?.getAttribute(attributeName) ??
|
|
22
|
+
const [value, setValueState] = useState(() => element?.getAttribute(attributeName) ?? void 0);
|
|
23
23
|
useEffect(() => {
|
|
24
24
|
if (!element) return;
|
|
25
|
-
setValueState(element.getAttribute(attributeName));
|
|
25
|
+
setValueState(element.getAttribute(attributeName) ?? void 0);
|
|
26
26
|
const observer = observeAttributes({ [attributeName]: (next) => {
|
|
27
|
-
setValueState(next);
|
|
27
|
+
setValueState(next ?? void 0);
|
|
28
28
|
} }, element);
|
|
29
29
|
return () => observer.disconnect();
|
|
30
30
|
}, [element, attributeName]);
|
|
31
31
|
return [value, useCallback((next) => {
|
|
32
32
|
if (!element) return;
|
|
33
|
-
if (next
|
|
33
|
+
if (next == null) element.removeAttribute(attributeName);
|
|
34
34
|
else element.setAttribute(attributeName, next);
|
|
35
35
|
}, [element, attributeName])];
|
|
36
36
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-attribute.mjs","names":[],"sources":["../../../src/react/hooks/use-attribute.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from 'react'\nimport { observeAttributes } from '../../attributes/observe-attribute.ts'\n\n/**\n * React hook that returns the current value of an attribute on a target element\n * and a setter to update it. Stays in sync when the attribute changes (e.g. from elsewhere).\n *\n * @param attributeName - The attribute to observe (e.g. `'class'`, `'data-theme'`).\n * @param element - The element to observe. Defaults to `document.documentElement` when omitted.\n * @returns Tuple of [value, setValue]. Pass null to setValue to remove the attribute.\n *\n * @example\n * ```tsx\n * const [className, setClassName] = useAttribute('class')\n * const [theme, setTheme] = useAttribute('data-theme', myElement)\n * setTheme('dark')\n * setClassName(
|
|
1
|
+
{"version":3,"file":"use-attribute.mjs","names":[],"sources":["../../../src/react/hooks/use-attribute.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from 'react'\nimport { observeAttributes } from '../../attributes/observe-attribute.ts'\n\n/**\n * React hook that returns the current value of an attribute on a target element\n * and a setter to update it. Stays in sync when the attribute changes (e.g. from elsewhere).\n *\n * @param attributeName - The attribute to observe (e.g. `'class'`, `'data-theme'`).\n * @param element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement` when omitted.\n * @returns Tuple of [value, setValue]. Pass null or undefined to setValue to remove the attribute.\n *\n * @example\n * ```tsx\n * const [className, setClassName] = useAttribute('class')\n * const [theme, setTheme] = useAttribute('data-theme', myElement)\n * setTheme('dark')\n * setClassName(undefined) // removes class attribute\n * ```\n */\nexport function useAttribute(\n\tattributeName: string,\n\telement: Element | null | undefined = typeof document !== 'undefined'\n\t\t? document.documentElement\n\t\t: undefined\n): [string | undefined, (value: string | null | undefined) => void] {\n\tconst [value, setValueState] = useState<string | undefined>(\n\t\t() => element?.getAttribute(attributeName) ?? undefined\n\t)\n\n\tuseEffect(() => {\n\t\tif (!element) return\n\n\t\tsetValueState(element.getAttribute(attributeName) ?? undefined)\n\n\t\tconst observer = observeAttributes(\n\t\t\t{\n\t\t\t\t[attributeName]: (next) => {\n\t\t\t\t\tsetValueState(next ?? undefined)\n\t\t\t\t}\n\t\t\t},\n\t\t\telement\n\t\t)\n\t\treturn () => observer.disconnect()\n\t}, [element, attributeName])\n\n\tconst setValue = useCallback(\n\t\t(next: string | null | undefined) => {\n\t\t\tif (!element) return\n\t\t\tif (next == null) {\n\t\t\t\telement.removeAttribute(attributeName)\n\t\t\t} else {\n\t\t\t\telement.setAttribute(attributeName, next)\n\t\t\t}\n\t\t},\n\t\t[element, attributeName]\n\t)\n\n\treturn [value, setValue]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,aACf,eACA,UAAsC,OAAO,aAAa,cACvD,SAAS,kBACT,QACgE;CACnE,MAAM,CAAC,OAAO,iBAAiB,eACxB,SAAS,aAAa,cAAc,IAAI,OAC9C;AAED,iBAAgB;AACf,MAAI,CAAC,QAAS;AAEd,gBAAc,QAAQ,aAAa,cAAc,IAAI,OAAU;EAE/D,MAAM,WAAW,kBAChB,GACE,iBAAiB,SAAS;AAC1B,iBAAc,QAAQ,OAAU;KAEjC,EACD,QACA;AACD,eAAa,SAAS,YAAY;IAChC,CAAC,SAAS,cAAc,CAAC;AAc5B,QAAO,CAAC,OAZS,aACf,SAAoC;AACpC,MAAI,CAAC,QAAS;AACd,MAAI,QAAQ,KACX,SAAQ,gBAAgB,cAAc;MAEtC,SAAQ,aAAa,eAAe,KAAK;IAG3C,CAAC,SAAS,cAAc,CACxB,CAEuB"}
|
|
@@ -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");
|
|
@@ -13,7 +12,7 @@ let react = require("react");
|
|
|
13
12
|
*
|
|
14
13
|
* @param themes - Record mapping theme keys to their class name values
|
|
15
14
|
* @param options.theme - Fallback theme key when no matching class is found
|
|
16
|
-
* @param options.element - Element to read/set theme on (
|
|
15
|
+
* @param options.element - Element to read/set theme on (accepts null e.g. from refs). Defaults to document.documentElement.
|
|
17
16
|
* @returns Tuple of [currentTheme, setTheme]
|
|
18
17
|
*
|
|
19
18
|
* @example
|
|
@@ -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 (accepts null e.g. from refs). 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 | null | 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"}
|
|
@@ -8,7 +8,7 @@ import { ThemeMap } from "../../theme/theme-map.types.cjs";
|
|
|
8
8
|
*
|
|
9
9
|
* @param themes - Record mapping theme keys to their class name values
|
|
10
10
|
* @param options.theme - Fallback theme key when no matching class is found
|
|
11
|
-
* @param options.element - Element to read/set theme on (
|
|
11
|
+
* @param options.element - Element to read/set theme on (accepts null e.g. from refs). Defaults to document.documentElement.
|
|
12
12
|
* @returns Tuple of [currentTheme, setTheme]
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
@@ -27,7 +27,7 @@ import { ThemeMap } from "../../theme/theme-map.types.cjs";
|
|
|
27
27
|
*/
|
|
28
28
|
declare function useThemeByClassName<Themes extends ThemeMap>(themes: Themes, options?: {
|
|
29
29
|
defaultTheme?: keyof Themes | undefined;
|
|
30
|
-
element?: Element | undefined;
|
|
30
|
+
element?: Element | null | undefined;
|
|
31
31
|
}): [keyof Themes | undefined, (theme: keyof Themes) => void];
|
|
32
32
|
//#endregion
|
|
33
33
|
export { useThemeByClassName };
|
|
@@ -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"}
|
|
@@ -8,7 +8,7 @@ import { ThemeMap } from "../../theme/theme-map.types.mjs";
|
|
|
8
8
|
*
|
|
9
9
|
* @param themes - Record mapping theme keys to their class name values
|
|
10
10
|
* @param options.theme - Fallback theme key when no matching class is found
|
|
11
|
-
* @param options.element - Element to read/set theme on (
|
|
11
|
+
* @param options.element - Element to read/set theme on (accepts null e.g. from refs). Defaults to document.documentElement.
|
|
12
12
|
* @returns Tuple of [currentTheme, setTheme]
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
@@ -27,7 +27,7 @@ import { ThemeMap } from "../../theme/theme-map.types.mjs";
|
|
|
27
27
|
*/
|
|
28
28
|
declare function useThemeByClassName<Themes extends ThemeMap>(themes: Themes, options?: {
|
|
29
29
|
defaultTheme?: keyof Themes | undefined;
|
|
30
|
-
element?: Element | undefined;
|
|
30
|
+
element?: Element | null | undefined;
|
|
31
31
|
}): [keyof Themes | undefined, (theme: keyof Themes) => void];
|
|
32
32
|
//#endregion
|
|
33
33
|
export { useThemeByClassName };
|
|
@@ -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";
|
|
@@ -12,7 +11,7 @@ import { useCallback, useEffect, useMemo, useState } from "react";
|
|
|
12
11
|
*
|
|
13
12
|
* @param themes - Record mapping theme keys to their class name values
|
|
14
13
|
* @param options.theme - Fallback theme key when no matching class is found
|
|
15
|
-
* @param options.element - Element to read/set theme on (
|
|
14
|
+
* @param options.element - Element to read/set theme on (accepts null e.g. from refs). Defaults to document.documentElement.
|
|
16
15
|
* @returns Tuple of [currentTheme, setTheme]
|
|
17
16
|
*
|
|
18
17
|
* @example
|
|
@@ -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 (accepts null e.g. from refs). 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 | null | 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
|
|
|
@@ -15,7 +13,7 @@ let react = require("react");
|
|
|
15
13
|
* @param themes - Record mapping theme keys to their data attribute values
|
|
16
14
|
* @param options.attributeName - Data attribute name (e.g. `data-theme`)
|
|
17
15
|
* @param options.defaultTheme - Fallback theme key when no matching attribute value is found
|
|
18
|
-
* @param options.element - Element to read/set theme on (
|
|
16
|
+
* @param options.element - Element to read/set theme on (accepts null e.g. from refs). Defaults to document.documentElement.
|
|
19
17
|
* @returns Tuple of [currentTheme, setTheme]
|
|
20
18
|
*
|
|
21
19
|
* @example
|
|
@@ -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 (accepts null e.g. from refs). 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 | null | 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"}
|
|
@@ -9,7 +9,7 @@ import { ThemeMap } from "../../theme/theme-map.types.cjs";
|
|
|
9
9
|
* @param themes - Record mapping theme keys to their data attribute values
|
|
10
10
|
* @param options.attributeName - Data attribute name (e.g. `data-theme`)
|
|
11
11
|
* @param options.defaultTheme - Fallback theme key when no matching attribute value is found
|
|
12
|
-
* @param options.element - Element to read/set theme on (
|
|
12
|
+
* @param options.element - Element to read/set theme on (accepts null e.g. from refs). Defaults to document.documentElement.
|
|
13
13
|
* @returns Tuple of [currentTheme, setTheme]
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
@@ -32,7 +32,7 @@ import { ThemeMap } from "../../theme/theme-map.types.cjs";
|
|
|
32
32
|
declare function useThemeByDataAttribute<Themes extends ThemeMap>(themes: Themes, options: {
|
|
33
33
|
attributeName: `data-${string}`;
|
|
34
34
|
defaultTheme?: keyof Themes | undefined;
|
|
35
|
-
element?: Element | undefined;
|
|
35
|
+
element?: Element | null | undefined;
|
|
36
36
|
}): [keyof Themes | undefined, (theme: keyof Themes) => void];
|
|
37
37
|
//#endregion
|
|
38
38
|
export { useThemeByDataAttribute };
|
|
@@ -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"}
|
|
@@ -9,7 +9,7 @@ import { ThemeMap } from "../../theme/theme-map.types.mjs";
|
|
|
9
9
|
* @param themes - Record mapping theme keys to their data attribute values
|
|
10
10
|
* @param options.attributeName - Data attribute name (e.g. `data-theme`)
|
|
11
11
|
* @param options.defaultTheme - Fallback theme key when no matching attribute value is found
|
|
12
|
-
* @param options.element - Element to read/set theme on (
|
|
12
|
+
* @param options.element - Element to read/set theme on (accepts null e.g. from refs). Defaults to document.documentElement.
|
|
13
13
|
* @returns Tuple of [currentTheme, setTheme]
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
@@ -32,7 +32,7 @@ import { ThemeMap } from "../../theme/theme-map.types.mjs";
|
|
|
32
32
|
declare function useThemeByDataAttribute<Themes extends ThemeMap>(themes: Themes, options: {
|
|
33
33
|
attributeName: `data-${string}`;
|
|
34
34
|
defaultTheme?: keyof Themes | undefined;
|
|
35
|
-
element?: Element | undefined;
|
|
35
|
+
element?: Element | null | undefined;
|
|
36
36
|
}): [keyof Themes | undefined, (theme: keyof Themes) => void];
|
|
37
37
|
//#endregion
|
|
38
38
|
export { useThemeByDataAttribute };
|
|
@@ -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
|
|
|
@@ -14,7 +12,7 @@ import { useCallback, useEffect, useMemo, useState } from "react";
|
|
|
14
12
|
* @param themes - Record mapping theme keys to their data attribute values
|
|
15
13
|
* @param options.attributeName - Data attribute name (e.g. `data-theme`)
|
|
16
14
|
* @param options.defaultTheme - Fallback theme key when no matching attribute value is found
|
|
17
|
-
* @param options.element - Element to read/set theme on (
|
|
15
|
+
* @param options.element - Element to read/set theme on (accepts null e.g. from refs). Defaults to document.documentElement.
|
|
18
16
|
* @returns Tuple of [currentTheme, setTheme]
|
|
19
17
|
*
|
|
20
18
|
* @example
|
|
@@ -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 (accepts null e.g. from refs). 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 | null | 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"}
|