yummies 7.11.0 → 7.13.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 (159) hide show
  1. package/README.md +5 -87
  2. package/async.cjs +179 -48
  3. package/async.cjs.map +1 -1
  4. package/async.d.ts +125 -7
  5. package/async.js +180 -54
  6. package/async.js.map +1 -1
  7. package/chunk-CVq3Gv4J.cjs +50 -0
  8. package/chunk-YKewjYmz.js +37 -0
  9. package/common.cjs +48 -8
  10. package/common.cjs.map +1 -1
  11. package/common.d.ts +53 -2
  12. package/common.js +49 -11
  13. package/common.js.map +1 -1
  14. package/complex.cjs +275 -128
  15. package/complex.cjs.map +1 -1
  16. package/complex.d.ts +66 -0
  17. package/complex.js +275 -133
  18. package/complex.js.map +1 -1
  19. package/cookie.cjs +17 -7
  20. package/cookie.cjs.map +1 -1
  21. package/cookie.d.ts +26 -0
  22. package/cookie.js +18 -9
  23. package/cookie.js.map +1 -1
  24. package/css.cjs +163 -39
  25. package/css.cjs.map +1 -1
  26. package/css.d.ts +115 -6
  27. package/css.js +159 -41
  28. package/css.js.map +1 -1
  29. package/data.cjs +90 -55
  30. package/data.cjs.map +1 -1
  31. package/data.d.ts +50 -0
  32. package/data.js +91 -61
  33. package/data.js.map +1 -1
  34. package/date-time.cjs +594 -412
  35. package/date-time.cjs.map +1 -1
  36. package/date-time.d.ts +105 -0
  37. package/date-time.js +591 -421
  38. package/date-time.js.map +1 -1
  39. package/device.cjs +65 -23
  40. package/device.cjs.map +1 -1
  41. package/device.d.ts +49 -0
  42. package/device.js +66 -31
  43. package/device.js.map +1 -1
  44. package/encodings.cjs +275 -266
  45. package/encodings.cjs.map +1 -1
  46. package/encodings.d.ts +25 -0
  47. package/encodings.js +276 -268
  48. package/encodings.js.map +1 -1
  49. package/errors.cjs +36 -18
  50. package/errors.cjs.map +1 -1
  51. package/errors.d.ts +17 -0
  52. package/errors.js +35 -19
  53. package/errors.js.map +1 -1
  54. package/file.cjs +58 -24
  55. package/file.cjs.map +1 -1
  56. package/file.d.ts +32 -0
  57. package/file.js +59 -27
  58. package/file.js.map +1 -1
  59. package/format.cjs +125 -83
  60. package/format.cjs.map +1 -1
  61. package/format.d.ts +18 -0
  62. package/format.js +118 -82
  63. package/format.js.map +1 -1
  64. package/html.cjs +242 -137
  65. package/html.cjs.map +1 -1
  66. package/html.d.ts +81 -0
  67. package/html.js +239 -150
  68. package/html.js.map +1 -1
  69. package/id.cjs +90 -17
  70. package/id.cjs.map +1 -1
  71. package/id.d.ts +16 -0
  72. package/id.js +89 -24
  73. package/id.js.map +1 -1
  74. package/imports.cjs +57 -29
  75. package/imports.cjs.map +1 -1
  76. package/imports.d.ts +24 -0
  77. package/imports.js +56 -31
  78. package/imports.js.map +1 -1
  79. package/math.cjs +32 -6
  80. package/math.cjs.map +1 -1
  81. package/math.d.ts +33 -0
  82. package/math.js +33 -10
  83. package/math.js.map +1 -1
  84. package/media.cjs +291 -84
  85. package/media.cjs.map +1 -1
  86. package/media.d.ts +204 -2
  87. package/media.js +290 -93
  88. package/media.js.map +1 -1
  89. package/mobx.cjs +449 -193
  90. package/mobx.cjs.map +1 -1
  91. package/mobx.d.ts +108 -0
  92. package/mobx.js +447 -200
  93. package/mobx.js.map +1 -1
  94. package/ms.cjs +37 -10
  95. package/ms.cjs.map +1 -1
  96. package/ms.d.ts +16 -0
  97. package/ms.js +38 -13
  98. package/ms.js.map +1 -1
  99. package/number.cjs +29 -7
  100. package/number.cjs.map +1 -1
  101. package/number.d.ts +16 -0
  102. package/number.js +30 -9
  103. package/number.js.map +1 -1
  104. package/package.json +11 -3
  105. package/parser.cjs +117 -64
  106. package/parser.cjs.map +1 -1
  107. package/parser.d.ts +17 -0
  108. package/parser.js +111 -64
  109. package/parser.js.map +1 -1
  110. package/price.cjs +24 -18
  111. package/price.cjs.map +1 -1
  112. package/price.d.ts +24 -0
  113. package/price.js +25 -20
  114. package/price.js.map +1 -1
  115. package/random.cjs +95 -13
  116. package/random.cjs.map +1 -1
  117. package/random.d.ts +80 -0
  118. package/random.js +96 -22
  119. package/random.js.map +1 -1
  120. package/react.cjs +673 -214
  121. package/react.cjs.map +1 -1
  122. package/react.d.ts +21 -0
  123. package/react.js +674 -239
  124. package/react.js.map +1 -1
  125. package/sound.cjs +30 -9
  126. package/sound.cjs.map +1 -1
  127. package/sound.d.ts +16 -0
  128. package/sound.js +31 -11
  129. package/sound.js.map +1 -1
  130. package/storage.cjs +49 -50
  131. package/storage.cjs.map +1 -1
  132. package/storage.d.ts +24 -0
  133. package/storage.js +50 -53
  134. package/storage.js.map +1 -1
  135. package/text.cjs +67 -34
  136. package/text.cjs.map +1 -1
  137. package/text.d.ts +16 -0
  138. package/text.js +68 -37
  139. package/text.js.map +1 -1
  140. package/type-guard.cjs +292 -72
  141. package/type-guard.cjs.map +1 -1
  142. package/type-guard.d.ts +18 -0
  143. package/type-guard.js +288 -73
  144. package/type-guard.js.map +1 -1
  145. package/types.cjs +0 -2
  146. package/types.d.ts +41 -0
  147. package/types.global.cjs +0 -2
  148. package/types.global.d.ts +41 -0
  149. package/types.global.js +0 -2
  150. package/types.js +0 -2
  151. package/vibrate.cjs +47 -6
  152. package/vibrate.cjs.map +1 -1
  153. package/vibrate.d.ts +39 -1
  154. package/vibrate.js +48 -8
  155. package/vibrate.js.map +1 -1
  156. package/types.cjs.map +0 -1
  157. package/types.global.cjs.map +0 -1
  158. package/types.global.js.map +0 -1
  159. package/types.js.map +0 -1
