@pandacss/token-dictionary 0.37.0 → 0.37.1
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 +25 -3
- package/dist/index.d.ts +25 -3
- package/dist/index.js +42 -6
- package/dist/index.mjs +35 -5
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _pandacss_types from '@pandacss/types';
|
|
2
|
-
import { Tokens, SemanticTokens, ThemeVariantsMap } from '@pandacss/types';
|
|
2
|
+
import { Tokens, SemanticTokens, ThemeVariantsMap, Token as Token$1 } from '@pandacss/types';
|
|
3
3
|
import { CssVarOptions, CssVar } from '@pandacss/shared';
|
|
4
4
|
|
|
5
5
|
type TokenStatus = 'deprecated' | 'experimental' | 'new';
|
|
@@ -147,9 +147,13 @@ declare class TokenDictionary {
|
|
|
147
147
|
*/
|
|
148
148
|
expandReferenceInValue(value: string): string;
|
|
149
149
|
/**
|
|
150
|
-
*
|
|
150
|
+
* Get the value of a token reference
|
|
151
151
|
*/
|
|
152
152
|
resolveReference(value: string): string;
|
|
153
|
+
/**
|
|
154
|
+
* Resolve token references to their actual raw value (recursively resolves references)
|
|
155
|
+
*/
|
|
156
|
+
deepResolveReference(originalValue: string): string | undefined;
|
|
153
157
|
build(): this;
|
|
154
158
|
get isEmpty(): boolean;
|
|
155
159
|
view: ReturnType<TokenDictionaryView['getTokensView']>;
|
|
@@ -164,6 +168,7 @@ declare class TokenDictionaryView {
|
|
|
164
168
|
colorPalettes: Map<string, Map<string, string>>;
|
|
165
169
|
vars: Map<string, Map<string, string>>;
|
|
166
170
|
values: Map<string, string>;
|
|
171
|
+
nameByVar: Map<string, string>;
|
|
167
172
|
json: Record<string, Record<string, string>>;
|
|
168
173
|
get: (path: string, fallback?: string | number) => string;
|
|
169
174
|
getCategoryValues: (category: string) => Record<string, string> | undefined;
|
|
@@ -175,4 +180,21 @@ declare class TokenDictionaryView {
|
|
|
175
180
|
private processVars;
|
|
176
181
|
}
|
|
177
182
|
|
|
178
|
-
|
|
183
|
+
/**
|
|
184
|
+
* Returns all references in a string
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
*
|
|
188
|
+
* `{colors.red.300} {sizes.sm}` => ['colors.red.300', 'sizes.sm']
|
|
189
|
+
*/
|
|
190
|
+
declare function getReferences(value: string): string[];
|
|
191
|
+
declare const hasReference: (value: string) => boolean;
|
|
192
|
+
declare function expandReferences(value: string, fn: (key: string) => string): string;
|
|
193
|
+
/**
|
|
194
|
+
* Converts a JS Map to an object
|
|
195
|
+
*/
|
|
196
|
+
declare function mapToJson(map: Map<string, any>): Record<string, unknown>;
|
|
197
|
+
declare const isToken: (value: any) => value is Token$1<any>;
|
|
198
|
+
declare function assertTokenFormat(token: any): asserts token is Token$1;
|
|
199
|
+
|
|
200
|
+
export { Token, TokenDictionary, type TokenExtensions, assertTokenFormat, expandReferences, getReferences, hasReference, isToken, mapToJson };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _pandacss_types from '@pandacss/types';
|
|
2
|
-
import { Tokens, SemanticTokens, ThemeVariantsMap } from '@pandacss/types';
|
|
2
|
+
import { Tokens, SemanticTokens, ThemeVariantsMap, Token as Token$1 } from '@pandacss/types';
|
|
3
3
|
import { CssVarOptions, CssVar } from '@pandacss/shared';
|
|
4
4
|
|
|
5
5
|
type TokenStatus = 'deprecated' | 'experimental' | 'new';
|
|
@@ -147,9 +147,13 @@ declare class TokenDictionary {
|
|
|
147
147
|
*/
|
|
148
148
|
expandReferenceInValue(value: string): string;
|
|
149
149
|
/**
|
|
150
|
-
*
|
|
150
|
+
* Get the value of a token reference
|
|
151
151
|
*/
|
|
152
152
|
resolveReference(value: string): string;
|
|
153
|
+
/**
|
|
154
|
+
* Resolve token references to their actual raw value (recursively resolves references)
|
|
155
|
+
*/
|
|
156
|
+
deepResolveReference(originalValue: string): string | undefined;
|
|
153
157
|
build(): this;
|
|
154
158
|
get isEmpty(): boolean;
|
|
155
159
|
view: ReturnType<TokenDictionaryView['getTokensView']>;
|
|
@@ -164,6 +168,7 @@ declare class TokenDictionaryView {
|
|
|
164
168
|
colorPalettes: Map<string, Map<string, string>>;
|
|
165
169
|
vars: Map<string, Map<string, string>>;
|
|
166
170
|
values: Map<string, string>;
|
|
171
|
+
nameByVar: Map<string, string>;
|
|
167
172
|
json: Record<string, Record<string, string>>;
|
|
168
173
|
get: (path: string, fallback?: string | number) => string;
|
|
169
174
|
getCategoryValues: (category: string) => Record<string, string> | undefined;
|
|
@@ -175,4 +180,21 @@ declare class TokenDictionaryView {
|
|
|
175
180
|
private processVars;
|
|
176
181
|
}
|
|
177
182
|
|
|
178
|
-
|
|
183
|
+
/**
|
|
184
|
+
* Returns all references in a string
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
*
|
|
188
|
+
* `{colors.red.300} {sizes.sm}` => ['colors.red.300', 'sizes.sm']
|
|
189
|
+
*/
|
|
190
|
+
declare function getReferences(value: string): string[];
|
|
191
|
+
declare const hasReference: (value: string) => boolean;
|
|
192
|
+
declare function expandReferences(value: string, fn: (key: string) => string): string;
|
|
193
|
+
/**
|
|
194
|
+
* Converts a JS Map to an object
|
|
195
|
+
*/
|
|
196
|
+
declare function mapToJson(map: Map<string, any>): Record<string, unknown>;
|
|
197
|
+
declare const isToken: (value: any) => value is Token$1<any>;
|
|
198
|
+
declare function assertTokenFormat(token: any): asserts token is Token$1;
|
|
199
|
+
|
|
200
|
+
export { Token, TokenDictionary, type TokenExtensions, assertTokenFormat, expandReferences, getReferences, hasReference, isToken, mapToJson };
|
package/dist/index.js
CHANGED
|
@@ -21,7 +21,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
Token: () => Token,
|
|
24
|
-
TokenDictionary: () => TokenDictionary
|
|
24
|
+
TokenDictionary: () => TokenDictionary,
|
|
25
|
+
assertTokenFormat: () => assertTokenFormat,
|
|
26
|
+
expandReferences: () => expandReferences,
|
|
27
|
+
getReferences: () => getReferences,
|
|
28
|
+
hasReference: () => hasReference,
|
|
29
|
+
isToken: () => isToken,
|
|
30
|
+
mapToJson: () => mapToJson
|
|
25
31
|
});
|
|
26
32
|
module.exports = __toCommonJS(src_exports);
|
|
27
33
|
|
|
@@ -1001,11 +1007,32 @@ var TokenDictionary = class {
|
|
|
1001
1007
|
});
|
|
1002
1008
|
}
|
|
1003
1009
|
/**
|
|
1004
|
-
*
|
|
1010
|
+
* Get the value of a token reference
|
|
1005
1011
|
*/
|
|
1006
1012
|
resolveReference(value) {
|
|
1007
1013
|
return expandReferences(value, (key) => this.getByName(key)?.value);
|
|
1008
1014
|
}
|
|
1015
|
+
/**
|
|
1016
|
+
* Resolve token references to their actual raw value (recursively resolves references)
|
|
1017
|
+
*/
|
|
1018
|
+
deepResolveReference(originalValue) {
|
|
1019
|
+
const stack = [originalValue];
|
|
1020
|
+
while (stack.length) {
|
|
1021
|
+
const next = stack.pop();
|
|
1022
|
+
if (next.startsWith("{")) {
|
|
1023
|
+
stack.push(this.resolveReference(next));
|
|
1024
|
+
continue;
|
|
1025
|
+
}
|
|
1026
|
+
if (next.startsWith("var(")) {
|
|
1027
|
+
const ref = this.view.nameByVar.get(next);
|
|
1028
|
+
if (ref) {
|
|
1029
|
+
stack.push(this.resolveReference(`{${ref}}`));
|
|
1030
|
+
continue;
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
return next;
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1009
1036
|
build() {
|
|
1010
1037
|
this.applyMiddlewares("pre");
|
|
1011
1038
|
this.transformTokens("pre");
|
|
@@ -1037,12 +1064,13 @@ var TokenDictionaryView = class {
|
|
|
1037
1064
|
const colorPalettes = /* @__PURE__ */ new Map();
|
|
1038
1065
|
const valuesByCategory = /* @__PURE__ */ new Map();
|
|
1039
1066
|
const flatValues = /* @__PURE__ */ new Map();
|
|
1067
|
+
const nameByVar = /* @__PURE__ */ new Map();
|
|
1040
1068
|
const vars = /* @__PURE__ */ new Map();
|
|
1041
1069
|
this.dictionary.allTokens.forEach((token) => {
|
|
1042
1070
|
this.processCondition(token, conditionMap);
|
|
1043
1071
|
this.processColorPalette(token, colorPalettes, this.dictionary.byName);
|
|
1044
1072
|
this.processCategory(token, categoryMap);
|
|
1045
|
-
this.processValue(token, valuesByCategory, flatValues);
|
|
1073
|
+
this.processValue(token, valuesByCategory, flatValues, nameByVar);
|
|
1046
1074
|
this.processVars(token, vars);
|
|
1047
1075
|
});
|
|
1048
1076
|
const json = mapToJson(valuesByCategory);
|
|
@@ -1052,6 +1080,7 @@ var TokenDictionaryView = class {
|
|
|
1052
1080
|
colorPalettes,
|
|
1053
1081
|
vars,
|
|
1054
1082
|
values: flatValues,
|
|
1083
|
+
nameByVar,
|
|
1055
1084
|
json,
|
|
1056
1085
|
get: (0, import_shared5.memo)((path, fallback) => {
|
|
1057
1086
|
return flatValues.get(path) ?? fallback;
|
|
@@ -1117,7 +1146,7 @@ var TokenDictionaryView = class {
|
|
|
1117
1146
|
group.set(category, /* @__PURE__ */ new Map());
|
|
1118
1147
|
group.get(category).set(prop, token);
|
|
1119
1148
|
}
|
|
1120
|
-
processValue(token, byCategory,
|
|
1149
|
+
processValue(token, byCategory, flatValues, nameByVar) {
|
|
1121
1150
|
const { category, prop, varRef, isNegative } = token.extensions;
|
|
1122
1151
|
if (!category)
|
|
1123
1152
|
return;
|
|
@@ -1125,7 +1154,8 @@ var TokenDictionaryView = class {
|
|
|
1125
1154
|
byCategory.set(category, /* @__PURE__ */ new Map());
|
|
1126
1155
|
const value = isNegative ? token.extensions.condition !== "base" ? token.originalValue : token.value : varRef;
|
|
1127
1156
|
byCategory.get(category).set(prop, value);
|
|
1128
|
-
|
|
1157
|
+
flatValues.set(token.name, value);
|
|
1158
|
+
nameByVar.set(value, token.name);
|
|
1129
1159
|
}
|
|
1130
1160
|
processVars(token, group) {
|
|
1131
1161
|
const { condition, isNegative, isVirtual, var: varName, theme } = token.extensions;
|
|
@@ -1150,5 +1180,11 @@ function replaceRootWithColorPalette(path, colorPaletteRoot) {
|
|
|
1150
1180
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1151
1181
|
0 && (module.exports = {
|
|
1152
1182
|
Token,
|
|
1153
|
-
TokenDictionary
|
|
1183
|
+
TokenDictionary,
|
|
1184
|
+
assertTokenFormat,
|
|
1185
|
+
expandReferences,
|
|
1186
|
+
getReferences,
|
|
1187
|
+
hasReference,
|
|
1188
|
+
isToken,
|
|
1189
|
+
mapToJson
|
|
1154
1190
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -982,11 +982,32 @@ var TokenDictionary = class {
|
|
|
982
982
|
});
|
|
983
983
|
}
|
|
984
984
|
/**
|
|
985
|
-
*
|
|
985
|
+
* Get the value of a token reference
|
|
986
986
|
*/
|
|
987
987
|
resolveReference(value) {
|
|
988
988
|
return expandReferences(value, (key) => this.getByName(key)?.value);
|
|
989
989
|
}
|
|
990
|
+
/**
|
|
991
|
+
* Resolve token references to their actual raw value (recursively resolves references)
|
|
992
|
+
*/
|
|
993
|
+
deepResolveReference(originalValue) {
|
|
994
|
+
const stack = [originalValue];
|
|
995
|
+
while (stack.length) {
|
|
996
|
+
const next = stack.pop();
|
|
997
|
+
if (next.startsWith("{")) {
|
|
998
|
+
stack.push(this.resolveReference(next));
|
|
999
|
+
continue;
|
|
1000
|
+
}
|
|
1001
|
+
if (next.startsWith("var(")) {
|
|
1002
|
+
const ref = this.view.nameByVar.get(next);
|
|
1003
|
+
if (ref) {
|
|
1004
|
+
stack.push(this.resolveReference(`{${ref}}`));
|
|
1005
|
+
continue;
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
return next;
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
990
1011
|
build() {
|
|
991
1012
|
this.applyMiddlewares("pre");
|
|
992
1013
|
this.transformTokens("pre");
|
|
@@ -1018,12 +1039,13 @@ var TokenDictionaryView = class {
|
|
|
1018
1039
|
const colorPalettes = /* @__PURE__ */ new Map();
|
|
1019
1040
|
const valuesByCategory = /* @__PURE__ */ new Map();
|
|
1020
1041
|
const flatValues = /* @__PURE__ */ new Map();
|
|
1042
|
+
const nameByVar = /* @__PURE__ */ new Map();
|
|
1021
1043
|
const vars = /* @__PURE__ */ new Map();
|
|
1022
1044
|
this.dictionary.allTokens.forEach((token) => {
|
|
1023
1045
|
this.processCondition(token, conditionMap);
|
|
1024
1046
|
this.processColorPalette(token, colorPalettes, this.dictionary.byName);
|
|
1025
1047
|
this.processCategory(token, categoryMap);
|
|
1026
|
-
this.processValue(token, valuesByCategory, flatValues);
|
|
1048
|
+
this.processValue(token, valuesByCategory, flatValues, nameByVar);
|
|
1027
1049
|
this.processVars(token, vars);
|
|
1028
1050
|
});
|
|
1029
1051
|
const json = mapToJson(valuesByCategory);
|
|
@@ -1033,6 +1055,7 @@ var TokenDictionaryView = class {
|
|
|
1033
1055
|
colorPalettes,
|
|
1034
1056
|
vars,
|
|
1035
1057
|
values: flatValues,
|
|
1058
|
+
nameByVar,
|
|
1036
1059
|
json,
|
|
1037
1060
|
get: memo((path, fallback) => {
|
|
1038
1061
|
return flatValues.get(path) ?? fallback;
|
|
@@ -1098,7 +1121,7 @@ var TokenDictionaryView = class {
|
|
|
1098
1121
|
group.set(category, /* @__PURE__ */ new Map());
|
|
1099
1122
|
group.get(category).set(prop, token);
|
|
1100
1123
|
}
|
|
1101
|
-
processValue(token, byCategory,
|
|
1124
|
+
processValue(token, byCategory, flatValues, nameByVar) {
|
|
1102
1125
|
const { category, prop, varRef, isNegative } = token.extensions;
|
|
1103
1126
|
if (!category)
|
|
1104
1127
|
return;
|
|
@@ -1106,7 +1129,8 @@ var TokenDictionaryView = class {
|
|
|
1106
1129
|
byCategory.set(category, /* @__PURE__ */ new Map());
|
|
1107
1130
|
const value = isNegative ? token.extensions.condition !== "base" ? token.originalValue : token.value : varRef;
|
|
1108
1131
|
byCategory.get(category).set(prop, value);
|
|
1109
|
-
|
|
1132
|
+
flatValues.set(token.name, value);
|
|
1133
|
+
nameByVar.set(value, token.name);
|
|
1110
1134
|
}
|
|
1111
1135
|
processVars(token, group) {
|
|
1112
1136
|
const { condition, isNegative, isVirtual, var: varName, theme } = token.extensions;
|
|
@@ -1130,5 +1154,11 @@ function replaceRootWithColorPalette(path, colorPaletteRoot) {
|
|
|
1130
1154
|
}
|
|
1131
1155
|
export {
|
|
1132
1156
|
Token,
|
|
1133
|
-
TokenDictionary
|
|
1157
|
+
TokenDictionary,
|
|
1158
|
+
assertTokenFormat,
|
|
1159
|
+
expandReferences,
|
|
1160
|
+
getReferences,
|
|
1161
|
+
hasReference,
|
|
1162
|
+
isToken,
|
|
1163
|
+
mapToJson
|
|
1134
1164
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pandacss/token-dictionary",
|
|
3
|
-
"version": "0.37.
|
|
3
|
+
"version": "0.37.1",
|
|
4
4
|
"description": "Common error messages for css panda",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"ts-pattern": "5.0.8",
|
|
36
|
-
"@pandacss/logger": "^0.37.
|
|
37
|
-
"@pandacss/shared": "0.37.
|
|
38
|
-
"@pandacss/types": "0.37.
|
|
36
|
+
"@pandacss/logger": "^0.37.1",
|
|
37
|
+
"@pandacss/shared": "0.37.1",
|
|
38
|
+
"@pandacss/types": "0.37.1"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "tsup src/index.ts --format=esm,cjs --dts",
|