@pandacss/token-dictionary 0.27.3 → 0.29.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.d.mts CHANGED
@@ -154,7 +154,14 @@ declare class TokenDictionary extends TokenDictionary$1 {
154
154
  [k: string]: string;
155
155
  } | undefined;
156
156
  getTokenVar: (path: string) => any;
157
+ /**
158
+ * Expand token references to their CSS variable
159
+ */
157
160
  expandReference(value: string): string;
161
+ /**
162
+ * Resolve token references to their actual raw value
163
+ */
164
+ resolveReference(value: string): string;
158
165
  }
159
166
 
160
167
  export { Token, TokenDictionary };
package/dist/index.d.ts CHANGED
@@ -154,7 +154,14 @@ declare class TokenDictionary extends TokenDictionary$1 {
154
154
  [k: string]: string;
155
155
  } | undefined;
156
156
  getTokenVar: (path: string) => any;
157
+ /**
158
+ * Expand token references to their CSS variable
159
+ */
157
160
  expandReference(value: string): string;
161
+ /**
162
+ * Resolve token references to their actual raw value
163
+ */
164
+ resolveReference(value: string): string;
158
165
  }
159
166
 
160
167
  export { Token, TokenDictionary };
package/dist/index.js CHANGED
@@ -70,6 +70,7 @@ var isCompositeTokenValue = (value) => {
70
70
  var import_shared2 = require("@pandacss/shared");
71
71
 
72
72
  // src/utils.ts
73
+ var import_logger = require("@pandacss/logger");
73
74
  var import_shared = require("@pandacss/shared");
74
75
  var REFERENCE_REGEX = /(\$[^\s,]+\w)|({([^}]*)})/g;
75
76
  var curlyBracketRegex = /[{}]/g;
@@ -81,17 +82,42 @@ function getReferences(value) {
81
82
  return [];
82
83
  return matches.map((match3) => match3.replace(curlyBracketRegex, "")).map((value2) => value2.trim());
83
84
  }
