yummies 7.10.0 → 7.12.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/async.cjs +162 -48
- package/async.cjs.map +1 -1
- package/async.d.ts +112 -13
- package/async.js +163 -54
- package/async.js.map +1 -1
- package/chunk-CVq3Gv4J.cjs +50 -0
- package/chunk-YKewjYmz.js +37 -0
- package/common.cjs +48 -8
- package/common.cjs.map +1 -1
- package/common.d.ts +35 -2
- package/common.js +49 -11
- package/common.js.map +1 -1
- package/complex.cjs +275 -104
- package/complex.cjs.map +1 -1
- package/complex.d.ts +133 -13
- package/complex.js +275 -109
- package/complex.js.map +1 -1
- package/cookie.cjs +17 -7
- package/cookie.cjs.map +1 -1
- package/cookie.d.ts +8 -0
- package/cookie.js +18 -9
- package/cookie.js.map +1 -1
- package/css.cjs +147 -39
- package/css.cjs.map +1 -1
- package/css.d.ts +98 -6
- package/css.js +143 -41
- package/css.js.map +1 -1
- package/data.cjs +90 -55
- package/data.cjs.map +1 -1
- package/data.d.ts +32 -0
- package/data.js +91 -61
- package/data.js.map +1 -1
- package/date-time.cjs +578 -412
- package/date-time.cjs.map +1 -1
- package/date-time.d.ts +88 -0
- package/date-time.js +575 -421
- package/date-time.js.map +1 -1
- package/device.cjs +48 -23
- package/device.cjs.map +1 -1
- package/device.d.ts +32 -0
- package/device.js +49 -31
- package/device.js.map +1 -1
- package/encodings.cjs +275 -266
- package/encodings.cjs.map +1 -1
- package/encodings.d.ts +8 -0
- package/encodings.js +276 -268
- package/encodings.js.map +1 -1
- package/errors.cjs +20 -18
- package/errors.cjs.map +1 -1
- package/errors.js +19 -19
- package/errors.js.map +1 -1
- package/file.cjs +42 -24
- package/file.cjs.map +1 -1
- package/file.d.ts +16 -0
- package/file.js +43 -27
- package/file.js.map +1 -1
- package/format.cjs +125 -83
- package/format.cjs.map +1 -1
- package/format.d.ts +89 -4
- package/format.js +118 -82
- package/format.js.map +1 -1
- package/html.cjs +226 -137
- package/html.cjs.map +1 -1
- package/html.d.ts +67 -3
- package/html.js +223 -150
- package/html.js.map +1 -1
- package/id.cjs +74 -17
- package/id.cjs.map +1 -1
- package/id.d.ts +10 -10
- package/id.js +73 -24
- package/id.js.map +1 -1
- package/imports.cjs +41 -29
- package/imports.cjs.map +1 -1
- package/imports.d.ts +13 -4
- package/imports.js +40 -31
- package/imports.js.map +1 -1
- package/math.cjs +32 -6
- package/math.cjs.map +1 -1
- package/math.d.ts +17 -1
- package/math.js +33 -10
- package/math.js.map +1 -1
- package/media.cjs +275 -84
- package/media.cjs.map +1 -1
- package/media.d.ts +188 -2
- package/media.js +274 -93
- package/media.js.map +1 -1
- package/mobx.cjs +353 -193
- package/mobx.cjs.map +1 -1
- package/mobx.d.ts +172 -6
- package/mobx.js +351 -200
- package/mobx.js.map +1 -1
- package/ms.cjs +21 -10
- package/ms.cjs.map +1 -1
- package/ms.d.ts +1 -1
- package/ms.js +22 -13
- package/ms.js.map +1 -1
- package/number.cjs +13 -7
- package/number.cjs.map +1 -1
- package/number.js +14 -9
- package/number.js.map +1 -1
- package/package.json +13 -5
- package/parser.cjs +117 -64
- package/parser.cjs.map +1 -1
- package/parser.d.ts +63 -0
- package/parser.js +111 -64
- package/parser.js.map +1 -1
- package/price.cjs +24 -18
- package/price.cjs.map +1 -1
- package/price.d.ts +8 -0
- package/price.js +25 -20
- package/price.js.map +1 -1
- package/random.cjs +79 -13
- package/random.cjs.map +1 -1
- package/random.d.ts +64 -0
- package/random.js +80 -22
- package/random.js.map +1 -1
- package/react.cjs +673 -214
- package/react.cjs.map +1 -1
- package/react.d.ts +428 -9
- package/react.js +674 -239
- package/react.js.map +1 -1
- package/sound.cjs +14 -9
- package/sound.cjs.map +1 -1
- package/sound.d.ts +1 -1
- package/sound.js +15 -11
- package/sound.js.map +1 -1
- package/storage.cjs +49 -50
- package/storage.cjs.map +1 -1
- package/storage.d.ts +15 -6
- package/storage.js +50 -53
- package/storage.js.map +1 -1
- package/text.cjs +51 -34
- package/text.cjs.map +1 -1
- package/text.d.ts +5 -5
- package/text.js +52 -37
- package/text.js.map +1 -1
- package/type-guard.cjs +292 -72
- package/type-guard.cjs.map +1 -1
- package/type-guard.d.ts +199 -42
- package/type-guard.js +288 -73
- package/type-guard.js.map +1 -1
- package/types.cjs +0 -2
- package/types.global.cjs +0 -2
- package/types.global.js +0 -2
- package/types.js +0 -2
- package/vibrate.cjs +31 -6
- package/vibrate.cjs.map +1 -1
- package/vibrate.d.ts +23 -1
- package/vibrate.js +32 -8
- package/vibrate.js.map +1 -1
- package/types.cjs.map +0 -1
- package/types.global.cjs.map +0 -1
- package/types.global.js.map +0 -1
- package/types.js.map +0 -1
package/css.cjs
CHANGED
|
@@ -1,46 +1,154 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
const require_chunk = require("./chunk-CVq3Gv4J.cjs");
|
|
3
|
+
let class_variance_authority = require("class-variance-authority");
|
|
4
|
+
let clsx = require("clsx");
|
|
5
|
+
clsx = require_chunk.__toESM(clsx);
|
|
6
|
+
let tailwind_merge = require("tailwind-merge");
|
|
7
|
+
//#region src/css.ts
|
|
8
|
+
/**
|
|
9
|
+
* Converts a length in **pixels** to a CSS **`rem`** string (`"<number>rem"`).
|
|
10
|
+
*
|
|
11
|
+
* Use when authoring component styles in JS/TS where design tokens are in px but the stylesheet
|
|
12
|
+
* should scale with root font size (accessibility, user zoom). `remValue` is the assumed
|
|
13
|
+
* `1rem` size in px (browser default is typically `16`).
|
|
14
|
+
*
|
|
15
|
+
* @param px - Pixel value to convert (not rounded; stringification keeps full float).
|
|
16
|
+
* @param remValue - How many pixels one `rem` equals. Defaults to `16`.
|
|
17
|
+
* @returns A string like `"1.5rem"` suitable for `style` or CSS-in-JS.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const width = toRem(24); // '1.5rem' with default 16px root
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* // Custom root / design system where 1rem === 10px
|
|
27
|
+
* const gap = toRem(20, 10); // '2rem'
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
var toRem = (px, remValue = 16) => `${px / remValue}rem`;
|
|
31
|
+
/**
|
|
32
|
+
* Composes conditional class names like {@link https://github.com/lukeed/clsx | clsx}, then runs
|
|
33
|
+
* the result through {@link https://github.com/dcastil/tailwind-merge | tailwind-merge} so
|
|
34
|
+
* conflicting Tailwind utilities collapse to the last/intended one (e.g. two `padding-x` classes).
|
|
35
|
+
*
|
|
36
|
+
* Accepts the same argument shapes as `clsx`: strings, objects, arrays, falsy values to omit.
|
|
37
|
+
*
|
|
38
|
+
* @param args - Same as `clsx(...args)` — `ClassValue` rest parameters.
|
|
39
|
+
* @returns A single merged class string, safe for `className` on DOM/React.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* cx('px-2 py-1 text-sm', 'px-4'); // 'py-1 text-sm px-4' — padding-x merged
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* cx('btn', { 'btn--active': isActive, 'btn--disabled': disabled }, className);
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
var cx = (...args) => (0, tailwind_merge.twMerge)((0, clsx.default)(...args));
|
|
52
|
+
/**
|
|
53
|
+
* {@link https://cva.style/docs | Class Variance Authority (cva)} with the same **tailwind-merge**
|
|
54
|
+
* pass as {@link cx}: the class string produced by the variant function is merged so Tailwind
|
|
55
|
+
* conflicts resolve predictably.
|
|
56
|
+
*
|
|
57
|
+
* API matches `cva` from `class-variance-authority`: optional `base` classes, `config` with
|
|
58
|
+
* `variants`, `defaultVariants`, and `compoundVariants`. The returned function accepts variant
|
|
59
|
+
* props plus optional `class` / `className` for one-off overrides.
|
|
60
|
+
*
|
|
61
|
+
* Use {@link VariantProps} with `typeof buttonVariants` (or similar) to type component props.
|
|
62
|
+
*
|
|
63
|
+
* @param base - Base `ClassValue`(s) always applied.
|
|
64
|
+
* @param config - Variant schema and defaults (same shape as upstream `cva`).
|
|
65
|
+
* @returns A function `(props?) => string` that resolves variant classes, merged with tw-merge.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* const button = cva('rounded font-medium', {
|
|
70
|
+
* variants: {
|
|
71
|
+
* tone: { primary: 'bg-blue-600 text-white', ghost: 'bg-transparent' },
|
|
72
|
+
* size: { sm: 'text-sm px-2', md: 'text-base px-4' },
|
|
73
|
+
* },
|
|
74
|
+
* defaultVariants: { tone: 'primary', size: 'md' },
|
|
75
|
+
* });
|
|
76
|
+
* button({ tone: 'ghost', className: 'ml-2' });
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* const card = cva('border p-4', {
|
|
82
|
+
* variants: { elevated: { true: 'shadow-lg', false: 'shadow-none' } },
|
|
83
|
+
* defaultVariants: { elevated: false },
|
|
84
|
+
* });
|
|
85
|
+
* card({ elevated: true });
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
var cva = ((...args) => {
|
|
89
|
+
const schema = (0, class_variance_authority.cva)(...args);
|
|
90
|
+
return (...inputArgs) => (0, tailwind_merge.twMerge)(schema(...inputArgs));
|
|
11
91
|
});
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Injects a stylesheet by appending a `<link rel="stylesheet">` to `document.head`.
|
|
94
|
+
* Resolves when the sheet fires `load`; rejects on `error` (e.g. 404 or network failure).
|
|
95
|
+
*
|
|
96
|
+
* **Id replacement:** if `attrubutes.id` is set, any existing element with that `id` is removed
|
|
97
|
+
* first, so repeated calls with the same `id` replace the previous link (useful for theme or
|
|
98
|
+
* font URLs that change).
|
|
99
|
+
*
|
|
100
|
+
* If `rel` is omitted in `attrubutes`, it defaults to `stylesheet`. Other attributes (`crossorigin`,
|
|
101
|
+
* `media`, `data-*`, etc.) are set via `setAttribute` from the record entries.
|
|
102
|
+
*
|
|
103
|
+
* @param url - Stylesheet URL (`href`).
|
|
104
|
+
* @param attrubutes - Optional HTML attributes for the `<link>` element (see `id` / `rel` behavior above).
|
|
105
|
+
* @returns Promise that resolves to `undefined` on load, or rejects on load error.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* await loadCssFile('https://example.com/fonts.css', {
|
|
110
|
+
* id: 'app-fonts',
|
|
111
|
+
* crossOrigin: 'anonymous',
|
|
112
|
+
* });
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* // Swap theme stylesheet without duplicate link tags
|
|
118
|
+
* await loadCssFile('/themes/dark.css', { id: 'theme' });
|
|
119
|
+
* await loadCssFile('/themes/light.css', { id: 'theme' });
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
var loadCssFile = (url, attrubutes) => new Promise((resolve, reject) => {
|
|
123
|
+
let link;
|
|
124
|
+
if (attrubutes?.id) {
|
|
125
|
+
link = document.getElementById(attrubutes.id);
|
|
126
|
+
if (link) link.remove();
|
|
127
|
+
}
|
|
128
|
+
link = document.createElement("link");
|
|
129
|
+
const handleLoad = () => {
|
|
130
|
+
resolve(void 0);
|
|
131
|
+
link.removeEventListener("load", handleLoad);
|
|
132
|
+
link.removeEventListener("error", handleError);
|
|
133
|
+
};
|
|
134
|
+
const handleError = () => {
|
|
135
|
+
reject(void 0);
|
|
136
|
+
link.removeEventListener("load", handleLoad);
|
|
137
|
+
link.removeEventListener("error", handleError);
|
|
138
|
+
};
|
|
139
|
+
link.addEventListener("load", handleLoad);
|
|
140
|
+
link.addEventListener("error", handleError);
|
|
141
|
+
link.setAttribute("href", url);
|
|
142
|
+
if (!attrubutes?.rel) link.setAttribute("rel", "stylesheet");
|
|
143
|
+
Object.entries(attrubutes || {}).forEach(([key, value]) => {
|
|
144
|
+
link.setAttribute(key, value);
|
|
145
|
+
});
|
|
146
|
+
document.head.appendChild(link);
|
|
41
147
|
});
|
|
148
|
+
//#endregion
|
|
42
149
|
exports.cva = cva;
|
|
43
150
|
exports.cx = cx;
|
|
44
151
|
exports.loadCssFile = loadCssFile;
|
|
45
152
|
exports.toRem = toRem;
|
|
46
|
-
|
|
153
|
+
|
|
154
|
+
//# sourceMappingURL=css.cjs.map
|
package/css.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"css.cjs","sources":["../src/css.ts"],"sourcesContent":["import { cva as cvaLib } from 'class-variance-authority';\nimport clsx, { type ClassValue } from 'clsx';\nimport { twMerge } from 'tailwind-merge';\nimport type { Maybe } from 'yummies/types';\n\ntype ClassProp = {\n class?: ClassValue;\n className?: ClassValue;\n};\n\ntype StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T;\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"css.cjs","names":[],"sources":["../src/css.ts"],"sourcesContent":["import { cva as cvaLib } from 'class-variance-authority';\nimport clsx, { type ClassValue } from 'clsx';\nimport { twMerge } from 'tailwind-merge';\nimport type { Maybe } from 'yummies/types';\n\ntype ClassProp = {\n class?: ClassValue;\n className?: ClassValue;\n};\n\ntype StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T;\n\n/**\n * Converts a length in **pixels** to a CSS **`rem`** string (`\"<number>rem\"`).\n *\n * Use when authoring component styles in JS/TS where design tokens are in px but the stylesheet\n * should scale with root font size (accessibility, user zoom). `remValue` is the assumed\n * `1rem` size in px (browser default is typically `16`).\n *\n * @param px - Pixel value to convert (not rounded; stringification keeps full float).\n * @param remValue - How many pixels one `rem` equals. Defaults to `16`.\n * @returns A string like `\"1.5rem\"` suitable for `style` or CSS-in-JS.\n *\n * @example\n * ```ts\n * const width = toRem(24); // '1.5rem' with default 16px root\n * ```\n *\n * @example\n * ```ts\n * // Custom root / design system where 1rem === 10px\n * const gap = toRem(20, 10); // '2rem'\n * ```\n */\nexport const toRem = (px: number, remValue = 16) => `${px / remValue}rem`;\n\n/**\n * Composes conditional class names like {@link https://github.com/lukeed/clsx | clsx}, then runs\n * the result through {@link https://github.com/dcastil/tailwind-merge | tailwind-merge} so\n * conflicting Tailwind utilities collapse to the last/intended one (e.g. two `padding-x` classes).\n *\n * Accepts the same argument shapes as `clsx`: strings, objects, arrays, falsy values to omit.\n *\n * @param args - Same as `clsx(...args)` — `ClassValue` rest parameters.\n * @returns A single merged class string, safe for `className` on DOM/React.\n *\n * @example\n * ```ts\n * cx('px-2 py-1 text-sm', 'px-4'); // 'py-1 text-sm px-4' — padding-x merged\n * ```\n *\n * @example\n * ```ts\n * cx('btn', { 'btn--active': isActive, 'btn--disabled': disabled }, className);\n * ```\n */\nexport const cx = (...args: Parameters<typeof clsx>) => twMerge(clsx(...args));\n\ntype ConfigSchema = Record<string, Record<string, ClassValue>>;\ntype ConfigVariants<T extends ConfigSchema> = {\n [Variant in keyof T]?: StringToBoolean<keyof T[Variant]> | null | undefined;\n};\ntype ConfigVariantsMulti<T extends ConfigSchema> = {\n [Variant in keyof T]?:\n | StringToBoolean<keyof T[Variant]>\n | StringToBoolean<keyof T[Variant]>[]\n | undefined;\n};\ntype Config<T> = T extends ConfigSchema\n ? {\n variants?: T;\n defaultVariants?: ConfigVariants<T>;\n compoundVariants?: (T extends ConfigSchema\n ? (ConfigVariants<T> | ConfigVariantsMulti<T>) & ClassProp\n : ClassProp)[];\n }\n : never;\n\ntype Props<T> = T extends ConfigSchema\n ? ConfigVariants<T> & ClassProp\n : ClassProp;\n\n/**\n * {@link https://cva.style/docs | Class Variance Authority (cva)} with the same **tailwind-merge**\n * pass as {@link cx}: the class string produced by the variant function is merged so Tailwind\n * conflicts resolve predictably.\n *\n * API matches `cva` from `class-variance-authority`: optional `base` classes, `config` with\n * `variants`, `defaultVariants`, and `compoundVariants`. The returned function accepts variant\n * props plus optional `class` / `className` for one-off overrides.\n *\n * Use {@link VariantProps} with `typeof buttonVariants` (or similar) to type component props.\n *\n * @param base - Base `ClassValue`(s) always applied.\n * @param config - Variant schema and defaults (same shape as upstream `cva`).\n * @returns A function `(props?) => string` that resolves variant classes, merged with tw-merge.\n *\n * @example\n * ```ts\n * const button = cva('rounded font-medium', {\n * variants: {\n * tone: { primary: 'bg-blue-600 text-white', ghost: 'bg-transparent' },\n * size: { sm: 'text-sm px-2', md: 'text-base px-4' },\n * },\n * defaultVariants: { tone: 'primary', size: 'md' },\n * });\n * button({ tone: 'ghost', className: 'ml-2' });\n * ```\n *\n * @example\n * ```ts\n * const card = cva('border p-4', {\n * variants: { elevated: { true: 'shadow-lg', false: 'shadow-none' } },\n * defaultVariants: { elevated: false },\n * });\n * card({ elevated: true });\n * ```\n */\nexport const cva = ((...args: any[]) => {\n const schema = cvaLib(...args);\n return (...inputArgs: any[]) => twMerge(schema(...inputArgs));\n}) as any as <T>(\n base?: ClassValue,\n config?: Config<T>,\n) => (props?: Props<T>) => string;\n\n/**\n * Utility type from `class-variance-authority`: infers the variant prop object from a `cva` instance.\n * Use it to type React (or other) components that forward variant props.\n *\n * @example\n * ```ts\n * const input = cva('border', { variants: { size: { sm: 'h-8', lg: 'h-12' } } });\n * type InputVariants = VariantProps<typeof input>;\n * // { size?: 'sm' | 'lg' | null }\n * ```\n */\nexport type { VariantProps } from 'class-variance-authority';\n\n/**\n * Re-export from `clsx`: a class name fragment — string, number, nested arrays, object map of\n * flags, or falsy nodes to skip. Used by {@link cx}, {@link cva}, and typical `className` helpers.\n *\n * @example\n * ```ts\n * const value: ClassValue = ['btn', false && 'hidden', { active: true }];\n * ```\n */\nexport type { ClassValue } from 'clsx';\n\n/**\n * Injects a stylesheet by appending a `<link rel=\"stylesheet\">` to `document.head`.\n * Resolves when the sheet fires `load`; rejects on `error` (e.g. 404 or network failure).\n *\n * **Id replacement:** if `attrubutes.id` is set, any existing element with that `id` is removed\n * first, so repeated calls with the same `id` replace the previous link (useful for theme or\n * font URLs that change).\n *\n * If `rel` is omitted in `attrubutes`, it defaults to `stylesheet`. Other attributes (`crossorigin`,\n * `media`, `data-*`, etc.) are set via `setAttribute` from the record entries.\n *\n * @param url - Stylesheet URL (`href`).\n * @param attrubutes - Optional HTML attributes for the `<link>` element (see `id` / `rel` behavior above).\n * @returns Promise that resolves to `undefined` on load, or rejects on load error.\n *\n * @example\n * ```ts\n * await loadCssFile('https://example.com/fonts.css', {\n * id: 'app-fonts',\n * crossOrigin: 'anonymous',\n * });\n * ```\n *\n * @example\n * ```ts\n * // Swap theme stylesheet without duplicate link tags\n * await loadCssFile('/themes/dark.css', { id: 'theme' });\n * await loadCssFile('/themes/light.css', { id: 'theme' });\n * ```\n */\nexport const loadCssFile = (url: string, attrubutes?: Record<string, any>) =>\n new Promise((resolve, reject) => {\n let link: Maybe<HTMLLinkElement>;\n\n if (attrubutes?.id) {\n link = document.getElementById(attrubutes.id) as HTMLLinkElement | null;\n\n if (link) {\n link.remove();\n }\n }\n\n link = document.createElement('link');\n\n const handleLoad = () => {\n resolve(undefined);\n link!.removeEventListener('load', handleLoad);\n link!.removeEventListener('error', handleError);\n };\n\n const handleError = () => {\n reject(undefined);\n link!.removeEventListener('load', handleLoad);\n link!.removeEventListener('error', handleError);\n };\n\n link.addEventListener('load', handleLoad);\n link.addEventListener('error', handleError);\n\n link.setAttribute('href', url);\n\n if (!attrubutes?.rel) {\n link.setAttribute('rel', 'stylesheet');\n }\n\n Object.entries(attrubutes || {}).forEach(([key, value]) => {\n link.setAttribute(key, value);\n });\n\n document.head.appendChild(link);\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,IAAa,SAAS,IAAY,WAAW,OAAO,GAAG,KAAK,SAAS;;;;;;;;;;;;;;;;;;;;;AAsBrE,IAAa,MAAM,GAAG,UAAA,GAAA,eAAA,UAAA,GAAA,KAAA,SAA+C,GAAG,KAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8D9E,IAAa,QAAQ,GAAG,SAAgB;CACtC,MAAM,UAAA,GAAA,yBAAA,KAAgB,GAAG,KAAK;AAC9B,SAAQ,GAAG,eAAA,GAAA,eAAA,SAA6B,OAAO,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4D/D,IAAa,eAAe,KAAa,eACvC,IAAI,SAAS,SAAS,WAAW;CAC/B,IAAI;AAEJ,KAAI,YAAY,IAAI;AAClB,SAAO,SAAS,eAAe,WAAW,GAAG;AAE7C,MAAI,KACF,MAAK,QAAQ;;AAIjB,QAAO,SAAS,cAAc,OAAO;CAErC,MAAM,mBAAmB;AACvB,UAAQ,KAAA,EAAU;AAClB,OAAM,oBAAoB,QAAQ,WAAW;AAC7C,OAAM,oBAAoB,SAAS,YAAY;;CAGjD,MAAM,oBAAoB;AACxB,SAAO,KAAA,EAAU;AACjB,OAAM,oBAAoB,QAAQ,WAAW;AAC7C,OAAM,oBAAoB,SAAS,YAAY;;AAGjD,MAAK,iBAAiB,QAAQ,WAAW;AACzC,MAAK,iBAAiB,SAAS,YAAY;AAE3C,MAAK,aAAa,QAAQ,IAAI;AAE9B,KAAI,CAAC,YAAY,IACf,MAAK,aAAa,OAAO,aAAa;AAGxC,QAAO,QAAQ,cAAc,EAAE,CAAC,CAAC,SAAS,CAAC,KAAK,WAAW;AACzD,OAAK,aAAa,KAAK,MAAM;GAC7B;AAEF,UAAS,KAAK,YAAY,KAAK;EAC/B"}
|
package/css.d.ts
CHANGED
|
@@ -8,11 +8,47 @@ type ClassProp = {
|
|
|
8
8
|
};
|
|
9
9
|
type StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T;
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Converts a length in **pixels** to a CSS **`rem`** string (`"<number>rem"`).
|
|
12
|
+
*
|
|
13
|
+
* Use when authoring component styles in JS/TS where design tokens are in px but the stylesheet
|
|
14
|
+
* should scale with root font size (accessibility, user zoom). `remValue` is the assumed
|
|
15
|
+
* `1rem` size in px (browser default is typically `16`).
|
|
16
|
+
*
|
|
17
|
+
* @param px - Pixel value to convert (not rounded; stringification keeps full float).
|
|
18
|
+
* @param remValue - How many pixels one `rem` equals. Defaults to `16`.
|
|
19
|
+
* @returns A string like `"1.5rem"` suitable for `style` or CSS-in-JS.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* const width = toRem(24); // '1.5rem' with default 16px root
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* // Custom root / design system where 1rem === 10px
|
|
29
|
+
* const gap = toRem(20, 10); // '2rem'
|
|
30
|
+
* ```
|
|
12
31
|
*/
|
|
13
32
|
declare const toRem: (px: number, remValue?: number) => string;
|
|
14
33
|
/**
|
|
15
|
-
*
|
|
34
|
+
* Composes conditional class names like {@link https://github.com/lukeed/clsx | clsx}, then runs
|
|
35
|
+
* the result through {@link https://github.com/dcastil/tailwind-merge | tailwind-merge} so
|
|
36
|
+
* conflicting Tailwind utilities collapse to the last/intended one (e.g. two `padding-x` classes).
|
|
37
|
+
*
|
|
38
|
+
* Accepts the same argument shapes as `clsx`: strings, objects, arrays, falsy values to omit.
|
|
39
|
+
*
|
|
40
|
+
* @param args - Same as `clsx(...args)` — `ClassValue` rest parameters.
|
|
41
|
+
* @returns A single merged class string, safe for `className` on DOM/React.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* cx('px-2 py-1 text-sm', 'px-4'); // 'py-1 text-sm px-4' — padding-x merged
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* cx('btn', { 'btn--active': isActive, 'btn--disabled': disabled }, className);
|
|
51
|
+
* ```
|
|
16
52
|
*/
|
|
17
53
|
declare const cx: (...args: Parameters<typeof clsx>) => string;
|
|
18
54
|
type ConfigSchema = Record<string, Record<string, ClassValue>>;
|
|
@@ -29,16 +65,72 @@ type Config<T> = T extends ConfigSchema ? {
|
|
|
29
65
|
} : never;
|
|
30
66
|
type Props<T> = T extends ConfigSchema ? ConfigVariants<T> & ClassProp : ClassProp;
|
|
31
67
|
/**
|
|
32
|
-
* Class Variance Authority
|
|
68
|
+
* {@link https://cva.style/docs | Class Variance Authority (cva)} with the same **tailwind-merge**
|
|
69
|
+
* pass as {@link cx}: the class string produced by the variant function is merged so Tailwind
|
|
70
|
+
* conflicts resolve predictably.
|
|
33
71
|
*
|
|
34
|
-
*
|
|
72
|
+
* API matches `cva` from `class-variance-authority`: optional `base` classes, `config` with
|
|
73
|
+
* `variants`, `defaultVariants`, and `compoundVariants`. The returned function accepts variant
|
|
74
|
+
* props plus optional `class` / `className` for one-off overrides.
|
|
75
|
+
*
|
|
76
|
+
* Use {@link VariantProps} with `typeof buttonVariants` (or similar) to type component props.
|
|
77
|
+
*
|
|
78
|
+
* @param base - Base `ClassValue`(s) always applied.
|
|
79
|
+
* @param config - Variant schema and defaults (same shape as upstream `cva`).
|
|
80
|
+
* @returns A function `(props?) => string` that resolves variant classes, merged with tw-merge.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* const button = cva('rounded font-medium', {
|
|
85
|
+
* variants: {
|
|
86
|
+
* tone: { primary: 'bg-blue-600 text-white', ghost: 'bg-transparent' },
|
|
87
|
+
* size: { sm: 'text-sm px-2', md: 'text-base px-4' },
|
|
88
|
+
* },
|
|
89
|
+
* defaultVariants: { tone: 'primary', size: 'md' },
|
|
90
|
+
* });
|
|
91
|
+
* button({ tone: 'ghost', className: 'ml-2' });
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* const card = cva('border p-4', {
|
|
97
|
+
* variants: { elevated: { true: 'shadow-lg', false: 'shadow-none' } },
|
|
98
|
+
* defaultVariants: { elevated: false },
|
|
99
|
+
* });
|
|
100
|
+
* card({ elevated: true });
|
|
101
|
+
* ```
|
|
35
102
|
*/
|
|
36
103
|
declare const cva: <T>(base?: ClassValue, config?: Config<T>) => (props?: Props<T>) => string;
|
|
37
104
|
|
|
38
105
|
/**
|
|
39
|
-
*
|
|
106
|
+
* Injects a stylesheet by appending a `<link rel="stylesheet">` to `document.head`.
|
|
107
|
+
* Resolves when the sheet fires `load`; rejects on `error` (e.g. 404 or network failure).
|
|
108
|
+
*
|
|
109
|
+
* **Id replacement:** if `attrubutes.id` is set, any existing element with that `id` is removed
|
|
110
|
+
* first, so repeated calls with the same `id` replace the previous link (useful for theme or
|
|
111
|
+
* font URLs that change).
|
|
112
|
+
*
|
|
113
|
+
* If `rel` is omitted in `attrubutes`, it defaults to `stylesheet`. Other attributes (`crossorigin`,
|
|
114
|
+
* `media`, `data-*`, etc.) are set via `setAttribute` from the record entries.
|
|
115
|
+
*
|
|
116
|
+
* @param url - Stylesheet URL (`href`).
|
|
117
|
+
* @param attrubutes - Optional HTML attributes for the `<link>` element (see `id` / `rel` behavior above).
|
|
118
|
+
* @returns Promise that resolves to `undefined` on load, or rejects on load error.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* await loadCssFile('https://example.com/fonts.css', {
|
|
123
|
+
* id: 'app-fonts',
|
|
124
|
+
* crossOrigin: 'anonymous',
|
|
125
|
+
* });
|
|
126
|
+
* ```
|
|
40
127
|
*
|
|
41
|
-
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* // Swap theme stylesheet without duplicate link tags
|
|
131
|
+
* await loadCssFile('/themes/dark.css', { id: 'theme' });
|
|
132
|
+
* await loadCssFile('/themes/light.css', { id: 'theme' });
|
|
133
|
+
* ```
|
|
42
134
|
*/
|
|
43
135
|
declare const loadCssFile: (url: string, attrubutes?: Record<string, any>) => Promise<unknown>;
|
|
44
136
|
|
package/css.js
CHANGED
|
@@ -1,46 +1,148 @@
|
|
|
1
1
|
import { cva as cva$1 } from "class-variance-authority";
|
|
2
2
|
import clsx from "clsx";
|
|
3
3
|
import { twMerge } from "tailwind-merge";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
//#region src/css.ts
|
|
5
|
+
/**
|
|
6
|
+
* Converts a length in **pixels** to a CSS **`rem`** string (`"<number>rem"`).
|
|
7
|
+
*
|
|
8
|
+
* Use when authoring component styles in JS/TS where design tokens are in px but the stylesheet
|
|
9
|
+
* should scale with root font size (accessibility, user zoom). `remValue` is the assumed
|
|
10
|
+
* `1rem` size in px (browser default is typically `16`).
|
|
11
|
+
*
|
|
12
|
+
* @param px - Pixel value to convert (not rounded; stringification keeps full float).
|
|
13
|
+
* @param remValue - How many pixels one `rem` equals. Defaults to `16`.
|
|
14
|
+
* @returns A string like `"1.5rem"` suitable for `style` or CSS-in-JS.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const width = toRem(24); // '1.5rem' with default 16px root
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* // Custom root / design system where 1rem === 10px
|
|
24
|
+
* const gap = toRem(20, 10); // '2rem'
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
var toRem = (px, remValue = 16) => `${px / remValue}rem`;
|
|
28
|
+
/**
|
|
29
|
+
* Composes conditional class names like {@link https://github.com/lukeed/clsx | clsx}, then runs
|
|
30
|
+
* the result through {@link https://github.com/dcastil/tailwind-merge | tailwind-merge} so
|
|
31
|
+
* conflicting Tailwind utilities collapse to the last/intended one (e.g. two `padding-x` classes).
|
|
32
|
+
*
|
|
33
|
+
* Accepts the same argument shapes as `clsx`: strings, objects, arrays, falsy values to omit.
|
|
34
|
+
*
|
|
35
|
+
* @param args - Same as `clsx(...args)` — `ClassValue` rest parameters.
|
|
36
|
+
* @returns A single merged class string, safe for `className` on DOM/React.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* cx('px-2 py-1 text-sm', 'px-4'); // 'py-1 text-sm px-4' — padding-x merged
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* cx('btn', { 'btn--active': isActive, 'btn--disabled': disabled }, className);
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
var cx = (...args) => twMerge(clsx(...args));
|
|
49
|
+
/**
|
|
50
|
+
* {@link https://cva.style/docs | Class Variance Authority (cva)} with the same **tailwind-merge**
|
|
51
|
+
* pass as {@link cx}: the class string produced by the variant function is merged so Tailwind
|
|
52
|
+
* conflicts resolve predictably.
|
|
53
|
+
*
|
|
54
|
+
* API matches `cva` from `class-variance-authority`: optional `base` classes, `config` with
|
|
55
|
+
* `variants`, `defaultVariants`, and `compoundVariants`. The returned function accepts variant
|
|
56
|
+
* props plus optional `class` / `className` for one-off overrides.
|
|
57
|
+
*
|
|
58
|
+
* Use {@link VariantProps} with `typeof buttonVariants` (or similar) to type component props.
|
|
59
|
+
*
|
|
60
|
+
* @param base - Base `ClassValue`(s) always applied.
|
|
61
|
+
* @param config - Variant schema and defaults (same shape as upstream `cva`).
|
|
62
|
+
* @returns A function `(props?) => string` that resolves variant classes, merged with tw-merge.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* const button = cva('rounded font-medium', {
|
|
67
|
+
* variants: {
|
|
68
|
+
* tone: { primary: 'bg-blue-600 text-white', ghost: 'bg-transparent' },
|
|
69
|
+
* size: { sm: 'text-sm px-2', md: 'text-base px-4' },
|
|
70
|
+
* },
|
|
71
|
+
* defaultVariants: { tone: 'primary', size: 'md' },
|
|
72
|
+
* });
|
|
73
|
+
* button({ tone: 'ghost', className: 'ml-2' });
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* const card = cva('border p-4', {
|
|
79
|
+
* variants: { elevated: { true: 'shadow-lg', false: 'shadow-none' } },
|
|
80
|
+
* defaultVariants: { elevated: false },
|
|
81
|
+
* });
|
|
82
|
+
* card({ elevated: true });
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
var cva = ((...args) => {
|
|
86
|
+
const schema = cva$1(...args);
|
|
87
|
+
return (...inputArgs) => twMerge(schema(...inputArgs));
|
|
9
88
|
});
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
89
|
+
/**
|
|
90
|
+
* Injects a stylesheet by appending a `<link rel="stylesheet">` to `document.head`.
|
|
91
|
+
* Resolves when the sheet fires `load`; rejects on `error` (e.g. 404 or network failure).
|
|
92
|
+
*
|
|
93
|
+
* **Id replacement:** if `attrubutes.id` is set, any existing element with that `id` is removed
|
|
94
|
+
* first, so repeated calls with the same `id` replace the previous link (useful for theme or
|
|
95
|
+
* font URLs that change).
|
|
96
|
+
*
|
|
97
|
+
* If `rel` is omitted in `attrubutes`, it defaults to `stylesheet`. Other attributes (`crossorigin`,
|
|
98
|
+
* `media`, `data-*`, etc.) are set via `setAttribute` from the record entries.
|
|
99
|
+
*
|
|
100
|
+
* @param url - Stylesheet URL (`href`).
|
|
101
|
+
* @param attrubutes - Optional HTML attributes for the `<link>` element (see `id` / `rel` behavior above).
|
|
102
|
+
* @returns Promise that resolves to `undefined` on load, or rejects on load error.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```ts
|
|
106
|
+
* await loadCssFile('https://example.com/fonts.css', {
|
|
107
|
+
* id: 'app-fonts',
|
|
108
|
+
* crossOrigin: 'anonymous',
|
|
109
|
+
* });
|
|
110
|
+
* ```
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* // Swap theme stylesheet without duplicate link tags
|
|
115
|
+
* await loadCssFile('/themes/dark.css', { id: 'theme' });
|
|
116
|
+
* await loadCssFile('/themes/light.css', { id: 'theme' });
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
var loadCssFile = (url, attrubutes) => new Promise((resolve, reject) => {
|
|
120
|
+
let link;
|
|
121
|
+
if (attrubutes?.id) {
|
|
122
|
+
link = document.getElementById(attrubutes.id);
|
|
123
|
+
if (link) link.remove();
|
|
124
|
+
}
|
|
125
|
+
link = document.createElement("link");
|
|
126
|
+
const handleLoad = () => {
|
|
127
|
+
resolve(void 0);
|
|
128
|
+
link.removeEventListener("load", handleLoad);
|
|
129
|
+
link.removeEventListener("error", handleError);
|
|
130
|
+
};
|
|
131
|
+
const handleError = () => {
|
|
132
|
+
reject(void 0);
|
|
133
|
+
link.removeEventListener("load", handleLoad);
|
|
134
|
+
link.removeEventListener("error", handleError);
|
|
135
|
+
};
|
|
136
|
+
link.addEventListener("load", handleLoad);
|
|
137
|
+
link.addEventListener("error", handleError);
|
|
138
|
+
link.setAttribute("href", url);
|
|
139
|
+
if (!attrubutes?.rel) link.setAttribute("rel", "stylesheet");
|
|
140
|
+
Object.entries(attrubutes || {}).forEach(([key, value]) => {
|
|
141
|
+
link.setAttribute(key, value);
|
|
142
|
+
});
|
|
143
|
+
document.head.appendChild(link);
|
|
39
144
|
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
toRem
|
|
45
|
-
};
|
|
46
|
-
//# sourceMappingURL=css.js.map
|
|
145
|
+
//#endregion
|
|
146
|
+
export { cva, cx, loadCssFile, toRem };
|
|
147
|
+
|
|
148
|
+
//# sourceMappingURL=css.js.map
|
package/css.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"css.js","sources":["../src/css.ts"],"sourcesContent":["import { cva as cvaLib } from 'class-variance-authority';\nimport clsx, { type ClassValue } from 'clsx';\nimport { twMerge } from 'tailwind-merge';\nimport type { Maybe } from 'yummies/types';\n\ntype ClassProp = {\n class?: ClassValue;\n className?: ClassValue;\n};\n\ntype StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T;\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"css.js","names":[],"sources":["../src/css.ts"],"sourcesContent":["import { cva as cvaLib } from 'class-variance-authority';\nimport clsx, { type ClassValue } from 'clsx';\nimport { twMerge } from 'tailwind-merge';\nimport type { Maybe } from 'yummies/types';\n\ntype ClassProp = {\n class?: ClassValue;\n className?: ClassValue;\n};\n\ntype StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T;\n\n/**\n * Converts a length in **pixels** to a CSS **`rem`** string (`\"<number>rem\"`).\n *\n * Use when authoring component styles in JS/TS where design tokens are in px but the stylesheet\n * should scale with root font size (accessibility, user zoom). `remValue` is the assumed\n * `1rem` size in px (browser default is typically `16`).\n *\n * @param px - Pixel value to convert (not rounded; stringification keeps full float).\n * @param remValue - How many pixels one `rem` equals. Defaults to `16`.\n * @returns A string like `\"1.5rem\"` suitable for `style` or CSS-in-JS.\n *\n * @example\n * ```ts\n * const width = toRem(24); // '1.5rem' with default 16px root\n * ```\n *\n * @example\n * ```ts\n * // Custom root / design system where 1rem === 10px\n * const gap = toRem(20, 10); // '2rem'\n * ```\n */\nexport const toRem = (px: number, remValue = 16) => `${px / remValue}rem`;\n\n/**\n * Composes conditional class names like {@link https://github.com/lukeed/clsx | clsx}, then runs\n * the result through {@link https://github.com/dcastil/tailwind-merge | tailwind-merge} so\n * conflicting Tailwind utilities collapse to the last/intended one (e.g. two `padding-x` classes).\n *\n * Accepts the same argument shapes as `clsx`: strings, objects, arrays, falsy values to omit.\n *\n * @param args - Same as `clsx(...args)` — `ClassValue` rest parameters.\n * @returns A single merged class string, safe for `className` on DOM/React.\n *\n * @example\n * ```ts\n * cx('px-2 py-1 text-sm', 'px-4'); // 'py-1 text-sm px-4' — padding-x merged\n * ```\n *\n * @example\n * ```ts\n * cx('btn', { 'btn--active': isActive, 'btn--disabled': disabled }, className);\n * ```\n */\nexport const cx = (...args: Parameters<typeof clsx>) => twMerge(clsx(...args));\n\ntype ConfigSchema = Record<string, Record<string, ClassValue>>;\ntype ConfigVariants<T extends ConfigSchema> = {\n [Variant in keyof T]?: StringToBoolean<keyof T[Variant]> | null | undefined;\n};\ntype ConfigVariantsMulti<T extends ConfigSchema> = {\n [Variant in keyof T]?:\n | StringToBoolean<keyof T[Variant]>\n | StringToBoolean<keyof T[Variant]>[]\n | undefined;\n};\ntype Config<T> = T extends ConfigSchema\n ? {\n variants?: T;\n defaultVariants?: ConfigVariants<T>;\n compoundVariants?: (T extends ConfigSchema\n ? (ConfigVariants<T> | ConfigVariantsMulti<T>) & ClassProp\n : ClassProp)[];\n }\n : never;\n\ntype Props<T> = T extends ConfigSchema\n ? ConfigVariants<T> & ClassProp\n : ClassProp;\n\n/**\n * {@link https://cva.style/docs | Class Variance Authority (cva)} with the same **tailwind-merge**\n * pass as {@link cx}: the class string produced by the variant function is merged so Tailwind\n * conflicts resolve predictably.\n *\n * API matches `cva` from `class-variance-authority`: optional `base` classes, `config` with\n * `variants`, `defaultVariants`, and `compoundVariants`. The returned function accepts variant\n * props plus optional `class` / `className` for one-off overrides.\n *\n * Use {@link VariantProps} with `typeof buttonVariants` (or similar) to type component props.\n *\n * @param base - Base `ClassValue`(s) always applied.\n * @param config - Variant schema and defaults (same shape as upstream `cva`).\n * @returns A function `(props?) => string` that resolves variant classes, merged with tw-merge.\n *\n * @example\n * ```ts\n * const button = cva('rounded font-medium', {\n * variants: {\n * tone: { primary: 'bg-blue-600 text-white', ghost: 'bg-transparent' },\n * size: { sm: 'text-sm px-2', md: 'text-base px-4' },\n * },\n * defaultVariants: { tone: 'primary', size: 'md' },\n * });\n * button({ tone: 'ghost', className: 'ml-2' });\n * ```\n *\n * @example\n * ```ts\n * const card = cva('border p-4', {\n * variants: { elevated: { true: 'shadow-lg', false: 'shadow-none' } },\n * defaultVariants: { elevated: false },\n * });\n * card({ elevated: true });\n * ```\n */\nexport const cva = ((...args: any[]) => {\n const schema = cvaLib(...args);\n return (...inputArgs: any[]) => twMerge(schema(...inputArgs));\n}) as any as <T>(\n base?: ClassValue,\n config?: Config<T>,\n) => (props?: Props<T>) => string;\n\n/**\n * Utility type from `class-variance-authority`: infers the variant prop object from a `cva` instance.\n * Use it to type React (or other) components that forward variant props.\n *\n * @example\n * ```ts\n * const input = cva('border', { variants: { size: { sm: 'h-8', lg: 'h-12' } } });\n * type InputVariants = VariantProps<typeof input>;\n * // { size?: 'sm' | 'lg' | null }\n * ```\n */\nexport type { VariantProps } from 'class-variance-authority';\n\n/**\n * Re-export from `clsx`: a class name fragment — string, number, nested arrays, object map of\n * flags, or falsy nodes to skip. Used by {@link cx}, {@link cva}, and typical `className` helpers.\n *\n * @example\n * ```ts\n * const value: ClassValue = ['btn', false && 'hidden', { active: true }];\n * ```\n */\nexport type { ClassValue } from 'clsx';\n\n/**\n * Injects a stylesheet by appending a `<link rel=\"stylesheet\">` to `document.head`.\n * Resolves when the sheet fires `load`; rejects on `error` (e.g. 404 or network failure).\n *\n * **Id replacement:** if `attrubutes.id` is set, any existing element with that `id` is removed\n * first, so repeated calls with the same `id` replace the previous link (useful for theme or\n * font URLs that change).\n *\n * If `rel` is omitted in `attrubutes`, it defaults to `stylesheet`. Other attributes (`crossorigin`,\n * `media`, `data-*`, etc.) are set via `setAttribute` from the record entries.\n *\n * @param url - Stylesheet URL (`href`).\n * @param attrubutes - Optional HTML attributes for the `<link>` element (see `id` / `rel` behavior above).\n * @returns Promise that resolves to `undefined` on load, or rejects on load error.\n *\n * @example\n * ```ts\n * await loadCssFile('https://example.com/fonts.css', {\n * id: 'app-fonts',\n * crossOrigin: 'anonymous',\n * });\n * ```\n *\n * @example\n * ```ts\n * // Swap theme stylesheet without duplicate link tags\n * await loadCssFile('/themes/dark.css', { id: 'theme' });\n * await loadCssFile('/themes/light.css', { id: 'theme' });\n * ```\n */\nexport const loadCssFile = (url: string, attrubutes?: Record<string, any>) =>\n new Promise((resolve, reject) => {\n let link: Maybe<HTMLLinkElement>;\n\n if (attrubutes?.id) {\n link = document.getElementById(attrubutes.id) as HTMLLinkElement | null;\n\n if (link) {\n link.remove();\n }\n }\n\n link = document.createElement('link');\n\n const handleLoad = () => {\n resolve(undefined);\n link!.removeEventListener('load', handleLoad);\n link!.removeEventListener('error', handleError);\n };\n\n const handleError = () => {\n reject(undefined);\n link!.removeEventListener('load', handleLoad);\n link!.removeEventListener('error', handleError);\n };\n\n link.addEventListener('load', handleLoad);\n link.addEventListener('error', handleError);\n\n link.setAttribute('href', url);\n\n if (!attrubutes?.rel) {\n link.setAttribute('rel', 'stylesheet');\n }\n\n Object.entries(attrubutes || {}).forEach(([key, value]) => {\n link.setAttribute(key, value);\n });\n\n document.head.appendChild(link);\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,IAAa,SAAS,IAAY,WAAW,OAAO,GAAG,KAAK,SAAS;;;;;;;;;;;;;;;;;;;;;AAsBrE,IAAa,MAAM,GAAG,SAAkC,QAAQ,KAAK,GAAG,KAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8D9E,IAAa,QAAQ,GAAG,SAAgB;CACtC,MAAM,SAAS,MAAO,GAAG,KAAK;AAC9B,SAAQ,GAAG,cAAqB,QAAQ,OAAO,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4D/D,IAAa,eAAe,KAAa,eACvC,IAAI,SAAS,SAAS,WAAW;CAC/B,IAAI;AAEJ,KAAI,YAAY,IAAI;AAClB,SAAO,SAAS,eAAe,WAAW,GAAG;AAE7C,MAAI,KACF,MAAK,QAAQ;;AAIjB,QAAO,SAAS,cAAc,OAAO;CAErC,MAAM,mBAAmB;AACvB,UAAQ,KAAA,EAAU;AAClB,OAAM,oBAAoB,QAAQ,WAAW;AAC7C,OAAM,oBAAoB,SAAS,YAAY;;CAGjD,MAAM,oBAAoB;AACxB,SAAO,KAAA,EAAU;AACjB,OAAM,oBAAoB,QAAQ,WAAW;AAC7C,OAAM,oBAAoB,SAAS,YAAY;;AAGjD,MAAK,iBAAiB,QAAQ,WAAW;AACzC,MAAK,iBAAiB,SAAS,YAAY;AAE3C,MAAK,aAAa,QAAQ,IAAI;AAE9B,KAAI,CAAC,YAAY,IACf,MAAK,aAAa,OAAO,aAAa;AAGxC,QAAO,QAAQ,cAAc,EAAE,CAAC,CAAC,SAAS,CAAC,KAAK,WAAW;AACzD,OAAK,aAAa,KAAK,MAAM;GAC7B;AAEF,UAAS,KAAK,YAAY,KAAK;EAC/B"}
|