@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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-theme-hook.cjs","names":["lastTheme: keyof Themes | undefined","unobserve: () => void","themeEntry","composeThemeStores"],"sources":["../../../src/react/theme/create-theme-hook.ts"],"sourcesContent":["import { useCallback, useSyncExternalStore } from 'react'\nimport type { Required } from 'type-plus'\nimport {\n\ttype ComposeThemeStoreEntry,\n\ttype ComposeThemeStoresOptions,\n\tcomposeThemeStores\n} from '../../theme/compose-theme-stores.ts'\nimport { themeEntry } from '../../theme/theme-entry.ts'\nimport type { ThemeEntry } from '../../theme/theme-entry.types.ts'\nimport type { ThemeMap } from '../../theme/theme-map.types.ts'\nimport type { AsyncThemeStore } from '../../theme/theme-store/async-theme-store.types.ts'\nimport type { ThemeStoreFactory } from '../../theme/theme-store/theme-store-factory.types.ts'\n\n/**\n * Creates a React hook for theme selection that reads from and writes to composed theme stores.\n *\n * The returned hook subscribes to store changes via `useSyncExternalStore`, supports SSR\n * (uses `defaultTheme` for server snapshot), and returns a `[theme, setTheme]` tuple.\n * Channels are cached per store configuration and default theme for efficient reuse.\n *\n * @param themes - ThemeMap mapping theme keys to their values (e.g. CSS class names)\n * @param stores - Array of 1–8 theme stores or factory configs (see ComposeThemeStoreEntry)\n * @param options.defaultTheme - Fallback theme key when stores return empty; also used for SSR\n * @returns A `useTheme` hook that returns `[currentTheme, setTheme]` tuple\n *\n * @example\n * ```ts\n * const useTheme = createThemeHook(themes, [localStorageStore], { defaultTheme: 'light' })\n * const [theme, setTheme] = useTheme()\n * setTheme('dark')\n * ```\n */\nexport function createThemeHook<\n\tThemes extends ThemeMap,\n\tA extends ThemeStoreFactory<Themes> = never,\n\tB extends ThemeStoreFactory<Themes> = never,\n\tC extends ThemeStoreFactory<Themes> = never,\n\tD extends ThemeStoreFactory<Themes> = never,\n\tE extends ThemeStoreFactory<Themes> = never,\n\tF extends ThemeStoreFactory<Themes> = never,\n\tG extends ThemeStoreFactory<Themes> = never,\n\tH extends ThemeStoreFactory<Themes> = never\n>(\n\tthemes: Themes,\n\tstores: readonly [\n\t\tstore1: ComposeThemeStoreEntry<Themes, A>,\n\t\tstore2?: ComposeThemeStoreEntry<Themes, B>,\n\t\tstore3?: ComposeThemeStoreEntry<Themes, C>,\n\t\tstore4?: ComposeThemeStoreEntry<Themes, D>,\n\t\tstore5?: ComposeThemeStoreEntry<Themes, E>,\n\t\tstore6?: ComposeThemeStoreEntry<Themes, F>,\n\t\tstore7?: ComposeThemeStoreEntry<Themes, G>,\n\t\tstore8?: ComposeThemeStoreEntry<Themes, H>\n\t],\n\toptions?: ComposeThemeStoresOptions<Themes>\n): (\n\toverrideDefaultTheme?: keyof Themes | undefined\n) => [keyof Themes | undefined, (theme: keyof Themes) => void] {\n\tconst { defaultTheme } = options ?? {}\n\treturn function useTheme(overrideDefaultTheme?: keyof Themes | undefined) {\n\t\tconst effectiveDefault = overrideDefaultTheme ?? defaultTheme\n\t\tconst channel = getOrCreateChannel<Themes, A, B, C, D, E, F, G, H>(themes, stores, {\n\t\t\tdefaultTheme: effectiveDefault\n\t\t})\n\n\t\tconst theme = useSyncExternalStore<keyof Themes | undefined>(\n\t\t\tchannel.subscribe,\n\t\t\tchannel.getSnapshot,\n\t\t\tchannel.getServerSnapshot\n\t\t)\n\n\t\tconst setTheme = useCallback(\n\t\t\tasync (newTheme: keyof Themes) => {\n\t\t\t\tawait channel.setTheme(newTheme)\n\t\t\t},\n\t\t\t[channel]\n\t\t)\n\n\t\treturn [theme, setTheme]\n\t}\n}\n\n/**\n * Creates a subscription channel bridging a composed theme store to React's useSyncExternalStore.\n * Manages listeners, initial async read from store, and delegates setTheme to store.write.\n *\n * @internal\n */\nfunction createSharedChannel<Themes extends ThemeMap>(\n\tthemes: Themes,\n\tcomposedStore: Required<AsyncThemeStore<Themes>>,\n\tdefaultTheme: keyof Themes | undefined\n) {\n\tlet lastTheme: keyof Themes | undefined = defaultTheme\n\tconst listeners = new Set<(theme: keyof Themes | undefined) => void>()\n\n\tconst notify = (theme: keyof Themes | undefined) => {\n\t\tlastTheme = theme\n\t\tfor (const fn of listeners) {\n\t\t\tfn(theme)\n\t\t}\n\t}\n\n\tconst handleStoreUpdate = (entry: ThemeEntry<Themes> | undefined
|
|
1
|
+
{"version":3,"file":"create-theme-hook.cjs","names":["lastTheme: keyof Themes | undefined","unobserve: () => void","themeEntry","composeThemeStores"],"sources":["../../../src/react/theme/create-theme-hook.ts"],"sourcesContent":["import { useCallback, useSyncExternalStore } from 'react'\nimport type { Required } from 'type-plus'\nimport {\n\ttype ComposeThemeStoreEntry,\n\ttype ComposeThemeStoresOptions,\n\tcomposeThemeStores\n} from '../../theme/compose-theme-stores.ts'\nimport { themeEntry } from '../../theme/theme-entry.ts'\nimport type { ThemeEntry } from '../../theme/theme-entry.types.ts'\nimport type { ThemeMap } from '../../theme/theme-map.types.ts'\nimport type { AsyncThemeStore } from '../../theme/theme-store/async-theme-store.types.ts'\nimport type { ThemeStoreFactory } from '../../theme/theme-store/theme-store-factory.types.ts'\n\n/**\n * Creates a React hook for theme selection that reads from and writes to composed theme stores.\n *\n * The returned hook subscribes to store changes via `useSyncExternalStore`, supports SSR\n * (uses `defaultTheme` for server snapshot), and returns a `[theme, setTheme]` tuple.\n * Channels are cached per store configuration and default theme for efficient reuse.\n *\n * @param themes - ThemeMap mapping theme keys to their values (e.g. CSS class names)\n * @param stores - Array of 1–8 theme stores or factory configs (see ComposeThemeStoreEntry)\n * @param options.defaultTheme - Fallback theme key when stores return empty; also used for SSR\n * @returns A `useTheme` hook that returns `[currentTheme, setTheme]` tuple\n *\n * @example\n * ```ts\n * const useTheme = createThemeHook(themes, [localStorageStore], { defaultTheme: 'light' })\n * const [theme, setTheme] = useTheme()\n * setTheme('dark')\n * ```\n */\nexport function createThemeHook<\n\tThemes extends ThemeMap,\n\tA extends ThemeStoreFactory<Themes> = never,\n\tB extends ThemeStoreFactory<Themes> = never,\n\tC extends ThemeStoreFactory<Themes> = never,\n\tD extends ThemeStoreFactory<Themes> = never,\n\tE extends ThemeStoreFactory<Themes> = never,\n\tF extends ThemeStoreFactory<Themes> = never,\n\tG extends ThemeStoreFactory<Themes> = never,\n\tH extends ThemeStoreFactory<Themes> = never\n>(\n\tthemes: Themes,\n\tstores: readonly [\n\t\tstore1: ComposeThemeStoreEntry<Themes, A>,\n\t\tstore2?: ComposeThemeStoreEntry<Themes, B>,\n\t\tstore3?: ComposeThemeStoreEntry<Themes, C>,\n\t\tstore4?: ComposeThemeStoreEntry<Themes, D>,\n\t\tstore5?: ComposeThemeStoreEntry<Themes, E>,\n\t\tstore6?: ComposeThemeStoreEntry<Themes, F>,\n\t\tstore7?: ComposeThemeStoreEntry<Themes, G>,\n\t\tstore8?: ComposeThemeStoreEntry<Themes, H>\n\t],\n\toptions?: ComposeThemeStoresOptions<Themes>\n): (\n\toverrideDefaultTheme?: keyof Themes | undefined\n) => [keyof Themes | undefined, (theme: keyof Themes) => void] {\n\tconst { defaultTheme } = options ?? {}\n\treturn function useTheme(overrideDefaultTheme?: keyof Themes | undefined) {\n\t\tconst effectiveDefault = overrideDefaultTheme ?? defaultTheme\n\t\tconst channel = getOrCreateChannel<Themes, A, B, C, D, E, F, G, H>(themes, stores, {\n\t\t\tdefaultTheme: effectiveDefault\n\t\t})\n\n\t\tconst theme = useSyncExternalStore<keyof Themes | undefined>(\n\t\t\tchannel.subscribe,\n\t\t\tchannel.getSnapshot,\n\t\t\tchannel.getServerSnapshot\n\t\t)\n\n\t\tconst setTheme = useCallback(\n\t\t\tasync (newTheme: keyof Themes) => {\n\t\t\t\tawait channel.setTheme(newTheme)\n\t\t\t},\n\t\t\t[channel]\n\t\t)\n\n\t\treturn [theme, setTheme]\n\t}\n}\n\n/**\n * Creates a subscription channel bridging a composed theme store to React's useSyncExternalStore.\n * Manages listeners, initial async read from store, and delegates setTheme to store.write.\n *\n * @internal\n */\nfunction createSharedChannel<Themes extends ThemeMap>(\n\tthemes: Themes,\n\tcomposedStore: Required<AsyncThemeStore<Themes>>,\n\tdefaultTheme: keyof Themes | undefined\n) {\n\tlet lastTheme: keyof Themes | undefined = defaultTheme\n\tconst listeners = new Set<(theme: keyof Themes | undefined) => void>()\n\n\tconst notify = (theme: keyof Themes | undefined) => {\n\t\tlastTheme = theme\n\t\tfor (const fn of listeners) {\n\t\t\tfn(theme)\n\t\t}\n\t}\n\n\tconst handleStoreUpdate = (entry: ThemeEntry<Themes> | undefined) => {\n\t\tnotify(entry?.theme ?? defaultTheme)\n\t}\n\n\t// Initial read to populate lastTheme (compose store subscribe has no initial notify)\n\tvoid Promise.resolve(composedStore.read()).then((entry: ThemeEntry<Themes> | undefined) => {\n\t\tnotify(entry?.theme ?? defaultTheme)\n\t})\n\n\tlet unobserve: () => void = composedStore.subscribe(handleStoreUpdate)\n\tlet isSubscribedToStore = true\n\n\tconst subscribe = (listener: (theme: keyof Themes | undefined) => void) => {\n\t\tif (!isSubscribedToStore) {\n\t\t\tunobserve = composedStore.subscribe(handleStoreUpdate)\n\t\t\tisSubscribedToStore = true\n\t\t}\n\t\tlisteners.add(listener)\n\t\tlistener(lastTheme)\n\t\treturn () => {\n\t\t\tlisteners.delete(listener)\n\t\t\tif (listeners.size === 0) {\n\t\t\t\tunobserve()\n\t\t\t\tisSubscribedToStore = false\n\t\t\t}\n\t\t}\n\t}\n\n\tconst getSnapshot = (): keyof Themes | undefined => lastTheme\n\tconst getServerSnapshot = (): keyof Themes | undefined => defaultTheme\n\n\treturn {\n\t\tsubscribe,\n\t\tgetSnapshot,\n\t\tgetServerSnapshot,\n\t\tsetTheme: (theme: keyof Themes) => composedStore.write(themeEntry(themes, theme))\n\t}\n}\n\nconst channelsByStores = new WeakMap<\n\tobject,\n\tMap<string | undefined, ReturnType<typeof createSharedChannel<any>>>\n>()\n\n/**\n * Returns a cached shared channel for the given themes, stores, and defaultTheme.\n * Channels are keyed by stores (WeakMap) and defaultTheme to avoid duplicate subscriptions.\n *\n * @internal\n */\nfunction getOrCreateChannel<\n\tThemes extends ThemeMap,\n\tA extends ThemeStoreFactory<Themes> = never,\n\tB extends ThemeStoreFactory<Themes> = never,\n\tC extends ThemeStoreFactory<Themes> = never,\n\tD extends ThemeStoreFactory<Themes> = never,\n\tE extends ThemeStoreFactory<Themes> = never,\n\tF extends ThemeStoreFactory<Themes> = never,\n\tG extends ThemeStoreFactory<Themes> = never,\n\tH extends ThemeStoreFactory<Themes> = never\n>(\n\tthemes: Themes,\n\tstores: readonly [\n\t\tstore1: ComposeThemeStoreEntry<Themes, A>,\n\t\tstore2?: ComposeThemeStoreEntry<Themes, B>,\n\t\tstore3?: ComposeThemeStoreEntry<Themes, C>,\n\t\tstore4?: ComposeThemeStoreEntry<Themes, D>,\n\t\tstore5?: ComposeThemeStoreEntry<Themes, E>,\n\t\tstore6?: ComposeThemeStoreEntry<Themes, F>,\n\t\tstore7?: ComposeThemeStoreEntry<Themes, G>,\n\t\tstore8?: ComposeThemeStoreEntry<Themes, H>\n\t],\n\toptions?: ComposeThemeStoresOptions<Themes> | undefined\n) {\n\tconst { defaultTheme } = options ?? {}\n\tconst storesKey = stores as unknown as object\n\tlet byDefault = channelsByStores.get(storesKey) as Map<\n\t\tkeyof Themes | undefined,\n\t\tReturnType<typeof createSharedChannel<Themes>>\n\t>\n\tif (!byDefault) {\n\t\tbyDefault = new Map<keyof Themes | undefined, ReturnType<typeof createSharedChannel<Themes>>>()\n\t\tchannelsByStores.set(storesKey, byDefault as any)\n\t}\n\tlet channel = byDefault.get(defaultTheme) as ReturnType<typeof createSharedChannel<Themes>>\n\tif (!channel) {\n\t\tconst composedStore = composeThemeStores(themes, stores, { defaultTheme })\n\t\tchannel = createSharedChannel<Themes>(themes, composedStore, defaultTheme)\n\t\tbyDefault.set(defaultTheme, channel)\n\t}\n\treturn channel\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,SAAgB,gBAWf,QACA,QAUA,SAG8D;CAC9D,MAAM,EAAE,iBAAiB,WAAW,EAAE;AACtC,QAAO,SAAS,SAAS,sBAAiD;EAEzE,MAAM,UAAU,mBAAmD,QAAQ,QAAQ,EAClF,cAFwB,wBAAwB,cAGhD,CAAC;AAeF,SAAO,iCAZN,QAAQ,WACR,QAAQ,aACR,QAAQ,kBACR,yBAGA,OAAO,aAA2B;AACjC,SAAM,QAAQ,SAAS,SAAS;KAEjC,CAAC,QAAQ,CACT,CAEuB;;;;;;;;;AAU1B,SAAS,oBACR,QACA,eACA,cACC;CACD,IAAIA,YAAsC;CAC1C,MAAM,4BAAY,IAAI,KAAgD;CAEtE,MAAM,UAAU,UAAoC;AACnD,cAAY;AACZ,OAAK,MAAM,MAAM,UAChB,IAAG,MAAM;;CAIX,MAAM,qBAAqB,UAA0C;AACpE,SAAO,OAAO,SAAS,aAAa;;AAIrC,CAAK,QAAQ,QAAQ,cAAc,MAAM,CAAC,CAAC,MAAM,UAA0C;AAC1F,SAAO,OAAO,SAAS,aAAa;GACnC;CAEF,IAAIC,YAAwB,cAAc,UAAU,kBAAkB;CACtE,IAAI,sBAAsB;CAE1B,MAAM,aAAa,aAAwD;AAC1E,MAAI,CAAC,qBAAqB;AACzB,eAAY,cAAc,UAAU,kBAAkB;AACtD,yBAAsB;;AAEvB,YAAU,IAAI,SAAS;AACvB,WAAS,UAAU;AACnB,eAAa;AACZ,aAAU,OAAO,SAAS;AAC1B,OAAI,UAAU,SAAS,GAAG;AACzB,eAAW;AACX,0BAAsB;;;;CAKzB,MAAM,oBAA8C;CACpD,MAAM,0BAAoD;AAE1D,QAAO;EACN;EACA;EACA;EACA,WAAW,UAAwB,cAAc,MAAMC,+BAAW,QAAQ,MAAM,CAAC;EACjF;;AAGF,MAAM,mCAAmB,IAAI,SAG1B;;;;;;;AAQH,SAAS,mBAWR,QACA,QAUA,SACC;CACD,MAAM,EAAE,iBAAiB,WAAW,EAAE;CACtC,MAAM,YAAY;CAClB,IAAI,YAAY,iBAAiB,IAAI,UAAU;AAI/C,KAAI,CAAC,WAAW;AACf,8BAAY,IAAI,KAA+E;AAC/F,mBAAiB,IAAI,WAAW,UAAiB;;CAElD,IAAI,UAAU,UAAU,IAAI,aAAa;AACzC,KAAI,CAAC,SAAS;AAEb,YAAU,oBAA4B,QADhBC,gDAAmB,QAAQ,QAAQ,EAAE,cAAc,CAAC,EACb,aAAa;AAC1E,YAAU,IAAI,cAAc,QAAQ;;AAErC,QAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-theme-hook.mjs","names":["lastTheme: keyof Themes | undefined","unobserve: () => void"],"sources":["../../../src/react/theme/create-theme-hook.ts"],"sourcesContent":["import { useCallback, useSyncExternalStore } from 'react'\nimport type { Required } from 'type-plus'\nimport {\n\ttype ComposeThemeStoreEntry,\n\ttype ComposeThemeStoresOptions,\n\tcomposeThemeStores\n} from '../../theme/compose-theme-stores.ts'\nimport { themeEntry } from '../../theme/theme-entry.ts'\nimport type { ThemeEntry } from '../../theme/theme-entry.types.ts'\nimport type { ThemeMap } from '../../theme/theme-map.types.ts'\nimport type { AsyncThemeStore } from '../../theme/theme-store/async-theme-store.types.ts'\nimport type { ThemeStoreFactory } from '../../theme/theme-store/theme-store-factory.types.ts'\n\n/**\n * Creates a React hook for theme selection that reads from and writes to composed theme stores.\n *\n * The returned hook subscribes to store changes via `useSyncExternalStore`, supports SSR\n * (uses `defaultTheme` for server snapshot), and returns a `[theme, setTheme]` tuple.\n * Channels are cached per store configuration and default theme for efficient reuse.\n *\n * @param themes - ThemeMap mapping theme keys to their values (e.g. CSS class names)\n * @param stores - Array of 1–8 theme stores or factory configs (see ComposeThemeStoreEntry)\n * @param options.defaultTheme - Fallback theme key when stores return empty; also used for SSR\n * @returns A `useTheme` hook that returns `[currentTheme, setTheme]` tuple\n *\n * @example\n * ```ts\n * const useTheme = createThemeHook(themes, [localStorageStore], { defaultTheme: 'light' })\n * const [theme, setTheme] = useTheme()\n * setTheme('dark')\n * ```\n */\nexport function createThemeHook<\n\tThemes extends ThemeMap,\n\tA extends ThemeStoreFactory<Themes> = never,\n\tB extends ThemeStoreFactory<Themes> = never,\n\tC extends ThemeStoreFactory<Themes> = never,\n\tD extends ThemeStoreFactory<Themes> = never,\n\tE extends ThemeStoreFactory<Themes> = never,\n\tF extends ThemeStoreFactory<Themes> = never,\n\tG extends ThemeStoreFactory<Themes> = never,\n\tH extends ThemeStoreFactory<Themes> = never\n>(\n\tthemes: Themes,\n\tstores: readonly [\n\t\tstore1: ComposeThemeStoreEntry<Themes, A>,\n\t\tstore2?: ComposeThemeStoreEntry<Themes, B>,\n\t\tstore3?: ComposeThemeStoreEntry<Themes, C>,\n\t\tstore4?: ComposeThemeStoreEntry<Themes, D>,\n\t\tstore5?: ComposeThemeStoreEntry<Themes, E>,\n\t\tstore6?: ComposeThemeStoreEntry<Themes, F>,\n\t\tstore7?: ComposeThemeStoreEntry<Themes, G>,\n\t\tstore8?: ComposeThemeStoreEntry<Themes, H>\n\t],\n\toptions?: ComposeThemeStoresOptions<Themes>\n): (\n\toverrideDefaultTheme?: keyof Themes | undefined\n) => [keyof Themes | undefined, (theme: keyof Themes) => void] {\n\tconst { defaultTheme } = options ?? {}\n\treturn function useTheme(overrideDefaultTheme?: keyof Themes | undefined) {\n\t\tconst effectiveDefault = overrideDefaultTheme ?? defaultTheme\n\t\tconst channel = getOrCreateChannel<Themes, A, B, C, D, E, F, G, H>(themes, stores, {\n\t\t\tdefaultTheme: effectiveDefault\n\t\t})\n\n\t\tconst theme = useSyncExternalStore<keyof Themes | undefined>(\n\t\t\tchannel.subscribe,\n\t\t\tchannel.getSnapshot,\n\t\t\tchannel.getServerSnapshot\n\t\t)\n\n\t\tconst setTheme = useCallback(\n\t\t\tasync (newTheme: keyof Themes) => {\n\t\t\t\tawait channel.setTheme(newTheme)\n\t\t\t},\n\t\t\t[channel]\n\t\t)\n\n\t\treturn [theme, setTheme]\n\t}\n}\n\n/**\n * Creates a subscription channel bridging a composed theme store to React's useSyncExternalStore.\n * Manages listeners, initial async read from store, and delegates setTheme to store.write.\n *\n * @internal\n */\nfunction createSharedChannel<Themes extends ThemeMap>(\n\tthemes: Themes,\n\tcomposedStore: Required<AsyncThemeStore<Themes>>,\n\tdefaultTheme: keyof Themes | undefined\n) {\n\tlet lastTheme: keyof Themes | undefined = defaultTheme\n\tconst listeners = new Set<(theme: keyof Themes | undefined) => void>()\n\n\tconst notify = (theme: keyof Themes | undefined) => {\n\t\tlastTheme = theme\n\t\tfor (const fn of listeners) {\n\t\t\tfn(theme)\n\t\t}\n\t}\n\n\tconst handleStoreUpdate = (entry: ThemeEntry<Themes> | undefined
|
|
1
|
+
{"version":3,"file":"create-theme-hook.mjs","names":["lastTheme: keyof Themes | undefined","unobserve: () => void"],"sources":["../../../src/react/theme/create-theme-hook.ts"],"sourcesContent":["import { useCallback, useSyncExternalStore } from 'react'\nimport type { Required } from 'type-plus'\nimport {\n\ttype ComposeThemeStoreEntry,\n\ttype ComposeThemeStoresOptions,\n\tcomposeThemeStores\n} from '../../theme/compose-theme-stores.ts'\nimport { themeEntry } from '../../theme/theme-entry.ts'\nimport type { ThemeEntry } from '../../theme/theme-entry.types.ts'\nimport type { ThemeMap } from '../../theme/theme-map.types.ts'\nimport type { AsyncThemeStore } from '../../theme/theme-store/async-theme-store.types.ts'\nimport type { ThemeStoreFactory } from '../../theme/theme-store/theme-store-factory.types.ts'\n\n/**\n * Creates a React hook for theme selection that reads from and writes to composed theme stores.\n *\n * The returned hook subscribes to store changes via `useSyncExternalStore`, supports SSR\n * (uses `defaultTheme` for server snapshot), and returns a `[theme, setTheme]` tuple.\n * Channels are cached per store configuration and default theme for efficient reuse.\n *\n * @param themes - ThemeMap mapping theme keys to their values (e.g. CSS class names)\n * @param stores - Array of 1–8 theme stores or factory configs (see ComposeThemeStoreEntry)\n * @param options.defaultTheme - Fallback theme key when stores return empty; also used for SSR\n * @returns A `useTheme` hook that returns `[currentTheme, setTheme]` tuple\n *\n * @example\n * ```ts\n * const useTheme = createThemeHook(themes, [localStorageStore], { defaultTheme: 'light' })\n * const [theme, setTheme] = useTheme()\n * setTheme('dark')\n * ```\n */\nexport function createThemeHook<\n\tThemes extends ThemeMap,\n\tA extends ThemeStoreFactory<Themes> = never,\n\tB extends ThemeStoreFactory<Themes> = never,\n\tC extends ThemeStoreFactory<Themes> = never,\n\tD extends ThemeStoreFactory<Themes> = never,\n\tE extends ThemeStoreFactory<Themes> = never,\n\tF extends ThemeStoreFactory<Themes> = never,\n\tG extends ThemeStoreFactory<Themes> = never,\n\tH extends ThemeStoreFactory<Themes> = never\n>(\n\tthemes: Themes,\n\tstores: readonly [\n\t\tstore1: ComposeThemeStoreEntry<Themes, A>,\n\t\tstore2?: ComposeThemeStoreEntry<Themes, B>,\n\t\tstore3?: ComposeThemeStoreEntry<Themes, C>,\n\t\tstore4?: ComposeThemeStoreEntry<Themes, D>,\n\t\tstore5?: ComposeThemeStoreEntry<Themes, E>,\n\t\tstore6?: ComposeThemeStoreEntry<Themes, F>,\n\t\tstore7?: ComposeThemeStoreEntry<Themes, G>,\n\t\tstore8?: ComposeThemeStoreEntry<Themes, H>\n\t],\n\toptions?: ComposeThemeStoresOptions<Themes>\n): (\n\toverrideDefaultTheme?: keyof Themes | undefined\n) => [keyof Themes | undefined, (theme: keyof Themes) => void] {\n\tconst { defaultTheme } = options ?? {}\n\treturn function useTheme(overrideDefaultTheme?: keyof Themes | undefined) {\n\t\tconst effectiveDefault = overrideDefaultTheme ?? defaultTheme\n\t\tconst channel = getOrCreateChannel<Themes, A, B, C, D, E, F, G, H>(themes, stores, {\n\t\t\tdefaultTheme: effectiveDefault\n\t\t})\n\n\t\tconst theme = useSyncExternalStore<keyof Themes | undefined>(\n\t\t\tchannel.subscribe,\n\t\t\tchannel.getSnapshot,\n\t\t\tchannel.getServerSnapshot\n\t\t)\n\n\t\tconst setTheme = useCallback(\n\t\t\tasync (newTheme: keyof Themes) => {\n\t\t\t\tawait channel.setTheme(newTheme)\n\t\t\t},\n\t\t\t[channel]\n\t\t)\n\n\t\treturn [theme, setTheme]\n\t}\n}\n\n/**\n * Creates a subscription channel bridging a composed theme store to React's useSyncExternalStore.\n * Manages listeners, initial async read from store, and delegates setTheme to store.write.\n *\n * @internal\n */\nfunction createSharedChannel<Themes extends ThemeMap>(\n\tthemes: Themes,\n\tcomposedStore: Required<AsyncThemeStore<Themes>>,\n\tdefaultTheme: keyof Themes | undefined\n) {\n\tlet lastTheme: keyof Themes | undefined = defaultTheme\n\tconst listeners = new Set<(theme: keyof Themes | undefined) => void>()\n\n\tconst notify = (theme: keyof Themes | undefined) => {\n\t\tlastTheme = theme\n\t\tfor (const fn of listeners) {\n\t\t\tfn(theme)\n\t\t}\n\t}\n\n\tconst handleStoreUpdate = (entry: ThemeEntry<Themes> | undefined) => {\n\t\tnotify(entry?.theme ?? defaultTheme)\n\t}\n\n\t// Initial read to populate lastTheme (compose store subscribe has no initial notify)\n\tvoid Promise.resolve(composedStore.read()).then((entry: ThemeEntry<Themes> | undefined) => {\n\t\tnotify(entry?.theme ?? defaultTheme)\n\t})\n\n\tlet unobserve: () => void = composedStore.subscribe(handleStoreUpdate)\n\tlet isSubscribedToStore = true\n\n\tconst subscribe = (listener: (theme: keyof Themes | undefined) => void) => {\n\t\tif (!isSubscribedToStore) {\n\t\t\tunobserve = composedStore.subscribe(handleStoreUpdate)\n\t\t\tisSubscribedToStore = true\n\t\t}\n\t\tlisteners.add(listener)\n\t\tlistener(lastTheme)\n\t\treturn () => {\n\t\t\tlisteners.delete(listener)\n\t\t\tif (listeners.size === 0) {\n\t\t\t\tunobserve()\n\t\t\t\tisSubscribedToStore = false\n\t\t\t}\n\t\t}\n\t}\n\n\tconst getSnapshot = (): keyof Themes | undefined => lastTheme\n\tconst getServerSnapshot = (): keyof Themes | undefined => defaultTheme\n\n\treturn {\n\t\tsubscribe,\n\t\tgetSnapshot,\n\t\tgetServerSnapshot,\n\t\tsetTheme: (theme: keyof Themes) => composedStore.write(themeEntry(themes, theme))\n\t}\n}\n\nconst channelsByStores = new WeakMap<\n\tobject,\n\tMap<string | undefined, ReturnType<typeof createSharedChannel<any>>>\n>()\n\n/**\n * Returns a cached shared channel for the given themes, stores, and defaultTheme.\n * Channels are keyed by stores (WeakMap) and defaultTheme to avoid duplicate subscriptions.\n *\n * @internal\n */\nfunction getOrCreateChannel<\n\tThemes extends ThemeMap,\n\tA extends ThemeStoreFactory<Themes> = never,\n\tB extends ThemeStoreFactory<Themes> = never,\n\tC extends ThemeStoreFactory<Themes> = never,\n\tD extends ThemeStoreFactory<Themes> = never,\n\tE extends ThemeStoreFactory<Themes> = never,\n\tF extends ThemeStoreFactory<Themes> = never,\n\tG extends ThemeStoreFactory<Themes> = never,\n\tH extends ThemeStoreFactory<Themes> = never\n>(\n\tthemes: Themes,\n\tstores: readonly [\n\t\tstore1: ComposeThemeStoreEntry<Themes, A>,\n\t\tstore2?: ComposeThemeStoreEntry<Themes, B>,\n\t\tstore3?: ComposeThemeStoreEntry<Themes, C>,\n\t\tstore4?: ComposeThemeStoreEntry<Themes, D>,\n\t\tstore5?: ComposeThemeStoreEntry<Themes, E>,\n\t\tstore6?: ComposeThemeStoreEntry<Themes, F>,\n\t\tstore7?: ComposeThemeStoreEntry<Themes, G>,\n\t\tstore8?: ComposeThemeStoreEntry<Themes, H>\n\t],\n\toptions?: ComposeThemeStoresOptions<Themes> | undefined\n) {\n\tconst { defaultTheme } = options ?? {}\n\tconst storesKey = stores as unknown as object\n\tlet byDefault = channelsByStores.get(storesKey) as Map<\n\t\tkeyof Themes | undefined,\n\t\tReturnType<typeof createSharedChannel<Themes>>\n\t>\n\tif (!byDefault) {\n\t\tbyDefault = new Map<keyof Themes | undefined, ReturnType<typeof createSharedChannel<Themes>>>()\n\t\tchannelsByStores.set(storesKey, byDefault as any)\n\t}\n\tlet channel = byDefault.get(defaultTheme) as ReturnType<typeof createSharedChannel<Themes>>\n\tif (!channel) {\n\t\tconst composedStore = composeThemeStores(themes, stores, { defaultTheme })\n\t\tchannel = createSharedChannel<Themes>(themes, composedStore, defaultTheme)\n\t\tbyDefault.set(defaultTheme, channel)\n\t}\n\treturn channel\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAgCA,SAAgB,gBAWf,QACA,QAUA,SAG8D;CAC9D,MAAM,EAAE,iBAAiB,WAAW,EAAE;AACtC,QAAO,SAAS,SAAS,sBAAiD;EAEzE,MAAM,UAAU,mBAAmD,QAAQ,QAAQ,EAClF,cAFwB,wBAAwB,cAGhD,CAAC;AAeF,SAAO,CAbO,qBACb,QAAQ,WACR,QAAQ,aACR,QAAQ,kBACR,EAEgB,YAChB,OAAO,aAA2B;AACjC,SAAM,QAAQ,SAAS,SAAS;KAEjC,CAAC,QAAQ,CACT,CAEuB;;;;;;;;;AAU1B,SAAS,oBACR,QACA,eACA,cACC;CACD,IAAIA,YAAsC;CAC1C,MAAM,4BAAY,IAAI,KAAgD;CAEtE,MAAM,UAAU,UAAoC;AACnD,cAAY;AACZ,OAAK,MAAM,MAAM,UAChB,IAAG,MAAM;;CAIX,MAAM,qBAAqB,UAA0C;AACpE,SAAO,OAAO,SAAS,aAAa;;AAIrC,CAAK,QAAQ,QAAQ,cAAc,MAAM,CAAC,CAAC,MAAM,UAA0C;AAC1F,SAAO,OAAO,SAAS,aAAa;GACnC;CAEF,IAAIC,YAAwB,cAAc,UAAU,kBAAkB;CACtE,IAAI,sBAAsB;CAE1B,MAAM,aAAa,aAAwD;AAC1E,MAAI,CAAC,qBAAqB;AACzB,eAAY,cAAc,UAAU,kBAAkB;AACtD,yBAAsB;;AAEvB,YAAU,IAAI,SAAS;AACvB,WAAS,UAAU;AACnB,eAAa;AACZ,aAAU,OAAO,SAAS;AAC1B,OAAI,UAAU,SAAS,GAAG;AACzB,eAAW;AACX,0BAAsB;;;;CAKzB,MAAM,oBAA8C;CACpD,MAAM,0BAAoD;AAE1D,QAAO;EACN;EACA;EACA;EACA,WAAW,UAAwB,cAAc,MAAM,WAAW,QAAQ,MAAM,CAAC;EACjF;;AAGF,MAAM,mCAAmB,IAAI,SAG1B;;;;;;;AAQH,SAAS,mBAWR,QACA,QAUA,SACC;CACD,MAAM,EAAE,iBAAiB,WAAW,EAAE;CACtC,MAAM,YAAY;CAClB,IAAI,YAAY,iBAAiB,IAAI,UAAU;AAI/C,KAAI,CAAC,WAAW;AACf,8BAAY,IAAI,KAA+E;AAC/F,mBAAiB,IAAI,WAAW,UAAiB;;CAElD,IAAI,UAAU,UAAU,IAAI,aAAa;AACzC,KAAI,CAAC,SAAS;AAEb,YAAU,oBAA4B,QADhB,mBAAmB,QAAQ,QAAQ,EAAE,cAAc,CAAC,EACb,aAAa;AAC1E,YAAU,IAAI,cAAc,QAAQ;;AAErC,QAAO"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_resolve_theme_map_value = require('./resolve-theme-map-value.cjs');
|
|
3
|
+
let type_plus = require("type-plus");
|
|
4
|
+
|
|
5
|
+
//#region src/theme/_utils/match-attribute-value-to-theme.ts
|
|
6
|
+
/**
|
|
7
|
+
* Matches an attribute value string against the theme map and returns the theme key.
|
|
8
|
+
* Pure function: no DOM access. Used by parseDataAttribute and custom parse paths.
|
|
9
|
+
*
|
|
10
|
+
* @param themes - Record mapping theme keys to attribute values
|
|
11
|
+
* @param attrValue - Attribute value string (e.g. from getAttribute)
|
|
12
|
+
* @param options.separator - When defined, split by separator and use first token
|
|
13
|
+
* @returns Theme key if a match is found, otherwise undefined
|
|
14
|
+
*/
|
|
15
|
+
function matchAttributeValueToTheme(themes, attrValue, options) {
|
|
16
|
+
if (attrValue === null || attrValue === "") return void 0;
|
|
17
|
+
const valueToMatch = options?.separator !== void 0 ? attrValue.trim().split(options.separator).find((s) => s.trim() !== "") : attrValue;
|
|
18
|
+
if (valueToMatch === void 0) return void 0;
|
|
19
|
+
return (0, type_plus.findKey)(themes, (key) => {
|
|
20
|
+
const value = themes[key];
|
|
21
|
+
if (value === void 0) return false;
|
|
22
|
+
const resolved = require_resolve_theme_map_value.resolveThemeMapValue(value);
|
|
23
|
+
return (Array.isArray(resolved) ? resolved[0] : resolved) === valueToMatch;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
exports.matchAttributeValueToTheme = matchAttributeValueToTheme;
|
|
29
|
+
//# sourceMappingURL=match-attribute-value-to-theme.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match-attribute-value-to-theme.cjs","names":["resolveThemeMapValue"],"sources":["../../../src/theme/_utils/match-attribute-value-to-theme.ts"],"sourcesContent":["import { findKey } from 'type-plus'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport { resolveThemeMapValue } from './resolve-theme-map-value.ts'\n\n/**\n * Matches an attribute value string against the theme map and returns the theme key.\n * Pure function: no DOM access. Used by parseDataAttribute and custom parse paths.\n *\n * @param themes - Record mapping theme keys to attribute values\n * @param attrValue - Attribute value string (e.g. from getAttribute)\n * @param options.separator - When defined, split by separator and use first token\n * @returns Theme key if a match is found, otherwise undefined\n */\nexport function matchAttributeValueToTheme<Theme extends string>(\n\tthemes: ThemeMap<Theme>,\n\tattrValue: string | null,\n\toptions?: { separator?: string | undefined } | undefined\n): Theme | undefined {\n\tif (attrValue === null || attrValue === '') return undefined\n\tconst valueToMatch =\n\t\toptions?.separator !== undefined\n\t\t\t? attrValue\n\t\t\t\t\t.trim()\n\t\t\t\t\t.split(options.separator)\n\t\t\t\t\t.find((s) => s.trim() !== '')\n\t\t\t: attrValue\n\tif (valueToMatch === undefined) return undefined\n\tconst theme = findKey(themes, (key) => {\n\t\tconst value = themes[key]\n\t\tif (value === undefined) return false\n\t\tconst resolved = resolveThemeMapValue(value)\n\t\tconst v = Array.isArray(resolved) ? resolved[0] : resolved\n\t\treturn v === valueToMatch\n\t})\n\treturn theme\n}\n"],"mappings":";;;;;;;;;;;;;;AAaA,SAAgB,2BACf,QACA,WACA,SACoB;AACpB,KAAI,cAAc,QAAQ,cAAc,GAAI,QAAO;CACnD,MAAM,eACL,SAAS,cAAc,SACpB,UACC,MAAM,CACN,MAAM,QAAQ,UAAU,CACxB,MAAM,MAAM,EAAE,MAAM,KAAK,GAAG,GAC7B;AACJ,KAAI,iBAAiB,OAAW,QAAO;AAQvC,+BAPsB,SAAS,QAAQ;EACtC,MAAM,QAAQ,OAAO;AACrB,MAAI,UAAU,OAAW,QAAO;EAChC,MAAM,WAAWA,qDAAqB,MAAM;AAE5C,UADU,MAAM,QAAQ,SAAS,GAAG,SAAS,KAAK,cACrC;GACZ"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { resolveThemeMapValue } from "./resolve-theme-map-value.mjs";
|
|
2
|
+
import { findKey } from "type-plus";
|
|
3
|
+
|
|
4
|
+
//#region src/theme/_utils/match-attribute-value-to-theme.ts
|
|
5
|
+
/**
|
|
6
|
+
* Matches an attribute value string against the theme map and returns the theme key.
|
|
7
|
+
* Pure function: no DOM access. Used by parseDataAttribute and custom parse paths.
|
|
8
|
+
*
|
|
9
|
+
* @param themes - Record mapping theme keys to attribute values
|
|
10
|
+
* @param attrValue - Attribute value string (e.g. from getAttribute)
|
|
11
|
+
* @param options.separator - When defined, split by separator and use first token
|
|
12
|
+
* @returns Theme key if a match is found, otherwise undefined
|
|
13
|
+
*/
|
|
14
|
+
function matchAttributeValueToTheme(themes, attrValue, options) {
|
|
15
|
+
if (attrValue === null || attrValue === "") return void 0;
|
|
16
|
+
const valueToMatch = options?.separator !== void 0 ? attrValue.trim().split(options.separator).find((s) => s.trim() !== "") : attrValue;
|
|
17
|
+
if (valueToMatch === void 0) return void 0;
|
|
18
|
+
return findKey(themes, (key) => {
|
|
19
|
+
const value = themes[key];
|
|
20
|
+
if (value === void 0) return false;
|
|
21
|
+
const resolved = resolveThemeMapValue(value);
|
|
22
|
+
return (Array.isArray(resolved) ? resolved[0] : resolved) === valueToMatch;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { matchAttributeValueToTheme };
|
|
28
|
+
//# sourceMappingURL=match-attribute-value-to-theme.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match-attribute-value-to-theme.mjs","names":[],"sources":["../../../src/theme/_utils/match-attribute-value-to-theme.ts"],"sourcesContent":["import { findKey } from 'type-plus'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport { resolveThemeMapValue } from './resolve-theme-map-value.ts'\n\n/**\n * Matches an attribute value string against the theme map and returns the theme key.\n * Pure function: no DOM access. Used by parseDataAttribute and custom parse paths.\n *\n * @param themes - Record mapping theme keys to attribute values\n * @param attrValue - Attribute value string (e.g. from getAttribute)\n * @param options.separator - When defined, split by separator and use first token\n * @returns Theme key if a match is found, otherwise undefined\n */\nexport function matchAttributeValueToTheme<Theme extends string>(\n\tthemes: ThemeMap<Theme>,\n\tattrValue: string | null,\n\toptions?: { separator?: string | undefined } | undefined\n): Theme | undefined {\n\tif (attrValue === null || attrValue === '') return undefined\n\tconst valueToMatch =\n\t\toptions?.separator !== undefined\n\t\t\t? attrValue\n\t\t\t\t\t.trim()\n\t\t\t\t\t.split(options.separator)\n\t\t\t\t\t.find((s) => s.trim() !== '')\n\t\t\t: attrValue\n\tif (valueToMatch === undefined) return undefined\n\tconst theme = findKey(themes, (key) => {\n\t\tconst value = themes[key]\n\t\tif (value === undefined) return false\n\t\tconst resolved = resolveThemeMapValue(value)\n\t\tconst v = Array.isArray(resolved) ? resolved[0] : resolved\n\t\treturn v === valueToMatch\n\t})\n\treturn theme\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,2BACf,QACA,WACA,SACoB;AACpB,KAAI,cAAc,QAAQ,cAAc,GAAI,QAAO;CACnD,MAAM,eACL,SAAS,cAAc,SACpB,UACC,MAAM,CACN,MAAM,QAAQ,UAAU,CACxB,MAAM,MAAM,EAAE,MAAM,KAAK,GAAG,GAC7B;AACJ,KAAI,iBAAiB,OAAW,QAAO;AAQvC,QAPc,QAAQ,SAAS,QAAQ;EACtC,MAAM,QAAQ,OAAO;AACrB,MAAI,UAAU,OAAW,QAAO;EAChC,MAAM,WAAW,qBAAqB,MAAM;AAE5C,UADU,MAAM,QAAQ,SAAS,GAAG,SAAS,KAAK,cACrC;GACZ"}
|
|
@@ -1,20 +1,74 @@
|
|
|
1
|
+
const require_resolve_theme_map_value = require('./resolve-theme-map-value.cjs');
|
|
1
2
|
const require_try_parse_json = require('../../_internal/utils/try-parse-json.cjs');
|
|
2
3
|
|
|
3
4
|
//#region src/theme/_utils/parse-stored-theme.ts
|
|
5
|
+
function getShapeAndComparable(v) {
|
|
6
|
+
if (typeof v === "string") return {
|
|
7
|
+
shape: "string",
|
|
8
|
+
comparable: v
|
|
9
|
+
};
|
|
10
|
+
if (Array.isArray(v)) return {
|
|
11
|
+
shape: "array",
|
|
12
|
+
comparable: v[0]
|
|
13
|
+
};
|
|
14
|
+
if (v !== null && typeof v === "object" && "themeValue" in v) {
|
|
15
|
+
const tv = v.themeValue;
|
|
16
|
+
if (typeof tv === "string") return {
|
|
17
|
+
shape: "object-string",
|
|
18
|
+
comparable: tv
|
|
19
|
+
};
|
|
20
|
+
if (Array.isArray(tv)) return {
|
|
21
|
+
shape: "object-array",
|
|
22
|
+
comparable: tv[0]
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
function getCanonicalShapeAndComparable(v) {
|
|
28
|
+
if (typeof v === "string") return {
|
|
29
|
+
shape: "string",
|
|
30
|
+
comparable: v
|
|
31
|
+
};
|
|
32
|
+
if (require_resolve_theme_map_value.isReadonlyStringArray(v)) return {
|
|
33
|
+
shape: "array",
|
|
34
|
+
comparable: v[0]
|
|
35
|
+
};
|
|
36
|
+
const tv = v.themeValue;
|
|
37
|
+
if (typeof tv === "string") return {
|
|
38
|
+
shape: "object-string",
|
|
39
|
+
comparable: tv
|
|
40
|
+
};
|
|
41
|
+
return {
|
|
42
|
+
shape: "object-array",
|
|
43
|
+
comparable: tv[0]
|
|
44
|
+
};
|
|
45
|
+
}
|
|
4
46
|
/**
|
|
5
|
-
* Parses stored JSON theme and validates
|
|
47
|
+
* Parses stored JSON theme and validates against theme map with strict shape and comparable matching.
|
|
6
48
|
*
|
|
7
49
|
* Expects stored shape: { theme: string, value?: unknown }
|
|
8
50
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
51
|
+
* When shape matches AND comparable value (string or [0]) matches themes[theme]:
|
|
52
|
+
* returns { theme, value: stored.value }. Else returns undefined.
|
|
53
|
+
*
|
|
54
|
+
* @param themes - Record of valid theme keys and values (required for validation)
|
|
55
|
+
* @param value - Raw string from localStorage/sessionStorage/cookie (accepts null)
|
|
56
|
+
* @returns ThemeEntry when valid, otherwise undefined
|
|
12
57
|
*/
|
|
13
58
|
function parseStoredTheme(themes, value) {
|
|
14
|
-
const parsed = require_try_parse_json.tryParseJSON(value);
|
|
59
|
+
const parsed = require_try_parse_json.tryParseJSON(value ?? null);
|
|
15
60
|
if (!parsed?.theme || typeof parsed.theme !== "string") return void 0;
|
|
16
|
-
if (themes
|
|
17
|
-
|
|
61
|
+
if (!themes || !(parsed.theme in themes)) return void 0;
|
|
62
|
+
if (parsed.value === void 0) return void 0;
|
|
63
|
+
const storedInfo = getShapeAndComparable(parsed.value);
|
|
64
|
+
if (!storedInfo) return void 0;
|
|
65
|
+
const canonical = getCanonicalShapeAndComparable(themes[parsed.theme]);
|
|
66
|
+
if (storedInfo.shape !== canonical.shape) return void 0;
|
|
67
|
+
if (storedInfo.comparable !== canonical.comparable) return void 0;
|
|
68
|
+
return {
|
|
69
|
+
theme: parsed.theme,
|
|
70
|
+
value: parsed.value
|
|
71
|
+
};
|
|
18
72
|
}
|
|
19
73
|
|
|
20
74
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-stored-theme.cjs","names":["tryParseJSON"],"sources":["../../../src/theme/_utils/parse-stored-theme.ts"],"sourcesContent":["import { tryParseJSON } from '../../_internal/utils/try-parse-json.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\n\n/**\n * Parses stored JSON theme and validates
|
|
1
|
+
{"version":3,"file":"parse-stored-theme.cjs","names":["isReadonlyStringArray","tryParseJSON"],"sources":["../../../src/theme/_utils/parse-stored-theme.ts"],"sourcesContent":["import { tryParseJSON } from '../../_internal/utils/try-parse-json.ts'\nimport type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap, ThemeMapValue } from '../theme-map.types.ts'\nimport { isReadonlyStringArray } from './resolve-theme-map-value.ts'\n\ntype Shape = 'string' | 'array' | 'object-string' | 'object-array'\n\nfunction getShapeAndComparable(\n\tv: unknown\n): { shape: Shape; comparable: string | undefined } | null {\n\tif (typeof v === 'string') return { shape: 'string', comparable: v }\n\tif (Array.isArray(v)) return { shape: 'array', comparable: v[0] }\n\tif (v !== null && typeof v === 'object' && 'themeValue' in v) {\n\t\tconst tv = (v as { themeValue: string | string[] }).themeValue\n\t\tif (typeof tv === 'string') return { shape: 'object-string', comparable: tv }\n\t\tif (Array.isArray(tv)) return { shape: 'object-array', comparable: tv[0] }\n\t}\n\treturn null\n}\n\nfunction getCanonicalShapeAndComparable(v: ThemeMapValue): {\n\tshape: Shape\n\tcomparable: string | undefined\n} {\n\tif (typeof v === 'string') return { shape: 'string', comparable: v }\n\tif (isReadonlyStringArray(v)) return { shape: 'array', comparable: v[0] }\n\tconst tv = v.themeValue\n\tif (typeof tv === 'string') return { shape: 'object-string', comparable: tv }\n\treturn { shape: 'object-array', comparable: tv[0] }\n}\n\n/**\n * Parses stored JSON theme and validates against theme map with strict shape and comparable matching.\n *\n * Expects stored shape: { theme: string, value?: unknown }\n *\n * When shape matches AND comparable value (string or [0]) matches themes[theme]:\n * returns { theme, value: stored.value }. Else returns undefined.\n *\n * @param themes - Record of valid theme keys and values (required for validation)\n * @param value - Raw string from localStorage/sessionStorage/cookie (accepts null)\n * @returns ThemeEntry when valid, otherwise undefined\n */\nexport function parseStoredTheme<Themes extends ThemeMap>(\n\tthemes: Themes | undefined,\n\tvalue: string | null | undefined\n): ThemeEntry<Themes> | undefined {\n\tconst parsed = tryParseJSON<{ theme: string; value?: unknown }>(value ?? null)\n\tif (!parsed?.theme || typeof parsed.theme !== 'string') return undefined\n\tif (!themes || !(parsed.theme in themes)) return undefined\n\tif (parsed.value === undefined) return undefined\n\n\tconst storedInfo = getShapeAndComparable(parsed.value)\n\tif (!storedInfo) return undefined\n\n\tconst canonical = getCanonicalShapeAndComparable(themes[parsed.theme] as ThemeMapValue)\n\tif (storedInfo.shape !== canonical.shape) return undefined\n\tif (storedInfo.comparable !== canonical.comparable) return undefined\n\n\treturn { theme: parsed.theme as keyof Themes, value: parsed.value as Themes[keyof Themes] }\n}\n"],"mappings":";;;;AAOA,SAAS,sBACR,GAC0D;AAC1D,KAAI,OAAO,MAAM,SAAU,QAAO;EAAE,OAAO;EAAU,YAAY;EAAG;AACpE,KAAI,MAAM,QAAQ,EAAE,CAAE,QAAO;EAAE,OAAO;EAAS,YAAY,EAAE;EAAI;AACjE,KAAI,MAAM,QAAQ,OAAO,MAAM,YAAY,gBAAgB,GAAG;EAC7D,MAAM,KAAM,EAAwC;AACpD,MAAI,OAAO,OAAO,SAAU,QAAO;GAAE,OAAO;GAAiB,YAAY;GAAI;AAC7E,MAAI,MAAM,QAAQ,GAAG,CAAE,QAAO;GAAE,OAAO;GAAgB,YAAY,GAAG;GAAI;;AAE3E,QAAO;;AAGR,SAAS,+BAA+B,GAGtC;AACD,KAAI,OAAO,MAAM,SAAU,QAAO;EAAE,OAAO;EAAU,YAAY;EAAG;AACpE,KAAIA,sDAAsB,EAAE,CAAE,QAAO;EAAE,OAAO;EAAS,YAAY,EAAE;EAAI;CACzE,MAAM,KAAK,EAAE;AACb,KAAI,OAAO,OAAO,SAAU,QAAO;EAAE,OAAO;EAAiB,YAAY;EAAI;AAC7E,QAAO;EAAE,OAAO;EAAgB,YAAY,GAAG;EAAI;;;;;;;;;;;;;;AAepD,SAAgB,iBACf,QACA,OACiC;CACjC,MAAM,SAASC,oCAAiD,SAAS,KAAK;AAC9E,KAAI,CAAC,QAAQ,SAAS,OAAO,OAAO,UAAU,SAAU,QAAO;AAC/D,KAAI,CAAC,UAAU,EAAE,OAAO,SAAS,QAAS,QAAO;AACjD,KAAI,OAAO,UAAU,OAAW,QAAO;CAEvC,MAAM,aAAa,sBAAsB,OAAO,MAAM;AACtD,KAAI,CAAC,WAAY,QAAO;CAExB,MAAM,YAAY,+BAA+B,OAAO,OAAO,OAAwB;AACvF,KAAI,WAAW,UAAU,UAAU,MAAO,QAAO;AACjD,KAAI,WAAW,eAAe,UAAU,WAAY,QAAO;AAE3D,QAAO;EAAE,OAAO,OAAO;EAAuB,OAAO,OAAO;EAA+B"}
|
|
@@ -1,20 +1,74 @@
|
|
|
1
|
+
import { isReadonlyStringArray } from "./resolve-theme-map-value.mjs";
|
|
1
2
|
import { tryParseJSON } from "../../_internal/utils/try-parse-json.mjs";
|
|
2
3
|
|
|
3
4
|
//#region src/theme/_utils/parse-stored-theme.ts
|
|
5
|
+
function getShapeAndComparable(v) {
|
|
6
|
+
if (typeof v === "string") return {
|
|
7
|
+
shape: "string",
|
|
8
|
+
comparable: v
|
|
9
|
+
};
|
|
10
|
+
if (Array.isArray(v)) return {
|
|
11
|
+
shape: "array",
|
|
12
|
+
comparable: v[0]
|
|
13
|
+
};
|
|
14
|
+
if (v !== null && typeof v === "object" && "themeValue" in v) {
|
|
15
|
+
const tv = v.themeValue;
|
|
16
|
+
if (typeof tv === "string") return {
|
|
17
|
+
shape: "object-string",
|
|
18
|
+
comparable: tv
|
|
19
|
+
};
|
|
20
|
+
if (Array.isArray(tv)) return {
|
|
21
|
+
shape: "object-array",
|
|
22
|
+
comparable: tv[0]
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
function getCanonicalShapeAndComparable(v) {
|
|
28
|
+
if (typeof v === "string") return {
|
|
29
|
+
shape: "string",
|
|
30
|
+
comparable: v
|
|
31
|
+
};
|
|
32
|
+
if (isReadonlyStringArray(v)) return {
|
|
33
|
+
shape: "array",
|
|
34
|
+
comparable: v[0]
|
|
35
|
+
};
|
|
36
|
+
const tv = v.themeValue;
|
|
37
|
+
if (typeof tv === "string") return {
|
|
38
|
+
shape: "object-string",
|
|
39
|
+
comparable: tv
|
|
40
|
+
};
|
|
41
|
+
return {
|
|
42
|
+
shape: "object-array",
|
|
43
|
+
comparable: tv[0]
|
|
44
|
+
};
|
|
45
|
+
}
|
|
4
46
|
/**
|
|
5
|
-
* Parses stored JSON theme and validates
|
|
47
|
+
* Parses stored JSON theme and validates against theme map with strict shape and comparable matching.
|
|
6
48
|
*
|
|
7
49
|
* Expects stored shape: { theme: string, value?: unknown }
|
|
8
50
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
51
|
+
* When shape matches AND comparable value (string or [0]) matches themes[theme]:
|
|
52
|
+
* returns { theme, value: stored.value }. Else returns undefined.
|
|
53
|
+
*
|
|
54
|
+
* @param themes - Record of valid theme keys and values (required for validation)
|
|
55
|
+
* @param value - Raw string from localStorage/sessionStorage/cookie (accepts null)
|
|
56
|
+
* @returns ThemeEntry when valid, otherwise undefined
|
|
12
57
|
*/
|
|
13
58
|
function parseStoredTheme(themes, value) {
|
|
14
|
-
const parsed = tryParseJSON(value);
|
|
59
|
+
const parsed = tryParseJSON(value ?? null);
|
|
15
60
|
if (!parsed?.theme || typeof parsed.theme !== "string") return void 0;
|
|
16
|
-
if (themes
|
|
17
|
-
|
|
61
|
+
if (!themes || !(parsed.theme in themes)) return void 0;
|
|
62
|
+
if (parsed.value === void 0) return void 0;
|
|
63
|
+
const storedInfo = getShapeAndComparable(parsed.value);
|
|
64
|
+
if (!storedInfo) return void 0;
|
|
65
|
+
const canonical = getCanonicalShapeAndComparable(themes[parsed.theme]);
|
|
66
|
+
if (storedInfo.shape !== canonical.shape) return void 0;
|
|
67
|
+
if (storedInfo.comparable !== canonical.comparable) return void 0;
|
|
68
|
+
return {
|
|
69
|
+
theme: parsed.theme,
|
|
70
|
+
value: parsed.value
|
|
71
|
+
};
|
|
18
72
|
}
|
|
19
73
|
|
|
20
74
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-stored-theme.mjs","names":[],"sources":["../../../src/theme/_utils/parse-stored-theme.ts"],"sourcesContent":["import { tryParseJSON } from '../../_internal/utils/try-parse-json.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\n\n/**\n * Parses stored JSON theme and validates
|
|
1
|
+
{"version":3,"file":"parse-stored-theme.mjs","names":[],"sources":["../../../src/theme/_utils/parse-stored-theme.ts"],"sourcesContent":["import { tryParseJSON } from '../../_internal/utils/try-parse-json.ts'\nimport type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap, ThemeMapValue } from '../theme-map.types.ts'\nimport { isReadonlyStringArray } from './resolve-theme-map-value.ts'\n\ntype Shape = 'string' | 'array' | 'object-string' | 'object-array'\n\nfunction getShapeAndComparable(\n\tv: unknown\n): { shape: Shape; comparable: string | undefined } | null {\n\tif (typeof v === 'string') return { shape: 'string', comparable: v }\n\tif (Array.isArray(v)) return { shape: 'array', comparable: v[0] }\n\tif (v !== null && typeof v === 'object' && 'themeValue' in v) {\n\t\tconst tv = (v as { themeValue: string | string[] }).themeValue\n\t\tif (typeof tv === 'string') return { shape: 'object-string', comparable: tv }\n\t\tif (Array.isArray(tv)) return { shape: 'object-array', comparable: tv[0] }\n\t}\n\treturn null\n}\n\nfunction getCanonicalShapeAndComparable(v: ThemeMapValue): {\n\tshape: Shape\n\tcomparable: string | undefined\n} {\n\tif (typeof v === 'string') return { shape: 'string', comparable: v }\n\tif (isReadonlyStringArray(v)) return { shape: 'array', comparable: v[0] }\n\tconst tv = v.themeValue\n\tif (typeof tv === 'string') return { shape: 'object-string', comparable: tv }\n\treturn { shape: 'object-array', comparable: tv[0] }\n}\n\n/**\n * Parses stored JSON theme and validates against theme map with strict shape and comparable matching.\n *\n * Expects stored shape: { theme: string, value?: unknown }\n *\n * When shape matches AND comparable value (string or [0]) matches themes[theme]:\n * returns { theme, value: stored.value }. Else returns undefined.\n *\n * @param themes - Record of valid theme keys and values (required for validation)\n * @param value - Raw string from localStorage/sessionStorage/cookie (accepts null)\n * @returns ThemeEntry when valid, otherwise undefined\n */\nexport function parseStoredTheme<Themes extends ThemeMap>(\n\tthemes: Themes | undefined,\n\tvalue: string | null | undefined\n): ThemeEntry<Themes> | undefined {\n\tconst parsed = tryParseJSON<{ theme: string; value?: unknown }>(value ?? null)\n\tif (!parsed?.theme || typeof parsed.theme !== 'string') return undefined\n\tif (!themes || !(parsed.theme in themes)) return undefined\n\tif (parsed.value === undefined) return undefined\n\n\tconst storedInfo = getShapeAndComparable(parsed.value)\n\tif (!storedInfo) return undefined\n\n\tconst canonical = getCanonicalShapeAndComparable(themes[parsed.theme] as ThemeMapValue)\n\tif (storedInfo.shape !== canonical.shape) return undefined\n\tif (storedInfo.comparable !== canonical.comparable) return undefined\n\n\treturn { theme: parsed.theme as keyof Themes, value: parsed.value as Themes[keyof Themes] }\n}\n"],"mappings":";;;;AAOA,SAAS,sBACR,GAC0D;AAC1D,KAAI,OAAO,MAAM,SAAU,QAAO;EAAE,OAAO;EAAU,YAAY;EAAG;AACpE,KAAI,MAAM,QAAQ,EAAE,CAAE,QAAO;EAAE,OAAO;EAAS,YAAY,EAAE;EAAI;AACjE,KAAI,MAAM,QAAQ,OAAO,MAAM,YAAY,gBAAgB,GAAG;EAC7D,MAAM,KAAM,EAAwC;AACpD,MAAI,OAAO,OAAO,SAAU,QAAO;GAAE,OAAO;GAAiB,YAAY;GAAI;AAC7E,MAAI,MAAM,QAAQ,GAAG,CAAE,QAAO;GAAE,OAAO;GAAgB,YAAY,GAAG;GAAI;;AAE3E,QAAO;;AAGR,SAAS,+BAA+B,GAGtC;AACD,KAAI,OAAO,MAAM,SAAU,QAAO;EAAE,OAAO;EAAU,YAAY;EAAG;AACpE,KAAI,sBAAsB,EAAE,CAAE,QAAO;EAAE,OAAO;EAAS,YAAY,EAAE;EAAI;CACzE,MAAM,KAAK,EAAE;AACb,KAAI,OAAO,OAAO,SAAU,QAAO;EAAE,OAAO;EAAiB,YAAY;EAAI;AAC7E,QAAO;EAAE,OAAO;EAAgB,YAAY,GAAG;EAAI;;;;;;;;;;;;;;AAepD,SAAgB,iBACf,QACA,OACiC;CACjC,MAAM,SAAS,aAAiD,SAAS,KAAK;AAC9E,KAAI,CAAC,QAAQ,SAAS,OAAO,OAAO,UAAU,SAAU,QAAO;AAC/D,KAAI,CAAC,UAAU,EAAE,OAAO,SAAS,QAAS,QAAO;AACjD,KAAI,OAAO,UAAU,OAAW,QAAO;CAEvC,MAAM,aAAa,sBAAsB,OAAO,MAAM;AACtD,KAAI,CAAC,WAAY,QAAO;CAExB,MAAM,YAAY,+BAA+B,OAAO,OAAO,OAAwB;AACvF,KAAI,WAAW,UAAU,UAAU,MAAO,QAAO;AACjD,KAAI,WAAW,eAAe,UAAU,WAAY,QAAO;AAE3D,QAAO;EAAE,OAAO,OAAO;EAAuB,OAAO,OAAO;EAA+B"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/theme/_utils/resolve-theme-map-value.ts
|
|
3
|
+
function isReadonlyStringArray(v) {
|
|
4
|
+
return Array.isArray(v);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Resolves ThemeMapValue to its underlying string or string[] for DOM application and matching.
|
|
8
|
+
* Used when applying themes to className, data attributes, or when resolving theme from DOM.
|
|
9
|
+
*/
|
|
10
|
+
function resolveThemeMapValue(v) {
|
|
11
|
+
if (typeof v === "string") return v;
|
|
12
|
+
if (isReadonlyStringArray(v)) return v;
|
|
13
|
+
return v.themeValue;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
exports.isReadonlyStringArray = isReadonlyStringArray;
|
|
18
|
+
exports.resolveThemeMapValue = resolveThemeMapValue;
|
|
19
|
+
//# sourceMappingURL=resolve-theme-map-value.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-theme-map-value.cjs","names":[],"sources":["../../../src/theme/_utils/resolve-theme-map-value.ts"],"sourcesContent":["import type { ThemeMapValue } from '../theme-map.types.ts'\n\nexport function isReadonlyStringArray(v: ThemeMapValue): v is readonly string[] {\n\treturn Array.isArray(v)\n}\n\n/**\n * Resolves ThemeMapValue to its underlying string or string[] for DOM application and matching.\n * Used when applying themes to className, data attributes, or when resolving theme from DOM.\n */\nexport function resolveThemeMapValue(v: ThemeMapValue): string | readonly string[] {\n\tif (typeof v === 'string') return v\n\tif (isReadonlyStringArray(v)) return v\n\treturn v.themeValue\n}\n"],"mappings":";;AAEA,SAAgB,sBAAsB,GAA0C;AAC/E,QAAO,MAAM,QAAQ,EAAE;;;;;;AAOxB,SAAgB,qBAAqB,GAA8C;AAClF,KAAI,OAAO,MAAM,SAAU,QAAO;AAClC,KAAI,sBAAsB,EAAE,CAAE,QAAO;AACrC,QAAO,EAAE"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/theme/_utils/resolve-theme-map-value.ts
|
|
2
|
+
function isReadonlyStringArray(v) {
|
|
3
|
+
return Array.isArray(v);
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Resolves ThemeMapValue to its underlying string or string[] for DOM application and matching.
|
|
7
|
+
* Used when applying themes to className, data attributes, or when resolving theme from DOM.
|
|
8
|
+
*/
|
|
9
|
+
function resolveThemeMapValue(v) {
|
|
10
|
+
if (typeof v === "string") return v;
|
|
11
|
+
if (isReadonlyStringArray(v)) return v;
|
|
12
|
+
return v.themeValue;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { isReadonlyStringArray, resolveThemeMapValue };
|
|
17
|
+
//# sourceMappingURL=resolve-theme-map-value.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-theme-map-value.mjs","names":[],"sources":["../../../src/theme/_utils/resolve-theme-map-value.ts"],"sourcesContent":["import type { ThemeMapValue } from '../theme-map.types.ts'\n\nexport function isReadonlyStringArray(v: ThemeMapValue): v is readonly string[] {\n\treturn Array.isArray(v)\n}\n\n/**\n * Resolves ThemeMapValue to its underlying string or string[] for DOM application and matching.\n * Used when applying themes to className, data attributes, or when resolving theme from DOM.\n */\nexport function resolveThemeMapValue(v: ThemeMapValue): string | readonly string[] {\n\tif (typeof v === 'string') return v\n\tif (isReadonlyStringArray(v)) return v\n\treturn v.themeValue\n}\n"],"mappings":";AAEA,SAAgB,sBAAsB,GAA0C;AAC/E,QAAO,MAAM,QAAQ,EAAE;;;;;;AAOxB,SAAgB,qBAAqB,GAA8C;AAClF,KAAI,OAAO,MAAM,SAAU,QAAO;AAClC,KAAI,sBAAsB,EAAE,CAAE,QAAO;AACrC,QAAO,EAAE"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Writes theme entry to all stores that have a write method.
|
|
5
5
|
*
|
|
6
6
|
* @param stores - Array of theme stores
|
|
7
|
-
* @param entry - Theme entry to write, or undefined to clear
|
|
7
|
+
* @param entry - Theme entry to write, or null/undefined to clear
|
|
8
8
|
*/
|
|
9
9
|
async function setThemeToStores(stores, entry) {
|
|
10
10
|
const withWrite = stores.filter((s) => typeof s.write === "function");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"set-theme-to-stores.cjs","names":[],"sources":["../../../src/theme/_utils/set-theme-to-stores.ts"],"sourcesContent":["import type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport type { AsyncThemeStore } from '../theme-store/async-theme-store.types.ts'\nimport type { ThemeStore } from '../theme-store/theme-store.types.ts'\n\ntype StoreWithWrite<Themes extends ThemeMap> = (ThemeStore<Themes> | AsyncThemeStore<Themes>) & {\n\twrite: (entry: ThemeEntry<Themes> | undefined) => void | Promise<void>\n}\n\n/**\n * Writes theme entry to all stores that have a write method.\n *\n * @param stores - Array of theme stores\n * @param entry - Theme entry to write, or undefined to clear\n */\nexport async function setThemeToStores<Themes extends ThemeMap>(\n\tstores: (ThemeStore<Themes> | AsyncThemeStore<Themes>)[],\n\tentry: ThemeEntry<Themes> | undefined\n): Promise<void> {\n\tconst withWrite = stores.filter((s): s is StoreWithWrite<Themes> => typeof s.write === 'function')\n\n\tawait Promise.all(withWrite.map((store) => Promise.resolve(store.write!(entry))))\n}\n"],"mappings":";;;;;;;;AAeA,eAAsB,iBACrB,QACA,OACgB;CAChB,MAAM,YAAY,OAAO,QAAQ,MAAmC,OAAO,EAAE,UAAU,WAAW;AAElG,OAAM,QAAQ,IAAI,UAAU,KAAK,UAAU,QAAQ,QAAQ,MAAM,MAAO,MAAM,CAAC,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"set-theme-to-stores.cjs","names":[],"sources":["../../../src/theme/_utils/set-theme-to-stores.ts"],"sourcesContent":["import type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport type { AsyncThemeStore } from '../theme-store/async-theme-store.types.ts'\nimport type { ThemeStore } from '../theme-store/theme-store.types.ts'\n\ntype StoreWithWrite<Themes extends ThemeMap> = (ThemeStore<Themes> | AsyncThemeStore<Themes>) & {\n\twrite: (entry: ThemeEntry<Themes> | null | undefined) => void | Promise<void>\n}\n\n/**\n * Writes theme entry to all stores that have a write method.\n *\n * @param stores - Array of theme stores\n * @param entry - Theme entry to write, or null/undefined to clear\n */\nexport async function setThemeToStores<Themes extends ThemeMap>(\n\tstores: (ThemeStore<Themes> | AsyncThemeStore<Themes>)[],\n\tentry: ThemeEntry<Themes> | null | undefined\n): Promise<void> {\n\tconst withWrite = stores.filter((s): s is StoreWithWrite<Themes> => typeof s.write === 'function')\n\n\tawait Promise.all(withWrite.map((store) => Promise.resolve(store.write!(entry))))\n}\n"],"mappings":";;;;;;;;AAeA,eAAsB,iBACrB,QACA,OACgB;CAChB,MAAM,YAAY,OAAO,QAAQ,MAAmC,OAAO,EAAE,UAAU,WAAW;AAElG,OAAM,QAAQ,IAAI,UAAU,KAAK,UAAU,QAAQ,QAAQ,MAAM,MAAO,MAAM,CAAC,CAAC,CAAC"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Writes theme entry to all stores that have a write method.
|
|
4
4
|
*
|
|
5
5
|
* @param stores - Array of theme stores
|
|
6
|
-
* @param entry - Theme entry to write, or undefined to clear
|
|
6
|
+
* @param entry - Theme entry to write, or null/undefined to clear
|
|
7
7
|
*/
|
|
8
8
|
async function setThemeToStores(stores, entry) {
|
|
9
9
|
const withWrite = stores.filter((s) => typeof s.write === "function");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"set-theme-to-stores.mjs","names":[],"sources":["../../../src/theme/_utils/set-theme-to-stores.ts"],"sourcesContent":["import type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport type { AsyncThemeStore } from '../theme-store/async-theme-store.types.ts'\nimport type { ThemeStore } from '../theme-store/theme-store.types.ts'\n\ntype StoreWithWrite<Themes extends ThemeMap> = (ThemeStore<Themes> | AsyncThemeStore<Themes>) & {\n\twrite: (entry: ThemeEntry<Themes> | undefined) => void | Promise<void>\n}\n\n/**\n * Writes theme entry to all stores that have a write method.\n *\n * @param stores - Array of theme stores\n * @param entry - Theme entry to write, or undefined to clear\n */\nexport async function setThemeToStores<Themes extends ThemeMap>(\n\tstores: (ThemeStore<Themes> | AsyncThemeStore<Themes>)[],\n\tentry: ThemeEntry<Themes> | undefined\n): Promise<void> {\n\tconst withWrite = stores.filter((s): s is StoreWithWrite<Themes> => typeof s.write === 'function')\n\n\tawait Promise.all(withWrite.map((store) => Promise.resolve(store.write!(entry))))\n}\n"],"mappings":";;;;;;;AAeA,eAAsB,iBACrB,QACA,OACgB;CAChB,MAAM,YAAY,OAAO,QAAQ,MAAmC,OAAO,EAAE,UAAU,WAAW;AAElG,OAAM,QAAQ,IAAI,UAAU,KAAK,UAAU,QAAQ,QAAQ,MAAM,MAAO,MAAM,CAAC,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"set-theme-to-stores.mjs","names":[],"sources":["../../../src/theme/_utils/set-theme-to-stores.ts"],"sourcesContent":["import type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport type { AsyncThemeStore } from '../theme-store/async-theme-store.types.ts'\nimport type { ThemeStore } from '../theme-store/theme-store.types.ts'\n\ntype StoreWithWrite<Themes extends ThemeMap> = (ThemeStore<Themes> | AsyncThemeStore<Themes>) & {\n\twrite: (entry: ThemeEntry<Themes> | null | undefined) => void | Promise<void>\n}\n\n/**\n * Writes theme entry to all stores that have a write method.\n *\n * @param stores - Array of theme stores\n * @param entry - Theme entry to write, or null/undefined to clear\n */\nexport async function setThemeToStores<Themes extends ThemeMap>(\n\tstores: (ThemeStore<Themes> | AsyncThemeStore<Themes>)[],\n\tentry: ThemeEntry<Themes> | null | undefined\n): Promise<void> {\n\tconst withWrite = stores.filter((s): s is StoreWithWrite<Themes> => typeof s.write === 'function')\n\n\tawait Promise.all(withWrite.map((store) => Promise.resolve(store.write!(entry))))\n}\n"],"mappings":";;;;;;;AAeA,eAAsB,iBACrB,QACA,OACgB;CAChB,MAAM,YAAY,OAAO,QAAQ,MAAmC,OAAO,EAAE,UAAU,WAAW;AAElG,OAAM,QAAQ,IAAI,UAAU,KAAK,UAAU,QAAQ,QAAQ,MAAM,MAAO,MAAM,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_theme_entry = require('../theme-entry.cjs');
|
|
3
|
+
const require_resolve_theme_map_value = require('../_utils/resolve-theme-map-value.cjs');
|
|
4
|
+
let type_plus = require("type-plus");
|
|
5
|
+
|
|
6
|
+
//#region src/theme/class-name/parse-class-name.ts
|
|
7
|
+
/**
|
|
8
|
+
* Parses a class name string into a ThemeEntry.
|
|
9
|
+
*
|
|
10
|
+
* Pure function: no DOM access. Matches class strings by checking if any theme
|
|
11
|
+
* class is included in the className (e.g. `className.includes(themeClass)`).
|
|
12
|
+
* Arrays in theme map use first value for matching.
|
|
13
|
+
*
|
|
14
|
+
* @param themes - Record mapping theme keys to class name(s)
|
|
15
|
+
* @param className - Raw class attribute value (e.g. from element.className; accepts null)
|
|
16
|
+
* @returns ThemeEntry if a match is found, otherwise undefined
|
|
17
|
+
*/
|
|
18
|
+
function parseClassName(themes, className) {
|
|
19
|
+
const cls = className ?? "";
|
|
20
|
+
const theme = (0, type_plus.findKey)(themes, (key) => {
|
|
21
|
+
const value = themes[key];
|
|
22
|
+
if (value === void 0) return false;
|
|
23
|
+
const resolved = require_resolve_theme_map_value.resolveThemeMapValue(value);
|
|
24
|
+
const v = Array.isArray(resolved) ? resolved[0] : resolved;
|
|
25
|
+
return !!v && cls.includes(v);
|
|
26
|
+
});
|
|
27
|
+
return theme !== void 0 ? require_theme_entry.themeEntry(themes, theme) : void 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
exports.parseClassName = parseClassName;
|
|
32
|
+
//# sourceMappingURL=parse-class-name.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-class-name.cjs","names":["resolveThemeMapValue","themeEntry"],"sources":["../../../src/theme/class-name/parse-class-name.ts"],"sourcesContent":["import { findKey } from 'type-plus'\nimport { resolveThemeMapValue } from '../_utils/resolve-theme-map-value.ts'\nimport { themeEntry } from '../theme-entry.ts'\nimport type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\n\n/**\n * Parses a class name string into a ThemeEntry.\n *\n * Pure function: no DOM access. Matches class strings by checking if any theme\n * class is included in the className (e.g. `className.includes(themeClass)`).\n * Arrays in theme map use first value for matching.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param className - Raw class attribute value (e.g. from element.className; accepts null)\n * @returns ThemeEntry if a match is found, otherwise undefined\n */\nexport function parseClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\tclassName: string | null | undefined\n): ThemeEntry<Themes> | undefined {\n\tconst cls = className ?? ''\n\tconst theme = findKey(themes, (key) => {\n\t\tconst value = themes[key]\n\t\tif (value === undefined) return false\n\t\tconst resolved = resolveThemeMapValue(value)\n\t\tconst v = Array.isArray(resolved) ? resolved[0] : resolved\n\t\treturn !!v && cls.includes(v)\n\t})\n\treturn theme !== undefined ? themeEntry(themes, theme) : undefined\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,SAAgB,eACf,QACA,WACiC;CACjC,MAAM,MAAM,aAAa;CACzB,MAAM,+BAAgB,SAAS,QAAQ;EACtC,MAAM,QAAQ,OAAO;AACrB,MAAI,UAAU,OAAW,QAAO;EAChC,MAAM,WAAWA,qDAAqB,MAAM;EAC5C,MAAM,IAAI,MAAM,QAAQ,SAAS,GAAG,SAAS,KAAK;AAClD,SAAO,CAAC,CAAC,KAAK,IAAI,SAAS,EAAE;GAC5B;AACF,QAAO,UAAU,SAAYC,+BAAW,QAAQ,MAAM,GAAG"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ThemeMap } from "../theme-map.types.cjs";
|
|
2
|
+
import { ThemeEntry } from "../theme-entry.types.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/theme/class-name/parse-class-name.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Parses a class name string into a ThemeEntry.
|
|
8
|
+
*
|
|
9
|
+
* Pure function: no DOM access. Matches class strings by checking if any theme
|
|
10
|
+
* class is included in the className (e.g. `className.includes(themeClass)`).
|
|
11
|
+
* Arrays in theme map use first value for matching.
|
|
12
|
+
*
|
|
13
|
+
* @param themes - Record mapping theme keys to class name(s)
|
|
14
|
+
* @param className - Raw class attribute value (e.g. from element.className; accepts null)
|
|
15
|
+
* @returns ThemeEntry if a match is found, otherwise undefined
|
|
16
|
+
*/
|
|
17
|
+
declare function parseClassName<Themes extends ThemeMap>(themes: Themes, className: string | null | undefined): ThemeEntry<Themes> | undefined;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { parseClassName };
|
|
20
|
+
//# sourceMappingURL=parse-class-name.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-class-name.d.cts","names":[],"sources":["../../../src/theme/class-name/parse-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAiBA;;;;;;;;;iBAAgB,8BAA8B,kBACrC,+CAEN,WAAW"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ThemeMap } from "../theme-map.types.mjs";
|
|
2
|
+
import { ThemeEntry } from "../theme-entry.types.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/theme/class-name/parse-class-name.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Parses a class name string into a ThemeEntry.
|
|
8
|
+
*
|
|
9
|
+
* Pure function: no DOM access. Matches class strings by checking if any theme
|
|
10
|
+
* class is included in the className (e.g. `className.includes(themeClass)`).
|
|
11
|
+
* Arrays in theme map use first value for matching.
|
|
12
|
+
*
|
|
13
|
+
* @param themes - Record mapping theme keys to class name(s)
|
|
14
|
+
* @param className - Raw class attribute value (e.g. from element.className; accepts null)
|
|
15
|
+
* @returns ThemeEntry if a match is found, otherwise undefined
|
|
16
|
+
*/
|
|
17
|
+
declare function parseClassName<Themes extends ThemeMap>(themes: Themes, className: string | null | undefined): ThemeEntry<Themes> | undefined;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { parseClassName };
|
|
20
|
+
//# sourceMappingURL=parse-class-name.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-class-name.d.mts","names":[],"sources":["../../../src/theme/class-name/parse-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAiBA;;;;;;;;;iBAAgB,8BAA8B,kBACrC,+CAEN,WAAW"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { themeEntry } from "../theme-entry.mjs";
|
|
2
|
+
import { resolveThemeMapValue } from "../_utils/resolve-theme-map-value.mjs";
|
|
3
|
+
import { findKey } from "type-plus";
|
|
4
|
+
|
|
5
|
+
//#region src/theme/class-name/parse-class-name.ts
|
|
6
|
+
/**
|
|
7
|
+
* Parses a class name string into a ThemeEntry.
|
|
8
|
+
*
|
|
9
|
+
* Pure function: no DOM access. Matches class strings by checking if any theme
|
|
10
|
+
* class is included in the className (e.g. `className.includes(themeClass)`).
|
|
11
|
+
* Arrays in theme map use first value for matching.
|
|
12
|
+
*
|
|
13
|
+
* @param themes - Record mapping theme keys to class name(s)
|
|
14
|
+
* @param className - Raw class attribute value (e.g. from element.className; accepts null)
|
|
15
|
+
* @returns ThemeEntry if a match is found, otherwise undefined
|
|
16
|
+
*/
|
|
17
|
+
function parseClassName(themes, className) {
|
|
18
|
+
const cls = className ?? "";
|
|
19
|
+
const theme = findKey(themes, (key) => {
|
|
20
|
+
const value = themes[key];
|
|
21
|
+
if (value === void 0) return false;
|
|
22
|
+
const resolved = resolveThemeMapValue(value);
|
|
23
|
+
const v = Array.isArray(resolved) ? resolved[0] : resolved;
|
|
24
|
+
return !!v && cls.includes(v);
|
|
25
|
+
});
|
|
26
|
+
return theme !== void 0 ? themeEntry(themes, theme) : void 0;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
export { parseClassName };
|
|
31
|
+
//# sourceMappingURL=parse-class-name.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-class-name.mjs","names":[],"sources":["../../../src/theme/class-name/parse-class-name.ts"],"sourcesContent":["import { findKey } from 'type-plus'\nimport { resolveThemeMapValue } from '../_utils/resolve-theme-map-value.ts'\nimport { themeEntry } from '../theme-entry.ts'\nimport type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\n\n/**\n * Parses a class name string into a ThemeEntry.\n *\n * Pure function: no DOM access. Matches class strings by checking if any theme\n * class is included in the className (e.g. `className.includes(themeClass)`).\n * Arrays in theme map use first value for matching.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param className - Raw class attribute value (e.g. from element.className; accepts null)\n * @returns ThemeEntry if a match is found, otherwise undefined\n */\nexport function parseClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\tclassName: string | null | undefined\n): ThemeEntry<Themes> | undefined {\n\tconst cls = className ?? ''\n\tconst theme = findKey(themes, (key) => {\n\t\tconst value = themes[key]\n\t\tif (value === undefined) return false\n\t\tconst resolved = resolveThemeMapValue(value)\n\t\tconst v = Array.isArray(resolved) ? resolved[0] : resolved\n\t\treturn !!v && cls.includes(v)\n\t})\n\treturn theme !== undefined ? themeEntry(themes, theme) : undefined\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAiBA,SAAgB,eACf,QACA,WACiC;CACjC,MAAM,MAAM,aAAa;CACzB,MAAM,QAAQ,QAAQ,SAAS,QAAQ;EACtC,MAAM,QAAQ,OAAO;AACrB,MAAI,UAAU,OAAW,QAAO;EAChC,MAAM,WAAW,qBAAqB,MAAM;EAC5C,MAAM,IAAI,MAAM,QAAQ,SAAS,GAAG,SAAS,KAAK;AAClD,SAAO,CAAC,CAAC,KAAK,IAAI,SAAS,EAAE;GAC5B;AACF,QAAO,UAAU,SAAY,WAAW,QAAQ,MAAM,GAAG"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const require_parse_class_name = require('./parse-class-name.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/theme/class-name/read-class-name.ts
|
|
4
|
+
/**
|
|
5
|
+
* Reads a theme entry from the class attribute on an element.
|
|
6
|
+
*
|
|
7
|
+
* @param themes - Record mapping theme keys to class name(s)
|
|
8
|
+
* @param options.element - Element to read from (accepts null e.g. from refs). Defaults to document.documentElement.
|
|
9
|
+
* @param options.parse - Custom parser (default: parseClassName)
|
|
10
|
+
* @returns ThemeEntry if found, undefined otherwise. Returns undefined when element is not available (e.g. SSR).
|
|
11
|
+
*/
|
|
12
|
+
function readClassName(themes, options) {
|
|
13
|
+
const element = options?.element ?? document?.documentElement;
|
|
14
|
+
if (!element) return void 0;
|
|
15
|
+
return (options?.parse ?? require_parse_class_name.parseClassName)(themes, element.className ?? void 0);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
exports.readClassName = readClassName;
|
|
20
|
+
//# sourceMappingURL=read-class-name.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-class-name.cjs","names":["parseClassName"],"sources":["../../../src/theme/class-name/read-class-name.ts"],"sourcesContent":["import type { ParseStoredTheme, ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport { parseClassName } from './parse-class-name.ts'\n\n/**\n * Reads a theme entry from the class attribute on an element.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param options.element - Element to read from (accepts null e.g. from refs). Defaults to document.documentElement.\n * @param options.parse - Custom parser (default: parseClassName)\n * @returns ThemeEntry if found, undefined otherwise. Returns undefined when element is not available (e.g. SSR).\n */\nexport function readClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\toptions?:\n\t\t| { element?: Element | null | undefined; parse?: ParseStoredTheme<Themes> | undefined }\n\t\t| undefined\n): ThemeEntry<Themes> | undefined {\n\tconst element = options?.element ?? document?.documentElement\n\tif (!element) return undefined\n\tconst parse = options?.parse ?? parseClassName\n\tconst raw = element.className ?? undefined\n\treturn parse(themes, raw)\n}\n"],"mappings":";;;;;;;;;;;AAYA,SAAgB,cACf,QACA,SAGiC;CACjC,MAAM,UAAU,SAAS,WAAW,UAAU;AAC9C,KAAI,CAAC,QAAS,QAAO;AAGrB,SAFc,SAAS,SAASA,yCAEnB,QADD,QAAQ,aAAa,OACR"}
|