@dloizides/logo-kit 0.0.0-stage → 0.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 +9 -0
- package/LICENSE +21 -0
- package/README.md +13 -2
- package/dist/cli.js +1487 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +363 -0
- package/dist/index.js +1624 -0
- package/dist/index.js.map +1 -0
- package/package.json +68 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,1624 @@
|
|
|
1
|
+
import { contrastRatio, PRESETS } from '@dloizides/design-tokens';
|
|
2
|
+
import { Resvg } from '@resvg/resvg-js';
|
|
3
|
+
import fs2 from 'fs';
|
|
4
|
+
import path3 from 'path';
|
|
5
|
+
import { execFileSync } from 'child_process';
|
|
6
|
+
|
|
7
|
+
// src/core/Mode.ts
|
|
8
|
+
var Mode = /* @__PURE__ */ ((Mode2) => {
|
|
9
|
+
Mode2["Light"] = "light";
|
|
10
|
+
Mode2["Dark"] = "dark";
|
|
11
|
+
return Mode2;
|
|
12
|
+
})(Mode || {});
|
|
13
|
+
var MODES = ["light" /* Light */, "dark" /* Dark */];
|
|
14
|
+
|
|
15
|
+
// src/core/CvdKind.ts
|
|
16
|
+
var CvdKind = /* @__PURE__ */ ((CvdKind2) => {
|
|
17
|
+
CvdKind2["Protan"] = "protan";
|
|
18
|
+
CvdKind2["Deutan"] = "deutan";
|
|
19
|
+
CvdKind2["Tritan"] = "tritan";
|
|
20
|
+
return CvdKind2;
|
|
21
|
+
})(CvdKind || {});
|
|
22
|
+
var CVD_KINDS = ["protan" /* Protan */, "deutan" /* Deutan */, "tritan" /* Tritan */];
|
|
23
|
+
var MACHADO = {
|
|
24
|
+
["protan" /* Protan */]: [[0.152286, 1.052583, -0.204868], [0.114503, 0.786281, 0.099216], [-3882e-6, -0.048116, 1.051998]],
|
|
25
|
+
["deutan" /* Deutan */]: [[0.367322, 0.860646, -0.227968], [0.280085, 0.672501, 0.047413], [-0.01182, 0.04294, 0.968881]],
|
|
26
|
+
["tritan" /* Tritan */]: [[1.255528, -0.076749, -0.178779], [-0.078411, 0.930809, 0.147602], [4733e-6, 0.691367, 0.3039]]
|
|
27
|
+
};
|
|
28
|
+
var HEX = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i;
|
|
29
|
+
var MAX = 255;
|
|
30
|
+
var GAMMA_KNEE = 0.04045;
|
|
31
|
+
var LINEAR_KNEE = 31308e-7;
|
|
32
|
+
var LAB_KNEE = 8856e-6;
|
|
33
|
+
function hexToRgb(hex) {
|
|
34
|
+
const match = HEX.exec(hex.trim());
|
|
35
|
+
if (!match?.[1]) {
|
|
36
|
+
throw new Error(`not a hex colour: ${hex}`);
|
|
37
|
+
}
|
|
38
|
+
const raw = match[1].length === 3 ? match[1].split("").map((c) => c + c).join("") : match[1];
|
|
39
|
+
return [0, 2, 4].map((i) => parseInt(raw.slice(i, i + 2), 16));
|
|
40
|
+
}
|
|
41
|
+
function rgbToHex(rgb) {
|
|
42
|
+
return `#${rgb.map((c) => Math.round(Math.min(MAX, Math.max(0, c))).toString(16).padStart(2, "0")).join("")}`;
|
|
43
|
+
}
|
|
44
|
+
var toLinear = (c) => {
|
|
45
|
+
const s = c / MAX;
|
|
46
|
+
return s <= GAMMA_KNEE ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
|
47
|
+
};
|
|
48
|
+
var fromLinear = (l) => {
|
|
49
|
+
const v = Math.min(1, Math.max(0, l));
|
|
50
|
+
return MAX * (v <= LINEAR_KNEE ? v * 12.92 : 1.055 * v ** (1 / 2.4) - 0.055);
|
|
51
|
+
};
|
|
52
|
+
function simulateCvd(hex, kind) {
|
|
53
|
+
const lin = hexToRgb(hex).map(toLinear);
|
|
54
|
+
const out = MACHADO[kind].map((row) => row[0] * (lin[0] ?? 0) + row[1] * (lin[1] ?? 0) + row[2] * (lin[2] ?? 0));
|
|
55
|
+
return rgbToHex(out.map(fromLinear));
|
|
56
|
+
}
|
|
57
|
+
function toLab(hex) {
|
|
58
|
+
const [r, g, b] = hexToRgb(hex).map(toLinear);
|
|
59
|
+
const xyz = [(0.4124 * r + 0.3576 * g + 0.1805 * b) / 0.95047, 0.2126 * r + 0.7152 * g + 0.0722 * b, (0.0193 * r + 0.1192 * g + 0.9505 * b) / 1.08883];
|
|
60
|
+
const f = (t) => t > LAB_KNEE ? Math.cbrt(t) : 7.787 * t + 16 / 116;
|
|
61
|
+
const [fx, fy, fz] = xyz.map(f);
|
|
62
|
+
return [116 * fy - 16, 500 * (fx - fy), 200 * (fy - fz)];
|
|
63
|
+
}
|
|
64
|
+
function deltaE(a, b) {
|
|
65
|
+
const la = toLab(a);
|
|
66
|
+
const lb = toLab(b);
|
|
67
|
+
return Math.hypot(la[0] - lb[0], la[1] - lb[1], la[2] - lb[2]);
|
|
68
|
+
}
|
|
69
|
+
function contrast(a, b) {
|
|
70
|
+
return contrastRatio(a, b);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/core/path.ts
|
|
74
|
+
var CMD = /^[A-Za-z]$/;
|
|
75
|
+
var CURVE_STEPS = 12;
|
|
76
|
+
var ARC_STEPS = 24;
|
|
77
|
+
var CURVES = /* @__PURE__ */ new Set(["c", "s", "q", "t"]);
|
|
78
|
+
var more = (c) => c.i < c.tokens.length && !CMD.test(c.tokens[c.i] ?? "Z");
|
|
79
|
+
var num = (c) => Number(c.tokens[c.i++]);
|
|
80
|
+
var pt = (c, rel) => {
|
|
81
|
+
const x = num(c);
|
|
82
|
+
const y = num(c);
|
|
83
|
+
return rel ? { x: c.cur.x + x, y: c.cur.y + y } : { x, y };
|
|
84
|
+
};
|
|
85
|
+
var push = (c, p) => {
|
|
86
|
+
c.sub.push(p);
|
|
87
|
+
c.cur = p;
|
|
88
|
+
};
|
|
89
|
+
var bez = (pts, t) => {
|
|
90
|
+
let level = pts;
|
|
91
|
+
while (level.length > 1) {
|
|
92
|
+
const prev = level;
|
|
93
|
+
level = prev.slice(1).map((p, k) => {
|
|
94
|
+
const q = prev[k] ?? p;
|
|
95
|
+
return { x: q.x + (p.x - q.x) * t, y: q.y + (p.y - q.y) * t };
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return level[0] ?? { x: 0, y: 0 };
|
|
99
|
+
};
|
|
100
|
+
var curve = (c, ctrl, end) => {
|
|
101
|
+
const pts = [c.cur, ...ctrl, end];
|
|
102
|
+
for (let k = 1; k <= CURVE_STEPS; k++) {
|
|
103
|
+
push(c, bez(pts, k / CURVE_STEPS));
|
|
104
|
+
}
|
|
105
|
+
c.ctrl = ctrl[ctrl.length - 1] ?? null;
|
|
106
|
+
};
|
|
107
|
+
var reflect = (c) => c.ctrl ? { x: 2 * c.cur.x - c.ctrl.x, y: 2 * c.cur.y - c.ctrl.y } : c.cur;
|
|
108
|
+
var SEPARATORS = /* @__PURE__ */ new Set([" ", ",", "\n", "\r", " "]);
|
|
109
|
+
var isCommand = (ch) => ch !== "e" && ch !== "E" && CMD.test(ch);
|
|
110
|
+
var startsNumber = (cur, ch) => {
|
|
111
|
+
const afterExponent = cur.endsWith("e") || cur.endsWith("E");
|
|
112
|
+
return ch === "-" && cur !== "" && !afterExponent || ch === "." && cur.includes(".");
|
|
113
|
+
};
|
|
114
|
+
function tokenizePath(d) {
|
|
115
|
+
const out = [];
|
|
116
|
+
let cur = "";
|
|
117
|
+
for (const ch of d) {
|
|
118
|
+
const separator = SEPARATORS.has(ch) || isCommand(ch) || startsNumber(cur, ch);
|
|
119
|
+
if (separator && cur !== "") {
|
|
120
|
+
out.push(cur);
|
|
121
|
+
cur = "";
|
|
122
|
+
}
|
|
123
|
+
if (isCommand(ch)) {
|
|
124
|
+
out.push(ch);
|
|
125
|
+
} else if (!SEPARATORS.has(ch)) {
|
|
126
|
+
cur += ch;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return cur !== "" ? [...out, cur] : out;
|
|
130
|
+
}
|
|
131
|
+
function vecAngle(ux, uy, vx, vy) {
|
|
132
|
+
return Math.atan2(ux * vy - uy * vx, ux * vx + uy * vy);
|
|
133
|
+
}
|
|
134
|
+
function arcPoints(p0, arc, p1) {
|
|
135
|
+
if (arc.radii.x === 0 || arc.radii.y === 0) {
|
|
136
|
+
return [p1];
|
|
137
|
+
}
|
|
138
|
+
const phi = arc.phiDeg * Math.PI / 180;
|
|
139
|
+
const cos = Math.cos(phi);
|
|
140
|
+
const sin = Math.sin(phi);
|
|
141
|
+
const x1 = cos * (p0.x - p1.x) / 2 + sin * (p0.y - p1.y) / 2;
|
|
142
|
+
const y1 = -sin * (p0.x - p1.x) / 2 + cos * (p0.y - p1.y) / 2;
|
|
143
|
+
const lambda = Math.max(1, Math.sqrt(x1 * x1 / (arc.radii.x * arc.radii.x) + y1 * y1 / (arc.radii.y * arc.radii.y)));
|
|
144
|
+
const rx = Math.abs(arc.radii.x) * lambda;
|
|
145
|
+
const ry = Math.abs(arc.radii.y) * lambda;
|
|
146
|
+
const den = rx * rx * y1 * y1 + ry * ry * x1 * x1;
|
|
147
|
+
const co = Math.sqrt(Math.max(0, (rx * rx * ry * ry - den) / den)) * (arc.large === arc.sweep ? -1 : 1);
|
|
148
|
+
const cx1 = co * rx * y1 / ry;
|
|
149
|
+
const cy1 = -co * ry * x1 / rx;
|
|
150
|
+
const cx = cos * cx1 - sin * cy1 + (p0.x + p1.x) / 2;
|
|
151
|
+
const cy = sin * cx1 + cos * cy1 + (p0.y + p1.y) / 2;
|
|
152
|
+
const t1 = vecAngle(1, 0, (x1 - cx1) / rx, (y1 - cy1) / ry);
|
|
153
|
+
let dt = vecAngle((x1 - cx1) / rx, (y1 - cy1) / ry, (-x1 - cx1) / rx, (-y1 - cy1) / ry);
|
|
154
|
+
if (!arc.sweep && dt > 0) {
|
|
155
|
+
dt -= 2 * Math.PI;
|
|
156
|
+
} else if (arc.sweep && dt < 0) {
|
|
157
|
+
dt += 2 * Math.PI;
|
|
158
|
+
}
|
|
159
|
+
return Array.from({ length: ARC_STEPS }, (_, k) => {
|
|
160
|
+
const t = t1 + dt * (k + 1) / ARC_STEPS;
|
|
161
|
+
return { x: cx + rx * Math.cos(t) * cos - ry * Math.sin(t) * sin, y: cy + rx * Math.cos(t) * sin + ry * Math.sin(t) * cos };
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
var moveTo = (c, rel) => {
|
|
165
|
+
if (c.sub.length > 1) {
|
|
166
|
+
c.subs.push(c.sub);
|
|
167
|
+
}
|
|
168
|
+
const p = pt(c, rel);
|
|
169
|
+
c.sub = [p];
|
|
170
|
+
c.cur = p;
|
|
171
|
+
c.start = p;
|
|
172
|
+
while (more(c)) {
|
|
173
|
+
push(c, pt(c, rel));
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
var arcTo = (c, rel) => {
|
|
177
|
+
const radii = { x: num(c), y: num(c) };
|
|
178
|
+
const phiDeg = num(c);
|
|
179
|
+
const large = num(c) !== 0;
|
|
180
|
+
const sweep = num(c) !== 0;
|
|
181
|
+
const end = pt(c, rel);
|
|
182
|
+
for (const p of arcPoints(c.cur, { radii, phiDeg, large, sweep }, end)) {
|
|
183
|
+
push(c, p);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
var HANDLERS = {
|
|
187
|
+
m: moveTo,
|
|
188
|
+
l: (c, rel) => push(c, pt(c, rel)),
|
|
189
|
+
h: (c, rel) => {
|
|
190
|
+
const x = num(c);
|
|
191
|
+
push(c, { x: rel ? c.cur.x + x : x, y: c.cur.y });
|
|
192
|
+
},
|
|
193
|
+
v: (c, rel) => {
|
|
194
|
+
const y = num(c);
|
|
195
|
+
push(c, { x: c.cur.x, y: rel ? c.cur.y + y : y });
|
|
196
|
+
},
|
|
197
|
+
c: (c, rel) => {
|
|
198
|
+
const a = pt(c, rel);
|
|
199
|
+
const b = pt(c, rel);
|
|
200
|
+
curve(c, [a, b], pt(c, rel));
|
|
201
|
+
},
|
|
202
|
+
s: (c, rel) => {
|
|
203
|
+
const a = reflect(c);
|
|
204
|
+
const b = pt(c, rel);
|
|
205
|
+
curve(c, [a, b], pt(c, rel));
|
|
206
|
+
},
|
|
207
|
+
q: (c, rel) => {
|
|
208
|
+
const a = pt(c, rel);
|
|
209
|
+
curve(c, [a], pt(c, rel));
|
|
210
|
+
},
|
|
211
|
+
t: (c, rel) => curve(c, [reflect(c)], pt(c, rel)),
|
|
212
|
+
a: arcTo
|
|
213
|
+
};
|
|
214
|
+
function closePath(c) {
|
|
215
|
+
c.subs.push(c.sub);
|
|
216
|
+
c.sub = [c.start];
|
|
217
|
+
c.cur = c.start;
|
|
218
|
+
}
|
|
219
|
+
function step(c, cmd) {
|
|
220
|
+
const lower = cmd.toLowerCase();
|
|
221
|
+
if (lower === "z") {
|
|
222
|
+
closePath(c);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const handler = HANDLERS[lower];
|
|
226
|
+
if (!handler) {
|
|
227
|
+
throw new Error(`unsupported path command ${cmd}`);
|
|
228
|
+
}
|
|
229
|
+
do {
|
|
230
|
+
handler(c, cmd === lower);
|
|
231
|
+
if (!CURVES.has(lower)) {
|
|
232
|
+
c.ctrl = null;
|
|
233
|
+
}
|
|
234
|
+
} while (lower !== "m" && more(c));
|
|
235
|
+
}
|
|
236
|
+
function flattenPath(d) {
|
|
237
|
+
const c = { tokens: tokenizePath(d), i: 0, cur: { x: 0, y: 0 }, start: { x: 0, y: 0 }, ctrl: null, sub: [], subs: [] };
|
|
238
|
+
while (c.i < c.tokens.length) {
|
|
239
|
+
step(c, c.tokens[c.i++] ?? "Z");
|
|
240
|
+
}
|
|
241
|
+
if (c.sub.length > 1) {
|
|
242
|
+
c.subs.push(c.sub);
|
|
243
|
+
}
|
|
244
|
+
return c.subs.filter((s) => s.length > 2);
|
|
245
|
+
}
|
|
246
|
+
var CHANNEL_TOLERANCE = 24;
|
|
247
|
+
var WHITE = 255;
|
|
248
|
+
var HALF = 128;
|
|
249
|
+
var ICO_HEADER = 6;
|
|
250
|
+
var ICO_ENTRY = 16;
|
|
251
|
+
var ICO_MAX_SIDE = 256;
|
|
252
|
+
var BITS = 32;
|
|
253
|
+
var options = (width, fontFiles) => ({
|
|
254
|
+
fitTo: { mode: "width", value: width },
|
|
255
|
+
font: { loadSystemFonts: false, fontFiles }
|
|
256
|
+
});
|
|
257
|
+
function renderSvg(svg2, width, fontFiles = []) {
|
|
258
|
+
const img = new Resvg(svg2, options(width, fontFiles)).render();
|
|
259
|
+
return { width: img.width, height: img.height, data: new Uint8Array(img.pixels) };
|
|
260
|
+
}
|
|
261
|
+
function renderPng(svg2, width, fontFiles = []) {
|
|
262
|
+
return new Resvg(svg2, options(width, fontFiles)).render().asPng();
|
|
263
|
+
}
|
|
264
|
+
function alphaMask(bmp) {
|
|
265
|
+
const out = new Uint8Array(bmp.width * bmp.height);
|
|
266
|
+
for (let i = 0; i < out.length; i++) {
|
|
267
|
+
out[i] = (bmp.data[i * 4 + 3] ?? 0) >= HALF ? 1 : 0;
|
|
268
|
+
}
|
|
269
|
+
return out;
|
|
270
|
+
}
|
|
271
|
+
var onWhite = (data, i) => {
|
|
272
|
+
const a = (data[i + 3] ?? 0) / WHITE;
|
|
273
|
+
return [0, 1, 2].map((k) => (data[i + k] ?? 0) * a + WHITE * (1 - a));
|
|
274
|
+
};
|
|
275
|
+
var differs = (x, y) => x.some((v, k) => Math.abs(v - (y[k] ?? 0)) > CHANNEL_TOLERANCE);
|
|
276
|
+
function inkBox(bmps) {
|
|
277
|
+
const box = { x0: Infinity, y0: Infinity, x1: -1, y1: -1 };
|
|
278
|
+
for (const bmp of bmps) {
|
|
279
|
+
const ground = onWhite(bmp.data, Math.floor(bmp.width / 2) * 4);
|
|
280
|
+
for (let p = 0; p < bmp.width * bmp.height; p++) {
|
|
281
|
+
if (differs(onWhite(bmp.data, p * 4), ground)) {
|
|
282
|
+
const x = p % bmp.width;
|
|
283
|
+
const y = Math.floor(p / bmp.width);
|
|
284
|
+
box.x0 = Math.min(box.x0, x);
|
|
285
|
+
box.y0 = Math.min(box.y0, y);
|
|
286
|
+
box.x1 = Math.max(box.x1, x);
|
|
287
|
+
box.y1 = Math.max(box.y1, y);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return box;
|
|
292
|
+
}
|
|
293
|
+
function pixelDiff(a, b) {
|
|
294
|
+
if (a.width !== b.width || a.height !== b.height) {
|
|
295
|
+
return 1;
|
|
296
|
+
}
|
|
297
|
+
const box = inkBox([a, b]);
|
|
298
|
+
if (box.x1 < 0) {
|
|
299
|
+
return 0;
|
|
300
|
+
}
|
|
301
|
+
let differ = 0;
|
|
302
|
+
for (let y = box.y0; y <= box.y1; y++) {
|
|
303
|
+
for (let x = box.x0; x <= box.x1; x++) {
|
|
304
|
+
const p = (y * a.width + x) * 4;
|
|
305
|
+
differ += differs(onWhite(a.data, p), onWhite(b.data, p)) ? 1 : 0;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return differ / ((box.x1 - box.x0 + 1) * (box.y1 - box.y0 + 1));
|
|
309
|
+
}
|
|
310
|
+
function pngSize(png) {
|
|
311
|
+
const view = new DataView(png.buffer, png.byteOffset, png.byteLength);
|
|
312
|
+
return { width: view.getUint32(16), height: view.getUint32(20) };
|
|
313
|
+
}
|
|
314
|
+
function buildIco(pngs) {
|
|
315
|
+
const header = Buffer.alloc(ICO_HEADER + ICO_ENTRY * pngs.length);
|
|
316
|
+
header.writeUInt16LE(1, 2);
|
|
317
|
+
header.writeUInt16LE(pngs.length, 4);
|
|
318
|
+
let offset = header.length;
|
|
319
|
+
pngs.forEach((png, k) => {
|
|
320
|
+
const { width, height } = pngSize(png);
|
|
321
|
+
const pos = ICO_HEADER + ICO_ENTRY * k;
|
|
322
|
+
header.writeUInt8(width >= ICO_MAX_SIDE ? 0 : width, pos);
|
|
323
|
+
header.writeUInt8(height >= ICO_MAX_SIDE ? 0 : height, pos + 1);
|
|
324
|
+
header.writeUInt16LE(1, pos + 4);
|
|
325
|
+
header.writeUInt16LE(BITS, pos + 6);
|
|
326
|
+
header.writeUInt32LE(png.length, pos + 8);
|
|
327
|
+
header.writeUInt32LE(offset, pos + 12);
|
|
328
|
+
offset += png.length;
|
|
329
|
+
});
|
|
330
|
+
return Buffer.concat([header, ...pngs.map((p) => Buffer.from(p))]);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// src/core/num.ts
|
|
334
|
+
var PLACES = 3;
|
|
335
|
+
function fmt(value) {
|
|
336
|
+
return String(Number(value.toFixed(PLACES)));
|
|
337
|
+
}
|
|
338
|
+
function escapeXml(text) {
|
|
339
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// src/core/svg.ts
|
|
343
|
+
var DEFAULT_SIZE = 256;
|
|
344
|
+
var colourOf = (colours, role, override) => {
|
|
345
|
+
if (override !== void 0) {
|
|
346
|
+
return override;
|
|
347
|
+
}
|
|
348
|
+
const hex = colours[role];
|
|
349
|
+
if (hex === void 0) {
|
|
350
|
+
throw new Error(`palette has no colour for role "${role}"`);
|
|
351
|
+
}
|
|
352
|
+
return hex;
|
|
353
|
+
};
|
|
354
|
+
function paintAttrs(item, colours, override) {
|
|
355
|
+
const fill = item.fill !== void 0 ? colourOf(colours, item.fill, override) : "none";
|
|
356
|
+
const stroke = item.stroke !== void 0 ? ` stroke="${colourOf(colours, item.stroke, override)}" stroke-width="${item.width ?? 1}"` : "";
|
|
357
|
+
return `fill="${fill}"${stroke}`;
|
|
358
|
+
}
|
|
359
|
+
function layerSvg(layer, index, colours, mode, opts = {}) {
|
|
360
|
+
const items = mode === "dark" /* Dark */ ? layer.paint.dark : layer.paint.light;
|
|
361
|
+
const rule = layer.evenOdd === true ? ' fill-rule="evenodd"' : "";
|
|
362
|
+
const len = opts.drawLayers?.has(layer.name) === true ? ' pathLength="1"' : "";
|
|
363
|
+
const path5 = (item, head2) => `<path${head2} ${paintAttrs(item, colours, opts.colourOverride)}${rule}${len} d="${layer.d}"/>`;
|
|
364
|
+
const head = ` id="mark-${layer.name}" class="l${index}"`;
|
|
365
|
+
const body = items.length === 1 && items[0] ? path5(items[0], head) : `<g${head}>${items.map((item) => path5(item, "")).join("")}</g>`;
|
|
366
|
+
return layer.transform !== void 0 ? `<g transform="${layer.transform}">${body}</g>` : body;
|
|
367
|
+
}
|
|
368
|
+
function markBody(mark, palette, mode, opts = {}) {
|
|
369
|
+
const colours = mode === "dark" /* Dark */ ? palette.dark : palette.light;
|
|
370
|
+
return `<g id="mark">${mark.layers.map((layer, i) => layerSvg(layer, i, colours, mode, opts)).join("")}</g>`;
|
|
371
|
+
}
|
|
372
|
+
function markSvg(mark, palette, mode, opts) {
|
|
373
|
+
const size = opts.size ?? DEFAULT_SIZE;
|
|
374
|
+
const label = escapeXml(opts.label);
|
|
375
|
+
const style = opts.style !== void 0 ? `<style>${opts.style}</style>` : "";
|
|
376
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="${mark.viewBox}" width="${size}" height="${size}" role="img" aria-label="${label}"><title>${label}</title>${style}${markBody(mark, palette, mode, opts)}${opts.overlay ?? ""}</svg>`;
|
|
377
|
+
}
|
|
378
|
+
function viewBoxOf(mark) {
|
|
379
|
+
const [x = 0, y = 0, w = 1, h = 1] = mark.viewBox.trim().split(/[\s,]+/).map(Number);
|
|
380
|
+
return { x, y, w, h };
|
|
381
|
+
}
|
|
382
|
+
function placeMark(mark, palette, mode, box) {
|
|
383
|
+
return `<svg x="${box.x}" y="${box.y}" width="${box.size}" height="${box.size}" viewBox="${mark.viewBox}">${markBody(mark, palette, mode)}</svg>`;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// src/motion/MotionPreset.ts
|
|
387
|
+
var MotionPreset = /* @__PURE__ */ ((MotionPreset2) => {
|
|
388
|
+
MotionPreset2["Draw"] = "draw";
|
|
389
|
+
MotionPreset2["Flood"] = "flood";
|
|
390
|
+
MotionPreset2["StaggerRise"] = "stagger-rise";
|
|
391
|
+
MotionPreset2["ScalePop"] = "scale-pop";
|
|
392
|
+
MotionPreset2["Orbit"] = "orbit";
|
|
393
|
+
MotionPreset2["Wipe"] = "wipe";
|
|
394
|
+
MotionPreset2["MorphFromCircle"] = "morph-from-circle";
|
|
395
|
+
MotionPreset2["Sweep"] = "sweep";
|
|
396
|
+
MotionPreset2["Pulse"] = "pulse";
|
|
397
|
+
MotionPreset2["Spread"] = "spread";
|
|
398
|
+
return MotionPreset2;
|
|
399
|
+
})(MotionPreset || {});
|
|
400
|
+
var INTRO_PRESETS = [
|
|
401
|
+
"draw" /* Draw */,
|
|
402
|
+
"flood" /* Flood */,
|
|
403
|
+
"stagger-rise" /* StaggerRise */,
|
|
404
|
+
"scale-pop" /* ScalePop */,
|
|
405
|
+
"orbit" /* Orbit */,
|
|
406
|
+
"wipe" /* Wipe */,
|
|
407
|
+
"morph-from-circle" /* MorphFromCircle */,
|
|
408
|
+
"sweep" /* Sweep */,
|
|
409
|
+
"pulse" /* Pulse */
|
|
410
|
+
];
|
|
411
|
+
var MICRO_PRESETS = ["spread" /* Spread */];
|
|
412
|
+
|
|
413
|
+
// src/motion/defaults.ts
|
|
414
|
+
var INTRO_CAP_MS = 1200;
|
|
415
|
+
var MICRO_CAP_MS = 300;
|
|
416
|
+
var EASE = "cubic-bezier(0.2,0,0,1)";
|
|
417
|
+
var EASE_IN_FIRST = "cubic-bezier(0,0,0,1)";
|
|
418
|
+
var MARK_TARGET = "@mark";
|
|
419
|
+
var PRESET_DEFAULTS = {
|
|
420
|
+
["draw" /* Draw */]: { preset: "draw" /* Draw */, durationMs: 700, stepMs: 120 },
|
|
421
|
+
["flood" /* Flood */]: { preset: "flood" /* Flood */, durationMs: 500, delayMs: 300, stepMs: 80 },
|
|
422
|
+
["stagger-rise" /* StaggerRise */]: { preset: "stagger-rise" /* StaggerRise */, durationMs: 600, stepMs: 150, distance: 4 },
|
|
423
|
+
["scale-pop" /* ScalePop */]: { preset: "scale-pop" /* ScalePop */, durationMs: 500, stepMs: 120 },
|
|
424
|
+
["orbit" /* Orbit */]: { preset: "orbit" /* Orbit */, durationMs: 800, stepMs: 100 },
|
|
425
|
+
["wipe" /* Wipe */]: { preset: "wipe" /* Wipe */, durationMs: 700, stepMs: 120 },
|
|
426
|
+
["morph-from-circle" /* MorphFromCircle */]: { preset: "morph-from-circle" /* MorphFromCircle */, durationMs: 1200, stops: [0, 40, 100] },
|
|
427
|
+
["sweep" /* Sweep */]: { preset: "sweep" /* Sweep */, durationMs: 600, delayMs: 400, stepMs: 60, share: 0.12, width: 2 },
|
|
428
|
+
["pulse" /* Pulse */]: { preset: "pulse" /* Pulse */, durationMs: 400, delayMs: 700, layers: [MARK_TARGET], scale: 1.07 },
|
|
429
|
+
["spread" /* Spread */]: { preset: "spread" /* Spread */, durationMs: 300, distance: 1.6 }
|
|
430
|
+
};
|
|
431
|
+
var DEFAULT_MOTION_CONFIG = {
|
|
432
|
+
intro: [{ preset: "stagger-rise" /* StaggerRise */, durationMs: 600, stepMs: 150, distance: 4 }],
|
|
433
|
+
micro: [{ preset: "spread" /* Spread */, durationMs: 300, distance: 1.6, easing: EASE }]
|
|
434
|
+
};
|
|
435
|
+
function presetOf(id) {
|
|
436
|
+
const preset = PRESETS[id];
|
|
437
|
+
if (!preset) {
|
|
438
|
+
throw new Error(`unknown design-tokens preset "${id}", known: ${Object.keys(PRESETS).join(", ")}`);
|
|
439
|
+
}
|
|
440
|
+
return preset;
|
|
441
|
+
}
|
|
442
|
+
function resolveToken(ref) {
|
|
443
|
+
if (ref.startsWith("#")) {
|
|
444
|
+
return ref;
|
|
445
|
+
}
|
|
446
|
+
const [id = "", ...path5] = ref.split(".");
|
|
447
|
+
let node = presetOf(id);
|
|
448
|
+
for (const key2 of path5) {
|
|
449
|
+
node = typeof node === "object" && node !== null ? node[key2] : void 0;
|
|
450
|
+
}
|
|
451
|
+
if (typeof node !== "string") {
|
|
452
|
+
throw new Error(`token "${ref}" is not a colour`);
|
|
453
|
+
}
|
|
454
|
+
return node;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// src/config/loadBrand.ts
|
|
458
|
+
var DEFAULT_ICONS = { dark: true, share: 0.66, radius: 0.2 };
|
|
459
|
+
var DEFAULT_FONT = "Hanken Grotesk, Arial, sans-serif";
|
|
460
|
+
var DEFAULT_GENERATE = { seed: 1, count: 200 };
|
|
461
|
+
function toLayer(raw) {
|
|
462
|
+
const paint = raw.paint ?? (raw.role !== void 0 ? { light: [{ fill: raw.role }], dark: [{ fill: raw.role }] } : void 0);
|
|
463
|
+
if (!paint) {
|
|
464
|
+
throw new Error(`layer "${raw.name}" needs "role" or "paint"`);
|
|
465
|
+
}
|
|
466
|
+
return { name: raw.name, d: raw.d, paint, ...raw.transform !== void 0 ? { transform: raw.transform } : {}, ...raw.evenOdd === true ? { evenOdd: true } : {} };
|
|
467
|
+
}
|
|
468
|
+
var resolveAll = (refs) => Object.fromEntries(Object.entries(refs).map(([role, ref]) => [role, resolveToken(ref)]));
|
|
469
|
+
function toPalette(raw, name) {
|
|
470
|
+
const light = resolveAll(raw.light);
|
|
471
|
+
const dark = resolveAll(raw.dark);
|
|
472
|
+
const mono = raw.mono !== void 0 ? resolveToken(raw.mono) : light["text"] ?? "#000000";
|
|
473
|
+
return { name, light, dark, mono };
|
|
474
|
+
}
|
|
475
|
+
function parseBrand(raw, baseDir) {
|
|
476
|
+
const firstRef = Object.values(raw.palette.light).find((ref) => !ref.startsWith("#"));
|
|
477
|
+
const small = raw.smallMark;
|
|
478
|
+
return {
|
|
479
|
+
icons: { ...DEFAULT_ICONS, ...raw.icons },
|
|
480
|
+
...small ? { smallMark: { ...small, light: resolveToken(small.light), dark: resolveToken(small.dark) } } : {},
|
|
481
|
+
name: raw.name,
|
|
482
|
+
slug: raw.slug,
|
|
483
|
+
wordmark: raw.wordmark ?? { fontFamily: DEFAULT_FONT },
|
|
484
|
+
mark: { id: raw.slug, viewBox: raw.mark.viewBox, layers: raw.mark.layers.map(toLayer) },
|
|
485
|
+
palette: toPalette(raw.palette, raw.slug),
|
|
486
|
+
motion: { ...DEFAULT_MOTION_CONFIG, ...raw.motion },
|
|
487
|
+
generate: raw.generate ?? DEFAULT_GENERATE,
|
|
488
|
+
tokens: raw.tokens ?? firstRef?.split(".")[0] ?? "mooncube",
|
|
489
|
+
baseDir
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
function loadBrand(file) {
|
|
493
|
+
const raw = JSON.parse(fs2.readFileSync(file, "utf8"));
|
|
494
|
+
return parseBrand(raw, path3.dirname(path3.resolve(file)));
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// src/core/rng.ts
|
|
498
|
+
var UINT32 = 4294967296;
|
|
499
|
+
function seededRandom(seed) {
|
|
500
|
+
let state = seed >>> 0;
|
|
501
|
+
return () => {
|
|
502
|
+
state = state + 1831565813 >>> 0;
|
|
503
|
+
let t = state;
|
|
504
|
+
t = Math.imul(t ^ t >>> 15, t | 1);
|
|
505
|
+
t ^= t + Math.imul(t ^ t >>> 7, t | 61);
|
|
506
|
+
return ((t ^ t >>> 14) >>> 0) / UINT32;
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
function pick(random, items) {
|
|
510
|
+
const item = items[Math.floor(random() * items.length)];
|
|
511
|
+
if (item === void 0) {
|
|
512
|
+
throw new Error("pick: empty list");
|
|
513
|
+
}
|
|
514
|
+
return item;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// src/core/polygon.ts
|
|
518
|
+
function polygonsToD(polys) {
|
|
519
|
+
const point = (p) => `${fmt(p.x)} ${fmt(p.y)}`;
|
|
520
|
+
const ring = (poly) => poly.map(point).join("L");
|
|
521
|
+
return polys.map((poly) => `M${ring(poly)}Z`).join("");
|
|
522
|
+
}
|
|
523
|
+
function resample(poly, n) {
|
|
524
|
+
const first = poly[0] ?? { x: 0, y: 0 };
|
|
525
|
+
const closed = [...poly, first];
|
|
526
|
+
const lengths = closed.slice(1).map((p, k) => Math.hypot(p.x - (closed[k]?.x ?? 0), p.y - (closed[k]?.y ?? 0)));
|
|
527
|
+
const total = lengths.reduce((a, b) => a + b, 0);
|
|
528
|
+
const out = [];
|
|
529
|
+
let seg = 0;
|
|
530
|
+
let walked = 0;
|
|
531
|
+
for (let k = 0; k < n; k++) {
|
|
532
|
+
const target = total * k / n;
|
|
533
|
+
while (seg < lengths.length - 1 && walked + (lengths[seg] ?? 0) < target) {
|
|
534
|
+
walked += lengths[seg] ?? 0;
|
|
535
|
+
seg++;
|
|
536
|
+
}
|
|
537
|
+
const a = closed[seg] ?? first;
|
|
538
|
+
const b = closed[seg + 1] ?? a;
|
|
539
|
+
const len = lengths[seg] ?? 0;
|
|
540
|
+
const t = len > 0 ? (target - walked) / len : 0;
|
|
541
|
+
out.push({ x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t });
|
|
542
|
+
}
|
|
543
|
+
return out;
|
|
544
|
+
}
|
|
545
|
+
function circlePoints(c, r, n) {
|
|
546
|
+
return Array.from({ length: n }, (_, k) => {
|
|
547
|
+
const t = -Math.PI / 2 + 2 * Math.PI * k / n;
|
|
548
|
+
return { x: c.x + r * Math.cos(t), y: c.y + r * Math.sin(t) };
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
function centroid(pts) {
|
|
552
|
+
const n = Math.max(1, pts.length);
|
|
553
|
+
return { x: pts.reduce((s, p) => s + p.x, 0) / n, y: pts.reduce((s, p) => s + p.y, 0) / n };
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
// src/generate/shapes.ts
|
|
557
|
+
var CIRCLE_N = 48;
|
|
558
|
+
var ORIGIN = { x: 0, y: 0 };
|
|
559
|
+
var SQRT3_2 = Math.sqrt(3) / 2;
|
|
560
|
+
var FACE_SHRINK = 0.9;
|
|
561
|
+
var ngon = (n, r, start = -Math.PI / 2) => Array.from({ length: n }, (_, k) => ({ x: r * Math.cos(start + 2 * Math.PI * k / n), y: r * Math.sin(start + 2 * Math.PI * k / n) }));
|
|
562
|
+
var shrink = (poly, s) => {
|
|
563
|
+
const c = poly.reduce((a, p) => ({ x: a.x + p.x / poly.length, y: a.y + p.y / poly.length }), ORIGIN);
|
|
564
|
+
return poly.map((p) => ({ x: c.x + (p.x - c.x) * s, y: c.y + (p.y - c.y) * s }));
|
|
565
|
+
};
|
|
566
|
+
var arcPts = (r, from, to, n) => Array.from({ length: n + 1 }, (_, k) => ({ x: r * Math.cos(from + (to - from) * k / n), y: r * Math.sin(from + (to - from) * k / n) }));
|
|
567
|
+
function crescent(dx = 0.36, r = 0.83) {
|
|
568
|
+
const ix = (1 - r * r + dx * dx) / (2 * dx);
|
|
569
|
+
const theta = Math.acos(Math.min(1, ix));
|
|
570
|
+
const phi = Math.atan2(Math.sin(theta), ix - dx);
|
|
571
|
+
const outer = arcPts(1, theta, 2 * Math.PI - theta, CIRCLE_N);
|
|
572
|
+
const inner = arcPts(r, 2 * Math.PI - phi, phi, CIRCLE_N).map((p) => ({ x: p.x + dx, y: p.y }));
|
|
573
|
+
return [[...outer, ...inner]];
|
|
574
|
+
}
|
|
575
|
+
function cubeFaces() {
|
|
576
|
+
const top = [{ x: 0, y: -1 }, { x: SQRT3_2, y: -0.5 }, { x: 0, y: 0 }, { x: -SQRT3_2, y: -0.5 }];
|
|
577
|
+
const left = [{ x: -SQRT3_2, y: -0.5 }, { x: 0, y: 0 }, { x: 0, y: 1 }, { x: -SQRT3_2, y: 0.5 }];
|
|
578
|
+
const right = [{ x: SQRT3_2, y: -0.5 }, { x: SQRT3_2, y: 0.5 }, { x: 0, y: 1 }, { x: 0, y: 0 }];
|
|
579
|
+
return [top, left, right].map((f) => shrink(f, FACE_SHRINK));
|
|
580
|
+
}
|
|
581
|
+
var band = (outer, inner, start, end) => [[...arcPts(outer, start, end, CIRCLE_N), ...arcPts(inner, end, start, CIRCLE_N)]];
|
|
582
|
+
var rect = (x, y, w, h) => [{ x, y }, { x: x + w, y }, { x: x + w, y: y + h }, { x, y: y + h }];
|
|
583
|
+
var star = (n, inner) => ngon(2 * n, 1).map((p, k) => k % 2 === 1 ? { x: p.x * inner, y: p.y * inner } : p);
|
|
584
|
+
var wave = () => {
|
|
585
|
+
const xs = Array.from({ length: 25 }, (_, k) => -1 + k / 12);
|
|
586
|
+
const back = [...xs];
|
|
587
|
+
back.reverse();
|
|
588
|
+
return [...xs.map((x) => ({ x, y: -0.3 + 0.22 * Math.sin(x * Math.PI * 1.5) })), ...back.map((x) => ({ x, y: 0.3 + 0.22 * Math.sin(x * Math.PI * 1.5) }))];
|
|
589
|
+
};
|
|
590
|
+
var grid = () => [-0.7, 0, 0.7].flatMap((y) => [-0.7, 0, 0.7].map((x) => rect(x - 0.24, y - 0.24, 0.48, 0.48)));
|
|
591
|
+
var PRIMITIVES = {
|
|
592
|
+
disc: () => [circlePoints(ORIGIN, 1, CIRCLE_N)],
|
|
593
|
+
ring: () => [circlePoints(ORIGIN, 1, CIRCLE_N), circlePoints(ORIGIN, 0.6, CIRCLE_N)],
|
|
594
|
+
crescent: () => crescent(),
|
|
595
|
+
cube: cubeFaces,
|
|
596
|
+
hexagon: () => [ngon(6, 1)],
|
|
597
|
+
arc: () => band(1, 0.62, Math.PI * 0.75, Math.PI * 2.25),
|
|
598
|
+
star4: () => [star(4, 0.42)],
|
|
599
|
+
star8: () => [star(8, 0.62)],
|
|
600
|
+
square: () => [rect(-0.85, -0.85, 1.7, 1.7)],
|
|
601
|
+
triangle: () => [ngon(3, 1)],
|
|
602
|
+
diamond: () => [ngon(4, 1)],
|
|
603
|
+
wave: () => [wave()],
|
|
604
|
+
grid,
|
|
605
|
+
bars: () => [rect(-1, -0.8, 2, 0.4), rect(-1, -0.2, 1.5, 0.4), rect(-1, 0.4, 1, 0.4)]
|
|
606
|
+
};
|
|
607
|
+
var SPLIT_PARTS = /* @__PURE__ */ new Set(["cube"]);
|
|
608
|
+
var EVEN_ODD = /* @__PURE__ */ new Set(["ring"]);
|
|
609
|
+
|
|
610
|
+
// src/generate/generate.ts
|
|
611
|
+
var VIEW = 64;
|
|
612
|
+
var HALF2 = VIEW / 2;
|
|
613
|
+
var UNIT = 28;
|
|
614
|
+
var NAMES = Object.keys(PRIMITIVES);
|
|
615
|
+
var ANGLES = [0, 0, 0, 15, 30, 45, 90];
|
|
616
|
+
var map = (polys, f) => polys.map((poly) => poly.map(f));
|
|
617
|
+
var place = (polys, s, cx, cy) => map(polys, (p) => ({ x: cx + p.x * s, y: cy + p.y * s }));
|
|
618
|
+
var rotate = (polys, deg) => {
|
|
619
|
+
const a = deg * Math.PI / 180;
|
|
620
|
+
return map(polys, (p) => ({ x: p.x * Math.cos(a) - p.y * Math.sin(a), y: p.x * Math.sin(a) + p.y * Math.cos(a) }));
|
|
621
|
+
};
|
|
622
|
+
var mirrorX = (polys) => map(polys, (p) => ({ x: -p.x, y: p.y })).map((poly) => [...poly].reverse());
|
|
623
|
+
function parts(name, s, cx, cy, role) {
|
|
624
|
+
const builder = PRIMITIVES[name];
|
|
625
|
+
if (!builder) {
|
|
626
|
+
throw new Error(`unknown primitive ${name}`);
|
|
627
|
+
}
|
|
628
|
+
const polys = place(builder(), s, cx, cy);
|
|
629
|
+
if (SPLIT_PARTS.has(name)) {
|
|
630
|
+
return polys.map((poly, k) => ({ name: `${name}-${k}`, polys: [poly], role: k === 0 ? "a" : "b", evenOdd: false }));
|
|
631
|
+
}
|
|
632
|
+
return [{ name, polys, role, evenOdd: EVEN_ODD.has(name) }];
|
|
633
|
+
}
|
|
634
|
+
var COMBINATORS = {
|
|
635
|
+
single: (_r, a) => parts(a, 1, 0, 0, "a"),
|
|
636
|
+
overlap: (_r, a, b) => [...parts(a, 0.68, -0.3, 0, "a"), ...parts(b, 0.68, 0.3, 0, "b")],
|
|
637
|
+
nest: (_r, a, b) => [...parts(a, 1, 0, 0, "a"), ...parts(b, 0.42, 0, 0, "b")],
|
|
638
|
+
orbit: (r, a, b) => {
|
|
639
|
+
const t = pick(r, [0, 45, 90, 135, 180, 225, 270, 315]) * (Math.PI / 180);
|
|
640
|
+
return [...parts(a, 0.72, 0, 0, "a"), ...parts(b, 0.24, 0.82 * Math.cos(t), 0.82 * Math.sin(t), "b")];
|
|
641
|
+
},
|
|
642
|
+
repeat: (r, a) => {
|
|
643
|
+
const n = pick(r, [3, 4, 5, 6]);
|
|
644
|
+
return Array.from({ length: n }, (_, k) => {
|
|
645
|
+
const t = -Math.PI / 2 + 2 * Math.PI * k / n;
|
|
646
|
+
return parts(a, 0.34, 0.6 * Math.cos(t), 0.6 * Math.sin(t), k % 2 === 0 ? "a" : "b").map((p) => ({ ...p, name: `${p.name}-${k}` }));
|
|
647
|
+
}).flat();
|
|
648
|
+
},
|
|
649
|
+
mirror: (_r, a) => {
|
|
650
|
+
const left = parts(a, 0.5, -0.45, 0, "a");
|
|
651
|
+
return [...left, ...left.map((p) => ({ ...p, name: `${p.name}-m`, polys: mirrorX(p.polys), role: "b" }))];
|
|
652
|
+
},
|
|
653
|
+
cut: (_r, a, b) => {
|
|
654
|
+
const pa = parts(a, 1, 0, 0, "a");
|
|
655
|
+
const pb = parts(b, 0.5, 0.25, -0.2, "a");
|
|
656
|
+
return [{ name: `${a}-cut-${b}`, polys: [...pa.flatMap((p) => p.polys), ...pb.flatMap((p) => p.polys)], role: "a", evenOdd: true }];
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
var COMBINATOR_NAMES = Object.keys(COMBINATORS);
|
|
660
|
+
function toLayer2(p, deg) {
|
|
661
|
+
const polys = place(rotate(p.polys, deg), UNIT, HALF2, HALF2);
|
|
662
|
+
const paint = { light: [{ fill: p.role }], dark: [{ fill: p.role }] };
|
|
663
|
+
return { name: p.name, d: polygonsToD(polys), paint, ...p.evenOdd ? { evenOdd: true } : {} };
|
|
664
|
+
}
|
|
665
|
+
function oneVariant(r, id) {
|
|
666
|
+
const combinator = pick(r, COMBINATOR_NAMES);
|
|
667
|
+
const a = pick(r, NAMES);
|
|
668
|
+
const b = pick(r, NAMES);
|
|
669
|
+
const deg = pick(r, ANGLES);
|
|
670
|
+
const build = COMBINATORS[combinator] ?? COMBINATORS["single"];
|
|
671
|
+
const placed = build ? build(r, a, b) : [];
|
|
672
|
+
const unary = combinator === "single" || combinator === "repeat" || combinator === "mirror";
|
|
673
|
+
const args = (unary ? [a] : [a, b]).join(",");
|
|
674
|
+
const recipe = `${combinator}(${args}) rotate ${deg}`;
|
|
675
|
+
return { id, recipe, mark: { id, viewBox: `0 0 ${VIEW} ${VIEW}`, layers: placed.map((p) => toLayer2(p, deg)) } };
|
|
676
|
+
}
|
|
677
|
+
function generateVariants(seed, count) {
|
|
678
|
+
const r = seededRandom(seed);
|
|
679
|
+
return Array.from({ length: count }, (_, k) => oneVariant(r, `s${seed}-${String(k).padStart(3, "0")}`));
|
|
680
|
+
}
|
|
681
|
+
function primitiveMark(name) {
|
|
682
|
+
return { id: name, viewBox: `0 0 ${VIEW} ${VIEW}`, layers: parts(name, 1, 0, 0, "a").map((p) => toLayer2(p, 0)) };
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
// src/palette/paletteChecks.ts
|
|
686
|
+
var MIN_CONTRAST = 3;
|
|
687
|
+
var MIN_CVD_DELTA_E = 10;
|
|
688
|
+
var bgOf = (colours) => colours["background"] ?? "#ffffff";
|
|
689
|
+
function contrastFailures(palette, roles) {
|
|
690
|
+
const out = [];
|
|
691
|
+
for (const [mode, colours] of [["light", palette.light], ["dark", palette.dark]]) {
|
|
692
|
+
for (const role of roles) {
|
|
693
|
+
const hex = colours[role];
|
|
694
|
+
if (hex === void 0) {
|
|
695
|
+
out.push(`contrast: ${mode} has no colour for "${role}"`);
|
|
696
|
+
} else if (contrast(hex, bgOf(colours)) < MIN_CONTRAST) {
|
|
697
|
+
out.push(`contrast: ${mode} "${role}" ${hex} is ${contrast(hex, bgOf(colours)).toFixed(2)}:1 on ${bgOf(colours)}`);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
return out;
|
|
702
|
+
}
|
|
703
|
+
function cvdModeFailures(colours, roles, mode) {
|
|
704
|
+
const out = [];
|
|
705
|
+
const hexes = [...new Set(roles.map((r) => colours[r]).filter((h) => h !== void 0))];
|
|
706
|
+
for (const kind of CVD_KINDS) {
|
|
707
|
+
const sim = hexes.map((h) => simulateCvd(h, kind));
|
|
708
|
+
const bg = simulateCvd(bgOf(colours), kind);
|
|
709
|
+
sim.forEach((s, i) => {
|
|
710
|
+
if (contrast(s, bg) < MIN_CONTRAST) {
|
|
711
|
+
out.push(`cvd: ${mode} ${hexes[i] ?? ""} drops under 3:1 for ${kind}`);
|
|
712
|
+
}
|
|
713
|
+
sim.slice(i + 1).forEach((t, j) => {
|
|
714
|
+
if (deltaE(s, t) < MIN_CVD_DELTA_E) {
|
|
715
|
+
out.push(`cvd: ${mode} ${hexes[i] ?? ""} and ${hexes[i + j + 1] ?? ""} look the same for ${kind}`);
|
|
716
|
+
}
|
|
717
|
+
});
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
return out;
|
|
721
|
+
}
|
|
722
|
+
function cvdFailures(palette, roles) {
|
|
723
|
+
return [...cvdModeFailures(palette.light, roles, "light"), ...cvdModeFailures(palette.dark, roles, "dark")];
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
// src/palette/roles.ts
|
|
727
|
+
function rolesOf(mark) {
|
|
728
|
+
const roles = [];
|
|
729
|
+
for (const layer of mark.layers) {
|
|
730
|
+
for (const item of [...layer.paint.light, ...layer.paint.dark]) {
|
|
731
|
+
for (const role of [item.fill, item.stroke]) {
|
|
732
|
+
if (role !== void 0 && !roles.includes(role)) {
|
|
733
|
+
roles.push(role);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
return roles;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
// src/checks/grid.ts
|
|
742
|
+
var GRID = 24;
|
|
743
|
+
var SAMPLES = 3;
|
|
744
|
+
var MAJORITY = 5;
|
|
745
|
+
function maskBox(mask, w, h) {
|
|
746
|
+
let x0 = w;
|
|
747
|
+
let y0 = h;
|
|
748
|
+
let x1 = -1;
|
|
749
|
+
let y1 = -1;
|
|
750
|
+
for (let y = 0; y < h; y++) {
|
|
751
|
+
for (let x = 0; x < w; x++) {
|
|
752
|
+
if (mask[y * w + x] === 1) {
|
|
753
|
+
x0 = Math.min(x0, x);
|
|
754
|
+
y0 = Math.min(y0, y);
|
|
755
|
+
x1 = Math.max(x1, x);
|
|
756
|
+
y1 = Math.max(y1, y);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
return x1 < 0 ? null : { x: x0, y: y0, w: x1 - x0 + 1, h: y1 - y0 + 1 };
|
|
761
|
+
}
|
|
762
|
+
function normalise(mask, w, h) {
|
|
763
|
+
const out = new Uint8Array(GRID * GRID);
|
|
764
|
+
const box = maskBox(mask, w, h);
|
|
765
|
+
if (!box) {
|
|
766
|
+
return out;
|
|
767
|
+
}
|
|
768
|
+
const side = Math.max(box.w, box.h);
|
|
769
|
+
const ox = box.x - (side - box.w) / 2;
|
|
770
|
+
const oy = box.y - (side - box.h) / 2;
|
|
771
|
+
for (let gy = 0; gy < GRID; gy++) {
|
|
772
|
+
for (let gx = 0; gx < GRID; gx++) {
|
|
773
|
+
let hits = 0;
|
|
774
|
+
for (let s = 0; s < SAMPLES * SAMPLES; s++) {
|
|
775
|
+
const px = Math.floor(ox + (gx + (s % SAMPLES + 0.5) / SAMPLES) * side / GRID);
|
|
776
|
+
const py = Math.floor(oy + (gy + (Math.floor(s / SAMPLES) + 0.5) / SAMPLES) * side / GRID);
|
|
777
|
+
hits += px >= 0 && py >= 0 && px < w && py < h ? mask[py * w + px] ?? 0 : 0;
|
|
778
|
+
}
|
|
779
|
+
out[gy * GRID + gx] = hits >= MAJORITY ? 1 : 0;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
return out;
|
|
783
|
+
}
|
|
784
|
+
var rot90 = (g) => g.map((_, i) => g[(GRID - 1 - i % GRID) * GRID + Math.floor(i / GRID)] ?? 0);
|
|
785
|
+
var mirror = (g) => g.map((_, i) => g[Math.floor(i / GRID) * GRID + (GRID - 1 - i % GRID)] ?? 0);
|
|
786
|
+
function orientations(g) {
|
|
787
|
+
const out = [];
|
|
788
|
+
let cur = g;
|
|
789
|
+
for (let k = 0; k < 4; k++) {
|
|
790
|
+
out.push(cur, mirror(cur));
|
|
791
|
+
cur = rot90(cur);
|
|
792
|
+
}
|
|
793
|
+
return out;
|
|
794
|
+
}
|
|
795
|
+
var cell = (g, x, y) => x >= 0 && y >= 0 && x < GRID && y < GRID ? g[y * GRID + x] ?? 0 : 0;
|
|
796
|
+
function iouAt(a, b, dx, dy) {
|
|
797
|
+
let inter = 0;
|
|
798
|
+
let union = 0;
|
|
799
|
+
for (let i = 0; i < GRID * GRID; i++) {
|
|
800
|
+
const va = a[i] ?? 0;
|
|
801
|
+
const vb = cell(b, i % GRID + dx, Math.floor(i / GRID) + dy);
|
|
802
|
+
inter += va & vb;
|
|
803
|
+
union += va | vb;
|
|
804
|
+
}
|
|
805
|
+
return union > 0 ? inter / union : 0;
|
|
806
|
+
}
|
|
807
|
+
function bestIou(a, b) {
|
|
808
|
+
let best = 0;
|
|
809
|
+
for (let k = 0; k < 9; k++) {
|
|
810
|
+
best = Math.max(best, iouAt(a, b, k % 3 - 1, Math.floor(k / 3) - 1));
|
|
811
|
+
}
|
|
812
|
+
return best;
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
// src/checks/visible.ts
|
|
816
|
+
var SEEN = 60;
|
|
817
|
+
function visibleShare(tile, ink2) {
|
|
818
|
+
const mask = alphaMask(ink2);
|
|
819
|
+
const ground = [0, 1, 2].map((k) => tile.data[k] ?? 0);
|
|
820
|
+
let total = 0;
|
|
821
|
+
let seen = 0;
|
|
822
|
+
mask.forEach((v, p) => {
|
|
823
|
+
if (v === 1) {
|
|
824
|
+
total++;
|
|
825
|
+
const diff = ground.reduce((s, g, k) => s + Math.abs((tile.data[p * 4 + k] ?? 0) - g), 0);
|
|
826
|
+
seen += diff > SEEN ? 1 : 0;
|
|
827
|
+
}
|
|
828
|
+
});
|
|
829
|
+
return total > 0 ? seen / total : 0;
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
// src/checks/symbols.ts
|
|
833
|
+
var svg = (body) => `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">${body}</svg>`;
|
|
834
|
+
var crescentBody = (dx, r) => `<mask id="c"><rect width="100" height="100" fill="#fff"/><circle cx="${50 + dx}" cy="50" r="${r}" fill="#000"/></mask><circle cx="50" cy="50" r="40" mask="url(#c)"/>`;
|
|
835
|
+
var starPoints = (cx, cy, r, n, inner) => Array.from({ length: 2 * n }, (_, k) => {
|
|
836
|
+
const t = -Math.PI / 2 + Math.PI * k / n;
|
|
837
|
+
const rr = k % 2 === 0 ? r : r * inner;
|
|
838
|
+
return `${(cx + rr * Math.cos(t)).toFixed(2)},${(cy + rr * Math.sin(t)).toFixed(2)}`;
|
|
839
|
+
}).join(" ");
|
|
840
|
+
var star5 = (cx, cy, r) => `<polygon points="${starPoints(cx, cy, r, 5, 0.4)}"/>`;
|
|
841
|
+
var tri = (deg) => [0, 120, 240].map((a) => {
|
|
842
|
+
const t = (deg + a) * Math.PI / 180;
|
|
843
|
+
return `${(50 + 45 * Math.cos(t)).toFixed(2)},${(50 + 45 * Math.sin(t)).toFixed(2)}`;
|
|
844
|
+
}).join(" ");
|
|
845
|
+
var ironArm = (deg) => `<polygon transform="rotate(${deg} 50 50)" points="30,6 70,6 56,44 44,44"/>`;
|
|
846
|
+
var SYMBOLS = [
|
|
847
|
+
{ id: "crescent-star", label: "Crescent and star", silhouettes: [svg(crescentBody(14, 33) + star5(72, 50, 15)), svg(crescentBody(10, 32) + star5(76, 50, 12))] },
|
|
848
|
+
{ id: "red-crescent", label: "Crescent (Red Crescent emblem)", silhouettes: [svg(crescentBody(14, 33)), svg(crescentBody(10, 32))] },
|
|
849
|
+
{ id: "latin-cross", label: "Latin cross", silhouettes: [svg('<rect x="42" y="8" width="16" height="84"/><rect x="22" y="28" width="56" height="16"/>')] },
|
|
850
|
+
{ id: "greek-cross", label: "Greek cross (Red Cross emblem)", silhouettes: [svg('<rect x="38" y="12" width="24" height="76"/><rect x="12" y="38" width="76" height="24"/>')] },
|
|
851
|
+
{ id: "star-of-david", label: "Star of David", silhouettes: [svg(`<polygon points="${tri(-90)}"/><polygon points="${tri(90)}"/>`)] },
|
|
852
|
+
{ id: "swastika", label: "Swastika", silhouettes: [svg('<rect x="44" y="15" width="12" height="70"/><rect x="15" y="44" width="70" height="12"/><rect x="44" y="15" width="41" height="12"/><rect x="73" y="44" width="12" height="41"/><rect x="15" y="73" width="41" height="12"/><rect x="15" y="15" width="12" height="41"/>')] },
|
|
853
|
+
{ id: "hammer-and-sickle", label: "Hammer and sickle", silhouettes: [svg('<path d="M28 28 A30 30 0 1 0 78 60" fill="none" stroke="#000" stroke-width="10"/><g transform="rotate(-45 50 50)"><rect x="46" y="28" width="8" height="58"/><rect x="34" y="20" width="32" height="12"/></g>')] },
|
|
854
|
+
{ id: "iron-cross", label: "Iron cross", silhouettes: [svg([0, 90, 180, 270].map(ironArm).join("") + '<rect x="42" y="42" width="16" height="16"/>')] },
|
|
855
|
+
{ id: "celtic-cross", label: "Celtic cross", silhouettes: [svg('<rect x="44" y="8" width="12" height="84"/><rect x="18" y="32" width="64" height="12"/><circle cx="50" cy="38" r="20" fill="none" stroke="#000" stroke-width="7"/>')] },
|
|
856
|
+
{ id: "ankh", label: "Ankh", silhouettes: [svg('<ellipse cx="50" cy="26" rx="13" ry="17" fill="none" stroke="#000" stroke-width="8"/><rect x="45" y="42" width="10" height="50"/><rect x="24" y="42" width="52" height="10"/>')] },
|
|
857
|
+
{ id: "pentagram", label: "Five-point star (pentagram)", silhouettes: [svg(star5(50, 52, 46))] },
|
|
858
|
+
{ id: "yin-yang", label: "Yin and yang", silhouettes: [svg('<path d="M50 5A45 45 0 0 1 50 95A22.5 22.5 0 0 1 50 50A22.5 22.5 0 0 0 50 5Z"/><circle cx="50" cy="27.5" r="7"/>')] },
|
|
859
|
+
{ id: "orthodox-cross", label: "Orthodox cross", silhouettes: [svg('<rect x="44" y="6" width="12" height="88"/><rect x="36" y="16" width="28" height="8"/><rect x="22" y="32" width="56" height="10"/><rect x="30" y="68" width="40" height="8" transform="rotate(-20 50 72)"/>')] }
|
|
860
|
+
];
|
|
861
|
+
|
|
862
|
+
// src/checks/lookalike.ts
|
|
863
|
+
var LOOKALIKE_THRESHOLD = 0.7;
|
|
864
|
+
var RENDER = 96;
|
|
865
|
+
var INK = "#000000";
|
|
866
|
+
var INK_PALETTE = { light: {}, dark: {}};
|
|
867
|
+
var symbolGrids = /* @__PURE__ */ new Map();
|
|
868
|
+
function gridOf(svg2) {
|
|
869
|
+
const mask = alphaMask(renderSvg(svg2, RENDER));
|
|
870
|
+
return { grid: normalise(mask, RENDER, RENDER), mask };
|
|
871
|
+
}
|
|
872
|
+
function gridsFor(id, silhouettes) {
|
|
873
|
+
const cached = symbolGrids.get(id);
|
|
874
|
+
if (cached) {
|
|
875
|
+
return cached;
|
|
876
|
+
}
|
|
877
|
+
const grids = silhouettes.map((s) => gridOf(s).grid);
|
|
878
|
+
symbolGrids.set(id, grids);
|
|
879
|
+
return grids;
|
|
880
|
+
}
|
|
881
|
+
var scoreAgainst = (grid2, targets) => Math.max(0, ...orientations(grid2).flatMap((o) => targets.map((t) => bestIou(o, t))));
|
|
882
|
+
function inkSvg(mark, only) {
|
|
883
|
+
const layers = only === void 0 ? mark.layers : mark.layers.filter((_, i) => i === only);
|
|
884
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="${mark.viewBox}">${markBody({ ...mark, layers }, INK_PALETTE, "light" /* Light */, { colourOverride: INK })}</svg>`;
|
|
885
|
+
}
|
|
886
|
+
function crescentWithObject(mark) {
|
|
887
|
+
const crescents = gridsFor("red-crescent", SYMBOLS.find((s) => s.id === "red-crescent")?.silhouettes ?? []);
|
|
888
|
+
const layers = mark.layers.map((_, i) => gridOf(inkSvg(mark, i)));
|
|
889
|
+
let best = 0;
|
|
890
|
+
layers.forEach((layer, i) => {
|
|
891
|
+
const score = scoreAgainst(layer.grid, crescents);
|
|
892
|
+
const box = maskBox(layer.mask, RENDER, RENDER);
|
|
893
|
+
const holdsObject = layers.some((other, j) => {
|
|
894
|
+
const ob = maskBox(other.mask, RENDER, RENDER);
|
|
895
|
+
if (j === i || !ob || !box) {
|
|
896
|
+
return false;
|
|
897
|
+
}
|
|
898
|
+
const cx = ob.x + ob.w / 2;
|
|
899
|
+
const cy = ob.y + ob.h / 2;
|
|
900
|
+
return cx > box.x && cx < box.x + box.w && cy > box.y && cy < box.y + box.h && layer.mask[Math.floor(cy) * RENDER + Math.floor(cx)] === 0;
|
|
901
|
+
});
|
|
902
|
+
best = holdsObject ? Math.max(best, score) : best;
|
|
903
|
+
});
|
|
904
|
+
return best;
|
|
905
|
+
}
|
|
906
|
+
function svgSymbolScores(svg2) {
|
|
907
|
+
const whole = gridOf(svg2).grid;
|
|
908
|
+
return SYMBOLS.map((s) => ({ symbol: s.id, score: scoreAgainst(whole, gridsFor(s.id, s.silhouettes)) }));
|
|
909
|
+
}
|
|
910
|
+
function symbolScores(mark) {
|
|
911
|
+
const scores = svgSymbolScores(inkSvg(mark));
|
|
912
|
+
const compound = crescentWithObject(mark);
|
|
913
|
+
const cs = scores.find((s) => s.symbol === "crescent-star");
|
|
914
|
+
if (cs && compound > cs.score) {
|
|
915
|
+
cs.score = compound;
|
|
916
|
+
}
|
|
917
|
+
return scores.sort((a, b) => b.score - a.score);
|
|
918
|
+
}
|
|
919
|
+
function symbolMatches(mark) {
|
|
920
|
+
return symbolScores(mark).filter((s) => s.score >= LOOKALIKE_THRESHOLD);
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
// src/checks/runChecks.ts
|
|
924
|
+
var MIN_LAYER_PX = { 16: 2, 32: 6 };
|
|
925
|
+
var MIN_COVER = 0.06;
|
|
926
|
+
var MAX_COVER = 0.9;
|
|
927
|
+
var MIN_BOX_FILL = 0.12;
|
|
928
|
+
var MAX_BOX_FILL = 0.92;
|
|
929
|
+
var ONE_COLOUR_SIZE = 64;
|
|
930
|
+
var ink = (mask) => mask.reduce((s, v) => s + v, 0);
|
|
931
|
+
function legibility(mark, size) {
|
|
932
|
+
const out = [];
|
|
933
|
+
const cover = ink(alphaMask(renderSvg(inkSvg(mark), size))) / (size * size);
|
|
934
|
+
if (cover < MIN_COVER || cover > MAX_COVER) {
|
|
935
|
+
out.push(`legible${size}: ink covers ${(cover * 100).toFixed(0)}% of the ${size} px tile`);
|
|
936
|
+
}
|
|
937
|
+
mark.layers.forEach((layer, i) => {
|
|
938
|
+
const px = ink(alphaMask(renderSvg(inkSvg(mark, i), size)));
|
|
939
|
+
if (px < (MIN_LAYER_PX[size] ?? 1)) {
|
|
940
|
+
out.push(`legible${size}: layer "${layer.name}" is ${px} px, lost at ${size} px`);
|
|
941
|
+
}
|
|
942
|
+
});
|
|
943
|
+
return out;
|
|
944
|
+
}
|
|
945
|
+
function oneColour(mark) {
|
|
946
|
+
const mask = alphaMask(renderSvg(inkSvg(mark), ONE_COLOUR_SIZE));
|
|
947
|
+
const box = maskBox(mask, ONE_COLOUR_SIZE, ONE_COLOUR_SIZE);
|
|
948
|
+
const fill = box ? ink(mask) / (box.w * box.h) : 0;
|
|
949
|
+
return fill < MIN_BOX_FILL || fill > MAX_BOX_FILL ? [`oneColour: one colour fills ${(fill * 100).toFixed(0)}% of its box, reads as ${fill > MAX_BOX_FILL ? "a solid block" : "dust"}`] : [];
|
|
950
|
+
}
|
|
951
|
+
var MIN_REVERSED_SHOWN = 0.9;
|
|
952
|
+
function reversed(mark, palette) {
|
|
953
|
+
const ink2 = palette.light["background"] ?? "#ffffff";
|
|
954
|
+
const bg = palette.dark["background"] ?? "#000000";
|
|
955
|
+
const vb = viewBoxOf(mark);
|
|
956
|
+
const body = markBody(mark, palette, "light" /* Light */, { colourOverride: ink2 });
|
|
957
|
+
const svg2 = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="${mark.viewBox}"><rect x="${vb.x}" y="${vb.y}" width="${vb.w}" height="${vb.h}" fill="${bg}"/>${body}</svg>`;
|
|
958
|
+
const shown = visibleShare(renderSvg(svg2, ONE_COLOUR_SIZE), renderSvg(inkSvg(mark), ONE_COLOUR_SIZE));
|
|
959
|
+
const out = contrast(ink2, bg) < MIN_CONTRAST ? [`reversed: ${ink2} on ${bg} is under 3:1`] : [];
|
|
960
|
+
return shown < MIN_REVERSED_SHOWN ? [...out, `reversed: only ${(shown * 100).toFixed(0)}% of the mark shows on ${bg}`] : out;
|
|
961
|
+
}
|
|
962
|
+
function runChecks(mark, palette) {
|
|
963
|
+
const roles = rolesOf(mark);
|
|
964
|
+
const symbols = symbolMatches(mark).map((m) => `symbol: looks like ${m.symbol} (${m.score.toFixed(2)})`);
|
|
965
|
+
const reasons = [...legibility(mark, 16), ...legibility(mark, 32), ...oneColour(mark), ...reversed(mark, palette), ...contrastFailures(palette, roles), ...cvdFailures(palette, roles), ...symbols];
|
|
966
|
+
return { pass: reasons.length === 0, reasons };
|
|
967
|
+
}
|
|
968
|
+
function checkVariants(seed, variants, palette) {
|
|
969
|
+
const report = { seed, count: variants.length, passed: [], dropped: [] };
|
|
970
|
+
for (const v of variants) {
|
|
971
|
+
const result = runChecks(v.mark, palette);
|
|
972
|
+
if (result.pass) {
|
|
973
|
+
report.passed.push(v.id);
|
|
974
|
+
} else {
|
|
975
|
+
report.dropped.push({ id: v.id, recipe: v.recipe, reasons: result.reasons });
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
return report;
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
// src/palette/variants.ts
|
|
982
|
+
var unique = (list) => [...new Set(list.filter((h) => h !== void 0).map((h) => h.toLowerCase()))];
|
|
983
|
+
function tokenPools(t) {
|
|
984
|
+
const light = unique([t.primary, t.secondary, t.light.text, t.light.brandFill, t.semantic.info, t.light.textSecondary]);
|
|
985
|
+
const dark = unique([t.accent, t.dark.text, t.dark.brandFill, t.dark.focusRing, t.dark.textSecondary, t.dark.textTertiary, t.semantic.warning]);
|
|
986
|
+
return {
|
|
987
|
+
light: light.filter((h) => contrast(h, t.light.background) >= MIN_CONTRAST),
|
|
988
|
+
dark: dark.filter((h) => contrast(h, t.dark.background) >= MIN_CONTRAST)
|
|
989
|
+
};
|
|
990
|
+
}
|
|
991
|
+
function candidate(t, roles, pick2, name) {
|
|
992
|
+
const light = { background: t.light.background, text: t.light.text };
|
|
993
|
+
const dark = { background: t.dark.background, text: t.dark.text };
|
|
994
|
+
roles.forEach((role, j) => {
|
|
995
|
+
const [l, d] = pick2(j);
|
|
996
|
+
light[role] = l;
|
|
997
|
+
dark[role] = d;
|
|
998
|
+
});
|
|
999
|
+
return { name, light, dark, mono: t.light.text };
|
|
1000
|
+
}
|
|
1001
|
+
function candidates(t, roles, tokensId) {
|
|
1002
|
+
const { light, dark } = tokenPools(t);
|
|
1003
|
+
const out = [];
|
|
1004
|
+
const nl = light.length;
|
|
1005
|
+
const nd = dark.length;
|
|
1006
|
+
for (let k = 0; k < nl * nd; k++) {
|
|
1007
|
+
const li = k % nl;
|
|
1008
|
+
const di = Math.floor(k / nl);
|
|
1009
|
+
out.push(candidate(t, roles, (j) => [light[(li + j) % nl] ?? "", dark[(di + j) % nd] ?? ""], `${tokensId}-${li}${di}`));
|
|
1010
|
+
}
|
|
1011
|
+
light.forEach((l, i) => out.push(candidate(t, roles, () => [l, dark[i % nd] ?? ""], `${tokensId}-mono-${i}`)));
|
|
1012
|
+
return out;
|
|
1013
|
+
}
|
|
1014
|
+
function paletteVariants(mark, tokensId, count = 5) {
|
|
1015
|
+
const t = presetOf(tokensId);
|
|
1016
|
+
const roles = rolesOf(mark);
|
|
1017
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1018
|
+
const out = [];
|
|
1019
|
+
for (const p of candidates(t, roles, tokensId)) {
|
|
1020
|
+
const key2 = JSON.stringify([p.light, p.dark]);
|
|
1021
|
+
const passes = contrastFailures(p, roles).length === 0 && cvdFailures(p, roles).length === 0;
|
|
1022
|
+
if (passes && !seen.has(key2)) {
|
|
1023
|
+
seen.add(key2);
|
|
1024
|
+
out.push(p);
|
|
1025
|
+
}
|
|
1026
|
+
if (out.length >= count) {
|
|
1027
|
+
break;
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
return out;
|
|
1031
|
+
}
|
|
1032
|
+
function generatorPalette(tokensId) {
|
|
1033
|
+
const t = presetOf(tokensId);
|
|
1034
|
+
return {
|
|
1035
|
+
name: `${tokensId}-generator`,
|
|
1036
|
+
light: { background: t.light.background, text: t.light.text, a: t.primary, b: t.light.text },
|
|
1037
|
+
dark: { background: t.dark.background, text: t.dark.text, a: t.accent, b: t.dark.text },
|
|
1038
|
+
mono: t.light.text
|
|
1039
|
+
};
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
// src/motion/timeline.ts
|
|
1043
|
+
function targetsOf(beat, layerNames) {
|
|
1044
|
+
if (!beat.layers) {
|
|
1045
|
+
return [...layerNames];
|
|
1046
|
+
}
|
|
1047
|
+
return beat.layers.includes(MARK_TARGET) ? [MARK_TARGET] : layerNames.filter((n) => beat.layers?.includes(n));
|
|
1048
|
+
}
|
|
1049
|
+
function schedule(beat, layerNames) {
|
|
1050
|
+
return targetsOf(beat, layerNames).map((target, k) => ({ target, delayMs: (beat.delayMs ?? 0) + k * (beat.stepMs ?? 0), durationMs: beat.durationMs }));
|
|
1051
|
+
}
|
|
1052
|
+
function totalMs(beats, layerNames) {
|
|
1053
|
+
return Math.max(0, ...beats.flatMap((b) => schedule(b, layerNames).map((s) => s.delayMs + s.durationMs)));
|
|
1054
|
+
}
|
|
1055
|
+
function fitBeat(beat, n, capMs) {
|
|
1056
|
+
const room = capMs - (beat.delayMs ?? 0) - beat.durationMs;
|
|
1057
|
+
const step2 = n > 1 ? Math.min(beat.stepMs ?? 0, Math.max(0, Math.floor(room / (n - 1)))) : beat.stepMs ?? 0;
|
|
1058
|
+
return { ...beat, stepMs: step2 };
|
|
1059
|
+
}
|
|
1060
|
+
function morphClashes(beats, layerNames) {
|
|
1061
|
+
const morph = new Set(beats.filter((b) => b.preset === "morph-from-circle" /* MorphFromCircle */).flatMap((b) => targetsOf(b, layerNames)));
|
|
1062
|
+
const other = beats.filter((b) => b.preset !== "morph-from-circle" /* MorphFromCircle */ && b.preset !== "sweep" /* Sweep */).flatMap((b) => targetsOf(b, layerNames));
|
|
1063
|
+
return other.filter((t) => morph.has(t)).map((t) => `layer "${t}" has morph-from-circle and another preset`);
|
|
1064
|
+
}
|
|
1065
|
+
function validateMotion(config, layerNames) {
|
|
1066
|
+
const introMs = totalMs(config.intro, layerNames);
|
|
1067
|
+
const microMs = totalMs(config.micro, layerNames);
|
|
1068
|
+
const errors = [
|
|
1069
|
+
...config.intro.filter((b) => !INTRO_PRESETS.includes(b.preset)).map((b) => `unknown intro preset "${b.preset}"`),
|
|
1070
|
+
...config.micro.filter((b) => !MICRO_PRESETS.includes(b.preset)).map((b) => `unknown micro preset "${b.preset}"`),
|
|
1071
|
+
...morphClashes(config.intro, layerNames)
|
|
1072
|
+
];
|
|
1073
|
+
const warnings = [];
|
|
1074
|
+
if (introMs > INTRO_CAP_MS) {
|
|
1075
|
+
const message = `intro runs ${introMs} ms, cap ${INTRO_CAP_MS} ms`;
|
|
1076
|
+
if (config.allowLongIntro !== void 0) {
|
|
1077
|
+
warnings.push(`${message} (allowed: ${config.allowLongIntro})`);
|
|
1078
|
+
} else {
|
|
1079
|
+
errors.push(message);
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
if (microMs > MICRO_CAP_MS) {
|
|
1083
|
+
errors.push(`micro runs ${microMs} ms, cap ${MICRO_CAP_MS} ms`);
|
|
1084
|
+
}
|
|
1085
|
+
return { introMs, microMs, errors, warnings };
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
// src/motion/morph.ts
|
|
1089
|
+
var POINTS = 96;
|
|
1090
|
+
function startAtTop(poly, c) {
|
|
1091
|
+
let best = 0;
|
|
1092
|
+
let bestScore = Infinity;
|
|
1093
|
+
poly.forEach((p, k) => {
|
|
1094
|
+
const score = Math.abs(Math.atan2(p.x - c.x, -(p.y - c.y)));
|
|
1095
|
+
if (score < bestScore) {
|
|
1096
|
+
bestScore = score;
|
|
1097
|
+
best = k;
|
|
1098
|
+
}
|
|
1099
|
+
});
|
|
1100
|
+
return [...poly.slice(best), ...poly.slice(0, best)];
|
|
1101
|
+
}
|
|
1102
|
+
var signedArea = (poly) => poly.reduce((s, p, k) => {
|
|
1103
|
+
const q = poly[(k + 1) % poly.length] ?? p;
|
|
1104
|
+
return s + p.x * q.y - q.x * p.y;
|
|
1105
|
+
}, 0);
|
|
1106
|
+
function morphPair(d) {
|
|
1107
|
+
const subs = flattenPath(d);
|
|
1108
|
+
const to = [];
|
|
1109
|
+
const from = [];
|
|
1110
|
+
for (const sub of subs) {
|
|
1111
|
+
const c = centroid(sub);
|
|
1112
|
+
const r = Math.max(...sub.map((p) => Math.hypot(p.x - c.x, p.y - c.y)));
|
|
1113
|
+
const oriented = signedArea(sub) < 0 ? [...sub].reverse() : sub;
|
|
1114
|
+
to.push(startAtTop(resample(oriented, POINTS), c));
|
|
1115
|
+
from.push(circlePoints(c, r, POINTS));
|
|
1116
|
+
}
|
|
1117
|
+
return { from: polygonsToD(from), to: polygonsToD(to) };
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
// src/motion/presets.ts
|
|
1121
|
+
var fillBox = "transform-box:fill-box;transform-origin:center";
|
|
1122
|
+
function morphFrames(beat, ctx) {
|
|
1123
|
+
const layer = ctx.layer;
|
|
1124
|
+
if (!layer) {
|
|
1125
|
+
throw new Error("morph-from-circle needs a layer, not the whole mark");
|
|
1126
|
+
}
|
|
1127
|
+
const { from, to } = morphPair(layer.d);
|
|
1128
|
+
const fade = beat.fadeIn?.includes(layer.name) === true;
|
|
1129
|
+
const stops = beat.stops ?? [0, 40, 100];
|
|
1130
|
+
return stops.map((stop, k) => {
|
|
1131
|
+
const first = k === 0;
|
|
1132
|
+
const d = first ? from : to;
|
|
1133
|
+
const opacity = first && fade ? 0 : 1;
|
|
1134
|
+
const easing = first ? beat.easing ?? EASE_IN_FIRST : beat.settleEasing ?? EASE;
|
|
1135
|
+
return `${stop.toFixed(2)}%{d:path("${d}");opacity:${opacity};animation-timing-function:${easing}}`;
|
|
1136
|
+
}).join("");
|
|
1137
|
+
}
|
|
1138
|
+
function spreadFrames(beat, ctx) {
|
|
1139
|
+
const pts = ctx.layer ? flattenPath(ctx.layer.d).flat() : [];
|
|
1140
|
+
const c = pts.length > 0 ? centroid(pts) : ctx.markCentre;
|
|
1141
|
+
const dx = c.x - ctx.markCentre.x;
|
|
1142
|
+
const dy = c.y - ctx.markCentre.y;
|
|
1143
|
+
const len = Math.hypot(dx, dy) || 1;
|
|
1144
|
+
const dist = beat.distance ?? 1.6;
|
|
1145
|
+
const tx = (dx / len * dist).toFixed(2);
|
|
1146
|
+
const ty = (dy / len * dist).toFixed(2);
|
|
1147
|
+
return `0%{transform:translate(0,0)}50%{transform:translate(${tx}px,${ty}px);animation-timing-function:${beat.easing ?? EASE}}100%{transform:translate(0,0)}`;
|
|
1148
|
+
}
|
|
1149
|
+
var PRESETS2 = {
|
|
1150
|
+
["draw" /* Draw */]: (b) => ({ keyframes: "0%{stroke-dasharray:1 1;stroke-dashoffset:1}100%{stroke-dasharray:1 1;stroke-dashoffset:0}", timing: b.easing ?? EASE }),
|
|
1151
|
+
["flood" /* Flood */]: (b) => ({ keyframes: "0%{fill-opacity:0}100%{fill-opacity:1}", timing: b.easing ?? EASE }),
|
|
1152
|
+
["stagger-rise" /* StaggerRise */]: (b) => ({ keyframes: `0%{opacity:0;transform:translateY(${b.distance ?? 4}px)}100%{opacity:1;transform:none}`, timing: b.easing ?? EASE }),
|
|
1153
|
+
["scale-pop" /* ScalePop */]: (b) => ({ keyframes: "0%{opacity:0;transform:scale(0.6)}70%{opacity:1;transform:scale(1.06)}100%{opacity:1;transform:scale(1)}", timing: b.easing ?? EASE, extra: fillBox }),
|
|
1154
|
+
["orbit" /* Orbit */]: (b, ctx) => ({
|
|
1155
|
+
keyframes: "0%{opacity:0;transform:rotate(-90deg)}100%{opacity:1;transform:rotate(0deg)}",
|
|
1156
|
+
timing: b.easing ?? EASE,
|
|
1157
|
+
extra: `transform-box:view-box;transform-origin:${ctx.markCentre.x}px ${ctx.markCentre.y}px`
|
|
1158
|
+
}),
|
|
1159
|
+
["wipe" /* Wipe */]: (b) => ({ keyframes: "0%{clip-path:inset(0 100% 0 0)}100%{clip-path:inset(0 0 0 0)}", timing: b.easing ?? EASE }),
|
|
1160
|
+
["morph-from-circle" /* MorphFromCircle */]: (b, ctx) => ({ keyframes: morphFrames(b, ctx), timing: "linear", supportsD: true }),
|
|
1161
|
+
["sweep" /* Sweep */]: (b) => ({ keyframes: `0%{stroke-dashoffset:${b.share ?? 0.12};opacity:1}99%{stroke-dashoffset:-1;opacity:1}100%{stroke-dashoffset:-1;opacity:0}`, timing: b.easing ?? "linear" }),
|
|
1162
|
+
["pulse" /* Pulse */]: (b) => ({ keyframes: `0%{transform:scale(1)}50%{transform:scale(${b.scale ?? 1.07})}100%{transform:scale(1)}`, timing: b.easing ?? "ease-in-out", extra: fillBox }),
|
|
1163
|
+
["spread" /* Spread */]: (b, ctx) => ({ keyframes: spreadFrames(b, ctx), timing: "linear" })
|
|
1164
|
+
};
|
|
1165
|
+
function presetFrames(beat, ctx) {
|
|
1166
|
+
const fn = PRESETS2[beat.preset];
|
|
1167
|
+
if (!fn) {
|
|
1168
|
+
throw new Error(`unknown motion preset "${beat.preset}"`);
|
|
1169
|
+
}
|
|
1170
|
+
return fn(beat, ctx);
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
// src/motion/motionCss.ts
|
|
1174
|
+
var REDUCED_MOTION = "@media (prefers-reduced-motion:reduce){*{animation:none!important}}";
|
|
1175
|
+
var selectorOf = (target, index, hover, sweep) => {
|
|
1176
|
+
const root = hover ? "svg:hover" : "svg";
|
|
1177
|
+
if (target === MARK_TARGET) {
|
|
1178
|
+
return `${root} #mark`;
|
|
1179
|
+
}
|
|
1180
|
+
return `${root} .${sweep ? "lks" : "l"}${index}`;
|
|
1181
|
+
};
|
|
1182
|
+
function sweepOverlay(mark, index, beat, colour) {
|
|
1183
|
+
const layer = mark.layers[index];
|
|
1184
|
+
if (!layer) {
|
|
1185
|
+
return "";
|
|
1186
|
+
}
|
|
1187
|
+
const attrs = [`class="lks${index}"`, `d="${layer.d}"`, 'fill="none"', `stroke="${colour}"`, `stroke-width="${beat.width ?? 2}"`, 'stroke-linecap="round"', 'pathLength="1"', `stroke-dasharray="${beat.share ?? 0.12} 1"`, 'opacity="0"'];
|
|
1188
|
+
if (layer.transform !== void 0) {
|
|
1189
|
+
attrs.push(`transform="${layer.transform}"`);
|
|
1190
|
+
}
|
|
1191
|
+
return `<path ${attrs.join(" ")}/>`;
|
|
1192
|
+
}
|
|
1193
|
+
function render(rules, keyframes) {
|
|
1194
|
+
const plain = keyframes.filter((k) => !k.supportsD).map((k) => k.body).join("");
|
|
1195
|
+
const morph = keyframes.filter((k) => k.supportsD).map((k) => k.body).join("");
|
|
1196
|
+
const decls = (r) => [...r.extras, "animation:".concat(r.animations.join(","))].join(";");
|
|
1197
|
+
const css = (list) => list.map((r) => `${r.selector}{${decls(r)}}`).join("");
|
|
1198
|
+
const all = [...rules.values()];
|
|
1199
|
+
const supports = all.filter((r) => r.supportsD);
|
|
1200
|
+
const wrapped = supports.length > 0 ? `@supports (d:path("M0 0")){${morph}${css(supports)}}` : "";
|
|
1201
|
+
return `${plain}${css(all.filter((r) => !r.supportsD))}${wrapped}${REDUCED_MOTION}`;
|
|
1202
|
+
}
|
|
1203
|
+
function addSlot(ctx, beat, b, slot) {
|
|
1204
|
+
const sweep = beat.preset === "sweep" /* Sweep */;
|
|
1205
|
+
const index = ctx.names.indexOf(slot.target);
|
|
1206
|
+
const frames = presetFrames(beat, { layer: ctx.mark.layers[index] ?? null, markCentre: ctx.markCentre });
|
|
1207
|
+
const suffix = slot.target === MARK_TARGET ? "m" : String(index);
|
|
1208
|
+
const name = `lk${ctx.hover ? "m" : "i"}${b}-${suffix}`;
|
|
1209
|
+
const selector = selectorOf(slot.target, index, ctx.hover, sweep);
|
|
1210
|
+
const rule = ctx.rules.get(selector) ?? { selector, animations: [], extras: [], supportsD: false };
|
|
1211
|
+
const delay = slot.delayMs > 0 ? ` ${slot.delayMs}ms` : "";
|
|
1212
|
+
const fill = ctx.hover ? "" : " backwards";
|
|
1213
|
+
rule.animations.push(`${name} ${slot.durationMs}ms ${frames.timing}${delay} 1${fill}`);
|
|
1214
|
+
if (frames.extra !== void 0 && !rule.extras.includes(frames.extra)) {
|
|
1215
|
+
rule.extras.push(frames.extra);
|
|
1216
|
+
}
|
|
1217
|
+
rule.supportsD = rule.supportsD || frames.supportsD === true;
|
|
1218
|
+
ctx.rules.set(selector, rule);
|
|
1219
|
+
ctx.keyframes.push({ body: `@keyframes ${name}{${frames.keyframes}}`, supportsD: frames.supportsD === true });
|
|
1220
|
+
if (beat.preset === "draw" /* Draw */) {
|
|
1221
|
+
ctx.drawLayers.add(slot.target);
|
|
1222
|
+
}
|
|
1223
|
+
if (sweep) {
|
|
1224
|
+
ctx.overlay.push(sweepOverlay(ctx.mark, index, beat, ctx.colour(beat.colour)));
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
function motionCss(mark, beats, palette, mode, hover) {
|
|
1228
|
+
const vb = viewBoxOf(mark);
|
|
1229
|
+
const colours = mode === "dark" /* Dark */ ? palette.dark : palette.light;
|
|
1230
|
+
const ctx = {
|
|
1231
|
+
mark,
|
|
1232
|
+
names: mark.layers.map((l) => l.name),
|
|
1233
|
+
markCentre: { x: vb.x + vb.w / 2, y: vb.y + vb.h / 2 },
|
|
1234
|
+
colour: (role) => colours[role ?? "text"] ?? "#ffffff",
|
|
1235
|
+
hover,
|
|
1236
|
+
rules: /* @__PURE__ */ new Map(),
|
|
1237
|
+
keyframes: [],
|
|
1238
|
+
drawLayers: /* @__PURE__ */ new Set(),
|
|
1239
|
+
overlay: []
|
|
1240
|
+
};
|
|
1241
|
+
beats.forEach((beat, b) => schedule(beat, ctx.names).forEach((slot) => addSlot(ctx, beat, b, slot)));
|
|
1242
|
+
return { style: render(ctx.rules, ctx.keyframes), overlay: ctx.overlay.join(""), drawLayers: ctx.drawLayers };
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1245
|
+
// src/motion/motionSvg.ts
|
|
1246
|
+
function introSvg(mark, palette, mode, beats, opts) {
|
|
1247
|
+
const m = motionCss(mark, beats, palette, mode, false);
|
|
1248
|
+
return markSvg(mark, palette, mode, { ...opts, style: m.style, overlay: m.overlay, drawLayers: m.drawLayers });
|
|
1249
|
+
}
|
|
1250
|
+
function microSvg(mark, palette, mode, beats, opts) {
|
|
1251
|
+
const m = motionCss(mark, beats, palette, mode, true);
|
|
1252
|
+
return markSvg(mark, palette, mode, { ...opts, style: m.style, overlay: m.overlay, drawLayers: m.drawLayers });
|
|
1253
|
+
}
|
|
1254
|
+
function animatedSvg(mark, palette, mode, motion, opts) {
|
|
1255
|
+
const intro = motionCss(mark, motion.intro, palette, mode, false);
|
|
1256
|
+
const micro = motionCss(mark, motion.micro, palette, mode, true);
|
|
1257
|
+
const style = `${intro.style.replace(REDUCED_MOTION, "")}${micro.style}`;
|
|
1258
|
+
const drawLayers = /* @__PURE__ */ new Set([...intro.drawLayers, ...micro.drawLayers]);
|
|
1259
|
+
return markSvg(mark, palette, mode, { ...opts, style, overlay: intro.overlay + micro.overlay, drawLayers });
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
// src/motion/parseTiming.ts
|
|
1263
|
+
var NESTING = { "(": 1, ")": -1, "{": 1, "}": -1 };
|
|
1264
|
+
var KEYFRAMES = "@keyframes ";
|
|
1265
|
+
function splitTop(list) {
|
|
1266
|
+
const out = [];
|
|
1267
|
+
let depth = 0;
|
|
1268
|
+
let cur = "";
|
|
1269
|
+
for (const ch of list) {
|
|
1270
|
+
depth += ch === "(" || ch === ")" ? NESTING[ch] ?? 0 : 0;
|
|
1271
|
+
if (ch === "," && depth === 0) {
|
|
1272
|
+
out.push(cur.trim());
|
|
1273
|
+
cur = "";
|
|
1274
|
+
} else {
|
|
1275
|
+
cur += ch;
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
return cur.trim() ? [...out, cur.trim()] : out;
|
|
1279
|
+
}
|
|
1280
|
+
function cutKeyframes(css) {
|
|
1281
|
+
const bodies = /* @__PURE__ */ new Map();
|
|
1282
|
+
let rest = "";
|
|
1283
|
+
let i = 0;
|
|
1284
|
+
while (i < css.length) {
|
|
1285
|
+
const at = css.indexOf(KEYFRAMES, i);
|
|
1286
|
+
if (at < 0) {
|
|
1287
|
+
rest += css.slice(i);
|
|
1288
|
+
break;
|
|
1289
|
+
}
|
|
1290
|
+
rest += css.slice(i, at);
|
|
1291
|
+
const open = css.indexOf("{", at);
|
|
1292
|
+
let depth = 1;
|
|
1293
|
+
let j = open + 1;
|
|
1294
|
+
while (depth > 0 && j < css.length) {
|
|
1295
|
+
depth += NESTING[css[j] ?? ""] ?? 0;
|
|
1296
|
+
j++;
|
|
1297
|
+
}
|
|
1298
|
+
bodies.set(css.slice(at + KEYFRAMES.length, open).trim(), css.slice(open + 1, j - 1));
|
|
1299
|
+
i = j;
|
|
1300
|
+
}
|
|
1301
|
+
return { bodies, rest };
|
|
1302
|
+
}
|
|
1303
|
+
function stopsOf(body) {
|
|
1304
|
+
return body.split("}").filter((part) => part.includes("%{")).map((part) => {
|
|
1305
|
+
const [stop = "", props = ""] = part.split("%{");
|
|
1306
|
+
const opacity = /(?:^|;)opacity:([\d.]+)/.exec(props)?.[1];
|
|
1307
|
+
const easing = /animation-timing-function:([^;]+)/.exec(props)?.[1];
|
|
1308
|
+
return { at: Number(stop.trim()), opacity: opacity !== void 0 ? Number(opacity) : null, easing: easing?.trim() ?? null };
|
|
1309
|
+
});
|
|
1310
|
+
}
|
|
1311
|
+
var targetOf = (selector) => /\.(l\d+|lks\d+)\s*$/.exec(selector)?.[1] ?? (/#mark\s*$/.test(selector) ? "mark" : null);
|
|
1312
|
+
function animationOf(anim, bodies) {
|
|
1313
|
+
const words = anim.split(" ").filter((w) => w !== "");
|
|
1314
|
+
const ms = words.filter((w) => w.endsWith("ms")).map((w) => Number(w.slice(0, -2)));
|
|
1315
|
+
return { durationMs: ms[0] ?? 0, delayMs: ms[1] ?? 0, stops: stopsOf(bodies.get(words[0] ?? "") ?? "") };
|
|
1316
|
+
}
|
|
1317
|
+
function parseTiming(svg2) {
|
|
1318
|
+
const css = /<style>([\s\S]*?)<\/style>/.exec(svg2)?.[1] ?? "";
|
|
1319
|
+
const { bodies, rest } = cutKeyframes(css);
|
|
1320
|
+
const out = {};
|
|
1321
|
+
for (const segment of rest.split("}")) {
|
|
1322
|
+
const open = segment.lastIndexOf("{");
|
|
1323
|
+
const decls = segment.slice(open + 1);
|
|
1324
|
+
const at = decls.indexOf("animation:");
|
|
1325
|
+
const target = targetOf(segment.slice(segment.lastIndexOf("{", open - 1) + 1, open));
|
|
1326
|
+
if (open < 0 || at < 0 || target === null || decls.includes("none")) {
|
|
1327
|
+
continue;
|
|
1328
|
+
}
|
|
1329
|
+
out[target] = splitTop(decls.slice(at + "animation:".length)).map((anim) => animationOf(anim, bodies));
|
|
1330
|
+
}
|
|
1331
|
+
return out;
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
// src/export/canvas.ts
|
|
1335
|
+
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
1336
|
+
function iconCanvas(brand, mode, size, share, background, radius = 0) {
|
|
1337
|
+
const side = Math.min(size.w, size.h) * share;
|
|
1338
|
+
const r = Math.min(size.w, size.h) * radius;
|
|
1339
|
+
const bg = background !== null ? `<rect width="${size.w}" height="${size.h}" rx="${r}" fill="${background}"/>` : "";
|
|
1340
|
+
const mark = placeMark(brand.mark, brand.palette, mode, { x: (size.w - side) / 2, y: (size.h - side) / 2, size: side });
|
|
1341
|
+
return `<svg xmlns="${SVG_NS}" width="${size.w}" height="${size.h}" viewBox="0 0 ${size.w} ${size.h}">${bg}${mark}</svg>`;
|
|
1342
|
+
}
|
|
1343
|
+
var TEXT_SHARE = 0.3;
|
|
1344
|
+
function faviconSvg(brand, size) {
|
|
1345
|
+
const sm = brand.smallMark;
|
|
1346
|
+
if (!sm) {
|
|
1347
|
+
return null;
|
|
1348
|
+
}
|
|
1349
|
+
const name = escapeXml(brand.name);
|
|
1350
|
+
const style = `<style>path{fill:${sm.light}}@media (prefers-color-scheme:dark){path{fill:${sm.dark}}}</style>`;
|
|
1351
|
+
return `<svg xmlns="${SVG_NS}" viewBox="${sm.viewBox}" width="${size}" height="${size}" role="img" aria-label="${name}"><title>${name}</title>${style}<path d="${sm.d}"/></svg>`;
|
|
1352
|
+
}
|
|
1353
|
+
function lockupSvg(brand, mode, height) {
|
|
1354
|
+
const colours = mode === "dark" /* Dark */ ? brand.palette.dark : brand.palette.light;
|
|
1355
|
+
const gap = Math.round(height * 1.15);
|
|
1356
|
+
const width = Math.round(gap + brand.name.length * height * TEXT_SHARE);
|
|
1357
|
+
const name = escapeXml(brand.name);
|
|
1358
|
+
const text = `<text x="${gap}" y="${Math.round(height * 0.66)}" font-family="${escapeXml(brand.wordmark.fontFamily)}" font-size="${Math.round(height * 0.5)}" font-weight="700" fill="${colours["text"] ?? "#000000"}">${name}</text>`;
|
|
1359
|
+
const svg2 = `<svg xmlns="${SVG_NS}" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" role="img" aria-label="${name}"><title>${name}</title>${placeMark(brand.mark, brand.palette, mode, { x: 0, y: 0, size: height })}${text}</svg>`;
|
|
1360
|
+
return { svg: svg2, width };
|
|
1361
|
+
}
|
|
1362
|
+
function cardSvg(brand, mode, size) {
|
|
1363
|
+
const colours = mode === "dark" /* Dark */ ? brand.palette.dark : brand.palette.light;
|
|
1364
|
+
const side = Math.round(size.h * 0.56);
|
|
1365
|
+
const x = Math.round(size.w * 0.1);
|
|
1366
|
+
const y = Math.round((size.h - side) / 2);
|
|
1367
|
+
const name = escapeXml(brand.name);
|
|
1368
|
+
const text = `<text x="${x + side + Math.round(side * 0.2)}" y="${Math.round(size.h / 2 + side * 0.1)}" font-family="${escapeXml(brand.wordmark.fontFamily)}" font-size="${Math.round(side * 0.22)}" font-weight="700" fill="${colours["text"] ?? "#000000"}">${name}</text>`;
|
|
1369
|
+
return `<svg xmlns="${SVG_NS}" width="${size.w}" height="${size.h}" viewBox="0 0 ${size.w} ${size.h}"><rect width="${size.w}" height="${size.h}" fill="${colours["background"] ?? "#ffffff"}"/>${placeMark(brand.mark, brand.palette, mode, { x, y, size: side })}${text}</svg>`;
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
// src/export/geometryModule.ts
|
|
1373
|
+
var IDENT = /^[A-Za-z_$][\w$]*$/;
|
|
1374
|
+
var key = (name) => IDENT.test(name) ? name : `'${name}'`;
|
|
1375
|
+
function geometryModule(mark) {
|
|
1376
|
+
const paths = mark.layers.map((l) => ` ${key(l.name)}: '${l.d}',`).join("\n");
|
|
1377
|
+
const lines = mark.layers.filter((l) => l.transform !== void 0).map((l) => ` ${key(l.name)}: '${l.transform ?? ""}',`);
|
|
1378
|
+
const block = lines.join("\n");
|
|
1379
|
+
const transforms = lines.length > 0 ? `
|
|
1380
|
+
export const MARK_TRANSFORMS = {
|
|
1381
|
+
${block}
|
|
1382
|
+
} as const;
|
|
1383
|
+
` : "";
|
|
1384
|
+
return `export const MARK_VIEW_BOX = '${mark.viewBox}';
|
|
1385
|
+
|
|
1386
|
+
export const MARK_PATHS = {
|
|
1387
|
+
${paths}
|
|
1388
|
+
} as const;
|
|
1389
|
+
${transforms}`;
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
// src/export/exportBrand.ts
|
|
1393
|
+
var MARK_SIZE = 256;
|
|
1394
|
+
var FAVICON = 32;
|
|
1395
|
+
var ICO_SIZES = [16, 32, 48];
|
|
1396
|
+
var HEADERS = [[360, 40], [1280, 56]];
|
|
1397
|
+
var ICONS = [["apple-touch-icon.png", 180, false], ["icon-192.png", 192, true], ["icon-512.png", 512, true], ["icon-512-maskable.png", 512, false]];
|
|
1398
|
+
function writer(brand, outDir) {
|
|
1399
|
+
const files = [];
|
|
1400
|
+
const fonts = brand.wordmark.fontFile !== void 0 ? [path3.resolve(brand.baseDir, brand.wordmark.fontFile)] : [];
|
|
1401
|
+
fs2.mkdirSync(outDir, { recursive: true });
|
|
1402
|
+
return {
|
|
1403
|
+
files,
|
|
1404
|
+
svg: (file, body, width, height) => {
|
|
1405
|
+
fs2.writeFileSync(path3.join(outDir, file), body);
|
|
1406
|
+
files.push({ file, width, height });
|
|
1407
|
+
},
|
|
1408
|
+
png: (file, body, width) => {
|
|
1409
|
+
const png = renderPng(body, width, fonts);
|
|
1410
|
+
fs2.writeFileSync(path3.join(outDir, file), png);
|
|
1411
|
+
files.push({ file, ...pngSize(png) });
|
|
1412
|
+
}
|
|
1413
|
+
};
|
|
1414
|
+
}
|
|
1415
|
+
function writeMarks(brand, w) {
|
|
1416
|
+
const opts = { label: brand.name, size: MARK_SIZE };
|
|
1417
|
+
w.svg("mark.svg", markSvg(brand.mark, brand.palette, "light" /* Light */, opts), MARK_SIZE, MARK_SIZE);
|
|
1418
|
+
w.svg("mark-dark.svg", markSvg(brand.mark, brand.palette, "dark" /* Dark */, opts), MARK_SIZE, MARK_SIZE);
|
|
1419
|
+
w.svg("mark-mono.svg", markSvg(brand.mark, brand.palette, "light" /* Light */, { ...opts, colourOverride: brand.palette.mono }), MARK_SIZE, MARK_SIZE);
|
|
1420
|
+
w.svg("mark-reversed.svg", markSvg(brand.mark, brand.palette, "dark" /* Dark */, { ...opts, colourOverride: brand.palette.light["background"] ?? "#ffffff" }), MARK_SIZE, MARK_SIZE);
|
|
1421
|
+
w.svg("favicon.svg", faviconSvg(brand, FAVICON) ?? markSvg(brand.mark, brand.palette, "light" /* Light */, { label: brand.name, size: FAVICON }), FAVICON, FAVICON);
|
|
1422
|
+
}
|
|
1423
|
+
function writeMotion(brand, w) {
|
|
1424
|
+
for (const mode of ["light" /* Light */, "dark" /* Dark */]) {
|
|
1425
|
+
w.svg(`intro-${mode}.svg`, introSvg(brand.mark, brand.palette, mode, brand.motion.intro, { label: `${brand.name}, intro`, size: MARK_SIZE }), MARK_SIZE, MARK_SIZE);
|
|
1426
|
+
w.svg(`micro-${mode}.svg`, microSvg(brand.mark, brand.palette, mode, brand.motion.micro, { label: `${brand.name}, hover`, size: MARK_SIZE }), MARK_SIZE, MARK_SIZE);
|
|
1427
|
+
}
|
|
1428
|
+
w.svg("mark-animated.svg", animatedSvg(brand.mark, brand.palette, "light" /* Light */, brand.motion, { label: brand.name, size: MARK_SIZE }), MARK_SIZE, MARK_SIZE);
|
|
1429
|
+
}
|
|
1430
|
+
function writeRasters(brand, w, outDir) {
|
|
1431
|
+
const mode = brand.icons.dark ? "dark" /* Dark */ : "light" /* Light */;
|
|
1432
|
+
const bg = (mode === "dark" /* Dark */ ? brand.palette.dark : brand.palette.light)["background"] ?? "#ffffff";
|
|
1433
|
+
for (const [file, size, rounded] of ICONS) {
|
|
1434
|
+
w.png(file, iconCanvas(brand, mode, { w: size, h: size }, brand.icons.share, bg, rounded ? brand.icons.radius : 0), size);
|
|
1435
|
+
}
|
|
1436
|
+
const favicon = (s) => faviconSvg(brand, s) ?? iconCanvas(brand, "light" /* Light */, { w: s, h: s }, 1, null);
|
|
1437
|
+
const icoPngs = ICO_SIZES.map((s) => renderPng(favicon(s), s));
|
|
1438
|
+
fs2.writeFileSync(path3.join(outDir, "favicon.ico"), buildIco(icoPngs));
|
|
1439
|
+
w.files.push({ file: "favicon.ico", width: Math.max(...ICO_SIZES), height: Math.max(...ICO_SIZES) });
|
|
1440
|
+
w.png("og.png", cardSvg(brand, "dark" /* Dark */, { w: 1200, h: 630 }), 1200);
|
|
1441
|
+
w.png("landing-card.png", cardSvg(brand, "light" /* Light */, { w: 640, h: 400 }), 640);
|
|
1442
|
+
}
|
|
1443
|
+
function exportBrand(brand, outDir) {
|
|
1444
|
+
const report = validateMotion(brand.motion, brand.mark.layers.map((l) => l.name));
|
|
1445
|
+
if (report.errors.length > 0) {
|
|
1446
|
+
throw new Error(`motion: ${report.errors.join("; ")}`);
|
|
1447
|
+
}
|
|
1448
|
+
const w = writer(brand, outDir);
|
|
1449
|
+
writeMarks(brand, w);
|
|
1450
|
+
writeMotion(brand, w);
|
|
1451
|
+
writeRasters(brand, w, outDir);
|
|
1452
|
+
for (const [vw, h] of HEADERS) {
|
|
1453
|
+
for (const mode of ["light" /* Light */, "dark" /* Dark */]) {
|
|
1454
|
+
const lockup = lockupSvg(brand, mode, h);
|
|
1455
|
+
w.svg(`header-${mode}-${vw}.svg`, lockup.svg, lockup.width, h);
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
const moduleDir = path3.join(outDir, `brand-${brand.slug}`);
|
|
1459
|
+
fs2.mkdirSync(moduleDir, { recursive: true });
|
|
1460
|
+
fs2.writeFileSync(path3.join(moduleDir, "markGeometry.ts"), geometryModule(brand.mark));
|
|
1461
|
+
w.files.push({ file: `brand-${brand.slug}/markGeometry.ts`, width: 0, height: 0 });
|
|
1462
|
+
return w.files;
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
// src/pick/frames.ts
|
|
1466
|
+
var FRAME = { w: 360, h: 640 };
|
|
1467
|
+
var TARGET_BOX = { x: 80, y: 180, w: 200, h: 200 };
|
|
1468
|
+
function frameSvg(mark, palette, beats = []) {
|
|
1469
|
+
const bg = palette.light["background"] ?? "#ffffff";
|
|
1470
|
+
const motion = beats.length > 0 ? motionCss(mark, beats, palette, "light" /* Light */, false) : null;
|
|
1471
|
+
const style = motion ? `<style>${motion.style}</style>` : "";
|
|
1472
|
+
const body = markBody(mark, palette, "light" /* Light */, motion ? { drawLayers: motion.drawLayers } : {});
|
|
1473
|
+
const b = TARGET_BOX;
|
|
1474
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${FRAME.w}" height="${FRAME.h}" viewBox="0 0 ${FRAME.w} ${FRAME.h}">${style}<rect width="${FRAME.w}" height="${FRAME.h}" fill="${bg}"/><svg x="${b.x}" y="${b.y}" width="${b.w}" height="${b.h}" viewBox="${mark.viewBox}">${body}${motion?.overlay ?? ""}</svg></svg>`;
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
// src/pick/buildPickSpec.ts
|
|
1478
|
+
var MAX_OPTIONS = 5;
|
|
1479
|
+
var MIN_OPTIONS = 3;
|
|
1480
|
+
var MOTION_OPTIONS = ["stagger-rise" /* StaggerRise */, "scale-pop" /* ScalePop */, "orbit" /* Orbit */, "wipe" /* Wipe */, "morph-from-circle" /* MorphFromCircle */];
|
|
1481
|
+
function frame(outDir, file, mark, palette) {
|
|
1482
|
+
const rel = `frames/${file}.png`;
|
|
1483
|
+
fs2.mkdirSync(path3.join(outDir, "frames"), { recursive: true });
|
|
1484
|
+
fs2.writeFileSync(path3.join(outDir, rel), renderPng(frameSvg(mark, palette), FRAME.w));
|
|
1485
|
+
return rel;
|
|
1486
|
+
}
|
|
1487
|
+
var option = (name, why, image, extra = {}) => ({ name, why, image, inventory: "1/1", aligned: "pass", targetBox: TARGET_BOX, ...extra });
|
|
1488
|
+
var need = (list, what) => {
|
|
1489
|
+
if (list.length < MIN_OPTIONS) {
|
|
1490
|
+
throw new Error(`pick: only ${list.length} ${what} passed the checks, need ${MIN_OPTIONS}`);
|
|
1491
|
+
}
|
|
1492
|
+
};
|
|
1493
|
+
function shapeStep(brand, outDir) {
|
|
1494
|
+
const palette = generatorPalette(brand.tokens);
|
|
1495
|
+
const passing = generateVariants(brand.generate.seed, brand.generate.count).filter((v) => runChecks(v.mark, palette).pass).slice(0, MAX_OPTIONS - 1);
|
|
1496
|
+
need(passing, "shapes");
|
|
1497
|
+
const options2 = passing.map((v) => option(v.id, `Generated from ${v.recipe}; passes every check.`, frame(outDir, `shape-${v.id}`, v.mark, palette)));
|
|
1498
|
+
const first = passing[0];
|
|
1499
|
+
if (!first) {
|
|
1500
|
+
throw new Error("pick: no shape");
|
|
1501
|
+
}
|
|
1502
|
+
return { step: { screen: "logo-shape", viewport: "mobile", target: "#mark", title: "Shape", question: "Which shape should the mark have?", options: options2 }, chosen: first.mark };
|
|
1503
|
+
}
|
|
1504
|
+
function colourStep(brand, mark, outDir) {
|
|
1505
|
+
const byLight = /* @__PURE__ */ new Map();
|
|
1506
|
+
for (const p of paletteVariants(mark, brand.tokens, MAX_OPTIONS * 3)) {
|
|
1507
|
+
const key2 = JSON.stringify(p.light);
|
|
1508
|
+
if (!byLight.has(key2)) {
|
|
1509
|
+
byLight.set(key2, p);
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
const palettes = [...byLight.values()].slice(0, MAX_OPTIONS);
|
|
1513
|
+
need(palettes, "palettes");
|
|
1514
|
+
const options2 = palettes.map((p) => option(p.name, `Colours from the ${brand.tokens} tokens; 3:1 on light and dark and colour-blind safe.`, frame(outDir, `colour-${p.name}`, mark, p)));
|
|
1515
|
+
const first = palettes[0];
|
|
1516
|
+
if (!first) {
|
|
1517
|
+
throw new Error("pick: no palette");
|
|
1518
|
+
}
|
|
1519
|
+
return { step: { screen: "logo-colour", viewport: "mobile", target: "#mark", title: "Colour", question: "Which colours should the mark use?", options: options2 }, palette: first };
|
|
1520
|
+
}
|
|
1521
|
+
function motionStep(mark, palette, outDir) {
|
|
1522
|
+
const still = frame(outDir, "motion-still", mark, palette);
|
|
1523
|
+
fs2.mkdirSync(path3.join(outDir, "motion"), { recursive: true });
|
|
1524
|
+
const n = mark.layers.length;
|
|
1525
|
+
const options2 = MOTION_OPTIONS.map((preset) => {
|
|
1526
|
+
const base = PRESET_DEFAULTS[preset] ?? { preset, durationMs: 600 };
|
|
1527
|
+
const beat = preset === "morph-from-circle" /* MorphFromCircle */ ? { ...base, fadeIn: mark.layers.slice(1).map((l) => l.name) } : fitBeat(base, n, INTRO_CAP_MS);
|
|
1528
|
+
const rel = `motion/${preset}.svg`;
|
|
1529
|
+
fs2.writeFileSync(path3.join(outDir, rel), frameSvg(mark, palette, [beat]));
|
|
1530
|
+
return option(preset, `The ${preset} intro, ${beat.durationMs} ms per layer, ends on the still.`, still, { motion: rel, targetBox: void 0 });
|
|
1531
|
+
});
|
|
1532
|
+
return { screen: "logo-motion", viewport: "mobile", kind: "motion", target: "n/a -- the options differ over time; every still frame is the same end frame", title: "Motion", question: "Which intro should the mark play?", options: options2 };
|
|
1533
|
+
}
|
|
1534
|
+
function buildPickSpec(brand, outDir) {
|
|
1535
|
+
fs2.mkdirSync(outDir, { recursive: true });
|
|
1536
|
+
const shape = shapeStep(brand, outDir);
|
|
1537
|
+
const colour = colourStep(brand, shape.chosen, outDir);
|
|
1538
|
+
const motion = motionStep(shape.chosen, colour.palette, outDir);
|
|
1539
|
+
const spec = {
|
|
1540
|
+
docKey: `logo-kit-${brand.slug}-pick`,
|
|
1541
|
+
title: `${brand.name}: pick the mark`,
|
|
1542
|
+
brand: `${brand.name}: logo pick`,
|
|
1543
|
+
intro: "Pick the shape first, then its colours, then how it moves. Every option already passed the size, contrast, colour-blind and symbol checks.",
|
|
1544
|
+
beforeAfter: "none -- new marks generated by logo-kit; no live screen is replaced on this page",
|
|
1545
|
+
noloss: "noloss: allow new screen -- a logo pick page has no screen fields",
|
|
1546
|
+
steps: [shape.step, colour.step, motion]
|
|
1547
|
+
};
|
|
1548
|
+
fs2.writeFileSync(path3.join(outDir, "spec.json"), `${JSON.stringify(spec, null, 2)}
|
|
1549
|
+
`);
|
|
1550
|
+
return spec;
|
|
1551
|
+
}
|
|
1552
|
+
function buildPickPage(builder, outDir) {
|
|
1553
|
+
const html = path3.join(outDir, "index.html");
|
|
1554
|
+
execFileSync(process.execPath, [builder, path3.join(outDir, "spec.json"), html], { stdio: "inherit" });
|
|
1555
|
+
return html;
|
|
1556
|
+
}
|
|
1557
|
+
var USAGE = "usage: logo-kit <export|generate|pick|check> <brand.json> [--out dir] [--seed n] [--count n] [--builder build-pick-page.mjs]";
|
|
1558
|
+
function flags(args) {
|
|
1559
|
+
const out = /* @__PURE__ */ new Map();
|
|
1560
|
+
args.forEach((a, i) => {
|
|
1561
|
+
const next = args[i + 1];
|
|
1562
|
+
if (a.startsWith("--") && next !== void 0) {
|
|
1563
|
+
out.set(a.slice(2), next);
|
|
1564
|
+
}
|
|
1565
|
+
});
|
|
1566
|
+
return out;
|
|
1567
|
+
}
|
|
1568
|
+
function generate(file, f, out) {
|
|
1569
|
+
const brand = loadBrand(file);
|
|
1570
|
+
const seed = Number(f.get("seed") ?? brand.generate.seed);
|
|
1571
|
+
const count = Number(f.get("count") ?? brand.generate.count);
|
|
1572
|
+
const dir = f.get("out") ?? "variants";
|
|
1573
|
+
const palette = generatorPalette(brand.tokens);
|
|
1574
|
+
const variants = generateVariants(seed, count);
|
|
1575
|
+
fs2.mkdirSync(dir, { recursive: true });
|
|
1576
|
+
for (const v of variants) {
|
|
1577
|
+
fs2.writeFileSync(path3.join(dir, `${v.id}.svg`), markSvg(v.mark, palette, "light" /* Light */, { label: v.recipe }));
|
|
1578
|
+
}
|
|
1579
|
+
const report = checkVariants(seed, variants, palette);
|
|
1580
|
+
fs2.writeFileSync(path3.join(dir, `checks-${seed}.json`), `${JSON.stringify(report, null, 2)}
|
|
1581
|
+
`);
|
|
1582
|
+
out(`generated ${count}, passed ${report.passed.length}, dropped ${report.dropped.length} -> ${dir}`);
|
|
1583
|
+
return 0;
|
|
1584
|
+
}
|
|
1585
|
+
function check(file, out) {
|
|
1586
|
+
const brand = loadBrand(file);
|
|
1587
|
+
const result = runChecks(brand.mark, brand.palette);
|
|
1588
|
+
const motion = validateMotion(brand.motion, brand.mark.layers.map((l) => l.name));
|
|
1589
|
+
out(JSON.stringify({ ...result, motion }, null, 2));
|
|
1590
|
+
return result.pass && motion.errors.length === 0 ? 0 : 1;
|
|
1591
|
+
}
|
|
1592
|
+
function runCli(args, out = (line) => process.stdout.write(`${line}
|
|
1593
|
+
`)) {
|
|
1594
|
+
const [cmd, file] = args;
|
|
1595
|
+
const f = flags(args);
|
|
1596
|
+
if (file === void 0) {
|
|
1597
|
+
out(USAGE);
|
|
1598
|
+
return 2;
|
|
1599
|
+
}
|
|
1600
|
+
if (cmd === "export") {
|
|
1601
|
+
const files = exportBrand(loadBrand(file), f.get("out") ?? "export");
|
|
1602
|
+
files.forEach((x) => out(`${x.file} ${x.width}x${x.height}`));
|
|
1603
|
+
return 0;
|
|
1604
|
+
}
|
|
1605
|
+
if (cmd === "generate") {
|
|
1606
|
+
return generate(file, f, out);
|
|
1607
|
+
}
|
|
1608
|
+
if (cmd === "pick") {
|
|
1609
|
+
const dir = f.get("out") ?? "pick";
|
|
1610
|
+
const spec = buildPickSpec(loadBrand(file), dir);
|
|
1611
|
+
const builder = f.get("builder");
|
|
1612
|
+
out(builder !== void 0 ? `built ${buildPickPage(builder, dir)}` : `wrote ${spec.steps.length} steps -> ${path3.join(dir, "spec.json")}`);
|
|
1613
|
+
return 0;
|
|
1614
|
+
}
|
|
1615
|
+
if (cmd === "check") {
|
|
1616
|
+
return check(file, out);
|
|
1617
|
+
}
|
|
1618
|
+
out(USAGE);
|
|
1619
|
+
return 2;
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1622
|
+
export { CVD_KINDS, CvdKind, INTRO_CAP_MS, INTRO_PRESETS, LOOKALIKE_THRESHOLD, MICRO_CAP_MS, MICRO_PRESETS, MODES, Mode, MotionPreset, PRESET_DEFAULTS, PRIMITIVES, SYMBOLS, alphaMask, animatedSvg, buildPickPage, buildPickSpec, checkVariants, contrast, deltaE, exportBrand, fitBeat, flattenPath, generateVariants, generatorPalette, geometryModule, introSvg, loadBrand, markSvg, microSvg, paletteVariants, parseBrand, parseTiming, pixelDiff, pngSize, primitiveMark, renderPng, renderSvg, resolveToken, runChecks, runCli, schedule, simulateCvd, symbolMatches, symbolScores, totalMs, validateMotion };
|
|
1623
|
+
//# sourceMappingURL=index.js.map
|
|
1624
|
+
//# sourceMappingURL=index.js.map
|