@tenphi/tasty 0.0.0-snapshot.b2ad8a7 → 0.0.0-snapshot.b317d64

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 (119) hide show
  1. package/README.md +6 -6
  2. package/dist/babel-types-C_7kRP38.d.ts +18 -0
  3. package/dist/chunks/async-storage-CG5HnUT5.js +20 -0
  4. package/dist/chunks/async-storage-CG5HnUT5.js.map +1 -0
  5. package/dist/chunks/build-config-BDLYGmKn.js +60 -0
  6. package/dist/chunks/build-config-BDLYGmKn.js.map +1 -0
  7. package/dist/{collector-DCI2yzwx.js → chunks/collector-DqcB0UUT.js} +25 -119
  8. package/dist/chunks/collector-DqcB0UUT.js.map +1 -0
  9. package/dist/chunks/config-engine-CGIMO2PV.js +272 -0
  10. package/dist/chunks/config-engine-CGIMO2PV.js.map +1 -0
  11. package/dist/chunks/css-definitions-BibU6ZnP.js +904 -0
  12. package/dist/chunks/css-definitions-BibU6ZnP.js.map +1 -0
  13. package/dist/chunks/css-resources-P7IBUUZs.js +142 -0
  14. package/dist/chunks/css-resources-P7IBUUZs.js.map +1 -0
  15. package/dist/chunks/debug-Dy36S1sU.js +502 -0
  16. package/dist/chunks/debug-Dy36S1sU.js.map +1 -0
  17. package/dist/chunks/dsl-DRhFWQzo.js +1378 -0
  18. package/dist/chunks/dsl-DRhFWQzo.js.map +1 -0
  19. package/dist/chunks/hydration-TRcz5vnk.js +41 -0
  20. package/dist/chunks/hydration-TRcz5vnk.js.map +1 -0
  21. package/dist/chunks/react-runtime-BljxMd6C.js +582 -0
  22. package/dist/chunks/react-runtime-BljxMd6C.js.map +1 -0
  23. package/dist/chunks/runtime-engine-CPYI2bA8.js +2415 -0
  24. package/dist/chunks/runtime-engine-CPYI2bA8.js.map +1 -0
  25. package/dist/chunks/runtime-state-C0u1jp-Q.js +141 -0
  26. package/dist/chunks/runtime-state-C0u1jp-Q.js.map +1 -0
  27. package/dist/{merge-styles-CzVxdtav.js → chunks/shared-utils-y-HjvPN4.js} +60 -55
  28. package/dist/chunks/shared-utils-y-HjvPN4.js.map +1 -0
  29. package/dist/chunks/style-engine-D35rvcdB.js +5420 -0
  30. package/dist/chunks/style-engine-D35rvcdB.js.map +1 -0
  31. package/dist/{css-writer-Cq0fg5v8.js → chunks/zero-engine-b--JCZad.js} +51 -146
  32. package/dist/chunks/zero-engine-b--JCZad.js.map +1 -0
  33. package/dist/{collector-CQDeU7WS.d.ts → collector-w4mBj5gd.d.ts} +23 -4
  34. package/dist/{config-CwRr6-fG.d.ts → config-CrZOfNJ5.d.ts} +110 -96
  35. package/dist/core/index.d.ts +5 -5
  36. package/dist/core/index.js +9 -6
  37. package/dist/{index-C0W21Qcb.d.ts → index-CYJtAI9a.d.ts} +243 -281
  38. package/dist/index.d.ts +5 -5
  39. package/dist/index.js +11 -998
  40. package/dist/{merge-styles-Bpwfy1CS.d.ts → merge-styles-VXwJ0Frr.d.ts} +2 -3
  41. package/dist/ssr/astro-client.d.ts +1 -1
  42. package/dist/ssr/astro-client.js +1 -14
  43. package/dist/ssr/astro-client.js.map +1 -1
  44. package/dist/ssr/astro-middleware-extract-static.d.ts +10 -0
  45. package/dist/ssr/astro-middleware-extract-static.js +9 -0
  46. package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
  47. package/dist/ssr/astro-middleware-extract.d.ts +10 -0
  48. package/dist/ssr/astro-middleware-extract.js +9 -0
  49. package/dist/ssr/astro-middleware-extract.js.map +1 -0
  50. package/dist/ssr/astro-middleware-static.d.ts +3 -2
  51. package/dist/ssr/astro-middleware-static.js +0 -11
  52. package/dist/ssr/astro-middleware-static.js.map +1 -1
  53. package/dist/ssr/astro-middleware.d.ts +3 -2
  54. package/dist/ssr/astro-middleware.js +0 -12
  55. package/dist/ssr/astro-middleware.js.map +1 -1
  56. package/dist/ssr/astro.d.ts +40 -6
  57. package/dist/ssr/astro.js +157 -93
  58. package/dist/ssr/astro.js.map +1 -1
  59. package/dist/ssr/index.d.ts +10 -11
  60. package/dist/ssr/index.js +4 -4
  61. package/dist/ssr/index.js.map +1 -1
  62. package/dist/ssr/next-config.d.ts +64 -0
  63. package/dist/ssr/next-config.js +134 -0
  64. package/dist/ssr/next-config.js.map +1 -0
  65. package/dist/ssr/next.d.ts +9 -8
  66. package/dist/ssr/next.js +29 -43
  67. package/dist/ssr/next.js.map +1 -1
  68. package/dist/static/index.d.ts +8 -9
  69. package/dist/static/index.js +4 -22
  70. package/dist/static/index.js.map +1 -1
  71. package/dist/static/inject.d.ts +1 -2
  72. package/dist/{index-DpykQKO8.d.ts → types-JEY8PVYP.d.ts} +986 -972
  73. package/dist/zero/babel.d.ts +67 -2
  74. package/dist/zero/babel.js +57 -131
  75. package/dist/zero/babel.js.map +1 -1
  76. package/dist/zero/index.d.ts +44 -8
  77. package/dist/zero/index.js +24 -2
  78. package/dist/zero/index.js.map +1 -0
  79. package/dist/zero/next.d.ts +4 -5
  80. package/dist/zero/next.js +0 -31
  81. package/dist/zero/next.js.map +1 -1
  82. package/docs/ai-agents.md +31 -5
  83. package/docs/configuration.md +18 -2
  84. package/docs/debug.md +15 -5
  85. package/docs/dsl.md +56 -8
  86. package/docs/getting-started.md +13 -11
  87. package/docs/injector.md +21 -7
  88. package/docs/methodology.md +5 -5
  89. package/docs/pipeline.md +34 -10
  90. package/docs/plugins.md +1 -1
  91. package/docs/react-api.md +9 -0
  92. package/docs/runtime-benchmarks.md +282 -110
  93. package/docs/ssr.md +179 -20
  94. package/docs/styles.md +89 -19
  95. package/docs/tasty-static.md +34 -1
  96. package/package.json +101 -36
  97. package/dist/async-storage-DKK-wTD4.js +0 -44
  98. package/dist/async-storage-DKK-wTD4.js.map +0 -1
  99. package/dist/babel-B_P8t-f0.d.ts +0 -83
  100. package/dist/collector-DCI2yzwx.js.map +0 -1
  101. package/dist/config-B97n_EIv.js +0 -12612
  102. package/dist/config-B97n_EIv.js.map +0 -1
  103. package/dist/context-CA8YKeMn.js +0 -24
  104. package/dist/context-CA8YKeMn.js.map +0 -1
  105. package/dist/core-DWrUWxog.js +0 -1645
  106. package/dist/core-DWrUWxog.js.map +0 -1
  107. package/dist/css-writer-Cq0fg5v8.js.map +0 -1
  108. package/dist/format-global-rules-DklyaXv-.js +0 -22
  109. package/dist/format-global-rules-DklyaXv-.js.map +0 -1
  110. package/dist/format-rules-Wb7dJOoL.js +0 -130
  111. package/dist/format-rules-Wb7dJOoL.js.map +0 -1
  112. package/dist/hydrate-gFTLBDK9.js +0 -37
  113. package/dist/hydrate-gFTLBDK9.js.map +0 -1
  114. package/dist/index.js.map +0 -1
  115. package/dist/merge-styles-CzVxdtav.js.map +0 -1
  116. package/dist/renderChunk-COXABoQz.js +0 -290
  117. package/dist/renderChunk-COXABoQz.js.map +0 -1
  118. package/dist/resolve-recipes-BnrUEjWV.js +0 -144
  119. package/dist/resolve-recipes-BnrUEjWV.js.map +0 -1
