@bamboocss/token-dictionary 1.11.1 → 1.11.3
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.cjs +1313 -0
- package/dist/index.d.cts +235 -0
- package/dist/index.d.mts +235 -0
- package/dist/index.mjs +1234 -1277
- package/package.json +11 -11
- package/dist/index.js +0 -1359
package/dist/index.js
DELETED
|
@@ -1,1359 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
TOKEN_CATEGORIES: () => TOKEN_CATEGORIES,
|
|
34
|
-
Token: () => Token,
|
|
35
|
-
TokenDictionary: () => TokenDictionary,
|
|
36
|
-
assertTokenFormat: () => assertTokenFormat,
|
|
37
|
-
expandReferences: () => expandReferences,
|
|
38
|
-
getReferences: () => getReferences,
|
|
39
|
-
hasReference: () => hasReference,
|
|
40
|
-
isToken: () => isToken,
|
|
41
|
-
mapToJson: () => mapToJson
|
|
42
|
-
});
|
|
43
|
-
module.exports = __toCommonJS(index_exports);
|
|
44
|
-
|
|
45
|
-
// src/dictionary.ts
|
|
46
|
-
var import_shared6 = require("@bamboocss/shared");
|
|
47
|
-
var import_ts_pattern3 = require("ts-pattern");
|
|
48
|
-
|
|
49
|
-
// src/is-composite.ts
|
|
50
|
-
var import_ts_pattern = require("ts-pattern");
|
|
51
|
-
var isCompositeShadow = (0, import_ts_pattern.isMatching)({
|
|
52
|
-
inset: import_ts_pattern.P.optional(import_ts_pattern.P.boolean),
|
|
53
|
-
offsetX: import_ts_pattern.P.union(import_ts_pattern.P.number, import_ts_pattern.P.string),
|
|
54
|
-
offsetY: import_ts_pattern.P.union(import_ts_pattern.P.number, import_ts_pattern.P.string),
|
|
55
|
-
blur: import_ts_pattern.P.union(import_ts_pattern.P.number, import_ts_pattern.P.string),
|
|
56
|
-
spread: import_ts_pattern.P.union(import_ts_pattern.P.number, import_ts_pattern.P.string),
|
|
57
|
-
color: import_ts_pattern.P.string
|
|
58
|
-
});
|
|
59
|
-
var isCompositeGradient = (0, import_ts_pattern.isMatching)({
|
|
60
|
-
type: import_ts_pattern.P.string,
|
|
61
|
-
placement: import_ts_pattern.P.string,
|
|
62
|
-
stops: import_ts_pattern.P.union(
|
|
63
|
-
import_ts_pattern.P.array(import_ts_pattern.P.string),
|
|
64
|
-
import_ts_pattern.P.array({
|
|
65
|
-
color: import_ts_pattern.P.string,
|
|
66
|
-
position: import_ts_pattern.P.number
|
|
67
|
-
})
|
|
68
|
-
)
|
|
69
|
-
});
|
|
70
|
-
var isCompositeBorder = (0, import_ts_pattern.isMatching)({
|
|
71
|
-
color: import_ts_pattern.P.string,
|
|
72
|
-
width: import_ts_pattern.P.union(import_ts_pattern.P.string, import_ts_pattern.P.number),
|
|
73
|
-
style: import_ts_pattern.P.string
|
|
74
|
-
});
|
|
75
|
-
var isCompositeAsset = (0, import_ts_pattern.isMatching)({
|
|
76
|
-
type: import_ts_pattern.P.union("url", "svg"),
|
|
77
|
-
value: import_ts_pattern.P.string
|
|
78
|
-
});
|
|
79
|
-
var isCompositeTokenValue = (value) => {
|
|
80
|
-
return isCompositeGradient(value) || isCompositeShadow(value) || isCompositeBorder(value) || isCompositeAsset(value) || Array.isArray(value);
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
// src/middleware.ts
|
|
84
|
-
var import_shared3 = require("@bamboocss/shared");
|
|
85
|
-
|
|
86
|
-
// src/token.ts
|
|
87
|
-
var import_shared2 = require("@bamboocss/shared");
|
|
88
|
-
|
|
89
|
-
// src/utils.ts
|
|
90
|
-
var import_logger = require("@bamboocss/logger");
|
|
91
|
-
var import_shared = require("@bamboocss/shared");
|
|
92
|
-
var REFERENCE_REGEX = /({([^}]*)})/g;
|
|
93
|
-
var curlyBracketRegex = /[{}]/g;
|
|
94
|
-
function getReferences(value) {
|
|
95
|
-
if (typeof value !== "string") return [];
|
|
96
|
-
const matches = value.match(REFERENCE_REGEX);
|
|
97
|
-
if (!matches) return [];
|
|
98
|
-
return matches.map((match3) => match3.replace(curlyBracketRegex, "")).map((value2) => value2.trim());
|
|
99
|
-
}
|
|
100
|
-
var hasReference = (value) => getReferences(value).length > 0;
|
|
101
|
-
var tokenFunctionRegex = /token\(([^)]+)\)/g;
|
|
102
|
-
var closingParenthesisRegex = /\)$/g;
|
|
103
|
-
var hasTokenReference = (str) => str.includes("token(");
|
|
104
|
-
var tokenReplacer = (a, b) => b ? a.endsWith(")") ? a.replace(closingParenthesisRegex, `, ${b})`) : `var(${a}, ${b})` : a;
|
|
105
|
-
var notFoundMessage = (key, value) => `Reference not found: \`${key}\` in "${value}"`;
|
|
106
|
-
var isTokenReference = (v) => hasReference(v) || hasTokenReference(v);
|
|
107
|
-
function expandReferences(value, fn) {
|
|
108
|
-
if (!isTokenReference(value)) return value;
|
|
109
|
-
const references = getReferences(value);
|
|
110
|
-
const expanded = references.reduce((valueStr, key) => {
|
|
111
|
-
const resolved = fn(key);
|
|
112
|
-
if (!resolved) {
|
|
113
|
-
import_logger.logger.warn("token", notFoundMessage(key, value));
|
|
114
|
-
}
|
|
115
|
-
const expandedValue = resolved ?? (0, import_shared.esc)(key);
|
|
116
|
-
return valueStr.replaceAll(`{${key}}`, expandedValue);
|
|
117
|
-
}, value);
|
|
118
|
-
if (!expanded.includes(`token(`)) return expanded;
|
|
119
|
-
return expanded.replace(tokenFunctionRegex, (_, token) => {
|
|
120
|
-
const [tokenValue, tokenFallback] = token.split(",").map((s) => s.trim());
|
|
121
|
-
const result = [tokenValue, tokenFallback].filter(Boolean).map((key) => {
|
|
122
|
-
const resolved = fn(key);
|
|
123
|
-
if (!resolved && isTokenReference(key)) {
|
|
124
|
-
import_logger.logger.warn("token", notFoundMessage(key, value));
|
|
125
|
-
}
|
|
126
|
-
return resolved ?? (0, import_shared.esc)(key);
|
|
127
|
-
});
|
|
128
|
-
if (result.length > 1) {
|
|
129
|
-
const [a, b] = result;
|
|
130
|
-
return tokenReplacer(a, b);
|
|
131
|
-
}
|
|
132
|
-
return tokenReplacer(result[0]);
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
function mapToJson(map) {
|
|
136
|
-
const obj = {};
|
|
137
|
-
map.forEach((value, key) => {
|
|
138
|
-
if (value instanceof Map) {
|
|
139
|
-
obj[key] = Object.fromEntries(value);
|
|
140
|
-
} else {
|
|
141
|
-
obj[key] = value;
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
return obj;
|
|
145
|
-
}
|
|
146
|
-
var isToken = (value) => {
|
|
147
|
-
return (0, import_shared.isObject)(value) && "value" in value;
|
|
148
|
-
};
|
|
149
|
-
function assertTokenFormat(token) {
|
|
150
|
-
if (!isToken(token)) {
|
|
151
|
-
throw new import_shared.BambooError("INVALID_TOKEN", `Invalid token format: ${JSON.stringify(token)}`);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// src/token.ts
|
|
156
|
-
var Token = class _Token {
|
|
157
|
-
name;
|
|
158
|
-
value;
|
|
159
|
-
originalValue;
|
|
160
|
-
path;
|
|
161
|
-
type;
|
|
162
|
-
description;
|
|
163
|
-
deprecated;
|
|
164
|
-
extensions;
|
|
165
|
-
constructor(input) {
|
|
166
|
-
this.name = input.name;
|
|
167
|
-
this.value = input.value;
|
|
168
|
-
this.originalValue = input.value;
|
|
169
|
-
this.path = input.path ?? [];
|
|
170
|
-
if (input.type) {
|
|
171
|
-
this.type = input.type;
|
|
172
|
-
}
|
|
173
|
-
if (input.description) {
|
|
174
|
-
this.description = input.description;
|
|
175
|
-
}
|
|
176
|
-
this.extensions = input.extensions ?? {};
|
|
177
|
-
this.extensions.condition = input.extensions?.condition ?? "base";
|
|
178
|
-
this.deprecated = input.deprecated;
|
|
179
|
-
this.setType();
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* The unique identifier of the token.
|
|
183
|
-
*/
|
|
184
|
-
get id() {
|
|
185
|
-
return (0, import_shared2.toHash)(`${this.name}-${this.extensions.condition}-${this.value}`);
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Whether the token is a conditional token.
|
|
189
|
-
* Conditional tokens are tokens that have multiple values based on a condition.
|
|
190
|
-
*/
|
|
191
|
-
get isConditional() {
|
|
192
|
-
return !!this.extensions?.conditions;
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Whether the token has a reference in its value.
|
|
196
|
-
* e.g. {color.gray.100}
|
|
197
|
-
*/
|
|
198
|
-
get hasReference() {
|
|
199
|
-
return !!this.extensions?.references;
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Whether the token is a complex or composite token.
|
|
203
|
-
*/
|
|
204
|
-
get isComposite() {
|
|
205
|
-
return isCompositeTokenValue(this.originalValue);
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Returns the token value with the references expanded.
|
|
209
|
-
* e.g. {color.gray.100} => var(--colors-gray-100)
|
|
210
|
-
*
|
|
211
|
-
*/
|
|
212
|
-
expandReferences() {
|
|
213
|
-
if (!this.hasReference) return this.extensions.varRef ?? this.value;
|
|
214
|
-
const references = this.extensions.references ?? {};
|
|
215
|
-
this.value = Object.keys(references).reduce((valueStr, key) => {
|
|
216
|
-
const referenceToken = references[key];
|
|
217
|
-
if (referenceToken.isConditional) {
|
|
218
|
-
return valueStr;
|
|
219
|
-
}
|
|
220
|
-
const value = referenceToken.expandReferences();
|
|
221
|
-
return valueStr.replaceAll(`{${key}}`, value);
|
|
222
|
-
}, this.value);
|
|
223
|
-
delete this.extensions.references;
|
|
224
|
-
return this.value;
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Whether this token has a reference to another token
|
|
228
|
-
*/
|
|
229
|
-
get isReference() {
|
|
230
|
-
return hasReference(this.originalValue);
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Returns the list of references in the token value
|
|
234
|
-
*/
|
|
235
|
-
get references() {
|
|
236
|
-
return getReferences(this.originalValue);
|
|
237
|
-
}
|
|
238
|
-
clone() {
|
|
239
|
-
return new _Token({
|
|
240
|
-
name: this.name,
|
|
241
|
-
value: this.value,
|
|
242
|
-
type: this.type,
|
|
243
|
-
path: [...this.path],
|
|
244
|
-
description: this.description,
|
|
245
|
-
extensions: cloneDeep(this.extensions)
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Returns an array of tokens per conditions.
|
|
250
|
-
* It is commonly used in semantic tokens, and can have multiple values based on a condition.
|
|
251
|
-
* e.g. primary: { light: '#000', dark: '#fff' }
|
|
252
|
-
*/
|
|
253
|
-
getConditionTokens() {
|
|
254
|
-
if (!this.isConditional) return;
|
|
255
|
-
const conditions = this.extensions.conditions ?? {};
|
|
256
|
-
const conditionalTokens = [];
|
|
257
|
-
(0, import_shared2.walkObject)(conditions, (value, path) => {
|
|
258
|
-
const newPath = path.filter((v) => !(0, import_shared2.isBaseCondition)(v));
|
|
259
|
-
if (!newPath.length) return;
|
|
260
|
-
const token = this.clone();
|
|
261
|
-
token.value = value;
|
|
262
|
-
token.extensions.condition = newPath.join(":");
|
|
263
|
-
conditionalTokens.push(token);
|
|
264
|
-
});
|
|
265
|
-
return conditionalTokens;
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* Add more extensions to the token
|
|
269
|
-
*/
|
|
270
|
-
setExtensions(extensions) {
|
|
271
|
-
this.extensions = { ...this.extensions, ...extensions };
|
|
272
|
-
this.setType();
|
|
273
|
-
return this;
|
|
274
|
-
}
|
|
275
|
-
setType() {
|
|
276
|
-
if (this.type) return;
|
|
277
|
-
if (this.extensions.category) {
|
|
278
|
-
this.type = TOKEN_TYPES[this.extensions.category];
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
function cloneDeep(value) {
|
|
283
|
-
if (value instanceof Token) {
|
|
284
|
-
return value.clone();
|
|
285
|
-
}
|
|
286
|
-
if (Array.isArray(value)) {
|
|
287
|
-
return value.map((child) => cloneDeep(child));
|
|
288
|
-
}
|
|
289
|
-
if (typeof value === "object" && value !== null) {
|
|
290
|
-
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, cloneDeep(v)]));
|
|
291
|
-
}
|
|
292
|
-
return value;
|
|
293
|
-
}
|
|
294
|
-
var TOKEN_TYPES = {
|
|
295
|
-
colors: "color",
|
|
296
|
-
spacing: "dimension",
|
|
297
|
-
sizes: "dimension",
|
|
298
|
-
shadows: "shadow",
|
|
299
|
-
fonts: "fontFamily",
|
|
300
|
-
fontSizes: "fontSize",
|
|
301
|
-
fontWeights: "fontWeight",
|
|
302
|
-
letterSpacings: "letterSpacing",
|
|
303
|
-
lineHeights: "lineHeight",
|
|
304
|
-
durations: "duration",
|
|
305
|
-
transitions: "transition",
|
|
306
|
-
radii: "borderRadius",
|
|
307
|
-
gradients: "gradient",
|
|
308
|
-
easings: "cubicBezier",
|
|
309
|
-
borders: "border",
|
|
310
|
-
borderWidths: "borderWidth",
|
|
311
|
-
zIndex: "zIndex",
|
|
312
|
-
opacity: "opacity",
|
|
313
|
-
blurs: "blur",
|
|
314
|
-
aspectRatios: "aspectRatio",
|
|
315
|
-
cursor: "cursor",
|
|
316
|
-
assets: "asset"
|
|
317
|
-
};
|
|
318
|
-
var TOKEN_CATEGORIES = Object.keys(TOKEN_TYPES);
|
|
319
|
-
|
|
320
|
-
// src/middleware.ts
|
|
321
|
-
var addNegativeTokens = {
|
|
322
|
-
enforce: "pre",
|
|
323
|
-
transform(dictionary) {
|
|
324
|
-
const { prefix, hash } = dictionary;
|
|
325
|
-
const tokens = dictionary.filter({
|
|
326
|
-
extensions: { category: "spacing" }
|
|
327
|
-
});
|
|
328
|
-
tokens.forEach((token) => {
|
|
329
|
-
const originalPath = [...token.path];
|
|
330
|
-
const originalVar = dictionary.formatCssVar(originalPath, { prefix, hash });
|
|
331
|
-
if (token.value === "0rem") {
|
|
332
|
-
return;
|
|
333
|
-
}
|
|
334
|
-
const node = token.clone();
|
|
335
|
-
node.setExtensions({
|
|
336
|
-
isNegative: true,
|
|
337
|
-
prop: `-${token.extensions.prop}`,
|
|
338
|
-
originalPath
|
|
339
|
-
});
|
|
340
|
-
node.value = import_shared3.calc.negate(originalVar);
|
|
341
|
-
const last = node.path.at(-1);
|
|
342
|
-
if (last != null) {
|
|
343
|
-
node.path[node.path.length - 1] = `-${last}`;
|
|
344
|
-
}
|
|
345
|
-
if (node.path) {
|
|
346
|
-
node.name = dictionary.formatTokenName(node.path);
|
|
347
|
-
}
|
|
348
|
-
dictionary.registerToken(node);
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
};
|
|
352
|
-
var units = /* @__PURE__ */ new Set(["spacing", "sizes", "borderWidths", "fontSizes", "radii"]);
|
|
353
|
-
var addPixelUnit = {
|
|
354
|
-
enforce: "post",
|
|
355
|
-
transform(dictionary) {
|
|
356
|
-
const tokens = dictionary.filter((token) => {
|
|
357
|
-
return units.has(token.extensions.category) && !token.extensions.isNegative;
|
|
358
|
-
});
|
|
359
|
-
tokens.forEach((token) => {
|
|
360
|
-
token.setExtensions({
|
|
361
|
-
pixelValue: (0, import_shared3.toPx)(token.value)
|
|
362
|
-
});
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
};
|
|
366
|
-
var addVirtualPalette = {
|
|
367
|
-
enforce: "post",
|
|
368
|
-
transform(dictionary) {
|
|
369
|
-
const colorPaletteConfig = dictionary.colorPalette;
|
|
370
|
-
const enabled = colorPaletteConfig?.enabled ?? true;
|
|
371
|
-
if (!enabled) return;
|
|
372
|
-
const tokens = dictionary.filter({ extensions: { category: "colors" } });
|
|
373
|
-
const keys = /* @__PURE__ */ new Map();
|
|
374
|
-
const colorPalettes = /* @__PURE__ */ new Map();
|
|
375
|
-
tokens.forEach((token) => {
|
|
376
|
-
const { colorPalette, colorPaletteRoots, colorPaletteTokenKeys } = token.extensions;
|
|
377
|
-
if (!colorPalette) return;
|
|
378
|
-
colorPaletteTokenKeys.forEach((keyPath) => {
|
|
379
|
-
keys.set(dictionary.formatTokenName(keyPath), keyPath);
|
|
380
|
-
});
|
|
381
|
-
colorPaletteRoots.forEach((colorPaletteRoot) => {
|
|
382
|
-
const formated = dictionary.formatTokenName(colorPaletteRoot);
|
|
383
|
-
const colorPaletteList = colorPalettes.get(formated) || [];
|
|
384
|
-
colorPaletteList.push(token);
|
|
385
|
-
colorPalettes.set(formated, colorPaletteList);
|
|
386
|
-
if (token.extensions.isDefault && colorPaletteRoot.length === 1) {
|
|
387
|
-
const keyPath = colorPaletteTokenKeys[0]?.filter(Boolean);
|
|
388
|
-
if (!keyPath.length) return;
|
|
389
|
-
const path = colorPaletteRoot.concat(keyPath);
|
|
390
|
-
keys.set(dictionary.formatTokenName(path), []);
|
|
391
|
-
}
|
|
392
|
-
});
|
|
393
|
-
});
|
|
394
|
-
keys.forEach((segments) => {
|
|
395
|
-
const node = new Token({
|
|
396
|
-
name: dictionary.formatTokenName(["colors", "colorPalette", ...segments].filter(Boolean)),
|
|
397
|
-
value: dictionary.formatTokenName(["colors", "colorPalette", ...segments].filter(Boolean)),
|
|
398
|
-
path: ["colors", "colorPalette", ...segments]
|
|
399
|
-
});
|
|
400
|
-
node.setExtensions({
|
|
401
|
-
category: "colors",
|
|
402
|
-
prop: dictionary.formatTokenName(["colorPalette", ...segments].filter(Boolean)),
|
|
403
|
-
isVirtual: true
|
|
404
|
-
});
|
|
405
|
-
dictionary.registerToken(node, "pre");
|
|
406
|
-
});
|
|
407
|
-
}
|
|
408
|
-
};
|
|
409
|
-
var removeEmptyTokens = {
|
|
410
|
-
enforce: "post",
|
|
411
|
-
transform(dictionary) {
|
|
412
|
-
dictionary.allTokens = dictionary.allTokens.filter((token) => token.value !== "");
|
|
413
|
-
}
|
|
414
|
-
};
|
|
415
|
-
var middlewares = [addNegativeTokens, addVirtualPalette, removeEmptyTokens, addPixelUnit];
|
|
416
|
-
|
|
417
|
-
// src/transform.ts
|
|
418
|
-
var import_shared4 = require("@bamboocss/shared");
|
|
419
|
-
var import_picomatch = __toESM(require("picomatch"));
|
|
420
|
-
var import_ts_pattern2 = require("ts-pattern");
|
|
421
|
-
|
|
422
|
-
// src/mini-svg-uri.ts
|
|
423
|
-
var shorterNames = {
|
|
424
|
-
aqua: /#00ffff(ff)?(?!\w)|#0ff(f)?(?!\w)/gi,
|
|
425
|
-
azure: /#f0ffff(ff)?(?!\w)/gi,
|
|
426
|
-
beige: /#f5f5dc(ff)?(?!\w)/gi,
|
|
427
|
-
bisque: /#ffe4c4(ff)?(?!\w)/gi,
|
|
428
|
-
black: /#000000(ff)?(?!\w)|#000(f)?(?!\w)/gi,
|
|
429
|
-
blue: /#0000ff(ff)?(?!\w)|#00f(f)?(?!\w)/gi,
|
|
430
|
-
brown: /#a52a2a(ff)?(?!\w)/gi,
|
|
431
|
-
coral: /#ff7f50(ff)?(?!\w)/gi,
|
|
432
|
-
cornsilk: /#fff8dc(ff)?(?!\w)/gi,
|
|
433
|
-
crimson: /#dc143c(ff)?(?!\w)/gi,
|
|
434
|
-
cyan: /#00ffff(ff)?(?!\w)|#0ff(f)?(?!\w)/gi,
|
|
435
|
-
darkblue: /#00008b(ff)?(?!\w)/gi,
|
|
436
|
-
darkcyan: /#008b8b(ff)?(?!\w)/gi,
|
|
437
|
-
darkgrey: /#a9a9a9(ff)?(?!\w)/gi,
|
|
438
|
-
darkred: /#8b0000(ff)?(?!\w)/gi,
|
|
439
|
-
deeppink: /#ff1493(ff)?(?!\w)/gi,
|
|
440
|
-
dimgrey: /#696969(ff)?(?!\w)/gi,
|
|
441
|
-
gold: /#ffd700(ff)?(?!\w)/gi,
|
|
442
|
-
green: /#008000(ff)?(?!\w)/gi,
|
|
443
|
-
grey: /#808080(ff)?(?!\w)/gi,
|
|
444
|
-
honeydew: /#f0fff0(ff)?(?!\w)/gi,
|
|
445
|
-
hotpink: /#ff69b4(ff)?(?!\w)/gi,
|
|
446
|
-
indigo: /#4b0082(ff)?(?!\w)/gi,
|
|
447
|
-
ivory: /#fffff0(ff)?(?!\w)/gi,
|
|
448
|
-
khaki: /#f0e68c(ff)?(?!\w)/gi,
|
|
449
|
-
lavender: /#e6e6fa(ff)?(?!\w)/gi,
|
|
450
|
-
lime: /#00ff00(ff)?(?!\w)|#0f0(f)?(?!\w)/gi,
|
|
451
|
-
linen: /#faf0e6(ff)?(?!\w)/gi,
|
|
452
|
-
maroon: /#800000(ff)?(?!\w)/gi,
|
|
453
|
-
moccasin: /#ffe4b5(ff)?(?!\w)/gi,
|
|
454
|
-
navy: /#000080(ff)?(?!\w)/gi,
|
|
455
|
-
oldlace: /#fdf5e6(ff)?(?!\w)/gi,
|
|
456
|
-
olive: /#808000(ff)?(?!\w)/gi,
|
|
457
|
-
orange: /#ffa500(ff)?(?!\w)/gi,
|
|
458
|
-
orchid: /#da70d6(ff)?(?!\w)/gi,
|
|
459
|
-
peru: /#cd853f(ff)?(?!\w)/gi,
|
|
460
|
-
pink: /#ffc0cb(ff)?(?!\w)/gi,
|
|
461
|
-
plum: /#dda0dd(ff)?(?!\w)/gi,
|
|
462
|
-
purple: /#800080(ff)?(?!\w)/gi,
|
|
463
|
-
red: /#ff0000(ff)?(?!\w)|#f00(f)?(?!\w)/gi,
|
|
464
|
-
salmon: /#fa8072(ff)?(?!\w)/gi,
|
|
465
|
-
seagreen: /#2e8b57(ff)?(?!\w)/gi,
|
|
466
|
-
seashell: /#fff5ee(ff)?(?!\w)/gi,
|
|
467
|
-
sienna: /#a0522d(ff)?(?!\w)/gi,
|
|
468
|
-
silver: /#c0c0c0(ff)?(?!\w)/gi,
|
|
469
|
-
skyblue: /#87ceeb(ff)?(?!\w)/gi,
|
|
470
|
-
snow: /#fffafa(ff)?(?!\w)/gi,
|
|
471
|
-
tan: /#d2b48c(ff)?(?!\w)/gi,
|
|
472
|
-
teal: /#008080(ff)?(?!\w)/gi,
|
|
473
|
-
thistle: /#d8bfd8(ff)?(?!\w)/gi,
|
|
474
|
-
tomato: /#ff6347(ff)?(?!\w)/gi,
|
|
475
|
-
violet: /#ee82ee(ff)?(?!\w)/gi,
|
|
476
|
-
wheat: /#f5deb3(ff)?(?!\w)/gi,
|
|
477
|
-
white: /#ffffff(ff)?(?!\w)|#fff(f)?(?!\w)/gi
|
|
478
|
-
};
|
|
479
|
-
var REGEX = {
|
|
480
|
-
whitespace: /\s+/g,
|
|
481
|
-
urlHexPairs: /%[\dA-F]{2}/g,
|
|
482
|
-
quotes: /"/g
|
|
483
|
-
};
|
|
484
|
-
function collapseWhitespace(str) {
|
|
485
|
-
return str.trim().replace(REGEX.whitespace, " ");
|
|
486
|
-
}
|
|
487
|
-
function dataURIPayload(string) {
|
|
488
|
-
return encodeURIComponent(string).replace(REGEX.urlHexPairs, specialHexEncode);
|
|
489
|
-
}
|
|
490
|
-
function colorCodeToShorterNames(string) {
|
|
491
|
-
objectKeys(shorterNames).forEach((key) => {
|
|
492
|
-
if (shorterNames[key].test(string)) {
|
|
493
|
-
string = string.replace(shorterNames[key], key);
|
|
494
|
-
}
|
|
495
|
-
});
|
|
496
|
-
return string;
|
|
497
|
-
}
|
|
498
|
-
function specialHexEncode(match3) {
|
|
499
|
-
switch (match3) {
|
|
500
|
-
case "%20":
|
|
501
|
-
return " ";
|
|
502
|
-
case "%3D":
|
|
503
|
-
return "=";
|
|
504
|
-
case "%3A":
|
|
505
|
-
return ":";
|
|
506
|
-
case "%2F":
|
|
507
|
-
return "/";
|
|
508
|
-
default:
|
|
509
|
-
return match3.toLowerCase();
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
function svgToDataUri(svgString) {
|
|
513
|
-
if (typeof svgString !== "string") {
|
|
514
|
-
throw new TypeError("Expected a string, but received " + typeof svgString);
|
|
515
|
-
}
|
|
516
|
-
if (svgString.charCodeAt(0) === 65279) {
|
|
517
|
-
svgString = svgString.slice(1);
|
|
518
|
-
}
|
|
519
|
-
const body = colorCodeToShorterNames(collapseWhitespace(svgString)).replace(REGEX.quotes, "'");
|
|
520
|
-
return "data:image/svg+xml," + dataURIPayload(body);
|
|
521
|
-
}
|
|
522
|
-
var objectKeys = (obj) => Object.keys(obj);
|
|
523
|
-
|
|
524
|
-
// src/transform.ts
|
|
525
|
-
function toUnit(v) {
|
|
526
|
-
return (0, import_shared4.isCssUnit)(v) || hasReference(v.toString()) ? v : `${v}px`;
|
|
527
|
-
}
|
|
528
|
-
function px(v) {
|
|
529
|
-
return (0, import_shared4.isString)(v) ? v : `${v}px`;
|
|
530
|
-
}
|
|
531
|
-
var transformShadow = {
|
|
532
|
-
name: "tokens/shadow",
|
|
533
|
-
match: (token) => token.extensions.category === "shadows",
|
|
534
|
-
transform(token, dict) {
|
|
535
|
-
if ((0, import_shared4.isString)(token.value)) {
|
|
536
|
-
return token.value;
|
|
537
|
-
}
|
|
538
|
-
if (Array.isArray(token.value)) {
|
|
539
|
-
return token.value.map((value) => this.transform({ value }, dict)).join(", ");
|
|
540
|
-
}
|
|
541
|
-
if (isCompositeShadow(token.value)) {
|
|
542
|
-
const { offsetX, offsetY, blur, spread, color, inset } = token.value;
|
|
543
|
-
return [inset ? "inset " : "", px(offsetX), px(offsetY), px(blur), px(spread), color].filter(Boolean).join(" ");
|
|
544
|
-
}
|
|
545
|
-
return token.value;
|
|
546
|
-
}
|
|
547
|
-
};
|
|
548
|
-
var transformGradient = {
|
|
549
|
-
name: "tokens/gradient",
|
|
550
|
-
match: (token) => token.extensions.category === "gradients",
|
|
551
|
-
transform(token) {
|
|
552
|
-
if ((0, import_shared4.isString)(token.value)) {
|
|
553
|
-
return token.value;
|
|
554
|
-
}
|
|
555
|
-
if (isCompositeGradient(token.value)) {
|
|
556
|
-
const { type, stops, placement } = token.value;
|
|
557
|
-
const rawStops = stops.map((stop) => {
|
|
558
|
-
if ((0, import_shared4.isString)(stop)) return stop;
|
|
559
|
-
const { color, position } = stop;
|
|
560
|
-
return `${color} ${position}px`;
|
|
561
|
-
});
|
|
562
|
-
return `${type}-gradient(${placement}, ${rawStops.join(", ")})`;
|
|
563
|
-
}
|
|
564
|
-
return token.value;
|
|
565
|
-
}
|
|
566
|
-
};
|
|
567
|
-
var transformFonts = {
|
|
568
|
-
name: "tokens/fonts",
|
|
569
|
-
match: (token) => token.extensions.category === "fonts",
|
|
570
|
-
transform(token) {
|
|
571
|
-
if (Array.isArray(token.value)) {
|
|
572
|
-
return token.value.join(", ");
|
|
573
|
-
}
|
|
574
|
-
return token.value;
|
|
575
|
-
}
|
|
576
|
-
};
|
|
577
|
-
var transformEasings = {
|
|
578
|
-
name: "tokens/easings",
|
|
579
|
-
match: (token) => token.extensions.category === "easings",
|
|
580
|
-
transform(token) {
|
|
581
|
-
if ((0, import_shared4.isString)(token.value)) {
|
|
582
|
-
return token.value;
|
|
583
|
-
}
|
|
584
|
-
if (Array.isArray(token.value)) {
|
|
585
|
-
return `cubic-bezier(${token.value.join(", ")})`;
|
|
586
|
-
}
|
|
587
|
-
return token.value;
|
|
588
|
-
}
|
|
589
|
-
};
|
|
590
|
-
var transformBorders = {
|
|
591
|
-
name: "tokens/borders",
|
|
592
|
-
match: (token) => token.extensions.category === "borders",
|
|
593
|
-
transform(token) {
|
|
594
|
-
if ((0, import_shared4.isString)(token.value)) {
|
|
595
|
-
return token.value;
|
|
596
|
-
}
|
|
597
|
-
if (isCompositeBorder(token.value)) {
|
|
598
|
-
const { width, style, color } = token.value;
|
|
599
|
-
return `${toUnit(width)} ${style} ${color}`;
|
|
600
|
-
}
|
|
601
|
-
return token.value;
|
|
602
|
-
}
|
|
603
|
-
};
|
|
604
|
-
var transformAssets = {
|
|
605
|
-
name: "tokens/assets",
|
|
606
|
-
match: (token) => token.extensions.category === "assets",
|
|
607
|
-
transform(token) {
|
|
608
|
-
const raw = token.value;
|
|
609
|
-
return (0, import_ts_pattern2.match)(raw).with(import_ts_pattern2.P.string, (value) => value).with({ type: "url" }, ({ value }) => `url("${value}")`).with({ type: "svg" }, ({ value }) => `url("${svgToDataUri(value)}")`).exhaustive();
|
|
610
|
-
}
|
|
611
|
-
};
|
|
612
|
-
var transformColorMix = {
|
|
613
|
-
name: "tokens/color-mix",
|
|
614
|
-
match: (token) => {
|
|
615
|
-
return token.extensions.category === "colors" && token.value.includes("/");
|
|
616
|
-
},
|
|
617
|
-
transform(token, dict) {
|
|
618
|
-
if (!token.value.includes("/")) return token;
|
|
619
|
-
return expandReferences(token.value, (path) => {
|
|
620
|
-
const tokenFn = (tokenPath) => {
|
|
621
|
-
const token2 = dict.getByName(tokenPath);
|
|
622
|
-
return token2?.extensions.varRef;
|
|
623
|
-
};
|
|
624
|
-
const mix = dict.colorMix(path, tokenFn);
|
|
625
|
-
if (mix.invalid) {
|
|
626
|
-
throw new import_shared4.BambooError("INVALID_TOKEN", "Invalid color mix at " + path + ": " + mix.value);
|
|
627
|
-
}
|
|
628
|
-
return mix.value;
|
|
629
|
-
});
|
|
630
|
-
}
|
|
631
|
-
};
|
|
632
|
-
var addCssVariables = {
|
|
633
|
-
type: "extensions",
|
|
634
|
-
name: "tokens/css-var",
|
|
635
|
-
transform(token, dictionary) {
|
|
636
|
-
const { prefix, hash } = dictionary;
|
|
637
|
-
const { isNegative, originalPath } = token.extensions;
|
|
638
|
-
const pathValue = isNegative ? originalPath : token.path;
|
|
639
|
-
const variable = dictionary.formatCssVar(pathValue.filter(Boolean), { prefix, hash });
|
|
640
|
-
return {
|
|
641
|
-
var: variable.var,
|
|
642
|
-
varRef: variable.ref
|
|
643
|
-
};
|
|
644
|
-
}
|
|
645
|
-
};
|
|
646
|
-
var addConditionalCssVariables = {
|
|
647
|
-
enforce: "post",
|
|
648
|
-
name: "tokens/conditionals",
|
|
649
|
-
transform(token, dictionary) {
|
|
650
|
-
const { prefix, hash } = dictionary;
|
|
651
|
-
const refs = getReferences(token.value);
|
|
652
|
-
if (!refs.length) return token.value;
|
|
653
|
-
const modifier = refs.some((ref) => ref.includes("/"));
|
|
654
|
-
if (!modifier) {
|
|
655
|
-
refs.forEach((ref) => {
|
|
656
|
-
const variable = dictionary.formatCssVar(ref.split("."), { prefix, hash }).ref;
|
|
657
|
-
token.value = token.value.replaceAll(`{${ref}}`, variable);
|
|
658
|
-
});
|
|
659
|
-
} else {
|
|
660
|
-
const tokenFn = (name) => {
|
|
661
|
-
const token2 = dictionary.getByName(name);
|
|
662
|
-
return token2?.extensions.varRef;
|
|
663
|
-
};
|
|
664
|
-
token.value = expandReferences(token.value, (path) => {
|
|
665
|
-
const mix = dictionary.colorMix(path, tokenFn);
|
|
666
|
-
if (mix.invalid) {
|
|
667
|
-
throw new import_shared4.BambooError("INVALID_TOKEN", "Invalid color mix at " + path + ": " + mix.value);
|
|
668
|
-
}
|
|
669
|
-
return mix.value;
|
|
670
|
-
});
|
|
671
|
-
}
|
|
672
|
-
return token.value;
|
|
673
|
-
}
|
|
674
|
-
};
|
|
675
|
-
var addColorPalette = {
|
|
676
|
-
type: "extensions",
|
|
677
|
-
name: "tokens/colors/colorPalette",
|
|
678
|
-
match(token) {
|
|
679
|
-
return token.extensions.category === "colors" && !token.extensions.isVirtual;
|
|
680
|
-
},
|
|
681
|
-
transform(token, dict) {
|
|
682
|
-
const colorPaletteConfig = dict.colorPalette;
|
|
683
|
-
const enabled = colorPaletteConfig?.enabled ?? true;
|
|
684
|
-
const include = colorPaletteConfig?.include;
|
|
685
|
-
const exclude = colorPaletteConfig?.exclude;
|
|
686
|
-
if (!enabled) return {};
|
|
687
|
-
let colorPath = token.path.slice(1, -1);
|
|
688
|
-
if (colorPath.length === 0) {
|
|
689
|
-
colorPath = token.path.slice(1);
|
|
690
|
-
if (colorPath.length === 0) {
|
|
691
|
-
return {};
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
const colorPathString = colorPath.join(".");
|
|
695
|
-
if (exclude?.length) {
|
|
696
|
-
const excludeMatchers = exclude.map((pattern) => (0, import_picomatch.default)(pattern));
|
|
697
|
-
if (excludeMatchers.some((matcher) => matcher(colorPathString))) {
|
|
698
|
-
return {};
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
if (include?.length) {
|
|
702
|
-
const includeMatchers = include.map((pattern) => (0, import_picomatch.default)(pattern));
|
|
703
|
-
if (!includeMatchers.some((matcher) => matcher(colorPathString))) {
|
|
704
|
-
return {};
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
const colorPaletteRoots = [];
|
|
708
|
-
for (let i = 0; i < colorPath.length; i++) {
|
|
709
|
-
colorPaletteRoots.push(colorPath.slice(0, i + 1));
|
|
710
|
-
}
|
|
711
|
-
const colorPaletteRoot = colorPath[0];
|
|
712
|
-
const colorPalette = dict.formatTokenName(colorPath);
|
|
713
|
-
const startIndex = token.path.indexOf(colorPaletteRoot) + 1;
|
|
714
|
-
const remainingPath = token.path.slice(startIndex);
|
|
715
|
-
const colorPaletteTokenKeys = [];
|
|
716
|
-
for (let i = 0; i < remainingPath.length; i++) {
|
|
717
|
-
colorPaletteTokenKeys.push(remainingPath.slice(i));
|
|
718
|
-
}
|
|
719
|
-
if (colorPaletteTokenKeys.length === 0) {
|
|
720
|
-
colorPaletteTokenKeys.push([""]);
|
|
721
|
-
}
|
|
722
|
-
return {
|
|
723
|
-
colorPalette,
|
|
724
|
-
colorPaletteRoots,
|
|
725
|
-
colorPaletteTokenKeys
|
|
726
|
-
};
|
|
727
|
-
}
|
|
728
|
-
};
|
|
729
|
-
var transforms = [
|
|
730
|
-
transformShadow,
|
|
731
|
-
transformGradient,
|
|
732
|
-
transformFonts,
|
|
733
|
-
transformEasings,
|
|
734
|
-
transformBorders,
|
|
735
|
-
transformAssets,
|
|
736
|
-
addCssVariables,
|
|
737
|
-
transformColorMix,
|
|
738
|
-
// depends on `addCssVariables`
|
|
739
|
-
addConditionalCssVariables,
|
|
740
|
-
addColorPalette
|
|
741
|
-
];
|
|
742
|
-
|
|
743
|
-
// src/expand-token-references.ts
|
|
744
|
-
var import_shared5 = require("@bamboocss/shared");
|
|
745
|
-
var expandTokenReferences = (str, resolve) => {
|
|
746
|
-
let expanded = "";
|
|
747
|
-
let index = 0;
|
|
748
|
-
let state = "char";
|
|
749
|
-
let tokenPath = "";
|
|
750
|
-
let fallback = "";
|
|
751
|
-
const currentStates = [];
|
|
752
|
-
while (index < str.length) {
|
|
753
|
-
const char = str[index];
|
|
754
|
-
if (char === "{") {
|
|
755
|
-
const endIndex = str.indexOf("}", index);
|
|
756
|
-
if (endIndex === -1) {
|
|
757
|
-
break;
|
|
758
|
-
}
|
|
759
|
-
const path = str.slice(index + 1, endIndex);
|
|
760
|
-
const resolved = resolve(path);
|
|
761
|
-
expanded += resolved ?? path;
|
|
762
|
-
index = endIndex + 1;
|
|
763
|
-
continue;
|
|
764
|
-
}
|
|
765
|
-
if (state === "token") {
|
|
766
|
-
if (char === ",") {
|
|
767
|
-
if (str[index] === "") {
|
|
768
|
-
index++;
|
|
769
|
-
}
|
|
770
|
-
state = "fallback";
|
|
771
|
-
currentStates.push(state);
|
|
772
|
-
const resolved = resolve(tokenPath);
|
|
773
|
-
if (resolved?.endsWith(")")) {
|
|
774
|
-
expanded += resolved.slice(0, -1);
|
|
775
|
-
}
|
|
776
|
-
tokenPath = "";
|
|
777
|
-
fallback = "";
|
|
778
|
-
continue;
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
if (state === "fallback") {
|
|
782
|
-
const nextFallback = fallback + char;
|
|
783
|
-
if (nextFallback === ", var(") {
|
|
784
|
-
const innerEndIndex = cssVarParser(str.slice(index + 1));
|
|
785
|
-
const endIndex = innerEndIndex + index + 1;
|
|
786
|
-
const cssVar2 = str.slice(index + 1, endIndex);
|
|
787
|
-
if (endIndex === -1) {
|
|
788
|
-
break;
|
|
789
|
-
}
|
|
790
|
-
expanded += ", var(" + cssVar2 + ")";
|
|
791
|
-
index = endIndex + 1;
|
|
792
|
-
state = currentStates.pop() ?? state;
|
|
793
|
-
fallback = "";
|
|
794
|
-
continue;
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
if (state === "token" || state === "fallback") {
|
|
798
|
-
index++;
|
|
799
|
-
if (char === ")") {
|
|
800
|
-
state = currentStates.pop() ?? state ?? "char";
|
|
801
|
-
fallback += char;
|
|
802
|
-
const resolved = tokenPath ? resolve(tokenPath) ?? (0, import_shared5.esc)(tokenPath) : tokenPath;
|
|
803
|
-
if (fallback) {
|
|
804
|
-
fallback = fallback.slice(1).trim();
|
|
805
|
-
if (!fallback.startsWith("token(") && fallback.endsWith(")")) {
|
|
806
|
-
fallback = fallback.slice(0, -1);
|
|
807
|
-
}
|
|
808
|
-
if (fallback.includes("token(")) {
|
|
809
|
-
const parsed = expandTokenReferences(fallback, resolve);
|
|
810
|
-
if (parsed) {
|
|
811
|
-
fallback = parsed.slice(0, -1);
|
|
812
|
-
}
|
|
813
|
-
} else if (fallback) {
|
|
814
|
-
const resolvedFallback = resolve(fallback);
|
|
815
|
-
if (resolvedFallback) {
|
|
816
|
-
fallback = resolvedFallback;
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
const lastChar = expanded.at(-1);
|
|
821
|
-
if (fallback) {
|
|
822
|
-
if (lastChar?.trim()) {
|
|
823
|
-
expanded += resolved.slice(0, -1) + (", " + fallback + ")");
|
|
824
|
-
} else {
|
|
825
|
-
expanded += fallback;
|
|
826
|
-
}
|
|
827
|
-
} else {
|
|
828
|
-
expanded += resolved || ")";
|
|
829
|
-
}
|
|
830
|
-
tokenPath = "";
|
|
831
|
-
fallback = "";
|
|
832
|
-
state = "char";
|
|
833
|
-
continue;
|
|
834
|
-
}
|
|
835
|
-
if (state === "token") {
|
|
836
|
-
tokenPath += char;
|
|
837
|
-
}
|
|
838
|
-
if (state === "fallback") {
|
|
839
|
-
fallback += char;
|
|
840
|
-
}
|
|
841
|
-
continue;
|
|
842
|
-
}
|
|
843
|
-
const tokenIndex = str.indexOf("token(", index);
|
|
844
|
-
if (tokenIndex !== -1) {
|
|
845
|
-
const innerTokenIndex = tokenIndex + "token(".length;
|
|
846
|
-
expanded += str.slice(index, tokenIndex);
|
|
847
|
-
index = innerTokenIndex;
|
|
848
|
-
state = "token";
|
|
849
|
-
currentStates.push(state);
|
|
850
|
-
continue;
|
|
851
|
-
}
|
|
852
|
-
expanded += char;
|
|
853
|
-
index++;
|
|
854
|
-
}
|
|
855
|
-
return expanded;
|
|
856
|
-
};
|
|
857
|
-
var cssVarParser = (str) => {
|
|
858
|
-
let index = 0;
|
|
859
|
-
const openedParenthesises = ["("];
|
|
860
|
-
while (index < str.length) {
|
|
861
|
-
const char = str[index];
|
|
862
|
-
if (char === "(") {
|
|
863
|
-
openedParenthesises.push(char);
|
|
864
|
-
} else if (char === ")") {
|
|
865
|
-
openedParenthesises.pop();
|
|
866
|
-
if (openedParenthesises.length === 0) {
|
|
867
|
-
return index;
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
index++;
|
|
871
|
-
}
|
|
872
|
-
return index;
|
|
873
|
-
};
|
|
874
|
-
|
|
875
|
-
// src/dictionary.ts
|
|
876
|
-
function expandBreakpoints(breakpoints) {
|
|
877
|
-
if (!breakpoints) return { breakpoints: {}, sizes: {} };
|
|
878
|
-
return {
|
|
879
|
-
breakpoints: (0, import_shared6.mapObject)(breakpoints, (value) => ({ value })),
|
|
880
|
-
sizes: Object.fromEntries(Object.entries(breakpoints).map(([key, value]) => [`breakpoint-${key}`, { value }]))
|
|
881
|
-
};
|
|
882
|
-
}
|
|
883
|
-
function filterDefault(path) {
|
|
884
|
-
if (path[0] === "DEFAULT") return path;
|
|
885
|
-
return path.filter((item) => item !== "DEFAULT");
|
|
886
|
-
}
|
|
887
|
-
var TokenDictionary = class {
|
|
888
|
-
constructor(options) {
|
|
889
|
-
this.options = options;
|
|
890
|
-
}
|
|
891
|
-
allTokens = [];
|
|
892
|
-
byName = /* @__PURE__ */ new Map();
|
|
893
|
-
deprecated = /* @__PURE__ */ new Set();
|
|
894
|
-
init() {
|
|
895
|
-
this.registerTokens();
|
|
896
|
-
this.registerTransform(...transforms);
|
|
897
|
-
this.registerMiddleware(...middlewares);
|
|
898
|
-
this.build();
|
|
899
|
-
return this;
|
|
900
|
-
}
|
|
901
|
-
get prefix() {
|
|
902
|
-
return this.options.prefix;
|
|
903
|
-
}
|
|
904
|
-
get hash() {
|
|
905
|
-
return this.options.hash;
|
|
906
|
-
}
|
|
907
|
-
get colorPalette() {
|
|
908
|
-
return this.options.colorPalette;
|
|
909
|
-
}
|
|
910
|
-
getByName = (path) => {
|
|
911
|
-
return this.byName.get(path);
|
|
912
|
-
};
|
|
913
|
-
formatTokenName = (path) => path.join(".");
|
|
914
|
-
formatCssVar = (path, options) => (0, import_shared6.cssVar)(path.join("-"), options);
|
|
915
|
-
registerTokens() {
|
|
916
|
-
const { tokens = {}, semanticTokens = {}, breakpoints, themes = {} } = this.options;
|
|
917
|
-
const breakpointTokens = expandBreakpoints(breakpoints);
|
|
918
|
-
const computedTokens = (0, import_shared6.compact)({
|
|
919
|
-
...tokens,
|
|
920
|
-
breakpoints: breakpointTokens.breakpoints,
|
|
921
|
-
sizes: {
|
|
922
|
-
...tokens.sizes,
|
|
923
|
-
...breakpointTokens.sizes
|
|
924
|
-
}
|
|
925
|
-
});
|
|
926
|
-
const processToken = (token, path) => {
|
|
927
|
-
const isDefault = path.includes("DEFAULT");
|
|
928
|
-
path = filterDefault(path);
|
|
929
|
-
assertTokenFormat(token);
|
|
930
|
-
const category = path[0];
|
|
931
|
-
const name = this.formatTokenName(path);
|
|
932
|
-
const node = new Token({ ...token, name, path });
|
|
933
|
-
node.setExtensions({
|
|
934
|
-
category,
|
|
935
|
-
prop: this.formatTokenName(path.slice(1))
|
|
936
|
-
});
|
|
937
|
-
if (isDefault) {
|
|
938
|
-
node.setExtensions({ isDefault });
|
|
939
|
-
}
|
|
940
|
-
return node;
|
|
941
|
-
};
|
|
942
|
-
const processSemantic = (token, path) => {
|
|
943
|
-
const isDefault = path.includes("DEFAULT");
|
|
944
|
-
path = filterDefault(path);
|
|
945
|
-
assertTokenFormat(token);
|
|
946
|
-
const category = path[0];
|
|
947
|
-
const name = this.formatTokenName(path);
|
|
948
|
-
const normalizedToken = (0, import_shared6.isString)(token.value) || isCompositeTokenValue(token.value) ? { value: { base: token.value } } : token;
|
|
949
|
-
const { value, ...restData } = normalizedToken;
|
|
950
|
-
const node = new Token({
|
|
951
|
-
...restData,
|
|
952
|
-
name,
|
|
953
|
-
value: value.base || "",
|
|
954
|
-
path
|
|
955
|
-
});
|
|
956
|
-
node.setExtensions({
|
|
957
|
-
category,
|
|
958
|
-
conditions: value,
|
|
959
|
-
rawValue: value,
|
|
960
|
-
prop: this.formatTokenName(path.slice(1))
|
|
961
|
-
});
|
|
962
|
-
if (isDefault) {
|
|
963
|
-
node.setExtensions({ isDefault });
|
|
964
|
-
}
|
|
965
|
-
return node;
|
|
966
|
-
};
|
|
967
|
-
(0, import_shared6.walkObject)(
|
|
968
|
-
computedTokens,
|
|
969
|
-
(token, path) => {
|
|
970
|
-
const node = processToken(token, path);
|
|
971
|
-
this.registerToken(node);
|
|
972
|
-
},
|
|
973
|
-
{ stop: isToken }
|
|
974
|
-
);
|
|
975
|
-
(0, import_shared6.walkObject)(
|
|
976
|
-
semanticTokens,
|
|
977
|
-
(token, path) => {
|
|
978
|
-
const node = processSemantic(token, path);
|
|
979
|
-
this.registerToken(node);
|
|
980
|
-
},
|
|
981
|
-
{ stop: isToken }
|
|
982
|
-
);
|
|
983
|
-
Object.entries(themes).forEach(([theme, themeVariant]) => {
|
|
984
|
-
const condName = "_theme" + (0, import_shared6.capitalize)(theme);
|
|
985
|
-
(0, import_shared6.walkObject)(
|
|
986
|
-
themeVariant.tokens ?? {},
|
|
987
|
-
(token, path) => {
|
|
988
|
-
const themeToken = { value: { [condName]: token.value } };
|
|
989
|
-
const node = processSemantic(themeToken, path);
|
|
990
|
-
node.setExtensions({ theme, isVirtual: true });
|
|
991
|
-
this.registerToken(node);
|
|
992
|
-
},
|
|
993
|
-
{ stop: isToken }
|
|
994
|
-
);
|
|
995
|
-
(0, import_shared6.walkObject)(
|
|
996
|
-
themeVariant.semanticTokens ?? {},
|
|
997
|
-
(token, path) => {
|
|
998
|
-
const themeToken = { value: { [condName]: token.value } };
|
|
999
|
-
const node = processSemantic(themeToken, path);
|
|
1000
|
-
node.setExtensions({ theme, isSemantic: true, isVirtual: true });
|
|
1001
|
-
this.registerToken(node);
|
|
1002
|
-
},
|
|
1003
|
-
{ stop: isToken }
|
|
1004
|
-
);
|
|
1005
|
-
});
|
|
1006
|
-
return this;
|
|
1007
|
-
}
|
|
1008
|
-
registerToken = (token, transformPhase) => {
|
|
1009
|
-
this.allTokens.push(token);
|
|
1010
|
-
this.byName.set(token.name, token);
|
|
1011
|
-
if (token.deprecated) {
|
|
1012
|
-
this.deprecated.add(token.name);
|
|
1013
|
-
}
|
|
1014
|
-
if (transformPhase) {
|
|
1015
|
-
this.transforms.forEach((transform) => {
|
|
1016
|
-
if (transform.enforce === transformPhase) {
|
|
1017
|
-
this.execTransformOnToken(transform, token);
|
|
1018
|
-
}
|
|
1019
|
-
});
|
|
1020
|
-
}
|
|
1021
|
-
};
|
|
1022
|
-
transforms = /* @__PURE__ */ new Map();
|
|
1023
|
-
registerTransform(...transforms2) {
|
|
1024
|
-
transforms2.forEach((transform) => {
|
|
1025
|
-
transform.type ||= "value";
|
|
1026
|
-
transform.enforce ||= "pre";
|
|
1027
|
-
this.transforms.set(transform.name, transform);
|
|
1028
|
-
});
|
|
1029
|
-
return this;
|
|
1030
|
-
}
|
|
1031
|
-
execTransform(name) {
|
|
1032
|
-
const transform = this.transforms.get(name);
|
|
1033
|
-
if (!transform) return;
|
|
1034
|
-
this.allTokens.forEach((token) => {
|
|
1035
|
-
this.execTransformOnToken(transform, token);
|
|
1036
|
-
});
|
|
1037
|
-
}
|
|
1038
|
-
execTransformOnToken(transform, token) {
|
|
1039
|
-
if (token.extensions.hasReference) return;
|
|
1040
|
-
if (typeof transform.match === "function" && !transform.match(token)) return;
|
|
1041
|
-
const exec = (v) => transform.transform(v, this);
|
|
1042
|
-
const transformed = exec(token);
|
|
1043
|
-
(0, import_ts_pattern3.match)(transform).with({ type: "extensions" }, () => {
|
|
1044
|
-
token.setExtensions(transformed);
|
|
1045
|
-
}).with({ type: "value" }, () => {
|
|
1046
|
-
token.value = transformed;
|
|
1047
|
-
if (token.isComposite) {
|
|
1048
|
-
token.originalValue = transformed;
|
|
1049
|
-
}
|
|
1050
|
-
if (token.extensions.conditions) {
|
|
1051
|
-
const conditions = token.extensions.conditions;
|
|
1052
|
-
const transformedConditions = (0, import_shared6.walkObject)(conditions, (value) => exec({ value }), {
|
|
1053
|
-
stop: isCompositeTokenValue
|
|
1054
|
-
});
|
|
1055
|
-
token.setExtensions({
|
|
1056
|
-
conditions: transformedConditions
|
|
1057
|
-
});
|
|
1058
|
-
}
|
|
1059
|
-
}).otherwise(() => {
|
|
1060
|
-
token[transform.type] = transformed;
|
|
1061
|
-
});
|
|
1062
|
-
}
|
|
1063
|
-
transformTokens(enforce) {
|
|
1064
|
-
this.transforms.forEach((transform) => {
|
|
1065
|
-
if (transform.enforce === enforce) {
|
|
1066
|
-
this.execTransform(transform.name);
|
|
1067
|
-
}
|
|
1068
|
-
});
|
|
1069
|
-
return this;
|
|
1070
|
-
}
|
|
1071
|
-
middlewares = [];
|
|
1072
|
-
registerMiddleware(...middlewares2) {
|
|
1073
|
-
for (const middleware of middlewares2) {
|
|
1074
|
-
middleware.enforce ||= "pre";
|
|
1075
|
-
this.middlewares.push(middleware);
|
|
1076
|
-
}
|
|
1077
|
-
return this;
|
|
1078
|
-
}
|
|
1079
|
-
applyMiddlewares(enforce) {
|
|
1080
|
-
this.middlewares.forEach((middleware) => {
|
|
1081
|
-
if (middleware.enforce === enforce) {
|
|
1082
|
-
middleware.transform(this);
|
|
1083
|
-
}
|
|
1084
|
-
});
|
|
1085
|
-
}
|
|
1086
|
-
getReferences(value) {
|
|
1087
|
-
const refs = getReferences(value);
|
|
1088
|
-
return refs.map((ref) => this.getByName(ref)).filter(Boolean);
|
|
1089
|
-
}
|
|
1090
|
-
usesReference(value) {
|
|
1091
|
-
if (!(0, import_shared6.isString)(value)) return false;
|
|
1092
|
-
return this.getReferences(value).length > 0;
|
|
1093
|
-
}
|
|
1094
|
-
addReferences() {
|
|
1095
|
-
this.allTokens.forEach((token) => {
|
|
1096
|
-
if (!this.usesReference(token.value)) return;
|
|
1097
|
-
const references = this.getReferences(token.value);
|
|
1098
|
-
token.setExtensions({
|
|
1099
|
-
references: references.reduce(
|
|
1100
|
-
(object, reference) => {
|
|
1101
|
-
object[reference.name] = reference;
|
|
1102
|
-
return object;
|
|
1103
|
-
},
|
|
1104
|
-
{}
|
|
1105
|
-
)
|
|
1106
|
-
});
|
|
1107
|
-
});
|
|
1108
|
-
return this;
|
|
1109
|
-
}
|
|
1110
|
-
filter(pattern) {
|
|
1111
|
-
const predicate = typeof pattern === "function" ? pattern : (0, import_ts_pattern3.isMatching)(pattern);
|
|
1112
|
-
return this.allTokens.filter(predicate);
|
|
1113
|
-
}
|
|
1114
|
-
addConditionalTokens() {
|
|
1115
|
-
this.allTokens.forEach((token) => {
|
|
1116
|
-
const conditionalTokens = token.getConditionTokens();
|
|
1117
|
-
if (conditionalTokens && conditionalTokens.length > 0) {
|
|
1118
|
-
conditionalTokens.forEach((token2) => {
|
|
1119
|
-
this.registerToken(token2);
|
|
1120
|
-
});
|
|
1121
|
-
}
|
|
1122
|
-
});
|
|
1123
|
-
return this;
|
|
1124
|
-
}
|
|
1125
|
-
expandTokenReferences() {
|
|
1126
|
-
this.allTokens.forEach((token) => {
|
|
1127
|
-
token.expandReferences();
|
|
1128
|
-
});
|
|
1129
|
-
return this;
|
|
1130
|
-
}
|
|
1131
|
-
colorMix = (value, tokenFn) => {
|
|
1132
|
-
if (!value || typeof value !== "string") return { invalid: true, value };
|
|
1133
|
-
const [colorPath, rawOpacity] = value.split("/");
|
|
1134
|
-
if (!colorPath || !rawOpacity) {
|
|
1135
|
-
return { invalid: true, value: colorPath };
|
|
1136
|
-
}
|
|
1137
|
-
const colorToken = tokenFn(colorPath);
|
|
1138
|
-
const opacityToken = this.getByName(`opacity.${rawOpacity}`)?.value;
|
|
1139
|
-
if (!opacityToken && isNaN(Number(rawOpacity))) {
|
|
1140
|
-
return { invalid: true, value: colorPath };
|
|
1141
|
-
}
|
|
1142
|
-
const percent = opacityToken ? Number(opacityToken) * 100 + "%" : `${rawOpacity}%`;
|
|
1143
|
-
const color = colorToken ?? colorPath;
|
|
1144
|
-
return {
|
|
1145
|
-
invalid: false,
|
|
1146
|
-
color,
|
|
1147
|
-
value: `color-mix(in srgb, ${color} ${percent}, transparent)`
|
|
1148
|
-
};
|
|
1149
|
-
};
|
|
1150
|
-
/**
|
|
1151
|
-
* Expand token references to their CSS variable
|
|
1152
|
-
*/
|
|
1153
|
-
expandReferenceInValue(value) {
|
|
1154
|
-
return expandTokenReferences(value, (path) => {
|
|
1155
|
-
if (!path) return;
|
|
1156
|
-
if (path.includes("/")) {
|
|
1157
|
-
const mix = this.colorMix(path, this.view.getVar.bind(this.view));
|
|
1158
|
-
if (mix.invalid) {
|
|
1159
|
-
throw new import_shared6.BambooError("INVALID_TOKEN", "Invalid color mix at " + path + ": " + mix.value);
|
|
1160
|
-
}
|
|
1161
|
-
return mix.value;
|
|
1162
|
-
}
|
|
1163
|
-
const resolved = this.view.getVar(path);
|
|
1164
|
-
if (resolved) return resolved;
|
|
1165
|
-
return tokenPathRegex.test(path) ? (0, import_shared6.esc)(path) : path;
|
|
1166
|
-
});
|
|
1167
|
-
}
|
|
1168
|
-
/**
|
|
1169
|
-
* Get the value of a token reference
|
|
1170
|
-
*/
|
|
1171
|
-
resolveReference(value) {
|
|
1172
|
-
return expandReferences(value, (key) => this.getByName(key)?.value);
|
|
1173
|
-
}
|
|
1174
|
-
/**
|
|
1175
|
-
* Resolve token references to their actual raw value (recursively resolves references)
|
|
1176
|
-
*/
|
|
1177
|
-
deepResolveReference(originalValue) {
|
|
1178
|
-
const stack = [originalValue];
|
|
1179
|
-
while (stack.length) {
|
|
1180
|
-
const next = stack.pop();
|
|
1181
|
-
if (next.startsWith("{")) {
|
|
1182
|
-
stack.push(this.resolveReference(next));
|
|
1183
|
-
continue;
|
|
1184
|
-
}
|
|
1185
|
-
if (next.startsWith("var(")) {
|
|
1186
|
-
const ref = this.view.nameByVar.get(next);
|
|
1187
|
-
if (ref) {
|
|
1188
|
-
stack.push(this.resolveReference(`{${ref}}`));
|
|
1189
|
-
continue;
|
|
1190
|
-
}
|
|
1191
|
-
}
|
|
1192
|
-
return next;
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
isDeprecated(name) {
|
|
1196
|
-
return this.deprecated.has(name);
|
|
1197
|
-
}
|
|
1198
|
-
build() {
|
|
1199
|
-
this.applyMiddlewares("pre");
|
|
1200
|
-
this.transformTokens("pre");
|
|
1201
|
-
this.addConditionalTokens();
|
|
1202
|
-
this.addReferences();
|
|
1203
|
-
this.expandTokenReferences();
|
|
1204
|
-
this.applyMiddlewares("post");
|
|
1205
|
-
this.transformTokens("post");
|
|
1206
|
-
this.setComputedView();
|
|
1207
|
-
return this;
|
|
1208
|
-
}
|
|
1209
|
-
get isEmpty() {
|
|
1210
|
-
return this.allTokens.length === 0;
|
|
1211
|
-
}
|
|
1212
|
-
view;
|
|
1213
|
-
setComputedView() {
|
|
1214
|
-
this.view = new TokenDictionaryView(this).getTokensView();
|
|
1215
|
-
return this;
|
|
1216
|
-
}
|
|
1217
|
-
};
|
|
1218
|
-
var TokenDictionaryView = class {
|
|
1219
|
-
constructor(dictionary) {
|
|
1220
|
-
this.dictionary = dictionary;
|
|
1221
|
-
this.dictionary = dictionary;
|
|
1222
|
-
}
|
|
1223
|
-
getTokensView() {
|
|
1224
|
-
const conditionMap = /* @__PURE__ */ new Map();
|
|
1225
|
-
const categoryMap = /* @__PURE__ */ new Map();
|
|
1226
|
-
const colorPalettes = /* @__PURE__ */ new Map();
|
|
1227
|
-
const colorPaletteTokens = /* @__PURE__ */ new Map();
|
|
1228
|
-
const valuesByCategory = /* @__PURE__ */ new Map();
|
|
1229
|
-
const flatValues = /* @__PURE__ */ new Map();
|
|
1230
|
-
const rawValues = /* @__PURE__ */ new Map();
|
|
1231
|
-
const nameByVar = /* @__PURE__ */ new Map();
|
|
1232
|
-
const vars = /* @__PURE__ */ new Map();
|
|
1233
|
-
this.dictionary.allTokens.forEach((token) => {
|
|
1234
|
-
this.processCondition(token, conditionMap);
|
|
1235
|
-
this.processColorPalette(token, colorPalettes, colorPaletteTokens, this.dictionary.byName);
|
|
1236
|
-
this.processCategory(token, categoryMap);
|
|
1237
|
-
this.processValue(token, valuesByCategory, flatValues, rawValues, nameByVar);
|
|
1238
|
-
this.processVars(token, vars);
|
|
1239
|
-
});
|
|
1240
|
-
const json = mapToJson(valuesByCategory);
|
|
1241
|
-
return {
|
|
1242
|
-
conditionMap,
|
|
1243
|
-
categoryMap,
|
|
1244
|
-
colorPalettes,
|
|
1245
|
-
vars,
|
|
1246
|
-
values: flatValues,
|
|
1247
|
-
nameByVar,
|
|
1248
|
-
json,
|
|
1249
|
-
valuesByCategory,
|
|
1250
|
-
get: (0, import_shared6.memo)((path, fallback) => {
|
|
1251
|
-
return rawValues.get(path) ?? fallback;
|
|
1252
|
-
}),
|
|
1253
|
-
getVar: (0, import_shared6.memo)((path, fallback) => {
|
|
1254
|
-
return flatValues.get(path) ?? fallback;
|
|
1255
|
-
}),
|
|
1256
|
-
getCategoryValues: (0, import_shared6.memo)((category) => {
|
|
1257
|
-
const result = json[category];
|
|
1258
|
-
if (result != null) {
|
|
1259
|
-
return result;
|
|
1260
|
-
}
|
|
1261
|
-
}),
|
|
1262
|
-
getColorPaletteValues: (0, import_shared6.memo)((palette) => {
|
|
1263
|
-
const tokens = colorPaletteTokens.get(palette);
|
|
1264
|
-
if (!tokens) return [];
|
|
1265
|
-
return Array.from(tokens).sort();
|
|
1266
|
-
})
|
|
1267
|
-
};
|
|
1268
|
-
}
|
|
1269
|
-
processCondition(token, group) {
|
|
1270
|
-
const { condition } = token.extensions;
|
|
1271
|
-
if (!condition) return;
|
|
1272
|
-
if (!group.has(condition)) group.set(condition, /* @__PURE__ */ new Set());
|
|
1273
|
-
group.get(condition).add(token);
|
|
1274
|
-
}
|
|
1275
|
-
processColorPalette(token, group, tokenPaths, byName) {
|
|
1276
|
-
const extensions = token.extensions;
|
|
1277
|
-
const { colorPalette, colorPaletteRoots, isVirtual } = extensions;
|
|
1278
|
-
if (!colorPalette || isVirtual) return;
|
|
1279
|
-
colorPaletteRoots.forEach((colorPaletteRoot) => {
|
|
1280
|
-
const formated = this.dictionary.formatTokenName(colorPaletteRoot);
|
|
1281
|
-
if (!group.has(formated)) {
|
|
1282
|
-
group.set(formated, /* @__PURE__ */ new Map());
|
|
1283
|
-
}
|
|
1284
|
-
if (!tokenPaths.has(formated)) {
|
|
1285
|
-
tokenPaths.set(formated, /* @__PURE__ */ new Set());
|
|
1286
|
-
}
|
|
1287
|
-
const virtualPath = replaceRootWithColorPalette([...token.path], [...colorPaletteRoot]);
|
|
1288
|
-
const virtualName = this.dictionary.formatTokenName(virtualPath);
|
|
1289
|
-
const virtualToken = byName.get(virtualName);
|
|
1290
|
-
if (!virtualToken) return;
|
|
1291
|
-
const virtualVar = virtualToken.extensions.var;
|
|
1292
|
-
group.get(formated).set(virtualVar, token.extensions.varRef);
|
|
1293
|
-
const tokenPath = this.dictionary.formatTokenName(virtualPath.slice(1));
|
|
1294
|
-
tokenPaths.get(formated).add(tokenPath);
|
|
1295
|
-
if (extensions.isDefault && colorPaletteRoot.length === 1) {
|
|
1296
|
-
const colorPaletteName = this.dictionary.formatTokenName(["colors", "colorPalette"]);
|
|
1297
|
-
const colorPaletteToken = byName.get(colorPaletteName);
|
|
1298
|
-
if (!colorPaletteToken) return;
|
|
1299
|
-
const name = this.dictionary.formatTokenName(token.path);
|
|
1300
|
-
const virtualToken2 = byName.get(name);
|
|
1301
|
-
if (!virtualToken2) return;
|
|
1302
|
-
const keyPath = extensions.colorPaletteTokenKeys[0]?.filter(Boolean);
|
|
1303
|
-
if (!keyPath.length) return;
|
|
1304
|
-
const formated2 = this.dictionary.formatTokenName(colorPaletteRoot.concat(keyPath));
|
|
1305
|
-
if (!group.has(formated2)) {
|
|
1306
|
-
group.set(formated2, /* @__PURE__ */ new Map());
|
|
1307
|
-
}
|
|
1308
|
-
group.get(formated2).set(colorPaletteToken.extensions.var, virtualToken2.extensions.varRef);
|
|
1309
|
-
}
|
|
1310
|
-
});
|
|
1311
|
-
}
|
|
1312
|
-
processCategory(token, group) {
|
|
1313
|
-
const { category, prop } = token.extensions;
|
|
1314
|
-
if (!category) return;
|
|
1315
|
-
if (!group.has(category)) group.set(category, /* @__PURE__ */ new Map());
|
|
1316
|
-
group.get(category).set(prop, token);
|
|
1317
|
-
}
|
|
1318
|
-
processValue(token, byCategory, flatValues, rawValues, nameByVar) {
|
|
1319
|
-
const { category, prop, varRef, isNegative, isVirtual, condition } = token.extensions;
|
|
1320
|
-
if (!category) return;
|
|
1321
|
-
if (!byCategory.has(category)) byCategory.set(category, /* @__PURE__ */ new Map());
|
|
1322
|
-
const value = isNegative ? token.extensions.condition !== "base" ? token.originalValue : token.value : varRef;
|
|
1323
|
-
byCategory.get(category).set(prop, value);
|
|
1324
|
-
flatValues.set(token.name, value);
|
|
1325
|
-
nameByVar.set(value, token.name);
|
|
1326
|
-
const rawValue = isVirtual || condition !== "base" ? varRef : token.value;
|
|
1327
|
-
rawValues.set(token.name, rawValue);
|
|
1328
|
-
}
|
|
1329
|
-
processVars(token, group) {
|
|
1330
|
-
const { condition, isNegative, isVirtual, var: varName, theme } = token.extensions;
|
|
1331
|
-
if (isNegative || !theme && isVirtual || !condition) return;
|
|
1332
|
-
if (!group.has(condition)) group.set(condition, /* @__PURE__ */ new Map());
|
|
1333
|
-
group.get(condition).set(varName, token.value);
|
|
1334
|
-
}
|
|
1335
|
-
};
|
|
1336
|
-
function replaceRootWithColorPalette(path, colorPaletteRoot) {
|
|
1337
|
-
const startIndex = path.findIndex(
|
|
1338
|
-
(element, index) => colorPaletteRoot.every((rootElement, rootIndex) => path[index + rootIndex] === rootElement)
|
|
1339
|
-
);
|
|
1340
|
-
if (startIndex === -1) {
|
|
1341
|
-
return path;
|
|
1342
|
-
}
|
|
1343
|
-
path.splice(startIndex, colorPaletteRoot.length);
|
|
1344
|
-
path.splice(startIndex, 0, "colorPalette");
|
|
1345
|
-
return path;
|
|
1346
|
-
}
|
|
1347
|
-
var tokenPathRegex = /\w+\.\w+/;
|
|
1348
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1349
|
-
0 && (module.exports = {
|
|
1350
|
-
TOKEN_CATEGORIES,
|
|
1351
|
-
Token,
|
|
1352
|
-
TokenDictionary,
|
|
1353
|
-
assertTokenFormat,
|
|
1354
|
-
expandReferences,
|
|
1355
|
-
getReferences,
|
|
1356
|
-
hasReference,
|
|
1357
|
-
isToken,
|
|
1358
|
-
mapToJson
|
|
1359
|
-
});
|