@just-web/css 0.6.1 → 0.8.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/cjs/index.cjs +394 -0
- package/cjs/index.cjs.map +1 -0
- package/cjs/index.d.cts +412 -0
- package/cjs/index.d.cts.map +1 -0
- package/esm/index.d.mts +412 -0
- package/esm/index.d.mts.map +1 -0
- package/esm/index.mjs +378 -0
- package/esm/index.mjs.map +1 -0
- package/package.json +36 -35
- package/src/convertors/px_2_num.ts +17 -0
- package/src/index.ts +6 -2
- package/src/{css-properties/css-properties.ts → properties/css_properties.ts} +6 -2
- package/{cjs/css-properties/css-properties.d.ts → src/properties/properties.ts} +9 -4
- package/src/{css-properties → properties}/to_dom_style.ts +1 -1
- package/src/props/class-name.ts +1 -1
- package/src/props/style.ts +3 -3
- package/cjs/convertors/px_2_rem.d.ts +0 -21
- package/cjs/convertors/px_2_rem.js +0 -17
- package/cjs/convertors/rem_2_px.d.ts +0 -21
- package/cjs/convertors/rem_2_px.js +0 -17
- package/cjs/css-properties/css-properties.js +0 -9
- package/cjs/css-properties/to_dom_style.d.ts +0 -19
- package/cjs/css-properties/to_dom_style.js +0 -14
- package/cjs/globals.ctx.d.ts +0 -5
- package/cjs/globals.ctx.js +0 -18
- package/cjs/index.d.ts +0 -12
- package/cjs/index.js +0 -137
- package/cjs/package.json +0 -1
- package/cjs/props/class-name.d.ts +0 -11
- package/cjs/props/class-name.js +0 -1
- package/cjs/props/style.d.ts +0 -7
- package/cjs/props/style.js +0 -1
- package/cjs/tailwind.css +0 -1
- package/cjs/testing/log-panel.d.ts +0 -4
- package/cjs/testing/log-panel.js +0 -19
- package/cjs/testing/toggle-attribute-button.d.ts +0 -4
- package/cjs/testing/toggle-attribute-button.js +0 -28
- package/cjs/theme/class-name.d.ts +0 -41
- package/cjs/theme/class-name.js +0 -32
- package/cjs/theme/data-attribute.d.ts +0 -83
- package/cjs/theme/data-attribute.js +0 -33
- package/cjs/utils/attribute.d.ts +0 -36
- package/cjs/utils/attribute.js +0 -25
- package/cjs/utils/data-attribute.d.ts +0 -23
- package/cjs/utils/data-attribute.js +0 -15
- package/cjs/utils/get-css-prop-values.d.ts +0 -16
- package/cjs/utils/get-css-prop-values.js +0 -13
- package/cjs/utils/prefers-color-scheme.d.ts +0 -33
- package/cjs/utils/prefers-color-scheme.js +0 -29
- package/esm/convertors/px_2_rem.d.ts +0 -22
- package/esm/convertors/px_2_rem.d.ts.map +0 -1
- package/esm/convertors/px_2_rem.js +0 -26
- package/esm/convertors/px_2_rem.js.map +0 -1
- package/esm/convertors/rem_2_px.d.ts +0 -22
- package/esm/convertors/rem_2_px.d.ts.map +0 -1
- package/esm/convertors/rem_2_px.js +0 -26
- package/esm/convertors/rem_2_px.js.map +0 -1
- package/esm/css-properties/css-properties.d.ts +0 -27
- package/esm/css-properties/css-properties.d.ts.map +0 -1
- package/esm/css-properties/css-properties.js +0 -20
- package/esm/css-properties/css-properties.js.map +0 -1
- package/esm/css-properties/to_dom_style.d.ts +0 -20
- package/esm/css-properties/to_dom_style.d.ts.map +0 -1
- package/esm/css-properties/to_dom_style.js +0 -27
- package/esm/css-properties/to_dom_style.js.map +0 -1
- package/esm/globals.ctx.d.ts +0 -6
- package/esm/globals.ctx.d.ts.map +0 -1
- package/esm/globals.ctx.js +0 -13
- package/esm/globals.ctx.js.map +0 -1
- package/esm/index.d.ts +0 -13
- package/esm/index.d.ts.map +0 -1
- package/esm/index.js +0 -13
- package/esm/index.js.map +0 -1
- package/esm/props/class-name.d.ts +0 -12
- package/esm/props/class-name.d.ts.map +0 -1
- package/esm/props/class-name.js +0 -6
- package/esm/props/class-name.js.map +0 -1
- package/esm/props/style.d.ts +0 -8
- package/esm/props/style.d.ts.map +0 -1
- package/esm/props/style.js +0 -2
- package/esm/props/style.js.map +0 -1
- package/esm/testing/log-panel.d.ts +0 -5
- package/esm/testing/log-panel.d.ts.map +0 -1
- package/esm/testing/log-panel.js +0 -5
- package/esm/testing/log-panel.js.map +0 -1
- package/esm/testing/toggle-attribute-button.d.ts +0 -5
- package/esm/testing/toggle-attribute-button.d.ts.map +0 -1
- package/esm/testing/toggle-attribute-button.js +0 -19
- package/esm/testing/toggle-attribute-button.js.map +0 -1
- package/esm/theme/class-name.d.ts +0 -42
- package/esm/theme/class-name.d.ts.map +0 -1
- package/esm/theme/class-name.js +0 -56
- package/esm/theme/class-name.js.map +0 -1
- package/esm/theme/data-attribute.d.ts +0 -84
- package/esm/theme/data-attribute.d.ts.map +0 -1
- package/esm/theme/data-attribute.js +0 -27
- package/esm/theme/data-attribute.js.map +0 -1
- package/esm/utils/attribute.d.ts +0 -37
- package/esm/utils/attribute.d.ts.map +0 -1
- package/esm/utils/attribute.js +0 -53
- package/esm/utils/attribute.js.map +0 -1
- package/esm/utils/data-attribute.d.ts +0 -24
- package/esm/utils/data-attribute.d.ts.map +0 -1
- package/esm/utils/data-attribute.js +0 -30
- package/esm/utils/data-attribute.js.map +0 -1
- package/esm/utils/get-css-prop-values.d.ts +0 -17
- package/esm/utils/get-css-prop-values.d.ts.map +0 -1
- package/esm/utils/get-css-prop-values.js +0 -8
- package/esm/utils/get-css-prop-values.js.map +0 -1
- package/esm/utils/prefers-color-scheme.d.ts +0 -34
- package/esm/utils/prefers-color-scheme.d.ts.map +0 -1
- package/esm/utils/prefers-color-scheme.js +0 -54
- package/esm/utils/prefers-color-scheme.js.map +0 -1
- package/src/tailwind.css +0 -3
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Gets the theme based on a data attribute value.
|
|
3
|
-
*
|
|
4
|
-
* @param options - Configuration options
|
|
5
|
-
* @param options.themes - Record mapping theme keys to their data attribute values
|
|
6
|
-
* @param options.defaultTheme - Fallback theme key if attribute value doesn't match any theme
|
|
7
|
-
* @param options.attributeName - Name of the data attribute to check (must start with 'data-')
|
|
8
|
-
* @param options.allowCustom - Whether to allow custom themes value
|
|
9
|
-
* @returns The matching theme key, or defaultTheme if no match found
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* const themes = {
|
|
14
|
-
* light: 'light',
|
|
15
|
-
* dark: 'dark',
|
|
16
|
-
* system: 'system'
|
|
17
|
-
* }
|
|
18
|
-
*
|
|
19
|
-
* // Get theme from data-theme attribute
|
|
20
|
-
* const theme = getThemeByDataAttribute({
|
|
21
|
-
* themes,
|
|
22
|
-
* defaultTheme: 'system',
|
|
23
|
-
* attributeName: 'data-theme'
|
|
24
|
-
* })
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
export declare function getThemeByDataAttribute<Themes extends Record<string, string>>(options: {
|
|
28
|
-
attributeName: `data-${string}`;
|
|
29
|
-
defaultTheme?: keyof Themes | undefined;
|
|
30
|
-
themes: Themes;
|
|
31
|
-
element?: Element | undefined;
|
|
32
|
-
}): keyof Themes | undefined;
|
|
33
|
-
export declare function getThemeByDataAttribute<Themes extends Record<string, string>>(options: {
|
|
34
|
-
attributeName: `data-${string}`;
|
|
35
|
-
allowCustom: true | undefined;
|
|
36
|
-
defaultTheme?: keyof Themes | undefined;
|
|
37
|
-
themes: Themes;
|
|
38
|
-
element?: Element | undefined;
|
|
39
|
-
}): string | undefined;
|
|
40
|
-
/**
|
|
41
|
-
* Observes changes to a theme data attribute and calls a handler when it changes.
|
|
42
|
-
*
|
|
43
|
-
* @param options - Configuration options
|
|
44
|
-
* @param options.themes - Record mapping theme keys to their data attribute values
|
|
45
|
-
* @param options.handler - Callback function called with the new theme value or null when removed
|
|
46
|
-
* @param options.defaultTheme - Fallback theme key if attribute value doesn't match any theme
|
|
47
|
-
* @param options.attributeName - Name of the data attribute to observe (must start with 'data-')
|
|
48
|
-
* @returns A MutationObserver that can be disconnected to stop observing
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* ```ts
|
|
52
|
-
* const themes = {
|
|
53
|
-
* light: 'light',
|
|
54
|
-
* dark: 'dark'
|
|
55
|
-
* }
|
|
56
|
-
*
|
|
57
|
-
* // Observe data-theme attribute changes
|
|
58
|
-
* const observer = observeThemeByDataAttributes({
|
|
59
|
-
* themes,
|
|
60
|
-
* handler: (theme) => console.log('Theme changed to:', theme),
|
|
61
|
-
* defaultTheme: 'light',
|
|
62
|
-
* attributeName: 'data-theme'
|
|
63
|
-
* })
|
|
64
|
-
*
|
|
65
|
-
* // Stop observing
|
|
66
|
-
* observer.disconnect()
|
|
67
|
-
* ```
|
|
68
|
-
*/
|
|
69
|
-
export declare function observeThemeByDataAttributes<Themes extends Record<string, string>>(options: {
|
|
70
|
-
attributeName: `data-${string}`;
|
|
71
|
-
themes: Themes;
|
|
72
|
-
handler: (value: string | null) => void;
|
|
73
|
-
defaultTheme?: keyof Themes | undefined;
|
|
74
|
-
element?: Element | undefined;
|
|
75
|
-
}): MutationObserver;
|
|
76
|
-
export declare function observeThemeByDataAttributes<Themes extends Record<string, string>>(options: {
|
|
77
|
-
attributeName: `data-${string}`;
|
|
78
|
-
themes: Themes;
|
|
79
|
-
handler: (value: string | null) => void;
|
|
80
|
-
allowCustom: true | undefined;
|
|
81
|
-
defaultTheme?: keyof Themes | undefined;
|
|
82
|
-
element?: Element | undefined;
|
|
83
|
-
}): MutationObserver;
|
|
84
|
-
//# sourceMappingURL=data-attribute.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"data-attribute.d.ts","sourceRoot":"","sources":["../../src/theme/data-attribute.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE;IACvF,aAAa,EAAE,QAAQ,MAAM,EAAE,CAAA;IAC/B,YAAY,CAAC,EAAE,MAAM,MAAM,GAAG,SAAS,CAAA;IACvC,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAC7B,GAAG,MAAM,MAAM,GAAG,SAAS,CAAA;AAC5B,wBAAgB,uBAAuB,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE;IACvF,aAAa,EAAE,QAAQ,MAAM,EAAE,CAAA;IAC/B,WAAW,EAAE,IAAI,GAAG,SAAS,CAAA;IAC7B,YAAY,CAAC,EAAE,MAAM,MAAM,GAAG,SAAS,CAAA;IACvC,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAC7B,GAAG,MAAM,GAAG,SAAS,CAAA;AActB;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE;IAC5F,aAAa,EAAE,QAAQ,MAAM,EAAE,CAAA;IAC/B,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAA;IACvC,YAAY,CAAC,EAAE,MAAM,MAAM,GAAG,SAAS,CAAA;IACvC,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAC7B,GAAG,gBAAgB,CAAA;AACpB,wBAAgB,4BAA4B,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE;IAC5F,aAAa,EAAE,QAAQ,MAAM,EAAE,CAAA;IAC/B,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAA;IACvC,WAAW,EAAE,IAAI,GAAG,SAAS,CAAA;IAC7B,YAAY,CAAC,EAAE,MAAM,MAAM,GAAG,SAAS,CAAA;IACvC,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAC7B,GAAG,gBAAgB,CAAA"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { findKey } from 'type-plus';
|
|
2
|
-
import { getDataAttribute, observeDataAttributes } from "../utils/data-attribute.js";
|
|
3
|
-
export function getThemeByDataAttribute(options) {
|
|
4
|
-
const value = getDataAttribute(options.attributeName, options.element) ?? undefined;
|
|
5
|
-
const theme = findKey(options.themes, (theme) => options.themes[theme] === value);
|
|
6
|
-
return theme ?? options.defaultTheme ?? (options.allowCustom ? value : undefined);
|
|
7
|
-
}
|
|
8
|
-
export function observeThemeByDataAttributes(options) {
|
|
9
|
-
return observeDataAttributes({
|
|
10
|
-
[options.attributeName]: (value) => {
|
|
11
|
-
if (value === null) {
|
|
12
|
-
options.handler(options.defaultTheme ?? null);
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
for (const name in options.themes) {
|
|
16
|
-
if (options.themes[name] === value) {
|
|
17
|
-
options.handler(name);
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
if (options.allowCustom) {
|
|
22
|
-
options.handler(value);
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
}, options.element);
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=data-attribute.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"data-attribute.js","sourceRoot":"","sources":["../../src/theme/data-attribute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AAyCpF,MAAM,UAAU,uBAAuB,CAAwC,OAM9E;IACA,MAAM,KAAK,GAAG,gBAAgB,CAAC,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,SAAS,CAAA;IACnF,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,CAAA;IAEjF,OAAO,KAAK,IAAI,OAAO,CAAC,YAAY,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;AAClF,CAAC;AA8CD,MAAM,UAAU,4BAA4B,CAAwC,OAOnF;IACA,OAAO,qBAAqB,CAC3B;QACC,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC,KAAoB,EAAE,EAAE;YACjD,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;gBACpB,OAAO,CAAC,OAAO,CAAE,OAAO,CAAC,YAAuB,IAAI,IAAI,CAAC,CAAA;gBACzD,OAAM;YACP,CAAC;YAED,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;gBACnC,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,KAAK,EAAE,CAAC;oBACpC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;oBACrB,OAAM;gBACP,CAAC;YACF,CAAC;YAED,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;gBACzB,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;YACvB,CAAC;QACF,CAAC;KACD,EACD,OAAO,CAAC,OAAO,CACf,CAAA;AACF,CAAC"}
|
package/esm/utils/attribute.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Gets the value of an attribute from an element.
|
|
3
|
-
*
|
|
4
|
-
* @param qualifiedName - The name of the attribute to get
|
|
5
|
-
* @param element - The element to get the attribute from. Defaults to `document.documentElement`
|
|
6
|
-
* @returns The attribute value cast to type T, or null if the attribute doesn't exist
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* // Get theme from document root
|
|
11
|
-
* const theme = getAttribute('data-theme')
|
|
12
|
-
*
|
|
13
|
-
* // Get data-testid from a specific element
|
|
14
|
-
* const testId = getAttribute('data-testid', element)
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
export declare function getAttribute<T extends string>(qualifiedName: T, element?: Element | undefined): string | null;
|
|
18
|
-
/**
|
|
19
|
-
* Observes attributes changes on an element and calls corresponding handlers.
|
|
20
|
-
*
|
|
21
|
-
* @param handlers - An object mapping attribute names to handler functions.
|
|
22
|
-
* @param element - The element to observe. Defaults to `document.documentElement`.
|
|
23
|
-
* @returns {MutationObserver} The observer instance, which can be used to disconnect the observer.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```ts
|
|
27
|
-
* const observer = observeAttributes({
|
|
28
|
-
* 'data-theme': (attr, value) => console.log(`Theme changed to: ${value}`),
|
|
29
|
-
* 'class': (attr, value) => console.log(`class changed to: ${value}`)
|
|
30
|
-
* });
|
|
31
|
-
*
|
|
32
|
-
* // Later, to stop observing:
|
|
33
|
-
* observer.disconnect();
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export declare function observeAttributes<T extends string>(handlers: Record<string, (value: T | null) => void>, element?: Element | undefined): MutationObserver;
|
|
37
|
-
//# sourceMappingURL=attribute.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"attribute.d.ts","sourceRoot":"","sources":["../../src/utils/attribute.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAC5C,aAAa,EAAE,CAAC,EAChB,OAAO,GAAE,OAAO,GAAG,SAAoC,iBAGvD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,EACjD,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,KAAK,IAAI,CAAC,EACnD,OAAO,GAAE,OAAO,GAAG,SAAoC,oBAcvD"}
|
package/esm/utils/attribute.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { ctx } from "../globals.ctx.js";
|
|
2
|
-
/**
|
|
3
|
-
* Gets the value of an attribute from an element.
|
|
4
|
-
*
|
|
5
|
-
* @param qualifiedName - The name of the attribute to get
|
|
6
|
-
* @param element - The element to get the attribute from. Defaults to `document.documentElement`
|
|
7
|
-
* @returns The attribute value cast to type T, or null if the attribute doesn't exist
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* // Get theme from document root
|
|
12
|
-
* const theme = getAttribute('data-theme')
|
|
13
|
-
*
|
|
14
|
-
* // Get data-testid from a specific element
|
|
15
|
-
* const testId = getAttribute('data-testid', element)
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export function getAttribute(qualifiedName, element = ctx.getDocumentElement()) {
|
|
19
|
-
return element?.getAttribute(qualifiedName);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Observes attributes changes on an element and calls corresponding handlers.
|
|
23
|
-
*
|
|
24
|
-
* @param handlers - An object mapping attribute names to handler functions.
|
|
25
|
-
* @param element - The element to observe. Defaults to `document.documentElement`.
|
|
26
|
-
* @returns {MutationObserver} The observer instance, which can be used to disconnect the observer.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```ts
|
|
30
|
-
* const observer = observeAttributes({
|
|
31
|
-
* 'data-theme': (attr, value) => console.log(`Theme changed to: ${value}`),
|
|
32
|
-
* 'class': (attr, value) => console.log(`class changed to: ${value}`)
|
|
33
|
-
* });
|
|
34
|
-
*
|
|
35
|
-
* // Later, to stop observing:
|
|
36
|
-
* observer.disconnect();
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
export function observeAttributes(handlers, element = ctx.getDocumentElement()) {
|
|
40
|
-
const observer = new MutationObserver((mutations) => {
|
|
41
|
-
for (const mutation of mutations) {
|
|
42
|
-
const attribute = mutation.attributeName;
|
|
43
|
-
const value = element.getAttribute(attribute);
|
|
44
|
-
handlers[attribute]?.(value);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
observer.observe(element, {
|
|
48
|
-
attributes: true,
|
|
49
|
-
attributeFilter: Object.keys(handlers),
|
|
50
|
-
});
|
|
51
|
-
return observer;
|
|
52
|
-
}
|
|
53
|
-
//# sourceMappingURL=attribute.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"attribute.js","sourceRoot":"","sources":["../../src/utils/attribute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AAEvC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,YAAY,CAC3B,aAAgB,EAChB,UAA+B,GAAG,CAAC,kBAAkB,EAAE;IAEvD,OAAO,OAAO,EAAE,YAAY,CAAC,aAAa,CAAC,CAAA;AAC5C,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,iBAAiB,CAChC,QAAmD,EACnD,UAA+B,GAAG,CAAC,kBAAkB,EAAE;IAEvD,MAAM,QAAQ,GAAG,IAAI,gBAAgB,CAAC,CAAC,SAAS,EAAE,EAAE;QACnD,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;YAClC,MAAM,SAAS,GAAG,QAAQ,CAAC,aAAc,CAAA;YACzC,MAAM,KAAK,GAAG,OAAO,CAAC,YAAY,CAAC,SAAS,CAAa,CAAA;YACzD,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,CAAC,CAAA;QAC7B,CAAC;IACF,CAAC,CAAC,CAAA;IACF,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE;QACzB,UAAU,EAAE,IAAI;QAChB,eAAe,EAAE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;KACtC,CAAC,CAAA;IACF,OAAO,QAAQ,CAAA;AAChB,CAAC"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export declare function getDataAttribute<T extends `data-${string}`>(qualifiedName: T, element?: Element | undefined): string | null;
|
|
2
|
-
/**
|
|
3
|
-
* Observes changes to `data-*` attributes on an element and calls corresponding handlers.
|
|
4
|
-
*
|
|
5
|
-
* @param options - Configuration options
|
|
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`
|
|
8
|
-
* @returns {MutationObserver} The observer instance, which can be used to disconnect the observer
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```ts
|
|
12
|
-
* const observer = observeDataAttributes({
|
|
13
|
-
* handlers: {
|
|
14
|
-
* 'data-theme': (value) => console.log(`Theme changed to: ${value}`),
|
|
15
|
-
* 'data-mode': (value) => console.log(`Mode changed to: ${value}`)
|
|
16
|
-
* }
|
|
17
|
-
* });
|
|
18
|
-
*
|
|
19
|
-
* // Later, to stop observing:
|
|
20
|
-
* observer.disconnect();
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export declare function observeDataAttributes<T extends string, K extends `data-${string}`>(handlers: Record<K, (value: T | null) => void>, element?: Element | undefined): MutationObserver;
|
|
24
|
-
//# sourceMappingURL=data-attribute.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"data-attribute.d.ts","sourceRoot":"","sources":["../../src/utils/data-attribute.ts"],"names":[],"mappings":"AAGA,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,QAAQ,MAAM,EAAE,EAC1D,aAAa,EAAE,CAAC,EAChB,OAAO,GAAE,OAAO,GAAG,SAAoC,iBAGvD;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,QAAQ,MAAM,EAAE,EACjF,QAAQ,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,KAAK,IAAI,CAAC,EAC9C,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,oBAG7B"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { ctx } from "../globals.ctx.js";
|
|
2
|
-
import { getAttribute, observeAttributes } from "./attribute.js";
|
|
3
|
-
export function getDataAttribute(qualifiedName, element = ctx.getDocumentElement()) {
|
|
4
|
-
return getAttribute(qualifiedName, element);
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Observes changes to `data-*` attributes on an element and calls corresponding handlers.
|
|
8
|
-
*
|
|
9
|
-
* @param options - Configuration options
|
|
10
|
-
* @param options.handlers - An object mapping `data-*` attribute names to handler functions.
|
|
11
|
-
* @param options.element - The element to observe. Defaults to `document.documentElement`
|
|
12
|
-
* @returns {MutationObserver} The observer instance, which can be used to disconnect the observer
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```ts
|
|
16
|
-
* const observer = observeDataAttributes({
|
|
17
|
-
* handlers: {
|
|
18
|
-
* 'data-theme': (value) => console.log(`Theme changed to: ${value}`),
|
|
19
|
-
* 'data-mode': (value) => console.log(`Mode changed to: ${value}`)
|
|
20
|
-
* }
|
|
21
|
-
* });
|
|
22
|
-
*
|
|
23
|
-
* // Later, to stop observing:
|
|
24
|
-
* observer.disconnect();
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
export function observeDataAttributes(handlers, element) {
|
|
28
|
-
return observeAttributes(handlers, element);
|
|
29
|
-
}
|
|
30
|
-
//# sourceMappingURL=data-attribute.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"data-attribute.js","sourceRoot":"","sources":["../../src/utils/data-attribute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAEhE,MAAM,UAAU,gBAAgB,CAC/B,aAAgB,EAChB,UAA+B,GAAG,CAAC,kBAAkB,EAAE;IAEvD,OAAO,YAAY,CAAC,aAAa,EAAE,OAAO,CAAC,CAAA;AAC5C,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,qBAAqB,CACpC,QAA8C,EAC9C,OAA6B;IAE7B,OAAO,iBAAiB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;AAC5C,CAAC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { CreateTuple } from 'type-plus';
|
|
2
|
-
/**
|
|
3
|
-
* Retrieves CSS custom property values from the specified element.
|
|
4
|
-
*
|
|
5
|
-
* @param element - The HTML element to get property values from
|
|
6
|
-
* @param props - CSS custom property names to retrieve, must be in the format `--property-name`
|
|
7
|
-
* @returns Array of property values corresponding to the requested custom properties
|
|
8
|
-
*/
|
|
9
|
-
export declare function getCSSPropValues<Props extends Array<`--${string}`>>(element: HTMLElement, ...props: Props): CreateTuple<Props['length'], string>;
|
|
10
|
-
/**
|
|
11
|
-
* Retrieves CSS custom property values from `document.body`.
|
|
12
|
-
*
|
|
13
|
-
* @param props - CSS custom property names to retrieve, must be in the format `--property-name`
|
|
14
|
-
* @returns Array of property values corresponding to the requested custom properties
|
|
15
|
-
*/
|
|
16
|
-
export declare function getCSSPropValues<Props extends Array<`--${string}`>>(...props: Props): CreateTuple<Props['length'], string>;
|
|
17
|
-
//# sourceMappingURL=get-css-prop-values.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-css-prop-values.d.ts","sourceRoot":"","sources":["../../src/utils/get-css-prop-values.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAE5C;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,SAAS,KAAK,CAAC,KAAK,MAAM,EAAE,CAAC,EAClE,OAAO,EAAE,WAAW,EACpB,GAAG,KAAK,EAAE,KAAK,GACb,WAAW,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAA;AACvC;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,SAAS,KAAK,CAAC,KAAK,MAAM,EAAE,CAAC,EAClE,GAAG,KAAK,EAAE,KAAK,GACb,WAAW,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAA"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export function getCSSPropValues(element, ...props) {
|
|
2
|
-
if (typeof element === 'string') {
|
|
3
|
-
return getCSSPropValues(globalThis.document.body, element, ...props);
|
|
4
|
-
}
|
|
5
|
-
const style = globalThis.getComputedStyle(element);
|
|
6
|
-
return props.map((v) => style.getPropertyValue(v));
|
|
7
|
-
}
|
|
8
|
-
//# sourceMappingURL=get-css-prop-values.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-css-prop-values.js","sourceRoot":"","sources":["../../src/utils/get-css-prop-values.ts"],"names":[],"mappings":"AAsBA,MAAM,UAAU,gBAAgB,CAAqC,OAAgB,EAAE,GAAG,KAAY;IACrG,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QACjC,OAAO,gBAAgB,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAwB,EAAE,GAAG,KAAK,CAAC,CAAA;IACtF,CAAC;IACD,MAAM,KAAK,GAAG,UAAU,CAAC,gBAAgB,CAAC,OAAsB,CAAC,CAAA;IACjE,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAQ,CAAA;AAC1D,CAAC"}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Observes system color scheme preference changes and calls handlers when they occur.
|
|
3
|
-
*
|
|
4
|
-
* @param themes - An object mapping theme names to handler functions that are called when that theme is activated
|
|
5
|
-
* @returns A cleanup function that removes all event listeners
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* // Observe light/dark mode changes
|
|
10
|
-
* const cleanup = observePrefersColorScheme({
|
|
11
|
-
* light: (theme) => console.log('Light mode activated'),
|
|
12
|
-
* dark: (theme) => console.log('Dark mode activated')
|
|
13
|
-
* })
|
|
14
|
-
*
|
|
15
|
-
* // Later, to stop observing:
|
|
16
|
-
* cleanup()
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
export declare function observePrefersColorScheme<T extends string>(themes: Record<T, (value: T | null) => void>): () => void;
|
|
20
|
-
/**
|
|
21
|
-
* Gets the current preferred color theme from the system settings.
|
|
22
|
-
*
|
|
23
|
-
* @param themes - A list of theme names to check against the system preference
|
|
24
|
-
* @returns The first matching theme from the provided list, or null if none match
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```ts
|
|
28
|
-
* // Check if system prefers light or dark mode
|
|
29
|
-
* const theme = getPrefersColorTheme('light', 'dark')
|
|
30
|
-
* // Returns 'light', 'dark', or null
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
export declare function getPrefersColorTheme<T extends string>(...themes: T[]): T | null;
|
|
34
|
-
//# sourceMappingURL=prefers-color-scheme.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prefers-color-scheme.d.ts","sourceRoot":"","sources":["../../src/utils/prefers-color-scheme.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,KAAK,IAAI,CAAC,cAkBvG;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,EAAE,YAEpE"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { mapKey } from 'type-plus';
|
|
2
|
-
import { ctx } from "../globals.ctx.js";
|
|
3
|
-
/**
|
|
4
|
-
* Observes system color scheme preference changes and calls handlers when they occur.
|
|
5
|
-
*
|
|
6
|
-
* @param themes - An object mapping theme names to handler functions that are called when that theme is activated
|
|
7
|
-
* @returns A cleanup function that removes all event listeners
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* // Observe light/dark mode changes
|
|
12
|
-
* const cleanup = observePrefersColorScheme({
|
|
13
|
-
* light: (theme) => console.log('Light mode activated'),
|
|
14
|
-
* dark: (theme) => console.log('Dark mode activated')
|
|
15
|
-
* })
|
|
16
|
-
*
|
|
17
|
-
* // Later, to stop observing:
|
|
18
|
-
* cleanup()
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export function observePrefersColorScheme(themes) {
|
|
22
|
-
const removers = mapKey(themes, (t) => {
|
|
23
|
-
const m = ctx.matchMedia(`(prefers-color-scheme: ${t})`);
|
|
24
|
-
const listener = (event) => {
|
|
25
|
-
if (event.matches) {
|
|
26
|
-
themes[t]?.(t);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
m.addEventListener('change', listener);
|
|
30
|
-
return () => m.removeEventListener('change', listener);
|
|
31
|
-
});
|
|
32
|
-
return () => {
|
|
33
|
-
for (const remover of removers) {
|
|
34
|
-
remover();
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Gets the current preferred color theme from the system settings.
|
|
40
|
-
*
|
|
41
|
-
* @param themes - A list of theme names to check against the system preference
|
|
42
|
-
* @returns The first matching theme from the provided list, or null if none match
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* ```ts
|
|
46
|
-
* // Check if system prefers light or dark mode
|
|
47
|
-
* const theme = getPrefersColorTheme('light', 'dark')
|
|
48
|
-
* // Returns 'light', 'dark', or null
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
export function getPrefersColorTheme(...themes) {
|
|
52
|
-
return themes.find((theme) => ctx.matchMedia(`(prefers-color-scheme: ${theme})`).matches) ?? null;
|
|
53
|
-
}
|
|
54
|
-
//# sourceMappingURL=prefers-color-scheme.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prefers-color-scheme.js","sourceRoot":"","sources":["../../src/utils/prefers-color-scheme.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAClC,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AAEvC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,yBAAyB,CAAmB,MAA4C;IACvG,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE;QACrC,MAAM,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC,0BAA0B,CAAW,GAAG,CAAC,CAAA;QAClE,MAAM,QAAQ,GAAG,CAAC,KAA0B,EAAE,EAAE;YAC/C,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;gBACnB,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;YACf,CAAC;QACF,CAAC,CAAA;QAED,CAAC,CAAC,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;QACtC,OAAO,GAAG,EAAE,CAAC,CAAC,CAAC,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;IACvD,CAAC,CAAC,CAAA;IAEF,OAAO,GAAG,EAAE;QACX,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAChC,OAAO,EAAE,CAAA;QACV,CAAC;IACF,CAAC,CAAA;AACF,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,oBAAoB,CAAmB,GAAG,MAAW;IACpE,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,0BAA0B,KAAK,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,IAAI,CAAA;AAClG,CAAC"}
|
package/src/tailwind.css
DELETED