@tenphi/tasty 0.0.0-snapshot.056b911

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 (332) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +635 -0
  3. package/dist/_virtual/_rolldown/runtime.js +7 -0
  4. package/dist/chunks/cacheKey.d.ts +1 -0
  5. package/dist/chunks/cacheKey.js +77 -0
  6. package/dist/chunks/cacheKey.js.map +1 -0
  7. package/dist/chunks/definitions.d.ts +37 -0
  8. package/dist/chunks/definitions.js +258 -0
  9. package/dist/chunks/definitions.js.map +1 -0
  10. package/dist/chunks/index.d.ts +1 -0
  11. package/dist/chunks/renderChunk.d.ts +1 -0
  12. package/dist/chunks/renderChunk.js +59 -0
  13. package/dist/chunks/renderChunk.js.map +1 -0
  14. package/dist/compute-styles.d.ts +31 -0
  15. package/dist/compute-styles.js +335 -0
  16. package/dist/compute-styles.js.map +1 -0
  17. package/dist/config.d.ts +409 -0
  18. package/dist/config.js +584 -0
  19. package/dist/config.js.map +1 -0
  20. package/dist/core/index.d.ts +34 -0
  21. package/dist/core/index.js +27 -0
  22. package/dist/counter-style/index.js +51 -0
  23. package/dist/counter-style/index.js.map +1 -0
  24. package/dist/debug.d.ts +89 -0
  25. package/dist/debug.js +453 -0
  26. package/dist/debug.js.map +1 -0
  27. package/dist/font-face/index.js +63 -0
  28. package/dist/font-face/index.js.map +1 -0
  29. package/dist/hooks/index.d.ts +7 -0
  30. package/dist/hooks/useCounterStyle.d.ts +36 -0
  31. package/dist/hooks/useCounterStyle.js +64 -0
  32. package/dist/hooks/useCounterStyle.js.map +1 -0
  33. package/dist/hooks/useFontFace.d.ts +45 -0
  34. package/dist/hooks/useFontFace.js +66 -0
  35. package/dist/hooks/useFontFace.js.map +1 -0
  36. package/dist/hooks/useGlobalStyles.d.ts +46 -0
  37. package/dist/hooks/useGlobalStyles.js +88 -0
  38. package/dist/hooks/useGlobalStyles.js.map +1 -0
  39. package/dist/hooks/useKeyframes.d.ts +58 -0
  40. package/dist/hooks/useKeyframes.js +54 -0
  41. package/dist/hooks/useKeyframes.js.map +1 -0
  42. package/dist/hooks/useProperty.d.ts +81 -0
  43. package/dist/hooks/useProperty.js +96 -0
  44. package/dist/hooks/useProperty.js.map +1 -0
  45. package/dist/hooks/useRawCSS.d.ts +22 -0
  46. package/dist/hooks/useRawCSS.js +103 -0
  47. package/dist/hooks/useRawCSS.js.map +1 -0
  48. package/dist/hooks/useStyles.d.ts +40 -0
  49. package/dist/hooks/useStyles.js +31 -0
  50. package/dist/hooks/useStyles.js.map +1 -0
  51. package/dist/index.d.ts +51 -0
  52. package/dist/index.js +36 -0
  53. package/dist/injector/index.d.ts +182 -0
  54. package/dist/injector/index.js +185 -0
  55. package/dist/injector/index.js.map +1 -0
  56. package/dist/injector/injector.d.ts +193 -0
  57. package/dist/injector/injector.js +564 -0
  58. package/dist/injector/injector.js.map +1 -0
  59. package/dist/injector/sheet-manager.d.ts +132 -0
  60. package/dist/injector/sheet-manager.js +698 -0
  61. package/dist/injector/sheet-manager.js.map +1 -0
  62. package/dist/injector/types.d.ts +228 -0
  63. package/dist/keyframes/index.js +206 -0
  64. package/dist/keyframes/index.js.map +1 -0
  65. package/dist/parser/classify.js +319 -0
  66. package/dist/parser/classify.js.map +1 -0
  67. package/dist/parser/const.js +60 -0
  68. package/dist/parser/const.js.map +1 -0
  69. package/dist/parser/lru.js +109 -0
  70. package/dist/parser/lru.js.map +1 -0
  71. package/dist/parser/parser.d.ts +25 -0
  72. package/dist/parser/parser.js +115 -0
  73. package/dist/parser/parser.js.map +1 -0
  74. package/dist/parser/tokenizer.js +69 -0
  75. package/dist/parser/tokenizer.js.map +1 -0
  76. package/dist/parser/types.d.ts +51 -0
  77. package/dist/parser/types.js +46 -0
  78. package/dist/parser/types.js.map +1 -0
  79. package/dist/pipeline/conditions.d.ts +134 -0
  80. package/dist/pipeline/conditions.js +406 -0
  81. package/dist/pipeline/conditions.js.map +1 -0
  82. package/dist/pipeline/exclusive.js +230 -0
  83. package/dist/pipeline/exclusive.js.map +1 -0
  84. package/dist/pipeline/index.d.ts +55 -0
  85. package/dist/pipeline/index.js +708 -0
  86. package/dist/pipeline/index.js.map +1 -0
  87. package/dist/pipeline/materialize.js +1103 -0
  88. package/dist/pipeline/materialize.js.map +1 -0
  89. package/dist/pipeline/parseStateKey.d.ts +15 -0
  90. package/dist/pipeline/parseStateKey.js +446 -0
  91. package/dist/pipeline/parseStateKey.js.map +1 -0
  92. package/dist/pipeline/simplify.js +515 -0
  93. package/dist/pipeline/simplify.js.map +1 -0
  94. package/dist/pipeline/warnings.js +18 -0
  95. package/dist/pipeline/warnings.js.map +1 -0
  96. package/dist/plugins/index.d.ts +2 -0
  97. package/dist/plugins/okhsl-plugin.d.ts +35 -0
  98. package/dist/plugins/okhsl-plugin.js +97 -0
  99. package/dist/plugins/okhsl-plugin.js.map +1 -0
  100. package/dist/plugins/types.d.ts +87 -0
  101. package/dist/properties/index.js +222 -0
  102. package/dist/properties/index.js.map +1 -0
  103. package/dist/properties/property-type-resolver.d.ts +24 -0
  104. package/dist/properties/property-type-resolver.js +90 -0
  105. package/dist/properties/property-type-resolver.js.map +1 -0
  106. package/dist/rsc-cache.js +81 -0
  107. package/dist/rsc-cache.js.map +1 -0
  108. package/dist/ssr/astro-client.d.ts +1 -0
  109. package/dist/ssr/astro-client.js +24 -0
  110. package/dist/ssr/astro-client.js.map +1 -0
  111. package/dist/ssr/astro-middleware.d.ts +15 -0
  112. package/dist/ssr/astro-middleware.js +19 -0
  113. package/dist/ssr/astro-middleware.js.map +1 -0
  114. package/dist/ssr/astro.d.ts +106 -0
  115. package/dist/ssr/astro.js +149 -0
  116. package/dist/ssr/astro.js.map +1 -0
  117. package/dist/ssr/async-storage.d.ts +17 -0
  118. package/dist/ssr/async-storage.js +44 -0
  119. package/dist/ssr/async-storage.js.map +1 -0
  120. package/dist/ssr/collect-auto-properties.js +58 -0
  121. package/dist/ssr/collect-auto-properties.js.map +1 -0
  122. package/dist/ssr/collector.d.ts +102 -0
  123. package/dist/ssr/collector.js +227 -0
  124. package/dist/ssr/collector.js.map +1 -0
  125. package/dist/ssr/context.js +16 -0
  126. package/dist/ssr/context.js.map +1 -0
  127. package/dist/ssr/format-global-rules.js +22 -0
  128. package/dist/ssr/format-global-rules.js.map +1 -0
  129. package/dist/ssr/format-keyframes.js +69 -0
  130. package/dist/ssr/format-keyframes.js.map +1 -0
  131. package/dist/ssr/format-property.js +49 -0
  132. package/dist/ssr/format-property.js.map +1 -0
  133. package/dist/ssr/format-rules.js +73 -0
  134. package/dist/ssr/format-rules.js.map +1 -0
  135. package/dist/ssr/hydrate.d.ts +22 -0
  136. package/dist/ssr/hydrate.js +49 -0
  137. package/dist/ssr/hydrate.js.map +1 -0
  138. package/dist/ssr/index.d.ts +4 -0
  139. package/dist/ssr/index.js +10 -0
  140. package/dist/ssr/index.js.map +1 -0
  141. package/dist/ssr/next.d.ts +45 -0
  142. package/dist/ssr/next.js +75 -0
  143. package/dist/ssr/next.js.map +1 -0
  144. package/dist/ssr/ssr-collector-ref.js +29 -0
  145. package/dist/ssr/ssr-collector-ref.js.map +1 -0
  146. package/dist/states/index.d.ts +49 -0
  147. package/dist/states/index.js +170 -0
  148. package/dist/states/index.js.map +1 -0
  149. package/dist/static/index.d.ts +5 -0
  150. package/dist/static/index.js +4 -0
  151. package/dist/static/inject.d.ts +5 -0
  152. package/dist/static/inject.js +17 -0
  153. package/dist/static/inject.js.map +1 -0
  154. package/dist/static/tastyStatic.d.ts +46 -0
  155. package/dist/static/tastyStatic.js +30 -0
  156. package/dist/static/tastyStatic.js.map +1 -0
  157. package/dist/static/types.d.ts +49 -0
  158. package/dist/static/types.js +24 -0
  159. package/dist/static/types.js.map +1 -0
  160. package/dist/styles/border.d.ts +25 -0
  161. package/dist/styles/border.js +120 -0
  162. package/dist/styles/border.js.map +1 -0
  163. package/dist/styles/color.d.ts +14 -0
  164. package/dist/styles/color.js +26 -0
  165. package/dist/styles/color.js.map +1 -0
  166. package/dist/styles/const.js +17 -0
  167. package/dist/styles/const.js.map +1 -0
  168. package/dist/styles/createStyle.js +79 -0
  169. package/dist/styles/createStyle.js.map +1 -0
  170. package/dist/styles/dimension.js +109 -0
  171. package/dist/styles/dimension.js.map +1 -0
  172. package/dist/styles/directional.js +133 -0
  173. package/dist/styles/directional.js.map +1 -0
  174. package/dist/styles/display.d.ts +30 -0
  175. package/dist/styles/display.js +73 -0
  176. package/dist/styles/display.js.map +1 -0
  177. package/dist/styles/fade.d.ts +15 -0
  178. package/dist/styles/fade.js +62 -0
  179. package/dist/styles/fade.js.map +1 -0
  180. package/dist/styles/fill.d.ts +42 -0
  181. package/dist/styles/fill.js +51 -0
  182. package/dist/styles/fill.js.map +1 -0
  183. package/dist/styles/flow.d.ts +16 -0
  184. package/dist/styles/flow.js +12 -0
  185. package/dist/styles/flow.js.map +1 -0
  186. package/dist/styles/gap.d.ts +31 -0
  187. package/dist/styles/gap.js +38 -0
  188. package/dist/styles/gap.js.map +1 -0
  189. package/dist/styles/height.d.ts +17 -0
  190. package/dist/styles/height.js +19 -0
  191. package/dist/styles/height.js.map +1 -0
  192. package/dist/styles/index.d.ts +1 -0
  193. package/dist/styles/index.js +8 -0
  194. package/dist/styles/index.js.map +1 -0
  195. package/dist/styles/inset.d.ts +24 -0
  196. package/dist/styles/inset.js +34 -0
  197. package/dist/styles/inset.js.map +1 -0
  198. package/dist/styles/list.d.ts +16 -0
  199. package/dist/styles/list.js +100 -0
  200. package/dist/styles/list.js.map +1 -0
  201. package/dist/styles/margin.d.ts +24 -0
  202. package/dist/styles/margin.js +32 -0
  203. package/dist/styles/margin.js.map +1 -0
  204. package/dist/styles/outline.d.ts +29 -0
  205. package/dist/styles/outline.js +55 -0
  206. package/dist/styles/outline.js.map +1 -0
  207. package/dist/styles/padding.d.ts +24 -0
  208. package/dist/styles/padding.js +32 -0
  209. package/dist/styles/padding.js.map +1 -0
  210. package/dist/styles/placement.d.ts +37 -0
  211. package/dist/styles/placement.js +74 -0
  212. package/dist/styles/placement.js.map +1 -0
  213. package/dist/styles/predefined.d.ts +71 -0
  214. package/dist/styles/predefined.js +237 -0
  215. package/dist/styles/predefined.js.map +1 -0
  216. package/dist/styles/preset.d.ts +52 -0
  217. package/dist/styles/preset.js +127 -0
  218. package/dist/styles/preset.js.map +1 -0
  219. package/dist/styles/radius.d.ts +12 -0
  220. package/dist/styles/radius.js +83 -0
  221. package/dist/styles/radius.js.map +1 -0
  222. package/dist/styles/scrollMargin.d.ts +24 -0
  223. package/dist/styles/scrollMargin.js +32 -0
  224. package/dist/styles/scrollMargin.js.map +1 -0
  225. package/dist/styles/scrollbar.d.ts +25 -0
  226. package/dist/styles/scrollbar.js +51 -0
  227. package/dist/styles/scrollbar.js.map +1 -0
  228. package/dist/styles/shadow.d.ts +14 -0
  229. package/dist/styles/shadow.js +25 -0
  230. package/dist/styles/shadow.js.map +1 -0
  231. package/dist/styles/shared.js +17 -0
  232. package/dist/styles/shared.js.map +1 -0
  233. package/dist/styles/transition.d.ts +14 -0
  234. package/dist/styles/transition.js +159 -0
  235. package/dist/styles/transition.js.map +1 -0
  236. package/dist/styles/types.d.ts +564 -0
  237. package/dist/styles/width.d.ts +17 -0
  238. package/dist/styles/width.js +19 -0
  239. package/dist/styles/width.js.map +1 -0
  240. package/dist/tasty.d.ts +134 -0
  241. package/dist/tasty.js +243 -0
  242. package/dist/tasty.js.map +1 -0
  243. package/dist/types.d.ts +184 -0
  244. package/dist/utils/cache-wrapper.js +21 -0
  245. package/dist/utils/cache-wrapper.js.map +1 -0
  246. package/dist/utils/case-converter.js +8 -0
  247. package/dist/utils/case-converter.js.map +1 -0
  248. package/dist/utils/color-math.d.ts +46 -0
  249. package/dist/utils/color-math.js +749 -0
  250. package/dist/utils/color-math.js.map +1 -0
  251. package/dist/utils/color-space.d.ts +5 -0
  252. package/dist/utils/color-space.js +228 -0
  253. package/dist/utils/color-space.js.map +1 -0
  254. package/dist/utils/colors.d.ts +5 -0
  255. package/dist/utils/colors.js +10 -0
  256. package/dist/utils/colors.js.map +1 -0
  257. package/dist/utils/css-types.d.ts +7 -0
  258. package/dist/utils/deps-equal.js +15 -0
  259. package/dist/utils/deps-equal.js.map +1 -0
  260. package/dist/utils/dotize.d.ts +26 -0
  261. package/dist/utils/dotize.js +122 -0
  262. package/dist/utils/dotize.js.map +1 -0
  263. package/dist/utils/filter-base-props.d.ts +15 -0
  264. package/dist/utils/filter-base-props.js +45 -0
  265. package/dist/utils/filter-base-props.js.map +1 -0
  266. package/dist/utils/get-display-name.d.ts +7 -0
  267. package/dist/utils/get-display-name.js +10 -0
  268. package/dist/utils/get-display-name.js.map +1 -0
  269. package/dist/utils/has-keys.js +13 -0
  270. package/dist/utils/has-keys.js.map +1 -0
  271. package/dist/utils/hash.js +14 -0
  272. package/dist/utils/hash.js.map +1 -0
  273. package/dist/utils/is-dev-env.js +19 -0
  274. package/dist/utils/is-dev-env.js.map +1 -0
  275. package/dist/utils/is-valid-element-type.js +15 -0
  276. package/dist/utils/is-valid-element-type.js.map +1 -0
  277. package/dist/utils/merge-styles.d.ts +7 -0
  278. package/dist/utils/merge-styles.js +145 -0
  279. package/dist/utils/merge-styles.js.map +1 -0
  280. package/dist/utils/mod-attrs.d.ts +6 -0
  281. package/dist/utils/mod-attrs.js +20 -0
  282. package/dist/utils/mod-attrs.js.map +1 -0
  283. package/dist/utils/process-tokens.d.ts +17 -0
  284. package/dist/utils/process-tokens.js +83 -0
  285. package/dist/utils/process-tokens.js.map +1 -0
  286. package/dist/utils/resolve-recipes.d.ts +17 -0
  287. package/dist/utils/resolve-recipes.js +146 -0
  288. package/dist/utils/resolve-recipes.js.map +1 -0
  289. package/dist/utils/selector-transform.js +32 -0
  290. package/dist/utils/selector-transform.js.map +1 -0
  291. package/dist/utils/string.js +8 -0
  292. package/dist/utils/string.js.map +1 -0
  293. package/dist/utils/styles.d.ts +99 -0
  294. package/dist/utils/styles.js +220 -0
  295. package/dist/utils/styles.js.map +1 -0
  296. package/dist/utils/typography.d.ts +58 -0
  297. package/dist/utils/typography.js +51 -0
  298. package/dist/utils/typography.js.map +1 -0
  299. package/dist/utils/warnings.d.ts +16 -0
  300. package/dist/utils/warnings.js +16 -0
  301. package/dist/utils/warnings.js.map +1 -0
  302. package/dist/zero/babel.d.ts +195 -0
  303. package/dist/zero/babel.js +456 -0
  304. package/dist/zero/babel.js.map +1 -0
  305. package/dist/zero/css-writer.d.ts +45 -0
  306. package/dist/zero/css-writer.js +73 -0
  307. package/dist/zero/css-writer.js.map +1 -0
  308. package/dist/zero/extractor.d.ts +24 -0
  309. package/dist/zero/extractor.js +266 -0
  310. package/dist/zero/extractor.js.map +1 -0
  311. package/dist/zero/index.d.ts +3 -0
  312. package/dist/zero/index.js +3 -0
  313. package/dist/zero/next.d.ts +86 -0
  314. package/dist/zero/next.js +143 -0
  315. package/dist/zero/next.js.map +1 -0
  316. package/docs/PIPELINE.md +519 -0
  317. package/docs/README.md +31 -0
  318. package/docs/adoption.md +298 -0
  319. package/docs/comparison.md +419 -0
  320. package/docs/configuration.md +389 -0
  321. package/docs/debug.md +318 -0
  322. package/docs/design-system.md +436 -0
  323. package/docs/dsl.md +688 -0
  324. package/docs/getting-started.md +217 -0
  325. package/docs/injector.md +544 -0
  326. package/docs/methodology.md +616 -0
  327. package/docs/react-api.md +557 -0
  328. package/docs/ssr.md +440 -0
  329. package/docs/styles.md +596 -0
  330. package/docs/tasty-static.md +532 -0
  331. package/package.json +221 -0
  332. package/tasty.config.ts +14 -0
