@everymatrix/general-footer-template 1.55.0 → 1.56.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/dist/cjs/custom-clock.cjs.entry.js +2 -2
  2. package/dist/cjs/custom-content-section.cjs.entry.js +1418 -1564
  3. package/dist/cjs/general-footer-template.cjs.entry.js +1 -1
  4. package/dist/cjs/general-footer-template.cjs.js +2 -2
  5. package/dist/cjs/image-list.cjs.entry.js +1 -1
  6. package/dist/cjs/{index-d85e54c5.js → index-a7f717fa.js} +8 -42
  7. package/dist/cjs/link-section-list.cjs.entry.js +1 -1
  8. package/dist/cjs/loader.cjs.js +1 -1
  9. package/dist/collection/collection-manifest.json +2 -2
  10. package/dist/esm/custom-clock.entry.js +2 -2
  11. package/dist/esm/custom-content-section.entry.js +1418 -1564
  12. package/dist/esm/general-footer-template.entry.js +1 -1
  13. package/dist/esm/general-footer-template.js +3 -3
  14. package/dist/esm/image-list.entry.js +1 -1
  15. package/dist/esm/{index-7f32a4a7.js → index-e6e68604.js} +8 -42
  16. package/dist/esm/link-section-list.entry.js +1 -1
  17. package/dist/esm/loader.js +2 -2
  18. package/dist/general-footer-template/general-footer-template.esm.js +1 -1
  19. package/dist/general-footer-template/{p-9aeab1ea.entry.js → p-076550c8.entry.js} +1 -1
  20. package/dist/general-footer-template/p-16bd4237.js +2 -0
  21. package/dist/general-footer-template/{p-122e0353.entry.js → p-2879096a.entry.js} +1 -1
  22. package/dist/general-footer-template/{p-cd14a119.entry.js → p-5f13c34b.entry.js} +2 -2
  23. package/dist/general-footer-template/{p-a6279430.entry.js → p-d7132f51.entry.js} +1 -1
  24. package/dist/general-footer-template/{p-f5a17365.entry.js → p-f12f5263.entry.js} +1 -1
  25. package/dist/types/stencil-public-runtime.d.ts +0 -6
  26. package/package.json +1 -1
  27. package/dist/general-footer-template/p-905acd21.js +0 -2
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const index$2 = require('./index-d85e54c5.js');
5
+ const index$2 = require('./index-a7f717fa.js');
6
6
  const _commonjsHelpers = require('./_commonjsHelpers-0a7b82d9.js');
7
7
 
8
8
  var decode = {};
@@ -4009,7 +4009,7 @@ const esm = /*#__PURE__*/Object.freeze({
4009
4009
  DomUtils: index
4010
4010
  });
4011
4011
 
4012
- const require$$0$1 = /*@__PURE__*/_commonjsHelpers.getAugmentedNamespace(esm);
4012
+ const require$$0 = /*@__PURE__*/_commonjsHelpers.getAugmentedNamespace(esm);
4013
4013
 