@@ -1,2 +1,67 @@
1
- import { n as _default, r as TastyZeroConfig, t as TastyZeroBabelOptions } from "../babel-B_P8t-f0.js";
2
- export { TastyZeroBabelOptions, type TastyZeroConfig, _default as default };
1
+ import { t as TastyZeroConfig } from "../babel-types-C_7kRP38.js";
2
+ import { PluginPass } from "@babel/core";
3
+ //#region src/zero/babel.d.ts
4
+ /**
5
+ * Options for the `@tenphi/tasty/babel-plugin` Babel plugin.
6
+ */
7
+ export interface TastyZeroBabelOptions {
8
+ /** Output path for generated CSS (default: 'tasty.css') */
9
+ output?: string;
10
+ /**
11
+ * Tasty configuration for build-time processing.
12
+ * Can be a static object or a factory function that returns fresh config.
13
+ * A factory is called on each plugin invocation, enabling hot reload
14
+ * of config values that depend on external files (e.g. theme tokens).
15
+ */
16
+ config?: TastyZeroConfig | (() => TastyZeroConfig);
17
+ /**
18
+ * Absolute path to a TypeScript/JavaScript module that default-exports
19
+ * a `TastyZeroConfig` object. The module is loaded via jiti on each
20
+ * plugin invocation, enabling hot reload when the file changes.
21
+ *
22
+ * This option is JSON-serializable and is the primary way Turbopack
23
+ * passes config to the Babel plugin (since Turbopack loader options
24
+ * must be plain primitives/objects/arrays).
25
+ *
26
+ * When both `config` and `configFile` are set, `config` takes precedence.
27
+ *
28
+ * @example '/absolute/path/to/tasty-zero.config.ts'
29
+ */
30
+ configFile?: string;
31
+ /**
32
+ * Absolute file paths whose content affects the generated CSS.
33
+ * When any of these files change, babel-loader invalidates its cache
34
+ * and re-runs the plugin with fresh config values.
35
+ *
36
+ * Typically includes theme files that define Glaze palettes or token values.
37
+ * Paths must be absolute (resolved by the Next.js wrapper).
38
+ */
39
+ configDeps?: string[];
40
+ /**
41
+ * Automatically replace `@tenphi/tasty/static` imports with an import
42
+ * of the generated CSS file. This eliminates the need for users to
43
+ * manually import the CSS in their app entry point.
44
+ *
45
+ * @default true
46
+ */
47
+ injectImport?: boolean;
48
+ /**
49
+ * Output mode for extracted CSS.
50
+ *
51
+ * - `'file'` (default): CSS is written to a single output file and
52
+ * the `@tenphi/tasty/static` import is rewritten to import that file.
53
+ * - `'inject'`: CSS is embedded inline in the JS output and injected
54
+ * at runtime via a tiny injector from `@tenphi/tasty/static/inject`.
55
+ * No CSS file is written. Each `tastyStatic` call becomes
56
+ * self-contained. Best for reusable components and extensions.
57
+ *
58
+ * When `mode` is `'inject'`, `output` and `injectImport` are ignored.
59
+ *
60
+ * @default 'file'
61
+ */
62
+ mode?: 'file' | 'inject';
63
+ }
64
+ declare const _default: (api: object, options: TastyZeroBabelOptions | null | undefined, dirname: string) => import("@babel/core").PluginObj<PluginPass>;
65
+ //#endregion
66
+ export { type TastyZeroConfig, _default as default };
67
+ //# sourceMappingURL=babel.d.ts.map
@@ -1,7 +1,8 @@
1
- import { d as getGlobalStyles, i as getGlobalConfigTokens, s as getGlobalFunctions, t as configure, x as resetConfig } from "../config-B97n_EIv.js";
2
- import { t as mergeStyles } from "../merge-styles-CzVxdtav.js";
3
- import { t as resolveRecipes } from "../resolve-recipes-BnrUEjWV.js";
4
- import { a as extractFunctionsFromStyles, c as extractStylesForSelector, i as extractFontFaceFromStyles, l as extractStylesWithChunks, o as extractKeyframesFromStyles, r as extractCounterStyleFromStyles, s as extractPropertiesFromStyles, t as CSSWriter, u as setExtractorNamePrefix } from "../css-writer-Cq0fg5v8.js";
1
+ import { t as mergeStyles } from "../chunks/shared-utils-y-HjvPN4.js";
2
+ import "../chunks/css-definitions-BibU6ZnP.js";
3
+ import { t as resolveRecipesWith } from "../chunks/config-engine-CGIMO2PV.js";
4
+ import { a as resetZeroConfig, i as reapplyZeroConfig, n as functionsForExtraction, t as configureZero } from "../chunks/build-config-BDLYGmKn.js";
5
+ import { a as extractFontFaceFromStyles, c as extractPropertiesFromStyles, f as renderSelectorCSS, i as extractCounterStyleFromStyles, l as extractSelectorCSS, m as setExtractorNamePrefix, o as extractFunctionsFromStyles, p as replaceAnimationNamesInCSS, r as extractChunks, s as extractKeyframesFromStyles, t as CSSWriter } from "../chunks/zero-engine-b--JCZad.js";
5
6
  import * as fs from "fs";
