create-ilorb 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +304 -2
- package/assets/dev-local.mjs +205 -0
- package/dist/args.js +39 -0
- package/dist/cli.js +7 -0
- package/dist/cloudflare/provider.js +48 -0
- package/dist/cloudflare/real.js +211 -0
- package/dist/cloudflare/simulated.js +213 -0
- package/dist/core-admin.js +85 -0
- package/dist/engine.js +52 -0
- package/dist/errors.js +23 -0
- package/dist/exec.js +49 -0
- package/dist/fsutil.js +130 -0
- package/dist/generate.js +260 -0
- package/dist/i18n/en.js +422 -0
- package/dist/i18n/es.js +414 -0
- package/dist/i18n/index.js +23 -0
- package/dist/i18n/pt.js +414 -0
- package/dist/license/activate.js +71 -0
- package/dist/license/keys.js +14 -0
- package/dist/license/verify.js +56 -0
- package/dist/local/ports.js +33 -0
- package/dist/main.js +642 -0
- package/dist/products.js +1528 -0
- package/dist/readme.js +228 -0
- package/dist/state.js +58 -0
- package/dist/steps.js +875 -0
- package/dist/templates.js +31 -0
- package/dist/theme/preview.js +67 -0
- package/dist/theme/vendor/color.js +133 -0
- package/dist/theme/vendor/tokens.js +314 -0
- package/dist/theme/vendor/validate.js +219 -0
- package/dist/ui/prompt.js +108 -0
- package/dist/ui/term.js +92 -0
- package/dist/update.js +348 -0
- package/package.json +49 -4
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Where the templates come from: the download unlocked by activation (the normal case: the templates ARE the paid product)
|
|
2
|
+
// or a local folder (--templates, for whoever develops Overture and for tests).
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { mkdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { HumanError } from "./errors.js";
|
|
7
|
+
export async function downloadTemplates(ref, tmpDir, f, exec) {
|
|
8
|
+
let res;
|
|
9
|
+
try {
|
|
10
|
+
res = await f(ref.url, { signal: AbortSignal.timeout(300_000) });
|
|
11
|
+
}
|
|
12
|
+
catch (e) {
|
|
13
|
+
throw new HumanError('templates_download_failed', { status: 'rede' }, e.message);
|
|
14
|
+
}
|
|
15
|
+
if (!res.ok)
|
|
16
|
+
throw new HumanError('templates_download_failed', { status: res.status });
|
|
17
|
+
const buf = Buffer.from(await res.arrayBuffer());
|
|
18
|
+
const sum = createHash('sha256').update(buf).digest('hex');
|
|
19
|
+
if (sum !== ref.sha256)
|
|
20
|
+
throw new HumanError('templates_checksum', {}, `esperado ${ref.sha256}, veio ${sum}`);
|
|
21
|
+
rmSync(tmpDir, { recursive: true, force: true });
|
|
22
|
+
mkdirSync(join(tmpDir, 'root'), { recursive: true });
|
|
23
|
+
const file = join(tmpDir, 'templates.tgz');
|
|
24
|
+
writeFileSync(file, buf);
|
|
25
|
+
// tar exists on macOS, Linux and Windows 10+ (bsdtar)
|
|
26
|
+
const r = await exec('tar', ['-xzf', file, '-C', join(tmpDir, 'root')]);
|
|
27
|
+
if (r.code !== 0)
|
|
28
|
+
throw new HumanError('command_failed', { code: r.code, cmd: `tar -xzf templates.tgz` }, r.stderr);
|
|
29
|
+
rmSync(file, { force: true });
|
|
30
|
+
return join(tmpDir, 'root');
|
|
31
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Theme samples in the terminal, with the SAME engine as the app (buildTheme, faithful copy of
|
|
2
|
+
// overture-core/app/react-native/packages/theme/src — the theme-sync test checks it has not diverged).
|
|
3
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { contrast } from "./vendor/color.js";
|
|
6
|
+
import { checkThemeShape, normalizeHex as fullHex } from "./vendor/validate.js";
|
|
7
|
+
import { buildTheme, PRESETS, resolveConfig } from "./vendor/tokens.js";
|
|
8
|
+
import { t } from "../i18n/index.js";
|
|
9
|
+
export const PRESET_IDS = Object.keys(PRESETS);
|
|
10
|
+
export function normalizeHex(v) {
|
|
11
|
+
const h = v.trim().replace(/^#/, '').toUpperCase();
|
|
12
|
+
return `#${h}`;
|
|
13
|
+
}
|
|
14
|
+
/** One line per mode: button, my bubble, the other's bubble, highlight. */
|
|
15
|
+
export function themeLine(out, cfg, label, button) {
|
|
16
|
+
const parts = [];
|
|
17
|
+
for (const scheme of ['light', 'dark']) {
|
|
18
|
+
const th = buildTheme(cfg, scheme);
|
|
19
|
+
const c = th.colors;
|
|
20
|
+
parts.push(out.swatch(c.bg, ' ') +
|
|
21
|
+
out.swatch(c.primary, ` ${button} `, c.onPrimary) +
|
|
22
|
+
out.swatch(c.bg, ' ') +
|
|
23
|
+
out.swatch(c.bubbleMine, ` ${t('theme.mine')} `, c.onBubbleMine) +
|
|
24
|
+
out.swatch(c.bg, ' ') +
|
|
25
|
+
out.swatch(c.bubbleOther, ` ${t('theme.other')} `, c.onBubbleOther) +
|
|
26
|
+
out.swatch(c.bg, ' ') +
|
|
27
|
+
out.swatch(c.accentSoft, ' ', c.onAccentSoft) +
|
|
28
|
+
out.swatch(c.bg, ' '));
|
|
29
|
+
}
|
|
30
|
+
const hex = out.dim(buildTheme(cfg, 'light').colors.primary);
|
|
31
|
+
return `${label.padEnd(7)} ${parts[0]} ${parts[1]} ${hex}`;
|
|
32
|
+
}
|
|
33
|
+
export function resolveTheme(preset, primary) {
|
|
34
|
+
const r = resolveConfig({ preset, ...(primary ? { primary: normalizeHex(primary) } : {}) });
|
|
35
|
+
return { preset: r.preset, mode: r.mode, primary: r.primary, accent: r.accent, radius: r.radius, font: r.font, density: r.density };
|
|
36
|
+
}
|
|
37
|
+
export const THEME_FILE = 'overture.theme.json';
|
|
38
|
+
/**
|
|
39
|
+
* The look the buyer chose on Ilorb Code: `<template folder>/overture.theme.json` (appended to the zip by the download,
|
|
40
|
+
* next to ilorb.env; same shape this installer writes). Validated with the engine's checkThemeShape (format: known keys,
|
|
41
|
+
* hex colors, enums). null = no file; `{ error }` = a file that is not usable (the caller warns and asks as usual).
|
|
42
|
+
* Its radius and font are KEPT (resolveConfig), not re-derived from the style.
|
|
43
|
+
*/
|
|
44
|
+
export function readThemeFile(dir) {
|
|
45
|
+
const file = join(dir, THEME_FILE);
|
|
46
|
+
if (!existsSync(file))
|
|
47
|
+
return null;
|
|
48
|
+
let input;
|
|
49
|
+
try {
|
|
50
|
+
input = JSON.parse(readFileSync(file, 'utf8'));
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return { error: 'not JSON' };
|
|
54
|
+
}
|
|
55
|
+
const issues = checkThemeShape(input).filter((i) => i.severity === 'error');
|
|
56
|
+
if (issues.length)
|
|
57
|
+
return { error: [...new Set(issues.map((i) => i.field || 'theme'))].join(', ') };
|
|
58
|
+
const r = resolveConfig(input);
|
|
59
|
+
// #abc → #AABBCC: the answers (and --primary) use 6 hex digits
|
|
60
|
+
return { theme: { preset: r.preset, mode: r.mode, primary: fullHex(r.primary), accent: fullHex(r.accent), radius: r.radius, font: r.font, density: r.density } };
|
|
61
|
+
}
|
|
62
|
+
/** What the engine did with the chosen color (to tell the buyer, with no surprise). */
|
|
63
|
+
export function primaryReport(cfg) {
|
|
64
|
+
const l = buildTheme(cfg, 'light').colors;
|
|
65
|
+
const d = buildTheme(cfg, 'dark').colors;
|
|
66
|
+
return { light: l.primary, dark: d.primary, ratioLight: Math.round(contrast(l.primary, l.onPrimary) * 10) / 10, adjusted: l.primary.toUpperCase() !== cfg.primary.toUpperCase() };
|
|
67
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// Ilorb color: sRGB ↔ OKLCH conversion, WCAG 2.x contrast and adjustment until the minimum is met.
|
|
2
|
+
// No dependencies. OKLCH is used because changing its lightness (L) does not change the perceived
|
|
3
|
+
// "tone" — which is what lets us generate a whole scale from ONE color the buyer chose.
|
|
4
|
+
const clamp01 = (x) => Math.min(1, Math.max(0, x));
|
|
5
|
+
export function hexToRgb(hex) {
|
|
6
|
+
let h = hex.trim().replace(/^#/, '');
|
|
7
|
+
if (h.length === 3)
|
|
8
|
+
h = h.split('').map((ch) => ch + ch).join('');
|
|
9
|
+
if (!/^[0-9a-fA-F]{6}$/.test(h))
|
|
10
|
+
throw new Error(`cor inválida: ${hex}`);
|
|
11
|
+
const n = parseInt(h, 16);
|
|
12
|
+
return [((n >> 16) & 255) / 255, ((n >> 8) & 255) / 255, (n & 255) / 255];
|
|
13
|
+
}
|
|
14
|
+
export function rgbToHex([r, g, b]) {
|
|
15
|
+
const to = (x) => Math.round(clamp01(x) * 255).toString(16).padStart(2, '0');
|
|
16
|
+
return `#${to(r)}${to(g)}${to(b)}`.toUpperCase();
|
|
17
|
+
}
|
|
18
|
+
const toLinear = (c) => (c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);
|
|
19
|
+
const fromLinear = (c) => (c <= 0.0031308 ? 12.92 * c : 1.055 * c ** (1 / 2.4) - 0.055);
|
|
20
|
+
export function hexToOklch(hex) {
|
|
21
|
+
const [r, g, b] = hexToRgb(hex).map(toLinear);
|
|
22
|
+
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
|
23
|
+
const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
|
|
24
|
+
const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
|
|
25
|
+
const L = 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s;
|
|
26
|
+
const A = 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s;
|
|
27
|
+
const B = 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s;
|
|
28
|
+
const c = Math.sqrt(A * A + B * B);
|
|
29
|
+
const h = ((Math.atan2(B, A) * 180) / Math.PI + 360) % 360;
|
|
30
|
+
return { l: L, c, h };
|
|
31
|
+
}
|
|
32
|
+
function oklchToRgbRaw({ l: L, c, h }) {
|
|
33
|
+
const A = c * Math.cos((h * Math.PI) / 180);
|
|
34
|
+
const B = c * Math.sin((h * Math.PI) / 180);
|
|
35
|
+
const l = (L + 0.3963377774 * A + 0.2158037573 * B) ** 3;
|
|
36
|
+
const m = (L - 0.1055613458 * A - 0.0638541728 * B) ** 3;
|
|
37
|
+
const s = (L - 0.0894841775 * A - 1.291485548 * B) ** 3;
|
|
38
|
+
return [
|
|
39
|
+
fromLinear(4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s),
|
|
40
|
+
fromLinear(-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s),
|
|
41
|
+
fromLinear(-0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s),
|
|
42
|
+
];
|
|
43
|
+
}
|
|
44
|
+
const inGamut = (rgb) => rgb.every((x) => x >= -1e-4 && x <= 1 + 1e-4);
|
|
45
|
+
/** OKLCH → hex. Outside the sRGB gamut, reduces chroma (keeps L and hue) until it fits. */
|
|
46
|
+
export function oklchToHex(o) {
|
|
47
|
+
const L = clamp01(o.l);
|
|
48
|
+
let rgb = oklchToRgbRaw({ ...o, l: L });
|
|
49
|
+
if (inGamut(rgb))
|
|
50
|
+
return rgbToHex(rgb);
|
|
51
|
+
let lo = 0;
|
|
52
|
+
let hi = o.c;
|
|
53
|
+
for (let i = 0; i < 24; i++) {
|
|
54
|
+
const mid = (lo + hi) / 2;
|
|
55
|
+
if (inGamut(oklchToRgbRaw({ l: L, c: mid, h: o.h })))
|
|
56
|
+
lo = mid;
|
|
57
|
+
else
|
|
58
|
+
hi = mid;
|
|
59
|
+
}
|
|
60
|
+
rgb = oklchToRgbRaw({ l: L, c: lo, h: o.h });
|
|
61
|
+
return rgbToHex(rgb);
|
|
62
|
+
}
|
|
63
|
+
/** WCAG 2.x relative luminance. */
|
|
64
|
+
export function luminance(hex) {
|
|
65
|
+
const [r, g, b] = hexToRgb(hex).map(toLinear);
|
|
66
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
67
|
+
}
|
|
68
|
+
/** WCAG 2.x contrast (1 to 21). */
|
|
69
|
+
export function contrast(a, b) {
|
|
70
|
+
const la = luminance(a);
|
|
71
|
+
const lb = luminance(b);
|
|
72
|
+
const [hi, lo] = la > lb ? [la, lb] : [lb, la];
|
|
73
|
+
return (hi + 0.05) / (lo + 0.05);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Adjusts only the lightness of `fg` until it has `min` contrast against `bg`.
|
|
77
|
+
* Goes in the direction away from the background (light background → darkens). If even the extreme
|
|
78
|
+
* does not reach it, returns the extreme (black or white), which is the best possible.
|
|
79
|
+
*/
|
|
80
|
+
export function ensureContrast(fg, bg, min) {
|
|
81
|
+
if (contrast(fg, bg) >= min)
|
|
82
|
+
return fg;
|
|
83
|
+
const o = hexToOklch(fg);
|
|
84
|
+
const darken = luminance(bg) > 0.18;
|
|
85
|
+
let lo = darken ? 0 : o.l;
|
|
86
|
+
let hi = darken ? o.l : 1;
|
|
87
|
+
// search for the lightness CLOSEST to the original that still passes
|
|
88
|
+
for (let i = 0; i < 28; i++) {
|
|
89
|
+
const mid = (lo + hi) / 2;
|
|
90
|
+
const ok = contrast(oklchToHex({ ...o, l: mid }), bg) >= min;
|
|
91
|
+
if (darken)
|
|
92
|
+
ok ? (lo = mid) : (hi = mid);
|
|
93
|
+
else
|
|
94
|
+
ok ? (hi = mid) : (lo = mid);
|
|
95
|
+
}
|
|
96
|
+
const out = oklchToHex({ ...o, l: darken ? lo : hi });
|
|
97
|
+
if (contrast(out, bg) >= min)
|
|
98
|
+
return out;
|
|
99
|
+
return darken ? '#000000' : '#FFFFFF';
|
|
100
|
+
}
|
|
101
|
+
/** Text on a solid color: white or near-black, whichever has more contrast. */
|
|
102
|
+
export function onColor(bg, dark = '#0B0D12') {
|
|
103
|
+
return contrast('#FFFFFF', bg) >= contrast(dark, bg) ? '#FFFFFF' : dark;
|
|
104
|
+
}
|
|
105
|
+
/** Mixes `a` with `b` at `t` (0 = a, 1 = b) in OKLab — for "soft" status backgrounds. */
|
|
106
|
+
export function mix(a, b, t) {
|
|
107
|
+
const A = hexToOklch(a);
|
|
108
|
+
const B = hexToOklch(b);
|
|
109
|
+
const ax = A.c * Math.cos((A.h * Math.PI) / 180);
|
|
110
|
+
const ay = A.c * Math.sin((A.h * Math.PI) / 180);
|
|
111
|
+
const bx = B.c * Math.cos((B.h * Math.PI) / 180);
|
|
112
|
+
const by = B.c * Math.sin((B.h * Math.PI) / 180);
|
|
113
|
+
const x = ax + (bx - ax) * t;
|
|
114
|
+
const y = ay + (by - ay) * t;
|
|
115
|
+
return oklchToHex({
|
|
116
|
+
l: A.l + (B.l - A.l) * t,
|
|
117
|
+
c: Math.sqrt(x * x + y * y),
|
|
118
|
+
h: ((Math.atan2(y, x) * 180) / Math.PI + 360) % 360,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
export const SCALE_STEPS = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950];
|
|
122
|
+
const SCALE_L = [0.975, 0.945, 0.89, 0.815, 0.72, 0.63, 0.55, 0.475, 0.395, 0.325, 0.255];
|
|
123
|
+
const SCALE_C = [0.1, 0.22, 0.42, 0.66, 0.88, 1, 1, 0.95, 0.85, 0.72, 0.58];
|
|
124
|
+
/** 50–950 scale with the tone of `hex` (the original color does not need to land on a step). */
|
|
125
|
+
export function buildScale(hex) {
|
|
126
|
+
const o = hexToOklch(hex);
|
|
127
|
+
const out = {};
|
|
128
|
+
SCALE_STEPS.forEach((step, i) => {
|
|
129
|
+
// the three lists have the same size; the `??` only exists to compile with noUncheckedIndexedAccess
|
|
130
|
+
out[step] = oklchToHex({ l: SCALE_L[i] ?? 0.5, c: o.c * (SCALE_C[i] ?? 1), h: o.h });
|
|
131
|
+
});
|
|
132
|
+
return out;
|
|
133
|
+
}
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
// Ilorb tokens — the ONLY source of visual values for all products.
|
|
2
|
+
// No screen writes a loose color, size, radius or shadow: everything comes out of buildTheme().
|
|
3
|
+
import { buildScale, contrast, ensureContrast, hexToOklch, mix, oklchToHex, onColor } from "./color.js";
|
|
4
|
+
/** body size in px: the rest of the scale follows in the same proportion */
|
|
5
|
+
export const FONT_SIZE = { min: 14, max: 18, default: 16 };
|
|
6
|
+
export const PRESETS = {
|
|
7
|
+
clean: { label: 'Clean', mode: 'system', primary: '#4F46E5', accent: '#B9A7FF', radius: 'soft', font: 'inter', density: 'regular' },
|
|
8
|
+
bold: { label: 'Bold', mode: 'system', primary: '#F04438', accent: '#C4B1FF', radius: 'sharp', font: 'jakarta', density: 'regular' },
|
|
9
|
+
soft: { label: 'Soft', mode: 'light', primary: '#8B5CF6', accent: '#D4C4FF', radius: 'round', font: 'nunito', density: 'comfortable' },
|
|
10
|
+
night: { label: 'Night', mode: 'dark', primary: '#10B981', accent: '#A996FF', radius: 'soft', font: 'inter', density: 'compact' },
|
|
11
|
+
};
|
|
12
|
+
export const MODE_IDS = ['system', 'light', 'dark'];
|
|
13
|
+
export const RADIUS_IDS = ['sharp', 'soft', 'round'];
|
|
14
|
+
export const FONT_IDS = ['system', 'inter', 'jakarta', 'nunito'];
|
|
15
|
+
export const DENSITY_IDS = ['compact', 'regular', 'comfortable'];
|
|
16
|
+
export const HEADING_WEIGHT_IDS = ['semibold', 'bold', 'extrabold'];
|
|
17
|
+
/** color hex (#RGB or #RRGGBB). Letter case is kept (the buyer's color comes back as it came). */
|
|
18
|
+
export const isHex = (v) => typeof v === 'string' && /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(v);
|
|
19
|
+
const pickEnum = (v, ok, dflt) => ok.includes(v) ? v : dflt;
|
|
20
|
+
const pickHex = (v) => (isHex(v) ? v : null);
|
|
21
|
+
const pickUrl = (v) => (typeof v === 'string' && v.length > 0 && v.length <= 500 ? v : null);
|
|
22
|
+
/**
|
|
23
|
+
* Completes the config with the style. Never breaks: an invalid value (hand-written, old version) falls back to the default —
|
|
24
|
+
* whoever wants to REJECT an invalid value uses `validateTheme()` (validate.ts) before saving.
|
|
25
|
+
*/
|
|
26
|
+
export function resolveConfig(cfg) {
|
|
27
|
+
const preset = cfg.preset in PRESETS ? cfg.preset : 'clean';
|
|
28
|
+
const base = PRESETS[preset];
|
|
29
|
+
const secondary = pickHex(cfg.secondary) ?? pickHex(cfg.accent) ?? base.accent;
|
|
30
|
+
const size = typeof cfg.fontSize === 'number' && Number.isFinite(cfg.fontSize)
|
|
31
|
+
? Math.min(FONT_SIZE.max, Math.max(FONT_SIZE.min, Math.round(cfg.fontSize)))
|
|
32
|
+
: FONT_SIZE.default;
|
|
33
|
+
return {
|
|
34
|
+
preset,
|
|
35
|
+
mode: pickEnum(cfg.mode, MODE_IDS, base.mode),
|
|
36
|
+
primary: pickHex(cfg.primary) ?? base.primary,
|
|
37
|
+
secondary,
|
|
38
|
+
accent: secondary,
|
|
39
|
+
radius: pickEnum(cfg.radius, RADIUS_IDS, base.radius),
|
|
40
|
+
font: pickEnum(cfg.font, FONT_IDS, base.font),
|
|
41
|
+
density: pickEnum(cfg.density, DENSITY_IDS, base.density),
|
|
42
|
+
fontSize: size,
|
|
43
|
+
headingWeight: pickEnum(cfg.headingWeight, HEADING_WEIGHT_IDS, 'bold'),
|
|
44
|
+
background: pickHex(cfg.background),
|
|
45
|
+
text: pickHex(cfg.text),
|
|
46
|
+
backgroundDark: pickHex(cfg.backgroundDark),
|
|
47
|
+
textDark: pickHex(cfg.textDark),
|
|
48
|
+
success: pickHex(cfg.success),
|
|
49
|
+
danger: pickHex(cfg.danger),
|
|
50
|
+
logo: pickUrl(cfg.logo),
|
|
51
|
+
logoDark: pickUrl(cfg.logoDark),
|
|
52
|
+
favicon: pickUrl(cfg.favicon),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
// ─── Escalas fixas ─────────────────────────────────────────────────────────────────────────
|
|
56
|
+
/** space: base 4. Use space[n], never a loose number. */
|
|
57
|
+
export const space = { 0: 0, 0.5: 2, 1: 4, 2: 8, 3: 12, 4: 16, 5: 20, 6: 24, 8: 32, 10: 40, 12: 48, 16: 64 };
|
|
58
|
+
const RADII = {
|
|
59
|
+
sharp: { xs: 2, sm: 4, md: 6, lg: 8, xl: 12, full: 999 },
|
|
60
|
+
soft: { xs: 4, sm: 8, md: 12, lg: 16, xl: 24, full: 999 },
|
|
61
|
+
round: { xs: 6, sm: 12, md: 16, lg: 24, xl: 32, full: 999 },
|
|
62
|
+
};
|
|
63
|
+
/** control height and vertical breathing room. The touch minimum (44) NEVER drops, not even in compact. */
|
|
64
|
+
const DENSITY = {
|
|
65
|
+
compact: { control: 44, controlSm: 36, listItem: 52, padY: 8, gap: 8 },
|
|
66
|
+
regular: { control: 48, controlSm: 40, listItem: 60, padY: 12, gap: 12 },
|
|
67
|
+
comfortable: { control: 52, controlSm: 44, listItem: 68, padY: 16, gap: 16 },
|
|
68
|
+
};
|
|
69
|
+
export const FONTS = {
|
|
70
|
+
system: { regular: 'System', medium: 'System', semibold: 'System', bold: 'System', extrabold: 'System' },
|
|
71
|
+
inter: { regular: 'Inter-Regular', medium: 'Inter-Medium', semibold: 'Inter-SemiBold', bold: 'Inter-Bold', extrabold: 'Inter-ExtraBold', file: 'Inter' },
|
|
72
|
+
jakarta: {
|
|
73
|
+
regular: 'PlusJakartaSans-Regular', medium: 'PlusJakartaSans-Medium',
|
|
74
|
+
semibold: 'PlusJakartaSans-SemiBold', bold: 'PlusJakartaSans-ExtraBold', extrabold: 'PlusJakartaSans-ExtraBold', file: 'PlusJakartaSans',
|
|
75
|
+
},
|
|
76
|
+
nunito: { regular: 'Nunito-Regular', medium: 'Nunito-Medium', semibold: 'Nunito-SemiBold', bold: 'Nunito-Bold', extrabold: 'Nunito-ExtraBold', file: 'Nunito' },
|
|
77
|
+
};
|
|
78
|
+
/** in Arabic, swaps the whole family (the Latin ones above have no Arabic). IBM Plex Sans Arabic goes up to Bold (700). */
|
|
79
|
+
export const FONT_ARABIC = {
|
|
80
|
+
regular: 'IBMPlexSansArabic-Regular', medium: 'IBMPlexSansArabic-Medium',
|
|
81
|
+
semibold: 'IBMPlexSansArabic-SemiBold', bold: 'IBMPlexSansArabic-Bold', extrabold: 'IBMPlexSansArabic-Bold', file: 'IBMPlexSansArabic',
|
|
82
|
+
};
|
|
83
|
+
const TYPE_SCALE = {
|
|
84
|
+
display: { size: 32, line: 40, weight: 'bold' },
|
|
85
|
+
title1: { size: 26, line: 32, weight: 'bold' },
|
|
86
|
+
title2: { size: 21, line: 28, weight: 'semibold' },
|
|
87
|
+
headline: { size: 17, line: 24, weight: 'semibold' },
|
|
88
|
+
body: { size: 16, line: 24, weight: 'regular' },
|
|
89
|
+
bodyStrong: { size: 16, line: 24, weight: 'semibold' },
|
|
90
|
+
callout: { size: 15, line: 22, weight: 'regular' },
|
|
91
|
+
subhead: { size: 14, line: 20, weight: 'medium' },
|
|
92
|
+
footnote: { size: 13, line: 18, weight: 'regular' },
|
|
93
|
+
caption: { size: 12, line: 16, weight: 'medium' },
|
|
94
|
+
};
|
|
95
|
+
/** letter spacing of headings (fraction of the size): large letters look firmer slightly closer together.
|
|
96
|
+
* Body and caption stay at 0. In Arabic it is always 0 (the script is joined: spacing breaks the letters). */
|
|
97
|
+
const TRACKING = { display: -0.022, title1: -0.02, title2: -0.012, headline: -0.008 };
|
|
98
|
+
/** weight of each heading per `headingWeight` ('bold' = the usual: display/title1 bold, title2 semibold) */
|
|
99
|
+
const HEADING_WEIGHTS = {
|
|
100
|
+
semibold: { top: 'semibold', title2: 'semibold' },
|
|
101
|
+
bold: { top: 'bold', title2: 'semibold' },
|
|
102
|
+
extrabold: { top: 'extrabold', title2: 'bold' },
|
|
103
|
+
};
|
|
104
|
+
export const motion = { fast: 120, base: 200, slow: 320, easing: 'cubic-bezier(0.2, 0, 0, 1)' };
|
|
105
|
+
export const iconSize = { sm: 16, md: 20, lg: 24, xl: 32 };
|
|
106
|
+
export const zIndex = { base: 0, sticky: 10, sheet: 40, modal: 50, toast: 60 };
|
|
107
|
+
const STATUS_HUE_SOURCE = { success: '#12B76A', warning: '#F79009', danger: '#F04438', info: '#2E90FA', live: '#E5163A' };
|
|
108
|
+
function neutralScale(primary) {
|
|
109
|
+
// neutrals slightly tinted by the brand tone: the whole app "matches" effortlessly
|
|
110
|
+
const { h } = hexToOklch(primary);
|
|
111
|
+
return buildScale(oklchToHex({ l: 0.6, c: 0.018, h }));
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Solid color (button, badge) + the text on top, with 4.5 guaranteed. Prefers WHITE text when it is enough to
|
|
115
|
+
* darken a little (red, orange, medium green); if it would need to darken a lot (yellow, light
|
|
116
|
+
* cyan), keeps the color and uses dark text — the buyer's brand stays recognizable.
|
|
117
|
+
*/
|
|
118
|
+
export function solidWithOn(color, maxShift = 0.09) {
|
|
119
|
+
if (contrast('#FFFFFF', color) >= 4.5)
|
|
120
|
+
return { solid: color, on: '#FFFFFF' };
|
|
121
|
+
const forWhite = ensureContrast(color, '#FFFFFF', 4.5);
|
|
122
|
+
if (hexToOklch(color).l - hexToOklch(forWhite).l <= maxShift)
|
|
123
|
+
return { solid: forWhite, on: '#FFFFFF' };
|
|
124
|
+
const dark = onColor(color);
|
|
125
|
+
return { solid: ensureContrast(color, dark, 4.5), on: dark };
|
|
126
|
+
}
|
|
127
|
+
function status(source, scheme, bg, customBg = false) {
|
|
128
|
+
const sc = buildScale(source);
|
|
129
|
+
const { solid, on } = scheme === 'light' ? solidWithOn(source) : { solid: sc[400], on: onColor(sc[400]) };
|
|
130
|
+
return {
|
|
131
|
+
solid,
|
|
132
|
+
on,
|
|
133
|
+
soft: scheme === 'light' && !customBg ? sc[50] : mix(bg, sc[500], scheme === 'light' ? 0.12 : 0.18),
|
|
134
|
+
text: ensureContrast(scheme === 'light' ? sc[700] : sc[300], bg, 4.5),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
// ─── Buyer background and text ─────────────────────────────────────────────────────────────
|
|
138
|
+
/** Range of each mode: the light background needs ≥ 10:1 with black; the dark one, ≥ 10:1 with white. */
|
|
139
|
+
export const BACKGROUND_RANGE = { light: { against: '#000000', min: 10 }, dark: { against: '#FFFFFF', min: 10 } };
|
|
140
|
+
/** minimum contrast of the buyer's text over their background (WCAG AA, normal text) */
|
|
141
|
+
export const TEXT_MIN = 4.5;
|
|
142
|
+
/** contrast the DEFAULT text (no buyer choice) aims for: AAA */
|
|
143
|
+
export const TEXT_DEFAULT_MIN = 7;
|
|
144
|
+
const DEFAULT_DARK_TEXT = '#F2F3F5';
|
|
145
|
+
const chroma = (hex) => hexToOklch(hex).c;
|
|
146
|
+
/** background within the mode range (only the lightness changes) */
|
|
147
|
+
export function clampBackground(bg, scheme) {
|
|
148
|
+
const r = BACKGROUND_RANGE[scheme];
|
|
149
|
+
return ensureContrast(bg, r.against, r.min);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* The mode's background and text BEFORE correction, and where they came from. In dark, without `backgroundDark`, derives from the
|
|
153
|
+
* light `background` when it has a color (buyer's tone, dark-background lightness); same for the text.
|
|
154
|
+
* `null` = the buyer did not choose (the engine uses the style default).
|
|
155
|
+
*/
|
|
156
|
+
export function chosenSurface(config, scheme) {
|
|
157
|
+
if (scheme === 'light')
|
|
158
|
+
return { bg: config.background, text: config.text, bgFrom: config.background ? 'background' : null, textFrom: config.text ? 'text' : null };
|
|
159
|
+
let bg = config.backgroundDark;
|
|
160
|
+
let bgFrom = bg ? 'backgroundDark' : null;
|
|
161
|
+
if (!bg && config.background && chroma(config.background) >= 0.012) {
|
|
162
|
+
const o = hexToOklch(config.background);
|
|
163
|
+
bg = oklchToHex({ l: 0.17, c: Math.min(o.c, 0.035), h: o.h });
|
|
164
|
+
bgFrom = 'derived';
|
|
165
|
+
}
|
|
166
|
+
let text = config.textDark;
|
|
167
|
+
let textFrom = text ? 'textDark' : null;
|
|
168
|
+
if (!text && config.text && chroma(config.text) >= 0.012) {
|
|
169
|
+
const o = hexToOklch(config.text);
|
|
170
|
+
text = oklchToHex({ l: 0.95, c: Math.min(o.c, 0.02), h: o.h });
|
|
171
|
+
textFrom = 'derived';
|
|
172
|
+
}
|
|
173
|
+
return { bg, text, bgFrom, textFrom };
|
|
174
|
+
}
|
|
175
|
+
/** the mode's default text (the usual: near-black in the brand tone / near-white) */
|
|
176
|
+
export function defaultText(config, scheme) {
|
|
177
|
+
return scheme === 'light' ? neutralScale(config.primary)[950] : DEFAULT_DARK_TEXT;
|
|
178
|
+
}
|
|
179
|
+
/** the mode's default background */
|
|
180
|
+
export function defaultBackground(config, scheme) {
|
|
181
|
+
return scheme === 'light' ? neutralScale(config.primary)[50] : oklchToHex({ ...hexToOklch(neutralScale(config.primary)[950]), l: 0.17 });
|
|
182
|
+
}
|
|
183
|
+
export function buildTheme(input, scheme, opts = {}) {
|
|
184
|
+
const config = resolveConfig(input);
|
|
185
|
+
const dir = opts.dir ?? (opts.locale?.startsWith('ar') ? 'rtl' : 'ltr');
|
|
186
|
+
const arabic = opts.locale?.startsWith('ar') ?? false;
|
|
187
|
+
const P = buildScale(config.primary);
|
|
188
|
+
const N = neutralScale(config.primary);
|
|
189
|
+
const light = scheme === 'light';
|
|
190
|
+
const chosen = chosenSurface(config, scheme);
|
|
191
|
+
const customBg = !!chosen.bg;
|
|
192
|
+
// backgrounds: the buyer's (within the mode range) or the usual ones
|
|
193
|
+
let bg, surface, surfaceMuted, surfacePressed, bgElevated, border;
|
|
194
|
+
if (chosen.bg) {
|
|
195
|
+
bg = clampBackground(chosen.bg, scheme);
|
|
196
|
+
const o = hexToOklch(bg);
|
|
197
|
+
const at = (dl) => oklchToHex({ l: o.l + dl, c: o.c, h: o.h });
|
|
198
|
+
surface = at(light ? -0.025 : 0.04);
|
|
199
|
+
surfaceMuted = at(light ? -0.055 : 0.08);
|
|
200
|
+
surfacePressed = at(light ? -0.09 : 0.12);
|
|
201
|
+
border = at(light ? -0.09 : 0.14);
|
|
202
|
+
bgElevated = light ? bg : surface;
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
bg = light ? N[50] : oklchToHex({ ...hexToOklch(N[950]), l: 0.17 });
|
|
206
|
+
surface = light ? '#FFFFFF' : oklchToHex({ ...hexToOklch(N[950]), l: 0.21 });
|
|
207
|
+
surfaceMuted = light ? N[100] : oklchToHex({ ...hexToOklch(N[950]), l: 0.25 });
|
|
208
|
+
surfacePressed = light ? N[200] : oklchToHex({ ...hexToOklch(N[950]), l: 0.29 });
|
|
209
|
+
bgElevated = light ? '#FFFFFF' : surface;
|
|
210
|
+
border = light ? N[200] : oklchToHex({ ...hexToOklch(N[950]), l: 0.31 });
|
|
211
|
+
}
|
|
212
|
+
// highlight/secondary (lilac by default): accent = decorative (bubbles, illustration); accentSoft = badge/icon background;
|
|
213
|
+
// accentWash = the "veil" at the top of the login and welcome screens (fades into bg as a gradient)
|
|
214
|
+
const A = hexToOklch(config.secondary);
|
|
215
|
+
const accent = light ? config.secondary : oklchToHex({ ...A, l: Math.min(A.l, 0.62) });
|
|
216
|
+
const accentSoft = light && !customBg ? oklchToHex({ l: 0.95, c: Math.min(A.c, 0.045), h: A.h }) : mix(bg, config.secondary, 0.2);
|
|
217
|
+
const accentWash = light && !customBg ? oklchToHex({ l: 0.975, c: Math.min(A.c, 0.03), h: A.h }) : mix(bg, config.secondary, 0.12);
|
|
218
|
+
const onAccentSoft = ensureContrast(light ? oklchToHex({ l: 0.42, c: Math.min(A.c * 1.4, 0.16), h: A.h }) : oklchToHex({ l: 0.88, c: Math.min(A.c, 0.08), h: A.h }), accentSoft, 4.5);
|
|
219
|
+
// text: the buyer's (minimum 4.5) or the usual; in both cases guaranteed over bg, surface and the veil
|
|
220
|
+
let text;
|
|
221
|
+
let textMuted;
|
|
222
|
+
if (chosen.bg || chosen.text) {
|
|
223
|
+
const min = chosen.text ? TEXT_MIN : TEXT_DEFAULT_MIN;
|
|
224
|
+
text = chosen.text ?? defaultText(config, scheme);
|
|
225
|
+
for (const over of [bg, surface, accentWash])
|
|
226
|
+
text = ensureContrast(text, over, min);
|
|
227
|
+
textMuted = mix(text, bg, 0.38);
|
|
228
|
+
for (const over of [bg, surface, accentWash])
|
|
229
|
+
textMuted = ensureContrast(textMuted, over, 4.5);
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
text = light ? N[950] : DEFAULT_DARK_TEXT;
|
|
233
|
+
// textMuted must pass over the background AND over the surface (cards)
|
|
234
|
+
textMuted = ensureContrast(ensureContrast(light ? N[600] : N[400], bg, 4.5), surface, 4.5);
|
|
235
|
+
textMuted = ensureContrast(textMuted, accentWash, 4.5); // login and welcome use secondary text over the veil
|
|
236
|
+
}
|
|
237
|
+
// primary button: the buyer's color, fixed only as much as needed for the text to pass 4.5
|
|
238
|
+
const base = light ? config.primary : ensureContrast(P[400], bg, 3);
|
|
239
|
+
const { solid: primary, on: onPrimary } = light ? solidWithOn(base) : { solid: ensureContrast(base, onColor(base), 4.5), on: onColor(base) };
|
|
240
|
+
const primaryPressed = oklchToHex({ ...hexToOklch(primary), l: hexToOklch(primary).l + (light ? -0.06 : 0.06) });
|
|
241
|
+
const primarySoft = light && !customBg ? P[50] : mix(bg, P[500], light ? 0.14 : 0.2);
|
|
242
|
+
const primaryText = ensureContrast(ensureContrast(light ? P[600] : P[300], bg, 4.5), surface, 4.5);
|
|
243
|
+
const onPrimarySoft = ensureContrast(primaryText, primarySoft, 4.5);
|
|
244
|
+
const S = {
|
|
245
|
+
success: status(config.success ?? STATUS_HUE_SOURCE.success, scheme, bg, customBg),
|
|
246
|
+
warning: status(STATUS_HUE_SOURCE.warning, scheme, bg, customBg),
|
|
247
|
+
danger: status(config.danger ?? STATUS_HUE_SOURCE.danger, scheme, bg, customBg),
|
|
248
|
+
info: status(STATUS_HUE_SOURCE.info, scheme, bg, customBg),
|
|
249
|
+
};
|
|
250
|
+
// the colored text of notices also passes over the notice's own soft background
|
|
251
|
+
for (const k of ['success', 'warning', 'danger', 'info'])
|
|
252
|
+
S[k].text = ensureContrast(S[k].text, S[k].soft, 4.5);
|
|
253
|
+
const live = ensureContrast(STATUS_HUE_SOURCE.live, '#FFFFFF', 4.5);
|
|
254
|
+
const colors = {
|
|
255
|
+
bg, bgElevated, surface, surfaceMuted, surfacePressed,
|
|
256
|
+
border,
|
|
257
|
+
// field/control border: it is the only thing showing the boundary → 3:1 (WCAG 1.4.11)
|
|
258
|
+
borderStrong: ensureContrast(light ? N[400] : N[500], bg, 3),
|
|
259
|
+
overlay: light ? 'rgba(12,14,20,0.5)' : 'rgba(0,0,0,0.62)',
|
|
260
|
+
focus: ensureContrast(light ? P[500] : P[300], bg, 3),
|
|
261
|
+
text, textMuted,
|
|
262
|
+
textSubtle: light ? N[400] : N[600], // ONLY disabled/decorative (exempt from contrast)
|
|
263
|
+
textInverse: light ? '#FFFFFF' : N[950],
|
|
264
|
+
primary, primaryPressed, onPrimary, primarySoft, onPrimarySoft, primaryText,
|
|
265
|
+
accent, accentSoft, onAccentSoft, accentWash,
|
|
266
|
+
secondary: accent, secondarySoft: accentSoft, onSecondarySoft: onAccentSoft,
|
|
267
|
+
success: S.success.solid, onSuccess: S.success.on, successSoft: S.success.soft, successText: S.success.text,
|
|
268
|
+
warning: S.warning.solid, onWarning: S.warning.on, warningSoft: S.warning.soft, warningText: S.warning.text,
|
|
269
|
+
danger: S.danger.solid, onDanger: S.danger.on, dangerSoft: S.danger.soft, dangerText: S.danger.text,
|
|
270
|
+
info: S.info.solid, onInfo: S.info.on, infoSoft: S.info.soft, infoText: S.info.text,
|
|
271
|
+
live, onLive: '#FFFFFF',
|
|
272
|
+
bubbleMine: primary, onBubbleMine: onPrimary,
|
|
273
|
+
bubbleOther: surfaceMuted, onBubbleOther: text,
|
|
274
|
+
speaking: light ? ensureContrast(S.success.solid, bg, 3) : S.success.solid,
|
|
275
|
+
};
|
|
276
|
+
// guarantees the other person's bubble text (surfaceMuted can get close to the text in extreme themes)
|
|
277
|
+
if (contrast(colors.onBubbleOther, colors.bubbleOther) < 4.5)
|
|
278
|
+
colors.onBubbleOther = onColor(colors.bubbleOther);
|
|
279
|
+
const fam = arabic ? FONT_ARABIC : FONTS[config.font];
|
|
280
|
+
const weightCss = { regular: '400', medium: '500', semibold: '600', bold: config.font === 'jakarta' ? '800' : '700', extrabold: '800' };
|
|
281
|
+
const lineFactor = arabic ? 1.15 : 1; // Arabic has larger ascenders/descenders
|
|
282
|
+
const k = config.fontSize / FONT_SIZE.default; // a escala inteira acompanha o corpo escolhido
|
|
283
|
+
const hw = HEADING_WEIGHTS[config.headingWeight];
|
|
284
|
+
const weightOf = (role, w) => (role === 'display' || role === 'title1' ? hw.top : role === 'title2' ? hw.title2 : w);
|
|
285
|
+
const type = Object.fromEntries(Object.entries(TYPE_SCALE).map(([role, t]) => {
|
|
286
|
+
const w = weightOf(role, t.weight);
|
|
287
|
+
return [role, {
|
|
288
|
+
fontFamily: fam[w],
|
|
289
|
+
fontSize: Math.round(t.size * k),
|
|
290
|
+
lineHeight: Math.round(t.line * k * lineFactor),
|
|
291
|
+
...(TRACKING[role] && !arabic ? { letterSpacing: Math.round(TRACKING[role] * t.size * k * 100) / 100 } : {}),
|
|
292
|
+
// with a custom font the weight is already in the file; with "System" it goes through fontWeight
|
|
293
|
+
...(config.font === 'system' && !arabic ? { fontWeight: weightCss[w] } : {}),
|
|
294
|
+
}];
|
|
295
|
+
}));
|
|
296
|
+
const shadow = (y, blur, op, el) => light
|
|
297
|
+
? { shadowColor: '#0B0D12', shadowOffset: { width: 0, height: y }, shadowOpacity: op, shadowRadius: blur, elevation: el }
|
|
298
|
+
: { elevation: 0 }; // in dark, elevation comes from the surface color, not from a shadow
|
|
299
|
+
return {
|
|
300
|
+
config, scheme, dir, colors,
|
|
301
|
+
palette: { primary: P, neutral: N },
|
|
302
|
+
space,
|
|
303
|
+
radius: RADII[config.radius],
|
|
304
|
+
size: { ...DENSITY[config.density], touch: 44, icon: iconSize, avatar: { sm: 32, md: 40, lg: 56, xl: 88 } },
|
|
305
|
+
type,
|
|
306
|
+
elevation: { 0: {}, 1: shadow(1, 4, 0.07, 1), 2: shadow(4, 12, 0.1, 4), 3: shadow(12, 28, 0.16, 12) },
|
|
307
|
+
motion, zIndex,
|
|
308
|
+
assets: { logo: (light ? config.logo : config.logoDark ?? config.logo) ?? null, favicon: config.favicon },
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
/** claro/escuro final: "system" segue o aparelho */
|
|
312
|
+
export function schemeFor(mode, device) {
|
|
313
|
+
return mode === 'system' ? (device ?? 'light') : mode;
|
|
314
|
+
}
|