@conveno/cli 0.1.1 → 0.2.0-rc.10

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.
@@ -0,0 +1,731 @@
1
+ import "node:url";
2
+ // ../brand/dist/index.js
3
+ const tokens = {
4
+ "name": "Conveno",
5
+ "direction": "Minutes",
6
+ "version": "1.0.0-lock",
7
+ "mark": {
8
+ "file": "mark.svg",
9
+ "grid": 64,
10
+ "unit": 8,
11
+ "construction": "Lowercase c: spine x8 y12 w12 h40; top arm x20 y12 w24 h8; bottom arm x20 y44 w24 h8 (the arms are the record's entries). Point: circle cx52 cy32 r8 (accent), sitting in the c's opening = the orchestrator / the decision. Flat cut ends, no rounding. Edges on multiples of 4 for whole pixels at 16 and 32. Known risk: at 16px it can read as '[' plus a dot; keep the aperture open and the point clearly separated.",
12
+ "clearSpace": "1 unit (8/64 of mark height) minimum on every side; 2 units preferred",
13
+ "minSize": {
14
+ "mark": 16,
15
+ "lockup": 96
16
+ }
17
+ },
18
+ "color": {
19
+ "light": {
20
+ "ground": "#F3F5F7",
21
+ "surface": "#FFFFFF",
22
+ "sunken": "#E9EDF1",
23
+ "ink": "#111B28",
24
+ "quiet": "#566474",
25
+ "rule": "#C7D0DA",
26
+ "entry": "#2346D9",
27
+ "entryInk": "#FFFFFF",
28
+ "stamp": "#9A5700",
29
+ "ok": "#1E7B3A",
30
+ "warn": "#8A5200",
31
+ "error": "#B3202A",
32
+ "info": "#0A6C82",
33
+ "focus": "#2346D9"
34
+ },
35
+ "dark": {
36
+ "ground": "#0D1520",
37
+ "surface": "#141F2E",
38
+ "sunken": "#0A111A",
39
+ "ink": "#E4EAF1",
40
+ "quiet": "#93A1B3",
41
+ "rule": "#2A384A",
42
+ "entry": "#8CA6FF",
43
+ "entryInk": "#0D1520",
44
+ "stamp": "#FFB547",
45
+ "ok": "#7BD88F",
46
+ "warn": "#FFB547",
47
+ "error": "#F2777A",
48
+ "info": "#6FD3E8",
49
+ "focus": "#8CA6FF"
50
+ },
51
+ "roles": {
52
+ "entry": "The one accent. The point in the mark, the orchestrator, links, primary actions, 'live'. Never used for decoration.",
53
+ "stamp": "Attention that needs the owner: open tickets, waiting on question. Not an error.",
54
+ "ok/warn/error/info": "Semantic state only. Never as brand accents."
55
+ },
56
+ "derived": {
57
+ "ruleSoft": "color-mix(in srgb, var(--cv-rule) 55%, transparent)",
58
+ "tint(x)": "color-mix(in srgb, var(--cv-x) 12%, var(--cv-surface))"
59
+ },
60
+ "accentDiscipline": "Entry blue is reserved for: (1) the mark's point wherever the mark or its motif appears (logo, lockups, the c───● spinner point); (2) the orchestrator (marker, status-orchestrator, orchestrator icons); (3) the live delivery tier; (4) links; (5) focus ring. Everything else is ink/quiet/semantic: icon points default to currentColor; primary buttons, toggles, checkboxes are ink; terminal commands are bold ink; the prompt › is quiet; a handoff in transit is ink."
61
+ },
62
+ "type": {
63
+ "display": {
64
+ "family": "Schibsted Grotesk",
65
+ "fallback": "ui-sans-serif, system-ui, sans-serif",
66
+ "weights": [
67
+ 500,
68
+ 700,
69
+ 800
70
+ ]
71
+ },
72
+ "body": {
73
+ "family": "IBM Plex Sans",
74
+ "fallback": "ui-sans-serif, system-ui, sans-serif",
75
+ "weights": [
76
+ 400,
77
+ 500,
78
+ 600
79
+ ]
80
+ },
81
+ "mono": {
82
+ "family": "IBM Plex Mono",
83
+ "fallback": "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",
84
+ "weights": [400, 500]
85
+ },
86
+ "scale": {
87
+ "xs": 12,
88
+ "sm": 13,
89
+ "base": 15,
90
+ "md": 17,
91
+ "lg": 20,
92
+ "xl": 24,
93
+ "2xl": 32,
94
+ "3xl": 44,
95
+ "4xl": 60
96
+ },
97
+ "lineHeight": {
98
+ "tight": 1.05,
99
+ "heading": 1.2,
100
+ "body": 1.55,
101
+ "mono": 1.6
102
+ },
103
+ "tracking": {
104
+ "display": "-0.02em",
105
+ "label": "0.08em"
106
+ },
107
+ "rules": "Timestamps, session names, commands and ids are always mono. Labels are mono uppercase at xs with label tracking. Headings use display, sentence case."
108
+ },
109
+ "space": {
110
+ "unit": 4,
111
+ "scale": [
112
+ 0,
113
+ 4,
114
+ 8,
115
+ 12,
116
+ 16,
117
+ 24,
118
+ 32,
119
+ 48,
120
+ 64,
121
+ 96
122
+ ]
123
+ },
124
+ "radius": {
125
+ "none": 0,
126
+ "sm": 2,
127
+ "md": 4,
128
+ "lg": 8,
129
+ "pill": 999,
130
+ "appIcon": "22%"
131
+ },
132
+ "stroke": {
133
+ "rule": 1,
134
+ "icon24": 1.5,
135
+ "icon16": 1.25,
136
+ "focus": 2
137
+ },
138
+ "motion": {
139
+ "ease": {
140
+ "enter": "cubic-bezier(0.2, 0.7, 0.1, 1)",
141
+ "exit": "cubic-bezier(0.4, 0, 1, 1)",
142
+ "record": "cubic-bezier(0.65, 0, 0.25, 1)"
143
+ },
144
+ "duration": {
145
+ "instant": 120,
146
+ "quick": 200,
147
+ "base": 320,
148
+ "slow": 560,
149
+ "reveal": 900,
150
+ "stage": 880,
151
+ "idle": 5600
152
+ },
153
+ "stagger": 80,
154
+ "rules": "Motion explains a change in the record: something written, moved, sealed or answered. No bounce, no overshoot, no ambient looping except the stoppable 'listening' idle. Respect prefers-reduced-motion by showing the end state.",
155
+ "offset": { "pointLand": 640 }
156
+ },
157
+ "ansi": {
158
+ "dark": {
159
+ "background": "#0B121C",
160
+ "foreground": "#D5DEE8",
161
+ "black": "#1B2636",
162
+ "red": "#F2777A",
163
+ "green": "#7BD88F",
164
+ "yellow": "#FFB547",
165
+ "blue": "#8CA6FF",
166
+ "magenta": "#E394C0",
167
+ "cyan": "#6FD3E8",
168
+ "white": "#D5DEE8",
169
+ "brightBlack": "#7F8EA1",
170
+ "brightRed": "#FF9A9C",
171
+ "brightGreen": "#9BE8AC",
172
+ "brightYellow": "#FFCB78",
173
+ "brightBlue": "#B0C2FF",
174
+ "brightMagenta": "#F0B3D5",
175
+ "brightCyan": "#99E4F3",
176
+ "brightWhite": "#F3F6FA"
177
+ },
178
+ "light": {
179
+ "background": "#FBFCFD",
180
+ "foreground": "#111B28",
181
+ "black": "#111B28",
182
+ "red": "#B3202A",
183
+ "green": "#1E7B3A",
184
+ "yellow": "#8A5200",
185
+ "blue": "#2346D9",
186
+ "magenta": "#9B2F6B",
187
+ "cyan": "#0A6C82",
188
+ "white": "#5E6B7C",
189
+ "brightBlack": "#5C6A7B",
190
+ "brightRed": "#C92A35",
191
+ "brightGreen": "#1A7236",
192
+ "brightYellow": "#7E4A00",
193
+ "brightBlue": "#1F3FC4",
194
+ "brightMagenta": "#8A2660",
195
+ "brightCyan": "#08627A",
196
+ "brightWhite": "#3F4B5B"
197
+ }
198
+ },
199
+ "terminal": {
200
+ "glyphs": {
201
+ "ok": "✓",
202
+ "warn": "!",
203
+ "error": "x",
204
+ "info": "i",
205
+ "prompt": "›",
206
+ "bullet": "·",
207
+ "orchestrator": "●",
208
+ "busy": "●",
209
+ "waiting": "◉",
210
+ "idle": "○",
211
+ "offline": "-",
212
+ "arrow": "→",
213
+ "rule": "─"
214
+ },
215
+ "glyphColors": {
216
+ "ok": "ok",
217
+ "warn": "warn",
218
+ "error": "error",
219
+ "info": "info",
220
+ "orchestrator": "entry",
221
+ "busy": "ink",
222
+ "waiting": "stamp",
223
+ "idle": "quiet",
224
+ "offline": "quiet",
225
+ "prompt": "quiet",
226
+ "bullet": "quiet",
227
+ "arrow": "quiet",
228
+ "rule": "quiet"
229
+ },
230
+ "asciiFallback": {
231
+ "✓": "+",
232
+ "●": "*",
233
+ "○": "o",
234
+ "›": ">",
235
+ "·": ".",
236
+ "→": "->",
237
+ "─": "-",
238
+ "◉": "@"
239
+ },
240
+ "spinner": {
241
+ "name": "entry-write",
242
+ "intervalMs": 120,
243
+ "frames": [
244
+ "c ",
245
+ "c─ ",
246
+ "c── ",
247
+ "c─── ",
248
+ "c─── ●",
249
+ "c─── ●"
250
+ ],
251
+ "asciiFrames": [
252
+ "c ",
253
+ "c- ",
254
+ "c-- ",
255
+ "c--- ",
256
+ "c--- *",
257
+ "c--- *"
258
+ ],
259
+ "showAfterMs": 400,
260
+ "noMotion": "Static 'c─── ●' line when CONVENO_NO_MOTION=1, CI is set, stdout is not a TTY, or NO_COLOR with TERM=dumb."
261
+ },
262
+ "env": "NO_COLOR disables colour; FORCE_COLOR=0..3 forces level; COLORTERM=truecolor|24bit enables truecolor; CONVENO_NO_MOTION and CI disable spinners."
263
+ },
264
+ "naming": {
265
+ "cssVariables": "All CSS custom properties use the --cv- prefix (e.g. --cv-ink, --cv-ease-enter, --cv-dur-quick, --cv-fs-sm, --cv-s-4, --cv-r-md). The icon accent point colour is --cv-point.",
266
+ "cssClasses": "Components: .cv-<component>. Motion demo-only classes: .cv-m-<name> (never collide with components). Icon sprite ids: #cv-<icon-name>.",
267
+ "iconInternals": ".cv-pt (icon point, fill var(--cv-point, currentColor)) and .cv-pt-entry (point that defaults to entry) are part of the icon library."
268
+ },
269
+ "status": {
270
+ "shapes": {
271
+ "busy": "filled dot (ink)",
272
+ "idle": "ring (quiet)",
273
+ "waiting": "filled dot (stamp) inside a ring (stamp)",
274
+ "offline": "short dash (quiet)",
275
+ "error": "x cross, two strokes (error)",
276
+ "orchestrator": "small c + point (point in entry blue): the mark in miniature. The only status shape that is a c, so it reads without colour."
277
+ },
278
+ "terminal": {
279
+ "busy": "●",
280
+ "idle": "○",
281
+ "waiting": "◉ or fallback '@'",
282
+ "offline": "-",
283
+ "error": "x",
284
+ "orchestrator": "● in entry, always followed by the label 'orchestrator' (the terminal can't draw the c)"
285
+ },
286
+ "rule": "Icons (status-*), UI components and terminal all use these same five shapes."
287
+ },
288
+ "showcaseRules": "No eyebrow/kicker labels that repeat headings. Section structure uses the Minutes margin rule with an INK node per section. Headings (h1-h3) use the display font (Schibsted Grotesk 700/800). Buttons, toast titles, form labels and UI text use the body font (Plex Sans 500). Mono only for timestamps, names, commands, ids, code. Showcase pages may use page-local class names but must NOT use the reserved .cv- / .cv-m- prefixes for page chrome.",
289
+ "budgets": {
290
+ "svgDefault": "15 KB",
291
+ "exempt": ["icons/sprite.svg (bundle)", "assets/social-preview*.svg (source for the PNG; outlined text)"]
292
+ }
293
+ };
294
+ import.meta.url;
295
+ const terminalTheme = {
296
+ "name": "Conveno terminal theme",
297
+ "version": "1.0.0-lock",
298
+ "source": "../tokens.json (color.*, ansi.*, terminal.*, status.*)",
299
+ "note": "Roles are what the CLI code asks for. truecolor is exact; ansi256 is the nearest xterm-256 index that keeps AA contrast on the matching background; ansi16 uses the plain SGR codes so the user's own terminal theme decides the hue. 'dark' and 'light' name the terminal background. Detect with COLORFGBG or OSC 11 when available; otherwise default to dark.",
300
+ "background": {
301
+ "dark": "#0B121C",
302
+ "light": "#FBFCFD"
303
+ },
304
+ "attributes": {
305
+ "bold": "SGR 1. Used for names, ticket ids and the one key phrase of a line. Never the only signal.",
306
+ "dim": "Not used. 'quiet' is a colour, because SGR 2 is unreliable across terminals.",
307
+ "underline": "SGR 4. URLs only.",
308
+ "reset": "SGR 0 at the end of every coloured span and every line."
309
+ },
310
+ "roles": {
311
+ "entry": {
312
+ "use": "The accent, reserved for: orchestrator dot, live tier, links, and the spinner's point (the mark's point). Not commands and not the prompt.",
313
+ "truecolor": {
314
+ "dark": "#8CA6FF",
315
+ "light": "#2346D9"
316
+ },
317
+ "ansi256": {
318
+ "dark": 111,
319
+ "light": 26
320
+ },
321
+ "ansi16": {
322
+ "fg": 34,
323
+ "note": "blue; use 94 (bright blue) only when the user's 16-colour theme renders 34 too dark"
324
+ }
325
+ },
326
+ "stamp": {
327
+ "use": "Needs the owner: open tickets, waiting on a question. Not an error.",
328
+ "truecolor": {
329
+ "dark": "#FFB547",
330
+ "light": "#9A5700"
331
+ },
332
+ "ansi256": {
333
+ "dark": 215,
334
+ "light": 130
335
+ },
336
+ "ansi16": { "fg": 33 }
337
+ },
338
+ "ok": {
339
+ "use": "Healthy, done, answered.",
340
+ "truecolor": {
341
+ "dark": "#7BD88F",
342
+ "light": "#1E7B3A"
343
+ },
344
+ "ansi256": {
345
+ "dark": 114,
346
+ "light": 28
347
+ },
348
+ "ansi16": { "fg": 32 }
349
+ },
350
+ "warn": {
351
+ "use": "Works, but will bite later. Always with a fix line.",
352
+ "truecolor": {
353
+ "dark": "#FFB547",
354
+ "light": "#8A5200"
355
+ },
356
+ "ansi256": {
357
+ "dark": 215,
358
+ "light": 94
359
+ },
360
+ "ansi16": { "fg": 33 }
361
+ },
362
+ "error": {
363
+ "use": "Failed or broken. Always with what happened and how to fix it.",
364
+ "truecolor": {
365
+ "dark": "#F2777A",
366
+ "light": "#B3202A"
367
+ },
368
+ "ansi256": {
369
+ "dark": 210,
370
+ "light": 124
371
+ },
372
+ "ansi16": { "fg": 31 }
373
+ },
374
+ "info": {
375
+ "use": "Neutral facts worth a second look: versions, paths, counts.",
376
+ "truecolor": {
377
+ "dark": "#6FD3E8",
378
+ "light": "#0A6C82"
379
+ },
380
+ "ansi256": {
381
+ "dark": 117,
382
+ "light": 30
383
+ },
384
+ "ansi16": { "fg": 36 }
385
+ },
386
+ "quiet": {
387
+ "use": "Timestamps, column heads, hints, separators, idle and offline.",
388
+ "truecolor": {
389
+ "dark": "#7F8EA1",
390
+ "light": "#5C6A7B"
391
+ },
392
+ "ansi256": {
393
+ "dark": 245,
394
+ "light": 242
395
+ },
396
+ "ansi16": {
397
+ "fg": 90,
398
+ "note": "bright black"
399
+ }
400
+ },
401
+ "ink": {
402
+ "use": "Primary text, the busy dot, and commands (bold). Left as the terminal's default foreground; never set explicitly except bold.",
403
+ "truecolor": {
404
+ "dark": "#D5DEE8",
405
+ "light": "#111B28"
406
+ },
407
+ "ansi256": {
408
+ "dark": 253,
409
+ "light": 234
410
+ },
411
+ "ansi16": {
412
+ "fg": 39,
413
+ "note": "default foreground"
414
+ }
415
+ }
416
+ },
417
+ "ansiPalette": {
418
+ "note": "The 16 slots Conveno ships in its own terminal theme and the colours mockups are drawn with.",
419
+ "dark": {
420
+ "background": "#0B121C",
421
+ "foreground": "#D5DEE8",
422
+ "black": "#1B2636",
423
+ "red": "#F2777A",
424
+ "green": "#7BD88F",
425
+ "yellow": "#FFB547",
426
+ "blue": "#8CA6FF",
427
+ "magenta": "#E394C0",
428
+ "cyan": "#6FD3E8",
429
+ "white": "#D5DEE8",
430
+ "brightBlack": "#7F8EA1",
431
+ "brightRed": "#FF9A9C",
432
+ "brightGreen": "#9BE8AC",
433
+ "brightYellow": "#FFCB78",
434
+ "brightBlue": "#B0C2FF",
435
+ "brightMagenta": "#F0B3D5",
436
+ "brightCyan": "#99E4F3",
437
+ "brightWhite": "#F3F6FA"
438
+ },
439
+ "light": {
440
+ "background": "#FBFCFD",
441
+ "foreground": "#111B28",
442
+ "black": "#111B28",
443
+ "red": "#B3202A",
444
+ "green": "#1E7B3A",
445
+ "yellow": "#8A5200",
446
+ "blue": "#2346D9",
447
+ "magenta": "#9B2F6B",
448
+ "cyan": "#0A6C82",
449
+ "white": "#5E6B7C",
450
+ "brightBlack": "#5C6A7B",
451
+ "brightRed": "#C92A35",
452
+ "brightGreen": "#1A7236",
453
+ "brightYellow": "#7E4A00",
454
+ "brightBlue": "#1F3FC4",
455
+ "brightMagenta": "#8A2660",
456
+ "brightCyan": "#08627A",
457
+ "brightWhite": "#3F4B5B"
458
+ }
459
+ },
460
+ "glyphs": {
461
+ "ok": {
462
+ "unicode": "✓",
463
+ "ascii": "+",
464
+ "role": "ok"
465
+ },
466
+ "warn": {
467
+ "unicode": "!",
468
+ "ascii": "!",
469
+ "role": "warn"
470
+ },
471
+ "error": {
472
+ "unicode": "x",
473
+ "ascii": "x",
474
+ "role": "error"
475
+ },
476
+ "info": {
477
+ "unicode": "i",
478
+ "ascii": "i",
479
+ "role": "info"
480
+ },
481
+ "prompt": {
482
+ "unicode": "›",
483
+ "ascii": ">",
484
+ "role": "quiet"
485
+ },
486
+ "bullet": {
487
+ "unicode": "·",
488
+ "ascii": ".",
489
+ "role": "quiet"
490
+ },
491
+ "orchestrator": {
492
+ "unicode": "●",
493
+ "ascii": "*",
494
+ "role": "entry"
495
+ },
496
+ "busy": {
497
+ "unicode": "●",
498
+ "ascii": "*",
499
+ "role": "ink"
500
+ },
501
+ "waiting": {
502
+ "unicode": "◉",
503
+ "ascii": "@",
504
+ "role": "stamp"
505
+ },
506
+ "idle": {
507
+ "unicode": "○",
508
+ "ascii": "o",
509
+ "role": "quiet"
510
+ },
511
+ "offline": {
512
+ "unicode": "-",
513
+ "ascii": "-",
514
+ "role": "quiet"
515
+ },
516
+ "arrow": {
517
+ "unicode": "→",
518
+ "ascii": "->",
519
+ "role": "quiet"
520
+ },
521
+ "rule": {
522
+ "unicode": "─",
523
+ "ascii": "-",
524
+ "role": "quiet"
525
+ }
526
+ },
527
+ "environment": {
528
+ "NO_COLOR": "Any non-empty value: no colour, no bold. Glyphs stay.",
529
+ "FORCE_COLOR": "0 = off, 1 = 16-colour, 2 = 256, 3 = truecolor. Empty or 'true' = at least 16-colour. Overrides TTY detection, never NO_COLOR.",
530
+ "COLORTERM": "'truecolor' or '24bit' selects truecolor.",
531
+ "TERM": "'dumb' or unset: no colour. '*-256color' selects 256. Otherwise 16.",
532
+ "CONVENO_ASCII": "1 forces the ASCII glyph column and the ASCII spinner.",
533
+ "precedence": [
534
+ "NO_COLOR",
535
+ "FORCE_COLOR",
536
+ "CLI flag --no-color / --color",
537
+ "stdout is a TTY",
538
+ "COLORTERM",
539
+ "TERM"
540
+ ],
541
+ "CONVENO_NO_MOTION": "1 disables the spinner and prints the static 'c─── ●' line. CI, a non-TTY stdout, or NO_COLOR with TERM=dumb do the same."
542
+ },
543
+ "status": {
544
+ "shapes": {
545
+ "busy": "filled dot (ink)",
546
+ "idle": "ring (quiet)",
547
+ "waiting": "filled dot (stamp) inside a ring (stamp)",
548
+ "offline": "short dash (quiet)",
549
+ "error": "x cross, two strokes (error)",
550
+ "orchestrator": "filled dot (entry), the only blue status"
551
+ },
552
+ "terminal": {
553
+ "busy": "●",
554
+ "idle": "○",
555
+ "waiting": "◉ or fallback '@'",
556
+ "offline": "-",
557
+ "error": "x",
558
+ "orchestrator": "●"
559
+ },
560
+ "note": "Orchestrator is the only blue status. Same five shapes as the status-* icons and the UI chips."
561
+ },
562
+ "spinner": {
563
+ "name": "entry-write",
564
+ "intervalMs": 120,
565
+ "frames": [
566
+ "c ",
567
+ "c─ ",
568
+ "c── ",
569
+ "c─── ",
570
+ "c─── ●",
571
+ "c─── ●"
572
+ ],
573
+ "asciiFrames": [
574
+ "c ",
575
+ "c- ",
576
+ "c-- ",
577
+ "c--- ",
578
+ "c--- *",
579
+ "c--- *"
580
+ ],
581
+ "showAfterMs": 400,
582
+ "color": {
583
+ "line": "quiet",
584
+ "point": "entry",
585
+ "note": "The c and the entry line are quiet; only the final point is entry (the mark's point)."
586
+ },
587
+ "staticLine": "c─── ●",
588
+ "noMotion": "Static 'c─── ●' line when CONVENO_NO_MOTION=1, CI is set, stdout is not a TTY, or NO_COLOR with TERM=dumb."
589
+ },
590
+ "redaction": {
591
+ "unicode": "[redacted]",
592
+ "ascii": "[redacted]",
593
+ "note": "Fixed text, inverse video when colour is on."
594
+ }
595
+ };
596
+ const ESC = "\x1B[";
597
+ const RESET = `${ESC}0m`;
598
+ const set = (v) => v !== void 0 && v !== "";
599
+ const falsy = (v) => v === void 0 || v === "" || v === "0" || v.toLowerCase() === "false";
600
+ function currentContext() {
601
+ return {
602
+ env: process.env,
603
+ isTTY: Boolean(process.stdout.isTTY),
604
+ platform: process.platform
605
+ };
606
+ }
607
+ /** Precedence from brand/components/terminal-theme.json: NO_COLOR, FORCE_COLOR, flag, TTY, COLORTERM, TERM. */
608
+ function detectColorLevel(ctx = currentContext(), flag = "auto") {
609
+ const { env } = ctx;
610
+ if (set(env.NO_COLOR)) return 0;
611
+ let floor = 0;
612
+ const force = env.FORCE_COLOR;
613
+ if (force !== void 0) {
614
+ if (force === "0" || force.toLowerCase() === "false") return 0;
615
+ if (force === "1") return 1;
616
+ if (force === "2") return 2;
617
+ if (force === "3") return 3;
618
+ floor = 1;
619
+ }
620
+ if (flag === "never") return 0;
621
+ if (flag === "always") floor = Math.max(floor, 1);
622
+ if (floor === 0 && !ctx.isTTY) return 0;
623
+ const colorterm = (env.COLORTERM ?? "").toLowerCase();
624
+ const term = env.TERM ?? "";
625
+ let detected;
626
+ if (colorterm === "truecolor" || colorterm === "24bit") detected = 3;
627
+ else if (ctx.platform === "win32" && (set(env.WT_SESSION) || env.ConEmuANSI === "ON")) detected = 3;
628
+ else if (term === "dumb") detected = 0;
629
+ else if (term === "" && ctx.platform !== "win32") detected = 0;
630
+ else if (/256color/.test(term)) detected = 2;
631
+ else detected = 1;
632
+ return Math.max(detected, floor);
633
+ }
634
+ /** COLORFGBG ("fg;bg") when the terminal sets it. Defaults to dark. */
635
+ function detectBackground(env = process.env) {
636
+ const raw = env.COLORFGBG;
637
+ if (raw) {
638
+ const bg = Number(raw.split(";").at(-1));
639
+ if (Number.isInteger(bg)) return bg === 7 || bg === 15 ? "light" : "dark";
640
+ }
641
+ return "dark";
642
+ }
643
+ /** False for CONVENO_ASCII=1, the legacy Windows console and non-UTF-8 locales. */
644
+ function detectUnicode(ctx = currentContext()) {
645
+ const { env } = ctx;
646
+ if (!falsy(env.CONVENO_ASCII)) return false;
647
+ if (ctx.platform === "win32") return set(env.WT_SESSION) || set(env.TERM_PROGRAM) || env.ConEmuANSI === "ON" || env.TERM === "xterm-256color" || env.TERM === "alacritty";
648
+ if (env.TERM === "linux") return false;
649
+ const locale = env.LC_ALL || env.LC_CTYPE || env.LANG;
650
+ if (set(locale)) return /utf-?8/i.test(locale);
651
+ return true;
652
+ }
653
+ /** Spinner gate from tokens.terminal.spinner.noMotion: CONVENO_NO_MOTION, CI, non-TTY, TERM=dumb. */
654
+ function detectMotion(ctx = currentContext()) {
655
+ const { env } = ctx;
656
+ if (!falsy(env.CONVENO_NO_MOTION)) return false;
657
+ if (!falsy(env.CI)) return false;
658
+ if (!ctx.isTTY) return false;
659
+ if (env.TERM === "dumb") return false;
660
+ return true;
661
+ }
662
+ function sgr(role, level, bg) {
663
+ const r = terminalTheme.roles[role];
664
+ if (level === 3) {
665
+ const hex = r.truecolor[bg].slice(1);
666
+ const n = Number.parseInt(hex, 16);
667
+ return `38;2;${n >> 16 & 255};${n >> 8 & 255};${n & 255}`;
668
+ }
669
+ if (level === 2) return `38;5;${r.ansi256[bg]}`;
670
+ return String(r.ansi16.fg);
671
+ }
672
+ function createTheme(opts = {}) {
673
+ const now = currentContext();
674
+ const ctx = {
675
+ env: opts.env ?? now.env,
676
+ isTTY: opts.isTTY ?? now.isTTY,
677
+ platform: opts.platform ?? now.platform
678
+ };
679
+ const colorLevel = detectColorLevel(ctx, opts.color);
680
+ const background = opts.background ?? detectBackground(ctx.env);
681
+ const unicode = opts.ascii ? false : detectUnicode(ctx);
682
+ const motion = detectMotion(ctx);
683
+ const wrap = (codes, text) => `${ESC}${codes}m${text}${RESET}`;
684
+ const paint = (role, text, o) => {
685
+ if (colorLevel === 0 || text === "") return text;
686
+ if (role === "ink") return o?.bold ? wrap("1", text) : text;
687
+ const color = sgr(role, colorLevel, background);
688
+ return wrap(o?.bold ? `1;${color}` : color, text);
689
+ };
690
+ const bold = (text) => colorLevel === 0 || text === "" ? text : wrap("1", text);
691
+ const glyph = (name) => {
692
+ const u = tokens.terminal.glyphs[name];
693
+ if (unicode) return u;
694
+ return tokens.terminal.asciiFallback[u] ?? u;
695
+ };
696
+ const status = (name) => paint(tokens.terminal.glyphColors[name], glyph(name));
697
+ const point = unicode ? "●" : tokens.terminal.asciiFallback["●"] ?? "*";
698
+ const mark = () => `${paint("ink", "c")}${paint("entry", point)}`;
699
+ const spinner = () => {
700
+ const sp = tokens.terminal.spinner;
701
+ const raw = unicode ? sp.frames : sp.asciiFrames;
702
+ const dot = unicode ? "●" : "*";
703
+ const paintFrame = (f) => {
704
+ const i = f.indexOf(dot);
705
+ const line = i === -1 ? f : f.slice(0, i);
706
+ const tail = i === -1 ? "" : paint("entry", dot);
707
+ return paint("quiet", line.trimEnd()) + " ".repeat(line.length - line.trimEnd().length) + tail;
708
+ };
709
+ const frames = raw.map(paintFrame);
710
+ return {
711
+ animated: motion,
712
+ intervalMs: sp.intervalMs,
713
+ showAfterMs: sp.showAfterMs,
714
+ frames,
715
+ staticLine: paintFrame(raw[raw.length - 1])
716
+ };
717
+ };
718
+ return {
719
+ colorLevel,
720
+ background,
721
+ unicode,
722
+ motion,
723
+ paint,
724
+ bold,
725
+ glyph,
726
+ status,
727
+ mark,
728
+ spinner
729
+ };
730
+ }
731
+ export { tokens as i, detectColorLevel as n, detectUnicode as r, createTheme as t };