84
- function hasReference(value) {
85
- return REFERENCE_REGEX.test(value);
86
- }
85
+ var hasReference = (value) => REFERENCE_REGEX.test(value);
86
+ var tokenFunctionRegex = /token\(([^)]+)\)/g;
87
+ var closingParenthesisRegex = /\)$/g;
88
+ var hasTokenReference = (str) => str.includes("token(");
89
+ var tokenReplacer = (a, b) => b ? a.endsWith(")") ? a.replace(closingParenthesisRegex, `, ${b})`) : `var(${a}, ${b})` : a;
90
+ var notFoundMessage = (key, value) => `Reference not found: \`${key}\` in "${value}"`;
91
+ var isTokenReference = (v) => hasReference(v) || hasTokenReference(v);
87
92
  function expandReferences(value, fn) {
88
- if (!hasReference(value))
93
+ if (!isTokenReference(value))
89
94
  return value;
90
95
  const references = getReferences(value);
91
- return references.reduce((valueStr, key) => {
92
- const value2 = fn(key) ?? key;
93
- return valueStr.replace(`{${key}}`, value2);
96
+ const expanded = references.reduce((valueStr, key) => {
97
+ const resolved = fn(key);
98
+ if (!resolved) {
99
+ import_logger.logger.warn("token", notFoundMessage(key, value));
100
+ }
101
+ const expandedValue = resolved ?? (0, import_shared.esc)(key);
102
+ return valueStr.replace(`{${key}}`, expandedValue);
94
103
  }, value);
104
+ if (!expanded.includes(`token(`))
105
+ return expanded;
106
+ return expanded.replace(tokenFunctionRegex, (_, token) => {
107
+ const [tokenValue, tokenFallback] = token.split(",").map((s) => s.trim());
108
+ const result = [tokenValue, tokenFallback].filter(Boolean).map((key) => {
109
+ const resolved = fn(key);
110
+ if (!resolved && isTokenReference(key)) {
111
+ import_logger.logger.warn("token", notFoundMessage(key, value));
112
+ }
113
+ return resolved ?? (0, import_shared.esc)(key);
114
+ });
115
+ if (result.length > 1) {
116
+ const [a, b] = result;
117
+ return tokenReplacer(a, b);
118
+ }
119
+ return tokenReplacer(result[0]);
120
+ });
95
121
  }
96
122
  function mapToJson(map) {
97
123
  const obj = {};
@@ -109,7 +135,7 @@ var isToken = (value) => {
109
135
  };
110
136
  function assertTokenFormat(token) {
111
137
  if (!isToken(token)) {
112
- throw new Error(`Invalid token format: ${JSON.stringify(token)}`);
138
+ throw new import_shared.PandaError("INVALID_TOKEN", `Invalid token format: ${JSON.stringify(token)}`);
113
139
  }
114
140
  }
115
141
 
@@ -269,6 +295,7 @@ var TOKEN_TYPES = {
269
295
  gradients: "gradient",
270
296
  easings: "cubicBezier",
271
297
  borders: "border",
298
+ borderWidths: "borderWidth",
272
299
  components: "cti",
273
300
  assets: "asset",
274
301
  aspectRatios: "aspectRatio"
@@ -952,9 +979,18 @@ var TokenDictionary2 = class extends TokenDictionary {
952
979
  getTokenVar = (0, import_shared7.memo)((path) => {
953
980
  return (0, import_shared7.getDotPath)(this.json, path);
954
981
  });
982
+ /**
983
+ * Expand token references to their CSS variable
984
+ */
955
985
  expandReference(value) {
956
986
  return expandReferences(value, (key) => this.get(key));
957
987
  }
988
+ /**
989
+ * Resolve token references to their actual raw value
990
+ */
991
+ resolveReference(value) {
992
+ return expandReferences(value, (key) => this.getByName(key)?.value);
993
+ }
958
994
  };
959
995
  // Annotate the CommonJS export names for ESM import in node:
960
996
  0 && (module.exports = {
package/dist/index.mjs CHANGED
@@ -43,7 +43,8 @@ var isCompositeTokenValue = (value) => {
43
43
  import { isBaseCondition, toHash, walkObject } from "@pandacss/shared";
44
44
 
45
45
  // src/utils.ts
46
- import { isObject } from "@pandacss/shared";
46
+ import { logger } from "@pandacss/logger";
47
+ import { PandaError, esc, isObject } from "@pandacss/shared";
47
48
  var REFERENCE_REGEX = /(\$[^\s,]+\w)|({([^}]*)})/g;
48
49
  var curlyBracketRegex = /[{}]/g;
49
50
  function getReferences(value) {
@@ -54,17 +55,42 @@ function getReferences(value) {
54
55
  return [];
55
56
  return matches.map((match3) => match3.replace(curlyBracketRegex, "")).map((value2) => value2.trim());
56
57
  }
57
- function hasReference(value) {
58
- return REFERENCE_REGEX.test(value);
59
- }
58
+ var hasReference = (value) => REFERENCE_REGEX.test(value);
59
+ var tokenFunctionRegex = /token\(([^)]+)\)/g;
60
+ var closingParenthesisRegex = /\)$/g;
61
+ var hasTokenReference = (str) => str.includes("token(");
62
+ var tokenReplacer = (a, b) => b ? a.endsWith(")") ? a.replace(closingParenthesisRegex, `, ${b})`) : `var(${a}, ${b})` : a;
63
+ var notFoundMessage = (key, value) => `Reference not found: \`${key}\` in "${value}"`;
64
+ var isTokenReference = (v) => hasReference(v) || hasTokenReference(v);
60
65
  function expandReferences(value, fn) {
61
- if (!hasReference(value))
66
+ if (!isTokenReference(value))
62
67
  return value;
63
68
  const references = getReferences(value);
64
- return references.reduce((valueStr, key) => {
65
- const value2 = fn(key) ?? key;
66
- return valueStr.replace(`{${key}}`, value2);
69
+ const expanded = references.reduce((valueStr, key) => {
70
+ const resolved = fn(key);
71
+ if (!resolved) {
72
+ logger.warn("token", notFoundMessage(key, value));
73
+ }
74
+ const expandedValue = resolved ?? esc(key);
75
+ return valueStr.replace(`{${key}}`, expandedValue);
67
76
  }, value);
77
+ if (!expanded.includes(`token(`))
78
+ return expanded;
79
+ return expanded.replace(tokenFunctionRegex, (_, token) => {
80
+ const [tokenValue, tokenFallback] = token.split(",").map((s) => s.trim());
81
+ const result = [tokenValue, tokenFallback].filter(Boolean).map((key) => {
82
+ const resolved = fn(key);
83
+ if (!resolved && isTokenReference(key)) {
84
+ logger.warn("token", notFoundMessage(key, value));
85
+ }
86
+ return resolved ?? esc(key);
87
+ });
88
+ if (result.length > 1) {
89
+ const [a, b] = result;
90
+ return tokenReplacer(a, b);
91
+ }
92
+ return tokenReplacer(result[0]);
93
+ });
68
94
  }
69
95
  function mapToJson(map) {
70
96
  const obj = {};
@@ -82,7 +108,7 @@ var isToken = (value) => {
82
108
  };
83
109
  function assertTokenFormat(token) {
84
110
  if (!isToken(token)) {
85
- throw new Error(`Invalid token format: ${JSON.stringify(token)}`);
111
+ throw new PandaError("INVALID_TOKEN", `Invalid token format: ${JSON.stringify(token)}`);
86
112
  }
87
113
  }
88
114
 
@@ -242,6 +268,7 @@ var TOKEN_TYPES = {
242
268
  gradients: "gradient",
243
269
  easings: "cubicBezier",
244
270
  borders: "border",
271
+ borderWidths: "borderWidth",
245
272
  components: "cti",
246
273
  assets: "asset",
247
274
  aspectRatios: "aspectRatio"
@@ -925,9 +952,18 @@ var TokenDictionary2 = class extends TokenDictionary {
925
952
  getTokenVar = memo2((path) => {
926
953
  return getDotPath2(this.json, path);
927
954
  });
955
+ /**
956
+ * Expand token references to their CSS variable
957
+ */
928
958
  expandReference(value) {
929
959
  return expandReferences(value, (key) => this.get(key));
930
960
  }
961
+ /**
962
+ * Resolve token references to their actual raw value
963
+ */
964
+ resolveReference(value) {
965
+ return expandReferences(value, (key) => this.getByName(key)?.value);
966
+ }
931
967
  };
932
968
  export {
933
969
  Token,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pandacss/token-dictionary",
3
- "version": "0.27.3",
3
+ "version": "0.29.0",
4
4
  "description": "Common error messages for css panda",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -33,8 +33,9 @@
33
33
  ],
34
34
  "dependencies": {
35
35
  "ts-pattern": "5.0.5",
36
- "@pandacss/shared": "0.27.3",
37
- "@pandacss/types": "0.27.3"
36
+ "@pandacss/logger": "^0.29.0",
37
+ "@pandacss/shared": "0.29.0",
38
+ "@pandacss/types": "0.29.0"
38
39
  },
39
40
  "scripts": {
40
41
  "build": "tsup src/index.ts --format=esm,cjs --dts",