@just-web/toolkits 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_internal/utils/try-parse-json.cjs +14 -0
- package/dist/_internal/utils/try-parse-json.cjs.map +1 -0
- package/dist/_internal/utils/try-parse-json.mjs +13 -0
- package/dist/_internal/utils/try-parse-json.mjs.map +1 -0
- package/dist/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/attributes/data-attribute.d.cts +17 -0
- package/dist/attributes/data-attribute.d.cts.map +1 -0
- package/dist/attributes/data-attribute.d.mts +17 -0
- package/dist/attributes/data-attribute.d.mts.map +1 -0
- package/dist/attributes/get-attribute.cjs +26 -0
- package/dist/attributes/get-attribute.cjs.map +1 -0
- package/dist/attributes/get-attribute.d.cts +21 -0
- package/dist/attributes/get-attribute.d.cts.map +1 -0
- package/dist/attributes/get-attribute.d.mts +21 -0
- package/dist/attributes/get-attribute.d.mts.map +1 -0
- package/dist/attributes/get-attribute.mjs +25 -0
- package/dist/attributes/get-attribute.mjs.map +1 -0
- package/dist/attributes/get-data-attribute.cjs +19 -0
- package/dist/attributes/get-data-attribute.cjs.map +1 -0
- package/dist/attributes/get-data-attribute.d.cts +17 -0
- package/dist/attributes/get-data-attribute.d.cts.map +1 -0
- package/dist/attributes/get-data-attribute.d.mts +17 -0
- package/dist/attributes/get-data-attribute.d.mts.map +1 -0
- package/dist/attributes/get-data-attribute.mjs +19 -0
- package/dist/attributes/get-data-attribute.mjs.map +1 -0
- package/dist/attributes/observe-attribute.cjs +40 -0
- package/dist/attributes/observe-attribute.cjs.map +1 -0
- package/dist/attributes/observe-attribute.d.cts +23 -0
- package/dist/attributes/observe-attribute.d.cts.map +1 -0
- package/dist/attributes/observe-attribute.d.mts +23 -0
- package/dist/attributes/observe-attribute.d.mts.map +1 -0
- package/dist/attributes/observe-attribute.mjs +39 -0
- package/dist/attributes/observe-attribute.mjs.map +1 -0
- package/dist/attributes/observe-data-attribute.cjs +31 -0
- package/dist/attributes/observe-data-attribute.cjs.map +1 -0
- package/dist/attributes/observe-data-attribute.d.cts +26 -0
- package/dist/attributes/observe-data-attribute.d.cts.map +1 -0
- package/dist/attributes/observe-data-attribute.d.mts +26 -0
- package/dist/attributes/observe-data-attribute.d.mts.map +1 -0
- package/dist/attributes/observe-data-attribute.mjs +31 -0
- package/dist/attributes/observe-data-attribute.mjs.map +1 -0
- package/dist/children/just-children.d.cts +37 -0
- package/dist/children/just-children.d.cts.map +1 -0
- package/dist/children/just-children.d.mts +37 -0
- package/dist/children/just-children.d.mts.map +1 -0
- package/dist/children/resolve-children.cjs +11 -0
- package/dist/children/resolve-children.cjs.map +1 -0
- package/dist/children/resolve-children.d.cts +9 -0
- package/dist/children/resolve-children.d.cts.map +1 -0
- package/dist/children/resolve-children.d.mts +9 -0
- package/dist/children/resolve-children.d.mts.map +1 -0
- package/dist/children/resolve-children.mjs +10 -0
- package/dist/children/resolve-children.mjs.map +1 -0
- package/dist/class-name/class-name-props.d.cts +11 -0
- package/dist/class-name/class-name-props.d.cts.map +1 -0
- package/dist/class-name/class-name-props.d.mts +11 -0
- package/dist/class-name/class-name-props.d.mts.map +1 -0
- package/dist/class-name/clsx.cjs +3 -0
- package/dist/class-name/clsx.d.cts +2 -0
- package/dist/class-name/clsx.d.mts +2 -0
- package/dist/class-name/clsx.mjs +3 -0
- package/dist/class-name/just-class-name.d.cts +36 -0
- package/dist/class-name/just-class-name.d.cts.map +1 -0
- package/dist/class-name/just-class-name.d.mts +36 -0
- package/dist/class-name/just-class-name.d.mts.map +1 -0
- package/dist/class-name/resolve-class-name.cjs +12 -0
- package/dist/class-name/resolve-class-name.cjs.map +1 -0
- package/dist/class-name/resolve-class-name.d.cts +8 -0
- package/dist/class-name/resolve-class-name.d.cts.map +1 -0
- package/dist/class-name/resolve-class-name.d.mts +8 -0
- package/dist/class-name/resolve-class-name.d.mts.map +1 -0
- package/dist/class-name/resolve-class-name.mjs +10 -0
- package/dist/class-name/resolve-class-name.mjs.map +1 -0
- package/dist/color-scheme/get-prefers-color-scheme.cjs +21 -0
- package/dist/color-scheme/get-prefers-color-scheme.cjs.map +1 -0
- package/dist/color-scheme/get-prefers-color-scheme.d.cts +16 -0
- package/dist/color-scheme/get-prefers-color-scheme.d.cts.map +1 -0
- package/dist/color-scheme/get-prefers-color-scheme.d.mts +16 -0
- package/dist/color-scheme/get-prefers-color-scheme.d.mts.map +1 -0
- package/dist/color-scheme/get-prefers-color-scheme.mjs +20 -0
- package/dist/color-scheme/get-prefers-color-scheme.mjs.map +1 -0
- package/dist/color-scheme/observe-prefers-color-scheme.cjs +29 -0
- package/dist/color-scheme/observe-prefers-color-scheme.cjs.map +1 -0
- package/dist/color-scheme/observe-prefers-color-scheme.d.cts +20 -0
- package/dist/color-scheme/observe-prefers-color-scheme.d.cts.map +1 -0
- package/dist/color-scheme/observe-prefers-color-scheme.d.mts +20 -0
- package/dist/color-scheme/observe-prefers-color-scheme.d.mts.map +1 -0
- package/dist/color-scheme/observe-prefers-color-scheme.mjs +28 -0
- package/dist/color-scheme/observe-prefers-color-scheme.mjs.map +1 -0
- package/dist/index.cjs +39 -0
- package/dist/index.d.cts +26 -0
- package/dist/index.d.mts +26 -0
- package/dist/index.mjs +20 -0
- package/dist/react/hooks/use-attribute.cjs +41 -0
- package/dist/react/hooks/use-attribute.cjs.map +1 -0
- package/dist/react/hooks/use-attribute.d.cts +21 -0
- package/dist/react/hooks/use-attribute.d.cts.map +1 -0
- package/dist/react/hooks/use-attribute.d.mts +21 -0
- package/dist/react/hooks/use-attribute.d.mts.map +1 -0
- package/dist/react/hooks/use-attribute.mjs +40 -0
- package/dist/react/hooks/use-attribute.mjs.map +1 -0
- package/dist/react/hooks/use-prefers-color-scheme.cjs +42 -0
- package/dist/react/hooks/use-prefers-color-scheme.cjs.map +1 -0
- package/dist/react/hooks/use-prefers-color-scheme.d.cts +29 -0
- package/dist/react/hooks/use-prefers-color-scheme.d.cts.map +1 -0
- package/dist/react/hooks/use-prefers-color-scheme.d.mts +29 -0
- package/dist/react/hooks/use-prefers-color-scheme.d.mts.map +1 -0
- package/dist/react/hooks/use-prefers-color-scheme.mjs +41 -0
- package/dist/react/hooks/use-prefers-color-scheme.mjs.map +1 -0
- package/dist/react/hooks/use-theme-by-class-name.cjs +60 -0
- package/dist/react/hooks/use-theme-by-class-name.cjs.map +1 -0
- package/dist/react/hooks/use-theme-by-class-name.d.cts +34 -0
- package/dist/react/hooks/use-theme-by-class-name.d.cts.map +1 -0
- package/dist/react/hooks/use-theme-by-class-name.d.mts +34 -0
- package/dist/react/hooks/use-theme-by-class-name.d.mts.map +1 -0
- package/dist/react/hooks/use-theme-by-class-name.mjs +59 -0
- package/dist/react/hooks/use-theme-by-class-name.mjs.map +1 -0
- package/dist/react/hooks/use-theme-by-data-attribute.cjs +73 -0
- package/dist/react/hooks/use-theme-by-data-attribute.cjs.map +1 -0
- package/dist/react/hooks/use-theme-by-data-attribute.d.cts +39 -0
- package/dist/react/hooks/use-theme-by-data-attribute.d.cts.map +1 -0
- package/dist/react/hooks/use-theme-by-data-attribute.d.mts +39 -0
- package/dist/react/hooks/use-theme-by-data-attribute.d.mts.map +1 -0
- package/dist/react/hooks/use-theme-by-data-attribute.mjs +72 -0
- package/dist/react/hooks/use-theme-by-data-attribute.mjs.map +1 -0
- package/dist/react/hooks/use-theme-by-local-storage.cjs +53 -0
- package/dist/react/hooks/use-theme-by-local-storage.cjs.map +1 -0
- package/dist/react/hooks/use-theme-by-local-storage.d.cts +37 -0
- package/dist/react/hooks/use-theme-by-local-storage.d.cts.map +1 -0
- package/dist/react/hooks/use-theme-by-local-storage.d.mts +37 -0
- package/dist/react/hooks/use-theme-by-local-storage.d.mts.map +1 -0
- package/dist/react/hooks/use-theme-by-local-storage.mjs +52 -0
- package/dist/react/hooks/use-theme-by-local-storage.mjs.map +1 -0
- package/dist/react/hooks/use-theme-stores.cjs +40 -0
- package/dist/react/hooks/use-theme-stores.cjs.map +1 -0
- package/dist/react/hooks/use-theme-stores.d.cts +38 -0
- package/dist/react/hooks/use-theme-stores.d.cts.map +1 -0
- package/dist/react/hooks/use-theme-stores.d.mts +38 -0
- package/dist/react/hooks/use-theme-stores.d.mts.map +1 -0
- package/dist/react/hooks/use-theme-stores.mjs +39 -0
- package/dist/react/hooks/use-theme-stores.mjs.map +1 -0
- package/dist/react/theme/create-theme-hook.cjs +105 -0
- package/dist/react/theme/create-theme-hook.cjs.map +1 -0
- package/dist/react/theme/create-theme-hook.d.cts +29 -0
- package/dist/react/theme/create-theme-hook.d.cts.map +1 -0
- package/dist/react/theme/create-theme-hook.d.mts +29 -0
- package/dist/react/theme/create-theme-hook.d.mts.map +1 -0
- package/dist/react/theme/create-theme-hook.mjs +104 -0
- package/dist/react/theme/create-theme-hook.mjs.map +1 -0
- package/dist/react.cjs +15 -0
- package/dist/react.d.cts +8 -0
- package/dist/react.d.mts +8 -0
- package/dist/react.mjs +9 -0
- package/dist/style/css-properties.d.cts +20 -0
- package/dist/style/css-properties.d.cts.map +1 -0
- package/dist/style/css-properties.d.mts +20 -0
- package/dist/style/css-properties.d.mts.map +1 -0
- package/dist/style/define-css-properties.cjs +25 -0
- package/dist/style/define-css-properties.cjs.map +1 -0
- package/dist/style/define-css-properties.d.cts +24 -0
- package/dist/style/define-css-properties.d.cts.map +1 -0
- package/dist/style/define-css-properties.d.mts +24 -0
- package/dist/style/define-css-properties.d.mts.map +1 -0
- package/dist/style/define-css-properties.mjs +24 -0
- package/dist/style/define-css-properties.mjs.map +1 -0
- package/dist/style/get-css-variable-value.cjs +11 -0
- package/dist/style/get-css-variable-value.cjs.map +1 -0
- package/dist/style/get-css-variable-value.d.cts +22 -0
- package/dist/style/get-css-variable-value.d.cts.map +1 -0
- package/dist/style/get-css-variable-value.d.mts +22 -0
- package/dist/style/get-css-variable-value.d.mts.map +1 -0
- package/dist/style/get-css-variable-value.mjs +10 -0
- package/dist/style/get-css-variable-value.mjs.map +1 -0
- package/dist/style/just-style.d.cts +44 -0
- package/dist/style/just-style.d.cts.map +1 -0
- package/dist/style/just-style.d.mts +44 -0
- package/dist/style/just-style.d.mts.map +1 -0
- package/dist/style/resolve-style.cjs +14 -0
- package/dist/style/resolve-style.cjs.map +1 -0
- package/dist/style/resolve-style.d.cts +11 -0
- package/dist/style/resolve-style.d.cts.map +1 -0
- package/dist/style/resolve-style.d.mts +11 -0
- package/dist/style/resolve-style.d.mts.map +1 -0
- package/dist/style/resolve-style.mjs +13 -0
- package/dist/style/resolve-style.mjs.map +1 -0
- package/dist/style/style-props.d.cts +13 -0
- package/dist/style/style-props.d.cts.map +1 -0
- package/dist/style/style-props.d.mts +13 -0
- package/dist/style/style-props.d.mts.map +1 -0
- package/dist/style/to-dom-style.cjs +33 -0
- package/dist/style/to-dom-style.cjs.map +1 -0
- package/dist/style/to-dom-style.d.cts +29 -0
- package/dist/style/to-dom-style.d.cts.map +1 -0
- package/dist/style/to-dom-style.d.mts +29 -0
- package/dist/style/to-dom-style.d.mts.map +1 -0
- package/dist/style/to-dom-style.mjs +32 -0
- package/dist/style/to-dom-style.mjs.map +1 -0
- package/dist/testing/theme/dummy-theme-store.cjs +11 -0
- package/dist/testing/theme/dummy-theme-store.cjs.map +1 -0
- package/dist/testing/theme/dummy-theme-store.mjs +10 -0
- package/dist/testing/theme/dummy-theme-store.mjs.map +1 -0
- package/dist/theme/_utils/get-theme-from-stores.cjs +24 -0
- package/dist/theme/_utils/get-theme-from-stores.cjs.map +1 -0
- package/dist/theme/_utils/get-theme-from-stores.mjs +23 -0
- package/dist/theme/_utils/get-theme-from-stores.mjs.map +1 -0
- package/dist/theme/_utils/observe-theme-from-stores.cjs +39 -0
- package/dist/theme/_utils/observe-theme-from-stores.cjs.map +1 -0
- package/dist/theme/_utils/observe-theme-from-stores.mjs +39 -0
- package/dist/theme/_utils/observe-theme-from-stores.mjs.map +1 -0
- package/dist/theme/_utils/parse-stored-theme.cjs +22 -0
- package/dist/theme/_utils/parse-stored-theme.cjs.map +1 -0
- package/dist/theme/_utils/parse-stored-theme.mjs +22 -0
- package/dist/theme/_utils/parse-stored-theme.mjs.map +1 -0
- package/dist/theme/_utils/set-theme-to-stores.cjs +16 -0
- package/dist/theme/_utils/set-theme-to-stores.cjs.map +1 -0
- package/dist/theme/_utils/set-theme-to-stores.mjs +15 -0
- package/dist/theme/_utils/set-theme-to-stores.mjs.map +1 -0
- package/dist/theme/class-name/apply-theme-to-class-name.cjs +23 -0
- package/dist/theme/class-name/apply-theme-to-class-name.cjs.map +1 -0
- package/dist/theme/class-name/apply-theme-to-class-name.mjs +22 -0
- package/dist/theme/class-name/apply-theme-to-class-name.mjs.map +1 -0
- package/dist/theme/class-name/resolve-theme-from-class-name.cjs +23 -0
- package/dist/theme/class-name/resolve-theme-from-class-name.cjs.map +1 -0
- package/dist/theme/class-name/resolve-theme-from-class-name.mjs +22 -0
- package/dist/theme/class-name/resolve-theme-from-class-name.mjs.map +1 -0
- package/dist/theme/compose-theme-stores.cjs +74 -0
- package/dist/theme/compose-theme-stores.cjs.map +1 -0
- package/dist/theme/compose-theme-stores.d.cts +33 -0
- package/dist/theme/compose-theme-stores.d.cts.map +1 -0
- package/dist/theme/compose-theme-stores.d.mts +33 -0
- package/dist/theme/compose-theme-stores.d.mts.map +1 -0
- package/dist/theme/compose-theme-stores.mjs +74 -0
- package/dist/theme/compose-theme-stores.mjs.map +1 -0
- package/dist/theme/data-attribute/apply-theme-to-data-attribute.cjs +23 -0
- package/dist/theme/data-attribute/apply-theme-to-data-attribute.cjs.map +1 -0
- package/dist/theme/data-attribute/apply-theme-to-data-attribute.mjs +22 -0
- package/dist/theme/data-attribute/apply-theme-to-data-attribute.mjs.map +1 -0
- package/dist/theme/data-attribute/resolve-theme-from-data-attribute.cjs +23 -0
- package/dist/theme/data-attribute/resolve-theme-from-data-attribute.cjs.map +1 -0
- package/dist/theme/data-attribute/resolve-theme-from-data-attribute.mjs +22 -0
- package/dist/theme/data-attribute/resolve-theme-from-data-attribute.mjs.map +1 -0
- package/dist/theme/theme-entry.cjs +13 -0
- package/dist/theme/theme-entry.cjs.map +1 -0
- package/dist/theme/theme-entry.d.cts +9 -0
- package/dist/theme/theme-entry.d.cts.map +1 -0
- package/dist/theme/theme-entry.d.mts +9 -0
- package/dist/theme/theme-entry.d.mts.map +1 -0
- package/dist/theme/theme-entry.mjs +12 -0
- package/dist/theme/theme-entry.mjs.map +1 -0
- package/dist/theme/theme-entry.types.d.cts +16 -0
- package/dist/theme/theme-entry.types.d.cts.map +1 -0
- package/dist/theme/theme-entry.types.d.mts +16 -0
- package/dist/theme/theme-entry.types.d.mts.map +1 -0
- package/dist/theme/theme-map.types.d.cts +10 -0
- package/dist/theme/theme-map.types.d.cts.map +1 -0
- package/dist/theme/theme-map.types.d.mts +10 -0
- package/dist/theme/theme-map.types.d.mts.map +1 -0
- package/dist/theme/theme-store/async-theme-store.types.d.cts +25 -0
- package/dist/theme/theme-store/async-theme-store.types.d.cts.map +1 -0
- package/dist/theme/theme-store/async-theme-store.types.d.mts +25 -0
- package/dist/theme/theme-store/async-theme-store.types.d.mts.map +1 -0
- package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.cjs +53 -0
- package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.cjs.map +1 -0
- package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.d.cts +28 -0
- package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.d.cts.map +1 -0
- package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.d.mts +28 -0
- package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.d.mts.map +1 -0
- package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.mjs +53 -0
- package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.mjs.map +1 -0
- package/dist/theme/theme-store/cookie-theme-store/cookie-theme-store.cjs +121 -0
- package/dist/theme/theme-store/cookie-theme-store/cookie-theme-store.cjs.map +1 -0
- package/dist/theme/theme-store/cookie-theme-store/cookie-theme-store.d.cts +65 -0
- package/dist/theme/theme-store/cookie-theme-store/cookie-theme-store.d.cts.map +1 -0
- package/dist/theme/theme-store/cookie-theme-store/cookie-theme-store.d.mts +65 -0
- package/dist/theme/theme-store/cookie-theme-store/cookie-theme-store.d.mts.map +1 -0
- package/dist/theme/theme-store/cookie-theme-store/cookie-theme-store.mjs +120 -0
- package/dist/theme/theme-store/cookie-theme-store/cookie-theme-store.mjs.map +1 -0
- package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.cjs +51 -0
- package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.cjs.map +1 -0
- package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.d.cts +30 -0
- package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.d.cts.map +1 -0
- package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.d.mts +30 -0
- package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.d.mts.map +1 -0
- package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.mjs +51 -0
- package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.mjs.map +1 -0
- package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.cjs +54 -0
- package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.cjs.map +1 -0
- package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.d.cts +31 -0
- package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.d.cts.map +1 -0
- package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.d.mts +31 -0
- package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.d.mts.map +1 -0
- package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.mjs +54 -0
- package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.mjs.map +1 -0
- package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.cjs +67 -0
- package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.cjs.map +1 -0
- package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.d.cts +34 -0
- package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.d.cts.map +1 -0
- package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.d.mts +34 -0
- package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.d.mts.map +1 -0
- package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.mjs +67 -0
- package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.mjs.map +1 -0
- package/dist/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.cjs +39 -0
- package/dist/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.cjs.map +1 -0
- package/dist/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.d.cts +32 -0
- package/dist/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.d.cts.map +1 -0
- package/dist/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.d.mts +32 -0
- package/dist/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.d.mts.map +1 -0
- package/dist/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.mjs +39 -0
- package/dist/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.mjs.map +1 -0
- package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.cjs +67 -0
- package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.cjs.map +1 -0
- package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.d.cts +34 -0
- package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.d.cts.map +1 -0
- package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.d.mts +34 -0
- package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.d.mts.map +1 -0
- package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.mjs +67 -0
- package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.mjs.map +1 -0
- package/dist/theme/theme-store/theme-store-factory.types.d.cts +10 -0
- package/dist/theme/theme-store/theme-store-factory.types.d.cts.map +1 -0
- package/dist/theme/theme-store/theme-store-factory.types.d.mts +10 -0
- package/dist/theme/theme-store/theme-store-factory.types.d.mts.map +1 -0
- package/dist/theme/theme-store/theme-store.types.d.cts +33 -0
- package/dist/theme/theme-store/theme-store.types.d.cts.map +1 -0
- package/dist/theme/theme-store/theme-store.types.d.mts +33 -0
- package/dist/theme/theme-store/theme-store.types.d.mts.map +1 -0
- package/dist/theme.cjs +20 -0
- package/dist/theme.d.cts +15 -0
- package/dist/theme.d.mts +15 -0
- package/dist/theme.mjs +11 -0
- package/dist/units/get-rem-to-px-scale.cjs +30 -0
- package/dist/units/get-rem-to-px-scale.cjs.map +1 -0
- package/dist/units/get-rem-to-px-scale.d.cts +21 -0
- package/dist/units/get-rem-to-px-scale.d.cts.map +1 -0
- package/dist/units/get-rem-to-px-scale.d.mts +21 -0
- package/dist/units/get-rem-to-px-scale.d.mts.map +1 -0
- package/dist/units/get-rem-to-px-scale.mjs +29 -0
- package/dist/units/get-rem-to-px-scale.mjs.map +1 -0
- package/dist/units/px-2-num.cjs +23 -0
- package/dist/units/px-2-num.cjs.map +1 -0
- package/dist/units/px-2-num.d.cts +19 -0
- package/dist/units/px-2-num.d.cts.map +1 -0
- package/dist/units/px-2-num.d.mts +19 -0
- package/dist/units/px-2-num.d.mts.map +1 -0
- package/dist/units/px-2-num.mjs +22 -0
- package/dist/units/px-2-num.mjs.map +1 -0
- package/dist/units/px-2-rem.cjs +31 -0
- package/dist/units/px-2-rem.cjs.map +1 -0
- package/dist/units/px-2-rem.d.cts +25 -0
- package/dist/units/px-2-rem.d.cts.map +1 -0
- package/dist/units/px-2-rem.d.mts +25 -0
- package/dist/units/px-2-rem.d.mts.map +1 -0
- package/dist/units/px-2-rem.mjs +30 -0
- package/dist/units/px-2-rem.mjs.map +1 -0
- package/dist/units/rem-2-px.cjs +31 -0
- package/dist/units/rem-2-px.cjs.map +1 -0
- package/dist/units/rem-2-px.d.cts +25 -0
- package/dist/units/rem-2-px.d.cts.map +1 -0
- package/dist/units/rem-2-px.d.mts +25 -0
- package/dist/units/rem-2-px.d.mts.map +1 -0
- package/dist/units/rem-2-px.mjs +30 -0
- package/dist/units/rem-2-px.mjs.map +1 -0
- package/dist/utils/append-id.cjs +16 -0
- package/dist/utils/append-id.cjs.map +1 -0
- package/dist/utils/append-id.d.cts +12 -0
- package/dist/utils/append-id.d.cts.map +1 -0
- package/dist/utils/append-id.d.mts +12 -0
- package/dist/utils/append-id.d.mts.map +1 -0
- package/dist/utils/append-id.mjs +15 -0
- package/dist/utils/append-id.mjs.map +1 -0
- package/package.json +120 -0
- package/readme.md +15 -0
- package/src/_internal/utils/try-parse-json.ts +8 -0
- package/src/attributes/data-attribute.ts +49 -0
- package/src/attributes/get-attribute.ts +20 -0
- package/src/attributes/get-data-attribute.ts +15 -0
- package/src/attributes/observe-attribute.ts +37 -0
- package/src/attributes/observe-data-attribute.ts +29 -0
- package/src/children/just-children-fn-props.editor.default.tsx +29 -0
- package/src/children/just-children-props.editor.default.tsx +17 -0
- package/src/children/just-children.editor.default.tsx +11 -0
- package/src/children/just-children.ts +37 -0
- package/src/children/resolve-children.ts +16 -0
- package/src/class-name/class-name-props.editor.tsx +13 -0
- package/src/class-name/class-name-props.ts +7 -0
- package/src/class-name/clsx.ts +3 -0
- package/src/class-name/just-class-name-props.editor.default.tsx +23 -0
- package/src/class-name/just-class-name-resolver-state.editor.default.tsx +18 -0
- package/src/class-name/just-class-name.editor.default-class-name.tsx +28 -0
- package/src/class-name/just-class-name.editor.default.tsx +14 -0
- package/src/class-name/just-class-name.editor.type-param.tsx +25 -0
- package/src/class-name/just-class-name.ts +36 -0
- package/src/class-name/resolve-class-name.ts +12 -0
- package/src/color-scheme/get-prefers-color-scheme.ts +17 -0
- package/src/color-scheme/observe-prefers-color-scheme.ts +24 -0
- package/src/index.ts +25 -0
- package/src/react/hooks/use-attribute.ts +59 -0
- package/src/react/hooks/use-prefers-color-scheme.ts +42 -0
- package/src/react/hooks/use-theme-by-class-name.ts +69 -0
- package/src/react/hooks/use-theme-by-data-attribute.ts +84 -0
- package/src/react/hooks/use-theme-by-local-storage.ts +68 -0
- package/src/react/hooks/use-theme-stores.ts +83 -0
- package/src/react/theme/create-theme-hook.ts +197 -0
- package/src/react.ts +7 -0
- package/src/style/css-properties.ts +20 -0
- package/src/style/define-css-properties.ts +23 -0
- package/src/style/get-css-variable-value.ts +32 -0
- package/src/style/just-style-props.editor.default.tsx +17 -0
- package/src/style/just-style-resolver-state.editor.default.tsx +22 -0
- package/src/style/just-style.editor.default.tsx +17 -0
- package/src/style/just-style.editor.type-param.tsx +31 -0
- package/src/style/just-style.ts +60 -0
- package/src/style/resolve-style.ts +23 -0
- package/src/style/style-props.editor.tsx +13 -0
- package/src/style/style-props.ts +8 -0
- package/src/style/to-dom-style.ts +36 -0
- package/src/testing/button.theme.ts +21 -0
- package/src/testing/button.tsx +11 -0
- package/src/testing/log-panel.tsx +14 -0
- package/src/testing/theme/dummy-theme-store.ts +7 -0
- package/src/testing/theme/theme-result-card.tsx +43 -0
- package/src/testing/theme/theme-store-demo.tsx +87 -0
- package/src/theme/_utils/get-theme-from-stores.ts +34 -0
- package/src/theme/_utils/observe-theme-from-stores.ts +57 -0
- package/src/theme/_utils/parse-stored-theme.ts +21 -0
- package/src/theme/_utils/set-theme-to-stores.ts +23 -0
- package/src/theme/class-name/apply-theme-to-class-name.ts +26 -0
- package/src/theme/class-name/resolve-theme-from-class-name.ts +22 -0
- package/src/theme/compose-theme-stores.ts +139 -0
- package/src/theme/data-attribute/apply-theme-to-data-attribute.ts +27 -0
- package/src/theme/data-attribute/resolve-theme-from-data-attribute.ts +23 -0
- package/src/theme/theme-entry.ts +10 -0
- package/src/theme/theme-entry.types.ts +11 -0
- package/src/theme/theme-map.types.ts +6 -0
- package/src/theme/theme-store/async-theme-store.types.ts +24 -0
- package/src/theme/theme-store/class-name-theme-store/class-name-theme-store.ts +62 -0
- package/src/theme/theme-store/cookie-theme-store/cookie-theme-store.ts +174 -0
- package/src/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.ts +60 -0
- package/src/theme/theme-store/in-memory-theme-store/in-memory-theme-store.ts +54 -0
- package/src/theme/theme-store/local-storage-theme-store/local-storage-theme-store.ts +83 -0
- package/src/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.ts +43 -0
- package/src/theme/theme-store/session-storage-theme-store/session-storage-theme-store.ts +83 -0
- package/src/theme/theme-store/theme-store-factory.types.ts +9 -0
- package/src/theme/theme-store/theme-store.types.ts +30 -0
- package/src/theme.ts +14 -0
- package/src/units/get-rem-to-px-scale.ts +27 -0
- package/src/units/px-2-num.ts +17 -0
- package/src/units/px-2-rem.ts +30 -0
- package/src/units/rem-2-px.ts +30 -0
- package/src/utils/append-id.ts +10 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const require_theme_entry = require('../../theme-entry.cjs');
|
|
2
|
+
const require_dummy_theme_store = require('../../../testing/theme/dummy-theme-store.cjs');
|
|
3
|
+
const require_parse_stored_theme = require('../../_utils/parse-stored-theme.cjs');
|
|
4
|
+
|
|
5
|
+
//#region src/theme/theme-store/local-storage-theme-store/local-storage-theme-store.ts
|
|
6
|
+
/**
|
|
7
|
+
* Creates a theme store backed by localStorage.
|
|
8
|
+
*
|
|
9
|
+
* Persists across sessions; cross-tab sync via StorageEvent.
|
|
10
|
+
* Same-tab writes trigger manual notify (StorageEvent does not fire for same tab).
|
|
11
|
+
*
|
|
12
|
+
* @param themes - Record mapping theme keys to values (for validation)
|
|
13
|
+
* @param options.storageKey - localStorage key
|
|
14
|
+
* @returns ThemeStore
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const themes = { current: 'theme-current', grayscale: 'theme-grayscale' }
|
|
19
|
+
* const store = localStorageThemeStore(themes, { storageKey: 'theme' })
|
|
20
|
+
* store.read() // returns themeResult from localStorage
|
|
21
|
+
* store.write(themeEntry(themes, 'grayscale'))
|
|
22
|
+
* store.subscribe((themeResult) => {})
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
function localStorageThemeStore(themes, options) {
|
|
26
|
+
const { storageKey } = options;
|
|
27
|
+
if (typeof window === "undefined" || !window.localStorage) return require_dummy_theme_store.dummyThemeStore;
|
|
28
|
+
const handlers = /* @__PURE__ */ new Set();
|
|
29
|
+
let lastNotifiedKey = read()?.theme ?? void 0;
|
|
30
|
+
function read() {
|
|
31
|
+
const theme = require_parse_stored_theme.parseStoredTheme(themes, window.localStorage.getItem(storageKey));
|
|
32
|
+
if (theme === void 0) return void 0;
|
|
33
|
+
return require_theme_entry.themeEntry(themes, theme);
|
|
34
|
+
}
|
|
35
|
+
function notify() {
|
|
36
|
+
const result = read();
|
|
37
|
+
const key = result?.theme ?? void 0;
|
|
38
|
+
if (key === lastNotifiedKey) return;
|
|
39
|
+
lastNotifiedKey = key;
|
|
40
|
+
for (const h of handlers) h(result);
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
read,
|
|
44
|
+
write(entry) {
|
|
45
|
+
try {
|
|
46
|
+
if (entry === void 0) window.localStorage.removeItem(storageKey);
|
|
47
|
+
else window.localStorage.setItem(storageKey, JSON.stringify(entry));
|
|
48
|
+
notify();
|
|
49
|
+
} catch {}
|
|
50
|
+
},
|
|
51
|
+
subscribe(handler) {
|
|
52
|
+
handlers.add(handler);
|
|
53
|
+
const onStorage = (e) => {
|
|
54
|
+
if (e.key === storageKey && e.storageArea === window.localStorage) notify();
|
|
55
|
+
};
|
|
56
|
+
window.addEventListener("storage", onStorage);
|
|
57
|
+
return () => {
|
|
58
|
+
handlers.delete(handler);
|
|
59
|
+
window.removeEventListener("storage", onStorage);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
exports.localStorageThemeStore = localStorageThemeStore;
|
|
67
|
+
//# sourceMappingURL=local-storage-theme-store.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-storage-theme-store.cjs","names":["dummyThemeStore","lastNotifiedKey: keyof Themes | undefined","parseStoredTheme","themeEntry"],"sources":["../../../../src/theme/theme-store/local-storage-theme-store/local-storage-theme-store.ts"],"sourcesContent":["import { dummyThemeStore } from '../../../testing/theme/dummy-theme-store.ts'\nimport { parseStoredTheme } from '../../_utils/parse-stored-theme.ts'\nimport { themeEntry } from '../../theme-entry.ts'\nimport type { ThemeEntry } from '../../theme-entry.types.ts'\nimport type { ThemeMap } from '../../theme-map.types.ts'\nimport type { ThemeStore } from '../theme-store.types.ts'\n\n/**\n * Creates a theme store backed by localStorage.\n *\n * Persists across sessions; cross-tab sync via StorageEvent.\n * Same-tab writes trigger manual notify (StorageEvent does not fire for same tab).\n *\n * @param themes - Record mapping theme keys to values (for validation)\n * @param options.storageKey - localStorage key\n * @returns ThemeStore\n *\n * @example\n * ```ts\n * const themes = { current: 'theme-current', grayscale: 'theme-grayscale' }\n * const store = localStorageThemeStore(themes, { storageKey: 'theme' })\n * store.read() // returns themeResult from localStorage\n * store.write(themeEntry(themes, 'grayscale'))\n * store.subscribe((themeResult) => {})\n * ```\n */\nexport function localStorageThemeStore<Themes extends ThemeMap>(\n\tthemes: Themes,\n\toptions: { storageKey: string }\n) {\n\tconst { storageKey } = options\n\n\tif (typeof window === 'undefined' || !window.localStorage) {\n\t\treturn dummyThemeStore satisfies ThemeStore<Themes>\n\t}\n\n\tconst handlers = new Set<(theme: ThemeEntry<Themes> | undefined) => void>()\n\tlet lastNotifiedKey: keyof Themes | undefined = read()?.theme ?? undefined\n\n\tfunction read() {\n\t\tconst stored = window.localStorage.getItem(storageKey)\n\t\tconst theme = parseStoredTheme(themes, stored)\n\t\tif (theme === undefined) return undefined\n\t\treturn themeEntry(themes, theme)\n\t}\n\n\tfunction notify() {\n\t\tconst result = read()\n\t\tconst key = result?.theme ?? undefined\n\t\tif (key === lastNotifiedKey) return\n\t\tlastNotifiedKey = key\n\t\tfor (const h of handlers) h(result)\n\t}\n\n\treturn {\n\t\tread,\n\t\twrite(entry) {\n\t\t\ttry {\n\t\t\t\tif (entry === undefined) {\n\t\t\t\t\twindow.localStorage.removeItem(storageKey)\n\t\t\t\t} else {\n\t\t\t\t\twindow.localStorage.setItem(storageKey, JSON.stringify(entry))\n\t\t\t\t}\n\t\t\t\tnotify()\n\t\t\t} catch {\n\t\t\t\t// Ignore quota or other errors\n\t\t\t}\n\t\t},\n\t\tsubscribe(handler) {\n\t\t\thandlers.add(handler)\n\n\t\t\tconst onStorage = (e: StorageEvent) => {\n\t\t\t\tif (e.key === storageKey && e.storageArea === window.localStorage) notify()\n\t\t\t}\n\t\t\twindow.addEventListener('storage', onStorage)\n\n\t\t\treturn () => {\n\t\t\t\thandlers.delete(handler)\n\t\t\t\twindow.removeEventListener('storage', onStorage)\n\t\t\t}\n\t\t}\n\t} satisfies ThemeStore<Themes>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA0BA,SAAgB,uBACf,QACA,SACC;CACD,MAAM,EAAE,eAAe;AAEvB,KAAI,OAAO,WAAW,eAAe,CAAC,OAAO,aAC5C,QAAOA;CAGR,MAAM,2BAAW,IAAI,KAAsD;CAC3E,IAAIC,kBAA4C,MAAM,EAAE,SAAS;CAEjE,SAAS,OAAO;EAEf,MAAM,QAAQC,4CAAiB,QADhB,OAAO,aAAa,QAAQ,WAAW,CACR;AAC9C,MAAI,UAAU,OAAW,QAAO;AAChC,SAAOC,+BAAW,QAAQ,MAAM;;CAGjC,SAAS,SAAS;EACjB,MAAM,SAAS,MAAM;EACrB,MAAM,MAAM,QAAQ,SAAS;AAC7B,MAAI,QAAQ,gBAAiB;AAC7B,oBAAkB;AAClB,OAAK,MAAM,KAAK,SAAU,GAAE,OAAO;;AAGpC,QAAO;EACN;EACA,MAAM,OAAO;AACZ,OAAI;AACH,QAAI,UAAU,OACb,QAAO,aAAa,WAAW,WAAW;QAE1C,QAAO,aAAa,QAAQ,YAAY,KAAK,UAAU,MAAM,CAAC;AAE/D,YAAQ;WACD;;EAIT,UAAU,SAAS;AAClB,YAAS,IAAI,QAAQ;GAErB,MAAM,aAAa,MAAoB;AACtC,QAAI,EAAE,QAAQ,cAAc,EAAE,gBAAgB,OAAO,aAAc,SAAQ;;AAE5E,UAAO,iBAAiB,WAAW,UAAU;AAE7C,gBAAa;AACZ,aAAS,OAAO,QAAQ;AACxB,WAAO,oBAAoB,WAAW,UAAU;;;EAGlD"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ThemeMap } from "../../theme-map.types.cjs";
|
|
2
|
+
import { ThemeEntry } from "../../theme-entry.types.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/theme/theme-store/local-storage-theme-store/local-storage-theme-store.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Creates a theme store backed by localStorage.
|
|
8
|
+
*
|
|
9
|
+
* Persists across sessions; cross-tab sync via StorageEvent.
|
|
10
|
+
* Same-tab writes trigger manual notify (StorageEvent does not fire for same tab).
|
|
11
|
+
*
|
|
12
|
+
* @param themes - Record mapping theme keys to values (for validation)
|
|
13
|
+
* @param options.storageKey - localStorage key
|
|
14
|
+
* @returns ThemeStore
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const themes = { current: 'theme-current', grayscale: 'theme-grayscale' }
|
|
19
|
+
* const store = localStorageThemeStore(themes, { storageKey: 'theme' })
|
|
20
|
+
* store.read() // returns themeResult from localStorage
|
|
21
|
+
* store.write(themeEntry(themes, 'grayscale'))
|
|
22
|
+
* store.subscribe((themeResult) => {})
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
declare function localStorageThemeStore<Themes extends ThemeMap>(themes: Themes, options: {
|
|
26
|
+
storageKey: string;
|
|
27
|
+
}): {
|
|
28
|
+
read: () => ThemeEntry<Themes> | undefined;
|
|
29
|
+
write(entry: ThemeEntry<Themes> | undefined): void;
|
|
30
|
+
subscribe(handler: (theme: ThemeEntry<Themes> | null | undefined) => void): () => void;
|
|
31
|
+
};
|
|
32
|
+
//#endregion
|
|
33
|
+
export { localStorageThemeStore };
|
|
34
|
+
//# sourceMappingURL=local-storage-theme-store.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-storage-theme-store.d.cts","names":[],"sources":["../../../../src/theme/theme-store/local-storage-theme-store/local-storage-theme-store.ts"],"sourcesContent":[],"mappings":";;;;;;;AA0BA;;;;;;;;;;;;;;;;;iBAAgB,sCAAsC,kBAC7C"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ThemeMap } from "../../theme-map.types.mjs";
|
|
2
|
+
import { ThemeEntry } from "../../theme-entry.types.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/theme/theme-store/local-storage-theme-store/local-storage-theme-store.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Creates a theme store backed by localStorage.
|
|
8
|
+
*
|
|
9
|
+
* Persists across sessions; cross-tab sync via StorageEvent.
|
|
10
|
+
* Same-tab writes trigger manual notify (StorageEvent does not fire for same tab).
|
|
11
|
+
*
|
|
12
|
+
* @param themes - Record mapping theme keys to values (for validation)
|
|
13
|
+
* @param options.storageKey - localStorage key
|
|
14
|
+
* @returns ThemeStore
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const themes = { current: 'theme-current', grayscale: 'theme-grayscale' }
|
|
19
|
+
* const store = localStorageThemeStore(themes, { storageKey: 'theme' })
|
|
20
|
+
* store.read() // returns themeResult from localStorage
|
|
21
|
+
* store.write(themeEntry(themes, 'grayscale'))
|
|
22
|
+
* store.subscribe((themeResult) => {})
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
declare function localStorageThemeStore<Themes extends ThemeMap>(themes: Themes, options: {
|
|
26
|
+
storageKey: string;
|
|
27
|
+
}): {
|
|
28
|
+
read: () => ThemeEntry<Themes> | undefined;
|
|
29
|
+
write(entry: ThemeEntry<Themes> | undefined): void;
|
|
30
|
+
subscribe(handler: (theme: ThemeEntry<Themes> | null | undefined) => void): () => void;
|
|
31
|
+
};
|
|
32
|
+
//#endregion
|
|
33
|
+
export { localStorageThemeStore };
|
|
34
|
+
//# sourceMappingURL=local-storage-theme-store.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-storage-theme-store.d.mts","names":[],"sources":["../../../../src/theme/theme-store/local-storage-theme-store/local-storage-theme-store.ts"],"sourcesContent":[],"mappings":";;;;;;;AA0BA;;;;;;;;;;;;;;;;;iBAAgB,sCAAsC,kBAC7C"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { themeEntry } from "../../theme-entry.mjs";
|
|
2
|
+
import { dummyThemeStore } from "../../../testing/theme/dummy-theme-store.mjs";
|
|
3
|
+
import { parseStoredTheme } from "../../_utils/parse-stored-theme.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/theme/theme-store/local-storage-theme-store/local-storage-theme-store.ts
|
|
6
|
+
/**
|
|
7
|
+
* Creates a theme store backed by localStorage.
|
|
8
|
+
*
|
|
9
|
+
* Persists across sessions; cross-tab sync via StorageEvent.
|
|
10
|
+
* Same-tab writes trigger manual notify (StorageEvent does not fire for same tab).
|
|
11
|
+
*
|
|
12
|
+
* @param themes - Record mapping theme keys to values (for validation)
|
|
13
|
+
* @param options.storageKey - localStorage key
|
|
14
|
+
* @returns ThemeStore
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const themes = { current: 'theme-current', grayscale: 'theme-grayscale' }
|
|
19
|
+
* const store = localStorageThemeStore(themes, { storageKey: 'theme' })
|
|
20
|
+
* store.read() // returns themeResult from localStorage
|
|
21
|
+
* store.write(themeEntry(themes, 'grayscale'))
|
|
22
|
+
* store.subscribe((themeResult) => {})
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
function localStorageThemeStore(themes, options) {
|
|
26
|
+
const { storageKey } = options;
|
|
27
|
+
if (typeof window === "undefined" || !window.localStorage) return dummyThemeStore;
|
|
28
|
+
const handlers = /* @__PURE__ */ new Set();
|
|
29
|
+
let lastNotifiedKey = read()?.theme ?? void 0;
|
|
30
|
+
function read() {
|
|
31
|
+
const theme = parseStoredTheme(themes, window.localStorage.getItem(storageKey));
|
|
32
|
+
if (theme === void 0) return void 0;
|
|
33
|
+
return themeEntry(themes, theme);
|
|
34
|
+
}
|
|
35
|
+
function notify() {
|
|
36
|
+
const result = read();
|
|
37
|
+
const key = result?.theme ?? void 0;
|
|
38
|
+
if (key === lastNotifiedKey) return;
|
|
39
|
+
lastNotifiedKey = key;
|
|
40
|
+
for (const h of handlers) h(result);
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
read,
|
|
44
|
+
write(entry) {
|
|
45
|
+
try {
|
|
46
|
+
if (entry === void 0) window.localStorage.removeItem(storageKey);
|
|
47
|
+
else window.localStorage.setItem(storageKey, JSON.stringify(entry));
|
|
48
|
+
notify();
|
|
49
|
+
} catch {}
|
|
50
|
+
},
|
|
51
|
+
subscribe(handler) {
|
|
52
|
+
handlers.add(handler);
|
|
53
|
+
const onStorage = (e) => {
|
|
54
|
+
if (e.key === storageKey && e.storageArea === window.localStorage) notify();
|
|
55
|
+
};
|
|
56
|
+
window.addEventListener("storage", onStorage);
|
|
57
|
+
return () => {
|
|
58
|
+
handlers.delete(handler);
|
|
59
|
+
window.removeEventListener("storage", onStorage);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
export { localStorageThemeStore };
|
|
67
|
+
//# sourceMappingURL=local-storage-theme-store.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-storage-theme-store.mjs","names":["lastNotifiedKey: keyof Themes | undefined"],"sources":["../../../../src/theme/theme-store/local-storage-theme-store/local-storage-theme-store.ts"],"sourcesContent":["import { dummyThemeStore } from '../../../testing/theme/dummy-theme-store.ts'\nimport { parseStoredTheme } from '../../_utils/parse-stored-theme.ts'\nimport { themeEntry } from '../../theme-entry.ts'\nimport type { ThemeEntry } from '../../theme-entry.types.ts'\nimport type { ThemeMap } from '../../theme-map.types.ts'\nimport type { ThemeStore } from '../theme-store.types.ts'\n\n/**\n * Creates a theme store backed by localStorage.\n *\n * Persists across sessions; cross-tab sync via StorageEvent.\n * Same-tab writes trigger manual notify (StorageEvent does not fire for same tab).\n *\n * @param themes - Record mapping theme keys to values (for validation)\n * @param options.storageKey - localStorage key\n * @returns ThemeStore\n *\n * @example\n * ```ts\n * const themes = { current: 'theme-current', grayscale: 'theme-grayscale' }\n * const store = localStorageThemeStore(themes, { storageKey: 'theme' })\n * store.read() // returns themeResult from localStorage\n * store.write(themeEntry(themes, 'grayscale'))\n * store.subscribe((themeResult) => {})\n * ```\n */\nexport function localStorageThemeStore<Themes extends ThemeMap>(\n\tthemes: Themes,\n\toptions: { storageKey: string }\n) {\n\tconst { storageKey } = options\n\n\tif (typeof window === 'undefined' || !window.localStorage) {\n\t\treturn dummyThemeStore satisfies ThemeStore<Themes>\n\t}\n\n\tconst handlers = new Set<(theme: ThemeEntry<Themes> | undefined) => void>()\n\tlet lastNotifiedKey: keyof Themes | undefined = read()?.theme ?? undefined\n\n\tfunction read() {\n\t\tconst stored = window.localStorage.getItem(storageKey)\n\t\tconst theme = parseStoredTheme(themes, stored)\n\t\tif (theme === undefined) return undefined\n\t\treturn themeEntry(themes, theme)\n\t}\n\n\tfunction notify() {\n\t\tconst result = read()\n\t\tconst key = result?.theme ?? undefined\n\t\tif (key === lastNotifiedKey) return\n\t\tlastNotifiedKey = key\n\t\tfor (const h of handlers) h(result)\n\t}\n\n\treturn {\n\t\tread,\n\t\twrite(entry) {\n\t\t\ttry {\n\t\t\t\tif (entry === undefined) {\n\t\t\t\t\twindow.localStorage.removeItem(storageKey)\n\t\t\t\t} else {\n\t\t\t\t\twindow.localStorage.setItem(storageKey, JSON.stringify(entry))\n\t\t\t\t}\n\t\t\t\tnotify()\n\t\t\t} catch {\n\t\t\t\t// Ignore quota or other errors\n\t\t\t}\n\t\t},\n\t\tsubscribe(handler) {\n\t\t\thandlers.add(handler)\n\n\t\t\tconst onStorage = (e: StorageEvent) => {\n\t\t\t\tif (e.key === storageKey && e.storageArea === window.localStorage) notify()\n\t\t\t}\n\t\t\twindow.addEventListener('storage', onStorage)\n\n\t\t\treturn () => {\n\t\t\t\thandlers.delete(handler)\n\t\t\t\twindow.removeEventListener('storage', onStorage)\n\t\t\t}\n\t\t}\n\t} satisfies ThemeStore<Themes>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA0BA,SAAgB,uBACf,QACA,SACC;CACD,MAAM,EAAE,eAAe;AAEvB,KAAI,OAAO,WAAW,eAAe,CAAC,OAAO,aAC5C,QAAO;CAGR,MAAM,2BAAW,IAAI,KAAsD;CAC3E,IAAIA,kBAA4C,MAAM,EAAE,SAAS;CAEjE,SAAS,OAAO;EAEf,MAAM,QAAQ,iBAAiB,QADhB,OAAO,aAAa,QAAQ,WAAW,CACR;AAC9C,MAAI,UAAU,OAAW,QAAO;AAChC,SAAO,WAAW,QAAQ,MAAM;;CAGjC,SAAS,SAAS;EACjB,MAAM,SAAS,MAAM;EACrB,MAAM,MAAM,QAAQ,SAAS;AAC7B,MAAI,QAAQ,gBAAiB;AAC7B,oBAAkB;AAClB,OAAK,MAAM,KAAK,SAAU,GAAE,OAAO;;AAGpC,QAAO;EACN;EACA,MAAM,OAAO;AACZ,OAAI;AACH,QAAI,UAAU,OACb,QAAO,aAAa,WAAW,WAAW;QAE1C,QAAO,aAAa,QAAQ,YAAY,KAAK,UAAU,MAAM,CAAC;AAE/D,YAAQ;WACD;;EAIT,UAAU,SAAS;AAClB,YAAS,IAAI,QAAQ;GAErB,MAAM,aAAa,MAAoB;AACtC,QAAI,EAAE,QAAQ,cAAc,EAAE,gBAAgB,OAAO,aAAc,SAAQ;;AAE5E,UAAO,iBAAiB,WAAW,UAAU;AAE7C,gBAAa;AACZ,aAAS,OAAO,QAAQ;AACxB,WAAO,oBAAoB,WAAW,UAAU;;;EAGlD"}
|
package/dist/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.cjs
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const require_get_prefers_color_scheme = require('../../../color-scheme/get-prefers-color-scheme.cjs');
|
|
2
|
+
const require_observe_prefers_color_scheme = require('../../../color-scheme/observe-prefers-color-scheme.cjs');
|
|
3
|
+
const require_theme_entry = require('../../theme-entry.cjs');
|
|
4
|
+
|
|
5
|
+
//#region src/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.ts
|
|
6
|
+
/**
|
|
7
|
+
* Creates a read-only theme store that reads from `prefers-color-scheme`.
|
|
8
|
+
*
|
|
9
|
+
* **Color-scheme specific:** Themes must only include `light` and `dark` keys—this store
|
|
10
|
+
* mirrors the system preference which is always one of these.
|
|
11
|
+
*
|
|
12
|
+
* Returns `ThemeEntry` for `light` or `dark` based on system preference.
|
|
13
|
+
* No write method—the value is controlled by the system.
|
|
14
|
+
*
|
|
15
|
+
* @param themes - Record with `light` and `dark` keys mapping to theme values
|
|
16
|
+
* @returns ThemeStore with read and subscribe only
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const themes = { light: 'theme-light', dark: 'theme-dark' }
|
|
21
|
+
* const store = prefersColorSchemeThemeStore(themes)
|
|
22
|
+
* store.read() // ThemeEntry for current system preference
|
|
23
|
+
* store.subscribe((entry) => {})
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
function prefersColorSchemeThemeStore(themes) {
|
|
27
|
+
return {
|
|
28
|
+
read() {
|
|
29
|
+
return require_theme_entry.themeEntry(themes, require_get_prefers_color_scheme.getPrefersColorScheme());
|
|
30
|
+
},
|
|
31
|
+
subscribe(handler) {
|
|
32
|
+
return require_observe_prefers_color_scheme.observePrefersColorScheme((scheme) => handler(require_theme_entry.themeEntry(themes, scheme)));
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
exports.prefersColorSchemeThemeStore = prefersColorSchemeThemeStore;
|
|
39
|
+
//# sourceMappingURL=prefers-color-scheme-theme-store.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefers-color-scheme-theme-store.cjs","names":["themeEntry","getPrefersColorScheme","observePrefersColorScheme"],"sources":["../../../../src/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.ts"],"sourcesContent":["import type { RequiredPick } from 'type-plus'\nimport { getPrefersColorScheme } from '../../../color-scheme/get-prefers-color-scheme.ts'\nimport { observePrefersColorScheme } from '../../../color-scheme/observe-prefers-color-scheme.ts'\nimport { themeEntry } from '../../theme-entry.ts'\nimport type { ThemeStore } from '../theme-store.types.ts'\n\ntype PrefersColorSchemeThemes = {\n\tlight: string | readonly string[]\n\tdark: string | readonly string[]\n}\n\n/**\n * Creates a read-only theme store that reads from `prefers-color-scheme`.\n *\n * **Color-scheme specific:** Themes must only include `light` and `dark` keys—this store\n * mirrors the system preference which is always one of these.\n *\n * Returns `ThemeEntry` for `light` or `dark` based on system preference.\n * No write method—the value is controlled by the system.\n *\n * @param themes - Record with `light` and `dark` keys mapping to theme values\n * @returns ThemeStore with read and subscribe only\n *\n * @example\n * ```ts\n * const themes = { light: 'theme-light', dark: 'theme-dark' }\n * const store = prefersColorSchemeThemeStore(themes)\n * store.read() // ThemeEntry for current system preference\n * store.subscribe((entry) => {})\n * ```\n */\nexport function prefersColorSchemeThemeStore<Themes extends PrefersColorSchemeThemes>(\n\tthemes: Themes\n): RequiredPick<ThemeStore<Themes>, 'read' | 'subscribe'> {\n\treturn {\n\t\tread() {\n\t\t\treturn themeEntry(themes, getPrefersColorScheme())\n\t\t},\n\t\tsubscribe(handler) {\n\t\t\treturn observePrefersColorScheme((scheme) => handler(themeEntry(themes, scheme)))\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,SAAgB,6BACf,QACyD;AACzD,QAAO;EACN,OAAO;AACN,UAAOA,+BAAW,QAAQC,wDAAuB,CAAC;;EAEnD,UAAU,SAAS;AAClB,UAAOC,gEAA2B,WAAW,QAAQF,+BAAW,QAAQ,OAAO,CAAC,CAAC;;EAElF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ThemeStore } from "../theme-store.types.cjs";
|
|
2
|
+
import { RequiredPick } from "type-plus";
|
|
3
|
+
|
|
4
|
+
//#region src/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.d.ts
|
|
5
|
+
type PrefersColorSchemeThemes = {
|
|
6
|
+
light: string | readonly string[];
|
|
7
|
+
dark: string | readonly string[];
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Creates a read-only theme store that reads from `prefers-color-scheme`.
|
|
11
|
+
*
|
|
12
|
+
* **Color-scheme specific:** Themes must only include `light` and `dark` keys—this store
|
|
13
|
+
* mirrors the system preference which is always one of these.
|
|
14
|
+
*
|
|
15
|
+
* Returns `ThemeEntry` for `light` or `dark` based on system preference.
|
|
16
|
+
* No write method—the value is controlled by the system.
|
|
17
|
+
*
|
|
18
|
+
* @param themes - Record with `light` and `dark` keys mapping to theme values
|
|
19
|
+
* @returns ThemeStore with read and subscribe only
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* const themes = { light: 'theme-light', dark: 'theme-dark' }
|
|
24
|
+
* const store = prefersColorSchemeThemeStore(themes)
|
|
25
|
+
* store.read() // ThemeEntry for current system preference
|
|
26
|
+
* store.subscribe((entry) => {})
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
declare function prefersColorSchemeThemeStore<Themes extends PrefersColorSchemeThemes>(themes: Themes): RequiredPick<ThemeStore<Themes>, 'read' | 'subscribe'>;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { prefersColorSchemeThemeStore };
|
|
32
|
+
//# sourceMappingURL=prefers-color-scheme-theme-store.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefers-color-scheme-theme-store.d.cts","names":[],"sources":["../../../../src/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.ts"],"sourcesContent":[],"mappings":";;;;KAMK,wBAAA;;EAAA,IAAA,EAAA,MAAA,GAAA,SAAA,MAAwB,EAAA;AAyB7B,CAAA;;;;;;;;;;;;;;;;;;;;;iBAAgB,4CAA4C,kCACnD,SACN,aAAa,WAAW"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ThemeStore } from "../theme-store.types.mjs";
|
|
2
|
+
import { RequiredPick } from "type-plus";
|
|
3
|
+
|
|
4
|
+
//#region src/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.d.ts
|
|
5
|
+
type PrefersColorSchemeThemes = {
|
|
6
|
+
light: string | readonly string[];
|
|
7
|
+
dark: string | readonly string[];
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Creates a read-only theme store that reads from `prefers-color-scheme`.
|
|
11
|
+
*
|
|
12
|
+
* **Color-scheme specific:** Themes must only include `light` and `dark` keys—this store
|
|
13
|
+
* mirrors the system preference which is always one of these.
|
|
14
|
+
*
|
|
15
|
+
* Returns `ThemeEntry` for `light` or `dark` based on system preference.
|
|
16
|
+
* No write method—the value is controlled by the system.
|
|
17
|
+
*
|
|
18
|
+
* @param themes - Record with `light` and `dark` keys mapping to theme values
|
|
19
|
+
* @returns ThemeStore with read and subscribe only
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* const themes = { light: 'theme-light', dark: 'theme-dark' }
|
|
24
|
+
* const store = prefersColorSchemeThemeStore(themes)
|
|
25
|
+
* store.read() // ThemeEntry for current system preference
|
|
26
|
+
* store.subscribe((entry) => {})
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
declare function prefersColorSchemeThemeStore<Themes extends PrefersColorSchemeThemes>(themes: Themes): RequiredPick<ThemeStore<Themes>, 'read' | 'subscribe'>;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { prefersColorSchemeThemeStore };
|
|
32
|
+
//# sourceMappingURL=prefers-color-scheme-theme-store.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefers-color-scheme-theme-store.d.mts","names":[],"sources":["../../../../src/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.ts"],"sourcesContent":[],"mappings":";;;;KAMK,wBAAA;;EAAA,IAAA,EAAA,MAAA,GAAA,SAAA,MAAwB,EAAA;AAyB7B,CAAA;;;;;;;;;;;;;;;;;;;;;iBAAgB,4CAA4C,kCACnD,SACN,aAAa,WAAW"}
|
package/dist/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.mjs
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { getPrefersColorScheme } from "../../../color-scheme/get-prefers-color-scheme.mjs";
|
|
2
|
+
import { observePrefersColorScheme } from "../../../color-scheme/observe-prefers-color-scheme.mjs";
|
|
3
|
+
import { themeEntry } from "../../theme-entry.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.ts
|
|
6
|
+
/**
|
|
7
|
+
* Creates a read-only theme store that reads from `prefers-color-scheme`.
|
|
8
|
+
*
|
|
9
|
+
* **Color-scheme specific:** Themes must only include `light` and `dark` keys—this store
|
|
10
|
+
* mirrors the system preference which is always one of these.
|
|
11
|
+
*
|
|
12
|
+
* Returns `ThemeEntry` for `light` or `dark` based on system preference.
|
|
13
|
+
* No write method—the value is controlled by the system.
|
|
14
|
+
*
|
|
15
|
+
* @param themes - Record with `light` and `dark` keys mapping to theme values
|
|
16
|
+
* @returns ThemeStore with read and subscribe only
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const themes = { light: 'theme-light', dark: 'theme-dark' }
|
|
21
|
+
* const store = prefersColorSchemeThemeStore(themes)
|
|
22
|
+
* store.read() // ThemeEntry for current system preference
|
|
23
|
+
* store.subscribe((entry) => {})
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
function prefersColorSchemeThemeStore(themes) {
|
|
27
|
+
return {
|
|
28
|
+
read() {
|
|
29
|
+
return themeEntry(themes, getPrefersColorScheme());
|
|
30
|
+
},
|
|
31
|
+
subscribe(handler) {
|
|
32
|
+
return observePrefersColorScheme((scheme) => handler(themeEntry(themes, scheme)));
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { prefersColorSchemeThemeStore };
|
|
39
|
+
//# sourceMappingURL=prefers-color-scheme-theme-store.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefers-color-scheme-theme-store.mjs","names":[],"sources":["../../../../src/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.ts"],"sourcesContent":["import type { RequiredPick } from 'type-plus'\nimport { getPrefersColorScheme } from '../../../color-scheme/get-prefers-color-scheme.ts'\nimport { observePrefersColorScheme } from '../../../color-scheme/observe-prefers-color-scheme.ts'\nimport { themeEntry } from '../../theme-entry.ts'\nimport type { ThemeStore } from '../theme-store.types.ts'\n\ntype PrefersColorSchemeThemes = {\n\tlight: string | readonly string[]\n\tdark: string | readonly string[]\n}\n\n/**\n * Creates a read-only theme store that reads from `prefers-color-scheme`.\n *\n * **Color-scheme specific:** Themes must only include `light` and `dark` keys—this store\n * mirrors the system preference which is always one of these.\n *\n * Returns `ThemeEntry` for `light` or `dark` based on system preference.\n * No write method—the value is controlled by the system.\n *\n * @param themes - Record with `light` and `dark` keys mapping to theme values\n * @returns ThemeStore with read and subscribe only\n *\n * @example\n * ```ts\n * const themes = { light: 'theme-light', dark: 'theme-dark' }\n * const store = prefersColorSchemeThemeStore(themes)\n * store.read() // ThemeEntry for current system preference\n * store.subscribe((entry) => {})\n * ```\n */\nexport function prefersColorSchemeThemeStore<Themes extends PrefersColorSchemeThemes>(\n\tthemes: Themes\n): RequiredPick<ThemeStore<Themes>, 'read' | 'subscribe'> {\n\treturn {\n\t\tread() {\n\t\t\treturn themeEntry(themes, getPrefersColorScheme())\n\t\t},\n\t\tsubscribe(handler) {\n\t\t\treturn observePrefersColorScheme((scheme) => handler(themeEntry(themes, scheme)))\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,SAAgB,6BACf,QACyD;AACzD,QAAO;EACN,OAAO;AACN,UAAO,WAAW,QAAQ,uBAAuB,CAAC;;EAEnD,UAAU,SAAS;AAClB,UAAO,2BAA2B,WAAW,QAAQ,WAAW,QAAQ,OAAO,CAAC,CAAC;;EAElF"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const require_theme_entry = require('../../theme-entry.cjs');
|
|
2
|
+
const require_dummy_theme_store = require('../../../testing/theme/dummy-theme-store.cjs');
|
|
3
|
+
const require_parse_stored_theme = require('../../_utils/parse-stored-theme.cjs');
|
|
4
|
+
|
|
5
|
+
//#region src/theme/theme-store/session-storage-theme-store/session-storage-theme-store.ts
|
|
6
|
+
/**
|
|
7
|
+
* Creates a theme store backed by sessionStorage.
|
|
8
|
+
*
|
|
9
|
+
* Persists per tab; cross-tab sync via StorageEvent when available.
|
|
10
|
+
* Same-tab writes trigger manual notify (StorageEvent does not fire for same tab).
|
|
11
|
+
*
|
|
12
|
+
* @param themes - Record mapping theme keys to values (for validation)
|
|
13
|
+
* @param options.storageKey - sessionStorage key
|
|
14
|
+
* @returns ThemeStore
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const themes = { current: 'theme-current', grayscale: 'theme-grayscale' }
|
|
19
|
+
* const store = sessionStorageThemeStore(themes, { storageKey: 'theme' })
|
|
20
|
+
* store.read() // returns themeResult from sessionStorage
|
|
21
|
+
* store.write(themeEntry(themes, 'grayscale'))
|
|
22
|
+
* store.subscribe((themeResult) => {})
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
function sessionStorageThemeStore(themes, options) {
|
|
26
|
+
const { storageKey } = options;
|
|
27
|
+
if (typeof window === "undefined" || !window.sessionStorage) return require_dummy_theme_store.dummyThemeStore;
|
|
28
|
+
const handlers = /* @__PURE__ */ new Set();
|
|
29
|
+
let lastNotifiedKey = read()?.theme ?? void 0;
|
|
30
|
+
function read() {
|
|
31
|
+
const theme = require_parse_stored_theme.parseStoredTheme(themes, window.sessionStorage.getItem(storageKey));
|
|
32
|
+
if (theme === void 0) return void 0;
|
|
33
|
+
return require_theme_entry.themeEntry(themes, theme);
|
|
34
|
+
}
|
|
35
|
+
function notify() {
|
|
36
|
+
const result = read();
|
|
37
|
+
const key = result?.theme ?? void 0;
|
|
38
|
+
if (key === lastNotifiedKey) return;
|
|
39
|
+
lastNotifiedKey = key;
|
|
40
|
+
for (const h of handlers) h(result);
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
read,
|
|
44
|
+
write(entry) {
|
|
45
|
+
try {
|
|
46
|
+
if (entry === void 0) window.sessionStorage.removeItem(storageKey);
|
|
47
|
+
else window.sessionStorage.setItem(storageKey, JSON.stringify(entry));
|
|
48
|
+
notify();
|
|
49
|
+
} catch {}
|
|
50
|
+
},
|
|
51
|
+
subscribe(handler) {
|
|
52
|
+
handlers.add(handler);
|
|
53
|
+
const onStorage = (e) => {
|
|
54
|
+
if (e.key === storageKey && e.storageArea === window.sessionStorage) notify();
|
|
55
|
+
};
|
|
56
|
+
window.addEventListener("storage", onStorage);
|
|
57
|
+
return () => {
|
|
58
|
+
handlers.delete(handler);
|
|
59
|
+
window.removeEventListener("storage", onStorage);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
exports.sessionStorageThemeStore = sessionStorageThemeStore;
|
|
67
|
+
//# sourceMappingURL=session-storage-theme-store.cjs.map
|
package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-storage-theme-store.cjs","names":["dummyThemeStore","lastNotifiedKey: keyof Themes | undefined","parseStoredTheme","themeEntry"],"sources":["../../../../src/theme/theme-store/session-storage-theme-store/session-storage-theme-store.ts"],"sourcesContent":["import { dummyThemeStore } from '../../../testing/theme/dummy-theme-store.ts'\nimport { parseStoredTheme } from '../../_utils/parse-stored-theme.ts'\nimport { themeEntry } from '../../theme-entry.ts'\nimport type { ThemeEntry } from '../../theme-entry.types.ts'\nimport type { ThemeMap } from '../../theme-map.types.ts'\nimport type { ThemeStore } from '../theme-store.types.ts'\n\n/**\n * Creates a theme store backed by sessionStorage.\n *\n * Persists per tab; cross-tab sync via StorageEvent when available.\n * Same-tab writes trigger manual notify (StorageEvent does not fire for same tab).\n *\n * @param themes - Record mapping theme keys to values (for validation)\n * @param options.storageKey - sessionStorage key\n * @returns ThemeStore\n *\n * @example\n * ```ts\n * const themes = { current: 'theme-current', grayscale: 'theme-grayscale' }\n * const store = sessionStorageThemeStore(themes, { storageKey: 'theme' })\n * store.read() // returns themeResult from sessionStorage\n * store.write(themeEntry(themes, 'grayscale'))\n * store.subscribe((themeResult) => {})\n * ```\n */\nexport function sessionStorageThemeStore<Themes extends ThemeMap>(\n\tthemes: Themes,\n\toptions: { storageKey: string }\n) {\n\tconst { storageKey } = options\n\n\tif (typeof window === 'undefined' || !window.sessionStorage) {\n\t\treturn dummyThemeStore satisfies ThemeStore<Themes>\n\t}\n\n\tconst handlers = new Set<(theme: ThemeEntry<Themes> | undefined) => void>()\n\tlet lastNotifiedKey: keyof Themes | undefined = read()?.theme ?? undefined\n\n\tfunction read() {\n\t\tconst stored = window.sessionStorage.getItem(storageKey)\n\t\tconst theme = parseStoredTheme(themes, stored)\n\t\tif (theme === undefined) return undefined\n\t\treturn themeEntry(themes, theme)\n\t}\n\n\tfunction notify() {\n\t\tconst result = read()\n\t\tconst key = result?.theme ?? undefined\n\t\tif (key === lastNotifiedKey) return\n\t\tlastNotifiedKey = key\n\t\tfor (const h of handlers) h(result)\n\t}\n\n\treturn {\n\t\tread,\n\t\twrite(entry) {\n\t\t\ttry {\n\t\t\t\tif (entry === undefined) {\n\t\t\t\t\twindow.sessionStorage.removeItem(storageKey)\n\t\t\t\t} else {\n\t\t\t\t\twindow.sessionStorage.setItem(storageKey, JSON.stringify(entry))\n\t\t\t\t}\n\t\t\t\tnotify()\n\t\t\t} catch {\n\t\t\t\t// Ignore quota or other errors\n\t\t\t}\n\t\t},\n\t\tsubscribe(handler) {\n\t\t\thandlers.add(handler)\n\n\t\t\tconst onStorage = (e: StorageEvent) => {\n\t\t\t\tif (e.key === storageKey && e.storageArea === window.sessionStorage) notify()\n\t\t\t}\n\t\t\twindow.addEventListener('storage', onStorage)\n\n\t\t\treturn () => {\n\t\t\t\thandlers.delete(handler)\n\t\t\t\twindow.removeEventListener('storage', onStorage)\n\t\t\t}\n\t\t}\n\t} satisfies ThemeStore<Themes>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA0BA,SAAgB,yBACf,QACA,SACC;CACD,MAAM,EAAE,eAAe;AAEvB,KAAI,OAAO,WAAW,eAAe,CAAC,OAAO,eAC5C,QAAOA;CAGR,MAAM,2BAAW,IAAI,KAAsD;CAC3E,IAAIC,kBAA4C,MAAM,EAAE,SAAS;CAEjE,SAAS,OAAO;EAEf,MAAM,QAAQC,4CAAiB,QADhB,OAAO,eAAe,QAAQ,WAAW,CACV;AAC9C,MAAI,UAAU,OAAW,QAAO;AAChC,SAAOC,+BAAW,QAAQ,MAAM;;CAGjC,SAAS,SAAS;EACjB,MAAM,SAAS,MAAM;EACrB,MAAM,MAAM,QAAQ,SAAS;AAC7B,MAAI,QAAQ,gBAAiB;AAC7B,oBAAkB;AAClB,OAAK,MAAM,KAAK,SAAU,GAAE,OAAO;;AAGpC,QAAO;EACN;EACA,MAAM,OAAO;AACZ,OAAI;AACH,QAAI,UAAU,OACb,QAAO,eAAe,WAAW,WAAW;QAE5C,QAAO,eAAe,QAAQ,YAAY,KAAK,UAAU,MAAM,CAAC;AAEjE,YAAQ;WACD;;EAIT,UAAU,SAAS;AAClB,YAAS,IAAI,QAAQ;GAErB,MAAM,aAAa,MAAoB;AACtC,QAAI,EAAE,QAAQ,cAAc,EAAE,gBAAgB,OAAO,eAAgB,SAAQ;;AAE9E,UAAO,iBAAiB,WAAW,UAAU;AAE7C,gBAAa;AACZ,aAAS,OAAO,QAAQ;AACxB,WAAO,oBAAoB,WAAW,UAAU;;;EAGlD"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ThemeMap } from "../../theme-map.types.cjs";
|
|
2
|
+
import { ThemeEntry } from "../../theme-entry.types.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/theme/theme-store/session-storage-theme-store/session-storage-theme-store.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Creates a theme store backed by sessionStorage.
|
|
8
|
+
*
|
|
9
|
+
* Persists per tab; cross-tab sync via StorageEvent when available.
|
|
10
|
+
* Same-tab writes trigger manual notify (StorageEvent does not fire for same tab).
|
|
11
|
+
*
|
|
12
|
+
* @param themes - Record mapping theme keys to values (for validation)
|
|
13
|
+
* @param options.storageKey - sessionStorage key
|
|
14
|
+
* @returns ThemeStore
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const themes = { current: 'theme-current', grayscale: 'theme-grayscale' }
|
|
19
|
+
* const store = sessionStorageThemeStore(themes, { storageKey: 'theme' })
|
|
20
|
+
* store.read() // returns themeResult from sessionStorage
|
|
21
|
+
* store.write(themeEntry(themes, 'grayscale'))
|
|
22
|
+
* store.subscribe((themeResult) => {})
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
declare function sessionStorageThemeStore<Themes extends ThemeMap>(themes: Themes, options: {
|
|
26
|
+
storageKey: string;
|
|
27
|
+
}): {
|
|
28
|
+
read: () => ThemeEntry<Themes> | undefined;
|
|
29
|
+
write(entry: ThemeEntry<Themes> | undefined): void;
|
|
30
|
+
subscribe(handler: (theme: ThemeEntry<Themes> | null | undefined) => void): () => void;
|
|
31
|
+
};
|
|
32
|
+
//#endregion
|
|
33
|
+
export { sessionStorageThemeStore };
|
|
34
|
+
//# sourceMappingURL=session-storage-theme-store.d.cts.map
|
package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.d.cts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-storage-theme-store.d.cts","names":[],"sources":["../../../../src/theme/theme-store/session-storage-theme-store/session-storage-theme-store.ts"],"sourcesContent":[],"mappings":";;;;;;;AA0BA;;;;;;;;;;;;;;;;;iBAAgB,wCAAwC,kBAC/C"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ThemeMap } from "../../theme-map.types.mjs";
|
|
2
|
+
import { ThemeEntry } from "../../theme-entry.types.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/theme/theme-store/session-storage-theme-store/session-storage-theme-store.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Creates a theme store backed by sessionStorage.
|
|
8
|
+
*
|
|
9
|
+
* Persists per tab; cross-tab sync via StorageEvent when available.
|
|
10
|
+
* Same-tab writes trigger manual notify (StorageEvent does not fire for same tab).
|
|
11
|
+
*
|
|
12
|
+
* @param themes - Record mapping theme keys to values (for validation)
|
|
13
|
+
* @param options.storageKey - sessionStorage key
|
|
14
|
+
* @returns ThemeStore
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const themes = { current: 'theme-current', grayscale: 'theme-grayscale' }
|
|
19
|
+
* const store = sessionStorageThemeStore(themes, { storageKey: 'theme' })
|
|
20
|
+
* store.read() // returns themeResult from sessionStorage
|
|
21
|
+
* store.write(themeEntry(themes, 'grayscale'))
|
|
22
|
+
* store.subscribe((themeResult) => {})
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
declare function sessionStorageThemeStore<Themes extends ThemeMap>(themes: Themes, options: {
|
|
26
|
+
storageKey: string;
|
|
27
|
+
}): {
|
|
28
|
+
read: () => ThemeEntry<Themes> | undefined;
|
|
29
|
+
write(entry: ThemeEntry<Themes> | undefined): void;
|
|
30
|
+
subscribe(handler: (theme: ThemeEntry<Themes> | null | undefined) => void): () => void;
|
|
31
|
+
};
|
|
32
|
+
//#endregion
|
|
33
|
+
export { sessionStorageThemeStore };
|
|
34
|
+
//# sourceMappingURL=session-storage-theme-store.d.mts.map
|
package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.d.mts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-storage-theme-store.d.mts","names":[],"sources":["../../../../src/theme/theme-store/session-storage-theme-store/session-storage-theme-store.ts"],"sourcesContent":[],"mappings":";;;;;;;AA0BA;;;;;;;;;;;;;;;;;iBAAgB,wCAAwC,kBAC/C"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { themeEntry } from "../../theme-entry.mjs";
|
|
2
|
+
import { dummyThemeStore } from "../../../testing/theme/dummy-theme-store.mjs";
|
|
3
|
+
import { parseStoredTheme } from "../../_utils/parse-stored-theme.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/theme/theme-store/session-storage-theme-store/session-storage-theme-store.ts
|
|
6
|
+
/**
|
|
7
|
+
* Creates a theme store backed by sessionStorage.
|
|
8
|
+
*
|
|
9
|
+
* Persists per tab; cross-tab sync via StorageEvent when available.
|
|
10
|
+
* Same-tab writes trigger manual notify (StorageEvent does not fire for same tab).
|
|
11
|
+
*
|
|
12
|
+
* @param themes - Record mapping theme keys to values (for validation)
|
|
13
|
+
* @param options.storageKey - sessionStorage key
|
|
14
|
+
* @returns ThemeStore
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const themes = { current: 'theme-current', grayscale: 'theme-grayscale' }
|
|
19
|
+
* const store = sessionStorageThemeStore(themes, { storageKey: 'theme' })
|
|
20
|
+
* store.read() // returns themeResult from sessionStorage
|
|
21
|
+
* store.write(themeEntry(themes, 'grayscale'))
|
|
22
|
+
* store.subscribe((themeResult) => {})
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
function sessionStorageThemeStore(themes, options) {
|
|
26
|
+
const { storageKey } = options;
|
|
27
|
+
if (typeof window === "undefined" || !window.sessionStorage) return dummyThemeStore;
|
|
28
|
+
const handlers = /* @__PURE__ */ new Set();
|
|
29
|
+
let lastNotifiedKey = read()?.theme ?? void 0;
|
|
30
|
+
function read() {
|
|
31
|
+
const theme = parseStoredTheme(themes, window.sessionStorage.getItem(storageKey));
|
|
32
|
+
if (theme === void 0) return void 0;
|
|
33
|
+
return themeEntry(themes, theme);
|
|
34
|
+
}
|
|
35
|
+
function notify() {
|
|
36
|
+
const result = read();
|
|
37
|
+
const key = result?.theme ?? void 0;
|
|
38
|
+
if (key === lastNotifiedKey) return;
|
|
39
|
+
lastNotifiedKey = key;
|
|
40
|
+
for (const h of handlers) h(result);
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
read,
|
|
44
|
+
write(entry) {
|
|
45
|
+
try {
|
|
46
|
+
if (entry === void 0) window.sessionStorage.removeItem(storageKey);
|
|
47
|
+
else window.sessionStorage.setItem(storageKey, JSON.stringify(entry));
|
|
48
|
+
notify();
|
|
49
|
+
} catch {}
|
|
50
|
+
},
|
|
51
|
+
subscribe(handler) {
|
|
52
|
+
handlers.add(handler);
|
|
53
|
+
const onStorage = (e) => {
|
|
54
|
+
if (e.key === storageKey && e.storageArea === window.sessionStorage) notify();
|
|
55
|
+
};
|
|
56
|
+
window.addEventListener("storage", onStorage);
|
|
57
|
+
return () => {
|
|
58
|
+
handlers.delete(handler);
|
|
59
|
+
window.removeEventListener("storage", onStorage);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
export { sessionStorageThemeStore };
|
|
67
|
+
//# sourceMappingURL=session-storage-theme-store.mjs.map
|
package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-storage-theme-store.mjs","names":["lastNotifiedKey: keyof Themes | undefined"],"sources":["../../../../src/theme/theme-store/session-storage-theme-store/session-storage-theme-store.ts"],"sourcesContent":["import { dummyThemeStore } from '../../../testing/theme/dummy-theme-store.ts'\nimport { parseStoredTheme } from '../../_utils/parse-stored-theme.ts'\nimport { themeEntry } from '../../theme-entry.ts'\nimport type { ThemeEntry } from '../../theme-entry.types.ts'\nimport type { ThemeMap } from '../../theme-map.types.ts'\nimport type { ThemeStore } from '../theme-store.types.ts'\n\n/**\n * Creates a theme store backed by sessionStorage.\n *\n * Persists per tab; cross-tab sync via StorageEvent when available.\n * Same-tab writes trigger manual notify (StorageEvent does not fire for same tab).\n *\n * @param themes - Record mapping theme keys to values (for validation)\n * @param options.storageKey - sessionStorage key\n * @returns ThemeStore\n *\n * @example\n * ```ts\n * const themes = { current: 'theme-current', grayscale: 'theme-grayscale' }\n * const store = sessionStorageThemeStore(themes, { storageKey: 'theme' })\n * store.read() // returns themeResult from sessionStorage\n * store.write(themeEntry(themes, 'grayscale'))\n * store.subscribe((themeResult) => {})\n * ```\n */\nexport function sessionStorageThemeStore<Themes extends ThemeMap>(\n\tthemes: Themes,\n\toptions: { storageKey: string }\n) {\n\tconst { storageKey } = options\n\n\tif (typeof window === 'undefined' || !window.sessionStorage) {\n\t\treturn dummyThemeStore satisfies ThemeStore<Themes>\n\t}\n\n\tconst handlers = new Set<(theme: ThemeEntry<Themes> | undefined) => void>()\n\tlet lastNotifiedKey: keyof Themes | undefined = read()?.theme ?? undefined\n\n\tfunction read() {\n\t\tconst stored = window.sessionStorage.getItem(storageKey)\n\t\tconst theme = parseStoredTheme(themes, stored)\n\t\tif (theme === undefined) return undefined\n\t\treturn themeEntry(themes, theme)\n\t}\n\n\tfunction notify() {\n\t\tconst result = read()\n\t\tconst key = result?.theme ?? undefined\n\t\tif (key === lastNotifiedKey) return\n\t\tlastNotifiedKey = key\n\t\tfor (const h of handlers) h(result)\n\t}\n\n\treturn {\n\t\tread,\n\t\twrite(entry) {\n\t\t\ttry {\n\t\t\t\tif (entry === undefined) {\n\t\t\t\t\twindow.sessionStorage.removeItem(storageKey)\n\t\t\t\t} else {\n\t\t\t\t\twindow.sessionStorage.setItem(storageKey, JSON.stringify(entry))\n\t\t\t\t}\n\t\t\t\tnotify()\n\t\t\t} catch {\n\t\t\t\t// Ignore quota or other errors\n\t\t\t}\n\t\t},\n\t\tsubscribe(handler) {\n\t\t\thandlers.add(handler)\n\n\t\t\tconst onStorage = (e: StorageEvent) => {\n\t\t\t\tif (e.key === storageKey && e.storageArea === window.sessionStorage) notify()\n\t\t\t}\n\t\t\twindow.addEventListener('storage', onStorage)\n\n\t\t\treturn () => {\n\t\t\t\thandlers.delete(handler)\n\t\t\t\twindow.removeEventListener('storage', onStorage)\n\t\t\t}\n\t\t}\n\t} satisfies ThemeStore<Themes>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA0BA,SAAgB,yBACf,QACA,SACC;CACD,MAAM,EAAE,eAAe;AAEvB,KAAI,OAAO,WAAW,eAAe,CAAC,OAAO,eAC5C,QAAO;CAGR,MAAM,2BAAW,IAAI,KAAsD;CAC3E,IAAIA,kBAA4C,MAAM,EAAE,SAAS;CAEjE,SAAS,OAAO;EAEf,MAAM,QAAQ,iBAAiB,QADhB,OAAO,eAAe,QAAQ,WAAW,CACV;AAC9C,MAAI,UAAU,OAAW,QAAO;AAChC,SAAO,WAAW,QAAQ,MAAM;;CAGjC,SAAS,SAAS;EACjB,MAAM,SAAS,MAAM;EACrB,MAAM,MAAM,QAAQ,SAAS;AAC7B,MAAI,QAAQ,gBAAiB;AAC7B,oBAAkB;AAClB,OAAK,MAAM,KAAK,SAAU,GAAE,OAAO;;AAGpC,QAAO;EACN;EACA,MAAM,OAAO;AACZ,OAAI;AACH,QAAI,UAAU,OACb,QAAO,eAAe,WAAW,WAAW;QAE5C,QAAO,eAAe,QAAQ,YAAY,KAAK,UAAU,MAAM,CAAC;AAEjE,YAAQ;WACD;;EAIT,UAAU,SAAS;AAClB,YAAS,IAAI,QAAQ;GAErB,MAAM,aAAa,MAAoB;AACtC,QAAI,EAAE,QAAQ,cAAc,EAAE,gBAAgB,OAAO,eAAgB,SAAQ;;AAE9E,UAAO,iBAAiB,WAAW,UAAU;AAE7C,gBAAa;AACZ,aAAS,OAAO,QAAQ;AACxB,WAAO,oBAAoB,WAAW,UAAU;;;EAGlD"}
|