@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
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Gets the value of an attribute from an element.
|
|
5
5
|
*
|
|
6
6
|
* @param qualifiedName - The name of the attribute to get
|
|
7
|
-
* @param element - The element to get the attribute from. Defaults to `document.documentElement`
|
|
7
|
+
* @param element - The element to get the attribute from (accepts null e.g. from refs). Defaults to `document.documentElement`
|
|
8
8
|
* @returns The attribute value cast to type T, or null if the attribute doesn't exist
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-attribute.cjs","names":[],"sources":["../../src/attributes/get-attribute.ts"],"sourcesContent":["/**\n * Gets the value of an attribute from an element.\n *\n * @param qualifiedName - The name of the attribute to get\n * @param element - The element to get the attribute from. Defaults to `document.documentElement`\n * @returns The attribute value cast to type T, or null if the attribute doesn't exist\n *\n * @example\n * ```ts\n * // Get theme from document root\n * const theme = getAttribute('data-theme')\n *\n * // Get data-testid from a specific element\n * const testId = getAttribute('data-testid', element)\n * ```\n */\nexport function getAttribute<T extends string>(
|
|
1
|
+
{"version":3,"file":"get-attribute.cjs","names":[],"sources":["../../src/attributes/get-attribute.ts"],"sourcesContent":["/**\n * Gets the value of an attribute from an element.\n *\n * @param qualifiedName - The name of the attribute to get\n * @param element - The element to get the attribute from (accepts null e.g. from refs). Defaults to `document.documentElement`\n * @returns The attribute value cast to type T, or null if the attribute doesn't exist\n *\n * @example\n * ```ts\n * // Get theme from document root\n * const theme = getAttribute('data-theme')\n *\n * // Get data-testid from a specific element\n * const testId = getAttribute('data-testid', element)\n * ```\n */\nexport function getAttribute<T extends string>(\n\tqualifiedName: T,\n\telement?: Element | null | undefined\n) {\n\telement = element ?? globalThis.document.documentElement\n\treturn element.getAttribute(qualifiedName)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAgBA,SAAgB,aACf,eACA,SACC;AACD,WAAU,WAAW,WAAW,SAAS;AACzC,QAAO,QAAQ,aAAa,cAAc"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Gets the value of an attribute from an element.
|
|
4
4
|
*
|
|
5
5
|
* @param qualifiedName - The name of the attribute to get
|
|
6
|
-
* @param element - The element to get the attribute from. Defaults to `document.documentElement`
|
|
6
|
+
* @param element - The element to get the attribute from (accepts null e.g. from refs). Defaults to `document.documentElement`
|
|
7
7
|
* @returns The attribute value cast to type T, or null if the attribute doesn't exist
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* const testId = getAttribute('data-testid', element)
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
|
-
declare function getAttribute<T extends string>(qualifiedName: T, element?: Element | undefined): string | null;
|
|
18
|
+
declare function getAttribute<T extends string>(qualifiedName: T, element?: Element | null | undefined): string | null;
|
|
19
19
|
//#endregion
|
|
20
20
|
export { getAttribute };
|
|
21
21
|
//# sourceMappingURL=get-attribute.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-attribute.d.cts","names":[],"sources":["../../src/attributes/get-attribute.ts"],"sourcesContent":[],"mappings":";;AAgBA;;;;;;;;;;;;;;;iBAAgB,
|
|
1
|
+
{"version":3,"file":"get-attribute.d.cts","names":[],"sources":["../../src/attributes/get-attribute.ts"],"sourcesContent":[],"mappings":";;AAgBA;;;;;;;;;;;;;;;iBAAgB,8CACA,aACL"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Gets the value of an attribute from an element.
|
|
4
4
|
*
|
|
5
5
|
* @param qualifiedName - The name of the attribute to get
|
|
6
|
-
* @param element - The element to get the attribute from. Defaults to `document.documentElement`
|
|
6
|
+
* @param element - The element to get the attribute from (accepts null e.g. from refs). Defaults to `document.documentElement`
|
|
7
7
|
* @returns The attribute value cast to type T, or null if the attribute doesn't exist
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* const testId = getAttribute('data-testid', element)
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
|
-
declare function getAttribute<T extends string>(qualifiedName: T, element?: Element | undefined): string | null;
|
|
18
|
+
declare function getAttribute<T extends string>(qualifiedName: T, element?: Element | null | undefined): string | null;
|
|
19
19
|
//#endregion
|
|
20
20
|
export { getAttribute };
|
|
21
21
|
//# sourceMappingURL=get-attribute.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-attribute.d.mts","names":[],"sources":["../../src/attributes/get-attribute.ts"],"sourcesContent":[],"mappings":";;AAgBA;;;;;;;;;;;;;;;iBAAgB,
|
|
1
|
+
{"version":3,"file":"get-attribute.d.mts","names":[],"sources":["../../src/attributes/get-attribute.ts"],"sourcesContent":[],"mappings":";;AAgBA;;;;;;;;;;;;;;;iBAAgB,8CACA,aACL"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Gets the value of an attribute from an element.
|
|
4
4
|
*
|
|
5
5
|
* @param qualifiedName - The name of the attribute to get
|
|
6
|
-
* @param element - The element to get the attribute from. Defaults to `document.documentElement`
|
|
6
|
+
* @param element - The element to get the attribute from (accepts null e.g. from refs). Defaults to `document.documentElement`
|
|
7
7
|
* @returns The attribute value cast to type T, or null if the attribute doesn't exist
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-attribute.mjs","names":[],"sources":["../../src/attributes/get-attribute.ts"],"sourcesContent":["/**\n * Gets the value of an attribute from an element.\n *\n * @param qualifiedName - The name of the attribute to get\n * @param element - The element to get the attribute from. Defaults to `document.documentElement`\n * @returns The attribute value cast to type T, or null if the attribute doesn't exist\n *\n * @example\n * ```ts\n * // Get theme from document root\n * const theme = getAttribute('data-theme')\n *\n * // Get data-testid from a specific element\n * const testId = getAttribute('data-testid', element)\n * ```\n */\nexport function getAttribute<T extends string>(
|
|
1
|
+
{"version":3,"file":"get-attribute.mjs","names":[],"sources":["../../src/attributes/get-attribute.ts"],"sourcesContent":["/**\n * Gets the value of an attribute from an element.\n *\n * @param qualifiedName - The name of the attribute to get\n * @param element - The element to get the attribute from (accepts null e.g. from refs). Defaults to `document.documentElement`\n * @returns The attribute value cast to type T, or null if the attribute doesn't exist\n *\n * @example\n * ```ts\n * // Get theme from document root\n * const theme = getAttribute('data-theme')\n *\n * // Get data-testid from a specific element\n * const testId = getAttribute('data-testid', element)\n * ```\n */\nexport function getAttribute<T extends string>(\n\tqualifiedName: T,\n\telement?: Element | null | undefined\n) {\n\telement = element ?? globalThis.document.documentElement\n\treturn element.getAttribute(qualifiedName)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAgBA,SAAgB,aACf,eACA,SACC;AACD,WAAU,WAAW,WAAW,SAAS;AACzC,QAAO,QAAQ,aAAa,cAAc"}
|
|
@@ -5,7 +5,7 @@ const require_get_attribute = require('./get-attribute.cjs');
|
|
|
5
5
|
* Gets the value of a data attribute from an element.
|
|
6
6
|
*
|
|
7
7
|
* @param qualifiedName - The name of the data attribute to get
|
|
8
|
-
* @param element - The element to get the data attribute from. Defaults to `document.documentElement`
|
|
8
|
+
* @param element - The element to get the data attribute from (accepts null e.g. from refs). Defaults to `document.documentElement`
|
|
9
9
|
* @returns The data attribute value, or null if the attribute doesn't exist
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-data-attribute.cjs","names":["getAttribute"],"sources":["../../src/attributes/get-data-attribute.ts"],"sourcesContent":["import type { DataAttribute } from './data-attribute.ts'\nimport { getAttribute } from './get-attribute.ts'\n\n/**\n * Gets the value of a data attribute from an element.\n *\n * @param qualifiedName - The name of the data attribute to get\n * @param element - The element to get the data attribute from. Defaults to `document.documentElement`\n * @returns The data attribute value, or null if the attribute doesn't exist\n *\n * @example\n */\nexport function getDataAttribute(
|
|
1
|
+
{"version":3,"file":"get-data-attribute.cjs","names":["getAttribute"],"sources":["../../src/attributes/get-data-attribute.ts"],"sourcesContent":["import type { DataAttribute } from './data-attribute.ts'\nimport { getAttribute } from './get-attribute.ts'\n\n/**\n * Gets the value of a data attribute from an element.\n *\n * @param qualifiedName - The name of the data attribute to get\n * @param element - The element to get the data attribute from (accepts null e.g. from refs). Defaults to `document.documentElement`\n * @returns The data attribute value, or null if the attribute doesn't exist\n *\n * @example\n */\nexport function getDataAttribute(\n\tqualifiedName: DataAttribute,\n\telement?: Element | null | undefined\n) {\n\treturn getAttribute(qualifiedName, element)\n}\n"],"mappings":";;;;;;;;;;;;AAYA,SAAgB,iBACf,eACA,SACC;AACD,QAAOA,mCAAa,eAAe,QAAQ"}
|
|
@@ -6,12 +6,12 @@ import { DataAttribute } from "./data-attribute.cjs";
|
|
|
6
6
|
* Gets the value of a data attribute from an element.
|
|
7
7
|
*
|
|
8
8
|
* @param qualifiedName - The name of the data attribute to get
|
|
9
|
-
* @param element - The element to get the data attribute from. Defaults to `document.documentElement`
|
|
9
|
+
* @param element - The element to get the data attribute from (accepts null e.g. from refs). Defaults to `document.documentElement`
|
|
10
10
|
* @returns The data attribute value, or null if the attribute doesn't exist
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
*/
|
|
14
|
-
declare function getDataAttribute(qualifiedName: DataAttribute, element?: Element | undefined): string | null;
|
|
14
|
+
declare function getDataAttribute(qualifiedName: DataAttribute, element?: Element | null | undefined): string | null;
|
|
15
15
|
//#endregion
|
|
16
16
|
export { getDataAttribute };
|
|
17
17
|
//# sourceMappingURL=get-data-attribute.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-data-attribute.d.cts","names":[],"sources":["../../src/attributes/get-data-attribute.ts"],"sourcesContent":[],"mappings":";;;;;;AAYA;;;;;;;iBAAgB,gBAAA,
|
|
1
|
+
{"version":3,"file":"get-data-attribute.d.cts","names":[],"sources":["../../src/attributes/get-data-attribute.ts"],"sourcesContent":[],"mappings":";;;;;;AAYA;;;;;;;iBAAgB,gBAAA,gBACA,yBACL"}
|
|
@@ -6,12 +6,12 @@ import { DataAttribute } from "./data-attribute.mjs";
|
|
|
6
6
|
* Gets the value of a data attribute from an element.
|
|
7
7
|
*
|
|
8
8
|
* @param qualifiedName - The name of the data attribute to get
|
|
9
|
-
* @param element - The element to get the data attribute from. Defaults to `document.documentElement`
|
|
9
|
+
* @param element - The element to get the data attribute from (accepts null e.g. from refs). Defaults to `document.documentElement`
|
|
10
10
|
* @returns The data attribute value, or null if the attribute doesn't exist
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
*/
|
|
14
|
-
declare function getDataAttribute(qualifiedName: DataAttribute, element?: Element | undefined): string | null;
|
|
14
|
+
declare function getDataAttribute(qualifiedName: DataAttribute, element?: Element | null | undefined): string | null;
|
|
15
15
|
//#endregion
|
|
16
16
|
export { getDataAttribute };
|
|
17
17
|
//# sourceMappingURL=get-data-attribute.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-data-attribute.d.mts","names":[],"sources":["../../src/attributes/get-data-attribute.ts"],"sourcesContent":[],"mappings":";;;;;;AAYA;;;;;;;iBAAgB,gBAAA,
|
|
1
|
+
{"version":3,"file":"get-data-attribute.d.mts","names":[],"sources":["../../src/attributes/get-data-attribute.ts"],"sourcesContent":[],"mappings":";;;;;;AAYA;;;;;;;iBAAgB,gBAAA,gBACA,yBACL"}
|
|
@@ -5,7 +5,7 @@ import { getAttribute } from "./get-attribute.mjs";
|
|
|
5
5
|
* Gets the value of a data attribute from an element.
|
|
6
6
|
*
|
|
7
7
|
* @param qualifiedName - The name of the data attribute to get
|
|
8
|
-
* @param element - The element to get the data attribute from. Defaults to `document.documentElement`
|
|
8
|
+
* @param element - The element to get the data attribute from (accepts null e.g. from refs). Defaults to `document.documentElement`
|
|
9
9
|
* @returns The data attribute value, or null if the attribute doesn't exist
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-data-attribute.mjs","names":[],"sources":["../../src/attributes/get-data-attribute.ts"],"sourcesContent":["import type { DataAttribute } from './data-attribute.ts'\nimport { getAttribute } from './get-attribute.ts'\n\n/**\n * Gets the value of a data attribute from an element.\n *\n * @param qualifiedName - The name of the data attribute to get\n * @param element - The element to get the data attribute from. Defaults to `document.documentElement`\n * @returns The data attribute value, or null if the attribute doesn't exist\n *\n * @example\n */\nexport function getDataAttribute(
|
|
1
|
+
{"version":3,"file":"get-data-attribute.mjs","names":[],"sources":["../../src/attributes/get-data-attribute.ts"],"sourcesContent":["import type { DataAttribute } from './data-attribute.ts'\nimport { getAttribute } from './get-attribute.ts'\n\n/**\n * Gets the value of a data attribute from an element.\n *\n * @param qualifiedName - The name of the data attribute to get\n * @param element - The element to get the data attribute from (accepts null e.g. from refs). Defaults to `document.documentElement`\n * @returns The data attribute value, or null if the attribute doesn't exist\n *\n * @example\n */\nexport function getDataAttribute(\n\tqualifiedName: DataAttribute,\n\telement?: Element | null | undefined\n) {\n\treturn getAttribute(qualifiedName, element)\n}\n"],"mappings":";;;;;;;;;;;;AAYA,SAAgB,iBACf,eACA,SACC;AACD,QAAO,aAAa,eAAe,QAAQ"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Observes attributes changes on an element and calls corresponding handlers.
|
|
5
5
|
*
|
|
6
6
|
* @param handlers - An object mapping attribute names to handler functions.
|
|
7
|
-
* @param element - The element to observe. Defaults to `document.documentElement`.
|
|
7
|
+
* @param element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement`.
|
|
8
8
|
* @returns {MutationObserver} The observer instance, which can be used to disconnect the observer.
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observe-attribute.cjs","names":[],"sources":["../../src/attributes/observe-attribute.ts"],"sourcesContent":["/**\n * Observes attributes changes on an element and calls corresponding handlers.\n *\n * @param handlers - An object mapping attribute names to handler functions.\n * @param element - The element to observe. Defaults to `document.documentElement`.\n * @returns {MutationObserver} The observer instance, which can be used to disconnect the observer.\n *\n * @example\n * ```ts\n * const observer = observeAttributes({\n * 'data-theme': (attr, value) => console.log(`Theme changed to: ${value}`),\n * 'class': (attr, value) => console.log(`class changed to: ${value}`)\n * });\n *\n * // Later, to stop observing:\n * observer.disconnect();\n * ```\n */\nexport function observeAttributes<T extends string>(\n\thandlers: Record<string, (value: T | null) => void>,\n\telement?: Element | undefined\n) {\n\telement = element ?? globalThis.document.documentElement\n\tconst observer = new MutationObserver((mutations) => {\n\t\tfor (const mutation of mutations) {\n\t\t\tconst attribute = mutation.attributeName\n\t\t\tif (!attribute) continue\n\t\t\tconst value = element.getAttribute(attribute) as T | null\n\t\t\thandlers[attribute]?.(value)\n\t\t}\n\t})\n\tobserver.observe(element, {\n\t\tattributes: true,\n\t\tattributeFilter: Object.keys(handlers)\n\t})\n\treturn observer\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAkBA,SAAgB,kBACf,UACA,SACC;AACD,WAAU,WAAW,WAAW,SAAS;CACzC,MAAM,WAAW,IAAI,kBAAkB,cAAc;AACpD,OAAK,MAAM,YAAY,WAAW;GACjC,MAAM,YAAY,SAAS;AAC3B,OAAI,CAAC,UAAW;GAChB,MAAM,QAAQ,QAAQ,aAAa,UAAU;AAC7C,YAAS,aAAa,MAAM;;GAE5B;AACF,UAAS,QAAQ,SAAS;EACzB,YAAY;EACZ,iBAAiB,OAAO,KAAK,SAAS;EACtC,CAAC;AACF,QAAO"}
|
|
1
|
+
{"version":3,"file":"observe-attribute.cjs","names":[],"sources":["../../src/attributes/observe-attribute.ts"],"sourcesContent":["/**\n * Observes attributes changes on an element and calls corresponding handlers.\n *\n * @param handlers - An object mapping attribute names to handler functions.\n * @param element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement`.\n * @returns {MutationObserver} The observer instance, which can be used to disconnect the observer.\n *\n * @example\n * ```ts\n * const observer = observeAttributes({\n * 'data-theme': (attr, value) => console.log(`Theme changed to: ${value}`),\n * 'class': (attr, value) => console.log(`class changed to: ${value}`)\n * });\n *\n * // Later, to stop observing:\n * observer.disconnect();\n * ```\n */\nexport function observeAttributes<T extends string>(\n\thandlers: Record<string, (value: T | null) => void>,\n\telement?: Element | null | undefined\n) {\n\telement = element ?? globalThis.document.documentElement\n\tconst observer = new MutationObserver((mutations) => {\n\t\tfor (const mutation of mutations) {\n\t\t\tconst attribute = mutation.attributeName\n\t\t\tif (!attribute) continue\n\t\t\tconst value = element.getAttribute(attribute) as T | null\n\t\t\thandlers[attribute]?.(value)\n\t\t}\n\t})\n\tobserver.observe(element, {\n\t\tattributes: true,\n\t\tattributeFilter: Object.keys(handlers)\n\t})\n\treturn observer\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAkBA,SAAgB,kBACf,UACA,SACC;AACD,WAAU,WAAW,WAAW,SAAS;CACzC,MAAM,WAAW,IAAI,kBAAkB,cAAc;AACpD,OAAK,MAAM,YAAY,WAAW;GACjC,MAAM,YAAY,SAAS;AAC3B,OAAI,CAAC,UAAW;GAChB,MAAM,QAAQ,QAAQ,aAAa,UAAU;AAC7C,YAAS,aAAa,MAAM;;GAE5B;AACF,UAAS,QAAQ,SAAS;EACzB,YAAY;EACZ,iBAAiB,OAAO,KAAK,SAAS;EACtC,CAAC;AACF,QAAO"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Observes attributes changes on an element and calls corresponding handlers.
|
|
4
4
|
*
|
|
5
5
|
* @param handlers - An object mapping attribute names to handler functions.
|
|
6
|
-
* @param element - The element to observe. Defaults to `document.documentElement`.
|
|
6
|
+
* @param element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement`.
|
|
7
7
|
* @returns {MutationObserver} The observer instance, which can be used to disconnect the observer.
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* observer.disconnect();
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
|
-
declare function observeAttributes<T extends string>(handlers: Record<string, (value: T | null) => void>, element?: Element | undefined): MutationObserver;
|
|
20
|
+
declare function observeAttributes<T extends string>(handlers: Record<string, (value: T | null) => void>, element?: Element | null | undefined): MutationObserver;
|
|
21
21
|
//#endregion
|
|
22
22
|
export { observeAttributes };
|
|
23
23
|
//# sourceMappingURL=observe-attribute.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observe-attribute.d.cts","names":[],"sources":["../../src/attributes/observe-attribute.ts"],"sourcesContent":[],"mappings":";;AAkBA;;;;;;;;;;;;;;;;;iBAAgB,8CACL,uBAAuB,8BACvB,
|
|
1
|
+
{"version":3,"file":"observe-attribute.d.cts","names":[],"sources":["../../src/attributes/observe-attribute.ts"],"sourcesContent":[],"mappings":";;AAkBA;;;;;;;;;;;;;;;;;iBAAgB,8CACL,uBAAuB,8BACvB,6BAA0B"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Observes attributes changes on an element and calls corresponding handlers.
|
|
4
4
|
*
|
|
5
5
|
* @param handlers - An object mapping attribute names to handler functions.
|
|
6
|
-
* @param element - The element to observe. Defaults to `document.documentElement`.
|
|
6
|
+
* @param element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement`.
|
|
7
7
|
* @returns {MutationObserver} The observer instance, which can be used to disconnect the observer.
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* observer.disconnect();
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
|
-
declare function observeAttributes<T extends string>(handlers: Record<string, (value: T | null) => void>, element?: Element | undefined): MutationObserver;
|
|
20
|
+
declare function observeAttributes<T extends string>(handlers: Record<string, (value: T | null) => void>, element?: Element | null | undefined): MutationObserver;
|
|
21
21
|
//#endregion
|
|
22
22
|
export { observeAttributes };
|
|
23
23
|
//# sourceMappingURL=observe-attribute.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observe-attribute.d.mts","names":[],"sources":["../../src/attributes/observe-attribute.ts"],"sourcesContent":[],"mappings":";;AAkBA;;;;;;;;;;;;;;;;;iBAAgB,8CACL,uBAAuB,8BACvB,
|
|
1
|
+
{"version":3,"file":"observe-attribute.d.mts","names":[],"sources":["../../src/attributes/observe-attribute.ts"],"sourcesContent":[],"mappings":";;AAkBA;;;;;;;;;;;;;;;;;iBAAgB,8CACL,uBAAuB,8BACvB,6BAA0B"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Observes attributes changes on an element and calls corresponding handlers.
|
|
4
4
|
*
|
|
5
5
|
* @param handlers - An object mapping attribute names to handler functions.
|
|
6
|
-
* @param element - The element to observe. Defaults to `document.documentElement`.
|
|
6
|
+
* @param element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement`.
|
|
7
7
|
* @returns {MutationObserver} The observer instance, which can be used to disconnect the observer.
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observe-attribute.mjs","names":[],"sources":["../../src/attributes/observe-attribute.ts"],"sourcesContent":["/**\n * Observes attributes changes on an element and calls corresponding handlers.\n *\n * @param handlers - An object mapping attribute names to handler functions.\n * @param element - The element to observe. Defaults to `document.documentElement`.\n * @returns {MutationObserver} The observer instance, which can be used to disconnect the observer.\n *\n * @example\n * ```ts\n * const observer = observeAttributes({\n * 'data-theme': (attr, value) => console.log(`Theme changed to: ${value}`),\n * 'class': (attr, value) => console.log(`class changed to: ${value}`)\n * });\n *\n * // Later, to stop observing:\n * observer.disconnect();\n * ```\n */\nexport function observeAttributes<T extends string>(\n\thandlers: Record<string, (value: T | null) => void>,\n\telement?: Element | undefined\n) {\n\telement = element ?? globalThis.document.documentElement\n\tconst observer = new MutationObserver((mutations) => {\n\t\tfor (const mutation of mutations) {\n\t\t\tconst attribute = mutation.attributeName\n\t\t\tif (!attribute) continue\n\t\t\tconst value = element.getAttribute(attribute) as T | null\n\t\t\thandlers[attribute]?.(value)\n\t\t}\n\t})\n\tobserver.observe(element, {\n\t\tattributes: true,\n\t\tattributeFilter: Object.keys(handlers)\n\t})\n\treturn observer\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,SAAgB,kBACf,UACA,SACC;AACD,WAAU,WAAW,WAAW,SAAS;CACzC,MAAM,WAAW,IAAI,kBAAkB,cAAc;AACpD,OAAK,MAAM,YAAY,WAAW;GACjC,MAAM,YAAY,SAAS;AAC3B,OAAI,CAAC,UAAW;GAChB,MAAM,QAAQ,QAAQ,aAAa,UAAU;AAC7C,YAAS,aAAa,MAAM;;GAE5B;AACF,UAAS,QAAQ,SAAS;EACzB,YAAY;EACZ,iBAAiB,OAAO,KAAK,SAAS;EACtC,CAAC;AACF,QAAO"}
|
|
1
|
+
{"version":3,"file":"observe-attribute.mjs","names":[],"sources":["../../src/attributes/observe-attribute.ts"],"sourcesContent":["/**\n * Observes attributes changes on an element and calls corresponding handlers.\n *\n * @param handlers - An object mapping attribute names to handler functions.\n * @param element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement`.\n * @returns {MutationObserver} The observer instance, which can be used to disconnect the observer.\n *\n * @example\n * ```ts\n * const observer = observeAttributes({\n * 'data-theme': (attr, value) => console.log(`Theme changed to: ${value}`),\n * 'class': (attr, value) => console.log(`class changed to: ${value}`)\n * });\n *\n * // Later, to stop observing:\n * observer.disconnect();\n * ```\n */\nexport function observeAttributes<T extends string>(\n\thandlers: Record<string, (value: T | null) => void>,\n\telement?: Element | null | undefined\n) {\n\telement = element ?? globalThis.document.documentElement\n\tconst observer = new MutationObserver((mutations) => {\n\t\tfor (const mutation of mutations) {\n\t\t\tconst attribute = mutation.attributeName\n\t\t\tif (!attribute) continue\n\t\t\tconst value = element.getAttribute(attribute) as T | null\n\t\t\thandlers[attribute]?.(value)\n\t\t}\n\t})\n\tobserver.observe(element, {\n\t\tattributes: true,\n\t\tattributeFilter: Object.keys(handlers)\n\t})\n\treturn observer\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,SAAgB,kBACf,UACA,SACC;AACD,WAAU,WAAW,WAAW,SAAS;CACzC,MAAM,WAAW,IAAI,kBAAkB,cAAc;AACpD,OAAK,MAAM,YAAY,WAAW;GACjC,MAAM,YAAY,SAAS;AAC3B,OAAI,CAAC,UAAW;GAChB,MAAM,QAAQ,QAAQ,aAAa,UAAU;AAC7C,YAAS,aAAa,MAAM;;GAE5B;AACF,UAAS,QAAQ,SAAS;EACzB,YAAY;EACZ,iBAAiB,OAAO,KAAK,SAAS;EACtC,CAAC;AACF,QAAO"}
|
|
@@ -6,7 +6,7 @@ const require_observe_attribute = require('./observe-attribute.cjs');
|
|
|
6
6
|
*
|
|
7
7
|
* @param options - Configuration options
|
|
8
8
|
* @param options.handlers - An object mapping `data-*` attribute names to handler functions.
|
|
9
|
-
* @param options.element - The element to observe. Defaults to `document.documentElement`
|
|
9
|
+
* @param options.element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement`
|
|
10
10
|
* @returns {MutationObserver} The observer instance, which can be used to disconnect the observer
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observe-data-attribute.cjs","names":["observeAttributes"],"sources":["../../src/attributes/observe-data-attribute.ts"],"sourcesContent":["import { observeAttributes } from './observe-attribute.ts'\n\n/**\n * Observes changes to `data-*` attributes on an element and calls corresponding handlers.\n *\n * @param options - Configuration options\n * @param options.handlers - An object mapping `data-*` attribute names to handler functions.\n * @param options.element - The element to observe. Defaults to `document.documentElement`\n * @returns {MutationObserver} The observer instance, which can be used to disconnect the observer\n *\n * @example\n * ```ts\n * const observer = observeDataAttributes({\n * handlers: {\n * 'data-theme': (value) => console.log(`Theme changed to: ${value}`),\n * 'data-mode': (value) => console.log(`Mode changed to: ${value}`)\n * }\n * });\n *\n * // Later, to stop observing:\n * observer.disconnect();\n * ```\n */\nexport function observeDataAttributes<T extends string, K extends `data-${string}`>(\n\thandlers: Record<K, (value: T | null) => void>,\n\telement?: Element | undefined\n) {\n\treturn observeAttributes(handlers, element)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,sBACf,UACA,SACC;AACD,QAAOA,4CAAkB,UAAU,QAAQ"}
|
|
1
|
+
{"version":3,"file":"observe-data-attribute.cjs","names":["observeAttributes"],"sources":["../../src/attributes/observe-data-attribute.ts"],"sourcesContent":["import { observeAttributes } from './observe-attribute.ts'\n\n/**\n * Observes changes to `data-*` attributes on an element and calls corresponding handlers.\n *\n * @param options - Configuration options\n * @param options.handlers - An object mapping `data-*` attribute names to handler functions.\n * @param options.element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement`\n * @returns {MutationObserver} The observer instance, which can be used to disconnect the observer\n *\n * @example\n * ```ts\n * const observer = observeDataAttributes({\n * handlers: {\n * 'data-theme': (value) => console.log(`Theme changed to: ${value}`),\n * 'data-mode': (value) => console.log(`Mode changed to: ${value}`)\n * }\n * });\n *\n * // Later, to stop observing:\n * observer.disconnect();\n * ```\n */\nexport function observeDataAttributes<T extends string, K extends `data-${string}`>(\n\thandlers: Record<K, (value: T | null) => void>,\n\telement?: Element | null | undefined\n) {\n\treturn observeAttributes(handlers, element)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,sBACf,UACA,SACC;AACD,QAAOA,4CAAkB,UAAU,QAAQ"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @param options - Configuration options
|
|
6
6
|
* @param options.handlers - An object mapping `data-*` attribute names to handler functions.
|
|
7
|
-
* @param options.element - The element to observe. Defaults to `document.documentElement`
|
|
7
|
+
* @param options.element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement`
|
|
8
8
|
* @returns {MutationObserver} The observer instance, which can be used to disconnect the observer
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
* observer.disconnect();
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
|
-
declare function observeDataAttributes<T extends string, K extends `data-${string}`>(handlers: Record<K, (value: T | null) => void>, element?: Element | undefined): MutationObserver;
|
|
23
|
+
declare function observeDataAttributes<T extends string, K extends `data-${string}`>(handlers: Record<K, (value: T | null) => void>, element?: Element | null | undefined): MutationObserver;
|
|
24
24
|
//#endregion
|
|
25
25
|
export { observeDataAttributes };
|
|
26
26
|
//# sourceMappingURL=observe-data-attribute.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observe-data-attribute.d.cts","names":[],"sources":["../../src/attributes/observe-data-attribute.ts"],"sourcesContent":[],"mappings":";;AAuBA;;;;;;;;;;;;;;;;;;;;iBAAgB,8EACL,OAAO,WAAW,8BAClB,
|
|
1
|
+
{"version":3,"file":"observe-data-attribute.d.cts","names":[],"sources":["../../src/attributes/observe-data-attribute.ts"],"sourcesContent":[],"mappings":";;AAuBA;;;;;;;;;;;;;;;;;;;;iBAAgB,8EACL,OAAO,WAAW,8BAClB,6BAA0B"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @param options - Configuration options
|
|
6
6
|
* @param options.handlers - An object mapping `data-*` attribute names to handler functions.
|
|
7
|
-
* @param options.element - The element to observe. Defaults to `document.documentElement`
|
|
7
|
+
* @param options.element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement`
|
|
8
8
|
* @returns {MutationObserver} The observer instance, which can be used to disconnect the observer
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
* observer.disconnect();
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
|
-
declare function observeDataAttributes<T extends string, K extends `data-${string}`>(handlers: Record<K, (value: T | null) => void>, element?: Element | undefined): MutationObserver;
|
|
23
|
+
declare function observeDataAttributes<T extends string, K extends `data-${string}`>(handlers: Record<K, (value: T | null) => void>, element?: Element | null | undefined): MutationObserver;
|
|
24
24
|
//#endregion
|
|
25
25
|
export { observeDataAttributes };
|
|
26
26
|
//# sourceMappingURL=observe-data-attribute.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observe-data-attribute.d.mts","names":[],"sources":["../../src/attributes/observe-data-attribute.ts"],"sourcesContent":[],"mappings":";;AAuBA;;;;;;;;;;;;;;;;;;;;iBAAgB,8EACL,OAAO,WAAW,8BAClB,
|
|
1
|
+
{"version":3,"file":"observe-data-attribute.d.mts","names":[],"sources":["../../src/attributes/observe-data-attribute.ts"],"sourcesContent":[],"mappings":";;AAuBA;;;;;;;;;;;;;;;;;;;;iBAAgB,8EACL,OAAO,WAAW,8BAClB,6BAA0B"}
|
|
@@ -6,7 +6,7 @@ import { observeAttributes } from "./observe-attribute.mjs";
|
|
|
6
6
|
*
|
|
7
7
|
* @param options - Configuration options
|
|
8
8
|
* @param options.handlers - An object mapping `data-*` attribute names to handler functions.
|
|
9
|
-
* @param options.element - The element to observe. Defaults to `document.documentElement`
|
|
9
|
+
* @param options.element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement`
|
|
10
10
|
* @returns {MutationObserver} The observer instance, which can be used to disconnect the observer
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observe-data-attribute.mjs","names":[],"sources":["../../src/attributes/observe-data-attribute.ts"],"sourcesContent":["import { observeAttributes } from './observe-attribute.ts'\n\n/**\n * Observes changes to `data-*` attributes on an element and calls corresponding handlers.\n *\n * @param options - Configuration options\n * @param options.handlers - An object mapping `data-*` attribute names to handler functions.\n * @param options.element - The element to observe. Defaults to `document.documentElement`\n * @returns {MutationObserver} The observer instance, which can be used to disconnect the observer\n *\n * @example\n * ```ts\n * const observer = observeDataAttributes({\n * handlers: {\n * 'data-theme': (value) => console.log(`Theme changed to: ${value}`),\n * 'data-mode': (value) => console.log(`Mode changed to: ${value}`)\n * }\n * });\n *\n * // Later, to stop observing:\n * observer.disconnect();\n * ```\n */\nexport function observeDataAttributes<T extends string, K extends `data-${string}`>(\n\thandlers: Record<K, (value: T | null) => void>,\n\telement?: Element | undefined\n) {\n\treturn observeAttributes(handlers, element)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,sBACf,UACA,SACC;AACD,QAAO,kBAAkB,UAAU,QAAQ"}
|
|
1
|
+
{"version":3,"file":"observe-data-attribute.mjs","names":[],"sources":["../../src/attributes/observe-data-attribute.ts"],"sourcesContent":["import { observeAttributes } from './observe-attribute.ts'\n\n/**\n * Observes changes to `data-*` attributes on an element and calls corresponding handlers.\n *\n * @param options - Configuration options\n * @param options.handlers - An object mapping `data-*` attribute names to handler functions.\n * @param options.element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement`\n * @returns {MutationObserver} The observer instance, which can be used to disconnect the observer\n *\n * @example\n * ```ts\n * const observer = observeDataAttributes({\n * handlers: {\n * 'data-theme': (value) => console.log(`Theme changed to: ${value}`),\n * 'data-mode': (value) => console.log(`Mode changed to: ${value}`)\n * }\n * });\n *\n * // Later, to stop observing:\n * observer.disconnect();\n * ```\n */\nexport function observeDataAttributes<T extends string, K extends `data-${string}`>(\n\thandlers: Record<K, (value: T | null) => void>,\n\telement?: Element | null | undefined\n) {\n\treturn observeAttributes(handlers, element)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,sBACf,UACA,SACC;AACD,QAAO,kBAAkB,UAAU,QAAQ"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/color-scheme/color-scheme.types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The color scheme of the system.
|
|
4
|
+
*
|
|
5
|
+
* Per {@link https://drafts.csswg.org/mediaqueries-5/#prefers-color-scheme Media Queries Level 5 § prefers-color-scheme},
|
|
6
|
+
* these are the only valid values exposed by the `prefers-color-scheme` media feature.
|
|
7
|
+
*/
|
|
8
|
+
type ColorScheme = 'light' | 'dark';
|
|
9
|
+
//#endregion
|
|
10
|
+
export { ColorScheme };
|
|
11
|
+
//# sourceMappingURL=color-scheme.types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-scheme.types.d.cts","names":[],"sources":["../../src/color-scheme/color-scheme.types.ts"],"sourcesContent":[],"mappings":";;AAMA;;;;;KAAY,WAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/color-scheme/color-scheme.types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The color scheme of the system.
|
|
4
|
+
*
|
|
5
|
+
* Per {@link https://drafts.csswg.org/mediaqueries-5/#prefers-color-scheme Media Queries Level 5 § prefers-color-scheme},
|
|
6
|
+
* these are the only valid values exposed by the `prefers-color-scheme` media feature.
|
|
7
|
+
*/
|
|
8
|
+
type ColorScheme = 'light' | 'dark';
|
|
9
|
+
//#endregion
|
|
10
|
+
export { ColorScheme };
|
|
11
|
+
//# sourceMappingURL=color-scheme.types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-scheme.types.d.mts","names":[],"sources":["../../src/color-scheme/color-scheme.types.ts"],"sourcesContent":[],"mappings":";;AAMA;;;;;KAAY,WAAA"}
|
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
* Gets the current preferred color scheme.
|
|
5
5
|
* It can only be 'light' or 'dark'.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* Per {@link https://drafts.csswg.org/mediaqueries-5/#prefers-color-scheme Media Queries Level 5},
|
|
8
|
+
* the `prefers-color-scheme` media feature has only two valid values. Even if the browser
|
|
9
|
+
* preference is 'auto'/'device', it will return 'light' or 'dark'.
|
|
8
10
|
*
|
|
9
11
|
* When `matchMedia` is unavailable (e.g. SSR), returns `defaultColorScheme`.
|
|
10
12
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-prefers-color-scheme.cjs","names":[],"sources":["../../src/color-scheme/get-prefers-color-scheme.ts"],"sourcesContent":["/**\n * Gets the current preferred color scheme.\n * It can only be 'light' or 'dark'.\n *\n * Even if the browser preference is 'auto'/'device', it will return 'light' or 'dark'.\n *\n * When `matchMedia` is unavailable (e.g. SSR), returns `defaultColorScheme`.\n *\n * @param defaultColorScheme - Fallback when `matchMedia` is unavailable (default: `'light'`)\n * @returns 'light' or 'dark'\n */\nexport function getPrefersColorScheme(
|
|
1
|
+
{"version":3,"file":"get-prefers-color-scheme.cjs","names":[],"sources":["../../src/color-scheme/get-prefers-color-scheme.ts"],"sourcesContent":["import type { ColorScheme } from './color-scheme.types.ts'\n\n/**\n * Gets the current preferred color scheme.\n * It can only be 'light' or 'dark'.\n *\n * Per {@link https://drafts.csswg.org/mediaqueries-5/#prefers-color-scheme Media Queries Level 5},\n * the `prefers-color-scheme` media feature has only two valid values. Even if the browser\n * preference is 'auto'/'device', it will return 'light' or 'dark'.\n *\n * When `matchMedia` is unavailable (e.g. SSR), returns `defaultColorScheme`.\n *\n * @param defaultColorScheme - Fallback when `matchMedia` is unavailable (default: `'light'`)\n * @returns 'light' or 'dark'\n */\nexport function getPrefersColorScheme(defaultColorScheme: ColorScheme = 'light'): ColorScheme {\n\tif (typeof matchMedia === 'undefined') return defaultColorScheme\n\treturn matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark'\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,SAAgB,sBAAsB,qBAAkC,SAAsB;AAC7F,KAAI,OAAO,eAAe,YAAa,QAAO;AAC9C,QAAO,WAAW,gCAAgC,CAAC,UAAU,UAAU"}
|
|
@@ -1,16 +1,21 @@
|
|
|
1
|
+
import { ColorScheme } from "./color-scheme.types.cjs";
|
|
2
|
+
|
|
1
3
|
//#region src/color-scheme/get-prefers-color-scheme.d.ts
|
|
4
|
+
|
|
2
5
|
/**
|
|
3
6
|
* Gets the current preferred color scheme.
|
|
4
7
|
* It can only be 'light' or 'dark'.
|
|
5
8
|
*
|
|
6
|
-
*
|
|
9
|
+
* Per {@link https://drafts.csswg.org/mediaqueries-5/#prefers-color-scheme Media Queries Level 5},
|
|
10
|
+
* the `prefers-color-scheme` media feature has only two valid values. Even if the browser
|
|
11
|
+
* preference is 'auto'/'device', it will return 'light' or 'dark'.
|
|
7
12
|
*
|
|
8
13
|
* When `matchMedia` is unavailable (e.g. SSR), returns `defaultColorScheme`.
|
|
9
14
|
*
|
|
10
15
|
* @param defaultColorScheme - Fallback when `matchMedia` is unavailable (default: `'light'`)
|
|
11
16
|
* @returns 'light' or 'dark'
|
|
12
17
|
*/
|
|
13
|
-
declare function getPrefersColorScheme(defaultColorScheme?:
|
|
18
|
+
declare function getPrefersColorScheme(defaultColorScheme?: ColorScheme): ColorScheme;
|
|
14
19
|
//#endregion
|
|
15
20
|
export { getPrefersColorScheme };
|
|
16
21
|
//# sourceMappingURL=get-prefers-color-scheme.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-prefers-color-scheme.d.cts","names":[],"sources":["../../src/color-scheme/get-prefers-color-scheme.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-prefers-color-scheme.d.cts","names":[],"sources":["../../src/color-scheme/get-prefers-color-scheme.ts"],"sourcesContent":[],"mappings":";;;;;;AAeA;;;;;;;;;;;iBAAgB,qBAAA,sBAA0C,cAAwB"}
|
|
@@ -1,16 +1,21 @@
|
|
|
1
|
+
import { ColorScheme } from "./color-scheme.types.mjs";
|
|
2
|
+
|
|
1
3
|
//#region src/color-scheme/get-prefers-color-scheme.d.ts
|
|
4
|
+
|
|
2
5
|
/**
|
|
3
6
|
* Gets the current preferred color scheme.
|
|
4
7
|
* It can only be 'light' or 'dark'.
|
|
5
8
|
*
|
|
6
|
-
*
|
|
9
|
+
* Per {@link https://drafts.csswg.org/mediaqueries-5/#prefers-color-scheme Media Queries Level 5},
|
|
10
|
+
* the `prefers-color-scheme` media feature has only two valid values. Even if the browser
|
|
11
|
+
* preference is 'auto'/'device', it will return 'light' or 'dark'.
|
|
7
12
|
*
|
|
8
13
|
* When `matchMedia` is unavailable (e.g. SSR), returns `defaultColorScheme`.
|
|
9
14
|
*
|
|
10
15
|
* @param defaultColorScheme - Fallback when `matchMedia` is unavailable (default: `'light'`)
|
|
11
16
|
* @returns 'light' or 'dark'
|
|
12
17
|
*/
|
|
13
|
-
declare function getPrefersColorScheme(defaultColorScheme?:
|
|
18
|
+
declare function getPrefersColorScheme(defaultColorScheme?: ColorScheme): ColorScheme;
|
|
14
19
|
//#endregion
|
|
15
20
|
export { getPrefersColorScheme };
|
|
16
21
|
//# sourceMappingURL=get-prefers-color-scheme.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-prefers-color-scheme.d.mts","names":[],"sources":["../../src/color-scheme/get-prefers-color-scheme.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-prefers-color-scheme.d.mts","names":[],"sources":["../../src/color-scheme/get-prefers-color-scheme.ts"],"sourcesContent":[],"mappings":";;;;;;AAeA;;;;;;;;;;;iBAAgB,qBAAA,sBAA0C,cAAwB"}
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
* Gets the current preferred color scheme.
|
|
4
4
|
* It can only be 'light' or 'dark'.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
6
|
+
* Per {@link https://drafts.csswg.org/mediaqueries-5/#prefers-color-scheme Media Queries Level 5},
|
|
7
|
+
* the `prefers-color-scheme` media feature has only two valid values. Even if the browser
|
|
8
|
+
* preference is 'auto'/'device', it will return 'light' or 'dark'.
|
|
7
9
|
*
|
|
8
10
|
* When `matchMedia` is unavailable (e.g. SSR), returns `defaultColorScheme`.
|
|
9
11
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-prefers-color-scheme.mjs","names":[],"sources":["../../src/color-scheme/get-prefers-color-scheme.ts"],"sourcesContent":["/**\n * Gets the current preferred color scheme.\n * It can only be 'light' or 'dark'.\n *\n * Even if the browser preference is 'auto'/'device', it will return 'light' or 'dark'.\n *\n * When `matchMedia` is unavailable (e.g. SSR), returns `defaultColorScheme`.\n *\n * @param defaultColorScheme - Fallback when `matchMedia` is unavailable (default: `'light'`)\n * @returns 'light' or 'dark'\n */\nexport function getPrefersColorScheme(
|
|
1
|
+
{"version":3,"file":"get-prefers-color-scheme.mjs","names":[],"sources":["../../src/color-scheme/get-prefers-color-scheme.ts"],"sourcesContent":["import type { ColorScheme } from './color-scheme.types.ts'\n\n/**\n * Gets the current preferred color scheme.\n * It can only be 'light' or 'dark'.\n *\n * Per {@link https://drafts.csswg.org/mediaqueries-5/#prefers-color-scheme Media Queries Level 5},\n * the `prefers-color-scheme` media feature has only two valid values. Even if the browser\n * preference is 'auto'/'device', it will return 'light' or 'dark'.\n *\n * When `matchMedia` is unavailable (e.g. SSR), returns `defaultColorScheme`.\n *\n * @param defaultColorScheme - Fallback when `matchMedia` is unavailable (default: `'light'`)\n * @returns 'light' or 'dark'\n */\nexport function getPrefersColorScheme(defaultColorScheme: ColorScheme = 'light'): ColorScheme {\n\tif (typeof matchMedia === 'undefined') return defaultColorScheme\n\treturn matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark'\n}\n"],"mappings":";;;;;;;;;;;;;;AAeA,SAAgB,sBAAsB,qBAAkC,SAAsB;AAC7F,KAAI,OAAO,eAAe,YAAa,QAAO;AAC9C,QAAO,WAAW,gCAAgC,CAAC,UAAU,UAAU"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observe-prefers-color-scheme.cjs","names":[],"sources":["../../src/color-scheme/observe-prefers-color-scheme.ts"],"sourcesContent":["/**\n * Observes system color scheme preference changes and calls handlers when they occur.\n *\n * @param handler - A function that is called when the color scheme preference changes\n * @returns A cleanup function that removes all event listeners\n *\n * @example\n * ```ts\n * // Observe light/dark mode changes\n * const cleanup = observePrefersColorScheme((value) => console.log('Color scheme changed to:', value))\n *\n * // Later, to stop observing:\n * cleanup()\n * ```\n */\nexport function observePrefersColorScheme(handler: (value:
|
|
1
|
+
{"version":3,"file":"observe-prefers-color-scheme.cjs","names":[],"sources":["../../src/color-scheme/observe-prefers-color-scheme.ts"],"sourcesContent":["import type { ColorScheme } from './color-scheme.types.ts'\n\n/**\n * Observes system color scheme preference changes and calls handlers when they occur.\n *\n * @param handler - A function that is called when the color scheme preference changes\n * @returns A cleanup function that removes all event listeners\n *\n * @example\n * ```ts\n * // Observe light/dark mode changes\n * const cleanup = observePrefersColorScheme((value) => console.log('Color scheme changed to:', value))\n *\n * // Later, to stop observing:\n * cleanup()\n * ```\n */\nexport function observePrefersColorScheme(handler: (value: ColorScheme) => void) {\n\tconst m = globalThis.matchMedia('(prefers-color-scheme: light)')\n\tconst listener = (event: MediaQueryListEvent) => {\n\t\thandler(event.matches ? 'light' : 'dark')\n\t}\n\n\tm.addEventListener('change', listener)\n\treturn () => m.removeEventListener('change', listener)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,SAAgB,0BAA0B,SAAuC;CAChF,MAAM,IAAI,WAAW,WAAW,gCAAgC;CAChE,MAAM,YAAY,UAA+B;AAChD,UAAQ,MAAM,UAAU,UAAU,OAAO;;AAG1C,GAAE,iBAAiB,UAAU,SAAS;AACtC,cAAa,EAAE,oBAAoB,UAAU,SAAS"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { ColorScheme } from "./color-scheme.types.cjs";
|
|
2
|
+
|
|
1
3
|
//#region src/color-scheme/observe-prefers-color-scheme.d.ts
|
|
4
|
+
|
|
2
5
|
/**
|
|
3
6
|
* Observes system color scheme preference changes and calls handlers when they occur.
|
|
4
7
|
*
|
|
@@ -14,7 +17,7 @@
|
|
|
14
17
|
* cleanup()
|
|
15
18
|
* ```
|
|
16
19
|
*/
|
|
17
|
-
declare function observePrefersColorScheme(handler: (value:
|
|
20
|
+
declare function observePrefersColorScheme(handler: (value: ColorScheme) => void): () => void;
|
|
18
21
|
//#endregion
|
|
19
22
|
export { observePrefersColorScheme };
|
|
20
23
|
//# sourceMappingURL=observe-prefers-color-scheme.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observe-prefers-color-scheme.d.cts","names":[],"sources":["../../src/color-scheme/observe-prefers-color-scheme.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"observe-prefers-color-scheme.d.cts","names":[],"sources":["../../src/color-scheme/observe-prefers-color-scheme.ts"],"sourcesContent":[],"mappings":";;;;;;AAiBA;;;;;;;;;;;;;iBAAgB,yBAAA,kBAA2C"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { ColorScheme } from "./color-scheme.types.mjs";
|
|
2
|
+
|
|
1
3
|
//#region src/color-scheme/observe-prefers-color-scheme.d.ts
|
|
4
|
+
|
|
2
5
|
/**
|
|
3
6
|
* Observes system color scheme preference changes and calls handlers when they occur.
|
|
4
7
|
*
|
|
@@ -14,7 +17,7 @@
|
|
|
14
17
|
* cleanup()
|
|
15
18
|
* ```
|
|
16
19
|
*/
|
|
17
|
-
declare function observePrefersColorScheme(handler: (value:
|
|
20
|
+
declare function observePrefersColorScheme(handler: (value: ColorScheme) => void): () => void;
|
|
18
21
|
//#endregion
|
|
19
22
|
export { observePrefersColorScheme };
|
|
20
23
|
//# sourceMappingURL=observe-prefers-color-scheme.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observe-prefers-color-scheme.d.mts","names":[],"sources":["../../src/color-scheme/observe-prefers-color-scheme.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"observe-prefers-color-scheme.d.mts","names":[],"sources":["../../src/color-scheme/observe-prefers-color-scheme.ts"],"sourcesContent":[],"mappings":";;;;;;AAiBA;;;;;;;;;;;;;iBAAgB,yBAAA,kBAA2C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observe-prefers-color-scheme.mjs","names":[],"sources":["../../src/color-scheme/observe-prefers-color-scheme.ts"],"sourcesContent":["/**\n * Observes system color scheme preference changes and calls handlers when they occur.\n *\n * @param handler - A function that is called when the color scheme preference changes\n * @returns A cleanup function that removes all event listeners\n *\n * @example\n * ```ts\n * // Observe light/dark mode changes\n * const cleanup = observePrefersColorScheme((value) => console.log('Color scheme changed to:', value))\n *\n * // Later, to stop observing:\n * cleanup()\n * ```\n */\nexport function observePrefersColorScheme(handler: (value:
|
|
1
|
+
{"version":3,"file":"observe-prefers-color-scheme.mjs","names":[],"sources":["../../src/color-scheme/observe-prefers-color-scheme.ts"],"sourcesContent":["import type { ColorScheme } from './color-scheme.types.ts'\n\n/**\n * Observes system color scheme preference changes and calls handlers when they occur.\n *\n * @param handler - A function that is called when the color scheme preference changes\n * @returns A cleanup function that removes all event listeners\n *\n * @example\n * ```ts\n * // Observe light/dark mode changes\n * const cleanup = observePrefersColorScheme((value) => console.log('Color scheme changed to:', value))\n *\n * // Later, to stop observing:\n * cleanup()\n * ```\n */\nexport function observePrefersColorScheme(handler: (value: ColorScheme) => void) {\n\tconst m = globalThis.matchMedia('(prefers-color-scheme: light)')\n\tconst listener = (event: MediaQueryListEvent) => {\n\t\thandler(event.matches ? 'light' : 'dark')\n\t}\n\n\tm.addEventListener('change', listener)\n\treturn () => m.removeEventListener('change', listener)\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAiBA,SAAgB,0BAA0B,SAAuC;CAChF,MAAM,IAAI,WAAW,WAAW,gCAAgC;CAChE,MAAM,YAAY,UAA+B;AAChD,UAAQ,MAAM,UAAU,UAAU,OAAO;;AAG1C,GAAE,iBAAiB,UAAU,SAAS;AACtC,cAAa,EAAE,oBAAoB,UAAU,SAAS"}
|
package/dist/index.d.cts
CHANGED
|
@@ -9,6 +9,7 @@ import { ClassNameProps } from "./class-name/class-name-props.cjs";
|
|
|
9
9
|
import { clsx } from "./class-name/clsx.cjs";
|
|
10
10
|
import { JustClassName, JustClassNameFnProps, JustClassNameProps } from "./class-name/just-class-name.cjs";
|
|
11
11
|
import { resolveClassName } from "./class-name/resolve-class-name.cjs";
|
|
12
|
+
import { ColorScheme } from "./color-scheme/color-scheme.types.cjs";
|
|
12
13
|
import { getPrefersColorScheme } from "./color-scheme/get-prefers-color-scheme.cjs";
|
|
13
14
|
import { observePrefersColorScheme } from "./color-scheme/observe-prefers-color-scheme.cjs";
|
|
14
15
|
import { CSSProperties } from "./style/css-properties.cjs";
|
|
@@ -23,4 +24,4 @@ import { px2num } from "./units/px-2-num.cjs";
|
|
|
23
24
|
import { px2rem } from "./units/px-2-rem.cjs";
|
|
24
25
|
import { rem2px } from "./units/rem-2-px.cjs";
|
|
25
26
|
import { appendId } from "./utils/append-id.cjs";
|
|
26
|
-
export { CSSProperties, ClassNameProps, DataAttribute, JustChildren, JustChildrenFnProps, JustChildrenProps, JustClassName, JustClassNameFnProps, JustClassNameProps, JustStyle, JustStyleFnProps, JustStyleProps, StyleProps, appendId, clsx, defineCSSProperties, getAttribute, getCSSVariableValue, getDataAttribute, getPrefersColorScheme, getRemToPxScale, observeAttributes, observeDataAttributes, observePrefersColorScheme, px2num, px2rem, rem2px, resolveChildren, resolveClassName, resolveStyle, toDomStyle };
|
|
27
|
+
export { CSSProperties, ClassNameProps, ColorScheme, DataAttribute, JustChildren, JustChildrenFnProps, JustChildrenProps, JustClassName, JustClassNameFnProps, JustClassNameProps, JustStyle, JustStyleFnProps, JustStyleProps, StyleProps, appendId, clsx, defineCSSProperties, getAttribute, getCSSVariableValue, getDataAttribute, getPrefersColorScheme, getRemToPxScale, observeAttributes, observeDataAttributes, observePrefersColorScheme, px2num, px2rem, rem2px, resolveChildren, resolveClassName, resolveStyle, toDomStyle };
|
package/dist/index.d.mts
CHANGED
|
@@ -9,6 +9,7 @@ import { ClassNameProps } from "./class-name/class-name-props.mjs";
|
|
|
9
9
|
import { clsx } from "./class-name/clsx.mjs";
|
|
10
10
|
import { JustClassName, JustClassNameFnProps, JustClassNameProps } from "./class-name/just-class-name.mjs";
|
|
11
11
|
import { resolveClassName } from "./class-name/resolve-class-name.mjs";
|
|
12
|
+
import { ColorScheme } from "./color-scheme/color-scheme.types.mjs";
|
|
12
13
|
import { getPrefersColorScheme } from "./color-scheme/get-prefers-color-scheme.mjs";
|
|
13
14
|
import { observePrefersColorScheme } from "./color-scheme/observe-prefers-color-scheme.mjs";
|
|
14
15
|
import { CSSProperties } from "./style/css-properties.mjs";
|
|
@@ -23,4 +24,4 @@ import { px2num } from "./units/px-2-num.mjs";
|
|
|
23
24
|
import { px2rem } from "./units/px-2-rem.mjs";
|
|
24
25
|
import { rem2px } from "./units/rem-2-px.mjs";
|
|
25
26
|
import { appendId } from "./utils/append-id.mjs";
|
|
26
|
-
export { CSSProperties, ClassNameProps, DataAttribute, JustChildren, JustChildrenFnProps, JustChildrenProps, JustClassName, JustClassNameFnProps, JustClassNameProps, JustStyle, JustStyleFnProps, JustStyleProps, StyleProps, appendId, clsx, defineCSSProperties, getAttribute, getCSSVariableValue, getDataAttribute, getPrefersColorScheme, getRemToPxScale, observeAttributes, observeDataAttributes, observePrefersColorScheme, px2num, px2rem, rem2px, resolveChildren, resolveClassName, resolveStyle, toDomStyle };
|
|
27
|
+
export { CSSProperties, ClassNameProps, ColorScheme, DataAttribute, JustChildren, JustChildrenFnProps, JustChildrenProps, JustClassName, JustClassNameFnProps, JustClassNameProps, JustStyle, JustStyleFnProps, JustStyleProps, StyleProps, appendId, clsx, defineCSSProperties, getAttribute, getCSSVariableValue, getDataAttribute, getPrefersColorScheme, getRemToPxScale, observeAttributes, observeDataAttributes, observePrefersColorScheme, px2num, px2rem, rem2px, resolveChildren, resolveClassName, resolveStyle, toDomStyle };
|