@softure-ai/marketing-kit 0.15.0 → 0.17.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 (108) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/README.md +138 -16
  3. package/dist/config/schema.d.ts +2 -1
  4. package/dist/config/schema.d.ts.map +1 -1
  5. package/dist/config/schema.js +7 -0
  6. package/dist/config/schema.js.map +1 -1
  7. package/dist/footage/clip-sound.d.ts +58 -0
  8. package/dist/footage/clip-sound.d.ts.map +1 -0
  9. package/dist/footage/clip-sound.js +103 -0
  10. package/dist/footage/clip-sound.js.map +1 -0
  11. package/dist/footage/declick.d.ts +1 -1
  12. package/dist/footage/declick.d.ts.map +1 -1
  13. package/dist/footage/declick.js +3 -4
  14. package/dist/footage/declick.js.map +1 -1
  15. package/dist/footage/draft.d.ts +19 -5
  16. package/dist/footage/draft.d.ts.map +1 -1
  17. package/dist/footage/draft.js +92 -22
  18. package/dist/footage/draft.js.map +1 -1
  19. package/dist/footage/elevenlabs.d.ts +5 -0
  20. package/dist/footage/elevenlabs.d.ts.map +1 -1
  21. package/dist/footage/elevenlabs.js +10 -3
  22. package/dist/footage/elevenlabs.js.map +1 -1
  23. package/dist/footage/failure.d.ts +12 -1
  24. package/dist/footage/failure.d.ts.map +1 -1
  25. package/dist/footage/failure.js +10 -1
  26. package/dist/footage/failure.js.map +1 -1
  27. package/dist/footage/fake.d.ts +10 -1
  28. package/dist/footage/fake.d.ts.map +1 -1
  29. package/dist/footage/fake.js +19 -4
  30. package/dist/footage/fake.js.map +1 -1
  31. package/dist/footage/hyperframes-capture.d.ts +30 -0
  32. package/dist/footage/hyperframes-capture.d.ts.map +1 -0
  33. package/dist/footage/hyperframes-capture.js +80 -0
  34. package/dist/footage/hyperframes-capture.js.map +1 -0
  35. package/dist/footage/isolate-ranges.d.ts +34 -6
  36. package/dist/footage/isolate-ranges.d.ts.map +1 -1
  37. package/dist/footage/isolate-ranges.js +90 -23
  38. package/dist/footage/isolate-ranges.js.map +1 -1
  39. package/dist/footage/loudness.d.ts +16 -2
  40. package/dist/footage/loudness.d.ts.map +1 -1
  41. package/dist/footage/loudness.js +10 -7
  42. package/dist/footage/loudness.js.map +1 -1
  43. package/dist/footage/paid.d.ts +12 -2
  44. package/dist/footage/paid.d.ts.map +1 -1
  45. package/dist/footage/paid.js +8 -3
  46. package/dist/footage/paid.js.map +1 -1
  47. package/dist/footage/pipeline.d.ts +14 -2
  48. package/dist/footage/pipeline.d.ts.map +1 -1
  49. package/dist/footage/pipeline.js +55 -46
  50. package/dist/footage/pipeline.js.map +1 -1
  51. package/dist/footage/providers.d.ts +5 -0
  52. package/dist/footage/providers.d.ts.map +1 -1
  53. package/dist/footage/providers.js.map +1 -1
  54. package/dist/footage/render.d.ts +1 -1
  55. package/dist/footage/render.d.ts.map +1 -1
  56. package/dist/footage/render.js +4 -3
  57. package/dist/footage/render.js.map +1 -1
  58. package/dist/footage/speech-ranges.d.ts +79 -11
  59. package/dist/footage/speech-ranges.d.ts.map +1 -1
  60. package/dist/footage/speech-ranges.js +137 -17
  61. package/dist/footage/speech-ranges.js.map +1 -1
  62. package/dist/index.d.ts +9 -6
  63. package/dist/index.d.ts.map +1 -1
  64. package/dist/index.js +8 -5
  65. package/dist/index.js.map +1 -1
  66. package/dist/og/index.d.ts +2 -0
  67. package/dist/og/index.d.ts.map +1 -1
  68. package/dist/og/index.js +2 -0
  69. package/dist/og/index.js.map +1 -1
  70. package/dist/og/photo-cover.d.ts +74 -0
  71. package/dist/og/photo-cover.d.ts.map +1 -0
  72. package/dist/og/photo-cover.js +357 -0
  73. package/dist/og/photo-cover.js.map +1 -0
  74. package/dist/og/photo.d.ts +51 -0
  75. package/dist/og/photo.d.ts.map +1 -0
  76. package/dist/og/photo.js +154 -0
  77. package/dist/og/photo.js.map +1 -0
  78. package/dist/voice/provider-failure.d.ts +41 -0
  79. package/dist/voice/provider-failure.d.ts.map +1 -0
  80. package/dist/voice/provider-failure.js +68 -0
  81. package/dist/voice/provider-failure.js.map +1 -0
  82. package/dist/voice/provider.d.ts +7 -1
  83. package/dist/voice/provider.d.ts.map +1 -1
  84. package/dist/voice/provider.js +1 -1
  85. package/dist/voice/provider.js.map +1 -1
  86. package/package.json +2 -1
  87. package/schema/marketing.schema.json +6 -0
  88. package/src/config/schema.ts +7 -0
  89. package/src/footage/clip-sound.ts +124 -0
  90. package/src/footage/declick.ts +3 -4
  91. package/src/footage/draft.ts +123 -22
  92. package/src/footage/elevenlabs.ts +11 -3
  93. package/src/footage/failure.ts +14 -1
  94. package/src/footage/fake.ts +28 -4
  95. package/src/footage/hyperframes-capture.ts +100 -0
  96. package/src/footage/isolate-ranges.ts +124 -29
  97. package/src/footage/loudness.ts +17 -8
  98. package/src/footage/paid.ts +25 -3
  99. package/src/footage/pipeline.ts +68 -47
  100. package/src/footage/providers.ts +5 -0
  101. package/src/footage/render.ts +4 -3
  102. package/src/footage/speech-ranges.ts +184 -19
  103. package/src/index.ts +49 -1
  104. package/src/og/index.ts +28 -0
  105. package/src/og/photo-cover.ts +442 -0
  106. package/src/og/photo.ts +177 -0
  107. package/src/voice/provider-failure.ts +98 -0
  108. package/src/voice/provider.ts +7 -2
