@pandacss/token-dictionary 1.4.0 → 1.4.2

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.mts CHANGED
@@ -174,6 +174,7 @@ declare class TokenDictionaryView {
174
174
  json: Record<string, Record<string, string>>;
175
175
  valuesByCategory: Map<keyof _pandacss_types.TokenDataTypes, Map<string, string>>;
176
176
  get: (path: string, fallback?: string | number) => string;
177
+ getVar: (path: string, fallback?: string | number) => string;
177
178
  getCategoryValues: (category: string) => Record<string, string> | undefined;
178
179
  };
179
180
  private processCondition;
package/dist/index.d.ts CHANGED
@@ -174,6 +174,7 @@ declare class TokenDictionaryView {
174
174
  json: Record<string, Record<string, string>>;
175
175
  valuesByCategory: Map<keyof _pandacss_types.TokenDataTypes, Map<string, string>>;
176
176
  get: (path: string, fallback?: string | number) => string;
177
+ getVar: (path: string, fallback?: string | number) => string;
177
178
  getCategoryValues: (category: string) => Record<string, string> | undefined;
178
179
  };
179
180
  private processCondition;
package/dist/index.js CHANGED
@@ -604,7 +604,7 @@ var transformColorMix = {
604
604
  };
605
605
  const mix = dict.colorMix(path, tokenFn);
606
606
  if (mix.invalid) {
607
- throw new Error("Invalid color mix at " + path + ": " + mix.value);
607
+ throw new import_shared4.PandaError("INVALID_TOKEN", "Invalid color mix at " + path + ": " + mix.value);
608
608
  }
609
609
  return mix.value;
610
610
  });
