@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,22 @@
|
|
|
1
|
+
const require_try_parse_json = require('../../_internal/utils/try-parse-json.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/theme/_utils/parse-stored-theme.ts
|
|
4
|
+
/**
|
|
5
|
+
* Parses stored JSON theme and validates the theme key against theme map.
|
|
6
|
+
*
|
|
7
|
+
* Expects stored shape: { theme: string, value?: unknown }
|
|
8
|
+
*
|
|
9
|
+
* @param themes - Record of valid theme keys (optional; if omitted, any theme string is accepted)
|
|
10
|
+
* @param value - Raw string from localStorage/sessionStorage
|
|
11
|
+
* @returns Theme key if valid, otherwise undefined
|
|
12
|
+
*/
|
|
13
|
+
function parseStoredTheme(themes, value) {
|
|
14
|
+
const parsed = require_try_parse_json.tryParseJSON(value);
|
|
15
|
+
if (!parsed?.theme || typeof parsed.theme !== "string") return void 0;
|
|
16
|
+
if (themes && !(parsed.theme in themes)) return void 0;
|
|
17
|
+
return parsed.theme;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
exports.parseStoredTheme = parseStoredTheme;
|
|
22
|
+
//# sourceMappingURL=parse-stored-theme.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-stored-theme.cjs","names":["tryParseJSON"],"sources":["../../../src/theme/_utils/parse-stored-theme.ts"],"sourcesContent":["import { tryParseJSON } from '../../_internal/utils/try-parse-json.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\n\n/**\n * Parses stored JSON theme and validates the theme key against theme map.\n *\n * Expects stored shape: { theme: string, value?: unknown }\n *\n * @param themes - Record of valid theme keys (optional; if omitted, any theme string is accepted)\n * @param value - Raw string from localStorage/sessionStorage\n * @returns Theme key if valid, otherwise undefined\n */\nexport function parseStoredTheme<Theme extends string>(\n\tthemes: ThemeMap<Theme> | undefined,\n\tvalue: string | null | undefined\n): Theme | undefined {\n\tconst parsed = tryParseJSON<{ theme: string }>(value)\n\tif (!parsed?.theme || typeof parsed.theme !== 'string') return undefined\n\tif (themes && !(parsed.theme in themes)) return undefined\n\treturn parsed.theme as Theme\n}\n"],"mappings":";;;;;;;;;;;;AAYA,SAAgB,iBACf,QACA,OACoB;CACpB,MAAM,SAASA,oCAAgC,MAAM;AACrD,KAAI,CAAC,QAAQ,SAAS,OAAO,OAAO,UAAU,SAAU,QAAO;AAC/D,KAAI,UAAU,EAAE,OAAO,SAAS,QAAS,QAAO;AAChD,QAAO,OAAO"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { tryParseJSON } from "../../_internal/utils/try-parse-json.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/theme/_utils/parse-stored-theme.ts
|
|
4
|
+
/**
|
|
5
|
+
* Parses stored JSON theme and validates the theme key against theme map.
|
|
6
|
+
*
|
|
7
|
+
* Expects stored shape: { theme: string, value?: unknown }
|
|
8
|
+
*
|
|
9
|
+
* @param themes - Record of valid theme keys (optional; if omitted, any theme string is accepted)
|
|
10
|
+
* @param value - Raw string from localStorage/sessionStorage
|
|
11
|
+
* @returns Theme key if valid, otherwise undefined
|
|
12
|
+
*/
|
|
13
|
+
function parseStoredTheme(themes, value) {
|
|
14
|
+
const parsed = tryParseJSON(value);
|
|
15
|
+
if (!parsed?.theme || typeof parsed.theme !== "string") return void 0;
|
|
16
|
+
if (themes && !(parsed.theme in themes)) return void 0;
|
|
17
|
+
return parsed.theme;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { parseStoredTheme };
|
|
22
|
+
//# sourceMappingURL=parse-stored-theme.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-stored-theme.mjs","names":[],"sources":["../../../src/theme/_utils/parse-stored-theme.ts"],"sourcesContent":["import { tryParseJSON } from '../../_internal/utils/try-parse-json.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\n\n/**\n * Parses stored JSON theme and validates the theme key against theme map.\n *\n * Expects stored shape: { theme: string, value?: unknown }\n *\n * @param themes - Record of valid theme keys (optional; if omitted, any theme string is accepted)\n * @param value - Raw string from localStorage/sessionStorage\n * @returns Theme key if valid, otherwise undefined\n */\nexport function parseStoredTheme<Theme extends string>(\n\tthemes: ThemeMap<Theme> | undefined,\n\tvalue: string | null | undefined\n): Theme | undefined {\n\tconst parsed = tryParseJSON<{ theme: string }>(value)\n\tif (!parsed?.theme || typeof parsed.theme !== 'string') return undefined\n\tif (themes && !(parsed.theme in themes)) return undefined\n\treturn parsed.theme as Theme\n}\n"],"mappings":";;;;;;;;;;;;AAYA,SAAgB,iBACf,QACA,OACoB;CACpB,MAAM,SAAS,aAAgC,MAAM;AACrD,KAAI,CAAC,QAAQ,SAAS,OAAO,OAAO,UAAU,SAAU,QAAO;AAC/D,KAAI,UAAU,EAAE,OAAO,SAAS,QAAS,QAAO;AAChD,QAAO,OAAO"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/theme/_utils/set-theme-to-stores.ts
|
|
3
|
+
/**
|
|
4
|
+
* Writes theme entry to all stores that have a write method.
|
|
5
|
+
*
|
|
6
|
+
* @param stores - Array of theme stores
|
|
7
|
+
* @param entry - Theme entry to write, or undefined to clear
|
|
8
|
+
*/
|
|
9
|
+
async function setThemeToStores(stores, entry) {
|
|
10
|
+
const withWrite = stores.filter((s) => typeof s.write === "function");
|
|
11
|
+
await Promise.all(withWrite.map((store) => Promise.resolve(store.write(entry))));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
exports.setThemeToStores = setThemeToStores;
|
|
16
|
+
//# sourceMappingURL=set-theme-to-stores.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set-theme-to-stores.cjs","names":[],"sources":["../../../src/theme/_utils/set-theme-to-stores.ts"],"sourcesContent":["import type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport type { AsyncThemeStore } from '../theme-store/async-theme-store.types.ts'\nimport type { ThemeStore } from '../theme-store/theme-store.types.ts'\n\ntype StoreWithWrite<Themes extends ThemeMap> = (ThemeStore<Themes> | AsyncThemeStore<Themes>) & {\n\twrite: (entry: ThemeEntry<Themes> | undefined) => void | Promise<void>\n}\n\n/**\n * Writes theme entry to all stores that have a write method.\n *\n * @param stores - Array of theme stores\n * @param entry - Theme entry to write, or undefined to clear\n */\nexport async function setThemeToStores<Themes extends ThemeMap>(\n\tstores: (ThemeStore<Themes> | AsyncThemeStore<Themes>)[],\n\tentry: ThemeEntry<Themes> | undefined\n): Promise<void> {\n\tconst withWrite = stores.filter((s): s is StoreWithWrite<Themes> => typeof s.write === 'function')\n\n\tawait Promise.all(withWrite.map((store) => Promise.resolve(store.write!(entry))))\n}\n"],"mappings":";;;;;;;;AAeA,eAAsB,iBACrB,QACA,OACgB;CAChB,MAAM,YAAY,OAAO,QAAQ,MAAmC,OAAO,EAAE,UAAU,WAAW;AAElG,OAAM,QAAQ,IAAI,UAAU,KAAK,UAAU,QAAQ,QAAQ,MAAM,MAAO,MAAM,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/theme/_utils/set-theme-to-stores.ts
|
|
2
|
+
/**
|
|
3
|
+
* Writes theme entry to all stores that have a write method.
|
|
4
|
+
*
|
|
5
|
+
* @param stores - Array of theme stores
|
|
6
|
+
* @param entry - Theme entry to write, or undefined to clear
|
|
7
|
+
*/
|
|
8
|
+
async function setThemeToStores(stores, entry) {
|
|
9
|
+
const withWrite = stores.filter((s) => typeof s.write === "function");
|
|
10
|
+
await Promise.all(withWrite.map((store) => Promise.resolve(store.write(entry))));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
export { setThemeToStores };
|
|
15
|
+
//# sourceMappingURL=set-theme-to-stores.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set-theme-to-stores.mjs","names":[],"sources":["../../../src/theme/_utils/set-theme-to-stores.ts"],"sourcesContent":["import type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport type { AsyncThemeStore } from '../theme-store/async-theme-store.types.ts'\nimport type { ThemeStore } from '../theme-store/theme-store.types.ts'\n\ntype StoreWithWrite<Themes extends ThemeMap> = (ThemeStore<Themes> | AsyncThemeStore<Themes>) & {\n\twrite: (entry: ThemeEntry<Themes> | undefined) => void | Promise<void>\n}\n\n/**\n * Writes theme entry to all stores that have a write method.\n *\n * @param stores - Array of theme stores\n * @param entry - Theme entry to write, or undefined to clear\n */\nexport async function setThemeToStores<Themes extends ThemeMap>(\n\tstores: (ThemeStore<Themes> | AsyncThemeStore<Themes>)[],\n\tentry: ThemeEntry<Themes> | undefined\n): Promise<void> {\n\tconst withWrite = stores.filter((s): s is StoreWithWrite<Themes> => typeof s.write === 'function')\n\n\tawait Promise.all(withWrite.map((store) => Promise.resolve(store.write!(entry))))\n}\n"],"mappings":";;;;;;;AAeA,eAAsB,iBACrB,QACA,OACgB;CAChB,MAAM,YAAY,OAAO,QAAQ,MAAmC,OAAO,EAAE,UAAU,WAAW;AAElG,OAAM,QAAQ,IAAI,UAAU,KAAK,UAAU,QAAQ,QAAQ,MAAM,MAAO,MAAM,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const require_set_theme_to_stores = require('./_utils/set-theme-to-stores.cjs');
|
|
2
|
+
const require_theme_entry = require('./theme-entry.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/theme/compose-theme-stores.ts
|
|
5
|
+
/**
|
|
6
|
+
* Composes multiple theme stores into a single store.
|
|
7
|
+
*
|
|
8
|
+
* Accepts concrete stores or store factory tuples `[factory]` or `[factory, options]`.
|
|
9
|
+
* For factory tuples, calls `factory(themes)` or `factory(themes, options)` to create stores.
|
|
10
|
+
*
|
|
11
|
+
* - **read**: Returns first non-empty `ThemeEntry` from stores (waterfall). When all empty
|
|
12
|
+
* and `defaultTheme` is defined, returns `themeEntry(themes, defaultTheme)`.
|
|
13
|
+
* - **write**: Delegates to `setThemeToStores` (writes to all stores with write).
|
|
14
|
+
* - **subscribe**: Aggregates child store subscriptions. No initial notify—handler is only
|
|
15
|
+
* called when a child store emits.
|
|
16
|
+
*
|
|
17
|
+
* @param themes - ThemeMap for synthesizing fallback ThemeEntry
|
|
18
|
+
* @param stores - Array of theme stores or factory configs [factory, options?]
|
|
19
|
+
* @param options.defaultTheme - Fallback theme key when all stores return empty
|
|
20
|
+
* @returns AsyncThemeStore
|
|
21
|
+
*/
|
|
22
|
+
function composeThemeStores(themes, stores, options) {
|
|
23
|
+
const { defaultTheme } = options ?? {};
|
|
24
|
+
const resolved = resolveStores(themes, stores);
|
|
25
|
+
const withRead = resolved.filter((s) => typeof s.read === "function");
|
|
26
|
+
async function readFromStores() {
|
|
27
|
+
for (const store of withRead) {
|
|
28
|
+
const result = await Promise.resolve(store.read());
|
|
29
|
+
if (result !== void 0) return result;
|
|
30
|
+
}
|
|
31
|
+
return defaultTheme !== void 0 ? require_theme_entry.themeEntry(themes, defaultTheme) : void 0;
|
|
32
|
+
}
|
|
33
|
+
const withSubscribe = resolved.filter((s) => typeof s.subscribe === "function");
|
|
34
|
+
function subscribe(handler) {
|
|
35
|
+
let scheduled = false;
|
|
36
|
+
let lastEmitted;
|
|
37
|
+
const scheduleNotify = () => {
|
|
38
|
+
if (scheduled) return;
|
|
39
|
+
scheduled = true;
|
|
40
|
+
queueMicrotask(async () => {
|
|
41
|
+
scheduled = false;
|
|
42
|
+
const entry = await readFromStores();
|
|
43
|
+
const key = entry?.theme ?? void 0;
|
|
44
|
+
if (key === lastEmitted) return;
|
|
45
|
+
lastEmitted = key;
|
|
46
|
+
handler(entry ?? void 0);
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
const unSubs = withSubscribe.map((s) => s.subscribe((_result) => scheduleNotify()));
|
|
50
|
+
return () => {
|
|
51
|
+
for (const unSub of unSubs) unSub();
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
read: readFromStores,
|
|
56
|
+
write(entry) {
|
|
57
|
+
return require_set_theme_to_stores.setThemeToStores(resolved, entry);
|
|
58
|
+
},
|
|
59
|
+
subscribe: withSubscribe.length > 0 ? subscribe : () => () => {}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function resolveStores(themes, stores) {
|
|
63
|
+
return stores.map((item) => {
|
|
64
|
+
if (Array.isArray(item)) {
|
|
65
|
+
const [factory, options] = item;
|
|
66
|
+
return factory(themes, options);
|
|
67
|
+
}
|
|
68
|
+
return item;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
//#endregion
|
|
73
|
+
exports.composeThemeStores = composeThemeStores;
|
|
74
|
+
//# sourceMappingURL=compose-theme-stores.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compose-theme-stores.cjs","names":["themeEntry","lastEmitted: keyof Themes | undefined","setThemeToStores"],"sources":["../../src/theme/compose-theme-stores.ts"],"sourcesContent":["import type { Required, RequiredPick } from 'type-plus'\nimport { setThemeToStores } from './_utils/set-theme-to-stores.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 { AsyncThemeStore } from './theme-store/async-theme-store.types.ts'\nimport type { ThemeStore } from './theme-store/theme-store.types.ts'\nimport type { ThemeStoreFactory } from './theme-store/theme-store-factory.types.ts'\n\n/** Input item for one position: concrete store or factory config [factory, options?]. */\nexport type ComposeThemeStoreEntry<\n\tThemes extends ThemeMap,\n\tF extends ThemeStoreFactory<Themes> = never\n> = ThemeStore<Themes> | AsyncThemeStore<Themes> | readonly [F] | readonly [F, Parameters<F>[1]]\n\nexport type ComposeThemeStoresOptions<Themes extends ThemeMap> = {\n\tdefaultTheme?: keyof Themes | undefined\n}\n\n/**\n * Composes multiple theme stores into a single store.\n *\n * Accepts concrete stores or store factory tuples `[factory]` or `[factory, options]`.\n * For factory tuples, calls `factory(themes)` or `factory(themes, options)` to create stores.\n *\n * - **read**: Returns first non-empty `ThemeEntry` from stores (waterfall). When all empty\n * and `defaultTheme` is defined, returns `themeEntry(themes, defaultTheme)`.\n * - **write**: Delegates to `setThemeToStores` (writes to all stores with write).\n * - **subscribe**: Aggregates child store subscriptions. No initial notify—handler is only\n * called when a child store emits.\n *\n * @param themes - ThemeMap for synthesizing fallback ThemeEntry\n * @param stores - Array of theme stores or factory configs [factory, options?]\n * @param options.defaultTheme - Fallback theme key when all stores return empty\n * @returns AsyncThemeStore\n */\nexport function composeThemeStores<\n\tThemes extends ThemeMap,\n\tA extends ThemeStoreFactory<Themes> = never,\n\tB extends ThemeStoreFactory<Themes> = never,\n\tC extends ThemeStoreFactory<Themes> = never,\n\tD extends ThemeStoreFactory<Themes> = never,\n\tE extends ThemeStoreFactory<Themes> = never,\n\tF extends ThemeStoreFactory<Themes> = never,\n\tG extends ThemeStoreFactory<Themes> = never,\n\tH extends ThemeStoreFactory<Themes> = never\n>(\n\tthemes: Themes,\n\tstores: readonly [\n\t\tstore1: ComposeThemeStoreEntry<Themes, A>,\n\t\tstore2?: ComposeThemeStoreEntry<Themes, B>,\n\t\tstore3?: ComposeThemeStoreEntry<Themes, C>,\n\t\tstore4?: ComposeThemeStoreEntry<Themes, D>,\n\t\tstore5?: ComposeThemeStoreEntry<Themes, E>,\n\t\tstore6?: ComposeThemeStoreEntry<Themes, F>,\n\t\tstore7?: ComposeThemeStoreEntry<Themes, G>,\n\t\tstore8?: ComposeThemeStoreEntry<Themes, H>\n\t],\n\toptions?: ComposeThemeStoresOptions<Themes> | undefined\n): Required<AsyncThemeStore<Themes>> {\n\tconst { defaultTheme } = options ?? {}\n\tconst resolved = resolveStores(themes, stores)\n\tconst withRead = resolved.filter((s): s is StoreWithRead<Themes> => typeof s.read === 'function')\n\n\tasync function readFromStores(): Promise<ThemeEntry<Themes> | undefined> {\n\t\tfor (const store of withRead) {\n\t\t\tconst result = await Promise.resolve(store.read())\n\t\t\tif (result !== undefined) return result\n\t\t}\n\t\treturn defaultTheme !== undefined ? themeEntry(themes, defaultTheme) : undefined\n\t}\n\n\tconst withSubscribe = resolved.filter(\n\t\t(s): s is StoreWithSubscribe<Themes> => typeof s.subscribe === 'function'\n\t)\n\n\tfunction subscribe(handler: (theme: ThemeEntry<Themes> | undefined | null) => void): () => void {\n\t\tlet scheduled = false\n\t\tlet lastEmitted: keyof Themes | undefined\n\n\t\tconst scheduleNotify = () => {\n\t\t\tif (scheduled) return\n\t\t\tscheduled = true\n\t\t\tqueueMicrotask(async () => {\n\t\t\t\tscheduled = false\n\t\t\t\tconst entry = await readFromStores()\n\t\t\t\tconst key = entry?.theme ?? undefined\n\t\t\t\tif (key === lastEmitted) return\n\t\t\t\tlastEmitted = key\n\t\t\t\thandler(entry ?? undefined)\n\t\t\t})\n\t\t}\n\n\t\tconst unSubs = withSubscribe.map((s) => s.subscribe!((_result) => scheduleNotify()))\n\n\t\treturn () => {\n\t\t\tfor (const unSub of unSubs) {\n\t\t\t\tunSub()\n\t\t\t}\n\t\t}\n\t}\n\n\treturn {\n\t\tread: readFromStores,\n\t\twrite(entry) {\n\t\t\treturn setThemeToStores(resolved, entry)\n\t\t},\n\t\tsubscribe: withSubscribe.length > 0 ? subscribe : () => () => {}\n\t}\n}\n\ntype StoreWithRead<Themes extends ThemeMap> = RequiredPick<AsyncThemeStore<Themes>, 'read'>\n\ntype StoreWithSubscribe<Themes extends ThemeMap> = RequiredPick<\n\tAsyncThemeStore<Themes>,\n\t'subscribe'\n>\n\nfunction resolveStores<Themes extends ThemeMap>(\n\tthemes: Themes,\n\tstores: readonly [\n\t\tstore1: ComposeThemeStoreEntry<Themes, any>,\n\t\tstore2?: ComposeThemeStoreEntry<Themes, any>,\n\t\tstore3?: ComposeThemeStoreEntry<Themes, any>,\n\t\tstore4?: ComposeThemeStoreEntry<Themes, any>,\n\t\tstore5?: ComposeThemeStoreEntry<Themes, any>,\n\t\tstore6?: ComposeThemeStoreEntry<Themes, any>,\n\t\tstore7?: ComposeThemeStoreEntry<Themes, any>,\n\t\tstore8?: ComposeThemeStoreEntry<Themes, any>\n\t]\n): (ThemeStore<Themes> | AsyncThemeStore<Themes>)[] {\n\treturn stores.map((item) => {\n\t\tif (Array.isArray(item)) {\n\t\t\tconst [factory, options] = item\n\t\t\treturn (factory as (t: Themes, o?: unknown) => ThemeStore<Themes>)(themes, options)\n\t\t}\n\t\treturn item as ThemeStore<Themes> | AsyncThemeStore<Themes>\n\t})\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAoCA,SAAgB,mBAWf,QACA,QAUA,SACoC;CACpC,MAAM,EAAE,iBAAiB,WAAW,EAAE;CACtC,MAAM,WAAW,cAAc,QAAQ,OAAO;CAC9C,MAAM,WAAW,SAAS,QAAQ,MAAkC,OAAO,EAAE,SAAS,WAAW;CAEjG,eAAe,iBAA0D;AACxE,OAAK,MAAM,SAAS,UAAU;GAC7B,MAAM,SAAS,MAAM,QAAQ,QAAQ,MAAM,MAAM,CAAC;AAClD,OAAI,WAAW,OAAW,QAAO;;AAElC,SAAO,iBAAiB,SAAYA,+BAAW,QAAQ,aAAa,GAAG;;CAGxE,MAAM,gBAAgB,SAAS,QAC7B,MAAuC,OAAO,EAAE,cAAc,WAC/D;CAED,SAAS,UAAU,SAA6E;EAC/F,IAAI,YAAY;EAChB,IAAIC;EAEJ,MAAM,uBAAuB;AAC5B,OAAI,UAAW;AACf,eAAY;AACZ,kBAAe,YAAY;AAC1B,gBAAY;IACZ,MAAM,QAAQ,MAAM,gBAAgB;IACpC,MAAM,MAAM,OAAO,SAAS;AAC5B,QAAI,QAAQ,YAAa;AACzB,kBAAc;AACd,YAAQ,SAAS,OAAU;KAC1B;;EAGH,MAAM,SAAS,cAAc,KAAK,MAAM,EAAE,WAAY,YAAY,gBAAgB,CAAC,CAAC;AAEpF,eAAa;AACZ,QAAK,MAAM,SAAS,OACnB,QAAO;;;AAKV,QAAO;EACN,MAAM;EACN,MAAM,OAAO;AACZ,UAAOC,6CAAiB,UAAU,MAAM;;EAEzC,WAAW,cAAc,SAAS,IAAI,wBAAwB;EAC9D;;AAUF,SAAS,cACR,QACA,QAUmD;AACnD,QAAO,OAAO,KAAK,SAAS;AAC3B,MAAI,MAAM,QAAQ,KAAK,EAAE;GACxB,MAAM,CAAC,SAAS,WAAW;AAC3B,UAAQ,QAA2D,QAAQ,QAAQ;;AAEpF,SAAO;GACN"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ThemeMap } from "./theme-map.types.cjs";
|
|
2
|
+
import { AsyncThemeStore } from "./theme-store/async-theme-store.types.cjs";
|
|
3
|
+
import { ThemeStore } from "./theme-store/theme-store.types.cjs";
|
|
4
|
+
import { ThemeStoreFactory } from "./theme-store/theme-store-factory.types.cjs";
|
|
5
|
+
import { Required } from "type-plus";
|
|
6
|
+
|
|
7
|
+
//#region src/theme/compose-theme-stores.d.ts
|
|
8
|
+
/** Input item for one position: concrete store or factory config [factory, options?]. */
|
|
9
|
+
type ComposeThemeStoreEntry<Themes extends ThemeMap, F extends ThemeStoreFactory<Themes> = never> = ThemeStore<Themes> | AsyncThemeStore<Themes> | readonly [F] | readonly [F, Parameters<F>[1]];
|
|
10
|
+
type ComposeThemeStoresOptions<Themes extends ThemeMap> = {
|
|
11
|
+
defaultTheme?: keyof Themes | undefined;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Composes multiple theme stores into a single store.
|
|
15
|
+
*
|
|
16
|
+
* Accepts concrete stores or store factory tuples `[factory]` or `[factory, options]`.
|
|
17
|
+
* For factory tuples, calls `factory(themes)` or `factory(themes, options)` to create stores.
|
|
18
|
+
*
|
|
19
|
+
* - **read**: Returns first non-empty `ThemeEntry` from stores (waterfall). When all empty
|
|
20
|
+
* and `defaultTheme` is defined, returns `themeEntry(themes, defaultTheme)`.
|
|
21
|
+
* - **write**: Delegates to `setThemeToStores` (writes to all stores with write).
|
|
22
|
+
* - **subscribe**: Aggregates child store subscriptions. No initial notify—handler is only
|
|
23
|
+
* called when a child store emits.
|
|
24
|
+
*
|
|
25
|
+
* @param themes - ThemeMap for synthesizing fallback ThemeEntry
|
|
26
|
+
* @param stores - Array of theme stores or factory configs [factory, options?]
|
|
27
|
+
* @param options.defaultTheme - Fallback theme key when all stores return empty
|
|
28
|
+
* @returns AsyncThemeStore
|
|
29
|
+
*/
|
|
30
|
+
declare function composeThemeStores<Themes extends ThemeMap, A extends ThemeStoreFactory<Themes> = never, B extends ThemeStoreFactory<Themes> = never, C extends ThemeStoreFactory<Themes> = never, D extends ThemeStoreFactory<Themes> = never, E extends ThemeStoreFactory<Themes> = never, F extends ThemeStoreFactory<Themes> = never, G extends ThemeStoreFactory<Themes> = never, H extends ThemeStoreFactory<Themes> = never>(themes: Themes, stores: readonly [store1: ComposeThemeStoreEntry<Themes, A>, store2?: ComposeThemeStoreEntry<Themes, B>, store3?: ComposeThemeStoreEntry<Themes, C>, store4?: ComposeThemeStoreEntry<Themes, D>, store5?: ComposeThemeStoreEntry<Themes, E>, store6?: ComposeThemeStoreEntry<Themes, F>, store7?: ComposeThemeStoreEntry<Themes, G>, store8?: ComposeThemeStoreEntry<Themes, H>], options?: ComposeThemeStoresOptions<Themes> | undefined): Required<AsyncThemeStore<Themes>>;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { ComposeThemeStoreEntry, ComposeThemeStoresOptions, composeThemeStores };
|
|
33
|
+
//# sourceMappingURL=compose-theme-stores.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compose-theme-stores.d.cts","names":[],"sources":["../../src/theme/compose-theme-stores.ts"],"sourcesContent":[],"mappings":";;;;;;;;KAUY,sCACI,oBACL,kBAAkB,mBACzB,WAAW,UAAU,gBAAgB,oBAAoB,eAAe,GAAG,WAAW;AAH9E,KAKA,yBALsB,CAAA,eAKmB,QALnB,CAAA,GAAA;EAClB,YAAA,CAAA,EAAA,MAKM,MALN,GAAA,SAAA;CACa;;;;;;;;;;;AAG7B;AAqBA;;;;;;AAI6B,iBAJb,kBAIa,CAAA,eAHb,QAGa,EAAA,UAFlB,iBAEkB,CAFA,MAEA,CAAA,GAAA,KAAA,EAAA,UADlB,iBACkB,CADA,MACA,CAAA,GAAA,KAAA,EAAA,UAAlB,iBAAkB,CAAA,MAAA,CAAA,GAAA,KAAA,EAAA,UAClB,iBADkB,CACA,MADA,CAAA,GAAA,KAAA,EAAA,UAElB,iBAFkB,CAEA,MAFA,CAAA,GAAA,KAAA,EAAA,UAGlB,iBAHkB,CAGA,MAHA,CAAA,GAAA,KAAA,EAAA,UAIlB,iBAJkB,CAIA,MAJA,CAAA,GAAA,KAAA,EAAA,UAKlB,iBALkB,CAKA,MALA,CAAA,GAAA,KAAA,CAAA,CAAA,MAAA,EAOpB,MAPoB,EAAA,MAAA,EAAA,SAAA,CAAlB,MAAA,EASD,sBATC,CASsB,MATtB,EAS8B,CAT9B,CAAA,EACkB,MAAA,GASlB,sBATkB,CASK,MATL,EASa,CATb,CAAA,EAAlB,MAAA,GAUA,sBAVA,CAUuB,MAVvB,EAU+B,CAV/B,CAAA,EACkB,MAAA,GAUlB,sBAVkB,CAUK,MAVL,EAUa,CAVb,CAAA,EAAlB,MAAA,GAWA,sBAXA,CAWuB,MAXvB,EAW+B,CAX/B,CAAA,EACkB,MAAA,GAWlB,sBAXkB,CAWK,MAXL,EAWa,CAXb,CAAA,EAAlB,MAAA,GAYA,sBAZA,CAYuB,MAZvB,EAY+B,CAZ/B,CAAA,EACkB,MAAA,GAYlB,sBAZkB,CAYK,MAZL,EAYa,CAZb,CAAA,CAAlB,EAAA,OAAA,CAAA,EAcA,yBAdA,CAc0B,MAd1B,CAAA,GAAA,SAAA,CAAA,EAeR,QAfQ,CAeC,eAfD,CAeiB,MAfjB,CAAA,CAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ThemeMap } from "./theme-map.types.mjs";
|
|
2
|
+
import { AsyncThemeStore } from "./theme-store/async-theme-store.types.mjs";
|
|
3
|
+
import { ThemeStore } from "./theme-store/theme-store.types.mjs";
|
|
4
|
+
import { ThemeStoreFactory } from "./theme-store/theme-store-factory.types.mjs";
|
|
5
|
+
import { Required } from "type-plus";
|
|
6
|
+
|
|
7
|
+
//#region src/theme/compose-theme-stores.d.ts
|
|
8
|
+
/** Input item for one position: concrete store or factory config [factory, options?]. */
|
|
9
|
+
type ComposeThemeStoreEntry<Themes extends ThemeMap, F extends ThemeStoreFactory<Themes> = never> = ThemeStore<Themes> | AsyncThemeStore<Themes> | readonly [F] | readonly [F, Parameters<F>[1]];
|
|
10
|
+
type ComposeThemeStoresOptions<Themes extends ThemeMap> = {
|
|
11
|
+
defaultTheme?: keyof Themes | undefined;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Composes multiple theme stores into a single store.
|
|
15
|
+
*
|
|
16
|
+
* Accepts concrete stores or store factory tuples `[factory]` or `[factory, options]`.
|
|
17
|
+
* For factory tuples, calls `factory(themes)` or `factory(themes, options)` to create stores.
|
|
18
|
+
*
|
|
19
|
+
* - **read**: Returns first non-empty `ThemeEntry` from stores (waterfall). When all empty
|
|
20
|
+
* and `defaultTheme` is defined, returns `themeEntry(themes, defaultTheme)`.
|
|
21
|
+
* - **write**: Delegates to `setThemeToStores` (writes to all stores with write).
|
|
22
|
+
* - **subscribe**: Aggregates child store subscriptions. No initial notify—handler is only
|
|
23
|
+
* called when a child store emits.
|
|
24
|
+
*
|
|
25
|
+
* @param themes - ThemeMap for synthesizing fallback ThemeEntry
|
|
26
|
+
* @param stores - Array of theme stores or factory configs [factory, options?]
|
|
27
|
+
* @param options.defaultTheme - Fallback theme key when all stores return empty
|
|
28
|
+
* @returns AsyncThemeStore
|
|
29
|
+
*/
|
|
30
|
+
declare function composeThemeStores<Themes extends ThemeMap, A extends ThemeStoreFactory<Themes> = never, B extends ThemeStoreFactory<Themes> = never, C extends ThemeStoreFactory<Themes> = never, D extends ThemeStoreFactory<Themes> = never, E extends ThemeStoreFactory<Themes> = never, F extends ThemeStoreFactory<Themes> = never, G extends ThemeStoreFactory<Themes> = never, H extends ThemeStoreFactory<Themes> = never>(themes: Themes, stores: readonly [store1: ComposeThemeStoreEntry<Themes, A>, store2?: ComposeThemeStoreEntry<Themes, B>, store3?: ComposeThemeStoreEntry<Themes, C>, store4?: ComposeThemeStoreEntry<Themes, D>, store5?: ComposeThemeStoreEntry<Themes, E>, store6?: ComposeThemeStoreEntry<Themes, F>, store7?: ComposeThemeStoreEntry<Themes, G>, store8?: ComposeThemeStoreEntry<Themes, H>], options?: ComposeThemeStoresOptions<Themes> | undefined): Required<AsyncThemeStore<Themes>>;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { ComposeThemeStoreEntry, ComposeThemeStoresOptions, composeThemeStores };
|
|
33
|
+
//# sourceMappingURL=compose-theme-stores.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compose-theme-stores.d.mts","names":[],"sources":["../../src/theme/compose-theme-stores.ts"],"sourcesContent":[],"mappings":";;;;;;;;KAUY,sCACI,oBACL,kBAAkB,mBACzB,WAAW,UAAU,gBAAgB,oBAAoB,eAAe,GAAG,WAAW;AAH9E,KAKA,yBALsB,CAAA,eAKmB,QALnB,CAAA,GAAA;EAClB,YAAA,CAAA,EAAA,MAKM,MALN,GAAA,SAAA;CACa;;;;;;;;;;;AAG7B;AAqBA;;;;;;AAI6B,iBAJb,kBAIa,CAAA,eAHb,QAGa,EAAA,UAFlB,iBAEkB,CAFA,MAEA,CAAA,GAAA,KAAA,EAAA,UADlB,iBACkB,CADA,MACA,CAAA,GAAA,KAAA,EAAA,UAAlB,iBAAkB,CAAA,MAAA,CAAA,GAAA,KAAA,EAAA,UAClB,iBADkB,CACA,MADA,CAAA,GAAA,KAAA,EAAA,UAElB,iBAFkB,CAEA,MAFA,CAAA,GAAA,KAAA,EAAA,UAGlB,iBAHkB,CAGA,MAHA,CAAA,GAAA,KAAA,EAAA,UAIlB,iBAJkB,CAIA,MAJA,CAAA,GAAA,KAAA,EAAA,UAKlB,iBALkB,CAKA,MALA,CAAA,GAAA,KAAA,CAAA,CAAA,MAAA,EAOpB,MAPoB,EAAA,MAAA,EAAA,SAAA,CAAlB,MAAA,EASD,sBATC,CASsB,MATtB,EAS8B,CAT9B,CAAA,EACkB,MAAA,GASlB,sBATkB,CASK,MATL,EASa,CATb,CAAA,EAAlB,MAAA,GAUA,sBAVA,CAUuB,MAVvB,EAU+B,CAV/B,CAAA,EACkB,MAAA,GAUlB,sBAVkB,CAUK,MAVL,EAUa,CAVb,CAAA,EAAlB,MAAA,GAWA,sBAXA,CAWuB,MAXvB,EAW+B,CAX/B,CAAA,EACkB,MAAA,GAWlB,sBAXkB,CAWK,MAXL,EAWa,CAXb,CAAA,EAAlB,MAAA,GAYA,sBAZA,CAYuB,MAZvB,EAY+B,CAZ/B,CAAA,EACkB,MAAA,GAYlB,sBAZkB,CAYK,MAZL,EAYa,CAZb,CAAA,CAAlB,EAAA,OAAA,CAAA,EAcA,yBAdA,CAc0B,MAd1B,CAAA,GAAA,SAAA,CAAA,EAeR,QAfQ,CAeC,eAfD,CAeiB,MAfjB,CAAA,CAAA"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { setThemeToStores } from "./_utils/set-theme-to-stores.mjs";
|
|
2
|
+
import { themeEntry } from "./theme-entry.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/theme/compose-theme-stores.ts
|
|
5
|
+
/**
|
|
6
|
+
* Composes multiple theme stores into a single store.
|
|
7
|
+
*
|
|
8
|
+
* Accepts concrete stores or store factory tuples `[factory]` or `[factory, options]`.
|
|
9
|
+
* For factory tuples, calls `factory(themes)` or `factory(themes, options)` to create stores.
|
|
10
|
+
*
|
|
11
|
+
* - **read**: Returns first non-empty `ThemeEntry` from stores (waterfall). When all empty
|
|
12
|
+
* and `defaultTheme` is defined, returns `themeEntry(themes, defaultTheme)`.
|
|
13
|
+
* - **write**: Delegates to `setThemeToStores` (writes to all stores with write).
|
|
14
|
+
* - **subscribe**: Aggregates child store subscriptions. No initial notify—handler is only
|
|
15
|
+
* called when a child store emits.
|
|
16
|
+
*
|
|
17
|
+
* @param themes - ThemeMap for synthesizing fallback ThemeEntry
|
|
18
|
+
* @param stores - Array of theme stores or factory configs [factory, options?]
|
|
19
|
+
* @param options.defaultTheme - Fallback theme key when all stores return empty
|
|
20
|
+
* @returns AsyncThemeStore
|
|
21
|
+
*/
|
|
22
|
+
function composeThemeStores(themes, stores, options) {
|
|
23
|
+
const { defaultTheme } = options ?? {};
|
|
24
|
+
const resolved = resolveStores(themes, stores);
|
|
25
|
+
const withRead = resolved.filter((s) => typeof s.read === "function");
|
|
26
|
+
async function readFromStores() {
|
|
27
|
+
for (const store of withRead) {
|
|
28
|
+
const result = await Promise.resolve(store.read());
|
|
29
|
+
if (result !== void 0) return result;
|
|
30
|
+
}
|
|
31
|
+
return defaultTheme !== void 0 ? themeEntry(themes, defaultTheme) : void 0;
|
|
32
|
+
}
|
|
33
|
+
const withSubscribe = resolved.filter((s) => typeof s.subscribe === "function");
|
|
34
|
+
function subscribe(handler) {
|
|
35
|
+
let scheduled = false;
|
|
36
|
+
let lastEmitted;
|
|
37
|
+
const scheduleNotify = () => {
|
|
38
|
+
if (scheduled) return;
|
|
39
|
+
scheduled = true;
|
|
40
|
+
queueMicrotask(async () => {
|
|
41
|
+
scheduled = false;
|
|
42
|
+
const entry = await readFromStores();
|
|
43
|
+
const key = entry?.theme ?? void 0;
|
|
44
|
+
if (key === lastEmitted) return;
|
|
45
|
+
lastEmitted = key;
|
|
46
|
+
handler(entry ?? void 0);
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
const unSubs = withSubscribe.map((s) => s.subscribe((_result) => scheduleNotify()));
|
|
50
|
+
return () => {
|
|
51
|
+
for (const unSub of unSubs) unSub();
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
read: readFromStores,
|
|
56
|
+
write(entry) {
|
|
57
|
+
return setThemeToStores(resolved, entry);
|
|
58
|
+
},
|
|
59
|
+
subscribe: withSubscribe.length > 0 ? subscribe : () => () => {}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function resolveStores(themes, stores) {
|
|
63
|
+
return stores.map((item) => {
|
|
64
|
+
if (Array.isArray(item)) {
|
|
65
|
+
const [factory, options] = item;
|
|
66
|
+
return factory(themes, options);
|
|
67
|
+
}
|
|
68
|
+
return item;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
//#endregion
|
|
73
|
+
export { composeThemeStores };
|
|
74
|
+
//# sourceMappingURL=compose-theme-stores.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compose-theme-stores.mjs","names":["lastEmitted: keyof Themes | undefined"],"sources":["../../src/theme/compose-theme-stores.ts"],"sourcesContent":["import type { Required, RequiredPick } from 'type-plus'\nimport { setThemeToStores } from './_utils/set-theme-to-stores.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 { AsyncThemeStore } from './theme-store/async-theme-store.types.ts'\nimport type { ThemeStore } from './theme-store/theme-store.types.ts'\nimport type { ThemeStoreFactory } from './theme-store/theme-store-factory.types.ts'\n\n/** Input item for one position: concrete store or factory config [factory, options?]. */\nexport type ComposeThemeStoreEntry<\n\tThemes extends ThemeMap,\n\tF extends ThemeStoreFactory<Themes> = never\n> = ThemeStore<Themes> | AsyncThemeStore<Themes> | readonly [F] | readonly [F, Parameters<F>[1]]\n\nexport type ComposeThemeStoresOptions<Themes extends ThemeMap> = {\n\tdefaultTheme?: keyof Themes | undefined\n}\n\n/**\n * Composes multiple theme stores into a single store.\n *\n * Accepts concrete stores or store factory tuples `[factory]` or `[factory, options]`.\n * For factory tuples, calls `factory(themes)` or `factory(themes, options)` to create stores.\n *\n * - **read**: Returns first non-empty `ThemeEntry` from stores (waterfall). When all empty\n * and `defaultTheme` is defined, returns `themeEntry(themes, defaultTheme)`.\n * - **write**: Delegates to `setThemeToStores` (writes to all stores with write).\n * - **subscribe**: Aggregates child store subscriptions. No initial notify—handler is only\n * called when a child store emits.\n *\n * @param themes - ThemeMap for synthesizing fallback ThemeEntry\n * @param stores - Array of theme stores or factory configs [factory, options?]\n * @param options.defaultTheme - Fallback theme key when all stores return empty\n * @returns AsyncThemeStore\n */\nexport function composeThemeStores<\n\tThemes extends ThemeMap,\n\tA extends ThemeStoreFactory<Themes> = never,\n\tB extends ThemeStoreFactory<Themes> = never,\n\tC extends ThemeStoreFactory<Themes> = never,\n\tD extends ThemeStoreFactory<Themes> = never,\n\tE extends ThemeStoreFactory<Themes> = never,\n\tF extends ThemeStoreFactory<Themes> = never,\n\tG extends ThemeStoreFactory<Themes> = never,\n\tH extends ThemeStoreFactory<Themes> = never\n>(\n\tthemes: Themes,\n\tstores: readonly [\n\t\tstore1: ComposeThemeStoreEntry<Themes, A>,\n\t\tstore2?: ComposeThemeStoreEntry<Themes, B>,\n\t\tstore3?: ComposeThemeStoreEntry<Themes, C>,\n\t\tstore4?: ComposeThemeStoreEntry<Themes, D>,\n\t\tstore5?: ComposeThemeStoreEntry<Themes, E>,\n\t\tstore6?: ComposeThemeStoreEntry<Themes, F>,\n\t\tstore7?: ComposeThemeStoreEntry<Themes, G>,\n\t\tstore8?: ComposeThemeStoreEntry<Themes, H>\n\t],\n\toptions?: ComposeThemeStoresOptions<Themes> | undefined\n): Required<AsyncThemeStore<Themes>> {\n\tconst { defaultTheme } = options ?? {}\n\tconst resolved = resolveStores(themes, stores)\n\tconst withRead = resolved.filter((s): s is StoreWithRead<Themes> => typeof s.read === 'function')\n\n\tasync function readFromStores(): Promise<ThemeEntry<Themes> | undefined> {\n\t\tfor (const store of withRead) {\n\t\t\tconst result = await Promise.resolve(store.read())\n\t\t\tif (result !== undefined) return result\n\t\t}\n\t\treturn defaultTheme !== undefined ? themeEntry(themes, defaultTheme) : undefined\n\t}\n\n\tconst withSubscribe = resolved.filter(\n\t\t(s): s is StoreWithSubscribe<Themes> => typeof s.subscribe === 'function'\n\t)\n\n\tfunction subscribe(handler: (theme: ThemeEntry<Themes> | undefined | null) => void): () => void {\n\t\tlet scheduled = false\n\t\tlet lastEmitted: keyof Themes | undefined\n\n\t\tconst scheduleNotify = () => {\n\t\t\tif (scheduled) return\n\t\t\tscheduled = true\n\t\t\tqueueMicrotask(async () => {\n\t\t\t\tscheduled = false\n\t\t\t\tconst entry = await readFromStores()\n\t\t\t\tconst key = entry?.theme ?? undefined\n\t\t\t\tif (key === lastEmitted) return\n\t\t\t\tlastEmitted = key\n\t\t\t\thandler(entry ?? undefined)\n\t\t\t})\n\t\t}\n\n\t\tconst unSubs = withSubscribe.map((s) => s.subscribe!((_result) => scheduleNotify()))\n\n\t\treturn () => {\n\t\t\tfor (const unSub of unSubs) {\n\t\t\t\tunSub()\n\t\t\t}\n\t\t}\n\t}\n\n\treturn {\n\t\tread: readFromStores,\n\t\twrite(entry) {\n\t\t\treturn setThemeToStores(resolved, entry)\n\t\t},\n\t\tsubscribe: withSubscribe.length > 0 ? subscribe : () => () => {}\n\t}\n}\n\ntype StoreWithRead<Themes extends ThemeMap> = RequiredPick<AsyncThemeStore<Themes>, 'read'>\n\ntype StoreWithSubscribe<Themes extends ThemeMap> = RequiredPick<\n\tAsyncThemeStore<Themes>,\n\t'subscribe'\n>\n\nfunction resolveStores<Themes extends ThemeMap>(\n\tthemes: Themes,\n\tstores: readonly [\n\t\tstore1: ComposeThemeStoreEntry<Themes, any>,\n\t\tstore2?: ComposeThemeStoreEntry<Themes, any>,\n\t\tstore3?: ComposeThemeStoreEntry<Themes, any>,\n\t\tstore4?: ComposeThemeStoreEntry<Themes, any>,\n\t\tstore5?: ComposeThemeStoreEntry<Themes, any>,\n\t\tstore6?: ComposeThemeStoreEntry<Themes, any>,\n\t\tstore7?: ComposeThemeStoreEntry<Themes, any>,\n\t\tstore8?: ComposeThemeStoreEntry<Themes, any>\n\t]\n): (ThemeStore<Themes> | AsyncThemeStore<Themes>)[] {\n\treturn stores.map((item) => {\n\t\tif (Array.isArray(item)) {\n\t\t\tconst [factory, options] = item\n\t\t\treturn (factory as (t: Themes, o?: unknown) => ThemeStore<Themes>)(themes, options)\n\t\t}\n\t\treturn item as ThemeStore<Themes> | AsyncThemeStore<Themes>\n\t})\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAoCA,SAAgB,mBAWf,QACA,QAUA,SACoC;CACpC,MAAM,EAAE,iBAAiB,WAAW,EAAE;CACtC,MAAM,WAAW,cAAc,QAAQ,OAAO;CAC9C,MAAM,WAAW,SAAS,QAAQ,MAAkC,OAAO,EAAE,SAAS,WAAW;CAEjG,eAAe,iBAA0D;AACxE,OAAK,MAAM,SAAS,UAAU;GAC7B,MAAM,SAAS,MAAM,QAAQ,QAAQ,MAAM,MAAM,CAAC;AAClD,OAAI,WAAW,OAAW,QAAO;;AAElC,SAAO,iBAAiB,SAAY,WAAW,QAAQ,aAAa,GAAG;;CAGxE,MAAM,gBAAgB,SAAS,QAC7B,MAAuC,OAAO,EAAE,cAAc,WAC/D;CAED,SAAS,UAAU,SAA6E;EAC/F,IAAI,YAAY;EAChB,IAAIA;EAEJ,MAAM,uBAAuB;AAC5B,OAAI,UAAW;AACf,eAAY;AACZ,kBAAe,YAAY;AAC1B,gBAAY;IACZ,MAAM,QAAQ,MAAM,gBAAgB;IACpC,MAAM,MAAM,OAAO,SAAS;AAC5B,QAAI,QAAQ,YAAa;AACzB,kBAAc;AACd,YAAQ,SAAS,OAAU;KAC1B;;EAGH,MAAM,SAAS,cAAc,KAAK,MAAM,EAAE,WAAY,YAAY,gBAAgB,CAAC,CAAC;AAEpF,eAAa;AACZ,QAAK,MAAM,SAAS,OACnB,QAAO;;;AAKV,QAAO;EACN,MAAM;EACN,MAAM,OAAO;AACZ,UAAO,iBAAiB,UAAU,MAAM;;EAEzC,WAAW,cAAc,SAAS,IAAI,wBAAwB;EAC9D;;AAUF,SAAS,cACR,QACA,QAUmD;AACnD,QAAO,OAAO,KAAK,SAAS;AAC3B,MAAI,MAAM,QAAQ,KAAK,EAAE;GACxB,MAAM,CAAC,SAAS,WAAW;AAC3B,UAAQ,QAA2D,QAAQ,QAAQ;;AAEpF,SAAO;GACN"}
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/theme/theme-entry.ts
|
|
3
|
+
/** Creates ThemeEntry from theme map and theme key. */
|
|
4
|
+
function themeEntry(themes, theme) {
|
|
5
|
+
return {
|
|
6
|
+
theme,
|
|
7
|
+
value: themes[theme]
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
exports.themeEntry = themeEntry;
|
|
13
|
+
//# sourceMappingURL=theme-entry.cjs.map
|