@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
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { DataAttribute } from "./attributes/data-attribute.cjs";
|
|
2
|
+
import { getAttribute } from "./attributes/get-attribute.cjs";
|
|
3
|
+
import { getDataAttribute } from "./attributes/get-data-attribute.cjs";
|
|
4
|
+
import { observeAttributes } from "./attributes/observe-attribute.cjs";
|
|
5
|
+
import { observeDataAttributes } from "./attributes/observe-data-attribute.cjs";
|
|
6
|
+
import { JustChildren, JustChildrenFnProps, JustChildrenProps } from "./children/just-children.cjs";
|
|
7
|
+
import { resolveChildren } from "./children/resolve-children.cjs";
|
|
8
|
+
import { ClassNameProps } from "./class-name/class-name-props.cjs";
|
|
9
|
+
import { clsx } from "./class-name/clsx.cjs";
|
|
10
|
+
import { JustClassName, JustClassNameFnProps, JustClassNameProps } from "./class-name/just-class-name.cjs";
|
|
11
|
+
import { resolveClassName } from "./class-name/resolve-class-name.cjs";
|
|
12
|
+
import { getPrefersColorScheme } from "./color-scheme/get-prefers-color-scheme.cjs";
|
|
13
|
+
import { observePrefersColorScheme } from "./color-scheme/observe-prefers-color-scheme.cjs";
|
|
14
|
+
import { CSSProperties } from "./style/css-properties.cjs";
|
|
15
|
+
import { defineCSSProperties } from "./style/define-css-properties.cjs";
|
|
16
|
+
import { getCSSVariableValue } from "./style/get-css-variable-value.cjs";
|
|
17
|
+
import { JustStyle, JustStyleFnProps, JustStyleProps } from "./style/just-style.cjs";
|
|
18
|
+
import { resolveStyle } from "./style/resolve-style.cjs";
|
|
19
|
+
import { StyleProps } from "./style/style-props.cjs";
|
|
20
|
+
import { toDomStyle } from "./style/to-dom-style.cjs";
|
|
21
|
+
import { getRemToPxScale } from "./units/get-rem-to-px-scale.cjs";
|
|
22
|
+
import { px2num } from "./units/px-2-num.cjs";
|
|
23
|
+
import { px2rem } from "./units/px-2-rem.cjs";
|
|
24
|
+
import { rem2px } from "./units/rem-2-px.cjs";
|
|
25
|
+
import { appendId } from "./utils/append-id.cjs";
|
|
26
|
+
export { CSSProperties, ClassNameProps, DataAttribute, JustChildren, JustChildrenFnProps, JustChildrenProps, JustClassName, JustClassNameFnProps, JustClassNameProps, JustStyle, JustStyleFnProps, JustStyleProps, StyleProps, appendId, clsx, defineCSSProperties, getAttribute, getCSSVariableValue, getDataAttribute, getPrefersColorScheme, getRemToPxScale, observeAttributes, observeDataAttributes, observePrefersColorScheme, px2num, px2rem, rem2px, resolveChildren, resolveClassName, resolveStyle, toDomStyle };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { DataAttribute } from "./attributes/data-attribute.mjs";
|
|
2
|
+
import { getAttribute } from "./attributes/get-attribute.mjs";
|
|
3
|
+
import { getDataAttribute } from "./attributes/get-data-attribute.mjs";
|
|
4
|
+
import { observeAttributes } from "./attributes/observe-attribute.mjs";
|
|
5
|
+
import { observeDataAttributes } from "./attributes/observe-data-attribute.mjs";
|
|
6
|
+
import { JustChildren, JustChildrenFnProps, JustChildrenProps } from "./children/just-children.mjs";
|
|
7
|
+
import { resolveChildren } from "./children/resolve-children.mjs";
|
|
8
|
+
import { ClassNameProps } from "./class-name/class-name-props.mjs";
|
|
9
|
+
import { clsx } from "./class-name/clsx.mjs";
|
|
10
|
+
import { JustClassName, JustClassNameFnProps, JustClassNameProps } from "./class-name/just-class-name.mjs";
|
|
11
|
+
import { resolveClassName } from "./class-name/resolve-class-name.mjs";
|
|
12
|
+
import { getPrefersColorScheme } from "./color-scheme/get-prefers-color-scheme.mjs";
|
|
13
|
+
import { observePrefersColorScheme } from "./color-scheme/observe-prefers-color-scheme.mjs";
|
|
14
|
+
import { CSSProperties } from "./style/css-properties.mjs";
|
|
15
|
+
import { defineCSSProperties } from "./style/define-css-properties.mjs";
|
|
16
|
+
import { getCSSVariableValue } from "./style/get-css-variable-value.mjs";
|
|
17
|
+
import { JustStyle, JustStyleFnProps, JustStyleProps } from "./style/just-style.mjs";
|
|
18
|
+
import { resolveStyle } from "./style/resolve-style.mjs";
|
|
19
|
+
import { StyleProps } from "./style/style-props.mjs";
|
|
20
|
+
import { toDomStyle } from "./style/to-dom-style.mjs";
|
|
21
|
+
import { getRemToPxScale } from "./units/get-rem-to-px-scale.mjs";
|
|
22
|
+
import { px2num } from "./units/px-2-num.mjs";
|
|
23
|
+
import { px2rem } from "./units/px-2-rem.mjs";
|
|
24
|
+
import { rem2px } from "./units/rem-2-px.mjs";
|
|
25
|
+
import { appendId } from "./utils/append-id.mjs";
|
|
26
|
+
export { CSSProperties, ClassNameProps, DataAttribute, JustChildren, JustChildrenFnProps, JustChildrenProps, JustClassName, JustClassNameFnProps, JustClassNameProps, JustStyle, JustStyleFnProps, JustStyleProps, StyleProps, appendId, clsx, defineCSSProperties, getAttribute, getCSSVariableValue, getDataAttribute, getPrefersColorScheme, getRemToPxScale, observeAttributes, observeDataAttributes, observePrefersColorScheme, px2num, px2rem, rem2px, resolveChildren, resolveClassName, resolveStyle, toDomStyle };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { getAttribute } from "./attributes/get-attribute.mjs";
|
|
2
|
+
import { getDataAttribute } from "./attributes/get-data-attribute.mjs";
|
|
3
|
+
import { observeAttributes } from "./attributes/observe-attribute.mjs";
|
|
4
|
+
import { observeDataAttributes } from "./attributes/observe-data-attribute.mjs";
|
|
5
|
+
import { resolveChildren } from "./children/resolve-children.mjs";
|
|
6
|
+
import { clsx } from "./class-name/clsx.mjs";
|
|
7
|
+
import { resolveClassName } from "./class-name/resolve-class-name.mjs";
|
|
8
|
+
import { getPrefersColorScheme } from "./color-scheme/get-prefers-color-scheme.mjs";
|
|
9
|
+
import { observePrefersColorScheme } from "./color-scheme/observe-prefers-color-scheme.mjs";
|
|
10
|
+
import { defineCSSProperties } from "./style/define-css-properties.mjs";
|
|
11
|
+
import { getCSSVariableValue } from "./style/get-css-variable-value.mjs";
|
|
12
|
+
import { resolveStyle } from "./style/resolve-style.mjs";
|
|
13
|
+
import { toDomStyle } from "./style/to-dom-style.mjs";
|
|
14
|
+
import { getRemToPxScale } from "./units/get-rem-to-px-scale.mjs";
|
|
15
|
+
import { px2num } from "./units/px-2-num.mjs";
|
|
16
|
+
import { px2rem } from "./units/px-2-rem.mjs";
|
|
17
|
+
import { rem2px } from "./units/rem-2-px.mjs";
|
|
18
|
+
import { appendId } from "./utils/append-id.mjs";
|
|
19
|
+
|
|
20
|
+
export { appendId, clsx, defineCSSProperties, getAttribute, getCSSVariableValue, getDataAttribute, getPrefersColorScheme, getRemToPxScale, observeAttributes, observeDataAttributes, observePrefersColorScheme, px2num, px2rem, rem2px, resolveChildren, resolveClassName, resolveStyle, toDomStyle };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_observe_attribute = require('../../attributes/observe-attribute.cjs');
|
|
3
|
+
let react = require("react");
|
|
4
|
+
|
|
5
|
+
//#region src/react/hooks/use-attribute.ts
|
|
6
|
+
/**
|
|
7
|
+
* React hook that returns the current value of an attribute on a target element
|
|
8
|
+
* and a setter to update it. Stays in sync when the attribute changes (e.g. from elsewhere).
|
|
9
|
+
*
|
|
10
|
+
* @param attributeName - The attribute to observe (e.g. `'class'`, `'data-theme'`).
|
|
11
|
+
* @param element - The element to observe. Defaults to `document.documentElement` when omitted.
|
|
12
|
+
* @returns Tuple of [value, setValue]. Pass null to setValue to remove the attribute.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* const [className, setClassName] = useAttribute('class')
|
|
17
|
+
* const [theme, setTheme] = useAttribute('data-theme', myElement)
|
|
18
|
+
* setTheme('dark')
|
|
19
|
+
* setClassName(null) // removes class attribute
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
function useAttribute(attributeName, element = typeof document !== "undefined" ? document.documentElement : void 0) {
|
|
23
|
+
const [value, setValueState] = (0, react.useState)(() => element?.getAttribute(attributeName) ?? null);
|
|
24
|
+
(0, react.useEffect)(() => {
|
|
25
|
+
if (!element) return;
|
|
26
|
+
setValueState(element.getAttribute(attributeName));
|
|
27
|
+
const observer = require_observe_attribute.observeAttributes({ [attributeName]: (next) => {
|
|
28
|
+
setValueState(next);
|
|
29
|
+
} }, element);
|
|
30
|
+
return () => observer.disconnect();
|
|
31
|
+
}, [element, attributeName]);
|
|
32
|
+
return [value, (0, react.useCallback)((next) => {
|
|
33
|
+
if (!element) return;
|
|
34
|
+
if (next === null) element.removeAttribute(attributeName);
|
|
35
|
+
else element.setAttribute(attributeName, next);
|
|
36
|
+
}, [element, attributeName])];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
exports.useAttribute = useAttribute;
|
|
41
|
+
//# sourceMappingURL=use-attribute.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-attribute.cjs","names":["observeAttributes"],"sources":["../../../src/react/hooks/use-attribute.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from 'react'\nimport { observeAttributes } from '../../attributes/observe-attribute.ts'\n\n/**\n * React hook that returns the current value of an attribute on a target element\n * and a setter to update it. Stays in sync when the attribute changes (e.g. from elsewhere).\n *\n * @param attributeName - The attribute to observe (e.g. `'class'`, `'data-theme'`).\n * @param element - The element to observe. Defaults to `document.documentElement` when omitted.\n * @returns Tuple of [value, setValue]. Pass null to setValue to remove the attribute.\n *\n * @example\n * ```tsx\n * const [className, setClassName] = useAttribute('class')\n * const [theme, setTheme] = useAttribute('data-theme', myElement)\n * setTheme('dark')\n * setClassName(null) // removes class attribute\n * ```\n */\nexport function useAttribute(\n\tattributeName: string,\n\telement: Element | undefined = typeof document !== 'undefined'\n\t\t? document.documentElement\n\t\t: undefined\n): [string | null, (value: string | null) => void] {\n\tconst [value, setValueState] = useState<string | null>(\n\t\t() => element?.getAttribute(attributeName) ?? null\n\t)\n\n\tuseEffect(() => {\n\t\tif (!element) return\n\n\t\tsetValueState(element.getAttribute(attributeName))\n\n\t\tconst observer = observeAttributes(\n\t\t\t{\n\t\t\t\t[attributeName]: (next) => {\n\t\t\t\t\tsetValueState(next)\n\t\t\t\t}\n\t\t\t},\n\t\t\telement\n\t\t)\n\t\treturn () => observer.disconnect()\n\t}, [element, attributeName])\n\n\tconst setValue = useCallback(\n\t\t(next: string | null) => {\n\t\t\tif (!element) return\n\t\t\tif (next === null) {\n\t\t\t\telement.removeAttribute(attributeName)\n\t\t\t} else {\n\t\t\t\telement.setAttribute(attributeName, next)\n\t\t\t}\n\t\t},\n\t\t[element, attributeName]\n\t)\n\n\treturn [value, setValue]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,aACf,eACA,UAA+B,OAAO,aAAa,cAChD,SAAS,kBACT,QAC+C;CAClD,MAAM,CAAC,OAAO,2CACP,SAAS,aAAa,cAAc,IAAI,KAC9C;AAED,4BAAgB;AACf,MAAI,CAAC,QAAS;AAEd,gBAAc,QAAQ,aAAa,cAAc,CAAC;EAElD,MAAM,WAAWA,4CAChB,GACE,iBAAiB,SAAS;AAC1B,iBAAc,KAAK;KAEpB,EACD,QACA;AACD,eAAa,SAAS,YAAY;IAChC,CAAC,SAAS,cAAc,CAAC;AAc5B,QAAO,CAAC,+BAXN,SAAwB;AACxB,MAAI,CAAC,QAAS;AACd,MAAI,SAAS,KACZ,SAAQ,gBAAgB,cAAc;MAEtC,SAAQ,aAAa,eAAe,KAAK;IAG3C,CAAC,SAAS,cAAc,CACxB,CAEuB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/react/hooks/use-attribute.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* React hook that returns the current value of an attribute on a target element
|
|
4
|
+
* and a setter to update it. Stays in sync when the attribute changes (e.g. from elsewhere).
|
|
5
|
+
*
|
|
6
|
+
* @param attributeName - The attribute to observe (e.g. `'class'`, `'data-theme'`).
|
|
7
|
+
* @param element - The element to observe. Defaults to `document.documentElement` when omitted.
|
|
8
|
+
* @returns Tuple of [value, setValue]. Pass null to setValue to remove the attribute.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* const [className, setClassName] = useAttribute('class')
|
|
13
|
+
* const [theme, setTheme] = useAttribute('data-theme', myElement)
|
|
14
|
+
* setTheme('dark')
|
|
15
|
+
* setClassName(null) // removes class attribute
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
declare function useAttribute(attributeName: string, element?: Element | undefined): [string | null, (value: string | null) => void];
|
|
19
|
+
//#endregion
|
|
20
|
+
export { useAttribute };
|
|
21
|
+
//# sourceMappingURL=use-attribute.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-attribute.d.cts","names":[],"sources":["../../../src/react/hooks/use-attribute.ts"],"sourcesContent":[],"mappings":";;AAmBA;;;;;;;;;;;;;;;iBAAgB,YAAA,kCAEN"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/react/hooks/use-attribute.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* React hook that returns the current value of an attribute on a target element
|
|
4
|
+
* and a setter to update it. Stays in sync when the attribute changes (e.g. from elsewhere).
|
|
5
|
+
*
|
|
6
|
+
* @param attributeName - The attribute to observe (e.g. `'class'`, `'data-theme'`).
|
|
7
|
+
* @param element - The element to observe. Defaults to `document.documentElement` when omitted.
|
|
8
|
+
* @returns Tuple of [value, setValue]. Pass null to setValue to remove the attribute.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* const [className, setClassName] = useAttribute('class')
|
|
13
|
+
* const [theme, setTheme] = useAttribute('data-theme', myElement)
|
|
14
|
+
* setTheme('dark')
|
|
15
|
+
* setClassName(null) // removes class attribute
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
declare function useAttribute(attributeName: string, element?: Element | undefined): [string | null, (value: string | null) => void];
|
|
19
|
+
//#endregion
|
|
20
|
+
export { useAttribute };
|
|
21
|
+
//# sourceMappingURL=use-attribute.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-attribute.d.mts","names":[],"sources":["../../../src/react/hooks/use-attribute.ts"],"sourcesContent":[],"mappings":";;AAmBA;;;;;;;;;;;;;;;iBAAgB,YAAA,kCAEN"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { observeAttributes } from "../../attributes/observe-attribute.mjs";
|
|
2
|
+
import { useCallback, useEffect, useState } from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/react/hooks/use-attribute.ts
|
|
5
|
+
/**
|
|
6
|
+
* React hook that returns the current value of an attribute on a target element
|
|
7
|
+
* and a setter to update it. Stays in sync when the attribute changes (e.g. from elsewhere).
|
|
8
|
+
*
|
|
9
|
+
* @param attributeName - The attribute to observe (e.g. `'class'`, `'data-theme'`).
|
|
10
|
+
* @param element - The element to observe. Defaults to `document.documentElement` when omitted.
|
|
11
|
+
* @returns Tuple of [value, setValue]. Pass null to setValue to remove the attribute.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* const [className, setClassName] = useAttribute('class')
|
|
16
|
+
* const [theme, setTheme] = useAttribute('data-theme', myElement)
|
|
17
|
+
* setTheme('dark')
|
|
18
|
+
* setClassName(null) // removes class attribute
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
function useAttribute(attributeName, element = typeof document !== "undefined" ? document.documentElement : void 0) {
|
|
22
|
+
const [value, setValueState] = useState(() => element?.getAttribute(attributeName) ?? null);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (!element) return;
|
|
25
|
+
setValueState(element.getAttribute(attributeName));
|
|
26
|
+
const observer = observeAttributes({ [attributeName]: (next) => {
|
|
27
|
+
setValueState(next);
|
|
28
|
+
} }, element);
|
|
29
|
+
return () => observer.disconnect();
|
|
30
|
+
}, [element, attributeName]);
|
|
31
|
+
return [value, useCallback((next) => {
|
|
32
|
+
if (!element) return;
|
|
33
|
+
if (next === null) element.removeAttribute(attributeName);
|
|
34
|
+
else element.setAttribute(attributeName, next);
|
|
35
|
+
}, [element, attributeName])];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { useAttribute };
|
|
40
|
+
//# sourceMappingURL=use-attribute.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-attribute.mjs","names":[],"sources":["../../../src/react/hooks/use-attribute.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from 'react'\nimport { observeAttributes } from '../../attributes/observe-attribute.ts'\n\n/**\n * React hook that returns the current value of an attribute on a target element\n * and a setter to update it. Stays in sync when the attribute changes (e.g. from elsewhere).\n *\n * @param attributeName - The attribute to observe (e.g. `'class'`, `'data-theme'`).\n * @param element - The element to observe. Defaults to `document.documentElement` when omitted.\n * @returns Tuple of [value, setValue]. Pass null to setValue to remove the attribute.\n *\n * @example\n * ```tsx\n * const [className, setClassName] = useAttribute('class')\n * const [theme, setTheme] = useAttribute('data-theme', myElement)\n * setTheme('dark')\n * setClassName(null) // removes class attribute\n * ```\n */\nexport function useAttribute(\n\tattributeName: string,\n\telement: Element | undefined = typeof document !== 'undefined'\n\t\t? document.documentElement\n\t\t: undefined\n): [string | null, (value: string | null) => void] {\n\tconst [value, setValueState] = useState<string | null>(\n\t\t() => element?.getAttribute(attributeName) ?? null\n\t)\n\n\tuseEffect(() => {\n\t\tif (!element) return\n\n\t\tsetValueState(element.getAttribute(attributeName))\n\n\t\tconst observer = observeAttributes(\n\t\t\t{\n\t\t\t\t[attributeName]: (next) => {\n\t\t\t\t\tsetValueState(next)\n\t\t\t\t}\n\t\t\t},\n\t\t\telement\n\t\t)\n\t\treturn () => observer.disconnect()\n\t}, [element, attributeName])\n\n\tconst setValue = useCallback(\n\t\t(next: string | null) => {\n\t\t\tif (!element) return\n\t\t\tif (next === null) {\n\t\t\t\telement.removeAttribute(attributeName)\n\t\t\t} else {\n\t\t\t\telement.setAttribute(attributeName, next)\n\t\t\t}\n\t\t},\n\t\t[element, attributeName]\n\t)\n\n\treturn [value, setValue]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,aACf,eACA,UAA+B,OAAO,aAAa,cAChD,SAAS,kBACT,QAC+C;CAClD,MAAM,CAAC,OAAO,iBAAiB,eACxB,SAAS,aAAa,cAAc,IAAI,KAC9C;AAED,iBAAgB;AACf,MAAI,CAAC,QAAS;AAEd,gBAAc,QAAQ,aAAa,cAAc,CAAC;EAElD,MAAM,WAAW,kBAChB,GACE,iBAAiB,SAAS;AAC1B,iBAAc,KAAK;KAEpB,EACD,QACA;AACD,eAAa,SAAS,YAAY;IAChC,CAAC,SAAS,cAAc,CAAC;AAc5B,QAAO,CAAC,OAZS,aACf,SAAwB;AACxB,MAAI,CAAC,QAAS;AACd,MAAI,SAAS,KACZ,SAAQ,gBAAgB,cAAc;MAEtC,SAAQ,aAAa,eAAe,KAAK;IAG3C,CAAC,SAAS,cAAc,CACxB,CAEuB"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_get_prefers_color_scheme = require('../../color-scheme/get-prefers-color-scheme.cjs');
|
|
3
|
+
const require_observe_prefers_color_scheme = require('../../color-scheme/observe-prefers-color-scheme.cjs');
|
|
4
|
+
let react = require("react");
|
|
5
|
+
|
|
6
|
+
//#region src/react/hooks/use-prefers-color-scheme.ts
|
|
7
|
+
/**
|
|
8
|
+
* React hook that returns the current system color scheme preference and re-renders when it changes.
|
|
9
|
+
*
|
|
10
|
+
* Uses `prefers-color-scheme` media query. Returns `'light'` or `'dark'`; re-renders when the user
|
|
11
|
+
* changes their OS or browser light/dark setting.
|
|
12
|
+
*
|
|
13
|
+
* For SSR, uses `defaultColorScheme` when `matchMedia` is unavailable. On client, reads the real
|
|
14
|
+
* value immediately (no flicker); `useEffect` syncs and subscribes to changes.
|
|
15
|
+
*
|
|
16
|
+
* @param defaultColorScheme - Fallback when `matchMedia` is unavailable (default: `'light'`)
|
|
17
|
+
* @returns Current system color scheme: `'light'` or `'dark'`
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* const scheme = usePrefersColorScheme()
|
|
22
|
+
* return <div>System prefers: {scheme}</div>
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```tsx
|
|
27
|
+
* const scheme = usePrefersColorScheme('dark')
|
|
28
|
+
* return <div>System prefers: {scheme}</div>
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
function usePrefersColorScheme(defaultColorScheme = "light") {
|
|
32
|
+
const [scheme, setScheme] = (0, react.useState)(() => require_get_prefers_color_scheme.getPrefersColorScheme(defaultColorScheme));
|
|
33
|
+
(0, react.useEffect)(() => {
|
|
34
|
+
setScheme(require_get_prefers_color_scheme.getPrefersColorScheme());
|
|
35
|
+
return require_observe_prefers_color_scheme.observePrefersColorScheme(setScheme);
|
|
36
|
+
}, []);
|
|
37
|
+
return scheme;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
exports.usePrefersColorScheme = usePrefersColorScheme;
|
|
42
|
+
//# sourceMappingURL=use-prefers-color-scheme.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-prefers-color-scheme.cjs","names":["getPrefersColorScheme","observePrefersColorScheme"],"sources":["../../../src/react/hooks/use-prefers-color-scheme.ts"],"sourcesContent":["import { useEffect, useState } from 'react'\nimport { getPrefersColorScheme } from '../../color-scheme/get-prefers-color-scheme.ts'\nimport { observePrefersColorScheme } from '../../color-scheme/observe-prefers-color-scheme.ts'\n\n/**\n * React hook that returns the current system color scheme preference and re-renders when it changes.\n *\n * Uses `prefers-color-scheme` media query. Returns `'light'` or `'dark'`; re-renders when the user\n * changes their OS or browser light/dark setting.\n *\n * For SSR, uses `defaultColorScheme` when `matchMedia` is unavailable. On client, reads the real\n * value immediately (no flicker); `useEffect` syncs and subscribes to changes.\n *\n * @param defaultColorScheme - Fallback when `matchMedia` is unavailable (default: `'light'`)\n * @returns Current system color scheme: `'light'` or `'dark'`\n *\n * @example\n * ```tsx\n * const scheme = usePrefersColorScheme()\n * return <div>System prefers: {scheme}</div>\n * ```\n *\n * @example\n * ```tsx\n * const scheme = usePrefersColorScheme('dark')\n * return <div>System prefers: {scheme}</div>\n * ```\n */\nexport function usePrefersColorScheme(\n\tdefaultColorScheme: 'light' | 'dark' = 'light'\n): 'light' | 'dark' {\n\tconst [scheme, setScheme] = useState<'light' | 'dark'>(() =>\n\t\tgetPrefersColorScheme(defaultColorScheme)\n\t)\n\n\tuseEffect(() => {\n\t\tsetScheme(getPrefersColorScheme())\n\t\treturn observePrefersColorScheme(setScheme)\n\t}, [])\n\n\treturn scheme\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,sBACf,qBAAuC,SACpB;CACnB,MAAM,CAAC,QAAQ,uCACdA,uDAAsB,mBAAmB,CACzC;AAED,4BAAgB;AACf,YAAUA,wDAAuB,CAAC;AAClC,SAAOC,+DAA0B,UAAU;IACzC,EAAE,CAAC;AAEN,QAAO"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region src/react/hooks/use-prefers-color-scheme.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* React hook that returns the current system color scheme preference and re-renders when it changes.
|
|
4
|
+
*
|
|
5
|
+
* Uses `prefers-color-scheme` media query. Returns `'light'` or `'dark'`; re-renders when the user
|
|
6
|
+
* changes their OS or browser light/dark setting.
|
|
7
|
+
*
|
|
8
|
+
* For SSR, uses `defaultColorScheme` when `matchMedia` is unavailable. On client, reads the real
|
|
9
|
+
* value immediately (no flicker); `useEffect` syncs and subscribes to changes.
|
|
10
|
+
*
|
|
11
|
+
* @param defaultColorScheme - Fallback when `matchMedia` is unavailable (default: `'light'`)
|
|
12
|
+
* @returns Current system color scheme: `'light'` or `'dark'`
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* const scheme = usePrefersColorScheme()
|
|
17
|
+
* return <div>System prefers: {scheme}</div>
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```tsx
|
|
22
|
+
* const scheme = usePrefersColorScheme('dark')
|
|
23
|
+
* return <div>System prefers: {scheme}</div>
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
declare function usePrefersColorScheme(defaultColorScheme?: 'light' | 'dark'): 'light' | 'dark';
|
|
27
|
+
//#endregion
|
|
28
|
+
export { usePrefersColorScheme };
|
|
29
|
+
//# sourceMappingURL=use-prefers-color-scheme.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-prefers-color-scheme.d.cts","names":[],"sources":["../../../src/react/hooks/use-prefers-color-scheme.ts"],"sourcesContent":[],"mappings":";;AA4BA;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,qBAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region src/react/hooks/use-prefers-color-scheme.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* React hook that returns the current system color scheme preference and re-renders when it changes.
|
|
4
|
+
*
|
|
5
|
+
* Uses `prefers-color-scheme` media query. Returns `'light'` or `'dark'`; re-renders when the user
|
|
6
|
+
* changes their OS or browser light/dark setting.
|
|
7
|
+
*
|
|
8
|
+
* For SSR, uses `defaultColorScheme` when `matchMedia` is unavailable. On client, reads the real
|
|
9
|
+
* value immediately (no flicker); `useEffect` syncs and subscribes to changes.
|
|
10
|
+
*
|
|
11
|
+
* @param defaultColorScheme - Fallback when `matchMedia` is unavailable (default: `'light'`)
|
|
12
|
+
* @returns Current system color scheme: `'light'` or `'dark'`
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* const scheme = usePrefersColorScheme()
|
|
17
|
+
* return <div>System prefers: {scheme}</div>
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```tsx
|
|
22
|
+
* const scheme = usePrefersColorScheme('dark')
|
|
23
|
+
* return <div>System prefers: {scheme}</div>
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
declare function usePrefersColorScheme(defaultColorScheme?: 'light' | 'dark'): 'light' | 'dark';
|
|
27
|
+
//#endregion
|
|
28
|
+
export { usePrefersColorScheme };
|
|
29
|
+
//# sourceMappingURL=use-prefers-color-scheme.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-prefers-color-scheme.d.mts","names":[],"sources":["../../../src/react/hooks/use-prefers-color-scheme.ts"],"sourcesContent":[],"mappings":";;AA4BA;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,qBAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { getPrefersColorScheme } from "../../color-scheme/get-prefers-color-scheme.mjs";
|
|
2
|
+
import { observePrefersColorScheme } from "../../color-scheme/observe-prefers-color-scheme.mjs";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/react/hooks/use-prefers-color-scheme.ts
|
|
6
|
+
/**
|
|
7
|
+
* React hook that returns the current system color scheme preference and re-renders when it changes.
|
|
8
|
+
*
|
|
9
|
+
* Uses `prefers-color-scheme` media query. Returns `'light'` or `'dark'`; re-renders when the user
|
|
10
|
+
* changes their OS or browser light/dark setting.
|
|
11
|
+
*
|
|
12
|
+
* For SSR, uses `defaultColorScheme` when `matchMedia` is unavailable. On client, reads the real
|
|
13
|
+
* value immediately (no flicker); `useEffect` syncs and subscribes to changes.
|
|
14
|
+
*
|
|
15
|
+
* @param defaultColorScheme - Fallback when `matchMedia` is unavailable (default: `'light'`)
|
|
16
|
+
* @returns Current system color scheme: `'light'` or `'dark'`
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* const scheme = usePrefersColorScheme()
|
|
21
|
+
* return <div>System prefers: {scheme}</div>
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```tsx
|
|
26
|
+
* const scheme = usePrefersColorScheme('dark')
|
|
27
|
+
* return <div>System prefers: {scheme}</div>
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
function usePrefersColorScheme(defaultColorScheme = "light") {
|
|
31
|
+
const [scheme, setScheme] = useState(() => getPrefersColorScheme(defaultColorScheme));
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
setScheme(getPrefersColorScheme());
|
|
34
|
+
return observePrefersColorScheme(setScheme);
|
|
35
|
+
}, []);
|
|
36
|
+
return scheme;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
export { usePrefersColorScheme };
|
|
41
|
+
//# sourceMappingURL=use-prefers-color-scheme.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-prefers-color-scheme.mjs","names":[],"sources":["../../../src/react/hooks/use-prefers-color-scheme.ts"],"sourcesContent":["import { useEffect, useState } from 'react'\nimport { getPrefersColorScheme } from '../../color-scheme/get-prefers-color-scheme.ts'\nimport { observePrefersColorScheme } from '../../color-scheme/observe-prefers-color-scheme.ts'\n\n/**\n * React hook that returns the current system color scheme preference and re-renders when it changes.\n *\n * Uses `prefers-color-scheme` media query. Returns `'light'` or `'dark'`; re-renders when the user\n * changes their OS or browser light/dark setting.\n *\n * For SSR, uses `defaultColorScheme` when `matchMedia` is unavailable. On client, reads the real\n * value immediately (no flicker); `useEffect` syncs and subscribes to changes.\n *\n * @param defaultColorScheme - Fallback when `matchMedia` is unavailable (default: `'light'`)\n * @returns Current system color scheme: `'light'` or `'dark'`\n *\n * @example\n * ```tsx\n * const scheme = usePrefersColorScheme()\n * return <div>System prefers: {scheme}</div>\n * ```\n *\n * @example\n * ```tsx\n * const scheme = usePrefersColorScheme('dark')\n * return <div>System prefers: {scheme}</div>\n * ```\n */\nexport function usePrefersColorScheme(\n\tdefaultColorScheme: 'light' | 'dark' = 'light'\n): 'light' | 'dark' {\n\tconst [scheme, setScheme] = useState<'light' | 'dark'>(() =>\n\t\tgetPrefersColorScheme(defaultColorScheme)\n\t)\n\n\tuseEffect(() => {\n\t\tsetScheme(getPrefersColorScheme())\n\t\treturn observePrefersColorScheme(setScheme)\n\t}, [])\n\n\treturn scheme\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,sBACf,qBAAuC,SACpB;CACnB,MAAM,CAAC,QAAQ,aAAa,eAC3B,sBAAsB,mBAAmB,CACzC;AAED,iBAAgB;AACf,YAAU,uBAAuB,CAAC;AAClC,SAAO,0BAA0B,UAAU;IACzC,EAAE,CAAC;AAEN,QAAO"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_observe_theme_from_stores = require('../../theme/_utils/observe-theme-from-stores.cjs');
|
|
3
|
+
const require_set_theme_to_stores = require('../../theme/_utils/set-theme-to-stores.cjs');
|
|
4
|
+
const require_resolve_theme_from_class_name = require('../../theme/class-name/resolve-theme-from-class-name.cjs');
|
|
5
|
+
const require_theme_entry = require('../../theme/theme-entry.cjs');
|
|
6
|
+
const require_class_name_theme_store = require('../../theme/theme-store/class-name-theme-store/class-name-theme-store.cjs');
|
|
7
|
+
let react = require("react");
|
|
8
|
+
|
|
9
|
+
//#region src/react/hooks/use-theme-by-class-name.ts
|
|
10
|
+
/**
|
|
11
|
+
* React hook that returns the current theme (from element class) and a setter.
|
|
12
|
+
* Subscribes to class changes on the element so the returned theme stays in sync.
|
|
13
|
+
*
|
|
14
|
+
* @param themes - Record mapping theme keys to their class name values
|
|
15
|
+
* @param options.theme - Fallback theme key when no matching class is found
|
|
16
|
+
* @param options.element - Element to read/set theme on (defaults to document.documentElement)
|
|
17
|
+
* @returns Tuple of [currentTheme, setTheme]
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* const themes = { light: 'theme-light', dark: 'theme-dark' }
|
|
22
|
+
* const [theme, setTheme] = useThemeByClassName(themes, { theme: 'light' })
|
|
23
|
+
*
|
|
24
|
+
* return (
|
|
25
|
+
* <>
|
|
26
|
+
* <span>Current: {theme}</span>
|
|
27
|
+
* <button onClick={() => setTheme('dark')}>Dark</button>
|
|
28
|
+
* <button onClick={() => setTheme('light')}>Light</button>
|
|
29
|
+
* </>
|
|
30
|
+
* )
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
function useThemeByClassName(themes, options) {
|
|
34
|
+
const element = options?.element ?? (typeof document !== "undefined" ? document.documentElement : void 0);
|
|
35
|
+
const defaultTheme = options?.defaultTheme;
|
|
36
|
+
const store = (0, react.useMemo)(() => require_class_name_theme_store.classNameThemeStore(themes, { element }), [element, themes]);
|
|
37
|
+
const [theme, setThemeState] = (0, react.useState)(() => {
|
|
38
|
+
if (element) return require_resolve_theme_from_class_name.resolveThemeFromClassName(themes, element.className) ?? defaultTheme;
|
|
39
|
+
return defaultTheme;
|
|
40
|
+
});
|
|
41
|
+
(0, react.useEffect)(() => {
|
|
42
|
+
if (!element) return;
|
|
43
|
+
return require_observe_theme_from_stores.observeThemeFromStores([store], defaultTheme, setThemeState);
|
|
44
|
+
}, [
|
|
45
|
+
element,
|
|
46
|
+
store,
|
|
47
|
+
defaultTheme
|
|
48
|
+
]);
|
|
49
|
+
return [theme, (0, react.useCallback)((themeKey) => {
|
|
50
|
+
if (element) require_set_theme_to_stores.setThemeToStores([store], require_theme_entry.themeEntry(themes, themeKey));
|
|
51
|
+
}, [
|
|
52
|
+
element,
|
|
53
|
+
store,
|
|
54
|
+
themes
|
|
55
|
+
])];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
exports.useThemeByClassName = useThemeByClassName;
|
|
60
|
+
//# sourceMappingURL=use-theme-by-class-name.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-theme-by-class-name.cjs","names":["classNameThemeStore","resolveThemeFromClassName","observeThemeFromStores","themeEntry"],"sources":["../../../src/react/hooks/use-theme-by-class-name.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useState } from 'react'\nimport { observeThemeFromStores } from '../../theme/_utils/observe-theme-from-stores.ts'\nimport { setThemeToStores } from '../../theme/_utils/set-theme-to-stores.ts'\nimport { resolveThemeFromClassName } from '../../theme/class-name/resolve-theme-from-class-name.ts'\nimport { themeEntry } from '../../theme/theme-entry.ts'\nimport type { ThemeMap } from '../../theme/theme-map.types.ts'\nimport { classNameThemeStore } from '../../theme/theme-store/class-name-theme-store/class-name-theme-store.ts'\n\n/**\n * React hook that returns the current theme (from element class) and a setter.\n * Subscribes to class changes on the element so the returned theme stays in sync.\n *\n * @param themes - Record mapping theme keys to their class name values\n * @param options.theme - Fallback theme key when no matching class is found\n * @param options.element - Element to read/set theme on (defaults to document.documentElement)\n * @returns Tuple of [currentTheme, setTheme]\n *\n * @example\n * ```tsx\n * const themes = { light: 'theme-light', dark: 'theme-dark' }\n * const [theme, setTheme] = useThemeByClassName(themes, { theme: 'light' })\n *\n * return (\n * <>\n * <span>Current: {theme}</span>\n * <button onClick={() => setTheme('dark')}>Dark</button>\n * <button onClick={() => setTheme('light')}>Light</button>\n * </>\n * )\n * ```\n */\nexport function useThemeByClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\toptions?: {\n\t\tdefaultTheme?: keyof Themes | undefined\n\t\telement?: Element | undefined\n\t}\n): [keyof Themes | undefined, (theme: keyof Themes) => void] {\n\tconst element =\n\t\toptions?.element ?? (typeof document !== 'undefined' ? document.documentElement : undefined)\n\tconst defaultTheme = options?.defaultTheme\n\n\tconst store = useMemo(() => classNameThemeStore(themes, { element }), [element, themes])\n\n\tconst [theme, setThemeState] = useState<keyof Themes | undefined>(() => {\n\t\tif (element) {\n\t\t\tconst resolved = resolveThemeFromClassName(themes, element.className)\n\t\t\treturn resolved ?? defaultTheme\n\t\t}\n\t\treturn defaultTheme\n\t})\n\n\tuseEffect(() => {\n\t\tif (!element) return\n\t\tconst unobserve = observeThemeFromStores([store], defaultTheme, setThemeState)\n\t\treturn unobserve\n\t}, [element, store, defaultTheme])\n\n\tconst setTheme = useCallback(\n\t\t(themeKey: keyof Themes) => {\n\t\t\tif (element) {\n\t\t\t\tsetThemeToStores([store], themeEntry(themes, themeKey))\n\t\t\t}\n\t\t},\n\t\t[element, store, themes]\n\t)\n\n\treturn [theme, setTheme]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,SAAgB,oBACf,QACA,SAI4D;CAC5D,MAAM,UACL,SAAS,YAAY,OAAO,aAAa,cAAc,SAAS,kBAAkB;CACnF,MAAM,eAAe,SAAS;CAE9B,MAAM,iCAAsBA,mDAAoB,QAAQ,EAAE,SAAS,CAAC,EAAE,CAAC,SAAS,OAAO,CAAC;CAExF,MAAM,CAAC,OAAO,2CAA0D;AACvE,MAAI,QAEH,QADiBC,gEAA0B,QAAQ,QAAQ,UAAU,IAClD;AAEpB,SAAO;GACN;AAEF,4BAAgB;AACf,MAAI,CAAC,QAAS;AAEd,SADkBC,yDAAuB,CAAC,MAAM,EAAE,cAAc,cAAc;IAE5E;EAAC;EAAS;EAAO;EAAa,CAAC;AAWlC,QAAO,CAAC,+BARN,aAA2B;AAC3B,MAAI,QACH,8CAAiB,CAAC,MAAM,EAAEC,+BAAW,QAAQ,SAAS,CAAC;IAGzD;EAAC;EAAS;EAAO;EAAO,CACxB,CAEuB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ThemeMap } from "../../theme/theme-map.types.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/react/hooks/use-theme-by-class-name.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* React hook that returns the current theme (from element class) and a setter.
|
|
7
|
+
* Subscribes to class changes on the element so the returned theme stays in sync.
|
|
8
|
+
*
|
|
9
|
+
* @param themes - Record mapping theme keys to their class name values
|
|
10
|
+
* @param options.theme - Fallback theme key when no matching class is found
|
|
11
|
+
* @param options.element - Element to read/set theme on (defaults to document.documentElement)
|
|
12
|
+
* @returns Tuple of [currentTheme, setTheme]
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* const themes = { light: 'theme-light', dark: 'theme-dark' }
|
|
17
|
+
* const [theme, setTheme] = useThemeByClassName(themes, { theme: 'light' })
|
|
18
|
+
*
|
|
19
|
+
* return (
|
|
20
|
+
* <>
|
|
21
|
+
* <span>Current: {theme}</span>
|
|
22
|
+
* <button onClick={() => setTheme('dark')}>Dark</button>
|
|
23
|
+
* <button onClick={() => setTheme('light')}>Light</button>
|
|
24
|
+
* </>
|
|
25
|
+
* )
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
declare function useThemeByClassName<Themes extends ThemeMap>(themes: Themes, options?: {
|
|
29
|
+
defaultTheme?: keyof Themes | undefined;
|
|
30
|
+
element?: Element | undefined;
|
|
31
|
+
}): [keyof Themes | undefined, (theme: keyof Themes) => void];
|
|
32
|
+
//#endregion
|
|
33
|
+
export { useThemeByClassName };
|
|
34
|
+
//# sourceMappingURL=use-theme-by-class-name.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-theme-by-class-name.d.cts","names":[],"sources":["../../../src/react/hooks/use-theme-by-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;AA+BA;;;;;;;;;;;;;;;;;;;;;iBAAgB,mCAAmC,kBAC1C;uBAEc;YACX;WAEF,kCAAkC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ThemeMap } from "../../theme/theme-map.types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/react/hooks/use-theme-by-class-name.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* React hook that returns the current theme (from element class) and a setter.
|
|
7
|
+
* Subscribes to class changes on the element so the returned theme stays in sync.
|
|
8
|
+
*
|
|
9
|
+
* @param themes - Record mapping theme keys to their class name values
|
|
10
|
+
* @param options.theme - Fallback theme key when no matching class is found
|
|
11
|
+
* @param options.element - Element to read/set theme on (defaults to document.documentElement)
|
|
12
|
+
* @returns Tuple of [currentTheme, setTheme]
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* const themes = { light: 'theme-light', dark: 'theme-dark' }
|
|
17
|
+
* const [theme, setTheme] = useThemeByClassName(themes, { theme: 'light' })
|
|
18
|
+
*
|
|
19
|
+
* return (
|
|
20
|
+
* <>
|
|
21
|
+
* <span>Current: {theme}</span>
|
|
22
|
+
* <button onClick={() => setTheme('dark')}>Dark</button>
|
|
23
|
+
* <button onClick={() => setTheme('light')}>Light</button>
|
|
24
|
+
* </>
|
|
25
|
+
* )
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
declare function useThemeByClassName<Themes extends ThemeMap>(themes: Themes, options?: {
|
|
29
|
+
defaultTheme?: keyof Themes | undefined;
|
|
30
|
+
element?: Element | undefined;
|
|
31
|
+
}): [keyof Themes | undefined, (theme: keyof Themes) => void];
|
|
32
|
+
//#endregion
|
|
33
|
+
export { useThemeByClassName };
|
|
34
|
+
//# sourceMappingURL=use-theme-by-class-name.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-theme-by-class-name.d.mts","names":[],"sources":["../../../src/react/hooks/use-theme-by-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;AA+BA;;;;;;;;;;;;;;;;;;;;;iBAAgB,mCAAmC,kBAC1C;uBAEc;YACX;WAEF,kCAAkC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { observeThemeFromStores } from "../../theme/_utils/observe-theme-from-stores.mjs";
|
|
2
|
+
import { setThemeToStores } from "../../theme/_utils/set-theme-to-stores.mjs";
|
|
3
|
+
import { resolveThemeFromClassName } from "../../theme/class-name/resolve-theme-from-class-name.mjs";
|
|
4
|
+
import { themeEntry } from "../../theme/theme-entry.mjs";
|
|
5
|
+
import { classNameThemeStore } from "../../theme/theme-store/class-name-theme-store/class-name-theme-store.mjs";
|
|
6
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
7
|
+
|
|
8
|
+
//#region src/react/hooks/use-theme-by-class-name.ts
|
|
9
|
+
/**
|
|
10
|
+
* React hook that returns the current theme (from element class) and a setter.
|
|
11
|
+
* Subscribes to class changes on the element so the returned theme stays in sync.
|
|
12
|
+
*
|
|
13
|
+
* @param themes - Record mapping theme keys to their class name values
|
|
14
|
+
* @param options.theme - Fallback theme key when no matching class is found
|
|
15
|
+
* @param options.element - Element to read/set theme on (defaults to document.documentElement)
|
|
16
|
+
* @returns Tuple of [currentTheme, setTheme]
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* const themes = { light: 'theme-light', dark: 'theme-dark' }
|
|
21
|
+
* const [theme, setTheme] = useThemeByClassName(themes, { theme: 'light' })
|
|
22
|
+
*
|
|
23
|
+
* return (
|
|
24
|
+
* <>
|
|
25
|
+
* <span>Current: {theme}</span>
|
|
26
|
+
* <button onClick={() => setTheme('dark')}>Dark</button>
|
|
27
|
+
* <button onClick={() => setTheme('light')}>Light</button>
|
|
28
|
+
* </>
|
|
29
|
+
* )
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
function useThemeByClassName(themes, options) {
|
|
33
|
+
const element = options?.element ?? (typeof document !== "undefined" ? document.documentElement : void 0);
|
|
34
|
+
const defaultTheme = options?.defaultTheme;
|
|
35
|
+
const store = useMemo(() => classNameThemeStore(themes, { element }), [element, themes]);
|
|
36
|
+
const [theme, setThemeState] = useState(() => {
|
|
37
|
+
if (element) return resolveThemeFromClassName(themes, element.className) ?? defaultTheme;
|
|
38
|
+
return defaultTheme;
|
|
39
|
+
});
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (!element) return;
|
|
42
|
+
return observeThemeFromStores([store], defaultTheme, setThemeState);
|
|
43
|
+
}, [
|
|
44
|
+
element,
|
|
45
|
+
store,
|
|
46
|
+
defaultTheme
|
|
47
|
+
]);
|
|
48
|
+
return [theme, useCallback((themeKey) => {
|
|
49
|
+
if (element) setThemeToStores([store], themeEntry(themes, themeKey));
|
|
50
|
+
}, [
|
|
51
|
+
element,
|
|
52
|
+
store,
|
|
53
|
+
themes
|
|
54
|
+
])];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
export { useThemeByClassName };
|
|
59
|
+
//# sourceMappingURL=use-theme-by-class-name.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-theme-by-class-name.mjs","names":[],"sources":["../../../src/react/hooks/use-theme-by-class-name.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useState } from 'react'\nimport { observeThemeFromStores } from '../../theme/_utils/observe-theme-from-stores.ts'\nimport { setThemeToStores } from '../../theme/_utils/set-theme-to-stores.ts'\nimport { resolveThemeFromClassName } from '../../theme/class-name/resolve-theme-from-class-name.ts'\nimport { themeEntry } from '../../theme/theme-entry.ts'\nimport type { ThemeMap } from '../../theme/theme-map.types.ts'\nimport { classNameThemeStore } from '../../theme/theme-store/class-name-theme-store/class-name-theme-store.ts'\n\n/**\n * React hook that returns the current theme (from element class) and a setter.\n * Subscribes to class changes on the element so the returned theme stays in sync.\n *\n * @param themes - Record mapping theme keys to their class name values\n * @param options.theme - Fallback theme key when no matching class is found\n * @param options.element - Element to read/set theme on (defaults to document.documentElement)\n * @returns Tuple of [currentTheme, setTheme]\n *\n * @example\n * ```tsx\n * const themes = { light: 'theme-light', dark: 'theme-dark' }\n * const [theme, setTheme] = useThemeByClassName(themes, { theme: 'light' })\n *\n * return (\n * <>\n * <span>Current: {theme}</span>\n * <button onClick={() => setTheme('dark')}>Dark</button>\n * <button onClick={() => setTheme('light')}>Light</button>\n * </>\n * )\n * ```\n */\nexport function useThemeByClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\toptions?: {\n\t\tdefaultTheme?: keyof Themes | undefined\n\t\telement?: Element | undefined\n\t}\n): [keyof Themes | undefined, (theme: keyof Themes) => void] {\n\tconst element =\n\t\toptions?.element ?? (typeof document !== 'undefined' ? document.documentElement : undefined)\n\tconst defaultTheme = options?.defaultTheme\n\n\tconst store = useMemo(() => classNameThemeStore(themes, { element }), [element, themes])\n\n\tconst [theme, setThemeState] = useState<keyof Themes | undefined>(() => {\n\t\tif (element) {\n\t\t\tconst resolved = resolveThemeFromClassName(themes, element.className)\n\t\t\treturn resolved ?? defaultTheme\n\t\t}\n\t\treturn defaultTheme\n\t})\n\n\tuseEffect(() => {\n\t\tif (!element) return\n\t\tconst unobserve = observeThemeFromStores([store], defaultTheme, setThemeState)\n\t\treturn unobserve\n\t}, [element, store, defaultTheme])\n\n\tconst setTheme = useCallback(\n\t\t(themeKey: keyof Themes) => {\n\t\t\tif (element) {\n\t\t\t\tsetThemeToStores([store], themeEntry(themes, themeKey))\n\t\t\t}\n\t\t},\n\t\t[element, store, themes]\n\t)\n\n\treturn [theme, setTheme]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,SAAgB,oBACf,QACA,SAI4D;CAC5D,MAAM,UACL,SAAS,YAAY,OAAO,aAAa,cAAc,SAAS,kBAAkB;CACnF,MAAM,eAAe,SAAS;CAE9B,MAAM,QAAQ,cAAc,oBAAoB,QAAQ,EAAE,SAAS,CAAC,EAAE,CAAC,SAAS,OAAO,CAAC;CAExF,MAAM,CAAC,OAAO,iBAAiB,eAAyC;AACvE,MAAI,QAEH,QADiB,0BAA0B,QAAQ,QAAQ,UAAU,IAClD;AAEpB,SAAO;GACN;AAEF,iBAAgB;AACf,MAAI,CAAC,QAAS;AAEd,SADkB,uBAAuB,CAAC,MAAM,EAAE,cAAc,cAAc;IAE5E;EAAC;EAAS;EAAO;EAAa,CAAC;AAWlC,QAAO,CAAC,OATS,aACf,aAA2B;AAC3B,MAAI,QACH,kBAAiB,CAAC,MAAM,EAAE,WAAW,QAAQ,SAAS,CAAC;IAGzD;EAAC;EAAS;EAAO;EAAO,CACxB,CAEuB"}
|