mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-24 09:25:15 +00:00
1 line
9.5 KiB
Plaintext
1 line
9.5 KiB
Plaintext
|
{"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
|