@@ -0,0 +1,74 @@
1
+ import type { BrandColors } from "../config/colors.js";
2
+ import { type OgFonts } from "./fonts.js";
3
+ import { type FocusPoint } from "./photo.js";
4
+ import { type OgResult } from "./result.js";
5
+ /**
6
+ * A publish-ready cover for a vertical video from a photo the owner picks: the photo scaled to cover the frame and
7
+ * cropped around a focus point (EXIF orientation applied), and optional text in the brand's display font laid out by
8
+ * one of `PHOTO_COVER_LAYOUTS`, kept inside the centre 4:5 band the platforms keep when they crop the cover for the
9
+ * profile grid. Satori lays the text out, resvg draws the whole cover, `jpeg-js` encodes it: no network, no system
10
+ * fonts.
11
+ */
12
+ /** A Reels, Shorts and TikTok cover. */
13
+ export declare const PHOTO_COVER_SIZE: readonly [number, number];
14
+ export declare const PHOTO_COVER_QUALITY = 90;
15
+ /** The longest caption accepted before layout; whether a shorter one fits is measured on the drawn caption. */
16
+ export declare const MAX_COVER_CAPTION_LENGTH = 80;
17
+ /** The longest kicker (the small line above the title in `kicker-title`). */
18
+ export declare const MAX_COVER_KICKER_LENGTH = 40;
19
+ /** The longest label of the `pill` layout (the caption set in a rounded box). */
20
+ export declare const MAX_COVER_PILL_LENGTH = 32;
21
+ /**
22
+ * Where the cover's text goes. `photo`: no text. `title-bottom`, `title-center`, `title-top`: the caption in the lower
23
+ * half, the middle third or the upper half of the band. `kicker-title`: a small kicker line above the caption, in the
24
+ * lower half. `pill`: the caption as a short label in a rounded box, in the lower half.
25
+ */
26
+ export declare const PHOTO_COVER_LAYOUTS: readonly ["photo", "title-bottom", "title-center", "title-top", "kicker-title", "pill"];
27
+ export type PhotoCoverLayout = (typeof PHOTO_COVER_LAYOUTS)[number];
28
+ /** `light`: light text over a dark scrim. `dark`: dark text over a light scrim. */
29
+ export type PhotoCoverTone = "light" | "dark";
30
+ /** The centre 4:5 band of a cover, in pixels. */
31
+ export interface CoverBand {
32
+ left: number;
33
+ top: number;
34
+ width: number;
35
+ height: number;
36
+ }
37
+ /** The widest 4:5 rectangle centred in a frame of `size`. */
38
+ export declare function getCoverBand(size: readonly [number, number]): CoverBand;
39
+ /** The caption size at a 1080 px band: shorter captions get bigger type. */
40
+ export declare function getCoverCaptionSize(caption: string): number;
41
+ export interface PhotoCoverInput {
42
+ /** A JPEG or PNG: its path, or its bytes. */
43
+ photo: string | Buffer;
44
+ /** The cover's size; 1080×1920 by default. */
45
+ size?: readonly [number, number];
46
+ /** The point of the upright photo to keep in view, as fractions of its width and height; the centre by default. */
47
+ focus?: FocusPoint;
48
+ /** Where the text goes (`PHOTO_COVER_LAYOUTS`); `title-bottom` with a caption and `photo` without one by default. */
49
+ layout?: PhotoCoverLayout;
50
+ /** The title (2 to 6 words fit best), or the `pill` label; required by every layout but `photo`, refused by it. */
51
+ caption?: string;
52
+ /** The small line above the title; required by `kicker-title` and refused by the other layouts. */
53
+ kicker?: string;
54
+ /** `light` text over a dark scrim, or `dark` text over a light one; `light` by default. */
55
+ tone?: PhotoCoverTone;
56
+ /** The light colour is the lighter of `foreground` and `background`, the dark colour the darker. */
57
+ colors: BrandColors;
58
+ /** The brand's fonts (`loadOgFonts`); the text is set in the heading (display) family. */
59
+ fonts: OgFonts;
60
+ /** JPEG quality, 1-100; 90 by default. */
61
+ quality?: number;
62
+ /** Names the cover in errors, e.g. the video's id. */
63
+ id?: string;
64
+ }
65
+ export interface PhotoCover {
66
+ /** A baseline JPEG of exactly `width` × `height`, without an ICC profile (sRGB). */
67
+ jpeg: Buffer;
68
+ width: number;
69
+ height: number;
70
+ bytes: number;
71
+ }
72
+ /** Renders the cover: the photo cropped to `size` around the focus point, the layout's text (if any) over a soft scrim. */
73
+ export declare function renderPhotoCover(input: PhotoCoverInput): Promise<OgResult<PhotoCover>>;
74
+ //# sourceMappingURL=photo-cover.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"photo-cover.d.ts","sourceRoot":"","sources":["../../src/og/photo-cover.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,EAA+B,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAGvE,OAAO,EAAsE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AACjH,OAAO,EAAW,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAErD;;;;;;GAMG;AAEH,wCAAwC;AACxC,eAAO,MAAM,gBAAgB,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAgB,CAAC;AAExE,eAAO,MAAM,mBAAmB,KAAK,CAAC;AAEtC,+GAA+G;AAC/G,eAAO,MAAM,wBAAwB,KAAK,CAAC;AAE3C,6EAA6E;AAC7E,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAE1C,iFAAiF;AACjF,eAAO,MAAM,qBAAqB,KAAK,CAAC;AA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AE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AAwPD,2HAA2H;AAC3H,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAoD5F"}
@@ -0,0 +1,357 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { Resvg } from "@resvg/resvg-js";
3
+ import jpeg from "jpeg-js";
4
+ import satori from "satori";
5
+ import { z } from "zod";
6
+ import { h } from "./element.js";
7
+ import { pickWeight, toFontFamilyCss } from "./fonts.js";
8
+ import { describeCharacter, findMissingGlyphs } from "./glyphs.js";
9
+ import { toOpaqueHex, withAlpha } from "./palette.js";
10
+ import { getCoverCrop, getOrientationMatrix, getOrientedSize, readPhotoInfo } from "./photo.js";
11
+ import { err, ok } from "./result.js";
12
+ /**
13
+ * A publish-ready cover for a vertical video from a photo the owner picks: the photo scaled to cover the frame and
14
+ * cropped around a focus point (EXIF orientation applied), and optional text in the brand's display font laid out by
15
+ * one of `PHOTO_COVER_LAYOUTS`, kept inside the centre 4:5 band the platforms keep when they crop the cover for the
16
+ * profile grid. Satori lays the text out, resvg draws the whole cover, `jpeg-js` encodes it: no network, no system
17
+ * fonts.
18
+ */
19
+ /** A Reels, Shorts and TikTok cover. */
20
+ export const PHOTO_COVER_SIZE = [1080, 1920];
21
+ export const PHOTO_COVER_QUALITY = 90;
22
+ /** The longest caption accepted before layout; whether a shorter one fits is measured on the drawn caption. */
23
+ export const MAX_COVER_CAPTION_LENGTH = 80;
24
+ /** The longest kicker (the small line above the title in `kicker-title`). */
25
+ export const MAX_COVER_KICKER_LENGTH = 40;
26
+ /** The longest label of the `pill` layout (the caption set in a rounded box). */
27
+ export const MAX_COVER_PILL_LENGTH = 32;
28
+ /**
29
+ * Where the cover's text goes. `photo`: no text. `title-bottom`, `title-center`, `title-top`: the caption in the lower
30
+ * half, the middle third or the upper half of the band. `kicker-title`: a small kicker line above the caption, in the
31
+ * lower half. `pill`: the caption as a short label in a rounded box, in the lower half.
32
+ */
33
+ export const PHOTO_COVER_LAYOUTS = ["photo", "title-bottom", "title-center", "title-top", "kicker-title", "pill"];
34
+ /** Sizes in this file are written for a 1080 px wide band and scaled with its width. */
35
+ const BAND_BASE_WIDTH = 1080;
36
+ const CAPTION_SIDE_PADDING = 80;
37
+ const CAPTION_BOTTOM_PADDING = 120;
38
+ const CAPTION_TOP_PADDING = 120;
39
+ const KICKER_SIZE = 44;
40
+ const KICKER_GAP = 20;
41
+ const PILL_SIZE = 56;
42
+ const PILL_PADDING = [22, 48];
43
+ /** The pill box's opacity: the box is the pill's scrim. */
44
+ const PILL_ALPHA = 0xd9;
45
+ /** A pixel whose alpha is above this counts as drawn when the caption is measured (the shadow's faint fringe does not). */
46
+ const DRAWN_ALPHA = 16;
47
+ /** The scrim's opacity at the band's lower edge and below it. */
48
+ const SCRIM_ALPHA = 0x8c;
49
+ /** The widest 4:5 rectangle centred in a frame of `size`. */
50
+ export function getCoverBand(size) {
51
+ const [width, height] = size;
52
+ const bandWidth = Math.min(width, Math.floor((height * 4) / 5));
53
+ const bandHeight = Math.min(height, Math.round((bandWidth * 5) / 4));
54
+ return { left: Math.floor((width - bandWidth) / 2), top: Math.floor((height - bandHeight) / 2), width: bandWidth, height: bandHeight };
55
+ }
56
+ /** The caption size at a 1080 px band: shorter captions get bigger type. */
57
+ export function getCoverCaptionSize(caption) {
58
+ if (caption.length <= 16)
59
+ return 112;
60
+ if (caption.length <= 32)
61
+ return 96;
62
+ return 80;
63
+ }
64
+ const coverOptionsSchema = z.object({
65
+ photo: z.union([z.string().min(1), z.instanceof(Buffer)]),
66
+ size: z.tuple([z.number().int().min(64).max(4096), z.number().int().min(64).max(4096)]).default([...PHOTO_COVER_SIZE]),
67
+ focus: z.object({ x: z.number().min(0).max(1), y: z.number().min(0).max(1) }).default({ x: 0.5, y: 0.5 }),
68
+ layout: z.enum(PHOTO_COVER_LAYOUTS).optional(),
69
+ caption: z
70
+ .string()
71
+ .trim()
72
+ .min(1, "the caption is empty; leave it out for a cover without one")
73
+ .max(MAX_COVER_CAPTION_LENGTH, `the caption is longer than ${String(MAX_COVER_CAPTION_LENGTH)} characters`)
74
+ .optional(),
75
+ kicker: z
76
+ .string()
77
+ .trim()
78
+ .min(1, "the kicker is empty")
79
+ .max(MAX_COVER_KICKER_LENGTH, `the kicker is longer than ${String(MAX_COVER_KICKER_LENGTH)} characters`)
80
+ .optional(),
81
+ tone: z.enum(["light", "dark"]).optional(),
82
+ quality: z.number().int().min(1).max(100).default(PHOTO_COVER_QUALITY),
83
+ });
84
+ /** The part of the band each text layout keeps to. */
85
+ const LAYOUT_REGIONS = {
86
+ "title-bottom": "lower half",
87
+ "title-center": "middle third",
88
+ "title-top": "upper half",
89
+ "kicker-title": "lower half",
90
+ pill: "lower half",
91
+ };
92
+ /** The rows of `region` in the band: `top` included, `bottom` excluded. */
93
+ function getRegionRows(band, region) {
94
+ const bandBottom = band.top + band.height;
95
+ if (region === "lower half")
96
+ return { top: band.top + Math.floor(band.height / 2), bottom: bandBottom };
97
+ if (region === "upper half")
98
+ return { top: band.top, bottom: band.top + Math.floor(band.height / 2) };
99
+ return { top: band.top + Math.floor(band.height / 3), bottom: band.top + Math.floor((2 * band.height) / 3) };
100
+ }
101
+ /** The text the options ask for, or an error when the layout and the texts do not go together. */
102
+ function resolveCoverText(options) {
103
+ const { caption, kicker } = options;
104
+ const layout = options.layout ?? (caption === undefined ? "photo" : "title-bottom");
105
+ if (kicker !== undefined && layout !== "kicker-title")
106
+ return err(`the kicker is drawn only by the layout "kicker-title", not "${layout}"; leave it out`);
107
+ if (layout === "photo")
108
+ return caption === undefined ? ok(null) : err('the layout "photo" draws no text; leave the caption out or pick a text layout');
109
+ if (caption === undefined)
110
+ return err(`the layout "${layout}" needs a caption`);
111
+ if (layout === "kicker-title")
112
+ return kicker === undefined ? err('the layout "kicker-title" needs a kicker') : ok({ layout, caption, kicker });
113
+ if (layout === "pill" && caption.length > MAX_COVER_PILL_LENGTH) {
114
+ return err(`the pill label ${JSON.stringify(caption)} is longer than ${String(MAX_COVER_PILL_LENGTH)} characters`);
115
+ }
116
+ return ok({ layout, caption });
117
+ }
118
+ function describeCover(id) {
119
+ return id === undefined ? "Photo cover" : `Photo cover "${id}"`;
120
+ }
121
+ function readPhoto(photo) {
122
+ if (typeof photo !== "string")
123
+ return ok(photo);
124
+ try {
125
+ return ok(readFileSync(photo));
126
+ }
127
+ catch (error) {
128
+ return err(`reading the photo ${photo}: ${error.code ?? String(error)}`);
129
+ }
130
+ }
131
+ /** Relative luminance (WCAG) of an opaque `#rrggbb`. */
132
+ function getLuminance(color) {
133
+ const hex = toOpaqueHex(color);
134
+ const channel = (offset) => {
135
+ const value = Number.parseInt(hex.slice(offset, offset + 2), 16) / 255;
136
+ return value <= 0.039_28 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
137
+ };
138
+ return 0.2126 * channel(1) + 0.7152 * channel(3) + 0.0722 * channel(5);
139
+ }
140
+ /** The text colour and the scrim (and shadow) colour: the brand's light and dark colour, swapped for a `dark` tone. */
141
+ function getCoverInk(colors, tone) {
142
+ const foreground = toOpaqueHex(colors.foreground);
143
+ const background = toOpaqueHex(colors.background);
144
+ const [light, dark] = getLuminance(foreground) >= getLuminance(background) ? [foreground, background] : [background, foreground];
145
+ return tone === "light" ? { text: light, shade: dark } : { text: dark, shade: light };
146
+ }
147
+ /** Where the text block sits: its foot above the band's lower edge, its head below the band's top, or centred in the middle third. */
148
+ function getBlockPlacement(layout, scale) {
149
+ const [, height] = layout.size;
150
+ const { band } = layout;
151
+ const region = LAYOUT_REGIONS[layout.text.layout];
152
+ if (region === "lower half")
153
+ return { bottom: height - (band.top + band.height) + Math.round(CAPTION_BOTTOM_PADDING * scale) };
154
+ if (region === "upper half")
155
+ return { top: band.top + Math.round(CAPTION_TOP_PADDING * scale) };
156
+ const rows = getRegionRows(band, region);
157
+ return { top: rows.top, height: rows.bottom - rows.top, justifyContent: "center" };
158
+ }
159
+ /** The text alone on a transparent frame, laid out by its layout and centred across the band. */
160
+ function buildTextTree(layout) {
161
+ const [width, height] = layout.size;
162
+ const { band, fonts, ink, text } = layout;
163
+ const scale = band.width / BAND_BASE_WIDTH;
164
+ const side = Math.round(CAPTION_SIDE_PADDING * scale);
165
+ const font = { fontFamily: toFontFamilyCss(fonts.heading), fontWeight: pickWeight(fonts.heading.weights, 700) };
166
+ const shadow = `0px ${String(Math.round(4 * scale))}px ${String(Math.round(24 * scale))}px ${withAlpha(ink.shade, 0xb3)}`;
167
+ const line = (content, style) => h("div", { style: { display: "flex", justifyContent: "center", width: "100%", textAlign: "center", wordBreak: "break-word", color: ink.text, ...font, ...style } }, content);
168
+ const children = text.layout === "pill"
169
+ ? [
170
+ h("div", {
171
+ style: {
172
+ display: "flex",
173
+ maxWidth: "100%",
174
+ padding: `${String(Math.round(PILL_PADDING[0] * scale))}px ${String(Math.round(PILL_PADDING[1] * scale))}px`,
175
+ borderRadius: Math.round(PILL_SIZE * scale),
176
+ backgroundColor: withAlpha(ink.shade, PILL_ALPHA),
177
+ textAlign: "center",
178
+ wordBreak: "break-word",
179
+ color: ink.text,
180
+ fontSize: Math.round(PILL_SIZE * scale),
181
+ lineHeight: 1.15,
182
+ ...font,
183
+ },
184
+ }, text.caption),
185
+ ]
186
+ : [
187
+ ...(text.layout === "kicker-title"
188
+ ? [line(text.kicker, { fontSize: Math.round(KICKER_SIZE * scale), lineHeight: 1.2, letterSpacing: Math.round(3 * scale), marginBottom: Math.round(KICKER_GAP * scale), textShadow: shadow })]
189
+ : []),
190
+ line(text.caption, { fontSize: Math.round(getCoverCaptionSize(text.caption) * scale), lineHeight: 1.08, textShadow: shadow }),
191
+ ];
192
+ return h("div", { style: { display: "flex", position: "relative", width, height } }, h("div", {
193
+ style: {
194
+ position: "absolute",
195
+ display: "flex",
196
+ flexDirection: "column",
197
+ alignItems: "center",
198
+ left: band.left + side,
199
+ width: band.width - 2 * side,
200
+ ...getBlockPlacement(layout, scale),
201
+ },
202
+ }, ...children));
203
+ }
204
+ /** How errors name the cover's text, e.g. `the kicker "New" and the caption "Lisbon"`. */
205
+ function describeText(text) {
206
+ if (text.layout === "pill")
207
+ return { name: `the pill label ${JSON.stringify(text.caption)}`, isPlural: false };
208
+ if (text.layout === "kicker-title")
209
+ return { name: `the kicker ${JSON.stringify(text.kicker)} and the caption ${JSON.stringify(text.caption)}`, isPlural: true };
210
+ return { name: `the caption ${JSON.stringify(text.caption)}`, isPlural: false };
211
+ }
212
+ function checkTextGlyphs(tree, fonts, text) {
213
+ const missing = findMissingGlyphs(tree, fonts.satoriFonts);
214
+ if (!missing.ok)
215
+ return err(`reading ${missing.error}`);
216
+ const sentences = missing.value
217
+ .filter((entry) => entry.characters.length > 0)
218
+ .map((entry) => {
219
+ const role = text.layout === "pill" ? "pill label" : text.layout === "kicker-title" && entry.text === text.kicker ? "kicker" : "caption";
220
+ return `the ${role} ${JSON.stringify(entry.text)} has characters none of the loaded fonts can draw at its weight: ${entry.characters.map(describeCharacter).join(", ")}`;
221
+ });
222
+ if (sentences.length === 0)
223
+ return ok(null);
224
+ return err(`${sentences.join("; ")}. Use font files that cover them`);
225
+ }
226
+ /** The rows of `pixels` (RGBA, `width` wide) that hold anything drawn, or null when nothing is. */
227
+ function findDrawnBox(pixels, width, height) {
228
+ let top = height;
229
+ let bottom = -1;
230
+ let left = width;
231
+ let right = -1;
232
+ for (let y = 0; y < height; y += 1) {
233
+ for (let x = 0; x < width; x += 1) {
234
+ if ((pixels[(y * width + x) * 4 + 3] ?? 0) <= DRAWN_ALPHA)
235
+ continue;
236
+ top = Math.min(top, y);
237
+ bottom = Math.max(bottom, y);
238
+ left = Math.min(left, x);
239
+ right = Math.max(right, x);
240
+ }
241
+ }
242
+ return bottom < 0 ? null : { top, bottom, left, right };
243
+ }
244
+ /** The text as SVG and the rows it draws, or an error when it does not fit its part of the band. */
245
+ async function layOutText(layout) {
246
+ const tree = buildTextTree(layout);
247
+ const glyphs = checkTextGlyphs(tree, layout.fonts, layout.text);
248
+ if (!glyphs.ok)
249
+ return glyphs;
250
+ const [width, height] = layout.size;
251
+ let svg;
252
+ try {
253
+ // Satori is typed for React elements; it reads only `type` and `props`, which `OgNode` has.
254
+ svg = await satori(tree, { width, height, fonts: layout.fonts.satoriFonts });
255
+ }
256
+ catch (error) {
257
+ return err(`laying out the text failed: ${error instanceof Error ? error.message : String(error)}`);
258
+ }
259
+ const pixels = new Resvg(svg, { fitTo: { mode: "original" }, font: { loadSystemFonts: false } }).render().pixels;
260
+ const box = findDrawnBox(pixels, width, height);
261
+ const { name, isPlural } = describeText(layout.text);
262
+ if (box === null)
263
+ return err(`${name} ${isPlural ? "draw" : "draws"} nothing`);
264
+ const { band } = layout;
265
+ // The text keeps to the part of the band its layout names, so the photo's subject elsewhere stays clear.
266
+ const region = LAYOUT_REGIONS[layout.text.layout];
267
+ const rows = getRegionRows(band, region);
268
+ const isInside = box.top >= rows.top && box.bottom < rows.bottom && box.left >= band.left && box.right < band.left + band.width;
269
+ if (!isInside) {
270
+ return err(`${name} ${isPlural ? "do" : "does"} not fit the ${region} of the centre 4:5 band (${String(band.width)}×${String(band.height)}); shorten ${isPlural ? "them" : "it"}`);
271
+ }
272
+ return ok({ svg, top: box.top, bottom: box.bottom });
273
+ }
274
+ /** The scrim behind the text, as SVG: a gradient of the shade that follows the text's position; none for a pill (its box is its scrim). */
275
+ function buildScrim(input) {
276
+ const [width, height] = input.size;
277
+ const { band, shade } = input;
278
+ const region = LAYOUT_REGIONS[input.layout];
279
+ if (input.layout === "pill")
280
+ return "";
281
+ const fade = Math.round(band.height / 5);
282
+ const alpha = (SCRIM_ALPHA / 255).toFixed(3);
283
+ const stop = (offset, opacity) => `<stop offset="${offset.toFixed(4)}" stop-color="${shade}" stop-opacity="${opacity}"/>`;
284
+ const gradient = (y1, y2, stops) => `<defs><linearGradient id="scrim" gradientUnits="userSpaceOnUse" x1="0" y1="${String(y1)}" x2="0" y2="${String(y2)}">${stops}</linearGradient></defs>`;
285
+ const rect = (top, bottom) => `<rect y="${String(top)}" width="${String(width)}" height="${String(bottom - top)}" fill="url(#scrim)"/>`;
286
+ if (region === "lower half") {
287
+ // Fades in over a fifth of the band above the text and holds from the band's lower edge down.
288
+ const start = Math.max(0, input.text.top - fade);
289
+ return gradient(start, band.top + band.height, stop(0, "0") + stop(1, alpha)) + rect(start, height);
290
+ }
291
+ if (region === "upper half") {
292
+ // Holds from the frame's top to the band's top and fades out over a fifth of the band below the text.
293
+ const end = Math.min(height, input.text.bottom + fade);
294
+ return gradient(band.top, end, stop(0, alpha) + stop(1, "0")) + rect(0, end);
295
+ }
296
+ // Fades in above the text, holds behind it and fades out below it.
297
+ const start = Math.max(0, input.text.top - fade);
298
+ const end = Math.min(height, input.text.bottom + fade);
299
+ const span = Math.max(1, end - start);
300
+ return gradient(start, end, stop(0, "0") + stop((input.text.top - start) / span, alpha) + stop((input.text.bottom - start) / span, alpha) + stop(1, "0")) + rect(start, end);
301
+ }
302
+ const toDataUri = (type, bytes) => `data:${type};base64,${Buffer.from(bytes).toString("base64")}`;
303
+ /** Renders the cover: the photo cropped to `size` around the focus point, the layout's text (if any) over a soft scrim. */
304
+ export async function renderPhotoCover(input) {
305
+ const name = describeCover(input.id);
306
+ const parsed = coverOptionsSchema.safeParse({
307
+ photo: input.photo,
308
+ size: input.size,
309
+ focus: input.focus,
310
+ layout: input.layout,
311
+ caption: input.caption,
312
+ kicker: input.kicker,
313
+ tone: input.tone,
314
+ quality: input.quality,
315
+ });
316
+ if (!parsed.success) {
317
+ const lines = parsed.error.issues.map((issue) => ` ${issue.path.length > 0 ? issue.path.join(".") : "input"}: ${issue.message}`);
318
+ return err(`${name}: the input is not valid:\n${lines.join("\n")}`);
319
+ }
320
+ const options = parsed.data;
321
+ const text = resolveCoverText(options);
322
+ if (!text.ok)
323
+ return err(`${name}: ${text.error}.`);
324
+ const bytes = readPhoto(options.photo);
325
+ if (!bytes.ok)
326
+ return err(`${name}: ${bytes.error}.`);
327
+ const info = readPhotoInfo(bytes.value);
328
+ if (!info.ok)
329
+ return err(`${name}: the photo${typeof options.photo === "string" ? ` ${options.photo}` : ""} cannot be used: ${info.error}.`);
330
+ const size = options.size;
331
+ const [width, height] = size;
332
+ const band = getCoverBand(size);
333
+ const ink = getCoverInk(input.colors, options.tone ?? "light");
334
+ const drawn = text.value === null ? null : await layOutText({ size, band, text: text.value, fonts: input.fonts, ink });
335
+ if (drawn !== null && !drawn.ok)
336
+ return err(`${name}: ${drawn.error}.`);
337
+ const crop = getCoverCrop(getOrientedSize(info.value), size, options.focus);
338
+ const matrix = getOrientationMatrix(info.value.orientation, info.value.width, info.value.height).join(" ");
339
+ const layers = [
340
+ `<rect width="${String(width)}" height="${String(height)}" fill="${ink.shade}"/>`,
341
+ `<image href="${toDataUri(`image/${info.value.format}`, bytes.value)}" width="${String(info.value.width)}" height="${String(info.value.height)}" preserveAspectRatio="none" ` +
342
+ `transform="translate(${String(crop.x)} ${String(crop.y)}) scale(${String(crop.scale)}) matrix(${matrix})"/>`,
343
+ ];
344
+ if (drawn !== null && text.value !== null) {
345
+ layers.push(buildScrim({ size, band, layout: text.value.layout, text: drawn.value, shade: ink.shade }), `<image href="${toDataUri("image/svg+xml", drawn.value.svg)}" width="${String(width)}" height="${String(height)}"/>`);
346
+ }
347
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${String(width)}" height="${String(height)}" viewBox="0 0 ${String(width)} ${String(height)}">${layers.join("")}</svg>`;
348
+ try {
349
+ const image = new Resvg(svg, { fitTo: { mode: "original" }, font: { loadSystemFonts: false } }).render();
350
+ const encoded = jpeg.encode({ data: Buffer.from(image.pixels), width: image.width, height: image.height }, options.quality).data;
351
+ return ok({ jpeg: encoded, width: image.width, height: image.height, bytes: encoded.length });
352
+ }
353
+ catch (error) {
354
+ return err(`${name}: drawing the cover failed: ${error instanceof Error ? error.message : String(error)}.`);
355
+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O,CAAC,CAAC,IAAI,CAAC;QACjI,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAChG,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,GAAG,CAAC,GAAG,IAAI,+BAA+B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC9G,CAAC;AACH,CAAC"}
@@ -0,0 +1,51 @@
1
+ import { type OgResult } from "./result.js";
2
+ /**
3
+ * What a photo's header says, read without decoding it: the format, the stored pixel size and the EXIF orientation.
4
+ * resvg draws a JPEG or PNG as stored and ignores EXIF orientation, so a cover applies the orientation itself
5
+ * (`getOrientationMatrix`).
6
+ */
7
+ export type PhotoFormat = "jpeg" | "png";
8
+ /** EXIF orientation 1-8: 1 is upright, 5-8 swap width and height. */
9
+ export type PhotoOrientation = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
10
+ export interface PhotoInfo {
11
+ format: PhotoFormat;
12
+ /** The stored size, before orientation. */
13
+ width: number;
14
+ height: number;
15
+ orientation: PhotoOrientation;
16
+ }
17
+ /** The orientation in a TIFF block (an EXIF payload after `Exif\0\0`, or a PNG `eXIf` chunk); 1 when absent. */
18
+ export declare function readTiffOrientation(tiff: Buffer): PhotoOrientation;
19
+ /** The format, stored size and orientation of a JPEG or PNG; anything else is an error naming what is wrong. */
20
+ export declare function readPhotoInfo(bytes: Buffer): OgResult<PhotoInfo>;
21
+ /** The size a viewer shows: orientations 5-8 turn the photo a quarter, swapping width and height. */
22
+ export declare function getOrientedSize(info: Pick<PhotoInfo, "width" | "height" | "orientation">): {
23
+ width: number;
24
+ height: number;
25
+ };
26
+ /**
27
+ * The SVG `matrix(a b c d e f)` that maps the stored pixels (`width` × `height`) onto the upright photo, so that
28
+ * `x' = a·x + c·y + e` and `y' = b·x + d·y + f`.
29
+ */
30
+ export declare function getOrientationMatrix(orientation: PhotoOrientation, width: number, height: number): readonly [number, number, number, number, number, number];
31
+ /** A point of the photo as fractions of its upright width and height, 0..1. */
32
+ export interface FocusPoint {
33
+ x: number;
34
+ y: number;
35
+ }
36
+ /** How the upright photo is scaled and shifted to cover the frame. */
37
+ export interface CoverCrop {
38
+ scale: number;
39
+ /** The scaled photo's offset from the frame's top-left corner, zero or negative. */
40
+ x: number;
41
+ y: number;
42
+ }
43
+ /**
44
+ * Scales the upright photo to cover `frame` and shifts it so the focus point sits as near the frame's centre as the
45
+ * photo allows: an edge of the photo never comes inside the frame.
46
+ */
47
+ export declare function getCoverCrop(photo: {
48
+ width: number;
49
+ height: number;
50
+ }, frame: readonly [number, number], focus: FocusPoint): CoverCrop;
51
+ //# sourceMappingURL=photo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"photo.d.ts","sourceRoot":"","sources":["../../src/og/photo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAErD;;;;GAIG;AAEH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,KAAK,CAAC;AAEzC,qEAAqE;AACrE,MAAM,MAAM,gBAAgB,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAE7D,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,WAAW,CAAC;IACpB,2CAA2C;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,gBAAgB,CAAC;CAC/B;AAWD,gHAAgH;AAChH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAoBlE;AA6DD,gHAAgH;AAChH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