@pixerate/editor 0.24.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -1
- package/THIRD_PARTY_NOTICES.md +29 -0
- package/dist/agent/index.cjs +10 -9
- package/dist/agent/index.cjs.map +1 -1
- package/dist/agent/index.d.cts +1 -1
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.js +4 -3
- package/dist/agent/index.js.map +1 -1
- package/dist/canvas/index.cjs +3173 -340
- package/dist/canvas/index.cjs.map +1 -1
- package/dist/canvas/index.d.cts +617 -4
- package/dist/canvas/index.d.ts +617 -4
- package/dist/canvas/index.js +3105 -272
- package/dist/canvas/index.js.map +1 -1
- package/dist/chunk-4BVP64JJ.cjs +1406 -0
- package/dist/chunk-4BVP64JJ.cjs.map +1 -0
- package/dist/{chunk-XNORY7M6.cjs → chunk-7WISYZFO.cjs} +105 -50
- package/dist/chunk-7WISYZFO.cjs.map +1 -0
- package/dist/{chunk-OLZJXL4R.cjs → chunk-AL6JMGWW.cjs} +59 -25
- package/dist/chunk-AL6JMGWW.cjs.map +1 -0
- package/dist/chunk-BVP3TSLH.cjs +69 -0
- package/dist/chunk-BVP3TSLH.cjs.map +1 -0
- package/dist/{chunk-MCSJFWAO.cjs → chunk-C7P22VIP.cjs} +670 -96
- package/dist/chunk-C7P22VIP.cjs.map +1 -0
- package/dist/{chunk-PGNZKFQS.js → chunk-ECCCYKGL.js} +76 -21
- package/dist/chunk-ECCCYKGL.js.map +1 -0
- package/dist/{chunk-3CN2WD3X.js → chunk-FH6F67DN.js} +646 -72
- package/dist/chunk-FH6F67DN.js.map +1 -0
- package/dist/chunk-HRMEDT2L.js +1406 -0
- package/dist/chunk-HRMEDT2L.js.map +1 -0
- package/dist/{chunk-ITBSKI26.js → chunk-IXHSYOVY.js} +941 -9
- package/dist/chunk-IXHSYOVY.js.map +1 -0
- package/dist/{chunk-FODNLX5N.js → chunk-NAXVVS5I.js} +38 -4
- package/dist/chunk-NAXVVS5I.js.map +1 -0
- package/dist/chunk-O5RYH2PG.js +69 -0
- package/dist/chunk-O5RYH2PG.js.map +1 -0
- package/dist/{chunk-SBCZ6RN5.cjs → chunk-PO6A6QQH.cjs} +1039 -107
- package/dist/chunk-PO6A6QQH.cjs.map +1 -0
- package/dist/{chunk-3LV6RRPH.js → chunk-QGYDWPRM.js} +2 -2
- package/dist/{chunk-U5KWZU4X.js → chunk-RR7F5GUM.js} +2632 -129
- package/dist/chunk-RR7F5GUM.js.map +1 -0
- package/dist/{chunk-5S3Z4PPF.js → chunk-UAKDG62Z.js} +232 -25
- package/dist/chunk-UAKDG62Z.js.map +1 -0
- package/dist/{chunk-SML64VJG.cjs → chunk-V3CHHWOE.cjs} +4 -4
- package/dist/{chunk-SML64VJG.cjs.map → chunk-V3CHHWOE.cjs.map} +1 -1
- package/dist/chunk-WSQKHXW7.cjs +5726 -0
- package/dist/chunk-WSQKHXW7.cjs.map +1 -0
- package/dist/{chunk-D27YFC46.cjs → chunk-X4N4WUKB.cjs} +267 -60
- package/dist/chunk-X4N4WUKB.cjs.map +1 -0
- package/dist/commands/index.cjs +74 -1
- package/dist/commands/index.cjs.map +1 -1
- package/dist/commands/index.d.cts +34 -1
- package/dist/commands/index.d.ts +34 -1
- package/dist/commands/index.js +73 -0
- package/dist/commands/index.js.map +1 -1
- package/dist/compare/index.cjs +3 -3
- package/dist/compare/index.d.cts +1 -1
- package/dist/compare/index.d.ts +1 -1
- package/dist/compare/index.js +2 -2
- package/dist/controller-BIJiNoVs.d.cts +1842 -0
- package/dist/controller-BIJiNoVs.d.ts +1842 -0
- package/dist/{documents-BQjzJNe2.d.ts → documents-CHT1U5Vs.d.ts} +10 -0
- package/dist/{documents-KRTPhvst.d.cts → documents-Gp7wb0Me.d.cts} +10 -0
- package/dist/extensions/index.cjs +53 -6
- package/dist/extensions/index.cjs.map +1 -1
- package/dist/extensions/index.d.cts +12 -4
- package/dist/extensions/index.d.ts +12 -4
- package/dist/extensions/index.js +53 -6
- package/dist/generation/index.cjs +1013 -69
- package/dist/generation/index.cjs.map +1 -1
- package/dist/generation/index.d.cts +474 -13
- package/dist/generation/index.d.ts +474 -13
- package/dist/generation/index.js +976 -32
- package/dist/generation/index.js.map +1 -1
- package/dist/image-editor/index.cjs +3385 -1275
- package/dist/image-editor/index.cjs.map +1 -1
- package/dist/image-editor/index.d.cts +693 -128
- package/dist/image-editor/index.d.ts +693 -128
- package/dist/image-editor/index.js +3325 -1215
- package/dist/image-editor/index.js.map +1 -1
- package/dist/{index-fJrlkJCd.d.ts → index-7a6bHTLy.d.ts} +494 -5
- package/dist/{index-BhJBSm2d.d.cts → index-Csd5qI8u.d.cts} +494 -5
- package/dist/index.cjs +1491 -45
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +110 -19
- package/dist/index.d.ts +110 -19
- package/dist/index.js +1464 -18
- package/dist/index.js.map +1 -1
- package/dist/mention-text-CDnCFd3c.d.cts +53 -0
- package/dist/mention-text-CDnCFd3c.d.ts +53 -0
- package/dist/model-C1zApQM8.d.cts +219 -0
- package/dist/model-C1zApQM8.d.ts +219 -0
- package/dist/persistence/index.d.cts +3 -120
- package/dist/persistence/index.d.ts +3 -120
- package/dist/{registry-GJI4gToU.d.cts → registry-CEgwXED1.d.cts} +12 -1
- package/dist/{registry-GJI4gToU.d.ts → registry-CEgwXED1.d.ts} +12 -1
- package/dist/serializers/index.cjs +12 -4
- package/dist/serializers/index.cjs.map +1 -1
- package/dist/serializers/index.d.cts +39 -12
- package/dist/serializers/index.d.ts +39 -12
- package/dist/serializers/index.js +12 -4
- package/dist/spreadsheet/index.cjs +127 -3
- package/dist/spreadsheet/index.cjs.map +1 -1
- package/dist/spreadsheet/index.d.cts +431 -11
- package/dist/spreadsheet/index.d.ts +431 -11
- package/dist/spreadsheet/index.js +127 -3
- package/dist/storage-BpFfspHm.d.cts +120 -0
- package/dist/storage-BpFfspHm.d.ts +120 -0
- package/dist/tokens/index.cjs +115 -0
- package/dist/tokens/index.cjs.map +1 -0
- package/dist/tokens/index.d.cts +212 -0
- package/dist/tokens/index.d.ts +212 -0
- package/dist/tokens/index.js +115 -0
- package/dist/tokens/index.js.map +1 -0
- package/dist/{track-changes-BK5sVf4_.d.cts → track-changes-D_VAPELi.d.cts} +95 -11
- package/dist/{track-changes-CDjCrwKe.d.ts → track-changes-Db_fGEvx.d.ts} +95 -11
- package/package.json +6 -1
- package/dist/chunk-3CN2WD3X.js.map +0 -1
- package/dist/chunk-5S3Z4PPF.js.map +0 -1
- package/dist/chunk-D27YFC46.cjs.map +0 -1
- package/dist/chunk-FODNLX5N.js.map +0 -1
- package/dist/chunk-ITBSKI26.js.map +0 -1
- package/dist/chunk-MA2F5KHF.cjs +0 -3223
- package/dist/chunk-MA2F5KHF.cjs.map +0 -1
- package/dist/chunk-MCSJFWAO.cjs.map +0 -1
- package/dist/chunk-OLZJXL4R.cjs.map +0 -1
- package/dist/chunk-PGNZKFQS.js.map +0 -1
- package/dist/chunk-SBCZ6RN5.cjs.map +0 -1
- package/dist/chunk-U5KWZU4X.js.map +0 -1
- package/dist/chunk-XNORY7M6.cjs.map +0 -1
- package/dist/controller-BhLLAoi8.d.cts +0 -1000
- package/dist/controller-BhLLAoi8.d.ts +0 -1000
- /package/dist/{chunk-3LV6RRPH.js.map → chunk-QGYDWPRM.js.map} +0 -0
|
@@ -0,0 +1,1406 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;// src/tokens/types.ts
|
|
2
|
+
var TOKEN_TYPES = ["color", "number", "string", "boolean"];
|
|
3
|
+
var TokenError = class extends Error {
|
|
4
|
+
|
|
5
|
+
constructor(code, message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "TokenError";
|
|
8
|
+
this.code = code;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
function isTokenAlias(value) {
|
|
12
|
+
return typeof value === "object" && value !== null && typeof value.alias === "string";
|
|
13
|
+
}
|
|
14
|
+
var EMPTY_TOKEN_STATE = Object.freeze({ collections: Object.freeze([]), variables: Object.freeze([]) });
|
|
15
|
+
|
|
16
|
+
// src/tokens/color.ts
|
|
17
|
+
var HEX = /^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
18
|
+
var RGB = /^rgba?\(([^()]*)\)$/i;
|
|
19
|
+
var clamp01 = (v) => Math.min(1, Math.max(0, v));
|
|
20
|
+
var byte = (v) => Math.round(clamp01(v) * 255);
|
|
21
|
+
var hex2 = (n) => n.toString(16).padStart(2, "0");
|
|
22
|
+
function rgbaToHex(r, g, b, a = 1) {
|
|
23
|
+
const head = `#${hex2(byte(r))}${hex2(byte(g))}${hex2(byte(b))}`;
|
|
24
|
+
const alpha = byte(a);
|
|
25
|
+
return alpha === 255 ? head : head + hex2(alpha);
|
|
26
|
+
}
|
|
27
|
+
function hexToRgba(hex) {
|
|
28
|
+
const normal = normalizeTokenColor(hex);
|
|
29
|
+
if (normal === null) return null;
|
|
30
|
+
const n = (i) => parseInt(normal.slice(i, i + 2), 16) / 255;
|
|
31
|
+
return { r: n(1), g: n(3), b: n(5), a: normal.length === 9 ? n(7) : 1 };
|
|
32
|
+
}
|
|
33
|
+
function channel(part, scale) {
|
|
34
|
+
const pct = part.endsWith("%");
|
|
35
|
+
const n = Number(pct ? part.slice(0, -1) : part);
|
|
36
|
+
if (!Number.isFinite(n)) return null;
|
|
37
|
+
return pct ? n / 100 : n / scale;
|
|
38
|
+
}
|
|
39
|
+
function normalizeTokenColor(input) {
|
|
40
|
+
if (typeof input === "string") {
|
|
41
|
+
const text = input.trim();
|
|
42
|
+
if (text.length > 200) return null;
|
|
43
|
+
const lower = text.toLowerCase();
|
|
44
|
+
if (lower === "transparent") return "#00000000";
|
|
45
|
+
if (lower === "black") return "#000000";
|
|
46
|
+
if (lower === "white") return "#ffffff";
|
|
47
|
+
const hex = HEX.exec(text);
|
|
48
|
+
if (hex) {
|
|
49
|
+
let digits = hex[1].toLowerCase();
|
|
50
|
+
if (digits.length <= 4) digits = [...digits].map((c) => c + c).join("");
|
|
51
|
+
if (digits.length === 8 && digits.endsWith("ff")) digits = digits.slice(0, 6);
|
|
52
|
+
return `#${digits}`;
|
|
53
|
+
}
|
|
54
|
+
const rgb = RGB.exec(text);
|
|
55
|
+
if (rgb) {
|
|
56
|
+
const [colour, alphaPart] = rgb[1].split("/");
|
|
57
|
+
const parts = colour.split(/[\s,]+/).filter(Boolean);
|
|
58
|
+
let alpha = _optionalChain([alphaPart, 'optionalAccess', _ => _.trim, 'call', _2 => _2()]);
|
|
59
|
+
if (parts.length === 4 && alpha === void 0) alpha = parts.pop();
|
|
60
|
+
if (parts.length !== 3) return null;
|
|
61
|
+
const channels = parts.map((p) => channel(p, 255));
|
|
62
|
+
const a = alpha === void 0 || alpha === "" ? 1 : channel(alpha, 1);
|
|
63
|
+
if (channels.some((c) => c === null) || a === null) return null;
|
|
64
|
+
return rgbaToHex(channels[0], channels[1], channels[2], a);
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
if (typeof input === "object" && input !== null) {
|
|
69
|
+
const obj = input;
|
|
70
|
+
if (Array.isArray(obj.components)) {
|
|
71
|
+
const space = obj.colorSpace;
|
|
72
|
+
if (space === void 0 || space === "srgb") {
|
|
73
|
+
const [r2, g2, b2] = obj.components;
|
|
74
|
+
const a2 = obj.alpha === void 0 ? 1 : obj.alpha;
|
|
75
|
+
if ([r2, g2, b2, a2].every((v) => typeof v === "number" && Number.isFinite(v))) {
|
|
76
|
+
return rgbaToHex(r2, g2, b2, a2);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (typeof obj.hex === "string") {
|
|
80
|
+
const base = normalizeTokenColor(obj.hex);
|
|
81
|
+
if (base === null) return null;
|
|
82
|
+
const a2 = typeof obj.alpha === "number" ? obj.alpha : 1;
|
|
83
|
+
const c = hexToRgba(base);
|
|
84
|
+
return rgbaToHex(c.r, c.g, c.b, a2);
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
const { r, g, b } = obj;
|
|
89
|
+
const a = obj.a === void 0 ? 1 : obj.a;
|
|
90
|
+
if ([r, g, b, a].every((v) => typeof v === "number" && Number.isFinite(v))) {
|
|
91
|
+
return rgbaToHex(r, g, b, a);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// src/tokens/model.ts
|
|
98
|
+
var indexes = /* @__PURE__ */ new WeakMap();
|
|
99
|
+
function indexOf(state) {
|
|
100
|
+
let index = indexes.get(state);
|
|
101
|
+
if (!index) {
|
|
102
|
+
index = {
|
|
103
|
+
collections: new Map(state.collections.map((c) => [c.id, c])),
|
|
104
|
+
variables: new Map(state.variables.map((v) => [v.id, v]))
|
|
105
|
+
};
|
|
106
|
+
indexes.set(state, index);
|
|
107
|
+
}
|
|
108
|
+
return index;
|
|
109
|
+
}
|
|
110
|
+
function getTokenCollection(state, id) {
|
|
111
|
+
return indexOf(state).collections.get(id);
|
|
112
|
+
}
|
|
113
|
+
function getTokenVariable(state, id) {
|
|
114
|
+
return indexOf(state).variables.get(id);
|
|
115
|
+
}
|
|
116
|
+
function findTokenCollection(state, name) {
|
|
117
|
+
return state.collections.find((c) => c.name === name);
|
|
118
|
+
}
|
|
119
|
+
function findTokenVariable(state, name, collectionId) {
|
|
120
|
+
return state.variables.find((v) => v.name === name && (collectionId === void 0 || v.collectionId === collectionId));
|
|
121
|
+
}
|
|
122
|
+
function getCollectionVariables(state, collectionId) {
|
|
123
|
+
return state.variables.filter((v) => v.collectionId === collectionId);
|
|
124
|
+
}
|
|
125
|
+
function getDefaultMode(collection) {
|
|
126
|
+
return collection.modes[0];
|
|
127
|
+
}
|
|
128
|
+
function findTokenMode(collection, key) {
|
|
129
|
+
return _nullishCoalesce(collection.modes.find((m) => m.id === key), () => ( collection.modes.find((m) => m.name === key)));
|
|
130
|
+
}
|
|
131
|
+
function getCurrentMode(collection, modes) {
|
|
132
|
+
const chosen = _optionalChain([modes, 'optionalAccess', _3 => _3[collection.id]]);
|
|
133
|
+
return chosen !== void 0 && collection.modes.find((m) => m.id === chosen) || collection.modes[0];
|
|
134
|
+
}
|
|
135
|
+
function defaultTokenValue(type) {
|
|
136
|
+
switch (type) {
|
|
137
|
+
case "color":
|
|
138
|
+
return "#000000";
|
|
139
|
+
case "number":
|
|
140
|
+
return 0;
|
|
141
|
+
case "string":
|
|
142
|
+
return "";
|
|
143
|
+
case "boolean":
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function coerceTokenLiteral(type, value) {
|
|
148
|
+
switch (type) {
|
|
149
|
+
case "color":
|
|
150
|
+
return normalizeTokenColor(value);
|
|
151
|
+
case "number": {
|
|
152
|
+
if (typeof value === "number") return Number.isFinite(value) ? value : null;
|
|
153
|
+
if (typeof value === "string" && value.trim() !== "") {
|
|
154
|
+
const n = Number(value);
|
|
155
|
+
return Number.isFinite(n) ? n : null;
|
|
156
|
+
}
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
case "string":
|
|
160
|
+
return typeof value === "string" ? value : null;
|
|
161
|
+
case "boolean":
|
|
162
|
+
if (typeof value === "boolean") return value;
|
|
163
|
+
if (value === "true") return true;
|
|
164
|
+
if (value === "false") return false;
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function literalTokenType(value) {
|
|
169
|
+
return typeof value === "number" ? "number" : typeof value === "boolean" ? "boolean" : "string";
|
|
170
|
+
}
|
|
171
|
+
function formatTokenValue(state, value) {
|
|
172
|
+
if (value === void 0) return "";
|
|
173
|
+
if (isTokenAlias(value)) return `\u2192 ${_nullishCoalesce(_optionalChain([getTokenVariable, 'call', _4 => _4(state, value.alias), 'optionalAccess', _5 => _5.name]), () => ( value.alias))}`;
|
|
174
|
+
return String(value);
|
|
175
|
+
}
|
|
176
|
+
function label(state, id) {
|
|
177
|
+
const v = getTokenVariable(state, id);
|
|
178
|
+
return v ? `\`${v.name}\`` : `\`${id}\``;
|
|
179
|
+
}
|
|
180
|
+
function resolveToken(state, id, modes) {
|
|
181
|
+
const chain = [];
|
|
182
|
+
const seen = /* @__PURE__ */ new Set();
|
|
183
|
+
let current = id;
|
|
184
|
+
let type;
|
|
185
|
+
for (; ; ) {
|
|
186
|
+
if (seen.has(current)) {
|
|
187
|
+
chain.push(current);
|
|
188
|
+
return {
|
|
189
|
+
ok: false,
|
|
190
|
+
code: "cycle",
|
|
191
|
+
message: `Alias cycle: ${chain.map((c) => label(state, c)).join(" \u2192 ")}`,
|
|
192
|
+
chain
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
seen.add(current);
|
|
196
|
+
chain.push(current);
|
|
197
|
+
const variable = getTokenVariable(state, current);
|
|
198
|
+
if (!variable) {
|
|
199
|
+
return {
|
|
200
|
+
ok: false,
|
|
201
|
+
code: "missing",
|
|
202
|
+
message: chain.length === 1 ? `No variable ${label(state, current)}` : `${label(state, chain[chain.length - 2])} aliases a missing variable ${label(state, current)}`,
|
|
203
|
+
chain
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
if (type !== void 0 && variable.type !== type) {
|
|
207
|
+
return {
|
|
208
|
+
ok: false,
|
|
209
|
+
code: "type-mismatch",
|
|
210
|
+
message: `${label(state, chain[chain.length - 2])} (${type}) aliases ${label(state, current)} (${variable.type})`,
|
|
211
|
+
chain
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
type = variable.type;
|
|
215
|
+
const collection = getTokenCollection(state, variable.collectionId);
|
|
216
|
+
const mode = collection ? getCurrentMode(collection, modes) : void 0;
|
|
217
|
+
let modeId = _optionalChain([mode, 'optionalAccess', _6 => _6.id]);
|
|
218
|
+
let value = modeId !== void 0 ? variable.valuesByMode[modeId] : void 0;
|
|
219
|
+
if (value === void 0) {
|
|
220
|
+
const fallback = _optionalChain([collection, 'optionalAccess', _7 => _7.modes, 'access', _8 => _8[0], 'optionalAccess', _9 => _9.id]);
|
|
221
|
+
if (fallback !== void 0 && variable.valuesByMode[fallback] !== void 0) {
|
|
222
|
+
modeId = fallback;
|
|
223
|
+
value = variable.valuesByMode[fallback];
|
|
224
|
+
} else {
|
|
225
|
+
const first = Object.keys(variable.valuesByMode)[0];
|
|
226
|
+
if (first !== void 0) {
|
|
227
|
+
modeId = first;
|
|
228
|
+
value = variable.valuesByMode[first];
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (value === void 0 || modeId === void 0) {
|
|
233
|
+
return { ok: false, code: "no-value", message: `${label(state, current)} has no value`, chain };
|
|
234
|
+
}
|
|
235
|
+
if (isTokenAlias(value)) {
|
|
236
|
+
current = value.alias;
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
return { ok: true, value, type: variable.type, variable, modeId, chain };
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function resolveTokenValue(state, id, modes) {
|
|
243
|
+
const result = resolveToken(state, id, modes);
|
|
244
|
+
return result.ok ? result.value : void 0;
|
|
245
|
+
}
|
|
246
|
+
function resolveTokenInMode(state, variableId, modeId) {
|
|
247
|
+
const variable = getTokenVariable(state, variableId);
|
|
248
|
+
if (!variable) return void 0;
|
|
249
|
+
return resolveTokenValue(state, variableId, { [variable.collectionId]: modeId });
|
|
250
|
+
}
|
|
251
|
+
function checkTokenAlias(state, variable, targetId) {
|
|
252
|
+
const target = getTokenVariable(state, targetId);
|
|
253
|
+
if (!target) return new TokenError("alias-missing", `No variable \`${targetId}\` to alias`);
|
|
254
|
+
if (target.type !== variable.type) {
|
|
255
|
+
return new TokenError("type-mismatch", `Can't alias a ${variable.type} variable to a ${target.type} one (\`${target.name}\`)`);
|
|
256
|
+
}
|
|
257
|
+
const parent = /* @__PURE__ */ new Map([[target.id, null]]);
|
|
258
|
+
const stack = [target.id];
|
|
259
|
+
while (stack.length > 0) {
|
|
260
|
+
const current = stack.pop();
|
|
261
|
+
if (current === variable.id) {
|
|
262
|
+
const path2 = [];
|
|
263
|
+
for (let at = current; at != null; at = parent.get(at)) path2.push(at);
|
|
264
|
+
const names = [variable.id, ...path2.reverse()].map((id) => id === variable.id ? `\`${variable.name}\`` : label(state, id));
|
|
265
|
+
return new TokenError("alias-cycle", `The alias would create a cycle: ${names.join(" \u2192 ")}`);
|
|
266
|
+
}
|
|
267
|
+
const v = getTokenVariable(state, current);
|
|
268
|
+
if (!v) continue;
|
|
269
|
+
for (const value of Object.values(v.valuesByMode)) {
|
|
270
|
+
if (isTokenAlias(value) && !parent.has(value.alias)) {
|
|
271
|
+
parent.set(value.alias, current);
|
|
272
|
+
stack.push(value.alias);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
var TOKEN_SCOPES_BY_TYPE = {
|
|
279
|
+
number: [
|
|
280
|
+
"CORNER_RADIUS",
|
|
281
|
+
"WIDTH_HEIGHT",
|
|
282
|
+
"GAP",
|
|
283
|
+
"OPACITY",
|
|
284
|
+
"STROKE_FLOAT",
|
|
285
|
+
"EFFECT_FLOAT",
|
|
286
|
+
"FONT_WEIGHT",
|
|
287
|
+
"FONT_SIZE",
|
|
288
|
+
"LINE_HEIGHT",
|
|
289
|
+
"LETTER_SPACING",
|
|
290
|
+
"PARAGRAPH_SPACING",
|
|
291
|
+
"PARAGRAPH_INDENT",
|
|
292
|
+
"TEXT_CONTENT"
|
|
293
|
+
],
|
|
294
|
+
color: ["FRAME_FILL", "SHAPE_FILL", "TEXT_FILL", "STROKE_COLOR", "EFFECT_COLOR"],
|
|
295
|
+
string: ["TEXT_CONTENT", "FONT_FAMILY", "FONT_STYLE"],
|
|
296
|
+
boolean: []
|
|
297
|
+
};
|
|
298
|
+
function isTokenScopeKnown(type, scope) {
|
|
299
|
+
return scope === "ALL_SCOPES" || scope === "ALL_FILLS" && type === "color" || TOKEN_SCOPES_BY_TYPE[type].includes(scope);
|
|
300
|
+
}
|
|
301
|
+
function normalizeTokenScopes(type, scopes) {
|
|
302
|
+
if (scopes == null) return void 0;
|
|
303
|
+
const list = [];
|
|
304
|
+
for (const scope of scopes) {
|
|
305
|
+
if (!isTokenScopeKnown(type, scope)) throw new TokenError("unknown-scope", `Unknown ${type} scope \`${scope}\``);
|
|
306
|
+
if (!list.includes(scope)) list.push(scope);
|
|
307
|
+
}
|
|
308
|
+
const allowed = TOKEN_SCOPES_BY_TYPE[type];
|
|
309
|
+
const all = list.includes("ALL_SCOPES") || allowed.length > 0 && allowed.every((s) => list.includes(s));
|
|
310
|
+
return all ? void 0 : list;
|
|
311
|
+
}
|
|
312
|
+
function isTokenInScope(variable, scope) {
|
|
313
|
+
if (!variable.scopes || scope === void 0) return true;
|
|
314
|
+
return variable.scopes.some((s) => s === scope || s === "ALL_SCOPES" || s === "ALL_FILLS" && scope.endsWith("_FILL"));
|
|
315
|
+
}
|
|
316
|
+
var BAD_NAME_CHARS = /[{}.]/;
|
|
317
|
+
function normalizeTokenName(name, what = "Variable") {
|
|
318
|
+
if (typeof name !== "string") throw new TokenError("invalid-name", `${what} name must be a string`);
|
|
319
|
+
const segments = name.split("/").map((s) => s.trim());
|
|
320
|
+
if (name.length > 500 || segments.some((s) => s === "")) {
|
|
321
|
+
throw new TokenError("invalid-name", `${what} name \`${name}\` has an empty group`);
|
|
322
|
+
}
|
|
323
|
+
for (const segment of segments) {
|
|
324
|
+
if (BAD_NAME_CHARS.test(segment) || segment.startsWith("$")) {
|
|
325
|
+
throw new TokenError("invalid-name", `${what} name \`${name}\` can't contain \`{\`, \`}\` or \`.\`, or start a group with \`$\``);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return segments.join("/");
|
|
329
|
+
}
|
|
330
|
+
function normalizeModeName(name) {
|
|
331
|
+
if (typeof name !== "string" || name.trim() === "") throw new TokenError("invalid-name", "Mode name can't be empty");
|
|
332
|
+
return name.trim().slice(0, 200);
|
|
333
|
+
}
|
|
334
|
+
function checkVariableName(state, collectionId, name, exceptId) {
|
|
335
|
+
for (const other of state.variables) {
|
|
336
|
+
if (other.collectionId !== collectionId || other.id === exceptId) continue;
|
|
337
|
+
if (other.name === name) throw new TokenError("duplicate-name", `A variable named \`${name}\` already exists in this collection`);
|
|
338
|
+
if (other.name.startsWith(name + "/") || name.startsWith(other.name + "/")) {
|
|
339
|
+
throw new TokenError("name-conflict", `\`${name}\` clashes with \`${other.name}\`: a name can't be both a variable and a group`);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
var fallbackCounter = 0;
|
|
344
|
+
var defaultTokenId = (kind) => {
|
|
345
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") return `${kind}-${crypto.randomUUID()}`;
|
|
346
|
+
fallbackCounter += 1;
|
|
347
|
+
return `${kind}-${Date.now().toString(36)}-${fallbackCounter}`;
|
|
348
|
+
};
|
|
349
|
+
function requireCollection(state, id) {
|
|
350
|
+
const c = getTokenCollection(state, id);
|
|
351
|
+
if (!c) throw new TokenError("not-found", `No collection \`${id}\``);
|
|
352
|
+
return c;
|
|
353
|
+
}
|
|
354
|
+
function requireVariable(state, id) {
|
|
355
|
+
const v = getTokenVariable(state, id);
|
|
356
|
+
if (!v) throw new TokenError("not-found", `No variable \`${id}\``);
|
|
357
|
+
return v;
|
|
358
|
+
}
|
|
359
|
+
function requireMode(collection, key) {
|
|
360
|
+
const m = findTokenMode(collection, key);
|
|
361
|
+
if (!m) throw new TokenError("not-found", `No mode \`${key}\` in \`${collection.name}\``);
|
|
362
|
+
return m;
|
|
363
|
+
}
|
|
364
|
+
function replaceCollection(state, next) {
|
|
365
|
+
return { ...state, collections: state.collections.map((c) => c.id === next.id ? next : c) };
|
|
366
|
+
}
|
|
367
|
+
function replaceVariable(state, next) {
|
|
368
|
+
return { ...state, variables: state.variables.map((v) => v.id === next.id ? next : v) };
|
|
369
|
+
}
|
|
370
|
+
function createTokenCollection(state, input, createId = defaultTokenId) {
|
|
371
|
+
const name = normalizeTokenName(input.name, "Collection");
|
|
372
|
+
if (state.collections.some((c) => c.name === name)) {
|
|
373
|
+
throw new TokenError("duplicate-name", `A collection named \`${name}\` already exists`);
|
|
374
|
+
}
|
|
375
|
+
const modeNames = input.modes && input.modes.length > 0 ? input.modes.map(normalizeModeName) : ["Default"];
|
|
376
|
+
const collection = {
|
|
377
|
+
id: createId("collection"),
|
|
378
|
+
name,
|
|
379
|
+
modes: modeNames.map((n) => ({ id: createId("mode"), name: n }))
|
|
380
|
+
};
|
|
381
|
+
return { state: { ...state, collections: [...state.collections, collection] }, collection };
|
|
382
|
+
}
|
|
383
|
+
function renameTokenCollection(state, id, name) {
|
|
384
|
+
const collection = requireCollection(state, id);
|
|
385
|
+
const next = normalizeTokenName(name, "Collection");
|
|
386
|
+
if (state.collections.some((c) => c.id !== id && c.name === next)) {
|
|
387
|
+
throw new TokenError("duplicate-name", `A collection named \`${next}\` already exists`);
|
|
388
|
+
}
|
|
389
|
+
return replaceCollection(state, { ...collection, name: next });
|
|
390
|
+
}
|
|
391
|
+
function deleteTokenVariables(state, ids) {
|
|
392
|
+
const gone = /* @__PURE__ */ new Set();
|
|
393
|
+
for (const id of ids) if (getTokenVariable(state, id)) gone.add(id);
|
|
394
|
+
if (gone.size === 0) return { state, deleted: [] };
|
|
395
|
+
const variables = [];
|
|
396
|
+
for (const v of state.variables) {
|
|
397
|
+
if (gone.has(v.id)) continue;
|
|
398
|
+
let values = null;
|
|
399
|
+
for (const [modeId, value] of Object.entries(v.valuesByMode)) {
|
|
400
|
+
if (!isTokenAlias(value) || !gone.has(value.alias)) continue;
|
|
401
|
+
const target = getTokenVariable(state, value.alias);
|
|
402
|
+
const resolved = resolveTokenValue(state, target.id, { [target.collectionId]: modeId, [v.collectionId]: modeId });
|
|
403
|
+
values ??= { ...v.valuesByMode };
|
|
404
|
+
values[modeId] = _nullishCoalesce(resolved, () => ( defaultTokenValue(v.type)));
|
|
405
|
+
}
|
|
406
|
+
variables.push(values ? { ...v, valuesByMode: values } : v);
|
|
407
|
+
}
|
|
408
|
+
return { state: { ...state, variables }, deleted: [...gone] };
|
|
409
|
+
}
|
|
410
|
+
function deleteTokenCollection(state, id) {
|
|
411
|
+
requireCollection(state, id);
|
|
412
|
+
const result = deleteTokenVariables(
|
|
413
|
+
state,
|
|
414
|
+
state.variables.filter((v) => v.collectionId === id).map((v) => v.id)
|
|
415
|
+
);
|
|
416
|
+
return { state: { ...result.state, collections: result.state.collections.filter((c) => c.id !== id) }, deleted: result.deleted };
|
|
417
|
+
}
|
|
418
|
+
function addTokenMode(state, collectionId, name, options = {}, createId = defaultTokenId) {
|
|
419
|
+
const collection = requireCollection(state, collectionId);
|
|
420
|
+
const modeName = normalizeModeName(name);
|
|
421
|
+
if (collection.modes.some((m) => m.name === modeName)) {
|
|
422
|
+
throw new TokenError("duplicate-name", `\`${collection.name}\` already has a mode named \`${modeName}\``);
|
|
423
|
+
}
|
|
424
|
+
const source = options.from !== void 0 ? requireMode(collection, options.from) : collection.modes[0];
|
|
425
|
+
const mode = { id: createId("mode"), name: modeName };
|
|
426
|
+
let next = replaceCollection(state, { ...collection, modes: [...collection.modes, mode] });
|
|
427
|
+
next = {
|
|
428
|
+
...next,
|
|
429
|
+
variables: next.variables.map((v) => {
|
|
430
|
+
if (v.collectionId !== collectionId) return v;
|
|
431
|
+
const value = _nullishCoalesce(v.valuesByMode[source.id], () => ( defaultTokenValue(v.type)));
|
|
432
|
+
return { ...v, valuesByMode: { ...v.valuesByMode, [mode.id]: value } };
|
|
433
|
+
})
|
|
434
|
+
};
|
|
435
|
+
return { state: next, mode };
|
|
436
|
+
}
|
|
437
|
+
function renameTokenMode(state, collectionId, modeId, name) {
|
|
438
|
+
const collection = requireCollection(state, collectionId);
|
|
439
|
+
const mode = requireMode(collection, modeId);
|
|
440
|
+
const modeName = normalizeModeName(name);
|
|
441
|
+
if (collection.modes.some((m) => m.id !== mode.id && m.name === modeName)) {
|
|
442
|
+
throw new TokenError("duplicate-name", `\`${collection.name}\` already has a mode named \`${modeName}\``);
|
|
443
|
+
}
|
|
444
|
+
return replaceCollection(state, { ...collection, modes: collection.modes.map((m) => m.id === mode.id ? { ...m, name: modeName } : m) });
|
|
445
|
+
}
|
|
446
|
+
function removeTokenMode(state, collectionId, modeId) {
|
|
447
|
+
const collection = requireCollection(state, collectionId);
|
|
448
|
+
const mode = requireMode(collection, modeId);
|
|
449
|
+
if (collection.modes.length < 2) throw new TokenError("last-mode", "A collection keeps at least one mode");
|
|
450
|
+
const next = replaceCollection(state, { ...collection, modes: collection.modes.filter((m) => m.id !== mode.id) });
|
|
451
|
+
return {
|
|
452
|
+
...next,
|
|
453
|
+
variables: next.variables.map((v) => {
|
|
454
|
+
if (v.collectionId !== collectionId || !(mode.id in v.valuesByMode)) return v;
|
|
455
|
+
const values = { ...v.valuesByMode };
|
|
456
|
+
delete values[mode.id];
|
|
457
|
+
return { ...v, valuesByMode: values };
|
|
458
|
+
})
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
function moveTokenMode(state, collectionId, modeId, to) {
|
|
462
|
+
const collection = requireCollection(state, collectionId);
|
|
463
|
+
const mode = requireMode(collection, modeId);
|
|
464
|
+
const modes = collection.modes.filter((m) => m.id !== mode.id);
|
|
465
|
+
const at = Math.min(Math.max(Number.isFinite(to) ? Math.trunc(to) : 0, 0), modes.length);
|
|
466
|
+
modes.splice(at, 0, mode);
|
|
467
|
+
return replaceCollection(state, { ...collection, modes });
|
|
468
|
+
}
|
|
469
|
+
function prepareTokenValue(state, variable, value) {
|
|
470
|
+
if (isTokenAlias(value)) {
|
|
471
|
+
const error = checkTokenAlias(state, variable, value.alias);
|
|
472
|
+
if (error) throw error;
|
|
473
|
+
return { alias: value.alias };
|
|
474
|
+
}
|
|
475
|
+
const literal = coerceTokenLiteral(variable.type, value);
|
|
476
|
+
if (literal === null) {
|
|
477
|
+
throw new TokenError("invalid-value", `\`${String(value)}\` is not a ${variable.type} value for \`${variable.name}\``);
|
|
478
|
+
}
|
|
479
|
+
return literal;
|
|
480
|
+
}
|
|
481
|
+
function normalizeUnit(unit) {
|
|
482
|
+
if (unit === void 0 || unit === null || unit === "") return void 0;
|
|
483
|
+
if (typeof unit !== "string" || !/^[a-z%]{1,8}$/i.test(unit)) throw new TokenError("invalid-value", `Unknown unit \`${String(unit)}\``);
|
|
484
|
+
return unit.toLowerCase();
|
|
485
|
+
}
|
|
486
|
+
function createTokenVariable(state, input, createId = defaultTokenId) {
|
|
487
|
+
const collection = requireCollection(state, input.collectionId);
|
|
488
|
+
if (!["color", "number", "string", "boolean"].includes(input.type)) {
|
|
489
|
+
throw new TokenError("invalid-type", `Unknown variable type \`${String(input.type)}\``);
|
|
490
|
+
}
|
|
491
|
+
const name = normalizeTokenName(input.name);
|
|
492
|
+
checkVariableName(state, collection.id, name);
|
|
493
|
+
const id = createId("variable");
|
|
494
|
+
const stub = { id, type: input.type, name };
|
|
495
|
+
const base = input.value === void 0 ? defaultTokenValue(input.type) : prepareTokenValue(state, stub, input.value);
|
|
496
|
+
const valuesByMode = {};
|
|
497
|
+
for (const mode of collection.modes) valuesByMode[mode.id] = base;
|
|
498
|
+
if (input.values) {
|
|
499
|
+
for (const [key, raw] of Object.entries(input.values)) {
|
|
500
|
+
const mode = requireMode(collection, key);
|
|
501
|
+
valuesByMode[mode.id] = prepareTokenValue(state, stub, raw);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
const variable = {
|
|
505
|
+
id,
|
|
506
|
+
name,
|
|
507
|
+
collectionId: collection.id,
|
|
508
|
+
type: input.type,
|
|
509
|
+
valuesByMode,
|
|
510
|
+
...input.description ? { description: String(input.description) } : {},
|
|
511
|
+
...input.scopes !== void 0 ? { scopes: normalizeTokenScopes(input.type, input.scopes) } : {}
|
|
512
|
+
};
|
|
513
|
+
if (variable.scopes === void 0) delete variable.scopes;
|
|
514
|
+
const unit = normalizeUnit(input.unit);
|
|
515
|
+
if (unit) variable.unit = unit;
|
|
516
|
+
return { state: { ...state, variables: [...state.variables, variable] }, variable };
|
|
517
|
+
}
|
|
518
|
+
function setTokenValue(state, variableId, value, modeId) {
|
|
519
|
+
const variable = requireVariable(state, variableId);
|
|
520
|
+
const collection = requireCollection(state, variable.collectionId);
|
|
521
|
+
const mode = modeId === void 0 ? collection.modes[0] : requireMode(collection, modeId);
|
|
522
|
+
const prepared = prepareTokenValue(state, variable, value);
|
|
523
|
+
const current = variable.valuesByMode[mode.id];
|
|
524
|
+
if (current === prepared || isTokenAlias(current) && isTokenAlias(prepared) && current.alias === prepared.alias) return state;
|
|
525
|
+
return replaceVariable(state, { ...variable, valuesByMode: { ...variable.valuesByMode, [mode.id]: prepared } });
|
|
526
|
+
}
|
|
527
|
+
function renameTokenVariable(state, variableId, name) {
|
|
528
|
+
const variable = requireVariable(state, variableId);
|
|
529
|
+
const next = normalizeTokenName(name);
|
|
530
|
+
if (next === variable.name) return state;
|
|
531
|
+
checkVariableName(state, variable.collectionId, next, variable.id);
|
|
532
|
+
return replaceVariable(state, { ...variable, name: next });
|
|
533
|
+
}
|
|
534
|
+
function updateTokenVariable(state, variableId, input) {
|
|
535
|
+
const variable = requireVariable(state, variableId);
|
|
536
|
+
const next = { ...variable };
|
|
537
|
+
if (input.description !== void 0) {
|
|
538
|
+
if (input.description) next.description = String(input.description);
|
|
539
|
+
else delete next.description;
|
|
540
|
+
}
|
|
541
|
+
if (input.scopes !== void 0) {
|
|
542
|
+
const scopes = normalizeTokenScopes(variable.type, input.scopes);
|
|
543
|
+
if (scopes) next.scopes = scopes;
|
|
544
|
+
else delete next.scopes;
|
|
545
|
+
}
|
|
546
|
+
if (input.unit !== void 0) {
|
|
547
|
+
const unit = normalizeUnit(input.unit);
|
|
548
|
+
if (unit) next.unit = unit;
|
|
549
|
+
else delete next.unit;
|
|
550
|
+
}
|
|
551
|
+
return replaceVariable(state, next);
|
|
552
|
+
}
|
|
553
|
+
function parseTokenState(input) {
|
|
554
|
+
const issues = [];
|
|
555
|
+
let raw = input;
|
|
556
|
+
if (typeof raw === "string") {
|
|
557
|
+
try {
|
|
558
|
+
raw = JSON.parse(raw);
|
|
559
|
+
} catch (e) {
|
|
560
|
+
return { state: { collections: [], variables: [] }, issues: [{ message: "Not JSON" }] };
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
const obj = typeof raw === "object" && raw !== null ? raw : {};
|
|
564
|
+
const collections = [];
|
|
565
|
+
const ids = /* @__PURE__ */ new Set();
|
|
566
|
+
for (const c of Array.isArray(obj.collections) ? obj.collections : []) {
|
|
567
|
+
const item = c;
|
|
568
|
+
const modes = Array.isArray(_optionalChain([item, 'optionalAccess', _10 => _10.modes])) ? item.modes.filter(
|
|
569
|
+
(m) => typeof m === "object" && m !== null && typeof m.id === "string" && typeof m.name === "string"
|
|
570
|
+
) : [];
|
|
571
|
+
if (!item || typeof item.id !== "string" || typeof item.name !== "string" || modes.length === 0 || ids.has(item.id)) {
|
|
572
|
+
issues.push({ message: "Dropped an invalid collection" });
|
|
573
|
+
continue;
|
|
574
|
+
}
|
|
575
|
+
ids.add(item.id);
|
|
576
|
+
collections.push({ id: item.id, name: item.name, modes: modes.map((m) => ({ id: m.id, name: m.name })) });
|
|
577
|
+
}
|
|
578
|
+
const byId = new Map(collections.map((c) => [c.id, c]));
|
|
579
|
+
const variables = [];
|
|
580
|
+
const varIds = /* @__PURE__ */ new Set();
|
|
581
|
+
for (const v of Array.isArray(obj.variables) ? obj.variables : []) {
|
|
582
|
+
const item = v;
|
|
583
|
+
const collection = item && typeof item.collectionId === "string" ? byId.get(item.collectionId) : void 0;
|
|
584
|
+
if (!item || typeof item.id !== "string" || typeof item.name !== "string" || !collection || !["color", "number", "string", "boolean"].includes(item.type) || varIds.has(item.id)) {
|
|
585
|
+
issues.push({ message: "Dropped an invalid variable", variableId: typeof _optionalChain([item, 'optionalAccess', _11 => _11.id]) === "string" ? item.id : void 0 });
|
|
586
|
+
continue;
|
|
587
|
+
}
|
|
588
|
+
varIds.add(item.id);
|
|
589
|
+
const type = item.type;
|
|
590
|
+
const values = {};
|
|
591
|
+
const rawValues = typeof item.valuesByMode === "object" && item.valuesByMode !== null ? item.valuesByMode : {};
|
|
592
|
+
for (const mode of collection.modes) {
|
|
593
|
+
const value = rawValues[mode.id];
|
|
594
|
+
if (isTokenAlias(value)) values[mode.id] = { alias: value.alias };
|
|
595
|
+
else {
|
|
596
|
+
const literal = coerceTokenLiteral(type, value);
|
|
597
|
+
if (literal === null) issues.push({ message: `\`${item.name}\` had no valid value in \`${mode.name}\``, variableId: item.id });
|
|
598
|
+
values[mode.id] = _nullishCoalesce(literal, () => ( defaultTokenValue(type)));
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
const variable = { id: item.id, name: item.name, collectionId: collection.id, type, valuesByMode: values };
|
|
602
|
+
if (typeof item.description === "string" && item.description) variable.description = item.description;
|
|
603
|
+
if (Array.isArray(item.scopes)) {
|
|
604
|
+
try {
|
|
605
|
+
const scopes = normalizeTokenScopes(type, item.scopes);
|
|
606
|
+
if (scopes) variable.scopes = scopes;
|
|
607
|
+
} catch (e2) {
|
|
608
|
+
issues.push({ message: `Dropped unknown scopes of \`${item.name}\``, variableId: item.id });
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
if (typeof item.unit === "string" && /^[a-z%]{1,8}$/i.test(item.unit)) variable.unit = item.unit.toLowerCase();
|
|
612
|
+
variables.push(variable);
|
|
613
|
+
}
|
|
614
|
+
let state = { collections, variables };
|
|
615
|
+
const fixed = state.variables.map((variable) => {
|
|
616
|
+
let values = null;
|
|
617
|
+
for (const [modeId, value] of Object.entries(variable.valuesByMode)) {
|
|
618
|
+
if (!isTokenAlias(value)) continue;
|
|
619
|
+
const target = state.variables.find((t) => t.id === value.alias);
|
|
620
|
+
if (!target || target.type !== variable.type) {
|
|
621
|
+
values ??= { ...variable.valuesByMode };
|
|
622
|
+
values[modeId] = defaultTokenValue(variable.type);
|
|
623
|
+
issues.push({ message: `\`${variable.name}\` aliased a missing or mistyped variable`, variableId: variable.id });
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
return values ? { ...variable, valuesByMode: values } : variable;
|
|
627
|
+
});
|
|
628
|
+
state = { collections, variables: fixed };
|
|
629
|
+
const literalOnly = fixed.map((variable) => {
|
|
630
|
+
const values = {};
|
|
631
|
+
for (const [modeId, value] of Object.entries(variable.valuesByMode)) values[modeId] = isTokenAlias(value) ? defaultTokenValue(variable.type) : value;
|
|
632
|
+
return { ...variable, valuesByMode: values };
|
|
633
|
+
});
|
|
634
|
+
let rebuilt = { collections, variables: literalOnly };
|
|
635
|
+
for (const variable of fixed) {
|
|
636
|
+
for (const [modeId, value] of Object.entries(variable.valuesByMode)) {
|
|
637
|
+
if (!isTokenAlias(value)) continue;
|
|
638
|
+
const error = checkTokenAlias(rebuilt, variable, value.alias);
|
|
639
|
+
if (error) {
|
|
640
|
+
issues.push({ message: `\`${variable.name}\`: ${error.message}`, variableId: variable.id });
|
|
641
|
+
continue;
|
|
642
|
+
}
|
|
643
|
+
const current = getTokenVariable(rebuilt, variable.id);
|
|
644
|
+
rebuilt = replaceVariable(rebuilt, { ...current, valuesByMode: { ...current.valuesByMode, [modeId]: { alias: value.alias } } });
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
return { state: rebuilt, issues };
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
// src/tokens/store.ts
|
|
651
|
+
var TokenStore = (_class = class {
|
|
652
|
+
|
|
653
|
+
__init() {this.undoStack = []}
|
|
654
|
+
__init2() {this.redoStack = []}
|
|
655
|
+
__init3() {this.listeners = /* @__PURE__ */ new Set()}
|
|
656
|
+
__init4() {this.pending = null}
|
|
657
|
+
__init5() {this.depth = 0}
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
constructor(options = {}) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);_class.prototype.__init5.call(this);_class.prototype.__init6.call(this);_class.prototype.__init7.call(this);
|
|
661
|
+
this.state = _nullishCoalesce(options.initialState, () => ( EMPTY_TOKEN_STATE));
|
|
662
|
+
this.createId = _nullishCoalesce(options.createId, () => ( defaultTokenId));
|
|
663
|
+
this.historyLimit = Math.max(0, _nullishCoalesce(options.historyLimit, () => ( 100)));
|
|
664
|
+
}
|
|
665
|
+
__init6() {this.getState = () => this.state}
|
|
666
|
+
__init7() {this.subscribe = (listener) => {
|
|
667
|
+
this.listeners.add(listener);
|
|
668
|
+
return () => {
|
|
669
|
+
this.listeners.delete(listener);
|
|
670
|
+
};
|
|
671
|
+
}}
|
|
672
|
+
get collections() {
|
|
673
|
+
return this.state.collections;
|
|
674
|
+
}
|
|
675
|
+
get variables() {
|
|
676
|
+
return this.state.variables;
|
|
677
|
+
}
|
|
678
|
+
canUndo() {
|
|
679
|
+
return this.undoStack.length > 0;
|
|
680
|
+
}
|
|
681
|
+
canRedo() {
|
|
682
|
+
return this.redoStack.length > 0;
|
|
683
|
+
}
|
|
684
|
+
/** Resolves a variable under `modes` (see `resolveToken`). */
|
|
685
|
+
resolve(id, modes) {
|
|
686
|
+
return resolveToken(this.state, id, modes);
|
|
687
|
+
}
|
|
688
|
+
resolveValue(id, modes) {
|
|
689
|
+
return resolveTokenValue(this.state, id, modes);
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
692
|
+
* Runs `fn` as one undo step with one change event. If `fn` throws, every change it made is
|
|
693
|
+
* rolled back and the error rethrown.
|
|
694
|
+
*/
|
|
695
|
+
transact(reason, fn) {
|
|
696
|
+
const outer = this.depth === 0;
|
|
697
|
+
if (outer) this.pending = { reason, previous: this.state, deleted: [] };
|
|
698
|
+
this.depth += 1;
|
|
699
|
+
try {
|
|
700
|
+
const result = fn(this);
|
|
701
|
+
this.depth -= 1;
|
|
702
|
+
if (outer) this.flush();
|
|
703
|
+
return result;
|
|
704
|
+
} catch (error) {
|
|
705
|
+
this.depth -= 1;
|
|
706
|
+
if (outer) {
|
|
707
|
+
this.state = this.pending.previous;
|
|
708
|
+
this.pending = null;
|
|
709
|
+
}
|
|
710
|
+
throw error;
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
apply(reason, next, deleted = []) {
|
|
714
|
+
if (next === this.state) return;
|
|
715
|
+
if (this.depth > 0) {
|
|
716
|
+
this.state = next;
|
|
717
|
+
this.pending.deleted.push(...deleted);
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
this.pending = { reason, previous: this.state, deleted: [...deleted] };
|
|
721
|
+
this.state = next;
|
|
722
|
+
this.flush();
|
|
723
|
+
}
|
|
724
|
+
flush() {
|
|
725
|
+
const pending = this.pending;
|
|
726
|
+
this.pending = null;
|
|
727
|
+
if (pending.previous === this.state) return;
|
|
728
|
+
this.undoStack.push({ state: pending.previous, reason: pending.reason });
|
|
729
|
+
if (this.undoStack.length > this.historyLimit) this.undoStack.splice(0, this.undoStack.length - this.historyLimit);
|
|
730
|
+
this.redoStack = [];
|
|
731
|
+
this.emit({ source: "edit", reason: pending.reason, state: this.state, previous: pending.previous, deletedVariableIds: pending.deleted });
|
|
732
|
+
}
|
|
733
|
+
emit(event) {
|
|
734
|
+
for (const listener of [...this.listeners]) listener(event);
|
|
735
|
+
}
|
|
736
|
+
undo() {
|
|
737
|
+
const entry = this.undoStack.pop();
|
|
738
|
+
if (!entry) return false;
|
|
739
|
+
const previous = this.state;
|
|
740
|
+
this.redoStack.push({ state: previous, reason: entry.reason });
|
|
741
|
+
this.state = entry.state;
|
|
742
|
+
this.emit({ source: "undo", reason: entry.reason, state: this.state, previous, deletedVariableIds: [] });
|
|
743
|
+
return true;
|
|
744
|
+
}
|
|
745
|
+
redo() {
|
|
746
|
+
const entry = this.redoStack.pop();
|
|
747
|
+
if (!entry) return false;
|
|
748
|
+
const previous = this.state;
|
|
749
|
+
this.undoStack.push({ state: previous, reason: entry.reason });
|
|
750
|
+
this.state = entry.state;
|
|
751
|
+
this.emit({ source: "redo", reason: entry.reason, state: this.state, previous, deletedVariableIds: [] });
|
|
752
|
+
return true;
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* Replaces the whole state (e.g. after loading a file). Untrusted data should go through
|
|
756
|
+
* `parseTokenState` first. With `record: true` it is an undo step; otherwise history is cleared.
|
|
757
|
+
*/
|
|
758
|
+
replaceState(state, options = {}) {
|
|
759
|
+
if (options.record) {
|
|
760
|
+
this.apply(_nullishCoalesce(options.reason, () => ( "replace")), state);
|
|
761
|
+
return;
|
|
762
|
+
}
|
|
763
|
+
const previous = this.state;
|
|
764
|
+
this.state = state;
|
|
765
|
+
this.undoStack = [];
|
|
766
|
+
this.redoStack = [];
|
|
767
|
+
this.emit({ source: "replace", reason: _nullishCoalesce(options.reason, () => ( "replace")), state, previous, deletedVariableIds: [] });
|
|
768
|
+
}
|
|
769
|
+
/** Loads untrusted JSON (or an object) as the new state; returns the issues found. */
|
|
770
|
+
load(input) {
|
|
771
|
+
const { state, issues } = parseTokenState(input);
|
|
772
|
+
this.replaceState(state, { reason: "load" });
|
|
773
|
+
return issues;
|
|
774
|
+
}
|
|
775
|
+
/** The state as JSON. */
|
|
776
|
+
toJSON() {
|
|
777
|
+
return this.state;
|
|
778
|
+
}
|
|
779
|
+
// --- Collections and modes -----------------------------------------------------------------
|
|
780
|
+
createCollection(name, modes) {
|
|
781
|
+
const input = { name, modes };
|
|
782
|
+
const result = createTokenCollection(this.state, input, this.createId);
|
|
783
|
+
this.apply("createCollection", result.state);
|
|
784
|
+
return result.collection;
|
|
785
|
+
}
|
|
786
|
+
renameCollection(id, name) {
|
|
787
|
+
this.apply("renameCollection", renameTokenCollection(this.state, id, name));
|
|
788
|
+
}
|
|
789
|
+
deleteCollection(id) {
|
|
790
|
+
const result = deleteTokenCollection(this.state, id);
|
|
791
|
+
this.apply("deleteCollection", result.state, result.deleted);
|
|
792
|
+
return result.deleted;
|
|
793
|
+
}
|
|
794
|
+
addMode(collectionId, name, options = {}) {
|
|
795
|
+
const result = addTokenMode(this.state, collectionId, name, options, this.createId);
|
|
796
|
+
this.apply("addMode", result.state);
|
|
797
|
+
return result.mode;
|
|
798
|
+
}
|
|
799
|
+
renameMode(collectionId, modeId, name) {
|
|
800
|
+
this.apply("renameMode", renameTokenMode(this.state, collectionId, modeId, name));
|
|
801
|
+
}
|
|
802
|
+
removeMode(collectionId, modeId) {
|
|
803
|
+
this.apply("removeMode", removeTokenMode(this.state, collectionId, modeId));
|
|
804
|
+
}
|
|
805
|
+
moveMode(collectionId, modeId, to) {
|
|
806
|
+
this.apply("moveMode", moveTokenMode(this.state, collectionId, modeId, to));
|
|
807
|
+
}
|
|
808
|
+
/** Makes a mode the default by moving it first. */
|
|
809
|
+
setDefaultMode(collectionId, modeId) {
|
|
810
|
+
this.apply("setDefaultMode", moveTokenMode(this.state, collectionId, modeId, 0));
|
|
811
|
+
}
|
|
812
|
+
// --- Variables -----------------------------------------------------------------------------
|
|
813
|
+
createVariable(input) {
|
|
814
|
+
const result = createTokenVariable(this.state, input, this.createId);
|
|
815
|
+
this.apply("createVariable", result.state);
|
|
816
|
+
return result.variable;
|
|
817
|
+
}
|
|
818
|
+
/** Sets a literal or `{ alias }` in one mode (id or name; default: the default mode). */
|
|
819
|
+
setValue(variableId, value, modeId) {
|
|
820
|
+
this.apply("setValue", setTokenValue(this.state, variableId, value, modeId));
|
|
821
|
+
}
|
|
822
|
+
renameVariable(variableId, name) {
|
|
823
|
+
this.apply("renameVariable", renameTokenVariable(this.state, variableId, name));
|
|
824
|
+
}
|
|
825
|
+
updateVariable(variableId, input) {
|
|
826
|
+
this.apply("updateVariable", updateTokenVariable(this.state, variableId, input));
|
|
827
|
+
}
|
|
828
|
+
/** Deletes variables; aliases to them take their values. Returns the ids deleted. */
|
|
829
|
+
deleteVariables(ids) {
|
|
830
|
+
const result = deleteTokenVariables(this.state, typeof ids === "string" ? [ids] : ids);
|
|
831
|
+
this.apply("deleteVariables", result.state, result.deleted);
|
|
832
|
+
return result.deleted;
|
|
833
|
+
}
|
|
834
|
+
/** Applies a pure state transform (e.g. `importW3CTokens`) as one undo step. */
|
|
835
|
+
update(reason, fn) {
|
|
836
|
+
this.apply(reason, fn(this.state));
|
|
837
|
+
}
|
|
838
|
+
}, _class);
|
|
839
|
+
function createTokenStore(options = {}) {
|
|
840
|
+
return new TokenStore(options);
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
// src/tokens/css.ts
|
|
844
|
+
function tokenSlug(name) {
|
|
845
|
+
let out = "";
|
|
846
|
+
let dash = false;
|
|
847
|
+
for (const ch of name.toLowerCase()) {
|
|
848
|
+
if (ch >= "a" && ch <= "z" || ch >= "0" && ch <= "9" || ch === "_") {
|
|
849
|
+
if (dash && out) out += "-";
|
|
850
|
+
out += ch;
|
|
851
|
+
dash = false;
|
|
852
|
+
} else dash = true;
|
|
853
|
+
}
|
|
854
|
+
return out || "token";
|
|
855
|
+
}
|
|
856
|
+
function getTokenCssName(state, variable, options = {}) {
|
|
857
|
+
const collection = getTokenCollection(state, variable.collectionId);
|
|
858
|
+
const head = options.collectionPrefix && collection ? `${tokenSlug(collection.name)}-` : "";
|
|
859
|
+
const prefix = options.prefix ? `${tokenSlug(options.prefix)}-` : "";
|
|
860
|
+
return `--${prefix}${head}${tokenSlug(variable.name)}`;
|
|
861
|
+
}
|
|
862
|
+
function cssString(value) {
|
|
863
|
+
let out = '"';
|
|
864
|
+
for (const ch of value) {
|
|
865
|
+
if (ch === '"' || ch === "\\") out += "\\" + ch;
|
|
866
|
+
else if (ch === "\n") out += "\\a ";
|
|
867
|
+
else if (ch === "\r") out += "\\d ";
|
|
868
|
+
else if (ch === "<") out += "\\3c ";
|
|
869
|
+
else out += ch;
|
|
870
|
+
}
|
|
871
|
+
return out + '"';
|
|
872
|
+
}
|
|
873
|
+
function formatTokenCssValue(value, variable, options = {}) {
|
|
874
|
+
switch (variable.type) {
|
|
875
|
+
case "color":
|
|
876
|
+
return String(value);
|
|
877
|
+
case "number":
|
|
878
|
+
return options.formatNumber ? options.formatNumber(value, variable) : `${value}${_nullishCoalesce(variable.unit, () => ( ""))}`;
|
|
879
|
+
case "string":
|
|
880
|
+
return cssString(String(value));
|
|
881
|
+
case "boolean":
|
|
882
|
+
return value ? "true" : "false";
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
var defaultModeValue = (mode) => tokenSlug(mode.name);
|
|
886
|
+
function attributeFor(options, collection) {
|
|
887
|
+
const attr = typeof options.attribute === "function" ? options.attribute(collection) : _nullishCoalesce(options.attribute, () => ( "data-mode"));
|
|
888
|
+
return tokenSlug(attr);
|
|
889
|
+
}
|
|
890
|
+
function exportTokensCss(state, options = {}) {
|
|
891
|
+
const selector = _nullishCoalesce(options.selector, () => ( ":root"));
|
|
892
|
+
const wanted = options.collections ? new Set(options.collections) : null;
|
|
893
|
+
const collections = state.collections.filter((c) => !wanted || wanted.has(c.id));
|
|
894
|
+
const exported = new Set(state.variables.filter((v) => collections.some((c) => c.id === v.collectionId)).map((v) => v.id));
|
|
895
|
+
const modeValue = _nullishCoalesce(options.modeValue, () => ( defaultModeValue));
|
|
896
|
+
const declaration = (variable, collection, mode) => {
|
|
897
|
+
const value = variable.valuesByMode[mode.id];
|
|
898
|
+
if (isTokenAlias(value) && exported.has(value.alias)) {
|
|
899
|
+
const target = getTokenVariable(state, value.alias);
|
|
900
|
+
return ` ${getTokenCssName(state, variable, options)}: var(${getTokenCssName(state, target, options)});`;
|
|
901
|
+
}
|
|
902
|
+
const resolved = resolveToken(state, variable.id, { [collection.id]: mode.id });
|
|
903
|
+
if (!resolved.ok) return null;
|
|
904
|
+
return ` ${getTokenCssName(state, variable, options)}: ${formatTokenCssValue(resolved.value, variable, options)};`;
|
|
905
|
+
};
|
|
906
|
+
const blocks = [];
|
|
907
|
+
const rootLines = [];
|
|
908
|
+
for (const collection of collections) {
|
|
909
|
+
const vars = state.variables.filter((v) => v.collectionId === collection.id);
|
|
910
|
+
for (const v of vars) {
|
|
911
|
+
const line = declaration(v, collection, collection.modes[0]);
|
|
912
|
+
if (line) rootLines.push(line);
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
const rootSelectors = [selector];
|
|
916
|
+
if (options.nested) {
|
|
917
|
+
for (const collection of collections) {
|
|
918
|
+
rootSelectors.push(`[${attributeFor(options, collection)}="${tokenSlug(modeValue(collection.modes[0], collection))}"]`);
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
blocks.push(`${[...new Set(rootSelectors)].join(", ")} {
|
|
922
|
+
${rootLines.join("\n")}${rootLines.length ? "\n" : ""}}`);
|
|
923
|
+
for (const collection of collections) {
|
|
924
|
+
const vars = state.variables.filter((v) => v.collectionId === collection.id);
|
|
925
|
+
const attr = attributeFor(options, collection);
|
|
926
|
+
for (const mode of collection.modes.slice(1)) {
|
|
927
|
+
const lines = vars.map((v) => declaration(v, collection, mode)).filter((l) => l !== null);
|
|
928
|
+
const value = tokenSlug(modeValue(mode, collection));
|
|
929
|
+
const selectors = [`${selector}[${attr}="${value}"]`];
|
|
930
|
+
if (options.nested) selectors.push(`[${attr}="${value}"]`);
|
|
931
|
+
blocks.push(`${selectors.join(", ")} {
|
|
932
|
+
${lines.join("\n")}${lines.length ? "\n" : ""}}`);
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
return blocks.join("\n\n") + "\n";
|
|
936
|
+
}
|
|
937
|
+
function getTokenCssVariables(state, modes, options = {}) {
|
|
938
|
+
const wanted = options.collections ? new Set(options.collections) : null;
|
|
939
|
+
const out = {};
|
|
940
|
+
for (const variable of state.variables) {
|
|
941
|
+
if (wanted && !wanted.has(variable.collectionId)) continue;
|
|
942
|
+
const collection = getTokenCollection(state, variable.collectionId);
|
|
943
|
+
if (!collection) continue;
|
|
944
|
+
const resolved = resolveToken(state, variable.id, { ...modes, [collection.id]: getCurrentMode(collection, modes).id });
|
|
945
|
+
if (resolved.ok) out[getTokenCssName(state, variable, options)] = formatTokenCssValue(resolved.value, variable, options);
|
|
946
|
+
}
|
|
947
|
+
return out;
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
// src/tokens/w3c.ts
|
|
951
|
+
var W3C_TOKENS_EXTENSION = "com.pixerate.tokens";
|
|
952
|
+
function path(name) {
|
|
953
|
+
return name.split("/");
|
|
954
|
+
}
|
|
955
|
+
function reference(state, variable) {
|
|
956
|
+
const collection = getTokenCollection(state, variable.collectionId);
|
|
957
|
+
return `{${[_nullishCoalesce(_optionalChain([collection, 'optionalAccess', _12 => _12.name]), () => ( variable.collectionId)), ...path(variable.name)].join(".")}}`;
|
|
958
|
+
}
|
|
959
|
+
function w3cType(variable) {
|
|
960
|
+
if (variable.type === "number") {
|
|
961
|
+
if (variable.unit === "ms" || variable.unit === "s") return "duration";
|
|
962
|
+
if (variable.unit) return "dimension";
|
|
963
|
+
}
|
|
964
|
+
return variable.type;
|
|
965
|
+
}
|
|
966
|
+
function w3cLiteral(variable, value, colorFormat) {
|
|
967
|
+
if (variable.type === "color" && colorFormat === "object") {
|
|
968
|
+
const c = hexToRgba(String(value));
|
|
969
|
+
if (c) {
|
|
970
|
+
const round = (n) => Math.round(n * 1e4) / 1e4;
|
|
971
|
+
return { colorSpace: "srgb", components: [round(c.r), round(c.g), round(c.b)], alpha: round(c.a), hex: String(value).slice(0, 7) };
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
if (variable.type === "number" && variable.unit) return { value, unit: variable.unit };
|
|
975
|
+
return value;
|
|
976
|
+
}
|
|
977
|
+
function w3cValue(state, variable, value, colorFormat) {
|
|
978
|
+
if (value === void 0) return null;
|
|
979
|
+
if (isTokenAlias(value)) {
|
|
980
|
+
const target = getTokenVariable(state, value.alias);
|
|
981
|
+
return target ? reference(state, target) : null;
|
|
982
|
+
}
|
|
983
|
+
return w3cLiteral(variable, value, colorFormat);
|
|
984
|
+
}
|
|
985
|
+
function exportW3CTokens(state, options = {}) {
|
|
986
|
+
const withExtensions = options.extensions !== false;
|
|
987
|
+
const colorFormat = _nullishCoalesce(options.colorFormat, () => ( "hex"));
|
|
988
|
+
const wanted = options.collections ? new Set(options.collections) : null;
|
|
989
|
+
const root = {};
|
|
990
|
+
for (const collection of state.collections) {
|
|
991
|
+
if (wanted && !wanted.has(collection.id)) continue;
|
|
992
|
+
const group = {};
|
|
993
|
+
if (withExtensions) {
|
|
994
|
+
group.$extensions = {
|
|
995
|
+
[W3C_TOKENS_EXTENSION]: { id: collection.id, modes: collection.modes.map((m) => ({ id: m.id, name: m.name })) }
|
|
996
|
+
};
|
|
997
|
+
}
|
|
998
|
+
const chosen = _optionalChain([options, 'access', _13 => _13.modes, 'optionalAccess', _14 => _14[collection.id]]);
|
|
999
|
+
const mode = chosen !== void 0 && collection.modes.find((m) => m.id === chosen) || collection.modes[0];
|
|
1000
|
+
for (const variable of state.variables) {
|
|
1001
|
+
if (variable.collectionId !== collection.id) continue;
|
|
1002
|
+
const token = {
|
|
1003
|
+
$type: w3cType(variable),
|
|
1004
|
+
$value: w3cValue(state, variable, variable.valuesByMode[mode.id], colorFormat)
|
|
1005
|
+
};
|
|
1006
|
+
if (variable.description) token.$description = variable.description;
|
|
1007
|
+
if (withExtensions) {
|
|
1008
|
+
const modes = {};
|
|
1009
|
+
for (const m of collection.modes) modes[m.name] = w3cValue(state, variable, variable.valuesByMode[m.id], colorFormat);
|
|
1010
|
+
const ext = { id: variable.id, modes };
|
|
1011
|
+
if (variable.scopes) ext.scopes = [...variable.scopes];
|
|
1012
|
+
if (variable.unit) ext.unit = variable.unit;
|
|
1013
|
+
token.$extensions = { [W3C_TOKENS_EXTENSION]: ext };
|
|
1014
|
+
}
|
|
1015
|
+
let at = group;
|
|
1016
|
+
const segments = path(variable.name);
|
|
1017
|
+
for (const segment of segments.slice(0, -1)) {
|
|
1018
|
+
const next = at[segment];
|
|
1019
|
+
if (typeof next !== "object" || next === null || Array.isArray(next) || "$value" in next) at[segment] = {};
|
|
1020
|
+
at = at[segment];
|
|
1021
|
+
}
|
|
1022
|
+
at[segments[segments.length - 1]] = token;
|
|
1023
|
+
}
|
|
1024
|
+
root[collection.name] = group;
|
|
1025
|
+
}
|
|
1026
|
+
return root;
|
|
1027
|
+
}
|
|
1028
|
+
function exportW3CTokensJson(state, options = {}) {
|
|
1029
|
+
return JSON.stringify(exportW3CTokens(state, options), null, 2);
|
|
1030
|
+
}
|
|
1031
|
+
var MAX_DEPTH = 32;
|
|
1032
|
+
var REF = /^\{([^{}]+)\}$/;
|
|
1033
|
+
var MEASURE = /^(-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?)\s*([a-z%]*)$/i;
|
|
1034
|
+
var FONT_WEIGHTS = {
|
|
1035
|
+
thin: 100,
|
|
1036
|
+
hairline: 100,
|
|
1037
|
+
"extra-light": 200,
|
|
1038
|
+
"ultra-light": 200,
|
|
1039
|
+
light: 300,
|
|
1040
|
+
normal: 400,
|
|
1041
|
+
regular: 400,
|
|
1042
|
+
book: 400,
|
|
1043
|
+
medium: 500,
|
|
1044
|
+
"semi-bold": 600,
|
|
1045
|
+
"demi-bold": 600,
|
|
1046
|
+
bold: 700,
|
|
1047
|
+
"extra-bold": 800,
|
|
1048
|
+
"ultra-bold": 800,
|
|
1049
|
+
black: 900,
|
|
1050
|
+
heavy: 900,
|
|
1051
|
+
"extra-black": 950,
|
|
1052
|
+
"ultra-black": 950
|
|
1053
|
+
};
|
|
1054
|
+
var isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1055
|
+
function extensionOf(node) {
|
|
1056
|
+
const ext = node.$extensions;
|
|
1057
|
+
if (!isObject(ext)) return void 0;
|
|
1058
|
+
const ours = ext[W3C_TOKENS_EXTENSION];
|
|
1059
|
+
return isObject(ours) ? ours : void 0;
|
|
1060
|
+
}
|
|
1061
|
+
function aliasRef(value) {
|
|
1062
|
+
if (typeof value !== "string" || value.length > 1e3) return null;
|
|
1063
|
+
const match = REF.exec(value.trim());
|
|
1064
|
+
return match ? match[1].trim() : null;
|
|
1065
|
+
}
|
|
1066
|
+
function mapType(type) {
|
|
1067
|
+
switch (type) {
|
|
1068
|
+
case "color":
|
|
1069
|
+
return "color";
|
|
1070
|
+
case "number":
|
|
1071
|
+
case "dimension":
|
|
1072
|
+
case "duration":
|
|
1073
|
+
case "fontWeight":
|
|
1074
|
+
return "number";
|
|
1075
|
+
case "string":
|
|
1076
|
+
case "text":
|
|
1077
|
+
case "fontFamily":
|
|
1078
|
+
case "fontStyle":
|
|
1079
|
+
return "string";
|
|
1080
|
+
case "boolean":
|
|
1081
|
+
return "boolean";
|
|
1082
|
+
default:
|
|
1083
|
+
return null;
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
function inferType(value) {
|
|
1087
|
+
if (typeof value === "boolean") return "boolean";
|
|
1088
|
+
if (typeof value === "number") return "number";
|
|
1089
|
+
if (typeof value === "string") {
|
|
1090
|
+
const text = value.trim();
|
|
1091
|
+
if ((text.startsWith("#") || /^rgba?\(/i.test(text)) && normalizeTokenColor(text)) return "color";
|
|
1092
|
+
if (MEASURE.test(text) && /[a-z%]$/i.test(text)) return "dimension";
|
|
1093
|
+
return "string";
|
|
1094
|
+
}
|
|
1095
|
+
if (isObject(value) && Array.isArray(value.components)) return "color";
|
|
1096
|
+
if (isObject(value) && typeof value.value === "number" && typeof value.unit === "string") return "dimension";
|
|
1097
|
+
return void 0;
|
|
1098
|
+
}
|
|
1099
|
+
function readLiteral(w3cType2, type, value) {
|
|
1100
|
+
if (type === "number") {
|
|
1101
|
+
if (w3cType2 === "fontWeight" && typeof value === "string") {
|
|
1102
|
+
const weight = FONT_WEIGHTS[value.trim().toLowerCase()];
|
|
1103
|
+
return weight === void 0 ? null : { value: weight };
|
|
1104
|
+
}
|
|
1105
|
+
if (isObject(value) && typeof value.value === "number" && Number.isFinite(value.value)) {
|
|
1106
|
+
const unit = typeof value.unit === "string" && /^[a-z%]{1,8}$/i.test(value.unit) ? value.unit.toLowerCase() : void 0;
|
|
1107
|
+
return { value: value.value, unit };
|
|
1108
|
+
}
|
|
1109
|
+
if (typeof value === "string" && value.length <= 100) {
|
|
1110
|
+
const match = MEASURE.exec(value.trim());
|
|
1111
|
+
if (!match) return null;
|
|
1112
|
+
const n2 = Number(match[1]);
|
|
1113
|
+
if (!Number.isFinite(n2)) return null;
|
|
1114
|
+
const unit = match[2] ? match[2].toLowerCase() : void 0;
|
|
1115
|
+
return { value: n2, unit: unit && unit.length <= 8 ? unit : void 0 };
|
|
1116
|
+
}
|
|
1117
|
+
const n = coerceTokenLiteral("number", value);
|
|
1118
|
+
return n === null ? null : { value: n };
|
|
1119
|
+
}
|
|
1120
|
+
if (type === "string" && w3cType2 === "fontFamily" && Array.isArray(value)) {
|
|
1121
|
+
return value.every((v) => typeof v === "string") ? { value: value.join(", ") } : null;
|
|
1122
|
+
}
|
|
1123
|
+
const literal = coerceTokenLiteral(type, value);
|
|
1124
|
+
return literal === null ? null : { value: literal };
|
|
1125
|
+
}
|
|
1126
|
+
function collectTokens(group, collection, prefix, inheritedType, out, warnings, depth) {
|
|
1127
|
+
if (depth > MAX_DEPTH) {
|
|
1128
|
+
warnings.push(`\`${prefix.join(".")}\` is nested too deeply; skipped`);
|
|
1129
|
+
return;
|
|
1130
|
+
}
|
|
1131
|
+
const groupType = typeof group.$type === "string" ? group.$type : inheritedType;
|
|
1132
|
+
for (const [key, child] of Object.entries(group)) {
|
|
1133
|
+
if (key.startsWith("$")) continue;
|
|
1134
|
+
const at = [...prefix, key];
|
|
1135
|
+
if (!isObject(child)) {
|
|
1136
|
+
warnings.push(`\`${at.join(".")}\` is not a token or group; skipped`);
|
|
1137
|
+
continue;
|
|
1138
|
+
}
|
|
1139
|
+
if ("$value" in child) {
|
|
1140
|
+
out.push({
|
|
1141
|
+
collection,
|
|
1142
|
+
path: at,
|
|
1143
|
+
type: typeof child.$type === "string" ? child.$type : groupType,
|
|
1144
|
+
value: child.$value,
|
|
1145
|
+
description: child.$description,
|
|
1146
|
+
ext: extensionOf(child)
|
|
1147
|
+
});
|
|
1148
|
+
} else collectTokens(child, collection, at, groupType, out, warnings, depth + 1);
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
function importW3CTokens(state, input, options = {}) {
|
|
1152
|
+
let doc = input;
|
|
1153
|
+
if (typeof doc === "string") {
|
|
1154
|
+
try {
|
|
1155
|
+
doc = JSON.parse(doc);
|
|
1156
|
+
} catch (e3) {
|
|
1157
|
+
throw new TokenError("invalid-input", "Not JSON");
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
if (!isObject(doc)) throw new TokenError("invalid-input", "Expected a design tokens object");
|
|
1161
|
+
const createId = _nullishCoalesce(options.createId, () => ( defaultTokenId));
|
|
1162
|
+
const report = { collectionsAdded: 0, modesAdded: 0, variablesAdded: 0, variablesUpdated: 0, warnings: [] };
|
|
1163
|
+
const warn = (message) => {
|
|
1164
|
+
if (report.warnings.length < 500) report.warnings.push(message);
|
|
1165
|
+
};
|
|
1166
|
+
const marked = Object.entries(doc).filter(([key, value]) => !key.startsWith("$") && isObject(value) && !("$value" in value) && Array.isArray(_optionalChain([extensionOf, 'call', _15 => _15(value), 'optionalAccess', _16 => _16.modes])));
|
|
1167
|
+
const plainName = _nullishCoalesce(options.collection, () => ( "Tokens"));
|
|
1168
|
+
const sources = [];
|
|
1169
|
+
if (marked.length > 0) {
|
|
1170
|
+
for (const [key, value] of marked) {
|
|
1171
|
+
const ext = extensionOf(value);
|
|
1172
|
+
sources.push({ name: key, group: value, modes: ext.modes, id: ext.id, plain: false });
|
|
1173
|
+
}
|
|
1174
|
+
const rest = {};
|
|
1175
|
+
for (const [key, value] of Object.entries(doc)) if (!marked.some(([k]) => k === key)) rest[key] = value;
|
|
1176
|
+
if (Object.keys(rest).some((k) => !k.startsWith("$"))) sources.push({ name: plainName, group: rest, plain: true });
|
|
1177
|
+
} else sources.push({ name: plainName, group: doc, plain: true });
|
|
1178
|
+
const usedIds = /* @__PURE__ */ new Set([...state.collections.map((c) => c.id), ...state.variables.map((v) => v.id)]);
|
|
1179
|
+
for (const c of state.collections) for (const m of c.modes) usedIds.add(m.id);
|
|
1180
|
+
const idFrom = (candidate, kind) => (k) => {
|
|
1181
|
+
if (k === kind && typeof candidate === "string" && candidate.length > 0 && candidate.length <= 200 && !usedIds.has(candidate)) {
|
|
1182
|
+
usedIds.add(candidate);
|
|
1183
|
+
return candidate;
|
|
1184
|
+
}
|
|
1185
|
+
const id = createId(k);
|
|
1186
|
+
usedIds.add(id);
|
|
1187
|
+
return id;
|
|
1188
|
+
};
|
|
1189
|
+
let next = state;
|
|
1190
|
+
const tokens = [];
|
|
1191
|
+
const collectionIds = /* @__PURE__ */ new Map();
|
|
1192
|
+
const plainMode = /* @__PURE__ */ new Map();
|
|
1193
|
+
const ensureMode = (collectionId, name, id) => {
|
|
1194
|
+
const collection = getTokenCollection(next, collectionId);
|
|
1195
|
+
const existing = findTokenMode(collection, name);
|
|
1196
|
+
if (existing) return existing.id;
|
|
1197
|
+
try {
|
|
1198
|
+
const result = addTokenMode(next, collectionId, name, {}, idFrom(id, "mode"));
|
|
1199
|
+
next = result.state;
|
|
1200
|
+
report.modesAdded += 1;
|
|
1201
|
+
return result.mode.id;
|
|
1202
|
+
} catch (error) {
|
|
1203
|
+
warn(`Mode \`${name}\`: ${error.message}`);
|
|
1204
|
+
return null;
|
|
1205
|
+
}
|
|
1206
|
+
};
|
|
1207
|
+
for (const source of sources) {
|
|
1208
|
+
let collection = findTokenCollection(next, source.name);
|
|
1209
|
+
if (!collection) {
|
|
1210
|
+
const declared = (_nullishCoalesce(source.modes, () => ( []))).filter(isObject);
|
|
1211
|
+
const names = declared.map((m) => m.name).filter((n) => typeof n === "string" && n.trim() !== "");
|
|
1212
|
+
if (source.plain && options.mode) names.splice(0, names.length, options.mode);
|
|
1213
|
+
try {
|
|
1214
|
+
const ids = [source.id, ...declared.map((m) => m.id)];
|
|
1215
|
+
let i = 0;
|
|
1216
|
+
const factory = (kind) => idFrom(kind === "collection" ? ids[0] : ids[++i], kind)(kind);
|
|
1217
|
+
const result = createTokenCollection(next, { name: source.name, modes: names.length ? names : void 0 }, factory);
|
|
1218
|
+
next = result.state;
|
|
1219
|
+
collection = result.collection;
|
|
1220
|
+
report.collectionsAdded += 1;
|
|
1221
|
+
} catch (error) {
|
|
1222
|
+
warn(`Collection \`${source.name}\`: ${error.message}`);
|
|
1223
|
+
continue;
|
|
1224
|
+
}
|
|
1225
|
+
} else {
|
|
1226
|
+
for (const m of (_nullishCoalesce(source.modes, () => ( []))).filter(isObject)) {
|
|
1227
|
+
if (typeof m.name === "string" && m.name.trim()) ensureMode(collection.id, m.name, m.id);
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
collectionIds.set(source.name, collection.id);
|
|
1231
|
+
const modeId = options.mode && source.plain ? ensureMode(collection.id, options.mode) : getTokenCollection(next, collection.id).modes[0].id;
|
|
1232
|
+
if (modeId) plainMode.set(source.name, modeId);
|
|
1233
|
+
collectTokens(source.group, source.name, [], void 0, tokens, report.warnings, 0);
|
|
1234
|
+
}
|
|
1235
|
+
const byFullPath = /* @__PURE__ */ new Map();
|
|
1236
|
+
for (const token of tokens) byFullPath.set([token.collection, ...token.path].join("."), token);
|
|
1237
|
+
const findRaw = (ref, from) => _nullishCoalesce(byFullPath.get(ref), () => ( byFullPath.get(`${from.collection}.${ref}`)));
|
|
1238
|
+
const typeOf = (token) => {
|
|
1239
|
+
let current = token;
|
|
1240
|
+
for (let i = 0; i < MAX_DEPTH && current; i++) {
|
|
1241
|
+
if (current.type) return current.type;
|
|
1242
|
+
const ref = aliasRef(current.value);
|
|
1243
|
+
if (ref === null) return inferType(current.value);
|
|
1244
|
+
current = findRaw(ref, current);
|
|
1245
|
+
}
|
|
1246
|
+
return void 0;
|
|
1247
|
+
};
|
|
1248
|
+
const pending = [];
|
|
1249
|
+
const variableFor = /* @__PURE__ */ new Map();
|
|
1250
|
+
for (const token of tokens) {
|
|
1251
|
+
const label2 = [token.collection, ...token.path].join(".");
|
|
1252
|
+
const collectionId = collectionIds.get(token.collection);
|
|
1253
|
+
if (!collectionId) continue;
|
|
1254
|
+
const w3cType2 = typeOf(token);
|
|
1255
|
+
const type = w3cType2 ? mapType(w3cType2) : null;
|
|
1256
|
+
if (!w3cType2 || !type) {
|
|
1257
|
+
warn(`\`${label2}\` has an unsupported type \`${_nullishCoalesce(w3cType2, () => ( "unknown"))}\`; skipped`);
|
|
1258
|
+
continue;
|
|
1259
|
+
}
|
|
1260
|
+
let name;
|
|
1261
|
+
try {
|
|
1262
|
+
name = normalizeTokenName(token.path.join("/"));
|
|
1263
|
+
} catch (error) {
|
|
1264
|
+
warn(`\`${label2}\`: ${error.message}`);
|
|
1265
|
+
continue;
|
|
1266
|
+
}
|
|
1267
|
+
let variable = findTokenVariable(next, name, collectionId);
|
|
1268
|
+
if (variable && variable.type !== type) {
|
|
1269
|
+
warn(`\`${name}\` is a ${variable.type} variable; the ${type} token \`${label2}\` was skipped`);
|
|
1270
|
+
continue;
|
|
1271
|
+
}
|
|
1272
|
+
if (!variable) {
|
|
1273
|
+
try {
|
|
1274
|
+
const result = createTokenVariable(next, { collectionId, name, type }, idFrom(_optionalChain([token, 'access', _17 => _17.ext, 'optionalAccess', _18 => _18.id]), "variable"));
|
|
1275
|
+
next = result.state;
|
|
1276
|
+
variable = result.variable;
|
|
1277
|
+
report.variablesAdded += 1;
|
|
1278
|
+
} catch (error) {
|
|
1279
|
+
warn(`\`${label2}\`: ${error.message}`);
|
|
1280
|
+
continue;
|
|
1281
|
+
}
|
|
1282
|
+
} else report.variablesUpdated += 1;
|
|
1283
|
+
variableFor.set(token, variable.id);
|
|
1284
|
+
const values = [];
|
|
1285
|
+
const extModes = _optionalChain([token, 'access', _19 => _19.ext, 'optionalAccess', _20 => _20.modes]);
|
|
1286
|
+
if (isObject(extModes)) {
|
|
1287
|
+
for (const [modeName, value] of Object.entries(extModes)) {
|
|
1288
|
+
const modeId = ensureMode(collectionId, modeName);
|
|
1289
|
+
if (modeId) values.push([modeId, value]);
|
|
1290
|
+
}
|
|
1291
|
+
} else {
|
|
1292
|
+
const modeId = plainMode.get(token.collection);
|
|
1293
|
+
if (modeId) values.push([modeId, token.value]);
|
|
1294
|
+
}
|
|
1295
|
+
let unit;
|
|
1296
|
+
for (const [modeId, raw] of values) {
|
|
1297
|
+
const ref = aliasRef(raw);
|
|
1298
|
+
if (ref !== null) {
|
|
1299
|
+
pending.push({ variable, modeId, ref, token });
|
|
1300
|
+
continue;
|
|
1301
|
+
}
|
|
1302
|
+
const literal = readLiteral(w3cType2, type, raw);
|
|
1303
|
+
if (!literal) {
|
|
1304
|
+
warn(`\`${label2}\` has an invalid ${w3cType2} value; kept the previous value`);
|
|
1305
|
+
continue;
|
|
1306
|
+
}
|
|
1307
|
+
if (literal.unit) unit = literal.unit;
|
|
1308
|
+
next = setTokenValue(next, variable.id, literal.value, modeId);
|
|
1309
|
+
}
|
|
1310
|
+
const update = {};
|
|
1311
|
+
if (typeof token.description === "string") update.description = token.description;
|
|
1312
|
+
const extUnit = _optionalChain([token, 'access', _21 => _21.ext, 'optionalAccess', _22 => _22.unit]);
|
|
1313
|
+
if (typeof extUnit === "string") unit = extUnit;
|
|
1314
|
+
if (unit && unit !== variable.unit) update.unit = unit;
|
|
1315
|
+
if (Array.isArray(_optionalChain([token, 'access', _23 => _23.ext, 'optionalAccess', _24 => _24.scopes]))) update.scopes = token.ext.scopes.filter((s) => typeof s === "string");
|
|
1316
|
+
if (Object.keys(update).length > 0) {
|
|
1317
|
+
try {
|
|
1318
|
+
next = updateTokenVariable(next, variable.id, update);
|
|
1319
|
+
} catch (error) {
|
|
1320
|
+
warn(`\`${label2}\`: ${error.message}`);
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
for (const { variable, modeId, ref, token } of pending) {
|
|
1325
|
+
const label2 = [token.collection, ...token.path].join(".");
|
|
1326
|
+
const raw = findRaw(ref, token);
|
|
1327
|
+
let targetId = raw ? variableFor.get(raw) : void 0;
|
|
1328
|
+
if (!targetId) {
|
|
1329
|
+
const dot = ref.indexOf(".");
|
|
1330
|
+
const inCollection = dot > 0 ? findTokenCollection(next, ref.slice(0, dot)) : void 0;
|
|
1331
|
+
const found = inCollection && findTokenVariable(next, ref.slice(dot + 1).split(".").join("/"), inCollection.id) || findTokenVariable(next, ref.split(".").join("/"), variable.collectionId);
|
|
1332
|
+
targetId = found ? found.id : void 0;
|
|
1333
|
+
}
|
|
1334
|
+
if (!targetId) {
|
|
1335
|
+
warn(`\`${label2}\` refers to \`{${ref}}\`, which doesn't exist; kept the previous value`);
|
|
1336
|
+
continue;
|
|
1337
|
+
}
|
|
1338
|
+
const current = getTokenVariable(next, variable.id);
|
|
1339
|
+
const error = checkTokenAlias(next, current, targetId);
|
|
1340
|
+
if (error) {
|
|
1341
|
+
warn(`\`${label2}\`: ${error.message}`);
|
|
1342
|
+
continue;
|
|
1343
|
+
}
|
|
1344
|
+
next = setTokenValue(next, variable.id, { alias: targetId }, modeId);
|
|
1345
|
+
}
|
|
1346
|
+
return { state: next, report };
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
|
|
1350
|
+
|
|
1351
|
+
|
|
1352
|
+
|
|
1353
|
+
|
|
1354
|
+
|
|
1355
|
+
|
|
1356
|
+
|
|
1357
|
+
|
|
1358
|
+
|
|
1359
|
+
|
|
1360
|
+
|
|
1361
|
+
|
|
1362
|
+
|
|
1363
|
+
|
|
1364
|
+
|
|
1365
|
+
|
|
1366
|
+
|
|
1367
|
+
|
|
1368
|
+
|
|
1369
|
+
|
|
1370
|
+
|
|
1371
|
+
|
|
1372
|
+
|
|
1373
|
+
|
|
1374
|
+
|
|
1375
|
+
|
|
1376
|
+
|
|
1377
|
+
|
|
1378
|
+
|
|
1379
|
+
|
|
1380
|
+
|
|
1381
|
+
|
|
1382
|
+
|
|
1383
|
+
|
|
1384
|
+
|
|
1385
|
+
|
|
1386
|
+
|
|
1387
|
+
|
|
1388
|
+
|
|
1389
|
+
|
|
1390
|
+
|
|
1391
|
+
|
|
1392
|
+
|
|
1393
|
+
|
|
1394
|
+
|
|
1395
|
+
|
|
1396
|
+
|
|
1397
|
+
|
|
1398
|
+
|
|
1399
|
+
|
|
1400
|
+
|
|
1401
|
+
|
|
1402
|
+
|
|
1403
|
+
|
|
1404
|
+
|
|
1405
|
+
exports.TOKEN_TYPES = TOKEN_TYPES; exports.TokenError = TokenError; exports.isTokenAlias = isTokenAlias; exports.EMPTY_TOKEN_STATE = EMPTY_TOKEN_STATE; exports.rgbaToHex = rgbaToHex; exports.hexToRgba = hexToRgba; exports.normalizeTokenColor = normalizeTokenColor; exports.getTokenCollection = getTokenCollection; exports.getTokenVariable = getTokenVariable; exports.findTokenCollection = findTokenCollection; exports.findTokenVariable = findTokenVariable; exports.getCollectionVariables = getCollectionVariables; exports.getDefaultMode = getDefaultMode; exports.findTokenMode = findTokenMode; exports.getCurrentMode = getCurrentMode; exports.defaultTokenValue = defaultTokenValue; exports.coerceTokenLiteral = coerceTokenLiteral; exports.literalTokenType = literalTokenType; exports.formatTokenValue = formatTokenValue; exports.resolveToken = resolveToken; exports.resolveTokenValue = resolveTokenValue; exports.resolveTokenInMode = resolveTokenInMode; exports.checkTokenAlias = checkTokenAlias; exports.TOKEN_SCOPES_BY_TYPE = TOKEN_SCOPES_BY_TYPE; exports.isTokenScopeKnown = isTokenScopeKnown; exports.normalizeTokenScopes = normalizeTokenScopes; exports.isTokenInScope = isTokenInScope; exports.normalizeTokenName = normalizeTokenName; exports.defaultTokenId = defaultTokenId; exports.createTokenCollection = createTokenCollection; exports.renameTokenCollection = renameTokenCollection; exports.deleteTokenVariables = deleteTokenVariables; exports.deleteTokenCollection = deleteTokenCollection; exports.addTokenMode = addTokenMode; exports.renameTokenMode = renameTokenMode; exports.removeTokenMode = removeTokenMode; exports.moveTokenMode = moveTokenMode; exports.prepareTokenValue = prepareTokenValue; exports.createTokenVariable = createTokenVariable; exports.setTokenValue = setTokenValue; exports.renameTokenVariable = renameTokenVariable; exports.updateTokenVariable = updateTokenVariable; exports.parseTokenState = parseTokenState; exports.TokenStore = TokenStore; exports.createTokenStore = createTokenStore; exports.tokenSlug = tokenSlug; exports.getTokenCssName = getTokenCssName; exports.cssString = cssString; exports.formatTokenCssValue = formatTokenCssValue; exports.exportTokensCss = exportTokensCss; exports.getTokenCssVariables = getTokenCssVariables; exports.W3C_TOKENS_EXTENSION = W3C_TOKENS_EXTENSION; exports.exportW3CTokens = exportW3CTokens; exports.exportW3CTokensJson = exportW3CTokensJson; exports.importW3CTokens = importW3CTokens;
|
|
1406
|
+
//# sourceMappingURL=chunk-4BVP64JJ.cjs.map
|