@tbela99/css-parser 0.4.0 → 0.5.0

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.
@@ -179,7 +179,7 @@
179
179
  }
180
180
  };
181
181
  const colorFuncColorSpace = ['srgb', 'srgb-linear', 'display-p3', 'prophoto-rgb', 'a98-rgb', 'rec2020', 'xyz', 'xyz-d65', 'xyz-d50'];
182
- const powerlessColorComponent = { typ: exports.EnumToken.IdenTokenType, val: 'none' };
182
+ ({ typ: exports.EnumToken.IdenTokenType, val: 'none' });
183
183
  const D50 = [0.3457 / 0.3585, 1.00000, (1.0 - 0.3457 - 0.3585) / 0.3585];
184
184
  const k = Math.pow(29, 3) / Math.pow(3, 3);
185
185
  const e = Math.pow(6, 3) / Math.pow(29, 3);
@@ -559,42 +559,6 @@
559
559
  return alpha == null ? [l, c, h] : [l, c, h, alpha];
560
560
  }
561
561
 
562
- function eq(a, b) {
563
- if (a == null || b == null) {
564
- return a == b;
565
- }
566
- if (typeof a != 'object' || typeof b != 'object') {
567
- return a === b;
568
- }
569
- if (Object.getPrototypeOf(a) !== Object.getPrototypeOf(b)) {
570
- return false;
571
- }
572
- if (Array.isArray(a)) {
573
- if (a.length != b.length) {
574
- return false;
575
- }
576
- let i = 0;
577
- for (; i < a.length; i++) {
578
- if (!eq(a[i], b[i])) {
579
- return false;
580
- }
581
- }
582
- return true;
583
- }
584
- const k1 = Object.keys(a);
585
- const k2 = Object.keys(b);
586
- if (k1.length != k2.length) {
587
- return false;
588
- }
589
- let key;
590
- for (key of k1) {
591
- if (!(key in b) || !eq(a[key], b[key])) {
592
- return false;
593
- }
594
- }
595
- return true;
596
- }
597
-
598
562
  function hex2oklch(token) {
599
563
  // @ts-ignore
600
564
  return lab2lchvalues(...hex2oklab(token));
@@ -644,7 +608,7 @@
644
608
  // @ts-ignore
645
609
  t = components[3];
646
610
  // @ts-ignore
647
- const alpha = t == null || eq(t, powerlessColorComponent) ? 1 : getNumber(t);
611
+ const alpha = t == null || (t.typ == exports.EnumToken.IdenTokenType && t.val == 'none') ? 1 : getNumber(t);
648
612
  return [l, c, h, alpha];
649
613
  }
650
614
 
@@ -703,7 +667,7 @@
703
667
  // @ts-ignore
704
668
  t = components[3];
705
669
  // @ts-ignore
706
- const alpha = t == null || eq(t, powerlessColorComponent) ? 1 : getNumber(t);
670
+ const alpha = t == null || (t.typ == exports.EnumToken.IdenTokenType && t.val == 'none') ? 1 : getNumber(t);
707
671
  const rgb = [l, a, b];
708
672
  if (alpha != 1 && alpha != null) {
709
673
  rgb.push(alpha);
@@ -908,10 +872,7 @@
908
872
  return null;
909
873
  }
910
874
  function rgb2srgb(token) {
911
- return getComponents(token).map((t, index) => index == 3 ? (eq(t, {
912
- typ: exports.EnumToken.IdenTokenType,
913
- val: 'none'
914
- }) ? 1 : getNumber(t)) : (t.typ == exports.EnumToken.PercentageTokenType ? 255 : 1) * getNumber(t) / 255);
875
+ return getComponents(token).map((t, index) => index == 3 ? ((t.typ == exports.EnumToken.IdenTokenType && t.val == 'none') ? 1 : getNumber(t)) : (t.typ == exports.EnumToken.PercentageTokenType ? 255 : 1) * getNumber(t) / 255);
915
876
  }
