UNPKG

otion

Version:

Atomic CSS-in-JS with a featherweight runtime

1 lines 32.3 kB
{"version":3,"file":"bundle.min.mjs","sources":["../../../../node_modules/@emotion/hash/dist/hash.browser.esm.js","../../../../node_modules/tiny-css-prefixer/dist/tiny-css-prefixer.es.js","../../src/env.ts","../../src/getStyleElement.ts","../../src/injectors.ts","../../src/minify.ts","../../src/propertyMatchers.ts","../../src/pseudos.ts","../../src/rulePrecedence.ts","../../src/createInstance.ts","../../src/index.ts"],"sourcesContent":["/* eslint-disable */\n// Inspired by https://github.com/garycourt/murmurhash-js\n// Ported from https://github.com/aappleby/smhasher/blob/61a0530f28277f2e850bfc39600ce61d02b518de/src/MurmurHash2.cpp#L37-L86\nfunction murmur2(str) {\n // 'm' and 'r' are mixing constants generated offline.\n // They're not really 'magic', they just happen to work well.\n // const m = 0x5bd1e995;\n // const r = 24;\n // Initialize the hash\n var h = 0; // Mix 4 bytes at a time into the hash\n\n var k,\n i = 0,\n len = str.length;\n\n for (; len >= 4; ++i, len -= 4) {\n k = str.charCodeAt(i) & 0xff | (str.charCodeAt(++i) & 0xff) << 8 | (str.charCodeAt(++i) & 0xff) << 16 | (str.charCodeAt(++i) & 0xff) << 24;\n k =\n /* Math.imul(k, m): */\n (k & 0xffff) * 0x5bd1e995 + ((k >>> 16) * 0xe995 << 16);\n k ^=\n /* k >>> r: */\n k >>> 24;\n h =\n /* Math.imul(k, m): */\n (k & 0xffff) * 0x5bd1e995 + ((k >>> 16) * 0xe995 << 16) ^\n /* Math.imul(h, m): */\n (h & 0xffff) * 0x5bd1e995 + ((h >>> 16) * 0xe995 << 16);\n } // Handle the last few bytes of the input array\n\n\n switch (len) {\n case 3:\n h ^= (str.charCodeAt(i + 2) & 0xff) << 16;\n\n case 2:\n h ^= (str.charCodeAt(i + 1) & 0xff) << 8;\n\n case 1:\n h ^= str.charCodeAt(i) & 0xff;\n h =\n /* Math.imul(h, m): */\n (h & 0xffff) * 0x5bd1e995 + ((h >>> 16) * 0xe995 << 16);\n } // Do a few final mixes of the hash to ensure the last few\n // bytes are well-incorporated.\n\n\n h ^= h >>> 13;\n h =\n /* Math.imul(h, m): */\n (h & 0xffff) * 0x5bd1e995 + ((h >>> 16) * 0xe995 << 16);\n return ((h ^ h >>> 15) >>> 0).toString(36);\n}\n\nexport default murmur2;\n","var t=/^(br|hy|us|wr|text-si|scroll-snap-t)/,e=/^(ap|us|tab-|border-e|margin-e|margin-s|padding-e|padding-s|border-sta)/,r=/^(ap|br|hy|us|wr|mas|colu|clip-|box-de|font-k|text-e|font-fe|shape-i|text-or|text-si|border-e|margin-e|margin-s|padding-e|padding-s|border-sta|background-cl|scroll-snap-t|text-decoration-)/,s=/^(pos|background-cl)/,a={},n=function(s){return a[s]?a[s]:a[s]=1*t.test(s)|2*e.test(s)|4*r.test(s)},o=function(t,e){return s.test(t)?e.replace(/(sticky|text)/,\"-webkit-$1, $1\"):e};export{n as prefixProperty,o as prefixValue};\n","export const isBrowser = typeof window !== \"undefined\";\nexport const isDev = process.env.NODE_ENV !== \"production\";\n","export const STYLE_ELEMENT_ID = \"__otion\";\n\nexport function getStyleElement(): HTMLStyleElement {\n\t// Hydrate existing style element if available\n\tlet el = document.getElementById(STYLE_ELEMENT_ID) as HTMLStyleElement | null;\n\tif (el) return el;\n\n\t// Create a new one otherwise\n\tel = document.createElement(\"style\");\n\tel.id = STYLE_ELEMENT_ID;\n\n\treturn document.head.appendChild(el);\n}\n","import { getStyleElement } from \"./getStyleElement\";\n\nexport interface InjectorConfig<T> {\n\t/** Sets a cryptographic nonce (number used once) on the enclosing `<style>` tag when generating a page on demand. Useful for enforcing a [Content Security Policy (CSP)](https://developer.mozilla.org/docs/Web/HTTP/CSP). */\n\tnonce?: string;\n\n\t/** Target to insert rules into. */\n\ttarget?: T;\n}\n\nexport type InjectorInstance = {\n\tsheet?: CSSStyleSheet;\n\tinsert(rule: string, index: number): number;\n};\n\ntype VirtualInjectorInstance = InjectorInstance & {\n\tnonce: string | undefined;\n\truleTexts: string[];\n};\n\n/**\n * Creates an injector which collects style rules during server-side rendering.\n */\nexport function VirtualInjector({\n\tnonce,\n\ttarget: ruleTexts = [],\n}: InjectorConfig<string[]> = {}): VirtualInjectorInstance {\n\treturn {\n\t\tnonce,\n\t\truleTexts,\n\n\t\tinsert(rule, index): number {\n\t\t\truleTexts.splice(index, 0, rule);\n\t\t\treturn index;\n\t\t},\n\t};\n}\n\n/**\n * Creates an injector which inserts style rules through the CSS Object Model.\n */\nexport function CSSOMInjector({\n\tnonce,\n\ttarget = getStyleElement().sheet as CSSStyleSheet,\n}: InjectorConfig<CSSStyleSheet>): InjectorInstance {\n\t// eslint-disable-next-line no-param-reassign\n\t(target.ownerNode as HTMLStyleElement).nonce = nonce;\n\n\treturn {\n\t\tsheet: target,\n\n\t\tinsert(rule, index): number {\n\t\t\t// Avoid render failure during production if a rule cannot be parsed\n\t\t\ttry {\n\t\t\t\treturn target.insertRule(rule, index);\n\t\t\t} catch {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t},\n\t};\n}\n\n/**\n * Creates an injector which inserts style rules through the Document Object Model.\n */\nexport function DOMInjector({\n\tnonce,\n\ttarget = getStyleElement(),\n}: InjectorConfig<HTMLStyleElement>): InjectorInstance {\n\t// eslint-disable-next-line no-param-reassign\n\ttarget.nonce = nonce;\n\n\treturn {\n\t\tsheet: target.sheet as CSSStyleSheet,\n\n\t\tinsert(rule, index): number {\n\t\t\ttarget.insertBefore(\n\t\t\t\tdocument.createTextNode(rule),\n\t\t\t\ttarget.childNodes[index],\n\t\t\t);\n\t\t\treturn index;\n\t\t},\n\t};\n}\n\n/**\n * An injector placeholder which performs no operations. Useful for avoiding errors in a non-browser environment.\n */\nexport const NoOpInjector: InjectorInstance = {\n\tinsert(): number {\n\t\treturn 0;\n\t},\n};\n","export function minifyValue(value: string): string {\n\t// Remove excess white space characters\n\treturn value.trim().replace(/\\s+/g, \" \");\n}\n\nexport function minifyCondition(condition: string): string {\n\treturn minifyValue(condition).replace(/([([]) | ([)\\]])| ?(:) ?/g, \"$1$2$3\");\n}\n","/*\n\tThe order of rules is influenced by CSS usage metrics:\n\n\t- https://www.cssstats.com/stats/?url=css-tricks.com\n\t- https://www.cssstats.com/stats/?url=joshwcomeau.com\n\t- https://www.cssstats.com/stats/?url=mastery.games\n\t- https://www.cssstats.com/stats/?url=nytimes.com\n\t- https://www.chromestatus.com/metrics/css/popularity\n*/\n\n// Includes support for CSS custom properties\nexport const PROPERTY_ACCEPTS_UNITLESS_VALUES = /^(-|f[lo].*?[^se]$|g.{6,}[^ps]$|z|o[pr]|(-w.{6})?li.*?(t|mp)$|an|(bo|s).{5}im|sca|m.{7}[ds]|ta|c.*?[st]$|wido|ini)/;\n\n// TODO: Add tests to match everything below, without false positives\nexport const propertiesAcceptingUnitlessValues = [\n\t/* ^f[lo].*?[^se]$ */\n\t\"flex\",\n\t\"flex-grow\",\n\t\"flex-shrink\",\n\t\"font-size-adjust\",\n\t\"font-weight\",\n\n\t/* ^g.{6,}[^ps]$ */\n\t\"grid-area\",\n\t\"grid-column\",\n\t\"grid-column-end\",\n\t\"grid-column-start\",\n\t\"grid-row\",\n\t\"grid-row-end\",\n\t\"grid-row-start\",\n\n\t/* ^z */\n\t\"z-index\",\n\n\t/* ^o[pr] */\n\t\"opacity\",\n\t\"order\",\n\t\"orphans\",\n\n\t/* ^(-w.{6})?li.*?(t|mp)$ */\n\t\"line-height\",\n\t\"line-clamp\",\n\t\"-webkit-line-clamp\",\n\n\t/* ^an */\n\t\"animation\",\n\t\"animation-iteration-count\",\n\n\t/* ^(bo|s).{5}im */\n\t\"border-image\",\n\t\"border-image-outset\",\n\t\"border-image-slice\",\n\t\"border-image-width\",\n\t\"shape-image-threshold\",\n\n\t/* ^sca */\n\t\"scale\",\n\n\t/* ^m.{7}[ds] */\n\t\"mask-border\",\n\t\"mask-border-outset\",\n\t\"mask-border-slice\",\n\t\"mask-border-width\",\n\t\"max-lines\",\n\n\t/* ^ta */\n\t\"tab-size\",\n\n\t/* ^c.*?[st]$ */\n\t\"columns\",\n\t\"column-count\",\n\n\t/* ^wido */\n\t\"widows\",\n\n\t/* ^ini */\n\t\"initial-letter\",\n];\n\nexport const PROPERTY_PRECEDENCE_CORRECTION_GROUPS = /^(?:(border-(?!w|c|sty)|[tlbr].{2,4}m?$|c.{7}$)|([fl].{5}l|g.{8}$|pl))/;\n\n// TODO: Add tests to match everything below, with no conflicting longhands\nexport const propertiesByPrecedenceCorrectionGroup = {\n\t\"+1\": [\n\t\t/* ^border-(?!w|c|sty) */\n\t\t\"border-!(width,color,style)\",\n\n\t\t/* ^[tlbr].{2,4}m?$ */\n\t\t\"top\",\n\t\t\"left\",\n\t\t\"bottom\",\n\t\t\"right\",\n\n\t\t/* ^c.{7}$ */\n\t\t\"continue\",\n\t],\n\n\t\"-1\": [\n\t\t/* ^[fl].{5}l */\n\t\t\"flex-flow\",\n\t\t\"line-clamp\",\n\n\t\t/* ^g.{8}$ */\n\t\t\"grid-area\",\n\n\t\t/* ^pl */\n\t\t\"place-content\",\n\t\t\"place-items\",\n\t\t\"place-self\",\n\t],\n};\n","/*\n\tSources:\n\n\t- https://bitsofco.de/when-do-the-hover-focus-and-active-pseudo-classes-apply/#orderofstyleshoverthenfocusthenactive\n\t- https://developer.mozilla.org/docs/Web/CSS/:active#Active_links\n*/\n\nexport const PRECEDENCES_BY_PSEUDO_CLASS = new Map([\n\t[/* li */ \"nk\", 1],\n\t[/* vi */ \"sited\", 2],\n\t[/* em */ \"pty\", 3],\n\t[/* fo */ \"cus-w\" /* ithin */, 4],\n\t[/* ho */ \"ver\", 5],\n\t[/* fo */ \"cus\", 6],\n\t[/* fo */ \"cus-v\" /* isible */, 7],\n\t[/* ac */ \"tive\", 8],\n\t[/* di */ \"sable\" /* d */, 9],\n]);\n\nexport const PSEUDO_CLASS_PRECEDENCE_GROUP_COUNT = 9;\n","import { PROPERTY_PRECEDENCE_CORRECTION_GROUPS } from \"./propertyMatchers\";\nimport {\n\tPRECEDENCES_BY_PSEUDO_CLASS,\n\tPSEUDO_CLASS_PRECEDENCE_GROUP_COUNT,\n} from \"./pseudos\";\n\nexport function rulePrecedence(\n\tproperty: string,\n\tpseudoClass: string,\n\tisConditionalRule: boolean,\n): number {\n\tlet precedence = 0;\n\n\tconst isCustomProperty = property[1] === \"-\";\n\tif (!isCustomProperty) {\n\t\t// The property's baseline precedence is based on \"-\" counting\n\t\tconst unprefixedProperty =\n\t\t\tproperty[0] === \"-\"\n\t\t\t\t? property.slice(property.indexOf(\"-\", 1)) + 1\n\t\t\t\t: property;\n\t\tconst matches = PROPERTY_PRECEDENCE_CORRECTION_GROUPS.exec(\n\t\t\tunprefixedProperty,\n\t\t);\n\t\tprecedence =\n\t\t\t(matches ? +!!matches[1] /* +1 */ || -!!matches[2] /* -1 */ : 0) + 1;\n\t\tlet position = 1; // First character of the property can't be `-`\n\t\twhile (\n\t\t\t// eslint-disable-next-line no-cond-assign\n\t\t\t(position = unprefixedProperty.indexOf(\"-\", position) + 1) /* > 0 */\n\t\t) {\n\t\t\t++precedence;\n\t\t}\n\t}\n\n\t// Pseudo-classes also have an impact on rule precedence\n\tconst conditionalPrecedenceGroupExistenceMultiplier = 2;\n\tprecedence *=\n\t\tconditionalPrecedenceGroupExistenceMultiplier *\n\t\t((pseudoClass &&\n\t\t\tPRECEDENCES_BY_PSEUDO_CLASS.get(\n\t\t\t\tpseudoClass.slice(3, 8), // Uniquely identifies a pseudo selector\n\t\t\t)) ||\n\t\t\tPSEUDO_CLASS_PRECEDENCE_GROUP_COUNT + 1);\n\n\t// Conditional rules should take precedence over non-conditionals\n\tprecedence += +isConditionalRule;\n\n\treturn precedence;\n}\n","import hash from \"@emotion/hash\";\nimport { prefixProperty, prefixValue } from \"tiny-css-prefixer\";\n\nimport { CSSKeyframeRules, ScopedCSSRules } from \"./cssTypes\";\nimport { isBrowser, isDev } from \"./env\";\nimport {\n\tCSSOMInjector,\n\tDOMInjector,\n\tInjectorInstance,\n\tNoOpInjector,\n} from \"./injectors\";\nimport { minifyCondition, minifyValue } from \"./minify\";\nimport { PROPERTY_ACCEPTS_UNITLESS_VALUES } from \"./propertyMatchers\";\nimport { rulePrecedence } from \"./rulePrecedence\";\n\nexport const PRECEDENCE_GROUP_COUNT = 72;\n\nfunction toHyphenLower(match: string): string {\n\treturn `-${match.toLowerCase()}`;\n}\n\nexport interface OtionConfig {\n\t/** Style insertion methodology to be used. */\n\tinjector?: InjectorInstance;\n\n\t/** Auto-prefixer method for CSS property–value pairs. */\n\tprefix?: (property: string, value: string) => string;\n}\n\nexport interface OtionInstance {\n\t/**\n\t * Customizes the otion instance. May only be called once, before using the instance for anything else.\n\t */\n\tsetup(options: OtionConfig): void;\n\n\t/**\n\t * Marks server-rendered CSS identity names as available to avoid re-injecting them to the style sheet during runtime.\n\t */\n\thydrate(): void;\n\n\t/**\n\t * Decomposes CSS into atomic styles. Rules are injected to the style sheet if not already available.\n\t *\n\t * @param rules Scoped CSS as [object styles](https://gist.github.com/threepointone/9f87907a91ec6cbcd376dded7811eb31), with value fallbacks represented as arrays.\n\t *\n\t * - Numbers assigned to non-unitless properties are postfixed with \"px\".\n\t * - Excess white space characters are truncated.\n\t *\n\t * @returns A space-separated list of stably generated unique class names.\n\t *\n\t * @example\n\t * const classNames = css({\n\t * display: \"flex\",\n\t * justifyContent: [\"space-around\", \"space-evenly\"], // Last takes precedence\n\t * padding: 8, // \"8px\"\n\t * lineHeight: 1.5, // \"1.5\" without a unit\n\t * selectors: {\n\t * // Advanced selectors must start with \"&\"\n\t * \"& > * + *\": {\n\t * paddingLeft: 16\n\t * }\n\t * }\n\t * });\n\t */\n\tcss(rules: ScopedCSSRules): string;\n\n\t// used to specify the values for the animating properties at various points during the animation\n\t/**\n\t * Creates keyframes for animating values of given properties over time.\n\t *\n\t * @param rules CSS keyframe rules as [object styles](https://gist.github.com/threepointone/9f87907a91ec6cbcd376dded7811eb31), with value fallbacks represented as arrays.\n\t *\n\t * - Numbers assigned to non-unitless properties are postfixed with \"px\".\n\t * - Excess white space characters are truncated.\n\t *\n\t * @returns Lazy method for stably generating a unique animation name upon usage.\n\t *\n\t * @example\n\t * const pulse = keyframes({\n\t * from: { opacity: 0 },\n\t * to: { opacity: 1 }\n\t * });\n\t *\n\t * // Referencing\n\t * const className = css({\n\t * animation: `${pulse} 3s infinite alternate`\n\t * });\n\t */\n\tkeyframes(rules: CSSKeyframeRules): { /** @private */ toString(): string };\n}\n\n/**\n * Creates a new otion instance. Usable for managing styles of multiple browsing contexts (e.g. an `<iframe>` besides the main document).\n */\nexport function createInstance(): OtionInstance {\n\tlet injector: InjectorInstance;\n\tlet prefix: (property: string, value: string) => string;\n\tlet ruleIndexesByIdentName: Map<string, number>;\n\tlet nextRuleIndexesByPrecedenceGroup: Uint16Array;\n\n\tfunction checkSetup(): void {\n\t\tif (!injector || !prefix || !ruleIndexesByIdentName) {\n\t\t\tthrow new Error(\n\t\t\t\t\"On a custom otion instance, `setup()` must be called before usage.\",\n\t\t\t);\n\t\t}\n\t}\n\n\tfunction updatePrecedenceGroupRanges(fromPrecedence: number) {\n\t\tfor (let i = fromPrecedence; i <= PRECEDENCE_GROUP_COUNT; ++i) {\n\t\t\t++nextRuleIndexesByPrecedenceGroup[i];\n\t\t}\n\t}\n\n\tfunction hydrateScopedSubtree(\n\t\tcssRule: CSSRule,\n\t\tisConditionalRule?: boolean,\n\t): void {\n\t\tif (cssRule.type === 1 /* CSSRule.STYLE_RULE */) {\n\t\t\tconst { selectorText, style } = cssRule as CSSStyleRule;\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tconst [, identName, pseudoClass] = /^..([0-9a-z]+)(:.*)?/.exec(\n\t\t\t\tselectorText,\n\t\t\t)!;\n\t\t\tconst property = style[0];\n\t\t\tif (property) {\n\t\t\t\t// Broken rule declarations are ignored\n\t\t\t\tupdatePrecedenceGroupRanges(\n\t\t\t\t\trulePrecedence(property, pseudoClass, !!isConditionalRule),\n\t\t\t\t);\n\t\t\t}\n\t\t\truleIndexesByIdentName.set(identName, ruleIndexesByIdentName.size);\n\t\t} else {\n\t\t\t/* cssRule.type === CSSRule.MEDIA_RULE */\n\t\t\thydrateScopedSubtree((cssRule as CSSGroupingRule).cssRules[0], true);\n\t\t}\n\t}\n\n\tfunction normalizeDeclaration(\n\t\tproperty: string,\n\t\tvalue: string | number,\n\t): string {\n\t\tconst formattedValue =\n\t\t\ttypeof value === \"number\" &&\n\t\t\t!PROPERTY_ACCEPTS_UNITLESS_VALUES.test(property)\n\t\t\t\t? `${value}px` // Append missing unit\n\t\t\t\t: minifyValue(`${value}`);\n\t\treturn prefix(property, formattedValue);\n\t}\n\n\tfunction serializeDeclarationList(\n\t\tproperty: string,\n\t\tvalue: string | number | Array<string | number | undefined>,\n\t): string {\n\t\tif (typeof value !== \"object\") {\n\t\t\treturn normalizeDeclaration(property, value);\n\t\t}\n\n\t\tlet cssText = \"\";\n\t\tvalue.forEach((fallbackValue) => {\n\t\t\tif (fallbackValue) {\n\t\t\t\tcssText += `;${normalizeDeclaration(property, fallbackValue)}`;\n\t\t\t}\n\t\t});\n\n\t\t// The leading declaration separator character gets removed\n\t\treturn cssText.slice(1);\n\t}\n\n\tfunction decomposeToClassNames(\n\t\trules: ScopedCSSRules,\n\t\tcssTextHead: string,\n\t\tcssTextTail: string,\n\t\tmaxPrecedingConditionalRuleIndexesByPrecedenceGroup: Uint16Array,\n\t\tclassSelectorStartIndex?: number,\n\t): string {\n\t\tlet classNames = \"\";\n\n\t\t// TODO: Replace `var` with `const` once it minifies equivalently\n\t\t// eslint-disable-next-line guard-for-in, no-restricted-syntax, no-var, vars-on-top\n\t\tfor (var key in rules) {\n\t\t\tconst value = rules[key as keyof typeof rules];\n\n\t\t\tif (value != null) {\n\t\t\t\tif (typeof value !== \"object\" || Array.isArray(value)) {\n\t\t\t\t\t// Class specificities are controlled with repetition, see:\n\t\t\t\t\t// https://csswizardry.com/2014/07/hacks-for-dealing-with-specificity/\n\n\t\t\t\t\t// TODO: Consider removing IE vendor prefix support\n\t\t\t\t\tconst property = key.replace(/^ms|[A-Z]/g, toHyphenLower);\n\t\t\t\t\tconst declarations = serializeDeclarationList(property, value);\n\t\t\t\t\tconst className = `_${hash(cssTextHead + declarations)}`;\n\t\t\t\t\tconst isConditionalRule = cssTextTail;\n\n\t\t\t\t\tlet ruleIndex = ruleIndexesByIdentName.get(className);\n\n\t\t\t\t\tif (ruleIndex == null || isConditionalRule) {\n\t\t\t\t\t\tconst precedence = rulePrecedence(\n\t\t\t\t\t\t\tproperty,\n\t\t\t\t\t\t\tclassSelectorStartIndex == null\n\t\t\t\t\t\t\t\t? \"\"\n\t\t\t\t\t\t\t\t: cssTextHead.slice(classSelectorStartIndex),\n\t\t\t\t\t\t\t!!isConditionalRule,\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\truleIndex == null ||\n\t\t\t\t\t\t\t// Re-insert conditional rule if necessary to fix CSS source order\n\t\t\t\t\t\t\tmaxPrecedingConditionalRuleIndexesByPrecedenceGroup[precedence] >\n\t\t\t\t\t\t\t\truleIndex\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tconst scopeSelector = `.${className}`;\n\t\t\t\t\t\t\tinjector.insert(\n\t\t\t\t\t\t\t\t`${\n\t\t\t\t\t\t\t\t\tcssTextHead.slice(0, classSelectorStartIndex) +\n\t\t\t\t\t\t\t\t\tscopeSelector +\n\t\t\t\t\t\t\t\t\t(classSelectorStartIndex != null\n\t\t\t\t\t\t\t\t\t\t? `${\n\t\t\t\t\t\t\t\t\t\t\t\tcssTextHead\n\t\t\t\t\t\t\t\t\t\t\t\t\t.slice(classSelectorStartIndex)\n\t\t\t\t\t\t\t\t\t\t\t\t\t.replace(/&/g, scopeSelector) // Resolve references\n\t\t\t\t\t\t\t\t\t\t }{`\n\t\t\t\t\t\t\t\t\t\t: \"{\")\n\t\t\t\t\t\t\t\t}${declarations}}${cssTextTail}`,\n\t\t\t\t\t\t\t\tnextRuleIndexesByPrecedenceGroup[precedence],\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tupdatePrecedenceGroupRanges(precedence);\n\n\t\t\t\t\t\t\truleIndex = ruleIndexesByIdentName.size;\n\t\t\t\t\t\t\truleIndexesByIdentName.set(className, ruleIndex);\n\n\t\t\t\t\t\t\tif (isConditionalRule) {\n\t\t\t\t\t\t\t\t// eslint-disable-next-line no-param-reassign\n\t\t\t\t\t\t\t\tmaxPrecedingConditionalRuleIndexesByPrecedenceGroup[\n\t\t\t\t\t\t\t\t\tprecedence\n\t\t\t\t\t\t\t\t] = Math.max(\n\t\t\t\t\t\t\t\t\tmaxPrecedingConditionalRuleIndexesByPrecedenceGroup[\n\t\t\t\t\t\t\t\t\t\tprecedence\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\truleIndex,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tclassNames += ` ${className}`;\n\t\t\t\t} else {\n\t\t\t\t\tlet parentRuleHeads: string[] | undefined;\n\t\t\t\t\tlet firstParentRuleHead =\n\t\t\t\t\t\tkey[0] === \":\" || key[0] === \"@\" || key[0] === \"&\"\n\t\t\t\t\t\t\t? key\n\t\t\t\t\t\t\t: minifyCondition(key);\n\t\t\t\t\tlet parentRuleTail = \"\";\n\t\t\t\t\tlet scopeClassSelectorStartIndex = classSelectorStartIndex;\n\n\t\t\t\t\tif (scopeClassSelectorStartIndex == null) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tfirstParentRuleHead[0] === \":\" ||\n\t\t\t\t\t\t\tfirstParentRuleHead[0] === \"&\"\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tscopeClassSelectorStartIndex = cssTextHead.length;\n\t\t\t\t\t\t\tparentRuleHeads = firstParentRuleHead\n\t\t\t\t\t\t\t\t.split(\n\t\t\t\t\t\t\t\t\t// Separate selector list items by \",\"\n\t\t\t\t\t\t\t\t\t// Inspired by: https://stackoverflow.com/a/9030062\n\t\t\t\t\t\t\t\t\t/,(?![^[]*?[^\\\\][\"']\\s*?\\])/,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t.map(\n\t\t\t\t\t\t\t\t\t(singleSelector) =>\n\t\t\t\t\t\t\t\t\t\t// Keep non-first occurrences of \"&\" for later replacement\n\t\t\t\t\t\t\t\t\t\tminifyValue(singleSelector).replace(\"&\", \"\"), // lgtm [js/incomplete-sanitization]\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} else if (firstParentRuleHead === \"selectors\") {\n\t\t\t\t\t\t\tfirstParentRuleHead = \"\";\n\t\t\t\t\t\t} else if (firstParentRuleHead[0] !== \"@\") {\n\t\t\t\t\t\t\tfirstParentRuleHead += \"{\";\n\t\t\t\t\t\t\tparentRuleTail = \"}\";\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t(parentRuleHeads || [firstParentRuleHead]).forEach(\n\t\t\t\t\t\t// eslint-disable-next-line no-loop-func\n\t\t\t\t\t\t(parentRuleHead) => {\n\t\t\t\t\t\t\tclassNames += decomposeToClassNames(\n\t\t\t\t\t\t\t\tvalue as ScopedCSSRules,\n\t\t\t\t\t\t\t\tcssTextHead + parentRuleHead,\n\t\t\t\t\t\t\t\tparentRuleTail + cssTextTail,\n\t\t\t\t\t\t\t\tmaxPrecedingConditionalRuleIndexesByPrecedenceGroup,\n\t\t\t\t\t\t\t\tscopeClassSelectorStartIndex,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn classNames;\n\t}\n\n\treturn {\n\t\tsetup(options): void {\n\t\t\tinjector =\n\t\t\t\toptions.injector ||\n\t\t\t\t// eslint-disable-next-line no-nested-ternary\n\t\t\t\t(isBrowser\n\t\t\t\t\t? isDev\n\t\t\t\t\t\t? DOMInjector({})\n\t\t\t\t\t\t: CSSOMInjector({})\n\t\t\t\t\t: NoOpInjector);\n\n\t\t\tprefix =\n\t\t\t\toptions.prefix ||\n\t\t\t\t((property: string, value: string): string => {\n\t\t\t\t\tconst declaration = `${property}:${prefixValue(property, value)}`;\n\t\t\t\t\tlet cssText = declaration;\n\t\t\t\t\tconst flag = prefixProperty(property);\n\t\t\t\t\tif (flag & 0b001) cssText += `;-ms-${declaration}`;\n\t\t\t\t\tif (flag & 0b010) cssText += `;-moz-${declaration}`;\n\t\t\t\t\tif (flag & 0b100) cssText += `;-webkit-${declaration}`;\n\t\t\t\t\treturn cssText;\n\t\t\t\t});\n\n\t\t\truleIndexesByIdentName = new Map();\n\t\t\tnextRuleIndexesByPrecedenceGroup = new Uint16Array(\n\t\t\t\tPRECEDENCE_GROUP_COUNT,\n\t\t\t);\n\t\t},\n\n\t\thydrate(): void {\n\t\t\tif (isDev) checkSetup();\n\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tconst { cssRules } = injector.sheet!;\n\t\t\tfor (let i = 0, { length } = cssRules; i < length; ++i) {\n\t\t\t\tconst cssRule = cssRules[i];\n\t\t\t\tif (cssRule.type === 7 /* CSSRule.KEYFRAMES_RULE */) {\n\t\t\t\t\t// Keyframes needn't be checked recursively, as they are never nested\n\t\t\t\t\truleIndexesByIdentName.set(\n\t\t\t\t\t\t(cssRule as CSSKeyframesRule).name,\n\t\t\t\t\t\truleIndexesByIdentName.size,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\thydrateScopedSubtree(cssRule);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\n\t\tcss(rules): string {\n\t\t\tif (isDev) checkSetup();\n\n\t\t\t// The leading white space character gets removed\n\t\t\treturn decomposeToClassNames(\n\t\t\t\trules,\n\t\t\t\t\"\",\n\t\t\t\t\"\",\n\t\t\t\tnew Uint16Array(PRECEDENCE_GROUP_COUNT),\n\t\t\t).slice(1);\n\t\t},\n\n\t\tkeyframes(rules): { toString(): string } {\n\t\t\tif (isDev) checkSetup();\n\n\t\t\tlet identName: string | undefined;\n\n\t\t\treturn {\n\t\t\t\ttoString(): string {\n\t\t\t\t\tif (!identName) {\n\t\t\t\t\t\tlet cssText = \"\";\n\n\t\t\t\t\t\t// TODO: Replace var with const once it minifies equivalently\n\t\t\t\t\t\t// eslint-disable-next-line guard-for-in, no-restricted-syntax, no-var, vars-on-top\n\t\t\t\t\t\tfor (var time in rules) {\n\t\t\t\t\t\t\tcssText += `${time}{`;\n\n\t\t\t\t\t\t\tconst declarations = rules[time as keyof typeof rules];\n\n\t\t\t\t\t\t\t// TODO: Replace var with const once it minifies equivalently\n\t\t\t\t\t\t\t// eslint-disable-next-line guard-for-in, no-restricted-syntax, no-var, vars-on-top\n\t\t\t\t\t\t\tfor (var property in declarations) {\n\t\t\t\t\t\t\t\tconst value =\n\t\t\t\t\t\t\t\t\tdeclarations[property as keyof typeof declarations];\n\n\t\t\t\t\t\t\t\tif (value != null) {\n\t\t\t\t\t\t\t\t\tcssText += serializeDeclarationList(property, value);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tcssText += \"}\";\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tidentName = `_${hash(cssText)}`;\n\t\t\t\t\t\tif (!ruleIndexesByIdentName.has(identName)) {\n\t\t\t\t\t\t\tinjector.insert(\n\t\t\t\t\t\t\t\t`@keyframes ${identName}{${cssText}}`,\n\t\t\t\t\t\t\t\truleIndexesByIdentName.size,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\truleIndexesByIdentName.set(\n\t\t\t\t\t\t\t\tidentName,\n\t\t\t\t\t\t\t\truleIndexesByIdentName.size,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\treturn identName!;\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t};\n}\n","import { createInstance, OtionInstance } from \"./createInstance\";\n\nexport { createInstance };\n\nconst defaultInstance = createInstance();\ndefaultInstance.setup({});\n\n// Make sure to keep documentation comments for aliases\n/* eslint-disable prefer-destructuring */\nexport const setup: OtionInstance[\"setup\"] = defaultInstance.setup;\nexport const hydrate: OtionInstance[\"hydrate\"] = defaultInstance.hydrate;\nexport const css: OtionInstance[\"css\"] = defaultInstance.css;\nexport const keyframes: OtionInstance[\"keyframes\"] = defaultInstance.keyframes;\n/* eslint-enable prefer-destructuring */\n\nexport { CSSOMInjector, DOMInjector, NoOpInjector } from \"./injectors\";\n\nexport type { ScopedCSSRules } from \"./cssTypes\";\n"],"names":["murmur2","str","k","h","i","len","length","charCodeAt","toString","t","e","r","s","a","isBrowser","window","isDev","process","env","NODE_ENV","getStyleElement","el","document","getElementById","createElement","id","head","appendChild","CSSOMInjector","nonce","target","sheet","ownerNode","[object Object]","rule","index","insertRule","DOMInjector","insert","insertBefore","createTextNode","childNodes","NoOpInjector","minifyValue","value","trim","replace","PROPERTY_ACCEPTS_UNITLESS_VALUES","PROPERTY_PRECEDENCE_CORRECTION_GROUPS","PRECEDENCES_BY_PSEUDO_CLASS","Map","rulePrecedence","property","pseudoClass","isConditionalRule","precedence","unprefixedProperty","slice","indexOf","matches","exec","position","get","PSEUDO_CLASS_PRECEDENCE_GROUP_COUNT","toHyphenLower","match","toLowerCase","createInstance","injector","prefix","ruleIndexesByIdentName","nextRuleIndexesByPrecedenceGroup","checkSetup","Error","updatePrecedenceGroupRanges","fromPrecedence","hydrateScopedSubtree","cssRule","type","selectorText","style","identName","set","size","cssRules","normalizeDeclaration","formattedValue","test","serializeDeclarationList","cssText","forEach","fallbackValue","decomposeToClassNames","rules","cssTextHead","cssTextTail","maxPrecedingConditionalRuleIndexesByPrecedenceGroup","classSelectorStartIndex","classNames","key","Array","isArray","declarations","className","hash","ruleIndex","scopeSelector","Math","max","parentRuleHeads","firstParentRuleHead","parentRuleTail","scopeClassSelectorStartIndex","split","map","singleSelector","parentRuleHead","options","declaration","prefixVal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