@abraca/junis 2.84.0 → 2.85.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.
Files changed (40) hide show
  1. package/dist/module.json +1 -1
  2. package/dist/module.mjs +35 -3
  3. package/dist/runtime/assets/css/jun.css +1 -1
  4. package/dist/runtime/components/JunBlobBackdrop.client.vue +1 -1
  5. package/dist/runtime/components/JunHead.vue +37 -5
  6. package/dist/runtime/components/JunLogo.vue +10 -45
  7. package/dist/runtime/components/JunPatternBackdrop.client.vue +1 -1
  8. package/dist/runtime/components/JunShaderBackdrop.client.vue +1 -1
  9. package/dist/runtime/components/renderers/JunConfigRenderer.vue +14 -14
  10. package/dist/runtime/components/renderers/JunEntryRenderer.vue +6 -8
  11. package/dist/runtime/components/renderers/JunFestivalRenderer.vue +1 -1
  12. package/dist/runtime/components/renderers/JunHomeRenderer.vue +3 -3
  13. package/dist/runtime/components/renderers/JunLiveRenderer.vue +1 -1
  14. package/dist/runtime/components/renderers/JunNowRenderer.vue +2 -2
  15. package/dist/runtime/components/renderers/JunUsesRenderer.vue +6 -8
  16. package/dist/runtime/composables/useJunOptions.d.ts +1 -0
  17. package/dist/runtime/composables/useJunTheme.js +9 -48
  18. package/dist/runtime/plugins/jun-sw.client.d.ts +2 -0
  19. package/dist/runtime/plugins/jun-sw.client.js +36 -0
  20. package/dist/runtime/server/plugins/jun-janitor.js +2 -1
  21. package/dist/runtime/server/routes/jun-icon.png.get.d.ts +2 -0
  22. package/dist/runtime/server/routes/jun-icon.png.get.js +25 -0
  23. package/dist/runtime/server/routes/jun-icon.svg.get.d.ts +2 -0
  24. package/dist/runtime/server/routes/jun-icon.svg.get.js +9 -0
  25. package/dist/runtime/server/routes/jun-splash.png.get.d.ts +2 -0
  26. package/dist/runtime/server/routes/jun-splash.png.get.js +37 -0
  27. package/dist/runtime/server/routes/jun-sw.js.get.d.ts +2 -0
  28. package/dist/runtime/server/routes/jun-sw.js.get.js +126 -0
  29. package/dist/runtime/server/routes/manifest.webmanifest.get.d.ts +24 -0
  30. package/dist/runtime/server/routes/manifest.webmanifest.get.js +51 -0
  31. package/dist/runtime/server/utils/junBrand.d.ts +4 -0
  32. package/dist/runtime/server/utils/junBrand.js +9 -0
  33. package/dist/runtime/server/utils/junIcon.d.ts +44 -0
  34. package/dist/runtime/server/utils/junIcon.js +374 -0
  35. package/dist/runtime/types.d.ts +25 -2
  36. package/dist/runtime/utils/junIdentity.d.ts +121 -0
  37. package/dist/runtime/utils/junIdentity.js +115 -0
  38. package/dist/runtime/utils/junMark.d.ts +254 -0
  39. package/dist/runtime/utils/junMark.js +169 -0
  40. package/package.json +1 -1
