@pandacss/token-dictionary 0.53.7 → 1.0.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/index.js +40 -76
- package/dist/index.mjs +37 -73
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -18,8 +18,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
20
|
// src/index.ts
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
23
|
Token: () => Token,
|
|
24
24
|
TokenDictionary: () => TokenDictionary,
|
|
25
25
|
assertTokenFormat: () => assertTokenFormat,
|
|
@@ -29,7 +29,7 @@ __export(src_exports, {
|
|
|
29
29
|
isToken: () => isToken,
|
|
30
30
|
mapToJson: () => mapToJson
|
|
31
31
|
});
|
|
32
|
-
module.exports = __toCommonJS(
|
|
32
|
+
module.exports = __toCommonJS(index_exports);
|
|
33
33
|
|
|
34
34
|
// src/dictionary.ts
|
|
35
35
|
var import_shared6 = require("@pandacss/shared");
|
|
@@ -81,14 +81,12 @@ var import_shared = require("@pandacss/shared");
|
|
|
81
81
|
var REFERENCE_REGEX = /({([^}]*)})/g;
|
|
82
82
|
var curlyBracketRegex = /[{}]/g;
|
|
83
83
|
function getReferences(value) {
|
|
84
|
-
if (typeof value !== "string")
|
|
85
|
-
return [];
|
|
84
|
+
if (typeof value !== "string") return [];
|
|
86
85
|
const matches = value.match(REFERENCE_REGEX);
|
|
87
|
-
if (!matches)
|
|
88
|
-
return [];
|
|
86
|
+
if (!matches) return [];
|
|
89
87
|
return matches.map((match3) => match3.replace(curlyBracketRegex, "")).map((value2) => value2.trim());
|
|
90
88
|
}
|
|
91
|
-
var hasReference = (value) =>
|
|
89
|
+
var hasReference = (value) => getReferences(value).length > 0;
|
|
92
90
|
var tokenFunctionRegex = /token\(([^)]+)\)/g;
|
|
93
91
|
var closingParenthesisRegex = /\)$/g;
|
|
94
92
|
var hasTokenReference = (str) => str.includes("token(");
|
|
@@ -96,8 +94,7 @@ var tokenReplacer = (a, b) => b ? a.endsWith(")") ? a.replace(closingParenthesis
|
|
|
96
94
|
var notFoundMessage = (key, value) => `Reference not found: \`${key}\` in "${value}"`;
|
|
97
95
|
var isTokenReference = (v) => hasReference(v) || hasTokenReference(v);
|
|
98
96
|
function expandReferences(value, fn) {
|
|
99
|
-
if (!isTokenReference(value))
|
|
100
|
-
return value;
|
|
97
|
+
if (!isTokenReference(value)) return value;
|
|
101
98
|
const references = getReferences(value);
|
|
102
99
|
const expanded = references.reduce((valueStr, key) => {
|
|
103
100
|
const resolved = fn(key);
|
|
@@ -107,8 +104,7 @@ function expandReferences(value, fn) {
|
|
|
107
104
|
const expandedValue = resolved ?? (0, import_shared.esc)(key);
|
|
108
105
|
return valueStr.replace(`{${key}}`, expandedValue);
|
|
109
106
|
}, value);
|
|
110
|
-
if (!expanded.includes(`token(`))
|
|
111
|
-
return expanded;
|
|
107
|
+
if (!expanded.includes(`token(`)) return expanded;
|
|
112
108
|
return expanded.replace(tokenFunctionRegex, (_, token) => {
|
|
113
109
|
const [tokenValue, tokenFallback] = token.split(",").map((s) => s.trim());
|
|
114
110
|
const result = [tokenValue, tokenFallback].filter(Boolean).map((key) => {
|
|
@@ -203,8 +199,7 @@ var Token = class _Token {
|
|
|
203
199
|
*
|
|
204
200
|
*/
|
|
205
201
|
expandReferences() {
|
|
206
|
-
if (!this.hasReference)
|
|
207
|
-
return this.extensions.varRef ?? this.value;
|
|
202
|
+
if (!this.hasReference) return this.extensions.varRef ?? this.value;
|
|
208
203
|
const references = this.extensions.references ?? {};
|
|
209
204
|
this.value = Object.keys(references).reduce((valueStr, key) => {
|
|
210
205
|
const referenceToken = references[key];
|
|
@@ -245,14 +240,12 @@ var Token = class _Token {
|
|
|
245
240
|
* e.g. primary: { light: '#000', dark: '#fff' }
|
|
246
241
|
*/
|
|
247
242
|
getConditionTokens() {
|
|
248
|
-
if (!this.isConditional)
|
|
249
|
-
return;
|
|
243
|
+
if (!this.isConditional) return;
|
|
250
244
|
const conditions = this.extensions.conditions ?? {};
|
|
251
245
|
const conditionalTokens = [];
|
|
252
246
|
(0, import_shared2.walkObject)(conditions, (value, path) => {
|
|
253
247
|
const newPath = path.filter((v) => !(0, import_shared2.isBaseCondition)(v));
|
|
254
|
-
if (!newPath.length)
|
|
255
|
-
return;
|
|
248
|
+
if (!newPath.length) return;
|
|
256
249
|
const token = this.clone();
|
|
257
250
|
token.value = value;
|
|
258
251
|
token.extensions.condition = newPath.join(":");
|
|
@@ -269,8 +262,7 @@ var Token = class _Token {
|
|
|
269
262
|
return this;
|
|
270
263
|
}
|
|
271
264
|
setType() {
|
|
272
|
-
if (this.type)
|
|
273
|
-
return;
|
|
265
|
+
if (this.type) return;
|
|
274
266
|
if (this.extensions.category) {
|
|
275
267
|
this.type = TOKEN_TYPES[this.extensions.category];
|
|
276
268
|
}
|
|
@@ -364,8 +356,7 @@ var addVirtualPalette = {
|
|
|
364
356
|
const colorPalettes = /* @__PURE__ */ new Map();
|
|
365
357
|
tokens.forEach((token) => {
|
|
366
358
|
const { colorPalette, colorPaletteRoots, colorPaletteTokenKeys } = token.extensions;
|
|
367
|
-
if (!colorPalette)
|
|
368
|
-
return;
|
|
359
|
+
if (!colorPalette) return;
|
|
369
360
|
colorPaletteTokenKeys.forEach((keyPath) => {
|
|
370
361
|
keys.set(dictionary.formatTokenName(keyPath), keyPath);
|
|
371
362
|
});
|
|
@@ -376,8 +367,7 @@ var addVirtualPalette = {
|
|
|
376
367
|
colorPalettes.set(formated, colorPaletteList);
|
|
377
368
|
if (token.extensions.isDefault && colorPaletteRoot.length === 1) {
|
|
378
369
|
const keyPath = colorPaletteTokenKeys[0]?.filter(Boolean);
|
|
379
|
-
if (!keyPath.length)
|
|
380
|
-
return;
|
|
370
|
+
if (!keyPath.length) return;
|
|
381
371
|
const path = colorPaletteRoot.concat(keyPath);
|
|
382
372
|
keys.set(dictionary.formatTokenName(path), []);
|
|
383
373
|
}
|
|
@@ -546,8 +536,7 @@ var transformGradient = {
|
|
|
546
536
|
if (isCompositeGradient(token.value)) {
|
|
547
537
|
const { type, stops, placement } = token.value;
|
|
548
538
|
const rawStops = stops.map((stop) => {
|
|
549
|
-
if ((0, import_shared4.isString)(stop))
|
|
550
|
-
return stop;
|
|
539
|
+
if ((0, import_shared4.isString)(stop)) return stop;
|
|
551
540
|
const { color, position } = stop;
|
|
552
541
|
return `${color} ${position}px`;
|
|
553
542
|
});
|
|
@@ -607,8 +596,7 @@ var transformColorMix = {
|
|
|
607
596
|
return token.extensions.category === "colors" && token.value.includes("/");
|
|
608
597
|
},
|
|
609
598
|
transform(token, dict) {
|
|
610
|
-
if (!token.value.includes("/"))
|
|
611
|
-
return token;
|
|
599
|
+
if (!token.value.includes("/")) return token;
|
|
612
600
|
return expandReferences(token.value, (path) => {
|
|
613
601
|
const tokenFn = (tokenPath) => {
|
|
614
602
|
const token2 = dict.getByName(tokenPath);
|
|
@@ -642,8 +630,7 @@ var addConditionalCssVariables = {
|
|
|
642
630
|
transform(token, dictionary) {
|
|
643
631
|
const { prefix, hash } = dictionary;
|
|
644
632
|
const refs = getReferences(token.value);
|
|
645
|
-
if (!refs.length)
|
|
646
|
-
return token.value;
|
|
633
|
+
if (!refs.length) return token.value;
|
|
647
634
|
const modifier = refs.some((ref) => ref.includes("/"));
|
|
648
635
|
if (!modifier) {
|
|
649
636
|
refs.forEach((ref) => {
|
|
@@ -859,16 +846,14 @@ var cssVarParser = (str) => {
|
|
|
859
846
|
|
|
860
847
|
// src/dictionary.ts
|
|
861
848
|
function expandBreakpoints(breakpoints) {
|
|
862
|
-
if (!breakpoints)
|
|
863
|
-
return { breakpoints: {}, sizes: {} };
|
|
849
|
+
if (!breakpoints) return { breakpoints: {}, sizes: {} };
|
|
864
850
|
return {
|
|
865
851
|
breakpoints: (0, import_shared6.mapObject)(breakpoints, (value) => ({ value })),
|
|
866
852
|
sizes: Object.fromEntries(Object.entries(breakpoints).map(([key, value]) => [`breakpoint-${key}`, { value }]))
|
|
867
853
|
};
|
|
868
854
|
}
|
|
869
855
|
function filterDefault(path) {
|
|
870
|
-
if (path[0] === "DEFAULT")
|
|
871
|
-
return path;
|
|
856
|
+
if (path[0] === "DEFAULT") return path;
|
|
872
857
|
return path.filter((item) => item !== "DEFAULT");
|
|
873
858
|
}
|
|
874
859
|
var TokenDictionary = class {
|
|
@@ -1013,17 +998,14 @@ var TokenDictionary = class {
|
|
|
1013
998
|
}
|
|
1014
999
|
execTransform(name) {
|
|
1015
1000
|
const transform = this.transforms.get(name);
|
|
1016
|
-
if (!transform)
|
|
1017
|
-
return;
|
|
1001
|
+
if (!transform) return;
|
|
1018
1002
|
this.allTokens.forEach((token) => {
|
|
1019
1003
|
this.execTransformOnToken(transform, token);
|
|
1020
1004
|
});
|
|
1021
1005
|
}
|
|
1022
1006
|
execTransformOnToken(transform, token) {
|
|
1023
|
-
if (token.extensions.hasReference)
|
|
1024
|
-
|
|
1025
|
-
if (typeof transform.match === "function" && !transform.match(token))
|
|
1026
|
-
return;
|
|
1007
|
+
if (token.extensions.hasReference) return;
|
|
1008
|
+
if (typeof transform.match === "function" && !transform.match(token)) return;
|
|
1027
1009
|
const exec = (v) => transform.transform(v, this);
|
|
1028
1010
|
const transformed = exec(token);
|
|
1029
1011
|
(0, import_ts_pattern3.match)(transform).with({ type: "extensions" }, () => {
|
|
@@ -1074,14 +1056,12 @@ var TokenDictionary = class {
|
|
|
1074
1056
|
return refs.map((ref) => this.getByName(ref)).filter(Boolean);
|
|
1075
1057
|
}
|
|
1076
1058
|
usesReference(value) {
|
|
1077
|
-
if (!(0, import_shared6.isString)(value))
|
|
1078
|
-
return false;
|
|
1059
|
+
if (!(0, import_shared6.isString)(value)) return false;
|
|
1079
1060
|
return this.getReferences(value).length > 0;
|
|
1080
1061
|
}
|
|
1081
1062
|
addReferences() {
|
|
1082
1063
|
this.allTokens.forEach((token) => {
|
|
1083
|
-
if (!this.usesReference(token.value))
|
|
1084
|
-
return;
|
|
1064
|
+
if (!this.usesReference(token.value)) return;
|
|
1085
1065
|
const references = this.getReferences(token.value);
|
|
1086
1066
|
token.setExtensions({
|
|
1087
1067
|
references: references.reduce(
|
|
@@ -1117,8 +1097,7 @@ var TokenDictionary = class {
|
|
|
1117
1097
|
return this;
|
|
1118
1098
|
}
|
|
1119
1099
|
colorMix = (value, tokenFn) => {
|
|
1120
|
-
if (!value || typeof value !== "string")
|
|
1121
|
-
return { invalid: true, value };
|
|
1100
|
+
if (!value || typeof value !== "string") return { invalid: true, value };
|
|
1122
1101
|
const [colorPath, rawOpacity] = value.split("/");
|
|
1123
1102
|
if (!colorPath || !rawOpacity) {
|
|
1124
1103
|
return { invalid: true, value: colorPath };
|
|
@@ -1141,8 +1120,7 @@ var TokenDictionary = class {
|
|
|
1141
1120
|
*/
|
|
1142
1121
|
expandReferenceInValue(value) {
|
|
1143
1122
|
return expandTokenReferences(value, (path) => {
|
|
1144
|
-
if (!path)
|
|
1145
|
-
return;
|
|
1123
|
+
if (!path) return;
|
|
1146
1124
|
if (path.includes("/")) {
|
|
1147
1125
|
const mix = this.colorMix(path, this.view.get.bind(this.view));
|
|
1148
1126
|
if (mix.invalid) {
|
|
@@ -1151,8 +1129,7 @@ var TokenDictionary = class {
|
|
|
1151
1129
|
return mix.value;
|
|
1152
1130
|
}
|
|
1153
1131
|
const resolved = this.view.get(path);
|
|
1154
|
-
if (resolved)
|
|
1155
|
-
return resolved;
|
|
1132
|
+
if (resolved) return resolved;
|
|
1156
1133
|
return tokenPathRegex.test(path) ? (0, import_shared6.esc)(path) : path;
|
|
1157
1134
|
});
|
|
1158
1135
|
}
|
|
@@ -1249,17 +1226,14 @@ var TokenDictionaryView = class {
|
|
|
1249
1226
|
}
|
|
1250
1227
|
processCondition(token, group) {
|
|
1251
1228
|
const { condition } = token.extensions;
|
|
1252
|
-
if (!condition)
|
|
1253
|
-
|
|
1254
|
-
if (!group.has(condition))
|
|
1255
|
-
group.set(condition, /* @__PURE__ */ new Set());
|
|
1229
|
+
if (!condition) return;
|
|
1230
|
+
if (!group.has(condition)) group.set(condition, /* @__PURE__ */ new Set());
|
|
1256
1231
|
group.get(condition).add(token);
|
|
1257
1232
|
}
|
|
1258
1233
|
processColorPalette(token, group, byName) {
|
|
1259
1234
|
const extensions = token.extensions;
|
|
1260
1235
|
const { colorPalette, colorPaletteRoots, isVirtual } = extensions;
|
|
1261
|
-
if (!colorPalette || isVirtual)
|
|
1262
|
-
return;
|
|
1236
|
+
if (!colorPalette || isVirtual) return;
|
|
1263
1237
|
colorPaletteRoots.forEach((colorPaletteRoot) => {
|
|
1264
1238
|
const formated = this.dictionary.formatTokenName(colorPaletteRoot);
|
|
1265
1239
|
if (!group.has(formated)) {
|
|
@@ -1268,22 +1242,18 @@ var TokenDictionaryView = class {
|
|
|
1268
1242
|
const virtualPath = replaceRootWithColorPalette([...token.path], [...colorPaletteRoot]);
|
|
1269
1243
|
const virtualName = this.dictionary.formatTokenName(virtualPath);
|
|
1270
1244
|
const virtualToken = byName.get(virtualName);
|
|
1271
|
-
if (!virtualToken)
|
|
1272
|
-
return;
|
|
1245
|
+
if (!virtualToken) return;
|
|
1273
1246
|
const virtualVar = virtualToken.extensions.var;
|
|
1274
1247
|
group.get(formated).set(virtualVar, token.extensions.varRef);
|
|
1275
1248
|
if (extensions.isDefault && colorPaletteRoot.length === 1) {
|
|
1276
1249
|
const colorPaletteName = this.dictionary.formatTokenName(["colors", "colorPalette"]);
|
|
1277
1250
|
const colorPaletteToken = byName.get(colorPaletteName);
|
|
1278
|
-
if (!colorPaletteToken)
|
|
1279
|
-
return;
|
|
1251
|
+
if (!colorPaletteToken) return;
|
|
1280
1252
|
const name = this.dictionary.formatTokenName(token.path);
|
|
1281
1253
|
const virtualToken2 = byName.get(name);
|
|
1282
|
-
if (!virtualToken2)
|
|
1283
|
-
return;
|
|
1254
|
+
if (!virtualToken2) return;
|
|
1284
1255
|
const keyPath = extensions.colorPaletteTokenKeys[0]?.filter(Boolean);
|
|
1285
|
-
if (!keyPath.length)
|
|
1286
|
-
return;
|
|
1256
|
+
if (!keyPath.length) return;
|
|
1287
1257
|
const formated2 = this.dictionary.formatTokenName(colorPaletteRoot.concat(keyPath));
|
|
1288
1258
|
if (!group.has(formated2)) {
|
|
1289
1259
|
group.set(formated2, /* @__PURE__ */ new Map());
|
|
@@ -1294,18 +1264,14 @@ var TokenDictionaryView = class {
|
|
|
1294
1264
|
}
|
|
1295
1265
|
processCategory(token, group) {
|
|
1296
1266
|
const { category, prop } = token.extensions;
|
|
1297
|
-
if (!category)
|
|
1298
|
-
|
|
1299
|
-
if (!group.has(category))
|
|
1300
|
-
group.set(category, /* @__PURE__ */ new Map());
|
|
1267
|
+
if (!category) return;
|
|
1268
|
+
if (!group.has(category)) group.set(category, /* @__PURE__ */ new Map());
|
|
1301
1269
|
group.get(category).set(prop, token);
|
|
1302
1270
|
}
|
|
1303
1271
|
processValue(token, byCategory, flatValues, nameByVar) {
|
|
1304
1272
|
const { category, prop, varRef, isNegative } = token.extensions;
|
|
1305
|
-
if (!category)
|
|
1306
|
-
|
|
1307
|
-
if (!byCategory.has(category))
|
|
1308
|
-
byCategory.set(category, /* @__PURE__ */ new Map());
|
|
1273
|
+
if (!category) return;
|
|
1274
|
+
if (!byCategory.has(category)) byCategory.set(category, /* @__PURE__ */ new Map());
|
|
1309
1275
|
const value = isNegative ? token.extensions.condition !== "base" ? token.originalValue : token.value : varRef;
|
|
1310
1276
|
byCategory.get(category).set(prop, value);
|
|
1311
1277
|
flatValues.set(token.name, value);
|
|
@@ -1313,10 +1279,8 @@ var TokenDictionaryView = class {
|
|
|
1313
1279
|
}
|
|
1314
1280
|
processVars(token, group) {
|
|
1315
1281
|
const { condition, isNegative, isVirtual, var: varName, theme } = token.extensions;
|
|
1316
|
-
if (isNegative || !theme && isVirtual || !condition)
|
|
1317
|
-
|
|
1318
|
-
if (!group.has(condition))
|
|
1319
|
-
group.set(condition, /* @__PURE__ */ new Map());
|
|
1282
|
+
if (isNegative || !theme && isVirtual || !condition) return;
|
|
1283
|
+
if (!group.has(condition)) group.set(condition, /* @__PURE__ */ new Map());
|
|
1320
1284
|
group.get(condition).set(varName, token.value);
|
|
1321
1285
|
}
|
|
1322
1286
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -57,14 +57,12 @@ import { PandaError, esc, isObject } from "@pandacss/shared";
|
|
|
57
57
|
var REFERENCE_REGEX = /({([^}]*)})/g;
|
|
58
58
|
var curlyBracketRegex = /[{}]/g;
|
|
59
59
|
function getReferences(value) {
|
|
60
|
-
if (typeof value !== "string")
|
|
61
|
-
return [];
|
|
60
|
+
if (typeof value !== "string") return [];
|
|
62
61
|
const matches = value.match(REFERENCE_REGEX);
|
|
63
|
-
if (!matches)
|
|
64
|
-
return [];
|
|
62
|
+
if (!matches) return [];
|
|
65
63
|
return matches.map((match3) => match3.replace(curlyBracketRegex, "")).map((value2) => value2.trim());
|
|
66
64
|
}
|
|
67
|
-
var hasReference = (value) =>
|
|
65
|
+
var hasReference = (value) => getReferences(value).length > 0;
|
|
68
66
|
var tokenFunctionRegex = /token\(([^)]+)\)/g;
|
|
69
67
|
var closingParenthesisRegex = /\)$/g;
|
|
70
68
|
var hasTokenReference = (str) => str.includes("token(");
|
|
@@ -72,8 +70,7 @@ var tokenReplacer = (a, b) => b ? a.endsWith(")") ? a.replace(closingParenthesis
|
|
|
72
70
|
var notFoundMessage = (key, value) => `Reference not found: \`${key}\` in "${value}"`;
|
|
73
71
|
var isTokenReference = (v) => hasReference(v) || hasTokenReference(v);
|
|
74
72
|
function expandReferences(value, fn) {
|
|
75
|
-
if (!isTokenReference(value))
|
|
76
|
-
return value;
|
|
73
|
+
if (!isTokenReference(value)) return value;
|
|
77
74
|
const references = getReferences(value);
|
|
78
75
|
const expanded = references.reduce((valueStr, key) => {
|
|
79
76
|
const resolved = fn(key);
|
|
@@ -83,8 +80,7 @@ function expandReferences(value, fn) {
|
|
|
83
80
|
const expandedValue = resolved ?? esc(key);
|
|
84
81
|
return valueStr.replace(`{${key}}`, expandedValue);
|
|
85
82
|
}, value);
|
|
86
|
-
if (!expanded.includes(`token(`))
|
|
87
|
-
return expanded;
|
|
83
|
+
if (!expanded.includes(`token(`)) return expanded;
|
|
88
84
|
return expanded.replace(tokenFunctionRegex, (_, token) => {
|
|
89
85
|
const [tokenValue, tokenFallback] = token.split(",").map((s) => s.trim());
|
|
90
86
|
const result = [tokenValue, tokenFallback].filter(Boolean).map((key) => {
|
|
@@ -179,8 +175,7 @@ var Token = class _Token {
|
|
|
179
175
|
*
|
|
180
176
|
*/
|
|
181
177
|
expandReferences() {
|
|
182
|
-
if (!this.hasReference)
|
|
183
|
-
return this.extensions.varRef ?? this.value;
|
|
178
|
+
if (!this.hasReference) return this.extensions.varRef ?? this.value;
|
|
184
179
|
const references = this.extensions.references ?? {};
|
|
185
180
|
this.value = Object.keys(references).reduce((valueStr, key) => {
|
|
186
181
|
const referenceToken = references[key];
|
|
@@ -221,14 +216,12 @@ var Token = class _Token {
|
|
|
221
216
|
* e.g. primary: { light: '#000', dark: '#fff' }
|
|
222
217
|
*/
|
|
223
218
|
getConditionTokens() {
|
|
224
|
-
if (!this.isConditional)
|
|
225
|
-
return;
|
|
219
|
+
if (!this.isConditional) return;
|
|
226
220
|
const conditions = this.extensions.conditions ?? {};
|
|
227
221
|
const conditionalTokens = [];
|
|
228
222
|
walkObject(conditions, (value, path) => {
|
|
229
223
|
const newPath = path.filter((v) => !isBaseCondition(v));
|
|
230
|
-
if (!newPath.length)
|
|
231
|
-
return;
|
|
224
|
+
if (!newPath.length) return;
|
|
232
225
|
const token = this.clone();
|
|
233
226
|
token.value = value;
|
|
234
227
|
token.extensions.condition = newPath.join(":");
|
|
@@ -245,8 +238,7 @@ var Token = class _Token {
|
|
|
245
238
|
return this;
|
|
246
239
|
}
|
|
247
240
|
setType() {
|
|
248
|
-
if (this.type)
|
|
249
|
-
return;
|
|
241
|
+
if (this.type) return;
|
|
250
242
|
if (this.extensions.category) {
|
|
251
243
|
this.type = TOKEN_TYPES[this.extensions.category];
|
|
252
244
|
}
|
|
@@ -340,8 +332,7 @@ var addVirtualPalette = {
|
|
|
340
332
|
const colorPalettes = /* @__PURE__ */ new Map();
|
|
341
333
|
tokens.forEach((token) => {
|
|
342
334
|
const { colorPalette, colorPaletteRoots, colorPaletteTokenKeys } = token.extensions;
|
|
343
|
-
if (!colorPalette)
|
|
344
|
-
return;
|
|
335
|
+
if (!colorPalette) return;
|
|
345
336
|
colorPaletteTokenKeys.forEach((keyPath) => {
|
|
346
337
|
keys.set(dictionary.formatTokenName(keyPath), keyPath);
|
|
347
338
|
});
|
|
@@ -352,8 +343,7 @@ var addVirtualPalette = {
|
|
|
352
343
|
colorPalettes.set(formated, colorPaletteList);
|
|
353
344
|
if (token.extensions.isDefault && colorPaletteRoot.length === 1) {
|
|
354
345
|
const keyPath = colorPaletteTokenKeys[0]?.filter(Boolean);
|
|
355
|
-
if (!keyPath.length)
|
|
356
|
-
return;
|
|
346
|
+
if (!keyPath.length) return;
|
|
357
347
|
const path = colorPaletteRoot.concat(keyPath);
|
|
358
348
|
keys.set(dictionary.formatTokenName(path), []);
|
|
359
349
|
}
|
|
@@ -522,8 +512,7 @@ var transformGradient = {
|
|
|
522
512
|
if (isCompositeGradient(token.value)) {
|
|
523
513
|
const { type, stops, placement } = token.value;
|
|
524
514
|
const rawStops = stops.map((stop) => {
|
|
525
|
-
if (isString(stop))
|
|
526
|
-
return stop;
|
|
515
|
+
if (isString(stop)) return stop;
|
|
527
516
|
const { color, position } = stop;
|
|
528
517
|
return `${color} ${position}px`;
|
|
529
518
|
});
|
|
@@ -583,8 +572,7 @@ var transformColorMix = {
|
|
|
583
572
|
return token.extensions.category === "colors" && token.value.includes("/");
|
|
584
573
|
},
|
|
585
574
|
transform(token, dict) {
|
|
586
|
-
if (!token.value.includes("/"))
|
|
587
|
-
return token;
|
|
575
|
+
if (!token.value.includes("/")) return token;
|
|
588
576
|
return expandReferences(token.value, (path) => {
|
|
589
577
|
const tokenFn = (tokenPath) => {
|
|
590
578
|
const token2 = dict.getByName(tokenPath);
|
|
@@ -618,8 +606,7 @@ var addConditionalCssVariables = {
|
|
|
618
606
|
transform(token, dictionary) {
|
|
619
607
|
const { prefix, hash } = dictionary;
|
|
620
608
|
const refs = getReferences(token.value);
|
|
621
|
-
if (!refs.length)
|
|
622
|
-
return token.value;
|
|
609
|
+
if (!refs.length) return token.value;
|
|
623
610
|
const modifier = refs.some((ref) => ref.includes("/"));
|
|
624
611
|
if (!modifier) {
|
|
625
612
|
refs.forEach((ref) => {
|
|
@@ -835,16 +822,14 @@ var cssVarParser = (str) => {
|
|
|
835
822
|
|
|
836
823
|
// src/dictionary.ts
|
|
837
824
|
function expandBreakpoints(breakpoints) {
|
|
838
|
-
if (!breakpoints)
|
|
839
|
-
return { breakpoints: {}, sizes: {} };
|
|
825
|
+
if (!breakpoints) return { breakpoints: {}, sizes: {} };
|
|
840
826
|
return {
|
|
841
827
|
breakpoints: mapObject(breakpoints, (value) => ({ value })),
|
|
842
828
|
sizes: Object.fromEntries(Object.entries(breakpoints).map(([key, value]) => [`breakpoint-${key}`, { value }]))
|
|
843
829
|
};
|
|
844
830
|
}
|
|
845
831
|
function filterDefault(path) {
|
|
846
|
-
if (path[0] === "DEFAULT")
|
|
847
|
-
return path;
|
|
832
|
+
if (path[0] === "DEFAULT") return path;
|
|
848
833
|
return path.filter((item) => item !== "DEFAULT");
|
|
849
834
|
}
|
|
850
835
|
var TokenDictionary = class {
|
|
@@ -989,17 +974,14 @@ var TokenDictionary = class {
|
|
|
989
974
|
}
|
|
990
975
|
execTransform(name) {
|
|
991
976
|
const transform = this.transforms.get(name);
|
|
992
|
-
if (!transform)
|
|
993
|
-
return;
|
|
977
|
+
if (!transform) return;
|
|
994
978
|
this.allTokens.forEach((token) => {
|
|
995
979
|
this.execTransformOnToken(transform, token);
|
|
996
980
|
});
|
|
997
981
|
}
|
|
998
982
|
execTransformOnToken(transform, token) {
|
|
999
|
-
if (token.extensions.hasReference)
|
|
1000
|
-
|
|
1001
|
-
if (typeof transform.match === "function" && !transform.match(token))
|
|
1002
|
-
return;
|
|
983
|
+
if (token.extensions.hasReference) return;
|
|
984
|
+
if (typeof transform.match === "function" && !transform.match(token)) return;
|
|
1003
985
|
const exec = (v) => transform.transform(v, this);
|
|
1004
986
|
const transformed = exec(token);
|
|
1005
987
|
match2(transform).with({ type: "extensions" }, () => {
|
|
@@ -1050,14 +1032,12 @@ var TokenDictionary = class {
|
|
|
1050
1032
|
return refs.map((ref) => this.getByName(ref)).filter(Boolean);
|
|
1051
1033
|
}
|
|
1052
1034
|
usesReference(value) {
|
|
1053
|
-
if (!isString2(value))
|
|
1054
|
-
return false;
|
|
1035
|
+
if (!isString2(value)) return false;
|
|
1055
1036
|
return this.getReferences(value).length > 0;
|
|
1056
1037
|
}
|
|
1057
1038
|
addReferences() {
|
|
1058
1039
|
this.allTokens.forEach((token) => {
|
|
1059
|
-
if (!this.usesReference(token.value))
|
|
1060
|
-
return;
|
|
1040
|
+
if (!this.usesReference(token.value)) return;
|
|
1061
1041
|
const references = this.getReferences(token.value);
|
|
1062
1042
|
token.setExtensions({
|
|
1063
1043
|
references: references.reduce(
|
|
@@ -1093,8 +1073,7 @@ var TokenDictionary = class {
|
|
|
1093
1073
|
return this;
|
|
1094
1074
|
}
|
|
1095
1075
|
colorMix = (value, tokenFn) => {
|
|
1096
|
-
if (!value || typeof value !== "string")
|
|
1097
|
-
return { invalid: true, value };
|
|
1076
|
+
if (!value || typeof value !== "string") return { invalid: true, value };
|
|
1098
1077
|
const [colorPath, rawOpacity] = value.split("/");
|
|
1099
1078
|
if (!colorPath || !rawOpacity) {
|
|
1100
1079
|
return { invalid: true, value: colorPath };
|
|
@@ -1117,8 +1096,7 @@ var TokenDictionary = class {
|
|
|
1117
1096
|
*/
|
|
1118
1097
|
expandReferenceInValue(value) {
|
|
1119
1098
|
return expandTokenReferences(value, (path) => {
|
|
1120
|
-
if (!path)
|
|
1121
|
-
return;
|
|
1099
|
+
if (!path) return;
|
|
1122
1100
|
if (path.includes("/")) {
|
|
1123
1101
|
const mix = this.colorMix(path, this.view.get.bind(this.view));
|
|
1124
1102
|
if (mix.invalid) {
|
|
@@ -1127,8 +1105,7 @@ var TokenDictionary = class {
|
|
|
1127
1105
|
return mix.value;
|
|
1128
1106
|
}
|
|
1129
1107
|
const resolved = this.view.get(path);
|
|
1130
|
-
if (resolved)
|
|
1131
|
-
return resolved;
|
|
1108
|
+
if (resolved) return resolved;
|
|
1132
1109
|
return tokenPathRegex.test(path) ? esc3(path) : path;
|
|
1133
1110
|
});
|
|
1134
1111
|
}
|
|
@@ -1225,17 +1202,14 @@ var TokenDictionaryView = class {
|
|
|
1225
1202
|
}
|
|
1226
1203
|
processCondition(token, group) {
|
|
1227
1204
|
const { condition } = token.extensions;
|
|
1228
|
-
if (!condition)
|
|
1229
|
-
|
|
1230
|
-
if (!group.has(condition))
|
|
1231
|
-
group.set(condition, /* @__PURE__ */ new Set());
|
|
1205
|
+
if (!condition) return;
|
|
1206
|
+
if (!group.has(condition)) group.set(condition, /* @__PURE__ */ new Set());
|
|
1232
1207
|
group.get(condition).add(token);
|
|
1233
1208
|
}
|
|
1234
1209
|
processColorPalette(token, group, byName) {
|
|
1235
1210
|
const extensions = token.extensions;
|
|
1236
1211
|
const { colorPalette, colorPaletteRoots, isVirtual } = extensions;
|
|
1237
|
-
if (!colorPalette || isVirtual)
|
|
1238
|
-
return;
|
|
1212
|
+
if (!colorPalette || isVirtual) return;
|
|
1239
1213
|
colorPaletteRoots.forEach((colorPaletteRoot) => {
|
|
1240
1214
|
const formated = this.dictionary.formatTokenName(colorPaletteRoot);
|
|
1241
1215
|
if (!group.has(formated)) {
|
|
@@ -1244,22 +1218,18 @@ var TokenDictionaryView = class {
|
|
|
1244
1218
|
const virtualPath = replaceRootWithColorPalette([...token.path], [...colorPaletteRoot]);
|
|
1245
1219
|
const virtualName = this.dictionary.formatTokenName(virtualPath);
|
|
1246
1220
|
const virtualToken = byName.get(virtualName);
|
|
1247
|
-
if (!virtualToken)
|
|
1248
|
-
return;
|
|
1221
|
+
if (!virtualToken) return;
|
|
1249
1222
|
const virtualVar = virtualToken.extensions.var;
|
|
1250
1223
|
group.get(formated).set(virtualVar, token.extensions.varRef);
|
|
1251
1224
|
if (extensions.isDefault && colorPaletteRoot.length === 1) {
|
|
1252
1225
|
const colorPaletteName = this.dictionary.formatTokenName(["colors", "colorPalette"]);
|
|
1253
1226
|
const colorPaletteToken = byName.get(colorPaletteName);
|
|
1254
|
-
if (!colorPaletteToken)
|
|
1255
|
-
return;
|
|
1227
|
+
if (!colorPaletteToken) return;
|
|
1256
1228
|
const name = this.dictionary.formatTokenName(token.path);
|
|
1257
1229
|
const virtualToken2 = byName.get(name);
|
|
1258
|
-
if (!virtualToken2)
|
|
1259
|
-
return;
|
|
1230
|
+
if (!virtualToken2) return;
|
|
1260
1231
|
const keyPath = extensions.colorPaletteTokenKeys[0]?.filter(Boolean);
|
|
1261
|
-
if (!keyPath.length)
|
|
1262
|
-
return;
|
|
1232
|
+
if (!keyPath.length) return;
|
|
1263
1233
|
const formated2 = this.dictionary.formatTokenName(colorPaletteRoot.concat(keyPath));
|
|
1264
1234
|
if (!group.has(formated2)) {
|
|
1265
1235
|
group.set(formated2, /* @__PURE__ */ new Map());
|
|
@@ -1270,18 +1240,14 @@ var TokenDictionaryView = class {
|
|
|
1270
1240
|
}
|
|
1271
1241
|
processCategory(token, group) {
|
|
1272
1242
|
const { category, prop } = token.extensions;
|
|
1273
|
-
if (!category)
|
|
1274
|
-
|
|
1275
|
-
if (!group.has(category))
|
|
1276
|
-
group.set(category, /* @__PURE__ */ new Map());
|
|
1243
|
+
if (!category) return;
|
|
1244
|
+
if (!group.has(category)) group.set(category, /* @__PURE__ */ new Map());
|
|
1277
1245
|
group.get(category).set(prop, token);
|
|
1278
1246
|
}
|
|
1279
1247
|
processValue(token, byCategory, flatValues, nameByVar) {
|
|
1280
1248
|
const { category, prop, varRef, isNegative } = token.extensions;
|
|
1281
|
-
if (!category)
|
|
1282
|
-
|
|
1283
|
-
if (!byCategory.has(category))
|
|
1284
|
-
byCategory.set(category, /* @__PURE__ */ new Map());
|
|
1249
|
+
if (!category) return;
|
|
1250
|
+
if (!byCategory.has(category)) byCategory.set(category, /* @__PURE__ */ new Map());
|
|
1285
1251
|
const value = isNegative ? token.extensions.condition !== "base" ? token.originalValue : token.value : varRef;
|
|
1286
1252
|
byCategory.get(category).set(prop, value);
|
|
1287
1253
|
flatValues.set(token.name, value);
|
|
@@ -1289,10 +1255,8 @@ var TokenDictionaryView = class {
|
|
|
1289
1255
|
}
|
|
1290
1256
|
processVars(token, group) {
|
|
1291
1257
|
const { condition, isNegative, isVirtual, var: varName, theme } = token.extensions;
|
|
1292
|
-
if (isNegative || !theme && isVirtual || !condition)
|
|
1293
|
-
|
|
1294
|
-
if (!group.has(condition))
|
|
1295
|
-
group.set(condition, /* @__PURE__ */ new Map());
|
|
1258
|
+
if (isNegative || !theme && isVirtual || !condition) return;
|
|
1259
|
+
if (!group.has(condition)) group.set(condition, /* @__PURE__ */ new Map());
|
|
1296
1260
|
group.get(condition).set(varName, token.value);
|
|
1297
1261
|
}
|
|
1298
1262
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pandacss/token-dictionary",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Common error messages for css panda",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
"dist"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"ts-pattern": "5.0
|
|
36
|
-
"@pandacss/logger": "^0.
|
|
37
|
-
"@pandacss/shared": "0.
|
|
38
|
-
"@pandacss/types": "0.
|
|
35
|
+
"ts-pattern": "5.8.0",
|
|
36
|
+
"@pandacss/logger": "^1.0.0",
|
|
37
|
+
"@pandacss/shared": "1.0.0",
|
|
38
|
+
"@pandacss/types": "1.0.0"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "tsup src/index.ts --format=esm,cjs --dts",
|