@appsurify-testmap/rrdom 2.1.3-alpha.4 → 3.1.1-alpha.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.
@@ -1,16 +1,4 @@
1
- (function (g, f) {
2
- if ("object" == typeof exports && "object" == typeof module) {
3
- module.exports = f();
4
- } else if ("function" == typeof define && define.amd) {
5
- define("rrdom", [], f);
6
- } else if ("object" == typeof exports) {
7
- exports["rrdom"] = f();
8
- } else {
9
- g["rrdom"] = f();
10
- }
11
- }(this, () => {
12
- var exports = {};
13
- var module = { exports };
1
+ (function (g, f) {if ("object" == typeof exports && "object" == typeof module) {module.exports = f();} else if ("function" == typeof define && define.amd) {define("rrdom", [], f);} else if ("object" == typeof exports) {exports["rrdom"] = f();} else {g["rrdom"] = f();}}(typeof self !== 'undefined' ? self : typeof globalThis !== 'undefined' ? globalThis : this, () => {var exports = {};var module = { exports };
14
2
  "use strict";
15
3
  var __defProp = Object.defineProperty;
16
4
  var __defProps = Object.defineProperties;
@@ -54,6 +42,7 @@ let Mirror$1 = class Mirror {
54
42
  constructor() {
55
43
  __publicField2(this, "idNodeMap", /* @__PURE__ */ new Map());
56
44
  __publicField2(this, "nodeMetaMap", /* @__PURE__ */ new WeakMap());
45
+ __publicField2(this, "selectorNodeMap", /* @__PURE__ */ new Map());
57
46
  }
58
47
  getId(n) {
59
48
  var _a;
@@ -76,6 +65,16 @@ let Mirror$1 = class Mirror {
76
65
  removeNodeFromMap(n) {
77
66
  const id = this.getId(n);
78
67
  this.idNodeMap.delete(id);
68
+ const meta = this.getMeta(n);
69
+ if (meta == null ? void 0 : meta.selector) {
70
+ const nodes = this.selectorNodeMap.get(meta.selector);
71
+ if (nodes) {
72
+ nodes.delete(n);
73
+ if (nodes.size === 0) {
74
+ this.selectorNodeMap.delete(meta.selector);
75
+ }
76
+ }
77
+ }
79
78
  if (n.childNodes) {
80
79
  n.childNodes.forEach(
81
80
  (childNode) => this.removeNodeFromMap(childNode)
@@ -92,19 +91,50 @@ let Mirror$1 = class Mirror {
92
91
  const id = meta.id;
93
92
  this.idNodeMap.set(id, n);
94
93
  this.nodeMetaMap.set(n, meta);
94
+ if (meta.selector) {
95
+ let nodes = this.selectorNodeMap.get(meta.selector);
96
+ if (!nodes) {
97
+ nodes = /* @__PURE__ */ new Set();
98
+ this.selectorNodeMap.set(meta.selector, nodes);
99
+ }
100
+ nodes.add(n);
101
+ }
95
102
  }
96
103
  replace(id, n) {
97
104
  const oldNode = this.getNode(id);
98
105
  if (oldNode) {
99
106
  const meta = this.nodeMetaMap.get(oldNode);
100
- if (meta)
107
+ if (meta) {
101
108
  this.nodeMetaMap.set(n, meta);
109
+ if (meta.selector) {
110
+ const nodes = this.selectorNodeMap.get(meta.selector);
111
+ if (nodes) {
112
+ nodes.delete(oldNode);
113
+ nodes.add(n);
114
+ }
115
+ }
116
+ }
102
117
  }
103
118
  this.idNodeMap.set(id, n);
104
119
  }
105
120
  reset() {
106
121
  this.idNodeMap = /* @__PURE__ */ new Map();
107
122
  this.nodeMetaMap = /* @__PURE__ */ new WeakMap();
123
+ this.selectorNodeMap = /* @__PURE__ */ new Map();
124
+ }
125
+ getNodeBySelector(selector) {
126
+ const nodes = this.selectorNodeMap.get(selector);
127
+ if (!nodes || nodes.size === 0)
128
+ return null;
129
+ return nodes.values().next().value || null;
130
+ }
131
+ getNodesBySelector(selector) {
132
+ const nodes = this.selectorNodeMap.get(selector);
133
+ return nodes ? Array.from(nodes) : [];
134
+ }
135
+ hasSelector(selector) {
136
+ const nodes = this.selectorNodeMap.get(selector);
137
+ return nodes !== void 0 && nodes.size > 0;
108
138
  }
109
139
  };
110
140
  function createMirror$1() {
@@ -210,12 +240,12 @@ function getAugmentedNamespace(n) {
210
240
  } else
211
241
  a = {};
212
242
  Object.defineProperty(a, "__esModule", { value: true });
213
- Object.keys(n).forEach(function(k) {
214
- var d = Object.getOwnPropertyDescriptor(n, k);
215
- Object.defineProperty(a, k, d.get ? d : {
243
+ Object.keys(n).forEach(function(k2) {
244
+ var d = Object.getOwnPropertyDescriptor(n, k2);
245
+ Object.defineProperty(a, k2, d.get ? d : {
216
246
  enumerable: true,
217
247
  get: function() {
218
- return n[k];
248
+ return n[k2];
219
249
  }
220
250
  });
221
251
  });
@@ -224,7 +254,7 @@ function getAugmentedNamespace(n) {
224
254
  var picocolors_browser = { exports: {} };
225
255
  var x = String;
226
256
  var create = function() {
227
- return { isColorSupported: false, reset: x, bold: x, dim: x, italic: x, underline: x, inverse: x, hidden: x, strikethrough: x, black: x, red: x, green: x, yellow: x, blue: x, magenta: x, cyan: x, white: x, gray: x, bgBlack: x, bgRed: x, bgGreen: x, bgYellow: x, bgBlue: x, bgMagenta: x, bgCyan: x, bgWhite: x };
257
+ return { isColorSupported: false, reset: x, bold: x, dim: x, italic: x, underline: x, inverse: x, hidden: x, strikethrough: x, black: x, red: x, green: x, yellow: x, blue: x, magenta: x, cyan: x, white: x, gray: x, bgBlack: x, bgRed: x, bgGreen: x, bgYellow: x, bgBlue: x, bgMagenta: x, bgCyan: x, bgWhite: x, blackBright: x, redBright: x, greenBright: x, yellowBright: x, blueBright: x, magentaBright: x, cyanBright: x, whiteBright: x, bgBlackBright: x, bgRedBright: x, bgGreenBright: x, bgYellowBright: x, bgBlueBright: x, bgMagentaBright: x, bgCyanBright: x, bgWhiteBright: x };
228
258
  };
229
259
  picocolors_browser.exports = create();
230
260
  picocolors_browser.exports.createColors = create;
@@ -281,30 +311,40 @@ let CssSyntaxError$3 = class CssSyntaxError extends Error {
281
311
  let css = this.source;
282
312
  if (color == null)
283
313
  color = pico.isColorSupported;
284
- if (terminalHighlight$1) {
285
- if (color)
286
- css = terminalHighlight$1(css);
287
- }
288
- let lines = css.split(/\r?\n/);
289
- let start = Math.max(this.line - 3, 0);
290
- let end = Math.min(this.line + 2, lines.length);
291
- let maxWidth = String(end).length;
292
- let mark, aside;
314
+ let aside = (text) => text;
315
+ let mark = (text) => text;
316
+ let highlight = (text) => text;
293
317
  if (color) {
294
318
  let { bold, gray, red } = pico.createColors(true);
295
319
  mark = (text) => bold(red(text));
296
320
  aside = (text) => gray(text);
297
- } else {
298
- mark = aside = (str) => str;
321
+ if (terminalHighlight$1) {
322
+ highlight = (text) => terminalHighlight$1(text);
323
+ }
299
324
  }
325
+ let lines = css.split(/\r?\n/);
326
+ let start = Math.max(this.line - 3, 0);
327
+ let end = Math.min(this.line + 2, lines.length);
328
+ let maxWidth = String(end).length;
300
329
  return lines.slice(start, end).map((line, index2) => {
301
330
  let number = start + 1 + index2;
302
331
  let gutter = " " + (" " + number).slice(-maxWidth) + " | ";
303
332
  if (number === this.line) {
333
+ if (line.length > 160) {
334
+ let padding = 20;
335
+ let subLineStart = Math.max(0, this.column - padding);
336
+ let subLineEnd = Math.max(
337
+ this.column + padding,
338
+ this.endColumn + padding
339
+ );
340
+ let subLine = line.slice(subLineStart, subLineEnd);
341
+ let spacing2 = aside(gutter.replace(/\d/g, " ")) + line.slice(0, Math.min(this.column - 1, padding - 1)).replace(/[^\t]/g, " ");
342
+ return mark(">") + aside(gutter) + highlight(subLine) + "\n " + spacing2 + mark("^");
343
+ }
304
344
  let spacing = aside(gutter.replace(/\d/g, " ")) + line.slice(0, this.column - 1).replace(/[^\t]/g, " ");
305
- return mark(">") + aside(gutter) + line + "\n " + spacing + mark("^");
345
+ return mark(">") + aside(gutter) + highlight(line) + "\n " + spacing + mark("^");
306
346
  }
307
- return " " + aside(gutter) + line;
347
+ return " " + aside(gutter) + highlight(line);
308
348
  }).join("\n");
309
349
  }
310
350
  toString() {
@@ -317,9 +357,6 @@ let CssSyntaxError$3 = class CssSyntaxError extends Error {
317
357
  };
318
358
  var cssSyntaxError = CssSyntaxError$3;
319
359
  CssSyntaxError$3.default = CssSyntaxError$3;
320
- var symbols = {};
321
- symbols.isClean = Symbol("isClean");
322
- symbols.my = Symbol("my");
323
360
  const DEFAULT_RAW = {
324
361
  after: "\n",
325
362
  beforeClose: "\n",
@@ -642,10 +679,13 @@ function stringify$4(node2, builder) {
642
679
  }
643
680
  var stringify_1 = stringify$4;
644
681
  stringify$4.default = stringify$4;
645
- let { isClean: isClean$2, my: my$2 } = symbols;
682
+ var symbols = {};
683
+ symbols.isClean = Symbol("isClean");
684
+ symbols.my = Symbol("my");
646
685
  let CssSyntaxError$2 = cssSyntaxError;
647
686
  let Stringifier2 = stringifier;
648
687
  let stringify$3 = stringify_1;
688
+ let { isClean: isClean$2, my: my$2 } = symbols;
649
689
  function cloneNode(obj, parent) {
650
690
  let cloned = new obj.constructor();
651
691
  for (let i in obj) {
@@ -662,7 +702,7 @@ function cloneNode(obj, parent) {
662
702
  } else if (i === "source") {
663
703
  cloned[i] = value;
664
704
  } else if (Array.isArray(value)) {
665
- cloned[i] = value.map((j) => cloneNode(j, cloned));
705
+ cloned[i] = value.map((j2) => cloneNode(j2, cloned));
666
706
  } else {
667
707
  if (type === "object" && value !== null)
668
708
  value = cloneNode(value);
@@ -671,7 +711,31 @@ function cloneNode(obj, parent) {
671
711
  }
672
712
  return cloned;
673
713
  }
714
+ function sourceOffset(inputCSS, position) {
715
+ if (position && typeof position.offset !== "undefined") {
716
+ return position.offset;
717
+ }
718
+ let column = 1;
719
+ let line = 1;
720
+ let offset = 0;
721
+ for (let i = 0; i < inputCSS.length; i++) {
722
+ if (line === position.line && column === position.column) {
723
+ offset = i;
724
+ break;
725
+ }
726
+ if (inputCSS[i] === "\n") {
727
+ column = 1;
728
+ line += 1;
729
+ } else {
730
+ column += 1;
731
+ }
732
+ }
733
+ return offset;
734
+ }
674
735
  let Node$5 = class Node2 {
736
+ get proxyOf() {
737
+ return this;
738
+ }
675
739
  constructor(defaults = {}) {
676
740
  this.raws = {};
677
741
  this[isClean$2] = false;
@@ -774,6 +838,10 @@ let Node$5 = class Node2 {
774
838
  }
775
839
  };
776
840
  }
841
+ /* c8 ignore next 3 */
842
+ markClean() {
843
+ this[isClean$2] = true;
844
+ }
777
845
  markDirty() {
778
846
  if (this[isClean$2]) {
779
847
  this[isClean$2] = false;
@@ -789,31 +857,37 @@ let Node$5 = class Node2 {
789
857
  let index2 = this.parent.index(this);
790
858
  return this.parent.nodes[index2 + 1];
791
859
  }
792
- positionBy(opts, stringRepresentation) {
860
+ positionBy(opts = {}) {
793
861
  let pos = this.source.start;
794
862
  if (opts.index) {
795
- pos = this.positionInside(opts.index, stringRepresentation);
863
+ pos = this.positionInside(opts.index);
796
864
  } else if (opts.word) {
797
- stringRepresentation = this.toString();
865
+ let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
866
+ let stringRepresentation = inputString.slice(
867
+ sourceOffset(inputString, this.source.start),
868
+ sourceOffset(inputString, this.source.end)
869
+ );
798
870
  let index2 = stringRepresentation.indexOf(opts.word);
799
871
  if (index2 !== -1)
800
- pos = this.positionInside(index2, stringRepresentation);
872
+ pos = this.positionInside(index2);
801
873
  }
802
874
  return pos;
803
875
  }
804
- positionInside(index2, stringRepresentation) {
805
- let string = stringRepresentation || this.toString();
876
+ positionInside(index2) {
806
877
  let column = this.source.start.column;
807
878
  let line = this.source.start.line;
808
- for (let i = 0; i < index2; i++) {
809
- if (string[i] === "\n") {
879
+ let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
880
+ let offset = sourceOffset(inputString, this.source.start);
881
+ let end = offset + index2;
882
+ for (let i = offset; i < end; i++) {
883
+ if (inputString[i] === "\n") {
810
884
  column = 1;
811
885
  line += 1;
812
886
  } else {
813
887
  column += 1;
814
888
  }
815
889
  }
816
- return { column, line };
890
+ return { column, line, offset: end };
817
891
  }
818
892
  prev() {
819
893
  if (!this.parent)
@@ -821,30 +895,46 @@ let Node$5 = class Node2 {
821
895
  let index2 = this.parent.index(this);
822
896
  return this.parent.nodes[index2 - 1];
823
897
  }
824
- rangeBy(opts) {
898
+ rangeBy(opts = {}) {
899
+ let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
825
900
  let start = {
826
901
  column: this.source.start.column,
827
- line: this.source.start.line
902
+ line: this.source.start.line,
903
+ offset: sourceOffset(inputString, this.source.start)
828
904
  };
829
905
  let end = this.source.end ? {
830
906
  column: this.source.end.column + 1,
831
- line: this.source.end.line
907
+ line: this.source.end.line,
908
+ offset: typeof this.source.end.offset === "number" ? (
909
+ // `source.end.offset` is exclusive, so we don't need to add 1
910
+ this.source.end.offset
911
+ ) : (
912
+ // Since line/column in this.source.end is inclusive,
913
+ // the `sourceOffset(... , this.source.end)` returns an inclusive offset.
914
+ // So, we add 1 to convert it to exclusive.
915
+ sourceOffset(inputString, this.source.end) + 1
916
+ )
832
917
  } : {
833
918
  column: start.column + 1,
834
- line: start.line
919
+ line: start.line,
920
+ offset: start.offset + 1
835
921
  };
836
922
  if (opts.word) {
837
- let stringRepresentation = this.toString();
923
+ let stringRepresentation = inputString.slice(
924
+ sourceOffset(inputString, this.source.start),
925
+ sourceOffset(inputString, this.source.end)
926
+ );
838
927
  let index2 = stringRepresentation.indexOf(opts.word);
839
928
  if (index2 !== -1) {
840
- start = this.positionInside(index2, stringRepresentation);
841
- end = this.positionInside(index2 + opts.word.length, stringRepresentation);
929
+ start = this.positionInside(index2);
930
+ end = this.positionInside(index2 + opts.word.length);
842
931
  }
843
932
  } else {
844
933
  if (opts.start) {
845
934
  start = {
846
935
  column: opts.start.column,
847
- line: opts.start.line
936
+ line: opts.start.line,
937
+ offset: sourceOffset(inputString, opts.start)
848
938
  };
849
939
  } else if (opts.index) {
850
940
  start = this.positionInside(opts.index);
@@ -852,7 +942,8 @@ let Node$5 = class Node2 {
852
942
  if (opts.end) {
853
943
  end = {
854
944
  column: opts.end.column,
855
- line: opts.end.line
945
+ line: opts.end.line,
946
+ offset: sourceOffset(inputString, opts.end)
856
947
  };
857
948
  } else if (typeof opts.endIndex === "number") {
858
949
  end = this.positionInside(opts.endIndex);
@@ -861,7 +952,11 @@ let Node$5 = class Node2 {
861
952
  }
862
953
  }
863
954
  if (end.line < start.line || end.line === start.line && end.column <= start.column) {
864
- end = { column: start.column + 1, line: start.line };
955
+ end = {
956
+ column: start.column + 1,
957
+ line: start.line,
958
+ offset: start.offset + 1
959
+ };
865
960
  }
866
961
  return { end, start };
867
962
  }
@@ -903,7 +998,7 @@ let Node$5 = class Node2 {
903
998
  }
904
999
  return result2;
905
1000
  }
906
- toJSON(_, inputs) {
1001
+ toJSON(_2, inputs) {
907
1002
  let fixed = {};
908
1003
  let emitInputs = inputs == null;
909
1004
  inputs = inputs || /* @__PURE__ */ new Map();
@@ -926,6 +1021,8 @@ let Node$5 = class Node2 {
926
1021
  } else if (typeof value === "object" && value.toJSON) {
927
1022
  fixed[name] = value.toJSON(null, inputs);
928
1023
  } else if (name === "source") {
1024
+ if (value == null)
1025
+ continue;
929
1026
  let inputId = inputs.get(value.input);
930
1027
  if (inputId == null) {
931
1028
  inputId = inputsNextIndex;
@@ -961,20 +1058,29 @@ let Node$5 = class Node2 {
961
1058
  });
962
1059
  return result2;
963
1060
  }
964
- warn(result2, text, opts) {
1061
+ warn(result2, text, opts = {}) {
965
1062
  let data = { node: this };
966
1063
  for (let i in opts)
967
1064
  data[i] = opts[i];
968
1065
  return result2.warn(text, data);
969
1066
  }
970
- get proxyOf() {
971
- return this;
972
- }
973
1067
  };
974
1068
  var node = Node$5;
975
1069
  Node$5.default = Node$5;
976
1070
  let Node$4 = node;
977
- let Declaration$4 = class Declaration extends Node$4 {
1071
+ let Comment$4 = class Comment extends Node$4 {
1072
+ constructor(defaults) {
1073
+ super(defaults);
1074
+ this.type = "comment";
1075
+ }
1076
+ };
1077
+ var comment = Comment$4;
1078
+ Comment$4.default = Comment$4;
1079
+ let Node$3 = node;
1080
+ let Declaration$4 = class Declaration extends Node$3 {
1081
+ get variable() {
1082
+ return this.prop.startsWith("--") || this.prop[0] === "$";
1083
+ }
978
1084
  constructor(defaults) {
979
1085
  if (defaults && typeof defaults.value !== "undefined" && typeof defaults.value !== "string") {
980
1086
  defaults = __spreadProps(__spreadValues({}, defaults), { value: String(defaults.value) });
@@ -982,1179 +1088,1301 @@ let Declaration$4 = class Declaration extends Node$4 {
982
1088
  super(defaults);
983
1089
  this.type = "decl";
984
1090
  }
985
- get variable() {
986
- return this.prop.startsWith("--") || this.prop[0] === "$";
987
- }
988
1091
  };
989
1092
  var declaration = Declaration$4;
990
1093
  Declaration$4.default = Declaration$4;
991
- let urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
992
- let customAlphabet = (alphabet, defaultSize = 21) => {
993
- return (size = defaultSize) => {
994
- let id = "";
995
- let i = size;
996
- while (i--) {
997
- id += alphabet[Math.random() * alphabet.length | 0];
998
- }
999
- return id;
1000
- };
1001
- };
1002
- let nanoid$1 = (size = 21) => {
1003
- let id = "";
1004
- let i = size;
1005
- while (i--) {
1006
- id += urlAlphabet[Math.random() * 64 | 0];
1007
- }
1008
- return id;
1009
- };
1010
- var nonSecure = { nanoid: nanoid$1, customAlphabet };
1011
- let { SourceMapConsumer: SourceMapConsumer$2, SourceMapGenerator: SourceMapGenerator$2 } = require$$2;
1012
- let { existsSync, readFileSync } = require$$2;
1013
- let { dirname: dirname$1, join } = require$$2;
1014
- function fromBase64(str) {
1015
- if (Buffer) {
1016
- return Buffer.from(str, "base64").toString();
1017
- } else {
1018
- return window.atob(str);
1019
- }
1094
+ let Comment$3 = comment;
1095
+ let Declaration$3 = declaration;
1096
+ let Node$2 = node;
1097
+ let { isClean: isClean$1, my: my$1 } = symbols;
1098
+ let AtRule$4;
1099
+ let parse$4;
1100
+ let Root$6;
1101
+ let Rule$4;
1102
+ function cleanSource(nodes) {
1103
+ return nodes.map((i) => {
1104
+ if (i.nodes)
1105
+ i.nodes = cleanSource(i.nodes);
1106
+ delete i.source;
1107
+ return i;
1108
+ });
1020
1109
  }
1021
- let PreviousMap$2 = class PreviousMap {
1022
- constructor(css, opts) {
1023
- if (opts.map === false)
1024
- return;
1025
- this.loadAnnotation(css);
1026
- this.inline = this.startWith(this.annotation, "data:");
1027
- let prev = opts.map ? opts.map.prev : void 0;
1028
- let text = this.loadMap(opts.from, prev);
1029
- if (!this.mapFile && opts.from) {
1030
- this.mapFile = opts.from;
1031
- }
1032
- if (this.mapFile)
1033
- this.root = dirname$1(this.mapFile);
1034
- if (text)
1035
- this.text = text;
1036
- }
1037
- consumer() {
1038
- if (!this.consumerCache) {
1039
- this.consumerCache = new SourceMapConsumer$2(this.text);
1040
- }
1041
- return this.consumerCache;
1042
- }
1043
- decodeInline(text) {
1044
- let baseCharsetUri = /^data:application\/json;charset=utf-?8;base64,/;
1045
- let baseUri = /^data:application\/json;base64,/;
1046
- let charsetUri = /^data:application\/json;charset=utf-?8,/;
1047
- let uri = /^data:application\/json,/;
1048
- if (charsetUri.test(text) || uri.test(text)) {
1049
- return decodeURIComponent(text.substr(RegExp.lastMatch.length));
1050
- }
1051
- if (baseCharsetUri.test(text) || baseUri.test(text)) {
1052
- return fromBase64(text.substr(RegExp.lastMatch.length));
1110
+ function markTreeDirty(node2) {
1111
+ node2[isClean$1] = false;
1112
+ if (node2.proxyOf.nodes) {
1113
+ for (let i of node2.proxyOf.nodes) {
1114
+ markTreeDirty(i);
1053
1115
  }
1054
- let encoding = text.match(/data:application\/json;([^,]+),/)[1];
1055
- throw new Error("Unsupported source map encoding " + encoding);
1056
1116
  }
1057
- getAnnotationURL(sourceMapString) {
1058
- return sourceMapString.replace(/^\/\*\s*# sourceMappingURL=/, "").trim();
1117
+ }
1118
+ let Container$7 = class Container extends Node$2 {
1119
+ get first() {
1120
+ if (!this.proxyOf.nodes)
1121
+ return void 0;
1122
+ return this.proxyOf.nodes[0];
1059
1123
  }
1060
- isMap(map) {
1061
- if (typeof map !== "object")
1062
- return false;
1063
- return typeof map.mappings === "string" || typeof map._mappings === "string" || Array.isArray(map.sections);
1124
+ get last() {
1125
+ if (!this.proxyOf.nodes)
1126
+ return void 0;
1127
+ return this.proxyOf.nodes[this.proxyOf.nodes.length - 1];
1064
1128
  }
1065
- loadAnnotation(css) {
1066
- let comments = css.match(/\/\*\s*# sourceMappingURL=/gm);
1067
- if (!comments)
1068
- return;
1069
- let start = css.lastIndexOf(comments.pop());
1070
- let end = css.indexOf("*/", start);
1071
- if (start > -1 && end > -1) {
1072
- this.annotation = this.getAnnotationURL(css.substring(start, end));
1129
+ append(...children) {
1130
+ for (let child of children) {
1131
+ let nodes = this.normalize(child, this.last);
1132
+ for (let node2 of nodes)
1133
+ this.proxyOf.nodes.push(node2);
1073
1134
  }
1135
+ this.markDirty();
1136
+ return this;
1074
1137
  }
1075
- loadFile(path) {
1076
- this.root = dirname$1(path);
1077
- if (existsSync(path)) {
1078
- this.mapFile = path;
1079
- return readFileSync(path, "utf-8").toString().trim();
1138
+ cleanRaws(keepBetween) {
1139
+ super.cleanRaws(keepBetween);
1140
+ if (this.nodes) {
1141
+ for (let node2 of this.nodes)
1142
+ node2.cleanRaws(keepBetween);
1080
1143
  }
1081
1144
  }
1082
- loadMap(file, prev) {
1083
- if (prev === false)
1084
- return false;
1085
- if (prev) {
1086
- if (typeof prev === "string") {
1087
- return prev;
1088
- } else if (typeof prev === "function") {
1089
- let prevPath = prev(file);
1090
- if (prevPath) {
1091
- let map = this.loadFile(prevPath);
1092
- if (!map) {
1093
- throw new Error(
1094
- "Unable to load previous source map: " + prevPath.toString()
1095
- );
1096
- }
1097
- return map;
1098
- }
1099
- } else if (prev instanceof SourceMapConsumer$2) {
1100
- return SourceMapGenerator$2.fromSourceMap(prev).toString();
1101
- } else if (prev instanceof SourceMapGenerator$2) {
1102
- return prev.toString();
1103
- } else if (this.isMap(prev)) {
1104
- return JSON.stringify(prev);
1105
- } else {
1106
- throw new Error(
1107
- "Unsupported previous source map format: " + prev.toString()
1108
- );
1109
- }
1110
- } else if (this.inline) {
1111
- return this.decodeInline(this.annotation);
1112
- } else if (this.annotation) {
1113
- let map = this.annotation;
1114
- if (file)
1115
- map = join(dirname$1(file), map);
1116
- return this.loadFile(map);
1145
+ each(callback) {
1146
+ if (!this.proxyOf.nodes)
1147
+ return void 0;
1148
+ let iterator = this.getIterator();
1149
+ let index2, result2;
1150
+ while (this.indexes[iterator] < this.proxyOf.nodes.length) {
1151
+ index2 = this.indexes[iterator];
1152
+ result2 = callback(this.proxyOf.nodes[index2], index2);
1153
+ if (result2 === false)
1154
+ break;
1155
+ this.indexes[iterator] += 1;
1117
1156
  }
1157
+ delete this.indexes[iterator];
1158
+ return result2;
1118
1159
  }
1119
- startWith(string, start) {
1120
- if (!string)
1121
- return false;
1122
- return string.substr(0, start.length) === start;
1160
+ every(condition) {
1161
+ return this.nodes.every(condition);
1123
1162
  }
1124
- withContent() {
1125
- return !!(this.consumer().sourcesContent && this.consumer().sourcesContent.length > 0);
1163
+ getIterator() {
1164
+ if (!this.lastEach)
1165
+ this.lastEach = 0;
1166
+ if (!this.indexes)
1167
+ this.indexes = {};
1168
+ this.lastEach += 1;
1169
+ let iterator = this.lastEach;
1170
+ this.indexes[iterator] = 0;
1171
+ return iterator;
1126
1172
  }
1127
- };
1128
- var previousMap = PreviousMap$2;
1129
- PreviousMap$2.default = PreviousMap$2;
1130
- let { SourceMapConsumer: SourceMapConsumer$1, SourceMapGenerator: SourceMapGenerator$1 } = require$$2;
1131
- let { fileURLToPath, pathToFileURL: pathToFileURL$1 } = require$$2;
1132
- let { isAbsolute, resolve: resolve$1 } = require$$2;
1133
- let { nanoid } = nonSecure;
1134
- let terminalHighlight = require$$2;
1135
- let CssSyntaxError$1 = cssSyntaxError;
1136
- let PreviousMap$1 = previousMap;
1137
- let fromOffsetCache = Symbol("fromOffsetCache");
1138
- let sourceMapAvailable$1 = Boolean(SourceMapConsumer$1 && SourceMapGenerator$1);
1139
- let pathAvailable$1 = Boolean(resolve$1 && isAbsolute);
1140
- let Input$4 = class Input {
1141
- constructor(css, opts = {}) {
1142
- if (css === null || typeof css === "undefined" || typeof css === "object" && !css.toString) {
1143
- throw new Error(`PostCSS received ${css} instead of CSS string`);
1144
- }
1145
- this.css = css.toString();
1146
- if (this.css[0] === "\uFEFF" || this.css[0] === "\uFFFE") {
1147
- this.hasBOM = true;
1148
- this.css = this.css.slice(1);
1149
- } else {
1150
- this.hasBOM = false;
1151
- }
1152
- if (opts.from) {
1153
- if (!pathAvailable$1 || /^\w+:\/\//.test(opts.from) || isAbsolute(opts.from)) {
1154
- this.file = opts.from;
1155
- } else {
1156
- this.file = resolve$1(opts.from);
1173
+ getProxyProcessor() {
1174
+ return {
1175
+ get(node2, prop) {
1176
+ if (prop === "proxyOf") {
1177
+ return node2;
1178
+ } else if (!node2[prop]) {
1179
+ return node2[prop];
1180
+ } else if (prop === "each" || typeof prop === "string" && prop.startsWith("walk")) {
1181
+ return (...args) => {
1182
+ return node2[prop](
1183
+ ...args.map((i) => {
1184
+ if (typeof i === "function") {
1185
+ return (child, index2) => i(child.toProxy(), index2);
1186
+ } else {
1187
+ return i;
1188
+ }
1189
+ })
1190
+ );
1191
+ };
1192
+ } else if (prop === "every" || prop === "some") {
1193
+ return (cb) => {
1194
+ return node2[prop](
1195
+ (child, ...other) => cb(child.toProxy(), ...other)
1196
+ );
1197
+ };
1198
+ } else if (prop === "root") {
1199
+ return () => node2.root().toProxy();
1200
+ } else if (prop === "nodes") {
1201
+ return node2.nodes.map((i) => i.toProxy());
1202
+ } else if (prop === "first" || prop === "last") {
1203
+ return node2[prop].toProxy();
1204
+ } else {
1205
+ return node2[prop];
1206
+ }
1207
+ },
1208
+ set(node2, prop, value) {
1209
+ if (node2[prop] === value)
1210
+ return true;
1211
+ node2[prop] = value;
1212
+ if (prop === "name" || prop === "params" || prop === "selector") {
1213
+ node2.markDirty();
1214
+ }
1215
+ return true;
1157
1216
  }
1158
- }
1159
- if (pathAvailable$1 && sourceMapAvailable$1) {
1160
- let map = new PreviousMap$1(this.css, opts);
1161
- if (map.text) {
1162
- this.map = map;
1163
- let file = map.consumer().file;
1164
- if (!this.file && file)
1165
- this.file = this.mapResolve(file);
1217
+ };
1218
+ }
1219
+ index(child) {
1220
+ if (typeof child === "number")
1221
+ return child;
1222
+ if (child.proxyOf)
1223
+ child = child.proxyOf;
1224
+ return this.proxyOf.nodes.indexOf(child);
1225
+ }
1226
+ insertAfter(exist, add) {
1227
+ let existIndex = this.index(exist);
1228
+ let nodes = this.normalize(add, this.proxyOf.nodes[existIndex]).reverse();
1229
+ existIndex = this.index(exist);
1230
+ for (let node2 of nodes)
1231
+ this.proxyOf.nodes.splice(existIndex + 1, 0, node2);
1232
+ let index2;
1233
+ for (let id in this.indexes) {
1234
+ index2 = this.indexes[id];
1235
+ if (existIndex < index2) {
1236
+ this.indexes[id] = index2 + nodes.length;
1166
1237
  }
1167
1238
  }
1168
- if (!this.file) {
1169
- this.id = "<input css " + nanoid(6) + ">";
1239
+ this.markDirty();
1240
+ return this;
1241
+ }
1242
+ insertBefore(exist, add) {
1243
+ let existIndex = this.index(exist);
1244
+ let type = existIndex === 0 ? "prepend" : false;
1245
+ let nodes = this.normalize(
1246
+ add,
1247
+ this.proxyOf.nodes[existIndex],
1248
+ type
1249
+ ).reverse();
1250
+ existIndex = this.index(exist);
1251
+ for (let node2 of nodes)
1252
+ this.proxyOf.nodes.splice(existIndex, 0, node2);
1253
+ let index2;
1254
+ for (let id in this.indexes) {
1255
+ index2 = this.indexes[id];
1256
+ if (existIndex <= index2) {
1257
+ this.indexes[id] = index2 + nodes.length;
1258
+ }
1170
1259
  }
1171
- if (this.map)
1172
- this.map.file = this.from;
1260
+ this.markDirty();
1261
+ return this;
1173
1262
  }
1174
- error(message, line, column, opts = {}) {
1175
- let result2, endLine, endColumn;
1176
- if (line && typeof line === "object") {
1177
- let start = line;
1178
- let end = column;
1179
- if (typeof start.offset === "number") {
1180
- let pos = this.fromOffset(start.offset);
1181
- line = pos.line;
1182
- column = pos.col;
1183
- } else {
1184
- line = start.line;
1185
- column = start.column;
1263
+ normalize(nodes, sample) {
1264
+ if (typeof nodes === "string") {
1265
+ nodes = cleanSource(parse$4(nodes).nodes);
1266
+ } else if (typeof nodes === "undefined") {
1267
+ nodes = [];
1268
+ } else if (Array.isArray(nodes)) {
1269
+ nodes = nodes.slice(0);
1270
+ for (let i of nodes) {
1271
+ if (i.parent)
1272
+ i.parent.removeChild(i, "ignore");
1186
1273
  }
1187
- if (typeof end.offset === "number") {
1188
- let pos = this.fromOffset(end.offset);
1189
- endLine = pos.line;
1190
- endColumn = pos.col;
1191
- } else {
1192
- endLine = end.line;
1193
- endColumn = end.column;
1274
+ } else if (nodes.type === "root" && this.type !== "document") {
1275
+ nodes = nodes.nodes.slice(0);
1276
+ for (let i of nodes) {
1277
+ if (i.parent)
1278
+ i.parent.removeChild(i, "ignore");
1194
1279
  }
1195
- } else if (!column) {
1196
- let pos = this.fromOffset(line);
1197
- line = pos.line;
1198
- column = pos.col;
1199
- }
1200
- let origin = this.origin(line, column, endLine, endColumn);
1201
- if (origin) {
1202
- result2 = new CssSyntaxError$1(
1203
- message,
1204
- origin.endLine === void 0 ? origin.line : { column: origin.column, line: origin.line },
1205
- origin.endLine === void 0 ? origin.column : { column: origin.endColumn, line: origin.endLine },
1206
- origin.source,
1207
- origin.file,
1208
- opts.plugin
1209
- );
1210
- } else {
1211
- result2 = new CssSyntaxError$1(
1212
- message,
1213
- endLine === void 0 ? line : { column, line },
1214
- endLine === void 0 ? column : { column: endColumn, line: endLine },
1215
- this.css,
1216
- this.file,
1217
- opts.plugin
1218
- );
1219
- }
1220
- result2.input = { column, endColumn, endLine, line, source: this.css };
1221
- if (this.file) {
1222
- if (pathToFileURL$1) {
1223
- result2.input.url = pathToFileURL$1(this.file).toString();
1280
+ } else if (nodes.type) {
1281
+ nodes = [nodes];
1282
+ } else if (nodes.prop) {
1283
+ if (typeof nodes.value === "undefined") {
1284
+ throw new Error("Value field is missed in node creation");
1285
+ } else if (typeof nodes.value !== "string") {
1286
+ nodes.value = String(nodes.value);
1224
1287
  }
1225
- result2.input.file = this.file;
1226
- }
1227
- return result2;
1228
- }
1229
- fromOffset(offset) {
1230
- let lastLine, lineToIndex;
1231
- if (!this[fromOffsetCache]) {
1232
- let lines = this.css.split("\n");
1233
- lineToIndex = new Array(lines.length);
1234
- let prevIndex = 0;
1235
- for (let i = 0, l = lines.length; i < l; i++) {
1236
- lineToIndex[i] = prevIndex;
1237
- prevIndex += lines[i].length + 1;
1238
- }
1239
- this[fromOffsetCache] = lineToIndex;
1288
+ nodes = [new Declaration$3(nodes)];
1289
+ } else if (nodes.selector || nodes.selectors) {
1290
+ nodes = [new Rule$4(nodes)];
1291
+ } else if (nodes.name) {
1292
+ nodes = [new AtRule$4(nodes)];
1293
+ } else if (nodes.text) {
1294
+ nodes = [new Comment$3(nodes)];
1240
1295
  } else {
1241
- lineToIndex = this[fromOffsetCache];
1296
+ throw new Error("Unknown node type in node creation");
1242
1297
  }
1243
- lastLine = lineToIndex[lineToIndex.length - 1];
1244
- let min = 0;
1245
- if (offset >= lastLine) {
1246
- min = lineToIndex.length - 1;
1247
- } else {
1248
- let max = lineToIndex.length - 2;
1249
- let mid;
1250
- while (min < max) {
1251
- mid = min + (max - min >> 1);
1252
- if (offset < lineToIndex[mid]) {
1253
- max = mid - 1;
1254
- } else if (offset >= lineToIndex[mid + 1]) {
1255
- min = mid + 1;
1256
- } else {
1257
- min = mid;
1258
- break;
1298
+ let processed = nodes.map((i) => {
1299
+ if (!i[my$1])
1300
+ Container.rebuild(i);
1301
+ i = i.proxyOf;
1302
+ if (i.parent)
1303
+ i.parent.removeChild(i);
1304
+ if (i[isClean$1])
1305
+ markTreeDirty(i);
1306
+ if (!i.raws)
1307
+ i.raws = {};
1308
+ if (typeof i.raws.before === "undefined") {
1309
+ if (sample && typeof sample.raws.before !== "undefined") {
1310
+ i.raws.before = sample.raws.before.replace(/\S/g, "");
1259
1311
  }
1260
1312
  }
1313
+ i.parent = this.proxyOf;
1314
+ return i;
1315
+ });
1316
+ return processed;
1317
+ }
1318
+ prepend(...children) {
1319
+ children = children.reverse();
1320
+ for (let child of children) {
1321
+ let nodes = this.normalize(child, this.first, "prepend").reverse();
1322
+ for (let node2 of nodes)
1323
+ this.proxyOf.nodes.unshift(node2);
1324
+ for (let id in this.indexes) {
1325
+ this.indexes[id] = this.indexes[id] + nodes.length;
1326
+ }
1261
1327
  }
1262
- return {
1263
- col: offset - lineToIndex[min] + 1,
1264
- line: min + 1
1265
- };
1328
+ this.markDirty();
1329
+ return this;
1266
1330
  }
1267
- mapResolve(file) {
1268
- if (/^\w+:\/\//.test(file)) {
1269
- return file;
1331
+ push(child) {
1332
+ child.parent = this;
1333
+ this.proxyOf.nodes.push(child);
1334
+ return this;
1335
+ }
1336
+ removeAll() {
1337
+ for (let node2 of this.proxyOf.nodes)
1338
+ node2.parent = void 0;
1339
+ this.proxyOf.nodes = [];
1340
+ this.markDirty();
1341
+ return this;
1342
+ }
1343
+ removeChild(child) {
1344
+ child = this.index(child);
1345
+ this.proxyOf.nodes[child].parent = void 0;
1346
+ this.proxyOf.nodes.splice(child, 1);
1347
+ let index2;
1348
+ for (let id in this.indexes) {
1349
+ index2 = this.indexes[id];
1350
+ if (index2 >= child) {
1351
+ this.indexes[id] = index2 - 1;
1352
+ }
1270
1353
  }
1271
- return resolve$1(this.map.consumer().sourceRoot || this.map.root || ".", file);
1354
+ this.markDirty();
1355
+ return this;
1272
1356
  }
1273
- origin(line, column, endLine, endColumn) {
1274
- if (!this.map)
1275
- return false;
1276
- let consumer = this.map.consumer();
1277
- let from = consumer.originalPositionFor({ column, line });
1278
- if (!from.source)
1279
- return false;
1280
- let to;
1281
- if (typeof endLine === "number") {
1282
- to = consumer.originalPositionFor({ column: endColumn, line: endLine });
1283
- }
1284
- let fromUrl;
1285
- if (isAbsolute(from.source)) {
1286
- fromUrl = pathToFileURL$1(from.source);
1287
- } else {
1288
- fromUrl = new URL(
1289
- from.source,
1290
- this.map.consumer().sourceRoot || pathToFileURL$1(this.map.mapFile)
1291
- );
1292
- }
1293
- let result2 = {
1294
- column: from.column,
1295
- endColumn: to && to.column,
1296
- endLine: to && to.line,
1297
- line: from.line,
1298
- url: fromUrl.toString()
1299
- };
1300
- if (fromUrl.protocol === "file:") {
1301
- if (fileURLToPath) {
1302
- result2.file = fileURLToPath(fromUrl);
1303
- } else {
1304
- throw new Error(`file: protocol is not available in this PostCSS build`);
1305
- }
1357
+ replaceValues(pattern, opts, callback) {
1358
+ if (!callback) {
1359
+ callback = opts;
1360
+ opts = {};
1306
1361
  }
1307
- let source = consumer.sourceContentFor(from.source);
1308
- if (source)
1309
- result2.source = source;
1310
- return result2;
1362
+ this.walkDecls((decl) => {
1363
+ if (opts.props && !opts.props.includes(decl.prop))
1364
+ return;
1365
+ if (opts.fast && !decl.value.includes(opts.fast))
1366
+ return;
1367
+ decl.value = decl.value.replace(pattern, callback);
1368
+ });
1369
+ this.markDirty();
1370
+ return this;
1311
1371
  }
1312
- toJSON() {
1313
- let json = {};
1314
- for (let name of ["hasBOM", "css", "file", "id"]) {
1315
- if (this[name] != null) {
1316
- json[name] = this[name];
1372
+ some(condition) {
1373
+ return this.nodes.some(condition);
1374
+ }
1375
+ walk(callback) {
1376
+ return this.each((child, i) => {
1377
+ let result2;
1378
+ try {
1379
+ result2 = callback(child, i);
1380
+ } catch (e) {
1381
+ throw child.addToError(e);
1317
1382
  }
1318
- }
1319
- if (this.map) {
1320
- json.map = __spreadValues({}, this.map);
1321
- if (json.map.consumerCache) {
1322
- json.map.consumerCache = void 0;
1383
+ if (result2 !== false && child.walk) {
1384
+ result2 = child.walk(callback);
1323
1385
  }
1324
- }
1325
- return json;
1326
- }
1327
- get from() {
1328
- return this.file || this.id;
1329
- }
1330
- };
1331
- var input = Input$4;
1332
- Input$4.default = Input$4;
1333
- if (terminalHighlight && terminalHighlight.registerInput) {
1334
- terminalHighlight.registerInput(Input$4);
1335
- }
1336
- let { SourceMapConsumer, SourceMapGenerator } = require$$2;
1337
- let { dirname, relative, resolve, sep } = require$$2;
1338
- let { pathToFileURL } = require$$2;
1339
- let Input$3 = input;
1340
- let sourceMapAvailable = Boolean(SourceMapConsumer && SourceMapGenerator);
1341
- let pathAvailable = Boolean(dirname && resolve && relative && sep);
1342
- let MapGenerator$2 = class MapGenerator {
1343
- constructor(stringify2, root2, opts, cssString) {
1344
- this.stringify = stringify2;
1345
- this.mapOpts = opts.map || {};
1346
- this.root = root2;
1347
- this.opts = opts;
1348
- this.css = cssString;
1349
- this.originalCSS = cssString;
1350
- this.usesFileUrls = !this.mapOpts.from && this.mapOpts.absolute;
1351
- this.memoizedFileURLs = /* @__PURE__ */ new Map();
1352
- this.memoizedPaths = /* @__PURE__ */ new Map();
1353
- this.memoizedURLs = /* @__PURE__ */ new Map();
1386
+ return result2;
1387
+ });
1354
1388
  }
1355
- addAnnotation() {
1356
- let content;
1357
- if (this.isInline()) {
1358
- content = "data:application/json;base64," + this.toBase64(this.map.toString());
1359
- } else if (typeof this.mapOpts.annotation === "string") {
1360
- content = this.mapOpts.annotation;
1361
- } else if (typeof this.mapOpts.annotation === "function") {
1362
- content = this.mapOpts.annotation(this.opts.to, this.root);
1363
- } else {
1364
- content = this.outputFile() + ".map";
1389
+ walkAtRules(name, callback) {
1390
+ if (!callback) {
1391
+ callback = name;
1392
+ return this.walk((child, i) => {
1393
+ if (child.type === "atrule") {
1394
+ return callback(child, i);
1395
+ }
1396
+ });
1365
1397
  }
1366
- let eol = "\n";
1367
- if (this.css.includes("\r\n"))
1368
- eol = "\r\n";
1369
- this.css += eol + "/*# sourceMappingURL=" + content + " */";
1370
- }
1371
- applyPrevMaps() {
1372
- for (let prev of this.previous()) {
1373
- let from = this.toUrl(this.path(prev.file));
1374
- let root2 = prev.root || dirname(prev.file);
1375
- let map;
1376
- if (this.mapOpts.sourcesContent === false) {
1377
- map = new SourceMapConsumer(prev.text);
1378
- if (map.sourcesContent) {
1379
- map.sourcesContent = null;
1398
+ if (name instanceof RegExp) {
1399
+ return this.walk((child, i) => {
1400
+ if (child.type === "atrule" && name.test(child.name)) {
1401
+ return callback(child, i);
1380
1402
  }
1381
- } else {
1382
- map = prev.consumer();
1383
- }
1384
- this.map.applySourceMap(map, from, this.toUrl(this.path(root2)));
1403
+ });
1385
1404
  }
1405
+ return this.walk((child, i) => {
1406
+ if (child.type === "atrule" && child.name === name) {
1407
+ return callback(child, i);
1408
+ }
1409
+ });
1386
1410
  }
1387
- clearAnnotation() {
1388
- if (this.mapOpts.annotation === false)
1389
- return;
1390
- if (this.root) {
1391
- let node2;
1392
- for (let i = this.root.nodes.length - 1; i >= 0; i--) {
1393
- node2 = this.root.nodes[i];
1394
- if (node2.type !== "comment")
1395
- continue;
1396
- if (node2.text.indexOf("# sourceMappingURL=") === 0) {
1397
- this.root.removeChild(i);
1398
- }
1411
+ walkComments(callback) {
1412
+ return this.walk((child, i) => {
1413
+ if (child.type === "comment") {
1414
+ return callback(child, i);
1399
1415
  }
1400
- } else if (this.css) {
1401
- this.css = this.css.replace(/\n*?\/\*#[\S\s]*?\*\/$/gm, "");
1402
- }
1416
+ });
1403
1417
  }
1404
- generate() {
1405
- this.clearAnnotation();
1406
- if (pathAvailable && sourceMapAvailable && this.isMap()) {
1407
- return this.generateMap();
1408
- } else {
1409
- let result2 = "";
1410
- this.stringify(this.root, (i) => {
1411
- result2 += i;
1418
+ walkDecls(prop, callback) {
1419
+ if (!callback) {
1420
+ callback = prop;
1421
+ return this.walk((child, i) => {
1422
+ if (child.type === "decl") {
1423
+ return callback(child, i);
1424
+ }
1412
1425
  });
1413
- return [result2];
1414
1426
  }
1415
- }
1416
- generateMap() {
1417
- if (this.root) {
1418
- this.generateString();
1419
- } else if (this.previous().length === 1) {
1420
- let prev = this.previous()[0].consumer();
1421
- prev.file = this.outputFile();
1422
- this.map = SourceMapGenerator.fromSourceMap(prev, {
1423
- ignoreInvalidMapping: true
1424
- });
1425
- } else {
1426
- this.map = new SourceMapGenerator({
1427
- file: this.outputFile(),
1428
- ignoreInvalidMapping: true
1427
+ if (prop instanceof RegExp) {
1428
+ return this.walk((child, i) => {
1429
+ if (child.type === "decl" && prop.test(child.prop)) {
1430
+ return callback(child, i);
1431
+ }
1429
1432
  });
1430
- this.map.addMapping({
1431
- generated: { column: 0, line: 1 },
1432
- original: { column: 0, line: 1 },
1433
- source: this.opts.from ? this.toUrl(this.path(this.opts.from)) : "<no source>"
1433
+ }
1434
+ return this.walk((child, i) => {
1435
+ if (child.type === "decl" && child.prop === prop) {
1436
+ return callback(child, i);
1437
+ }
1438
+ });
1439
+ }
1440
+ walkRules(selector, callback) {
1441
+ if (!callback) {
1442
+ callback = selector;
1443
+ return this.walk((child, i) => {
1444
+ if (child.type === "rule") {
1445
+ return callback(child, i);
1446
+ }
1434
1447
  });
1435
1448
  }
1436
- if (this.isSourcesContent())
1437
- this.setSourcesContent();
1438
- if (this.root && this.previous().length > 0)
1439
- this.applyPrevMaps();
1440
- if (this.isAnnotation())
1441
- this.addAnnotation();
1442
- if (this.isInline()) {
1443
- return [this.css];
1444
- } else {
1445
- return [this.css, this.map];
1449
+ if (selector instanceof RegExp) {
1450
+ return this.walk((child, i) => {
1451
+ if (child.type === "rule" && selector.test(child.selector)) {
1452
+ return callback(child, i);
1453
+ }
1454
+ });
1446
1455
  }
1447
- }
1448
- generateString() {
1449
- this.css = "";
1450
- this.map = new SourceMapGenerator({
1451
- file: this.outputFile(),
1452
- ignoreInvalidMapping: true
1456
+ return this.walk((child, i) => {
1457
+ if (child.type === "rule" && child.selector === selector) {
1458
+ return callback(child, i);
1459
+ }
1453
1460
  });
1454
- let line = 1;
1455
- let column = 1;
1456
- let noSource = "<no source>";
1457
- let mapping = {
1458
- generated: { column: 0, line: 0 },
1459
- original: { column: 0, line: 0 },
1460
- source: ""
1461
- };
1462
- let lines, last;
1463
- this.stringify(this.root, (str, node2, type) => {
1464
- this.css += str;
1465
- if (node2 && type !== "end") {
1466
- mapping.generated.line = line;
1467
- mapping.generated.column = column - 1;
1468
- if (node2.source && node2.source.start) {
1469
- mapping.source = this.sourcePath(node2);
1470
- mapping.original.line = node2.source.start.line;
1471
- mapping.original.column = node2.source.start.column - 1;
1472
- this.map.addMapping(mapping);
1473
- } else {
1474
- mapping.source = noSource;
1475
- mapping.original.line = 1;
1476
- mapping.original.column = 0;
1477
- this.map.addMapping(mapping);
1478
- }
1479
- }
1480
- lines = str.match(/\n/g);
1481
- if (lines) {
1482
- line += lines.length;
1483
- last = str.lastIndexOf("\n");
1484
- column = str.length - last;
1485
- } else {
1486
- column += str.length;
1487
- }
1488
- if (node2 && type !== "start") {
1489
- let p = node2.parent || { raws: {} };
1490
- let childless = node2.type === "decl" || node2.type === "atrule" && !node2.nodes;
1491
- if (!childless || node2 !== p.last || p.raws.semicolon) {
1492
- if (node2.source && node2.source.end) {
1493
- mapping.source = this.sourcePath(node2);
1494
- mapping.original.line = node2.source.end.line;
1495
- mapping.original.column = node2.source.end.column - 1;
1496
- mapping.generated.line = line;
1497
- mapping.generated.column = column - 2;
1498
- this.map.addMapping(mapping);
1499
- } else {
1500
- mapping.source = noSource;
1501
- mapping.original.line = 1;
1502
- mapping.original.column = 0;
1503
- mapping.generated.line = line;
1504
- mapping.generated.column = column - 1;
1505
- this.map.addMapping(mapping);
1506
- }
1507
- }
1508
- }
1461
+ }
1462
+ };
1463
+ Container$7.registerParse = (dependant) => {
1464
+ parse$4 = dependant;
1465
+ };
1466
+ Container$7.registerRule = (dependant) => {
1467
+ Rule$4 = dependant;
1468
+ };
1469
+ Container$7.registerAtRule = (dependant) => {
1470
+ AtRule$4 = dependant;
1471
+ };
1472
+ Container$7.registerRoot = (dependant) => {
1473
+ Root$6 = dependant;
1474
+ };
1475
+ var container = Container$7;
1476
+ Container$7.default = Container$7;
1477
+ Container$7.rebuild = (node2) => {
1478
+ if (node2.type === "atrule") {
1479
+ Object.setPrototypeOf(node2, AtRule$4.prototype);
1480
+ } else if (node2.type === "rule") {
1481
+ Object.setPrototypeOf(node2, Rule$4.prototype);
1482
+ } else if (node2.type === "decl") {
1483
+ Object.setPrototypeOf(node2, Declaration$3.prototype);
1484
+ } else if (node2.type === "comment") {
1485
+ Object.setPrototypeOf(node2, Comment$3.prototype);
1486
+ } else if (node2.type === "root") {
1487
+ Object.setPrototypeOf(node2, Root$6.prototype);
1488
+ }
1489
+ node2[my$1] = true;
1490
+ if (node2.nodes) {
1491
+ node2.nodes.forEach((child) => {
1492
+ Container$7.rebuild(child);
1509
1493
  });
1510
1494
  }
1511
- isAnnotation() {
1512
- if (this.isInline()) {
1513
- return true;
1514
- }
1515
- if (typeof this.mapOpts.annotation !== "undefined") {
1516
- return this.mapOpts.annotation;
1517
- }
1518
- if (this.previous().length) {
1519
- return this.previous().some((i) => i.annotation);
1520
- }
1521
- return true;
1495
+ };
1496
+ let Container$6 = container;
1497
+ let AtRule$3 = class AtRule extends Container$6 {
1498
+ constructor(defaults) {
1499
+ super(defaults);
1500
+ this.type = "atrule";
1522
1501
  }
1523
- isInline() {
1524
- if (typeof this.mapOpts.inline !== "undefined") {
1525
- return this.mapOpts.inline;
1526
- }
1527
- let annotation = this.mapOpts.annotation;
1528
- if (typeof annotation !== "undefined" && annotation !== true) {
1529
- return false;
1530
- }
1531
- if (this.previous().length) {
1532
- return this.previous().some((i) => i.inline);
1533
- }
1534
- return true;
1502
+ append(...children) {
1503
+ if (!this.proxyOf.nodes)
1504
+ this.nodes = [];
1505
+ return super.append(...children);
1535
1506
  }
1536
- isMap() {
1537
- if (typeof this.opts.map !== "undefined") {
1538
- return !!this.opts.map;
1539
- }
1540
- return this.previous().length > 0;
1507
+ prepend(...children) {
1508
+ if (!this.proxyOf.nodes)
1509
+ this.nodes = [];
1510
+ return super.prepend(...children);
1541
1511
  }
1542
- isSourcesContent() {
1543
- if (typeof this.mapOpts.sourcesContent !== "undefined") {
1544
- return this.mapOpts.sourcesContent;
1545
- }
1546
- if (this.previous().length) {
1547
- return this.previous().some((i) => i.withContent());
1512
+ };
1513
+ var atRule = AtRule$3;
1514
+ AtRule$3.default = AtRule$3;
1515
+ Container$6.registerAtRule(AtRule$3);
1516
+ let Container$5 = container;
1517
+ let LazyResult$4;
1518
+ let Processor$3;
1519
+ let Document$4 = class Document2 extends Container$5 {
1520
+ constructor(defaults) {
1521
+ super(__spreadValues({ type: "document" }, defaults));
1522
+ if (!this.nodes) {
1523
+ this.nodes = [];
1548
1524
  }
1549
- return true;
1550
1525
  }
1551
- outputFile() {
1552
- if (this.opts.to) {
1553
- return this.path(this.opts.to);
1554
- } else if (this.opts.from) {
1555
- return this.path(this.opts.from);
1556
- } else {
1557
- return "to.css";
1558
- }
1526
+ toResult(opts = {}) {
1527
+ let lazy = new LazyResult$4(new Processor$3(), this, opts);
1528
+ return lazy.stringify();
1559
1529
  }
1560
- path(file) {
1561
- if (this.mapOpts.absolute)
1562
- return file;
1563
- if (file.charCodeAt(0) === 60)
1564
- return file;
1565
- if (/^\w+:\/\//.test(file))
1566
- return file;
1567
- let cached = this.memoizedPaths.get(file);
1568
- if (cached)
1569
- return cached;
1570
- let from = this.opts.to ? dirname(this.opts.to) : ".";
1571
- if (typeof this.mapOpts.annotation === "string") {
1572
- from = dirname(resolve(from, this.mapOpts.annotation));
1573
- }
1574
- let path = relative(from, file);
1575
- this.memoizedPaths.set(file, path);
1576
- return path;
1530
+ };
1531
+ Document$4.registerLazyResult = (dependant) => {
1532
+ LazyResult$4 = dependant;
1533
+ };
1534
+ Document$4.registerProcessor = (dependant) => {
1535
+ Processor$3 = dependant;
1536
+ };
1537
+ var document$1 = Document$4;
1538
+ Document$4.default = Document$4;
1539
+ let urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
1540
+ let nanoid$1 = (size = 21) => {
1541
+ let id = "";
1542
+ let i = size | 0;
1543
+ while (i--) {
1544
+ id += urlAlphabet[Math.random() * 64 | 0];
1577
1545
  }
1578
- previous() {
1579
- if (!this.previousMaps) {
1580
- this.previousMaps = [];
1581
- if (this.root) {
1582
- this.root.walk((node2) => {
1583
- if (node2.source && node2.source.input.map) {
1584
- let map = node2.source.input.map;
1585
- if (!this.previousMaps.includes(map)) {
1586
- this.previousMaps.push(map);
1587
- }
1588
- }
1589
- });
1590
- } else {
1591
- let input2 = new Input$3(this.originalCSS, this.opts);
1592
- if (input2.map)
1593
- this.previousMaps.push(input2.map);
1594
- }
1595
- }
1596
- return this.previousMaps;
1546
+ return id;
1547
+ };
1548
+ var nonSecure = { nanoid: nanoid$1 };
1549
+ let { existsSync, readFileSync } = require$$2;
1550
+ let { dirname: dirname$1, join } = require$$2;
1551
+ let { SourceMapConsumer: SourceMapConsumer$2, SourceMapGenerator: SourceMapGenerator$2 } = require$$2;
1552
+ function fromBase64(str) {
1553
+ if (Buffer) {
1554
+ return Buffer.from(str, "base64").toString();
1555
+ } else {
1556
+ return window.atob(str);
1597
1557
  }
1598
- setSourcesContent() {
1599
- let already = {};
1600
- if (this.root) {
1601
- this.root.walk((node2) => {
1602
- if (node2.source) {
1603
- let from = node2.source.input.from;
1604
- if (from && !already[from]) {
1605
- already[from] = true;
1606
- let fromUrl = this.usesFileUrls ? this.toFileUrl(from) : this.toUrl(this.path(from));
1607
- this.map.setSourceContent(fromUrl, node2.source.input.css);
1608
- }
1609
- }
1610
- });
1611
- } else if (this.css) {
1612
- let from = this.opts.from ? this.toUrl(this.path(this.opts.from)) : "<no source>";
1613
- this.map.setSourceContent(from, this.css);
1558
+ }
1559
+ let PreviousMap$2 = class PreviousMap {
1560
+ constructor(css, opts) {
1561
+ if (opts.map === false)
1562
+ return;
1563
+ this.loadAnnotation(css);
1564
+ this.inline = this.startWith(this.annotation, "data:");
1565
+ let prev = opts.map ? opts.map.prev : void 0;
1566
+ let text = this.loadMap(opts.from, prev);
1567
+ if (!this.mapFile && opts.from) {
1568
+ this.mapFile = opts.from;
1614
1569
  }
1570
+ if (this.mapFile)
1571
+ this.root = dirname$1(this.mapFile);
1572
+ if (text)
1573
+ this.text = text;
1615
1574
  }
1616
- sourcePath(node2) {
1617
- if (this.mapOpts.from) {
1618
- return this.toUrl(this.mapOpts.from);
1619
- } else if (this.usesFileUrls) {
1620
- return this.toFileUrl(node2.source.input.from);
1621
- } else {
1622
- return this.toUrl(this.path(node2.source.input.from));
1575
+ consumer() {
1576
+ if (!this.consumerCache) {
1577
+ this.consumerCache = new SourceMapConsumer$2(this.text);
1623
1578
  }
1579
+ return this.consumerCache;
1624
1580
  }
1625
- toBase64(str) {
1626
- if (Buffer) {
1627
- return Buffer.from(str).toString("base64");
1628
- } else {
1629
- return window.btoa(unescape(encodeURIComponent(str)));
1581
+ decodeInline(text) {
1582
+ let baseCharsetUri = /^data:application\/json;charset=utf-?8;base64,/;
1583
+ let baseUri = /^data:application\/json;base64,/;
1584
+ let charsetUri = /^data:application\/json;charset=utf-?8,/;
1585
+ let uri = /^data:application\/json,/;
1586
+ let uriMatch = text.match(charsetUri) || text.match(uri);
1587
+ if (uriMatch) {
1588
+ return decodeURIComponent(text.substr(uriMatch[0].length));
1630
1589
  }
1590
+ let baseUriMatch = text.match(baseCharsetUri) || text.match(baseUri);
1591
+ if (baseUriMatch) {
1592
+ return fromBase64(text.substr(baseUriMatch[0].length));
1593
+ }
1594
+ let encoding = text.match(/data:application\/json;([^,]+),/)[1];
1595
+ throw new Error("Unsupported source map encoding " + encoding);
1631
1596
  }
1632
- toFileUrl(path) {
1633
- let cached = this.memoizedFileURLs.get(path);
1634
- if (cached)
1635
- return cached;
1636
- if (pathToFileURL) {
1637
- let fileURL = pathToFileURL(path).toString();
1638
- this.memoizedFileURLs.set(path, fileURL);
1639
- return fileURL;
1640
- } else {
1641
- throw new Error(
1642
- "`map.absolute` option is not available in this PostCSS build"
1643
- );
1597
+ getAnnotationURL(sourceMapString) {
1598
+ return sourceMapString.replace(/^\/\*\s*# sourceMappingURL=/, "").trim();
1599
+ }
1600
+ isMap(map) {
1601
+ if (typeof map !== "object")
1602
+ return false;
1603
+ return typeof map.mappings === "string" || typeof map._mappings === "string" || Array.isArray(map.sections);
1604
+ }
1605
+ loadAnnotation(css) {
1606
+ let comments = css.match(/\/\*\s*# sourceMappingURL=/g);
1607
+ if (!comments)
1608
+ return;
1609
+ let start = css.lastIndexOf(comments.pop());
1610
+ let end = css.indexOf("*/", start);
1611
+ if (start > -1 && end > -1) {
1612
+ this.annotation = this.getAnnotationURL(css.substring(start, end));
1644
1613
  }
1645
1614
  }
1646
- toUrl(path) {
1647
- let cached = this.memoizedURLs.get(path);
1648
- if (cached)
1649
- return cached;
1650
- if (sep === "\\") {
1651
- path = path.replace(/\\/g, "/");
1615
+ loadFile(path) {
1616
+ this.root = dirname$1(path);
1617
+ if (existsSync(path)) {
1618
+ this.mapFile = path;
1619
+ return readFileSync(path, "utf-8").toString().trim();
1652
1620
  }
1653
- let url = encodeURI(path).replace(/[#?]/g, encodeURIComponent);
1654
- this.memoizedURLs.set(path, url);
1655
- return url;
1656
1621
  }
1657
- };
1658
- var mapGenerator = MapGenerator$2;
1659
- let Node$3 = node;
1660
- let Comment$4 = class Comment extends Node$3 {
1661
- constructor(defaults) {
1662
- super(defaults);
1663
- this.type = "comment";
1622
+ loadMap(file, prev) {
1623
+ if (prev === false)
1624
+ return false;
1625
+ if (prev) {
1626
+ if (typeof prev === "string") {
1627
+ return prev;
1628
+ } else if (typeof prev === "function") {
1629
+ let prevPath = prev(file);
1630
+ if (prevPath) {
1631
+ let map = this.loadFile(prevPath);
1632
+ if (!map) {
1633
+ throw new Error(
1634
+ "Unable to load previous source map: " + prevPath.toString()
1635
+ );
1636
+ }
1637
+ return map;
1638
+ }
1639
+ } else if (prev instanceof SourceMapConsumer$2) {
1640
+ return SourceMapGenerator$2.fromSourceMap(prev).toString();
1641
+ } else if (prev instanceof SourceMapGenerator$2) {
1642
+ return prev.toString();
1643
+ } else if (this.isMap(prev)) {
1644
+ return JSON.stringify(prev);
1645
+ } else {
1646
+ throw new Error(
1647
+ "Unsupported previous source map format: " + prev.toString()
1648
+ );
1649
+ }
1650
+ } else if (this.inline) {
1651
+ return this.decodeInline(this.annotation);
1652
+ } else if (this.annotation) {
1653
+ let map = this.annotation;
1654
+ if (file)
1655
+ map = join(dirname$1(file), map);
1656
+ return this.loadFile(map);
1657
+ }
1658
+ }
1659
+ startWith(string, start) {
1660
+ if (!string)
1661
+ return false;
1662
+ return string.substr(0, start.length) === start;
1663
+ }
1664
+ withContent() {
1665
+ return !!(this.consumer().sourcesContent && this.consumer().sourcesContent.length > 0);
1664
1666
  }
1665
1667
  };
1666
- var comment = Comment$4;
1667
- Comment$4.default = Comment$4;
1668
- let { isClean: isClean$1, my: my$1 } = symbols;
1669
- let Declaration$3 = declaration;
1670
- let Comment$3 = comment;
1671
- let Node$2 = node;
1672
- let parse$4;
1673
- let Rule$4;
1674
- let AtRule$4;
1675
- let Root$6;
1676
- function cleanSource(nodes) {
1677
- return nodes.map((i) => {
1678
- if (i.nodes)
1679
- i.nodes = cleanSource(i.nodes);
1680
- delete i.source;
1681
- return i;
1682
- });
1668
+ var previousMap = PreviousMap$2;
1669
+ PreviousMap$2.default = PreviousMap$2;
1670
+ let { nanoid } = nonSecure;
1671
+ let { isAbsolute, resolve: resolve$1 } = require$$2;
1672
+ let { SourceMapConsumer: SourceMapConsumer$1, SourceMapGenerator: SourceMapGenerator$1 } = require$$2;
1673
+ let { fileURLToPath, pathToFileURL: pathToFileURL$1 } = require$$2;
1674
+ let CssSyntaxError$1 = cssSyntaxError;
1675
+ let PreviousMap$1 = previousMap;
1676
+ let terminalHighlight = require$$2;
1677
+ let lineToIndexCache = Symbol("lineToIndexCache");
1678
+ let sourceMapAvailable$1 = Boolean(SourceMapConsumer$1 && SourceMapGenerator$1);
1679
+ let pathAvailable$1 = Boolean(resolve$1 && isAbsolute);
1680
+ function getLineToIndex(input2) {
1681
+ if (input2[lineToIndexCache])
1682
+ return input2[lineToIndexCache];
1683
+ let lines = input2.css.split("\n");
1684
+ let lineToIndex = new Array(lines.length);
1685
+ let prevIndex = 0;
1686
+ for (let i = 0, l = lines.length; i < l; i++) {
1687
+ lineToIndex[i] = prevIndex;
1688
+ prevIndex += lines[i].length + 1;
1689
+ }
1690
+ input2[lineToIndexCache] = lineToIndex;
1691
+ return lineToIndex;
1683
1692
  }
1684
- function markDirtyUp(node2) {
1685
- node2[isClean$1] = false;
1686
- if (node2.proxyOf.nodes) {
1687
- for (let i of node2.proxyOf.nodes) {
1688
- markDirtyUp(i);
1689
- }
1693
+ let Input$4 = class Input {
1694
+ get from() {
1695
+ return this.file || this.id;
1690
1696
  }
1691
- }
1692
- let Container$7 = class Container extends Node$2 {
1693
- append(...children) {
1694
- for (let child of children) {
1695
- let nodes = this.normalize(child, this.last);
1696
- for (let node2 of nodes)
1697
- this.proxyOf.nodes.push(node2);
1697
+ constructor(css, opts = {}) {
1698
+ if (css === null || typeof css === "undefined" || typeof css === "object" && !css.toString) {
1699
+ throw new Error(`PostCSS received ${css} instead of CSS string`);
1698
1700
  }
1699
- this.markDirty();
1700
- return this;
1701
- }
1702
- cleanRaws(keepBetween) {
1703
- super.cleanRaws(keepBetween);
1704
- if (this.nodes) {
1705
- for (let node2 of this.nodes)
1706
- node2.cleanRaws(keepBetween);
1701
+ this.css = css.toString();
1702
+ if (this.css[0] === "\uFEFF" || this.css[0] === "\uFFFE") {
1703
+ this.hasBOM = true;
1704
+ this.css = this.css.slice(1);
1705
+ } else {
1706
+ this.hasBOM = false;
1707
+ }
1708
+ this.document = this.css;
1709
+ if (opts.document)
1710
+ this.document = opts.document.toString();
1711
+ if (opts.from) {
1712
+ if (!pathAvailable$1 || /^\w+:\/\//.test(opts.from) || isAbsolute(opts.from)) {
1713
+ this.file = opts.from;
1714
+ } else {
1715
+ this.file = resolve$1(opts.from);
1716
+ }
1717
+ }
1718
+ if (pathAvailable$1 && sourceMapAvailable$1) {
1719
+ let map = new PreviousMap$1(this.css, opts);
1720
+ if (map.text) {
1721
+ this.map = map;
1722
+ let file = map.consumer().file;
1723
+ if (!this.file && file)
1724
+ this.file = this.mapResolve(file);
1725
+ }
1726
+ }
1727
+ if (!this.file) {
1728
+ this.id = "<input css " + nanoid(6) + ">";
1707
1729
  }
1730
+ if (this.map)
1731
+ this.map.file = this.from;
1708
1732
  }
1709
- each(callback) {
1710
- if (!this.proxyOf.nodes)
1711
- return void 0;
1712
- let iterator = this.getIterator();
1713
- let index2, result2;
1714
- while (this.indexes[iterator] < this.proxyOf.nodes.length) {
1715
- index2 = this.indexes[iterator];
1716
- result2 = callback(this.proxyOf.nodes[index2], index2);
1717
- if (result2 === false)
1718
- break;
1719
- this.indexes[iterator] += 1;
1733
+ error(message, line, column, opts = {}) {
1734
+ let endColumn, endLine, endOffset, offset, result2;
1735
+ if (line && typeof line === "object") {
1736
+ let start = line;
1737
+ let end = column;
1738
+ if (typeof start.offset === "number") {
1739
+ offset = start.offset;
1740
+ let pos = this.fromOffset(offset);
1741
+ line = pos.line;
1742
+ column = pos.col;
1743
+ } else {
1744
+ line = start.line;
1745
+ column = start.column;
1746
+ offset = this.fromLineAndColumn(line, column);
1747
+ }
1748
+ if (typeof end.offset === "number") {
1749
+ endOffset = end.offset;
1750
+ let pos = this.fromOffset(endOffset);
1751
+ endLine = pos.line;
1752
+ endColumn = pos.col;
1753
+ } else {
1754
+ endLine = end.line;
1755
+ endColumn = end.column;
1756
+ endOffset = this.fromLineAndColumn(end.line, end.column);
1757
+ }
1758
+ } else if (!column) {
1759
+ offset = line;
1760
+ let pos = this.fromOffset(offset);
1761
+ line = pos.line;
1762
+ column = pos.col;
1763
+ } else {
1764
+ offset = this.fromLineAndColumn(line, column);
1765
+ }
1766
+ let origin = this.origin(line, column, endLine, endColumn);
1767
+ if (origin) {
1768
+ result2 = new CssSyntaxError$1(
1769
+ message,
1770
+ origin.endLine === void 0 ? origin.line : { column: origin.column, line: origin.line },
1771
+ origin.endLine === void 0 ? origin.column : { column: origin.endColumn, line: origin.endLine },
1772
+ origin.source,
1773
+ origin.file,
1774
+ opts.plugin
1775
+ );
1776
+ } else {
1777
+ result2 = new CssSyntaxError$1(
1778
+ message,
1779
+ endLine === void 0 ? line : { column, line },
1780
+ endLine === void 0 ? column : { column: endColumn, line: endLine },
1781
+ this.css,
1782
+ this.file,
1783
+ opts.plugin
1784
+ );
1785
+ }
1786
+ result2.input = { column, endColumn, endLine, endOffset, line, offset, source: this.css };
1787
+ if (this.file) {
1788
+ if (pathToFileURL$1) {
1789
+ result2.input.url = pathToFileURL$1(this.file).toString();
1790
+ }
1791
+ result2.input.file = this.file;
1720
1792
  }
1721
- delete this.indexes[iterator];
1722
1793
  return result2;
1723
1794
  }
1724
- every(condition) {
1725
- return this.nodes.every(condition);
1726
- }
1727
- getIterator() {
1728
- if (!this.lastEach)
1729
- this.lastEach = 0;
1730
- if (!this.indexes)
1731
- this.indexes = {};
1732
- this.lastEach += 1;
1733
- let iterator = this.lastEach;
1734
- this.indexes[iterator] = 0;
1735
- return iterator;
1795
+ fromLineAndColumn(line, column) {
1796
+ let lineToIndex = getLineToIndex(this);
1797
+ let index2 = lineToIndex[line - 1];
1798
+ return index2 + column - 1;
1736
1799
  }
1737
- getProxyProcessor() {
1738
- return {
1739
- get(node2, prop) {
1740
- if (prop === "proxyOf") {
1741
- return node2;
1742
- } else if (!node2[prop]) {
1743
- return node2[prop];
1744
- } else if (prop === "each" || typeof prop === "string" && prop.startsWith("walk")) {
1745
- return (...args) => {
1746
- return node2[prop](
1747
- ...args.map((i) => {
1748
- if (typeof i === "function") {
1749
- return (child, index2) => i(child.toProxy(), index2);
1750
- } else {
1751
- return i;
1752
- }
1753
- })
1754
- );
1755
- };
1756
- } else if (prop === "every" || prop === "some") {
1757
- return (cb) => {
1758
- return node2[prop](
1759
- (child, ...other) => cb(child.toProxy(), ...other)
1760
- );
1761
- };
1762
- } else if (prop === "root") {
1763
- return () => node2.root().toProxy();
1764
- } else if (prop === "nodes") {
1765
- return node2.nodes.map((i) => i.toProxy());
1766
- } else if (prop === "first" || prop === "last") {
1767
- return node2[prop].toProxy();
1800
+ fromOffset(offset) {
1801
+ let lineToIndex = getLineToIndex(this);
1802
+ let lastLine = lineToIndex[lineToIndex.length - 1];
1803
+ let min = 0;
1804
+ if (offset >= lastLine) {
1805
+ min = lineToIndex.length - 1;
1806
+ } else {
1807
+ let max = lineToIndex.length - 2;
1808
+ let mid;
1809
+ while (min < max) {
1810
+ mid = min + (max - min >> 1);
1811
+ if (offset < lineToIndex[mid]) {
1812
+ max = mid - 1;
1813
+ } else if (offset >= lineToIndex[mid + 1]) {
1814
+ min = mid + 1;
1768
1815
  } else {
1769
- return node2[prop];
1770
- }
1771
- },
1772
- set(node2, prop, value) {
1773
- if (node2[prop] === value)
1774
- return true;
1775
- node2[prop] = value;
1776
- if (prop === "name" || prop === "params" || prop === "selector") {
1777
- node2.markDirty();
1816
+ min = mid;
1817
+ break;
1778
1818
  }
1779
- return true;
1780
1819
  }
1820
+ }
1821
+ return {
1822
+ col: offset - lineToIndex[min] + 1,
1823
+ line: min + 1
1781
1824
  };
1782
1825
  }
1783
- index(child) {
1784
- if (typeof child === "number")
1785
- return child;
1786
- if (child.proxyOf)
1787
- child = child.proxyOf;
1788
- return this.proxyOf.nodes.indexOf(child);
1789
- }
1790
- insertAfter(exist, add) {
1791
- let existIndex = this.index(exist);
1792
- let nodes = this.normalize(add, this.proxyOf.nodes[existIndex]).reverse();
1793
- existIndex = this.index(exist);
1794
- for (let node2 of nodes)
1795
- this.proxyOf.nodes.splice(existIndex + 1, 0, node2);
1796
- let index2;
1797
- for (let id in this.indexes) {
1798
- index2 = this.indexes[id];
1799
- if (existIndex < index2) {
1800
- this.indexes[id] = index2 + nodes.length;
1801
- }
1826
+ mapResolve(file) {
1827
+ if (/^\w+:\/\//.test(file)) {
1828
+ return file;
1802
1829
  }
1803
- this.markDirty();
1804
- return this;
1830
+ return resolve$1(this.map.consumer().sourceRoot || this.map.root || ".", file);
1805
1831
  }
1806
- insertBefore(exist, add) {
1807
- let existIndex = this.index(exist);
1808
- let type = existIndex === 0 ? "prepend" : false;
1809
- let nodes = this.normalize(add, this.proxyOf.nodes[existIndex], type).reverse();
1810
- existIndex = this.index(exist);
1811
- for (let node2 of nodes)
1812
- this.proxyOf.nodes.splice(existIndex, 0, node2);
1813
- let index2;
1814
- for (let id in this.indexes) {
1815
- index2 = this.indexes[id];
1816
- if (existIndex <= index2) {
1817
- this.indexes[id] = index2 + nodes.length;
1832
+ origin(line, column, endLine, endColumn) {
1833
+ if (!this.map)
1834
+ return false;
1835
+ let consumer = this.map.consumer();
1836
+ let from = consumer.originalPositionFor({ column, line });
1837
+ if (!from.source)
1838
+ return false;
1839
+ let to;
1840
+ if (typeof endLine === "number") {
1841
+ to = consumer.originalPositionFor({ column: endColumn, line: endLine });
1842
+ }
1843
+ let fromUrl;
1844
+ if (isAbsolute(from.source)) {
1845
+ fromUrl = pathToFileURL$1(from.source);
1846
+ } else {
1847
+ fromUrl = new URL(
1848
+ from.source,
1849
+ this.map.consumer().sourceRoot || pathToFileURL$1(this.map.mapFile)
1850
+ );
1851
+ }
1852
+ let result2 = {
1853
+ column: from.column,
1854
+ endColumn: to && to.column,
1855
+ endLine: to && to.line,
1856
+ line: from.line,
1857
+ url: fromUrl.toString()
1858
+ };
1859
+ if (fromUrl.protocol === "file:") {
1860
+ if (fileURLToPath) {
1861
+ result2.file = fileURLToPath(fromUrl);
1862
+ } else {
1863
+ throw new Error(`file: protocol is not available in this PostCSS build`);
1818
1864
  }
1819
1865
  }
1820
- this.markDirty();
1821
- return this;
1866
+ let source = consumer.sourceContentFor(from.source);
1867
+ if (source)
1868
+ result2.source = source;
1869
+ return result2;
1822
1870
  }
1823
- normalize(nodes, sample) {
1824
- if (typeof nodes === "string") {
1825
- nodes = cleanSource(parse$4(nodes).nodes);
1826
- } else if (typeof nodes === "undefined") {
1827
- nodes = [];
1828
- } else if (Array.isArray(nodes)) {
1829
- nodes = nodes.slice(0);
1830
- for (let i of nodes) {
1831
- if (i.parent)
1832
- i.parent.removeChild(i, "ignore");
1871
+ toJSON() {
1872
+ let json = {};
1873
+ for (let name of ["hasBOM", "css", "file", "id"]) {
1874
+ if (this[name] != null) {
1875
+ json[name] = this[name];
1833
1876
  }
1834
- } else if (nodes.type === "root" && this.type !== "document") {
1835
- nodes = nodes.nodes.slice(0);
1836
- for (let i of nodes) {
1837
- if (i.parent)
1838
- i.parent.removeChild(i, "ignore");
1877
+ }
1878
+ if (this.map) {
1879
+ json.map = __spreadValues({}, this.map);
1880
+ if (json.map.consumerCache) {
1881
+ json.map.consumerCache = void 0;
1839
1882
  }
1840
- } else if (nodes.type) {
1841
- nodes = [nodes];
1842
- } else if (nodes.prop) {
1843
- if (typeof nodes.value === "undefined") {
1844
- throw new Error("Value field is missed in node creation");
1845
- } else if (typeof nodes.value !== "string") {
1846
- nodes.value = String(nodes.value);
1883
+ }
1884
+ return json;
1885
+ }
1886
+ };
1887
+ var input = Input$4;
1888
+ Input$4.default = Input$4;
1889
+ if (terminalHighlight && terminalHighlight.registerInput) {
1890
+ terminalHighlight.registerInput(Input$4);
1891
+ }
1892
+ let Container$4 = container;
1893
+ let LazyResult$3;
1894
+ let Processor$2;
1895
+ let Root$5 = class Root extends Container$4 {
1896
+ constructor(defaults) {
1897
+ super(defaults);
1898
+ this.type = "root";
1899
+ if (!this.nodes)
1900
+ this.nodes = [];
1901
+ }
1902
+ normalize(child, sample, type) {
1903
+ let nodes = super.normalize(child);
1904
+ if (sample) {
1905
+ if (type === "prepend") {
1906
+ if (this.nodes.length > 1) {
1907
+ sample.raws.before = this.nodes[1].raws.before;
1908
+ } else {
1909
+ delete sample.raws.before;
1910
+ }
1911
+ } else if (this.first !== sample) {
1912
+ for (let node2 of nodes) {
1913
+ node2.raws.before = sample.raws.before;
1914
+ }
1847
1915
  }
1848
- nodes = [new Declaration$3(nodes)];
1849
- } else if (nodes.selector) {
1850
- nodes = [new Rule$4(nodes)];
1851
- } else if (nodes.name) {
1852
- nodes = [new AtRule$4(nodes)];
1853
- } else if (nodes.text) {
1854
- nodes = [new Comment$3(nodes)];
1855
- } else {
1856
- throw new Error("Unknown node type in node creation");
1857
1916
  }
1858
- let processed = nodes.map((i) => {
1859
- if (!i[my$1])
1860
- Container.rebuild(i);
1861
- i = i.proxyOf;
1862
- if (i.parent)
1863
- i.parent.removeChild(i);
1864
- if (i[isClean$1])
1865
- markDirtyUp(i);
1866
- if (typeof i.raws.before === "undefined") {
1867
- if (sample && typeof sample.raws.before !== "undefined") {
1868
- i.raws.before = sample.raws.before.replace(/\S/g, "");
1917
+ return nodes;
1918
+ }
1919
+ removeChild(child, ignore) {
1920
+ let index2 = this.index(child);
1921
+ if (!ignore && index2 === 0 && this.nodes.length > 1) {
1922
+ this.nodes[1].raws.before = this.nodes[index2].raws.before;
1923
+ }
1924
+ return super.removeChild(child);
1925
+ }
1926
+ toResult(opts = {}) {
1927
+ let lazy = new LazyResult$3(new Processor$2(), this, opts);
1928
+ return lazy.stringify();
1929
+ }
1930
+ };
1931
+ Root$5.registerLazyResult = (dependant) => {
1932
+ LazyResult$3 = dependant;
1933
+ };
1934
+ Root$5.registerProcessor = (dependant) => {
1935
+ Processor$2 = dependant;
1936
+ };
1937
+ var root = Root$5;
1938
+ Root$5.default = Root$5;
1939
+ Container$4.registerRoot(Root$5);
1940
+ let list$2 = {
1941
+ comma(string) {
1942
+ return list$2.split(string, [","], true);
1943
+ },
1944
+ space(string) {
1945
+ let spaces = [" ", "\n", " "];
1946
+ return list$2.split(string, spaces);
1947
+ },
1948
+ split(string, separators, last) {
1949
+ let array = [];
1950
+ let current = "";
1951
+ let split = false;
1952
+ let func = 0;
1953
+ let inQuote = false;
1954
+ let prevQuote = "";
1955
+ let escape = false;
1956
+ for (let letter of string) {
1957
+ if (escape) {
1958
+ escape = false;
1959
+ } else if (letter === "\\") {
1960
+ escape = true;
1961
+ } else if (inQuote) {
1962
+ if (letter === prevQuote) {
1963
+ inQuote = false;
1869
1964
  }
1965
+ } else if (letter === '"' || letter === "'") {
1966
+ inQuote = true;
1967
+ prevQuote = letter;
1968
+ } else if (letter === "(") {
1969
+ func += 1;
1970
+ } else if (letter === ")") {
1971
+ if (func > 0)
1972
+ func -= 1;
1973
+ } else if (func === 0) {
1974
+ if (separators.includes(letter))
1975
+ split = true;
1870
1976
  }
1871
- i.parent = this.proxyOf;
1872
- return i;
1873
- });
1874
- return processed;
1977
+ if (split) {
1978
+ if (current !== "")
1979
+ array.push(current.trim());
1980
+ current = "";
1981
+ split = false;
1982
+ } else {
1983
+ current += letter;
1984
+ }
1985
+ }
1986
+ if (last || current !== "")
1987
+ array.push(current.trim());
1988
+ return array;
1875
1989
  }
1876
- prepend(...children) {
1877
- children = children.reverse();
1878
- for (let child of children) {
1879
- let nodes = this.normalize(child, this.first, "prepend").reverse();
1880
- for (let node2 of nodes)
1881
- this.proxyOf.nodes.unshift(node2);
1882
- for (let id in this.indexes) {
1883
- this.indexes[id] = this.indexes[id] + nodes.length;
1990
+ };
1991
+ var list_1 = list$2;
1992
+ list$2.default = list$2;
1993
+ let Container$3 = container;
1994
+ let list$1 = list_1;
1995
+ let Rule$3 = class Rule extends Container$3 {
1996
+ get selectors() {
1997
+ return list$1.comma(this.selector);
1998
+ }
1999
+ set selectors(values) {
2000
+ let match = this.selector ? this.selector.match(/,\s*/) : null;
2001
+ let sep2 = match ? match[0] : "," + this.raw("between", "beforeOpen");
2002
+ this.selector = values.join(sep2);
2003
+ }
2004
+ constructor(defaults) {
2005
+ super(defaults);
2006
+ this.type = "rule";
2007
+ if (!this.nodes)
2008
+ this.nodes = [];
2009
+ }
2010
+ };
2011
+ var rule = Rule$3;
2012
+ Rule$3.default = Rule$3;
2013
+ Container$3.registerRule(Rule$3);
2014
+ let AtRule$2 = atRule;
2015
+ let Comment$2 = comment;
2016
+ let Declaration$2 = declaration;
2017
+ let Input$3 = input;
2018
+ let PreviousMap2 = previousMap;
2019
+ let Root$4 = root;
2020
+ let Rule$2 = rule;
2021
+ function fromJSON$1(json, inputs) {
2022
+ if (Array.isArray(json))
2023
+ return json.map((n) => fromJSON$1(n));
2024
+ let _a = json, { inputs: ownInputs } = _a, defaults = __objRest(_a, ["inputs"]);
2025
+ if (ownInputs) {
2026
+ inputs = [];
2027
+ for (let input2 of ownInputs) {
2028
+ let inputHydrated = __spreadProps(__spreadValues({}, input2), { __proto__: Input$3.prototype });
2029
+ if (inputHydrated.map) {
2030
+ inputHydrated.map = __spreadProps(__spreadValues({}, inputHydrated.map), {
2031
+ __proto__: PreviousMap2.prototype
2032
+ });
1884
2033
  }
2034
+ inputs.push(inputHydrated);
1885
2035
  }
1886
- this.markDirty();
1887
- return this;
1888
- }
1889
- push(child) {
1890
- child.parent = this;
1891
- this.proxyOf.nodes.push(child);
1892
- return this;
1893
2036
  }
1894
- removeAll() {
1895
- for (let node2 of this.proxyOf.nodes)
1896
- node2.parent = void 0;
1897
- this.proxyOf.nodes = [];
1898
- this.markDirty();
1899
- return this;
2037
+ if (defaults.nodes) {
2038
+ defaults.nodes = json.nodes.map((n) => fromJSON$1(n, inputs));
1900
2039
  }
1901
- removeChild(child) {
1902
- child = this.index(child);
1903
- this.proxyOf.nodes[child].parent = void 0;
1904
- this.proxyOf.nodes.splice(child, 1);
1905
- let index2;
1906
- for (let id in this.indexes) {
1907
- index2 = this.indexes[id];
1908
- if (index2 >= child) {
1909
- this.indexes[id] = index2 - 1;
1910
- }
2040
+ if (defaults.source) {
2041
+ let _b = defaults.source, { inputId } = _b, source = __objRest(_b, ["inputId"]);
2042
+ defaults.source = source;
2043
+ if (inputId != null) {
2044
+ defaults.source.input = inputs[inputId];
1911
2045
  }
1912
- this.markDirty();
1913
- return this;
1914
2046
  }
1915
- replaceValues(pattern, opts, callback) {
1916
- if (!callback) {
1917
- callback = opts;
1918
- opts = {};
1919
- }
1920
- this.walkDecls((decl) => {
1921
- if (opts.props && !opts.props.includes(decl.prop))
1922
- return;
1923
- if (opts.fast && !decl.value.includes(opts.fast))
1924
- return;
1925
- decl.value = decl.value.replace(pattern, callback);
1926
- });
1927
- this.markDirty();
1928
- return this;
2047
+ if (defaults.type === "root") {
2048
+ return new Root$4(defaults);
2049
+ } else if (defaults.type === "decl") {
2050
+ return new Declaration$2(defaults);
2051
+ } else if (defaults.type === "rule") {
2052
+ return new Rule$2(defaults);
2053
+ } else if (defaults.type === "comment") {
2054
+ return new Comment$2(defaults);
2055
+ } else if (defaults.type === "atrule") {
2056
+ return new AtRule$2(defaults);
2057
+ } else {
2058
+ throw new Error("Unknown node type: " + json.type);
1929
2059
  }
1930
- some(condition) {
1931
- return this.nodes.some(condition);
2060
+ }
2061
+ var fromJSON_1 = fromJSON$1;
2062
+ fromJSON$1.default = fromJSON$1;
2063
+ let { dirname, relative, resolve, sep } = require$$2;
2064
+ let { SourceMapConsumer, SourceMapGenerator } = require$$2;
2065
+ let { pathToFileURL } = require$$2;
2066
+ let Input$2 = input;
2067
+ let sourceMapAvailable = Boolean(SourceMapConsumer && SourceMapGenerator);
2068
+ let pathAvailable = Boolean(dirname && resolve && relative && sep);
2069
+ let MapGenerator$2 = class MapGenerator {
2070
+ constructor(stringify2, root2, opts, cssString) {
2071
+ this.stringify = stringify2;
2072
+ this.mapOpts = opts.map || {};
2073
+ this.root = root2;
2074
+ this.opts = opts;
2075
+ this.css = cssString;
2076
+ this.originalCSS = cssString;
2077
+ this.usesFileUrls = !this.mapOpts.from && this.mapOpts.absolute;
2078
+ this.memoizedFileURLs = /* @__PURE__ */ new Map();
2079
+ this.memoizedPaths = /* @__PURE__ */ new Map();
2080
+ this.memoizedURLs = /* @__PURE__ */ new Map();
1932
2081
  }
1933
- walk(callback) {
1934
- return this.each((child, i) => {
1935
- let result2;
1936
- try {
1937
- result2 = callback(child, i);
1938
- } catch (e) {
1939
- throw child.addToError(e);
1940
- }
1941
- if (result2 !== false && child.walk) {
1942
- result2 = child.walk(callback);
2082
+ addAnnotation() {
2083
+ let content;
2084
+ if (this.isInline()) {
2085
+ content = "data:application/json;base64," + this.toBase64(this.map.toString());
2086
+ } else if (typeof this.mapOpts.annotation === "string") {
2087
+ content = this.mapOpts.annotation;
2088
+ } else if (typeof this.mapOpts.annotation === "function") {
2089
+ content = this.mapOpts.annotation(this.opts.to, this.root);
2090
+ } else {
2091
+ content = this.outputFile() + ".map";
2092
+ }
2093
+ let eol = "\n";
2094
+ if (this.css.includes("\r\n"))
2095
+ eol = "\r\n";
2096
+ this.css += eol + "/*# sourceMappingURL=" + content + " */";
2097
+ }
2098
+ applyPrevMaps() {
2099
+ for (let prev of this.previous()) {
2100
+ let from = this.toUrl(this.path(prev.file));
2101
+ let root2 = prev.root || dirname(prev.file);
2102
+ let map;
2103
+ if (this.mapOpts.sourcesContent === false) {
2104
+ map = new SourceMapConsumer(prev.text);
2105
+ if (map.sourcesContent) {
2106
+ map.sourcesContent = null;
2107
+ }
2108
+ } else {
2109
+ map = prev.consumer();
1943
2110
  }
1944
- return result2;
1945
- });
2111
+ this.map.applySourceMap(map, from, this.toUrl(this.path(root2)));
2112
+ }
1946
2113
  }
1947
- walkAtRules(name, callback) {
1948
- if (!callback) {
1949
- callback = name;
1950
- return this.walk((child, i) => {
1951
- if (child.type === "atrule") {
1952
- return callback(child, i);
2114
+ clearAnnotation() {
2115
+ if (this.mapOpts.annotation === false)
2116
+ return;
2117
+ if (this.root) {
2118
+ let node2;
2119
+ for (let i = this.root.nodes.length - 1; i >= 0; i--) {
2120
+ node2 = this.root.nodes[i];
2121
+ if (node2.type !== "comment")
2122
+ continue;
2123
+ if (node2.text.startsWith("# sourceMappingURL=")) {
2124
+ this.root.removeChild(i);
1953
2125
  }
2126
+ }
2127
+ } else if (this.css) {
2128
+ this.css = this.css.replace(/\n*\/\*#[\S\s]*?\*\/$/gm, "");
2129
+ }
2130
+ }
2131
+ generate() {
2132
+ this.clearAnnotation();
2133
+ if (pathAvailable && sourceMapAvailable && this.isMap()) {
2134
+ return this.generateMap();
2135
+ } else {
2136
+ let result2 = "";
2137
+ this.stringify(this.root, (i) => {
2138
+ result2 += i;
1954
2139
  });
2140
+ return [result2];
1955
2141
  }
1956
- if (name instanceof RegExp) {
1957
- return this.walk((child, i) => {
1958
- if (child.type === "atrule" && name.test(child.name)) {
1959
- return callback(child, i);
1960
- }
2142
+ }
2143
+ generateMap() {
2144
+ if (this.root) {
2145
+ this.generateString();
2146
+ } else if (this.previous().length === 1) {
2147
+ let prev = this.previous()[0].consumer();
2148
+ prev.file = this.outputFile();
2149
+ this.map = SourceMapGenerator.fromSourceMap(prev, {
2150
+ ignoreInvalidMapping: true
2151
+ });
2152
+ } else {
2153
+ this.map = new SourceMapGenerator({
2154
+ file: this.outputFile(),
2155
+ ignoreInvalidMapping: true
2156
+ });
2157
+ this.map.addMapping({
2158
+ generated: { column: 0, line: 1 },
2159
+ original: { column: 0, line: 1 },
2160
+ source: this.opts.from ? this.toUrl(this.path(this.opts.from)) : "<no source>"
1961
2161
  });
1962
2162
  }
1963
- return this.walk((child, i) => {
1964
- if (child.type === "atrule" && child.name === name) {
1965
- return callback(child, i);
1966
- }
1967
- });
2163
+ if (this.isSourcesContent())
2164
+ this.setSourcesContent();
2165
+ if (this.root && this.previous().length > 0)
2166
+ this.applyPrevMaps();
2167
+ if (this.isAnnotation())
2168
+ this.addAnnotation();
2169
+ if (this.isInline()) {
2170
+ return [this.css];
2171
+ } else {
2172
+ return [this.css, this.map];
2173
+ }
1968
2174
  }
1969
- walkComments(callback) {
1970
- return this.walk((child, i) => {
1971
- if (child.type === "comment") {
1972
- return callback(child, i);
2175
+ generateString() {
2176
+ this.css = "";
2177
+ this.map = new SourceMapGenerator({
2178
+ file: this.outputFile(),
2179
+ ignoreInvalidMapping: true
2180
+ });
2181
+ let line = 1;
2182
+ let column = 1;
2183
+ let noSource = "<no source>";
2184
+ let mapping = {
2185
+ generated: { column: 0, line: 0 },
2186
+ original: { column: 0, line: 0 },
2187
+ source: ""
2188
+ };
2189
+ let last, lines;
2190
+ this.stringify(this.root, (str, node2, type) => {
2191
+ this.css += str;
2192
+ if (node2 && type !== "end") {
2193
+ mapping.generated.line = line;
2194
+ mapping.generated.column = column - 1;
2195
+ if (node2.source && node2.source.start) {
2196
+ mapping.source = this.sourcePath(node2);
2197
+ mapping.original.line = node2.source.start.line;
2198
+ mapping.original.column = node2.source.start.column - 1;
2199
+ this.map.addMapping(mapping);
2200
+ } else {
2201
+ mapping.source = noSource;
2202
+ mapping.original.line = 1;
2203
+ mapping.original.column = 0;
2204
+ this.map.addMapping(mapping);
2205
+ }
2206
+ }
2207
+ lines = str.match(/\n/g);
2208
+ if (lines) {
2209
+ line += lines.length;
2210
+ last = str.lastIndexOf("\n");
2211
+ column = str.length - last;
2212
+ } else {
2213
+ column += str.length;
2214
+ }
2215
+ if (node2 && type !== "start") {
2216
+ let p = node2.parent || { raws: {} };
2217
+ let childless = node2.type === "decl" || node2.type === "atrule" && !node2.nodes;
2218
+ if (!childless || node2 !== p.last || p.raws.semicolon) {
2219
+ if (node2.source && node2.source.end) {
2220
+ mapping.source = this.sourcePath(node2);
2221
+ mapping.original.line = node2.source.end.line;
2222
+ mapping.original.column = node2.source.end.column - 1;
2223
+ mapping.generated.line = line;
2224
+ mapping.generated.column = column - 2;
2225
+ this.map.addMapping(mapping);
2226
+ } else {
2227
+ mapping.source = noSource;
2228
+ mapping.original.line = 1;
2229
+ mapping.original.column = 0;
2230
+ mapping.generated.line = line;
2231
+ mapping.generated.column = column - 1;
2232
+ this.map.addMapping(mapping);
2233
+ }
2234
+ }
1973
2235
  }
1974
2236
  });
1975
2237
  }
1976
- walkDecls(prop, callback) {
1977
- if (!callback) {
1978
- callback = prop;
1979
- return this.walk((child, i) => {
1980
- if (child.type === "decl") {
1981
- return callback(child, i);
1982
- }
1983
- });
2238
+ isAnnotation() {
2239
+ if (this.isInline()) {
2240
+ return true;
1984
2241
  }
1985
- if (prop instanceof RegExp) {
1986
- return this.walk((child, i) => {
1987
- if (child.type === "decl" && prop.test(child.prop)) {
1988
- return callback(child, i);
1989
- }
1990
- });
2242
+ if (typeof this.mapOpts.annotation !== "undefined") {
2243
+ return this.mapOpts.annotation;
1991
2244
  }
1992
- return this.walk((child, i) => {
1993
- if (child.type === "decl" && child.prop === prop) {
1994
- return callback(child, i);
1995
- }
1996
- });
2245
+ if (this.previous().length) {
2246
+ return this.previous().some((i) => i.annotation);
2247
+ }
2248
+ return true;
1997
2249
  }
1998
- walkRules(selector, callback) {
1999
- if (!callback) {
2000
- callback = selector;
2001
- return this.walk((child, i) => {
2002
- if (child.type === "rule") {
2003
- return callback(child, i);
2004
- }
2005
- });
2250
+ isInline() {
2251
+ if (typeof this.mapOpts.inline !== "undefined") {
2252
+ return this.mapOpts.inline;
2006
2253
  }
2007
- if (selector instanceof RegExp) {
2008
- return this.walk((child, i) => {
2009
- if (child.type === "rule" && selector.test(child.selector)) {
2010
- return callback(child, i);
2011
- }
2012
- });
2254
+ let annotation = this.mapOpts.annotation;
2255
+ if (typeof annotation !== "undefined" && annotation !== true) {
2256
+ return false;
2013
2257
  }
2014
- return this.walk((child, i) => {
2015
- if (child.type === "rule" && child.selector === selector) {
2016
- return callback(child, i);
2017
- }
2018
- });
2019
- }
2020
- get first() {
2021
- if (!this.proxyOf.nodes)
2022
- return void 0;
2023
- return this.proxyOf.nodes[0];
2024
- }
2025
- get last() {
2026
- if (!this.proxyOf.nodes)
2027
- return void 0;
2028
- return this.proxyOf.nodes[this.proxyOf.nodes.length - 1];
2029
- }
2030
- };
2031
- Container$7.registerParse = (dependant) => {
2032
- parse$4 = dependant;
2033
- };
2034
- Container$7.registerRule = (dependant) => {
2035
- Rule$4 = dependant;
2036
- };
2037
- Container$7.registerAtRule = (dependant) => {
2038
- AtRule$4 = dependant;
2039
- };
2040
- Container$7.registerRoot = (dependant) => {
2041
- Root$6 = dependant;
2042
- };
2043
- var container = Container$7;
2044
- Container$7.default = Container$7;
2045
- Container$7.rebuild = (node2) => {
2046
- if (node2.type === "atrule") {
2047
- Object.setPrototypeOf(node2, AtRule$4.prototype);
2048
- } else if (node2.type === "rule") {
2049
- Object.setPrototypeOf(node2, Rule$4.prototype);
2050
- } else if (node2.type === "decl") {
2051
- Object.setPrototypeOf(node2, Declaration$3.prototype);
2052
- } else if (node2.type === "comment") {
2053
- Object.setPrototypeOf(node2, Comment$3.prototype);
2054
- } else if (node2.type === "root") {
2055
- Object.setPrototypeOf(node2, Root$6.prototype);
2056
- }
2057
- node2[my$1] = true;
2058
- if (node2.nodes) {
2059
- node2.nodes.forEach((child) => {
2060
- Container$7.rebuild(child);
2061
- });
2062
- }
2063
- };
2064
- let Container$6 = container;
2065
- let LazyResult$4;
2066
- let Processor$3;
2067
- let Document$3 = class Document2 extends Container$6 {
2068
- constructor(defaults) {
2069
- super(__spreadValues({ type: "document" }, defaults));
2070
- if (!this.nodes) {
2071
- this.nodes = [];
2258
+ if (this.previous().length) {
2259
+ return this.previous().some((i) => i.inline);
2072
2260
  }
2261
+ return true;
2073
2262
  }
2074
- toResult(opts = {}) {
2075
- let lazy = new LazyResult$4(new Processor$3(), this, opts);
2076
- return lazy.stringify();
2077
- }
2078
- };
2079
- Document$3.registerLazyResult = (dependant) => {
2080
- LazyResult$4 = dependant;
2081
- };
2082
- Document$3.registerProcessor = (dependant) => {
2083
- Processor$3 = dependant;
2084
- };
2085
- var document$1 = Document$3;
2086
- Document$3.default = Document$3;
2087
- let printed = {};
2088
- var warnOnce$2 = function warnOnce(message) {
2089
- if (printed[message])
2090
- return;
2091
- printed[message] = true;
2092
- if (typeof console !== "undefined" && console.warn) {
2093
- console.warn(message);
2094
- }
2095
- };
2096
- let Warning$2 = class Warning {
2097
- constructor(text, opts = {}) {
2098
- this.type = "warning";
2099
- this.text = text;
2100
- if (opts.node && opts.node.source) {
2101
- let range = opts.node.rangeBy(opts);
2102
- this.line = range.start.line;
2103
- this.column = range.start.column;
2104
- this.endLine = range.end.line;
2105
- this.endColumn = range.end.column;
2263
+ isMap() {
2264
+ if (typeof this.opts.map !== "undefined") {
2265
+ return !!this.opts.map;
2106
2266
  }
2107
- for (let opt in opts)
2108
- this[opt] = opts[opt];
2267
+ return this.previous().length > 0;
2109
2268
  }
2110
- toString() {
2111
- if (this.node) {
2112
- return this.node.error(this.text, {
2113
- index: this.index,
2114
- plugin: this.plugin,
2115
- word: this.word
2116
- }).message;
2269
+ isSourcesContent() {
2270
+ if (typeof this.mapOpts.sourcesContent !== "undefined") {
2271
+ return this.mapOpts.sourcesContent;
2117
2272
  }
2118
- if (this.plugin) {
2119
- return this.plugin + ": " + this.text;
2273
+ if (this.previous().length) {
2274
+ return this.previous().some((i) => i.withContent());
2120
2275
  }
2121
- return this.text;
2276
+ return true;
2122
2277
  }
2123
- };
2124
- var warning = Warning$2;
2125
- Warning$2.default = Warning$2;
2126
- let Warning$1 = warning;
2127
- let Result$3 = class Result {
2128
- constructor(processor2, root2, opts) {
2129
- this.processor = processor2;
2130
- this.messages = [];
2131
- this.root = root2;
2132
- this.opts = opts;
2133
- this.css = void 0;
2134
- this.map = void 0;
2278
+ outputFile() {
2279
+ if (this.opts.to) {
2280
+ return this.path(this.opts.to);
2281
+ } else if (this.opts.from) {
2282
+ return this.path(this.opts.from);
2283
+ } else {
2284
+ return "to.css";
2285
+ }
2135
2286
  }
2136
- toString() {
2137
- return this.css;
2287
+ path(file) {
2288
+ if (this.mapOpts.absolute)
2289
+ return file;
2290
+ if (file.charCodeAt(0) === 60)
2291
+ return file;
2292
+ if (/^\w+:\/\//.test(file))
2293
+ return file;
2294
+ let cached = this.memoizedPaths.get(file);
2295
+ if (cached)
2296
+ return cached;
2297
+ let from = this.opts.to ? dirname(this.opts.to) : ".";
2298
+ if (typeof this.mapOpts.annotation === "string") {
2299
+ from = dirname(resolve(from, this.mapOpts.annotation));
2300
+ }
2301
+ let path = relative(from, file);
2302
+ this.memoizedPaths.set(file, path);
2303
+ return path;
2138
2304
  }
2139
- warn(text, opts = {}) {
2140
- if (!opts.plugin) {
2141
- if (this.lastPlugin && this.lastPlugin.postcssPlugin) {
2142
- opts.plugin = this.lastPlugin.postcssPlugin;
2305
+ previous() {
2306
+ if (!this.previousMaps) {
2307
+ this.previousMaps = [];
2308
+ if (this.root) {
2309
+ this.root.walk((node2) => {
2310
+ if (node2.source && node2.source.input.map) {
2311
+ let map = node2.source.input.map;
2312
+ if (!this.previousMaps.includes(map)) {
2313
+ this.previousMaps.push(map);
2314
+ }
2315
+ }
2316
+ });
2317
+ } else {
2318
+ let input2 = new Input$2(this.originalCSS, this.opts);
2319
+ if (input2.map)
2320
+ this.previousMaps.push(input2.map);
2143
2321
  }
2144
2322
  }
2145
- let warning2 = new Warning$1(text, opts);
2146
- this.messages.push(warning2);
2147
- return warning2;
2323
+ return this.previousMaps;
2324
+ }
2325
+ setSourcesContent() {
2326
+ let already = {};
2327
+ if (this.root) {
2328
+ this.root.walk((node2) => {
2329
+ if (node2.source) {
2330
+ let from = node2.source.input.from;
2331
+ if (from && !already[from]) {
2332
+ already[from] = true;
2333
+ let fromUrl = this.usesFileUrls ? this.toFileUrl(from) : this.toUrl(this.path(from));
2334
+ this.map.setSourceContent(fromUrl, node2.source.input.css);
2335
+ }
2336
+ }
2337
+ });
2338
+ } else if (this.css) {
2339
+ let from = this.opts.from ? this.toUrl(this.path(this.opts.from)) : "<no source>";
2340
+ this.map.setSourceContent(from, this.css);
2341
+ }
2342
+ }
2343
+ sourcePath(node2) {
2344
+ if (this.mapOpts.from) {
2345
+ return this.toUrl(this.mapOpts.from);
2346
+ } else if (this.usesFileUrls) {
2347
+ return this.toFileUrl(node2.source.input.from);
2348
+ } else {
2349
+ return this.toUrl(this.path(node2.source.input.from));
2350
+ }
2351
+ }
2352
+ toBase64(str) {
2353
+ if (Buffer) {
2354
+ return Buffer.from(str).toString("base64");
2355
+ } else {
2356
+ return window.btoa(unescape(encodeURIComponent(str)));
2357
+ }
2148
2358
  }
2149
- warnings() {
2150
- return this.messages.filter((i) => i.type === "warning");
2359
+ toFileUrl(path) {
2360
+ let cached = this.memoizedFileURLs.get(path);
2361
+ if (cached)
2362
+ return cached;
2363
+ if (pathToFileURL) {
2364
+ let fileURL = pathToFileURL(path).toString();
2365
+ this.memoizedFileURLs.set(path, fileURL);
2366
+ return fileURL;
2367
+ } else {
2368
+ throw new Error(
2369
+ "`map.absolute` option is not available in this PostCSS build"
2370
+ );
2371
+ }
2151
2372
  }
2152
- get content() {
2153
- return this.css;
2373
+ toUrl(path) {
2374
+ let cached = this.memoizedURLs.get(path);
2375
+ if (cached)
2376
+ return cached;
2377
+ if (sep === "\\") {
2378
+ path = path.replace(/\\/g, "/");
2379
+ }
2380
+ let url = encodeURI(path).replace(/[#?]/g, encodeURIComponent);
2381
+ this.memoizedURLs.set(path, url);
2382
+ return url;
2154
2383
  }
2155
2384
  };
2156
- var result = Result$3;
2157
- Result$3.default = Result$3;
2385
+ var mapGenerator = MapGenerator$2;
2158
2386
  const SINGLE_QUOTE = "'".charCodeAt(0);
2159
2387
  const DOUBLE_QUOTE = '"'.charCodeAt(0);
2160
2388
  const BACKSLASH = "\\".charCodeAt(0);
@@ -2181,8 +2409,8 @@ const RE_HEX_ESCAPE = /[\da-f]/i;
2181
2409
  var tokenize = function tokenizer(input2, options = {}) {
2182
2410
  let css = input2.css.valueOf();
2183
2411
  let ignore = options.ignoreErrors;
2184
- let code, next, quote, content, escape;
2185
- let escaped, escapePos, prev, n, currentToken;
2412
+ let code, content, escape, next, quote;
2413
+ let currentToken, escaped, escapePos, n, prev;
2186
2414
  let length = css.length;
2187
2415
  let pos = 0;
2188
2416
  let buffer = [];
@@ -2365,154 +2593,12 @@ var tokenize = function tokenizer(input2, options = {}) {
2365
2593
  position
2366
2594
  };
2367
2595
  };
2368
- let Container$5 = container;
2369
- let AtRule$3 = class AtRule extends Container$5 {
2370
- constructor(defaults) {
2371
- super(defaults);
2372
- this.type = "atrule";
2373
- }
2374
- append(...children) {
2375
- if (!this.proxyOf.nodes)
2376
- this.nodes = [];
2377
- return super.append(...children);
2378
- }
2379
- prepend(...children) {
2380
- if (!this.proxyOf.nodes)
2381
- this.nodes = [];
2382
- return super.prepend(...children);
2383
- }
2384
- };
2385
- var atRule = AtRule$3;
2386
- AtRule$3.default = AtRule$3;
2387
- Container$5.registerAtRule(AtRule$3);
2388
- let Container$4 = container;
2389
- let LazyResult$3;
2390
- let Processor$2;
2391
- let Root$5 = class Root extends Container$4 {
2392
- constructor(defaults) {
2393
- super(defaults);
2394
- this.type = "root";
2395
- if (!this.nodes)
2396
- this.nodes = [];
2397
- }
2398
- normalize(child, sample, type) {
2399
- let nodes = super.normalize(child);
2400
- if (sample) {
2401
- if (type === "prepend") {
2402
- if (this.nodes.length > 1) {
2403
- sample.raws.before = this.nodes[1].raws.before;
2404
- } else {
2405
- delete sample.raws.before;
2406
- }
2407
- } else if (this.first !== sample) {
2408
- for (let node2 of nodes) {
2409
- node2.raws.before = sample.raws.before;
2410
- }
2411
- }
2412
- }
2413
- return nodes;
2414
- }
2415
- removeChild(child, ignore) {
2416
- let index2 = this.index(child);
2417
- if (!ignore && index2 === 0 && this.nodes.length > 1) {
2418
- this.nodes[1].raws.before = this.nodes[index2].raws.before;
2419
- }
2420
- return super.removeChild(child);
2421
- }
2422
- toResult(opts = {}) {
2423
- let lazy = new LazyResult$3(new Processor$2(), this, opts);
2424
- return lazy.stringify();
2425
- }
2426
- };
2427
- Root$5.registerLazyResult = (dependant) => {
2428
- LazyResult$3 = dependant;
2429
- };
2430
- Root$5.registerProcessor = (dependant) => {
2431
- Processor$2 = dependant;
2432
- };
2433
- var root = Root$5;
2434
- Root$5.default = Root$5;
2435
- Container$4.registerRoot(Root$5);
2436
- let list$2 = {
2437
- comma(string) {
2438
- return list$2.split(string, [","], true);
2439
- },
2440
- space(string) {
2441
- let spaces = [" ", "\n", " "];
2442
- return list$2.split(string, spaces);
2443
- },
2444
- split(string, separators, last) {
2445
- let array = [];
2446
- let current = "";
2447
- let split = false;
2448
- let func = 0;
2449
- let inQuote = false;
2450
- let prevQuote = "";
2451
- let escape = false;
2452
- for (let letter of string) {
2453
- if (escape) {
2454
- escape = false;
2455
- } else if (letter === "\\") {
2456
- escape = true;
2457
- } else if (inQuote) {
2458
- if (letter === prevQuote) {
2459
- inQuote = false;
2460
- }
2461
- } else if (letter === '"' || letter === "'") {
2462
- inQuote = true;
2463
- prevQuote = letter;
2464
- } else if (letter === "(") {
2465
- func += 1;
2466
- } else if (letter === ")") {
2467
- if (func > 0)
2468
- func -= 1;
2469
- } else if (func === 0) {
2470
- if (separators.includes(letter))
2471
- split = true;
2472
- }
2473
- if (split) {
2474
- if (current !== "")
2475
- array.push(current.trim());
2476
- current = "";
2477
- split = false;
2478
- } else {
2479
- current += letter;
2480
- }
2481
- }
2482
- if (last || current !== "")
2483
- array.push(current.trim());
2484
- return array;
2485
- }
2486
- };
2487
- var list_1 = list$2;
2488
- list$2.default = list$2;
2489
- let Container$3 = container;
2490
- let list$1 = list_1;
2491
- let Rule$3 = class Rule extends Container$3 {
2492
- constructor(defaults) {
2493
- super(defaults);
2494
- this.type = "rule";
2495
- if (!this.nodes)
2496
- this.nodes = [];
2497
- }
2498
- get selectors() {
2499
- return list$1.comma(this.selector);
2500
- }
2501
- set selectors(values) {
2502
- let match = this.selector ? this.selector.match(/,\s*/) : null;
2503
- let sep2 = match ? match[0] : "," + this.raw("between", "beforeOpen");
2504
- this.selector = values.join(sep2);
2505
- }
2506
- };
2507
- var rule = Rule$3;
2508
- Rule$3.default = Rule$3;
2509
- Container$3.registerRule(Rule$3);
2510
- let Declaration$2 = declaration;
2596
+ let AtRule$1 = atRule;
2597
+ let Comment$1 = comment;
2598
+ let Declaration$1 = declaration;
2599
+ let Root$3 = root;
2600
+ let Rule$1 = rule;
2511
2601
  let tokenizer2 = tokenize;
2512
- let Comment$2 = comment;
2513
- let AtRule$2 = atRule;
2514
- let Root$4 = root;
2515
- let Rule$2 = rule;
2516
2602
  const SAFE_COMMENT_NEIGHBOR = {
2517
2603
  empty: true,
2518
2604
  space: true
@@ -2528,7 +2614,7 @@ function findLastWithPosition(tokens) {
2528
2614
  let Parser$1 = class Parser {
2529
2615
  constructor(input2) {
2530
2616
  this.input = input2;
2531
- this.root = new Root$4();
2617
+ this.root = new Root$3();
2532
2618
  this.current = this.root;
2533
2619
  this.spaces = "";
2534
2620
  this.semicolon = false;
@@ -2536,7 +2622,7 @@ let Parser$1 = class Parser {
2536
2622
  this.root.source = { input: input2, start: { column: 1, line: 1, offset: 0 } };
2537
2623
  }
2538
2624
  atrule(token) {
2539
- let node2 = new AtRule$2();
2625
+ let node2 = new AtRule$1();
2540
2626
  node2.name = token[1].slice(1);
2541
2627
  if (node2.name === "") {
2542
2628
  this.unnamedAtrule(node2, token);
@@ -2619,8 +2705,8 @@ let Parser$1 = class Parser {
2619
2705
  return;
2620
2706
  let founded = 0;
2621
2707
  let token;
2622
- for (let j = colon - 1; j >= 0; j--) {
2623
- token = tokens[j];
2708
+ for (let j2 = colon - 1; j2 >= 0; j2--) {
2709
+ token = tokens[j2];
2624
2710
  if (token[0] !== "space") {
2625
2711
  founded += 1;
2626
2712
  if (founded === 2)
@@ -2634,7 +2720,7 @@ let Parser$1 = class Parser {
2634
2720
  }
2635
2721
  colon(tokens) {
2636
2722
  let brackets = 0;
2637
- let token, type, prev;
2723
+ let prev, token, type;
2638
2724
  for (let [i, element] of tokens.entries()) {
2639
2725
  token = element;
2640
2726
  type = token[0];
@@ -2658,7 +2744,7 @@ let Parser$1 = class Parser {
2658
2744
  return false;
2659
2745
  }
2660
2746
  comment(token) {
2661
- let node2 = new Comment$2();
2747
+ let node2 = new Comment$1();
2662
2748
  this.init(node2, token[2]);
2663
2749
  node2.source.end = this.getPosition(token[3] || token[2]);
2664
2750
  node2.source.end.offset++;
@@ -2678,7 +2764,7 @@ let Parser$1 = class Parser {
2678
2764
  this.tokenizer = tokenizer2(this.input);
2679
2765
  }
2680
2766
  decl(tokens, customProperty) {
2681
- let node2 = new Declaration$2();
2767
+ let node2 = new Declaration$1();
2682
2768
  this.init(node2, tokens[0][2]);
2683
2769
  let last = tokens[tokens.length - 1];
2684
2770
  if (last[0] === ";") {
@@ -2742,14 +2828,14 @@ let Parser$1 = class Parser {
2742
2828
  } else if (token[1].toLowerCase() === "important") {
2743
2829
  let cache = tokens.slice(0);
2744
2830
  let str = "";
2745
- for (let j = i; j > 0; j--) {
2746
- let type = cache[j][0];
2747
- if (str.trim().indexOf("!") === 0 && type !== "space") {
2831
+ for (let j2 = i; j2 > 0; j2--) {
2832
+ let type = cache[j2][0];
2833
+ if (str.trim().startsWith("!") && type !== "space") {
2748
2834
  break;
2749
2835
  }
2750
2836
  str = cache.pop()[1] + str;
2751
2837
  }
2752
- if (str.trim().indexOf("!") === 0) {
2838
+ if (str.trim().startsWith("!")) {
2753
2839
  node2.important = true;
2754
2840
  node2.raws.important = str;
2755
2841
  tokens = cache;
@@ -2777,7 +2863,7 @@ let Parser$1 = class Parser {
2777
2863
  );
2778
2864
  }
2779
2865
  emptyRule(token) {
2780
- let node2 = new Rule$2();
2866
+ let node2 = new Rule$1();
2781
2867
  this.init(node2, token[2]);
2782
2868
  node2.selector = "";
2783
2869
  node2.raws.between = "";
@@ -2814,6 +2900,8 @@ let Parser$1 = class Parser {
2814
2900
  if (prev && prev.type === "rule" && !prev.raws.ownSemicolon) {
2815
2901
  prev.raws.ownSemicolon = this.spaces;
2816
2902
  this.spaces = "";
2903
+ prev.source.end = this.getPosition(token[2]);
2904
+ prev.source.end.offset += prev.raws.ownSemicolon.length;
2817
2905
  }
2818
2906
  }
2819
2907
  }
@@ -2967,7 +3055,7 @@ let Parser$1 = class Parser {
2967
3055
  }
2968
3056
  rule(tokens) {
2969
3057
  tokens.pop();
2970
- let node2 = new Rule$2();
3058
+ let node2 = new Rule$1();
2971
3059
  this.init(node2, tokens[0][2]);
2972
3060
  node2.raws.between = this.spacesAndCommentsFromEnd(tokens);
2973
3061
  this.raw(node2, "selector", tokens);
@@ -3035,7 +3123,7 @@ let Parser$1 = class Parser {
3035
3123
  }
3036
3124
  unknownWord(tokens) {
3037
3125
  throw this.input.error(
3038
- "Unknown word",
3126
+ "Unknown word " + tokens[0][1],
3039
3127
  { offset: tokens[0][2] },
3040
3128
  { offset: tokens[0][2] + tokens[0][1].length }
3041
3129
  );
@@ -3047,44 +3135,115 @@ let Parser$1 = class Parser {
3047
3135
  { offset: token[2] + token[1].length }
3048
3136
  );
3049
3137
  }
3050
- };
3051
- var parser = Parser$1;
3052
- let Container$2 = container;
3053
- let Parser2 = parser;
3054
- let Input$2 = input;
3055
- function parse$3(css, opts) {
3056
- let input2 = new Input$2(css, opts);
3057
- let parser2 = new Parser2(input2);
3058
- try {
3059
- parser2.parse();
3060
- } catch (e) {
3061
- if (true) {
3062
- if (e.name === "CssSyntaxError" && opts && opts.from) {
3063
- if (/\.scss$/i.test(opts.from)) {
3064
- e.message += "\nYou tried to parse SCSS with the standard CSS parser; try again with the postcss-scss parser";
3065
- } else if (/\.sass/i.test(opts.from)) {
3066
- e.message += "\nYou tried to parse Sass with the standard CSS parser; try again with the postcss-sass parser";
3067
- } else if (/\.less$/i.test(opts.from)) {
3068
- e.message += "\nYou tried to parse Less with the standard CSS parser; try again with the postcss-less parser";
3069
- }
3138
+ };
3139
+ var parser = Parser$1;
3140
+ let Container$2 = container;
3141
+ let Input$1 = input;
3142
+ let Parser2 = parser;
3143
+ function parse$3(css, opts) {
3144
+ let input2 = new Input$1(css, opts);
3145
+ let parser2 = new Parser2(input2);
3146
+ try {
3147
+ parser2.parse();
3148
+ } catch (e) {
3149
+ if (true) {
3150
+ if (e.name === "CssSyntaxError" && opts && opts.from) {
3151
+ if (/\.scss$/i.test(opts.from)) {
3152
+ e.message += "\nYou tried to parse SCSS with the standard CSS parser; try again with the postcss-scss parser";
3153
+ } else if (/\.sass/i.test(opts.from)) {
3154
+ e.message += "\nYou tried to parse Sass with the standard CSS parser; try again with the postcss-sass parser";
3155
+ } else if (/\.less$/i.test(opts.from)) {
3156
+ e.message += "\nYou tried to parse Less with the standard CSS parser; try again with the postcss-less parser";
3157
+ }
3158
+ }
3159
+ }
3160
+ throw e;
3161
+ }
3162
+ return parser2.root;
3163
+ }
3164
+ var parse_1 = parse$3;
3165
+ parse$3.default = parse$3;
3166
+ Container$2.registerParse(parse$3);
3167
+ let Warning$2 = class Warning {
3168
+ constructor(text, opts = {}) {
3169
+ this.type = "warning";
3170
+ this.text = text;
3171
+ if (opts.node && opts.node.source) {
3172
+ let range = opts.node.rangeBy(opts);
3173
+ this.line = range.start.line;
3174
+ this.column = range.start.column;
3175
+ this.endLine = range.end.line;
3176
+ this.endColumn = range.end.column;
3177
+ }
3178
+ for (let opt in opts)
3179
+ this[opt] = opts[opt];
3180
+ }
3181
+ toString() {
3182
+ if (this.node) {
3183
+ return this.node.error(this.text, {
3184
+ index: this.index,
3185
+ plugin: this.plugin,
3186
+ word: this.word
3187
+ }).message;
3188
+ }
3189
+ if (this.plugin) {
3190
+ return this.plugin + ": " + this.text;
3191
+ }
3192
+ return this.text;
3193
+ }
3194
+ };
3195
+ var warning = Warning$2;
3196
+ Warning$2.default = Warning$2;
3197
+ let Warning$1 = warning;
3198
+ let Result$3 = class Result {
3199
+ get content() {
3200
+ return this.css;
3201
+ }
3202
+ constructor(processor2, root2, opts) {
3203
+ this.processor = processor2;
3204
+ this.messages = [];
3205
+ this.root = root2;
3206
+ this.opts = opts;
3207
+ this.css = "";
3208
+ this.map = void 0;
3209
+ }
3210
+ toString() {
3211
+ return this.css;
3212
+ }
3213
+ warn(text, opts = {}) {
3214
+ if (!opts.plugin) {
3215
+ if (this.lastPlugin && this.lastPlugin.postcssPlugin) {
3216
+ opts.plugin = this.lastPlugin.postcssPlugin;
3070
3217
  }
3071
3218
  }
3072
- throw e;
3219
+ let warning2 = new Warning$1(text, opts);
3220
+ this.messages.push(warning2);
3221
+ return warning2;
3073
3222
  }
3074
- return parser2.root;
3075
- }
3076
- var parse_1 = parse$3;
3077
- parse$3.default = parse$3;
3078
- Container$2.registerParse(parse$3);
3079
- let { isClean, my } = symbols;
3223
+ warnings() {
3224
+ return this.messages.filter((i) => i.type === "warning");
3225
+ }
3226
+ };
3227
+ var result = Result$3;
3228
+ Result$3.default = Result$3;
3229
+ let printed = {};
3230
+ var warnOnce$2 = function warnOnce(message) {
3231
+ if (printed[message])
3232
+ return;
3233
+ printed[message] = true;
3234
+ if (typeof console !== "undefined" && console.warn) {
3235
+ console.warn(message);
3236
+ }
3237
+ };
3238
+ let Container$1 = container;
3239
+ let Document$3 = document$1;
3080
3240
  let MapGenerator$1 = mapGenerator;
3241
+ let parse$2 = parse_1;
3242
+ let Result$2 = result;
3243
+ let Root$2 = root;
3081
3244
  let stringify$2 = stringify_1;
3082
- let Container$1 = container;
3083
- let Document$2 = document$1;
3245
+ let { isClean, my } = symbols;
3084
3246
  let warnOnce$1 = warnOnce$2;
3085
- let Result$2 = result;
3086
- let parse$2 = parse_1;
3087
- let Root$3 = root;
3088
3247
  const TYPE_TO_CLASS_NAME = {
3089
3248
  atrule: "AtRule",
3090
3249
  comment: "Comment",
@@ -3170,6 +3329,30 @@ function cleanMarks(node2) {
3170
3329
  }
3171
3330
  let postcss$2 = {};
3172
3331
  let LazyResult$2 = class LazyResult {
3332
+ get content() {
3333
+ return this.stringify().content;
3334
+ }
3335
+ get css() {
3336
+ return this.stringify().css;
3337
+ }
3338
+ get map() {
3339
+ return this.stringify().map;
3340
+ }
3341
+ get messages() {
3342
+ return this.sync().messages;
3343
+ }
3344
+ get opts() {
3345
+ return this.result.opts;
3346
+ }
3347
+ get processor() {
3348
+ return this.result.processor;
3349
+ }
3350
+ get root() {
3351
+ return this.sync().root;
3352
+ }
3353
+ get [Symbol.toStringTag]() {
3354
+ return "LazyResult";
3355
+ }
3173
3356
  constructor(processor2, css, opts) {
3174
3357
  this.stringified = false;
3175
3358
  this.processed = false;
@@ -3531,17 +3714,31 @@ let LazyResult$2 = class LazyResult {
3531
3714
  warnings() {
3532
3715
  return this.sync().warnings();
3533
3716
  }
3717
+ };
3718
+ LazyResult$2.registerPostcss = (dependant) => {
3719
+ postcss$2 = dependant;
3720
+ };
3721
+ var lazyResult = LazyResult$2;
3722
+ LazyResult$2.default = LazyResult$2;
3723
+ Root$2.registerLazyResult(LazyResult$2);
3724
+ Document$3.registerLazyResult(LazyResult$2);
3725
+ let MapGenerator2 = mapGenerator;
3726
+ let parse$1 = parse_1;
3727
+ const Result$1 = result;
3728
+ let stringify$1 = stringify_1;
3729
+ let warnOnce2 = warnOnce$2;
3730
+ let NoWorkResult$1 = class NoWorkResult {
3534
3731
  get content() {
3535
- return this.stringify().content;
3732
+ return this.result.css;
3536
3733
  }
3537
3734
  get css() {
3538
- return this.stringify().css;
3735
+ return this.result.css;
3539
3736
  }
3540
3737
  get map() {
3541
- return this.stringify().map;
3738
+ return this.result.map;
3542
3739
  }
3543
3740
  get messages() {
3544
- return this.sync().messages;
3741
+ return [];
3545
3742
  }
3546
3743
  get opts() {
3547
3744
  return this.result.opts;
@@ -3550,25 +3747,26 @@ let LazyResult$2 = class LazyResult {
3550
3747
  return this.result.processor;
3551
3748
  }
3552
3749
  get root() {
3553
- return this.sync().root;
3750
+ if (this._root) {
3751
+ return this._root;
3752
+ }
3753
+ let root2;
3754
+ let parser2 = parse$1;
3755
+ try {
3756
+ root2 = parser2(this._css, this._opts);
3757
+ } catch (error) {
3758
+ this.error = error;
3759
+ }
3760
+ if (this.error) {
3761
+ throw this.error;
3762
+ } else {
3763
+ this._root = root2;
3764
+ return root2;
3765
+ }
3554
3766
  }
3555
3767
  get [Symbol.toStringTag]() {
3556
- return "LazyResult";
3768
+ return "NoWorkResult";
3557
3769
  }
3558
- };
3559
- LazyResult$2.registerPostcss = (dependant) => {
3560
- postcss$2 = dependant;
3561
- };
3562
- var lazyResult = LazyResult$2;
3563
- LazyResult$2.default = LazyResult$2;
3564
- Root$3.registerLazyResult(LazyResult$2);
3565
- Document$2.registerLazyResult(LazyResult$2);
3566
- let MapGenerator2 = mapGenerator;
3567
- let stringify$1 = stringify_1;
3568
- let warnOnce2 = warnOnce$2;
3569
- let parse$1 = parse_1;
3570
- const Result$1 = result;
3571
- let NoWorkResult$1 = class NoWorkResult {
3572
3770
  constructor(processor2, css, opts) {
3573
3771
  css = css.toString();
3574
3772
  this.stringified = false;
@@ -3632,55 +3830,16 @@ let NoWorkResult$1 = class NoWorkResult {
3632
3830
  warnings() {
3633
3831
  return [];
3634
3832
  }
3635
- get content() {
3636
- return this.result.css;
3637
- }
3638
- get css() {
3639
- return this.result.css;
3640
- }
3641
- get map() {
3642
- return this.result.map;
3643
- }
3644
- get messages() {
3645
- return [];
3646
- }
3647
- get opts() {
3648
- return this.result.opts;
3649
- }
3650
- get processor() {
3651
- return this.result.processor;
3652
- }
3653
- get root() {
3654
- if (this._root) {
3655
- return this._root;
3656
- }
3657
- let root2;
3658
- let parser2 = parse$1;
3659
- try {
3660
- root2 = parser2(this._css, this._opts);
3661
- } catch (error) {
3662
- this.error = error;
3663
- }
3664
- if (this.error) {
3665
- throw this.error;
3666
- } else {
3667
- this._root = root2;
3668
- return root2;
3669
- }
3670
- }
3671
- get [Symbol.toStringTag]() {
3672
- return "NoWorkResult";
3673
- }
3674
3833
  };
3675
3834
  var noWorkResult = NoWorkResult$1;
3676
3835
  NoWorkResult$1.default = NoWorkResult$1;
3677
- let NoWorkResult2 = noWorkResult;
3836
+ let Document$2 = document$1;
3678
3837
  let LazyResult$1 = lazyResult;
3679
- let Document$1 = document$1;
3680
- let Root$2 = root;
3838
+ let NoWorkResult2 = noWorkResult;
3839
+ let Root$1 = root;
3681
3840
  let Processor$1 = class Processor {
3682
3841
  constructor(plugins = []) {
3683
- this.version = "8.4.38";
3842
+ this.version = "8.5.6";
3684
3843
  this.plugins = this.normalize(plugins);
3685
3844
  }
3686
3845
  normalize(plugins) {
@@ -3723,75 +3882,26 @@ let Processor$1 = class Processor {
3723
3882
  };
3724
3883
  var processor = Processor$1;
3725
3884
  Processor$1.default = Processor$1;
3726
- Root$2.registerProcessor(Processor$1);
3727
- Document$1.registerProcessor(Processor$1);
3728
- let Declaration$1 = declaration;
3729
- let PreviousMap2 = previousMap;
3730
- let Comment$1 = comment;
3731
- let AtRule$1 = atRule;
3732
- let Input$1 = input;
3733
- let Root$1 = root;
3734
- let Rule$1 = rule;
3735
- function fromJSON$1(json, inputs) {
3736
- if (Array.isArray(json))
3737
- return json.map((n) => fromJSON$1(n));
3738
- let _a = json, { inputs: ownInputs } = _a, defaults = __objRest(_a, ["inputs"]);
3739
- if (ownInputs) {
3740
- inputs = [];
3741
- for (let input2 of ownInputs) {
3742
- let inputHydrated = __spreadProps(__spreadValues({}, input2), { __proto__: Input$1.prototype });
3743
- if (inputHydrated.map) {
3744
- inputHydrated.map = __spreadProps(__spreadValues({}, inputHydrated.map), {
3745
- __proto__: PreviousMap2.prototype
3746
- });
3747
- }
3748
- inputs.push(inputHydrated);
3749
- }
3750
- }
3751
- if (defaults.nodes) {
3752
- defaults.nodes = json.nodes.map((n) => fromJSON$1(n, inputs));
3753
- }
3754
- if (defaults.source) {
3755
- let _b = defaults.source, { inputId } = _b, source = __objRest(_b, ["inputId"]);
3756
- defaults.source = source;
3757
- if (inputId != null) {
3758
- defaults.source.input = inputs[inputId];
3759
- }
3760
- }
3761
- if (defaults.type === "root") {
3762
- return new Root$1(defaults);
3763
- } else if (defaults.type === "decl") {
3764
- return new Declaration$1(defaults);
3765
- } else if (defaults.type === "rule") {
3766
- return new Rule$1(defaults);
3767
- } else if (defaults.type === "comment") {
3768
- return new Comment$1(defaults);
3769
- } else if (defaults.type === "atrule") {
3770
- return new AtRule$1(defaults);
3771
- } else {
3772
- throw new Error("Unknown node type: " + json.type);
3773
- }
3774
- }
3775
- var fromJSON_1 = fromJSON$1;
3776
- fromJSON$1.default = fromJSON$1;
3885
+ Root$1.registerProcessor(Processor$1);
3886
+ Document$2.registerProcessor(Processor$1);
3887
+ let AtRule2 = atRule;
3888
+ let Comment2 = comment;
3889
+ let Container2 = container;
3777
3890
  let CssSyntaxError2 = cssSyntaxError;
3778
3891
  let Declaration2 = declaration;
3779
- let LazyResult2 = lazyResult;
3780
- let Container2 = container;
3781
- let Processor2 = processor;
3782
- let stringify = stringify_1;
3892
+ let Document$1 = document$1;
3783
3893
  let fromJSON = fromJSON_1;
3784
- let Document22 = document$1;
3785
- let Warning2 = warning;
3786
- let Comment2 = comment;
3787
- let AtRule2 = atRule;
3788
- let Result2 = result;
3789
3894
  let Input2 = input;
3790
- let parse = parse_1;
3895
+ let LazyResult2 = lazyResult;
3791
3896
  let list = list_1;
3792
- let Rule2 = rule;
3793
- let Root2 = root;
3794
3897
  let Node$1 = node;
3898
+ let parse = parse_1;
3899
+ let Processor2 = processor;
3900
+ let Result2 = result;
3901
+ let Root2 = root;
3902
+ let Rule2 = rule;
3903
+ let stringify = stringify_1;
3904
+ let Warning2 = warning;
3795
3905
  function postcss(...plugins) {
3796
3906
  if (plugins.length === 1 && Array.isArray(plugins[0])) {
3797
3907
  plugins = plugins[0];
@@ -3839,12 +3949,12 @@ postcss.atRule = (defaults) => new AtRule2(defaults);
3839
3949
  postcss.decl = (defaults) => new Declaration2(defaults);
3840
3950
  postcss.rule = (defaults) => new Rule2(defaults);
3841
3951
  postcss.root = (defaults) => new Root2(defaults);
3842
- postcss.document = (defaults) => new Document22(defaults);
3952
+ postcss.document = (defaults) => new Document$1(defaults);
3843
3953
  postcss.CssSyntaxError = CssSyntaxError2;
3844
3954
  postcss.Declaration = Declaration2;
3845
3955
  postcss.Container = Container2;
3846
3956
  postcss.Processor = Processor2;
3847
- postcss.Document = Document22;
3957
+ postcss.Document = Document$1;
3848
3958
  postcss.Comment = Comment2;
3849
3959
  postcss.Warning = Warning2;
3850
3960
  postcss.AtRule = AtRule2;
@@ -5095,6 +5205,7 @@ class Mirror2 {
5095
5205
  constructor() {
5096
5206
  __publicField(this, "idNodeMap", /* @__PURE__ */ new Map());
5097
5207
  __publicField(this, "nodeMetaMap", /* @__PURE__ */ new WeakMap());
5208
+ __publicField(this, "selectorNodeMap", /* @__PURE__ */ new Map());
5098
5209
  }
5099
5210
  getId(n) {
5100
5211
  var _a;
@@ -5117,6 +5228,16 @@ class Mirror2 {
5117
5228
  removeNodeFromMap(n) {
5118
5229
  const id = this.getId(n);
5119
5230
  this.idNodeMap.delete(id);
5231
+ const meta = this.getMeta(n);
5232
+ if (meta == null ? void 0 : meta.selector) {
5233
+ const nodes = this.selectorNodeMap.get(meta.selector);
5234
+ if (nodes) {
5235
+ nodes.delete(n);
5236
+ if (nodes.size === 0) {
5237
+ this.selectorNodeMap.delete(meta.selector);
5238
+ }
5239
+ }
5240
+ }
5120
5241
  if (n.childNodes) {
5121
5242
  n.childNodes.forEach((childNode) => this.removeNodeFromMap(childNode));
5122
5243
  }
@@ -5131,19 +5252,50 @@ class Mirror2 {
5131
5252
  const id = meta.id;
5132
5253
  this.idNodeMap.set(id, n);
5133
5254
  this.nodeMetaMap.set(n, meta);
5255
+ if (meta.selector) {
5256
+ let nodes = this.selectorNodeMap.get(meta.selector);
5257
+ if (!nodes) {
5258
+ nodes = /* @__PURE__ */ new Set();
5259
+ this.selectorNodeMap.set(meta.selector, nodes);
5260
+ }
5261
+ nodes.add(n);
5262
+ }
5134
5263
  }
5135
5264
  replace(id, n) {
5136
5265
  const oldNode = this.getNode(id);
5137
5266
  if (oldNode) {
5138
5267
  const meta = this.nodeMetaMap.get(oldNode);
5139
- if (meta)
5268
+ if (meta) {
5140
5269
  this.nodeMetaMap.set(n, meta);
5270
+ if (meta.selector) {
5271
+ const nodes = this.selectorNodeMap.get(meta.selector);
5272
+ if (nodes) {
5273
+ nodes.delete(oldNode);
5274
+ nodes.add(n);
5275
+ }
5276
+ }
5277
+ }
5141
5278
  }
5142
5279
  this.idNodeMap.set(id, n);
5143
5280
  }
5144
5281
  reset() {
5145
5282
  this.idNodeMap = /* @__PURE__ */ new Map();
5146
5283
  this.nodeMetaMap = /* @__PURE__ */ new WeakMap();
5284
+ this.selectorNodeMap = /* @__PURE__ */ new Map();
5285
+ }
5286
+ getNodeBySelector(selector) {
5287
+ const nodes = this.selectorNodeMap.get(selector);
5288
+ if (!nodes || nodes.size === 0)
5289
+ return null;
5290
+ return nodes.values().next().value || null;
5291
+ }
5292
+ getNodesBySelector(selector) {
5293
+ const nodes = this.selectorNodeMap.get(selector);
5294
+ return nodes ? Array.from(nodes) : [];
5295
+ }
5296
+ hasSelector(selector) {
5297
+ const nodes = this.selectorNodeMap.get(selector);
5298
+ return nodes !== void 0 && nodes.size > 0;
5147
5299
  }
5148
5300
  }
5149
5301
  function getDefaultSN(node2, id) {
@@ -5245,7 +5397,7 @@ exports.createOrGetNode = createOrGetNode;
5245
5397
  exports.diff = diff;
5246
5398
  exports.getDefaultSN = getDefaultSN;
5247
5399
  exports.printRRDom = printRRDom;
5248
- if (typeof module.exports == "object" && typeof exports == "object") {
5400
+ ;if (typeof module.exports == "object" && typeof exports == "object") {
5249
5401
  var __cp = (to, from, except, desc) => {
5250
5402
  if ((from && typeof from === "object") || typeof from === "function") {
5251
5403
  for (let key of Object.getOwnPropertyNames(from)) {