@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
package/esm/index.d.mts
ADDED
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
import { CreateTuple } from "type-plus";
|
|
2
|
+
import { Properties as Properties$1 } from "csstype";
|
|
3
|
+
export * from "csstype";
|
|
4
|
+
|
|
5
|
+
//#region src/convertors/px_2_num.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Converts pixel values to numbers.
|
|
9
|
+
*
|
|
10
|
+
* @param px - The pixel value to convert. Can be a number or string (e.g. '16px' or '16')
|
|
11
|
+
* @returns The numeric value
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* px2num(16) // 16
|
|
16
|
+
* px2num('32px') // 32
|
|
17
|
+
* px2num('12.5px') // 12.5
|
|
18
|
+
* px2num('0px') // 0
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare function px2num(px: number | string | undefined): number;
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/convertors/px_2_rem.d.ts
|
|
24
|
+
/**
|
|
25
|
+
* Converts pixel values to rem units.
|
|
26
|
+
*
|
|
27
|
+
* @param px - The pixel value to convert. Can be a number or string (e.g. '16px' or '16')
|
|
28
|
+
* @param options - Optional configuration
|
|
29
|
+
* @param options.base - Base pixel value to calculate rem units from. Defaults to 16
|
|
30
|
+
* @param options.precision - Number of decimal places in the output. Defaults to 4
|
|
31
|
+
* @returns The converted value as a string with 'rem' units
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* px2rem(16) // '1.0000'
|
|
36
|
+
* px2rem('32px') // '2.0000'
|
|
37
|
+
* px2rem(20, { base: 20 }) // '1.0000'
|
|
38
|
+
* px2rem(13, { precision: 2 }) // '0.81'
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
declare function px2rem(px: number | string, options?: {
|
|
42
|
+
base?: number | undefined;
|
|
43
|
+
precision?: number | undefined;
|
|
44
|
+
}): number;
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/convertors/rem_2_px.d.ts
|
|
47
|
+
/**
|
|
48
|
+
* Converts rem values to pixel units.
|
|
49
|
+
*
|
|
50
|
+
* @param rem - The rem value to convert. Can be a number or string (e.g. '1rem' or '1')
|
|
51
|
+
* @param options - Optional configuration
|
|
52
|
+
* @param options.base - Base pixel value to calculate pixels from. Defaults to 16
|
|
53
|
+
* @param options.precision - Number of decimal places in the output. Defaults to 4
|
|
54
|
+
* @returns The converted value as a string with 'px' units
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* rem2px(1) // '16.0000'
|
|
59
|
+
* rem2px('2rem') // '32.0000'
|
|
60
|
+
* rem2px(1, { base: 20 }) // '20.0000'
|
|
61
|
+
* rem2px(0.8125, { precision: 2 }) // '13.00'
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
declare function rem2px(rem: number | string, options?: {
|
|
65
|
+
base?: number | undefined;
|
|
66
|
+
precision?: number | undefined;
|
|
67
|
+
}): number;
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/properties/css_properties.d.ts
|
|
70
|
+
/**
|
|
71
|
+
* Extends CSS properties to include custom properties.
|
|
72
|
+
* Allows for string or number values for standard properties,
|
|
73
|
+
* and string values for custom properties with '--' prefix.
|
|
74
|
+
*
|
|
75
|
+
* @deprecated Use `Properties` instead.
|
|
76
|
+
*/
|
|
77
|
+
interface CSSProperties extends Properties$1<string | number> {
|
|
78
|
+
[k: `--${string}`]: string;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Defines CSS properties including custom properties.
|
|
82
|
+
* This function is used to properly type CSS properties when defining styles,
|
|
83
|
+
* especially when using CSS custom properties (variables).
|
|
84
|
+
*
|
|
85
|
+
* @deprecated Use `defineProperties` instead.
|
|
86
|
+
*
|
|
87
|
+
* @param style - CSS properties object that can include both standard and custom properties
|
|
88
|
+
* @returns The same style object with proper typing
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* defineCSSProperties({
|
|
93
|
+
* color: 'red',
|
|
94
|
+
* '--custom-color': '#ff0000'
|
|
95
|
+
* })
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
declare function defineCSSProperties(style: CSSProperties): any;
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/properties/properties.d.ts
|
|
101
|
+
/**
|
|
102
|
+
* Extends CSS properties to include custom properties.
|
|
103
|
+
* Allows for string or number values for standard properties,
|
|
104
|
+
* and string values for custom properties with '--' prefix.
|
|
105
|
+
*/
|
|
106
|
+
interface Properties<TLength = 0 | (string & {}), TTime = string & {}> extends Properties$1<TLength, TTime> {
|
|
107
|
+
[k: `--${string}`]: string;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Defines CSS properties including custom properties.
|
|
111
|
+
* This function is used to properly type CSS properties when defining styles,
|
|
112
|
+
* especially when using CSS custom properties (variables).
|
|
113
|
+
*
|
|
114
|
+
* @param style - CSS properties object that can include both standard and custom properties
|
|
115
|
+
* @returns The same style object with proper typing
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* defineCSSProperties({
|
|
120
|
+
* color: 'red',
|
|
121
|
+
* '--custom-color': '#ff0000'
|
|
122
|
+
* })
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
declare function defineProperties<TLength = 0 | (string & {}), TTime = string & {}>(style: Properties<TLength, TTime>): Properties;
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src/properties/to_dom_style.d.ts
|
|
128
|
+
/**
|
|
129
|
+
* Converts React-style CSS properties to DOM style properties.
|
|
130
|
+
* This function handles both standard CSS properties and custom properties,
|
|
131
|
+
* ensuring proper formatting for DOM style application.
|
|
132
|
+
*
|
|
133
|
+
* @param style - React-style CSS properties object
|
|
134
|
+
* @returns CSSStyleDeclaration compatible object for DOM style application
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* const domStyle = toDOMStyle({
|
|
139
|
+
* backgroundColor: 'red',
|
|
140
|
+
* '--custom-color': '#ff0000'
|
|
141
|
+
* })
|
|
142
|
+
* element.style = domStyle
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
declare function toDOMStyle(style: CSSProperties | undefined): Partial<CSSStyleDeclaration> | undefined;
|
|
146
|
+
//#endregion
|
|
147
|
+
//#region src/props/class-name.d.ts
|
|
148
|
+
/**
|
|
149
|
+
* Note that `className` could be specific to ReactJS.
|
|
150
|
+
* So this type may be misplaced in this package.
|
|
151
|
+
*/
|
|
152
|
+
/**
|
|
153
|
+
* Interface for component props that include a className property.
|
|
154
|
+
* The className property accepts a string value for CSS class names.
|
|
155
|
+
*/
|
|
156
|
+
type ClassNameProps = {
|
|
157
|
+
className?: string | undefined;
|
|
158
|
+
};
|
|
159
|
+
//#endregion
|
|
160
|
+
//#region src/props/style.d.ts
|
|
161
|
+
/**
|
|
162
|
+
* Interface for component props that include a style property.
|
|
163
|
+
*/
|
|
164
|
+
type StyleProps<TLength = 0 | (string & {}), TTime = string & {}> = {
|
|
165
|
+
style?: Properties<TLength, TTime> | undefined;
|
|
166
|
+
};
|
|
167
|
+
//#endregion
|
|
168
|
+
//#region src/theme/class-name.d.ts
|
|
169
|
+
/**
|
|
170
|
+
* Gets the current theme by checking element class names against a themes map.
|
|
171
|
+
*
|
|
172
|
+
* @param options - Configuration options
|
|
173
|
+
* @param options.themes - Record mapping theme keys to their class name values
|
|
174
|
+
* @param options.defaultTheme - Fallback theme key if no matching class is found
|
|
175
|
+
* @param options.element - Element to check classes on (defaults to document.documentElement)
|
|
176
|
+
* @returns The matching theme key or defaultTheme if no match found
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```ts
|
|
180
|
+
* const themes = {
|
|
181
|
+
* light: 'theme-light',
|
|
182
|
+
* dark: 'theme-dark'
|
|
183
|
+
* }
|
|
184
|
+
*
|
|
185
|
+
* // Get current theme from document.documentElement
|
|
186
|
+
* const theme = getThemeByClassName({
|
|
187
|
+
* themes,
|
|
188
|
+
* defaultTheme: 'light'
|
|
189
|
+
* })
|
|
190
|
+
*
|
|
191
|
+
* // Get theme from specific element
|
|
192
|
+
* const theme = getThemeByClassName({
|
|
193
|
+
* themes,
|
|
194
|
+
* element: myElement,
|
|
195
|
+
* defaultTheme: 'light'
|
|
196
|
+
* })
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
declare function getThemeByClassName<Themes extends Record<string, string>>(options: {
|
|
200
|
+
themes: Themes;
|
|
201
|
+
defaultTheme?: keyof Themes | undefined;
|
|
202
|
+
element?: Element | undefined;
|
|
203
|
+
}): keyof Themes | undefined;
|
|
204
|
+
declare function observeThemeByClassName<Themes extends Record<string, string>>(options: {
|
|
205
|
+
themes: Themes;
|
|
206
|
+
handler: (value: string | undefined) => void;
|
|
207
|
+
defaultTheme?: keyof Themes | undefined;
|
|
208
|
+
element?: Element | undefined;
|
|
209
|
+
}): MutationObserver;
|
|
210
|
+
//#endregion
|
|
211
|
+
//#region src/theme/data-attribute.d.ts
|
|
212
|
+
/**
|
|
213
|
+
* Gets the theme based on a data attribute value.
|
|
214
|
+
*
|
|
215
|
+
* @param options - Configuration options
|
|
216
|
+
* @param options.themes - Record mapping theme keys to their data attribute values
|
|
217
|
+
* @param options.defaultTheme - Fallback theme key if attribute value doesn't match any theme
|
|
218
|
+
* @param options.attributeName - Name of the data attribute to check (must start with 'data-')
|
|
219
|
+
* @param options.allowCustom - Whether to allow custom themes value
|
|
220
|
+
* @returns The matching theme key, or defaultTheme if no match found
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```ts
|
|
224
|
+
* const themes = {
|
|
225
|
+
* light: 'light',
|
|
226
|
+
* dark: 'dark',
|
|
227
|
+
* system: 'system'
|
|
228
|
+
* }
|
|
229
|
+
*
|
|
230
|
+
* // Get theme from data-theme attribute
|
|
231
|
+
* const theme = getThemeByDataAttribute({
|
|
232
|
+
* themes,
|
|
233
|
+
* defaultTheme: 'system',
|
|
234
|
+
* attributeName: 'data-theme'
|
|
235
|
+
* })
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
declare function getThemeByDataAttribute<Themes extends Record<string, string>>(options: {
|
|
239
|
+
attributeName: `data-${string}`;
|
|
240
|
+
defaultTheme?: keyof Themes | undefined;
|
|
241
|
+
themes: Themes;
|
|
242
|
+
element?: Element | undefined;
|
|
243
|
+
}): keyof Themes | undefined;
|
|
244
|
+
declare function getThemeByDataAttribute<Themes extends Record<string, string>>(options: {
|
|
245
|
+
attributeName: `data-${string}`;
|
|
246
|
+
allowCustom: true | undefined;
|
|
247
|
+
defaultTheme?: keyof Themes | undefined;
|
|
248
|
+
themes: Themes;
|
|
249
|
+
element?: Element | undefined;
|
|
250
|
+
}): string | undefined;
|
|
251
|
+
/**
|
|
252
|
+
* Observes changes to a theme data attribute and calls a handler when it changes.
|
|
253
|
+
*
|
|
254
|
+
* @param options - Configuration options
|
|
255
|
+
* @param options.themes - Record mapping theme keys to their data attribute values
|
|
256
|
+
* @param options.handler - Callback function called with the new theme value or null when removed
|
|
257
|
+
* @param options.defaultTheme - Fallback theme key if attribute value doesn't match any theme
|
|
258
|
+
* @param options.attributeName - Name of the data attribute to observe (must start with 'data-')
|
|
259
|
+
* @returns A MutationObserver that can be disconnected to stop observing
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* ```ts
|
|
263
|
+
* const themes = {
|
|
264
|
+
* light: 'light',
|
|
265
|
+
* dark: 'dark'
|
|
266
|
+
* }
|
|
267
|
+
*
|
|
268
|
+
* // Observe data-theme attribute changes
|
|
269
|
+
* const observer = observeThemeByDataAttributes({
|
|
270
|
+
* themes,
|
|
271
|
+
* handler: (theme) => console.log('Theme changed to:', theme),
|
|
272
|
+
* defaultTheme: 'light',
|
|
273
|
+
* attributeName: 'data-theme'
|
|
274
|
+
* })
|
|
275
|
+
*
|
|
276
|
+
* // Stop observing
|
|
277
|
+
* observer.disconnect()
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
280
|
+
declare function observeThemeByDataAttributes<Themes extends Record<string, string>>(options: {
|
|
281
|
+
attributeName: `data-${string}`;
|
|
282
|
+
themes: Themes;
|
|
283
|
+
handler: (value: string | null) => void;
|
|
284
|
+
defaultTheme?: keyof Themes | undefined;
|
|
285
|
+
element?: Element | undefined;
|
|
286
|
+
}): MutationObserver;
|
|
287
|
+
declare function observeThemeByDataAttributes<Themes extends Record<string, string>>(options: {
|
|
288
|
+
attributeName: `data-${string}`;
|
|
289
|
+
themes: Themes;
|
|
290
|
+
handler: (value: string | null) => void;
|
|
291
|
+
allowCustom: true | undefined;
|
|
292
|
+
defaultTheme?: keyof Themes | undefined;
|
|
293
|
+
element?: Element | undefined;
|
|
294
|
+
}): MutationObserver;
|
|
295
|
+
//#endregion
|
|
296
|
+
//#region src/utils/attribute.d.ts
|
|
297
|
+
/**
|
|
298
|
+
* Gets the value of an attribute from an element.
|
|
299
|
+
*
|
|
300
|
+
* @param qualifiedName - The name of the attribute to get
|
|
301
|
+
* @param element - The element to get the attribute from. Defaults to `document.documentElement`
|
|
302
|
+
* @returns The attribute value cast to type T, or null if the attribute doesn't exist
|
|
303
|
+
*
|
|
304
|
+
* @example
|
|
305
|
+
* ```ts
|
|
306
|
+
* // Get theme from document root
|
|
307
|
+
* const theme = getAttribute('data-theme')
|
|
308
|
+
*
|
|
309
|
+
* // Get data-testid from a specific element
|
|
310
|
+
* const testId = getAttribute('data-testid', element)
|
|
311
|
+
* ```
|
|
312
|
+
*/
|
|
313
|
+
declare function getAttribute<T extends string>(qualifiedName: T, element?: Element | undefined): string | null;
|
|
314
|
+
/**
|
|
315
|
+
* Observes attributes changes on an element and calls corresponding handlers.
|
|
316
|
+
*
|
|
317
|
+
* @param handlers - An object mapping attribute names to handler functions.
|
|
318
|
+
* @param element - The element to observe. Defaults to `document.documentElement`.
|
|
319
|
+
* @returns {MutationObserver} The observer instance, which can be used to disconnect the observer.
|
|
320
|
+
*
|
|
321
|
+
* @example
|
|
322
|
+
* ```ts
|
|
323
|
+
* const observer = observeAttributes({
|
|
324
|
+
* 'data-theme': (attr, value) => console.log(`Theme changed to: ${value}`),
|
|
325
|
+
* 'class': (attr, value) => console.log(`class changed to: ${value}`)
|
|
326
|
+
* });
|
|
327
|
+
*
|
|
328
|
+
* // Later, to stop observing:
|
|
329
|
+
* observer.disconnect();
|
|
330
|
+
* ```
|
|
331
|
+
*/
|
|
332
|
+
declare function observeAttributes<T extends string>(handlers: Record<string, (value: T | null) => void>, element?: Element | undefined): MutationObserver;
|
|
333
|
+
//#endregion
|
|
334
|
+
//#region src/utils/data-attribute.d.ts
|
|
335
|
+
declare function getDataAttribute<T extends `data-${string}`>(qualifiedName: T, element?: Element | undefined): string | null;
|
|
336
|
+
/**
|
|
337
|
+
* Observes changes to `data-*` attributes on an element and calls corresponding handlers.
|
|
338
|
+
*
|
|
339
|
+
* @param options - Configuration options
|
|
340
|
+
* @param options.handlers - An object mapping `data-*` attribute names to handler functions.
|
|
341
|
+
* @param options.element - The element to observe. Defaults to `document.documentElement`
|
|
342
|
+
* @returns {MutationObserver} The observer instance, which can be used to disconnect the observer
|
|
343
|
+
*
|
|
344
|
+
* @example
|
|
345
|
+
* ```ts
|
|
346
|
+
* const observer = observeDataAttributes({
|
|
347
|
+
* handlers: {
|
|
348
|
+
* 'data-theme': (value) => console.log(`Theme changed to: ${value}`),
|
|
349
|
+
* 'data-mode': (value) => console.log(`Mode changed to: ${value}`)
|
|
350
|
+
* }
|
|
351
|
+
* });
|
|
352
|
+
*
|
|
353
|
+
* // Later, to stop observing:
|
|
354
|
+
* observer.disconnect();
|
|
355
|
+
* ```
|
|
356
|
+
*/
|
|
357
|
+
declare function observeDataAttributes<T extends string, K extends `data-${string}`>(handlers: Record<K, (value: T | null) => void>, element?: Element | undefined): MutationObserver;
|
|
358
|
+
//#endregion
|
|
359
|
+
//#region src/utils/get-css-prop-values.d.ts
|
|
360
|
+
/**
|
|
361
|
+
* Retrieves CSS custom property values from the specified element.
|
|
362
|
+
*
|
|
363
|
+
* @param element - The HTML element to get property values from
|
|
364
|
+
* @param props - CSS custom property names to retrieve, must be in the format `--property-name`
|
|
365
|
+
* @returns Array of property values corresponding to the requested custom properties
|
|
366
|
+
*/
|
|
367
|
+
declare function getCSSPropValues<Props extends Array<`--${string}`>>(element: HTMLElement, ...props: Props): CreateTuple<Props['length'], string>;
|
|
368
|
+
/**
|
|
369
|
+
* Retrieves CSS custom property values from `document.body`.
|
|
370
|
+
*
|
|
371
|
+
* @param props - CSS custom property names to retrieve, must be in the format `--property-name`
|
|
372
|
+
* @returns Array of property values corresponding to the requested custom properties
|
|
373
|
+
*/
|
|
374
|
+
declare function getCSSPropValues<Props extends Array<`--${string}`>>(...props: Props): CreateTuple<Props['length'], string>;
|
|
375
|
+
//#endregion
|
|
376
|
+
//#region src/utils/prefers-color-scheme.d.ts
|
|
377
|
+
/**
|
|
378
|
+
* Observes system color scheme preference changes and calls handlers when they occur.
|
|
379
|
+
*
|
|
380
|
+
* @param themes - An object mapping theme names to handler functions that are called when that theme is activated
|
|
381
|
+
* @returns A cleanup function that removes all event listeners
|
|
382
|
+
*
|
|
383
|
+
* @example
|
|
384
|
+
* ```ts
|
|
385
|
+
* // Observe light/dark mode changes
|
|
386
|
+
* const cleanup = observePrefersColorScheme({
|
|
387
|
+
* light: (theme) => console.log('Light mode activated'),
|
|
388
|
+
* dark: (theme) => console.log('Dark mode activated')
|
|
389
|
+
* })
|
|
390
|
+
*
|
|
391
|
+
* // Later, to stop observing:
|
|
392
|
+
* cleanup()
|
|
393
|
+
* ```
|
|
394
|
+
*/
|
|
395
|
+
declare function observePrefersColorScheme<T extends string>(themes: Record<T, (value: T | null) => void>): () => void;
|
|
396
|
+
/**
|
|
397
|
+
* Gets the current preferred color theme from the system settings.
|
|
398
|
+
*
|
|
399
|
+
* @param themes - A list of theme names to check against the system preference
|
|
400
|
+
* @returns The first matching theme from the provided list, or null if none match
|
|
401
|
+
*
|
|
402
|
+
* @example
|
|
403
|
+
* ```ts
|
|
404
|
+
* // Check if system prefers light or dark mode
|
|
405
|
+
* const theme = getPrefersColorTheme('light', 'dark')
|
|
406
|
+
* // Returns 'light', 'dark', or null
|
|
407
|
+
* ```
|
|
408
|
+
*/
|
|
409
|
+
declare function getPrefersColorTheme<T extends string>(...themes: T[]): T | null;
|
|
410
|
+
//#endregion
|
|
411
|
+
export { CSSProperties, ClassNameProps, type Properties, StyleProps, defineCSSProperties, defineProperties, getAttribute, getCSSPropValues, getDataAttribute, getPrefersColorTheme, getThemeByClassName, getThemeByDataAttribute, observeAttributes, observeDataAttributes, observePrefersColorScheme, observeThemeByClassName, observeThemeByDataAttributes, px2num, px2rem, rem2px, toDOMStyle };
|
|
412
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/convertors/px_2_num.ts","../src/convertors/px_2_rem.ts","../src/convertors/rem_2_px.ts","../src/properties/css_properties.ts","../src/properties/properties.ts","../src/properties/to_dom_style.ts","../src/props/class-name.ts","../src/props/style.ts","../src/theme/class-name.ts","../src/theme/data-attribute.ts","../src/utils/attribute.ts","../src/utils/data-attribute.ts","../src/utils/get-css-prop-values.ts","../src/utils/prefers-color-scheme.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;AAcA;;;;ACGA;;;;ACAgB,iBFHA,MAAA,CEGM,EAAA,EAAA,MAAA,GAAA,MAAA,GAAA,SAAA,CAAA,EAAA,MAAA;;;;;;;;;AFHtB;;;;ACGA;;;;ACAA;;;iBDAgB,MAAA;EERC,IAAA,CAAA,EAAA,MAAA,GAAc,SAAA;EAsBf,SAAA,CAAA,EAAA,MAAA,GAAA,SAAmB;;;;;;;;;;AHjBnC;;;;ACGA;;;;ACAA;;;iBAAgB,MAAA;ECRC,IAAA,CAAA,EAAA,MAAA,GAAc,SAAA;EAsBf,SAAA,CAAA,EAAA,MAAA,GAAA,SAAmB;;;;;;;;;AHjBnC;;UGLiB,aAAA,SAAsB;;AFQvC;;;;ACAA;;;;ACRA;AAsBA;;;;ACxBA;;;;;AAqBA;AAAqG,iBDGrF,mBAAA,CCHqF,KAAA,EDG1D,aCH0D,CAAA,EAAA,GAAA;;;;;;;;AJdrF,UIPC,UJOK,CAAA,UAAA,CAAA,GAAA,CAAA,MAAA,GAAA,CAAA,CAAA,CAAA,EAAA,QAAA,MAAA,GAAA,CAAA,CAAA,C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