@plumeria/utils 19.1.5 → 19.1.7
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/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/dist/parser.d.ts +7 -0
- package/dist/parser.js +27 -0
- package/dist/transform.js +109 -54
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type { CSSObject, StaticTable, KeyframesHashTable, ViewTransitionHashTable, CreateHashTable, CreateFunctionTable, CreateThemeHashTable, CreateStaticHashTable, } from './types';
|
|
2
|
-
export { objectExpressionToObject, collectLocalConsts, traverse, t, getRootIdentifier, unwrapExpression, extractOndemandStyles, deepMerge, scanAll, resolveFileError, getFileDependencies, resolveExport, resolveComponentKey, resolveThemeSelector, } from './parser';
|
|
2
|
+
export { objectExpressionToObject, collectLocalConsts, traverse, t, getRootIdentifier, resolveOriginError, unwrapExpression, extractOndemandStyles, deepMerge, scanAll, resolveFileError, getFileDependencies, resolveExport, resolveComponentKey, resolveThemeSelector, } from './parser';
|
|
3
3
|
export type { StyleRecord } from './create';
|
|
4
4
|
export { getStyleRecords } from './create';
|
|
5
5
|
export type { NamedParam, StyleFunction, StyleFunctions, DynamicStyleTables, DynamicStyleResult, } from './dynamicKey';
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transformSource = exports.assertPropertyPolicy = exports.resolvePropertyPolicy = exports.DEFAULT_STYLE_PROP = exports.timedAsync = exports.timed = exports.tally = exports.measure = exports.mark = exports.profiling = exports.collectReferenceIdentifiers = exports.getLeadingCommentLength = exports.optimizer = exports.resolveImportPath = exports.themeHashOf = exports.getStateWeights = exports.getPseudoElement = exports.getSpecificity = exports.resolveDynamicStyle = exports.applyVarFallback = exports.splitVarByUnit = exports.isUnitlessProp = exports.styleFunctionsOf = exports.getStyleRecords = exports.resolveThemeSelector = exports.resolveComponentKey = exports.resolveExport = exports.getFileDependencies = exports.resolveFileError = exports.scanAll = exports.deepMerge = exports.extractOndemandStyles = exports.unwrapExpression = exports.getRootIdentifier = exports.t = exports.traverse = exports.collectLocalConsts = exports.objectExpressionToObject = void 0;
|
|
3
|
+
exports.transformSource = exports.assertPropertyPolicy = exports.resolvePropertyPolicy = exports.DEFAULT_STYLE_PROP = exports.timedAsync = exports.timed = exports.tally = exports.measure = exports.mark = exports.profiling = exports.collectReferenceIdentifiers = exports.getLeadingCommentLength = exports.optimizer = exports.resolveImportPath = exports.themeHashOf = exports.getStateWeights = exports.getPseudoElement = exports.getSpecificity = exports.resolveDynamicStyle = exports.applyVarFallback = exports.splitVarByUnit = exports.isUnitlessProp = exports.styleFunctionsOf = exports.getStyleRecords = exports.resolveThemeSelector = exports.resolveComponentKey = exports.resolveExport = exports.getFileDependencies = exports.resolveFileError = exports.scanAll = exports.deepMerge = exports.extractOndemandStyles = exports.unwrapExpression = exports.resolveOriginError = exports.getRootIdentifier = exports.t = exports.traverse = exports.collectLocalConsts = exports.objectExpressionToObject = void 0;
|
|
4
4
|
var parser_1 = require("./parser");
|
|
5
5
|
Object.defineProperty(exports, "objectExpressionToObject", { enumerable: true, get: function () { return parser_1.objectExpressionToObject; } });
|
|
6
6
|
Object.defineProperty(exports, "collectLocalConsts", { enumerable: true, get: function () { return parser_1.collectLocalConsts; } });
|
|
7
7
|
Object.defineProperty(exports, "traverse", { enumerable: true, get: function () { return parser_1.traverse; } });
|
|
8
8
|
Object.defineProperty(exports, "t", { enumerable: true, get: function () { return parser_1.t; } });
|
|
9
9
|
Object.defineProperty(exports, "getRootIdentifier", { enumerable: true, get: function () { return parser_1.getRootIdentifier; } });
|
|
10
|
+
Object.defineProperty(exports, "resolveOriginError", { enumerable: true, get: function () { return parser_1.resolveOriginError; } });
|
|
10
11
|
Object.defineProperty(exports, "unwrapExpression", { enumerable: true, get: function () { return parser_1.unwrapExpression; } });
|
|
11
12
|
Object.defineProperty(exports, "extractOndemandStyles", { enumerable: true, get: function () { return parser_1.extractOndemandStyles; } });
|
|
12
13
|
Object.defineProperty(exports, "deepMerge", { enumerable: true, get: function () { return parser_1.deepMerge; } });
|
package/dist/parser.d.ts
CHANGED
|
@@ -2,6 +2,13 @@ import type { CSSObject, Tables, StaticTable, KeyframesHashTable, ViewTransition
|
|
|
2
2
|
import type { Module, Expression, CallExpression, Identifier, KeyValueProperty, StringLiteral, NumericLiteral, BooleanLiteral, ObjectExpression, MemberExpression, TemplateLiteral, BinaryExpression, UnaryExpression, ParenthesisExpression, VariableDeclaration, VariableDeclarator, ExportDeclaration, ConditionalExpression, JSXExpression, ArrowFunctionExpression, FunctionExpression } from '@swc/core';
|
|
3
3
|
export declare function unwrapExpression(node: any): any;
|
|
4
4
|
export declare const getRootIdentifier: (node: Expression) => string | null;
|
|
5
|
+
export declare function resolveOriginError(node: Expression, rootName: string | null, localImports: Record<string, {
|
|
6
|
+
actualPath: string;
|
|
7
|
+
importedName: string;
|
|
8
|
+
}>): {
|
|
9
|
+
filePath: string;
|
|
10
|
+
message: string;
|
|
11
|
+
} | undefined;
|
|
5
12
|
export declare function resolveComponentKey(nameNode: any, filePath: string, localImports: Record<string, {
|
|
6
13
|
actualPath: string;
|
|
7
14
|
importedName: string;
|
package/dist/parser.js
CHANGED
|
@@ -35,6 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.t = exports.getRootIdentifier = void 0;
|
|
37
37
|
exports.unwrapExpression = unwrapExpression;
|
|
38
|
+
exports.resolveOriginError = resolveOriginError;
|
|
38
39
|
exports.resolveComponentKey = resolveComponentKey;
|
|
39
40
|
exports.traverse = traverse;
|
|
40
41
|
exports.objectExpressionToObject = objectExpressionToObject;
|
|
@@ -98,6 +99,32 @@ const getRootIdentifier = (node) => {
|
|
|
98
99
|
return null;
|
|
99
100
|
};
|
|
100
101
|
exports.getRootIdentifier = getRootIdentifier;
|
|
102
|
+
const getNamespaceMember = (node, rootName) => {
|
|
103
|
+
node = unwrapExpression(node);
|
|
104
|
+
if (exports.t.isCallExpression(node)) {
|
|
105
|
+
const callee = node.callee;
|
|
106
|
+
if (callee.type === 'Super' || callee.type === 'Import')
|
|
107
|
+
return null;
|
|
108
|
+
return getNamespaceMember(callee, rootName);
|
|
109
|
+
}
|
|
110
|
+
if (exports.t.isMemberExpression(node)) {
|
|
111
|
+
const object = unwrapExpression(node.object);
|
|
112
|
+
if (exports.t.isIdentifier(object) && object.value === rootName) {
|
|
113
|
+
return exports.t.isIdentifier(node.property) ? node.property.value : null;
|
|
114
|
+
}
|
|
115
|
+
return getNamespaceMember(object, rootName);
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
};
|
|
119
|
+
function resolveOriginError(node, rootName, localImports) {
|
|
120
|
+
const origin = rootName ? localImports[rootName] : undefined;
|
|
121
|
+
if (!origin)
|
|
122
|
+
return undefined;
|
|
123
|
+
const exportName = origin.importedName === '*' && rootName
|
|
124
|
+
? (getNamespaceMember(node, rootName) ?? '*')
|
|
125
|
+
: origin.importedName;
|
|
126
|
+
return resolveFileError(origin.actualPath, exportName);
|
|
127
|
+
}
|
|
101
128
|
function resolveComponentKey(nameNode, filePath, localImports) {
|
|
102
129
|
if (nameNode?.type === 'Identifier') {
|
|
103
130
|
const name = nameNode.value;
|
package/dist/transform.js
CHANGED
|
@@ -193,10 +193,7 @@ const transformSource = async (env) => {
|
|
|
193
193
|
localCreateStyles[rootId].type !== 'constant') ||
|
|
194
194
|
mergedCreateTable[rootId] !== undefined);
|
|
195
195
|
if (!isPlumeriaStyle) {
|
|
196
|
-
const
|
|
197
|
-
const failure = origin
|
|
198
|
-
? (0, parser_1.resolveFileError)(origin.actualPath, origin.importedName)
|
|
199
|
-
: undefined;
|
|
196
|
+
const failure = (0, parser_1.resolveOriginError)(node, rootId, localImports);
|
|
200
197
|
if (failure) {
|
|
201
198
|
throwCompilationError(`Plumeria: ${failure.message} (${path.basename(failure.filePath)})`);
|
|
202
199
|
}
|
|
@@ -1702,11 +1699,13 @@ const transformSource = async (env) => {
|
|
|
1702
1699
|
Object.keys(conflictVarGroups).forEach((id) => {
|
|
1703
1700
|
const groupId = Number(id);
|
|
1704
1701
|
const opts = conflictVarGroups[groupId];
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1702
|
+
const present = new Set(opts.map((c) => c.valueName));
|
|
1703
|
+
conditionals.forEach((c) => {
|
|
1704
|
+
if (c.groupId !== groupId || present.has(c.valueName))
|
|
1705
|
+
return;
|
|
1706
|
+
present.add(c.valueName);
|
|
1707
|
+
opts.push({ ...c, truthy: {}, falsy: {} });
|
|
1708
|
+
});
|
|
1710
1709
|
});
|
|
1711
1710
|
Object.entries(conflictVarGroups).forEach(([, opts]) => {
|
|
1712
1711
|
ordered.push({
|
|
@@ -1725,45 +1724,98 @@ const transformSource = async (env) => {
|
|
|
1725
1724
|
});
|
|
1726
1725
|
ordered.sort((a, b) => a.order - b.order);
|
|
1727
1726
|
const dimensions = ordered.map((o) => o.dimension);
|
|
1728
|
-
const
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1727
|
+
const keysOf = (dim) => {
|
|
1728
|
+
const keys = new Set();
|
|
1729
|
+
dim.options.forEach((opt) => Object.keys(opt.style).forEach((key) => {
|
|
1730
|
+
if (conflictingKeys.has(key))
|
|
1731
|
+
keys.add(key);
|
|
1732
|
+
}));
|
|
1733
|
+
return keys;
|
|
1734
|
+
};
|
|
1735
|
+
const dimensionKeys = dimensions.map(keysOf);
|
|
1736
|
+
const parent = dimensions.map((_, index) => index);
|
|
1737
|
+
const find = (index) => parent[index] === index ? index : (parent[index] = find(parent[index]));
|
|
1738
|
+
const ownerByKey = new Map();
|
|
1739
|
+
dimensionKeys.forEach((keys, index) => {
|
|
1740
|
+
keys.forEach((key) => {
|
|
1741
|
+
const owner = ownerByKey.get(key);
|
|
1742
|
+
if (owner === undefined) {
|
|
1743
|
+
ownerByKey.set(key, index);
|
|
1744
|
+
return;
|
|
1745
|
+
}
|
|
1746
|
+
const a = find(owner);
|
|
1747
|
+
const b = find(index);
|
|
1748
|
+
if (a !== b)
|
|
1749
|
+
parent[b] = a;
|
|
1736
1750
|
});
|
|
1737
|
-
dim.testExpr = `(${JSON.stringify(numbers)}[${dim.testExpr}] || "")`;
|
|
1738
1751
|
});
|
|
1739
|
-
const
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1752
|
+
const components = new Map();
|
|
1753
|
+
dimensions.forEach((_, index) => {
|
|
1754
|
+
const root = find(index);
|
|
1755
|
+
const group = components.get(root);
|
|
1756
|
+
if (group)
|
|
1757
|
+
group.push(index);
|
|
1758
|
+
else
|
|
1759
|
+
components.set(root, [index]);
|
|
1760
|
+
});
|
|
1761
|
+
const emitComponent = (indexes) => {
|
|
1762
|
+
const dims = indexes.map((index) => dimensions[index]);
|
|
1763
|
+
const variables = dims.filter((dim) => dim.type !== 'const');
|
|
1764
|
+
const joined = variables.length > 1;
|
|
1765
|
+
dims.forEach((dim) => {
|
|
1766
|
+
if (!joined || dim.type !== 'var' || !dim.ownKeys)
|
|
1767
|
+
return;
|
|
1768
|
+
const numbers = {};
|
|
1769
|
+
dim.options.forEach((opt, index) => {
|
|
1770
|
+
numbers[String(opt.value)] = String(index);
|
|
1771
|
+
opt.value = String(index);
|
|
1772
|
+
});
|
|
1773
|
+
dim.testExpr = `(${JSON.stringify(numbers)}[${dim.testExpr}] || "")`;
|
|
1774
|
+
});
|
|
1775
|
+
const results = {};
|
|
1776
|
+
const recurse = (dimIndex, currentStyle, keyParts) => {
|
|
1777
|
+
if (dimIndex >= dims.length) {
|
|
1778
|
+
const className = processStyleRecords(currentStyle, stateWeights)
|
|
1779
|
+
.map((r) => r.hash)
|
|
1780
|
+
.join(' ');
|
|
1781
|
+
if (className)
|
|
1782
|
+
results[keyParts.join('__')] = className;
|
|
1783
|
+
return;
|
|
1784
|
+
}
|
|
1785
|
+
const dimension = dims[dimIndex];
|
|
1786
|
+
dimension.options.forEach((opt) => recurse(dimIndex + 1, (0, parser_1.deepMerge)(currentStyle, opt.style), dimension.type === 'const'
|
|
1787
|
+
? keyParts
|
|
1788
|
+
: [...keyParts, String(opt.value)]));
|
|
1789
|
+
};
|
|
1790
|
+
recurse(0, {}, []);
|
|
1791
|
+
if (variables.length === 0) {
|
|
1792
|
+
const only = results[''];
|
|
1793
|
+
if (only)
|
|
1794
|
+
classParts.push(JSON.stringify(only));
|
|
1747
1795
|
return;
|
|
1748
1796
|
}
|
|
1749
|
-
const
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1797
|
+
const componentKeys = new Set();
|
|
1798
|
+
indexes.forEach((index) => dimensionKeys[index].forEach((key) => componentKeys.add(key)));
|
|
1799
|
+
const componentBase = {};
|
|
1800
|
+
Object.entries(baseConflict).forEach(([key, value]) => {
|
|
1801
|
+
if (componentKeys.has(key))
|
|
1802
|
+
componentBase[key] = value;
|
|
1803
|
+
});
|
|
1804
|
+
const baseConflictClass = Object.keys(componentBase).length > 0
|
|
1805
|
+
? processStyleRecords(componentBase, stateWeights)
|
|
1806
|
+
.map((r) => r.hash)
|
|
1807
|
+
.join(' ')
|
|
1808
|
+
: '';
|
|
1809
|
+
const masterKeyExpr = variables
|
|
1810
|
+
.map((dim) => dim.type === 'std'
|
|
1811
|
+
? `(${dim.testExpr} ? "1" : "0")`
|
|
1812
|
+
: dim.testExpr || '""')
|
|
1813
|
+
.join(' + "__" + ');
|
|
1814
|
+
classParts.push(`(${JSON.stringify(results)}[${masterKeyExpr}] || ${baseConflictClass ? JSON.stringify(baseConflictClass) : '""'})`);
|
|
1753
1815
|
};
|
|
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) : '""'})`);
|
|
1816
|
+
[...components.values()]
|
|
1817
|
+
.sort((a, b) => a[0] - b[0])
|
|
1818
|
+
.forEach(emitComponent);
|
|
1767
1819
|
}
|
|
1768
1820
|
classParts.push(...dynamicClassParts);
|
|
1769
1821
|
return {
|
|
@@ -1958,21 +2010,24 @@ const transformSource = async (env) => {
|
|
|
1958
2010
|
if (node.name.type !== 'Identifier')
|
|
1959
2011
|
return;
|
|
1960
2012
|
const attrName = node.name.value;
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
break;
|
|
1970
|
-
}
|
|
2013
|
+
let compKey = null;
|
|
2014
|
+
for (const [, val] of jsxOpeningElementMap) {
|
|
2015
|
+
const found = val.attributes
|
|
2016
|
+
.filter((a) => a.type === 'JSXAttribute')
|
|
2017
|
+
.find((a) => a.span.start === node.span.start);
|
|
2018
|
+
if (found) {
|
|
2019
|
+
compKey = val.compKey;
|
|
2020
|
+
break;
|
|
1971
2021
|
}
|
|
2022
|
+
}
|
|
2023
|
+
const relayed = compKey
|
|
2024
|
+
? scannedTables.componentPropsTable?.[compKey]?.[attrName]
|
|
2025
|
+
: undefined;
|
|
2026
|
+
if (attrName !== styleProp || relayed) {
|
|
1972
2027
|
if (compKey) {
|
|
1973
2028
|
if (node.value?.type === 'JSXExpressionContainer')
|
|
1974
2029
|
assertNoStyleArraySpread(node.value.expression);
|
|
1975
|
-
const list =
|
|
2030
|
+
const list = relayed;
|
|
1976
2031
|
if (list &&
|
|
1977
2032
|
node.value &&
|
|
1978
2033
|
node.value.type === 'JSXExpressionContainer') {
|