@hanzo/studio 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/LICENSE +29 -0
- package/NOTICE +68 -0
- package/lib/chat/store.d.ts +33 -0
- package/lib/chat/store.js +56 -0
- package/lib/chat/turn.d.ts +51 -0
- package/lib/chat/turn.js +274 -0
- package/lib/desk.d.ts +14 -0
- package/lib/desk.js +72 -0
- package/lib/gpu.d.ts +15 -0
- package/lib/gpu.js +41 -0
- package/lib/home.d.ts +6 -0
- package/lib/home.js +48 -0
- package/lib/host.d.ts +12 -0
- package/lib/host.js +18 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +11 -0
- package/lib/kinds/ad.d.ts +51 -0
- package/lib/kinds/ad.js +124 -0
- package/lib/kinds/document.d.ts +6 -0
- package/lib/kinds/document.js +271 -0
- package/lib/kinds/image.d.ts +47 -0
- package/lib/kinds/image.js +179 -0
- package/lib/kinds/index.d.ts +9 -0
- package/lib/kinds/index.js +12 -0
- package/lib/kinds/kind.d.ts +113 -0
- package/lib/kinds/kind.js +13 -0
- package/lib/kinds/mesh/index.d.ts +2 -0
- package/lib/kinds/mesh/index.js +76 -0
- package/lib/kinds/mesh/viewer.d.ts +7 -0
- package/lib/kinds/mesh/viewer.js +79 -0
- package/lib/kinds/poster/compose.d.ts +40 -0
- package/lib/kinds/poster/compose.js +289 -0
- package/lib/kinds/poster/index.d.ts +21 -0
- package/lib/kinds/poster/index.js +210 -0
- package/lib/kinds/sound.d.ts +6 -0
- package/lib/kinds/sound.js +100 -0
- package/lib/kinds/type/fonts.d.ts +30 -0
- package/lib/kinds/type/fonts.js +111 -0
- package/lib/kinds/type/index.d.ts +5 -0
- package/lib/kinds/type/index.js +117 -0
- package/lib/kinds/type/system.d.ts +164 -0
- package/lib/kinds/type/system.js +302 -0
- package/lib/kinds/video.d.ts +2 -0
- package/lib/kinds/video.js +81 -0
- package/lib/live.d.ts +44 -0
- package/lib/live.js +128 -0
- package/lib/made.d.ts +75 -0
- package/lib/made.js +36 -0
- package/lib/nav.d.ts +17 -0
- package/lib/nav.js +29 -0
- package/lib/pdf.d.ts +16 -0
- package/lib/pdf.js +53 -0
- package/lib/places.d.ts +6 -0
- package/lib/places.js +121 -0
- package/lib/raster.d.ts +7 -0
- package/lib/raster.js +53 -0
- package/lib/route.d.ts +33 -0
- package/lib/route.js +52 -0
- package/lib/starters.d.ts +31 -0
- package/lib/starters.js +62 -0
- package/lib/studio.d.ts +26 -0
- package/lib/studio.js +58 -0
- package/lib/talk.d.ts +3 -0
- package/lib/talk.js +369 -0
- package/lib/ui.d.ts +50 -0
- package/lib/ui.js +57 -0
- package/lib/use.d.ts +11 -0
- package/lib/use.js +35 -0
- package/lib/wire.d.ts +239 -0
- package/lib/wire.js +478 -0
- package/lib/zip.d.ts +9 -0
- package/lib/zip.js +60 -0
- package/package.json +75 -3
- package/README.md +0 -3
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The faces a type system may pair: Zen (the Hanzo family, @hanzo/font) and a
|
|
3
|
+
* short list of open fonts. Every one is SIL OFL 1.1, read from its own OFL.txt
|
|
4
|
+
* in github.com/google/fonts on 2026-10-16 (`licence` is that file), so a
|
|
5
|
+
* poster, a document or a deck drawn in any of them is free to ship.
|
|
6
|
+
*
|
|
7
|
+
* A face is loaded in the page by its stylesheet, and drawn into a picture
|
|
8
|
+
* (a poster's PNG, its PDF) by its bytes: `face()` reads the woff2 the
|
|
9
|
+
* stylesheet names and hands it back as a data: URL an SVG can embed.
|
|
10
|
+
*/
|
|
11
|
+
export type Role = 'sans' | 'serif' | 'display' | 'mono';
|
|
12
|
+
export interface Font {
|
|
13
|
+
family: string;
|
|
14
|
+
role: Role;
|
|
15
|
+
/** The weights it carries; a variable face carries the range. */
|
|
16
|
+
weights: readonly number[];
|
|
17
|
+
italic: boolean;
|
|
18
|
+
/** The stylesheet that loads it; '' for Zen, which the host already loads. */
|
|
19
|
+
css: string;
|
|
20
|
+
licence: string;
|
|
21
|
+
}
|
|
22
|
+
export declare const FONTS: readonly Font[];
|
|
23
|
+
export declare const FAMILIES: readonly string[];
|
|
24
|
+
export declare const font: (family: string) => Font;
|
|
25
|
+
/** A CSS font-family value with a fallback of its own role. */
|
|
26
|
+
export declare function stack(family: string): string;
|
|
27
|
+
/** Load a face in this page, once. */
|
|
28
|
+
export declare function use(family: string): void;
|
|
29
|
+
/** The @font-face rules for a face with its bytes inline, for an SVG that is drawn to a picture. */
|
|
30
|
+
export declare function face(family: string): Promise<string>;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The faces a type system may pair: Zen (the Hanzo family, @hanzo/font) and a
|
|
3
|
+
* short list of open fonts. Every one is SIL OFL 1.1, read from its own OFL.txt
|
|
4
|
+
* in github.com/google/fonts on 2026-10-16 (`licence` is that file), so a
|
|
5
|
+
* poster, a document or a deck drawn in any of them is free to ship.
|
|
6
|
+
*
|
|
7
|
+
* A face is loaded in the page by its stylesheet, and drawn into a picture
|
|
8
|
+
* (a poster's PNG, its PDF) by its bytes: `face()` reads the woff2 the
|
|
9
|
+
* stylesheet names and hands it back as a data: URL an SVG can embed.
|
|
10
|
+
*/
|
|
11
|
+
const OFL = (dir) => `https://github.com/google/fonts/blob/main/ofl/${dir}/OFL.txt`;
|
|
12
|
+
const G = (q) => `https://fonts.googleapis.com/css2?family=${q}&display=swap`;
|
|
13
|
+
export const FONTS = [
|
|
14
|
+
{ family: 'Zen', role: 'sans', weights: [100, 200, 300, 400, 500, 600, 700, 800, 900], italic: true, css: '', licence: 'https://www.npmjs.com/package/@hanzo/font (LICENSE.txt, SIL OFL 1.1)' },
|
|
15
|
+
{ family: 'Zen Mono', role: 'mono', weights: [100, 200, 300, 400, 500, 600, 700, 800, 900], italic: false, css: '', licence: 'https://www.npmjs.com/package/@hanzo/font (LICENSE.txt, SIL OFL 1.1)' },
|
|
16
|
+
{ family: 'Inter', role: 'sans', weights: [400, 500, 600, 700, 800], italic: true, css: G('Inter:ital,wght@0,400..800;1,400..800'), licence: OFL('inter') },
|
|
17
|
+
{ family: 'Manrope', role: 'sans', weights: [400, 500, 600, 700, 800], italic: false, css: G('Manrope:wght@400..800'), licence: OFL('manrope') },
|
|
18
|
+
{ family: 'DM Sans', role: 'sans', weights: [400, 500, 600, 700], italic: true, css: G('DM+Sans:ital,wght@0,400..700;1,400..700'), licence: OFL('dmsans') },
|
|
19
|
+
{ family: 'Work Sans', role: 'sans', weights: [400, 500, 600, 700], italic: true, css: G('Work+Sans:ital,wght@0,400..700;1,400..700'), licence: OFL('worksans') },
|
|
20
|
+
{ family: 'IBM Plex Sans', role: 'sans', weights: [400, 500, 600, 700], italic: true, css: G('IBM+Plex+Sans:ital,wght@0,400;0,500;0,600;0,700;1,400'), licence: OFL('ibmplexsans') },
|
|
21
|
+
{ family: 'Space Grotesk', role: 'display', weights: [400, 500, 600, 700], italic: false, css: G('Space+Grotesk:wght@400..700'), licence: OFL('spacegrotesk') },
|
|
22
|
+
{ family: 'Archivo', role: 'display', weights: [400, 500, 600, 700, 800, 900], italic: true, css: G('Archivo:ital,wght@0,400..900;1,400..900'), licence: OFL('archivo') },
|
|
23
|
+
{ family: 'Bricolage Grotesque', role: 'display', weights: [400, 500, 600, 700, 800], italic: false, css: G('Bricolage+Grotesque:wght@400..800'), licence: OFL('bricolagegrotesque') },
|
|
24
|
+
{ family: 'Syne', role: 'display', weights: [400, 500, 600, 700, 800], italic: false, css: G('Syne:wght@400..800'), licence: OFL('syne') },
|
|
25
|
+
{ family: 'Fraunces', role: 'serif', weights: [400, 500, 600, 700, 800, 900], italic: true, css: G('Fraunces:ital,wght@0,400..900;1,400..900'), licence: OFL('fraunces') },
|
|
26
|
+
{ family: 'Playfair Display', role: 'serif', weights: [400, 500, 600, 700, 800, 900], italic: true, css: G('Playfair+Display:ital,wght@0,400..900;1,400..900'), licence: OFL('playfairdisplay') },
|
|
27
|
+
{ family: 'DM Serif Display', role: 'serif', weights: [400], italic: true, css: G('DM+Serif+Display:ital@0;1'), licence: OFL('dmserifdisplay') },
|
|
28
|
+
{ family: 'Instrument Serif', role: 'serif', weights: [400], italic: true, css: G('Instrument+Serif:ital@0;1'), licence: OFL('instrumentserif') },
|
|
29
|
+
{ family: 'Cormorant Garamond', role: 'serif', weights: [400, 500, 600, 700], italic: true, css: G('Cormorant+Garamond:ital,wght@0,400..700;1,400..700'), licence: OFL('cormorantgaramond') },
|
|
30
|
+
{ family: 'EB Garamond', role: 'serif', weights: [400, 500, 600, 700, 800], italic: true, css: G('EB+Garamond:ital,wght@0,400..800;1,400..800'), licence: OFL('ebgaramond') },
|
|
31
|
+
{ family: 'Source Serif 4', role: 'serif', weights: [400, 500, 600, 700], italic: true, css: G('Source+Serif+4:ital,wght@0,400..700;1,400..700'), licence: OFL('sourceserif4') },
|
|
32
|
+
{ family: 'IBM Plex Mono', role: 'mono', weights: [400, 500, 600], italic: true, css: G('IBM+Plex+Mono:ital,wght@0,400;0,500;0,600;1,400'), licence: OFL('ibmplexmono') },
|
|
33
|
+
{ family: 'JetBrains Mono', role: 'mono', weights: [400, 500, 600, 700], italic: true, css: G('JetBrains+Mono:ital,wght@0,400..700;1,400..700'), licence: OFL('jetbrainsmono') },
|
|
34
|
+
];
|
|
35
|
+
export const FAMILIES = FONTS.map((f) => f.family);
|
|
36
|
+
export const font = (family) => FONTS.find((f) => f.family === family) ?? FONTS[0];
|
|
37
|
+
/** A CSS font-family value with a fallback of its own role. */
|
|
38
|
+
export function stack(family) {
|
|
39
|
+
const f = font(family);
|
|
40
|
+
const fall = f.role === 'serif' ? 'Georgia, serif' : f.role === 'mono' ? 'ui-monospace, monospace' : 'system-ui, sans-serif';
|
|
41
|
+
return `"${f.family}", ${fall}`;
|
|
42
|
+
}
|
|
43
|
+
const linked = new Set();
|
|
44
|
+
/** Load a face in this page, once. */
|
|
45
|
+
export function use(family) {
|
|
46
|
+
const f = font(family);
|
|
47
|
+
if (!f.css || linked.has(f.css) || typeof document === 'undefined')
|
|
48
|
+
return;
|
|
49
|
+
linked.add(f.css);
|
|
50
|
+
const link = document.createElement('link');
|
|
51
|
+
link.rel = 'stylesheet';
|
|
52
|
+
link.href = f.css;
|
|
53
|
+
document.head.appendChild(link);
|
|
54
|
+
}
|
|
55
|
+
const embedded = new Map();
|
|
56
|
+
/** The @font-face rules for a face with its bytes inline, for an SVG that is drawn to a picture. */
|
|
57
|
+
export function face(family) {
|
|
58
|
+
const f = font(family);
|
|
59
|
+
let hit = embedded.get(f.family);
|
|
60
|
+
if (!hit) {
|
|
61
|
+
hit = (async () => {
|
|
62
|
+
if (!f.css)
|
|
63
|
+
return zen(f.family);
|
|
64
|
+
const css = await (await fetch(f.css)).text();
|
|
65
|
+
// The Latin subset only: the blocks a stylesheet marks /* latin */.
|
|
66
|
+
const blocks = css.split('/* ').filter((b) => b.startsWith('latin */'));
|
|
67
|
+
const out = [];
|
|
68
|
+
for (const b of blocks.length ? blocks : [css]) {
|
|
69
|
+
const src = /url\((https:[^)]+\.woff2)\)/.exec(b)?.[1];
|
|
70
|
+
if (!src)
|
|
71
|
+
continue;
|
|
72
|
+
const data = await inline(src, 'font/woff2');
|
|
73
|
+
out.push(b.replace(/^latin \*\//, '').replace(/url\(https:[^)]+\.woff2\)/, `url(${data})`));
|
|
74
|
+
}
|
|
75
|
+
return out.join('\n');
|
|
76
|
+
})();
|
|
77
|
+
embedded.set(f.family, hit);
|
|
78
|
+
hit.catch(() => embedded.delete(f.family));
|
|
79
|
+
}
|
|
80
|
+
return hit;
|
|
81
|
+
}
|
|
82
|
+
/** Zen's faces as this page loaded them (@hanzo/font/css), found in its stylesheets. */
|
|
83
|
+
async function zen(family) {
|
|
84
|
+
const rules = [];
|
|
85
|
+
for (const sheet of Array.from(document.styleSheets)) {
|
|
86
|
+
let list;
|
|
87
|
+
try {
|
|
88
|
+
list = sheet.cssRules;
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
for (const r of Array.from(list)) {
|
|
94
|
+
if (r instanceof CSSFontFaceRule && r.style.getPropertyValue('font-family').replace(/["']/g, '').trim() === family) {
|
|
95
|
+
const src = /url\(["']?([^"')]+\.woff2)["']?\)/.exec(r.style.getPropertyValue('src'))?.[1];
|
|
96
|
+
if (!src)
|
|
97
|
+
continue;
|
|
98
|
+
const abs = new URL(src, sheet.href ?? document.baseURI).href;
|
|
99
|
+
rules.push(r.cssText.replace(/url\(["']?[^"')]+\.woff2["']?\)/, `url(${await inline(abs, 'font/woff2')})`));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return rules.join('\n');
|
|
104
|
+
}
|
|
105
|
+
async function inline(url, mime) {
|
|
106
|
+
const buf = new Uint8Array(await (await fetch(url)).arrayBuffer());
|
|
107
|
+
let bin = '';
|
|
108
|
+
for (let i = 0; i < buf.length; i += 0x8000)
|
|
109
|
+
bin += String.fromCharCode(...buf.subarray(i, i + 0x8000));
|
|
110
|
+
return `data:${mime};base64,${btoa(bin)}`;
|
|
111
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The type system kind: generated from a prompt or a brand, or started from a
|
|
4
|
+
* preset; drawn as a specimen page; exported as CSS variables, design tokens
|
|
5
|
+
* and a @hanzo/gui theme. Its spec IS the type system, so an edit in place is
|
|
6
|
+
* a patch to it, and `system.json` beside it is what the Brand chip lists.
|
|
7
|
+
*/
|
|
8
|
+
import { SizableText, XStack, YStack } from '@hanzo/gui';
|
|
9
|
+
import { Type } from '@hanzogui/lucide-icons-2';
|
|
10
|
+
import { useEffect } from 'react';
|
|
11
|
+
import { filename } from '../../made.js';
|
|
12
|
+
import { structured } from '../../wire.js';
|
|
13
|
+
import { Choice, Color, Row } from '../../ui.js';
|
|
14
|
+
import { str } from '../kind.js';
|
|
15
|
+
import { FAMILIES, font, stack, use } from './fonts.js';
|
|
16
|
+
import { BRIEF, contrast, css, gui, PRESETS, RATIOS, SCHEMA, settle, size, STEPS, tokens } from './system.js';
|
|
17
|
+
const preset = (name) => PRESETS.find((p) => p.name.toLowerCase() === name.toLowerCase()) ?? null;
|
|
18
|
+
const of = (spec) => settle(spec);
|
|
19
|
+
async function write(w, ask, base) {
|
|
20
|
+
w.doing('Pairing faces and setting the scale');
|
|
21
|
+
const from = base ? `\nStart from this system and change only what the brief asks:\n${JSON.stringify(base)}` : '';
|
|
22
|
+
const raw = await structured(w.wire, w.writer, BRIEF + from, ask, SCHEMA, w.signal);
|
|
23
|
+
return settle(raw, base ?? PRESETS[0]);
|
|
24
|
+
}
|
|
25
|
+
async function keep(w, t) {
|
|
26
|
+
await w.keep('system.json', new Blob([JSON.stringify(t, null, 2)], { type: 'application/json' }));
|
|
27
|
+
}
|
|
28
|
+
export const type = {
|
|
29
|
+
id: 'type',
|
|
30
|
+
label: 'Type system',
|
|
31
|
+
blurb: 'Faces, scale, weights and colours, as CSS, tokens and a gui theme.',
|
|
32
|
+
icon: Type,
|
|
33
|
+
tool: {
|
|
34
|
+
name: 'make_type_system',
|
|
35
|
+
description: 'Design a type system (a brand\'s faces, type scale, weights, line heights and colours). Use for "type system", "design system", "brand", "fonts", "typography". The result becomes the brand other things are drawn in.',
|
|
36
|
+
parameters: {
|
|
37
|
+
type: 'object',
|
|
38
|
+
properties: {
|
|
39
|
+
brief: { type: 'string', description: 'What the brand is and how it should feel, in the person\'s words.' },
|
|
40
|
+
preset: { type: 'string', enum: PRESETS.map((p) => p.name), description: 'A starting system, when one fits or the person names it.' },
|
|
41
|
+
},
|
|
42
|
+
required: ['brief'],
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
needs: () => null,
|
|
46
|
+
make: async (w, args) => {
|
|
47
|
+
const brief = str(args.brief);
|
|
48
|
+
const start = preset(str(args.preset));
|
|
49
|
+
const t = brief ? await write(w, brief, start) : (start ?? PRESETS[0]);
|
|
50
|
+
await keep(w, t);
|
|
51
|
+
return { title: t.name, draft: { spec: t, files: [], note: brief || `The ${t.name} preset`, by: brief ? w.writer : 'preset' } };
|
|
52
|
+
},
|
|
53
|
+
revise: async (w, made, change) => {
|
|
54
|
+
const now = of(made.versions[made.at].spec);
|
|
55
|
+
const t = change.patch ? settle({ ...now, ...change.patch }, now) : await write(w, str(change.instruction), now);
|
|
56
|
+
await keep(w, t);
|
|
57
|
+
return { spec: t, files: [], note: change.instruction ?? 'Edited', by: change.patch ? 'edit' : w.writer };
|
|
58
|
+
},
|
|
59
|
+
View: Specimen,
|
|
60
|
+
exports: [
|
|
61
|
+
{ label: 'CSS variables', run: async (_w, m, v) => ({ name: filename(m.title, 'css'), blob: new Blob([css(of(v.spec))], { type: 'text/css' }) }) },
|
|
62
|
+
{ label: 'Design tokens (JSON)', run: async (_w, m, v) => ({ name: filename(m.title, 'tokens.json'), blob: new Blob([tokens(of(v.spec))], { type: 'application/json' }) }) },
|
|
63
|
+
{ label: 'gui theme (TypeScript)', run: async (_w, m, v) => ({ name: filename(m.title, 'theme.ts'), blob: new Blob([gui(of(v.spec))], { type: 'text/typescript' }) }) },
|
|
64
|
+
{ label: 'Specimen page (HTML)', run: async (_w, m, v) => ({ name: filename(m.title, 'html'), blob: new Blob([page(of(v.spec))], { type: 'text/html' }) }) },
|
|
65
|
+
],
|
|
66
|
+
};
|
|
67
|
+
/** The faces a system names, loaded into this page. */
|
|
68
|
+
export function useFaces(t) {
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (!t)
|
|
71
|
+
return;
|
|
72
|
+
use(t.display);
|
|
73
|
+
use(t.text);
|
|
74
|
+
use(t.mono);
|
|
75
|
+
}, [t?.display, t?.text, t?.mono]);
|
|
76
|
+
}
|
|
77
|
+
const SAMPLE = 'Every surface reads in one voice: the same faces, the same steps, the same colours, wherever it is drawn.';
|
|
78
|
+
function Specimen({ version, edit, busy }) {
|
|
79
|
+
const t = of(version.spec);
|
|
80
|
+
useFaces(t);
|
|
81
|
+
const c = t.colors;
|
|
82
|
+
const caps = { fontFamily: stack(t.text), fontSize: size(t, 'caption'), letterSpacing: `${t.tracking.caps}em`, textTransform: 'uppercase', color: c.muted, fontWeight: t.weights.strong };
|
|
83
|
+
return (_jsxs(YStack, { flex: 1, minH: 0, overflow: "scroll", children: [_jsxs(XStack, { flexWrap: "wrap", gap: "$3", p: "$3", borderBottomWidth: 1, borderColor: "$borderColor", items: "flex-end", children: [_jsx(Row, { label: "Display", children: _jsx(Choice, { label: "Display face", value: t.display, options: FAMILIES.map((f) => ({ value: f })), onChange: (display) => edit({ display }, `Display face: ${display}`) }) }), _jsx(Row, { label: "Text", children: _jsx(Choice, { label: "Text face", value: t.text, options: FAMILIES.map((f) => ({ value: f })), onChange: (text) => edit({ text }, `Text face: ${text}`) }) }), _jsx(Row, { label: "Mono", children: _jsx(Choice, { label: "Mono face", value: t.mono, options: FAMILIES.filter((f) => font(f).role === 'mono').map((f) => ({ value: f })), onChange: (mono) => edit({ mono }, `Mono face: ${mono}`) }) }), _jsx(Row, { label: "Scale", children: _jsx(Choice, { label: "Scale ratio", value: String(t.scale.ratio), options: RATIOS.map(([r, n]) => ({ value: String(r), label: `${r} ${n}` })), onChange: (r) => edit({ scale: { ...t.scale, ratio: Number(r) } }, `Scale: ${r}`) }) }), _jsx(Row, { label: "Body", children: _jsx(Choice, { label: "Body size", value: String(t.scale.base), options: [14, 15, 16, 17, 18, 20].map((n) => ({ value: String(n), label: `${n}px` })), onChange: (b) => edit({ scale: { ...t.scale, base: Number(b) } }, `Body size: ${b}px`) }) }), Object.keys(c).map((k) => (_jsx(Row, { label: k, children: _jsx(Color, { label: `${k} colour`, value: c[k], onChange: (v) => edit({ colors: { ...c, [k]: v } }, `${k}: ${v}`) }) }, k))), busy ? (_jsx(SizableText, { size: "$1", color: "$soft", children: "Saving\u2026" })) : null] }), _jsxs("div", { "data-slot": "specimen", style: { background: c.paper, color: c.ink, padding: 'clamp(20px, 5vw, 56px)', minHeight: '100%' }, children: [_jsx("div", { style: caps, children: `${t.display} / ${t.text} / ${t.mono}` }), _jsx("h1", { style: {
|
|
84
|
+
fontFamily: stack(t.display),
|
|
85
|
+
fontWeight: t.weights.display,
|
|
86
|
+
fontSize: `clamp(40px, 9vw, ${size(t, 'display')}px)`,
|
|
87
|
+
lineHeight: t.leading.display,
|
|
88
|
+
letterSpacing: `${t.tracking.display}em`,
|
|
89
|
+
color: c.ink,
|
|
90
|
+
margin: '16px 0 12px',
|
|
91
|
+
}, children: t.name }), _jsx("p", { style: { fontFamily: stack(t.text), fontSize: size(t, 'lead'), lineHeight: t.leading.body, color: c.muted, maxWidth: '40em', margin: 0 }, children: t.blurb }), _jsx("div", { style: { height: 1, background: c.muted, opacity: 0.4, margin: '32px 0' } }), [...STEPS].reverse().map(([s]) => (_jsxs("div", { style: { display: 'flex', gap: 16, alignItems: 'baseline', margin: '0 0 10px', overflow: 'hidden' }, children: [_jsx("span", { style: { ...caps, width: 72, flexShrink: 0 }, children: `${s} ${size(t, s)}` }), _jsx("span", { style: {
|
|
92
|
+
color: c.ink,
|
|
93
|
+
fontFamily: stack(['display', 'h1', 'h2', 'h3', 'h4'].includes(s) ? t.display : t.text),
|
|
94
|
+
fontWeight: s === 'display' ? t.weights.display : ['h1', 'h2', 'h3', 'h4'].includes(s) ? t.weights.heading : t.weights.body,
|
|
95
|
+
fontSize: Math.min(size(t, s), 96),
|
|
96
|
+
lineHeight: s === 'display' ? t.leading.display : ['h1', 'h2', 'h3', 'h4'].includes(s) ? t.leading.heading : t.leading.body,
|
|
97
|
+
whiteSpace: 'nowrap',
|
|
98
|
+
textOverflow: 'ellipsis',
|
|
99
|
+
overflow: 'hidden',
|
|
100
|
+
}, children: "The quick brown fox" })] }, s))), _jsx("div", { style: { height: 1, background: c.muted, opacity: 0.4, margin: '32px 0' } }), _jsxs("div", { style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(220px, 1fr))', gap: 24 }, children: [_jsxs("div", { children: [_jsx("div", { style: caps, children: "Text" }), _jsxs("p", { style: { fontFamily: stack(t.text), fontSize: size(t, 'body'), lineHeight: t.leading.body, fontWeight: t.weights.body, color: c.ink }, children: [SAMPLE, " ", _jsx("strong", { style: { fontWeight: t.weights.strong }, children: "Strong words hold their weight" }), ", and ", _jsx("em", { children: "emphasis leans" }), " without shouting."] })] }), _jsxs("div", { children: [_jsx("div", { style: caps, children: "Mono" }), _jsx("pre", { style: { fontFamily: stack(t.mono), fontSize: size(t, 'small'), lineHeight: 1.6, color: c.ink, whiteSpace: 'pre-wrap', margin: '12px 0 0' }, children: `--text-body: ${size(t, 'body')}px;\n--text-h1: ${size(t, 'h1')}px;\n--leading-body: ${t.leading.body};` })] })] }), _jsx("div", { style: { height: 1, background: c.muted, opacity: 0.4, margin: '32px 0' } }), _jsx("div", { style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(120px, 1fr))', gap: 12 }, children: Object.keys(c).map((k) => (_jsxs("div", { children: [_jsx("div", { style: { height: 56, borderRadius: 10, background: c[k], border: `1px solid ${c.muted}55` } }), _jsx("div", { style: { ...caps, marginTop: 8 }, children: k }), _jsx("div", { style: { fontFamily: stack(t.mono), fontSize: size(t, 'caption'), color: c.ink }, children: c[k] }), k !== 'paper' ? _jsx("div", { style: { fontFamily: stack(t.mono), fontSize: size(t, 'caption'), color: c.muted }, children: `${contrast(c[k], c.paper).toFixed(1)}:1 on paper` }) : null] }, k))) })] })] }));
|
|
101
|
+
}
|
|
102
|
+
const esc = (s) => s.replace(/[&<>"]/g, (ch) => ({ '&': '&', '<': '<', '>': '>', '"': '"' })[ch]);
|
|
103
|
+
/** The specimen as a page of its own: the export. */
|
|
104
|
+
function page(t) {
|
|
105
|
+
const links = [...new Set([t.display, t.text, t.mono].map((f) => font(f).css).filter(Boolean))].map((h) => `<link rel="stylesheet" href="${esc(h)}">`).join('\n');
|
|
106
|
+
const rows = [...STEPS]
|
|
107
|
+
.reverse()
|
|
108
|
+
.map(([s]) => `<div class="row"><span class="caps">${s} ${size(t, s)}</span><span style="font: var(--weight-heading) ${size(t, s)}px/${t.leading.heading} var(--font-${['display', 'h1', 'h2', 'h3', 'h4'].includes(s) ? 'display' : 'text'})">The quick brown fox</span></div>`)
|
|
109
|
+
.join('\n');
|
|
110
|
+
return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
|
|
111
|
+
<title>${esc(t.name)}</title>${links}<style>${css(t)}
|
|
112
|
+
body{margin:0;padding:48px;background:var(--color-paper);color:var(--color-ink);font:var(--weight-body) var(--text-body)/var(--leading-body) var(--font-text)}
|
|
113
|
+
h1{font:var(--weight-display) var(--text-display)/var(--leading-display) var(--font-display);letter-spacing:var(--tracking-display);margin:16px 0}
|
|
114
|
+
.caps{font-size:var(--text-caption);letter-spacing:var(--tracking-caps);text-transform:uppercase;color:var(--color-muted);width:96px;flex-shrink:0}
|
|
115
|
+
.row{display:flex;gap:16px;align-items:baseline;white-space:nowrap;overflow:hidden}
|
|
116
|
+
</style></head><body><div class="caps">${esc(`${t.display} / ${t.text} / ${t.mono}`)}</div><h1>${esc(t.name)}</h1><p>${esc(t.blurb)}</p>${rows}<p>${esc(SAMPLE)}</p></body></html>`;
|
|
117
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
export interface Colors {
|
|
2
|
+
ink: string;
|
|
3
|
+
paper: string;
|
|
4
|
+
accent: string;
|
|
5
|
+
muted: string;
|
|
6
|
+
/** A second accent, for charts and tags. */
|
|
7
|
+
second: string;
|
|
8
|
+
}
|
|
9
|
+
export interface TypeSystem {
|
|
10
|
+
name: string;
|
|
11
|
+
blurb: string;
|
|
12
|
+
display: string;
|
|
13
|
+
text: string;
|
|
14
|
+
mono: string;
|
|
15
|
+
scale: {
|
|
16
|
+
base: number;
|
|
17
|
+
ratio: number;
|
|
18
|
+
};
|
|
19
|
+
weights: {
|
|
20
|
+
display: number;
|
|
21
|
+
heading: number;
|
|
22
|
+
body: number;
|
|
23
|
+
strong: number;
|
|
24
|
+
};
|
|
25
|
+
leading: {
|
|
26
|
+
display: number;
|
|
27
|
+
heading: number;
|
|
28
|
+
body: number;
|
|
29
|
+
};
|
|
30
|
+
/** Letter-spacing, em: display sizes and all-caps labels. */
|
|
31
|
+
tracking: {
|
|
32
|
+
display: number;
|
|
33
|
+
caps: number;
|
|
34
|
+
};
|
|
35
|
+
colors: Colors;
|
|
36
|
+
}
|
|
37
|
+
/** The named steps, smallest first, and the power of the ratio each is. */
|
|
38
|
+
export declare const STEPS: readonly [readonly ['caption', -2], readonly ['small', -1], readonly ['body', 0], readonly ['lead', 1], readonly ['h4', 2], readonly ['h3', 3], readonly ['h2', 4], readonly ['h1', 5], readonly ['display', 7]];
|
|
39
|
+
export type Step = (typeof STEPS)[number][0];
|
|
40
|
+
export declare function size(t: TypeSystem, step: Step): number;
|
|
41
|
+
/** The ratios a scale may take, by their musical names. */
|
|
42
|
+
export declare const RATIOS: readonly [readonly [1.125, 'Major second'], readonly [1.2, 'Minor third'], readonly [1.25, 'Major third'], readonly [1.333, 'Perfect fourth'], readonly [1.414, 'Augmented fourth'], readonly [1.5, 'Perfect fifth'], readonly [1.618, 'Golden']];
|
|
43
|
+
export declare const PRESETS: readonly TypeSystem[];
|
|
44
|
+
/** A type system as the model or a person wrote it, made safe to draw: unknown faces, bad colours and wild numbers fall back. */
|
|
45
|
+
export declare function settle(v: Partial<TypeSystem> & Record<string, unknown>, base?: TypeSystem): TypeSystem;
|
|
46
|
+
/** The JSON Schema a model fills to write one. */
|
|
47
|
+
export declare const SCHEMA: {
|
|
48
|
+
readonly type: 'object';
|
|
49
|
+
readonly additionalProperties: false;
|
|
50
|
+
readonly required: readonly ['name', 'blurb', 'display', 'text', 'mono', 'scale', 'weights', 'leading', 'tracking', 'colors'];
|
|
51
|
+
readonly properties: {
|
|
52
|
+
readonly name: {
|
|
53
|
+
readonly type: 'string';
|
|
54
|
+
};
|
|
55
|
+
readonly blurb: {
|
|
56
|
+
readonly type: 'string';
|
|
57
|
+
};
|
|
58
|
+
readonly display: {
|
|
59
|
+
readonly type: 'string';
|
|
60
|
+
readonly enum: readonly string[];
|
|
61
|
+
};
|
|
62
|
+
readonly text: {
|
|
63
|
+
readonly type: 'string';
|
|
64
|
+
readonly enum: readonly string[];
|
|
65
|
+
};
|
|
66
|
+
readonly mono: {
|
|
67
|
+
readonly type: 'string';
|
|
68
|
+
readonly enum: string[];
|
|
69
|
+
};
|
|
70
|
+
readonly scale: {
|
|
71
|
+
readonly type: 'object';
|
|
72
|
+
readonly additionalProperties: false;
|
|
73
|
+
readonly required: readonly ['base', 'ratio'];
|
|
74
|
+
readonly properties: {
|
|
75
|
+
readonly base: {
|
|
76
|
+
readonly type: 'number';
|
|
77
|
+
};
|
|
78
|
+
readonly ratio: {
|
|
79
|
+
readonly type: 'number';
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
readonly weights: {
|
|
84
|
+
readonly type: 'object';
|
|
85
|
+
readonly additionalProperties: false;
|
|
86
|
+
readonly required: readonly ['display', 'heading', 'body', 'strong'];
|
|
87
|
+
readonly properties: {
|
|
88
|
+
readonly display: {
|
|
89
|
+
readonly type: 'number';
|
|
90
|
+
};
|
|
91
|
+
readonly heading: {
|
|
92
|
+
readonly type: 'number';
|
|
93
|
+
};
|
|
94
|
+
readonly body: {
|
|
95
|
+
readonly type: 'number';
|
|
96
|
+
};
|
|
97
|
+
readonly strong: {
|
|
98
|
+
readonly type: 'number';
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
readonly leading: {
|
|
103
|
+
readonly type: 'object';
|
|
104
|
+
readonly additionalProperties: false;
|
|
105
|
+
readonly required: readonly ['display', 'heading', 'body'];
|
|
106
|
+
readonly properties: {
|
|
107
|
+
readonly display: {
|
|
108
|
+
readonly type: 'number';
|
|
109
|
+
};
|
|
110
|
+
readonly heading: {
|
|
111
|
+
readonly type: 'number';
|
|
112
|
+
};
|
|
113
|
+
readonly body: {
|
|
114
|
+
readonly type: 'number';
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
readonly tracking: {
|
|
119
|
+
readonly type: 'object';
|
|
120
|
+
readonly additionalProperties: false;
|
|
121
|
+
readonly required: readonly ['display', 'caps'];
|
|
122
|
+
readonly properties: {
|
|
123
|
+
readonly display: {
|
|
124
|
+
readonly type: 'number';
|
|
125
|
+
};
|
|
126
|
+
readonly caps: {
|
|
127
|
+
readonly type: 'number';
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
readonly colors: {
|
|
132
|
+
readonly type: 'object';
|
|
133
|
+
readonly additionalProperties: false;
|
|
134
|
+
readonly required: readonly ['ink', 'paper', 'accent', 'muted', 'second'];
|
|
135
|
+
readonly properties: {
|
|
136
|
+
readonly ink: {
|
|
137
|
+
readonly type: 'string';
|
|
138
|
+
};
|
|
139
|
+
readonly paper: {
|
|
140
|
+
readonly type: 'string';
|
|
141
|
+
};
|
|
142
|
+
readonly accent: {
|
|
143
|
+
readonly type: 'string';
|
|
144
|
+
};
|
|
145
|
+
readonly muted: {
|
|
146
|
+
readonly type: 'string';
|
|
147
|
+
};
|
|
148
|
+
readonly second: {
|
|
149
|
+
readonly type: 'string';
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
/** What a writer is told: the faces it may use, and the rules a pairing keeps. */
|
|
156
|
+
export declare const BRIEF: string;
|
|
157
|
+
/** WCAG relative luminance contrast of two #rrggbb colours. */
|
|
158
|
+
export declare function contrast(a: string, b: string): number;
|
|
159
|
+
/** CSS custom properties: the one export every web surface reads. */
|
|
160
|
+
export declare function css(t: TypeSystem): string;
|
|
161
|
+
/** Design tokens in the W3C Design Tokens format ($value / $type). */
|
|
162
|
+
export declare function tokens(t: TypeSystem): string;
|
|
163
|
+
/** A @hanzo/gui theme module: the faces as gui fonts, the colours as a theme. */
|
|
164
|
+
export declare function gui(t: TypeSystem): string;
|