{"version":3,"file":"index.cjs","sources":["../src/transform.js","../src/index.js"],"sourcesContent":["/**\n * CSS Custom Function Transformation Engine\n * Integrated solution combining runtime polyfill with build-time transformation\n */\n\n/* global document */\n\n/**\n * Handle string parsing in CSS\n */\nconst handleStrings = (char, previousChar, parseState) => {\n\tif ((char === '\"' || char === \"'\") && previousChar !== '\\\\') {\n\t\tif (!parseState.inString) {\n\t\t\tparseState.inString = true;\n\t\t\tparseState.stringChar = char;\n\t\t} else if (char === parseState.stringChar) {\n\t\t\tparseState.inString = false;\n\t\t\tparseState.stringChar = '';\n\t\t}\n\t}\n\n\treturn parseState.inString;\n};\n\n/**\n * Parse CSS rules with proper handling of nested structures\n */\nconst parseCSSRules = (cssText) => {\n\tconst rules = [];\n\tlet currentRule = '';\n\tlet braceCount = 0;\n\tlet inRule = false;\n\n\tconst parseState = {\n\t\tinString: false,\n\t\tstringChar: '',\n\t\tinComment: false\n\t};\n\n\tfor (let i = 0; i < cssText.length; i++) {\n\t\tconst char = cssText[i];\n\t\tconst nextChar = cssText[i + 1];\n\t\tconst previousChar = cssText[i - 1];\n\n\t\t// Handle comment start\n\t\tif (\n\t\t\t!parseState.inString &&\n\t\t\t!parseState.inComment &&\n\t\t\tchar === '/' &&\n\t\t\tnextChar === '*'\n\t\t) {\n\t\t\t// If we have accumulated content before the comment, save it\n\t\t\tif (currentRule.trim() && !inRule) {\n\t\t\t\trules.push(currentRule.trim());\n\t\t\t\tcurrentRule = '';\n\t\t\t}\n\n\t\t\tparseState.inComment = true;\n\t\t\tcurrentRule += char;\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Handle comment end\n\t\tif (parseState.inComment && char === '*' && nextChar === '/') {\n\t\t\tcurrentRule += char + nextChar;\n\t\t\tparseState.inComment = false;\n\n\t\t\t// Save the complete comment as a rule\n\t\t\trules.push(currentRule.trim());\n\t\t\tcurrentRule = '';\n\t\t\ti++; // Skip the next character\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (parseState.inComment) {\n\t\t\tcurrentRule += char;\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Handle strings\n\t\thandleStrings(char, previousChar, parseState);\n\n\t\t// Handle braces (only when not in string)\n\t\tif (!parseState.inString) {\n\t\t\tif (char === '{') {\n\t\t\t\tbraceCount++;\n\t\t\t\tinRule = true;\n\t\t\t} else if (char === '}') {\n\t\t\t\tbraceCount--;\n\t\t\t}\n\t\t}\n\n\t\tcurrentRule += char;\n\n\t\t// Complete rule found\n\t\tif (inRule && braceCount === 0 && char === '}') {\n\t\t\trules.push(currentRule.trim());\n\t\t\tcurrentRule = '';\n\t\t\tinRule = false;\n\t\t}\n\t}\n\n\t// Handle any remaining content\n\tif (currentRule.trim()) {\n\t\trules.push(currentRule.trim());\n\t}\n\n\treturn rules;\n};\n\n/**\n * Extract if() functions from CSS text\n */\nconst extractIfFunctions = (cssText) => {\n\tconst functions = [];\n\tlet index = 0;\n\n\twhile (index < cssText.length) {\n\t\tconst ifMatch = cssText.indexOf('if(', index);\n\t\tif (ifMatch === -1) {\n\t\t\tbreak;\n\t\t}\n\n\t\t// Ensure it's actually an if() function\n\t\tif (ifMatch > 0 && /[\\w-]/.test(cssText[ifMatch - 1])) {\n\t\t\tindex = ifMatch + 1;\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Find matching closing parenthesis\n\t\tlet depth = 0;\n\t\tlet inQuotes = false;\n\t\tlet quoteChar = '';\n\t\tconst start = ifMatch + 3;\n\t\tlet end = -1;\n\n\t\tfor (let i = start; i < cssText.length; i++) {\n\t\t\tconst char = cssText[i];\n\t\t\tconst previousChar = i > 0 ? cssText[i - 1] : '';\n\n\t\t\t// Handle quotes\n\t\t\tif ((char === '\"' || char === \"'\") && previousChar !== '\\\\') {\n\t\t\t\tif (!inQuotes) {\n\t\t\t\t\tinQuotes = true;\n\t\t\t\t\tquoteChar = char;\n\t\t\t\t} else if (char === quoteChar) {\n\t\t\t\t\tinQuotes = false;\n\t\t\t\t\tquoteChar = '';\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (!inQuotes) {\n\t\t\t\tif (char === '(') {\n\t\t\t\t\tdepth++;\n\t\t\t\t} else if (char === ')') {\n\t\t\t\t\tif (depth === 0) {\n\t\t\t\t\t\tend = i;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tdepth--;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (end === -1) {\n\t\t\tindex = ifMatch + 1;\n\t\t} else {\n\t\t\tconst fullFunction = cssText.slice(ifMatch, end + 1);\n\t\t\tconst content = cssText.slice(start, end);\n\n\t\t\tfunctions.push({\n\t\t\t\tfullFunction,\n\t\t\t\tcontent,\n\t\t\t\tstart: ifMatch,\n\t\t\t\tend: end + 1\n\t\t\t});\n\n\t\t\tindex = end + 1;\n\t\t}\n\t}\n\n\treturn functions;\n};\n\n/**\n * Parse if() function content - supports both single conditions and multiple chained conditions\n */\n/**\n * Split content by semicolons, respecting parentheses and quotes\n */\nconst splitIfConditionSegments = (content) => {\n\tconst segments = [];\n\tlet currentSegment = '';\n\tlet parenDepth = 0;\n\tlet inQuotes = false;\n\tlet quoteChar = '';\n\n\tfor (let i = 0; i < content.length; i++) {\n\t\tconst char = content[i];\n\t\tconst previousChar = i > 0 ? content[i - 1] : '';\n\n\t\t// Handle quotes\n\t\tif ((char === '\"' || char === \"'\") && previousChar !== '\\\\') {\n\t\t\tif (!inQuotes) {\n\t\t\t\tinQuotes = true;\n\t\t\t\tquoteChar = char;\n\t\t\t} else if (char === quoteChar) {\n\t\t\t\tinQuotes = false;\n\t\t\t\tquoteChar = '';\n\t\t\t}\n\t\t}\n\n\t\tif (!inQuotes) {\n\t\t\tif (char === '(') {\n\t\t\t\tparenDepth++;\n\t\t\t} else if (char === ')') {\n\t\t\t\tparenDepth--;\n\t\t\t} else if (char === ';' && parenDepth === 0) {\n\t\t\t\t// End of segment\n\t\t\t\tsegments.push(currentSegment.trim());\n\t\t\t\tcurrentSegment = '';\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\n\t\tcurrentSegment += char;\n\t}\n\n\t// Add the last segment\n\tif (currentSegment.trim()) {\n\t\tsegments.push(currentSegment.trim());\n\t}\n\n\treturn segments;\n};\n\n/**\n * Find colon outside of parentheses and quotes\n */\nconst findConditionValueSeparator = (segment) => {\n\tlet parenDepth = 0;\n\tlet inQuotes = false;\n\tlet quoteChar = '';\n\n\tfor (let i = 0; i < segment.length; i++) {\n\t\tconst char = segment[i];\n\t\tconst previousChar = i > 0 ? segment[i - 1] : '';\n\n\t\t// Handle quotes\n\t\tif ((char === '\"' || char === \"'\") && previousChar !== '\\\\') {\n\t\t\tif (!inQuotes) {\n\t\t\t\tinQuotes = true;\n\t\t\t\tquoteChar = char;\n\t\t\t} else if (char === quoteChar) {\n\t\t\t\tinQuotes = false;\n\t\t\t\tquoteChar = '';\n\t\t\t}\n\t\t}\n\n\t\tif (!inQuotes) {\n\t\t\tif (char === '(') {\n\t\t\t\tparenDepth++;\n\t\t\t} else if (char === ')') {\n\t\t\t\tparenDepth--;\n\t\t\t} else if (char === ':' && parenDepth === 0) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn -1;\n};\n\n/**\n * Parse if() function content - supports both single conditions and multiple chained conditions\n */\nconst parseIfFunction = (content) => {\n\tconst segments = splitIfConditionSegments(content);\n\tconst conditions = [];\n\tlet elseValue = null;\n\n\tfor (const segment of segments) {\n\t\t// Check if this is an else clause\n\t\tconst elseMatch = segment.match(/^else:\\s*(.*)$/);\n\t\tif (elseMatch) {\n\t\t\telseValue = elseMatch[1].trim();\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Parse condition: value format\n\t\tconst colonIndex = findConditionValueSeparator(segment);\n\t\tif (colonIndex === -1) {\n\t\t\tthrow new Error('Invalid if() function: missing colon in segment');\n\t\t}\n\n\t\tconst conditionPart = segment.slice(0, colonIndex).trim();\n\t\tconst valuePart = segment.slice(colonIndex + 1).trim();\n\n\t\t// Parse the condition type and expression\n\t\tconst conditionMatch = conditionPart.match(\n\t\t\t/^(style|media|supports)\\((.*)\\)$/\n\t\t);\n\t\tif (!conditionMatch) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid if() function: unknown condition type in \"${conditionPart}\"`\n\t\t\t);\n\t\t}\n\n\t\tconditions.push({\n\t\t\tconditionType: conditionMatch[1],\n\t\t\tconditionExpression: conditionMatch[2],\n\t\t\tvalue: valuePart\n\t\t});\n\t}\n\n\tif (!elseValue) {\n\t\tthrow new Error('Invalid if() function: missing else clause');\n\t}\n\n\treturn {\n\t\tconditions,\n\t\telseValue,\n\t\tisMultipleConditions: conditions.length > 1\n\t};\n};\n\n/**\n * Transform property with if() to native CSS\n */\nconst transformPropertyToNative = (selector, property, value) => {\n\tconst ifFunctions = extractIfFunctions(value);\n\n\tif (ifFunctions.length === 0) {\n\t\treturn {\n\t\t\tnativeCSS: `${selector} { ${property}: ${value}; }`,\n\t\t\truntimeCSS: '',\n\t\t\thasRuntimeRules: false\n\t\t};\n\t}\n\n\tconst nativeRules = [];\n\tconst runtimeRules = [];\n\n\t// Process each if() function\n\tfor (const ifFunc of ifFunctions) {\n\t\ttry {\n\t\t\tconst parsed = parseIfFunction(ifFunc.content);\n\n\t\t\t// Check if any condition uses style() - if so, needs runtime processing\n\t\t\tconst hasStyleCondition = parsed.conditions.some(\n\t\t\t\t(condition) => condition.conditionType === 'style'\n\t\t\t);\n\n\t\t\tif (hasStyleCondition) {\n\t\t\t\t// If any condition uses style(), fall back to runtime processing\n\t\t\t\truntimeRules.push({\n\t\t\t\t\tselector,\n\t\t\t\t\tproperty,\n\t\t\t\t\tvalue,\n\t\t\t\t\tcondition: parsed\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// All conditions are media() or supports() - can transform to native CSS\n\t\t\t// Create fallback rule first\n\t\t\tconst fallbackValue = value.replace(\n\t\t\t\tifFunc.fullFunction,\n\t\t\t\tparsed.elseValue\n\t\t\t);\n\t\t\tnativeRules.push({\n\t\t\t\tcondition: null, // No condition = fallback\n\t\t\t\trule: `${selector} { ${property}: ${fallbackValue}; }`\n\t\t\t});\n\n\t\t\t// Create conditional rules for each condition (in reverse order for CSS cascade)\n\t\t\tconst { conditions } = parsed;\n\t\t\tfor (let i = conditions.length - 1; i >= 0; i--) {\n\t\t\t\tconst condition = conditions[i];\n\t\t\t\tconst nativeCondition =\n\t\t\t\t\tcondition.conditionType === 'media'\n\t\t\t\t\t\t? `@media (${condition.conditionExpression})`\n\t\t\t\t\t\t: `@supports (${condition.conditionExpression})`;\n\n\t\t\t\tconst conditionalValue = value.replace(\n\t\t\t\t\tifFunc.fullFunction,\n\t\t\t\t\tcondition.value\n\t\t\t\t);\n\t\t\t\tnativeRules.push({\n\t\t\t\t\tcondition: nativeCondition,\n\t\t\t\t\trule: `${selector} { ${property}: ${conditionalValue}; }`\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (error) {\n\t\t\t// If parsing fails, fall back to runtime processing\n\t\t\truntimeRules.push({\n\t\t\t\tselector,\n\t\t\t\tproperty,\n\t\t\t\tvalue,\n\t\t\t\terror: error.message\n\t\t\t});\n\t\t}\n\t}\n\n\t// Generate native CSS\n\tlet nativeCSS = '';\n\tconst fallbackRules = [];\n\n\tfor (const rule of nativeRules) {\n\t\tif (rule.condition) {\n\t\t\tnativeCSS += `${rule.condition} {\\n  ${rule.rule}\\n}\\n`;\n\t\t} else {\n\t\t\tfallbackRules.push(rule.rule);\n\t\t}\n\t}\n\n\t// Add fallback rules first (mobile-first approach)\n\tif (fallbackRules.length > 0) {\n\t\tnativeCSS = fallbackRules.join('\\n') + '\\n' + nativeCSS;\n\t}\n\n\t// Generate runtime CSS\n\tlet runtimeCSS = '';\n\tif (runtimeRules.length > 0) {\n\t\truntimeCSS = runtimeRules\n\t\t\t.map(\n\t\t\t\t(rule) =>\n\t\t\t\t\t`${rule.selector} { ${rule.property}: ${rule.value}; }`\n\t\t\t)\n\t\t\t.join('\\n');\n\t}\n\n\treturn {\n\t\tnativeCSS: nativeCSS.trim(),\n\t\truntimeCSS: runtimeCSS.trim(),\n\t\thasRuntimeRules: runtimeRules.length > 0\n\t};\n};\n\n/**\n * Parse a CSS declaration string into property-value pairs\n */\nconst parseDeclaration = (declaration) => {\n\tconst colonIndex = declaration.indexOf(':');\n\tif (colonIndex === -1) {\n\t\treturn null;\n\t}\n\n\tconst property = declaration.slice(0, colonIndex).trim();\n\tconst value = declaration.slice(colonIndex + 1).trim();\n\n\tif (property && value) {\n\t\treturn { property, value };\n\t}\n\n\treturn null;\n};\n\n/**\n * Parse a CSS rule and extract selector and properties\n */\nconst parseRule = (ruleText) => {\n\tconst openBrace = ruleText.indexOf('{');\n\tconst closeBrace = ruleText.lastIndexOf('}');\n\n\tif (openBrace === -1 || closeBrace === -1) {\n\t\treturn null;\n\t}\n\n\tconst selector = ruleText.slice(0, openBrace).trim();\n\tconst declarations = ruleText.slice(openBrace + 1, closeBrace).trim();\n\n\tconst properties = [];\n\n\t// Parse declarations with proper handling of semicolons in parentheses\n\tlet currentDeclaration = '';\n\tlet depth = 0;\n\tlet inQuotes = false;\n\tlet quoteChar = '';\n\n\tfor (let i = 0; i < declarations.length; i++) {\n\t\tconst char = declarations[i];\n\t\tconst previousChar = i > 0 ? declarations[i - 1] : '';\n\n\t\t// Handle quotes\n\t\tif ((char === '\"' || char === \"'\") && previousChar !== '\\\\') {\n\t\t\tif (!inQuotes) {\n\t\t\t\tinQuotes = true;\n\t\t\t\tquoteChar = char;\n\t\t\t} else if (char === quoteChar) {\n\t\t\t\tinQuotes = false;\n\t\t\t\tquoteChar = '';\n\t\t\t}\n\t\t}\n\n\t\tif (!inQuotes) {\n\t\t\tif (char === '(') {\n\t\t\t\tdepth++;\n\t\t\t} else if (char === ')') {\n\t\t\t\tdepth--;\n\t\t\t}\n\t\t}\n\n\t\tif (char === ';' && depth === 0 && !inQuotes) {\n\t\t\t// This is a real property separator\n\t\t\tif (currentDeclaration.trim()) {\n\t\t\t\tconst parsed = parseDeclaration(currentDeclaration);\n\t\t\t\tif (parsed) {\n\t\t\t\t\tproperties.push(parsed);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tcurrentDeclaration = '';\n\t\t} else {\n\t\t\tcurrentDeclaration += char;\n\t\t}\n\t}\n\n\t// Handle the last declaration\n\tif (currentDeclaration.trim()) {\n\t\tconst parsed = parseDeclaration(currentDeclaration);\n\t\tif (parsed) {\n\t\t\tproperties.push(parsed);\n\t\t}\n\t}\n\n\treturn {\n\t\tselector,\n\t\tproperties\n\t};\n};\n\n/**\n * Transform CSS text to native CSS where possible\n */\nconst transformToNativeCSS = (cssText) => {\n\tconst rules = parseCSSRules(cssText);\n\tlet nativeCSS = '';\n\tlet runtimeCSS = '';\n\tlet hasRuntimeRules = false;\n\n\tfor (const ruleText of rules) {\n\t\tconst rule = parseRule(ruleText);\n\n\t\tif (!rule) {\n\t\t\t// Keep non-rule content as-is\n\t\t\tnativeCSS += ruleText + '\\n';\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet hasIfConditions = false;\n\t\tconst nonIfProperties = [];\n\n\t\tfor (const { property, value } of rule.properties) {\n\t\t\tif (value.includes('if(')) {\n\t\t\t\thasIfConditions = true;\n\t\t\t\tconst transformed = transformPropertyToNative(\n\t\t\t\t\trule.selector,\n\t\t\t\t\tproperty,\n\t\t\t\t\tvalue\n\t\t\t\t);\n\n\t\t\t\tif (transformed.nativeCSS) {\n\t\t\t\t\tnativeCSS += transformed.nativeCSS + '\\n';\n\t\t\t\t}\n\n\t\t\t\tif (transformed.hasRuntimeRules) {\n\t\t\t\t\truntimeCSS += transformed.runtimeCSS + '\\n';\n\t\t\t\t\thasRuntimeRules = true;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Collect non-if() properties to preserve them\n\t\t\t\tnonIfProperties.push(`${property}: ${value}`);\n\t\t\t}\n\t\t}\n\n\t\t// If we have non-if() properties in a rule that also has if() properties,\n\t\t// we need to create a base rule with those properties\n\t\tif (hasIfConditions && nonIfProperties.length > 0) {\n\t\t\tnativeCSS += `${rule.selector} { ${nonIfProperties.join('; ')}; }\\n`;\n\t\t} else if (!hasIfConditions) {\n\t\t\t// Keep rules without if() conditions as-is\n\t\t\tnativeCSS += ruleText + '\\n';\n\t\t}\n\t}\n\n\treturn {\n\t\tnativeCSS: nativeCSS.trim(),\n\t\truntimeCSS: runtimeCSS.trim(),\n\t\thasRuntimeRules,\n\t\tstats: {\n\t\t\ttotalRules: rules.length,\n\t\t\ttransformedRules: rules.filter((rule) => rule.includes('if('))\n\t\t\t\t.length\n\t\t}\n\t};\n};\n\n/**\n * Build-time transformation utility\n */\nconst buildTimeTransform = (cssText, options = {}) => {\n\tconst {\n\t\t_generateFallbacks = true,\n\t\t_optimizeMediaQueries = true,\n\t\tminify = false\n\t} = options;\n\n\tconst result = transformToNativeCSS(cssText);\n\n\tif (minify) {\n\t\tresult.nativeCSS = result.nativeCSS\n\t\t\t.replaceAll(/\\s+/g, ' ')\n\t\t\t.replaceAll(/;\\s*}/g, '}')\n\t\t\t.replaceAll(/{\\s+/g, '{')\n\t\t\t.trim();\n\t}\n\n\treturn result;\n};\n\n/**\n * Runtime transformation utility (for integration with existing polyfill)\n */\nconst runtimeTransform = (cssText, element) => {\n\tconst result = transformToNativeCSS(cssText);\n\n\t// Apply native CSS immediately if we have it\n\tif (result.nativeCSS && element) {\n\t\tconst style = document.createElement('style');\n\t\tstyle.textContent = result.nativeCSS;\n\t\tstyle.dataset.cssIfNative = 'true';\n\t\tdocument.head.append(style);\n\t}\n\n\t// Return runtime CSS for further processing by the polyfill\n\treturn {\n\t\tprocessedCSS: result.runtimeCSS,\n\t\thasRuntimeRules: result.hasRuntimeRules,\n\t\tnativeCSS: result.nativeCSS\n\t};\n};\n\nexport {\n\tbuildTimeTransform,\n\textractIfFunctions,\n\tparseCSSRules,\n\tparseIfFunction,\n\tparseRule,\n\truntimeTransform,\n\ttransformPropertyToNative,\n\ttransformToNativeCSS\n};\n","/**\n * CSS Custom Function Function Polyfill\n * Provides support for CSS Custom Function function with style(), media(), and supports() conditions\n * Syntax: if(condition: value; else: fallback-value)\n * Supports multiple conditions within a single if() and usage within CSS shorthand properties\n */\n\n/* global document, CSS, Node, MutationObserver */\n\nimport { runtimeTransform } from './transform.js';\n\n// Global state\nlet polyfillOptions = {\n\tdebug: false,\n\tautoInit: true,\n\tuseNativeTransform: true // New option to enable native CSS transformation\n};\n\n// Registry for tracking media queries and their associated elements\nconst mediaQueryRegistry = new Map(); // MediaQuery -> Set of { element, originalContent }\nconst mediaQueryListeners = new Map(); // MediaQuery -> MediaQueryList\n\n/**\n * Log debug messages\n */\nconst log = (...arguments_) => {\n\tif (polyfillOptions.debug) {\n\t\tconsole.log('[CSS Custom Functions polyfill]', ...arguments_);\n\t}\n};\n\n/**\n * Check if browser has native CSS Custom Function support\n */\nconst hasNativeSupport = () => {\n\tif (globalThis.window === undefined || !globalThis.CSS) {\n\t\treturn false;\n\t}\n\n\ttry {\n\t\t// Test if CSS Custom Function function is supported by testing a specific CSS Custom Function syntax\n\t\treturn globalThis.CSS.supports(\n\t\t\t'color',\n\t\t\t'if(style(--true): red; else: blue)'\n\t\t);\n\t} catch {\n\t\treturn false;\n\t}\n};\n\n/**\n * Evaluate a condition (style(), media(), supports())\n */\nconst evaluateCondition = (\n\tcondition,\n\tregisterForTracking = false,\n\telement = null,\n\toriginalContent = null\n) => {\n\tcondition = condition.trim();\n\n\t// Handle style() function\n\tif (condition.startsWith('style(')) {\n\t\treturn evaluateStyleCondition(condition);\n\t}\n\n\t// Handle media() function\n\tif (condition.startsWith('media(')) {\n\t\treturn evaluateMediaCondition(\n\t\t\tcondition,\n\t\t\tregisterForTracking,\n\t\t\telement,\n\t\t\toriginalContent\n\t\t);\n\t}\n\n\t// Handle supports() function\n\tif (condition.startsWith('supports(')) {\n\t\treturn evaluateSupportsCondition(condition);\n\t}\n\n\t// Direct boolean evaluation\n\treturn evaluateBooleanCondition(condition);\n};\n\n/**\n * Evaluate style() condition\n */\nconst evaluateStyleCondition = (condition) => {\n\tconst match = condition.match(/style\\s*\\(\\s*([^)]+)\\s*\\)/);\n\tif (!match) {\n\t\treturn false;\n\t}\n\n\tconst query = match[1].trim();\n\n\t// Parse property and optional value\n\tconst parts = query.split(':').map((part) => part.trim());\n\tconst property = parts[0];\n\tconst expectedValue = parts[1];\n\n\t// Get computed style from document element or a test element\n\tconst testElement = document.createElement('div');\n\tdocument.body.append(testElement);\n\n\ttry {\n\t\tconst computedStyle = globalThis.getComputedStyle(testElement);\n\t\tconst actualValue = computedStyle.getPropertyValue(property);\n\n\t\tif (expectedValue) {\n\t\t\treturn actualValue === expectedValue;\n\t\t}\n\n\t\t// If no expected value, check if property has any value\n\t\treturn actualValue !== '' && actualValue !== 'initial';\n\t} catch {\n\t\treturn false;\n\t} finally {\n\t\ttestElement.remove();\n\t}\n};\n\n/**\n * Evaluate media() condition\n */\nconst evaluateMediaCondition = (\n\tcondition,\n\tregisterForTracking = false,\n\telement = null,\n\toriginalContent = null\n) => {\n\tconst match = condition.match(/media\\s*\\(\\s*([^)]+)\\s*\\)/);\n\tif (!match) {\n\t\treturn false;\n\t}\n\n\tconst mediaQuery = match[1].trim();\n\n\ttry {\n\t\tconst mediaQueryList = globalThis.matchMedia(`(${mediaQuery})`);\n\t\tconst result = mediaQueryList.matches;\n\n\t\t// Register this media query for change tracking if requested\n\t\tif (registerForTracking && element && originalContent) {\n\t\t\tregisterMediaQuery(\n\t\t\t\tmediaQuery,\n\t\t\t\telement,\n\t\t\t\toriginalContent,\n\t\t\t\tmediaQueryList\n\t\t\t);\n\t\t}\n\n\t\treturn result;\n\t} catch {\n\t\treturn false;\n\t}\n};\n\n/**\n * Evaluate supports() condition\n */\nconst evaluateSupportsCondition = (condition) => {\n\tconst match = condition.match(/supports\\s*\\(\\s*([^)]+)\\s*\\)/);\n\tif (!match) {\n\t\treturn false;\n\t}\n\n\tconst feature = match[1].trim();\n\n\ttry {\n\t\treturn CSS.supports(feature);\n\t} catch {\n\t\treturn false;\n\t}\n};\n\n/**\n * Evaluate boolean condition\n */\nconst evaluateBooleanCondition = (condition) => {\n\t// Simple boolean evaluation\n\tconst lowerCondition = condition.toLowerCase();\n\n\tif (lowerCondition === 'true' || lowerCondition === '1') {\n\t\treturn true;\n\t}\n\n\tif (lowerCondition === 'false' || lowerCondition === '0') {\n\t\treturn false;\n\t}\n\n\treturn false;\n};\n\n/**\n * Parse multiple conditions within a single if() function\n */\nconst parseMultipleConditions = (ifContent) => {\n\tconst conditions = [];\n\tlet currentCondition = '';\n\tlet depth = 0;\n\tlet inQuotes = false;\n\tlet quoteChar = '';\n\n\tfor (let i = 0; i < ifContent.length; i++) {\n\t\tconst char = ifContent[i];\n\t\tconst previousChar = i > 0 ? ifContent[i - 1] : '';\n\n\t\t// Handle quotes\n\t\tif ((char === '\"' || char === \"'\") && previousChar !== '\\\\') {\n\t\t\tif (!inQuotes) {\n\t\t\t\tinQuotes = true;\n\t\t\t\tquoteChar = char;\n\t\t\t} else if (char === quoteChar) {\n\t\t\t\tinQuotes = false;\n\t\t\t\tquoteChar = '';\n\t\t\t}\n\t\t}\n\n\t\t// Handle parentheses depth\n\t\tif (!inQuotes) {\n\t\t\tif (char === '(') {\n\t\t\t\tdepth++;\n\t\t\t} else if (char === ')') {\n\t\t\t\tdepth--;\n\t\t\t}\n\t\t}\n\n\t\t// Check for semicolon separator at depth 0\n\t\tif (!inQuotes && depth === 0 && char === ';') {\n\t\t\t// This is a separator between conditions\n\t\t\tif (currentCondition.trim()) {\n\t\t\t\tconditions.push(currentCondition.trim());\n\t\t\t}\n\n\t\t\tcurrentCondition = '';\n\t\t\tcontinue;\n\t\t}\n\n\t\tcurrentCondition += char;\n\t}\n\n\t// Add the last condition\n\tif (currentCondition.trim()) {\n\t\tconditions.push(currentCondition.trim());\n\t}\n\n\treturn conditions;\n};\n\n/**\n * Process a single condition within an if() function\n */\nconst processSingleCondition = (condition) => {\n\t// Check if this is an else clause\n\tif (condition.trim().startsWith('else:')) {\n\t\treturn {\n\t\t\tisElse: true,\n\t\t\tvalue: condition.replace(/^\\s*else\\s*:\\s*/, '').trim()\n\t\t};\n\t}\n\n\t// Find the main separator colon (outside of parentheses)\n\tlet depth = 0;\n\tlet inQuotes = false;\n\tlet quoteChar = '';\n\tlet separatorIndex = -1;\n\n\tfor (let i = 0; i < condition.length; i++) {\n\t\tconst char = condition[i];\n\t\tconst previousChar = i > 0 ? condition[i - 1] : '';\n\n\t\t// Handle quotes\n\t\tif ((char === '\"' || char === \"'\") && previousChar !== '\\\\') {\n\t\t\tif (!inQuotes) {\n\t\t\t\tinQuotes = true;\n\t\t\t\tquoteChar = char;\n\t\t\t} else if (char === quoteChar) {\n\t\t\t\tinQuotes = false;\n\t\t\t\tquoteChar = '';\n\t\t\t}\n\t\t}\n\n\t\t// Handle parentheses depth\n\t\tif (!inQuotes) {\n\t\t\tif (char === '(') {\n\t\t\t\tdepth++;\n\t\t\t} else if (char === ')') {\n\t\t\t\tdepth--;\n\t\t\t} else if (char === ':' && depth === 0) {\n\t\t\t\t// This is the main separator colon\n\t\t\t\tseparatorIndex = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (separatorIndex === -1) {\n\t\tlog('Invalid condition format:', condition);\n\t\treturn null;\n\t}\n\n\tconst conditionPart = condition.slice(0, separatorIndex).trim();\n\tconst valuePart = condition.slice(separatorIndex + 1).trim();\n\n\treturn {\n\t\tisElse: false,\n\t\tcondition: conditionPart,\n\t\tvalue: valuePart\n\t};\n};\n\n/**\n * Process multiple conditions within a single if() function\n */\nconst processMultipleConditions = (\n\tifContent,\n\tregisterForTracking = false,\n\telement = null,\n\toriginalContent = null\n) => {\n\t// Handle malformed if() functions that don't contain proper syntax\n\tif (!ifContent || !ifContent.includes(':')) {\n\t\tlog('Malformed if() function - missing colon separator');\n\t\tthrow new Error('Malformed if() syntax');\n\t}\n\n\tconst conditions = parseMultipleConditions(ifContent);\n\tlet elseValue = '';\n\n\t// Process each condition in order\n\tfor (const condition of conditions) {\n\t\tconst parsed = processSingleCondition(condition);\n\n\t\tif (!parsed) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (parsed.isElse) {\n\t\t\telseValue = parsed.value;\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Evaluate the condition\n\t\tconst isTrue = evaluateCondition(\n\t\t\tparsed.condition,\n\t\t\tregisterForTracking,\n\t\t\telement,\n\t\t\toriginalContent\n\t\t);\n\n\t\tif (isTrue) {\n\t\t\tlog(`Condition matched: ${parsed.condition} -> ${parsed.value}`);\n\t\t\treturn parsed.value;\n\t\t}\n\t}\n\n\t// No condition matched, return else value\n\tlog(`No condition matched, using else value: ${elseValue}`);\n\treturn elseValue;\n};\n\n/**\n * Find and extract if() functions with proper nested parentheses handling\n */\nconst findIfFunctions = (text) => {\n\tconst functions = [];\n\tlet index = 0;\n\n\twhile (index < text.length) {\n\t\tconst match = text.indexOf('if(', index);\n\t\tif (match === -1) {\n\t\t\tbreak;\n\t\t}\n\n\t\t// Make sure it's actually an if() function (not part of another word)\n\t\tif (match > 0 && /[\\w-]/.test(text[match - 1])) {\n\t\t\tindex = match + 1;\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Find the matching closing parenthesis\n\t\tlet depth = 0;\n\t\tlet inQuotes = false;\n\t\tlet quoteChar = '';\n\t\tconst start = match + 3; // Start after 'if('\n\t\tlet end = -1;\n\n\t\tfor (let i = start; i < text.length; i++) {\n\t\t\tconst char = text[i];\n\t\t\tconst previousChar = i > 0 ? text[i - 1] : '';\n\n\t\t\t// Handle quotes\n\t\t\tif ((char === '\"' || char === \"'\") && previousChar !== '\\\\') {\n\t\t\t\tif (!inQuotes) {\n\t\t\t\t\tinQuotes = true;\n\t\t\t\t\tquoteChar = char;\n\t\t\t\t} else if (char === quoteChar) {\n\t\t\t\t\tinQuotes = false;\n\t\t\t\t\tquoteChar = '';\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (!inQuotes) {\n\t\t\t\tif (char === '(') {\n\t\t\t\t\tdepth++;\n\t\t\t\t} else if (char === ')') {\n\t\t\t\t\tif (depth === 0) {\n\t\t\t\t\t\tend = i;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tdepth--;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (end === -1) {\n\t\t\t// Malformed if() function\n\t\t\tindex = match + 3;\n\t\t} else {\n\t\t\tconst fullMatch = text.slice(match, end + 1);\n\t\t\tconst content = text.slice(start, end);\n\t\t\tfunctions.push({\n\t\t\t\tmatch: fullMatch,\n\t\t\t\tcontent,\n\t\t\t\tstart: match,\n\t\t\t\tend: end + 1\n\t\t\t});\n\t\t\tindex = end + 1;\n\t\t}\n\t}\n\n\treturn functions;\n};\n\n/**\n * Process CSS text manually\n */\nconst processCSSText = (cssText, options = {}, element = null) => {\n\t// Set options for this processing session\n\tconst originalOptions = { ...polyfillOptions };\n\tpolyfillOptions = { ...polyfillOptions, ...options };\n\n\t// Store original content for media query tracking\n\tconst originalContent = cssText;\n\n\ttry {\n\t\t// Check if we should use native transformation\n\t\t// Disable native transformation if browser APIs appear to be mocked (for testing)\n\t\tconst shouldUseNativeTransform =\n\t\t\tpolyfillOptions.useNativeTransform &&\n\t\t\t!(\n\t\t\t\tglobalThis.matchMedia?.mockClear ||\n\t\t\t\tglobalThis.CSS?.supports?.mockClear\n\t\t\t);\n\n\t\t// Try native transformation first if enabled and not in test environment\n\t\tif (shouldUseNativeTransform) {\n\t\t\ttry {\n\t\t\t\tconst transformResult = runtimeTransform(cssText, element);\n\n\t\t\t\tif (transformResult.nativeCSS) {\n\t\t\t\t\tlog('Native CSS transformation applied');\n\t\t\t\t}\n\n\t\t\t\t// If we have runtime rules that need processing, continue with polyfill\n\t\t\t\tif (transformResult.hasRuntimeRules) {\n\t\t\t\t\t// Use processed CSS Custom Function available, otherwise continue with original\n\t\t\t\t\tcssText = transformResult.processedCSS || cssText;\n\t\t\t\t} else {\n\t\t\t\t\t// All transformations were native, return original CSS\n\t\t\t\t\t// The native CSS was already injected by runtimeTransform\n\t\t\t\t\treturn cssText;\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tlog(\n\t\t\t\t\t'Native transformation failed, falling back to polyfill:',\n\t\t\t\t\terror\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tlet result = cssText;\n\t\tlet hasChanges = true;\n\n\t\t// Keep processing until no more if() functions are found\n\t\t// This handles multiple if() functions in the same property value\n\t\twhile (hasChanges) {\n\t\t\thasChanges = false;\n\t\t\tconst ifFunctions = findIfFunctions(result);\n\n\t\t\t// Process if() functions from right to left to maintain indices\n\t\t\tfor (let i = ifFunctions.length - 1; i >= 0; i--) {\n\t\t\t\tconst { match, content, start, end } = ifFunctions[i];\n\n\t\t\t\tlog('Processing if() function:', match);\n\n\t\t\t\ttry {\n\t\t\t\t\t// Enable media query tracking if we have an element\n\t\t\t\t\tconst registerForTracking = element !== null;\n\t\t\t\t\tconst processedResult = processMultipleConditions(\n\t\t\t\t\t\tcontent,\n\t\t\t\t\t\tregisterForTracking,\n\t\t\t\t\t\telement,\n\t\t\t\t\t\toriginalContent\n\t\t\t\t\t);\n\t\t\t\t\tlog(`Result: ${processedResult}`);\n\n\t\t\t\t\t// Replace the if() function with the result\n\t\t\t\t\tresult =\n\t\t\t\t\t\tresult.slice(0, start) +\n\t\t\t\t\t\tprocessedResult +\n\t\t\t\t\t\tresult.slice(end);\n\t\t\t\t\thasChanges = true;\n\t\t\t\t} catch (error) {\n\t\t\t\t\tlog('Error processing if() function:', error);\n\t\t\t\t\t// For malformed if() functions, leave them unchanged\n\t\t\t\t\t// Don't remove them, as they might be valid in future CSS specs\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\t} finally {\n\t\t// Restore original options\n\t\tpolyfillOptions = originalOptions;\n\t}\n};\n\n/**\n * Process a style element by rewriting its content\n */\nconst processStyleElement = (styleElement) => {\n\tif (styleElement.dataset.cssIfPolyfillProcessed) {\n\t\treturn; // Already processed\n\t}\n\n\tconst originalContent = styleElement.textContent;\n\tconst processedContent = processCSSText(originalContent, {}, styleElement);\n\n\tif (processedContent !== originalContent) {\n\t\tlog(\n\t\t\t'Processing style element, original length:',\n\t\t\toriginalContent.length\n\t\t);\n\t\tstyleElement.textContent = processedContent;\n\t\tstyleElement.dataset.cssIfPolyfillProcessed = 'true';\n\t\tlog('Style element processed, new length:', processedContent.length);\n\t}\n};\n\n/**\n * Process all existing style elements\n */\nconst processExistingStylesheets = () => {\n\t// Process inline style elements\n\tconst styleElements = document.querySelectorAll(\n\t\t'style:not([data-css-custom-functions-polyfill-processed])'\n\t);\n\tlog(`Found ${styleElements.length} unprocessed style elements`);\n\n\tfor (const styleElement of styleElements) {\n\t\tprocessStyleElement(styleElement);\n\t}\n\n\t// Process link stylesheets that we can access\n\tconst linkElements = document.querySelectorAll('link[rel=\"stylesheet\"]');\n\tfor (const linkElement of linkElements) {\n\t\t// We can't directly modify external stylesheets due to CORS,\n\t\t// but we can try to fetch and reprocess them if they're same-origin\n\t\tprocessLinkStylesheet(linkElement);\n\t}\n};\n\n/**\n * Process external stylesheet (if accessible)\n */\nasync function processLinkStylesheet(linkElement) {\n\tif (linkElement.dataset.cssIfPolyfillProcessed) {\n\t\treturn;\n\t}\n\n\t// Only process same-origin stylesheets\n\ttry {\n\t\tconst url = new URL(linkElement.href);\n\t\tif (url.origin !== globalThis.location.origin) {\n\t\t\tlog('Skipping cross-origin stylesheet:', linkElement.href);\n\t\t\treturn;\n\t\t}\n\n\t\t// Fetch the stylesheet content\n\t\ttry {\n\t\t\tconst response = await fetch(linkElement.href);\n\t\t\tconst cssText = await response.text();\n\n\t\t\t// Create a new style element first so we can pass it for tracking\n\t\t\tconst styleElement = document.createElement('style');\n\t\t\tconst processedCssText = processCSSText(cssText, {}, styleElement);\n\n\t\t\tif (processedCssText !== cssText) {\n\t\t\t\tstyleElement.textContent = processedCssText;\n\t\t\t\tstyleElement.dataset.cssIfPolyfillProcessed = 'true';\n\t\t\t\tstyleElement.dataset.originalHref = linkElement.href;\n\n\t\t\t\t// Insert the style element after the link element\n\t\t\t\tlinkElement.parentNode.insertBefore(\n\t\t\t\t\tstyleElement,\n\t\t\t\t\tlinkElement.nextSibling\n\t\t\t\t);\n\n\t\t\t\t// Disable the original link (but don't remove it for compatibility)\n\t\t\t\tlinkElement.disabled = true;\n\t\t\t\tlinkElement.dataset.cssIfPolyfillProcessed = 'true';\n\n\t\t\t\tlog(\n\t\t\t\t\t'External stylesheet processed and replaced:',\n\t\t\t\t\tlinkElement.href\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tlog(\n\t\t\t\t'Could not fetch external stylesheet:',\n\t\t\t\tlinkElement.href,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t} catch (error) {\n\t\tlog('Error processing external stylesheet:', error);\n\t}\n}\n\n/**\n * Register a media query for change tracking\n */\nconst registerMediaQuery = (\n\tmediaQuery,\n\telement,\n\toriginalContent,\n\tmediaQueryList = null\n) => {\n\tif (!mediaQueryRegistry.has(mediaQuery)) {\n\t\tmediaQueryRegistry.set(mediaQuery, new Set());\n\t}\n\n\tmediaQueryRegistry.get(mediaQuery).add({ element, originalContent });\n\n\t// Set up listener if not already done\n\tif (!mediaQueryListeners.has(mediaQuery)) {\n\t\ttry {\n\t\t\t// Use provided MediaQueryList or create a new one\n\t\t\tconst mql =\n\t\t\t\tmediaQueryList || globalThis.matchMedia(`(${mediaQuery})`);\n\t\t\tconst listener = () => {\n\t\t\t\tlog(`Media query changed: ${mediaQuery}`);\n\t\t\t\treprocessElementsForMediaQuery(mediaQuery);\n\t\t\t};\n\n\t\t\tmql.addEventListener('change', listener);\n\t\t\tmediaQueryListeners.set(mediaQuery, {\n\t\t\t\tmediaQueryList: mql,\n\t\t\t\tlistener\n\t\t\t});\n\n\t\t\tlog(`Registered media query listener: ${mediaQuery}`);\n\t\t} catch (error) {\n\t\t\tlog(\n\t\t\t\t`Failed to register media query listener: ${mediaQuery}`,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n};\n\n/**\n * Reprocess elements when a media query changes\n */\nconst reprocessElementsForMediaQuery = (mediaQuery) => {\n\tconst elements = mediaQueryRegistry.get(mediaQuery);\n\tif (!elements) {\n\t\treturn;\n\t}\n\n\tfor (const { element, originalContent } of elements) {\n\t\ttry {\n\t\t\tconst processedContent = processCSSText(originalContent);\n\t\t\tif (element.textContent !== processedContent) {\n\t\t\t\tlog(\n\t\t\t\t\t`Updating element due to media query change: ${mediaQuery}`\n\t\t\t\t);\n\t\t\t\telement.textContent = processedContent;\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tlog(\n\t\t\t\t`Error reprocessing element for media query ${mediaQuery}:`,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n};\n\n/**\n * Clean up media query listeners\n */\nconst cleanupMediaQueryListeners = () => {\n\tfor (const [\n\t\tmediaQuery,\n\t\t{ mediaQueryList, listener }\n\t] of mediaQueryListeners) {\n\t\ttry {\n\t\t\tmediaQueryList.removeEventListener('change', listener);\n\t\t\tlog(`Cleaned up media query listener: ${mediaQuery}`);\n\t\t} catch (error) {\n\t\t\tlog(`Error cleaning up media query listener: ${mediaQuery}`, error);\n\t\t}\n\t}\n\n\tmediaQueryListeners.clear();\n\tmediaQueryRegistry.clear();\n};\n\n/**\n * Observe stylesheet changes\n */\nconst observeStylesheetChanges = () => {\n\t// Create a MutationObserver to watch for new stylesheets\n\tconst observer = new MutationObserver((mutations) => {\n\t\tfor (const mutation of mutations) {\n\t\t\tfor (const node of mutation.addedNodes) {\n\t\t\t\tif (\n\t\t\t\t\tnode.nodeType === Node.ELEMENT_NODE &&\n\t\t\t\t\t(node.tagName === 'STYLE' || node.tagName === 'LINK')\n\t\t\t\t) {\n\t\t\t\t\tlog('New style element detected:', node.tagName);\n\n\t\t\t\t\tif (node.tagName === 'STYLE') {\n\t\t\t\t\t\t// Process inline style elements immediately\n\t\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\t\tprocessStyleElement(node);\n\t\t\t\t\t\t}, 0);\n\t\t\t\t\t} else if (\n\t\t\t\t\t\tnode.tagName === 'LINK' &&\n\t\t\t\t\t\tnode.rel === 'stylesheet'\n\t\t\t\t\t) {\n\t\t\t\t\t\t// Process link stylesheets after they load\n\t\t\t\t\t\tnode.addEventListener('load', () => {\n\t\t\t\t\t\t\tprocessLinkStylesheet(node);\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\t// Also try to process immediately in case it's already loaded\n\t\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\t\tprocessLinkStylesheet(node);\n\t\t\t\t\t\t}, 100);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t});\n\n\tobserver.observe(document.head, {\n\t\tchildList: true,\n\t\tsubtree: true\n\t});\n\n\t// Also observe the body for style elements that might be added there\n\tobserver.observe(document.body, {\n\t\tchildList: true,\n\t\tsubtree: true\n\t});\n};\n\n/**\n * Initialize the polyfill\n */\nconst init = (options = {}) => {\n\tif (globalThis.window === undefined) {\n\t\tthrow new TypeError(\n\t\t\t'CSS Custom Functions polyfill requires a browser environment'\n\t\t);\n\t}\n\n\t// Update global options\n\tpolyfillOptions = { ...polyfillOptions, ...options };\n\n\tif (hasNativeSupport()) {\n\t\tlog('Native CSS Custom Function support detected, polyfill not needed');\n\t\treturn;\n\t}\n\n\tlog('Initializing CSS Custom Functions polyfill');\n\tprocessExistingStylesheets();\n\tobserveStylesheetChanges();\n};\n\n/**\n * Public API to manually trigger processing\n */\nconst refresh = () => {\n\tprocessExistingStylesheets();\n};\n\n// Auto-initialize if in browser and DOMContentLoaded\nif (globalThis.window !== undefined && typeof document !== 'undefined') {\n\tif (document.readyState === 'loading') {\n\t\tdocument.addEventListener('DOMContentLoaded', () => {\n\t\t\tinit();\n\t\t});\n\t} else {\n\t\tinit();\n\t}\n}\n\n// Named exports for modern usage\n// Re-export build-time transformation\nexport { buildTimeTransform } from './transform.js';\nexport {\n\tcleanupMediaQueryListeners,\n\thasNativeSupport,\n\tinit,\n\tprocessCSSText,\n\trefresh\n};\n"],"names":["handleStrings","char","previousChar","parseState","inString","stringChar","findConditionValueSeparator","segment","parenDepth","inQuotes","quoteChar","i","length","parseIfFunction","content","_step","segments","currentSegment","push","trim","splitIfConditionSegments","conditions","elseValue","_iterator","_createForOfIteratorHelperLoose","done","value","elseMatch","match","colonIndex","Error","conditionPart","slice","valuePart","conditionMatch","conditionType","conditionExpression","isMultipleConditions","transformPropertyToNative","selector","property","ifFunctions","cssText","functions","index","ifMatch","indexOf","test","depth","start","end","fullFunction","extractIfFunctions","nativeCSS","runtimeCSS","hasRuntimeRules","_step2","nativeRules","runtimeRules","_iterator2","ifFunc","parsed","hasStyleCondition","some","condition","fallbackValue","replace","rule","nativeCondition","conditionalValue","error","message","fallbackRules","_i","_nativeRules","join","map","parseDeclaration","declaration","parseRule","ruleText","openBrace","closeBrace","lastIndexOf","declarations","properties","currentDeclaration","transformToNativeCSS","_step3","rules","currentRule","braceCount","inRule","inComment","nextChar","parseCSSRules","_iterator3","_step4","hasIfConditions","nonIfProperties","_iterator4","_step4$value","includes","transformed","stats","totalRules","transformedRules","filter","_catch","body","recover","result","e","then","processLinkStylesheet","linkElement","dataset","cssIfPolyfillProcessed","Promise","resolve","URL","href","origin","globalThis","location","_temp","fetch","response","text","styleElement","document","createElement","processedCssText","processCSSText","textContent","originalHref","parentNode","insertBefore","nextSibling","disabled","log","reject","polyfillOptions","debug","autoInit","useNativeTransform","mediaQueryRegistry","Map","mediaQueryListeners","_console","console","apply","concat","call","arguments","hasNativeSupport","undefined","window","CSS","supports","_unused","evaluateCondition","registerForTracking","element","originalContent","startsWith","evaluateStyleCondition","evaluateMediaCondition","evaluateSupportsCondition","evaluateBooleanCondition","parts","split","part","expectedValue","testElement","append","actualValue","getComputedStyle","getPropertyValue","_unused2","remove","mediaQuery","mediaQueryList","matchMedia","matches","registerMediaQuery","_unused3","feature","_unused4","lowerCondition","toLowerCase","processSingleCondition","isElse","separatorIndex","processMultipleConditions","ifContent","currentCondition","parseMultipleConditions","findIfFunctions","fullMatch","options","originalOptions","_extends","_globalThis$matchMedi","_globalThis$CSS","mockClear","transformResult","style","cssIfNative","head","processedCSS","runtimeTransform","hasChanges","_ifFunctions$i","processedResult","processStyleElement","processedContent","processExistingStylesheets","styleElements","querySelectorAll","has","set","Set","get","add","mql","listener","reprocessElementsForMediaQuery","addEventListener","elements","init","TypeError","observer","MutationObserver","mutations","_iterator6","_step6","_step7","_loop","node","nodeType","Node","ELEMENT_NODE","tagName","setTimeout","rel","_iterator7","addedNodes","observe","childList","subtree","readyState","_options$minify","minify","replaceAll","_step5","_iterator5","_step5$value","_step5$value$","removeEventListener","clear"],"mappings":"4/BAUA,IAAMA,EAAgB,SAACC,EAAMC,EAAcC,GAW1C,MAVc,MAATF,GAAyB,MAATA,GAAkC,OAAjBC,IAChCC,EAAWC,SAGLH,IAASE,EAAWE,aAC9BF,EAAWC,UAAW,EACtBD,EAAWE,WAAa,KAJxBF,EAAWC,UAAW,EACtBD,EAAWE,WAAaJ,IAOnBE,EAAWC,QACnB,EA0NME,EAA8B,SAACC,GAKpC,IAJA,IAAIC,EAAa,EACbC,GAAW,EACXC,EAAY,GAEPC,EAAI,EAAGA,EAAIJ,EAAQK,OAAQD,IAAK,CACxC,IAAMV,EAAOM,EAAQI,GAcrB,GAVc,MAATV,GAAyB,MAATA,GAAkC,QAHlCU,EAAI,EAAIJ,EAAQI,EAAI,GAAK,MAIxCF,EAGMR,IAASS,IACnBD,GAAW,EACXC,EAAY,KAJZD,GAAW,EACXC,EAAYT,KAOTQ,EACJ,GAAa,MAATR,EACHO,SACM,GAAa,MAATP,EACVO,SACM,GAAa,MAATP,GAA+B,IAAfO,EAC1B,OAAOG,CAGV,CAEA,OAAQ,CACT,EAKME,EAAkB,SAACC,GAKxB,IAJA,IAI8BC,EAJxBC,EAvF0B,SAACF,GAOjC,IANA,IAAME,EAAW,GACbC,EAAiB,GACjBT,EAA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