6
7
  import * as path from "path";
7
8
  import { declare } from "@babel/helper-plugin-utils";
@@ -17,24 +18,6 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
17
18
  const writerCache = /* @__PURE__ */ new Map();
18
19
  //#endregion
19
20
  //#region src/zero/babel.ts
20
- /**
21
- * Babel plugin for zero-runtime tasty static site generation.
22
- *
23
- * Transforms:
24
- * - `tastyStatic(styles)` → StaticStyle object { className, styles, toString() }
25
- * - `tastyStatic(base, styles)` → StaticStyle object with merged styles
26
- * - `tastyStatic(selector, styles)` → removed entirely
27
- *
28
- * Usage:
29
- * ```javascript
30
- * // babel.config.js
31
- * module.exports = {
32
- * plugins: [
33
- * ['@tenphi/tasty/babel-plugin', { output: 'public/tasty.css' }]
34
- * ]
35
- * };
36
- * ```
37
- */
38
21
  function mtime(filePath) {
39
22
  try {
40
23
  return fs.statSync(filePath).mtimeMs;
@@ -87,45 +70,43 @@ var babel_default = declare((api, options) => {
87
70
  resolvedConfig = loaded && typeof loaded === "object" && "default" in loaded ? loaded.default : loaded;
88
71
  } else resolvedConfig = {};
89
72
  const devMode = resolvedConfig.devMode ?? false;
90
- if (cached) resetConfig();
73
+ resetZeroConfig();
91
74
  const finalConfig = {
92
75
  namePrefix: "ts",
93
76
  ...resolvedConfig
94
77
  };
95
- configure(finalConfig);
78
+ const config = configureZero(finalConfig);
96
79
  setExtractorNamePrefix(finalConfig.namePrefix ?? "ts");
97
80
  const newWriter = new CSSWriter(outputPath, { devMode });
98
81
  if (mode !== "inject") {
99
- const tokenCSS = extractCSSFromStyles(":root", getGlobalConfigTokens());
82
+ const tokenCSS = extractCSSFromStyles(":root", config.normalized.tokens);
100
83
  if (tokenCSS) newWriter.add(":root:tokens", tokenCSS);
101
- const globalStyles = getGlobalStyles();
102
- if (globalStyles) for (const [selector, styles] of Object.entries(globalStyles)) {
103
- const css = extractCSSFromStyles(selector, styles);
104
- if (css) newWriter.add(`global:${selector}`, css);
105
- }
84
+ for (const [selector, styles] of Object.entries(config.normalized.globalStyles)) writeGlobalStyles(newWriter, selector, styles, config.normalized.keyframes);
106
85
  }
107
86
  writerCache.set(resolvedOutputPath, {
108
87
  writer: newWriter,
109
88
  configKey,
110
89
  registry: {},
111
- config: finalConfig
90
+ config
112
91
  });
113
92
  }
114
93
  const entry = writerCache.get(resolvedOutputPath);
94
+ entry.config = reapplyZeroConfig(entry.config);
115
95
  const cssWriter = entry.writer;
116
96
  const globalRegistry = entry.registry;
117
97
  const config = entry.config;
118
- const devMode = config.devMode ?? false;
119
- setExtractorNamePrefix(config.namePrefix ?? "ts");
98
+ const sourceConfig = config.source;
99
+ const devMode = sourceConfig.devMode ?? false;
100
+ setExtractorNamePrefix(sourceConfig.namePrefix ?? "ts");
120
101
  let tokenCSS;
121
102
  let globalStylesCSS;
122
103
  if (mode === "inject") {
123
- tokenCSS = extractCSSFromStyles(":root", getGlobalConfigTokens());
124
- const gs = getGlobalStyles();
125
- if (gs) {
104
+ tokenCSS = extractCSSFromStyles(":root", config.normalized.tokens);
105
+ const gs = config.normalized.globalStyles;
106
+ if (Object.keys(gs).length > 0) {
126
107
  globalStylesCSS = /* @__PURE__ */ new Map();
127
108
  for (const [selector, styles] of Object.entries(gs)) {
128
- const css = extractCSSFromStyles(selector, styles);
109
+ const css = extractCSSFromStyles(selector, styles, config.normalized.keyframes);
129
110
  if (css) globalStylesCSS.set(selector, css);
130
111
  }
131
112
  if (globalStylesCSS.size === 0) globalStylesCSS = void 0;
@@ -134,6 +115,8 @@ var babel_default = declare((api, options) => {
134
115
  return {
135
116
  name: "tasty-zero",
136
117
  pre() {
118
+ entry.config = reapplyZeroConfig(entry.config);
119
+ setExtractorNamePrefix(sourceConfig.namePrefix ?? "ts");
137
120
  this.staticStyleRegistry = {};
138
121
  this._fileAddedCSS = false;
139
122
  if (devMode && this.filename) this.sourceFile = this.filename.split("/").pop() || this.filename;
@@ -141,16 +124,18 @@ var babel_default = declare((api, options) => {
141
124
  visitor: {
142
125
  ImportDeclaration(nodePath, state) {
143
126
  const source = nodePath.node.source.value;
144
- if (source === "@tenphi/tasty/static" || source.endsWith("/tasty/static")) if (mode === "inject") nodePath.replaceWith(t.importDeclaration([t.importSpecifier(t.identifier("_$i"), t.identifier("injectCSS"))], t.stringLiteral("@tenphi/tasty/static/inject")));
145
- else if (injectImport) {
146
- let importPath = resolvedOutputPath;
147
- if (state.filename) {
148
- const sourceDir = path.dirname(state.filename);
149
- importPath = path.relative(sourceDir, resolvedOutputPath);
150
- if (!importPath.startsWith(".")) importPath = "./" + importPath;
151
- }
152
- nodePath.replaceWith(t.importDeclaration([], t.stringLiteral(importPath)));
153
- } else nodePath.remove();
127
+ if (source === "@tenphi/tasty/static" || source.endsWith("/tasty/static")) {
128
+ if (mode === "inject") nodePath.replaceWith(t.importDeclaration([t.importSpecifier(t.identifier("_$i"), t.identifier("injectCSS"))], t.stringLiteral("@tenphi/tasty/static/inject")));
129
+ else if (injectImport) {
130
+ let importPath = resolvedOutputPath;
131
+ if (state.filename) {
132
+ const sourceDir = path.dirname(state.filename);
133
+ importPath = path.relative(sourceDir, resolvedOutputPath);
134
+ if (!importPath.startsWith(".")) importPath = "./" + importPath;
135
+ }
136
+ nodePath.replaceWith(t.importDeclaration([], t.stringLiteral(importPath)));
137
+ } else nodePath.remove();
138
+ }
154
139
  },
155
140
  CallExpression(path, state) {
156
141
  const callee = path.node.callee;
@@ -159,9 +144,9 @@ var babel_default = declare((api, options) => {
159
144
  const args = path.node.arguments;
160
145
  if (args.length === 0) throw path.buildCodeFrameError("tastyStatic() requires at least one argument");
161
146
  const firstArg = args[0];
162
- if (t.isStringLiteral(firstArg)) handleSelectorMode(path, args, cssWriter, mode, state.sourceFile, config.keyframes, config.autoPropertyTypes, config.fontFaces, config.counterStyles, getGlobalFunctions() ?? void 0);
163
- else if (t.isObjectExpression(firstArg)) handleStylesMode(path, args, cssWriter, state, globalRegistry, mode, config.keyframes, config.autoPropertyTypes, config.fontFaces, config.counterStyles, getGlobalFunctions() ?? void 0);
164
- else if (t.isIdentifier(firstArg)) handleExtensionMode(path, args, cssWriter, state, globalRegistry, mode, config.keyframes, config.autoPropertyTypes, config.fontFaces, config.counterStyles, getGlobalFunctions() ?? void 0);
147
+ if (t.isStringLiteral(firstArg)) handleSelectorMode(path, args, cssWriter, mode, state.sourceFile, config.normalized.keyframes, sourceConfig.autoPropertyTypes, config.normalized.fontFaces, config.normalized.counterStyles, functionsForExtraction(config), config.normalized.recipes);
148
+ else if (t.isObjectExpression(firstArg)) handleStylesMode(path, args, cssWriter, state, globalRegistry, mode, config.normalized.keyframes, sourceConfig.autoPropertyTypes, config.normalized.fontFaces, config.normalized.counterStyles, functionsForExtraction(config), config.normalized.recipes);
149
+ else if (t.isIdentifier(firstArg)) handleExtensionMode(path, args, cssWriter, state, globalRegistry, mode, config.normalized.keyframes, sourceConfig.autoPropertyTypes, config.normalized.fontFaces, config.normalized.counterStyles, functionsForExtraction(config), config.normalized.recipes);
165
150
  else throw path.buildCodeFrameError("tastyStatic() first argument must be an object (styles), identifier (base StaticStyle), or string (selector)");
166
151
  },
167
152
  VariableDeclarator(path, state) {
@@ -207,41 +192,30 @@ var babel_default = declare((api, options) => {
207
192
  }
208
193
  };
209
194
  });
210
- /**
211
- * Check if an object expression looks like a StaticStyle object
212
- */
213
195
  function isStaticStyleObject(node) {
214
196
  const hasClassName = node.properties.some((p) => t.isObjectProperty(p) && t.isIdentifier(p.key, { name: "className" }));
215
197
  const hasStyles = node.properties.some((p) => t.isObjectProperty(p) && t.isIdentifier(p.key, { name: "styles" }));
216
198
  return hasClassName && hasStyles;
217
199
  }
218
- /**
219
- * Extract styles object from a StaticStyle object expression
220
- */
221
200
  function extractStylesFromStaticStyleObject(node, path) {
222
201
  for (const prop of node.properties) if (t.isObjectProperty(prop) && t.isIdentifier(prop.key, { name: "styles" }) && t.isObjectExpression(prop.value)) return evaluateObjectExpression(prop.value, path);
223
202
  return null;
224
203
  }
225
- /**
226
- * Extract className from a StaticStyle object expression
227
- */
228
204
  function extractClassNameFromStaticStyleObject(node) {
229
205
  for (const prop of node.properties) if (t.isObjectProperty(prop) && t.isIdentifier(prop.key, { name: "className" }) && t.isStringLiteral(prop.value)) return prop.value.value;
230
206
  return null;
231
207
  }
232
- /**
233
- * Handle tastyStatic(styles) - returns StaticStyle object
234
- */
235
- function handleStylesMode(path, args, cssWriter, state, globalRegistry, mode, globalKeyframes, autoPropertyTypes, globalFontFace, globalCounterStyle, globalFunction) {
208
+ function handleStylesMode(path, args, cssWriter, state, globalRegistry, mode, globalKeyframes, autoPropertyTypes, globalFontFace, globalCounterStyle, globalFunction, globalRecipes) {
236
209
  const stylesArg = args[0];
237
210
  if (!t.isObjectExpression(stylesArg)) throw path.buildCodeFrameError("tastyStatic(styles) argument must be a static object literal");
238
- const styles = resolveRecipes(evaluateObjectExpression(stylesArg, path));
211
+ const rawStyles = evaluateObjectExpression(stylesArg, path);
212
+ const styles = resolveRecipesWith(rawStyles, globalRecipes ?? null);
239
213
  const { keyframes, nameMap } = extractKeyframesFromStyles(styles, globalKeyframes);
240
214
  const properties = extractPropertiesFromStyles(styles, { autoPropertyTypes });
241
215
  const fontFaces = extractFontFaceFromStyles(styles, globalFontFace);
242
216
  const counterStyles = extractCounterStyleFromStyles(styles, globalCounterStyle);
243
217
  const functions = extractFunctionsFromStyles(styles, globalFunction);
244
- const chunks = extractStylesWithChunks(styles);
218
+ const chunks = extractChunks(styles);
245
219
  const className = chunks.length > 0 ? chunks.map((c) => c.className).join(" ") : "";
246
220
  const staticStyleObject = createStaticStyleAST(className, styles);
247
221
  if (mode === "inject") {
@@ -253,10 +227,7 @@ function handleStylesMode(path, args, cssWriter, state, globalRegistry, mode, gl
253
227
  }
254
228
  registerIfVariableDeclaration(path, className, styles, state, globalRegistry);
255
229
  }
256
- /**
257
- * Handle tastyStatic(base, styles) - extends base with additional styles
258
- */
259
- function handleExtensionMode(path, args, cssWriter, state, globalRegistry, mode, globalKeyframes, autoPropertyTypes, globalFontFace, globalCounterStyle, globalFunction) {
230
+ function handleExtensionMode(path, args, cssWriter, state, globalRegistry, mode, globalKeyframes, autoPropertyTypes, globalFontFace, globalCounterStyle, globalFunction, globalRecipes) {
260
231
  if (args.length < 2) throw path.buildCodeFrameError("tastyStatic(base, styles) requires two arguments");
261
232
  const baseArg = args[0];
262
233
  const stylesArg = args[1];
@@ -266,13 +237,13 @@ function handleExtensionMode(path, args, cssWriter, state, globalRegistry, mode,
266
237
  const baseEntry = state.staticStyleRegistry[baseName] || globalRegistry[baseName];
267
238
  if (!baseEntry) throw path.buildCodeFrameError(`Cannot find base StaticStyle '${baseName}'. Make sure it is defined before being extended.`);
268
239
  const overrideStyles = evaluateObjectExpression(stylesArg, path);
269
- const mergedStyles = resolveRecipes(mergeStyles(baseEntry.styles, overrideStyles));
240
+ const mergedStyles = resolveRecipesWith(mergeStyles(baseEntry.styles, overrideStyles), globalRecipes ?? null);
270
241
  const { keyframes, nameMap } = extractKeyframesFromStyles(mergedStyles, globalKeyframes);
271
242
  const properties = extractPropertiesFromStyles(mergedStyles, { autoPropertyTypes });
272
243
  const fontFaces = extractFontFaceFromStyles(mergedStyles, globalFontFace);
273
244
  const counterStyles = extractCounterStyleFromStyles(mergedStyles, globalCounterStyle);
274
245
  const functions = extractFunctionsFromStyles(mergedStyles, globalFunction);
275
- const chunks = extractStylesWithChunks(mergedStyles);
246
+ const chunks = extractChunks(mergedStyles);
276
247
  const className = chunks.length > 0 ? chunks.map((c) => c.className).join(" ") : "";
277
248
  const staticStyleObject = createStaticStyleAST(className, mergedStyles);
278
249
  if (mode === "inject") {
@@ -284,24 +255,22 @@ function handleExtensionMode(path, args, cssWriter, state, globalRegistry, mode,
284
255
  }
285
256
  registerIfVariableDeclaration(path, className, mergedStyles, state, globalRegistry);
286
257
  }
287
- /**
288
- * Handle tastyStatic(selector, styles) - removes the call entirely
289
- */
290
- function handleSelectorMode(path, args, cssWriter, mode, sourceFile, globalKeyframes, autoPropertyTypes, globalFontFace, globalCounterStyle, globalFunction) {
258
+ function handleSelectorMode(path, args, cssWriter, mode, sourceFile, globalKeyframes, autoPropertyTypes, globalFontFace, globalCounterStyle, globalFunction, globalRecipes) {
291
259
  if (args.length < 2) throw path.buildCodeFrameError("tastyStatic(selector, styles) requires two arguments");
292
260
  const selectorArg = args[0];
293
261
  const stylesArg = args[1];
294
262
  if (!t.isStringLiteral(selectorArg)) throw path.buildCodeFrameError("tastyStatic(selector, styles) first argument must be a string literal");
295
263
  if (!t.isObjectExpression(stylesArg)) throw path.buildCodeFrameError("tastyStatic(selector, styles) second argument must be a static object literal");
296
264
  const selector = selectorArg.value;
297
- const styles = resolveRecipes(evaluateObjectExpression(stylesArg, path));
265
+ const rawStyles = evaluateObjectExpression(stylesArg, path);
266
+ const styles = resolveRecipesWith(rawStyles, globalRecipes ?? null);
298
267
  const { keyframes, nameMap } = extractKeyframesFromStyles(styles, globalKeyframes);
299
268
  const properties = extractPropertiesFromStyles(styles, { autoPropertyTypes });
300
269
  const fontFaces = extractFontFaceFromStyles(styles, globalFontFace);
301
270
  const counterStyles = extractCounterStyleFromStyles(styles, globalCounterStyle);
302
271
  const functions = extractFunctionsFromStyles(styles, globalFunction);
303
- const result = extractStylesForSelector(selector, styles);
304
- const selectorCSS = nameMap.size > 0 ? replaceAnimationNamesInCSS(result.css, nameMap) : result.css;
272
+ const css = renderSelectorCSS(selector, styles);
273
+ const selectorCSS = nameMap.size > 0 ? replaceAnimationNamesInCSS(css, nameMap) : css;
305
274
  if (mode === "inject") {
306
275
  const cssParts = [];
307
276
  for (const kf of keyframes) cssParts.push(kf.css);
@@ -322,9 +291,6 @@ function handleSelectorMode(path, args, cssWriter, mode, sourceFile, globalKeyfr
322
291
  else path.replaceWith(t.identifier("undefined"));
323
292
  }
324
293
  }
325
- /**
326
- * Collect all extracted CSS parts into a single string (for inject mode).
327
- */
328
294
  function collectAllCSS(keyframes, properties, fontFaces, counterStyles, functions, chunks, nameMap) {
329
295
  const parts = [];
330
296
  for (const kf of keyframes) parts.push(kf.css);
@@ -335,9 +301,6 @@ function collectAllCSS(keyframes, properties, fontFaces, counterStyles, function
335
301
  for (const chunk of chunks) parts.push(nameMap.size > 0 ? replaceAnimationNamesInCSS(chunk.css, nameMap) : chunk.css);
336
302
  return parts.join("\n");
337
303
  }
338
- /**
339
- * Write all extracted CSS parts to a CSSWriter (for file mode).
340
- */
341
304
  function writeCSSToWriter(cssWriter, keyframes, properties, fontFaces, counterStyles, functions, chunks, nameMap, sourceFile) {
342
305
  for (const kf of keyframes) cssWriter.add(kf.css, kf.css, sourceFile);
343
306
  for (const prop of properties) cssWriter.add(prop.css, prop.css, sourceFile);
@@ -349,23 +312,19 @@ function writeCSSToWriter(cssWriter, keyframes, properties, fontFaces, counterSt
349
312
  cssWriter.add(chunk.className, css, sourceFile);
350
313
  }
351
314
  }
352
- /**
353
- * Extract CSS for a selector from a styles/tokens object.
354
- * Returns undefined when there are no styles or no CSS output.
355
- */
356
- function extractCSSFromStyles(selector, styles) {
315
+ function extractCSSFromStyles(selector, styles, globalKeyframes) {
357
316
  if (!styles || Object.keys(styles).length === 0) return void 0;
358
- return extractStylesForSelector(selector, styles).css || void 0;
317
+ return extractSelectorCSS(selector, styles, globalKeyframes) || void 0;
318
+ }
319
+ function writeGlobalStyles(cssWriter, selector, styles, globalKeyframes) {
320
+ const { keyframes, nameMap } = extractKeyframesFromStyles(styles, globalKeyframes);
321
+ for (const kf of keyframes) cssWriter.add(kf.css, kf.css);
322
+ const css = replaceAnimationNamesInCSS(renderSelectorCSS(selector, styles), nameMap);
323
+ if (css) cssWriter.add(`global:${selector}`, css);
359
324
  }
360
- /**
361
- * Create an `_$i(id, css)` call expression AST node for inject mode.
362
- */
363
325
  function createInjectCallAST(id, css) {
364
326
  return t.callExpression(t.identifier("_$i"), [t.stringLiteral(id), t.stringLiteral(css)]);
365
327
  }
366
- /**
367
- * Create a StaticStyle object AST node
368
- */
369
328
  function createStaticStyleAST(className, styles) {
370
329
  return t.objectExpression([
371
330
  t.objectProperty(t.identifier("className"), t.stringLiteral(className)),
@@ -373,9 +332,6 @@ function createStaticStyleAST(className, styles) {
373
332
  t.objectMethod("method", t.identifier("toString"), [], t.blockStatement([t.returnStatement(t.memberExpression(t.thisExpression(), t.identifier("className")))]))
374
333
  ]);
375
334
  }
376
- /**
377
- * Register a StaticStyle in the registry if it's being assigned to a variable
378
- */
379
335
  function registerIfVariableDeclaration(path, className, styles, state, globalRegistry) {
380
336
  const parent = path.parentPath;
381
337
  if (parent && t.isVariableDeclarator(parent.node)) {
@@ -393,9 +349,6 @@ function registerIfVariableDeclaration(path, className, styles, state, globalReg
393
349
  }
394
350
  }
395
351
  }
396
- /**
397
- * Convert a JavaScript value to an AST node
398
- */
399
352
  function valueToAST(value) {
400
353
  if (value === null) return t.nullLiteral();
401
354
  if (value === void 0) return t.identifier("undefined");
@@ -409,10 +362,6 @@ function valueToAST(value) {
409
362
  }
410
363
  return t.identifier("undefined");
411
364
  }
412
- /**
413
- * Evaluate an ObjectExpression to a plain JavaScript object.
414
- * Only supports static values that can be determined at build time.
415
- */
416
365
  function evaluateObjectExpression(node, path) {
417
366
  const result = {};
418
367
  for (const prop of node.properties) {
@@ -422,13 +371,11 @@ function evaluateObjectExpression(node, path) {
422
371
  if (t.isIdentifier(prop.key)) key = prop.key.name;
423
372
  else if (t.isStringLiteral(prop.key)) key = prop.key.value;
424
373
  else throw path.buildCodeFrameError("Dynamic property keys are not supported in tastyStatic()");
425
- result[key] = evaluateExpression(prop.value, path);
374
+ const value = evaluateExpression(prop.value, path);
375
+ result[key] = value;
426
376
  }
427
377
  return result;
428
378
  }
429
- /**
430
- * Evaluate an expression to a JavaScript value.
431
- */
432
379
  function evaluateExpression(node, path) {
433
380
  if (t.isStringLiteral(node)) return node.value;
434
381
  if (t.isNumericLiteral(node)) return node.value;
@@ -451,27 +398,6 @@ function evaluateExpression(node, path) {
451
398
  }
452
399
  throw path.buildCodeFrameError(`Dynamic expressions are not supported in tastyStatic() - got ${node.type}. All values must be static literals.`);
453
400
  }
454
- /**
455
- * Replace animation names in CSS string.
456
- * Wraps the keyframes replaceAnimationNames to work on full CSS blocks.
457
- */
458
- function replaceAnimationNamesInCSS(css, nameMap) {
459
- if (nameMap.size === 0) return css;
460
- return css.replace(/(animation(?:-name)?)\s*:\s*([^;}]+)/gi, (match, prop, value) => {
461
- let newValue = value;
462
- for (const [original, replacement] of nameMap) {
463
- const pattern = new RegExp(`\\b${escapeRegex(original)}\\b`, "g");
464
- newValue = newValue.replace(pattern, replacement);
465
- }
466
- return `${prop}: ${newValue}`;
467
- });
468
- }
469
- /**
470
- * Escape special regex characters.
471
- */
472
- function escapeRegex(str) {
473
- return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
474
- }
475
401
  //#endregion
476
402
  export { babel_default as default };
477
403