@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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ThemeMap } from "../../theme-map.types.cjs";
|
|
2
|
+
import { ParseStoredTheme, StringifyStoredTheme } from "../../theme-entry.types.cjs";
|
|
2
3
|
import { ThemeStore } from "../theme-store.types.cjs";
|
|
3
4
|
import { Required } from "type-plus";
|
|
4
5
|
|
|
@@ -8,7 +9,9 @@ import { Required } from "type-plus";
|
|
|
8
9
|
* Creates a theme store that reads and writes via element class names.
|
|
9
10
|
*
|
|
10
11
|
* @param themes - Record mapping theme keys to class name(s)
|
|
11
|
-
* @param options.element - Element to operate on (
|
|
12
|
+
* @param options.element - Element to operate on (accepts null e.g. from refs). Defaults to document.documentElement.
|
|
13
|
+
* @param options.parse - Custom parser (default: parseClassName)
|
|
14
|
+
* @param options.stringify - Custom serializer (default: stringifyClassName)
|
|
12
15
|
* @returns ThemeStore
|
|
13
16
|
*
|
|
14
17
|
* @example
|
|
@@ -21,7 +24,9 @@ import { Required } from "type-plus";
|
|
|
21
24
|
* ```
|
|
22
25
|
*/
|
|
23
26
|
declare function classNameThemeStore<Themes extends ThemeMap>(themes: Themes, options?: {
|
|
24
|
-
element?: Element | undefined;
|
|
27
|
+
element?: Element | null | undefined;
|
|
28
|
+
parse?: ParseStoredTheme<Themes> | undefined;
|
|
29
|
+
stringify?: StringifyStoredTheme<Themes> | undefined;
|
|
25
30
|
}): Required<ThemeStore<Themes>>;
|
|
26
31
|
//#endregion
|
|
27
32
|
export { classNameThemeStore };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"class-name-theme-store.d.cts","names":[],"sources":["../../../../src/theme/theme-store/class-name-theme-store/class-name-theme-store.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"class-name-theme-store.d.cts","names":[],"sources":["../../../../src/theme/theme-store/class-name-theme-store/class-name-theme-store.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AA6BA;;;;;;;;;;;;;;;;iBAAgB,mCAAmC,kBAC1C;YAEG;UACF,iBAAiB;cACb,qBAAqB;IAEhC,SAAS,WAAW"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ThemeMap } from "../../theme-map.types.mjs";
|
|
2
|
+
import { ParseStoredTheme, StringifyStoredTheme } from "../../theme-entry.types.mjs";
|
|
2
3
|
import { ThemeStore } from "../theme-store.types.mjs";
|
|
3
4
|
import { Required } from "type-plus";
|
|
4
5
|
|
|
@@ -8,7 +9,9 @@ import { Required } from "type-plus";
|
|
|
8
9
|
* Creates a theme store that reads and writes via element class names.
|
|
9
10
|
*
|
|
10
11
|
* @param themes - Record mapping theme keys to class name(s)
|
|
11
|
-
* @param options.element - Element to operate on (
|
|
12
|
+
* @param options.element - Element to operate on (accepts null e.g. from refs). Defaults to document.documentElement.
|
|
13
|
+
* @param options.parse - Custom parser (default: parseClassName)
|
|
14
|
+
* @param options.stringify - Custom serializer (default: stringifyClassName)
|
|
12
15
|
* @returns ThemeStore
|
|
13
16
|
*
|
|
14
17
|
* @example
|
|
@@ -21,7 +24,9 @@ import { Required } from "type-plus";
|
|
|
21
24
|
* ```
|
|
22
25
|
*/
|
|
23
26
|
declare function classNameThemeStore<Themes extends ThemeMap>(themes: Themes, options?: {
|
|
24
|
-
element?: Element | undefined;
|
|
27
|
+
element?: Element | null | undefined;
|
|
28
|
+
parse?: ParseStoredTheme<Themes> | undefined;
|
|
29
|
+
stringify?: StringifyStoredTheme<Themes> | undefined;
|
|
25
30
|
}): Required<ThemeStore<Themes>>;
|
|
26
31
|
//#endregion
|
|
27
32
|
export { classNameThemeStore };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"class-name-theme-store.d.mts","names":[],"sources":["../../../../src/theme/theme-store/class-name-theme-store/class-name-theme-store.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"class-name-theme-store.d.mts","names":[],"sources":["../../../../src/theme/theme-store/class-name-theme-store/class-name-theme-store.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AA6BA;;;;;;;;;;;;;;;;iBAAgB,mCAAmC,kBAC1C;YAEG;UACF,iBAAiB;cACb,qBAAqB;IAEhC,SAAS,WAAW"}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import { observeAttributes } from "../../../attributes/observe-attribute.mjs";
|
|
2
|
-
import { resolveThemeFromClassName } from "../../class-name/resolve-theme-from-class-name.mjs";
|
|
3
|
-
import { themeEntry } from "../../theme-entry.mjs";
|
|
4
1
|
import { dummyThemeStore } from "../../../testing/theme/dummy-theme-store.mjs";
|
|
5
|
-
import {
|
|
2
|
+
import { parseClassName } from "../../class-name/parse-class-name.mjs";
|
|
3
|
+
import { readClassName } from "../../class-name/read-class-name.mjs";
|
|
4
|
+
import { stringifyClassName } from "../../class-name/stringify-class-name.mjs";
|
|
5
|
+
import { subscribeClassName } from "../../class-name/subscribe-class-name.mjs";
|
|
6
|
+
import { writeClassName } from "../../class-name/write-class-name.mjs";
|
|
6
7
|
|
|
7
8
|
//#region src/theme/theme-store/class-name-theme-store/class-name-theme-store.ts
|
|
8
9
|
/**
|
|
9
10
|
* Creates a theme store that reads and writes via element class names.
|
|
10
11
|
*
|
|
11
12
|
* @param themes - Record mapping theme keys to class name(s)
|
|
12
|
-
* @param options.element - Element to operate on (
|
|
13
|
+
* @param options.element - Element to operate on (accepts null e.g. from refs). Defaults to document.documentElement.
|
|
14
|
+
* @param options.parse - Custom parser (default: parseClassName)
|
|
15
|
+
* @param options.stringify - Custom serializer (default: stringifyClassName)
|
|
13
16
|
* @returns ThemeStore
|
|
14
17
|
*
|
|
15
18
|
* @example
|
|
@@ -24,26 +27,26 @@ import { applyThemeToClassName } from "../../class-name/apply-theme-to-class-nam
|
|
|
24
27
|
function classNameThemeStore(themes, options) {
|
|
25
28
|
const element = options?.element ?? document?.documentElement;
|
|
26
29
|
if (!element) return dummyThemeStore;
|
|
30
|
+
const parse = options?.parse ?? parseClassName;
|
|
31
|
+
const stringify = options?.stringify ?? stringifyClassName;
|
|
27
32
|
return {
|
|
28
33
|
read() {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
return readClassName(themes, {
|
|
35
|
+
element,
|
|
36
|
+
parse
|
|
37
|
+
});
|
|
32
38
|
},
|
|
33
39
|
write(entry) {
|
|
34
|
-
|
|
40
|
+
writeClassName(themes, entry, {
|
|
41
|
+
element,
|
|
42
|
+
stringify
|
|
43
|
+
});
|
|
35
44
|
},
|
|
36
45
|
subscribe(handler) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const key = theme ?? void 0;
|
|
42
|
-
if (lastEmitted === key) return;
|
|
43
|
-
lastEmitted = key;
|
|
44
|
-
handler(entry);
|
|
45
|
-
} }, element);
|
|
46
|
-
return () => observer.disconnect();
|
|
46
|
+
return subscribeClassName(themes, handler, {
|
|
47
|
+
element,
|
|
48
|
+
parse
|
|
49
|
+
});
|
|
47
50
|
}
|
|
48
51
|
};
|
|
49
52
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"class-name-theme-store.mjs","names":[
|
|
1
|
+
{"version":3,"file":"class-name-theme-store.mjs","names":[],"sources":["../../../../src/theme/theme-store/class-name-theme-store/class-name-theme-store.ts"],"sourcesContent":["import type { Required } from 'type-plus'\nimport { dummyThemeStore } from '../../../testing/theme/dummy-theme-store.ts'\nimport { parseClassName } from '../../class-name/parse-class-name.ts'\nimport { readClassName } from '../../class-name/read-class-name.ts'\nimport { stringifyClassName } from '../../class-name/stringify-class-name.ts'\nimport { subscribeClassName } from '../../class-name/subscribe-class-name.ts'\nimport { writeClassName } from '../../class-name/write-class-name.ts'\nimport type { ParseStoredTheme, StringifyStoredTheme } from '../../theme-entry.types.ts'\nimport type { ThemeMap } from '../../theme-map.types.ts'\nimport type { ThemeStore } from '../theme-store.types.ts'\n\n/**\n * Creates a theme store that reads and writes via element class names.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param options.element - Element to operate on (accepts null e.g. from refs). Defaults to document.documentElement.\n * @param options.parse - Custom parser (default: parseClassName)\n * @param options.stringify - Custom serializer (default: stringifyClassName)\n * @returns ThemeStore\n *\n * @example\n * ```ts\n * const themes = { current: 'theme-current', grayscale: 'theme-grayscale' }\n * const store = classNameThemeStore(themes)\n * store.read() // returns themeResult from element.className\n * store.write(themeEntry(themes, 'grayscale'))\n * store.subscribe((themeResult) => {})\n * ```\n */\nexport function classNameThemeStore<Themes extends ThemeMap>(\n\tthemes: Themes,\n\toptions?: {\n\t\telement?: Element | null | undefined\n\t\tparse?: ParseStoredTheme<Themes> | undefined\n\t\tstringify?: StringifyStoredTheme<Themes> | undefined\n\t}\n): Required<ThemeStore<Themes>> {\n\tconst element = options?.element ?? document?.documentElement\n\n\tif (!element) return dummyThemeStore\n\n\tconst parse = options?.parse ?? parseClassName\n\tconst stringify = options?.stringify ?? stringifyClassName\n\n\treturn {\n\t\tread() {\n\t\t\treturn readClassName(themes, { element, parse })\n\t\t},\n\t\twrite(entry) {\n\t\t\twriteClassName(themes, entry, { element, stringify })\n\t\t},\n\t\tsubscribe(handler) {\n\t\t\treturn subscribeClassName(themes, handler, { element, parse })\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAgB,oBACf,QACA,SAK+B;CAC/B,MAAM,UAAU,SAAS,WAAW,UAAU;AAE9C,KAAI,CAAC,QAAS,QAAO;CAErB,MAAM,QAAQ,SAAS,SAAS;CAChC,MAAM,YAAY,SAAS,aAAa;AAExC,QAAO;EACN,OAAO;AACN,UAAO,cAAc,QAAQ;IAAE;IAAS;IAAO,CAAC;;EAEjD,MAAM,OAAO;AACZ,kBAAe,QAAQ,OAAO;IAAE;IAAS;IAAW,CAAC;;EAEtD,UAAU,SAAS;AAClB,UAAO,mBAAmB,QAAQ,SAAS;IAAE;IAAS;IAAO,CAAC;;EAE/D"}
|
|
@@ -1,24 +1,10 @@
|
|
|
1
|
-
const require_theme_entry = require('../../theme-entry.cjs');
|
|
2
1
|
const require_dummy_theme_store = require('../../../testing/theme/dummy-theme-store.cjs');
|
|
3
2
|
const require_parse_stored_theme = require('../../_utils/parse-stored-theme.cjs');
|
|
3
|
+
const require__cookie_utils = require('../../cookie/_cookie-utils.cjs');
|
|
4
|
+
const require_read_cookie_theme = require('../../cookie/read-cookie-theme.cjs');
|
|
5
|
+
const require_write_cookie_theme = require('../../cookie/write-cookie-theme.cjs');
|
|
4
6
|
|
|
5
7
|
//#region src/theme/theme-store/cookie-theme-store/cookie-theme-store.ts
|
|
6
|
-
function getCookieValue(name) {
|
|
7
|
-
if (typeof document === "undefined" || !document.cookie) return null;
|
|
8
|
-
const value = document.cookie.match(/* @__PURE__ */ new RegExp(`(?:^|;\\s*)${name}=([^;]*)`))?.[1];
|
|
9
|
-
return value !== void 0 ? decodeURIComponent(value) : null;
|
|
10
|
-
}
|
|
11
|
-
function setCookie(name, value, options) {
|
|
12
|
-
const parts = [`${name}=${encodeURIComponent(value)}`];
|
|
13
|
-
parts.push(`path=${options.path ?? "/"}`);
|
|
14
|
-
if (options.maxAge !== void 0) parts.push(`max-age=${options.maxAge}`);
|
|
15
|
-
if (options.sameSite !== void 0) parts.push(`samesite=${options.sameSite}`);
|
|
16
|
-
if (options.secure) parts.push("secure");
|
|
17
|
-
document.cookie = parts.join("; ");
|
|
18
|
-
}
|
|
19
|
-
function deleteCookie(name, path = "/") {
|
|
20
|
-
document.cookie = `${name}=; path=${path}; max-age=0`;
|
|
21
|
-
}
|
|
22
8
|
/**
|
|
23
9
|
* Creates a theme store backed by cookies.
|
|
24
10
|
*
|
|
@@ -32,6 +18,7 @@ function deleteCookie(name, path = "/") {
|
|
|
32
18
|
* @param options.maxAge - Cookie max-age in seconds
|
|
33
19
|
* @param options.sameSite - Cookie sameSite attribute
|
|
34
20
|
* @param options.secure - Cookie secure attribute
|
|
21
|
+
* @param options.parse - Optional custom parser for stored string (default: parseStoredTheme)
|
|
35
22
|
* @returns ThemeStore
|
|
36
23
|
*
|
|
37
24
|
* @example
|
|
@@ -44,14 +31,16 @@ function deleteCookie(name, path = "/") {
|
|
|
44
31
|
* ```
|
|
45
32
|
*/
|
|
46
33
|
function cookieThemeStore(themes, options) {
|
|
47
|
-
const { cookieName, path = "/", maxAge, sameSite, secure } = options;
|
|
34
|
+
const { cookieName, path = "/", maxAge, sameSite, secure, parse = require_parse_stored_theme.parseStoredTheme } = options;
|
|
48
35
|
if (document.cookie === void 0) return require_dummy_theme_store.dummyThemeStore;
|
|
49
36
|
const handlers = /* @__PURE__ */ new Set();
|
|
50
37
|
let lastNotifiedKey = read()?.theme ?? void 0;
|
|
51
38
|
function read() {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
39
|
+
return require_read_cookie_theme.readCookieTheme(themes, {
|
|
40
|
+
cookieName,
|
|
41
|
+
path,
|
|
42
|
+
parse
|
|
43
|
+
});
|
|
55
44
|
}
|
|
56
45
|
function notify() {
|
|
57
46
|
const result = read();
|
|
@@ -64,14 +53,13 @@ function cookieThemeStore(themes, options) {
|
|
|
64
53
|
read,
|
|
65
54
|
write(entry) {
|
|
66
55
|
try {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
56
|
+
require_write_cookie_theme.writeCookieTheme(themes, entry, {
|
|
57
|
+
cookieName,
|
|
58
|
+
path,
|
|
59
|
+
maxAge,
|
|
60
|
+
sameSite,
|
|
61
|
+
secure
|
|
62
|
+
});
|
|
75
63
|
notify();
|
|
76
64
|
} catch {}
|
|
77
65
|
},
|
|
@@ -83,10 +71,6 @@ function cookieThemeStore(themes, options) {
|
|
|
83
71
|
}
|
|
84
72
|
};
|
|
85
73
|
}
|
|
86
|
-
function getCookieFromHeader(cookieHeader, name) {
|
|
87
|
-
const value = cookieHeader.match(/* @__PURE__ */ new RegExp(`(?:^|;\\s*)${name}=([^;]*)`))?.[1];
|
|
88
|
-
return value !== void 0 ? decodeURIComponent(value.trim()) : null;
|
|
89
|
-
}
|
|
90
74
|
/**
|
|
91
75
|
* Reads the theme from cookies during SSR. Use with the request's Cookie header or
|
|
92
76
|
* a framework's cookie API (e.g. Next.js cookies()).
|
|
@@ -110,9 +94,7 @@ function getCookieFromHeader(cookieHeader, name) {
|
|
|
110
94
|
*/
|
|
111
95
|
function getThemeFromCookie(cookieSource, themes, options = {}) {
|
|
112
96
|
const cookieName = options.cookieName ?? "theme";
|
|
113
|
-
|
|
114
|
-
if (theme === void 0) return void 0;
|
|
115
|
-
return require_theme_entry.themeEntry(themes, theme);
|
|
97
|
+
return require_parse_stored_theme.parseStoredTheme(themes, (typeof cookieSource === "function" ? cookieSource(cookieName) ?? null : cookieSource ? require__cookie_utils.getCookieFromHeader(cookieSource, cookieName) : null) ?? void 0);
|
|
116
98
|
}
|
|
117
99
|
|
|
118
100
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookie-theme-store.cjs","names":["dummyThemeStore","lastNotifiedKey: keyof Themes | undefined","
|
|
1
|
+
{"version":3,"file":"cookie-theme-store.cjs","names":["parseStoredTheme","dummyThemeStore","lastNotifiedKey: keyof Themes | undefined","readCookieTheme","getCookieFromHeader"],"sources":["../../../../src/theme/theme-store/cookie-theme-store/cookie-theme-store.ts"],"sourcesContent":["import type { Required } from 'type-plus'\nimport { dummyThemeStore } from '../../../testing/theme/dummy-theme-store.ts'\nimport { parseStoredTheme } from '../../_utils/parse-stored-theme.ts'\nimport { getCookieFromHeader } from '../../cookie/_cookie-utils.ts'\nimport { readCookieTheme } from '../../cookie/read-cookie-theme.ts'\nimport { writeCookieTheme } from '../../cookie/write-cookie-theme.ts'\nimport type { ParseStoredTheme, ThemeEntry } from '../../theme-entry.types.ts'\nimport type { ThemeMap } from '../../theme-map.types.ts'\nimport type { ThemeStore } from '../theme-store.types.ts'\n\nexport interface CookieThemeStoreOptions<Themes extends ThemeMap = ThemeMap> {\n\tcookieName: string\n\tpath?: string | undefined\n\tmaxAge?: number | undefined\n\tsameSite?: 'lax' | 'strict' | 'none' | undefined\n\tsecure?: boolean | undefined\n\tparse?: ParseStoredTheme<Themes> | undefined\n}\n\n/**\n * Creates a theme store backed by cookies.\n *\n * Persists across sessions. Cookies are sent with every request, so the server can\n * read the theme during SSR to avoid flash of wrong theme. Cross-tab sync is not\n * supported (cookies have no StorageEvent).\n *\n * @param themes - Record mapping theme keys to values (for validation)\n * @param options.cookieName - Cookie name for theme storage\n * @param options.path - Cookie path (default: '/')\n * @param options.maxAge - Cookie max-age in seconds\n * @param options.sameSite - Cookie sameSite attribute\n * @param options.secure - Cookie secure attribute\n * @param options.parse - Optional custom parser for stored string (default: parseStoredTheme)\n * @returns ThemeStore\n *\n * @example\n * ```ts\n * const themes = { current: 'theme-current', grayscale: 'theme-grayscale' }\n * const store = cookieThemeStore(themes, { cookieName: 'theme' })\n * store.read()\n * store.write(themeEntry(themes, 'grayscale'))\n * store.subscribe((themeResult) => {})\n * ```\n */\nexport function cookieThemeStore<Themes extends ThemeMap>(\n\tthemes: Themes,\n\toptions: CookieThemeStoreOptions<Themes>\n): Required<ThemeStore<Themes>> {\n\tconst { cookieName, path = '/', maxAge, sameSite, secure, parse = parseStoredTheme } = options\n\n\tif (document.cookie === undefined) {\n\t\treturn dummyThemeStore\n\t}\n\n\tconst handlers = new Set<(theme: ThemeEntry<Themes> | undefined) => void>()\n\tlet lastNotifiedKey: keyof Themes | undefined = read()?.theme ?? undefined\n\n\tfunction read() {\n\t\treturn readCookieTheme(themes, { cookieName, path, parse })\n\t}\n\n\tfunction notify() {\n\t\tconst result = read()\n\t\tconst key = result?.theme ?? undefined\n\t\tif (key === lastNotifiedKey) return\n\t\tlastNotifiedKey = key\n\t\tfor (const h of handlers) h(result)\n\t}\n\n\treturn {\n\t\tread,\n\t\twrite(entry) {\n\t\t\ttry {\n\t\t\t\twriteCookieTheme(themes, entry, {\n\t\t\t\t\tcookieName,\n\t\t\t\t\tpath,\n\t\t\t\t\tmaxAge,\n\t\t\t\t\tsameSite,\n\t\t\t\t\tsecure\n\t\t\t\t})\n\t\t\t\tnotify()\n\t\t\t} catch {\n\t\t\t\t// Ignore quota or other errors\n\t\t\t}\n\t\t},\n\t\tsubscribe(handler) {\n\t\t\thandlers.add(handler)\n\t\t\treturn () => {\n\t\t\t\thandlers.delete(handler)\n\t\t\t}\n\t\t}\n\t} satisfies ThemeStore<Themes>\n}\n\n/**\n * Reads the theme from cookies during SSR. Use with the request's Cookie header or\n * a framework's cookie API (e.g. Next.js cookies()).\n *\n * @param cookieSource - Raw Cookie header string, or a getter (name) => value for framework APIs\n * @param themes - Record mapping theme keys to values (for validation)\n * @param options - Optional cookie name (default: 'theme')\n * @returns ThemeEntry if valid cookie found, otherwise undefined\n *\n * @example\n * ```ts\n * // With raw Cookie header (Express, Remix, etc.)\n * const theme = getThemeFromCookie(request.headers.get('Cookie') ?? '', themes)\n *\n * // With Next.js cookies()\n * const theme = getThemeFromCookie(\n * (name) => cookies().get(name)?.value ?? undefined,\n * themes\n * )\n * ```\n */\nexport function getThemeFromCookie<Themes extends ThemeMap>(\n\tcookieSource: string | null | undefined | ((name: string) => string | null | undefined),\n\tthemes: Themes,\n\toptions: { cookieName?: string | undefined } = {}\n): ThemeEntry<Themes> | undefined {\n\tconst cookieName = options.cookieName ?? 'theme'\n\tconst stored =\n\t\ttypeof cookieSource === 'function'\n\t\t\t? (cookieSource(cookieName) ?? null)\n\t\t\t: cookieSource\n\t\t\t\t? getCookieFromHeader(cookieSource, cookieName)\n\t\t\t\t: null\n\treturn parseStoredTheme(themes, stored ?? undefined)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,SAAgB,iBACf,QACA,SAC+B;CAC/B,MAAM,EAAE,YAAY,OAAO,KAAK,QAAQ,UAAU,QAAQ,QAAQA,gDAAqB;AAEvF,KAAI,SAAS,WAAW,OACvB,QAAOC;CAGR,MAAM,2BAAW,IAAI,KAAsD;CAC3E,IAAIC,kBAA4C,MAAM,EAAE,SAAS;CAEjE,SAAS,OAAO;AACf,SAAOC,0CAAgB,QAAQ;GAAE;GAAY;GAAM;GAAO,CAAC;;CAG5D,SAAS,SAAS;EACjB,MAAM,SAAS,MAAM;EACrB,MAAM,MAAM,QAAQ,SAAS;AAC7B,MAAI,QAAQ,gBAAiB;AAC7B,oBAAkB;AAClB,OAAK,MAAM,KAAK,SAAU,GAAE,OAAO;;AAGpC,QAAO;EACN;EACA,MAAM,OAAO;AACZ,OAAI;AACH,gDAAiB,QAAQ,OAAO;KAC/B;KACA;KACA;KACA;KACA;KACA,CAAC;AACF,YAAQ;WACD;;EAIT,UAAU,SAAS;AAClB,YAAS,IAAI,QAAQ;AACrB,gBAAa;AACZ,aAAS,OAAO,QAAQ;;;EAG1B;;;;;;;;;;;;;;;;;;;;;;;AAwBF,SAAgB,mBACf,cACA,QACA,UAA+C,EAAE,EAChB;CACjC,MAAM,aAAa,QAAQ,cAAc;AAOzC,QAAOH,4CAAiB,SALvB,OAAO,iBAAiB,aACpB,aAAa,WAAW,IAAI,OAC7B,eACCI,0CAAoB,cAAc,WAAW,GAC7C,SACqC,OAAU"}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { ThemeMap } from "../../theme-map.types.cjs";
|
|
2
|
-
import { ThemeEntry } from "../../theme-entry.types.cjs";
|
|
2
|
+
import { ParseStoredTheme, ThemeEntry } from "../../theme-entry.types.cjs";
|
|
3
3
|
import { ThemeStore } from "../theme-store.types.cjs";
|
|
4
4
|
import { Required } from "type-plus";
|
|
5
5
|
|
|
6
6
|
//#region src/theme/theme-store/cookie-theme-store/cookie-theme-store.d.ts
|
|
7
|
-
interface CookieThemeStoreOptions {
|
|
7
|
+
interface CookieThemeStoreOptions<Themes extends ThemeMap = ThemeMap> {
|
|
8
8
|
cookieName: string;
|
|
9
9
|
path?: string | undefined;
|
|
10
10
|
maxAge?: number | undefined;
|
|
11
11
|
sameSite?: 'lax' | 'strict' | 'none' | undefined;
|
|
12
12
|
secure?: boolean | undefined;
|
|
13
|
+
parse?: ParseStoredTheme<Themes> | undefined;
|
|
13
14
|
}
|
|
14
15
|
/**
|
|
15
16
|
* Creates a theme store backed by cookies.
|
|
@@ -24,6 +25,7 @@ interface CookieThemeStoreOptions {
|
|
|
24
25
|
* @param options.maxAge - Cookie max-age in seconds
|
|
25
26
|
* @param options.sameSite - Cookie sameSite attribute
|
|
26
27
|
* @param options.secure - Cookie secure attribute
|
|
28
|
+
* @param options.parse - Optional custom parser for stored string (default: parseStoredTheme)
|
|
27
29
|
* @returns ThemeStore
|
|
28
30
|
*
|
|
29
31
|
* @example
|
|
@@ -35,7 +37,7 @@ interface CookieThemeStoreOptions {
|
|
|
35
37
|
* store.subscribe((themeResult) => {})
|
|
36
38
|
* ```
|
|
37
39
|
*/
|
|
38
|
-
declare function cookieThemeStore<Themes extends ThemeMap>(themes: Themes, options: CookieThemeStoreOptions): Required<ThemeStore<Themes>>;
|
|
40
|
+
declare function cookieThemeStore<Themes extends ThemeMap>(themes: Themes, options: CookieThemeStoreOptions<Themes>): Required<ThemeStore<Themes>>;
|
|
39
41
|
/**
|
|
40
42
|
* Reads the theme from cookies during SSR. Use with the request's Cookie header or
|
|
41
43
|
* a framework's cookie API (e.g. Next.js cookies()).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookie-theme-store.d.cts","names":[],"sources":["../../../../src/theme/theme-store/cookie-theme-store/cookie-theme-store.ts"],"sourcesContent":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"cookie-theme-store.d.cts","names":[],"sources":["../../../../src/theme/theme-store/cookie-theme-store/cookie-theme-store.ts"],"sourcesContent":[],"mappings":";;;;;;UAUiB,uCAAuC,WAAW;;EAAlD,IAAA,CAAA,EAAA,MAAA,GAAA,SAAA;EAAuC,MAAA,CAAA,EAAA,MAAA,GAAA,SAAA;EAAW,QAAA,CAAA,EAAA,KAAA,GAAA,QAAA,GAAA,MAAA,GAAA,SAAA;EAMzC,MAAA,CAAA,EAAA,OAAA,GAAA,SAAA;EAAjB,KAAA,CAAA,EAAA,gBAAA,CAAiB,MAAjB,CAAA,GAAA,SAAA;;AA4BT;;;;;;;;;AAuEA;;;;;;;;;;;;;;;;iBAvEgB,gCAAgC,kBACvC,iBACC,wBAAwB,UAC/B,SAAS,WAAW;;;;;;;;;;;;;;;;;;;;;;iBAoEP,kCAAkC,2GAEzC;;IAEN,WAAW"}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { ThemeMap } from "../../theme-map.types.mjs";
|
|
2
|
-
import { ThemeEntry } from "../../theme-entry.types.mjs";
|
|
2
|
+
import { ParseStoredTheme, ThemeEntry } from "../../theme-entry.types.mjs";
|
|
3
3
|
import { ThemeStore } from "../theme-store.types.mjs";
|
|
4
4
|
import { Required } from "type-plus";
|
|
5
5
|
|
|
6
6
|
//#region src/theme/theme-store/cookie-theme-store/cookie-theme-store.d.ts
|
|
7
|
-
interface CookieThemeStoreOptions {
|
|
7
|
+
interface CookieThemeStoreOptions<Themes extends ThemeMap = ThemeMap> {
|
|
8
8
|
cookieName: string;
|
|
9
9
|
path?: string | undefined;
|
|
10
10
|
maxAge?: number | undefined;
|
|
11
11
|
sameSite?: 'lax' | 'strict' | 'none' | undefined;
|
|
12
12
|
secure?: boolean | undefined;
|
|
13
|
+
parse?: ParseStoredTheme<Themes> | undefined;
|
|
13
14
|
}
|
|
14
15
|
/**
|
|
15
16
|
* Creates a theme store backed by cookies.
|
|
@@ -24,6 +25,7 @@ interface CookieThemeStoreOptions {
|
|
|
24
25
|
* @param options.maxAge - Cookie max-age in seconds
|
|
25
26
|
* @param options.sameSite - Cookie sameSite attribute
|
|
26
27
|
* @param options.secure - Cookie secure attribute
|
|
28
|
+
* @param options.parse - Optional custom parser for stored string (default: parseStoredTheme)
|
|
27
29
|
* @returns ThemeStore
|
|
28
30
|
*
|
|
29
31
|
* @example
|
|
@@ -35,7 +37,7 @@ interface CookieThemeStoreOptions {
|
|
|
35
37
|
* store.subscribe((themeResult) => {})
|
|
36
38
|
* ```
|
|
37
39
|
*/
|
|
38
|
-
declare function cookieThemeStore<Themes extends ThemeMap>(themes: Themes, options: CookieThemeStoreOptions): Required<ThemeStore<Themes>>;
|
|
40
|
+
declare function cookieThemeStore<Themes extends ThemeMap>(themes: Themes, options: CookieThemeStoreOptions<Themes>): Required<ThemeStore<Themes>>;
|
|
39
41
|
/**
|
|
40
42
|
* Reads the theme from cookies during SSR. Use with the request's Cookie header or
|
|
41
43
|
* a framework's cookie API (e.g. Next.js cookies()).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookie-theme-store.d.mts","names":[],"sources":["../../../../src/theme/theme-store/cookie-theme-store/cookie-theme-store.ts"],"sourcesContent":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"cookie-theme-store.d.mts","names":[],"sources":["../../../../src/theme/theme-store/cookie-theme-store/cookie-theme-store.ts"],"sourcesContent":[],"mappings":";;;;;;UAUiB,uCAAuC,WAAW;;EAAlD,IAAA,CAAA,EAAA,MAAA,GAAA,SAAA;EAAuC,MAAA,CAAA,EAAA,MAAA,GAAA,SAAA;EAAW,QAAA,CAAA,EAAA,KAAA,GAAA,QAAA,GAAA,MAAA,GAAA,SAAA;EAMzC,MAAA,CAAA,EAAA,OAAA,GAAA,SAAA;EAAjB,KAAA,CAAA,EAAA,gBAAA,CAAiB,MAAjB,CAAA,GAAA,SAAA;;AA4BT;;;;;;;;;AAuEA;;;;;;;;;;;;;;;;iBAvEgB,gCAAgC,kBACvC,iBACC,wBAAwB,UAC/B,SAAS,WAAW;;;;;;;;;;;;;;;;;;;;;;iBAoEP,kCAAkC,2GAEzC;;IAEN,WAAW"}
|
|
@@ -1,24 +1,10 @@
|
|
|
1
|
-
import { themeEntry } from "../../theme-entry.mjs";
|
|
2
1
|
import { dummyThemeStore } from "../../../testing/theme/dummy-theme-store.mjs";
|
|
3
2
|
import { parseStoredTheme } from "../../_utils/parse-stored-theme.mjs";
|
|
3
|
+
import { getCookieFromHeader } from "../../cookie/_cookie-utils.mjs";
|
|
4
|
+
import { readCookieTheme } from "../../cookie/read-cookie-theme.mjs";
|
|
5
|
+
import { writeCookieTheme } from "../../cookie/write-cookie-theme.mjs";
|
|
4
6
|
|
|
5
7
|
//#region src/theme/theme-store/cookie-theme-store/cookie-theme-store.ts
|
|
6
|
-
function getCookieValue(name) {
|
|
7
|
-
if (typeof document === "undefined" || !document.cookie) return null;
|
|
8
|
-
const value = document.cookie.match(/* @__PURE__ */ new RegExp(`(?:^|;\\s*)${name}=([^;]*)`))?.[1];
|
|
9
|
-
return value !== void 0 ? decodeURIComponent(value) : null;
|
|
10
|
-
}
|
|
11
|
-
function setCookie(name, value, options) {
|
|
12
|
-
const parts = [`${name}=${encodeURIComponent(value)}`];
|
|
13
|
-
parts.push(`path=${options.path ?? "/"}`);
|
|
14
|
-
if (options.maxAge !== void 0) parts.push(`max-age=${options.maxAge}`);
|
|
15
|
-
if (options.sameSite !== void 0) parts.push(`samesite=${options.sameSite}`);
|
|
16
|
-
if (options.secure) parts.push("secure");
|
|
17
|
-
document.cookie = parts.join("; ");
|
|
18
|
-
}
|
|
19
|
-
function deleteCookie(name, path = "/") {
|
|
20
|
-
document.cookie = `${name}=; path=${path}; max-age=0`;
|
|
21
|
-
}
|
|
22
8
|
/**
|
|
23
9
|
* Creates a theme store backed by cookies.
|
|
24
10
|
*
|
|
@@ -32,6 +18,7 @@ function deleteCookie(name, path = "/") {
|
|
|
32
18
|
* @param options.maxAge - Cookie max-age in seconds
|
|
33
19
|
* @param options.sameSite - Cookie sameSite attribute
|
|
34
20
|
* @param options.secure - Cookie secure attribute
|
|
21
|
+
* @param options.parse - Optional custom parser for stored string (default: parseStoredTheme)
|
|
35
22
|
* @returns ThemeStore
|
|
36
23
|
*
|
|
37
24
|
* @example
|
|
@@ -44,14 +31,16 @@ function deleteCookie(name, path = "/") {
|
|
|
44
31
|
* ```
|
|
45
32
|
*/
|
|
46
33
|
function cookieThemeStore(themes, options) {
|
|
47
|
-
const { cookieName, path = "/", maxAge, sameSite, secure } = options;
|
|
34
|
+
const { cookieName, path = "/", maxAge, sameSite, secure, parse = parseStoredTheme } = options;
|
|
48
35
|
if (document.cookie === void 0) return dummyThemeStore;
|
|
49
36
|
const handlers = /* @__PURE__ */ new Set();
|
|
50
37
|
let lastNotifiedKey = read()?.theme ?? void 0;
|
|
51
38
|
function read() {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
39
|
+
return readCookieTheme(themes, {
|
|
40
|
+
cookieName,
|
|
41
|
+
path,
|
|
42
|
+
parse
|
|
43
|
+
});
|
|
55
44
|
}
|
|
56
45
|
function notify() {
|
|
57
46
|
const result = read();
|
|
@@ -64,14 +53,13 @@ function cookieThemeStore(themes, options) {
|
|
|
64
53
|
read,
|
|
65
54
|
write(entry) {
|
|
66
55
|
try {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
56
|
+
writeCookieTheme(themes, entry, {
|
|
57
|
+
cookieName,
|
|
58
|
+
path,
|
|
59
|
+
maxAge,
|
|
60
|
+
sameSite,
|
|
61
|
+
secure
|
|
62
|
+
});
|
|
75
63
|
notify();
|
|
76
64
|
} catch {}
|
|
77
65
|
},
|
|
@@ -83,10 +71,6 @@ function cookieThemeStore(themes, options) {
|
|
|
83
71
|
}
|
|
84
72
|
};
|
|
85
73
|
}
|
|
86
|
-
function getCookieFromHeader(cookieHeader, name) {
|
|
87
|
-
const value = cookieHeader.match(/* @__PURE__ */ new RegExp(`(?:^|;\\s*)${name}=([^;]*)`))?.[1];
|
|
88
|
-
return value !== void 0 ? decodeURIComponent(value.trim()) : null;
|
|
89
|
-
}
|
|
90
74
|
/**
|
|
91
75
|
* Reads the theme from cookies during SSR. Use with the request's Cookie header or
|
|
92
76
|
* a framework's cookie API (e.g. Next.js cookies()).
|
|
@@ -110,9 +94,7 @@ function getCookieFromHeader(cookieHeader, name) {
|
|
|
110
94
|
*/
|
|
111
95
|
function getThemeFromCookie(cookieSource, themes, options = {}) {
|
|
112
96
|
const cookieName = options.cookieName ?? "theme";
|
|
113
|
-
|
|
114
|
-
if (theme === void 0) return void 0;
|
|
115
|
-
return themeEntry(themes, theme);
|
|
97
|
+
return parseStoredTheme(themes, (typeof cookieSource === "function" ? cookieSource(cookieName) ?? null : cookieSource ? getCookieFromHeader(cookieSource, cookieName) : null) ?? void 0);
|
|
116
98
|
}
|
|
117
99
|
|
|
118
100
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookie-theme-store.mjs","names":["lastNotifiedKey: keyof Themes | undefined"
|
|
1
|
+
{"version":3,"file":"cookie-theme-store.mjs","names":["lastNotifiedKey: keyof Themes | undefined"],"sources":["../../../../src/theme/theme-store/cookie-theme-store/cookie-theme-store.ts"],"sourcesContent":["import type { Required } from 'type-plus'\nimport { dummyThemeStore } from '../../../testing/theme/dummy-theme-store.ts'\nimport { parseStoredTheme } from '../../_utils/parse-stored-theme.ts'\nimport { getCookieFromHeader } from '../../cookie/_cookie-utils.ts'\nimport { readCookieTheme } from '../../cookie/read-cookie-theme.ts'\nimport { writeCookieTheme } from '../../cookie/write-cookie-theme.ts'\nimport type { ParseStoredTheme, ThemeEntry } from '../../theme-entry.types.ts'\nimport type { ThemeMap } from '../../theme-map.types.ts'\nimport type { ThemeStore } from '../theme-store.types.ts'\n\nexport interface CookieThemeStoreOptions<Themes extends ThemeMap = ThemeMap> {\n\tcookieName: string\n\tpath?: string | undefined\n\tmaxAge?: number | undefined\n\tsameSite?: 'lax' | 'strict' | 'none' | undefined\n\tsecure?: boolean | undefined\n\tparse?: ParseStoredTheme<Themes> | undefined\n}\n\n/**\n * Creates a theme store backed by cookies.\n *\n * Persists across sessions. Cookies are sent with every request, so the server can\n * read the theme during SSR to avoid flash of wrong theme. Cross-tab sync is not\n * supported (cookies have no StorageEvent).\n *\n * @param themes - Record mapping theme keys to values (for validation)\n * @param options.cookieName - Cookie name for theme storage\n * @param options.path - Cookie path (default: '/')\n * @param options.maxAge - Cookie max-age in seconds\n * @param options.sameSite - Cookie sameSite attribute\n * @param options.secure - Cookie secure attribute\n * @param options.parse - Optional custom parser for stored string (default: parseStoredTheme)\n * @returns ThemeStore\n *\n * @example\n * ```ts\n * const themes = { current: 'theme-current', grayscale: 'theme-grayscale' }\n * const store = cookieThemeStore(themes, { cookieName: 'theme' })\n * store.read()\n * store.write(themeEntry(themes, 'grayscale'))\n * store.subscribe((themeResult) => {})\n * ```\n */\nexport function cookieThemeStore<Themes extends ThemeMap>(\n\tthemes: Themes,\n\toptions: CookieThemeStoreOptions<Themes>\n): Required<ThemeStore<Themes>> {\n\tconst { cookieName, path = '/', maxAge, sameSite, secure, parse = parseStoredTheme } = options\n\n\tif (document.cookie === undefined) {\n\t\treturn dummyThemeStore\n\t}\n\n\tconst handlers = new Set<(theme: ThemeEntry<Themes> | undefined) => void>()\n\tlet lastNotifiedKey: keyof Themes | undefined = read()?.theme ?? undefined\n\n\tfunction read() {\n\t\treturn readCookieTheme(themes, { cookieName, path, parse })\n\t}\n\n\tfunction notify() {\n\t\tconst result = read()\n\t\tconst key = result?.theme ?? undefined\n\t\tif (key === lastNotifiedKey) return\n\t\tlastNotifiedKey = key\n\t\tfor (const h of handlers) h(result)\n\t}\n\n\treturn {\n\t\tread,\n\t\twrite(entry) {\n\t\t\ttry {\n\t\t\t\twriteCookieTheme(themes, entry, {\n\t\t\t\t\tcookieName,\n\t\t\t\t\tpath,\n\t\t\t\t\tmaxAge,\n\t\t\t\t\tsameSite,\n\t\t\t\t\tsecure\n\t\t\t\t})\n\t\t\t\tnotify()\n\t\t\t} catch {\n\t\t\t\t// Ignore quota or other errors\n\t\t\t}\n\t\t},\n\t\tsubscribe(handler) {\n\t\t\thandlers.add(handler)\n\t\t\treturn () => {\n\t\t\t\thandlers.delete(handler)\n\t\t\t}\n\t\t}\n\t} satisfies ThemeStore<Themes>\n}\n\n/**\n * Reads the theme from cookies during SSR. Use with the request's Cookie header or\n * a framework's cookie API (e.g. Next.js cookies()).\n *\n * @param cookieSource - Raw Cookie header string, or a getter (name) => value for framework APIs\n * @param themes - Record mapping theme keys to values (for validation)\n * @param options - Optional cookie name (default: 'theme')\n * @returns ThemeEntry if valid cookie found, otherwise undefined\n *\n * @example\n * ```ts\n * // With raw Cookie header (Express, Remix, etc.)\n * const theme = getThemeFromCookie(request.headers.get('Cookie') ?? '', themes)\n *\n * // With Next.js cookies()\n * const theme = getThemeFromCookie(\n * (name) => cookies().get(name)?.value ?? undefined,\n * themes\n * )\n * ```\n */\nexport function getThemeFromCookie<Themes extends ThemeMap>(\n\tcookieSource: string | null | undefined | ((name: string) => string | null | undefined),\n\tthemes: Themes,\n\toptions: { cookieName?: string | undefined } = {}\n): ThemeEntry<Themes> | undefined {\n\tconst cookieName = options.cookieName ?? 'theme'\n\tconst stored =\n\t\ttypeof cookieSource === 'function'\n\t\t\t? (cookieSource(cookieName) ?? null)\n\t\t\t: cookieSource\n\t\t\t\t? getCookieFromHeader(cookieSource, cookieName)\n\t\t\t\t: null\n\treturn parseStoredTheme(themes, stored ?? undefined)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,SAAgB,iBACf,QACA,SAC+B;CAC/B,MAAM,EAAE,YAAY,OAAO,KAAK,QAAQ,UAAU,QAAQ,QAAQ,qBAAqB;AAEvF,KAAI,SAAS,WAAW,OACvB,QAAO;CAGR,MAAM,2BAAW,IAAI,KAAsD;CAC3E,IAAIA,kBAA4C,MAAM,EAAE,SAAS;CAEjE,SAAS,OAAO;AACf,SAAO,gBAAgB,QAAQ;GAAE;GAAY;GAAM;GAAO,CAAC;;CAG5D,SAAS,SAAS;EACjB,MAAM,SAAS,MAAM;EACrB,MAAM,MAAM,QAAQ,SAAS;AAC7B,MAAI,QAAQ,gBAAiB;AAC7B,oBAAkB;AAClB,OAAK,MAAM,KAAK,SAAU,GAAE,OAAO;;AAGpC,QAAO;EACN;EACA,MAAM,OAAO;AACZ,OAAI;AACH,qBAAiB,QAAQ,OAAO;KAC/B;KACA;KACA;KACA;KACA;KACA,CAAC;AACF,YAAQ;WACD;;EAIT,UAAU,SAAS;AAClB,YAAS,IAAI,QAAQ;AACrB,gBAAa;AACZ,aAAS,OAAO,QAAQ;;;EAG1B;;;;;;;;;;;;;;;;;;;;;;;AAwBF,SAAgB,mBACf,cACA,QACA,UAA+C,EAAE,EAChB;CACjC,MAAM,aAAa,QAAQ,cAAc;AAOzC,QAAO,iBAAiB,SALvB,OAAO,iBAAiB,aACpB,aAAa,WAAW,IAAI,OAC7B,eACC,oBAAoB,cAAc,WAAW,GAC7C,SACqC,OAAU"}
|
|
@@ -1,47 +1,67 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
1
|
+
const require__constant = require('../../data-attribute/_constant.cjs');
|
|
2
|
+
const require_parse_data_attribute = require('../../data-attribute/parse-data-attribute.cjs');
|
|
3
|
+
const require_read_data_attribute = require('../../data-attribute/read-data-attribute.cjs');
|
|
4
|
+
const require_stringify_data_attribute = require('../../data-attribute/stringify-data-attribute.cjs');
|
|
5
|
+
const require_subscribe_data_attribute = require('../../data-attribute/subscribe-data-attribute.cjs');
|
|
6
|
+
const require_write_data_attribute = require('../../data-attribute/write-data-attribute.cjs');
|
|
7
7
|
|
|
8
8
|
//#region src/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.ts
|
|
9
9
|
/**
|
|
10
10
|
* Creates a theme store that reads and writes via a data attribute.
|
|
11
11
|
*
|
|
12
|
+
* read: parse(themes, getDataAttribute(element, attribute)) → ThemeEntry
|
|
13
|
+
* write: setAttribute(attribute, stringify(themes, getDataAttribute(element, attribute), entry))
|
|
14
|
+
*
|
|
15
|
+
* Supports space-separated attribute values by default. Use `parse` and `stringify` to customize
|
|
16
|
+
* (e.g. comma-separated via curried parseDataAttribute/stringifyDataAttribute).
|
|
17
|
+
*
|
|
12
18
|
* @param themes - Record mapping theme keys to attribute values
|
|
13
19
|
* @param options.attributeName - Data attribute name (e.g. `data-theme`)
|
|
14
|
-
* @param options.element - Element to operate on (
|
|
20
|
+
* @param options.element - Element to operate on (accepts null e.g. from refs). Defaults to document.documentElement.
|
|
21
|
+
* @param options.parse - Custom parser (default: parseDataAttribute with space separator)
|
|
22
|
+
* @param options.stringify - Custom serializer (default: stringifyDataAttribute with space separator)
|
|
15
23
|
* @returns ThemeStore
|
|
16
24
|
*
|
|
17
25
|
* @example
|
|
18
26
|
* ```ts
|
|
19
27
|
* const themes = { current: 'current', grayscale: 'grayscale' }
|
|
20
28
|
* const store = dataAttributeThemeStore(themes, { attributeName: 'data-theme' })
|
|
21
|
-
* store.read() // returns
|
|
29
|
+
* store.read() // returns ThemeEntry from data attribute
|
|
22
30
|
* store.write(themeEntry(themes, 'grayscale'))
|
|
23
|
-
* store.subscribe((
|
|
31
|
+
* store.subscribe((entry) => {})
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* // Comma-separated
|
|
37
|
+
* const store = dataAttributeThemeStore(themes, {
|
|
38
|
+
* attributeName: 'data-theme',
|
|
39
|
+
* parse: (t, v) => parseDataAttribute(t, v, { separator: ',' }),
|
|
40
|
+
* stringify: (t, x, e) => stringifyDataAttribute(t, x, e, { separator: ',' })
|
|
41
|
+
* })
|
|
24
42
|
* ```
|
|
25
43
|
*/
|
|
26
44
|
function dataAttributeThemeStore(themes, options) {
|
|
27
45
|
const element = options.element ?? document?.documentElement;
|
|
28
|
-
const { attributeName } = options;
|
|
29
|
-
if (!element) return require_dummy_theme_store.dummyThemeStore;
|
|
46
|
+
const { attributeName, parse = (t, v) => require_parse_data_attribute.parseDataAttribute(t, v, { separator: require__constant.SEPARATOR_SPACE }), stringify = (t, x, e) => require_stringify_data_attribute.stringifyDataAttribute(t, x, e, { separator: require__constant.SEPARATOR_SPACE }) } = options;
|
|
30
47
|
return {
|
|
31
48
|
read() {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
49
|
+
return require_read_data_attribute.readDataAttribute(themes, attributeName, {
|
|
50
|
+
element,
|
|
51
|
+
parse
|
|
52
|
+
});
|
|
35
53
|
},
|
|
36
54
|
write(entry) {
|
|
37
|
-
|
|
55
|
+
require_write_data_attribute.writeDataAttribute(themes, attributeName, entry, {
|
|
56
|
+
element,
|
|
57
|
+
stringify
|
|
58
|
+
});
|
|
38
59
|
},
|
|
39
60
|
subscribe(handler) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
return () => observer.disconnect();
|
|
61
|
+
return require_subscribe_data_attribute.subscribeDataAttribute(themes, attributeName, handler, {
|
|
62
|
+
element,
|
|
63
|
+
parse
|
|
64
|
+
});
|
|
45
65
|
}
|
|
46
66
|
};
|
|
47
67
|
}
|