@tenphi/tasty 2.1.2 → 2.3.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.
- package/README.md +4 -1
- package/dist/{collector-LuU1vZ68.d.ts → collector-BQHl-atL.d.ts} +12 -2
- package/dist/{collector-C4sagPeG.js → collector-W0bezf67.js} +24 -11
- package/dist/collector-W0bezf67.js.map +1 -0
- package/dist/{config-BovFXQil.js → config-64Uwyc2X.js} +179 -77
- package/dist/config-64Uwyc2X.js.map +1 -0
- package/dist/{config-vuCRkBWX.d.ts → config-aro6t9gs.d.ts} +43 -4
- package/dist/core/index.d.ts +5 -5
- package/dist/core/index.js +6 -6
- package/dist/{core-CpKZ2RrZ.js → core-PLIDTtQC.js} +18 -12
- package/dist/core-PLIDTtQC.js.map +1 -0
- package/dist/{css-writer-BYgviy4G.js → css-writer-jWRnDIy6.js} +28 -6
- package/dist/css-writer-jWRnDIy6.js.map +1 -0
- package/dist/{format-rules-BBK7s2il.js → format-rules-Dv0JpQgQ.js} +2 -2
- package/dist/{format-rules-BBK7s2il.js.map → format-rules-Dv0JpQgQ.js.map} +1 -1
- package/dist/{hydrate-DN98QICD.js → hydrate-DX8vMcau.js} +2 -2
- package/dist/{hydrate-DN98QICD.js.map → hydrate-DX8vMcau.js.map} +1 -1
- package/dist/{index-dUtwpOux.d.ts → index-Dy74C11K.d.ts} +8 -1
- package/dist/{index-ZRxZWzlj.d.ts → index-IOt-QoB7.d.ts} +32 -6
- package/dist/index.d.ts +5 -5
- package/dist/index.js +10 -10
- package/dist/index.js.map +1 -1
- package/dist/{keyframes-Bzl_6mN0.js → keyframes-B-7Bm9aG.js} +3 -2
- package/dist/{keyframes-Bzl_6mN0.js.map → keyframes-B-7Bm9aG.js.map} +1 -1
- package/dist/{merge-styles-CtDJMhpJ.d.ts → merge-styles-BS-mpcci.d.ts} +2 -2
- package/dist/{merge-styles-BjdI0NVL.js → merge-styles-ucwtvIa_.js} +2 -2
- package/dist/{merge-styles-BjdI0NVL.js.map → merge-styles-ucwtvIa_.js.map} +1 -1
- package/dist/{resolve-recipes-9zJQojHT.js → resolve-recipes-prBKwyCz.js} +3 -3
- package/dist/{resolve-recipes-9zJQojHT.js.map → resolve-recipes-prBKwyCz.js.map} +1 -1
- package/dist/ssr/astro-client.js +1 -1
- package/dist/ssr/astro.d.ts +1 -12
- package/dist/ssr/astro.js +3 -3
- package/dist/ssr/astro.js.map +1 -1
- package/dist/ssr/index.d.ts +1 -1
- package/dist/ssr/index.js +3 -3
- package/dist/ssr/next.d.ts +1 -1
- package/dist/ssr/next.js +4 -4
- package/dist/ssr/next.js.map +1 -1
- package/dist/static/index.d.ts +2 -2
- package/dist/static/index.js +1 -1
- package/dist/static/index.js.map +1 -1
- package/dist/zero/babel.d.ts +1 -1
- package/dist/zero/babel.js +16 -8
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +1 -1
- package/dist/zero/index.js +1 -1
- package/docs/configuration.md +44 -0
- package/docs/dsl.md +14 -13
- package/docs/ssr.md +5 -3
- package/docs/tasty-static.md +15 -0
- package/package.json +1 -1
- package/tasty.config.ts +1 -0
- package/dist/collector-C4sagPeG.js.map +0 -1
- package/dist/config-BovFXQil.js.map +0 -1
- package/dist/core-CpKZ2RrZ.js.map +0 -1
- package/dist/css-writer-BYgviy4G.js.map +0 -1
package/dist/zero/babel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"babel.js","names":[],"sources":["../../src/zero/babel.ts"],"sourcesContent":["/**\n * Babel plugin for zero-runtime tasty static site generation.\n *\n * Transforms:\n * - `tastyStatic(styles)` → StaticStyle object { className, styles, toString() }\n * - `tastyStatic(base, styles)` → StaticStyle object with merged styles\n * - `tastyStatic(selector, styles)` → removed entirely\n *\n * Usage:\n * ```javascript\n * // babel.config.js\n * module.exports = {\n * plugins: [\n * ['@tenphi/tasty/babel-plugin', { output: 'public/tasty.css' }]\n * ]\n * };\n * ```\n */\n\nimport * as fs from 'fs';\nimport * as path from 'path';\n\nimport { declare } from '@babel/helper-plugin-utils';\nimport * as t from '@babel/types';\nimport { createJiti } from 'jiti';\n\nimport {\n configure,\n getGlobalStyles,\n getGlobalConfigTokens,\n resetConfig,\n} from '../config';\nimport type { TastyConfig } from '../config';\nimport type { Styles, ConfigTokens } from '../styles/types';\nimport { mergeStyles } from '../utils/merge-styles';\nimport { resolveRecipes } from '../utils/resolve-recipes';\n\nimport { CSSWriter } from './css-writer';\nimport {\n extractCounterStyleFromStyles,\n extractFontFaceFromStyles,\n extractKeyframesFromStyles,\n extractPropertiesFromStyles,\n extractStylesForSelector,\n extractStylesWithChunks,\n} from './extractor';\nimport type {\n ExtractedChunk,\n ExtractedCounterStyle,\n ExtractedFontFace,\n ExtractedKeyframes,\n ExtractedProperty,\n} from './extractor';\n\nimport type { NodePath, PluginPass } from '@babel/core';\nimport type {\n CounterStyleDescriptors,\n FontFaceInput,\n KeyframesSteps,\n} from '../injector/types';\n\n/**\n * Build-time configuration for zero-runtime mode.\n * Subset of TastyConfig excluding runtime-only DOM options\n * (`nonce`, `maxRulesPerSheet`, `forceTextInjection`, `gc`)\n * and overriding `devMode` default to `false`.\n */\nexport type TastyZeroConfig = Omit<\n TastyConfig,\n 'nonce' | 'maxRulesPerSheet' | 'forceTextInjection' | 'gc' | 'devMode'\n> & {\n /**\n * Enable development mode features: source comments in generated CSS.\n * @default false\n */\n devMode?: boolean;\n};\n\nexport interface TastyZeroBabelOptions {\n /** Output path for generated CSS (default: 'tasty.css') */\n output?: string;\n /**\n * Tasty configuration for build-time processing.\n * Can be a static object or a factory function that returns fresh config.\n * A factory is called on each plugin invocation, enabling hot reload\n * of config values that depend on external files (e.g. theme tokens).\n */\n config?: TastyZeroConfig | (() => TastyZeroConfig);\n /**\n * Absolute path to a TypeScript/JavaScript module that default-exports\n * a `TastyZeroConfig` object. The module is loaded via jiti on each\n * plugin invocation, enabling hot reload when the file changes.\n *\n * This option is JSON-serializable and is the primary way Turbopack\n * passes config to the Babel plugin (since Turbopack loader options\n * must be plain primitives/objects/arrays).\n *\n * When both `config` and `configFile` are set, `config` takes precedence.\n *\n * @example '/absolute/path/to/tasty-zero.config.ts'\n */\n configFile?: string;\n /**\n * Absolute file paths whose content affects the generated CSS.\n * When any of these files change, babel-loader invalidates its cache\n * and re-runs the plugin with fresh config values.\n *\n * Typically includes theme files that define Glaze palettes or token values.\n * Paths must be absolute (resolved by the Next.js wrapper).\n */\n configDeps?: string[];\n /**\n * Automatically replace `@tenphi/tasty/static` imports with an import\n * of the generated CSS file. This eliminates the need for users to\n * manually import the CSS in their app entry point.\n *\n * @default true\n */\n injectImport?: boolean;\n /**\n * Output mode for extracted CSS.\n *\n * - `'file'` (default): CSS is written to a single output file and\n * the `@tenphi/tasty/static` import is rewritten to import that file.\n * - `'inject'`: CSS is embedded inline in the JS output and injected\n * at runtime via a tiny injector from `@tenphi/tasty/static/inject`.\n * No CSS file is written. Each `tastyStatic` call becomes\n * self-contained. Best for reusable components and extensions.\n *\n * When `mode` is `'inject'`, `output` and `injectImport` are ignored.\n *\n * @default 'file'\n */\n mode?: 'file' | 'inject';\n}\n\n/**\n * Registry to track StaticStyle objects by their variable names.\n * Used to resolve base styles when extending.\n */\ntype StaticStyleRegistry = Record<\n string,\n {\n styles: Styles;\n className: string;\n }\n>;\n\ninterface PluginState extends PluginPass {\n staticStyleRegistry: StaticStyleRegistry;\n /** Current source file path (for devMode source comments) */\n sourceFile?: string;\n /** Whether this file added CSS blocks to the writer (via tastyStatic calls) */\n _fileAddedCSS?: boolean;\n}\n\nfunction mtime(filePath: string): number | null {\n try {\n return fs.statSync(filePath).mtimeMs;\n } catch {\n return null;\n }\n}\n\nfunction clearRequireCacheTree(filePath: string): void {\n let resolved: string;\n\n try {\n resolved = require.resolve(filePath);\n } catch {\n return;\n }\n\n const mod = require.cache[resolved];\n\n if (!mod) return;\n\n const dir = resolved.substring(0, resolved.lastIndexOf('/'));\n\n if (mod.children) {\n for (const child of mod.children) {\n if (child.id.startsWith(dir) && !child.id.includes('node_modules')) {\n clearRequireCacheTree(child.id);\n }\n }\n }\n\n delete require.cache[resolved];\n}\n\n// Shared CSSWriter cache keyed by resolved output path.\n// Persists across per-file Babel invocations (Turbopack model) so that\n// CSS from all files accumulates instead of being overwritten.\ninterface WriterCacheEntry {\n writer: CSSWriter;\n configKey: string;\n registry: StaticStyleRegistry;\n config: TastyZeroConfig;\n}\nconst writerCache = new Map<string, WriterCacheEntry>();\n\n/** Clear the shared CSSWriter cache. Exposed for testing. */\nexport function clearWriterCache(): void {\n writerCache.clear();\n}\n\n// @ts-expect-error PluginState vs PluginPass type mismatch in @babel/helper-plugin-utils\nexport default declare<TastyZeroBabelOptions>((api, options) => {\n api.assertVersion(7);\n\n const mode = options.mode ?? 'file';\n const outputPath = options.output || 'tasty.css';\n const resolvedOutputPath = path.resolve(outputPath);\n const injectImport = options.injectImport ?? true;\n\n if (mode === 'file' && injectImport) {\n const dir = path.dirname(resolvedOutputPath);\n\n if (!fs.existsSync(dir)) {\n fs.mkdirSync(dir, { recursive: true });\n }\n\n if (!fs.existsSync(resolvedOutputPath)) {\n fs.writeFileSync(\n resolvedOutputPath,\n '/* Generated by @tenphi/tasty/zero - DO NOT EDIT */\\n',\n );\n }\n }\n\n const configDeps = [\n ...(options.configFile ? [options.configFile] : []),\n ...(options.configDeps || []),\n ];\n\n // Fingerprint for config deps — used to detect config changes\n // and invalidate the shared CSSWriter cache.\n const configKey =\n configDeps.length > 0 ? configDeps.map(mtime).join(',') : '';\n\n // Register external dependencies for babel-loader cache invalidation.\n // When any configDeps file changes, babel-loader discards the cached\n // transform result and re-runs the plugin, picking up fresh config.\n if (configDeps.length > 0) {\n api.cache.using(() => configKey);\n\n for (const dep of configDeps) {\n try {\n (\n api as unknown as { addExternalDependency(path: string): void }\n ).addExternalDependency(dep);\n } catch {\n // addExternalDependency may not be available in all environments\n }\n }\n } else {\n api.cache.forever();\n }\n\n // When configDeps are set, clear the require cache so we get fresh values.\n if (configDeps.length > 0) {\n for (const dep of configDeps) {\n clearRequireCacheTree(dep);\n }\n }\n\n // Look up or create the shared CSSWriter for this output path.\n // When config deps change (different configKey), discard the old writer\n // and reset pipeline state so configure() can run again.\n const cached = writerCache.get(resolvedOutputPath);\n const configChanged = !cached || cached.configKey !== configKey;\n\n if (configChanged) {\n const configOption = options.config;\n let resolvedConfig: TastyZeroConfig;\n\n if (configOption) {\n resolvedConfig =\n typeof configOption === 'function' ? configOption() : configOption;\n } else if (options.configFile) {\n const jiti = createJiti(path.dirname(options.configFile), {\n moduleCache: false,\n });\n\n resolvedConfig = jiti(options.configFile) as TastyZeroConfig;\n } else {\n resolvedConfig = {};\n }\n\n const devMode = resolvedConfig.devMode ?? false;\n\n if (cached) {\n resetConfig();\n }\n\n configure(resolvedConfig);\n\n const newWriter = new CSSWriter(outputPath, { devMode });\n\n // Emit configured tokens and global styles (file mode only;\n // inject mode handles injection per-file in the post hook).\n if (mode !== 'inject') {\n const tokenCSS = extractCSSFromStyles(':root', getGlobalConfigTokens());\n if (tokenCSS) newWriter.add(':root:tokens', tokenCSS);\n\n const globalStyles = getGlobalStyles();\n if (globalStyles) {\n for (const [selector, styles] of Object.entries(globalStyles)) {\n const css = extractCSSFromStyles(selector, styles);\n if (css) newWriter.add(`global:${selector}`, css);\n }\n }\n }\n\n writerCache.set(resolvedOutputPath, {\n writer: newWriter,\n configKey,\n registry: {},\n config: resolvedConfig,\n });\n }\n\n const entry = writerCache.get(resolvedOutputPath)!;\n const cssWriter = entry.writer;\n const globalRegistry = entry.registry;\n const config = entry.config;\n const devMode = config.devMode ?? false;\n\n // Precompute token CSS and global styles CSS for inject mode\n let tokenCSS: string | undefined;\n let globalStylesCSS: Map<string, string> | undefined;\n if (mode === 'inject') {\n tokenCSS = extractCSSFromStyles(':root', getGlobalConfigTokens());\n const gs = getGlobalStyles();\n if (gs) {\n globalStylesCSS = new Map();\n for (const [selector, styles] of Object.entries(gs)) {\n const css = extractCSSFromStyles(selector, styles);\n if (css) globalStylesCSS.set(selector, css);\n }\n if (globalStylesCSS.size === 0) globalStylesCSS = undefined;\n }\n }\n\n return {\n name: 'tasty-zero',\n\n pre(this: PluginState) {\n // Initialize per-file registry\n this.staticStyleRegistry = {};\n this._fileAddedCSS = false;\n // Extract source filename for devMode comments\n if (devMode && this.filename) {\n // Get relative path or just filename\n this.sourceFile = this.filename.split('/').pop() || this.filename;\n }\n },\n\n visitor: {\n ImportDeclaration(\n nodePath: NodePath<t.ImportDeclaration>,\n state: PluginState,\n ) {\n const source = nodePath.node.source.value;\n\n if (\n source === '@tenphi/tasty/static' ||\n source.endsWith('/tasty/static')\n ) {\n if (mode === 'inject') {\n nodePath.replaceWith(\n t.importDeclaration(\n [\n t.importSpecifier(\n t.identifier('_$i'),\n t.identifier('injectCSS'),\n ),\n ],\n t.stringLiteral('@tenphi/tasty/static/inject'),\n ),\n );\n } else if (injectImport) {\n let importPath = resolvedOutputPath;\n\n if (state.filename) {\n const sourceDir = path.dirname(state.filename);\n importPath = path.relative(sourceDir, resolvedOutputPath);\n\n if (!importPath.startsWith('.')) {\n importPath = './' + importPath;\n }\n }\n\n nodePath.replaceWith(\n t.importDeclaration([], t.stringLiteral(importPath)),\n );\n } else {\n nodePath.remove();\n }\n }\n },\n\n // Transform tastyStatic() calls\n CallExpression(path: NodePath<t.CallExpression>, state: PluginState) {\n const callee = path.node.callee;\n\n // Match tastyStatic(...) calls\n if (!t.isIdentifier(callee, { name: 'tastyStatic' })) {\n return;\n }\n\n state._fileAddedCSS = true;\n\n const args = path.node.arguments;\n\n if (args.length === 0) {\n throw path.buildCodeFrameError(\n 'tastyStatic() requires at least one argument',\n );\n }\n\n const firstArg = args[0];\n\n if (t.isStringLiteral(firstArg)) {\n // Selector mode: tastyStatic(selector, styles)\n handleSelectorMode(\n path,\n args,\n cssWriter,\n mode,\n state.sourceFile,\n config.keyframes,\n config.autoPropertyTypes,\n config.fontFace,\n config.counterStyle,\n );\n } else if (t.isObjectExpression(firstArg)) {\n // Styles mode: tastyStatic(styles)\n handleStylesMode(\n path,\n args,\n cssWriter,\n state,\n globalRegistry,\n mode,\n config.keyframes,\n config.autoPropertyTypes,\n config.fontFace,\n config.counterStyle,\n );\n } else if (t.isIdentifier(firstArg)) {\n // Extension mode: tastyStatic(base, styles)\n handleExtensionMode(\n path,\n args,\n cssWriter,\n state,\n globalRegistry,\n mode,\n config.keyframes,\n config.autoPropertyTypes,\n config.fontFace,\n config.counterStyle,\n );\n } else {\n throw path.buildCodeFrameError(\n 'tastyStatic() first argument must be an object (styles), ' +\n 'identifier (base StaticStyle), or string (selector)',\n );\n }\n },\n\n // Track variable declarations to register StaticStyle objects\n VariableDeclarator(\n path: NodePath<t.VariableDeclarator>,\n state: PluginState,\n ) {\n const init = path.node.init;\n const id = path.node.id;\n\n // Check if this is a StaticStyle object (has className and styles properties)\n if (\n t.isIdentifier(id) &&\n t.isObjectExpression(init) &&\n isStaticStyleObject(init)\n ) {\n const variableName = id.name;\n const styles = extractStylesFromStaticStyleObject(init, path);\n const className = extractClassNameFromStaticStyleObject(init);\n\n if (styles && className) {\n state.staticStyleRegistry[variableName] = { styles, className };\n globalRegistry[variableName] = { styles, className };\n }\n }\n },\n },\n\n post(this: PluginState) {\n if (mode === 'inject') {\n // In inject mode, inject token/global CSS as top-level statements\n // when this file had tastyStatic calls and config CSS exists.\n if (this._fileAddedCSS && (tokenCSS || globalStylesCSS)) {\n const program = this.file.ast.program;\n\n // Find the position after the inject import\n let insertIndex = 0;\n for (let i = 0; i < program.body.length; i++) {\n if (t.isImportDeclaration(program.body[i])) {\n insertIndex = i + 1;\n }\n }\n\n if (tokenCSS) {\n const injectCall = createInjectCallAST(':root', tokenCSS);\n program.body.splice(\n insertIndex,\n 0,\n t.expressionStatement(injectCall),\n );\n insertIndex++;\n }\n\n if (globalStylesCSS) {\n for (const [selector, css] of globalStylesCSS) {\n const injectCall = createInjectCallAST(selector, css);\n program.body.splice(\n insertIndex,\n 0,\n t.expressionStatement(injectCall),\n );\n insertIndex++;\n }\n }\n }\n return;\n }\n\n // Only write when this file contributed CSS (had tastyStatic calls).\n // In Turbopack, separate workers each have their own CSSWriter with\n // only token CSS. Letting those workers write would overwrite the\n // complete CSS produced by the worker that processed tastyStatic files.\n if (this._fileAddedCSS && cssWriter.size > 0) {\n cssWriter.write();\n }\n },\n };\n});\n\n/**\n * Check if an object expression looks like a StaticStyle object\n */\nfunction isStaticStyleObject(node: t.ObjectExpression): boolean {\n const hasClassName = node.properties.some(\n (p) =>\n t.isObjectProperty(p) && t.isIdentifier(p.key, { name: 'className' }),\n );\n const hasStyles = node.properties.some(\n (p) => t.isObjectProperty(p) && t.isIdentifier(p.key, { name: 'styles' }),\n );\n return hasClassName && hasStyles;\n}\n\n/**\n * Extract styles object from a StaticStyle object expression\n */\nfunction extractStylesFromStaticStyleObject(\n node: t.ObjectExpression,\n path: NodePath,\n): Styles | null {\n for (const prop of node.properties) {\n if (\n t.isObjectProperty(prop) &&\n t.isIdentifier(prop.key, { name: 'styles' }) &&\n t.isObjectExpression(prop.value)\n ) {\n return evaluateObjectExpression(prop.value, path) as Styles;\n }\n }\n return null;\n}\n\n/**\n * Extract className from a StaticStyle object expression\n */\nfunction extractClassNameFromStaticStyleObject(\n node: t.ObjectExpression,\n): string | null {\n for (const prop of node.properties) {\n if (\n t.isObjectProperty(prop) &&\n t.isIdentifier(prop.key, { name: 'className' }) &&\n t.isStringLiteral(prop.value)\n ) {\n return prop.value.value;\n }\n }\n return null;\n}\n\n/**\n * Handle tastyStatic(styles) - returns StaticStyle object\n */\nfunction handleStylesMode(\n path: NodePath<t.CallExpression>,\n args: t.CallExpression['arguments'],\n cssWriter: CSSWriter,\n state: PluginState,\n globalRegistry: StaticStyleRegistry,\n mode: 'file' | 'inject',\n globalKeyframes?: Record<string, KeyframesSteps>,\n autoPropertyTypes?: boolean,\n globalFontFace?: Record<string, FontFaceInput>,\n globalCounterStyle?: Record<string, CounterStyleDescriptors>,\n): void {\n const stylesArg = args[0];\n\n if (!t.isObjectExpression(stylesArg)) {\n throw path.buildCodeFrameError(\n 'tastyStatic(styles) argument must be a static object literal',\n );\n }\n\n // Evaluate styles object at build time\n const rawStyles = evaluateObjectExpression(stylesArg, path) as Styles;\n\n // Resolve recipes before extraction\n const styles = resolveRecipes(rawStyles);\n\n // Extract keyframes (deduplicated by content)\n const { keyframes, nameMap } = extractKeyframesFromStyles(\n styles,\n globalKeyframes,\n );\n\n // Extract and add auto-inferred @property rules\n const properties = extractPropertiesFromStyles(styles, { autoPropertyTypes });\n\n // Extract @font-face rules\n const fontFaces = extractFontFaceFromStyles(styles, globalFontFace);\n\n // Extract @counter-style rules\n const counterStyles = extractCounterStyleFromStyles(\n styles,\n globalCounterStyle,\n );\n\n // Extract styles with chunking\n const chunks = extractStylesWithChunks(styles);\n\n const className =\n chunks.length > 0 ? chunks.map((c) => c.className).join(' ') : '';\n const staticStyleObject = createStaticStyleAST(className, styles);\n\n if (mode === 'inject') {\n const allCSS = collectAllCSS(\n keyframes,\n properties,\n fontFaces,\n counterStyles,\n chunks,\n nameMap,\n );\n const injectCall = createInjectCallAST(className, allCSS);\n\n path.replaceWith(t.sequenceExpression([injectCall, staticStyleObject]));\n } else {\n writeCSSToWriter(\n cssWriter,\n keyframes,\n properties,\n fontFaces,\n counterStyles,\n chunks,\n nameMap,\n state.sourceFile,\n );\n path.replaceWith(staticStyleObject);\n }\n\n registerIfVariableDeclaration(path, className, styles, state, globalRegistry);\n}\n\n/**\n * Handle tastyStatic(base, styles) - extends base with additional styles\n */\nfunction handleExtensionMode(\n path: NodePath<t.CallExpression>,\n args: t.CallExpression['arguments'],\n cssWriter: CSSWriter,\n state: PluginState,\n globalRegistry: StaticStyleRegistry,\n mode: 'file' | 'inject',\n globalKeyframes?: Record<string, KeyframesSteps>,\n autoPropertyTypes?: boolean,\n globalFontFace?: Record<string, FontFaceInput>,\n globalCounterStyle?: Record<string, CounterStyleDescriptors>,\n): void {\n if (args.length < 2) {\n throw path.buildCodeFrameError(\n 'tastyStatic(base, styles) requires two arguments',\n );\n }\n\n const baseArg = args[0];\n const stylesArg = args[1];\n\n if (!t.isIdentifier(baseArg)) {\n throw path.buildCodeFrameError(\n 'tastyStatic(base, styles) first argument must be an identifier',\n );\n }\n\n if (!t.isObjectExpression(stylesArg)) {\n throw path.buildCodeFrameError(\n 'tastyStatic(base, styles) second argument must be a static object literal',\n );\n }\n\n const baseName = baseArg.name;\n\n // Look up base styles in registry\n const baseEntry =\n state.staticStyleRegistry[baseName] || globalRegistry[baseName];\n\n if (!baseEntry) {\n throw path.buildCodeFrameError(\n `Cannot find base StaticStyle '${baseName}'. ` +\n 'Make sure it is defined before being extended.',\n );\n }\n\n // Evaluate override styles\n const overrideStyles = evaluateObjectExpression(stylesArg, path) as Styles;\n\n // Merge styles using mergeStyles, then resolve recipes\n const mergedStyles = resolveRecipes(\n mergeStyles(baseEntry.styles, overrideStyles),\n );\n\n // Extract keyframes (deduplicated by content)\n const { keyframes, nameMap } = extractKeyframesFromStyles(\n mergedStyles,\n globalKeyframes,\n );\n\n // Extract auto-inferred @property rules\n const properties = extractPropertiesFromStyles(mergedStyles, {\n autoPropertyTypes,\n });\n\n // Extract @font-face rules\n const fontFaces = extractFontFaceFromStyles(mergedStyles, globalFontFace);\n\n // Extract @counter-style rules\n const counterStyles = extractCounterStyleFromStyles(\n mergedStyles,\n globalCounterStyle,\n );\n\n // Extract styles with chunking\n const chunks = extractStylesWithChunks(mergedStyles);\n\n const className =\n chunks.length > 0 ? chunks.map((c) => c.className).join(' ') : '';\n const staticStyleObject = createStaticStyleAST(className, mergedStyles);\n\n if (mode === 'inject') {\n const allCSS = collectAllCSS(\n keyframes,\n properties,\n fontFaces,\n counterStyles,\n chunks,\n nameMap,\n );\n const injectCall = createInjectCallAST(className, allCSS);\n\n path.replaceWith(t.sequenceExpression([injectCall, staticStyleObject]));\n } else {\n writeCSSToWriter(\n cssWriter,\n keyframes,\n properties,\n fontFaces,\n counterStyles,\n chunks,\n nameMap,\n state.sourceFile,\n );\n path.replaceWith(staticStyleObject);\n }\n\n registerIfVariableDeclaration(\n path,\n className,\n mergedStyles,\n state,\n globalRegistry,\n );\n}\n\n/**\n * Handle tastyStatic(selector, styles) - removes the call entirely\n */\nfunction handleSelectorMode(\n path: NodePath<t.CallExpression>,\n args: t.CallExpression['arguments'],\n cssWriter: CSSWriter,\n mode: 'file' | 'inject',\n sourceFile?: string,\n globalKeyframes?: Record<string, KeyframesSteps>,\n autoPropertyTypes?: boolean,\n globalFontFace?: Record<string, FontFaceInput>,\n globalCounterStyle?: Record<string, CounterStyleDescriptors>,\n): void {\n if (args.length < 2) {\n throw path.buildCodeFrameError(\n 'tastyStatic(selector, styles) requires two arguments',\n );\n }\n\n const selectorArg = args[0];\n const stylesArg = args[1];\n\n if (!t.isStringLiteral(selectorArg)) {\n throw path.buildCodeFrameError(\n 'tastyStatic(selector, styles) first argument must be a string literal',\n );\n }\n\n if (!t.isObjectExpression(stylesArg)) {\n throw path.buildCodeFrameError(\n 'tastyStatic(selector, styles) second argument must be a static object literal',\n );\n }\n\n const selector = selectorArg.value;\n const rawStyles = evaluateObjectExpression(stylesArg, path) as Styles;\n\n // Resolve recipes before extraction\n const styles = resolveRecipes(rawStyles);\n\n // Extract keyframes (deduplicated by content)\n const { keyframes, nameMap } = extractKeyframesFromStyles(\n styles,\n globalKeyframes,\n );\n\n // Extract auto-inferred @property rules\n const properties = extractPropertiesFromStyles(styles, { autoPropertyTypes });\n\n // Extract @font-face rules\n const fontFaces = extractFontFaceFromStyles(styles, globalFontFace);\n\n // Extract @counter-style rules\n const counterStyles = extractCounterStyleFromStyles(\n styles,\n globalCounterStyle,\n );\n\n // Extract styles for selector\n const result = extractStylesForSelector(selector, styles);\n\n const selectorCSS =\n nameMap.size > 0\n ? replaceAnimationNamesInCSS(result.css, nameMap)\n : result.css;\n\n if (mode === 'inject') {\n const cssParts: string[] = [];\n\n for (const kf of keyframes) cssParts.push(kf.css);\n for (const prop of properties) cssParts.push(prop.css);\n for (const ff of fontFaces) cssParts.push(ff.css);\n for (const cs of counterStyles) cssParts.push(cs.css);\n cssParts.push(selectorCSS);\n\n const injectCall = createInjectCallAST(selector, cssParts.join('\\n'));\n\n const parent = path.parentPath;\n if (parent && t.isExpressionStatement(parent.node)) {\n parent.replaceWith(t.expressionStatement(injectCall));\n } else {\n path.replaceWith(injectCall);\n }\n } else {\n writeCSSToWriter(\n cssWriter,\n keyframes,\n properties,\n fontFaces,\n counterStyles,\n [],\n nameMap,\n sourceFile,\n );\n cssWriter.add(selector, selectorCSS, sourceFile);\n\n const parent = path.parentPath;\n if (parent && t.isExpressionStatement(parent.node)) {\n parent.remove();\n } else {\n path.replaceWith(t.identifier('undefined'));\n }\n }\n}\n\n/**\n * Collect all extracted CSS parts into a single string (for inject mode).\n */\nfunction collectAllCSS(\n keyframes: ExtractedKeyframes[],\n properties: ExtractedProperty[],\n fontFaces: ExtractedFontFace[],\n counterStyles: ExtractedCounterStyle[],\n chunks: ExtractedChunk[],\n nameMap: Map<string, string>,\n): string {\n const parts: string[] = [];\n\n for (const kf of keyframes) parts.push(kf.css);\n for (const prop of properties) parts.push(prop.css);\n for (const ff of fontFaces) parts.push(ff.css);\n for (const cs of counterStyles) parts.push(cs.css);\n\n for (const chunk of chunks) {\n parts.push(\n nameMap.size > 0\n ? replaceAnimationNamesInCSS(chunk.css, nameMap)\n : chunk.css,\n );\n }\n\n return parts.join('\\n');\n}\n\n/**\n * Write all extracted CSS parts to a CSSWriter (for file mode).\n */\nfunction writeCSSToWriter(\n cssWriter: CSSWriter,\n keyframes: ExtractedKeyframes[],\n properties: ExtractedProperty[],\n fontFaces: ExtractedFontFace[],\n counterStyles: ExtractedCounterStyle[],\n chunks: ExtractedChunk[],\n nameMap: Map<string, string>,\n sourceFile?: string,\n): void {\n for (const kf of keyframes) {\n cssWriter.add(kf.css, kf.css, sourceFile);\n }\n for (const prop of properties) {\n cssWriter.add(prop.css, prop.css, sourceFile);\n }\n for (const ff of fontFaces) {\n cssWriter.add(ff.css, ff.css, sourceFile);\n }\n for (const cs of counterStyles) {\n cssWriter.add(cs.css, cs.css, sourceFile);\n }\n\n for (const chunk of chunks) {\n const css =\n nameMap.size > 0\n ? replaceAnimationNamesInCSS(chunk.css, nameMap)\n : chunk.css;\n cssWriter.add(chunk.className, css, sourceFile);\n }\n}\n\n/**\n * Extract CSS for a selector from a styles/tokens object.\n * Returns undefined when there are no styles or no CSS output.\n */\nfunction extractCSSFromStyles(\n selector: string,\n styles: Styles | ConfigTokens | null,\n): string | undefined {\n if (!styles || Object.keys(styles).length === 0) return undefined;\n const result = extractStylesForSelector(selector, styles as Styles);\n return result.css || undefined;\n}\n\n/**\n * Create an `_$i(id, css)` call expression AST node for inject mode.\n */\nfunction createInjectCallAST(id: string, css: string): t.CallExpression {\n return t.callExpression(t.identifier('_$i'), [\n t.stringLiteral(id),\n t.stringLiteral(css),\n ]);\n}\n\n/**\n * Create a StaticStyle object AST node\n */\nfunction createStaticStyleAST(\n className: string,\n styles: Styles,\n): t.ObjectExpression {\n return t.objectExpression([\n t.objectProperty(t.identifier('className'), t.stringLiteral(className)),\n t.objectProperty(t.identifier('styles'), valueToAST(styles)),\n t.objectMethod(\n 'method',\n t.identifier('toString'),\n [],\n t.blockStatement([\n t.returnStatement(\n t.memberExpression(t.thisExpression(), t.identifier('className')),\n ),\n ]),\n ),\n ]);\n}\n\n/**\n * Register a StaticStyle in the registry if it's being assigned to a variable\n */\nfunction registerIfVariableDeclaration(\n path: NodePath,\n className: string,\n styles: Styles,\n state: PluginState,\n globalRegistry: StaticStyleRegistry,\n): void {\n const parent = path.parentPath;\n if (parent && t.isVariableDeclarator(parent.node)) {\n const id = parent.node.id;\n if (t.isIdentifier(id)) {\n const variableName = id.name;\n state.staticStyleRegistry[variableName] = { styles, className };\n globalRegistry[variableName] = { styles, className };\n }\n }\n}\n\n/**\n * Convert a JavaScript value to an AST node\n */\nfunction valueToAST(value: unknown): t.Expression {\n if (value === null) {\n return t.nullLiteral();\n }\n if (value === undefined) {\n return t.identifier('undefined');\n }\n if (typeof value === 'string') {\n return t.stringLiteral(value);\n }\n if (typeof value === 'number') {\n return t.numericLiteral(value);\n }\n if (typeof value === 'boolean') {\n return t.booleanLiteral(value);\n }\n if (Array.isArray(value)) {\n return t.arrayExpression(value.map(valueToAST));\n }\n if (typeof value === 'object') {\n const properties = Object.entries(value).map(([key, val]) =>\n t.objectProperty(\n /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key)\n ? t.identifier(key)\n : t.stringLiteral(key),\n valueToAST(val),\n ),\n );\n return t.objectExpression(properties);\n }\n // Fallback for unsupported types\n return t.identifier('undefined');\n}\n\n/**\n * Evaluate an ObjectExpression to a plain JavaScript object.\n * Only supports static values that can be determined at build time.\n */\nfunction evaluateObjectExpression(\n node: t.ObjectExpression,\n path: NodePath,\n): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n\n for (const prop of node.properties) {\n if (t.isSpreadElement(prop)) {\n throw path.buildCodeFrameError(\n 'Spread elements are not supported in tastyStatic() - styles must be fully static',\n );\n }\n\n if (!t.isObjectProperty(prop)) {\n throw path.buildCodeFrameError(\n 'Only object properties are supported in tastyStatic()',\n );\n }\n\n // Get key\n let key: string;\n if (t.isIdentifier(prop.key)) {\n key = prop.key.name;\n } else if (t.isStringLiteral(prop.key)) {\n key = prop.key.value;\n } else {\n throw path.buildCodeFrameError(\n 'Dynamic property keys are not supported in tastyStatic()',\n );\n }\n\n // Get value\n const value = evaluateExpression(prop.value, path);\n result[key] = value;\n }\n\n return result;\n}\n\n/**\n * Evaluate an expression to a JavaScript value.\n */\nfunction evaluateExpression(node: t.Node, path: NodePath): unknown {\n if (t.isStringLiteral(node)) {\n return node.value;\n }\n\n if (t.isNumericLiteral(node)) {\n return node.value;\n }\n\n if (t.isBooleanLiteral(node)) {\n return node.value;\n }\n\n if (t.isNullLiteral(node)) {\n return null;\n }\n\n if (t.isIdentifier(node, { name: 'undefined' })) {\n return undefined;\n }\n\n if (t.isArrayExpression(node)) {\n return node.elements.map((el) => {\n if (el === null) return null;\n if (t.isSpreadElement(el)) {\n throw path.buildCodeFrameError(\n 'Spread elements are not supported in tastyStatic()',\n );\n }\n return evaluateExpression(el, path);\n });\n }\n\n if (t.isObjectExpression(node)) {\n return evaluateObjectExpression(node, path);\n }\n\n if (t.isTemplateLiteral(node)) {\n // Only support template literals without expressions\n if (node.expressions.length > 0) {\n throw path.buildCodeFrameError(\n 'Template literals with expressions are not supported in tastyStatic()',\n );\n }\n return node.quasis.map((q) => q.value.cooked).join('');\n }\n\n if (t.isUnaryExpression(node, { operator: '-' })) {\n const arg = evaluateExpression(node.argument, path);\n if (typeof arg === 'number') {\n return -arg;\n }\n }\n\n throw path.buildCodeFrameError(\n `Dynamic expressions are not supported in tastyStatic() - got ${node.type}. ` +\n 'All values must be static literals.',\n );\n}\n\n/**\n * Replace animation names in CSS string.\n * Wraps the keyframes replaceAnimationNames to work on full CSS blocks.\n */\nfunction replaceAnimationNamesInCSS(\n css: string,\n nameMap: Map<string, string>,\n): string {\n if (nameMap.size === 0) return css;\n\n // The CSS contains full rules like \".class { animation: name 1s; }\"\n // We need to replace animation names within declaration blocks\n return css.replace(\n /(animation(?:-name)?)\\s*:\\s*([^;}]+)/gi,\n (match, prop, value) => {\n let newValue = value;\n for (const [original, replacement] of nameMap) {\n // Word boundary replacement\n const pattern = new RegExp(`\\\\b${escapeRegex(original)}\\\\b`, 'g');\n newValue = newValue.replace(pattern, replacement);\n }\n return `${prop}: ${newValue}`;\n },\n );\n}\n\n/**\n * Escape special regex characters.\n */\nfunction escapeRegex(str: string): string {\n return str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4JA,SAAS,MAAM,UAAiC;AAC9C,KAAI;AACF,SAAO,GAAG,SAAS,SAAS,CAAC;SACvB;AACN,SAAO;;;AAIX,SAAS,sBAAsB,UAAwB;CACrD,IAAI;AA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
|
+
{"version":3,"file":"babel.js","names":[],"sources":["../../src/zero/babel.ts"],"sourcesContent":["/**\n * Babel plugin for zero-runtime tasty static site generation.\n *\n * Transforms:\n * - `tastyStatic(styles)` → StaticStyle object { className, styles, toString() }\n * - `tastyStatic(base, styles)` → StaticStyle object with merged styles\n * - `tastyStatic(selector, styles)` → removed entirely\n *\n * Usage:\n * ```javascript\n * // babel.config.js\n * module.exports = {\n * plugins: [\n * ['@tenphi/tasty/babel-plugin', { output: 'public/tasty.css' }]\n * ]\n * };\n * ```\n */\n\nimport * as fs from 'fs';\nimport * as path from 'path';\n\nimport { declare } from '@babel/helper-plugin-utils';\nimport * as t from '@babel/types';\nimport { createJiti } from 'jiti';\n\nimport {\n configure,\n getGlobalStyles,\n getGlobalConfigTokens,\n resetConfig,\n} from '../config';\nimport type { TastyConfig } from '../config';\nimport type { Styles, ConfigTokens } from '../styles/types';\nimport { mergeStyles } from '../utils/merge-styles';\nimport { DEFAULT_ZERO_NAME_PREFIX } from '../utils/name-prefix';\nimport { resolveRecipes } from '../utils/resolve-recipes';\n\nimport { CSSWriter } from './css-writer';\nimport {\n extractCounterStyleFromStyles,\n extractFontFaceFromStyles,\n extractKeyframesFromStyles,\n extractPropertiesFromStyles,\n extractStylesForSelector,\n extractStylesWithChunks,\n setExtractorNamePrefix,\n} from './extractor';\nimport type {\n ExtractedChunk,\n ExtractedCounterStyle,\n ExtractedFontFace,\n ExtractedKeyframes,\n ExtractedProperty,\n} from './extractor';\n\nimport type { NodePath, PluginPass } from '@babel/core';\nimport type {\n CounterStyleDescriptors,\n FontFaceInput,\n KeyframesSteps,\n} from '../injector/types';\n\n/**\n * Build-time configuration for zero-runtime mode.\n * Subset of TastyConfig excluding runtime-only DOM options\n * (`nonce`, `maxRulesPerSheet`, `forceTextInjection`, `gc`)\n * and overriding `devMode` default to `false`.\n */\nexport type TastyZeroConfig = Omit<\n TastyConfig,\n 'nonce' | 'maxRulesPerSheet' | 'forceTextInjection' | 'gc' | 'devMode'\n> & {\n /**\n * Enable development mode features: source comments in generated CSS.\n * @default false\n */\n devMode?: boolean;\n};\n\nexport interface TastyZeroBabelOptions {\n /** Output path for generated CSS (default: 'tasty.css') */\n output?: string;\n /**\n * Tasty configuration for build-time processing.\n * Can be a static object or a factory function that returns fresh config.\n * A factory is called on each plugin invocation, enabling hot reload\n * of config values that depend on external files (e.g. theme tokens).\n */\n config?: TastyZeroConfig | (() => TastyZeroConfig);\n /**\n * Absolute path to a TypeScript/JavaScript module that default-exports\n * a `TastyZeroConfig` object. The module is loaded via jiti on each\n * plugin invocation, enabling hot reload when the file changes.\n *\n * This option is JSON-serializable and is the primary way Turbopack\n * passes config to the Babel plugin (since Turbopack loader options\n * must be plain primitives/objects/arrays).\n *\n * When both `config` and `configFile` are set, `config` takes precedence.\n *\n * @example '/absolute/path/to/tasty-zero.config.ts'\n */\n configFile?: string;\n /**\n * Absolute file paths whose content affects the generated CSS.\n * When any of these files change, babel-loader invalidates its cache\n * and re-runs the plugin with fresh config values.\n *\n * Typically includes theme files that define Glaze palettes or token values.\n * Paths must be absolute (resolved by the Next.js wrapper).\n */\n configDeps?: string[];\n /**\n * Automatically replace `@tenphi/tasty/static` imports with an import\n * of the generated CSS file. This eliminates the need for users to\n * manually import the CSS in their app entry point.\n *\n * @default true\n */\n injectImport?: boolean;\n /**\n * Output mode for extracted CSS.\n *\n * - `'file'` (default): CSS is written to a single output file and\n * the `@tenphi/tasty/static` import is rewritten to import that file.\n * - `'inject'`: CSS is embedded inline in the JS output and injected\n * at runtime via a tiny injector from `@tenphi/tasty/static/inject`.\n * No CSS file is written. Each `tastyStatic` call becomes\n * self-contained. Best for reusable components and extensions.\n *\n * When `mode` is `'inject'`, `output` and `injectImport` are ignored.\n *\n * @default 'file'\n */\n mode?: 'file' | 'inject';\n}\n\n/**\n * Registry to track StaticStyle objects by their variable names.\n * Used to resolve base styles when extending.\n */\ntype StaticStyleRegistry = Record<\n string,\n {\n styles: Styles;\n className: string;\n }\n>;\n\ninterface PluginState extends PluginPass {\n staticStyleRegistry: StaticStyleRegistry;\n /** Current source file path (for devMode source comments) */\n sourceFile?: string;\n /** Whether this file added CSS blocks to the writer (via tastyStatic calls) */\n _fileAddedCSS?: boolean;\n}\n\nfunction mtime(filePath: string): number | null {\n try {\n return fs.statSync(filePath).mtimeMs;\n } catch {\n return null;\n }\n}\n\nfunction clearRequireCacheTree(filePath: string): void {\n let resolved: string;\n\n try {\n resolved = require.resolve(filePath);\n } catch {\n return;\n }\n\n const mod = require.cache[resolved];\n\n if (!mod) return;\n\n const dir = resolved.substring(0, resolved.lastIndexOf('/'));\n\n if (mod.children) {\n for (const child of mod.children) {\n if (child.id.startsWith(dir) && !child.id.includes('node_modules')) {\n clearRequireCacheTree(child.id);\n }\n }\n }\n\n delete require.cache[resolved];\n}\n\n// Shared CSSWriter cache keyed by resolved output path.\n// Persists across per-file Babel invocations (Turbopack model) so that\n// CSS from all files accumulates instead of being overwritten.\ninterface WriterCacheEntry {\n writer: CSSWriter;\n configKey: string;\n registry: StaticStyleRegistry;\n config: TastyZeroConfig;\n}\nconst writerCache = new Map<string, WriterCacheEntry>();\n\n/** Clear the shared CSSWriter cache. Exposed for testing. */\nexport function clearWriterCache(): void {\n writerCache.clear();\n}\n\n// @ts-expect-error PluginState vs PluginPass type mismatch in @babel/helper-plugin-utils\nexport default declare<TastyZeroBabelOptions>((api, options) => {\n api.assertVersion(7);\n\n const mode = options.mode ?? 'file';\n const outputPath = options.output || 'tasty.css';\n const resolvedOutputPath = path.resolve(outputPath);\n const injectImport = options.injectImport ?? true;\n\n if (mode === 'file' && injectImport) {\n const dir = path.dirname(resolvedOutputPath);\n\n if (!fs.existsSync(dir)) {\n fs.mkdirSync(dir, { recursive: true });\n }\n\n if (!fs.existsSync(resolvedOutputPath)) {\n fs.writeFileSync(\n resolvedOutputPath,\n '/* Generated by @tenphi/tasty/zero - DO NOT EDIT */\\n',\n );\n }\n }\n\n const configDeps = [\n ...(options.configFile ? [options.configFile] : []),\n ...(options.configDeps || []),\n ];\n\n // Fingerprint for config deps — used to detect config changes\n // and invalidate the shared CSSWriter cache.\n const configKey =\n configDeps.length > 0 ? configDeps.map(mtime).join(',') : '';\n\n // Register external dependencies for babel-loader cache invalidation.\n // When any configDeps file changes, babel-loader discards the cached\n // transform result and re-runs the plugin, picking up fresh config.\n if (configDeps.length > 0) {\n api.cache.using(() => configKey);\n\n for (const dep of configDeps) {\n try {\n (\n api as unknown as { addExternalDependency(path: string): void }\n ).addExternalDependency(dep);\n } catch {\n // addExternalDependency may not be available in all environments\n }\n }\n } else {\n api.cache.forever();\n }\n\n // When configDeps are set, clear the require cache so we get fresh values.\n if (configDeps.length > 0) {\n for (const dep of configDeps) {\n clearRequireCacheTree(dep);\n }\n }\n\n // Look up or create the shared CSSWriter for this output path.\n // When config deps change (different configKey), discard the old writer\n // and reset pipeline state so configure() can run again.\n const cached = writerCache.get(resolvedOutputPath);\n const configChanged = !cached || cached.configKey !== configKey;\n\n if (configChanged) {\n const configOption = options.config;\n let resolvedConfig: TastyZeroConfig;\n\n if (configOption) {\n resolvedConfig =\n typeof configOption === 'function' ? configOption() : configOption;\n } else if (options.configFile) {\n const jiti = createJiti(path.dirname(options.configFile), {\n moduleCache: false,\n });\n\n const loaded = jiti(options.configFile) as\n | TastyZeroConfig\n | { default: TastyZeroConfig };\n // jiti returns the ESM namespace, so unwrap `default` when present.\n resolvedConfig =\n loaded && typeof loaded === 'object' && 'default' in loaded\n ? (loaded.default as TastyZeroConfig)\n : (loaded as TastyZeroConfig);\n } else {\n resolvedConfig = {};\n }\n\n const devMode = resolvedConfig.devMode ?? false;\n\n if (cached) {\n resetConfig();\n }\n\n // Default to the zero-runtime prefix ('ts') unless the user opts out.\n // Using the same `namePrefix` config entry as the runtime keeps the\n // API uniform; the different default prevents collisions when both\n // runtime and zero-runtime classes appear on the same page.\n const finalConfig: TastyZeroConfig = {\n namePrefix: DEFAULT_ZERO_NAME_PREFIX,\n ...resolvedConfig,\n };\n\n configure(finalConfig);\n setExtractorNamePrefix(finalConfig.namePrefix ?? DEFAULT_ZERO_NAME_PREFIX);\n\n const newWriter = new CSSWriter(outputPath, { devMode });\n\n // Emit configured tokens and global styles (file mode only;\n // inject mode handles injection per-file in the post hook).\n if (mode !== 'inject') {\n const tokenCSS = extractCSSFromStyles(':root', getGlobalConfigTokens());\n if (tokenCSS) newWriter.add(':root:tokens', tokenCSS);\n\n const globalStyles = getGlobalStyles();\n if (globalStyles) {\n for (const [selector, styles] of Object.entries(globalStyles)) {\n const css = extractCSSFromStyles(selector, styles);\n if (css) newWriter.add(`global:${selector}`, css);\n }\n }\n }\n\n writerCache.set(resolvedOutputPath, {\n writer: newWriter,\n configKey,\n registry: {},\n config: finalConfig,\n });\n }\n\n const entry = writerCache.get(resolvedOutputPath)!;\n const cssWriter = entry.writer;\n const globalRegistry = entry.registry;\n const config = entry.config;\n const devMode = config.devMode ?? false;\n // When the writer entry was reused from a previous Babel invocation\n // (configChanged=false), make sure the extractor's module-level prefix\n // still matches this build's config — module state can outlive a\n // single configure() call across worker reuse.\n setExtractorNamePrefix(config.namePrefix ?? DEFAULT_ZERO_NAME_PREFIX);\n\n // Precompute token CSS and global styles CSS for inject mode\n let tokenCSS: string | undefined;\n let globalStylesCSS: Map<string, string> | undefined;\n if (mode === 'inject') {\n tokenCSS = extractCSSFromStyles(':root', getGlobalConfigTokens());\n const gs = getGlobalStyles();\n if (gs) {\n globalStylesCSS = new Map();\n for (const [selector, styles] of Object.entries(gs)) {\n const css = extractCSSFromStyles(selector, styles);\n if (css) globalStylesCSS.set(selector, css);\n }\n if (globalStylesCSS.size === 0) globalStylesCSS = undefined;\n }\n }\n\n return {\n name: 'tasty-zero',\n\n pre(this: PluginState) {\n // Initialize per-file registry\n this.staticStyleRegistry = {};\n this._fileAddedCSS = false;\n // Extract source filename for devMode comments\n if (devMode && this.filename) {\n // Get relative path or just filename\n this.sourceFile = this.filename.split('/').pop() || this.filename;\n }\n },\n\n visitor: {\n ImportDeclaration(\n nodePath: NodePath<t.ImportDeclaration>,\n state: PluginState,\n ) {\n const source = nodePath.node.source.value;\n\n if (\n source === '@tenphi/tasty/static' ||\n source.endsWith('/tasty/static')\n ) {\n if (mode === 'inject') {\n nodePath.replaceWith(\n t.importDeclaration(\n [\n t.importSpecifier(\n t.identifier('_$i'),\n t.identifier('injectCSS'),\n ),\n ],\n t.stringLiteral('@tenphi/tasty/static/inject'),\n ),\n );\n } else if (injectImport) {\n let importPath = resolvedOutputPath;\n\n if (state.filename) {\n const sourceDir = path.dirname(state.filename);\n importPath = path.relative(sourceDir, resolvedOutputPath);\n\n if (!importPath.startsWith('.')) {\n importPath = './' + importPath;\n }\n }\n\n nodePath.replaceWith(\n t.importDeclaration([], t.stringLiteral(importPath)),\n );\n } else {\n nodePath.remove();\n }\n }\n },\n\n // Transform tastyStatic() calls\n CallExpression(path: NodePath<t.CallExpression>, state: PluginState) {\n const callee = path.node.callee;\n\n // Match tastyStatic(...) calls\n if (!t.isIdentifier(callee, { name: 'tastyStatic' })) {\n return;\n }\n\n state._fileAddedCSS = true;\n\n const args = path.node.arguments;\n\n if (args.length === 0) {\n throw path.buildCodeFrameError(\n 'tastyStatic() requires at least one argument',\n );\n }\n\n const firstArg = args[0];\n\n if (t.isStringLiteral(firstArg)) {\n // Selector mode: tastyStatic(selector, styles)\n handleSelectorMode(\n path,\n args,\n cssWriter,\n mode,\n state.sourceFile,\n config.keyframes,\n config.autoPropertyTypes,\n config.fontFace,\n config.counterStyle,\n );\n } else if (t.isObjectExpression(firstArg)) {\n // Styles mode: tastyStatic(styles)\n handleStylesMode(\n path,\n args,\n cssWriter,\n state,\n globalRegistry,\n mode,\n config.keyframes,\n config.autoPropertyTypes,\n config.fontFace,\n config.counterStyle,\n );\n } else if (t.isIdentifier(firstArg)) {\n // Extension mode: tastyStatic(base, styles)\n handleExtensionMode(\n path,\n args,\n cssWriter,\n state,\n globalRegistry,\n mode,\n config.keyframes,\n config.autoPropertyTypes,\n config.fontFace,\n config.counterStyle,\n );\n } else {\n throw path.buildCodeFrameError(\n 'tastyStatic() first argument must be an object (styles), ' +\n 'identifier (base StaticStyle), or string (selector)',\n );\n }\n },\n\n // Track variable declarations to register StaticStyle objects\n VariableDeclarator(\n path: NodePath<t.VariableDeclarator>,\n state: PluginState,\n ) {\n const init = path.node.init;\n const id = path.node.id;\n\n // Check if this is a StaticStyle object (has className and styles properties)\n if (\n t.isIdentifier(id) &&\n t.isObjectExpression(init) &&\n isStaticStyleObject(init)\n ) {\n const variableName = id.name;\n const styles = extractStylesFromStaticStyleObject(init, path);\n const className = extractClassNameFromStaticStyleObject(init);\n\n if (styles && className) {\n state.staticStyleRegistry[variableName] = { styles, className };\n globalRegistry[variableName] = { styles, className };\n }\n }\n },\n },\n\n post(this: PluginState) {\n if (mode === 'inject') {\n // In inject mode, inject token/global CSS as top-level statements\n // when this file had tastyStatic calls and config CSS exists.\n if (this._fileAddedCSS && (tokenCSS || globalStylesCSS)) {\n const program = this.file.ast.program;\n\n // Find the position after the inject import\n let insertIndex = 0;\n for (let i = 0; i < program.body.length; i++) {\n if (t.isImportDeclaration(program.body[i])) {\n insertIndex = i + 1;\n }\n }\n\n if (tokenCSS) {\n const injectCall = createInjectCallAST(':root', tokenCSS);\n program.body.splice(\n insertIndex,\n 0,\n t.expressionStatement(injectCall),\n );\n insertIndex++;\n }\n\n if (globalStylesCSS) {\n for (const [selector, css] of globalStylesCSS) {\n const injectCall = createInjectCallAST(selector, css);\n program.body.splice(\n insertIndex,\n 0,\n t.expressionStatement(injectCall),\n );\n insertIndex++;\n }\n }\n }\n return;\n }\n\n // Only write when this file contributed CSS (had tastyStatic calls).\n // In Turbopack, separate workers each have their own CSSWriter with\n // only token CSS. Letting those workers write would overwrite the\n // complete CSS produced by the worker that processed tastyStatic files.\n if (this._fileAddedCSS && cssWriter.size > 0) {\n cssWriter.write();\n }\n },\n };\n});\n\n/**\n * Check if an object expression looks like a StaticStyle object\n */\nfunction isStaticStyleObject(node: t.ObjectExpression): boolean {\n const hasClassName = node.properties.some(\n (p) =>\n t.isObjectProperty(p) && t.isIdentifier(p.key, { name: 'className' }),\n );\n const hasStyles = node.properties.some(\n (p) => t.isObjectProperty(p) && t.isIdentifier(p.key, { name: 'styles' }),\n );\n return hasClassName && hasStyles;\n}\n\n/**\n * Extract styles object from a StaticStyle object expression\n */\nfunction extractStylesFromStaticStyleObject(\n node: t.ObjectExpression,\n path: NodePath,\n): Styles | null {\n for (const prop of node.properties) {\n if (\n t.isObjectProperty(prop) &&\n t.isIdentifier(prop.key, { name: 'styles' }) &&\n t.isObjectExpression(prop.value)\n ) {\n return evaluateObjectExpression(prop.value, path) as Styles;\n }\n }\n return null;\n}\n\n/**\n * Extract className from a StaticStyle object expression\n */\nfunction extractClassNameFromStaticStyleObject(\n node: t.ObjectExpression,\n): string | null {\n for (const prop of node.properties) {\n if (\n t.isObjectProperty(prop) &&\n t.isIdentifier(prop.key, { name: 'className' }) &&\n t.isStringLiteral(prop.value)\n ) {\n return prop.value.value;\n }\n }\n return null;\n}\n\n/**\n * Handle tastyStatic(styles) - returns StaticStyle object\n */\nfunction handleStylesMode(\n path: NodePath<t.CallExpression>,\n args: t.CallExpression['arguments'],\n cssWriter: CSSWriter,\n state: PluginState,\n globalRegistry: StaticStyleRegistry,\n mode: 'file' | 'inject',\n globalKeyframes?: Record<string, KeyframesSteps>,\n autoPropertyTypes?: boolean,\n globalFontFace?: Record<string, FontFaceInput>,\n globalCounterStyle?: Record<string, CounterStyleDescriptors>,\n): void {\n const stylesArg = args[0];\n\n if (!t.isObjectExpression(stylesArg)) {\n throw path.buildCodeFrameError(\n 'tastyStatic(styles) argument must be a static object literal',\n );\n }\n\n // Evaluate styles object at build time\n const rawStyles = evaluateObjectExpression(stylesArg, path) as Styles;\n\n // Resolve recipes before extraction\n const styles = resolveRecipes(rawStyles);\n\n // Extract keyframes (deduplicated by content)\n const { keyframes, nameMap } = extractKeyframesFromStyles(\n styles,\n globalKeyframes,\n );\n\n // Extract and add auto-inferred @property rules\n const properties = extractPropertiesFromStyles(styles, { autoPropertyTypes });\n\n // Extract @font-face rules\n const fontFaces = extractFontFaceFromStyles(styles, globalFontFace);\n\n // Extract @counter-style rules\n const counterStyles = extractCounterStyleFromStyles(\n styles,\n globalCounterStyle,\n );\n\n // Extract styles with chunking\n const chunks = extractStylesWithChunks(styles);\n\n const className =\n chunks.length > 0 ? chunks.map((c) => c.className).join(' ') : '';\n const staticStyleObject = createStaticStyleAST(className, styles);\n\n if (mode === 'inject') {\n const allCSS = collectAllCSS(\n keyframes,\n properties,\n fontFaces,\n counterStyles,\n chunks,\n nameMap,\n );\n const injectCall = createInjectCallAST(className, allCSS);\n\n path.replaceWith(t.sequenceExpression([injectCall, staticStyleObject]));\n } else {\n writeCSSToWriter(\n cssWriter,\n keyframes,\n properties,\n fontFaces,\n counterStyles,\n chunks,\n nameMap,\n state.sourceFile,\n );\n path.replaceWith(staticStyleObject);\n }\n\n registerIfVariableDeclaration(path, className, styles, state, globalRegistry);\n}\n\n/**\n * Handle tastyStatic(base, styles) - extends base with additional styles\n */\nfunction handleExtensionMode(\n path: NodePath<t.CallExpression>,\n args: t.CallExpression['arguments'],\n cssWriter: CSSWriter,\n state: PluginState,\n globalRegistry: StaticStyleRegistry,\n mode: 'file' | 'inject',\n globalKeyframes?: Record<string, KeyframesSteps>,\n autoPropertyTypes?: boolean,\n globalFontFace?: Record<string, FontFaceInput>,\n globalCounterStyle?: Record<string, CounterStyleDescriptors>,\n): void {\n if (args.length < 2) {\n throw path.buildCodeFrameError(\n 'tastyStatic(base, styles) requires two arguments',\n );\n }\n\n const baseArg = args[0];\n const stylesArg = args[1];\n\n if (!t.isIdentifier(baseArg)) {\n throw path.buildCodeFrameError(\n 'tastyStatic(base, styles) first argument must be an identifier',\n );\n }\n\n if (!t.isObjectExpression(stylesArg)) {\n throw path.buildCodeFrameError(\n 'tastyStatic(base, styles) second argument must be a static object literal',\n );\n }\n\n const baseName = baseArg.name;\n\n // Look up base styles in registry\n const baseEntry =\n state.staticStyleRegistry[baseName] || globalRegistry[baseName];\n\n if (!baseEntry) {\n throw path.buildCodeFrameError(\n `Cannot find base StaticStyle '${baseName}'. ` +\n 'Make sure it is defined before being extended.',\n );\n }\n\n // Evaluate override styles\n const overrideStyles = evaluateObjectExpression(stylesArg, path) as Styles;\n\n // Merge styles using mergeStyles, then resolve recipes\n const mergedStyles = resolveRecipes(\n mergeStyles(baseEntry.styles, overrideStyles),\n );\n\n // Extract keyframes (deduplicated by content)\n const { keyframes, nameMap } = extractKeyframesFromStyles(\n mergedStyles,\n globalKeyframes,\n );\n\n // Extract auto-inferred @property rules\n const properties = extractPropertiesFromStyles(mergedStyles, {\n autoPropertyTypes,\n });\n\n // Extract @font-face rules\n const fontFaces = extractFontFaceFromStyles(mergedStyles, globalFontFace);\n\n // Extract @counter-style rules\n const counterStyles = extractCounterStyleFromStyles(\n mergedStyles,\n globalCounterStyle,\n );\n\n // Extract styles with chunking\n const chunks = extractStylesWithChunks(mergedStyles);\n\n const className =\n chunks.length > 0 ? chunks.map((c) => c.className).join(' ') : '';\n const staticStyleObject = createStaticStyleAST(className, mergedStyles);\n\n if (mode === 'inject') {\n const allCSS = collectAllCSS(\n keyframes,\n properties,\n fontFaces,\n counterStyles,\n chunks,\n nameMap,\n );\n const injectCall = createInjectCallAST(className, allCSS);\n\n path.replaceWith(t.sequenceExpression([injectCall, staticStyleObject]));\n } else {\n writeCSSToWriter(\n cssWriter,\n keyframes,\n properties,\n fontFaces,\n counterStyles,\n chunks,\n nameMap,\n state.sourceFile,\n );\n path.replaceWith(staticStyleObject);\n }\n\n registerIfVariableDeclaration(\n path,\n className,\n mergedStyles,\n state,\n globalRegistry,\n );\n}\n\n/**\n * Handle tastyStatic(selector, styles) - removes the call entirely\n */\nfunction handleSelectorMode(\n path: NodePath<t.CallExpression>,\n args: t.CallExpression['arguments'],\n cssWriter: CSSWriter,\n mode: 'file' | 'inject',\n sourceFile?: string,\n globalKeyframes?: Record<string, KeyframesSteps>,\n autoPropertyTypes?: boolean,\n globalFontFace?: Record<string, FontFaceInput>,\n globalCounterStyle?: Record<string, CounterStyleDescriptors>,\n): void {\n if (args.length < 2) {\n throw path.buildCodeFrameError(\n 'tastyStatic(selector, styles) requires two arguments',\n );\n }\n\n const selectorArg = args[0];\n const stylesArg = args[1];\n\n if (!t.isStringLiteral(selectorArg)) {\n throw path.buildCodeFrameError(\n 'tastyStatic(selector, styles) first argument must be a string literal',\n );\n }\n\n if (!t.isObjectExpression(stylesArg)) {\n throw path.buildCodeFrameError(\n 'tastyStatic(selector, styles) second argument must be a static object literal',\n );\n }\n\n const selector = selectorArg.value;\n const rawStyles = evaluateObjectExpression(stylesArg, path) as Styles;\n\n // Resolve recipes before extraction\n const styles = resolveRecipes(rawStyles);\n\n // Extract keyframes (deduplicated by content)\n const { keyframes, nameMap } = extractKeyframesFromStyles(\n styles,\n globalKeyframes,\n );\n\n // Extract auto-inferred @property rules\n const properties = extractPropertiesFromStyles(styles, { autoPropertyTypes });\n\n // Extract @font-face rules\n const fontFaces = extractFontFaceFromStyles(styles, globalFontFace);\n\n // Extract @counter-style rules\n const counterStyles = extractCounterStyleFromStyles(\n styles,\n globalCounterStyle,\n );\n\n // Extract styles for selector\n const result = extractStylesForSelector(selector, styles);\n\n const selectorCSS =\n nameMap.size > 0\n ? replaceAnimationNamesInCSS(result.css, nameMap)\n : result.css;\n\n if (mode === 'inject') {\n const cssParts: string[] = [];\n\n for (const kf of keyframes) cssParts.push(kf.css);\n for (const prop of properties) cssParts.push(prop.css);\n for (const ff of fontFaces) cssParts.push(ff.css);\n for (const cs of counterStyles) cssParts.push(cs.css);\n cssParts.push(selectorCSS);\n\n const injectCall = createInjectCallAST(selector, cssParts.join('\\n'));\n\n const parent = path.parentPath;\n if (parent && t.isExpressionStatement(parent.node)) {\n parent.replaceWith(t.expressionStatement(injectCall));\n } else {\n path.replaceWith(injectCall);\n }\n } else {\n writeCSSToWriter(\n cssWriter,\n keyframes,\n properties,\n fontFaces,\n counterStyles,\n [],\n nameMap,\n sourceFile,\n );\n cssWriter.add(selector, selectorCSS, sourceFile);\n\n const parent = path.parentPath;\n if (parent && t.isExpressionStatement(parent.node)) {\n parent.remove();\n } else {\n path.replaceWith(t.identifier('undefined'));\n }\n }\n}\n\n/**\n * Collect all extracted CSS parts into a single string (for inject mode).\n */\nfunction collectAllCSS(\n keyframes: ExtractedKeyframes[],\n properties: ExtractedProperty[],\n fontFaces: ExtractedFontFace[],\n counterStyles: ExtractedCounterStyle[],\n chunks: ExtractedChunk[],\n nameMap: Map<string, string>,\n): string {\n const parts: string[] = [];\n\n for (const kf of keyframes) parts.push(kf.css);\n for (const prop of properties) parts.push(prop.css);\n for (const ff of fontFaces) parts.push(ff.css);\n for (const cs of counterStyles) parts.push(cs.css);\n\n for (const chunk of chunks) {\n parts.push(\n nameMap.size > 0\n ? replaceAnimationNamesInCSS(chunk.css, nameMap)\n : chunk.css,\n );\n }\n\n return parts.join('\\n');\n}\n\n/**\n * Write all extracted CSS parts to a CSSWriter (for file mode).\n */\nfunction writeCSSToWriter(\n cssWriter: CSSWriter,\n keyframes: ExtractedKeyframes[],\n properties: ExtractedProperty[],\n fontFaces: ExtractedFontFace[],\n counterStyles: ExtractedCounterStyle[],\n chunks: ExtractedChunk[],\n nameMap: Map<string, string>,\n sourceFile?: string,\n): void {\n for (const kf of keyframes) {\n cssWriter.add(kf.css, kf.css, sourceFile);\n }\n for (const prop of properties) {\n cssWriter.add(prop.css, prop.css, sourceFile);\n }\n for (const ff of fontFaces) {\n cssWriter.add(ff.css, ff.css, sourceFile);\n }\n for (const cs of counterStyles) {\n cssWriter.add(cs.css, cs.css, sourceFile);\n }\n\n for (const chunk of chunks) {\n const css =\n nameMap.size > 0\n ? replaceAnimationNamesInCSS(chunk.css, nameMap)\n : chunk.css;\n cssWriter.add(chunk.className, css, sourceFile);\n }\n}\n\n/**\n * Extract CSS for a selector from a styles/tokens object.\n * Returns undefined when there are no styles or no CSS output.\n */\nfunction extractCSSFromStyles(\n selector: string,\n styles: Styles | ConfigTokens | null,\n): string | undefined {\n if (!styles || Object.keys(styles).length === 0) return undefined;\n const result = extractStylesForSelector(selector, styles as Styles);\n return result.css || undefined;\n}\n\n/**\n * Create an `_$i(id, css)` call expression AST node for inject mode.\n */\nfunction createInjectCallAST(id: string, css: string): t.CallExpression {\n return t.callExpression(t.identifier('_$i'), [\n t.stringLiteral(id),\n t.stringLiteral(css),\n ]);\n}\n\n/**\n * Create a StaticStyle object AST node\n */\nfunction createStaticStyleAST(\n className: string,\n styles: Styles,\n): t.ObjectExpression {\n return t.objectExpression([\n t.objectProperty(t.identifier('className'), t.stringLiteral(className)),\n t.objectProperty(t.identifier('styles'), valueToAST(styles)),\n t.objectMethod(\n 'method',\n t.identifier('toString'),\n [],\n t.blockStatement([\n t.returnStatement(\n t.memberExpression(t.thisExpression(), t.identifier('className')),\n ),\n ]),\n ),\n ]);\n}\n\n/**\n * Register a StaticStyle in the registry if it's being assigned to a variable\n */\nfunction registerIfVariableDeclaration(\n path: NodePath,\n className: string,\n styles: Styles,\n state: PluginState,\n globalRegistry: StaticStyleRegistry,\n): void {\n const parent = path.parentPath;\n if (parent && t.isVariableDeclarator(parent.node)) {\n const id = parent.node.id;\n if (t.isIdentifier(id)) {\n const variableName = id.name;\n state.staticStyleRegistry[variableName] = { styles, className };\n globalRegistry[variableName] = { styles, className };\n }\n }\n}\n\n/**\n * Convert a JavaScript value to an AST node\n */\nfunction valueToAST(value: unknown): t.Expression {\n if (value === null) {\n return t.nullLiteral();\n }\n if (value === undefined) {\n return t.identifier('undefined');\n }\n if (typeof value === 'string') {\n return t.stringLiteral(value);\n }\n if (typeof value === 'number') {\n return t.numericLiteral(value);\n }\n if (typeof value === 'boolean') {\n return t.booleanLiteral(value);\n }\n if (Array.isArray(value)) {\n return t.arrayExpression(value.map(valueToAST));\n }\n if (typeof value === 'object') {\n const properties = Object.entries(value).map(([key, val]) =>\n t.objectProperty(\n /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key)\n ? t.identifier(key)\n : t.stringLiteral(key),\n valueToAST(val),\n ),\n );\n return t.objectExpression(properties);\n }\n // Fallback for unsupported types\n return t.identifier('undefined');\n}\n\n/**\n * Evaluate an ObjectExpression to a plain JavaScript object.\n * Only supports static values that can be determined at build time.\n */\nfunction evaluateObjectExpression(\n node: t.ObjectExpression,\n path: NodePath,\n): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n\n for (const prop of node.properties) {\n if (t.isSpreadElement(prop)) {\n throw path.buildCodeFrameError(\n 'Spread elements are not supported in tastyStatic() - styles must be fully static',\n );\n }\n\n if (!t.isObjectProperty(prop)) {\n throw path.buildCodeFrameError(\n 'Only object properties are supported in tastyStatic()',\n );\n }\n\n // Get key\n let key: string;\n if (t.isIdentifier(prop.key)) {\n key = prop.key.name;\n } else if (t.isStringLiteral(prop.key)) {\n key = prop.key.value;\n } else {\n throw path.buildCodeFrameError(\n 'Dynamic property keys are not supported in tastyStatic()',\n );\n }\n\n // Get value\n const value = evaluateExpression(prop.value, path);\n result[key] = value;\n }\n\n return result;\n}\n\n/**\n * Evaluate an expression to a JavaScript value.\n */\nfunction evaluateExpression(node: t.Node, path: NodePath): unknown {\n if (t.isStringLiteral(node)) {\n return node.value;\n }\n\n if (t.isNumericLiteral(node)) {\n return node.value;\n }\n\n if (t.isBooleanLiteral(node)) {\n return node.value;\n }\n\n if (t.isNullLiteral(node)) {\n return null;\n }\n\n if (t.isIdentifier(node, { name: 'undefined' })) {\n return undefined;\n }\n\n if (t.isArrayExpression(node)) {\n return node.elements.map((el) => {\n if (el === null) return null;\n if (t.isSpreadElement(el)) {\n throw path.buildCodeFrameError(\n 'Spread elements are not supported in tastyStatic()',\n );\n }\n return evaluateExpression(el, path);\n });\n }\n\n if (t.isObjectExpression(node)) {\n return evaluateObjectExpression(node, path);\n }\n\n if (t.isTemplateLiteral(node)) {\n // Only support template literals without expressions\n if (node.expressions.length > 0) {\n throw path.buildCodeFrameError(\n 'Template literals with expressions are not supported in tastyStatic()',\n );\n }\n return node.quasis.map((q) => q.value.cooked).join('');\n }\n\n if (t.isUnaryExpression(node, { operator: '-' })) {\n const arg = evaluateExpression(node.argument, path);\n if (typeof arg === 'number') {\n return -arg;\n }\n }\n\n throw path.buildCodeFrameError(\n `Dynamic expressions are not supported in tastyStatic() - got ${node.type}. ` +\n 'All values must be static literals.',\n );\n}\n\n/**\n * Replace animation names in CSS string.\n * Wraps the keyframes replaceAnimationNames to work on full CSS blocks.\n */\nfunction replaceAnimationNamesInCSS(\n css: string,\n nameMap: Map<string, string>,\n): string {\n if (nameMap.size === 0) return css;\n\n // The CSS contains full rules like \".class { animation: name 1s; }\"\n // We need to replace animation names within declaration blocks\n return css.replace(\n /(animation(?:-name)?)\\s*:\\s*([^;}]+)/gi,\n (match, prop, value) => {\n let newValue = value;\n for (const [original, replacement] of nameMap) {\n // Word boundary replacement\n const pattern = new RegExp(`\\\\b${escapeRegex(original)}\\\\b`, 'g');\n newValue = newValue.replace(pattern, replacement);\n }\n return `${prop}: ${newValue}`;\n },\n );\n}\n\n/**\n * Escape special regex characters.\n */\nfunction escapeRegex(str: string): string {\n return str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8JA,SAAS,MAAM,UAAiC;AAC9C,KAAI;AACF,SAAO,GAAG,SAAS,SAAS,CAAC;SACvB;AACN,SAAO;;;AAIX,SAAS,sBAAsB,UAAwB;CACrD,IAAI;AAEJ,KAAI;AACF,aAAA,UAAmB,QAAQ,SAAS;SAC9B;AACN;;CAGF,MAAM,MAAA,UAAc,MAAM;AAE1B,KAAI,CAAC,IAAK;CAEV,MAAM,MAAM,SAAS,UAAU,GAAG,SAAS,YAAY,IAAI,CAAC;AAE5D,KAAI,IAAI;OACD,MAAM,SAAS,IAAI,SACtB,KAAI,MAAM,GAAG,WAAW,IAAI,IAAI,CAAC,MAAM,GAAG,SAAS,eAAe,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as extractStylesWithChunks, t as CSSWriter } from "../css-writer-
|
|
1
|
+
import { o as extractStylesForSelector, s as extractStylesWithChunks, t as CSSWriter } from "../css-writer-jWRnDIy6.js";
|
|
2
2
|
export { CSSWriter, extractStylesForSelector, extractStylesWithChunks };
|
package/docs/configuration.md
CHANGED
|
@@ -61,6 +61,7 @@ These docs use `data-schema="dark"` in examples. If your app already standardize
|
|
|
61
61
|
| `presets` | `Record<string, TypographyPreset>` | - | Typography presets — shorthand for `generateTypographyTokens()` |
|
|
62
62
|
| `globalStyles` | `Record<string, Styles>` | - | Global Tasty styles keyed by CSS selector |
|
|
63
63
|
| `colorSpace` | `'rgb' \| 'hsl' \| 'oklch'` | `'oklch'` | Color space for decomposed color token companion variables |
|
|
64
|
+
| `namePrefix` | `string` | `'t'` (runtime) / `'ts'` (zero-runtime) | Prefix prepended to every generated identifier (class, keyframe, counter-style names). See [Name prefix](#name-prefix). |
|
|
64
65
|
|
|
65
66
|
---
|
|
66
67
|
|
|
@@ -84,6 +85,49 @@ The `oklch` color space is the default because it provides perceptually uniform
|
|
|
84
85
|
|
|
85
86
|
---
|
|
86
87
|
|
|
88
|
+
## Name Prefix
|
|
89
|
+
|
|
90
|
+
Every identifier Tasty generates — class names, keyframe names, counter-style names — starts with a configurable prefix. The runtime, SSR, and RSC paths default to `'t'`; the zero-runtime build path (`tastyStatic` via the Babel plugin) defaults to `'ts'` so static-extracted classes can never collide with runtime classes when both are loaded on the same page.
|
|
91
|
+
|
|
92
|
+
```jsx
|
|
93
|
+
configure({
|
|
94
|
+
namePrefix: 'mb',
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
The prefix is prepended verbatim to the hash, so include any separator inside the prefix string itself:
|
|
99
|
+
|
|
100
|
+
| Setting | Class | Keyframe | Counter-style |
|
|
101
|
+
|---|---|---|---|
|
|
102
|
+
| `'t'` (runtime default) | `t1a2b3` | `tk1a2b3` | `tc1a2b3` |
|
|
103
|
+
| `'ts'` (zero-runtime default) | `ts1a2b3` | `tsk1a2b3` | `tsc1a2b3` |
|
|
104
|
+
| `'mb'` | `mb1a2b3` | `mbk1a2b3` | `mbc1a2b3` |
|
|
105
|
+
| `'myapp-'` | `myapp-1a2b3` | `myapp-k1a2b3` | `myapp-c1a2b3` |
|
|
106
|
+
|
|
107
|
+
The single-letter discriminators (`k` for keyframes, `c` for counter-styles) keep the three kinds visually distinct in devtools — they are not required for correctness because CSS keeps these in separate namespaces.
|
|
108
|
+
|
|
109
|
+
### Rules
|
|
110
|
+
|
|
111
|
+
- Must match `^[a-zA-Z_][a-zA-Z0-9_-]{0,31}$`. Examples that pass: `'t'`, `'ts'`, `'app'`, `'myapp-'`, `'_foo'`. Examples that fail: `''`, `'1foo'`, `'my app'`.
|
|
112
|
+
- Validated at `configure()` time; an invalid prefix throws synchronously rather than silently producing broken hydration.
|
|
113
|
+
- Locked once styles have been generated, like all other config.
|
|
114
|
+
|
|
115
|
+
### Coexistence with the zero-runtime build
|
|
116
|
+
|
|
117
|
+
The runtime and zero-runtime builds **must use different prefixes** when both are loaded on the same page. Defaults already guarantee this; if you customize one, customize the other accordingly:
|
|
118
|
+
|
|
119
|
+
```jsx
|
|
120
|
+
// app config (runtime / SSR / RSC)
|
|
121
|
+
configure({ namePrefix: 'mb' });
|
|
122
|
+
|
|
123
|
+
// tasty-zero.config.ts (Babel plugin)
|
|
124
|
+
export default { namePrefix: 'mbs' };
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
If you only use one of the two builds, you only need to set `namePrefix` on that path.
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
87
131
|
## Design Tokens
|
|
88
132
|
|
|
89
133
|
Design tokens define CSS custom properties on `:root`. They are injected automatically when the first style is rendered. Values are parsed through the Tasty DSL, so you can use units, color syntax, and other DSL features.
|
package/docs/dsl.md
CHANGED
|
@@ -52,22 +52,23 @@ styles: { Title: { preset: 'h3' } }
|
|
|
52
52
|
|
|
53
53
|
#### Selector Affix (`$`)
|
|
54
54
|
|
|
55
|
-
Control how a sub-element selector attaches to the root selector using the `$` property inside the sub-element's styles
|
|
55
|
+
Control how a sub-element selector attaches to the root selector using the `$` property inside the sub-element's styles.
|
|
56
|
+
|
|
57
|
+
Examples below assume the sub-element key is **Cell** (i.e. `[data-element="Cell"]` in CSS):
|
|
56
58
|
|
|
57
59
|
| Pattern | Result | Description |
|
|
58
60
|
|---------|--------|-------------|
|
|
59
|
-
| *(none)* | `
|
|
60
|
-
| `>` | `> [
|
|
61
|
-
| `>Body
|
|
62
|
-
| `>
|
|
63
|
-
| `h1` | `
|
|
64
|
-
| `h1 >` | `
|
|
65
|
-
| `h1 *` | `
|
|
66
|
-
| `*` |
|
|
67
|
-
|
|
|
68
|
-
| `@::before` | `[
|
|
69
|
-
|
|
|
70
|
-
| `>@.active` | `> [el].active` | Class on the sub-element |
|
|
61
|
+
| *(none)* | `[data-element="Cell"]` | Descendant (default) |
|
|
62
|
+
| `>` | `> [data-element="Cell"]` | Direct child |
|
|
63
|
+
| `>Body>` | `> [data-element="Body"] > [data-element="Cell"]` | Chained elements |
|
|
64
|
+
| `> Cell` | `> [data-element="Cell"]` | Self-name shorthand — when the trailing element name matches the sub-element's own key, it acts as the placeholder (same as `@`); no duplication |
|
|
65
|
+
| `h1` | `h1` | Tag selector (no key injection) |
|
|
66
|
+
| `h1 >` | `h1 > [data-element="Cell"]` | Key is direct child of tag |
|
|
67
|
+
| `h1 *` | `h1 *` | Any descendant of tag |
|
|
68
|
+
| `*` | `*` | All descendants |
|
|
69
|
+
| `&::before` | `::before` | Root pseudo (no key); `&` is required |
|
|
70
|
+
| `@::before` | `[data-element="Cell"]::before` | Pseudo on the sub-element |
|
|
71
|
+
| `>@.active` | `> [data-element="Cell"].active` | Class on the sub-element |
|
|
71
72
|
|
|
72
73
|
Rules for key injection (`[data-element="..."]`):
|
|
73
74
|
|
package/docs/ssr.md
CHANGED
|
@@ -358,16 +358,18 @@ const stream = await runWithCollector(collector, () =>
|
|
|
358
358
|
|
|
359
359
|
Server-safe style collector. One instance per request.
|
|
360
360
|
|
|
361
|
+
Constructor: `new ServerStyleCollector(namePrefix?)`. The optional `namePrefix` overrides the value from `configure({ namePrefix })`; in normal usage you pass nothing and let the global config drive it. See [Configuration: Name prefix](configuration.md#name-prefix).
|
|
362
|
+
|
|
361
363
|
| Method | Description |
|
|
362
364
|
|---|---|
|
|
363
|
-
| `allocateClassName(cacheKey)` | Allocate a
|
|
365
|
+
| `allocateClassName(cacheKey)` | Allocate a deterministic, content-hashed class name for a cache key (e.g. `t1a2b3` with the default prefix). The same `cacheKey` always produces the same class name on server and client when both share the same `namePrefix`. Returns `{ className, isNewAllocation }`. |
|
|
364
366
|
| `collectChunk(cacheKey, className, rules)` | Record CSS rules for a chunk. Deduplicated by `cacheKey`. |
|
|
365
367
|
| `collectKeyframes(name, css)` | Record a `@keyframes` rule. Deduplicated by name. |
|
|
366
|
-
| `allocateKeyframeName(providedName?)` | Allocate a keyframe name. Returns `providedName` if given, otherwise generates one (`
|
|
368
|
+
| `allocateKeyframeName(providedName?)` | Allocate a keyframe name. Returns `providedName` if given, otherwise generates one using `${namePrefix}k${counter}` (e.g. `tk0`, `tk1`, ...). |
|
|
367
369
|
| `collectProperty(name, css)` | Record a `@property` rule. Deduplicated by name. |
|
|
368
370
|
| `collectFontFace(key, css)` | Record a `@font-face` rule. Deduplicated by content hash. |
|
|
369
371
|
| `collectCounterStyle(name, css)` | Record a `@counter-style` rule. Deduplicated by name. |
|
|
370
|
-
| `allocateCounterStyleName(providedName?)` | Allocate a counter-style name. Returns `providedName` if given, otherwise generates one (`
|
|
372
|
+
| `allocateCounterStyleName(providedName?)` | Allocate a counter-style name. Returns `providedName` if given, otherwise generates one using `${namePrefix}c${counter}` (e.g. `tc0`, `tc1`, ...). |
|
|
371
373
|
| `collectGlobalStyles(key, css)` | Record global styles (from `useGlobalStyles`). Deduplicated by key. |
|
|
372
374
|
| `collectRawCSS(key, css)` | Record raw CSS text (from `useRawCSS`). Deduplicated by key. |
|
|
373
375
|
| `collectInternals()` | Collect internal `@property` rules, `:root` token defaults, `@font-face`, and `@counter-style` rules from the global config. Called automatically on first chunk collection; idempotent. |
|
package/docs/tasty-static.md
CHANGED
|
@@ -178,6 +178,21 @@ module.exports = {
|
|
|
178
178
|
| `config.globalStyles` | `Record<string, Styles>` | — | Global Tasty styles keyed by CSS selector. Supports the full style syntax. |
|
|
179
179
|
| `config.autoPropertyTypes` | `boolean` | `true` | Automatically infer and register CSS `@property` declarations from values |
|
|
180
180
|
| `config.parserCacheSize` | `number` | `1000` | Parser LRU cache size. Larger values improve performance for builds with many unique style values |
|
|
181
|
+
| `config.namePrefix` | `string` | `'ts'` | Prefix prepended to every generated identifier. Defaults to `'ts'` so static classes never collide with runtime (`'t'`) classes. See [Configuration: Name prefix](configuration.md#name-prefix). |
|
|
182
|
+
|
|
183
|
+
### Coexisting with runtime tasty
|
|
184
|
+
|
|
185
|
+
When a page mixes `tastyStatic` with runtime `tasty`, both must use **different** `namePrefix` values. The defaults handle this automatically (`'t'` for runtime, `'ts'` for zero-runtime). If you customize one, customize the other:
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
// tasty-zero.config.ts (Babel plugin)
|
|
189
|
+
export default { namePrefix: 'mbs' };
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
```ts
|
|
193
|
+
// app entry (runtime configure)
|
|
194
|
+
configure({ namePrefix: 'mb' });
|
|
195
|
+
```
|
|
181
196
|
|
|
182
197
|
---
|
|
183
198
|
|
package/package.json
CHANGED
package/tasty.config.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"collector-C4sagPeG.js","names":[],"sources":["../src/ssr/collector.ts"],"sourcesContent":["/**\n * ServerStyleCollector — server-safe style collector for SSR.\n *\n * Accumulates CSS rules and cache metadata during server rendering.\n * This is the server-side counterpart to StyleInjector: it allocates\n * hash-based class names (`t${hash}`), formats CSS rules into text,\n * and tracks rendered class names for lightweight client transfer.\n *\n * One instance is created per HTTP request. Concurrent requests\n * each get their own collector (via AsyncLocalStorage or React context).\n */\n\nimport {\n getEffectiveProperties,\n getGlobalStyles,\n getGlobalCounterStyle,\n getGlobalFontFace,\n getGlobalConfigTokens,\n} from '../config';\nimport { formatCounterStyleRule } from '../counter-style';\nimport { fontFaceContentHash, formatFontFaceRule } from '../font-face';\nimport { renderStyles } from '../pipeline';\nimport type { StyleResult } from '../pipeline';\nimport { hashString } from '../utils/hash';\nimport { formatPropertyCSS } from './format-property';\nimport { formatGlobalRules } from './format-global-rules';\nimport { formatRules } from './format-rules';\n\nfunction generateClassName(cacheKey: string): string {\n return `t${hashString(cacheKey)}`;\n}\n\nexport class ServerStyleCollector {\n private chunks = new Map<string, string>();\n private cacheKeyToClassName = new Map<string, string>();\n private flushedKeys = new Set<string>();\n private propertyRules = new Map<string, string>();\n private flushedPropertyKeys = new Set<string>();\n private keyframeRules = new Map<string, string>();\n private flushedKeyframeKeys = new Set<string>();\n private globalStyles = new Map<string, string>();\n private flushedGlobalKeys = new Set<string>();\n private rawCSS = new Map<string, string>();\n private flushedRawKeys = new Set<string>();\n private fontFaceRules = new Map<string, string>();\n private flushedFontFaceKeys = new Set<string>();\n private counterStyleRules = new Map<string, string>();\n private flushedCounterStyleKeys = new Set<string>();\n private keyframesCounter = 0;\n private counterStyleCounter = 0;\n private internalsCollected = false;\n\n /**\n * Collect internal @property rules and :root token defaults.\n * Mirrors markStylesGenerated() from the client-side injector.\n * Called automatically on first chunk collection; idempotent.\n *\n * Internals are always emitted here — the RSC path deliberately\n * defers to SSR so that tokens appear exactly once per page in\n * <style data-tasty-ssr> (avoiding duplication of large token sets).\n */\n collectInternals(): void {\n if (this.internalsCollected) return;\n this.internalsCollected = true;\n\n for (const [token, definition] of Object.entries(\n getEffectiveProperties(),\n )) {\n const css = formatPropertyCSS(token, definition);\n if (css) {\n this.collectProperty(`__prop:${token}`, css);\n }\n }\n\n const tokenStyles = getGlobalConfigTokens();\n if (tokenStyles && Object.keys(tokenStyles).length > 0) {\n const tokenRules = renderStyles(tokenStyles, ':root') as StyleResult[];\n if (tokenRules.length > 0) {\n const css = formatGlobalRules(tokenRules);\n if (css) {\n this.collectGlobalStyles('__global:tokens', css);\n }\n }\n }\n\n const globalFF = getGlobalFontFace();\n if (globalFF) {\n for (const [family, input] of Object.entries(globalFF)) {\n const descriptors = Array.isArray(input) ? input : [input];\n for (const desc of descriptors) {\n const hash = fontFaceContentHash(family, desc);\n const css = formatFontFaceRule(family, desc);\n this.collectFontFace(hash, css);\n }\n }\n }\n\n const globalCS = getGlobalCounterStyle();\n if (globalCS) {\n for (const [name, descriptors] of Object.entries(globalCS)) {\n const css = formatCounterStyleRule(name, descriptors);\n this.collectCounterStyle(name, css);\n }\n }\n\n const globalStyles = getGlobalStyles();\n if (globalStyles) {\n for (const [selector, styles] of Object.entries(globalStyles)) {\n if (Object.keys(styles).length > 0) {\n const rules = renderStyles(styles, selector) as StyleResult[];\n if (rules.length > 0) {\n const css = formatGlobalRules(rules);\n if (css) {\n this.collectGlobalStyles(`__global:styles:${selector}`, css);\n }\n }\n }\n }\n }\n }\n\n /**\n * Allocate a className for a cache key, server-side.\n * Mirrors StyleInjector.allocateClassName but without DOM access.\n */\n allocateClassName(cacheKey: string): {\n className: string;\n isNewAllocation: boolean;\n } {\n const existing = this.cacheKeyToClassName.get(cacheKey);\n if (existing) {\n return { className: existing, isNewAllocation: false };\n }\n\n const className = generateClassName(cacheKey);\n this.cacheKeyToClassName.set(cacheKey, className);\n\n return { className, isNewAllocation: true };\n }\n\n /**\n * Record CSS rules for a chunk.\n * Called by useStyles during server render.\n */\n collectChunk(\n cacheKey: string,\n className: string,\n rules: StyleResult[],\n ): void {\n if (this.chunks.has(cacheKey)) return;\n const css = formatRules(rules, className);\n if (css) {\n this.chunks.set(cacheKey, css);\n }\n }\n\n /**\n * Record a @property rule. Deduplicated by name.\n */\n collectProperty(name: string, css: string): void {\n if (!this.propertyRules.has(name)) {\n this.propertyRules.set(name, css);\n }\n }\n\n /**\n * Record a @keyframes rule. Deduplicated by name.\n */\n collectKeyframes(name: string, css: string): void {\n if (!this.keyframeRules.has(name)) {\n this.keyframeRules.set(name, css);\n }\n }\n\n /**\n * Allocate a keyframe name for SSR. Uses provided name or generates one.\n */\n allocateKeyframeName(providedName?: string): string {\n return providedName ?? `k${this.keyframesCounter++}`;\n }\n\n /**\n * Record a @font-face rule. Deduplicated by key (content hash).\n */\n collectFontFace(key: string, css: string): void {\n if (!this.fontFaceRules.has(key)) {\n this.fontFaceRules.set(key, css);\n }\n }\n\n /**\n * Record a @counter-style rule. Deduplicated by name.\n */\n collectCounterStyle(name: string, css: string): void {\n if (!this.counterStyleRules.has(name)) {\n this.counterStyleRules.set(name, css);\n }\n }\n\n /**\n * Allocate a counter-style name for SSR. Uses provided name or generates one.\n */\n allocateCounterStyleName(providedName?: string): string {\n return providedName ?? `cs${this.counterStyleCounter++}`;\n }\n\n /**\n * Record global styles (from useGlobalStyles). Deduplicated by key.\n */\n collectGlobalStyles(key: string, css: string): void {\n if (!this.globalStyles.has(key)) {\n this.globalStyles.set(key, css);\n }\n }\n\n /**\n * Record raw CSS text (from useRawCSS). Deduplicated by key.\n */\n collectRawCSS(key: string, css: string): void {\n if (!this.rawCSS.has(key)) {\n this.rawCSS.set(key, css);\n }\n }\n\n /**\n * Extract all CSS collected so far as a single string.\n * Includes @property and @keyframes rules.\n * Used for non-streaming SSR (renderToString).\n */\n getCSS(): string {\n const parts: string[] = [];\n\n for (const css of this.propertyRules.values()) {\n parts.push(css);\n }\n\n for (const css of this.fontFaceRules.values()) {\n parts.push(css);\n }\n\n for (const css of this.counterStyleRules.values()) {\n parts.push(css);\n }\n\n for (const css of this.rawCSS.values()) {\n parts.push(css);\n }\n\n for (const css of this.globalStyles.values()) {\n parts.push(css);\n }\n\n for (const css of this.chunks.values()) {\n parts.push(css);\n }\n\n for (const css of this.keyframeRules.values()) {\n parts.push(css);\n }\n\n return parts.join('\\n');\n }\n\n /**\n * Flush only newly collected CSS since the last flush.\n * Used for streaming SSR (renderToPipeableStream + useServerInsertedHTML).\n */\n flushCSS(): string {\n const parts: string[] = [];\n\n for (const [name, css] of this.propertyRules) {\n if (!this.flushedPropertyKeys.has(name)) {\n parts.push(css);\n this.flushedPropertyKeys.add(name);\n }\n }\n\n for (const [key, css] of this.fontFaceRules) {\n if (!this.flushedFontFaceKeys.has(key)) {\n parts.push(css);\n this.flushedFontFaceKeys.add(key);\n }\n }\n\n for (const [key, css] of this.counterStyleRules) {\n if (!this.flushedCounterStyleKeys.has(key)) {\n parts.push(css);\n this.flushedCounterStyleKeys.add(key);\n }\n }\n\n for (const [key, css] of this.rawCSS) {\n if (!this.flushedRawKeys.has(key)) {\n parts.push(css);\n this.flushedRawKeys.add(key);\n }\n }\n\n for (const [key, css] of this.globalStyles) {\n if (!this.flushedGlobalKeys.has(key)) {\n parts.push(css);\n this.flushedGlobalKeys.add(key);\n }\n }\n\n for (const [key, css] of this.chunks) {\n if (!this.flushedKeys.has(key)) {\n parts.push(css);\n this.flushedKeys.add(key);\n }\n }\n\n for (const [name, css] of this.keyframeRules) {\n if (!this.flushedKeyframeKeys.has(name)) {\n parts.push(css);\n this.flushedKeyframeKeys.add(name);\n }\n }\n\n return parts.join('\\n');\n }\n\n private flushedClassNames = new Set<string>();\n\n /**\n * Return class names rendered since the last call (for streaming).\n * Used to emit lightweight class-list scripts for client hydration.\n */\n getRenderedClassNames(): string[] {\n const names: string[] = [];\n for (const className of this.cacheKeyToClassName.values()) {\n if (!this.flushedClassNames.has(className)) {\n this.flushedClassNames.add(className);\n names.push(className);\n }\n }\n return names;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AA4BA,SAAS,kBAAkB,UAA0B;AACnD,QAAO,IAAI,WAAW,SAAS;;AAGjC,IAAa,uBAAb,MAAkC;CAChC,yBAAiB,IAAI,KAAqB;CAC1C,sCAA8B,IAAI,KAAqB;CACvD,8BAAsB,IAAI,KAAa;CACvC,gCAAwB,IAAI,K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