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3D,IAAI,YAAY,EAAE;QAChB,iBAAiB,CAAC,YAAY,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAC;QAE/D,OAAO,YAAY,CAAC,SAAS,CAAC;KAC/B;IAED,OAAO,EAAE,CAAC;AACZ,CAAC","sourcesContent":["import { IStyle } from './IStyle';\nimport { IRawStyle } from './IRawStyle';\n\nimport { Stylesheet } from './Stylesheet';\nimport { kebabRules } from './transforms/kebabRules';\nimport { prefixRules } from './transforms/prefixRules';\nimport { provideUnits } from './transforms/provideUnits';\nimport { rtlifyRules } from './transforms/rtlifyRules';\nimport { IStyleOptions } from './IStyleOptions';\n\nconst DISPLAY_NAME = 'displayName';\n\ntype IDictionary = { [key: string]: any };\n\ninterface IRuleSet {\n __order: string[];\n [key: string]: IDictionary;\n}\n\nfunction getDisplayName(rules?: { [key: string]: IRawStyle }): string | undefined {\n const rootStyle: IStyle = rules && rules['&'];\n\n return rootStyle ? (rootStyle as IRawStyle).displayName : undefined;\n}\n\nconst globalSelectorRegExp = /\\:global\\((.+?)\\)/g;\n\ntype ReplacementInfo = [number, number, string];\n\n/**\n * Finds comma separated selectors in a :global() e.g. \":global(.class1, .class2, .class3)\"\n * and wraps them each in their own global \":global(.class1), :global(.class2), :global(.class3)\"\n *\n * @param selectorWithGlobals The selector to process\n * @returns The updated selector\n */\nfunction expandCommaSeparatedGlobals(selectorWithGlobals: string): string {\n // We the selector does not have a :global() we can shortcut\n if (!globalSelectorRegExp.test(selectorWithGlobals)) {\n return selectorWithGlobals;\n }\n\n const replacementInfo: ReplacementInfo[] = [];\n\n const findGlobal = /\\:global\\((.+?)\\)/g;\n let match = null;\n // Create a result list for global selectors so we can replace them.\n while ((match = findGlobal.exec(selectorWithGlobals))) {\n // Only if the found selector is a comma separated list we'll process it.\n if (match[1].indexOf(',') > -1) {\n replacementInfo.push([\n match.index,\n match.index + match[0].length,\n // Wrap each of the found selectors in :global()\n match[1]\n .split(',')\n .map((v: string) => `:global(${v.trim()})`)\n .join(', '),\n ]);\n }\n }\n\n // Replace the found selectors with their wrapped variants in reverse order\n return replacementInfo\n .reverse()\n .reduce((selector: string, [matchIndex, matchEndIndex, replacement]: ReplacementInfo) => {\n const prefix = selector.slice(0, matchIndex);\n const suffix = selector.slice(matchEndIndex);\n\n return prefix + replacement + suffix;\n }, selectorWithGlobals);\n}\n\nfunction expandSelector(newSelector: string, currentSelector: string): string {\n if (newSelector.indexOf(':global(') >= 0) {\n return newSelector.replace(globalSelectorRegExp, '$1');\n } else if (newSelector.indexOf(':') === 0) {\n return currentSelector + newSelector;\n } else if (newSelector.indexOf('&') < 0) {\n return currentSelector + ' ' + newSelector;\n }\n\n return newSelector;\n}\n\nfunction extractSelector(currentSelector: string, rules: IRuleSet = { __order: [] }, selector: string, value: IStyle) {\n if (selector.indexOf('@') === 0) {\n selector = selector + '{' + currentSelector;\n extractRules([value], rules, selector);\n } else if (selector.indexOf(',') > -1) {\n expandCommaSeparatedGlobals(selector)\n .split(',')\n .map((s: string) => s.trim())\n .forEach((separatedSelector: string) =>\n extractRules([value], rules, expandSelector(separatedSelector, currentSelector)),\n );\n } else {\n extractRules([value], rules, expandSelector(selector, currentSelector));\n }\n}\n\nfunction extractRules(args: IStyle[], rules: IRuleSet = { __order: [] }, currentSelector: string = '&'): IRuleSet {\n const stylesheet = Stylesheet.getInstance();\n let currentRules: IDictionary | undefined = rules[currentSelector] as IDictionary;\n\n if (!currentRules) {\n currentRules = {};\n rules[currentSelector] = currentRules;\n rules.__order.push(currentSelector);\n }\n\n for (const arg of args) {\n // If the arg is a string, we need to look up the class map and merge.\n if (typeof arg === 'string') {\n const expandedRules = stylesheet.argsFromClassName(arg);\n\n if (expandedRules) {\n extractRules(expandedRules, rules, currentSelector);\n }\n // Else if the arg is an array, we need to recurse in.\n } else if (Array.isArray(arg)) {\n extractRules(arg, rules, currentSelector);\n } else {\n for (const prop in arg as any) {\n if ((arg as any).hasOwnProperty(prop)) {\n const propValue = (arg as any)[prop];\n\n if (prop === 'selectors') {\n // every child is a selector.\n const selectors: { [key: string]: IStyle } = (arg as any).selectors;\n\n for (const newSelector in selectors) {\n if (selectors.hasOwnProperty(newSelector)) {\n extractSelector(currentSelector, rules, newSelector, selectors[newSelector]);\n }\n }\n } else if (typeof propValue === 'object') {\n // prop is a selector.\n if (propValue !== null) {\n extractSelector(currentSelector, rules, prop, propValue);\n }\n } else {\n if (propValue !== undefined) {\n // Else, add the rule to the currentSelector.\n if (prop === 'margin' || prop === 'padding') {\n expandQuads(currentRules, prop, propValue);\n } else {\n (currentRules as any)[prop] = propValue;\n }\n }\n }\n }\n }\n }\n }\n\n return rules;\n}\n\nfunction expandQuads(currentRules: IDictionary, name: string, value: string): void {\n const parts = typeof value === 'string' ? value.split(' ') : [value];\n\n currentRules[name + 'Top'] = parts[0];\n currentRules[name + 'Right'] = parts[1] || parts[0];\n currentRules[name + 'Bottom'] = parts[2] || parts[0];\n currentRules[name + 'Left'] = parts[3] || parts[1] || parts[0];\n}\n\nfunction getKeyForRules(options: IStyleOptions, rules: IRuleSet): string | undefined {\n const serialized: string[] = [options.rtl ? 'rtl' : 'ltr'];\n let hasProps = false;\n\n for (const selector of rules.__order) {\n serialized.push(selector);\n const rulesForSelector = rules[selector];\n\n for (const propName in rulesForSelector) {\n if (rulesForSelector.hasOwnProperty(propName) && rulesForSelector[propName] !== undefined) {\n hasProps = true;\n serialized.push(propName, rulesForSelector[propName]);\n }\n }\n }\n\n return hasProps ? serialized.join('') : undefined;\n}\n\nfunction repeatString(target: string, count: number): string {\n if (count <= 0) {\n return '';\n }\n\n if (count === 1) {\n return target;\n }\n\n return target + repeatString(target, count - 1);\n}\n\nexport function serializeRuleEntries(options: IStyleOptions, ruleEntries: { [key: string]: string | number }): string {\n if (!ruleEntries) {\n return '';\n }\n\n const allEntries: (string | number)[] = [];\n\n for (const entry in ruleEntries) {\n if (ruleEntries.hasOwnProperty(entry) && entry !== DISPLAY_NAME && ruleEntries[entry] !== undefined) {\n allEntries.push(entry, ruleEntries[entry]);\n }\n }\n\n // Apply transforms.\n for (let i = 0; i < allEntries.length; i += 2) {\n kebabRules(allEntries, i);\n provideUnits(allEntries, i);\n rtlifyRules(options, allEntries, i);\n prefixRules(allEntries, i);\n }\n\n // Apply punctuation.\n for (let i = 1; i < allEntries.length; i += 4) {\n allEntries.splice(i, 1, ':', allEntries[i], ';');\n }\n\n return allEntries.join('');\n}\n\nexport interface IRegistration {\n className: string;\n key: string;\n args: IStyle[];\n rulesToInsert: string[];\n}\n\nexport function styleToRegistration(options: IStyleOptions, ...args: IStyle[]): IRegistration | undefined {\n const rules: IRuleSet = extractRules(args);\n const key = getKeyForRules(options, rules);\n\n if (key) {\n const stylesheet = Stylesheet.getInstance();\n const registration: Partial<IRegistration> = {\n className: stylesheet.classNameFromKey(key),\n key,\n args,\n };\n\n if (!registration.className) {\n registration.className = stylesheet.getClassName(getDisplayName(rules));\n const rulesToInsert: string[] = [];\n\n for (const selector of rules.__order) {\n rulesToInsert.push(selector, serializeRuleEntries(options, rules[selector]));\n }\n registration.rulesToInsert = rulesToInsert;\n }\n\n return registration as IRegistration;\n }\n\n return undefined;\n}\n\n/**\n * Insert style to stylesheet.\n * @param registration Style registration.\n * @param specificityMultiplier Number of times classname selector is repeated in the css rule.\n * This is to increase css specificity in case it's needed. Default to 1.\n */\nexport function applyRegistration(registration: IRegistration, specificityMultiplier: number = 1): void {\n const stylesheet = Stylesheet.getInstance();\n const { className, key, args, rulesToInsert } = registration;\n\n if (rulesToInsert) {\n // rulesToInsert is an ordered array of selector/rule pairs.\n for (let i = 0; i < rulesToInsert.length; i += 2) {\n const rules = rulesToInsert[i + 1];\n if (rules) {\n let selector = rulesToInsert[i];\n selector = selector.replace(/&/g, repeatString(`.${registration.className}`, specificityMultiplier));\n\n // Insert. Note if a media query, we must close the query with a final bracket.\n const processedRule = `${selector}{${rules}}${selector.indexOf('@') === 0 ? '}' : ''}`;\n stylesheet.insertRule(processedRule);\n }\n }\n stylesheet.cacheClassName(className!, key!, args!, rulesToInsert);\n }\n}\n\nexport function styleToClassName(options: IStyleOptions, ...args: IStyle[]): string {\n const registration = styleToRegistration(options, ...args);\n if (registration) {\n applyRegistration(registration, options.specificityMultiplier);\n\n return registration.className;\n }\n\n return '';\n}\n"]}
\No newline at end of file