[57e58a3] | 1 | import { Q as commonjsGlobal, P as getDefaultExportFromCjs } from './dep-CfG9u7Cn.js';
|
---|
| 2 | import require$$0$2 from 'fs';
|
---|
| 3 | import require$$0 from 'postcss';
|
---|
| 4 | import require$$0$1 from 'path';
|
---|
| 5 | import require$$3 from 'crypto';
|
---|
| 6 | import require$$1 from 'util';
|
---|
| 7 | import { l as lib } from './dep-3RmXg9uo.js';
|
---|
| 8 |
|
---|
| 9 | function _mergeNamespaces(n, m) {
|
---|
| 10 | for (var i = 0; i < m.length; i++) {
|
---|
| 11 | var e = m[i];
|
---|
| 12 | if (typeof e !== 'string' && !Array.isArray(e)) { for (var k in e) {
|
---|
| 13 | if (k !== 'default' && !(k in n)) {
|
---|
| 14 | n[k] = e[k];
|
---|
| 15 | }
|
---|
| 16 | } }
|
---|
| 17 | }
|
---|
| 18 | return n;
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | var build = {exports: {}};
|
---|
| 22 |
|
---|
| 23 | var fs = {};
|
---|
| 24 |
|
---|
| 25 | Object.defineProperty(fs, "__esModule", {
|
---|
| 26 | value: true
|
---|
| 27 | });
|
---|
| 28 | fs.getFileSystem = getFileSystem;
|
---|
| 29 | fs.setFileSystem = setFileSystem;
|
---|
| 30 | let fileSystem = {
|
---|
| 31 | readFile: () => {
|
---|
| 32 | throw Error("readFile not implemented");
|
---|
| 33 | },
|
---|
| 34 | writeFile: () => {
|
---|
| 35 | throw Error("writeFile not implemented");
|
---|
| 36 | }
|
---|
| 37 | };
|
---|
| 38 |
|
---|
| 39 | function setFileSystem(fs) {
|
---|
| 40 | fileSystem.readFile = fs.readFile;
|
---|
| 41 | fileSystem.writeFile = fs.writeFile;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | function getFileSystem() {
|
---|
| 45 | return fileSystem;
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | var pluginFactory = {};
|
---|
| 49 |
|
---|
| 50 | var unquote$1 = {};
|
---|
| 51 |
|
---|
| 52 | Object.defineProperty(unquote$1, "__esModule", {
|
---|
| 53 | value: true
|
---|
| 54 | });
|
---|
| 55 | unquote$1.default = unquote;
|
---|
| 56 | // copied from https://github.com/lakenen/node-unquote
|
---|
| 57 | const reg = /['"]/;
|
---|
| 58 |
|
---|
| 59 | function unquote(str) {
|
---|
| 60 | if (!str) {
|
---|
| 61 | return "";
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | if (reg.test(str.charAt(0))) {
|
---|
| 65 | str = str.substr(1);
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | if (reg.test(str.charAt(str.length - 1))) {
|
---|
| 69 | str = str.substr(0, str.length - 1);
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | return str;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | var Parser$1 = {};
|
---|
| 76 |
|
---|
| 77 | const matchValueName = /[$]?[\w-]+/g;
|
---|
| 78 |
|
---|
| 79 | const replaceValueSymbols$2 = (value, replacements) => {
|
---|
| 80 | let matches;
|
---|
| 81 |
|
---|
| 82 | while ((matches = matchValueName.exec(value))) {
|
---|
| 83 | const replacement = replacements[matches[0]];
|
---|
| 84 |
|
---|
| 85 | if (replacement) {
|
---|
| 86 | value =
|
---|
| 87 | value.slice(0, matches.index) +
|
---|
| 88 | replacement +
|
---|
| 89 | value.slice(matchValueName.lastIndex);
|
---|
| 90 |
|
---|
| 91 | matchValueName.lastIndex -= matches[0].length - replacement.length;
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | return value;
|
---|
| 96 | };
|
---|
| 97 |
|
---|
| 98 | var replaceValueSymbols_1 = replaceValueSymbols$2;
|
---|
| 99 |
|
---|
| 100 | const replaceValueSymbols$1 = replaceValueSymbols_1;
|
---|
| 101 |
|
---|
| 102 | const replaceSymbols$1 = (css, replacements) => {
|
---|
| 103 | css.walk((node) => {
|
---|
| 104 | if (node.type === "decl" && node.value) {
|
---|
| 105 | node.value = replaceValueSymbols$1(node.value.toString(), replacements);
|
---|
| 106 | } else if (node.type === "rule" && node.selector) {
|
---|
| 107 | node.selector = replaceValueSymbols$1(
|
---|
| 108 | node.selector.toString(),
|
---|
| 109 | replacements
|
---|
| 110 | );
|
---|
| 111 | } else if (node.type === "atrule" && node.params) {
|
---|
| 112 | node.params = replaceValueSymbols$1(node.params.toString(), replacements);
|
---|
| 113 | }
|
---|
| 114 | });
|
---|
| 115 | };
|
---|
| 116 |
|
---|
| 117 | var replaceSymbols_1 = replaceSymbols$1;
|
---|
| 118 |
|
---|
| 119 | const importPattern = /^:import\(("[^"]*"|'[^']*'|[^"']+)\)$/;
|
---|
| 120 | const balancedQuotes = /^("[^"]*"|'[^']*'|[^"']+)$/;
|
---|
| 121 |
|
---|
| 122 | const getDeclsObject = (rule) => {
|
---|
| 123 | const object = {};
|
---|
| 124 |
|
---|
| 125 | rule.walkDecls((decl) => {
|
---|
| 126 | const before = decl.raws.before ? decl.raws.before.trim() : "";
|
---|
| 127 |
|
---|
| 128 | object[before + decl.prop] = decl.value;
|
---|
| 129 | });
|
---|
| 130 |
|
---|
| 131 | return object;
|
---|
| 132 | };
|
---|
| 133 | /**
|
---|
| 134 | *
|
---|
| 135 | * @param {string} css
|
---|
| 136 | * @param {boolean} removeRules
|
---|
| 137 | * @param {'auto' | 'rule' | 'at-rule'} mode
|
---|
| 138 | */
|
---|
| 139 | const extractICSS$2 = (css, removeRules = true, mode = "auto") => {
|
---|
| 140 | const icssImports = {};
|
---|
| 141 | const icssExports = {};
|
---|
| 142 |
|
---|
| 143 | function addImports(node, path) {
|
---|
| 144 | const unquoted = path.replace(/'|"/g, "");
|
---|
| 145 | icssImports[unquoted] = Object.assign(
|
---|
| 146 | icssImports[unquoted] || {},
|
---|
| 147 | getDeclsObject(node)
|
---|
| 148 | );
|
---|
| 149 |
|
---|
| 150 | if (removeRules) {
|
---|
| 151 | node.remove();
|
---|
| 152 | }
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | function addExports(node) {
|
---|
| 156 | Object.assign(icssExports, getDeclsObject(node));
|
---|
| 157 | if (removeRules) {
|
---|
| 158 | node.remove();
|
---|
| 159 | }
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | css.each((node) => {
|
---|
| 163 | if (node.type === "rule" && mode !== "at-rule") {
|
---|
| 164 | if (node.selector.slice(0, 7) === ":import") {
|
---|
| 165 | const matches = importPattern.exec(node.selector);
|
---|
| 166 |
|
---|
| 167 | if (matches) {
|
---|
| 168 | addImports(node, matches[1]);
|
---|
| 169 | }
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 | if (node.selector === ":export") {
|
---|
| 173 | addExports(node);
|
---|
| 174 | }
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | if (node.type === "atrule" && mode !== "rule") {
|
---|
| 178 | if (node.name === "icss-import") {
|
---|
| 179 | const matches = balancedQuotes.exec(node.params);
|
---|
| 180 |
|
---|
| 181 | if (matches) {
|
---|
| 182 | addImports(node, matches[1]);
|
---|
| 183 | }
|
---|
| 184 | }
|
---|
| 185 | if (node.name === "icss-export") {
|
---|
| 186 | addExports(node);
|
---|
| 187 | }
|
---|
| 188 | }
|
---|
| 189 | });
|
---|
| 190 |
|
---|
| 191 | return { icssImports, icssExports };
|
---|
| 192 | };
|
---|
| 193 |
|
---|
| 194 | var extractICSS_1 = extractICSS$2;
|
---|
| 195 |
|
---|
| 196 | const createImports = (imports, postcss, mode = "rule") => {
|
---|
| 197 | return Object.keys(imports).map((path) => {
|
---|
| 198 | const aliases = imports[path];
|
---|
| 199 | const declarations = Object.keys(aliases).map((key) =>
|
---|
| 200 | postcss.decl({
|
---|
| 201 | prop: key,
|
---|
| 202 | value: aliases[key],
|
---|
| 203 | raws: { before: "\n " },
|
---|
| 204 | })
|
---|
| 205 | );
|
---|
| 206 |
|
---|
| 207 | const hasDeclarations = declarations.length > 0;
|
---|
| 208 |
|
---|
| 209 | const rule =
|
---|
| 210 | mode === "rule"
|
---|
| 211 | ? postcss.rule({
|
---|
| 212 | selector: `:import('${path}')`,
|
---|
| 213 | raws: { after: hasDeclarations ? "\n" : "" },
|
---|
| 214 | })
|
---|
| 215 | : postcss.atRule({
|
---|
| 216 | name: "icss-import",
|
---|
| 217 | params: `'${path}'`,
|
---|
| 218 | raws: { after: hasDeclarations ? "\n" : "" },
|
---|
| 219 | });
|
---|
| 220 |
|
---|
| 221 | if (hasDeclarations) {
|
---|
| 222 | rule.append(declarations);
|
---|
| 223 | }
|
---|
| 224 |
|
---|
| 225 | return rule;
|
---|
| 226 | });
|
---|
| 227 | };
|
---|
| 228 |
|
---|
| 229 | const createExports = (exports, postcss, mode = "rule") => {
|
---|
| 230 | const declarations = Object.keys(exports).map((key) =>
|
---|
| 231 | postcss.decl({
|
---|
| 232 | prop: key,
|
---|
| 233 | value: exports[key],
|
---|
| 234 | raws: { before: "\n " },
|
---|
| 235 | })
|
---|
| 236 | );
|
---|
| 237 |
|
---|
| 238 | if (declarations.length === 0) {
|
---|
| 239 | return [];
|
---|
| 240 | }
|
---|
| 241 | const rule =
|
---|
| 242 | mode === "rule"
|
---|
| 243 | ? postcss.rule({
|
---|
| 244 | selector: `:export`,
|
---|
| 245 | raws: { after: "\n" },
|
---|
| 246 | })
|
---|
| 247 | : postcss.atRule({
|
---|
| 248 | name: "icss-export",
|
---|
| 249 | raws: { after: "\n" },
|
---|
| 250 | });
|
---|
| 251 |
|
---|
| 252 | rule.append(declarations);
|
---|
| 253 |
|
---|
| 254 | return [rule];
|
---|
| 255 | };
|
---|
| 256 |
|
---|
| 257 | const createICSSRules$1 = (imports, exports, postcss, mode) => [
|
---|
| 258 | ...createImports(imports, postcss, mode),
|
---|
| 259 | ...createExports(exports, postcss, mode),
|
---|
| 260 | ];
|
---|
| 261 |
|
---|
| 262 | var createICSSRules_1 = createICSSRules$1;
|
---|
| 263 |
|
---|
| 264 | const replaceValueSymbols = replaceValueSymbols_1;
|
---|
| 265 | const replaceSymbols = replaceSymbols_1;
|
---|
| 266 | const extractICSS$1 = extractICSS_1;
|
---|
| 267 | const createICSSRules = createICSSRules_1;
|
---|
| 268 |
|
---|
| 269 | var src$4 = {
|
---|
| 270 | replaceValueSymbols,
|
---|
| 271 | replaceSymbols,
|
---|
| 272 | extractICSS: extractICSS$1,
|
---|
| 273 | createICSSRules,
|
---|
| 274 | };
|
---|
| 275 |
|
---|
| 276 | Object.defineProperty(Parser$1, "__esModule", {
|
---|
| 277 | value: true
|
---|
| 278 | });
|
---|
| 279 | Parser$1.default = undefined;
|
---|
| 280 |
|
---|
| 281 | var _icssUtils = src$4;
|
---|
| 282 |
|
---|
| 283 | // Initially copied from https://github.com/css-modules/css-modules-loader-core
|
---|
| 284 | const importRegexp = /^:import\((.+)\)$/;
|
---|
| 285 |
|
---|
| 286 | class Parser {
|
---|
| 287 | constructor(pathFetcher, trace) {
|
---|
| 288 | this.pathFetcher = pathFetcher;
|
---|
| 289 | this.plugin = this.plugin.bind(this);
|
---|
| 290 | this.exportTokens = {};
|
---|
| 291 | this.translations = {};
|
---|
| 292 | this.trace = trace;
|
---|
| 293 | }
|
---|
| 294 |
|
---|
| 295 | plugin() {
|
---|
| 296 | const parser = this;
|
---|
| 297 | return {
|
---|
| 298 | postcssPlugin: "css-modules-parser",
|
---|
| 299 |
|
---|
| 300 | async OnceExit(css) {
|
---|
| 301 | await Promise.all(parser.fetchAllImports(css));
|
---|
| 302 | parser.linkImportedSymbols(css);
|
---|
| 303 | return parser.extractExports(css);
|
---|
| 304 | }
|
---|
| 305 |
|
---|
| 306 | };
|
---|
| 307 | }
|
---|
| 308 |
|
---|
| 309 | fetchAllImports(css) {
|
---|
| 310 | let imports = [];
|
---|
| 311 | css.each(node => {
|
---|
| 312 | if (node.type == "rule" && node.selector.match(importRegexp)) {
|
---|
| 313 | imports.push(this.fetchImport(node, css.source.input.from, imports.length));
|
---|
| 314 | }
|
---|
| 315 | });
|
---|
| 316 | return imports;
|
---|
| 317 | }
|
---|
| 318 |
|
---|
| 319 | linkImportedSymbols(css) {
|
---|
| 320 | (0, _icssUtils.replaceSymbols)(css, this.translations);
|
---|
| 321 | }
|
---|
| 322 |
|
---|
| 323 | extractExports(css) {
|
---|
| 324 | css.each(node => {
|
---|
| 325 | if (node.type == "rule" && node.selector == ":export") this.handleExport(node);
|
---|
| 326 | });
|
---|
| 327 | }
|
---|
| 328 |
|
---|
| 329 | handleExport(exportNode) {
|
---|
| 330 | exportNode.each(decl => {
|
---|
| 331 | if (decl.type == "decl") {
|
---|
| 332 | Object.keys(this.translations).forEach(translation => {
|
---|
| 333 | decl.value = decl.value.replace(translation, this.translations[translation]);
|
---|
| 334 | });
|
---|
| 335 | this.exportTokens[decl.prop] = decl.value;
|
---|
| 336 | }
|
---|
| 337 | });
|
---|
| 338 | exportNode.remove();
|
---|
| 339 | }
|
---|
| 340 |
|
---|
| 341 | async fetchImport(importNode, relativeTo, depNr) {
|
---|
| 342 | const file = importNode.selector.match(importRegexp)[1];
|
---|
| 343 | const depTrace = this.trace + String.fromCharCode(depNr);
|
---|
| 344 | const exports = await this.pathFetcher(file, relativeTo, depTrace);
|
---|
| 345 |
|
---|
| 346 | try {
|
---|
| 347 | importNode.each(decl => {
|
---|
| 348 | if (decl.type == "decl") {
|
---|
| 349 | this.translations[decl.prop] = exports[decl.value];
|
---|
| 350 | }
|
---|
| 351 | });
|
---|
| 352 | importNode.remove();
|
---|
| 353 | } catch (err) {
|
---|
| 354 | console.log(err);
|
---|
| 355 | }
|
---|
| 356 | }
|
---|
| 357 |
|
---|
| 358 | }
|
---|
| 359 |
|
---|
| 360 | Parser$1.default = Parser;
|
---|
| 361 |
|
---|
| 362 | var saveJSON$1 = {};
|
---|
| 363 |
|
---|
| 364 | Object.defineProperty(saveJSON$1, "__esModule", {
|
---|
| 365 | value: true
|
---|
| 366 | });
|
---|
| 367 | saveJSON$1.default = saveJSON;
|
---|
| 368 |
|
---|
| 369 | var _fs$2 = fs;
|
---|
| 370 |
|
---|
| 371 | function saveJSON(cssFile, json) {
|
---|
| 372 | return new Promise((resolve, reject) => {
|
---|
| 373 | const {
|
---|
| 374 | writeFile
|
---|
| 375 | } = (0, _fs$2.getFileSystem)();
|
---|
| 376 | writeFile(`${cssFile}.json`, JSON.stringify(json), e => e ? reject(e) : resolve(json));
|
---|
| 377 | });
|
---|
| 378 | }
|
---|
| 379 |
|
---|
| 380 | var localsConvention = {};
|
---|
| 381 |
|
---|
| 382 | /**
|
---|
| 383 | * lodash (Custom Build) <https://lodash.com/>
|
---|
| 384 | * Build: `lodash modularize exports="npm" -o ./`
|
---|
| 385 | * Copyright jQuery Foundation and other contributors <https://jquery.org/>
|
---|
| 386 | * Released under MIT license <https://lodash.com/license>
|
---|
| 387 | * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
---|
| 388 | * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
---|
| 389 | */
|
---|
| 390 |
|
---|
| 391 | /** `Object#toString` result references. */
|
---|
| 392 | var symbolTag = '[object Symbol]';
|
---|
| 393 |
|
---|
| 394 | /** Used to match words composed of alphanumeric characters. */
|
---|
| 395 | var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
|
---|
| 396 |
|
---|
| 397 | /** Used to match Latin Unicode letters (excluding mathematical operators). */
|
---|
| 398 | var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
|
---|
| 399 |
|
---|
| 400 | /** Used to compose unicode character classes. */
|
---|
| 401 | var rsAstralRange = '\\ud800-\\udfff',
|
---|
| 402 | rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23',
|
---|
| 403 | rsComboSymbolsRange = '\\u20d0-\\u20f0',
|
---|
| 404 | rsDingbatRange = '\\u2700-\\u27bf',
|
---|
| 405 | rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
|
---|
| 406 | rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
|
---|
| 407 | rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
|
---|
| 408 | rsPunctuationRange = '\\u2000-\\u206f',
|
---|
| 409 | rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000',
|
---|
| 410 | rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
|
---|
| 411 | rsVarRange = '\\ufe0e\\ufe0f',
|
---|
| 412 | rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
|
---|
| 413 |
|
---|
| 414 | /** Used to compose unicode capture groups. */
|
---|
| 415 | var rsApos = "['\u2019]",
|
---|
| 416 | rsAstral = '[' + rsAstralRange + ']',
|
---|
| 417 | rsBreak = '[' + rsBreakRange + ']',
|
---|
| 418 | rsCombo = '[' + rsComboMarksRange + rsComboSymbolsRange + ']',
|
---|
| 419 | rsDigits = '\\d+',
|
---|
| 420 | rsDingbat = '[' + rsDingbatRange + ']',
|
---|
| 421 | rsLower = '[' + rsLowerRange + ']',
|
---|
| 422 | rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
|
---|
| 423 | rsFitz = '\\ud83c[\\udffb-\\udfff]',
|
---|
| 424 | rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
|
---|
| 425 | rsNonAstral = '[^' + rsAstralRange + ']',
|
---|
| 426 | rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
|
---|
| 427 | rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
|
---|
| 428 | rsUpper = '[' + rsUpperRange + ']',
|
---|
| 429 | rsZWJ = '\\u200d';
|
---|
| 430 |
|
---|
| 431 | /** Used to compose unicode regexes. */
|
---|
| 432 | var rsLowerMisc = '(?:' + rsLower + '|' + rsMisc + ')',
|
---|
| 433 | rsUpperMisc = '(?:' + rsUpper + '|' + rsMisc + ')',
|
---|
| 434 | rsOptLowerContr = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?',
|
---|
| 435 | rsOptUpperContr = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?',
|
---|
| 436 | reOptMod = rsModifier + '?',
|
---|
| 437 | rsOptVar = '[' + rsVarRange + ']?',
|
---|
| 438 | rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
|
---|
| 439 | rsSeq = rsOptVar + reOptMod + rsOptJoin,
|
---|
| 440 | rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
|
---|
| 441 | rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
|
---|
| 442 |
|
---|
| 443 | /** Used to match apostrophes. */
|
---|
| 444 | var reApos = RegExp(rsApos, 'g');
|
---|
| 445 |
|
---|
| 446 | /**
|
---|
| 447 | * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
|
---|
| 448 | * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
|
---|
| 449 | */
|
---|
| 450 | var reComboMark = RegExp(rsCombo, 'g');
|
---|
| 451 |
|
---|
| 452 | /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
|
---|
| 453 | var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
|
---|
| 454 |
|
---|
| 455 | /** Used to match complex or compound words. */
|
---|
| 456 | var reUnicodeWord = RegExp([
|
---|
| 457 | rsUpper + '?' + rsLower + '+' + rsOptLowerContr + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
|
---|
| 458 | rsUpperMisc + '+' + rsOptUpperContr + '(?=' + [rsBreak, rsUpper + rsLowerMisc, '$'].join('|') + ')',
|
---|
| 459 | rsUpper + '?' + rsLowerMisc + '+' + rsOptLowerContr,
|
---|
| 460 | rsUpper + '+' + rsOptUpperContr,
|
---|
| 461 | rsDigits,
|
---|
| 462 | rsEmoji
|
---|
| 463 | ].join('|'), 'g');
|
---|
| 464 |
|
---|
| 465 | /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */
|
---|
| 466 | var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']');
|
---|
| 467 |
|
---|
| 468 | /** Used to detect strings that need a more robust regexp to match words. */
|
---|
| 469 | var reHasUnicodeWord = /[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;
|
---|
| 470 |
|
---|
| 471 | /** Used to map Latin Unicode letters to basic Latin letters. */
|
---|
| 472 | var deburredLetters = {
|
---|
| 473 | // Latin-1 Supplement block.
|
---|
| 474 | '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
|
---|
| 475 | '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
|
---|
| 476 | '\xc7': 'C', '\xe7': 'c',
|
---|
| 477 | '\xd0': 'D', '\xf0': 'd',
|
---|
| 478 | '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
|
---|
| 479 | '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
|
---|
| 480 | '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
|
---|
| 481 | '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
|
---|
| 482 | '\xd1': 'N', '\xf1': 'n',
|
---|
| 483 | '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
|
---|
| 484 | '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
|
---|
| 485 | '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
|
---|
| 486 | '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
|
---|
| 487 | '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
|
---|
| 488 | '\xc6': 'Ae', '\xe6': 'ae',
|
---|
| 489 | '\xde': 'Th', '\xfe': 'th',
|
---|
| 490 | '\xdf': 'ss',
|
---|
| 491 | // Latin Extended-A block.
|
---|
| 492 | '\u0100': 'A', '\u0102': 'A', '\u0104': 'A',
|
---|
| 493 | '\u0101': 'a', '\u0103': 'a', '\u0105': 'a',
|
---|
| 494 | '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C',
|
---|
| 495 | '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c',
|
---|
| 496 | '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd',
|
---|
| 497 | '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E',
|
---|
| 498 | '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e',
|
---|
| 499 | '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G',
|
---|
| 500 | '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g',
|
---|
| 501 | '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h',
|
---|
| 502 | '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I',
|
---|
| 503 | '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i',
|
---|
| 504 | '\u0134': 'J', '\u0135': 'j',
|
---|
| 505 | '\u0136': 'K', '\u0137': 'k', '\u0138': 'k',
|
---|
| 506 | '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L',
|
---|
| 507 | '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l',
|
---|
| 508 | '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N',
|
---|
| 509 | '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n',
|
---|
| 510 | '\u014c': 'O', '\u014e': 'O', '\u0150': 'O',
|
---|
| 511 | '\u014d': 'o', '\u014f': 'o', '\u0151': 'o',
|
---|
| 512 | '\u0154': 'R', '\u0156': 'R', '\u0158': 'R',
|
---|
| 513 | '\u0155': 'r', '\u0157': 'r', '\u0159': 'r',
|
---|
| 514 | '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S',
|
---|
| 515 | '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's',
|
---|
| 516 | '\u0162': 'T', '\u0164': 'T', '\u0166': 'T',
|
---|
| 517 | '\u0163': 't', '\u0165': 't', '\u0167': 't',
|
---|
| 518 | '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U',
|
---|
| 519 | '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u',
|
---|
| 520 | '\u0174': 'W', '\u0175': 'w',
|
---|
| 521 | '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y',
|
---|
| 522 | '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z',
|
---|
| 523 | '\u017a': 'z', '\u017c': 'z', '\u017e': 'z',
|
---|
| 524 | '\u0132': 'IJ', '\u0133': 'ij',
|
---|
| 525 | '\u0152': 'Oe', '\u0153': 'oe',
|
---|
| 526 | '\u0149': "'n", '\u017f': 'ss'
|
---|
| 527 | };
|
---|
| 528 |
|
---|
| 529 | /** Detect free variable `global` from Node.js. */
|
---|
| 530 | var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
|
---|
| 531 |
|
---|
| 532 | /** Detect free variable `self`. */
|
---|
| 533 | var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
|
---|
| 534 |
|
---|
| 535 | /** Used as a reference to the global object. */
|
---|
| 536 | var root$2 = freeGlobal || freeSelf || Function('return this')();
|
---|
| 537 |
|
---|
| 538 | /**
|
---|
| 539 | * A specialized version of `_.reduce` for arrays without support for
|
---|
| 540 | * iteratee shorthands.
|
---|
| 541 | *
|
---|
| 542 | * @private
|
---|
| 543 | * @param {Array} [array] The array to iterate over.
|
---|
| 544 | * @param {Function} iteratee The function invoked per iteration.
|
---|
| 545 | * @param {*} [accumulator] The initial value.
|
---|
| 546 | * @param {boolean} [initAccum] Specify using the first element of `array` as
|
---|
| 547 | * the initial value.
|
---|
| 548 | * @returns {*} Returns the accumulated value.
|
---|
| 549 | */
|
---|
| 550 | function arrayReduce(array, iteratee, accumulator, initAccum) {
|
---|
| 551 | var index = -1,
|
---|
| 552 | length = array ? array.length : 0;
|
---|
| 553 | while (++index < length) {
|
---|
| 554 | accumulator = iteratee(accumulator, array[index], index, array);
|
---|
| 555 | }
|
---|
| 556 | return accumulator;
|
---|
| 557 | }
|
---|
| 558 |
|
---|
| 559 | /**
|
---|
| 560 | * Converts an ASCII `string` to an array.
|
---|
| 561 | *
|
---|
| 562 | * @private
|
---|
| 563 | * @param {string} string The string to convert.
|
---|
| 564 | * @returns {Array} Returns the converted array.
|
---|
| 565 | */
|
---|
| 566 | function asciiToArray(string) {
|
---|
| 567 | return string.split('');
|
---|
| 568 | }
|
---|
| 569 |
|
---|
| 570 | /**
|
---|
| 571 | * Splits an ASCII `string` into an array of its words.
|
---|
| 572 | *
|
---|
| 573 | * @private
|
---|
| 574 | * @param {string} The string to inspect.
|
---|
| 575 | * @returns {Array} Returns the words of `string`.
|
---|
| 576 | */
|
---|
| 577 | function asciiWords(string) {
|
---|
| 578 | return string.match(reAsciiWord) || [];
|
---|
| 579 | }
|
---|
| 580 |
|
---|
| 581 | /**
|
---|
| 582 | * The base implementation of `_.propertyOf` without support for deep paths.
|
---|
| 583 | *
|
---|
| 584 | * @private
|
---|
| 585 | * @param {Object} object The object to query.
|
---|
| 586 | * @returns {Function} Returns the new accessor function.
|
---|
| 587 | */
|
---|
| 588 | function basePropertyOf(object) {
|
---|
| 589 | return function(key) {
|
---|
| 590 | return object == null ? undefined : object[key];
|
---|
| 591 | };
|
---|
| 592 | }
|
---|
| 593 |
|
---|
| 594 | /**
|
---|
| 595 | * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
|
---|
| 596 | * letters to basic Latin letters.
|
---|
| 597 | *
|
---|
| 598 | * @private
|
---|
| 599 | * @param {string} letter The matched letter to deburr.
|
---|
| 600 | * @returns {string} Returns the deburred letter.
|
---|
| 601 | */
|
---|
| 602 | var deburrLetter = basePropertyOf(deburredLetters);
|
---|
| 603 |
|
---|
| 604 | /**
|
---|
| 605 | * Checks if `string` contains Unicode symbols.
|
---|
| 606 | *
|
---|
| 607 | * @private
|
---|
| 608 | * @param {string} string The string to inspect.
|
---|
| 609 | * @returns {boolean} Returns `true` if a symbol is found, else `false`.
|
---|
| 610 | */
|
---|
| 611 | function hasUnicode(string) {
|
---|
| 612 | return reHasUnicode.test(string);
|
---|
| 613 | }
|
---|
| 614 |
|
---|
| 615 | /**
|
---|
| 616 | * Checks if `string` contains a word composed of Unicode symbols.
|
---|
| 617 | *
|
---|
| 618 | * @private
|
---|
| 619 | * @param {string} string The string to inspect.
|
---|
| 620 | * @returns {boolean} Returns `true` if a word is found, else `false`.
|
---|
| 621 | */
|
---|
| 622 | function hasUnicodeWord(string) {
|
---|
| 623 | return reHasUnicodeWord.test(string);
|
---|
| 624 | }
|
---|
| 625 |
|
---|
| 626 | /**
|
---|
| 627 | * Converts `string` to an array.
|
---|
| 628 | *
|
---|
| 629 | * @private
|
---|
| 630 | * @param {string} string The string to convert.
|
---|
| 631 | * @returns {Array} Returns the converted array.
|
---|
| 632 | */
|
---|
| 633 | function stringToArray(string) {
|
---|
| 634 | return hasUnicode(string)
|
---|
| 635 | ? unicodeToArray(string)
|
---|
| 636 | : asciiToArray(string);
|
---|
| 637 | }
|
---|
| 638 |
|
---|
| 639 | /**
|
---|
| 640 | * Converts a Unicode `string` to an array.
|
---|
| 641 | *
|
---|
| 642 | * @private
|
---|
| 643 | * @param {string} string The string to convert.
|
---|
| 644 | * @returns {Array} Returns the converted array.
|
---|
| 645 | */
|
---|
| 646 | function unicodeToArray(string) {
|
---|
| 647 | return string.match(reUnicode) || [];
|
---|
| 648 | }
|
---|
| 649 |
|
---|
| 650 | /**
|
---|
| 651 | * Splits a Unicode `string` into an array of its words.
|
---|
| 652 | *
|
---|
| 653 | * @private
|
---|
| 654 | * @param {string} The string to inspect.
|
---|
| 655 | * @returns {Array} Returns the words of `string`.
|
---|
| 656 | */
|
---|
| 657 | function unicodeWords(string) {
|
---|
| 658 | return string.match(reUnicodeWord) || [];
|
---|
| 659 | }
|
---|
| 660 |
|
---|
| 661 | /** Used for built-in method references. */
|
---|
| 662 | var objectProto = Object.prototype;
|
---|
| 663 |
|
---|
| 664 | /**
|
---|
| 665 | * Used to resolve the
|
---|
| 666 | * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
|
---|
| 667 | * of values.
|
---|
| 668 | */
|
---|
| 669 | var objectToString = objectProto.toString;
|
---|
| 670 |
|
---|
| 671 | /** Built-in value references. */
|
---|
| 672 | var Symbol$1 = root$2.Symbol;
|
---|
| 673 |
|
---|
| 674 | /** Used to convert symbols to primitives and strings. */
|
---|
| 675 | var symbolProto = Symbol$1 ? Symbol$1.prototype : undefined,
|
---|
| 676 | symbolToString = symbolProto ? symbolProto.toString : undefined;
|
---|
| 677 |
|
---|
| 678 | /**
|
---|
| 679 | * The base implementation of `_.slice` without an iteratee call guard.
|
---|
| 680 | *
|
---|
| 681 | * @private
|
---|
| 682 | * @param {Array} array The array to slice.
|
---|
| 683 | * @param {number} [start=0] The start position.
|
---|
| 684 | * @param {number} [end=array.length] The end position.
|
---|
| 685 | * @returns {Array} Returns the slice of `array`.
|
---|
| 686 | */
|
---|
| 687 | function baseSlice(array, start, end) {
|
---|
| 688 | var index = -1,
|
---|
| 689 | length = array.length;
|
---|
| 690 |
|
---|
| 691 | if (start < 0) {
|
---|
| 692 | start = -start > length ? 0 : (length + start);
|
---|
| 693 | }
|
---|
| 694 | end = end > length ? length : end;
|
---|
| 695 | if (end < 0) {
|
---|
| 696 | end += length;
|
---|
| 697 | }
|
---|
| 698 | length = start > end ? 0 : ((end - start) >>> 0);
|
---|
| 699 | start >>>= 0;
|
---|
| 700 |
|
---|
| 701 | var result = Array(length);
|
---|
| 702 | while (++index < length) {
|
---|
| 703 | result[index] = array[index + start];
|
---|
| 704 | }
|
---|
| 705 | return result;
|
---|
| 706 | }
|
---|
| 707 |
|
---|
| 708 | /**
|
---|
| 709 | * The base implementation of `_.toString` which doesn't convert nullish
|
---|
| 710 | * values to empty strings.
|
---|
| 711 | *
|
---|
| 712 | * @private
|
---|
| 713 | * @param {*} value The value to process.
|
---|
| 714 | * @returns {string} Returns the string.
|
---|
| 715 | */
|
---|
| 716 | function baseToString(value) {
|
---|
| 717 | // Exit early for strings to avoid a performance hit in some environments.
|
---|
| 718 | if (typeof value == 'string') {
|
---|
| 719 | return value;
|
---|
| 720 | }
|
---|
| 721 | if (isSymbol(value)) {
|
---|
| 722 | return symbolToString ? symbolToString.call(value) : '';
|
---|
| 723 | }
|
---|
| 724 | var result = (value + '');
|
---|
| 725 | return (result == '0' && (1 / value) == -Infinity) ? '-0' : result;
|
---|
| 726 | }
|
---|
| 727 |
|
---|
| 728 | /**
|
---|
| 729 | * Casts `array` to a slice if it's needed.
|
---|
| 730 | *
|
---|
| 731 | * @private
|
---|
| 732 | * @param {Array} array The array to inspect.
|
---|
| 733 | * @param {number} start The start position.
|
---|
| 734 | * @param {number} [end=array.length] The end position.
|
---|
| 735 | * @returns {Array} Returns the cast slice.
|
---|
| 736 | */
|
---|
| 737 | function castSlice(array, start, end) {
|
---|
| 738 | var length = array.length;
|
---|
| 739 | end = end === undefined ? length : end;
|
---|
| 740 | return (!start && end >= length) ? array : baseSlice(array, start, end);
|
---|
| 741 | }
|
---|
| 742 |
|
---|
| 743 | /**
|
---|
| 744 | * Creates a function like `_.lowerFirst`.
|
---|
| 745 | *
|
---|
| 746 | * @private
|
---|
| 747 | * @param {string} methodName The name of the `String` case method to use.
|
---|
| 748 | * @returns {Function} Returns the new case function.
|
---|
| 749 | */
|
---|
| 750 | function createCaseFirst(methodName) {
|
---|
| 751 | return function(string) {
|
---|
| 752 | string = toString(string);
|
---|
| 753 |
|
---|
| 754 | var strSymbols = hasUnicode(string)
|
---|
| 755 | ? stringToArray(string)
|
---|
| 756 | : undefined;
|
---|
| 757 |
|
---|
| 758 | var chr = strSymbols
|
---|
| 759 | ? strSymbols[0]
|
---|
| 760 | : string.charAt(0);
|
---|
| 761 |
|
---|
| 762 | var trailing = strSymbols
|
---|
| 763 | ? castSlice(strSymbols, 1).join('')
|
---|
| 764 | : string.slice(1);
|
---|
| 765 |
|
---|
| 766 | return chr[methodName]() + trailing;
|
---|
| 767 | };
|
---|
| 768 | }
|
---|
| 769 |
|
---|
| 770 | /**
|
---|
| 771 | * Creates a function like `_.camelCase`.
|
---|
| 772 | *
|
---|
| 773 | * @private
|
---|
| 774 | * @param {Function} callback The function to combine each word.
|
---|
| 775 | * @returns {Function} Returns the new compounder function.
|
---|
| 776 | */
|
---|
| 777 | function createCompounder(callback) {
|
---|
| 778 | return function(string) {
|
---|
| 779 | return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
|
---|
| 780 | };
|
---|
| 781 | }
|
---|
| 782 |
|
---|
| 783 | /**
|
---|
| 784 | * Checks if `value` is object-like. A value is object-like if it's not `null`
|
---|
| 785 | * and has a `typeof` result of "object".
|
---|
| 786 | *
|
---|
| 787 | * @static
|
---|
| 788 | * @memberOf _
|
---|
| 789 | * @since 4.0.0
|
---|
| 790 | * @category Lang
|
---|
| 791 | * @param {*} value The value to check.
|
---|
| 792 | * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
|
---|
| 793 | * @example
|
---|
| 794 | *
|
---|
| 795 | * _.isObjectLike({});
|
---|
| 796 | * // => true
|
---|
| 797 | *
|
---|
| 798 | * _.isObjectLike([1, 2, 3]);
|
---|
| 799 | * // => true
|
---|
| 800 | *
|
---|
| 801 | * _.isObjectLike(_.noop);
|
---|
| 802 | * // => false
|
---|
| 803 | *
|
---|
| 804 | * _.isObjectLike(null);
|
---|
| 805 | * // => false
|
---|
| 806 | */
|
---|
| 807 | function isObjectLike(value) {
|
---|
| 808 | return !!value && typeof value == 'object';
|
---|
| 809 | }
|
---|
| 810 |
|
---|
| 811 | /**
|
---|
| 812 | * Checks if `value` is classified as a `Symbol` primitive or object.
|
---|
| 813 | *
|
---|
| 814 | * @static
|
---|
| 815 | * @memberOf _
|
---|
| 816 | * @since 4.0.0
|
---|
| 817 | * @category Lang
|
---|
| 818 | * @param {*} value The value to check.
|
---|
| 819 | * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
|
---|
| 820 | * @example
|
---|
| 821 | *
|
---|
| 822 | * _.isSymbol(Symbol.iterator);
|
---|
| 823 | * // => true
|
---|
| 824 | *
|
---|
| 825 | * _.isSymbol('abc');
|
---|
| 826 | * // => false
|
---|
| 827 | */
|
---|
| 828 | function isSymbol(value) {
|
---|
| 829 | return typeof value == 'symbol' ||
|
---|
| 830 | (isObjectLike(value) && objectToString.call(value) == symbolTag);
|
---|
| 831 | }
|
---|
| 832 |
|
---|
| 833 | /**
|
---|
| 834 | * Converts `value` to a string. An empty string is returned for `null`
|
---|
| 835 | * and `undefined` values. The sign of `-0` is preserved.
|
---|
| 836 | *
|
---|
| 837 | * @static
|
---|
| 838 | * @memberOf _
|
---|
| 839 | * @since 4.0.0
|
---|
| 840 | * @category Lang
|
---|
| 841 | * @param {*} value The value to process.
|
---|
| 842 | * @returns {string} Returns the string.
|
---|
| 843 | * @example
|
---|
| 844 | *
|
---|
| 845 | * _.toString(null);
|
---|
| 846 | * // => ''
|
---|
| 847 | *
|
---|
| 848 | * _.toString(-0);
|
---|
| 849 | * // => '-0'
|
---|
| 850 | *
|
---|
| 851 | * _.toString([1, 2, 3]);
|
---|
| 852 | * // => '1,2,3'
|
---|
| 853 | */
|
---|
| 854 | function toString(value) {
|
---|
| 855 | return value == null ? '' : baseToString(value);
|
---|
| 856 | }
|
---|
| 857 |
|
---|
| 858 | /**
|
---|
| 859 | * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
|
---|
| 860 | *
|
---|
| 861 | * @static
|
---|
| 862 | * @memberOf _
|
---|
| 863 | * @since 3.0.0
|
---|
| 864 | * @category String
|
---|
| 865 | * @param {string} [string=''] The string to convert.
|
---|
| 866 | * @returns {string} Returns the camel cased string.
|
---|
| 867 | * @example
|
---|
| 868 | *
|
---|
| 869 | * _.camelCase('Foo Bar');
|
---|
| 870 | * // => 'fooBar'
|
---|
| 871 | *
|
---|
| 872 | * _.camelCase('--foo-bar--');
|
---|
| 873 | * // => 'fooBar'
|
---|
| 874 | *
|
---|
| 875 | * _.camelCase('__FOO_BAR__');
|
---|
| 876 | * // => 'fooBar'
|
---|
| 877 | */
|
---|
| 878 | var camelCase = createCompounder(function(result, word, index) {
|
---|
| 879 | word = word.toLowerCase();
|
---|
| 880 | return result + (index ? capitalize(word) : word);
|
---|
| 881 | });
|
---|
| 882 |
|
---|
| 883 | /**
|
---|
| 884 | * Converts the first character of `string` to upper case and the remaining
|
---|
| 885 | * to lower case.
|
---|
| 886 | *
|
---|
| 887 | * @static
|
---|
| 888 | * @memberOf _
|
---|
| 889 | * @since 3.0.0
|
---|
| 890 | * @category String
|
---|
| 891 | * @param {string} [string=''] The string to capitalize.
|
---|
| 892 | * @returns {string} Returns the capitalized string.
|
---|
| 893 | * @example
|
---|
| 894 | *
|
---|
| 895 | * _.capitalize('FRED');
|
---|
| 896 | * // => 'Fred'
|
---|
| 897 | */
|
---|
| 898 | function capitalize(string) {
|
---|
| 899 | return upperFirst(toString(string).toLowerCase());
|
---|
| 900 | }
|
---|
| 901 |
|
---|
| 902 | /**
|
---|
| 903 | * Deburrs `string` by converting
|
---|
| 904 | * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
|
---|
| 905 | * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
|
---|
| 906 | * letters to basic Latin letters and removing
|
---|
| 907 | * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
|
---|
| 908 | *
|
---|
| 909 | * @static
|
---|
| 910 | * @memberOf _
|
---|
| 911 | * @since 3.0.0
|
---|
| 912 | * @category String
|
---|
| 913 | * @param {string} [string=''] The string to deburr.
|
---|
| 914 | * @returns {string} Returns the deburred string.
|
---|
| 915 | * @example
|
---|
| 916 | *
|
---|
| 917 | * _.deburr('déjà vu');
|
---|
| 918 | * // => 'deja vu'
|
---|
| 919 | */
|
---|
| 920 | function deburr(string) {
|
---|
| 921 | string = toString(string);
|
---|
| 922 | return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
|
---|
| 923 | }
|
---|
| 924 |
|
---|
| 925 | /**
|
---|
| 926 | * Converts the first character of `string` to upper case.
|
---|
| 927 | *
|
---|
| 928 | * @static
|
---|
| 929 | * @memberOf _
|
---|
| 930 | * @since 4.0.0
|
---|
| 931 | * @category String
|
---|
| 932 | * @param {string} [string=''] The string to convert.
|
---|
| 933 | * @returns {string} Returns the converted string.
|
---|
| 934 | * @example
|
---|
| 935 | *
|
---|
| 936 | * _.upperFirst('fred');
|
---|
| 937 | * // => 'Fred'
|
---|
| 938 | *
|
---|
| 939 | * _.upperFirst('FRED');
|
---|
| 940 | * // => 'FRED'
|
---|
| 941 | */
|
---|
| 942 | var upperFirst = createCaseFirst('toUpperCase');
|
---|
| 943 |
|
---|
| 944 | /**
|
---|
| 945 | * Splits `string` into an array of its words.
|
---|
| 946 | *
|
---|
| 947 | * @static
|
---|
| 948 | * @memberOf _
|
---|
| 949 | * @since 3.0.0
|
---|
| 950 | * @category String
|
---|
| 951 | * @param {string} [string=''] The string to inspect.
|
---|
| 952 | * @param {RegExp|string} [pattern] The pattern to match words.
|
---|
| 953 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
---|
| 954 | * @returns {Array} Returns the words of `string`.
|
---|
| 955 | * @example
|
---|
| 956 | *
|
---|
| 957 | * _.words('fred, barney, & pebbles');
|
---|
| 958 | * // => ['fred', 'barney', 'pebbles']
|
---|
| 959 | *
|
---|
| 960 | * _.words('fred, barney, & pebbles', /[^, ]+/g);
|
---|
| 961 | * // => ['fred', 'barney', '&', 'pebbles']
|
---|
| 962 | */
|
---|
| 963 | function words(string, pattern, guard) {
|
---|
| 964 | string = toString(string);
|
---|
| 965 | pattern = pattern;
|
---|
| 966 |
|
---|
| 967 | if (pattern === undefined) {
|
---|
| 968 | return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
|
---|
| 969 | }
|
---|
| 970 | return string.match(pattern) || [];
|
---|
| 971 | }
|
---|
| 972 |
|
---|
| 973 | var lodash_camelcase = camelCase;
|
---|
| 974 |
|
---|
| 975 | Object.defineProperty(localsConvention, "__esModule", {
|
---|
| 976 | value: true
|
---|
| 977 | });
|
---|
| 978 | localsConvention.makeLocalsConventionReducer = makeLocalsConventionReducer;
|
---|
| 979 |
|
---|
| 980 | var _lodash = _interopRequireDefault$5(lodash_camelcase);
|
---|
| 981 |
|
---|
| 982 | function _interopRequireDefault$5(obj) { return obj.__esModule ? obj : { default: obj }; }
|
---|
| 983 |
|
---|
| 984 | function dashesCamelCase(string) {
|
---|
| 985 | return string.replace(/-+(\w)/g, (_, firstLetter) => firstLetter.toUpperCase());
|
---|
| 986 | }
|
---|
| 987 |
|
---|
| 988 | function makeLocalsConventionReducer(localsConvention, inputFile) {
|
---|
| 989 | const isFunc = typeof localsConvention === "function";
|
---|
| 990 | return (tokens, [className, value]) => {
|
---|
| 991 | if (isFunc) {
|
---|
| 992 | const convention = localsConvention(className, value, inputFile);
|
---|
| 993 | tokens[convention] = value;
|
---|
| 994 | return tokens;
|
---|
| 995 | }
|
---|
| 996 |
|
---|
| 997 | switch (localsConvention) {
|
---|
| 998 | case "camelCase":
|
---|
| 999 | tokens[className] = value;
|
---|
| 1000 | tokens[(0, _lodash.default)(className)] = value;
|
---|
| 1001 | break;
|
---|
| 1002 |
|
---|
| 1003 | case "camelCaseOnly":
|
---|
| 1004 | tokens[(0, _lodash.default)(className)] = value;
|
---|
| 1005 | break;
|
---|
| 1006 |
|
---|
| 1007 | case "dashes":
|
---|
| 1008 | tokens[className] = value;
|
---|
| 1009 | tokens[dashesCamelCase(className)] = value;
|
---|
| 1010 | break;
|
---|
| 1011 |
|
---|
| 1012 | case "dashesOnly":
|
---|
| 1013 | tokens[dashesCamelCase(className)] = value;
|
---|
| 1014 | break;
|
---|
| 1015 | }
|
---|
| 1016 |
|
---|
| 1017 | return tokens;
|
---|
| 1018 | };
|
---|
| 1019 | }
|
---|
| 1020 |
|
---|
| 1021 | var FileSystemLoader$1 = {};
|
---|
| 1022 |
|
---|
| 1023 | Object.defineProperty(FileSystemLoader$1, "__esModule", {
|
---|
| 1024 | value: true
|
---|
| 1025 | });
|
---|
| 1026 | FileSystemLoader$1.default = undefined;
|
---|
| 1027 |
|
---|
| 1028 | var _postcss$1 = _interopRequireDefault$4(require$$0);
|
---|
| 1029 |
|
---|
| 1030 | var _path = _interopRequireDefault$4(require$$0$1);
|
---|
| 1031 |
|
---|
| 1032 | var _Parser$1 = _interopRequireDefault$4(Parser$1);
|
---|
| 1033 |
|
---|
| 1034 | var _fs$1 = fs;
|
---|
| 1035 |
|
---|
| 1036 | function _interopRequireDefault$4(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
---|
| 1037 |
|
---|
| 1038 | // Initially copied from https://github.com/css-modules/css-modules-loader-core
|
---|
| 1039 | class Core {
|
---|
| 1040 | constructor(plugins) {
|
---|
| 1041 | this.plugins = plugins || Core.defaultPlugins;
|
---|
| 1042 | }
|
---|
| 1043 |
|
---|
| 1044 | async load(sourceString, sourcePath, trace, pathFetcher) {
|
---|
| 1045 | const parser = new _Parser$1.default(pathFetcher, trace);
|
---|
| 1046 | const plugins = this.plugins.concat([parser.plugin()]);
|
---|
| 1047 | const result = await (0, _postcss$1.default)(plugins).process(sourceString, {
|
---|
| 1048 | from: sourcePath
|
---|
| 1049 | });
|
---|
| 1050 | return {
|
---|
| 1051 | injectableSource: result.css,
|
---|
| 1052 | exportTokens: parser.exportTokens
|
---|
| 1053 | };
|
---|
| 1054 | }
|
---|
| 1055 |
|
---|
| 1056 | } // Sorts dependencies in the following way:
|
---|
| 1057 | // AAA comes before AA and A
|
---|
| 1058 | // AB comes after AA and before A
|
---|
| 1059 | // All Bs come after all As
|
---|
| 1060 | // This ensures that the files are always returned in the following order:
|
---|
| 1061 | // - In the order they were required, except
|
---|
| 1062 | // - After all their dependencies
|
---|
| 1063 |
|
---|
| 1064 |
|
---|
| 1065 | const traceKeySorter = (a, b) => {
|
---|
| 1066 | if (a.length < b.length) {
|
---|
| 1067 | return a < b.substring(0, a.length) ? -1 : 1;
|
---|
| 1068 | }
|
---|
| 1069 |
|
---|
| 1070 | if (a.length > b.length) {
|
---|
| 1071 | return a.substring(0, b.length) <= b ? -1 : 1;
|
---|
| 1072 | }
|
---|
| 1073 |
|
---|
| 1074 | return a < b ? -1 : 1;
|
---|
| 1075 | };
|
---|
| 1076 |
|
---|
| 1077 | class FileSystemLoader {
|
---|
| 1078 | constructor(root, plugins, fileResolve) {
|
---|
| 1079 | if (root === "/" && process.platform === "win32") {
|
---|
| 1080 | const cwdDrive = process.cwd().slice(0, 3);
|
---|
| 1081 |
|
---|
| 1082 | if (!/^[A-Za-z]:\\$/.test(cwdDrive)) {
|
---|
| 1083 | throw new Error(`Failed to obtain root from "${process.cwd()}".`);
|
---|
| 1084 | }
|
---|
| 1085 |
|
---|
| 1086 | root = cwdDrive;
|
---|
| 1087 | }
|
---|
| 1088 |
|
---|
| 1089 | this.root = root;
|
---|
| 1090 | this.fileResolve = fileResolve;
|
---|
| 1091 | this.sources = {};
|
---|
| 1092 | this.traces = {};
|
---|
| 1093 | this.importNr = 0;
|
---|
| 1094 | this.core = new Core(plugins);
|
---|
| 1095 | this.tokensByFile = {};
|
---|
| 1096 | this.fs = (0, _fs$1.getFileSystem)();
|
---|
| 1097 | }
|
---|
| 1098 |
|
---|
| 1099 | async fetch(_newPath, relativeTo, _trace) {
|
---|
| 1100 | const newPath = _newPath.replace(/^["']|["']$/g, "");
|
---|
| 1101 |
|
---|
| 1102 | const trace = _trace || String.fromCharCode(this.importNr++);
|
---|
| 1103 |
|
---|
| 1104 | const useFileResolve = typeof this.fileResolve === "function";
|
---|
| 1105 | const fileResolvedPath = useFileResolve ? await this.fileResolve(newPath, relativeTo) : await Promise.resolve();
|
---|
| 1106 |
|
---|
| 1107 | if (fileResolvedPath && !_path.default.isAbsolute(fileResolvedPath)) {
|
---|
| 1108 | throw new Error('The returned path from the "fileResolve" option must be absolute.');
|
---|
| 1109 | }
|
---|
| 1110 |
|
---|
| 1111 | const relativeDir = _path.default.dirname(relativeTo);
|
---|
| 1112 |
|
---|
| 1113 | const rootRelativePath = fileResolvedPath || _path.default.resolve(relativeDir, newPath);
|
---|
| 1114 |
|
---|
| 1115 | let fileRelativePath = fileResolvedPath || _path.default.resolve(_path.default.resolve(this.root, relativeDir), newPath); // if the path is not relative or absolute, try to resolve it in node_modules
|
---|
| 1116 |
|
---|
| 1117 |
|
---|
| 1118 | if (!useFileResolve && newPath[0] !== "." && !_path.default.isAbsolute(newPath)) {
|
---|
| 1119 | try {
|
---|
| 1120 | fileRelativePath = require.resolve(newPath);
|
---|
| 1121 | } catch (e) {// noop
|
---|
| 1122 | }
|
---|
| 1123 | }
|
---|
| 1124 |
|
---|
| 1125 | const tokens = this.tokensByFile[fileRelativePath];
|
---|
| 1126 | if (tokens) return tokens;
|
---|
| 1127 | return new Promise((resolve, reject) => {
|
---|
| 1128 | this.fs.readFile(fileRelativePath, "utf-8", async (err, source) => {
|
---|
| 1129 | if (err) reject(err);
|
---|
| 1130 | const {
|
---|
| 1131 | injectableSource,
|
---|
| 1132 | exportTokens
|
---|
| 1133 | } = await this.core.load(source, rootRelativePath, trace, this.fetch.bind(this));
|
---|
| 1134 | this.sources[fileRelativePath] = injectableSource;
|
---|
| 1135 | this.traces[trace] = fileRelativePath;
|
---|
| 1136 | this.tokensByFile[fileRelativePath] = exportTokens;
|
---|
| 1137 | resolve(exportTokens);
|
---|
| 1138 | });
|
---|
| 1139 | });
|
---|
| 1140 | }
|
---|
| 1141 |
|
---|
| 1142 | get finalSource() {
|
---|
| 1143 | const traces = this.traces;
|
---|
| 1144 | const sources = this.sources;
|
---|
| 1145 | let written = new Set();
|
---|
| 1146 | return Object.keys(traces).sort(traceKeySorter).map(key => {
|
---|
| 1147 | const filename = traces[key];
|
---|
| 1148 |
|
---|
| 1149 | if (written.has(filename)) {
|
---|
| 1150 | return null;
|
---|
| 1151 | }
|
---|
| 1152 |
|
---|
| 1153 | written.add(filename);
|
---|
| 1154 | return sources[filename];
|
---|
| 1155 | }).join("");
|
---|
| 1156 | }
|
---|
| 1157 |
|
---|
| 1158 | }
|
---|
| 1159 |
|
---|
| 1160 | FileSystemLoader$1.default = FileSystemLoader;
|
---|
| 1161 |
|
---|
| 1162 | var scoping = {};
|
---|
| 1163 |
|
---|
| 1164 | var src$3 = {exports: {}};
|
---|
| 1165 |
|
---|
| 1166 | const PERMANENT_MARKER = 2;
|
---|
| 1167 | const TEMPORARY_MARKER = 1;
|
---|
| 1168 |
|
---|
| 1169 | function createError(node, graph) {
|
---|
| 1170 | const er = new Error("Nondeterministic import's order");
|
---|
| 1171 |
|
---|
| 1172 | const related = graph[node];
|
---|
| 1173 | const relatedNode = related.find(
|
---|
| 1174 | (relatedNode) => graph[relatedNode].indexOf(node) > -1
|
---|
| 1175 | );
|
---|
| 1176 |
|
---|
| 1177 | er.nodes = [node, relatedNode];
|
---|
| 1178 |
|
---|
| 1179 | return er;
|
---|
| 1180 | }
|
---|
| 1181 |
|
---|
| 1182 | function walkGraph(node, graph, state, result, strict) {
|
---|
| 1183 | if (state[node] === PERMANENT_MARKER) {
|
---|
| 1184 | return;
|
---|
| 1185 | }
|
---|
| 1186 |
|
---|
| 1187 | if (state[node] === TEMPORARY_MARKER) {
|
---|
| 1188 | if (strict) {
|
---|
| 1189 | return createError(node, graph);
|
---|
| 1190 | }
|
---|
| 1191 |
|
---|
| 1192 | return;
|
---|
| 1193 | }
|
---|
| 1194 |
|
---|
| 1195 | state[node] = TEMPORARY_MARKER;
|
---|
| 1196 |
|
---|
| 1197 | const children = graph[node];
|
---|
| 1198 | const length = children.length;
|
---|
| 1199 |
|
---|
| 1200 | for (let i = 0; i < length; ++i) {
|
---|
| 1201 | const error = walkGraph(children[i], graph, state, result, strict);
|
---|
| 1202 |
|
---|
| 1203 | if (error instanceof Error) {
|
---|
| 1204 | return error;
|
---|
| 1205 | }
|
---|
| 1206 | }
|
---|
| 1207 |
|
---|
| 1208 | state[node] = PERMANENT_MARKER;
|
---|
| 1209 |
|
---|
| 1210 | result.push(node);
|
---|
| 1211 | }
|
---|
| 1212 |
|
---|
| 1213 | function topologicalSort$1(graph, strict) {
|
---|
| 1214 | const result = [];
|
---|
| 1215 | const state = {};
|
---|
| 1216 |
|
---|
| 1217 | const nodes = Object.keys(graph);
|
---|
| 1218 | const length = nodes.length;
|
---|
| 1219 |
|
---|
| 1220 | for (let i = 0; i < length; ++i) {
|
---|
| 1221 | const er = walkGraph(nodes[i], graph, state, result, strict);
|
---|
| 1222 |
|
---|
| 1223 | if (er instanceof Error) {
|
---|
| 1224 | return er;
|
---|
| 1225 | }
|
---|
| 1226 | }
|
---|
| 1227 |
|
---|
| 1228 | return result;
|
---|
| 1229 | }
|
---|
| 1230 |
|
---|
| 1231 | var topologicalSort_1 = topologicalSort$1;
|
---|
| 1232 |
|
---|
| 1233 | const topologicalSort = topologicalSort_1;
|
---|
| 1234 |
|
---|
| 1235 | const matchImports$1 = /^(.+?)\s+from\s+(?:"([^"]+)"|'([^']+)'|(global))$/;
|
---|
| 1236 | const icssImport = /^:import\((?:"([^"]+)"|'([^']+)')\)/;
|
---|
| 1237 |
|
---|
| 1238 | const VISITED_MARKER = 1;
|
---|
| 1239 |
|
---|
| 1240 | /**
|
---|
| 1241 | * :import('G') {}
|
---|
| 1242 | *
|
---|
| 1243 | * Rule
|
---|
| 1244 | * composes: ... from 'A'
|
---|
| 1245 | * composes: ... from 'B'
|
---|
| 1246 |
|
---|
| 1247 | * Rule
|
---|
| 1248 | * composes: ... from 'A'
|
---|
| 1249 | * composes: ... from 'A'
|
---|
| 1250 | * composes: ... from 'C'
|
---|
| 1251 | *
|
---|
| 1252 | * Results in:
|
---|
| 1253 | *
|
---|
| 1254 | * graph: {
|
---|
| 1255 | * G: [],
|
---|
| 1256 | * A: [],
|
---|
| 1257 | * B: ['A'],
|
---|
| 1258 | * C: ['A'],
|
---|
| 1259 | * }
|
---|
| 1260 | */
|
---|
| 1261 | function addImportToGraph(importId, parentId, graph, visited) {
|
---|
| 1262 | const siblingsId = parentId + "_" + "siblings";
|
---|
| 1263 | const visitedId = parentId + "_" + importId;
|
---|
| 1264 |
|
---|
| 1265 | if (visited[visitedId] !== VISITED_MARKER) {
|
---|
| 1266 | if (!Array.isArray(visited[siblingsId])) {
|
---|
| 1267 | visited[siblingsId] = [];
|
---|
| 1268 | }
|
---|
| 1269 |
|
---|
| 1270 | const siblings = visited[siblingsId];
|
---|
| 1271 |
|
---|
| 1272 | if (Array.isArray(graph[importId])) {
|
---|
| 1273 | graph[importId] = graph[importId].concat(siblings);
|
---|
| 1274 | } else {
|
---|
| 1275 | graph[importId] = siblings.slice();
|
---|
| 1276 | }
|
---|
| 1277 |
|
---|
| 1278 | visited[visitedId] = VISITED_MARKER;
|
---|
| 1279 |
|
---|
| 1280 | siblings.push(importId);
|
---|
| 1281 | }
|
---|
| 1282 | }
|
---|
| 1283 |
|
---|
| 1284 | src$3.exports = (options = {}) => {
|
---|
| 1285 | let importIndex = 0;
|
---|
| 1286 | const createImportedName =
|
---|
| 1287 | typeof options.createImportedName !== "function"
|
---|
| 1288 | ? (importName /*, path*/) =>
|
---|
| 1289 | `i__imported_${importName.replace(/\W/g, "_")}_${importIndex++}`
|
---|
| 1290 | : options.createImportedName;
|
---|
| 1291 | const failOnWrongOrder = options.failOnWrongOrder;
|
---|
| 1292 |
|
---|
| 1293 | return {
|
---|
| 1294 | postcssPlugin: "postcss-modules-extract-imports",
|
---|
| 1295 | prepare() {
|
---|
| 1296 | const graph = {};
|
---|
| 1297 | const visited = {};
|
---|
| 1298 | const existingImports = {};
|
---|
| 1299 | const importDecls = {};
|
---|
| 1300 | const imports = {};
|
---|
| 1301 |
|
---|
| 1302 | return {
|
---|
| 1303 | Once(root, postcss) {
|
---|
| 1304 | // Check the existing imports order and save refs
|
---|
| 1305 | root.walkRules((rule) => {
|
---|
| 1306 | const matches = icssImport.exec(rule.selector);
|
---|
| 1307 |
|
---|
| 1308 | if (matches) {
|
---|
| 1309 | const [, /*match*/ doubleQuotePath, singleQuotePath] = matches;
|
---|
| 1310 | const importPath = doubleQuotePath || singleQuotePath;
|
---|
| 1311 |
|
---|
| 1312 | addImportToGraph(importPath, "root", graph, visited);
|
---|
| 1313 |
|
---|
| 1314 | existingImports[importPath] = rule;
|
---|
| 1315 | }
|
---|
| 1316 | });
|
---|
| 1317 |
|
---|
| 1318 | root.walkDecls(/^composes$/, (declaration) => {
|
---|
| 1319 | const multiple = declaration.value.split(",");
|
---|
| 1320 | const values = [];
|
---|
| 1321 |
|
---|
| 1322 | multiple.forEach((value) => {
|
---|
| 1323 | const matches = value.trim().match(matchImports$1);
|
---|
| 1324 |
|
---|
| 1325 | if (!matches) {
|
---|
| 1326 | values.push(value);
|
---|
| 1327 |
|
---|
| 1328 | return;
|
---|
| 1329 | }
|
---|
| 1330 |
|
---|
| 1331 | let tmpSymbols;
|
---|
| 1332 | let [
|
---|
| 1333 | ,
|
---|
| 1334 | /*match*/ symbols,
|
---|
| 1335 | doubleQuotePath,
|
---|
| 1336 | singleQuotePath,
|
---|
| 1337 | global,
|
---|
| 1338 | ] = matches;
|
---|
| 1339 |
|
---|
| 1340 | if (global) {
|
---|
| 1341 | // Composing globals simply means changing these classes to wrap them in global(name)
|
---|
| 1342 | tmpSymbols = symbols.split(/\s+/).map((s) => `global(${s})`);
|
---|
| 1343 | } else {
|
---|
| 1344 | const importPath = doubleQuotePath || singleQuotePath;
|
---|
| 1345 |
|
---|
| 1346 | let parent = declaration.parent;
|
---|
| 1347 | let parentIndexes = "";
|
---|
| 1348 |
|
---|
| 1349 | while (parent.type !== "root") {
|
---|
| 1350 | parentIndexes =
|
---|
| 1351 | parent.parent.index(parent) + "_" + parentIndexes;
|
---|
| 1352 | parent = parent.parent;
|
---|
| 1353 | }
|
---|
| 1354 |
|
---|
| 1355 | const { selector } = declaration.parent;
|
---|
| 1356 | const parentRule = `_${parentIndexes}${selector}`;
|
---|
| 1357 |
|
---|
| 1358 | addImportToGraph(importPath, parentRule, graph, visited);
|
---|
| 1359 |
|
---|
| 1360 | importDecls[importPath] = declaration;
|
---|
| 1361 | imports[importPath] = imports[importPath] || {};
|
---|
| 1362 |
|
---|
| 1363 | tmpSymbols = symbols.split(/\s+/).map((s) => {
|
---|
| 1364 | if (!imports[importPath][s]) {
|
---|
| 1365 | imports[importPath][s] = createImportedName(s, importPath);
|
---|
| 1366 | }
|
---|
| 1367 |
|
---|
| 1368 | return imports[importPath][s];
|
---|
| 1369 | });
|
---|
| 1370 | }
|
---|
| 1371 |
|
---|
| 1372 | values.push(tmpSymbols.join(" "));
|
---|
| 1373 | });
|
---|
| 1374 |
|
---|
| 1375 | declaration.value = values.join(", ");
|
---|
| 1376 | });
|
---|
| 1377 |
|
---|
| 1378 | const importsOrder = topologicalSort(graph, failOnWrongOrder);
|
---|
| 1379 |
|
---|
| 1380 | if (importsOrder instanceof Error) {
|
---|
| 1381 | const importPath = importsOrder.nodes.find((importPath) =>
|
---|
| 1382 | // eslint-disable-next-line no-prototype-builtins
|
---|
| 1383 | importDecls.hasOwnProperty(importPath)
|
---|
| 1384 | );
|
---|
| 1385 | const decl = importDecls[importPath];
|
---|
| 1386 |
|
---|
| 1387 | throw decl.error(
|
---|
| 1388 | "Failed to resolve order of composed modules " +
|
---|
| 1389 | importsOrder.nodes
|
---|
| 1390 | .map((importPath) => "`" + importPath + "`")
|
---|
| 1391 | .join(", ") +
|
---|
| 1392 | ".",
|
---|
| 1393 | {
|
---|
| 1394 | plugin: "postcss-modules-extract-imports",
|
---|
| 1395 | word: "composes",
|
---|
| 1396 | }
|
---|
| 1397 | );
|
---|
| 1398 | }
|
---|
| 1399 |
|
---|
| 1400 | let lastImportRule;
|
---|
| 1401 |
|
---|
| 1402 | importsOrder.forEach((path) => {
|
---|
| 1403 | const importedSymbols = imports[path];
|
---|
| 1404 | let rule = existingImports[path];
|
---|
| 1405 |
|
---|
| 1406 | if (!rule && importedSymbols) {
|
---|
| 1407 | rule = postcss.rule({
|
---|
| 1408 | selector: `:import("${path}")`,
|
---|
| 1409 | raws: { after: "\n" },
|
---|
| 1410 | });
|
---|
| 1411 |
|
---|
| 1412 | if (lastImportRule) {
|
---|
| 1413 | root.insertAfter(lastImportRule, rule);
|
---|
| 1414 | } else {
|
---|
| 1415 | root.prepend(rule);
|
---|
| 1416 | }
|
---|
| 1417 | }
|
---|
| 1418 |
|
---|
| 1419 | lastImportRule = rule;
|
---|
| 1420 |
|
---|
| 1421 | if (!importedSymbols) {
|
---|
| 1422 | return;
|
---|
| 1423 | }
|
---|
| 1424 |
|
---|
| 1425 | Object.keys(importedSymbols).forEach((importedSymbol) => {
|
---|
| 1426 | rule.append(
|
---|
| 1427 | postcss.decl({
|
---|
| 1428 | value: importedSymbol,
|
---|
| 1429 | prop: importedSymbols[importedSymbol],
|
---|
| 1430 | raws: { before: "\n " },
|
---|
| 1431 | })
|
---|
| 1432 | );
|
---|
| 1433 | });
|
---|
| 1434 | });
|
---|
| 1435 | },
|
---|
| 1436 | };
|
---|
| 1437 | },
|
---|
| 1438 | };
|
---|
| 1439 | };
|
---|
| 1440 |
|
---|
| 1441 | src$3.exports.postcss = true;
|
---|
| 1442 |
|
---|
| 1443 | var srcExports$2 = src$3.exports;
|
---|
| 1444 |
|
---|
| 1445 | var wasmHash = {exports: {}};
|
---|
| 1446 |
|
---|
| 1447 | /*
|
---|
| 1448 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
| 1449 | Author Tobias Koppers @sokra
|
---|
| 1450 | */
|
---|
| 1451 |
|
---|
| 1452 | var hasRequiredWasmHash;
|
---|
| 1453 |
|
---|
| 1454 | function requireWasmHash () {
|
---|
| 1455 | if (hasRequiredWasmHash) return wasmHash.exports;
|
---|
| 1456 | hasRequiredWasmHash = 1;
|
---|
| 1457 |
|
---|
| 1458 | // 65536 is the size of a wasm memory page
|
---|
| 1459 | // 64 is the maximum chunk size for every possible wasm hash implementation
|
---|
| 1460 | // 4 is the maximum number of bytes per char for string encoding (max is utf-8)
|
---|
| 1461 | // ~3 makes sure that it's always a block of 4 chars, so avoid partially encoded bytes for base64
|
---|
| 1462 | const MAX_SHORT_STRING = Math.floor((65536 - 64) / 4) & -4;
|
---|
| 1463 |
|
---|
| 1464 | class WasmHash {
|
---|
| 1465 | /**
|
---|
| 1466 | * @param {WebAssembly.Instance} instance wasm instance
|
---|
| 1467 | * @param {WebAssembly.Instance[]} instancesPool pool of instances
|
---|
| 1468 | * @param {number} chunkSize size of data chunks passed to wasm
|
---|
| 1469 | * @param {number} digestSize size of digest returned by wasm
|
---|
| 1470 | */
|
---|
| 1471 | constructor(instance, instancesPool, chunkSize, digestSize) {
|
---|
| 1472 | const exports = /** @type {any} */ (instance.exports);
|
---|
| 1473 |
|
---|
| 1474 | exports.init();
|
---|
| 1475 |
|
---|
| 1476 | this.exports = exports;
|
---|
| 1477 | this.mem = Buffer.from(exports.memory.buffer, 0, 65536);
|
---|
| 1478 | this.buffered = 0;
|
---|
| 1479 | this.instancesPool = instancesPool;
|
---|
| 1480 | this.chunkSize = chunkSize;
|
---|
| 1481 | this.digestSize = digestSize;
|
---|
| 1482 | }
|
---|
| 1483 |
|
---|
| 1484 | reset() {
|
---|
| 1485 | this.buffered = 0;
|
---|
| 1486 | this.exports.init();
|
---|
| 1487 | }
|
---|
| 1488 |
|
---|
| 1489 | /**
|
---|
| 1490 | * @param {Buffer | string} data data
|
---|
| 1491 | * @param {BufferEncoding=} encoding encoding
|
---|
| 1492 | * @returns {this} itself
|
---|
| 1493 | */
|
---|
| 1494 | update(data, encoding) {
|
---|
| 1495 | if (typeof data === "string") {
|
---|
| 1496 | while (data.length > MAX_SHORT_STRING) {
|
---|
| 1497 | this._updateWithShortString(data.slice(0, MAX_SHORT_STRING), encoding);
|
---|
| 1498 | data = data.slice(MAX_SHORT_STRING);
|
---|
| 1499 | }
|
---|
| 1500 |
|
---|
| 1501 | this._updateWithShortString(data, encoding);
|
---|
| 1502 |
|
---|
| 1503 | return this;
|
---|
| 1504 | }
|
---|
| 1505 |
|
---|
| 1506 | this._updateWithBuffer(data);
|
---|
| 1507 |
|
---|
| 1508 | return this;
|
---|
| 1509 | }
|
---|
| 1510 |
|
---|
| 1511 | /**
|
---|
| 1512 | * @param {string} data data
|
---|
| 1513 | * @param {BufferEncoding=} encoding encoding
|
---|
| 1514 | * @returns {void}
|
---|
| 1515 | */
|
---|
| 1516 | _updateWithShortString(data, encoding) {
|
---|
| 1517 | const { exports, buffered, mem, chunkSize } = this;
|
---|
| 1518 |
|
---|
| 1519 | let endPos;
|
---|
| 1520 |
|
---|
| 1521 | if (data.length < 70) {
|
---|
| 1522 | if (!encoding || encoding === "utf-8" || encoding === "utf8") {
|
---|
| 1523 | endPos = buffered;
|
---|
| 1524 | for (let i = 0; i < data.length; i++) {
|
---|
| 1525 | const cc = data.charCodeAt(i);
|
---|
| 1526 |
|
---|
| 1527 | if (cc < 0x80) {
|
---|
| 1528 | mem[endPos++] = cc;
|
---|
| 1529 | } else if (cc < 0x800) {
|
---|
| 1530 | mem[endPos] = (cc >> 6) | 0xc0;
|
---|
| 1531 | mem[endPos + 1] = (cc & 0x3f) | 0x80;
|
---|
| 1532 | endPos += 2;
|
---|
| 1533 | } else {
|
---|
| 1534 | // bail-out for weird chars
|
---|
| 1535 | endPos += mem.write(data.slice(i), endPos, encoding);
|
---|
| 1536 | break;
|
---|
| 1537 | }
|
---|
| 1538 | }
|
---|
| 1539 | } else if (encoding === "latin1") {
|
---|
| 1540 | endPos = buffered;
|
---|
| 1541 |
|
---|
| 1542 | for (let i = 0; i < data.length; i++) {
|
---|
| 1543 | const cc = data.charCodeAt(i);
|
---|
| 1544 |
|
---|
| 1545 | mem[endPos++] = cc;
|
---|
| 1546 | }
|
---|
| 1547 | } else {
|
---|
| 1548 | endPos = buffered + mem.write(data, buffered, encoding);
|
---|
| 1549 | }
|
---|
| 1550 | } else {
|
---|
| 1551 | endPos = buffered + mem.write(data, buffered, encoding);
|
---|
| 1552 | }
|
---|
| 1553 |
|
---|
| 1554 | if (endPos < chunkSize) {
|
---|
| 1555 | this.buffered = endPos;
|
---|
| 1556 | } else {
|
---|
| 1557 | const l = endPos & ~(this.chunkSize - 1);
|
---|
| 1558 |
|
---|
| 1559 | exports.update(l);
|
---|
| 1560 |
|
---|
| 1561 | const newBuffered = endPos - l;
|
---|
| 1562 |
|
---|
| 1563 | this.buffered = newBuffered;
|
---|
| 1564 |
|
---|
| 1565 | if (newBuffered > 0) {
|
---|
| 1566 | mem.copyWithin(0, l, endPos);
|
---|
| 1567 | }
|
---|
| 1568 | }
|
---|
| 1569 | }
|
---|
| 1570 |
|
---|
| 1571 | /**
|
---|
| 1572 | * @param {Buffer} data data
|
---|
| 1573 | * @returns {void}
|
---|
| 1574 | */
|
---|
| 1575 | _updateWithBuffer(data) {
|
---|
| 1576 | const { exports, buffered, mem } = this;
|
---|
| 1577 | const length = data.length;
|
---|
| 1578 |
|
---|
| 1579 | if (buffered + length < this.chunkSize) {
|
---|
| 1580 | data.copy(mem, buffered, 0, length);
|
---|
| 1581 |
|
---|
| 1582 | this.buffered += length;
|
---|
| 1583 | } else {
|
---|
| 1584 | const l = (buffered + length) & ~(this.chunkSize - 1);
|
---|
| 1585 |
|
---|
| 1586 | if (l > 65536) {
|
---|
| 1587 | let i = 65536 - buffered;
|
---|
| 1588 |
|
---|
| 1589 | data.copy(mem, buffered, 0, i);
|
---|
| 1590 | exports.update(65536);
|
---|
| 1591 |
|
---|
| 1592 | const stop = l - buffered - 65536;
|
---|
| 1593 |
|
---|
| 1594 | while (i < stop) {
|
---|
| 1595 | data.copy(mem, 0, i, i + 65536);
|
---|
| 1596 | exports.update(65536);
|
---|
| 1597 | i += 65536;
|
---|
| 1598 | }
|
---|
| 1599 |
|
---|
| 1600 | data.copy(mem, 0, i, l - buffered);
|
---|
| 1601 |
|
---|
| 1602 | exports.update(l - buffered - i);
|
---|
| 1603 | } else {
|
---|
| 1604 | data.copy(mem, buffered, 0, l - buffered);
|
---|
| 1605 |
|
---|
| 1606 | exports.update(l);
|
---|
| 1607 | }
|
---|
| 1608 |
|
---|
| 1609 | const newBuffered = length + buffered - l;
|
---|
| 1610 |
|
---|
| 1611 | this.buffered = newBuffered;
|
---|
| 1612 |
|
---|
| 1613 | if (newBuffered > 0) {
|
---|
| 1614 | data.copy(mem, 0, length - newBuffered, length);
|
---|
| 1615 | }
|
---|
| 1616 | }
|
---|
| 1617 | }
|
---|
| 1618 |
|
---|
| 1619 | digest(type) {
|
---|
| 1620 | const { exports, buffered, mem, digestSize } = this;
|
---|
| 1621 |
|
---|
| 1622 | exports.final(buffered);
|
---|
| 1623 |
|
---|
| 1624 | this.instancesPool.push(this);
|
---|
| 1625 |
|
---|
| 1626 | const hex = mem.toString("latin1", 0, digestSize);
|
---|
| 1627 |
|
---|
| 1628 | if (type === "hex") {
|
---|
| 1629 | return hex;
|
---|
| 1630 | }
|
---|
| 1631 |
|
---|
| 1632 | if (type === "binary" || !type) {
|
---|
| 1633 | return Buffer.from(hex, "hex");
|
---|
| 1634 | }
|
---|
| 1635 |
|
---|
| 1636 | return Buffer.from(hex, "hex").toString(type);
|
---|
| 1637 | }
|
---|
| 1638 | }
|
---|
| 1639 |
|
---|
| 1640 | const create = (wasmModule, instancesPool, chunkSize, digestSize) => {
|
---|
| 1641 | if (instancesPool.length > 0) {
|
---|
| 1642 | const old = instancesPool.pop();
|
---|
| 1643 |
|
---|
| 1644 | old.reset();
|
---|
| 1645 |
|
---|
| 1646 | return old;
|
---|
| 1647 | } else {
|
---|
| 1648 | return new WasmHash(
|
---|
| 1649 | new WebAssembly.Instance(wasmModule),
|
---|
| 1650 | instancesPool,
|
---|
| 1651 | chunkSize,
|
---|
| 1652 | digestSize
|
---|
| 1653 | );
|
---|
| 1654 | }
|
---|
| 1655 | };
|
---|
| 1656 |
|
---|
| 1657 | wasmHash.exports = create;
|
---|
| 1658 | wasmHash.exports.MAX_SHORT_STRING = MAX_SHORT_STRING;
|
---|
| 1659 | return wasmHash.exports;
|
---|
| 1660 | }
|
---|
| 1661 |
|
---|
| 1662 | /*
|
---|
| 1663 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
| 1664 | Author Tobias Koppers @sokra
|
---|
| 1665 | */
|
---|
| 1666 |
|
---|
| 1667 | var xxhash64_1;
|
---|
| 1668 | var hasRequiredXxhash64;
|
---|
| 1669 |
|
---|
| 1670 | function requireXxhash64 () {
|
---|
| 1671 | if (hasRequiredXxhash64) return xxhash64_1;
|
---|
| 1672 | hasRequiredXxhash64 = 1;
|
---|
| 1673 |
|
---|
| 1674 | const create = requireWasmHash();
|
---|
| 1675 |
|
---|
| 1676 | //#region wasm code: xxhash64 (../../../assembly/hash/xxhash64.asm.ts) --initialMemory 1
|
---|
| 1677 | const xxhash64 = new WebAssembly.Module(
|
---|
| 1678 | Buffer.from(
|
---|
| 1679 | // 1173 bytes
|
---|
| 1680 | "AGFzbQEAAAABCAJgAX8AYAAAAwQDAQAABQMBAAEGGgV+AUIAC34BQgALfgFCAAt+AUIAC34BQgALByIEBGluaXQAAAZ1cGRhdGUAAQVmaW5hbAACBm1lbW9yeQIACrUIAzAAQtbrgu7q/Yn14AAkAELP1tO+0ser2UIkAUIAJAJC+erQ0OfJoeThACQDQgAkBAvUAQIBfwR+IABFBEAPCyMEIACtfCQEIwAhAiMBIQMjAiEEIwMhBQNAIAIgASkDAELP1tO+0ser2UJ+fEIfiUKHla+vmLbem55/fiECIAMgASkDCELP1tO+0ser2UJ+fEIfiUKHla+vmLbem55/fiEDIAQgASkDEELP1tO+0ser2UJ+fEIfiUKHla+vmLbem55/fiEEIAUgASkDGELP1tO+0ser2UJ+fEIfiUKHla+vmLbem55/fiEFIAAgAUEgaiIBSw0ACyACJAAgAyQBIAQkAiAFJAMLqwYCAX8EfiMEQgBSBH4jACICQgGJIwEiA0IHiXwjAiIEQgyJfCMDIgVCEol8IAJCz9bTvtLHq9lCfkIfiUKHla+vmLbem55/foVCh5Wvr5i23puef35CnaO16oOxjYr6AH0gA0LP1tO+0ser2UJ+Qh+JQoeVr6+Ytt6bnn9+hUKHla+vmLbem55/fkKdo7Xqg7GNivoAfSAEQs/W077Sx6vZQn5CH4lCh5Wvr5i23puef36FQoeVr6+Ytt6bnn9+Qp2jteqDsY2K+gB9IAVCz9bTvtLHq9lCfkIfiUKHla+vmLbem55/foVCh5Wvr5i23puef35CnaO16oOxjYr6AH0FQsXP2bLx5brqJwsjBCAArXx8IQIDQCABQQhqIABNBEAgAiABKQMAQs/W077Sx6vZQn5CH4lCh5Wvr5i23puef36FQhuJQoeVr6+Ytt6bnn9+Qp2jteqDsY2K+gB9IQIgAUEIaiEBDAELCyABQQRqIABNBEACfyACIAE1AgBCh5Wvr5i23puef36FQheJQs/W077Sx6vZQn5C+fPd8Zn2masWfCECIAFBBGoLIQELA0AgACABRwRAIAIgATEAAELFz9my8eW66id+hUILiUKHla+vmLbem55/fiECIAFBAWohAQwBCwtBACACIAJCIYiFQs/W077Sx6vZQn4iAiACQh2IhUL5893xmfaZqxZ+IgIgAkIgiIUiAkIgiCIDQv//A4NCIIYgA0KAgPz/D4NCEIiEIgNC/4GAgPAfg0IQhiADQoD+g4CA4D+DQgiIhCIDQo+AvIDwgcAHg0IIhiADQvCBwIeAnoD4AINCBIiEIgNChoyYsODAgYMGfEIEiEKBgoSIkKDAgAGDQid+IANCsODAgYOGjJgwhHw3AwBBCCACQv////8PgyICQv//A4NCIIYgAkKAgPz/D4NCEIiEIgJC/4GAgPAfg0IQhiACQoD+g4CA4D+DQgiIhCICQo+AvIDwgcAHg0IIhiACQvCBwIeAnoD4AINCBIiEIgJChoyYsODAgYMGfEIEiEKBgoSIkKDAgAGDQid+IAJCsODAgYOGjJgwhHw3AwAL",
|
---|
| 1681 | "base64"
|
---|
| 1682 | )
|
---|
| 1683 | );
|
---|
| 1684 | //#endregion
|
---|
| 1685 |
|
---|
| 1686 | xxhash64_1 = create.bind(null, xxhash64, [], 32, 16);
|
---|
| 1687 | return xxhash64_1;
|
---|
| 1688 | }
|
---|
| 1689 |
|
---|
| 1690 | var BatchedHash_1;
|
---|
| 1691 | var hasRequiredBatchedHash;
|
---|
| 1692 |
|
---|
| 1693 | function requireBatchedHash () {
|
---|
| 1694 | if (hasRequiredBatchedHash) return BatchedHash_1;
|
---|
| 1695 | hasRequiredBatchedHash = 1;
|
---|
| 1696 | const MAX_SHORT_STRING = requireWasmHash().MAX_SHORT_STRING;
|
---|
| 1697 |
|
---|
| 1698 | class BatchedHash {
|
---|
| 1699 | constructor(hash) {
|
---|
| 1700 | this.string = undefined;
|
---|
| 1701 | this.encoding = undefined;
|
---|
| 1702 | this.hash = hash;
|
---|
| 1703 | }
|
---|
| 1704 |
|
---|
| 1705 | /**
|
---|
| 1706 | * Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
|
---|
| 1707 | * @param {string|Buffer} data data
|
---|
| 1708 | * @param {string=} inputEncoding data encoding
|
---|
| 1709 | * @returns {this} updated hash
|
---|
| 1710 | */
|
---|
| 1711 | update(data, inputEncoding) {
|
---|
| 1712 | if (this.string !== undefined) {
|
---|
| 1713 | if (
|
---|
| 1714 | typeof data === "string" &&
|
---|
| 1715 | inputEncoding === this.encoding &&
|
---|
| 1716 | this.string.length + data.length < MAX_SHORT_STRING
|
---|
| 1717 | ) {
|
---|
| 1718 | this.string += data;
|
---|
| 1719 |
|
---|
| 1720 | return this;
|
---|
| 1721 | }
|
---|
| 1722 |
|
---|
| 1723 | this.hash.update(this.string, this.encoding);
|
---|
| 1724 | this.string = undefined;
|
---|
| 1725 | }
|
---|
| 1726 |
|
---|
| 1727 | if (typeof data === "string") {
|
---|
| 1728 | if (
|
---|
| 1729 | data.length < MAX_SHORT_STRING &&
|
---|
| 1730 | // base64 encoding is not valid since it may contain padding chars
|
---|
| 1731 | (!inputEncoding || !inputEncoding.startsWith("ba"))
|
---|
| 1732 | ) {
|
---|
| 1733 | this.string = data;
|
---|
| 1734 | this.encoding = inputEncoding;
|
---|
| 1735 | } else {
|
---|
| 1736 | this.hash.update(data, inputEncoding);
|
---|
| 1737 | }
|
---|
| 1738 | } else {
|
---|
| 1739 | this.hash.update(data);
|
---|
| 1740 | }
|
---|
| 1741 |
|
---|
| 1742 | return this;
|
---|
| 1743 | }
|
---|
| 1744 |
|
---|
| 1745 | /**
|
---|
| 1746 | * Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
|
---|
| 1747 | * @param {string=} encoding encoding of the return value
|
---|
| 1748 | * @returns {string|Buffer} digest
|
---|
| 1749 | */
|
---|
| 1750 | digest(encoding) {
|
---|
| 1751 | if (this.string !== undefined) {
|
---|
| 1752 | this.hash.update(this.string, this.encoding);
|
---|
| 1753 | }
|
---|
| 1754 |
|
---|
| 1755 | return this.hash.digest(encoding);
|
---|
| 1756 | }
|
---|
| 1757 | }
|
---|
| 1758 |
|
---|
| 1759 | BatchedHash_1 = BatchedHash;
|
---|
| 1760 | return BatchedHash_1;
|
---|
| 1761 | }
|
---|
| 1762 |
|
---|
| 1763 | /*
|
---|
| 1764 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
| 1765 | Author Tobias Koppers @sokra
|
---|
| 1766 | */
|
---|
| 1767 |
|
---|
| 1768 | var md4_1;
|
---|
| 1769 | var hasRequiredMd4;
|
---|
| 1770 |
|
---|
| 1771 | function requireMd4 () {
|
---|
| 1772 | if (hasRequiredMd4) return md4_1;
|
---|
| 1773 | hasRequiredMd4 = 1;
|
---|
| 1774 |
|
---|
| 1775 | const create = requireWasmHash();
|
---|
| 1776 |
|
---|
| 1777 | //#region wasm code: md4 (../../../assembly/hash/md4.asm.ts) --initialMemory 1
|
---|
| 1778 | const md4 = new WebAssembly.Module(
|
---|
| 1779 | Buffer.from(
|
---|
| 1780 | // 2150 bytes
|
---|
| 1781 | "AGFzbQEAAAABCAJgAX8AYAAAAwUEAQAAAAUDAQABBhoFfwFBAAt/AUEAC38BQQALfwFBAAt/AUEACwciBARpbml0AAAGdXBkYXRlAAIFZmluYWwAAwZtZW1vcnkCAAqFEAQmAEGBxpS6BiQBQYnXtv5+JAJB/rnrxXkkA0H2qMmBASQEQQAkAAvMCgEYfyMBIQojAiEGIwMhByMEIQgDQCAAIAVLBEAgBSgCCCINIAcgBiAFKAIEIgsgCCAHIAUoAgAiDCAKIAggBiAHIAhzcXNqakEDdyIDIAYgB3Nxc2pqQQd3IgEgAyAGc3FzampBC3chAiAFKAIUIg8gASACIAUoAhAiCSADIAEgBSgCDCIOIAYgAyACIAEgA3Nxc2pqQRN3IgQgASACc3FzampBA3ciAyACIARzcXNqakEHdyEBIAUoAiAiEiADIAEgBSgCHCIRIAQgAyAFKAIYIhAgAiAEIAEgAyAEc3FzampBC3ciAiABIANzcXNqakETdyIEIAEgAnNxc2pqQQN3IQMgBSgCLCIVIAQgAyAFKAIoIhQgAiAEIAUoAiQiEyABIAIgAyACIARzcXNqakEHdyIBIAMgBHNxc2pqQQt3IgIgASADc3FzampBE3chBCAPIBAgCSAVIBQgEyAFKAI4IhYgAiAEIAUoAjQiFyABIAIgBSgCMCIYIAMgASAEIAEgAnNxc2pqQQN3IgEgAiAEc3FzampBB3ciAiABIARzcXNqakELdyIDIAkgAiAMIAEgBSgCPCIJIAQgASADIAEgAnNxc2pqQRN3IgEgAiADcnEgAiADcXJqakGZ84nUBWpBA3ciAiABIANycSABIANxcmpqQZnzidQFakEFdyIEIAEgAnJxIAEgAnFyaiASakGZ84nUBWpBCXciAyAPIAQgCyACIBggASADIAIgBHJxIAIgBHFyampBmfOJ1AVqQQ13IgEgAyAEcnEgAyAEcXJqakGZ84nUBWpBA3ciAiABIANycSABIANxcmpqQZnzidQFakEFdyIEIAEgAnJxIAEgAnFyampBmfOJ1AVqQQl3IgMgECAEIAIgFyABIAMgAiAEcnEgAiAEcXJqakGZ84nUBWpBDXciASADIARycSADIARxcmogDWpBmfOJ1AVqQQN3IgIgASADcnEgASADcXJqakGZ84nUBWpBBXciBCABIAJycSABIAJxcmpqQZnzidQFakEJdyIDIBEgBCAOIAIgFiABIAMgAiAEcnEgAiAEcXJqakGZ84nUBWpBDXciASADIARycSADIARxcmpqQZnzidQFakEDdyICIAEgA3JxIAEgA3FyampBmfOJ1AVqQQV3IgQgASACcnEgASACcXJqakGZ84nUBWpBCXciAyAMIAIgAyAJIAEgAyACIARycSACIARxcmpqQZnzidQFakENdyIBcyAEc2pqQaHX5/YGakEDdyICIAQgASACcyADc2ogEmpBodfn9gZqQQl3IgRzIAFzampBodfn9gZqQQt3IgMgAiADIBggASADIARzIAJzampBodfn9gZqQQ93IgFzIARzaiANakGh1+f2BmpBA3ciAiAUIAQgASACcyADc2pqQaHX5/YGakEJdyIEcyABc2pqQaHX5/YGakELdyIDIAsgAiADIBYgASADIARzIAJzampBodfn9gZqQQ93IgFzIARzampBodfn9gZqQQN3IgIgEyAEIAEgAnMgA3NqakGh1+f2BmpBCXciBHMgAXNqakGh1+f2BmpBC3chAyAKIA4gAiADIBcgASADIARzIAJzampBodfn9gZqQQ93IgFzIARzampBodfn9gZqQQN3IgJqIQogBiAJIAEgESADIAIgFSAEIAEgAnMgA3NqakGh1+f2BmpBCXciBHMgAXNqakGh1+f2BmpBC3ciAyAEcyACc2pqQaHX5/YGakEPd2ohBiADIAdqIQcgBCAIaiEIIAVBQGshBQwBCwsgCiQBIAYkAiAHJAMgCCQECw0AIAAQASMAIABqJAAL/wQCA38BfiMAIABqrUIDhiEEIABByABqQUBxIgJBCGshAyAAIgFBAWohACABQYABOgAAA0AgACACSUEAIABBB3EbBEAgAEEAOgAAIABBAWohAAwBCwsDQCAAIAJJBEAgAEIANwMAIABBCGohAAwBCwsgAyAENwMAIAIQAUEAIwGtIgRC//8DgyAEQoCA/P8Pg0IQhoQiBEL/gYCA8B+DIARCgP6DgIDgP4NCCIaEIgRCj4C8gPCBwAeDQgiGIARC8IHAh4CegPgAg0IEiIQiBEKGjJiw4MCBgwZ8QgSIQoGChIiQoMCAAYNCJ34gBEKw4MCBg4aMmDCEfDcDAEEIIwKtIgRC//8DgyAEQoCA/P8Pg0IQhoQiBEL/gYCA8B+DIARCgP6DgIDgP4NCCIaEIgRCj4C8gPCBwAeDQgiGIARC8IHAh4CegPgAg0IEiIQiBEKGjJiw4MCBgwZ8QgSIQoGChIiQoMCAAYNCJ34gBEKw4MCBg4aMmDCEfDcDAEEQIwOtIgRC//8DgyAEQoCA/P8Pg0IQhoQiBEL/gYCA8B+DIARCgP6DgIDgP4NCCIaEIgRCj4C8gPCBwAeDQgiGIARC8IHAh4CegPgAg0IEiIQiBEKGjJiw4MCBgwZ8QgSIQoGChIiQoMCAAYNCJ34gBEKw4MCBg4aMmDCEfDcDAEEYIwStIgRC//8DgyAEQoCA/P8Pg0IQhoQiBEL/gYCA8B+DIARCgP6DgIDgP4NCCIaEIgRCj4C8gPCBwAeDQgiGIARC8IHAh4CegPgAg0IEiIQiBEKGjJiw4MCBgwZ8QgSIQoGChIiQoMCAAYNCJ34gBEKw4MCBg4aMmDCEfDcDAAs=",
|
---|
| 1782 | "base64"
|
---|
| 1783 | )
|
---|
| 1784 | );
|
---|
| 1785 | //#endregion
|
---|
| 1786 |
|
---|
| 1787 | md4_1 = create.bind(null, md4, [], 64, 32);
|
---|
| 1788 | return md4_1;
|
---|
| 1789 | }
|
---|
| 1790 |
|
---|
| 1791 | var BulkUpdateDecorator_1;
|
---|
| 1792 | var hasRequiredBulkUpdateDecorator;
|
---|
| 1793 |
|
---|
| 1794 | function requireBulkUpdateDecorator () {
|
---|
| 1795 | if (hasRequiredBulkUpdateDecorator) return BulkUpdateDecorator_1;
|
---|
| 1796 | hasRequiredBulkUpdateDecorator = 1;
|
---|
| 1797 | const BULK_SIZE = 2000;
|
---|
| 1798 |
|
---|
| 1799 | // We are using an object instead of a Map as this will stay static during the runtime
|
---|
| 1800 | // so access to it can be optimized by v8
|
---|
| 1801 | const digestCaches = {};
|
---|
| 1802 |
|
---|
| 1803 | class BulkUpdateDecorator {
|
---|
| 1804 | /**
|
---|
| 1805 | * @param {Hash | function(): Hash} hashOrFactory function to create a hash
|
---|
| 1806 | * @param {string=} hashKey key for caching
|
---|
| 1807 | */
|
---|
| 1808 | constructor(hashOrFactory, hashKey) {
|
---|
| 1809 | this.hashKey = hashKey;
|
---|
| 1810 |
|
---|
| 1811 | if (typeof hashOrFactory === "function") {
|
---|
| 1812 | this.hashFactory = hashOrFactory;
|
---|
| 1813 | this.hash = undefined;
|
---|
| 1814 | } else {
|
---|
| 1815 | this.hashFactory = undefined;
|
---|
| 1816 | this.hash = hashOrFactory;
|
---|
| 1817 | }
|
---|
| 1818 |
|
---|
| 1819 | this.buffer = "";
|
---|
| 1820 | }
|
---|
| 1821 |
|
---|
| 1822 | /**
|
---|
| 1823 | * Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
|
---|
| 1824 | * @param {string|Buffer} data data
|
---|
| 1825 | * @param {string=} inputEncoding data encoding
|
---|
| 1826 | * @returns {this} updated hash
|
---|
| 1827 | */
|
---|
| 1828 | update(data, inputEncoding) {
|
---|
| 1829 | if (
|
---|
| 1830 | inputEncoding !== undefined ||
|
---|
| 1831 | typeof data !== "string" ||
|
---|
| 1832 | data.length > BULK_SIZE
|
---|
| 1833 | ) {
|
---|
| 1834 | if (this.hash === undefined) {
|
---|
| 1835 | this.hash = this.hashFactory();
|
---|
| 1836 | }
|
---|
| 1837 |
|
---|
| 1838 | if (this.buffer.length > 0) {
|
---|
| 1839 | this.hash.update(this.buffer);
|
---|
| 1840 | this.buffer = "";
|
---|
| 1841 | }
|
---|
| 1842 |
|
---|
| 1843 | this.hash.update(data, inputEncoding);
|
---|
| 1844 | } else {
|
---|
| 1845 | this.buffer += data;
|
---|
| 1846 |
|
---|
| 1847 | if (this.buffer.length > BULK_SIZE) {
|
---|
| 1848 | if (this.hash === undefined) {
|
---|
| 1849 | this.hash = this.hashFactory();
|
---|
| 1850 | }
|
---|
| 1851 |
|
---|
| 1852 | this.hash.update(this.buffer);
|
---|
| 1853 | this.buffer = "";
|
---|
| 1854 | }
|
---|
| 1855 | }
|
---|
| 1856 |
|
---|
| 1857 | return this;
|
---|
| 1858 | }
|
---|
| 1859 |
|
---|
| 1860 | /**
|
---|
| 1861 | * Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
|
---|
| 1862 | * @param {string=} encoding encoding of the return value
|
---|
| 1863 | * @returns {string|Buffer} digest
|
---|
| 1864 | */
|
---|
| 1865 | digest(encoding) {
|
---|
| 1866 | let digestCache;
|
---|
| 1867 |
|
---|
| 1868 | const buffer = this.buffer;
|
---|
| 1869 |
|
---|
| 1870 | if (this.hash === undefined) {
|
---|
| 1871 | // short data for hash, we can use caching
|
---|
| 1872 | const cacheKey = `${this.hashKey}-${encoding}`;
|
---|
| 1873 |
|
---|
| 1874 | digestCache = digestCaches[cacheKey];
|
---|
| 1875 |
|
---|
| 1876 | if (digestCache === undefined) {
|
---|
| 1877 | digestCache = digestCaches[cacheKey] = new Map();
|
---|
| 1878 | }
|
---|
| 1879 |
|
---|
| 1880 | const cacheEntry = digestCache.get(buffer);
|
---|
| 1881 |
|
---|
| 1882 | if (cacheEntry !== undefined) {
|
---|
| 1883 | return cacheEntry;
|
---|
| 1884 | }
|
---|
| 1885 |
|
---|
| 1886 | this.hash = this.hashFactory();
|
---|
| 1887 | }
|
---|
| 1888 |
|
---|
| 1889 | if (buffer.length > 0) {
|
---|
| 1890 | this.hash.update(buffer);
|
---|
| 1891 | }
|
---|
| 1892 |
|
---|
| 1893 | const digestResult = this.hash.digest(encoding);
|
---|
| 1894 |
|
---|
| 1895 | if (digestCache !== undefined) {
|
---|
| 1896 | digestCache.set(buffer, digestResult);
|
---|
| 1897 | }
|
---|
| 1898 |
|
---|
| 1899 | return digestResult;
|
---|
| 1900 | }
|
---|
| 1901 | }
|
---|
| 1902 |
|
---|
| 1903 | BulkUpdateDecorator_1 = BulkUpdateDecorator;
|
---|
| 1904 | return BulkUpdateDecorator_1;
|
---|
| 1905 | }
|
---|
| 1906 |
|
---|
| 1907 | const baseEncodeTables = {
|
---|
| 1908 | 26: "abcdefghijklmnopqrstuvwxyz",
|
---|
| 1909 | 32: "123456789abcdefghjkmnpqrstuvwxyz", // no 0lio
|
---|
| 1910 | 36: "0123456789abcdefghijklmnopqrstuvwxyz",
|
---|
| 1911 | 49: "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ", // no lIO
|
---|
| 1912 | 52: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
---|
| 1913 | 58: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ", // no 0lIO
|
---|
| 1914 | 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
---|
| 1915 | 64: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_",
|
---|
| 1916 | };
|
---|
| 1917 |
|
---|
| 1918 | /**
|
---|
| 1919 | * @param {Uint32Array} uint32Array Treated as a long base-0x100000000 number, little endian
|
---|
| 1920 | * @param {number} divisor The divisor
|
---|
| 1921 | * @return {number} Modulo (remainder) of the division
|
---|
| 1922 | */
|
---|
| 1923 | function divmod32(uint32Array, divisor) {
|
---|
| 1924 | let carry = 0;
|
---|
| 1925 | for (let i = uint32Array.length - 1; i >= 0; i--) {
|
---|
| 1926 | const value = carry * 0x100000000 + uint32Array[i];
|
---|
| 1927 | carry = value % divisor;
|
---|
| 1928 | uint32Array[i] = Math.floor(value / divisor);
|
---|
| 1929 | }
|
---|
| 1930 | return carry;
|
---|
| 1931 | }
|
---|
| 1932 |
|
---|
| 1933 | function encodeBufferToBase(buffer, base, length) {
|
---|
| 1934 | const encodeTable = baseEncodeTables[base];
|
---|
| 1935 |
|
---|
| 1936 | if (!encodeTable) {
|
---|
| 1937 | throw new Error("Unknown encoding base" + base);
|
---|
| 1938 | }
|
---|
| 1939 |
|
---|
| 1940 | // Input bits are only enough to generate this many characters
|
---|
| 1941 | const limit = Math.ceil((buffer.length * 8) / Math.log2(base));
|
---|
| 1942 | length = Math.min(length, limit);
|
---|
| 1943 |
|
---|
| 1944 | // Most of the crypto digests (if not all) has length a multiple of 4 bytes.
|
---|
| 1945 | // Fewer numbers in the array means faster math.
|
---|
| 1946 | const uint32Array = new Uint32Array(Math.ceil(buffer.length / 4));
|
---|
| 1947 |
|
---|
| 1948 | // Make sure the input buffer data is copied and is not mutated by reference.
|
---|
| 1949 | // divmod32() would corrupt the BulkUpdateDecorator cache otherwise.
|
---|
| 1950 | buffer.copy(Buffer.from(uint32Array.buffer));
|
---|
| 1951 |
|
---|
| 1952 | let output = "";
|
---|
| 1953 |
|
---|
| 1954 | for (let i = 0; i < length; i++) {
|
---|
| 1955 | output = encodeTable[divmod32(uint32Array, base)] + output;
|
---|
| 1956 | }
|
---|
| 1957 |
|
---|
| 1958 | return output;
|
---|
| 1959 | }
|
---|
| 1960 |
|
---|
| 1961 | let crypto = undefined;
|
---|
| 1962 | let createXXHash64 = undefined;
|
---|
| 1963 | let createMd4 = undefined;
|
---|
| 1964 | let BatchedHash = undefined;
|
---|
| 1965 | let BulkUpdateDecorator = undefined;
|
---|
| 1966 |
|
---|
| 1967 | function getHashDigest$1(buffer, algorithm, digestType, maxLength) {
|
---|
| 1968 | algorithm = algorithm || "xxhash64";
|
---|
| 1969 | maxLength = maxLength || 9999;
|
---|
| 1970 |
|
---|
| 1971 | let hash;
|
---|
| 1972 |
|
---|
| 1973 | if (algorithm === "xxhash64") {
|
---|
| 1974 | if (createXXHash64 === undefined) {
|
---|
| 1975 | createXXHash64 = requireXxhash64();
|
---|
| 1976 |
|
---|
| 1977 | if (BatchedHash === undefined) {
|
---|
| 1978 | BatchedHash = requireBatchedHash();
|
---|
| 1979 | }
|
---|
| 1980 | }
|
---|
| 1981 |
|
---|
| 1982 | hash = new BatchedHash(createXXHash64());
|
---|
| 1983 | } else if (algorithm === "md4") {
|
---|
| 1984 | if (createMd4 === undefined) {
|
---|
| 1985 | createMd4 = requireMd4();
|
---|
| 1986 |
|
---|
| 1987 | if (BatchedHash === undefined) {
|
---|
| 1988 | BatchedHash = requireBatchedHash();
|
---|
| 1989 | }
|
---|
| 1990 | }
|
---|
| 1991 |
|
---|
| 1992 | hash = new BatchedHash(createMd4());
|
---|
| 1993 | } else if (algorithm === "native-md4") {
|
---|
| 1994 | if (typeof crypto === "undefined") {
|
---|
| 1995 | crypto = require$$3;
|
---|
| 1996 |
|
---|
| 1997 | if (BulkUpdateDecorator === undefined) {
|
---|
| 1998 | BulkUpdateDecorator = requireBulkUpdateDecorator();
|
---|
| 1999 | }
|
---|
| 2000 | }
|
---|
| 2001 |
|
---|
| 2002 | hash = new BulkUpdateDecorator(() => crypto.createHash("md4"), "md4");
|
---|
| 2003 | } else {
|
---|
| 2004 | if (typeof crypto === "undefined") {
|
---|
| 2005 | crypto = require$$3;
|
---|
| 2006 |
|
---|
| 2007 | if (BulkUpdateDecorator === undefined) {
|
---|
| 2008 | BulkUpdateDecorator = requireBulkUpdateDecorator();
|
---|
| 2009 | }
|
---|
| 2010 | }
|
---|
| 2011 |
|
---|
| 2012 | hash = new BulkUpdateDecorator(
|
---|
| 2013 | () => crypto.createHash(algorithm),
|
---|
| 2014 | algorithm
|
---|
| 2015 | );
|
---|
| 2016 | }
|
---|
| 2017 |
|
---|
| 2018 | hash.update(buffer);
|
---|
| 2019 |
|
---|
| 2020 | if (
|
---|
| 2021 | digestType === "base26" ||
|
---|
| 2022 | digestType === "base32" ||
|
---|
| 2023 | digestType === "base36" ||
|
---|
| 2024 | digestType === "base49" ||
|
---|
| 2025 | digestType === "base52" ||
|
---|
| 2026 | digestType === "base58" ||
|
---|
| 2027 | digestType === "base62" ||
|
---|
| 2028 | digestType === "base64safe"
|
---|
| 2029 | ) {
|
---|
| 2030 | return encodeBufferToBase(
|
---|
| 2031 | hash.digest(),
|
---|
| 2032 | digestType === "base64safe" ? 64 : digestType.substr(4),
|
---|
| 2033 | maxLength
|
---|
| 2034 | );
|
---|
| 2035 | }
|
---|
| 2036 |
|
---|
| 2037 | return hash.digest(digestType || "hex").substr(0, maxLength);
|
---|
| 2038 | }
|
---|
| 2039 |
|
---|
| 2040 | var getHashDigest_1 = getHashDigest$1;
|
---|
| 2041 |
|
---|
| 2042 | const path$1 = require$$0$1;
|
---|
| 2043 | const getHashDigest = getHashDigest_1;
|
---|
| 2044 |
|
---|
| 2045 | function interpolateName$1(loaderContext, name, options = {}) {
|
---|
| 2046 | let filename;
|
---|
| 2047 |
|
---|
| 2048 | const hasQuery =
|
---|
| 2049 | loaderContext.resourceQuery && loaderContext.resourceQuery.length > 1;
|
---|
| 2050 |
|
---|
| 2051 | if (typeof name === "function") {
|
---|
| 2052 | filename = name(
|
---|
| 2053 | loaderContext.resourcePath,
|
---|
| 2054 | hasQuery ? loaderContext.resourceQuery : undefined
|
---|
| 2055 | );
|
---|
| 2056 | } else {
|
---|
| 2057 | filename = name || "[hash].[ext]";
|
---|
| 2058 | }
|
---|
| 2059 |
|
---|
| 2060 | const context = options.context;
|
---|
| 2061 | const content = options.content;
|
---|
| 2062 | const regExp = options.regExp;
|
---|
| 2063 |
|
---|
| 2064 | let ext = "bin";
|
---|
| 2065 | let basename = "file";
|
---|
| 2066 | let directory = "";
|
---|
| 2067 | let folder = "";
|
---|
| 2068 | let query = "";
|
---|
| 2069 |
|
---|
| 2070 | if (loaderContext.resourcePath) {
|
---|
| 2071 | const parsed = path$1.parse(loaderContext.resourcePath);
|
---|
| 2072 | let resourcePath = loaderContext.resourcePath;
|
---|
| 2073 |
|
---|
| 2074 | if (parsed.ext) {
|
---|
| 2075 | ext = parsed.ext.substr(1);
|
---|
| 2076 | }
|
---|
| 2077 |
|
---|
| 2078 | if (parsed.dir) {
|
---|
| 2079 | basename = parsed.name;
|
---|
| 2080 | resourcePath = parsed.dir + path$1.sep;
|
---|
| 2081 | }
|
---|
| 2082 |
|
---|
| 2083 | if (typeof context !== "undefined") {
|
---|
| 2084 | directory = path$1
|
---|
| 2085 | .relative(context, resourcePath + "_")
|
---|
| 2086 | .replace(/\\/g, "/")
|
---|
| 2087 | .replace(/\.\.(\/)?/g, "_$1");
|
---|
| 2088 | directory = directory.substr(0, directory.length - 1);
|
---|
| 2089 | } else {
|
---|
| 2090 | directory = resourcePath.replace(/\\/g, "/").replace(/\.\.(\/)?/g, "_$1");
|
---|
| 2091 | }
|
---|
| 2092 |
|
---|
| 2093 | if (directory.length <= 1) {
|
---|
| 2094 | directory = "";
|
---|
| 2095 | } else {
|
---|
| 2096 | // directory.length > 1
|
---|
| 2097 | folder = path$1.basename(directory);
|
---|
| 2098 | }
|
---|
| 2099 | }
|
---|
| 2100 |
|
---|
| 2101 | if (loaderContext.resourceQuery && loaderContext.resourceQuery.length > 1) {
|
---|
| 2102 | query = loaderContext.resourceQuery;
|
---|
| 2103 |
|
---|
| 2104 | const hashIdx = query.indexOf("#");
|
---|
| 2105 |
|
---|
| 2106 | if (hashIdx >= 0) {
|
---|
| 2107 | query = query.substr(0, hashIdx);
|
---|
| 2108 | }
|
---|
| 2109 | }
|
---|
| 2110 |
|
---|
| 2111 | let url = filename;
|
---|
| 2112 |
|
---|
| 2113 | if (content) {
|
---|
| 2114 | // Match hash template
|
---|
| 2115 | url = url
|
---|
| 2116 | // `hash` and `contenthash` are same in `loader-utils` context
|
---|
| 2117 | // let's keep `hash` for backward compatibility
|
---|
| 2118 | .replace(
|
---|
| 2119 | /\[(?:([^[:\]]+):)?(?:hash|contenthash)(?::([a-z]+\d*(?:safe)?))?(?::(\d+))?\]/gi,
|
---|
| 2120 | (all, hashType, digestType, maxLength) =>
|
---|
| 2121 | getHashDigest(content, hashType, digestType, parseInt(maxLength, 10))
|
---|
| 2122 | );
|
---|
| 2123 | }
|
---|
| 2124 |
|
---|
| 2125 | url = url
|
---|
| 2126 | .replace(/\[ext\]/gi, () => ext)
|
---|
| 2127 | .replace(/\[name\]/gi, () => basename)
|
---|
| 2128 | .replace(/\[path\]/gi, () => directory)
|
---|
| 2129 | .replace(/\[folder\]/gi, () => folder)
|
---|
| 2130 | .replace(/\[query\]/gi, () => query);
|
---|
| 2131 |
|
---|
| 2132 | if (regExp && loaderContext.resourcePath) {
|
---|
| 2133 | const match = loaderContext.resourcePath.match(new RegExp(regExp));
|
---|
| 2134 |
|
---|
| 2135 | match &&
|
---|
| 2136 | match.forEach((matched, i) => {
|
---|
| 2137 | url = url.replace(new RegExp("\\[" + i + "\\]", "ig"), matched);
|
---|
| 2138 | });
|
---|
| 2139 | }
|
---|
| 2140 |
|
---|
| 2141 | if (
|
---|
| 2142 | typeof loaderContext.options === "object" &&
|
---|
| 2143 | typeof loaderContext.options.customInterpolateName === "function"
|
---|
| 2144 | ) {
|
---|
| 2145 | url = loaderContext.options.customInterpolateName.call(
|
---|
| 2146 | loaderContext,
|
---|
| 2147 | url,
|
---|
| 2148 | name,
|
---|
| 2149 | options
|
---|
| 2150 | );
|
---|
| 2151 | }
|
---|
| 2152 |
|
---|
| 2153 | return url;
|
---|
| 2154 | }
|
---|
| 2155 |
|
---|
| 2156 | var interpolateName_1 = interpolateName$1;
|
---|
| 2157 |
|
---|
| 2158 | var interpolateName = interpolateName_1;
|
---|
| 2159 | var path = require$$0$1;
|
---|
| 2160 |
|
---|
| 2161 | /**
|
---|
| 2162 | * @param {string} pattern
|
---|
| 2163 | * @param {object} options
|
---|
| 2164 | * @param {string} options.context
|
---|
| 2165 | * @param {string} options.hashPrefix
|
---|
| 2166 | * @return {function}
|
---|
| 2167 | */
|
---|
| 2168 | var genericNames = function createGenerator(pattern, options) {
|
---|
| 2169 | options = options || {};
|
---|
| 2170 | var context =
|
---|
| 2171 | options && typeof options.context === "string"
|
---|
| 2172 | ? options.context
|
---|
| 2173 | : process.cwd();
|
---|
| 2174 | var hashPrefix =
|
---|
| 2175 | options && typeof options.hashPrefix === "string" ? options.hashPrefix : "";
|
---|
| 2176 |
|
---|
| 2177 | /**
|
---|
| 2178 | * @param {string} localName Usually a class name
|
---|
| 2179 | * @param {string} filepath Absolute path
|
---|
| 2180 | * @return {string}
|
---|
| 2181 | */
|
---|
| 2182 | return function generate(localName, filepath) {
|
---|
| 2183 | var name = pattern.replace(/\[local\]/gi, localName);
|
---|
| 2184 | var loaderContext = {
|
---|
| 2185 | resourcePath: filepath,
|
---|
| 2186 | };
|
---|
| 2187 |
|
---|
| 2188 | var loaderOptions = {
|
---|
| 2189 | content:
|
---|
| 2190 | hashPrefix +
|
---|
| 2191 | path.relative(context, filepath).replace(/\\/g, "/") +
|
---|
| 2192 | "\x00" +
|
---|
| 2193 | localName,
|
---|
| 2194 | context: context,
|
---|
| 2195 | };
|
---|
| 2196 |
|
---|
| 2197 | var genericName = interpolateName(loaderContext, name, loaderOptions);
|
---|
| 2198 | return genericName
|
---|
| 2199 | .replace(new RegExp("[^a-zA-Z0-9\\-_\u00A0-\uFFFF]", "g"), "-")
|
---|
| 2200 | .replace(/^((-?[0-9])|--)/, "_$1");
|
---|
| 2201 | };
|
---|
| 2202 | };
|
---|
| 2203 |
|
---|
| 2204 | var src$2 = {exports: {}};
|
---|
| 2205 |
|
---|
| 2206 | var dist = {exports: {}};
|
---|
| 2207 |
|
---|
| 2208 | var processor = {exports: {}};
|
---|
| 2209 |
|
---|
| 2210 | var parser = {exports: {}};
|
---|
| 2211 |
|
---|
| 2212 | var root$1 = {exports: {}};
|
---|
| 2213 |
|
---|
| 2214 | var container = {exports: {}};
|
---|
| 2215 |
|
---|
| 2216 | var node$1 = {exports: {}};
|
---|
| 2217 |
|
---|
| 2218 | var util = {};
|
---|
| 2219 |
|
---|
| 2220 | var unesc = {exports: {}};
|
---|
| 2221 |
|
---|
| 2222 | (function (module, exports) {
|
---|
| 2223 |
|
---|
| 2224 | exports.__esModule = true;
|
---|
| 2225 | exports["default"] = unesc;
|
---|
| 2226 | // Many thanks for this post which made this migration much easier.
|
---|
| 2227 | // https://mathiasbynens.be/notes/css-escapes
|
---|
| 2228 |
|
---|
| 2229 | /**
|
---|
| 2230 | *
|
---|
| 2231 | * @param {string} str
|
---|
| 2232 | * @returns {[string, number]|undefined}
|
---|
| 2233 | */
|
---|
| 2234 | function gobbleHex(str) {
|
---|
| 2235 | var lower = str.toLowerCase();
|
---|
| 2236 | var hex = '';
|
---|
| 2237 | var spaceTerminated = false;
|
---|
| 2238 | for (var i = 0; i < 6 && lower[i] !== undefined; i++) {
|
---|
| 2239 | var code = lower.charCodeAt(i);
|
---|
| 2240 | // check to see if we are dealing with a valid hex char [a-f|0-9]
|
---|
| 2241 | var valid = code >= 97 && code <= 102 || code >= 48 && code <= 57;
|
---|
| 2242 | // https://drafts.csswg.org/css-syntax/#consume-escaped-code-point
|
---|
| 2243 | spaceTerminated = code === 32;
|
---|
| 2244 | if (!valid) {
|
---|
| 2245 | break;
|
---|
| 2246 | }
|
---|
| 2247 | hex += lower[i];
|
---|
| 2248 | }
|
---|
| 2249 | if (hex.length === 0) {
|
---|
| 2250 | return undefined;
|
---|
| 2251 | }
|
---|
| 2252 | var codePoint = parseInt(hex, 16);
|
---|
| 2253 | var isSurrogate = codePoint >= 0xD800 && codePoint <= 0xDFFF;
|
---|
| 2254 | // Add special case for
|
---|
| 2255 | // "If this number is zero, or is for a surrogate, or is greater than the maximum allowed code point"
|
---|
| 2256 | // https://drafts.csswg.org/css-syntax/#maximum-allowed-code-point
|
---|
| 2257 | if (isSurrogate || codePoint === 0x0000 || codePoint > 0x10FFFF) {
|
---|
| 2258 | return ["\uFFFD", hex.length + (spaceTerminated ? 1 : 0)];
|
---|
| 2259 | }
|
---|
| 2260 | return [String.fromCodePoint(codePoint), hex.length + (spaceTerminated ? 1 : 0)];
|
---|
| 2261 | }
|
---|
| 2262 | var CONTAINS_ESCAPE = /\\/;
|
---|
| 2263 | function unesc(str) {
|
---|
| 2264 | var needToProcess = CONTAINS_ESCAPE.test(str);
|
---|
| 2265 | if (!needToProcess) {
|
---|
| 2266 | return str;
|
---|
| 2267 | }
|
---|
| 2268 | var ret = "";
|
---|
| 2269 | for (var i = 0; i < str.length; i++) {
|
---|
| 2270 | if (str[i] === "\\") {
|
---|
| 2271 | var gobbled = gobbleHex(str.slice(i + 1, i + 7));
|
---|
| 2272 | if (gobbled !== undefined) {
|
---|
| 2273 | ret += gobbled[0];
|
---|
| 2274 | i += gobbled[1];
|
---|
| 2275 | continue;
|
---|
| 2276 | }
|
---|
| 2277 |
|
---|
| 2278 | // Retain a pair of \\ if double escaped `\\\\`
|
---|
| 2279 | // https://github.com/postcss/postcss-selector-parser/commit/268c9a7656fb53f543dc620aa5b73a30ec3ff20e
|
---|
| 2280 | if (str[i + 1] === "\\") {
|
---|
| 2281 | ret += "\\";
|
---|
| 2282 | i++;
|
---|
| 2283 | continue;
|
---|
| 2284 | }
|
---|
| 2285 |
|
---|
| 2286 | // if \\ is at the end of the string retain it
|
---|
| 2287 | // https://github.com/postcss/postcss-selector-parser/commit/01a6b346e3612ce1ab20219acc26abdc259ccefb
|
---|
| 2288 | if (str.length === i + 1) {
|
---|
| 2289 | ret += str[i];
|
---|
| 2290 | }
|
---|
| 2291 | continue;
|
---|
| 2292 | }
|
---|
| 2293 | ret += str[i];
|
---|
| 2294 | }
|
---|
| 2295 | return ret;
|
---|
| 2296 | }
|
---|
| 2297 | module.exports = exports.default;
|
---|
| 2298 | } (unesc, unesc.exports));
|
---|
| 2299 |
|
---|
| 2300 | var unescExports = unesc.exports;
|
---|
| 2301 |
|
---|
| 2302 | var getProp = {exports: {}};
|
---|
| 2303 |
|
---|
| 2304 | (function (module, exports) {
|
---|
| 2305 |
|
---|
| 2306 | exports.__esModule = true;
|
---|
| 2307 | exports["default"] = getProp;
|
---|
| 2308 | function getProp(obj) {
|
---|
| 2309 | for (var _len = arguments.length, props = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
---|
| 2310 | props[_key - 1] = arguments[_key];
|
---|
| 2311 | }
|
---|
| 2312 | while (props.length > 0) {
|
---|
| 2313 | var prop = props.shift();
|
---|
| 2314 | if (!obj[prop]) {
|
---|
| 2315 | return undefined;
|
---|
| 2316 | }
|
---|
| 2317 | obj = obj[prop];
|
---|
| 2318 | }
|
---|
| 2319 | return obj;
|
---|
| 2320 | }
|
---|
| 2321 | module.exports = exports.default;
|
---|
| 2322 | } (getProp, getProp.exports));
|
---|
| 2323 |
|
---|
| 2324 | var getPropExports = getProp.exports;
|
---|
| 2325 |
|
---|
| 2326 | var ensureObject = {exports: {}};
|
---|
| 2327 |
|
---|
| 2328 | (function (module, exports) {
|
---|
| 2329 |
|
---|
| 2330 | exports.__esModule = true;
|
---|
| 2331 | exports["default"] = ensureObject;
|
---|
| 2332 | function ensureObject(obj) {
|
---|
| 2333 | for (var _len = arguments.length, props = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
---|
| 2334 | props[_key - 1] = arguments[_key];
|
---|
| 2335 | }
|
---|
| 2336 | while (props.length > 0) {
|
---|
| 2337 | var prop = props.shift();
|
---|
| 2338 | if (!obj[prop]) {
|
---|
| 2339 | obj[prop] = {};
|
---|
| 2340 | }
|
---|
| 2341 | obj = obj[prop];
|
---|
| 2342 | }
|
---|
| 2343 | }
|
---|
| 2344 | module.exports = exports.default;
|
---|
| 2345 | } (ensureObject, ensureObject.exports));
|
---|
| 2346 |
|
---|
| 2347 | var ensureObjectExports = ensureObject.exports;
|
---|
| 2348 |
|
---|
| 2349 | var stripComments = {exports: {}};
|
---|
| 2350 |
|
---|
| 2351 | (function (module, exports) {
|
---|
| 2352 |
|
---|
| 2353 | exports.__esModule = true;
|
---|
| 2354 | exports["default"] = stripComments;
|
---|
| 2355 | function stripComments(str) {
|
---|
| 2356 | var s = "";
|
---|
| 2357 | var commentStart = str.indexOf("/*");
|
---|
| 2358 | var lastEnd = 0;
|
---|
| 2359 | while (commentStart >= 0) {
|
---|
| 2360 | s = s + str.slice(lastEnd, commentStart);
|
---|
| 2361 | var commentEnd = str.indexOf("*/", commentStart + 2);
|
---|
| 2362 | if (commentEnd < 0) {
|
---|
| 2363 | return s;
|
---|
| 2364 | }
|
---|
| 2365 | lastEnd = commentEnd + 2;
|
---|
| 2366 | commentStart = str.indexOf("/*", lastEnd);
|
---|
| 2367 | }
|
---|
| 2368 | s = s + str.slice(lastEnd);
|
---|
| 2369 | return s;
|
---|
| 2370 | }
|
---|
| 2371 | module.exports = exports.default;
|
---|
| 2372 | } (stripComments, stripComments.exports));
|
---|
| 2373 |
|
---|
| 2374 | var stripCommentsExports = stripComments.exports;
|
---|
| 2375 |
|
---|
| 2376 | util.__esModule = true;
|
---|
| 2377 | util.unesc = util.stripComments = util.getProp = util.ensureObject = undefined;
|
---|
| 2378 | var _unesc = _interopRequireDefault$3(unescExports);
|
---|
| 2379 | util.unesc = _unesc["default"];
|
---|
| 2380 | var _getProp = _interopRequireDefault$3(getPropExports);
|
---|
| 2381 | util.getProp = _getProp["default"];
|
---|
| 2382 | var _ensureObject = _interopRequireDefault$3(ensureObjectExports);
|
---|
| 2383 | util.ensureObject = _ensureObject["default"];
|
---|
| 2384 | var _stripComments = _interopRequireDefault$3(stripCommentsExports);
|
---|
| 2385 | util.stripComments = _stripComments["default"];
|
---|
| 2386 | function _interopRequireDefault$3(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
---|
| 2387 |
|
---|
| 2388 | (function (module, exports) {
|
---|
| 2389 |
|
---|
| 2390 | exports.__esModule = true;
|
---|
| 2391 | exports["default"] = undefined;
|
---|
| 2392 | var _util = util;
|
---|
| 2393 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
---|
| 2394 | function _createClass(Constructor, protoProps, staticProps) { _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
---|
| 2395 | var cloneNode = function cloneNode(obj, parent) {
|
---|
| 2396 | if (typeof obj !== 'object' || obj === null) {
|
---|
| 2397 | return obj;
|
---|
| 2398 | }
|
---|
| 2399 | var cloned = new obj.constructor();
|
---|
| 2400 | for (var i in obj) {
|
---|
| 2401 | if (!obj.hasOwnProperty(i)) {
|
---|
| 2402 | continue;
|
---|
| 2403 | }
|
---|
| 2404 | var value = obj[i];
|
---|
| 2405 | var type = typeof value;
|
---|
| 2406 | if (i === 'parent' && type === 'object') {
|
---|
| 2407 | if (parent) {
|
---|
| 2408 | cloned[i] = parent;
|
---|
| 2409 | }
|
---|
| 2410 | } else if (value instanceof Array) {
|
---|
| 2411 | cloned[i] = value.map(function (j) {
|
---|
| 2412 | return cloneNode(j, cloned);
|
---|
| 2413 | });
|
---|
| 2414 | } else {
|
---|
| 2415 | cloned[i] = cloneNode(value, cloned);
|
---|
| 2416 | }
|
---|
| 2417 | }
|
---|
| 2418 | return cloned;
|
---|
| 2419 | };
|
---|
| 2420 | var Node = /*#__PURE__*/function () {
|
---|
| 2421 | function Node(opts) {
|
---|
| 2422 | if (opts === undefined) {
|
---|
| 2423 | opts = {};
|
---|
| 2424 | }
|
---|
| 2425 | Object.assign(this, opts);
|
---|
| 2426 | this.spaces = this.spaces || {};
|
---|
| 2427 | this.spaces.before = this.spaces.before || '';
|
---|
| 2428 | this.spaces.after = this.spaces.after || '';
|
---|
| 2429 | }
|
---|
| 2430 | var _proto = Node.prototype;
|
---|
| 2431 | _proto.remove = function remove() {
|
---|
| 2432 | if (this.parent) {
|
---|
| 2433 | this.parent.removeChild(this);
|
---|
| 2434 | }
|
---|
| 2435 | this.parent = undefined;
|
---|
| 2436 | return this;
|
---|
| 2437 | };
|
---|
| 2438 | _proto.replaceWith = function replaceWith() {
|
---|
| 2439 | if (this.parent) {
|
---|
| 2440 | for (var index in arguments) {
|
---|
| 2441 | this.parent.insertBefore(this, arguments[index]);
|
---|
| 2442 | }
|
---|
| 2443 | this.remove();
|
---|
| 2444 | }
|
---|
| 2445 | return this;
|
---|
| 2446 | };
|
---|
| 2447 | _proto.next = function next() {
|
---|
| 2448 | return this.parent.at(this.parent.index(this) + 1);
|
---|
| 2449 | };
|
---|
| 2450 | _proto.prev = function prev() {
|
---|
| 2451 | return this.parent.at(this.parent.index(this) - 1);
|
---|
| 2452 | };
|
---|
| 2453 | _proto.clone = function clone(overrides) {
|
---|
| 2454 | if (overrides === undefined) {
|
---|
| 2455 | overrides = {};
|
---|
| 2456 | }
|
---|
| 2457 | var cloned = cloneNode(this);
|
---|
| 2458 | for (var name in overrides) {
|
---|
| 2459 | cloned[name] = overrides[name];
|
---|
| 2460 | }
|
---|
| 2461 | return cloned;
|
---|
| 2462 | }
|
---|
| 2463 |
|
---|
| 2464 | /**
|
---|
| 2465 | * Some non-standard syntax doesn't follow normal escaping rules for css.
|
---|
| 2466 | * This allows non standard syntax to be appended to an existing property
|
---|
| 2467 | * by specifying the escaped value. By specifying the escaped value,
|
---|
| 2468 | * illegal characters are allowed to be directly inserted into css output.
|
---|
| 2469 | * @param {string} name the property to set
|
---|
| 2470 | * @param {any} value the unescaped value of the property
|
---|
| 2471 | * @param {string} valueEscaped optional. the escaped value of the property.
|
---|
| 2472 | */;
|
---|
| 2473 | _proto.appendToPropertyAndEscape = function appendToPropertyAndEscape(name, value, valueEscaped) {
|
---|
| 2474 | if (!this.raws) {
|
---|
| 2475 | this.raws = {};
|
---|
| 2476 | }
|
---|
| 2477 | var originalValue = this[name];
|
---|
| 2478 | var originalEscaped = this.raws[name];
|
---|
| 2479 | this[name] = originalValue + value; // this may trigger a setter that updates raws, so it has to be set first.
|
---|
| 2480 | if (originalEscaped || valueEscaped !== value) {
|
---|
| 2481 | this.raws[name] = (originalEscaped || originalValue) + valueEscaped;
|
---|
| 2482 | } else {
|
---|
| 2483 | delete this.raws[name]; // delete any escaped value that was created by the setter.
|
---|
| 2484 | }
|
---|
| 2485 | }
|
---|
| 2486 |
|
---|
| 2487 | /**
|
---|
| 2488 | * Some non-standard syntax doesn't follow normal escaping rules for css.
|
---|
| 2489 | * This allows the escaped value to be specified directly, allowing illegal
|
---|
| 2490 | * characters to be directly inserted into css output.
|
---|
| 2491 | * @param {string} name the property to set
|
---|
| 2492 | * @param {any} value the unescaped value of the property
|
---|
| 2493 | * @param {string} valueEscaped the escaped value of the property.
|
---|
| 2494 | */;
|
---|
| 2495 | _proto.setPropertyAndEscape = function setPropertyAndEscape(name, value, valueEscaped) {
|
---|
| 2496 | if (!this.raws) {
|
---|
| 2497 | this.raws = {};
|
---|
| 2498 | }
|
---|
| 2499 | this[name] = value; // this may trigger a setter that updates raws, so it has to be set first.
|
---|
| 2500 | this.raws[name] = valueEscaped;
|
---|
| 2501 | }
|
---|
| 2502 |
|
---|
| 2503 | /**
|
---|
| 2504 | * When you want a value to passed through to CSS directly. This method
|
---|
| 2505 | * deletes the corresponding raw value causing the stringifier to fallback
|
---|
| 2506 | * to the unescaped value.
|
---|
| 2507 | * @param {string} name the property to set.
|
---|
| 2508 | * @param {any} value The value that is both escaped and unescaped.
|
---|
| 2509 | */;
|
---|
| 2510 | _proto.setPropertyWithoutEscape = function setPropertyWithoutEscape(name, value) {
|
---|
| 2511 | this[name] = value; // this may trigger a setter that updates raws, so it has to be set first.
|
---|
| 2512 | if (this.raws) {
|
---|
| 2513 | delete this.raws[name];
|
---|
| 2514 | }
|
---|
| 2515 | }
|
---|
| 2516 |
|
---|
| 2517 | /**
|
---|
| 2518 | *
|
---|
| 2519 | * @param {number} line The number (starting with 1)
|
---|
| 2520 | * @param {number} column The column number (starting with 1)
|
---|
| 2521 | */;
|
---|
| 2522 | _proto.isAtPosition = function isAtPosition(line, column) {
|
---|
| 2523 | if (this.source && this.source.start && this.source.end) {
|
---|
| 2524 | if (this.source.start.line > line) {
|
---|
| 2525 | return false;
|
---|
| 2526 | }
|
---|
| 2527 | if (this.source.end.line < line) {
|
---|
| 2528 | return false;
|
---|
| 2529 | }
|
---|
| 2530 | if (this.source.start.line === line && this.source.start.column > column) {
|
---|
| 2531 | return false;
|
---|
| 2532 | }
|
---|
| 2533 | if (this.source.end.line === line && this.source.end.column < column) {
|
---|
| 2534 | return false;
|
---|
| 2535 | }
|
---|
| 2536 | return true;
|
---|
| 2537 | }
|
---|
| 2538 | return undefined;
|
---|
| 2539 | };
|
---|
| 2540 | _proto.stringifyProperty = function stringifyProperty(name) {
|
---|
| 2541 | return this.raws && this.raws[name] || this[name];
|
---|
| 2542 | };
|
---|
| 2543 | _proto.valueToString = function valueToString() {
|
---|
| 2544 | return String(this.stringifyProperty("value"));
|
---|
| 2545 | };
|
---|
| 2546 | _proto.toString = function toString() {
|
---|
| 2547 | return [this.rawSpaceBefore, this.valueToString(), this.rawSpaceAfter].join('');
|
---|
| 2548 | };
|
---|
| 2549 | _createClass(Node, [{
|
---|
| 2550 | key: "rawSpaceBefore",
|
---|
| 2551 | get: function get() {
|
---|
| 2552 | var rawSpace = this.raws && this.raws.spaces && this.raws.spaces.before;
|
---|
| 2553 | if (rawSpace === undefined) {
|
---|
| 2554 | rawSpace = this.spaces && this.spaces.before;
|
---|
| 2555 | }
|
---|
| 2556 | return rawSpace || "";
|
---|
| 2557 | },
|
---|
| 2558 | set: function set(raw) {
|
---|
| 2559 | (0, _util.ensureObject)(this, "raws", "spaces");
|
---|
| 2560 | this.raws.spaces.before = raw;
|
---|
| 2561 | }
|
---|
| 2562 | }, {
|
---|
| 2563 | key: "rawSpaceAfter",
|
---|
| 2564 | get: function get() {
|
---|
| 2565 | var rawSpace = this.raws && this.raws.spaces && this.raws.spaces.after;
|
---|
| 2566 | if (rawSpace === undefined) {
|
---|
| 2567 | rawSpace = this.spaces.after;
|
---|
| 2568 | }
|
---|
| 2569 | return rawSpace || "";
|
---|
| 2570 | },
|
---|
| 2571 | set: function set(raw) {
|
---|
| 2572 | (0, _util.ensureObject)(this, "raws", "spaces");
|
---|
| 2573 | this.raws.spaces.after = raw;
|
---|
| 2574 | }
|
---|
| 2575 | }]);
|
---|
| 2576 | return Node;
|
---|
| 2577 | }();
|
---|
| 2578 | exports["default"] = Node;
|
---|
| 2579 | module.exports = exports.default;
|
---|
| 2580 | } (node$1, node$1.exports));
|
---|
| 2581 |
|
---|
| 2582 | var nodeExports = node$1.exports;
|
---|
| 2583 |
|
---|
| 2584 | var types = {};
|
---|
| 2585 |
|
---|
| 2586 | types.__esModule = true;
|
---|
| 2587 | types.UNIVERSAL = types.TAG = types.STRING = types.SELECTOR = types.ROOT = types.PSEUDO = types.NESTING = types.ID = types.COMMENT = types.COMBINATOR = types.CLASS = types.ATTRIBUTE = undefined;
|
---|
| 2588 | var TAG = 'tag';
|
---|
| 2589 | types.TAG = TAG;
|
---|
| 2590 | var STRING = 'string';
|
---|
| 2591 | types.STRING = STRING;
|
---|
| 2592 | var SELECTOR = 'selector';
|
---|
| 2593 | types.SELECTOR = SELECTOR;
|
---|
| 2594 | var ROOT = 'root';
|
---|
| 2595 | types.ROOT = ROOT;
|
---|
| 2596 | var PSEUDO = 'pseudo';
|
---|
| 2597 | types.PSEUDO = PSEUDO;
|
---|
| 2598 | var NESTING = 'nesting';
|
---|
| 2599 | types.NESTING = NESTING;
|
---|
| 2600 | var ID = 'id';
|
---|
| 2601 | types.ID = ID;
|
---|
| 2602 | var COMMENT = 'comment';
|
---|
| 2603 | types.COMMENT = COMMENT;
|
---|
| 2604 | var COMBINATOR = 'combinator';
|
---|
| 2605 | types.COMBINATOR = COMBINATOR;
|
---|
| 2606 | var CLASS = 'class';
|
---|
| 2607 | types.CLASS = CLASS;
|
---|
| 2608 | var ATTRIBUTE = 'attribute';
|
---|
| 2609 | types.ATTRIBUTE = ATTRIBUTE;
|
---|
| 2610 | var UNIVERSAL = 'universal';
|
---|
| 2611 | types.UNIVERSAL = UNIVERSAL;
|
---|
| 2612 |
|
---|
| 2613 | (function (module, exports) {
|
---|
| 2614 |
|
---|
| 2615 | exports.__esModule = true;
|
---|
| 2616 | exports["default"] = undefined;
|
---|
| 2617 | var _node = _interopRequireDefault(nodeExports);
|
---|
| 2618 | var types$1 = _interopRequireWildcard(types);
|
---|
| 2619 | function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
---|
| 2620 | function _interopRequireWildcard(obj, nodeInterop) { if (obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
---|
| 2621 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
---|
| 2622 | function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike) { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
---|
| 2623 | function _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); }
|
---|
| 2624 | function _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; }
|
---|
| 2625 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
---|
| 2626 | function _createClass(Constructor, protoProps, staticProps) { _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
---|
| 2627 | function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
|
---|
| 2628 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
---|
| 2629 | var Container = /*#__PURE__*/function (_Node) {
|
---|
| 2630 | _inheritsLoose(Container, _Node);
|
---|
| 2631 | function Container(opts) {
|
---|
| 2632 | var _this;
|
---|
| 2633 | _this = _Node.call(this, opts) || this;
|
---|
| 2634 | if (!_this.nodes) {
|
---|
| 2635 | _this.nodes = [];
|
---|
| 2636 | }
|
---|
| 2637 | return _this;
|
---|
| 2638 | }
|
---|
| 2639 | var _proto = Container.prototype;
|
---|
| 2640 | _proto.append = function append(selector) {
|
---|
| 2641 | selector.parent = this;
|
---|
| 2642 | this.nodes.push(selector);
|
---|
| 2643 | return this;
|
---|
| 2644 | };
|
---|
| 2645 | _proto.prepend = function prepend(selector) {
|
---|
| 2646 | selector.parent = this;
|
---|
| 2647 | this.nodes.unshift(selector);
|
---|
| 2648 | return this;
|
---|
| 2649 | };
|
---|
| 2650 | _proto.at = function at(index) {
|
---|
| 2651 | return this.nodes[index];
|
---|
| 2652 | };
|
---|
| 2653 | _proto.index = function index(child) {
|
---|
| 2654 | if (typeof child === 'number') {
|
---|
| 2655 | return child;
|
---|
| 2656 | }
|
---|
| 2657 | return this.nodes.indexOf(child);
|
---|
| 2658 | };
|
---|
| 2659 | _proto.removeChild = function removeChild(child) {
|
---|
| 2660 | child = this.index(child);
|
---|
| 2661 | this.at(child).parent = undefined;
|
---|
| 2662 | this.nodes.splice(child, 1);
|
---|
| 2663 | var index;
|
---|
| 2664 | for (var id in this.indexes) {
|
---|
| 2665 | index = this.indexes[id];
|
---|
| 2666 | if (index >= child) {
|
---|
| 2667 | this.indexes[id] = index - 1;
|
---|
| 2668 | }
|
---|
| 2669 | }
|
---|
| 2670 | return this;
|
---|
| 2671 | };
|
---|
| 2672 | _proto.removeAll = function removeAll() {
|
---|
| 2673 | for (var _iterator = _createForOfIteratorHelperLoose(this.nodes), _step; !(_step = _iterator()).done;) {
|
---|
| 2674 | var node = _step.value;
|
---|
| 2675 | node.parent = undefined;
|
---|
| 2676 | }
|
---|
| 2677 | this.nodes = [];
|
---|
| 2678 | return this;
|
---|
| 2679 | };
|
---|
| 2680 | _proto.empty = function empty() {
|
---|
| 2681 | return this.removeAll();
|
---|
| 2682 | };
|
---|
| 2683 | _proto.insertAfter = function insertAfter(oldNode, newNode) {
|
---|
| 2684 | newNode.parent = this;
|
---|
| 2685 | var oldIndex = this.index(oldNode);
|
---|
| 2686 | this.nodes.splice(oldIndex + 1, 0, newNode);
|
---|
| 2687 | newNode.parent = this;
|
---|
| 2688 | var index;
|
---|
| 2689 | for (var id in this.indexes) {
|
---|
| 2690 | index = this.indexes[id];
|
---|
| 2691 | if (oldIndex <= index) {
|
---|
| 2692 | this.indexes[id] = index + 1;
|
---|
| 2693 | }
|
---|
| 2694 | }
|
---|
| 2695 | return this;
|
---|
| 2696 | };
|
---|
| 2697 | _proto.insertBefore = function insertBefore(oldNode, newNode) {
|
---|
| 2698 | newNode.parent = this;
|
---|
| 2699 | var oldIndex = this.index(oldNode);
|
---|
| 2700 | this.nodes.splice(oldIndex, 0, newNode);
|
---|
| 2701 | newNode.parent = this;
|
---|
| 2702 | var index;
|
---|
| 2703 | for (var id in this.indexes) {
|
---|
| 2704 | index = this.indexes[id];
|
---|
| 2705 | if (index <= oldIndex) {
|
---|
| 2706 | this.indexes[id] = index + 1;
|
---|
| 2707 | }
|
---|
| 2708 | }
|
---|
| 2709 | return this;
|
---|
| 2710 | };
|
---|
| 2711 | _proto._findChildAtPosition = function _findChildAtPosition(line, col) {
|
---|
| 2712 | var found = undefined;
|
---|
| 2713 | this.each(function (node) {
|
---|
| 2714 | if (node.atPosition) {
|
---|
| 2715 | var foundChild = node.atPosition(line, col);
|
---|
| 2716 | if (foundChild) {
|
---|
| 2717 | found = foundChild;
|
---|
| 2718 | return false;
|
---|
| 2719 | }
|
---|
| 2720 | } else if (node.isAtPosition(line, col)) {
|
---|
| 2721 | found = node;
|
---|
| 2722 | return false;
|
---|
| 2723 | }
|
---|
| 2724 | });
|
---|
| 2725 | return found;
|
---|
| 2726 | }
|
---|
| 2727 |
|
---|
| 2728 | /**
|
---|
| 2729 | * Return the most specific node at the line and column number given.
|
---|
| 2730 | * The source location is based on the original parsed location, locations aren't
|
---|
| 2731 | * updated as selector nodes are mutated.
|
---|
| 2732 | *
|
---|
| 2733 | * Note that this location is relative to the location of the first character
|
---|
| 2734 | * of the selector, and not the location of the selector in the overall document
|
---|
| 2735 | * when used in conjunction with postcss.
|
---|
| 2736 | *
|
---|
| 2737 | * If not found, returns undefined.
|
---|
| 2738 | * @param {number} line The line number of the node to find. (1-based index)
|
---|
| 2739 | * @param {number} col The column number of the node to find. (1-based index)
|
---|
| 2740 | */;
|
---|
| 2741 | _proto.atPosition = function atPosition(line, col) {
|
---|
| 2742 | if (this.isAtPosition(line, col)) {
|
---|
| 2743 | return this._findChildAtPosition(line, col) || this;
|
---|
| 2744 | } else {
|
---|
| 2745 | return undefined;
|
---|
| 2746 | }
|
---|
| 2747 | };
|
---|
| 2748 | _proto._inferEndPosition = function _inferEndPosition() {
|
---|
| 2749 | if (this.last && this.last.source && this.last.source.end) {
|
---|
| 2750 | this.source = this.source || {};
|
---|
| 2751 | this.source.end = this.source.end || {};
|
---|
| 2752 | Object.assign(this.source.end, this.last.source.end);
|
---|
| 2753 | }
|
---|
| 2754 | };
|
---|
| 2755 | _proto.each = function each(callback) {
|
---|
| 2756 | if (!this.lastEach) {
|
---|
| 2757 | this.lastEach = 0;
|
---|
| 2758 | }
|
---|
| 2759 | if (!this.indexes) {
|
---|
| 2760 | this.indexes = {};
|
---|
| 2761 | }
|
---|
| 2762 | this.lastEach++;
|
---|
| 2763 | var id = this.lastEach;
|
---|
| 2764 | this.indexes[id] = 0;
|
---|
| 2765 | if (!this.length) {
|
---|
| 2766 | return undefined;
|
---|
| 2767 | }
|
---|
| 2768 | var index, result;
|
---|
| 2769 | while (this.indexes[id] < this.length) {
|
---|
| 2770 | index = this.indexes[id];
|
---|
| 2771 | result = callback(this.at(index), index);
|
---|
| 2772 | if (result === false) {
|
---|
| 2773 | break;
|
---|
| 2774 | }
|
---|
| 2775 | this.indexes[id] += 1;
|
---|
| 2776 | }
|
---|
| 2777 | delete this.indexes[id];
|
---|
| 2778 | if (result === false) {
|
---|
| 2779 | return false;
|
---|
| 2780 | }
|
---|
| 2781 | };
|
---|
| 2782 | _proto.walk = function walk(callback) {
|
---|
| 2783 | return this.each(function (node, i) {
|
---|
| 2784 | var result = callback(node, i);
|
---|
| 2785 | if (result !== false && node.length) {
|
---|
| 2786 | result = node.walk(callback);
|
---|
| 2787 | }
|
---|
| 2788 | if (result === false) {
|
---|
| 2789 | return false;
|
---|
| 2790 | }
|
---|
| 2791 | });
|
---|
| 2792 | };
|
---|
| 2793 | _proto.walkAttributes = function walkAttributes(callback) {
|
---|
| 2794 | var _this2 = this;
|
---|
| 2795 | return this.walk(function (selector) {
|
---|
| 2796 | if (selector.type === types$1.ATTRIBUTE) {
|
---|
| 2797 | return callback.call(_this2, selector);
|
---|
| 2798 | }
|
---|
| 2799 | });
|
---|
| 2800 | };
|
---|
| 2801 | _proto.walkClasses = function walkClasses(callback) {
|
---|
| 2802 | var _this3 = this;
|
---|
| 2803 | return this.walk(function (selector) {
|
---|
| 2804 | if (selector.type === types$1.CLASS) {
|
---|
| 2805 | return callback.call(_this3, selector);
|
---|
| 2806 | }
|
---|
| 2807 | });
|
---|
| 2808 | };
|
---|
| 2809 | _proto.walkCombinators = function walkCombinators(callback) {
|
---|
| 2810 | var _this4 = this;
|
---|
| 2811 | return this.walk(function (selector) {
|
---|
| 2812 | if (selector.type === types$1.COMBINATOR) {
|
---|
| 2813 | return callback.call(_this4, selector);
|
---|
| 2814 | }
|
---|
| 2815 | });
|
---|
| 2816 | };
|
---|
| 2817 | _proto.walkComments = function walkComments(callback) {
|
---|
| 2818 | var _this5 = this;
|
---|
| 2819 | return this.walk(function (selector) {
|
---|
| 2820 | if (selector.type === types$1.COMMENT) {
|
---|
| 2821 | return callback.call(_this5, selector);
|
---|
| 2822 | }
|
---|
| 2823 | });
|
---|
| 2824 | };
|
---|
| 2825 | _proto.walkIds = function walkIds(callback) {
|
---|
| 2826 | var _this6 = this;
|
---|
| 2827 | return this.walk(function (selector) {
|
---|
| 2828 | if (selector.type === types$1.ID) {
|
---|
| 2829 | return callback.call(_this6, selector);
|
---|
| 2830 | }
|
---|
| 2831 | });
|
---|
| 2832 | };
|
---|
| 2833 | _proto.walkNesting = function walkNesting(callback) {
|
---|
| 2834 | var _this7 = this;
|
---|
| 2835 | return this.walk(function (selector) {
|
---|
| 2836 | if (selector.type === types$1.NESTING) {
|
---|
| 2837 | return callback.call(_this7, selector);
|
---|
| 2838 | }
|
---|
| 2839 | });
|
---|
| 2840 | };
|
---|
| 2841 | _proto.walkPseudos = function walkPseudos(callback) {
|
---|
| 2842 | var _this8 = this;
|
---|
| 2843 | return this.walk(function (selector) {
|
---|
| 2844 | if (selector.type === types$1.PSEUDO) {
|
---|
| 2845 | return callback.call(_this8, selector);
|
---|
| 2846 | }
|
---|
| 2847 | });
|
---|
| 2848 | };
|
---|
| 2849 | _proto.walkTags = function walkTags(callback) {
|
---|
| 2850 | var _this9 = this;
|
---|
| 2851 | return this.walk(function (selector) {
|
---|
| 2852 | if (selector.type === types$1.TAG) {
|
---|
| 2853 | return callback.call(_this9, selector);
|
---|
| 2854 | }
|
---|
| 2855 | });
|
---|
| 2856 | };
|
---|
| 2857 | _proto.walkUniversals = function walkUniversals(callback) {
|
---|
| 2858 | var _this10 = this;
|
---|
| 2859 | return this.walk(function (selector) {
|
---|
| 2860 | if (selector.type === types$1.UNIVERSAL) {
|
---|
| 2861 | return callback.call(_this10, selector);
|
---|
| 2862 | }
|
---|
| 2863 | });
|
---|
| 2864 | };
|
---|
| 2865 | _proto.split = function split(callback) {
|
---|
| 2866 | var _this11 = this;
|
---|
| 2867 | var current = [];
|
---|
| 2868 | return this.reduce(function (memo, node, index) {
|
---|
| 2869 | var split = callback.call(_this11, node);
|
---|
| 2870 | current.push(node);
|
---|
| 2871 | if (split) {
|
---|
| 2872 | memo.push(current);
|
---|
| 2873 | current = [];
|
---|
| 2874 | } else if (index === _this11.length - 1) {
|
---|
| 2875 | memo.push(current);
|
---|
| 2876 | }
|
---|
| 2877 | return memo;
|
---|
| 2878 | }, []);
|
---|
| 2879 | };
|
---|
| 2880 | _proto.map = function map(callback) {
|
---|
| 2881 | return this.nodes.map(callback);
|
---|
| 2882 | };
|
---|
| 2883 | _proto.reduce = function reduce(callback, memo) {
|
---|
| 2884 | return this.nodes.reduce(callback, memo);
|
---|
| 2885 | };
|
---|
| 2886 | _proto.every = function every(callback) {
|
---|
| 2887 | return this.nodes.every(callback);
|
---|
| 2888 | };
|
---|
| 2889 | _proto.some = function some(callback) {
|
---|
| 2890 | return this.nodes.some(callback);
|
---|
| 2891 | };
|
---|
| 2892 | _proto.filter = function filter(callback) {
|
---|
| 2893 | return this.nodes.filter(callback);
|
---|
| 2894 | };
|
---|
| 2895 | _proto.sort = function sort(callback) {
|
---|
| 2896 | return this.nodes.sort(callback);
|
---|
| 2897 | };
|
---|
| 2898 | _proto.toString = function toString() {
|
---|
| 2899 | return this.map(String).join('');
|
---|
| 2900 | };
|
---|
| 2901 | _createClass(Container, [{
|
---|
| 2902 | key: "first",
|
---|
| 2903 | get: function get() {
|
---|
| 2904 | return this.at(0);
|
---|
| 2905 | }
|
---|
| 2906 | }, {
|
---|
| 2907 | key: "last",
|
---|
| 2908 | get: function get() {
|
---|
| 2909 | return this.at(this.length - 1);
|
---|
| 2910 | }
|
---|
| 2911 | }, {
|
---|
| 2912 | key: "length",
|
---|
| 2913 | get: function get() {
|
---|
| 2914 | return this.nodes.length;
|
---|
| 2915 | }
|
---|
| 2916 | }]);
|
---|
| 2917 | return Container;
|
---|
| 2918 | }(_node["default"]);
|
---|
| 2919 | exports["default"] = Container;
|
---|
| 2920 | module.exports = exports.default;
|
---|
| 2921 | } (container, container.exports));
|
---|
| 2922 |
|
---|
| 2923 | var containerExports = container.exports;
|
---|
| 2924 |
|
---|
| 2925 | (function (module, exports) {
|
---|
| 2926 |
|
---|
| 2927 | exports.__esModule = true;
|
---|
| 2928 | exports["default"] = undefined;
|
---|
| 2929 | var _container = _interopRequireDefault(containerExports);
|
---|
| 2930 | var _types = types;
|
---|
| 2931 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
---|
| 2932 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
---|
| 2933 | function _createClass(Constructor, protoProps, staticProps) { _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
---|
| 2934 | function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
|
---|
| 2935 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
---|
| 2936 | var Root = /*#__PURE__*/function (_Container) {
|
---|
| 2937 | _inheritsLoose(Root, _Container);
|
---|
| 2938 | function Root(opts) {
|
---|
| 2939 | var _this;
|
---|
| 2940 | _this = _Container.call(this, opts) || this;
|
---|
| 2941 | _this.type = _types.ROOT;
|
---|
| 2942 | return _this;
|
---|
| 2943 | }
|
---|
| 2944 | var _proto = Root.prototype;
|
---|
| 2945 | _proto.toString = function toString() {
|
---|
| 2946 | var str = this.reduce(function (memo, selector) {
|
---|
| 2947 | memo.push(String(selector));
|
---|
| 2948 | return memo;
|
---|
| 2949 | }, []).join(',');
|
---|
| 2950 | return this.trailingComma ? str + ',' : str;
|
---|
| 2951 | };
|
---|
| 2952 | _proto.error = function error(message, options) {
|
---|
| 2953 | if (this._error) {
|
---|
| 2954 | return this._error(message, options);
|
---|
| 2955 | } else {
|
---|
| 2956 | return new Error(message);
|
---|
| 2957 | }
|
---|
| 2958 | };
|
---|
| 2959 | _createClass(Root, [{
|
---|
| 2960 | key: "errorGenerator",
|
---|
| 2961 | set: function set(handler) {
|
---|
| 2962 | this._error = handler;
|
---|
| 2963 | }
|
---|
| 2964 | }]);
|
---|
| 2965 | return Root;
|
---|
| 2966 | }(_container["default"]);
|
---|
| 2967 | exports["default"] = Root;
|
---|
| 2968 | module.exports = exports.default;
|
---|
| 2969 | } (root$1, root$1.exports));
|
---|
| 2970 |
|
---|
| 2971 | var rootExports = root$1.exports;
|
---|
| 2972 |
|
---|
| 2973 | var selector$1 = {exports: {}};
|
---|
| 2974 |
|
---|
| 2975 | (function (module, exports) {
|
---|
| 2976 |
|
---|
| 2977 | exports.__esModule = true;
|
---|
| 2978 | exports["default"] = undefined;
|
---|
| 2979 | var _container = _interopRequireDefault(containerExports);
|
---|
| 2980 | var _types = types;
|
---|
| 2981 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
---|
| 2982 | function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
|
---|
| 2983 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
---|
| 2984 | var Selector = /*#__PURE__*/function (_Container) {
|
---|
| 2985 | _inheritsLoose(Selector, _Container);
|
---|
| 2986 | function Selector(opts) {
|
---|
| 2987 | var _this;
|
---|
| 2988 | _this = _Container.call(this, opts) || this;
|
---|
| 2989 | _this.type = _types.SELECTOR;
|
---|
| 2990 | return _this;
|
---|
| 2991 | }
|
---|
| 2992 | return Selector;
|
---|
| 2993 | }(_container["default"]);
|
---|
| 2994 | exports["default"] = Selector;
|
---|
| 2995 | module.exports = exports.default;
|
---|
| 2996 | } (selector$1, selector$1.exports));
|
---|
| 2997 |
|
---|
| 2998 | var selectorExports = selector$1.exports;
|
---|
| 2999 |
|
---|
| 3000 | var className$1 = {exports: {}};
|
---|
| 3001 |
|
---|
| 3002 | /*! https://mths.be/cssesc v3.0.0 by @mathias */
|
---|
| 3003 |
|
---|
| 3004 | var object = {};
|
---|
| 3005 | var hasOwnProperty$1 = object.hasOwnProperty;
|
---|
| 3006 | var merge = function merge(options, defaults) {
|
---|
| 3007 | if (!options) {
|
---|
| 3008 | return defaults;
|
---|
| 3009 | }
|
---|
| 3010 | var result = {};
|
---|
| 3011 | for (var key in defaults) {
|
---|
| 3012 | // `if (defaults.hasOwnProperty(key) { … }` is not needed here, since
|
---|
| 3013 | // only recognized option names are used.
|
---|
| 3014 | result[key] = hasOwnProperty$1.call(options, key) ? options[key] : defaults[key];
|
---|
| 3015 | }
|
---|
| 3016 | return result;
|
---|
| 3017 | };
|
---|
| 3018 |
|
---|
| 3019 | var regexAnySingleEscape = /[ -,\.\/:-@\[-\^`\{-~]/;
|
---|
| 3020 | var regexSingleEscape = /[ -,\.\/:-@\[\]\^`\{-~]/;
|
---|
| 3021 | var regexExcessiveSpaces = /(^|\\+)?(\\[A-F0-9]{1,6})\x20(?![a-fA-F0-9\x20])/g;
|
---|
| 3022 |
|
---|
| 3023 | // https://mathiasbynens.be/notes/css-escapes#css
|
---|
| 3024 | var cssesc = function cssesc(string, options) {
|
---|
| 3025 | options = merge(options, cssesc.options);
|
---|
| 3026 | if (options.quotes != 'single' && options.quotes != 'double') {
|
---|
| 3027 | options.quotes = 'single';
|
---|
| 3028 | }
|
---|
| 3029 | var quote = options.quotes == 'double' ? '"' : '\'';
|
---|
| 3030 | var isIdentifier = options.isIdentifier;
|
---|
| 3031 |
|
---|
| 3032 | var firstChar = string.charAt(0);
|
---|
| 3033 | var output = '';
|
---|
| 3034 | var counter = 0;
|
---|
| 3035 | var length = string.length;
|
---|
| 3036 | while (counter < length) {
|
---|
| 3037 | var character = string.charAt(counter++);
|
---|
| 3038 | var codePoint = character.charCodeAt();
|
---|
| 3039 | var value = undefined;
|
---|
| 3040 | // If it’s not a printable ASCII character…
|
---|
| 3041 | if (codePoint < 0x20 || codePoint > 0x7E) {
|
---|
| 3042 | if (codePoint >= 0xD800 && codePoint <= 0xDBFF && counter < length) {
|
---|
| 3043 | // It’s a high surrogate, and there is a next character.
|
---|
| 3044 | var extra = string.charCodeAt(counter++);
|
---|
| 3045 | if ((extra & 0xFC00) == 0xDC00) {
|
---|
| 3046 | // next character is low surrogate
|
---|
| 3047 | codePoint = ((codePoint & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000;
|
---|
| 3048 | } else {
|
---|
| 3049 | // It’s an unmatched surrogate; only append this code unit, in case
|
---|
| 3050 | // the next code unit is the high surrogate of a surrogate pair.
|
---|
| 3051 | counter--;
|
---|
| 3052 | }
|
---|
| 3053 | }
|
---|
| 3054 | value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
|
---|
| 3055 | } else {
|
---|
| 3056 | if (options.escapeEverything) {
|
---|
| 3057 | if (regexAnySingleEscape.test(character)) {
|
---|
| 3058 | value = '\\' + character;
|
---|
| 3059 | } else {
|
---|
| 3060 | value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
|
---|
| 3061 | }
|
---|
| 3062 | } else if (/[\t\n\f\r\x0B]/.test(character)) {
|
---|
| 3063 | value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
|
---|
| 3064 | } else if (character == '\\' || !isIdentifier && (character == '"' && quote == character || character == '\'' && quote == character) || isIdentifier && regexSingleEscape.test(character)) {
|
---|
| 3065 | value = '\\' + character;
|
---|
| 3066 | } else {
|
---|
| 3067 | value = character;
|
---|
| 3068 | }
|
---|
| 3069 | }
|
---|
| 3070 | output += value;
|
---|
| 3071 | }
|
---|
| 3072 |
|
---|
| 3073 | if (isIdentifier) {
|
---|
| 3074 | if (/^-[-\d]/.test(output)) {
|
---|
| 3075 | output = '\\-' + output.slice(1);
|
---|
| 3076 | } else if (/\d/.test(firstChar)) {
|
---|
| 3077 | output = '\\3' + firstChar + ' ' + output.slice(1);
|
---|
| 3078 | }
|
---|
| 3079 | }
|
---|
| 3080 |
|
---|
| 3081 | // Remove spaces after `\HEX` escapes that are not followed by a hex digit,
|
---|
| 3082 | // since they’re redundant. Note that this is only possible if the escape
|
---|
| 3083 | // sequence isn’t preceded by an odd number of backslashes.
|
---|
| 3084 | output = output.replace(regexExcessiveSpaces, function ($0, $1, $2) {
|
---|
| 3085 | if ($1 && $1.length % 2) {
|
---|
| 3086 | // It’s not safe to remove the space, so don’t.
|
---|
| 3087 | return $0;
|
---|
| 3088 | }
|
---|
| 3089 | // Strip the space.
|
---|
| 3090 | return ($1 || '') + $2;
|
---|
| 3091 | });
|
---|
| 3092 |
|
---|
| 3093 | if (!isIdentifier && options.wrap) {
|
---|
| 3094 | return quote + output + quote;
|
---|
| 3095 | }
|
---|
| 3096 | return output;
|
---|
| 3097 | };
|
---|
| 3098 |
|
---|
| 3099 | // Expose default options (so they can be overridden globally).
|
---|
| 3100 | cssesc.options = {
|
---|
| 3101 | 'escapeEverything': false,
|
---|
| 3102 | 'isIdentifier': false,
|
---|
| 3103 | 'quotes': 'single',
|
---|
| 3104 | 'wrap': false
|
---|
| 3105 | };
|
---|
| 3106 |
|
---|
| 3107 | cssesc.version = '3.0.0';
|
---|
| 3108 |
|
---|
| 3109 | var cssesc_1 = cssesc;
|
---|
| 3110 |
|
---|
| 3111 | (function (module, exports) {
|
---|
| 3112 |
|
---|
| 3113 | exports.__esModule = true;
|
---|
| 3114 | exports["default"] = undefined;
|
---|
| 3115 | var _cssesc = _interopRequireDefault(cssesc_1);
|
---|
| 3116 | var _util = util;
|
---|
| 3117 | var _node = _interopRequireDefault(nodeExports);
|
---|
| 3118 | var _types = types;
|
---|
| 3119 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
---|
| 3120 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
---|
| 3121 | function _createClass(Constructor, protoProps, staticProps) { _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
---|
| 3122 | function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
|
---|
| 3123 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
---|
| 3124 | var ClassName = /*#__PURE__*/function (_Node) {
|
---|
| 3125 | _inheritsLoose(ClassName, _Node);
|
---|
| 3126 | function ClassName(opts) {
|
---|
| 3127 | var _this;
|
---|
| 3128 | _this = _Node.call(this, opts) || this;
|
---|
| 3129 | _this.type = _types.CLASS;
|
---|
| 3130 | _this._constructed = true;
|
---|
| 3131 | return _this;
|
---|
| 3132 | }
|
---|
| 3133 | var _proto = ClassName.prototype;
|
---|
| 3134 | _proto.valueToString = function valueToString() {
|
---|
| 3135 | return '.' + _Node.prototype.valueToString.call(this);
|
---|
| 3136 | };
|
---|
| 3137 | _createClass(ClassName, [{
|
---|
| 3138 | key: "value",
|
---|
| 3139 | get: function get() {
|
---|
| 3140 | return this._value;
|
---|
| 3141 | },
|
---|
| 3142 | set: function set(v) {
|
---|
| 3143 | if (this._constructed) {
|
---|
| 3144 | var escaped = (0, _cssesc["default"])(v, {
|
---|
| 3145 | isIdentifier: true
|
---|
| 3146 | });
|
---|
| 3147 | if (escaped !== v) {
|
---|
| 3148 | (0, _util.ensureObject)(this, "raws");
|
---|
| 3149 | this.raws.value = escaped;
|
---|
| 3150 | } else if (this.raws) {
|
---|
| 3151 | delete this.raws.value;
|
---|
| 3152 | }
|
---|
| 3153 | }
|
---|
| 3154 | this._value = v;
|
---|
| 3155 | }
|
---|
| 3156 | }]);
|
---|
| 3157 | return ClassName;
|
---|
| 3158 | }(_node["default"]);
|
---|
| 3159 | exports["default"] = ClassName;
|
---|
| 3160 | module.exports = exports.default;
|
---|
| 3161 | } (className$1, className$1.exports));
|
---|
| 3162 |
|
---|
| 3163 | var classNameExports = className$1.exports;
|
---|
| 3164 |
|
---|
| 3165 | var comment$2 = {exports: {}};
|
---|
| 3166 |
|
---|
| 3167 | (function (module, exports) {
|
---|
| 3168 |
|
---|
| 3169 | exports.__esModule = true;
|
---|
| 3170 | exports["default"] = undefined;
|
---|
| 3171 | var _node = _interopRequireDefault(nodeExports);
|
---|
| 3172 | var _types = types;
|
---|
| 3173 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
---|
| 3174 | function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
|
---|
| 3175 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
---|
| 3176 | var Comment = /*#__PURE__*/function (_Node) {
|
---|
| 3177 | _inheritsLoose(Comment, _Node);
|
---|
| 3178 | function Comment(opts) {
|
---|
| 3179 | var _this;
|
---|
| 3180 | _this = _Node.call(this, opts) || this;
|
---|
| 3181 | _this.type = _types.COMMENT;
|
---|
| 3182 | return _this;
|
---|
| 3183 | }
|
---|
| 3184 | return Comment;
|
---|
| 3185 | }(_node["default"]);
|
---|
| 3186 | exports["default"] = Comment;
|
---|
| 3187 | module.exports = exports.default;
|
---|
| 3188 | } (comment$2, comment$2.exports));
|
---|
| 3189 |
|
---|
| 3190 | var commentExports = comment$2.exports;
|
---|
| 3191 |
|
---|
| 3192 | var id$1 = {exports: {}};
|
---|
| 3193 |
|
---|
| 3194 | (function (module, exports) {
|
---|
| 3195 |
|
---|
| 3196 | exports.__esModule = true;
|
---|
| 3197 | exports["default"] = undefined;
|
---|
| 3198 | var _node = _interopRequireDefault(nodeExports);
|
---|
| 3199 | var _types = types;
|
---|
| 3200 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
---|
| 3201 | function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
|
---|
| 3202 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
---|
| 3203 | var ID = /*#__PURE__*/function (_Node) {
|
---|
| 3204 | _inheritsLoose(ID, _Node);
|
---|
| 3205 | function ID(opts) {
|
---|
| 3206 | var _this;
|
---|
| 3207 | _this = _Node.call(this, opts) || this;
|
---|
| 3208 | _this.type = _types.ID;
|
---|
| 3209 | return _this;
|
---|
| 3210 | }
|
---|
| 3211 | var _proto = ID.prototype;
|
---|
| 3212 | _proto.valueToString = function valueToString() {
|
---|
| 3213 | return '#' + _Node.prototype.valueToString.call(this);
|
---|
| 3214 | };
|
---|
| 3215 | return ID;
|
---|
| 3216 | }(_node["default"]);
|
---|
| 3217 | exports["default"] = ID;
|
---|
| 3218 | module.exports = exports.default;
|
---|
| 3219 | } (id$1, id$1.exports));
|
---|
| 3220 |
|
---|
| 3221 | var idExports = id$1.exports;
|
---|
| 3222 |
|
---|
| 3223 | var tag$1 = {exports: {}};
|
---|
| 3224 |
|
---|
| 3225 | var namespace = {exports: {}};
|
---|
| 3226 |
|
---|
| 3227 | (function (module, exports) {
|
---|
| 3228 |
|
---|
| 3229 | exports.__esModule = true;
|
---|
| 3230 | exports["default"] = undefined;
|
---|
| 3231 | var _cssesc = _interopRequireDefault(cssesc_1);
|
---|
| 3232 | var _util = util;
|
---|
| 3233 | var _node = _interopRequireDefault(nodeExports);
|
---|
| 3234 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
---|
| 3235 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
---|
| 3236 | function _createClass(Constructor, protoProps, staticProps) { _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
---|
| 3237 | function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
|
---|
| 3238 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
---|
| 3239 | var Namespace = /*#__PURE__*/function (_Node) {
|
---|
| 3240 | _inheritsLoose(Namespace, _Node);
|
---|
| 3241 | function Namespace() {
|
---|
| 3242 | return _Node.apply(this, arguments) || this;
|
---|
| 3243 | }
|
---|
| 3244 | var _proto = Namespace.prototype;
|
---|
| 3245 | _proto.qualifiedName = function qualifiedName(value) {
|
---|
| 3246 | if (this.namespace) {
|
---|
| 3247 | return this.namespaceString + "|" + value;
|
---|
| 3248 | } else {
|
---|
| 3249 | return value;
|
---|
| 3250 | }
|
---|
| 3251 | };
|
---|
| 3252 | _proto.valueToString = function valueToString() {
|
---|
| 3253 | return this.qualifiedName(_Node.prototype.valueToString.call(this));
|
---|
| 3254 | };
|
---|
| 3255 | _createClass(Namespace, [{
|
---|
| 3256 | key: "namespace",
|
---|
| 3257 | get: function get() {
|
---|
| 3258 | return this._namespace;
|
---|
| 3259 | },
|
---|
| 3260 | set: function set(namespace) {
|
---|
| 3261 | if (namespace === true || namespace === "*" || namespace === "&") {
|
---|
| 3262 | this._namespace = namespace;
|
---|
| 3263 | if (this.raws) {
|
---|
| 3264 | delete this.raws.namespace;
|
---|
| 3265 | }
|
---|
| 3266 | return;
|
---|
| 3267 | }
|
---|
| 3268 | var escaped = (0, _cssesc["default"])(namespace, {
|
---|
| 3269 | isIdentifier: true
|
---|
| 3270 | });
|
---|
| 3271 | this._namespace = namespace;
|
---|
| 3272 | if (escaped !== namespace) {
|
---|
| 3273 | (0, _util.ensureObject)(this, "raws");
|
---|
| 3274 | this.raws.namespace = escaped;
|
---|
| 3275 | } else if (this.raws) {
|
---|
| 3276 | delete this.raws.namespace;
|
---|
| 3277 | }
|
---|
| 3278 | }
|
---|
| 3279 | }, {
|
---|
| 3280 | key: "ns",
|
---|
| 3281 | get: function get() {
|
---|
| 3282 | return this._namespace;
|
---|
| 3283 | },
|
---|
| 3284 | set: function set(namespace) {
|
---|
| 3285 | this.namespace = namespace;
|
---|
| 3286 | }
|
---|
| 3287 | }, {
|
---|
| 3288 | key: "namespaceString",
|
---|
| 3289 | get: function get() {
|
---|
| 3290 | if (this.namespace) {
|
---|
| 3291 | var ns = this.stringifyProperty("namespace");
|
---|
| 3292 | if (ns === true) {
|
---|
| 3293 | return '';
|
---|
| 3294 | } else {
|
---|
| 3295 | return ns;
|
---|
| 3296 | }
|
---|
| 3297 | } else {
|
---|
| 3298 | return '';
|
---|
| 3299 | }
|
---|
| 3300 | }
|
---|
| 3301 | }]);
|
---|
| 3302 | return Namespace;
|
---|
| 3303 | }(_node["default"]);
|
---|
| 3304 | exports["default"] = Namespace;
|
---|
| 3305 | module.exports = exports.default;
|
---|
| 3306 | } (namespace, namespace.exports));
|
---|
| 3307 |
|
---|
| 3308 | var namespaceExports = namespace.exports;
|
---|
| 3309 |
|
---|
| 3310 | (function (module, exports) {
|
---|
| 3311 |
|
---|
| 3312 | exports.__esModule = true;
|
---|
| 3313 | exports["default"] = undefined;
|
---|
| 3314 | var _namespace = _interopRequireDefault(namespaceExports);
|
---|
| 3315 | var _types = types;
|
---|
| 3316 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
---|
| 3317 | function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
|
---|
| 3318 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
---|
| 3319 | var Tag = /*#__PURE__*/function (_Namespace) {
|
---|
| 3320 | _inheritsLoose(Tag, _Namespace);
|
---|
| 3321 | function Tag(opts) {
|
---|
| 3322 | var _this;
|
---|
| 3323 | _this = _Namespace.call(this, opts) || this;
|
---|
| 3324 | _this.type = _types.TAG;
|
---|
| 3325 | return _this;
|
---|
| 3326 | }
|
---|
| 3327 | return Tag;
|
---|
| 3328 | }(_namespace["default"]);
|
---|
| 3329 | exports["default"] = Tag;
|
---|
| 3330 | module.exports = exports.default;
|
---|
| 3331 | } (tag$1, tag$1.exports));
|
---|
| 3332 |
|
---|
| 3333 | var tagExports = tag$1.exports;
|
---|
| 3334 |
|
---|
| 3335 | var string$1 = {exports: {}};
|
---|
| 3336 |
|
---|
| 3337 | (function (module, exports) {
|
---|
| 3338 |
|
---|
| 3339 | exports.__esModule = true;
|
---|
| 3340 | exports["default"] = undefined;
|
---|
| 3341 | var _node = _interopRequireDefault(nodeExports);
|
---|
| 3342 | var _types = types;
|
---|
| 3343 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
---|
| 3344 | function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
|
---|
| 3345 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
---|
| 3346 | var String = /*#__PURE__*/function (_Node) {
|
---|
| 3347 | _inheritsLoose(String, _Node);
|
---|
| 3348 | function String(opts) {
|
---|
| 3349 | var _this;
|
---|
| 3350 | _this = _Node.call(this, opts) || this;
|
---|
| 3351 | _this.type = _types.STRING;
|
---|
| 3352 | return _this;
|
---|
| 3353 | }
|
---|
| 3354 | return String;
|
---|
| 3355 | }(_node["default"]);
|
---|
| 3356 | exports["default"] = String;
|
---|
| 3357 | module.exports = exports.default;
|
---|
| 3358 | } (string$1, string$1.exports));
|
---|
| 3359 |
|
---|
| 3360 | var stringExports = string$1.exports;
|
---|
| 3361 |
|
---|
| 3362 | var pseudo$1 = {exports: {}};
|
---|
| 3363 |
|
---|
| 3364 | (function (module, exports) {
|
---|
| 3365 |
|
---|
| 3366 | exports.__esModule = true;
|
---|
| 3367 | exports["default"] = undefined;
|
---|
| 3368 | var _container = _interopRequireDefault(containerExports);
|
---|
| 3369 | var _types = types;
|
---|
| 3370 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
---|
| 3371 | function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
|
---|
| 3372 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
---|
| 3373 | var Pseudo = /*#__PURE__*/function (_Container) {
|
---|
| 3374 | _inheritsLoose(Pseudo, _Container);
|
---|
| 3375 | function Pseudo(opts) {
|
---|
| 3376 | var _this;
|
---|
| 3377 | _this = _Container.call(this, opts) || this;
|
---|
| 3378 | _this.type = _types.PSEUDO;
|
---|
| 3379 | return _this;
|
---|
| 3380 | }
|
---|
| 3381 | var _proto = Pseudo.prototype;
|
---|
| 3382 | _proto.toString = function toString() {
|
---|
| 3383 | var params = this.length ? '(' + this.map(String).join(',') + ')' : '';
|
---|
| 3384 | return [this.rawSpaceBefore, this.stringifyProperty("value"), params, this.rawSpaceAfter].join('');
|
---|
| 3385 | };
|
---|
| 3386 | return Pseudo;
|
---|
| 3387 | }(_container["default"]);
|
---|
| 3388 | exports["default"] = Pseudo;
|
---|
| 3389 | module.exports = exports.default;
|
---|
| 3390 | } (pseudo$1, pseudo$1.exports));
|
---|
| 3391 |
|
---|
| 3392 | var pseudoExports = pseudo$1.exports;
|
---|
| 3393 |
|
---|
| 3394 | var attribute$1 = {};
|
---|
| 3395 |
|
---|
| 3396 | /**
|
---|
| 3397 | * For Node.js, simply re-export the core `util.deprecate` function.
|
---|
| 3398 | */
|
---|
| 3399 |
|
---|
| 3400 | var node = require$$1.deprecate;
|
---|
| 3401 |
|
---|
| 3402 | (function (exports) {
|
---|
| 3403 |
|
---|
| 3404 | exports.__esModule = true;
|
---|
| 3405 | exports["default"] = undefined;
|
---|
| 3406 | exports.unescapeValue = unescapeValue;
|
---|
| 3407 | var _cssesc = _interopRequireDefault(cssesc_1);
|
---|
| 3408 | var _unesc = _interopRequireDefault(unescExports);
|
---|
| 3409 | var _namespace = _interopRequireDefault(namespaceExports);
|
---|
| 3410 | var _types = types;
|
---|
| 3411 | var _CSSESC_QUOTE_OPTIONS;
|
---|
| 3412 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
---|
| 3413 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
---|
| 3414 | function _createClass(Constructor, protoProps, staticProps) { _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
---|
| 3415 | function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
|
---|
| 3416 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
---|
| 3417 | var deprecate = node;
|
---|
| 3418 | var WRAPPED_IN_QUOTES = /^('|")([^]*)\1$/;
|
---|
| 3419 | var warnOfDeprecatedValueAssignment = deprecate(function () {}, "Assigning an attribute a value containing characters that might need to be escaped is deprecated. " + "Call attribute.setValue() instead.");
|
---|
| 3420 | var warnOfDeprecatedQuotedAssignment = deprecate(function () {}, "Assigning attr.quoted is deprecated and has no effect. Assign to attr.quoteMark instead.");
|
---|
| 3421 | var warnOfDeprecatedConstructor = deprecate(function () {}, "Constructing an Attribute selector with a value without specifying quoteMark is deprecated. Note: The value should be unescaped now.");
|
---|
| 3422 | function unescapeValue(value) {
|
---|
| 3423 | var deprecatedUsage = false;
|
---|
| 3424 | var quoteMark = null;
|
---|
| 3425 | var unescaped = value;
|
---|
| 3426 | var m = unescaped.match(WRAPPED_IN_QUOTES);
|
---|
| 3427 | if (m) {
|
---|
| 3428 | quoteMark = m[1];
|
---|
| 3429 | unescaped = m[2];
|
---|
| 3430 | }
|
---|
| 3431 | unescaped = (0, _unesc["default"])(unescaped);
|
---|
| 3432 | if (unescaped !== value) {
|
---|
| 3433 | deprecatedUsage = true;
|
---|
| 3434 | }
|
---|
| 3435 | return {
|
---|
| 3436 | deprecatedUsage: deprecatedUsage,
|
---|
| 3437 | unescaped: unescaped,
|
---|
| 3438 | quoteMark: quoteMark
|
---|
| 3439 | };
|
---|
| 3440 | }
|
---|
| 3441 | function handleDeprecatedContructorOpts(opts) {
|
---|
| 3442 | if (opts.quoteMark !== undefined) {
|
---|
| 3443 | return opts;
|
---|
| 3444 | }
|
---|
| 3445 | if (opts.value === undefined) {
|
---|
| 3446 | return opts;
|
---|
| 3447 | }
|
---|
| 3448 | warnOfDeprecatedConstructor();
|
---|
| 3449 | var _unescapeValue = unescapeValue(opts.value),
|
---|
| 3450 | quoteMark = _unescapeValue.quoteMark,
|
---|
| 3451 | unescaped = _unescapeValue.unescaped;
|
---|
| 3452 | if (!opts.raws) {
|
---|
| 3453 | opts.raws = {};
|
---|
| 3454 | }
|
---|
| 3455 | if (opts.raws.value === undefined) {
|
---|
| 3456 | opts.raws.value = opts.value;
|
---|
| 3457 | }
|
---|
| 3458 | opts.value = unescaped;
|
---|
| 3459 | opts.quoteMark = quoteMark;
|
---|
| 3460 | return opts;
|
---|
| 3461 | }
|
---|
| 3462 | var Attribute = /*#__PURE__*/function (_Namespace) {
|
---|
| 3463 | _inheritsLoose(Attribute, _Namespace);
|
---|
| 3464 | function Attribute(opts) {
|
---|
| 3465 | var _this;
|
---|
| 3466 | if (opts === undefined) {
|
---|
| 3467 | opts = {};
|
---|
| 3468 | }
|
---|
| 3469 | _this = _Namespace.call(this, handleDeprecatedContructorOpts(opts)) || this;
|
---|
| 3470 | _this.type = _types.ATTRIBUTE;
|
---|
| 3471 | _this.raws = _this.raws || {};
|
---|
| 3472 | Object.defineProperty(_this.raws, 'unquoted', {
|
---|
| 3473 | get: deprecate(function () {
|
---|
| 3474 | return _this.value;
|
---|
| 3475 | }, "attr.raws.unquoted is deprecated. Call attr.value instead."),
|
---|
| 3476 | set: deprecate(function () {
|
---|
| 3477 | return _this.value;
|
---|
| 3478 | }, "Setting attr.raws.unquoted is deprecated and has no effect. attr.value is unescaped by default now.")
|
---|
| 3479 | });
|
---|
| 3480 | _this._constructed = true;
|
---|
| 3481 | return _this;
|
---|
| 3482 | }
|
---|
| 3483 |
|
---|
| 3484 | /**
|
---|
| 3485 | * Returns the Attribute's value quoted such that it would be legal to use
|
---|
| 3486 | * in the value of a css file. The original value's quotation setting
|
---|
| 3487 | * used for stringification is left unchanged. See `setValue(value, options)`
|
---|
| 3488 | * if you want to control the quote settings of a new value for the attribute.
|
---|
| 3489 | *
|
---|
| 3490 | * You can also change the quotation used for the current value by setting quoteMark.
|
---|
| 3491 | *
|
---|
| 3492 | * Options:
|
---|
| 3493 | * * quoteMark {'"' | "'" | null} - Use this value to quote the value. If this
|
---|
| 3494 | * option is not set, the original value for quoteMark will be used. If
|
---|
| 3495 | * indeterminate, a double quote is used. The legal values are:
|
---|
| 3496 | * * `null` - the value will be unquoted and characters will be escaped as necessary.
|
---|
| 3497 | * * `'` - the value will be quoted with a single quote and single quotes are escaped.
|
---|
| 3498 | * * `"` - the value will be quoted with a double quote and double quotes are escaped.
|
---|
| 3499 | * * preferCurrentQuoteMark {boolean} - if true, prefer the source quote mark
|
---|
| 3500 | * over the quoteMark option value.
|
---|
| 3501 | * * smart {boolean} - if true, will select a quote mark based on the value
|
---|
| 3502 | * and the other options specified here. See the `smartQuoteMark()`
|
---|
| 3503 | * method.
|
---|
| 3504 | **/
|
---|
| 3505 | var _proto = Attribute.prototype;
|
---|
| 3506 | _proto.getQuotedValue = function getQuotedValue(options) {
|
---|
| 3507 | if (options === undefined) {
|
---|
| 3508 | options = {};
|
---|
| 3509 | }
|
---|
| 3510 | var quoteMark = this._determineQuoteMark(options);
|
---|
| 3511 | var cssescopts = CSSESC_QUOTE_OPTIONS[quoteMark];
|
---|
| 3512 | var escaped = (0, _cssesc["default"])(this._value, cssescopts);
|
---|
| 3513 | return escaped;
|
---|
| 3514 | };
|
---|
| 3515 | _proto._determineQuoteMark = function _determineQuoteMark(options) {
|
---|
| 3516 | return options.smart ? this.smartQuoteMark(options) : this.preferredQuoteMark(options);
|
---|
| 3517 | }
|
---|
| 3518 |
|
---|
| 3519 | /**
|
---|
| 3520 | * Set the unescaped value with the specified quotation options. The value
|
---|
| 3521 | * provided must not include any wrapping quote marks -- those quotes will
|
---|
| 3522 | * be interpreted as part of the value and escaped accordingly.
|
---|
| 3523 | */;
|
---|
| 3524 | _proto.setValue = function setValue(value, options) {
|
---|
| 3525 | if (options === undefined) {
|
---|
| 3526 | options = {};
|
---|
| 3527 | }
|
---|
| 3528 | this._value = value;
|
---|
| 3529 | this._quoteMark = this._determineQuoteMark(options);
|
---|
| 3530 | this._syncRawValue();
|
---|
| 3531 | }
|
---|
| 3532 |
|
---|
| 3533 | /**
|
---|
| 3534 | * Intelligently select a quoteMark value based on the value's contents. If
|
---|
| 3535 | * the value is a legal CSS ident, it will not be quoted. Otherwise a quote
|
---|
| 3536 | * mark will be picked that minimizes the number of escapes.
|
---|
| 3537 | *
|
---|
| 3538 | * If there's no clear winner, the quote mark from these options is used,
|
---|
| 3539 | * then the source quote mark (this is inverted if `preferCurrentQuoteMark` is
|
---|
| 3540 | * true). If the quoteMark is unspecified, a double quote is used.
|
---|
| 3541 | *
|
---|
| 3542 | * @param options This takes the quoteMark and preferCurrentQuoteMark options
|
---|
| 3543 | * from the quoteValue method.
|
---|
| 3544 | */;
|
---|
| 3545 | _proto.smartQuoteMark = function smartQuoteMark(options) {
|
---|
| 3546 | var v = this.value;
|
---|
| 3547 | var numSingleQuotes = v.replace(/[^']/g, '').length;
|
---|
| 3548 | var numDoubleQuotes = v.replace(/[^"]/g, '').length;
|
---|
| 3549 | if (numSingleQuotes + numDoubleQuotes === 0) {
|
---|
| 3550 | var escaped = (0, _cssesc["default"])(v, {
|
---|
| 3551 | isIdentifier: true
|
---|
| 3552 | });
|
---|
| 3553 | if (escaped === v) {
|
---|
| 3554 | return Attribute.NO_QUOTE;
|
---|
| 3555 | } else {
|
---|
| 3556 | var pref = this.preferredQuoteMark(options);
|
---|
| 3557 | if (pref === Attribute.NO_QUOTE) {
|
---|
| 3558 | // pick a quote mark that isn't none and see if it's smaller
|
---|
| 3559 | var quote = this.quoteMark || options.quoteMark || Attribute.DOUBLE_QUOTE;
|
---|
| 3560 | var opts = CSSESC_QUOTE_OPTIONS[quote];
|
---|
| 3561 | var quoteValue = (0, _cssesc["default"])(v, opts);
|
---|
| 3562 | if (quoteValue.length < escaped.length) {
|
---|
| 3563 | return quote;
|
---|
| 3564 | }
|
---|
| 3565 | }
|
---|
| 3566 | return pref;
|
---|
| 3567 | }
|
---|
| 3568 | } else if (numDoubleQuotes === numSingleQuotes) {
|
---|
| 3569 | return this.preferredQuoteMark(options);
|
---|
| 3570 | } else if (numDoubleQuotes < numSingleQuotes) {
|
---|
| 3571 | return Attribute.DOUBLE_QUOTE;
|
---|
| 3572 | } else {
|
---|
| 3573 | return Attribute.SINGLE_QUOTE;
|
---|
| 3574 | }
|
---|
| 3575 | }
|
---|
| 3576 |
|
---|
| 3577 | /**
|
---|
| 3578 | * Selects the preferred quote mark based on the options and the current quote mark value.
|
---|
| 3579 | * If you want the quote mark to depend on the attribute value, call `smartQuoteMark(opts)`
|
---|
| 3580 | * instead.
|
---|
| 3581 | */;
|
---|
| 3582 | _proto.preferredQuoteMark = function preferredQuoteMark(options) {
|
---|
| 3583 | var quoteMark = options.preferCurrentQuoteMark ? this.quoteMark : options.quoteMark;
|
---|
| 3584 | if (quoteMark === undefined) {
|
---|
| 3585 | quoteMark = options.preferCurrentQuoteMark ? options.quoteMark : this.quoteMark;
|
---|
| 3586 | }
|
---|
| 3587 | if (quoteMark === undefined) {
|
---|
| 3588 | quoteMark = Attribute.DOUBLE_QUOTE;
|
---|
| 3589 | }
|
---|
| 3590 | return quoteMark;
|
---|
| 3591 | };
|
---|
| 3592 | _proto._syncRawValue = function _syncRawValue() {
|
---|
| 3593 | var rawValue = (0, _cssesc["default"])(this._value, CSSESC_QUOTE_OPTIONS[this.quoteMark]);
|
---|
| 3594 | if (rawValue === this._value) {
|
---|
| 3595 | if (this.raws) {
|
---|
| 3596 | delete this.raws.value;
|
---|
| 3597 | }
|
---|
| 3598 | } else {
|
---|
| 3599 | this.raws.value = rawValue;
|
---|
| 3600 | }
|
---|
| 3601 | };
|
---|
| 3602 | _proto._handleEscapes = function _handleEscapes(prop, value) {
|
---|
| 3603 | if (this._constructed) {
|
---|
| 3604 | var escaped = (0, _cssesc["default"])(value, {
|
---|
| 3605 | isIdentifier: true
|
---|
| 3606 | });
|
---|
| 3607 | if (escaped !== value) {
|
---|
| 3608 | this.raws[prop] = escaped;
|
---|
| 3609 | } else {
|
---|
| 3610 | delete this.raws[prop];
|
---|
| 3611 | }
|
---|
| 3612 | }
|
---|
| 3613 | };
|
---|
| 3614 | _proto._spacesFor = function _spacesFor(name) {
|
---|
| 3615 | var attrSpaces = {
|
---|
| 3616 | before: '',
|
---|
| 3617 | after: ''
|
---|
| 3618 | };
|
---|
| 3619 | var spaces = this.spaces[name] || {};
|
---|
| 3620 | var rawSpaces = this.raws.spaces && this.raws.spaces[name] || {};
|
---|
| 3621 | return Object.assign(attrSpaces, spaces, rawSpaces);
|
---|
| 3622 | };
|
---|
| 3623 | _proto._stringFor = function _stringFor(name, spaceName, concat) {
|
---|
| 3624 | if (spaceName === undefined) {
|
---|
| 3625 | spaceName = name;
|
---|
| 3626 | }
|
---|
| 3627 | if (concat === undefined) {
|
---|
| 3628 | concat = defaultAttrConcat;
|
---|
| 3629 | }
|
---|
| 3630 | var attrSpaces = this._spacesFor(spaceName);
|
---|
| 3631 | return concat(this.stringifyProperty(name), attrSpaces);
|
---|
| 3632 | }
|
---|
| 3633 |
|
---|
| 3634 | /**
|
---|
| 3635 | * returns the offset of the attribute part specified relative to the
|
---|
| 3636 | * start of the node of the output string.
|
---|
| 3637 | *
|
---|
| 3638 | * * "ns" - alias for "namespace"
|
---|
| 3639 | * * "namespace" - the namespace if it exists.
|
---|
| 3640 | * * "attribute" - the attribute name
|
---|
| 3641 | * * "attributeNS" - the start of the attribute or its namespace
|
---|
| 3642 | * * "operator" - the match operator of the attribute
|
---|
| 3643 | * * "value" - The value (string or identifier)
|
---|
| 3644 | * * "insensitive" - the case insensitivity flag;
|
---|
| 3645 | * @param part One of the possible values inside an attribute.
|
---|
| 3646 | * @returns -1 if the name is invalid or the value doesn't exist in this attribute.
|
---|
| 3647 | */;
|
---|
| 3648 | _proto.offsetOf = function offsetOf(name) {
|
---|
| 3649 | var count = 1;
|
---|
| 3650 | var attributeSpaces = this._spacesFor("attribute");
|
---|
| 3651 | count += attributeSpaces.before.length;
|
---|
| 3652 | if (name === "namespace" || name === "ns") {
|
---|
| 3653 | return this.namespace ? count : -1;
|
---|
| 3654 | }
|
---|
| 3655 | if (name === "attributeNS") {
|
---|
| 3656 | return count;
|
---|
| 3657 | }
|
---|
| 3658 | count += this.namespaceString.length;
|
---|
| 3659 | if (this.namespace) {
|
---|
| 3660 | count += 1;
|
---|
| 3661 | }
|
---|
| 3662 | if (name === "attribute") {
|
---|
| 3663 | return count;
|
---|
| 3664 | }
|
---|
| 3665 | count += this.stringifyProperty("attribute").length;
|
---|
| 3666 | count += attributeSpaces.after.length;
|
---|
| 3667 | var operatorSpaces = this._spacesFor("operator");
|
---|
| 3668 | count += operatorSpaces.before.length;
|
---|
| 3669 | var operator = this.stringifyProperty("operator");
|
---|
| 3670 | if (name === "operator") {
|
---|
| 3671 | return operator ? count : -1;
|
---|
| 3672 | }
|
---|
| 3673 | count += operator.length;
|
---|
| 3674 | count += operatorSpaces.after.length;
|
---|
| 3675 | var valueSpaces = this._spacesFor("value");
|
---|
| 3676 | count += valueSpaces.before.length;
|
---|
| 3677 | var value = this.stringifyProperty("value");
|
---|
| 3678 | if (name === "value") {
|
---|
| 3679 | return value ? count : -1;
|
---|
| 3680 | }
|
---|
| 3681 | count += value.length;
|
---|
| 3682 | count += valueSpaces.after.length;
|
---|
| 3683 | var insensitiveSpaces = this._spacesFor("insensitive");
|
---|
| 3684 | count += insensitiveSpaces.before.length;
|
---|
| 3685 | if (name === "insensitive") {
|
---|
| 3686 | return this.insensitive ? count : -1;
|
---|
| 3687 | }
|
---|
| 3688 | return -1;
|
---|
| 3689 | };
|
---|
| 3690 | _proto.toString = function toString() {
|
---|
| 3691 | var _this2 = this;
|
---|
| 3692 | var selector = [this.rawSpaceBefore, '['];
|
---|
| 3693 | selector.push(this._stringFor('qualifiedAttribute', 'attribute'));
|
---|
| 3694 | if (this.operator && (this.value || this.value === '')) {
|
---|
| 3695 | selector.push(this._stringFor('operator'));
|
---|
| 3696 | selector.push(this._stringFor('value'));
|
---|
| 3697 | selector.push(this._stringFor('insensitiveFlag', 'insensitive', function (attrValue, attrSpaces) {
|
---|
| 3698 | if (attrValue.length > 0 && !_this2.quoted && attrSpaces.before.length === 0 && !(_this2.spaces.value && _this2.spaces.value.after)) {
|
---|
| 3699 | attrSpaces.before = " ";
|
---|
| 3700 | }
|
---|
| 3701 | return defaultAttrConcat(attrValue, attrSpaces);
|
---|
| 3702 | }));
|
---|
| 3703 | }
|
---|
| 3704 | selector.push(']');
|
---|
| 3705 | selector.push(this.rawSpaceAfter);
|
---|
| 3706 | return selector.join('');
|
---|
| 3707 | };
|
---|
| 3708 | _createClass(Attribute, [{
|
---|
| 3709 | key: "quoted",
|
---|
| 3710 | get: function get() {
|
---|
| 3711 | var qm = this.quoteMark;
|
---|
| 3712 | return qm === "'" || qm === '"';
|
---|
| 3713 | },
|
---|
| 3714 | set: function set(value) {
|
---|
| 3715 | warnOfDeprecatedQuotedAssignment();
|
---|
| 3716 | }
|
---|
| 3717 |
|
---|
| 3718 | /**
|
---|
| 3719 | * returns a single (`'`) or double (`"`) quote character if the value is quoted.
|
---|
| 3720 | * returns `null` if the value is not quoted.
|
---|
| 3721 | * returns `undefined` if the quotation state is unknown (this can happen when
|
---|
| 3722 | * the attribute is constructed without specifying a quote mark.)
|
---|
| 3723 | */
|
---|
| 3724 | }, {
|
---|
| 3725 | key: "quoteMark",
|
---|
| 3726 | get: function get() {
|
---|
| 3727 | return this._quoteMark;
|
---|
| 3728 | }
|
---|
| 3729 |
|
---|
| 3730 | /**
|
---|
| 3731 | * Set the quote mark to be used by this attribute's value.
|
---|
| 3732 | * If the quote mark changes, the raw (escaped) value at `attr.raws.value` of the attribute
|
---|
| 3733 | * value is updated accordingly.
|
---|
| 3734 | *
|
---|
| 3735 | * @param {"'" | '"' | null} quoteMark The quote mark or `null` if the value should be unquoted.
|
---|
| 3736 | */,
|
---|
| 3737 | set: function set(quoteMark) {
|
---|
| 3738 | if (!this._constructed) {
|
---|
| 3739 | this._quoteMark = quoteMark;
|
---|
| 3740 | return;
|
---|
| 3741 | }
|
---|
| 3742 | if (this._quoteMark !== quoteMark) {
|
---|
| 3743 | this._quoteMark = quoteMark;
|
---|
| 3744 | this._syncRawValue();
|
---|
| 3745 | }
|
---|
| 3746 | }
|
---|
| 3747 | }, {
|
---|
| 3748 | key: "qualifiedAttribute",
|
---|
| 3749 | get: function get() {
|
---|
| 3750 | return this.qualifiedName(this.raws.attribute || this.attribute);
|
---|
| 3751 | }
|
---|
| 3752 | }, {
|
---|
| 3753 | key: "insensitiveFlag",
|
---|
| 3754 | get: function get() {
|
---|
| 3755 | return this.insensitive ? 'i' : '';
|
---|
| 3756 | }
|
---|
| 3757 | }, {
|
---|
| 3758 | key: "value",
|
---|
| 3759 | get: function get() {
|
---|
| 3760 | return this._value;
|
---|
| 3761 | },
|
---|
| 3762 | set:
|
---|
| 3763 | /**
|
---|
| 3764 | * Before 3.0, the value had to be set to an escaped value including any wrapped
|
---|
| 3765 | * quote marks. In 3.0, the semantics of `Attribute.value` changed so that the value
|
---|
| 3766 | * is unescaped during parsing and any quote marks are removed.
|
---|
| 3767 | *
|
---|
| 3768 | * Because the ambiguity of this semantic change, if you set `attr.value = newValue`,
|
---|
| 3769 | * a deprecation warning is raised when the new value contains any characters that would
|
---|
| 3770 | * require escaping (including if it contains wrapped quotes).
|
---|
| 3771 | *
|
---|
| 3772 | * Instead, you should call `attr.setValue(newValue, opts)` and pass options that describe
|
---|
| 3773 | * how the new value is quoted.
|
---|
| 3774 | */
|
---|
| 3775 | function set(v) {
|
---|
| 3776 | if (this._constructed) {
|
---|
| 3777 | var _unescapeValue2 = unescapeValue(v),
|
---|
| 3778 | deprecatedUsage = _unescapeValue2.deprecatedUsage,
|
---|
| 3779 | unescaped = _unescapeValue2.unescaped,
|
---|
| 3780 | quoteMark = _unescapeValue2.quoteMark;
|
---|
| 3781 | if (deprecatedUsage) {
|
---|
| 3782 | warnOfDeprecatedValueAssignment();
|
---|
| 3783 | }
|
---|
| 3784 | if (unescaped === this._value && quoteMark === this._quoteMark) {
|
---|
| 3785 | return;
|
---|
| 3786 | }
|
---|
| 3787 | this._value = unescaped;
|
---|
| 3788 | this._quoteMark = quoteMark;
|
---|
| 3789 | this._syncRawValue();
|
---|
| 3790 | } else {
|
---|
| 3791 | this._value = v;
|
---|
| 3792 | }
|
---|
| 3793 | }
|
---|
| 3794 | }, {
|
---|
| 3795 | key: "insensitive",
|
---|
| 3796 | get: function get() {
|
---|
| 3797 | return this._insensitive;
|
---|
| 3798 | }
|
---|
| 3799 |
|
---|
| 3800 | /**
|
---|
| 3801 | * Set the case insensitive flag.
|
---|
| 3802 | * If the case insensitive flag changes, the raw (escaped) value at `attr.raws.insensitiveFlag`
|
---|
| 3803 | * of the attribute is updated accordingly.
|
---|
| 3804 | *
|
---|
| 3805 | * @param {true | false} insensitive true if the attribute should match case-insensitively.
|
---|
| 3806 | */,
|
---|
| 3807 | set: function set(insensitive) {
|
---|
| 3808 | if (!insensitive) {
|
---|
| 3809 | this._insensitive = false;
|
---|
| 3810 |
|
---|
| 3811 | // "i" and "I" can be used in "this.raws.insensitiveFlag" to store the original notation.
|
---|
| 3812 | // When setting `attr.insensitive = false` both should be erased to ensure correct serialization.
|
---|
| 3813 | if (this.raws && (this.raws.insensitiveFlag === 'I' || this.raws.insensitiveFlag === 'i')) {
|
---|
| 3814 | this.raws.insensitiveFlag = undefined;
|
---|
| 3815 | }
|
---|
| 3816 | }
|
---|
| 3817 | this._insensitive = insensitive;
|
---|
| 3818 | }
|
---|
| 3819 | }, {
|
---|
| 3820 | key: "attribute",
|
---|
| 3821 | get: function get() {
|
---|
| 3822 | return this._attribute;
|
---|
| 3823 | },
|
---|
| 3824 | set: function set(name) {
|
---|
| 3825 | this._handleEscapes("attribute", name);
|
---|
| 3826 | this._attribute = name;
|
---|
| 3827 | }
|
---|
| 3828 | }]);
|
---|
| 3829 | return Attribute;
|
---|
| 3830 | }(_namespace["default"]);
|
---|
| 3831 | exports["default"] = Attribute;
|
---|
| 3832 | Attribute.NO_QUOTE = null;
|
---|
| 3833 | Attribute.SINGLE_QUOTE = "'";
|
---|
| 3834 | Attribute.DOUBLE_QUOTE = '"';
|
---|
| 3835 | var CSSESC_QUOTE_OPTIONS = (_CSSESC_QUOTE_OPTIONS = {
|
---|
| 3836 | "'": {
|
---|
| 3837 | quotes: 'single',
|
---|
| 3838 | wrap: true
|
---|
| 3839 | },
|
---|
| 3840 | '"': {
|
---|
| 3841 | quotes: 'double',
|
---|
| 3842 | wrap: true
|
---|
| 3843 | }
|
---|
| 3844 | }, _CSSESC_QUOTE_OPTIONS[null] = {
|
---|
| 3845 | isIdentifier: true
|
---|
| 3846 | }, _CSSESC_QUOTE_OPTIONS);
|
---|
| 3847 | function defaultAttrConcat(attrValue, attrSpaces) {
|
---|
| 3848 | return "" + attrSpaces.before + attrValue + attrSpaces.after;
|
---|
| 3849 | }
|
---|
| 3850 | } (attribute$1));
|
---|
| 3851 |
|
---|
| 3852 | var universal$1 = {exports: {}};
|
---|
| 3853 |
|
---|
| 3854 | (function (module, exports) {
|
---|
| 3855 |
|
---|
| 3856 | exports.__esModule = true;
|
---|
| 3857 | exports["default"] = undefined;
|
---|
| 3858 | var _namespace = _interopRequireDefault(namespaceExports);
|
---|
| 3859 | var _types = types;
|
---|
| 3860 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
---|
| 3861 | function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
|
---|
| 3862 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
---|
| 3863 | var Universal = /*#__PURE__*/function (_Namespace) {
|
---|
| 3864 | _inheritsLoose(Universal, _Namespace);
|
---|
| 3865 | function Universal(opts) {
|
---|
| 3866 | var _this;
|
---|
| 3867 | _this = _Namespace.call(this, opts) || this;
|
---|
| 3868 | _this.type = _types.UNIVERSAL;
|
---|
| 3869 | _this.value = '*';
|
---|
| 3870 | return _this;
|
---|
| 3871 | }
|
---|
| 3872 | return Universal;
|
---|
| 3873 | }(_namespace["default"]);
|
---|
| 3874 | exports["default"] = Universal;
|
---|
| 3875 | module.exports = exports.default;
|
---|
| 3876 | } (universal$1, universal$1.exports));
|
---|
| 3877 |
|
---|
| 3878 | var universalExports = universal$1.exports;
|
---|
| 3879 |
|
---|
| 3880 | var combinator$2 = {exports: {}};
|
---|
| 3881 |
|
---|
| 3882 | (function (module, exports) {
|
---|
| 3883 |
|
---|
| 3884 | exports.__esModule = true;
|
---|
| 3885 | exports["default"] = undefined;
|
---|
| 3886 | var _node = _interopRequireDefault(nodeExports);
|
---|
| 3887 | var _types = types;
|
---|
| 3888 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
---|
| 3889 | function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
|
---|
| 3890 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
---|
| 3891 | var Combinator = /*#__PURE__*/function (_Node) {
|
---|
| 3892 | _inheritsLoose(Combinator, _Node);
|
---|
| 3893 | function Combinator(opts) {
|
---|
| 3894 | var _this;
|
---|
| 3895 | _this = _Node.call(this, opts) || this;
|
---|
| 3896 | _this.type = _types.COMBINATOR;
|
---|
| 3897 | return _this;
|
---|
| 3898 | }
|
---|
| 3899 | return Combinator;
|
---|
| 3900 | }(_node["default"]);
|
---|
| 3901 | exports["default"] = Combinator;
|
---|
| 3902 | module.exports = exports.default;
|
---|
| 3903 | } (combinator$2, combinator$2.exports));
|
---|
| 3904 |
|
---|
| 3905 | var combinatorExports = combinator$2.exports;
|
---|
| 3906 |
|
---|
| 3907 | var nesting$1 = {exports: {}};
|
---|
| 3908 |
|
---|
| 3909 | (function (module, exports) {
|
---|
| 3910 |
|
---|
| 3911 | exports.__esModule = true;
|
---|
| 3912 | exports["default"] = undefined;
|
---|
| 3913 | var _node = _interopRequireDefault(nodeExports);
|
---|
| 3914 | var _types = types;
|
---|
| 3915 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
---|
| 3916 | function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
|
---|
| 3917 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
---|
| 3918 | var Nesting = /*#__PURE__*/function (_Node) {
|
---|
| 3919 | _inheritsLoose(Nesting, _Node);
|
---|
| 3920 | function Nesting(opts) {
|
---|
| 3921 | var _this;
|
---|
| 3922 | _this = _Node.call(this, opts) || this;
|
---|
| 3923 | _this.type = _types.NESTING;
|
---|
| 3924 | _this.value = '&';
|
---|
| 3925 | return _this;
|
---|
| 3926 | }
|
---|
| 3927 | return Nesting;
|
---|
| 3928 | }(_node["default"]);
|
---|
| 3929 | exports["default"] = Nesting;
|
---|
| 3930 | module.exports = exports.default;
|
---|
| 3931 | } (nesting$1, nesting$1.exports));
|
---|
| 3932 |
|
---|
| 3933 | var nestingExports = nesting$1.exports;
|
---|
| 3934 |
|
---|
| 3935 | var sortAscending = {exports: {}};
|
---|
| 3936 |
|
---|
| 3937 | (function (module, exports) {
|
---|
| 3938 |
|
---|
| 3939 | exports.__esModule = true;
|
---|
| 3940 | exports["default"] = sortAscending;
|
---|
| 3941 | function sortAscending(list) {
|
---|
| 3942 | return list.sort(function (a, b) {
|
---|
| 3943 | return a - b;
|
---|
| 3944 | });
|
---|
| 3945 | }
|
---|
| 3946 | module.exports = exports.default;
|
---|
| 3947 | } (sortAscending, sortAscending.exports));
|
---|
| 3948 |
|
---|
| 3949 | var sortAscendingExports = sortAscending.exports;
|
---|
| 3950 |
|
---|
| 3951 | var tokenize = {};
|
---|
| 3952 |
|
---|
| 3953 | var tokenTypes = {};
|
---|
| 3954 |
|
---|
| 3955 | tokenTypes.__esModule = true;
|
---|
| 3956 | tokenTypes.word = tokenTypes.tilde = tokenTypes.tab = tokenTypes.str = tokenTypes.space = tokenTypes.slash = tokenTypes.singleQuote = tokenTypes.semicolon = tokenTypes.plus = tokenTypes.pipe = tokenTypes.openSquare = tokenTypes.openParenthesis = tokenTypes.newline = tokenTypes.greaterThan = tokenTypes.feed = tokenTypes.equals = tokenTypes.doubleQuote = tokenTypes.dollar = tokenTypes.cr = tokenTypes.comment = tokenTypes.comma = tokenTypes.combinator = tokenTypes.colon = tokenTypes.closeSquare = tokenTypes.closeParenthesis = tokenTypes.caret = tokenTypes.bang = tokenTypes.backslash = tokenTypes.at = tokenTypes.asterisk = tokenTypes.ampersand = undefined;
|
---|
| 3957 | var ampersand = 38; // `&`.charCodeAt(0);
|
---|
| 3958 | tokenTypes.ampersand = ampersand;
|
---|
| 3959 | var asterisk = 42; // `*`.charCodeAt(0);
|
---|
| 3960 | tokenTypes.asterisk = asterisk;
|
---|
| 3961 | var at = 64; // `@`.charCodeAt(0);
|
---|
| 3962 | tokenTypes.at = at;
|
---|
| 3963 | var comma = 44; // `,`.charCodeAt(0);
|
---|
| 3964 | tokenTypes.comma = comma;
|
---|
| 3965 | var colon = 58; // `:`.charCodeAt(0);
|
---|
| 3966 | tokenTypes.colon = colon;
|
---|
| 3967 | var semicolon = 59; // `;`.charCodeAt(0);
|
---|
| 3968 | tokenTypes.semicolon = semicolon;
|
---|
| 3969 | var openParenthesis = 40; // `(`.charCodeAt(0);
|
---|
| 3970 | tokenTypes.openParenthesis = openParenthesis;
|
---|
| 3971 | var closeParenthesis = 41; // `)`.charCodeAt(0);
|
---|
| 3972 | tokenTypes.closeParenthesis = closeParenthesis;
|
---|
| 3973 | var openSquare = 91; // `[`.charCodeAt(0);
|
---|
| 3974 | tokenTypes.openSquare = openSquare;
|
---|
| 3975 | var closeSquare = 93; // `]`.charCodeAt(0);
|
---|
| 3976 | tokenTypes.closeSquare = closeSquare;
|
---|
| 3977 | var dollar = 36; // `$`.charCodeAt(0);
|
---|
| 3978 | tokenTypes.dollar = dollar;
|
---|
| 3979 | var tilde = 126; // `~`.charCodeAt(0);
|
---|
| 3980 | tokenTypes.tilde = tilde;
|
---|
| 3981 | var caret = 94; // `^`.charCodeAt(0);
|
---|
| 3982 | tokenTypes.caret = caret;
|
---|
| 3983 | var plus = 43; // `+`.charCodeAt(0);
|
---|
| 3984 | tokenTypes.plus = plus;
|
---|
| 3985 | var equals = 61; // `=`.charCodeAt(0);
|
---|
| 3986 | tokenTypes.equals = equals;
|
---|
| 3987 | var pipe = 124; // `|`.charCodeAt(0);
|
---|
| 3988 | tokenTypes.pipe = pipe;
|
---|
| 3989 | var greaterThan = 62; // `>`.charCodeAt(0);
|
---|
| 3990 | tokenTypes.greaterThan = greaterThan;
|
---|
| 3991 | var space = 32; // ` `.charCodeAt(0);
|
---|
| 3992 | tokenTypes.space = space;
|
---|
| 3993 | var singleQuote = 39; // `'`.charCodeAt(0);
|
---|
| 3994 | tokenTypes.singleQuote = singleQuote;
|
---|
| 3995 | var doubleQuote = 34; // `"`.charCodeAt(0);
|
---|
| 3996 | tokenTypes.doubleQuote = doubleQuote;
|
---|
| 3997 | var slash = 47; // `/`.charCodeAt(0);
|
---|
| 3998 | tokenTypes.slash = slash;
|
---|
| 3999 | var bang = 33; // `!`.charCodeAt(0);
|
---|
| 4000 | tokenTypes.bang = bang;
|
---|
| 4001 | var backslash = 92; // '\\'.charCodeAt(0);
|
---|
| 4002 | tokenTypes.backslash = backslash;
|
---|
| 4003 | var cr = 13; // '\r'.charCodeAt(0);
|
---|
| 4004 | tokenTypes.cr = cr;
|
---|
| 4005 | var feed = 12; // '\f'.charCodeAt(0);
|
---|
| 4006 | tokenTypes.feed = feed;
|
---|
| 4007 | var newline = 10; // '\n'.charCodeAt(0);
|
---|
| 4008 | tokenTypes.newline = newline;
|
---|
| 4009 | var tab = 9; // '\t'.charCodeAt(0);
|
---|
| 4010 |
|
---|
| 4011 | // Expose aliases primarily for readability.
|
---|
| 4012 | tokenTypes.tab = tab;
|
---|
| 4013 | var str = singleQuote;
|
---|
| 4014 |
|
---|
| 4015 | // No good single character representation!
|
---|
| 4016 | tokenTypes.str = str;
|
---|
| 4017 | var comment$1 = -1;
|
---|
| 4018 | tokenTypes.comment = comment$1;
|
---|
| 4019 | var word = -2;
|
---|
| 4020 | tokenTypes.word = word;
|
---|
| 4021 | var combinator$1 = -3;
|
---|
| 4022 | tokenTypes.combinator = combinator$1;
|
---|
| 4023 |
|
---|
| 4024 | (function (exports) {
|
---|
| 4025 |
|
---|
| 4026 | exports.__esModule = true;
|
---|
| 4027 | exports.FIELDS = undefined;
|
---|
| 4028 | exports["default"] = tokenize;
|
---|
| 4029 | var t = _interopRequireWildcard(tokenTypes);
|
---|
| 4030 | var _unescapable, _wordDelimiters;
|
---|
| 4031 | function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
---|
| 4032 | function _interopRequireWildcard(obj, nodeInterop) { if (obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
---|
| 4033 | var unescapable = (_unescapable = {}, _unescapable[t.tab] = true, _unescapable[t.newline] = true, _unescapable[t.cr] = true, _unescapable[t.feed] = true, _unescapable);
|
---|
| 4034 | var wordDelimiters = (_wordDelimiters = {}, _wordDelimiters[t.space] = true, _wordDelimiters[t.tab] = true, _wordDelimiters[t.newline] = true, _wordDelimiters[t.cr] = true, _wordDelimiters[t.feed] = true, _wordDelimiters[t.ampersand] = true, _wordDelimiters[t.asterisk] = true, _wordDelimiters[t.bang] = true, _wordDelimiters[t.comma] = true, _wordDelimiters[t.colon] = true, _wordDelimiters[t.semicolon] = true, _wordDelimiters[t.openParenthesis] = true, _wordDelimiters[t.closeParenthesis] = true, _wordDelimiters[t.openSquare] = true, _wordDelimiters[t.closeSquare] = true, _wordDelimiters[t.singleQuote] = true, _wordDelimiters[t.doubleQuote] = true, _wordDelimiters[t.plus] = true, _wordDelimiters[t.pipe] = true, _wordDelimiters[t.tilde] = true, _wordDelimiters[t.greaterThan] = true, _wordDelimiters[t.equals] = true, _wordDelimiters[t.dollar] = true, _wordDelimiters[t.caret] = true, _wordDelimiters[t.slash] = true, _wordDelimiters);
|
---|
| 4035 | var hex = {};
|
---|
| 4036 | var hexChars = "0123456789abcdefABCDEF";
|
---|
| 4037 | for (var i = 0; i < hexChars.length; i++) {
|
---|
| 4038 | hex[hexChars.charCodeAt(i)] = true;
|
---|
| 4039 | }
|
---|
| 4040 |
|
---|
| 4041 | /**
|
---|
| 4042 | * Returns the last index of the bar css word
|
---|
| 4043 | * @param {string} css The string in which the word begins
|
---|
| 4044 | * @param {number} start The index into the string where word's first letter occurs
|
---|
| 4045 | */
|
---|
| 4046 | function consumeWord(css, start) {
|
---|
| 4047 | var next = start;
|
---|
| 4048 | var code;
|
---|
| 4049 | do {
|
---|
| 4050 | code = css.charCodeAt(next);
|
---|
| 4051 | if (wordDelimiters[code]) {
|
---|
| 4052 | return next - 1;
|
---|
| 4053 | } else if (code === t.backslash) {
|
---|
| 4054 | next = consumeEscape(css, next) + 1;
|
---|
| 4055 | } else {
|
---|
| 4056 | // All other characters are part of the word
|
---|
| 4057 | next++;
|
---|
| 4058 | }
|
---|
| 4059 | } while (next < css.length);
|
---|
| 4060 | return next - 1;
|
---|
| 4061 | }
|
---|
| 4062 |
|
---|
| 4063 | /**
|
---|
| 4064 | * Returns the last index of the escape sequence
|
---|
| 4065 | * @param {string} css The string in which the sequence begins
|
---|
| 4066 | * @param {number} start The index into the string where escape character (`\`) occurs.
|
---|
| 4067 | */
|
---|
| 4068 | function consumeEscape(css, start) {
|
---|
| 4069 | var next = start;
|
---|
| 4070 | var code = css.charCodeAt(next + 1);
|
---|
| 4071 | if (unescapable[code]) ; else if (hex[code]) {
|
---|
| 4072 | var hexDigits = 0;
|
---|
| 4073 | // consume up to 6 hex chars
|
---|
| 4074 | do {
|
---|
| 4075 | next++;
|
---|
| 4076 | hexDigits++;
|
---|
| 4077 | code = css.charCodeAt(next + 1);
|
---|
| 4078 | } while (hex[code] && hexDigits < 6);
|
---|
| 4079 | // if fewer than 6 hex chars, a trailing space ends the escape
|
---|
| 4080 | if (hexDigits < 6 && code === t.space) {
|
---|
| 4081 | next++;
|
---|
| 4082 | }
|
---|
| 4083 | } else {
|
---|
| 4084 | // the next char is part of the current word
|
---|
| 4085 | next++;
|
---|
| 4086 | }
|
---|
| 4087 | return next;
|
---|
| 4088 | }
|
---|
| 4089 | var FIELDS = {
|
---|
| 4090 | TYPE: 0,
|
---|
| 4091 | START_LINE: 1,
|
---|
| 4092 | START_COL: 2,
|
---|
| 4093 | END_LINE: 3,
|
---|
| 4094 | END_COL: 4,
|
---|
| 4095 | START_POS: 5,
|
---|
| 4096 | END_POS: 6
|
---|
| 4097 | };
|
---|
| 4098 | exports.FIELDS = FIELDS;
|
---|
| 4099 | function tokenize(input) {
|
---|
| 4100 | var tokens = [];
|
---|
| 4101 | var css = input.css.valueOf();
|
---|
| 4102 | var _css = css,
|
---|
| 4103 | length = _css.length;
|
---|
| 4104 | var offset = -1;
|
---|
| 4105 | var line = 1;
|
---|
| 4106 | var start = 0;
|
---|
| 4107 | var end = 0;
|
---|
| 4108 | var code, content, endColumn, endLine, escaped, escapePos, last, lines, next, nextLine, nextOffset, quote, tokenType;
|
---|
| 4109 | function unclosed(what, fix) {
|
---|
| 4110 | if (input.safe) {
|
---|
| 4111 | // fyi: this is never set to true.
|
---|
| 4112 | css += fix;
|
---|
| 4113 | next = css.length - 1;
|
---|
| 4114 | } else {
|
---|
| 4115 | throw input.error('Unclosed ' + what, line, start - offset, start);
|
---|
| 4116 | }
|
---|
| 4117 | }
|
---|
| 4118 | while (start < length) {
|
---|
| 4119 | code = css.charCodeAt(start);
|
---|
| 4120 | if (code === t.newline) {
|
---|
| 4121 | offset = start;
|
---|
| 4122 | line += 1;
|
---|
| 4123 | }
|
---|
| 4124 | switch (code) {
|
---|
| 4125 | case t.space:
|
---|
| 4126 | case t.tab:
|
---|
| 4127 | case t.newline:
|
---|
| 4128 | case t.cr:
|
---|
| 4129 | case t.feed:
|
---|
| 4130 | next = start;
|
---|
| 4131 | do {
|
---|
| 4132 | next += 1;
|
---|
| 4133 | code = css.charCodeAt(next);
|
---|
| 4134 | if (code === t.newline) {
|
---|
| 4135 | offset = next;
|
---|
| 4136 | line += 1;
|
---|
| 4137 | }
|
---|
| 4138 | } while (code === t.space || code === t.newline || code === t.tab || code === t.cr || code === t.feed);
|
---|
| 4139 | tokenType = t.space;
|
---|
| 4140 | endLine = line;
|
---|
| 4141 | endColumn = next - offset - 1;
|
---|
| 4142 | end = next;
|
---|
| 4143 | break;
|
---|
| 4144 | case t.plus:
|
---|
| 4145 | case t.greaterThan:
|
---|
| 4146 | case t.tilde:
|
---|
| 4147 | case t.pipe:
|
---|
| 4148 | next = start;
|
---|
| 4149 | do {
|
---|
| 4150 | next += 1;
|
---|
| 4151 | code = css.charCodeAt(next);
|
---|
| 4152 | } while (code === t.plus || code === t.greaterThan || code === t.tilde || code === t.pipe);
|
---|
| 4153 | tokenType = t.combinator;
|
---|
| 4154 | endLine = line;
|
---|
| 4155 | endColumn = start - offset;
|
---|
| 4156 | end = next;
|
---|
| 4157 | break;
|
---|
| 4158 |
|
---|
| 4159 | // Consume these characters as single tokens.
|
---|
| 4160 | case t.asterisk:
|
---|
| 4161 | case t.ampersand:
|
---|
| 4162 | case t.bang:
|
---|
| 4163 | case t.comma:
|
---|
| 4164 | case t.equals:
|
---|
| 4165 | case t.dollar:
|
---|
| 4166 | case t.caret:
|
---|
| 4167 | case t.openSquare:
|
---|
| 4168 | case t.closeSquare:
|
---|
| 4169 | case t.colon:
|
---|
| 4170 | case t.semicolon:
|
---|
| 4171 | case t.openParenthesis:
|
---|
| 4172 | case t.closeParenthesis:
|
---|
| 4173 | next = start;
|
---|
| 4174 | tokenType = code;
|
---|
| 4175 | endLine = line;
|
---|
| 4176 | endColumn = start - offset;
|
---|
| 4177 | end = next + 1;
|
---|
| 4178 | break;
|
---|
| 4179 | case t.singleQuote:
|
---|
| 4180 | case t.doubleQuote:
|
---|
| 4181 | quote = code === t.singleQuote ? "'" : '"';
|
---|
| 4182 | next = start;
|
---|
| 4183 | do {
|
---|
| 4184 | escaped = false;
|
---|
| 4185 | next = css.indexOf(quote, next + 1);
|
---|
| 4186 | if (next === -1) {
|
---|
| 4187 | unclosed('quote', quote);
|
---|
| 4188 | }
|
---|
| 4189 | escapePos = next;
|
---|
| 4190 | while (css.charCodeAt(escapePos - 1) === t.backslash) {
|
---|
| 4191 | escapePos -= 1;
|
---|
| 4192 | escaped = !escaped;
|
---|
| 4193 | }
|
---|
| 4194 | } while (escaped);
|
---|
| 4195 | tokenType = t.str;
|
---|
| 4196 | endLine = line;
|
---|
| 4197 | endColumn = start - offset;
|
---|
| 4198 | end = next + 1;
|
---|
| 4199 | break;
|
---|
| 4200 | default:
|
---|
| 4201 | if (code === t.slash && css.charCodeAt(start + 1) === t.asterisk) {
|
---|
| 4202 | next = css.indexOf('*/', start + 2) + 1;
|
---|
| 4203 | if (next === 0) {
|
---|
| 4204 | unclosed('comment', '*/');
|
---|
| 4205 | }
|
---|
| 4206 | content = css.slice(start, next + 1);
|
---|
| 4207 | lines = content.split('\n');
|
---|
| 4208 | last = lines.length - 1;
|
---|
| 4209 | if (last > 0) {
|
---|
| 4210 | nextLine = line + last;
|
---|
| 4211 | nextOffset = next - lines[last].length;
|
---|
| 4212 | } else {
|
---|
| 4213 | nextLine = line;
|
---|
| 4214 | nextOffset = offset;
|
---|
| 4215 | }
|
---|
| 4216 | tokenType = t.comment;
|
---|
| 4217 | line = nextLine;
|
---|
| 4218 | endLine = nextLine;
|
---|
| 4219 | endColumn = next - nextOffset;
|
---|
| 4220 | } else if (code === t.slash) {
|
---|
| 4221 | next = start;
|
---|
| 4222 | tokenType = code;
|
---|
| 4223 | endLine = line;
|
---|
| 4224 | endColumn = start - offset;
|
---|
| 4225 | end = next + 1;
|
---|
| 4226 | } else {
|
---|
| 4227 | next = consumeWord(css, start);
|
---|
| 4228 | tokenType = t.word;
|
---|
| 4229 | endLine = line;
|
---|
| 4230 | endColumn = next - offset;
|
---|
| 4231 | }
|
---|
| 4232 | end = next + 1;
|
---|
| 4233 | break;
|
---|
| 4234 | }
|
---|
| 4235 |
|
---|
| 4236 | // Ensure that the token structure remains consistent
|
---|
| 4237 | tokens.push([tokenType,
|
---|
| 4238 | // [0] Token type
|
---|
| 4239 | line,
|
---|
| 4240 | // [1] Starting line
|
---|
| 4241 | start - offset,
|
---|
| 4242 | // [2] Starting column
|
---|
| 4243 | endLine,
|
---|
| 4244 | // [3] Ending line
|
---|
| 4245 | endColumn,
|
---|
| 4246 | // [4] Ending column
|
---|
| 4247 | start,
|
---|
| 4248 | // [5] Start position / Source index
|
---|
| 4249 | end // [6] End position
|
---|
| 4250 | ]);
|
---|
| 4251 |
|
---|
| 4252 | // Reset offset for the next token
|
---|
| 4253 | if (nextOffset) {
|
---|
| 4254 | offset = nextOffset;
|
---|
| 4255 | nextOffset = null;
|
---|
| 4256 | }
|
---|
| 4257 | start = end;
|
---|
| 4258 | }
|
---|
| 4259 | return tokens;
|
---|
| 4260 | }
|
---|
| 4261 | } (tokenize));
|
---|
| 4262 |
|
---|
| 4263 | (function (module, exports) {
|
---|
| 4264 |
|
---|
| 4265 | exports.__esModule = true;
|
---|
| 4266 | exports["default"] = undefined;
|
---|
| 4267 | var _root = _interopRequireDefault(rootExports);
|
---|
| 4268 | var _selector = _interopRequireDefault(selectorExports);
|
---|
| 4269 | var _className = _interopRequireDefault(classNameExports);
|
---|
| 4270 | var _comment = _interopRequireDefault(commentExports);
|
---|
| 4271 | var _id = _interopRequireDefault(idExports);
|
---|
| 4272 | var _tag = _interopRequireDefault(tagExports);
|
---|
| 4273 | var _string = _interopRequireDefault(stringExports);
|
---|
| 4274 | var _pseudo = _interopRequireDefault(pseudoExports);
|
---|
| 4275 | var _attribute = _interopRequireWildcard(attribute$1);
|
---|
| 4276 | var _universal = _interopRequireDefault(universalExports);
|
---|
| 4277 | var _combinator = _interopRequireDefault(combinatorExports);
|
---|
| 4278 | var _nesting = _interopRequireDefault(nestingExports);
|
---|
| 4279 | var _sortAscending = _interopRequireDefault(sortAscendingExports);
|
---|
| 4280 | var _tokenize = _interopRequireWildcard(tokenize);
|
---|
| 4281 | var tokens = _interopRequireWildcard(tokenTypes);
|
---|
| 4282 | var types$1 = _interopRequireWildcard(types);
|
---|
| 4283 | var _util = util;
|
---|
| 4284 | var _WHITESPACE_TOKENS, _Object$assign;
|
---|
| 4285 | function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
---|
| 4286 | function _interopRequireWildcard(obj, nodeInterop) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
---|
| 4287 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
---|
| 4288 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
---|
| 4289 | function _createClass(Constructor, protoProps, staticProps) { _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
---|
| 4290 | var WHITESPACE_TOKENS = (_WHITESPACE_TOKENS = {}, _WHITESPACE_TOKENS[tokens.space] = true, _WHITESPACE_TOKENS[tokens.cr] = true, _WHITESPACE_TOKENS[tokens.feed] = true, _WHITESPACE_TOKENS[tokens.newline] = true, _WHITESPACE_TOKENS[tokens.tab] = true, _WHITESPACE_TOKENS);
|
---|
| 4291 | var WHITESPACE_EQUIV_TOKENS = Object.assign({}, WHITESPACE_TOKENS, (_Object$assign = {}, _Object$assign[tokens.comment] = true, _Object$assign));
|
---|
| 4292 | function tokenStart(token) {
|
---|
| 4293 | return {
|
---|
| 4294 | line: token[_tokenize.FIELDS.START_LINE],
|
---|
| 4295 | column: token[_tokenize.FIELDS.START_COL]
|
---|
| 4296 | };
|
---|
| 4297 | }
|
---|
| 4298 | function tokenEnd(token) {
|
---|
| 4299 | return {
|
---|
| 4300 | line: token[_tokenize.FIELDS.END_LINE],
|
---|
| 4301 | column: token[_tokenize.FIELDS.END_COL]
|
---|
| 4302 | };
|
---|
| 4303 | }
|
---|
| 4304 | function getSource(startLine, startColumn, endLine, endColumn) {
|
---|
| 4305 | return {
|
---|
| 4306 | start: {
|
---|
| 4307 | line: startLine,
|
---|
| 4308 | column: startColumn
|
---|
| 4309 | },
|
---|
| 4310 | end: {
|
---|
| 4311 | line: endLine,
|
---|
| 4312 | column: endColumn
|
---|
| 4313 | }
|
---|
| 4314 | };
|
---|
| 4315 | }
|
---|
| 4316 | function getTokenSource(token) {
|
---|
| 4317 | return getSource(token[_tokenize.FIELDS.START_LINE], token[_tokenize.FIELDS.START_COL], token[_tokenize.FIELDS.END_LINE], token[_tokenize.FIELDS.END_COL]);
|
---|
| 4318 | }
|
---|
| 4319 | function getTokenSourceSpan(startToken, endToken) {
|
---|
| 4320 | if (!startToken) {
|
---|
| 4321 | return undefined;
|
---|
| 4322 | }
|
---|
| 4323 | return getSource(startToken[_tokenize.FIELDS.START_LINE], startToken[_tokenize.FIELDS.START_COL], endToken[_tokenize.FIELDS.END_LINE], endToken[_tokenize.FIELDS.END_COL]);
|
---|
| 4324 | }
|
---|
| 4325 | function unescapeProp(node, prop) {
|
---|
| 4326 | var value = node[prop];
|
---|
| 4327 | if (typeof value !== "string") {
|
---|
| 4328 | return;
|
---|
| 4329 | }
|
---|
| 4330 | if (value.indexOf("\\") !== -1) {
|
---|
| 4331 | (0, _util.ensureObject)(node, 'raws');
|
---|
| 4332 | node[prop] = (0, _util.unesc)(value);
|
---|
| 4333 | if (node.raws[prop] === undefined) {
|
---|
| 4334 | node.raws[prop] = value;
|
---|
| 4335 | }
|
---|
| 4336 | }
|
---|
| 4337 | return node;
|
---|
| 4338 | }
|
---|
| 4339 | function indexesOf(array, item) {
|
---|
| 4340 | var i = -1;
|
---|
| 4341 | var indexes = [];
|
---|
| 4342 | while ((i = array.indexOf(item, i + 1)) !== -1) {
|
---|
| 4343 | indexes.push(i);
|
---|
| 4344 | }
|
---|
| 4345 | return indexes;
|
---|
| 4346 | }
|
---|
| 4347 | function uniqs() {
|
---|
| 4348 | var list = Array.prototype.concat.apply([], arguments);
|
---|
| 4349 | return list.filter(function (item, i) {
|
---|
| 4350 | return i === list.indexOf(item);
|
---|
| 4351 | });
|
---|
| 4352 | }
|
---|
| 4353 | var Parser = /*#__PURE__*/function () {
|
---|
| 4354 | function Parser(rule, options) {
|
---|
| 4355 | if (options === undefined) {
|
---|
| 4356 | options = {};
|
---|
| 4357 | }
|
---|
| 4358 | this.rule = rule;
|
---|
| 4359 | this.options = Object.assign({
|
---|
| 4360 | lossy: false,
|
---|
| 4361 | safe: false
|
---|
| 4362 | }, options);
|
---|
| 4363 | this.position = 0;
|
---|
| 4364 | this.css = typeof this.rule === 'string' ? this.rule : this.rule.selector;
|
---|
| 4365 | this.tokens = (0, _tokenize["default"])({
|
---|
| 4366 | css: this.css,
|
---|
| 4367 | error: this._errorGenerator(),
|
---|
| 4368 | safe: this.options.safe
|
---|
| 4369 | });
|
---|
| 4370 | var rootSource = getTokenSourceSpan(this.tokens[0], this.tokens[this.tokens.length - 1]);
|
---|
| 4371 | this.root = new _root["default"]({
|
---|
| 4372 | source: rootSource
|
---|
| 4373 | });
|
---|
| 4374 | this.root.errorGenerator = this._errorGenerator();
|
---|
| 4375 | var selector = new _selector["default"]({
|
---|
| 4376 | source: {
|
---|
| 4377 | start: {
|
---|
| 4378 | line: 1,
|
---|
| 4379 | column: 1
|
---|
| 4380 | }
|
---|
| 4381 | },
|
---|
| 4382 | sourceIndex: 0
|
---|
| 4383 | });
|
---|
| 4384 | this.root.append(selector);
|
---|
| 4385 | this.current = selector;
|
---|
| 4386 | this.loop();
|
---|
| 4387 | }
|
---|
| 4388 | var _proto = Parser.prototype;
|
---|
| 4389 | _proto._errorGenerator = function _errorGenerator() {
|
---|
| 4390 | var _this = this;
|
---|
| 4391 | return function (message, errorOptions) {
|
---|
| 4392 | if (typeof _this.rule === 'string') {
|
---|
| 4393 | return new Error(message);
|
---|
| 4394 | }
|
---|
| 4395 | return _this.rule.error(message, errorOptions);
|
---|
| 4396 | };
|
---|
| 4397 | };
|
---|
| 4398 | _proto.attribute = function attribute() {
|
---|
| 4399 | var attr = [];
|
---|
| 4400 | var startingToken = this.currToken;
|
---|
| 4401 | this.position++;
|
---|
| 4402 | while (this.position < this.tokens.length && this.currToken[_tokenize.FIELDS.TYPE] !== tokens.closeSquare) {
|
---|
| 4403 | attr.push(this.currToken);
|
---|
| 4404 | this.position++;
|
---|
| 4405 | }
|
---|
| 4406 | if (this.currToken[_tokenize.FIELDS.TYPE] !== tokens.closeSquare) {
|
---|
| 4407 | return this.expected('closing square bracket', this.currToken[_tokenize.FIELDS.START_POS]);
|
---|
| 4408 | }
|
---|
| 4409 | var len = attr.length;
|
---|
| 4410 | var node = {
|
---|
| 4411 | source: getSource(startingToken[1], startingToken[2], this.currToken[3], this.currToken[4]),
|
---|
| 4412 | sourceIndex: startingToken[_tokenize.FIELDS.START_POS]
|
---|
| 4413 | };
|
---|
| 4414 | if (len === 1 && !~[tokens.word].indexOf(attr[0][_tokenize.FIELDS.TYPE])) {
|
---|
| 4415 | return this.expected('attribute', attr[0][_tokenize.FIELDS.START_POS]);
|
---|
| 4416 | }
|
---|
| 4417 | var pos = 0;
|
---|
| 4418 | var spaceBefore = '';
|
---|
| 4419 | var commentBefore = '';
|
---|
| 4420 | var lastAdded = null;
|
---|
| 4421 | var spaceAfterMeaningfulToken = false;
|
---|
| 4422 | while (pos < len) {
|
---|
| 4423 | var token = attr[pos];
|
---|
| 4424 | var content = this.content(token);
|
---|
| 4425 | var next = attr[pos + 1];
|
---|
| 4426 | switch (token[_tokenize.FIELDS.TYPE]) {
|
---|
| 4427 | case tokens.space:
|
---|
| 4428 | // if (
|
---|
| 4429 | // len === 1 ||
|
---|
| 4430 | // pos === 0 && this.content(next) === '|'
|
---|
| 4431 | // ) {
|
---|
| 4432 | // return this.expected('attribute', token[TOKEN.START_POS], content);
|
---|
| 4433 | // }
|
---|
| 4434 | spaceAfterMeaningfulToken = true;
|
---|
| 4435 | if (this.options.lossy) {
|
---|
| 4436 | break;
|
---|
| 4437 | }
|
---|
| 4438 | if (lastAdded) {
|
---|
| 4439 | (0, _util.ensureObject)(node, 'spaces', lastAdded);
|
---|
| 4440 | var prevContent = node.spaces[lastAdded].after || '';
|
---|
| 4441 | node.spaces[lastAdded].after = prevContent + content;
|
---|
| 4442 | var existingComment = (0, _util.getProp)(node, 'raws', 'spaces', lastAdded, 'after') || null;
|
---|
| 4443 | if (existingComment) {
|
---|
| 4444 | node.raws.spaces[lastAdded].after = existingComment + content;
|
---|
| 4445 | }
|
---|
| 4446 | } else {
|
---|
| 4447 | spaceBefore = spaceBefore + content;
|
---|
| 4448 | commentBefore = commentBefore + content;
|
---|
| 4449 | }
|
---|
| 4450 | break;
|
---|
| 4451 | case tokens.asterisk:
|
---|
| 4452 | if (next[_tokenize.FIELDS.TYPE] === tokens.equals) {
|
---|
| 4453 | node.operator = content;
|
---|
| 4454 | lastAdded = 'operator';
|
---|
| 4455 | } else if ((!node.namespace || lastAdded === "namespace" && !spaceAfterMeaningfulToken) && next) {
|
---|
| 4456 | if (spaceBefore) {
|
---|
| 4457 | (0, _util.ensureObject)(node, 'spaces', 'attribute');
|
---|
| 4458 | node.spaces.attribute.before = spaceBefore;
|
---|
| 4459 | spaceBefore = '';
|
---|
| 4460 | }
|
---|
| 4461 | if (commentBefore) {
|
---|
| 4462 | (0, _util.ensureObject)(node, 'raws', 'spaces', 'attribute');
|
---|
| 4463 | node.raws.spaces.attribute.before = spaceBefore;
|
---|
| 4464 | commentBefore = '';
|
---|
| 4465 | }
|
---|
| 4466 | node.namespace = (node.namespace || "") + content;
|
---|
| 4467 | var rawValue = (0, _util.getProp)(node, 'raws', 'namespace') || null;
|
---|
| 4468 | if (rawValue) {
|
---|
| 4469 | node.raws.namespace += content;
|
---|
| 4470 | }
|
---|
| 4471 | lastAdded = 'namespace';
|
---|
| 4472 | }
|
---|
| 4473 | spaceAfterMeaningfulToken = false;
|
---|
| 4474 | break;
|
---|
| 4475 | case tokens.dollar:
|
---|
| 4476 | if (lastAdded === "value") {
|
---|
| 4477 | var oldRawValue = (0, _util.getProp)(node, 'raws', 'value');
|
---|
| 4478 | node.value += "$";
|
---|
| 4479 | if (oldRawValue) {
|
---|
| 4480 | node.raws.value = oldRawValue + "$";
|
---|
| 4481 | }
|
---|
| 4482 | break;
|
---|
| 4483 | }
|
---|
| 4484 | // Falls through
|
---|
| 4485 | case tokens.caret:
|
---|
| 4486 | if (next[_tokenize.FIELDS.TYPE] === tokens.equals) {
|
---|
| 4487 | node.operator = content;
|
---|
| 4488 | lastAdded = 'operator';
|
---|
| 4489 | }
|
---|
| 4490 | spaceAfterMeaningfulToken = false;
|
---|
| 4491 | break;
|
---|
| 4492 | case tokens.combinator:
|
---|
| 4493 | if (content === '~' && next[_tokenize.FIELDS.TYPE] === tokens.equals) {
|
---|
| 4494 | node.operator = content;
|
---|
| 4495 | lastAdded = 'operator';
|
---|
| 4496 | }
|
---|
| 4497 | if (content !== '|') {
|
---|
| 4498 | spaceAfterMeaningfulToken = false;
|
---|
| 4499 | break;
|
---|
| 4500 | }
|
---|
| 4501 | if (next[_tokenize.FIELDS.TYPE] === tokens.equals) {
|
---|
| 4502 | node.operator = content;
|
---|
| 4503 | lastAdded = 'operator';
|
---|
| 4504 | } else if (!node.namespace && !node.attribute) {
|
---|
| 4505 | node.namespace = true;
|
---|
| 4506 | }
|
---|
| 4507 | spaceAfterMeaningfulToken = false;
|
---|
| 4508 | break;
|
---|
| 4509 | case tokens.word:
|
---|
| 4510 | if (next && this.content(next) === '|' && attr[pos + 2] && attr[pos + 2][_tokenize.FIELDS.TYPE] !== tokens.equals &&
|
---|
| 4511 | // this look-ahead probably fails with comment nodes involved.
|
---|
| 4512 | !node.operator && !node.namespace) {
|
---|
| 4513 | node.namespace = content;
|
---|
| 4514 | lastAdded = 'namespace';
|
---|
| 4515 | } else if (!node.attribute || lastAdded === "attribute" && !spaceAfterMeaningfulToken) {
|
---|
| 4516 | if (spaceBefore) {
|
---|
| 4517 | (0, _util.ensureObject)(node, 'spaces', 'attribute');
|
---|
| 4518 | node.spaces.attribute.before = spaceBefore;
|
---|
| 4519 | spaceBefore = '';
|
---|
| 4520 | }
|
---|
| 4521 | if (commentBefore) {
|
---|
| 4522 | (0, _util.ensureObject)(node, 'raws', 'spaces', 'attribute');
|
---|
| 4523 | node.raws.spaces.attribute.before = commentBefore;
|
---|
| 4524 | commentBefore = '';
|
---|
| 4525 | }
|
---|
| 4526 | node.attribute = (node.attribute || "") + content;
|
---|
| 4527 | var _rawValue = (0, _util.getProp)(node, 'raws', 'attribute') || null;
|
---|
| 4528 | if (_rawValue) {
|
---|
| 4529 | node.raws.attribute += content;
|
---|
| 4530 | }
|
---|
| 4531 | lastAdded = 'attribute';
|
---|
| 4532 | } else if (!node.value && node.value !== "" || lastAdded === "value" && !(spaceAfterMeaningfulToken || node.quoteMark)) {
|
---|
| 4533 | var _unescaped = (0, _util.unesc)(content);
|
---|
| 4534 | var _oldRawValue = (0, _util.getProp)(node, 'raws', 'value') || '';
|
---|
| 4535 | var oldValue = node.value || '';
|
---|
| 4536 | node.value = oldValue + _unescaped;
|
---|
| 4537 | node.quoteMark = null;
|
---|
| 4538 | if (_unescaped !== content || _oldRawValue) {
|
---|
| 4539 | (0, _util.ensureObject)(node, 'raws');
|
---|
| 4540 | node.raws.value = (_oldRawValue || oldValue) + content;
|
---|
| 4541 | }
|
---|
| 4542 | lastAdded = 'value';
|
---|
| 4543 | } else {
|
---|
| 4544 | var insensitive = content === 'i' || content === "I";
|
---|
| 4545 | if ((node.value || node.value === '') && (node.quoteMark || spaceAfterMeaningfulToken)) {
|
---|
| 4546 | node.insensitive = insensitive;
|
---|
| 4547 | if (!insensitive || content === "I") {
|
---|
| 4548 | (0, _util.ensureObject)(node, 'raws');
|
---|
| 4549 | node.raws.insensitiveFlag = content;
|
---|
| 4550 | }
|
---|
| 4551 | lastAdded = 'insensitive';
|
---|
| 4552 | if (spaceBefore) {
|
---|
| 4553 | (0, _util.ensureObject)(node, 'spaces', 'insensitive');
|
---|
| 4554 | node.spaces.insensitive.before = spaceBefore;
|
---|
| 4555 | spaceBefore = '';
|
---|
| 4556 | }
|
---|
| 4557 | if (commentBefore) {
|
---|
| 4558 | (0, _util.ensureObject)(node, 'raws', 'spaces', 'insensitive');
|
---|
| 4559 | node.raws.spaces.insensitive.before = commentBefore;
|
---|
| 4560 | commentBefore = '';
|
---|
| 4561 | }
|
---|
| 4562 | } else if (node.value || node.value === '') {
|
---|
| 4563 | lastAdded = 'value';
|
---|
| 4564 | node.value += content;
|
---|
| 4565 | if (node.raws.value) {
|
---|
| 4566 | node.raws.value += content;
|
---|
| 4567 | }
|
---|
| 4568 | }
|
---|
| 4569 | }
|
---|
| 4570 | spaceAfterMeaningfulToken = false;
|
---|
| 4571 | break;
|
---|
| 4572 | case tokens.str:
|
---|
| 4573 | if (!node.attribute || !node.operator) {
|
---|
| 4574 | return this.error("Expected an attribute followed by an operator preceding the string.", {
|
---|
| 4575 | index: token[_tokenize.FIELDS.START_POS]
|
---|
| 4576 | });
|
---|
| 4577 | }
|
---|
| 4578 | var _unescapeValue = (0, _attribute.unescapeValue)(content),
|
---|
| 4579 | unescaped = _unescapeValue.unescaped,
|
---|
| 4580 | quoteMark = _unescapeValue.quoteMark;
|
---|
| 4581 | node.value = unescaped;
|
---|
| 4582 | node.quoteMark = quoteMark;
|
---|
| 4583 | lastAdded = 'value';
|
---|
| 4584 | (0, _util.ensureObject)(node, 'raws');
|
---|
| 4585 | node.raws.value = content;
|
---|
| 4586 | spaceAfterMeaningfulToken = false;
|
---|
| 4587 | break;
|
---|
| 4588 | case tokens.equals:
|
---|
| 4589 | if (!node.attribute) {
|
---|
| 4590 | return this.expected('attribute', token[_tokenize.FIELDS.START_POS], content);
|
---|
| 4591 | }
|
---|
| 4592 | if (node.value) {
|
---|
| 4593 | return this.error('Unexpected "=" found; an operator was already defined.', {
|
---|
| 4594 | index: token[_tokenize.FIELDS.START_POS]
|
---|
| 4595 | });
|
---|
| 4596 | }
|
---|
| 4597 | node.operator = node.operator ? node.operator + content : content;
|
---|
| 4598 | lastAdded = 'operator';
|
---|
| 4599 | spaceAfterMeaningfulToken = false;
|
---|
| 4600 | break;
|
---|
| 4601 | case tokens.comment:
|
---|
| 4602 | if (lastAdded) {
|
---|
| 4603 | if (spaceAfterMeaningfulToken || next && next[_tokenize.FIELDS.TYPE] === tokens.space || lastAdded === 'insensitive') {
|
---|
| 4604 | var lastComment = (0, _util.getProp)(node, 'spaces', lastAdded, 'after') || '';
|
---|
| 4605 | var rawLastComment = (0, _util.getProp)(node, 'raws', 'spaces', lastAdded, 'after') || lastComment;
|
---|
| 4606 | (0, _util.ensureObject)(node, 'raws', 'spaces', lastAdded);
|
---|
| 4607 | node.raws.spaces[lastAdded].after = rawLastComment + content;
|
---|
| 4608 | } else {
|
---|
| 4609 | var lastValue = node[lastAdded] || '';
|
---|
| 4610 | var rawLastValue = (0, _util.getProp)(node, 'raws', lastAdded) || lastValue;
|
---|
| 4611 | (0, _util.ensureObject)(node, 'raws');
|
---|
| 4612 | node.raws[lastAdded] = rawLastValue + content;
|
---|
| 4613 | }
|
---|
| 4614 | } else {
|
---|
| 4615 | commentBefore = commentBefore + content;
|
---|
| 4616 | }
|
---|
| 4617 | break;
|
---|
| 4618 | default:
|
---|
| 4619 | return this.error("Unexpected \"" + content + "\" found.", {
|
---|
| 4620 | index: token[_tokenize.FIELDS.START_POS]
|
---|
| 4621 | });
|
---|
| 4622 | }
|
---|
| 4623 | pos++;
|
---|
| 4624 | }
|
---|
| 4625 | unescapeProp(node, "attribute");
|
---|
| 4626 | unescapeProp(node, "namespace");
|
---|
| 4627 | this.newNode(new _attribute["default"](node));
|
---|
| 4628 | this.position++;
|
---|
| 4629 | }
|
---|
| 4630 |
|
---|
| 4631 | /**
|
---|
| 4632 | * return a node containing meaningless garbage up to (but not including) the specified token position.
|
---|
| 4633 | * if the token position is negative, all remaining tokens are consumed.
|
---|
| 4634 | *
|
---|
| 4635 | * This returns an array containing a single string node if all whitespace,
|
---|
| 4636 | * otherwise an array of comment nodes with space before and after.
|
---|
| 4637 | *
|
---|
| 4638 | * These tokens are not added to the current selector, the caller can add them or use them to amend
|
---|
| 4639 | * a previous node's space metadata.
|
---|
| 4640 | *
|
---|
| 4641 | * In lossy mode, this returns only comments.
|
---|
| 4642 | */;
|
---|
| 4643 | _proto.parseWhitespaceEquivalentTokens = function parseWhitespaceEquivalentTokens(stopPosition) {
|
---|
| 4644 | if (stopPosition < 0) {
|
---|
| 4645 | stopPosition = this.tokens.length;
|
---|
| 4646 | }
|
---|
| 4647 | var startPosition = this.position;
|
---|
| 4648 | var nodes = [];
|
---|
| 4649 | var space = "";
|
---|
| 4650 | var lastComment = undefined;
|
---|
| 4651 | do {
|
---|
| 4652 | if (WHITESPACE_TOKENS[this.currToken[_tokenize.FIELDS.TYPE]]) {
|
---|
| 4653 | if (!this.options.lossy) {
|
---|
| 4654 | space += this.content();
|
---|
| 4655 | }
|
---|
| 4656 | } else if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.comment) {
|
---|
| 4657 | var spaces = {};
|
---|
| 4658 | if (space) {
|
---|
| 4659 | spaces.before = space;
|
---|
| 4660 | space = "";
|
---|
| 4661 | }
|
---|
| 4662 | lastComment = new _comment["default"]({
|
---|
| 4663 | value: this.content(),
|
---|
| 4664 | source: getTokenSource(this.currToken),
|
---|
| 4665 | sourceIndex: this.currToken[_tokenize.FIELDS.START_POS],
|
---|
| 4666 | spaces: spaces
|
---|
| 4667 | });
|
---|
| 4668 | nodes.push(lastComment);
|
---|
| 4669 | }
|
---|
| 4670 | } while (++this.position < stopPosition);
|
---|
| 4671 | if (space) {
|
---|
| 4672 | if (lastComment) {
|
---|
| 4673 | lastComment.spaces.after = space;
|
---|
| 4674 | } else if (!this.options.lossy) {
|
---|
| 4675 | var firstToken = this.tokens[startPosition];
|
---|
| 4676 | var lastToken = this.tokens[this.position - 1];
|
---|
| 4677 | nodes.push(new _string["default"]({
|
---|
| 4678 | value: '',
|
---|
| 4679 | source: getSource(firstToken[_tokenize.FIELDS.START_LINE], firstToken[_tokenize.FIELDS.START_COL], lastToken[_tokenize.FIELDS.END_LINE], lastToken[_tokenize.FIELDS.END_COL]),
|
---|
| 4680 | sourceIndex: firstToken[_tokenize.FIELDS.START_POS],
|
---|
| 4681 | spaces: {
|
---|
| 4682 | before: space,
|
---|
| 4683 | after: ''
|
---|
| 4684 | }
|
---|
| 4685 | }));
|
---|
| 4686 | }
|
---|
| 4687 | }
|
---|
| 4688 | return nodes;
|
---|
| 4689 | }
|
---|
| 4690 |
|
---|
| 4691 | /**
|
---|
| 4692 | *
|
---|
| 4693 | * @param {*} nodes
|
---|
| 4694 | */;
|
---|
| 4695 | _proto.convertWhitespaceNodesToSpace = function convertWhitespaceNodesToSpace(nodes, requiredSpace) {
|
---|
| 4696 | var _this2 = this;
|
---|
| 4697 | if (requiredSpace === undefined) {
|
---|
| 4698 | requiredSpace = false;
|
---|
| 4699 | }
|
---|
| 4700 | var space = "";
|
---|
| 4701 | var rawSpace = "";
|
---|
| 4702 | nodes.forEach(function (n) {
|
---|
| 4703 | var spaceBefore = _this2.lossySpace(n.spaces.before, requiredSpace);
|
---|
| 4704 | var rawSpaceBefore = _this2.lossySpace(n.rawSpaceBefore, requiredSpace);
|
---|
| 4705 | space += spaceBefore + _this2.lossySpace(n.spaces.after, requiredSpace && spaceBefore.length === 0);
|
---|
| 4706 | rawSpace += spaceBefore + n.value + _this2.lossySpace(n.rawSpaceAfter, requiredSpace && rawSpaceBefore.length === 0);
|
---|
| 4707 | });
|
---|
| 4708 | if (rawSpace === space) {
|
---|
| 4709 | rawSpace = undefined;
|
---|
| 4710 | }
|
---|
| 4711 | var result = {
|
---|
| 4712 | space: space,
|
---|
| 4713 | rawSpace: rawSpace
|
---|
| 4714 | };
|
---|
| 4715 | return result;
|
---|
| 4716 | };
|
---|
| 4717 | _proto.isNamedCombinator = function isNamedCombinator(position) {
|
---|
| 4718 | if (position === undefined) {
|
---|
| 4719 | position = this.position;
|
---|
| 4720 | }
|
---|
| 4721 | return this.tokens[position + 0] && this.tokens[position + 0][_tokenize.FIELDS.TYPE] === tokens.slash && this.tokens[position + 1] && this.tokens[position + 1][_tokenize.FIELDS.TYPE] === tokens.word && this.tokens[position + 2] && this.tokens[position + 2][_tokenize.FIELDS.TYPE] === tokens.slash;
|
---|
| 4722 | };
|
---|
| 4723 | _proto.namedCombinator = function namedCombinator() {
|
---|
| 4724 | if (this.isNamedCombinator()) {
|
---|
| 4725 | var nameRaw = this.content(this.tokens[this.position + 1]);
|
---|
| 4726 | var name = (0, _util.unesc)(nameRaw).toLowerCase();
|
---|
| 4727 | var raws = {};
|
---|
| 4728 | if (name !== nameRaw) {
|
---|
| 4729 | raws.value = "/" + nameRaw + "/";
|
---|
| 4730 | }
|
---|
| 4731 | var node = new _combinator["default"]({
|
---|
| 4732 | value: "/" + name + "/",
|
---|
| 4733 | source: getSource(this.currToken[_tokenize.FIELDS.START_LINE], this.currToken[_tokenize.FIELDS.START_COL], this.tokens[this.position + 2][_tokenize.FIELDS.END_LINE], this.tokens[this.position + 2][_tokenize.FIELDS.END_COL]),
|
---|
| 4734 | sourceIndex: this.currToken[_tokenize.FIELDS.START_POS],
|
---|
| 4735 | raws: raws
|
---|
| 4736 | });
|
---|
| 4737 | this.position = this.position + 3;
|
---|
| 4738 | return node;
|
---|
| 4739 | } else {
|
---|
| 4740 | this.unexpected();
|
---|
| 4741 | }
|
---|
| 4742 | };
|
---|
| 4743 | _proto.combinator = function combinator() {
|
---|
| 4744 | var _this3 = this;
|
---|
| 4745 | if (this.content() === '|') {
|
---|
| 4746 | return this.namespace();
|
---|
| 4747 | }
|
---|
| 4748 | // We need to decide between a space that's a descendant combinator and meaningless whitespace at the end of a selector.
|
---|
| 4749 | var nextSigTokenPos = this.locateNextMeaningfulToken(this.position);
|
---|
| 4750 | if (nextSigTokenPos < 0 || this.tokens[nextSigTokenPos][_tokenize.FIELDS.TYPE] === tokens.comma || this.tokens[nextSigTokenPos][_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
|
---|
| 4751 | var nodes = this.parseWhitespaceEquivalentTokens(nextSigTokenPos);
|
---|
| 4752 | if (nodes.length > 0) {
|
---|
| 4753 | var last = this.current.last;
|
---|
| 4754 | if (last) {
|
---|
| 4755 | var _this$convertWhitespa = this.convertWhitespaceNodesToSpace(nodes),
|
---|
| 4756 | space = _this$convertWhitespa.space,
|
---|
| 4757 | rawSpace = _this$convertWhitespa.rawSpace;
|
---|
| 4758 | if (rawSpace !== undefined) {
|
---|
| 4759 | last.rawSpaceAfter += rawSpace;
|
---|
| 4760 | }
|
---|
| 4761 | last.spaces.after += space;
|
---|
| 4762 | } else {
|
---|
| 4763 | nodes.forEach(function (n) {
|
---|
| 4764 | return _this3.newNode(n);
|
---|
| 4765 | });
|
---|
| 4766 | }
|
---|
| 4767 | }
|
---|
| 4768 | return;
|
---|
| 4769 | }
|
---|
| 4770 | var firstToken = this.currToken;
|
---|
| 4771 | var spaceOrDescendantSelectorNodes = undefined;
|
---|
| 4772 | if (nextSigTokenPos > this.position) {
|
---|
| 4773 | spaceOrDescendantSelectorNodes = this.parseWhitespaceEquivalentTokens(nextSigTokenPos);
|
---|
| 4774 | }
|
---|
| 4775 | var node;
|
---|
| 4776 | if (this.isNamedCombinator()) {
|
---|
| 4777 | node = this.namedCombinator();
|
---|
| 4778 | } else if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.combinator) {
|
---|
| 4779 | node = new _combinator["default"]({
|
---|
| 4780 | value: this.content(),
|
---|
| 4781 | source: getTokenSource(this.currToken),
|
---|
| 4782 | sourceIndex: this.currToken[_tokenize.FIELDS.START_POS]
|
---|
| 4783 | });
|
---|
| 4784 | this.position++;
|
---|
| 4785 | } else if (WHITESPACE_TOKENS[this.currToken[_tokenize.FIELDS.TYPE]]) ; else if (!spaceOrDescendantSelectorNodes) {
|
---|
| 4786 | this.unexpected();
|
---|
| 4787 | }
|
---|
| 4788 | if (node) {
|
---|
| 4789 | if (spaceOrDescendantSelectorNodes) {
|
---|
| 4790 | var _this$convertWhitespa2 = this.convertWhitespaceNodesToSpace(spaceOrDescendantSelectorNodes),
|
---|
| 4791 | _space = _this$convertWhitespa2.space,
|
---|
| 4792 | _rawSpace = _this$convertWhitespa2.rawSpace;
|
---|
| 4793 | node.spaces.before = _space;
|
---|
| 4794 | node.rawSpaceBefore = _rawSpace;
|
---|
| 4795 | }
|
---|
| 4796 | } else {
|
---|
| 4797 | // descendant combinator
|
---|
| 4798 | var _this$convertWhitespa3 = this.convertWhitespaceNodesToSpace(spaceOrDescendantSelectorNodes, true),
|
---|
| 4799 | _space2 = _this$convertWhitespa3.space,
|
---|
| 4800 | _rawSpace2 = _this$convertWhitespa3.rawSpace;
|
---|
| 4801 | if (!_rawSpace2) {
|
---|
| 4802 | _rawSpace2 = _space2;
|
---|
| 4803 | }
|
---|
| 4804 | var spaces = {};
|
---|
| 4805 | var raws = {
|
---|
| 4806 | spaces: {}
|
---|
| 4807 | };
|
---|
| 4808 | if (_space2.endsWith(' ') && _rawSpace2.endsWith(' ')) {
|
---|
| 4809 | spaces.before = _space2.slice(0, _space2.length - 1);
|
---|
| 4810 | raws.spaces.before = _rawSpace2.slice(0, _rawSpace2.length - 1);
|
---|
| 4811 | } else if (_space2.startsWith(' ') && _rawSpace2.startsWith(' ')) {
|
---|
| 4812 | spaces.after = _space2.slice(1);
|
---|
| 4813 | raws.spaces.after = _rawSpace2.slice(1);
|
---|
| 4814 | } else {
|
---|
| 4815 | raws.value = _rawSpace2;
|
---|
| 4816 | }
|
---|
| 4817 | node = new _combinator["default"]({
|
---|
| 4818 | value: ' ',
|
---|
| 4819 | source: getTokenSourceSpan(firstToken, this.tokens[this.position - 1]),
|
---|
| 4820 | sourceIndex: firstToken[_tokenize.FIELDS.START_POS],
|
---|
| 4821 | spaces: spaces,
|
---|
| 4822 | raws: raws
|
---|
| 4823 | });
|
---|
| 4824 | }
|
---|
| 4825 | if (this.currToken && this.currToken[_tokenize.FIELDS.TYPE] === tokens.space) {
|
---|
| 4826 | node.spaces.after = this.optionalSpace(this.content());
|
---|
| 4827 | this.position++;
|
---|
| 4828 | }
|
---|
| 4829 | return this.newNode(node);
|
---|
| 4830 | };
|
---|
| 4831 | _proto.comma = function comma() {
|
---|
| 4832 | if (this.position === this.tokens.length - 1) {
|
---|
| 4833 | this.root.trailingComma = true;
|
---|
| 4834 | this.position++;
|
---|
| 4835 | return;
|
---|
| 4836 | }
|
---|
| 4837 | this.current._inferEndPosition();
|
---|
| 4838 | var selector = new _selector["default"]({
|
---|
| 4839 | source: {
|
---|
| 4840 | start: tokenStart(this.tokens[this.position + 1])
|
---|
| 4841 | },
|
---|
| 4842 | sourceIndex: this.tokens[this.position + 1][_tokenize.FIELDS.START_POS]
|
---|
| 4843 | });
|
---|
| 4844 | this.current.parent.append(selector);
|
---|
| 4845 | this.current = selector;
|
---|
| 4846 | this.position++;
|
---|
| 4847 | };
|
---|
| 4848 | _proto.comment = function comment() {
|
---|
| 4849 | var current = this.currToken;
|
---|
| 4850 | this.newNode(new _comment["default"]({
|
---|
| 4851 | value: this.content(),
|
---|
| 4852 | source: getTokenSource(current),
|
---|
| 4853 | sourceIndex: current[_tokenize.FIELDS.START_POS]
|
---|
| 4854 | }));
|
---|
| 4855 | this.position++;
|
---|
| 4856 | };
|
---|
| 4857 | _proto.error = function error(message, opts) {
|
---|
| 4858 | throw this.root.error(message, opts);
|
---|
| 4859 | };
|
---|
| 4860 | _proto.missingBackslash = function missingBackslash() {
|
---|
| 4861 | return this.error('Expected a backslash preceding the semicolon.', {
|
---|
| 4862 | index: this.currToken[_tokenize.FIELDS.START_POS]
|
---|
| 4863 | });
|
---|
| 4864 | };
|
---|
| 4865 | _proto.missingParenthesis = function missingParenthesis() {
|
---|
| 4866 | return this.expected('opening parenthesis', this.currToken[_tokenize.FIELDS.START_POS]);
|
---|
| 4867 | };
|
---|
| 4868 | _proto.missingSquareBracket = function missingSquareBracket() {
|
---|
| 4869 | return this.expected('opening square bracket', this.currToken[_tokenize.FIELDS.START_POS]);
|
---|
| 4870 | };
|
---|
| 4871 | _proto.unexpected = function unexpected() {
|
---|
| 4872 | return this.error("Unexpected '" + this.content() + "'. Escaping special characters with \\ may help.", this.currToken[_tokenize.FIELDS.START_POS]);
|
---|
| 4873 | };
|
---|
| 4874 | _proto.unexpectedPipe = function unexpectedPipe() {
|
---|
| 4875 | return this.error("Unexpected '|'.", this.currToken[_tokenize.FIELDS.START_POS]);
|
---|
| 4876 | };
|
---|
| 4877 | _proto.namespace = function namespace() {
|
---|
| 4878 | var before = this.prevToken && this.content(this.prevToken) || true;
|
---|
| 4879 | if (this.nextToken[_tokenize.FIELDS.TYPE] === tokens.word) {
|
---|
| 4880 | this.position++;
|
---|
| 4881 | return this.word(before);
|
---|
| 4882 | } else if (this.nextToken[_tokenize.FIELDS.TYPE] === tokens.asterisk) {
|
---|
| 4883 | this.position++;
|
---|
| 4884 | return this.universal(before);
|
---|
| 4885 | }
|
---|
| 4886 | this.unexpectedPipe();
|
---|
| 4887 | };
|
---|
| 4888 | _proto.nesting = function nesting() {
|
---|
| 4889 | if (this.nextToken) {
|
---|
| 4890 | var nextContent = this.content(this.nextToken);
|
---|
| 4891 | if (nextContent === "|") {
|
---|
| 4892 | this.position++;
|
---|
| 4893 | return;
|
---|
| 4894 | }
|
---|
| 4895 | }
|
---|
| 4896 | var current = this.currToken;
|
---|
| 4897 | this.newNode(new _nesting["default"]({
|
---|
| 4898 | value: this.content(),
|
---|
| 4899 | source: getTokenSource(current),
|
---|
| 4900 | sourceIndex: current[_tokenize.FIELDS.START_POS]
|
---|
| 4901 | }));
|
---|
| 4902 | this.position++;
|
---|
| 4903 | };
|
---|
| 4904 | _proto.parentheses = function parentheses() {
|
---|
| 4905 | var last = this.current.last;
|
---|
| 4906 | var unbalanced = 1;
|
---|
| 4907 | this.position++;
|
---|
| 4908 | if (last && last.type === types$1.PSEUDO) {
|
---|
| 4909 | var selector = new _selector["default"]({
|
---|
| 4910 | source: {
|
---|
| 4911 | start: tokenStart(this.tokens[this.position])
|
---|
| 4912 | },
|
---|
| 4913 | sourceIndex: this.tokens[this.position][_tokenize.FIELDS.START_POS]
|
---|
| 4914 | });
|
---|
| 4915 | var cache = this.current;
|
---|
| 4916 | last.append(selector);
|
---|
| 4917 | this.current = selector;
|
---|
| 4918 | while (this.position < this.tokens.length && unbalanced) {
|
---|
| 4919 | if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis) {
|
---|
| 4920 | unbalanced++;
|
---|
| 4921 | }
|
---|
| 4922 | if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
|
---|
| 4923 | unbalanced--;
|
---|
| 4924 | }
|
---|
| 4925 | if (unbalanced) {
|
---|
| 4926 | this.parse();
|
---|
| 4927 | } else {
|
---|
| 4928 | this.current.source.end = tokenEnd(this.currToken);
|
---|
| 4929 | this.current.parent.source.end = tokenEnd(this.currToken);
|
---|
| 4930 | this.position++;
|
---|
| 4931 | }
|
---|
| 4932 | }
|
---|
| 4933 | this.current = cache;
|
---|
| 4934 | } else {
|
---|
| 4935 | // I think this case should be an error. It's used to implement a basic parse of media queries
|
---|
| 4936 | // but I don't think it's a good idea.
|
---|
| 4937 | var parenStart = this.currToken;
|
---|
| 4938 | var parenValue = "(";
|
---|
| 4939 | var parenEnd;
|
---|
| 4940 | while (this.position < this.tokens.length && unbalanced) {
|
---|
| 4941 | if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis) {
|
---|
| 4942 | unbalanced++;
|
---|
| 4943 | }
|
---|
| 4944 | if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
|
---|
| 4945 | unbalanced--;
|
---|
| 4946 | }
|
---|
| 4947 | parenEnd = this.currToken;
|
---|
| 4948 | parenValue += this.parseParenthesisToken(this.currToken);
|
---|
| 4949 | this.position++;
|
---|
| 4950 | }
|
---|
| 4951 | if (last) {
|
---|
| 4952 | last.appendToPropertyAndEscape("value", parenValue, parenValue);
|
---|
| 4953 | } else {
|
---|
| 4954 | this.newNode(new _string["default"]({
|
---|
| 4955 | value: parenValue,
|
---|
| 4956 | source: getSource(parenStart[_tokenize.FIELDS.START_LINE], parenStart[_tokenize.FIELDS.START_COL], parenEnd[_tokenize.FIELDS.END_LINE], parenEnd[_tokenize.FIELDS.END_COL]),
|
---|
| 4957 | sourceIndex: parenStart[_tokenize.FIELDS.START_POS]
|
---|
| 4958 | }));
|
---|
| 4959 | }
|
---|
| 4960 | }
|
---|
| 4961 | if (unbalanced) {
|
---|
| 4962 | return this.expected('closing parenthesis', this.currToken[_tokenize.FIELDS.START_POS]);
|
---|
| 4963 | }
|
---|
| 4964 | };
|
---|
| 4965 | _proto.pseudo = function pseudo() {
|
---|
| 4966 | var _this4 = this;
|
---|
| 4967 | var pseudoStr = '';
|
---|
| 4968 | var startingToken = this.currToken;
|
---|
| 4969 | while (this.currToken && this.currToken[_tokenize.FIELDS.TYPE] === tokens.colon) {
|
---|
| 4970 | pseudoStr += this.content();
|
---|
| 4971 | this.position++;
|
---|
| 4972 | }
|
---|
| 4973 | if (!this.currToken) {
|
---|
| 4974 | return this.expected(['pseudo-class', 'pseudo-element'], this.position - 1);
|
---|
| 4975 | }
|
---|
| 4976 | if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.word) {
|
---|
| 4977 | this.splitWord(false, function (first, length) {
|
---|
| 4978 | pseudoStr += first;
|
---|
| 4979 | _this4.newNode(new _pseudo["default"]({
|
---|
| 4980 | value: pseudoStr,
|
---|
| 4981 | source: getTokenSourceSpan(startingToken, _this4.currToken),
|
---|
| 4982 | sourceIndex: startingToken[_tokenize.FIELDS.START_POS]
|
---|
| 4983 | }));
|
---|
| 4984 | if (length > 1 && _this4.nextToken && _this4.nextToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis) {
|
---|
| 4985 | _this4.error('Misplaced parenthesis.', {
|
---|
| 4986 | index: _this4.nextToken[_tokenize.FIELDS.START_POS]
|
---|
| 4987 | });
|
---|
| 4988 | }
|
---|
| 4989 | });
|
---|
| 4990 | } else {
|
---|
| 4991 | return this.expected(['pseudo-class', 'pseudo-element'], this.currToken[_tokenize.FIELDS.START_POS]);
|
---|
| 4992 | }
|
---|
| 4993 | };
|
---|
| 4994 | _proto.space = function space() {
|
---|
| 4995 | var content = this.content();
|
---|
| 4996 | // Handle space before and after the selector
|
---|
| 4997 | if (this.position === 0 || this.prevToken[_tokenize.FIELDS.TYPE] === tokens.comma || this.prevToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis || this.current.nodes.every(function (node) {
|
---|
| 4998 | return node.type === 'comment';
|
---|
| 4999 | })) {
|
---|
| 5000 | this.spaces = this.optionalSpace(content);
|
---|
| 5001 | this.position++;
|
---|
| 5002 | } else if (this.position === this.tokens.length - 1 || this.nextToken[_tokenize.FIELDS.TYPE] === tokens.comma || this.nextToken[_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
|
---|
| 5003 | this.current.last.spaces.after = this.optionalSpace(content);
|
---|
| 5004 | this.position++;
|
---|
| 5005 | } else {
|
---|
| 5006 | this.combinator();
|
---|
| 5007 | }
|
---|
| 5008 | };
|
---|
| 5009 | _proto.string = function string() {
|
---|
| 5010 | var current = this.currToken;
|
---|
| 5011 | this.newNode(new _string["default"]({
|
---|
| 5012 | value: this.content(),
|
---|
| 5013 | source: getTokenSource(current),
|
---|
| 5014 | sourceIndex: current[_tokenize.FIELDS.START_POS]
|
---|
| 5015 | }));
|
---|
| 5016 | this.position++;
|
---|
| 5017 | };
|
---|
| 5018 | _proto.universal = function universal(namespace) {
|
---|
| 5019 | var nextToken = this.nextToken;
|
---|
| 5020 | if (nextToken && this.content(nextToken) === '|') {
|
---|
| 5021 | this.position++;
|
---|
| 5022 | return this.namespace();
|
---|
| 5023 | }
|
---|
| 5024 | var current = this.currToken;
|
---|
| 5025 | this.newNode(new _universal["default"]({
|
---|
| 5026 | value: this.content(),
|
---|
| 5027 | source: getTokenSource(current),
|
---|
| 5028 | sourceIndex: current[_tokenize.FIELDS.START_POS]
|
---|
| 5029 | }), namespace);
|
---|
| 5030 | this.position++;
|
---|
| 5031 | };
|
---|
| 5032 | _proto.splitWord = function splitWord(namespace, firstCallback) {
|
---|
| 5033 | var _this5 = this;
|
---|
| 5034 | var nextToken = this.nextToken;
|
---|
| 5035 | var word = this.content();
|
---|
| 5036 | while (nextToken && ~[tokens.dollar, tokens.caret, tokens.equals, tokens.word].indexOf(nextToken[_tokenize.FIELDS.TYPE])) {
|
---|
| 5037 | this.position++;
|
---|
| 5038 | var current = this.content();
|
---|
| 5039 | word += current;
|
---|
| 5040 | if (current.lastIndexOf('\\') === current.length - 1) {
|
---|
| 5041 | var next = this.nextToken;
|
---|
| 5042 | if (next && next[_tokenize.FIELDS.TYPE] === tokens.space) {
|
---|
| 5043 | word += this.requiredSpace(this.content(next));
|
---|
| 5044 | this.position++;
|
---|
| 5045 | }
|
---|
| 5046 | }
|
---|
| 5047 | nextToken = this.nextToken;
|
---|
| 5048 | }
|
---|
| 5049 | var hasClass = indexesOf(word, '.').filter(function (i) {
|
---|
| 5050 | // Allow escaped dot within class name
|
---|
| 5051 | var escapedDot = word[i - 1] === '\\';
|
---|
| 5052 | // Allow decimal numbers percent in @keyframes
|
---|
| 5053 | var isKeyframesPercent = /^\d+\.\d+%$/.test(word);
|
---|
| 5054 | return !escapedDot && !isKeyframesPercent;
|
---|
| 5055 | });
|
---|
| 5056 | var hasId = indexesOf(word, '#').filter(function (i) {
|
---|
| 5057 | return word[i - 1] !== '\\';
|
---|
| 5058 | });
|
---|
| 5059 | // Eliminate Sass interpolations from the list of id indexes
|
---|
| 5060 | var interpolations = indexesOf(word, '#{');
|
---|
| 5061 | if (interpolations.length) {
|
---|
| 5062 | hasId = hasId.filter(function (hashIndex) {
|
---|
| 5063 | return !~interpolations.indexOf(hashIndex);
|
---|
| 5064 | });
|
---|
| 5065 | }
|
---|
| 5066 | var indices = (0, _sortAscending["default"])(uniqs([0].concat(hasClass, hasId)));
|
---|
| 5067 | indices.forEach(function (ind, i) {
|
---|
| 5068 | var index = indices[i + 1] || word.length;
|
---|
| 5069 | var value = word.slice(ind, index);
|
---|
| 5070 | if (i === 0 && firstCallback) {
|
---|
| 5071 | return firstCallback.call(_this5, value, indices.length);
|
---|
| 5072 | }
|
---|
| 5073 | var node;
|
---|
| 5074 | var current = _this5.currToken;
|
---|
| 5075 | var sourceIndex = current[_tokenize.FIELDS.START_POS] + indices[i];
|
---|
| 5076 | var source = getSource(current[1], current[2] + ind, current[3], current[2] + (index - 1));
|
---|
| 5077 | if (~hasClass.indexOf(ind)) {
|
---|
| 5078 | var classNameOpts = {
|
---|
| 5079 | value: value.slice(1),
|
---|
| 5080 | source: source,
|
---|
| 5081 | sourceIndex: sourceIndex
|
---|
| 5082 | };
|
---|
| 5083 | node = new _className["default"](unescapeProp(classNameOpts, "value"));
|
---|
| 5084 | } else if (~hasId.indexOf(ind)) {
|
---|
| 5085 | var idOpts = {
|
---|
| 5086 | value: value.slice(1),
|
---|
| 5087 | source: source,
|
---|
| 5088 | sourceIndex: sourceIndex
|
---|
| 5089 | };
|
---|
| 5090 | node = new _id["default"](unescapeProp(idOpts, "value"));
|
---|
| 5091 | } else {
|
---|
| 5092 | var tagOpts = {
|
---|
| 5093 | value: value,
|
---|
| 5094 | source: source,
|
---|
| 5095 | sourceIndex: sourceIndex
|
---|
| 5096 | };
|
---|
| 5097 | unescapeProp(tagOpts, "value");
|
---|
| 5098 | node = new _tag["default"](tagOpts);
|
---|
| 5099 | }
|
---|
| 5100 | _this5.newNode(node, namespace);
|
---|
| 5101 | // Ensure that the namespace is used only once
|
---|
| 5102 | namespace = null;
|
---|
| 5103 | });
|
---|
| 5104 | this.position++;
|
---|
| 5105 | };
|
---|
| 5106 | _proto.word = function word(namespace) {
|
---|
| 5107 | var nextToken = this.nextToken;
|
---|
| 5108 | if (nextToken && this.content(nextToken) === '|') {
|
---|
| 5109 | this.position++;
|
---|
| 5110 | return this.namespace();
|
---|
| 5111 | }
|
---|
| 5112 | return this.splitWord(namespace);
|
---|
| 5113 | };
|
---|
| 5114 | _proto.loop = function loop() {
|
---|
| 5115 | while (this.position < this.tokens.length) {
|
---|
| 5116 | this.parse(true);
|
---|
| 5117 | }
|
---|
| 5118 | this.current._inferEndPosition();
|
---|
| 5119 | return this.root;
|
---|
| 5120 | };
|
---|
| 5121 | _proto.parse = function parse(throwOnParenthesis) {
|
---|
| 5122 | switch (this.currToken[_tokenize.FIELDS.TYPE]) {
|
---|
| 5123 | case tokens.space:
|
---|
| 5124 | this.space();
|
---|
| 5125 | break;
|
---|
| 5126 | case tokens.comment:
|
---|
| 5127 | this.comment();
|
---|
| 5128 | break;
|
---|
| 5129 | case tokens.openParenthesis:
|
---|
| 5130 | this.parentheses();
|
---|
| 5131 | break;
|
---|
| 5132 | case tokens.closeParenthesis:
|
---|
| 5133 | if (throwOnParenthesis) {
|
---|
| 5134 | this.missingParenthesis();
|
---|
| 5135 | }
|
---|
| 5136 | break;
|
---|
| 5137 | case tokens.openSquare:
|
---|
| 5138 | this.attribute();
|
---|
| 5139 | break;
|
---|
| 5140 | case tokens.dollar:
|
---|
| 5141 | case tokens.caret:
|
---|
| 5142 | case tokens.equals:
|
---|
| 5143 | case tokens.word:
|
---|
| 5144 | this.word();
|
---|
| 5145 | break;
|
---|
| 5146 | case tokens.colon:
|
---|
| 5147 | this.pseudo();
|
---|
| 5148 | break;
|
---|
| 5149 | case tokens.comma:
|
---|
| 5150 | this.comma();
|
---|
| 5151 | break;
|
---|
| 5152 | case tokens.asterisk:
|
---|
| 5153 | this.universal();
|
---|
| 5154 | break;
|
---|
| 5155 | case tokens.ampersand:
|
---|
| 5156 | this.nesting();
|
---|
| 5157 | break;
|
---|
| 5158 | case tokens.slash:
|
---|
| 5159 | case tokens.combinator:
|
---|
| 5160 | this.combinator();
|
---|
| 5161 | break;
|
---|
| 5162 | case tokens.str:
|
---|
| 5163 | this.string();
|
---|
| 5164 | break;
|
---|
| 5165 | // These cases throw; no break needed.
|
---|
| 5166 | case tokens.closeSquare:
|
---|
| 5167 | this.missingSquareBracket();
|
---|
| 5168 | case tokens.semicolon:
|
---|
| 5169 | this.missingBackslash();
|
---|
| 5170 | default:
|
---|
| 5171 | this.unexpected();
|
---|
| 5172 | }
|
---|
| 5173 | }
|
---|
| 5174 |
|
---|
| 5175 | /**
|
---|
| 5176 | * Helpers
|
---|
| 5177 | */;
|
---|
| 5178 | _proto.expected = function expected(description, index, found) {
|
---|
| 5179 | if (Array.isArray(description)) {
|
---|
| 5180 | var last = description.pop();
|
---|
| 5181 | description = description.join(', ') + " or " + last;
|
---|
| 5182 | }
|
---|
| 5183 | var an = /^[aeiou]/.test(description[0]) ? 'an' : 'a';
|
---|
| 5184 | if (!found) {
|
---|
| 5185 | return this.error("Expected " + an + " " + description + ".", {
|
---|
| 5186 | index: index
|
---|
| 5187 | });
|
---|
| 5188 | }
|
---|
| 5189 | return this.error("Expected " + an + " " + description + ", found \"" + found + "\" instead.", {
|
---|
| 5190 | index: index
|
---|
| 5191 | });
|
---|
| 5192 | };
|
---|
| 5193 | _proto.requiredSpace = function requiredSpace(space) {
|
---|
| 5194 | return this.options.lossy ? ' ' : space;
|
---|
| 5195 | };
|
---|
| 5196 | _proto.optionalSpace = function optionalSpace(space) {
|
---|
| 5197 | return this.options.lossy ? '' : space;
|
---|
| 5198 | };
|
---|
| 5199 | _proto.lossySpace = function lossySpace(space, required) {
|
---|
| 5200 | if (this.options.lossy) {
|
---|
| 5201 | return required ? ' ' : '';
|
---|
| 5202 | } else {
|
---|
| 5203 | return space;
|
---|
| 5204 | }
|
---|
| 5205 | };
|
---|
| 5206 | _proto.parseParenthesisToken = function parseParenthesisToken(token) {
|
---|
| 5207 | var content = this.content(token);
|
---|
| 5208 | if (token[_tokenize.FIELDS.TYPE] === tokens.space) {
|
---|
| 5209 | return this.requiredSpace(content);
|
---|
| 5210 | } else {
|
---|
| 5211 | return content;
|
---|
| 5212 | }
|
---|
| 5213 | };
|
---|
| 5214 | _proto.newNode = function newNode(node, namespace) {
|
---|
| 5215 | if (namespace) {
|
---|
| 5216 | if (/^ +$/.test(namespace)) {
|
---|
| 5217 | if (!this.options.lossy) {
|
---|
| 5218 | this.spaces = (this.spaces || '') + namespace;
|
---|
| 5219 | }
|
---|
| 5220 | namespace = true;
|
---|
| 5221 | }
|
---|
| 5222 | node.namespace = namespace;
|
---|
| 5223 | unescapeProp(node, "namespace");
|
---|
| 5224 | }
|
---|
| 5225 | if (this.spaces) {
|
---|
| 5226 | node.spaces.before = this.spaces;
|
---|
| 5227 | this.spaces = '';
|
---|
| 5228 | }
|
---|
| 5229 | return this.current.append(node);
|
---|
| 5230 | };
|
---|
| 5231 | _proto.content = function content(token) {
|
---|
| 5232 | if (token === undefined) {
|
---|
| 5233 | token = this.currToken;
|
---|
| 5234 | }
|
---|
| 5235 | return this.css.slice(token[_tokenize.FIELDS.START_POS], token[_tokenize.FIELDS.END_POS]);
|
---|
| 5236 | };
|
---|
| 5237 | /**
|
---|
| 5238 | * returns the index of the next non-whitespace, non-comment token.
|
---|
| 5239 | * returns -1 if no meaningful token is found.
|
---|
| 5240 | */
|
---|
| 5241 | _proto.locateNextMeaningfulToken = function locateNextMeaningfulToken(startPosition) {
|
---|
| 5242 | if (startPosition === undefined) {
|
---|
| 5243 | startPosition = this.position + 1;
|
---|
| 5244 | }
|
---|
| 5245 | var searchPosition = startPosition;
|
---|
| 5246 | while (searchPosition < this.tokens.length) {
|
---|
| 5247 | if (WHITESPACE_EQUIV_TOKENS[this.tokens[searchPosition][_tokenize.FIELDS.TYPE]]) {
|
---|
| 5248 | searchPosition++;
|
---|
| 5249 | continue;
|
---|
| 5250 | } else {
|
---|
| 5251 | return searchPosition;
|
---|
| 5252 | }
|
---|
| 5253 | }
|
---|
| 5254 | return -1;
|
---|
| 5255 | };
|
---|
| 5256 | _createClass(Parser, [{
|
---|
| 5257 | key: "currToken",
|
---|
| 5258 | get: function get() {
|
---|
| 5259 | return this.tokens[this.position];
|
---|
| 5260 | }
|
---|
| 5261 | }, {
|
---|
| 5262 | key: "nextToken",
|
---|
| 5263 | get: function get() {
|
---|
| 5264 | return this.tokens[this.position + 1];
|
---|
| 5265 | }
|
---|
| 5266 | }, {
|
---|
| 5267 | key: "prevToken",
|
---|
| 5268 | get: function get() {
|
---|
| 5269 | return this.tokens[this.position - 1];
|
---|
| 5270 | }
|
---|
| 5271 | }]);
|
---|
| 5272 | return Parser;
|
---|
| 5273 | }();
|
---|
| 5274 | exports["default"] = Parser;
|
---|
| 5275 | module.exports = exports.default;
|
---|
| 5276 | } (parser, parser.exports));
|
---|
| 5277 |
|
---|
| 5278 | var parserExports = parser.exports;
|
---|
| 5279 |
|
---|
| 5280 | (function (module, exports) {
|
---|
| 5281 |
|
---|
| 5282 | exports.__esModule = true;
|
---|
| 5283 | exports["default"] = undefined;
|
---|
| 5284 | var _parser = _interopRequireDefault(parserExports);
|
---|
| 5285 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
---|
| 5286 | var Processor = /*#__PURE__*/function () {
|
---|
| 5287 | function Processor(func, options) {
|
---|
| 5288 | this.func = func || function noop() {};
|
---|
| 5289 | this.funcRes = null;
|
---|
| 5290 | this.options = options;
|
---|
| 5291 | }
|
---|
| 5292 | var _proto = Processor.prototype;
|
---|
| 5293 | _proto._shouldUpdateSelector = function _shouldUpdateSelector(rule, options) {
|
---|
| 5294 | if (options === undefined) {
|
---|
| 5295 | options = {};
|
---|
| 5296 | }
|
---|
| 5297 | var merged = Object.assign({}, this.options, options);
|
---|
| 5298 | if (merged.updateSelector === false) {
|
---|
| 5299 | return false;
|
---|
| 5300 | } else {
|
---|
| 5301 | return typeof rule !== "string";
|
---|
| 5302 | }
|
---|
| 5303 | };
|
---|
| 5304 | _proto._isLossy = function _isLossy(options) {
|
---|
| 5305 | if (options === undefined) {
|
---|
| 5306 | options = {};
|
---|
| 5307 | }
|
---|
| 5308 | var merged = Object.assign({}, this.options, options);
|
---|
| 5309 | if (merged.lossless === false) {
|
---|
| 5310 | return true;
|
---|
| 5311 | } else {
|
---|
| 5312 | return false;
|
---|
| 5313 | }
|
---|
| 5314 | };
|
---|
| 5315 | _proto._root = function _root(rule, options) {
|
---|
| 5316 | if (options === undefined) {
|
---|
| 5317 | options = {};
|
---|
| 5318 | }
|
---|
| 5319 | var parser = new _parser["default"](rule, this._parseOptions(options));
|
---|
| 5320 | return parser.root;
|
---|
| 5321 | };
|
---|
| 5322 | _proto._parseOptions = function _parseOptions(options) {
|
---|
| 5323 | return {
|
---|
| 5324 | lossy: this._isLossy(options)
|
---|
| 5325 | };
|
---|
| 5326 | };
|
---|
| 5327 | _proto._run = function _run(rule, options) {
|
---|
| 5328 | var _this = this;
|
---|
| 5329 | if (options === undefined) {
|
---|
| 5330 | options = {};
|
---|
| 5331 | }
|
---|
| 5332 | return new Promise(function (resolve, reject) {
|
---|
| 5333 | try {
|
---|
| 5334 | var root = _this._root(rule, options);
|
---|
| 5335 | Promise.resolve(_this.func(root)).then(function (transform) {
|
---|
| 5336 | var string = undefined;
|
---|
| 5337 | if (_this._shouldUpdateSelector(rule, options)) {
|
---|
| 5338 | string = root.toString();
|
---|
| 5339 | rule.selector = string;
|
---|
| 5340 | }
|
---|
| 5341 | return {
|
---|
| 5342 | transform: transform,
|
---|
| 5343 | root: root,
|
---|
| 5344 | string: string
|
---|
| 5345 | };
|
---|
| 5346 | }).then(resolve, reject);
|
---|
| 5347 | } catch (e) {
|
---|
| 5348 | reject(e);
|
---|
| 5349 | return;
|
---|
| 5350 | }
|
---|
| 5351 | });
|
---|
| 5352 | };
|
---|
| 5353 | _proto._runSync = function _runSync(rule, options) {
|
---|
| 5354 | if (options === undefined) {
|
---|
| 5355 | options = {};
|
---|
| 5356 | }
|
---|
| 5357 | var root = this._root(rule, options);
|
---|
| 5358 | var transform = this.func(root);
|
---|
| 5359 | if (transform && typeof transform.then === "function") {
|
---|
| 5360 | throw new Error("Selector processor returned a promise to a synchronous call.");
|
---|
| 5361 | }
|
---|
| 5362 | var string = undefined;
|
---|
| 5363 | if (options.updateSelector && typeof rule !== "string") {
|
---|
| 5364 | string = root.toString();
|
---|
| 5365 | rule.selector = string;
|
---|
| 5366 | }
|
---|
| 5367 | return {
|
---|
| 5368 | transform: transform,
|
---|
| 5369 | root: root,
|
---|
| 5370 | string: string
|
---|
| 5371 | };
|
---|
| 5372 | }
|
---|
| 5373 |
|
---|
| 5374 | /**
|
---|
| 5375 | * Process rule into a selector AST.
|
---|
| 5376 | *
|
---|
| 5377 | * @param rule {postcss.Rule | string} The css selector to be processed
|
---|
| 5378 | * @param options The options for processing
|
---|
| 5379 | * @returns {Promise<parser.Root>} The AST of the selector after processing it.
|
---|
| 5380 | */;
|
---|
| 5381 | _proto.ast = function ast(rule, options) {
|
---|
| 5382 | return this._run(rule, options).then(function (result) {
|
---|
| 5383 | return result.root;
|
---|
| 5384 | });
|
---|
| 5385 | }
|
---|
| 5386 |
|
---|
| 5387 | /**
|
---|
| 5388 | * Process rule into a selector AST synchronously.
|
---|
| 5389 | *
|
---|
| 5390 | * @param rule {postcss.Rule | string} The css selector to be processed
|
---|
| 5391 | * @param options The options for processing
|
---|
| 5392 | * @returns {parser.Root} The AST of the selector after processing it.
|
---|
| 5393 | */;
|
---|
| 5394 | _proto.astSync = function astSync(rule, options) {
|
---|
| 5395 | return this._runSync(rule, options).root;
|
---|
| 5396 | }
|
---|
| 5397 |
|
---|
| 5398 | /**
|
---|
| 5399 | * Process a selector into a transformed value asynchronously
|
---|
| 5400 | *
|
---|
| 5401 | * @param rule {postcss.Rule | string} The css selector to be processed
|
---|
| 5402 | * @param options The options for processing
|
---|
| 5403 | * @returns {Promise<any>} The value returned by the processor.
|
---|
| 5404 | */;
|
---|
| 5405 | _proto.transform = function transform(rule, options) {
|
---|
| 5406 | return this._run(rule, options).then(function (result) {
|
---|
| 5407 | return result.transform;
|
---|
| 5408 | });
|
---|
| 5409 | }
|
---|
| 5410 |
|
---|
| 5411 | /**
|
---|
| 5412 | * Process a selector into a transformed value synchronously.
|
---|
| 5413 | *
|
---|
| 5414 | * @param rule {postcss.Rule | string} The css selector to be processed
|
---|
| 5415 | * @param options The options for processing
|
---|
| 5416 | * @returns {any} The value returned by the processor.
|
---|
| 5417 | */;
|
---|
| 5418 | _proto.transformSync = function transformSync(rule, options) {
|
---|
| 5419 | return this._runSync(rule, options).transform;
|
---|
| 5420 | }
|
---|
| 5421 |
|
---|
| 5422 | /**
|
---|
| 5423 | * Process a selector into a new selector string asynchronously.
|
---|
| 5424 | *
|
---|
| 5425 | * @param rule {postcss.Rule | string} The css selector to be processed
|
---|
| 5426 | * @param options The options for processing
|
---|
| 5427 | * @returns {string} the selector after processing.
|
---|
| 5428 | */;
|
---|
| 5429 | _proto.process = function process(rule, options) {
|
---|
| 5430 | return this._run(rule, options).then(function (result) {
|
---|
| 5431 | return result.string || result.root.toString();
|
---|
| 5432 | });
|
---|
| 5433 | }
|
---|
| 5434 |
|
---|
| 5435 | /**
|
---|
| 5436 | * Process a selector into a new selector string synchronously.
|
---|
| 5437 | *
|
---|
| 5438 | * @param rule {postcss.Rule | string} The css selector to be processed
|
---|
| 5439 | * @param options The options for processing
|
---|
| 5440 | * @returns {string} the selector after processing.
|
---|
| 5441 | */;
|
---|
| 5442 | _proto.processSync = function processSync(rule, options) {
|
---|
| 5443 | var result = this._runSync(rule, options);
|
---|
| 5444 | return result.string || result.root.toString();
|
---|
| 5445 | };
|
---|
| 5446 | return Processor;
|
---|
| 5447 | }();
|
---|
| 5448 | exports["default"] = Processor;
|
---|
| 5449 | module.exports = exports.default;
|
---|
| 5450 | } (processor, processor.exports));
|
---|
| 5451 |
|
---|
| 5452 | var processorExports = processor.exports;
|
---|
| 5453 |
|
---|
| 5454 | var selectors = {};
|
---|
| 5455 |
|
---|
| 5456 | var constructors = {};
|
---|
| 5457 |
|
---|
| 5458 | constructors.__esModule = true;
|
---|
| 5459 | constructors.universal = constructors.tag = constructors.string = constructors.selector = constructors.root = constructors.pseudo = constructors.nesting = constructors.id = constructors.comment = constructors.combinator = constructors.className = constructors.attribute = undefined;
|
---|
| 5460 | var _attribute = _interopRequireDefault$2(attribute$1);
|
---|
| 5461 | var _className = _interopRequireDefault$2(classNameExports);
|
---|
| 5462 | var _combinator = _interopRequireDefault$2(combinatorExports);
|
---|
| 5463 | var _comment = _interopRequireDefault$2(commentExports);
|
---|
| 5464 | var _id = _interopRequireDefault$2(idExports);
|
---|
| 5465 | var _nesting = _interopRequireDefault$2(nestingExports);
|
---|
| 5466 | var _pseudo = _interopRequireDefault$2(pseudoExports);
|
---|
| 5467 | var _root = _interopRequireDefault$2(rootExports);
|
---|
| 5468 | var _selector = _interopRequireDefault$2(selectorExports);
|
---|
| 5469 | var _string = _interopRequireDefault$2(stringExports);
|
---|
| 5470 | var _tag = _interopRequireDefault$2(tagExports);
|
---|
| 5471 | var _universal = _interopRequireDefault$2(universalExports);
|
---|
| 5472 | function _interopRequireDefault$2(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
---|
| 5473 | var attribute = function attribute(opts) {
|
---|
| 5474 | return new _attribute["default"](opts);
|
---|
| 5475 | };
|
---|
| 5476 | constructors.attribute = attribute;
|
---|
| 5477 | var className = function className(opts) {
|
---|
| 5478 | return new _className["default"](opts);
|
---|
| 5479 | };
|
---|
| 5480 | constructors.className = className;
|
---|
| 5481 | var combinator = function combinator(opts) {
|
---|
| 5482 | return new _combinator["default"](opts);
|
---|
| 5483 | };
|
---|
| 5484 | constructors.combinator = combinator;
|
---|
| 5485 | var comment = function comment(opts) {
|
---|
| 5486 | return new _comment["default"](opts);
|
---|
| 5487 | };
|
---|
| 5488 | constructors.comment = comment;
|
---|
| 5489 | var id = function id(opts) {
|
---|
| 5490 | return new _id["default"](opts);
|
---|
| 5491 | };
|
---|
| 5492 | constructors.id = id;
|
---|
| 5493 | var nesting = function nesting(opts) {
|
---|
| 5494 | return new _nesting["default"](opts);
|
---|
| 5495 | };
|
---|
| 5496 | constructors.nesting = nesting;
|
---|
| 5497 | var pseudo = function pseudo(opts) {
|
---|
| 5498 | return new _pseudo["default"](opts);
|
---|
| 5499 | };
|
---|
| 5500 | constructors.pseudo = pseudo;
|
---|
| 5501 | var root = function root(opts) {
|
---|
| 5502 | return new _root["default"](opts);
|
---|
| 5503 | };
|
---|
| 5504 | constructors.root = root;
|
---|
| 5505 | var selector = function selector(opts) {
|
---|
| 5506 | return new _selector["default"](opts);
|
---|
| 5507 | };
|
---|
| 5508 | constructors.selector = selector;
|
---|
| 5509 | var string = function string(opts) {
|
---|
| 5510 | return new _string["default"](opts);
|
---|
| 5511 | };
|
---|
| 5512 | constructors.string = string;
|
---|
| 5513 | var tag = function tag(opts) {
|
---|
| 5514 | return new _tag["default"](opts);
|
---|
| 5515 | };
|
---|
| 5516 | constructors.tag = tag;
|
---|
| 5517 | var universal = function universal(opts) {
|
---|
| 5518 | return new _universal["default"](opts);
|
---|
| 5519 | };
|
---|
| 5520 | constructors.universal = universal;
|
---|
| 5521 |
|
---|
| 5522 | var guards = {};
|
---|
| 5523 |
|
---|
| 5524 | guards.__esModule = true;
|
---|
| 5525 | guards.isComment = guards.isCombinator = guards.isClassName = guards.isAttribute = undefined;
|
---|
| 5526 | guards.isContainer = isContainer;
|
---|
| 5527 | guards.isIdentifier = undefined;
|
---|
| 5528 | guards.isNamespace = isNamespace;
|
---|
| 5529 | guards.isNesting = undefined;
|
---|
| 5530 | guards.isNode = isNode;
|
---|
| 5531 | guards.isPseudo = undefined;
|
---|
| 5532 | guards.isPseudoClass = isPseudoClass;
|
---|
| 5533 | guards.isPseudoElement = isPseudoElement;
|
---|
| 5534 | guards.isUniversal = guards.isTag = guards.isString = guards.isSelector = guards.isRoot = undefined;
|
---|
| 5535 | var _types = types;
|
---|
| 5536 | var _IS_TYPE;
|
---|
| 5537 | var IS_TYPE = (_IS_TYPE = {}, _IS_TYPE[_types.ATTRIBUTE] = true, _IS_TYPE[_types.CLASS] = true, _IS_TYPE[_types.COMBINATOR] = true, _IS_TYPE[_types.COMMENT] = true, _IS_TYPE[_types.ID] = true, _IS_TYPE[_types.NESTING] = true, _IS_TYPE[_types.PSEUDO] = true, _IS_TYPE[_types.ROOT] = true, _IS_TYPE[_types.SELECTOR] = true, _IS_TYPE[_types.STRING] = true, _IS_TYPE[_types.TAG] = true, _IS_TYPE[_types.UNIVERSAL] = true, _IS_TYPE);
|
---|
| 5538 | function isNode(node) {
|
---|
| 5539 | return typeof node === "object" && IS_TYPE[node.type];
|
---|
| 5540 | }
|
---|
| 5541 | function isNodeType(type, node) {
|
---|
| 5542 | return isNode(node) && node.type === type;
|
---|
| 5543 | }
|
---|
| 5544 | var isAttribute = isNodeType.bind(null, _types.ATTRIBUTE);
|
---|
| 5545 | guards.isAttribute = isAttribute;
|
---|
| 5546 | var isClassName = isNodeType.bind(null, _types.CLASS);
|
---|
| 5547 | guards.isClassName = isClassName;
|
---|
| 5548 | var isCombinator = isNodeType.bind(null, _types.COMBINATOR);
|
---|
| 5549 | guards.isCombinator = isCombinator;
|
---|
| 5550 | var isComment = isNodeType.bind(null, _types.COMMENT);
|
---|
| 5551 | guards.isComment = isComment;
|
---|
| 5552 | var isIdentifier = isNodeType.bind(null, _types.ID);
|
---|
| 5553 | guards.isIdentifier = isIdentifier;
|
---|
| 5554 | var isNesting = isNodeType.bind(null, _types.NESTING);
|
---|
| 5555 | guards.isNesting = isNesting;
|
---|
| 5556 | var isPseudo = isNodeType.bind(null, _types.PSEUDO);
|
---|
| 5557 | guards.isPseudo = isPseudo;
|
---|
| 5558 | var isRoot = isNodeType.bind(null, _types.ROOT);
|
---|
| 5559 | guards.isRoot = isRoot;
|
---|
| 5560 | var isSelector = isNodeType.bind(null, _types.SELECTOR);
|
---|
| 5561 | guards.isSelector = isSelector;
|
---|
| 5562 | var isString = isNodeType.bind(null, _types.STRING);
|
---|
| 5563 | guards.isString = isString;
|
---|
| 5564 | var isTag = isNodeType.bind(null, _types.TAG);
|
---|
| 5565 | guards.isTag = isTag;
|
---|
| 5566 | var isUniversal = isNodeType.bind(null, _types.UNIVERSAL);
|
---|
| 5567 | guards.isUniversal = isUniversal;
|
---|
| 5568 | function isPseudoElement(node) {
|
---|
| 5569 | return isPseudo(node) && node.value && (node.value.startsWith("::") || node.value.toLowerCase() === ":before" || node.value.toLowerCase() === ":after" || node.value.toLowerCase() === ":first-letter" || node.value.toLowerCase() === ":first-line");
|
---|
| 5570 | }
|
---|
| 5571 | function isPseudoClass(node) {
|
---|
| 5572 | return isPseudo(node) && !isPseudoElement(node);
|
---|
| 5573 | }
|
---|
| 5574 | function isContainer(node) {
|
---|
| 5575 | return !!(isNode(node) && node.walk);
|
---|
| 5576 | }
|
---|
| 5577 | function isNamespace(node) {
|
---|
| 5578 | return isAttribute(node) || isTag(node);
|
---|
| 5579 | }
|
---|
| 5580 |
|
---|
| 5581 | (function (exports) {
|
---|
| 5582 |
|
---|
| 5583 | exports.__esModule = true;
|
---|
| 5584 | var _types = types;
|
---|
| 5585 | Object.keys(_types).forEach(function (key) {
|
---|
| 5586 | if (key === "default" || key === "__esModule") return;
|
---|
| 5587 | if (key in exports && exports[key] === _types[key]) return;
|
---|
| 5588 | exports[key] = _types[key];
|
---|
| 5589 | });
|
---|
| 5590 | var _constructors = constructors;
|
---|
| 5591 | Object.keys(_constructors).forEach(function (key) {
|
---|
| 5592 | if (key === "default" || key === "__esModule") return;
|
---|
| 5593 | if (key in exports && exports[key] === _constructors[key]) return;
|
---|
| 5594 | exports[key] = _constructors[key];
|
---|
| 5595 | });
|
---|
| 5596 | var _guards = guards;
|
---|
| 5597 | Object.keys(_guards).forEach(function (key) {
|
---|
| 5598 | if (key === "default" || key === "__esModule") return;
|
---|
| 5599 | if (key in exports && exports[key] === _guards[key]) return;
|
---|
| 5600 | exports[key] = _guards[key];
|
---|
| 5601 | });
|
---|
| 5602 | } (selectors));
|
---|
| 5603 |
|
---|
| 5604 | (function (module, exports) {
|
---|
| 5605 |
|
---|
| 5606 | exports.__esModule = true;
|
---|
| 5607 | exports["default"] = undefined;
|
---|
| 5608 | var _processor = _interopRequireDefault(processorExports);
|
---|
| 5609 | var selectors$1 = _interopRequireWildcard(selectors);
|
---|
| 5610 | function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
---|
| 5611 | function _interopRequireWildcard(obj, nodeInterop) { if (obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
---|
| 5612 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
---|
| 5613 | var parser = function parser(processor) {
|
---|
| 5614 | return new _processor["default"](processor);
|
---|
| 5615 | };
|
---|
| 5616 | Object.assign(parser, selectors$1);
|
---|
| 5617 | delete parser.__esModule;
|
---|
| 5618 | var _default = parser;
|
---|
| 5619 | exports["default"] = _default;
|
---|
| 5620 | module.exports = exports.default;
|
---|
| 5621 | } (dist, dist.exports));
|
---|
| 5622 |
|
---|
| 5623 | var distExports = dist.exports;
|
---|
| 5624 |
|
---|
| 5625 | const selectorParser$1 = distExports;
|
---|
| 5626 | const valueParser = lib;
|
---|
| 5627 | const { extractICSS } = src$4;
|
---|
| 5628 |
|
---|
| 5629 | const isSpacing = (node) => node.type === "combinator" && node.value === " ";
|
---|
| 5630 |
|
---|
| 5631 | function normalizeNodeArray(nodes) {
|
---|
| 5632 | const array = [];
|
---|
| 5633 |
|
---|
| 5634 | nodes.forEach((x) => {
|
---|
| 5635 | if (Array.isArray(x)) {
|
---|
| 5636 | normalizeNodeArray(x).forEach((item) => {
|
---|
| 5637 | array.push(item);
|
---|
| 5638 | });
|
---|
| 5639 | } else if (x) {
|
---|
| 5640 | array.push(x);
|
---|
| 5641 | }
|
---|
| 5642 | });
|
---|
| 5643 |
|
---|
| 5644 | if (array.length > 0 && isSpacing(array[array.length - 1])) {
|
---|
| 5645 | array.pop();
|
---|
| 5646 | }
|
---|
| 5647 | return array;
|
---|
| 5648 | }
|
---|
| 5649 |
|
---|
| 5650 | function localizeNode(rule, mode, localAliasMap) {
|
---|
| 5651 | const transform = (node, context) => {
|
---|
| 5652 | if (context.ignoreNextSpacing && !isSpacing(node)) {
|
---|
| 5653 | throw new Error("Missing whitespace after " + context.ignoreNextSpacing);
|
---|
| 5654 | }
|
---|
| 5655 |
|
---|
| 5656 | if (context.enforceNoSpacing && isSpacing(node)) {
|
---|
| 5657 | throw new Error("Missing whitespace before " + context.enforceNoSpacing);
|
---|
| 5658 | }
|
---|
| 5659 |
|
---|
| 5660 | let newNodes;
|
---|
| 5661 |
|
---|
| 5662 | switch (node.type) {
|
---|
| 5663 | case "root": {
|
---|
| 5664 | let resultingGlobal;
|
---|
| 5665 |
|
---|
| 5666 | context.hasPureGlobals = false;
|
---|
| 5667 |
|
---|
| 5668 | newNodes = node.nodes.map((n) => {
|
---|
| 5669 | const nContext = {
|
---|
| 5670 | global: context.global,
|
---|
| 5671 | lastWasSpacing: true,
|
---|
| 5672 | hasLocals: false,
|
---|
| 5673 | explicit: false,
|
---|
| 5674 | };
|
---|
| 5675 |
|
---|
| 5676 | n = transform(n, nContext);
|
---|
| 5677 |
|
---|
| 5678 | if (typeof resultingGlobal === "undefined") {
|
---|
| 5679 | resultingGlobal = nContext.global;
|
---|
| 5680 | } else if (resultingGlobal !== nContext.global) {
|
---|
| 5681 | throw new Error(
|
---|
| 5682 | 'Inconsistent rule global/local result in rule "' +
|
---|
| 5683 | node +
|
---|
| 5684 | '" (multiple selectors must result in the same mode for the rule)'
|
---|
| 5685 | );
|
---|
| 5686 | }
|
---|
| 5687 |
|
---|
| 5688 | if (!nContext.hasLocals) {
|
---|
| 5689 | context.hasPureGlobals = true;
|
---|
| 5690 | }
|
---|
| 5691 |
|
---|
| 5692 | return n;
|
---|
| 5693 | });
|
---|
| 5694 |
|
---|
| 5695 | context.global = resultingGlobal;
|
---|
| 5696 |
|
---|
| 5697 | node.nodes = normalizeNodeArray(newNodes);
|
---|
| 5698 | break;
|
---|
| 5699 | }
|
---|
| 5700 | case "selector": {
|
---|
| 5701 | newNodes = node.map((childNode) => transform(childNode, context));
|
---|
| 5702 |
|
---|
| 5703 | node = node.clone();
|
---|
| 5704 | node.nodes = normalizeNodeArray(newNodes);
|
---|
| 5705 | break;
|
---|
| 5706 | }
|
---|
| 5707 | case "combinator": {
|
---|
| 5708 | if (isSpacing(node)) {
|
---|
| 5709 | if (context.ignoreNextSpacing) {
|
---|
| 5710 | context.ignoreNextSpacing = false;
|
---|
| 5711 | context.lastWasSpacing = false;
|
---|
| 5712 | context.enforceNoSpacing = false;
|
---|
| 5713 | return null;
|
---|
| 5714 | }
|
---|
| 5715 | context.lastWasSpacing = true;
|
---|
| 5716 | return node;
|
---|
| 5717 | }
|
---|
| 5718 | break;
|
---|
| 5719 | }
|
---|
| 5720 | case "pseudo": {
|
---|
| 5721 | let childContext;
|
---|
| 5722 | const isNested = !!node.length;
|
---|
| 5723 | const isScoped = node.value === ":local" || node.value === ":global";
|
---|
| 5724 | const isImportExport =
|
---|
| 5725 | node.value === ":import" || node.value === ":export";
|
---|
| 5726 |
|
---|
| 5727 | if (isImportExport) {
|
---|
| 5728 | context.hasLocals = true;
|
---|
| 5729 | // :local(.foo)
|
---|
| 5730 | } else if (isNested) {
|
---|
| 5731 | if (isScoped) {
|
---|
| 5732 | if (node.nodes.length === 0) {
|
---|
| 5733 | throw new Error(`${node.value}() can't be empty`);
|
---|
| 5734 | }
|
---|
| 5735 |
|
---|
| 5736 | if (context.inside) {
|
---|
| 5737 | throw new Error(
|
---|
| 5738 | `A ${node.value} is not allowed inside of a ${context.inside}(...)`
|
---|
| 5739 | );
|
---|
| 5740 | }
|
---|
| 5741 |
|
---|
| 5742 | childContext = {
|
---|
| 5743 | global: node.value === ":global",
|
---|
| 5744 | inside: node.value,
|
---|
| 5745 | hasLocals: false,
|
---|
| 5746 | explicit: true,
|
---|
| 5747 | };
|
---|
| 5748 |
|
---|
| 5749 | newNodes = node
|
---|
| 5750 | .map((childNode) => transform(childNode, childContext))
|
---|
| 5751 | .reduce((acc, next) => acc.concat(next.nodes), []);
|
---|
| 5752 |
|
---|
| 5753 | if (newNodes.length) {
|
---|
| 5754 | const { before, after } = node.spaces;
|
---|
| 5755 |
|
---|
| 5756 | const first = newNodes[0];
|
---|
| 5757 | const last = newNodes[newNodes.length - 1];
|
---|
| 5758 |
|
---|
| 5759 | first.spaces = { before, after: first.spaces.after };
|
---|
| 5760 | last.spaces = { before: last.spaces.before, after };
|
---|
| 5761 | }
|
---|
| 5762 |
|
---|
| 5763 | node = newNodes;
|
---|
| 5764 |
|
---|
| 5765 | break;
|
---|
| 5766 | } else {
|
---|
| 5767 | childContext = {
|
---|
| 5768 | global: context.global,
|
---|
| 5769 | inside: context.inside,
|
---|
| 5770 | lastWasSpacing: true,
|
---|
| 5771 | hasLocals: false,
|
---|
| 5772 | explicit: context.explicit,
|
---|
| 5773 | };
|
---|
| 5774 | newNodes = node.map((childNode) => {
|
---|
| 5775 | const newContext = {
|
---|
| 5776 | ...childContext,
|
---|
| 5777 | enforceNoSpacing: false,
|
---|
| 5778 | };
|
---|
| 5779 |
|
---|
| 5780 | const result = transform(childNode, newContext);
|
---|
| 5781 |
|
---|
| 5782 | childContext.global = newContext.global;
|
---|
| 5783 | childContext.hasLocals = newContext.hasLocals;
|
---|
| 5784 |
|
---|
| 5785 | return result;
|
---|
| 5786 | });
|
---|
| 5787 |
|
---|
| 5788 | node = node.clone();
|
---|
| 5789 | node.nodes = normalizeNodeArray(newNodes);
|
---|
| 5790 |
|
---|
| 5791 | if (childContext.hasLocals) {
|
---|
| 5792 | context.hasLocals = true;
|
---|
| 5793 | }
|
---|
| 5794 | }
|
---|
| 5795 | break;
|
---|
| 5796 |
|
---|
| 5797 | //:local .foo .bar
|
---|
| 5798 | } else if (isScoped) {
|
---|
| 5799 | if (context.inside) {
|
---|
| 5800 | throw new Error(
|
---|
| 5801 | `A ${node.value} is not allowed inside of a ${context.inside}(...)`
|
---|
| 5802 | );
|
---|
| 5803 | }
|
---|
| 5804 |
|
---|
| 5805 | const addBackSpacing = !!node.spaces.before;
|
---|
| 5806 |
|
---|
| 5807 | context.ignoreNextSpacing = context.lastWasSpacing
|
---|
| 5808 | ? node.value
|
---|
| 5809 | : false;
|
---|
| 5810 |
|
---|
| 5811 | context.enforceNoSpacing = context.lastWasSpacing
|
---|
| 5812 | ? false
|
---|
| 5813 | : node.value;
|
---|
| 5814 |
|
---|
| 5815 | context.global = node.value === ":global";
|
---|
| 5816 | context.explicit = true;
|
---|
| 5817 |
|
---|
| 5818 | // because this node has spacing that is lost when we remove it
|
---|
| 5819 | // we make up for it by adding an extra combinator in since adding
|
---|
| 5820 | // spacing on the parent selector doesn't work
|
---|
| 5821 | return addBackSpacing
|
---|
| 5822 | ? selectorParser$1.combinator({ value: " " })
|
---|
| 5823 | : null;
|
---|
| 5824 | }
|
---|
| 5825 | break;
|
---|
| 5826 | }
|
---|
| 5827 | case "id":
|
---|
| 5828 | case "class": {
|
---|
| 5829 | if (!node.value) {
|
---|
| 5830 | throw new Error("Invalid class or id selector syntax");
|
---|
| 5831 | }
|
---|
| 5832 |
|
---|
| 5833 | if (context.global) {
|
---|
| 5834 | break;
|
---|
| 5835 | }
|
---|
| 5836 |
|
---|
| 5837 | const isImportedValue = localAliasMap.has(node.value);
|
---|
| 5838 | const isImportedWithExplicitScope = isImportedValue && context.explicit;
|
---|
| 5839 |
|
---|
| 5840 | if (!isImportedValue || isImportedWithExplicitScope) {
|
---|
| 5841 | const innerNode = node.clone();
|
---|
| 5842 | innerNode.spaces = { before: "", after: "" };
|
---|
| 5843 |
|
---|
| 5844 | node = selectorParser$1.pseudo({
|
---|
| 5845 | value: ":local",
|
---|
| 5846 | nodes: [innerNode],
|
---|
| 5847 | spaces: node.spaces,
|
---|
| 5848 | });
|
---|
| 5849 |
|
---|
| 5850 | context.hasLocals = true;
|
---|
| 5851 | }
|
---|
| 5852 |
|
---|
| 5853 | break;
|
---|
| 5854 | }
|
---|
| 5855 | case "nesting": {
|
---|
| 5856 | if (node.value === "&") {
|
---|
| 5857 | context.hasLocals = true;
|
---|
| 5858 | }
|
---|
| 5859 | }
|
---|
| 5860 | }
|
---|
| 5861 |
|
---|
| 5862 | context.lastWasSpacing = false;
|
---|
| 5863 | context.ignoreNextSpacing = false;
|
---|
| 5864 | context.enforceNoSpacing = false;
|
---|
| 5865 |
|
---|
| 5866 | return node;
|
---|
| 5867 | };
|
---|
| 5868 |
|
---|
| 5869 | const rootContext = {
|
---|
| 5870 | global: mode === "global",
|
---|
| 5871 | hasPureGlobals: false,
|
---|
| 5872 | };
|
---|
| 5873 |
|
---|
| 5874 | rootContext.selector = selectorParser$1((root) => {
|
---|
| 5875 | transform(root, rootContext);
|
---|
| 5876 | }).processSync(rule, { updateSelector: false, lossless: true });
|
---|
| 5877 |
|
---|
| 5878 | return rootContext;
|
---|
| 5879 | }
|
---|
| 5880 |
|
---|
| 5881 | function localizeDeclNode(node, context) {
|
---|
| 5882 | switch (node.type) {
|
---|
| 5883 | case "word":
|
---|
| 5884 | if (context.localizeNextItem) {
|
---|
| 5885 | if (!context.localAliasMap.has(node.value)) {
|
---|
| 5886 | node.value = ":local(" + node.value + ")";
|
---|
| 5887 | context.localizeNextItem = false;
|
---|
| 5888 | }
|
---|
| 5889 | }
|
---|
| 5890 | break;
|
---|
| 5891 |
|
---|
| 5892 | case "function":
|
---|
| 5893 | if (
|
---|
| 5894 | context.options &&
|
---|
| 5895 | context.options.rewriteUrl &&
|
---|
| 5896 | node.value.toLowerCase() === "url"
|
---|
| 5897 | ) {
|
---|
| 5898 | node.nodes.map((nestedNode) => {
|
---|
| 5899 | if (nestedNode.type !== "string" && nestedNode.type !== "word") {
|
---|
| 5900 | return;
|
---|
| 5901 | }
|
---|
| 5902 |
|
---|
| 5903 | let newUrl = context.options.rewriteUrl(
|
---|
| 5904 | context.global,
|
---|
| 5905 | nestedNode.value
|
---|
| 5906 | );
|
---|
| 5907 |
|
---|
| 5908 | switch (nestedNode.type) {
|
---|
| 5909 | case "string":
|
---|
| 5910 | if (nestedNode.quote === "'") {
|
---|
| 5911 | newUrl = newUrl.replace(/(\\)/g, "\\$1").replace(/'/g, "\\'");
|
---|
| 5912 | }
|
---|
| 5913 |
|
---|
| 5914 | if (nestedNode.quote === '"') {
|
---|
| 5915 | newUrl = newUrl.replace(/(\\)/g, "\\$1").replace(/"/g, '\\"');
|
---|
| 5916 | }
|
---|
| 5917 |
|
---|
| 5918 | break;
|
---|
| 5919 | case "word":
|
---|
| 5920 | newUrl = newUrl.replace(/("|'|\)|\\)/g, "\\$1");
|
---|
| 5921 | break;
|
---|
| 5922 | }
|
---|
| 5923 |
|
---|
| 5924 | nestedNode.value = newUrl;
|
---|
| 5925 | });
|
---|
| 5926 | }
|
---|
| 5927 | break;
|
---|
| 5928 | }
|
---|
| 5929 | return node;
|
---|
| 5930 | }
|
---|
| 5931 |
|
---|
| 5932 | // `none` is special value, other is global values
|
---|
| 5933 | const specialKeywords = [
|
---|
| 5934 | "none",
|
---|
| 5935 | "inherit",
|
---|
| 5936 | "initial",
|
---|
| 5937 | "revert",
|
---|
| 5938 | "revert-layer",
|
---|
| 5939 | "unset",
|
---|
| 5940 | ];
|
---|
| 5941 |
|
---|
| 5942 | function localizeDeclarationValues(localize, declaration, context) {
|
---|
| 5943 | const valueNodes = valueParser(declaration.value);
|
---|
| 5944 |
|
---|
| 5945 | valueNodes.walk((node, index, nodes) => {
|
---|
| 5946 | if (
|
---|
| 5947 | node.type === "function" &&
|
---|
| 5948 | (node.value.toLowerCase() === "var" || node.value.toLowerCase() === "env")
|
---|
| 5949 | ) {
|
---|
| 5950 | return false;
|
---|
| 5951 | }
|
---|
| 5952 |
|
---|
| 5953 | if (
|
---|
| 5954 | node.type === "word" &&
|
---|
| 5955 | specialKeywords.includes(node.value.toLowerCase())
|
---|
| 5956 | ) {
|
---|
| 5957 | return;
|
---|
| 5958 | }
|
---|
| 5959 |
|
---|
| 5960 | const subContext = {
|
---|
| 5961 | options: context.options,
|
---|
| 5962 | global: context.global,
|
---|
| 5963 | localizeNextItem: localize && !context.global,
|
---|
| 5964 | localAliasMap: context.localAliasMap,
|
---|
| 5965 | };
|
---|
| 5966 | nodes[index] = localizeDeclNode(node, subContext);
|
---|
| 5967 | });
|
---|
| 5968 |
|
---|
| 5969 | declaration.value = valueNodes.toString();
|
---|
| 5970 | }
|
---|
| 5971 |
|
---|
| 5972 | function localizeDeclaration(declaration, context) {
|
---|
| 5973 | const isAnimation = /animation$/i.test(declaration.prop);
|
---|
| 5974 |
|
---|
| 5975 | if (isAnimation) {
|
---|
| 5976 | // letter
|
---|
| 5977 | // An uppercase letter or a lowercase letter.
|
---|
| 5978 | //
|
---|
| 5979 | // ident-start code point
|
---|
| 5980 | // A letter, a non-ASCII code point, or U+005F LOW LINE (_).
|
---|
| 5981 | //
|
---|
| 5982 | // ident code point
|
---|
| 5983 | // An ident-start code point, a digit, or U+002D HYPHEN-MINUS (-).
|
---|
| 5984 |
|
---|
| 5985 | // We don't validate `hex digits`, because we don't need it, it is work of linters.
|
---|
| 5986 | const validIdent =
|
---|
| 5987 | /^-?([a-z\u0080-\uFFFF_]|(\\[^\r\n\f])|-(?![0-9]))((\\[^\r\n\f])|[a-z\u0080-\uFFFF_0-9-])*$/i;
|
---|
| 5988 |
|
---|
| 5989 | /*
|
---|
| 5990 | The spec defines some keywords that you can use to describe properties such as the timing
|
---|
| 5991 | function. These are still valid animation names, so as long as there is a property that accepts
|
---|
| 5992 | a keyword, it is given priority. Only when all the properties that can take a keyword are
|
---|
| 5993 | exhausted can the animation name be set to the keyword. I.e.
|
---|
| 5994 |
|
---|
| 5995 | animation: infinite infinite;
|
---|
| 5996 |
|
---|
| 5997 | The animation will repeat an infinite number of times from the first argument, and will have an
|
---|
| 5998 | animation name of infinite from the second.
|
---|
| 5999 | */
|
---|
| 6000 | const animationKeywords = {
|
---|
| 6001 | // animation-direction
|
---|
| 6002 | $normal: 1,
|
---|
| 6003 | $reverse: 1,
|
---|
| 6004 | $alternate: 1,
|
---|
| 6005 | "$alternate-reverse": 1,
|
---|
| 6006 | // animation-fill-mode
|
---|
| 6007 | $forwards: 1,
|
---|
| 6008 | $backwards: 1,
|
---|
| 6009 | $both: 1,
|
---|
| 6010 | // animation-iteration-count
|
---|
| 6011 | $infinite: 1,
|
---|
| 6012 | // animation-play-state
|
---|
| 6013 | $paused: 1,
|
---|
| 6014 | $running: 1,
|
---|
| 6015 | // animation-timing-function
|
---|
| 6016 | $ease: 1,
|
---|
| 6017 | "$ease-in": 1,
|
---|
| 6018 | "$ease-out": 1,
|
---|
| 6019 | "$ease-in-out": 1,
|
---|
| 6020 | $linear: 1,
|
---|
| 6021 | "$step-end": 1,
|
---|
| 6022 | "$step-start": 1,
|
---|
| 6023 | // Special
|
---|
| 6024 | $none: Infinity, // No matter how many times you write none, it will never be an animation name
|
---|
| 6025 | // Global values
|
---|
| 6026 | $initial: Infinity,
|
---|
| 6027 | $inherit: Infinity,
|
---|
| 6028 | $unset: Infinity,
|
---|
| 6029 | $revert: Infinity,
|
---|
| 6030 | "$revert-layer": Infinity,
|
---|
| 6031 | };
|
---|
| 6032 | let parsedAnimationKeywords = {};
|
---|
| 6033 | const valueNodes = valueParser(declaration.value).walk((node) => {
|
---|
| 6034 | // If div-token appeared (represents as comma ','), a possibility of an animation-keywords should be reflesh.
|
---|
| 6035 | if (node.type === "div") {
|
---|
| 6036 | parsedAnimationKeywords = {};
|
---|
| 6037 |
|
---|
| 6038 | return;
|
---|
| 6039 | }
|
---|
| 6040 | // Do not handle nested functions
|
---|
| 6041 | else if (node.type === "function") {
|
---|
| 6042 | return false;
|
---|
| 6043 | }
|
---|
| 6044 | // Ignore all except word
|
---|
| 6045 | else if (node.type !== "word") {
|
---|
| 6046 | return;
|
---|
| 6047 | }
|
---|
| 6048 |
|
---|
| 6049 | const value = node.type === "word" ? node.value.toLowerCase() : null;
|
---|
| 6050 |
|
---|
| 6051 | let shouldParseAnimationName = false;
|
---|
| 6052 |
|
---|
| 6053 | if (value && validIdent.test(value)) {
|
---|
| 6054 | if ("$" + value in animationKeywords) {
|
---|
| 6055 | parsedAnimationKeywords["$" + value] =
|
---|
| 6056 | "$" + value in parsedAnimationKeywords
|
---|
| 6057 | ? parsedAnimationKeywords["$" + value] + 1
|
---|
| 6058 | : 0;
|
---|
| 6059 |
|
---|
| 6060 | shouldParseAnimationName =
|
---|
| 6061 | parsedAnimationKeywords["$" + value] >=
|
---|
| 6062 | animationKeywords["$" + value];
|
---|
| 6063 | } else {
|
---|
| 6064 | shouldParseAnimationName = true;
|
---|
| 6065 | }
|
---|
| 6066 | }
|
---|
| 6067 |
|
---|
| 6068 | const subContext = {
|
---|
| 6069 | options: context.options,
|
---|
| 6070 | global: context.global,
|
---|
| 6071 | localizeNextItem: shouldParseAnimationName && !context.global,
|
---|
| 6072 | localAliasMap: context.localAliasMap,
|
---|
| 6073 | };
|
---|
| 6074 |
|
---|
| 6075 | return localizeDeclNode(node, subContext);
|
---|
| 6076 | });
|
---|
| 6077 |
|
---|
| 6078 | declaration.value = valueNodes.toString();
|
---|
| 6079 |
|
---|
| 6080 | return;
|
---|
| 6081 | }
|
---|
| 6082 |
|
---|
| 6083 | const isAnimationName = /animation(-name)?$/i.test(declaration.prop);
|
---|
| 6084 |
|
---|
| 6085 | if (isAnimationName) {
|
---|
| 6086 | return localizeDeclarationValues(true, declaration, context);
|
---|
| 6087 | }
|
---|
| 6088 |
|
---|
| 6089 | const hasUrl = /url\(/i.test(declaration.value);
|
---|
| 6090 |
|
---|
| 6091 | if (hasUrl) {
|
---|
| 6092 | return localizeDeclarationValues(false, declaration, context);
|
---|
| 6093 | }
|
---|
| 6094 | }
|
---|
| 6095 |
|
---|
| 6096 | src$2.exports = (options = {}) => {
|
---|
| 6097 | if (
|
---|
| 6098 | options &&
|
---|
| 6099 | options.mode &&
|
---|
| 6100 | options.mode !== "global" &&
|
---|
| 6101 | options.mode !== "local" &&
|
---|
| 6102 | options.mode !== "pure"
|
---|
| 6103 | ) {
|
---|
| 6104 | throw new Error(
|
---|
| 6105 | 'options.mode must be either "global", "local" or "pure" (default "local")'
|
---|
| 6106 | );
|
---|
| 6107 | }
|
---|
| 6108 |
|
---|
| 6109 | const pureMode = options && options.mode === "pure";
|
---|
| 6110 | const globalMode = options && options.mode === "global";
|
---|
| 6111 |
|
---|
| 6112 | return {
|
---|
| 6113 | postcssPlugin: "postcss-modules-local-by-default",
|
---|
| 6114 | prepare() {
|
---|
| 6115 | const localAliasMap = new Map();
|
---|
| 6116 |
|
---|
| 6117 | return {
|
---|
| 6118 | Once(root) {
|
---|
| 6119 | const { icssImports } = extractICSS(root, false);
|
---|
| 6120 |
|
---|
| 6121 | Object.keys(icssImports).forEach((key) => {
|
---|
| 6122 | Object.keys(icssImports[key]).forEach((prop) => {
|
---|
| 6123 | localAliasMap.set(prop, icssImports[key][prop]);
|
---|
| 6124 | });
|
---|
| 6125 | });
|
---|
| 6126 |
|
---|
| 6127 | root.walkAtRules((atRule) => {
|
---|
| 6128 | if (/keyframes$/i.test(atRule.name)) {
|
---|
| 6129 | const globalMatch = /^\s*:global\s*\((.+)\)\s*$/.exec(
|
---|
| 6130 | atRule.params
|
---|
| 6131 | );
|
---|
| 6132 | const localMatch = /^\s*:local\s*\((.+)\)\s*$/.exec(
|
---|
| 6133 | atRule.params
|
---|
| 6134 | );
|
---|
| 6135 |
|
---|
| 6136 | let globalKeyframes = globalMode;
|
---|
| 6137 |
|
---|
| 6138 | if (globalMatch) {
|
---|
| 6139 | if (pureMode) {
|
---|
| 6140 | throw atRule.error(
|
---|
| 6141 | "@keyframes :global(...) is not allowed in pure mode"
|
---|
| 6142 | );
|
---|
| 6143 | }
|
---|
| 6144 | atRule.params = globalMatch[1];
|
---|
| 6145 | globalKeyframes = true;
|
---|
| 6146 | } else if (localMatch) {
|
---|
| 6147 | atRule.params = localMatch[0];
|
---|
| 6148 | globalKeyframes = false;
|
---|
| 6149 | } else if (
|
---|
| 6150 | atRule.params &&
|
---|
| 6151 | !globalMode &&
|
---|
| 6152 | !localAliasMap.has(atRule.params)
|
---|
| 6153 | ) {
|
---|
| 6154 | atRule.params = ":local(" + atRule.params + ")";
|
---|
| 6155 | }
|
---|
| 6156 |
|
---|
| 6157 | atRule.walkDecls((declaration) => {
|
---|
| 6158 | localizeDeclaration(declaration, {
|
---|
| 6159 | localAliasMap,
|
---|
| 6160 | options: options,
|
---|
| 6161 | global: globalKeyframes,
|
---|
| 6162 | });
|
---|
| 6163 | });
|
---|
| 6164 | } else if (/scope$/i.test(atRule.name)) {
|
---|
| 6165 | if (atRule.params) {
|
---|
| 6166 | atRule.params = atRule.params
|
---|
| 6167 | .split("to")
|
---|
| 6168 | .map((item) => {
|
---|
| 6169 | const selector = item.trim().slice(1, -1).trim();
|
---|
| 6170 | const context = localizeNode(
|
---|
| 6171 | selector,
|
---|
| 6172 | options.mode,
|
---|
| 6173 | localAliasMap
|
---|
| 6174 | );
|
---|
| 6175 |
|
---|
| 6176 | context.options = options;
|
---|
| 6177 | context.localAliasMap = localAliasMap;
|
---|
| 6178 |
|
---|
| 6179 | if (pureMode && context.hasPureGlobals) {
|
---|
| 6180 | throw atRule.error(
|
---|
| 6181 | 'Selector in at-rule"' +
|
---|
| 6182 | selector +
|
---|
| 6183 | '" is not pure ' +
|
---|
| 6184 | "(pure selectors must contain at least one local class or id)"
|
---|
| 6185 | );
|
---|
| 6186 | }
|
---|
| 6187 |
|
---|
| 6188 | return `(${context.selector})`;
|
---|
| 6189 | })
|
---|
| 6190 | .join(" to ");
|
---|
| 6191 | }
|
---|
| 6192 |
|
---|
| 6193 | atRule.nodes.forEach((declaration) => {
|
---|
| 6194 | if (declaration.type === "decl") {
|
---|
| 6195 | localizeDeclaration(declaration, {
|
---|
| 6196 | localAliasMap,
|
---|
| 6197 | options: options,
|
---|
| 6198 | global: globalMode,
|
---|
| 6199 | });
|
---|
| 6200 | }
|
---|
| 6201 | });
|
---|
| 6202 | } else if (atRule.nodes) {
|
---|
| 6203 | atRule.nodes.forEach((declaration) => {
|
---|
| 6204 | if (declaration.type === "decl") {
|
---|
| 6205 | localizeDeclaration(declaration, {
|
---|
| 6206 | localAliasMap,
|
---|
| 6207 | options: options,
|
---|
| 6208 | global: globalMode,
|
---|
| 6209 | });
|
---|
| 6210 | }
|
---|
| 6211 | });
|
---|
| 6212 | }
|
---|
| 6213 | });
|
---|
| 6214 |
|
---|
| 6215 | root.walkRules((rule) => {
|
---|
| 6216 | if (
|
---|
| 6217 | rule.parent &&
|
---|
| 6218 | rule.parent.type === "atrule" &&
|
---|
| 6219 | /keyframes$/i.test(rule.parent.name)
|
---|
| 6220 | ) {
|
---|
| 6221 | // ignore keyframe rules
|
---|
| 6222 | return;
|
---|
| 6223 | }
|
---|
| 6224 |
|
---|
| 6225 | const context = localizeNode(rule, options.mode, localAliasMap);
|
---|
| 6226 |
|
---|
| 6227 | context.options = options;
|
---|
| 6228 | context.localAliasMap = localAliasMap;
|
---|
| 6229 |
|
---|
| 6230 | if (pureMode && context.hasPureGlobals) {
|
---|
| 6231 | throw rule.error(
|
---|
| 6232 | 'Selector "' +
|
---|
| 6233 | rule.selector +
|
---|
| 6234 | '" is not pure ' +
|
---|
| 6235 | "(pure selectors must contain at least one local class or id)"
|
---|
| 6236 | );
|
---|
| 6237 | }
|
---|
| 6238 |
|
---|
| 6239 | rule.selector = context.selector;
|
---|
| 6240 |
|
---|
| 6241 | // Less-syntax mixins parse as rules with no nodes
|
---|
| 6242 | if (rule.nodes) {
|
---|
| 6243 | rule.nodes.forEach((declaration) =>
|
---|
| 6244 | localizeDeclaration(declaration, context)
|
---|
| 6245 | );
|
---|
| 6246 | }
|
---|
| 6247 | });
|
---|
| 6248 | },
|
---|
| 6249 | };
|
---|
| 6250 | },
|
---|
| 6251 | };
|
---|
| 6252 | };
|
---|
| 6253 | src$2.exports.postcss = true;
|
---|
| 6254 |
|
---|
| 6255 | var srcExports$1 = src$2.exports;
|
---|
| 6256 |
|
---|
| 6257 | const selectorParser = distExports;
|
---|
| 6258 |
|
---|
| 6259 | const hasOwnProperty = Object.prototype.hasOwnProperty;
|
---|
| 6260 |
|
---|
| 6261 | function isNestedRule(rule) {
|
---|
| 6262 | if (!rule.parent || rule.parent.type === "root") {
|
---|
| 6263 | return false;
|
---|
| 6264 | }
|
---|
| 6265 |
|
---|
| 6266 | if (rule.parent.type === "rule") {
|
---|
| 6267 | return true;
|
---|
| 6268 | }
|
---|
| 6269 |
|
---|
| 6270 | return isNestedRule(rule.parent);
|
---|
| 6271 | }
|
---|
| 6272 |
|
---|
| 6273 | function getSingleLocalNamesForComposes(root, rule) {
|
---|
| 6274 | if (isNestedRule(rule)) {
|
---|
| 6275 | throw new Error(`composition is not allowed in nested rule \n\n${rule}`);
|
---|
| 6276 | }
|
---|
| 6277 |
|
---|
| 6278 | return root.nodes.map((node) => {
|
---|
| 6279 | if (node.type !== "selector" || node.nodes.length !== 1) {
|
---|
| 6280 | throw new Error(
|
---|
| 6281 | `composition is only allowed when selector is single :local class name not in "${root}"`
|
---|
| 6282 | );
|
---|
| 6283 | }
|
---|
| 6284 |
|
---|
| 6285 | node = node.nodes[0];
|
---|
| 6286 |
|
---|
| 6287 | if (
|
---|
| 6288 | node.type !== "pseudo" ||
|
---|
| 6289 | node.value !== ":local" ||
|
---|
| 6290 | node.nodes.length !== 1
|
---|
| 6291 | ) {
|
---|
| 6292 | throw new Error(
|
---|
| 6293 | 'composition is only allowed when selector is single :local class name not in "' +
|
---|
| 6294 | root +
|
---|
| 6295 | '", "' +
|
---|
| 6296 | node +
|
---|
| 6297 | '" is weird'
|
---|
| 6298 | );
|
---|
| 6299 | }
|
---|
| 6300 |
|
---|
| 6301 | node = node.first;
|
---|
| 6302 |
|
---|
| 6303 | if (node.type !== "selector" || node.length !== 1) {
|
---|
| 6304 | throw new Error(
|
---|
| 6305 | 'composition is only allowed when selector is single :local class name not in "' +
|
---|
| 6306 | root +
|
---|
| 6307 | '", "' +
|
---|
| 6308 | node +
|
---|
| 6309 | '" is weird'
|
---|
| 6310 | );
|
---|
| 6311 | }
|
---|
| 6312 |
|
---|
| 6313 | node = node.first;
|
---|
| 6314 |
|
---|
| 6315 | if (node.type !== "class") {
|
---|
| 6316 | // 'id' is not possible, because you can't compose ids
|
---|
| 6317 | throw new Error(
|
---|
| 6318 | 'composition is only allowed when selector is single :local class name not in "' +
|
---|
| 6319 | root +
|
---|
| 6320 | '", "' +
|
---|
| 6321 | node +
|
---|
| 6322 | '" is weird'
|
---|
| 6323 | );
|
---|
| 6324 | }
|
---|
| 6325 |
|
---|
| 6326 | return node.value;
|
---|
| 6327 | });
|
---|
| 6328 | }
|
---|
| 6329 |
|
---|
| 6330 | const whitespace = "[\\x20\\t\\r\\n\\f]";
|
---|
| 6331 | const unescapeRegExp = new RegExp(
|
---|
| 6332 | "\\\\([\\da-f]{1,6}" + whitespace + "?|(" + whitespace + ")|.)",
|
---|
| 6333 | "ig"
|
---|
| 6334 | );
|
---|
| 6335 |
|
---|
| 6336 | function unescape(str) {
|
---|
| 6337 | return str.replace(unescapeRegExp, (_, escaped, escapedWhitespace) => {
|
---|
| 6338 | const high = "0x" + escaped - 0x10000;
|
---|
| 6339 |
|
---|
| 6340 | // NaN means non-codepoint
|
---|
| 6341 | // Workaround erroneous numeric interpretation of +"0x"
|
---|
| 6342 | return high !== high || escapedWhitespace
|
---|
| 6343 | ? escaped
|
---|
| 6344 | : high < 0
|
---|
| 6345 | ? // BMP codepoint
|
---|
| 6346 | String.fromCharCode(high + 0x10000)
|
---|
| 6347 | : // Supplemental Plane codepoint (surrogate pair)
|
---|
| 6348 | String.fromCharCode((high >> 10) | 0xd800, (high & 0x3ff) | 0xdc00);
|
---|
| 6349 | });
|
---|
| 6350 | }
|
---|
| 6351 |
|
---|
| 6352 | const plugin = (options = {}) => {
|
---|
| 6353 | const generateScopedName =
|
---|
| 6354 | (options && options.generateScopedName) || plugin.generateScopedName;
|
---|
| 6355 | const generateExportEntry =
|
---|
| 6356 | (options && options.generateExportEntry) || plugin.generateExportEntry;
|
---|
| 6357 | const exportGlobals = options && options.exportGlobals;
|
---|
| 6358 |
|
---|
| 6359 | return {
|
---|
| 6360 | postcssPlugin: "postcss-modules-scope",
|
---|
| 6361 | Once(root, { rule }) {
|
---|
| 6362 | const exports = Object.create(null);
|
---|
| 6363 |
|
---|
| 6364 | function exportScopedName(name, rawName, node) {
|
---|
| 6365 | const scopedName = generateScopedName(
|
---|
| 6366 | rawName ? rawName : name,
|
---|
| 6367 | root.source.input.from,
|
---|
| 6368 | root.source.input.css,
|
---|
| 6369 | node
|
---|
| 6370 | );
|
---|
| 6371 | const exportEntry = generateExportEntry(
|
---|
| 6372 | rawName ? rawName : name,
|
---|
| 6373 | scopedName,
|
---|
| 6374 | root.source.input.from,
|
---|
| 6375 | root.source.input.css,
|
---|
| 6376 | node
|
---|
| 6377 | );
|
---|
| 6378 | const { key, value } = exportEntry;
|
---|
| 6379 |
|
---|
| 6380 | exports[key] = exports[key] || [];
|
---|
| 6381 |
|
---|
| 6382 | if (exports[key].indexOf(value) < 0) {
|
---|
| 6383 | exports[key].push(value);
|
---|
| 6384 | }
|
---|
| 6385 |
|
---|
| 6386 | return scopedName;
|
---|
| 6387 | }
|
---|
| 6388 |
|
---|
| 6389 | function localizeNode(node) {
|
---|
| 6390 | switch (node.type) {
|
---|
| 6391 | case "selector":
|
---|
| 6392 | node.nodes = node.map((item) => localizeNode(item));
|
---|
| 6393 | return node;
|
---|
| 6394 | case "class":
|
---|
| 6395 | return selectorParser.className({
|
---|
| 6396 | value: exportScopedName(
|
---|
| 6397 | node.value,
|
---|
| 6398 | node.raws && node.raws.value ? node.raws.value : null,
|
---|
| 6399 | node
|
---|
| 6400 | ),
|
---|
| 6401 | });
|
---|
| 6402 | case "id": {
|
---|
| 6403 | return selectorParser.id({
|
---|
| 6404 | value: exportScopedName(
|
---|
| 6405 | node.value,
|
---|
| 6406 | node.raws && node.raws.value ? node.raws.value : null,
|
---|
| 6407 | node
|
---|
| 6408 | ),
|
---|
| 6409 | });
|
---|
| 6410 | }
|
---|
| 6411 | case "attribute": {
|
---|
| 6412 | if (node.attribute === "class" && node.operator === "=") {
|
---|
| 6413 | return selectorParser.attribute({
|
---|
| 6414 | attribute: node.attribute,
|
---|
| 6415 | operator: node.operator,
|
---|
| 6416 | quoteMark: "'",
|
---|
| 6417 | value: exportScopedName(node.value, null, null),
|
---|
| 6418 | });
|
---|
| 6419 | }
|
---|
| 6420 | }
|
---|
| 6421 | }
|
---|
| 6422 |
|
---|
| 6423 | throw new Error(
|
---|
| 6424 | `${node.type} ("${node}") is not allowed in a :local block`
|
---|
| 6425 | );
|
---|
| 6426 | }
|
---|
| 6427 |
|
---|
| 6428 | function traverseNode(node) {
|
---|
| 6429 | switch (node.type) {
|
---|
| 6430 | case "pseudo":
|
---|
| 6431 | if (node.value === ":local") {
|
---|
| 6432 | if (node.nodes.length !== 1) {
|
---|
| 6433 | throw new Error('Unexpected comma (",") in :local block');
|
---|
| 6434 | }
|
---|
| 6435 |
|
---|
| 6436 | const selector = localizeNode(node.first);
|
---|
| 6437 | // move the spaces that were around the pseudo selector to the first
|
---|
| 6438 | // non-container node
|
---|
| 6439 | selector.first.spaces = node.spaces;
|
---|
| 6440 |
|
---|
| 6441 | const nextNode = node.next();
|
---|
| 6442 |
|
---|
| 6443 | if (
|
---|
| 6444 | nextNode &&
|
---|
| 6445 | nextNode.type === "combinator" &&
|
---|
| 6446 | nextNode.value === " " &&
|
---|
| 6447 | /\\[A-F0-9]{1,6}$/.test(selector.last.value)
|
---|
| 6448 | ) {
|
---|
| 6449 | selector.last.spaces.after = " ";
|
---|
| 6450 | }
|
---|
| 6451 |
|
---|
| 6452 | node.replaceWith(selector);
|
---|
| 6453 |
|
---|
| 6454 | return;
|
---|
| 6455 | }
|
---|
| 6456 | /* falls through */
|
---|
| 6457 | case "root":
|
---|
| 6458 | case "selector": {
|
---|
| 6459 | node.each((item) => traverseNode(item));
|
---|
| 6460 | break;
|
---|
| 6461 | }
|
---|
| 6462 | case "id":
|
---|
| 6463 | case "class":
|
---|
| 6464 | if (exportGlobals) {
|
---|
| 6465 | exports[node.value] = [node.value];
|
---|
| 6466 | }
|
---|
| 6467 | break;
|
---|
| 6468 | }
|
---|
| 6469 | return node;
|
---|
| 6470 | }
|
---|
| 6471 |
|
---|
| 6472 | // Find any :import and remember imported names
|
---|
| 6473 | const importedNames = {};
|
---|
| 6474 |
|
---|
| 6475 | root.walkRules(/^:import\(.+\)$/, (rule) => {
|
---|
| 6476 | rule.walkDecls((decl) => {
|
---|
| 6477 | importedNames[decl.prop] = true;
|
---|
| 6478 | });
|
---|
| 6479 | });
|
---|
| 6480 |
|
---|
| 6481 | // Find any :local selectors
|
---|
| 6482 | root.walkRules((rule) => {
|
---|
| 6483 | let parsedSelector = selectorParser().astSync(rule);
|
---|
| 6484 |
|
---|
| 6485 | rule.selector = traverseNode(parsedSelector.clone()).toString();
|
---|
| 6486 |
|
---|
| 6487 | rule.walkDecls(/^(composes|compose-with)$/i, (decl) => {
|
---|
| 6488 | const localNames = getSingleLocalNamesForComposes(
|
---|
| 6489 | parsedSelector,
|
---|
| 6490 | decl.parent
|
---|
| 6491 | );
|
---|
| 6492 | const multiple = decl.value.split(",");
|
---|
| 6493 |
|
---|
| 6494 | multiple.forEach((value) => {
|
---|
| 6495 | const classes = value.trim().split(/\s+/);
|
---|
| 6496 |
|
---|
| 6497 | classes.forEach((className) => {
|
---|
| 6498 | const global = /^global\(([^)]+)\)$/.exec(className);
|
---|
| 6499 |
|
---|
| 6500 | if (global) {
|
---|
| 6501 | localNames.forEach((exportedName) => {
|
---|
| 6502 | exports[exportedName].push(global[1]);
|
---|
| 6503 | });
|
---|
| 6504 | } else if (hasOwnProperty.call(importedNames, className)) {
|
---|
| 6505 | localNames.forEach((exportedName) => {
|
---|
| 6506 | exports[exportedName].push(className);
|
---|
| 6507 | });
|
---|
| 6508 | } else if (hasOwnProperty.call(exports, className)) {
|
---|
| 6509 | localNames.forEach((exportedName) => {
|
---|
| 6510 | exports[className].forEach((item) => {
|
---|
| 6511 | exports[exportedName].push(item);
|
---|
| 6512 | });
|
---|
| 6513 | });
|
---|
| 6514 | } else {
|
---|
| 6515 | throw decl.error(
|
---|
| 6516 | `referenced class name "${className}" in ${decl.prop} not found`
|
---|
| 6517 | );
|
---|
| 6518 | }
|
---|
| 6519 | });
|
---|
| 6520 | });
|
---|
| 6521 |
|
---|
| 6522 | decl.remove();
|
---|
| 6523 | });
|
---|
| 6524 |
|
---|
| 6525 | // Find any :local values
|
---|
| 6526 | rule.walkDecls((decl) => {
|
---|
| 6527 | if (!/:local\s*\((.+?)\)/.test(decl.value)) {
|
---|
| 6528 | return;
|
---|
| 6529 | }
|
---|
| 6530 |
|
---|
| 6531 | let tokens = decl.value.split(/(,|'[^']*'|"[^"]*")/);
|
---|
| 6532 |
|
---|
| 6533 | tokens = tokens.map((token, idx) => {
|
---|
| 6534 | if (idx === 0 || tokens[idx - 1] === ",") {
|
---|
| 6535 | let result = token;
|
---|
| 6536 |
|
---|
| 6537 | const localMatch = /:local\s*\((.+?)\)/.exec(token);
|
---|
| 6538 |
|
---|
| 6539 | if (localMatch) {
|
---|
| 6540 | const input = localMatch.input;
|
---|
| 6541 | const matchPattern = localMatch[0];
|
---|
| 6542 | const matchVal = localMatch[1];
|
---|
| 6543 | const newVal = exportScopedName(matchVal);
|
---|
| 6544 |
|
---|
| 6545 | result = input.replace(matchPattern, newVal);
|
---|
| 6546 | } else {
|
---|
| 6547 | return token;
|
---|
| 6548 | }
|
---|
| 6549 |
|
---|
| 6550 | return result;
|
---|
| 6551 | } else {
|
---|
| 6552 | return token;
|
---|
| 6553 | }
|
---|
| 6554 | });
|
---|
| 6555 |
|
---|
| 6556 | decl.value = tokens.join("");
|
---|
| 6557 | });
|
---|
| 6558 | });
|
---|
| 6559 |
|
---|
| 6560 | // Find any :local keyframes
|
---|
| 6561 | root.walkAtRules(/keyframes$/i, (atRule) => {
|
---|
| 6562 | const localMatch = /^\s*:local\s*\((.+?)\)\s*$/.exec(atRule.params);
|
---|
| 6563 |
|
---|
| 6564 | if (!localMatch) {
|
---|
| 6565 | return;
|
---|
| 6566 | }
|
---|
| 6567 |
|
---|
| 6568 | atRule.params = exportScopedName(localMatch[1]);
|
---|
| 6569 | });
|
---|
| 6570 |
|
---|
| 6571 | root.walkAtRules(/scope$/i, (atRule) => {
|
---|
| 6572 | if (atRule.params) {
|
---|
| 6573 | atRule.params = atRule.params
|
---|
| 6574 | .split("to")
|
---|
| 6575 | .map((item) => {
|
---|
| 6576 | const selector = item.trim().slice(1, -1).trim();
|
---|
| 6577 |
|
---|
| 6578 | const localMatch = /^\s*:local\s*\((.+?)\)\s*$/.exec(selector);
|
---|
| 6579 |
|
---|
| 6580 | if (!localMatch) {
|
---|
| 6581 | return `(${selector})`;
|
---|
| 6582 | }
|
---|
| 6583 |
|
---|
| 6584 | let parsedSelector = selectorParser().astSync(selector);
|
---|
| 6585 |
|
---|
| 6586 | return `(${traverseNode(parsedSelector).toString()})`;
|
---|
| 6587 | })
|
---|
| 6588 | .join(" to ");
|
---|
| 6589 | }
|
---|
| 6590 | });
|
---|
| 6591 |
|
---|
| 6592 | // If we found any :locals, insert an :export rule
|
---|
| 6593 | const exportedNames = Object.keys(exports);
|
---|
| 6594 |
|
---|
| 6595 | if (exportedNames.length > 0) {
|
---|
| 6596 | const exportRule = rule({ selector: ":export" });
|
---|
| 6597 |
|
---|
| 6598 | exportedNames.forEach((exportedName) =>
|
---|
| 6599 | exportRule.append({
|
---|
| 6600 | prop: exportedName,
|
---|
| 6601 | value: exports[exportedName].join(" "),
|
---|
| 6602 | raws: { before: "\n " },
|
---|
| 6603 | })
|
---|
| 6604 | );
|
---|
| 6605 |
|
---|
| 6606 | root.append(exportRule);
|
---|
| 6607 | }
|
---|
| 6608 | },
|
---|
| 6609 | };
|
---|
| 6610 | };
|
---|
| 6611 |
|
---|
| 6612 | plugin.postcss = true;
|
---|
| 6613 |
|
---|
| 6614 | plugin.generateScopedName = function (name, path) {
|
---|
| 6615 | const sanitisedPath = path
|
---|
| 6616 | .replace(/\.[^./\\]+$/, "")
|
---|
| 6617 | .replace(/[\W_]+/g, "_")
|
---|
| 6618 | .replace(/^_|_$/g, "");
|
---|
| 6619 |
|
---|
| 6620 | return `_${sanitisedPath}__${name}`.trim();
|
---|
| 6621 | };
|
---|
| 6622 |
|
---|
| 6623 | plugin.generateExportEntry = function (name, scopedName) {
|
---|
| 6624 | return {
|
---|
| 6625 | key: unescape(name),
|
---|
| 6626 | value: unescape(scopedName),
|
---|
| 6627 | };
|
---|
| 6628 | };
|
---|
| 6629 |
|
---|
| 6630 | var src$1 = plugin;
|
---|
| 6631 |
|
---|
| 6632 | function hash(str) {
|
---|
| 6633 | var hash = 5381,
|
---|
| 6634 | i = str.length;
|
---|
| 6635 |
|
---|
| 6636 | while(i) {
|
---|
| 6637 | hash = (hash * 33) ^ str.charCodeAt(--i);
|
---|
| 6638 | }
|
---|
| 6639 |
|
---|
| 6640 | /* JavaScript does bitwise operations (like XOR, above) on 32-bit signed
|
---|
| 6641 | * integers. Since we want the results to be always positive, convert the
|
---|
| 6642 | * signed int to an unsigned by doing an unsigned bitshift. */
|
---|
| 6643 | return hash >>> 0;
|
---|
| 6644 | }
|
---|
| 6645 |
|
---|
| 6646 | var stringHash = hash;
|
---|
| 6647 |
|
---|
| 6648 | var src = {exports: {}};
|
---|
| 6649 |
|
---|
| 6650 | const ICSSUtils = src$4;
|
---|
| 6651 |
|
---|
| 6652 | const matchImports = /^(.+?|\([\s\S]+?\))\s+from\s+("[^"]*"|'[^']*'|[\w-]+)$/;
|
---|
| 6653 | const matchValueDefinition = /(?:\s+|^)([\w-]+):?(.*?)$/;
|
---|
| 6654 | const matchImport = /^([\w-]+)(?:\s+as\s+([\w-]+))?/;
|
---|
| 6655 |
|
---|
| 6656 | src.exports = (options) => {
|
---|
| 6657 | let importIndex = 0;
|
---|
| 6658 | const createImportedName =
|
---|
| 6659 | (options && options.createImportedName) ||
|
---|
| 6660 | ((importName /*, path*/) =>
|
---|
| 6661 | `i__const_${importName.replace(/\W/g, "_")}_${importIndex++}`);
|
---|
| 6662 |
|
---|
| 6663 | return {
|
---|
| 6664 | postcssPlugin: "postcss-modules-values",
|
---|
| 6665 | prepare(result) {
|
---|
| 6666 | const importAliases = [];
|
---|
| 6667 | const definitions = {};
|
---|
| 6668 |
|
---|
| 6669 | return {
|
---|
| 6670 | Once(root, postcss) {
|
---|
| 6671 | root.walkAtRules(/value/i, (atRule) => {
|
---|
| 6672 | const matches = atRule.params.match(matchImports);
|
---|
| 6673 |
|
---|
| 6674 | if (matches) {
|
---|
| 6675 | let [, /*match*/ aliases, path] = matches;
|
---|
| 6676 |
|
---|
| 6677 | // We can use constants for path names
|
---|
| 6678 | if (definitions[path]) {
|
---|
| 6679 | path = definitions[path];
|
---|
| 6680 | }
|
---|
| 6681 |
|
---|
| 6682 | const imports = aliases
|
---|
| 6683 | .replace(/^\(\s*([\s\S]+)\s*\)$/, "$1")
|
---|
| 6684 | .split(/\s*,\s*/)
|
---|
| 6685 | .map((alias) => {
|
---|
| 6686 | const tokens = matchImport.exec(alias);
|
---|
| 6687 |
|
---|
| 6688 | if (tokens) {
|
---|
| 6689 | const [, /*match*/ theirName, myName = theirName] = tokens;
|
---|
| 6690 | const importedName = createImportedName(myName);
|
---|
| 6691 | definitions[myName] = importedName;
|
---|
| 6692 | return { theirName, importedName };
|
---|
| 6693 | } else {
|
---|
| 6694 | throw new Error(`@import statement "${alias}" is invalid!`);
|
---|
| 6695 | }
|
---|
| 6696 | });
|
---|
| 6697 |
|
---|
| 6698 | importAliases.push({ path, imports });
|
---|
| 6699 |
|
---|
| 6700 | atRule.remove();
|
---|
| 6701 |
|
---|
| 6702 | return;
|
---|
| 6703 | }
|
---|
| 6704 |
|
---|
| 6705 | if (atRule.params.indexOf("@value") !== -1) {
|
---|
| 6706 | result.warn("Invalid value definition: " + atRule.params);
|
---|
| 6707 | }
|
---|
| 6708 |
|
---|
| 6709 | let [, key, value] = `${atRule.params}${atRule.raws.between}`.match(
|
---|
| 6710 | matchValueDefinition
|
---|
| 6711 | );
|
---|
| 6712 |
|
---|
| 6713 | const normalizedValue = value.replace(/\/\*((?!\*\/).*?)\*\//g, "");
|
---|
| 6714 |
|
---|
| 6715 | if (normalizedValue.length === 0) {
|
---|
| 6716 | result.warn("Invalid value definition: " + atRule.params);
|
---|
| 6717 | atRule.remove();
|
---|
| 6718 |
|
---|
| 6719 | return;
|
---|
| 6720 | }
|
---|
| 6721 |
|
---|
| 6722 | let isOnlySpace = /^\s+$/.test(normalizedValue);
|
---|
| 6723 |
|
---|
| 6724 | if (!isOnlySpace) {
|
---|
| 6725 | value = value.trim();
|
---|
| 6726 | }
|
---|
| 6727 |
|
---|
| 6728 | // Add to the definitions, knowing that values can refer to each other
|
---|
| 6729 | definitions[key] = ICSSUtils.replaceValueSymbols(
|
---|
| 6730 | value,
|
---|
| 6731 | definitions
|
---|
| 6732 | );
|
---|
| 6733 |
|
---|
| 6734 | atRule.remove();
|
---|
| 6735 | });
|
---|
| 6736 |
|
---|
| 6737 | /* If we have no definitions, don't continue */
|
---|
| 6738 | if (!Object.keys(definitions).length) {
|
---|
| 6739 | return;
|
---|
| 6740 | }
|
---|
| 6741 |
|
---|
| 6742 | /* Perform replacements */
|
---|
| 6743 | ICSSUtils.replaceSymbols(root, definitions);
|
---|
| 6744 |
|
---|
| 6745 | /* We want to export anything defined by now, but don't add it to the CSS yet or it well get picked up by the replacement stuff */
|
---|
| 6746 | const exportDeclarations = Object.keys(definitions).map((key) =>
|
---|
| 6747 | postcss.decl({
|
---|
| 6748 | value: definitions[key],
|
---|
| 6749 | prop: key,
|
---|
| 6750 | raws: { before: "\n " },
|
---|
| 6751 | })
|
---|
| 6752 | );
|
---|
| 6753 |
|
---|
| 6754 | /* Add export rules if any */
|
---|
| 6755 | if (exportDeclarations.length > 0) {
|
---|
| 6756 | const exportRule = postcss.rule({
|
---|
| 6757 | selector: ":export",
|
---|
| 6758 | raws: { after: "\n" },
|
---|
| 6759 | });
|
---|
| 6760 |
|
---|
| 6761 | exportRule.append(exportDeclarations);
|
---|
| 6762 |
|
---|
| 6763 | root.prepend(exportRule);
|
---|
| 6764 | }
|
---|
| 6765 |
|
---|
| 6766 | /* Add import rules */
|
---|
| 6767 | importAliases.reverse().forEach(({ path, imports }) => {
|
---|
| 6768 | const importRule = postcss.rule({
|
---|
| 6769 | selector: `:import(${path})`,
|
---|
| 6770 | raws: { after: "\n" },
|
---|
| 6771 | });
|
---|
| 6772 |
|
---|
| 6773 | imports.forEach(({ theirName, importedName }) => {
|
---|
| 6774 | importRule.append({
|
---|
| 6775 | value: theirName,
|
---|
| 6776 | prop: importedName,
|
---|
| 6777 | raws: { before: "\n " },
|
---|
| 6778 | });
|
---|
| 6779 | });
|
---|
| 6780 |
|
---|
| 6781 | root.prepend(importRule);
|
---|
| 6782 | });
|
---|
| 6783 | },
|
---|
| 6784 | };
|
---|
| 6785 | },
|
---|
| 6786 | };
|
---|
| 6787 | };
|
---|
| 6788 |
|
---|
| 6789 | src.exports.postcss = true;
|
---|
| 6790 |
|
---|
| 6791 | var srcExports = src.exports;
|
---|
| 6792 |
|
---|
| 6793 | Object.defineProperty(scoping, "__esModule", {
|
---|
| 6794 | value: true
|
---|
| 6795 | });
|
---|
| 6796 | scoping.behaviours = undefined;
|
---|
| 6797 | scoping.getDefaultPlugins = getDefaultPlugins;
|
---|
| 6798 | scoping.getDefaultScopeBehaviour = getDefaultScopeBehaviour;
|
---|
| 6799 | scoping.getScopedNameGenerator = getScopedNameGenerator;
|
---|
| 6800 |
|
---|
| 6801 | var _postcssModulesExtractImports = _interopRequireDefault$1(srcExports$2);
|
---|
| 6802 |
|
---|
| 6803 | var _genericNames = _interopRequireDefault$1(genericNames);
|
---|
| 6804 |
|
---|
| 6805 | var _postcssModulesLocalByDefault = _interopRequireDefault$1(srcExports$1);
|
---|
| 6806 |
|
---|
| 6807 | var _postcssModulesScope = _interopRequireDefault$1(src$1);
|
---|
| 6808 |
|
---|
| 6809 | var _stringHash = _interopRequireDefault$1(stringHash);
|
---|
| 6810 |
|
---|
| 6811 | var _postcssModulesValues = _interopRequireDefault$1(srcExports);
|
---|
| 6812 |
|
---|
| 6813 | function _interopRequireDefault$1(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
---|
| 6814 |
|
---|
| 6815 | const behaviours = {
|
---|
| 6816 | LOCAL: "local",
|
---|
| 6817 | GLOBAL: "global"
|
---|
| 6818 | };
|
---|
| 6819 | scoping.behaviours = behaviours;
|
---|
| 6820 |
|
---|
| 6821 | function getDefaultPlugins({
|
---|
| 6822 | behaviour,
|
---|
| 6823 | generateScopedName,
|
---|
| 6824 | exportGlobals
|
---|
| 6825 | }) {
|
---|
| 6826 | const scope = (0, _postcssModulesScope.default)({
|
---|
| 6827 | generateScopedName,
|
---|
| 6828 | exportGlobals
|
---|
| 6829 | });
|
---|
| 6830 | const plugins = {
|
---|
| 6831 | [behaviours.LOCAL]: [_postcssModulesValues.default, (0, _postcssModulesLocalByDefault.default)({
|
---|
| 6832 | mode: "local"
|
---|
| 6833 | }), _postcssModulesExtractImports.default, scope],
|
---|
| 6834 | [behaviours.GLOBAL]: [_postcssModulesValues.default, (0, _postcssModulesLocalByDefault.default)({
|
---|
| 6835 | mode: "global"
|
---|
| 6836 | }), _postcssModulesExtractImports.default, scope]
|
---|
| 6837 | };
|
---|
| 6838 | return plugins[behaviour];
|
---|
| 6839 | }
|
---|
| 6840 |
|
---|
| 6841 | function isValidBehaviour(behaviour) {
|
---|
| 6842 | return Object.keys(behaviours).map(key => behaviours[key]).indexOf(behaviour) > -1;
|
---|
| 6843 | }
|
---|
| 6844 |
|
---|
| 6845 | function getDefaultScopeBehaviour(scopeBehaviour) {
|
---|
| 6846 | return scopeBehaviour && isValidBehaviour(scopeBehaviour) ? scopeBehaviour : behaviours.LOCAL;
|
---|
| 6847 | }
|
---|
| 6848 |
|
---|
| 6849 | function generateScopedNameDefault(name, filename, css) {
|
---|
| 6850 | const i = css.indexOf(`.${name}`);
|
---|
| 6851 | const lineNumber = css.substr(0, i).split(/[\r\n]/).length;
|
---|
| 6852 | const hash = (0, _stringHash.default)(css).toString(36).substr(0, 5);
|
---|
| 6853 | return `_${name}_${hash}_${lineNumber}`;
|
---|
| 6854 | }
|
---|
| 6855 |
|
---|
| 6856 | function getScopedNameGenerator(generateScopedName, hashPrefix) {
|
---|
| 6857 | const scopedNameGenerator = generateScopedName || generateScopedNameDefault;
|
---|
| 6858 |
|
---|
| 6859 | if (typeof scopedNameGenerator === "function") {
|
---|
| 6860 | return scopedNameGenerator;
|
---|
| 6861 | }
|
---|
| 6862 |
|
---|
| 6863 | return (0, _genericNames.default)(scopedNameGenerator, {
|
---|
| 6864 | context: process.cwd(),
|
---|
| 6865 | hashPrefix: hashPrefix
|
---|
| 6866 | });
|
---|
| 6867 | }
|
---|
| 6868 |
|
---|
| 6869 | Object.defineProperty(pluginFactory, "__esModule", {
|
---|
| 6870 | value: true
|
---|
| 6871 | });
|
---|
| 6872 | pluginFactory.makePlugin = makePlugin;
|
---|
| 6873 |
|
---|
| 6874 | var _postcss = _interopRequireDefault(require$$0);
|
---|
| 6875 |
|
---|
| 6876 | var _unquote = _interopRequireDefault(unquote$1);
|
---|
| 6877 |
|
---|
| 6878 | var _Parser = _interopRequireDefault(Parser$1);
|
---|
| 6879 |
|
---|
| 6880 | var _saveJSON = _interopRequireDefault(saveJSON$1);
|
---|
| 6881 |
|
---|
| 6882 | var _localsConvention = localsConvention;
|
---|
| 6883 |
|
---|
| 6884 | var _FileSystemLoader = _interopRequireDefault(FileSystemLoader$1);
|
---|
| 6885 |
|
---|
| 6886 | var _scoping = scoping;
|
---|
| 6887 |
|
---|
| 6888 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
---|
| 6889 |
|
---|
| 6890 | const PLUGIN_NAME = "postcss-modules";
|
---|
| 6891 |
|
---|
| 6892 | function isGlobalModule(globalModules, inputFile) {
|
---|
| 6893 | return globalModules.some(regex => inputFile.match(regex));
|
---|
| 6894 | }
|
---|
| 6895 |
|
---|
| 6896 | function getDefaultPluginsList(opts, inputFile) {
|
---|
| 6897 | const globalModulesList = opts.globalModulePaths || null;
|
---|
| 6898 | const exportGlobals = opts.exportGlobals || false;
|
---|
| 6899 | const defaultBehaviour = (0, _scoping.getDefaultScopeBehaviour)(opts.scopeBehaviour);
|
---|
| 6900 | const generateScopedName = (0, _scoping.getScopedNameGenerator)(opts.generateScopedName, opts.hashPrefix);
|
---|
| 6901 |
|
---|
| 6902 | if (globalModulesList && isGlobalModule(globalModulesList, inputFile)) {
|
---|
| 6903 | return (0, _scoping.getDefaultPlugins)({
|
---|
| 6904 | behaviour: _scoping.behaviours.GLOBAL,
|
---|
| 6905 | generateScopedName,
|
---|
| 6906 | exportGlobals
|
---|
| 6907 | });
|
---|
| 6908 | }
|
---|
| 6909 |
|
---|
| 6910 | return (0, _scoping.getDefaultPlugins)({
|
---|
| 6911 | behaviour: defaultBehaviour,
|
---|
| 6912 | generateScopedName,
|
---|
| 6913 | exportGlobals
|
---|
| 6914 | });
|
---|
| 6915 | }
|
---|
| 6916 |
|
---|
| 6917 | function getLoader(opts, plugins) {
|
---|
| 6918 | const root = typeof opts.root === "undefined" ? "/" : opts.root;
|
---|
| 6919 | return typeof opts.Loader === "function" ? new opts.Loader(root, plugins, opts.resolve) : new _FileSystemLoader.default(root, plugins, opts.resolve);
|
---|
| 6920 | }
|
---|
| 6921 |
|
---|
| 6922 | function isOurPlugin(plugin) {
|
---|
| 6923 | return plugin.postcssPlugin === PLUGIN_NAME;
|
---|
| 6924 | }
|
---|
| 6925 |
|
---|
| 6926 | function makePlugin(opts) {
|
---|
| 6927 | return {
|
---|
| 6928 | postcssPlugin: PLUGIN_NAME,
|
---|
| 6929 |
|
---|
| 6930 | async OnceExit(css, {
|
---|
| 6931 | result
|
---|
| 6932 | }) {
|
---|
| 6933 | const getJSON = opts.getJSON || _saveJSON.default;
|
---|
| 6934 | const inputFile = css.source.input.file;
|
---|
| 6935 | const pluginList = getDefaultPluginsList(opts, inputFile);
|
---|
| 6936 | const resultPluginIndex = result.processor.plugins.findIndex(plugin => isOurPlugin(plugin));
|
---|
| 6937 |
|
---|
| 6938 | if (resultPluginIndex === -1) {
|
---|
| 6939 | throw new Error("Plugin missing from options.");
|
---|
| 6940 | }
|
---|
| 6941 |
|
---|
| 6942 | const earlierPlugins = result.processor.plugins.slice(0, resultPluginIndex);
|
---|
| 6943 | const loaderPlugins = [...earlierPlugins, ...pluginList];
|
---|
| 6944 | const loader = getLoader(opts, loaderPlugins);
|
---|
| 6945 |
|
---|
| 6946 | const fetcher = async (file, relativeTo, depTrace) => {
|
---|
| 6947 | const unquoteFile = (0, _unquote.default)(file);
|
---|
| 6948 | return loader.fetch.call(loader, unquoteFile, relativeTo, depTrace);
|
---|
| 6949 | };
|
---|
| 6950 |
|
---|
| 6951 | const parser = new _Parser.default(fetcher);
|
---|
| 6952 | await (0, _postcss.default)([...pluginList, parser.plugin()]).process(css, {
|
---|
| 6953 | from: inputFile
|
---|
| 6954 | });
|
---|
| 6955 | const out = loader.finalSource;
|
---|
| 6956 | if (out) css.prepend(out);
|
---|
| 6957 |
|
---|
| 6958 | if (opts.localsConvention) {
|
---|
| 6959 | const reducer = (0, _localsConvention.makeLocalsConventionReducer)(opts.localsConvention, inputFile);
|
---|
| 6960 | parser.exportTokens = Object.entries(parser.exportTokens).reduce(reducer, {});
|
---|
| 6961 | }
|
---|
| 6962 |
|
---|
| 6963 | result.messages.push({
|
---|
| 6964 | type: "export",
|
---|
| 6965 | plugin: "postcss-modules",
|
---|
| 6966 | exportTokens: parser.exportTokens
|
---|
| 6967 | }); // getJSON may return a promise
|
---|
| 6968 |
|
---|
| 6969 | return getJSON(css.source.input.file, parser.exportTokens, result.opts.to);
|
---|
| 6970 | }
|
---|
| 6971 |
|
---|
| 6972 | };
|
---|
| 6973 | }
|
---|
| 6974 |
|
---|
| 6975 | var _fs = require$$0$2;
|
---|
| 6976 |
|
---|
| 6977 | var _fs2 = fs;
|
---|
| 6978 |
|
---|
| 6979 | var _pluginFactory = pluginFactory;
|
---|
| 6980 |
|
---|
| 6981 | (0, _fs2.setFileSystem)({
|
---|
| 6982 | readFile: _fs.readFile,
|
---|
| 6983 | writeFile: _fs.writeFile
|
---|
| 6984 | });
|
---|
| 6985 |
|
---|
| 6986 | build.exports = (opts = {}) => (0, _pluginFactory.makePlugin)(opts);
|
---|
| 6987 |
|
---|
| 6988 | var postcss = build.exports.postcss = true;
|
---|
| 6989 |
|
---|
| 6990 | var buildExports = build.exports;
|
---|
| 6991 | var index = /*@__PURE__*/getDefaultExportFromCjs(buildExports);
|
---|
| 6992 |
|
---|
| 6993 | var index$1 = /*#__PURE__*/_mergeNamespaces({
|
---|
| 6994 | __proto__: null,
|
---|
| 6995 | default: index,
|
---|
| 6996 | postcss: postcss
|
---|
| 6997 | }, [buildExports]);
|
---|
| 6998 |
|
---|
| 6999 | export { index$1 as i };
|
---|