@tenphi/tasty 0.0.0-snapshot.002b1b3
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/LICENSE +21 -0
- package/README.md +637 -0
- package/dist/async-storage-B7_o6FKt.js +44 -0
- package/dist/async-storage-B7_o6FKt.js.map +1 -0
- package/dist/collector-LuU1vZ68.d.ts +98 -0
- package/dist/collector-MOYY2SOr.js +230 -0
- package/dist/collector-MOYY2SOr.js.map +1 -0
- package/dist/config-A237aY9H.js +10235 -0
- package/dist/config-A237aY9H.js.map +1 -0
- package/dist/config-vuCRkBWX.d.ts +884 -0
- package/dist/context-CkSg-kDT.js +24 -0
- package/dist/context-CkSg-kDT.js.map +1 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.js +6 -0
- package/dist/core-BkKav78f.js +1592 -0
- package/dist/core-BkKav78f.js.map +1 -0
- package/dist/css-writer-Cos9tQRM.js +329 -0
- package/dist/css-writer-Cos9tQRM.js.map +1 -0
- package/dist/format-global-rules-Dbc_1tc3.js +22 -0
- package/dist/format-global-rules-Dbc_1tc3.js.map +1 -0
- package/dist/format-rules-C2oiTsEO.js +143 -0
- package/dist/format-rules-C2oiTsEO.js.map +1 -0
- package/dist/hydrate-miFzWIKR.js +45 -0
- package/dist/hydrate-miFzWIKR.js.map +1 -0
- package/dist/index-CJMXAAO5.d.ts +1602 -0
- package/dist/index-dUtwpOux.d.ts +1266 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +732 -0
- package/dist/index.js.map +1 -0
- package/dist/keyframes-DDtNo_hl.js +587 -0
- package/dist/keyframes-DDtNo_hl.js.map +1 -0
- package/dist/merge-styles-CtDJMhpJ.d.ts +7 -0
- package/dist/merge-styles-D_HbBOlq.js +144 -0
- package/dist/merge-styles-D_HbBOlq.js.map +1 -0
- package/dist/resolve-recipes-B7-823LL.js +144 -0
- package/dist/resolve-recipes-B7-823LL.js.map +1 -0
- package/dist/ssr/astro-client.d.ts +1 -0
- package/dist/ssr/astro-client.js +19 -0
- package/dist/ssr/astro-client.js.map +1 -0
- package/dist/ssr/astro-middleware.d.ts +15 -0
- package/dist/ssr/astro-middleware.js +19 -0
- package/dist/ssr/astro-middleware.js.map +1 -0
- package/dist/ssr/astro.d.ts +97 -0
- package/dist/ssr/astro.js +149 -0
- package/dist/ssr/astro.js.map +1 -0
- package/dist/ssr/index.d.ts +44 -0
- package/dist/ssr/index.js +10 -0
- package/dist/ssr/index.js.map +1 -0
- package/dist/ssr/next.d.ts +46 -0
- package/dist/ssr/next.js +75 -0
- package/dist/ssr/next.js.map +1 -0
- package/dist/static/index.d.ts +91 -0
- package/dist/static/index.js +50 -0
- package/dist/static/index.js.map +1 -0
- package/dist/static/inject.d.ts +5 -0
- package/dist/static/inject.js +17 -0
- package/dist/static/inject.js.map +1 -0
- package/dist/zero/babel.d.ts +81 -0
- package/dist/zero/babel.js +466 -0
- package/dist/zero/babel.js.map +1 -0
- package/dist/zero/index.d.ts +67 -0
- package/dist/zero/index.js +2 -0
- package/dist/zero/next.d.ts +86 -0
- package/dist/zero/next.js +143 -0
- package/dist/zero/next.js.map +1 -0
- package/docs/README.md +31 -0
- package/docs/adoption.md +298 -0
- package/docs/comparison.md +419 -0
- package/docs/configuration.md +394 -0
- package/docs/debug.md +320 -0
- package/docs/design-system.md +436 -0
- package/docs/dsl.md +688 -0
- package/docs/getting-started.md +217 -0
- package/docs/injector.md +544 -0
- package/docs/methodology.md +616 -0
- package/docs/pipeline.md +673 -0
- package/docs/react-api.md +557 -0
- package/docs/ssr.md +442 -0
- package/docs/styles.md +596 -0
- package/docs/tasty-static.md +532 -0
- package/package.json +222 -0
- package/tasty.config.ts +15 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-writer-Cos9tQRM.js","names":[],"sources":["../src/zero/extractor.ts","../src/zero/css-writer.ts"],"sourcesContent":["import { createHash } from 'crypto';\n\nimport {\n categorizeStyleKeys,\n generateChunkCacheKey,\n renderStylesForChunk,\n} from '../chunks';\nimport type {\n CounterStyleDescriptors,\n FontFaceDescriptors,\n FontFaceInput,\n KeyframesSteps,\n} from '../injector/types';\nimport {\n extractLocalCounterStyle,\n formatCounterStyleRule,\n hasLocalCounterStyle,\n} from '../counter-style';\nimport {\n extractLocalFontFace,\n formatFontFaceRule,\n hasLocalFontFace,\n} from '../font-face';\nimport {\n extractAnimationNamesFromStyles,\n extractLocalKeyframes,\n filterUsedKeyframes,\n hasLocalKeyframes,\n mergeKeyframes,\n} from '../keyframes';\nimport type { StyleResult } from '../pipeline';\nimport { renderStyles } from '../pipeline';\nimport { extractLocalProperties, hasLocalProperties } from '../properties';\nimport { PropertyTypeResolver } from '../properties/property-type-resolver';\nimport type { Styles } from '../styles/types';\n\nexport interface ExtractedChunk {\n className: string;\n css: string;\n}\n\nexport interface ExtractedSelector {\n selector: string;\n css: string;\n}\n\nexport interface ExtractedKeyframes {\n name: string;\n css: string;\n}\n\nexport interface KeyframesExtractionResult {\n /** Keyframes to inject (deduplicated by content) */\n keyframes: ExtractedKeyframes[];\n /** Map from original animation name to canonical name (for replacement) */\n nameMap: Map<string, string>;\n}\n\n/**\n * Generate a deterministic className from a cache key using content hash.\n * This ensures the same styles always produce the same className,\n * regardless of build order or incremental compilation.\n */\nfunction generateClassName(cacheKey: string): string {\n const hash = createHash('md5').update(cacheKey).digest('hex').slice(0, 6);\n return `ts${hash}`; // 'ts' prefix for \"tasty-static\" to distinguish from runtime 't' classes\n}\n\n/**\n * Extract styles using chunking (for className mode).\n * Returns multiple classes, one per chunk.\n */\nexport function extractStylesWithChunks(styles: Styles): ExtractedChunk[] {\n const chunks: ExtractedChunk[] = [];\n\n // Categorize style keys into chunks\n const chunkMap = categorizeStyleKeys(styles as Record<string, unknown>);\n\n for (const [chunkName, chunkStyleKeys] of chunkMap) {\n if (chunkStyleKeys.length === 0) continue;\n\n // Generate cache key for this chunk (used for className hash)\n const cacheKey = generateChunkCacheKey(styles, chunkName, chunkStyleKeys);\n\n // Render styles for this chunk\n const renderResult = renderStylesForChunk(\n styles,\n chunkName,\n chunkStyleKeys,\n );\n\n if (renderResult.rules.length === 0) continue;\n\n // Generate deterministic className from content hash\n const className = generateClassName(cacheKey);\n const selector = `.${className}.${className}`;\n\n // Format CSS\n const css = formatRulesToCSS(renderResult.rules, selector);\n\n chunks.push({ className, css });\n }\n\n return chunks;\n}\n\n/**\n * Extract styles for a specific selector (for global/selector mode).\n * Returns a single CSS block.\n */\nexport function extractStylesForSelector(\n selector: string,\n styles: Styles,\n): ExtractedSelector {\n // renderStyles with selector returns StyleResult[] with selectors already applied\n const rules = renderStyles(styles, selector);\n // Format without re-prefixing - rules already have the full selector\n const css = formatRulesDirectly(rules);\n\n return { selector, css };\n}\n\n/**\n * Format StyleResult[] to CSS string.\n * Prefixes each rule's selector with the base selector.\n * Used for chunked styles where rules have relative selectors.\n */\nfunction formatRulesToCSS(rules: StyleResult[], baseSelector: string): string {\n return rules\n .map((rule) => {\n // Handle selector as array (OR conditions) or string\n // Note: renderStyles without className joins array selectors with '|||' placeholder\n const selectorParts = Array.isArray(rule.selector)\n ? rule.selector\n : rule.selector\n ? rule.selector.split('|||')\n : [''];\n\n // Prefix each selector part with the base selector\n const fullSelector = selectorParts\n .map((part) => {\n // Build selector: [rootPrefix] baseSelector[part]\n let selector: string;\n\n // If part is empty, just use base selector\n if (!part) {\n selector = baseSelector;\n } else if (part.startsWith(':') || part.startsWith('[')) {\n // If part starts with a pseudo-class or pseudo-element, append to base\n selector = `${baseSelector}${part}`;\n } else if (\n part.startsWith('>') ||\n part.startsWith('+') ||\n part.startsWith('~')\n ) {\n // If part starts with >, +, ~ combinator, append with space\n selector = `${baseSelector}${part}`;\n } else {\n // Otherwise, combine base with part\n selector = `${baseSelector}${part}`;\n }\n\n // Prepend rootPrefix if present (for @root() states)\n if (rule.rootPrefix) {\n selector = `${rule.rootPrefix} ${selector}`;\n }\n\n return selector;\n })\n .join(', ');\n\n let css = `${fullSelector} { ${rule.declarations} }`;\n\n // Wrap in at-rules (in reverse order for proper nesting)\n if (rule.atRules && rule.atRules.length > 0) {\n for (const atRule of [...rule.atRules].reverse()) {\n css = `${atRule} {\\n ${css}\\n}`;\n }\n }\n\n return css;\n })\n .join('\\n\\n');\n}\n\n/**\n * Format StyleResult[] to CSS string directly without prefixing.\n * Used for global styles where rules already have the full selector.\n */\nfunction formatRulesDirectly(rules: StyleResult[]): string {\n return rules\n .map((rule) => {\n // Prepend rootPrefix if present (for @root() states)\n const selector = rule.rootPrefix\n ? `${rule.rootPrefix} ${rule.selector}`\n : rule.selector;\n\n let css = `${selector} { ${rule.declarations} }`;\n\n // Wrap in at-rules (in reverse order for proper nesting)\n if (rule.atRules && rule.atRules.length > 0) {\n for (const atRule of [...rule.atRules].reverse()) {\n css = `${atRule} {\\n ${css}\\n}`;\n }\n }\n\n return css;\n })\n .join('\\n\\n');\n}\n\n// Note: With hash-based className generation, counter management functions\n// are no longer needed. ClassNames are deterministic based on content.\n\n/**\n * Generate a deterministic keyframes name from content hash.\n * This ensures the same keyframes content always produces the same name,\n * enabling automatic deduplication across elements and files.\n */\nfunction generateKeyframesName(steps: KeyframesSteps): string {\n const content = JSON.stringify(steps);\n const hash = createHash('md5').update(content).digest('hex').slice(0, 6);\n return `kf${hash}`; // 'kf' prefix for \"keyframes\"\n}\n\n/**\n * Extract keyframes that are used in styles.\n * Merges local @keyframes with global keyframes, filters to only used ones.\n * Generates hash-based names from content for automatic deduplication.\n *\n * @param styles - The styles object (may contain @keyframes and animation properties)\n * @param globalKeyframes - Optional global keyframes from config\n * @returns Keyframes to inject and name mapping for replacement\n */\nexport function extractKeyframesFromStyles(\n styles: Styles,\n globalKeyframes?: Record<string, KeyframesSteps> | null,\n): KeyframesExtractionResult {\n const emptyResult: KeyframesExtractionResult = {\n keyframes: [],\n nameMap: new Map(),\n };\n\n // Extract animation names from styles\n const usedNames = extractAnimationNamesFromStyles(styles);\n if (usedNames.size === 0) return emptyResult;\n\n // Merge local and global keyframes\n const local = hasLocalKeyframes(styles)\n ? extractLocalKeyframes(styles)\n : null;\n const allKeyframes = mergeKeyframes(local, globalKeyframes ?? null);\n\n // Filter to only used keyframes\n const usedKeyframes = filterUsedKeyframes(allKeyframes, usedNames);\n if (!usedKeyframes) return emptyResult;\n\n // Generate hash-based names and collect unique keyframes\n const seenHashes = new Set<string>();\n const nameMap = new Map<string, string>();\n const keyframesToEmit: ExtractedKeyframes[] = [];\n\n for (const [originalName, steps] of Object.entries(usedKeyframes)) {\n const hashedName = generateKeyframesName(steps);\n\n // Always map original name to hashed name (for CSS replacement)\n nameMap.set(originalName, hashedName);\n\n // Only emit each unique keyframe once\n if (!seenHashes.has(hashedName)) {\n seenHashes.add(hashedName);\n const css = keyframesToCSS(hashedName, steps);\n keyframesToEmit.push({ name: hashedName, css });\n }\n }\n\n return { keyframes: keyframesToEmit, nameMap };\n}\n\n/**\n * Convert keyframes steps to CSS string.\n */\nfunction keyframesToCSS(name: string, steps: KeyframesSteps): string {\n const stepRules: string[] = [];\n\n for (const [key, value] of Object.entries(steps)) {\n if (typeof value === 'string') {\n // Raw CSS string\n stepRules.push(`${key} { ${value.trim()} }`);\n } else if (value && typeof value === 'object') {\n // Style map - convert to CSS declarations\n const declarations = Object.entries(value)\n .map(([prop, val]) => {\n const cssProperty = camelToKebab(prop);\n return `${cssProperty}: ${val}`;\n })\n .join('; ');\n stepRules.push(`${key} { ${declarations} }`);\n }\n }\n\n return `@keyframes ${name} { ${stepRules.join(' ')} }`;\n}\n\n/**\n * Convert camelCase to kebab-case.\n */\nfunction camelToKebab(str: string): string {\n return str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n}\n\n// ============================================================================\n// Property Extraction (auto-infer @property types for zero-runtime)\n// ============================================================================\n\nexport interface ExtractedProperty {\n name: string;\n css: string;\n}\n\n/**\n * Extract auto-inferred @property declarations from styles.\n * Scans rendered style declarations and keyframe declarations for custom properties\n * whose types can be inferred from their values.\n *\n * @param styles - The styles object\n * @param options - Options including autoPropertyTypes flag\n * @returns Array of @property CSS rules to inject\n */\nexport function extractPropertiesFromStyles(\n styles: Styles,\n options?: { autoPropertyTypes?: boolean },\n): ExtractedProperty[] {\n if (options?.autoPropertyTypes === false) return [];\n\n const registered = new Set<string>();\n const results: ExtractedProperty[] = [];\n\n // Collect explicitly declared properties (they take precedence)\n if (hasLocalProperties(styles)) {\n const localProps = extractLocalProperties(styles);\n if (localProps) {\n for (const token of Object.keys(localProps)) {\n // Normalize token to CSS name\n let cssName: string;\n if (token.startsWith('#')) {\n cssName = `--${token.slice(1)}-color`;\n } else if (token.startsWith('$')) {\n cssName = `--${token.slice(1)}`;\n } else if (token.startsWith('--')) {\n cssName = token;\n } else {\n cssName = `--${token}`;\n }\n registered.add(cssName);\n }\n }\n }\n\n const resolver = new PropertyTypeResolver();\n\n const registerProperty = (\n name: string,\n syntax: string,\n initialValue: string,\n ) => {\n if (registered.has(name)) return;\n registered.add(name);\n\n const parts: string[] = [];\n parts.push(`syntax: \"${syntax}\";`);\n parts.push(`inherits: true;`);\n parts.push(`initial-value: ${initialValue};`);\n\n const css = `@property ${name} { ${parts.join(' ')} }`;\n results.push({ name, css });\n };\n\n const isPropertyDefined = (name: string) => registered.has(name);\n\n // Scan rendered style declarations\n const chunkMap = categorizeStyleKeys(styles as Record<string, unknown>);\n for (const [chunkName, chunkStyleKeys] of chunkMap) {\n if (chunkStyleKeys.length === 0) continue;\n const renderResult = renderStylesForChunk(\n styles,\n chunkName,\n chunkStyleKeys,\n );\n for (const rule of renderResult.rules) {\n if (!rule.declarations) continue;\n resolver.scanDeclarations(\n rule.declarations,\n isPropertyDefined,\n registerProperty,\n );\n }\n }\n\n // Scan keyframe declarations\n if (hasLocalKeyframes(styles)) {\n const localKf = extractLocalKeyframes(styles);\n if (localKf) {\n for (const steps of Object.values(localKf)) {\n scanKeyframeSteps(steps, resolver, isPropertyDefined, registerProperty);\n }\n }\n }\n\n return results;\n}\n\nfunction scanKeyframeSteps(\n steps: KeyframesSteps,\n resolver: PropertyTypeResolver,\n isPropertyDefined: (name: string) => boolean,\n registerProperty: (\n name: string,\n syntax: string,\n initialValue: string,\n ) => void,\n): void {\n for (const value of Object.values(steps)) {\n if (typeof value === 'string') {\n resolver.scanDeclarations(value, isPropertyDefined, registerProperty);\n } else if (value && typeof value === 'object') {\n const declarations = Object.entries(value)\n .map(([prop, val]) => {\n const cssProperty = camelToKebab(prop);\n return `${cssProperty}: ${val}`;\n })\n .join('; ');\n resolver.scanDeclarations(\n declarations,\n isPropertyDefined,\n registerProperty,\n );\n }\n }\n}\n\n// ============================================================================\n// Font Face Extraction (zero-runtime)\n// ============================================================================\n\nexport interface ExtractedFontFace {\n css: string;\n}\n\n/**\n * Extract @font-face rules from styles, merging with global config.\n * Deduplicates by content hash.\n */\nexport function extractFontFaceFromStyles(\n styles: Styles,\n globalFontFace?: Record<string, FontFaceInput> | null,\n): ExtractedFontFace[] {\n const results: ExtractedFontFace[] = [];\n const seenHashes = new Set<string>();\n\n function addFontFace(family: string, input: FontFaceInput) {\n const descriptors: FontFaceDescriptors[] = Array.isArray(input)\n ? input\n : [input];\n for (const desc of descriptors) {\n const hash = createHash('md5')\n .update(JSON.stringify({ family, ...desc }))\n .digest('hex')\n .slice(0, 8);\n if (!seenHashes.has(hash)) {\n seenHashes.add(hash);\n results.push({ css: formatFontFaceRule(family, desc) });\n }\n }\n }\n\n // Global font faces first\n if (globalFontFace) {\n for (const [family, input] of Object.entries(globalFontFace)) {\n addFontFace(family, input);\n }\n }\n\n // Local font faces (override globals with same hash)\n if (hasLocalFontFace(styles)) {\n const local = extractLocalFontFace(styles);\n if (local) {\n for (const [family, input] of Object.entries(local)) {\n addFontFace(family, input);\n }\n }\n }\n\n return results;\n}\n\n// ============================================================================\n// Counter Style Extraction (zero-runtime)\n// ============================================================================\n\nexport interface ExtractedCounterStyle {\n name: string;\n css: string;\n}\n\n/**\n * Extract @counter-style rules from styles, merging with global config.\n * Deduplicates by name (first definition wins).\n */\nexport function extractCounterStyleFromStyles(\n styles: Styles,\n globalCounterStyle?: Record<string, CounterStyleDescriptors> | null,\n): ExtractedCounterStyle[] {\n const results: ExtractedCounterStyle[] = [];\n const seenNames = new Set<string>();\n\n function addCounterStyle(name: string, descriptors: CounterStyleDescriptors) {\n if (!seenNames.has(name)) {\n seenNames.add(name);\n results.push({ name, css: formatCounterStyleRule(name, descriptors) });\n }\n }\n\n // Global counter styles first\n if (globalCounterStyle) {\n for (const [name, descriptors] of Object.entries(globalCounterStyle)) {\n addCounterStyle(name, descriptors);\n }\n }\n\n // Local counter styles (override globals with same name)\n if (hasLocalCounterStyle(styles)) {\n const local = extractLocalCounterStyle(styles);\n if (local) {\n for (const [name, descriptors] of Object.entries(local)) {\n addCounterStyle(name, descriptors);\n }\n }\n }\n\n return results;\n}\n","import * as fs from 'fs';\nimport * as path from 'path';\n\nexport interface CSSWriterOptions {\n /** Enable source comments in output (e.g., \"from: Button.tsx\") */\n devMode?: boolean;\n}\n\ninterface CSSBlock {\n css: string;\n source?: string;\n}\n\nexport class CSSWriter {\n private cssBlocks = new Map<string, CSSBlock>();\n private outputPath: string;\n private devMode: boolean;\n\n constructor(outputPath: string, options: CSSWriterOptions = {}) {\n this.outputPath = outputPath;\n this.devMode = options.devMode ?? false;\n }\n\n /**\n * Add CSS block with deduplication key\n * @param key - Unique key for deduplication\n * @param css - CSS content\n * @param source - Optional source file path (used in devMode)\n */\n add(key: string, css: string, source?: string): void {\n this.cssBlocks.set(key, { css, source });\n }\n\n /**\n * Check if a key already exists\n */\n has(key: string): boolean {\n return this.cssBlocks.has(key);\n }\n\n /**\n * Get the number of CSS blocks\n */\n get size(): number {\n return this.cssBlocks.size;\n }\n\n /**\n * Write all collected CSS to the output file\n */\n write(): void {\n const outputDir = path.dirname(this.outputPath);\n\n // Ensure directory exists\n if (!fs.existsSync(outputDir)) {\n fs.mkdirSync(outputDir, { recursive: true });\n }\n\n // Combine all CSS blocks with optional source comments\n const cssBlocks: string[] = [];\n for (const block of this.cssBlocks.values()) {\n if (this.devMode && block.source) {\n cssBlocks.push(`/* from: ${block.source} */\\n${block.css}`);\n } else {\n cssBlocks.push(block.css);\n }\n }\n const css = cssBlocks.join('\\n\\n');\n\n // Add header comment\n const header = `/* Generated by @tenphi/tasty/zero - DO NOT EDIT */\\n\\n`;\n\n fs.writeFileSync(this.outputPath, header + css);\n }\n\n /**\n * Get all CSS as string (for testing or in-memory use)\n */\n getCSS(): string {\n const cssBlocks: string[] = [];\n for (const block of this.cssBlocks.values()) {\n if (this.devMode && block.source) {\n cssBlocks.push(`/* from: ${block.source} */\\n${block.css}`);\n } else {\n cssBlocks.push(block.css);\n }\n }\n return cssBlocks.join('\\n\\n');\n }\n\n /**\n * Clear all collected CSS\n */\n clear(): void {\n this.cssBlocks.clear();\n }\n\n /**\n * Get the output path\n */\n getOutputPath(): string {\n return this.outputPath;\n }\n}\n"],"mappings":";;;;;;;;;;;AA+DA,SAAS,kBAAkB,UAA0B;AAEnD,QAAO,KADM,WAAW,MAAM,CAAC,OAAO,SAAS,CAAC,OAAO,MAAM,CAAC,MAAM,GAAG,EAAE;;;;;;AAQ3E,SAAgB,wBAAwB,QAAkC;CACxE,MAAM,SAA2B,EAAE;CAGnC,MAAM,WAAW,oBAAoB,OAAkC;AAEvE,MAAK,MAAM,CAAC,WAAW,mBAAmB,UAAU;AAClD,MAAI,eAAe,WAAW,EAAG;EAGjC,MAAM,WAAW,sBAAsB,QAAQ,WAAW,eAAe;EAGzE,MAAM,eAAe,qBACnB,QACA,WACA,eACD;AAED,MAAI,aAAa,MAAM,WAAW,EAAG;EAGrC,MAAM,YAAY,kBAAkB,SAAS;EAC7C,MAAM,WAAW,IAAI,UAAU,GAAG;EAGlC,MAAM,MAAM,iBAAiB,aAAa,OAAO,SAAS;AAE1D,SAAO,KAAK;GAAE;GAAW;GAAK,CAAC;;AAGjC,QAAO;;;;;;AAOT,SAAgB,yBACd,UACA,QACmB;AAMnB,QAAO;EAAE;EAAU,KAFP,oBAFE,a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AAK,MAAM,SAAS,KAAK,UAAU,QAAQ,CACzC,KAAI,KAAK,WAAW,MAAM,OACxB,WAAU,KAAK,YAAY,MAAM,OAAO,OAAO,MAAM,MAAM;MAE3D,WAAU,KAAK,MAAM,IAAI;EAG7B,MAAM,MAAM,UAAU,KAAK,OAAO;AAKlC,KAAG,cAAc,KAAK,YAFP,4DAE4B,IAAI;;;;;CAMjD,SAAiB;EACf,MAAM,YAAsB,EAAE;AAC9B,OAAK,MAAM,SAAS,KAAK,UAAU,QAAQ,CACzC,KAAI,KAAK,WAAW,MAAM,OACxB,WAAU,KAAK,YAAY,MAAM,OAAO,OAAO,MAAM,MAAM;MAE3D,WAAU,KAAK,MAAM,IAAI;AAG7B,SAAO,UAAU,KAAK,OAAO;;;;;CAM/B,QAAc;AACZ,OAAK,UAAU,OAAO;;;;;CAMxB,gBAAwB;AACtB,SAAO,KAAK"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/ssr/format-global-rules.ts
|
|
2
|
+
/**
|
|
3
|
+
* Format an array of global StyleResult rules into a CSS text string.
|
|
4
|
+
*
|
|
5
|
+
* Rules already have their full selectors applied by renderStyles().
|
|
6
|
+
* Handles rootPrefix prepending and at-rule wrapping.
|
|
7
|
+
*/
|
|
8
|
+
function formatGlobalRules(rules) {
|
|
9
|
+
if (rules.length === 0) return "";
|
|
10
|
+
const cssRules = [];
|
|
11
|
+
for (const rule of rules) {
|
|
12
|
+
const baseRule = `${rule.rootPrefix ? `${rule.rootPrefix} ${rule.selector}` : rule.selector} { ${rule.declarations} }`;
|
|
13
|
+
let fullRule = baseRule;
|
|
14
|
+
if (rule.atRules && rule.atRules.length > 0) fullRule = rule.atRules.reduce((css, atRule) => `${atRule} { ${css} }`, baseRule);
|
|
15
|
+
cssRules.push(fullRule);
|
|
16
|
+
}
|
|
17
|
+
return cssRules.join("\n");
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { formatGlobalRules as t };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=format-global-rules-Dbc_1tc3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-global-rules-Dbc_1tc3.js","names":[],"sources":["../src/ssr/format-global-rules.ts"],"sourcesContent":["/**\n * Format global CSS rules for SSR output.\n *\n * Unlike formatRules() which applies className-based specificity doubling,\n * this function formats rules that already have their full selectors\n * (from renderStyles called with a selector string).\n */\n\nimport type { StyleResult } from '../pipeline';\n\n/**\n * Format an array of global StyleResult rules into a CSS text string.\n *\n * Rules already have their full selectors applied by renderStyles().\n * Handles rootPrefix prepending and at-rule wrapping.\n */\nexport function formatGlobalRules(rules: StyleResult[]): string {\n if (rules.length === 0) return '';\n\n const cssRules: string[] = [];\n\n for (const rule of rules) {\n const selector = rule.rootPrefix\n ? `${rule.rootPrefix} ${rule.selector}`\n : rule.selector;\n\n const baseRule = `${selector} { ${rule.declarations} }`;\n\n let fullRule = baseRule;\n if (rule.atRules && rule.atRules.length > 0) {\n fullRule = rule.atRules.reduce(\n (css, atRule) => `${atRule} { ${css} }`,\n baseRule,\n );\n }\n\n cssRules.push(fullRule);\n }\n\n return cssRules.join('\\n');\n}\n"],"mappings":";;;;;;;AAgBA,SAAgB,kBAAkB,OAA8B;AAC9D,KAAI,MAAM,WAAW,EAAG,QAAO;CAE/B,MAAM,WAAqB,EAAE;AAE7B,MAAK,MAAM,QAAQ,OAAO;EAKxB,MAAM,WAAW,GAJA,KAAK,aAClB,GAAG,KAAK,WAAW,GAAG,KAAK,aAC3B,KAAK,SAEoB,KAAK,KAAK,aAAa;EAEpD,IAAI,WAAW;AACf,MAAI,KAAK,WAAW,KAAK,QAAQ,SAAS,EACxC,YAAW,KAAK,QAAQ,QACrB,KAAK,WAAW,GAAG,OAAO,KAAK,IAAI,KACpC,SACD;AAGH,WAAS,KAAK,SAAS;;AAGzB,QAAO,SAAS,KAAK,KAAK"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { $ as parseStyle, _t as getComponentPropertySyntax, gt as getColorSpaceSuffix, pt as colorInitialValueToComponents, ut as getEffectiveDefinition } from "./config-A237aY9H.js";
|
|
2
|
+
//#region src/ssr/ssr-collector-ref.ts
|
|
3
|
+
const GETTER_KEY = "__tasty_ssr_collector_getter__";
|
|
4
|
+
let _getSSRCollector = null;
|
|
5
|
+
/**
|
|
6
|
+
* Register the collector getter in the current module graph only.
|
|
7
|
+
* Used by Next.js TastyRegistry.
|
|
8
|
+
*/
|
|
9
|
+
function registerSSRCollectorGetter(fn) {
|
|
10
|
+
_getSSRCollector = fn;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Register the collector getter on globalThis so it is visible across
|
|
14
|
+
* separate module graphs (e.g. Astro middleware ↔ page components).
|
|
15
|
+
*/
|
|
16
|
+
function registerSSRCollectorGetterGlobal(fn) {
|
|
17
|
+
globalThis[GETTER_KEY] = fn;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Retrieve the SSR collector: module-level first, globalThis fallback.
|
|
21
|
+
*/
|
|
22
|
+
function getRegisteredSSRCollector() {
|
|
23
|
+
if (_getSSRCollector) return _getSSRCollector();
|
|
24
|
+
const getter = globalThis[GETTER_KEY];
|
|
25
|
+
return getter ? getter() : null;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/ssr/format-property.ts
|
|
29
|
+
/**
|
|
30
|
+
* Format a single @property rule as a CSS string.
|
|
31
|
+
*
|
|
32
|
+
* Returns the full `@property --name { ... }` text, or empty string
|
|
33
|
+
* if the token is invalid. For color properties, also returns
|
|
34
|
+
* the companion component property.
|
|
35
|
+
*/
|
|
36
|
+
function formatPropertyCSS(token, definition) {
|
|
37
|
+
const result = getEffectiveDefinition(token, definition);
|
|
38
|
+
if (!result.isValid) return "";
|
|
39
|
+
const rules = [];
|
|
40
|
+
rules.push(buildPropertyRule(result.cssName, result.definition));
|
|
41
|
+
if (result.isColor) {
|
|
42
|
+
const suffix = getColorSpaceSuffix();
|
|
43
|
+
const componentCssName = `${result.cssName}-${suffix}`;
|
|
44
|
+
const componentInitial = colorInitialValueToComponents(result.definition.initialValue);
|
|
45
|
+
rules.push(buildPropertyRule(componentCssName, {
|
|
46
|
+
syntax: getComponentPropertySyntax(),
|
|
47
|
+
inherits: result.definition.inherits,
|
|
48
|
+
initialValue: componentInitial
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
return rules.join("\n");
|
|
52
|
+
}
|
|
53
|
+
function buildPropertyRule(cssName, definition) {
|
|
54
|
+
const parts = [];
|
|
55
|
+
if (definition.syntax != null) {
|
|
56
|
+
let syntax = String(definition.syntax).trim();
|
|
57
|
+
if (!/^['"]/u.test(syntax)) syntax = `"${syntax}"`;
|
|
58
|
+
parts.push(`syntax: ${syntax};`);
|
|
59
|
+
}
|
|
60
|
+
const inherits = definition.inherits ?? true;
|
|
61
|
+
parts.push(`inherits: ${inherits ? "true" : "false"};`);
|
|
62
|
+
if (definition.initialValue != null) {
|
|
63
|
+
let initialValueStr;
|
|
64
|
+
if (typeof definition.initialValue === "number") initialValueStr = String(definition.initialValue);
|
|
65
|
+
else initialValueStr = parseStyle(definition.initialValue).output;
|
|
66
|
+
parts.push(`initial-value: ${initialValueStr};`);
|
|
67
|
+
}
|
|
68
|
+
return `@property ${cssName} { ${parts.join(" ").trim()} }`;
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/ssr/format-rules.ts
|
|
72
|
+
/**
|
|
73
|
+
* Resolve selectors for a rule, applying className-based specificity doubling
|
|
74
|
+
* and rootPrefix handling. Mirrors the logic in StyleInjector.inject().
|
|
75
|
+
*/
|
|
76
|
+
function resolveSelector(rule, className) {
|
|
77
|
+
let selector = rule.selector;
|
|
78
|
+
if (rule.needsClassName) {
|
|
79
|
+
const selectorParts = selector ? selector.split("|||") : [""];
|
|
80
|
+
const classPrefix = `.${className}.${className}`;
|
|
81
|
+
selector = selectorParts.map((part) => {
|
|
82
|
+
const classSelector = part ? `${classPrefix}${part}` : classPrefix;
|
|
83
|
+
if (rule.rootPrefix) return `${rule.rootPrefix} ${classSelector}`;
|
|
84
|
+
return classSelector;
|
|
85
|
+
}).join(", ");
|
|
86
|
+
}
|
|
87
|
+
return selector;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Group rules by selector + at-rules + startingStyle and merge their declarations.
|
|
91
|
+
* Mirrors the grouping logic in SheetManager.insertRule().
|
|
92
|
+
*/
|
|
93
|
+
function groupRules(rules) {
|
|
94
|
+
const groupMap = /* @__PURE__ */ new Map();
|
|
95
|
+
const order = [];
|
|
96
|
+
const atKey = (at) => at && at.length ? at.join("|") : "";
|
|
97
|
+
for (const r of rules) {
|
|
98
|
+
const key = `${atKey(r.atRules)}||${r.selector}||${r.startingStyle ? "1" : "0"}`;
|
|
99
|
+
const existing = groupMap.get(key);
|
|
100
|
+
if (existing) existing.declarations = existing.declarations ? `${existing.declarations} ${r.declarations}` : r.declarations;
|
|
101
|
+
else {
|
|
102
|
+
groupMap.set(key, {
|
|
103
|
+
selector: r.selector,
|
|
104
|
+
atRules: r.atRules,
|
|
105
|
+
startingStyle: r.startingStyle,
|
|
106
|
+
declarations: r.declarations
|
|
107
|
+
});
|
|
108
|
+
order.push(key);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return order.map((key) => groupMap.get(key));
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Format an array of StyleResult rules into a CSS text string.
|
|
115
|
+
*
|
|
116
|
+
* Applies className-based specificity doubling (.cls.cls),
|
|
117
|
+
* groups rules by selector + at-rules, and wraps with at-rule blocks.
|
|
118
|
+
*
|
|
119
|
+
* Produces the same CSS text as SheetManager.insertRule() would insert
|
|
120
|
+
* into the DOM, but as a plain string suitable for SSR output.
|
|
121
|
+
*/
|
|
122
|
+
function formatRules(rules, className) {
|
|
123
|
+
if (rules.length === 0) return "";
|
|
124
|
+
const grouped = groupRules(rules.map((rule) => ({
|
|
125
|
+
selector: resolveSelector(rule, className),
|
|
126
|
+
declarations: rule.declarations,
|
|
127
|
+
atRules: rule.atRules,
|
|
128
|
+
startingStyle: rule.startingStyle
|
|
129
|
+
})));
|
|
130
|
+
const cssRules = [];
|
|
131
|
+
for (const rule of grouped) {
|
|
132
|
+
const innerContent = rule.startingStyle ? `@starting-style { ${rule.declarations} }` : rule.declarations;
|
|
133
|
+
const baseRule = `${rule.selector} { ${innerContent} }`;
|
|
134
|
+
let fullRule = baseRule;
|
|
135
|
+
if (rule.atRules && rule.atRules.length > 0) fullRule = rule.atRules.reduce((css, atRule) => `${atRule} { ${css} }`, baseRule);
|
|
136
|
+
cssRules.push(fullRule);
|
|
137
|
+
}
|
|
138
|
+
return cssRules.join("\n");
|
|
139
|
+
}
|
|
140
|
+
//#endregion
|
|
141
|
+
export { registerSSRCollectorGetterGlobal as a, registerSSRCollectorGetter as i, formatPropertyCSS as n, getRegisteredSSRCollector as r, formatRules as t };
|
|
142
|
+
|
|
143
|
+
//# sourceMappingURL=format-rules-C2oiTsEO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-rules-C2oiTsEO.js","names":[],"sources":["../src/ssr/ssr-collector-ref.ts","../src/ssr/format-property.ts","../src/ssr/format-rules.ts"],"sourcesContent":["/**\n * Global reference to the SSR collector getter function.\n *\n * This indirection avoids importing 'node:async_hooks' in the browser bundle.\n * The SSR entry point sets this ref when loaded on the server. The useStyles\n * hook calls it if set; on the client it stays null and is never called.\n *\n * Uses a module-level variable as the primary mechanism. In Next.js App\n * Router the RSC and SSR module graphs load separate copies of this module,\n * so the getter registered by TastyRegistry (SSR layer) is invisible to\n * server components (RSC layer) — which correctly fall through to inline\n * RSC styles.\n *\n * A globalThis fallback (`registerSSRCollectorGetterGlobal`) is provided\n * for frameworks like Astro where middleware and page components live in\n * different module graphs and must share the getter across them.\n */\n\nimport type { ServerStyleCollector } from './collector';\n\ntype SSRCollectorGetter = () => ServerStyleCollector | null;\n\nconst GETTER_KEY = '__tasty_ssr_collector_getter__';\n\nlet _getSSRCollector: SSRCollectorGetter | null = null;\n\n/**\n * Register the collector getter in the current module graph only.\n * Used by Next.js TastyRegistry.\n */\nexport function registerSSRCollectorGetter(fn: SSRCollectorGetter): void {\n _getSSRCollector = fn;\n}\n\n/**\n * Register the collector getter on globalThis so it is visible across\n * separate module graphs (e.g. Astro middleware ↔ page components).\n */\nexport function registerSSRCollectorGetterGlobal(fn: SSRCollectorGetter): void {\n (globalThis as Record<string, unknown>)[GETTER_KEY] = fn;\n}\n\n/**\n * Retrieve the SSR collector: module-level first, globalThis fallback.\n */\nexport function getRegisteredSSRCollector(): ServerStyleCollector | null {\n if (_getSSRCollector) return _getSSRCollector();\n const getter = (globalThis as Record<string, unknown>)[GETTER_KEY] as\n | SSRCollectorGetter\n | undefined;\n return getter ? getter() : null;\n}\n","/**\n * Format @property CSS rules for SSR output.\n *\n * Replicates the CSS construction from StyleInjector.property()\n * but returns a CSS string instead of inserting into the DOM.\n */\n\nimport type { PropertyDefinition } from '../injector/types';\nimport { getEffectiveDefinition } from '../properties';\nimport {\n colorInitialValueToComponents,\n getColorSpaceSuffix,\n getComponentPropertySyntax,\n} from '../utils/color-space';\nimport type { StyleValue } from '../utils/styles';\nimport { parseStyle } from '../utils/styles';\n\n/**\n * Format a single @property rule as a CSS string.\n *\n * Returns the full `@property --name { ... }` text, or empty string\n * if the token is invalid. For color properties, also returns\n * the companion component property.\n */\nexport function formatPropertyCSS(\n token: string,\n definition: PropertyDefinition,\n): string {\n const result = getEffectiveDefinition(token, definition);\n if (!result.isValid) return '';\n\n const rules: string[] = [];\n\n rules.push(buildPropertyRule(result.cssName, result.definition));\n\n if (result.isColor) {\n const suffix = getColorSpaceSuffix();\n const componentCssName = `${result.cssName}-${suffix}`;\n const componentInitial = colorInitialValueToComponents(\n result.definition.initialValue,\n );\n rules.push(\n buildPropertyRule(componentCssName, {\n syntax: getComponentPropertySyntax(),\n inherits: result.definition.inherits,\n initialValue: componentInitial,\n }),\n );\n }\n\n return rules.join('\\n');\n}\n\nfunction buildPropertyRule(\n cssName: string,\n definition: PropertyDefinition,\n): string {\n const parts: string[] = [];\n\n if (definition.syntax != null) {\n let syntax = String(definition.syntax).trim();\n if (!/^['\"]/u.test(syntax)) syntax = `\"${syntax}\"`;\n parts.push(`syntax: ${syntax};`);\n }\n\n const inherits = definition.inherits ?? true;\n parts.push(`inherits: ${inherits ? 'true' : 'false'};`);\n\n if (definition.initialValue != null) {\n let initialValueStr: string;\n if (typeof definition.initialValue === 'number') {\n initialValueStr = String(definition.initialValue);\n } else {\n initialValueStr = parseStyle(\n definition.initialValue as StyleValue,\n ).output;\n }\n parts.push(`initial-value: ${initialValueStr};`);\n }\n\n const declarations = parts.join(' ').trim();\n return `@property ${cssName} { ${declarations} }`;\n}\n","/**\n * Shared CSS rule formatting utility.\n *\n * Extracted from SheetManager to allow both the DOM-based injector (client)\n * and the ServerStyleCollector (server) to produce identical CSS text\n * from StyleResult arrays.\n */\n\nimport type { StyleResult } from '../pipeline';\n\n/**\n * Resolve selectors for a rule, applying className-based specificity doubling\n * and rootPrefix handling. Mirrors the logic in StyleInjector.inject().\n */\nfunction resolveSelector(rule: StyleResult, className: string): string {\n let selector = rule.selector;\n\n if (rule.needsClassName) {\n const selectorParts = selector ? selector.split('|||') : [''];\n const classPrefix = `.${className}.${className}`;\n\n selector = selectorParts\n .map((part) => {\n const classSelector = part ? `${classPrefix}${part}` : classPrefix;\n\n if (rule.rootPrefix) {\n return `${rule.rootPrefix} ${classSelector}`;\n }\n return classSelector;\n })\n .join(', ');\n }\n\n return selector;\n}\n\ninterface GroupedRule {\n selector: string;\n declarations: string;\n atRules?: string[];\n startingStyle?: boolean;\n}\n\n/**\n * Group rules by selector + at-rules + startingStyle and merge their declarations.\n * Mirrors the grouping logic in SheetManager.insertRule().\n */\nfunction groupRules(rules: GroupedRule[]): GroupedRule[] {\n const groupMap = new Map<string, GroupedRule>();\n const order: string[] = [];\n\n const atKey = (at?: string[]) => (at && at.length ? at.join('|') : '');\n\n for (const r of rules) {\n const key = `${atKey(r.atRules)}||${r.selector}||${r.startingStyle ? '1' : '0'}`;\n const existing = groupMap.get(key);\n if (existing) {\n existing.declarations = existing.declarations\n ? `${existing.declarations} ${r.declarations}`\n : r.declarations;\n } else {\n groupMap.set(key, {\n selector: r.selector,\n atRules: r.atRules,\n startingStyle: r.startingStyle,\n declarations: r.declarations,\n });\n order.push(key);\n }\n }\n\n return order.map((key) => groupMap.get(key)!);\n}\n\n/**\n * Format an array of StyleResult rules into a CSS text string.\n *\n * Applies className-based specificity doubling (.cls.cls),\n * groups rules by selector + at-rules, and wraps with at-rule blocks.\n *\n * Produces the same CSS text as SheetManager.insertRule() would insert\n * into the DOM, but as a plain string suitable for SSR output.\n */\nexport function formatRules(rules: StyleResult[], className: string): string {\n if (rules.length === 0) return '';\n\n const resolvedRules = rules.map((rule) => ({\n selector: resolveSelector(rule, className),\n declarations: rule.declarations,\n atRules: rule.atRules,\n startingStyle: rule.startingStyle,\n }));\n\n const grouped = groupRules(resolvedRules);\n const cssRules: string[] = [];\n\n for (const rule of grouped) {\n const innerContent = rule.startingStyle\n ? `@starting-style { ${rule.declarations} }`\n : rule.declarations;\n const baseRule = `${rule.selector} { ${innerContent} }`;\n\n let fullRule = baseRule;\n if (rule.atRules && rule.atRules.length > 0) {\n fullRule = rule.atRules.reduce(\n (css, atRule) => `${atRule} { ${css} }`,\n baseRule,\n );\n }\n\n cssRules.push(fullRule);\n }\n\n return cssRules.join('\\n');\n}\n"],"mappings":";;AAsBA,MAAM,aAAa;AAEnB,IAAI,mBAA8C;;;;;AAMlD,SAAgB,2BAA2B,IAA8B;AACvE,oBAAmB;;;;;;AAOrB,SAAgB,iCAAiC,IAA8B;AAC5E,YAAuC,cAAc;;;;;AAMxD,SAAgB,4BAAyD;AACvE,KAAI,iBAAkB,QAAO,kBAAkB;CAC/C,MAAM,SAAU,WAAuC;AAGvD,QAAO,SAAS,QAAQ,GAAG;;;;;;;;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AAW,KAAK,QAAQ,SAAS,EACxC,YAAW,KAAK,QAAQ,QACrB,KAAK,WAAW,GAAG,OAAO,KAAK,IAAI,KACpC,SACD;AAGH,WAAS,KAAK,SAAS;;AAGzB,QAAO,SAAS,KAAK,KAAK"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { s as getGlobalInjector } from "./config-A237aY9H.js";
|
|
2
|
+
//#region src/ssr/hydrate.ts
|
|
3
|
+
/**
|
|
4
|
+
* Client-side cache hydration for SSR/RSC.
|
|
5
|
+
*
|
|
6
|
+
* Pre-populates the client injector's rules map with class names
|
|
7
|
+
* rendered on the server. With hash-based naming, the client derives
|
|
8
|
+
* the same class name from the same cache key, so only the class name
|
|
9
|
+
* list needs to cross the wire — no cache keys or counters.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Pre-populate the client-side style registry from the server's class name list.
|
|
13
|
+
*
|
|
14
|
+
* Call this before ReactDOM.hydrateRoot() or ensure it runs before
|
|
15
|
+
* any tasty() component renders on the client.
|
|
16
|
+
*
|
|
17
|
+
* When called without arguments, reads the class list from `window.__TASTY__`
|
|
18
|
+
* (populated by inline scripts emitted during SSR/RSC streaming).
|
|
19
|
+
*/
|
|
20
|
+
function hydrateTastyClasses(classes) {
|
|
21
|
+
if (typeof document === "undefined") return;
|
|
22
|
+
if (!classes) classes = typeof window !== "undefined" ? window.__TASTY__ : void 0;
|
|
23
|
+
if (!classes?.length) return;
|
|
24
|
+
const registry = getGlobalInjector()._sheetManager.getRegistry(document);
|
|
25
|
+
for (const cls of classes) if (!registry.rules.has(cls)) {
|
|
26
|
+
registry.rules.set(cls, {
|
|
27
|
+
className: cls,
|
|
28
|
+
ruleIndex: -2,
|
|
29
|
+
sheetIndex: -2
|
|
30
|
+
});
|
|
31
|
+
registry.refCounts.set(cls, 0);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @deprecated Use `hydrateTastyClasses()` instead. This alias exists
|
|
36
|
+
* for backwards compatibility and will be removed in a future major version.
|
|
37
|
+
*/
|
|
38
|
+
function hydrateTastyCache(state) {
|
|
39
|
+
if (state?.entries) hydrateTastyClasses(Object.values(state.entries));
|
|
40
|
+
else hydrateTastyClasses();
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { hydrateTastyClasses as n, hydrateTastyCache as t };
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=hydrate-miFzWIKR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydrate-miFzWIKR.js","names":[],"sources":["../src/ssr/hydrate.ts"],"sourcesContent":["/**\n * Client-side cache hydration for SSR/RSC.\n *\n * Pre-populates the client injector's rules map with class names\n * rendered on the server. With hash-based naming, the client derives\n * the same class name from the same cache key, so only the class name\n * list needs to cross the wire — no cache keys or counters.\n */\n\nimport { getGlobalInjector } from '../config';\nimport { HYDRATED_RULE_INDEX } from '../injector/types';\n\n/**\n * Pre-populate the client-side style registry from the server's class name list.\n *\n * Call this before ReactDOM.hydrateRoot() or ensure it runs before\n * any tasty() component renders on the client.\n *\n * When called without arguments, reads the class list from `window.__TASTY__`\n * (populated by inline scripts emitted during SSR/RSC streaming).\n */\nexport function hydrateTastyClasses(classes?: string[]): void {\n if (typeof document === 'undefined') return;\n\n if (!classes) {\n classes = typeof window !== 'undefined' ? window.__TASTY__ : undefined;\n }\n\n if (!classes?.length) return;\n\n const injector = getGlobalInjector();\n const registry = injector._sheetManager.getRegistry(document);\n\n for (const cls of classes) {\n if (!registry.rules.has(cls)) {\n registry.rules.set(cls, {\n className: cls,\n ruleIndex: HYDRATED_RULE_INDEX,\n sheetIndex: HYDRATED_RULE_INDEX,\n });\n registry.refCounts.set(cls, 0);\n }\n }\n}\n\n/**\n * @deprecated Use `hydrateTastyClasses()` instead. This alias exists\n * for backwards compatibility and will be removed in a future major version.\n */\nexport function hydrateTastyCache(state?: {\n entries?: Record<string, string>;\n}): void {\n if (state?.entries) {\n hydrateTastyClasses(Object.values(state.entries));\n } else {\n hydrateTastyClasses();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,oBAAoB,SAA0B;AAC5D,KAAI,OAAO,aAAa,YAAa;AAErC,KAAI,CAAC,QACH,WAAU,OAAO,WAAW,cAAc,OAAO,YAAY,KAAA;AAG/D,KAAI,CAAC,SAAS,OAAQ;CAGtB,MAAM,WADW,mBAAmB,CACV,cAAc,YAAY,SAAS;AAE7D,MAAK,MAAM,OAAO,QAChB,KAAI,CAAC,SAAS,MAAM,IAAI,IAAI,EAAE;AAC5B,WAAS,MAAM,IAAI,KAAK;GACtB,WAAW;GACX,WAAA;GACA,YAAA;GACD,CAAC;AACF,WAAS,UAAU,IAAI,KAAK,EAAE;;;;;;;AASpC,SAAgB,kBAAkB,OAEzB;AACP,KAAI,OAAO,QACT,qBAAoB,OAAO,OAAO,MAAM,QAAQ,CAAC;KAEjD,sBAAqB"}
|