@hanzo/studio 0.1.18 → 0.1.20

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/lib/home.js CHANGED
@@ -11,7 +11,7 @@ import { DropdownMenu } from '@hanzo/ui';
11
11
  import { useState } from 'react';
12
12
  import { useHost } from './host.js';
13
13
  import { kind } from './kinds/index.js';
14
- import { stack, use } from './kinds/type/fonts.js';
14
+ import { stack } from './kinds/type/fonts.js';
15
15
  import { PRESETS } from './kinds/type/system.js';
16
16
  import { useChats, useWire } from './live.js';
17
17
  import { path } from './route.js';
@@ -118,7 +118,6 @@ function Card({ s, i, onPress }) {
118
118
  const k = kind(s.kind);
119
119
  const Icon = k.icon;
120
120
  const look = PRESETS[i % PRESETS.length];
121
- use(look.display);
122
121
  return (_jsxs(YStack, { role: "listitem", shrink: 0, width: "calc(50% - 8px)", minW: 156, $md: { width: 'calc(33.333% - 11px)', minW: 0 }, $lg: { width: 'calc(25% - 12px)', minW: 0 }, gap: "$2", style: { scrollSnapAlign: 'start' }, children: [_jsxs(YStack, { position: "relative", width: "100%", rounded: 14, overflow: "hidden", borderWidth: 1, borderColor: "var(--border)", bg: "var(--surface-card)", style: { aspectRatio: '4 / 3' }, children: [s.thumb ? (_jsx("img", { src: s.thumb, alt: "", style: { position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover' } })) : (_jsxs("div", { "aria-hidden": true, style: { position: 'absolute', inset: 0, background: look.colors.paper, color: look.colors.ink, padding: '12% 10%', display: 'flex', flexDirection: 'column', justifyContent: 'flex-end', textAlign: 'left' }, children: [_jsx("div", { style: { width: '28%', height: 3, background: look.colors.accent, marginBottom: 8 } }), _jsx("div", { style: { fontFamily: stack(look.display), fontWeight: look.weights.display, fontSize: 'clamp(16px, 2vw, 24px)', lineHeight: look.leading.display, letterSpacing: `${look.tracking.display}em` }, children: s.title })] })), _jsxs(XStack, { "aria-hidden": true, position: "absolute", t: 8, l: 8, r: 8, justify: "space-between", items: "center", children: [_jsx(XStack, { width: 26, height: 26, rounded: 99, bg: "var(--surface-header)", borderWidth: 1, borderColor: "var(--border-strong)", boxShadow: "0 1px 4px rgba(0, 0, 0, 0.24)", items: "center", justify: "center", style: { border: '1px solid var(--border-strong)', color: 'var(--foreground)' }, "$platform-web": { color: 'var(--foreground)' }, children: _jsx(Icon, { size: 13 }) }), _jsx(XStack, { px: "$2", height: 22, rounded: 99, bg: "var(--surface-header)", borderWidth: 1, borderColor: "var(--border-strong)", boxShadow: "0 1px 4px rgba(0, 0, 0, 0.24)", style: { border: '1px solid var(--border-strong)' }, items: "center", children: _jsx(SizableText, { size: "$1", fontFamily: "$mono", fontWeight: "600", color: "$ink", children: RUNTIME[s.kind] }) })] }), _jsx(YStack, { render: _jsx("button", { type: "button" }), "aria-label": `${s.title}: ${s.subtitle}`, onClick: onPress, position: "absolute", t: 0, l: 0, r: 0, b: 0, rounded: 14, cursor: "pointer", hoverStyle: { bg: '$hover' }, focusVisibleStyle: RING_INSET })] }), _jsxs(YStack, { gap: 3, px: "$0.5", minW: 0, children: [_jsx(SizableText, { size: "$2", fontWeight: "600", color: "$ink", lineHeight: 19, numberOfLines: 1, children: s.title }), _jsx(SizableText, { size: "$1", color: "$soft", lineHeight: 16, numberOfLines: 1, children: s.subtitle })] })] }));
123
122
  }
124
123
  const STATE = { making: 'Making', done: 'Done', failed: 'Failed' };
@@ -8,7 +8,7 @@
8
8
  * it fits its box in at most its lines, measured in the face it is drawn in;
9
9
  * every other block wraps at its measure and stops at its line limit.
10
10
  */
11
- import { face, stack, use } from '../type/fonts.js';
11
+ import { face, stack } from '../type/fonts.js';
12
12
  const mm = (v) => (v * 72) / 25.4;
13
13
  export const FORMATS = [
14
14
  { id: 'a4', label: 'A4', width: 1240, height: 1754, points: [mm(210), mm(297)] },
@@ -102,8 +102,6 @@ function block(b, x, y, anchor = 'start') {
102
102
  const height = (b) => (b.lines.length ? b.px * (1 + (b.lines.length - 1) * b.leading) : 0);
103
103
  /** Load the faces a poster draws in, so measuring and drawing use them. */
104
104
  export async function ready(t) {
105
- use(t.display);
106
- use(t.text);
107
105
  await Promise.all([
108
106
  document.fonts.load(`${t.weights.display} 64px ${stack(t.display)}`),
109
107
  document.fonts.load(`${t.weights.body} 32px ${stack(t.text)}`),
@@ -4,9 +4,11 @@
4
4
  * in github.com/google/fonts on 2026-10-16 (`licence` is that file), so a
5
5
  * poster, a document or a deck drawn in any of them is free to ship.
6
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.
7
+ * Every face is the host's own bytes, never a third party's: the host loads Zen
8
+ * with `@hanzo/font/css` and the rest with `@hanzo/font/open.css`, and a page that
9
+ * draws a type system has them. A face is drawn into a picture (a poster's PNG,
10
+ * its PDF) by those bytes: `face()` finds the host's @font-face rules for it and
11
+ * hands them back with the woff2 as a data: URL an SVG can embed.
10
12
  */
11
13
  export type Role = 'sans' | 'serif' | 'display' | 'mono';
12
14
  export interface Font {
@@ -15,8 +17,8 @@ export interface Font {
15
17
  /** The weights it carries; a variable face carries the range. */
16
18
  weights: readonly number[];
17
19
  italic: boolean;
18
- /** The stylesheet that loads it; '' for Zen, which the host already loads. */
19
- css: string;
20
+ /** The stylesheet an exported page links to for it, public and its bytes beside it; '' for Zen, which an export names by family only. */
21
+ shared: string;
20
22
  licence: string;
21
23
  }
22
24
  export declare const FONTS: readonly Font[];
@@ -24,7 +26,5 @@ export declare const FAMILIES: readonly string[];
24
26
  export declare const font: (family: string) => Font;
25
27
  /** A CSS font-family value with a fallback of its own role. */
26
28
  export declare function stack(family: string): string;
27
- /** Load a face in this page, once. */
28
- export declare function use(family: string): void;
29
29
  /** The @font-face rules for a face with its bytes inline, for an SVG that is drawn to a picture. */
30
30
  export declare function face(family: string): Promise<string>;
@@ -4,33 +4,19 @@
4
4
  * in github.com/google/fonts on 2026-10-16 (`licence` is that file), so a
5
5
  * poster, a document or a deck drawn in any of them is free to ship.
6
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.
7
+ * Every face is the host's own bytes, never a third party's: the host loads Zen
8
+ * with `@hanzo/font/css` and the rest with `@hanzo/font/open.css`, and a page that
9
+ * draws a type system has them. A face is drawn into a picture (a poster's PNG,
10
+ * its PDF) by those bytes: `face()` finds the host's @font-face rules for it and
11
+ * hands them back with the woff2 as a data: URL an SVG can embed.
10
12
  */
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
+ import { OPEN } from '@hanzo/font/open';
14
+ const ZEN = 'https://www.npmjs.com/package/@hanzo/font (LICENSE.txt, SIL OFL 1.1)';
15
+ const ALL = [100, 200, 300, 400, 500, 600, 700, 800, 900];
13
16
  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') },
17
+ { family: 'Zen', role: 'sans', weights: ALL, italic: true, shared: '', licence: ZEN },
18
+ { family: 'Zen Mono', role: 'mono', weights: ALL, italic: false, shared: '', licence: ZEN },
19
+ ...OPEN.map((o) => ({ ...o, shared: `https://cdn.jsdelivr.net/npm/@hanzo/font/dist/open/${o.slug}.css` })),
34
20
  ];
35
21
  export const FAMILIES = FONTS.map((f) => f.family);
36
22
  export const font = (family) => FONTS.find((f) => f.family === family) ?? FONTS[0];
@@ -40,18 +26,6 @@ export function stack(family) {
40
26
  const fall = f.role === 'serif' ? 'Georgia, serif' : f.role === 'mono' ? 'ui-monospace, monospace' : 'system-ui, sans-serif';
41
27
  return `"${f.family}", ${fall}`;
42
28
  }
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
29
  const embedded = new Map();
56
30
  /** The @font-face rules for a face with its bytes inline, for an SVG that is drawn to a picture. */
57
31
  export function face(family) {
@@ -59,28 +33,15 @@ export function face(family) {
59
33
  let hit = embedded.get(f.family);
60
34
  if (!hit) {
61
35
  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');
36
+ return host(f.family);
76
37
  })();
77
38
  embedded.set(f.family, hit);
78
39
  hit.catch(() => embedded.delete(f.family));
79
40
  }
80
41
  return hit;
81
42
  }
82
- /** Zen's faces as this page loaded them (@hanzo/font/css), found in its stylesheets. */
83
- async function zen(family) {
43
+ /** A face as this page loaded it (@hanzo/font/css, @hanzo/font/open.css), found in its stylesheets. */
44
+ async function host(family) {
84
45
  const rules = [];
85
46
  for (const sheet of Array.from(document.styleSheets)) {
86
47
  let list;
@@ -1,5 +1,2 @@
1
1
  import { type Kind } from '../kind.ts';
2
- import { type TypeSystem } from './system.ts';
3
2
  export declare const type: Kind;
4
- /** The faces a system names, loaded into this page. */
5
- export declare function useFaces(t: TypeSystem | null): void;
@@ -7,12 +7,11 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
7
7
  */
8
8
  import { SizableText, XStack, YStack } from '@hanzo/gui';
9
9
  import { Type } from '@hanzogui/lucide-icons-2';
10
- import { useEffect } from 'react';
11
10
  import { filename } from '../../made.js';
12
11
  import { structured } from '../../wire.js';
13
12
  import { Choice, Color, Row } from '../../ui.js';
14
13
  import { str } from '../kind.js';
15
- import { FAMILIES, font, stack, use } from './fonts.js';
14
+ import { FAMILIES, font, stack } from './fonts.js';
16
15
  import { BRIEF, contrast, css, gui, PRESETS, RATIOS, SCHEMA, settle, size, STEPS, tokens } from './system.js';
17
16
  const preset = (name) => PRESETS.find((p) => p.name.toLowerCase() === name.toLowerCase()) ?? null;
18
17
  const of = (spec) => settle(spec);
@@ -64,20 +63,9 @@ export const type = {
64
63
  { 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
64
  ],
66
65
  };
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
66
  const SAMPLE = 'Every surface reads in one voice: the same faces, the same steps, the same colours, wherever it is drawn.';
78
67
  function Specimen({ version, edit, busy }) {
79
68
  const t = of(version.spec);
80
- useFaces(t);
81
69
  const c = t.colors;
82
70
  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
71
  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: {
@@ -102,7 +90,7 @@ function Specimen({ version, edit, busy }) {
102
90
  const esc = (s) => s.replace(/[&<>"]/g, (ch) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' })[ch]);
103
91
  /** The specimen as a page of its own: the export. */
104
92
  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');
93
+ const links = [...new Set([t.display, t.text, t.mono].map((f) => font(f).shared).filter(Boolean))].map((h) => `<link rel="stylesheet" href="${esc(h)}">`).join('\n');
106
94
  const rows = [...STEPS]
107
95
  .reverse()
108
96
  .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>`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanzo/studio",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "type": "module",
5
5
  "license": "BSD-3-Clause",
6
6
  "description": "Hanzo Studio: a chat that makes images, posters, documents, slides, type systems, 3D, video and sound, with every result open in a tab beside it. Mounted by the Hanzo app at hanzo.ai/studio and served whole at studio.hanzo.ai.",
@@ -15,7 +15,7 @@
15
15
  "@axe-core/playwright": "4.14.0",
16
16
  "@hanzo/build": "0.2.85",
17
17
  "@hanzo/composer": "0.2.0",
18
- "@hanzo/font": "1.9.3",
18
+ "@hanzo/font": "1.11.0",
19
19
  "@hanzo/gui": "8.3.5",
20
20
  "@hanzo/i18n": "0.5.3",
21
21
  "@hanzo/ui": "8.29.24",