@tenphi/tasty 3.14.0 → 3.16.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/dist/{babel-types-docs8f4c.d.ts → babel-types-CCAgO9ZM.d.ts} +2 -2
- package/dist/chunks/{build-config-DmSCYjYl.js → build-config-BTMXiCMW.js} +5 -5
- package/dist/chunks/{build-config-DmSCYjYl.js.map → build-config-BTMXiCMW.js.map} +1 -1
- package/dist/chunks/{collector-8w5r-xFl.js → collector-Dit2r0Jc.js} +4 -4
- package/dist/chunks/{collector-8w5r-xFl.js.map → collector-Dit2r0Jc.js.map} +1 -1
- package/dist/chunks/{config-engine-DjRv6Axa.js → config-engine-IYvCVLNM.js} +4 -4
- package/dist/chunks/{config-engine-DjRv6Axa.js.map → config-engine-IYvCVLNM.js.map} +1 -1
- package/dist/chunks/{css-definitions-_UidGa56.js → css-definitions-D6ToG43M.js} +3 -3
- package/dist/chunks/{css-definitions-_UidGa56.js.map → css-definitions-D6ToG43M.js.map} +1 -1
- package/dist/chunks/{debug-DjK_ggek.js → debug-BmIXavn5.js} +4 -4
- package/dist/chunks/{debug-DjK_ggek.js.map → debug-BmIXavn5.js.map} +1 -1
- package/dist/chunks/{dsl-rgu6XQcD.js → dsl-CsFl9LGn.js} +82 -10
- package/dist/chunks/dsl-CsFl9LGn.js.map +1 -0
- package/dist/chunks/{react-runtime-DMLdIO3J.js → react-runtime-B52DjXFu.js} +5 -5
- package/dist/chunks/{react-runtime-DMLdIO3J.js.map → react-runtime-B52DjXFu.js.map} +1 -1
- package/dist/chunks/{runtime-engine-CGO46QGS.js → runtime-engine-rlmL8Koo.js} +6 -6
- package/dist/chunks/{runtime-engine-CGO46QGS.js.map → runtime-engine-rlmL8Koo.js.map} +1 -1
- package/dist/chunks/{runtime-state-C8MzPjBR.js → runtime-state-CB3ZPAKl.js} +2 -2
- package/dist/chunks/{runtime-state-C8MzPjBR.js.map → runtime-state-CB3ZPAKl.js.map} +1 -1
- package/dist/chunks/{style-engine-DoGrZPBB.js → style-engine-Cq7kL3Xh.js} +41 -9
- package/dist/chunks/style-engine-Cq7kL3Xh.js.map +1 -0
- package/dist/chunks/{zero-engine-CiVidroC.js → zero-engine-B1PkpmG-.js} +5 -5
- package/dist/chunks/{zero-engine-CiVidroC.js.map → zero-engine-B1PkpmG-.js.map} +1 -1
- package/dist/{collector-CTU-nl0g.d.ts → collector-C6RV9oQV.d.ts} +2 -2
- package/dist/{config-DDY7NlZ1.d.ts → config-RsgpMdyc.d.ts} +2 -2
- package/dist/core/index.d.ts +4 -4
- package/dist/core/index.js +7 -7
- package/dist/{index-BR0HTOim.d.ts → index-CDRJqQIM.d.ts} +5 -5
- package/dist/index.d.ts +4 -4
- package/dist/index.js +8 -8
- package/dist/{merge-styles-DSkVc6CD.d.ts → merge-styles-CkJeO9AJ.d.ts} +2 -2
- package/dist/ssr/astro.js +2 -2
- package/dist/ssr/index.d.ts +1 -1
- package/dist/ssr/index.js +2 -2
- package/dist/ssr/next-config.d.ts +1 -1
- package/dist/ssr/next-config.js +3 -3
- package/dist/ssr/next.d.ts +1 -1
- package/dist/ssr/next.js +3 -3
- package/dist/static/index.d.ts +2 -2
- package/dist/{types-DJEM_BOJ.d.ts → types-DeVUQ6o-.d.ts} +5 -3
- package/dist/zero/babel.d.ts +1 -1
- package/dist/zero/babel.js +4 -4
- package/dist/zero/index.d.ts +3 -3
- package/dist/zero/index.js +3 -3
- package/dist/zero/next.d.ts +1 -1
- package/docs/ai-agents.md +2 -1
- package/docs/dsl.md +52 -0
- package/docs/react-api.md +1 -1
- package/docs/styles.md +53 -3
- package/package.json +8 -8
- package/dist/chunks/dsl-rgu6XQcD.js.map +0 -1
- package/dist/chunks/style-engine-DoGrZPBB.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debug-DjK_ggek.js","names":[],"sources":["../../src/debug.ts"],"sourcesContent":["/* eslint-disable no-console */\nimport { CHUNK_NAMES } from './chunks/definitions';\nimport { getNamePrefix } from './config';\nimport { flushStyles, getCSSTextForNode, injector } from './injector';\nimport type { CacheMetrics, RootRegistry } from './injector/types';\nimport { tastyClassRegex } from './utils/name-prefix';\n\ndeclare global {\n interface Window {\n tastyDebug?: typeof tastyDebug;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\ntype CSSTarget =\n 'all' | 'global' | 'active' | 'unused' | 'page' | string | string[] | Element;\n\nexport interface DebugOptions {\n root?: Document | ShadowRoot;\n /** Suppress console logging and return data only (default: false) */\n raw?: boolean;\n}\n\nexport interface CSSOptions extends DebugOptions {\n prettify?: boolean;\n /** Read from stored source CSS (dev-mode only) instead of live CSSOM */\n source?: boolean;\n}\n\nexport interface DebugChunkInfo {\n className: string;\n chunkName: string | null;\n}\n\nexport interface InspectResult {\n element?: Element | null;\n classes: string[];\n chunks: DebugChunkInfo[];\n css: string;\n size: number;\n rules: number;\n}\n\nexport interface CacheStatus {\n classes: {\n active: string[];\n unused: string[];\n all: string[];\n };\n metrics: CacheMetrics | null;\n}\n\nexport interface ChunkBreakdown {\n byChunk: Record<\n string,\n { classes: string[]; cssSize: number; ruleCount: number }\n >;\n totalChunkTypes: number;\n totalClasses: number;\n}\n\nexport interface Summary {\n activeClasses: string[];\n /** Classes `gc({ force: true })` would delete right now. */\n unusedClasses: string[];\n /**\n * Held but in neither list: nothing renders them, yet collection will not\n * take them — inside the grace window, or pinned by an `inject()` handle.\n */\n hotClasses: string[];\n totalStyledClasses: string[];\n\n activeCSSSize: number;\n unusedCSSSize: number;\n globalCSSSize: number;\n rawCSSSize: number;\n keyframesCSSSize: number;\n propertyCSSSize: number;\n totalCSSSize: number;\n\n activeRuleCount: number;\n unusedRuleCount: number;\n globalRuleCount: number;\n rawRuleCount: number;\n keyframesRuleCount: number;\n propertyRuleCount: number;\n totalRuleCount: number;\n\n metrics: CacheMetrics | null;\n definedProperties: string[];\n definedKeyframes: { name: string; refCount: number }[];\n chunkBreakdown: ChunkBreakdown;\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\nfunction fmtSize(bytes: number): string {\n return bytes > 1024 ? `${(bytes / 1024).toFixed(1)}KB` : `${bytes}B`;\n}\n\nfunction countRules(css: string): number {\n return (css.match(/\\{[^}]*\\}/g) || []).length;\n}\n\nfunction sortTastyClasses(classes: Iterable<string>): string[] {\n // Class names use a base36 hash format (e.g. `t3a5f`), so sort lexicographically.\n return Array.from(classes).sort((a, b) => a.localeCompare(b));\n}\n\n/** A DOM root to read, or `null` when the environment has no DOM at all. */\ntype DebugRoot = Document | ShadowRoot | null;\n\n/**\n * The root these helpers read, or `null` where there is no DOM.\n *\n * `document` used to be a default parameter value, and a default is evaluated\n * at the call site — so every read below threw a bare `ReferenceError` under\n * Node, taking out five of the eight public methods. A debug utility must not\n * be able to fail an SSR render because a call was left in, so the DOM-less\n * case reports an empty result and says why.\n */\nfunction defaultRoot(): DebugRoot {\n return typeof document === 'undefined' ? null : document;\n}\n\nlet warnedNoDom = false;\n\n/** Say once why the numbers are empty. Silent under `{ raw: true }`. */\nfunction warnNoDom(raw: boolean): void {\n if (raw || warnedNoDom) return;\n warnedNoDom = true;\n console.warn(\n '[Tasty] tastyDebug reads the DOM and this environment has none, so the ' +\n 'result is empty. During SSR, read the ServerStyleCollector instead.',\n );\n}\n\n/**\n * The registry for `root`, with every queued write landed first.\n *\n * Every injector read API is a flush point, and the reads below reach past\n * those APIs straight into the registry and the sheet manager. Without this\n * they would report a batch window's contents as absent — a rule that is\n * enqueued but not yet in a sheet is missing from `globalRules`, from the\n * sheets, and from anything counting either.\n */\nfunction getRegistry(\n root: DebugRoot = defaultRoot(),\n): RootRegistry | undefined {\n if (!root) return undefined;\n flushStyles();\n\n return injector.instance._sheetManager?.getRegistry(root);\n}\n\nfunction findDomTastyClasses(root: DebugRoot = defaultRoot()): string[] {\n if (!root) return [];\n const classes = new Set<string>();\n const elements = (root as Document).querySelectorAll?.('[class]') || [];\n const classRegex = tastyClassRegex(getNamePrefix());\n for (const element of elements) {\n const attribute = element.getAttribute('class');\n if (!attribute) continue;\n for (const className of attribute.split(/\\s+/)) {\n if (classRegex.test(className)) classes.add(className);\n }\n }\n return sortTastyClasses(classes);\n}\n\n/**\n * Everything this injector holds in `root`, in the order the engine applies it,\n * with the sources kept byte-for-byte — trimming would report a total smaller\n * than one of its own parts whenever raw CSS has edge whitespace.\n */\nfunction getAllCSS(root: DebugRoot = defaultRoot()): string {\n const registry = getRegistry(root);\n const sheetManager = injector.instance._sheetManager;\n // `getRegistry` already returns nothing for a null root; the `!root` is what\n // narrows the type for the call below.\n if (!root || !registry || !sheetManager) return '';\n\n return sheetManager.getOwnedCSSInOrder(registry, root).join('\\n');\n}\n\n/**\n * The injector's own readers fall back to `document` when `root` is omitted, so\n * they have to be reached with a real root or not at all.\n */\nfunction cssTextForClasses(classNames: string[], root: DebugRoot): string {\n if (!root) return '';\n\n return injector.instance.getCSSTextForClasses(classNames, { root });\n}\n\nfunction getInjectorMetrics(root: DebugRoot): CacheMetrics | null {\n if (!root) return null;\n\n return injector.instance.getMetrics({ root });\n}\n\n/**\n * Injected classes that no element carries and nobody pinned — the exact set\n * `gc({ force: true })` would delete.\n *\n * Deliberately borrowed from the injector rather than recomputed here: the two\n * drifted apart once before, when this file still read \"unused\" off the pin\n * counts the render path had stopped maintaining.\n */\nfunction getUnusedClasses(root: DebugRoot = defaultRoot()): string[] {\n if (!root) return [];\n\n return sortTastyClasses(injector.instance.getUnusedClasses({ root }));\n}\n\n/** Every class this injector holds CSS for in `root`. */\nfunction getOwnedClasses(root: DebugRoot = defaultRoot()): string[] {\n const registry = getRegistry(root);\n if (!registry) return [];\n\n const owned: string[] = [];\n for (const [className, info] of registry.rules) {\n // A negative sheet index marks a class whose CSS this injector does not\n // hold: server-rendered, pre-allocated, or queued.\n if (info.sheetIndex >= 0) owned.push(className);\n }\n\n return sortTastyClasses(owned);\n}\n\n// ---------------------------------------------------------------------------\n// prettifyCSS — readable output for nested rules\n// ---------------------------------------------------------------------------\n\nfunction prettifyCSS(css: string): string {\n if (!css || !css.trim()) return '';\n\n const out: string[] = [];\n let depth = 0;\n\n const lines = css\n .replace(/\\s+/g, ' ')\n .trim()\n .replaceAll(' {', '{')\n .replaceAll('{', ' {\\n')\n .replaceAll('}', '\\n}\\n')\n .replaceAll(';', ';\\n')\n .split('\\n');\n\n for (let line of lines) {\n line = line.trim();\n if (!line) continue;\n\n if (line === '}') {\n const last = out.at(-1);\n if (last && !/[;{}]$/.test(last)) {\n out[out.length - 1] += ';';\n }\n depth = Math.max(0, depth - 1);\n }\n out.push(`${' '.repeat(depth)}${line}`);\n if (line.endsWith('{')) depth++;\n }\n\n return out.join('\\n');\n}\n\n// ---------------------------------------------------------------------------\n// Chunk helpers\n// ---------------------------------------------------------------------------\n\nfunction extractChunkName(cacheKey: string): string | null {\n for (const part of cacheKey.split('\\0')) {\n if (part.startsWith('[states:')) continue;\n if (!part.includes(':') && part.length > 0) return part;\n }\n return null;\n}\n\nfunction getChunkForClass(\n className: string,\n root: DebugRoot = defaultRoot(),\n): string | null {\n const registry = getRegistry(root);\n if (!registry) return null;\n for (const [key, cn] of registry.cacheKeyToClassName) {\n if (cn === className) return extractChunkName(key);\n }\n return null;\n}\n\nfunction buildChunkBreakdown(root: DebugRoot = defaultRoot()): ChunkBreakdown {\n const registry = getRegistry(root);\n if (!root || !registry)\n return { byChunk: {}, totalChunkTypes: 0, totalClasses: 0 };\n\n const byChunk: ChunkBreakdown['byChunk'] = {};\n for (const [cacheKey, className] of registry.cacheKeyToClassName) {\n const chunk = extractChunkName(cacheKey) || 'unknown';\n const entry = (byChunk[chunk] ??= {\n classes: [],\n cssSize: 0,\n ruleCount: 0,\n });\n entry.classes.push(className);\n const css = cssTextForClasses([className], root);\n entry.cssSize += css.length;\n entry.ruleCount += countRules(css);\n }\n\n const entries = Object.values(byChunk);\n for (const entry of entries) {\n entry.classes = sortTastyClasses(entry.classes);\n }\n\n const totalClasses = entries.reduce((sum, entry) => {\n return sum + entry.classes.length;\n }, 0);\n return {\n byChunk,\n totalChunkTypes: Object.keys(byChunk).length,\n totalClasses,\n };\n}\n\n// ---------------------------------------------------------------------------\n// Global-type CSS helper (internal only)\n// ---------------------------------------------------------------------------\n\n/**\n * Every prefix `registry.globalRules` is keyed by. Anything missing here is a\n * rule the summary would hold but never count, which is how the totals stopped\n * adding up the first time.\n */\nconst GLOBAL_RULE_PREFIXES = {\n global: 'global:',\n property: 'property:',\n fontFace: 'fontface:',\n counterStyle: 'counterstyle:',\n function: 'function:',\n} as const;\n\nfunction getGlobalTypeCSS(\n type: keyof typeof GLOBAL_RULE_PREFIXES | 'raw' | 'keyframes',\n root: DebugRoot = defaultRoot(),\n includeCSS = true,\n): { css: string; ruleCount: number; size: number } {\n const registry = getRegistry(root);\n if (!root || !registry) return { css: '', ruleCount: 0, size: 0 };\n\n const chunks: string[] = [];\n const sheetManager = injector.instance._sheetManager;\n let rc = 0;\n\n if (type === 'raw') {\n // Raw blocks are kept by the sheet manager, not in `globalRules`, so the\n // prefix scan below never sees them — and their rules are counted from the\n // parsed sheet, since one raw block is one string but any number of rules.\n const css = injector.instance.getRawCSSText({ root });\n\n return {\n css: includeCSS ? prettifyCSS(css) : '',\n ruleCount: sheetManager?.getRawRuleCount(root) ?? 0,\n size: css.length,\n };\n }\n\n if (type === 'keyframes') {\n for (const [, entry] of registry.keyframesCache) {\n const info = entry.info;\n const sheetInfo = registry.sheets[info.sheetIndex];\n const ss =\n sheetInfo && sheetManager ? sheetManager.getCSSSheet(sheetInfo) : null;\n if (ss && info.ruleIndex < ss.cssRules.length) {\n const rule = ss.cssRules[info.ruleIndex];\n if (rule) {\n chunks.push(rule.cssText);\n rc++;\n }\n } else if (info.cssText) {\n chunks.push(info.cssText);\n rc++;\n }\n }\n } else {\n const prefix = GLOBAL_RULE_PREFIXES[type];\n for (const [key, ri] of registry.globalRules) {\n if (!key.startsWith(prefix)) continue;\n const sheetInfo = registry.sheets[ri.sheetIndex];\n const ss =\n sheetInfo && sheetManager ? sheetManager.getCSSSheet(sheetInfo) : null;\n if (ss) {\n const start = Math.max(0, ri.ruleIndex);\n const end = Math.min(\n ss.cssRules.length - 1,\n (ri.endRuleIndex as number) ?? ri.ruleIndex,\n );\n if (start >= 0 && end >= start && start < ss.cssRules.length) {\n for (let i = start; i <= end; i++) {\n const rule = ss.cssRules[i];\n if (rule) {\n chunks.push(rule.cssText);\n rc++;\n }\n }\n }\n } else if (ri.cssText?.length) {\n chunks.push(...ri.cssText);\n rc += ri.cssText.length;\n }\n }\n }\n\n const raw = chunks.join('\\n');\n return {\n css: includeCSS ? prettifyCSS(raw) : '',\n ruleCount: rc,\n size: raw.length,\n };\n}\n\n// ---------------------------------------------------------------------------\n// Source CSS (dev-mode RuleInfo.cssText)\n// ---------------------------------------------------------------------------\n\nfunction getSourceCssForClasses(\n classNames: string[],\n root: DebugRoot = defaultRoot(),\n): string | null {\n const registry = getRegistry(root);\n if (!registry) return null;\n\n const chunks: string[] = [];\n let found = false;\n for (const cls of classNames) {\n const info = registry.rules.get(cls);\n if (info?.cssText?.length) {\n chunks.push(...info.cssText);\n found = true;\n }\n }\n return found ? chunks.join('\\n') : null;\n}\n\n// ---------------------------------------------------------------------------\n// Definitions helper (internal)\n// ---------------------------------------------------------------------------\n\nfunction getDefs(root: DebugRoot = defaultRoot()) {\n const registry = getRegistry(root);\n let properties: string[] = [];\n if (registry?.injectedProperties) {\n properties = Array.from(\n (registry.injectedProperties as Map<string, string>).keys(),\n ).sort();\n }\n\n const keyframes: { name: string; refCount: number }[] = [];\n if (registry) {\n for (const entry of registry.keyframesCache.values()) {\n keyframes.push({ name: entry.name, refCount: entry.refCount });\n }\n keyframes.sort((a, b) => a.name.localeCompare(b.name));\n }\n\n return { properties, keyframes };\n}\n\n// ---------------------------------------------------------------------------\n// Chunk display order\n// ---------------------------------------------------------------------------\n\nconst CHUNK_ORDER = [\n CHUNK_NAMES.COMBINED,\n CHUNK_NAMES.APPEARANCE,\n CHUNK_NAMES.FONT,\n CHUNK_NAMES.DIMENSION,\n CHUNK_NAMES.DISPLAY,\n CHUNK_NAMES.LAYOUT,\n CHUNK_NAMES.POSITION,\n CHUNK_NAMES.MISC,\n CHUNK_NAMES.SUBCOMPONENTS,\n];\n\nfunction logChunkEntries(breakdown: ChunkBreakdown): void {\n for (const name of CHUNK_ORDER) {\n const data = breakdown.byChunk[name];\n if (data)\n console.log(\n ` ${name}: ${data.classes.length} cls, ${data.ruleCount} rules, ${fmtSize(data.cssSize)}`,\n );\n }\n for (const [name, data] of Object.entries(breakdown.byChunk)) {\n if (!CHUNK_ORDER.includes(name as (typeof CHUNK_ORDER)[number]))\n console.log(\n ` ${name}: ${data.classes.length} cls, ${data.ruleCount} rules, ${fmtSize(data.cssSize)}`,\n );\n }\n}\n\n// ---------------------------------------------------------------------------\n// tastyDebug API\n// ---------------------------------------------------------------------------\n\nexport const tastyDebug = {\n css(target: CSSTarget, opts?: CSSOptions): string {\n const {\n root = defaultRoot(),\n prettify = true,\n raw = false,\n source = false,\n } = opts || {};\n if (!root) {\n warnNoDom(raw);\n\n return '';\n }\n let css = '';\n\n const classRegex = tastyClassRegex(getNamePrefix());\n if (source && typeof target === 'string' && classRegex.test(target)) {\n const src = getSourceCssForClasses([target], root);\n if (src) {\n css = src;\n } else {\n if (!raw) {\n console.warn(\n '[Tasty] source CSS not available (requires dev mode or TASTY_DEBUG=true). Falling back to live CSSOM.',\n );\n }\n css = cssTextForClasses([target], root);\n }\n } else if (source && Array.isArray(target)) {\n const src = getSourceCssForClasses(target, root);\n if (src) {\n css = src;\n } else {\n if (!raw) {\n console.warn(\n '[Tasty] source CSS not available. Falling back to live CSSOM.',\n );\n }\n css = cssTextForClasses(target, root);\n }\n } else if (typeof target === 'string') {\n if (target === 'all') {\n // Documented as component + global + raw, and raw has its own sheet.\n css = getAllCSS(root);\n } else if (target === 'global') {\n css = getGlobalTypeCSS('global', root).css;\n return css; // already prettified\n } else if (target === 'active') {\n const active = findDomTastyClasses(root);\n css = cssTextForClasses(active, root);\n } else if (target === 'unused') {\n const unused = getUnusedClasses(root);\n css = cssTextForClasses(unused, root);\n } else if (target === 'page') {\n css = getPageCSS(root);\n } else if (classRegex.test(target)) {\n css = cssTextForClasses([target], root);\n } else {\n const el = (root as Document).querySelector?.(target);\n if (el) css = getCSSTextForNode(el, { root });\n }\n } else if (Array.isArray(target)) {\n css = cssTextForClasses(target, root);\n } else if (target instanceof Element) {\n css = getCSSTextForNode(target, { root });\n }\n\n const result = prettify ? prettifyCSS(css) : css;\n\n if (!raw) {\n const label = Array.isArray(target) ? `[${target.join(', ')}]` : target;\n const rc = countRules(css);\n console.group(`CSS for ${label} (${rc} rules, ${fmtSize(css.length)})`);\n console.log(result || '(empty)');\n console.groupEnd();\n }\n\n return result;\n },\n\n inspect(target: string | Element, opts?: DebugOptions): InspectResult {\n const { root = defaultRoot(), raw = false } = opts || {};\n const element = !root\n ? null\n : typeof target === 'string'\n ? (root as Document).querySelector?.(target)\n : target;\n if (!root) warnNoDom(raw);\n\n if (!element) {\n const empty: InspectResult = {\n element: null,\n classes: [],\n chunks: [],\n css: '',\n size: 0,\n rules: 0,\n };\n // With no DOM at all, `warnNoDom` above already said why; \"element not\n // found\" would only misdirect.\n if (!raw && root)\n console.warn('[Tasty] debug.inspect: element not found');\n return empty;\n }\n\n const classList = element.getAttribute('class') || '';\n const classRegex = tastyClassRegex(getNamePrefix());\n const tastyClasses = classList\n .split(/\\s+/)\n .filter((cls) => classRegex.test(cls));\n\n const chunks: DebugChunkInfo[] = tastyClasses.map((className) => ({\n className,\n chunkName: getChunkForClass(className, root),\n }));\n\n const css = getCSSTextForNode(element, { root: root ?? undefined });\n const rules = countRules(css);\n\n const result: InspectResult = {\n element,\n classes: tastyClasses,\n chunks,\n css: prettifyCSS(css),\n size: css.length,\n rules,\n };\n\n if (!raw) {\n const tag = element.tagName.toLowerCase();\n const id = element.id ? `#${element.id}` : '';\n console.group(\n `inspect ${tag}${id} — ${tastyClasses.length} classes, ${rules} rules, ${fmtSize(css.length)}`,\n );\n if (chunks.length) {\n console.log(\n 'Chunks:',\n chunks.map((c) => `${c.className}→${c.chunkName || '?'}`).join(', '),\n );\n }\n console.groupCollapsed('CSS');\n console.log(result.css || '(empty)');\n console.groupEnd();\n console.groupEnd();\n }\n\n return result;\n },\n\n summary(opts?: DebugOptions): Summary {\n const { root = defaultRoot(), raw = false } = opts || {};\n if (!root) warnNoDom(raw);\n\n const activeClasses = findDomTastyClasses(root);\n const unusedClasses = getUnusedClasses(root);\n // Everything, not just the two bands above: a class that went cold a\n // moment ago is in neither, and dropping it here is the accounting failure\n // this whole change started from.\n const ownedClasses = getOwnedClasses(root);\n const totalStyledClasses = sortTastyClasses(\n new Set([...activeClasses, ...ownedClasses]),\n );\n const unusedSet = new Set(unusedClasses);\n const activeSet = new Set(activeClasses);\n const hotClasses = ownedClasses.filter(\n (className) => !activeSet.has(className) && !unusedSet.has(className),\n );\n const hotCSS = cssTextForClasses(hotClasses, root);\n\n const activeCSS = cssTextForClasses(activeClasses, root);\n const unusedCSS = cssTextForClasses(unusedClasses, root);\n const allCSS = getAllCSS(root);\n\n const activeRuleCount = countRules(activeCSS);\n const unusedRuleCount = countRules(unusedCSS);\n\n const globalData = getGlobalTypeCSS('global', root, false);\n const rawData = getGlobalTypeCSS('raw', root, false);\n const kfData = getGlobalTypeCSS('keyframes', root, false);\n const propData = getGlobalTypeCSS('property', root, false);\n // Folded into the global line rather than given their own: they are all\n // at-rules injected once and kept forever, and leaving them out of the\n // total is what made it not a total.\n const atRuleData = (\n ['fontFace', 'counterStyle', 'function'] as const\n ).reduce(\n (total, type) => {\n const data = getGlobalTypeCSS(type, root, false);\n total.ruleCount += data.ruleCount;\n total.size += data.size;\n return total;\n },\n { ruleCount: 0, size: 0 },\n );\n\n const hotRuleCount = countRules(hotCSS);\n const globalRuleCount = globalData.ruleCount + atRuleData.ruleCount;\n const globalCSSSize = globalData.size + atRuleData.size;\n\n const totalRuleCount =\n activeRuleCount +\n unusedRuleCount +\n hotRuleCount +\n globalRuleCount +\n rawData.ruleCount +\n kfData.ruleCount +\n propData.ruleCount;\n\n const metrics = getInjectorMetrics(root);\n const defs = getDefs(root);\n const chunkBreakdown = buildChunkBreakdown(root);\n\n const summary: Summary = {\n activeClasses,\n unusedClasses,\n hotClasses,\n totalStyledClasses,\n activeCSSSize: activeCSS.length,\n unusedCSSSize: unusedCSS.length,\n globalCSSSize,\n rawCSSSize: rawData.size,\n keyframesCSSSize: kfData.size,\n propertyCSSSize: propData.size,\n totalCSSSize: allCSS.length,\n activeRuleCount,\n unusedRuleCount,\n globalRuleCount,\n rawRuleCount: rawData.ruleCount,\n keyframesRuleCount: kfData.ruleCount,\n propertyRuleCount: propData.ruleCount,\n totalRuleCount,\n metrics,\n definedProperties: defs.properties,\n definedKeyframes: defs.keyframes,\n chunkBreakdown,\n };\n\n if (!raw) {\n console.group('Tasty Summary');\n console.log(\n `Active: ${activeClasses.length} classes, ${activeRuleCount} rules, ${fmtSize(activeCSS.length)}`,\n );\n console.log(\n `Unused: ${unusedClasses.length} classes, ${unusedRuleCount} rules, ${fmtSize(unusedCSS.length)}`,\n );\n if (hotClasses.length)\n console.log(\n `Held: ${hotClasses.length} classes, ${hotRuleCount} rules, ${fmtSize(hotCSS.length)} (not rendered, not yet collectable)`,\n );\n console.log(\n `Global: ${globalRuleCount} rules, ${fmtSize(globalCSSSize)}`,\n );\n if (rawData.ruleCount)\n console.log(\n `Raw: ${rawData.ruleCount} rules, ${fmtSize(rawData.size)}`,\n );\n if (kfData.ruleCount)\n console.log(\n `Keyframes: ${kfData.ruleCount} rules, ${fmtSize(kfData.size)}`,\n );\n if (propData.ruleCount)\n console.log(\n `@property: ${propData.ruleCount} rules, ${fmtSize(propData.size)}`,\n );\n console.log(\n `Total: ${totalStyledClasses.length} classes, ${totalRuleCount} rules, ${fmtSize(allCSS.length)}`,\n );\n\n if (metrics) {\n const total = metrics.hits + metrics.misses;\n const rate = total > 0 ? ((metrics.hits / total) * 100).toFixed(1) : 0;\n console.log(`Cache: ${rate}% hit rate (${total} lookups)`);\n }\n\n if (chunkBreakdown.totalChunkTypes > 0) {\n console.groupCollapsed(\n `Chunks (${chunkBreakdown.totalChunkTypes} types, ${chunkBreakdown.totalClasses} classes)`,\n );\n logChunkEntries(chunkBreakdown);\n console.groupEnd();\n }\n\n if (defs.properties.length || defs.keyframes.length) {\n console.log(\n `Defs: ${defs.properties.length} @property, ${defs.keyframes.length} @keyframes`,\n );\n }\n\n console.groupEnd();\n }\n\n return summary;\n },\n\n chunks(opts?: DebugOptions): ChunkBreakdown {\n const { root = defaultRoot(), raw = false } = opts || {};\n if (!root) warnNoDom(raw);\n const breakdown = buildChunkBreakdown(root);\n\n if (!raw) {\n console.group(\n `Chunks (${breakdown.totalChunkTypes} types, ${breakdown.totalClasses} classes)`,\n );\n logChunkEntries(breakdown);\n console.groupEnd();\n }\n\n return breakdown;\n },\n\n cache(opts?: DebugOptions): CacheStatus {\n const { root = defaultRoot(), raw = false } = opts || {};\n if (!root) warnNoDom(raw);\n const active = findDomTastyClasses(root);\n const unused = getUnusedClasses(root);\n const metrics = getInjectorMetrics(root);\n\n // `all` is everything held, not the two bands above: a class that went cold\n // a moment ago is in neither, and it is still taking up a sheet.\n const all = sortTastyClasses(\n new Set([...active, ...getOwnedClasses(root)]),\n );\n\n const status: CacheStatus = {\n classes: { active, unused, all },\n metrics,\n };\n\n if (!raw) {\n console.group('Cache');\n console.log(`Active: ${active.length}, Unused: ${unused.length}`);\n if (metrics) {\n const total = metrics.hits + metrics.misses;\n const rate = total > 0 ? ((metrics.hits / total) * 100).toFixed(1) : 0;\n console.log(\n `Hits: ${metrics.hits}, Misses: ${metrics.misses}, Rate: ${rate}%`,\n );\n }\n console.groupEnd();\n }\n\n return status;\n },\n\n cleanup(opts?: { root?: Document | ShadowRoot }): void {\n const root = opts?.root ?? defaultRoot();\n if (!root) return;\n injector.instance.cleanup(root);\n },\n\n help(): void {\n console.log(`tastyDebug API:\n .summary() — overview (classes, rules, sizes)\n .css(\"active\") — CSS for classes in DOM\n .css(\"t3a5f\") — CSS for a specific class\n .css(\"t3a5f\",{source:true}) — original CSS before browser parsing (dev only)\n .css(\".selector\") — CSS for a DOM element\n .inspect(\".selector\") — element details (classes, chunks, rules)\n .chunks() — style chunk breakdown\n .cache() — cache status and metrics\n .cleanup() — force unused style cleanup\nOptions: { raw: true } suppresses logging, { root: shadowRoot } targets Shadow DOM`);\n },\n\n install(): void {\n if (typeof window !== 'undefined' && window.tastyDebug !== tastyDebug) {\n window.tastyDebug = tastyDebug;\n console.log('tastyDebug installed. Run tastyDebug.help() for commands.');\n }\n },\n};\n\n// ---------------------------------------------------------------------------\n// Page CSS (minimal, kept internal)\n// ---------------------------------------------------------------------------\n\nfunction getPageCSS(root: DebugRoot = defaultRoot()): string {\n if (!root) return '';\n const chunks: string[] = [];\n try {\n if ('styleSheets' in root) {\n for (const sheet of Array.from((root as Document).styleSheets)) {\n try {\n if (sheet.cssRules)\n chunks.push(\n Array.from(sheet.cssRules)\n .map((r) => r.cssText)\n .join('\\n'),\n );\n } catch {\n /* cross-origin */\n }\n }\n }\n } catch {\n /* ignore */\n }\n return chunks.join('\\n');\n}\n"],"mappings":";;;;AAqGA,SAAS,QAAQ,OAAuB;CACtC,OAAO,QAAQ,OAAO,IAAI,QAAQ,KAAA,CAAM,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM;AACpE;AAEA,SAAS,WAAW,KAAqB;CACvC,QAAQ,IAAI,MAAM,YAAY,KAAK,CAAC,EAAA,CAAG;AACzC;AAEA,SAAS,iBAAiB,SAAqC;CAE7D,OAAO,MAAM,KAAK,OAAO,CAAC,CAAC,MAAM,GAAG,MAAM,EAAE,cAAc,CAAC,CAAC;AAC9D;AAcA,SAAS,cAAyB;CAChC,OAAO,OAAO,aAAa,cAAc,OAAO;AAClD;AAEA,IAAI,cAAc;AAGlB,SAAS,UAAU,KAAoB;CACrC,IAAI,OAA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AO,WAAW,eAAe,OAAO,eAAe,YAAY;GACrE,OAAO,aAAa;GACpB,QAAQ,IAAI,2DAA2D;EACzE;CACF;AACF;AAMA,SAAS,WAAW,OAAkB,YAAY,GAAW;CAC3D,IAAI,CAAC,MAAM,OAAO;CAClB,MAAM,SAAmB,CAAC;CAC1B,IAAI;EACF,IAAI,iBAAiB,MACnB,KAAK,MAAM,SAAS,MAAM,KAAM,KAAkB,WAAW,GAC3D,IAAI;GACF,IAAI,MAAM,UACR,OAAO,KACL,MAAM,KAAK,MAAM,QAAQ,CAAC,CACvB,KAAK,MAAM,EAAE,OAAO,CAAC,CACrB,KAAK,IAAI,CACd;EACJ,QAAQ,CAER;CAGN,QAAQ,CAER;CACA,OAAO,OAAO,KAAK,IAAI;AACzB"}
|
|
1
|
+
{"version":3,"file":"debug-BmIXavn5.js","names":[],"sources":["../../src/debug.ts"],"sourcesContent":["/* eslint-disable no-console */\nimport { CHUNK_NAMES } from './chunks/definitions';\nimport { getNamePrefix } from './config';\nimport { flushStyles, getCSSTextForNode, injector } from './injector';\nimport type { CacheMetrics, RootRegistry } from './injector/types';\nimport { tastyClassRegex } from './utils/name-prefix';\n\ndeclare global {\n interface Window {\n tastyDebug?: typeof tastyDebug;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\ntype CSSTarget =\n 'all' | 'global' | 'active' | 'unused' | 'page' | string | string[] | Element;\n\nexport interface DebugOptions {\n root?: Document | ShadowRoot;\n /** Suppress console logging and return data only (default: false) */\n raw?: boolean;\n}\n\nexport interface CSSOptions extends DebugOptions {\n prettify?: boolean;\n /** Read from stored source CSS (dev-mode only) instead of live CSSOM */\n source?: boolean;\n}\n\nexport interface DebugChunkInfo {\n className: string;\n chunkName: string | null;\n}\n\nexport interface InspectResult {\n element?: Element | null;\n classes: string[];\n chunks: DebugChunkInfo[];\n css: string;\n size: number;\n rules: number;\n}\n\nexport interface CacheStatus {\n classes: {\n active: string[];\n unused: string[];\n all: string[];\n };\n metrics: CacheMetrics | null;\n}\n\nexport interface ChunkBreakdown {\n byChunk: Record<\n string,\n { classes: string[]; cssSize: number; ruleCount: number }\n >;\n totalChunkTypes: number;\n totalClasses: number;\n}\n\nexport interface Summary {\n activeClasses: string[];\n /** Classes `gc({ force: true })` would delete right now. */\n unusedClasses: string[];\n /**\n * Held but in neither list: nothing renders them, yet collection will not\n * take them — inside the grace window, or pinned by an `inject()` handle.\n */\n hotClasses: string[];\n totalStyledClasses: string[];\n\n activeCSSSize: number;\n unusedCSSSize: number;\n globalCSSSize: number;\n rawCSSSize: number;\n keyframesCSSSize: number;\n propertyCSSSize: number;\n totalCSSSize: number;\n\n activeRuleCount: number;\n unusedRuleCount: number;\n globalRuleCount: number;\n rawRuleCount: number;\n keyframesRuleCount: number;\n propertyRuleCount: number;\n totalRuleCount: number;\n\n metrics: CacheMetrics | null;\n definedProperties: string[];\n definedKeyframes: { name: string; refCount: number }[];\n chunkBreakdown: ChunkBreakdown;\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\nfunction fmtSize(bytes: number): string {\n return bytes > 1024 ? `${(bytes / 1024).toFixed(1)}KB` : `${bytes}B`;\n}\n\nfunction countRules(css: string): number {\n return (css.match(/\\{[^}]*\\}/g) || []).length;\n}\n\nfunction sortTastyClasses(classes: Iterable<string>): string[] {\n // Class names use a base36 hash format (e.g. `t3a5f`), so sort lexicographically.\n return Array.from(classes).sort((a, b) => a.localeCompare(b));\n}\n\n/** A DOM root to read, or `null` when the environment has no DOM at all. */\ntype DebugRoot = Document | ShadowRoot | null;\n\n/**\n * The root these helpers read, or `null` where there is no DOM.\n *\n * `document` used to be a default parameter value, and a default is evaluated\n * at the call site — so every read below threw a bare `ReferenceError` under\n * Node, taking out five of the eight public methods. A debug utility must not\n * be able to fail an SSR render because a call was left in, so the DOM-less\n * case reports an empty result and says why.\n */\nfunction defaultRoot(): DebugRoot {\n return typeof document === 'undefined' ? null : document;\n}\n\nlet warnedNoDom = false;\n\n/** Say once why the numbers are empty. Silent under `{ raw: true }`. */\nfunction warnNoDom(raw: boolean): void {\n if (raw || warnedNoDom) return;\n warnedNoDom = true;\n console.warn(\n '[Tasty] tastyDebug reads the DOM and this environment has none, so the ' +\n 'result is empty. During SSR, read the ServerStyleCollector instead.',\n );\n}\n\n/**\n * The registry for `root`, with every queued write landed first.\n *\n * Every injector read API is a flush point, and the reads below reach past\n * those APIs straight into the registry and the sheet manager. Without this\n * they would report a batch window's contents as absent — a rule that is\n * enqueued but not yet in a sheet is missing from `globalRules`, from the\n * sheets, and from anything counting either.\n */\nfunction getRegistry(\n root: DebugRoot = defaultRoot(),\n): RootRegistry | undefined {\n if (!root) return undefined;\n flushStyles();\n\n return injector.instance._sheetManager?.getRegistry(root);\n}\n\nfunction findDomTastyClasses(root: DebugRoot = defaultRoot()): string[] {\n if (!root) return [];\n const classes = new Set<string>();\n const elements = (root as Document).querySelectorAll?.('[class]') || [];\n const classRegex = tastyClassRegex(getNamePrefix());\n for (const element of elements) {\n const attribute = element.getAttribute('class');\n if (!attribute) continue;\n for (const className of attribute.split(/\\s+/)) {\n if (classRegex.test(className)) classes.add(className);\n }\n }\n return sortTastyClasses(classes);\n}\n\n/**\n * Everything this injector holds in `root`, in the order the engine applies it,\n * with the sources kept byte-for-byte — trimming would report a total smaller\n * than one of its own parts whenever raw CSS has edge whitespace.\n */\nfunction getAllCSS(root: DebugRoot = defaultRoot()): string {\n const registry = getRegistry(root);\n const sheetManager = injector.instance._sheetManager;\n // `getRegistry` already returns nothing for a null root; the `!root` is what\n // narrows the type for the call below.\n if (!root || !registry || !sheetManager) return '';\n\n return sheetManager.getOwnedCSSInOrder(registry, root).join('\\n');\n}\n\n/**\n * The injector's own readers fall back to `document` when `root` is omitted, so\n * they have to be reached with a real root or not at all.\n */\nfunction cssTextForClasses(classNames: string[], root: DebugRoot): string {\n if (!root) return '';\n\n return injector.instance.getCSSTextForClasses(classNames, { root });\n}\n\nfunction getInjectorMetrics(root: DebugRoot): CacheMetrics | null {\n if (!root) return null;\n\n return injector.instance.getMetrics({ root });\n}\n\n/**\n * Injected classes that no element carries and nobody pinned — the exact set\n * `gc({ force: true })` would delete.\n *\n * Deliberately borrowed from the injector rather than recomputed here: the two\n * drifted apart once before, when this file still read \"unused\" off the pin\n * counts the render path had stopped maintaining.\n */\nfunction getUnusedClasses(root: DebugRoot = defaultRoot()): string[] {\n if (!root) return [];\n\n return sortTastyClasses(injector.instance.getUnusedClasses({ root }));\n}\n\n/** Every class this injector holds CSS for in `root`. */\nfunction getOwnedClasses(root: DebugRoot = defaultRoot()): string[] {\n const registry = getRegistry(root);\n if (!registry) return [];\n\n const owned: string[] = [];\n for (const [className, info] of registry.rules) {\n // A negative sheet index marks a class whose CSS this injector does not\n // hold: server-rendered, pre-allocated, or queued.\n if (info.sheetIndex >= 0) owned.push(className);\n }\n\n return sortTastyClasses(owned);\n}\n\n// ---------------------------------------------------------------------------\n// prettifyCSS — readable output for nested rules\n// ---------------------------------------------------------------------------\n\nfunction prettifyCSS(css: string): string {\n if (!css || !css.trim()) return '';\n\n const out: string[] = [];\n let depth = 0;\n\n const lines = css\n .replace(/\\s+/g, ' ')\n .trim()\n .replaceAll(' {', '{')\n .replaceAll('{', ' {\\n')\n .replaceAll('}', '\\n}\\n')\n .replaceAll(';', ';\\n')\n .split('\\n');\n\n for (let line of lines) {\n line = line.trim();\n if (!line) continue;\n\n if (line === '}') {\n const last = out.at(-1);\n if (last && !/[;{}]$/.test(last)) {\n out[out.length - 1] += ';';\n }\n depth = Math.max(0, depth - 1);\n }\n out.push(`${' '.repeat(depth)}${line}`);\n if (line.endsWith('{')) depth++;\n }\n\n return out.join('\\n');\n}\n\n// ---------------------------------------------------------------------------\n// Chunk helpers\n// ---------------------------------------------------------------------------\n\nfunction extractChunkName(cacheKey: string): string | null {\n for (const part of cacheKey.split('\\0')) {\n if (part.startsWith('[states:')) continue;\n if (!part.includes(':') && part.length > 0) return part;\n }\n return null;\n}\n\nfunction getChunkForClass(\n className: string,\n root: DebugRoot = defaultRoot(),\n): string | null {\n const registry = getRegistry(root);\n if (!registry) return null;\n for (const [key, cn] of registry.cacheKeyToClassName) {\n if (cn === className) return extractChunkName(key);\n }\n return null;\n}\n\nfunction buildChunkBreakdown(root: DebugRoot = defaultRoot()): ChunkBreakdown {\n const registry = getRegistry(root);\n if (!root || !registry)\n return { byChunk: {}, totalChunkTypes: 0, totalClasses: 0 };\n\n const byChunk: ChunkBreakdown['byChunk'] = {};\n for (const [cacheKey, className] of registry.cacheKeyToClassName) {\n const chunk = extractChunkName(cacheKey) || 'unknown';\n const entry = (byChunk[chunk] ??= {\n classes: [],\n cssSize: 0,\n ruleCount: 0,\n });\n entry.classes.push(className);\n const css = cssTextForClasses([className], root);\n entry.cssSize += css.length;\n entry.ruleCount += countRules(css);\n }\n\n const entries = Object.values(byChunk);\n for (const entry of entries) {\n entry.classes = sortTastyClasses(entry.classes);\n }\n\n const totalClasses = entries.reduce((sum, entry) => {\n return sum + entry.classes.length;\n }, 0);\n return {\n byChunk,\n totalChunkTypes: Object.keys(byChunk).length,\n totalClasses,\n };\n}\n\n// ---------------------------------------------------------------------------\n// Global-type CSS helper (internal only)\n// ---------------------------------------------------------------------------\n\n/**\n * Every prefix `registry.globalRules` is keyed by. Anything missing here is a\n * rule the summary would hold but never count, which is how the totals stopped\n * adding up the first time.\n */\nconst GLOBAL_RULE_PREFIXES = {\n global: 'global:',\n property: 'property:',\n fontFace: 'fontface:',\n counterStyle: 'counterstyle:',\n function: 'function:',\n} as const;\n\nfunction getGlobalTypeCSS(\n type: keyof typeof GLOBAL_RULE_PREFIXES | 'raw' | 'keyframes',\n root: DebugRoot = defaultRoot(),\n includeCSS = true,\n): { css: string; ruleCount: number; size: number } {\n const registry = getRegistry(root);\n if (!root || !registry) return { css: '', ruleCount: 0, size: 0 };\n\n const chunks: string[] = [];\n const sheetManager = injector.instance._sheetManager;\n let rc = 0;\n\n if (type === 'raw') {\n // Raw blocks are kept by the sheet manager, not in `globalRules`, so the\n // prefix scan below never sees them — and their rules are counted from the\n // parsed sheet, since one raw block is one string but any number of rules.\n const css = injector.instance.getRawCSSText({ root });\n\n return {\n css: includeCSS ? prettifyCSS(css) : '',\n ruleCount: sheetManager?.getRawRuleCount(root) ?? 0,\n size: css.length,\n };\n }\n\n if (type === 'keyframes') {\n for (const [, entry] of registry.keyframesCache) {\n const info = entry.info;\n const sheetInfo = registry.sheets[info.sheetIndex];\n const ss =\n sheetInfo && sheetManager ? sheetManager.getCSSSheet(sheetInfo) : null;\n if (ss && info.ruleIndex < ss.cssRules.length) {\n const rule = ss.cssRules[info.ruleIndex];\n if (rule) {\n chunks.push(rule.cssText);\n rc++;\n }\n } else if (info.cssText) {\n chunks.push(info.cssText);\n rc++;\n }\n }\n } else {\n const prefix = GLOBAL_RULE_PREFIXES[type];\n for (const [key, ri] of registry.globalRules) {\n if (!key.startsWith(prefix)) continue;\n const sheetInfo = registry.sheets[ri.sheetIndex];\n const ss =\n sheetInfo && sheetManager ? sheetManager.getCSSSheet(sheetInfo) : null;\n if (ss) {\n const start = Math.max(0, ri.ruleIndex);\n const end = Math.min(\n ss.cssRules.length - 1,\n (ri.endRuleIndex as number) ?? ri.ruleIndex,\n );\n if (start >= 0 && end >= start && start < ss.cssRules.length) {\n for (let i = start; i <= end; i++) {\n const rule = ss.cssRules[i];\n if (rule) {\n chunks.push(rule.cssText);\n rc++;\n }\n }\n }\n } else if (ri.cssText?.length) {\n chunks.push(...ri.cssText);\n rc += ri.cssText.length;\n }\n }\n }\n\n const raw = chunks.join('\\n');\n return {\n css: includeCSS ? prettifyCSS(raw) : '',\n ruleCount: rc,\n size: raw.length,\n };\n}\n\n// ---------------------------------------------------------------------------\n// Source CSS (dev-mode RuleInfo.cssText)\n// ---------------------------------------------------------------------------\n\nfunction getSourceCssForClasses(\n classNames: string[],\n root: DebugRoot = defaultRoot(),\n): string | null {\n const registry = getRegistry(root);\n if (!registry) return null;\n\n const chunks: string[] = [];\n let found = false;\n for (const cls of classNames) {\n const info = registry.rules.get(cls);\n if (info?.cssText?.length) {\n chunks.push(...info.cssText);\n found = true;\n }\n }\n return found ? chunks.join('\\n') : null;\n}\n\n// ---------------------------------------------------------------------------\n// Definitions helper (internal)\n// ---------------------------------------------------------------------------\n\nfunction getDefs(root: DebugRoot = defaultRoot()) {\n const registry = getRegistry(root);\n let properties: string[] = [];\n if (registry?.injectedProperties) {\n properties = Array.from(\n (registry.injectedProperties as Map<string, string>).keys(),\n ).sort();\n }\n\n const keyframes: { name: string; refCount: number }[] = [];\n if (registry) {\n for (const entry of registry.keyframesCache.values()) {\n keyframes.push({ name: entry.name, refCount: entry.refCount });\n }\n keyframes.sort((a, b) => a.name.localeCompare(b.name));\n }\n\n return { properties, keyframes };\n}\n\n// ---------------------------------------------------------------------------\n// Chunk display order\n// ---------------------------------------------------------------------------\n\nconst CHUNK_ORDER = [\n CHUNK_NAMES.COMBINED,\n CHUNK_NAMES.APPEARANCE,\n CHUNK_NAMES.FONT,\n CHUNK_NAMES.DIMENSION,\n CHUNK_NAMES.DISPLAY,\n CHUNK_NAMES.LAYOUT,\n CHUNK_NAMES.POSITION,\n CHUNK_NAMES.MISC,\n CHUNK_NAMES.SUBCOMPONENTS,\n];\n\nfunction logChunkEntries(breakdown: ChunkBreakdown): void {\n for (const name of CHUNK_ORDER) {\n const data = breakdown.byChunk[name];\n if (data)\n console.log(\n ` ${name}: ${data.classes.length} cls, ${data.ruleCount} rules, ${fmtSize(data.cssSize)}`,\n );\n }\n for (const [name, data] of Object.entries(breakdown.byChunk)) {\n if (!CHUNK_ORDER.includes(name as (typeof CHUNK_ORDER)[number]))\n console.log(\n ` ${name}: ${data.classes.length} cls, ${data.ruleCount} rules, ${fmtSize(data.cssSize)}`,\n );\n }\n}\n\n// ---------------------------------------------------------------------------\n// tastyDebug API\n// ---------------------------------------------------------------------------\n\nexport const tastyDebug = {\n css(target: CSSTarget, opts?: CSSOptions): string {\n const {\n root = defaultRoot(),\n prettify = true,\n raw = false,\n source = false,\n } = opts || {};\n if (!root) {\n warnNoDom(raw);\n\n return '';\n }\n let css = '';\n\n const classRegex = tastyClassRegex(getNamePrefix());\n if (source && typeof target === 'string' && classRegex.test(target)) {\n const src = getSourceCssForClasses([target], root);\n if (src) {\n css = src;\n } else {\n if (!raw) {\n console.warn(\n '[Tasty] source CSS not available (requires dev mode or TASTY_DEBUG=true). Falling back to live CSSOM.',\n );\n }\n css = cssTextForClasses([target], root);\n }\n } else if (source && Array.isArray(target)) {\n const src = getSourceCssForClasses(target, root);\n if (src) {\n css = src;\n } else {\n if (!raw) {\n console.warn(\n '[Tasty] source CSS not available. Falling back to live CSSOM.',\n );\n }\n css = cssTextForClasses(target, root);\n }\n } else if (typeof target === 'string') {\n if (target === 'all') {\n // Documented as component + global + raw, and raw has its own sheet.\n css = getAllCSS(root);\n } else if (target === 'global') {\n css = getGlobalTypeCSS('global', root).css;\n return css; // already prettified\n } else if (target === 'active') {\n const active = findDomTastyClasses(root);\n css = cssTextForClasses(active, root);\n } else if (target === 'unused') {\n const unused = getUnusedClasses(root);\n css = cssTextForClasses(unused, root);\n } else if (target === 'page') {\n css = getPageCSS(root);\n } else if (classRegex.test(target)) {\n css = cssTextForClasses([target], root);\n } else {\n const el = (root as Document).querySelector?.(target);\n if (el) css = getCSSTextForNode(el, { root });\n }\n } else if (Array.isArray(target)) {\n css = cssTextForClasses(target, root);\n } else if (target instanceof Element) {\n css = getCSSTextForNode(target, { root });\n }\n\n const result = prettify ? prettifyCSS(css) : css;\n\n if (!raw) {\n const label = Array.isArray(target) ? `[${target.join(', ')}]` : target;\n const rc = countRules(css);\n console.group(`CSS for ${label} (${rc} rules, ${fmtSize(css.length)})`);\n console.log(result || '(empty)');\n console.groupEnd();\n }\n\n return result;\n },\n\n inspect(target: string | Element, opts?: DebugOptions): InspectResult {\n const { root = defaultRoot(), raw = false } = opts || {};\n const element = !root\n ? null\n : typeof target === 'string'\n ? (root as Document).querySelector?.(target)\n : target;\n if (!root) warnNoDom(raw);\n\n if (!element) {\n const empty: InspectResult = {\n element: null,\n classes: [],\n chunks: [],\n css: '',\n size: 0,\n rules: 0,\n };\n // With no DOM at all, `warnNoDom` above already said why; \"element not\n // found\" would only misdirect.\n if (!raw && root)\n console.warn('[Tasty] debug.inspect: element not found');\n return empty;\n }\n\n const classList = element.getAttribute('class') || '';\n const classRegex = tastyClassRegex(getNamePrefix());\n const tastyClasses = classList\n .split(/\\s+/)\n .filter((cls) => classRegex.test(cls));\n\n const chunks: DebugChunkInfo[] = tastyClasses.map((className) => ({\n className,\n chunkName: getChunkForClass(className, root),\n }));\n\n const css = getCSSTextForNode(element, { root: root ?? undefined });\n const rules = countRules(css);\n\n const result: InspectResult = {\n element,\n classes: tastyClasses,\n chunks,\n css: prettifyCSS(css),\n size: css.length,\n rules,\n };\n\n if (!raw) {\n const tag = element.tagName.toLowerCase();\n const id = element.id ? `#${element.id}` : '';\n console.group(\n `inspect ${tag}${id} — ${tastyClasses.length} classes, ${rules} rules, ${fmtSize(css.length)}`,\n );\n if (chunks.length) {\n console.log(\n 'Chunks:',\n chunks.map((c) => `${c.className}→${c.chunkName || '?'}`).join(', '),\n );\n }\n console.groupCollapsed('CSS');\n console.log(result.css || '(empty)');\n console.groupEnd();\n console.groupEnd();\n }\n\n return result;\n },\n\n summary(opts?: DebugOptions): Summary {\n const { root = defaultRoot(), raw = false } = opts || {};\n if (!root) warnNoDom(raw);\n\n const activeClasses = findDomTastyClasses(root);\n const unusedClasses = getUnusedClasses(root);\n // Everything, not just the two bands above: a class that went cold a\n // moment ago is in neither, and dropping it here is the accounting failure\n // this whole change started from.\n const ownedClasses = getOwnedClasses(root);\n const totalStyledClasses = sortTastyClasses(\n new Set([...activeClasses, ...ownedClasses]),\n );\n const unusedSet = new Set(unusedClasses);\n const activeSet = new Set(activeClasses);\n const hotClasses = ownedClasses.filter(\n (className) => !activeSet.has(className) && !unusedSet.has(className),\n );\n const hotCSS = cssTextForClasses(hotClasses, root);\n\n const activeCSS = cssTextForClasses(activeClasses, root);\n const unusedCSS = cssTextForClasses(unusedClasses, root);\n const allCSS = getAllCSS(root);\n\n const activeRuleCount = countRules(activeCSS);\n const unusedRuleCount = countRules(unusedCSS);\n\n const globalData = getGlobalTypeCSS('global', root, false);\n const rawData = getGlobalTypeCSS('raw', root, false);\n const kfData = getGlobalTypeCSS('keyframes', root, false);\n const propData = getGlobalTypeCSS('property', root, false);\n // Folded into the global line rather than given their own: they are all\n // at-rules injected once and kept forever, and leaving them out of the\n // total is what made it not a total.\n const atRuleData = (\n ['fontFace', 'counterStyle', 'function'] as const\n ).reduce(\n (total, type) => {\n const data = getGlobalTypeCSS(type, root, false);\n total.ruleCount += data.ruleCount;\n total.size += data.size;\n return total;\n },\n { ruleCount: 0, size: 0 },\n );\n\n const hotRuleCount = countRules(hotCSS);\n const globalRuleCount = globalData.ruleCount + atRuleData.ruleCount;\n const globalCSSSize = globalData.size + atRuleData.size;\n\n const totalRuleCount =\n activeRuleCount +\n unusedRuleCount +\n hotRuleCount +\n globalRuleCount +\n rawData.ruleCount +\n kfData.ruleCount +\n propData.ruleCount;\n\n const metrics = getInjectorMetrics(root);\n const defs = getDefs(root);\n const chunkBreakdown = buildChunkBreakdown(root);\n\n const summary: Summary = {\n activeClasses,\n unusedClasses,\n hotClasses,\n totalStyledClasses,\n activeCSSSize: activeCSS.length,\n unusedCSSSize: unusedCSS.length,\n globalCSSSize,\n rawCSSSize: rawData.size,\n keyframesCSSSize: kfData.size,\n propertyCSSSize: propData.size,\n totalCSSSize: allCSS.length,\n activeRuleCount,\n unusedRuleCount,\n globalRuleCount,\n rawRuleCount: rawData.ruleCount,\n keyframesRuleCount: kfData.ruleCount,\n propertyRuleCount: propData.ruleCount,\n totalRuleCount,\n metrics,\n definedProperties: defs.properties,\n definedKeyframes: defs.keyframes,\n chunkBreakdown,\n };\n\n if (!raw) {\n console.group('Tasty Summary');\n console.log(\n `Active: ${activeClasses.length} classes, ${activeRuleCount} rules, ${fmtSize(activeCSS.length)}`,\n );\n console.log(\n `Unused: ${unusedClasses.length} classes, ${unusedRuleCount} rules, ${fmtSize(unusedCSS.length)}`,\n );\n if (hotClasses.length)\n console.log(\n `Held: ${hotClasses.length} classes, ${hotRuleCount} rules, ${fmtSize(hotCSS.length)} (not rendered, not yet collectable)`,\n );\n console.log(\n `Global: ${globalRuleCount} rules, ${fmtSize(globalCSSSize)}`,\n );\n if (rawData.ruleCount)\n console.log(\n `Raw: ${rawData.ruleCount} rules, ${fmtSize(rawData.size)}`,\n );\n if (kfData.ruleCount)\n console.log(\n `Keyframes: ${kfData.ruleCount} rules, ${fmtSize(kfData.size)}`,\n );\n if (propData.ruleCount)\n console.log(\n `@property: ${propData.ruleCount} rules, ${fmtSize(propData.size)}`,\n );\n console.log(\n `Total: ${totalStyledClasses.length} classes, ${totalRuleCount} rules, ${fmtSize(allCSS.length)}`,\n );\n\n if (metrics) {\n const total = metrics.hits + metrics.misses;\n const rate = total > 0 ? ((metrics.hits / total) * 100).toFixed(1) : 0;\n console.log(`Cache: ${rate}% hit rate (${total} lookups)`);\n }\n\n if (chunkBreakdown.totalChunkTypes > 0) {\n console.groupCollapsed(\n `Chunks (${chunkBreakdown.totalChunkTypes} types, ${chunkBreakdown.totalClasses} classes)`,\n );\n logChunkEntries(chunkBreakdown);\n console.groupEnd();\n }\n\n if (defs.properties.length || defs.keyframes.length) {\n console.log(\n `Defs: ${defs.properties.length} @property, ${defs.keyframes.length} @keyframes`,\n );\n }\n\n console.groupEnd();\n }\n\n return summary;\n },\n\n chunks(opts?: DebugOptions): ChunkBreakdown {\n const { root = defaultRoot(), raw = false } = opts || {};\n if (!root) warnNoDom(raw);\n const breakdown = buildChunkBreakdown(root);\n\n if (!raw) {\n console.group(\n `Chunks (${breakdown.totalChunkTypes} types, ${breakdown.totalClasses} classes)`,\n );\n logChunkEntries(breakdown);\n console.groupEnd();\n }\n\n return breakdown;\n },\n\n cache(opts?: DebugOptions): CacheStatus {\n const { root = defaultRoot(), raw = false } = opts || {};\n if (!root) warnNoDom(raw);\n const active = findDomTastyClasses(root);\n const unused = getUnusedClasses(root);\n const metrics = getInjectorMetrics(root);\n\n // `all` is everything held, not the two bands above: a class that went cold\n // a moment ago is in neither, and it is still taking up a sheet.\n const all = sortTastyClasses(\n new Set([...active, ...getOwnedClasses(root)]),\n );\n\n const status: CacheStatus = {\n classes: { active, unused, all },\n metrics,\n };\n\n if (!raw) {\n console.group('Cache');\n console.log(`Active: ${active.length}, Unused: ${unused.length}`);\n if (metrics) {\n const total = metrics.hits + metrics.misses;\n const rate = total > 0 ? ((metrics.hits / total) * 100).toFixed(1) : 0;\n console.log(\n `Hits: ${metrics.hits}, Misses: ${metrics.misses}, Rate: ${rate}%`,\n );\n }\n console.groupEnd();\n }\n\n return status;\n },\n\n cleanup(opts?: { root?: Document | ShadowRoot }): void {\n const root = opts?.root ?? defaultRoot();\n if (!root) return;\n injector.instance.cleanup(root);\n },\n\n help(): void {\n console.log(`tastyDebug API:\n .summary() — overview (classes, rules, sizes)\n .css(\"active\") — CSS for classes in DOM\n .css(\"t3a5f\") — CSS for a specific class\n .css(\"t3a5f\",{source:true}) — original CSS before browser parsing (dev only)\n .css(\".selector\") — CSS for a DOM element\n .inspect(\".selector\") — element details (classes, chunks, rules)\n .chunks() — style chunk breakdown\n .cache() — cache status and metrics\n .cleanup() — force unused style cleanup\nOptions: { raw: true } suppresses logging, { root: shadowRoot } targets Shadow DOM`);\n },\n\n install(): void {\n if (typeof window !== 'undefined' && window.tastyDebug !== tastyDebug) {\n window.tastyDebug = tastyDebug;\n console.log('tastyDebug installed. Run tastyDebug.help() for commands.');\n }\n },\n};\n\n// ---------------------------------------------------------------------------\n// Page CSS (minimal, kept internal)\n// ---------------------------------------------------------------------------\n\nfunction getPageCSS(root: DebugRoot = defaultRoot()): string {\n if (!root) return '';\n const chunks: string[] = [];\n try {\n if ('styleSheets' in root) {\n for (const sheet of Array.from((root as Document).styleSheets)) {\n try {\n if (sheet.cssRules)\n chunks.push(\n Array.from(sheet.cssRules)\n .map((r) => r.cssText)\n .join('\\n'),\n );\n } catch {\n /* cross-origin */\n }\n }\n }\n } catch {\n /* ignore */\n }\n return chunks.join('\\n');\n}\n"],"mappings":";;;;AAqGA,SAAS,QAAQ,OAAuB;CACtC,OAAO,QAAQ,OAAO,IAAI,QAAQ,KAAA,CAAM,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM;AACpE;AAEA,SAAS,WAAW,KAAqB;CACvC,QAAQ,IAAI,MAAM,YAAY,KAAK,CAAC,EAAA,CAAG;AACzC;AAEA,SAAS,iBAAiB,SAAqC;CAE7D,OAAO,MAAM,KAAK,OAAO,CAAC,CAAC,MAAM,GAAG,MAAM,EAAE,cAAc,CAAC,CAAC;AAC9D;AAcA,SAAS,cAAyB;CAChC,OAAO,OAAO,aAAa,cAAc,OAAO;AAClD;AAEA,IAAI,cAAc;AAGlB,SAAS,UAAU,KAAoB;CACrC,IAAI,OAAO,aAAa;CACxB,cAAc;CACd,QAAQ,KACN,4IAEF;AACF;AAWA,SAAS,YACP,OAAkB,YAAY,GACJ;CAC1B,IAAI,CAAC,MAAM,OAAO,KAAA;CAClB,YAAY;CAEZ,OAAO,SAAS,SAAS,eAAe,YAAY,IAAI;AAC1D;AAEA,SAAS,oBAAoB,OAAkB,YAAY,GAAa;CACtE,IAAI,CAAC,MAAM,OAAO,CAAC;CACnB,MAAM,0BAAU,IAAI,IAAY;CAChC,MAAM,WAAY,KAAkB,mBAAmB,SAAS,KAAK,CAAC;CACtE,MAAM,aAAa,gBAAgB,cAAc,CAAC;CAClD,KAAK,MAAM,WAAW,UAAU;EAC9B,MAAM,YAAY,QAAQ,aAAa,OAAO;EAC9C,IAAI,CAAC,WAAW;EAChB,KAAK,MAAM,aAAa,UAAU,MAAM,KAAK,GAC3C,IAAI,WAAW,KAAK,SAAS,GAAG,QAAQ,IAAI,SAAS;CAEzD;CACA,OAAO,iBAAiB,OAAO;AACjC;AAOA,SAAS,UAAU,OAAkB,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none`;
|
|
478
|
+
const RE_SLASH_ZERO_ALPHA = new RegExp(String.raw`\/\s*(?:${ZERO_ALPHA})\s*\)$`, "i");
|
|
479
|
+
const RE_LEGACY_ZERO_ALPHA = new RegExp(String.raw`^(?:rgba|hsla)\([^(),]*,[^(),]*,[^(),]*,\s*(?:${ZERO_ALPHA})\s*\)$`, "i");
|
|
480
|
+
function isTransparent(color) {
|
|
481
|
+
return color === "transparent" || parseAlphaMix(color)?.percentage === "0%" || RE_SLASH_ZERO_ALPHA.test(color) || RE_LEGACY_ZERO_ALPHA.test(color);
|
|
482
|
+
}
|
|
477
483
|
function alphaToPercentage(alpha) {
|
|
478
484
|
return `${Number(((Number.isNaN(alpha) ? 1 : Math.min(1, Math.max(0, alpha))) * 100).toFixed(6))}%`;
|
|
479
485
|
}
|
|
@@ -508,6 +514,35 @@ function alphaSuffixToPercentage(rawAlpha) {
|
|
|
508
514
|
function fadeColor(color, rawAlpha) {
|
|
509
515
|
return mixColorAlpha(color, alphaSuffixToPercentage(rawAlpha));
|
|
510
516
|
}
|
|
517
|
+
const ALPHA_SUFFIX = String.raw`(\$[a-z_][a-z0-9-_]*|[0-9]+)`;
|
|
518
|
+
const RE_CURRENT_ALPHA = new RegExp(`^#current\\.${ALPHA_SUFFIX}$`, "i");
|
|
519
|
+
const RE_TOKEN_ALPHA = new RegExp(`^(#[a-z0-9-]+)\\.${ALPHA_SUFFIX}$`, "i");
|
|
520
|
+
const RE_COLOR_LAYER = new RegExp(`^(#[a-z0-9-]+)(?:\\.${ALPHA_SUFFIX})?$`, "i");
|
|
521
|
+
function layerColors(token, opts, recurse) {
|
|
522
|
+
const operands = token.split("+").map((part) => part.match(RE_COLOR_LAYER));
|
|
523
|
+
if (operands.some((match) => !match)) return null;
|
|
524
|
+
const colorOf = (input) => {
|
|
525
|
+
const { bucket, processed } = classify(input, opts, recurse);
|
|
526
|
+
return bucket === 0 || bucket === 3 ? processed : null;
|
|
527
|
+
};
|
|
528
|
+
const [base, ...layers] = operands;
|
|
529
|
+
let result = colorOf(base[0]);
|
|
530
|
+
if (result === null) return null;
|
|
531
|
+
for (const [layerInput, name, rawAlpha] of layers) {
|
|
532
|
+
const color = colorOf(name);
|
|
533
|
+
if (color === null) return null;
|
|
534
|
+
if (isTransparent(color)) continue;
|
|
535
|
+
if (rawAlpha === void 0) {
|
|
536
|
+
warnOnceDev(`compound-color-opaque:${token}`, `"${token}": "${layerInput}" has no opacity, so it covers everything before it and the color is just "${layerInput}". Give the layer an opacity, such as "${layerInput}.04".`);
|
|
537
|
+
result = color;
|
|
538
|
+
continue;
|
|
539
|
+
}
|
|
540
|
+
const opacity = alphaSuffixToPercentage(rawAlpha);
|
|
541
|
+
if (opacity === "0%") continue;
|
|
542
|
+
result = isTransparent(result) ? mixColorAlpha(color, opacity) : `color-mix(in srgb, ${color} ${opacity}, ${result})`;
|
|
543
|
+
}
|
|
544
|
+
return result;
|
|
545
|
+
}
|
|
511
546
|
function hasColorArgs(parsed) {
|
|
512
547
|
return parsed.groups.some((group) => group.colors.length > 0);
|
|
513
548
|
}
|
|
@@ -606,11 +641,23 @@ function classify(raw, opts, recurse) {
|
|
|
606
641
|
processed: `--${rest}-color`
|
|
607
642
|
};
|
|
608
643
|
}
|
|
644
|
+
if (token[0] === "#" && token.includes("+")) {
|
|
645
|
+
const layered = layerColors(token, opts, recurse);
|
|
646
|
+
if (layered !== null) return {
|
|
647
|
+
bucket: 0,
|
|
648
|
+
processed: layered
|
|
649
|
+
};
|
|
650
|
+
warnOnceDev(`compound-color-invalid:${token}`, `"${token}" is not a compound color and is ignored: every part joined by "+" must be a color token with an optional opacity, such as "#surface+#dark.04".`);
|
|
651
|
+
return {
|
|
652
|
+
bucket: 2,
|
|
653
|
+
processed: ""
|
|
654
|
+
};
|
|
655
|
+
}
|
|
609
656
|
if (token === "#current") return {
|
|
610
657
|
bucket: 0,
|
|
611
658
|
processed: "currentcolor"
|
|
612
659
|
};
|
|
613
|
-
const currentAlphaMatch = token.match(
|
|
660
|
+
const currentAlphaMatch = token.match(RE_CURRENT_ALPHA);
|
|
614
661
|
if (currentAlphaMatch) return {
|
|
615
662
|
bucket: 0,
|
|
616
663
|
processed: fadeColor("currentcolor", currentAlphaMatch[1])
|
|
@@ -624,7 +671,7 @@ function classify(raw, opts, recurse) {
|
|
|
624
671
|
return classify(foldDslCase(tokenValue), opts, recurse);
|
|
625
672
|
}
|
|
626
673
|
if (token[0] === "#") {
|
|
627
|
-
const alphaMatch = token.match(
|
|
674
|
+
const alphaMatch = token.match(RE_TOKEN_ALPHA);
|
|
628
675
|
if (alphaMatch) {
|
|
629
676
|
const [, baseToken, rawAlpha] = alphaMatch;
|
|
630
677
|
const baseKey = baseToken.toLowerCase();
|
|
@@ -634,15 +681,23 @@ function classify(raw, opts, recurse) {
|
|
|
634
681
|
bucket: 0,
|
|
635
682
|
processed: "transparent"
|
|
636
683
|
};
|
|
684
|
+
const fadeWhole = () => {
|
|
685
|
+
const { bucket, processed } = classify(foldDslCase(resolvedValue), opts, recurse);
|
|
686
|
+
return bucket === 0 || bucket === 3 ? {
|
|
687
|
+
bucket: 0,
|
|
688
|
+
processed: fadeColor(processed, rawAlpha)
|
|
689
|
+
} : {
|
|
690
|
+
bucket: 2,
|
|
691
|
+
processed: ""
|
|
692
|
+
};
|
|
693
|
+
};
|
|
694
|
+
if (resolvedValue.startsWith("#") && resolvedValue.includes("+")) return fadeWhole();
|
|
637
695
|
if (resolvedValue.startsWith("#")) return classify(`${foldDslCase(resolvedValue)}.${rawAlpha}`, opts, recurse);
|
|
638
696
|
const funcMatch = resolvedValue.match(RE_FUNC_CALL);
|
|
639
697
|
if (funcMatch) {
|
|
640
698
|
const [, funcName, args] = funcMatch;
|
|
641
699
|
const lowerFunc = funcName.toLowerCase();
|
|
642
|
-
if (DERIVED_COLOR_FUNCS.has(lowerFunc)) return
|
|
643
|
-
bucket: 0,
|
|
644
|
-
processed: fadeColor(classify(foldDslCase(resolvedValue), opts, recurse).processed, rawAlpha)
|
|
645
|
-
};
|
|
700
|
+
if (DERIVED_COLOR_FUNCS.has(lowerFunc)) return fadeWhole();
|
|
646
701
|
const isCustomFunc = !!(opts.functions && lowerFunc in opts.functions && !COLOR_FUNCS.has(lowerFunc) && !COLOR_FUNCS.has(funcName.replace(/a$/i, "").toLowerCase()));
|
|
647
702
|
const normalizedFunc = isCustomFunc ? lowerFunc : funcName.replace(/a$/i, "").toLowerCase();
|
|
648
703
|
if (!(COLOR_FUNCS.has(normalizedFunc) || COLOR_FUNCS.has(lowerFunc) || isCustomFunc)) return classify(`${resolvedValue}.${rawAlpha}`, opts, recurse);
|
|
@@ -732,9 +787,10 @@ function classify(raw, opts, recurse) {
|
|
|
732
787
|
}
|
|
733
788
|
}
|
|
734
789
|
if (token[0] === "#" && token.length > 1) {
|
|
735
|
-
const alphaMatch = token.match(
|
|
790
|
+
const alphaMatch = token.match(RE_TOKEN_ALPHA);
|
|
736
791
|
if (alphaMatch) {
|
|
737
|
-
const [,
|
|
792
|
+
const [, baseToken, rawAlpha] = alphaMatch;
|
|
793
|
+
const base = baseToken.slice(1);
|
|
738
794
|
return {
|
|
739
795
|
bucket: 0,
|
|
740
796
|
processed: fadeColor(RE_HEX.test(base) ? `var(--${base}-color, #${base})` : `var(--${base}-color)`, rawAlpha)
|
|
@@ -993,6 +1049,16 @@ function scan(src, cb) {
|
|
|
993
1049
|
}
|
|
994
1050
|
//#endregion
|
|
995
1051
|
//#region src/parser/parser.ts
|
|
1052
|
+
function warnSpacedCompound(src, tokens) {
|
|
1053
|
+
for (let i = 1; i < tokens.length; i++) {
|
|
1054
|
+
const prev = tokens[i - 1];
|
|
1055
|
+
const tok = tokens[i];
|
|
1056
|
+
if (prev[0] === "#" && (tok.startsWith("+#") || tok === "+" && tokens[i + 1]?.[0] === "#" || prev.endsWith("+") && tok[0] === "#")) {
|
|
1057
|
+
warnOnceDev(`compound-color-spaced:${src}`, `"${src}": a "+" joins colors only without spaces around it. Write "${src.replace(/(#[^\s,()+#]+)\s*\+\s*(?=#)/g, "$1+")}".`);
|
|
1058
|
+
return;
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
996
1062
|
var StyleParser = class {
|
|
997
1063
|
opts;
|
|
998
1064
|
cache;
|
|
@@ -1056,8 +1122,10 @@ var StyleParser = class {
|
|
|
1056
1122
|
parts = [];
|
|
1057
1123
|
}
|
|
1058
1124
|
};
|
|
1125
|
+
const tokens = [];
|
|
1059
1126
|
scan(stripped, (tok, isComma, isSlash) => {
|
|
1060
1127
|
if (tok) {
|
|
1128
|
+
tokens.push(tok);
|
|
1061
1129
|
if (currentGroup.input) currentGroup.input += ` ${tok}`;
|
|
1062
1130
|
else currentGroup.input = tok;
|
|
1063
1131
|
const { bucket, processed } = classify(tok, this.opts, (sub) => this.process(sub));
|
|
@@ -1067,6 +1135,7 @@ var StyleParser = class {
|
|
|
1067
1135
|
if (isComma) endGroup();
|
|
1068
1136
|
});
|
|
1069
1137
|
if (currentPart.all.length || parts.length || !groups.length) endGroup(false);
|
|
1138
|
+
warnSpacedCompound(src, tokens);
|
|
1070
1139
|
const result = {
|
|
1071
1140
|
output: groups.length === 1 ? groups[0].output : groups.map((group) => group.output).join(", "),
|
|
1072
1141
|
groups
|
|
@@ -1281,6 +1350,9 @@ function resolveCustomProperties(value) {
|
|
|
1281
1350
|
if (!RE_CUSTOM_PROPERTY_REF.test(value)) return value;
|
|
1282
1351
|
return parseStyle(value).output || value;
|
|
1283
1352
|
}
|
|
1353
|
+
function isDroppedValue(value) {
|
|
1354
|
+
return parseStyle(value).groups.every((group) => group.all.length === 0);
|
|
1355
|
+
}
|
|
1284
1356
|
function parseColor(val, ignoreError = false) {
|
|
1285
1357
|
if (typeof val !== "string") val = String(val ?? "");
|
|
1286
1358
|
val = val.trim();
|
|
@@ -1381,6 +1453,6 @@ function color(name, opacity = 1) {
|
|
|
1381
1453
|
return `var(--${name}-color)`;
|
|
1382
1454
|
}
|
|
1383
1455
|
//#endregion
|
|
1384
|
-
export {
|
|
1456
|
+
export { getRgbValuesFromRgbaString as A, createColorFunc as C, isTransparent as D, makeEmptyDetails as E, normalizeDslName as F, toSnakeCase as I, CSS_WIDE_KEYWORDS as L, hslToRgbValues as M, isColorKeyword as N, parseAlphaMix as O, strToRgb as P, RE_NUMBER as R, okhslPlugin as S, Lru as T, setGlobalPredefinedTokens as _, customFunction as a, okhstPlugin as b, getGlobalParser as c, normalizeColorTokenValue as d, parseColor as f, resolveCustomProperties as g, resetGlobalPredefinedTokens as h, DIRECTIONS as i, hexToRgb as j, getNamedColorHex as k, getGlobalPredefinedTokens as l, resetGlobalParseFunctions as m, resolveFunctionColor as n, filterMods as o, parseStyle as p, CUSTOM_UNITS as r, getGlobalParseFunctions as s, color as t, isDroppedValue as u, stringifyStyles as v, StyleParser as w, okhslFunction as x, okhstFunction as y, RE_RAW_UNIT as z };
|
|
1385
1457
|
|
|
1386
|
-
//# sourceMappingURL=dsl-
|
|
1458
|
+
//# sourceMappingURL=dsl-CsFl9LGn.js.map
|