@spunto/brand-kit 0.14.0 → 0.15.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/package.json +1 -1
- package/src/home/code.tsx +94 -0
- package/src/home/home.tsx +10 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spunto/brand-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "Spunto's brand kit — the centre of the brand: the product family and its paints (the colours the design system renders), the voice, the sourced figures, the home editions, the illustrations and the templates (social cards, video scenes, stories) everything we say about Spunto is made from.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { ReactNode } from "react"
|
|
2
|
+
import { hexAlpha, type Surface } from "../theme"
|
|
3
|
+
|
|
4
|
+
/* A command or a snippet of an edition, coloured. Every block of code in a home sits on a dark ground (the
|
|
5
|
+
ink, or black over the field), so the colours are the product's own seen at night: the signal for what the
|
|
6
|
+
language says (keywords, a shell's command, flags), its opposite on the colour wheel, kept light, for what
|
|
7
|
+
the code says (strings), white for names (calls, components, tags), the text dimmed for comments. No grammar per
|
|
8
|
+
language and no dependency: one small tokenizer reads well enough the TypeScript/TSX, shell, YAML and CSS
|
|
9
|
+
the editions show — they are short, and they are real. */
|
|
10
|
+
|
|
11
|
+
type Kind = "keyword" | "string" | "comment" | "name" | "number" | "flag" | "punct"
|
|
12
|
+
|
|
13
|
+
const KEYWORDS = new Set(
|
|
14
|
+
"import export from default const let var function return async await new if else for of in as type interface extends class this null undefined true false typeof void throw try catch".split(" "),
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
// Order matters: comments and strings first, so a `//` in a URL or a `#` in a string stays where it is.
|
|
18
|
+
const TOKEN =
|
|
19
|
+
/((?<=^|\s)(?:\/\/|#)[^\n]*)|('(?:[^'\\\n]|\\.)*'|"(?:[^"\\\n]|\\.)*"|`(?:[^`\\]|\\.)*`)|(<\/?[A-Za-z][\w.]*|\/?>)|((?<=^|\s)--?[A-Za-z][\w-]*)|(\b\d[\d_.]*\b)|(@?[A-Za-z_$][\w$-]*)/gm
|
|
20
|
+
|
|
21
|
+
/** The tokens of a snippet, each with its kind — what `Code` colours. Exported for the tests. */
|
|
22
|
+
export function tokenize(code: string, shell: boolean): { text: string; kind?: Kind }[] {
|
|
23
|
+
const out: { text: string; kind?: Kind }[] = []
|
|
24
|
+
let last = 0
|
|
25
|
+
// The first word of each shell line is the command (`npm`, `curl`, `sbx`).
|
|
26
|
+
let lineStart = true
|
|
27
|
+
for (const m of code.matchAll(TOKEN)) {
|
|
28
|
+
const i = m.index!
|
|
29
|
+
const before = code.slice(last, i)
|
|
30
|
+
if (before) out.push({ text: before })
|
|
31
|
+
// A new line starts a command, unless the last one went on (`\`); so does a pipe or a `&&`.
|
|
32
|
+
if ((before.includes("\n") && !/\\\s*\n/.test(before)) || /\||&&|;/.test(before)) lineStart = true
|
|
33
|
+
const [text, comment, string, tag, flag, number, word] = m
|
|
34
|
+
let kind: Kind | undefined
|
|
35
|
+
if (comment) kind = "comment"
|
|
36
|
+
else if (string) kind = "string"
|
|
37
|
+
else if (tag) kind = "punct"
|
|
38
|
+
else if (flag) kind = "flag"
|
|
39
|
+
else if (number) kind = "number"
|
|
40
|
+
else if (word) {
|
|
41
|
+
const next = code.slice(i + text.length).match(/^\s*(\(|:(?=\s|$))/)
|
|
42
|
+
if (shell && lineStart) kind = "keyword"
|
|
43
|
+
else if (KEYWORDS.has(word)) kind = "keyword"
|
|
44
|
+
else if (/^[A-Z]/.test(word) || next?.[1] === "(") kind = "name"
|
|
45
|
+
// A key: `runs-on:` in YAML, `{ title: … }` in an object.
|
|
46
|
+
else if (next?.[1] === ":") kind = "name"
|
|
47
|
+
}
|
|
48
|
+
// A tag's name is a name, its brackets are punctuation.
|
|
49
|
+
if (tag && /[A-Za-z]/.test(tag)) {
|
|
50
|
+
const name = tag.match(/[A-Za-z][\w.]*/)![0]
|
|
51
|
+
out.push({ text: tag.slice(0, tag.length - name.length), kind: "punct" }, { text: name, kind: "name" })
|
|
52
|
+
} else out.push({ text, kind })
|
|
53
|
+
if (!comment && text.trim()) lineStart = false
|
|
54
|
+
last = i + text.length
|
|
55
|
+
}
|
|
56
|
+
if (last < code.length) out.push({ text: code.slice(last) })
|
|
57
|
+
return out
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** The signal's opposite on the colour wheel, kept light: a second colour every product has, in its own key. */
|
|
61
|
+
function opposite(hex: string) {
|
|
62
|
+
const n = parseInt(hex.slice(1), 16)
|
|
63
|
+
const [r, g, b] = [(n >> 16) & 255, (n >> 8) & 255, n & 255].map((v) => v / 255)
|
|
64
|
+
const max = Math.max(r, g, b)
|
|
65
|
+
const min = Math.min(r, g, b)
|
|
66
|
+
const d = max - min
|
|
67
|
+
const h = d === 0 ? 0 : max === r ? ((g - b) / d + 6) % 6 : max === g ? (b - r) / d + 2 : (r - g) / d + 4
|
|
68
|
+
return `hsl(${Math.round(h * 60 + 180) % 360} 70% 76%)`
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** A step's command has no prompt flag: a line without code's punctuation is a shell's (`sbx pause hello`). */
|
|
72
|
+
export const looksLikeShell = (code: string) => !/[(){};=]/.test(code)
|
|
73
|
+
|
|
74
|
+
/** `code` coloured on a dark ground, in the surface's product colours. `shell` reads its first words as commands. */
|
|
75
|
+
export function Code({ code, s, shell = false }: { code: string; s: Surface; shell?: boolean }): ReactNode {
|
|
76
|
+
const colour: Record<Kind, string> = {
|
|
77
|
+
keyword: s.signal,
|
|
78
|
+
flag: s.signal,
|
|
79
|
+
number: s.signal,
|
|
80
|
+
string: opposite(s.signal),
|
|
81
|
+
name: "#ffffff",
|
|
82
|
+
comment: hexAlpha("#e9efeb", 0.45),
|
|
83
|
+
punct: hexAlpha("#e9efeb", 0.6),
|
|
84
|
+
}
|
|
85
|
+
return tokenize(code, shell).map((t, i) =>
|
|
86
|
+
t.kind ? (
|
|
87
|
+
<span key={i} style={{ color: colour[t.kind], fontStyle: t.kind === "comment" ? "italic" : undefined }}>
|
|
88
|
+
{t.text}
|
|
89
|
+
</span>
|
|
90
|
+
) : (
|
|
91
|
+
t.text
|
|
92
|
+
),
|
|
93
|
+
)
|
|
94
|
+
}
|
package/src/home/home.tsx
CHANGED
|
@@ -6,6 +6,7 @@ import { Illustration } from "../illustrations"
|
|
|
6
6
|
import { Module3DView } from "../three/view"
|
|
7
7
|
import type { Module3DRef } from "../three/catalog"
|
|
8
8
|
import { ShowcaseScreen } from "./showcase/view"
|
|
9
|
+
import { Code, looksLikeShell } from "./code"
|
|
9
10
|
import { BRAND_NEUTRALS, BRAND_PRODUCTS, brandProduct, plain, productHref, type BrandLocale } from "../products"
|
|
10
11
|
import { FONT, hexAlpha, surface, type Surface } from "../theme"
|
|
11
12
|
import { MARKS, MARK_COLORS } from "../marks"
|
|
@@ -261,7 +262,7 @@ function SectionView({ section, ctx, path: p }: { section: HomeSection; ctx: Ctx
|
|
|
261
262
|
}}
|
|
262
263
|
>
|
|
263
264
|
{section.prompt !== false && <span style={{ color: section.theme === "paper" ? s.signal : s.accent }}>$ </span>}
|
|
264
|
-
{section.command}
|
|
265
|
+
<Code code={section.command} s={s} shell={section.prompt !== false} />
|
|
265
266
|
</pre>
|
|
266
267
|
{section.caption && <div style={{ marginTop: 10, fontFamily: FONT.mono, fontSize: 12, color: s.muted }}>{ctx.t(section.caption, `${p}.caption`)}</div>}
|
|
267
268
|
</div>
|
|
@@ -344,7 +345,7 @@ function SectionView({ section, ctx, path: p }: { section: HomeSection; ctx: Ctx
|
|
|
344
345
|
<p style={{ margin: 0, fontSize: 16, lineHeight: 1.55, color: s.muted }}>{ctx.t(it.text, `${p}.items.${i}.text`)}</p>
|
|
345
346
|
{it.command && (
|
|
346
347
|
<pre style={{ margin: 0, padding: "12px 14px", borderRadius: 4, background: section.theme === "night" ? "rgba(0,0,0,0.32)" : BRAND_NEUTRALS.ink, color: "#e9efeb", fontFamily: FONT.mono, fontSize: 12.5, lineHeight: 1.6, whiteSpace: "pre-wrap", wordBreak: "break-word" }}>
|
|
347
|
-
{it.command}
|
|
348
|
+
<Code code={it.command} s={s} shell={looksLikeShell(it.command)} />
|
|
348
349
|
</pre>
|
|
349
350
|
)}
|
|
350
351
|
</li>
|
|
@@ -613,7 +614,7 @@ function WaysSection({ section, s, ctx, path: p }: { section: Extract<HomeSectio
|
|
|
613
614
|
{it.code && (
|
|
614
615
|
<pre style={{ margin: 0, color: "#e9efeb", fontFamily: FONT.mono, fontSize: 12, lineHeight: 1.65, whiteSpace: "pre-wrap", wordBreak: "break-word" }}>
|
|
615
616
|
<span style={{ color: s.signal }}>$ </span>
|
|
616
|
-
{ctx.r(it.code, `${ip}.code`)}
|
|
617
|
+
{ctx.editing ? ctx.r(it.code, `${ip}.code`) : <Code code={it.code} s={s} shell />}
|
|
617
618
|
</pre>
|
|
618
619
|
)}
|
|
619
620
|
{it.marks && it.marks.length > 0 && (
|
|
@@ -1208,7 +1209,9 @@ function HeroSection({ section, s, ctx, path: p }: { section: Extract<HomeSectio
|
|
|
1208
1209
|
)
|
|
1209
1210
|
)
|
|
1210
1211
|
return (
|
|
1211
|
-
|
|
1212
|
+
// A hero is seen whole, on a laptop too: its height also follows the screen's (`svh`) — a wide, short window
|
|
1213
|
+
// takes less air above and a smaller title, rather than pushing the buttons under the fold.
|
|
1214
|
+
<section id={section.id} style={{ position: "relative", overflow: "hidden", background: s.bg, color: s.fg, padding: "clamp(56px, min(13cqi, 11svh), 168px) clamp(20px, 5cqi, 64px) clamp(48px, min(10cqi, 8svh), 128px)" }}>
|
|
1212
1215
|
{behind && <Scene3D ctx={ctx} scene={section.scene!} theme={section.theme} fill style={{ position: "absolute", inset: 0, height: "100%" }} />}
|
|
1213
1216
|
{section.theme !== "paper" && !behind && (
|
|
1214
1217
|
<Illustration
|
|
@@ -1219,14 +1222,14 @@ function HeroSection({ section, s, ctx, path: p }: { section: Extract<HomeSectio
|
|
|
1219
1222
|
/>
|
|
1220
1223
|
)}
|
|
1221
1224
|
<div style={{ ...WRAP, pointerEvents: behind ? "none" : undefined, display: "grid", gridTemplateColumns: split ? "repeat(auto-fit, minmax(320px, 1fr))" : "1fr", gap: "clamp(32px, 5cqi, 64px)", alignItems: "center" }}>
|
|
1222
|
-
<div style={{ display: "flex", flexDirection: "column", gap:
|
|
1225
|
+
<div style={{ display: "flex", flexDirection: "column", gap: "clamp(14px, 2.4svh, 22px)", alignItems: centered ? "center" : "flex-start", textAlign: centered ? "center" : "left", pointerEvents: "auto" }}>
|
|
1223
1226
|
{section.kicker && <span style={{ fontFamily: FONT.mono, fontSize: 13, letterSpacing: "0.14em", textTransform: "uppercase", color: section.theme === "signal" ? s.fg : s.accent }}>{ctx.t(section.kicker, `${p}.kicker`)}</span>}
|
|
1224
1227
|
<h1
|
|
1225
1228
|
style={{
|
|
1226
1229
|
margin: 0,
|
|
1227
1230
|
fontFamily: FONT.display,
|
|
1228
1231
|
fontWeight: 400,
|
|
1229
|
-
fontSize: section.layout === "band" ? "clamp(46px, 9cqi, 112px)" : "clamp(
|
|
1232
|
+
fontSize: section.layout === "band" ? "clamp(46px, 9cqi, 112px)" : "clamp(40px, min(7cqi, 8.5svh), 92px)",
|
|
1230
1233
|
lineHeight: 0.98,
|
|
1231
1234
|
letterSpacing: "-0.025em",
|
|
1232
1235
|
maxWidth: centered ? "16ch" : "14ch",
|
|
@@ -1256,7 +1259,7 @@ function HeroSection({ section, s, ctx, path: p }: { section: Extract<HomeSectio
|
|
|
1256
1259
|
}}
|
|
1257
1260
|
>
|
|
1258
1261
|
<span style={{ color: section.theme === "paper" ? s.signal : s.accent, userSelect: "none" }}>$ </span>
|
|
1259
|
-
{section.command}
|
|
1262
|
+
<Code code={section.command} s={s} shell />
|
|
1260
1263
|
</pre>
|
|
1261
1264
|
)}
|
|
1262
1265
|
{section.actions && <Actions actions={section.actions} s={s} theme={section.theme} ctx={ctx} path={`${p}.actions`} center={centered} />}
|