916
877
  function hex2srgb(token) {
917
878
  const value = expandHexValue(token.kin == 'lit' ? COLORS_NAMES[token.val.toLowerCase()] : token.val);
@@ -1198,7 +1159,7 @@
1198
1159
  t = chi[3];
1199
1160
  // @ts-ignore
1200
1161
  let a = null;
1201
- if (t != null && !eq(t, { typ: exports.EnumToken.IdenTokenType, val: 'none' })) {
1162
+ if (t != null && !(t.typ == exports.EnumToken.IdenTokenType && t.val == 'none')) {
1202
1163
  // @ts-ignore
1203
1164
  a = getNumber(t) / 255;
1204
1165
  }
@@ -1284,7 +1245,7 @@
1284
1245
  function rgb2hwb(token) {
1285
1246
  // @ts-ignore
1286
1247
  return srgb2hwb(...getComponents(token).map((t, index) => {
1287
- if (index == 3 && eq(t, { typ: exports.EnumToken.IdenTokenType, val: 'none' })) {
1248
+ if (index == 3 && t.typ == exports.EnumToken.IdenTokenType && t.val == 'none') {
1288
1249
  return 1;
1289
1250
  }
1290
1251
  return getNumber(t) / 255;
@@ -1293,7 +1254,7 @@
1293
1254
  function hsl2hwb(token) {
1294
1255
  // @ts-ignore
1295
1256
  return hsl2hwbvalues(...getComponents(token).map((t, index) => {
1296
- if (index == 3 && eq(t, { typ: exports.EnumToken.IdenTokenType, val: 'none' })) {
1257
+ if (index == 3 && (t.typ == exports.EnumToken.IdenTokenType && t.val == 'none')) {
1297
1258
  return 1;
1298
1259
  }
1299
1260
  if (index == 0) {
@@ -1914,10 +1875,47 @@
1914
1875
  case 'lch':
1915
1876
  values.push(...lch2srgb(token));
1916
1877
  break;
1917
- case 'color':
1878
+ case 'oklch':
1918
1879
  // @ts-ignore
1919
1880
  values.push(...srgb2oklch(...color2srgbvalues(token)));
1920
1881
  break;
1882
+ case 'color':
1883
+ const val = color2srgbvalues(token);
1884
+ switch (to) {
1885
+ case 'srgb':
1886
+ values.push(...val);
1887
+ break;
1888
+ case 'srgb-linear':
1889
+ // @ts-ignore
1890
+ values.push(...srgb2lsrgbvalues(...val));
1891
+ break;
1892
+ case 'display-p3':
1893
+ // @ts-ignore
1894
+ values.push(...srgb2p3values(...val));
1895
+ break;
1896
+ case 'prophoto-rgb':
1897
+ // @ts-ignore
1898
+ values.push(...srgb2prophotorgbvalues(...val));
1899
+ break;
1900
+ case 'a98-rgb':
1901
+ // @ts-ignore
1902
+ values.push(...srgb2a98values(...val));
1903
+ break;
1904
+ case 'rec2020':
1905
+ // @ts-ignore
1906
+ values.push(...srgb2rec2020values(...val));
1907
+ break;
1908
+ case 'xyz':
1909
+ case 'xyz-d65':
1910
+ // @ts-ignore
1911
+ values.push(...srgb2xyz(...val));
1912
+ break;
1913
+ case 'xyz-d50':
1914
+ // @ts-ignore
1915
+ values.push(...(XYZ_D65_to_D50(...srgb2xyz(...val))));
1916
+ break;
1917
+ }
1918
+ break;
1921
1919
  }
1922
1920
  if (values.length > 0) {
1923
1921
  return values2colortoken(values, to);
@@ -2191,10 +2189,10 @@
2191
2189
  }
2192
2190
  const components1 = getComponents(color1);
2193
2191
  const components2 = getComponents(color2);
2194
- if (eq(components1[3], powerlessColorComponent) && values2.length == 4) {
2192
+ if ((components1[3] != null && components1[3].typ == exports.EnumToken.IdenTokenType && components1[3].val == 'none') && values2.length == 4) {
2195
2193
  values1[3] = values2[3];
2196
2194
  }
2197
- if (eq(components2[3], powerlessColorComponent) && values1.length == 4) {
2195
+ if ((components2[3] != null && components2[3].typ == exports.EnumToken.IdenTokenType && components2[3].val == 'none') && values1.length == 4) {
2198
2196
  values2[3] = values1[3];
2199
2197
  }
2200
2198
  const p1 = getNumber(percentage1);
@@ -2306,13 +2304,13 @@
2306
2304
  const lchSpaces = ['lch', 'oklch'];
2307
2305
  // powerless
2308
2306
  if (lchSpaces.includes(color1.kin) || lchSpaces.includes(colorSpace.val)) {
2309
- if (eq(components1[2], powerlessColorComponent) || values1[2] == 0) {
2307
+ if ((components1[2].typ == exports.EnumToken.IdenTokenType && components1[2].val == 'none') || values1[2] == 0) {
2310
2308
  values1[2] = values2[2];
2311
2309
  }
2312
2310
  }
2313
2311
  // powerless
2314
2312
  if (lchSpaces.includes(color1.kin) || lchSpaces.includes(colorSpace.val)) {
2315
- if (eq(components2[2], powerlessColorComponent) || values2[2] == 0) {
2313
+ if ((components2[2].typ == exports.EnumToken.IdenTokenType && components2[2].val == 'none') || values2[2] == 0) {
2316
2314
  values2[2] = values1[2];
2317
2315
  }
2318
2316
  }
@@ -2743,10 +2741,7 @@
2743
2741
  [names[1]]: getValue(g, converted, names[1]), // string,
2744
2742
  [names[2]]: getValue(b, converted, names[2]),
2745
2743
  // @ts-ignore
2746
- alpha: alpha == null || eq(alpha, {
2747
- typ: exports.EnumToken.IdenTokenType,
2748
- val: 'none'
2749
- }) ? {
2744
+ alpha: alpha == null || (alpha.typ == exports.EnumToken.IdenTokenType && alpha.val == 'none') ? {
2750
2745
  typ: exports.EnumToken.NumberTokenType,
2751
2746
  val: '1'
2752
2747
  } : (alpha.typ == exports.EnumToken.PercentageTokenType ? {
@@ -2759,7 +2754,7 @@
2759
2754
  [names[1]]: getValue(gExp, converted, names[1]),
2760
2755
  [names[2]]: getValue(bExp, converted, names[2]),
2761
2756
  // @ts-ignore
2762
- alpha: getValue(aExp == null || eq(aExp, { typ: exports.EnumToken.IdenTokenType, val: 'none' }) ? {
2757
+ alpha: getValue(aExp == null || (aExp.typ == exports.EnumToken.IdenTokenType && aExp.val == 'none') ? {
2763
2758
  typ: exports.EnumToken.NumberTokenType,
2764
2759
  val: '1'
2765
2760
  } : aExp)
@@ -2997,6 +2992,19 @@
2997
2992
  removeComments: false,
2998
2993
  }), sourcemap: false, convertColor: true, expandNestingRules: false, preserveLicense: false, ...options
2999
2994
  };
2995
+ if (options.withParents) {
2996
+ // @ts-ignore
2997
+ let parent = data.parent;
2998
+ // @ts-ignore
2999
+ while (data.parent != null) {
3000
+ // @ts-ignore
3001
+ parent = { ...data.parent, chi: [{ ...data }] };
3002
+ // @ts-ignore
3003
+ parent.parent = data.parent.parent;
3004
+ // @ts-ignore
3005
+ data = parent;
3006
+ }
3007
+ }
3000
3008
  const startTime = performance.now();
3001
3009
  const errors = [];
3002
3010
  const sourcemap = options.sourcemap ? new SourceMap : null;
@@ -3063,7 +3071,7 @@
3063
3071
  return `${data.nam}:${options.indent}${data.val.reduce(reducer, '')}`;
3064
3072
  case exports.EnumToken.CommentNodeType:
3065
3073
  case exports.EnumToken.CDOCOMMNodeType:
3066
- if (data.val.startsWith('# sourceMappingURL=')) {
3074
+ if (data.val.startsWith('/*# sourceMappingURL=')) {
3067
3075
  // ignore sourcemap
3068
3076
  return '';
3069
3077
  }
@@ -3075,12 +3083,12 @@
3075
3083
  return css;
3076
3084
  }
3077
3085
  if (css === '') {
3078
- if (sourcemap != null) {
3086
+ if (sourcemap != null && node.loc != null) {
3079
3087
  updateSourceMap(node, options, cache, sourcemap, position, str);
3080
3088
  }
3081
3089
  return str;
3082
3090
  }
3083
- if (sourcemap != null) {
3091
+ if (sourcemap != null && node.loc != null) {
3084
3092
  update(position, options.newLine);
3085
3093
  updateSourceMap(node, options, cache, sourcemap, position, str);
3086
3094
  }
@@ -3512,14 +3520,14 @@
3512
3520
  // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-ident-token
3513
3521
  // '\\'
3514
3522
  const REVERSE_SOLIDUS = 0x5c;
3515
- const dimensionUnits = [
3523
+ const dimensionUnits = new Set([
3516
3524
  'q', 'cap', 'ch', 'cm', 'cqb', 'cqh', 'cqi', 'cqmax', 'cqmin', 'cqw', 'dvb',
3517
3525
  'dvh', 'dvi', 'dvmax', 'dvmin', 'dvw', 'em', 'ex', 'ic', 'in', 'lh', 'lvb',
3518
3526
  'lvh', 'lvi', 'lvmax', 'lvw', 'mm', 'pc', 'pt', 'px', 'rem', 'rlh', 'svb',
3519
3527
  'svh', 'svi', 'svmin', 'svw', 'vb', 'vh', 'vi', 'vmax', 'vmin', 'vw'
3520
- ];
3528
+ ]);
3521
3529
  function isLength(dimension) {
3522
- return 'unit' in dimension && dimensionUnits.includes(dimension.unit.toLowerCase());
3530
+ return 'unit' in dimension && dimensionUnits.has(dimension.unit.toLowerCase());
3523
3531
  }
3524
3532
  function isResolution(dimension) {
3525
3533
  return 'unit' in dimension && ['dpi', 'dpcm', 'dppx', 'x'].includes(dimension.unit.toLowerCase());
@@ -3579,7 +3587,7 @@
3579
3587
  for (let i = 1; i < children.length - 2; i++) {
3580
3588
  if (children[i].typ == exports.EnumToken.IdenTokenType) {
3581
3589
  if (children[i].val != 'none' &&
3582
- !(isRelative && ['alpha', 'r', 'g', 'b'].includes(children[i].val) || isColorspace(children[i]))) {
3590
+ !(isRelative && ['alpha', 'r', 'g', 'b', 'x', 'y', 'z'].includes(children[i].val) || isColorspace(children[i]))) {
3583
3591
  return false;
3584
3592
  }
3585
3593
  }
@@ -3587,10 +3595,14 @@
3587
3595
  return false;
3588
3596
  }
3589
3597
  }
3598
+ if (children.length == 4 || (isRelative && children.length == 6)) {
3599
+ return true;
3600
+ }
3590
3601
  if (children.length == 8 || children.length == 6) {
3591
3602
  const sep = children.at(-2);
3592
3603
  const alpha = children.at(-1);
3593
- if (sep.typ != exports.EnumToken.LiteralTokenType || sep.val != '/') {
3604
+ // @ts-ignore
3605
+ if ((children.length > 6 || !isRelative) && sep.typ != exports.EnumToken.LiteralTokenType || sep.val != '/') {
3594
3606
  return false;
3595
3607
  }
3596
3608
  if (alpha.typ == exports.EnumToken.IdenTokenType && alpha.val != 'none') {
@@ -4292,18 +4304,18 @@
4292
4304
  "initial"
4293
4305
  ],
4294
4306
  "default": [
4295
- "0",
4296
- "0 1",
4297
- "0 auto",
4298
- "0 1 auto"
4299
4307
  ],
4308
+ mapping: {
4309
+ "0 1 auto": "initial",
4310
+ "0 0 auto": "none",
4311
+ "1 1 auto": "auto"
4312
+ },
4300
4313
  properties: {
4301
4314
  "flex-grow": {
4302
4315
  required: true,
4303
4316
  keywords: [
4304
4317
  ],
4305
4318
  "default": [
4306
- "0"
4307
4319
  ],
4308
4320
  types: [
4309
4321
  "Number"
@@ -4313,7 +4325,6 @@
4313
4325
  keywords: [
4314
4326
  ],
4315
4327
  "default": [
4316
- "1"
4317
4328
  ],
4318
4329
  types: [
4319
4330
  "Number"
@@ -4329,7 +4340,6 @@
4329
4340
  "auto"
4330
4341
  ],
4331
4342
  "default": [
4332
- "auto"
4333
4343
  ],
4334
4344
  types: [
4335
4345
  "Length",
@@ -4989,8 +4999,8 @@
4989
4999
  "Number"
4990
5000
  ],
4991
5001
  "default": [
4992
- "normal",
4993
- "400"
5002
+ "400",
5003
+ "normal"
4994
5004
  ],
4995
5005
  keywords: [
4996
5006
  "normal",
@@ -5345,6 +5355,8 @@
5345
5355
  left: "0",
5346
5356
  top: "0",
5347
5357
  center: "50%",
5358
+ "center center": "50%",
5359
+ "50% 50%": "50%",
5348
5360
  bottom: "100%",
5349
5361
  right: "100%"
5350
5362
  },
@@ -6029,194 +6041,229 @@
6029
6041
  exports.EnumToken.BadUrlTokenType,
6030
6042
  exports.EnumToken.BadStringTokenType
6031
6043
  ];
6044
+ const enumTokenHints = new Set([
6045
+ exports.EnumToken.WhitespaceTokenType, exports.EnumToken.SemiColonTokenType, exports.EnumToken.ColonTokenType, exports.EnumToken.BlockStartTokenType,
6046
+ exports.EnumToken.BlockStartTokenType, exports.EnumToken.AttrStartTokenType, exports.EnumToken.AttrEndTokenType, exports.EnumToken.StartParensTokenType, exports.EnumToken.EndParensTokenType,
6047
+ exports.EnumToken.CommaTokenType, exports.EnumToken.GtTokenType, exports.EnumToken.LtTokenType, exports.EnumToken.GteTokenType, exports.EnumToken.LteTokenType, exports.EnumToken.CommaTokenType,
6048
+ exports.EnumToken.StartMatchTokenType, exports.EnumToken.EndMatchTokenType, exports.EnumToken.IncludeMatchTokenType, exports.EnumToken.DashMatchTokenType, exports.EnumToken.ContainMatchTokenType,
6049
+ exports.EnumToken.EOFTokenType
6050
+ ]);
6032
6051
  const webkitPseudoAliasMap = {
6033
6052
  '-webkit-autofill': 'autofill'
6034
6053
  };
6054
+ function reject(reason) {
6055
+ throw new Error(reason ?? 'Parsing aborted');
6056
+ }
6035
6057
  async function doParse(iterator, options = {}) {
6036
- return new Promise(async (resolve, reject) => {
6037
- if (options.signal != null) {
6038
- options.signal.addEventListener('abort', reject);
6039
- }
6040
- options = {
6041
- src: '',
6042
- sourcemap: false,
6043
- minify: true,
6044
- parseColor: true,
6045
- nestingRules: false,
6046
- resolveImport: false,
6047
- resolveUrls: false,
6048
- removeCharset: false,
6049
- removeEmpty: true,
6050
- removeDuplicateDeclarations: true,
6051
- computeShorthand: true,
6052
- computeCalcExpression: true,
6053
- inlineCssVariables: false,
6054
- ...options
6055
- };
6056
- if (options.expandNestingRules) {
6057
- options.nestingRules = false;
6058
- }
6059
- if (options.resolveImport) {
6060
- options.resolveUrls = true;
6061
- }
6062
- const startTime = performance.now();
6063
- const errors = [];
6064
- const src = options.src;
6065
- const stack = [];
6066
- const stats = {
6067
- bytesIn: 0,
6068
- importedBytesIn: 0,
6069
- parse: `0ms`,
6070
- minify: `0ms`,
6071
- total: `0ms`
6072
- };
6073
- let ast = {
6074
- typ: exports.EnumToken.StyleSheetNodeType,
6075
- chi: []
6058
+ // return new Promise(async (resolve, reject) => {
6059
+ if (options.signal != null) {
6060
+ options.signal.addEventListener('abort', reject);
6061
+ }
6062
+ options = {
6063
+ src: '',
6064
+ sourcemap: false,
6065
+ minify: true,
6066
+ parseColor: true,
6067
+ nestingRules: false,
6068
+ resolveImport: false,
6069
+ resolveUrls: false,
6070
+ removeCharset: true,
6071
+ removeEmpty: true,
6072
+ removeDuplicateDeclarations: true,
6073
+ computeShorthand: true,
6074
+ computeCalcExpression: true,
6075
+ inlineCssVariables: false,
6076
+ setParent: true,
6077
+ ...options
6078
+ };
6079
+ if (options.expandNestingRules) {
6080
+ options.nestingRules = false;
6081
+ }
6082
+ if (options.resolveImport) {
6083
+ options.resolveUrls = true;
6084
+ }
6085
+ const startTime = performance.now();
6086
+ const errors = [];
6087
+ const src = options.src;
6088
+ const stack = [];
6089
+ const stats = {
6090
+ bytesIn: 0,
6091
+ importedBytesIn: 0,
6092
+ parse: `0ms`,
6093
+ minify: `0ms`,
6094
+ total: `0ms`
6095
+ };
6096
+ let ast = {
6097
+ typ: exports.EnumToken.StyleSheetNodeType,
6098
+ chi: []
6099
+ };
6100
+ let tokens = [];
6101
+ let map = new Map;
6102
+ let context = ast;
6103
+ if (options.sourcemap) {
6104
+ ast.loc = {
6105
+ sta: {
6106
+ ind: 0,
6107
+ lin: 1,
6108
+ col: 1
6109
+ },
6110
+ src: ''
6076
6111
  };
6077
- let tokens = [];
6078
- let map = new Map;
6079
- let context = ast;
6080
- if (options.sourcemap) {
6081
- ast.loc = {
6082
- sta: {
6083
- ind: 0,
6084
- lin: 1,
6085
- col: 1
6086
- },
6087
- src: ''
6088
- };
6112
+ }
6113
+ const iter = tokenize(iterator);
6114
+ let item;
6115
+ while (item = iter.next().value) {
6116
+ stats.bytesIn = item.bytesIn;
6117
+ //
6118
+ // doParse error
6119
+ if (item.hint != null && BadTokensTypes.includes(item.hint)) {
6120
+ // bad token
6121
+ continue;
6089
6122
  }
6090
- const iter = tokenize(iterator);
6091
- let item;
6092
- while (item = iter.next().value) {
6093
- stats.bytesIn = item.bytesIn;
6094
- //
6095
- // doParse error
6096
- if (item.hint != null && BadTokensTypes.includes(item.hint)) {
6097
- // bad token
6098
- continue;
6099
- }
6100
- if (item.hint != exports.EnumToken.EOFTokenType) {
6101
- tokens.push(item);
6102
- }
6103
- if (item.token == ';' || item.token == '{') {
6104
- let node = await parseNode(tokens, context, stats, options, errors, src, map);
6105
- if (node != null) {
6106
- stack.push(node);
6107
- // @ts-ignore
6108
- context = node;
6109
- }
6110
- else if (item.token == '{') {
6111
- // node == null
6112
- // consume and throw away until the closing '}' or EOF
6113
- let inBlock = 1;
6114
- do {
6115
- item = iter.next().value;
6116
- if (item == null) {
6117
- break;
6118
- }
6119
- if (item.token == '{') {
6120
- inBlock++;
6121
- }
6122
- else if (item.token == '}') {
6123
- inBlock--;
6124
- }
6125
- } while (inBlock != 0);
6126
- }
6127
- tokens = [];
6128
- map = new Map;
6129
- }
6130
- else if (item.token == '}') {
6131
- await parseNode(tokens, context, stats, options, errors, src, map);
6132
- const previousNode = stack.pop();
6133
- // @ts-ignore
6134
- context = stack[stack.length - 1] || ast;
6123
+ if (item.hint != exports.EnumToken.EOFTokenType) {
6124
+ tokens.push(item);
6125
+ }
6126
+ if (item.token == ';' || item.token == '{') {
6127
+ let node = await parseNode(tokens, context, stats, options, errors, src, map);
6128
+ if (node != null) {
6129
+ stack.push(node);
6135
6130
  // @ts-ignore
6136
- if (options.removeEmpty && previousNode != null && previousNode.chi.length == 0 && context.chi[context.chi.length - 1] == previousNode) {
6137
- context.chi.pop();
6138
- }
6139
- tokens = [];
6140
- map = new Map;
6131
+ context = node;
6132
+ }
6133
+ else if (item.token == '{') {
6134
+ // node == null
6135
+ // consume and throw away until the closing '}' or EOF
6136
+ let inBlock = 1;
6137
+ do {
6138
+ item = iter.next().value;
6139
+ if (item == null) {
6140
+ break;
6141
+ }
6142
+ if (item.token == '{') {
6143
+ inBlock++;
6144
+ }
6145
+ else if (item.token == '}') {
6146
+ inBlock--;
6147
+ }
6148
+ } while (inBlock != 0);
6141
6149
  }
6150
+ tokens = [];
6151
+ map = new Map;
6142
6152
  }
6143
- if (tokens.length > 0) {
6153
+ else if (item.token == '}') {
6144
6154
  await parseNode(tokens, context, stats, options, errors, src, map);
6145
- }
6146
- while (stack.length > 0 && context != ast) {
6147
6155
  const previousNode = stack.pop();
6148
6156
  // @ts-ignore
6149
- context = stack[stack.length - 1] ?? ast;
6157
+ context = stack[stack.length - 1] || ast;
6150
6158
  // @ts-ignore
6151
6159
  if (options.removeEmpty && previousNode != null && previousNode.chi.length == 0 && context.chi[context.chi.length - 1] == previousNode) {
6152
6160
  context.chi.pop();
6153
- continue;
6154
6161
  }
6155
- break;
6162
+ tokens = [];
6163
+ map = new Map;
6156
6164
  }
6157
- const endParseTime = performance.now();
6158
- if (options.expandNestingRules) {
6159
- ast = expand(ast);
6165
+ }
6166
+ if (tokens.length > 0) {
6167
+ await parseNode(tokens, context, stats, options, errors, src, map);
6168
+ }
6169
+ while (stack.length > 0 && context != ast) {
6170
+ const previousNode = stack.pop();
6171
+ // @ts-ignore
6172
+ context = stack[stack.length - 1] ?? ast;
6173
+ // @ts-ignore
6174
+ if (options.removeEmpty && previousNode != null && previousNode.chi.length == 0 && context.chi[context.chi.length - 1] == previousNode) {
6175
+ context.chi.pop();
6176
+ continue;
6160
6177
  }
6161
- if (options.visitor != null) {
6162
- for (const result of walk(ast)) {
6163
- if (result.node.typ == exports.EnumToken.DeclarationNodeType &&
6164
- // @ts-ignore
6165
- (typeof options.visitor.Declaration == 'function' || options.visitor.Declaration?.[result.node.nam] != null)) {
6166
- const callable = typeof options.visitor.Declaration == 'function' ? options.visitor.Declaration : options.visitor.Declaration[result.node.nam];
6167
- const results = await callable(result.node);
6168
- if (results == null || (Array.isArray(results) && results.length == 0)) {
6169
- continue;
6170
- }
6171
- // @ts-ignore
6172
- result.parent.chi.splice(result.parent.chi.indexOf(result.node), 1, ...(Array.isArray(results) ? results : [results]));
6178
+ break;
6179
+ }
6180
+ const endParseTime = performance.now();
6181
+ if (options.expandNestingRules) {
6182
+ ast = expand(ast);
6183
+ }
6184
+ if (options.visitor != null) {
6185
+ for (const result of walk(ast)) {
6186
+ if (result.node.typ == exports.EnumToken.DeclarationNodeType &&
6187
+ // @ts-ignore
6188
+ (typeof options.visitor.Declaration == 'function' || options.visitor.Declaration?.[result.node.nam] != null)) {
6189
+ const callable = typeof options.visitor.Declaration == 'function' ? options.visitor.Declaration : options.visitor.Declaration[result.node.nam];
6190
+ const results = await callable(result.node);
6191
+ if (results == null || (Array.isArray(results) && results.length == 0)) {
6192
+ continue;
6173
6193
  }
6174
- else if (options.visitor.Rule != null && result.node.typ == exports.EnumToken.RuleNodeType) {
6175
- const results = await options.visitor.Rule(result.node);
6176
- if (results == null || (Array.isArray(results) && results.length == 0)) {
6177
- continue;
6178
- }
6179
- // @ts-ignore
6180
- result.parent.chi.splice(result.parent.chi.indexOf(result.node), 1, ...(Array.isArray(results) ? results : [results]));
6194
+ // @ts-ignore
6195
+ result.parent.chi.splice(result.parent.chi.indexOf(result.node), 1, ...(Array.isArray(results) ? results : [results]));
6196
+ }
6197
+ else if (options.visitor.Rule != null && result.node.typ == exports.EnumToken.RuleNodeType) {
6198
+ const results = await options.visitor.Rule(result.node);
6199
+ if (results == null || (Array.isArray(results) && results.length == 0)) {
6200
+ continue;
6181
6201
  }
6182
- else if (options.visitor.AtRule != null &&
6183
- result.node.typ == exports.EnumToken.AtRuleNodeType &&
6184
- // @ts-ignore
6185
- (typeof options.visitor.AtRule == 'function' || options.visitor.AtRule?.[result.node.nam] != null)) {
6186
- const callable = typeof options.visitor.AtRule == 'function' ? options.visitor.AtRule : options.visitor.AtRule[result.node.nam];
6187
- const results = await callable(result.node);
6188
- if (results == null || (Array.isArray(results) && results.length == 0)) {
6189
- continue;
6190
- }
6191
- // @ts-ignore
6192
- result.parent.chi.splice(result.parent.chi.indexOf(result.node), 1, ...(Array.isArray(results) ? results : [results]));
6202
+ // @ts-ignore
6203
+ result.parent.chi.splice(result.parent.chi.indexOf(result.node), 1, ...(Array.isArray(results) ? results : [results]));
6204
+ }
6205
+ else if (options.visitor.AtRule != null &&
6206
+ result.node.typ == exports.EnumToken.AtRuleNodeType &&
6207
+ // @ts-ignore
6208
+ (typeof options.visitor.AtRule == 'function' || options.visitor.AtRule?.[result.node.nam] != null)) {
6209
+ const callable = typeof options.visitor.AtRule == 'function' ? options.visitor.AtRule : options.visitor.AtRule[result.node.nam];
6210
+ const results = await callable(result.node);
6211
+ if (results == null || (Array.isArray(results) && results.length == 0)) {
6212
+ continue;
6193
6213
  }
6214
+ // @ts-ignore
6215
+ result.parent.chi.splice(result.parent.chi.indexOf(result.node), 1, ...(Array.isArray(results) ? results : [results]));
6194
6216
  }
6195
6217
  }
6196
- if (options.minify) {
6197
- if (ast.chi.length > 0) {
6198
- minify(ast, options, true, errors, false);
6218
+ }
6219
+ if (options.minify) {
6220
+ if (ast.chi.length > 0) {
6221
+ minify(ast, options, true, errors, false);
6222
+ }
6223
+ }
6224
+ if (options.setParent) {
6225
+ const nodes = [ast];
6226
+ let node;
6227
+ while ((node = nodes.shift())) {
6228
+ // @ts-ignore
6229
+ if (node.chi.length > 0) {
6230
+ // @ts-ignore
6231
+ for (const child of node.chi) {
6232
+ if (child.parent != node) {
6233
+ Object.defineProperty(child, 'parent', { ...definedPropertySettings, value: node });
6234
+ }
6235
+ if ('chi' in child && child.chi.length > 0) {
6236
+ // @ts-ignore
6237
+ nodes.push(child);
6238
+ }
6239
+ }
6199
6240
  }
6200
6241
  }
6201
- const endTime = performance.now();
6202
- if (options.signal != null) {
6203
- options.signal.removeEventListener('abort', reject);
6242
+ }
6243
+ const endTime = performance.now();
6244
+ if (options.signal != null) {
6245
+ options.signal.removeEventListener('abort', reject);
6246
+ }
6247
+ stats.bytesIn += stats.importedBytesIn;
6248
+ return {
6249
+ ast,
6250
+ errors,
6251
+ stats: {
6252
+ ...stats,
6253
+ parse: `${(endParseTime - startTime).toFixed(2)}ms`,
6254
+ minify: `${(endTime - endParseTime).toFixed(2)}ms`,
6255
+ total: `${(endTime - startTime).toFixed(2)}ms`
6204
6256
  }
6205
- stats.bytesIn += stats.importedBytesIn;
6206
- resolve({
6207
- ast,
6208
- errors,
6209
- stats: {
6210
- ...stats,
6211
- parse: `${(endParseTime - startTime).toFixed(2)}ms`,
6212
- minify: `${(endTime - endParseTime).toFixed(2)}ms`,
6213
- total: `${(endTime - startTime).toFixed(2)}ms`
6214
- }
6215
- });
6216
- });
6257
+ };
6258
+ // });
6217
6259
  }
6218
6260
  async function parseNode(results, context, stats, options, errors, src, map) {
6219
- let tokens = results.map((t) => mapToken(t, map));
6261
+ let tokens = [];
6262
+ for (const t of results) {
6263
+ const node = getTokenType(t.token, t.hint);
6264
+ map.set(node, t.position);
6265
+ tokens.push(node);
6266
+ }
6220
6267
  let i;
6221
6268
  let loc;
6222
6269
  for (i = 0; i < tokens.length; i++) {
@@ -6340,6 +6387,7 @@
6340
6387
  const root = await options.load(url, options.src).then((src) => {
6341
6388
  return doParse(src, Object.assign({}, options, {
6342
6389
  minify: false,
6390
+ setParent: false,
6343
6391
  // @ts-ignore
6344
6392
  src: options.resolve(url, options.src).absolute
6345
6393
  }));
@@ -6373,7 +6421,7 @@
6373
6421
  nam: renderToken(atRule, { removeComments: true }),
6374
6422
  val: raw.join('')
6375
6423
  };
6376
- Object.defineProperty(node, 'raw', { enumerable: false, configurable: true, writable: true, value: raw });
6424
+ Object.defineProperty(node, 'raw', { ...definedPropertySettings, value: raw });
6377
6425
  if (delim.typ == exports.EnumToken.BlockStartTokenType) {
6378
6426
  node.chi = [];
6379
6427
  }
@@ -6499,11 +6547,6 @@
6499
6547
  }
6500
6548
  }
6501
6549
  }
6502
- function mapToken(token, map) {
6503
- const node = getTokenType(token.token, token.hint);
6504
- map.set(node, token.position);
6505
- return node;
6506
- }
6507
6550
  function parseString(src, options = { location: false }) {
6508
6551
  return parseTokens([...tokenize(src)].map(t => {
6509
6552
  const token = getTokenType(t.token, t.hint);
@@ -6518,13 +6561,7 @@
6518
6561
  throw new Error('empty string?');
6519
6562
  }
6520
6563
  if (hint != null) {
6521
- return ([
6522
- exports.EnumToken.WhitespaceTokenType, exports.EnumToken.SemiColonTokenType, exports.EnumToken.ColonTokenType, exports.EnumToken.BlockStartTokenType,
6523
- exports.EnumToken.BlockStartTokenType, exports.EnumToken.AttrStartTokenType, exports.EnumToken.AttrEndTokenType, exports.EnumToken.StartParensTokenType, exports.EnumToken.EndParensTokenType,
6524
- exports.EnumToken.CommaTokenType, exports.EnumToken.GtTokenType, exports.EnumToken.LtTokenType, exports.EnumToken.GteTokenType, exports.EnumToken.LteTokenType, exports.EnumToken.CommaTokenType,
6525
- exports.EnumToken.StartMatchTokenType, exports.EnumToken.EndMatchTokenType, exports.EnumToken.IncludeMatchTokenType, exports.EnumToken.DashMatchTokenType, exports.EnumToken.ContainMatchTokenType,
6526
- exports.EnumToken.EOFTokenType
6527
- ].includes(hint) ? { typ: hint } : { typ: hint, val });
6564
+ return enumTokenHints.has(hint) ? { typ: hint } : { typ: hint, val };
6528
6565
  }
6529
6566
  if (val == ' ') {
6530
6567
  return { typ: exports.EnumToken.WhitespaceTokenType };
@@ -6643,10 +6680,10 @@
6643
6680
  return parseDimension(val);
6644
6681
  }
6645
6682
  const v = val.toLowerCase();
6646
- if (v == 'currentcolor' || val == 'transparent' || v in COLORS_NAMES) {
6683
+ if (v == 'currentcolor' || v == 'transparent' || v in COLORS_NAMES) {
6647
6684
  return {
6648
6685
  typ: exports.EnumToken.ColorTokenType,
6649
- val,
6686
+ val: v,
6650
6687
  kin: 'lit'
6651
6688
  };
6652
6689
  }
@@ -6996,12 +7033,47 @@
6996
7033
  return tokens;
6997
7034
  }
6998
7035
 
7036
+ function eq(a, b) {
7037
+ if (a == null || b == null) {
7038
+ return a == b;
7039
+ }
7040
+ if (typeof a != 'object' || typeof b != 'object') {
7041
+ return a === b;
7042
+ }
7043
+ if (a.constructor != b.constructor) {
7044
+ return false;
7045
+ }
7046
+ if (Array.isArray(a)) {
7047
+ if (a.length != b.length) {
7048
+ return false;
7049
+ }
7050
+ let i = 0;
7051
+ for (; i < a.length; i++) {
7052
+ if (!eq(a[i], b[i])) {
7053
+ return false;
7054
+ }
7055
+ }
7056
+ return true;
7057
+ }
7058
+ const k1 = Object.keys(a);
7059
+ const k2 = Object.keys(b);
7060
+ if (k1.length != k2.length) {
7061
+ return false;
7062
+ }
7063
+ let key;
7064
+ for (key of k1) {
7065
+ if (!(key in b) || !eq(a[key], b[key])) {
7066
+ return false;
7067
+ }
7068
+ }
7069
+ return true;
7070
+ }
7071
+
6999
7072
  function* walk(node, filter) {
7000
7073
  const parents = [node];
7001
7074
  const root = node;
7002
- const weakMap = new WeakMap;
7003
- while (parents.length > 0) {
7004
- node = parents.shift();
7075
+ const map = new Map;
7076
+ while ((node = parents.shift())) {
7005
7077
  let option = null;
7006
7078
  if (filter != null) {
7007
7079
  option = filter(node);
@@ -7015,22 +7087,21 @@
7015
7087
  // @ts-ignore
7016
7088
  if (option !== 'children') {
7017
7089
  // @ts-ignore
7018
- yield { node, parent: weakMap.get(node), root };
7090
+ yield { node, parent: map.get(node), root };
7019
7091
  }
7020
7092
  if (option !== 'ignore-children' && 'chi' in node) {
7021
7093
  parents.unshift(...node.chi);
7022
7094
  for (const child of node.chi.slice()) {
7023
- weakMap.set(child, node);
7095
+ map.set(child, node);
7024
7096
  }
7025
7097
  }
7026
7098
  }
7027
7099
  }
7028
7100
  function* walkValues(values, root = null, filter) {
7029
7101
  const stack = values.slice();
7030
- const weakMap = new WeakMap;
7102
+ const map = new Map;
7031
7103
  let value;
7032
- while (stack.length > 0) {
7033
- value = stack.shift();
7104
+ while ((value = stack.shift())) {
7034
7105
  let option = null;
7035
7106
  if (filter != null) {
7036
7107
  option = filter(value);
@@ -7044,17 +7115,17 @@
7044
7115
  // @ts-ignore
7045
7116
  if (option !== 'children') {
7046
7117
  // @ts-ignore
7047
- yield { value, parent: weakMap.get(value), root };
7118
+ yield { value, parent: map.get(value), root };
7048
7119
  }
7049
7120
  if (option !== 'ignore-children' && 'chi' in value) {
7050
7121
  for (const child of value.chi.slice()) {
7051
- weakMap.set(child, value);
7122
+ map.set(child, value);
7052
7123
  }
7053
7124
  stack.unshift(...value.chi);
7054
7125
  }
7055
7126
  else if (value.typ == exports.EnumToken.BinaryExpressionTokenType) {
7056
- weakMap.set(value.l, value);
7057
- weakMap.set(value.r, value);
7127
+ map.set(value.l, value);
7128
+ map.set(value.r, value);
7058
7129
  stack.unshift(value.l, value.r);
7059
7130
  }
7060
7131
  }
@@ -7205,61 +7276,6 @@
7205
7276
  }).reduce((acc, curr) => acc + (curr == '&' ? replace : curr), '');
7206
7277
  }
7207
7278
 
7208
- class MinifyFeature {
7209
- static get ordering() {
7210
- return 10000;
7211
- }
7212
- register(options) {
7213
- }
7214
- }
7215
-
7216
- class IterableWeakSet {
7217
- #weakset = new WeakSet;
7218
- #set = new Set;
7219
- constructor(iterable) {
7220
- if (iterable) {
7221
- for (const value of iterable) {
7222
- const ref = new WeakRef(value);
7223
- this.#weakset.add(value);
7224
- this.#set.add(ref);
7225
- }
7226
- }
7227
- }
7228
- has(value) {
7229
- return this.#weakset.has(value);
7230
- }
7231
- delete(value) {
7232
- if (this.#weakset.has(value)) {
7233
- for (const ref of this.#set) {
7234
- if (ref.deref() === value) {
7235
- this.#set.delete(ref);
7236
- break;
7237
- }
7238
- }
7239
- return this.#weakset.delete(value);
7240
- }
7241
- return false;
7242
- }
7243
- add(value) {
7244
- if (!this.#weakset.has(value)) {
7245
- this.#weakset.add(value);
7246
- this.#set.add(new WeakRef(value));
7247
- }
7248
- return this;
7249
- }
7250
- *[Symbol.iterator]() {
7251
- for (const ref of new Set(this.#set)) {
7252
- const key = ref.deref();
7253
- if (key != null) {
7254
- yield key;
7255
- }
7256
- else {
7257
- this.#set.delete(ref);
7258
- }
7259
- }
7260
- }
7261
- }
7262
-
7263
7279
  function replace(node, variableScope) {
7264
7280
  for (const { value, parent: parentValue } of walkValues(node.val)) {
7265
7281
  if (value?.typ == exports.EnumToken.FunctionTokenType && value.val == 'var') {
@@ -7283,7 +7299,7 @@
7283
7299
  }
7284
7300
  }
7285
7301
  }
7286
- class InlineCssVariablesFeature extends MinifyFeature {
7302
+ class InlineCssVariablesFeature {
7287
7303
  static get ordering() {
7288
7304
  return 0;
7289
7305
  }
@@ -7318,7 +7334,7 @@
7318
7334
  const info = {
7319
7335
  globalScope: isRoot,
7320
7336
  // @ts-ignore
7321
- parent: new IterableWeakSet(),
7337
+ parent: new Set(),
7322
7338
  declarationCount: 1,
7323
7339
  replaceable: isRoot,
7324
7340
  node: node
@@ -7356,6 +7372,9 @@
7356
7372
  }
7357
7373
  cleanup(ast, options = {}, context) {
7358
7374
  const variableScope = context.variableScope;
7375
+ if (variableScope == null) {
7376
+ return;
7377
+ }
7359
7378
  for (const info of variableScope.values()) {
7360
7379
  if (info.replaceable) {
7361
7380
  let i;
@@ -7446,6 +7465,7 @@
7446
7465
  }
7447
7466
  tokens[current].push(token);
7448
7467
  }
7468
+ // @ts-ignore
7449
7469
  if (token.typ == exports.EnumToken.LiteralTokenType && token.val == this.config.separator) {
7450
7470
  tokens.push([]);
7451
7471
  current++;
@@ -7549,6 +7569,7 @@
7549
7569
  }
7550
7570
  }
7551
7571
  if (acc.length > 0) {
7572
+ // @ts-ignore
7552
7573
  acc.push({ typ: exports.EnumToken.LiteralTokenType, val: this.config.separator });
7553
7574
  }
7554
7575
  acc.push(...curr);
@@ -7594,6 +7615,7 @@
7594
7615
  else {
7595
7616
  const separator = this.config.separator != null ? {
7596
7617
  ...this.config.separator,
7618
+ // @ts-ignore
7597
7619
  typ: exports.EnumToken[this.config.separator.typ]
7598
7620
  } : null;
7599
7621
  // expand shorthand
@@ -7603,7 +7625,7 @@
7603
7625
  // @ts-ignore
7604
7626
  this.declarations.get(this.config.shorthand).val.slice().reduce((acc, curr) => {
7605
7627
  // @ts-ignore
7606
- if (separator != null && separator.typ == curr.typ && eq(separator, curr)) {
7628
+ if (separator != null && separator.typ == curr.typ && separator.val == curr.val) {
7607
7629
  acc.push([]);
7608
7630
  return acc;
7609
7631
  }
@@ -7642,11 +7664,8 @@
7642
7664
  i--;
7643
7665
  // @ts-ignore
7644
7666
  if ('prefix' in props && acc[i]?.typ == exports.EnumToken[props.prefix.typ]) {
7645
- if (eq(acc[i], {
7646
- ...this.config.properties[property].prefix,
7647
- // @ts-ignore
7648
- typ: exports.EnumToken[props.prefix.typ]
7649
- })) {
7667
+ // @ts-ignore
7668
+ if (acc[i].typ == exports.EnumToken[props.prefix.typ] && acc[i].val == this.config.properties[property].prefix.val) {
7650
7669
  acc.splice(i, 1);
7651
7670
  i--;
7652
7671
  }
@@ -7813,6 +7832,7 @@
7813
7832
  let values = [];
7814
7833
  // @ts-ignore
7815
7834
  let typ = (exports.EnumToken[this.config.separator?.typ] ?? exports.EnumToken.CommaTokenType);
7835
+ // @ts-ignore
7816
7836
  let separator = this.config.separator ? renderToken(this.config.separator) : ',';
7817
7837
  this.matchTypes(declaration);
7818
7838
  values.push(value);
@@ -7892,6 +7912,26 @@
7892
7912
  }
7893
7913
  return (filtered.length > 0 ? filtered : values)[Symbol.iterator]();
7894
7914
  }
7915
+ for (const declaration of this.declarations.values()) {
7916
+ if (declaration instanceof PropertySet) {
7917
+ continue;
7918
+ }
7919
+ const config = declaration.nam == this.config.shorthand ? this.config : this.config.properties[declaration.nam] ?? this.config;
7920
+ if (!('mapping' in config)) {
7921
+ continue;
7922
+ }
7923
+ // @ts-ignore
7924
+ for (const [key, val] of Object.entries(config.mapping)) {
7925
+ const keys = parseString(key);
7926
+ if (keys.length != declaration.val.length) {
7927
+ continue;
7928
+ }
7929
+ if (eq(declaration.val, keys)) {
7930
+ declaration.val = parseString(val);
7931
+ break;
7932
+ }
7933
+ }
7934
+ }
7895
7935
  // @ts-ignore
7896
7936
  iterable = this.declarations.values();
7897
7937
  }
@@ -7900,6 +7940,7 @@
7900
7940
  let match;
7901
7941
  const separator = this.config.separator != null ? {
7902
7942
  ...this.config.separator,
7943
+ // @ts-ignore
7903
7944
  typ: exports.EnumToken[this.config.separator.typ]
7904
7945
  } : null;
7905
7946
  const tokens = {};
@@ -7917,7 +7958,8 @@
7917
7958
  for (const declaration of [(properties instanceof PropertySet ? [...properties][0] : properties)]) {
7918
7959
  // @ts-ignore
7919
7960
  for (const val of declaration.val) {
7920
- if (separator != null && separator.typ == val.typ && eq(separator, val)) {
7961
+ // @ts-ignore
7962
+ if (separator != null && separator.typ == val.typ && separator.val == val.val) {
7921
7963
  current++;
7922
7964
  if (tokens[curr[0]].length == current) {
7923
7965
  tokens[curr[0]].push([]);
@@ -7928,10 +7970,11 @@
7928
7970
  continue;
7929
7971
  }
7930
7972
  // @ts-ignore
7931
- if (props.multiple && props.separator != null && exports.EnumToken[props.separator.typ] == val.typ && eq({
7932
- ...props.separator,
7933
- typ: exports.EnumToken[props.separator.typ]
7934
- }, val)) {
7973
+ if (props.multiple && props.separator != null &&
7974
+ // @ts-ignore
7975
+ exports.EnumToken[props.separator.typ] == val.typ &&
7976
+ // @ts-ignore
7977
+ props.separator.val == val.val) {
7935
7978
  continue;
7936
7979
  }
7937
7980
  // @ts-ignore
@@ -8036,6 +8079,7 @@
8036
8079
  acc.push({
8037
8080
  ...((props.separator && {
8038
8081
  ...props.separator,
8082
+ // @ts-ignore
8039
8083
  typ: exports.EnumToken[props.separator.typ]
8040
8084
  }) ?? { typ: exports.EnumToken.WhitespaceTokenType })
8041
8085
  });
@@ -8136,6 +8180,7 @@
8136
8180
  if (value[index].typ == exports.EnumToken.WhitespaceTokenType) {
8137
8181
  continue;
8138
8182
  }
8183
+ // @ts-ignore@
8139
8184
  if (value[index].typ == exports.EnumToken[config.prefix.typ] &&
8140
8185
  // @ts-ignore
8141
8186
  value[index].val == config.prefix.val) {
@@ -8156,12 +8201,7 @@
8156
8201
  options = { removeDuplicateDeclarations: true, computeShorthand: true };
8157
8202
  declarations;
8158
8203
  constructor(options = {}) {
8159
- for (const key of Object.keys(this.options)) {
8160
- if (key in options) {
8161
- // @ts-ignore
8162
- this.options[key] = options[key];
8163
- }
8164
- }
8204
+ this.options = options;
8165
8205
  this.declarations = new Map;
8166
8206
  }
8167
8207
  set(nam, value) {
@@ -8255,7 +8295,7 @@
8255
8295
  }
8256
8296
  }
8257
8297
 
8258
- class ComputeShorthandFeature extends MinifyFeature {
8298
+ class ComputeShorthandFeature {
8259
8299
  static get ordering() {
8260
8300
  return 2;
8261
8301
  }
@@ -8267,7 +8307,7 @@
8267
8307
  }
8268
8308
  }
8269
8309
  // @ts-ignore
8270
- options.features.push(new ComputeShorthandFeature());
8310
+ options.features.push(new ComputeShorthandFeature(options));
8271
8311
  }
8272
8312
  }
8273
8313
  run(ast, options = {}, parent, context) {
@@ -8291,7 +8331,7 @@
8291
8331
  }
8292
8332
  }
8293
8333
 
8294
- class ComputeCalcExpressionFeature extends MinifyFeature {
8334
+ class ComputeCalcExpressionFeature {
8295
8335
  static get ordering() {
8296
8336
  return 1;
8297
8337
  }
@@ -8315,7 +8355,7 @@
8315
8355
  if (node.typ != exports.EnumToken.DeclarationNodeType) {
8316
8356
  continue;
8317
8357
  }
8318
- const set = new IterableWeakSet;
8358
+ const set = new Set;
8319
8359
  for (const { value, parent } of walkValues(node.val)) {
8320
8360
  if (value != null && value.typ == exports.EnumToken.FunctionTokenType && value.val == 'calc') {
8321
8361
  if (!set.has(parent)) {
@@ -8356,8 +8396,8 @@
8356
8396
  });
8357
8397
 
8358
8398
  const combinators = ['+', '>', '~', '||'];
8359
- const notEndingWith = ['(', '['].concat(combinators);
8360
8399
  const definedPropertySettings = { configurable: true, enumerable: false, writable: true };
8400
+ const notEndingWith = ['(', '['].concat(combinators);
8361
8401
  // @ts-ignore
8362
8402
  const features = Object.values(allFeatures).sort((a, b) => a.ordering - b.ordering);
8363
8403
  function minify(ast, options = {}, recursive = false, errors, nestingContent, context = {}) {
@@ -9353,8 +9393,10 @@
9353
9393
  if (matchUrl.test(currentFile)) {
9354
9394
  return fetch(new URL(url, currentFile)).then(parseResponse);
9355
9395
  }
9396
+ const path = resolve(url, currentFile).absolute;
9397
+ const t = new URL(path, self.origin);
9356
9398
  // return fetch(new URL(url, new URL(currentFile, self.location.href).href)).then(parseResponse);
9357
- return fetch(resolve(url, currentFile).absolute).then(parseResponse);
9399
+ return fetch(url, t.origin != self.location.origin ? { mode: 'cors' } : {}).then(parseResponse);
9358
9400
  }
9359
9401
 
9360
9402
  function render(data, options = {}) {