1 line
5.8 KiB
JSON
1 line
5.8 KiB
JSON
{"ast":null,"code":"'use strict';\n\nfunction _createForOfIteratorHelper(o) { if (typeof Symbol === \"undefined\" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (o = _unsupportedIterableToArray(o))) { var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError(\"Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); } var it, normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }\n\nfunction _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === \"string\") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === \"Object\" && o.constructor) n = o.constructor.name; if (n === \"Map\" || n === \"Set\") return Array.from(o); if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }\n\nfunction _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }\n\nvar TEMPLATE_REGEX = /(?:\\\\(u[a-f\\d]{4}|x[a-f\\d]{2}|.))|(?:\\{(~)?(\\w+(?:\\([^)]*\\))?(?:\\.\\w+(?:\\([^)]*\\))?)*)(?:[ \\t]|(?=\\r?\\n)))|(\\})|((?:.|[\\r\\n\\f])+?)/gi;\nvar STYLE_REGEX = /(?:^|\\.)(\\w+)(?:\\(([^)]*)\\))?/g;\nvar STRING_REGEX = /^(['\"])((?:\\\\.|(?!\\1)[^\\\\])*)\\1$/;\nvar ESCAPE_REGEX = /\\\\(u[a-f\\d]{4}|x[a-f\\d]{2}|.)|([^\\\\])/gi;\nvar ESCAPES = new Map([['n', '\\n'], ['r', '\\r'], ['t', '\\t'], ['b', '\\b'], ['f', '\\f'], ['v', '\\v'], ['0', '\\0'], ['\\\\', '\\\\'], ['e', \"\\x1B\"], ['a', \"\\x07\"]]);\n\nfunction unescape(c) {\n if (c[0] === 'u' && c.length === 5 || c[0] === 'x' && c.length === 3) {\n return String.fromCharCode(parseInt(c.slice(1), 16));\n }\n\n return ESCAPES.get(c) || c;\n}\n\nfunction parseArguments(name, args) {\n var results = [];\n var chunks = args.trim().split(/\\s*,\\s*/g);\n var matches;\n\n var _iterator = _createForOfIteratorHelper(chunks),\n _step;\n\n try {\n for (_iterator.s(); !(_step = _iterator.n()).done;) {\n var chunk = _step.value;\n\n if (!isNaN(chunk)) {\n results.push(Number(chunk));\n } else if (matches = chunk.match(STRING_REGEX)) {\n results.push(matches[2].replace(ESCAPE_REGEX, function (m, escape, chr) {\n return escape ? unescape(escape) : chr;\n }));\n } else {\n throw new Error(\"Invalid Chalk template style argument: \".concat(chunk, \" (in style '\").concat(name, \"')\"));\n }\n }\n } catch (err) {\n _iterator.e(err);\n } finally {\n _iterator.f();\n }\n\n return results;\n}\n\nfunction parseStyle(style) {\n STYLE_REGEX.lastIndex = 0;\n var results = [];\n var matches;\n\n while ((matches = STYLE_REGEX.exec(style)) !== null) {\n var name = matches[1];\n\n if (matches[2]) {\n var args = parseArguments(name, matches[2]);\n results.push([name].concat(args));\n } else {\n results.push([name]);\n }\n }\n\n return results;\n}\n\nfunction buildStyle(chalk, styles) {\n var enabled = {};\n\n var _iterator2 = _createForOfIteratorHelper(styles),\n _step2;\n\n try {\n for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {\n var layer = _step2.value;\n\n var _iterator3 = _createForOfIteratorHelper(layer.styles),\n _step3;\n\n try {\n for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {\n var style = _step3.value;\n enabled[style[0]] = layer.inverse ? null : style.slice(1);\n }\n } catch (err) {\n _iterator3.e(err);\n } finally {\n _iterator3.f();\n }\n }\n } catch (err) {\n _iterator2.e(err);\n } finally {\n _iterator2.f();\n }\n\n var current = chalk;\n\n for (var _i = 0, _Object$keys = Object.keys(enabled); _i < _Object$keys.length; _i++) {\n var styleName = _Object$keys[_i];\n\n if (Array.isArray(enabled[styleName])) {\n if (!(styleName in current)) {\n throw new Error(\"Unknown Chalk style: \".concat(styleName));\n }\n\n if (enabled[styleName].length > 0) {\n current = current[styleName].apply(current, enabled[styleName]);\n } else {\n current = current[styleName];\n }\n }\n }\n\n return current;\n}\n\nmodule.exports = function (chalk, tmp) {\n var styles = [];\n var chunks = [];\n var chunk = []; // eslint-disable-next-line max-params\n\n tmp.replace(TEMPLATE_REGEX, function (m, escapeChar, inverse, style, close, chr) {\n if (escapeChar) {\n chunk.push(unescape(escapeChar));\n } else if (style) {\n var str = chunk.join('');\n chunk = [];\n chunks.push(styles.length === 0 ? str : buildStyle(chalk, styles)(str));\n styles.push({\n inverse: inverse,\n styles: parseStyle(style)\n });\n } else if (close) {\n if (styles.length === 0) {\n throw new Error('Found extraneous } in Chalk template literal');\n }\n\n chunks.push(buildStyle(chalk, styles)(chunk.join('')));\n chunk = [];\n styles.pop();\n } else {\n chunk.push(chr);\n }\n });\n chunks.push(chunk.join(''));\n\n if (styles.length > 0) {\n var errMsg = \"Chalk template literal is missing \".concat(styles.length, \" closing bracket\").concat(styles.length === 1 ? '' : 's', \" (`}`)\");\n throw new Error(errMsg);\n }\n\n return chunks.join('');\n};","map":null,"metadata":{},"sourceType":"script"} |