yummies 7.19.4 → 7.20.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.
Files changed (162) hide show
  1. package/assert.cjs +1 -1
  2. package/assert.cjs.map +1 -1
  3. package/assert.js +1 -1
  4. package/assert.js.map +1 -1
  5. package/async.cjs +147 -137
  6. package/async.cjs.map +1 -1
  7. package/async.d.ts +98 -131
  8. package/async.js +147 -137
  9. package/async.js.map +1 -1
  10. package/common.cjs +3 -1
  11. package/common.cjs.map +1 -1
  12. package/common.d.ts +18 -24
  13. package/common.js +3 -1
  14. package/common.js.map +1 -1
  15. package/complex.cjs +1 -0
  16. package/complex.cjs.map +1 -1
  17. package/complex.js +1 -0
  18. package/complex.js.map +1 -1
  19. package/cookie.cjs +1 -1
  20. package/cookie.cjs.map +1 -1
  21. package/cookie.d.ts +0 -18
  22. package/cookie.js +1 -1
  23. package/cookie.js.map +1 -1
  24. package/css-cx.cjs +78 -0
  25. package/css-cx.cjs.map +1 -0
  26. package/css-cx.d.ts +69 -0
  27. package/css-cx.js +74 -0
  28. package/css-cx.js.map +1 -0
  29. package/css.cjs +32 -111
  30. package/css.cjs.map +1 -1
  31. package/css.d.ts +32 -42
  32. package/css.js +30 -107
  33. package/css.js.map +1 -1
  34. package/data.cjs +60 -50
  35. package/data.cjs.map +1 -1
  36. package/data.d.ts +21 -34
  37. package/data.js +60 -50
  38. package/data.js.map +1 -1
  39. package/date-time.cjs +104 -98
  40. package/date-time.cjs.map +1 -1
  41. package/date-time.d.ts +51 -57
  42. package/date-time.js +104 -97
  43. package/date-time.js.map +1 -1
  44. package/device.cjs +14 -19
  45. package/device.cjs.map +1 -1
  46. package/device.d.ts +15 -26
  47. package/device.js +14 -19
  48. package/device.js.map +1 -1
  49. package/encodings.cjs +1 -1
  50. package/encodings.cjs.map +1 -1
  51. package/encodings.d.ts +0 -17
  52. package/encodings.js +1 -1
  53. package/encodings.js.map +1 -1
  54. package/errors.cjs +1 -18
  55. package/errors.cjs.map +1 -1
  56. package/errors.d.ts +0 -17
  57. package/errors.js +1 -17
  58. package/errors.js.map +1 -1
  59. package/file.cjs +3 -17
  60. package/file.cjs.map +1 -1
  61. package/file.d.ts +1 -16
  62. package/file.js +3 -17
  63. package/file.js.map +1 -1
  64. package/format.cjs +1 -1
  65. package/format.cjs.map +1 -1
  66. package/format.js +1 -1
  67. package/format.js.map +1 -1
  68. package/html.cjs +112 -175
  69. package/html.cjs.map +1 -1
  70. package/html.d.ts +58 -57
  71. package/html.js +111 -172
  72. package/html.js.map +1 -1
  73. package/id-nanoid.cjs +36 -0
  74. package/id-nanoid.cjs.map +1 -0
  75. package/id-nanoid.d.ts +26 -0
  76. package/id-nanoid.js +32 -0
  77. package/id-nanoid.js.map +1 -0
  78. package/id.cjs +10 -45
  79. package/id.cjs.map +1 -1
  80. package/id.d.ts +27 -36
  81. package/id.js +6 -40
  82. package/id.js.map +1 -1
  83. package/imports.cjs +3 -18
  84. package/imports.cjs.map +1 -1
  85. package/imports.d.ts +1 -16
  86. package/imports.js +3 -17
  87. package/imports.js.map +1 -1
  88. package/math.cjs +16 -12
  89. package/math.cjs.map +1 -1
  90. package/math.d.ts +9 -24
  91. package/math.js +16 -12
  92. package/math.js.map +1 -1
  93. package/media.cjs +88 -89
  94. package/media.cjs.map +1 -1
  95. package/media.d.ts +72 -80
  96. package/media.js +88 -88
  97. package/media.js.map +1 -1
  98. package/mobx.cjs +0 -1
  99. package/mobx.cjs.map +1 -1
  100. package/mobx.js.map +1 -1
  101. package/ms.cjs +3 -17
  102. package/ms.cjs.map +1 -1
  103. package/ms.d.ts +1 -16
  104. package/ms.js +3 -17
  105. package/ms.js.map +1 -1
  106. package/number.cjs +1 -17
  107. package/number.cjs.map +1 -1
  108. package/number.d.ts +0 -16
  109. package/number.js +1 -17
  110. package/number.js.map +1 -1
  111. package/package.json +6 -6
  112. package/parser.cjs +1 -1
  113. package/parser.cjs.map +1 -1
  114. package/parser.js +1 -1
  115. package/parser.js.map +1 -1
  116. package/price.cjs +1 -1
  117. package/price.cjs.map +1 -1
  118. package/price.d.ts +0 -16
  119. package/price.js +1 -1
  120. package/price.js.map +1 -1
  121. package/random.cjs +37 -39
  122. package/random.cjs.map +1 -1
  123. package/random.d.ts +31 -40
  124. package/random.js +37 -39
  125. package/random.js.map +1 -1
  126. package/react.cjs +0 -1
  127. package/react.cjs.map +1 -1
  128. package/react.js.map +1 -1
  129. package/sanitize-html.cjs +82 -0
  130. package/sanitize-html.cjs.map +1 -0
  131. package/sanitize-html.d.ts +28 -0
  132. package/sanitize-html.js +79 -0
  133. package/sanitize-html.js.map +1 -0
  134. package/sound.cjs +1 -17
  135. package/sound.cjs.map +1 -1
  136. package/sound.d.ts +0 -16
  137. package/sound.js +1 -17
  138. package/sound.js.map +1 -1
  139. package/storage.cjs +7 -5
  140. package/storage.cjs.map +1 -1
  141. package/storage.d.ts +3 -17
  142. package/storage.js +7 -5
  143. package/storage.js.map +1 -1
  144. package/text.cjs +3 -17
  145. package/text.cjs.map +1 -1
  146. package/text.d.ts +1 -16
  147. package/text.js +3 -17
  148. package/text.js.map +1 -1
  149. package/type-guard.cjs +38 -1
  150. package/type-guard.cjs.map +1 -1
  151. package/type-guard.d.ts +38 -0
  152. package/type-guard.js +38 -1
  153. package/type-guard.js.map +1 -1
  154. package/types.d.ts +10 -1
  155. package/types.global.d.ts +9 -0
  156. package/vibrate.cjs +1 -17
  157. package/vibrate.cjs.map +1 -1
  158. package/vibrate.d.ts +0 -16
  159. package/vibrate.js +1 -17
  160. package/vibrate.js.map +1 -1
  161. /package/{chunk-pbuEa-1d.js → chunk-D7D4PA-g.js} +0 -0
  162. /package/{chunk-CZWwpsFl.cjs → chunk-DakpK96I.cjs} +0 -0
