{"version":3,"file":"jss-plugin-global.js","sources":["../../../node_modules/@babel/runtime/helpers/esm/extends.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}","// @flow\nimport {\n RuleList,\n type Plugin,\n type RuleOptions,\n type ContainerRule,\n type StyleRule,\n type BaseRule\n} from 'jss'\n\nconst at = '@global'\nconst atPrefix = '@global '\n\nclass GlobalContainerRule implements ContainerRule {\n type = 'global'\n\n at: string = at\n\n rules: RuleList\n\n options: RuleOptions\n\n key: string\n\n isProcessed: boolean = false\n\n constructor(key, styles, options: RuleOptions) {\n this.key = key\n this.options = options\n this.rules = new RuleList({\n ...options,\n parent: this\n })\n\n for (const selector in styles) {\n this.rules.add(selector, styles[selector])\n }\n\n this.rules.process()\n }\n\n /**\n * Get a rule.\n */\n getRule(name) {\n return this.rules.get(name)\n }\n\n /**\n * Create and register rule, run plugins.\n */\n addRule(name, style, options) {\n const rule = this.rules.add(name, style, options)\n if (rule) this.options.jss.plugins.onProcessRule(rule)\n return rule\n }\n\n /**\n * Get index of a rule.\n */\n indexOf(rule) {\n return this.rules.indexOf(rule)\n }\n\n /**\n * Generates a CSS string.\n */\n toString() {\n return this.rules.toString()\n }\n}\n\nclass GlobalPrefixedRule implements BaseRule {\n type = 'global'\n\n at: string = at\n\n options: RuleOptions\n\n rule: BaseRule | null\n\n isProcessed: boolean = false\n\n key: string\n\n constructor(key, style, options) {\n this.key = key\n this.options = options\n const selector = key.substr(atPrefix.length)\n this.rule = options.jss.createRule(selector, style, {\n ...options,\n parent: this\n })\n }\n\n toString(options) {\n return this.rule ? this.rule.toString(options) : ''\n }\n}\n\nconst separatorRegExp = /\\s*,\\s*/g\n\nfunction addScope(selector, scope) {\n const parts = selector.split(separatorRegExp)\n let scoped = ''\n for (let i = 0; i < parts.length; i++) {\n scoped += `${scope} ${parts[i].trim()}`\n if (parts[i + 1]) scoped += ', '\n }\n return scoped\n}\n\nfunction handleNestedGlobalContainerRule(rule, sheet) {\n const {options, style} = rule\n const rules = style ? style[at] : null\n\n if (!rules) return\n\n for (const name in rules) {\n sheet.addRule(name, rules[name], {\n ...options,\n selector: addScope(name, rule.selector)\n })\n }\n\n delete style[at]\n}\n\nfunction handlePrefixedGlobalRule(rule, sheet) {\n const {options, style} = rule\n for (const prop in style) {\n if (prop[0] !== '@' || prop.substr(0, at.length) !== at) continue\n\n const selector = addScope(prop.substr(at.length), rule.selector)\n sheet.addRule(selector, style[prop], {\n ...options,\n selector\n })\n delete style[prop]\n }\n}\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 jssGlobal(): Plugin {\n function onCreateRule(name, styles, options) {\n if (!name) return null\n\n if (name === at) {\n return new GlobalContainerRule(name, styles, options)\n }\n\n if (name[0] === '@' && name.substr(0, atPrefix.length) === atPrefix) {\n return new GlobalPrefixedRule(name, styles, options)\n }\n\n const {parent} = options\n\n if (parent) {\n if (\n parent.type === 'global' ||\n (parent.options.parent && parent.options.parent.type === 'global')\n ) {\n options.scoped = false\n }\n }\n\n if (options.scoped === false) {\n options.selector = name\n }\n\n return null\n }\n\n function onProcessRule(rule, sheet) {\n if (rule.type !== 'style' || !sheet) return\n\n handleNestedGlobalContainerRule(((rule: any): StyleRule), sheet)\n handlePrefixedGlobalRule(((rule: any): StyleRule), sheet)\n }\n\n return {onCreateRule, onProcessRule}\n}\n"],"names":["at","atPrefix","GlobalContainerRule","key","styles","options","type","rules","isProcessed","RuleList","parent","selector","add","process","getRule","name","get","addRule","style","rule","jss","plugins","onProcessRule","indexOf","toString","GlobalPrefixedRule","substr","length","createRule","separatorRegExp","addScope","scope","parts","split","scoped","i","trim","handleNestedGlobalContainerRule","sheet","handlePrefixedGlobalRule","prop","jssGlobal","on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