@logomarks/lookbook 0.0.0-stage → 0.1.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.
@@ -0,0 +1,269 @@
1
+ /**
2
+ * @module @logomarks/lookbook/looks/studio
3
+ *
4
+ * The Lookbook's studio set (2026-11-12; the owner: "a few new ones … that are modern and look good"): frost, spectral,
5
+ * editorial, brandsheet and overprint. Quiet, current brand design: soft colour behind glass, a grainy spectrum in the
6
+ * mark, big type with a small mark, a brand sheet, a two-ink print. Same rules as ./index.js (pure HTML
7
+ * strings from the card's seeded random, per-card values as custom properties in `style`, ids under the card's uid,
8
+ * motion in CSS only and only while `is-live`, the still styles the final frame); each look's styles are a block at the
9
+ * end of wall-looks.css.
10
+ *
11
+ * - The two that move (frost, spectral) move by `transform` alone, on layers drawn once: the compositor does the work,
12
+ * so neither is heavy.
13
+ * - editorial and brandsheet are flat boxes, hairlines, the mark and words, so they also download as plain SVG.
14
+ */
15
+
16
+ import { escapeHtml } from '@arraypress/text';
17
+ import { art, around, def, markUrl, meta, mk, nameB, pad2, pickOf, use } from './kit.js';
18
+
19
+ /** The mark's one copy, in an empty `<svg>`, for the looks whose mark isn't in a drawn artwork. */
20
+ const defs = (c) => `<svg class="wx-def" aria-hidden="true"><defs>${def(c)}</defs></svg>`;
21
+ /** A small copy of the mark (a box that grows with the optical size, like a lockup's). */
22
+ const small = (c, cls) =>
23
+ `<svg class="${cls}" viewBox="0 0 512 512" fill="currentColor" aria-hidden="true"><use href="#${c.uid}-m" /></svg>`;
24
+ /** The made-up brand's web address. */
25
+ const host = (c) => `www.${c.name.toLowerCase().replace(/[^a-z0-9]/g, '')}${c.tld}`;
26
+
27
+ /** Instrument Sans 700's advance widths, in hundredths of an em (measured), for `sansEms`. */
28
+ const SANS = {
29
+ A: 74,
30
+ B: 65,
31
+ C: 75,
32
+ D: 76,
33
+ E: 63,
34
+ F: 59,
35
+ G: 76,
36
+ H: 72,
37
+ I: 25,
38
+ J: 41,
39
+ K: 72,
40
+ L: 59,
41
+ M: 89,
42
+ N: 72,
43
+ O: 80,
44
+ P: 67,
45
+ Q: 82,
46
+ R: 67,
47
+ S: 65,
48
+ T: 67,
49
+ U: 70,
50
+ V: 74,
51
+ W: 109,
52
+ X: 72,
53
+ Y: 71,
54
+ Z: 64,
55
+ a: 57,
56
+ b: 63,
57
+ c: 56,
58
+ d: 63,
59
+ e: 57,
60
+ f: 38,
61
+ g: 63,
62
+ h: 62,
63
+ i: 27,
64
+ j: 27,
65
+ k: 57,
66
+ l: 27,
67
+ m: 95,
68
+ n: 62,
69
+ o: 60,
70
+ p: 63,
71
+ q: 63,
72
+ r: 40,
73
+ s: 50,
74
+ t: 42,
75
+ u: 61,
76
+ v: 54,
77
+ w: 82,
78
+ x: 61,
79
+ y: 54,
80
+ z: 52,
81
+ ' ': 19,
82
+ '&': 77,
83
+ '-': 49,
84
+ '.': 29,
85
+ };
86
+
87
+ /**
88
+ * A name's width in ems, set in Instrument Sans 700 tracked −0.05 em (the editorial's name is sized to its measure
89
+ * from this). The Lookbook's script calls it again for a name typed in the toolbar (`data-fit="sans"`).
90
+ *
91
+ * @param name The name.
92
+ */
93
+ export function sansEms(name) {
94
+ let w = 0;
95
+ for (const ch of name) w += (SANS[ch] ?? 62) / 100 - 0.05;
96
+ return Math.max(2.2, +w.toFixed(2));
97
+ }
98
+
99
+ /* ---------- frost: the mark on a pane of frosted glass, soft colour drifting behind it ---------- */
100
+
101
+ /** Frost's grounds: the base, three soft lights behind the glass, and the ink. */
102
+ const frosts = (accent) => [
103
+ ['#141021', '#ff5e8a', '#7a5cff', '#ffb347', '#ffffff'],
104
+ ['#0b1520', '#3ad6c5', '#3b6cff', '#b7ff5a', '#ffffff'],
105
+ ['#190f13', '#ff7a45', '#ff3d81', '#ffd166', '#ffffff'],
106
+ ['#0d1324', '#5cc8ff', '#8a6bff', '#ff8fd0', '#ffffff'],
107
+ ['#0e150f', accent, '#0f8b8d', '#3ad66f', '#ffffff'],
108
+ ['#e8e5f0', '#ff9db8', '#9db4ff', '#ffd58a', '#15131c'],
109
+ ];
110
+
111
+ /** frost: three soft lights drift slowly behind a pane of frosted glass (a pale tint, a bright rim, fine grain), the
112
+ * mark on the pane in one ink, the name under it. The lights are plain radial fades moved by `transform`. */
113
+ function frost(c) {
114
+ const pick = pickOf(c);
115
+ const [bg, a, b, d, fg] = pick(frosts(c.accent));
116
+ const orbs = [a, b, d].map((col, k) => `<i class="is-k${k}" style="--c:${col}"></i>`).join('');
117
+ return {
118
+ style: `;--bg:${bg};--fg:${fg}`,
119
+ attrs: '',
120
+ inner:
121
+ `<span class="wx-frorbs" aria-hidden="true">${orbs}</span>` +
122
+ `<span class="wx-frpane">${art(around(64), `<defs>${def(c)}</defs>${mk(use(c, 'wx-frmark'))}`)}</span>` +
123
+ meta('tl', escapeHtml(c.line)) +
124
+ meta('tr', `Glass · ${pad2(1 + Math.floor(c.r() * 24))}`) +
125
+ `<span class="wx-foot is-centre">${nameB(c)}</span>`,
126
+ };
127
+ }
128
+
129
+ /* ---------- spectral: a grainy spectrum inside the mark ---------- */
130
+
131
+ /** Spectral's gradients, each ending where it starts (it tiles, so it can slide for ever). */
132
+ const spectra = (accent) => [
133
+ '#ff4d6d, #ff9e4a, #ffe66d, #6ee7b7, #5cc8ff, #8a6bff, #ff4d6d',
134
+ '#ff2e88, #ff7a45, #ffd23f, #ff7a45, #ff2e88',
135
+ '#22d3ee, #3b6cff, #8a6bff, #ff8fd0, #22d3ee',
136
+ `${accent}, #3ad6c5, #0f8b8d, #3ad6c5, ${accent}`,
137
+ '#f4f3ef, #9db4ff, #ff9db8, #ffd58a, #f4f3ef',
138
+ ];
139
+
140
+ /** spectral: the mark filled with a spectrum that slides slowly through it under film grain, on near-black or paper;
141
+ * nothing else on the card but its name and two small words. The mark is a mask (the glass look's `markUrl`); the
142
+ * spectrum is one wide strip moved by `transform`. */
143
+ function spectral(c) {
144
+ const pick = pickOf(c);
145
+ const light = c.r() < 0.25;
146
+ const all = spectra(c.accent);
147
+ const stops = pick(light ? all.slice(0, 4) : all);
148
+ return {
149
+ style: `;--bg:${light ? '#efede7' : '#0b0b0d'};--fg:${light ? '#131313' : '#f1f1f4'};--m:${markUrl(c.paths, '#fff')};--sp:linear-gradient(90deg, ${stops});--so:${Math.round(c.r() * 100)}`,
150
+ attrs: '',
151
+ inner:
152
+ defs(c) +
153
+ `<span class="wx-spfill" data-ink="#fff" aria-hidden="true"><i class="wx-spgrad"></i><i class="wx-spgrain"></i></span>` +
154
+ meta('tl', escapeHtml(c.line)) +
155
+ meta('tr', `No. ${pad2(1 + Math.floor(c.r() * 40))}`) +
156
+ `<span class="wx-foot">${nameB(c)}</span>`,
157
+ };
158
+ }
159
+
160
+ /* ---------- editorial: big type, a small mark ---------- */
161
+
162
+ /** Editorial's grounds: ground, ink, and the mark's colour. */
163
+ const editorials = (accent) => [
164
+ ['#f1efe9', '#111111', '#ff4d1f'],
165
+ ['#f1efe9', '#111111', '#2b4bff'],
166
+ ['#0c0c0d', '#f1efe9', accent],
167
+ ['#0c0c0d', '#f1efe9', '#f1efe9'],
168
+ ['#2b4bff', '#ffffff', '#ffffff'],
169
+ [accent, '#0b0b0b', '#0b0b0b'],
170
+ ['#ff4d1f', '#0b0b0b', '#0b0b0b'],
171
+ ];
172
+
173
+ /** editorial: a magazine cover: the mark small in the top corner beside an issue number, a hairline, the tagline in a
174
+ * light weight, and the name huge and tight in a bold grotesque the full measure (sized from its width, `sansEms`), a
175
+ * hairline and two small words at the foot. Flat colour, hairlines and words only. */
176
+ function editorial(c) {
177
+ const pick = pickOf(c);
178
+ const [bg, fg, ink] = pick(editorials(c.accent));
179
+ return {
180
+ style: `;--bg:${bg};--fg:${fg};--ink:${ink}`,
181
+ attrs: '',
182
+ inner:
183
+ defs(c) +
184
+ `<span class="wx-edtop">${small(c, 'wx-edmark')}<span class="wx-edmeta"><i>Issue ${pad2(1 + Math.floor(c.r() * 24))}</i><i>2026</i></span></span>` +
185
+ `<span class="wx-edlead"><i>${escapeHtml(c.tagline)}</i></span>` +
186
+ `<span class="wx-edname"><b class="wc-name" data-fit="sans" style="--chars:${sansEms(c.name)}">${escapeHtml(c.name)}</b></span>` +
187
+ `<span class="wx-edfoot"><i>${escapeHtml(c.line)}</i><i>${escapeHtml(host(c))}</i></span>`,
188
+ };
189
+ }
190
+
191
+ /* ---------- brandsheet: one page of a brand's guidelines ---------- */
192
+
193
+ /** A typeface's name from the card's `type` style (`font-family:'Sora Variable', sans-serif;…` → Sora). */
194
+ const faceName = (type) => (type.match(/font-family:\s*'([^']+)'/)?.[1] ?? 'Grotesk').replace(/ Variable$/, '');
195
+
196
+ /** brandsheet: a page from a brand's guidelines on a hairline grid: the name and a version in the header, the mark big
197
+ * in its own cell, then three cells: its minimum sizes, its colours as chips with the accent's hex, and its typeface
198
+ * ("Aa" in the card's face, named). Flat boxes, hairlines and words only. */
199
+ function brandsheet(c) {
200
+ const pick = pickOf(c);
201
+ const dark = c.r() < 0.35;
202
+ // an accent that reads on the sheet's ground
203
+ const accents = dark
204
+ ? [c.accent, '#5CECFF', '#FF5C64', '#FFD43B', '#FF3EA5']
205
+ : ['#2E4BFF', '#FF5C64', '#0E8C7E', '#FF6A00', '#7B3FF2', '#1E6B3A'];
206
+ const ink = pick(accents);
207
+ const [bg, fg] = dark ? ['#0e0e0f', '#f1efe9'] : ['#f4f3ef', '#0b0b0b'];
208
+ const sizes = [3, 2, 1].map((k) => small(c, `wx-bssz is-s${k}`)).join('');
209
+ const chips = `<em class="is-ink"></em><em class="is-fg"></em><em class="is-bg"></em>`;
210
+ return {
211
+ style: `;--bg:${bg};--fg:${fg};--ink:${ink}`,
212
+ attrs: '',
213
+ inner:
214
+ `<span class="wx-bshead">${nameB(c, '', false)}<i>Brand sheet · v1.${Math.floor(c.r() * 9)}</i></span>` +
215
+ `<span class="wx-bsmain">${art(around(70), `<defs>${def(c)}</defs>${mk(use(c, 'wx-bsmark'))}`)}</span>` +
216
+ `<span class="wx-bsrow">` +
217
+ `<span class="wx-bscell"><i>Minimum size</i><span class="wx-bssizes">${sizes}</span></span>` +
218
+ `<span class="wx-bscell"><i>Colour</i><span class="wx-bschips">${chips}</span><i class="wx-bshex">${ink.toUpperCase()}</i></span>` +
219
+ `<span class="wx-bscell"><i>Type</i><span class="wx-bsaa" style="${c.type}">Aa</span><i>${escapeHtml(faceName(c.type))}</i></span>` +
220
+ `</span>` +
221
+ `<span class="wx-bsfoot"><i>${escapeHtml(c.line)}</i><i>${escapeHtml(host(c))}</i></span>`,
222
+ };
223
+ }
224
+
225
+ /* ---------- overprint: two spot inks, a little off register ---------- */
226
+
227
+ /** Overprint's ink pairs (the first under, the second over it), bright spot colours that make a third where they cross. */
228
+ const SPOTS = [
229
+ ['#ff48b0', '#0078bf'],
230
+ ['#ff6c2f', '#00838a'],
231
+ ['#ffe800', '#ff48b0'],
232
+ ['#f15060', '#3255a4'],
233
+ ['#ffe800', '#0078bf'],
234
+ ];
235
+
236
+ /** overprint: the mark printed twice on uncoated paper in two spot inks: the first solid, the second through a 45°
237
+ * halftone screen and off register, multiplied over the first so a third colour shows in the dots where they cross;
238
+ * paper grain, two registration marks, the inks as swatches. A print-room proof, where the riso look is a photo. */
239
+ function overprint(c) {
240
+ const pick = pickOf(c);
241
+ const [a, b] = pick(SPOTS);
242
+ const paper = pick(['#f3efe4', '#f1ece2', '#eef0ea']);
243
+ // the second pass's slip: 14–22 units, down and to the right or left
244
+ const dx = (c.r() < 0.5 ? -1 : 1) * Math.round(14 + c.r() * 8),
245
+ dy = Math.round(12 + c.r() * 8);
246
+ // the second ink's screen: round dots on a 45° grid, as a mask
247
+ const screen =
248
+ `<pattern id="${c.uid}-hd" width="11" height="11" patternUnits="userSpaceOnUse" patternTransform="rotate(45)"><circle cx="5.5" cy="5.5" r="3.3" fill="#fff" /></pattern>` +
249
+ `<mask id="${c.uid}-hm" maskUnits="userSpaceOnUse" x="-100" y="-100" width="712" height="712"><rect x="-100" y="-100" width="712" height="712" fill="url(#${c.uid}-hd)" /></mask>`;
250
+ const reg = (pos) =>
251
+ `<svg class="wx-opreg is-${pos}" viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="6.5" /><path d="M12 0V24M0 12H24" /></svg>`;
252
+ return {
253
+ style: `;--bg:${paper};--fg:#1c1b19;--a:${a};--b:${b};--dx:${dx}px;--dy:${dy}px`,
254
+ attrs: '',
255
+ inner:
256
+ art(
257
+ around(100),
258
+ `<defs>${def(c)}${screen}</defs>${mk(`${use(c, 'wx-opa')}<g class="wx-opb" mask="url(#${c.uid}-hm)">${use(c, '')}</g>`)}`,
259
+ ) +
260
+ reg('l') +
261
+ reg('r') +
262
+ meta('tl', `Proof ${pad2(1 + Math.floor(c.r() * 12))} · 2 inks`) +
263
+ `<span class="wx-opinks" aria-hidden="true"><i class="is-a"></i><i class="is-b"></i></span>` +
264
+ `<span class="wx-foot">${nameB(c)}<i>${escapeHtml(c.line)}</i></span>`,
265
+ };
266
+ }
267
+
268
+ /** The set's looks, by kind. */
269
+ export const STUDIO = { frost, spectral, editorial, brandsheet, overprint };
package/src/marks.d.ts ADDED
@@ -0,0 +1,106 @@
1
+ /**
2
+ * @module @logomarks/lookbook/marks
3
+ *
4
+ * What the Lookbook's looks need to know about a mark's shape: its real box, its optical size (how much bigger a wide,
5
+ * slim or light mark is drawn), and the mark as square cells (the pixel and LED looks). Thin wiring over
6
+ * `@logomarks/core` (its SVG reader, ring sampler and pixelate grid); browser-safe,
7
+ * so the wall's script can make the same cards as the page.
8
+ *
9
+ * Bound for `@logomarks/core` (2026-11-15; the library imports them from there once core has them): `markBox`,
10
+ * `inkShare`, `opticalScale` and `OPTICAL` to `/analyse` (measures of a mark, like its widths and shape tags), and
11
+ * `cellsAcross` and `markCells` to `/edit` beside `pixelGrid` (a grid by cell count, where `pixelGrid` takes an amount
12
+ * and stops at 14 across; and shapes → rings → coverage → cells in one call). `opticalVars`, `opticalStyle` and
13
+ * `heatField` stay here: the first two are the cards' CSS, the third is the thermal look's own filter.
14
+ */
15
+ import { type PixelGrid } from '@logomarks/core/edit';
16
+ /** A box on the 512 canvas. */
17
+ export type Box = {
18
+ x: number;
19
+ y: number;
20
+ w: number;
21
+ h: number;
22
+ };
23
+ /** A mark as square cells: the grid, which cells are filled (row by row), and the filled cells as one path. */
24
+ export type MarkCells = {
25
+ grid: PixelGrid;
26
+ on: Uint8Array;
27
+ d: string;
28
+ };
29
+ /** The real box round a mark's outlines (its paths' markup), on the 512 canvas; the 448 fit's box when it can't be read. */
30
+ export declare function markBox(paths: string): Box;
31
+ /** The optical size's limits: the most a mark grows, and how much its box and its ink count. */
32
+ export declare const OPTICAL: {
33
+ /** The most a mark grows (× its 448 fit). */
34
+ readonly max: 1.3;
35
+ /** The box's term: (448² / its area) to this power, so a square is 1, 448 × 200 about 1.22. */
36
+ readonly power: 0.25;
37
+ /** The ink's term: up to this much more for a light mark … */
38
+ readonly light: 0.1;
39
+ /** … in full at or below this share of its box inked, none at or above `solid`. */
40
+ readonly thin: 0.2;
41
+ readonly solid: 0.45;
42
+ };
43
+ /**
44
+ * How much of a mark's own box is ink, 0–1 (core's scanline coverage on a grid 16 cells across its longest side).
45
+ *
46
+ * @param paths The mark's paths' markup.
47
+ */
48
+ export declare function inkShare(paths: string): number;
49
+ /**
50
+ * The mark's optical size: how much bigger to draw it so it holds as much of the eye as a square, solid mark at the 448
51
+ * fit. Every mark is fitted to 448 on its longest side, so a wide, short one (448 × 200) or a slim one (266 × 448)
52
+ * carries far less area, and a light, line-drawn one less weight. 1 for a square solid; 448 × 200 about 1.22; never
53
+ * below 1, never above `OPTICAL.max`. Each look caps it again for the room round its words (wall.css, `--mk-scale`).
54
+ *
55
+ * @param box The mark's box (`markBox`).
56
+ * @param ink The share of its box inked (`inkShare`); 1 leaves the ink out of it.
57
+ */
58
+ export declare function opticalScale(box: Pick<Box, 'w' | 'h'>, ink?: number): number;
59
+ /**
60
+ * A card's optical size as CSS custom properties for its `style`: `--mk-k` (the scale), `--mk-w` and `--mk-h` (the box,
61
+ * on the 512 canvas), from which wall.css works out `--mk-scale` within each look's room.
62
+ *
63
+ * @param paths The mark's paths' markup.
64
+ */
65
+ export declare function opticalVars(paths: string): Record<'--mk-k' | '--mk-w' | '--mk-h', string>;
66
+ /** `opticalVars` as a `style` fragment (`;--mk-k:…`). */
67
+ export declare const opticalStyle: (paths: string) => string;
68
+ /**
69
+ * A pixel grid of `n` cells across a box's longest side, centred on it (core's `pixelGrid`, sized by count).
70
+ *
71
+ * @param n Cells across the longest side.
72
+ * @param box The mark's box.
73
+ */
74
+ export declare function cellsAcross(n: number, box: Box): PixelGrid;
75
+ /**
76
+ * The mark as square cells, `n` across its longest side, measured by core's scanline coverage (half a cell covered, or
77
+ * a fifth where a cell would otherwise break a thin line).
78
+ *
79
+ * @param paths The mark's paths' markup.
80
+ * @param n Cells across.
81
+ */
82
+ export declare function markCells(paths: string, n: number): MarkCells;
83
+ /** A mark's heat: what the thermal look's infrared filter shows (./looks/index.js), worked out on a grid so the seeker
84
+ * knows where the mark is hottest. */
85
+ export type HeatField = {
86
+ /** The grid (8 units a cell, round the 512 canvas with a 40-unit margin). */
87
+ grid: PixelGrid;
88
+ /** Heat per cell, row by row: 0 to about 1.1 (the filter shows it clipped at 1; the seeker reads it whole, so it
89
+ * finds the middle of a solid mark's white). */
90
+ heat: Float32Array;
91
+ /** Ink coverage 0–1 per cell, row by row. */
92
+ ink: Float32Array;
93
+ /** The hottest cell's centre, on the 512 canvas, and its heat. */
94
+ peak: {
95
+ x: number;
96
+ y: number;
97
+ v: number;
98
+ };
99
+ };
100
+ /**
101
+ * The mark's heat as the thermal look draws it: its coverage blurred at two radii (8 and 30 units) and mixed 0.6 : 0.5,
102
+ * like the look's SVG filter, on an 8-unit grid; and the hottest point.
103
+ *
104
+ * @param paths The mark's paths' markup.
105
+ */
106
+ export declare function heatField(paths: string): HeatField;
package/src/marks.js ADDED
@@ -0,0 +1,178 @@
1
+ /**
2
+ * @module @logomarks/lookbook/marks
3
+ *
4
+ * What the Lookbook's looks need to know about a mark's shape: its real box, its optical size (how much bigger a wide,
5
+ * slim or light mark is drawn), and the mark as square cells (the pixel and LED looks). Thin wiring over
6
+ * `@logomarks/core` (its SVG reader, ring sampler and pixelate grid); browser-safe,
7
+ * so the wall's script can make the same cards as the page.
8
+ *
9
+ * Bound for `@logomarks/core` (2026-11-15; the library imports them from there once core has them): `markBox`,
10
+ * `inkShare`, `opticalScale` and `OPTICAL` to `/analyse` (measures of a mark, like its widths and shape tags), and
11
+ * `cellsAcross` and `markCells` to `/edit` beside `pixelGrid` (a grid by cell count, where `pixelGrid` takes an amount
12
+ * and stops at 14 across; and shapes → rings → coverage → cells in one call). `opticalVars`, `opticalStyle` and
13
+ * `heatField` stay here: the first two are the cards' CSS, the third is the thermal look's own filter.
14
+ */
15
+
16
+ import { shapes, rings, bounds } from '@logomarks/core/svg';
17
+ import { pixelCoverage, pixelCells, pixelPath } from '@logomarks/core/edit';
18
+
19
+ /** The real box round a mark's outlines (its paths' markup), on the 512 canvas; the 448 fit's box when it can't be read. */
20
+ export function markBox(paths) {
21
+ const list = shapes(paths);
22
+ if (!list.length) return { x: 32, y: 32, w: 448, h: 448 };
23
+ const b = bounds(list);
24
+ return Number.isFinite(b.w) && b.w > 0 ? b : { x: 32, y: 32, w: 448, h: 448 };
25
+ }
26
+
27
+ /** The optical size's limits: the most a mark grows, and how much its box and its ink count. */
28
+ export const OPTICAL = {
29
+ /** The most a mark grows (× its 448 fit). */
30
+ max: 1.3,
31
+ /** The box's term: (448² / its area) to this power, so a square is 1, 448 × 200 about 1.22. */
32
+ power: 0.25,
33
+ /** The ink's term: up to this much more for a light mark … */
34
+ light: 0.1,
35
+ /** … in full at or below this share of its box inked, none at or above `solid`. */
36
+ thin: 0.2,
37
+ solid: 0.45,
38
+ };
39
+
40
+ /**
41
+ * How much of a mark's own box is ink, 0–1 (core's scanline coverage on a grid 16 cells across its longest side).
42
+ *
43
+ * @param paths The mark's paths' markup.
44
+ */
45
+ export function inkShare(paths) {
46
+ const list = shapes(paths);
47
+ if (!list.length) return 1;
48
+ const grid = cellsAcross(16, markBox(paths));
49
+ const cov = pixelCoverage(
50
+ list.map((s) => ({ rings: rings(s.segs, 3), evenodd: s.evenodd })),
51
+ grid,
52
+ );
53
+ let sum = 0;
54
+ for (const v of cov) sum += v;
55
+ return cov.length ? sum / cov.length : 1;
56
+ }
57
+
58
+ /**
59
+ * The mark's optical size: how much bigger to draw it so it holds as much of the eye as a square, solid mark at the 448
60
+ * fit. Every mark is fitted to 448 on its longest side, so a wide, short one (448 × 200) or a slim one (266 × 448)
61
+ * carries far less area, and a light, line-drawn one less weight. 1 for a square solid; 448 × 200 about 1.22; never
62
+ * below 1, never above `OPTICAL.max`. Each look caps it again for the room round its words (wall.css, `--mk-scale`).
63
+ *
64
+ * @param box The mark's box (`markBox`).
65
+ * @param ink The share of its box inked (`inkShare`); 1 leaves the ink out of it.
66
+ */
67
+ export function opticalScale(box, ink = 1) {
68
+ const { max, power, light, thin, solid } = OPTICAL;
69
+ const area = (448 * 448) / Math.max(1, box.w * box.h);
70
+ const weight = 1 + light * Math.min(1, Math.max(0, (solid - ink) / (solid - thin)));
71
+ return Math.min(max, Math.max(1, area ** power * weight));
72
+ }
73
+
74
+ /**
75
+ * A card's optical size as CSS custom properties for its `style`: `--mk-k` (the scale), `--mk-w` and `--mk-h` (the box,
76
+ * on the 512 canvas), from which wall.css works out `--mk-scale` within each look's room.
77
+ *
78
+ * @param paths The mark's paths' markup.
79
+ */
80
+ export function opticalVars(paths) {
81
+ const box = markBox(paths);
82
+ return {
83
+ '--mk-k': opticalScale(box, inkShare(paths)).toFixed(3),
84
+ '--mk-w': String(Math.round(box.w)),
85
+ '--mk-h': String(Math.round(box.h)),
86
+ };
87
+ }
88
+
89
+ /** `opticalVars` as a `style` fragment (`;--mk-k:…`). */
90
+ export const opticalStyle = (paths) =>
91
+ Object.entries(opticalVars(paths))
92
+ .map(([k, v]) => `;${k}:${v}`)
93
+ .join('');
94
+
95
+ /**
96
+ * A pixel grid of `n` cells across a box's longest side, centred on it (core's `pixelGrid`, sized by count).
97
+ *
98
+ * @param n Cells across the longest side.
99
+ * @param box The mark's box.
100
+ */
101
+ export function cellsAcross(n, box) {
102
+ const cell = Math.max(box.w, box.h) / n;
103
+ const cols = Math.max(1, Math.round(box.w / cell)),
104
+ rows = Math.max(1, Math.round(box.h / cell));
105
+ return { cols, rows, cell, x0: box.x + box.w / 2 - (cols * cell) / 2, y0: box.y + box.h / 2 - (rows * cell) / 2 };
106
+ }
107
+
108
+ /**
109
+ * The mark as square cells, `n` across its longest side, measured by core's scanline coverage (half a cell covered, or
110
+ * a fifth where a cell would otherwise break a thin line).
111
+ *
112
+ * @param paths The mark's paths' markup.
113
+ * @param n Cells across.
114
+ */
115
+ export function markCells(paths, n) {
116
+ const list = shapes(paths);
117
+ const grid = cellsAcross(n, markBox(paths));
118
+ const cov = pixelCoverage(
119
+ list.map((s) => ({ rings: rings(s.segs), evenodd: s.evenodd })),
120
+ grid,
121
+ );
122
+ return { grid, on: pixelCells(cov, grid), d: pixelPath(cov, grid) ?? '' };
123
+ }
124
+
125
+ /** A separable Gaussian blur of a grid, `sigma` in cells. */
126
+ function blur(src, cols, rows, sigma) {
127
+ const rad = Math.ceil(sigma * 3);
128
+ const k = Array.from({ length: 2 * rad + 1 }, (_, i) => Math.exp(-((i - rad) ** 2) / (2 * sigma * sigma)));
129
+ const sum = k.reduce((s, v) => s + v, 0);
130
+ const tmp = new Float32Array(src.length),
131
+ out = new Float32Array(src.length);
132
+ for (let j = 0; j < rows; j++)
133
+ for (let i = 0; i < cols; i++) {
134
+ let v = 0;
135
+ for (let t = -rad; t <= rad; t++) {
136
+ const x = i + t;
137
+ if (x >= 0 && x < cols) v += src[j * cols + x] * k[t + rad];
138
+ }
139
+ tmp[j * cols + i] = v / sum;
140
+ }
141
+ for (let j = 0; j < rows; j++)
142
+ for (let i = 0; i < cols; i++) {
143
+ let v = 0;
144
+ for (let t = -rad; t <= rad; t++) {
145
+ const y = j + t;
146
+ if (y >= 0 && y < rows) v += tmp[y * cols + i] * k[t + rad];
147
+ }
148
+ out[j * cols + i] = v / sum;
149
+ }
150
+ return out;
151
+ }
152
+
153
+ /**
154
+ * The mark's heat as the thermal look draws it: its coverage blurred at two radii (8 and 30 units) and mixed 0.6 : 0.5,
155
+ * like the look's SVG filter, on an 8-unit grid; and the hottest point.
156
+ *
157
+ * @param paths The mark's paths' markup.
158
+ */
159
+ export function heatField(paths) {
160
+ const list = shapes(paths);
161
+ const grid = { cols: 74, rows: 74, cell: 8, x0: -40, y0: -40 };
162
+ const ink = list.length
163
+ ? pixelCoverage(
164
+ list.map((s) => ({ rings: rings(s.segs), evenodd: s.evenodd })),
165
+ grid,
166
+ )
167
+ : new Float32Array(grid.cols * grid.rows);
168
+ const a = blur(ink, grid.cols, grid.rows, 1),
169
+ b = blur(ink, grid.cols, grid.rows, 3.75);
170
+ const heat = new Float32Array(ink.length);
171
+ let best = 0;
172
+ for (let i = 0; i < heat.length; i++) {
173
+ heat[i] = 0.6 * a[i] + 0.5 * b[i];
174
+ if (heat[i] > heat[best]) best = i;
175
+ }
176
+ const at = (i) => ({ x: grid.x0 + ((i % grid.cols) + 0.5) * grid.cell, y: grid.y0 + (Math.floor(i / grid.cols) + 0.5) * grid.cell });
177
+ return { grid, heat, ink, peak: { ...at(best), v: heat[best] || 1 } };
178
+ }
package/src/promo.d.ts ADDED
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @module @logomarks/lookbook/promo
3
+ *
4
+ * The cards between the marks (`feed`'s `promo`): a headline card that glitches now and then, a sponsor's card, and an
5
+ * open sponsor slot, each with smoke behind its words (`data-smoke`, started by `liveCards`). The words and links are
6
+ * the site's; the markup and its styles (wall.css) are these.
7
+ */
8
+ import type { Card } from './wall.js';
9
+ /**
10
+ * A headline card (4:5): a small tag, a headline whose two tinted copies slice and shift for a moment now and then
11
+ * (while live), and a line to act on.
12
+ *
13
+ * @param k Its place among the promo cards (1, 2 …): its glitch's moment.
14
+ * @param o `href`; `tag` (text); `head`, the headline (HTML, the site's own: an `<em>` for its second half); `cta` (text).
15
+ */
16
+ export declare function headlineCard(
17
+ k: number,
18
+ o: {
19
+ href: string;
20
+ tag: string;
21
+ head: string;
22
+ cta: string;
23
+ },
24
+ ): Card;
25
+ /**
26
+ * A sponsor's card (1:1): its logo, name and tagline over smoke; it opens the sponsor's site in a new tab.
27
+ *
28
+ * @param o `href`, the sponsor's address; `tag` (text); `logo`, an image address; `name` and `tagline` (text).
29
+ */
30
+ export declare function sponsorCard(o: { href: string; tag: string; logo: string; name: string; tagline: string }): Card;
31
+ /**
32
+ * An open sponsor slot (1:1): an empty logo with light scanning across it, a title, a line, and a line to book it that
33
+ * rises on hover.
34
+ *
35
+ * @param o `href`, where it's booked; `tag`, `title`, `line` and `go` (text).
36
+ */
37
+ export declare function openSlotCard(o: { href: string; tag: string; title: string; line: string; go: string }): Card;
package/src/promo.js ADDED
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @module @logomarks/lookbook/promo
3
+ *
4
+ * The cards between the marks (`feed`'s `promo`): a headline card that glitches now and then, a sponsor's card, and an
5
+ * open sponsor slot, each with smoke behind its words (`data-smoke`, started by `liveCards`). The words and links are
6
+ * the site's; the markup and its styles (wall.css) are these.
7
+ */
8
+
9
+ import { escapeHtml } from '@arraypress/text';
10
+
11
+ /**
12
+ * A headline card (4:5): a small tag, a headline whose two tinted copies slice and shift for a moment now and then
13
+ * (while live), and a line to act on.
14
+ *
15
+ * @param k Its place among the promo cards (1, 2 …): its glitch's moment.
16
+ * @param o `href`; `tag` (text); `head`, the headline (HTML, the site's own: an `<em>` for its second half); `cta` (text).
17
+ */
18
+ export function headlineCard(k, o) {
19
+ return {
20
+ html: `<a class="wc wc-promo wc-custom" href="${escapeHtml(o.href)}" data-anim style="aspect-ratio:4 / 5;--glitch-delay:${-((k * 1.7) % 5).toFixed(2)}s"><span class="wc-promo-tag">${escapeHtml(o.tag)}</span><span class="wc-glitch"><b>${o.head}</b><b class="wc-glitch-a" aria-hidden="true">${o.head}</b><b class="wc-glitch-b" aria-hidden="true">${o.head}</b></span><span class="wc-promo-cta">${escapeHtml(o.cta)}</span></a>`,
21
+ h: 5 / 4,
22
+ };
23
+ }
24
+
25
+ /**
26
+ * A sponsor's card (1:1): its logo, name and tagline over smoke; it opens the sponsor's site in a new tab.
27
+ *
28
+ * @param o `href`, the sponsor's address; `tag` (text); `logo`, an image address; `name` and `tagline` (text).
29
+ */
30
+ export function sponsorCard(o) {
31
+ return {
32
+ html: `<a class="wc wc-promo wc-sponsor" href="${escapeHtml(o.href)}" rel="sponsored noopener" target="_blank" data-smoke style="aspect-ratio:1 / 1"><canvas class="wc-smoke" aria-hidden="true"></canvas><span class="wc-promo-tag">${escapeHtml(o.tag)}</span><img class="wc-sponsor-logo" src="${escapeHtml(o.logo)}" alt="" loading="lazy" /><b>${escapeHtml(o.name)}</b><span>${escapeHtml(o.tagline)}</span></a>`,
33
+ h: 1,
34
+ };
35
+ }
36
+
37
+ /**
38
+ * An open sponsor slot (1:1): an empty logo with light scanning across it, a title, a line, and a line to book it that
39
+ * rises on hover.
40
+ *
41
+ * @param o `href`, where it's booked; `tag`, `title`, `line` and `go` (text).
42
+ */
43
+ export function openSlotCard(o) {
44
+ return {
45
+ html: `<a class="wc wc-promo wc-sponsor is-open" href="${escapeHtml(o.href)}" data-smoke style="aspect-ratio:1 / 1"><canvas class="wc-smoke" aria-hidden="true"></canvas><span class="wc-promo-tag">${escapeHtml(o.tag)}</span><span class="wc-sponsor-logo" aria-hidden="true"></span><b>${escapeHtml(o.title)}</b><span>${escapeHtml(o.line)}</span><span class="wc-sponsor-go">${escapeHtml(o.go)}</span></a>`,
46
+ h: 1,
47
+ };
48
+ }