@just-web/toolkits 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/attributes/get-attribute.cjs +1 -1
- package/dist/attributes/get-attribute.cjs.map +1 -1
- package/dist/attributes/get-attribute.d.cts +2 -2
- package/dist/attributes/get-attribute.d.cts.map +1 -1
- package/dist/attributes/get-attribute.d.mts +2 -2
- package/dist/attributes/get-attribute.d.mts.map +1 -1
- package/dist/attributes/get-attribute.mjs +1 -1
- package/dist/attributes/get-attribute.mjs.map +1 -1
- package/dist/attributes/get-data-attribute.cjs +1 -1
- package/dist/attributes/get-data-attribute.cjs.map +1 -1
- package/dist/attributes/get-data-attribute.d.cts +2 -2
- package/dist/attributes/get-data-attribute.d.cts.map +1 -1
- package/dist/attributes/get-data-attribute.d.mts +2 -2
- package/dist/attributes/get-data-attribute.d.mts.map +1 -1
- package/dist/attributes/get-data-attribute.mjs +1 -1
- package/dist/attributes/get-data-attribute.mjs.map +1 -1
- package/dist/attributes/observe-attribute.cjs +1 -1
- package/dist/attributes/observe-attribute.cjs.map +1 -1
- package/dist/attributes/observe-attribute.d.cts +2 -2
- package/dist/attributes/observe-attribute.d.cts.map +1 -1
- package/dist/attributes/observe-attribute.d.mts +2 -2
- package/dist/attributes/observe-attribute.d.mts.map +1 -1
- package/dist/attributes/observe-attribute.mjs +1 -1
- package/dist/attributes/observe-attribute.mjs.map +1 -1
- package/dist/attributes/observe-data-attribute.cjs +1 -1
- package/dist/attributes/observe-data-attribute.cjs.map +1 -1
- package/dist/attributes/observe-data-attribute.d.cts +2 -2
- package/dist/attributes/observe-data-attribute.d.cts.map +1 -1
- package/dist/attributes/observe-data-attribute.d.mts +2 -2
- package/dist/attributes/observe-data-attribute.d.mts.map +1 -1
- package/dist/attributes/observe-data-attribute.mjs +1 -1
- package/dist/attributes/observe-data-attribute.mjs.map +1 -1
- package/dist/color-scheme/color-scheme.types.d.cts +11 -0
- package/dist/color-scheme/color-scheme.types.d.cts.map +1 -0
- package/dist/color-scheme/color-scheme.types.d.mts +11 -0
- package/dist/color-scheme/color-scheme.types.d.mts.map +1 -0
- package/dist/color-scheme/get-prefers-color-scheme.cjs +3 -1
- package/dist/color-scheme/get-prefers-color-scheme.cjs.map +1 -1
- package/dist/color-scheme/get-prefers-color-scheme.d.cts +7 -2
- package/dist/color-scheme/get-prefers-color-scheme.d.cts.map +1 -1
- package/dist/color-scheme/get-prefers-color-scheme.d.mts +7 -2
- package/dist/color-scheme/get-prefers-color-scheme.d.mts.map +1 -1
- package/dist/color-scheme/get-prefers-color-scheme.mjs +3 -1
- package/dist/color-scheme/get-prefers-color-scheme.mjs.map +1 -1
- package/dist/color-scheme/observe-prefers-color-scheme.cjs.map +1 -1
- package/dist/color-scheme/observe-prefers-color-scheme.d.cts +4 -1
- package/dist/color-scheme/observe-prefers-color-scheme.d.cts.map +1 -1
- package/dist/color-scheme/observe-prefers-color-scheme.d.mts +4 -1
- package/dist/color-scheme/observe-prefers-color-scheme.d.mts.map +1 -1
- package/dist/color-scheme/observe-prefers-color-scheme.mjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.mts +2 -1
- package/dist/react/hooks/use-attribute.cjs +7 -7
- package/dist/react/hooks/use-attribute.cjs.map +1 -1
- package/dist/react/hooks/use-attribute.d.cts +4 -4
- package/dist/react/hooks/use-attribute.d.mts +4 -4
- package/dist/react/hooks/use-attribute.mjs +7 -7
- package/dist/react/hooks/use-attribute.mjs.map +1 -1
- package/dist/react/hooks/use-theme-by-class-name.cjs +1 -1
- package/dist/react/hooks/use-theme-by-class-name.cjs.map +1 -1
- package/dist/react/hooks/use-theme-by-class-name.d.cts +2 -2
- package/dist/react/hooks/use-theme-by-class-name.d.mts +2 -2
- package/dist/react/hooks/use-theme-by-class-name.mjs +1 -1
- package/dist/react/hooks/use-theme-by-class-name.mjs.map +1 -1
- package/dist/react/hooks/use-theme-by-data-attribute.cjs +1 -1
- package/dist/react/hooks/use-theme-by-data-attribute.cjs.map +1 -1
- package/dist/react/hooks/use-theme-by-data-attribute.d.cts +2 -2
- package/dist/react/hooks/use-theme-by-data-attribute.d.mts +2 -2
- package/dist/react/hooks/use-theme-by-data-attribute.mjs +1 -1
- package/dist/react/hooks/use-theme-by-data-attribute.mjs.map +1 -1
- package/dist/react/theme/create-theme-hook.cjs.map +1 -1
- package/dist/react/theme/create-theme-hook.mjs.map +1 -1
- package/dist/theme/_utils/parse-stored-theme.cjs +1 -1
- package/dist/theme/_utils/parse-stored-theme.cjs.map +1 -1
- package/dist/theme/_utils/parse-stored-theme.mjs +1 -1
- package/dist/theme/_utils/parse-stored-theme.mjs.map +1 -1
- package/dist/theme/_utils/set-theme-to-stores.cjs +1 -1
- package/dist/theme/_utils/set-theme-to-stores.cjs.map +1 -1
- package/dist/theme/_utils/set-theme-to-stores.mjs +1 -1
- package/dist/theme/_utils/set-theme-to-stores.mjs.map +1 -1
- package/dist/theme/class-name/parse-class-name.cjs +1 -1
- package/dist/theme/class-name/parse-class-name.cjs.map +1 -1
- package/dist/theme/class-name/parse-class-name.d.cts +2 -2
- package/dist/theme/class-name/parse-class-name.d.cts.map +1 -1
- package/dist/theme/class-name/parse-class-name.d.mts +2 -2
- package/dist/theme/class-name/parse-class-name.d.mts.map +1 -1
- package/dist/theme/class-name/parse-class-name.mjs +1 -1
- package/dist/theme/class-name/parse-class-name.mjs.map +1 -1
- package/dist/theme/class-name/read-class-name.cjs +1 -1
- package/dist/theme/class-name/read-class-name.cjs.map +1 -1
- package/dist/theme/class-name/read-class-name.d.cts +2 -2
- package/dist/theme/class-name/read-class-name.d.cts.map +1 -1
- package/dist/theme/class-name/read-class-name.d.mts +2 -2
- package/dist/theme/class-name/read-class-name.d.mts.map +1 -1
- package/dist/theme/class-name/read-class-name.mjs +1 -1
- package/dist/theme/class-name/read-class-name.mjs.map +1 -1
- package/dist/theme/class-name/stringify-class-name.cjs +4 -4
- package/dist/theme/class-name/stringify-class-name.cjs.map +1 -1
- package/dist/theme/class-name/stringify-class-name.d.cts +3 -3
- package/dist/theme/class-name/stringify-class-name.d.cts.map +1 -1
- package/dist/theme/class-name/stringify-class-name.d.mts +3 -3
- package/dist/theme/class-name/stringify-class-name.d.mts.map +1 -1
- package/dist/theme/class-name/stringify-class-name.mjs +4 -4
- package/dist/theme/class-name/stringify-class-name.mjs.map +1 -1
- package/dist/theme/class-name/subscribe-class-name.cjs +1 -1
- package/dist/theme/class-name/subscribe-class-name.cjs.map +1 -1
- package/dist/theme/class-name/subscribe-class-name.d.cts +2 -2
- package/dist/theme/class-name/subscribe-class-name.d.cts.map +1 -1
- package/dist/theme/class-name/subscribe-class-name.d.mts +2 -2
- package/dist/theme/class-name/subscribe-class-name.d.mts.map +1 -1
- package/dist/theme/class-name/subscribe-class-name.mjs +1 -1
- package/dist/theme/class-name/subscribe-class-name.mjs.map +1 -1
- package/dist/theme/class-name/write-class-name.cjs +2 -2
- package/dist/theme/class-name/write-class-name.cjs.map +1 -1
- package/dist/theme/class-name/write-class-name.d.cts +4 -4
- package/dist/theme/class-name/write-class-name.d.cts.map +1 -1
- package/dist/theme/class-name/write-class-name.d.mts +4 -4
- package/dist/theme/class-name/write-class-name.d.mts.map +1 -1
- package/dist/theme/class-name/write-class-name.mjs +2 -2
- package/dist/theme/class-name/write-class-name.mjs.map +1 -1
- package/dist/theme/compose-theme-stores.cjs.map +1 -1
- package/dist/theme/compose-theme-stores.mjs.map +1 -1
- package/dist/theme/cookie/write-cookie-theme.cjs +2 -2
- package/dist/theme/cookie/write-cookie-theme.cjs.map +1 -1
- package/dist/theme/cookie/write-cookie-theme.d.cts +2 -2
- package/dist/theme/cookie/write-cookie-theme.d.cts.map +1 -1
- package/dist/theme/cookie/write-cookie-theme.d.mts +2 -2
- package/dist/theme/cookie/write-cookie-theme.d.mts.map +1 -1
- package/dist/theme/cookie/write-cookie-theme.mjs +2 -2
- package/dist/theme/cookie/write-cookie-theme.mjs.map +1 -1
- package/dist/theme/data-attribute/parse-data-attribute.cjs +1 -1
- package/dist/theme/data-attribute/parse-data-attribute.cjs.map +1 -1
- package/dist/theme/data-attribute/parse-data-attribute.d.cts +2 -2
- package/dist/theme/data-attribute/parse-data-attribute.d.mts +2 -2
- package/dist/theme/data-attribute/parse-data-attribute.mjs +1 -1
- package/dist/theme/data-attribute/parse-data-attribute.mjs.map +1 -1
- package/dist/theme/data-attribute/read-data-attribute.cjs +1 -1
- package/dist/theme/data-attribute/read-data-attribute.cjs.map +1 -1
- package/dist/theme/data-attribute/read-data-attribute.d.cts +2 -2
- package/dist/theme/data-attribute/read-data-attribute.d.cts.map +1 -1
- package/dist/theme/data-attribute/read-data-attribute.d.mts +2 -2
- package/dist/theme/data-attribute/read-data-attribute.d.mts.map +1 -1
- package/dist/theme/data-attribute/read-data-attribute.mjs +1 -1
- package/dist/theme/data-attribute/read-data-attribute.mjs.map +1 -1
- package/dist/theme/data-attribute/stringify-data-attribute.cjs +4 -4
- package/dist/theme/data-attribute/stringify-data-attribute.cjs.map +1 -1
- package/dist/theme/data-attribute/stringify-data-attribute.d.cts +3 -3
- package/dist/theme/data-attribute/stringify-data-attribute.d.cts.map +1 -1
- package/dist/theme/data-attribute/stringify-data-attribute.d.mts +3 -3
- package/dist/theme/data-attribute/stringify-data-attribute.d.mts.map +1 -1
- package/dist/theme/data-attribute/stringify-data-attribute.mjs +4 -4
- package/dist/theme/data-attribute/stringify-data-attribute.mjs.map +1 -1
- package/dist/theme/data-attribute/subscribe-data-attribute.cjs +1 -1
- package/dist/theme/data-attribute/subscribe-data-attribute.cjs.map +1 -1
- package/dist/theme/data-attribute/subscribe-data-attribute.d.cts +2 -2
- package/dist/theme/data-attribute/subscribe-data-attribute.d.cts.map +1 -1
- package/dist/theme/data-attribute/subscribe-data-attribute.d.mts +2 -2
- package/dist/theme/data-attribute/subscribe-data-attribute.d.mts.map +1 -1
- package/dist/theme/data-attribute/subscribe-data-attribute.mjs +1 -1
- package/dist/theme/data-attribute/subscribe-data-attribute.mjs.map +1 -1
- package/dist/theme/data-attribute/write-data-attribute.cjs +3 -3
- package/dist/theme/data-attribute/write-data-attribute.cjs.map +1 -1
- package/dist/theme/data-attribute/write-data-attribute.d.cts +4 -4
- package/dist/theme/data-attribute/write-data-attribute.d.cts.map +1 -1
- package/dist/theme/data-attribute/write-data-attribute.d.mts +4 -4
- package/dist/theme/data-attribute/write-data-attribute.d.mts.map +1 -1
- package/dist/theme/data-attribute/write-data-attribute.mjs +3 -3
- package/dist/theme/data-attribute/write-data-attribute.mjs.map +1 -1
- package/dist/theme/local-storage/write-local-storage.cjs +1 -1
- package/dist/theme/local-storage/write-local-storage.cjs.map +1 -1
- package/dist/theme/local-storage/write-local-storage.d.cts +2 -2
- package/dist/theme/local-storage/write-local-storage.d.mts +2 -2
- package/dist/theme/local-storage/write-local-storage.mjs +1 -1
- package/dist/theme/local-storage/write-local-storage.mjs.map +1 -1
- package/dist/theme/session-storage/write-session-storage.cjs +1 -1
- package/dist/theme/session-storage/write-session-storage.cjs.map +1 -1
- package/dist/theme/session-storage/write-session-storage.d.cts +2 -2
- package/dist/theme/session-storage/write-session-storage.d.mts +2 -2
- package/dist/theme/session-storage/write-session-storage.mjs +1 -1
- package/dist/theme/session-storage/write-session-storage.mjs.map +1 -1
- package/dist/theme/theme-entry.types.d.cts +4 -2
- package/dist/theme/theme-entry.types.d.cts.map +1 -1
- package/dist/theme/theme-entry.types.d.mts +4 -2
- package/dist/theme/theme-entry.types.d.mts.map +1 -1
- package/dist/theme/theme-store/async-theme-store.types.d.cts +1 -1
- package/dist/theme/theme-store/async-theme-store.types.d.cts.map +1 -1
- package/dist/theme/theme-store/async-theme-store.types.d.mts +1 -1
- package/dist/theme/theme-store/async-theme-store.types.d.mts.map +1 -1
- package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.cjs +1 -1
- package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.cjs.map +1 -1
- package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.d.cts +2 -2
- package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.d.mts +2 -2
- package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.mjs +1 -1
- package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.mjs.map +1 -1
- package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.cjs +1 -1
- package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.cjs.map +1 -1
- package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.d.cts +3 -3
- package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.d.mts +3 -3
- package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.mjs +1 -1
- package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.mjs.map +1 -1
- package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.cjs +1 -1
- package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.cjs.map +1 -1
- package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.d.cts +1 -1
- package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.d.mts +1 -1
- package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.mjs +1 -1
- package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.mjs.map +1 -1
- package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.d.cts +1 -1
- package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.d.mts +1 -1
- package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.d.cts +1 -1
- package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.d.mts +1 -1
- package/dist/theme/theme-store/theme-store.types.d.cts +1 -1
- package/dist/theme/theme-store/theme-store.types.d.cts.map +1 -1
- package/dist/theme/theme-store/theme-store.types.d.mts +1 -1
- package/dist/theme/theme-store/theme-store.types.d.mts.map +1 -1
- package/dist/theme/web-storage/write-web-storage.cjs +3 -3
- package/dist/theme/web-storage/write-web-storage.cjs.map +1 -1
- package/dist/theme/web-storage/write-web-storage.d.cts +2 -2
- package/dist/theme/web-storage/write-web-storage.d.mts +2 -2
- package/dist/theme/web-storage/write-web-storage.mjs +3 -3
- package/dist/theme/web-storage/write-web-storage.mjs.map +1 -1
- package/dist/utils/append-id.cjs +2 -2
- package/dist/utils/append-id.cjs.map +1 -1
- package/dist/utils/append-id.d.cts +3 -3
- package/dist/utils/append-id.d.mts +3 -3
- package/dist/utils/append-id.mjs +2 -2
- package/dist/utils/append-id.mjs.map +1 -1
- package/package.json +1 -1
- package/src/attributes/get-attribute.ts +5 -2
- package/src/attributes/get-data-attribute.ts +5 -2
- package/src/attributes/observe-attribute.ts +2 -2
- package/src/attributes/observe-data-attribute.ts +2 -2
- package/src/color-scheme/color-scheme.types.ts +7 -0
- package/src/color-scheme/get-prefers-color-scheme.ts +6 -4
- package/src/color-scheme/observe-prefers-color-scheme.ts +3 -1
- package/src/index.ts +1 -0
- package/src/react/hooks/use-attribute.ts +11 -11
- package/src/react/hooks/use-theme-by-class-name.ts +2 -2
- package/src/react/hooks/use-theme-by-data-attribute.ts +2 -2
- package/src/react/theme/create-theme-hook.ts +4 -6
- package/src/theme/_utils/parse-stored-theme.ts +2 -2
- package/src/theme/_utils/set-theme-to-stores.ts +3 -3
- package/src/theme/class-name/parse-class-name.ts +2 -2
- package/src/theme/class-name/read-class-name.ts +2 -2
- package/src/theme/class-name/stringify-class-name.ts +6 -6
- package/src/theme/class-name/subscribe-class-name.ts +2 -2
- package/src/theme/class-name/write-class-name.ts +4 -4
- package/src/theme/compose-theme-stores.ts +1 -1
- package/src/theme/cookie/write-cookie-theme.ts +3 -3
- package/src/theme/data-attribute/parse-data-attribute.ts +2 -2
- package/src/theme/data-attribute/read-data-attribute.ts +2 -2
- package/src/theme/data-attribute/stringify-data-attribute.ts +6 -6
- package/src/theme/data-attribute/subscribe-data-attribute.ts +2 -2
- package/src/theme/data-attribute/write-data-attribute.ts +5 -5
- package/src/theme/local-storage/write-local-storage.ts +2 -2
- package/src/theme/session-storage/write-session-storage.ts +2 -2
- package/src/theme/theme-entry.types.ts +5 -3
- package/src/theme/theme-store/async-theme-store.types.ts +1 -3
- package/src/theme/theme-store/class-name-theme-store/class-name-theme-store.ts +2 -2
- package/src/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.ts +2 -2
- package/src/theme/theme-store/in-memory-theme-store/in-memory-theme-store.ts +1 -1
- package/src/theme/theme-store/theme-store.types.ts +1 -3
- package/src/theme/web-storage/write-web-storage.ts +5 -5
- package/src/utils/append-id.ts +3 -3
|
@@ -11,10 +11,10 @@ import { ThemeEntry } from "../theme-entry.types.cjs";
|
|
|
11
11
|
* Arrays in theme map use first value for matching.
|
|
12
12
|
*
|
|
13
13
|
* @param themes - Record mapping theme keys to class name(s)
|
|
14
|
-
* @param className - Raw class attribute value (e.g. from element.className)
|
|
14
|
+
* @param className - Raw class attribute value (e.g. from element.className; accepts null)
|
|
15
15
|
* @returns ThemeEntry if a match is found, otherwise undefined
|
|
16
16
|
*/
|
|
17
|
-
declare function parseClassName<Themes extends ThemeMap>(themes: Themes, className: string | undefined): ThemeEntry<Themes> | undefined;
|
|
17
|
+
declare function parseClassName<Themes extends ThemeMap>(themes: Themes, className: string | null | undefined): ThemeEntry<Themes> | undefined;
|
|
18
18
|
//#endregion
|
|
19
19
|
export { parseClassName };
|
|
20
20
|
//# sourceMappingURL=parse-class-name.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-class-name.d.cts","names":[],"sources":["../../../src/theme/class-name/parse-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAiBA;;;;;;;;;iBAAgB,8BAA8B,kBACrC,
|
|
1
|
+
{"version":3,"file":"parse-class-name.d.cts","names":[],"sources":["../../../src/theme/class-name/parse-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAiBA;;;;;;;;;iBAAgB,8BAA8B,kBACrC,+CAEN,WAAW"}
|
|
@@ -11,10 +11,10 @@ import { ThemeEntry } from "../theme-entry.types.mjs";
|
|
|
11
11
|
* Arrays in theme map use first value for matching.
|
|
12
12
|
*
|
|
13
13
|
* @param themes - Record mapping theme keys to class name(s)
|
|
14
|
-
* @param className - Raw class attribute value (e.g. from element.className)
|
|
14
|
+
* @param className - Raw class attribute value (e.g. from element.className; accepts null)
|
|
15
15
|
* @returns ThemeEntry if a match is found, otherwise undefined
|
|
16
16
|
*/
|
|
17
|
-
declare function parseClassName<Themes extends ThemeMap>(themes: Themes, className: string | undefined): ThemeEntry<Themes> | undefined;
|
|
17
|
+
declare function parseClassName<Themes extends ThemeMap>(themes: Themes, className: string | null | undefined): ThemeEntry<Themes> | undefined;
|
|
18
18
|
//#endregion
|
|
19
19
|
export { parseClassName };
|
|
20
20
|
//# sourceMappingURL=parse-class-name.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-class-name.d.mts","names":[],"sources":["../../../src/theme/class-name/parse-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAiBA;;;;;;;;;iBAAgB,8BAA8B,kBACrC,
|
|
1
|
+
{"version":3,"file":"parse-class-name.d.mts","names":[],"sources":["../../../src/theme/class-name/parse-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAiBA;;;;;;;;;iBAAgB,8BAA8B,kBACrC,+CAEN,WAAW"}
|
|
@@ -11,7 +11,7 @@ import { findKey } from "type-plus";
|
|
|
11
11
|
* Arrays in theme map use first value for matching.
|
|
12
12
|
*
|
|
13
13
|
* @param themes - Record mapping theme keys to class name(s)
|
|
14
|
-
* @param className - Raw class attribute value (e.g. from element.className)
|
|
14
|
+
* @param className - Raw class attribute value (e.g. from element.className; accepts null)
|
|
15
15
|
* @returns ThemeEntry if a match is found, otherwise undefined
|
|
16
16
|
*/
|
|
17
17
|
function parseClassName(themes, className) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-class-name.mjs","names":[],"sources":["../../../src/theme/class-name/parse-class-name.ts"],"sourcesContent":["import { findKey } from 'type-plus'\nimport { resolveThemeMapValue } from '../_utils/resolve-theme-map-value.ts'\nimport { themeEntry } from '../theme-entry.ts'\nimport type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\n\n/**\n * Parses a class name string into a ThemeEntry.\n *\n * Pure function: no DOM access. Matches class strings by checking if any theme\n * class is included in the className (e.g. `className.includes(themeClass)`).\n * Arrays in theme map use first value for matching.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param className - Raw class attribute value (e.g. from element.className)\n * @returns ThemeEntry if a match is found, otherwise undefined\n */\nexport function parseClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\tclassName: string | undefined\n): ThemeEntry<Themes> | undefined {\n\tconst cls = className ?? ''\n\tconst theme = findKey(themes, (key) => {\n\t\tconst value = themes[key]\n\t\tif (value === undefined) return false\n\t\tconst resolved = resolveThemeMapValue(value)\n\t\tconst v = Array.isArray(resolved) ? resolved[0] : resolved\n\t\treturn !!v && cls.includes(v)\n\t})\n\treturn theme !== undefined ? themeEntry(themes, theme) : undefined\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAiBA,SAAgB,eACf,QACA,WACiC;CACjC,MAAM,MAAM,aAAa;CACzB,MAAM,QAAQ,QAAQ,SAAS,QAAQ;EACtC,MAAM,QAAQ,OAAO;AACrB,MAAI,UAAU,OAAW,QAAO;EAChC,MAAM,WAAW,qBAAqB,MAAM;EAC5C,MAAM,IAAI,MAAM,QAAQ,SAAS,GAAG,SAAS,KAAK;AAClD,SAAO,CAAC,CAAC,KAAK,IAAI,SAAS,EAAE;GAC5B;AACF,QAAO,UAAU,SAAY,WAAW,QAAQ,MAAM,GAAG"}
|
|
1
|
+
{"version":3,"file":"parse-class-name.mjs","names":[],"sources":["../../../src/theme/class-name/parse-class-name.ts"],"sourcesContent":["import { findKey } from 'type-plus'\nimport { resolveThemeMapValue } from '../_utils/resolve-theme-map-value.ts'\nimport { themeEntry } from '../theme-entry.ts'\nimport type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\n\n/**\n * Parses a class name string into a ThemeEntry.\n *\n * Pure function: no DOM access. Matches class strings by checking if any theme\n * class is included in the className (e.g. `className.includes(themeClass)`).\n * Arrays in theme map use first value for matching.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param className - Raw class attribute value (e.g. from element.className; accepts null)\n * @returns ThemeEntry if a match is found, otherwise undefined\n */\nexport function parseClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\tclassName: string | null | undefined\n): ThemeEntry<Themes> | undefined {\n\tconst cls = className ?? ''\n\tconst theme = findKey(themes, (key) => {\n\t\tconst value = themes[key]\n\t\tif (value === undefined) return false\n\t\tconst resolved = resolveThemeMapValue(value)\n\t\tconst v = Array.isArray(resolved) ? resolved[0] : resolved\n\t\treturn !!v && cls.includes(v)\n\t})\n\treturn theme !== undefined ? themeEntry(themes, theme) : undefined\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAiBA,SAAgB,eACf,QACA,WACiC;CACjC,MAAM,MAAM,aAAa;CACzB,MAAM,QAAQ,QAAQ,SAAS,QAAQ;EACtC,MAAM,QAAQ,OAAO;AACrB,MAAI,UAAU,OAAW,QAAO;EAChC,MAAM,WAAW,qBAAqB,MAAM;EAC5C,MAAM,IAAI,MAAM,QAAQ,SAAS,GAAG,SAAS,KAAK;AAClD,SAAO,CAAC,CAAC,KAAK,IAAI,SAAS,EAAE;GAC5B;AACF,QAAO,UAAU,SAAY,WAAW,QAAQ,MAAM,GAAG"}
|
|
@@ -5,7 +5,7 @@ const require_parse_class_name = require('./parse-class-name.cjs');
|
|
|
5
5
|
* Reads a theme entry from the class attribute on an element.
|
|
6
6
|
*
|
|
7
7
|
* @param themes - Record mapping theme keys to class name(s)
|
|
8
|
-
* @param options.element - Element to read from (
|
|
8
|
+
* @param options.element - Element to read from (accepts null e.g. from refs). Defaults to document.documentElement.
|
|
9
9
|
* @param options.parse - Custom parser (default: parseClassName)
|
|
10
10
|
* @returns ThemeEntry if found, undefined otherwise. Returns undefined when element is not available (e.g. SSR).
|
|
11
11
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read-class-name.cjs","names":["parseClassName"],"sources":["../../../src/theme/class-name/read-class-name.ts"],"sourcesContent":["import type { ParseStoredTheme, ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport { parseClassName } from './parse-class-name.ts'\n\n/**\n * Reads a theme entry from the class attribute on an element.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param options.element - Element to read from (
|
|
1
|
+
{"version":3,"file":"read-class-name.cjs","names":["parseClassName"],"sources":["../../../src/theme/class-name/read-class-name.ts"],"sourcesContent":["import type { ParseStoredTheme, ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport { parseClassName } from './parse-class-name.ts'\n\n/**\n * Reads a theme entry from the class attribute on an element.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param options.element - Element to read from (accepts null e.g. from refs). Defaults to document.documentElement.\n * @param options.parse - Custom parser (default: parseClassName)\n * @returns ThemeEntry if found, undefined otherwise. Returns undefined when element is not available (e.g. SSR).\n */\nexport function readClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\toptions?:\n\t\t| { element?: Element | null | undefined; parse?: ParseStoredTheme<Themes> | undefined }\n\t\t| undefined\n): ThemeEntry<Themes> | undefined {\n\tconst element = options?.element ?? document?.documentElement\n\tif (!element) return undefined\n\tconst parse = options?.parse ?? parseClassName\n\tconst raw = element.className ?? undefined\n\treturn parse(themes, raw)\n}\n"],"mappings":";;;;;;;;;;;AAYA,SAAgB,cACf,QACA,SAGiC;CACjC,MAAM,UAAU,SAAS,WAAW,UAAU;AAC9C,KAAI,CAAC,QAAS,QAAO;AAGrB,SAFc,SAAS,SAASA,yCAEnB,QADD,QAAQ,aAAa,OACR"}
|
|
@@ -7,12 +7,12 @@ import { ParseStoredTheme, ThemeEntry } from "../theme-entry.types.cjs";
|
|
|
7
7
|
* Reads a theme entry from the class attribute on an element.
|
|
8
8
|
*
|
|
9
9
|
* @param themes - Record mapping theme keys to class name(s)
|
|
10
|
-
* @param options.element - Element to read from (
|
|
10
|
+
* @param options.element - Element to read from (accepts null e.g. from refs). Defaults to document.documentElement.
|
|
11
11
|
* @param options.parse - Custom parser (default: parseClassName)
|
|
12
12
|
* @returns ThemeEntry if found, undefined otherwise. Returns undefined when element is not available (e.g. SSR).
|
|
13
13
|
*/
|
|
14
14
|
declare function readClassName<Themes extends ThemeMap>(themes: Themes, options?: {
|
|
15
|
-
element?: Element | undefined;
|
|
15
|
+
element?: Element | null | undefined;
|
|
16
16
|
parse?: ParseStoredTheme<Themes> | undefined;
|
|
17
17
|
} | undefined): ThemeEntry<Themes> | undefined;
|
|
18
18
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read-class-name.d.cts","names":[],"sources":["../../../src/theme/class-name/read-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAYA;;;;;;AAKc,iBALE,aAKF,CAAA,eAL+B,QAK/B,CAAA,CAAA,MAAA,EAJL,MAIK,EAAA,QAAA,EAAA;EAAX,OAAA,CAAA,EAFa,OAEb,GAAA,SAAA;EAAU,KAAA,CAAA,
|
|
1
|
+
{"version":3,"file":"read-class-name.d.cts","names":[],"sources":["../../../src/theme/class-name/read-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAYA;;;;;;AAKc,iBALE,aAKF,CAAA,eAL+B,QAK/B,CAAA,CAAA,MAAA,EAJL,MAIK,EAAA,QAAA,EAAA;EAAX,OAAA,CAAA,EAFa,OAEb,GAAA,IAAA,GAAA,SAAA;EAAU,KAAA,CAAA,EAFuC,gBAEvC,CAFwD,MAExD,CAAA,GAAA,SAAA;gBAAV,WAAW"}
|
|
@@ -7,12 +7,12 @@ import { ParseStoredTheme, ThemeEntry } from "../theme-entry.types.mjs";
|
|
|
7
7
|
* Reads a theme entry from the class attribute on an element.
|
|
8
8
|
*
|
|
9
9
|
* @param themes - Record mapping theme keys to class name(s)
|
|
10
|
-
* @param options.element - Element to read from (
|
|
10
|
+
* @param options.element - Element to read from (accepts null e.g. from refs). Defaults to document.documentElement.
|
|
11
11
|
* @param options.parse - Custom parser (default: parseClassName)
|
|
12
12
|
* @returns ThemeEntry if found, undefined otherwise. Returns undefined when element is not available (e.g. SSR).
|
|
13
13
|
*/
|
|
14
14
|
declare function readClassName<Themes extends ThemeMap>(themes: Themes, options?: {
|
|
15
|
-
element?: Element | undefined;
|
|
15
|
+
element?: Element | null | undefined;
|
|
16
16
|
parse?: ParseStoredTheme<Themes> | undefined;
|
|
17
17
|
} | undefined): ThemeEntry<Themes> | undefined;
|
|
18
18
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read-class-name.d.mts","names":[],"sources":["../../../src/theme/class-name/read-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAYA;;;;;;AAKc,iBALE,aAKF,CAAA,eAL+B,QAK/B,CAAA,CAAA,MAAA,EAJL,MAIK,EAAA,QAAA,EAAA;EAAX,OAAA,CAAA,EAFa,OAEb,GAAA,SAAA;EAAU,KAAA,CAAA,
|
|
1
|
+
{"version":3,"file":"read-class-name.d.mts","names":[],"sources":["../../../src/theme/class-name/read-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAYA;;;;;;AAKc,iBALE,aAKF,CAAA,eAL+B,QAK/B,CAAA,CAAA,MAAA,EAJL,MAIK,EAAA,QAAA,EAAA;EAAX,OAAA,CAAA,EAFa,OAEb,GAAA,IAAA,GAAA,SAAA;EAAU,KAAA,CAAA,EAFuC,gBAEvC,CAFwD,MAExD,CAAA,GAAA,SAAA;gBAAV,WAAW"}
|
|
@@ -5,7 +5,7 @@ import { parseClassName } from "./parse-class-name.mjs";
|
|
|
5
5
|
* Reads a theme entry from the class attribute on an element.
|
|
6
6
|
*
|
|
7
7
|
* @param themes - Record mapping theme keys to class name(s)
|
|
8
|
-
* @param options.element - Element to read from (
|
|
8
|
+
* @param options.element - Element to read from (accepts null e.g. from refs). Defaults to document.documentElement.
|
|
9
9
|
* @param options.parse - Custom parser (default: parseClassName)
|
|
10
10
|
* @returns ThemeEntry if found, undefined otherwise. Returns undefined when element is not available (e.g. SSR).
|
|
11
11
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read-class-name.mjs","names":[],"sources":["../../../src/theme/class-name/read-class-name.ts"],"sourcesContent":["import type { ParseStoredTheme, ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport { parseClassName } from './parse-class-name.ts'\n\n/**\n * Reads a theme entry from the class attribute on an element.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param options.element - Element to read from (
|
|
1
|
+
{"version":3,"file":"read-class-name.mjs","names":[],"sources":["../../../src/theme/class-name/read-class-name.ts"],"sourcesContent":["import type { ParseStoredTheme, ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport { parseClassName } from './parse-class-name.ts'\n\n/**\n * Reads a theme entry from the class attribute on an element.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param options.element - Element to read from (accepts null e.g. from refs). Defaults to document.documentElement.\n * @param options.parse - Custom parser (default: parseClassName)\n * @returns ThemeEntry if found, undefined otherwise. Returns undefined when element is not available (e.g. SSR).\n */\nexport function readClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\toptions?:\n\t\t| { element?: Element | null | undefined; parse?: ParseStoredTheme<Themes> | undefined }\n\t\t| undefined\n): ThemeEntry<Themes> | undefined {\n\tconst element = options?.element ?? document?.documentElement\n\tif (!element) return undefined\n\tconst parse = options?.parse ?? parseClassName\n\tconst raw = element.className ?? undefined\n\treturn parse(themes, raw)\n}\n"],"mappings":";;;;;;;;;;;AAYA,SAAgB,cACf,QACA,SAGiC;CACjC,MAAM,UAAU,SAAS,WAAW,UAAU;AAC9C,KAAI,CAAC,QAAS,QAAO;AAGrB,SAFc,SAAS,SAAS,gBAEnB,QADD,QAAQ,aAAa,OACR"}
|
|
@@ -9,8 +9,8 @@ const require_resolve_theme_map_value = require('../_utils/resolve-theme-map-val
|
|
|
9
9
|
* (unlike stringifyDataAttribute which uses first only).
|
|
10
10
|
*
|
|
11
11
|
* @param themes - Record mapping theme keys to class names (used to identify theme tokens)
|
|
12
|
-
* @param existing - Current class attribute value string
|
|
13
|
-
* @param entry - Theme entry to stringify, or undefined to clear theme (keeps non-theme classes)
|
|
12
|
+
* @param existing - Current class attribute value string (accepts null)
|
|
13
|
+
* @param entry - Theme entry to stringify, or null/undefined to clear theme (keeps non-theme classes)
|
|
14
14
|
* @returns Class attribute value string
|
|
15
15
|
*/
|
|
16
16
|
function stringifyClassName(themes, existing, entry) {
|
|
@@ -18,8 +18,8 @@ function stringifyClassName(themes, existing, entry) {
|
|
|
18
18
|
const resolved = require_resolve_theme_map_value.resolveThemeMapValue(v);
|
|
19
19
|
return Array.isArray(resolved) ? [...resolved] : [resolved];
|
|
20
20
|
});
|
|
21
|
-
const withoutThemes = (existing?.trim() ? existing.trim().split(/\s+/) : []).filter((c) => !allThemeClasses.includes(c));
|
|
22
|
-
const activeClasses = entry
|
|
21
|
+
const withoutThemes = ((existing ?? "")?.trim() ? (existing ?? "").trim().split(/\s+/) : []).filter((c) => !allThemeClasses.includes(c));
|
|
22
|
+
const activeClasses = entry != null ? (() => {
|
|
23
23
|
const resolved = require_resolve_theme_map_value.resolveThemeMapValue(entry.value);
|
|
24
24
|
return Array.isArray(resolved) ? [...resolved] : [resolved];
|
|
25
25
|
})() : [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stringify-class-name.cjs","names":["resolveThemeMapValue"],"sources":["../../../src/theme/class-name/stringify-class-name.ts"],"sourcesContent":["import { resolveThemeMapValue } from '../_utils/resolve-theme-map-value.ts'\nimport type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\n\n/**\n * Stringifies a ThemeEntry for a class attribute value.\n *\n * Pure function: no DOM access. Removes all theme classes from existing, then\n * adds entry's class(es). Applies all classes from entry when value is an array\n * (unlike stringifyDataAttribute which uses first only).\n *\n * @param themes - Record mapping theme keys to class names (used to identify theme tokens)\n * @param existing - Current class attribute value string\n * @param entry - Theme entry to stringify, or undefined to clear theme (keeps non-theme classes)\n * @returns Class attribute value string\n */\nexport function stringifyClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\texisting: string | undefined,\n\tentry: ThemeEntry<Themes> | undefined\n): string {\n\tconst allThemeClasses = Object.values(themes).flatMap((v) => {\n\t\tconst resolved = resolveThemeMapValue(v)\n\t\treturn Array.isArray(resolved) ? [...resolved] : [resolved]\n\t})\n\tconst existingClasses = existing?.trim() ? existing.trim().split(/\\s+/) : []\n\tconst withoutThemes = existingClasses.filter((c) => !allThemeClasses.includes(c))\n\tconst activeClasses =\n\t\tentry
|
|
1
|
+
{"version":3,"file":"stringify-class-name.cjs","names":["resolveThemeMapValue"],"sources":["../../../src/theme/class-name/stringify-class-name.ts"],"sourcesContent":["import { resolveThemeMapValue } from '../_utils/resolve-theme-map-value.ts'\nimport type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\n\n/**\n * Stringifies a ThemeEntry for a class attribute value.\n *\n * Pure function: no DOM access. Removes all theme classes from existing, then\n * adds entry's class(es). Applies all classes from entry when value is an array\n * (unlike stringifyDataAttribute which uses first only).\n *\n * @param themes - Record mapping theme keys to class names (used to identify theme tokens)\n * @param existing - Current class attribute value string (accepts null)\n * @param entry - Theme entry to stringify, or null/undefined to clear theme (keeps non-theme classes)\n * @returns Class attribute value string\n */\nexport function stringifyClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\texisting: string | null | undefined,\n\tentry: ThemeEntry<Themes> | null | undefined\n): string {\n\tconst allThemeClasses = Object.values(themes).flatMap((v) => {\n\t\tconst resolved = resolveThemeMapValue(v)\n\t\treturn Array.isArray(resolved) ? [...resolved] : [resolved]\n\t})\n\tconst existingClasses = (existing ?? '')?.trim() ? (existing ?? '').trim().split(/\\s+/) : []\n\tconst withoutThemes = existingClasses.filter((c) => !allThemeClasses.includes(c))\n\tconst activeClasses =\n\t\tentry != null\n\t\t\t? (() => {\n\t\t\t\t\tconst resolved = resolveThemeMapValue(entry.value)\n\t\t\t\t\treturn Array.isArray(resolved) ? [...resolved] : [resolved]\n\t\t\t\t})()\n\t\t\t: []\n\treturn [...withoutThemes, ...activeClasses].filter(Boolean).join(' ')\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,SAAgB,mBACf,QACA,UACA,OACS;CACT,MAAM,kBAAkB,OAAO,OAAO,OAAO,CAAC,SAAS,MAAM;EAC5D,MAAM,WAAWA,qDAAqB,EAAE;AACxC,SAAO,MAAM,QAAQ,SAAS,GAAG,CAAC,GAAG,SAAS,GAAG,CAAC,SAAS;GAC1D;CAEF,MAAM,kBADmB,YAAY,KAAK,MAAM,IAAI,YAAY,IAAI,MAAM,CAAC,MAAM,MAAM,GAAG,EAAE,EACtD,QAAQ,MAAM,CAAC,gBAAgB,SAAS,EAAE,CAAC;CACjF,MAAM,gBACL,SAAS,cACC;EACP,MAAM,WAAWA,qDAAqB,MAAM,MAAM;AAClD,SAAO,MAAM,QAAQ,SAAS,GAAG,CAAC,GAAG,SAAS,GAAG,CAAC,SAAS;KACxD,GACH,EAAE;AACN,QAAO,CAAC,GAAG,eAAe,GAAG,cAAc,CAAC,OAAO,QAAQ,CAAC,KAAK,IAAI"}
|
|
@@ -11,11 +11,11 @@ import { ThemeEntry } from "../theme-entry.types.cjs";
|
|
|
11
11
|
* (unlike stringifyDataAttribute which uses first only).
|
|
12
12
|
*
|
|
13
13
|
* @param themes - Record mapping theme keys to class names (used to identify theme tokens)
|
|
14
|
-
* @param existing - Current class attribute value string
|
|
15
|
-
* @param entry - Theme entry to stringify, or undefined to clear theme (keeps non-theme classes)
|
|
14
|
+
* @param existing - Current class attribute value string (accepts null)
|
|
15
|
+
* @param entry - Theme entry to stringify, or null/undefined to clear theme (keeps non-theme classes)
|
|
16
16
|
* @returns Class attribute value string
|
|
17
17
|
*/
|
|
18
|
-
declare function stringifyClassName<Themes extends ThemeMap>(themes: Themes, existing: string | undefined, entry: ThemeEntry<Themes> | undefined): string;
|
|
18
|
+
declare function stringifyClassName<Themes extends ThemeMap>(themes: Themes, existing: string | null | undefined, entry: ThemeEntry<Themes> | null | undefined): string;
|
|
19
19
|
//#endregion
|
|
20
20
|
export { stringifyClassName };
|
|
21
21
|
//# sourceMappingURL=stringify-class-name.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stringify-class-name.d.cts","names":[],"sources":["../../../src/theme/class-name/stringify-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAgBA;;;;;;;;;;iBAAgB,kCAAkC,kBACzC,
|
|
1
|
+
{"version":3,"file":"stringify-class-name.d.cts","names":[],"sources":["../../../src/theme/class-name/stringify-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAgBA;;;;;;;;;;iBAAgB,kCAAkC,kBACzC,oDAED,WAAW"}
|
|
@@ -11,11 +11,11 @@ import { ThemeEntry } from "../theme-entry.types.mjs";
|
|
|
11
11
|
* (unlike stringifyDataAttribute which uses first only).
|
|
12
12
|
*
|
|
13
13
|
* @param themes - Record mapping theme keys to class names (used to identify theme tokens)
|
|
14
|
-
* @param existing - Current class attribute value string
|
|
15
|
-
* @param entry - Theme entry to stringify, or undefined to clear theme (keeps non-theme classes)
|
|
14
|
+
* @param existing - Current class attribute value string (accepts null)
|
|
15
|
+
* @param entry - Theme entry to stringify, or null/undefined to clear theme (keeps non-theme classes)
|
|
16
16
|
* @returns Class attribute value string
|
|
17
17
|
*/
|
|
18
|
-
declare function stringifyClassName<Themes extends ThemeMap>(themes: Themes, existing: string | undefined, entry: ThemeEntry<Themes> | undefined): string;
|
|
18
|
+
declare function stringifyClassName<Themes extends ThemeMap>(themes: Themes, existing: string | null | undefined, entry: ThemeEntry<Themes> | null | undefined): string;
|
|
19
19
|
//#endregion
|
|
20
20
|
export { stringifyClassName };
|
|
21
21
|
//# sourceMappingURL=stringify-class-name.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stringify-class-name.d.mts","names":[],"sources":["../../../src/theme/class-name/stringify-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAgBA;;;;;;;;;;iBAAgB,kCAAkC,kBACzC,
|
|
1
|
+
{"version":3,"file":"stringify-class-name.d.mts","names":[],"sources":["../../../src/theme/class-name/stringify-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAgBA;;;;;;;;;;iBAAgB,kCAAkC,kBACzC,oDAED,WAAW"}
|
|
@@ -9,8 +9,8 @@ import { resolveThemeMapValue } from "../_utils/resolve-theme-map-value.mjs";
|
|
|
9
9
|
* (unlike stringifyDataAttribute which uses first only).
|
|
10
10
|
*
|
|
11
11
|
* @param themes - Record mapping theme keys to class names (used to identify theme tokens)
|
|
12
|
-
* @param existing - Current class attribute value string
|
|
13
|
-
* @param entry - Theme entry to stringify, or undefined to clear theme (keeps non-theme classes)
|
|
12
|
+
* @param existing - Current class attribute value string (accepts null)
|
|
13
|
+
* @param entry - Theme entry to stringify, or null/undefined to clear theme (keeps non-theme classes)
|
|
14
14
|
* @returns Class attribute value string
|
|
15
15
|
*/
|
|
16
16
|
function stringifyClassName(themes, existing, entry) {
|
|
@@ -18,8 +18,8 @@ function stringifyClassName(themes, existing, entry) {
|
|
|
18
18
|
const resolved = resolveThemeMapValue(v);
|
|
19
19
|
return Array.isArray(resolved) ? [...resolved] : [resolved];
|
|
20
20
|
});
|
|
21
|
-
const withoutThemes = (existing?.trim() ? existing.trim().split(/\s+/) : []).filter((c) => !allThemeClasses.includes(c));
|
|
22
|
-
const activeClasses = entry
|
|
21
|
+
const withoutThemes = ((existing ?? "")?.trim() ? (existing ?? "").trim().split(/\s+/) : []).filter((c) => !allThemeClasses.includes(c));
|
|
22
|
+
const activeClasses = entry != null ? (() => {
|
|
23
23
|
const resolved = resolveThemeMapValue(entry.value);
|
|
24
24
|
return Array.isArray(resolved) ? [...resolved] : [resolved];
|
|
25
25
|
})() : [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stringify-class-name.mjs","names":[],"sources":["../../../src/theme/class-name/stringify-class-name.ts"],"sourcesContent":["import { resolveThemeMapValue } from '../_utils/resolve-theme-map-value.ts'\nimport type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\n\n/**\n * Stringifies a ThemeEntry for a class attribute value.\n *\n * Pure function: no DOM access. Removes all theme classes from existing, then\n * adds entry's class(es). Applies all classes from entry when value is an array\n * (unlike stringifyDataAttribute which uses first only).\n *\n * @param themes - Record mapping theme keys to class names (used to identify theme tokens)\n * @param existing - Current class attribute value string\n * @param entry - Theme entry to stringify, or undefined to clear theme (keeps non-theme classes)\n * @returns Class attribute value string\n */\nexport function stringifyClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\texisting: string | undefined,\n\tentry: ThemeEntry<Themes> | undefined\n): string {\n\tconst allThemeClasses = Object.values(themes).flatMap((v) => {\n\t\tconst resolved = resolveThemeMapValue(v)\n\t\treturn Array.isArray(resolved) ? [...resolved] : [resolved]\n\t})\n\tconst existingClasses = existing?.trim() ? existing.trim().split(/\\s+/) : []\n\tconst withoutThemes = existingClasses.filter((c) => !allThemeClasses.includes(c))\n\tconst activeClasses =\n\t\tentry
|
|
1
|
+
{"version":3,"file":"stringify-class-name.mjs","names":[],"sources":["../../../src/theme/class-name/stringify-class-name.ts"],"sourcesContent":["import { resolveThemeMapValue } from '../_utils/resolve-theme-map-value.ts'\nimport type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\n\n/**\n * Stringifies a ThemeEntry for a class attribute value.\n *\n * Pure function: no DOM access. Removes all theme classes from existing, then\n * adds entry's class(es). Applies all classes from entry when value is an array\n * (unlike stringifyDataAttribute which uses first only).\n *\n * @param themes - Record mapping theme keys to class names (used to identify theme tokens)\n * @param existing - Current class attribute value string (accepts null)\n * @param entry - Theme entry to stringify, or null/undefined to clear theme (keeps non-theme classes)\n * @returns Class attribute value string\n */\nexport function stringifyClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\texisting: string | null | undefined,\n\tentry: ThemeEntry<Themes> | null | undefined\n): string {\n\tconst allThemeClasses = Object.values(themes).flatMap((v) => {\n\t\tconst resolved = resolveThemeMapValue(v)\n\t\treturn Array.isArray(resolved) ? [...resolved] : [resolved]\n\t})\n\tconst existingClasses = (existing ?? '')?.trim() ? (existing ?? '').trim().split(/\\s+/) : []\n\tconst withoutThemes = existingClasses.filter((c) => !allThemeClasses.includes(c))\n\tconst activeClasses =\n\t\tentry != null\n\t\t\t? (() => {\n\t\t\t\t\tconst resolved = resolveThemeMapValue(entry.value)\n\t\t\t\t\treturn Array.isArray(resolved) ? [...resolved] : [resolved]\n\t\t\t\t})()\n\t\t\t: []\n\treturn [...withoutThemes, ...activeClasses].filter(Boolean).join(' ')\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,SAAgB,mBACf,QACA,UACA,OACS;CACT,MAAM,kBAAkB,OAAO,OAAO,OAAO,CAAC,SAAS,MAAM;EAC5D,MAAM,WAAW,qBAAqB,EAAE;AACxC,SAAO,MAAM,QAAQ,SAAS,GAAG,CAAC,GAAG,SAAS,GAAG,CAAC,SAAS;GAC1D;CAEF,MAAM,kBADmB,YAAY,KAAK,MAAM,IAAI,YAAY,IAAI,MAAM,CAAC,MAAM,MAAM,GAAG,EAAE,EACtD,QAAQ,MAAM,CAAC,gBAAgB,SAAS,EAAE,CAAC;CACjF,MAAM,gBACL,SAAS,cACC;EACP,MAAM,WAAW,qBAAqB,MAAM,MAAM;AAClD,SAAO,MAAM,QAAQ,SAAS,GAAG,CAAC,GAAG,SAAS,GAAG,CAAC,SAAS;KACxD,GACH,EAAE;AACN,QAAO,CAAC,GAAG,eAAe,GAAG,cAAc,CAAC,OAAO,QAAQ,CAAC,KAAK,IAAI"}
|
|
@@ -7,7 +7,7 @@ const require_parse_class_name = require('./parse-class-name.cjs');
|
|
|
7
7
|
*
|
|
8
8
|
* @param themes - Record mapping theme keys to class name(s)
|
|
9
9
|
* @param handler - Callback invoked when the class attribute changes
|
|
10
|
-
* @param options.element - Element to observe (
|
|
10
|
+
* @param options.element - Element to observe (accepts null e.g. from refs). Defaults to document.documentElement.
|
|
11
11
|
* @param options.parse - Custom parser (default: parseClassName)
|
|
12
12
|
* @returns Unsubscribe function. Returns a no-op function when element is not available (e.g. SSR).
|
|
13
13
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscribe-class-name.cjs","names":["parseClassName","lastEmitted: keyof Themes | undefined | null","observeAttributes"],"sources":["../../../src/theme/class-name/subscribe-class-name.ts"],"sourcesContent":["import { observeAttributes } from '../../attributes/observe-attribute.ts'\nimport type { ParseStoredTheme, ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport { parseClassName } from './parse-class-name.ts'\n\n/**\n * Subscribes to changes on the class attribute and invokes the handler with parsed theme entries.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param handler - Callback invoked when the class attribute changes\n * @param options.element - Element to observe (
|
|
1
|
+
{"version":3,"file":"subscribe-class-name.cjs","names":["parseClassName","lastEmitted: keyof Themes | undefined | null","observeAttributes"],"sources":["../../../src/theme/class-name/subscribe-class-name.ts"],"sourcesContent":["import { observeAttributes } from '../../attributes/observe-attribute.ts'\nimport type { ParseStoredTheme, ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport { parseClassName } from './parse-class-name.ts'\n\n/**\n * Subscribes to changes on the class attribute and invokes the handler with parsed theme entries.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param handler - Callback invoked when the class attribute changes\n * @param options.element - Element to observe (accepts null e.g. from refs). Defaults to document.documentElement.\n * @param options.parse - Custom parser (default: parseClassName)\n * @returns Unsubscribe function. Returns a no-op function when element is not available (e.g. SSR).\n */\nexport function subscribeClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\thandler: (entry: ThemeEntry<Themes> | undefined) => void,\n\toptions?:\n\t\t| { element?: Element | null | undefined; parse?: ParseStoredTheme<Themes> | undefined }\n\t\t| undefined\n): () => void {\n\tconst element = options?.element ?? document?.documentElement\n\tif (!element) return () => {}\n\tconst parse = options?.parse ?? parseClassName\n\tlet lastEmitted: keyof Themes | undefined | null = null\n\tconst observer = observeAttributes(\n\t\t{\n\t\t\tclass: (value) => {\n\t\t\t\tconst entry = parse(themes, value ?? undefined)\n\t\t\t\tconst key = entry?.theme ?? undefined\n\t\t\t\tif (lastEmitted === key) return\n\t\t\t\tlastEmitted = key\n\t\t\t\thandler(entry)\n\t\t\t}\n\t\t},\n\t\telement\n\t)\n\treturn () => observer.disconnect()\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,SAAgB,mBACf,QACA,SACA,SAGa;CACb,MAAM,UAAU,SAAS,WAAW,UAAU;AAC9C,KAAI,CAAC,QAAS,cAAa;CAC3B,MAAM,QAAQ,SAAS,SAASA;CAChC,IAAIC,cAA+C;CACnD,MAAM,WAAWC,4CAChB,EACC,QAAQ,UAAU;EACjB,MAAM,QAAQ,MAAM,QAAQ,SAAS,OAAU;EAC/C,MAAM,MAAM,OAAO,SAAS;AAC5B,MAAI,gBAAgB,IAAK;AACzB,gBAAc;AACd,UAAQ,MAAM;IAEf,EACD,QACA;AACD,cAAa,SAAS,YAAY"}
|
|
@@ -8,12 +8,12 @@ import { ParseStoredTheme, ThemeEntry } from "../theme-entry.types.cjs";
|
|
|
8
8
|
*
|
|
9
9
|
* @param themes - Record mapping theme keys to class name(s)
|
|
10
10
|
* @param handler - Callback invoked when the class attribute changes
|
|
11
|
-
* @param options.element - Element to observe (
|
|
11
|
+
* @param options.element - Element to observe (accepts null e.g. from refs). Defaults to document.documentElement.
|
|
12
12
|
* @param options.parse - Custom parser (default: parseClassName)
|
|
13
13
|
* @returns Unsubscribe function. Returns a no-op function when element is not available (e.g. SSR).
|
|
14
14
|
*/
|
|
15
15
|
declare function subscribeClassName<Themes extends ThemeMap>(themes: Themes, handler: (entry: ThemeEntry<Themes> | undefined) => void, options?: {
|
|
16
|
-
element?: Element | undefined;
|
|
16
|
+
element?: Element | null | undefined;
|
|
17
17
|
parse?: ParseStoredTheme<Themes> | undefined;
|
|
18
18
|
} | undefined): () => void;
|
|
19
19
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscribe-class-name.d.cts","names":[],"sources":["../../../src/theme/class-name/subscribe-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAcA;;;;;;;
|
|
1
|
+
{"version":3,"file":"subscribe-class-name.d.cts","names":[],"sources":["../../../src/theme/class-name/subscribe-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAcA;;;;;;;AAIoD,iBAJpC,kBAIoC,CAAA,eAJF,QAIE,CAAA,CAAA,MAAA,EAH3C,MAG2C,EAAA,OAAA,EAAA,CAAA,KAAA,EAFlC,UAEkC,CAFvB,MAEuB,CAAA,GAAA,SAAA,EAAA,GAAA,IAAA,EAAA,QAAA,EAAA;EAAgB,OAAA,CAAA,EAApD,OAAoD,GAAA,IAAA,GAAA,SAAA;UAAhB,iBAAiB"}
|
|
@@ -8,12 +8,12 @@ import { ParseStoredTheme, ThemeEntry } from "../theme-entry.types.mjs";
|
|
|
8
8
|
*
|
|
9
9
|
* @param themes - Record mapping theme keys to class name(s)
|
|
10
10
|
* @param handler - Callback invoked when the class attribute changes
|
|
11
|
-
* @param options.element - Element to observe (
|
|
11
|
+
* @param options.element - Element to observe (accepts null e.g. from refs). Defaults to document.documentElement.
|
|
12
12
|
* @param options.parse - Custom parser (default: parseClassName)
|
|
13
13
|
* @returns Unsubscribe function. Returns a no-op function when element is not available (e.g. SSR).
|
|
14
14
|
*/
|
|
15
15
|
declare function subscribeClassName<Themes extends ThemeMap>(themes: Themes, handler: (entry: ThemeEntry<Themes> | undefined) => void, options?: {
|
|
16
|
-
element?: Element | undefined;
|
|
16
|
+
element?: Element | null | undefined;
|
|
17
17
|
parse?: ParseStoredTheme<Themes> | undefined;
|
|
18
18
|
} | undefined): () => void;
|
|
19
19
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscribe-class-name.d.mts","names":[],"sources":["../../../src/theme/class-name/subscribe-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAcA;;;;;;;
|
|
1
|
+
{"version":3,"file":"subscribe-class-name.d.mts","names":[],"sources":["../../../src/theme/class-name/subscribe-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAcA;;;;;;;AAIoD,iBAJpC,kBAIoC,CAAA,eAJF,QAIE,CAAA,CAAA,MAAA,EAH3C,MAG2C,EAAA,OAAA,EAAA,CAAA,KAAA,EAFlC,UAEkC,CAFvB,MAEuB,CAAA,GAAA,SAAA,EAAA,GAAA,IAAA,EAAA,QAAA,EAAA;EAAgB,OAAA,CAAA,EAApD,OAAoD,GAAA,IAAA,GAAA,SAAA;UAAhB,iBAAiB"}
|
|
@@ -7,7 +7,7 @@ import { parseClassName } from "./parse-class-name.mjs";
|
|
|
7
7
|
*
|
|
8
8
|
* @param themes - Record mapping theme keys to class name(s)
|
|
9
9
|
* @param handler - Callback invoked when the class attribute changes
|
|
10
|
-
* @param options.element - Element to observe (
|
|
10
|
+
* @param options.element - Element to observe (accepts null e.g. from refs). Defaults to document.documentElement.
|
|
11
11
|
* @param options.parse - Custom parser (default: parseClassName)
|
|
12
12
|
* @returns Unsubscribe function. Returns a no-op function when element is not available (e.g. SSR).
|
|
13
13
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscribe-class-name.mjs","names":["lastEmitted: keyof Themes | undefined | null"],"sources":["../../../src/theme/class-name/subscribe-class-name.ts"],"sourcesContent":["import { observeAttributes } from '../../attributes/observe-attribute.ts'\nimport type { ParseStoredTheme, ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport { parseClassName } from './parse-class-name.ts'\n\n/**\n * Subscribes to changes on the class attribute and invokes the handler with parsed theme entries.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param handler - Callback invoked when the class attribute changes\n * @param options.element - Element to observe (
|
|
1
|
+
{"version":3,"file":"subscribe-class-name.mjs","names":["lastEmitted: keyof Themes | undefined | null"],"sources":["../../../src/theme/class-name/subscribe-class-name.ts"],"sourcesContent":["import { observeAttributes } from '../../attributes/observe-attribute.ts'\nimport type { ParseStoredTheme, ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport { parseClassName } from './parse-class-name.ts'\n\n/**\n * Subscribes to changes on the class attribute and invokes the handler with parsed theme entries.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param handler - Callback invoked when the class attribute changes\n * @param options.element - Element to observe (accepts null e.g. from refs). Defaults to document.documentElement.\n * @param options.parse - Custom parser (default: parseClassName)\n * @returns Unsubscribe function. Returns a no-op function when element is not available (e.g. SSR).\n */\nexport function subscribeClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\thandler: (entry: ThemeEntry<Themes> | undefined) => void,\n\toptions?:\n\t\t| { element?: Element | null | undefined; parse?: ParseStoredTheme<Themes> | undefined }\n\t\t| undefined\n): () => void {\n\tconst element = options?.element ?? document?.documentElement\n\tif (!element) return () => {}\n\tconst parse = options?.parse ?? parseClassName\n\tlet lastEmitted: keyof Themes | undefined | null = null\n\tconst observer = observeAttributes(\n\t\t{\n\t\t\tclass: (value) => {\n\t\t\t\tconst entry = parse(themes, value ?? undefined)\n\t\t\t\tconst key = entry?.theme ?? undefined\n\t\t\t\tif (lastEmitted === key) return\n\t\t\t\tlastEmitted = key\n\t\t\t\thandler(entry)\n\t\t\t}\n\t\t},\n\t\telement\n\t)\n\treturn () => observer.disconnect()\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,SAAgB,mBACf,QACA,SACA,SAGa;CACb,MAAM,UAAU,SAAS,WAAW,UAAU;AAC9C,KAAI,CAAC,QAAS,cAAa;CAC3B,MAAM,QAAQ,SAAS,SAAS;CAChC,IAAIA,cAA+C;CACnD,MAAM,WAAW,kBAChB,EACC,QAAQ,UAAU;EACjB,MAAM,QAAQ,MAAM,QAAQ,SAAS,OAAU;EAC/C,MAAM,MAAM,OAAO,SAAS;AAC5B,MAAI,gBAAgB,IAAK;AACzB,gBAAc;AACd,UAAQ,MAAM;IAEf,EACD,QACA;AACD,cAAa,SAAS,YAAY"}
|
|
@@ -5,8 +5,8 @@ const require_stringify_class_name = require('./stringify-class-name.cjs');
|
|
|
5
5
|
* Writes a theme entry to the class attribute on an element.
|
|
6
6
|
*
|
|
7
7
|
* @param themes - Record mapping theme keys to class name(s)
|
|
8
|
-
* @param entry - Theme entry to write, or undefined to remove the theme
|
|
9
|
-
* @param options.element - Element to write to (
|
|
8
|
+
* @param entry - Theme entry to write, or null/undefined to remove the theme
|
|
9
|
+
* @param options.element - Element to write to (accepts null e.g. from refs). Defaults to document.documentElement.
|
|
10
10
|
* @param options.stringify - Custom serializer (default: stringifyClassName)
|
|
11
11
|
*/
|
|
12
12
|
function writeClassName(themes, entry, options) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write-class-name.cjs","names":["stringifyClassName"],"sources":["../../../src/theme/class-name/write-class-name.ts"],"sourcesContent":["import type { StringifyStoredTheme, ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport { stringifyClassName } from './stringify-class-name.ts'\n\n/**\n * Writes a theme entry to the class attribute on an element.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param entry - Theme entry to write, or undefined to remove the theme\n * @param options.element - Element to write to (
|
|
1
|
+
{"version":3,"file":"write-class-name.cjs","names":["stringifyClassName"],"sources":["../../../src/theme/class-name/write-class-name.ts"],"sourcesContent":["import type { StringifyStoredTheme, ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport { stringifyClassName } from './stringify-class-name.ts'\n\n/**\n * Writes a theme entry to the class attribute on an element.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param entry - Theme entry to write, or null/undefined to remove the theme\n * @param options.element - Element to write to (accepts null e.g. from refs). Defaults to document.documentElement.\n * @param options.stringify - Custom serializer (default: stringifyClassName)\n */\nexport function writeClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\tentry: ThemeEntry<Themes> | null | undefined,\n\toptions?:\n\t\t| { element?: Element | null | undefined; stringify?: StringifyStoredTheme<Themes> | undefined }\n\t\t| undefined\n): void {\n\tconst element = options?.element ?? document?.documentElement\n\tif (!element) return\n\tconst stringify = options?.stringify ?? stringifyClassName\n\telement.className = stringify(themes, element.className ?? undefined, entry)\n}\n"],"mappings":";;;;;;;;;;;AAYA,SAAgB,eACf,QACA,OACA,SAGO;CACP,MAAM,UAAU,SAAS,WAAW,UAAU;AAC9C,KAAI,CAAC,QAAS;AAEd,SAAQ,aADU,SAAS,aAAaA,iDACV,QAAQ,QAAQ,aAAa,QAAW,MAAM"}
|
|
@@ -7,12 +7,12 @@ import { StringifyStoredTheme, ThemeEntry } from "../theme-entry.types.cjs";
|
|
|
7
7
|
* Writes a theme entry to the class attribute on an element.
|
|
8
8
|
*
|
|
9
9
|
* @param themes - Record mapping theme keys to class name(s)
|
|
10
|
-
* @param entry - Theme entry to write, or undefined to remove the theme
|
|
11
|
-
* @param options.element - Element to write to (
|
|
10
|
+
* @param entry - Theme entry to write, or null/undefined to remove the theme
|
|
11
|
+
* @param options.element - Element to write to (accepts null e.g. from refs). Defaults to document.documentElement.
|
|
12
12
|
* @param options.stringify - Custom serializer (default: stringifyClassName)
|
|
13
13
|
*/
|
|
14
|
-
declare function writeClassName<Themes extends ThemeMap>(themes: Themes, entry: ThemeEntry<Themes> | undefined, options?: {
|
|
15
|
-
element?: Element | undefined;
|
|
14
|
+
declare function writeClassName<Themes extends ThemeMap>(themes: Themes, entry: ThemeEntry<Themes> | null | undefined, options?: {
|
|
15
|
+
element?: Element | null | undefined;
|
|
16
16
|
stringify?: StringifyStoredTheme<Themes> | undefined;
|
|
17
17
|
} | undefined): void;
|
|
18
18
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write-class-name.d.cts","names":[],"sources":["../../../src/theme/class-name/write-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAYA;;;;;;
|
|
1
|
+
{"version":3,"file":"write-class-name.d.cts","names":[],"sources":["../../../src/theme/class-name/write-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAYA;;;;;;AAI6E,iBAJ7D,cAI6D,CAAA,eAJ/B,QAI+B,CAAA,CAAA,MAAA,EAHpE,MAGoE,EAAA,KAAA,EAFrE,UAEqE,CAF1D,MAE0D,CAAA,GAAA,IAAA,GAAA,SAAA,EAAA,QAAA,EAAA;EAArB,OAAA,CAAA,EAAxC,OAAwC,GAAA,IAAA,GAAA,SAAA;EAAoB,SAAA,CAAA,EAApB,oBAAoB,CAAC,MAAD,CAAA,GAAA,SAAA"}
|
|
@@ -7,12 +7,12 @@ import { StringifyStoredTheme, ThemeEntry } from "../theme-entry.types.mjs";
|
|
|
7
7
|
* Writes a theme entry to the class attribute on an element.
|
|
8
8
|
*
|
|
9
9
|
* @param themes - Record mapping theme keys to class name(s)
|
|
10
|
-
* @param entry - Theme entry to write, or undefined to remove the theme
|
|
11
|
-
* @param options.element - Element to write to (
|
|
10
|
+
* @param entry - Theme entry to write, or null/undefined to remove the theme
|
|
11
|
+
* @param options.element - Element to write to (accepts null e.g. from refs). Defaults to document.documentElement.
|
|
12
12
|
* @param options.stringify - Custom serializer (default: stringifyClassName)
|
|
13
13
|
*/
|
|
14
|
-
declare function writeClassName<Themes extends ThemeMap>(themes: Themes, entry: ThemeEntry<Themes> | undefined, options?: {
|
|
15
|
-
element?: Element | undefined;
|
|
14
|
+
declare function writeClassName<Themes extends ThemeMap>(themes: Themes, entry: ThemeEntry<Themes> | null | undefined, options?: {
|
|
15
|
+
element?: Element | null | undefined;
|
|
16
16
|
stringify?: StringifyStoredTheme<Themes> | undefined;
|
|
17
17
|
} | undefined): void;
|
|
18
18
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write-class-name.d.mts","names":[],"sources":["../../../src/theme/class-name/write-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAYA;;;;;;
|
|
1
|
+
{"version":3,"file":"write-class-name.d.mts","names":[],"sources":["../../../src/theme/class-name/write-class-name.ts"],"sourcesContent":[],"mappings":";;;;;;;AAYA;;;;;;AAI6E,iBAJ7D,cAI6D,CAAA,eAJ/B,QAI+B,CAAA,CAAA,MAAA,EAHpE,MAGoE,EAAA,KAAA,EAFrE,UAEqE,CAF1D,MAE0D,CAAA,GAAA,IAAA,GAAA,SAAA,EAAA,QAAA,EAAA;EAArB,OAAA,CAAA,EAAxC,OAAwC,GAAA,IAAA,GAAA,SAAA;EAAoB,SAAA,CAAA,EAApB,oBAAoB,CAAC,MAAD,CAAA,GAAA,SAAA"}
|
|
@@ -5,8 +5,8 @@ import { stringifyClassName } from "./stringify-class-name.mjs";
|
|
|
5
5
|
* Writes a theme entry to the class attribute on an element.
|
|
6
6
|
*
|
|
7
7
|
* @param themes - Record mapping theme keys to class name(s)
|
|
8
|
-
* @param entry - Theme entry to write, or undefined to remove the theme
|
|
9
|
-
* @param options.element - Element to write to (
|
|
8
|
+
* @param entry - Theme entry to write, or null/undefined to remove the theme
|
|
9
|
+
* @param options.element - Element to write to (accepts null e.g. from refs). Defaults to document.documentElement.
|
|
10
10
|
* @param options.stringify - Custom serializer (default: stringifyClassName)
|
|
11
11
|
*/
|
|
12
12
|
function writeClassName(themes, entry, options) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write-class-name.mjs","names":[],"sources":["../../../src/theme/class-name/write-class-name.ts"],"sourcesContent":["import type { StringifyStoredTheme, ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport { stringifyClassName } from './stringify-class-name.ts'\n\n/**\n * Writes a theme entry to the class attribute on an element.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param entry - Theme entry to write, or undefined to remove the theme\n * @param options.element - Element to write to (
|
|
1
|
+
{"version":3,"file":"write-class-name.mjs","names":[],"sources":["../../../src/theme/class-name/write-class-name.ts"],"sourcesContent":["import type { StringifyStoredTheme, ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport { stringifyClassName } from './stringify-class-name.ts'\n\n/**\n * Writes a theme entry to the class attribute on an element.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param entry - Theme entry to write, or null/undefined to remove the theme\n * @param options.element - Element to write to (accepts null e.g. from refs). Defaults to document.documentElement.\n * @param options.stringify - Custom serializer (default: stringifyClassName)\n */\nexport function writeClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\tentry: ThemeEntry<Themes> | null | undefined,\n\toptions?:\n\t\t| { element?: Element | null | undefined; stringify?: StringifyStoredTheme<Themes> | undefined }\n\t\t| undefined\n): void {\n\tconst element = options?.element ?? document?.documentElement\n\tif (!element) return\n\tconst stringify = options?.stringify ?? stringifyClassName\n\telement.className = stringify(themes, element.className ?? undefined, entry)\n}\n"],"mappings":";;;;;;;;;;;AAYA,SAAgB,eACf,QACA,OACA,SAGO;CACP,MAAM,UAAU,SAAS,WAAW,UAAU;AAC9C,KAAI,CAAC,QAAS;AAEd,SAAQ,aADU,SAAS,aAAa,oBACV,QAAQ,QAAQ,aAAa,QAAW,MAAM"}
|
|
@@ -1 +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
|
|
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) => 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,SAAsE;EACxF,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"}
|
|
@@ -1 +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
|
|
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) => 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,SAAsE;EACxF,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"}
|
|
@@ -7,13 +7,13 @@ const require__cookie_utils = require('./_cookie-utils.cjs');
|
|
|
7
7
|
* Performs cookie set/delete only. Does not notify subscribers; the store must call notify() after this.
|
|
8
8
|
*
|
|
9
9
|
* @param themes - Record mapping theme keys to values (used for type validation)
|
|
10
|
-
* @param entry - Theme entry to write, or undefined to remove
|
|
10
|
+
* @param entry - Theme entry to write, or null/undefined to remove
|
|
11
11
|
* @param options - Cookie options
|
|
12
12
|
*/
|
|
13
13
|
function writeCookieTheme(_themes, entry, options) {
|
|
14
14
|
const { cookieName, path = "/", maxAge, sameSite, secure } = options;
|
|
15
15
|
if (typeof document === "undefined" || document.cookie === void 0) return;
|
|
16
|
-
if (entry
|
|
16
|
+
if (entry == null) {
|
|
17
17
|
require__cookie_utils.deleteCookie(cookieName, path);
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write-cookie-theme.cjs","names":["opts: {\n\t\tpath: string\n\t\tmaxAge?: number\n\t\tsameSite?: 'lax' | 'strict' | 'none'\n\t\tsecure?: boolean\n\t}"],"sources":["../../../src/theme/cookie/write-cookie-theme.ts"],"sourcesContent":["import type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport { deleteCookie, setCookie } from './_cookie-utils.ts'\n\nexport interface WriteCookieThemeOptions<_Themes extends ThemeMap = ThemeMap> {\n\tcookieName: string\n\tpath?: string | undefined\n\tmaxAge?: number | undefined\n\tsameSite?: 'lax' | 'strict' | 'none' | undefined\n\tsecure?: boolean | undefined\n}\n\n/**\n * Writes a theme entry to a cookie.\n *\n * Performs cookie set/delete only. Does not notify subscribers; the store must call notify() after this.\n *\n * @param themes - Record mapping theme keys to values (used for type validation)\n * @param entry - Theme entry to write, or undefined to remove\n * @param options - Cookie options\n */\nexport function writeCookieTheme<Themes extends ThemeMap>(\n\t_themes: Themes,\n\tentry: ThemeEntry<Themes> | undefined,\n\toptions: WriteCookieThemeOptions<Themes>\n): void {\n\tconst { cookieName, path = '/', maxAge, sameSite, secure } = options\n\n\tif (typeof document === 'undefined' || document.cookie === undefined) {\n\t\treturn\n\t}\n\n\tif (entry
|
|
1
|
+
{"version":3,"file":"write-cookie-theme.cjs","names":["opts: {\n\t\tpath: string\n\t\tmaxAge?: number\n\t\tsameSite?: 'lax' | 'strict' | 'none'\n\t\tsecure?: boolean\n\t}"],"sources":["../../../src/theme/cookie/write-cookie-theme.ts"],"sourcesContent":["import type { ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport { deleteCookie, setCookie } from './_cookie-utils.ts'\n\nexport interface WriteCookieThemeOptions<_Themes extends ThemeMap = ThemeMap> {\n\tcookieName: string\n\tpath?: string | undefined\n\tmaxAge?: number | undefined\n\tsameSite?: 'lax' | 'strict' | 'none' | undefined\n\tsecure?: boolean | undefined\n}\n\n/**\n * Writes a theme entry to a cookie.\n *\n * Performs cookie set/delete only. Does not notify subscribers; the store must call notify() after this.\n *\n * @param themes - Record mapping theme keys to values (used for type validation)\n * @param entry - Theme entry to write, or null/undefined to remove\n * @param options - Cookie options\n */\nexport function writeCookieTheme<Themes extends ThemeMap>(\n\t_themes: Themes,\n\tentry: ThemeEntry<Themes> | null | undefined,\n\toptions: WriteCookieThemeOptions<Themes>\n): void {\n\tconst { cookieName, path = '/', maxAge, sameSite, secure } = options\n\n\tif (typeof document === 'undefined' || document.cookie === undefined) {\n\t\treturn\n\t}\n\n\tif (entry == null) {\n\t\tdeleteCookie(cookieName, path)\n\t\treturn\n\t}\n\n\tconst opts: {\n\t\tpath: string\n\t\tmaxAge?: number\n\t\tsameSite?: 'lax' | 'strict' | 'none'\n\t\tsecure?: boolean\n\t} = { path }\n\tif (maxAge !== undefined) opts.maxAge = maxAge\n\tif (sameSite !== undefined) opts.sameSite = sameSite\n\tif (secure) opts.secure = true\n\tsetCookie(cookieName, JSON.stringify(entry), opts)\n}\n"],"mappings":";;;;;;;;;;;;AAqBA,SAAgB,iBACf,SACA,OACA,SACO;CACP,MAAM,EAAE,YAAY,OAAO,KAAK,QAAQ,UAAU,WAAW;AAE7D,KAAI,OAAO,aAAa,eAAe,SAAS,WAAW,OAC1D;AAGD,KAAI,SAAS,MAAM;AAClB,qCAAa,YAAY,KAAK;AAC9B;;CAGD,MAAMA,OAKF,EAAE,MAAM;AACZ,KAAI,WAAW,OAAW,MAAK,SAAS;AACxC,KAAI,aAAa,OAAW,MAAK,WAAW;AAC5C,KAAI,OAAQ,MAAK,SAAS;AAC1B,iCAAU,YAAY,KAAK,UAAU,MAAM,EAAE,KAAK"}
|
|
@@ -15,10 +15,10 @@ interface WriteCookieThemeOptions<_Themes extends ThemeMap = ThemeMap> {
|
|
|
15
15
|
* Performs cookie set/delete only. Does not notify subscribers; the store must call notify() after this.
|
|
16
16
|
*
|
|
17
17
|
* @param themes - Record mapping theme keys to values (used for type validation)
|
|
18
|
-
* @param entry - Theme entry to write, or undefined to remove
|
|
18
|
+
* @param entry - Theme entry to write, or null/undefined to remove
|
|
19
19
|
* @param options - Cookie options
|
|
20
20
|
*/
|
|
21
|
-
declare function writeCookieTheme<Themes extends ThemeMap>(_themes: Themes, entry: ThemeEntry<Themes> | undefined, options: WriteCookieThemeOptions<Themes>): void;
|
|
21
|
+
declare function writeCookieTheme<Themes extends ThemeMap>(_themes: Themes, entry: ThemeEntry<Themes> | null | undefined, options: WriteCookieThemeOptions<Themes>): void;
|
|
22
22
|
//#endregion
|
|
23
23
|
export { WriteCookieThemeOptions, writeCookieTheme };
|
|
24
24
|
//# sourceMappingURL=write-cookie-theme.d.cts.map
|