@pandacss/token-dictionary 0.0.0-dev-20221121152823
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/LICENSE.md +21 -0
- package/dist/index.d.ts +216 -0
- package/dist/index.js +694 -0
- package/dist/index.mjs +667 -0
- package/package.json +28 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,667 @@
|
|
|
1
|
+
// src/create-dictionary.ts
|
|
2
|
+
import { getDotPath as getDotPath2, mapToJson as mapToJson2 } from "@pandacss/shared";
|
|
3
|
+
|
|
4
|
+
// src/dictionary.ts
|
|
5
|
+
import { isString, memo, walkObject } from "@pandacss/shared";
|
|
6
|
+
import { isMatching, match } from "ts-pattern";
|
|
7
|
+
|
|
8
|
+
// src/token.ts
|
|
9
|
+
import { isObject as isObject2 } from "@pandacss/shared";
|
|
10
|
+
|
|
11
|
+
// src/utils.ts
|
|
12
|
+
import { isObject } from "@pandacss/shared";
|
|
13
|
+
var REFERENCE_REGEX = /(\$[^\s,]+\w)|({([^}]*)})/g;
|
|
14
|
+
function getReferences(value) {
|
|
15
|
+
if (typeof value !== "string")
|
|
16
|
+
return [];
|
|
17
|
+
const matches = value.match(REFERENCE_REGEX);
|
|
18
|
+
if (!matches)
|
|
19
|
+
return [];
|
|
20
|
+
return matches.map((match2) => match2.replace(/[{}]/g, "")).map((value2) => value2.trim());
|
|
21
|
+
}
|
|
22
|
+
function hasReference(value) {
|
|
23
|
+
return REFERENCE_REGEX.test(value);
|
|
24
|
+
}
|
|
25
|
+
function mapToJson(map) {
|
|
26
|
+
const obj = {};
|
|
27
|
+
map.forEach((value, key) => {
|
|
28
|
+
if (value instanceof Map) {
|
|
29
|
+
obj[key] = Object.fromEntries(value);
|
|
30
|
+
} else {
|
|
31
|
+
obj[key] = value;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return obj;
|
|
35
|
+
}
|
|
36
|
+
var isToken = (value) => {
|
|
37
|
+
return isObject(value) && "value" in value;
|
|
38
|
+
};
|
|
39
|
+
function assertTokenFormat(token) {
|
|
40
|
+
if (!isToken(token)) {
|
|
41
|
+
throw new Error(`Invalid token format: ${JSON.stringify(token)}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/token.ts
|
|
46
|
+
var Token = class {
|
|
47
|
+
name;
|
|
48
|
+
value;
|
|
49
|
+
originalValue;
|
|
50
|
+
path;
|
|
51
|
+
type;
|
|
52
|
+
description;
|
|
53
|
+
extensions;
|
|
54
|
+
constructor(data) {
|
|
55
|
+
this.name = data.name;
|
|
56
|
+
this.value = data.value;
|
|
57
|
+
this.originalValue = data.value;
|
|
58
|
+
this.path = data.path ?? [];
|
|
59
|
+
if (data.type) {
|
|
60
|
+
this.type = data.type;
|
|
61
|
+
}
|
|
62
|
+
if (data.description) {
|
|
63
|
+
this.description = data.description;
|
|
64
|
+
}
|
|
65
|
+
this.extensions = data.extensions ?? {};
|
|
66
|
+
this.extensions.condition = data.extensions?.condition ?? "base";
|
|
67
|
+
this.setType();
|
|
68
|
+
}
|
|
69
|
+
get isConditional() {
|
|
70
|
+
return !!this.extensions?.conditions;
|
|
71
|
+
}
|
|
72
|
+
get hasReference() {
|
|
73
|
+
return !!this.extensions?.references;
|
|
74
|
+
}
|
|
75
|
+
get isComposite() {
|
|
76
|
+
return isObject2(this.originalValue) || Array.isArray(this.originalValue);
|
|
77
|
+
}
|
|
78
|
+
expandReferences() {
|
|
79
|
+
if (!this.hasReference)
|
|
80
|
+
return this.value;
|
|
81
|
+
const references = this.extensions.references ?? {};
|
|
82
|
+
this.value = Object.keys(references).reduce((valueStr, key) => {
|
|
83
|
+
const referenceToken = references[key];
|
|
84
|
+
if (referenceToken.isConditional) {
|
|
85
|
+
return valueStr;
|
|
86
|
+
}
|
|
87
|
+
const value = referenceToken.expandReferences();
|
|
88
|
+
return valueStr.replace(`{${key}}`, value);
|
|
89
|
+
}, this.value);
|
|
90
|
+
delete this.extensions.references;
|
|
91
|
+
return this.value;
|
|
92
|
+
}
|
|
93
|
+
get isReference() {
|
|
94
|
+
return hasReference(this.originalValue);
|
|
95
|
+
}
|
|
96
|
+
get references() {
|
|
97
|
+
return getReferences(this.originalValue);
|
|
98
|
+
}
|
|
99
|
+
clone() {
|
|
100
|
+
return new Token({
|
|
101
|
+
name: this.name,
|
|
102
|
+
value: this.value,
|
|
103
|
+
type: this.type,
|
|
104
|
+
path: [...this.path],
|
|
105
|
+
description: this.description,
|
|
106
|
+
extensions: cloneDeep(this.extensions)
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
getConditionTokens() {
|
|
110
|
+
if (!this.isConditional)
|
|
111
|
+
return;
|
|
112
|
+
const conditions = this.extensions.conditions ?? {};
|
|
113
|
+
const conditionalTokens = Object.entries(conditions).filter(([key]) => key !== "base").map(([key, value]) => {
|
|
114
|
+
const token = this.clone();
|
|
115
|
+
token.value = value;
|
|
116
|
+
token.extensions.condition = key;
|
|
117
|
+
return token;
|
|
118
|
+
});
|
|
119
|
+
return conditionalTokens;
|
|
120
|
+
}
|
|
121
|
+
setExtensions(extensions) {
|
|
122
|
+
this.extensions = { ...this.extensions, ...extensions };
|
|
123
|
+
this.setType();
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
setType() {
|
|
127
|
+
if (this.type)
|
|
128
|
+
return;
|
|
129
|
+
if (this.extensions.category) {
|
|
130
|
+
this.type = TokenTypes[this.extensions.category];
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
function cloneDeep(value) {
|
|
135
|
+
if (value instanceof Token) {
|
|
136
|
+
return value.clone();
|
|
137
|
+
}
|
|
138
|
+
if (Array.isArray(value)) {
|
|
139
|
+
return value.map((child) => cloneDeep(child));
|
|
140
|
+
}
|
|
141
|
+
if (typeof value === "object" && value !== null) {
|
|
142
|
+
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, cloneDeep(v)]));
|
|
143
|
+
}
|
|
144
|
+
return value;
|
|
145
|
+
}
|
|
146
|
+
var TokenTypes = {
|
|
147
|
+
colors: "color",
|
|
148
|
+
spacing: "dimension",
|
|
149
|
+
sizing: "dimension",
|
|
150
|
+
shadows: "shadow",
|
|
151
|
+
fonts: "fontFamily",
|
|
152
|
+
fontSizes: "fontSize",
|
|
153
|
+
fontWeights: "fontWeight",
|
|
154
|
+
letterSpacings: "letterSpacing",
|
|
155
|
+
durations: "duration",
|
|
156
|
+
transitions: "transition",
|
|
157
|
+
radii: "borderRadius",
|
|
158
|
+
gradients: "gradient",
|
|
159
|
+
easings: "cubicBezier",
|
|
160
|
+
borders: "border",
|
|
161
|
+
components: "cti"
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// src/dictionary.ts
|
|
165
|
+
var TokenDictionary = class {
|
|
166
|
+
allTokens = [];
|
|
167
|
+
prefix;
|
|
168
|
+
get allNames() {
|
|
169
|
+
return Array.from(new Set(this.allTokens.map((token) => token.name)));
|
|
170
|
+
}
|
|
171
|
+
constructor(options) {
|
|
172
|
+
const { tokens = {}, semanticTokens = {}, prefix } = options;
|
|
173
|
+
this.prefix = prefix;
|
|
174
|
+
walkObject(
|
|
175
|
+
tokens,
|
|
176
|
+
(token, path) => {
|
|
177
|
+
assertTokenFormat(token);
|
|
178
|
+
const category = path[0];
|
|
179
|
+
const name = path.join(".");
|
|
180
|
+
const node = new Token({ ...token, name, path });
|
|
181
|
+
node.setExtensions({
|
|
182
|
+
category,
|
|
183
|
+
prop: path.slice(1).join(".")
|
|
184
|
+
});
|
|
185
|
+
this.allTokens.push(node);
|
|
186
|
+
},
|
|
187
|
+
{ stop: isToken }
|
|
188
|
+
);
|
|
189
|
+
walkObject(
|
|
190
|
+
semanticTokens,
|
|
191
|
+
(token, path) => {
|
|
192
|
+
assertTokenFormat(token);
|
|
193
|
+
const category = path[0];
|
|
194
|
+
const name = path.join(".");
|
|
195
|
+
const normalizedToken = isString(token.value) ? { value: { base: token.value } } : token;
|
|
196
|
+
const { value, ...restData } = normalizedToken;
|
|
197
|
+
const node = new Token({
|
|
198
|
+
...restData,
|
|
199
|
+
name,
|
|
200
|
+
value: value.base || "",
|
|
201
|
+
path
|
|
202
|
+
});
|
|
203
|
+
node.setExtensions({
|
|
204
|
+
category,
|
|
205
|
+
conditions: value,
|
|
206
|
+
prop: path.slice(1).join(".")
|
|
207
|
+
});
|
|
208
|
+
this.allTokens.push(node);
|
|
209
|
+
},
|
|
210
|
+
{ stop: isToken }
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
getByName = memo((name) => {
|
|
214
|
+
for (const token of this.allTokens) {
|
|
215
|
+
if (token.name === name)
|
|
216
|
+
return token;
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
transforms = /* @__PURE__ */ new Map();
|
|
220
|
+
registerTransform(...transforms2) {
|
|
221
|
+
transforms2.forEach((transform) => {
|
|
222
|
+
transform.type ||= "value";
|
|
223
|
+
transform.enforce ||= "pre";
|
|
224
|
+
this.transforms.set(transform.name, transform);
|
|
225
|
+
});
|
|
226
|
+
return this;
|
|
227
|
+
}
|
|
228
|
+
execTransform(name) {
|
|
229
|
+
const transform = this.transforms.get(name);
|
|
230
|
+
if (!transform)
|
|
231
|
+
return;
|
|
232
|
+
this.allTokens.forEach((token) => {
|
|
233
|
+
if (token.extensions.hasReference)
|
|
234
|
+
return;
|
|
235
|
+
if (typeof transform.match === "function" && !transform.match(token))
|
|
236
|
+
return;
|
|
237
|
+
const transformed = transform.transform(token, { prefix: this.prefix });
|
|
238
|
+
match(transform).with({ type: "extensions" }, () => {
|
|
239
|
+
token.setExtensions(transformed);
|
|
240
|
+
}).with({ type: "value" }, () => {
|
|
241
|
+
token.value = transformed;
|
|
242
|
+
if (token.isComposite) {
|
|
243
|
+
token.originalValue = transformed;
|
|
244
|
+
}
|
|
245
|
+
}).otherwise(() => {
|
|
246
|
+
token[transform.type] = transformed;
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
transformTokens(enforce) {
|
|
251
|
+
this.transforms.forEach((transform) => {
|
|
252
|
+
if (transform.enforce === enforce) {
|
|
253
|
+
this.execTransform(transform.name);
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
return this;
|
|
257
|
+
}
|
|
258
|
+
middlewares = [];
|
|
259
|
+
registerMiddleware(...middlewares2) {
|
|
260
|
+
for (const middleware of middlewares2) {
|
|
261
|
+
middleware.enforce ||= "pre";
|
|
262
|
+
this.middlewares.push(middleware);
|
|
263
|
+
}
|
|
264
|
+
return this;
|
|
265
|
+
}
|
|
266
|
+
applyMiddlewares(enforce) {
|
|
267
|
+
this.middlewares.forEach((middleware) => {
|
|
268
|
+
if (middleware.enforce === enforce) {
|
|
269
|
+
middleware.transform(this, { prefix: this.prefix });
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
getReferences(value) {
|
|
274
|
+
const refs = getReferences(value);
|
|
275
|
+
return refs.map((ref) => this.getByName(ref)).filter(Boolean);
|
|
276
|
+
}
|
|
277
|
+
usesReference(value) {
|
|
278
|
+
if (!isString(value))
|
|
279
|
+
return false;
|
|
280
|
+
return this.getReferences(value).length > 0;
|
|
281
|
+
}
|
|
282
|
+
addReferences() {
|
|
283
|
+
this.allTokens.forEach((token) => {
|
|
284
|
+
if (!this.usesReference(token.value))
|
|
285
|
+
return;
|
|
286
|
+
const references = this.getReferences(token.value);
|
|
287
|
+
token.setExtensions({
|
|
288
|
+
references: references.reduce((object, reference) => {
|
|
289
|
+
object[reference.name] = reference;
|
|
290
|
+
return object;
|
|
291
|
+
}, {})
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
return this;
|
|
295
|
+
}
|
|
296
|
+
filter(pattern) {
|
|
297
|
+
const predicate = typeof pattern === "function" ? pattern : isMatching(pattern);
|
|
298
|
+
return this.allTokens.filter(predicate);
|
|
299
|
+
}
|
|
300
|
+
addConditionalTokens() {
|
|
301
|
+
const tokens = [];
|
|
302
|
+
this.allTokens.forEach((token) => {
|
|
303
|
+
tokens.push(token);
|
|
304
|
+
const conditionalTokens = token.getConditionTokens();
|
|
305
|
+
if (conditionalTokens && conditionalTokens.length > 0) {
|
|
306
|
+
tokens.push(...conditionalTokens);
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
this.allTokens = tokens;
|
|
310
|
+
return this;
|
|
311
|
+
}
|
|
312
|
+
expandReferences() {
|
|
313
|
+
this.allTokens.forEach((token) => {
|
|
314
|
+
token.expandReferences();
|
|
315
|
+
});
|
|
316
|
+
return this;
|
|
317
|
+
}
|
|
318
|
+
build() {
|
|
319
|
+
this.applyMiddlewares("pre");
|
|
320
|
+
this.transformTokens("pre");
|
|
321
|
+
this.addConditionalTokens();
|
|
322
|
+
this.addReferences();
|
|
323
|
+
this.expandReferences();
|
|
324
|
+
this.applyMiddlewares("post");
|
|
325
|
+
this.transformTokens("post");
|
|
326
|
+
}
|
|
327
|
+
get isEmpty() {
|
|
328
|
+
return this.allTokens.length === 0;
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
// src/format.ts
|
|
333
|
+
import { getDotPath } from "@pandacss/shared";
|
|
334
|
+
var formats = {
|
|
335
|
+
groupByCondition(dictionary) {
|
|
336
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
337
|
+
dictionary.allTokens.forEach((token) => {
|
|
338
|
+
const { condition } = token.extensions;
|
|
339
|
+
if (!condition)
|
|
340
|
+
return;
|
|
341
|
+
grouped.get(condition) || grouped.set(condition, /* @__PURE__ */ new Set());
|
|
342
|
+
grouped.set(condition, grouped.get(condition).add(token));
|
|
343
|
+
});
|
|
344
|
+
return grouped;
|
|
345
|
+
},
|
|
346
|
+
groupByPalette(dictionary) {
|
|
347
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
348
|
+
dictionary.allTokens.forEach((token) => {
|
|
349
|
+
const { palette } = token.extensions;
|
|
350
|
+
if (!palette || token.extensions.isVirtual)
|
|
351
|
+
return;
|
|
352
|
+
grouped.get(palette) || grouped.set(palette, /* @__PURE__ */ new Map());
|
|
353
|
+
const virtualName = token.name.replace(palette, "palette");
|
|
354
|
+
const virtualToken = dictionary.getByName(virtualName);
|
|
355
|
+
if (!virtualToken)
|
|
356
|
+
return;
|
|
357
|
+
const virtualVar = virtualToken.extensions.var;
|
|
358
|
+
grouped.get(palette).set(virtualVar, token.extensions.varRef);
|
|
359
|
+
});
|
|
360
|
+
return grouped;
|
|
361
|
+
},
|
|
362
|
+
groupByCategory(dictionary) {
|
|
363
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
364
|
+
dictionary.allTokens.forEach((token) => {
|
|
365
|
+
const { category, prop } = token.extensions;
|
|
366
|
+
if (!category)
|
|
367
|
+
return;
|
|
368
|
+
grouped.get(category) || grouped.set(category, /* @__PURE__ */ new Map());
|
|
369
|
+
grouped.set(category, grouped.get(category).set(prop, token));
|
|
370
|
+
});
|
|
371
|
+
return grouped;
|
|
372
|
+
},
|
|
373
|
+
getFlattenedValues(dictionary) {
|
|
374
|
+
const grouped = formats.groupByCategory(dictionary);
|
|
375
|
+
const result = /* @__PURE__ */ new Map();
|
|
376
|
+
grouped.forEach((tokens, category) => {
|
|
377
|
+
result.get(category) || result.set(category, /* @__PURE__ */ new Map());
|
|
378
|
+
tokens.forEach((token) => {
|
|
379
|
+
const { prop, varRef, isNegative } = token.extensions;
|
|
380
|
+
const value = isNegative ? token.isConditional ? token.originalValue : token.value : varRef;
|
|
381
|
+
result.set(category, result.get(category).set(prop, value));
|
|
382
|
+
});
|
|
383
|
+
});
|
|
384
|
+
return result;
|
|
385
|
+
},
|
|
386
|
+
getVars(dictionary) {
|
|
387
|
+
const grouped = formats.groupByCondition(dictionary);
|
|
388
|
+
const result = /* @__PURE__ */ new Map();
|
|
389
|
+
grouped.forEach((tokens, condition) => {
|
|
390
|
+
result.get(condition) || result.set(condition, /* @__PURE__ */ new Map());
|
|
391
|
+
tokens.forEach((token) => {
|
|
392
|
+
if (token.extensions.isNegative)
|
|
393
|
+
return;
|
|
394
|
+
result.get(condition).set(token.extensions.var, token.value);
|
|
395
|
+
});
|
|
396
|
+
});
|
|
397
|
+
return result;
|
|
398
|
+
},
|
|
399
|
+
createVarGetter(dictionary) {
|
|
400
|
+
const flatValues = mapToJson(formats.getFlattenedValues(dictionary));
|
|
401
|
+
return function getToken(path, fallback) {
|
|
402
|
+
return getDotPath(flatValues, path, fallback);
|
|
403
|
+
};
|
|
404
|
+
},
|
|
405
|
+
getPaletteValues(dictionary) {
|
|
406
|
+
const values = /* @__PURE__ */ new Set();
|
|
407
|
+
dictionary.allTokens.forEach((token) => {
|
|
408
|
+
const { palette } = token.extensions;
|
|
409
|
+
if (!palette || token.extensions.isVirtual)
|
|
410
|
+
return;
|
|
411
|
+
values.add(palette);
|
|
412
|
+
});
|
|
413
|
+
return values;
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
// src/middleware.ts
|
|
418
|
+
import { calc, cssVar } from "@pandacss/shared";
|
|
419
|
+
var addNegativeTokens = {
|
|
420
|
+
enforce: "pre",
|
|
421
|
+
transform(dictionary, { prefix }) {
|
|
422
|
+
const tokens = dictionary.filter({
|
|
423
|
+
extensions: { category: "spacing" }
|
|
424
|
+
});
|
|
425
|
+
tokens.forEach((token) => {
|
|
426
|
+
const originalPath = [...token.path];
|
|
427
|
+
const originalVar = cssVar(originalPath.join("-"), { prefix });
|
|
428
|
+
const node = token.clone();
|
|
429
|
+
node.setExtensions({
|
|
430
|
+
isNegative: true,
|
|
431
|
+
prop: `-${token.extensions.prop}`,
|
|
432
|
+
originalPath
|
|
433
|
+
});
|
|
434
|
+
node.value = calc.negate(originalVar);
|
|
435
|
+
const last = node.path.at(-1);
|
|
436
|
+
if (last != null) {
|
|
437
|
+
node.path[node.path.length - 1] = `-${last}`;
|
|
438
|
+
}
|
|
439
|
+
if (node.path) {
|
|
440
|
+
node.name = node.path.join(".");
|
|
441
|
+
}
|
|
442
|
+
dictionary.allTokens.push(node);
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
var addVirtualPalette = {
|
|
447
|
+
enforce: "post",
|
|
448
|
+
transform(dictionary) {
|
|
449
|
+
const tokens = dictionary.filter({
|
|
450
|
+
extensions: { category: "colors" }
|
|
451
|
+
});
|
|
452
|
+
const keys = /* @__PURE__ */ new Set();
|
|
453
|
+
const palettes = /* @__PURE__ */ new Map();
|
|
454
|
+
tokens.forEach((token) => {
|
|
455
|
+
const palette = token.extensions.palette;
|
|
456
|
+
if (!palette)
|
|
457
|
+
return;
|
|
458
|
+
const list = palettes.get(palette) || [];
|
|
459
|
+
keys.add(token.path.at(-1));
|
|
460
|
+
list.push(token);
|
|
461
|
+
palettes.set(palette, list);
|
|
462
|
+
});
|
|
463
|
+
keys.forEach((key) => {
|
|
464
|
+
const node = new Token({
|
|
465
|
+
name: `colors.palette.${key}`,
|
|
466
|
+
value: `{colors.palette.${key}}`,
|
|
467
|
+
path: ["colors", "palette", key]
|
|
468
|
+
});
|
|
469
|
+
node.setExtensions({
|
|
470
|
+
category: "colors",
|
|
471
|
+
prop: `palette.${key}`,
|
|
472
|
+
isVirtual: true
|
|
473
|
+
});
|
|
474
|
+
dictionary.allTokens.push(node);
|
|
475
|
+
});
|
|
476
|
+
dictionary.transformTokens("pre");
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
var removeEmptyTokens = {
|
|
480
|
+
enforce: "post",
|
|
481
|
+
transform(dictionary) {
|
|
482
|
+
dictionary.allTokens = dictionary.allTokens.filter((token) => token.value !== "");
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
var middlewares = [addNegativeTokens, addVirtualPalette, removeEmptyTokens];
|
|
486
|
+
|
|
487
|
+
// src/transform.ts
|
|
488
|
+
import { cssVar as cssVar2, isString as isString2 } from "@pandacss/shared";
|
|
489
|
+
import { isMatching as isMatching2, P } from "ts-pattern";
|
|
490
|
+
var isCompositeShadow = isMatching2({
|
|
491
|
+
inset: P.optional(P.boolean),
|
|
492
|
+
offsetX: P.number,
|
|
493
|
+
offsetY: P.number,
|
|
494
|
+
blur: P.number,
|
|
495
|
+
spread: P.number,
|
|
496
|
+
color: P.string
|
|
497
|
+
});
|
|
498
|
+
var transformShadow = {
|
|
499
|
+
name: "tokens/shadow",
|
|
500
|
+
match: (token) => token.extensions.category === "shadows",
|
|
501
|
+
transform(token, { prefix }) {
|
|
502
|
+
if (isString2(token.value)) {
|
|
503
|
+
return token.value;
|
|
504
|
+
}
|
|
505
|
+
if (Array.isArray(token.value)) {
|
|
506
|
+
return token.value.map((value) => this.transform({ value }, { prefix })).join(", ");
|
|
507
|
+
}
|
|
508
|
+
if (isCompositeShadow(token.value)) {
|
|
509
|
+
const { offsetX, offsetY, blur, spread, color, inset } = token.value;
|
|
510
|
+
return `${inset ? "inset " : ""}${offsetX}px ${offsetY}px ${blur}px ${spread}px ${color}`;
|
|
511
|
+
}
|
|
512
|
+
return token.value;
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
var isCompositeGradient = isMatching2({
|
|
516
|
+
type: P.string,
|
|
517
|
+
placement: P.string,
|
|
518
|
+
stops: P.array({
|
|
519
|
+
color: P.string,
|
|
520
|
+
position: P.number
|
|
521
|
+
})
|
|
522
|
+
});
|
|
523
|
+
var transformGradient = {
|
|
524
|
+
name: "tokens/gradient",
|
|
525
|
+
match: (token) => token.extensions.category === "gradients",
|
|
526
|
+
transform(token) {
|
|
527
|
+
if (isString2(token.value)) {
|
|
528
|
+
return token.value;
|
|
529
|
+
}
|
|
530
|
+
if (isCompositeGradient(token.value)) {
|
|
531
|
+
const { type, stops, placement } = token.value;
|
|
532
|
+
const rawStops = stops.map((stop) => {
|
|
533
|
+
const { color, position } = stop;
|
|
534
|
+
return `${color} ${position}px`;
|
|
535
|
+
});
|
|
536
|
+
return `${type}-gradient(${placement}, ${rawStops.join(", ")})`;
|
|
537
|
+
}
|
|
538
|
+
return token.value;
|
|
539
|
+
}
|
|
540
|
+
};
|
|
541
|
+
var transformFonts = {
|
|
542
|
+
name: "tokens/fonts",
|
|
543
|
+
match: (token) => token.extensions.category === "fonts",
|
|
544
|
+
transform(token) {
|
|
545
|
+
if (Array.isArray(token.value)) {
|
|
546
|
+
return token.value.join(", ");
|
|
547
|
+
}
|
|
548
|
+
return token.value;
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
var transformEasings = {
|
|
552
|
+
name: "tokens/easings",
|
|
553
|
+
match: (token) => token.extensions.category === "easings",
|
|
554
|
+
transform(token) {
|
|
555
|
+
if (isString2(token.value)) {
|
|
556
|
+
return token.value;
|
|
557
|
+
}
|
|
558
|
+
return `cubic-bezier(${token.value.join(", ")})`;
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
var transformBorders = {
|
|
562
|
+
name: "tokens/borders",
|
|
563
|
+
match: (token) => token.extensions.category === "borders",
|
|
564
|
+
transform(token) {
|
|
565
|
+
if (isString2(token.value)) {
|
|
566
|
+
return token.value;
|
|
567
|
+
}
|
|
568
|
+
const { width, style, color } = token.value;
|
|
569
|
+
return `${width}px ${style} ${color}`;
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
var addCssVariables = {
|
|
573
|
+
type: "extensions",
|
|
574
|
+
name: "tokens/css-var",
|
|
575
|
+
transform(token, { prefix }) {
|
|
576
|
+
const { isNegative, originalPath } = token.extensions;
|
|
577
|
+
const pathValue = isNegative ? originalPath : token.path;
|
|
578
|
+
const variable = cssVar2(pathValue.join("-"), { prefix });
|
|
579
|
+
return {
|
|
580
|
+
var: variable.var,
|
|
581
|
+
varRef: variable.ref
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
};
|
|
585
|
+
var addConditionalCssVariables = {
|
|
586
|
+
enforce: "post",
|
|
587
|
+
name: "tokens/conditionals",
|
|
588
|
+
transform(token, { prefix }) {
|
|
589
|
+
const refs = getReferences(token.value);
|
|
590
|
+
if (!refs.length)
|
|
591
|
+
return token.value;
|
|
592
|
+
refs.forEach((ref) => {
|
|
593
|
+
const variable = cssVar2(ref.split(".").join("-"), { prefix }).ref;
|
|
594
|
+
token.value = token.value.replace(`{${ref}}`, variable);
|
|
595
|
+
});
|
|
596
|
+
return token.value;
|
|
597
|
+
}
|
|
598
|
+
};
|
|
599
|
+
function getPaletteName(path) {
|
|
600
|
+
if (path.includes("colorPalette"))
|
|
601
|
+
return "";
|
|
602
|
+
const clone = [...path];
|
|
603
|
+
clone.pop();
|
|
604
|
+
clone.shift();
|
|
605
|
+
return clone.join(".");
|
|
606
|
+
}
|
|
607
|
+
var addPalette = {
|
|
608
|
+
type: "extensions",
|
|
609
|
+
name: "tokens/colors/palette",
|
|
610
|
+
match(token) {
|
|
611
|
+
return token.extensions.category === "colors";
|
|
612
|
+
},
|
|
613
|
+
transform(token) {
|
|
614
|
+
return { palette: getPaletteName(token.path) };
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
var transforms = [
|
|
618
|
+
transformShadow,
|
|
619
|
+
transformGradient,
|
|
620
|
+
transformFonts,
|
|
621
|
+
transformEasings,
|
|
622
|
+
transformBorders,
|
|
623
|
+
addCssVariables,
|
|
624
|
+
addConditionalCssVariables,
|
|
625
|
+
addPalette
|
|
626
|
+
];
|
|
627
|
+
|
|
628
|
+
// src/create-dictionary.ts
|
|
629
|
+
var TokenDictionary2 = class extends TokenDictionary {
|
|
630
|
+
constructor(options) {
|
|
631
|
+
super(options);
|
|
632
|
+
this.registerTransform(...transforms);
|
|
633
|
+
this.registerMiddleware(...middlewares);
|
|
634
|
+
this.build();
|
|
635
|
+
}
|
|
636
|
+
get get() {
|
|
637
|
+
return formats.createVarGetter(this);
|
|
638
|
+
}
|
|
639
|
+
get conditionMap() {
|
|
640
|
+
return formats.groupByCondition(this);
|
|
641
|
+
}
|
|
642
|
+
get categoryMap() {
|
|
643
|
+
return formats.groupByCategory(this);
|
|
644
|
+
}
|
|
645
|
+
get values() {
|
|
646
|
+
return formats.getFlattenedValues(this);
|
|
647
|
+
}
|
|
648
|
+
get palettes() {
|
|
649
|
+
return mapToJson2(formats.groupByPalette(this));
|
|
650
|
+
}
|
|
651
|
+
get vars() {
|
|
652
|
+
return formats.getVars(this);
|
|
653
|
+
}
|
|
654
|
+
getValue(path) {
|
|
655
|
+
const result = this.values.get(path);
|
|
656
|
+
if (result != null) {
|
|
657
|
+
return Object.fromEntries(result);
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
getTokenVar(path) {
|
|
661
|
+
const json = mapToJson2(this.values);
|
|
662
|
+
return getDotPath2(json, path);
|
|
663
|
+
}
|
|
664
|
+
};
|
|
665
|
+
export {
|
|
666
|
+
TokenDictionary2 as TokenDictionary
|
|
667
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pandacss/token-dictionary",
|
|
3
|
+
"version": "0.0.0-dev-20221121152823",
|
|
4
|
+
"description": "Common error messages for css panda",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"author": "Segun Adebayo <joseshegs@gmail.com>",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"ts-pattern": "4.0.6",
|
|
18
|
+
"@pandacss/shared": "0.0.0-dev-20221121152823"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@pandacss/fixture": "0.0.0-dev-20221121152823"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsup src/index.ts --format=esm,cjs --dts",
|
|
25
|
+
"build-fast": "tsup src/index.ts --format=esm,cjs --no-dts",
|
|
26
|
+
"dev": "pnpm build-fast --watch"
|
|
27
|
+
}
|
|
28
|
+
}
|