@tbela99/css-parser 1.6.0 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/CHANGELOG.md +118 -2
  2. package/README.md +4 -3
  3. package/dist/index-umd-web.js +1629 -467
  4. package/dist/index.cjs +1629 -467
  5. package/dist/index.d.ts +72 -7
  6. package/dist/lib/ast/features/prefix.js +9 -1
  7. package/dist/lib/ast/features/shorthand.js +1 -1
  8. package/dist/lib/ast/features/transform.js +1 -1
  9. package/dist/lib/ast/math/expression.js +175 -5
  10. package/dist/lib/ast/minify.js +84 -10
  11. package/dist/lib/ast/transform/compute.js +24 -55
  12. package/dist/lib/ast/transform/minify.js +1 -1
  13. package/dist/lib/ast/types.js +12 -0
  14. package/dist/{config.json.js → lib/data/properties.json.js} +106 -0
  15. package/dist/lib/{validation/config.json.js → data/validation.json.js} +11 -8
  16. package/dist/lib/parser/declaration/list.js +8 -10
  17. package/dist/lib/parser/parse.js +8 -14
  18. package/dist/lib/parser/tokenize.js +89 -58
  19. package/dist/lib/parser/utils/at-rule-font-feature-values.js +1 -1
  20. package/dist/lib/parser/utils/at-rule-media.js +66 -0
  21. package/dist/lib/parser/utils/at-rule-when-else.js +2 -2
  22. package/dist/lib/parser/utils/base64.js +14 -0
  23. package/dist/lib/parser/utils/config.js +1 -1
  24. package/dist/lib/parser/utils/declaration.js +18 -17
  25. package/dist/lib/parser/utils/eq.js +6 -0
  26. package/dist/lib/parser/utils/hash.js +1 -0
  27. package/dist/lib/parser/utils/selector.js +99 -89
  28. package/dist/lib/parser/utils/text.js +16 -0
  29. package/dist/lib/renderer/render.js +20 -6
  30. package/dist/lib/renderer/sourcemap/lib/codec.js +8 -3
  31. package/dist/lib/renderer/sourcemap/sourcemap.js +35 -5
  32. package/dist/lib/syntax/color/alpha.js +57 -22
  33. package/dist/lib/syntax/color/cmyk.js +4 -3
  34. package/dist/lib/syntax/color/color-mix.js +18 -18
  35. package/dist/lib/syntax/color/srgb.js +11 -5
  36. package/dist/lib/syntax/color/utils/components.js +1 -1
  37. package/dist/lib/syntax/color/utils/distance.js +2 -2
  38. package/dist/lib/syntax/color/utils/matrix.js +1 -0
  39. package/dist/lib/syntax/color/xyz.js +5 -0
  40. package/dist/lib/syntax/color/xyzd50.js +17 -0
  41. package/dist/lib/syntax/constants.js +1 -1
  42. package/dist/lib/syntax/syntax.js +549 -13
  43. package/dist/lib/validation/config.js +27 -1
  44. package/dist/lib/validation/match.js +16 -4
  45. package/dist/lib/validation/parser/parse.js +7 -3
  46. package/dist/node.js +8 -14
  47. package/dist/web.js +8 -14
  48. package/package.json +4 -4
