@glimt/record 0.0.10 → 0.0.12

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.
@@ -2107,7 +2107,7 @@ let Node$4$1 = class Node2 {
2107
2107
  let index2 = this.parent.index(this);
2108
2108
  return this.parent.nodes[index2 + 1];
2109
2109
  }
2110
- positionBy(opts) {
2110
+ positionBy(opts = {}) {
2111
2111
  let pos = this.source.start;
2112
2112
  if (opts.index) {
2113
2113
  pos = this.positionInside(opts.index);
@@ -2136,27 +2136,38 @@ let Node$4$1 = class Node2 {
2136
2136
  column += 1;
2137
2137
  }
2138
2138
  }
2139
- return { column, line };
2139
+ return { column, line, offset: end };
2140
2140
  }
2141
2141
  prev() {
2142
2142
  if (!this.parent) return void 0;
2143
2143
  let index2 = this.parent.index(this);
2144
2144
  return this.parent.nodes[index2 - 1];
2145
2145
  }
2146
- rangeBy(opts) {
2146
+ rangeBy(opts = {}) {
2147
+ let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
2147
2148
  let start = {
2148
2149
  column: this.source.start.column,
2149
- line: this.source.start.line
2150
+ line: this.source.start.line,
2151
+ offset: sourceOffset$1(inputString, this.source.start)
2150
2152
  };
2151
2153
  let end = this.source.end ? {
2152
2154
  column: this.source.end.column + 1,
2153
- line: this.source.end.line
2155
+ line: this.source.end.line,
2156
+ offset: typeof this.source.end.offset === "number" ? (
2157
+ // `source.end.offset` is exclusive, so we don't need to add 1
2158
+ this.source.end.offset
2159
+ ) : (
2160
+ // Since line/column in this.source.end is inclusive,
2161
+ // the `sourceOffset(... , this.source.end)` returns an inclusive offset.
2162
+ // So, we add 1 to convert it to exclusive.
2163
+ sourceOffset$1(inputString, this.source.end) + 1
2164
+ )
2154
2165
  } : {
2155
2166
  column: start.column + 1,
2156
- line: start.line
2167
+ line: start.line,
2168
+ offset: start.offset + 1
2157
2169
  };
2158
2170
  if (opts.word) {
2159
- let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
2160
2171
  let stringRepresentation = inputString.slice(
2161
2172
  sourceOffset$1(inputString, this.source.start),
2162
2173
  sourceOffset$1(inputString, this.source.end)
@@ -2164,15 +2175,14 @@ let Node$4$1 = class Node2 {
2164
2175
  let index2 = stringRepresentation.indexOf(opts.word);
2165
2176
  if (index2 !== -1) {
2166
2177
  start = this.positionInside(index2);
2167
- end = this.positionInside(
2168
- index2 + opts.word.length
2169
- );
2178
+ end = this.positionInside(index2 + opts.word.length);
2170
2179
  }
2171
2180
  } else {
2172
2181
  if (opts.start) {
2173
2182
  start = {
2174
2183
  column: opts.start.column,
2175
- line: opts.start.line
2184
+ line: opts.start.line,
2185
+ offset: sourceOffset$1(inputString, opts.start)
2176
2186
  };
2177
2187
  } else if (opts.index) {
2178
2188
  start = this.positionInside(opts.index);
@@ -2180,7 +2190,8 @@ let Node$4$1 = class Node2 {
2180
2190
  if (opts.end) {
2181
2191
  end = {
2182
2192
  column: opts.end.column,
2183
- line: opts.end.line
2193
+ line: opts.end.line,
2194
+ offset: sourceOffset$1(inputString, opts.end)
2184
2195
  };
2185
2196
  } else if (typeof opts.endIndex === "number") {
2186
2197
  end = this.positionInside(opts.endIndex);
@@ -2189,7 +2200,11 @@ let Node$4$1 = class Node2 {
2189
2200
  }
2190
2201
  }
2191
2202
  if (end.line < start.line || end.line === start.line && end.column <= start.column) {
2192
- end = { column: start.column + 1, line: start.line };
2203
+ end = {
2204
+ column: start.column + 1,
2205
+ line: start.line,
2206
+ offset: start.offset + 1
2207
+ };
2193
2208
  }
2194
2209
  return { end, start };
2195
2210
  }
@@ -2253,6 +2268,7 @@ let Node$4$1 = class Node2 {
2253
2268
  } else if (typeof value === "object" && value.toJSON) {
2254
2269
  fixed[name] = value.toJSON(null, inputs);
2255
2270
  } else if (name === "source") {
2271
+ if (value == null) continue;
2256
2272
  let inputId = inputs.get(value.input);
2257
2273
  if (inputId == null) {
2258
2274
  inputId = inputsNextIndex;
@@ -2287,7 +2303,7 @@ let Node$4$1 = class Node2 {
2287
2303
  });
2288
2304
  return result2;
2289
2305
  }
2290
- warn(result2, text, opts) {
2306
+ warn(result2, text, opts = {}) {
2291
2307
  let data = { node: this };
2292
2308
  for (let i2 in opts) data[i2] = opts[i2];
2293
2309
  return result2.warn(text, data);
@@ -2868,9 +2884,21 @@ let { fileURLToPath: fileURLToPath$1, pathToFileURL: pathToFileURL$1$1 } = requi
2868
2884
  let CssSyntaxError$1$1 = cssSyntaxError$1;
2869
2885
  let PreviousMap$1$1 = previousMap$1;
2870
2886
  let terminalHighlight$2 = require$$2$1;
2871
- let fromOffsetCache$1 = Symbol("fromOffsetCache");
2887
+ let lineToIndexCache$1 = Symbol("lineToIndexCache");
2872
2888
  let sourceMapAvailable$1$1 = Boolean(SourceMapConsumer$1$1 && SourceMapGenerator$1$1);
2873
2889
  let pathAvailable$1$1 = Boolean(resolve$1$1 && isAbsolute$1);
2890
+ function getLineToIndex$1(input2) {
2891
+ if (input2[lineToIndexCache$1]) return input2[lineToIndexCache$1];
2892
+ let lines = input2.css.split("\n");
2893
+ let lineToIndex = new Array(lines.length);
2894
+ let prevIndex = 0;
2895
+ for (let i2 = 0, l2 = lines.length; i2 < l2; i2++) {
2896
+ lineToIndex[i2] = prevIndex;
2897
+ prevIndex += lines[i2].length + 1;
2898
+ }
2899
+ input2[lineToIndexCache$1] = lineToIndex;
2900
+ return lineToIndex;
2901
+ }
2874
2902
  let Input$4$1 = class Input {
2875
2903
  get from() {
2876
2904
  return this.file || this.id;
@@ -2909,30 +2937,37 @@ let Input$4$1 = class Input {
2909
2937
  if (this.map) this.map.file = this.from;
2910
2938
  }
2911
2939
  error(message, line, column, opts = {}) {
2912
- let endColumn, endLine, result2;
2940
+ let endColumn, endLine, endOffset, offset, result2;
2913
2941
  if (line && typeof line === "object") {
2914
2942
  let start = line;
2915
2943
  let end = column;
2916
2944
  if (typeof start.offset === "number") {
2917
- let pos = this.fromOffset(start.offset);
2945
+ offset = start.offset;
2946
+ let pos = this.fromOffset(offset);
2918
2947
  line = pos.line;
2919
2948
  column = pos.col;
2920
2949
  } else {
2921
2950
  line = start.line;
2922
2951
  column = start.column;
2952
+ offset = this.fromLineAndColumn(line, column);
2923
2953
  }
2924
2954
  if (typeof end.offset === "number") {
2925
- let pos = this.fromOffset(end.offset);
2955
+ endOffset = end.offset;
2956
+ let pos = this.fromOffset(endOffset);
2926
2957
  endLine = pos.line;
2927
2958
  endColumn = pos.col;
2928
2959
  } else {
2929
2960
  endLine = end.line;
2930
2961
  endColumn = end.column;
2962
+ endOffset = this.fromLineAndColumn(end.line, end.column);
2931
2963
  }
2932
2964
  } else if (!column) {
2933
- let pos = this.fromOffset(line);
2965
+ offset = line;
2966
+ let pos = this.fromOffset(offset);
2934
2967
  line = pos.line;
2935
2968
  column = pos.col;
2969
+ } else {
2970
+ offset = this.fromLineAndColumn(line, column);
2936
2971
  }
2937
2972
  let origin = this.origin(line, column, endLine, endColumn);
2938
2973
  if (origin) {
@@ -2954,7 +2989,7 @@ let Input$4$1 = class Input {
2954
2989
  opts.plugin
2955
2990
  );
2956
2991
  }
2957
- result2.input = { column, endColumn, endLine, line, source: this.css };
2992
+ result2.input = { column, endColumn, endLine, endOffset, line, offset, source: this.css };
2958
2993
  if (this.file) {
2959
2994
  if (pathToFileURL$1$1) {
2960
2995
  result2.input.url = pathToFileURL$1$1(this.file).toString();
@@ -2963,21 +2998,14 @@ let Input$4$1 = class Input {
2963
2998
  }
2964
2999
  return result2;
2965
3000
  }
3001
+ fromLineAndColumn(line, column) {
3002
+ let lineToIndex = getLineToIndex$1(this);
3003
+ let index2 = lineToIndex[line - 1];
3004
+ return index2 + column - 1;
3005
+ }
2966
3006
  fromOffset(offset) {
2967
- let lastLine, lineToIndex;
2968
- if (!this[fromOffsetCache$1]) {
2969
- let lines = this.css.split("\n");
2970
- lineToIndex = new Array(lines.length);
2971
- let prevIndex = 0;
2972
- for (let i2 = 0, l2 = lines.length; i2 < l2; i2++) {
2973
- lineToIndex[i2] = prevIndex;
2974
- prevIndex += lines[i2].length + 1;
2975
- }
2976
- this[fromOffsetCache$1] = lineToIndex;
2977
- } else {
2978
- lineToIndex = this[fromOffsetCache$1];
2979
- }
2980
- lastLine = lineToIndex[lineToIndex.length - 1];
3007
+ let lineToIndex = getLineToIndex$1(this);
3008
+ let lastLine = lineToIndex[lineToIndex.length - 1];
2981
3009
  let min = 0;
2982
3010
  if (offset >= lastLine) {
2983
3011
  min = lineToIndex.length - 1;
@@ -4339,7 +4367,7 @@ let Result$3$1 = class Result {
4339
4367
  this.messages = [];
4340
4368
  this.root = root2;
4341
4369
  this.opts = opts;
4342
- this.css = void 0;
4370
+ this.css = "";
4343
4371
  this.map = void 0;
4344
4372
  }
4345
4373
  toString() {
@@ -4951,7 +4979,7 @@ let NoWorkResult2$1 = noWorkResult$1;
4951
4979
  let Root$1$1 = root$1;
4952
4980
  let Processor$1$1 = class Processor {
4953
4981
  constructor(plugins = []) {
4954
- this.version = "8.5.3";
4982
+ this.version = "8.5.4";
4955
4983
  this.plugins = this.normalize(plugins);
4956
4984
  }
4957
4985
  normalize(plugins) {
@@ -5712,7 +5740,7 @@ let Node$4 = class Node3 {
5712
5740
  let index2 = this.parent.index(this);
5713
5741
  return this.parent.nodes[index2 + 1];
5714
5742
  }
5715
- positionBy(opts) {
5743
+ positionBy(opts = {}) {
5716
5744
  let pos = this.source.start;
5717
5745
  if (opts.index) {
5718
5746
  pos = this.positionInside(opts.index);
@@ -5741,27 +5769,38 @@ let Node$4 = class Node3 {
5741
5769
  column += 1;
5742
5770
  }
5743
5771
  }
5744
- return { column, line };
5772
+ return { column, line, offset: end };
5745
5773
  }
5746
5774
  prev() {
5747
5775
  if (!this.parent) return void 0;
5748
5776
  let index2 = this.parent.index(this);
5749
5777
  return this.parent.nodes[index2 - 1];
5750
5778
  }
5751
- rangeBy(opts) {
5779
+ rangeBy(opts = {}) {
5780
+ let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
5752
5781
  let start = {
5753
5782
  column: this.source.start.column,
5754
- line: this.source.start.line
5783
+ line: this.source.start.line,
5784
+ offset: sourceOffset(inputString, this.source.start)
5755
5785
  };
5756
5786
  let end = this.source.end ? {
5757
5787
  column: this.source.end.column + 1,
5758
- line: this.source.end.line
5788
+ line: this.source.end.line,
5789
+ offset: typeof this.source.end.offset === "number" ? (
5790
+ // `source.end.offset` is exclusive, so we don't need to add 1
5791
+ this.source.end.offset
5792
+ ) : (
5793
+ // Since line/column in this.source.end is inclusive,
5794
+ // the `sourceOffset(... , this.source.end)` returns an inclusive offset.
5795
+ // So, we add 1 to convert it to exclusive.
5796
+ sourceOffset(inputString, this.source.end) + 1
5797
+ )
5759
5798
  } : {
5760
5799
  column: start.column + 1,
5761
- line: start.line
5800
+ line: start.line,
5801
+ offset: start.offset + 1
5762
5802
  };
5763
5803
  if (opts.word) {
5764
- let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
5765
5804
  let stringRepresentation = inputString.slice(
5766
5805
  sourceOffset(inputString, this.source.start),
5767
5806
  sourceOffset(inputString, this.source.end)
@@ -5769,15 +5808,14 @@ let Node$4 = class Node3 {
5769
5808
  let index2 = stringRepresentation.indexOf(opts.word);
5770
5809
  if (index2 !== -1) {
5771
5810
  start = this.positionInside(index2);
5772
- end = this.positionInside(
5773
- index2 + opts.word.length
5774
- );
5811
+ end = this.positionInside(index2 + opts.word.length);
5775
5812
  }
5776
5813
  } else {
5777
5814
  if (opts.start) {
5778
5815
  start = {
5779
5816
  column: opts.start.column,
5780
- line: opts.start.line
5817
+ line: opts.start.line,
5818
+ offset: sourceOffset(inputString, opts.start)
5781
5819
  };
5782
5820
  } else if (opts.index) {
5783
5821
  start = this.positionInside(opts.index);
@@ -5785,7 +5823,8 @@ let Node$4 = class Node3 {
5785
5823
  if (opts.end) {
5786
5824
  end = {
5787
5825
  column: opts.end.column,
5788
- line: opts.end.line
5826
+ line: opts.end.line,
5827
+ offset: sourceOffset(inputString, opts.end)
5789
5828
  };
5790
5829
  } else if (typeof opts.endIndex === "number") {
5791
5830
  end = this.positionInside(opts.endIndex);
@@ -5794,7 +5833,11 @@ let Node$4 = class Node3 {
5794
5833
  }
5795
5834
  }
5796
5835
  if (end.line < start.line || end.line === start.line && end.column <= start.column) {
5797
- end = { column: start.column + 1, line: start.line };
5836
+ end = {
5837
+ column: start.column + 1,
5838
+ line: start.line,
5839
+ offset: start.offset + 1
5840
+ };
5798
5841
  }
5799
5842
  return { end, start };
5800
5843
  }
@@ -5858,6 +5901,7 @@ let Node$4 = class Node3 {
5858
5901
  } else if (typeof value === "object" && value.toJSON) {
5859
5902
  fixed[name] = value.toJSON(null, inputs);
5860
5903
  } else if (name === "source") {
5904
+ if (value == null) continue;
5861
5905
  let inputId = inputs.get(value.input);
5862
5906
  if (inputId == null) {
5863
5907
  inputId = inputsNextIndex;
@@ -5892,7 +5936,7 @@ let Node$4 = class Node3 {
5892
5936
  });
5893
5937
  return result2;
5894
5938
  }
5895
- warn(result2, text, opts) {
5939
+ warn(result2, text, opts = {}) {
5896
5940
  let data = { node: this };
5897
5941
  for (let i2 in opts) data[i2] = opts[i2];
5898
5942
  return result2.warn(text, data);
@@ -6473,9 +6517,21 @@ let { fileURLToPath, pathToFileURL: pathToFileURL$1 } = require$$2;
6473
6517
  let CssSyntaxError$1 = cssSyntaxError;
6474
6518
  let PreviousMap$1 = previousMap;
6475
6519
  let terminalHighlight = require$$2;
6476
- let fromOffsetCache = Symbol("fromOffsetCache");
6520
+ let lineToIndexCache = Symbol("lineToIndexCache");
6477
6521
  let sourceMapAvailable$1 = Boolean(SourceMapConsumer$1 && SourceMapGenerator$1);
6478
6522
  let pathAvailable$1 = Boolean(resolve$1 && isAbsolute);
6523
+ function getLineToIndex(input2) {
6524
+ if (input2[lineToIndexCache]) return input2[lineToIndexCache];
6525
+ let lines = input2.css.split("\n");
6526
+ let lineToIndex = new Array(lines.length);
6527
+ let prevIndex = 0;
6528
+ for (let i2 = 0, l2 = lines.length; i2 < l2; i2++) {
6529
+ lineToIndex[i2] = prevIndex;
6530
+ prevIndex += lines[i2].length + 1;
6531
+ }
6532
+ input2[lineToIndexCache] = lineToIndex;
6533
+ return lineToIndex;
6534
+ }
6479
6535
  let Input$4 = class Input2 {
6480
6536
  get from() {
6481
6537
  return this.file || this.id;
@@ -6514,30 +6570,37 @@ let Input$4 = class Input2 {
6514
6570
  if (this.map) this.map.file = this.from;
6515
6571
  }
6516
6572
  error(message, line, column, opts = {}) {
6517
- let endColumn, endLine, result2;
6573
+ let endColumn, endLine, endOffset, offset, result2;
6518
6574
  if (line && typeof line === "object") {
6519
6575
  let start = line;
6520
6576
  let end = column;
6521
6577
  if (typeof start.offset === "number") {
6522
- let pos = this.fromOffset(start.offset);
6578
+ offset = start.offset;
6579
+ let pos = this.fromOffset(offset);
6523
6580
  line = pos.line;
6524
6581
  column = pos.col;
6525
6582
  } else {
6526
6583
  line = start.line;
6527
6584
  column = start.column;
6585
+ offset = this.fromLineAndColumn(line, column);
6528
6586
  }
6529
6587
  if (typeof end.offset === "number") {
6530
- let pos = this.fromOffset(end.offset);
6588
+ endOffset = end.offset;
6589
+ let pos = this.fromOffset(endOffset);
6531
6590
  endLine = pos.line;
6532
6591
  endColumn = pos.col;
6533
6592
  } else {
6534
6593
  endLine = end.line;
6535
6594
  endColumn = end.column;
6595
+ endOffset = this.fromLineAndColumn(end.line, end.column);
6536
6596
  }
6537
6597
  } else if (!column) {
6538
- let pos = this.fromOffset(line);
6598
+ offset = line;
6599
+ let pos = this.fromOffset(offset);
6539
6600
  line = pos.line;
6540
6601
  column = pos.col;
6602
+ } else {
6603
+ offset = this.fromLineAndColumn(line, column);
6541
6604
  }
6542
6605
  let origin = this.origin(line, column, endLine, endColumn);
6543
6606
  if (origin) {
@@ -6559,7 +6622,7 @@ let Input$4 = class Input2 {
6559
6622
  opts.plugin
6560
6623
  );
6561
6624
  }
6562
- result2.input = { column, endColumn, endLine, line, source: this.css };
6625
+ result2.input = { column, endColumn, endLine, endOffset, line, offset, source: this.css };
6563
6626
  if (this.file) {
6564
6627
  if (pathToFileURL$1) {
6565
6628
  result2.input.url = pathToFileURL$1(this.file).toString();
@@ -6568,21 +6631,14 @@ let Input$4 = class Input2 {
6568
6631
  }
6569
6632
  return result2;
6570
6633
  }
6634
+ fromLineAndColumn(line, column) {
6635
+ let lineToIndex = getLineToIndex(this);
6636
+ let index2 = lineToIndex[line - 1];
6637
+ return index2 + column - 1;
6638
+ }
6571
6639
  fromOffset(offset) {
6572
- let lastLine, lineToIndex;
6573
- if (!this[fromOffsetCache]) {
6574
- let lines = this.css.split("\n");
6575
- lineToIndex = new Array(lines.length);
6576
- let prevIndex = 0;
6577
- for (let i2 = 0, l2 = lines.length; i2 < l2; i2++) {
6578
- lineToIndex[i2] = prevIndex;
6579
- prevIndex += lines[i2].length + 1;
6580
- }
6581
- this[fromOffsetCache] = lineToIndex;
6582
- } else {
6583
- lineToIndex = this[fromOffsetCache];
6584
- }
6585
- lastLine = lineToIndex[lineToIndex.length - 1];
6640
+ let lineToIndex = getLineToIndex(this);
6641
+ let lastLine = lineToIndex[lineToIndex.length - 1];
6586
6642
  let min = 0;
6587
6643
  if (offset >= lastLine) {
6588
6644
  min = lineToIndex.length - 1;
@@ -7944,7 +8000,7 @@ let Result$3 = class Result2 {
7944
8000
  this.messages = [];
7945
8001
  this.root = root2;
7946
8002
  this.opts = opts;
7947
- this.css = void 0;
8003
+ this.css = "";
7948
8004
  this.map = void 0;
7949
8005
  }
7950
8006
  toString() {
@@ -8556,7 +8612,7 @@ let NoWorkResult22 = noWorkResult;
8556
8612
  let Root$1 = root;
8557
8613
  let Processor$1 = class Processor2 {
8558
8614
  constructor(plugins = []) {
8559
- this.version = "8.5.3";
8615
+ this.version = "8.5.4";
8560
8616
  this.plugins = this.normalize(plugins);
8561
8617
  }
8562
8618
  normalize(plugins) {