mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-28 19:35:15 +00:00
1 line
9.0 KiB
Plaintext
1 line
9.0 KiB
Plaintext
|
{"version":3,"file":"jss-plugin-nested.js","sources":["../../../node_modules/@babel/runtime/helpers/esm/extends.js","../../../node_modules/tiny-warning/dist/tiny-warning.esm.js","../src/index.js"],"sourcesContent":["export default function _extends() {\n _extends = Object.assign || function (target) {\n for (var i = 1; i < arguments.length; i++) {\n var source = arguments[i];\n\n for (var key in source) {\n if (Object.prototype.hasOwnProperty.call(source, key)) {\n target[key] = source[key];\n }\n }\n }\n\n return target;\n };\n\n return _extends.apply(this, arguments);\n}","var isProduction = process.env.NODE_ENV === 'production';\nfunction warning(condition, message) {\n if (!isProduction) {\n if (condition) {\n return;\n }\n\n var text = \"Warning: \" + message;\n\n if (typeof console !== 'undefined') {\n console.warn(text);\n }\n\n try {\n throw Error(text);\n } catch (x) {}\n }\n}\n\nexport default warning;\n","// @flow\nimport warning from 'tiny-warning'\nimport type {Plugin, StyleRule, StyleSheet} from 'jss'\n\nconst separatorRegExp = /\\s*,\\s*/g\nconst parentRegExp = /&/g\nconst refRegExp = /\\$([\\w-]+)/g\n\n/**\n * Convert nested rules to separate, remove them from original styles.\n *\n * @param {Rule} rule\n * @api public\n */\nexport default function jssNested(): Plugin {\n // Get a function to be used for $ref replacement.\n function getReplaceRef(container, sheet?: StyleSheet) {\n return (match, key) => {\n let rule = container.getRule(key) || (sheet && sheet.getRule(key))\n if (rule) {\n rule = ((rule: any): StyleRule)\n\n return rule.selector\n }\n\n warning(\n false,\n `[JSS] Could not find the referenced rule \"${key}\" in \"${container.options.meta ||\n container.toString()}\".`\n )\n return key\n }\n }\n\n function replaceParentRefs(nestedProp, parentProp) {\n const parentSelectors = parentProp.split(separatorRegExp)\n const nestedSelectors = nestedProp.split(separatorRegExp)\n\n let result = ''\n\n for (let i = 0; i < parentSelectors.length; i++) {\n const parent = parentSelectors[i]\n\n for (let j = 0; j < nestedSelectors.length; j++) {\n const nested = nestedSelectors[j]\n if (result) result += ', '\n // Replace all & by the parent or prefix & with the parent.\n result +=\n nested.indexOf('&') !== -1 ? nested.replace(parentRegExp, parent) : `${parent} ${nested}`\n }\n }\n\n return result\n }\n\n function getOptions(rule, container, prevOptions) {\n // Options has been already created, now we only increase index.\n if (prevOptions) return {...prevOptions, index: prevOptions.index + 1}\n\n // $FlowFixMe[prop-missing]\n let {nestingLevel} = rule.options\n nestingLevel = nestingLevel === undefined ? 1 : nestingLevel + 1\n\n const options = {\n ...rule.options,\n nestingLevel,\n index: container.indexOf(rule) + 1\n }\n // We don't need the parent name to be set options for chlid.\n delete options.name\n return options\n }\n\n function onProcessStyle(style, rule, sheet?: StyleSheet) {\n if (rule.type !== 'style') return style\n\n const styleRule: StyleRule = (rule: any)\n\n const container: StyleSheet = (styleRule.options.parent: any)\n let options\n let replaceRef\n for (const prop in style) {\n const isNested = prop.indexOf('&') !== -1\n const isNestedConditional = prop[0] === '@'\n\n if (!isNested && !isNestedConditional) continue\n\n options = getOptions(styleRule, container, options)\n\n if (isNested) {\n let selector = replaceParentRefs(prop, styleRule.selector)\n // Lazily create the ref replacer function just once for\n // all nested rules within the sheet.\n if (!replaceRef) replaceRef = getReplaceRef(container, sheet)\n // Replace all $refs.\n selector = selector.replace(refRegExp, replaceRef)\n\n container.addRule(selecto
|