@@ -645,7 +645,7 @@ var addConditionalCssVariables = {
645
645
  token.value = expandReferences(token.value, (path) => {
646
646
  const mix = dictionary.colorMix(path, tokenFn);
647
647
  if (mix.invalid) {
648
- throw new Error("Invalid color mix at " + path + ": " + mix.value);
648
+ throw new import_shared4.PandaError("INVALID_TOKEN", "Invalid color mix at " + path + ": " + mix.value);
649
649
  }
650
650
  return mix.value;
651
651
  });
@@ -1122,13 +1122,13 @@ var TokenDictionary = class {
1122
1122
  return expandTokenReferences(value, (path) => {
1123
1123
  if (!path) return;
1124
1124
  if (path.includes("/")) {
1125
- const mix = this.colorMix(path, this.view.get.bind(this.view));
1125
+ const mix = this.colorMix(path, this.view.getVar.bind(this.view));
1126
1126
  if (mix.invalid) {
1127
- throw new Error("Invalid color mix at " + path + ": " + mix.value);
1127
+ throw new import_shared6.PandaError("INVALID_TOKEN", "Invalid color mix at " + path + ": " + mix.value);
1128
1128
  }
1129
1129
  return mix.value;
1130
1130
  }
1131
- const resolved = this.view.get(path);
1131
+ const resolved = this.view.getVar(path);
1132
1132
  if (resolved) return resolved;
1133
1133
  return tokenPathRegex.test(path) ? (0, import_shared6.esc)(path) : path;
1134
1134
  });
@@ -1194,13 +1194,14 @@ var TokenDictionaryView = class {
1194
1194
  const colorPalettes = /* @__PURE__ */ new Map();
1195
1195
  const valuesByCategory = /* @__PURE__ */ new Map();
1196
1196
  const flatValues = /* @__PURE__ */ new Map();
1197
+ const rawValues = /* @__PURE__ */ new Map();
1197
1198
  const nameByVar = /* @__PURE__ */ new Map();
1198
1199
  const vars = /* @__PURE__ */ new Map();
1199
1200
  this.dictionary.allTokens.forEach((token) => {
1200
1201
  this.processCondition(token, conditionMap);
1201
1202
  this.processColorPalette(token, colorPalettes, this.dictionary.byName);
1202
1203
  this.processCategory(token, categoryMap);
1203
- this.processValue(token, valuesByCategory, flatValues, nameByVar);
1204
+ this.processValue(token, valuesByCategory, flatValues, rawValues, nameByVar);
1204
1205
  this.processVars(token, vars);
1205
1206
  });
1206
1207
  const json = mapToJson(valuesByCategory);
@@ -1214,6 +1215,9 @@ var TokenDictionaryView = class {
1214
1215
  json,
1215
1216
  valuesByCategory,
1216
1217
  get: (0, import_shared6.memo)((path, fallback) => {
1218
+ return rawValues.get(path) ?? fallback;
1219
+ }),
1220
+ getVar: (0, import_shared6.memo)((path, fallback) => {
1217
1221
  return flatValues.get(path) ?? fallback;
1218
1222
  }),
1219
1223
  getCategoryValues: (0, import_shared6.memo)((category) => {
@@ -1268,14 +1272,16 @@ var TokenDictionaryView = class {
1268
1272
  if (!group.has(category)) group.set(category, /* @__PURE__ */ new Map());
1269
1273
  group.get(category).set(prop, token);
1270
1274
  }
1271
- processValue(token, byCategory, flatValues, nameByVar) {
1272
- const { category, prop, varRef, isNegative } = token.extensions;
1275
+ processValue(token, byCategory, flatValues, rawValues, nameByVar) {
1276
+ const { category, prop, varRef, isNegative, isVirtual, condition } = token.extensions;
1273
1277
  if (!category) return;
1274
1278
  if (!byCategory.has(category)) byCategory.set(category, /* @__PURE__ */ new Map());
1275
1279
  const value = isNegative ? token.extensions.condition !== "base" ? token.originalValue : token.value : varRef;
1276
1280
  byCategory.get(category).set(prop, value);
1277
1281
  flatValues.set(token.name, value);
1278
1282
  nameByVar.set(value, token.name);
1283
+ const rawValue = isVirtual || condition !== "base" ? varRef : token.value;
1284
+ rawValues.set(token.name, rawValue);
1279
1285
  }
1280
1286
  processVars(token, group) {
1281
1287
  const { condition, isNegative, isVirtual, var: varName, theme } = token.extensions;
package/dist/index.mjs CHANGED
@@ -7,6 +7,7 @@ import {
7
7
  isString as isString2,
8
8
  mapObject,
9
9
  memo,
10
+ PandaError as PandaError3,
10
11
  walkObject as walkObject2
11
12
  } from "@pandacss/shared";
12
13
  import { isMatching as isMatching2, match as match2 } from "ts-pattern";
@@ -373,7 +374,7 @@ var removeEmptyTokens = {
373
374
  var middlewares = [addNegativeTokens, addVirtualPalette, removeEmptyTokens, addPixelUnit];
374
375
 
375
376
  // src/transform.ts
376
- import { isCssUnit, isString } from "@pandacss/shared";
377
+ import { isCssUnit, isString, PandaError as PandaError2 } from "@pandacss/shared";
377
378
  import { P as P2, match } from "ts-pattern";
378
379
 
379
380
  // src/mini-svg-uri.ts
@@ -580,7 +581,7 @@ var transformColorMix = {
580
581
  };
581
582
  const mix = dict.colorMix(path, tokenFn);
582
583
  if (mix.invalid) {
583
- throw new Error("Invalid color mix at " + path + ": " + mix.value);
584
+ throw new PandaError2("INVALID_TOKEN", "Invalid color mix at " + path + ": " + mix.value);
584
585
  }
585
586
  return mix.value;
586
587
  });
@@ -621,7 +622,7 @@ var addConditionalCssVariables = {
621
622
  token.value = expandReferences(token.value, (path) => {
622
623
  const mix = dictionary.colorMix(path, tokenFn);
623
624
  if (mix.invalid) {
624
- throw new Error("Invalid color mix at " + path + ": " + mix.value);
625
+ throw new PandaError2("INVALID_TOKEN", "Invalid color mix at " + path + ": " + mix.value);
625
626
  }
626
627
  return mix.value;
627
628
  });
@@ -1098,13 +1099,13 @@ var TokenDictionary = class {
1098
1099
  return expandTokenReferences(value, (path) => {
1099
1100
  if (!path) return;
1100
1101
  if (path.includes("/")) {
1101
- const mix = this.colorMix(path, this.view.get.bind(this.view));
1102
+ const mix = this.colorMix(path, this.view.getVar.bind(this.view));
1102
1103
  if (mix.invalid) {
1103
- throw new Error("Invalid color mix at " + path + ": " + mix.value);
1104
+ throw new PandaError3("INVALID_TOKEN", "Invalid color mix at " + path + ": " + mix.value);
1104
1105
  }
1105
1106
  return mix.value;
1106
1107
  }
1107
- const resolved = this.view.get(path);
1108
+ const resolved = this.view.getVar(path);
1108
1109
  if (resolved) return resolved;
1109
1110
  return tokenPathRegex.test(path) ? esc3(path) : path;
1110
1111
  });
@@ -1170,13 +1171,14 @@ var TokenDictionaryView = class {
1170
1171
  const colorPalettes = /* @__PURE__ */ new Map();
1171
1172
  const valuesByCategory = /* @__PURE__ */ new Map();
1172
1173
  const flatValues = /* @__PURE__ */ new Map();
1174
+ const rawValues = /* @__PURE__ */ new Map();
1173
1175
  const nameByVar = /* @__PURE__ */ new Map();
1174
1176
  const vars = /* @__PURE__ */ new Map();
1175
1177
  this.dictionary.allTokens.forEach((token) => {
1176
1178
  this.processCondition(token, conditionMap);
1177
1179
  this.processColorPalette(token, colorPalettes, this.dictionary.byName);
1178
1180
  this.processCategory(token, categoryMap);
1179
- this.processValue(token, valuesByCategory, flatValues, nameByVar);
1181
+ this.processValue(token, valuesByCategory, flatValues, rawValues, nameByVar);
1180
1182
  this.processVars(token, vars);
1181
1183
  });
1182
1184
  const json = mapToJson(valuesByCategory);
@@ -1190,6 +1192,9 @@ var TokenDictionaryView = class {
1190
1192
  json,
1191
1193
  valuesByCategory,
1192
1194
  get: memo((path, fallback) => {
1195
+ return rawValues.get(path) ?? fallback;
1196
+ }),
1197
+ getVar: memo((path, fallback) => {
1193
1198
  return flatValues.get(path) ?? fallback;
1194
1199
  }),
1195
1200
  getCategoryValues: memo((category) => {
@@ -1244,14 +1249,16 @@ var TokenDictionaryView = class {
1244
1249
  if (!group.has(category)) group.set(category, /* @__PURE__ */ new Map());
1245
1250
  group.get(category).set(prop, token);
1246
1251
  }
1247
- processValue(token, byCategory, flatValues, nameByVar) {
1248
- const { category, prop, varRef, isNegative } = token.extensions;
1252
+ processValue(token, byCategory, flatValues, rawValues, nameByVar) {
1253
+ const { category, prop, varRef, isNegative, isVirtual, condition } = token.extensions;
1249
1254
  if (!category) return;
1250
1255
  if (!byCategory.has(category)) byCategory.set(category, /* @__PURE__ */ new Map());
1251
1256
  const value = isNegative ? token.extensions.condition !== "base" ? token.originalValue : token.value : varRef;
1252
1257
  byCategory.get(category).set(prop, value);
1253
1258
  flatValues.set(token.name, value);
1254
1259
  nameByVar.set(value, token.name);
1260
+ const rawValue = isVirtual || condition !== "base" ? varRef : token.value;
1261
+ rawValues.set(token.name, rawValue);
1255
1262
  }
1256
1263
  processVars(token, group) {
1257
1264
  const { condition, isNegative, isVirtual, var: varName, theme } = token.extensions;
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@pandacss/token-dictionary",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "Common error messages for css panda",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",
8
8
  "author": "Segun Adebayo <joseshegs@gmail.com>",
9
+ "license": "MIT",
9
10
  "sideEffects": false,
10
11
  "homepage": "https://panda-css.com",
11
12
  "repository": {
@@ -33,9 +34,9 @@
33
34
  ],
34
35
  "dependencies": {
35
36
  "ts-pattern": "5.8.0",
36
- "@pandacss/logger": "^1.4.0",
37
- "@pandacss/types": "1.4.0",
38
- "@pandacss/shared": "1.4.0"
37
+ "@pandacss/logger": "^1.4.2",
38
+ "@pandacss/shared": "1.4.2",
39
+ "@pandacss/types": "1.4.2"
39
40
  },
40
41
  "scripts": {
41
42
  "build": "tsup src/index.ts --format=esm,cjs --dts",