package/dist/config.js ADDED
@@ -0,0 +1,584 @@
1
+ import { resetColorSpace, setColorSpace } from "./utils/color-space.js";
2
+ import { isDevEnv } from "./utils/is-dev-env.js";
3
+ import { CUSTOM_UNITS, getGlobalFuncs, getGlobalParser, normalizeColorTokenValue, resetGlobalPredefinedTokens, setGlobalPredefinedTokens } from "./utils/styles.js";
4
+ import { normalizeHandlerDefinition, registerHandler, resetHandlers } from "./styles/predefined.js";
5
+ import { StyleInjector } from "./injector/injector.js";
6
+ import { setGlobalPredefinedStates } from "./states/index.js";
7
+ import { clearPipelineCache, isSelector, renderStyles } from "./pipeline/index.js";
8
+ import { generateTypographyTokens } from "./utils/typography.js";
9
+ //#region src/config.ts
10
+ /**
11
+ * Tasty Configuration Module
12
+ *
13
+ * Centralizes all tasty configuration, including:
14
+ * - Style injector settings (nonce, cleanup thresholds, etc.)
15
+ * - Global predefined states for advanced state mapping
16
+ * - stylesGenerated flag that locks configuration after first style generation
17
+ *
18
+ * Configuration must be done BEFORE any styles are generated.
19
+ * After the first `inject()` call, configuration is locked and attempts to
20
+ * reconfigure will emit a warning and be ignored.
21
+ */
22
+ const emittedWarnings = /* @__PURE__ */ new Set();
23
+ const devMode = isDevEnv();
24
+ /**
25
+ * Emit a warning only once
26
+ */
27
+ function warnOnce(key, message) {
28
+ if (devMode && !emittedWarnings.has(key)) {
29
+ emittedWarnings.add(key);
30
+ console.warn(message);
31
+ }
32
+ }
33
+ let stylesGenerated = false;
34
+ let currentConfig = null;
35
+ let globalKeyframes = null;
36
+ let globalFontFace = null;
37
+ let globalCounterStyle = null;
38
+ let globalProperties = null;
39
+ let globalRecipes = null;
40
+ let globalConfigTokens = null;
41
+ let globalBodyStyles = null;
42
+ const GTKEY_TOKENS = "__tasty_cfg_tokens__";
43
+ const GTKEY_FONT_FACE = "__tasty_cfg_font_face__";
44
+ const GTKEY_COUNTER_STYLE = "__tasty_cfg_counter_style__";
45
+ const GTKEY_PROPERTIES = "__tasty_cfg_properties__";
46
+ const GTKEY_BODY_STYLES = "__tasty_cfg_body_styles__";
47
+ function setOnGlobalThis(key, value) {
48
+ globalThis[key] = value;
49
+ }
50
+ function getFromGlobalThis(key) {
51
+ return globalThis[key];
52
+ }
53
+ function clearGlobalThisConfig() {
54
+ const g = globalThis;
55
+ delete g[GTKEY_TOKENS];
56
+ delete g[GTKEY_FONT_FACE];
57
+ delete g[GTKEY_COUNTER_STYLE];
58
+ delete g[GTKEY_PROPERTIES];
59
+ delete g[GTKEY_BODY_STYLES];
60
+ }
61
+ /**
62
+ * Default properties shipped with tasty.
63
+ * These are always included unless explicitly overridden via `configure({ properties })`.
64
+ * Keys use tasty token syntax (#name for colors, $name for other properties).
65
+ *
66
+ * For properties with CSS @property-compatible types (length, time, number, color),
67
+ * an `initialValue` is provided so the property works even without a project-level token.
68
+ */
69
+ const DEFAULT_PROPERTIES = {
70
+ "#tasty-second-fill": {
71
+ inherits: false,
72
+ initialValue: "transparent"
73
+ },
74
+ "#current": {
75
+ inherits: true,
76
+ initialValue: "transparent"
77
+ },
78
+ "#white": {
79
+ inherits: true,
80
+ initialValue: "rgb(255 255 255)"
81
+ },
82
+ "#black": {
83
+ inherits: true,
84
+ initialValue: "rgb(0 0 0)"
85
+ },
86
+ "#clear": {
87
+ inherits: true,
88
+ initialValue: "transparent"
89
+ },
90
+ "#border": {
91
+ inherits: true,
92
+ initialValue: "rgb(0 0 0)"
93
+ },
94
+ $gap: {
95
+ syntax: "<length>",
96
+ inherits: true,
97
+ initialValue: "4px"
98
+ },
99
+ $radius: {
100
+ syntax: "<length>",
101
+ inherits: true,
102
+ initialValue: "6px"
103
+ },
104
+ "$border-width": {
105
+ syntax: "<length>",
106
+ inherits: true,
107
+ initialValue: "1px"
108
+ },
109
+ "$outline-width": {
110
+ syntax: "<length>",
111
+ inherits: true,
112
+ initialValue: "3px"
113
+ },
114
+ $transition: {
115
+ syntax: "<time>",
116
+ inherits: true,
117
+ initialValue: "80ms"
118
+ },
119
+ "$sharp-radius": {
120
+ syntax: "<length>",
121
+ inherits: true,
122
+ initialValue: "0px"
123
+ },
124
+ "$bold-font-weight": {
125
+ syntax: "<number>",
126
+ inherits: true,
127
+ initialValue: "700"
128
+ },
129
+ "$font-sans-fallback": {
130
+ syntax: "*",
131
+ inherits: true,
132
+ initialValue: "system-ui, -apple-system, \"Segoe UI\", Roboto, Helvetica, Arial, \"Apple Color Emoji\", \"Segoe UI Emoji\", sans-serif"
133
+ },
134
+ "$font-mono-fallback": {
135
+ syntax: "*",
136
+ inherits: true,
137
+ initialValue: "ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, \"Liberation Mono\", \"Courier New\", monospace"
138
+ }
139
+ };
140
+ const GLOBAL_INJECTOR_KEY = "__TASTY_GLOBAL_INJECTOR__";
141
+ /**
142
+ * Detect if we're running in a test environment
143
+ */
144
+ function isTestEnvironment() {
145
+ if (typeof global !== "undefined") {
146
+ const g = global;
147
+ if (g.vi || g.jest || g.expect || g.describe || g.it) return true;
148
+ }
149
+ if (typeof window !== "undefined" && window.navigator?.userAgent?.includes("jsdom")) return true;
150
+ if (typeof globalThis !== "undefined") {
151
+ const gt = globalThis;
152
+ if (gt.vitest || gt.mocha) return true;
153
+ }
154
+ return false;
155
+ }
156
+ /**
157
+ * Create default configuration with optional test environment detection
158
+ */
159
+ function createDefaultConfig(isTest) {
160
+ return {
161
+ maxRulesPerSheet: 8192,
162
+ forceTextInjection: isTest ?? false,
163
+ devMode: isDevEnv()
164
+ };
165
+ }
166
+ /**
167
+ * Mark that styles have been generated (called by injector on first inject)
168
+ * This locks the configuration - no further changes allowed.
169
+ * Also injects internal and global properties.
170
+ */
171
+ function markStylesGenerated() {
172
+ if (stylesGenerated) return;
173
+ stylesGenerated = true;
174
+ const injector = getGlobalInjector();
175
+ for (const [token, definition] of Object.entries(getEffectiveProperties())) injector.property(token, definition);
176
+ if (globalFontFace && Object.keys(globalFontFace).length > 0) for (const [family, input] of Object.entries(globalFontFace)) {
177
+ const descriptors = Array.isArray(input) ? input : [input];
178
+ for (const desc of descriptors) injector.fontFace(family, desc);
179
+ }
180
+ if (globalCounterStyle && Object.keys(globalCounterStyle).length > 0) for (const [name, descriptors] of Object.entries(globalCounterStyle)) injector.counterStyle(name, descriptors);
181
+ if (globalConfigTokens && Object.keys(globalConfigTokens).length > 0) {
182
+ const tokenRules = renderStyles(globalConfigTokens, ":root");
183
+ if (tokenRules.length > 0) injector.injectGlobal(tokenRules);
184
+ }
185
+ if (globalBodyStyles && Object.keys(globalBodyStyles).length > 0) {
186
+ const bodyRules = renderStyles(globalBodyStyles, "body");
187
+ if (bodyRules.length > 0) injector.injectGlobal(bodyRules);
188
+ }
189
+ }
190
+ /**
191
+ * Check if styles have been generated (configuration is locked)
192
+ */
193
+ function hasStylesGenerated() {
194
+ return stylesGenerated;
195
+ }
196
+ let _hasGlobalKeyframes = false;
197
+ /**
198
+ * Check if any global keyframes are configured.
199
+ * Uses a pre-computed flag to avoid Object.keys() allocation on every call.
200
+ */
201
+ function hasGlobalKeyframes() {
202
+ return _hasGlobalKeyframes;
203
+ }
204
+ /**
205
+ * Get global keyframes configuration.
206
+ * Returns null if no keyframes configured (fast path for zero-overhead).
207
+ */
208
+ function getGlobalKeyframes() {
209
+ return globalKeyframes;
210
+ }
211
+ /**
212
+ * Set global keyframes (called from configure).
213
+ * Internal use only.
214
+ */
215
+ function setGlobalKeyframes(keyframes) {
216
+ if (stylesGenerated) {
217
+ warnOnce("keyframes-after-styles", "[Tasty] Cannot update keyframes after styles have been generated.\nThe new keyframes will be ignored.");
218
+ return;
219
+ }
220
+ globalKeyframes = keyframes;
221
+ _hasGlobalKeyframes = Object.keys(keyframes).length > 0;
222
+ }
223
+ /**
224
+ * Set global properties (called from configure).
225
+ * Internal use only.
226
+ */
227
+ function setGlobalProperties(properties) {
228
+ if (stylesGenerated) {
229
+ warnOnce("properties-after-styles", "[Tasty] Cannot update properties after styles have been generated.\nThe new properties will be ignored.");
230
+ return;
231
+ }
232
+ globalProperties = properties;
233
+ setOnGlobalThis(GTKEY_PROPERTIES, globalProperties);
234
+ }
235
+ /**
236
+ * Get the effective properties: DEFAULT_PROPERTIES merged with user-configured
237
+ * properties. User properties override defaults with matching keys.
238
+ * Reads from globalThis first for cross-module SSR support.
239
+ */
240
+ function getEffectiveProperties() {
241
+ const props = globalProperties ?? getFromGlobalThis(GTKEY_PROPERTIES);
242
+ if (!props) return DEFAULT_PROPERTIES;
243
+ return {
244
+ ...DEFAULT_PROPERTIES,
245
+ ...props
246
+ };
247
+ }
248
+ /**
249
+ * Get global font-face configuration.
250
+ * Returns null if no font faces configured.
251
+ * Reads from globalThis first for cross-module SSR support.
252
+ */
253
+ function getGlobalFontFace() {
254
+ return globalFontFace ?? getFromGlobalThis(GTKEY_FONT_FACE) ?? null;
255
+ }
256
+ /**
257
+ * Set global font faces (called from configure).
258
+ * Internal use only.
259
+ */
260
+ function setGlobalFontFace(fontFace) {
261
+ if (stylesGenerated) {
262
+ warnOnce("fontface-after-styles", "[Tasty] Cannot update fontFace after styles have been generated.\nThe new font faces will be ignored.");
263
+ return;
264
+ }
265
+ globalFontFace = fontFace;
266
+ setOnGlobalThis(GTKEY_FONT_FACE, globalFontFace);
267
+ }
268
+ /**
269
+ * Get global counter-style configuration.
270
+ * Returns null if no counter styles configured.
271
+ * Reads from globalThis first for cross-module SSR support.
272
+ */
273
+ function getGlobalCounterStyle() {
274
+ return globalCounterStyle ?? getFromGlobalThis(GTKEY_COUNTER_STYLE) ?? null;
275
+ }
276
+ /**
277
+ * Set global counter styles (called from configure).
278
+ * Internal use only.
279
+ */
280
+ function setGlobalCounterStyle(counterStyle) {
281
+ if (stylesGenerated) {
282
+ warnOnce("counterstyle-after-styles", "[Tasty] Cannot update counterStyle after styles have been generated.\nThe new counter styles will be ignored.");
283
+ return;
284
+ }
285
+ globalCounterStyle = counterStyle;
286
+ setOnGlobalThis(GTKEY_COUNTER_STYLE, globalCounterStyle);
287
+ }
288
+ /**
289
+ * Check if any global recipes are configured.
290
+ * Fast path: returns false if no recipes were ever set.
291
+ */
292
+ function hasGlobalRecipes() {
293
+ return globalRecipes !== null && Object.keys(globalRecipes).length > 0;
294
+ }
295
+ /**
296
+ * Get global recipes configuration.
297
+ * Returns null if no recipes configured (fast path for zero-overhead).
298
+ */
299
+ function getGlobalRecipes() {
300
+ return globalRecipes;
301
+ }
302
+ /**
303
+ * Set global recipes (called from configure).
304
+ * Internal use only.
305
+ */
306
+ function setGlobalRecipes(recipes) {
307
+ if (stylesGenerated) {
308
+ warnOnce("recipes-after-styles", "[Tasty] Cannot update recipes after styles have been generated.\nThe new recipes will be ignored.");
309
+ return;
310
+ }
311
+ if (devMode) for (const [name, recipeStyles] of Object.entries(recipes)) {
312
+ if (name === "none") warnOnce("recipe-reserved-none", "[Tasty] Recipe name \"none\" is reserved. It is used as a keyword meaning \"no base recipes\" (e.g. recipe: 'none / post-recipe'). Choose a different name for your recipe.");
313
+ for (const key of Object.keys(recipeStyles)) {
314
+ 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.`);
315
+ 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'.`);
316
+ }
317
+ }
318
+ globalRecipes = recipes;
319
+ }
320
+ /**
321
+ * Get global token styles for :root injection.
322
+ * Returns null if no tokens configured.
323
+ * Reads from globalThis first for cross-module SSR support.
324
+ */
325
+ function getGlobalConfigTokens() {
326
+ return globalConfigTokens ?? getFromGlobalThis(GTKEY_TOKENS) ?? null;
327
+ }
328
+ /**
329
+ * Set global token styles (called from configure).
330
+ * Internal use only.
331
+ */
332
+ function setGlobalConfigTokens(styles) {
333
+ if (stylesGenerated) {
334
+ warnOnce("tokens-after-styles", "[Tasty] Cannot update tokens after styles have been generated.\nThe new tokens will be ignored.");
335
+ return;
336
+ }
337
+ globalConfigTokens = globalConfigTokens ? {
338
+ ...globalConfigTokens,
339
+ ...styles
340
+ } : styles;
341
+ setOnGlobalThis(GTKEY_TOKENS, globalConfigTokens);
342
+ }
343
+ /**
344
+ * Get global body styles for injection.
345
+ * Returns null if no body styles configured.
346
+ * Reads from globalThis first for cross-module SSR support.
347
+ */
348
+ function getGlobalBodyStyles() {
349
+ return globalBodyStyles ?? getFromGlobalThis(GTKEY_BODY_STYLES) ?? null;
350
+ }
351
+ /**
352
+ * Set global body styles (called from configure).
353
+ * Internal use only.
354
+ */
355
+ function setGlobalBodyStyles(styles) {
356
+ if (stylesGenerated) {
357
+ warnOnce("bodyStyles-after-styles", "[Tasty] Cannot update bodyStyles after styles have been generated.\nThe new body styles will be ignored.");
358
+ return;
359
+ }
360
+ globalBodyStyles = globalBodyStyles ? {
361
+ ...globalBodyStyles,
362
+ ...styles
363
+ } : styles;
364
+ setOnGlobalThis(GTKEY_BODY_STYLES, globalBodyStyles);
365
+ }
366
+ /**
367
+ * Check if configuration is locked (styles have been generated)
368
+ */
369
+ function isConfigLocked() {
370
+ return stylesGenerated;
371
+ }
372
+ /**
373
+ * Configure the Tasty style system.
374
+ *
375
+ * Must be called BEFORE any styles are generated (before first render that uses tasty).
376
+ * After styles are generated, configuration is locked and calls to configure() will
377
+ * emit a warning and be ignored.
378
+ *
379
+ * @example
380
+ * ```ts
381
+ * import { configure } from '@tenphi/tasty';
382
+ *
383
+ * // Configure before app renders
384
+ * configure({
385
+ * nonce: 'abc123',
386
+ * states: {
387
+ * '@mobile': '@media(w < 768px)',
388
+ * '@dark': '@root(theme=dark)',
389
+ * },
390
+ * });
391
+ * ```
392
+ */
393
+ function configure(config = {}) {
394
+ if (stylesGenerated) {
395
+ 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.");
396
+ return;
397
+ }
398
+ let mergedStates = {};
399
+ let mergedUnits = {};
400
+ let mergedFuncs = {};
401
+ let mergedHandlers = {};
402
+ let mergedReplaceTokens = {};
403
+ let mergedConfigTokens = {};
404
+ let mergedRecipes = {};
405
+ let mergedPresets = {};
406
+ let mergedBodyStyles;
407
+ if (config.plugins) for (const plugin of config.plugins) {
408
+ if (plugin.states) mergedStates = {
409
+ ...mergedStates,
410
+ ...plugin.states
411
+ };
412
+ if (plugin.units) mergedUnits = {
413
+ ...mergedUnits,
414
+ ...plugin.units
415
+ };
416
+ if (plugin.funcs) mergedFuncs = {
417
+ ...mergedFuncs,
418
+ ...plugin.funcs
419
+ };
420
+ if (plugin.handlers) mergedHandlers = {
421
+ ...mergedHandlers,
422
+ ...plugin.handlers
423
+ };
424
+ if (plugin.replaceTokens) mergedReplaceTokens = {
425
+ ...mergedReplaceTokens,
426
+ ...plugin.replaceTokens
427
+ };
428
+ if (plugin.tokens) mergedConfigTokens = {
429
+ ...mergedConfigTokens,
430
+ ...plugin.tokens
431
+ };
432
+ if (plugin.recipes) mergedRecipes = {
433
+ ...mergedRecipes,
434
+ ...plugin.recipes
435
+ };
436
+ if (plugin.presets) mergedPresets = {
437
+ ...mergedPresets,
438
+ ...plugin.presets
439
+ };
440
+ if (plugin.bodyStyles) mergedBodyStyles = mergedBodyStyles ? {
441
+ ...mergedBodyStyles,
442
+ ...plugin.bodyStyles
443
+ } : plugin.bodyStyles;
444
+ }
445
+ if (config.states) mergedStates = {
446
+ ...mergedStates,
447
+ ...config.states
448
+ };
449
+ if (config.units) mergedUnits = {
450
+ ...mergedUnits,
451
+ ...config.units
452
+ };
453
+ if (config.funcs) mergedFuncs = {
454
+ ...mergedFuncs,
455
+ ...config.funcs
456
+ };
457
+ if (config.handlers) mergedHandlers = {
458
+ ...mergedHandlers,
459
+ ...config.handlers
460
+ };
461
+ if (config.replaceTokens) mergedReplaceTokens = {
462
+ ...mergedReplaceTokens,
463
+ ...config.replaceTokens
464
+ };
465
+ if (config.presets) mergedPresets = {
466
+ ...mergedPresets,
467
+ ...config.presets
468
+ };
469
+ if (Object.keys(mergedPresets).length > 0) mergedConfigTokens = {
470
+ ...generateTypographyTokens(mergedPresets),
471
+ ...mergedConfigTokens
472
+ };
473
+ if (config.tokens) mergedConfigTokens = {
474
+ ...mergedConfigTokens,
475
+ ...config.tokens
476
+ };
477
+ if (config.recipes) mergedRecipes = {
478
+ ...mergedRecipes,
479
+ ...config.recipes
480
+ };
481
+ if (config.bodyStyles) mergedBodyStyles = mergedBodyStyles ? {
482
+ ...mergedBodyStyles,
483
+ ...config.bodyStyles
484
+ } : config.bodyStyles;
485
+ if (devMode) {
486
+ const tokenKeys = new Set(Object.keys(mergedConfigTokens));
487
+ for (const key of Object.keys(mergedReplaceTokens)) if (tokenKeys.has(key)) warnOnce(`token-conflict-${key}`, `[Tasty] Token "${key}" is defined in both \`tokens\` and \`replaceTokens\`. \`replaceTokens\` performs parse-time substitution, so the \`tokens\` CSS custom property will be injected but never used by Tasty styles. Remove it from one of the two.`);
488
+ }
489
+ if (config.colorSpace) {
490
+ setColorSpace(config.colorSpace);
491
+ getGlobalParser().clearCache();
492
+ }
493
+ if (Object.keys(mergedStates).length > 0) setGlobalPredefinedStates(mergedStates);
494
+ const parser = getGlobalParser();
495
+ if (config.parserCacheSize !== void 0) parser.updateOptions({ cacheSize: config.parserCacheSize });
496
+ if (Object.keys(mergedUnits).length > 0) {
497
+ const currentUnits = parser.getUnits() ?? CUSTOM_UNITS;
498
+ parser.setUnits({
499
+ ...currentUnits,
500
+ ...mergedUnits
501
+ });
502
+ }
503
+ if (Object.keys(mergedFuncs).length > 0) {
504
+ const currentFuncs = getGlobalFuncs();
505
+ const finalFuncs = {
506
+ ...currentFuncs,
507
+ ...mergedFuncs
508
+ };
509
+ parser.setFuncs(finalFuncs);
510
+ Object.assign(currentFuncs, mergedFuncs);
511
+ }
512
+ if (config.keyframes) setGlobalKeyframes(config.keyframes);
513
+ if (config.properties) setGlobalProperties(config.properties);
514
+ if (config.fontFace) setGlobalFontFace(config.fontFace);
515
+ if (config.counterStyle) setGlobalCounterStyle(config.counterStyle);
516
+ if (Object.keys(mergedHandlers).length > 0) for (const [name, definition] of Object.entries(mergedHandlers)) registerHandler(normalizeHandlerDefinition(name, definition));
517
+ if (Object.keys(mergedReplaceTokens).length > 0) {
518
+ const processedTokens = {};
519
+ for (const [key, value] of Object.entries(mergedReplaceTokens)) if (key.startsWith("#")) {
520
+ const normalized = normalizeColorTokenValue(value);
521
+ if (normalized === null) continue;
522
+ processedTokens[key] = String(normalized);
523
+ } else if (value === false) continue;
524
+ else processedTokens[key] = String(value);
525
+ setGlobalPredefinedTokens(processedTokens);
526
+ }
527
+ if (Object.keys(mergedConfigTokens).length > 0) setGlobalConfigTokens(mergedConfigTokens);
528
+ if (Object.keys(mergedRecipes).length > 0) setGlobalRecipes(mergedRecipes);
529
+ if (mergedBodyStyles && Object.keys(mergedBodyStyles).length > 0) setGlobalBodyStyles(mergedBodyStyles);
530
+ const { states: _states, parserCacheSize: _parserCacheSize, units: _units, funcs: _funcs, plugins: _plugins, keyframes: _keyframes, properties: _properties, fontFace: _fontFace, counterStyle: _counterStyle, handlers: _handlers, tokens: _tokens, replaceTokens: _replaceTokens, recipes: _recipes, colorSpace: _colorSpace, presets: _presets, bodyStyles: _bodyStyles, ...injectorConfig } = config;
531
+ const fullConfig = {
532
+ ...createDefaultConfig(),
533
+ ...currentConfig,
534
+ ...injectorConfig
535
+ };
536
+ currentConfig = fullConfig;
537
+ const storage = typeof window !== "undefined" ? window : globalThis;
538
+ storage[GLOBAL_INJECTOR_KEY] = new StyleInjector(fullConfig);
539
+ }
540
+ /**
541
+ * Get the current configuration.
542
+ * If not configured, returns default configuration.
543
+ */
544
+ function getConfig() {
545
+ if (!currentConfig) currentConfig = createDefaultConfig(isTestEnvironment());
546
+ return currentConfig;
547
+ }
548
+ /**
549
+ * Get the global injector instance.
550
+ * Auto-configures with defaults if not already configured.
551
+ */
552
+ function getGlobalInjector() {
553
+ const storage = typeof window !== "undefined" ? window : globalThis;
554
+ if (!storage[GLOBAL_INJECTOR_KEY]) configure();
555
+ return storage[GLOBAL_INJECTOR_KEY];
556
+ }
557
+ /**
558
+ * Reset configuration (for testing only).
559
+ * Clears the global injector and allows reconfiguration.
560
+ */
561
+ function resetConfig() {
562
+ stylesGenerated = false;
563
+ currentConfig = null;
564
+ globalKeyframes = null;
565
+ _hasGlobalKeyframes = false;
566
+ globalProperties = null;
567
+ globalFontFace = null;
568
+ globalCounterStyle = null;
569
+ globalRecipes = null;
570
+ globalConfigTokens = null;
571
+ globalBodyStyles = null;
572
+ clearGlobalThisConfig();
573
+ resetGlobalPredefinedTokens();
574
+ resetHandlers();
575
+ resetColorSpace();
576
+ clearPipelineCache();
577
+ emittedWarnings.clear();
578
+ const storage = typeof window !== "undefined" ? window : globalThis;
579
+ delete storage[GLOBAL_INJECTOR_KEY];
580
+ }
581
+ //#endregion
582
+ export { configure, getConfig, getEffectiveProperties, getGlobalBodyStyles, getGlobalConfigTokens, getGlobalCounterStyle, getGlobalFontFace, getGlobalInjector, getGlobalKeyframes, getGlobalRecipes, hasGlobalKeyframes, hasGlobalRecipes, hasStylesGenerated, isConfigLocked, isTestEnvironment, markStylesGenerated, resetConfig };
583
+
584
+ //# sourceMappingURL=config.js.map