@plumeria/vite-plugin 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
@@ -823,30 +823,44 @@ export function plumeria(options = {}) {
823
823
  }
824
824
  else {
825
825
  const table = {};
826
- const combinations = 1 << conditionals.length;
827
- for (let i = 0; i < combinations; i++) {
826
+ const groups = {};
827
+ let strayIdCounter = groupIdCounter + 1;
828
+ conditionals.forEach((c) => {
829
+ const gid = c.groupId !== undefined ? c.groupId : strayIdCounter++;
830
+ if (!groups[gid]) {
831
+ groups[gid] = [];
832
+ }
833
+ groups[gid].push(c);
834
+ });
835
+ const sortedGroupIds = Object.keys(groups)
836
+ .map(Number)
837
+ .sort((a, b) => a - b);
838
+ let totalCombinations = 1;
839
+ const groupMeta = sortedGroupIds.map((gid) => {
840
+ const options = groups[gid];
841
+ const isVariantGroup = options[0].groupId !== undefined;
842
+ const size = isVariantGroup ? options.length : 2;
843
+ const stride = totalCombinations;
844
+ totalCombinations *= size;
845
+ return { gid, options, size, stride, isVariantGroup };
846
+ });
847
+ for (let i = 0; i < totalCombinations; i++) {
828
848
  let currentStyle = { ...baseStyle };
829
- const seenGroups = new Set();
830
- let impossible = false;
831
- for (let j = 0; j < conditionals.length; j++) {
832
- if ((i >> j) & 1) {
833
- if (conditionals[j].groupId !== undefined) {
834
- if (seenGroups.has(conditionals[j].groupId)) {
835
- impossible = true;
836
- break;
837
- }
838
- seenGroups.add(conditionals[j].groupId);
839
- }
840
- currentStyle = deepMerge(currentStyle, conditionals[j].truthy);
849
+ for (const meta of groupMeta) {
850
+ const localIndex = Math.floor(i / meta.stride) % meta.size;
851
+ if (meta.isVariantGroup) {
852
+ currentStyle = deepMerge(currentStyle, meta.options[localIndex].truthy);
841
853
  }
842
854
  else {
843
- currentStyle = deepMerge(currentStyle, conditionals[j].falsy);
855
+ const cond = meta.options[0];
856
+ if (localIndex === 1) {
857
+ currentStyle = deepMerge(currentStyle, cond.truthy);
858
+ }
859
+ else {
860
+ currentStyle = deepMerge(currentStyle, cond.falsy);
861
+ }
844
862
  }
845
863
  }
846
- if (impossible) {
847
- table[i] = '';
848
- continue;
849
- }
850
864
  extractOndemandStyles(currentStyle, extractedSheets, scannedTables);
851
865
  const hash = genBase36Hash(currentStyle, 1, 8);
852
866
  const records = getStyleRecords(hash, currentStyle);
@@ -856,22 +870,50 @@ export function plumeria(options = {}) {
856
870
  .join(' ');
857
871
  table[i] = className;
858
872
  }
859
- let indexExpr = '';
860
- if (conditionals.length === 0) {
861
- indexExpr = '0';
862
- }
863
- else {
864
- const parts = conditionals.map((c, idx) => {
865
- if (c.testString) {
866
- return `(!!(${c.testString}) << ${idx})`;
873
+ const indexParts = [];
874
+ for (const meta of groupMeta) {
875
+ if (meta.isVariantGroup) {
876
+ const exprs = meta.options
877
+ .map((opt, idx) => {
878
+ if (idx === 0)
879
+ return null;
880
+ let testStr = opt.testString;
881
+ if (!testStr && opt.test) {
882
+ const start = opt.test.span.start - ast.span.start;
883
+ const end = opt.test.span.end - ast.span.start;
884
+ testStr = source.substring(start, end);
885
+ }
886
+ return `(!!(${testStr}) * ${idx})`;
887
+ })
888
+ .filter(Boolean);
889
+ if (exprs.length > 0) {
890
+ const groupSum = `(${exprs.join(' + ')})`;
891
+ if (meta.stride > 1) {
892
+ indexParts.push(`(${groupSum} * ${meta.stride})`);
893
+ }
894
+ else {
895
+ indexParts.push(groupSum);
896
+ }
867
897
  }
868
- const start = c.test.span.start - ast.span.start;
869
- const end = c.test.span.end - ast.span.start;
870
- const testStr = source.substring(start, end);
871
- return `(!!(${testStr}) << ${idx})`;
872
- });
873
- indexExpr = parts.join(' | ');
898
+ }
899
+ else {
900
+ const cond = meta.options[0];
901
+ let testStr = cond.testString;
902
+ if (!testStr && cond.test) {
903
+ const start = cond.test.span.start - ast.span.start;
904
+ const end = cond.test.span.end - ast.span.start;
905
+ testStr = source.substring(start, end);
906
+ }
907
+ const expr = `(!!(${testStr}))`;
908
+ if (meta.stride > 1) {
909
+ indexParts.push(`(${expr} * ${meta.stride})`);
910
+ }
911
+ else {
912
+ indexParts.push(`(${expr} * 1)`);
913
+ }
914
+ }
874
915
  }
916
+ const indexExpr = indexParts.join(' + ') || '0';
875
917
  const tableStr = JSON.stringify(table);
876
918
  const replacement = `${tableStr}[${indexExpr}]`;
877
919
  replacements.push({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/vite-plugin",
3
- "version": "6.3.1",
3
+ "version": "6.3.2",
4
4
  "type": "module",
5
5
  "description": "Plumeria Vite plugin",
6
6
  "author": "Refirst 11",
@@ -22,7 +22,7 @@
22
22
  "dist/"
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",