@plumeria/turbopack-loader 6.3.1 → 6.3.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 (2) hide show
  1. package/dist/index.js +75 -33
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -785,30 +785,44 @@ async function loader(source) {
785
785
  }
786
786
  else {
787
787
  const table = {};
788
- const combinations = 1 << conditionals.length;
789
- for (let i = 0; i < combinations; i++) {
788
+ const groups = {};
789
+ let strayIdCounter = groupIdCounter + 1;
790
+ conditionals.forEach((c) => {
791
+ const gid = c.groupId !== undefined ? c.groupId : strayIdCounter++;
792
+ if (!groups[gid]) {
793
+ groups[gid] = [];
794
+ }
795
+ groups[gid].push(c);
796
+ });
797
+ const sortedGroupIds = Object.keys(groups)
798
+ .map(Number)
799
+ .sort((a, b) => a - b);
800
+ let totalCombinations = 1;
801
+ const groupMeta = sortedGroupIds.map((gid) => {
802
+ const options = groups[gid];
803
+ const isVariantGroup = options[0].groupId !== undefined;
804
+ const size = isVariantGroup ? options.length : 2;
805
+ const stride = totalCombinations;
806
+ totalCombinations *= size;
807
+ return { gid, options, size, stride, isVariantGroup };
808
+ });
809
+ for (let i = 0; i < totalCombinations; i++) {
790
810
  let currentStyle = { ...baseStyle };
791
- const seenGroups = new Set();
792
- let impossible = false;
793
- for (let j = 0; j < conditionals.length; j++) {
794
- if ((i >> j) & 1) {
795
- if (conditionals[j].groupId !== undefined) {
796
- if (seenGroups.has(conditionals[j].groupId)) {
797
- impossible = true;
798
- break;
799
- }
800
- seenGroups.add(conditionals[j].groupId);
801
- }
802
- currentStyle = (0, utils_1.deepMerge)(currentStyle, conditionals[j].truthy);
811
+ for (const meta of groupMeta) {
812
+ const localIndex = Math.floor(i / meta.stride) % meta.size;
813
+ if (meta.isVariantGroup) {
814
+ currentStyle = (0, utils_1.deepMerge)(currentStyle, meta.options[localIndex].truthy);
803
815
  }
804
816
  else {
805
- currentStyle = (0, utils_1.deepMerge)(currentStyle, conditionals[j].falsy);
817
+ const cond = meta.options[0];
818
+ if (localIndex === 1) {
819
+ currentStyle = (0, utils_1.deepMerge)(currentStyle, cond.truthy);
820
+ }
821
+ else {
822
+ currentStyle = (0, utils_1.deepMerge)(currentStyle, cond.falsy);
823
+ }
806
824
  }
807
825
  }
808
- if (impossible) {
809
- table[i] = '';
810
- continue;
811
- }
812
826
  if (process.env.NODE_ENV !== 'production') {
813
827
  (0, utils_1.extractOndemandStyles)(currentStyle, extractedSheets, scannedTables);
814
828
  }
@@ -822,22 +836,50 @@ async function loader(source) {
822
836
  .join(' ');
823
837
  table[i] = className;
824
838
  }
825
- let indexExpr = '';
826
- if (conditionals.length === 0) {
827
- indexExpr = '0';
828
- }
829
- else {
830
- const parts = conditionals.map((c, idx) => {
831
- if (c.testString) {
832
- return `(!!(${c.testString}) << ${idx})`;
839
+ const indexParts = [];
840
+ for (const meta of groupMeta) {
841
+ if (meta.isVariantGroup) {
842
+ const exprs = meta.options
843
+ .map((opt, idx) => {
844
+ if (idx === 0)
845
+ return null;
846
+ let testStr = opt.testString;
847
+ if (!testStr && opt.test) {
848
+ const start = opt.test.span.start - ast.span.start;
849
+ const end = opt.test.span.end - ast.span.start;
850
+ testStr = source.substring(start, end);
851
+ }
852
+ return `(!!(${testStr}) * ${idx})`;
853
+ })
854
+ .filter(Boolean);
855
+ if (exprs.length > 0) {
856
+ const groupSum = `(${exprs.join(' + ')})`;
857
+ if (meta.stride > 1) {
858
+ indexParts.push(`(${groupSum} * ${meta.stride})`);
859
+ }
860
+ else {
861
+ indexParts.push(groupSum);
862
+ }
833
863
  }
834
- const start = c.test.span.start - ast.span.start;
835
- const end = c.test.span.end - ast.span.start;
836
- const testStr = source.substring(start, end);
837
- return `(!!(${testStr}) << ${idx})`;
838
- });
839
- indexExpr = parts.join(' | ');
864
+ }
865
+ else {
866
+ const cond = meta.options[0];
867
+ let testStr = cond.testString;
868
+ if (!testStr && cond.test) {
869
+ const start = cond.test.span.start - ast.span.start;
870
+ const end = cond.test.span.end - ast.span.start;
871
+ testStr = source.substring(start, end);
872
+ }
873
+ const expr = `(!!(${testStr}))`;
874
+ if (meta.stride > 1) {
875
+ indexParts.push(`(${expr} * ${meta.stride})`);
876
+ }
877
+ else {
878
+ indexParts.push(`(${expr} * 1)`);
879
+ }
880
+ }
840
881
  }
882
+ const indexExpr = indexParts.join(' + ') || '0';
841
883
  const tableStr = JSON.stringify(table);
842
884
  const replacement = `${tableStr}[${indexExpr}]`;
843
885
  replacements.push({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/turbopack-loader",
3
- "version": "6.3.1",
3
+ "version": "6.3.2",
4
4
  "description": "Plumeria Turbopack-loader",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",
@@ -22,7 +22,7 @@
22
22
  "zero-virtual.css"
23
23
  ],
24
24
  "dependencies": {
25
- "@plumeria/utils": "^6.3.1"
25
+ "@plumeria/utils": "^6.3.2"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@swc/core": "1.15.8",