@tenphi/tasty 0.1.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 (359) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +236 -0
  3. package/dist/_virtual/_rolldown/runtime.mjs +7 -0
  4. package/dist/chunks/cacheKey.d.ts +1 -0
  5. package/dist/chunks/cacheKey.js +70 -0
  6. package/dist/chunks/cacheKey.js.map +1 -0
  7. package/dist/chunks/cacheKey.mjs +70 -0
  8. package/dist/chunks/cacheKey.mjs.map +1 -0
  9. package/dist/chunks/definitions.d.ts +37 -0
  10. package/dist/chunks/definitions.js +260 -0
  11. package/dist/chunks/definitions.js.map +1 -0
  12. package/dist/chunks/definitions.mjs +260 -0
  13. package/dist/chunks/definitions.mjs.map +1 -0
  14. package/dist/chunks/index.d.ts +3 -0
  15. package/dist/chunks/renderChunk.d.ts +2 -0
  16. package/dist/chunks/renderChunk.js +61 -0
  17. package/dist/chunks/renderChunk.js.map +1 -0
  18. package/dist/chunks/renderChunk.mjs +61 -0
  19. package/dist/chunks/renderChunk.mjs.map +1 -0
  20. package/dist/config.d.ts +279 -0
  21. package/dist/config.js +400 -0
  22. package/dist/config.js.map +1 -0
  23. package/dist/config.mjs +231 -0
  24. package/dist/config.mjs.map +1 -0
  25. package/dist/css-writer.d.mts +45 -0
  26. package/dist/css-writer.mjs +74 -0
  27. package/dist/css-writer.mjs.map +1 -0
  28. package/dist/debug.d.ts +204 -0
  29. package/dist/debug.js +733 -0
  30. package/dist/debug.js.map +1 -0
  31. package/dist/extractor.d.mts +24 -0
  32. package/dist/extractor.mjs +150 -0
  33. package/dist/extractor.mjs.map +1 -0
  34. package/dist/hooks/index.d.ts +5 -0
  35. package/dist/hooks/useGlobalStyles.d.ts +27 -0
  36. package/dist/hooks/useGlobalStyles.js +56 -0
  37. package/dist/hooks/useGlobalStyles.js.map +1 -0
  38. package/dist/hooks/useKeyframes.d.ts +56 -0
  39. package/dist/hooks/useKeyframes.js +54 -0
  40. package/dist/hooks/useKeyframes.js.map +1 -0
  41. package/dist/hooks/useProperty.d.ts +79 -0
  42. package/dist/hooks/useProperty.js +91 -0
  43. package/dist/hooks/useProperty.js.map +1 -0
  44. package/dist/hooks/useRawCSS.d.ts +53 -0
  45. package/dist/hooks/useRawCSS.js +28 -0
  46. package/dist/hooks/useRawCSS.js.map +1 -0
  47. package/dist/hooks/useStyles.d.ts +40 -0
  48. package/dist/hooks/useStyles.js +169 -0
  49. package/dist/hooks/useStyles.js.map +1 -0
  50. package/dist/index.d.ts +38 -0
  51. package/dist/index.js +30 -0
  52. package/dist/injector/index.d.ts +157 -0
  53. package/dist/injector/index.js +154 -0
  54. package/dist/injector/index.js.map +1 -0
  55. package/dist/injector/injector.d.ts +139 -0
  56. package/dist/injector/injector.js +404 -0
  57. package/dist/injector/injector.js.map +1 -0
  58. package/dist/injector/injector.mjs +404 -0
  59. package/dist/injector/injector.mjs.map +1 -0
  60. package/dist/injector/sheet-manager.d.ts +127 -0
  61. package/dist/injector/sheet-manager.js +714 -0
  62. package/dist/injector/sheet-manager.js.map +1 -0
  63. package/dist/injector/sheet-manager.mjs +714 -0
  64. package/dist/injector/sheet-manager.mjs.map +1 -0
  65. package/dist/injector/types.d.mts +18 -0
  66. package/dist/injector/types.d.ts +135 -0
  67. package/dist/keyframes/index.js +206 -0
  68. package/dist/keyframes/index.js.map +1 -0
  69. package/dist/keyframes/index.mjs +156 -0
  70. package/dist/keyframes/index.mjs.map +1 -0
  71. package/dist/parser/classify.js +319 -0
  72. package/dist/parser/classify.js.map +1 -0
  73. package/dist/parser/classify.mjs +319 -0
  74. package/dist/parser/classify.mjs.map +1 -0
  75. package/dist/parser/const.js +33 -0
  76. package/dist/parser/const.js.map +1 -0
  77. package/dist/parser/const.mjs +33 -0
  78. package/dist/parser/const.mjs.map +1 -0
  79. package/dist/parser/lru.js +109 -0
  80. package/dist/parser/lru.js.map +1 -0
  81. package/dist/parser/lru.mjs +109 -0
  82. package/dist/parser/lru.mjs.map +1 -0
  83. package/dist/parser/parser.d.ts +25 -0
  84. package/dist/parser/parser.js +116 -0
  85. package/dist/parser/parser.js.map +1 -0
  86. package/dist/parser/parser.mjs +116 -0
  87. package/dist/parser/parser.mjs.map +1 -0
  88. package/dist/parser/tokenizer.js +69 -0
  89. package/dist/parser/tokenizer.js.map +1 -0
  90. package/dist/parser/tokenizer.mjs +69 -0
  91. package/dist/parser/tokenizer.mjs.map +1 -0
  92. package/dist/parser/types.d.mts +37 -0
  93. package/dist/parser/types.d.ts +46 -0
  94. package/dist/parser/types.js +46 -0
  95. package/dist/parser/types.js.map +1 -0
  96. package/dist/parser/types.mjs +46 -0
  97. package/dist/parser/types.mjs.map +1 -0
  98. package/dist/pipeline/conditions.js +377 -0
  99. package/dist/pipeline/conditions.js.map +1 -0
  100. package/dist/pipeline/conditions.mjs +377 -0
  101. package/dist/pipeline/conditions.mjs.map +1 -0
  102. package/dist/pipeline/exclusive.d.ts +1 -0
  103. package/dist/pipeline/exclusive.js +231 -0
  104. package/dist/pipeline/exclusive.js.map +1 -0
  105. package/dist/pipeline/exclusive.mjs +231 -0
  106. package/dist/pipeline/exclusive.mjs.map +1 -0
  107. package/dist/pipeline/index.d.ts +53 -0
  108. package/dist/pipeline/index.js +641 -0
  109. package/dist/pipeline/index.js.map +1 -0
  110. package/dist/pipeline/index.mjs +635 -0
  111. package/dist/pipeline/index.mjs.map +1 -0
  112. package/dist/pipeline/materialize.js +821 -0
  113. package/dist/pipeline/materialize.js.map +1 -0
  114. package/dist/pipeline/materialize.mjs +821 -0
  115. package/dist/pipeline/materialize.mjs.map +1 -0
  116. package/dist/pipeline/parseStateKey.d.ts +1 -0
  117. package/dist/pipeline/parseStateKey.js +418 -0
  118. package/dist/pipeline/parseStateKey.js.map +1 -0
  119. package/dist/pipeline/parseStateKey.mjs +418 -0
  120. package/dist/pipeline/parseStateKey.mjs.map +1 -0
  121. package/dist/pipeline/simplify.js +557 -0
  122. package/dist/pipeline/simplify.js.map +1 -0
  123. package/dist/pipeline/simplify.mjs +557 -0
  124. package/dist/pipeline/simplify.mjs.map +1 -0
  125. package/dist/plugins/index.d.ts +2 -0
  126. package/dist/plugins/okhsl-plugin.d.ts +35 -0
  127. package/dist/plugins/okhsl-plugin.js +371 -0
  128. package/dist/plugins/okhsl-plugin.js.map +1 -0
  129. package/dist/plugins/okhsl-plugin.mjs +345 -0
  130. package/dist/plugins/okhsl-plugin.mjs.map +1 -0
  131. package/dist/plugins/types.d.mts +49 -0
  132. package/dist/plugins/types.d.ts +69 -0
  133. package/dist/properties/index.js +158 -0
  134. package/dist/properties/index.js.map +1 -0
  135. package/dist/properties/index.mjs +141 -0
  136. package/dist/properties/index.mjs.map +1 -0
  137. package/dist/states/index.d.ts +45 -0
  138. package/dist/states/index.js +389 -0
  139. package/dist/states/index.js.map +1 -0
  140. package/dist/states/index.mjs +161 -0
  141. package/dist/states/index.mjs.map +1 -0
  142. package/dist/static/index.d.ts +5 -0
  143. package/dist/static/index.js +5 -0
  144. package/dist/static/tastyStatic.d.ts +46 -0
  145. package/dist/static/tastyStatic.js +31 -0
  146. package/dist/static/tastyStatic.js.map +1 -0
  147. package/dist/static/types.d.ts +49 -0
  148. package/dist/static/types.js +24 -0
  149. package/dist/static/types.js.map +1 -0
  150. package/dist/styles/align.d.ts +15 -0
  151. package/dist/styles/align.js +14 -0
  152. package/dist/styles/align.js.map +1 -0
  153. package/dist/styles/align.mjs +14 -0
  154. package/dist/styles/align.mjs.map +1 -0
  155. package/dist/styles/border.d.ts +25 -0
  156. package/dist/styles/border.js +114 -0
  157. package/dist/styles/border.js.map +1 -0
  158. package/dist/styles/border.mjs +114 -0
  159. package/dist/styles/border.mjs.map +1 -0
  160. package/dist/styles/color.d.ts +14 -0
  161. package/dist/styles/color.js +23 -0
  162. package/dist/styles/color.js.map +1 -0
  163. package/dist/styles/color.mjs +23 -0
  164. package/dist/styles/color.mjs.map +1 -0
  165. package/dist/styles/createStyle.js +77 -0
  166. package/dist/styles/createStyle.js.map +1 -0
  167. package/dist/styles/createStyle.mjs +77 -0
  168. package/dist/styles/createStyle.mjs.map +1 -0
  169. package/dist/styles/dimension.js +97 -0
  170. package/dist/styles/dimension.js.map +1 -0
  171. package/dist/styles/dimension.mjs +97 -0
  172. package/dist/styles/dimension.mjs.map +1 -0
  173. package/dist/styles/display.d.ts +37 -0
  174. package/dist/styles/display.js +67 -0
  175. package/dist/styles/display.js.map +1 -0
  176. package/dist/styles/display.mjs +67 -0
  177. package/dist/styles/display.mjs.map +1 -0
  178. package/dist/styles/fade.d.ts +15 -0
  179. package/dist/styles/fade.js +58 -0
  180. package/dist/styles/fade.js.map +1 -0
  181. package/dist/styles/fade.mjs +58 -0
  182. package/dist/styles/fade.mjs.map +1 -0
  183. package/dist/styles/fill.d.ts +44 -0
  184. package/dist/styles/fill.js +51 -0
  185. package/dist/styles/fill.js.map +1 -0
  186. package/dist/styles/fill.mjs +51 -0
  187. package/dist/styles/fill.mjs.map +1 -0
  188. package/dist/styles/flow.d.ts +16 -0
  189. package/dist/styles/flow.js +12 -0
  190. package/dist/styles/flow.js.map +1 -0
  191. package/dist/styles/flow.mjs +12 -0
  192. package/dist/styles/flow.mjs.map +1 -0
  193. package/dist/styles/gap.d.ts +31 -0
  194. package/dist/styles/gap.js +37 -0
  195. package/dist/styles/gap.js.map +1 -0
  196. package/dist/styles/gap.mjs +37 -0
  197. package/dist/styles/gap.mjs.map +1 -0
  198. package/dist/styles/height.d.ts +17 -0
  199. package/dist/styles/height.js +20 -0
  200. package/dist/styles/height.js.map +1 -0
  201. package/dist/styles/height.mjs +20 -0
  202. package/dist/styles/height.mjs.map +1 -0
  203. package/dist/styles/index.d.ts +2 -0
  204. package/dist/styles/index.js +9 -0
  205. package/dist/styles/index.js.map +1 -0
  206. package/dist/styles/index.mjs +9 -0
  207. package/dist/styles/index.mjs.map +1 -0
  208. package/dist/styles/inset.d.ts +50 -0
  209. package/dist/styles/inset.js +142 -0
  210. package/dist/styles/inset.js.map +1 -0
  211. package/dist/styles/inset.mjs +142 -0
  212. package/dist/styles/inset.mjs.map +1 -0
  213. package/dist/styles/justify.d.ts +15 -0
  214. package/dist/styles/justify.js +14 -0
  215. package/dist/styles/justify.js.map +1 -0
  216. package/dist/styles/justify.mjs +14 -0
  217. package/dist/styles/justify.mjs.map +1 -0
  218. package/dist/styles/list.d.ts +16 -0
  219. package/dist/styles/list.js +98 -0
  220. package/dist/styles/list.js.map +1 -0
  221. package/dist/styles/margin.d.ts +28 -0
  222. package/dist/styles/margin.js +96 -0
  223. package/dist/styles/margin.js.map +1 -0
  224. package/dist/styles/margin.mjs +96 -0
  225. package/dist/styles/margin.mjs.map +1 -0
  226. package/dist/styles/outline.d.ts +29 -0
  227. package/dist/styles/outline.js +65 -0
  228. package/dist/styles/outline.js.map +1 -0
  229. package/dist/styles/outline.mjs +65 -0
  230. package/dist/styles/outline.mjs.map +1 -0
  231. package/dist/styles/padding.d.ts +28 -0
  232. package/dist/styles/padding.js +96 -0
  233. package/dist/styles/padding.js.map +1 -0
  234. package/dist/styles/padding.mjs +96 -0
  235. package/dist/styles/padding.mjs.map +1 -0
  236. package/dist/styles/predefined.d.ts +74 -0
  237. package/dist/styles/predefined.js +241 -0
  238. package/dist/styles/predefined.js.map +1 -0
  239. package/dist/styles/predefined.mjs +232 -0
  240. package/dist/styles/predefined.mjs.map +1 -0
  241. package/dist/styles/preset.d.ts +47 -0
  242. package/dist/styles/preset.js +126 -0
  243. package/dist/styles/preset.js.map +1 -0
  244. package/dist/styles/preset.mjs +126 -0
  245. package/dist/styles/preset.mjs.map +1 -0
  246. package/dist/styles/radius.d.ts +14 -0
  247. package/dist/styles/radius.js +51 -0
  248. package/dist/styles/radius.js.map +1 -0
  249. package/dist/styles/radius.mjs +51 -0
  250. package/dist/styles/radius.mjs.map +1 -0
  251. package/dist/styles/scrollbar.d.ts +21 -0
  252. package/dist/styles/scrollbar.js +105 -0
  253. package/dist/styles/scrollbar.js.map +1 -0
  254. package/dist/styles/scrollbar.mjs +105 -0
  255. package/dist/styles/scrollbar.mjs.map +1 -0
  256. package/dist/styles/shadow.d.ts +14 -0
  257. package/dist/styles/shadow.js +24 -0
  258. package/dist/styles/shadow.js.map +1 -0
  259. package/dist/styles/shadow.mjs +24 -0
  260. package/dist/styles/shadow.mjs.map +1 -0
  261. package/dist/styles/styledScrollbar.d.ts +47 -0
  262. package/dist/styles/styledScrollbar.js +38 -0
  263. package/dist/styles/styledScrollbar.js.map +1 -0
  264. package/dist/styles/styledScrollbar.mjs +38 -0
  265. package/dist/styles/styledScrollbar.mjs.map +1 -0
  266. package/dist/styles/transition.d.ts +14 -0
  267. package/dist/styles/transition.js +138 -0
  268. package/dist/styles/transition.js.map +1 -0
  269. package/dist/styles/transition.mjs +138 -0
  270. package/dist/styles/transition.mjs.map +1 -0
  271. package/dist/styles/types.d.mts +492 -0
  272. package/dist/styles/types.d.ts +496 -0
  273. package/dist/styles/width.d.ts +17 -0
  274. package/dist/styles/width.js +20 -0
  275. package/dist/styles/width.js.map +1 -0
  276. package/dist/styles/width.mjs +20 -0
  277. package/dist/styles/width.mjs.map +1 -0
  278. package/dist/tasty.d.ts +983 -0
  279. package/dist/tasty.js +191 -0
  280. package/dist/tasty.js.map +1 -0
  281. package/dist/tokens/typography.d.ts +19 -0
  282. package/dist/tokens/typography.js +237 -0
  283. package/dist/tokens/typography.js.map +1 -0
  284. package/dist/types.d.ts +182 -0
  285. package/dist/utils/cache-wrapper.js +26 -0
  286. package/dist/utils/cache-wrapper.js.map +1 -0
  287. package/dist/utils/cache-wrapper.mjs +26 -0
  288. package/dist/utils/cache-wrapper.mjs.map +1 -0
  289. package/dist/utils/case-converter.js +8 -0
  290. package/dist/utils/case-converter.js.map +1 -0
  291. package/dist/utils/case-converter.mjs +8 -0
  292. package/dist/utils/case-converter.mjs.map +1 -0
  293. package/dist/utils/colors.d.ts +5 -0
  294. package/dist/utils/colors.js +9 -0
  295. package/dist/utils/colors.js.map +1 -0
  296. package/dist/utils/dotize.d.ts +26 -0
  297. package/dist/utils/dotize.js +122 -0
  298. package/dist/utils/dotize.js.map +1 -0
  299. package/dist/utils/filter-base-props.d.ts +15 -0
  300. package/dist/utils/filter-base-props.js +45 -0
  301. package/dist/utils/filter-base-props.js.map +1 -0
  302. package/dist/utils/get-display-name.d.ts +7 -0
  303. package/dist/utils/get-display-name.js +10 -0
  304. package/dist/utils/get-display-name.js.map +1 -0
  305. package/dist/utils/hsl-to-rgb.js +38 -0
  306. package/dist/utils/hsl-to-rgb.js.map +1 -0
  307. package/dist/utils/hsl-to-rgb.mjs +38 -0
  308. package/dist/utils/hsl-to-rgb.mjs.map +1 -0
  309. package/dist/utils/is-dev-env.js +19 -0
  310. package/dist/utils/is-dev-env.js.map +1 -0
  311. package/dist/utils/is-dev-env.mjs +19 -0
  312. package/dist/utils/is-dev-env.mjs.map +1 -0
  313. package/dist/utils/merge-styles.d.ts +7 -0
  314. package/dist/utils/merge-styles.js +146 -0
  315. package/dist/utils/merge-styles.js.map +1 -0
  316. package/dist/utils/merge-styles.mjs +146 -0
  317. package/dist/utils/merge-styles.mjs.map +1 -0
  318. package/dist/utils/mod-attrs.d.ts +8 -0
  319. package/dist/utils/mod-attrs.js +21 -0
  320. package/dist/utils/mod-attrs.js.map +1 -0
  321. package/dist/utils/okhsl-to-rgb.js +296 -0
  322. package/dist/utils/okhsl-to-rgb.js.map +1 -0
  323. package/dist/utils/okhsl-to-rgb.mjs +296 -0
  324. package/dist/utils/okhsl-to-rgb.mjs.map +1 -0
  325. package/dist/utils/process-tokens.d.ts +31 -0
  326. package/dist/utils/process-tokens.js +171 -0
  327. package/dist/utils/process-tokens.js.map +1 -0
  328. package/dist/utils/process-tokens.mjs +28 -0
  329. package/dist/utils/process-tokens.mjs.map +1 -0
  330. package/dist/utils/resolve-recipes.d.ts +17 -0
  331. package/dist/utils/resolve-recipes.js +143 -0
  332. package/dist/utils/resolve-recipes.js.map +1 -0
  333. package/dist/utils/resolve-recipes.mjs +143 -0
  334. package/dist/utils/resolve-recipes.mjs.map +1 -0
  335. package/dist/utils/string.js +8 -0
  336. package/dist/utils/string.js.map +1 -0
  337. package/dist/utils/string.mjs +8 -0
  338. package/dist/utils/string.mjs.map +1 -0
  339. package/dist/utils/styles.d.mts +18 -0
  340. package/dist/utils/styles.d.ts +183 -0
  341. package/dist/utils/styles.js +585 -0
  342. package/dist/utils/styles.js.map +1 -0
  343. package/dist/utils/styles.mjs +346 -0
  344. package/dist/utils/styles.mjs.map +1 -0
  345. package/dist/utils/typography.d.ts +36 -0
  346. package/dist/utils/typography.js +53 -0
  347. package/dist/utils/typography.js.map +1 -0
  348. package/dist/utils/warnings.d.ts +16 -0
  349. package/dist/utils/warnings.js +16 -0
  350. package/dist/utils/warnings.js.map +1 -0
  351. package/dist/zero/babel.d.mts +108 -0
  352. package/dist/zero/babel.mjs +282 -0
  353. package/dist/zero/babel.mjs.map +1 -0
  354. package/dist/zero/index.d.mts +3 -0
  355. package/dist/zero/index.mjs +4 -0
  356. package/dist/zero/next.d.mts +60 -0
  357. package/dist/zero/next.mjs +78 -0
  358. package/dist/zero/next.mjs.map +1 -0
  359. package/package.json +127 -0
