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.js
CHANGED
|
@@ -29,8 +29,7 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
|
29
29
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
30
30
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
31
31
|
}) : x)(function(x) {
|
|
32
|
-
if (typeof require !== "undefined")
|
|
33
|
-
return require.apply(this, arguments);
|
|
32
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
34
33
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
35
34
|
});
|
|
36
35
|
var __esm = (fn, res) => function __init() {
|
|
@@ -57,7 +56,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
57
56
|
));
|
|
58
57
|
var getFilename, getDirname, __dirname, __filename;
|
|
59
58
|
var init_esm_shims = __esm({
|
|
60
|
-
"../../node_modules/.pnpm/tsup@
|
|
59
|
+
"../../node_modules/.pnpm/tsup@8.4.0_jiti@1.21.6_typescript@5.4.5/node_modules/tsup/assets/esm_shims.js"() {
|
|
61
60
|
getFilename = () => fileURLToPath(import.meta.url);
|
|
62
61
|
getDirname = () => path.dirname(getFilename());
|
|
63
62
|
__dirname = /* @__PURE__ */ getDirname();
|
|
@@ -256,8 +255,7 @@ var require_HashArray = __commonJS({
|
|
|
256
255
|
continue;
|
|
257
256
|
}
|
|
258
257
|
this._map[inst].push(obj);
|
|
259
|
-
} else
|
|
260
|
-
this._map[inst] = [obj];
|
|
258
|
+
} else this._map[inst] = [obj];
|
|
261
259
|
}
|
|
262
260
|
}
|
|
263
261
|
if (!needsDupCheck || this._list.indexOf(obj) == -1)
|
|
@@ -346,8 +344,7 @@ var require_HashArray = __commonJS({
|
|
|
346
344
|
count = Math.min(Math.max(max - min, 1), count);
|
|
347
345
|
while (res.length < count) {
|
|
348
346
|
var r = Math.floor(min + Math.random() * (max + 1));
|
|
349
|
-
if (map[r])
|
|
350
|
-
continue;
|
|
347
|
+
if (map[r]) continue;
|
|
351
348
|
map[r] = true;
|
|
352
349
|
res.push(r);
|
|
353
350
|
}
|
|
@@ -620,8 +617,7 @@ var require_crypt = __commonJS({
|
|
|
620
617
|
base64ToBytes: function(base64) {
|
|
621
618
|
base64 = base64.replace(/[^A-Z0-9+\/]/ig, "");
|
|
622
619
|
for (var bytes = [], i = 0, imod4 = 0; i < base64.length; imod4 = ++i % 4) {
|
|
623
|
-
if (imod4 == 0)
|
|
624
|
-
continue;
|
|
620
|
+
if (imod4 == 0) continue;
|
|
625
621
|
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);
|
|
626
622
|
}
|
|
627
623
|
return bytes;
|
|
@@ -870,16 +866,14 @@ var require_TrieSearch = __commonJS({
|
|
|
870
866
|
}
|
|
871
867
|
TrieSearch2.prototype = {
|
|
872
868
|
add: function(item, customKeys) {
|
|
873
|
-
if (this.options.cache)
|
|
874
|
-
this.clearCache();
|
|
869
|
+
if (this.options.cache) this.clearCache();
|
|
875
870
|
if (typeof customKeys === "number") {
|
|
876
871
|
customKeys = void 0;
|
|
877
872
|
}
|
|
878
873
|
var keyFields = customKeys || this.keyFields;
|
|
879
874
|
for (var k in keyFields) {
|
|
880
875
|
var key = keyFields[k], isKeyArr = key instanceof Array, val = isKeyArr ? deepLookup(item, key) : item[key];
|
|
881
|
-
if (!val)
|
|
882
|
-
continue;
|
|
876
|
+
if (!val) continue;
|
|
883
877
|
val = val.toString();
|
|
884
878
|
if (this.options.ignoreCase) {
|
|
885
879
|
val = val.toLowerCase();
|
|
@@ -899,14 +893,12 @@ var require_TrieSearch = __commonJS({
|
|
|
899
893
|
* @param keyFields The keyfields in which to search for this phrase to remove
|
|
900
894
|
*/
|
|
901
895
|
remove: function(phrase, keyFields) {
|
|
902
|
-
if (!phrase)
|
|
903
|
-
return;
|
|
896
|
+
if (!phrase) return;
|
|
904
897
|
phrase = phrase.toString();
|
|
905
898
|
phrase = this.options.ignoreCase ? phrase.toLowerCase() : phrase;
|
|
906
899
|
keyFields = keyFields || this.keyFields;
|
|
907
900
|
keyFields = keyFields instanceof Array ? keyFields : [keyFields];
|
|
908
|
-
if (this.options.cache)
|
|
909
|
-
this.clearCache();
|
|
901
|
+
if (this.options.cache) this.clearCache();
|
|
910
902
|
var diacriticalVariants = this.expandString(phrase);
|
|
911
903
|
for (var variant of diacriticalVariants) {
|
|
912
904
|
var words = this.options.splitOnRegEx ? variant.split(this.options.splitOnRegEx) : [variant];
|
|
@@ -1058,17 +1050,14 @@ var require_TrieSearch = __commonJS({
|
|
|
1058
1050
|
return [];
|
|
1059
1051
|
keyArr = [key.substring(0, this.options.min)];
|
|
1060
1052
|
keyArr = keyArr.concat(key.substring(this.options.min).split(""));
|
|
1061
|
-
} else
|
|
1062
|
-
keyArr = key.split("");
|
|
1053
|
+
} else keyArr = key.split("");
|
|
1063
1054
|
return keyArr;
|
|
1064
1055
|
},
|
|
1065
1056
|
findNode: function(key) {
|
|
1066
1057
|
return f(this.keyToArr(key), this.root);
|
|
1067
1058
|
function f(keyArr, node) {
|
|
1068
|
-
if (!node)
|
|
1069
|
-
|
|
1070
|
-
if (keyArr.length === 0)
|
|
1071
|
-
return node;
|
|
1059
|
+
if (!node) return void 0;
|
|
1060
|
+
if (keyArr.length === 0) return node;
|
|
1072
1061
|
var k = keyArr.shift();
|
|
1073
1062
|
return f(keyArr, node[k]);
|
|
1074
1063
|
}
|
|
@@ -1105,8 +1094,7 @@ var require_TrieSearch = __commonJS({
|
|
|
1105
1094
|
var item = node2.value[i];
|
|
1106
1095
|
if (!limit || all.length < limit) {
|
|
1107
1096
|
const id = self.getId(item);
|
|
1108
|
-
if (dedupDict[id])
|
|
1109
|
-
continue;
|
|
1097
|
+
if (dedupDict[id]) continue;
|
|
1110
1098
|
all.push(item);
|
|
1111
1099
|
dedupDict[id] = item;
|
|
1112
1100
|
}
|
|
@@ -1140,8 +1128,7 @@ var require_TrieSearch = __commonJS({
|
|
|
1140
1128
|
return this.get(phrases, reducer, limit);
|
|
1141
1129
|
},
|
|
1142
1130
|
getId: function(item, customKeys) {
|
|
1143
|
-
if (item.$tsid)
|
|
1144
|
-
return item.$tsid;
|
|
1131
|
+
if (item.$tsid) return item.$tsid;
|
|
1145
1132
|
if (!this.options.idFieldOrFunction) {
|
|
1146
1133
|
var s = "";
|
|
1147
1134
|
var kf = customKeys || this.keyFields;
|
|
@@ -1726,8 +1713,7 @@ function getConfigPath(cwd, path2, type) {
|
|
|
1726
1713
|
function getConfigAtPath(path2, opts = { cache: true }) {
|
|
1727
1714
|
const config = (() => {
|
|
1728
1715
|
try {
|
|
1729
|
-
if (!opts.cache)
|
|
1730
|
-
delete __require.cache[__require.resolve(path2)];
|
|
1716
|
+
if (!opts.cache) delete __require.cache[__require.resolve(path2)];
|
|
1731
1717
|
return __require(path2);
|
|
1732
1718
|
} catch {
|
|
1733
1719
|
return lazyJiti({ cache: opts.cache })(path2);
|
|
@@ -1754,8 +1740,7 @@ function getThemeValueByTokenValueEntries(tokenValues, theme) {
|
|
|
1754
1740
|
return sorted.flatMap((tokenValue2) => {
|
|
1755
1741
|
const parts = Tokenami2.getTokenValueParts(tokenValue2);
|
|
1756
1742
|
const value = theme[parts.themeKey]?.[parts.token];
|
|
1757
|
-
if (value == null)
|
|
1758
|
-
return [];
|
|
1743
|
+
if (value == null) return [];
|
|
1759
1744
|
const valueString = String(value);
|
|
1760
1745
|
const tokenValues2 = findTokenValuesInThemeValue(valueString);
|
|
1761
1746
|
const themeValuesEntries = getThemeValueByTokenValueEntries(tokenValues2, theme);
|
|
@@ -1861,8 +1846,7 @@ function generate(params) {
|
|
|
1861
1846
|
}
|
|
1862
1847
|
}
|
|
1863
1848
|
function createSheet(params) {
|
|
1864
|
-
if (!params.tokens.properties.length)
|
|
1865
|
-
return "";
|
|
1849
|
+
if (!params.tokens.properties.length) return "";
|
|
1866
1850
|
const tokenProperties = params.tokens.properties;
|
|
1867
1851
|
const tokenValues = params.tokens.values;
|
|
1868
1852
|
const composeBlocks = parseComposeBlocks(params.tokens.composeBlocks, params.config);
|
|
@@ -1893,8 +1877,7 @@ function createSheet(params) {
|
|
|
1893
1877
|
const layerIndex = getAtomicLayerIndex(cssProperty, params.config);
|
|
1894
1878
|
const toggleKey = prop.responsive || prop.selector;
|
|
1895
1879
|
const propertyPrefix = prop.isCustom ? CUSTOM_PROP_PREFIX : "";
|
|
1896
|
-
if (layerIndex === -1)
|
|
1897
|
-
continue;
|
|
1880
|
+
if (layerIndex === -1) continue;
|
|
1898
1881
|
if (prop.variant && toggleKey) {
|
|
1899
1882
|
const responsive = getResponsiveSelectorFromConfig(prop.responsive, params.config);
|
|
1900
1883
|
const selectorConfig = getPropertyConfigSelector(prop.selector, params.config);
|
|
@@ -1909,8 +1892,7 @@ function createSheet(params) {
|
|
|
1909
1892
|
const declarationValue = prop.isCustom ? customPropertyValue : variantValue;
|
|
1910
1893
|
const declaration = `${propertyPrefix}${cssProperty}: ${declarationValue};`;
|
|
1911
1894
|
styles.reset.add(`${toggleProperty}: initial;`);
|
|
1912
|
-
if (!isInheritable && !hasCombinator)
|
|
1913
|
-
styles.reset.add(`${prop.tokenProperty}: initial;`);
|
|
1895
|
+
if (!isInheritable && !hasCombinator) styles.reset.add(`${prop.tokenProperty}: initial;`);
|
|
1914
1896
|
if (selectorConfig.includes(`&${SELECTION_PSEUDO}`)) {
|
|
1915
1897
|
styles.selectorsSelection[layer] ??= /* @__PURE__ */ new Set();
|
|
1916
1898
|
styles.selectorsSelection[layer].add(declaration);
|
|
@@ -1943,8 +1925,7 @@ function createSheet(params) {
|
|
|
1943
1925
|
const propertyValue = getBasePropertyValue(prop.tokenProperty, prop);
|
|
1944
1926
|
const declaration = `${propertyPrefix}${cssProperty}: ${propertyValue};`;
|
|
1945
1927
|
const layer = `${isLogical ? LAYERS.LOGICAL : LAYERS.BASE}${layerIndex}`;
|
|
1946
|
-
if (!isInheritable)
|
|
1947
|
-
styles.reset.add(`${prop.tokenProperty}: initial;`);
|
|
1928
|
+
if (!isInheritable) styles.reset.add(`${prop.tokenProperty}: initial;`);
|
|
1948
1929
|
styles.atomic[layer] ??= /* @__PURE__ */ new Set();
|
|
1949
1930
|
styles.atomic[layer].add(declaration);
|
|
1950
1931
|
if (prop.isGrid) {
|
|
@@ -2002,8 +1983,7 @@ function parseComposeBlocks(composeBlocks, config) {
|
|
|
2002
1983
|
const parsedProperty = Tokenami2.parseProperty(longProperty);
|
|
2003
1984
|
const calcToggle = Tokenami2.calcProperty(parsedProperty);
|
|
2004
1985
|
styles[parsedProperty] = value;
|
|
2005
|
-
if (propertyConfig.isCalc)
|
|
2006
|
-
styles[calcToggle] = "/**/";
|
|
1986
|
+
if (propertyConfig.isCalc) styles[calcToggle] = "/**/";
|
|
2007
1987
|
}
|
|
2008
1988
|
}
|
|
2009
1989
|
parsedComposeBlocks[selector] = styles;
|
|
@@ -2021,8 +2001,7 @@ function getPropertyBaseSelectors(composeBlocks, propertyConfigs, config) {
|
|
|
2021
2001
|
selfSelectors.push(...baseSelectors);
|
|
2022
2002
|
} else {
|
|
2023
2003
|
const parsedSelectors = getParsedSelectors(prop.selector, [elemSelector], baseSelectors);
|
|
2024
|
-
if (elemSelector === "&")
|
|
2025
|
-
selfSelectors.push(...parsedSelectors.flat());
|
|
2004
|
+
if (elemSelector === "&") selfSelectors.push(...parsedSelectors.flat());
|
|
2026
2005
|
elemSelectors.push(...parsedSelectors.flat());
|
|
2027
2006
|
}
|
|
2028
2007
|
}
|
|
@@ -2066,8 +2045,7 @@ function getPropertyConfigs(tokenProperties, config) {
|
|
|
2066
2045
|
const customProperties = Object.keys(config.customProperties || {});
|
|
2067
2046
|
for (const property of tokenProperties) {
|
|
2068
2047
|
const parts = Tokenami2.getTokenPropertyParts(property, config);
|
|
2069
|
-
if (!parts)
|
|
2070
|
-
continue;
|
|
2048
|
+
if (!parts) continue;
|
|
2071
2049
|
const properties = Tokenami2.getCSSPropertiesForAlias(parts.alias, config.aliases);
|
|
2072
2050
|
const responsiveOrder = parts.responsive ? 1 : 0;
|
|
2073
2051
|
const selectorOrder = parts.selector ? 2 : 0;
|
|
@@ -2089,8 +2067,7 @@ function getAtomicLayerIndex(cssProperty, config) {
|
|
|
2089
2067
|
const validProperties = getValidProperties(config);
|
|
2090
2068
|
const isSupported = validProperties.has(cssProperty);
|
|
2091
2069
|
const initialDepth = isSupported ? 1 : -1;
|
|
2092
|
-
if (cssProperty === "all")
|
|
2093
|
-
return 0;
|
|
2070
|
+
if (cssProperty === "all") return 0;
|
|
2094
2071
|
return SHORTHAND_TO_LONGHAND_ENTRIES.reduce((depth, [shorthand, longhands]) => {
|
|
2095
2072
|
const isLonghand = longhands.includes(cssProperty);
|
|
2096
2073
|
return isLonghand ? depth + getAtomicLayerIndex(shorthand, config) : depth;
|
|
@@ -2103,8 +2080,7 @@ function generateKeyframeRules(tokenValues, config) {
|
|
|
2103
2080
|
const rules = Object.entries(config.keyframes || {}).flatMap(([name, styles]) => {
|
|
2104
2081
|
const nameRegex = new RegExp(`\\b${name}\\b`);
|
|
2105
2082
|
const isUsingKeyframeName = themeValues.some((value) => nameRegex.test(value));
|
|
2106
|
-
if (!isUsingKeyframeName)
|
|
2107
|
-
return [];
|
|
2083
|
+
if (!isUsingKeyframeName) return [];
|
|
2108
2084
|
return [[`@keyframes ${name} { ${stringify(styles)} }`]];
|
|
2109
2085
|
});
|
|
2110
2086
|
return rules.join(" ");
|
|
@@ -2118,10 +2094,8 @@ function generateThemeTokens(tokenValues, styleSelector, config) {
|
|
|
2118
2094
|
const modeEntries = Object.entries(theme.modes || {});
|
|
2119
2095
|
for (const [mode, theme2] of modeEntries) {
|
|
2120
2096
|
const themeKey = JSON.stringify(theme2);
|
|
2121
|
-
if (themeKey in themeToModes)
|
|
2122
|
-
|
|
2123
|
-
else
|
|
2124
|
-
themeToModes[themeKey] = [mode];
|
|
2097
|
+
if (themeKey in themeToModes) themeToModes[themeKey].push(mode);
|
|
2098
|
+
else themeToModes[themeKey] = [mode];
|
|
2125
2099
|
}
|
|
2126
2100
|
const modeStyles = Object.entries(themeToModes).map(([theme2, modes]) => {
|
|
2127
2101
|
const selector = modes.map(config.themeSelector).join(", ");
|
|
@@ -2169,17 +2143,14 @@ function getCustomPropertyThemeValues(themeValues, config) {
|
|
|
2169
2143
|
var CUSTOM_PROP_REGEX = /\(--[^-][\w-]+/g;
|
|
2170
2144
|
var getPrefixedCustomPropertyValues = (themeValue, customProperties) => {
|
|
2171
2145
|
const variables = themeValue.match(CUSTOM_PROP_REGEX);
|
|
2172
|
-
if (!variables)
|
|
2173
|
-
return null;
|
|
2146
|
+
if (!variables) return null;
|
|
2174
2147
|
return themeValue.replace(CUSTOM_PROP_REGEX, (m) => {
|
|
2175
2148
|
const match = m.replace("(", "");
|
|
2176
2149
|
const tokenProperty4 = Tokenami2.TokenProperty.safeParse(match);
|
|
2177
|
-
if (!tokenProperty4.success)
|
|
2178
|
-
return m;
|
|
2150
|
+
if (!tokenProperty4.success) return m;
|
|
2179
2151
|
const parts = Tokenami2.getTokenPropertySplit(tokenProperty4.output);
|
|
2180
2152
|
const isCustom = Boolean(customProperties?.[parts.alias]);
|
|
2181
|
-
if (!isCustom)
|
|
2182
|
-
return m;
|
|
2153
|
+
if (!isCustom) return m;
|
|
2183
2154
|
const tokenPrefix = Tokenami2.tokenProperty("");
|
|
2184
2155
|
const customPrefixTokenValue = tokenProperty4.output.replace(tokenPrefix, CUSTOM_PROP_PREFIX);
|
|
2185
2156
|
return "(" + customPrefixTokenValue;
|
|
@@ -2217,75 +2188,7 @@ function getParsedSelectors(propertySelector, selectorConfig, elementSelectors)
|
|
|
2217
2188
|
|
|
2218
2189
|
// package.json
|
|
2219
2190
|
var package_default = {
|
|
2220
|
-
|
|
2221
|
-
version: "0.0.80",
|
|
2222
|
-
license: "MIT",
|
|
2223
|
-
type: "module",
|
|
2224
|
-
main: "./dist/index.cjs",
|
|
2225
|
-
module: "./dist/index.js",
|
|
2226
|
-
types: "./dist/index.d.ts",
|
|
2227
|
-
repository: "https://github.com/tokenami/tokenami",
|
|
2228
|
-
publishConfig: {
|
|
2229
|
-
access: "public"
|
|
2230
|
-
},
|
|
2231
|
-
exports: {
|
|
2232
|
-
".": {
|
|
2233
|
-
import: {
|
|
2234
|
-
types: "./dist/index.d.ts",
|
|
2235
|
-
default: "./dist/index.js"
|
|
2236
|
-
},
|
|
2237
|
-
require: {
|
|
2238
|
-
types: "./dist/index.d.cts",
|
|
2239
|
-
default: "./dist/index.cjs"
|
|
2240
|
-
}
|
|
2241
|
-
}
|
|
2242
|
-
},
|
|
2243
|
-
bin: {
|
|
2244
|
-
tokenami: "bin.js"
|
|
2245
|
-
},
|
|
2246
|
-
files: [
|
|
2247
|
-
"dist",
|
|
2248
|
-
"stubs",
|
|
2249
|
-
"bin.js"
|
|
2250
|
-
],
|
|
2251
|
-
scripts: {
|
|
2252
|
-
build: "tsup",
|
|
2253
|
-
dev: "tsup --watch",
|
|
2254
|
-
typecheck: "tsc --noEmit"
|
|
2255
|
-
},
|
|
2256
|
-
devDependencies: {
|
|
2257
|
-
"@types/css-tree": "^2.3.8",
|
|
2258
|
-
"@types/culori": "^2.1.0",
|
|
2259
|
-
"@types/inquirer": "^9.0.7",
|
|
2260
|
-
"@types/node": "^20.3.1",
|
|
2261
|
-
tsup: "^7.0.0",
|
|
2262
|
-
typescript: "^5.1.3"
|
|
2263
|
-
},
|
|
2264
|
-
dependencies: {
|
|
2265
|
-
"@stitches/stringify": "^1.2.8",
|
|
2266
|
-
"@tokenami/config": "workspace:*",
|
|
2267
|
-
"@tokenami/ds": "workspace:*",
|
|
2268
|
-
acorn: "^8.11.3",
|
|
2269
|
-
"acorn-walk": "^8.3.2",
|
|
2270
|
-
browserslist: "^4.24.4",
|
|
2271
|
-
cac: "^6.7.14",
|
|
2272
|
-
chalk: "^5.2.0",
|
|
2273
|
-
chokidar: "^3.5.3",
|
|
2274
|
-
"css-tree": "^3.0.0",
|
|
2275
|
-
csstype: "^3.1.2",
|
|
2276
|
-
culori: "^4.0.1",
|
|
2277
|
-
"fast-glob": "^3.2.12",
|
|
2278
|
-
inquirer: "^9.2.12",
|
|
2279
|
-
jiti: "^1.21.0",
|
|
2280
|
-
lightningcss: "1.29.1",
|
|
2281
|
-
pathe: "^1.1.1",
|
|
2282
|
-
sucrase: "^3.34.0",
|
|
2283
|
-
"trie-search": "^2.0.0"
|
|
2284
|
-
},
|
|
2285
|
-
peerDependencies: {
|
|
2286
|
-
typescript: ">= 5"
|
|
2287
|
-
}
|
|
2288
|
-
};
|
|
2191
|
+
version: "0.0.81"};
|
|
2289
2192
|
|
|
2290
2193
|
// src/ts-plugin/index.ts
|
|
2291
2194
|
init_esm_shims();
|
|
@@ -2311,8 +2214,7 @@ var TokenamiDiagnostics = class {
|
|
|
2311
2214
|
const processNode = this.#processNode.bind(this);
|
|
2312
2215
|
ts.forEachChild(sourceFile, function nextNode(node) {
|
|
2313
2216
|
const nodeDiagnostics = processNode(node, sourceFile);
|
|
2314
|
-
if (nodeDiagnostics)
|
|
2315
|
-
diagnostics.push(...nodeDiagnostics);
|
|
2217
|
+
if (nodeDiagnostics) diagnostics.push(...nodeDiagnostics);
|
|
2316
2218
|
ts.forEachChild(node, nextNode);
|
|
2317
2219
|
});
|
|
2318
2220
|
}
|
|
@@ -2320,16 +2222,14 @@ var TokenamiDiagnostics = class {
|
|
|
2320
2222
|
}
|
|
2321
2223
|
#processNode(node, sourceFile) {
|
|
2322
2224
|
const isDiagnosticPrevented = this.#shouldSuppressDiagnosticForNode(node, sourceFile);
|
|
2323
|
-
if (isDiagnosticPrevented)
|
|
2324
|
-
return;
|
|
2225
|
+
if (isDiagnosticPrevented) return;
|
|
2325
2226
|
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.expression) && node.expression.expression.text === "css" && node.expression.name.text === "compose" && node.arguments[0] && ts.isObjectLiteralExpression(node.arguments[0])) {
|
|
2326
2227
|
return this.#validateComposeConfig(node.arguments[0], sourceFile);
|
|
2327
2228
|
}
|
|
2328
2229
|
if (ts.isPropertyAssignment(node)) {
|
|
2329
2230
|
const nodeProperty = ts.isStringLiteral(node.name) ? node.name.text : null;
|
|
2330
2231
|
const property = Tokenami2.TokenProperty.safeParse(nodeProperty);
|
|
2331
|
-
if (!property.success)
|
|
2332
|
-
return;
|
|
2232
|
+
if (!property.success) return;
|
|
2333
2233
|
return this.#validateTokenamiProperty(property.output, node, sourceFile);
|
|
2334
2234
|
}
|
|
2335
2235
|
}
|
|
@@ -2337,8 +2237,7 @@ var TokenamiDiagnostics = class {
|
|
|
2337
2237
|
const { variants } = Tokenami2.getTokenPropertySplit(property);
|
|
2338
2238
|
const parts = Tokenami2.getTokenPropertyParts(property, this.#config);
|
|
2339
2239
|
const isArbitrarySelector = variants.some(Tokenami2.getArbitrarySelector);
|
|
2340
|
-
if (!variants.length || parts || isArbitrarySelector)
|
|
2341
|
-
return;
|
|
2240
|
+
if (!variants.length || parts || isArbitrarySelector) return;
|
|
2342
2241
|
const selector = variants.join("_");
|
|
2343
2242
|
const isEmptyArbSelector = variants.includes("{}");
|
|
2344
2243
|
const arbSuffix = isEmptyArbSelector ? ` Add an arbitrary selector or remove '${selector}'.` : "";
|
|
@@ -2366,8 +2265,7 @@ var TokenamiDiagnostics = class {
|
|
|
2366
2265
|
const length = prop.getWidth(sourceFile);
|
|
2367
2266
|
return [{ ...diagnostic, start, length }];
|
|
2368
2267
|
}
|
|
2369
|
-
if (!ts.isPropertyAssignment(prop))
|
|
2370
|
-
continue;
|
|
2268
|
+
if (!ts.isPropertyAssignment(prop)) continue;
|
|
2371
2269
|
const key = prop.name;
|
|
2372
2270
|
const value = prop.initializer;
|
|
2373
2271
|
if (ts.isComputedPropertyName(key)) {
|
|
@@ -2385,8 +2283,7 @@ var TokenamiDiagnostics = class {
|
|
|
2385
2283
|
}
|
|
2386
2284
|
}
|
|
2387
2285
|
#shouldSuppressDiagnosticForNode(node, sourceFile) {
|
|
2388
|
-
if (!sourceFile)
|
|
2389
|
-
return false;
|
|
2286
|
+
if (!sourceFile) return false;
|
|
2390
2287
|
const lineStarts = sourceFile.getLineStarts();
|
|
2391
2288
|
const nodeStartPos = node.getStart(sourceFile);
|
|
2392
2289
|
const nodeStartLine = sourceFile.getLineAndCharacterOfPosition(nodeStartPos).line;
|
|
@@ -2436,8 +2333,7 @@ var run = () => {
|
|
|
2436
2333
|
const cwd = process.cwd();
|
|
2437
2334
|
cli.command("init").option("-c, --config [path]", "Path to a custom config file").action(async (_, flags) => {
|
|
2438
2335
|
const projectConfig = getProjectConfig(cwd);
|
|
2439
|
-
if (projectConfig)
|
|
2440
|
-
questions.shift();
|
|
2336
|
+
if (projectConfig) questions.shift();
|
|
2441
2337
|
const answers = await inquirer.prompt(questions);
|
|
2442
2338
|
const type = projectConfig?.type ?? answers.type;
|
|
2443
2339
|
const extensions = projectConfig?.type === "ts" ? "ts,tsx" : "js,jsx";
|
|
@@ -2497,8 +2393,7 @@ var run = () => {
|
|
|
2497
2393
|
const targets = browserslistToTargets(browsers);
|
|
2498
2394
|
let config = getConfigAtPath(configPath);
|
|
2499
2395
|
config.include = flags.files || config.include;
|
|
2500
|
-
if (!config.include.length)
|
|
2501
|
-
error("Provide a glob pattern to include files");
|
|
2396
|
+
if (!config.include.length) error("Provide a glob pattern to include files");
|
|
2502
2397
|
async function regenerateStylesheet(file, config2) {
|
|
2503
2398
|
const generateTime = startTimer();
|
|
2504
2399
|
const tokens2 = await findUsedTokens(cwd, config2);
|
|
@@ -2536,15 +2431,13 @@ function getProjectConfig(cwd) {
|
|
|
2536
2431
|
const tsconfigPath = ts.findConfigFile(cwd, ts.sys.fileExists, "tsconfig.json");
|
|
2537
2432
|
if (tsconfigPath) {
|
|
2538
2433
|
const config = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
|
|
2539
|
-
if (config.error)
|
|
2540
|
-
return null;
|
|
2434
|
+
if (config.error) return null;
|
|
2541
2435
|
return { type: "ts", ...config };
|
|
2542
2436
|
}
|
|
2543
2437
|
const jsconfigPath = ts.findConfigFile(cwd, ts.sys.fileExists, "jsconfig.json");
|
|
2544
2438
|
if (jsconfigPath) {
|
|
2545
2439
|
const config = ts.readConfigFile(jsconfigPath, ts.sys.readFile);
|
|
2546
|
-
if (config.error)
|
|
2547
|
-
return null;
|
|
2440
|
+
if (config.error) return null;
|
|
2548
2441
|
return { type: "js", ...config };
|
|
2549
2442
|
}
|
|
2550
2443
|
return null;
|
|
@@ -2595,8 +2488,7 @@ async function findUsedTokens(cwd, config) {
|
|
|
2595
2488
|
function matchBaseComposeBlocks(ast) {
|
|
2596
2489
|
const composeBlocks = findComposeBlocks(ast);
|
|
2597
2490
|
let result = {};
|
|
2598
|
-
if (!composeBlocks)
|
|
2599
|
-
return result;
|
|
2491
|
+
if (!composeBlocks) return result;
|
|
2600
2492
|
for (const node of composeBlocks) {
|
|
2601
2493
|
let styles;
|
|
2602
2494
|
for (const tokenProperty4 of node.properties) {
|
|
@@ -2620,16 +2512,14 @@ function matchTokens(content, theme) {
|
|
|
2620
2512
|
const variableMatches = uniqueMatches.filter((match) => match !== Tokenami2.gridProperty());
|
|
2621
2513
|
const values = variableMatches.flatMap((match) => {
|
|
2622
2514
|
const valueProperty = Tokenami2.TokenValue.safeParse(`var(${match})`);
|
|
2623
|
-
if (!valueProperty.success)
|
|
2624
|
-
return [];
|
|
2515
|
+
if (!valueProperty.success) return [];
|
|
2625
2516
|
const themeValues = getThemeValuesByThemeMode(valueProperty.output, theme);
|
|
2626
2517
|
return Object.entries(themeValues).length ? [valueProperty.output] : [];
|
|
2627
2518
|
});
|
|
2628
2519
|
const properties = variableMatches.flatMap((match) => {
|
|
2629
2520
|
const tokenProperty4 = Tokenami2.TokenProperty.safeParse(match);
|
|
2630
2521
|
const isValue = values.includes(`var(${match})`);
|
|
2631
|
-
if (isValue || !tokenProperty4.success)
|
|
2632
|
-
return [];
|
|
2522
|
+
if (isValue || !tokenProperty4.success) return [];
|
|
2633
2523
|
return tokenProperty4.output;
|
|
2634
2524
|
});
|
|
2635
2525
|
return { properties, values };
|
|
@@ -2656,8 +2546,7 @@ function findSheetComposeBlocks(fileContents) {
|
|
|
2656
2546
|
csstree.walk(node, {
|
|
2657
2547
|
visit: "Rule",
|
|
2658
2548
|
enter(ruleNode) {
|
|
2659
|
-
if (!ruleNode.prelude || !ruleNode.block)
|
|
2660
|
-
return;
|
|
2549
|
+
if (!ruleNode.prelude || !ruleNode.block) return;
|
|
2661
2550
|
const selector = csstree.generate(ruleNode.prelude).trim();
|
|
2662
2551
|
let styles = {};
|
|
2663
2552
|
csstree.walk(ruleNode.block, {
|