@plumeria/utils 7.2.4 → 7.3.0
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/parser.js +32 -6
- package/package.json +1 -1
package/dist/parser.js
CHANGED
|
@@ -881,7 +881,7 @@ function extractOndemandStyles(obj, extractedSheets, t) {
|
|
|
881
881
|
const keyframesHashes = new Set();
|
|
882
882
|
const viewTransitionHashes = new Set();
|
|
883
883
|
const createHashes = new Set();
|
|
884
|
-
|
|
884
|
+
const usedVariables = new Set();
|
|
885
885
|
function walk(n) {
|
|
886
886
|
if (!n || typeof n !== 'object' || visited.has(n))
|
|
887
887
|
return;
|
|
@@ -898,7 +898,22 @@ function extractOndemandStyles(obj, extractedSheets, t) {
|
|
|
898
898
|
createHashes.add(val.slice(3));
|
|
899
899
|
}
|
|
900
900
|
else if (val.includes('var(--')) {
|
|
901
|
-
|
|
901
|
+
let startIdx = 0;
|
|
902
|
+
while ((startIdx = val.indexOf('var(--', startIdx)) !== -1) {
|
|
903
|
+
startIdx += 4;
|
|
904
|
+
const endIdx = val.indexOf(')', startIdx);
|
|
905
|
+
if (endIdx !== -1) {
|
|
906
|
+
const content = val.slice(startIdx, endIdx);
|
|
907
|
+
const varName = content.trim();
|
|
908
|
+
if (varName.startsWith('--')) {
|
|
909
|
+
usedVariables.add(varName);
|
|
910
|
+
}
|
|
911
|
+
startIdx = endIdx + 1;
|
|
912
|
+
}
|
|
913
|
+
else {
|
|
914
|
+
break;
|
|
915
|
+
}
|
|
916
|
+
}
|
|
902
917
|
}
|
|
903
918
|
}
|
|
904
919
|
else {
|
|
@@ -943,14 +958,25 @@ function extractOndemandStyles(obj, extractedSheets, t) {
|
|
|
943
958
|
}
|
|
944
959
|
}
|
|
945
960
|
}
|
|
946
|
-
if (
|
|
961
|
+
if (usedVariables.size > 0) {
|
|
947
962
|
for (const themeVarName in t.createThemeHashTable) {
|
|
948
963
|
const hash = t.createThemeHashTable[themeVarName];
|
|
949
964
|
const definition = t.createThemeObjectTable[hash];
|
|
950
965
|
if (definition && typeof definition === 'object') {
|
|
951
|
-
const
|
|
952
|
-
|
|
953
|
-
|
|
966
|
+
const filteredDefinition = {};
|
|
967
|
+
let hasUsed = false;
|
|
968
|
+
Object.keys(definition).forEach((key) => {
|
|
969
|
+
const varName = `--${(0, zss_engine_1.camelToKebabCase)(key)}`;
|
|
970
|
+
if (usedVariables.has(varName)) {
|
|
971
|
+
filteredDefinition[key] = definition[key];
|
|
972
|
+
hasUsed = true;
|
|
973
|
+
}
|
|
974
|
+
});
|
|
975
|
+
if (hasUsed) {
|
|
976
|
+
const styles = (0, createTheme_1.createTheme)(filteredDefinition);
|
|
977
|
+
const { styleSheet } = (0, zss_engine_1.transpile)(styles, undefined, '--global');
|
|
978
|
+
addSheet(styleSheet);
|
|
979
|
+
}
|
|
954
980
|
}
|
|
955
981
|
}
|
|
956
982
|
}
|