@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,7 +1,7 @@
|
|
|
1
1
|
import { dummyThemeStore } from '../../../testing/theme/dummy-theme-store.ts'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import type { ThemeEntry } from '../../theme-entry.types.ts'
|
|
2
|
+
import { readSessionStorage } from '../../session-storage/read-session-storage.ts'
|
|
3
|
+
import { writeSessionStorage } from '../../session-storage/write-session-storage.ts'
|
|
4
|
+
import type { ParseStoredTheme, StringifyStoredTheme, ThemeEntry } from '../../theme-entry.types.ts'
|
|
5
5
|
import type { ThemeMap } from '../../theme-map.types.ts'
|
|
6
6
|
import type { ThemeStore } from '../theme-store.types.ts'
|
|
7
7
|
|
|
@@ -13,6 +13,9 @@ import type { ThemeStore } from '../theme-store.types.ts'
|
|
|
13
13
|
*
|
|
14
14
|
* @param themes - Record mapping theme keys to values (for validation)
|
|
15
15
|
* @param options.storageKey - sessionStorage key
|
|
16
|
+
* @param options.parse - Optional custom parser for stored string (default: parseStoredTheme)
|
|
17
|
+
* @param options.stringify - Optional custom serializer (default: JSON.stringify)
|
|
18
|
+
* @param options.onError - Optional callback invoked when storage write throws
|
|
16
19
|
* @returns ThemeStore
|
|
17
20
|
*
|
|
18
21
|
* @example
|
|
@@ -26,11 +29,16 @@ import type { ThemeStore } from '../theme-store.types.ts'
|
|
|
26
29
|
*/
|
|
27
30
|
export function sessionStorageThemeStore<Themes extends ThemeMap>(
|
|
28
31
|
themes: Themes,
|
|
29
|
-
options: {
|
|
32
|
+
options: {
|
|
33
|
+
storageKey: string
|
|
34
|
+
parse?: ParseStoredTheme<Themes> | undefined
|
|
35
|
+
stringify?: StringifyStoredTheme<Themes> | undefined
|
|
36
|
+
onError?: ((error: unknown) => void) | undefined
|
|
37
|
+
}
|
|
30
38
|
) {
|
|
31
|
-
const { storageKey } = options
|
|
39
|
+
const { storageKey, parse, stringify, onError } = options
|
|
32
40
|
|
|
33
|
-
if (
|
|
41
|
+
if (!window?.sessionStorage) {
|
|
34
42
|
return dummyThemeStore satisfies ThemeStore<Themes>
|
|
35
43
|
}
|
|
36
44
|
|
|
@@ -38,10 +46,7 @@ export function sessionStorageThemeStore<Themes extends ThemeMap>(
|
|
|
38
46
|
let lastNotifiedKey: keyof Themes | undefined = read()?.theme ?? undefined
|
|
39
47
|
|
|
40
48
|
function read() {
|
|
41
|
-
|
|
42
|
-
const theme = parseStoredTheme(themes, stored)
|
|
43
|
-
if (theme === undefined) return undefined
|
|
44
|
-
return themeEntry(themes, theme)
|
|
49
|
+
return readSessionStorage(themes, storageKey, { parse })
|
|
45
50
|
}
|
|
46
51
|
|
|
47
52
|
function notify() {
|
|
@@ -55,16 +60,8 @@ export function sessionStorageThemeStore<Themes extends ThemeMap>(
|
|
|
55
60
|
return {
|
|
56
61
|
read,
|
|
57
62
|
write(entry) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
window.sessionStorage.removeItem(storageKey)
|
|
61
|
-
} else {
|
|
62
|
-
window.sessionStorage.setItem(storageKey, JSON.stringify(entry))
|
|
63
|
-
}
|
|
64
|
-
notify()
|
|
65
|
-
} catch {
|
|
66
|
-
// Ignore quota or other errors
|
|
67
|
-
}
|
|
63
|
+
writeSessionStorage(themes, storageKey, entry, { stringify, onError })
|
|
64
|
+
notify()
|
|
68
65
|
},
|
|
69
66
|
subscribe(handler) {
|
|
70
67
|
handlers.add(handler)
|
|
@@ -24,7 +24,5 @@ import type { ThemeMap } from '../theme-map.types.ts'
|
|
|
24
24
|
export interface ThemeStore<Themes extends ThemeMap = ThemeMap> {
|
|
25
25
|
read?: (() => ThemeEntry<Themes> | undefined) | undefined
|
|
26
26
|
write?: ((entry: ThemeEntry<Themes> | undefined) => void) | undefined
|
|
27
|
-
subscribe?:
|
|
28
|
-
| ((handler: (theme: ThemeEntry<Themes> | undefined | null) => void) => () => void)
|
|
29
|
-
| undefined
|
|
27
|
+
subscribe?: ((handler: (theme: ThemeEntry<Themes> | undefined) => void) => () => void) | undefined
|
|
30
28
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { parseStoredTheme } from '../_utils/parse-stored-theme.ts'
|
|
2
|
+
import type { ParseStoredTheme, ThemeEntry } from '../theme-entry.types.ts'
|
|
3
|
+
import type { ThemeMap } from '../theme-map.types.ts'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Reads a theme entry from a web storage (localStorage or sessionStorage).
|
|
7
|
+
*
|
|
8
|
+
* @param themes - Record mapping theme keys to values (for validation)
|
|
9
|
+
* @param storageKey - Storage key to read from
|
|
10
|
+
* @param options.storage - Storage object (localStorage or sessionStorage)
|
|
11
|
+
* @param options.parse - Custom parser (default: parseStoredTheme)
|
|
12
|
+
* @returns ThemeEntry if found, undefined otherwise. Returns undefined when storage is unavailable (e.g. SSR).
|
|
13
|
+
*/
|
|
14
|
+
export function readWebStorage<Themes extends ThemeMap>(
|
|
15
|
+
themes: Themes,
|
|
16
|
+
storageKey: string,
|
|
17
|
+
options: { storage: Storage; parse?: ParseStoredTheme<Themes> | undefined }
|
|
18
|
+
): ThemeEntry<Themes> | undefined {
|
|
19
|
+
const { storage, parse = parseStoredTheme } = options
|
|
20
|
+
const stored = storage.getItem(storageKey)
|
|
21
|
+
return parse(themes, stored ?? undefined)
|
|
22
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { StringifyStoredTheme, ThemeEntry } from '../theme-entry.types.ts'
|
|
2
|
+
import type { ThemeMap } from '../theme-map.types.ts'
|
|
3
|
+
|
|
4
|
+
function defaultStringify<Themes extends ThemeMap>(
|
|
5
|
+
_themes: Themes,
|
|
6
|
+
_existing: string | undefined,
|
|
7
|
+
entry: ThemeEntry<Themes> | null | undefined
|
|
8
|
+
): string {
|
|
9
|
+
return entry == null ? '' : JSON.stringify(entry)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Writes a theme entry to a web storage (localStorage or sessionStorage).
|
|
14
|
+
*
|
|
15
|
+
* Performs setItem/removeItem only. Does not notify subscribers; the store must call notify() after this.
|
|
16
|
+
*
|
|
17
|
+
* @param themes - Record mapping theme keys to values (used by stringify)
|
|
18
|
+
* @param storageKey - Storage key to write to
|
|
19
|
+
* @param entry - Theme entry to write, or null/undefined to remove
|
|
20
|
+
* @param options.storage - Storage object (localStorage or sessionStorage)
|
|
21
|
+
* @param options.stringify - Custom serializer (default: JSON.stringify)
|
|
22
|
+
* @param options.onError - Optional callback invoked when setItem/removeItem throws
|
|
23
|
+
*/
|
|
24
|
+
export function writeWebStorage<Themes extends ThemeMap>(
|
|
25
|
+
themes: Themes,
|
|
26
|
+
storageKey: string,
|
|
27
|
+
entry: ThemeEntry<Themes> | null | undefined,
|
|
28
|
+
options: {
|
|
29
|
+
storage: Storage
|
|
30
|
+
stringify?: StringifyStoredTheme<Themes> | undefined
|
|
31
|
+
onError?: ((error: unknown) => void) | undefined
|
|
32
|
+
}
|
|
33
|
+
): void {
|
|
34
|
+
const { storage, stringify = defaultStringify, onError } = options
|
|
35
|
+
try {
|
|
36
|
+
if (entry == null) {
|
|
37
|
+
storage.removeItem(storageKey)
|
|
38
|
+
} else {
|
|
39
|
+
const existing = storage.getItem(storageKey) ?? undefined
|
|
40
|
+
const value = stringify(themes, existing, entry)
|
|
41
|
+
storage.setItem(storageKey, value)
|
|
42
|
+
}
|
|
43
|
+
} catch (error) {
|
|
44
|
+
onError?.(error)
|
|
45
|
+
}
|
|
46
|
+
}
|
package/src/theme.ts
CHANGED
|
@@ -1,4 +1,22 @@
|
|
|
1
|
+
export * from './theme/class-name/parse-class-name.ts'
|
|
2
|
+
export * from './theme/class-name/read-class-name.ts'
|
|
3
|
+
export * from './theme/class-name/stringify-class-name.ts'
|
|
4
|
+
export * from './theme/class-name/subscribe-class-name.ts'
|
|
5
|
+
export * from './theme/class-name/write-class-name.ts'
|
|
1
6
|
export * from './theme/compose-theme-stores.ts'
|
|
7
|
+
export * from './theme/cookie/read-cookie-theme.ts'
|
|
8
|
+
export * from './theme/cookie/write-cookie-theme.ts'
|
|
9
|
+
export * from './theme/data-attribute/parse-data-attribute.ts'
|
|
10
|
+
export * from './theme/data-attribute/read-data-attribute.ts'
|
|
11
|
+
export * from './theme/data-attribute/stringify-data-attribute.ts'
|
|
12
|
+
export * from './theme/data-attribute/subscribe-data-attribute.ts'
|
|
13
|
+
export * from './theme/data-attribute/write-data-attribute.ts'
|
|
14
|
+
export * from './theme/local-storage/read-local-storage.ts'
|
|
15
|
+
export * from './theme/local-storage/write-local-storage.ts'
|
|
16
|
+
export * from './theme/prefers-color-scheme-theme/read-prefers-color-scheme-theme.ts'
|
|
17
|
+
export * from './theme/prefers-color-scheme-theme/subscribe-prefers-color-scheme-theme.ts'
|
|
18
|
+
export * from './theme/session-storage/read-session-storage.ts'
|
|
19
|
+
export * from './theme/session-storage/write-session-storage.ts'
|
|
2
20
|
export * from './theme/theme-entry.ts'
|
|
3
21
|
export type * from './theme/theme-entry.types.ts'
|
|
4
22
|
export type * from './theme/theme-map.types.ts'
|
|
@@ -12,3 +30,5 @@ export * from './theme/theme-store/prefers-color-scheme-theme-store/prefers-colo
|
|
|
12
30
|
export * from './theme/theme-store/session-storage-theme-store/session-storage-theme-store.ts'
|
|
13
31
|
export type * from './theme/theme-store/theme-store.types.ts'
|
|
14
32
|
export type * from './theme/theme-store/theme-store-factory.types.ts'
|
|
33
|
+
export * from './theme/web-storage/read-web-storage.ts'
|
|
34
|
+
export * from './theme/web-storage/write-web-storage.ts'
|
package/src/utils/append-id.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Appends a suffix to an ID if the ID is defined.
|
|
3
3
|
*
|
|
4
|
-
* @param id - The ID to append the suffix to.
|
|
4
|
+
* @param id - The ID to append the suffix to (accepts null e.g. from getAttribute).
|
|
5
5
|
* @param suffix - The suffix to append to the ID.
|
|
6
|
-
* @returns The ID with the suffix appended, or undefined if the ID is undefined.
|
|
6
|
+
* @returns The ID with the suffix appended, or undefined if the ID is null/undefined.
|
|
7
7
|
*/
|
|
8
|
-
export function appendId(id: string | undefined, suffix: string): string | undefined {
|
|
8
|
+
export function appendId(id: string | null | undefined, suffix: string): string | undefined {
|
|
9
9
|
return id ? `${id}-${suffix}` : undefined
|
|
10
10
|
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/theme/class-name/apply-theme-to-class-name.ts
|
|
3
|
-
/**
|
|
4
|
-
* Applies theme to element by updating its class attribute.
|
|
5
|
-
*
|
|
6
|
-
* Removes all theme classes from the element, then adds classes for the given entry.
|
|
7
|
-
* When entry is undefined, removes all theme classes (themeMap needed for clear path).
|
|
8
|
-
*
|
|
9
|
-
* @param element - Target element
|
|
10
|
-
* @param entry - Theme entry to apply, or undefined to clear
|
|
11
|
-
* @param themes - Record mapping theme keys to class names (used for clear case)
|
|
12
|
-
*/
|
|
13
|
-
function applyThemeToClassName(themes, element, entry) {
|
|
14
|
-
const allThemeClasses = Object.values(themes).flatMap((v) => Array.isArray(v) ? [...v] : [v]);
|
|
15
|
-
const current = element.className.trim();
|
|
16
|
-
const withoutThemes = (current ? current.split(/\s+/) : []).filter((c) => !allThemeClasses.includes(c));
|
|
17
|
-
const activeClasses = entry !== void 0 ? Array.isArray(entry.value) ? [...entry.value] : [entry.value] : [];
|
|
18
|
-
element.className = [...withoutThemes, ...activeClasses].filter(Boolean).join(" ");
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
//#endregion
|
|
22
|
-
exports.applyThemeToClassName = applyThemeToClassName;
|
|
23
|
-
//# sourceMappingURL=apply-theme-to-class-name.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"apply-theme-to-class-name.cjs","names":[],"sources":["../../../src/theme/class-name/apply-theme-to-class-name.ts"],"sourcesContent":["import type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\n\n/**\n * Applies theme to element by updating its class attribute.\n *\n * Removes all theme classes from the element, then adds classes for the given entry.\n * When entry is undefined, removes all theme classes (themeMap needed for clear path).\n *\n * @param element - Target element\n * @param entry - Theme entry to apply, or undefined to clear\n * @param themes - Record mapping theme keys to class names (used for clear case)\n */\nexport function applyThemeToClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\telement: Element,\n\tentry: ThemeEntry<Themes> | undefined\n): void {\n\tconst allThemeClasses = Object.values(themes).flatMap((v) => (Array.isArray(v) ? [...v] : [v]))\n\tconst current = element.className.trim()\n\tconst currentClasses = current ? current.split(/\\s+/) : []\n\tconst withoutThemes = currentClasses.filter((c) => !allThemeClasses.includes(c))\n\tconst activeClasses =\n\t\tentry !== undefined ? (Array.isArray(entry.value) ? [...entry.value] : [entry.value]) : []\n\telement.className = [...withoutThemes, ...activeClasses].filter(Boolean).join(' ')\n}\n"],"mappings":";;;;;;;;;;;;AAaA,SAAgB,sBACf,QACA,SACA,OACO;CACP,MAAM,kBAAkB,OAAO,OAAO,OAAO,CAAC,SAAS,MAAO,MAAM,QAAQ,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAE;CAC/F,MAAM,UAAU,QAAQ,UAAU,MAAM;CAExC,MAAM,iBADiB,UAAU,QAAQ,MAAM,MAAM,GAAG,EAAE,EACrB,QAAQ,MAAM,CAAC,gBAAgB,SAAS,EAAE,CAAC;CAChF,MAAM,gBACL,UAAU,SAAa,MAAM,QAAQ,MAAM,MAAM,GAAG,CAAC,GAAG,MAAM,MAAM,GAAG,CAAC,MAAM,MAAM,GAAI,EAAE;AAC3F,SAAQ,YAAY,CAAC,GAAG,eAAe,GAAG,cAAc,CAAC,OAAO,QAAQ,CAAC,KAAK,IAAI"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
//#region src/theme/class-name/apply-theme-to-class-name.ts
|
|
2
|
-
/**
|
|
3
|
-
* Applies theme to element by updating its class attribute.
|
|
4
|
-
*
|
|
5
|
-
* Removes all theme classes from the element, then adds classes for the given entry.
|
|
6
|
-
* When entry is undefined, removes all theme classes (themeMap needed for clear path).
|
|
7
|
-
*
|
|
8
|
-
* @param element - Target element
|
|
9
|
-
* @param entry - Theme entry to apply, or undefined to clear
|
|
10
|
-
* @param themes - Record mapping theme keys to class names (used for clear case)
|
|
11
|
-
*/
|
|
12
|
-
function applyThemeToClassName(themes, element, entry) {
|
|
13
|
-
const allThemeClasses = Object.values(themes).flatMap((v) => Array.isArray(v) ? [...v] : [v]);
|
|
14
|
-
const current = element.className.trim();
|
|
15
|
-
const withoutThemes = (current ? current.split(/\s+/) : []).filter((c) => !allThemeClasses.includes(c));
|
|
16
|
-
const activeClasses = entry !== void 0 ? Array.isArray(entry.value) ? [...entry.value] : [entry.value] : [];
|
|
17
|
-
element.className = [...withoutThemes, ...activeClasses].filter(Boolean).join(" ");
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
//#endregion
|
|
21
|
-
export { applyThemeToClassName };
|
|
22
|
-
//# sourceMappingURL=apply-theme-to-class-name.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"apply-theme-to-class-name.mjs","names":[],"sources":["../../../src/theme/class-name/apply-theme-to-class-name.ts"],"sourcesContent":["import type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\n\n/**\n * Applies theme to element by updating its class attribute.\n *\n * Removes all theme classes from the element, then adds classes for the given entry.\n * When entry is undefined, removes all theme classes (themeMap needed for clear path).\n *\n * @param element - Target element\n * @param entry - Theme entry to apply, or undefined to clear\n * @param themes - Record mapping theme keys to class names (used for clear case)\n */\nexport function applyThemeToClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\telement: Element,\n\tentry: ThemeEntry<Themes> | undefined\n): void {\n\tconst allThemeClasses = Object.values(themes).flatMap((v) => (Array.isArray(v) ? [...v] : [v]))\n\tconst current = element.className.trim()\n\tconst currentClasses = current ? current.split(/\\s+/) : []\n\tconst withoutThemes = currentClasses.filter((c) => !allThemeClasses.includes(c))\n\tconst activeClasses =\n\t\tentry !== undefined ? (Array.isArray(entry.value) ? [...entry.value] : [entry.value]) : []\n\telement.className = [...withoutThemes, ...activeClasses].filter(Boolean).join(' ')\n}\n"],"mappings":";;;;;;;;;;;AAaA,SAAgB,sBACf,QACA,SACA,OACO;CACP,MAAM,kBAAkB,OAAO,OAAO,OAAO,CAAC,SAAS,MAAO,MAAM,QAAQ,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAE;CAC/F,MAAM,UAAU,QAAQ,UAAU,MAAM;CAExC,MAAM,iBADiB,UAAU,QAAQ,MAAM,MAAM,GAAG,EAAE,EACrB,QAAQ,MAAM,CAAC,gBAAgB,SAAS,EAAE,CAAC;CAChF,MAAM,gBACL,UAAU,SAAa,MAAM,QAAQ,MAAM,MAAM,GAAG,CAAC,GAAG,MAAM,MAAM,GAAG,CAAC,MAAM,MAAM,GAAI,EAAE;AAC3F,SAAQ,YAAY,CAAC,GAAG,eAAe,GAAG,cAAc,CAAC,OAAO,QAAQ,CAAC,KAAK,IAAI"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let type_plus = require("type-plus");
|
|
3
|
-
|
|
4
|
-
//#region src/theme/class-name/resolve-theme-from-class-name.ts
|
|
5
|
-
/**
|
|
6
|
-
* Resolves theme key from class name string by matching against theme map.
|
|
7
|
-
*
|
|
8
|
-
* @param className - Element class attribute value
|
|
9
|
-
* @param themes - Record mapping theme keys to class name(s); arrays use first value for matching
|
|
10
|
-
* @returns Theme key if a match is found, otherwise undefined
|
|
11
|
-
*/
|
|
12
|
-
function resolveThemeFromClassName(themes, className) {
|
|
13
|
-
return (0, type_plus.findKey)(themes, (key) => {
|
|
14
|
-
const value = themes[key];
|
|
15
|
-
if (value === void 0) return false;
|
|
16
|
-
const v = Array.isArray(value) ? value[0] : value;
|
|
17
|
-
return !!v && className.includes(v);
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
//#endregion
|
|
22
|
-
exports.resolveThemeFromClassName = resolveThemeFromClassName;
|
|
23
|
-
//# sourceMappingURL=resolve-theme-from-class-name.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-theme-from-class-name.cjs","names":[],"sources":["../../../src/theme/class-name/resolve-theme-from-class-name.ts"],"sourcesContent":["import { findKey } from 'type-plus'\nimport type { ThemeMap } from '../theme-map.types.ts'\n\n/**\n * Resolves theme key from class name string by matching against theme map.\n *\n * @param className - Element class attribute value\n * @param themes - Record mapping theme keys to class name(s); arrays use first value for matching\n * @returns Theme key if a match is found, otherwise undefined\n */\nexport function resolveThemeFromClassName<Theme extends string>(\n\tthemes: ThemeMap<Theme>,\n\tclassName: string\n): Theme | undefined {\n\tconst theme = findKey(themes, (key) => {\n\t\tconst value = themes[key]\n\t\tif (value === undefined) return false\n\t\tconst v = Array.isArray(value) ? value[0] : value\n\t\treturn !!v && className.includes(v)\n\t})\n\treturn theme as Theme | undefined\n}\n"],"mappings":";;;;;;;;;;;AAUA,SAAgB,0BACf,QACA,WACoB;AAOpB,+BANsB,SAAS,QAAQ;EACtC,MAAM,QAAQ,OAAO;AACrB,MAAI,UAAU,OAAW,QAAO;EAChC,MAAM,IAAI,MAAM,QAAQ,MAAM,GAAG,MAAM,KAAK;AAC5C,SAAO,CAAC,CAAC,KAAK,UAAU,SAAS,EAAE;GAClC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { findKey } from "type-plus";
|
|
2
|
-
|
|
3
|
-
//#region src/theme/class-name/resolve-theme-from-class-name.ts
|
|
4
|
-
/**
|
|
5
|
-
* Resolves theme key from class name string by matching against theme map.
|
|
6
|
-
*
|
|
7
|
-
* @param className - Element class attribute value
|
|
8
|
-
* @param themes - Record mapping theme keys to class name(s); arrays use first value for matching
|
|
9
|
-
* @returns Theme key if a match is found, otherwise undefined
|
|
10
|
-
*/
|
|
11
|
-
function resolveThemeFromClassName(themes, className) {
|
|
12
|
-
return findKey(themes, (key) => {
|
|
13
|
-
const value = themes[key];
|
|
14
|
-
if (value === void 0) return false;
|
|
15
|
-
const v = Array.isArray(value) ? value[0] : value;
|
|
16
|
-
return !!v && className.includes(v);
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
//#endregion
|
|
21
|
-
export { resolveThemeFromClassName };
|
|
22
|
-
//# sourceMappingURL=resolve-theme-from-class-name.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-theme-from-class-name.mjs","names":[],"sources":["../../../src/theme/class-name/resolve-theme-from-class-name.ts"],"sourcesContent":["import { findKey } from 'type-plus'\nimport type { ThemeMap } from '../theme-map.types.ts'\n\n/**\n * Resolves theme key from class name string by matching against theme map.\n *\n * @param className - Element class attribute value\n * @param themes - Record mapping theme keys to class name(s); arrays use first value for matching\n * @returns Theme key if a match is found, otherwise undefined\n */\nexport function resolveThemeFromClassName<Theme extends string>(\n\tthemes: ThemeMap<Theme>,\n\tclassName: string\n): Theme | undefined {\n\tconst theme = findKey(themes, (key) => {\n\t\tconst value = themes[key]\n\t\tif (value === undefined) return false\n\t\tconst v = Array.isArray(value) ? value[0] : value\n\t\treturn !!v && className.includes(v)\n\t})\n\treturn theme as Theme | undefined\n}\n"],"mappings":";;;;;;;;;;AAUA,SAAgB,0BACf,QACA,WACoB;AAOpB,QANc,QAAQ,SAAS,QAAQ;EACtC,MAAM,QAAQ,OAAO;AACrB,MAAI,UAAU,OAAW,QAAO;EAChC,MAAM,IAAI,MAAM,QAAQ,MAAM,GAAG,MAAM,KAAK;AAC5C,SAAO,CAAC,CAAC,KAAK,UAAU,SAAS,EAAE;GAClC"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/theme/data-attribute/apply-theme-to-data-attribute.ts
|
|
3
|
-
/**
|
|
4
|
-
* Applies theme to element by setting or removing a data attribute.
|
|
5
|
-
*
|
|
6
|
-
* @param element - Target element
|
|
7
|
-
* @param attributeName - Data attribute name (e.g. `data-theme`)
|
|
8
|
-
* @param entry - Theme entry to apply, or undefined to remove attribute
|
|
9
|
-
*/
|
|
10
|
-
function applyThemeToDataAttribute(element, attributeName, entry) {
|
|
11
|
-
if (entry === void 0) {
|
|
12
|
-
element.removeAttribute(attributeName);
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
const val = entry.value;
|
|
16
|
-
const attributeValue = Array.isArray(val) ? val[0] : val;
|
|
17
|
-
if (attributeValue !== void 0 && attributeValue !== "") element.setAttribute(attributeName, attributeValue);
|
|
18
|
-
else element.removeAttribute(attributeName);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
//#endregion
|
|
22
|
-
exports.applyThemeToDataAttribute = applyThemeToDataAttribute;
|
|
23
|
-
//# sourceMappingURL=apply-theme-to-data-attribute.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"apply-theme-to-data-attribute.cjs","names":[],"sources":["../../../src/theme/data-attribute/apply-theme-to-data-attribute.ts"],"sourcesContent":["import type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\n\n/**\n * Applies theme to element by setting or removing a data attribute.\n *\n * @param element - Target element\n * @param attributeName - Data attribute name (e.g. `data-theme`)\n * @param entry - Theme entry to apply, or undefined to remove attribute\n */\nexport function applyThemeToDataAttribute<Themes extends ThemeMap>(\n\telement: Element,\n\tattributeName: `data-${string}`,\n\tentry: ThemeEntry<Themes> | undefined\n): void {\n\tif (entry === undefined) {\n\t\telement.removeAttribute(attributeName)\n\t\treturn\n\t}\n\tconst val = entry.value\n\tconst attributeValue = Array.isArray(val) ? val[0] : val\n\tif (attributeValue !== undefined && attributeValue !== '') {\n\t\telement.setAttribute(attributeName, attributeValue)\n\t} else {\n\t\telement.removeAttribute(attributeName)\n\t}\n}\n"],"mappings":";;;;;;;;;AAUA,SAAgB,0BACf,SACA,eACA,OACO;AACP,KAAI,UAAU,QAAW;AACxB,UAAQ,gBAAgB,cAAc;AACtC;;CAED,MAAM,MAAM,MAAM;CAClB,MAAM,iBAAiB,MAAM,QAAQ,IAAI,GAAG,IAAI,KAAK;AACrD,KAAI,mBAAmB,UAAa,mBAAmB,GACtD,SAAQ,aAAa,eAAe,eAAe;KAEnD,SAAQ,gBAAgB,cAAc"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
//#region src/theme/data-attribute/apply-theme-to-data-attribute.ts
|
|
2
|
-
/**
|
|
3
|
-
* Applies theme to element by setting or removing a data attribute.
|
|
4
|
-
*
|
|
5
|
-
* @param element - Target element
|
|
6
|
-
* @param attributeName - Data attribute name (e.g. `data-theme`)
|
|
7
|
-
* @param entry - Theme entry to apply, or undefined to remove attribute
|
|
8
|
-
*/
|
|
9
|
-
function applyThemeToDataAttribute(element, attributeName, entry) {
|
|
10
|
-
if (entry === void 0) {
|
|
11
|
-
element.removeAttribute(attributeName);
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
const val = entry.value;
|
|
15
|
-
const attributeValue = Array.isArray(val) ? val[0] : val;
|
|
16
|
-
if (attributeValue !== void 0 && attributeValue !== "") element.setAttribute(attributeName, attributeValue);
|
|
17
|
-
else element.removeAttribute(attributeName);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
//#endregion
|
|
21
|
-
export { applyThemeToDataAttribute };
|
|
22
|
-
//# sourceMappingURL=apply-theme-to-data-attribute.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"apply-theme-to-data-attribute.mjs","names":[],"sources":["../../../src/theme/data-attribute/apply-theme-to-data-attribute.ts"],"sourcesContent":["import type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\n\n/**\n * Applies theme to element by setting or removing a data attribute.\n *\n * @param element - Target element\n * @param attributeName - Data attribute name (e.g. `data-theme`)\n * @param entry - Theme entry to apply, or undefined to remove attribute\n */\nexport function applyThemeToDataAttribute<Themes extends ThemeMap>(\n\telement: Element,\n\tattributeName: `data-${string}`,\n\tentry: ThemeEntry<Themes> | undefined\n): void {\n\tif (entry === undefined) {\n\t\telement.removeAttribute(attributeName)\n\t\treturn\n\t}\n\tconst val = entry.value\n\tconst attributeValue = Array.isArray(val) ? val[0] : val\n\tif (attributeValue !== undefined && attributeValue !== '') {\n\t\telement.setAttribute(attributeName, attributeValue)\n\t} else {\n\t\telement.removeAttribute(attributeName)\n\t}\n}\n"],"mappings":";;;;;;;;AAUA,SAAgB,0BACf,SACA,eACA,OACO;AACP,KAAI,UAAU,QAAW;AACxB,UAAQ,gBAAgB,cAAc;AACtC;;CAED,MAAM,MAAM,MAAM;CAClB,MAAM,iBAAiB,MAAM,QAAQ,IAAI,GAAG,IAAI,KAAK;AACrD,KAAI,mBAAmB,UAAa,mBAAmB,GACtD,SAAQ,aAAa,eAAe,eAAe;KAEnD,SAAQ,gBAAgB,cAAc"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let type_plus = require("type-plus");
|
|
3
|
-
|
|
4
|
-
//#region src/theme/data-attribute/resolve-theme-from-data-attribute.ts
|
|
5
|
-
/**
|
|
6
|
-
* Resolves theme key from data attribute value by matching against theme map.
|
|
7
|
-
*
|
|
8
|
-
* @param attrValue - Data attribute value (e.g. from getAttribute)
|
|
9
|
-
* @param themes - Record mapping theme keys to attribute values
|
|
10
|
-
* @returns Theme key if a match is found, otherwise undefined
|
|
11
|
-
*/
|
|
12
|
-
function resolveThemeFromDataAttribute(themes, attrValue) {
|
|
13
|
-
if (attrValue === null || attrValue === "") return void 0;
|
|
14
|
-
return (0, type_plus.findKey)(themes, (key) => {
|
|
15
|
-
const value = themes[key];
|
|
16
|
-
if (value === void 0) return false;
|
|
17
|
-
return (Array.isArray(value) ? value[0] : value) === attrValue;
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
//#endregion
|
|
22
|
-
exports.resolveThemeFromDataAttribute = resolveThemeFromDataAttribute;
|
|
23
|
-
//# sourceMappingURL=resolve-theme-from-data-attribute.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-theme-from-data-attribute.cjs","names":[],"sources":["../../../src/theme/data-attribute/resolve-theme-from-data-attribute.ts"],"sourcesContent":["import { findKey } from 'type-plus'\nimport type { ThemeMap } from '../theme-map.types.ts'\n\n/**\n * Resolves theme key from data attribute value by matching against theme map.\n *\n * @param attrValue - Data attribute value (e.g. from getAttribute)\n * @param themes - Record mapping theme keys to attribute values\n * @returns Theme key if a match is found, otherwise undefined\n */\nexport function resolveThemeFromDataAttribute<Theme extends string>(\n\tthemes: ThemeMap<Theme>,\n\tattrValue: string | null\n): Theme | undefined {\n\tif (attrValue === null || attrValue === '') return undefined\n\tconst theme = findKey(themes, (key) => {\n\t\tconst value = themes[key]\n\t\tif (value === undefined) return false\n\t\tconst v = Array.isArray(value) ? value[0] : value\n\t\treturn v === attrValue\n\t})\n\treturn theme as Theme | undefined\n}\n"],"mappings":";;;;;;;;;;;AAUA,SAAgB,8BACf,QACA,WACoB;AACpB,KAAI,cAAc,QAAQ,cAAc,GAAI,QAAO;AAOnD,+BANsB,SAAS,QAAQ;EACtC,MAAM,QAAQ,OAAO;AACrB,MAAI,UAAU,OAAW,QAAO;AAEhC,UADU,MAAM,QAAQ,MAAM,GAAG,MAAM,KAAK,WAC/B;GACZ"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { findKey } from "type-plus";
|
|
2
|
-
|
|
3
|
-
//#region src/theme/data-attribute/resolve-theme-from-data-attribute.ts
|
|
4
|
-
/**
|
|
5
|
-
* Resolves theme key from data attribute value by matching against theme map.
|
|
6
|
-
*
|
|
7
|
-
* @param attrValue - Data attribute value (e.g. from getAttribute)
|
|
8
|
-
* @param themes - Record mapping theme keys to attribute values
|
|
9
|
-
* @returns Theme key if a match is found, otherwise undefined
|
|
10
|
-
*/
|
|
11
|
-
function resolveThemeFromDataAttribute(themes, attrValue) {
|
|
12
|
-
if (attrValue === null || attrValue === "") return void 0;
|
|
13
|
-
return findKey(themes, (key) => {
|
|
14
|
-
const value = themes[key];
|
|
15
|
-
if (value === void 0) return false;
|
|
16
|
-
return (Array.isArray(value) ? value[0] : value) === attrValue;
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
//#endregion
|
|
21
|
-
export { resolveThemeFromDataAttribute };
|
|
22
|
-
//# sourceMappingURL=resolve-theme-from-data-attribute.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-theme-from-data-attribute.mjs","names":[],"sources":["../../../src/theme/data-attribute/resolve-theme-from-data-attribute.ts"],"sourcesContent":["import { findKey } from 'type-plus'\nimport type { ThemeMap } from '../theme-map.types.ts'\n\n/**\n * Resolves theme key from data attribute value by matching against theme map.\n *\n * @param attrValue - Data attribute value (e.g. from getAttribute)\n * @param themes - Record mapping theme keys to attribute values\n * @returns Theme key if a match is found, otherwise undefined\n */\nexport function resolveThemeFromDataAttribute<Theme extends string>(\n\tthemes: ThemeMap<Theme>,\n\tattrValue: string | null\n): Theme | undefined {\n\tif (attrValue === null || attrValue === '') return undefined\n\tconst theme = findKey(themes, (key) => {\n\t\tconst value = themes[key]\n\t\tif (value === undefined) return false\n\t\tconst v = Array.isArray(value) ? value[0] : value\n\t\treturn v === attrValue\n\t})\n\treturn theme as Theme | undefined\n}\n"],"mappings":";;;;;;;;;;AAUA,SAAgB,8BACf,QACA,WACoB;AACpB,KAAI,cAAc,QAAQ,cAAc,GAAI,QAAO;AAOnD,QANc,QAAQ,SAAS,QAAQ;EACtC,MAAM,QAAQ,OAAO;AACrB,MAAI,UAAU,OAAW,QAAO;AAEhC,UADU,MAAM,QAAQ,MAAM,GAAG,MAAM,KAAK,WAC/B;GACZ"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { ThemeEntry } from '../theme-entry.types.ts'
|
|
2
|
-
import type { ThemeMap } from '../theme-map.types.ts'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Applies theme to element by updating its class attribute.
|
|
6
|
-
*
|
|
7
|
-
* Removes all theme classes from the element, then adds classes for the given entry.
|
|
8
|
-
* When entry is undefined, removes all theme classes (themeMap needed for clear path).
|
|
9
|
-
*
|
|
10
|
-
* @param element - Target element
|
|
11
|
-
* @param entry - Theme entry to apply, or undefined to clear
|
|
12
|
-
* @param themes - Record mapping theme keys to class names (used for clear case)
|
|
13
|
-
*/
|
|
14
|
-
export function applyThemeToClassName<Themes extends ThemeMap>(
|
|
15
|
-
themes: Themes,
|
|
16
|
-
element: Element,
|
|
17
|
-
entry: ThemeEntry<Themes> | undefined
|
|
18
|
-
): void {
|
|
19
|
-
const allThemeClasses = Object.values(themes).flatMap((v) => (Array.isArray(v) ? [...v] : [v]))
|
|
20
|
-
const current = element.className.trim()
|
|
21
|
-
const currentClasses = current ? current.split(/\s+/) : []
|
|
22
|
-
const withoutThemes = currentClasses.filter((c) => !allThemeClasses.includes(c))
|
|
23
|
-
const activeClasses =
|
|
24
|
-
entry !== undefined ? (Array.isArray(entry.value) ? [...entry.value] : [entry.value]) : []
|
|
25
|
-
element.className = [...withoutThemes, ...activeClasses].filter(Boolean).join(' ')
|
|
26
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { findKey } from 'type-plus'
|
|
2
|
-
import type { ThemeMap } from '../theme-map.types.ts'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Resolves theme key from class name string by matching against theme map.
|
|
6
|
-
*
|
|
7
|
-
* @param className - Element class attribute value
|
|
8
|
-
* @param themes - Record mapping theme keys to class name(s); arrays use first value for matching
|
|
9
|
-
* @returns Theme key if a match is found, otherwise undefined
|
|
10
|
-
*/
|
|
11
|
-
export function resolveThemeFromClassName<Theme extends string>(
|
|
12
|
-
themes: ThemeMap<Theme>,
|
|
13
|
-
className: string
|
|
14
|
-
): Theme | undefined {
|
|
15
|
-
const theme = findKey(themes, (key) => {
|
|
16
|
-
const value = themes[key]
|
|
17
|
-
if (value === undefined) return false
|
|
18
|
-
const v = Array.isArray(value) ? value[0] : value
|
|
19
|
-
return !!v && className.includes(v)
|
|
20
|
-
})
|
|
21
|
-
return theme as Theme | undefined
|
|
22
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { ThemeEntry } from '../theme-entry.types.ts'
|
|
2
|
-
import type { ThemeMap } from '../theme-map.types.ts'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Applies theme to element by setting or removing a data attribute.
|
|
6
|
-
*
|
|
7
|
-
* @param element - Target element
|
|
8
|
-
* @param attributeName - Data attribute name (e.g. `data-theme`)
|
|
9
|
-
* @param entry - Theme entry to apply, or undefined to remove attribute
|
|
10
|
-
*/
|
|
11
|
-
export function applyThemeToDataAttribute<Themes extends ThemeMap>(
|
|
12
|
-
element: Element,
|
|
13
|
-
attributeName: `data-${string}`,
|
|
14
|
-
entry: ThemeEntry<Themes> | undefined
|
|
15
|
-
): void {
|
|
16
|
-
if (entry === undefined) {
|
|
17
|
-
element.removeAttribute(attributeName)
|
|
18
|
-
return
|
|
19
|
-
}
|
|
20
|
-
const val = entry.value
|
|
21
|
-
const attributeValue = Array.isArray(val) ? val[0] : val
|
|
22
|
-
if (attributeValue !== undefined && attributeValue !== '') {
|
|
23
|
-
element.setAttribute(attributeName, attributeValue)
|
|
24
|
-
} else {
|
|
25
|
-
element.removeAttribute(attributeName)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { findKey } from 'type-plus'
|
|
2
|
-
import type { ThemeMap } from '../theme-map.types.ts'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Resolves theme key from data attribute value by matching against theme map.
|
|
6
|
-
*
|
|
7
|
-
* @param attrValue - Data attribute value (e.g. from getAttribute)
|
|
8
|
-
* @param themes - Record mapping theme keys to attribute values
|
|
9
|
-
* @returns Theme key if a match is found, otherwise undefined
|
|
10
|
-
*/
|
|
11
|
-
export function resolveThemeFromDataAttribute<Theme extends string>(
|
|
12
|
-
themes: ThemeMap<Theme>,
|
|
13
|
-
attrValue: string | null
|
|
14
|
-
): Theme | undefined {
|
|
15
|
-
if (attrValue === null || attrValue === '') return undefined
|
|
16
|
-
const theme = findKey(themes, (key) => {
|
|
17
|
-
const value = themes[key]
|
|
18
|
-
if (value === undefined) return false
|
|
19
|
-
const v = Array.isArray(value) ? value[0] : value
|
|
20
|
-
return v === attrValue
|
|
21
|
-
})
|
|
22
|
-
return theme as Theme | undefined
|
|
23
|
-
}
|