UNPKG

astexplorer.app

Version:

https://astexplorer.net with ES Modules support and Hot Reloading

1 lines 11.8 kB
(window.webpackJsonp=window.webpackJsonp||[]).push([[86],{"./node_modules/css/lib/parse/index.js":function(module,exports){eval("// http://www.w3.org/TR/CSS21/grammar.html\n// https://github.com/visionmedia/css-parse/pull/49#issuecomment-30088027\nvar commentre = /\\/\\*[^*]*\\*+([^/*][^*]*\\*+)*\\//g\n\nmodule.exports = function(css, options){\n options = options || {};\n\n /**\n * Positional.\n */\n\n var lineno = 1;\n var column = 1;\n\n /**\n * Update lineno and column based on `str`.\n */\n\n function updatePosition(str) {\n var lines = str.match(/\\n/g);\n if (lines) lineno += lines.length;\n var i = str.lastIndexOf('\\n');\n column = ~i ? str.length - i : column + str.length;\n }\n\n /**\n * Mark position and patch `node.position`.\n */\n\n function position() {\n var start = { line: lineno, column: column };\n return function(node){\n node.position = new Position(start);\n whitespace();\n return node;\n };\n }\n\n /**\n * Store position information for a node\n */\n\n function Position(start) {\n this.start = start;\n this.end = { line: lineno, column: column };\n this.source = options.source;\n }\n\n /**\n * Non-enumerable source string\n */\n\n Position.prototype.content = css;\n\n /**\n * Error `msg`.\n */\n\n var errorsList = [];\n\n function error(msg) {\n var err = new Error(options.source + ':' + lineno + ':' + column + ': ' + msg);\n err.reason = msg;\n err.filename = options.source;\n err.line = lineno;\n err.column = column;\n err.source = css;\n\n if (options.silent) {\n errorsList.push(err);\n } else {\n throw err;\n }\n }\n\n /**\n * Parse stylesheet.\n */\n\n function stylesheet() {\n var rulesList = rules();\n\n return {\n type: 'stylesheet',\n stylesheet: {\n source: options.source,\n rules: rulesList,\n parsingErrors: errorsList\n }\n };\n }\n\n /**\n * Opening brace.\n */\n\n function open() {\n return match(/^{\\s*/);\n }\n\n /**\n * Closing brace.\n */\n\n function close() {\n return match(/^}/);\n }\n\n /**\n * Parse ruleset.\n */\n\n function rules() {\n var node;\n var rules = [];\n whitespace();\n comments(rules);\n while (css.length && css.charAt(0) != '}' && (node = atrule() || rule())) {\n if (node !== false) {\n rules.push(node);\n comments(rules);\n }\n }\n return rules;\n }\n\n /**\n * Match `re` and return captures.\n */\n\n function match(re) {\n var m = re.exec(css);\n if (!m) return;\n var str = m[0];\n updatePosition(str);\n css = css.slice(str.length);\n return m;\n }\n\n /**\n * Parse whitespace.\n */\n\n function whitespace() {\n match(/^\\s*/);\n }\n\n /**\n * Parse comments;\n */\n\n function comments(rules) {\n var c;\n rules = rules || [];\n while (c = comment()) {\n if (c !== false) {\n rules.push(c);\n }\n }\n return rules;\n }\n\n /**\n * Parse comment.\n */\n\n function comment() {\n var pos = position();\n if ('/' != css.charAt(0) || '*' != css.charAt(1)) return;\n\n var i = 2;\n while (\"\" != css.charAt(i) && ('*' != css.charAt(i) || '/' != css.charAt(i + 1))) ++i;\n i += 2;\n\n if (\"\" === css.charAt(i-1)) {\n return error('End of comment missing');\n }\n\n var str = css.slice(2, i - 2);\n column += 2;\n updatePosition(str);\n css = css.slice(i);\n column += 2;\n\n return pos({\n type: 'comment',\n comment: str\n });\n }\n\n /**\n * Parse selector.\n */\n\n function selector() {\n var m = match(/^([^{]+)/);\n if (!m) return;\n /* @fix Remove all comments from selectors\n * http://ostermiller.org/findcomment.html */\n return trim(m[0])\n .replace(/\\/\\*([^*]|[\\r\\n]|(\\*+([^*/]|[\\r\\n])))*\\*\\/+/g, '')\n .replace(/\"(?:\\\\\"|[^\"])*\"|'(?:\\\\'|[^'])*'/g, function(m) {\n return m.replace(/,/g, '\\u200C');\n })\n .split(/\\s*(?![^(]*\\)),\\s*/)\n .map(function(s) {\n return s.replace(/\\u200C/g, ',');\n });\n }\n\n /**\n * Parse declaration.\n */\n\n function declaration() {\n var pos = position();\n\n // prop\n var prop = match(/^(\\*?[-#\\/\\*\\\\\\w]+(\\[[0-9a-z_-]+\\])?)\\s*/);\n if (!prop) return;\n prop = trim(prop[0]);\n\n // :\n if (!match(/^:\\s*/)) return error(\"property missing ':'\");\n\n // val\n var val = match(/^((?:'(?:\\\\'|.)*?'|\"(?:\\\\\"|.)*?\"|\\([^\\)]*?\\)|[^};])+)/);\n\n var ret = pos({\n type: 'declaration',\n property: prop.replace(commentre, ''),\n value: val ? trim(val[0]).replace(commentre, '') : ''\n });\n\n // ;\n match(/^[;\\s]*/);\n\n return ret;\n }\n\n /**\n * Parse declarations.\n */\n\n function declarations() {\n var decls = [];\n\n if (!open()) return error(\"missing '{'\");\n comments(decls);\n\n // declarations\n var decl;\n while (decl = declaration()) {\n if (decl !== false) {\n decls.push(decl);\n comments(decls);\n }\n }\n\n if (!close()) return error(\"missing '}'\");\n return decls;\n }\n\n /**\n * Parse keyframe.\n */\n\n function keyframe() {\n var m;\n var vals = [];\n var pos = position();\n\n while (m = match(/^((\\d+\\.\\d+|\\.\\d+|\\d+)%?|[a-z]+)\\s*/)) {\n vals.push(m[1]);\n match(/^,\\s*/);\n }\n\n if (!vals.length) return;\n\n return pos({\n type: 'keyframe',\n values: vals,\n declarations: declarations()\n });\n }\n\n /**\n * Parse keyframes.\n */\n\n function atkeyframes() {\n var pos = position();\n var m = match(/^@([-\\w]+)?keyframes\\s*/);\n\n if (!m) return;\n var vendor = m[1];\n\n // identifier\n var m = match(/^([-\\w]+)\\s*/);\n if (!m) return error(\"@keyframes missing name\");\n var name = m[1];\n\n if (!open()) return error(\"@keyframes missing '{'\");\n\n var frame;\n var frames = comments();\n while (frame = keyframe()) {\n frames.push(frame);\n frames = frames.concat(comments());\n }\n\n if (!close()) return error(\"@keyframes missing '}'\");\n\n return pos({\n type: 'keyframes',\n name: name,\n vendor: vendor,\n keyframes: frames\n });\n }\n\n /**\n * Parse supports.\n */\n\n function atsupports() {\n var pos = position();\n var m = match(/^@supports *([^{]+)/);\n\n if (!m) return;\n var supports = trim(m[1]);\n\n if (!open()) return error(\"@supports missing '{'\");\n\n var style = comments().concat(rules());\n\n if (!close()) return error(\"@supports missing '}'\");\n\n return pos({\n type: 'supports',\n supports: supports,\n rules: style\n });\n }\n\n /**\n * Parse host.\n */\n\n function athost() {\n var pos = position();\n var m = match(/^@host\\s*/);\n\n if (!m) return;\n\n if (!open()) return error(\"@host missing '{'\");\n\n var style = comments().concat(rules());\n\n if (!close()) return error(\"@host missing '}'\");\n\n return pos({\n type: 'host',\n rules: style\n });\n }\n\n /**\n * Parse media.\n */\n\n function atmedia() {\n var pos = position();\n var m = match(/^@media *([^{]+)/);\n\n if (!m) return;\n var media = trim(m[1]);\n\n if (!open()) return error(\"@media missing '{'\");\n\n var style = comments().concat(rules());\n\n if (!close()) return error(\"@media missing '}'\");\n\n return pos({\n type: 'media',\n media: media,\n rules: style\n });\n }\n\n\n /**\n * Parse custom-media.\n */\n\n function atcustommedia() {\n var pos = position();\n var m = match(/^@custom-media\\s+(--[^\\s]+)\\s*([^{;]+);/);\n if (!m) return;\n\n return pos({\n type: 'custom-media',\n name: trim(m[1]),\n media: trim(m[2])\n });\n }\n\n /**\n * Parse paged media.\n */\n\n function atpage() {\n var pos = position();\n var m = match(/^@page */);\n if (!m) return;\n\n var sel = selector() || [];\n\n if (!open()) return error(\"@page missing '{'\");\n var decls = comments();\n\n // declarations\n var decl;\n while (decl = declaration()) {\n decls.push(decl);\n decls = decls.concat(comments());\n }\n\n if (!close()) return error(\"@page missing '}'\");\n\n return pos({\n type: 'page',\n selectors: sel,\n declarations: decls\n });\n }\n\n /**\n * Parse document.\n */\n\n function atdocument() {\n var pos = position();\n var m = match(/^@([-\\w]+)?document *([^{]+)/);\n if (!m) return;\n\n var vendor = trim(m[1]);\n var doc = trim(m[2]);\n\n if (!open()) return error(\"@document missing '{'\");\n\n var style = comments().concat(rules());\n\n if (!close()) return error(\"@document missing '}'\");\n\n return pos({\n type: 'document',\n document: doc,\n vendor: vendor,\n rules: style\n });\n }\n\n /**\n * Parse font-face.\n */\n\n function atfontface() {\n var pos = position();\n var m = match(/^@font-face\\s*/);\n if (!m) return;\n\n if (!open()) return error(\"@font-face missing '{'\");\n var decls = comments();\n\n // declarations\n var decl;\n while (decl = declaration()) {\n decls.push(decl);\n decls = decls.concat(comments());\n }\n\n if (!close()) return error(\"@font-face missing '}'\");\n\n return pos({\n type: 'font-face',\n declarations: decls\n });\n }\n\n /**\n * Parse import\n */\n\n var atimport = _compileAtrule('import');\n\n /**\n * Parse charset\n */\n\n var atcharset = _compileAtrule('charset');\n\n /**\n * Parse namespace\n */\n\n var atnamespace = _compileAtrule('namespace');\n\n /**\n * Parse non-block at-rules\n */\n\n\n function _compileAtrule(name) {\n var re = new RegExp('^@' + name + '\\\\s*([^;]+);');\n return function() {\n var pos = position();\n var m = match(re);\n if (!m) return;\n var ret = { type: name };\n ret[name] = m[1].trim();\n return pos(ret);\n }\n }\n\n /**\n * Parse at rule.\n */\n\n function atrule() {\n if (css[0] != '@') return;\n\n return atkeyframes()\n || atmedia()\n || atcustommedia()\n || atsupports()\n || atimport()\n || atcharset()\n || atnamespace()\n || atdocument()\n || atpage()\n || athost()\n || atfontface();\n }\n\n /**\n * Parse rule.\n */\n\n function rule() {\n var pos = position();\n var sel = selector();\n\n if (!sel) return error('selector missing');\n comments();\n\n return pos({\n type: 'rule',\n selectors: sel,\n declarations: declarations()\n });\n }\n\n return addParent(stylesheet());\n};\n\n/**\n * Trim `str`.\n */\n\nfunction trim(str) {\n return str ? str.replace(/^\\s+|\\s+$/g, '') : '';\n}\n\n/**\n * Adds non-enumerable parent node reference to each node.\n */\n\nfunction addParent(obj, parent) {\n var isNode = obj && typeof obj.type === 'string';\n var childParent = isNode ? obj : parent;\n\n for (var k in obj) {\n var value = obj[k];\n if (Array.isArray(value)) {\n value.forEach(function(v) { addParent(v, childParent); });\n } else if (value && typeof value === 'object') {\n addParent(value, childParent);\n }\n }\n\n if (isNode) {\n Object.defineProperty(obj, 'parent', {\n configurable: true,\n writable: true,\n enumerable: false,\n value: parent || null\n });\n }\n\n return obj;\n}\n\n\n//# sourceURL=webpack:///./node_modules/css/lib/parse/index.js?")}}]);