@@ -10,7 +10,7 @@ function matchAtRuleWhenElseSyntax(stream, context, options = {}) {
10
10
  let i = 0;
11
11
  let success = true;
12
12
  let expectAndOr = false;
13
- let scope = new Set();
13
+ // let scope: Set<EnumToken> = new Set();
14
14
  const errors = [];
15
15
  // const scopes: Array<Set<EnumToken>> = [scope];
16
16
  for (; i < stream.length; i++) {
@@ -32,7 +32,7 @@ function matchAtRuleWhenElseSyntax(stream, context, options = {}) {
32
32
  Object.assign(stream[i], {
33
33
  typ: "or" === val ? EnumToken.OrTokenType : EnumToken.AndTokenType,
34
34
  });
35
- scope.add(stream[i].typ);
35
+ // scope.add(stream[i].typ);
36
36
  stack.push(stream[i]);
37
37
  // break;
38
38
  }
@@ -0,0 +1,14 @@
1
+ /**
2
+ *
3
+ * @param value
4
+ * @returns
5
+ */
6
+ function toBase64(value) {
7
+ let result = '';
8
+ for (const c of new TextEncoder().encode(value)) {
9
+ result += String.fromCharCode(c);
10
+ }
11
+ return btoa(result);
12
+ }
13
+
14
+ export { toBase64 };
@@ -1,4 +1,4 @@
1
- import config from '../../../config.json.js';
1
+ import config from '../../data/properties.json.js';
2
2
 
3
3
  Object.freeze(config);
4
4
  // @ts-expect-error
@@ -1,4 +1,4 @@
1
- import { EnumToken, EnumAstNodeStatus, ColorType, ValidationLevel } from '../../ast/types.js';
1
+ import { EnumToken, EnumAstNodeStatus, ColorType } from '../../ast/types.js';
2
2
  import { LOCEND, STATE, ERRORS, LOCSTA, tokensfuncDefMap, COLORS_NAMES, nonStandardColors, systemColors, deprecatedSystemColors, tokensMap, trimTokenSpace, LOCSRCID } from '../../syntax/constants.js';
3
3
  import { renamedStandardProperties, isColor, parseColor, isWhiteSpace } from '../../syntax/syntax.js';
4
4
  import { getSyntaxRule, getParsedSyntax } from '../../validation/config.js';
@@ -50,7 +50,6 @@ function parseGridTemplate(template) {
50
50
  * @param errors
51
51
  */
52
52
  function parseDeclaration(tokens, parent, options, errors) {
53
- // console.error(tokens);
54
53
  const name = tokens.shift();
55
54
  let i;
56
55
  let rules = null;
@@ -165,7 +164,7 @@ function parseDeclaration(tokens, parent, options, errors) {
165
164
  let token;
166
165
  let index;
167
166
  if (syntaxRules != null) {
168
- const doNotValidate = options.validation === false || options.validation === ValidationLevel.None;
167
+ const doNotValidate = options.validation === false;
169
168
  result = doNotValidate ? null : matchAllSyntaxes(syntaxRules, createValidationContext(tokens), options);
170
169
  if (doNotValidate || result != null) {
171
170
  success = doNotValidate || result?.success;
@@ -196,17 +195,11 @@ function parseDeclaration(tokens, parent, options, errors) {
196
195
  stack.push(token);
197
196
  continue;
198
197
  }
198
+ if (token.typ === EnumToken.ColonTokenType && stack.length == 0) {
199
+ stack.push(token);
200
+ continue;
201
+ }
199
202
  switch (token.typ) {
200
- // case EnumToken.IdenTokenType:
201
- // if (tokens[i + 1]?.typ == EnumToken.StartParensTokenType) {
202
- // Object.assign(token, {
203
- // typ: EnumToken.FunctionTokenDefType,
204
- // });
205
- // token[LOCEND] = tokens[i + 1][LOCEND];
206
- // tokens.splice(i + 1, 1);
207
- // stack.push(token);
208
- // }
209
- // break;
210
203
  case EnumToken.Literal:
211
204
  if (token.val === "/" && stack.at(-1)?.typ == EnumToken.MathFunctionTokenDefType) {
212
205
  Object.assign(token, {
@@ -384,10 +377,19 @@ function parseDeclaration(tokens, parent, options, errors) {
384
377
  }
385
378
  if (trimTokenSpace.has(token.typ)) {
386
379
  if (tokens[i + 1]?.typ === EnumToken.WhitespaceTokenType) {
387
- tokens.splice(i + 1, 1);
380
+ for (let index = i + 1; index < tokens.length - 1; index++) {
381
+ tokens[index] = tokens[index + 1];
382
+ }
383
+ tokens.length--;
384
+ i--;
385
+ continue;
388
386
  }
389
387
  if (tokens[i - 1]?.typ == EnumToken.WhitespaceTokenType) {
390
- tokens.splice(--i, 1);
388
+ for (let index = i - 1; index < tokens.length - 1; index++) {
389
+ tokens[index] = tokens[index + 1];
390
+ }
391
+ tokens.length--;
392
+ i--;
391
393
  }
392
394
  }
393
395
  }
@@ -439,12 +441,11 @@ function parseDeclaration(tokens, parent, options, errors) {
439
441
  name[STATE] = EnumAstNodeStatus.Unknown;
440
442
  name[ERRORS] = result?.errors ?? [];
441
443
  // @ts-expect-error
442
- const node = Object.assign(name, {
444
+ return Object.assign(name, {
443
445
  typ: EnumToken.DeclarationNodeType,
444
446
  nam: name.val,
445
447
  val: tokens,
446
448
  });
447
- return node;
448
449
  }
449
450
  if (equalsIgnoreCase("composes", name.val)) {
450
451
  let index = -1;
@@ -1,3 +1,9 @@
1
+ /**
2
+ *
3
+ * @param a
4
+ * @param b
5
+ * @returns
6
+ */
1
7
  function eq(a, b) {
2
8
  if (a == null || b == null) {
3
9
  return a == b;
@@ -65,6 +65,7 @@ function objectHash(object) {
65
65
  /**
66
66
  * convert input to hex
67
67
  * @param input
68
+ * @param length
68
69
  */
69
70
  function toHex(input, length) {
70
71
  let result = "";
@@ -74,7 +74,6 @@ function parseSelector(tokens, context, options, errors) {
74
74
  const stack = [];
75
75
  const uniq = new Map();
76
76
  let allowed = true;
77
- let i = 0;
78
77
  let index;
79
78
  let parent = context;
80
79
  let nested = false;
@@ -108,121 +107,132 @@ function parseSelector(tokens, context, options, errors) {
108
107
  nested = parent?.typ == EnumToken.RuleNodeType;
109
108
  parent = parent?.[PARENT];
110
109
  } while (!nested && parent != null);
111
- for (; i < tokens.length; i++) {
112
- if (tokens[i].typ == EnumToken.ColonTokenType) {
113
- if (tokens[i + 1]?.typ == EnumToken.IdenTokenType) {
114
- Object.assign(tokens[i], {
110
+ const all = new Array(tokens.length);
111
+ let write = 0;
112
+ for (let read = 0; read < tokens.length; read++) {
113
+ let token = tokens[read];
114
+ if (token.typ == EnumToken.ColonTokenType) {
115
+ const next = tokens[read + 1];
116
+ if (next?.typ == EnumToken.IdenTokenType) {
117
+ all[write++] = {
118
+ ...token,
115
119
  typ: EnumToken.PseudoElementTokenType,
116
- val: ":" + tokens[i + 1].val,
117
- });
118
- tokens[i][LOCEND] = tokens[i + 1][LOCEND];
119
- tokens.splice(i + 1, 1);
120
+ val: ":" + next.val,
121
+ [LOCEND]: next[LOCEND],
122
+ };
123
+ read++;
120
124
  continue;
121
125
  }
122
- if (tokens[i + 1]?.typ == EnumToken.FunctionTokenDefType) {
123
- val = ":" + tokens[i + 1].val;
124
- Object.assign(tokens[i], {
126
+ if (next?.typ == EnumToken.FunctionTokenDefType) {
127
+ val = ":" + next.val;
128
+ all[write++] = {
129
+ ...token,
125
130
  typ: val + "()" in getSyntaxConfig().selectors
126
131
  ? EnumToken.PseudoClassFunctionTokenDefType
127
- : tokens[i + 1].typ,
132
+ : next.typ,
128
133
  val,
129
- });
130
- tokens[i][LOCEND] = tokens[i + 1][LOCEND];
131
- tokens.splice(i + 1, 1);
134
+ [LOCEND]: next[LOCEND],
135
+ };
136
+ read++;
132
137
  continue;
133
138
  }
134
139
  }
135
- if (tokens[i].typ == EnumToken.DoubleColonTokenType) {
136
- val = ":" + tokens[i + 1].val;
137
- if (tokens[i + 1]?.typ == EnumToken.IdenTokenType) {
138
- Object.assign(tokens[i], {
140
+ if (token.typ == EnumToken.DoubleColonTokenType) {
141
+ const next = tokens[read + 1];
142
+ val = ":" + next.val;
143
+ if (next?.typ == EnumToken.IdenTokenType) {
144
+ all[write++] = {
145
+ ...token,
139
146
  typ: EnumToken.PseudoClassTokenType,
140
147
  val: (pseudoElements.includes(val) ? "" : ":") + val,
141
- });
142
- tokens[i][LOCEND] = tokens[i + 1][LOCEND];
143
- tokens.splice(i + 1, 1);
148
+ [LOCEND]: next[LOCEND],
149
+ };
150
+ read++;
144
151
  continue;
145
152
  }
146
- if (tokens[i + 1]?.typ == EnumToken.FunctionTokenDefType) {
147
- val = "::" + tokens[i + 1].val;
148
- Object.assign(tokens[i], {
153
+ if (next?.typ == EnumToken.FunctionTokenDefType) {
154
+ val = "::" + next.val;
155
+ all[write++] = {
156
+ ...token,
149
157
  typ: val + "()" in getSyntaxConfig().selectors
150
158
  ? EnumToken.PseudoClassFunctionTokenDefType
151
159
  : EnumToken.FunctionTokenDefType,
152
160
  val,
153
- });
154
- tokens[i][LOCEND] = tokens[i + 1][LOCEND];
155
- tokens.splice(i + 1, 1);
161
+ [LOCEND]: next[LOCEND],
162
+ };
163
+ read++;
156
164
  continue;
157
165
  }
158
166
  }
159
- if (tokens[i].typ == EnumToken.ColorTokenType) {
160
- if (isHash(tokens[i].val)) {
161
- Object.assign(tokens[i], {
162
- typ: EnumToken.HashTokenType,
163
- });
167
+ if (token.typ == EnumToken.ColorTokenType) {
168
+ if (isHash(token.val)) {
169
+ token.typ = EnumToken.HashTokenType;
170
+ all[write++] = token;
171
+ continue;
164
172
  }
165
- else {
166
- return {
167
- typ: EnumToken.RuleNodeType,
168
- sel: [
169
- ...tokens
170
- .reduce((acc, curr, index, array) => {
171
- // if (curr.typ == EnumToken.CommentTokenType) {
172
- // return acc;
173
- // }
174
- if (curr.typ == EnumToken.WhitespaceTokenType) {
175
- if (trimWhiteSpace.includes(array[index - 1]?.typ) ||
176
- trimWhiteSpace.includes(array[index + 1]?.typ) ||
177
- combinators.includes(array[index - 1]?.val) ||
178
- combinators.includes(array[index + 1]?.val)) {
179
- return acc;
180
- }
181
- }
182
- let t = renderValue(curr, { minify: false });
183
- if (t == ",") {
184
- acc.push([]);
185
- }
186
- else {
187
- acc[acc.length - 1].push(t);
173
+ return {
174
+ typ: EnumToken.RuleNodeType,
175
+ sel: [
176
+ ...tokens
177
+ .reduce((acc, curr, index, array) => {
178
+ if (curr.typ == EnumToken.WhitespaceTokenType) {
179
+ if (trimWhiteSpace.includes(array[index - 1]?.typ) ||
180
+ trimWhiteSpace.includes(array[index + 1]?.typ) ||
181
+ combinators.includes(array[index - 1]?.val) ||
182
+ combinators.includes(array[index + 1]?.val)) {
183
+ return acc;
188
184
  }
189
- return acc;
190
- }, [[]])
191
- .reduce((acc, curr) => {
192
- let i = 0;
193
- for (; i < curr.length; i++) {
194
- if (i + 1 < curr.length && curr[i] == "*") {
195
- if (curr[i] == "*") {
196
- let index = curr[i + 1] == " " ? 2 : 1;
197
- if (![">", "~", "+"].includes(curr[index])) {
198
- curr.splice(i, index);
199
- }
185
+ }
186
+ let t = renderValue(curr, { minify: false });
187
+ if (t == ",") {
188
+ acc.push([]);
189
+ }
190
+ else {
191
+ acc[acc.length - 1].push(t);
192
+ }
193
+ return acc;
194
+ }, [[]])
195
+ .reduce((acc, curr) => {
196
+ let i = 0;
197
+ for (; i < curr.length; i++) {
198
+ if (i + 1 < curr.length && curr[i] == "*") {
199
+ if (curr[i] == "*") {
200
+ let index = curr[i + 1] == " " ? 2 : 1;
201
+ if (![">", "~", "+"].includes(curr[index])) {
202
+ curr.splice(i, index);
200
203
  }
201
204
  }
202
205
  }
203
- acc.set(curr.join(""), curr);
204
- return acc;
205
- }, uniq)
206
- .keys(),
207
- ].join(","),
208
- chi: [],
209
- [LOCSRCID]: tokens[0][LOCSRCID],
210
- [LOCSTA]: tokens[0][LOCSTA],
211
- [LOCEND]: tokens[tokens.length - 1][LOCEND],
212
- [TOKENS]: tokens,
213
- [STATE]: EnumAstNodeStatus.Invalid,
214
- [ERRORS]: [
215
- {
216
- action: "drop",
217
- node: tokens[i],
218
- message: "invalid hash id",
219
- },
220
- ],
221
- };
222
- }
206
+ }
207
+ acc.set(curr.join(""), curr);
208
+ return acc;
209
+ }, uniq)
210
+ .keys(),
211
+ ].join(","),
212
+ chi: [],
213
+ [LOCSRCID]: tokens[0][LOCSRCID],
214
+ [LOCSTA]: tokens[0][LOCSTA],
215
+ [LOCEND]: tokens[tokens.length - 1][LOCEND],
216
+ [TOKENS]: tokens,
217
+ [STATE]: EnumAstNodeStatus.Invalid,
218
+ [ERRORS]: [
219
+ {
220
+ action: "drop",
221
+ node: token,
222
+ message: "invalid hash id",
223
+ },
224
+ ],
225
+ };
226
+ }
227
+ all[write++] = token;
228
+ }
229
+ if (write !== tokens.length) {
230
+ for (let index = 0; index < write; index++) {
231
+ tokens[index] = all[index];
223
232
  }
233
+ tokens.length = write;
224
234
  }
225
- const result = matchSelectorSyntax(tokens, errors, options, nested === true);
235
+ const result = matchSelectorSyntax(tokens, errors, options, nested);
226
236
  trimArray(tokens);
227
237
  if (result.success) {
228
238
  for (let i = 0; i < tokens.length; i++) {
@@ -1,9 +1,25 @@
1
+ /**
2
+ *
3
+ * @param value
4
+ * @returns
5
+ */
1
6
  function dasherize(value) {
2
7
  return value.replace(/([A-Z])/g, (all, one) => `-${one.toLowerCase()}`);
3
8
  }
9
+ /**
10
+ *
11
+ * @param value
12
+ * @returns
13
+ */
4
14
  function camelize(value) {
5
15
  return value.replace(/-([a-z])/g, (all, one) => one.toUpperCase());
6
16
  }
17
+ /**
18
+ *
19
+ * @param a
20
+ * @param b
21
+ * @returns
22
+ */
7
23
  function equalsIgnoreCase(a, b) {
8
24
  if (a.length !== b.length)
9
25
  return false;
@@ -10,6 +10,7 @@ import { toDegrees } from '../parser/utils/angle.js';
10
10
  import { LineMap } from '../parser/linesmap.js';
11
11
  import { dirname } from '../fs/resolve.js';
12
12
  import { SourceFile } from '../parser/source.js';
13
+ import { cloneNode } from '../ast/clone.js';
13
14
 
14
15
  /**
15
16
  * render ast
@@ -48,11 +49,13 @@ function doRender(data, options = {}, mapping) {
48
49
  ...options,
49
50
  };
50
51
  if (options.withParents) {
51
- // @ts-ignore
52
- let parent = data[PARENT];
52
+ let parent;
53
53
  while (data[PARENT] != null) {
54
54
  // @ts-ignore
55
- parent = { ...data[PARENT], chi: [{ ...data }] };
55
+ // parent = { ...data[PARENT], chi: [data] };
56
+ parent = cloneNode(data[PARENT]);
57
+ // @ts-ignore
58
+ parent.chi = [data];
56
59
  // @ts-ignore
57
60
  parent[PARENT] = data[PARENT][PARENT];
58
61
  // @ts-ignore
@@ -222,6 +225,8 @@ function updateSourceMap(node, options, cache, sourcemaps, sourceLocation, lines
222
225
  * @param sourceLocation
223
226
  * @param linesMap
224
227
  * @param str
228
+ * @param start
229
+ * @param end
225
230
  */
226
231
  function move(sourceLocation, linesMap, str, start, end) {
227
232
  let i = start ?? 0;
@@ -414,8 +419,8 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
414
419
  };
415
420
  }
416
421
  switch (token.typ) {
417
- case EnumToken.FunctionTokenDefType:
418
422
  case EnumToken.UrlFunctionTokenDefType:
423
+ case EnumToken.FunctionTokenDefType:
419
424
  case EnumToken.MathFunctionTokenDefType:
420
425
  case EnumToken.ImageFunctionTokenDefType:
421
426
  case EnumToken.ColorFunctionTokenDefType:
@@ -515,8 +520,8 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
515
520
  return token.val;
516
521
  }
517
522
  if (Array.isArray(token.chi)) {
518
- const fnName = token.val.toLowerCase();
519
- const isLegacy = ["rgb", "rgba", "hsl", "hsla"].includes(token.val.toLowerCase());
523
+ const fnName = token.val;
524
+ const isLegacy = ["rgb", "rgba", "hsl", "hsla"].includes(token.val);
520
525
  const hasAlpha = [
521
526
  "rgb",
522
527
  "rgba",
@@ -559,6 +564,9 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
559
564
  }
560
565
  case EnumToken.UrlFunctionTokenType:
561
566
  if (options.minify && token.typ === EnumToken.UrlFunctionTokenType) {
567
+ if (token.chi[0]?.typ === EnumToken.BadUrlTokenType) {
568
+ return "url()";
569
+ }
562
570
  for (const child of token.chi) {
563
571
  if (child.typ === EnumToken.StringTokenType) {
564
572
  if (child.val.slice(1, 5) !== "data:" &&
@@ -1246,6 +1254,12 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
1246
1254
  return token.val.typ == EnumToken.FractionTokenType
1247
1255
  ? renderValue(token.val, options, cache)
1248
1256
  : minifyNumber(token.val);
1257
+ case EnumToken.InfinityTokenType:
1258
+ return "0/0";
1259
+ case EnumToken.NegativeInfinityTokenType:
1260
+ return "-0/0";
1261
+ case EnumToken.NaNTokenType:
1262
+ return "NaN";
1249
1263
  case EnumToken.AtRuleTokenType:
1250
1264
  return "@" + token.nam;
1251
1265
  case EnumToken.CommentTokenType:
@@ -47,15 +47,20 @@ function decode(str) {
47
47
  * @returns
48
48
  */
49
49
  function encode(value) {
50
- if (typeof value === 'number') {
51
- return encode_integer(value);
52
- }
50
+ // if (typeof value === 'number') {
51
+ // return encode_integer(value);
52
+ // }
53
53
  let result = '';
54
54
  for (let i = 0; i < value.length; i += 1) {
55
55
  result += encode_integer(value[i]);
56
56
  }
57
57
  return result;
58
58
  }
59
+ /**
60
+ *
61
+ * @param num
62
+ * @returns
63
+ */
59
64
  function encode_integer(num) {
60
65
  let result = '';
61
66
  if (num < 0) {
@@ -1,7 +1,37 @@
1
+ import { toBase64 } from '../../parser/utils/base64.js';
1
2
  import { decode, encode } from './lib/codec.js';
2
3
 
3
4
  /**
4
5
  * Generate and parse source map
6
+ *
7
+ * ```ts
8
+ * const sourcemap = new SourceMap();
9
+ *
10
+ * // you can also pass an input sourcemap
11
+ * // const sourcemap = new SourceMap(sourcemapObjectOrJSONString);
12
+ *
13
+ * sourcemap.addSourceContent(0, '/css/styles.css', null);
14
+ * sourcemap.addSourceContent(1, '/css/typography.css', null);
15
+ *
16
+ * const maps = [];
17
+ *
18
+ * maps.add([
19
+ 1, 1, 0, 1, 1]);
20
+ * maps.add([
21
+ 2, 1, 1, 1, 1
22
+ ]);
23
+
24
+ sourcemap.add(maps);
25
+
26
+ // convert to inline sourcemap
27
+ sourcemap.toUrl();
28
+
29
+ // convert to JSON
30
+ sourcemap.toJSON();
31
+
32
+ // find the original file, line and column
33
+ sourcemap.find(2, 1);
34
+ ```
5
35
  */
6
36
  class SourceMap {
7
37
  /**
@@ -52,7 +82,7 @@ class SourceMap {
52
82
  line = -1;
53
83
  /**
54
84
  *
55
- * @param sourcemaps
85
+ * @param sourcemaps input sourcemap
56
86
  */
57
87
  constructor(sourcemaps) {
58
88
  if (typeof sourcemaps === "string") {
@@ -93,9 +123,9 @@ class SourceMap {
93
123
  }
94
124
  /**
95
125
  * add source
96
- * @param id
97
- * @param fileName
98
- * @param content
126
+ * @param id source id
127
+ * @param fileName source file
128
+ * @param content source content
99
129
  * @returns
100
130
  */
101
131
  addSourceContent(id, fileName, content) {
@@ -231,7 +261,7 @@ class SourceMap {
231
261
  */
232
262
  toUrl() {
233
263
  // /*# sourceMappingURL = ${url} */
234
- return `data:application/json;charset=utf-8;base64,${btoa(JSON.stringify(this.toJSON()))}`;
264
+ return `data:application/json;charset=utf-8;base64,${toBase64(JSON.stringify(this.toJSON()))}`;
235
265
  }
236
266
  /**
237
267
  * Convert to JSON object