4014
4014
  var escapeStringRegexp$1 = string => {
4015
4015
  if (typeof string !== 'string') {
@@ -4592,70 +4592,37 @@ class CssSyntaxError$3 extends Error {
4592
4592
 
4593
4593
  let css = this.source;
4594
4594
  if (color == null) color = pico.isColorSupported;
4595
-
4596
- let aside = text => text;
4597
- let mark = text => text;
4598
- let highlight = text => text;
4599
- if (color) {
4600
- let { bold, gray, red } = pico.createColors(true);
4601
- mark = text => bold(red(text));
4602
- aside = text => gray(text);
4603
- if (terminalHighlight$1) {
4604
- highlight = text => terminalHighlight$1(text);
4605
- }
4595
+ if (terminalHighlight$1) {
4596
+ if (color) css = terminalHighlight$1(css);
4606
4597
  }
4607
4598
 
4608
4599
  let lines = css.split(/\r?\n/);
4609
4600
  let start = Math.max(this.line - 3, 0);
4610
4601
  let end = Math.min(this.line + 2, lines.length);
4602
+
4611
4603
  let maxWidth = String(end).length;
4612
4604
 
4605
+ let mark, aside;
4606
+ if (color) {
4607
+ let { bold, gray, red } = pico.createColors(true);
4608
+ mark = text => bold(red(text));
4609
+ aside = text => gray(text);
4610
+ } else {
4611
+ mark = aside = str => str;
4612
+ }
4613
+
4613
4614
  return lines
4614
4615
  .slice(start, end)
4615
4616
  .map((line, index) => {
4616
4617
  let number = start + 1 + index;
4617
4618
  let gutter = ' ' + (' ' + number).slice(-maxWidth) + ' | ';
4618
4619
  if (number === this.line) {
4619
- if (line.length > 160) {
4620
- let padding = 20;
4621
- let subLineStart = Math.max(0, this.column - padding);
4622
- let subLineEnd = Math.max(
4623
- this.column + padding,
4624
- this.endColumn + padding
4625
- );
4626
- let subLine = line.slice(subLineStart, subLineEnd);
4627
-
4628
- let spacing =
4629
- aside(gutter.replace(/\d/g, ' ')) +
4630
- line
4631
- .slice(0, Math.min(this.column - 1, padding - 1))
4632
- .replace(/[^\t]/g, ' ');
4633
-
4634
- return (
4635
- mark('>') +
4636
- aside(gutter) +
4637
- highlight(subLine) +
4638
- '\n ' +
4639
- spacing +
4640
- mark('^')
4641
- )
4642
- }
4643
-
4644
4620
  let spacing =
4645
4621
  aside(gutter.replace(/\d/g, ' ')) +
4646
4622
  line.slice(0, this.column - 1).replace(/[^\t]/g, ' ');
4647
-
4648
- return (
4649
- mark('>') +
4650
- aside(gutter) +
4651
- highlight(line) +
4652
- '\n ' +
4653
- spacing +
4654
- mark('^')
4655
- )
4623
+ return mark('>') + aside(gutter) + line + '\n ' + spacing + mark('^')
4656
4624
  }
4657
-
4658
- return ' ' + aside(gutter) + highlight(line)
4625
+ return ' ' + aside(gutter) + line
4659
4626
  })
4660
4627
  .join('\n')
4661
4628
  }
@@ -4672,6 +4639,12 @@ class CssSyntaxError$3 extends Error {
4672
4639
  var cssSyntaxError = CssSyntaxError$3;
4673
4640
  CssSyntaxError$3.default = CssSyntaxError$3;
4674
4641
 
4642
+ var symbols = {};
4643
+
4644
+ symbols.isClean = Symbol('isClean');
4645
+
4646
+ symbols.my = Symbol('my');
4647
+
4675
4648
  const DEFAULT_RAW = {
4676
4649
  after: '\n',
4677
4650
  beforeClose: '\n',
@@ -5034,16 +5007,10 @@ function stringify$4(node, builder) {
5034
5007
  var stringify_1 = stringify$4;
5035
5008
  stringify$4.default = stringify$4;
5036
5009
 
5037
- var symbols = {};
5038
-
5039
- symbols.isClean = Symbol('isClean');
5040
-
5041
- symbols.my = Symbol('my');
5042
-
5010
+ let { isClean: isClean$2, my: my$2 } = symbols;
5043
5011
  let CssSyntaxError$2 = cssSyntaxError;
5044
5012
  let Stringifier = stringifier;
5045
5013
  let stringify$3 = stringify_1;
5046
- let { isClean: isClean$2, my: my$2 } = symbols;
5047
5014
 
5048
5015
  function cloneNode(obj, parent) {
5049
5016
  let cloned = new obj.constructor();
@@ -5072,36 +5039,6 @@ function cloneNode(obj, parent) {
5072
5039
  return cloned
5073
5040
  }
5074
5041
 
5075
- function sourceOffset(inputCSS, position) {
5076
- // Not all custom syntaxes support `offset` in `source.start` and `source.end`
5077
- if (
5078
- position &&
5079
- typeof position.offset !== 'undefined'
5080
- ) {
5081
- return position.offset;
5082
- }
5083
-
5084
- let column = 1;
5085
- let line = 1;
5086
- let offset = 0;
5087
-
5088
- for (let i = 0; i < inputCSS.length; i++) {
5089
- if (line === position.line && column === position.column) {
5090
- offset = i;
5091
- break
5092
- }
5093
-
5094
- if (inputCSS[i] === '\n') {
5095
- column = 1;
5096
- line += 1;
5097
- } else {
5098
- column += 1;
5099
- }
5100
- }
5101
-
5102
- return offset
5103
- }
5104
-
5105
5042
  class Node$4 {
5106
5043
  constructor(defaults = {}) {
5107
5044
  this.raws = {};
@@ -5223,11 +5160,6 @@ class Node$4 {
5223
5160
  }
5224
5161
  }
5225
5162
 
5226
- /* c8 ignore next 3 */
5227
- markClean() {
5228
- this[isClean$2] = true;
5229
- }
5230
-
5231
5163
  markDirty() {
5232
5164
  if (this[isClean$2]) {
5233
5165
  this[isClean$2] = false;
@@ -5244,29 +5176,25 @@ class Node$4 {
5244
5176
  return this.parent.nodes[index + 1]
5245
5177
  }
5246
5178
 
5247
- positionBy(opts) {
5179
+ positionBy(opts, stringRepresentation) {
5248
5180
  let pos = this.source.start;
5249
5181
  if (opts.index) {
5250
- pos = this.positionInside(opts.index);
5182
+ pos = this.positionInside(opts.index, stringRepresentation);
5251
5183
  } else if (opts.word) {
5252
- let stringRepresentation = this.source.input.css.slice(
5253
- sourceOffset(this.source.input.css, this.source.start),
5254
- sourceOffset(this.source.input.css, this.source.end)
5255
- );
5184
+ stringRepresentation = this.toString();
5256
5185
  let index = stringRepresentation.indexOf(opts.word);
5257
- if (index !== -1) pos = this.positionInside(index);
5186
+ if (index !== -1) pos = this.positionInside(index, stringRepresentation);
5258
5187
  }
5259
5188
  return pos
5260
5189
  }
5261
5190
 
5262
- positionInside(index) {
5191
+ positionInside(index, stringRepresentation) {
5192
+ let string = stringRepresentation || this.toString();
5263
5193
  let column = this.source.start.column;
5264
5194
  let line = this.source.start.line;
5265
- let offset = sourceOffset(this.source.input.css, this.source.start);
5266
- let end = offset + index;
5267
5195
 
5268
- for (let i = offset; i < end; i++) {
5269
- if (this.source.input.css[i] === '\n') {
5196
+ for (let i = 0; i < index; i++) {
5197
+ if (string[i] === '\n') {
5270
5198
  column = 1;
5271
5199
  line += 1;
5272
5200
  } else {
@@ -5290,25 +5218,20 @@ class Node$4 {
5290
5218
  };
5291
5219
  let end = this.source.end
5292
5220
  ? {
5293
- column: this.source.end.column + 1,
5294
- line: this.source.end.line
5295
- }
5221
+ column: this.source.end.column + 1,
5222
+ line: this.source.end.line
5223
+ }
5296
5224
  : {
5297
- column: start.column + 1,
5298
- line: start.line
5299
- };
5225
+ column: start.column + 1,
5226
+ line: start.line
5227
+ };
5300
5228
 
5301
5229
  if (opts.word) {
5302
- let stringRepresentation = this.source.input.css.slice(
5303
- sourceOffset(this.source.input.css, this.source.start),
5304
- sourceOffset(this.source.input.css, this.source.end)
5305
- );
5230
+ let stringRepresentation = this.toString();
5306
5231
  let index = stringRepresentation.indexOf(opts.word);
5307
5232
  if (index !== -1) {
5308
- start = this.positionInside(index);
5309
- end = this.positionInside(
5310
- index + opts.word.length,
5311
- );
5233
+ start = this.positionInside(index, stringRepresentation);
5234
+ end = this.positionInside(index + opts.word.length, stringRepresentation);
5312
5235
  }
5313
5236
  } else {
5314
5237
  if (opts.start) {
@@ -5325,7 +5248,7 @@ class Node$4 {
5325
5248
  column: opts.end.column,
5326
5249
  line: opts.end.line
5327
5250
  };
5328
- } else if (typeof opts.endIndex === 'number') {
5251
+ } else if (opts.endIndex) {
5329
5252
  end = this.positionInside(opts.endIndex);
5330
5253
  } else if (opts.index) {
5331
5254
  end = this.positionInside(opts.index + 1);
@@ -5466,19 +5389,7 @@ Node$4.default = Node$4;
5466
5389
 
5467
5390
  let Node$3 = node_1;
5468
5391
 
5469
- class Comment$4 extends Node$3 {
5470
- constructor(defaults) {
5471
- super(defaults);
5472
- this.type = 'comment';
5473
- }
5474
- }
5475
-
5476
- var comment = Comment$4;
5477
- Comment$4.default = Comment$4;
5478
-
5479
- let Node$2 = node_1;
5480
-
5481
- class Declaration$4 extends Node$2 {
5392
+ class Declaration$4 extends Node$3 {
5482
5393
  constructor(defaults) {
5483
5394
  if (
5484
5395
  defaults &&
@@ -5499,1488 +5410,1353 @@ class Declaration$4 extends Node$2 {
5499
5410
  var declaration = Declaration$4;
5500
5411
  Declaration$4.default = Declaration$4;
5501
5412
 
5502
- let Comment$3 = comment;
5503
- let Declaration$3 = declaration;
5504
- let Node$1 = node_1;
5505
- let { isClean: isClean$1, my: my$1 } = symbols;
5413
+ // This alphabet uses `A-Za-z0-9_-` symbols.
5414
+ // The order of characters is optimized for better gzip and brotli compression.
5415
+ // References to the same file (works both for gzip and brotli):
5416
+ // `'use`, `andom`, and `rict'`
5417
+ // References to the brotli default dictionary:
5418
+ // `-26T`, `1983`, `40px`, `75px`, `bush`, `jack`, `mind`, `very`, and `wolf`
5419
+ let urlAlphabet =
5420
+ 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict';
5506
5421
 
5507
- let AtRule$4, parse$4, Root$6, Rule$4;
5422
+ let customAlphabet = (alphabet, defaultSize = 21) => {
5423
+ return (size = defaultSize) => {
5424
+ let id = '';
5425
+ // A compact alternative for `for (var i = 0; i < step; i++)`.
5426
+ let i = size | 0;
5427
+ while (i--) {
5428
+ // `| 0` is more compact and faster than `Math.floor()`.
5429
+ id += alphabet[(Math.random() * alphabet.length) | 0];
5430
+ }
5431
+ return id
5432
+ }
5433
+ };
5508
5434
 
5509
- function cleanSource(nodes) {
5510
- return nodes.map(i => {
5511
- if (i.nodes) i.nodes = cleanSource(i.nodes);
5512
- delete i.source;
5513
- return i
5514
- })
5515
- }
5435
+ let nanoid$1 = (size = 21) => {
5436
+ let id = '';
5437
+ // A compact alternative for `for (var i = 0; i < step; i++)`.
5438
+ let i = size | 0;
5439
+ while (i--) {
5440
+ // `| 0` is more compact and faster than `Math.floor()`.
5441
+ id += urlAlphabet[(Math.random() * 64) | 0];
5442
+ }
5443
+ return id
5444
+ };
5516
5445
 
5517
- function markTreeDirty(node) {
5518
- node[isClean$1] = false;
5519
- if (node.proxyOf.nodes) {
5520
- for (let i of node.proxyOf.nodes) {
5521
- markTreeDirty(i);
5522
- }
5446
+ const nonSecure = /*#__PURE__*/Object.freeze({
5447
+ __proto__: null,
5448
+ nanoid: nanoid$1,
5449
+ customAlphabet: customAlphabet
5450
+ });
5451
+
5452
+ const require$$3 = /*@__PURE__*/_commonjsHelpers.getAugmentedNamespace(nonSecure);
5453
+
5454
+ let { SourceMapConsumer: SourceMapConsumer$2, SourceMapGenerator: SourceMapGenerator$2 } = require$$2;
5455
+ let { existsSync, readFileSync } = require$$2;
5456
+ let { dirname: dirname$1, join } = require$$2;
5457
+
5458
+ function fromBase64(str) {
5459
+ if (Buffer) {
5460
+ return Buffer.from(str, 'base64').toString()
5461
+ } else {
5462
+ /* c8 ignore next 2 */
5463
+ return window.atob(str)
5523
5464
  }
5524
5465
  }
5525
5466
 
5526
- class Container$7 extends Node$1 {
5527
- append(...children) {
5528
- for (let child of children) {
5529
- let nodes = this.normalize(child, this.last);
5530
- for (let node of nodes) this.proxyOf.nodes.push(node);
5531
- }
5532
-
5533
- this.markDirty();
5467
+ class PreviousMap$2 {
5468
+ constructor(css, opts) {
5469
+ if (opts.map === false) return
5470
+ this.loadAnnotation(css);
5471
+ this.inline = this.startWith(this.annotation, 'data:');
5534
5472
 
5535
- return this
5473
+ let prev = opts.map ? opts.map.prev : undefined;
5474
+ let text = this.loadMap(opts.from, prev);
5475
+ if (!this.mapFile && opts.from) {
5476
+ this.mapFile = opts.from;
5477
+ }
5478
+ if (this.mapFile) this.root = dirname$1(this.mapFile);
5479
+ if (text) this.text = text;
5536
5480
  }
5537
5481
 
5538
- cleanRaws(keepBetween) {
5539
- super.cleanRaws(keepBetween);
5540
- if (this.nodes) {
5541
- for (let node of this.nodes) node.cleanRaws(keepBetween);
5482
+ consumer() {
5483
+ if (!this.consumerCache) {
5484
+ this.consumerCache = new SourceMapConsumer$2(this.text);
5542
5485
  }
5486
+ return this.consumerCache
5543
5487
  }
5544
5488
 
5545
- each(callback) {
5546
- if (!this.proxyOf.nodes) return undefined
5547
- let iterator = this.getIterator();
5489
+ decodeInline(text) {
5490
+ let baseCharsetUri = /^data:application\/json;charset=utf-?8;base64,/;
5491
+ let baseUri = /^data:application\/json;base64,/;
5492
+ let charsetUri = /^data:application\/json;charset=utf-?8,/;
5493
+ let uri = /^data:application\/json,/;
5548
5494
 
5549
- let index, result;
5550
- while (this.indexes[iterator] < this.proxyOf.nodes.length) {
5551
- index = this.indexes[iterator];
5552
- result = callback(this.proxyOf.nodes[index], index);
5553
- if (result === false) break
5495
+ if (charsetUri.test(text) || uri.test(text)) {
5496
+ return decodeURIComponent(text.substr(RegExp.lastMatch.length))
5497
+ }
5554
5498
 
5555
- this.indexes[iterator] += 1;
5499
+ if (baseCharsetUri.test(text) || baseUri.test(text)) {
5500
+ return fromBase64(text.substr(RegExp.lastMatch.length))
5556
5501
  }
5557
5502
 
5558
- delete this.indexes[iterator];
5559
- return result
5503
+ let encoding = text.match(/data:application\/json;([^,]+),/)[1];
5504
+ throw new Error('Unsupported source map encoding ' + encoding)
5560
5505
  }
5561
5506
 
5562
- every(condition) {
5563
- return this.nodes.every(condition)
5507
+ getAnnotationURL(sourceMapString) {
5508
+ return sourceMapString.replace(/^\/\*\s*# sourceMappingURL=/, '').trim()
5564
5509
  }
5565
5510
 
5566
- getIterator() {
5567
- if (!this.lastEach) this.lastEach = 0;
5568
- if (!this.indexes) this.indexes = {};
5569
-
5570
- this.lastEach += 1;
5571
- let iterator = this.lastEach;
5572
- this.indexes[iterator] = 0;
5573
-
5574
- return iterator
5511
+ isMap(map) {
5512
+ if (typeof map !== 'object') return false
5513
+ return (
5514
+ typeof map.mappings === 'string' ||
5515
+ typeof map._mappings === 'string' ||
5516
+ Array.isArray(map.sections)
5517
+ )
5575
5518
  }
5576
5519
 
5577
- getProxyProcessor() {
5578
- return {
5579
- get(node, prop) {
5580
- if (prop === 'proxyOf') {
5581
- return node
5582
- } else if (!node[prop]) {
5583
- return node[prop]
5584
- } else if (
5585
- prop === 'each' ||
5586
- (typeof prop === 'string' && prop.startsWith('walk'))
5587
- ) {
5588
- return (...args) => {
5589
- return node[prop](
5590
- ...args.map(i => {
5591
- if (typeof i === 'function') {
5592
- return (child, index) => i(child.toProxy(), index)
5593
- } else {
5594
- return i
5595
- }
5596
- })
5597
- )
5598
- }
5599
- } else if (prop === 'every' || prop === 'some') {
5600
- return cb => {
5601
- return node[prop]((child, ...other) =>
5602
- cb(child.toProxy(), ...other)
5603
- )
5604
- }
5605
- } else if (prop === 'root') {
5606
- return () => node.root().toProxy()
5607
- } else if (prop === 'nodes') {
5608
- return node.nodes.map(i => i.toProxy())
5609
- } else if (prop === 'first' || prop === 'last') {
5610
- return node[prop].toProxy()
5611
- } else {
5612
- return node[prop]
5613
- }
5614
- },
5520
+ loadAnnotation(css) {
5521
+ let comments = css.match(/\/\*\s*# sourceMappingURL=/gm);
5522
+ if (!comments) return
5615
5523
 
5616
- set(node, prop, value) {
5617
- if (node[prop] === value) return true
5618
- node[prop] = value;
5619
- if (prop === 'name' || prop === 'params' || prop === 'selector') {
5620
- node.markDirty();
5621
- }
5622
- return true
5623
- }
5524
+ // sourceMappingURLs from comments, strings, etc.
5525
+ let start = css.lastIndexOf(comments.pop());
5526
+ let end = css.indexOf('*/', start);
5527
+
5528
+ if (start > -1 && end > -1) {
5529
+ // Locate the last sourceMappingURL to avoid pickin
5530
+ this.annotation = this.getAnnotationURL(css.substring(start, end));
5624
5531
  }
5625
5532
  }
5626
5533
 
5627
- index(child) {
5628
- if (typeof child === 'number') return child
5629
- if (child.proxyOf) child = child.proxyOf;
5630
- return this.proxyOf.nodes.indexOf(child)
5534
+ loadFile(path) {
5535
+ this.root = dirname$1(path);
5536
+ if (existsSync(path)) {
5537
+ this.mapFile = path;
5538
+ return readFileSync(path, 'utf-8').toString().trim()
5539
+ }
5631
5540
  }
5632
5541
 
5633
- insertAfter(exist, add) {
5634
- let existIndex = this.index(exist);
5635
- let nodes = this.normalize(add, this.proxyOf.nodes[existIndex]).reverse();
5636
- existIndex = this.index(exist);
5637
- for (let node of nodes) this.proxyOf.nodes.splice(existIndex + 1, 0, node);
5542
+ loadMap(file, prev) {
5543
+ if (prev === false) return false
5638
5544
 
5639
- let index;
5640
- for (let id in this.indexes) {
5641
- index = this.indexes[id];
5642
- if (existIndex < index) {
5643
- this.indexes[id] = index + nodes.length;
5644
- }
5645
- }
5646
-
5647
- this.markDirty();
5648
-
5649
- return this
5650
- }
5651
-
5652
- insertBefore(exist, add) {
5653
- let existIndex = this.index(exist);
5654
- let type = existIndex === 0 ? 'prepend' : false;
5655
- let nodes = this.normalize(
5656
- add,
5657
- this.proxyOf.nodes[existIndex],
5658
- type
5659
- ).reverse();
5660
- existIndex = this.index(exist);
5661
- for (let node of nodes) this.proxyOf.nodes.splice(existIndex, 0, node);
5662
-
5663
- let index;
5664
- for (let id in this.indexes) {
5665
- index = this.indexes[id];
5666
- if (existIndex <= index) {
5667
- this.indexes[id] = index + nodes.length;
5668
- }
5669
- }
5670
-
5671
- this.markDirty();
5672
-
5673
- return this
5674
- }
5675
-
5676
- normalize(nodes, sample) {
5677
- if (typeof nodes === 'string') {
5678
- nodes = cleanSource(parse$4(nodes).nodes);
5679
- } else if (typeof nodes === 'undefined') {
5680
- nodes = [];
5681
- } else if (Array.isArray(nodes)) {
5682
- nodes = nodes.slice(0);
5683
- for (let i of nodes) {
5684
- if (i.parent) i.parent.removeChild(i, 'ignore');
5685
- }
5686
- } else if (nodes.type === 'root' && this.type !== 'document') {
5687
- nodes = nodes.nodes.slice(0);
5688
- for (let i of nodes) {
5689
- if (i.parent) i.parent.removeChild(i, 'ignore');
5690
- }
5691
- } else if (nodes.type) {
5692
- nodes = [nodes];
5693
- } else if (nodes.prop) {
5694
- if (typeof nodes.value === 'undefined') {
5695
- throw new Error('Value field is missed in node creation')
5696
- } else if (typeof nodes.value !== 'string') {
5697
- nodes.value = String(nodes.value);
5698
- }
5699
- nodes = [new Declaration$3(nodes)];
5700
- } else if (nodes.selector || nodes.selectors) {
5701
- nodes = [new Rule$4(nodes)];
5702
- } else if (nodes.name) {
5703
- nodes = [new AtRule$4(nodes)];
5704
- } else if (nodes.text) {
5705
- nodes = [new Comment$3(nodes)];
5706
- } else {
5707
- throw new Error('Unknown node type in node creation')
5708
- }
5709
-
5710
- let processed = nodes.map(i => {
5711
- /* c8 ignore next */
5712
- if (!i[my$1]) Container$7.rebuild(i);
5713
- i = i.proxyOf;
5714
- if (i.parent) i.parent.removeChild(i);
5715
- if (i[isClean$1]) markTreeDirty(i);
5716
-
5717
- if (!i.raws) i.raws = {};
5718
- if (typeof i.raws.before === 'undefined') {
5719
- if (sample && typeof sample.raws.before !== 'undefined') {
5720
- i.raws.before = sample.raws.before.replace(/\S/g, '');
5721
- }
5722
- }
5723
- i.parent = this.proxyOf;
5724
- return i
5725
- });
5726
-
5727
- return processed
5728
- }
5729
-
5730
- prepend(...children) {
5731
- children = children.reverse();
5732
- for (let child of children) {
5733
- let nodes = this.normalize(child, this.first, 'prepend').reverse();
5734
- for (let node of nodes) this.proxyOf.nodes.unshift(node);
5735
- for (let id in this.indexes) {
5736
- this.indexes[id] = this.indexes[id] + nodes.length;
5737
- }
5738
- }
5739
-
5740
- this.markDirty();
5741
-
5742
- return this
5743
- }
5744
-
5745
- push(child) {
5746
- child.parent = this;
5747
- this.proxyOf.nodes.push(child);
5748
- return this
5749
- }
5750
-
5751
- removeAll() {
5752
- for (let node of this.proxyOf.nodes) node.parent = undefined;
5753
- this.proxyOf.nodes = [];
5754
-
5755
- this.markDirty();
5756
-
5757
- return this
5758
- }
5759
-
5760
- removeChild(child) {
5761
- child = this.index(child);
5762
- this.proxyOf.nodes[child].parent = undefined;
5763
- this.proxyOf.nodes.splice(child, 1);
5764
-
5765
- let index;
5766
- for (let id in this.indexes) {
5767
- index = this.indexes[id];
5768
- if (index >= child) {
5769
- this.indexes[id] = index - 1;
5770
- }
5771
- }
5772
-
5773
- this.markDirty();
5774
-
5775
- return this
5776
- }
5777
-
5778
- replaceValues(pattern, opts, callback) {
5779
- if (!callback) {
5780
- callback = opts;
5781
- opts = {};
5782
- }
5783
-
5784
- this.walkDecls(decl => {
5785
- if (opts.props && !opts.props.includes(decl.prop)) return
5786
- if (opts.fast && !decl.value.includes(opts.fast)) return
5787
-
5788
- decl.value = decl.value.replace(pattern, callback);
5789
- });
5790
-
5791
- this.markDirty();
5792
-
5793
- return this
5794
- }
5795
-
5796
- some(condition) {
5797
- return this.nodes.some(condition)
5798
- }
5799
-
5800
- walk(callback) {
5801
- return this.each((child, i) => {
5802
- let result;
5803
- try {
5804
- result = callback(child, i);
5805
- } catch (e) {
5806
- throw child.addToError(e)
5807
- }
5808
- if (result !== false && child.walk) {
5809
- result = child.walk(callback);
5810
- }
5811
-
5812
- return result
5813
- })
5814
- }
5815
-
5816
- walkAtRules(name, callback) {
5817
- if (!callback) {
5818
- callback = name;
5819
- return this.walk((child, i) => {
5820
- if (child.type === 'atrule') {
5821
- return callback(child, i)
5822
- }
5823
- })
5824
- }
5825
- if (name instanceof RegExp) {
5826
- return this.walk((child, i) => {
5827
- if (child.type === 'atrule' && name.test(child.name)) {
5828
- return callback(child, i)
5829
- }
5830
- })
5831
- }
5832
- return this.walk((child, i) => {
5833
- if (child.type === 'atrule' && child.name === name) {
5834
- return callback(child, i)
5835
- }
5836
- })
5837
- }
5838
-
5839
- walkComments(callback) {
5840
- return this.walk((child, i) => {
5841
- if (child.type === 'comment') {
5842
- return callback(child, i)
5843
- }
5844
- })
5845
- }
5846
-
5847
- walkDecls(prop, callback) {
5848
- if (!callback) {
5849
- callback = prop;
5850
- return this.walk((child, i) => {
5851
- if (child.type === 'decl') {
5852
- return callback(child, i)
5853
- }
5854
- })
5855
- }
5856
- if (prop instanceof RegExp) {
5857
- return this.walk((child, i) => {
5858
- if (child.type === 'decl' && prop.test(child.prop)) {
5859
- return callback(child, i)
5545
+ if (prev) {
5546
+ if (typeof prev === 'string') {
5547
+ return prev
5548
+ } else if (typeof prev === 'function') {
5549
+ let prevPath = prev(file);
5550
+ if (prevPath) {
5551
+ let map = this.loadFile(prevPath);
5552
+ if (!map) {
5553
+ throw new Error(
5554
+ 'Unable to load previous source map: ' + prevPath.toString()
5555
+ )
5556
+ }
5557
+ return map
5860
5558
  }
5861
- })
5862
- }
5863
- return this.walk((child, i) => {
5864
- if (child.type === 'decl' && child.prop === prop) {
5865
- return callback(child, i)
5559
+ } else if (prev instanceof SourceMapConsumer$2) {
5560
+ return SourceMapGenerator$2.fromSourceMap(prev).toString()
5561
+ } else if (prev instanceof SourceMapGenerator$2) {
5562
+ return prev.toString()
5563
+ } else if (this.isMap(prev)) {
5564
+ return JSON.stringify(prev)
5565
+ } else {
5566
+ throw new Error(
5567
+ 'Unsupported previous source map format: ' + prev.toString()
5568
+ )
5866
5569
  }
5867
- })
5868
- }
5869
-
5870
- walkRules(selector, callback) {
5871
- if (!callback) {
5872
- callback = selector;
5873
-
5874
- return this.walk((child, i) => {
5875
- if (child.type === 'rule') {
5876
- return callback(child, i)
5877
- }
5878
- })
5879
- }
5880
- if (selector instanceof RegExp) {
5881
- return this.walk((child, i) => {
5882
- if (child.type === 'rule' && selector.test(child.selector)) {
5883
- return callback(child, i)
5884
- }
5885
- })
5570
+ } else if (this.inline) {
5571
+ return this.decodeInline(this.annotation)
5572
+ } else if (this.annotation) {
5573
+ let map = this.annotation;
5574
+ if (file) map = join(dirname$1(file), map);
5575
+ return this.loadFile(map)
5886
5576
  }
5887
- return this.walk((child, i) => {
5888
- if (child.type === 'rule' && child.selector === selector) {
5889
- return callback(child, i)
5890
- }
5891
- })
5892
5577
  }
5893
5578
 
5894
- get first() {
5895
- if (!this.proxyOf.nodes) return undefined
5896
- return this.proxyOf.nodes[0]
5579
+ startWith(string, start) {
5580
+ if (!string) return false
5581
+ return string.substr(0, start.length) === start
5897
5582
  }
5898
5583
 
5899
- get last() {
5900
- if (!this.proxyOf.nodes) return undefined
5901
- return this.proxyOf.nodes[this.proxyOf.nodes.length - 1]
5584
+ withContent() {
5585
+ return !!(
5586
+ this.consumer().sourcesContent &&
5587
+ this.consumer().sourcesContent.length > 0
5588
+ )
5902
5589
  }
5903
5590
  }
5904
5591
 
5905
- Container$7.registerParse = dependant => {
5906
- parse$4 = dependant;
5907
- };
5908
-
5909
- Container$7.registerRule = dependant => {
5910
- Rule$4 = dependant;
5911
- };
5912
-
5913
- Container$7.registerAtRule = dependant => {
5914
- AtRule$4 = dependant;
5915
- };
5916
-
5917
- Container$7.registerRoot = dependant => {
5918
- Root$6 = dependant;
5919
- };
5920
-
5921
- var container = Container$7;
5922
- Container$7.default = Container$7;
5923
-
5924
- /* c8 ignore start */
5925
- Container$7.rebuild = node => {
5926
- if (node.type === 'atrule') {
5927
- Object.setPrototypeOf(node, AtRule$4.prototype);
5928
- } else if (node.type === 'rule') {
5929
- Object.setPrototypeOf(node, Rule$4.prototype);
5930
- } else if (node.type === 'decl') {
5931
- Object.setPrototypeOf(node, Declaration$3.prototype);
5932
- } else if (node.type === 'comment') {
5933
- Object.setPrototypeOf(node, Comment$3.prototype);
5934
- } else if (node.type === 'root') {
5935
- Object.setPrototypeOf(node, Root$6.prototype);
5936
- }
5937
-
5938
- node[my$1] = true;
5939
-
5940
- if (node.nodes) {
5941
- node.nodes.forEach(child => {
5942
- Container$7.rebuild(child);
5943
- });
5944
- }
5945
- };
5946
-
5947
- let Container$6 = container;
5948
-
5949
- class AtRule$3 extends Container$6 {
5950
- constructor(defaults) {
5951
- super(defaults);
5952
- this.type = 'atrule';
5953
- }
5592
+ var previousMap = PreviousMap$2;
5593
+ PreviousMap$2.default = PreviousMap$2;
5954
5594
 
5955
- append(...children) {
5956
- if (!this.proxyOf.nodes) this.nodes = [];
5957
- return super.append(...children)
5958
- }
5595
+ let { SourceMapConsumer: SourceMapConsumer$1, SourceMapGenerator: SourceMapGenerator$1 } = require$$2;
5596
+ let { fileURLToPath, pathToFileURL: pathToFileURL$1 } = require$$2;
5597
+ let { isAbsolute, resolve: resolve$1 } = require$$2;
5598
+ let { nanoid } = require$$3;
5959
5599
 
5960
- prepend(...children) {
5961
- if (!this.proxyOf.nodes) this.nodes = [];
5962
- return super.prepend(...children)
5963
- }
5964
- }
5600
+ let terminalHighlight = require$$2;
5601
+ let CssSyntaxError$1 = cssSyntaxError;
5602
+ let PreviousMap$1 = previousMap;
5965
5603
 
5966
- var atRule = AtRule$3;
5967
- AtRule$3.default = AtRule$3;
5604
+ let fromOffsetCache = Symbol('fromOffsetCache');
5968
5605
 
5969
- Container$6.registerAtRule(AtRule$3);
5606
+ let sourceMapAvailable$1 = Boolean(SourceMapConsumer$1 && SourceMapGenerator$1);
5607
+ let pathAvailable$1 = Boolean(resolve$1 && isAbsolute);
5970
5608
 
5971
- let Container$5 = container;
5609
+ class Input$4 {
5610
+ constructor(css, opts = {}) {
5611
+ if (
5612
+ css === null ||
5613
+ typeof css === 'undefined' ||
5614
+ (typeof css === 'object' && !css.toString)
5615
+ ) {
5616
+ throw new Error(`PostCSS received ${css} instead of CSS string`)
5617
+ }
5972
5618
 
5973
- let LazyResult$4, Processor$3;
5619
+ this.css = css.toString();
5974
5620
 
5975
- class Document$3 extends Container$5 {
5976
- constructor(defaults) {
5977
- // type needs to be passed to super, otherwise child roots won't be normalized correctly
5978
- super({ type: 'document', ...defaults });
5621
+ if (this.css[0] === '\uFEFF' || this.css[0] === '\uFFFE') {
5622
+ this.hasBOM = true;
5623
+ this.css = this.css.slice(1);
5624
+ } else {
5625
+ this.hasBOM = false;
5626
+ }
5979
5627
 
5980
- if (!this.nodes) {
5981
- this.nodes = [];
5628
+ if (opts.from) {
5629
+ if (
5630
+ !pathAvailable$1 ||
5631
+ /^\w+:\/\//.test(opts.from) ||
5632
+ isAbsolute(opts.from)
5633
+ ) {
5634
+ this.file = opts.from;
5635
+ } else {
5636
+ this.file = resolve$1(opts.from);
5637
+ }
5982
5638
  }
5983
- }
5984
5639
 
5985
- toResult(opts = {}) {
5986
- let lazy = new LazyResult$4(new Processor$3(), this, opts);
5640
+ if (pathAvailable$1 && sourceMapAvailable$1) {
5641
+ let map = new PreviousMap$1(this.css, opts);
5642
+ if (map.text) {
5643
+ this.map = map;
5644
+ let file = map.consumer().file;
5645
+ if (!this.file && file) this.file = this.mapResolve(file);
5646
+ }
5647
+ }
5987
5648
 
5988
- return lazy.stringify()
5649
+ if (!this.file) {
5650
+ this.id = '<input css ' + nanoid(6) + '>';
5651
+ }
5652
+ if (this.map) this.map.file = this.from;
5989
5653
  }
5990
- }
5991
5654
 
5992
- Document$3.registerLazyResult = dependant => {
5993
- LazyResult$4 = dependant;
5994
- };
5655
+ error(message, line, column, opts = {}) {
5656
+ let result, endLine, endColumn;
5995
5657
 
5996
- Document$3.registerProcessor = dependant => {
5997
- Processor$3 = dependant;
5998
- };
5658
+ if (line && typeof line === 'object') {
5659
+ let start = line;
5660
+ let end = column;
5661
+ if (typeof start.offset === 'number') {
5662
+ let pos = this.fromOffset(start.offset);
5663
+ line = pos.line;
5664
+ column = pos.col;
5665
+ } else {
5666
+ line = start.line;
5667
+ column = start.column;
5668
+ }
5669
+ if (typeof end.offset === 'number') {
5670
+ let pos = this.fromOffset(end.offset);
5671
+ endLine = pos.line;
5672
+ endColumn = pos.col;
5673
+ } else {
5674
+ endLine = end.line;
5675
+ endColumn = end.column;
5676
+ }
5677
+ } else if (!column) {
5678
+ let pos = this.fromOffset(line);
5679
+ line = pos.line;
5680
+ column = pos.col;
5681
+ }
5999
5682
 
6000
- var document = Document$3;
6001
- Document$3.default = Document$3;
5683
+ let origin = this.origin(line, column, endLine, endColumn);
5684
+ if (origin) {
5685
+ result = new CssSyntaxError$1(
5686
+ message,
5687
+ origin.endLine === undefined
5688
+ ? origin.line
5689
+ : { column: origin.column, line: origin.line },
5690
+ origin.endLine === undefined
5691
+ ? origin.column
5692
+ : { column: origin.endColumn, line: origin.endLine },
5693
+ origin.source,
5694
+ origin.file,
5695
+ opts.plugin
5696
+ );
5697
+ } else {
5698
+ result = new CssSyntaxError$1(
5699
+ message,
5700
+ endLine === undefined ? line : { column, line },
5701
+ endLine === undefined ? column : { column: endColumn, line: endLine },
5702
+ this.css,
5703
+ this.file,
5704
+ opts.plugin
5705
+ );
5706
+ }
6002
5707
 
6003
- let urlAlphabet =
6004
- 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict';
6005
- let customAlphabet = (alphabet, defaultSize = 21) => {
6006
- return (size = defaultSize) => {
6007
- let id = '';
6008
- let i = size;
6009
- while (i--) {
6010
- id += alphabet[(Math.random() * alphabet.length) | 0];
5708
+ result.input = { column, endColumn, endLine, line, source: this.css };
5709
+ if (this.file) {
5710
+ if (pathToFileURL$1) {
5711
+ result.input.url = pathToFileURL$1(this.file).toString();
5712
+ }
5713
+ result.input.file = this.file;
6011
5714
  }
6012
- return id
6013
- }
6014
- };
6015
- let nanoid$1 = (size = 21) => {
6016
- let id = '';
6017
- let i = size;
6018
- while (i--) {
6019
- id += urlAlphabet[(Math.random() * 64) | 0];
5715
+
5716
+ return result
6020
5717
  }
6021
- return id
6022
- };
6023
5718
 
6024
- const nonSecure = /*#__PURE__*/Object.freeze({
6025
- __proto__: null,
6026
- nanoid: nanoid$1,
6027
- customAlphabet: customAlphabet
6028
- });
5719
+ fromOffset(offset) {
5720
+ let lastLine, lineToIndex;
5721
+ if (!this[fromOffsetCache]) {
5722
+ let lines = this.css.split('\n');
5723
+ lineToIndex = new Array(lines.length);
5724
+ let prevIndex = 0;
6029
5725
 
6030
- const require$$0 = /*@__PURE__*/_commonjsHelpers.getAugmentedNamespace(nonSecure);
5726
+ for (let i = 0, l = lines.length; i < l; i++) {
5727
+ lineToIndex[i] = prevIndex;
5728
+ prevIndex += lines[i].length + 1;
5729
+ }
6031
5730
 
6032
- let { existsSync, readFileSync } = require$$2;
6033
- let { dirname: dirname$1, join } = require$$2;
6034
- let { SourceMapConsumer: SourceMapConsumer$2, SourceMapGenerator: SourceMapGenerator$2 } = require$$2;
5731
+ this[fromOffsetCache] = lineToIndex;
5732
+ } else {
5733
+ lineToIndex = this[fromOffsetCache];
5734
+ }
5735
+ lastLine = lineToIndex[lineToIndex.length - 1];
6035
5736
 
6036
- function fromBase64(str) {
6037
- if (Buffer) {
6038
- return Buffer.from(str, 'base64').toString()
6039
- } else {
6040
- /* c8 ignore next 2 */
6041
- return window.atob(str)
5737
+ let min = 0;
5738
+ if (offset >= lastLine) {
5739
+ min = lineToIndex.length - 1;
5740
+ } else {
5741
+ let max = lineToIndex.length - 2;
5742
+ let mid;
5743
+ while (min < max) {
5744
+ mid = min + ((max - min) >> 1);
5745
+ if (offset < lineToIndex[mid]) {
5746
+ max = mid - 1;
5747
+ } else if (offset >= lineToIndex[mid + 1]) {
5748
+ min = mid + 1;
5749
+ } else {
5750
+ min = mid;
5751
+ break
5752
+ }
5753
+ }
5754
+ }
5755
+ return {
5756
+ col: offset - lineToIndex[min] + 1,
5757
+ line: min + 1
5758
+ }
6042
5759
  }
6043
- }
6044
-
6045
- class PreviousMap$2 {
6046
- constructor(css, opts) {
6047
- if (opts.map === false) return
6048
- this.loadAnnotation(css);
6049
- this.inline = this.startWith(this.annotation, 'data:');
6050
5760
 
6051
- let prev = opts.map ? opts.map.prev : undefined;
6052
- let text = this.loadMap(opts.from, prev);
6053
- if (!this.mapFile && opts.from) {
6054
- this.mapFile = opts.from;
5761
+ mapResolve(file) {
5762
+ if (/^\w+:\/\//.test(file)) {
5763
+ return file
6055
5764
  }
6056
- if (this.mapFile) this.root = dirname$1(this.mapFile);
6057
- if (text) this.text = text;
5765
+ return resolve$1(this.map.consumer().sourceRoot || this.map.root || '.', file)
6058
5766
  }
6059
5767
 
6060
- consumer() {
6061
- if (!this.consumerCache) {
6062
- this.consumerCache = new SourceMapConsumer$2(this.text);
5768
+ origin(line, column, endLine, endColumn) {
5769
+ if (!this.map) return false
5770
+ let consumer = this.map.consumer();
5771
+
5772
+ let from = consumer.originalPositionFor({ column, line });
5773
+ if (!from.source) return false
5774
+
5775
+ let to;
5776
+ if (typeof endLine === 'number') {
5777
+ to = consumer.originalPositionFor({ column: endColumn, line: endLine });
6063
5778
  }
6064
- return this.consumerCache
6065
- }
6066
5779
 
6067
- decodeInline(text) {
6068
- let baseCharsetUri = /^data:application\/json;charset=utf-?8;base64,/;
6069
- let baseUri = /^data:application\/json;base64,/;
6070
- let charsetUri = /^data:application\/json;charset=utf-?8,/;
6071
- let uri = /^data:application\/json,/;
5780
+ let fromUrl;
6072
5781
 
6073
- let uriMatch = text.match(charsetUri) || text.match(uri);
6074
- if (uriMatch) {
6075
- return decodeURIComponent(text.substr(uriMatch[0].length))
5782
+ if (isAbsolute(from.source)) {
5783
+ fromUrl = pathToFileURL$1(from.source);
5784
+ } else {
5785
+ fromUrl = new URL(
5786
+ from.source,
5787
+ this.map.consumer().sourceRoot || pathToFileURL$1(this.map.mapFile)
5788
+ );
6076
5789
  }
6077
5790
 
6078
- let baseUriMatch = text.match(baseCharsetUri) || text.match(baseUri);
6079
- if (baseUriMatch) {
6080
- return fromBase64(text.substr(baseUriMatch[0].length))
5791
+ let result = {
5792
+ column: from.column,
5793
+ endColumn: to && to.column,
5794
+ endLine: to && to.line,
5795
+ line: from.line,
5796
+ url: fromUrl.toString()
5797
+ };
5798
+
5799
+ if (fromUrl.protocol === 'file:') {
5800
+ if (fileURLToPath) {
5801
+ result.file = fileURLToPath(fromUrl);
5802
+ } else {
5803
+ /* c8 ignore next 2 */
5804
+ throw new Error(`file: protocol is not available in this PostCSS build`)
5805
+ }
6081
5806
  }
6082
5807
 
6083
- let encoding = text.match(/data:application\/json;([^,]+),/)[1];
6084
- throw new Error('Unsupported source map encoding ' + encoding)
5808
+ let source = consumer.sourceContentFor(from.source);
5809
+ if (source) result.source = source;
5810
+
5811
+ return result
5812
+ }
5813
+
5814
+ toJSON() {
5815
+ let json = {};
5816
+ for (let name of ['hasBOM', 'css', 'file', 'id']) {
5817
+ if (this[name] != null) {
5818
+ json[name] = this[name];
5819
+ }
5820
+ }
5821
+ if (this.map) {
5822
+ json.map = { ...this.map };
5823
+ if (json.map.consumerCache) {
5824
+ json.map.consumerCache = undefined;
5825
+ }
5826
+ }
5827
+ return json
6085
5828
  }
6086
5829
 
6087
- getAnnotationURL(sourceMapString) {
6088
- return sourceMapString.replace(/^\/\*\s*# sourceMappingURL=/, '').trim()
5830
+ get from() {
5831
+ return this.file || this.id
6089
5832
  }
5833
+ }
6090
5834
 
6091
- isMap(map) {
6092
- if (typeof map !== 'object') return false
6093
- return (
6094
- typeof map.mappings === 'string' ||
6095
- typeof map._mappings === 'string' ||
6096
- Array.isArray(map.sections)
6097
- )
6098
- }
5835
+ var input = Input$4;
5836
+ Input$4.default = Input$4;
6099
5837
 
6100
- loadAnnotation(css) {
6101
- let comments = css.match(/\/\*\s*# sourceMappingURL=/g);
6102
- if (!comments) return
5838
+ if (terminalHighlight && terminalHighlight.registerInput) {
5839
+ terminalHighlight.registerInput(Input$4);
5840
+ }
6103
5841
 
6104
- // sourceMappingURLs from comments, strings, etc.
6105
- let start = css.lastIndexOf(comments.pop());
6106
- let end = css.indexOf('*/', start);
5842
+ let { SourceMapConsumer, SourceMapGenerator } = require$$2;
5843
+ let { dirname, relative, resolve, sep } = require$$2;
5844
+ let { pathToFileURL } = require$$2;
6107
5845
 
6108
- if (start > -1 && end > -1) {
6109
- // Locate the last sourceMappingURL to avoid pickin
6110
- this.annotation = this.getAnnotationURL(css.substring(start, end));
6111
- }
5846
+ let Input$3 = input;
5847
+
5848
+ let sourceMapAvailable = Boolean(SourceMapConsumer && SourceMapGenerator);
5849
+ let pathAvailable = Boolean(dirname && resolve && relative && sep);
5850
+
5851
+ class MapGenerator$2 {
5852
+ constructor(stringify, root, opts, cssString) {
5853
+ this.stringify = stringify;
5854
+ this.mapOpts = opts.map || {};
5855
+ this.root = root;
5856
+ this.opts = opts;
5857
+ this.css = cssString;
5858
+ this.originalCSS = cssString;
5859
+ this.usesFileUrls = !this.mapOpts.from && this.mapOpts.absolute;
5860
+
5861
+ this.memoizedFileURLs = new Map();
5862
+ this.memoizedPaths = new Map();
5863
+ this.memoizedURLs = new Map();
6112
5864
  }
6113
5865
 
6114
- loadFile(path) {
6115
- this.root = dirname$1(path);
6116
- if (existsSync(path)) {
6117
- this.mapFile = path;
6118
- return readFileSync(path, 'utf-8').toString().trim()
5866
+ addAnnotation() {
5867
+ let content;
5868
+
5869
+ if (this.isInline()) {
5870
+ content =
5871
+ 'data:application/json;base64,' + this.toBase64(this.map.toString());
5872
+ } else if (typeof this.mapOpts.annotation === 'string') {
5873
+ content = this.mapOpts.annotation;
5874
+ } else if (typeof this.mapOpts.annotation === 'function') {
5875
+ content = this.mapOpts.annotation(this.opts.to, this.root);
5876
+ } else {
5877
+ content = this.outputFile() + '.map';
6119
5878
  }
5879
+ let eol = '\n';
5880
+ if (this.css.includes('\r\n')) eol = '\r\n';
5881
+
5882
+ this.css += eol + '/*# sourceMappingURL=' + content + ' */';
6120
5883
  }
6121
5884
 
6122
- loadMap(file, prev) {
6123
- if (prev === false) return false
5885
+ applyPrevMaps() {
5886
+ for (let prev of this.previous()) {
5887
+ let from = this.toUrl(this.path(prev.file));
5888
+ let root = prev.root || dirname(prev.file);
5889
+ let map;
6124
5890
 
6125
- if (prev) {
6126
- if (typeof prev === 'string') {
6127
- return prev
6128
- } else if (typeof prev === 'function') {
6129
- let prevPath = prev(file);
6130
- if (prevPath) {
6131
- let map = this.loadFile(prevPath);
6132
- if (!map) {
6133
- throw new Error(
6134
- 'Unable to load previous source map: ' + prevPath.toString()
6135
- )
6136
- }
6137
- return map
5891
+ if (this.mapOpts.sourcesContent === false) {
5892
+ map = new SourceMapConsumer(prev.text);
5893
+ if (map.sourcesContent) {
5894
+ map.sourcesContent = null;
6138
5895
  }
6139
- } else if (prev instanceof SourceMapConsumer$2) {
6140
- return SourceMapGenerator$2.fromSourceMap(prev).toString()
6141
- } else if (prev instanceof SourceMapGenerator$2) {
6142
- return prev.toString()
6143
- } else if (this.isMap(prev)) {
6144
- return JSON.stringify(prev)
6145
5896
  } else {
6146
- throw new Error(
6147
- 'Unsupported previous source map format: ' + prev.toString()
6148
- )
5897
+ map = prev.consumer();
6149
5898
  }
6150
- } else if (this.inline) {
6151
- return this.decodeInline(this.annotation)
6152
- } else if (this.annotation) {
6153
- let map = this.annotation;
6154
- if (file) map = join(dirname$1(file), map);
6155
- return this.loadFile(map)
5899
+
5900
+ this.map.applySourceMap(map, from, this.toUrl(this.path(root)));
6156
5901
  }
6157
5902
  }
6158
5903
 
6159
- startWith(string, start) {
6160
- if (!string) return false
6161
- return string.substr(0, start.length) === start
5904
+ clearAnnotation() {
5905
+ if (this.mapOpts.annotation === false) return
5906
+
5907
+ if (this.root) {
5908
+ let node;
5909
+ for (let i = this.root.nodes.length - 1; i >= 0; i--) {
5910
+ node = this.root.nodes[i];
5911
+ if (node.type !== 'comment') continue
5912
+ if (node.text.indexOf('# sourceMappingURL=') === 0) {
5913
+ this.root.removeChild(i);
5914
+ }
5915
+ }
5916
+ } else if (this.css) {
5917
+ this.css = this.css.replace(/\n*?\/\*#[\S\s]*?\*\/$/gm, '');
5918
+ }
6162
5919
  }
6163
5920
 
6164
- withContent() {
6165
- return !!(
6166
- this.consumer().sourcesContent &&
6167
- this.consumer().sourcesContent.length > 0
6168
- )
5921
+ generate() {
5922
+ this.clearAnnotation();
5923
+ if (pathAvailable && sourceMapAvailable && this.isMap()) {
5924
+ return this.generateMap()
5925
+ } else {
5926
+ let result = '';
5927
+ this.stringify(this.root, i => {
5928
+ result += i;
5929
+ });
5930
+ return [result]
5931
+ }
6169
5932
  }
6170
- }
6171
5933
 
6172
- var previousMap = PreviousMap$2;
6173
- PreviousMap$2.default = PreviousMap$2;
5934
+ generateMap() {
5935
+ if (this.root) {
5936
+ this.generateString();
5937
+ } else if (this.previous().length === 1) {
5938
+ let prev = this.previous()[0].consumer();
5939
+ prev.file = this.outputFile();
5940
+ this.map = SourceMapGenerator.fromSourceMap(prev);
5941
+ } else {
5942
+ this.map = new SourceMapGenerator({ file: this.outputFile() });
5943
+ this.map.addMapping({
5944
+ generated: { column: 0, line: 1 },
5945
+ original: { column: 0, line: 1 },
5946
+ source: this.opts.from
5947
+ ? this.toUrl(this.path(this.opts.from))
5948
+ : '<no source>'
5949
+ });
5950
+ }
6174
5951
 
6175
- let { nanoid } = require$$0;
6176
- let { isAbsolute, resolve: resolve$1 } = require$$2;
6177
- let { SourceMapConsumer: SourceMapConsumer$1, SourceMapGenerator: SourceMapGenerator$1 } = require$$2;
6178
- let { fileURLToPath, pathToFileURL: pathToFileURL$1 } = require$$2;
5952
+ if (this.isSourcesContent()) this.setSourcesContent();
5953
+ if (this.root && this.previous().length > 0) this.applyPrevMaps();
5954
+ if (this.isAnnotation()) this.addAnnotation();
6179
5955
 
6180
- let CssSyntaxError$1 = cssSyntaxError;
6181
- let PreviousMap$1 = previousMap;
6182
- let terminalHighlight = require$$2;
5956
+ if (this.isInline()) {
5957
+ return [this.css]
5958
+ } else {
5959
+ return [this.css, this.map]
5960
+ }
5961
+ }
6183
5962
 
6184
- let fromOffsetCache = Symbol('fromOffsetCache');
5963
+ generateString() {
5964
+ this.css = '';
5965
+ this.map = new SourceMapGenerator({ file: this.outputFile() });
6185
5966
 
6186
- let sourceMapAvailable$1 = Boolean(SourceMapConsumer$1 && SourceMapGenerator$1);
6187
- let pathAvailable$1 = Boolean(resolve$1 && isAbsolute);
5967
+ let line = 1;
5968
+ let column = 1;
6188
5969
 
6189
- class Input$4 {
6190
- constructor(css, opts = {}) {
6191
- if (
6192
- css === null ||
6193
- typeof css === 'undefined' ||
6194
- (typeof css === 'object' && !css.toString)
6195
- ) {
6196
- throw new Error(`PostCSS received ${css} instead of CSS string`)
6197
- }
5970
+ let noSource = '<no source>';
5971
+ let mapping = {
5972
+ generated: { column: 0, line: 0 },
5973
+ original: { column: 0, line: 0 },
5974
+ source: ''
5975
+ };
6198
5976
 
6199
- this.css = css.toString();
5977
+ let lines, last;
5978
+ this.stringify(this.root, (str, node, type) => {
5979
+ this.css += str;
6200
5980
 
6201
- if (this.css[0] === '\uFEFF' || this.css[0] === '\uFFFE') {
6202
- this.hasBOM = true;
6203
- this.css = this.css.slice(1);
6204
- } else {
6205
- this.hasBOM = false;
6206
- }
5981
+ if (node && type !== 'end') {
5982
+ mapping.generated.line = line;
5983
+ mapping.generated.column = column - 1;
5984
+ if (node.source && node.source.start) {
5985
+ mapping.source = this.sourcePath(node);
5986
+ mapping.original.line = node.source.start.line;
5987
+ mapping.original.column = node.source.start.column - 1;
5988
+ this.map.addMapping(mapping);
5989
+ } else {
5990
+ mapping.source = noSource;
5991
+ mapping.original.line = 1;
5992
+ mapping.original.column = 0;
5993
+ this.map.addMapping(mapping);
5994
+ }
5995
+ }
6207
5996
 
6208
- if (opts.from) {
6209
- if (
6210
- !pathAvailable$1 ||
6211
- /^\w+:\/\//.test(opts.from) ||
6212
- isAbsolute(opts.from)
6213
- ) {
6214
- this.file = opts.from;
5997
+ lines = str.match(/\n/g);
5998
+ if (lines) {
5999
+ line += lines.length;
6000
+ last = str.lastIndexOf('\n');
6001
+ column = str.length - last;
6215
6002
  } else {
6216
- this.file = resolve$1(opts.from);
6003
+ column += str.length;
6004
+ }
6005
+
6006
+ if (node && type !== 'start') {
6007
+ let p = node.parent || { raws: {} };
6008
+ let childless =
6009
+ node.type === 'decl' || (node.type === 'atrule' && !node.nodes);
6010
+ if (!childless || node !== p.last || p.raws.semicolon) {
6011
+ if (node.source && node.source.end) {
6012
+ mapping.source = this.sourcePath(node);
6013
+ mapping.original.line = node.source.end.line;
6014
+ mapping.original.column = node.source.end.column - 1;
6015
+ mapping.generated.line = line;
6016
+ mapping.generated.column = column - 2;
6017
+ this.map.addMapping(mapping);
6018
+ } else {
6019
+ mapping.source = noSource;
6020
+ mapping.original.line = 1;
6021
+ mapping.original.column = 0;
6022
+ mapping.generated.line = line;
6023
+ mapping.generated.column = column - 1;
6024
+ this.map.addMapping(mapping);
6025
+ }
6026
+ }
6217
6027
  }
6218
- }
6028
+ });
6029
+ }
6219
6030
 
6220
- if (pathAvailable$1 && sourceMapAvailable$1) {
6221
- let map = new PreviousMap$1(this.css, opts);
6222
- if (map.text) {
6223
- this.map = map;
6224
- let file = map.consumer().file;
6225
- if (!this.file && file) this.file = this.mapResolve(file);
6226
- }
6031
+ isAnnotation() {
6032
+ if (this.isInline()) {
6033
+ return true
6227
6034
  }
6228
-
6229
- if (!this.file) {
6230
- this.id = '<input css ' + nanoid(6) + '>';
6035
+ if (typeof this.mapOpts.annotation !== 'undefined') {
6036
+ return this.mapOpts.annotation
6231
6037
  }
6232
- if (this.map) this.map.file = this.from;
6038
+ if (this.previous().length) {
6039
+ return this.previous().some(i => i.annotation)
6040
+ }
6041
+ return true
6233
6042
  }
6234
6043
 
6235
- error(message, line, column, opts = {}) {
6236
- let endColumn, endLine, result;
6237
-
6238
- if (line && typeof line === 'object') {
6239
- let start = line;
6240
- let end = column;
6241
- if (typeof start.offset === 'number') {
6242
- let pos = this.fromOffset(start.offset);
6243
- line = pos.line;
6244
- column = pos.col;
6245
- } else {
6246
- line = start.line;
6247
- column = start.column;
6248
- }
6249
- if (typeof end.offset === 'number') {
6250
- let pos = this.fromOffset(end.offset);
6251
- endLine = pos.line;
6252
- endColumn = pos.col;
6253
- } else {
6254
- endLine = end.line;
6255
- endColumn = end.column;
6256
- }
6257
- } else if (!column) {
6258
- let pos = this.fromOffset(line);
6259
- line = pos.line;
6260
- column = pos.col;
6044
+ isInline() {
6045
+ if (typeof this.mapOpts.inline !== 'undefined') {
6046
+ return this.mapOpts.inline
6261
6047
  }
6262
6048
 
6263
- let origin = this.origin(line, column, endLine, endColumn);
6264
- if (origin) {
6265
- result = new CssSyntaxError$1(
6266
- message,
6267
- origin.endLine === undefined
6268
- ? origin.line
6269
- : { column: origin.column, line: origin.line },
6270
- origin.endLine === undefined
6271
- ? origin.column
6272
- : { column: origin.endColumn, line: origin.endLine },
6273
- origin.source,
6274
- origin.file,
6275
- opts.plugin
6276
- );
6277
- } else {
6278
- result = new CssSyntaxError$1(
6279
- message,
6280
- endLine === undefined ? line : { column, line },
6281
- endLine === undefined ? column : { column: endColumn, line: endLine },
6282
- this.css,
6283
- this.file,
6284
- opts.plugin
6285
- );
6049
+ let annotation = this.mapOpts.annotation;
6050
+ if (typeof annotation !== 'undefined' && annotation !== true) {
6051
+ return false
6286
6052
  }
6287
6053
 
6288
- result.input = { column, endColumn, endLine, line, source: this.css };
6289
- if (this.file) {
6290
- if (pathToFileURL$1) {
6291
- result.input.url = pathToFileURL$1(this.file).toString();
6292
- }
6293
- result.input.file = this.file;
6054
+ if (this.previous().length) {
6055
+ return this.previous().some(i => i.inline)
6294
6056
  }
6295
-
6296
- return result
6057
+ return true
6297
6058
  }
6298
6059
 
6299
- fromOffset(offset) {
6300
- let lastLine, lineToIndex;
6301
- if (!this[fromOffsetCache]) {
6302
- let lines = this.css.split('\n');
6303
- lineToIndex = new Array(lines.length);
6304
- let prevIndex = 0;
6305
-
6306
- for (let i = 0, l = lines.length; i < l; i++) {
6307
- lineToIndex[i] = prevIndex;
6308
- prevIndex += lines[i].length + 1;
6309
- }
6310
-
6311
- this[fromOffsetCache] = lineToIndex;
6312
- } else {
6313
- lineToIndex = this[fromOffsetCache];
6060
+ isMap() {
6061
+ if (typeof this.opts.map !== 'undefined') {
6062
+ return !!this.opts.map
6314
6063
  }
6315
- lastLine = lineToIndex[lineToIndex.length - 1];
6064
+ return this.previous().length > 0
6065
+ }
6316
6066
 
6317
- let min = 0;
6318
- if (offset >= lastLine) {
6319
- min = lineToIndex.length - 1;
6320
- } else {
6321
- let max = lineToIndex.length - 2;
6322
- let mid;
6323
- while (min < max) {
6324
- mid = min + ((max - min) >> 1);
6325
- if (offset < lineToIndex[mid]) {
6326
- max = mid - 1;
6327
- } else if (offset >= lineToIndex[mid + 1]) {
6328
- min = mid + 1;
6329
- } else {
6330
- min = mid;
6331
- break
6332
- }
6333
- }
6067
+ isSourcesContent() {
6068
+ if (typeof this.mapOpts.sourcesContent !== 'undefined') {
6069
+ return this.mapOpts.sourcesContent
6334
6070
  }
6335
- return {
6336
- col: offset - lineToIndex[min] + 1,
6337
- line: min + 1
6071
+ if (this.previous().length) {
6072
+ return this.previous().some(i => i.withContent())
6338
6073
  }
6074
+ return true
6339
6075
  }
6340
6076
 
6341
- mapResolve(file) {
6342
- if (/^\w+:\/\//.test(file)) {
6343
- return file
6077
+ outputFile() {
6078
+ if (this.opts.to) {
6079
+ return this.path(this.opts.to)
6080
+ } else if (this.opts.from) {
6081
+ return this.path(this.opts.from)
6082
+ } else {
6083
+ return 'to.css'
6344
6084
  }
6345
- return resolve$1(this.map.consumer().sourceRoot || this.map.root || '.', file)
6346
6085
  }
6347
6086
 
6348
- origin(line, column, endLine, endColumn) {
6349
- if (!this.map) return false
6350
- let consumer = this.map.consumer();
6087
+ path(file) {
6088
+ if (this.mapOpts.absolute) return file
6089
+ if (file.charCodeAt(0) === 60 /* `<` */) return file
6090
+ if (/^\w+:\/\//.test(file)) return file
6091
+ let cached = this.memoizedPaths.get(file);
6092
+ if (cached) return cached
6351
6093
 
6352
- let from = consumer.originalPositionFor({ column, line });
6353
- if (!from.source) return false
6094
+ let from = this.opts.to ? dirname(this.opts.to) : '.';
6354
6095
 
6355
- let to;
6356
- if (typeof endLine === 'number') {
6357
- to = consumer.originalPositionFor({ column: endColumn, line: endLine });
6096
+ if (typeof this.mapOpts.annotation === 'string') {
6097
+ from = dirname(resolve(from, this.mapOpts.annotation));
6358
6098
  }
6359
6099
 
6360
- let fromUrl;
6361
-
6362
- if (isAbsolute(from.source)) {
6363
- fromUrl = pathToFileURL$1(from.source);
6364
- } else {
6365
- fromUrl = new URL(
6366
- from.source,
6367
- this.map.consumer().sourceRoot || pathToFileURL$1(this.map.mapFile)
6368
- );
6369
- }
6100
+ let path = relative(from, file);
6101
+ this.memoizedPaths.set(file, path);
6370
6102
 
6371
- let result = {
6372
- column: from.column,
6373
- endColumn: to && to.column,
6374
- endLine: to && to.line,
6375
- line: from.line,
6376
- url: fromUrl.toString()
6377
- };
6103
+ return path
6104
+ }
6378
6105
 
6379
- if (fromUrl.protocol === 'file:') {
6380
- if (fileURLToPath) {
6381
- result.file = fileURLToPath(fromUrl);
6106
+ previous() {
6107
+ if (!this.previousMaps) {
6108
+ this.previousMaps = [];
6109
+ if (this.root) {
6110
+ this.root.walk(node => {
6111
+ if (node.source && node.source.input.map) {
6112
+ let map = node.source.input.map;
6113
+ if (!this.previousMaps.includes(map)) {
6114
+ this.previousMaps.push(map);
6115
+ }
6116
+ }
6117
+ });
6382
6118
  } else {
6383
- /* c8 ignore next 2 */
6384
- throw new Error(`file: protocol is not available in this PostCSS build`)
6119
+ let input = new Input$3(this.originalCSS, this.opts);
6120
+ if (input.map) this.previousMaps.push(input.map);
6385
6121
  }
6386
6122
  }
6387
6123
 
6388
- let source = consumer.sourceContentFor(from.source);
6389
- if (source) result.source = source;
6124
+ return this.previousMaps
6125
+ }
6390
6126
 
6391
- return result
6127
+ setSourcesContent() {
6128
+ let already = {};
6129
+ if (this.root) {
6130
+ this.root.walk(node => {
6131
+ if (node.source) {
6132
+ let from = node.source.input.from;
6133
+ if (from && !already[from]) {
6134
+ already[from] = true;
6135
+ let fromUrl = this.usesFileUrls
6136
+ ? this.toFileUrl(from)
6137
+ : this.toUrl(this.path(from));
6138
+ this.map.setSourceContent(fromUrl, node.source.input.css);
6139
+ }
6140
+ }
6141
+ });
6142
+ } else if (this.css) {
6143
+ let from = this.opts.from
6144
+ ? this.toUrl(this.path(this.opts.from))
6145
+ : '<no source>';
6146
+ this.map.setSourceContent(from, this.css);
6147
+ }
6392
6148
  }
6393
6149
 
6394
- toJSON() {
6395
- let json = {};
6396
- for (let name of ['hasBOM', 'css', 'file', 'id']) {
6397
- if (this[name] != null) {
6398
- json[name] = this[name];
6399
- }
6150
+ sourcePath(node) {
6151
+ if (this.mapOpts.from) {
6152
+ return this.toUrl(this.mapOpts.from)
6153
+ } else if (this.usesFileUrls) {
6154
+ return this.toFileUrl(node.source.input.from)
6155
+ } else {
6156
+ return this.toUrl(this.path(node.source.input.from))
6400
6157
  }
6401
- if (this.map) {
6402
- json.map = { ...this.map };
6403
- if (json.map.consumerCache) {
6404
- json.map.consumerCache = undefined;
6405
- }
6158
+ }
6159
+
6160
+ toBase64(str) {
6161
+ if (Buffer) {
6162
+ return Buffer.from(str).toString('base64')
6163
+ } else {
6164
+ return window.btoa(unescape(encodeURIComponent(str)))
6406
6165
  }
6407
- return json
6408
- }
6409
-
6410
- get from() {
6411
- return this.file || this.id
6412
6166
  }
6413
- }
6414
-
6415
- var input = Input$4;
6416
- Input$4.default = Input$4;
6417
-
6418
- if (terminalHighlight && terminalHighlight.registerInput) {
6419
- terminalHighlight.registerInput(Input$4);
6420
- }
6421
6167
 
6422
- let Container$4 = container;
6168
+ toFileUrl(path) {
6169
+ let cached = this.memoizedFileURLs.get(path);
6170
+ if (cached) return cached
6423
6171
 
6424
- let LazyResult$3, Processor$2;
6172
+ if (pathToFileURL) {
6173
+ let fileURL = pathToFileURL(path).toString();
6174
+ this.memoizedFileURLs.set(path, fileURL);
6425
6175
 
6426
- class Root$5 extends Container$4 {
6427
- constructor(defaults) {
6428
- super(defaults);
6429
- this.type = 'root';
6430
- if (!this.nodes) this.nodes = [];
6176
+ return fileURL
6177
+ } else {
6178
+ throw new Error(
6179
+ '`map.absolute` option is not available in this PostCSS build'
6180
+ )
6181
+ }
6431
6182
  }
6432
6183
 
6433
- normalize(child, sample, type) {
6434
- let nodes = super.normalize(child);
6184
+ toUrl(path) {
6185
+ let cached = this.memoizedURLs.get(path);
6186
+ if (cached) return cached
6435
6187
 
6436
- if (sample) {
6437
- if (type === 'prepend') {
6438
- if (this.nodes.length > 1) {
6439
- sample.raws.before = this.nodes[1].raws.before;
6440
- } else {
6441
- delete sample.raws.before;
6442
- }
6443
- } else if (this.first !== sample) {
6444
- for (let node of nodes) {
6445
- node.raws.before = sample.raws.before;
6446
- }
6447
- }
6188
+ if (sep === '\\') {
6189
+ path = path.replace(/\\/g, '/');
6448
6190
  }
6449
6191
 
6450
- return nodes
6451
- }
6192
+ let url = encodeURI(path).replace(/[#?]/g, encodeURIComponent);
6193
+ this.memoizedURLs.set(path, url);
6452
6194
 
6453
- removeChild(child, ignore) {
6454
- let index = this.index(child);
6195
+ return url
6196
+ }
6197
+ }
6455
6198
 
6456
- if (!ignore && index === 0 && this.nodes.length > 1) {
6457
- this.nodes[1].raws.before = this.nodes[index].raws.before;
6458
- }
6199
+ var mapGenerator = MapGenerator$2;
6459
6200
 
6460
- return super.removeChild(child)
6461
- }
6201
+ let Node$2 = node_1;
6462
6202
 
6463
- toResult(opts = {}) {
6464
- let lazy = new LazyResult$3(new Processor$2(), this, opts);
6465
- return lazy.stringify()
6203
+ class Comment$4 extends Node$2 {
6204
+ constructor(defaults) {
6205
+ super(defaults);
6206
+ this.type = 'comment';
6466
6207
  }
6467
6208
  }
6468
6209
 
6469
- Root$5.registerLazyResult = dependant => {
6470
- LazyResult$3 = dependant;
6471
- };
6472
-
6473
- Root$5.registerProcessor = dependant => {
6474
- Processor$2 = dependant;
6475
- };
6210
+ var comment = Comment$4;
6211
+ Comment$4.default = Comment$4;
6476
6212
 
6477
- var root = Root$5;
6478
- Root$5.default = Root$5;
6213
+ let { isClean: isClean$1, my: my$1 } = symbols;
6214
+ let Declaration$3 = declaration;
6215
+ let Comment$3 = comment;
6216
+ let Node$1 = node_1;
6479
6217
 
6480
- Container$4.registerRoot(Root$5);
6218
+ let parse$4, Rule$4, AtRule$4, Root$6;
6481
6219
 
6482
- let list$2 = {
6483
- comma(string) {
6484
- return list$2.split(string, [','], true)
6485
- },
6220
+ function cleanSource(nodes) {
6221
+ return nodes.map(i => {
6222
+ if (i.nodes) i.nodes = cleanSource(i.nodes);
6223
+ delete i.source;
6224
+ return i
6225
+ })
6226
+ }
6486
6227
 
6487
- space(string) {
6488
- let spaces = [' ', '\n', '\t'];
6489
- return list$2.split(string, spaces)
6490
- },
6228
+ function markDirtyUp(node) {
6229
+ node[isClean$1] = false;
6230
+ if (node.proxyOf.nodes) {
6231
+ for (let i of node.proxyOf.nodes) {
6232
+ markDirtyUp(i);
6233
+ }
6234
+ }
6235
+ }
6491
6236
 
6492
- split(string, separators, last) {
6493
- let array = [];
6494
- let current = '';
6495
- let split = false;
6237
+ class Container$7 extends Node$1 {
6238
+ append(...children) {
6239
+ for (let child of children) {
6240
+ let nodes = this.normalize(child, this.last);
6241
+ for (let node of nodes) this.proxyOf.nodes.push(node);
6242
+ }
6496
6243
 
6497
- let func = 0;
6498
- let inQuote = false;
6499
- let prevQuote = '';
6500
- let escape = false;
6244
+ this.markDirty();
6501
6245
 
6502
- for (let letter of string) {
6503
- if (escape) {
6504
- escape = false;
6505
- } else if (letter === '\\') {
6506
- escape = true;
6507
- } else if (inQuote) {
6508
- if (letter === prevQuote) {
6509
- inQuote = false;
6510
- }
6511
- } else if (letter === '"' || letter === "'") {
6512
- inQuote = true;
6513
- prevQuote = letter;
6514
- } else if (letter === '(') {
6515
- func += 1;
6516
- } else if (letter === ')') {
6517
- if (func > 0) func -= 1;
6518
- } else if (func === 0) {
6519
- if (separators.includes(letter)) split = true;
6520
- }
6246
+ return this
6247
+ }
6521
6248
 
6522
- if (split) {
6523
- if (current !== '') array.push(current.trim());
6524
- current = '';
6525
- split = false;
6526
- } else {
6527
- current += letter;
6528
- }
6249
+ cleanRaws(keepBetween) {
6250
+ super.cleanRaws(keepBetween);
6251
+ if (this.nodes) {
6252
+ for (let node of this.nodes) node.cleanRaws(keepBetween);
6529
6253
  }
6530
-
6531
- if (last || current !== '') array.push(current.trim());
6532
- return array
6533
6254
  }
6534
- };
6535
6255
 
6536
- var list_1 = list$2;
6537
- list$2.default = list$2;
6256
+ each(callback) {
6257
+ if (!this.proxyOf.nodes) return undefined
6258
+ let iterator = this.getIterator();
6538
6259
 
6539
- let Container$3 = container;
6540
- let list$1 = list_1;
6260
+ let index, result;
6261
+ while (this.indexes[iterator] < this.proxyOf.nodes.length) {
6262
+ index = this.indexes[iterator];
6263
+ result = callback(this.proxyOf.nodes[index], index);
6264
+ if (result === false) break
6541
6265
 
6542
- class Rule$3 extends Container$3 {
6543
- constructor(defaults) {
6544
- super(defaults);
6545
- this.type = 'rule';
6546
- if (!this.nodes) this.nodes = [];
6547
- }
6266
+ this.indexes[iterator] += 1;
6267
+ }
6548
6268
 
6549
- get selectors() {
6550
- return list$1.comma(this.selector)
6269
+ delete this.indexes[iterator];
6270
+ return result
6551
6271
  }
6552
6272
 
6553
- set selectors(values) {
6554
- let match = this.selector ? this.selector.match(/,\s*/) : null;
6555
- let sep = match ? match[0] : ',' + this.raw('between', 'beforeOpen');
6556
- this.selector = values.join(sep);
6273
+ every(condition) {
6274
+ return this.nodes.every(condition)
6557
6275
  }
6558
- }
6559
6276
 
6560
- var rule = Rule$3;
6561
- Rule$3.default = Rule$3;
6562
-
6563
- Container$3.registerRule(Rule$3);
6277
+ getIterator() {
6278
+ if (!this.lastEach) this.lastEach = 0;
6279
+ if (!this.indexes) this.indexes = {};
6564
6280
 
6565
- let AtRule$2 = atRule;
6566
- let Comment$2 = comment;
6567
- let Declaration$2 = declaration;
6568
- let Input$3 = input;
6569
- let PreviousMap = previousMap;
6570
- let Root$4 = root;
6571
- let Rule$2 = rule;
6281
+ this.lastEach += 1;
6282
+ let iterator = this.lastEach;
6283
+ this.indexes[iterator] = 0;
6572
6284
 
6573
- function fromJSON$1(json, inputs) {
6574
- if (Array.isArray(json)) return json.map(n => fromJSON$1(n))
6285
+ return iterator
6286
+ }
6575
6287
 
6576
- let { inputs: ownInputs, ...defaults } = json;
6577
- if (ownInputs) {
6578
- inputs = [];
6579
- for (let input of ownInputs) {
6580
- let inputHydrated = { ...input, __proto__: Input$3.prototype };
6581
- if (inputHydrated.map) {
6582
- inputHydrated.map = {
6583
- ...inputHydrated.map,
6584
- __proto__: PreviousMap.prototype
6585
- };
6288
+ getProxyProcessor() {
6289
+ return {
6290
+ get(node, prop) {
6291
+ if (prop === 'proxyOf') {
6292
+ return node
6293
+ } else if (!node[prop]) {
6294
+ return node[prop]
6295
+ } else if (
6296
+ prop === 'each' ||
6297
+ (typeof prop === 'string' && prop.startsWith('walk'))
6298
+ ) {
6299
+ return (...args) => {
6300
+ return node[prop](
6301
+ ...args.map(i => {
6302
+ if (typeof i === 'function') {
6303
+ return (child, index) => i(child.toProxy(), index)
6304
+ } else {
6305
+ return i
6306
+ }
6307
+ })
6308
+ )
6309
+ }
6310
+ } else if (prop === 'every' || prop === 'some') {
6311
+ return cb => {
6312
+ return node[prop]((child, ...other) =>
6313
+ cb(child.toProxy(), ...other)
6314
+ )
6315
+ }
6316
+ } else if (prop === 'root') {
6317
+ return () => node.root().toProxy()
6318
+ } else if (prop === 'nodes') {
6319
+ return node.nodes.map(i => i.toProxy())
6320
+ } else if (prop === 'first' || prop === 'last') {
6321
+ return node[prop].toProxy()
6322
+ } else {
6323
+ return node[prop]
6324
+ }
6325
+ },
6326
+
6327
+ set(node, prop, value) {
6328
+ if (node[prop] === value) return true
6329
+ node[prop] = value;
6330
+ if (prop === 'name' || prop === 'params' || prop === 'selector') {
6331
+ node.markDirty();
6332
+ }
6333
+ return true
6586
6334
  }
6587
- inputs.push(inputHydrated);
6588
- }
6589
- }
6590
- if (defaults.nodes) {
6591
- defaults.nodes = json.nodes.map(n => fromJSON$1(n, inputs));
6592
- }
6593
- if (defaults.source) {
6594
- let { inputId, ...source } = defaults.source;
6595
- defaults.source = source;
6596
- if (inputId != null) {
6597
- defaults.source.input = inputs[inputId];
6598
6335
  }
6599
6336
  }
6600
- if (defaults.type === 'root') {
6601
- return new Root$4(defaults)
6602
- } else if (defaults.type === 'decl') {
6603
- return new Declaration$2(defaults)
6604
- } else if (defaults.type === 'rule') {
6605
- return new Rule$2(defaults)
6606
- } else if (defaults.type === 'comment') {
6607
- return new Comment$2(defaults)
6608
- } else if (defaults.type === 'atrule') {
6609
- return new AtRule$2(defaults)
6610
- } else {
6611
- throw new Error('Unknown node type: ' + json.type)
6612
- }
6613
- }
6614
6337
 
6615
- var fromJSON_1 = fromJSON$1;
6616
- fromJSON$1.default = fromJSON$1;
6617
-
6618
- let { dirname, relative, resolve, sep } = require$$2;
6619
- let { SourceMapConsumer, SourceMapGenerator } = require$$2;
6620
- let { pathToFileURL } = require$$2;
6338
+ index(child) {
6339
+ if (typeof child === 'number') return child
6340
+ if (child.proxyOf) child = child.proxyOf;
6341
+ return this.proxyOf.nodes.indexOf(child)
6342
+ }
6621
6343
 
6622
- let Input$2 = input;
6344
+ insertAfter(exist, add) {
6345
+ let existIndex = this.index(exist);
6346
+ let nodes = this.normalize(add, this.proxyOf.nodes[existIndex]).reverse();
6347
+ existIndex = this.index(exist);
6348
+ for (let node of nodes) this.proxyOf.nodes.splice(existIndex + 1, 0, node);
6623
6349
 
6624
- let sourceMapAvailable = Boolean(SourceMapConsumer && SourceMapGenerator);
6625
- let pathAvailable = Boolean(dirname && resolve && relative && sep);
6350
+ let index;
6351
+ for (let id in this.indexes) {
6352
+ index = this.indexes[id];
6353
+ if (existIndex < index) {
6354
+ this.indexes[id] = index + nodes.length;
6355
+ }
6356
+ }
6626
6357
 
6627
- class MapGenerator$2 {
6628
- constructor(stringify, root, opts, cssString) {
6629
- this.stringify = stringify;
6630
- this.mapOpts = opts.map || {};
6631
- this.root = root;
6632
- this.opts = opts;
6633
- this.css = cssString;
6634
- this.originalCSS = cssString;
6635
- this.usesFileUrls = !this.mapOpts.from && this.mapOpts.absolute;
6358
+ this.markDirty();
6636
6359
 
6637
- this.memoizedFileURLs = new Map();
6638
- this.memoizedPaths = new Map();
6639
- this.memoizedURLs = new Map();
6360
+ return this
6640
6361
  }
6641
6362
 
6642
- addAnnotation() {
6643
- let content;
6363
+ insertBefore(exist, add) {
6364
+ let existIndex = this.index(exist);
6365
+ let type = existIndex === 0 ? 'prepend' : false;
6366
+ let nodes = this.normalize(add, this.proxyOf.nodes[existIndex], type).reverse();
6367
+ existIndex = this.index(exist);
6368
+ for (let node of nodes) this.proxyOf.nodes.splice(existIndex, 0, node);
6644
6369
 
6645
- if (this.isInline()) {
6646
- content =
6647
- 'data:application/json;base64,' + this.toBase64(this.map.toString());
6648
- } else if (typeof this.mapOpts.annotation === 'string') {
6649
- content = this.mapOpts.annotation;
6650
- } else if (typeof this.mapOpts.annotation === 'function') {
6651
- content = this.mapOpts.annotation(this.opts.to, this.root);
6652
- } else {
6653
- content = this.outputFile() + '.map';
6370
+ let index;
6371
+ for (let id in this.indexes) {
6372
+ index = this.indexes[id];
6373
+ if (existIndex <= index) {
6374
+ this.indexes[id] = index + nodes.length;
6375
+ }
6654
6376
  }
6655
- let eol = '\n';
6656
- if (this.css.includes('\r\n')) eol = '\r\n';
6657
6377
 
6658
- this.css += eol + '/*# sourceMappingURL=' + content + ' */';
6378
+ this.markDirty();
6379
+
6380
+ return this
6659
6381
  }
6660
6382
 
6661
- applyPrevMaps() {
6662
- for (let prev of this.previous()) {
6663
- let from = this.toUrl(this.path(prev.file));
6664
- let root = prev.root || dirname(prev.file);
6665
- let map;
6383
+ normalize(nodes, sample) {
6384
+ if (typeof nodes === 'string') {
6385
+ nodes = cleanSource(parse$4(nodes).nodes);
6386
+ } else if (typeof nodes === 'undefined') {
6387
+ nodes = [];
6388
+ } else if (Array.isArray(nodes)) {
6389
+ nodes = nodes.slice(0);
6390
+ for (let i of nodes) {
6391
+ if (i.parent) i.parent.removeChild(i, 'ignore');
6392
+ }
6393
+ } else if (nodes.type === 'root' && this.type !== 'document') {
6394
+ nodes = nodes.nodes.slice(0);
6395
+ for (let i of nodes) {
6396
+ if (i.parent) i.parent.removeChild(i, 'ignore');
6397
+ }
6398
+ } else if (nodes.type) {
6399
+ nodes = [nodes];
6400
+ } else if (nodes.prop) {
6401
+ if (typeof nodes.value === 'undefined') {
6402
+ throw new Error('Value field is missed in node creation')
6403
+ } else if (typeof nodes.value !== 'string') {
6404
+ nodes.value = String(nodes.value);
6405
+ }
6406
+ nodes = [new Declaration$3(nodes)];
6407
+ } else if (nodes.selector) {
6408
+ nodes = [new Rule$4(nodes)];
6409
+ } else if (nodes.name) {
6410
+ nodes = [new AtRule$4(nodes)];
6411
+ } else if (nodes.text) {
6412
+ nodes = [new Comment$3(nodes)];
6413
+ } else {
6414
+ throw new Error('Unknown node type in node creation')
6415
+ }
6666
6416
 
6667
- if (this.mapOpts.sourcesContent === false) {
6668
- map = new SourceMapConsumer(prev.text);
6669
- if (map.sourcesContent) {
6670
- map.sourcesContent = null;
6417
+ let processed = nodes.map(i => {
6418
+ /* c8 ignore next */
6419
+ if (!i[my$1]) Container$7.rebuild(i);
6420
+ i = i.proxyOf;
6421
+ if (i.parent) i.parent.removeChild(i);
6422
+ if (i[isClean$1]) markDirtyUp(i);
6423
+ if (typeof i.raws.before === 'undefined') {
6424
+ if (sample && typeof sample.raws.before !== 'undefined') {
6425
+ i.raws.before = sample.raws.before.replace(/\S/g, '');
6671
6426
  }
6672
- } else {
6673
- map = prev.consumer();
6674
6427
  }
6428
+ i.parent = this.proxyOf;
6429
+ return i
6430
+ });
6675
6431
 
6676
- this.map.applySourceMap(map, from, this.toUrl(this.path(root)));
6677
- }
6432
+ return processed
6678
6433
  }
6679
6434
 
6680
- clearAnnotation() {
6681
- if (this.mapOpts.annotation === false) return
6682
-
6683
- if (this.root) {
6684
- let node;
6685
- for (let i = this.root.nodes.length - 1; i >= 0; i--) {
6686
- node = this.root.nodes[i];
6687
- if (node.type !== 'comment') continue
6688
- if (node.text.startsWith('# sourceMappingURL=')) {
6689
- this.root.removeChild(i);
6690
- }
6435
+ prepend(...children) {
6436
+ children = children.reverse();
6437
+ for (let child of children) {
6438
+ let nodes = this.normalize(child, this.first, 'prepend').reverse();
6439
+ for (let node of nodes) this.proxyOf.nodes.unshift(node);
6440
+ for (let id in this.indexes) {
6441
+ this.indexes[id] = this.indexes[id] + nodes.length;
6691
6442
  }
6692
- } else if (this.css) {
6693
- this.css = this.css.replace(/\n*\/\*#[\S\s]*?\*\/$/gm, '');
6694
6443
  }
6444
+
6445
+ this.markDirty();
6446
+
6447
+ return this
6695
6448
  }
6696
6449
 
6697
- generate() {
6698
- this.clearAnnotation();
6699
- if (pathAvailable && sourceMapAvailable && this.isMap()) {
6700
- return this.generateMap()
6701
- } else {
6702
- let result = '';
6703
- this.stringify(this.root, i => {
6704
- result += i;
6705
- });
6706
- return [result]
6707
- }
6450
+ push(child) {
6451
+ child.parent = this;
6452
+ this.proxyOf.nodes.push(child);
6453
+ return this
6708
6454
  }
6709
6455
 
6710
- generateMap() {
6711
- if (this.root) {
6712
- this.generateString();
6713
- } else if (this.previous().length === 1) {
6714
- let prev = this.previous()[0].consumer();
6715
- prev.file = this.outputFile();
6716
- this.map = SourceMapGenerator.fromSourceMap(prev, {
6717
- ignoreInvalidMapping: true
6718
- });
6719
- } else {
6720
- this.map = new SourceMapGenerator({
6721
- file: this.outputFile(),
6722
- ignoreInvalidMapping: true
6723
- });
6724
- this.map.addMapping({
6725
- generated: { column: 0, line: 1 },
6726
- original: { column: 0, line: 1 },
6727
- source: this.opts.from
6728
- ? this.toUrl(this.path(this.opts.from))
6729
- : '<no source>'
6730
- });
6731
- }
6456
+ removeAll() {
6457
+ for (let node of this.proxyOf.nodes) node.parent = undefined;
6458
+ this.proxyOf.nodes = [];
6732
6459
 
6733
- if (this.isSourcesContent()) this.setSourcesContent();
6734
- if (this.root && this.previous().length > 0) this.applyPrevMaps();
6735
- if (this.isAnnotation()) this.addAnnotation();
6460
+ this.markDirty();
6736
6461
 
6737
- if (this.isInline()) {
6738
- return [this.css]
6739
- } else {
6740
- return [this.css, this.map]
6462
+ return this
6463
+ }
6464
+
6465
+ removeChild(child) {
6466
+ child = this.index(child);
6467
+ this.proxyOf.nodes[child].parent = undefined;
6468
+ this.proxyOf.nodes.splice(child, 1);
6469
+
6470
+ let index;
6471
+ for (let id in this.indexes) {
6472
+ index = this.indexes[id];
6473
+ if (index >= child) {
6474
+ this.indexes[id] = index - 1;
6475
+ }
6741
6476
  }
6477
+
6478
+ this.markDirty();
6479
+
6480
+ return this
6742
6481
  }
6743
6482
 
6744
- generateString() {
6745
- this.css = '';
6746
- this.map = new SourceMapGenerator({
6747
- file: this.outputFile(),
6748
- ignoreInvalidMapping: true
6749
- });
6483
+ replaceValues(pattern, opts, callback) {
6484
+ if (!callback) {
6485
+ callback = opts;
6486
+ opts = {};
6487
+ }
6750
6488
 
6751
- let line = 1;
6752
- let column = 1;
6489
+ this.walkDecls(decl => {
6490
+ if (opts.props && !opts.props.includes(decl.prop)) return
6491
+ if (opts.fast && !decl.value.includes(opts.fast)) return
6492
+
6493
+ decl.value = decl.value.replace(pattern, callback);
6494
+ });
6753
6495
 
6754
- let noSource = '<no source>';
6755
- let mapping = {
6756
- generated: { column: 0, line: 0 },
6757
- original: { column: 0, line: 0 },
6758
- source: ''
6759
- };
6496
+ this.markDirty();
6760
6497
 
6761
- let last, lines;
6762
- this.stringify(this.root, (str, node, type) => {
6763
- this.css += str;
6498
+ return this
6499
+ }
6764
6500
 
6765
- if (node && type !== 'end') {
6766
- mapping.generated.line = line;
6767
- mapping.generated.column = column - 1;
6768
- if (node.source && node.source.start) {
6769
- mapping.source = this.sourcePath(node);
6770
- mapping.original.line = node.source.start.line;
6771
- mapping.original.column = node.source.start.column - 1;
6772
- this.map.addMapping(mapping);
6773
- } else {
6774
- mapping.source = noSource;
6775
- mapping.original.line = 1;
6776
- mapping.original.column = 0;
6777
- this.map.addMapping(mapping);
6778
- }
6779
- }
6501
+ some(condition) {
6502
+ return this.nodes.some(condition)
6503
+ }
6780
6504
 
6781
- lines = str.match(/\n/g);
6782
- if (lines) {
6783
- line += lines.length;
6784
- last = str.lastIndexOf('\n');
6785
- column = str.length - last;
6786
- } else {
6787
- column += str.length;
6505
+ walk(callback) {
6506
+ return this.each((child, i) => {
6507
+ let result;
6508
+ try {
6509
+ result = callback(child, i);
6510
+ } catch (e) {
6511
+ throw child.addToError(e)
6788
6512
  }
6789
-
6790
- if (node && type !== 'start') {
6791
- let p = node.parent || { raws: {} };
6792
- let childless =
6793
- node.type === 'decl' || (node.type === 'atrule' && !node.nodes);
6794
- if (!childless || node !== p.last || p.raws.semicolon) {
6795
- if (node.source && node.source.end) {
6796
- mapping.source = this.sourcePath(node);
6797
- mapping.original.line = node.source.end.line;
6798
- mapping.original.column = node.source.end.column - 1;
6799
- mapping.generated.line = line;
6800
- mapping.generated.column = column - 2;
6801
- this.map.addMapping(mapping);
6802
- } else {
6803
- mapping.source = noSource;
6804
- mapping.original.line = 1;
6805
- mapping.original.column = 0;
6806
- mapping.generated.line = line;
6807
- mapping.generated.column = column - 1;
6808
- this.map.addMapping(mapping);
6809
- }
6810
- }
6513
+ if (result !== false && child.walk) {
6514
+ result = child.walk(callback);
6811
6515
  }
6812
- });
6516
+
6517
+ return result
6518
+ })
6813
6519
  }
6814
6520
 
6815
- isAnnotation() {
6816
- if (this.isInline()) {
6817
- return true
6818
- }
6819
- if (typeof this.mapOpts.annotation !== 'undefined') {
6820
- return this.mapOpts.annotation
6521
+ walkAtRules(name, callback) {
6522
+ if (!callback) {
6523
+ callback = name;
6524
+ return this.walk((child, i) => {
6525
+ if (child.type === 'atrule') {
6526
+ return callback(child, i)
6527
+ }
6528
+ })
6821
6529
  }
6822
- if (this.previous().length) {
6823
- return this.previous().some(i => i.annotation)
6530
+ if (name instanceof RegExp) {
6531
+ return this.walk((child, i) => {
6532
+ if (child.type === 'atrule' && name.test(child.name)) {
6533
+ return callback(child, i)
6534
+ }
6535
+ })
6824
6536
  }
6825
- return true
6537
+ return this.walk((child, i) => {
6538
+ if (child.type === 'atrule' && child.name === name) {
6539
+ return callback(child, i)
6540
+ }
6541
+ })
6826
6542
  }
6827
6543
 
6828
- isInline() {
6829
- if (typeof this.mapOpts.inline !== 'undefined') {
6830
- return this.mapOpts.inline
6831
- }
6544
+ walkComments(callback) {
6545
+ return this.walk((child, i) => {
6546
+ if (child.type === 'comment') {
6547
+ return callback(child, i)
6548
+ }
6549
+ })
6550
+ }
6832
6551
 
6833
- let annotation = this.mapOpts.annotation;
6834
- if (typeof annotation !== 'undefined' && annotation !== true) {
6835
- return false
6552
+ walkDecls(prop, callback) {
6553
+ if (!callback) {
6554
+ callback = prop;
6555
+ return this.walk((child, i) => {
6556
+ if (child.type === 'decl') {
6557
+ return callback(child, i)
6558
+ }
6559
+ })
6836
6560
  }
6837
-
6838
- if (this.previous().length) {
6839
- return this.previous().some(i => i.inline)
6561
+ if (prop instanceof RegExp) {
6562
+ return this.walk((child, i) => {
6563
+ if (child.type === 'decl' && prop.test(child.prop)) {
6564
+ return callback(child, i)
6565
+ }
6566
+ })
6840
6567
  }
6841
- return true
6568
+ return this.walk((child, i) => {
6569
+ if (child.type === 'decl' && child.prop === prop) {
6570
+ return callback(child, i)
6571
+ }
6572
+ })
6842
6573
  }
6843
6574
 
6844
- isMap() {
6845
- if (typeof this.opts.map !== 'undefined') {
6846
- return !!this.opts.map
6847
- }
6848
- return this.previous().length > 0
6849
- }
6575
+ walkRules(selector, callback) {
6576
+ if (!callback) {
6577
+ callback = selector;
6850
6578
 
6851
- isSourcesContent() {
6852
- if (typeof this.mapOpts.sourcesContent !== 'undefined') {
6853
- return this.mapOpts.sourcesContent
6579
+ return this.walk((child, i) => {
6580
+ if (child.type === 'rule') {
6581
+ return callback(child, i)
6582
+ }
6583
+ })
6854
6584
  }
6855
- if (this.previous().length) {
6856
- return this.previous().some(i => i.withContent())
6585
+ if (selector instanceof RegExp) {
6586
+ return this.walk((child, i) => {
6587
+ if (child.type === 'rule' && selector.test(child.selector)) {
6588
+ return callback(child, i)
6589
+ }
6590
+ })
6857
6591
  }
6858
- return true
6592
+ return this.walk((child, i) => {
6593
+ if (child.type === 'rule' && child.selector === selector) {
6594
+ return callback(child, i)
6595
+ }
6596
+ })
6859
6597
  }
6860
6598
 
6861
- outputFile() {
6862
- if (this.opts.to) {
6863
- return this.path(this.opts.to)
6864
- } else if (this.opts.from) {
6865
- return this.path(this.opts.from)
6866
- } else {
6867
- return 'to.css'
6868
- }
6599
+ get first() {
6600
+ if (!this.proxyOf.nodes) return undefined
6601
+ return this.proxyOf.nodes[0]
6869
6602
  }
6870
6603
 
6871
- path(file) {
6872
- if (this.mapOpts.absolute) return file
6873
- if (file.charCodeAt(0) === 60 /* `<` */) return file
6874
- if (/^\w+:\/\//.test(file)) return file
6875
- let cached = this.memoizedPaths.get(file);
6876
- if (cached) return cached
6604
+ get last() {
6605
+ if (!this.proxyOf.nodes) return undefined
6606
+ return this.proxyOf.nodes[this.proxyOf.nodes.length - 1]
6607
+ }
6608
+ }
6877
6609
 
6878
- let from = this.opts.to ? dirname(this.opts.to) : '.';
6610
+ Container$7.registerParse = dependant => {
6611
+ parse$4 = dependant;
6612
+ };
6879
6613
 
6880
- if (typeof this.mapOpts.annotation === 'string') {
6881
- from = dirname(resolve(from, this.mapOpts.annotation));
6882
- }
6614
+ Container$7.registerRule = dependant => {
6615
+ Rule$4 = dependant;
6616
+ };
6883
6617
 
6884
- let path = relative(from, file);
6885
- this.memoizedPaths.set(file, path);
6618
+ Container$7.registerAtRule = dependant => {
6619
+ AtRule$4 = dependant;
6620
+ };
6886
6621
 
6887
- return path
6622
+ Container$7.registerRoot = dependant => {
6623
+ Root$6 = dependant;
6624
+ };
6625
+
6626
+ var container = Container$7;
6627
+ Container$7.default = Container$7;
6628
+
6629
+ /* c8 ignore start */
6630
+ Container$7.rebuild = node => {
6631
+ if (node.type === 'atrule') {
6632
+ Object.setPrototypeOf(node, AtRule$4.prototype);
6633
+ } else if (node.type === 'rule') {
6634
+ Object.setPrototypeOf(node, Rule$4.prototype);
6635
+ } else if (node.type === 'decl') {
6636
+ Object.setPrototypeOf(node, Declaration$3.prototype);
6637
+ } else if (node.type === 'comment') {
6638
+ Object.setPrototypeOf(node, Comment$3.prototype);
6639
+ } else if (node.type === 'root') {
6640
+ Object.setPrototypeOf(node, Root$6.prototype);
6888
6641
  }
6889
6642
 
6890
- previous() {
6891
- if (!this.previousMaps) {
6892
- this.previousMaps = [];
6893
- if (this.root) {
6894
- this.root.walk(node => {
6895
- if (node.source && node.source.input.map) {
6896
- let map = node.source.input.map;
6897
- if (!this.previousMaps.includes(map)) {
6898
- this.previousMaps.push(map);
6899
- }
6900
- }
6901
- });
6902
- } else {
6903
- let input = new Input$2(this.originalCSS, this.opts);
6904
- if (input.map) this.previousMaps.push(input.map);
6905
- }
6643
+ node[my$1] = true;
6644
+
6645
+ if (node.nodes) {
6646
+ node.nodes.forEach(child => {
6647
+ Container$7.rebuild(child);
6648
+ });
6649
+ }
6650
+ };
6651
+
6652
+ let Container$6 = container;
6653
+
6654
+ let LazyResult$4, Processor$3;
6655
+
6656
+ class Document$3 extends Container$6 {
6657
+ constructor(defaults) {
6658
+ // type needs to be passed to super, otherwise child roots won't be normalized correctly
6659
+ super({ type: 'document', ...defaults });
6660
+
6661
+ if (!this.nodes) {
6662
+ this.nodes = [];
6906
6663
  }
6664
+ }
6907
6665
 
6908
- return this.previousMaps
6666
+ toResult(opts = {}) {
6667
+ let lazy = new LazyResult$4(new Processor$3(), this, opts);
6668
+
6669
+ return lazy.stringify()
6909
6670
  }
6671
+ }
6910
6672
 
6911
- setSourcesContent() {
6912
- let already = {};
6913
- if (this.root) {
6914
- this.root.walk(node => {
6915
- if (node.source) {
6916
- let from = node.source.input.from;
6917
- if (from && !already[from]) {
6918
- already[from] = true;
6919
- let fromUrl = this.usesFileUrls
6920
- ? this.toFileUrl(from)
6921
- : this.toUrl(this.path(from));
6922
- this.map.setSourceContent(fromUrl, node.source.input.css);
6923
- }
6924
- }
6925
- });
6926
- } else if (this.css) {
6927
- let from = this.opts.from
6928
- ? this.toUrl(this.path(this.opts.from))
6929
- : '<no source>';
6930
- this.map.setSourceContent(from, this.css);
6673
+ Document$3.registerLazyResult = dependant => {
6674
+ LazyResult$4 = dependant;
6675
+ };
6676
+
6677
+ Document$3.registerProcessor = dependant => {
6678
+ Processor$3 = dependant;
6679
+ };
6680
+
6681
+ var document = Document$3;
6682
+ Document$3.default = Document$3;
6683
+
6684
+ class Warning$2 {
6685
+ constructor(text, opts = {}) {
6686
+ this.type = 'warning';
6687
+ this.text = text;
6688
+
6689
+ if (opts.node && opts.node.source) {
6690
+ let range = opts.node.rangeBy(opts);
6691
+ this.line = range.start.line;
6692
+ this.column = range.start.column;
6693
+ this.endLine = range.end.line;
6694
+ this.endColumn = range.end.column;
6931
6695
  }
6696
+
6697
+ for (let opt in opts) this[opt] = opts[opt];
6932
6698
  }
6933
6699
 
6934
- sourcePath(node) {
6935
- if (this.mapOpts.from) {
6936
- return this.toUrl(this.mapOpts.from)
6937
- } else if (this.usesFileUrls) {
6938
- return this.toFileUrl(node.source.input.from)
6939
- } else {
6940
- return this.toUrl(this.path(node.source.input.from))
6700
+ toString() {
6701
+ if (this.node) {
6702
+ return this.node.error(this.text, {
6703
+ index: this.index,
6704
+ plugin: this.plugin,
6705
+ word: this.word
6706
+ }).message
6941
6707
  }
6942
- }
6943
6708
 
6944
- toBase64(str) {
6945
- if (Buffer) {
6946
- return Buffer.from(str).toString('base64')
6947
- } else {
6948
- return window.btoa(unescape(encodeURIComponent(str)))
6709
+ if (this.plugin) {
6710
+ return this.plugin + ': ' + this.text
6949
6711
  }
6712
+
6713
+ return this.text
6950
6714
  }
6715
+ }
6951
6716
 
6952
- toFileUrl(path) {
6953
- let cached = this.memoizedFileURLs.get(path);
6954
- if (cached) return cached
6717
+ var warning = Warning$2;
6718
+ Warning$2.default = Warning$2;
6955
6719
 
6956
- if (pathToFileURL) {
6957
- let fileURL = pathToFileURL(path).toString();
6958
- this.memoizedFileURLs.set(path, fileURL);
6720
+ let Warning$1 = warning;
6959
6721
 
6960
- return fileURL
6961
- } else {
6962
- throw new Error(
6963
- '`map.absolute` option is not available in this PostCSS build'
6964
- )
6965
- }
6722
+ class Result$3 {
6723
+ constructor(processor, root, opts) {
6724
+ this.processor = processor;
6725
+ this.messages = [];
6726
+ this.root = root;
6727
+ this.opts = opts;
6728
+ this.css = undefined;
6729
+ this.map = undefined;
6966
6730
  }
6967
6731
 
6968
- toUrl(path) {
6969
- let cached = this.memoizedURLs.get(path);
6970
- if (cached) return cached
6732
+ toString() {
6733
+ return this.css
6734
+ }
6971
6735
 
6972
- if (sep === '\\') {
6973
- path = path.replace(/\\/g, '/');
6736
+ warn(text, opts = {}) {
6737
+ if (!opts.plugin) {
6738
+ if (this.lastPlugin && this.lastPlugin.postcssPlugin) {
6739
+ opts.plugin = this.lastPlugin.postcssPlugin;
6740
+ }
6974
6741
  }
6975
6742
 
6976
- let url = encodeURI(path).replace(/[#?]/g, encodeURIComponent);
6977
- this.memoizedURLs.set(path, url);
6743
+ let warning = new Warning$1(text, opts);
6744
+ this.messages.push(warning);
6978
6745
 
6979
- return url
6746
+ return warning
6747
+ }
6748
+
6749
+ warnings() {
6750
+ return this.messages.filter(i => i.type === 'warning')
6751
+ }
6752
+
6753
+ get content() {
6754
+ return this.css
6980
6755
  }
6981
6756
  }
6982
6757
 
6983
- var mapGenerator = MapGenerator$2;
6758
+ var result = Result$3;
6759
+ Result$3.default = Result$3;
6984
6760
 
6985
6761
  const SINGLE_QUOTE = "'".charCodeAt(0);
6986
6762
  const DOUBLE_QUOTE = '"'.charCodeAt(0);
@@ -7011,8 +6787,8 @@ var tokenize = function tokenizer(input, options = {}) {
7011
6787
  let css = input.css.valueOf();
7012
6788
  let ignore = options.ignoreErrors;
7013
6789
 
7014
- let code, content, escape, next, quote;
7015
- let currentToken, escaped, escapePos, n, prev;
6790
+ let code, next, quote, content, escape;
6791
+ let escaped, escapePos, prev, n, currentToken;
7016
6792
 
7017
6793
  let length = css.length;
7018
6794
  let pos = 0;
@@ -7227,32 +7003,199 @@ var tokenize = function tokenizer(input, options = {}) {
7227
7003
  pos = next;
7228
7004
  }
7229
7005
 
7230
- break
7006
+ break
7007
+ }
7008
+ }
7009
+
7010
+ pos++;
7011
+ return currentToken
7012
+ }
7013
+
7014
+ function back(token) {
7015
+ returned.push(token);
7016
+ }
7017
+
7018
+ return {
7019
+ back,
7020
+ endOfFile,
7021
+ nextToken,
7022
+ position
7023
+ }
7024
+ };
7025
+
7026
+ let Container$5 = container;
7027
+
7028
+ class AtRule$3 extends Container$5 {
7029
+ constructor(defaults) {
7030
+ super(defaults);
7031
+ this.type = 'atrule';
7032
+ }
7033
+
7034
+ append(...children) {
7035
+ if (!this.proxyOf.nodes) this.nodes = [];
7036
+ return super.append(...children)
7037
+ }
7038
+
7039
+ prepend(...children) {
7040
+ if (!this.proxyOf.nodes) this.nodes = [];
7041
+ return super.prepend(...children)
7042
+ }
7043
+ }
7044
+
7045
+ var atRule = AtRule$3;
7046
+ AtRule$3.default = AtRule$3;
7047
+
7048
+ Container$5.registerAtRule(AtRule$3);
7049
+
7050
+ let Container$4 = container;
7051
+
7052
+ let LazyResult$3, Processor$2;
7053
+
7054
+ class Root$5 extends Container$4 {
7055
+ constructor(defaults) {
7056
+ super(defaults);
7057
+ this.type = 'root';
7058
+ if (!this.nodes) this.nodes = [];
7059
+ }
7060
+
7061
+ normalize(child, sample, type) {
7062
+ let nodes = super.normalize(child);
7063
+
7064
+ if (sample) {
7065
+ if (type === 'prepend') {
7066
+ if (this.nodes.length > 1) {
7067
+ sample.raws.before = this.nodes[1].raws.before;
7068
+ } else {
7069
+ delete sample.raws.before;
7070
+ }
7071
+ } else if (this.first !== sample) {
7072
+ for (let node of nodes) {
7073
+ node.raws.before = sample.raws.before;
7074
+ }
7075
+ }
7076
+ }
7077
+
7078
+ return nodes
7079
+ }
7080
+
7081
+ removeChild(child, ignore) {
7082
+ let index = this.index(child);
7083
+
7084
+ if (!ignore && index === 0 && this.nodes.length > 1) {
7085
+ this.nodes[1].raws.before = this.nodes[index].raws.before;
7086
+ }
7087
+
7088
+ return super.removeChild(child)
7089
+ }
7090
+
7091
+ toResult(opts = {}) {
7092
+ let lazy = new LazyResult$3(new Processor$2(), this, opts);
7093
+ return lazy.stringify()
7094
+ }
7095
+ }
7096
+
7097
+ Root$5.registerLazyResult = dependant => {
7098
+ LazyResult$3 = dependant;
7099
+ };
7100
+
7101
+ Root$5.registerProcessor = dependant => {
7102
+ Processor$2 = dependant;
7103
+ };
7104
+
7105
+ var root = Root$5;
7106
+ Root$5.default = Root$5;
7107
+
7108
+ Container$4.registerRoot(Root$5);
7109
+
7110
+ let list$2 = {
7111
+ comma(string) {
7112
+ return list$2.split(string, [','], true)
7113
+ },
7114
+
7115
+ space(string) {
7116
+ let spaces = [' ', '\n', '\t'];
7117
+ return list$2.split(string, spaces)
7118
+ },
7119
+
7120
+ split(string, separators, last) {
7121
+ let array = [];
7122
+ let current = '';
7123
+ let split = false;
7124
+
7125
+ let func = 0;
7126
+ let inQuote = false;
7127
+ let prevQuote = '';
7128
+ let escape = false;
7129
+
7130
+ for (let letter of string) {
7131
+ if (escape) {
7132
+ escape = false;
7133
+ } else if (letter === '\\') {
7134
+ escape = true;
7135
+ } else if (inQuote) {
7136
+ if (letter === prevQuote) {
7137
+ inQuote = false;
7138
+ }
7139
+ } else if (letter === '"' || letter === "'") {
7140
+ inQuote = true;
7141
+ prevQuote = letter;
7142
+ } else if (letter === '(') {
7143
+ func += 1;
7144
+ } else if (letter === ')') {
7145
+ if (func > 0) func -= 1;
7146
+ } else if (func === 0) {
7147
+ if (separators.includes(letter)) split = true;
7148
+ }
7149
+
7150
+ if (split) {
7151
+ if (current !== '') array.push(current.trim());
7152
+ current = '';
7153
+ split = false;
7154
+ } else {
7155
+ current += letter;
7231
7156
  }
7232
7157
  }
7233
7158
 
7234
- pos++;
7235
- return currentToken
7159
+ if (last || current !== '') array.push(current.trim());
7160
+ return array
7236
7161
  }
7162
+ };
7237
7163
 
7238
- function back(token) {
7239
- returned.push(token);
7164
+ var list_1 = list$2;
7165
+ list$2.default = list$2;
7166
+
7167
+ let Container$3 = container;
7168
+ let list$1 = list_1;
7169
+
7170
+ class Rule$3 extends Container$3 {
7171
+ constructor(defaults) {
7172
+ super(defaults);
7173
+ this.type = 'rule';
7174
+ if (!this.nodes) this.nodes = [];
7240
7175
  }
7241
7176
 
7242
- return {
7243
- back,
7244
- endOfFile,
7245
- nextToken,
7246
- position
7177
+ get selectors() {
7178
+ return list$1.comma(this.selector)
7247
7179
  }
7248
- };
7249
7180
 
7250
- let AtRule$1 = atRule;
7251
- let Comment$1 = comment;
7252
- let Declaration$1 = declaration;
7253
- let Root$3 = root;
7254
- let Rule$1 = rule;
7181
+ set selectors(values) {
7182
+ let match = this.selector ? this.selector.match(/,\s*/) : null;
7183
+ let sep = match ? match[0] : ',' + this.raw('between', 'beforeOpen');
7184
+ this.selector = values.join(sep);
7185
+ }
7186
+ }
7187
+
7188
+ var rule = Rule$3;
7189
+ Rule$3.default = Rule$3;
7190
+
7191
+ Container$3.registerRule(Rule$3);
7192
+
7193
+ let Declaration$2 = declaration;
7255
7194
  let tokenizer = tokenize;
7195
+ let Comment$2 = comment;
7196
+ let AtRule$2 = atRule;
7197
+ let Root$4 = root;
7198
+ let Rule$2 = rule;
7256
7199
 
7257
7200
  const SAFE_COMMENT_NEIGHBOR = {
7258
7201
  empty: true,
@@ -7271,7 +7214,7 @@ class Parser$1 {
7271
7214
  constructor(input) {
7272
7215
  this.input = input;
7273
7216
 
7274
- this.root = new Root$3();
7217
+ this.root = new Root$4();
7275
7218
  this.current = this.root;
7276
7219
  this.spaces = '';
7277
7220
  this.semicolon = false;
@@ -7281,7 +7224,7 @@ class Parser$1 {
7281
7224
  }
7282
7225
 
7283
7226
  atrule(token) {
7284
- let node = new AtRule$1();
7227
+ let node = new AtRule$2();
7285
7228
  node.name = token[1].slice(1);
7286
7229
  if (node.name === '') {
7287
7230
  this.unnamedAtrule(node, token);
@@ -7390,7 +7333,7 @@ class Parser$1 {
7390
7333
 
7391
7334
  colon(tokens) {
7392
7335
  let brackets = 0;
7393
- let prev, token, type;
7336
+ let token, type, prev;
7394
7337
  for (let [i, element] of tokens.entries()) {
7395
7338
  token = element;
7396
7339
  type = token[0];
@@ -7417,7 +7360,7 @@ class Parser$1 {
7417
7360
  }
7418
7361
 
7419
7362
  comment(token) {
7420
- let node = new Comment$1();
7363
+ let node = new Comment$2();
7421
7364
  this.init(node, token[2]);
7422
7365
  node.source.end = this.getPosition(token[3] || token[2]);
7423
7366
  node.source.end.offset++;
@@ -7440,7 +7383,7 @@ class Parser$1 {
7440
7383
  }
7441
7384
 
7442
7385
  decl(tokens, customProperty) {
7443
- let node = new Declaration$1();
7386
+ let node = new Declaration$2();
7444
7387
  this.init(node, tokens[0][2]);
7445
7388
 
7446
7389
  let last = tokens[tokens.length - 1];
@@ -7514,12 +7457,12 @@ class Parser$1 {
7514
7457
  let str = '';
7515
7458
  for (let j = i; j > 0; j--) {
7516
7459
  let type = cache[j][0];
7517
- if (str.trim().startsWith('!') && type !== 'space') {
7460
+ if (str.trim().indexOf('!') === 0 && type !== 'space') {
7518
7461
  break
7519
7462
  }
7520
7463
  str = cache.pop()[1] + str;
7521
7464
  }
7522
- if (str.trim().startsWith('!')) {
7465
+ if (str.trim().indexOf('!') === 0) {
7523
7466
  node.important = true;
7524
7467
  node.raws.important = str;
7525
7468
  tokens = cache;
@@ -7553,7 +7496,7 @@ class Parser$1 {
7553
7496
  }
7554
7497
 
7555
7498
  emptyRule(token) {
7556
- let node = new Rule$1();
7499
+ let node = new Rule$2();
7557
7500
  this.init(node, token[2]);
7558
7501
  node.selector = '';
7559
7502
  node.raws.between = '';
@@ -7763,7 +7706,7 @@ class Parser$1 {
7763
7706
  rule(tokens) {
7764
7707
  tokens.pop();
7765
7708
 
7766
- let node = new Rule$1();
7709
+ let node = new Rule$2();
7767
7710
  this.init(node, tokens[0][2]);
7768
7711
 
7769
7712
  node.raws.between = this.spacesAndCommentsFromEnd(tokens);
@@ -7856,11 +7799,11 @@ class Parser$1 {
7856
7799
  var parser = Parser$1;
7857
7800
 
7858
7801
  let Container$2 = container;
7859
- let Input$1 = input;
7860
7802
  let Parser = parser;
7803
+ let Input$2 = input;
7861
7804
 
7862
7805
  function parse$3(css, opts) {
7863
- let input = new Input$1(css, opts);
7806
+ let input = new Input$2(css, opts);
7864
7807
  let parser = new Parser(input);
7865
7808
  try {
7866
7809
  parser.parse();
@@ -7876,91 +7819,14 @@ parse$3.default = parse$3;
7876
7819
 
7877
7820
  Container$2.registerParse(parse$3);
7878
7821
 
7879
- class Warning$2 {
7880
- constructor(text, opts = {}) {
7881
- this.type = 'warning';
7882
- this.text = text;
7883
-
7884
- if (opts.node && opts.node.source) {
7885
- let range = opts.node.rangeBy(opts);
7886
- this.line = range.start.line;
7887
- this.column = range.start.column;
7888
- this.endLine = range.end.line;
7889
- this.endColumn = range.end.column;
7890
- }
7891
-
7892
- for (let opt in opts) this[opt] = opts[opt];
7893
- }
7894
-
7895
- toString() {
7896
- if (this.node) {
7897
- return this.node.error(this.text, {
7898
- index: this.index,
7899
- plugin: this.plugin,
7900
- word: this.word
7901
- }).message
7902
- }
7903
-
7904
- if (this.plugin) {
7905
- return this.plugin + ': ' + this.text
7906
- }
7907
-
7908
- return this.text
7909
- }
7910
- }
7911
-
7912
- var warning = Warning$2;
7913
- Warning$2.default = Warning$2;
7914
-
7915
- let Warning$1 = warning;
7916
-
7917
- class Result$3 {
7918
- constructor(processor, root, opts) {
7919
- this.processor = processor;
7920
- this.messages = [];
7921
- this.root = root;
7922
- this.opts = opts;
7923
- this.css = undefined;
7924
- this.map = undefined;
7925
- }
7926
-
7927
- toString() {
7928
- return this.css
7929
- }
7930
-
7931
- warn(text, opts = {}) {
7932
- if (!opts.plugin) {
7933
- if (this.lastPlugin && this.lastPlugin.postcssPlugin) {
7934
- opts.plugin = this.lastPlugin.postcssPlugin;
7935
- }
7936
- }
7937
-
7938
- let warning = new Warning$1(text, opts);
7939
- this.messages.push(warning);
7940
-
7941
- return warning
7942
- }
7943
-
7944
- warnings() {
7945
- return this.messages.filter(i => i.type === 'warning')
7946
- }
7947
-
7948
- get content() {
7949
- return this.css
7950
- }
7951
- }
7952
-
7953
- var result = Result$3;
7954
- Result$3.default = Result$3;
7955
-
7822
+ let { isClean, my } = symbols;
7823
+ let MapGenerator$1 = mapGenerator;
7824
+ let stringify$2 = stringify_1;
7956
7825
  let Container$1 = container;
7957
7826
  let Document$2 = document;
7958
- let MapGenerator$1 = mapGenerator;
7959
- let parse$2 = parse_1;
7960
7827
  let Result$2 = result;
7961
- let Root$2 = root;
7962
- let stringify$2 = stringify_1;
7963
- let { isClean, my } = symbols;
7828
+ let parse$2 = parse_1;
7829
+ let Root$3 = root;
7964
7830
 
7965
7831
  const TYPE_TO_CLASS_NAME = {
7966
7832
  atrule: 'AtRule',
@@ -8467,13 +8333,13 @@ LazyResult$2.registerPostcss = dependant => {
8467
8333
  var lazyResult = LazyResult$2;
8468
8334
  LazyResult$2.default = LazyResult$2;
8469
8335
 
8470
- Root$2.registerLazyResult(LazyResult$2);
8336
+ Root$3.registerLazyResult(LazyResult$2);
8471
8337
  Document$2.registerLazyResult(LazyResult$2);
8472
8338
 
8473
8339
  let MapGenerator = mapGenerator;
8340
+ let stringify$1 = stringify_1;
8474
8341
  let parse$1 = parse_1;
8475
8342
  const Result$1 = result;
8476
- let stringify$1 = stringify_1;
8477
8343
 
8478
8344
  class NoWorkResult$1 {
8479
8345
  constructor(processor, css, opts) {
@@ -8597,14 +8463,14 @@ class NoWorkResult$1 {
8597
8463
  var noWorkResult = NoWorkResult$1;
8598
8464
  NoWorkResult$1.default = NoWorkResult$1;
8599
8465
 
8600
- let Document$1 = document;
8601
- let LazyResult$1 = lazyResult;
8602
8466
  let NoWorkResult = noWorkResult;
8603
- let Root$1 = root;
8467
+ let LazyResult$1 = lazyResult;
8468
+ let Document$1 = document;
8469
+ let Root$2 = root;
8604
8470
 
8605
8471
  class Processor$1 {
8606
8472
  constructor(plugins = []) {
8607
- this.version = '8.4.49';
8473
+ this.version = '8.4.35';
8608
8474
  this.plugins = this.normalize(plugins);
8609
8475
  }
8610
8476
 
@@ -8652,27 +8518,80 @@ class Processor$1 {
8652
8518
  var processor = Processor$1;
8653
8519
  Processor$1.default = Processor$1;
8654
8520
 
8655
- Root$1.registerProcessor(Processor$1);
8521
+ Root$2.registerProcessor(Processor$1);
8656
8522
  Document$1.registerProcessor(Processor$1);
8657
8523
 
8658
- let AtRule = atRule;
8659
- let Comment = comment;
8660
- let Container = container;
8524
+ let Declaration$1 = declaration;
8525
+ let PreviousMap = previousMap;
8526
+ let Comment$1 = comment;
8527
+ let AtRule$1 = atRule;
8528
+ let Input$1 = input;
8529
+ let Root$1 = root;
8530
+ let Rule$1 = rule;
8531
+
8532
+ function fromJSON$1(json, inputs) {
8533
+ if (Array.isArray(json)) return json.map(n => fromJSON$1(n))
8534
+
8535
+ let { inputs: ownInputs, ...defaults } = json;
8536
+ if (ownInputs) {
8537
+ inputs = [];
8538
+ for (let input of ownInputs) {
8539
+ let inputHydrated = { ...input, __proto__: Input$1.prototype };
8540
+ if (inputHydrated.map) {
8541
+ inputHydrated.map = {
8542
+ ...inputHydrated.map,
8543
+ __proto__: PreviousMap.prototype
8544
+ };
8545
+ }
8546
+ inputs.push(inputHydrated);
8547
+ }
8548
+ }
8549
+ if (defaults.nodes) {
8550
+ defaults.nodes = json.nodes.map(n => fromJSON$1(n, inputs));
8551
+ }
8552
+ if (defaults.source) {
8553
+ let { inputId, ...source } = defaults.source;
8554
+ defaults.source = source;
8555
+ if (inputId != null) {
8556
+ defaults.source.input = inputs[inputId];
8557
+ }
8558
+ }
8559
+ if (defaults.type === 'root') {
8560
+ return new Root$1(defaults)
8561
+ } else if (defaults.type === 'decl') {
8562
+ return new Declaration$1(defaults)
8563
+ } else if (defaults.type === 'rule') {
8564
+ return new Rule$1(defaults)
8565
+ } else if (defaults.type === 'comment') {
8566
+ return new Comment$1(defaults)
8567
+ } else if (defaults.type === 'atrule') {
8568
+ return new AtRule$1(defaults)
8569
+ } else {
8570
+ throw new Error('Unknown node type: ' + json.type)
8571
+ }
8572
+ }
8573
+
8574
+ var fromJSON_1 = fromJSON$1;
8575
+ fromJSON$1.default = fromJSON$1;
8576
+
8661
8577
  let CssSyntaxError = cssSyntaxError;
8662
8578
  let Declaration = declaration;
8663
- let Document = document;
8664
- let fromJSON = fromJSON_1;
8665
- let Input = input;
8666
8579
  let LazyResult = lazyResult;
8667
- let list = list_1;
8668
- let Node = node_1;
8669
- let parse = parse_1;
8580
+ let Container = container;
8670
8581
  let Processor = processor;
8671
- let Result = result;
8672
- let Root = root;
8673
- let Rule = rule;
8674
8582
  let stringify = stringify_1;
8583
+ let fromJSON = fromJSON_1;
8584
+ let Document = document;
8675
8585
  let Warning = warning;
8586
+ let Comment = comment;
8587
+ let AtRule = atRule;
8588
+ let Result = result;
8589
+ let Input = input;
8590
+ let parse = parse_1;
8591
+ let list = list_1;
8592
+ let Rule = rule;
8593
+ let Root = root;
8594
+ let Node = node_1;
8676
8595
 
8677
8596
  function postcss(...plugins) {
8678
8597
  if (plugins.length === 1 && Array.isArray(plugins[0])) {
@@ -8755,7 +8674,7 @@ LazyResult.registerPostcss(postcss);
8755
8674
  var postcss_1 = postcss;
8756
8675
  postcss.default = postcss;
8757
8676
 
8758
- const htmlparser = require$$0$1;
8677
+ const htmlparser = require$$0;
8759
8678
  const escapeStringRegexp = escapeStringRegexp$1;
8760
8679
  const { isPlainObject } = require$$2$1;
8761
8680
  const deepmerge = cjs;
@@ -8927,24 +8846,20 @@ function sanitizeHtml(html, options, _recursing) {
8927
8846
  allowedAttributesMap[tag].push('class');
8928
8847
  }
8929
8848
 
8930
- allowedClassesMap[tag] = classes;
8931
-
8932
- if (Array.isArray(classes)) {
8933
- const globRegex = [];
8934
- allowedClassesMap[tag] = [];
8935
- allowedClassesRegexMap[tag] = [];
8936
- classes.forEach(function(obj) {
8937
- if (typeof obj === 'string' && obj.indexOf('*') >= 0) {
8938
- globRegex.push(escapeStringRegexp(obj).replace(/\\\*/g, '.*'));
8939
- } else if (obj instanceof RegExp) {
8940
- allowedClassesRegexMap[tag].push(obj);
8941
- } else {
8942
- allowedClassesMap[tag].push(obj);
8943
- }
8944
- });
8945
- if (globRegex.length) {
8946
- allowedClassesGlobMap[tag] = new RegExp('^(' + globRegex.join('|') + ')$');
8849
+ allowedClassesMap[tag] = [];
8850
+ allowedClassesRegexMap[tag] = [];
8851
+ const globRegex = [];
8852
+ classes.forEach(function(obj) {
8853
+ if (typeof obj === 'string' && obj.indexOf('*') >= 0) {
8854
+ globRegex.push(escapeStringRegexp(obj).replace(/\\\*/g, '.*'));
8855
+ } else if (obj instanceof RegExp) {
8856
+ allowedClassesRegexMap[tag].push(obj);
8857
+ } else {
8858
+ allowedClassesMap[tag].push(obj);
8947
8859
  }
8860
+ });
8861
+ if (globRegex.length) {
8862
+ allowedClassesGlobMap[tag] = new RegExp('^(' + globRegex.join('|') + ')$');
8948
8863
  }
8949
8864
  });
8950
8865
 
@@ -9019,7 +8934,7 @@ function sanitizeHtml(html, options, _recursing) {
9019
8934
  if (!tagAllowed(name) || (options.disallowedTagsMode === 'recursiveEscape' && !isEmptyObject(skipMap)) || (options.nestingLimit != null && depth >= options.nestingLimit)) {
9020
8935
  skip = true;
9021
8936
  skipMap[depth] = true;
9022
- if (options.disallowedTagsMode === 'discard' || options.disallowedTagsMode === 'completelyDiscard') {
8937
+ if (options.disallowedTagsMode === 'discard') {
9023
8938
  if (nonTextTagsArray.indexOf(name) !== -1) {
9024
8939
  skipText = true;
9025
8940
  skipTextDepth = 1;
@@ -9029,7 +8944,7 @@ function sanitizeHtml(html, options, _recursing) {
9029
8944
  }
9030
8945
  depth++;
9031
8946
  if (skip) {
9032
- if (options.disallowedTagsMode === 'discard' || options.disallowedTagsMode === 'completelyDiscard') {
8947
+ if (options.disallowedTagsMode === 'discard') {
9033
8948
  // We want the contents but not this tag
9034
8949
  return;
9035
8950
  }
@@ -9052,14 +8967,6 @@ function sanitizeHtml(html, options, _recursing) {
9052
8967
  delete frame.attribs[a];
9053
8968
  return;
9054
8969
  }
9055
- // If the value is empty, check if the attribute is in the allowedEmptyAttributes array.
9056
- // If it is not in the allowedEmptyAttributes array, and it is a known non-boolean attribute, delete it
9057
- // List taken from https://html.spec.whatwg.org/multipage/indices.html#attributes-3
9058
- if (value === '' && (!options.allowedEmptyAttributes.includes(a)) &&
9059
- (options.nonBooleanAttributes.includes(a) || options.nonBooleanAttributes.includes('*'))) {
9060
- delete frame.attribs[a];
9061
- return;
9062
- }
9063
8970
  // check allowedAttributesMap for the element and attribute and modify the value
9064
8971
  // as necessary if there are specific values defined.
9065
8972
  let passedAllowedAttributesMapCheck = false;
@@ -9188,13 +9095,12 @@ function sanitizeHtml(html, options, _recursing) {
9188
9095
  const allowedWildcardClasses = allowedClassesMap['*'];
9189
9096
  const allowedSpecificClassesGlob = allowedClassesGlobMap[name];
9190
9097
  const allowedSpecificClassesRegex = allowedClassesRegexMap[name];
9191
- const allowedWildcardClassesRegex = allowedClassesRegexMap['*'];
9192
9098
  const allowedWildcardClassesGlob = allowedClassesGlobMap['*'];
9193
9099
  const allowedClassesGlobs = [
9194
9100
  allowedSpecificClassesGlob,
9195
9101
  allowedWildcardClassesGlob
9196
9102
  ]
9197
- .concat(allowedSpecificClassesRegex, allowedWildcardClassesRegex)
9103
+ .concat(allowedSpecificClassesRegex)
9198
9104
  .filter(function (t) {
9199
9105
  return t;
9200
9106
  });
@@ -9211,7 +9117,7 @@ function sanitizeHtml(html, options, _recursing) {
9211
9117
  if (a === 'style') {
9212
9118
  if (options.parseStyleAttributes) {
9213
9119
  try {
9214
- const abstractSyntaxTree = postcssParse(name + ' {' + value + '}', { map: false });
9120
+ const abstractSyntaxTree = postcssParse(name + ' {' + value + '}');
9215
9121
  const filteredAST = filterCss(abstractSyntaxTree, options.allowedStyles);
9216
9122
 
9217
9123
  value = stringifyStyleAttributes(filteredAST);
@@ -9221,9 +9127,7 @@ function sanitizeHtml(html, options, _recursing) {
9221
9127
  return;
9222
9128
  }
9223
9129
  } catch (e) {
9224
- if (typeof window !== 'undefined') {
9225
- console.warn('Failed to parse "' + name + ' {' + value + '}' + '", If you\'re running this in a browser, we recommend to disable style parsing: options.parseStyleAttributes: false, since this only works in a node environment due to a postcss dependency, More info: https://github.com/apostrophecms/sanitize-html/issues/547');
9226
- }
9130
+ console.warn('Failed to parse "' + name + ' {' + value + '}' + '", If you\'re running this in a browser, we recommend to disable style parsing: options.parseStyleAttributes: false, since this only works in a node environment due to a postcss dependency, More info: https://github.com/apostrophecms/sanitize-html/issues/547');
9227
9131
  delete frame.attribs[a];
9228
9132
  return;
9229
9133
  }
@@ -9234,8 +9138,6 @@ function sanitizeHtml(html, options, _recursing) {
9234
9138
  result += ' ' + a;
9235
9139
  if (value && value.length) {
9236
9140
  result += '="' + escapeHtml(value, true) + '"';
9237
- } else if (options.allowedEmptyAttributes.includes(a)) {
9238
- result += '=""';
9239
9141
  }
9240
9142
  } else {
9241
9143
  delete frame.attribs[a];
@@ -9269,9 +9171,7 @@ function sanitizeHtml(html, options, _recursing) {
9269
9171
  text = lastFrame.innerText !== undefined ? lastFrame.innerText : text;
9270
9172
  }
9271
9173
 
9272
- if (options.disallowedTagsMode === 'completelyDiscard' && !tagAllowed(tag)) {
9273
- text = '';
9274
- } else if ((options.disallowedTagsMode === 'discard' || options.disallowedTagsMode === 'completelyDiscard') && ((tag === 'script') || (tag === 'style'))) {
9174
+ if (options.disallowedTagsMode === 'discard' && ((tag === 'script') || (tag === 'style'))) {
9275
9175
  // htmlparser2 gives us these as-is. Escaping them ruins the content. Allowing
9276
9176
  // script tags is, by definition, game over for XSS protection, so if that's
9277
9177
  // your concern, don't allow them. The same is essentially true for style tags
@@ -9319,7 +9219,7 @@ function sanitizeHtml(html, options, _recursing) {
9319
9219
  const skip = skipMap[depth];
9320
9220
  if (skip) {
9321
9221
  delete skipMap[depth];
9322
- if (options.disallowedTagsMode === 'discard' || options.disallowedTagsMode === 'completelyDiscard') {
9222
+ if (options.disallowedTagsMode === 'discard') {
9323
9223
  frame.updateParentNodeText();
9324
9224
  return;
9325
9225
  }
@@ -9590,49 +9490,6 @@ sanitizeHtml.defaults = {
9590
9490
  'caption', 'col', 'colgroup', 'table', 'tbody', 'td', 'tfoot', 'th',
9591
9491
  'thead', 'tr'
9592
9492
  ],
9593
- // Tags that cannot be boolean
9594
- nonBooleanAttributes: [
9595
- 'abbr', 'accept', 'accept-charset', 'accesskey', 'action',
9596
- 'allow', 'alt', 'as', 'autocapitalize', 'autocomplete',
9597
- 'blocking', 'charset', 'cite', 'class', 'color', 'cols',
9598
- 'colspan', 'content', 'contenteditable', 'coords', 'crossorigin',
9599
- 'data', 'datetime', 'decoding', 'dir', 'dirname', 'download',
9600
- 'draggable', 'enctype', 'enterkeyhint', 'fetchpriority', 'for',
9601
- 'form', 'formaction', 'formenctype', 'formmethod', 'formtarget',
9602
- 'headers', 'height', 'hidden', 'high', 'href', 'hreflang',
9603
- 'http-equiv', 'id', 'imagesizes', 'imagesrcset', 'inputmode',
9604
- 'integrity', 'is', 'itemid', 'itemprop', 'itemref', 'itemtype',
9605
- 'kind', 'label', 'lang', 'list', 'loading', 'low', 'max',
9606
- 'maxlength', 'media', 'method', 'min', 'minlength', 'name',
9607
- 'nonce', 'optimum', 'pattern', 'ping', 'placeholder', 'popover',
9608
- 'popovertarget', 'popovertargetaction', 'poster', 'preload',
9609
- 'referrerpolicy', 'rel', 'rows', 'rowspan', 'sandbox', 'scope',
9610
- 'shape', 'size', 'sizes', 'slot', 'span', 'spellcheck', 'src',
9611
- 'srcdoc', 'srclang', 'srcset', 'start', 'step', 'style',
9612
- 'tabindex', 'target', 'title', 'translate', 'type', 'usemap',
9613
- 'value', 'width', 'wrap',
9614
- // Event handlers
9615
- 'onauxclick', 'onafterprint', 'onbeforematch', 'onbeforeprint',
9616
- 'onbeforeunload', 'onbeforetoggle', 'onblur', 'oncancel',
9617
- 'oncanplay', 'oncanplaythrough', 'onchange', 'onclick', 'onclose',
9618
- 'oncontextlost', 'oncontextmenu', 'oncontextrestored', 'oncopy',
9619
- 'oncuechange', 'oncut', 'ondblclick', 'ondrag', 'ondragend',
9620
- 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart',
9621
- 'ondrop', 'ondurationchange', 'onemptied', 'onended',
9622
- 'onerror', 'onfocus', 'onformdata', 'onhashchange', 'oninput',
9623
- 'oninvalid', 'onkeydown', 'onkeypress', 'onkeyup',
9624
- 'onlanguagechange', 'onload', 'onloadeddata', 'onloadedmetadata',
9625
- 'onloadstart', 'onmessage', 'onmessageerror', 'onmousedown',
9626
- 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout',
9627
- 'onmouseover', 'onmouseup', 'onoffline', 'ononline', 'onpagehide',
9628
- 'onpageshow', 'onpaste', 'onpause', 'onplay', 'onplaying',
9629
- 'onpopstate', 'onprogress', 'onratechange', 'onreset', 'onresize',
9630
- 'onrejectionhandled', 'onscroll', 'onscrollend',
9631
- 'onsecuritypolicyviolation', 'onseeked', 'onseeking', 'onselect',
9632
- 'onslotchange', 'onstalled', 'onstorage', 'onsubmit', 'onsuspend',
9633
- 'ontimeupdate', 'ontoggle', 'onunhandledrejection', 'onunload',
9634
- 'onvolumechange', 'onwaiting', 'onwheel'
9635
- ],
9636
9493
  disallowedTagsMode: 'discard',
9637
9494
  allowedAttributes: {
9638
9495
  a: [ 'href', 'name', 'target' ],
@@ -9640,9 +9497,6 @@ sanitizeHtml.defaults = {
9640
9497
  // these attributes would make sense if we did.
9641
9498
  img: [ 'src', 'srcset', 'alt', 'title', 'width', 'height', 'loading' ]
9642
9499
  },
9643
- allowedEmptyAttributes: [
9644
- 'alt'
9645
- ],
9646
9500
  // Lots of these won't come up by default because we don't allow them
9647
9501
  selfClosing: [ 'img', 'br', 'hr', 'area', 'base', 'basefont', 'input', 'link', 'meta' ],
9648
9502
  // URL schemes we permit