@@ -0,0 +1,374 @@
1
+ import { JUN_MARKS, JUN_MARK_VIEWBOX, JUN_SUN, junHexToRgb } from "../../utils/junMark.js";
2
+ const CMD_RE = /[MmLlHhVvCcZz]|-?\d*\.?\d+(?:e[-+]?\d+)?/g;
3
+ export function junFlattenPath(d) {
4
+ const tokens = d.match(CMD_RE) ?? [];
5
+ const segs = [];
6
+ let i = 0;
7
+ let cmd = "";
8
+ let x = 0;
9
+ let y = 0;
10
+ let startX = 0;
11
+ let startY = 0;
12
+ let started = false;
13
+ const num = () => Number.parseFloat(tokens[i++] ?? "0");
14
+ const lineTo = (nx, ny) => {
15
+ segs.push([x, y, nx, ny]);
16
+ x = nx;
17
+ y = ny;
18
+ };
19
+ const cubicTo = (x1, y1, x2, y2, ex, ey) => {
20
+ const px = x;
21
+ const py = y;
22
+ const STEPS = 24;
23
+ for (let s = 1; s <= STEPS; s++) {
24
+ const t = s / STEPS;
25
+ const u = 1 - t;
26
+ const bx = u * u * u * px + 3 * u * u * t * x1 + 3 * u * t * t * x2 + t * t * t * ex;
27
+ const by = u * u * u * py + 3 * u * u * t * y1 + 3 * u * t * t * y2 + t * t * t * ey;
28
+ segs.push([x, y, bx, by]);
29
+ x = bx;
30
+ y = by;
31
+ }
32
+ };
33
+ while (i < tokens.length) {
34
+ const tok = tokens[i];
35
+ if (/[a-z]/i.test(tok)) {
36
+ cmd = tok;
37
+ i++;
38
+ } else if (cmd === "M") {
39
+ cmd = "L";
40
+ continue;
41
+ } else if (cmd === "m") {
42
+ cmd = "l";
43
+ continue;
44
+ }
45
+ switch (cmd) {
46
+ case "M":
47
+ case "m": {
48
+ const nx = num();
49
+ const ny = num();
50
+ x = cmd === "m" && started ? x + nx : nx;
51
+ y = cmd === "m" && started ? y + ny : ny;
52
+ startX = x;
53
+ startY = y;
54
+ started = true;
55
+ break;
56
+ }
57
+ case "L":
58
+ case "l": {
59
+ const nx = num();
60
+ const ny = num();
61
+ lineTo(cmd === "l" ? x + nx : nx, cmd === "l" ? y + ny : ny);
62
+ break;
63
+ }
64
+ case "H":
65
+ case "h": {
66
+ const nx = num();
67
+ lineTo(cmd === "h" ? x + nx : nx, y);
68
+ break;
69
+ }
70
+ case "V":
71
+ case "v": {
72
+ const ny = num();
73
+ lineTo(x, cmd === "v" ? y + ny : ny);
74
+ break;
75
+ }
76
+ case "C":
77
+ case "c": {
78
+ const rel = cmd === "c";
79
+ const x1 = num() + (rel ? x : 0);
80
+ const y1 = num() + (rel ? y : 0);
81
+ const x2 = num() + (rel ? x : 0);
82
+ const y2 = num() + (rel ? y : 0);
83
+ const ex = num() + (rel ? x : 0);
84
+ const ey = num() + (rel ? y : 0);
85
+ cubicTo(x1, y1, x2, y2, ex, ey);
86
+ break;
87
+ }
88
+ case "Z":
89
+ case "z":
90
+ lineTo(startX, startY);
91
+ break;
92
+ default:
93
+ i++;
94
+ }
95
+ }
96
+ return segs;
97
+ }
98
+ function distSqToSegment(px, py, s) {
99
+ const [ax, ay, bx, by] = s;
100
+ const dx = bx - ax;
101
+ const dy = by - ay;
102
+ const len = dx * dx + dy * dy;
103
+ let t = len === 0 ? 0 : ((px - ax) * dx + (py - ay) * dy) / len;
104
+ t = t < 0 ? 0 : t > 1 ? 1 : t;
105
+ const cx = ax + t * dx - px;
106
+ const cy = ay + t * dy - py;
107
+ return cx * cx + cy * cy;
108
+ }
109
+ function mixRgb(a, b, t) {
110
+ return [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];
111
+ }
112
+ function circleShape(cx, cy, r, rgb, alpha = 1) {
113
+ const r2 = r * r;
114
+ return {
115
+ bb: [cx - r, cy - r, cx + r, cy + r],
116
+ at: (x, y) => {
117
+ const dx = x - cx;
118
+ const dy = y - cy;
119
+ return dx * dx + dy * dy <= r2 ? [rgb[0], rgb[1], rgb[2], alpha] : null;
120
+ }
121
+ };
122
+ }
123
+ function strokeShape(segs, width, rgb) {
124
+ const half = width / 2;
125
+ const halfSq = half * half;
126
+ let x0 = Infinity;
127
+ let y0 = Infinity;
128
+ let x1 = -Infinity;
129
+ let y1 = -Infinity;
130
+ for (const s of segs) {
131
+ x0 = Math.min(x0, s[0], s[2]);
132
+ y0 = Math.min(y0, s[1], s[3]);
133
+ x1 = Math.max(x1, s[0], s[2]);
134
+ y1 = Math.max(y1, s[1], s[3]);
135
+ }
136
+ return {
137
+ bb: [x0 - half, y0 - half, x1 + half, y1 + half],
138
+ at: (x, y) => {
139
+ for (const s of segs) {
140
+ if (distSqToSegment(x, y, s) <= halfSq) return [rgb[0], rgb[1], rgb[2], 1];
141
+ }
142
+ return null;
143
+ }
144
+ };
145
+ }
146
+ function markShapes(mark, c) {
147
+ if (mark !== "sun") {
148
+ const geom = JUN_MARKS[mark] ?? JUN_MARKS.sprout;
149
+ const ink = junHexToRgb(c.ink);
150
+ return [
151
+ ...geom.paths.map((p) => strokeShape(junFlattenPath(p.d), p.w, ink)),
152
+ ...geom.dots.map((dot) => circleShape(dot.cx, dot.cy, dot.r, ink))
153
+ ];
154
+ }
155
+ const { body, core, glow, halo } = JUN_SUN;
156
+ const from = junHexToRgb(c.sunFrom);
157
+ const to = junHexToRgb(c.sunTo);
158
+ const coreRgb = junHexToRgb(c.sunCore);
159
+ const glowRgb = junHexToRgb(c.sunGlow);
160
+ const vb = JUN_MARK_VIEWBOX;
161
+ const bodyR2 = body.r * body.r;
162
+ const coreR2 = core.r * core.r;
163
+ const haloR2 = halo.r * halo.r;
164
+ const haloInnerStop = core.r / halo.r;
165
+ return [
166
+ // Body: `linearGradient x1/y1 0 → x2/y2 1` on a square box is exactly
167
+ // corner to corner, so the parameter is (x + y) over twice the box.
168
+ {
169
+ bb: [body.cx - body.r, body.cy - body.r, body.cx + body.r, body.cy + body.r],
170
+ at: (x, y) => {
171
+ const dx = x - body.cx;
172
+ const dy = y - body.cy;
173
+ if (dx * dx + dy * dy > bodyR2) return null;
174
+ const t = Math.max(0, Math.min(1, (x + y) / (2 * vb)));
175
+ const [r, g, b] = mixRgb(from, to, t);
176
+ return [r, g, b, 1];
177
+ }
178
+ },
179
+ // Halo: black, flat out to the core's edge, then falling away.
180
+ {
181
+ bb: [halo.cx - halo.r, halo.cy - halo.r, halo.cx + halo.r, halo.cy + halo.r],
182
+ at: (x, y) => {
183
+ const dx = x - halo.cx;
184
+ const dy = y - halo.cy;
185
+ const d2 = dx * dx + dy * dy;
186
+ if (d2 > haloR2) return null;
187
+ const t = Math.sqrt(d2) / halo.r;
188
+ let a;
189
+ if (t <= haloInnerStop) a = halo.inner;
190
+ else if (t <= 0.84) a = halo.inner + (halo.mid - halo.inner) * ((t - haloInnerStop) / (0.84 - haloInnerStop));
191
+ else a = halo.mid * (1 - (t - 0.84) / 0.16);
192
+ return [0, 0, 0, a];
193
+ }
194
+ },
195
+ circleShape(core.cx, core.cy, core.r, coreRgb),
196
+ // Glow: a radial gradient centred well outside the mark and CLIPPED by the
197
+ // core, which is what puts it in the core's lower right and leaves the
198
+ // upper left clean.
199
+ {
200
+ bb: [core.cx - core.r, core.cy - core.r, core.cx + core.r, core.cy + core.r],
201
+ at: (x, y) => {
202
+ const dx = x - core.cx;
203
+ const dy = y - core.cy;
204
+ if (dx * dx + dy * dy > coreR2) return null;
205
+ const gx = x - glow.cx;
206
+ const gy = y - glow.cy;
207
+ const a = 1 - Math.sqrt(gx * gx + gy * gy) / glow.r;
208
+ if (a <= 0) return null;
209
+ return [glowRgb[0], glowRgb[1], glowRgb[2], a];
210
+ }
211
+ }
212
+ ];
213
+ }
214
+ let crcTable = null;
215
+ function crc32(buf) {
216
+ if (!crcTable) {
217
+ crcTable = new Uint32Array(256);
218
+ for (let n = 0; n < 256; n++) {
219
+ let c2 = n;
220
+ for (let k = 0; k < 8; k++) c2 = c2 & 1 ? 3988292384 ^ c2 >>> 1 : c2 >>> 1;
221
+ crcTable[n] = c2 >>> 0;
222
+ }
223
+ }
224
+ let c = 4294967295;
225
+ for (let i = 0; i < buf.length; i++) c = crcTable[(c ^ buf[i]) & 255] ^ c >>> 8;
226
+ return (c ^ 4294967295) >>> 0;
227
+ }
228
+ function pngChunk(type, data) {
229
+ const typeBytes = new TextEncoder().encode(type);
230
+ const body = new Uint8Array(typeBytes.length + data.length);
231
+ body.set(typeBytes);
232
+ body.set(data, typeBytes.length);
233
+ const out = new Uint8Array(8 + data.length + 4);
234
+ const view = new DataView(out.buffer);
235
+ view.setUint32(0, data.length);
236
+ out.set(body, 4);
237
+ view.setUint32(4 + body.length, crc32(body));
238
+ return out;
239
+ }
240
+ async function encodePng(rgba, width, height) {
241
+ const { deflateSync } = await import("node:zlib");
242
+ const stride = width * 4;
243
+ const raw = new Uint8Array(height * (1 + stride));
244
+ for (let y = 0; y < height; y++) {
245
+ const at2 = y * (1 + stride);
246
+ if (y === 0) {
247
+ raw[at2] = 0;
248
+ raw.set(rgba.subarray(0, stride), at2 + 1);
249
+ continue;
250
+ }
251
+ raw[at2] = 2;
252
+ const row = y * stride;
253
+ const prev = row - stride;
254
+ for (let i = 0; i < stride; i++) {
255
+ raw[at2 + 1 + i] = rgba[row + i] - rgba[prev + i] & 255;
256
+ }
257
+ }
258
+ const ihdr = new Uint8Array(13);
259
+ const iv = new DataView(ihdr.buffer);
260
+ iv.setUint32(0, width);
261
+ iv.setUint32(4, height);
262
+ ihdr[8] = 8;
263
+ ihdr[9] = 6;
264
+ const parts = [
265
+ new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]),
266
+ pngChunk("IHDR", ihdr),
267
+ pngChunk("IDAT", new Uint8Array(deflateSync(Buffer.from(raw), { level: 6 }))),
268
+ pngChunk("IEND", new Uint8Array(0))
269
+ ];
270
+ const total = parts.reduce((n, p) => n + p.length, 0);
271
+ const png = new Uint8Array(total);
272
+ let at = 0;
273
+ for (const p of parts) {
274
+ png.set(p, at);
275
+ at += p.length;
276
+ }
277
+ return png;
278
+ }
279
+ const cache = /* @__PURE__ */ new Map();
280
+ function cacheKey(req) {
281
+ const c = req.colors;
282
+ return [
283
+ req.mark,
284
+ req.size,
285
+ req.height ?? req.size,
286
+ req.background ?? "-",
287
+ req.scale ?? 1,
288
+ c.ink,
289
+ c.sunFrom,
290
+ c.sunTo,
291
+ c.sunCore,
292
+ c.sunGlow
293
+ ].join("|");
294
+ }
295
+ export async function junRenderIcon(req) {
296
+ const key = cacheKey(req);
297
+ const hit = cache.get(key);
298
+ if (hit) return hit;
299
+ const width = Math.max(16, Math.min(4096, Math.round(req.size)));
300
+ const height = Math.max(16, Math.min(4096, Math.round(req.height ?? req.size)));
301
+ const scale = req.scale ?? 1;
302
+ const shorter = Math.min(width, height);
303
+ const ss = shorter < 256 ? 3 : 2;
304
+ const vb = JUN_MARK_VIEWBOX;
305
+ const shapes = markShapes(req.mark, req.colors);
306
+ const bg = req.background ? junHexToRgb(req.background) : null;
307
+ const box = shorter * scale;
308
+ const boxX = (width - box) / 2;
309
+ const boxY = (height - box) / 2;
310
+ const step = vb / box;
311
+ const sub = step / ss;
312
+ const offset = sub / 2;
313
+ const rgba = new Uint8Array(width * height * 4);
314
+ if (bg) {
315
+ for (let i = 0; i < rgba.length; i += 4) {
316
+ rgba[i] = bg[0];
317
+ rgba[i + 1] = bg[1];
318
+ rgba[i + 2] = bg[2];
319
+ rgba[i + 3] = 255;
320
+ }
321
+ }
322
+ const x0 = Math.max(0, Math.floor(boxX));
323
+ const y0 = Math.max(0, Math.floor(boxY));
324
+ const x1 = Math.min(width, Math.ceil(boxX + box));
325
+ const y1 = Math.min(height, Math.ceil(boxY + box));
326
+ const inv = 1 / (ss * ss);
327
+ for (let py = y0; py < y1; py++) {
328
+ for (let px = x0; px < x1; px++) {
329
+ let ar = 0;
330
+ let ag = 0;
331
+ let ab = 0;
332
+ let aa = 0;
333
+ for (let sy = 0; sy < ss; sy++) {
334
+ const uy = (py - boxY) * step + sy * sub + offset;
335
+ for (let sx = 0; sx < ss; sx++) {
336
+ const ux = (px - boxX) * step + sx * sub + offset;
337
+ let r = bg ? bg[0] : 0;
338
+ let g = bg ? bg[1] : 0;
339
+ let b = bg ? bg[2] : 0;
340
+ let a = bg ? 1 : 0;
341
+ for (const shape of shapes) {
342
+ if (ux < shape.bb[0] || ux > shape.bb[2] || uy < shape.bb[1] || uy > shape.bb[3]) continue;
343
+ const s = shape.at(ux, uy);
344
+ if (!s) continue;
345
+ const sa = s[3];
346
+ if (sa <= 0) continue;
347
+ const outA = sa + a * (1 - sa);
348
+ if (outA <= 0) continue;
349
+ r = (s[0] * sa + r * a * (1 - sa)) / outA;
350
+ g = (s[1] * sa + g * a * (1 - sa)) / outA;
351
+ b = (s[2] * sa + b * a * (1 - sa)) / outA;
352
+ a = outA;
353
+ }
354
+ ar += r * a;
355
+ ag += g * a;
356
+ ab += b * a;
357
+ aa += a;
358
+ }
359
+ }
360
+ const o = (py * width + px) * 4;
361
+ const alpha = aa * inv;
362
+ if (alpha > 0) {
363
+ rgba[o] = Math.round(Math.max(0, Math.min(255, ar / aa)));
364
+ rgba[o + 1] = Math.round(Math.max(0, Math.min(255, ag / aa)));
365
+ rgba[o + 2] = Math.round(Math.max(0, Math.min(255, ab / aa)));
366
+ }
367
+ rgba[o + 3] = Math.round(Math.max(0, Math.min(255, alpha * 255)));
368
+ }
369
+ }
370
+ const png = await encodePng(rgba, width, height);
371
+ if (cache.size > 48) cache.clear();
372
+ cache.set(key, png);
373
+ return png;
374
+ }
@@ -585,10 +585,25 @@ export interface JunBrand {
585
585
  logoVariant?: JunLogoVariant;
586
586
  /** PWA / browser theme colour. */
587
587
  themeColor?: string;
588
+ /**
589
+ * The tile the app icon is drawn on — the home-screen square, before iOS
590
+ * rounds it and Android crops it. Defaults to `themeColor`.
591
+ *
592
+ * It is ONE colour rather than a per-scheme pair, and that is not an
593
+ * omission: a home-screen icon sits on whatever wallpaper the person chose
594
+ * and never follows the site's colour mode. The mark is drawn in its DARK
595
+ * colours on it, because the default tile is near-black and the light mark's
596
+ * ink is near-black too.
597
+ */
598
+ iconBackground?: string;
588
599
  /**
589
600
  * PWA manifest icons. Public paths, since the manifest is fetched by the
590
- * browser rather than bundled. Omit and no manifest icons are declared —
591
- * which is better than pointing at files a site does not have.
601
+ * browser rather than bundled.
602
+ *
603
+ * Only needed to OVERRIDE the module's own: `/jun-icon.png?size=…` renders
604
+ * the site's configured mark in its configured accent, at any size, so a site
605
+ * that has not drawn its own artwork still installs with a real icon rather
606
+ * than with a screenshot of its front page.
592
607
  */
593
608
  icons?: {
594
609
  src: string;
@@ -808,6 +823,8 @@ export interface JunRuntimeOptions {
808
823
  logoMark: JunLogoMark;
809
824
  logoVariant: JunLogoVariant;
810
825
  themeColor: string;
826
+ /** The app-icon tile. Defaults to `themeColor`; see `JunBrand`. */
827
+ iconBackground: string;
811
828
  schemaType: JunBrand['schemaType'];
812
829
  };
813
830
  features: Required<JunFeatures>;
@@ -849,6 +866,12 @@ export interface JunRuntimeOptions {
849
866
  paletteMap: Record<string, string>;
850
867
  /** Where the module's own API routes live. Change only to avoid a collision. */
851
868
  apiBase: string;
869
+ /**
870
+ * Whether the module contributes app identity — manifest, icons, launch
871
+ * screens and a service worker. Read at RUNTIME by the service-worker
872
+ * plugin, which cannot see module options.
873
+ */
874
+ pwa: boolean;
852
875
  /** Mapbox token for the globe. Empty unless the site sets one. */
853
876
  mapboxToken: string;
854
877
  /** Third-party media policy. See `JunEmbedOptions`. */
@@ -0,0 +1,121 @@
1
+ /**
2
+ * "What does this site look like?" — the pure answer.
3
+ *
4
+ * Four places need it and none of them may disagree: `<JunHead>` (which writes
5
+ * the `<link>`s), the favicon route, the icon rasteriser and the web manifest.
6
+ * The first runs in the browser and during SSR; the rest run only in Nitro. So
7
+ * the resolution lives here, with **no imports beyond `junMark`**, and each
8
+ * caller supplies its own two inputs — the build-time `jun.brand` options and
9
+ * the Site Config document's meta.
10
+ *
11
+ * The consequence worth stating: the icon URLs carry a `?v=` computed from this
12
+ * identity, and both sides compute it from the same function. If one side ever
13
+ * resolved the brand differently, the head would emit a URL the routes render
14
+ * something else for, and the tab and the home screen would drift apart with
15
+ * nothing failing.
16
+ */
17
+ import type { JunMarkColors, JunMarkName } from './junMark.js';
18
+ export interface JunIdentity {
19
+ name: string;
20
+ /** What a home screen has room for. Launchers truncate rather than wrap. */
21
+ shortName: string;
22
+ description: string;
23
+ mark: JunMarkName;
24
+ light: JunMarkColors;
25
+ dark: JunMarkColors;
26
+ /**
27
+ * The app icon's tile. A home-screen icon is not theme-aware — it sits on
28
+ * whatever wallpaper the person chose — so it commits to ONE colour, and the
29
+ * site's `themeColor` is the colour its app chrome already uses.
30
+ */
31
+ tile: string;
32
+ themeColor: string;
33
+ /**
34
+ * Everything above, as a short stable string, used as the cache-buster on
35
+ * every icon URL. The icon responses are `immutable` for a year; without this
36
+ * an owner changing the accent would keep the old icon until it expired.
37
+ */
38
+ version: string;
39
+ }
40
+ /** The `jun.brand` options this needs. A subset, so the type stays portable. */
41
+ export interface JunIdentityBrand {
42
+ name?: string;
43
+ tagline?: string;
44
+ seoDescription?: string;
45
+ logoMark?: string;
46
+ themeColor?: string;
47
+ iconBackground?: string;
48
+ }
49
+ /**
50
+ * A short, stable, non-cryptographic digest — FNV-1a. A cache key, not a
51
+ * checksum: it has to be identical on both sides of the wire and cheap enough
52
+ * to compute on every render, and it is never compared against anything an
53
+ * attacker supplies.
54
+ */
55
+ export declare function junFingerprint(input: string): string;
56
+ export declare function junIdentity(brand: JunIdentityBrand | undefined, cfg: Record<string, unknown>): JunIdentity;
57
+ /**
58
+ * How much of its box a mark should fill.
59
+ *
60
+ * `sun` IS a disc that meets the edge — insetting it leaves a ring of tile
61
+ * around a shape whose whole job is to BE the tile. The monoline marks are
62
+ * drawn inside a 48-unit box with a margin already, but not enough of one for a
63
+ * launcher's crop.
64
+ *
65
+ * `maskable` is Android's promise that it may crop to any shape inside the
66
+ * central 80%, hence the much deeper inset. Getting this wrong is not subtle:
67
+ * an un-inset maskable icon comes back with its edges sliced off.
68
+ */
69
+ export declare function junIconScale(mark: JunMarkName, maskable?: boolean): number;
70
+ /** The icon URLs, so the head and the manifest cannot spell them differently. */
71
+ export declare function junIconUrls(identity: JunIdentity): {
72
+ favicon: string;
73
+ appleTouch: string;
74
+ png: (size: number, maskable?: boolean) => string;
75
+ splash: (w: number, h: number) => string;
76
+ };
77
+ /**
78
+ * The screens iOS will show a launch image on.
79
+ *
80
+ * ── Why a table at all ──────────────────────────────────────────────────────
81
+ * Android builds its own splash from the manifest (`background_color` + the
82
+ * 512 icon + the name), so everything Android needs is already declared. iOS
83
+ * builds nothing: with no `apple-touch-startup-image` it shows a WHITE screen
84
+ * on every launch, and a white flash in front of a dark site is the second most
85
+ * obvious tell that an installed app is a website — right behind the icon.
86
+ *
87
+ * ── Why it looks like this ──────────────────────────────────────────────────
88
+ * iOS matches on CSS dimensions and DPR, and it matches EXACTLY: a device with
89
+ * no entry gets white, and a near-miss does not letterbox, it is simply not
90
+ * used. So the media query has to name the device. Both orientations, because
91
+ * the query is on `orientation` too and a phone opened in landscape otherwise
92
+ * falls back to white.
93
+ *
94
+ * ── This list AGES, and that is the deal ────────────────────────────────────
95
+ * A device released after this list gets the old behaviour (white), never a
96
+ * broken one. Entries are CSS points at the stated DPR, portrait; the landscape
97
+ * link swaps them. Grouped by hardware generation rather than by marketing
98
+ * name, because several phones share a screen — `375×812@3` is the X, the XS,
99
+ * the 11 Pro, the 12 mini and the 13 mini.
100
+ *
101
+ * The BYTES are the reason this is worth checking before adding to it: 32 link
102
+ * tags is ~5KB of HTML on every page view. They are near-identical strings, so
103
+ * gzip takes them to a few hundred bytes — but that is a property of THIS
104
+ * shape, and a table that grows unboundedly would stop being free.
105
+ */
106
+ export declare const JUN_IOS_SCREENS: {
107
+ w: number;
108
+ h: number;
109
+ dpr: number;
110
+ }[];
111
+ /**
112
+ * The `<link rel="apple-touch-startup-image">` set, both orientations.
113
+ *
114
+ * The `href` is in DEVICE pixels (points × dpr) because that is the image; the
115
+ * media query is in POINTS because that is what iOS matches on.
116
+ */
117
+ export declare function junAppleSplashLinks(identity: JunIdentity): {
118
+ rel: string;
119
+ href: string;
120
+ media: string;
121
+ }[];
@@ -0,0 +1,115 @@
1
+ import { junMarkColorsFor, junMarkName } from "./junMark.js";
2
+ const HEX_RE = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;
3
+ const DEFAULT_THEME_COLOR = "#0e0f11";
4
+ const SHORT_NAME_MAX = 12;
5
+ function str(v) {
6
+ return typeof v === "string" && v.trim() ? v.trim() : void 0;
7
+ }
8
+ function hex(v, fallback) {
9
+ const s = str(v);
10
+ return s && HEX_RE.test(s) ? s : fallback;
11
+ }
12
+ export function junFingerprint(input) {
13
+ let h = 2166136261;
14
+ for (let i = 0; i < input.length; i++) {
15
+ h ^= input.charCodeAt(i);
16
+ h = Math.imul(h, 16777619) >>> 0;
17
+ }
18
+ return h.toString(36);
19
+ }
20
+ export function junIdentity(brand, cfg) {
21
+ const name = str(cfg.seoTitle) ?? str(brand?.name) ?? "Jun!s";
22
+ const description = str(cfg.seoDescription) ?? str(brand?.seoDescription) ?? str(brand?.tagline) ?? "";
23
+ const mark = junMarkName(cfg.brandLogo ?? brand?.logoMark, "sun");
24
+ const { light, dark } = junMarkColorsFor(cfg);
25
+ const themeColor = hex(brand?.themeColor, DEFAULT_THEME_COLOR);
26
+ const tile = hex(brand?.iconBackground, themeColor);
27
+ return {
28
+ name,
29
+ shortName: name.length <= SHORT_NAME_MAX ? name : name.slice(0, SHORT_NAME_MAX).trim(),
30
+ description,
31
+ mark,
32
+ light,
33
+ dark,
34
+ tile,
35
+ themeColor,
36
+ version: junFingerprint([
37
+ name,
38
+ mark,
39
+ tile,
40
+ themeColor,
41
+ light.ink,
42
+ light.sunFrom,
43
+ light.sunTo,
44
+ light.sunCore,
45
+ light.sunGlow,
46
+ dark.ink,
47
+ dark.sunFrom,
48
+ dark.sunTo,
49
+ dark.sunCore,
50
+ dark.sunGlow
51
+ ].join("|"))
52
+ };
53
+ }
54
+ export function junIconScale(mark, maskable = false) {
55
+ if (maskable) return mark === "sun" ? 0.72 : 0.56;
56
+ return mark === "sun" ? 1 : 0.8;
57
+ }
58
+ export function junIconUrls(identity) {
59
+ const v = identity.version;
60
+ return {
61
+ favicon: `/jun-icon.svg?v=${v}`,
62
+ appleTouch: `/apple-touch-icon.png?v=${v}`,
63
+ png: (size, maskable = false) => `/jun-icon.png?size=${size}&v=${v}${maskable ? "&maskable=1" : ""}`,
64
+ splash: (w, h) => `/jun-splash.png?w=${w}&h=${h}&v=${v}`
65
+ };
66
+ }
67
+ export const JUN_IOS_SCREENS = [
68
+ { w: 375, h: 667, dpr: 2 },
69
+ // SE (2nd/3rd), 6/7/8
70
+ { w: 414, h: 736, dpr: 3 },
71
+ // 8 Plus
72
+ { w: 375, h: 812, dpr: 3 },
73
+ // X, XS, 11 Pro, 12/13 mini
74
+ { w: 414, h: 896, dpr: 2 },
75
+ // XR, 11
76
+ { w: 414, h: 896, dpr: 3 },
77
+ // XS Max, 11 Pro Max
78
+ { w: 390, h: 844, dpr: 3 },
79
+ // 12, 12 Pro, 13, 13 Pro, 14
80
+ { w: 428, h: 926, dpr: 3 },
81
+ // 12/13 Pro Max, 14 Plus
82
+ { w: 393, h: 852, dpr: 3 },
83
+ // 14 Pro, 15, 15 Pro, 16
84
+ { w: 430, h: 932, dpr: 3 },
85
+ // 14 Pro Max, 15 Plus, 15/16 Pro Max
86
+ { w: 402, h: 874, dpr: 3 },
87
+ // 16 Pro
88
+ { w: 440, h: 956, dpr: 3 },
89
+ // 16 Pro Max
90
+ { w: 768, h: 1024, dpr: 2 },
91
+ // iPad, iPad mini (9.7"/7.9")
92
+ { w: 810, h: 1080, dpr: 2 },
93
+ // iPad 10.2"
94
+ { w: 820, h: 1180, dpr: 2 },
95
+ // iPad Air 10.9"/11"
96
+ { w: 834, h: 1194, dpr: 2 },
97
+ // iPad Pro 11"
98
+ { w: 1024, h: 1366, dpr: 2 }
99
+ // iPad Pro 12.9"/13"
100
+ ];
101
+ export function junAppleSplashLinks(identity) {
102
+ const url = junIconUrls(identity).splash;
103
+ return JUN_IOS_SCREENS.flatMap(({ w, h, dpr }) => [
104
+ {
105
+ rel: "apple-touch-startup-image",
106
+ href: url(w * dpr, h * dpr),
107
+ media: `(device-width:${w}px) and (device-height:${h}px) and (-webkit-device-pixel-ratio:${dpr}) and (orientation:portrait)`
108
+ },
109
+ {
110
+ rel: "apple-touch-startup-image",
111
+ href: url(h * dpr, w * dpr),
112
+ media: `(device-width:${w}px) and (device-height:${h}px) and (-webkit-device-pixel-ratio:${dpr}) and (orientation:landscape)`
113
+ }
114
+ ]);
115
+ }