vite 6.0.0-beta.8 → 6.0.0-beta.9

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.
@@ -1,4 +1,4 @@
1
- import { M as commonjsGlobal, L as getDefaultExportFromCjs } from './dep-Ddvoc4zx.js';
1
+ import { M as commonjsGlobal, L as getDefaultExportFromCjs } from './dep-CG5ueZZV.js';
2
2
  import require$$0$1 from 'fs';
3
3
  import require$$0 from 'postcss';
4
4
  import sysPath__default from 'path';
@@ -1432,54 +1432,63 @@ function requireSrc$3 () {
1432
1432
  });
1433
1433
 
1434
1434
  root.walkDecls(/^composes$/, (declaration) => {
1435
- const matches = declaration.value.match(matchImports);
1435
+ const multiple = declaration.value.split(",");
1436
+ const values = [];
1436
1437
 
1437
- if (!matches) {
1438
- return;
1439
- }
1438
+ multiple.forEach((value) => {
1439
+ const matches = value.trim().match(matchImports);
1440
1440
 
1441
- let tmpSymbols;
1442
- let [
1443
- ,
1444
- /*match*/ symbols,
1445
- doubleQuotePath,
1446
- singleQuotePath,
1447
- global,
1448
- ] = matches;
1449
-
1450
- if (global) {
1451
- // Composing globals simply means changing these classes to wrap them in global(name)
1452
- tmpSymbols = symbols.split(/\s+/).map((s) => `global(${s})`);
1453
- } else {
1454
- const importPath = doubleQuotePath || singleQuotePath;
1441
+ if (!matches) {
1442
+ values.push(value);
1455
1443
 
1456
- let parent = declaration.parent;
1457
- let parentIndexes = "";
1458
-
1459
- while (parent.type !== "root") {
1460
- parentIndexes =
1461
- parent.parent.index(parent) + "_" + parentIndexes;
1462
- parent = parent.parent;
1444
+ return;
1463
1445
  }
1464
1446
 
1465
- const { selector } = declaration.parent;
1466
- const parentRule = `_${parentIndexes}${selector}`;
1467
-
1468
- addImportToGraph(importPath, parentRule, graph, visited);
1447
+ let tmpSymbols;
1448
+ let [
1449
+ ,
1450
+ /*match*/ symbols,
1451
+ doubleQuotePath,
1452
+ singleQuotePath,
1453
+ global,
1454
+ ] = matches;
1455
+
1456
+ if (global) {
1457
+ // Composing globals simply means changing these classes to wrap them in global(name)
1458
+ tmpSymbols = symbols.split(/\s+/).map((s) => `global(${s})`);
1459
+ } else {
1460
+ const importPath = doubleQuotePath || singleQuotePath;
1469
1461
 
1470
- importDecls[importPath] = declaration;
1471
- imports[importPath] = imports[importPath] || {};
1462
+ let parent = declaration.parent;
1463
+ let parentIndexes = "";
1472
1464
 
1473
- tmpSymbols = symbols.split(/\s+/).map((s) => {
1474
- if (!imports[importPath][s]) {
1475
- imports[importPath][s] = createImportedName(s, importPath);
1465
+ while (parent.type !== "root") {
1466
+ parentIndexes =
1467
+ parent.parent.index(parent) + "_" + parentIndexes;
1468
+ parent = parent.parent;
1476
1469
  }
1477
1470
 
1478
- return imports[importPath][s];
1479
- });
1480
- }
1471
+ const { selector } = declaration.parent;
1472
+ const parentRule = `_${parentIndexes}${selector}`;
1473
+
1474
+ addImportToGraph(importPath, parentRule, graph, visited);
1475
+
1476
+ importDecls[importPath] = declaration;
1477
+ imports[importPath] = imports[importPath] || {};
1481
1478
 
1482
- declaration.value = tmpSymbols.join(" ");
1479
+ tmpSymbols = symbols.split(/\s+/).map((s) => {
1480
+ if (!imports[importPath][s]) {
1481
+ imports[importPath][s] = createImportedName(s, importPath);
1482
+ }
1483
+
1484
+ return imports[importPath][s];
1485
+ });
1486
+ }
1487
+
1488
+ values.push(tmpSymbols.join(" "));
1489
+ });
1490
+
1491
+ declaration.value = values.join(", ");
1483
1492
  });
1484
1493
 
1485
1494
  const importsOrder = topologicalSort(graph, failOnWrongOrder);
@@ -6093,9 +6102,19 @@ function requireSrc$2 () {
6093
6102
  hasLocals: false,
6094
6103
  explicit: context.explicit,
6095
6104
  };
6096
- newNodes = node.map((childNode) =>
6097
- transform(childNode, childContext)
6098
- );
6105
+ newNodes = node.map((childNode) => {
6106
+ const newContext = {
6107
+ ...childContext,
6108
+ enforceNoSpacing: false,
6109
+ };
6110
+
6111
+ const result = transform(childNode, newContext);
6112
+
6113
+ childContext.global = newContext.global;
6114
+ childContext.hasLocals = newContext.hasLocals;
6115
+
6116
+ return result;
6117
+ });
6099
6118
 
6100
6119
  node = node.clone();
6101
6120
  node.nodes = normalizeNodeArray(newNodes);
@@ -6164,6 +6183,11 @@ function requireSrc$2 () {
6164
6183
 
6165
6184
  break;
6166
6185
  }
6186
+ case "nesting": {
6187
+ if (node.value === "&") {
6188
+ context.hasLocals = true;
6189
+ }
6190
+ }
6167
6191
  }
6168
6192
 
6169
6193
  context.lastWasSpacing = false;
@@ -6236,19 +6260,34 @@ function requireSrc$2 () {
6236
6260
  return node;
6237
6261
  }
6238
6262
 
6239
- function isWordAFunctionArgument(wordNode, functionNode) {
6240
- return functionNode
6241
- ? functionNode.nodes.some(
6242
- (functionNodeChild) =>
6243
- functionNodeChild.sourceIndex === wordNode.sourceIndex
6244
- )
6245
- : false;
6246
- }
6263
+ // `none` is special value, other is global values
6264
+ const specialKeywords = [
6265
+ "none",
6266
+ "inherit",
6267
+ "initial",
6268
+ "revert",
6269
+ "revert-layer",
6270
+ "unset",
6271
+ ];
6247
6272
 
6248
6273
  function localizeDeclarationValues(localize, declaration, context) {
6249
6274
  const valueNodes = valueParser(declaration.value);
6250
6275
 
6251
6276
  valueNodes.walk((node, index, nodes) => {
6277
+ if (
6278
+ node.type === "function" &&
6279
+ (node.value.toLowerCase() === "var" || node.value.toLowerCase() === "env")
6280
+ ) {
6281
+ return false;
6282
+ }
6283
+
6284
+ if (
6285
+ node.type === "word" &&
6286
+ specialKeywords.includes(node.value.toLowerCase())
6287
+ ) {
6288
+ return;
6289
+ }
6290
+
6252
6291
  const subContext = {
6253
6292
  options: context.options,
6254
6293
  global: context.global,
@@ -6265,57 +6304,80 @@ function requireSrc$2 () {
6265
6304
  const isAnimation = /animation$/i.test(declaration.prop);
6266
6305
 
6267
6306
  if (isAnimation) {
6268
- const validIdent = /^-?[_a-z][_a-z0-9-]*$/i;
6307
+ // letter
6308
+ // An uppercase letter or a lowercase letter.
6309
+ //
6310
+ // ident-start code point
6311
+ // A letter, a non-ASCII code point, or U+005F LOW LINE (_).
6312
+ //
6313
+ // ident code point
6314
+ // An ident-start code point, a digit, or U+002D HYPHEN-MINUS (-).
6315
+
6316
+ // We don't validate `hex digits`, because we don't need it, it is work of linters.
6317
+ const validIdent =
6318
+ /^-?([a-z\u0080-\uFFFF_]|(\\[^\r\n\f])|-(?![0-9]))((\\[^\r\n\f])|[a-z\u0080-\uFFFF_0-9-])*$/i;
6269
6319
 
6270
6320
  /*
6271
6321
  The spec defines some keywords that you can use to describe properties such as the timing
6272
6322
  function. These are still valid animation names, so as long as there is a property that accepts
6273
6323
  a keyword, it is given priority. Only when all the properties that can take a keyword are
6274
6324
  exhausted can the animation name be set to the keyword. I.e.
6275
-
6325
+
6276
6326
  animation: infinite infinite;
6277
-
6327
+
6278
6328
  The animation will repeat an infinite number of times from the first argument, and will have an
6279
6329
  animation name of infinite from the second.
6280
6330
  */
6281
6331
  const animationKeywords = {
6332
+ // animation-direction
6333
+ $normal: 1,
6334
+ $reverse: 1,
6282
6335
  $alternate: 1,
6283
6336
  "$alternate-reverse": 1,
6337
+ // animation-fill-mode
6338
+ $forwards: 1,
6284
6339
  $backwards: 1,
6285
6340
  $both: 1,
6341
+ // animation-iteration-count
6342
+ $infinite: 1,
6343
+ // animation-play-state
6344
+ $paused: 1,
6345
+ $running: 1,
6346
+ // animation-timing-function
6286
6347
  $ease: 1,
6287
6348
  "$ease-in": 1,
6288
- "$ease-in-out": 1,
6289
6349
  "$ease-out": 1,
6290
- $forwards: 1,
6291
- $infinite: 1,
6350
+ "$ease-in-out": 1,
6292
6351
  $linear: 1,
6293
- $none: Infinity, // No matter how many times you write none, it will never be an animation name
6294
- $normal: 1,
6295
- $paused: 1,
6296
- $reverse: 1,
6297
- $running: 1,
6298
6352
  "$step-end": 1,
6299
6353
  "$step-start": 1,
6354
+ // Special
6355
+ $none: Infinity, // No matter how many times you write none, it will never be an animation name
6356
+ // Global values
6300
6357
  $initial: Infinity,
6301
6358
  $inherit: Infinity,
6302
6359
  $unset: Infinity,
6360
+ $revert: Infinity,
6361
+ "$revert-layer": Infinity,
6303
6362
  };
6304
6363
  let parsedAnimationKeywords = {};
6305
- let stepsFunctionNode = null;
6306
6364
  const valueNodes = valueParser(declaration.value).walk((node) => {
6307
- /* If div-token appeared (represents as comma ','), a possibility of an animation-keywords should be reflesh. */
6365
+ // If div-token appeared (represents as comma ','), a possibility of an animation-keywords should be reflesh.
6308
6366
  if (node.type === "div") {
6309
6367
  parsedAnimationKeywords = {};
6368
+
6369
+ return;
6370
+ }
6371
+ // Do not handle nested functions
6372
+ else if (node.type === "function") {
6373
+ return false;
6310
6374
  }
6311
- if (node.type === "function" && node.value.toLowerCase() === "steps") {
6312
- stepsFunctionNode = node;
6375
+ // Ignore all except word
6376
+ else if (node.type !== "word") {
6377
+ return;
6313
6378
  }
6314
- const value =
6315
- node.type === "word" &&
6316
- !isWordAFunctionArgument(node, stepsFunctionNode)
6317
- ? node.value.toLowerCase()
6318
- : null;
6379
+
6380
+ const value = node.type === "word" ? node.value.toLowerCase() : null;
6319
6381
 
6320
6382
  let shouldParseAnimationName = false;
6321
6383
 
@@ -6340,6 +6402,7 @@ function requireSrc$2 () {
6340
6402
  localizeNextItem: shouldParseAnimationName && !context.global,
6341
6403
  localAliasMap: context.localAliasMap,
6342
6404
  };
6405
+
6343
6406
  return localizeDeclNode(node, subContext);
6344
6407
  });
6345
6408
 
@@ -6414,10 +6477,12 @@ function requireSrc$2 () {
6414
6477
  } else if (localMatch) {
6415
6478
  atRule.params = localMatch[0];
6416
6479
  globalKeyframes = false;
6417
- } else if (!globalMode) {
6418
- if (atRule.params && !localAliasMap.has(atRule.params)) {
6419
- atRule.params = ":local(" + atRule.params + ")";
6420
- }
6480
+ } else if (
6481
+ atRule.params &&
6482
+ !globalMode &&
6483
+ !localAliasMap.has(atRule.params)
6484
+ ) {
6485
+ atRule.params = ":local(" + atRule.params + ")";
6421
6486
  }
6422
6487
 
6423
6488
  atRule.walkDecls((declaration) => {
@@ -6427,6 +6492,44 @@ function requireSrc$2 () {
6427
6492
  global: globalKeyframes,
6428
6493
  });
6429
6494
  });
6495
+ } else if (/scope$/i.test(atRule.name)) {
6496
+ if (atRule.params) {
6497
+ atRule.params = atRule.params
6498
+ .split("to")
6499
+ .map((item) => {
6500
+ const selector = item.trim().slice(1, -1).trim();
6501
+ const context = localizeNode(
6502
+ selector,
6503
+ options.mode,
6504
+ localAliasMap
6505
+ );
6506
+
6507
+ context.options = options;
6508
+ context.localAliasMap = localAliasMap;
6509
+
6510
+ if (pureMode && context.hasPureGlobals) {
6511
+ throw atRule.error(
6512
+ 'Selector in at-rule"' +
6513
+ selector +
6514
+ '" is not pure ' +
6515
+ "(pure selectors must contain at least one local class or id)"
6516
+ );
6517
+ }
6518
+
6519
+ return `(${context.selector})`;
6520
+ })
6521
+ .join(" to ");
6522
+ }
6523
+
6524
+ atRule.nodes.forEach((declaration) => {
6525
+ if (declaration.type === "decl") {
6526
+ localizeDeclaration(declaration, {
6527
+ localAliasMap,
6528
+ options: options,
6529
+ global: globalMode,
6530
+ });
6531
+ }
6532
+ });
6430
6533
  } else if (atRule.nodes) {
6431
6534
  atRule.nodes.forEach((declaration) => {
6432
6535
  if (declaration.type === "decl") {
@@ -6493,7 +6596,23 @@ function requireSrc$1 () {
6493
6596
 
6494
6597
  const hasOwnProperty = Object.prototype.hasOwnProperty;
6495
6598
 
6496
- function getSingleLocalNamesForComposes(root) {
6599
+ function isNestedRule(rule) {
6600
+ if (!rule.parent || rule.parent.type === "root") {
6601
+ return false;
6602
+ }
6603
+
6604
+ if (rule.parent.type === "rule") {
6605
+ return true;
6606
+ }
6607
+
6608
+ return isNestedRule(rule.parent);
6609
+ }
6610
+
6611
+ function getSingleLocalNamesForComposes(root, rule) {
6612
+ if (isNestedRule(rule)) {
6613
+ throw new Error(`composition is not allowed in nested rule \n\n${rule}`);
6614
+ }
6615
+
6497
6616
  return root.nodes.map((node) => {
6498
6617
  if (node.type !== "selector" || node.nodes.length !== 1) {
6499
6618
  throw new Error(
@@ -6580,17 +6699,19 @@ function requireSrc$1 () {
6580
6699
  Once(root, { rule }) {
6581
6700
  const exports = Object.create(null);
6582
6701
 
6583
- function exportScopedName(name, rawName) {
6702
+ function exportScopedName(name, rawName, node) {
6584
6703
  const scopedName = generateScopedName(
6585
6704
  rawName ? rawName : name,
6586
6705
  root.source.input.from,
6587
- root.source.input.css
6706
+ root.source.input.css,
6707
+ node
6588
6708
  );
6589
6709
  const exportEntry = generateExportEntry(
6590
6710
  rawName ? rawName : name,
6591
6711
  scopedName,
6592
6712
  root.source.input.from,
6593
- root.source.input.css
6713
+ root.source.input.css,
6714
+ node
6594
6715
  );
6595
6716
  const { key, value } = exportEntry;
6596
6717
 
@@ -6606,23 +6727,35 @@ function requireSrc$1 () {
6606
6727
  function localizeNode(node) {
6607
6728
  switch (node.type) {
6608
6729
  case "selector":
6609
- node.nodes = node.map(localizeNode);
6730
+ node.nodes = node.map((item) => localizeNode(item));
6610
6731
  return node;
6611
6732
  case "class":
6612
6733
  return selectorParser.className({
6613
6734
  value: exportScopedName(
6614
6735
  node.value,
6615
- node.raws && node.raws.value ? node.raws.value : null
6736
+ node.raws && node.raws.value ? node.raws.value : null,
6737
+ node
6616
6738
  ),
6617
6739
  });
6618
6740
  case "id": {
6619
6741
  return selectorParser.id({
6620
6742
  value: exportScopedName(
6621
6743
  node.value,
6622
- node.raws && node.raws.value ? node.raws.value : null
6744
+ node.raws && node.raws.value ? node.raws.value : null,
6745
+ node
6623
6746
  ),
6624
6747
  });
6625
6748
  }
6749
+ case "attribute": {
6750
+ if (node.attribute === "class" && node.operator === "=") {
6751
+ return selectorParser.attribute({
6752
+ attribute: node.attribute,
6753
+ operator: node.operator,
6754
+ quoteMark: "'",
6755
+ value: exportScopedName(node.value, null, null),
6756
+ });
6757
+ }
6758
+ }
6626
6759
  }
6627
6760
 
6628
6761
  throw new Error(
@@ -6639,7 +6772,7 @@ function requireSrc$1 () {
6639
6772
  }
6640
6773
 
6641
6774
  const selector = localizeNode(node.first);
6642
- // move the spaces that were around the psuedo selector to the first
6775
+ // move the spaces that were around the pseudo selector to the first
6643
6776
  // non-container node
6644
6777
  selector.first.spaces = node.spaces;
6645
6778
 
@@ -6661,7 +6794,7 @@ function requireSrc$1 () {
6661
6794
  /* falls through */
6662
6795
  case "root":
6663
6796
  case "selector": {
6664
- node.each(traverseNode);
6797
+ node.each((item) => traverseNode(item));
6665
6798
  break;
6666
6799
  }
6667
6800
  case "id":
@@ -6689,32 +6822,39 @@ function requireSrc$1 () {
6689
6822
 
6690
6823
  rule.selector = traverseNode(parsedSelector.clone()).toString();
6691
6824
 
6692
- rule.walkDecls(/composes|compose-with/i, (decl) => {
6693
- const localNames = getSingleLocalNamesForComposes(parsedSelector);
6694
- const classes = decl.value.split(/\s+/);
6825
+ rule.walkDecls(/^(composes|compose-with)$/i, (decl) => {
6826
+ const localNames = getSingleLocalNamesForComposes(
6827
+ parsedSelector,
6828
+ decl.parent
6829
+ );
6830
+ const multiple = decl.value.split(",");
6695
6831
 
6696
- classes.forEach((className) => {
6697
- const global = /^global\(([^)]+)\)$/.exec(className);
6832
+ multiple.forEach((value) => {
6833
+ const classes = value.trim().split(/\s+/);
6698
6834
 
6699
- if (global) {
6700
- localNames.forEach((exportedName) => {
6701
- exports[exportedName].push(global[1]);
6702
- });
6703
- } else if (hasOwnProperty.call(importedNames, className)) {
6704
- localNames.forEach((exportedName) => {
6705
- exports[exportedName].push(className);
6706
- });
6707
- } else if (hasOwnProperty.call(exports, className)) {
6708
- localNames.forEach((exportedName) => {
6709
- exports[className].forEach((item) => {
6710
- exports[exportedName].push(item);
6835
+ classes.forEach((className) => {
6836
+ const global = /^global\(([^)]+)\)$/.exec(className);
6837
+
6838
+ if (global) {
6839
+ localNames.forEach((exportedName) => {
6840
+ exports[exportedName].push(global[1]);
6711
6841
  });
6712
- });
6713
- } else {
6714
- throw decl.error(
6715
- `referenced class name "${className}" in ${decl.prop} not found`
6716
- );
6717
- }
6842
+ } else if (hasOwnProperty.call(importedNames, className)) {
6843
+ localNames.forEach((exportedName) => {
6844
+ exports[exportedName].push(className);
6845
+ });
6846
+ } else if (hasOwnProperty.call(exports, className)) {
6847
+ localNames.forEach((exportedName) => {
6848
+ exports[className].forEach((item) => {
6849
+ exports[exportedName].push(item);
6850
+ });
6851
+ });
6852
+ } else {
6853
+ throw decl.error(
6854
+ `referenced class name "${className}" in ${decl.prop} not found`
6855
+ );
6856
+ }
6857
+ });
6718
6858
  });
6719
6859
 
6720
6860
  decl.remove();
@@ -6766,6 +6906,27 @@ function requireSrc$1 () {
6766
6906
  atRule.params = exportScopedName(localMatch[1]);
6767
6907
  });
6768
6908
 
6909
+ root.walkAtRules(/scope$/i, (atRule) => {
6910
+ if (atRule.params) {
6911
+ atRule.params = atRule.params
6912
+ .split("to")
6913
+ .map((item) => {
6914
+ const selector = item.trim().slice(1, -1).trim();
6915
+
6916
+ const localMatch = /^\s*:local\s*\((.+?)\)\s*$/.exec(selector);
6917
+
6918
+ if (!localMatch) {
6919
+ return `(${selector})`;
6920
+ }
6921
+
6922
+ let parsedSelector = selectorParser().astSync(selector);
6923
+
6924
+ return `(${traverseNode(parsedSelector).toString()})`;
6925
+ })
6926
+ .join(" to ");
6927
+ }
6928
+ });
6929
+
6769
6930
  // If we found any :locals, insert an :export rule
6770
6931
  const exportedNames = Object.keys(exports);
6771
6932