package/css-cx.js ADDED
@@ -0,0 +1,74 @@
1
+ import { cva as cva$1 } from "class-variance-authority";
2
+ import clsx from "clsx";
3
+ import { twMerge } from "tailwind-merge";
4
+ //#region src/css/css-cx.ts
5
+ /**
6
+ * @internal Separate chunk so clsx + tailwind-merge + class-variance-authority are tree-shaken
7
+ * away when `cx`/`cva` are not used. Consumers import from `yummies/css` — this module is not a
8
+ * public entry point.
9
+ */
10
+ /**
11
+ * Composes conditional class names like {@link https://github.com/lukeed/clsx | clsx}, then runs
12
+ * the result through {@link https://github.com/dcastil/tailwind-merge | tailwind-merge} so
13
+ * conflicting Tailwind utilities collapse to the last/intended one (e.g. two `padding-x` classes).
14
+ *
15
+ * Accepts the same argument shapes as `clsx`: strings, objects, arrays, falsy values to omit.
16
+ *
17
+ * @param args - Same as `clsx(...args)` — `ClassValue` rest parameters.
18
+ * @returns A single merged class string, safe for `className` on DOM/React.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * cx('px-2 py-1 text-sm', 'px-4'); // 'py-1 text-sm px-4' — padding-x merged
23
+ * ```
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * cx('btn', { 'btn--active': isActive, 'btn--disabled': disabled }, className);
28
+ * ```
29
+ */
30
+ var cx = (...args) => twMerge(clsx(...args));
31
+ /**
32
+ * {@link https://cva.style/docs | Class Variance Authority (cva)} with the same **tailwind-merge**
33
+ * pass as {@link cx}: the class string produced by the variant function is merged so Tailwind
34
+ * conflicts resolve predictably.
35
+ *
36
+ * API matches `cva` from `class-variance-authority`: optional `base` classes, `config` with
37
+ * `variants`, `defaultVariants`, and `compoundVariants`. The returned function accepts variant
38
+ * props plus optional `class` / `className` for one-off overrides.
39
+ *
40
+ * Use {@link VariantProps} with `typeof buttonVariants` (or similar) to type component props.
41
+ *
42
+ * @param base - Base `ClassValue`(s) always applied.
43
+ * @param config - Variant schema and defaults (same shape as upstream `cva`).
44
+ * @returns A function `(props?) => string` that resolves variant classes, merged with tw-merge.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * const button = cva('rounded font-medium', {
49
+ * variants: {
50
+ * tone: { primary: 'bg-blue-600 text-white', ghost: 'bg-transparent' },
51
+ * size: { sm: 'text-sm px-2', md: 'text-base px-4' },
52
+ * },
53
+ * defaultVariants: { tone: 'primary', size: 'md' },
54
+ * });
55
+ * button({ tone: 'ghost', className: 'ml-2' });
56
+ * ```
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * const card = cva('border p-4', {
61
+ * variants: { elevated: { true: 'shadow-lg', false: 'shadow-none' } },
62
+ * defaultVariants: { elevated: false },
63
+ * });
64
+ * card({ elevated: true });
65
+ * ```
66
+ */
67
+ var cva = ((...args) => {
68
+ const schema = cva$1(...args);
69
+ return (...inputArgs) => twMerge(schema(...inputArgs));
70
+ });
71
+ //#endregion
72
+ export { cva, cx };
73
+
74
+ //# sourceMappingURL=css-cx.js.map
package/css-cx.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"css-cx.js","names":[],"sources":["../src/css/css-cx.ts"],"sourcesContent":["/**\n * @internal Separate chunk so clsx + tailwind-merge + class-variance-authority are tree-shaken\n * away when `cx`/`cva` are not used. Consumers import from `yummies/css` — this module is not a\n * public entry point.\n */\n\nimport { cva as cvaLib } from 'class-variance-authority';\nimport clsx from 'clsx';\nimport { twMerge } from 'tailwind-merge';\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\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 unknown as typeof cvaLib;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,IAAa,MAAM,GAAG,SAAkC,QAAQ,KAAK,GAAG,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsC7E,IAAa,QAAQ,GAAG,SAAgB;CACtC,MAAM,SAAS,MAAO,GAAG,IAAI;CAC7B,QAAQ,GAAG,cAAqB,QAAQ,OAAO,GAAG,SAAS,CAAC;AAC9D"}
package/css.cjs CHANGED
@@ -1,113 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_chunk = require("./chunk-CZWwpsFl.cjs");
3
- let class_variance_authority = require("class-variance-authority");
4
- let clsx = require("clsx");
5
- clsx = require_chunk.__toESM(clsx, 1);
6
- let tailwind_merge = require("tailwind-merge");
7
- //#region src/css.ts
8
- /**
9
- * ---header-docs-section---
10
- * # yummies/css
11
- *
12
- * ## Description
13
- *
14
- * Styling utilities for React and plain DOM: `rem` conversion, `clsx` + `tailwind-merge` via `cx`,
15
- * and a `cva` bridge for variant-driven class names. The goal is predictable class strings without
16
- * Tailwind conflicts and with less boilerplate than concatenating strings by hand across components.
17
- *
18
- * ## Usage
19
- *
20
- * ```ts
21
- * import { cx, toRem } from "yummies/css";
22
- * ```
23
- */
24
- /**
25
- * Converts a length in **pixels** to a CSS **`rem`** string (`"<number>rem"`).
26
- *
27
- * Use when authoring component styles in JS/TS where design tokens are in px but the stylesheet
28
- * should scale with root font size (accessibility, user zoom). `remValue` is the assumed
29
- * `1rem` size in px (browser default is typically `16`).
30
- *
31
- * Also you can override default rem value using `toRem.defaultRemValue = 24`
32
- *
33
- * @param px - Pixel value to convert (not rounded; stringification keeps full float).
34
- * @param remValue - How many pixels one `rem` equals. Defaults to `16`.
35
- * @returns A string like `"1.5rem"` suitable for `style` or CSS-in-JS.
36
- *
37
- * @example
38
- * ```ts
39
- * const width = toRem(24); // '1.5rem' with default 16px root
40
- * ```
41
- *
42
- * @example
43
- * ```ts
44
- * // Custom root / design system where 1rem === 10px
45
- * const gap = toRem(20, 10); // '2rem'
46
- * ```
47
- */
48
- var toRem = (px, remValue) => `${px / (remValue ?? toRem.defaultRemValue)}rem`;
49
- toRem.defaultRemValue = 16;
50
- /**
51
- * Composes conditional class names like {@link https://github.com/lukeed/clsx | clsx}, then runs
52
- * the result through {@link https://github.com/dcastil/tailwind-merge | tailwind-merge} so
53
- * conflicting Tailwind utilities collapse to the last/intended one (e.g. two `padding-x` classes).
54
- *
55
- * Accepts the same argument shapes as `clsx`: strings, objects, arrays, falsy values to omit.
56
- *
57
- * @param args - Same as `clsx(...args)` — `ClassValue` rest parameters.
58
- * @returns A single merged class string, safe for `className` on DOM/React.
59
- *
60
- * @example
61
- * ```ts
62
- * cx('px-2 py-1 text-sm', 'px-4'); // 'py-1 text-sm px-4' — padding-x merged
63
- * ```
64
- *
65
- * @example
66
- * ```ts
67
- * cx('btn', { 'btn--active': isActive, 'btn--disabled': disabled }, className);
68
- * ```
69
- */
70
- var cx = (...args) => (0, tailwind_merge.twMerge)((0, clsx.default)(...args));
71
- /**
72
- * {@link https://cva.style/docs | Class Variance Authority (cva)} with the same **tailwind-merge**
73
- * pass as {@link cx}: the class string produced by the variant function is merged so Tailwind
74
- * conflicts resolve predictably.
75
- *
76
- * API matches `cva` from `class-variance-authority`: optional `base` classes, `config` with
77
- * `variants`, `defaultVariants`, and `compoundVariants`. The returned function accepts variant
78
- * props plus optional `class` / `className` for one-off overrides.
79
- *
80
- * Use {@link VariantProps} with `typeof buttonVariants` (or similar) to type component props.
81
- *
82
- * @param base - Base `ClassValue`(s) always applied.
83
- * @param config - Variant schema and defaults (same shape as upstream `cva`).
84
- * @returns A function `(props?) => string` that resolves variant classes, merged with tw-merge.
85
- *
86
- * @example
87
- * ```ts
88
- * const button = cva('rounded font-medium', {
89
- * variants: {
90
- * tone: { primary: 'bg-blue-600 text-white', ghost: 'bg-transparent' },
91
- * size: { sm: 'text-sm px-2', md: 'text-base px-4' },
92
- * },
93
- * defaultVariants: { tone: 'primary', size: 'md' },
94
- * });
95
- * button({ tone: 'ghost', className: 'ml-2' });
96
- * ```
97
- *
98
- * @example
99
- * ```ts
100
- * const card = cva('border p-4', {
101
- * variants: { elevated: { true: 'shadow-lg', false: 'shadow-none' } },
102
- * defaultVariants: { elevated: false },
103
- * });
104
- * card({ elevated: true });
105
- * ```
106
- */
107
- var cva = ((...args) => {
108
- const schema = (0, class_variance_authority.cva)(...args);
109
- return (...inputArgs) => (0, tailwind_merge.twMerge)(schema(...inputArgs));
110
- });
2
+ const require_css_cx = require("./css-cx.cjs");
3
+ //#region src/css/load-css-file.ts
111
4
  /**
112
5
  * Injects a stylesheet by appending a `<link rel="stylesheet">` to `document.head`.
113
6
  * Resolves when the sheet fires `load`; rejects on `error` (e.g. 404 or network failure).
@@ -165,8 +58,36 @@ var loadCssFile = (url, attrubutes) => new Promise((resolve, reject) => {
165
58
  document.head.appendChild(link);
166
59
  });
167
60
  //#endregion
168
- exports.cva = cva;
169
- exports.cx = cx;
61
+ //#region src/css/to-rem.ts
62
+ /**
63
+ * Converts a length in **pixels** to a CSS **`rem`** string (`"<number>rem"`).
64
+ *
65
+ * Use when authoring component styles in JS/TS where design tokens are in px but the stylesheet
66
+ * should scale with root font size (accessibility, user zoom). `remValue` is the assumed
67
+ * `1rem` size in px (browser default is typically `16`).
68
+ *
69
+ * Also you can override default rem value using `toRem.defaultRemValue = 24`
70
+ *
71
+ * @param px - Pixel value to convert (not rounded; stringification keeps full float).
72
+ * @param remValue - How many pixels one `rem` equals. Defaults to `16`.
73
+ * @returns A string like `"1.5rem"` suitable for `style` or CSS-in-JS.
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * const width = toRem(24); // '1.5rem' with default 16px root
78
+ * ```
79
+ *
80
+ * @example
81
+ * ```ts
82
+ * // Custom root / design system where 1rem === 10px
83
+ * const gap = toRem(20, 10); // '2rem'
84
+ * ```
85
+ */
86
+ var toRem = (px, remValue) => `${px / (remValue ?? toRem.defaultRemValue)}rem`;
87
+ toRem.defaultRemValue = 16;
88
+ //#endregion
89
+ exports.cva = require_css_cx.cva;
90
+ exports.cx = require_css_cx.cx;
170
91
  exports.loadCssFile = loadCssFile;
