@angular/ssr 21.2.19 → 21.2.20

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.
@@ -605,6 +605,10 @@ function requireStringifier () {
605
605
  const STYLE_TAG = /(<)(\/?style\b)/gi;
606
606
  const COMMENT_OPEN = /(<)(!--)/g;
607
607
 
608
+ // Characters that end an at-rule name, mirroring RE_AT_END in the tokenizer.
609
+ // Params starting with anything else need a space to stay separate tokens.
610
+ const AT_NAME_END = /[\t\n\f\r "#'()/;[\\\]{}]/;
611
+
608
612
  function escapeHTMLInCSS(str) {
609
613
  if (typeof str !== 'string') return str
610
614
  if (!str.includes('<')) return str
@@ -630,27 +634,89 @@ function requireStringifier () {
630
634
  return str[0].toUpperCase() + str.slice(1)
631
635
  }
632
636
 
637
+ function atruleStart(str, node) {
638
+ let name = '@' + node.name;
639
+ let params = node.params ? str.rawValue(node, 'params') : '';
640
+ let afterName = node.raws.afterName;
641
+
642
+ if (typeof afterName === 'undefined') {
643
+ afterName = params ? ' ' : '';
644
+ } else if (afterName === '' && params && !AT_NAME_END.test(params[0])) {
645
+ afterName = ' ';
646
+ }
647
+
648
+ return name + afterName + params
649
+ }
650
+
651
+ function pushBody(str, stack, node) {
652
+ let nodes = node.nodes;
653
+ let last = nodes.length - 1;
654
+ while (last > 0) {
655
+ if (nodes[last].type !== 'comment') break
656
+ last -= 1;
657
+ }
658
+
659
+ let semicolon = str.raw(node, 'semicolon');
660
+ let isDocument = node.type === 'document';
661
+ for (let i = nodes.length - 1; i >= 0; i--) {
662
+ let child = nodes[i];
663
+ let childSemicolon = last !== i || semicolon;
664
+ // A childless at-rule or a custom property declaration that still has
665
+ // following siblings must be terminated. Without the semicolon those
666
+ // trailing comments are folded into the at-rule's prelude or the custom
667
+ // property's value and disappear when the output is re-parsed.
668
+ if (
669
+ !childSemicolon &&
670
+ i < nodes.length - 1 &&
671
+ ((child.type === 'atrule' && !child.nodes) ||
672
+ (child.type === 'decl' && child.prop.startsWith('--')))
673
+ ) {
674
+ childSemicolon = true;
675
+ }
676
+ stack.push({
677
+ document: isDocument,
678
+ node: child,
679
+ semicolon: childSemicolon
680
+ });
681
+ }
682
+ }
683
+
684
+ function pushBlock(str, stack, node, start) {
685
+ let between = str.raw(node, 'between', 'beforeOpen');
686
+ str.builder(escapeHTMLInCSS(start + between) + '{', node, 'start');
687
+
688
+ let hasNodes = node.nodes && node.nodes.length;
689
+ let close = () => {
690
+ let after = hasNodes
691
+ ? str.raw(node, 'after')
692
+ : str.raw(node, 'after', 'emptyBody');
693
+ if (after) str.builder(escapeHTMLInCSS(after));
694
+ str.builder('}', node, 'end');
695
+ if (node.type === 'rule' && node.raws.ownSemicolon) {
696
+ str.builder(escapeHTMLInCSS(node.raws.ownSemicolon), node, 'end');
697
+ }
698
+ };
699
+
700
+ if (hasNodes) {
701
+ stack.push(close);
702
+ pushBody(str, stack, node);
703
+ } else {
704
+ close();
705
+ }
706
+ }
707
+
633
708
  class Stringifier {
634
709
  constructor(builder) {
635
710
  this.builder = builder;
636
711
  }
637
712
 
638
713
  atrule(node, semicolon) {
639
- let raws = node.raws;
640
- let name = '@' + node.name;
641
- let params = node.params ? this.rawValue(node, 'params') : '';
642
-
643
- if (typeof raws.afterName !== 'undefined') {
644
- name += raws.afterName;
645
- } else if (params) {
646
- name += ' ';
647
- }
648
-
714
+ let start = atruleStart(this, node);
649
715
  if (node.nodes) {
650
- this.block(node, name + params);
716
+ this.block(node, start);
651
717
  } else {
652
- let end = (raws.between || '') + (semicolon ? ';' : '');
653
- this.builder(escapeHTMLInCSS(name + params + end), node);
718
+ let end = (node.raws.between || '') + (semicolon ? ';' : '');
719
+ this.builder(escapeHTMLInCSS(start + end), node);
654
720
  }
655
721
  }
656
722
 
@@ -684,22 +750,15 @@ function requireStringifier () {
684
750
  }
685
751
 
686
752
  block(node, start) {
687
- let raws = node.raws;
688
- let between = typeof raws.between !== 'undefined'
689
- ? raws.between
690
- : this.raw(node, 'between', 'beforeOpen');
753
+ let between = this.raw(node, 'between', 'beforeOpen');
691
754
  this.builder(escapeHTMLInCSS(start + between) + '{', node, 'start');
692
755
 
693
756
  let after;
694
757
  if (node.nodes && node.nodes.length) {
695
758
  this.body(node);
696
- after = typeof raws.after !== 'undefined'
697
- ? raws.after
698
- : this.raw(node, 'after');
759
+ after = this.raw(node, 'after');
699
760
  } else {
700
- after = typeof raws.after !== 'undefined'
701
- ? raws.after
702
- : this.raw(node, 'after', 'emptyBody');
761
+ after = this.raw(node, 'after', 'emptyBody');
703
762
  }
704
763
 
705
764
  if (after) this.builder(escapeHTMLInCSS(after));
@@ -707,47 +766,52 @@ function requireStringifier () {
707
766
  }
708
767
 
709
768
  body(node) {
710
- let nodes = node.nodes;
711
- let last = nodes.length - 1;
712
- while (last > 0) {
713
- if (nodes[last].type !== 'comment') break
714
- last -= 1;
715
- }
769
+ // Rules and at-rules are expanded into an explicit stack instead of
770
+ // recursive `stringify()` calls to survive deeply nested trees.
771
+ // If a subclass changes the traversal methods, its children go
772
+ // through `stringify()` to keep the override in charge.
773
+ let proto = Stringifier.prototype;
774
+ let expandable = ['atrule', 'block', 'body', 'rule', 'stringify'].every(
775
+ method => this[method] === proto[method]
776
+ );
716
777
 
717
- let semicolon = this.raw(node, 'semicolon');
718
- let isDocument = node.type === 'document';
719
- for (let i = 0; i < nodes.length; i++) {
720
- let child = nodes[i];
721
- let before = child.raws.before;
722
- if (typeof before === 'undefined') {
723
- before = this.raw(child, 'before');
778
+ let stack = [];
779
+ pushBody(this, stack, node);
780
+
781
+ while (stack.length > 0) {
782
+ let entry = stack.pop();
783
+ if (typeof entry === 'function') {
784
+ entry();
785
+ continue
786
+ }
787
+
788
+ let child = entry.node;
789
+ let before = this.raw(child, 'before');
790
+ if (before) {
791
+ this.builder(entry.document ? before : escapeHTMLInCSS(before));
792
+ }
793
+
794
+ if (expandable && child.type === 'rule') {
795
+ pushBlock(this, stack, child, this.rawValue(child, 'selector'));
796
+ } else if (expandable && child.type === 'atrule' && child.nodes) {
797
+ pushBlock(this, stack, child, atruleStart(this, child));
798
+ } else {
799
+ this.stringify(child, entry.semicolon);
724
800
  }
725
- if (before) this.builder(isDocument ? before : escapeHTMLInCSS(before));
726
- this.stringify(child, last !== i || semicolon);
727
801
  }
728
802
  }
729
803
 
730
804
  comment(node) {
731
- let raws = node.raws;
732
- let left = typeof raws.left !== 'undefined'
733
- ? raws.left
734
- : this.raw(node, 'left', 'commentLeft');
735
- let right = typeof raws.right !== 'undefined'
736
- ? raws.right
737
- : this.raw(node, 'right', 'commentRight');
805
+ let left = this.raw(node, 'left', 'commentLeft');
806
+ let right = this.raw(node, 'right', 'commentRight');
738
807
  this.builder(escapeHTMLInCSS('/*' + left + node.text + right + '*/'), node);
739
808
  }
740
809
 
741
810
  decl(node, semicolon) {
742
811
  let raws = node.raws;
743
- let between = typeof raws.between !== 'undefined'
744
- ? raws.between
745
- : this.raw(node, 'between', 'colon');
812
+ let between = this.raw(node, 'between', 'colon');
746
813
 
747
- let rawVal = raws.value;
748
- let value = rawVal && rawVal.value === node.value ? rawVal.raw : node.value;
749
-
750
- let string = node.prop + between + value;
814
+ let string = node.prop + between + this.rawValue(node, 'value');
751
815
 
752
816
  if (node.important) {
753
817
  string += raws.important || ' !important';
@@ -1041,25 +1105,41 @@ function requireNode$1 () {
1041
1105
 
1042
1106
  function cloneNode(obj, parent) {
1043
1107
  let cloned = new obj.constructor();
1044
-
1045
- for (let i in obj) {
1046
- if (!Object.prototype.hasOwnProperty.call(obj, i)) {
1047
- /* c8 ignore next 2 */
1048
- continue
1049
- }
1050
- if (i === 'proxyCache') continue
1051
- let value = obj[i];
1052
- let type = typeof value;
1053
-
1054
- if (i === 'parent' && type === 'object') {
1055
- if (parent) cloned[i] = parent;
1056
- } else if (i === 'source') {
1057
- cloned[i] = value;
1058
- } else if (Array.isArray(value)) {
1059
- cloned[i] = value.map(j => cloneNode(j, cloned));
1060
- } else {
1061
- if (type === 'object' && value !== null) value = cloneNode(value);
1062
- cloned[i] = value;
1108
+ // An explicit stack instead of recursive calls to survive deeply
1109
+ // nested trees. Each entry is [source, its clone, clone's parent].
1110
+ let stack = [[obj, cloned, parent]];
1111
+
1112
+ while (stack.length > 0) {
1113
+ let [source, target, targetParent] = stack.pop();
1114
+ for (let i in source) {
1115
+ if (!Object.prototype.hasOwnProperty.call(source, i)) {
1116
+ /* c8 ignore next 2 */
1117
+ continue
1118
+ }
1119
+ if (i === 'proxyCache') continue
1120
+ let value = source[i];
1121
+ let type = typeof value;
1122
+
1123
+ if (i === 'parent' && type === 'object') {
1124
+ if (targetParent) target[i] = targetParent;
1125
+ } else if (i === 'source') {
1126
+ target[i] = value;
1127
+ } else if (Array.isArray(value)) {
1128
+ let children = [];
1129
+ target[i] = children;
1130
+ for (let j of value) {
1131
+ let childClone = new j.constructor();
1132
+ children.push(childClone);
1133
+ stack.push([j, childClone, target]);
1134
+ }
1135
+ } else {
1136
+ if (type === 'object' && value !== null) {
1137
+ let valueClone = new value.constructor();
1138
+ stack.push([value, valueClone, undefined]);
1139
+ value = valueClone;
1140
+ }
1141
+ target[i] = value;
1142
+ }
1063
1143
  }
1064
1144
  }
1065
1145
 
@@ -1103,11 +1183,15 @@ function requireNode$1 () {
1103
1183
  this[isClean] = false;
1104
1184
  this[my] = true;
1105
1185
 
1106
- for (let name in defaults) {
1186
+ for (let name of Object.keys(defaults)) {
1187
+ if (name === '__proto__') continue
1107
1188
  if (name === 'nodes') {
1108
1189
  this.nodes = [];
1109
1190
  for (let node of defaults[name]) {
1110
- if (typeof node.clone === 'function') {
1191
+ // Clone only nodes that already belong to another tree, so passing a
1192
+ // freshly created (parent-less) node adopts that instance instead of
1193
+ // a copy and keeps the caller's reference usable. See #1987.
1194
+ if (typeof node.clone === 'function' && node.parent) {
1111
1195
  this.append(node.clone());
1112
1196
  } else {
1113
1197
  this.append(node);
@@ -1240,14 +1324,18 @@ function requireNode$1 () {
1240
1324
  }
1241
1325
 
1242
1326
  positionBy(opts = {}) {
1243
- let pos = this.source.start;
1327
+ let inputString =
1328
+ 'document' in this.source.input
1329
+ ? this.source.input.document
1330
+ : this.source.input.css;
1331
+ let pos = {
1332
+ column: this.source.start.column,
1333
+ line: this.source.start.line,
1334
+ offset: sourceOffset(inputString, this.source.start)
1335
+ };
1244
1336
  if (opts.index) {
1245
1337
  pos = this.positionInside(opts.index);
1246
1338
  } else if (opts.word) {
1247
- let inputString =
1248
- 'document' in this.source.input
1249
- ? this.source.input.document
1250
- : this.source.input.css;
1251
1339
  let stringRepresentation = inputString.slice(
1252
1340
  sourceOffset(inputString, this.source.start),
1253
1341
  sourceOffset(inputString, this.source.end)
@@ -1332,7 +1420,7 @@ function requireNode$1 () {
1332
1420
  line: opts.start.line,
1333
1421
  offset: sourceOffset(inputString, opts.start)
1334
1422
  };
1335
- } else if (opts.index) {
1423
+ } else if (typeof opts.index === 'number') {
1336
1424
  start = this.positionInside(opts.index);
1337
1425
  }
1338
1426
 
@@ -1344,7 +1432,7 @@ function requireNode$1 () {
1344
1432
  };
1345
1433
  } else if (typeof opts.endIndex === 'number') {
1346
1434
  end = this.positionInside(opts.endIndex);
1347
- } else if (opts.index) {
1435
+ } else if (typeof opts.index === 'number') {
1348
1436
  end = this.positionInside(opts.index + 1);
1349
1437
  }
1350
1438
  }
@@ -1408,47 +1496,68 @@ function requireNode$1 () {
1408
1496
  }
1409
1497
 
1410
1498
  toJSON(_, inputs) {
1411
- let fixed = {};
1412
1499
  let emitInputs = inputs == null;
1413
1500
  inputs = inputs || new Map();
1414
- let inputsNextIndex = 0;
1415
1501
 
1416
- for (let name in this) {
1417
- if (!Object.prototype.hasOwnProperty.call(this, name)) {
1418
- /* c8 ignore next 2 */
1419
- continue
1420
- }
1421
- if (name === 'parent' || name === 'proxyCache') continue
1422
- let value = this[name];
1502
+ // A worklist instead of recursive `toJSON()` calls to survive deeply
1503
+ // nested trees. Each entry converts one node and writes the result
1504
+ // into the already converted parent by [holder, key].
1505
+ let holderOfRoot = [];
1506
+ let queue = [[this, holderOfRoot, 0]];
1507
+
1508
+ for (let step = 0; step < queue.length; step++) {
1509
+ let [node, holder, key] = queue[step];
1510
+ let fixed = {};
1511
+ holder[key] = fixed;
1423
1512
 
1424
- if (Array.isArray(value)) {
1425
- fixed[name] = value.map(i => {
1426
- if (typeof i === 'object' && i.toJSON) {
1427
- return i.toJSON(null, inputs)
1513
+ for (let name in node) {
1514
+ if (!Object.prototype.hasOwnProperty.call(node, name)) {
1515
+ /* c8 ignore next 2 */
1516
+ continue
1517
+ }
1518
+ if (name === 'parent' || name === 'proxyCache') continue
1519
+ let value = node[name];
1520
+
1521
+ if (Array.isArray(value)) {
1522
+ let fixedArray = [];
1523
+ fixed[name] = fixedArray;
1524
+ for (let i = 0; i < value.length; i++) {
1525
+ let item = value[i];
1526
+ if (typeof item === 'object' && item.toJSON) {
1527
+ if (item.toJSON === Node.prototype.toJSON) {
1528
+ queue.push([item, fixedArray, i]);
1529
+ } else {
1530
+ fixedArray[i] = item.toJSON(null, inputs);
1531
+ }
1532
+ } else {
1533
+ fixedArray[i] = item;
1534
+ }
1535
+ }
1536
+ } else if (typeof value === 'object' && value.toJSON) {
1537
+ if (value.toJSON === Node.prototype.toJSON) {
1538
+ queue.push([value, fixed, name]);
1428
1539
  } else {
1429
- return i
1540
+ fixed[name] = value.toJSON(null, inputs);
1430
1541
  }
1431
- });
1432
- } else if (typeof value === 'object' && value.toJSON) {
1433
- fixed[name] = value.toJSON(null, inputs);
1434
- } else if (name === 'source') {
1435
- if (value == null) continue
1436
- let inputId = inputs.get(value.input);
1437
- if (inputId == null) {
1438
- inputId = inputsNextIndex;
1439
- inputs.set(value.input, inputsNextIndex);
1440
- inputsNextIndex++;
1542
+ } else if (name === 'source') {
1543
+ if (value == null) continue
1544
+ let inputId = inputs.get(value.input);
1545
+ if (inputId == null) {
1546
+ inputId = inputs.size;
1547
+ inputs.set(value.input, inputId);
1548
+ }
1549
+ fixed[name] = {
1550
+ end: value.end,
1551
+ inputId,
1552
+ start: value.start
1553
+ };
1554
+ } else {
1555
+ fixed[name] = value;
1441
1556
  }
1442
- fixed[name] = {
1443
- end: value.end,
1444
- inputId,
1445
- start: value.start
1446
- };
1447
- } else {
1448
- fixed[name] = value;
1449
1557
  }
1450
1558
  }
1451
1559
 
1560
+ let fixed = holderOfRoot[0];
1452
1561
  if (emitInputs) {
1453
1562
  fixed.inputs = [...inputs.keys()].map(input => input.toJSON());
1454
1563
  }
@@ -1552,18 +1661,25 @@ function requireContainer$1 () {
1552
1661
  let AtRule, parse, Root, Rule;
1553
1662
 
1554
1663
  function cleanSource(nodes) {
1555
- return nodes.map(i => {
1556
- if (i.nodes) i.nodes = cleanSource(i.nodes);
1557
- delete i.source;
1558
- return i
1559
- })
1664
+ let stack = nodes.slice();
1665
+ while (stack.length > 0) {
1666
+ let node = stack.pop();
1667
+ delete node.source;
1668
+ if (node.nodes) {
1669
+ node.nodes = node.nodes.slice();
1670
+ for (let i of node.nodes) stack.push(i);
1671
+ }
1672
+ }
1673
+ return nodes.slice()
1560
1674
  }
1561
1675
 
1562
1676
  function markTreeDirty(node) {
1563
- node[isClean] = false;
1564
- if (node.proxyOf.nodes) {
1565
- for (let i of node.proxyOf.nodes) {
1566
- markTreeDirty(i);
1677
+ let stack = [node];
1678
+ while (stack.length > 0) {
1679
+ let next = stack.pop();
1680
+ next[isClean] = false;
1681
+ if (next.proxyOf.nodes) {
1682
+ for (let i of next.proxyOf.nodes) stack.push(i);
1567
1683
  }
1568
1684
  }
1569
1685
  }
@@ -1591,9 +1707,18 @@ function requireContainer$1 () {
1591
1707
  }
1592
1708
 
1593
1709
  cleanRaws(keepBetween) {
1594
- super.cleanRaws(keepBetween);
1595
- if (this.nodes) {
1596
- for (let node of this.nodes) node.cleanRaws(keepBetween);
1710
+ let stack = [this];
1711
+ while (stack.length > 0) {
1712
+ let node = stack.pop();
1713
+ if (node !== this && node.cleanRaws !== Container.prototype.cleanRaws) {
1714
+ // Subclass with own logic; let it handle its subtree
1715
+ node.cleanRaws(keepBetween);
1716
+ continue
1717
+ }
1718
+ Node.prototype.cleanRaws.call(node, keepBetween);
1719
+ if (node.nodes) {
1720
+ for (let child of node.nodes) stack.push(child);
1721
+ }
1597
1722
  }
1598
1723
  }
1599
1724
 
@@ -1853,19 +1978,48 @@ function requireContainer$1 () {
1853
1978
  }
1854
1979
 
1855
1980
  walk(callback) {
1856
- return this.each((child, i) => {
1981
+ if (!this.proxyOf.nodes) return undefined
1982
+
1983
+ // An explicit stack instead of recursive `each()` calls to survive
1984
+ // deeply nested trees. Each frame keeps a live `indexes` slot, so
1985
+ // insertion and removal during the walk behave like `each()`: the
1986
+ // slot stays at the current child until its subtree is finished.
1987
+ let stack = [{ iterator: this.getIterator(), node: this.proxyOf }];
1988
+
1989
+ while (stack.length > 0) {
1990
+ let { iterator, node } = stack[stack.length - 1];
1991
+ let index = node.indexes[iterator];
1992
+
1993
+ if (index >= node.proxyOf.nodes.length) {
1994
+ delete node.indexes[iterator];
1995
+ stack.pop();
1996
+ let parent = stack[stack.length - 1];
1997
+ // Finish the parent’s step for the child subtree we just left
1998
+ if (parent) parent.node.indexes[parent.iterator] += 1;
1999
+ continue
2000
+ }
2001
+
2002
+ let child = node.proxyOf.nodes[index];
1857
2003
  let result;
1858
2004
  try {
1859
- result = callback(child, i);
2005
+ result = callback(child, index);
1860
2006
  } catch (e) {
1861
2007
  throw child.addToError(e)
1862
2008
  }
1863
- if (result !== false && child.walk) {
1864
- result = child.walk(callback);
2009
+ if (result === false) {
2010
+ for (let opened of stack) {
2011
+ delete opened.node.indexes[opened.iterator];
2012
+ }
2013
+ return false
2014
+ }
2015
+ if (child.walk && child.proxyOf.nodes) {
2016
+ stack.push({ iterator: child.getIterator(), node: child });
2017
+ } else {
2018
+ node.indexes[iterator] += 1;
1865
2019
  }
2020
+ }
1866
2021
 
1867
- return result
1868
- })
2022
+ return undefined
1869
2023
  }
1870
2024
 
1871
2025
  walkAtRules(name, callback) {
@@ -1968,24 +2122,26 @@ function requireContainer$1 () {
1968
2122
 
1969
2123
  /* c8 ignore start */
1970
2124
  Container.rebuild = node => {
1971
- if (node.type === 'atrule') {
1972
- Object.setPrototypeOf(node, AtRule.prototype);
1973
- } else if (node.type === 'rule') {
1974
- Object.setPrototypeOf(node, Rule.prototype);
1975
- } else if (node.type === 'decl') {
1976
- Object.setPrototypeOf(node, Declaration.prototype);
1977
- } else if (node.type === 'comment') {
1978
- Object.setPrototypeOf(node, Comment.prototype);
1979
- } else if (node.type === 'root') {
1980
- Object.setPrototypeOf(node, Root.prototype);
1981
- }
2125
+ let stack = [node];
2126
+ while (stack.length > 0) {
2127
+ let next = stack.pop();
2128
+ if (next.type === 'atrule') {
2129
+ Object.setPrototypeOf(next, AtRule.prototype);
2130
+ } else if (next.type === 'rule') {
2131
+ Object.setPrototypeOf(next, Rule.prototype);
2132
+ } else if (next.type === 'decl') {
2133
+ Object.setPrototypeOf(next, Declaration.prototype);
2134
+ } else if (next.type === 'comment') {
2135
+ Object.setPrototypeOf(next, Comment.prototype);
2136
+ } else if (next.type === 'root') {
2137
+ Object.setPrototypeOf(next, Root.prototype);
2138
+ }
1982
2139
 
1983
- node[my] = true;
2140
+ next[my] = true;
1984
2141
 
1985
- if (node.nodes) {
1986
- node.nodes.forEach(child => {
1987
- Container.rebuild(child);
1988
- });
2142
+ if (next.nodes) {
2143
+ for (let child of next.nodes) stack.push(child);
2144
+ }
1989
2145
  }
1990
2146
  };
1991
2147
  /* c8 ignore stop */
@@ -2072,22 +2228,14 @@ var hasRequiredNonSecure;
2072
2228
  function requireNonSecure () {
2073
2229
  if (hasRequiredNonSecure) return nonSecure;
2074
2230
  hasRequiredNonSecure = 1;
2075
- // This alphabet uses `A-Za-z0-9_-` symbols.
2076
- // The order of characters is optimized for better gzip and brotli compression.
2077
- // References to the same file (works both for gzip and brotli):
2078
- // `'use`, `andom`, and `rict'`
2079
- // References to the brotli default dictionary:
2080
- // `-26T`, `1983`, `40px`, `75px`, `bush`, `jack`, `mind`, `very`, and `wolf`
2081
2231
  let urlAlphabet =
2082
2232
  'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict';
2083
2233
 
2084
2234
  let customAlphabet = (alphabet, defaultSize = 21) => {
2085
2235
  return (size = defaultSize) => {
2086
2236
  let id = '';
2087
- // A compact alternative for `for (var i = 0; i < step; i++)`.
2088
2237
  let i = size | 0;
2089
- while (i--) {
2090
- // `| 0` is more compact and faster than `Math.floor()`.
2238
+ while (i-- > 0) {
2091
2239
  id += alphabet[(Math.random() * alphabet.length) | 0];
2092
2240
  }
2093
2241
  return id
@@ -2096,10 +2244,8 @@ function requireNonSecure () {
2096
2244
 
2097
2245
  let nanoid = (size = 21) => {
2098
2246
  let id = '';
2099
- // A compact alternative for `for (var i = 0; i < step; i++)`.
2100
2247
  let i = size | 0;
2101
- while (i--) {
2102
- // `| 0` is more compact and faster than `Math.floor()`.
2248
+ while (i-- > 0) {
2103
2249
  id += urlAlphabet[(Math.random() * 64) | 0];
2104
2250
  }
2105
2251
  return id
@@ -2117,7 +2263,7 @@ function requirePreviousMap () {
2117
2263
  hasRequiredPreviousMap = 1;
2118
2264
 
2119
2265
  let { existsSync, readFileSync } = require$$2;
2120
- let { dirname, join } = require$$2;
2266
+ let { dirname, isAbsolute, join, relative, sep } = require$$2;
2121
2267
  let { SourceMapConsumer, SourceMapGenerator } = require$$2;
2122
2268
 
2123
2269
  function fromBase64(str) {
@@ -2201,9 +2347,12 @@ function requirePreviousMap () {
2201
2347
  }
2202
2348
 
2203
2349
  loadFile(path, cssFile, trusted) {
2204
- /* c8 ignore next 5 */
2205
2350
  if (!trusted && !this.unsafeMap) {
2206
- if (!/\.map$/i.test(path)) {
2351
+ if (!/\.map$/i.test(path)) return undefined
2352
+ if (!cssFile) return undefined
2353
+
2354
+ let rel = relative(dirname(cssFile), path);
2355
+ if (rel === '..' || rel.startsWith('..' + sep) || isAbsolute(rel)) {
2207
2356
  return undefined
2208
2357
  }
2209
2358
  }
@@ -2491,12 +2640,21 @@ function requireInput () {
2491
2640
  if (!this.map) return false
2492
2641
  let consumer = this.map.consumer();
2493
2642
 
2494
- let from = consumer.originalPositionFor({ column, line });
2643
+ let from = consumer.originalPositionFor({ column: column - 1, line });
2495
2644
  if (!from.source) return false
2496
2645
 
2497
2646
  let to;
2498
2647
  if (typeof endLine === 'number') {
2499
- to = consumer.originalPositionFor({ column: endColumn, line: endLine });
2648
+ let toPosition = consumer.originalPositionFor({
2649
+ column: endColumn - 1,
2650
+ line: endLine
2651
+ });
2652
+ // The source map may not have a mapping that covers the end position
2653
+ // (`originalPositionFor()` then returns `null` for `line`/`column`
2654
+ // instead of omitting them). Treat that the same as not requesting
2655
+ // an end position at all, so `endLine`/`endColumn` stay a consistent
2656
+ // `undefined` pair instead of a mix of `null` and a bogus number.
2657
+ if (toPosition.source) to = toPosition;
2500
2658
  }
2501
2659
 
2502
2660
  let fromUrl;
@@ -2511,8 +2669,8 @@ function requireInput () {
2511
2669
  }
2512
2670
 
2513
2671
  let result = {
2514
- column: from.column,
2515
- endColumn: to && to.column,
2672
+ column: from.column + 1,
2673
+ endColumn: to && to.column + 1,
2516
2674
  endLine: to && to.line,
2517
2675
  line: from.line,
2518
2676
  url: fromUrl.toString()
@@ -2578,6 +2736,19 @@ function requireRoot () {
2578
2736
  }
2579
2737
 
2580
2738
  normalize(child, sample, type) {
2739
+ let keepBefore = new Set();
2740
+ for (let node of Array.isArray(child) ? child : [child]) {
2741
+ if (
2742
+ node &&
2743
+ typeof node === 'object' &&
2744
+ !node.parent &&
2745
+ node.raws &&
2746
+ typeof node.raws.before !== 'undefined'
2747
+ ) {
2748
+ keepBefore.add(node.raws);
2749
+ }
2750
+ }
2751
+
2581
2752
  let nodes = super.normalize(child);
2582
2753
 
2583
2754
  if (sample) {
@@ -2589,7 +2760,9 @@ function requireRoot () {
2589
2760
  }
2590
2761
  } else if (this.first !== sample) {
2591
2762
  for (let node of nodes) {
2592
- node.raws.before = sample.raws.before;
2763
+ if (!keepBefore.has(node.raws)) {
2764
+ node.raws.before = sample.raws.before;
2765
+ }
2593
2766
  }
2594
2767
  }
2595
2768
  }
@@ -2744,26 +2917,24 @@ function requireFromJSON () {
2744
2917
  let Root = requireRoot();
2745
2918
  let Rule = requireRule();
2746
2919
 
2747
- function fromJSON(json, inputs) {
2748
- if (Array.isArray(json)) return json.map(n => fromJSON(n))
2749
-
2750
- let { inputs: ownInputs, ...defaults } = json;
2751
- if (ownInputs) {
2752
- inputs = [];
2753
- for (let input of ownInputs) {
2754
- let inputHydrated = { ...input, __proto__: Input.prototype };
2755
- if (inputHydrated.map) {
2756
- inputHydrated.map = {
2757
- ...inputHydrated.map,
2758
- __proto__: PreviousMap.prototype
2759
- };
2760
- }
2761
- inputs.push(inputHydrated);
2920
+ function hydrateInputs(json, inputs) {
2921
+ if (!json.inputs) return inputs
2922
+ return json.inputs.map(input => {
2923
+ let inputHydrated = { ...input, __proto__: Input.prototype };
2924
+ if (inputHydrated.map) {
2925
+ inputHydrated.map = {
2926
+ ...inputHydrated.map,
2927
+ __proto__: PreviousMap.prototype
2928
+ };
2762
2929
  }
2763
- }
2764
- if (defaults.nodes) {
2765
- defaults.nodes = json.nodes.map(n => fromJSON(n, inputs));
2766
- }
2930
+ return inputHydrated
2931
+ })
2932
+ }
2933
+
2934
+ function constructNode(json, inputs, children) {
2935
+ let defaults = { ...json };
2936
+ delete defaults.inputs;
2937
+ delete defaults.nodes;
2767
2938
  if (defaults.source) {
2768
2939
  let { inputId, ...source } = defaults.source;
2769
2940
  defaults.source = source;
@@ -2771,19 +2942,74 @@ function requireFromJSON () {
2771
2942
  defaults.source.input = inputs[inputId];
2772
2943
  }
2773
2944
  }
2945
+
2946
+ let node;
2774
2947
  if (defaults.type === 'root') {
2775
- return new Root(defaults)
2948
+ node = new Root(defaults);
2776
2949
  } else if (defaults.type === 'decl') {
2777
- return new Declaration(defaults)
2950
+ node = new Declaration(defaults);
2778
2951
  } else if (defaults.type === 'rule') {
2779
- return new Rule(defaults)
2952
+ node = new Rule(defaults);
2780
2953
  } else if (defaults.type === 'comment') {
2781
- return new Comment(defaults)
2954
+ node = new Comment(defaults);
2782
2955
  } else if (defaults.type === 'atrule') {
2783
- return new AtRule(defaults)
2956
+ node = new AtRule(defaults);
2784
2957
  } else {
2785
2958
  throw new Error('Unknown node type: ' + json.type)
2786
2959
  }
2960
+
2961
+ // Rehydrated children are attached after construction. Passing them
2962
+ // through the container constructor would re-run insertion spacing
2963
+ // normalization and overwrite each child's own `raws.before`.
2964
+ if (children) {
2965
+ node.nodes = children;
2966
+ for (let child of children) child.parent = node;
2967
+ }
2968
+
2969
+ return node
2970
+ }
2971
+
2972
+ function fromJSON(json, inputs) {
2973
+ if (Array.isArray(json)) return json.map(n => fromJSON(n))
2974
+
2975
+ // An explicit stack instead of recursive calls to survive deeply
2976
+ // nested trees. Children are rehydrated before their parent node
2977
+ // is constructed.
2978
+ let result;
2979
+ let stack = [
2980
+ { childIndex: 0, children: [], inputs: hydrateInputs(json, inputs), json }
2981
+ ];
2982
+
2983
+ while (stack.length > 0) {
2984
+ let frame = stack[stack.length - 1];
2985
+ let jsonNodes = frame.json.nodes;
2986
+
2987
+ if (jsonNodes && frame.childIndex < jsonNodes.length) {
2988
+ let childJson = jsonNodes[frame.childIndex];
2989
+ frame.childIndex += 1;
2990
+ stack.push({
2991
+ childIndex: 0,
2992
+ children: [],
2993
+ inputs: hydrateInputs(childJson, frame.inputs),
2994
+ json: childJson
2995
+ });
2996
+ continue
2997
+ }
2998
+
2999
+ stack.pop();
3000
+ let node = constructNode(
3001
+ frame.json,
3002
+ frame.inputs,
3003
+ jsonNodes ? frame.children : undefined
3004
+ );
3005
+ if (stack.length > 0) {
3006
+ stack[stack.length - 1].children.push(node);
3007
+ } else {
3008
+ result = node;
3009
+ }
3010
+ }
3011
+
3012
+ return result
2787
3013
  }
2788
3014
 
2789
3015
  fromJSON_1 = fromJSON;
@@ -3480,6 +3706,12 @@ function requireParser () {
3480
3706
  }
3481
3707
  }
3482
3708
 
3709
+ function tokensToString(tokens, from, to) {
3710
+ let result = '';
3711
+ for (let i = from; i < to; i++) result += tokens[i][1];
3712
+ return result
3713
+ }
3714
+
3483
3715
  class Parser {
3484
3716
  constructor(input) {
3485
3717
  this.input = input;
@@ -3592,9 +3824,10 @@ function requireParser () {
3592
3824
  if (founded === 2) break
3593
3825
  }
3594
3826
  }
3595
- // If the token is a word, e.g. `!important`, `red` or any other valid property's value.
3596
- // Then we need to return the colon after that word token. [3] is the "end" colon of that word.
3597
- // And because we need it after that one we do +1 to get the next one.
3827
+ // If the token is a word, e.g. `!important`, `red` or any other valid
3828
+ // property's value. Then we need to return the colon after that word
3829
+ // token. [3] is the "end" colon of that word. And because we need it
3830
+ // after that one we do +1 to get the next one.
3598
3831
  throw this.input.error(
3599
3832
  'Missed semicolon',
3600
3833
  token[0] === 'word' ? token[3] + 1 : token[2]
@@ -3667,50 +3900,50 @@ function requireParser () {
3667
3900
  );
3668
3901
  node.source.end.offset++;
3669
3902
 
3670
- while (tokens[0][0] !== 'word') {
3671
- if (tokens.length === 1) this.unknownWord(tokens);
3672
- node.raws.before += tokens.shift()[1];
3903
+ let start = 0;
3904
+ while (tokens[start][0] !== 'word') {
3905
+ if (start === tokens.length - 1) this.unknownWord([tokens[start]]);
3906
+ start++;
3673
3907
  }
3674
- node.source.start = this.getPosition(tokens[0][2]);
3908
+ node.raws.before += tokensToString(tokens, 0, start);
3909
+ node.source.start = this.getPosition(tokens[start][2]);
3675
3910
 
3676
- node.prop = '';
3677
- while (tokens.length) {
3678
- let type = tokens[0][0];
3911
+ let propStart = start;
3912
+ while (start < tokens.length) {
3913
+ let type = tokens[start][0];
3679
3914
  if (type === ':' || type === 'space' || type === 'comment') {
3680
3915
  break
3681
3916
  }
3682
- node.prop += tokens.shift()[1];
3917
+ start++;
3683
3918
  }
3919
+ node.prop = tokensToString(tokens, propStart, start);
3684
3920
 
3685
- node.raws.between = '';
3686
-
3921
+ let betweenStart = start;
3687
3922
  let token;
3688
- while (tokens.length) {
3689
- token = tokens.shift();
3690
-
3691
- if (token[0] === ':') {
3692
- node.raws.between += token[1];
3693
- break
3694
- } else {
3695
- if (token[0] === 'word' && /\w/.test(token[1])) {
3696
- this.unknownWord([token]);
3697
- }
3698
- node.raws.between += token[1];
3923
+ while (start < tokens.length) {
3924
+ token = tokens[start];
3925
+ start++;
3926
+ if (token[0] === ':') break
3927
+ if (token[0] === 'word' && /\w/.test(token[1])) {
3928
+ this.unknownWord([token]);
3699
3929
  }
3700
3930
  }
3931
+ node.raws.between = tokensToString(tokens, betweenStart, start);
3701
3932
 
3702
3933
  if (node.prop[0] === '_' || node.prop[0] === '*') {
3703
3934
  node.raws.before += node.prop[0];
3704
3935
  node.prop = node.prop.slice(1);
3705
3936
  }
3706
3937
 
3707
- let firstSpaces = [];
3708
- let next;
3709
- while (tokens.length) {
3710
- next = tokens[0][0];
3938
+ let firstSpacesStart = start;
3939
+ while (start < tokens.length) {
3940
+ let next = tokens[start][0];
3711
3941
  if (next !== 'space' && next !== 'comment') break
3712
- firstSpaces.push(tokens.shift());
3942
+ start++;
3713
3943
  }
3944
+ let firstSpaces = tokens.slice(firstSpacesStart, start);
3945
+
3946
+ tokens = tokens.slice(start);
3714
3947
 
3715
3948
  this.precheckMissedSemicolon(tokens);
3716
3949
 
@@ -4129,12 +4362,22 @@ function requireWarning () {
4129
4362
  if (hasRequiredWarning) return warning;
4130
4363
  hasRequiredWarning = 1;
4131
4364
 
4365
+ let Container = requireContainer$1();
4366
+ let { my } = requireSymbols();
4367
+
4132
4368
  class Warning {
4133
4369
  constructor(text, opts = {}) {
4134
4370
  this.type = 'warning';
4135
4371
  this.text = text;
4136
4372
 
4137
4373
  if (opts.node && opts.node.source) {
4374
+ if (!opts.node[my]) {
4375
+ // The node comes from another PostCSS copy in node_modules, so it does
4376
+ // not have this copy’s methods. Container#normalize() rebuilds such
4377
+ // nodes on insert, but a node passed straight to Result#warn() never
4378
+ // goes through it.
4379
+ Container.rebuild(opts.node);
4380
+ }
4138
4381
  let range = opts.node.rangeBy(opts);
4139
4382
  this.line = range.start.line;
4140
4383
  this.column = range.start.column;
@@ -4343,8 +4586,14 @@ function requireLazyResult () {
4343
4586
  }
4344
4587
 
4345
4588
  function cleanMarks(node) {
4346
- node[isClean] = false;
4347
- if (node.nodes) node.nodes.forEach(i => cleanMarks(i));
4589
+ let stack = [node];
4590
+ while (stack.length > 0) {
4591
+ let next = stack.pop();
4592
+ next[isClean] = false;
4593
+ if (next.nodes) {
4594
+ for (let i of next.nodes) stack.push(i);
4595
+ }
4596
+ }
4348
4597
  return node
4349
4598
  }
4350
4599
 
@@ -4625,7 +4874,10 @@ function requireLazyResult () {
4625
4874
  if (str.stringify) str = str.stringify;
4626
4875
 
4627
4876
  let rootSource = this.result.root.source;
4628
- if (opts.map === undefined && !(rootSource && rootSource.input && rootSource.input.map)) {
4877
+ if (
4878
+ opts.map === undefined &&
4879
+ !(rootSource && rootSource.input && rootSource.input.map)
4880
+ ) {
4629
4881
  let result = '';
4630
4882
  str(this.result.root, i => {
4631
4883
  result += i;
@@ -4772,21 +5024,57 @@ function requireLazyResult () {
4772
5024
  }
4773
5025
 
4774
5026
  walkSync(node) {
5027
+ // An explicit stack like in async `visitTick()` to survive deeply
5028
+ // nested trees. Unlike `visitTick()`, nodes are marked clean only
5029
+ // on entering, so a node dirtied by its own visitors is revisited
5030
+ // on the next pass.
4775
5031
  node[isClean] = true;
4776
- let events = getEvents(node);
4777
- for (let event of events) {
4778
- if (event === CHILDREN) {
4779
- if (node.nodes) {
4780
- node.each(child => {
4781
- if (!child[isClean]) this.walkSync(child);
4782
- });
5032
+ let stack = [{ eventIndex: 0, events: getEvents(node), iterator: 0, node }];
5033
+
5034
+ while (stack.length > 0) {
5035
+ let visit = stack[stack.length - 1];
5036
+ let visitNode = visit.node;
5037
+
5038
+ if (visit.iterator !== 0) {
5039
+ let iterator = visit.iterator;
5040
+ let child;
5041
+ let descended = false;
5042
+ while ((child = visitNode.nodes[visitNode.indexes[iterator]])) {
5043
+ visitNode.indexes[iterator] += 1;
5044
+ if (!child[isClean]) {
5045
+ child[isClean] = true;
5046
+ stack.push({
5047
+ eventIndex: 0,
5048
+ events: getEvents(child),
5049
+ iterator: 0,
5050
+ node: child
5051
+ });
5052
+ descended = true;
5053
+ break
5054
+ }
4783
5055
  }
4784
- } else {
4785
- let visitors = this.listeners[event];
4786
- if (visitors) {
4787
- if (this.visitSync(visitors, node.toProxy())) return
5056
+ if (descended) continue
5057
+ visit.iterator = 0;
5058
+ delete visitNode.indexes[iterator];
5059
+ }
5060
+
5061
+ if (visit.eventIndex < visit.events.length) {
5062
+ let event = visit.events[visit.eventIndex];
5063
+ visit.eventIndex += 1;
5064
+ if (event === CHILDREN) {
5065
+ if (visitNode.nodes && visitNode.nodes.length) {
5066
+ visit.iterator = visitNode.getIterator();
5067
+ }
5068
+ } else {
5069
+ let visitors = this.listeners[event];
5070
+ if (visitors) {
5071
+ if (this.visitSync(visitors, visitNode.toProxy())) stack.pop();
5072
+ }
4788
5073
  }
5074
+ continue
4789
5075
  }
5076
+
5077
+ stack.pop();
4790
5078
  }
4791
5079
  }
4792
5080
 
@@ -4966,7 +5254,7 @@ function requireProcessor () {
4966
5254
 
4967
5255
  class Processor {
4968
5256
  constructor(plugins = []) {
4969
- this.version = '8.5.12';
5257
+ this.version = '8.5.23';
4970
5258
  this.plugins = this.normalize(plugins);
4971
5259
  }
4972
5260