tokenami 0.0.81 → 0.0.82
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/cli.cjs +46 -157
- package/dist/cli.js +45 -156
- package/dist/index.cjs +48 -92
- package/dist/index.d.cts +2 -11
- package/dist/index.d.ts +2 -11
- package/dist/index.js +47 -91
- package/package.json +6 -6
package/dist/cli.cjs
CHANGED
|
@@ -64,8 +64,7 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
|
64
64
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
65
65
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
66
66
|
}) : x)(function(x) {
|
|
67
|
-
if (typeof require !== "undefined")
|
|
68
|
-
return require.apply(this, arguments);
|
|
67
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
69
68
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
70
69
|
});
|
|
71
70
|
var __esm = (fn, res) => function __init() {
|
|
@@ -91,9 +90,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
91
90
|
mod
|
|
92
91
|
));
|
|
93
92
|
|
|
94
|
-
// ../../node_modules/.pnpm/tsup@
|
|
93
|
+
// ../../node_modules/.pnpm/tsup@8.4.0_jiti@1.21.6_typescript@5.4.5/node_modules/tsup/assets/cjs_shims.js
|
|
95
94
|
var init_cjs_shims = __esm({
|
|
96
|
-
"../../node_modules/.pnpm/tsup@
|
|
95
|
+
"../../node_modules/.pnpm/tsup@8.4.0_jiti@1.21.6_typescript@5.4.5/node_modules/tsup/assets/cjs_shims.js"() {
|
|
97
96
|
}
|
|
98
97
|
});
|
|
99
98
|
|
|
@@ -288,8 +287,7 @@ var require_HashArray = __commonJS({
|
|
|
288
287
|
continue;
|
|
289
288
|
}
|
|
290
289
|
this._map[inst].push(obj);
|
|
291
|
-
} else
|
|
292
|
-
this._map[inst] = [obj];
|
|
290
|
+
} else this._map[inst] = [obj];
|
|
293
291
|
}
|
|
294
292
|
}
|
|
295
293
|
if (!needsDupCheck || this._list.indexOf(obj) == -1)
|
|
@@ -378,8 +376,7 @@ var require_HashArray = __commonJS({
|
|
|
378
376
|
count = Math.min(Math.max(max - min, 1), count);
|
|
379
377
|
while (res.length < count) {
|
|
380
378
|
var r = Math.floor(min + Math.random() * (max + 1));
|
|
381
|
-
if (map[r])
|
|
382
|
-
continue;
|
|
379
|
+
if (map[r]) continue;
|
|
383
380
|
map[r] = true;
|
|
384
381
|
res.push(r);
|
|
385
382
|
}
|
|
@@ -652,8 +649,7 @@ var require_crypt = __commonJS({
|
|
|
652
649
|
base64ToBytes: function(base64) {
|
|
653
650
|
base64 = base64.replace(/[^A-Z0-9+\/]/ig, "");
|
|
654
651
|
for (var bytes = [], i = 0, imod4 = 0; i < base64.length; imod4 = ++i % 4) {
|
|
655
|
-
if (imod4 == 0)
|
|
656
|
-
continue;
|
|
652
|
+
if (imod4 == 0) continue;
|
|
657
653
|
bytes.push((base64map.indexOf(base64.charAt(i - 1)) & Math.pow(2, -2 * imod4 + 8) - 1) << imod4 * 2 | base64map.indexOf(base64.charAt(i)) >>> 6 - imod4 * 2);
|
|
658
654
|
}
|
|
659
655
|
return bytes;
|
|
@@ -902,16 +898,14 @@ var require_TrieSearch = __commonJS({
|
|
|
902
898
|
}
|
|
903
899
|
TrieSearch2.prototype = {
|
|
904
900
|
add: function(item, customKeys) {
|
|
905
|
-
if (this.options.cache)
|
|
906
|
-
this.clearCache();
|
|
901
|
+
if (this.options.cache) this.clearCache();
|
|
907
902
|
if (typeof customKeys === "number") {
|
|
908
903
|
customKeys = void 0;
|
|
909
904
|
}
|
|
910
905
|
var keyFields = customKeys || this.keyFields;
|
|
911
906
|
for (var k in keyFields) {
|
|
912
907
|
var key = keyFields[k], isKeyArr = key instanceof Array, val = isKeyArr ? deepLookup(item, key) : item[key];
|
|
913
|
-
if (!val)
|
|
914
|
-
continue;
|
|
908
|
+
if (!val) continue;
|
|
915
909
|
val = val.toString();
|
|
916
910
|
if (this.options.ignoreCase) {
|
|
917
911
|
val = val.toLowerCase();
|
|
@@ -931,14 +925,12 @@ var require_TrieSearch = __commonJS({
|
|
|
931
925
|
* @param keyFields The keyfields in which to search for this phrase to remove
|
|
932
926
|
*/
|
|
933
927
|
remove: function(phrase, keyFields) {
|
|
934
|
-
if (!phrase)
|
|
935
|
-
return;
|
|
928
|
+
if (!phrase) return;
|
|
936
929
|
phrase = phrase.toString();
|
|
937
930
|
phrase = this.options.ignoreCase ? phrase.toLowerCase() : phrase;
|
|
938
931
|
keyFields = keyFields || this.keyFields;
|
|
939
932
|
keyFields = keyFields instanceof Array ? keyFields : [keyFields];
|
|
940
|
-
if (this.options.cache)
|
|
941
|
-
this.clearCache();
|
|
933
|
+
if (this.options.cache) this.clearCache();
|
|
942
934
|
var diacriticalVariants = this.expandString(phrase);
|
|
943
935
|
for (var variant of diacriticalVariants) {
|
|
944
936
|
var words = this.options.splitOnRegEx ? variant.split(this.options.splitOnRegEx) : [variant];
|
|
@@ -1090,17 +1082,14 @@ var require_TrieSearch = __commonJS({
|
|
|
1090
1082
|
return [];
|
|
1091
1083
|
keyArr = [key.substring(0, this.options.min)];
|
|
1092
1084
|
keyArr = keyArr.concat(key.substring(this.options.min).split(""));
|
|
1093
|
-
} else
|
|
1094
|
-
keyArr = key.split("");
|
|
1085
|
+
} else keyArr = key.split("");
|
|
1095
1086
|
return keyArr;
|
|
1096
1087
|
},
|
|
1097
1088
|
findNode: function(key) {
|
|
1098
1089
|
return f(this.keyToArr(key), this.root);
|
|
1099
1090
|
function f(keyArr, node) {
|
|
1100
|
-
if (!node)
|
|
1101
|
-
|
|
1102
|
-
if (keyArr.length === 0)
|
|
1103
|
-
return node;
|
|
1091
|
+
if (!node) return void 0;
|
|
1092
|
+
if (keyArr.length === 0) return node;
|
|
1104
1093
|
var k = keyArr.shift();
|
|
1105
1094
|
return f(keyArr, node[k]);
|
|
1106
1095
|
}
|
|
@@ -1137,8 +1126,7 @@ var require_TrieSearch = __commonJS({
|
|
|
1137
1126
|
var item = node2.value[i];
|
|
1138
1127
|
if (!limit || all.length < limit) {
|
|
1139
1128
|
const id = self.getId(item);
|
|
1140
|
-
if (dedupDict[id])
|
|
1141
|
-
continue;
|
|
1129
|
+
if (dedupDict[id]) continue;
|
|
1142
1130
|
all.push(item);
|
|
1143
1131
|
dedupDict[id] = item;
|
|
1144
1132
|
}
|
|
@@ -1172,8 +1160,7 @@ var require_TrieSearch = __commonJS({
|
|
|
1172
1160
|
return this.get(phrases, reducer, limit);
|
|
1173
1161
|
},
|
|
1174
1162
|
getId: function(item, customKeys) {
|
|
1175
|
-
if (item.$tsid)
|
|
1176
|
-
return item.$tsid;
|
|
1163
|
+
if (item.$tsid) return item.$tsid;
|
|
1177
1164
|
if (!this.options.idFieldOrFunction) {
|
|
1178
1165
|
var s = "";
|
|
1179
1166
|
var kf = customKeys || this.keyFields;
|
|
@@ -1758,8 +1745,7 @@ function getConfigPath(cwd, path, type) {
|
|
|
1758
1745
|
function getConfigAtPath(path, opts = { cache: true }) {
|
|
1759
1746
|
const config = (() => {
|
|
1760
1747
|
try {
|
|
1761
|
-
if (!opts.cache)
|
|
1762
|
-
delete __require.cache[__require.resolve(path)];
|
|
1748
|
+
if (!opts.cache) delete __require.cache[__require.resolve(path)];
|
|
1763
1749
|
return __require(path);
|
|
1764
1750
|
} catch {
|
|
1765
1751
|
return lazyJiti({ cache: opts.cache })(path);
|
|
@@ -1786,8 +1772,7 @@ function getThemeValueByTokenValueEntries(tokenValues, theme) {
|
|
|
1786
1772
|
return sorted.flatMap((tokenValue2) => {
|
|
1787
1773
|
const parts = Tokenami2__namespace.getTokenValueParts(tokenValue2);
|
|
1788
1774
|
const value = theme[parts.themeKey]?.[parts.token];
|
|
1789
|
-
if (value == null)
|
|
1790
|
-
return [];
|
|
1775
|
+
if (value == null) return [];
|
|
1791
1776
|
const valueString = String(value);
|
|
1792
1777
|
const tokenValues2 = findTokenValuesInThemeValue(valueString);
|
|
1793
1778
|
const themeValuesEntries = getThemeValueByTokenValueEntries(tokenValues2, theme);
|
|
@@ -1893,8 +1878,7 @@ function generate(params) {
|
|
|
1893
1878
|
}
|
|
1894
1879
|
}
|
|
1895
1880
|
function createSheet(params) {
|
|
1896
|
-
if (!params.tokens.properties.length)
|
|
1897
|
-
return "";
|
|
1881
|
+
if (!params.tokens.properties.length) return "";
|
|
1898
1882
|
const tokenProperties = params.tokens.properties;
|
|
1899
1883
|
const tokenValues = params.tokens.values;
|
|
1900
1884
|
const composeBlocks = parseComposeBlocks(params.tokens.composeBlocks, params.config);
|
|
@@ -1925,8 +1909,7 @@ function createSheet(params) {
|
|
|
1925
1909
|
const layerIndex = getAtomicLayerIndex(cssProperty, params.config);
|
|
1926
1910
|
const toggleKey = prop.responsive || prop.selector;
|
|
1927
1911
|
const propertyPrefix = prop.isCustom ? CUSTOM_PROP_PREFIX : "";
|
|
1928
|
-
if (layerIndex === -1)
|
|
1929
|
-
continue;
|
|
1912
|
+
if (layerIndex === -1) continue;
|
|
1930
1913
|
if (prop.variant && toggleKey) {
|
|
1931
1914
|
const responsive = getResponsiveSelectorFromConfig(prop.responsive, params.config);
|
|
1932
1915
|
const selectorConfig = getPropertyConfigSelector(prop.selector, params.config);
|
|
@@ -1941,8 +1924,7 @@ function createSheet(params) {
|
|
|
1941
1924
|
const declarationValue = prop.isCustom ? customPropertyValue : variantValue;
|
|
1942
1925
|
const declaration = `${propertyPrefix}${cssProperty}: ${declarationValue};`;
|
|
1943
1926
|
styles.reset.add(`${toggleProperty}: initial;`);
|
|
1944
|
-
if (!isInheritable && !hasCombinator)
|
|
1945
|
-
styles.reset.add(`${prop.tokenProperty}: initial;`);
|
|
1927
|
+
if (!isInheritable && !hasCombinator) styles.reset.add(`${prop.tokenProperty}: initial;`);
|
|
1946
1928
|
if (selectorConfig.includes(`&${SELECTION_PSEUDO}`)) {
|
|
1947
1929
|
styles.selectorsSelection[layer] ??= /* @__PURE__ */ new Set();
|
|
1948
1930
|
styles.selectorsSelection[layer].add(declaration);
|
|
@@ -1975,8 +1957,7 @@ function createSheet(params) {
|
|
|
1975
1957
|
const propertyValue = getBasePropertyValue(prop.tokenProperty, prop);
|
|
1976
1958
|
const declaration = `${propertyPrefix}${cssProperty}: ${propertyValue};`;
|
|
1977
1959
|
const layer = `${isLogical ? LAYERS.LOGICAL : LAYERS.BASE}${layerIndex}`;
|
|
1978
|
-
if (!isInheritable)
|
|
1979
|
-
styles.reset.add(`${prop.tokenProperty}: initial;`);
|
|
1960
|
+
if (!isInheritable) styles.reset.add(`${prop.tokenProperty}: initial;`);
|
|
1980
1961
|
styles.atomic[layer] ??= /* @__PURE__ */ new Set();
|
|
1981
1962
|
styles.atomic[layer].add(declaration);
|
|
1982
1963
|
if (prop.isGrid) {
|
|
@@ -2034,8 +2015,7 @@ function parseComposeBlocks(composeBlocks, config) {
|
|
|
2034
2015
|
const parsedProperty = Tokenami2__namespace.parseProperty(longProperty);
|
|
2035
2016
|
const calcToggle = Tokenami2__namespace.calcProperty(parsedProperty);
|
|
2036
2017
|
styles[parsedProperty] = value;
|
|
2037
|
-
if (propertyConfig.isCalc)
|
|
2038
|
-
styles[calcToggle] = "/**/";
|
|
2018
|
+
if (propertyConfig.isCalc) styles[calcToggle] = "/**/";
|
|
2039
2019
|
}
|
|
2040
2020
|
}
|
|
2041
2021
|
parsedComposeBlocks[selector] = styles;
|
|
@@ -2053,8 +2033,7 @@ function getPropertyBaseSelectors(composeBlocks, propertyConfigs, config) {
|
|
|
2053
2033
|
selfSelectors.push(...baseSelectors);
|
|
2054
2034
|
} else {
|
|
2055
2035
|
const parsedSelectors = getParsedSelectors(prop.selector, [elemSelector], baseSelectors);
|
|
2056
|
-
if (elemSelector === "&")
|
|
2057
|
-
selfSelectors.push(...parsedSelectors.flat());
|
|
2036
|
+
if (elemSelector === "&") selfSelectors.push(...parsedSelectors.flat());
|
|
2058
2037
|
elemSelectors.push(...parsedSelectors.flat());
|
|
2059
2038
|
}
|
|
2060
2039
|
}
|
|
@@ -2098,8 +2077,7 @@ function getPropertyConfigs(tokenProperties, config) {
|
|
|
2098
2077
|
const customProperties = Object.keys(config.customProperties || {});
|
|
2099
2078
|
for (const property of tokenProperties) {
|
|
2100
2079
|
const parts = Tokenami2__namespace.getTokenPropertyParts(property, config);
|
|
2101
|
-
if (!parts)
|
|
2102
|
-
continue;
|
|
2080
|
+
if (!parts) continue;
|
|
2103
2081
|
const properties = Tokenami2__namespace.getCSSPropertiesForAlias(parts.alias, config.aliases);
|
|
2104
2082
|
const responsiveOrder = parts.responsive ? 1 : 0;
|
|
2105
2083
|
const selectorOrder = parts.selector ? 2 : 0;
|
|
@@ -2121,8 +2099,7 @@ function getAtomicLayerIndex(cssProperty, config) {
|
|
|
2121
2099
|
const validProperties = getValidProperties(config);
|
|
2122
2100
|
const isSupported = validProperties.has(cssProperty);
|
|
2123
2101
|
const initialDepth = isSupported ? 1 : -1;
|
|
2124
|
-
if (cssProperty === "all")
|
|
2125
|
-
return 0;
|
|
2102
|
+
if (cssProperty === "all") return 0;
|
|
2126
2103
|
return SHORTHAND_TO_LONGHAND_ENTRIES.reduce((depth, [shorthand, longhands]) => {
|
|
2127
2104
|
const isLonghand = longhands.includes(cssProperty);
|
|
2128
2105
|
return isLonghand ? depth + getAtomicLayerIndex(shorthand, config) : depth;
|
|
@@ -2135,8 +2112,7 @@ function generateKeyframeRules(tokenValues, config) {
|
|
|
2135
2112
|
const rules = Object.entries(config.keyframes || {}).flatMap(([name, styles]) => {
|
|
2136
2113
|
const nameRegex = new RegExp(`\\b${name}\\b`);
|
|
2137
2114
|
const isUsingKeyframeName = themeValues.some((value) => nameRegex.test(value));
|
|
2138
|
-
if (!isUsingKeyframeName)
|
|
2139
|
-
return [];
|
|
2115
|
+
if (!isUsingKeyframeName) return [];
|
|
2140
2116
|
return [[`@keyframes ${name} { ${stringify.stringify(styles)} }`]];
|
|
2141
2117
|
});
|
|
2142
2118
|
return rules.join(" ");
|
|
@@ -2150,10 +2126,8 @@ function generateThemeTokens(tokenValues, styleSelector, config) {
|
|
|
2150
2126
|
const modeEntries = Object.entries(theme.modes || {});
|
|
2151
2127
|
for (const [mode, theme2] of modeEntries) {
|
|
2152
2128
|
const themeKey = JSON.stringify(theme2);
|
|
2153
|
-
if (themeKey in themeToModes)
|
|
2154
|
-
|
|
2155
|
-
else
|
|
2156
|
-
themeToModes[themeKey] = [mode];
|
|
2129
|
+
if (themeKey in themeToModes) themeToModes[themeKey].push(mode);
|
|
2130
|
+
else themeToModes[themeKey] = [mode];
|
|
2157
2131
|
}
|
|
2158
2132
|
const modeStyles = Object.entries(themeToModes).map(([theme2, modes]) => {
|
|
2159
2133
|
const selector = modes.map(config.themeSelector).join(", ");
|
|
@@ -2201,17 +2175,14 @@ function getCustomPropertyThemeValues(themeValues, config) {
|
|
|
2201
2175
|
var CUSTOM_PROP_REGEX = /\(--[^-][\w-]+/g;
|
|
2202
2176
|
var getPrefixedCustomPropertyValues = (themeValue, customProperties) => {
|
|
2203
2177
|
const variables = themeValue.match(CUSTOM_PROP_REGEX);
|
|
2204
|
-
if (!variables)
|
|
2205
|
-
return null;
|
|
2178
|
+
if (!variables) return null;
|
|
2206
2179
|
return themeValue.replace(CUSTOM_PROP_REGEX, (m) => {
|
|
2207
2180
|
const match = m.replace("(", "");
|
|
2208
2181
|
const tokenProperty4 = Tokenami2__namespace.TokenProperty.safeParse(match);
|
|
2209
|
-
if (!tokenProperty4.success)
|
|
2210
|
-
return m;
|
|
2182
|
+
if (!tokenProperty4.success) return m;
|
|
2211
2183
|
const parts = Tokenami2__namespace.getTokenPropertySplit(tokenProperty4.output);
|
|
2212
2184
|
const isCustom = Boolean(customProperties?.[parts.alias]);
|
|
2213
|
-
if (!isCustom)
|
|
2214
|
-
return m;
|
|
2185
|
+
if (!isCustom) return m;
|
|
2215
2186
|
const tokenPrefix = Tokenami2__namespace.tokenProperty("");
|
|
2216
2187
|
const customPrefixTokenValue = tokenProperty4.output.replace(tokenPrefix, CUSTOM_PROP_PREFIX);
|
|
2217
2188
|
return "(" + customPrefixTokenValue;
|
|
@@ -2249,75 +2220,7 @@ function getParsedSelectors(propertySelector, selectorConfig, elementSelectors)
|
|
|
2249
2220
|
|
|
2250
2221
|
// package.json
|
|
2251
2222
|
var package_default = {
|
|
2252
|
-
|
|
2253
|
-
version: "0.0.80",
|
|
2254
|
-
license: "MIT",
|
|
2255
|
-
type: "module",
|
|
2256
|
-
main: "./dist/index.cjs",
|
|
2257
|
-
module: "./dist/index.js",
|
|
2258
|
-
types: "./dist/index.d.ts",
|
|
2259
|
-
repository: "https://github.com/tokenami/tokenami",
|
|
2260
|
-
publishConfig: {
|
|
2261
|
-
access: "public"
|
|
2262
|
-
},
|
|
2263
|
-
exports: {
|
|
2264
|
-
".": {
|
|
2265
|
-
import: {
|
|
2266
|
-
types: "./dist/index.d.ts",
|
|
2267
|
-
default: "./dist/index.js"
|
|
2268
|
-
},
|
|
2269
|
-
require: {
|
|
2270
|
-
types: "./dist/index.d.cts",
|
|
2271
|
-
default: "./dist/index.cjs"
|
|
2272
|
-
}
|
|
2273
|
-
}
|
|
2274
|
-
},
|
|
2275
|
-
bin: {
|
|
2276
|
-
tokenami: "bin.js"
|
|
2277
|
-
},
|
|
2278
|
-
files: [
|
|
2279
|
-
"dist",
|
|
2280
|
-
"stubs",
|
|
2281
|
-
"bin.js"
|
|
2282
|
-
],
|
|
2283
|
-
scripts: {
|
|
2284
|
-
build: "tsup",
|
|
2285
|
-
dev: "tsup --watch",
|
|
2286
|
-
typecheck: "tsc --noEmit"
|
|
2287
|
-
},
|
|
2288
|
-
devDependencies: {
|
|
2289
|
-
"@types/css-tree": "^2.3.8",
|
|
2290
|
-
"@types/culori": "^2.1.0",
|
|
2291
|
-
"@types/inquirer": "^9.0.7",
|
|
2292
|
-
"@types/node": "^20.3.1",
|
|
2293
|
-
tsup: "^7.0.0",
|
|
2294
|
-
typescript: "^5.1.3"
|
|
2295
|
-
},
|
|
2296
|
-
dependencies: {
|
|
2297
|
-
"@stitches/stringify": "^1.2.8",
|
|
2298
|
-
"@tokenami/config": "workspace:*",
|
|
2299
|
-
"@tokenami/ds": "workspace:*",
|
|
2300
|
-
acorn: "^8.11.3",
|
|
2301
|
-
"acorn-walk": "^8.3.2",
|
|
2302
|
-
browserslist: "^4.24.4",
|
|
2303
|
-
cac: "^6.7.14",
|
|
2304
|
-
chalk: "^5.2.0",
|
|
2305
|
-
chokidar: "^3.5.3",
|
|
2306
|
-
"css-tree": "^3.0.0",
|
|
2307
|
-
csstype: "^3.1.2",
|
|
2308
|
-
culori: "^4.0.1",
|
|
2309
|
-
"fast-glob": "^3.2.12",
|
|
2310
|
-
inquirer: "^9.2.12",
|
|
2311
|
-
jiti: "^1.21.0",
|
|
2312
|
-
lightningcss: "1.29.1",
|
|
2313
|
-
pathe: "^1.1.1",
|
|
2314
|
-
sucrase: "^3.34.0",
|
|
2315
|
-
"trie-search": "^2.0.0"
|
|
2316
|
-
},
|
|
2317
|
-
peerDependencies: {
|
|
2318
|
-
typescript: ">= 5"
|
|
2319
|
-
}
|
|
2320
|
-
};
|
|
2223
|
+
version: "0.0.81"};
|
|
2321
2224
|
|
|
2322
2225
|
// src/ts-plugin/index.ts
|
|
2323
2226
|
init_cjs_shims();
|
|
@@ -2343,8 +2246,7 @@ var TokenamiDiagnostics = class {
|
|
|
2343
2246
|
const processNode = this.#processNode.bind(this);
|
|
2344
2247
|
ts__default.default.forEachChild(sourceFile, function nextNode(node) {
|
|
2345
2248
|
const nodeDiagnostics = processNode(node, sourceFile);
|
|
2346
|
-
if (nodeDiagnostics)
|
|
2347
|
-
diagnostics.push(...nodeDiagnostics);
|
|
2249
|
+
if (nodeDiagnostics) diagnostics.push(...nodeDiagnostics);
|
|
2348
2250
|
ts__default.default.forEachChild(node, nextNode);
|
|
2349
2251
|
});
|
|
2350
2252
|
}
|
|
@@ -2352,16 +2254,14 @@ var TokenamiDiagnostics = class {
|
|
|
2352
2254
|
}
|
|
2353
2255
|
#processNode(node, sourceFile) {
|
|
2354
2256
|
const isDiagnosticPrevented = this.#shouldSuppressDiagnosticForNode(node, sourceFile);
|
|
2355
|
-
if (isDiagnosticPrevented)
|
|
2356
|
-
return;
|
|
2257
|
+
if (isDiagnosticPrevented) return;
|
|
2357
2258
|
if (ts__default.default.isCallExpression(node) && ts__default.default.isPropertyAccessExpression(node.expression) && ts__default.default.isIdentifier(node.expression.expression) && node.expression.expression.text === "css" && node.expression.name.text === "compose" && node.arguments[0] && ts__default.default.isObjectLiteralExpression(node.arguments[0])) {
|
|
2358
2259
|
return this.#validateComposeConfig(node.arguments[0], sourceFile);
|
|
2359
2260
|
}
|
|
2360
2261
|
if (ts__default.default.isPropertyAssignment(node)) {
|
|
2361
2262
|
const nodeProperty = ts__default.default.isStringLiteral(node.name) ? node.name.text : null;
|
|
2362
2263
|
const property = Tokenami2__namespace.TokenProperty.safeParse(nodeProperty);
|
|
2363
|
-
if (!property.success)
|
|
2364
|
-
return;
|
|
2264
|
+
if (!property.success) return;
|
|
2365
2265
|
return this.#validateTokenamiProperty(property.output, node, sourceFile);
|
|
2366
2266
|
}
|
|
2367
2267
|
}
|
|
@@ -2369,8 +2269,7 @@ var TokenamiDiagnostics = class {
|
|
|
2369
2269
|
const { variants } = Tokenami2__namespace.getTokenPropertySplit(property);
|
|
2370
2270
|
const parts = Tokenami2__namespace.getTokenPropertyParts(property, this.#config);
|
|
2371
2271
|
const isArbitrarySelector = variants.some(Tokenami2__namespace.getArbitrarySelector);
|
|
2372
|
-
if (!variants.length || parts || isArbitrarySelector)
|
|
2373
|
-
return;
|
|
2272
|
+
if (!variants.length || parts || isArbitrarySelector) return;
|
|
2374
2273
|
const selector = variants.join("_");
|
|
2375
2274
|
const isEmptyArbSelector = variants.includes("{}");
|
|
2376
2275
|
const arbSuffix = isEmptyArbSelector ? ` Add an arbitrary selector or remove '${selector}'.` : "";
|
|
@@ -2398,8 +2297,7 @@ var TokenamiDiagnostics = class {
|
|
|
2398
2297
|
const length = prop.getWidth(sourceFile);
|
|
2399
2298
|
return [{ ...diagnostic, start, length }];
|
|
2400
2299
|
}
|
|
2401
|
-
if (!ts__default.default.isPropertyAssignment(prop))
|
|
2402
|
-
continue;
|
|
2300
|
+
if (!ts__default.default.isPropertyAssignment(prop)) continue;
|
|
2403
2301
|
const key = prop.name;
|
|
2404
2302
|
const value = prop.initializer;
|
|
2405
2303
|
if (ts__default.default.isComputedPropertyName(key)) {
|
|
@@ -2417,8 +2315,7 @@ var TokenamiDiagnostics = class {
|
|
|
2417
2315
|
}
|
|
2418
2316
|
}
|
|
2419
2317
|
#shouldSuppressDiagnosticForNode(node, sourceFile) {
|
|
2420
|
-
if (!sourceFile)
|
|
2421
|
-
return false;
|
|
2318
|
+
if (!sourceFile) return false;
|
|
2422
2319
|
const lineStarts = sourceFile.getLineStarts();
|
|
2423
2320
|
const nodeStartPos = node.getStart(sourceFile);
|
|
2424
2321
|
const nodeStartLine = sourceFile.getLineAndCharacterOfPosition(nodeStartPos).line;
|
|
@@ -2468,8 +2365,7 @@ var run = () => {
|
|
|
2468
2365
|
const cwd = process.cwd();
|
|
2469
2366
|
cli.command("init").option("-c, --config [path]", "Path to a custom config file").action(async (_, flags) => {
|
|
2470
2367
|
const projectConfig = getProjectConfig(cwd);
|
|
2471
|
-
if (projectConfig)
|
|
2472
|
-
questions.shift();
|
|
2368
|
+
if (projectConfig) questions.shift();
|
|
2473
2369
|
const answers = await inquirer__default.default.prompt(questions);
|
|
2474
2370
|
const type = projectConfig?.type ?? answers.type;
|
|
2475
2371
|
const extensions = projectConfig?.type === "ts" ? "ts,tsx" : "js,jsx";
|
|
@@ -2529,8 +2425,7 @@ var run = () => {
|
|
|
2529
2425
|
const targets = lightning.browserslistToTargets(browsers);
|
|
2530
2426
|
let config = getConfigAtPath(configPath);
|
|
2531
2427
|
config.include = flags.files || config.include;
|
|
2532
|
-
if (!config.include.length)
|
|
2533
|
-
error("Provide a glob pattern to include files");
|
|
2428
|
+
if (!config.include.length) error("Provide a glob pattern to include files");
|
|
2534
2429
|
async function regenerateStylesheet(file, config2) {
|
|
2535
2430
|
const generateTime = startTimer();
|
|
2536
2431
|
const tokens2 = await findUsedTokens(cwd, config2);
|
|
@@ -2568,15 +2463,13 @@ function getProjectConfig(cwd) {
|
|
|
2568
2463
|
const tsconfigPath = ts__default.default.findConfigFile(cwd, ts__default.default.sys.fileExists, "tsconfig.json");
|
|
2569
2464
|
if (tsconfigPath) {
|
|
2570
2465
|
const config = ts__default.default.readConfigFile(tsconfigPath, ts__default.default.sys.readFile);
|
|
2571
|
-
if (config.error)
|
|
2572
|
-
return null;
|
|
2466
|
+
if (config.error) return null;
|
|
2573
2467
|
return { type: "ts", ...config };
|
|
2574
2468
|
}
|
|
2575
2469
|
const jsconfigPath = ts__default.default.findConfigFile(cwd, ts__default.default.sys.fileExists, "jsconfig.json");
|
|
2576
2470
|
if (jsconfigPath) {
|
|
2577
2471
|
const config = ts__default.default.readConfigFile(jsconfigPath, ts__default.default.sys.readFile);
|
|
2578
|
-
if (config.error)
|
|
2579
|
-
return null;
|
|
2472
|
+
if (config.error) return null;
|
|
2580
2473
|
return { type: "js", ...config };
|
|
2581
2474
|
}
|
|
2582
2475
|
return null;
|
|
@@ -2627,8 +2520,7 @@ async function findUsedTokens(cwd, config) {
|
|
|
2627
2520
|
function matchBaseComposeBlocks(ast) {
|
|
2628
2521
|
const composeBlocks = findComposeBlocks(ast);
|
|
2629
2522
|
let result = {};
|
|
2630
|
-
if (!composeBlocks)
|
|
2631
|
-
return result;
|
|
2523
|
+
if (!composeBlocks) return result;
|
|
2632
2524
|
for (const node of composeBlocks) {
|
|
2633
2525
|
let styles;
|
|
2634
2526
|
for (const tokenProperty4 of node.properties) {
|
|
@@ -2652,16 +2544,14 @@ function matchTokens(content, theme) {
|
|
|
2652
2544
|
const variableMatches = uniqueMatches.filter((match) => match !== Tokenami2__namespace.gridProperty());
|
|
2653
2545
|
const values = variableMatches.flatMap((match) => {
|
|
2654
2546
|
const valueProperty = Tokenami2__namespace.TokenValue.safeParse(`var(${match})`);
|
|
2655
|
-
if (!valueProperty.success)
|
|
2656
|
-
return [];
|
|
2547
|
+
if (!valueProperty.success) return [];
|
|
2657
2548
|
const themeValues = getThemeValuesByThemeMode(valueProperty.output, theme);
|
|
2658
2549
|
return Object.entries(themeValues).length ? [valueProperty.output] : [];
|
|
2659
2550
|
});
|
|
2660
2551
|
const properties = variableMatches.flatMap((match) => {
|
|
2661
2552
|
const tokenProperty4 = Tokenami2__namespace.TokenProperty.safeParse(match);
|
|
2662
2553
|
const isValue = values.includes(`var(${match})`);
|
|
2663
|
-
if (isValue || !tokenProperty4.success)
|
|
2664
|
-
return [];
|
|
2554
|
+
if (isValue || !tokenProperty4.success) return [];
|
|
2665
2555
|
return tokenProperty4.output;
|
|
2666
2556
|
});
|
|
2667
2557
|
return { properties, values };
|
|
@@ -2688,8 +2578,7 @@ function findSheetComposeBlocks(fileContents) {
|
|
|
2688
2578
|
csstree__namespace.walk(node, {
|
|
2689
2579
|
visit: "Rule",
|
|
2690
2580
|
enter(ruleNode) {
|
|
2691
|
-
if (!ruleNode.prelude || !ruleNode.block)
|
|
2692
|
-
return;
|
|
2581
|
+
if (!ruleNode.prelude || !ruleNode.block) return;
|
|
2693
2582
|
const selector = csstree__namespace.generate(ruleNode.prelude).trim();
|
|
2694
2583
|
let styles = {};
|
|
2695
2584
|
csstree__namespace.walk(ruleNode.block, {
|