@@ -0,0 +1,231 @@
1
+ import { CUSTOM_UNITS, getGlobalFuncs, getGlobalParser, normalizeColorTokenValue, setGlobalPredefinedTokens } from "./utils/styles.mjs";
2
+ import { isDevEnv } from "./utils/is-dev-env.mjs";
3
+ import { normalizeHandlerDefinition, registerHandler } from "./styles/predefined.mjs";
4
+ import { StyleInjector } from "./injector/injector.mjs";
5
+ import { setGlobalPredefinedStates } from "./states/index.mjs";
6
+ import { isSelector } from "./pipeline/index.mjs";
7
+
8
+ //#region src/config.ts
9
+ /**
10
+ * Tasty Configuration Module
11
+ *
12
+ * Centralizes all tasty configuration, including:
13
+ * - Style injector settings (nonce, cleanup thresholds, etc.)
14
+ * - Global predefined states for advanced state mapping
15
+ * - stylesGenerated flag that locks configuration after first style generation
16
+ *
17
+ * Configuration must be done BEFORE any styles are generated.
18
+ * After the first `inject()` call, configuration is locked and attempts to
19
+ * reconfigure will emit a warning and be ignored.
20
+ */
21
+ const emittedWarnings = /* @__PURE__ */ new Set();
22
+ const devMode = isDevEnv();
23
+ /**
24
+ * Emit a warning only once
25
+ */
26
+ function warnOnce(key, message) {
27
+ if (devMode && !emittedWarnings.has(key)) {
28
+ emittedWarnings.add(key);
29
+ console.warn(message);
30
+ }
31
+ }
32
+ let stylesGenerated = false;
33
+ let currentConfig = null;
34
+ let globalKeyframes = null;
35
+ let globalProperties = null;
36
+ let globalRecipes = null;
37
+ const GLOBAL_INJECTOR_KEY = "__TASTY_GLOBAL_INJECTOR__";
38
+ /**
39
+ * Create default configuration with optional test environment detection
40
+ */
41
+ function createDefaultConfig(isTest) {
42
+ return {
43
+ maxRulesPerSheet: 8192,
44
+ unusedStylesThreshold: 500,
45
+ bulkCleanupDelay: 5e3,
46
+ idleCleanup: true,
47
+ forceTextInjection: isTest ?? false,
48
+ devMode: isDevEnv(),
49
+ bulkCleanupBatchRatio: .5,
50
+ unusedStylesMinAgeMs: 1e4
51
+ };
52
+ }
53
+ /**
54
+ * Check if styles have been generated (configuration is locked)
55
+ */
56
+ function hasStylesGenerated() {
57
+ return stylesGenerated;
58
+ }
59
+ /**
60
+ * Set global keyframes (called from configure).
61
+ * Internal use only.
62
+ */
63
+ function setGlobalKeyframes(keyframes) {
64
+ if (stylesGenerated) {
65
+ warnOnce("keyframes-after-styles", "[Tasty] Cannot update keyframes after styles have been generated.\nThe new keyframes will be ignored.");
66
+ return;
67
+ }
68
+ globalKeyframes = keyframes;
69
+ }
70
+ /**
71
+ * Set global properties (called from configure).
72
+ * Internal use only.
73
+ */
74
+ function setGlobalProperties(properties) {
75
+ if (stylesGenerated) {
76
+ warnOnce("properties-after-styles", "[Tasty] Cannot update properties after styles have been generated.\nThe new properties will be ignored.");
77
+ return;
78
+ }
79
+ globalProperties = properties;
80
+ }
81
+ /**
82
+ * Get global recipes configuration.
83
+ * Returns null if no recipes configured (fast path for zero-overhead).
84
+ */
85
+ function getGlobalRecipes() {
86
+ return globalRecipes;
87
+ }
88
+ /**
89
+ * Set global recipes (called from configure).
90
+ * Internal use only.
91
+ */
92
+ function setGlobalRecipes(recipes) {
93
+ if (stylesGenerated) {
94
+ warnOnce("recipes-after-styles", "[Tasty] Cannot update recipes after styles have been generated.\nThe new recipes will be ignored.");
95
+ return;
96
+ }
97
+ if (devMode) for (const [name, recipeStyles] of Object.entries(recipes)) for (const key of Object.keys(recipeStyles)) {
98
+ if (isSelector(key)) warnOnce(`recipe-selector-${name}-${key}`, `[Tasty] Recipe "${name}" contains sub-element key "${key}". Recipes must be flat styles without sub-element keys. Remove the sub-element key from the recipe definition.`);
99
+ if (key === "recipe") warnOnce(`recipe-recursive-${name}`, `[Tasty] Recipe "${name}" contains a "recipe" key. Recipes cannot reference other recipes. Use space-separated names for composition: recipe: 'base elevated'.`);
100
+ }
101
+ globalRecipes = recipes;
102
+ }
103
+ /**
104
+ * Configure the Tasty style system.
105
+ *
106
+ * Must be called BEFORE any styles are generated (before first render that uses tasty).
107
+ * After styles are generated, configuration is locked and calls to configure() will
108
+ * emit a warning and be ignored.
109
+ *
110
+ * @example
111
+ * ```ts
112
+ * import { configure } from '@tenphi/tasty';
113
+ *
114
+ * // Configure before app renders
115
+ * configure({
116
+ * nonce: 'abc123',
117
+ * states: {
118
+ * '@mobile': '@media(w < 768px)',
119
+ * '@dark': '@root(theme=dark)',
120
+ * },
121
+ * });
122
+ * ```
123
+ */
124
+ function configure(config = {}) {
125
+ if (stylesGenerated) {
126
+ warnOnce("configure-after-styles", "[Tasty] Cannot call configure() after styles have been generated.\nConfiguration must be done before the first render. The configuration will be ignored.");
127
+ return;
128
+ }
129
+ let mergedStates = {};
130
+ let mergedUnits = {};
131
+ let mergedFuncs = {};
132
+ let mergedHandlers = {};
133
+ let mergedTokens = {};
134
+ let mergedRecipes = {};
135
+ if (config.plugins) for (const plugin of config.plugins) {
136
+ if (plugin.states) mergedStates = {
137
+ ...mergedStates,
138
+ ...plugin.states
139
+ };
140
+ if (plugin.units) mergedUnits = {
141
+ ...mergedUnits,
142
+ ...plugin.units
143
+ };
144
+ if (plugin.funcs) mergedFuncs = {
145
+ ...mergedFuncs,
146
+ ...plugin.funcs
147
+ };
148
+ if (plugin.handlers) mergedHandlers = {
149
+ ...mergedHandlers,
150
+ ...plugin.handlers
151
+ };
152
+ if (plugin.tokens) mergedTokens = {
153
+ ...mergedTokens,
154
+ ...plugin.tokens
155
+ };
156
+ if (plugin.recipes) mergedRecipes = {
157
+ ...mergedRecipes,
158
+ ...plugin.recipes
159
+ };
160
+ }
161
+ if (config.states) mergedStates = {
162
+ ...mergedStates,
163
+ ...config.states
164
+ };
165
+ if (config.units) mergedUnits = {
166
+ ...mergedUnits,
167
+ ...config.units
168
+ };
169
+ if (config.funcs) mergedFuncs = {
170
+ ...mergedFuncs,
171
+ ...config.funcs
172
+ };
173
+ if (config.handlers) mergedHandlers = {
174
+ ...mergedHandlers,
175
+ ...config.handlers
176
+ };
177
+ if (config.tokens) mergedTokens = {
178
+ ...mergedTokens,
179
+ ...config.tokens
180
+ };
181
+ if (config.recipes) mergedRecipes = {
182
+ ...mergedRecipes,
183
+ ...config.recipes
184
+ };
185
+ if (Object.keys(mergedStates).length > 0) setGlobalPredefinedStates(mergedStates);
186
+ const parser = getGlobalParser();
187
+ if (config.parserCacheSize !== void 0) parser.updateOptions({ cacheSize: config.parserCacheSize });
188
+ if (Object.keys(mergedUnits).length > 0) {
189
+ const currentUnits = parser.getUnits() ?? CUSTOM_UNITS;
190
+ parser.setUnits({
191
+ ...currentUnits,
192
+ ...mergedUnits
193
+ });
194
+ }
195
+ if (Object.keys(mergedFuncs).length > 0) {
196
+ const currentFuncs = getGlobalFuncs();
197
+ const finalFuncs = {
198
+ ...currentFuncs,
199
+ ...mergedFuncs
200
+ };
201
+ parser.setFuncs(finalFuncs);
202
+ Object.assign(currentFuncs, mergedFuncs);
203
+ }
204
+ if (config.keyframes) setGlobalKeyframes(config.keyframes);
205
+ if (config.properties) setGlobalProperties(config.properties);
206
+ if (Object.keys(mergedHandlers).length > 0) for (const [name, definition] of Object.entries(mergedHandlers)) registerHandler(normalizeHandlerDefinition(name, definition));
207
+ if (Object.keys(mergedTokens).length > 0) {
208
+ const processedTokens = {};
209
+ for (const [key, value] of Object.entries(mergedTokens)) if (key.startsWith("#")) {
210
+ const normalized = normalizeColorTokenValue(value);
211
+ if (normalized === null) continue;
212
+ processedTokens[key] = String(normalized);
213
+ } else if (value === false) continue;
214
+ else processedTokens[key] = String(value);
215
+ setGlobalPredefinedTokens(processedTokens);
216
+ }
217
+ if (Object.keys(mergedRecipes).length > 0) setGlobalRecipes(mergedRecipes);
218
+ const { states: _states, parserCacheSize: _parserCacheSize, units: _units, funcs: _funcs, plugins: _plugins, keyframes: _keyframes, properties: _properties, handlers: _handlers, tokens: _tokens, recipes: _recipes, ...injectorConfig } = config;
219
+ const fullConfig = {
220
+ ...createDefaultConfig(),
221
+ ...currentConfig,
222
+ ...injectorConfig
223
+ };
224
+ currentConfig = fullConfig;
225
+ const storage = typeof window !== "undefined" ? window : globalThis;
226
+ storage[GLOBAL_INJECTOR_KEY] = new StyleInjector(fullConfig);
227
+ }
228
+
229
+ //#endregion
230
+ export { configure, getGlobalRecipes, hasStylesGenerated };
231
+ //# sourceMappingURL=config.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.mjs","names":[],"sources":["../src/config.ts"],"sourcesContent":["/**\n * Tasty Configuration Module\n *\n * Centralizes all tasty configuration, including:\n * - Style injector settings (nonce, cleanup thresholds, etc.)\n * - Global predefined states for advanced state mapping\n * - stylesGenerated flag that locks configuration after first style generation\n *\n * Configuration must be done BEFORE any styles are generated.\n * After the first `inject()` call, configuration is locked and attempts to\n * reconfigure will emit a warning and be ignored.\n */\n\nimport { StyleInjector } from './injector/injector';\nimport { clearPipelineCache, isSelector } from './pipeline';\nimport { setGlobalPredefinedStates } from './states';\nimport {\n normalizeHandlerDefinition,\n registerHandler,\n resetHandlers,\n} from './styles/predefined';\nimport { isDevEnv } from './utils/is-dev-env';\nimport {\n CUSTOM_UNITS,\n getGlobalFuncs,\n getGlobalParser,\n normalizeColorTokenValue,\n resetGlobalPredefinedTokens,\n setGlobalPredefinedTokens,\n} from './utils/styles';\n\nimport type { KeyframesSteps, PropertyDefinition } from './injector/types';\nimport type { StyleDetails, UnitHandler } from './parser/types';\nimport type { TastyPlugin } from './plugins/types';\nimport type { RecipeStyles } from './styles/types';\nimport type { StyleHandlerDefinition } from './utils/styles';\n\n/**\n * Configuration options for the Tasty style system\n */\nexport interface TastyConfig {\n /** CSP nonce for style elements */\n nonce?: string;\n /** Maximum rules per stylesheet (default: 8192) */\n maxRulesPerSheet?: number;\n /** Threshold for bulk cleanup of unused styles (default: 500) */\n unusedStylesThreshold?: number;\n /** Delay before bulk cleanup in ms, ignored if idleCleanup is true (default: 5000) */\n bulkCleanupDelay?: number;\n /** Use requestIdleCallback for cleanup when available (default: true) */\n idleCleanup?: boolean;\n /** Force text injection mode, auto-detected in test environments (default: auto) */\n forceTextInjection?: boolean;\n /** Enable development mode features: performance metrics and debug info (default: auto) */\n devMode?: boolean;\n /**\n * Ratio of unused styles to delete per bulk cleanup run (0..1).\n * Defaults to 0.5 (oldest half) to reduce risk of removing styles\n * that may be restored shortly after being marked unused.\n */\n bulkCleanupBatchRatio?: number;\n /**\n * Minimum age (in ms) a style must remain unused before eligible for deletion.\n * Helps avoid races during rapid mount/unmount cycles. Default: 10000ms.\n */\n unusedStylesMinAgeMs?: number;\n /**\n * Global predefined states for advanced state mapping.\n * These are state aliases that can be used in any component.\n * Example: { '@mobile': '@media(w < 920px)', '@dark': '@root(theme=dark)' }\n */\n states?: Record<string, string>;\n /**\n * Parser LRU cache size (default: 1000).\n * Larger values improve performance for apps with many unique style values.\n */\n parserCacheSize?: number;\n /**\n * Custom units for the style parser (merged with built-in units).\n * Units transform numeric values like `2x` → `calc(2 * var(--gap))`.\n * @example { em: 'em', vw: 'vw', custom: (n) => `${n * 10}px` }\n */\n units?: Record<string, string | UnitHandler>;\n /**\n * Custom functions for the style parser (merged with existing).\n * Functions process parsed style groups and return CSS values.\n * @example { myFunc: (groups) => groups.map(g => g.output).join(' ') }\n */\n funcs?: Record<string, (groups: StyleDetails[]) => string>;\n /**\n * Plugins that extend tasty with custom functions, units, or states.\n * Plugins are processed in order, with later plugins overriding earlier ones.\n * @example\n * ```ts\n * import { okhslPlugin } from '@tenphi/tasty';\n *\n * configure({\n * plugins: [okhslPlugin()],\n * });\n * ```\n */\n plugins?: TastyPlugin[];\n /**\n * Global keyframes definitions that can be referenced by animation names in styles.\n * Keys are animation names, values are keyframes step definitions.\n * Keyframes are only injected when actually used in styles.\n * @example\n * ```ts\n * configure({\n * keyframes: {\n * fadeIn: { from: { opacity: 0 }, to: { opacity: 1 } },\n * pulse: { '0%, 100%': { transform: 'scale(1)' }, '50%': { transform: 'scale(1.05)' } },\n * },\n * });\n * ```\n */\n keyframes?: Record<string, KeyframesSteps>;\n /**\n * Global CSS @property definitions for custom properties.\n * Keys use tasty token syntax ($name for properties, #name for colors).\n * Properties are only injected when the component using them is rendered.\n *\n * For color tokens (#name), `syntax: '<color>'` is auto-set and\n * `initialValue` defaults to `'transparent'` if not specified.\n *\n * @example\n * ```ts\n * configure({\n * properties: {\n * '$rotation': { syntax: '<angle>', initialValue: '0deg' },\n * '$scale': { syntax: '<number>', inherits: false, initialValue: 1 },\n * '#accent': { initialValue: 'purple' }, // syntax: '<color>' auto-set\n * },\n * });\n *\n * // Now use in styles - properties are registered when component renders:\n * const Spinner = tasty({\n * styles: {\n * transform: 'rotate($rotation)',\n * transition: '$$rotation 0.3s', // outputs: --rotation 0.3s\n * },\n * });\n * ```\n */\n properties?: Record<string, PropertyDefinition>;\n /**\n * Custom style handlers that transform style properties into CSS declarations.\n * Handlers replace built-in handlers for the same style name.\n * @example\n * ```ts\n * import { styleHandlers } from '@tenphi/tasty';\n *\n * configure({\n * handlers: {\n * // Override fill with custom behavior\n * fill: ({ fill }) => {\n * if (fill?.startsWith('gradient:')) {\n * return { background: fill.slice(9) };\n * }\n * return styleHandlers.fill({ fill });\n * },\n * // Add new custom style\n * elevation: ({ elevation }) => {\n * const level = parseInt(elevation) || 1;\n * return {\n * 'box-shadow': `0 ${level * 2}px ${level * 4}px rgba(0,0,0,0.1)`,\n * 'z-index': String(level * 100),\n * };\n * },\n * },\n * });\n * ```\n */\n handlers?: Record<string, StyleHandlerDefinition>;\n /**\n * Predefined tokens that are replaced during style parsing.\n * Token values are processed through the parser (like component tokens).\n * Use `$name` for custom properties and `#name` for color tokens.\n *\n * For color tokens (#name), boolean `true` is converted to `transparent`.\n *\n * @example\n * ```ts\n * configure({\n * tokens: {\n * $spacing: '2x',\n * '$card-padding': '4x',\n * '#accent': '#purple',\n * '#surface': '#white',\n * '#overlay': true, // → transparent\n * },\n * });\n *\n * // Now use in styles - tokens are replaced at parse time:\n * const Card = tasty({\n * styles: {\n * padding: '$card-padding', // → calc(4 * var(--gap))\n * fill: '#surface', // → var(--white-color)\n * },\n * });\n * ```\n */\n tokens?: Record<`$${string}`, string | number | boolean> & Record<`#${string}`, string | number | boolean>;\n /**\n * Predefined style recipes -- named style bundles that can be applied via `recipe` style property.\n * Recipe values are flat tasty styles (no sub-element keys). They may contain base styles,\n * tokens (`$name`/`#name` definitions), local states, `@keyframes`, and `@properties`.\n *\n * Components reference recipes via: `recipe: 'name1 name2'` in their styles.\n * Use `|` to separate base recipes from post recipes: `recipe: 'base1 base2 | post1'`.\n * Resolution order: `base_recipes → component styles → post_recipes`.\n *\n * Recipes cannot reference other recipes.\n *\n * @example\n * ```ts\n * configure({\n * recipes: {\n * card: { padding: '4x', fill: '#surface', radius: '1r', border: true },\n * elevated: { shadow: '2x 2x 4x #shadow' },\n * },\n * });\n *\n * // Usage in styles:\n * const Card = tasty({\n * styles: {\n * recipe: 'card elevated',\n * color: '#text', // Overrides recipe values\n * },\n * });\n * ```\n */\n recipes?: Record<string, RecipeStyles>;\n}\n\n// Warnings tracking to avoid duplicates\nconst emittedWarnings = new Set<string>();\n\nconst devMode = isDevEnv();\n\n/**\n * Emit a warning only once\n */\nfunction warnOnce(key: string, message: string): void {\n if (devMode && !emittedWarnings.has(key)) {\n emittedWarnings.add(key);\n console.warn(message);\n }\n}\n\n// ============================================================================\n// Configuration State\n// ============================================================================\n\n// Track whether styles have been generated (locks configuration)\nlet stylesGenerated = false;\n\n// Current configuration (null until first configure() or auto-configured on first use)\nlet currentConfig: TastyConfig | null = null;\n\n// Global keyframes storage (null = no keyframes configured, empty object checked via hasGlobalKeyframes)\nlet globalKeyframes: Record<string, KeyframesSteps> | null = null;\n\n// Global properties storage (null = no properties configured)\nlet globalProperties: Record<string, PropertyDefinition> | null = null;\n\n// Global recipes storage (null = no recipes configured)\nlet globalRecipes: Record<string, RecipeStyles> | null = null;\n\n/**\n * Internal properties required by tasty core features.\n * These are always injected when styles are first generated.\n * Keys use tasty token syntax (#name for colors, $name for other properties).\n *\n * For properties with CSS @property-compatible types (length, time, number, color),\n * an `initialValue` is provided so the property works even without a project-level token.\n */\nexport const INTERNAL_PROPERTIES: Record<string, PropertyDefinition> = {\n // Used by dual-fill feature to enable CSS transitions on the second fill color\n '#tasty-second-fill': {\n inherits: false,\n initialValue: 'transparent',\n },\n // Current color context variable (set by the color style handler).\n // Companion --current-color-rgb is auto-created.\n '#current': {\n inherits: true,\n initialValue: 'transparent',\n },\n // White and black are fundamental colors that need explicit initial values.\n // Companion -rgb properties are auto-created from the color initial values.\n '#white': {\n inherits: true,\n initialValue: 'rgb(255 255 255)',\n },\n '#black': {\n inherits: true,\n initialValue: 'rgb(0 0 0)',\n },\n\n // ---- Core design tokens used by style handlers ----\n // These provide sensible defaults so tasty works standalone without a design system.\n // Consuming projects (e.g. uikit) override these by defining tokens on :root.\n\n $gap: {\n syntax: '<length>',\n inherits: true,\n initialValue: '4px',\n },\n $radius: {\n syntax: '<length>',\n inherits: true,\n initialValue: '6px',\n },\n '$border-width': {\n syntax: '<length>',\n inherits: true,\n initialValue: '1px',\n },\n '$outline-width': {\n syntax: '<length>',\n inherits: true,\n initialValue: '3px',\n },\n $transition: {\n syntax: '<time>',\n inherits: true,\n initialValue: '80ms',\n },\n // Used by radius.ts for `radius=\"leaf\"` modifier\n '$sharp-radius': {\n syntax: '<length>',\n inherits: true,\n initialValue: '0px',\n },\n // Used by preset.ts for `preset=\"... strong\"`\n '$bold-font-weight': {\n syntax: '<number>',\n inherits: true,\n initialValue: '700',\n },\n};\n\n/**\n * Internal token defaults that cannot be expressed as CSS @property initial values\n * (e.g. font stacks, keyword colors). These are injected as :root CSS variables.\n * Consuming projects override them by setting their own tokens on :root.\n *\n * Keys are raw CSS custom property names (--name).\n */\nexport const INTERNAL_TOKENS: Record<string, string> = {\n '--font':\n 'system-ui, -apple-system, \"Segoe UI\", Roboto, Helvetica, Arial, \"Apple Color Emoji\", \"Segoe UI Emoji\", sans-serif',\n '--monospace-font':\n 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, \"Liberation Mono\", \"Courier New\", monospace',\n // Default border color to the element's current text color\n '--border-color': 'currentColor',\n};\n\n// Global injector instance key\nconst GLOBAL_INJECTOR_KEY = '__TASTY_GLOBAL_INJECTOR__';\n\ninterface TastyGlobalStorage {\n [GLOBAL_INJECTOR_KEY]?: StyleInjector;\n}\n\ndeclare global {\n interface Window {\n [GLOBAL_INJECTOR_KEY]?: StyleInjector;\n }\n\n \n var __TASTY_GLOBAL_INJECTOR__: StyleInjector | undefined;\n}\n\n/**\n * Detect if we're running in a test environment\n */\nexport function isTestEnvironment(): boolean {\n // Check Node.js environment\n if (typeof process !== 'undefined' && process.env?.NODE_ENV === 'test') {\n return true;\n }\n\n // Check for test runner globals (safely)\n if (typeof global !== 'undefined') {\n const g = global as unknown as Record<string, unknown>;\n if (g.vi || g.jest || g.expect || g.describe || g.it) {\n return true;\n }\n }\n\n // Check for jsdom environment (common in tests)\n if (\n typeof window !== 'undefined' &&\n window.navigator?.userAgent?.includes('jsdom')\n ) {\n return true;\n }\n\n // Check for other test runners\n if (typeof globalThis !== 'undefined') {\n const gt = globalThis as unknown as Record<string, unknown>;\n if (gt.vitest || gt.mocha) {\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * Create default configuration with optional test environment detection\n */\nfunction createDefaultConfig(isTest?: boolean): TastyConfig {\n return {\n maxRulesPerSheet: 8192,\n unusedStylesThreshold: 500,\n bulkCleanupDelay: 5000,\n idleCleanup: true,\n forceTextInjection: isTest ?? false,\n devMode: isDevEnv(),\n bulkCleanupBatchRatio: 0.5,\n unusedStylesMinAgeMs: 10000,\n };\n}\n\n// ============================================================================\n// stylesGenerated Flag Management\n// ============================================================================\n\n/**\n * Mark that styles have been generated (called by injector on first inject)\n * This locks the configuration - no further changes allowed.\n * Also injects internal and global properties.\n */\nexport function markStylesGenerated(): void {\n if (stylesGenerated) return; // Already marked, skip\n\n stylesGenerated = true;\n\n const injector = getGlobalInjector();\n\n // Inject internal properties required by tasty core features\n for (const [token, definition] of Object.entries(INTERNAL_PROPERTIES)) {\n injector.property(token, definition);\n }\n\n // Inject internal token defaults as :root CSS variables.\n // Use injectGlobal (not injectRawCSS) so the rule goes through the same\n // injection path as all other tasty styles (consistent in both DOM and text/test mode).\n const internalTokenEntries = Object.entries(INTERNAL_TOKENS);\n if (internalTokenEntries.length > 0) {\n const declarations = internalTokenEntries\n .map(([name, value]) => `${name}: ${value}`)\n .join('; ');\n injector.injectGlobal([{ selector: ':root', declarations }]);\n }\n\n // Inject global properties if any were configured\n // Properties are permanent and only need to be injected once\n if (globalProperties && Object.keys(globalProperties).length > 0) {\n for (const [token, definition] of Object.entries(globalProperties)) {\n injector.property(token, definition);\n }\n }\n}\n\n/**\n * Check if styles have been generated (configuration is locked)\n */\nexport function hasStylesGenerated(): boolean {\n return stylesGenerated;\n}\n\n/**\n * Reset styles generated flag (for testing only)\n */\nexport function resetStylesGenerated(): void {\n stylesGenerated = false;\n emittedWarnings.clear();\n}\n\n// ============================================================================\n// Global Keyframes Management\n// ============================================================================\n\n/**\n * Check if any global keyframes are configured.\n * Fast path: returns false if no keyframes were ever set.\n */\nexport function hasGlobalKeyframes(): boolean {\n return globalKeyframes !== null && Object.keys(globalKeyframes).length > 0;\n}\n\n/**\n * Get global keyframes configuration.\n * Returns null if no keyframes configured (fast path for zero-overhead).\n */\nexport function getGlobalKeyframes(): Record<string, KeyframesSteps> | null {\n return globalKeyframes;\n}\n\n/**\n * Set global keyframes (called from configure).\n * Internal use only.\n */\nfunction setGlobalKeyframes(keyframes: Record<string, KeyframesSteps>): void {\n if (stylesGenerated) {\n warnOnce(\n 'keyframes-after-styles',\n `[Tasty] Cannot update keyframes after styles have been generated.\\n` +\n `The new keyframes will be ignored.`,\n );\n return;\n }\n globalKeyframes = keyframes;\n}\n\n// ============================================================================\n// Global Properties Management\n// ============================================================================\n\n/**\n * Check if any global properties are configured.\n * Fast path: returns false if no properties were ever set.\n */\nexport function hasGlobalProperties(): boolean {\n return globalProperties !== null && Object.keys(globalProperties).length > 0;\n}\n\n/**\n * Get global properties configuration.\n * Returns null if no properties configured (fast path for zero-overhead).\n */\nexport function getGlobalProperties(): Record<\n string,\n PropertyDefinition\n> | null {\n return globalProperties;\n}\n\n/**\n * Set global properties (called from configure).\n * Internal use only.\n */\nfunction setGlobalProperties(\n properties: Record<string, PropertyDefinition>,\n): void {\n if (stylesGenerated) {\n warnOnce(\n 'properties-after-styles',\n `[Tasty] Cannot update properties after styles have been generated.\\n` +\n `The new properties will be ignored.`,\n );\n return;\n }\n globalProperties = properties;\n}\n\n// ============================================================================\n// Global Recipes Management\n// ============================================================================\n\n/**\n * Check if any global recipes are configured.\n * Fast path: returns false if no recipes were ever set.\n */\nexport function hasGlobalRecipes(): boolean {\n return globalRecipes !== null && Object.keys(globalRecipes).length > 0;\n}\n\n/**\n * Get global recipes configuration.\n * Returns null if no recipes configured (fast path for zero-overhead).\n */\nexport function getGlobalRecipes(): Record<string, RecipeStyles> | null {\n return globalRecipes;\n}\n\n/**\n * Set global recipes (called from configure).\n * Internal use only.\n */\nfunction setGlobalRecipes(recipes: Record<string, RecipeStyles>): void {\n if (stylesGenerated) {\n warnOnce(\n 'recipes-after-styles',\n `[Tasty] Cannot update recipes after styles have been generated.\\n` +\n `The new recipes will be ignored.`,\n );\n return;\n }\n\n // Dev-mode validation\n if (devMode) {\n for (const [name, recipeStyles] of Object.entries(recipes)) {\n for (const key of Object.keys(recipeStyles)) {\n if (isSelector(key)) {\n warnOnce(\n `recipe-selector-${name}-${key}`,\n `[Tasty] Recipe \"${name}\" contains sub-element key \"${key}\". ` +\n `Recipes must be flat styles without sub-element keys. ` +\n `Remove the sub-element key from the recipe definition.`,\n );\n }\n if (key === 'recipe') {\n warnOnce(\n `recipe-recursive-${name}`,\n `[Tasty] Recipe \"${name}\" contains a \"recipe\" key. ` +\n `Recipes cannot reference other recipes. ` +\n `Use space-separated names for composition: recipe: 'base elevated'.`,\n );\n }\n }\n }\n }\n\n globalRecipes = recipes;\n}\n\n/**\n * Check if configuration is locked (styles have been generated)\n */\nexport function isConfigLocked(): boolean {\n return stylesGenerated;\n}\n\n// ============================================================================\n// Configuration API\n// ============================================================================\n\n/**\n * Configure the Tasty style system.\n *\n * Must be called BEFORE any styles are generated (before first render that uses tasty).\n * After styles are generated, configuration is locked and calls to configure() will\n * emit a warning and be ignored.\n *\n * @example\n * ```ts\n * import { configure } from '@tenphi/tasty';\n *\n * // Configure before app renders\n * configure({\n * nonce: 'abc123',\n * states: {\n * '@mobile': '@media(w < 768px)',\n * '@dark': '@root(theme=dark)',\n * },\n * });\n * ```\n */\nexport function configure(config: Partial<TastyConfig> = {}): void {\n if (stylesGenerated) {\n warnOnce(\n 'configure-after-styles',\n `[Tasty] Cannot call configure() after styles have been generated.\\n` +\n `Configuration must be done before the first render. The configuration will be ignored.`,\n );\n return;\n }\n\n // Collect merged values from plugins first, then override with direct config\n let mergedStates: Record<string, string> = {};\n let mergedUnits: Record<string, string | UnitHandler> = {};\n let mergedFuncs: Record<string, (groups: StyleDetails[]) => string> = {};\n let mergedHandlers: Record<string, StyleHandlerDefinition> = {};\n let mergedTokens: Record<string, string | number | boolean> = {};\n let mergedRecipes: Record<string, RecipeStyles> = {};\n\n // Process plugins in order\n if (config.plugins) {\n for (const plugin of config.plugins) {\n if (plugin.states) {\n mergedStates = { ...mergedStates, ...plugin.states };\n }\n if (plugin.units) {\n mergedUnits = { ...mergedUnits, ...plugin.units };\n }\n if (plugin.funcs) {\n mergedFuncs = { ...mergedFuncs, ...plugin.funcs };\n }\n if (plugin.handlers) {\n mergedHandlers = { ...mergedHandlers, ...plugin.handlers };\n }\n if (plugin.tokens) {\n mergedTokens = { ...mergedTokens, ...plugin.tokens };\n }\n if (plugin.recipes) {\n mergedRecipes = { ...mergedRecipes, ...plugin.recipes };\n }\n }\n }\n\n // Direct config overrides plugins\n if (config.states) {\n mergedStates = { ...mergedStates, ...config.states };\n }\n if (config.units) {\n mergedUnits = { ...mergedUnits, ...config.units };\n }\n if (config.funcs) {\n mergedFuncs = { ...mergedFuncs, ...config.funcs };\n }\n if (config.handlers) {\n mergedHandlers = { ...mergedHandlers, ...config.handlers };\n }\n if (config.tokens) {\n mergedTokens = { ...mergedTokens, ...config.tokens };\n }\n if (config.recipes) {\n mergedRecipes = { ...mergedRecipes, ...config.recipes };\n }\n\n // Handle predefined states\n if (Object.keys(mergedStates).length > 0) {\n setGlobalPredefinedStates(mergedStates);\n }\n\n // Handle parser configuration (merge semantics - extend, not replace)\n const parser = getGlobalParser();\n\n if (config.parserCacheSize !== undefined) {\n parser.updateOptions({ cacheSize: config.parserCacheSize });\n }\n\n if (Object.keys(mergedUnits).length > 0) {\n // Merge with existing units\n const currentUnits = parser.getUnits() ?? CUSTOM_UNITS;\n parser.setUnits({ ...currentUnits, ...mergedUnits });\n }\n\n if (Object.keys(mergedFuncs).length > 0) {\n // Merge with existing funcs\n const currentFuncs = getGlobalFuncs();\n const finalFuncs = { ...currentFuncs, ...mergedFuncs };\n parser.setFuncs(finalFuncs);\n // Also update the global registry so customFunc() continues to work\n Object.assign(currentFuncs, mergedFuncs);\n }\n\n // Handle keyframes\n if (config.keyframes) {\n setGlobalKeyframes(config.keyframes);\n }\n\n // Handle properties\n if (config.properties) {\n setGlobalProperties(config.properties);\n }\n\n // Handle custom handlers\n if (Object.keys(mergedHandlers).length > 0) {\n for (const [name, definition] of Object.entries(mergedHandlers)) {\n const handler = normalizeHandlerDefinition(name, definition);\n registerHandler(handler);\n }\n }\n\n // Handle predefined tokens\n // Note: Tokens are processed by the classifier, not here.\n // We just store the raw values; the classifier will process them when encountered.\n if (Object.keys(mergedTokens).length > 0) {\n // Store tokens (keys are normalized to lowercase by setGlobalPredefinedTokens)\n const processedTokens: Record<string, string> = {};\n for (const [key, value] of Object.entries(mergedTokens)) {\n if (key.startsWith('#')) {\n // Color token - use shared helper for boolean handling\n const normalized = normalizeColorTokenValue(value);\n if (normalized === null) continue; // Skip false values\n processedTokens[key] = String(normalized);\n } else if (value === false) {\n // Skip false values for non-color tokens\n continue;\n } else {\n processedTokens[key] = String(value);\n }\n }\n setGlobalPredefinedTokens(processedTokens);\n }\n\n // Handle recipes\n if (Object.keys(mergedRecipes).length > 0) {\n setGlobalRecipes(mergedRecipes);\n }\n\n \n const {\n states: _states,\n parserCacheSize: _parserCacheSize,\n units: _units,\n funcs: _funcs,\n plugins: _plugins,\n keyframes: _keyframes,\n properties: _properties,\n handlers: _handlers,\n tokens: _tokens,\n recipes: _recipes,\n ...injectorConfig\n } = config;\n \n\n const fullConfig: TastyConfig = {\n ...createDefaultConfig(),\n ...currentConfig,\n ...injectorConfig,\n };\n\n // Store the config\n currentConfig = fullConfig;\n\n // Create/replace the global injector\n const storage: TastyGlobalStorage =\n typeof window !== 'undefined' ? window : globalThis;\n storage[GLOBAL_INJECTOR_KEY] = new StyleInjector(fullConfig);\n}\n\n/**\n * Get the current configuration.\n * If not configured, returns default configuration.\n */\nexport function getConfig(): TastyConfig {\n if (!currentConfig) {\n currentConfig = createDefaultConfig(isTestEnvironment());\n }\n return currentConfig;\n}\n\n/**\n * Get the global injector instance.\n * Auto-configures with defaults if not already configured.\n */\nexport function getGlobalInjector(): StyleInjector {\n const storage: TastyGlobalStorage =\n typeof window !== 'undefined' ? window : globalThis;\n\n if (!storage[GLOBAL_INJECTOR_KEY]) {\n configure();\n }\n\n return storage[GLOBAL_INJECTOR_KEY]!;\n}\n\n/**\n * Reset configuration (for testing only).\n * Clears the global injector and allows reconfiguration.\n */\nexport function resetConfig(): void {\n stylesGenerated = false;\n currentConfig = null;\n globalKeyframes = null;\n globalProperties = null;\n globalRecipes = null;\n resetGlobalPredefinedTokens();\n resetHandlers();\n clearPipelineCache();\n emittedWarnings.clear();\n\n const storage: TastyGlobalStorage =\n typeof window !== 'undefined' ? window : globalThis;\n delete storage[GLOBAL_INJECTOR_KEY];\n}\n\n// Re-export TastyConfig as StyleInjectorConfig for backward compatibility\nexport type { TastyConfig as StyleInjectorConfig };\n"],"mappings":"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"}
@@ -0,0 +1,45 @@
1
+ //#region src/zero/css-writer.d.ts
2
+ interface CSSWriterOptions {
3
+ /** Enable source comments in output (e.g., "from: Button.tsx") */
4
+ devMode?: boolean;
5
+ }
6
+ declare class CSSWriter {
7
+ private cssBlocks;
8
+ private outputPath;
9
+ private devMode;
10
+ constructor(outputPath: string, options?: CSSWriterOptions);
11
+ /**
12
+ * Add CSS block with deduplication key
13
+ * @param key - Unique key for deduplication
14
+ * @param css - CSS content
15
+ * @param source - Optional source file path (used in devMode)
16
+ */
17
+ add(key: string, css: string, source?: string): void;
18
+ /**
19
+ * Check if a key already exists
20
+ */
21
+ has(key: string): boolean;
22
+ /**
23
+ * Get the number of CSS blocks
24
+ */
25
+ get size(): number;
26
+ /**
27
+ * Write all collected CSS to the output file
28
+ */
29
+ write(): void;
30
+ /**
31
+ * Get all CSS as string (for testing or in-memory use)
32
+ */
33
+ getCSS(): string;
34
+ /**
35
+ * Clear all collected CSS
36
+ */
37
+ clear(): void;
38
+ /**
39
+ * Get the output path
40
+ */
41
+ getOutputPath(): string;
42
+ }
43
+ //#endregion
44
+ export { CSSWriter };
45
+ //# sourceMappingURL=css-writer.d.mts.map
@@ -0,0 +1,74 @@
1
+ import * as fs from "fs";
2
+ import * as path from "path";
3
+
4
+ //#region src/zero/css-writer.ts
5
+ var CSSWriter = class {
6
+ cssBlocks = /* @__PURE__ */ new Map();
7
+ outputPath;
8
+ devMode;
9
+ constructor(outputPath, options = {}) {
10
+ this.outputPath = outputPath;
11
+ this.devMode = options.devMode ?? false;
12
+ }
13
+ /**
14
+ * Add CSS block with deduplication key
15
+ * @param key - Unique key for deduplication
16
+ * @param css - CSS content
17
+ * @param source - Optional source file path (used in devMode)
18
+ */
19
+ add(key, css, source) {
20
+ this.cssBlocks.set(key, {
21
+ css,
22
+ source
23
+ });
24
+ }
25
+ /**
26
+ * Check if a key already exists
27
+ */
28
+ has(key) {
29
+ return this.cssBlocks.has(key);
30
+ }
31
+ /**
32
+ * Get the number of CSS blocks
33
+ */
34
+ get size() {
35
+ return this.cssBlocks.size;
36
+ }
37
+ /**
38
+ * Write all collected CSS to the output file
39
+ */
40
+ write() {
41
+ const outputDir = path.dirname(this.outputPath);
42
+ if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir, { recursive: true });
43
+ const cssBlocks = [];
44
+ for (const block of this.cssBlocks.values()) if (this.devMode && block.source) cssBlocks.push(`/* from: ${block.source} */\n${block.css}`);
45
+ else cssBlocks.push(block.css);
46
+ const css = cssBlocks.join("\n\n");
47
+ fs.writeFileSync(this.outputPath, `/* Generated by @tenphi/tasty/zero - DO NOT EDIT */\n\n` + css);
48
+ }
49
+ /**
50
+ * Get all CSS as string (for testing or in-memory use)
51
+ */
52
+ getCSS() {
53
+ const cssBlocks = [];
54
+ for (const block of this.cssBlocks.values()) if (this.devMode && block.source) cssBlocks.push(`/* from: ${block.source} */\n${block.css}`);
55
+ else cssBlocks.push(block.css);
56
+ return cssBlocks.join("\n\n");
57
+ }
58
+ /**
59
+ * Clear all collected CSS
60
+ */
61
+ clear() {
62
+ this.cssBlocks.clear();
63
+ }
64
+ /**
65
+ * Get the output path
66
+ */
67
+ getOutputPath() {
68
+ return this.outputPath;
69
+ }
70
+ };
71
+
72
+ //#endregion
73
+ export { CSSWriter };
74
+ //# sourceMappingURL=css-writer.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"css-writer.mjs","names":[],"sources":["../src/zero/css-writer.ts"],"sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\n\nexport interface CSSWriterOptions {\n /** Enable source comments in output (e.g., \"from: Button.tsx\") */\n devMode?: boolean;\n}\n\ninterface CSSBlock {\n css: string;\n source?: string;\n}\n\nexport class CSSWriter {\n private cssBlocks = new Map<string, CSSBlock>();\n private outputPath: string;\n private devMode: boolean;\n\n constructor(outputPath: string, options: CSSWriterOptions = {}) {\n this.outputPath = outputPath;\n this.devMode = options.devMode ?? false;\n }\n\n /**\n * Add CSS block with deduplication key\n * @param key - Unique key for deduplication\n * @param css - CSS content\n * @param source - Optional source file path (used in devMode)\n */\n add(key: string, css: string, source?: string): void {\n this.cssBlocks.set(key, { css, source });\n }\n\n /**\n * Check if a key already exists\n */\n has(key: string): boolean {\n return this.cssBlocks.has(key);\n }\n\n /**\n * Get the number of CSS blocks\n */\n get size(): number {\n return this.cssBlocks.size;\n }\n\n /**\n * Write all collected CSS to the output file\n */\n write(): void {\n const outputDir = path.dirname(this.outputPath);\n\n // Ensure directory exists\n if (!fs.existsSync(outputDir)) {\n fs.mkdirSync(outputDir, { recursive: true });\n }\n\n // Combine all CSS blocks with optional source comments\n const cssBlocks: string[] = [];\n for (const block of this.cssBlocks.values()) {\n if (this.devMode && block.source) {\n cssBlocks.push(`/* from: ${block.source} */\\n${block.css}`);\n } else {\n cssBlocks.push(block.css);\n }\n }\n const css = cssBlocks.join('\\n\\n');\n\n // Add header comment\n const header = `/* Generated by @tenphi/tasty/zero - DO NOT EDIT */\\n\\n`;\n\n fs.writeFileSync(this.outputPath, header + css);\n }\n\n /**\n * Get all CSS as string (for testing or in-memory use)\n */\n getCSS(): string {\n const cssBlocks: string[] = [];\n for (const block of this.cssBlocks.values()) {\n if (this.devMode && block.source) {\n cssBlocks.push(`/* from: ${block.source} */\\n${block.css}`);\n } else {\n cssBlocks.push(block.css);\n }\n }\n return cssBlocks.join('\\n\\n');\n }\n\n /**\n * Clear all collected CSS\n */\n clear(): void {\n this.cssBlocks.clear();\n }\n\n /**\n * Get the output path\n */\n getOutputPath(): string {\n return this.outputPath;\n }\n}\n"],"mappings":";;;;AAaA,IAAa,YAAb,MAAuB;CACrB,AAAQ,4BAAY,IAAI,KAAuB;CAC/C,AAAQ;CACR,AAAQ;CAER,YAAY,YAAoB,UAA4B,EAAE,EAAE;AAC9D,OAAK,aAAa;AAClB,OAAK,UAAU,QAAQ,WAAW;;;;;;;;CASpC,IAAI,KAAa,KAAa,QAAuB;AACnD,OAAK,UAAU,IAAI,KAAK;GAAE;GAAK;GAAQ,CAAC;;;;;CAM1C,IAAI,KAAsB;AACxB,SAAO,KAAK,UAAU,IAAI,IAAI;;;;;CAMhC,IAAI,OAAe;AACjB,SAAO,KAAK,UAAU;;;;;CAMxB,QAAc;EACZ,MAAM,YAAY,KAAK,QAAQ,KAAK,WAAW;AAG/C,MAAI,CAAC,GAAG,WAAW,UAAU,CAC3B,IAAG,UAAU,WAAW,EAAE,WAAW,MAAM,CAAC;EAI9C,MAAM,YAAsB,EAAE;AAC9B,OAAK,MAAM,SAAS,KAAK,UAAU,QAAQ,CACzC,KAAI,KAAK,WAAW,MAAM,OACxB,WAAU,KAAK,YAAY,MAAM,OAAO,OAAO,MAAM,MAAM;MAE3D,WAAU,KAAK,MAAM,IAAI;EAG7B,MAAM,MAAM,UAAU,KAAK,OAAO;AAKlC,KAAG,cAAc,KAAK,YAFP,4DAE4B,IAAI;;;;;CAMjD,SAAiB;EACf,MAAM,YAAsB,EAAE;AAC9B,OAAK,MAAM,SAAS,KAAK,UAAU,QAAQ,CACzC,KAAI,KAAK,WAAW,MAAM,OACxB,WAAU,KAAK,YAAY,MAAM,OAAO,OAAO,MAAM,MAAM;MAE3D,WAAU,KAAK,MAAM,IAAI;AAG7B,SAAO,UAAU,KAAK,OAAO;;;;;CAM/B,QAAc;AACZ,OAAK,UAAU,OAAO;;;;;CAMxB,gBAAwB;AACtB,SAAO,KAAK"}
@@ -0,0 +1,204 @@
1
+ //#region src/debug.d.ts
2
+ /**
3
+ * Debug utilities for inspecting tasty-generated CSS at runtime
4
+ */
5
+ declare global {
6
+ interface Window {
7
+ tastyDebug?: typeof tastyDebug;
8
+ }
9
+ }
10
+ type CSSTarget = 'all' | 'global' | 'active' | 'unused' | 'page' | string | string[] | Element;
11
+ interface CssOptions {
12
+ root?: Document | ShadowRoot;
13
+ prettify?: boolean;
14
+ log?: boolean;
15
+ }
16
+ interface ChunkInfo {
17
+ className: string;
18
+ chunkName: string | null;
19
+ }
20
+ interface InspectResult {
21
+ element?: Element | null;
22
+ classes: string[];
23
+ chunks: ChunkInfo[];
24
+ css: string;
25
+ size: number;
26
+ rules: number;
27
+ }
28
+ interface CacheMetrics {
29
+ hits: number;
30
+ misses: number;
31
+ bulkCleanups: number;
32
+ totalInsertions: number;
33
+ totalUnused: number;
34
+ stylesCleanedUp: number;
35
+ cleanupHistory: {
36
+ timestamp: number;
37
+ classesDeleted: number;
38
+ cssSize: number;
39
+ rulesDeleted: number;
40
+ }[];
41
+ startTime: number;
42
+ unusedHits?: number;
43
+ }
44
+ interface CacheStatus {
45
+ classes: {
46
+ active: string[];
47
+ unused: string[];
48
+ all: string[];
49
+ };
50
+ metrics: CacheMetrics | null;
51
+ }
52
+ interface Definitions {
53
+ properties: string[];
54
+ keyframes: {
55
+ name: string;
56
+ refCount: number;
57
+ }[];
58
+ }
59
+ interface SummaryOptions {
60
+ root?: Document | ShadowRoot;
61
+ log?: boolean;
62
+ includePageCSS?: false | true | 'all';
63
+ }
64
+ interface Summary {
65
+ activeClasses: string[];
66
+ unusedClasses: string[];
67
+ totalStyledClasses: string[];
68
+ activeCSSSize: number;
69
+ unusedCSSSize: number;
70
+ globalCSSSize: number;
71
+ rawCSSSize: number;
72
+ keyframesCSSSize: number;
73
+ propertyCSSSize: number;
74
+ totalCSSSize: number;
75
+ activeCSS: string;
76
+ unusedCSS: string;
77
+ globalCSS: string;
78
+ rawCSS: string;
79
+ keyframesCSS: string;
80
+ propertyCSS: string;
81
+ allCSS: string;
82
+ globalRuleCount: number;
83
+ rawRuleCount: number;
84
+ keyframesRuleCount: number;
85
+ propertyRuleCount: number;
86
+ page?: {
87
+ css?: string;
88
+ cssSize: number;
89
+ ruleCount: number;
90
+ stylesheetCount: number;
91
+ skippedStylesheets: number;
92
+ };
93
+ metrics: CacheMetrics | null;
94
+ definedProperties: string[];
95
+ definedKeyframes: {
96
+ name: string;
97
+ refCount: number;
98
+ }[];
99
+ propertyCount: number;
100
+ keyframeCount: number;
101
+ cleanupSummary: {
102
+ enabled: boolean;
103
+ totalCleanups: number;
104
+ totalClassesDeleted: number;
105
+ totalCssDeleted: number;
106
+ totalRulesDeleted: number;
107
+ averageClassesPerCleanup: number;
108
+ averageCssPerCleanup: number;
109
+ averageRulesPerCleanup: number;
110
+ lastCleanup?: {
111
+ timestamp: number;
112
+ date: string;
113
+ classesDeleted: number;
114
+ cssSize: number;
115
+ rulesDeleted: number;
116
+ };
117
+ };
118
+ chunkBreakdown: {
119
+ byChunk: Record<string, {
120
+ classes: string[];
121
+ cssSize: number;
122
+ ruleCount: number;
123
+ }>;
124
+ totalChunkTypes: number;
125
+ };
126
+ }
127
+ /**
128
+ * Concise tastyDebug API for inspecting styles at runtime
129
+ */
130
+ declare const tastyDebug: {
131
+ css(target: CSSTarget, opts?: CssOptions): string;
132
+ inspect(target: string | Element, opts?: {
133
+ root?: Document | ShadowRoot;
134
+ }): InspectResult;
135
+ cache(opts?: {
136
+ root?: Document | ShadowRoot;
137
+ includeHistory?: boolean;
138
+ }): CacheStatus;
139
+ cleanup(opts?: {
140
+ root?: Document | ShadowRoot;
141
+ }): void;
142
+ metrics(opts?: {
143
+ root?: Document | ShadowRoot;
144
+ }): CacheMetrics | null;
145
+ resetMetrics(opts?: {
146
+ root?: Document | ShadowRoot;
147
+ }): void;
148
+ /**
149
+ * Get breakdown of styles by chunk type.
150
+ *
151
+ * With style chunking enabled, styles are split into logical chunks
152
+ * (appearance, font, dimension, container, etc.) for better caching
153
+ * and CSS reuse.
154
+ *
155
+ * @param opts - Options including root document/shadow root
156
+ * @returns Breakdown by chunk type with class counts and CSS sizes
157
+ */
158
+ chunks(opts?: {
159
+ root?: Document | ShadowRoot;
160
+ log?: boolean;
161
+ }): {
162
+ byChunk: Record<string, {
163
+ classes: string[];
164
+ cssSize: number;
165
+ ruleCount: number;
166
+ }>;
167
+ totalChunkTypes: number;
168
+ totalClasses: number;
169
+ };
170
+ getGlobalTypeCSS(type: "global" | "raw" | "keyframes" | "property", opts?: {
171
+ root?: Document | ShadowRoot;
172
+ }): {
173
+ css: string;
174
+ ruleCount: number;
175
+ size: number;
176
+ };
177
+ defs(opts?: {
178
+ root?: Document | ShadowRoot;
179
+ }): Definitions;
180
+ summary(opts?: SummaryOptions): Summary;
181
+ pageCSS(opts?: {
182
+ root?: Document | ShadowRoot;
183
+ prettify?: boolean;
184
+ log?: boolean;
185
+ includeCrossOrigin?: boolean;
186
+ }): string;
187
+ pageStats(opts?: {
188
+ root?: Document | ShadowRoot;
189
+ includeCrossOrigin?: boolean;
190
+ }): {
191
+ cssSize: number;
192
+ ruleCount: number;
193
+ stylesheetCount: number;
194
+ skippedStylesheets: number;
195
+ };
196
+ install(): void;
197
+ log(target: CSSTarget, opts?: CssOptions & {
198
+ title?: string;
199
+ }): void;
200
+ help(): void;
201
+ };
202
+ //#endregion
203
+ export { tastyDebug };
204
+ //# sourceMappingURL=debug.d.ts.map