@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.
package/src/wall.d.ts ADDED
@@ -0,0 +1,135 @@
1
+ /**
2
+ * @module @logomarks/lookbook
3
+ *
4
+ * The Lookbook's cards: one mark, already a brand — a made-up name in a typeface, on a photo, glass, a colour or paper,
5
+ * or the mark itself redrawn (`./looks/index.js`). Pure functions returning HTML, so a page built on the server and its
6
+ * script in the browser make identical cards. The brand names, the typefaces and the accent come in as options
7
+ * (`lookbook()`); the styles are `@logomarks/lookbook/wall.css` and `@logomarks/lookbook/wall-looks.css`.
8
+ */
9
+ import { type LookKind } from './looks/index.js';
10
+ /** The one accent: acid lime. Every lime the looks print is this, unless `lookbook({ accent })` says otherwise. */
11
+ export declare const ACCENT = '#C8FF00';
12
+ /** A mark as the wall needs it: its outline (its paths' markup on the 512 canvas), what the brand picker reads (subject,
13
+ * mood, style, letter, industries), and its shape tags (round, radial …), which say which looks suit it. */
14
+ export type WallMark = {
15
+ slug: string;
16
+ name: string;
17
+ paths: string;
18
+ tags?: readonly string[];
19
+ subject?: readonly string[];
20
+ mood?: readonly string[];
21
+ style?: string;
22
+ letter?: string;
23
+ industries?: readonly string[];
24
+ };
25
+ /** The pictures the cards are laid on: `photos` (by file name: `club-N` the club hall, `club-dancer-N`, `club-crowd-N`
26
+ * its people, portraits and the rest; see the README) and `glass` (abstracts and flowers: `bloom-N`, `dahlia-N` …). */
27
+ export type WallAssets = {
28
+ photos: string[];
29
+ glass: string[];
30
+ };
31
+ /** The looks: the older ones here (a mark laid on a photo, glass, a colour or paper), and the drawn ones
32
+ * (`./looks/index.js`: the mark itself traced, lit, contoured, pixelated …). */
33
+ export type Kind =
34
+ | 'photo'
35
+ | 'poster'
36
+ | 'mono'
37
+ | 'duo'
38
+ | 'jitter'
39
+ | 'riso'
40
+ | 'crt'
41
+ | 'pattern'
42
+ | 'crop'
43
+ | 'colour'
44
+ | 'tone'
45
+ | 'glass'
46
+ | 'paper'
47
+ | 'gradient'
48
+ | 'shader'
49
+ | LookKind;
50
+ /** A card's made-up brand: its name, its line ("Coffee Co."), a tagline and a web address ending, from one sector. */
51
+ export type Brand = {
52
+ name: string;
53
+ line: string;
54
+ tagline: string;
55
+ tld: string;
56
+ };
57
+ /** Picks a mark's brand: `seed` changes with the deal; `avoid` holds the names and lines the cards just before used. */
58
+ export type BrandPicker = (
59
+ mark: WallMark,
60
+ seed: number,
61
+ avoid: {
62
+ names: readonly string[];
63
+ lines: readonly string[];
64
+ },
65
+ ) => Brand;
66
+ /** A typeface for the names: family (as CSS), weight, tracking, case. The page loads each. */
67
+ export type Face = readonly [family: string, weight: number, tracking: string, textCase: string];
68
+ /** A card: its HTML and its height over its width. */
69
+ export type Card = {
70
+ html: string;
71
+ h: number;
72
+ };
73
+ /** What the cards just before this one used, so a card can avoid repeating them (see `feed`). */
74
+ export type Recent = {
75
+ kinds: Kind[];
76
+ names: string[];
77
+ lines: string[];
78
+ photos: string[];
79
+ };
80
+ /** The options a wall is made with. */
81
+ export type LookbookOptions = {
82
+ /** The made-up brand on each card (a site's own picker). */
83
+ brand: BrandPicker;
84
+ /** The typefaces the names are set in, one picked a card. */
85
+ faces: readonly Face[];
86
+ /** The accent (acid lime, `ACCENT`, by default). */
87
+ accent?: string;
88
+ /** Where a card links: `#slug` by default. */
89
+ href?: (mark: WallMark) => string;
90
+ /** Pictures in `assets.photos` that are never a card's ground (a site's other photos kept in the same folder). */
91
+ skip?: RegExp;
92
+ };
93
+ /** A wall: its cards, its feed, and the pictures a card's ground can step through. */
94
+ export type Lookbook = {
95
+ card: (
96
+ m: WallMark,
97
+ deal: number,
98
+ assets: WallAssets,
99
+ recent?: Recent,
100
+ only?: Kind,
101
+ among?: ReadonlySet<Kind>,
102
+ ) => Card & {
103
+ brand: Brand;
104
+ used: Recent;
105
+ };
106
+ feed: (
107
+ all: WallMark[],
108
+ order: number[],
109
+ from: number,
110
+ to: number,
111
+ deal: number,
112
+ assets: WallAssets,
113
+ promo?: (k: number) => Card,
114
+ among?: ReadonlySet<Kind>,
115
+ ) => Card[];
116
+ backgrounds: (assets: WallAssets, src: string) => string[];
117
+ };
118
+ /** How often each look is dealt (relative). The older looks keep the shares they had as a list (photo and gradient 3 in
119
+ * 23, tone, shader, mono and duo 2 …); the drawn looks' weights are `LOOK_WEIGHTS`, about 8 in 31 together. */
120
+ export declare const WEIGHTS: Record<Kind, number>;
121
+ /** A promo card every this many marks (`feed`). */
122
+ export declare const EVERY = 30;
123
+ /**
124
+ * A wall: `card`, `feed` and `backgrounds`, with the brand picker, the typefaces and the accent given here.
125
+ *
126
+ * @param options The brand picker, the faces, and optionally the accent, the links and the photos to skip.
127
+ */
128
+ export declare function lookbook(options: LookbookOptions): Lookbook;
129
+ /**
130
+ * A shuffled copy (seeded: the same seed, the same order).
131
+ *
132
+ * @param xs The items.
133
+ * @param seed The seed.
134
+ */
135
+ export declare function shuffled<T>(xs: T[], seed: number): T[];
package/src/wall.js ADDED
@@ -0,0 +1,441 @@
1
+ /**
2
+ * @module @logomarks/lookbook
3
+ *
4
+ * The Lookbook's cards: one mark, already a brand — a made-up name in a typeface, on a photo, glass, a colour or paper,
5
+ * or the mark itself redrawn (`./looks/index.js`). Pure functions returning HTML, so a page built on the server and its
6
+ * script in the browser make identical cards. The brand names, the typefaces and the accent come in as options
7
+ * (`lookbook()`); the styles are `@logomarks/lookbook/wall.css` and `@logomarks/lookbook/wall-looks.css`.
8
+ */
9
+
10
+ import { liveGradient } from '@arraypress/effects-astro/runtime/live-gradient';
11
+ import { escapeHtml } from '@arraypress/text';
12
+ // the share cards' mesh palettes and seeded random (@arraypress/og-image draws with the same); browser-safe
13
+ import { PALETTES as OG_MESHES, hash, rng } from '@arraypress/og-image/palette';
14
+ import { look, isLook, ACID, LOOK_RATIO, LOOK_WEIGHTS } from './looks/index.js';
15
+ import { opticalStyle } from './marks.js';
16
+ import { BLOOM_KINDS, bloomFits } from './looks/bloom.js';
17
+ import { CLUB_KINDS, CLUB_PHOTOS, clubFits } from './looks/club.js';
18
+
19
+ /** The one accent: acid lime. Every lime the looks print is this, unless `lookbook({ accent })` says otherwise. */
20
+ export const ACCENT = '#C8FF00';
21
+
22
+ /** Ground and ink for the colour cards (the accent first). */
23
+ const palettesOf = (accent) => [
24
+ [accent, '#0B0B0B'],
25
+ ['#2E4BFF', '#FFFFFF'],
26
+ ['#FF5C64', '#FFFFFF'],
27
+ ['#0E8C7E', '#FFFFFF'],
28
+ ['#FF6A00', '#0B0B0B'],
29
+ ['#7B3FF2', '#FFFFFF'],
30
+ ['#F4F3EF', '#0B0B0B'],
31
+ ['#FF3EA5', '#0B0B0B'],
32
+ ['#123B7A', '#FFFFFF'],
33
+ ['#FFD43B', '#0B0B0B'],
34
+ ['#1E6B3A', '#FFFFFF'],
35
+ ['#5CECFF', '#0B0B0B'],
36
+ ];
37
+ /** The inks a mono card's lockup can take, each strong on a greyscale photo: electric blue, crimson, the accent, ember, hot
38
+ * pink, violet, cyan, warm yellow. */
39
+ const inksOf = (accent) => ['#2b4bff', '#d0213c', accent, '#ff5a1f', '#ff2e88', '#8a6bff', '#22d3ee', '#ffd23f'];
40
+ /** Riso cards' two inks: the ink the shadows print in, and the paper the highlights show. */
41
+ const RISO = [
42
+ ['#1d3fd8', '#ffe3d6'],
43
+ ['#d81b3f', '#fff3cc'],
44
+ ['#0b7a57', '#f3e8ff'],
45
+ ['#f2541b', '#e8f3ff'],
46
+ ['#4b2bd8', '#e9ffb0'],
47
+ ['#111111', '#ff8fbd'],
48
+ ];
49
+ /** CRT cards' phosphors: green, amber, cyan. */
50
+ const PHOSPHOR = ['#39ff88', '#ffb000', '#5ce1ff'];
51
+ /** The washes a duo card's photo can take: violet, ultramarine, red, ember, emerald, and the acid set's lime and teal. */
52
+ const WASHES = ['#5b4bff', '#2b2be8', '#d62b35', '#e8773a', '#1fae6f', ACID.lime, ACID.teal];
53
+ /** The gradient and shader cards' meshes: the share cards' palettes, and the acid set (lime and teal over near-black). */
54
+ const MESHES = [
55
+ ...OG_MESHES,
56
+ { colors: [ACID.lime, ACID.teal, '#14402f'], base: ACID.black, ink: '#ffffff' },
57
+ // 2026-11-12: fourteen more, so a wall of gradients (the Gradients look set) doesn't repeat itself: deep grounds with
58
+ // two saturated blooms and a quiet third, and three pale ones
59
+ { colors: ['#FF4D2E', '#FF9E1F', '#5B1230'], base: '#120508', ink: '#FFFFFF' }, // ember
60
+ { colors: ['#3D7BFF', '#00D4C8', '#0A2A6B'], base: '#050A1C', ink: '#FFFFFF' }, // deep sea
61
+ { colors: ['#C84BFF', '#FF4FA3', '#2A0F5C'], base: '#0D0518', ink: '#FFFFFF' }, // ultraviolet
62
+ { colors: ['#19E68C', '#0E6BFF', '#062B3A'], base: '#03110F', ink: '#FFFFFF' }, // aurora
63
+ { colors: ['#FFB199', '#FF6F91', '#5E3A8C'], base: '#1A0E1F', ink: '#FFFFFF' }, // dusk
64
+ { colors: ['#F2E9DC', '#B8A38A', '#3B352E'], base: '#141210', ink: '#FFFFFF' }, // sandstone
65
+ { colors: ['#9BA8FF', '#5D5FEF', '#1B1464'], base: '#080720', ink: '#FFFFFF' }, // indigo
66
+ { colors: ['#FFE14D', '#FF7A1A', '#7A1E00'], base: '#150A02', ink: '#FFFFFF' }, // solar
67
+ { colors: ['#7CF5FF', '#B79CFF', '#123A5C'], base: '#06101C', ink: '#FFFFFF' }, // ice
68
+ { colors: ['#E8E8EC', '#7A7F8C', '#2A2D36'], base: '#0C0D10', ink: '#FFFFFF' }, // graphite
69
+ { colors: ['#FF5E5E', '#8B1E3F', '#2B0B1E'], base: '#10040A', ink: '#FFFFFF' }, // garnet
70
+ { colors: ['#FFD9E8', '#C9B8FF', '#A8E6FF'], base: '#FBF6FF', ink: '#0B0B0B' }, // pearl
71
+ { colors: ['#DFFFB0', '#9FF0D0', '#FFF3B0'], base: '#F8FBEF', ink: '#0B0B0B' }, // spring
72
+ { colors: ['#FFD2B8', '#FFB3A1', '#FFE9C7'], base: '#FFF7F0', ink: '#0B0B0B' }, // apricot
73
+ ];
74
+ /** A mesh's key among the recent backgrounds (see `Recent.photos`), so neighbouring gradient cards differ. */
75
+ const meshKey = (m) => `mesh:${m.colors[0]}${m.colors[1]}`;
76
+ /** Tone cards: a deep ground and an accent. */
77
+ const tonesOf = (accent) => [
78
+ ['#0F1A2E', '#5CECFF'],
79
+ ['#1A0F24', '#DC5CFF'],
80
+ ['#0E1A12', '#8DFF5C'],
81
+ ['#24100E', '#FF6A3D'],
82
+ ['#101010', accent],
83
+ ['#14122A', '#7C8CFF'],
84
+ ];
85
+ const RATIO = {
86
+ photo: '4 / 5',
87
+ poster: '3 / 4',
88
+ mono: '4 / 5',
89
+ duo: '4 / 5',
90
+ jitter: '4 / 5',
91
+ riso: '4 / 5',
92
+ crt: '1 / 1',
93
+ pattern: '4 / 5',
94
+ crop: '1 / 1',
95
+ colour: '1 / 1',
96
+ tone: '5 / 4',
97
+ glass: '1 / 1',
98
+ paper: '4 / 5',
99
+ gradient: '4 / 5',
100
+ shader: '4 / 5',
101
+ ...LOOK_RATIO,
102
+ };
103
+ /** How often each look is dealt (relative). The older looks keep the shares they had as a list (photo and gradient 3 in
104
+ * 23, tone, shader, mono and duo 2 …); the drawn looks' weights are `LOOK_WEIGHTS`, about 8 in 31 together. */
105
+ export const WEIGHTS = {
106
+ photo: 3,
107
+ gradient: 3,
108
+ tone: 2,
109
+ shader: 2,
110
+ mono: 2,
111
+ duo: 2,
112
+ poster: 1,
113
+ glass: 1,
114
+ paper: 1,
115
+ colour: 1,
116
+ jitter: 1,
117
+ riso: 1,
118
+ crt: 1,
119
+ pattern: 1,
120
+ crop: 1,
121
+ ...LOOK_WEIGHTS,
122
+ };
123
+ const DEAL = Object.entries(WEIGHTS);
124
+ const TOTAL = DEAL.reduce((s, [, w]) => s + w, 0);
125
+
126
+ /** The live backgrounds a shader card can have: Paper's shaders (vendored in the effects library), the calm looks
127
+ * picked from its presets (2026-11-12: the rainbow colour panels, the white-hot smoke ring, the grey ink and Paper's
128
+ * own pale mesh went: a white lockup didn't read on them; two warps, two grain gradients and an aurora border came).
129
+ * `ours` takes a wall gradient's colours instead, `ink` is the words' colour, `scale` the share of the pixel ratio it's
130
+ * drawn at (a soft picture loses nothing at half; fine lines and grain keep three quarters), and `still` what shows
131
+ * before it starts, under reduced motion's first paint and without WebGL. */
132
+ const LOOKS = [
133
+ { shader: 'mesh-gradient', preset: 'Default', ours: true, scale: 0.5, still: (a, b, c, base) => liveGradient([a, b, c, base]).fallback },
134
+ {
135
+ shader: 'mesh-gradient',
136
+ preset: 'Purple',
137
+ scale: 0.5,
138
+ still: 'radial-gradient(at 26% 14%, #a39fd9 0, transparent 60%), radial-gradient(at 82% 86%, #5946b0 0, transparent 62%), #7566c4',
139
+ },
140
+ {
141
+ shader: 'warp',
142
+ preset: 'Nectar',
143
+ ink: '#0B0B0B',
144
+ scale: 0.5,
145
+ still: 'radial-gradient(at 50% 0, #ecd3a8 0, transparent 62%), radial-gradient(at 84% 100%, #f0e7d8 0, transparent 52%), #d9b98a',
146
+ },
147
+ { shader: 'warp', preset: 'Passion', scale: 0.5, still: 'linear-gradient(158deg, #6a2d31, #3b1515 46%, #8f444d)' },
148
+ { shader: 'warp', preset: 'Default', ours: true, scale: 0.75, still: (a, b, c, base) => liveGradient([a, b, c, base]).fallback },
149
+ { shader: 'neuro-noise', preset: 'Default', scale: 0.75, still: 'radial-gradient(at 50% 100%, #12325c 0, transparent 62%), #05070d' },
150
+ {
151
+ shader: 'god-rays',
152
+ preset: 'Ether',
153
+ scale: 0.5,
154
+ still: 'radial-gradient(64% 50% at 0 50%, #6a90c0 0, transparent 100%), linear-gradient(#1a2132, #1f3352)',
155
+ },
156
+ {
157
+ shader: 'grain-gradient',
158
+ preset: 'Default',
159
+ ours: true,
160
+ scale: 0.75,
161
+ still: (a, b) => `radial-gradient(at 0 100%, ${a} 0, transparent 46%), radial-gradient(at 100% 0, ${b} 0, transparent 46%), #000`,
162
+ },
163
+ { shader: 'grain-gradient', preset: 'Wave', scale: 0.75, still: 'linear-gradient(158deg, #000a0f 32%, #b4720f 62%, #d8ccc7)' },
164
+ {
165
+ shader: 'pulsing-border',
166
+ preset: 'Northern lights',
167
+ scale: 0.5,
168
+ still:
169
+ 'radial-gradient(at 50% 0, #19c46b 0, transparent 44%), radial-gradient(at 0 100%, #4733cc 0, transparent 52%), radial-gradient(at 100% 62%, #774a7d 0, transparent 46%), #0c182c',
170
+ },
171
+ ];
172
+
173
+ const NONE = { kinds: [], names: [], lines: [], photos: [] };
174
+ /** How far back each repeat is avoided, in cards. */
175
+ const SPAN = { kinds: 3, names: 30, lines: 8, photos: 12 };
176
+ /** A promo card every this many marks (`feed`). */
177
+ export const EVERY = 30;
178
+
179
+ /**
180
+ * A wall: `card`, `feed` and `backgrounds`, with the brand picker, the typefaces and the accent given here.
181
+ *
182
+ * @param options The brand picker, the faces, and optionally the accent, the links and the photos to skip.
183
+ */
184
+ export function lookbook(options) {
185
+ const { brand: pickBrand, faces: FACES } = options;
186
+ const accent = options.accent ?? ACCENT;
187
+ const href = options.href ?? ((m) => `#${m.slug}`);
188
+ const skip = options.skip;
189
+ const skipped = (p) => !!skip && skip.test(p);
190
+ const PALETTES = palettesOf(accent),
191
+ INKS = inksOf(accent),
192
+ TONES = tonesOf(accent);
193
+
194
+ /** One card's HTML, its height over its width, its brand, and what it used. `deal` changes with Shuffle (new names
195
+ * and looks for the same marks); `recent` is what the cards just before it used, so neighbours don't repeat a look, a
196
+ * name, a line or a photo. `only` forces the look (a preview page); `among` narrows the deal to a look set. */
197
+ function card(m, deal, assets, recent = NONE, only, among) {
198
+ const r = rng(hash(m.slug) + deal * 7919);
199
+ const pick = (xs) => xs[Math.floor(r() * xs.length)];
200
+ /** A look, by weight. */
201
+ const dealt = () => {
202
+ let x = r() * TOTAL;
203
+ for (const [k, w] of DEAL) if ((x -= w) < 0) return k;
204
+ return DEAL[0][0];
205
+ };
206
+ /** A pick (from `next`) that isn't in `avoid`, when one can be found in a few tries. */
207
+ const freshBy = (next, avoid) => {
208
+ let x = next();
209
+ for (let i = 0; i < 8 && avoid.includes(x); i++) x = next();
210
+ return x;
211
+ };
212
+ const fresh = (xs, avoid) => freshBy(() => pick(xs), avoid);
213
+ /** A look this mark suits: the bloom looks only go to abstract, round marks (./looks/bloom.js), the club looks
214
+ * to marks for a club night (./looks/club.js). */
215
+ const suits = (k) => (!BLOOM_KINDS.has(k) || bloomFits(m)) && (!CLUB_KINDS.has(k) || clubFits(m));
216
+ const BLOOMS = [...BLOOM_KINDS];
217
+ const CLUBS = [...CLUB_KINDS];
218
+ /** With `among` (a look set): a look from it this mark suits, by weight. */
219
+ const pool = among ? DEAL.filter(([k]) => among.has(k) && suits(k)) : [];
220
+ const poolTotal = pool.reduce((t, [, w]) => t + w, 0);
221
+ const dealtFit = () => {
222
+ if (pool.length) {
223
+ let x = r() * poolTotal;
224
+ for (const [k, w] of pool) if ((x -= w) < 0) return k;
225
+ return pool[0][0];
226
+ }
227
+ // a round, abstract mark takes a bloom look one time in four, so they show on the wall; a club mark a club
228
+ // look one time in four
229
+ if (bloomFits(m) && r() < 0.25) return pick(BLOOMS);
230
+ if (clubFits(m) && r() < 0.25) return pick(CLUBS);
231
+ let k = dealt();
232
+ for (let i = 0; i < 12 && !suits(k); i++) k = dealt();
233
+ return suits(k) ? k : 'photo';
234
+ };
235
+ const kind = only ?? freshBy(dealtFit, recent.kinds);
236
+ const brand = pickBrand(m, deal * 7919 + 1, { names: recent.names, lines: recent.lines });
237
+ const { name, line } = brand;
238
+ let photo = '';
239
+ /** A photo the recent cards haven't shown: of those whose file names match `only`, or else any but a look set's
240
+ * own series (the club photos are for the club looks). */
241
+ const photoOf = (only) => {
242
+ const all = assets.photos.filter((p) => !CLUB_PHOTOS.test(p) && !skipped(p));
243
+ const list = only ? assets.photos.filter((p) => only.test(p)) : all;
244
+ return (photo = fresh(list.length ? list : all, recent.photos));
245
+ };
246
+ /** A glass background (abstracts and flowers) the recent cards haven't shown. */
247
+ const glassOf = (only) => {
248
+ const list = only ? assets.glass.filter((p) => only.test(p)) : assets.glass;
249
+ return (photo = fresh(list.length ? list : assets.glass, recent.photos));
250
+ };
251
+ const [family, weight, track, tcase] = pick(FACES);
252
+ const type = `font-family:${family};font-weight:${weight};letter-spacing:${track};text-transform:${tcase}`;
253
+ const svg = (cls = '') =>
254
+ `<svg viewBox="0 0 512 512" fill="currentColor" aria-hidden="true"${cls ? ` class="${cls}"` : ''}>${m.paths}</svg>`;
255
+ const img = (src) => `<img src="${src}" alt="" loading="lazy" decoding="async" />`;
256
+ // the mark's optical size (./marks.js): --mk-k, --mk-w, --mk-h, which wall.css turns into --mk-scale for each look
257
+ let inner = '',
258
+ attrs = '',
259
+ style = `aspect-ratio:${RATIO[kind]}${opticalStyle(m.paths)}`;
260
+ const uid = `wlk-${kind}-${hash(m.slug).toString(36)}-${deal}`;
261
+ if (isLook(kind)) {
262
+ // a drawn look (./looks/index.js)
263
+ const out = look({
264
+ kind,
265
+ slug: m.slug,
266
+ paths: m.paths,
267
+ r,
268
+ uid,
269
+ name,
270
+ line,
271
+ tagline: brand.tagline,
272
+ tld: brand.tld,
273
+ type,
274
+ accent,
275
+ inks: INKS,
276
+ palettes: PALETTES,
277
+ photo: photoOf,
278
+ glass: glassOf,
279
+ });
280
+ inner = out.inner;
281
+ style += out.style;
282
+ attrs = out.attrs;
283
+ } else if (kind === 'photo') {
284
+ inner = `${img(photoOf())}<span class="wc-lockup">${svg()}<b class="wc-name" style="${type}">${escapeHtml(name)}</b></span>`;
285
+ } else if (kind === 'poster') {
286
+ inner = `${img(photoOf())}<span class="wc-top">${svg()}<i>Vol. ${String(1 + Math.floor(r() * 9)).padStart(2, '0')}</i></span><span class="wc-foot"><b class="wc-name" style="${type}">${escapeHtml(name)}</b><i>${escapeHtml(line)}</i></span>`;
287
+ } else if (kind === 'mono') {
288
+ // the photo in black and white, the mark and a two-line name in one strong ink, heavy and extended (event-poster style)
289
+ style += `;--ink:${pick(INKS)}`;
290
+ inner = `${img(photoOf())}<span class="wc-lockup is-stack">${svg()}<i>${escapeHtml(line)}</i><b class="wc-name">${escapeHtml(name)}</b></span>`;
291
+ } else if (kind === 'duo') {
292
+ // the photo washed in one strong colour (greyscale, then the colour laid over it), the lockup in white
293
+ style += `;--wash:${pick(WASHES)}`;
294
+ inner = `${img(photoOf())}<span class="wc-lockup">${svg()}<b class="wc-name" style="${type}">${escapeHtml(name)}</b></span>`;
295
+ } else if (kind === 'jitter') {
296
+ // the photo glitching: two tinted copies flash in offset slices now and then (CSS, wall.css; still when motion is reduced)
297
+ const src = photoOf(),
298
+ copy = (n) => `<img class="wc-j wc-j${n}" src="${src}" alt="" aria-hidden="true" loading="lazy" decoding="async" />`;
299
+ style += `;--d:-${(r() * 6).toFixed(2)}s`;
300
+ attrs = ' data-anim'; // it moves only while live (near the screen), like the drawn looks
301
+ inner = `${img(src)}${copy(1)}${copy(2)}<span class="wc-lockup">${svg()}<b class="wc-name" style="${type}">${escapeHtml(name)}</b></span>`;
302
+ } else if (kind === 'riso') {
303
+ // the photo printed in two inks, a second pass a little off register, the lockup on a paper chip
304
+ const [ink, paper] = pick(RISO);
305
+ style += `;--ink:${ink};--paper:${paper}`;
306
+ const src = photoOf();
307
+ inner = `${img(src)}<img class="wc-ri2" src="${src}" alt="" aria-hidden="true" loading="lazy" decoding="async" /><span class="wc-lockup wc-chip">${svg()}<b class="wc-name" style="${type}">${escapeHtml(name)}</b></span>`;
308
+ } else if (kind === 'crt') {
309
+ // a dark screen: scanlines, a faint flicker, the lockup glowing in one phosphor
310
+ style += `;--ph:${pick(PHOSPHOR)}`;
311
+ attrs = ' data-anim'; // the flicker and the cursor run only while live
312
+ inner = `<span class="wc-lockup">${svg()}<b class="wc-name">${escapeHtml(name.toLowerCase())}<i class="wc-cursor">_</i></b></span>`;
313
+ } else if (kind === 'pattern') {
314
+ // the mark tiled as tilted wallpaper, the name on a solid chip over it
315
+ const [bg, fg] = pick(PALETTES),
316
+ id = `wp${hash(m.slug).toString(36)}${deal}`;
317
+ style += `;--bg:${bg};--fg:${fg}`;
318
+ inner = `<svg class="wc-pat" viewBox="0 0 400 500" preserveAspectRatio="xMidYMid slice" aria-hidden="true"><defs><pattern id="${id}" width="100" height="100" patternUnits="userSpaceOnUse" patternTransform="rotate(-14)"><g transform="translate(22 22) scale(0.1094)">${m.paths}</g></pattern></defs><rect width="400" height="500" fill="url(#${id})" /></svg><span class="wc-lockup wc-chip">${svg()}<b class="wc-name" style="${type}">${escapeHtml(name)}</b></span>`;
319
+ } else if (kind === 'crop') {
320
+ // the mark huge and cropped off the edge, the name small in the corner (poster style)
321
+ const [bg, fg] = pick(PALETTES);
322
+ style += `;--bg:${bg};--fg:${fg}`;
323
+ inner = `${svg('wc-big')}<span class="wc-corner"><b class="wc-name" style="${type}">${escapeHtml(name)}</b><i>${escapeHtml(line)}</i></span>`;
324
+ } else if (kind === 'glass') {
325
+ inner = `${img(pick(assets.glass))}<span class="wc-mark">${svg()}</span><span class="wc-small wc-name" style="${type}">${escapeHtml(name)}</span>`;
326
+ } else if (kind === 'gradient') {
327
+ // a live gradient (effects-astro): Paper's mesh in these colours, morphing slowly under the grain; its still
328
+ // CSS version shows until it starts (./live.js), and without WebGL
329
+ const mesh = freshBy(
330
+ () => pick(MESHES),
331
+ MESHES.filter((x) => recent.photos.includes(meshKey(x))),
332
+ );
333
+ photo = meshKey(mesh); // kept among the recent backgrounds, so the next gradients take other colours
334
+ const {
335
+ colors: [a, b, c],
336
+ base,
337
+ ink,
338
+ } = mesh;
339
+ const { config, fallback } = liveGradient([a, b, c, base]);
340
+ attrs = ` data-shader="${escapeHtml(JSON.stringify(config))}"`;
341
+ style += `;--fg:${ink};background:${fallback}`;
342
+ inner = '<canvas class="wc-fx" aria-hidden="true"></canvas>';
343
+ inner +=
344
+ r() < 0.5
345
+ ? `<span class="wc-lockup is-stack">${svg()}<b class="wc-name" style="${type}">${escapeHtml(name)}</b><i>${escapeHtml(line)}</i></span>`
346
+ : `<span class="wc-lockup">${svg()}<b class="wc-name" style="${type}">${escapeHtml(name)}</b></span>`;
347
+ } else if (kind === 'shader') {
348
+ // a live shader, started on screen (./live.js), fading in over its still: a CSS background in the same
349
+ // colours, which also shows without WebGL
350
+ // a shader in its own colours isn't shown again close by; one that takes ours takes colours not shown close by
351
+ const lookKey = (l) => `shader:${l.shader}:${l.preset}`;
352
+ const look = freshBy(
353
+ () => pick(LOOKS),
354
+ LOOKS.filter((l) => !l.ours && recent.photos.includes(lookKey(l))),
355
+ );
356
+ const mesh = freshBy(
357
+ () => pick(MESHES),
358
+ MESHES.filter((x) => recent.photos.includes(meshKey(x))),
359
+ );
360
+ photo = look.ours ? meshKey(mesh) : lookKey(look);
361
+ const {
362
+ colors: [a, b, c],
363
+ base,
364
+ } = mesh;
365
+ const cfg = { shader: look.shader, preset: look.preset, scale: look.scale, ...(look.ours ? { colors: [a, b, c, base] } : {}) };
366
+ attrs = ` data-shader="${escapeHtml(JSON.stringify(cfg))}"`;
367
+ style += `;--fg:${look.ink ?? '#fff'};background:${typeof look.still === 'string' ? look.still : look.still(a, b, c, base)}`;
368
+ inner = `<canvas class="wc-fx" aria-hidden="true"></canvas>${r() < 0.5 ? `<span class="wc-lockup is-stack">${svg()}<b class="wc-name" style="${type}">${escapeHtml(name)}</b><i>${escapeHtml(line)}</i></span>` : `<span class="wc-lockup">${svg()}<b class="wc-name" style="${type}">${escapeHtml(name)}</b></span>`}`;
369
+ } else if (kind === 'tone') {
370
+ const [bg, tint] = pick(TONES);
371
+ style += `;--bg:${bg};--accent:${tint}`;
372
+ inner = `${svg('wc-ghost')}<span class="wc-lockup is-row">${svg('wc-accent')}<b class="wc-name" style="${type}">${escapeHtml(name)}</b></span>`;
373
+ } else {
374
+ const [bg, fg] = kind === 'paper' ? ['#F4F3EF', '#0B0B0B'] : pick(PALETTES);
375
+ style += `;--bg:${bg};--fg:${fg}`;
376
+ inner = `<span class="wc-lockup is-stack">${svg()}<b class="wc-name" style="${type}">${escapeHtml(name)}</b><i>${escapeHtml(line)}</i></span>`;
377
+ }
378
+ // the Plain card, the same for every look (shown only in Plain mode): the mark at its optical size, the name under
379
+ // it; a drawn look's mark is its one copy, reused
380
+ const mark = isLook(kind) ? `<svg viewBox="0 0 512 512" fill="currentColor" aria-hidden="true"><use href="#${uid}-m" /></svg>` : svg();
381
+ const plain = `<span class="wc-plain">${mark}<b class="wc-name">${escapeHtml(name)}</b></span>`;
382
+ const [w, h] = RATIO[kind].split('/').map(Number);
383
+ return {
384
+ html: `<a class="wc wc-${kind}${isLook(kind) ? ' wx' : ''}" href="${href(m)}" style="${style}"${attrs}>${inner}${plain}<span class="wc-tag">${escapeHtml(m.name)} <em>→</em></span></a>`,
385
+ h: h / w,
386
+ brand,
387
+ used: { kinds: [kind], names: [name], lines: [line], photos: photo ? [photo] : [] },
388
+ };
389
+ }
390
+
391
+ /** The pictures a card's background steps through in the expanded view: its own set (the glass, the club hall, the
392
+ * club's people, or the other photos), so a club card stays in the club and a portrait card never lands on a dance
393
+ * floor. */
394
+ function backgrounds(assets, src) {
395
+ if (assets.glass.includes(src)) return assets.glass;
396
+ // the club photos split again: the hall's crowd (a mark goes over it) and the people (their faces never under a mark)
397
+ const set = (p) => (CLUB_PHOTOS.test(p) ? (/\/club-\d+\.webp$/.test(p) ? 'hall' : 'people') : 'photo');
398
+ return assets.photos.filter((p) => !skipped(p) && set(p) === set(src));
399
+ }
400
+
401
+ /** The feed from `from` to `to` (positions in `order`), with `promo(k)`'s card after every `EVERY` marks (the k-th). */
402
+ function feed(all, order, from, to, deal, assets, promo, among) {
403
+ const out = [];
404
+ let recent = NONE;
405
+ /** Adds a card's picks to the recent list, each kept for its SPAN. */
406
+ const note = (u) =>
407
+ (recent = {
408
+ kinds: [...u.kinds, ...recent.kinds].slice(0, SPAN.kinds),
409
+ names: [...u.names, ...recent.names].slice(0, SPAN.names),
410
+ lines: [...u.lines, ...recent.lines].slice(0, SPAN.lines),
411
+ photos: [...u.photos, ...recent.photos].slice(0, SPAN.photos),
412
+ });
413
+ // replay the cards just before `from`, so a chunk loaded on scroll doesn't repeat the end of the last one
414
+ for (let n = Math.max(0, from - SPAN.names); n < from; n++) note(card(all[order[n]], deal, assets, recent, undefined, among).used);
415
+ for (let n = from; n < Math.min(to, order.length); n++) {
416
+ const c = card(all[order[n]], deal, assets, recent, undefined, among);
417
+ note(c.used);
418
+ out.push(c);
419
+ if (promo && (n + 1) % EVERY === 0) out.push(promo((n + 1) / EVERY));
420
+ }
421
+ return out;
422
+ }
423
+
424
+ return { card, feed, backgrounds };
425
+ }
426
+
427
+ /**
428
+ * A shuffled copy (seeded: the same seed, the same order).
429
+ *
430
+ * @param xs The items.
431
+ * @param seed The seed.
432
+ */
433
+ export function shuffled(xs, seed) {
434
+ const r = rng(seed),
435
+ a = xs.slice();
436
+ for (let i = a.length - 1; i > 0; i--) {
437
+ const j = Math.floor(r() * (i + 1));
438
+ [a[i], a[j]] = [a[j], a[i]];
439
+ }
440
+ return a;
441
+ }