171
92
  exports.toRem = toRem;
172
93
 
package/css.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"css.cjs","names":[],"sources":["../src/css.ts"],"sourcesContent":["/**\n * ---header-docs-section---\n * # yummies/css\n *\n * ## Description\n *\n * Styling utilities for React and plain DOM: `rem` conversion, `clsx` + `tailwind-merge` via `cx`,\n * and a `cva` bridge for variant-driven class names. The goal is predictable class strings without\n * Tailwind conflicts and with less boilerplate than concatenating strings by hand across components.\n *\n * ## Usage\n *\n * ```ts\n * import { cx, toRem } from \"yummies/css\";\n * ```\n */\n\nimport { cva as cvaLib, VariantProps } from 'class-variance-authority';\nimport clsx from 'clsx';\nimport { twMerge } from 'tailwind-merge';\nimport type { Maybe } from 'yummies/types';\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 * Also you can override default rem value using `toRem.defaultRemValue = 24`\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?: number): string =>\n `${px / (remValue ?? toRem.defaultRemValue)}rem`;\n\ntoRem.defaultRemValue = 16;\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\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 unknown as typeof cvaLib;\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,IAAa,SAAS,IAAY,aAChC,GAAG,MAAM,YAAY,MAAM,iBAAiB;AAE9C,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;AAsBxB,IAAa,MAAM,GAAG,UAAA,GAAA,eAAA,UAAA,GAAA,KAAA,SAA+C,GAAG,KAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsC9E,IAAa,QAAQ,GAAG,SAAgB;CACtC,MAAM,UAAA,GAAA,yBAAA,KAAgB,GAAG,KAAK;AAC9B,SAAQ,GAAG,eAAA,GAAA,eAAA,SAA6B,OAAO,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyD/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"}
1
+ {"version":3,"file":"css.cjs","names":[],"sources":["../src/css/load-css-file.ts","../src/css/to-rem.ts"],"sourcesContent":["import type { Maybe } from 'yummies/types';\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","/**\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 * Also you can override default rem value using `toRem.defaultRemValue = 24`\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?: number): string =>\n `${px / (remValue ?? toRem.defaultRemValue)}rem`;\n\ntoRem.defaultRemValue = 16;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,IAAa,eAAe,KAAa,eACvC,IAAI,SAAS,SAAS,WAAW;CAC/B,IAAI;CAEJ,IAAI,YAAY,IAAI;EAClB,OAAO,SAAS,eAAe,WAAW,EAAE;EAE5C,IAAI,MACF,KAAK,OAAO;CAEhB;CAEA,OAAO,SAAS,cAAc,MAAM;CAEpC,MAAM,mBAAmB;EACvB,QAAQ,KAAA,CAAS;EACjB,KAAM,oBAAoB,QAAQ,UAAU;EAC5C,KAAM,oBAAoB,SAAS,WAAW;CAChD;CAEA,MAAM,oBAAoB;EACxB,OAAO,KAAA,CAAS;EAChB,KAAM,oBAAoB,QAAQ,UAAU;EAC5C,KAAM,oBAAoB,SAAS,WAAW;CAChD;CAEA,KAAK,iBAAiB,QAAQ,UAAU;CACxC,KAAK,iBAAiB,SAAS,WAAW;CAE1C,KAAK,aAAa,QAAQ,GAAG;CAE7B,IAAI,CAAC,YAAY,KACf,KAAK,aAAa,OAAO,YAAY;CAGvC,OAAO,QAAQ,cAAc,CAAC,CAAC,EAAE,SAAS,CAAC,KAAK,WAAW;EACzD,KAAK,aAAa,KAAK,KAAK;CAC9B,CAAC;CAED,SAAS,KAAK,YAAY,IAAI;AAChC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;AChDH,IAAa,SAAS,IAAY,aAChC,GAAG,MAAM,YAAY,MAAM,iBAAiB;AAE9C,MAAM,kBAAkB"}
package/css.d.ts CHANGED
@@ -4,50 +4,11 @@ import clsx from 'clsx';
4
4
  export { ClassValue } from 'clsx';
5
5
 
6
6
  /**
7
- * ---header-docs-section---
8
- * # yummies/css
9
- *
10
- * ## Description
11
- *
12
- * Styling utilities for React and plain DOM: `rem` conversion, `clsx` + `tailwind-merge` via `cx`,
13
- * and a `cva` bridge for variant-driven class names. The goal is predictable class strings without
14
- * Tailwind conflicts and with less boilerplate than concatenating strings by hand across components.
15
- *
16
- * ## Usage
17
- *
18
- * ```ts
19
- * import { cx, toRem } from "yummies/css";
20
- * ```
7
+ * @internal Separate chunk so clsx + tailwind-merge + class-variance-authority are tree-shaken
8
+ * away when `cx`/`cva` are not used. Consumers import from `yummies/css` — this module is not a
9
+ * public entry point.
21
10
  */
22
11
 
23
- /**
24
- * Converts a length in **pixels** to a CSS **`rem`** string (`"<number>rem"`).
25
- *
26
- * Use when authoring component styles in JS/TS where design tokens are in px but the stylesheet
27
- * should scale with root font size (accessibility, user zoom). `remValue` is the assumed
28
- * `1rem` size in px (browser default is typically `16`).
29
- *
30
- * Also you can override default rem value using `toRem.defaultRemValue = 24`
31
- *
32
- * @param px - Pixel value to convert (not rounded; stringification keeps full float).
33
- * @param remValue - How many pixels one `rem` equals. Defaults to `16`.
34
- * @returns A string like `"1.5rem"` suitable for `style` or CSS-in-JS.
35
- *
36
- * @example
37
- * ```ts
38
- * const width = toRem(24); // '1.5rem' with default 16px root
39
- * ```
40
- *
41
- * @example
42
- * ```ts
43
- * // Custom root / design system where 1rem === 10px
44
- * const gap = toRem(20, 10); // '2rem'
45
- * ```
46
- */
47
- declare const toRem: {
48
- (px: number, remValue?: number): string;
49
- defaultRemValue: number;
50
- };
51
12
  /**
52
13
  * Composes conditional class names like {@link https://github.com/lukeed/clsx | clsx}, then runs
53
14
  * the result through {@link https://github.com/dcastil/tailwind-merge | tailwind-merge} so
@@ -139,4 +100,33 @@ declare const cva: typeof cva$1;
139
100
  */
140
101
  declare const loadCssFile: (url: string, attrubutes?: Record<string, any>) => Promise<unknown>;
141
102
 
103
+ /**
104
+ * Converts a length in **pixels** to a CSS **`rem`** string (`"<number>rem"`).
105
+ *
106
+ * Use when authoring component styles in JS/TS where design tokens are in px but the stylesheet
107
+ * should scale with root font size (accessibility, user zoom). `remValue` is the assumed
108
+ * `1rem` size in px (browser default is typically `16`).
109
+ *
110
+ * Also you can override default rem value using `toRem.defaultRemValue = 24`
111
+ *
112
+ * @param px - Pixel value to convert (not rounded; stringification keeps full float).
113
+ * @param remValue - How many pixels one `rem` equals. Defaults to `16`.
114
+ * @returns A string like `"1.5rem"` suitable for `style` or CSS-in-JS.
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * const width = toRem(24); // '1.5rem' with default 16px root
119
+ * ```
120
+ *
121
+ * @example
122
+ * ```ts
123
+ * // Custom root / design system where 1rem === 10px
124
+ * const gap = toRem(20, 10); // '2rem'
125
+ * ```
126
+ */
127
+ declare const toRem: {
128
+ (px: number, remValue?: number): string;
129
+ defaultRemValue: number;
130
+ };
131
+
142
132
  export { cva, cx, loadCssFile, toRem };
package/css.js CHANGED
@@ -1,110 +1,5 @@
1
- import { cva as cva$1 } from "class-variance-authority";
2
- import clsx from "clsx";
3
- import { twMerge } from "tailwind-merge";
4
- //#region src/css.ts
5
- /**
6
- * ---header-docs-section---
7
- * # yummies/css
8
- *
9
- * ## Description
10
- *
11
- * Styling utilities for React and plain DOM: `rem` conversion, `clsx` + `tailwind-merge` via `cx`,
12
- * and a `cva` bridge for variant-driven class names. The goal is predictable class strings without
13
- * Tailwind conflicts and with less boilerplate than concatenating strings by hand across components.
14
- *
15
- * ## Usage
16
- *
17
- * ```ts
18
- * import { cx, toRem } from "yummies/css";
19
- * ```
20
- */
21
- /**
22
- * Converts a length in **pixels** to a CSS **`rem`** string (`"<number>rem"`).
23
- *
24
- * Use when authoring component styles in JS/TS where design tokens are in px but the stylesheet
25
- * should scale with root font size (accessibility, user zoom). `remValue` is the assumed
26
- * `1rem` size in px (browser default is typically `16`).
27
- *
28
- * Also you can override default rem value using `toRem.defaultRemValue = 24`
29
- *
30
- * @param px - Pixel value to convert (not rounded; stringification keeps full float).
31
- * @param remValue - How many pixels one `rem` equals. Defaults to `16`.
32
- * @returns A string like `"1.5rem"` suitable for `style` or CSS-in-JS.
33
- *
34
- * @example
35
- * ```ts
36
- * const width = toRem(24); // '1.5rem' with default 16px root
37
- * ```
38
- *
39
- * @example
40
- * ```ts
41
- * // Custom root / design system where 1rem === 10px
42
- * const gap = toRem(20, 10); // '2rem'
43
- * ```
44
- */
45
- var toRem = (px, remValue) => `${px / (remValue ?? toRem.defaultRemValue)}rem`;
46
- toRem.defaultRemValue = 16;
47
- /**
48
- * Composes conditional class names like {@link https://github.com/lukeed/clsx | clsx}, then runs
49
- * the result through {@link https://github.com/dcastil/tailwind-merge | tailwind-merge} so
50
- * conflicting Tailwind utilities collapse to the last/intended one (e.g. two `padding-x` classes).
51
- *
52
- * Accepts the same argument shapes as `clsx`: strings, objects, arrays, falsy values to omit.
53
- *
54
- * @param args - Same as `clsx(...args)` — `ClassValue` rest parameters.
55
- * @returns A single merged class string, safe for `className` on DOM/React.
56
- *
57
- * @example
58
- * ```ts
59
- * cx('px-2 py-1 text-sm', 'px-4'); // 'py-1 text-sm px-4' — padding-x merged
60
- * ```
61
- *
62
- * @example
63
- * ```ts
64
- * cx('btn', { 'btn--active': isActive, 'btn--disabled': disabled }, className);
65
- * ```
66
- */
67
- var cx = (...args) => twMerge(clsx(...args));
68
- /**
69
- * {@link https://cva.style/docs | Class Variance Authority (cva)} with the same **tailwind-merge**
70
- * pass as {@link cx}: the class string produced by the variant function is merged so Tailwind
71
- * conflicts resolve predictably.
72
- *
73
- * API matches `cva` from `class-variance-authority`: optional `base` classes, `config` with
74
- * `variants`, `defaultVariants`, and `compoundVariants`. The returned function accepts variant
75
- * props plus optional `class` / `className` for one-off overrides.
76
- *
77
- * Use {@link VariantProps} with `typeof buttonVariants` (or similar) to type component props.
78
- *
79
- * @param base - Base `ClassValue`(s) always applied.
80
- * @param config - Variant schema and defaults (same shape as upstream `cva`).
81
- * @returns A function `(props?) => string` that resolves variant classes, merged with tw-merge.
82
- *
83
- * @example
84
- * ```ts
85
- * const button = cva('rounded font-medium', {
86
- * variants: {
87
- * tone: { primary: 'bg-blue-600 text-white', ghost: 'bg-transparent' },
88
- * size: { sm: 'text-sm px-2', md: 'text-base px-4' },
89
- * },
90
- * defaultVariants: { tone: 'primary', size: 'md' },
91
- * });
92
- * button({ tone: 'ghost', className: 'ml-2' });
93
- * ```
94
- *
95
- * @example
96
- * ```ts
97
- * const card = cva('border p-4', {
98
- * variants: { elevated: { true: 'shadow-lg', false: 'shadow-none' } },
99
- * defaultVariants: { elevated: false },
100
- * });
101
- * card({ elevated: true });
102
- * ```
103
- */
104
- var cva = ((...args) => {
105
- const schema = cva$1(...args);
106
- return (...inputArgs) => twMerge(schema(...inputArgs));
107
- });
1
+ import { cva, cx } from "./css-cx.js";
2
+ //#region src/css/load-css-file.ts
108
3
  /**
109
4
  * Injects a stylesheet by appending a `<link rel="stylesheet">` to `document.head`.
110
5
  * Resolves when the sheet fires `load`; rejects on `error` (e.g. 404 or network failure).
@@ -162,6 +57,34 @@ var loadCssFile = (url, attrubutes) => new Promise((resolve, reject) => {
162
57
  document.head.appendChild(link);
163
58
  });
164
59
  //#endregion
60
+ //#region src/css/to-rem.ts
61
+ /**
62
+ * Converts a length in **pixels** to a CSS **`rem`** string (`"<number>rem"`).
63
+ *
64
+ * Use when authoring component styles in JS/TS where design tokens are in px but the stylesheet
65
+ * should scale with root font size (accessibility, user zoom). `remValue` is the assumed
66
+ * `1rem` size in px (browser default is typically `16`).
67
+ *
68
+ * Also you can override default rem value using `toRem.defaultRemValue = 24`
69
+ *
70
+ * @param px - Pixel value to convert (not rounded; stringification keeps full float).
71
+ * @param remValue - How many pixels one `rem` equals. Defaults to `16`.
72
+ * @returns A string like `"1.5rem"` suitable for `style` or CSS-in-JS.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * const width = toRem(24); // '1.5rem' with default 16px root
77
+ * ```
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * // Custom root / design system where 1rem === 10px
82
+ * const gap = toRem(20, 10); // '2rem'
83
+ * ```
84
+ */
85
+ var toRem = (px, remValue) => `${px / (remValue ?? toRem.defaultRemValue)}rem`;
86
+ toRem.defaultRemValue = 16;
87
+ //#endregion
165
88
  export { cva, cx, loadCssFile, toRem };
166
89
 
167
90
  //# sourceMappingURL=css.js.map
package/css.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"css.js","names":[],"sources":["../src/css.ts"],"sourcesContent":["/**\n * ---header-docs-section---\n * # yummies/css\n *\n * ## Description\n *\n * Styling utilities for React and plain DOM: `rem` conversion, `clsx` + `tailwind-merge` via `cx`,\n * and a `cva` bridge for variant-driven class names. The goal is predictable class strings without\n * Tailwind conflicts and with less boilerplate than concatenating strings by hand across components.\n *\n * ## Usage\n *\n * ```ts\n * import { cx, toRem } from \"yummies/css\";\n * ```\n */\n\nimport { cva as cvaLib, VariantProps } from 'class-variance-authority';\nimport clsx from 'clsx';\nimport { twMerge } from 'tailwind-merge';\nimport type { Maybe } from 'yummies/types';\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 * Also you can override default rem value using `toRem.defaultRemValue = 24`\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?: number): string =>\n `${px / (remValue ?? toRem.defaultRemValue)}rem`;\n\ntoRem.defaultRemValue = 16;\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\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 unknown as typeof cvaLib;\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,IAAa,SAAS,IAAY,aAChC,GAAG,MAAM,YAAY,MAAM,iBAAiB;AAE9C,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;AAsBxB,IAAa,MAAM,GAAG,SAAkC,QAAQ,KAAK,GAAG,KAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsC9E,IAAa,QAAQ,GAAG,SAAgB;CACtC,MAAM,SAAS,MAAO,GAAG,KAAK;AAC9B,SAAQ,GAAG,cAAqB,QAAQ,OAAO,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyD/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"}
1
+ {"version":3,"file":"css.js","names":[],"sources":["../src/css/load-css-file.ts","../src/css/to-rem.ts"],"sourcesContent":["import type { Maybe } from 'yummies/types';\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","/**\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 * Also you can override default rem value using `toRem.defaultRemValue = 24`\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?: number): string =>\n `${px / (remValue ?? toRem.defaultRemValue)}rem`;\n\ntoRem.defaultRemValue = 16;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,IAAa,eAAe,KAAa,eACvC,IAAI,SAAS,SAAS,WAAW;CAC/B,IAAI;CAEJ,IAAI,YAAY,IAAI;EAClB,OAAO,SAAS,eAAe,WAAW,EAAE;EAE5C,IAAI,MACF,KAAK,OAAO;CAEhB;CAEA,OAAO,SAAS,cAAc,MAAM;CAEpC,MAAM,mBAAmB;EACvB,QAAQ,KAAA,CAAS;EACjB,KAAM,oBAAoB,QAAQ,UAAU;EAC5C,KAAM,oBAAoB,SAAS,WAAW;CAChD;CAEA,MAAM,oBAAoB;EACxB,OAAO,KAAA,CAAS;EAChB,KAAM,oBAAoB,QAAQ,UAAU;EAC5C,KAAM,oBAAoB,SAAS,WAAW;CAChD;CAEA,KAAK,iBAAiB,QAAQ,UAAU;CACxC,KAAK,iBAAiB,SAAS,WAAW;CAE1C,KAAK,aAAa,QAAQ,GAAG;CAE7B,IAAI,CAAC,YAAY,KACf,KAAK,aAAa,OAAO,YAAY;CAGvC,OAAO,QAAQ,cAAc,CAAC,CAAC,EAAE,SAAS,CAAC,KAAK,WAAW;EACzD,KAAK,aAAa,KAAK,KAAK;CAC9B,CAAC;CAED,SAAS,KAAK,YAAY,IAAI;AAChC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;AChDH,IAAa,SAAS,IAAY,aAChC,GAAG,MAAM,YAAY,MAAM,iBAAiB;AAE9C,MAAM,kBAAkB"}