@styleframe/cli 4.0.0 → 4.1.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/CHANGELOG.md +43 -0
- package/dist/build-CBdsifMN.js +47 -0
- package/dist/build-D7cinF0l.cjs +50 -0
- package/dist/build-dtcg-BpbjBRCf.js +429 -0
- package/dist/build-dtcg-vuGHy-Sl.cjs +434 -0
- package/dist/chunk-D6vf50IK.cjs +28 -0
- package/dist/dtcg-D1-iITOr.js +14 -0
- package/dist/dtcg-D84AfyzO.cjs +13 -0
- package/dist/export-CBdPGGEq.js +66 -0
- package/dist/export-DmPAU9Wh.cjs +69 -0
- package/dist/export-ONk9eKoZ.cjs +86 -0
- package/dist/export-suUS16eO.js +83 -0
- package/dist/figma-BvXoqRPU.cjs +13 -0
- package/dist/figma-D2RJh56T.js +14 -0
- package/dist/import-BQrcHNjK.cjs +126 -0
- package/dist/import-Bll_uBvJ.js +123 -0
- package/dist/import-MqLYxb8d.js +114 -0
- package/dist/import-ibQc_GXm.cjs +117 -0
- package/dist/index.cjs +16 -16
- package/dist/index.d.cts +4 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.js +16 -17
- package/dist/init-CAO0mA_w.js +262 -0
- package/dist/init-CaJoUVv2.cjs +265 -0
- package/package.json +22 -20
- package/dist/build-BIWOTFZD.cjs +0 -49
- package/dist/build-CANA04j1.js +0 -49
- package/dist/export-BMneJTdq.cjs +0 -517
- package/dist/export-Cx6awh55.js +0 -517
- package/dist/import-BLbc2zWU.cjs +0 -90
- package/dist/import-a5DtGEAY.js +0 -90
- package/dist/index-BTHfb82h.js +0 -14
- package/dist/index-jMzviwjD.cjs +0 -14
- package/dist/init-CKeTXHp5.js +0 -234
- package/dist/init-CO7VnQKe.cjs +0 -234
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
let _styleframe_dtcg = require("@styleframe/dtcg");
|
|
2
|
+
//#region src/commands/dtcg/evaluate.ts
|
|
3
|
+
function isReference(value) {
|
|
4
|
+
return typeof value === "object" && value !== null && "type" in value && value.type === "reference";
|
|
5
|
+
}
|
|
6
|
+
function isCss(value) {
|
|
7
|
+
return typeof value === "object" && value !== null && "type" in value && value.type === "css";
|
|
8
|
+
}
|
|
9
|
+
function isPrimitive(value) {
|
|
10
|
+
return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Resolve a Reference's *primitive* value (following alias chains). Returns
|
|
14
|
+
* null if the chain is broken (missing target or cycle).
|
|
15
|
+
*/
|
|
16
|
+
function resolveReferenceTarget(ref, context) {
|
|
17
|
+
const visited = context.visited ?? /* @__PURE__ */ new Set();
|
|
18
|
+
if (visited.has(ref.name)) return {
|
|
19
|
+
resolved: null,
|
|
20
|
+
reason: `Reference cycle: ${[...visited, ref.name].join(" → ")}`
|
|
21
|
+
};
|
|
22
|
+
const target = context.variables.get(ref.name);
|
|
23
|
+
if (!target) {
|
|
24
|
+
if (ref.fallback !== void 0 && ref.fallback !== null) return evaluateValue(ref.fallback, context);
|
|
25
|
+
return {
|
|
26
|
+
resolved: null,
|
|
27
|
+
reason: `Unknown reference target: ${ref.name}`
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const nextContext = {
|
|
31
|
+
variables: context.variables,
|
|
32
|
+
visited: new Set([...visited, ref.name]),
|
|
33
|
+
maxViewport: context.maxViewport
|
|
34
|
+
};
|
|
35
|
+
return evaluateValue(target.value, nextContext);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Try to evaluate a CSS template literal. Two strategies:
|
|
39
|
+
*
|
|
40
|
+
* 1. **String-template fold**: replace each `Reference` part with its
|
|
41
|
+
* resolved primitive (stringified) and concatenate. If the resulting
|
|
42
|
+
* string parses as a known CSS form (cubic-bezier(...), a hex color,
|
|
43
|
+
* a dimension, a duration), return it.
|
|
44
|
+
* 2. **Pure arithmetic**: if every part reduces to a finite number or one
|
|
45
|
+
* of `+`/`-`/`*`/`/`/`(`/`)` operators with whitespace, evaluate the
|
|
46
|
+
* arithmetic and return the numeric result.
|
|
47
|
+
*
|
|
48
|
+
* Otherwise, return `{resolved: null, cssExpression: <fold>}` so the caller
|
|
49
|
+
* can preserve the expression in an extension.
|
|
50
|
+
*/
|
|
51
|
+
function evaluateCss(css, context) {
|
|
52
|
+
const parts = [];
|
|
53
|
+
let unevaluable = false;
|
|
54
|
+
let unevaluableReason;
|
|
55
|
+
for (const part of css.value) {
|
|
56
|
+
if (typeof part === "string") {
|
|
57
|
+
parts.push({
|
|
58
|
+
kind: "literal",
|
|
59
|
+
text: part
|
|
60
|
+
});
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const evaluated = evaluateValue(part, context);
|
|
64
|
+
if (evaluated.resolved === null) {
|
|
65
|
+
unevaluable = true;
|
|
66
|
+
unevaluableReason = evaluated.reason;
|
|
67
|
+
parts.push({
|
|
68
|
+
kind: "value",
|
|
69
|
+
text: ""
|
|
70
|
+
});
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const text = String(evaluated.resolved);
|
|
74
|
+
const numeric = typeof evaluated.resolved === "number" ? evaluated.resolved : void 0;
|
|
75
|
+
parts.push({
|
|
76
|
+
kind: "value",
|
|
77
|
+
text,
|
|
78
|
+
numeric
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
const folded = parts.map((p) => p.text).join("");
|
|
82
|
+
if (unevaluable) return {
|
|
83
|
+
resolved: null,
|
|
84
|
+
cssExpression: folded,
|
|
85
|
+
reason: unevaluableReason ?? "Computed expression includes an unresolvable reference"
|
|
86
|
+
};
|
|
87
|
+
if (parts.every((p) => {
|
|
88
|
+
if (p.kind === "value") return p.numeric !== void 0;
|
|
89
|
+
return /^[\d.\s+\-*/()]*$/.test(p.text);
|
|
90
|
+
}) && parts.some((p) => p.kind === "value")) try {
|
|
91
|
+
const result = safeArithmetic(folded.trim());
|
|
92
|
+
if (typeof result === "number" && Number.isFinite(result)) return { resolved: result };
|
|
93
|
+
} catch (err) {
|
|
94
|
+
return {
|
|
95
|
+
resolved: null,
|
|
96
|
+
cssExpression: folded,
|
|
97
|
+
reason: `Arithmetic evaluation failed: ${err.message}`
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
const subResult = substituteFluidUnits(folded, context.maxViewport ?? 1440);
|
|
101
|
+
if (subResult && /^[\d.\s+\-*/()]+$/.test(subResult.rebased)) try {
|
|
102
|
+
const result = safeArithmetic(subResult.rebased.trim());
|
|
103
|
+
if (typeof result === "number" && Number.isFinite(result)) return {
|
|
104
|
+
resolved: result,
|
|
105
|
+
...subResult.substituted ? { normalisationSource: "fluid-max" } : {}
|
|
106
|
+
};
|
|
107
|
+
} catch {}
|
|
108
|
+
return { resolved: folded };
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Replace fluid-friendly literals so a `calc()` expression mixing `100vw`,
|
|
112
|
+
* `rem`, and `px` reduces to pure arithmetic.
|
|
113
|
+
*
|
|
114
|
+
* Returns `null` when the input still contains units we don't substitute
|
|
115
|
+
* (e.g. `vh`, `%`, `em`) — the caller should fall back to the
|
|
116
|
+
* verbatim-string path.
|
|
117
|
+
*
|
|
118
|
+
* `substituted` indicates whether at least one fluid unit was actually
|
|
119
|
+
* substituted. `false` means we only stripped a bare `calc(...)` wrapper —
|
|
120
|
+
* the expression was effectively pure arithmetic and the result should NOT
|
|
121
|
+
* be flagged as fluid-normalised.
|
|
122
|
+
*/
|
|
123
|
+
function substituteFluidUnits(expression, maxViewport) {
|
|
124
|
+
let substituted = false;
|
|
125
|
+
let rebased = expression.replace(/\bcalc\b/g, "");
|
|
126
|
+
if (rebased.includes("100vw")) {
|
|
127
|
+
rebased = rebased.replace(/100vw/g, String(maxViewport));
|
|
128
|
+
substituted = true;
|
|
129
|
+
}
|
|
130
|
+
if (/(-?\d*\.?\d+)\s*rem/.test(rebased)) {
|
|
131
|
+
rebased = rebased.replace(/(-?\d*\.?\d+)\s*rem/g, "($1 * 16)");
|
|
132
|
+
substituted = true;
|
|
133
|
+
}
|
|
134
|
+
if (/(-?\d*\.?\d+)\s*px/.test(rebased)) {
|
|
135
|
+
rebased = rebased.replace(/(-?\d*\.?\d+)\s*px/g, "$1");
|
|
136
|
+
substituted = true;
|
|
137
|
+
}
|
|
138
|
+
if (/[a-zA-Z%]/.test(rebased)) return null;
|
|
139
|
+
return {
|
|
140
|
+
rebased,
|
|
141
|
+
substituted
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Safe arithmetic over a whitespace-trimmed expression containing only
|
|
146
|
+
* numbers, parentheses, and `+`/`-`/`*`/`/`. Throws on anything else.
|
|
147
|
+
*/
|
|
148
|
+
function safeArithmetic(expression) {
|
|
149
|
+
if (!/^[\d.\s+\-*/()]+$/.test(expression)) throw new Error(`Disallowed characters in expression: "${expression}"`);
|
|
150
|
+
return new Function(`return (${expression});`)();
|
|
151
|
+
}
|
|
152
|
+
function evaluateValue(value, context) {
|
|
153
|
+
if (value === null || value === void 0) return {
|
|
154
|
+
resolved: null,
|
|
155
|
+
reason: "Value is null/undefined"
|
|
156
|
+
};
|
|
157
|
+
if (isPrimitive(value)) return { resolved: value };
|
|
158
|
+
if (isReference(value)) {
|
|
159
|
+
const targetResolution = resolveReferenceTarget(value, context);
|
|
160
|
+
if ((!context.visited || context.visited.size === 0) && targetResolution.resolved !== null) return {
|
|
161
|
+
...targetResolution,
|
|
162
|
+
aliasTarget: value.name
|
|
163
|
+
};
|
|
164
|
+
return targetResolution;
|
|
165
|
+
}
|
|
166
|
+
if (isCss(value)) return evaluateCss(value, context);
|
|
167
|
+
if (Array.isArray(value)) return {
|
|
168
|
+
resolved: null,
|
|
169
|
+
reason: "Heterogeneous array — DTCG composite encoding not yet implemented"
|
|
170
|
+
};
|
|
171
|
+
return {
|
|
172
|
+
resolved: null,
|
|
173
|
+
reason: `Unsupported value shape: ${typeof value}`
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
//#endregion
|
|
177
|
+
//#region src/commands/dtcg/build-dtcg.ts
|
|
178
|
+
var TOKENS_SCHEMA_URL = "https://design-tokens.org/schemas/2025.10/tokens.json";
|
|
179
|
+
var RESOLVER_SCHEMA_URL = "https://www.designtokens.org/schemas/2025.10/resolver.json";
|
|
180
|
+
function buildVariableMap(root) {
|
|
181
|
+
const map = /* @__PURE__ */ new Map();
|
|
182
|
+
for (const v of root.variables) map.set(v.name, v);
|
|
183
|
+
for (const theme of root.themes) for (const v of theme.variables) if (!map.has(v.name)) map.set(v.name, v);
|
|
184
|
+
return map;
|
|
185
|
+
}
|
|
186
|
+
function processVariable(variable, context) {
|
|
187
|
+
const evaluation = evaluateValue(variable.value, context);
|
|
188
|
+
const classification = classifyValueForVariable(variable.name, evaluation);
|
|
189
|
+
return {
|
|
190
|
+
name: variable.name,
|
|
191
|
+
evaluation,
|
|
192
|
+
classification
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function classifyValueForVariable(name, evaluation) {
|
|
196
|
+
if (evaluation.resolved === null) return void 0;
|
|
197
|
+
return (0, _styleframe_dtcg.classifyValue)(evaluation.resolved, { path: name });
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Place a token at `dotPath` in `doc`. Two collision cases need handling:
|
|
201
|
+
*
|
|
202
|
+
* 1. **Token at a path whose group already has children.** If we set
|
|
203
|
+
* `border-width = {...token}` after `border-width.thin = {...}` was
|
|
204
|
+
* written, a naive overwrite drops the children. Instead, we promote
|
|
205
|
+
* the parent token into a `$root` slot inside the existing group.
|
|
206
|
+
* 2. **Children written into a slot that's already a token.** Reverse
|
|
207
|
+
* ordering: if `border-width = {...token}` was written first and we
|
|
208
|
+
* now need to add `border-width.thin = {...}`, we move the existing
|
|
209
|
+
* token into `$root` and continue descending into the new group.
|
|
210
|
+
*
|
|
211
|
+
* Both cases are handled by checking whether the slot looks like a token
|
|
212
|
+
* (`$value` present) or a group, and by upgrading to `$root` whenever a
|
|
213
|
+
* token coexists with siblings at the same path.
|
|
214
|
+
*/
|
|
215
|
+
function setNestedToken(doc, dotPath, token) {
|
|
216
|
+
const segments = dotPath.split(".");
|
|
217
|
+
let cursor = doc;
|
|
218
|
+
for (let i = 0; i < segments.length - 1; i++) {
|
|
219
|
+
const segment = segments[i];
|
|
220
|
+
const next = cursor[segment];
|
|
221
|
+
if (typeof next !== "object" || next === null || Array.isArray(next)) cursor[segment] = {};
|
|
222
|
+
else if ("$value" in next) cursor[segment] = { $root: next };
|
|
223
|
+
cursor = cursor[segment];
|
|
224
|
+
}
|
|
225
|
+
const leaf = segments[segments.length - 1];
|
|
226
|
+
const existing = cursor[leaf];
|
|
227
|
+
if (typeof existing === "object" && existing !== null && !Array.isArray(existing) && !("$value" in existing)) existing.$root = token;
|
|
228
|
+
else cursor[leaf] = token;
|
|
229
|
+
}
|
|
230
|
+
function hasRootToken(doc, dotPath) {
|
|
231
|
+
const segments = dotPath.split(".");
|
|
232
|
+
let cursor = doc;
|
|
233
|
+
for (const segment of segments) {
|
|
234
|
+
if (typeof cursor !== "object" || cursor === null || Array.isArray(cursor)) return false;
|
|
235
|
+
cursor = cursor[segment];
|
|
236
|
+
}
|
|
237
|
+
return typeof cursor === "object" && cursor !== null && !Array.isArray(cursor) && "$root" in cursor;
|
|
238
|
+
}
|
|
239
|
+
function setNestedOverride(context, dotPath, value, type) {
|
|
240
|
+
const segments = dotPath.split(".");
|
|
241
|
+
let cursor = context;
|
|
242
|
+
for (let i = 0; i < segments.length - 1; i++) {
|
|
243
|
+
const segment = segments[i];
|
|
244
|
+
const next = cursor[segment];
|
|
245
|
+
if (typeof next !== "object" || next === null || Array.isArray(next) || "$value" in next) cursor[segment] = {};
|
|
246
|
+
cursor = cursor[segment];
|
|
247
|
+
}
|
|
248
|
+
const token = { $value: value };
|
|
249
|
+
if (type !== void 0) token.$type = type;
|
|
250
|
+
cursor[segments[segments.length - 1]] = token;
|
|
251
|
+
}
|
|
252
|
+
function makeAliasToken(target, type, description) {
|
|
253
|
+
const token = { $value: (0, _styleframe_dtcg.formatAlias)(target) };
|
|
254
|
+
if (type !== void 0) token.$type = type;
|
|
255
|
+
if (description) token.$description = description;
|
|
256
|
+
return token;
|
|
257
|
+
}
|
|
258
|
+
function makeValueToken(classification, description, fluidBound) {
|
|
259
|
+
const token = {
|
|
260
|
+
$value: classification.value,
|
|
261
|
+
$type: classification.type
|
|
262
|
+
};
|
|
263
|
+
if (description) token.$description = description;
|
|
264
|
+
if (fluidBound) token.$extensions = { "dev.styleframe": { fluidBound } };
|
|
265
|
+
return token;
|
|
266
|
+
}
|
|
267
|
+
function makeExpressionToken(expression, description) {
|
|
268
|
+
const token = {
|
|
269
|
+
$value: expression,
|
|
270
|
+
$extensions: { "dev.styleframe": { expression } }
|
|
271
|
+
};
|
|
272
|
+
if (description) token.$description = description;
|
|
273
|
+
return token;
|
|
274
|
+
}
|
|
275
|
+
function valuesEqual(a, b) {
|
|
276
|
+
if (a === b) return true;
|
|
277
|
+
if (typeof a !== typeof b) return false;
|
|
278
|
+
if (typeof a === "object") return JSON.stringify(a) === JSON.stringify(b);
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
function capitalizeContextName(name) {
|
|
282
|
+
if (name.length === 0) return name;
|
|
283
|
+
return name.charAt(0).toUpperCase() + name.slice(1);
|
|
284
|
+
}
|
|
285
|
+
function buildDTCG(root, options = {}) {
|
|
286
|
+
const includeSchema = options.includeSchema ?? true;
|
|
287
|
+
const schemaUrl = options.schemaUrl ?? TOKENS_SCHEMA_URL;
|
|
288
|
+
const modifierName = options.modifierName ?? "theme";
|
|
289
|
+
const collectionName = options.collectionName ?? "Design Tokens";
|
|
290
|
+
const defaultModeName = options.defaultModeName ?? "Default";
|
|
291
|
+
const tokensSourceRef = options.tokensSourceRef ?? "tokens.json";
|
|
292
|
+
const variableMap = buildVariableMap(root);
|
|
293
|
+
const fluidMaxVariable = variableMap.get("fluid.max-width");
|
|
294
|
+
const fluidMaxResolved = fluidMaxVariable ? evaluateValue(fluidMaxVariable.value, { variables: variableMap }).resolved : null;
|
|
295
|
+
const maxViewport = typeof fluidMaxResolved === "number" ? fluidMaxResolved : 1440;
|
|
296
|
+
const context = {
|
|
297
|
+
variables: variableMap,
|
|
298
|
+
maxViewport
|
|
299
|
+
};
|
|
300
|
+
const processed = /* @__PURE__ */ new Map();
|
|
301
|
+
const typeMap = /* @__PURE__ */ new Map();
|
|
302
|
+
for (const variable of root.variables) {
|
|
303
|
+
const p = processVariable(variable, context);
|
|
304
|
+
processed.set(variable.name, p);
|
|
305
|
+
if (p.classification) typeMap.set(variable.name, p.classification.type);
|
|
306
|
+
}
|
|
307
|
+
const resolveTypeFromAliasChain = (name, seen) => {
|
|
308
|
+
if (seen.has(name)) return void 0;
|
|
309
|
+
const direct = typeMap.get(name);
|
|
310
|
+
if (direct) return direct;
|
|
311
|
+
const p = processed.get(name);
|
|
312
|
+
if (p?.evaluation.aliasTarget) return resolveTypeFromAliasChain(p.evaluation.aliasTarget, new Set([...seen, name]));
|
|
313
|
+
};
|
|
314
|
+
const tokens = {};
|
|
315
|
+
if (includeSchema) tokens.$schema = schemaUrl;
|
|
316
|
+
tokens.$extensions = { "dev.styleframe": { collection: collectionName } };
|
|
317
|
+
const diagnostics = [];
|
|
318
|
+
let emittedCount = 0;
|
|
319
|
+
let fluidNormalisedCount = 0;
|
|
320
|
+
for (const variable of root.variables) {
|
|
321
|
+
const p = processed.get(variable.name);
|
|
322
|
+
if (!p) continue;
|
|
323
|
+
const { evaluation, classification } = p;
|
|
324
|
+
if (evaluation.aliasTarget) {
|
|
325
|
+
const targetType = resolveTypeFromAliasChain(evaluation.aliasTarget, /* @__PURE__ */ new Set());
|
|
326
|
+
setNestedToken(tokens, variable.name, makeAliasToken(evaluation.aliasTarget, targetType));
|
|
327
|
+
emittedCount++;
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
if (classification) {
|
|
331
|
+
const fluidBound = evaluation.normalisationSource === "fluid-max" ? "max" : void 0;
|
|
332
|
+
const promoted = fluidBound && classification.type === "number" && typeof classification.value === "number" ? {
|
|
333
|
+
type: "dimension",
|
|
334
|
+
value: {
|
|
335
|
+
value: classification.value,
|
|
336
|
+
unit: "px"
|
|
337
|
+
}
|
|
338
|
+
} : classification;
|
|
339
|
+
setNestedToken(tokens, variable.name, makeValueToken(promoted, void 0, fluidBound));
|
|
340
|
+
if (fluidBound) fluidNormalisedCount++;
|
|
341
|
+
emittedCount++;
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
if (evaluation.cssExpression) {
|
|
345
|
+
setNestedToken(tokens, variable.name, makeExpressionToken(evaluation.cssExpression));
|
|
346
|
+
diagnostics.push({
|
|
347
|
+
name: variable.name,
|
|
348
|
+
level: "warn",
|
|
349
|
+
reason: evaluation.reason ?? "Computed expression — preserved as dev.styleframe.expression extension"
|
|
350
|
+
});
|
|
351
|
+
emittedCount++;
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
if (evaluation.resolved !== null && typeof evaluation.resolved !== "boolean") {
|
|
355
|
+
setNestedToken(tokens, variable.name, {
|
|
356
|
+
$value: String(evaluation.resolved),
|
|
357
|
+
$extensions: { "dev.styleframe": { unknownType: true } }
|
|
358
|
+
});
|
|
359
|
+
diagnostics.push({
|
|
360
|
+
name: variable.name,
|
|
361
|
+
level: "warn",
|
|
362
|
+
reason: "Could not infer DTCG $type — emitted as untyped string"
|
|
363
|
+
});
|
|
364
|
+
emittedCount++;
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
diagnostics.push({
|
|
368
|
+
name: variable.name,
|
|
369
|
+
level: "warn",
|
|
370
|
+
reason: evaluation.reason ?? "Unrepresentable value — skipped"
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
const themedThemes = root.themes.filter((t) => t.variables.length > 0);
|
|
374
|
+
let resolver;
|
|
375
|
+
if (themedThemes.length > 0) {
|
|
376
|
+
const contexts = {};
|
|
377
|
+
for (const theme of themedThemes) {
|
|
378
|
+
const contextDoc = {};
|
|
379
|
+
for (const variable of theme.variables) {
|
|
380
|
+
const themeProcessed = processVariable(variable, context);
|
|
381
|
+
const defaultProcessed = processed.get(variable.name);
|
|
382
|
+
let themeValue;
|
|
383
|
+
let themeType;
|
|
384
|
+
if (themeProcessed.evaluation.aliasTarget) {
|
|
385
|
+
themeValue = (0, _styleframe_dtcg.formatAlias)(themeProcessed.evaluation.aliasTarget);
|
|
386
|
+
themeType = resolveTypeFromAliasChain(themeProcessed.evaluation.aliasTarget, /* @__PURE__ */ new Set());
|
|
387
|
+
} else if (themeProcessed.classification) {
|
|
388
|
+
themeValue = themeProcessed.classification.value;
|
|
389
|
+
themeType = themeProcessed.classification.type;
|
|
390
|
+
}
|
|
391
|
+
if (themeValue === void 0) continue;
|
|
392
|
+
let defaultValue;
|
|
393
|
+
if (defaultProcessed?.evaluation.aliasTarget) defaultValue = (0, _styleframe_dtcg.formatAlias)(defaultProcessed.evaluation.aliasTarget);
|
|
394
|
+
else if (defaultProcessed?.classification) defaultValue = defaultProcessed.classification.value;
|
|
395
|
+
if (defaultValue !== void 0 && valuesEqual(themeValue, defaultValue)) continue;
|
|
396
|
+
setNestedOverride(contextDoc, hasRootToken(tokens, variable.name) ? `${variable.name}.$root` : variable.name, themeValue, themeType);
|
|
397
|
+
}
|
|
398
|
+
contexts[capitalizeContextName(theme.name)] = contextDoc;
|
|
399
|
+
}
|
|
400
|
+
for (const key of Object.keys(contexts)) if (Object.keys(contexts[key]).length === 0) delete contexts[key];
|
|
401
|
+
const themeContextNames = Object.keys(contexts);
|
|
402
|
+
if (themeContextNames.length > 0) {
|
|
403
|
+
const allContexts = { [defaultModeName]: [] };
|
|
404
|
+
for (const name of themeContextNames) allContexts[name] = [contexts[name]];
|
|
405
|
+
resolver = {
|
|
406
|
+
$schema: RESOLVER_SCHEMA_URL,
|
|
407
|
+
version: "2025.10",
|
|
408
|
+
modifiers: { [modifierName]: {
|
|
409
|
+
contexts: allContexts,
|
|
410
|
+
default: defaultModeName
|
|
411
|
+
} },
|
|
412
|
+
resolutionOrder: [{
|
|
413
|
+
type: "set",
|
|
414
|
+
sources: [{ $ref: tokensSourceRef }]
|
|
415
|
+
}, { $ref: `#/modifiers/${modifierName}` }]
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return {
|
|
420
|
+
tokens,
|
|
421
|
+
resolver,
|
|
422
|
+
diagnostics,
|
|
423
|
+
emittedCount,
|
|
424
|
+
fluidNormalisedCount,
|
|
425
|
+
maxViewport
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
//#endregion
|
|
429
|
+
Object.defineProperty(exports, "buildDTCG", {
|
|
430
|
+
enumerable: true,
|
|
431
|
+
get: function() {
|
|
432
|
+
return buildDTCG;
|
|
433
|
+
}
|
|
434
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
//#endregion
|
|
23
|
+
Object.defineProperty(exports, "__toESM", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function() {
|
|
26
|
+
return __toESM;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { defineCommand } from "citty";
|
|
2
|
+
//#region src/commands/dtcg/index.ts
|
|
3
|
+
var dtcg_default = defineCommand({
|
|
4
|
+
meta: {
|
|
5
|
+
name: "dtcg",
|
|
6
|
+
description: "Export Styleframe variables to and import them from DTCG format"
|
|
7
|
+
},
|
|
8
|
+
subCommands: {
|
|
9
|
+
export: () => import("./export-CBdPGGEq.js").then((m) => m.default),
|
|
10
|
+
import: () => import("./import-MqLYxb8d.js").then((m) => m.default)
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
//#endregion
|
|
14
|
+
export { dtcg_default as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/commands/dtcg/index.ts
|
|
2
|
+
var dtcg_default = (0, require("citty").defineCommand)({
|
|
3
|
+
meta: {
|
|
4
|
+
name: "dtcg",
|
|
5
|
+
description: "Export Styleframe variables to and import them from DTCG format"
|
|
6
|
+
},
|
|
7
|
+
subCommands: {
|
|
8
|
+
export: () => Promise.resolve().then(() => require("./export-DmPAU9Wh.cjs")).then((m) => m.default),
|
|
9
|
+
import: () => Promise.resolve().then(() => require("./import-ibQc_GXm.cjs")).then((m) => m.default)
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
//#endregion
|
|
13
|
+
exports.default = dtcg_default;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { t as buildDTCG } from "./build-dtcg-BpbjBRCf.js";
|
|
2
|
+
import { defineCommand } from "citty";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { loadConfiguration } from "@styleframe/loader";
|
|
5
|
+
import consola from "consola";
|
|
6
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
7
|
+
//#region src/commands/dtcg/export.ts
|
|
8
|
+
var export_default = defineCommand({
|
|
9
|
+
meta: {
|
|
10
|
+
name: "export",
|
|
11
|
+
description: "Export Styleframe variables to spec-conformant DTCG JSON"
|
|
12
|
+
},
|
|
13
|
+
args: {
|
|
14
|
+
config: {
|
|
15
|
+
type: "string",
|
|
16
|
+
description: "Path to the Styleframe config file",
|
|
17
|
+
default: "styleframe.config.ts",
|
|
18
|
+
alias: ["c"],
|
|
19
|
+
valueHint: "path"
|
|
20
|
+
},
|
|
21
|
+
output: {
|
|
22
|
+
type: "string",
|
|
23
|
+
description: "Output directory for DTCG files",
|
|
24
|
+
default: ".",
|
|
25
|
+
alias: ["o"],
|
|
26
|
+
valueHint: "path"
|
|
27
|
+
},
|
|
28
|
+
collection: {
|
|
29
|
+
type: "string",
|
|
30
|
+
description: "Collection name embedded in the export",
|
|
31
|
+
default: "Design Tokens",
|
|
32
|
+
alias: ["n", "name"]
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
async run({ args }) {
|
|
36
|
+
const configPath = path.resolve(args.config);
|
|
37
|
+
const outputDir = path.resolve(args.output);
|
|
38
|
+
consola.info(`Loading configuration from "${path.relative(process.cwd(), configPath)}"...`);
|
|
39
|
+
const root = (await loadConfiguration({ entry: configPath })).root;
|
|
40
|
+
consola.info("Building DTCG document...");
|
|
41
|
+
const { tokens, resolver, diagnostics, emittedCount, fluidNormalisedCount, maxViewport } = buildDTCG(root, {
|
|
42
|
+
collectionName: args.collection,
|
|
43
|
+
tokensSourceRef: "tokens.json"
|
|
44
|
+
});
|
|
45
|
+
await mkdir(outputDir, { recursive: true });
|
|
46
|
+
const tokensPath = path.join(outputDir, "tokens.json");
|
|
47
|
+
await writeFile(tokensPath, `${JSON.stringify(tokens, null, 2)}\n`);
|
|
48
|
+
consola.info(`Wrote ${emittedCount} tokens to "${path.relative(process.cwd(), tokensPath)}"`);
|
|
49
|
+
if (fluidNormalisedCount > 0) consola.info(`Normalised ${fluidNormalisedCount} fluid token(s) using max viewport (${maxViewport}px).`);
|
|
50
|
+
if (resolver) {
|
|
51
|
+
const resolverPath = path.join(outputDir, "tokens.resolver.json");
|
|
52
|
+
await writeFile(resolverPath, `${JSON.stringify(resolver, null, 2)}\n`);
|
|
53
|
+
consola.info(`Wrote resolver to "${path.relative(process.cwd(), resolverPath)}"`);
|
|
54
|
+
}
|
|
55
|
+
const warnings = diagnostics.filter((d) => d.level === "warn");
|
|
56
|
+
if (warnings.length > 0) {
|
|
57
|
+
consola.warn(`${warnings.length} variable(s) needed special handling — see Styleframe ↔ DTCG round-trip notes`);
|
|
58
|
+
for (const w of warnings.slice(0, 10)) consola.info(` - ${w.name}: ${w.reason}`);
|
|
59
|
+
if (warnings.length > 10) consola.info(` ... and ${warnings.length - 10} more`);
|
|
60
|
+
consola.info("Tip: untyped tokens are usually CSS keywords (e.g. \"normal\", \"thin\", \"italic\") with no DTCG equivalent — they round-trip to Figma as STRING variables.");
|
|
61
|
+
}
|
|
62
|
+
consola.success(`Exported ${emittedCount} tokens in DTCG format to "${path.relative(process.cwd(), outputDir)}"`);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
//#endregion
|
|
66
|
+
export { export_default as default };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const require_chunk = require("./chunk-D6vf50IK.cjs");
|
|
2
|
+
const require_build_dtcg = require("./build-dtcg-vuGHy-Sl.cjs");
|
|
3
|
+
let citty = require("citty");
|
|
4
|
+
let node_path = require("node:path");
|
|
5
|
+
node_path = require_chunk.__toESM(node_path, 1);
|
|
6
|
+
let _styleframe_loader = require("@styleframe/loader");
|
|
7
|
+
let consola = require("consola");
|
|
8
|
+
consola = require_chunk.__toESM(consola, 1);
|
|
9
|
+
let node_fs_promises = require("node:fs/promises");
|
|
10
|
+
//#region src/commands/dtcg/export.ts
|
|
11
|
+
var export_default = (0, citty.defineCommand)({
|
|
12
|
+
meta: {
|
|
13
|
+
name: "export",
|
|
14
|
+
description: "Export Styleframe variables to spec-conformant DTCG JSON"
|
|
15
|
+
},
|
|
16
|
+
args: {
|
|
17
|
+
config: {
|
|
18
|
+
type: "string",
|
|
19
|
+
description: "Path to the Styleframe config file",
|
|
20
|
+
default: "styleframe.config.ts",
|
|
21
|
+
alias: ["c"],
|
|
22
|
+
valueHint: "path"
|
|
23
|
+
},
|
|
24
|
+
output: {
|
|
25
|
+
type: "string",
|
|
26
|
+
description: "Output directory for DTCG files",
|
|
27
|
+
default: ".",
|
|
28
|
+
alias: ["o"],
|
|
29
|
+
valueHint: "path"
|
|
30
|
+
},
|
|
31
|
+
collection: {
|
|
32
|
+
type: "string",
|
|
33
|
+
description: "Collection name embedded in the export",
|
|
34
|
+
default: "Design Tokens",
|
|
35
|
+
alias: ["n", "name"]
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
async run({ args }) {
|
|
39
|
+
const configPath = node_path.default.resolve(args.config);
|
|
40
|
+
const outputDir = node_path.default.resolve(args.output);
|
|
41
|
+
consola.default.info(`Loading configuration from "${node_path.default.relative(process.cwd(), configPath)}"...`);
|
|
42
|
+
const root = (await (0, _styleframe_loader.loadConfiguration)({ entry: configPath })).root;
|
|
43
|
+
consola.default.info("Building DTCG document...");
|
|
44
|
+
const { tokens, resolver, diagnostics, emittedCount, fluidNormalisedCount, maxViewport } = require_build_dtcg.buildDTCG(root, {
|
|
45
|
+
collectionName: args.collection,
|
|
46
|
+
tokensSourceRef: "tokens.json"
|
|
47
|
+
});
|
|
48
|
+
await (0, node_fs_promises.mkdir)(outputDir, { recursive: true });
|
|
49
|
+
const tokensPath = node_path.default.join(outputDir, "tokens.json");
|
|
50
|
+
await (0, node_fs_promises.writeFile)(tokensPath, `${JSON.stringify(tokens, null, 2)}\n`);
|
|
51
|
+
consola.default.info(`Wrote ${emittedCount} tokens to "${node_path.default.relative(process.cwd(), tokensPath)}"`);
|
|
52
|
+
if (fluidNormalisedCount > 0) consola.default.info(`Normalised ${fluidNormalisedCount} fluid token(s) using max viewport (${maxViewport}px).`);
|
|
53
|
+
if (resolver) {
|
|
54
|
+
const resolverPath = node_path.default.join(outputDir, "tokens.resolver.json");
|
|
55
|
+
await (0, node_fs_promises.writeFile)(resolverPath, `${JSON.stringify(resolver, null, 2)}\n`);
|
|
56
|
+
consola.default.info(`Wrote resolver to "${node_path.default.relative(process.cwd(), resolverPath)}"`);
|
|
57
|
+
}
|
|
58
|
+
const warnings = diagnostics.filter((d) => d.level === "warn");
|
|
59
|
+
if (warnings.length > 0) {
|
|
60
|
+
consola.default.warn(`${warnings.length} variable(s) needed special handling — see Styleframe ↔ DTCG round-trip notes`);
|
|
61
|
+
for (const w of warnings.slice(0, 10)) consola.default.info(` - ${w.name}: ${w.reason}`);
|
|
62
|
+
if (warnings.length > 10) consola.default.info(` ... and ${warnings.length - 10} more`);
|
|
63
|
+
consola.default.info("Tip: untyped tokens are usually CSS keywords (e.g. \"normal\", \"thin\", \"italic\") with no DTCG equivalent — they round-trip to Figma as STRING variables.");
|
|
64
|
+
}
|
|
65
|
+
consola.default.success(`Exported ${emittedCount} tokens in DTCG format to "${node_path.default.relative(process.cwd(), outputDir)}"`);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
//#endregion
|
|
69
|
+
exports.default = export_default;
|