@posthog/rrdom 0.0.6 → 0.0.8

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.
package/dist/rrdom.cjs CHANGED
@@ -94,7 +94,7 @@ function getAugmentedNamespace(n) {
94
94
  var picocolors_browser = { exports: {} };
95
95
  var x = String;
96
96
  var create = function() {
97
- 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 };
97
+ 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 };
98
98
  };
99
99
  picocolors_browser.exports = create();
100
100
  picocolors_browser.exports.createColors = create;
@@ -107,8 +107,8 @@ const __viteBrowserExternal$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Ob
107
107
  const require$$2 = /* @__PURE__ */ getAugmentedNamespace(__viteBrowserExternal$1);
108
108
  let pico = picocolors_browserExports;
109
109
  let terminalHighlight$1 = require$$2;
110
- let CssSyntaxError$3 = class CssSyntaxError extends Error {
111
- constructor(message, line, column, source, file, plugin2) {
110
+ let CssSyntaxError$4 = class CssSyntaxError extends Error {
111
+ constructor(message, line, column, source, file, plugin3) {
112
112
  super(message);
113
113
  this.name = "CssSyntaxError";
114
114
  this.reason = message;
@@ -118,8 +118,8 @@ let CssSyntaxError$3 = class CssSyntaxError extends Error {
118
118
  if (source) {
119
119
  this.source = source;
120
120
  }
121
- if (plugin2) {
122
- this.plugin = plugin2;
121
+ if (plugin3) {
122
+ this.plugin = plugin3;
123
123
  }
124
124
  if (typeof line !== "undefined" && typeof column !== "undefined") {
125
125
  if (typeof line === "number") {
@@ -149,29 +149,40 @@ let CssSyntaxError$3 = class CssSyntaxError extends Error {
149
149
  if (!this.source) return "";
150
150
  let css = this.source;
151
151
  if (color == null) color = pico.isColorSupported;
152
- if (terminalHighlight$1) {
153
- if (color) css = terminalHighlight$1(css);
154
- }
155
- let lines = css.split(/\r?\n/);
156
- let start = Math.max(this.line - 3, 0);
157
- let end = Math.min(this.line + 2, lines.length);
158
- let maxWidth = String(end).length;
159
- let mark, aside;
152
+ let aside = (text) => text;
153
+ let mark = (text) => text;
154
+ let highlight = (text) => text;
160
155
  if (color) {
161
156
  let { bold, gray, red } = pico.createColors(true);
162
157
  mark = (text) => bold(red(text));
163
158
  aside = (text) => gray(text);
164
- } else {
165
- mark = aside = (str) => str;
159
+ if (terminalHighlight$1) {
160
+ highlight = (text) => terminalHighlight$1(text);
161
+ }
166
162
  }
163
+ let lines = css.split(/\r?\n/);
164
+ let start = Math.max(this.line - 3, 0);
165
+ let end = Math.min(this.line + 2, lines.length);
166
+ let maxWidth = String(end).length;
167
167
  return lines.slice(start, end).map((line, index2) => {
168
168
  let number = start + 1 + index2;
169
169
  let gutter = " " + (" " + number).slice(-maxWidth) + " | ";
170
170
  if (number === this.line) {
171
+ if (line.length > 160) {
172
+ let padding = 20;
173
+ let subLineStart = Math.max(0, this.column - padding);
174
+ let subLineEnd = Math.max(
175
+ this.column + padding,
176
+ this.endColumn + padding
177
+ );
178
+ let subLine = line.slice(subLineStart, subLineEnd);
179
+ let spacing2 = aside(gutter.replace(/\d/g, " ")) + line.slice(0, Math.min(this.column - 1, padding - 1)).replace(/[^\t]/g, " ");
180
+ return mark(">") + aside(gutter) + highlight(subLine) + "\n " + spacing2 + mark("^");
181
+ }
171
182
  let spacing = aside(gutter.replace(/\d/g, " ")) + line.slice(0, this.column - 1).replace(/[^\t]/g, " ");
172
- return mark(">") + aside(gutter) + line + "\n " + spacing + mark("^");
183
+ return mark(">") + aside(gutter) + highlight(line) + "\n " + spacing + mark("^");
173
184
  }
174
- return " " + aside(gutter) + line;
185
+ return " " + aside(gutter) + highlight(line);
175
186
  }).join("\n");
176
187
  }
177
188
  toString() {
@@ -182,11 +193,8 @@ let CssSyntaxError$3 = class CssSyntaxError extends Error {
182
193
  return this.name + ": " + this.message + code;
183
194
  }
184
195
  };
185
- var cssSyntaxError = CssSyntaxError$3;
186
- CssSyntaxError$3.default = CssSyntaxError$3;
187
- var symbols = {};
188
- symbols.isClean = Symbol("isClean");
189
- symbols.my = Symbol("my");
196
+ var cssSyntaxError = CssSyntaxError$4;
197
+ CssSyntaxError$4.default = CssSyntaxError$4;
190
198
  const DEFAULT_RAW = {
191
199
  after: "\n",
192
200
  beforeClose: "\n",
@@ -485,16 +493,19 @@ let Stringifier$2 = class Stringifier {
485
493
  var stringifier = Stringifier$2;
486
494
  Stringifier$2.default = Stringifier$2;
487
495
  let Stringifier$1 = stringifier;
488
- function stringify$4(node2, builder) {
496
+ function stringify$5(node2, builder) {
489
497
  let str = new Stringifier$1(builder);
490
498
  str.stringify(node2);
491
499
  }
492
- var stringify_1 = stringify$4;
493
- stringify$4.default = stringify$4;
494
- let { isClean: isClean$2, my: my$2 } = symbols;
495
- let CssSyntaxError$2 = cssSyntaxError;
500
+ var stringify_1 = stringify$5;
501
+ stringify$5.default = stringify$5;
502
+ var symbols = {};
503
+ symbols.isClean = Symbol("isClean");
504
+ symbols.my = Symbol("my");
505
+ let CssSyntaxError$3 = cssSyntaxError;
496
506
  let Stringifier2 = stringifier;
497
- let stringify$3 = stringify_1;
507
+ let stringify$4 = stringify_1;
508
+ let { isClean: isClean$2, my: my$2 } = symbols;
498
509
  function cloneNode(obj, parent) {
499
510
  let cloned = new obj.constructor();
500
511
  for (let i in obj) {
@@ -517,7 +528,28 @@ function cloneNode(obj, parent) {
517
528
  }
518
529
  return cloned;
519
530
  }
520
- let Node$4 = class Node {
531
+ function sourceOffset(inputCSS, position) {
532
+ if (position && typeof position.offset !== "undefined") {
533
+ return position.offset;
534
+ }
535
+ let column = 1;
536
+ let line = 1;
537
+ let offset = 0;
538
+ for (let i = 0; i < inputCSS.length; i++) {
539
+ if (line === position.line && column === position.column) {
540
+ offset = i;
541
+ break;
542
+ }
543
+ if (inputCSS[i] === "\n") {
544
+ column = 1;
545
+ line += 1;
546
+ } else {
547
+ column += 1;
548
+ }
549
+ }
550
+ return offset;
551
+ }
552
+ let Node$5 = class Node {
521
553
  constructor(defaults = {}) {
522
554
  this.raws = {};
523
555
  this[isClean$2] = false;
@@ -594,7 +626,7 @@ let Node$4 = class Node {
594
626
  opts
595
627
  );
596
628
  }
597
- return new CssSyntaxError$2(message);
629
+ return new CssSyntaxError$3(message);
598
630
  }
599
631
  getProxyProcessor() {
600
632
  return {
@@ -618,6 +650,10 @@ let Node$4 = class Node {
618
650
  }
619
651
  };
620
652
  }
653
+ /* c8 ignore next 3 */
654
+ markClean() {
655
+ this[isClean$2] = true;
656
+ }
621
657
  markDirty() {
622
658
  if (this[isClean$2]) {
623
659
  this[isClean$2] = false;
@@ -632,23 +668,29 @@ let Node$4 = class Node {
632
668
  let index2 = this.parent.index(this);
633
669
  return this.parent.nodes[index2 + 1];
634
670
  }
635
- positionBy(opts, stringRepresentation) {
671
+ positionBy(opts) {
636
672
  let pos = this.source.start;
637
673
  if (opts.index) {
638
- pos = this.positionInside(opts.index, stringRepresentation);
674
+ pos = this.positionInside(opts.index);
639
675
  } else if (opts.word) {
640
- stringRepresentation = this.toString();
676
+ let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
677
+ let stringRepresentation = inputString.slice(
678
+ sourceOffset(inputString, this.source.start),
679
+ sourceOffset(inputString, this.source.end)
680
+ );
641
681
  let index2 = stringRepresentation.indexOf(opts.word);
642
- if (index2 !== -1) pos = this.positionInside(index2, stringRepresentation);
682
+ if (index2 !== -1) pos = this.positionInside(index2);
643
683
  }
644
684
  return pos;
645
685
  }
646
- positionInside(index2, stringRepresentation) {
647
- let string = stringRepresentation || this.toString();
686
+ positionInside(index2) {
648
687
  let column = this.source.start.column;
649
688
  let line = this.source.start.line;
650
- for (let i = 0; i < index2; i++) {
651
- if (string[i] === "\n") {
689
+ let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
690
+ let offset = sourceOffset(inputString, this.source.start);
691
+ let end = offset + index2;
692
+ for (let i = offset; i < end; i++) {
693
+ if (inputString[i] === "\n") {
652
694
  column = 1;
653
695
  line += 1;
654
696
  } else {
@@ -675,11 +717,17 @@ let Node$4 = class Node {
675
717
  line: start.line
676
718
  };
677
719
  if (opts.word) {
678
- let stringRepresentation = this.toString();
720
+ let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
721
+ let stringRepresentation = inputString.slice(
722
+ sourceOffset(inputString, this.source.start),
723
+ sourceOffset(inputString, this.source.end)
724
+ );
679
725
  let index2 = stringRepresentation.indexOf(opts.word);
680
726
  if (index2 !== -1) {
681
- start = this.positionInside(index2, stringRepresentation);
682
- end = this.positionInside(index2 + opts.word.length, stringRepresentation);
727
+ start = this.positionInside(index2);
728
+ end = this.positionInside(
729
+ index2 + opts.word.length
730
+ );
683
731
  }
684
732
  } else {
685
733
  if (opts.start) {
@@ -792,7 +840,7 @@ let Node$4 = class Node {
792
840
  }
793
841
  return this.proxyCache;
794
842
  }
795
- toString(stringifier2 = stringify$3) {
843
+ toString(stringifier2 = stringify$4) {
796
844
  if (stringifier2.stringify) stringifier2 = stringifier2.stringify;
797
845
  let result2 = "";
798
846
  stringifier2(this, (i) => {
@@ -809,10 +857,19 @@ let Node$4 = class Node {
809
857
  return this;
810
858
  }
811
859
  };
812
- var node = Node$4;
813
- Node$4.default = Node$4;
860
+ var node = Node$5;
861
+ Node$5.default = Node$5;
862
+ let Node$4 = node;
863
+ let Comment$6 = class Comment extends Node$4 {
864
+ constructor(defaults) {
865
+ super(defaults);
866
+ this.type = "comment";
867
+ }
868
+ };
869
+ var comment$1 = Comment$6;
870
+ Comment$6.default = Comment$6;
814
871
  let Node$3 = node;
815
- let Declaration$4 = class Declaration extends Node$3 {
872
+ let Declaration$5 = class Declaration extends Node$3 {
816
873
  constructor(defaults) {
817
874
  if (defaults && typeof defaults.value !== "undefined" && typeof defaults.value !== "string") {
818
875
  defaults = { ...defaults, value: String(defaults.value) };
@@ -824,1120 +881,1233 @@ let Declaration$4 = class Declaration extends Node$3 {
824
881
  return this.prop.startsWith("--") || this.prop[0] === "$";
825
882
  }
826
883
  };
827
- var declaration = Declaration$4;
828
- Declaration$4.default = Declaration$4;
829
- let urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
830
- let customAlphabet = (alphabet, defaultSize = 21) => {
831
- return (size = defaultSize) => {
832
- let id = "";
833
- let i = size;
834
- while (i--) {
835
- id += alphabet[Math.random() * alphabet.length | 0];
884
+ var declaration = Declaration$5;
885
+ Declaration$5.default = Declaration$5;
886
+ let Comment$5 = comment$1;
887
+ let Declaration$4 = declaration;
888
+ let Node$2 = node;
889
+ let { isClean: isClean$1, my: my$1 } = symbols;
890
+ let AtRule$5, parse$5, Root$7, Rule$5;
891
+ function cleanSource(nodes) {
892
+ return nodes.map((i) => {
893
+ if (i.nodes) i.nodes = cleanSource(i.nodes);
894
+ delete i.source;
895
+ return i;
896
+ });
897
+ }
898
+ function markTreeDirty(node2) {
899
+ node2[isClean$1] = false;
900
+ if (node2.proxyOf.nodes) {
901
+ for (let i of node2.proxyOf.nodes) {
902
+ markTreeDirty(i);
836
903
  }
837
- return id;
838
- };
839
- };
840
- let nanoid$1 = (size = 21) => {
841
- let id = "";
842
- let i = size;
843
- while (i--) {
844
- id += urlAlphabet[Math.random() * 64 | 0];
845
- }
846
- return id;
847
- };
848
- var nonSecure = { nanoid: nanoid$1, customAlphabet };
849
- let { SourceMapConsumer: SourceMapConsumer$2, SourceMapGenerator: SourceMapGenerator$2 } = require$$2;
850
- let { existsSync, readFileSync } = require$$2;
851
- let { dirname: dirname$1, join } = require$$2;
852
- function fromBase64(str) {
853
- if (Buffer) {
854
- return Buffer.from(str, "base64").toString();
855
- } else {
856
- return window.atob(str);
857
904
  }
858
905
  }
859
- let PreviousMap$2 = class PreviousMap {
860
- constructor(css, opts) {
861
- if (opts.map === false) return;
862
- this.loadAnnotation(css);
863
- this.inline = this.startWith(this.annotation, "data:");
864
- let prev = opts.map ? opts.map.prev : void 0;
865
- let text = this.loadMap(opts.from, prev);
866
- if (!this.mapFile && opts.from) {
867
- this.mapFile = opts.from;
906
+ let Container$8 = class Container extends Node$2 {
907
+ append(...children) {
908
+ for (let child of children) {
909
+ let nodes = this.normalize(child, this.last);
910
+ for (let node2 of nodes) this.proxyOf.nodes.push(node2);
868
911
  }
869
- if (this.mapFile) this.root = dirname$1(this.mapFile);
870
- if (text) this.text = text;
912
+ this.markDirty();
913
+ return this;
871
914
  }
872
- consumer() {
873
- if (!this.consumerCache) {
874
- this.consumerCache = new SourceMapConsumer$2(this.text);
915
+ cleanRaws(keepBetween) {
916
+ super.cleanRaws(keepBetween);
917
+ if (this.nodes) {
918
+ for (let node2 of this.nodes) node2.cleanRaws(keepBetween);
875
919
  }
876
- return this.consumerCache;
877
920
  }
878
- decodeInline(text) {
879
- let baseCharsetUri = /^data:application\/json;charset=utf-?8;base64,/;
880
- let baseUri = /^data:application\/json;base64,/;
881
- let charsetUri = /^data:application\/json;charset=utf-?8,/;
882
- let uri = /^data:application\/json,/;
883
- if (charsetUri.test(text) || uri.test(text)) {
884
- return decodeURIComponent(text.substr(RegExp.lastMatch.length));
885
- }
886
- if (baseCharsetUri.test(text) || baseUri.test(text)) {
887
- return fromBase64(text.substr(RegExp.lastMatch.length));
921
+ each(callback) {
922
+ if (!this.proxyOf.nodes) return void 0;
923
+ let iterator = this.getIterator();
924
+ let index2, result2;
925
+ while (this.indexes[iterator] < this.proxyOf.nodes.length) {
926
+ index2 = this.indexes[iterator];
927
+ result2 = callback(this.proxyOf.nodes[index2], index2);
928
+ if (result2 === false) break;
929
+ this.indexes[iterator] += 1;
888
930
  }
889
- let encoding = text.match(/data:application\/json;([^,]+),/)[1];
890
- throw new Error("Unsupported source map encoding " + encoding);
891
- }
892
- getAnnotationURL(sourceMapString) {
893
- return sourceMapString.replace(/^\/\*\s*# sourceMappingURL=/, "").trim();
894
- }
895
- isMap(map) {
896
- if (typeof map !== "object") return false;
897
- return typeof map.mappings === "string" || typeof map._mappings === "string" || Array.isArray(map.sections);
931
+ delete this.indexes[iterator];
932
+ return result2;
898
933
  }
899
- loadAnnotation(css) {
900
- let comments = css.match(/\/\*\s*# sourceMappingURL=/gm);
901
- if (!comments) return;
902
- let start = css.lastIndexOf(comments.pop());
903
- let end = css.indexOf("*/", start);
904
- if (start > -1 && end > -1) {
905
- this.annotation = this.getAnnotationURL(css.substring(start, end));
906
- }
934
+ every(condition) {
935
+ return this.nodes.every(condition);
907
936
  }
908
- loadFile(path) {
909
- this.root = dirname$1(path);
910
- if (existsSync(path)) {
911
- this.mapFile = path;
912
- return readFileSync(path, "utf-8").toString().trim();
913
- }
937
+ getIterator() {
938
+ if (!this.lastEach) this.lastEach = 0;
939
+ if (!this.indexes) this.indexes = {};
940
+ this.lastEach += 1;
941
+ let iterator = this.lastEach;
942
+ this.indexes[iterator] = 0;
943
+ return iterator;
914
944
  }
915
- loadMap(file, prev) {
916
- if (prev === false) return false;
917
- if (prev) {
918
- if (typeof prev === "string") {
919
- return prev;
920
- } else if (typeof prev === "function") {
921
- let prevPath = prev(file);
922
- if (prevPath) {
923
- let map = this.loadFile(prevPath);
924
- if (!map) {
925
- throw new Error(
926
- "Unable to load previous source map: " + prevPath.toString()
945
+ getProxyProcessor() {
946
+ return {
947
+ get(node2, prop) {
948
+ if (prop === "proxyOf") {
949
+ return node2;
950
+ } else if (!node2[prop]) {
951
+ return node2[prop];
952
+ } else if (prop === "each" || typeof prop === "string" && prop.startsWith("walk")) {
953
+ return (...args) => {
954
+ return node2[prop](
955
+ ...args.map((i) => {
956
+ if (typeof i === "function") {
957
+ return (child, index2) => i(child.toProxy(), index2);
958
+ } else {
959
+ return i;
960
+ }
961
+ })
927
962
  );
928
- }
929
- return map;
963
+ };
964
+ } else if (prop === "every" || prop === "some") {
965
+ return (cb) => {
966
+ return node2[prop](
967
+ (child, ...other) => cb(child.toProxy(), ...other)
968
+ );
969
+ };
970
+ } else if (prop === "root") {
971
+ return () => node2.root().toProxy();
972
+ } else if (prop === "nodes") {
973
+ return node2.nodes.map((i) => i.toProxy());
974
+ } else if (prop === "first" || prop === "last") {
975
+ return node2[prop].toProxy();
976
+ } else {
977
+ return node2[prop];
930
978
  }
931
- } else if (prev instanceof SourceMapConsumer$2) {
932
- return SourceMapGenerator$2.fromSourceMap(prev).toString();
933
- } else if (prev instanceof SourceMapGenerator$2) {
934
- return prev.toString();
935
- } else if (this.isMap(prev)) {
936
- return JSON.stringify(prev);
937
- } else {
938
- throw new Error(
939
- "Unsupported previous source map format: " + prev.toString()
940
- );
979
+ },
980
+ set(node2, prop, value) {
981
+ if (node2[prop] === value) return true;
982
+ node2[prop] = value;
983
+ if (prop === "name" || prop === "params" || prop === "selector") {
984
+ node2.markDirty();
985
+ }
986
+ return true;
941
987
  }
942
- } else if (this.inline) {
943
- return this.decodeInline(this.annotation);
944
- } else if (this.annotation) {
945
- let map = this.annotation;
946
- if (file) map = join(dirname$1(file), map);
947
- return this.loadFile(map);
948
- }
988
+ };
949
989
  }
950
- startWith(string, start) {
951
- if (!string) return false;
952
- return string.substr(0, start.length) === start;
990
+ index(child) {
991
+ if (typeof child === "number") return child;
992
+ if (child.proxyOf) child = child.proxyOf;
993
+ return this.proxyOf.nodes.indexOf(child);
953
994
  }
954
- withContent() {
955
- return !!(this.consumer().sourcesContent && this.consumer().sourcesContent.length > 0);
995
+ insertAfter(exist, add) {
996
+ let existIndex = this.index(exist);
997
+ let nodes = this.normalize(add, this.proxyOf.nodes[existIndex]).reverse();
998
+ existIndex = this.index(exist);
999
+ for (let node2 of nodes) this.proxyOf.nodes.splice(existIndex + 1, 0, node2);
1000
+ let index2;
1001
+ for (let id in this.indexes) {
1002
+ index2 = this.indexes[id];
1003
+ if (existIndex < index2) {
1004
+ this.indexes[id] = index2 + nodes.length;
1005
+ }
1006
+ }
1007
+ this.markDirty();
1008
+ return this;
956
1009
  }
957
- };
958
- var previousMap = PreviousMap$2;
959
- PreviousMap$2.default = PreviousMap$2;
960
- let { SourceMapConsumer: SourceMapConsumer$1, SourceMapGenerator: SourceMapGenerator$1 } = require$$2;
961
- let { fileURLToPath, pathToFileURL: pathToFileURL$1 } = require$$2;
962
- let { isAbsolute, resolve: resolve$1 } = require$$2;
963
- let { nanoid } = nonSecure;
964
- let terminalHighlight = require$$2;
965
- let CssSyntaxError$1 = cssSyntaxError;
966
- let PreviousMap$1 = previousMap;
967
- let fromOffsetCache = Symbol("fromOffsetCache");
968
- let sourceMapAvailable$1 = Boolean(SourceMapConsumer$1 && SourceMapGenerator$1);
969
- let pathAvailable$1 = Boolean(resolve$1 && isAbsolute);
970
- let Input$4 = class Input {
971
- constructor(css, opts = {}) {
972
- if (css === null || typeof css === "undefined" || typeof css === "object" && !css.toString) {
973
- throw new Error(`PostCSS received ${css} instead of CSS string`);
1010
+ insertBefore(exist, add) {
1011
+ let existIndex = this.index(exist);
1012
+ let type = existIndex === 0 ? "prepend" : false;
1013
+ let nodes = this.normalize(
1014
+ add,
1015
+ this.proxyOf.nodes[existIndex],
1016
+ type
1017
+ ).reverse();
1018
+ existIndex = this.index(exist);
1019
+ for (let node2 of nodes) this.proxyOf.nodes.splice(existIndex, 0, node2);
1020
+ let index2;
1021
+ for (let id in this.indexes) {
1022
+ index2 = this.indexes[id];
1023
+ if (existIndex <= index2) {
1024
+ this.indexes[id] = index2 + nodes.length;
1025
+ }
974
1026
  }
975
- this.css = css.toString();
976
- if (this.css[0] === "\uFEFF" || this.css[0] === "￾") {
977
- this.hasBOM = true;
978
- this.css = this.css.slice(1);
1027
+ this.markDirty();
1028
+ return this;
1029
+ }
1030
+ normalize(nodes, sample) {
1031
+ if (typeof nodes === "string") {
1032
+ nodes = cleanSource(parse$5(nodes).nodes);
1033
+ } else if (typeof nodes === "undefined") {
1034
+ nodes = [];
1035
+ } else if (Array.isArray(nodes)) {
1036
+ nodes = nodes.slice(0);
1037
+ for (let i of nodes) {
1038
+ if (i.parent) i.parent.removeChild(i, "ignore");
1039
+ }
1040
+ } else if (nodes.type === "root" && this.type !== "document") {
1041
+ nodes = nodes.nodes.slice(0);
1042
+ for (let i of nodes) {
1043
+ if (i.parent) i.parent.removeChild(i, "ignore");
1044
+ }
1045
+ } else if (nodes.type) {
1046
+ nodes = [nodes];
1047
+ } else if (nodes.prop) {
1048
+ if (typeof nodes.value === "undefined") {
1049
+ throw new Error("Value field is missed in node creation");
1050
+ } else if (typeof nodes.value !== "string") {
1051
+ nodes.value = String(nodes.value);
1052
+ }
1053
+ nodes = [new Declaration$4(nodes)];
1054
+ } else if (nodes.selector || nodes.selectors) {
1055
+ nodes = [new Rule$5(nodes)];
1056
+ } else if (nodes.name) {
1057
+ nodes = [new AtRule$5(nodes)];
1058
+ } else if (nodes.text) {
1059
+ nodes = [new Comment$5(nodes)];
979
1060
  } else {
980
- this.hasBOM = false;
1061
+ throw new Error("Unknown node type in node creation");
981
1062
  }
982
- if (opts.from) {
983
- if (!pathAvailable$1 || /^\w+:\/\//.test(opts.from) || isAbsolute(opts.from)) {
984
- this.file = opts.from;
985
- } else {
986
- this.file = resolve$1(opts.from);
1063
+ let processed = nodes.map((i) => {
1064
+ if (!i[my$1]) Container.rebuild(i);
1065
+ i = i.proxyOf;
1066
+ if (i.parent) i.parent.removeChild(i);
1067
+ if (i[isClean$1]) markTreeDirty(i);
1068
+ if (!i.raws) i.raws = {};
1069
+ if (typeof i.raws.before === "undefined") {
1070
+ if (sample && typeof sample.raws.before !== "undefined") {
1071
+ i.raws.before = sample.raws.before.replace(/\S/g, "");
1072
+ }
1073
+ }
1074
+ i.parent = this.proxyOf;
1075
+ return i;
1076
+ });
1077
+ return processed;
1078
+ }
1079
+ prepend(...children) {
1080
+ children = children.reverse();
1081
+ for (let child of children) {
1082
+ let nodes = this.normalize(child, this.first, "prepend").reverse();
1083
+ for (let node2 of nodes) this.proxyOf.nodes.unshift(node2);
1084
+ for (let id in this.indexes) {
1085
+ this.indexes[id] = this.indexes[id] + nodes.length;
987
1086
  }
988
1087
  }
989
- if (pathAvailable$1 && sourceMapAvailable$1) {
990
- let map = new PreviousMap$1(this.css, opts);
991
- if (map.text) {
992
- this.map = map;
993
- let file = map.consumer().file;
994
- if (!this.file && file) this.file = this.mapResolve(file);
1088
+ this.markDirty();
1089
+ return this;
1090
+ }
1091
+ push(child) {
1092
+ child.parent = this;
1093
+ this.proxyOf.nodes.push(child);
1094
+ return this;
1095
+ }
1096
+ removeAll() {
1097
+ for (let node2 of this.proxyOf.nodes) node2.parent = void 0;
1098
+ this.proxyOf.nodes = [];
1099
+ this.markDirty();
1100
+ return this;
1101
+ }
1102
+ removeChild(child) {
1103
+ child = this.index(child);
1104
+ this.proxyOf.nodes[child].parent = void 0;
1105
+ this.proxyOf.nodes.splice(child, 1);
1106
+ let index2;
1107
+ for (let id in this.indexes) {
1108
+ index2 = this.indexes[id];
1109
+ if (index2 >= child) {
1110
+ this.indexes[id] = index2 - 1;
995
1111
  }
996
1112
  }
997
- if (!this.file) {
998
- this.id = "<input css " + nanoid(6) + ">";
1113
+ this.markDirty();
1114
+ return this;
1115
+ }
1116
+ replaceValues(pattern, opts, callback) {
1117
+ if (!callback) {
1118
+ callback = opts;
1119
+ opts = {};
999
1120
  }
1000
- if (this.map) this.map.file = this.from;
1121
+ this.walkDecls((decl2) => {
1122
+ if (opts.props && !opts.props.includes(decl2.prop)) return;
1123
+ if (opts.fast && !decl2.value.includes(opts.fast)) return;
1124
+ decl2.value = decl2.value.replace(pattern, callback);
1125
+ });
1126
+ this.markDirty();
1127
+ return this;
1001
1128
  }
1002
- error(message, line, column, opts = {}) {
1003
- let result2, endLine, endColumn;
1004
- if (line && typeof line === "object") {
1005
- let start = line;
1006
- let end = column;
1007
- if (typeof start.offset === "number") {
1008
- let pos = this.fromOffset(start.offset);
1009
- line = pos.line;
1010
- column = pos.col;
1011
- } else {
1012
- line = start.line;
1013
- column = start.column;
1129
+ some(condition) {
1130
+ return this.nodes.some(condition);
1131
+ }
1132
+ walk(callback) {
1133
+ return this.each((child, i) => {
1134
+ let result2;
1135
+ try {
1136
+ result2 = callback(child, i);
1137
+ } catch (e) {
1138
+ throw child.addToError(e);
1014
1139
  }
1015
- if (typeof end.offset === "number") {
1016
- let pos = this.fromOffset(end.offset);
1017
- endLine = pos.line;
1018
- endColumn = pos.col;
1019
- } else {
1020
- endLine = end.line;
1021
- endColumn = end.column;
1140
+ if (result2 !== false && child.walk) {
1141
+ result2 = child.walk(callback);
1022
1142
  }
1023
- } else if (!column) {
1024
- let pos = this.fromOffset(line);
1025
- line = pos.line;
1026
- column = pos.col;
1143
+ return result2;
1144
+ });
1145
+ }
1146
+ walkAtRules(name, callback) {
1147
+ if (!callback) {
1148
+ callback = name;
1149
+ return this.walk((child, i) => {
1150
+ if (child.type === "atrule") {
1151
+ return callback(child, i);
1152
+ }
1153
+ });
1027
1154
  }
1028
- let origin = this.origin(line, column, endLine, endColumn);
1029
- if (origin) {
1030
- result2 = new CssSyntaxError$1(
1031
- message,
1032
- origin.endLine === void 0 ? origin.line : { column: origin.column, line: origin.line },
1033
- origin.endLine === void 0 ? origin.column : { column: origin.endColumn, line: origin.endLine },
1034
- origin.source,
1035
- origin.file,
1036
- opts.plugin
1037
- );
1038
- } else {
1039
- result2 = new CssSyntaxError$1(
1040
- message,
1041
- endLine === void 0 ? line : { column, line },
1042
- endLine === void 0 ? column : { column: endColumn, line: endLine },
1043
- this.css,
1044
- this.file,
1045
- opts.plugin
1046
- );
1155
+ if (name instanceof RegExp) {
1156
+ return this.walk((child, i) => {
1157
+ if (child.type === "atrule" && name.test(child.name)) {
1158
+ return callback(child, i);
1159
+ }
1160
+ });
1047
1161
  }
1048
- result2.input = { column, endColumn, endLine, line, source: this.css };
1049
- if (this.file) {
1050
- if (pathToFileURL$1) {
1051
- result2.input.url = pathToFileURL$1(this.file).toString();
1162
+ return this.walk((child, i) => {
1163
+ if (child.type === "atrule" && child.name === name) {
1164
+ return callback(child, i);
1052
1165
  }
1053
- result2.input.file = this.file;
1054
- }
1055
- return result2;
1166
+ });
1056
1167
  }
1057
- fromOffset(offset) {
1058
- let lastLine, lineToIndex;
1059
- if (!this[fromOffsetCache]) {
1060
- let lines = this.css.split("\n");
1061
- lineToIndex = new Array(lines.length);
1062
- let prevIndex = 0;
1063
- for (let i = 0, l = lines.length; i < l; i++) {
1064
- lineToIndex[i] = prevIndex;
1065
- prevIndex += lines[i].length + 1;
1168
+ walkComments(callback) {
1169
+ return this.walk((child, i) => {
1170
+ if (child.type === "comment") {
1171
+ return callback(child, i);
1066
1172
  }
1067
- this[fromOffsetCache] = lineToIndex;
1068
- } else {
1069
- lineToIndex = this[fromOffsetCache];
1173
+ });
1174
+ }
1175
+ walkDecls(prop, callback) {
1176
+ if (!callback) {
1177
+ callback = prop;
1178
+ return this.walk((child, i) => {
1179
+ if (child.type === "decl") {
1180
+ return callback(child, i);
1181
+ }
1182
+ });
1070
1183
  }
1071
- lastLine = lineToIndex[lineToIndex.length - 1];
1072
- let min = 0;
1073
- if (offset >= lastLine) {
1074
- min = lineToIndex.length - 1;
1075
- } else {
1076
- let max = lineToIndex.length - 2;
1077
- let mid;
1078
- while (min < max) {
1079
- mid = min + (max - min >> 1);
1080
- if (offset < lineToIndex[mid]) {
1081
- max = mid - 1;
1082
- } else if (offset >= lineToIndex[mid + 1]) {
1083
- min = mid + 1;
1084
- } else {
1085
- min = mid;
1086
- break;
1184
+ if (prop instanceof RegExp) {
1185
+ return this.walk((child, i) => {
1186
+ if (child.type === "decl" && prop.test(child.prop)) {
1187
+ return callback(child, i);
1087
1188
  }
1088
- }
1189
+ });
1089
1190
  }
1090
- return {
1091
- col: offset - lineToIndex[min] + 1,
1092
- line: min + 1
1093
- };
1191
+ return this.walk((child, i) => {
1192
+ if (child.type === "decl" && child.prop === prop) {
1193
+ return callback(child, i);
1194
+ }
1195
+ });
1094
1196
  }
1095
- mapResolve(file) {
1096
- if (/^\w+:\/\//.test(file)) {
1097
- return file;
1098
- }
1099
- return resolve$1(this.map.consumer().sourceRoot || this.map.root || ".", file);
1100
- }
1101
- origin(line, column, endLine, endColumn) {
1102
- if (!this.map) return false;
1103
- let consumer = this.map.consumer();
1104
- let from = consumer.originalPositionFor({ column, line });
1105
- if (!from.source) return false;
1106
- let to;
1107
- if (typeof endLine === "number") {
1108
- to = consumer.originalPositionFor({ column: endColumn, line: endLine });
1197
+ walkRules(selector, callback) {
1198
+ if (!callback) {
1199
+ callback = selector;
1200
+ return this.walk((child, i) => {
1201
+ if (child.type === "rule") {
1202
+ return callback(child, i);
1203
+ }
1204
+ });
1109
1205
  }
1110
- let fromUrl;
1111
- if (isAbsolute(from.source)) {
1112
- fromUrl = pathToFileURL$1(from.source);
1113
- } else {
1114
- fromUrl = new URL(
1115
- from.source,
1116
- this.map.consumer().sourceRoot || pathToFileURL$1(this.map.mapFile)
1117
- );
1206
+ if (selector instanceof RegExp) {
1207
+ return this.walk((child, i) => {
1208
+ if (child.type === "rule" && selector.test(child.selector)) {
1209
+ return callback(child, i);
1210
+ }
1211
+ });
1118
1212
  }
1119
- let result2 = {
1120
- column: from.column,
1121
- endColumn: to && to.column,
1122
- endLine: to && to.line,
1123
- line: from.line,
1124
- url: fromUrl.toString()
1125
- };
1126
- if (fromUrl.protocol === "file:") {
1127
- if (fileURLToPath) {
1128
- result2.file = fileURLToPath(fromUrl);
1129
- } else {
1130
- throw new Error(`file: protocol is not available in this PostCSS build`);
1213
+ return this.walk((child, i) => {
1214
+ if (child.type === "rule" && child.selector === selector) {
1215
+ return callback(child, i);
1131
1216
  }
1132
- }
1133
- let source = consumer.sourceContentFor(from.source);
1134
- if (source) result2.source = source;
1135
- return result2;
1217
+ });
1136
1218
  }
1137
- toJSON() {
1138
- let json = {};
1139
- for (let name of ["hasBOM", "css", "file", "id"]) {
1140
- if (this[name] != null) {
1141
- json[name] = this[name];
1142
- }
1143
- }
1144
- if (this.map) {
1145
- json.map = { ...this.map };
1146
- if (json.map.consumerCache) {
1147
- json.map.consumerCache = void 0;
1148
- }
1149
- }
1150
- return json;
1219
+ get first() {
1220
+ if (!this.proxyOf.nodes) return void 0;
1221
+ return this.proxyOf.nodes[0];
1151
1222
  }
1152
- get from() {
1153
- return this.file || this.id;
1223
+ get last() {
1224
+ if (!this.proxyOf.nodes) return void 0;
1225
+ return this.proxyOf.nodes[this.proxyOf.nodes.length - 1];
1154
1226
  }
1155
1227
  };
1156
- var input = Input$4;
1157
- Input$4.default = Input$4;
1158
- if (terminalHighlight && terminalHighlight.registerInput) {
1159
- terminalHighlight.registerInput(Input$4);
1160
- }
1161
- let { SourceMapConsumer, SourceMapGenerator } = require$$2;
1162
- let { dirname, relative, resolve, sep } = require$$2;
1163
- let { pathToFileURL } = require$$2;
1164
- let Input$3 = input;
1165
- let sourceMapAvailable = Boolean(SourceMapConsumer && SourceMapGenerator);
1166
- let pathAvailable = Boolean(dirname && resolve && relative && sep);
1167
- let MapGenerator$2 = class MapGenerator {
1168
- constructor(stringify2, root2, opts, cssString) {
1169
- this.stringify = stringify2;
1170
- this.mapOpts = opts.map || {};
1171
- this.root = root2;
1172
- this.opts = opts;
1173
- this.css = cssString;
1174
- this.originalCSS = cssString;
1175
- this.usesFileUrls = !this.mapOpts.from && this.mapOpts.absolute;
1176
- this.memoizedFileURLs = /* @__PURE__ */ new Map();
1177
- this.memoizedPaths = /* @__PURE__ */ new Map();
1178
- this.memoizedURLs = /* @__PURE__ */ new Map();
1228
+ Container$8.registerParse = (dependant) => {
1229
+ parse$5 = dependant;
1230
+ };
1231
+ Container$8.registerRule = (dependant) => {
1232
+ Rule$5 = dependant;
1233
+ };
1234
+ Container$8.registerAtRule = (dependant) => {
1235
+ AtRule$5 = dependant;
1236
+ };
1237
+ Container$8.registerRoot = (dependant) => {
1238
+ Root$7 = dependant;
1239
+ };
1240
+ var container = Container$8;
1241
+ Container$8.default = Container$8;
1242
+ Container$8.rebuild = (node2) => {
1243
+ if (node2.type === "atrule") {
1244
+ Object.setPrototypeOf(node2, AtRule$5.prototype);
1245
+ } else if (node2.type === "rule") {
1246
+ Object.setPrototypeOf(node2, Rule$5.prototype);
1247
+ } else if (node2.type === "decl") {
1248
+ Object.setPrototypeOf(node2, Declaration$4.prototype);
1249
+ } else if (node2.type === "comment") {
1250
+ Object.setPrototypeOf(node2, Comment$5.prototype);
1251
+ } else if (node2.type === "root") {
1252
+ Object.setPrototypeOf(node2, Root$7.prototype);
1179
1253
  }
1180
- addAnnotation() {
1181
- let content;
1182
- if (this.isInline()) {
1183
- content = "data:application/json;base64," + this.toBase64(this.map.toString());
1184
- } else if (typeof this.mapOpts.annotation === "string") {
1185
- content = this.mapOpts.annotation;
1186
- } else if (typeof this.mapOpts.annotation === "function") {
1187
- content = this.mapOpts.annotation(this.opts.to, this.root);
1188
- } else {
1189
- content = this.outputFile() + ".map";
1254
+ node2[my$1] = true;
1255
+ if (node2.nodes) {
1256
+ node2.nodes.forEach((child) => {
1257
+ Container$8.rebuild(child);
1258
+ });
1259
+ }
1260
+ };
1261
+ let Container$7 = container;
1262
+ let AtRule$4 = class AtRule extends Container$7 {
1263
+ constructor(defaults) {
1264
+ super(defaults);
1265
+ this.type = "atrule";
1266
+ }
1267
+ append(...children) {
1268
+ if (!this.proxyOf.nodes) this.nodes = [];
1269
+ return super.append(...children);
1270
+ }
1271
+ prepend(...children) {
1272
+ if (!this.proxyOf.nodes) this.nodes = [];
1273
+ return super.prepend(...children);
1274
+ }
1275
+ };
1276
+ var atRule$1 = AtRule$4;
1277
+ AtRule$4.default = AtRule$4;
1278
+ Container$7.registerAtRule(AtRule$4);
1279
+ let Container$6 = container;
1280
+ let LazyResult$4, Processor$4;
1281
+ let Document$4 = class Document2 extends Container$6 {
1282
+ constructor(defaults) {
1283
+ super({ type: "document", ...defaults });
1284
+ if (!this.nodes) {
1285
+ this.nodes = [];
1190
1286
  }
1191
- let eol = "\n";
1192
- if (this.css.includes("\r\n")) eol = "\r\n";
1193
- this.css += eol + "/*# sourceMappingURL=" + content + " */";
1194
1287
  }
1195
- applyPrevMaps() {
1196
- for (let prev of this.previous()) {
1197
- let from = this.toUrl(this.path(prev.file));
1198
- let root2 = prev.root || dirname(prev.file);
1199
- let map;
1200
- if (this.mapOpts.sourcesContent === false) {
1201
- map = new SourceMapConsumer(prev.text);
1202
- if (map.sourcesContent) {
1203
- map.sourcesContent = null;
1204
- }
1205
- } else {
1206
- map = prev.consumer();
1207
- }
1208
- this.map.applySourceMap(map, from, this.toUrl(this.path(root2)));
1288
+ toResult(opts = {}) {
1289
+ let lazy = new LazyResult$4(new Processor$4(), this, opts);
1290
+ return lazy.stringify();
1291
+ }
1292
+ };
1293
+ Document$4.registerLazyResult = (dependant) => {
1294
+ LazyResult$4 = dependant;
1295
+ };
1296
+ Document$4.registerProcessor = (dependant) => {
1297
+ Processor$4 = dependant;
1298
+ };
1299
+ var document$2 = Document$4;
1300
+ Document$4.default = Document$4;
1301
+ let urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
1302
+ let customAlphabet = (alphabet, defaultSize = 21) => {
1303
+ return (size = defaultSize) => {
1304
+ let id = "";
1305
+ let i = size | 0;
1306
+ while (i--) {
1307
+ id += alphabet[Math.random() * alphabet.length | 0];
1209
1308
  }
1309
+ return id;
1310
+ };
1311
+ };
1312
+ let nanoid$1 = (size = 21) => {
1313
+ let id = "";
1314
+ let i = size | 0;
1315
+ while (i--) {
1316
+ id += urlAlphabet[Math.random() * 64 | 0];
1210
1317
  }
1211
- clearAnnotation() {
1212
- if (this.mapOpts.annotation === false) return;
1213
- if (this.root) {
1214
- let node2;
1215
- for (let i = this.root.nodes.length - 1; i >= 0; i--) {
1216
- node2 = this.root.nodes[i];
1217
- if (node2.type !== "comment") continue;
1218
- if (node2.text.indexOf("# sourceMappingURL=") === 0) {
1219
- this.root.removeChild(i);
1220
- }
1221
- }
1222
- } else if (this.css) {
1223
- this.css = this.css.replace(/\n*?\/\*#[\S\s]*?\*\/$/gm, "");
1318
+ return id;
1319
+ };
1320
+ var nonSecure = { nanoid: nanoid$1, customAlphabet };
1321
+ let { existsSync, readFileSync } = require$$2;
1322
+ let { dirname: dirname$1, join } = require$$2;
1323
+ let { SourceMapConsumer: SourceMapConsumer$2, SourceMapGenerator: SourceMapGenerator$2 } = require$$2;
1324
+ function fromBase64(str) {
1325
+ if (Buffer) {
1326
+ return Buffer.from(str, "base64").toString();
1327
+ } else {
1328
+ return window.atob(str);
1329
+ }
1330
+ }
1331
+ let PreviousMap$2 = class PreviousMap {
1332
+ constructor(css, opts) {
1333
+ if (opts.map === false) return;
1334
+ this.loadAnnotation(css);
1335
+ this.inline = this.startWith(this.annotation, "data:");
1336
+ let prev = opts.map ? opts.map.prev : void 0;
1337
+ let text = this.loadMap(opts.from, prev);
1338
+ if (!this.mapFile && opts.from) {
1339
+ this.mapFile = opts.from;
1224
1340
  }
1341
+ if (this.mapFile) this.root = dirname$1(this.mapFile);
1342
+ if (text) this.text = text;
1225
1343
  }
1226
- generate() {
1227
- this.clearAnnotation();
1228
- if (pathAvailable && sourceMapAvailable && this.isMap()) {
1229
- return this.generateMap();
1230
- } else {
1231
- let result2 = "";
1232
- this.stringify(this.root, (i) => {
1233
- result2 += i;
1234
- });
1235
- return [result2];
1344
+ consumer() {
1345
+ if (!this.consumerCache) {
1346
+ this.consumerCache = new SourceMapConsumer$2(this.text);
1236
1347
  }
1348
+ return this.consumerCache;
1237
1349
  }
1238
- generateMap() {
1239
- if (this.root) {
1240
- this.generateString();
1241
- } else if (this.previous().length === 1) {
1242
- let prev = this.previous()[0].consumer();
1243
- prev.file = this.outputFile();
1244
- this.map = SourceMapGenerator.fromSourceMap(prev, {
1245
- ignoreInvalidMapping: true
1246
- });
1247
- } else {
1248
- this.map = new SourceMapGenerator({
1249
- file: this.outputFile(),
1250
- ignoreInvalidMapping: true
1251
- });
1252
- this.map.addMapping({
1253
- generated: { column: 0, line: 1 },
1254
- original: { column: 0, line: 1 },
1255
- source: this.opts.from ? this.toUrl(this.path(this.opts.from)) : "<no source>"
1256
- });
1350
+ decodeInline(text) {
1351
+ let baseCharsetUri = /^data:application\/json;charset=utf-?8;base64,/;
1352
+ let baseUri = /^data:application\/json;base64,/;
1353
+ let charsetUri = /^data:application\/json;charset=utf-?8,/;
1354
+ let uri = /^data:application\/json,/;
1355
+ let uriMatch = text.match(charsetUri) || text.match(uri);
1356
+ if (uriMatch) {
1357
+ return decodeURIComponent(text.substr(uriMatch[0].length));
1257
1358
  }
1258
- if (this.isSourcesContent()) this.setSourcesContent();
1259
- if (this.root && this.previous().length > 0) this.applyPrevMaps();
1260
- if (this.isAnnotation()) this.addAnnotation();
1261
- if (this.isInline()) {
1262
- return [this.css];
1263
- } else {
1264
- return [this.css, this.map];
1359
+ let baseUriMatch = text.match(baseCharsetUri) || text.match(baseUri);
1360
+ if (baseUriMatch) {
1361
+ return fromBase64(text.substr(baseUriMatch[0].length));
1265
1362
  }
1363
+ let encoding = text.match(/data:application\/json;([^,]+),/)[1];
1364
+ throw new Error("Unsupported source map encoding " + encoding);
1266
1365
  }
1267
- generateString() {
1268
- this.css = "";
1269
- this.map = new SourceMapGenerator({
1270
- file: this.outputFile(),
1271
- ignoreInvalidMapping: true
1272
- });
1273
- let line = 1;
1274
- let column = 1;
1275
- let noSource = "<no source>";
1276
- let mapping = {
1277
- generated: { column: 0, line: 0 },
1278
- original: { column: 0, line: 0 },
1279
- source: ""
1280
- };
1281
- let lines, last;
1282
- this.stringify(this.root, (str, node2, type) => {
1283
- this.css += str;
1284
- if (node2 && type !== "end") {
1285
- mapping.generated.line = line;
1286
- mapping.generated.column = column - 1;
1287
- if (node2.source && node2.source.start) {
1288
- mapping.source = this.sourcePath(node2);
1289
- mapping.original.line = node2.source.start.line;
1290
- mapping.original.column = node2.source.start.column - 1;
1291
- this.map.addMapping(mapping);
1292
- } else {
1293
- mapping.source = noSource;
1294
- mapping.original.line = 1;
1295
- mapping.original.column = 0;
1296
- this.map.addMapping(mapping);
1297
- }
1298
- }
1299
- lines = str.match(/\n/g);
1300
- if (lines) {
1301
- line += lines.length;
1302
- last = str.lastIndexOf("\n");
1303
- column = str.length - last;
1304
- } else {
1305
- column += str.length;
1306
- }
1307
- if (node2 && type !== "start") {
1308
- let p = node2.parent || { raws: {} };
1309
- let childless = node2.type === "decl" || node2.type === "atrule" && !node2.nodes;
1310
- if (!childless || node2 !== p.last || p.raws.semicolon) {
1311
- if (node2.source && node2.source.end) {
1312
- mapping.source = this.sourcePath(node2);
1313
- mapping.original.line = node2.source.end.line;
1314
- mapping.original.column = node2.source.end.column - 1;
1315
- mapping.generated.line = line;
1316
- mapping.generated.column = column - 2;
1317
- this.map.addMapping(mapping);
1318
- } else {
1319
- mapping.source = noSource;
1320
- mapping.original.line = 1;
1321
- mapping.original.column = 0;
1322
- mapping.generated.line = line;
1323
- mapping.generated.column = column - 1;
1324
- this.map.addMapping(mapping);
1325
- }
1326
- }
1327
- }
1328
- });
1366
+ getAnnotationURL(sourceMapString) {
1367
+ return sourceMapString.replace(/^\/\*\s*# sourceMappingURL=/, "").trim();
1329
1368
  }
1330
- isAnnotation() {
1331
- if (this.isInline()) {
1332
- return true;
1333
- }
1334
- if (typeof this.mapOpts.annotation !== "undefined") {
1335
- return this.mapOpts.annotation;
1336
- }
1337
- if (this.previous().length) {
1338
- return this.previous().some((i) => i.annotation);
1339
- }
1340
- return true;
1369
+ isMap(map) {
1370
+ if (typeof map !== "object") return false;
1371
+ return typeof map.mappings === "string" || typeof map._mappings === "string" || Array.isArray(map.sections);
1341
1372
  }
1342
- isInline() {
1343
- if (typeof this.mapOpts.inline !== "undefined") {
1344
- return this.mapOpts.inline;
1345
- }
1346
- let annotation = this.mapOpts.annotation;
1347
- if (typeof annotation !== "undefined" && annotation !== true) {
1348
- return false;
1349
- }
1350
- if (this.previous().length) {
1351
- return this.previous().some((i) => i.inline);
1373
+ loadAnnotation(css) {
1374
+ let comments = css.match(/\/\*\s*# sourceMappingURL=/g);
1375
+ if (!comments) return;
1376
+ let start = css.lastIndexOf(comments.pop());
1377
+ let end = css.indexOf("*/", start);
1378
+ if (start > -1 && end > -1) {
1379
+ this.annotation = this.getAnnotationURL(css.substring(start, end));
1352
1380
  }
1353
- return true;
1354
1381
  }
1355
- isMap() {
1356
- if (typeof this.opts.map !== "undefined") {
1357
- return !!this.opts.map;
1382
+ loadFile(path) {
1383
+ this.root = dirname$1(path);
1384
+ if (existsSync(path)) {
1385
+ this.mapFile = path;
1386
+ return readFileSync(path, "utf-8").toString().trim();
1358
1387
  }
1359
- return this.previous().length > 0;
1360
1388
  }
1361
- isSourcesContent() {
1362
- if (typeof this.mapOpts.sourcesContent !== "undefined") {
1363
- return this.mapOpts.sourcesContent;
1364
- }
1365
- if (this.previous().length) {
1366
- return this.previous().some((i) => i.withContent());
1389
+ loadMap(file, prev) {
1390
+ if (prev === false) return false;
1391
+ if (prev) {
1392
+ if (typeof prev === "string") {
1393
+ return prev;
1394
+ } else if (typeof prev === "function") {
1395
+ let prevPath = prev(file);
1396
+ if (prevPath) {
1397
+ let map = this.loadFile(prevPath);
1398
+ if (!map) {
1399
+ throw new Error(
1400
+ "Unable to load previous source map: " + prevPath.toString()
1401
+ );
1402
+ }
1403
+ return map;
1404
+ }
1405
+ } else if (prev instanceof SourceMapConsumer$2) {
1406
+ return SourceMapGenerator$2.fromSourceMap(prev).toString();
1407
+ } else if (prev instanceof SourceMapGenerator$2) {
1408
+ return prev.toString();
1409
+ } else if (this.isMap(prev)) {
1410
+ return JSON.stringify(prev);
1411
+ } else {
1412
+ throw new Error(
1413
+ "Unsupported previous source map format: " + prev.toString()
1414
+ );
1415
+ }
1416
+ } else if (this.inline) {
1417
+ return this.decodeInline(this.annotation);
1418
+ } else if (this.annotation) {
1419
+ let map = this.annotation;
1420
+ if (file) map = join(dirname$1(file), map);
1421
+ return this.loadFile(map);
1367
1422
  }
1368
- return true;
1369
1423
  }
1370
- outputFile() {
1371
- if (this.opts.to) {
1372
- return this.path(this.opts.to);
1373
- } else if (this.opts.from) {
1374
- return this.path(this.opts.from);
1375
- } else {
1376
- return "to.css";
1377
- }
1424
+ startWith(string, start) {
1425
+ if (!string) return false;
1426
+ return string.substr(0, start.length) === start;
1378
1427
  }
1379
- path(file) {
1380
- if (this.mapOpts.absolute) return file;
1381
- if (file.charCodeAt(0) === 60) return file;
1382
- if (/^\w+:\/\//.test(file)) return file;
1383
- let cached = this.memoizedPaths.get(file);
1384
- if (cached) return cached;
1385
- let from = this.opts.to ? dirname(this.opts.to) : ".";
1386
- if (typeof this.mapOpts.annotation === "string") {
1387
- from = dirname(resolve(from, this.mapOpts.annotation));
1388
- }
1389
- let path = relative(from, file);
1390
- this.memoizedPaths.set(file, path);
1391
- return path;
1428
+ withContent() {
1429
+ return !!(this.consumer().sourcesContent && this.consumer().sourcesContent.length > 0);
1392
1430
  }
1393
- previous() {
1394
- if (!this.previousMaps) {
1395
- this.previousMaps = [];
1396
- if (this.root) {
1397
- this.root.walk((node2) => {
1398
- if (node2.source && node2.source.input.map) {
1399
- let map = node2.source.input.map;
1400
- if (!this.previousMaps.includes(map)) {
1401
- this.previousMaps.push(map);
1402
- }
1403
- }
1404
- });
1431
+ };
1432
+ var previousMap = PreviousMap$2;
1433
+ PreviousMap$2.default = PreviousMap$2;
1434
+ let { nanoid } = nonSecure;
1435
+ let { isAbsolute, resolve: resolve$1 } = require$$2;
1436
+ let { SourceMapConsumer: SourceMapConsumer$1, SourceMapGenerator: SourceMapGenerator$1 } = require$$2;
1437
+ let { fileURLToPath, pathToFileURL: pathToFileURL$1 } = require$$2;
1438
+ let CssSyntaxError$2 = cssSyntaxError;
1439
+ let PreviousMap$1 = previousMap;
1440
+ let terminalHighlight = require$$2;
1441
+ let fromOffsetCache = Symbol("fromOffsetCache");
1442
+ let sourceMapAvailable$1 = Boolean(SourceMapConsumer$1 && SourceMapGenerator$1);
1443
+ let pathAvailable$1 = Boolean(resolve$1 && isAbsolute);
1444
+ let Input$6 = class Input {
1445
+ constructor(css, opts = {}) {
1446
+ if (css === null || typeof css === "undefined" || typeof css === "object" && !css.toString) {
1447
+ throw new Error(`PostCSS received ${css} instead of CSS string`);
1448
+ }
1449
+ this.css = css.toString();
1450
+ if (this.css[0] === "\uFEFF" || this.css[0] === "￾") {
1451
+ this.hasBOM = true;
1452
+ this.css = this.css.slice(1);
1453
+ } else {
1454
+ this.hasBOM = false;
1455
+ }
1456
+ this.document = this.css;
1457
+ if (opts.document) this.document = opts.document.toString();
1458
+ if (opts.from) {
1459
+ if (!pathAvailable$1 || /^\w+:\/\//.test(opts.from) || isAbsolute(opts.from)) {
1460
+ this.file = opts.from;
1405
1461
  } else {
1406
- let input2 = new Input$3(this.originalCSS, this.opts);
1407
- if (input2.map) this.previousMaps.push(input2.map);
1462
+ this.file = resolve$1(opts.from);
1408
1463
  }
1409
1464
  }
1410
- return this.previousMaps;
1411
- }
1412
- setSourcesContent() {
1413
- let already = {};
1414
- if (this.root) {
1415
- this.root.walk((node2) => {
1416
- if (node2.source) {
1417
- let from = node2.source.input.from;
1418
- if (from && !already[from]) {
1419
- already[from] = true;
1420
- let fromUrl = this.usesFileUrls ? this.toFileUrl(from) : this.toUrl(this.path(from));
1421
- this.map.setSourceContent(fromUrl, node2.source.input.css);
1422
- }
1423
- }
1424
- });
1425
- } else if (this.css) {
1426
- let from = this.opts.from ? this.toUrl(this.path(this.opts.from)) : "<no source>";
1427
- this.map.setSourceContent(from, this.css);
1465
+ if (pathAvailable$1 && sourceMapAvailable$1) {
1466
+ let map = new PreviousMap$1(this.css, opts);
1467
+ if (map.text) {
1468
+ this.map = map;
1469
+ let file = map.consumer().file;
1470
+ if (!this.file && file) this.file = this.mapResolve(file);
1471
+ }
1428
1472
  }
1429
- }
1430
- sourcePath(node2) {
1431
- if (this.mapOpts.from) {
1432
- return this.toUrl(this.mapOpts.from);
1433
- } else if (this.usesFileUrls) {
1434
- return this.toFileUrl(node2.source.input.from);
1435
- } else {
1436
- return this.toUrl(this.path(node2.source.input.from));
1473
+ if (!this.file) {
1474
+ this.id = "<input css " + nanoid(6) + ">";
1437
1475
  }
1476
+ if (this.map) this.map.file = this.from;
1438
1477
  }
1439
- toBase64(str) {
1440
- if (Buffer) {
1441
- return Buffer.from(str).toString("base64");
1442
- } else {
1443
- return window.btoa(unescape(encodeURIComponent(str)));
1478
+ error(message, line, column, opts = {}) {
1479
+ let endColumn, endLine, result2;
1480
+ if (line && typeof line === "object") {
1481
+ let start = line;
1482
+ let end = column;
1483
+ if (typeof start.offset === "number") {
1484
+ let pos = this.fromOffset(start.offset);
1485
+ line = pos.line;
1486
+ column = pos.col;
1487
+ } else {
1488
+ line = start.line;
1489
+ column = start.column;
1490
+ }
1491
+ if (typeof end.offset === "number") {
1492
+ let pos = this.fromOffset(end.offset);
1493
+ endLine = pos.line;
1494
+ endColumn = pos.col;
1495
+ } else {
1496
+ endLine = end.line;
1497
+ endColumn = end.column;
1498
+ }
1499
+ } else if (!column) {
1500
+ let pos = this.fromOffset(line);
1501
+ line = pos.line;
1502
+ column = pos.col;
1444
1503
  }
1445
- }
1446
- toFileUrl(path) {
1447
- let cached = this.memoizedFileURLs.get(path);
1448
- if (cached) return cached;
1449
- if (pathToFileURL) {
1450
- let fileURL = pathToFileURL(path).toString();
1451
- this.memoizedFileURLs.set(path, fileURL);
1452
- return fileURL;
1504
+ let origin = this.origin(line, column, endLine, endColumn);
1505
+ if (origin) {
1506
+ result2 = new CssSyntaxError$2(
1507
+ message,
1508
+ origin.endLine === void 0 ? origin.line : { column: origin.column, line: origin.line },
1509
+ origin.endLine === void 0 ? origin.column : { column: origin.endColumn, line: origin.endLine },
1510
+ origin.source,
1511
+ origin.file,
1512
+ opts.plugin
1513
+ );
1453
1514
  } else {
1454
- throw new Error(
1455
- "`map.absolute` option is not available in this PostCSS build"
1515
+ result2 = new CssSyntaxError$2(
1516
+ message,
1517
+ endLine === void 0 ? line : { column, line },
1518
+ endLine === void 0 ? column : { column: endColumn, line: endLine },
1519
+ this.css,
1520
+ this.file,
1521
+ opts.plugin
1456
1522
  );
1457
1523
  }
1458
- }
1459
- toUrl(path) {
1460
- let cached = this.memoizedURLs.get(path);
1461
- if (cached) return cached;
1462
- if (sep === "\\") {
1463
- path = path.replace(/\\/g, "/");
1524
+ result2.input = { column, endColumn, endLine, line, source: this.css };
1525
+ if (this.file) {
1526
+ if (pathToFileURL$1) {
1527
+ result2.input.url = pathToFileURL$1(this.file).toString();
1528
+ }
1529
+ result2.input.file = this.file;
1464
1530
  }
1465
- let url = encodeURI(path).replace(/[#?]/g, encodeURIComponent);
1466
- this.memoizedURLs.set(path, url);
1467
- return url;
1468
- }
1469
- };
1470
- var mapGenerator = MapGenerator$2;
1471
- let Node$2 = node;
1472
- let Comment$4 = class Comment extends Node$2 {
1473
- constructor(defaults) {
1474
- super(defaults);
1475
- this.type = "comment";
1531
+ return result2;
1476
1532
  }
1477
- };
1478
- var comment = Comment$4;
1479
- Comment$4.default = Comment$4;
1480
- let { isClean: isClean$1, my: my$1 } = symbols;
1481
- let Declaration$3 = declaration;
1482
- let Comment$3 = comment;
1483
- let Node$1 = node;
1484
- let parse$4, Rule$4, AtRule$4, Root$6;
1485
- function cleanSource(nodes) {
1486
- return nodes.map((i) => {
1487
- if (i.nodes) i.nodes = cleanSource(i.nodes);
1488
- delete i.source;
1489
- return i;
1490
- });
1491
- }
1492
- function markDirtyUp(node2) {
1493
- node2[isClean$1] = false;
1494
- if (node2.proxyOf.nodes) {
1495
- for (let i of node2.proxyOf.nodes) {
1496
- markDirtyUp(i);
1533
+ fromOffset(offset) {
1534
+ let lastLine, lineToIndex;
1535
+ if (!this[fromOffsetCache]) {
1536
+ let lines = this.css.split("\n");
1537
+ lineToIndex = new Array(lines.length);
1538
+ let prevIndex = 0;
1539
+ for (let i = 0, l = lines.length; i < l; i++) {
1540
+ lineToIndex[i] = prevIndex;
1541
+ prevIndex += lines[i].length + 1;
1542
+ }
1543
+ this[fromOffsetCache] = lineToIndex;
1544
+ } else {
1545
+ lineToIndex = this[fromOffsetCache];
1546
+ }
1547
+ lastLine = lineToIndex[lineToIndex.length - 1];
1548
+ let min = 0;
1549
+ if (offset >= lastLine) {
1550
+ min = lineToIndex.length - 1;
1551
+ } else {
1552
+ let max = lineToIndex.length - 2;
1553
+ let mid;
1554
+ while (min < max) {
1555
+ mid = min + (max - min >> 1);
1556
+ if (offset < lineToIndex[mid]) {
1557
+ max = mid - 1;
1558
+ } else if (offset >= lineToIndex[mid + 1]) {
1559
+ min = mid + 1;
1560
+ } else {
1561
+ min = mid;
1562
+ break;
1563
+ }
1564
+ }
1497
1565
  }
1566
+ return {
1567
+ col: offset - lineToIndex[min] + 1,
1568
+ line: min + 1
1569
+ };
1498
1570
  }
1499
- }
1500
- let Container$7 = class Container extends Node$1 {
1501
- append(...children) {
1502
- for (let child of children) {
1503
- let nodes = this.normalize(child, this.last);
1504
- for (let node2 of nodes) this.proxyOf.nodes.push(node2);
1571
+ mapResolve(file) {
1572
+ if (/^\w+:\/\//.test(file)) {
1573
+ return file;
1505
1574
  }
1506
- this.markDirty();
1507
- return this;
1575
+ return resolve$1(this.map.consumer().sourceRoot || this.map.root || ".", file);
1508
1576
  }
1509
- cleanRaws(keepBetween) {
1510
- super.cleanRaws(keepBetween);
1511
- if (this.nodes) {
1512
- for (let node2 of this.nodes) node2.cleanRaws(keepBetween);
1577
+ origin(line, column, endLine, endColumn) {
1578
+ if (!this.map) return false;
1579
+ let consumer = this.map.consumer();
1580
+ let from = consumer.originalPositionFor({ column, line });
1581
+ if (!from.source) return false;
1582
+ let to;
1583
+ if (typeof endLine === "number") {
1584
+ to = consumer.originalPositionFor({ column: endColumn, line: endLine });
1513
1585
  }
1514
- }
1515
- each(callback) {
1516
- if (!this.proxyOf.nodes) return void 0;
1517
- let iterator = this.getIterator();
1518
- let index2, result2;
1519
- while (this.indexes[iterator] < this.proxyOf.nodes.length) {
1520
- index2 = this.indexes[iterator];
1521
- result2 = callback(this.proxyOf.nodes[index2], index2);
1522
- if (result2 === false) break;
1523
- this.indexes[iterator] += 1;
1586
+ let fromUrl;
1587
+ if (isAbsolute(from.source)) {
1588
+ fromUrl = pathToFileURL$1(from.source);
1589
+ } else {
1590
+ fromUrl = new URL(
1591
+ from.source,
1592
+ this.map.consumer().sourceRoot || pathToFileURL$1(this.map.mapFile)
1593
+ );
1524
1594
  }
1525
- delete this.indexes[iterator];
1595
+ let result2 = {
1596
+ column: from.column,
1597
+ endColumn: to && to.column,
1598
+ endLine: to && to.line,
1599
+ line: from.line,
1600
+ url: fromUrl.toString()
1601
+ };
1602
+ if (fromUrl.protocol === "file:") {
1603
+ if (fileURLToPath) {
1604
+ result2.file = fileURLToPath(fromUrl);
1605
+ } else {
1606
+ throw new Error(`file: protocol is not available in this PostCSS build`);
1607
+ }
1608
+ }
1609
+ let source = consumer.sourceContentFor(from.source);
1610
+ if (source) result2.source = source;
1526
1611
  return result2;
1527
1612
  }
1528
- every(condition) {
1529
- return this.nodes.every(condition);
1613
+ toJSON() {
1614
+ let json = {};
1615
+ for (let name of ["hasBOM", "css", "file", "id"]) {
1616
+ if (this[name] != null) {
1617
+ json[name] = this[name];
1618
+ }
1619
+ }
1620
+ if (this.map) {
1621
+ json.map = { ...this.map };
1622
+ if (json.map.consumerCache) {
1623
+ json.map.consumerCache = void 0;
1624
+ }
1625
+ }
1626
+ return json;
1530
1627
  }
1531
- getIterator() {
1532
- if (!this.lastEach) this.lastEach = 0;
1533
- if (!this.indexes) this.indexes = {};
1534
- this.lastEach += 1;
1535
- let iterator = this.lastEach;
1536
- this.indexes[iterator] = 0;
1537
- return iterator;
1628
+ get from() {
1629
+ return this.file || this.id;
1538
1630
  }
1539
- getProxyProcessor() {
1540
- return {
1541
- get(node2, prop) {
1542
- if (prop === "proxyOf") {
1543
- return node2;
1544
- } else if (!node2[prop]) {
1545
- return node2[prop];
1546
- } else if (prop === "each" || typeof prop === "string" && prop.startsWith("walk")) {
1547
- return (...args) => {
1548
- return node2[prop](
1549
- ...args.map((i) => {
1550
- if (typeof i === "function") {
1551
- return (child, index2) => i(child.toProxy(), index2);
1552
- } else {
1553
- return i;
1554
- }
1555
- })
1556
- );
1557
- };
1558
- } else if (prop === "every" || prop === "some") {
1559
- return (cb) => {
1560
- return node2[prop](
1561
- (child, ...other) => cb(child.toProxy(), ...other)
1562
- );
1563
- };
1564
- } else if (prop === "root") {
1565
- return () => node2.root().toProxy();
1566
- } else if (prop === "nodes") {
1567
- return node2.nodes.map((i) => i.toProxy());
1568
- } else if (prop === "first" || prop === "last") {
1569
- return node2[prop].toProxy();
1631
+ };
1632
+ var input = Input$6;
1633
+ Input$6.default = Input$6;
1634
+ if (terminalHighlight && terminalHighlight.registerInput) {
1635
+ terminalHighlight.registerInput(Input$6);
1636
+ }
1637
+ let Container$5 = container;
1638
+ let LazyResult$3, Processor$3;
1639
+ let Root$6 = class Root extends Container$5 {
1640
+ constructor(defaults) {
1641
+ super(defaults);
1642
+ this.type = "root";
1643
+ if (!this.nodes) this.nodes = [];
1644
+ }
1645
+ normalize(child, sample, type) {
1646
+ let nodes = super.normalize(child);
1647
+ if (sample) {
1648
+ if (type === "prepend") {
1649
+ if (this.nodes.length > 1) {
1650
+ sample.raws.before = this.nodes[1].raws.before;
1570
1651
  } else {
1571
- return node2[prop];
1652
+ delete sample.raws.before;
1572
1653
  }
1573
- },
1574
- set(node2, prop, value) {
1575
- if (node2[prop] === value) return true;
1576
- node2[prop] = value;
1577
- if (prop === "name" || prop === "params" || prop === "selector") {
1578
- node2.markDirty();
1654
+ } else if (this.first !== sample) {
1655
+ for (let node2 of nodes) {
1656
+ node2.raws.before = sample.raws.before;
1579
1657
  }
1580
- return true;
1581
- }
1582
- };
1583
- }
1584
- index(child) {
1585
- if (typeof child === "number") return child;
1586
- if (child.proxyOf) child = child.proxyOf;
1587
- return this.proxyOf.nodes.indexOf(child);
1588
- }
1589
- insertAfter(exist, add) {
1590
- let existIndex = this.index(exist);
1591
- let nodes = this.normalize(add, this.proxyOf.nodes[existIndex]).reverse();
1592
- existIndex = this.index(exist);
1593
- for (let node2 of nodes) this.proxyOf.nodes.splice(existIndex + 1, 0, node2);
1594
- let index2;
1595
- for (let id in this.indexes) {
1596
- index2 = this.indexes[id];
1597
- if (existIndex < index2) {
1598
- this.indexes[id] = index2 + nodes.length;
1599
1658
  }
1600
1659
  }
1601
- this.markDirty();
1602
- return this;
1660
+ return nodes;
1603
1661
  }
1604
- insertBefore(exist, add) {
1605
- let existIndex = this.index(exist);
1606
- let type = existIndex === 0 ? "prepend" : false;
1607
- let nodes = this.normalize(add, this.proxyOf.nodes[existIndex], type).reverse();
1608
- existIndex = this.index(exist);
1609
- for (let node2 of nodes) this.proxyOf.nodes.splice(existIndex, 0, node2);
1610
- let index2;
1611
- for (let id in this.indexes) {
1612
- index2 = this.indexes[id];
1613
- if (existIndex <= index2) {
1614
- this.indexes[id] = index2 + nodes.length;
1615
- }
1662
+ removeChild(child, ignore) {
1663
+ let index2 = this.index(child);
1664
+ if (!ignore && index2 === 0 && this.nodes.length > 1) {
1665
+ this.nodes[1].raws.before = this.nodes[index2].raws.before;
1616
1666
  }
1617
- this.markDirty();
1618
- return this;
1667
+ return super.removeChild(child);
1619
1668
  }
1620
- normalize(nodes, sample) {
1621
- if (typeof nodes === "string") {
1622
- nodes = cleanSource(parse$4(nodes).nodes);
1623
- } else if (typeof nodes === "undefined") {
1624
- nodes = [];
1625
- } else if (Array.isArray(nodes)) {
1626
- nodes = nodes.slice(0);
1627
- for (let i of nodes) {
1628
- if (i.parent) i.parent.removeChild(i, "ignore");
1629
- }
1630
- } else if (nodes.type === "root" && this.type !== "document") {
1631
- nodes = nodes.nodes.slice(0);
1632
- for (let i of nodes) {
1633
- if (i.parent) i.parent.removeChild(i, "ignore");
1634
- }
1635
- } else if (nodes.type) {
1636
- nodes = [nodes];
1637
- } else if (nodes.prop) {
1638
- if (typeof nodes.value === "undefined") {
1639
- throw new Error("Value field is missed in node creation");
1640
- } else if (typeof nodes.value !== "string") {
1641
- nodes.value = String(nodes.value);
1642
- }
1643
- nodes = [new Declaration$3(nodes)];
1644
- } else if (nodes.selector) {
1645
- nodes = [new Rule$4(nodes)];
1646
- } else if (nodes.name) {
1647
- nodes = [new AtRule$4(nodes)];
1648
- } else if (nodes.text) {
1649
- nodes = [new Comment$3(nodes)];
1650
- } else {
1651
- throw new Error("Unknown node type in node creation");
1652
- }
1653
- let processed = nodes.map((i) => {
1654
- if (!i[my$1]) Container.rebuild(i);
1655
- i = i.proxyOf;
1656
- if (i.parent) i.parent.removeChild(i);
1657
- if (i[isClean$1]) markDirtyUp(i);
1658
- if (typeof i.raws.before === "undefined") {
1659
- if (sample && typeof sample.raws.before !== "undefined") {
1660
- i.raws.before = sample.raws.before.replace(/\S/g, "");
1669
+ toResult(opts = {}) {
1670
+ let lazy = new LazyResult$3(new Processor$3(), this, opts);
1671
+ return lazy.stringify();
1672
+ }
1673
+ };
1674
+ Root$6.registerLazyResult = (dependant) => {
1675
+ LazyResult$3 = dependant;
1676
+ };
1677
+ Root$6.registerProcessor = (dependant) => {
1678
+ Processor$3 = dependant;
1679
+ };
1680
+ var root$1 = Root$6;
1681
+ Root$6.default = Root$6;
1682
+ Container$5.registerRoot(Root$6);
1683
+ let list$3 = {
1684
+ comma(string) {
1685
+ return list$3.split(string, [","], true);
1686
+ },
1687
+ space(string) {
1688
+ let spaces = [" ", "\n", " "];
1689
+ return list$3.split(string, spaces);
1690
+ },
1691
+ split(string, separators, last) {
1692
+ let array = [];
1693
+ let current = "";
1694
+ let split = false;
1695
+ let func = 0;
1696
+ let inQuote = false;
1697
+ let prevQuote = "";
1698
+ let escape = false;
1699
+ for (let letter of string) {
1700
+ if (escape) {
1701
+ escape = false;
1702
+ } else if (letter === "\\") {
1703
+ escape = true;
1704
+ } else if (inQuote) {
1705
+ if (letter === prevQuote) {
1706
+ inQuote = false;
1661
1707
  }
1708
+ } else if (letter === '"' || letter === "'") {
1709
+ inQuote = true;
1710
+ prevQuote = letter;
1711
+ } else if (letter === "(") {
1712
+ func += 1;
1713
+ } else if (letter === ")") {
1714
+ if (func > 0) func -= 1;
1715
+ } else if (func === 0) {
1716
+ if (separators.includes(letter)) split = true;
1662
1717
  }
1663
- i.parent = this.proxyOf;
1664
- return i;
1665
- });
1666
- return processed;
1667
- }
1668
- prepend(...children) {
1669
- children = children.reverse();
1670
- for (let child of children) {
1671
- let nodes = this.normalize(child, this.first, "prepend").reverse();
1672
- for (let node2 of nodes) this.proxyOf.nodes.unshift(node2);
1673
- for (let id in this.indexes) {
1674
- this.indexes[id] = this.indexes[id] + nodes.length;
1718
+ if (split) {
1719
+ if (current !== "") array.push(current.trim());
1720
+ current = "";
1721
+ split = false;
1722
+ } else {
1723
+ current += letter;
1675
1724
  }
1676
1725
  }
1677
- this.markDirty();
1678
- return this;
1726
+ if (last || current !== "") array.push(current.trim());
1727
+ return array;
1679
1728
  }
1680
- push(child) {
1681
- child.parent = this;
1682
- this.proxyOf.nodes.push(child);
1683
- return this;
1729
+ };
1730
+ var list_1 = list$3;
1731
+ list$3.default = list$3;
1732
+ let Container$4 = container;
1733
+ let list$2 = list_1;
1734
+ let Rule$4 = class Rule extends Container$4 {
1735
+ constructor(defaults) {
1736
+ super(defaults);
1737
+ this.type = "rule";
1738
+ if (!this.nodes) this.nodes = [];
1684
1739
  }
1685
- removeAll() {
1686
- for (let node2 of this.proxyOf.nodes) node2.parent = void 0;
1687
- this.proxyOf.nodes = [];
1688
- this.markDirty();
1689
- return this;
1740
+ get selectors() {
1741
+ return list$2.comma(this.selector);
1690
1742
  }
1691
- removeChild(child) {
1692
- child = this.index(child);
1693
- this.proxyOf.nodes[child].parent = void 0;
1694
- this.proxyOf.nodes.splice(child, 1);
1695
- let index2;
1696
- for (let id in this.indexes) {
1697
- index2 = this.indexes[id];
1698
- if (index2 >= child) {
1699
- this.indexes[id] = index2 - 1;
1743
+ set selectors(values) {
1744
+ let match = this.selector ? this.selector.match(/,\s*/) : null;
1745
+ let sep2 = match ? match[0] : "," + this.raw("between", "beforeOpen");
1746
+ this.selector = values.join(sep2);
1747
+ }
1748
+ };
1749
+ var rule$1 = Rule$4;
1750
+ Rule$4.default = Rule$4;
1751
+ Container$4.registerRule(Rule$4);
1752
+ let AtRule$3 = atRule$1;
1753
+ let Comment$4 = comment$1;
1754
+ let Declaration$3 = declaration;
1755
+ let Input$5 = input;
1756
+ let PreviousMap2 = previousMap;
1757
+ let Root$5 = root$1;
1758
+ let Rule$3 = rule$1;
1759
+ function fromJSON$2(json, inputs) {
1760
+ if (Array.isArray(json)) return json.map((n) => fromJSON$2(n));
1761
+ let { inputs: ownInputs, ...defaults } = json;
1762
+ if (ownInputs) {
1763
+ inputs = [];
1764
+ for (let input2 of ownInputs) {
1765
+ let inputHydrated = { ...input2, __proto__: Input$5.prototype };
1766
+ if (inputHydrated.map) {
1767
+ inputHydrated.map = {
1768
+ ...inputHydrated.map,
1769
+ __proto__: PreviousMap2.prototype
1770
+ };
1700
1771
  }
1772
+ inputs.push(inputHydrated);
1701
1773
  }
1702
- this.markDirty();
1703
- return this;
1704
1774
  }
1705
- replaceValues(pattern, opts, callback) {
1706
- if (!callback) {
1707
- callback = opts;
1708
- opts = {};
1775
+ if (defaults.nodes) {
1776
+ defaults.nodes = json.nodes.map((n) => fromJSON$2(n, inputs));
1777
+ }
1778
+ if (defaults.source) {
1779
+ let { inputId, ...source } = defaults.source;
1780
+ defaults.source = source;
1781
+ if (inputId != null) {
1782
+ defaults.source.input = inputs[inputId];
1709
1783
  }
1710
- this.walkDecls((decl) => {
1711
- if (opts.props && !opts.props.includes(decl.prop)) return;
1712
- if (opts.fast && !decl.value.includes(opts.fast)) return;
1713
- decl.value = decl.value.replace(pattern, callback);
1714
- });
1715
- this.markDirty();
1716
- return this;
1717
1784
  }
1718
- some(condition) {
1719
- return this.nodes.some(condition);
1785
+ if (defaults.type === "root") {
1786
+ return new Root$5(defaults);
1787
+ } else if (defaults.type === "decl") {
1788
+ return new Declaration$3(defaults);
1789
+ } else if (defaults.type === "rule") {
1790
+ return new Rule$3(defaults);
1791
+ } else if (defaults.type === "comment") {
1792
+ return new Comment$4(defaults);
1793
+ } else if (defaults.type === "atrule") {
1794
+ return new AtRule$3(defaults);
1795
+ } else {
1796
+ throw new Error("Unknown node type: " + json.type);
1720
1797
  }
1721
- walk(callback) {
1722
- return this.each((child, i) => {
1723
- let result2;
1724
- try {
1725
- result2 = callback(child, i);
1726
- } catch (e) {
1727
- throw child.addToError(e);
1728
- }
1729
- if (result2 !== false && child.walk) {
1730
- result2 = child.walk(callback);
1798
+ }
1799
+ var fromJSON_1 = fromJSON$2;
1800
+ fromJSON$2.default = fromJSON$2;
1801
+ let { dirname, relative, resolve, sep } = require$$2;
1802
+ let { SourceMapConsumer, SourceMapGenerator } = require$$2;
1803
+ let { pathToFileURL } = require$$2;
1804
+ let Input$4 = input;
1805
+ let sourceMapAvailable = Boolean(SourceMapConsumer && SourceMapGenerator);
1806
+ let pathAvailable = Boolean(dirname && resolve && relative && sep);
1807
+ let MapGenerator$2 = class MapGenerator {
1808
+ constructor(stringify2, root2, opts, cssString) {
1809
+ this.stringify = stringify2;
1810
+ this.mapOpts = opts.map || {};
1811
+ this.root = root2;
1812
+ this.opts = opts;
1813
+ this.css = cssString;
1814
+ this.originalCSS = cssString;
1815
+ this.usesFileUrls = !this.mapOpts.from && this.mapOpts.absolute;
1816
+ this.memoizedFileURLs = /* @__PURE__ */ new Map();
1817
+ this.memoizedPaths = /* @__PURE__ */ new Map();
1818
+ this.memoizedURLs = /* @__PURE__ */ new Map();
1819
+ }
1820
+ addAnnotation() {
1821
+ let content;
1822
+ if (this.isInline()) {
1823
+ content = "data:application/json;base64," + this.toBase64(this.map.toString());
1824
+ } else if (typeof this.mapOpts.annotation === "string") {
1825
+ content = this.mapOpts.annotation;
1826
+ } else if (typeof this.mapOpts.annotation === "function") {
1827
+ content = this.mapOpts.annotation(this.opts.to, this.root);
1828
+ } else {
1829
+ content = this.outputFile() + ".map";
1830
+ }
1831
+ let eol = "\n";
1832
+ if (this.css.includes("\r\n")) eol = "\r\n";
1833
+ this.css += eol + "/*# sourceMappingURL=" + content + " */";
1834
+ }
1835
+ applyPrevMaps() {
1836
+ for (let prev of this.previous()) {
1837
+ let from = this.toUrl(this.path(prev.file));
1838
+ let root2 = prev.root || dirname(prev.file);
1839
+ let map;
1840
+ if (this.mapOpts.sourcesContent === false) {
1841
+ map = new SourceMapConsumer(prev.text);
1842
+ if (map.sourcesContent) {
1843
+ map.sourcesContent = null;
1844
+ }
1845
+ } else {
1846
+ map = prev.consumer();
1731
1847
  }
1732
- return result2;
1733
- });
1848
+ this.map.applySourceMap(map, from, this.toUrl(this.path(root2)));
1849
+ }
1734
1850
  }
1735
- walkAtRules(name, callback) {
1736
- if (!callback) {
1737
- callback = name;
1738
- return this.walk((child, i) => {
1739
- if (child.type === "atrule") {
1740
- return callback(child, i);
1851
+ clearAnnotation() {
1852
+ if (this.mapOpts.annotation === false) return;
1853
+ if (this.root) {
1854
+ let node2;
1855
+ for (let i = this.root.nodes.length - 1; i >= 0; i--) {
1856
+ node2 = this.root.nodes[i];
1857
+ if (node2.type !== "comment") continue;
1858
+ if (node2.text.startsWith("# sourceMappingURL=")) {
1859
+ this.root.removeChild(i);
1741
1860
  }
1861
+ }
1862
+ } else if (this.css) {
1863
+ this.css = this.css.replace(/\n*\/\*#[\S\s]*?\*\/$/gm, "");
1864
+ }
1865
+ }
1866
+ generate() {
1867
+ this.clearAnnotation();
1868
+ if (pathAvailable && sourceMapAvailable && this.isMap()) {
1869
+ return this.generateMap();
1870
+ } else {
1871
+ let result2 = "";
1872
+ this.stringify(this.root, (i) => {
1873
+ result2 += i;
1742
1874
  });
1875
+ return [result2];
1743
1876
  }
1744
- if (name instanceof RegExp) {
1745
- return this.walk((child, i) => {
1746
- if (child.type === "atrule" && name.test(child.name)) {
1747
- return callback(child, i);
1748
- }
1877
+ }
1878
+ generateMap() {
1879
+ if (this.root) {
1880
+ this.generateString();
1881
+ } else if (this.previous().length === 1) {
1882
+ let prev = this.previous()[0].consumer();
1883
+ prev.file = this.outputFile();
1884
+ this.map = SourceMapGenerator.fromSourceMap(prev, {
1885
+ ignoreInvalidMapping: true
1886
+ });
1887
+ } else {
1888
+ this.map = new SourceMapGenerator({
1889
+ file: this.outputFile(),
1890
+ ignoreInvalidMapping: true
1891
+ });
1892
+ this.map.addMapping({
1893
+ generated: { column: 0, line: 1 },
1894
+ original: { column: 0, line: 1 },
1895
+ source: this.opts.from ? this.toUrl(this.path(this.opts.from)) : "<no source>"
1749
1896
  });
1750
1897
  }
1751
- return this.walk((child, i) => {
1752
- if (child.type === "atrule" && child.name === name) {
1753
- return callback(child, i);
1898
+ if (this.isSourcesContent()) this.setSourcesContent();
1899
+ if (this.root && this.previous().length > 0) this.applyPrevMaps();
1900
+ if (this.isAnnotation()) this.addAnnotation();
1901
+ if (this.isInline()) {
1902
+ return [this.css];
1903
+ } else {
1904
+ return [this.css, this.map];
1905
+ }
1906
+ }
1907
+ generateString() {
1908
+ this.css = "";
1909
+ this.map = new SourceMapGenerator({
1910
+ file: this.outputFile(),
1911
+ ignoreInvalidMapping: true
1912
+ });
1913
+ let line = 1;
1914
+ let column = 1;
1915
+ let noSource = "<no source>";
1916
+ let mapping = {
1917
+ generated: { column: 0, line: 0 },
1918
+ original: { column: 0, line: 0 },
1919
+ source: ""
1920
+ };
1921
+ let last, lines;
1922
+ this.stringify(this.root, (str, node2, type) => {
1923
+ this.css += str;
1924
+ if (node2 && type !== "end") {
1925
+ mapping.generated.line = line;
1926
+ mapping.generated.column = column - 1;
1927
+ if (node2.source && node2.source.start) {
1928
+ mapping.source = this.sourcePath(node2);
1929
+ mapping.original.line = node2.source.start.line;
1930
+ mapping.original.column = node2.source.start.column - 1;
1931
+ this.map.addMapping(mapping);
1932
+ } else {
1933
+ mapping.source = noSource;
1934
+ mapping.original.line = 1;
1935
+ mapping.original.column = 0;
1936
+ this.map.addMapping(mapping);
1937
+ }
1754
1938
  }
1755
- });
1756
- }
1757
- walkComments(callback) {
1758
- return this.walk((child, i) => {
1759
- if (child.type === "comment") {
1760
- return callback(child, i);
1939
+ lines = str.match(/\n/g);
1940
+ if (lines) {
1941
+ line += lines.length;
1942
+ last = str.lastIndexOf("\n");
1943
+ column = str.length - last;
1944
+ } else {
1945
+ column += str.length;
1761
1946
  }
1762
- });
1763
- }
1764
- walkDecls(prop, callback) {
1765
- if (!callback) {
1766
- callback = prop;
1767
- return this.walk((child, i) => {
1768
- if (child.type === "decl") {
1769
- return callback(child, i);
1770
- }
1771
- });
1772
- }
1773
- if (prop instanceof RegExp) {
1774
- return this.walk((child, i) => {
1775
- if (child.type === "decl" && prop.test(child.prop)) {
1776
- return callback(child, i);
1947
+ if (node2 && type !== "start") {
1948
+ let p = node2.parent || { raws: {} };
1949
+ let childless = node2.type === "decl" || node2.type === "atrule" && !node2.nodes;
1950
+ if (!childless || node2 !== p.last || p.raws.semicolon) {
1951
+ if (node2.source && node2.source.end) {
1952
+ mapping.source = this.sourcePath(node2);
1953
+ mapping.original.line = node2.source.end.line;
1954
+ mapping.original.column = node2.source.end.column - 1;
1955
+ mapping.generated.line = line;
1956
+ mapping.generated.column = column - 2;
1957
+ this.map.addMapping(mapping);
1958
+ } else {
1959
+ mapping.source = noSource;
1960
+ mapping.original.line = 1;
1961
+ mapping.original.column = 0;
1962
+ mapping.generated.line = line;
1963
+ mapping.generated.column = column - 1;
1964
+ this.map.addMapping(mapping);
1965
+ }
1777
1966
  }
1778
- });
1779
- }
1780
- return this.walk((child, i) => {
1781
- if (child.type === "decl" && child.prop === prop) {
1782
- return callback(child, i);
1783
1967
  }
1784
1968
  });
1785
1969
  }
1786
- walkRules(selector, callback) {
1787
- if (!callback) {
1788
- callback = selector;
1789
- return this.walk((child, i) => {
1790
- if (child.type === "rule") {
1791
- return callback(child, i);
1792
- }
1793
- });
1970
+ isAnnotation() {
1971
+ if (this.isInline()) {
1972
+ return true;
1794
1973
  }
1795
- if (selector instanceof RegExp) {
1796
- return this.walk((child, i) => {
1797
- if (child.type === "rule" && selector.test(child.selector)) {
1798
- return callback(child, i);
1799
- }
1800
- });
1974
+ if (typeof this.mapOpts.annotation !== "undefined") {
1975
+ return this.mapOpts.annotation;
1801
1976
  }
1802
- return this.walk((child, i) => {
1803
- if (child.type === "rule" && child.selector === selector) {
1804
- return callback(child, i);
1805
- }
1806
- });
1807
- }
1808
- get first() {
1809
- if (!this.proxyOf.nodes) return void 0;
1810
- return this.proxyOf.nodes[0];
1811
- }
1812
- get last() {
1813
- if (!this.proxyOf.nodes) return void 0;
1814
- return this.proxyOf.nodes[this.proxyOf.nodes.length - 1];
1815
- }
1816
- };
1817
- Container$7.registerParse = (dependant) => {
1818
- parse$4 = dependant;
1819
- };
1820
- Container$7.registerRule = (dependant) => {
1821
- Rule$4 = dependant;
1822
- };
1823
- Container$7.registerAtRule = (dependant) => {
1824
- AtRule$4 = dependant;
1825
- };
1826
- Container$7.registerRoot = (dependant) => {
1827
- Root$6 = dependant;
1828
- };
1829
- var container = Container$7;
1830
- Container$7.default = Container$7;
1831
- Container$7.rebuild = (node2) => {
1832
- if (node2.type === "atrule") {
1833
- Object.setPrototypeOf(node2, AtRule$4.prototype);
1834
- } else if (node2.type === "rule") {
1835
- Object.setPrototypeOf(node2, Rule$4.prototype);
1836
- } else if (node2.type === "decl") {
1837
- Object.setPrototypeOf(node2, Declaration$3.prototype);
1838
- } else if (node2.type === "comment") {
1839
- Object.setPrototypeOf(node2, Comment$3.prototype);
1840
- } else if (node2.type === "root") {
1841
- Object.setPrototypeOf(node2, Root$6.prototype);
1842
- }
1843
- node2[my$1] = true;
1844
- if (node2.nodes) {
1845
- node2.nodes.forEach((child) => {
1846
- Container$7.rebuild(child);
1847
- });
1977
+ if (this.previous().length) {
1978
+ return this.previous().some((i) => i.annotation);
1979
+ }
1980
+ return true;
1848
1981
  }
1849
- };
1850
- let Container$6 = container;
1851
- let LazyResult$4, Processor$3;
1852
- let Document$3 = class Document2 extends Container$6 {
1853
- constructor(defaults) {
1854
- super({ type: "document", ...defaults });
1855
- if (!this.nodes) {
1856
- this.nodes = [];
1982
+ isInline() {
1983
+ if (typeof this.mapOpts.inline !== "undefined") {
1984
+ return this.mapOpts.inline;
1985
+ }
1986
+ let annotation = this.mapOpts.annotation;
1987
+ if (typeof annotation !== "undefined" && annotation !== true) {
1988
+ return false;
1989
+ }
1990
+ if (this.previous().length) {
1991
+ return this.previous().some((i) => i.inline);
1857
1992
  }
1993
+ return true;
1858
1994
  }
1859
- toResult(opts = {}) {
1860
- let lazy = new LazyResult$4(new Processor$3(), this, opts);
1861
- return lazy.stringify();
1995
+ isMap() {
1996
+ if (typeof this.opts.map !== "undefined") {
1997
+ return !!this.opts.map;
1998
+ }
1999
+ return this.previous().length > 0;
1862
2000
  }
1863
- };
1864
- Document$3.registerLazyResult = (dependant) => {
1865
- LazyResult$4 = dependant;
1866
- };
1867
- Document$3.registerProcessor = (dependant) => {
1868
- Processor$3 = dependant;
1869
- };
1870
- var document$1 = Document$3;
1871
- Document$3.default = Document$3;
1872
- let printed = {};
1873
- var warnOnce$2 = function warnOnce(message) {
1874
- if (printed[message]) return;
1875
- printed[message] = true;
1876
- if (typeof console !== "undefined" && console.warn) {
1877
- console.warn(message);
2001
+ isSourcesContent() {
2002
+ if (typeof this.mapOpts.sourcesContent !== "undefined") {
2003
+ return this.mapOpts.sourcesContent;
2004
+ }
2005
+ if (this.previous().length) {
2006
+ return this.previous().some((i) => i.withContent());
2007
+ }
2008
+ return true;
1878
2009
  }
1879
- };
1880
- let Warning$2 = class Warning {
1881
- constructor(text, opts = {}) {
1882
- this.type = "warning";
1883
- this.text = text;
1884
- if (opts.node && opts.node.source) {
1885
- let range = opts.node.rangeBy(opts);
1886
- this.line = range.start.line;
1887
- this.column = range.start.column;
1888
- this.endLine = range.end.line;
1889
- this.endColumn = range.end.column;
2010
+ outputFile() {
2011
+ if (this.opts.to) {
2012
+ return this.path(this.opts.to);
2013
+ } else if (this.opts.from) {
2014
+ return this.path(this.opts.from);
2015
+ } else {
2016
+ return "to.css";
1890
2017
  }
1891
- for (let opt in opts) this[opt] = opts[opt];
1892
2018
  }
1893
- toString() {
1894
- if (this.node) {
1895
- return this.node.error(this.text, {
1896
- index: this.index,
1897
- plugin: this.plugin,
1898
- word: this.word
1899
- }).message;
2019
+ path(file) {
2020
+ if (this.mapOpts.absolute) return file;
2021
+ if (file.charCodeAt(0) === 60) return file;
2022
+ if (/^\w+:\/\//.test(file)) return file;
2023
+ let cached = this.memoizedPaths.get(file);
2024
+ if (cached) return cached;
2025
+ let from = this.opts.to ? dirname(this.opts.to) : ".";
2026
+ if (typeof this.mapOpts.annotation === "string") {
2027
+ from = dirname(resolve(from, this.mapOpts.annotation));
1900
2028
  }
1901
- if (this.plugin) {
1902
- return this.plugin + ": " + this.text;
2029
+ let path = relative(from, file);
2030
+ this.memoizedPaths.set(file, path);
2031
+ return path;
2032
+ }
2033
+ previous() {
2034
+ if (!this.previousMaps) {
2035
+ this.previousMaps = [];
2036
+ if (this.root) {
2037
+ this.root.walk((node2) => {
2038
+ if (node2.source && node2.source.input.map) {
2039
+ let map = node2.source.input.map;
2040
+ if (!this.previousMaps.includes(map)) {
2041
+ this.previousMaps.push(map);
2042
+ }
2043
+ }
2044
+ });
2045
+ } else {
2046
+ let input2 = new Input$4(this.originalCSS, this.opts);
2047
+ if (input2.map) this.previousMaps.push(input2.map);
2048
+ }
1903
2049
  }
1904
- return this.text;
2050
+ return this.previousMaps;
1905
2051
  }
1906
- };
1907
- var warning = Warning$2;
1908
- Warning$2.default = Warning$2;
1909
- let Warning$1 = warning;
1910
- let Result$3 = class Result {
1911
- constructor(processor2, root2, opts) {
1912
- this.processor = processor2;
1913
- this.messages = [];
1914
- this.root = root2;
1915
- this.opts = opts;
1916
- this.css = void 0;
1917
- this.map = void 0;
2052
+ setSourcesContent() {
2053
+ let already = {};
2054
+ if (this.root) {
2055
+ this.root.walk((node2) => {
2056
+ if (node2.source) {
2057
+ let from = node2.source.input.from;
2058
+ if (from && !already[from]) {
2059
+ already[from] = true;
2060
+ let fromUrl = this.usesFileUrls ? this.toFileUrl(from) : this.toUrl(this.path(from));
2061
+ this.map.setSourceContent(fromUrl, node2.source.input.css);
2062
+ }
2063
+ }
2064
+ });
2065
+ } else if (this.css) {
2066
+ let from = this.opts.from ? this.toUrl(this.path(this.opts.from)) : "<no source>";
2067
+ this.map.setSourceContent(from, this.css);
2068
+ }
1918
2069
  }
1919
- toString() {
1920
- return this.css;
2070
+ sourcePath(node2) {
2071
+ if (this.mapOpts.from) {
2072
+ return this.toUrl(this.mapOpts.from);
2073
+ } else if (this.usesFileUrls) {
2074
+ return this.toFileUrl(node2.source.input.from);
2075
+ } else {
2076
+ return this.toUrl(this.path(node2.source.input.from));
2077
+ }
1921
2078
  }
1922
- warn(text, opts = {}) {
1923
- if (!opts.plugin) {
1924
- if (this.lastPlugin && this.lastPlugin.postcssPlugin) {
1925
- opts.plugin = this.lastPlugin.postcssPlugin;
1926
- }
2079
+ toBase64(str) {
2080
+ if (Buffer) {
2081
+ return Buffer.from(str).toString("base64");
2082
+ } else {
2083
+ return window.btoa(unescape(encodeURIComponent(str)));
1927
2084
  }
1928
- let warning2 = new Warning$1(text, opts);
1929
- this.messages.push(warning2);
1930
- return warning2;
1931
2085
  }
1932
- warnings() {
1933
- return this.messages.filter((i) => i.type === "warning");
2086
+ toFileUrl(path) {
2087
+ let cached = this.memoizedFileURLs.get(path);
2088
+ if (cached) return cached;
2089
+ if (pathToFileURL) {
2090
+ let fileURL = pathToFileURL(path).toString();
2091
+ this.memoizedFileURLs.set(path, fileURL);
2092
+ return fileURL;
2093
+ } else {
2094
+ throw new Error(
2095
+ "`map.absolute` option is not available in this PostCSS build"
2096
+ );
2097
+ }
1934
2098
  }
1935
- get content() {
1936
- return this.css;
2099
+ toUrl(path) {
2100
+ let cached = this.memoizedURLs.get(path);
2101
+ if (cached) return cached;
2102
+ if (sep === "\\") {
2103
+ path = path.replace(/\\/g, "/");
2104
+ }
2105
+ let url = encodeURI(path).replace(/[#?]/g, encodeURIComponent);
2106
+ this.memoizedURLs.set(path, url);
2107
+ return url;
1937
2108
  }
1938
2109
  };
1939
- var result = Result$3;
1940
- Result$3.default = Result$3;
2110
+ var mapGenerator = MapGenerator$2;
1941
2111
  const SINGLE_QUOTE = "'".charCodeAt(0);
1942
2112
  const DOUBLE_QUOTE = '"'.charCodeAt(0);
1943
2113
  const BACKSLASH = "\\".charCodeAt(0);
@@ -1964,8 +2134,8 @@ const RE_HEX_ESCAPE = /[\da-f]/i;
1964
2134
  var tokenize = function tokenizer(input2, options = {}) {
1965
2135
  let css = input2.css.valueOf();
1966
2136
  let ignore = options.ignoreErrors;
1967
- let code, next, quote, content, escape;
1968
- let escaped, escapePos, prev, n, currentToken;
2137
+ let code, content, escape, next, quote;
2138
+ let currentToken, escaped, escapePos, n, prev;
1969
2139
  let length = css.length;
1970
2140
  let pos = 0;
1971
2141
  let buffer = [];
@@ -2146,145 +2316,12 @@ var tokenize = function tokenizer(input2, options = {}) {
2146
2316
  position
2147
2317
  };
2148
2318
  };
2149
- let Container$5 = container;
2150
- let AtRule$3 = class AtRule extends Container$5 {
2151
- constructor(defaults) {
2152
- super(defaults);
2153
- this.type = "atrule";
2154
- }
2155
- append(...children) {
2156
- if (!this.proxyOf.nodes) this.nodes = [];
2157
- return super.append(...children);
2158
- }
2159
- prepend(...children) {
2160
- if (!this.proxyOf.nodes) this.nodes = [];
2161
- return super.prepend(...children);
2162
- }
2163
- };
2164
- var atRule = AtRule$3;
2165
- AtRule$3.default = AtRule$3;
2166
- Container$5.registerAtRule(AtRule$3);
2167
- let Container$4 = container;
2168
- let LazyResult$3, Processor$2;
2169
- let Root$5 = class Root extends Container$4 {
2170
- constructor(defaults) {
2171
- super(defaults);
2172
- this.type = "root";
2173
- if (!this.nodes) this.nodes = [];
2174
- }
2175
- normalize(child, sample, type) {
2176
- let nodes = super.normalize(child);
2177
- if (sample) {
2178
- if (type === "prepend") {
2179
- if (this.nodes.length > 1) {
2180
- sample.raws.before = this.nodes[1].raws.before;
2181
- } else {
2182
- delete sample.raws.before;
2183
- }
2184
- } else if (this.first !== sample) {
2185
- for (let node2 of nodes) {
2186
- node2.raws.before = sample.raws.before;
2187
- }
2188
- }
2189
- }
2190
- return nodes;
2191
- }
2192
- removeChild(child, ignore) {
2193
- let index2 = this.index(child);
2194
- if (!ignore && index2 === 0 && this.nodes.length > 1) {
2195
- this.nodes[1].raws.before = this.nodes[index2].raws.before;
2196
- }
2197
- return super.removeChild(child);
2198
- }
2199
- toResult(opts = {}) {
2200
- let lazy = new LazyResult$3(new Processor$2(), this, opts);
2201
- return lazy.stringify();
2202
- }
2203
- };
2204
- Root$5.registerLazyResult = (dependant) => {
2205
- LazyResult$3 = dependant;
2206
- };
2207
- Root$5.registerProcessor = (dependant) => {
2208
- Processor$2 = dependant;
2209
- };
2210
- var root = Root$5;
2211
- Root$5.default = Root$5;
2212
- Container$4.registerRoot(Root$5);
2213
- let list$2 = {
2214
- comma(string) {
2215
- return list$2.split(string, [","], true);
2216
- },
2217
- space(string) {
2218
- let spaces = [" ", "\n", " "];
2219
- return list$2.split(string, spaces);
2220
- },
2221
- split(string, separators, last) {
2222
- let array = [];
2223
- let current = "";
2224
- let split = false;
2225
- let func = 0;
2226
- let inQuote = false;
2227
- let prevQuote = "";
2228
- let escape = false;
2229
- for (let letter of string) {
2230
- if (escape) {
2231
- escape = false;
2232
- } else if (letter === "\\") {
2233
- escape = true;
2234
- } else if (inQuote) {
2235
- if (letter === prevQuote) {
2236
- inQuote = false;
2237
- }
2238
- } else if (letter === '"' || letter === "'") {
2239
- inQuote = true;
2240
- prevQuote = letter;
2241
- } else if (letter === "(") {
2242
- func += 1;
2243
- } else if (letter === ")") {
2244
- if (func > 0) func -= 1;
2245
- } else if (func === 0) {
2246
- if (separators.includes(letter)) split = true;
2247
- }
2248
- if (split) {
2249
- if (current !== "") array.push(current.trim());
2250
- current = "";
2251
- split = false;
2252
- } else {
2253
- current += letter;
2254
- }
2255
- }
2256
- if (last || current !== "") array.push(current.trim());
2257
- return array;
2258
- }
2259
- };
2260
- var list_1 = list$2;
2261
- list$2.default = list$2;
2262
- let Container$3 = container;
2263
- let list$1 = list_1;
2264
- let Rule$3 = class Rule extends Container$3 {
2265
- constructor(defaults) {
2266
- super(defaults);
2267
- this.type = "rule";
2268
- if (!this.nodes) this.nodes = [];
2269
- }
2270
- get selectors() {
2271
- return list$1.comma(this.selector);
2272
- }
2273
- set selectors(values) {
2274
- let match = this.selector ? this.selector.match(/,\s*/) : null;
2275
- let sep2 = match ? match[0] : "," + this.raw("between", "beforeOpen");
2276
- this.selector = values.join(sep2);
2277
- }
2278
- };
2279
- var rule = Rule$3;
2280
- Rule$3.default = Rule$3;
2281
- Container$3.registerRule(Rule$3);
2319
+ let AtRule$2 = atRule$1;
2320
+ let Comment$3 = comment$1;
2282
2321
  let Declaration$2 = declaration;
2283
- let tokenizer2 = tokenize;
2284
- let Comment$2 = comment;
2285
- let AtRule$2 = atRule;
2286
- let Root$4 = root;
2287
- let Rule$2 = rule;
2322
+ let Root$4 = root$1;
2323
+ let Rule$2 = rule$1;
2324
+ let tokenizer$1 = tokenize;
2288
2325
  const SAFE_COMMENT_NEIGHBOR = {
2289
2326
  empty: true,
2290
2327
  space: true
@@ -2296,7 +2333,7 @@ function findLastWithPosition(tokens) {
2296
2333
  if (pos) return pos;
2297
2334
  }
2298
2335
  }
2299
- let Parser$1 = class Parser {
2336
+ let Parser$2 = class Parser {
2300
2337
  constructor(input2) {
2301
2338
  this.input = input2;
2302
2339
  this.root = new Root$4();
@@ -2403,7 +2440,7 @@ let Parser$1 = class Parser {
2403
2440
  }
2404
2441
  colon(tokens) {
2405
2442
  let brackets = 0;
2406
- let token, type, prev;
2443
+ let prev, token, type;
2407
2444
  for (let [i, element] of tokens.entries()) {
2408
2445
  token = element;
2409
2446
  type = token[0];
@@ -2427,7 +2464,7 @@ let Parser$1 = class Parser {
2427
2464
  return false;
2428
2465
  }
2429
2466
  comment(token) {
2430
- let node2 = new Comment$2();
2467
+ let node2 = new Comment$3();
2431
2468
  this.init(node2, token[2]);
2432
2469
  node2.source.end = this.getPosition(token[3] || token[2]);
2433
2470
  node2.source.end.offset++;
@@ -2444,7 +2481,7 @@ let Parser$1 = class Parser {
2444
2481
  }
2445
2482
  }
2446
2483
  createTokenizer() {
2447
- this.tokenizer = tokenizer2(this.input);
2484
+ this.tokenizer = tokenizer$1(this.input);
2448
2485
  }
2449
2486
  decl(tokens, customProperty) {
2450
2487
  let node2 = new Declaration$2();
@@ -2510,12 +2547,12 @@ let Parser$1 = class Parser {
2510
2547
  let str = "";
2511
2548
  for (let j = i; j > 0; j--) {
2512
2549
  let type = cache[j][0];
2513
- if (str.trim().indexOf("!") === 0 && type !== "space") {
2550
+ if (str.trim().startsWith("!") && type !== "space") {
2514
2551
  break;
2515
2552
  }
2516
2553
  str = cache.pop()[1] + str;
2517
2554
  }
2518
- if (str.trim().indexOf("!") === 0) {
2555
+ if (str.trim().startsWith("!")) {
2519
2556
  node2.important = true;
2520
2557
  node2.raws.important = str;
2521
2558
  tokens = cache;
@@ -2803,13 +2840,13 @@ let Parser$1 = class Parser {
2803
2840
  );
2804
2841
  }
2805
2842
  };
2806
- var parser = Parser$1;
2807
- let Container$2 = container;
2808
- let Parser2 = parser;
2809
- let Input$2 = input;
2810
- function parse$3(css, opts) {
2811
- let input2 = new Input$2(css, opts);
2812
- let parser2 = new Parser2(input2);
2843
+ var parser = Parser$2;
2844
+ let Container$3 = container;
2845
+ let Input$3 = input;
2846
+ let Parser$1 = parser;
2847
+ function parse$4(css, opts) {
2848
+ let input2 = new Input$3(css, opts);
2849
+ let parser2 = new Parser$1(input2);
2813
2850
  try {
2814
2851
  parser2.parse();
2815
2852
  } catch (e) {
@@ -2828,18 +2865,87 @@ function parse$3(css, opts) {
2828
2865
  }
2829
2866
  return parser2.root;
2830
2867
  }
2831
- var parse_1 = parse$3;
2832
- parse$3.default = parse$3;
2833
- Container$2.registerParse(parse$3);
2834
- let { isClean, my } = symbols;
2868
+ var parse_1 = parse$4;
2869
+ parse$4.default = parse$4;
2870
+ Container$3.registerParse(parse$4);
2871
+ let Warning$3 = class Warning {
2872
+ constructor(text, opts = {}) {
2873
+ this.type = "warning";
2874
+ this.text = text;
2875
+ if (opts.node && opts.node.source) {
2876
+ let range = opts.node.rangeBy(opts);
2877
+ this.line = range.start.line;
2878
+ this.column = range.start.column;
2879
+ this.endLine = range.end.line;
2880
+ this.endColumn = range.end.column;
2881
+ }
2882
+ for (let opt in opts) this[opt] = opts[opt];
2883
+ }
2884
+ toString() {
2885
+ if (this.node) {
2886
+ return this.node.error(this.text, {
2887
+ index: this.index,
2888
+ plugin: this.plugin,
2889
+ word: this.word
2890
+ }).message;
2891
+ }
2892
+ if (this.plugin) {
2893
+ return this.plugin + ": " + this.text;
2894
+ }
2895
+ return this.text;
2896
+ }
2897
+ };
2898
+ var warning = Warning$3;
2899
+ Warning$3.default = Warning$3;
2900
+ let Warning$2 = warning;
2901
+ let Result$4 = class Result {
2902
+ constructor(processor2, root2, opts) {
2903
+ this.processor = processor2;
2904
+ this.messages = [];
2905
+ this.root = root2;
2906
+ this.opts = opts;
2907
+ this.css = void 0;
2908
+ this.map = void 0;
2909
+ }
2910
+ toString() {
2911
+ return this.css;
2912
+ }
2913
+ warn(text, opts = {}) {
2914
+ if (!opts.plugin) {
2915
+ if (this.lastPlugin && this.lastPlugin.postcssPlugin) {
2916
+ opts.plugin = this.lastPlugin.postcssPlugin;
2917
+ }
2918
+ }
2919
+ let warning2 = new Warning$2(text, opts);
2920
+ this.messages.push(warning2);
2921
+ return warning2;
2922
+ }
2923
+ warnings() {
2924
+ return this.messages.filter((i) => i.type === "warning");
2925
+ }
2926
+ get content() {
2927
+ return this.css;
2928
+ }
2929
+ };
2930
+ var result = Result$4;
2931
+ Result$4.default = Result$4;
2932
+ let printed = {};
2933
+ var warnOnce$2 = function warnOnce(message) {
2934
+ if (printed[message]) return;
2935
+ printed[message] = true;
2936
+ if (typeof console !== "undefined" && console.warn) {
2937
+ console.warn(message);
2938
+ }
2939
+ };
2940
+ let Container$2 = container;
2941
+ let Document$3 = document$2;
2835
2942
  let MapGenerator$1 = mapGenerator;
2836
- let stringify$2 = stringify_1;
2837
- let Container$1 = container;
2838
- let Document$2 = document$1;
2943
+ let parse$3 = parse_1;
2944
+ let Result$3 = result;
2945
+ let Root$3 = root$1;
2946
+ let stringify$3 = stringify_1;
2947
+ let { isClean, my } = symbols;
2839
2948
  let warnOnce$1 = warnOnce$2;
2840
- let Result$2 = result;
2841
- let parse$2 = parse_1;
2842
- let Root$3 = root;
2843
2949
  const TYPE_TO_CLASS_NAME = {
2844
2950
  atrule: "AtRule",
2845
2951
  comment: "Comment",
@@ -2922,7 +3028,7 @@ function cleanMarks(node2) {
2922
3028
  if (node2.nodes) node2.nodes.forEach((i) => cleanMarks(i));
2923
3029
  return node2;
2924
3030
  }
2925
- let postcss$2 = {};
3031
+ let postcss$3 = {};
2926
3032
  let LazyResult$2 = class LazyResult {
2927
3033
  constructor(processor2, css, opts) {
2928
3034
  this.stringified = false;
@@ -2930,7 +3036,7 @@ let LazyResult$2 = class LazyResult {
2930
3036
  let root2;
2931
3037
  if (typeof css === "object" && css !== null && (css.type === "root" || css.type === "document")) {
2932
3038
  root2 = cleanMarks(css);
2933
- } else if (css instanceof LazyResult || css instanceof Result$2) {
3039
+ } else if (css instanceof LazyResult || css instanceof Result$3) {
2934
3040
  root2 = cleanMarks(css.root);
2935
3041
  if (css.map) {
2936
3042
  if (typeof opts.map === "undefined") opts.map = {};
@@ -2938,7 +3044,7 @@ let LazyResult$2 = class LazyResult {
2938
3044
  opts.map.prev = css.map;
2939
3045
  }
2940
3046
  } else {
2941
- let parser2 = parse$2;
3047
+ let parser2 = parse$3;
2942
3048
  if (opts.syntax) parser2 = opts.syntax.parse;
2943
3049
  if (opts.parser) parser2 = opts.parser;
2944
3050
  if (parser2.parse) parser2 = parser2.parse;
@@ -2949,16 +3055,16 @@ let LazyResult$2 = class LazyResult {
2949
3055
  this.error = error;
2950
3056
  }
2951
3057
  if (root2 && !root2[my]) {
2952
- Container$1.rebuild(root2);
3058
+ Container$2.rebuild(root2);
2953
3059
  }
2954
3060
  }
2955
- this.result = new Result$2(processor2, root2, opts);
2956
- this.helpers = { ...postcss$2, postcss: postcss$2, result: this.result };
2957
- this.plugins = this.processor.plugins.map((plugin2) => {
2958
- if (typeof plugin2 === "object" && plugin2.prepare) {
2959
- return { ...plugin2, ...plugin2.prepare(this.result) };
3061
+ this.result = new Result$3(processor2, root2, opts);
3062
+ this.helpers = { ...postcss$3, postcss: postcss$3, result: this.result };
3063
+ this.plugins = this.processor.plugins.map((plugin3) => {
3064
+ if (typeof plugin3 === "object" && plugin3.prepare) {
3065
+ return { ...plugin3, ...plugin3.prepare(this.result) };
2960
3066
  } else {
2961
- return plugin2;
3067
+ return plugin3;
2962
3068
  }
2963
3069
  });
2964
3070
  }
@@ -2980,17 +3086,17 @@ let LazyResult$2 = class LazyResult {
2980
3086
  throw new Error("Use process(css).then(cb) to work with async plugins");
2981
3087
  }
2982
3088
  handleError(error, node2) {
2983
- let plugin2 = this.result.lastPlugin;
3089
+ let plugin3 = this.result.lastPlugin;
2984
3090
  try {
2985
3091
  if (node2) node2.addToError(error);
2986
3092
  this.error = error;
2987
3093
  if (error.name === "CssSyntaxError" && !error.plugin) {
2988
- error.plugin = plugin2.postcssPlugin;
3094
+ error.plugin = plugin3.postcssPlugin;
2989
3095
  error.setMessage();
2990
- } else if (plugin2.postcssVersion) {
3096
+ } else if (plugin3.postcssVersion) {
2991
3097
  if (process.env.NODE_ENV !== "production") {
2992
- let pluginName = plugin2.postcssPlugin;
2993
- let pluginVer = plugin2.postcssVersion;
3098
+ let pluginName = plugin3.postcssPlugin;
3099
+ let pluginVer = plugin3.postcssVersion;
2994
3100
  let runtimeVer = this.result.processor.version;
2995
3101
  let a = pluginVer.split(".");
2996
3102
  let b = runtimeVer.split(".");
@@ -3008,33 +3114,33 @@ let LazyResult$2 = class LazyResult {
3008
3114
  }
3009
3115
  prepareVisitors() {
3010
3116
  this.listeners = {};
3011
- let add = (plugin2, type, cb) => {
3117
+ let add = (plugin3, type, cb) => {
3012
3118
  if (!this.listeners[type]) this.listeners[type] = [];
3013
- this.listeners[type].push([plugin2, cb]);
3119
+ this.listeners[type].push([plugin3, cb]);
3014
3120
  };
3015
- for (let plugin2 of this.plugins) {
3016
- if (typeof plugin2 === "object") {
3017
- for (let event in plugin2) {
3121
+ for (let plugin3 of this.plugins) {
3122
+ if (typeof plugin3 === "object") {
3123
+ for (let event in plugin3) {
3018
3124
  if (!PLUGIN_PROPS[event] && /^[A-Z]/.test(event)) {
3019
3125
  throw new Error(
3020
- `Unknown event ${event} in ${plugin2.postcssPlugin}. Try to update PostCSS (${this.processor.version} now).`
3126
+ `Unknown event ${event} in ${plugin3.postcssPlugin}. Try to update PostCSS (${this.processor.version} now).`
3021
3127
  );
3022
3128
  }
3023
3129
  if (!NOT_VISITORS[event]) {
3024
- if (typeof plugin2[event] === "object") {
3025
- for (let filter in plugin2[event]) {
3130
+ if (typeof plugin3[event] === "object") {
3131
+ for (let filter in plugin3[event]) {
3026
3132
  if (filter === "*") {
3027
- add(plugin2, event, plugin2[event][filter]);
3133
+ add(plugin3, event, plugin3[event][filter]);
3028
3134
  } else {
3029
3135
  add(
3030
- plugin2,
3136
+ plugin3,
3031
3137
  event + "-" + filter.toLowerCase(),
3032
- plugin2[event][filter]
3138
+ plugin3[event][filter]
3033
3139
  );
3034
3140
  }
3035
3141
  }
3036
- } else if (typeof plugin2[event] === "function") {
3037
- add(plugin2, event, plugin2[event]);
3142
+ } else if (typeof plugin3[event] === "function") {
3143
+ add(plugin3, event, plugin3[event]);
3038
3144
  }
3039
3145
  }
3040
3146
  }
@@ -3045,8 +3151,8 @@ let LazyResult$2 = class LazyResult {
3045
3151
  async runAsync() {
3046
3152
  this.plugin = 0;
3047
3153
  for (let i = 0; i < this.plugins.length; i++) {
3048
- let plugin2 = this.plugins[i];
3049
- let promise = this.runOnRoot(plugin2);
3154
+ let plugin3 = this.plugins[i];
3155
+ let promise = this.runOnRoot(plugin3);
3050
3156
  if (isPromise(promise)) {
3051
3157
  try {
3052
3158
  await promise;
@@ -3074,8 +3180,8 @@ let LazyResult$2 = class LazyResult {
3074
3180
  }
3075
3181
  }
3076
3182
  if (this.listeners.OnceExit) {
3077
- for (let [plugin2, visitor] of this.listeners.OnceExit) {
3078
- this.result.lastPlugin = plugin2;
3183
+ for (let [plugin3, visitor] of this.listeners.OnceExit) {
3184
+ this.result.lastPlugin = plugin3;
3079
3185
  try {
3080
3186
  if (root2.type === "document") {
3081
3187
  let roots = root2.nodes.map(
@@ -3094,22 +3200,22 @@ let LazyResult$2 = class LazyResult {
3094
3200
  this.processed = true;
3095
3201
  return this.stringify();
3096
3202
  }
3097
- runOnRoot(plugin2) {
3098
- this.result.lastPlugin = plugin2;
3203
+ runOnRoot(plugin3) {
3204
+ this.result.lastPlugin = plugin3;
3099
3205
  try {
3100
- if (typeof plugin2 === "object" && plugin2.Once) {
3206
+ if (typeof plugin3 === "object" && plugin3.Once) {
3101
3207
  if (this.result.root.type === "document") {
3102
3208
  let roots = this.result.root.nodes.map(
3103
- (root2) => plugin2.Once(root2, this.helpers)
3209
+ (root2) => plugin3.Once(root2, this.helpers)
3104
3210
  );
3105
3211
  if (isPromise(roots[0])) {
3106
3212
  return Promise.all(roots);
3107
3213
  }
3108
3214
  return roots;
3109
3215
  }
3110
- return plugin2.Once(this.result.root, this.helpers);
3111
- } else if (typeof plugin2 === "function") {
3112
- return plugin2(this.result.root, this.result);
3216
+ return plugin3.Once(this.result.root, this.helpers);
3217
+ } else if (typeof plugin3 === "function") {
3218
+ return plugin3(this.result.root, this.result);
3113
3219
  }
3114
3220
  } catch (error) {
3115
3221
  throw this.handleError(error);
@@ -3121,7 +3227,7 @@ let LazyResult$2 = class LazyResult {
3121
3227
  this.stringified = true;
3122
3228
  this.sync();
3123
3229
  let opts = this.result.opts;
3124
- let str = stringify$2;
3230
+ let str = stringify$3;
3125
3231
  if (opts.syntax) str = opts.syntax.stringify;
3126
3232
  if (opts.stringifier) str = opts.stringifier;
3127
3233
  if (str.stringify) str = str.stringify;
@@ -3138,8 +3244,8 @@ let LazyResult$2 = class LazyResult {
3138
3244
  if (this.processing) {
3139
3245
  throw this.getAsyncError();
3140
3246
  }
3141
- for (let plugin2 of this.plugins) {
3142
- let promise = this.runOnRoot(plugin2);
3247
+ for (let plugin3 of this.plugins) {
3248
+ let promise = this.runOnRoot(plugin3);
3143
3249
  if (isPromise(promise)) {
3144
3250
  throw this.getAsyncError();
3145
3251
  }
@@ -3177,8 +3283,8 @@ let LazyResult$2 = class LazyResult {
3177
3283
  return this.css;
3178
3284
  }
3179
3285
  visitSync(visitors, node2) {
3180
- for (let [plugin2, visitor] of visitors) {
3181
- this.result.lastPlugin = plugin2;
3286
+ for (let [plugin3, visitor] of visitors) {
3287
+ this.result.lastPlugin = plugin3;
3182
3288
  let promise;
3183
3289
  try {
3184
3290
  promise = visitor(node2, this.helpers);
@@ -3201,13 +3307,13 @@ let LazyResult$2 = class LazyResult {
3201
3307
  return;
3202
3308
  }
3203
3309
  if (visitors.length > 0 && visit2.visitorIndex < visitors.length) {
3204
- let [plugin2, visitor] = visitors[visit2.visitorIndex];
3310
+ let [plugin3, visitor] = visitors[visit2.visitorIndex];
3205
3311
  visit2.visitorIndex += 1;
3206
3312
  if (visit2.visitorIndex === visitors.length) {
3207
3313
  visit2.visitors = [];
3208
3314
  visit2.visitorIndex = 0;
3209
3315
  }
3210
- this.result.lastPlugin = plugin2;
3316
+ this.result.lastPlugin = plugin3;
3211
3317
  try {
3212
3318
  return visitor(node2.toProxy(), this.helpers);
3213
3319
  } catch (e) {
@@ -3292,17 +3398,17 @@ let LazyResult$2 = class LazyResult {
3292
3398
  }
3293
3399
  };
3294
3400
  LazyResult$2.registerPostcss = (dependant) => {
3295
- postcss$2 = dependant;
3401
+ postcss$3 = dependant;
3296
3402
  };
3297
3403
  var lazyResult = LazyResult$2;
3298
3404
  LazyResult$2.default = LazyResult$2;
3299
3405
  Root$3.registerLazyResult(LazyResult$2);
3300
- Document$2.registerLazyResult(LazyResult$2);
3406
+ Document$3.registerLazyResult(LazyResult$2);
3301
3407
  let MapGenerator2 = mapGenerator;
3302
- let stringify$1 = stringify_1;
3408
+ let parse$2 = parse_1;
3409
+ const Result$2 = result;
3410
+ let stringify$2 = stringify_1;
3303
3411
  let warnOnce2 = warnOnce$2;
3304
- let parse$1 = parse_1;
3305
- const Result$1 = result;
3306
3412
  let NoWorkResult$1 = class NoWorkResult {
3307
3413
  constructor(processor2, css, opts) {
3308
3414
  css = css.toString();
@@ -3312,8 +3418,8 @@ let NoWorkResult$1 = class NoWorkResult {
3312
3418
  this._opts = opts;
3313
3419
  this._map = void 0;
3314
3420
  let root2;
3315
- let str = stringify$1;
3316
- this.result = new Result$1(this._processor, root2, this._opts);
3421
+ let str = stringify$2;
3422
+ this.result = new Result$2(this._processor, root2, this._opts);
3317
3423
  this.result.css = css;
3318
3424
  let self = this;
3319
3425
  Object.defineProperty(this.result, "root", {
@@ -3388,7 +3494,7 @@ let NoWorkResult$1 = class NoWorkResult {
3388
3494
  return this._root;
3389
3495
  }
3390
3496
  let root2;
3391
- let parser2 = parse$1;
3497
+ let parser2 = parse$2;
3392
3498
  try {
3393
3499
  root2 = parser2(this._css, this._opts);
3394
3500
  } catch (error) {
@@ -3407,13 +3513,13 @@ let NoWorkResult$1 = class NoWorkResult {
3407
3513
  };
3408
3514
  var noWorkResult = NoWorkResult$1;
3409
3515
  NoWorkResult$1.default = NoWorkResult$1;
3410
- let NoWorkResult2 = noWorkResult;
3516
+ let Document$2 = document$2;
3411
3517
  let LazyResult$1 = lazyResult;
3412
- let Document$1 = document$1;
3413
- let Root$2 = root;
3414
- let Processor$1 = class Processor {
3518
+ let NoWorkResult2 = noWorkResult;
3519
+ let Root$2 = root$1;
3520
+ let Processor$2 = class Processor {
3415
3521
  constructor(plugins = []) {
3416
- this.version = "8.4.38";
3522
+ this.version = "8.5.1";
3417
3523
  this.plugins = this.normalize(plugins);
3418
3524
  }
3419
3525
  normalize(plugins) {
@@ -3449,89 +3555,40 @@ let Processor$1 = class Processor {
3449
3555
  return new LazyResult$1(this, css, opts);
3450
3556
  }
3451
3557
  }
3452
- use(plugin2) {
3453
- this.plugins = this.plugins.concat(this.normalize([plugin2]));
3558
+ use(plugin3) {
3559
+ this.plugins = this.plugins.concat(this.normalize([plugin3]));
3454
3560
  return this;
3455
3561
  }
3456
3562
  };
3457
- var processor = Processor$1;
3458
- Processor$1.default = Processor$1;
3459
- Root$2.registerProcessor(Processor$1);
3460
- Document$1.registerProcessor(Processor$1);
3563
+ var processor = Processor$2;
3564
+ Processor$2.default = Processor$2;
3565
+ Root$2.registerProcessor(Processor$2);
3566
+ Document$2.registerProcessor(Processor$2);
3567
+ let AtRule$1 = atRule$1;
3568
+ let Comment$2 = comment$1;
3569
+ let Container$1 = container;
3570
+ let CssSyntaxError$1 = cssSyntaxError;
3461
3571
  let Declaration$1 = declaration;
3462
- let PreviousMap2 = previousMap;
3463
- let Comment$1 = comment;
3464
- let AtRule$1 = atRule;
3465
- let Input$1 = input;
3466
- let Root$1 = root;
3467
- let Rule$1 = rule;
3468
- function fromJSON$1(json, inputs) {
3469
- if (Array.isArray(json)) return json.map((n) => fromJSON$1(n));
3470
- let { inputs: ownInputs, ...defaults } = json;
3471
- if (ownInputs) {
3472
- inputs = [];
3473
- for (let input2 of ownInputs) {
3474
- let inputHydrated = { ...input2, __proto__: Input$1.prototype };
3475
- if (inputHydrated.map) {
3476
- inputHydrated.map = {
3477
- ...inputHydrated.map,
3478
- __proto__: PreviousMap2.prototype
3479
- };
3480
- }
3481
- inputs.push(inputHydrated);
3482
- }
3483
- }
3484
- if (defaults.nodes) {
3485
- defaults.nodes = json.nodes.map((n) => fromJSON$1(n, inputs));
3486
- }
3487
- if (defaults.source) {
3488
- let { inputId, ...source } = defaults.source;
3489
- defaults.source = source;
3490
- if (inputId != null) {
3491
- defaults.source.input = inputs[inputId];
3492
- }
3493
- }
3494
- if (defaults.type === "root") {
3495
- return new Root$1(defaults);
3496
- } else if (defaults.type === "decl") {
3497
- return new Declaration$1(defaults);
3498
- } else if (defaults.type === "rule") {
3499
- return new Rule$1(defaults);
3500
- } else if (defaults.type === "comment") {
3501
- return new Comment$1(defaults);
3502
- } else if (defaults.type === "atrule") {
3503
- return new AtRule$1(defaults);
3504
- } else {
3505
- throw new Error("Unknown node type: " + json.type);
3506
- }
3507
- }
3508
- var fromJSON_1 = fromJSON$1;
3509
- fromJSON$1.default = fromJSON$1;
3510
- let CssSyntaxError2 = cssSyntaxError;
3511
- let Declaration2 = declaration;
3572
+ let Document$1 = document$2;
3573
+ let fromJSON$1 = fromJSON_1;
3574
+ let Input$2 = input;
3512
3575
  let LazyResult2 = lazyResult;
3513
- let Container2 = container;
3514
- let Processor2 = processor;
3515
- let stringify = stringify_1;
3516
- let fromJSON = fromJSON_1;
3517
- let Document22 = document$1;
3518
- let Warning2 = warning;
3519
- let Comment2 = comment;
3520
- let AtRule2 = atRule;
3521
- let Result2 = result;
3522
- let Input2 = input;
3523
- let parse = parse_1;
3524
- let list = list_1;
3525
- let Rule2 = rule;
3526
- let Root2 = root;
3527
- let Node2 = node;
3528
- function postcss(...plugins) {
3576
+ let list$1 = list_1;
3577
+ let Node$1 = node;
3578
+ let parse$1 = parse_1;
3579
+ let Processor$1 = processor;
3580
+ let Result$1 = result;
3581
+ let Root$1 = root$1;
3582
+ let Rule$1 = rule$1;
3583
+ let stringify$1 = stringify_1;
3584
+ let Warning$1 = warning;
3585
+ function postcss$1(...plugins) {
3529
3586
  if (plugins.length === 1 && Array.isArray(plugins[0])) {
3530
3587
  plugins = plugins[0];
3531
3588
  }
3532
- return new Processor2(plugins);
3589
+ return new Processor$1(plugins);
3533
3590
  }
3534
- postcss.plugin = function plugin(name, initializer) {
3591
+ postcss$1.plugin = function plugin(name, initializer) {
3535
3592
  let warningPrinted = false;
3536
3593
  function creator(...args) {
3537
3594
  if (console && console.warn && !warningPrinted) {
@@ -3547,7 +3604,7 @@ postcss.plugin = function plugin(name, initializer) {
3547
3604
  }
3548
3605
  let transformer = initializer(...args);
3549
3606
  transformer.postcssPlugin = name;
3550
- transformer.postcssVersion = new Processor2().version;
3607
+ transformer.postcssVersion = new Processor$1().version;
3551
3608
  return transformer;
3552
3609
  }
3553
3610
  let cache;
@@ -3558,61 +3615,61 @@ postcss.plugin = function plugin(name, initializer) {
3558
3615
  }
3559
3616
  });
3560
3617
  creator.process = function(css, processOpts, pluginOpts) {
3561
- return postcss([creator(pluginOpts)]).process(css, processOpts);
3618
+ return postcss$1([creator(pluginOpts)]).process(css, processOpts);
3562
3619
  };
3563
3620
  return creator;
3564
3621
  };
3565
- postcss.stringify = stringify;
3566
- postcss.parse = parse;
3567
- postcss.fromJSON = fromJSON;
3568
- postcss.list = list;
3569
- postcss.comment = (defaults) => new Comment2(defaults);
3570
- postcss.atRule = (defaults) => new AtRule2(defaults);
3571
- postcss.decl = (defaults) => new Declaration2(defaults);
3572
- postcss.rule = (defaults) => new Rule2(defaults);
3573
- postcss.root = (defaults) => new Root2(defaults);
3574
- postcss.document = (defaults) => new Document22(defaults);
3575
- postcss.CssSyntaxError = CssSyntaxError2;
3576
- postcss.Declaration = Declaration2;
3577
- postcss.Container = Container2;
3578
- postcss.Processor = Processor2;
3579
- postcss.Document = Document22;
3580
- postcss.Comment = Comment2;
3581
- postcss.Warning = Warning2;
3582
- postcss.AtRule = AtRule2;
3583
- postcss.Result = Result2;
3584
- postcss.Input = Input2;
3585
- postcss.Rule = Rule2;
3586
- postcss.Root = Root2;
3587
- postcss.Node = Node2;
3588
- LazyResult2.registerPostcss(postcss);
3589
- var postcss_1 = postcss;
3590
- postcss.default = postcss;
3591
- const postcss$1 = /* @__PURE__ */ getDefaultExportFromCjs(postcss_1);
3592
- postcss$1.stringify;
3593
- postcss$1.fromJSON;
3594
- postcss$1.plugin;
3595
- postcss$1.parse;
3596
- postcss$1.list;
3597
- postcss$1.document;
3598
- postcss$1.comment;
3599
- postcss$1.atRule;
3600
- postcss$1.rule;
3601
- postcss$1.decl;
3602
- postcss$1.root;
3603
- postcss$1.CssSyntaxError;
3604
- postcss$1.Declaration;
3605
- postcss$1.Container;
3606
- postcss$1.Processor;
3607
- postcss$1.Document;
3608
- postcss$1.Comment;
3609
- postcss$1.Warning;
3610
- postcss$1.AtRule;
3611
- postcss$1.Result;
3612
- postcss$1.Input;
3613
- postcss$1.Rule;
3614
- postcss$1.Root;
3615
- postcss$1.Node;
3622
+ postcss$1.stringify = stringify$1;
3623
+ postcss$1.parse = parse$1;
3624
+ postcss$1.fromJSON = fromJSON$1;
3625
+ postcss$1.list = list$1;
3626
+ postcss$1.comment = (defaults) => new Comment$2(defaults);
3627
+ postcss$1.atRule = (defaults) => new AtRule$1(defaults);
3628
+ postcss$1.decl = (defaults) => new Declaration$1(defaults);
3629
+ postcss$1.rule = (defaults) => new Rule$1(defaults);
3630
+ postcss$1.root = (defaults) => new Root$1(defaults);
3631
+ postcss$1.document = (defaults) => new Document$1(defaults);
3632
+ postcss$1.CssSyntaxError = CssSyntaxError$1;
3633
+ postcss$1.Declaration = Declaration$1;
3634
+ postcss$1.Container = Container$1;
3635
+ postcss$1.Processor = Processor$1;
3636
+ postcss$1.Document = Document$1;
3637
+ postcss$1.Comment = Comment$2;
3638
+ postcss$1.Warning = Warning$1;
3639
+ postcss$1.AtRule = AtRule$1;
3640
+ postcss$1.Result = Result$1;
3641
+ postcss$1.Input = Input$2;
3642
+ postcss$1.Rule = Rule$1;
3643
+ postcss$1.Root = Root$1;
3644
+ postcss$1.Node = Node$1;
3645
+ LazyResult2.registerPostcss(postcss$1);
3646
+ var postcss_1 = postcss$1;
3647
+ postcss$1.default = postcss$1;
3648
+ const postcss$2 = /* @__PURE__ */ getDefaultExportFromCjs(postcss_1);
3649
+ postcss$2.stringify;
3650
+ postcss$2.fromJSON;
3651
+ postcss$2.plugin;
3652
+ postcss$2.parse;
3653
+ postcss$2.list;
3654
+ postcss$2.document;
3655
+ postcss$2.comment;
3656
+ postcss$2.atRule;
3657
+ postcss$2.rule;
3658
+ postcss$2.decl;
3659
+ postcss$2.root;
3660
+ postcss$2.CssSyntaxError;
3661
+ postcss$2.Declaration;
3662
+ postcss$2.Container;
3663
+ postcss$2.Processor;
3664
+ postcss$2.Document;
3665
+ postcss$2.Comment;
3666
+ postcss$2.Warning;
3667
+ postcss$2.AtRule;
3668
+ postcss$2.Result;
3669
+ postcss$2.Input;
3670
+ postcss$2.Rule;
3671
+ postcss$2.Root;
3672
+ postcss$2.Node;
3616
3673
  var NodeType$1 = /* @__PURE__ */ ((NodeType2) => {
3617
3674
  NodeType2[NodeType2["Document"] = 0] = "Document";
3618
3675
  NodeType2[NodeType2["DocumentType"] = 1] = "DocumentType";
@@ -3626,8 +3683,8 @@ function parseCSSText(cssText) {
3626
3683
  const res = {};
3627
3684
  const listDelimiter = /;(?![^(]*\))/g;
3628
3685
  const propertyDelimiter = /:(.+)/;
3629
- const comment2 = /\/\*.*?\*\//g;
3630
- cssText.replace(comment2, "").split(listDelimiter).forEach(function(item) {
3686
+ const comment = /\/\*.*?\*\//g;
3687
+ cssText.replace(comment, "").split(listDelimiter).forEach(function(item) {
3631
3688
  if (item) {
3632
3689
  const tmp = item.split(propertyDelimiter);
3633
3690
  tmp.length > 1 && (res[camelize(tmp[0].trim())] = tmp[1].trim());
@@ -3822,9 +3879,9 @@ class BaseRRDocument extends BaseRRNode {
3822
3879
  return text;
3823
3880
  }
3824
3881
  createComment(data) {
3825
- const comment2 = new BaseRRComment(data);
3826
- comment2.ownerDocument = this;
3827
- return comment2;
3882
+ const comment = new BaseRRComment(data);
3883
+ comment.ownerDocument = this;
3884
+ return comment;
3828
3885
  }
3829
3886
  createCDATASection(data) {
3830
3887
  const CDATASection = new BaseRRCDATASection(data);