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