package/css.cjs CHANGED
@@ -1,46 +1,170 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const classVarianceAuthority = require("class-variance-authority");
4
- const clsx = require("clsx");
5
- const tailwindMerge = require("tailwind-merge");
6
- const toRem = (px, remValue = 16) => `${px / remValue}rem`;
7
- const cx = (...args) => tailwindMerge.twMerge(clsx(...args));
8
- const cva = ((...args) => {
9
- const schema = classVarianceAuthority.cva(...args);
10
- return (...inputArgs) => tailwindMerge.twMerge(schema(...inputArgs));
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
+ * ---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
+ * @param px - Pixel value to convert (not rounded; stringification keeps full float).
32
+ * @param remValue - How many pixels one `rem` equals. Defaults to `16`.
33
+ * @returns A string like `"1.5rem"` suitable for `style` or CSS-in-JS.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * const width = toRem(24); // '1.5rem' with default 16px root
38
+ * ```
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * // Custom root / design system where 1rem === 10px
43
+ * const gap = toRem(20, 10); // '2rem'
44
+ * ```
45
+ */
46
+ var toRem = (px, remValue = 16) => `${px / remValue}rem`;
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) => (0, tailwind_merge.twMerge)((0, clsx.default)(...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 = (0, class_variance_authority.cva)(...args);
106
+ return (...inputArgs) => (0, tailwind_merge.twMerge)(schema(...inputArgs));
11
107
  });
12
- const loadCssFile = (url, attrubutes) => new Promise((resolve, reject) => {
13
- let link;
14
- if (attrubutes?.id) {
15
- link = document.getElementById(attrubutes.id);
16
- if (link) {
17
- link.remove();
18
- }
19
- }
20
- link = document.createElement("link");
21
- const handleLoad = () => {
22
- resolve(void 0);
23
- link.removeEventListener("load", handleLoad);
24
- link.removeEventListener("error", handleError);
25
- };
26
- const handleError = () => {
27
- reject(void 0);
28
- link.removeEventListener("load", handleLoad);
29
- link.removeEventListener("error", handleError);
30
- };
31
- link.addEventListener("load", handleLoad);
32
- link.addEventListener("error", handleError);
33
- link.setAttribute("href", url);
34
- if (!attrubutes?.rel) {
35
- link.setAttribute("rel", "stylesheet");
36
- }
37
- Object.entries(attrubutes || {}).forEach(([key, value]) => {
38
- link.setAttribute(key, value);
39
- });
40
- document.head.appendChild(link);
108
+ /**
109
+ * Injects a stylesheet by appending a `<link rel="stylesheet">` to `document.head`.
110
+ * Resolves when the sheet fires `load`; rejects on `error` (e.g. 404 or network failure).
111
+ *
112
+ * **Id replacement:** if `attrubutes.id` is set, any existing element with that `id` is removed
113
+ * first, so repeated calls with the same `id` replace the previous link (useful for theme or
114
+ * font URLs that change).
115
+ *
116
+ * If `rel` is omitted in `attrubutes`, it defaults to `stylesheet`. Other attributes (`crossorigin`,
117
+ * `media`, `data-*`, etc.) are set via `setAttribute` from the record entries.
118
+ *
119
+ * @param url - Stylesheet URL (`href`).
120
+ * @param attrubutes - Optional HTML attributes for the `<link>` element (see `id` / `rel` behavior above).
121
+ * @returns Promise that resolves to `undefined` on load, or rejects on load error.
122
+ *
123
+ * @example
124
+ * ```ts
125
+ * await loadCssFile('https://example.com/fonts.css', {
126
+ * id: 'app-fonts',
127
+ * crossOrigin: 'anonymous',
128
+ * });
129
+ * ```
130
+ *
131
+ * @example
132
+ * ```ts
133
+ * // Swap theme stylesheet without duplicate link tags
134
+ * await loadCssFile('/themes/dark.css', { id: 'theme' });
135
+ * await loadCssFile('/themes/light.css', { id: 'theme' });
136
+ * ```
137
+ */
138
+ var loadCssFile = (url, attrubutes) => new Promise((resolve, reject) => {
139
+ let link;
140
+ if (attrubutes?.id) {
141
+ link = document.getElementById(attrubutes.id);
142
+ if (link) link.remove();
143
+ }
144
+ link = document.createElement("link");
145
+ const handleLoad = () => {
146
+ resolve(void 0);
147
+ link.removeEventListener("load", handleLoad);
148
+ link.removeEventListener("error", handleError);
149
+ };
150
+ const handleError = () => {
151
+ reject(void 0);
152
+ link.removeEventListener("load", handleLoad);
153
+ link.removeEventListener("error", handleError);
154
+ };
155
+ link.addEventListener("load", handleLoad);
156
+ link.addEventListener("error", handleError);
157
+ link.setAttribute("href", url);
158
+ if (!attrubutes?.rel) link.setAttribute("rel", "stylesheet");
159
+ Object.entries(attrubutes || {}).forEach(([key, value]) => {
160
+ link.setAttribute(key, value);
161
+ });
162
+ document.head.appendChild(link);
41
163
  });
164
+ //#endregion
42
165
  exports.cva = cva;
43
166
  exports.cx = cx;
44
167
  exports.loadCssFile = loadCssFile;
45
168
  exports.toRem = toRem;
46
- //# sourceMappingURL=css.cjs.map
169
+
170
+ //# 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 * Converts a pixel value to a `rem` string.\n */\nexport const toRem = (px: number, remValue = 16) => `${px / remValue}rem`;\n\n/**\n * `classNames`/`clsx` with `tailwind-merge` support.\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 * `Class Variance Authority` with `tailwind-merge` support.\n *\n * https://cva.style/docs\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\nexport type { VariantProps } from 'class-variance-authority';\nexport type { ClassValue } from 'clsx';\n\n/**\n * Load CSS file by providing `url`.\n *\n * **NOTE:** If `id` is provided, it will remove the existing link element with the same `id` before creating a new one.\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"],"names":["twMerge","cvaLib"],"mappings":";;;;;AAeO,MAAM,QAAQ,CAAC,IAAY,WAAW,OAAO,GAAG,KAAK,QAAQ;AAK7D,MAAM,KAAK,IAAI,SAAkCA,cAAAA,QAAQ,KAAK,GAAG,IAAI,CAAC;AA+BtE,MAAM,OAAO,IAAI,SAAgB;AACtC,QAAM,SAASC,2BAAO,GAAG,IAAI;AAC7B,SAAO,IAAI,cAAqBD,cAAAA,QAAQ,OAAO,GAAG,SAAS,CAAC;AAC9D;AAaO,MAAM,cAAc,CAAC,KAAa,eACvC,IAAI,QAAQ,CAAC,SAAS,WAAW;AAC/B,MAAI;AAEJ,MAAI,YAAY,IAAI;AAClB,WAAO,SAAS,eAAe,WAAW,EAAE;AAE5C,QAAI,MAAM;AACR,WAAK,OAAA;AAAA,IACP;AAAA,EACF;AAEA,SAAO,SAAS,cAAc,MAAM;AAEpC,QAAM,aAAa,MAAM;AACvB,YAAQ,MAAS;AACjB,SAAM,oBAAoB,QAAQ,UAAU;AAC5C,SAAM,oBAAoB,SAAS,WAAW;AAAA,EAChD;AAEA,QAAM,cAAc,MAAM;AACxB,WAAO,MAAS;AAChB,SAAM,oBAAoB,QAAQ,UAAU;AAC5C,SAAM,oBAAoB,SAAS,WAAW;AAAA,EAChD;AAEA,OAAK,iBAAiB,QAAQ,UAAU;AACxC,OAAK,iBAAiB,SAAS,WAAW;AAE1C,OAAK,aAAa,QAAQ,GAAG;AAE7B,MAAI,CAAC,YAAY,KAAK;AACpB,SAAK,aAAa,OAAO,YAAY;AAAA,EACvC;AAEA,SAAO,QAAQ,cAAc,CAAA,CAAE,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AACzD,SAAK,aAAa,KAAK,KAAK;AAAA,EAC9B,CAAC;AAED,WAAS,KAAK,YAAY,IAAI;AAChC,CAAC;;;;;"}
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 } 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDA,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
@@ -2,17 +2,70 @@ import clsx, { ClassValue } from 'clsx';
2
2
  export { ClassValue } from 'clsx';
3
3
  export { VariantProps } from 'class-variance-authority';
4
4
 
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
+
5
22
  type ClassProp = {
6
23
  class?: ClassValue;
7
24
  className?: ClassValue;
8
25
  };
9
26
  type StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T;
10
27
  /**
11
- * Converts a pixel value to a `rem` string.
28
+ * Converts a length in **pixels** to a CSS **`rem`** string (`"<number>rem"`).
29
+ *
30
+ * Use when authoring component styles in JS/TS where design tokens are in px but the stylesheet
31
+ * should scale with root font size (accessibility, user zoom). `remValue` is the assumed
32
+ * `1rem` size in px (browser default is typically `16`).
33
+ *
34
+ * @param px - Pixel value to convert (not rounded; stringification keeps full float).
35
+ * @param remValue - How many pixels one `rem` equals. Defaults to `16`.
36
+ * @returns A string like `"1.5rem"` suitable for `style` or CSS-in-JS.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * const width = toRem(24); // '1.5rem' with default 16px root
41
+ * ```
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * // Custom root / design system where 1rem === 10px
46
+ * const gap = toRem(20, 10); // '2rem'
47
+ * ```
12
48
  */
13
49
  declare const toRem: (px: number, remValue?: number) => string;
14
50
  /**
15
- * `classNames`/`clsx` with `tailwind-merge` support.
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
+ * ```
16
69
  */
17
70
  declare const cx: (...args: Parameters<typeof clsx>) => string;
18
71
  type ConfigSchema = Record<string, Record<string, ClassValue>>;
@@ -29,16 +82,72 @@ type Config<T> = T extends ConfigSchema ? {
29
82
  } : never;
30
83
  type Props<T> = T extends ConfigSchema ? ConfigVariants<T> & ClassProp : ClassProp;
31
84
  /**
32
- * `Class Variance Authority` with `tailwind-merge` support.
85
+ * {@link https://cva.style/docs | Class Variance Authority (cva)} with the same **tailwind-merge**
86
+ * pass as {@link cx}: the class string produced by the variant function is merged so Tailwind
87
+ * conflicts resolve predictably.
88
+ *
89
+ * API matches `cva` from `class-variance-authority`: optional `base` classes, `config` with
90
+ * `variants`, `defaultVariants`, and `compoundVariants`. The returned function accepts variant
91
+ * props plus optional `class` / `className` for one-off overrides.
92
+ *
93
+ * Use {@link VariantProps} with `typeof buttonVariants` (or similar) to type component props.
94
+ *
95
+ * @param base - Base `ClassValue`(s) always applied.
96
+ * @param config - Variant schema and defaults (same shape as upstream `cva`).
97
+ * @returns A function `(props?) => string` that resolves variant classes, merged with tw-merge.
33
98
  *
34
- * https://cva.style/docs
99
+ * @example
100
+ * ```ts
101
+ * const button = cva('rounded font-medium', {
102
+ * variants: {
103
+ * tone: { primary: 'bg-blue-600 text-white', ghost: 'bg-transparent' },
104
+ * size: { sm: 'text-sm px-2', md: 'text-base px-4' },
105
+ * },
106
+ * defaultVariants: { tone: 'primary', size: 'md' },
107
+ * });
108
+ * button({ tone: 'ghost', className: 'ml-2' });
109
+ * ```
110
+ *
111
+ * @example
112
+ * ```ts
113
+ * const card = cva('border p-4', {
114
+ * variants: { elevated: { true: 'shadow-lg', false: 'shadow-none' } },
115
+ * defaultVariants: { elevated: false },
116
+ * });
117
+ * card({ elevated: true });
118
+ * ```
35
119
  */
36
120
  declare const cva: <T>(base?: ClassValue, config?: Config<T>) => (props?: Props<T>) => string;
37
121
 
38
122
  /**
39
- * Load CSS file by providing `url`.
123
+ * Injects a stylesheet by appending a `<link rel="stylesheet">` to `document.head`.
124
+ * Resolves when the sheet fires `load`; rejects on `error` (e.g. 404 or network failure).
125
+ *
126
+ * **Id replacement:** if `attrubutes.id` is set, any existing element with that `id` is removed
127
+ * first, so repeated calls with the same `id` replace the previous link (useful for theme or
128
+ * font URLs that change).
129
+ *
130
+ * If `rel` is omitted in `attrubutes`, it defaults to `stylesheet`. Other attributes (`crossorigin`,
131
+ * `media`, `data-*`, etc.) are set via `setAttribute` from the record entries.
132
+ *
133
+ * @param url - Stylesheet URL (`href`).
134
+ * @param attrubutes - Optional HTML attributes for the `<link>` element (see `id` / `rel` behavior above).
135
+ * @returns Promise that resolves to `undefined` on load, or rejects on load error.
136
+ *
137
+ * @example
138
+ * ```ts
139
+ * await loadCssFile('https://example.com/fonts.css', {
140
+ * id: 'app-fonts',
141
+ * crossOrigin: 'anonymous',
142
+ * });
143
+ * ```
40
144
  *
41
- * **NOTE:** If `id` is provided, it will remove the existing link element with the same `id` before creating a new one.
145
+ * @example
146
+ * ```ts
147
+ * // Swap theme stylesheet without duplicate link tags
148
+ * await loadCssFile('/themes/dark.css', { id: 'theme' });
149
+ * await loadCssFile('/themes/light.css', { id: 'theme' });
150
+ * ```
42
151
  */
43
152
  declare const loadCssFile: (url: string, attrubutes?: Record<string, any>) => Promise<unknown>;
44
153
 
package/css.js CHANGED
@@ -1,46 +1,164 @@
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
- const toRem = (px, remValue = 16) => `${px / remValue}rem`;
5
- const cx = (...args) => twMerge(clsx(...args));
6
- const cva = ((...args) => {
7
- const schema = cva$1(...args);
8
- return (...inputArgs) => twMerge(schema(...inputArgs));
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
+ * @param px - Pixel value to convert (not rounded; stringification keeps full float).
29
+ * @param remValue - How many pixels one `rem` equals. Defaults to `16`.
30
+ * @returns A string like `"1.5rem"` suitable for `style` or CSS-in-JS.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const width = toRem(24); // '1.5rem' with default 16px root
35
+ * ```
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * // Custom root / design system where 1rem === 10px
40
+ * const gap = toRem(20, 10); // '2rem'
41
+ * ```
42
+ */
43
+ var toRem = (px, remValue = 16) => `${px / remValue}rem`;
44
+ /**
45
+ * Composes conditional class names like {@link https://github.com/lukeed/clsx | clsx}, then runs
46
+ * the result through {@link https://github.com/dcastil/tailwind-merge | tailwind-merge} so
47
+ * conflicting Tailwind utilities collapse to the last/intended one (e.g. two `padding-x` classes).
48
+ *
49
+ * Accepts the same argument shapes as `clsx`: strings, objects, arrays, falsy values to omit.
50
+ *
51
+ * @param args - Same as `clsx(...args)` — `ClassValue` rest parameters.
52
+ * @returns A single merged class string, safe for `className` on DOM/React.
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * cx('px-2 py-1 text-sm', 'px-4'); // 'py-1 text-sm px-4' — padding-x merged
57
+ * ```
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * cx('btn', { 'btn--active': isActive, 'btn--disabled': disabled }, className);
62
+ * ```
63
+ */
64
+ var cx = (...args) => twMerge(clsx(...args));
65
+ /**
66
+ * {@link https://cva.style/docs | Class Variance Authority (cva)} with the same **tailwind-merge**
67
+ * pass as {@link cx}: the class string produced by the variant function is merged so Tailwind
68
+ * conflicts resolve predictably.
69
+ *
70
+ * API matches `cva` from `class-variance-authority`: optional `base` classes, `config` with
71
+ * `variants`, `defaultVariants`, and `compoundVariants`. The returned function accepts variant
72
+ * props plus optional `class` / `className` for one-off overrides.
73
+ *
74
+ * Use {@link VariantProps} with `typeof buttonVariants` (or similar) to type component props.
75
+ *
76
+ * @param base - Base `ClassValue`(s) always applied.
77
+ * @param config - Variant schema and defaults (same shape as upstream `cva`).
78
+ * @returns A function `(props?) => string` that resolves variant classes, merged with tw-merge.
79
+ *
80
+ * @example
81
+ * ```ts
82
+ * const button = cva('rounded font-medium', {
83
+ * variants: {
84
+ * tone: { primary: 'bg-blue-600 text-white', ghost: 'bg-transparent' },
85
+ * size: { sm: 'text-sm px-2', md: 'text-base px-4' },
86
+ * },
87
+ * defaultVariants: { tone: 'primary', size: 'md' },
88
+ * });
89
+ * button({ tone: 'ghost', className: 'ml-2' });
90
+ * ```
91
+ *
92
+ * @example
93
+ * ```ts
94
+ * const card = cva('border p-4', {
95
+ * variants: { elevated: { true: 'shadow-lg', false: 'shadow-none' } },
96
+ * defaultVariants: { elevated: false },
97
+ * });
98
+ * card({ elevated: true });
99
+ * ```
100
+ */
101
+ var cva = ((...args) => {
102
+ const schema = cva$1(...args);
103
+ return (...inputArgs) => twMerge(schema(...inputArgs));
9
104
  });
10
- const loadCssFile = (url, attrubutes) => new Promise((resolve, reject) => {
11
- let link;
12
- if (attrubutes?.id) {
13
- link = document.getElementById(attrubutes.id);
14
- if (link) {
15
- link.remove();
16
- }
17
- }
18
- link = document.createElement("link");
19
- const handleLoad = () => {
20
- resolve(void 0);
21
- link.removeEventListener("load", handleLoad);
22
- link.removeEventListener("error", handleError);
23
- };
24
- const handleError = () => {
25
- reject(void 0);
26
- link.removeEventListener("load", handleLoad);
27
- link.removeEventListener("error", handleError);
28
- };
29
- link.addEventListener("load", handleLoad);
30
- link.addEventListener("error", handleError);
31
- link.setAttribute("href", url);
32
- if (!attrubutes?.rel) {
33
- link.setAttribute("rel", "stylesheet");
34
- }
35
- Object.entries(attrubutes || {}).forEach(([key, value]) => {
36
- link.setAttribute(key, value);
37
- });
38
- document.head.appendChild(link);
105
+ /**
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
+ * ```
127
+ *
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
+ * ```
134
+ */
135
+ var loadCssFile = (url, attrubutes) => new Promise((resolve, reject) => {
136
+ let link;
137
+ if (attrubutes?.id) {
138
+ link = document.getElementById(attrubutes.id);
139
+ if (link) link.remove();
140
+ }
141
+ link = document.createElement("link");
142
+ const handleLoad = () => {
143
+ resolve(void 0);
144
+ link.removeEventListener("load", handleLoad);
145
+ link.removeEventListener("error", handleError);
146
+ };
147
+ const handleError = () => {
148
+ reject(void 0);
149
+ link.removeEventListener("load", handleLoad);
150
+ link.removeEventListener("error", handleError);
151
+ };
152
+ link.addEventListener("load", handleLoad);
153
+ link.addEventListener("error", handleError);
154
+ link.setAttribute("href", url);
155
+ if (!attrubutes?.rel) link.setAttribute("rel", "stylesheet");
156
+ Object.entries(attrubutes || {}).forEach(([key, value]) => {
157
+ link.setAttribute(key, value);
158
+ });
159
+ document.head.appendChild(link);
39
160
  });
40
- export {
41
- cva,
42
- cx,
43
- loadCssFile,
44
- toRem
45
- };
46
- //# sourceMappingURL=css.js.map
161
+ //#endregion
162
+ export { cva, cx, loadCssFile, toRem };
163
+
164
+ //# 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 * Converts a pixel value to a `rem` string.\n */\nexport const toRem = (px: number, remValue = 16) => `${px / remValue}rem`;\n\n/**\n * `classNames`/`clsx` with `tailwind-merge` support.\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 * `Class Variance Authority` with `tailwind-merge` support.\n *\n * https://cva.style/docs\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\nexport type { VariantProps } from 'class-variance-authority';\nexport type { ClassValue } from 'clsx';\n\n/**\n * Load CSS file by providing `url`.\n *\n * **NOTE:** If `id` is provided, it will remove the existing link element with the same `id` before creating a new one.\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"],"names":["cvaLib"],"mappings":";;;AAeO,MAAM,QAAQ,CAAC,IAAY,WAAW,OAAO,GAAG,KAAK,QAAQ;AAK7D,MAAM,KAAK,IAAI,SAAkC,QAAQ,KAAK,GAAG,IAAI,CAAC;AA+BtE,MAAM,OAAO,IAAI,SAAgB;AACtC,QAAM,SAASA,MAAO,GAAG,IAAI;AAC7B,SAAO,IAAI,cAAqB,QAAQ,OAAO,GAAG,SAAS,CAAC;AAC9D;AAaO,MAAM,cAAc,CAAC,KAAa,eACvC,IAAI,QAAQ,CAAC,SAAS,WAAW;AAC/B,MAAI;AAEJ,MAAI,YAAY,IAAI;AAClB,WAAO,SAAS,eAAe,WAAW,EAAE;AAE5C,QAAI,MAAM;AACR,WAAK,OAAA;AAAA,IACP;AAAA,EACF;AAEA,SAAO,SAAS,cAAc,MAAM;AAEpC,QAAM,aAAa,MAAM;AACvB,YAAQ,MAAS;AACjB,SAAM,oBAAoB,QAAQ,UAAU;AAC5C,SAAM,oBAAoB,SAAS,WAAW;AAAA,EAChD;AAEA,QAAM,cAAc,MAAM;AACxB,WAAO,MAAS;AAChB,SAAM,oBAAoB,QAAQ,UAAU;AAC5C,SAAM,oBAAoB,SAAS,WAAW;AAAA,EAChD;AAEA,OAAK,iBAAiB,QAAQ,UAAU;AACxC,OAAK,iBAAiB,SAAS,WAAW;AAE1C,OAAK,aAAa,QAAQ,GAAG;AAE7B,MAAI,CAAC,YAAY,KAAK;AACpB,SAAK,aAAa,OAAO,YAAY;AAAA,EACvC;AAEA,SAAO,QAAQ,cAAc,CAAA,CAAE,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AACzD,SAAK,aAAa,KAAK,KAAK;AAAA,EAC9B,CAAC;AAED,WAAS,KAAK,YAAY,IAAI;AAChC,CAAC;"}
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 } 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDA,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"}