{"version":3,"file":"index.cjs","sources":["../src/transform.js","../src/index.js"],"sourcesContent":["/**\n * CSS if() 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].trim(),\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\n\t\t\t\t// Smart parentheses handling: don't add parentheses if:\n\t\t\t\t// 1. The expression already starts with '(' and ends with ')'\n\t\t\t\t// 2. The expression already contains properly parenthesized conditions (like media queries)\n\t\t\t\tconst trimmed = condition.conditionExpression.trim();\n\t\t\t\tconst needsParentheses = !(\n\t\t\t\t\t(trimmed.startsWith('(') && trimmed.endsWith(')')) ||\n\t\t\t\t\t// Check for patterns like \"(min-width: 768px) and (max-width: 1024px)\" which are already valid CSS\n\t\t\t\t\t/^\\([^)]+\\)\\s+(and|or)\\s+\\([^)]+\\)/.test(trimmed)\n\t\t\t\t);\n\t\t\t\tconst wrappedExpression = needsParentheses\n\t\t\t\t\t? `(${condition.conditionExpression})`\n\t\t\t\t\t: condition.conditionExpression;\n\n\t\t\t\tconst nativeCondition =\n\t\t\t\t\tcondition.conditionType === 'media'\n\t\t\t\t\t\t? `@media ${wrappedExpression}`\n\t\t\t\t\t\t: `@supports ${wrappedExpression}`;\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 if() Function Polyfill\n * Provides support for CSS if() 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 if() Polyfill]', ...arguments_);\n\t}\n};\n\n/**\n * Check if browser has native CSS if() 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 if() function is supported by testing a specific CSS if() 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 if 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-if-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('CSS if() polyfill requires a browser environment');\n\t}\n\n\t// Update global options\n\tpolyfillOptions = { ...polyfillOptions, ...options };\n\n\tif (hasNativeSupport()) {\n\t\tlog('Native CSS if() support detected, polyfill not needed');\n\t\treturn;\n\t}\n\n\tlog('Initializing CSS if() 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","trimmed","wrappedExpression","startsWith","endsWith","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","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","_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,I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