rvlib-shipkit 2.27.0 → 2.28.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/CHANGELOG.md +16 -0
- package/package.json +1 -1
- package/src/agent-time/hooks.ts +10 -3
- package/src/agent-time/live.ts +11 -5
- package/src/agent-time/registry.ts +289 -0
- package/src/agent-time/store.ts +2 -2
- package/src/annex/born.ts +2 -2
- package/src/annex/offload.ts +12 -11
- package/src/asks/ask-after.ts +6 -2
- package/src/asks/ask-bar-fold.ts +57 -0
- package/src/asks/ask-migrate.ts +280 -0
- package/src/asks/ask-steps-fold.ts +166 -0
- package/src/asks/ask-store.ts +586 -0
- package/src/assets/kits/identity-kit.ts +106 -38
- package/src/assets/kits/poster-thumbnail.ts +282 -0
- package/src/checks/SK003-claude-md-shape.check.ts +92 -25
- package/src/checks/SK004-gitignore-policy.check.ts +8 -4
- package/src/checks/SK013-one-way-in-policy.check.ts +10 -0
- package/src/checks/SK026-asks-autoclose.check.ts +9 -23
- package/src/checks/SK038-speaks-as.check.ts +3 -3
- package/src/checks/SK042-post-kinds.check.ts +26 -24
- package/src/checks/SK049-thread-answers-hook.check.ts +81 -0
- package/src/checks/SK050-retired-commands.check.ts +127 -0
- package/src/cli/cmd_Asks.ts +204 -53
- package/src/cli/cmd_Backup.ts +151 -8
- package/src/cli/cmd_Calls.ts +1 -0
- package/src/cli/cmd_Commands.ts +140 -34
- package/src/cli/cmd_Contracts.ts +1 -0
- package/src/cli/cmd_Keys.ts +1 -0
- package/src/cli/cmd_Lanes.ts +15 -4
- package/src/cli/cmd_Messages.ts +152 -1
- package/src/cli/cmd_Needs.ts +1 -0
- package/src/cli/cmd_Review.ts +931 -229
- package/src/cli/cmd_Secret.ts +255 -34
- package/src/cli/cmd_Social.ts +36 -33
- package/src/cli/cmd_SocialDrafts.ts +235 -0
- package/src/cli/cmd_Sound.ts +22 -1
- package/src/cli/cmd_Start.ts +3 -2
- package/src/cli/cmd_ThreadHolds.ts +34 -0
- package/src/cli/cmd_ThreadKinds.ts +146 -0
- package/src/cli/cmd_ThreadReflect.ts +83 -0
- package/src/cli/cmd_ThreadSyncNeeds.ts +62 -0
- package/src/cli/cmd_Vault.ts +1 -1
- package/src/cli/cmd_When.ts +1 -0
- package/src/cli/family-help.ts +2 -2
- package/src/cli/family-pages.ts +1 -1
- package/src/cli/kit/builtins.ts +1 -0
- package/src/cli/kit/verb.ts +6 -2
- package/src/cli/registry.ts +21 -2
- package/src/cli.ts +5 -2
- package/src/collections/actions.ts +25 -74
- package/src/collections/collection-types.ts +9 -5
- package/src/collections/md-body.ts +5 -3
- package/src/collections/pings.ts +13 -6
- package/src/collections/providers.ts +53 -61
- package/src/collections/reflections.ts +9 -4
- package/src/core/discover-checks.ts +18 -3
- package/src/core/git.ts +31 -0
- package/src/core/house-layout.ts +17 -0
- package/src/core/layout.ts +10 -5
- package/src/core/locked-write.ts +4 -1
- package/src/core/machine-db.ts +5 -3
- package/src/core/migrate-layout.ts +8 -10
- package/src/home/activity.ts +8 -15
- package/src/home/daemon-jobs.ts +13 -1
- package/src/home/home-paths.ts +6 -3
- package/src/home/home-routes.ts +8 -0
- package/src/home/inbox-shape.ts +233 -100
- package/src/home/inbox.ts +26 -71
- package/src/home/machine-fold.ts +10 -15
- package/src/home/machine-host.ts +19 -1
- package/src/home/other-macs.ts +2 -2
- package/src/home/serve-web.ts +6 -5
- package/src/home/space-page.ts +1 -1
- package/src/home/vault-page.ts +51 -17
- package/src/home/vault-words.ts +2 -2
- package/src/hooks/one-way-in-guard.ts +24 -2
- package/src/hq/files-send.ts +27 -28
- package/src/hq/hq-db.ts +4 -1
- package/src/hq/hq-local.ts +37 -4
- package/src/hq/hq-routes.ts +10 -2
- package/src/hq/hq-store.ts +6 -2
- package/src/hq/kinds/ask.ts +6 -6
- package/src/hq/outbox.ts +5 -3
- package/src/hq/replica.ts +1 -2
- package/src/hq/vault-route.ts +112 -0
- package/src/identities/collection.ts +2 -2
- package/src/identities/identities.ts +9 -8
- package/src/identities/machine-route.ts +8 -3
- package/src/ledger/db.ts +8 -1
- package/src/media-store/backup/daemon.ts +48 -8
- package/src/media-store/backup/keys.ts +1 -1
- package/src/media-store/backup/manifest.ts +20 -2
- package/src/media-store/backup/prune.ts +365 -0
- package/src/media-store/backup/retention.ts +122 -0
- package/src/media-store/backup/run.ts +14 -8
- package/src/media-store/backup/sources.ts +18 -17
- package/src/media-store/backup/thread-copy.ts +340 -0
- package/src/media-store/copy/config.ts +3 -4
- package/src/media-store/copy/store.ts +2 -2
- package/src/media-store/db.ts +2 -2
- package/src/media-store/forget.ts +118 -0
- package/src/media-store/purge.ts +3 -2
- package/src/media-store/space-listing.ts +20 -4
- package/src/media-store/space.ts +6 -5
- package/src/messages/guard.ts +49 -0
- package/src/messages/model.ts +1 -1
- package/src/messages/objects.ts +201 -0
- package/src/messages/routes.ts +2 -2
- package/src/messages/score.ts +1 -1
- package/src/messages/write.ts +285 -0
- package/src/pages/frame-client.ts +181 -4
- package/src/reflections/reflections-queue.ts +1 -1
- package/src/release/gate-checkout.ts +2 -1
- package/src/release/git-facts.ts +3 -2
- package/src/release/public-clean.ts +3 -2
- package/src/repo-config.ts +40 -18
- package/src/review/anim.ts +1 -1
- package/src/review/answer-kinds.ts +131 -0
- package/src/review/band.ts +53 -0
- package/src/review/branch-hold.ts +84 -0
- package/src/review/card-db.ts +16 -6
- package/src/review/card-rows.ts +4 -3
- package/src/review/cells.ts +297 -65
- package/src/review/close.ts +92 -0
- package/src/review/draft-card.ts +8 -16
- package/src/review/draft-model.ts +2 -2
- package/src/review/events.ts +171 -0
- package/src/review/format.ts +128 -14
- package/src/review/glyphs.ts +63 -0
- package/src/review/gone.ts +1 -1
- package/src/review/holds-sync.ts +62 -0
- package/src/review/holds.ts +85 -0
- package/src/review/house-kind-defs.ts +41 -0
- package/src/review/inbox-hook.ts +22 -9
- package/src/review/inbox-read.ts +201 -0
- package/src/review/instructions.ts +199 -0
- package/src/review/kind-apply.ts +61 -0
- package/src/review/kind-catalog.ts +96 -0
- package/src/review/kinds.ts +278 -0
- package/src/review/lane-ask.ts +109 -0
- package/src/review/model.ts +396 -86
- package/src/review/move.ts +3 -3
- package/src/review/need-address.ts +15 -0
- package/src/review/need-threads.ts +93 -0
- package/src/review/object-card.ts +48 -0
- package/src/review/object-read.ts +31 -0
- package/src/review/owner-verdict.ts +36 -0
- package/src/review/parties.ts +182 -0
- package/src/review/previews.ts +3 -1
- package/src/review/projections.ts +235 -0
- package/src/review/referring.ts +54 -0
- package/src/review/reflection-object.ts +195 -0
- package/src/review/routes.ts +137 -32
- package/src/review/secret-route.ts +80 -0
- package/src/review/snooze.ts +38 -0
- package/src/review/stage-card.ts +4 -4
- package/src/review/store.ts +366 -85
- package/src/review/supersede.ts +116 -0
- package/src/review/take-back.ts +52 -0
- package/src/review/thread-fold.ts +20 -7
- package/src/review/threads.ts +236 -39
- package/src/review/traces.ts +218 -0
- package/src/review/trailer-card.ts +2 -2
- package/src/review/unit.ts +71 -5
- package/src/review/verdict-items.ts +73 -0
- package/src/review/verdict-write.ts +15 -0
- package/src/review/wait.ts +85 -0
- package/src/review/watchers.ts +22 -9
- package/src/scaffold/files/claude-settings-local.json +2 -0
- package/src/secrets/archive-mark.ts +52 -0
- package/src/secrets/archive.ts +83 -0
- package/src/secrets/copy.ts +14 -14
- package/src/secrets/keychain-write.ts +48 -0
- package/src/secrets/keychain.ts +8 -5
- package/src/secrets/lapse-mark.ts +33 -0
- package/src/secrets/lapse.ts +60 -0
- package/src/secrets/list.ts +16 -22
- package/src/secrets/manager.ts +31 -16
- package/src/secrets/read.ts +161 -33
- package/src/secrets/tail.ts +31 -0
- package/src/serve/hub-app/asks-page.tsx +2 -1
- package/src/serve/hub-app/auto-text.tsx +14 -6
- package/src/serve/hub-app/benign-errors.ts +15 -1
- package/src/serve/hub-app/card-head.tsx +49 -0
- package/src/serve/hub-app/check-view.tsx +3 -2
- package/src/serve/hub-app/code-copy.ts +35 -0
- package/src/serve/hub-app/col-card.tsx +31 -40
- package/src/serve/hub-app/col-list-page.tsx +5 -2
- package/src/serve/hub-app/col-tables-view.tsx +7 -4
- package/src/serve/hub-app/col-tables.ts +5 -5
- package/src/serve/hub-app/cols-svc.ts +4 -79
- package/src/serve/hub-app/commands/commands-page.tsx +2 -1
- package/src/serve/hub-app/controls.css +83 -0
- package/src/serve/hub-app/frames-st.ts +17 -1
- package/src/serve/hub-app/git-view.tsx +3 -2
- package/src/serve/hub-app/home-st.ts +57 -6
- package/src/serve/hub-app/home-strip.css +1 -6
- package/src/serve/hub-app/home-strip.tsx +2 -1
- package/src/serve/hub-app/home.html +3 -0
- package/src/serve/hub-app/house-wiki-view.tsx +20 -0
- package/src/serve/hub-app/hub-app.tsx +48 -32
- package/src/serve/hub-app/hub-types.ts +2 -0
- package/src/serve/hub-app/hub.css +50 -61
- package/src/serve/hub-app/icons.tsx +14 -4
- package/src/serve/hub-app/identities-view.tsx +4 -3
- package/src/serve/hub-app/inbox-st.ts +203 -42
- package/src/serve/hub-app/inbox-view.tsx +189 -101
- package/src/serve/hub-app/inbox.css +47 -44
- package/src/serve/hub-app/index.html +3 -0
- package/src/serve/hub-app/instructions.css +30 -0
- package/src/serve/hub-app/keys.ts +5 -3
- package/src/serve/hub-app/machine-st.ts +2 -2
- package/src/serve/hub-app/machines-view.tsx +4 -11
- package/src/serve/hub-app/machines.css +0 -9
- package/src/serve/hub-app/markdown.css +51 -0
- package/src/serve/hub-app/md-copy.tsx +18 -40
- package/src/serve/hub-app/md.ts +25 -9
- package/src/serve/hub-app/media-view.tsx +2 -2
- package/src/serve/hub-app/messages/messages-page.tsx +2 -1
- package/src/serve/hub-app/messages/messages-st.ts +1 -1
- package/src/serve/hub-app/messages.css +0 -1
- package/src/serve/hub-app/objects.css +51 -0
- package/src/serve/hub-app/page-keys.ts +1 -1
- package/src/serve/hub-app/pages-frames.tsx +11 -1
- package/src/serve/hub-app/palette-st.ts +4 -4
- package/src/serve/hub-app/pane-boundary.tsx +72 -0
- package/src/serve/hub-app/pane-errors.ts +54 -0
- package/src/serve/hub-app/plan-view.tsx +3 -2
- package/src/serve/hub-app/planned-view.tsx +3 -3
- package/src/serve/hub-app/planned.css +0 -4
- package/src/serve/hub-app/processes-view.tsx +3 -2
- package/src/serve/hub-app/project-list.css +5 -13
- package/src/serve/hub-app/project-list.tsx +3 -6
- package/src/serve/hub-app/projects-svc.ts +6 -2
- package/src/serve/hub-app/readme.css +9 -15
- package/src/serve/hub-app/reflections-page.tsx +54 -1
- package/src/serve/hub-app/releases/releases-page.tsx +3 -2
- package/src/serve/hub-app/releases.css +0 -1
- package/src/serve/hub-app/review/code-colors.ts +30 -0
- package/src/serve/hub-app/review/diff-view.tsx +75 -0
- package/src/serve/hub-app/review/dock.tsx +104 -0
- package/src/serve/hub-app/review/draft-card.tsx +2 -2
- package/src/serve/hub-app/review/group-block.tsx +209 -0
- package/src/serve/hub-app/review/instructions-view.tsx +116 -0
- package/src/serve/hub-app/review/item-verdict.tsx +38 -0
- package/src/serve/hub-app/review/kind-states.tsx +193 -0
- package/src/serve/hub-app/review/kind-view.tsx +1 -37
- package/src/serve/hub-app/review/kit.tsx +57 -54
- package/src/serve/hub-app/review/lane-bar.tsx +64 -0
- package/src/serve/hub-app/review/object-card.tsx +62 -0
- package/src/serve/hub-app/review/object-panel.tsx +179 -0
- package/src/serve/hub-app/review/question-views.tsx +385 -0
- package/src/serve/hub-app/review/review-cells.tsx +86 -105
- package/src/serve/hub-app/review/review-list.tsx +104 -47
- package/src/serve/hub-app/review/review-page.tsx +5 -4
- package/src/serve/hub-app/review/review-st.ts +68 -28
- package/src/serve/hub-app/review/review-thread.tsx +171 -40
- package/src/serve/hub-app/review/review-views.tsx +35 -31
- package/src/serve/hub-app/review/thread-close.tsx +124 -0
- package/src/serve/hub-app/review/thread-control.tsx +4 -4
- package/src/serve/hub-app/review/thread-st.ts +222 -22
- package/src/serve/hub-app/review/trailer-card.tsx +1 -1
- package/src/serve/hub-app/review/trailer-timeline.tsx +2 -2
- package/src/serve/hub-app/review.css +216 -57
- package/src/serve/hub-app/section-head.tsx +51 -0
- package/src/serve/hub-app/social/calendar.tsx +5 -11
- package/src/serve/hub-app/social/comms-page.tsx +23 -10
- package/src/serve/hub-app/social/kit.tsx +8 -15
- package/src/serve/hub-app/social/next-release.tsx +3 -5
- package/src/serve/hub-app/social/post-card.tsx +3 -0
- package/src/serve/hub-app/social/post-page.tsx +80 -0
- package/src/serve/hub-app/social/problems.tsx +5 -9
- package/src/serve/hub-app/social/social-model.ts +13 -5
- package/src/serve/hub-app/social/social-page.tsx +1 -1
- package/src/serve/hub-app/social/social-st.ts +42 -5
- package/src/serve/hub-app/social.css +7 -17
- package/src/serve/hub-app/space.css +1 -1
- package/src/serve/hub-app/stores/stores-page.tsx +6 -2
- package/src/serve/hub-app/thread-row.tsx +101 -0
- package/src/serve/hub-app/time-ago.tsx +3 -2
- package/src/serve/hub-app/time-view.tsx +2 -1
- package/src/serve/hub-app/time.css +2 -5
- package/src/serve/hub-app/tree-row.tsx +1 -9
- package/src/serve/hub-app/vault-view.tsx +4 -4
- package/src/serve/hub-app/veille/veille-page.tsx +2 -11
- package/src/serve/hub-app/veille.css +0 -1
- package/src/serve/hub-app/waiting-svc.ts +4 -4
- package/src/serve/hub-app/when-view.tsx +6 -3
- package/src/serve/hub-app/wiki-st.ts +30 -4
- package/src/serve/hub-app/wikis-view.tsx +4 -3
- package/src/serve/hub-runtime.ts +20 -6
- package/src/serve/project-gutter-route.ts +16 -6
- package/src/serve/project-gutter.ts +6 -53
- package/src/serve/same-origin.ts +3 -0
- package/src/serve/secret-gate.ts +21 -0
- package/src/serve/serve-hub.ts +29 -20
- package/src/serve/tailnet-caller.ts +117 -0
- package/src/shipkit.ts +2 -2
- package/src/site/desk.ts +2 -2
- package/src/smoke/run-smoke.ts +3 -4
- package/src/social/brands.ts +4 -0
- package/src/social/card-drafts.ts +11 -19
- package/src/social/desk-index.ts +34 -13
- package/src/social/drafts.ts +4 -4
- package/src/social/import-drafts.ts +244 -0
- package/src/social/kind-pages.ts +3 -3
- package/src/social/kinds.ts +1 -1
- package/src/social/load.ts +89 -64
- package/src/social/media-kind.ts +68 -161
- package/src/social/media-of.ts +5 -4
- package/src/social/open.ts +3 -2
- package/src/social/post-object.ts +120 -0
- package/src/social/post-sources.ts +136 -0
- package/src/social/post-text.ts +103 -0
- package/src/social/posts.ts +378 -0
- package/src/social/presence.ts +7 -5
- package/src/social/publish/index.ts +17 -5
- package/src/social/publish/secret.ts +2 -2
- package/src/social/release-stage.ts +58 -57
- package/src/social/routes.ts +64 -24
- package/src/social/stage.ts +42 -57
- package/src/social/text.ts +4 -3
- package/src/social/thumbnail.ts +135 -43
- package/src/social/tracker.ts +1 -1
- package/src/social/writes.ts +12 -29
- package/src/stores/desk.ts +16 -11
- package/src/stores/unit.ts +2 -2
- package/src/trailer/sound/eleven.ts +33 -3
- package/src/urls/rows.ts +1 -1
- package/src/vault/vault-http.ts +11 -3
- package/src/vault/vault-import.ts +6 -1
- package/src/veille/identity.ts +2 -2
- package/src/wiki/graph-pages.ts +13 -1
- package/src/wiki/scan-md.ts +1 -1
- package/src/asks/asks-queue.ts +0 -424
- package/src/messages/suggest.ts +0 -96
- package/src/social/migrate.ts +0 -123
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// (renderReleaseCard) is the same brand drawn for a release post, rendered
|
|
15
15
|
// on demand, never committed here.
|
|
16
16
|
import { createCanvas, loadImage, type Image, type SKRSContext2D } from '@napi-rs/canvas'
|
|
17
|
-
import { mkdirSync } from 'fs'
|
|
17
|
+
import { mkdirSync, statSync } from 'fs'
|
|
18
18
|
import { dirname, join } from 'path'
|
|
19
19
|
import sharp from 'sharp'
|
|
20
20
|
import { defineKind, type CanvasGen, type ComfyGen, type Kind } from '../kit-config.ts'
|
|
@@ -46,6 +46,21 @@ export type Brand = {
|
|
|
46
46
|
* its sound section (`comfy`, `elevenKey`, `voice`, `voices`) makes the
|
|
47
47
|
* voice, sfx and music lines (trailer/sound/brand.ts) */
|
|
48
48
|
trailer?: TrailerLookInput & TrailerSoundInput
|
|
49
|
+
/** the recipe every video thumbnail of the repo starts from, a flag of `sk social thumbnail` winning over each
|
|
50
|
+
* field: a game keeps its poster here (its lettering, its figures, its studio), so its videos look one family.
|
|
51
|
+
* Paths from the repo root; a figure `<png>:flip` is mirrored */
|
|
52
|
+
thumbnail?: BrandThumbnail
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type BrandThumbnail = {
|
|
56
|
+
layout?: 'card' | 'poster'
|
|
57
|
+
place?: 'left' | 'right' | 'center'
|
|
58
|
+
wordmark?: string
|
|
59
|
+
figures?: readonly string[]
|
|
60
|
+
studio?: string
|
|
61
|
+
tags?: readonly string[]
|
|
62
|
+
line?: string
|
|
63
|
+
badge?: string
|
|
49
64
|
}
|
|
50
65
|
|
|
51
66
|
export const FAVICON_SIZE = 512
|
|
@@ -171,12 +186,33 @@ export type ReleaseCard = {
|
|
|
171
186
|
/** the brand's mark as an image: `markFile` when given (the rendered logo.png, or a comfy mark's pick), else a canvas
|
|
172
187
|
* mark draws itself. The file comes first because a brand.ts loads its own @napi-rs/canvas from its repo, and an
|
|
173
188
|
* image of one copy does not draw on a canvas of the other */
|
|
189
|
+
/** each mark drawn or read once: every asset of a kit (logo, card, thumbnail) draws it, and a draw and png encode of
|
|
190
|
+
* the 1024 px mark costs about 100 ms. A drawn mark is keyed by its mark object, a file by its path, time and size */
|
|
191
|
+
const drawnMarks = new WeakMap<object, Promise<Buffer>>()
|
|
192
|
+
const fileMarks = new Map<string, Promise<Buffer>>()
|
|
193
|
+
function kept<K>(cache: { get(k: K): Promise<Buffer> | undefined; set(k: K, v: Promise<Buffer>): unknown; delete(k: K): unknown }, key: K, make: () => Promise<Buffer>): Promise<Buffer> {
|
|
194
|
+
const held = cache.get(key)
|
|
195
|
+
if (held != null) return held
|
|
196
|
+
const made = make()
|
|
197
|
+
cache.set(key, made)
|
|
198
|
+
made.catch(() => cache.delete(key))
|
|
199
|
+
return made
|
|
200
|
+
}
|
|
201
|
+
|
|
174
202
|
async function markPng(brand: Brand, markFile: string | undefined): Promise<Buffer> {
|
|
175
|
-
if (markFile != null)
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
return
|
|
203
|
+
if (markFile != null) {
|
|
204
|
+
const st = statSync(markFile, { throwIfNoEntry: false })
|
|
205
|
+
// a missing file goes to sharp, whose refusal names it
|
|
206
|
+
if (st == null) return sharp(markFile).png().toBuffer()
|
|
207
|
+
return kept(fileMarks, `${markFile}\0${st.mtimeMs}\0${st.size}`, () => sharp(markFile).png().toBuffer())
|
|
208
|
+
}
|
|
209
|
+
const mark = brand.mark
|
|
210
|
+
if (mark.backend === 'canvas') {
|
|
211
|
+
return kept(drawnMarks, mark, async () => {
|
|
212
|
+
const c = createCanvas(LOGO_SIZE, LOGO_SIZE)
|
|
213
|
+
await mark.draw(c.getContext('2d'), { id: 'identity-logo', prompt: '' })
|
|
214
|
+
return c.toBuffer('image/png')
|
|
215
|
+
})
|
|
180
216
|
}
|
|
181
217
|
throw new Error(`brand '${brand.name}' uses a comfy mark and no roll is picked — ${NO_PICK_FIX}`)
|
|
182
218
|
}
|
|
@@ -213,7 +249,7 @@ async function houseFace(family: string, weight: number): Promise<string | null>
|
|
|
213
249
|
|
|
214
250
|
/** the display face as a canvas font at a size: the trailer's face (its file, a family the machine has, else that
|
|
215
251
|
* Google Fonts family, as the trailer draws it), else `house` (a Google Fonts face), else the og card's fonts in bold */
|
|
216
|
-
async function displayFace(brand: Brand, root: string, house?: { family: string; weight: number }): Promise<(px: number) => string> {
|
|
252
|
+
export async function displayFace(brand: Brand, root: string, house?: { family: string; weight: number }): Promise<(px: number) => string> {
|
|
217
253
|
const f = brand.trailer?.font
|
|
218
254
|
const weight = f?.weight ?? house?.weight ?? 900
|
|
219
255
|
if (f?.file) {
|
|
@@ -347,7 +383,7 @@ export type Rect = { x: number; y: number; w: number; h: number }
|
|
|
347
383
|
export type Point = [number, number]
|
|
348
384
|
export type ThumbnailLayout = {
|
|
349
385
|
mark: Rect | null
|
|
350
|
-
title: Rect & { px: number }
|
|
386
|
+
title: Rect & { px: number; lines: string[] }
|
|
351
387
|
line: (Rect & { px: number }) | null
|
|
352
388
|
chip: (Rect & { px: number }) | null
|
|
353
389
|
/** the frame's card before its tilt, and its four corners once tilted */
|
|
@@ -372,11 +408,33 @@ const largest = (text: string, role: keyof typeof SIZES, maxW: number, measure:
|
|
|
372
408
|
|
|
373
409
|
/** a thumbnail's text that does not fit at its smallest size; `flag` names the text */
|
|
374
410
|
export class TooLong extends Error {
|
|
375
|
-
constructor(readonly flag: 'title' | 'line' | 'chip' | 'badge', message: string) {
|
|
411
|
+
constructor(readonly flag: 'title' | 'line' | 'chip' | 'badge' | 'tag', message: string) {
|
|
376
412
|
super(message)
|
|
377
413
|
}
|
|
378
414
|
}
|
|
379
415
|
|
|
416
|
+
/** a name's line pitch, a share of its size */
|
|
417
|
+
export const TITLE_LEADING = 1.04
|
|
418
|
+
|
|
419
|
+
/** `text` at the largest size from `from` down to `to` that fits `maxW` on one line; else, a text of words, on two
|
|
420
|
+
* lines split where the longer one is shortest; null past the smallest size */
|
|
421
|
+
export function fitLines(text: string, [from, to]: readonly [number, number], maxW: number, width: (s: string, px: number) => number): { px: number; w: number; lines: string[] } | null {
|
|
422
|
+
for (let px = from; px >= to; px -= 2) {
|
|
423
|
+
const w = width(text, px)
|
|
424
|
+
if (w <= maxW) return { px, w, lines: [text] }
|
|
425
|
+
}
|
|
426
|
+
const words = text.trim().split(/\s+/)
|
|
427
|
+
const splits = words.slice(1).map((_, i) => [words.slice(0, i + 1).join(' '), words.slice(i + 1).join(' ')])
|
|
428
|
+
for (let px = from; px >= to; px -= 2) {
|
|
429
|
+
const best = splits.map((lines) => ({ lines, w: Math.max(...lines.map((l) => width(l, px))) })).sort((a, b) => a.w - b.w)[0]
|
|
430
|
+
if (best && best.w <= maxW) return { px, ...best }
|
|
431
|
+
}
|
|
432
|
+
return null
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/** the height a name's lines take at their size */
|
|
436
|
+
export const titleHeight = (px: number, lines: number): number => Math.round(px * (1 + (lines - 1) * TITLE_LEADING))
|
|
437
|
+
|
|
380
438
|
const tooLong = (flag: TooLong['flag'], text: string, role: keyof typeof SIZES, maxW: number, measure: Measure, pad = 0): TooLong =>
|
|
381
439
|
new TooLong(flag, `--${flag} "${text}" does not fit a thumbnail: at ${SIZES[role][1]} px it takes ${Math.round(measure(text, role, SIZES[role][1]) + pad)} px of the ${Math.round(maxW)} its place has; say it shorter`)
|
|
382
440
|
|
|
@@ -396,8 +454,9 @@ export function thumbnailLayout(a: { title: string; line?: string; chip?: string
|
|
|
396
454
|
return [cx + x * cos - y * sin, T.cardY + x * sin + y * cos]
|
|
397
455
|
})
|
|
398
456
|
const maxW = Math.min(...corners.map((c) => c[0])) - T.gap - T.left
|
|
399
|
-
const title =
|
|
457
|
+
const title = fitLines(a.title, SIZES.title, maxW, (s, px) => a.measure(s, 'title', px))
|
|
400
458
|
if (!title) throw tooLong('title', a.title, 'title', maxW, a.measure)
|
|
459
|
+
const titleH = titleHeight(title.px, title.lines.length)
|
|
401
460
|
const line = a.line ? largest(a.line, 'line', maxW, a.measure) : null
|
|
402
461
|
if (a.line && !line) throw tooLong('line', a.line, 'line', maxW, a.measure)
|
|
403
462
|
const chip = a.chip ? largest(a.chip, 'chip', maxW, a.measure, 2 * T.chipPad) : null
|
|
@@ -405,22 +464,16 @@ export function thumbnailLayout(a: { title: string; line?: string; chip?: string
|
|
|
405
464
|
const mk = a.mark ? Math.min(T.markW / a.mark.w, T.markH / a.mark.h) : 0
|
|
406
465
|
const markH = a.mark ? a.mark.h * mk : 0
|
|
407
466
|
const chipH = chip ? Math.round(chip.px * 1.25) + 24 : 0
|
|
408
|
-
const parts = [markH ? markH + 22 : 0,
|
|
467
|
+
const parts = [markH ? markH + 22 : 0, titleH, line ? 18 + Math.round(line.px * 1.1) : 0, chip ? 40 + chipH : 0]
|
|
409
468
|
let y = Math.max(40, T.cardY - parts.reduce((s, p) => s + p, 0) / 2)
|
|
410
469
|
const mark = a.mark ? { x: T.left, y, w: a.mark.w * mk, h: markH } : null
|
|
411
470
|
y += parts[0]!
|
|
412
|
-
const titleR = { x: T.left, y, w: title.w, h: title.px,
|
|
413
|
-
y +=
|
|
471
|
+
const titleR = { x: T.left, y, w: title.w, h: titleH, px: title.px, lines: title.lines }
|
|
472
|
+
y += titleH
|
|
414
473
|
const lineR = line ? { x: T.left, y: y + 18, w: line.w, h: Math.round(line.px * 1.1), px: line.px } : null
|
|
415
474
|
y += parts[2]!
|
|
416
475
|
const chipR = chip ? { x: T.left, y: y + 40, w: chip.w, h: chipH, px: chip.px } : null
|
|
417
|
-
|
|
418
|
-
if (a.badge) {
|
|
419
|
-
const room = 2 * (T.ribbon - T.band / 2)
|
|
420
|
-
const b = largest(a.badge.toUpperCase(), 'badge', room, a.measure)
|
|
421
|
-
if (!b) throw tooLong('badge', a.badge, 'badge', room, a.measure)
|
|
422
|
-
badge = { px: b.px, at: [THUMB_W - T.ribbon / Math.SQRT2, T.ribbon / Math.SQRT2], band: T.band }
|
|
423
|
-
}
|
|
476
|
+
const badge = a.badge ? ribbonLayout(a.badge, (s, px) => a.measure(s, 'badge', px)) : null
|
|
424
477
|
return { mark, title: titleR, line: lineR, chip: chipR, card: { x: cx - cw / 2, y: T.cardY - ch / 2, w: cw, h: ch, angle: T.tilt, corners }, badge }
|
|
425
478
|
}
|
|
426
479
|
|
|
@@ -544,7 +597,7 @@ export async function renderThumbnail(brand: Brand, root: string, t: ThumbnailCa
|
|
|
544
597
|
ctx.fillText(s, at.x, at.y + at.px * base)
|
|
545
598
|
ctx.restore()
|
|
546
599
|
}
|
|
547
|
-
text(
|
|
600
|
+
L.title.lines.forEach((l, i) => text(l, 'title', { ...L.title, y: L.title.y + i * L.title.px * TITLE_LEADING }, ink, 0.86))
|
|
548
601
|
if (line && L.line) text(line, 'line', L.line, accent, 0.9)
|
|
549
602
|
if (chip && L.chip) {
|
|
550
603
|
const p = L.chip
|
|
@@ -561,25 +614,40 @@ export async function renderThumbnail(brand: Brand, root: string, t: ThumbnailCa
|
|
|
561
614
|
ctx.fillText(chip, p.x + T.chipPad, p.y + p.h / 2 + 1)
|
|
562
615
|
}
|
|
563
616
|
if (badge && L.badge) {
|
|
564
|
-
|
|
565
|
-
ctx.
|
|
566
|
-
ctx.translate(b.at[0], b.at[1])
|
|
567
|
-
ctx.rotate(Math.PI / 4)
|
|
568
|
-
ctx.shadowColor = 'rgba(0,0,0,0.45)'
|
|
569
|
-
ctx.shadowBlur = 16
|
|
570
|
-
ctx.shadowOffsetY = 4
|
|
571
|
-
ctx.fillStyle = accent
|
|
572
|
-
ctx.fillRect(-THUMB_W / 2, -b.band / 2, THUMB_W, b.band)
|
|
573
|
-
ctx.shadowColor = 'transparent'
|
|
574
|
-
font('badge', b.px)
|
|
575
|
-
ctx.fillStyle = bg
|
|
576
|
-
ctx.textAlign = 'center'
|
|
577
|
-
ctx.textBaseline = 'middle'
|
|
578
|
-
ctx.fillText(badge.toUpperCase(), 0, 1)
|
|
579
|
-
ctx.restore()
|
|
617
|
+
font('badge', L.badge.px)
|
|
618
|
+
drawRibbon(ctx, badge, L.badge, accent, bg)
|
|
580
619
|
}
|
|
620
|
+
return thumbnailJpg(ctx)
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/** the ribbon across the top right corner, its word in capitals, in the font already set */
|
|
624
|
+
export function drawRibbon(ctx: SKRSContext2D, word: string, b: NonNullable<ThumbnailLayout['badge']>, fill: string, ink: string): void {
|
|
625
|
+
ctx.save()
|
|
626
|
+
ctx.translate(b.at[0], b.at[1])
|
|
627
|
+
ctx.rotate(Math.PI / 4)
|
|
628
|
+
ctx.shadowColor = 'rgba(0,0,0,0.45)'
|
|
629
|
+
ctx.shadowBlur = 16
|
|
630
|
+
ctx.shadowOffsetY = 4
|
|
631
|
+
ctx.fillStyle = fill
|
|
632
|
+
ctx.fillRect(-THUMB_W / 2, -b.band / 2, THUMB_W, b.band)
|
|
633
|
+
ctx.shadowColor = 'transparent'
|
|
634
|
+
ctx.fillStyle = ink
|
|
635
|
+
ctx.textAlign = 'center'
|
|
636
|
+
ctx.textBaseline = 'middle'
|
|
637
|
+
ctx.fillText(word.toUpperCase(), 0, 1)
|
|
638
|
+
ctx.restore()
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
/** where the ribbon goes and its word's size, or a TooLong */
|
|
642
|
+
export function ribbonLayout(word: string, measure: (s: string, px: number) => number): NonNullable<ThumbnailLayout['badge']> {
|
|
643
|
+
const room = 2 * (T.ribbon - T.band / 2)
|
|
644
|
+
const b = fitLines(word.toUpperCase(), SIZES.badge, room, measure)
|
|
645
|
+
if (!b || b.lines.length > 1) throw new TooLong('badge', `--badge "${word}" does not fit the ribbon: say it shorter`)
|
|
646
|
+
return { px: b.px, at: [THUMB_W - T.ribbon / Math.SQRT2, T.ribbon / Math.SQRT2], band: T.band }
|
|
647
|
+
}
|
|
581
648
|
|
|
582
|
-
|
|
649
|
+
/** the canvas as a jpg under YouTube's 2 MB, from the raw pixels: mozjpeg would save a few percent for ten times the encode */
|
|
650
|
+
export async function thumbnailJpg(ctx: SKRSContext2D): Promise<Buffer> {
|
|
583
651
|
const raw = sharp(Buffer.from(ctx.getImageData(0, 0, THUMB_W, THUMB_H).data.buffer), { raw: { width: THUMB_W, height: THUMB_H, channels: 4 } }).removeAlpha()
|
|
584
652
|
for (let q = 88; ; q -= 6) {
|
|
585
653
|
const jpg = await raw.clone().jpeg({ quality: q, chromaSubsampling: q >= 82 ? '4:4:4' : '4:2:0' }).toBuffer()
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
// the poster thumbnail (wiki tools/generate-assets/index.md, The thumbnail, the poster): the frame of the world fills the
|
|
2
|
+
// picture, a soft shade on the side the words take, the name huge (or the game's own lettering), a line, a row of
|
|
3
|
+
// labels, the figures cut out on the other side with a warm rim of light, the ribbon, the studio's mark in a free
|
|
4
|
+
// corner. The game's recipe: a viewer reads WHAT it is from the world and its characters, never from a screenshot card.
|
|
5
|
+
// The one constraint: a figure never stands on the words' side, so `place center` takes none
|
|
6
|
+
import { createCanvas, loadImage, type Image } from '@napi-rs/canvas'
|
|
7
|
+
import sharp from 'sharp'
|
|
8
|
+
import { alpha, darker, lifted, mixed } from '../../trailer/look.ts'
|
|
9
|
+
import { displayFace, drawRibbon, fitLines, ribbonLayout, THUMB_H, THUMB_W, thumbnailJpg, TITLE_LEADING, titleHeight, TooLong, type Brand, type Rect } from './identity-kit.ts'
|
|
10
|
+
|
|
11
|
+
export type Place = 'left' | 'right' | 'center'
|
|
12
|
+
export type Size = { w: number; h: number }
|
|
13
|
+
/** a text's drawn width at a size, in the face and spacing its role takes */
|
|
14
|
+
export type PosterMeasure = (text: string, role: 'title' | 'line' | 'tag', px: number) => number
|
|
15
|
+
|
|
16
|
+
export type PosterLayout = {
|
|
17
|
+
place: Place
|
|
18
|
+
/** a wordmark's box (no lines), or the name's lines centred in it */
|
|
19
|
+
title: Rect & { px: number; lines: string[] }
|
|
20
|
+
line: (Rect & { px: number }) | null
|
|
21
|
+
tags: (Rect & { px: number; text: string })[]
|
|
22
|
+
/** in the order drawn, the ones behind first; `index` into the figures given */
|
|
23
|
+
figures: (Rect & { index: number })[]
|
|
24
|
+
studio: Rect | null
|
|
25
|
+
/** the words' column, its centre and width */
|
|
26
|
+
column: { cx: number; w: number }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const M = 48
|
|
30
|
+
const SIZES = { title: [150, 72], line: [48, 28], tag: [26, 18] } as const
|
|
31
|
+
/** a figure's spot in the free side: `u` from the words' edge (0) to the far edge (1), its box as shares of the side's
|
|
32
|
+
* width and the picture's height, its feet as a share of the height */
|
|
33
|
+
type Spot = { u: number; w: number; h: number; feet: number }
|
|
34
|
+
/** one alone, large; two side by side, the first in front; three, the first in the middle and in front, larger */
|
|
35
|
+
const SPOTS: Record<number, { order: number[]; spots: Spot[] }> = {
|
|
36
|
+
1: { order: [0], spots: [{ u: 0.5, w: 1, h: 0.96, feet: 1 }] },
|
|
37
|
+
2: { order: [1, 0], spots: [{ u: 0.28, w: 0.54, h: 0.78, feet: 1 }, { u: 0.76, w: 0.5, h: 0.72, feet: 0.97 }] },
|
|
38
|
+
3: { order: [1, 2, 0], spots: [{ u: 0.5, w: 0.56, h: 0.78, feet: 1 }, { u: 0.18, w: 0.4, h: 0.56, feet: 0.94 }, { u: 0.84, w: 0.4, h: 0.56, feet: 0.94 }] },
|
|
39
|
+
}
|
|
40
|
+
const STUDIO = { w: 120, h: 72, margin: 24 }
|
|
41
|
+
|
|
42
|
+
const one = (flag: TooLong['flag'], text: string, sizes: readonly [number, number], maxW: number, width: (s: string, px: number) => number): { px: number; w: number } => {
|
|
43
|
+
for (let px = sizes[0]; px >= sizes[1]; px -= 2) {
|
|
44
|
+
const w = width(text, px)
|
|
45
|
+
if (w <= maxW) return { px, w }
|
|
46
|
+
}
|
|
47
|
+
throw new TooLong(flag, `--${flag} "${text}" does not fit a thumbnail: at ${sizes[1]} px it takes ${Math.round(width(text, sizes[1]))} px of the ${Math.round(maxW)} its place has; say it shorter`)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** where each part of a poster goes; throws on a text past its smallest size and on a figure with no free side */
|
|
51
|
+
export function posterLayout(a: { title: string; line?: string; tags?: readonly string[]; place: Place; wordmark: Size | null; figures: readonly Size[]; studio: Size | null; measure: PosterMeasure }): PosterLayout {
|
|
52
|
+
const n = a.figures.length
|
|
53
|
+
if (n > 0 && a.place === 'center') throw new Error('a figure needs --place left or right: the words take one side, the figures the other')
|
|
54
|
+
if (n > 3) throw new Error(`${n} figures: three at most stand on the free side`)
|
|
55
|
+
const cx = a.place === 'left' ? THUMB_W * 0.29 : a.place === 'right' ? THUMB_W * 0.71 : THUMB_W / 2
|
|
56
|
+
const colW = a.place === 'center' ? THUMB_W * 0.78 : THUMB_W * 0.5
|
|
57
|
+
const line = a.line ? one('line', a.line, SIZES.line, colW, (s, px) => a.measure(s, 'line', px)) : null
|
|
58
|
+
const lineH = line ? Math.round(line.px * 1.2) : 0
|
|
59
|
+
const tags = a.tags ?? []
|
|
60
|
+
let tagPx = 0
|
|
61
|
+
const pillW = (t: string, px: number): number => a.measure(t, 'tag', px) + px * 1.6
|
|
62
|
+
for (let px = SIZES.tag[0]; px >= SIZES.tag[1] && tags.length > 0; px -= 2) {
|
|
63
|
+
const total = tags.reduce((s, t) => s + pillW(t, px), 0) + px * 0.6 * (tags.length - 1)
|
|
64
|
+
if (total <= colW && tags.every((t) => pillW(t, px) <= colW * 0.6)) {
|
|
65
|
+
tagPx = px
|
|
66
|
+
break
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (tags.length > 0 && tagPx === 0) {
|
|
70
|
+
const longest = [...tags].sort((x, y) => y.length - x.length)[0]!
|
|
71
|
+
throw new TooLong('tag', `--tag "${longest}" does not fit a thumbnail beside its labels: say it shorter`)
|
|
72
|
+
}
|
|
73
|
+
const tagH = tagPx ? Math.round(tagPx * 1.75) : 0
|
|
74
|
+
const rest = (line ? 16 + lineH : 0) + (tagH ? 26 + tagH : 0)
|
|
75
|
+
// the studio's corner: the free side when nothing stands there, else under the words, which then stop above it
|
|
76
|
+
const studioLow = a.studio && n > 0 ? STUDIO.h + STUDIO.margin + 12 : 0
|
|
77
|
+
const room = THUMB_H - 2 * M - studioLow
|
|
78
|
+
let title: { w: number; h: number; px: number; lines: string[] }
|
|
79
|
+
if (a.wordmark) {
|
|
80
|
+
const k = Math.min(colW / a.wordmark.w, Math.min(THUMB_H * 0.62, room - rest) / a.wordmark.h)
|
|
81
|
+
title = { w: a.wordmark.w * k, h: a.wordmark.h * k, px: 0, lines: [] }
|
|
82
|
+
} else {
|
|
83
|
+
const t = fitLines(a.title, SIZES.title, colW, (s, px) => a.measure(s, 'title', px))
|
|
84
|
+
if (!t) throw new TooLong('title', `--title "${a.title}" does not fit a thumbnail, even on two lines at ${SIZES.title[1]} px: say it shorter`)
|
|
85
|
+
title = { w: t.w, h: titleHeight(t.px, t.lines.length), px: t.px, lines: t.lines }
|
|
86
|
+
}
|
|
87
|
+
const stack = title.h + rest
|
|
88
|
+
let y = Math.min(Math.max(M, THUMB_H * 0.47 - stack / 2), THUMB_H - M - studioLow - stack)
|
|
89
|
+
const titleR = { x: cx - title.w / 2, y, ...title }
|
|
90
|
+
y += title.h
|
|
91
|
+
const lineR = line ? { x: cx - line.w / 2, y: y + 16, w: line.w, h: lineH, px: line.px } : null
|
|
92
|
+
y += line ? 16 + lineH : 0
|
|
93
|
+
const tagRs: PosterLayout['tags'] = []
|
|
94
|
+
if (tagPx) {
|
|
95
|
+
const total = tags.reduce((s, t) => s + pillW(t, tagPx), 0) + tagPx * 0.6 * (tags.length - 1)
|
|
96
|
+
let x = cx - total / 2
|
|
97
|
+
for (const t of tags) {
|
|
98
|
+
const w = pillW(t, tagPx)
|
|
99
|
+
tagRs.push({ x, y: y + 26, w, h: tagH, px: tagPx, text: t })
|
|
100
|
+
x += w + tagPx * 0.6
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// the free side, from the words' edge to the far edge of the picture
|
|
104
|
+
const near = a.place === 'left' ? cx + colW / 2 + 12 : cx - colW / 2 - 12
|
|
105
|
+
const far = a.place === 'left' ? THUMB_W : 0
|
|
106
|
+
const Z = Math.abs(far - near)
|
|
107
|
+
const plan = SPOTS[n]
|
|
108
|
+
const figures: PosterLayout['figures'] = plan
|
|
109
|
+
? plan.order.map((i) => {
|
|
110
|
+
const s = plan.spots[i]!
|
|
111
|
+
const f = a.figures[i]!
|
|
112
|
+
const k = Math.min((s.w * Z) / f.w, (s.h * THUMB_H) / f.h)
|
|
113
|
+
const w = f.w * k
|
|
114
|
+
const h = f.h * k
|
|
115
|
+
const mid = near + Math.sign(far - near) * s.u * Z
|
|
116
|
+
const lo = Math.min(near, far)
|
|
117
|
+
const x = Math.min(Math.max(mid - w / 2, lo), lo + Z - w)
|
|
118
|
+
return { x, y: s.feet * THUMB_H - h, w, h, index: i }
|
|
119
|
+
})
|
|
120
|
+
: []
|
|
121
|
+
let studio: Rect | null = null
|
|
122
|
+
if (a.studio) {
|
|
123
|
+
const k = Math.min(STUDIO.w / a.studio.w, STUDIO.h / a.studio.h)
|
|
124
|
+
const w = a.studio.w * k
|
|
125
|
+
const h = a.studio.h * k
|
|
126
|
+
const wordsLeft = a.place !== 'right'
|
|
127
|
+
const left = n > 0 ? wordsLeft : !wordsLeft
|
|
128
|
+
studio = { x: left ? STUDIO.margin : THUMB_W - STUDIO.margin - w, y: THUMB_H - STUDIO.margin - h, w, h }
|
|
129
|
+
}
|
|
130
|
+
return { place: a.place, title: titleR, line: lineR, tags: tagRs, figures, studio, column: { cx, w: colW } }
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** what a poster draws: the frame of the world, the words, and the pictures that stand in it */
|
|
134
|
+
export type PosterCard = {
|
|
135
|
+
title: string
|
|
136
|
+
line?: string
|
|
137
|
+
tags?: readonly string[]
|
|
138
|
+
badge?: string
|
|
139
|
+
place?: Place
|
|
140
|
+
/** the world, any size: it covers the picture, centred */
|
|
141
|
+
frame: Buffer
|
|
142
|
+
/** the name as a picture, the game's own lettering, drawn in place of the name's words */
|
|
143
|
+
wordmark?: Buffer
|
|
144
|
+
/** cut outs (a png with alpha), trimmed to their pixels; `flip` mirrors one to turn it toward the words */
|
|
145
|
+
figures?: readonly { image: Buffer; flip?: boolean }[]
|
|
146
|
+
/** the studio's mark, small, in a free bottom corner */
|
|
147
|
+
studio?: Buffer
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const trimmed = async (png: Buffer): Promise<Image> => loadImage(await sharp(png).rotate().trim({ threshold: 10 }).png().toBuffer().catch(() => sharp(png).png().toBuffer()))
|
|
151
|
+
|
|
152
|
+
/** a poster thumbnail, 1280x720 jpg under YouTube's 2 MB, in the brand's ground, accent, ink and display face */
|
|
153
|
+
export async function renderPoster(brand: Brand, root: string, t: PosterCard): Promise<Buffer> {
|
|
154
|
+
const { bg, accent, ink } = brand.palette
|
|
155
|
+
const display = await displayFace(brand, root, { family: 'Inter', weight: 800 })
|
|
156
|
+
const c = createCanvas(THUMB_W, THUMB_H)
|
|
157
|
+
const ctx = c.getContext('2d')
|
|
158
|
+
const spacing = { title: -0.02, line: 0.14, tag: 0.18 } as const
|
|
159
|
+
const font = (role: keyof typeof spacing, px: number): void => {
|
|
160
|
+
ctx.font = display(px)
|
|
161
|
+
ctx.letterSpacing = `${Math.round(px * spacing[role] * 10) / 10}px`
|
|
162
|
+
}
|
|
163
|
+
const measure: PosterMeasure = (text, role, px) => {
|
|
164
|
+
font(role, px)
|
|
165
|
+
return ctx.measureText(text).width
|
|
166
|
+
}
|
|
167
|
+
const place = t.place ?? 'left'
|
|
168
|
+
const line = t.line?.trim().toUpperCase() || undefined
|
|
169
|
+
const tags = (t.tags ?? []).map((x) => x.trim().toUpperCase()).filter((x) => x !== '')
|
|
170
|
+
const [frame, wordmark, studio, ...figures] = await Promise.all([
|
|
171
|
+
loadImage(await sharp(t.frame).rotate().png().toBuffer()),
|
|
172
|
+
t.wordmark ? trimmed(t.wordmark) : null,
|
|
173
|
+
t.studio ? trimmed(t.studio) : null,
|
|
174
|
+
...(t.figures ?? []).map((f) => trimmed(f.image)),
|
|
175
|
+
])
|
|
176
|
+
const size = (i: Image | null): Size | null => (i ? { w: i.width, h: i.height } : null)
|
|
177
|
+
const L = posterLayout({ title: t.title.trim(), line, tags, place, wordmark: size(wordmark), figures: figures.map((f) => size(f)!), studio: size(studio), measure })
|
|
178
|
+
const ribbon = t.badge?.trim() ? ribbonLayout(t.badge.trim(), (s, px) => measure(s, 'tag', px)) : null
|
|
179
|
+
|
|
180
|
+
// the world covers the picture
|
|
181
|
+
const k = Math.max(THUMB_W / frame.width, THUMB_H / frame.height)
|
|
182
|
+
ctx.drawImage(frame, (THUMB_W - frame.width * k) / 2, (THUMB_H - frame.height * k) / 2, frame.width * k, frame.height * k)
|
|
183
|
+
// a soft shade where the words sit, so they read on any world; a light vignette round it
|
|
184
|
+
const shade = darker(bg, 0.35)
|
|
185
|
+
if (place === 'center') {
|
|
186
|
+
const g = ctx.createRadialGradient(L.column.cx, THUMB_H * 0.47, 0, L.column.cx, THUMB_H * 0.47, THUMB_W * 0.5)
|
|
187
|
+
g.addColorStop(0, alpha(shade, 0.62))
|
|
188
|
+
g.addColorStop(1, alpha(shade, 0))
|
|
189
|
+
ctx.fillStyle = g
|
|
190
|
+
} else {
|
|
191
|
+
const g = place === 'left' ? ctx.createLinearGradient(0, 0, THUMB_W * 0.64, 0) : ctx.createLinearGradient(THUMB_W, 0, THUMB_W * 0.36, 0)
|
|
192
|
+
g.addColorStop(0, alpha(shade, 0.86))
|
|
193
|
+
g.addColorStop(0.55, alpha(shade, 0.5))
|
|
194
|
+
g.addColorStop(1, alpha(shade, 0))
|
|
195
|
+
ctx.fillStyle = g
|
|
196
|
+
}
|
|
197
|
+
ctx.fillRect(0, 0, THUMB_W, THUMB_H)
|
|
198
|
+
const v = ctx.createRadialGradient(THUMB_W / 2, THUMB_H / 2, THUMB_H * 0.45, THUMB_W / 2, THUMB_H / 2, THUMB_W * 0.75)
|
|
199
|
+
v.addColorStop(0, alpha(shade, 0))
|
|
200
|
+
v.addColorStop(1, alpha(shade, 0.45))
|
|
201
|
+
ctx.fillStyle = v
|
|
202
|
+
ctx.fillRect(0, 0, THUMB_W, THUMB_H)
|
|
203
|
+
|
|
204
|
+
// the figures, a warm rim of light round each to part it from the world
|
|
205
|
+
const rim = alpha(mixed(lifted(ink, 0.2), accent, 0.3), 0.75)
|
|
206
|
+
for (const f of L.figures) {
|
|
207
|
+
const img = figures[f.index]!
|
|
208
|
+
ctx.save()
|
|
209
|
+
ctx.shadowColor = rim
|
|
210
|
+
ctx.shadowBlur = 28
|
|
211
|
+
if (t.figures?.[f.index]?.flip) {
|
|
212
|
+
ctx.translate(f.x + f.w, f.y)
|
|
213
|
+
ctx.scale(-1, 1)
|
|
214
|
+
ctx.drawImage(img, 0, 0, f.w, f.h)
|
|
215
|
+
} else ctx.drawImage(img, f.x, f.y, f.w, f.h)
|
|
216
|
+
ctx.restore()
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// the name: the lettering as it is, or the words outlined in the deep ground so they read at any size
|
|
220
|
+
if (wordmark) {
|
|
221
|
+
ctx.save()
|
|
222
|
+
ctx.shadowColor = 'rgba(0,0,0,0.55)'
|
|
223
|
+
ctx.shadowBlur = 30
|
|
224
|
+
ctx.shadowOffsetY = 10
|
|
225
|
+
ctx.drawImage(wordmark, L.title.x, L.title.y, L.title.w, L.title.h)
|
|
226
|
+
ctx.restore()
|
|
227
|
+
}
|
|
228
|
+
const words = (s: string, role: keyof typeof spacing, px: number, x: number, baseline: number, fill: string, outline: number): void => {
|
|
229
|
+
ctx.save()
|
|
230
|
+
font(role, px)
|
|
231
|
+
ctx.textAlign = 'center'
|
|
232
|
+
ctx.textBaseline = 'alphabetic'
|
|
233
|
+
ctx.lineJoin = 'round'
|
|
234
|
+
ctx.shadowColor = 'rgba(0,0,0,0.55)'
|
|
235
|
+
ctx.shadowBlur = px * 0.25
|
|
236
|
+
ctx.shadowOffsetY = px * 0.06
|
|
237
|
+
if (outline > 0) {
|
|
238
|
+
ctx.lineWidth = px * outline
|
|
239
|
+
ctx.strokeStyle = darker(bg, 0.55)
|
|
240
|
+
ctx.strokeText(s, x, baseline)
|
|
241
|
+
ctx.shadowColor = 'transparent'
|
|
242
|
+
}
|
|
243
|
+
ctx.fillStyle = fill
|
|
244
|
+
ctx.fillText(s, x, baseline)
|
|
245
|
+
ctx.restore()
|
|
246
|
+
}
|
|
247
|
+
L.title.lines.forEach((l, i) => words(l, 'title', L.title.px, L.column.cx, L.title.y + L.title.px * (0.86 + i * TITLE_LEADING), ink, 0.12))
|
|
248
|
+
if (line && L.line) words(line, 'line', L.line.px, L.column.cx, L.line.y + L.line.px * 0.92, ink, 0)
|
|
249
|
+
for (const p of L.tags) {
|
|
250
|
+
ctx.save()
|
|
251
|
+
ctx.shadowColor = 'rgba(0,0,0,0.5)'
|
|
252
|
+
ctx.shadowBlur = p.px * 0.6
|
|
253
|
+
ctx.shadowOffsetY = p.px * 0.15
|
|
254
|
+
const g = ctx.createLinearGradient(0, p.y, 0, p.y + p.h)
|
|
255
|
+
g.addColorStop(0, lifted(accent, 0.12))
|
|
256
|
+
g.addColorStop(1, darker(accent, 0.12))
|
|
257
|
+
ctx.fillStyle = g
|
|
258
|
+
ctx.beginPath()
|
|
259
|
+
ctx.roundRect(p.x, p.y, p.w, p.h, p.h / 2)
|
|
260
|
+
ctx.fill()
|
|
261
|
+
ctx.shadowColor = 'transparent'
|
|
262
|
+
font('tag', p.px)
|
|
263
|
+
ctx.fillStyle = darker(bg, 0.4)
|
|
264
|
+
ctx.textAlign = 'center'
|
|
265
|
+
ctx.textBaseline = 'middle'
|
|
266
|
+
// letter spacing trails the last letter: half of it back keeps the word centred
|
|
267
|
+
ctx.fillText(p.text, p.x + p.w / 2 + p.px * spacing.tag * 0.5, p.y + p.h / 2 + p.px * 0.06)
|
|
268
|
+
ctx.restore()
|
|
269
|
+
}
|
|
270
|
+
if (ribbon) {
|
|
271
|
+
font('tag', ribbon.px)
|
|
272
|
+
drawRibbon(ctx, t.badge!.trim(), ribbon, accent, darker(bg, 0.4))
|
|
273
|
+
}
|
|
274
|
+
if (studio && L.studio) {
|
|
275
|
+
ctx.save()
|
|
276
|
+
ctx.shadowColor = 'rgba(0,0,0,0.5)'
|
|
277
|
+
ctx.shadowBlur = 14
|
|
278
|
+
ctx.drawImage(studio, L.studio.x, L.studio.y, L.studio.w, L.studio.h)
|
|
279
|
+
ctx.restore()
|
|
280
|
+
}
|
|
281
|
+
return thumbnailJpg(ctx)
|
|
282
|
+
}
|