@plumeria/utils 19.1.5 → 19.1.6
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.
- package/dist/transform.js +94 -39
- package/package.json +1 -1
package/dist/transform.js
CHANGED
|
@@ -1702,11 +1702,13 @@ const transformSource = async (env) => {
|
|
|
1702
1702
|
Object.keys(conflictVarGroups).forEach((id) => {
|
|
1703
1703
|
const groupId = Number(id);
|
|
1704
1704
|
const opts = conflictVarGroups[groupId];
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1705
|
+
const present = new Set(opts.map((c) => c.valueName));
|
|
1706
|
+
conditionals.forEach((c) => {
|
|
1707
|
+
if (c.groupId !== groupId || present.has(c.valueName))
|
|
1708
|
+
return;
|
|
1709
|
+
present.add(c.valueName);
|
|
1710
|
+
opts.push({ ...c, truthy: {}, falsy: {} });
|
|
1711
|
+
});
|
|
1710
1712
|
});
|
|
1711
1713
|
Object.entries(conflictVarGroups).forEach(([, opts]) => {
|
|
1712
1714
|
ordered.push({
|
|
@@ -1725,45 +1727,98 @@ const transformSource = async (env) => {
|
|
|
1725
1727
|
});
|
|
1726
1728
|
ordered.sort((a, b) => a.order - b.order);
|
|
1727
1729
|
const dimensions = ordered.map((o) => o.dimension);
|
|
1728
|
-
const
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1730
|
+
const keysOf = (dim) => {
|
|
1731
|
+
const keys = new Set();
|
|
1732
|
+
dim.options.forEach((opt) => Object.keys(opt.style).forEach((key) => {
|
|
1733
|
+
if (conflictingKeys.has(key))
|
|
1734
|
+
keys.add(key);
|
|
1735
|
+
}));
|
|
1736
|
+
return keys;
|
|
1737
|
+
};
|
|
1738
|
+
const dimensionKeys = dimensions.map(keysOf);
|
|
1739
|
+
const parent = dimensions.map((_, index) => index);
|
|
1740
|
+
const find = (index) => parent[index] === index ? index : (parent[index] = find(parent[index]));
|
|
1741
|
+
const ownerByKey = new Map();
|
|
1742
|
+
dimensionKeys.forEach((keys, index) => {
|
|
1743
|
+
keys.forEach((key) => {
|
|
1744
|
+
const owner = ownerByKey.get(key);
|
|
1745
|
+
if (owner === undefined) {
|
|
1746
|
+
ownerByKey.set(key, index);
|
|
1747
|
+
return;
|
|
1748
|
+
}
|
|
1749
|
+
const a = find(owner);
|
|
1750
|
+
const b = find(index);
|
|
1751
|
+
if (a !== b)
|
|
1752
|
+
parent[b] = a;
|
|
1736
1753
|
});
|
|
1737
|
-
dim.testExpr = `(${JSON.stringify(numbers)}[${dim.testExpr}] || "")`;
|
|
1738
1754
|
});
|
|
1739
|
-
const
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1755
|
+
const components = new Map();
|
|
1756
|
+
dimensions.forEach((_, index) => {
|
|
1757
|
+
const root = find(index);
|
|
1758
|
+
const group = components.get(root);
|
|
1759
|
+
if (group)
|
|
1760
|
+
group.push(index);
|
|
1761
|
+
else
|
|
1762
|
+
components.set(root, [index]);
|
|
1763
|
+
});
|
|
1764
|
+
const emitComponent = (indexes) => {
|
|
1765
|
+
const dims = indexes.map((index) => dimensions[index]);
|
|
1766
|
+
const variables = dims.filter((dim) => dim.type !== 'const');
|
|
1767
|
+
const joined = variables.length > 1;
|
|
1768
|
+
dims.forEach((dim) => {
|
|
1769
|
+
if (!joined || dim.type !== 'var' || !dim.ownKeys)
|
|
1770
|
+
return;
|
|
1771
|
+
const numbers = {};
|
|
1772
|
+
dim.options.forEach((opt, index) => {
|
|
1773
|
+
numbers[String(opt.value)] = String(index);
|
|
1774
|
+
opt.value = String(index);
|
|
1775
|
+
});
|
|
1776
|
+
dim.testExpr = `(${JSON.stringify(numbers)}[${dim.testExpr}] || "")`;
|
|
1777
|
+
});
|
|
1778
|
+
const results = {};
|
|
1779
|
+
const recurse = (dimIndex, currentStyle, keyParts) => {
|
|
1780
|
+
if (dimIndex >= dims.length) {
|
|
1781
|
+
const className = processStyleRecords(currentStyle, stateWeights)
|
|
1782
|
+
.map((r) => r.hash)
|
|
1783
|
+
.join(' ');
|
|
1784
|
+
if (className)
|
|
1785
|
+
results[keyParts.join('__')] = className;
|
|
1786
|
+
return;
|
|
1787
|
+
}
|
|
1788
|
+
const dimension = dims[dimIndex];
|
|
1789
|
+
dimension.options.forEach((opt) => recurse(dimIndex + 1, (0, parser_1.deepMerge)(currentStyle, opt.style), dimension.type === 'const'
|
|
1790
|
+
? keyParts
|
|
1791
|
+
: [...keyParts, String(opt.value)]));
|
|
1792
|
+
};
|
|
1793
|
+
recurse(0, {}, []);
|
|
1794
|
+
if (variables.length === 0) {
|
|
1795
|
+
const only = results[''];
|
|
1796
|
+
if (only)
|
|
1797
|
+
classParts.push(JSON.stringify(only));
|
|
1747
1798
|
return;
|
|
1748
1799
|
}
|
|
1749
|
-
const
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1800
|
+
const componentKeys = new Set();
|
|
1801
|
+
indexes.forEach((index) => dimensionKeys[index].forEach((key) => componentKeys.add(key)));
|
|
1802
|
+
const componentBase = {};
|
|
1803
|
+
Object.entries(baseConflict).forEach(([key, value]) => {
|
|
1804
|
+
if (componentKeys.has(key))
|
|
1805
|
+
componentBase[key] = value;
|
|
1806
|
+
});
|
|
1807
|
+
const baseConflictClass = Object.keys(componentBase).length > 0
|
|
1808
|
+
? processStyleRecords(componentBase, stateWeights)
|
|
1809
|
+
.map((r) => r.hash)
|
|
1810
|
+
.join(' ')
|
|
1811
|
+
: '';
|
|
1812
|
+
const masterKeyExpr = variables
|
|
1813
|
+
.map((dim) => dim.type === 'std'
|
|
1814
|
+
? `(${dim.testExpr} ? "1" : "0")`
|
|
1815
|
+
: dim.testExpr || '""')
|
|
1816
|
+
.join(' + "__" + ');
|
|
1817
|
+
classParts.push(`(${JSON.stringify(results)}[${masterKeyExpr}] || ${baseConflictClass ? JSON.stringify(baseConflictClass) : '""'})`);
|
|
1753
1818
|
};
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
.map((r) => r.hash)
|
|
1758
|
-
.join(' ')
|
|
1759
|
-
: '';
|
|
1760
|
-
const masterKeyExpr = dimensions
|
|
1761
|
-
.filter((dim) => dim.type !== 'const')
|
|
1762
|
-
.map((dim) => dim.type === 'std'
|
|
1763
|
-
? `(${dim.testExpr} ? "1" : "0")`
|
|
1764
|
-
: dim.testExpr || '""')
|
|
1765
|
-
.join(' + "__" + ');
|
|
1766
|
-
classParts.push(`(${JSON.stringify(results)}[${masterKeyExpr || '""'}] || ${baseConflictClass ? JSON.stringify(baseConflictClass) : '""'})`);
|
|
1819
|
+
[...components.values()]
|
|
1820
|
+
.sort((a, b) => a[0] - b[0])
|
|
1821
|
+
.forEach(emitComponent);
|
|
1767
1822
|
}
|
|
1768
1823
|
classParts.push(...dynamicClassParts);
|
|
1769
1824
|
return {
|