@softure-ai/marketing-kit 0.21.2 → 0.23.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 (162) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/NOTICE +11 -0
  3. package/README.md +39 -5
  4. package/dist/cli/failure.d.ts.map +1 -1
  5. package/dist/cli/failure.js.map +1 -1
  6. package/dist/cli/films.js.map +1 -1
  7. package/dist/cli/main.js.map +1 -1
  8. package/dist/cli/options.d.ts.map +1 -1
  9. package/dist/compose/timeline.d.ts +22 -1
  10. package/dist/compose/timeline.d.ts.map +1 -1
  11. package/dist/compose/timeline.js +52 -14
  12. package/dist/compose/timeline.js.map +1 -1
  13. package/dist/config/actions-schema.d.ts +57 -57
  14. package/dist/config/actions-schema.d.ts.map +1 -1
  15. package/dist/config/brand.d.ts.map +1 -1
  16. package/dist/config/brand.js +22 -1
  17. package/dist/config/brand.js.map +1 -1
  18. package/dist/config/colors.d.ts +35 -3
  19. package/dist/config/colors.d.ts.map +1 -1
  20. package/dist/config/colors.js +32 -0
  21. package/dist/config/colors.js.map +1 -1
  22. package/dist/config/config.d.ts.map +1 -1
  23. package/dist/config/config.js +5 -0
  24. package/dist/config/config.js.map +1 -1
  25. package/dist/config/placeholders.d.ts.map +1 -1
  26. package/dist/config/placeholders.js.map +1 -1
  27. package/dist/config/schema.d.ts +340 -328
  28. package/dist/config/schema.d.ts.map +1 -1
  29. package/dist/config/schema.js +31 -4
  30. package/dist/config/schema.js.map +1 -1
  31. package/dist/config/shot-steps.d.ts +64 -64
  32. package/dist/film.d.ts.map +1 -1
  33. package/dist/footage/audio.js.map +1 -1
  34. package/dist/footage/caption-highlight.d.ts +44 -0
  35. package/dist/footage/caption-highlight.d.ts.map +1 -0
  36. package/dist/footage/caption-highlight.js +29 -0
  37. package/dist/footage/caption-highlight.js.map +1 -0
  38. package/dist/footage/captions.d.ts +14 -5
  39. package/dist/footage/captions.d.ts.map +1 -1
  40. package/dist/footage/captions.js +19 -11
  41. package/dist/footage/captions.js.map +1 -1
  42. package/dist/footage/clip-sound.d.ts.map +1 -1
  43. package/dist/footage/clip-sound.js.map +1 -1
  44. package/dist/footage/compose.d.ts +3 -0
  45. package/dist/footage/compose.d.ts.map +1 -1
  46. package/dist/footage/compose.js +33 -6
  47. package/dist/footage/compose.js.map +1 -1
  48. package/dist/footage/cuts.d.ts.map +1 -1
  49. package/dist/footage/cuts.js.map +1 -1
  50. package/dist/footage/declick.d.ts.map +1 -1
  51. package/dist/footage/disk.js.map +1 -1
  52. package/dist/footage/draft-color.d.ts +6 -0
  53. package/dist/footage/draft-color.d.ts.map +1 -0
  54. package/dist/footage/draft-color.js +14 -0
  55. package/dist/footage/draft-color.js.map +1 -0
  56. package/dist/footage/draft-font.js.map +1 -1
  57. package/dist/footage/draft-overlays.d.ts +12 -0
  58. package/dist/footage/draft-overlays.d.ts.map +1 -0
  59. package/dist/footage/draft-overlays.js +83 -0
  60. package/dist/footage/draft-overlays.js.map +1 -0
  61. package/dist/footage/draft.d.ts +27 -9
  62. package/dist/footage/draft.d.ts.map +1 -1
  63. package/dist/footage/draft.js +99 -37
  64. package/dist/footage/draft.js.map +1 -1
  65. package/dist/footage/edl.d.ts +54 -13
  66. package/dist/footage/edl.d.ts.map +1 -1
  67. package/dist/footage/edl.js +10 -0
  68. package/dist/footage/edl.js.map +1 -1
  69. package/dist/footage/elevenlabs.d.ts.map +1 -1
  70. package/dist/footage/failure.js.map +1 -1
  71. package/dist/footage/fake.js.map +1 -1
  72. package/dist/footage/ffmpeg-failure.d.ts.map +1 -1
  73. package/dist/footage/ffmpeg-failure.js.map +1 -1
  74. package/dist/footage/film.d.ts +23 -0
  75. package/dist/footage/film.d.ts.map +1 -1
  76. package/dist/footage/film.js +2 -0
  77. package/dist/footage/film.js.map +1 -1
  78. package/dist/footage/hyperframes-capture.d.ts.map +1 -1
  79. package/dist/footage/keyterms.d.ts.map +1 -1
  80. package/dist/footage/loudness.d.ts.map +1 -1
  81. package/dist/footage/loudness.js.map +1 -1
  82. package/dist/footage/mouth-clicks.d.ts.map +1 -1
  83. package/dist/footage/normalize.d.ts.map +1 -1
  84. package/dist/footage/normalize.js.map +1 -1
  85. package/dist/footage/overlay-html.d.ts +29 -0
  86. package/dist/footage/overlay-html.d.ts.map +1 -0
  87. package/dist/footage/overlay-html.js +112 -0
  88. package/dist/footage/overlay-html.js.map +1 -0
  89. package/dist/footage/overlay-schema.d.ts +97 -0
  90. package/dist/footage/overlay-schema.d.ts.map +1 -0
  91. package/dist/footage/overlay-schema.js +104 -0
  92. package/dist/footage/overlay-schema.js.map +1 -0
  93. package/dist/footage/overlays.d.ts +112 -0
  94. package/dist/footage/overlays.d.ts.map +1 -0
  95. package/dist/footage/overlays.js +222 -0
  96. package/dist/footage/overlays.js.map +1 -0
  97. package/dist/footage/paid.d.ts.map +1 -1
  98. package/dist/footage/pipeline.d.ts.map +1 -1
  99. package/dist/footage/pipeline.js +10 -1
  100. package/dist/footage/pipeline.js.map +1 -1
  101. package/dist/footage/probe.js.map +1 -1
  102. package/dist/footage/process.js.map +1 -1
  103. package/dist/footage/publish.js.map +1 -1
  104. package/dist/footage/render.js.map +1 -1
  105. package/dist/footage/sound-analysis.d.ts.map +1 -1
  106. package/dist/footage/speech-ranges.js.map +1 -1
  107. package/dist/footage/tonemap-lut.d.ts.map +1 -1
  108. package/dist/footage/tonemap-lut.js.map +1 -1
  109. package/dist/footage/tools.d.ts.map +1 -1
  110. package/dist/footage/tools.js.map +1 -1
  111. package/dist/index.d.ts +7 -4
  112. package/dist/index.d.ts.map +1 -1
  113. package/dist/index.js +7 -4
  114. package/dist/index.js.map +1 -1
  115. package/dist/messages/en.d.ts.map +1 -1
  116. package/dist/messages/index.js.map +1 -1
  117. package/dist/og/font-file.d.ts.map +1 -1
  118. package/dist/og/fonts.d.ts.map +1 -1
  119. package/dist/og/fonts.js.map +1 -1
  120. package/dist/og/index.d.ts +1 -1
  121. package/dist/og/index.d.ts.map +1 -1
  122. package/dist/og/index.js +1 -1
  123. package/dist/og/index.js.map +1 -1
  124. package/dist/og/photo-cover.d.ts +18 -1
  125. package/dist/og/photo-cover.d.ts.map +1 -1
  126. package/dist/og/photo-cover.js +56 -28
  127. package/dist/og/photo-cover.js.map +1 -1
  128. package/dist/og/result.d.ts.map +1 -1
  129. package/dist/og/templates/schemas.d.ts.map +1 -1
  130. package/dist/platforms.d.ts.map +1 -1
  131. package/dist/render/hyperframes.d.ts +1 -1
  132. package/dist/render/hyperframes.d.ts.map +1 -1
  133. package/dist/render/hyperframes.js +1 -1
  134. package/dist/render/hyperframes.js.map +1 -1
  135. package/dist/render/render.js.map +1 -1
  136. package/dist/screenshot/gates.d.ts.map +1 -1
  137. package/dist/voice/fake.js.map +1 -1
  138. package/dist/voice/provider.d.ts.map +1 -1
  139. package/package.json +4 -3
  140. package/schema/edl.schema.json +130 -0
  141. package/schema/marketing.schema.json +51 -0
  142. package/src/compose/timeline.ts +62 -13
  143. package/src/config/brand.ts +20 -1
  144. package/src/config/colors.ts +39 -2
  145. package/src/config/config.ts +5 -0
  146. package/src/config/schema.ts +34 -7
  147. package/src/footage/caption-highlight.ts +52 -0
  148. package/src/footage/captions.ts +26 -12
  149. package/src/footage/compose.ts +40 -6
  150. package/src/footage/draft-color.ts +12 -0
  151. package/src/footage/draft-overlays.ts +91 -0
  152. package/src/footage/draft.ts +117 -39
  153. package/src/footage/edl.ts +17 -0
  154. package/src/footage/film.ts +25 -0
  155. package/src/footage/overlay-html.ts +127 -0
  156. package/src/footage/overlay-schema.ts +146 -0
  157. package/src/footage/overlays.ts +272 -0
  158. package/src/footage/pipeline.ts +8 -1
  159. package/src/index.ts +58 -1
  160. package/src/og/index.ts +2 -0
  161. package/src/og/photo-cover.ts +83 -33
  162. package/src/render/hyperframes.ts +1 -1
package/src/index.ts CHANGED
@@ -47,7 +47,59 @@ export {
47
47
  type VideoConfig,
48
48
  type VideoPost,
49
49
  } from "./config/config.js";
50
- export { COLOR_ROLES, COLOR_THEMES, type BrandColors, type ColorRole, type ColorTheme, type ColorsResult } from "./config/colors.js";
50
+ export {
51
+ COLOR_ROLES,
52
+ COLOR_THEMES,
53
+ OPTIONAL_COLOR_ROLES,
54
+ getContrastRatio,
55
+ getRelativeLuminance,
56
+ type BrandColors,
57
+ type ColorRole,
58
+ type ColorTheme,
59
+ type ColorsResult,
60
+ type OptionalColorRole,
61
+ } from "./config/colors.js";
62
+ export {
63
+ CAPTION_HIGHLIGHT_BOX_PADDING_EM,
64
+ CAPTION_HIGHLIGHT_BOX_RADIUS,
65
+ CAPTION_HIGHLIGHT_SECONDS,
66
+ getCaptionHighlight,
67
+ getCaptionHighlightContrast,
68
+ type CaptionHighlightColors,
69
+ type CaptionHighlightContrast,
70
+ type CaptionHighlightLook,
71
+ type CaptionHighlightResult,
72
+ } from "./footage/caption-highlight.js";
73
+ export {
74
+ MAX_OVERLAY_KEYWORD_LENGTH,
75
+ MAX_OVERLAY_LIST_ITEM_LENGTH,
76
+ MAX_OVERLAY_LOWER_THIRD_LENGTH,
77
+ MAX_OVERLAY_SECONDS,
78
+ MIN_OVERLAY_SECONDS,
79
+ OVERLAY_KINDS,
80
+ OVERLAY_SIDES,
81
+ OVERLAY_SIZES,
82
+ type EdlOverlay,
83
+ type EdlOverlayAnchor,
84
+ type EdlOverlayStyle,
85
+ type EdlOverlayWord,
86
+ type OverlayKind,
87
+ type OverlaySide,
88
+ type OverlaySize,
89
+ } from "./footage/overlay-schema.js";
90
+ export {
91
+ OVERLAY_FONT_SIZES,
92
+ PUNCH_IN_EASE_SECONDS,
93
+ PUNCH_IN_SCALES,
94
+ getOverlaySafeZone,
95
+ getOverlayTexts,
96
+ resolveEdlOverlays,
97
+ type OverlayBox,
98
+ type OverlayPoint,
99
+ type ResolveOverlaysInput,
100
+ type ResolvedOverlay,
101
+ type ResolvedOverlaysResult,
102
+ } from "./footage/overlays.js";
51
103
  export { resolveBrandColors, type BrandColorsResult } from "./config/brand.js";
52
104
  export { readCssColors } from "./config/css-colors.js";
53
105
  export { readDesignJsonColors } from "./config/design-json.js";
@@ -114,6 +166,7 @@ export {
114
166
  TRANSITIONS,
115
167
  VIDEO_FORMATS,
116
168
  cameraPose,
169
+ balanceCaptionGroups,
117
170
  captionChunks,
118
171
  splitAfterKept,
119
172
  crossfadeArgs,
@@ -131,6 +184,7 @@ export {
131
184
  widePose,
132
185
  type CameraPose,
133
186
  type CaptionChunk,
187
+ type CaptionBalanceOptions,
134
188
  type CaptionChunkOptions,
135
189
  type CaptionLayout,
136
190
  type CrossfadeInput,
@@ -219,6 +273,7 @@ export {
219
273
  CAPTION_MIN_FONT_SCALE,
220
274
  CAPTION_PRESETS,
221
275
  CAPTION_STYLES,
276
+ CAPTION_HIGHLIGHT_STYLES,
222
277
  DEFAULT_EDIT,
223
278
  DEFAULT_END_CARD_SECONDS,
224
279
  DEFAULT_LOGO_END_CARD_FADE_SECONDS,
@@ -230,6 +285,7 @@ export {
230
285
  getFootageEdit,
231
286
  type CaptionPreset,
232
287
  type CaptionStyle,
288
+ type CaptionHighlightStyle,
233
289
  type FootageEdit,
234
290
  type ClipFit,
235
291
  type ClipRole,
@@ -435,6 +491,7 @@ export { buildFilmMixArgs, type FilmMixInput } from "./footage/film-mix.js";
435
491
  export { buildCutPreviewArgs, buildLastFrameArgs, buildMusicArgs, buildSpeechArgs, getSpeechCutOptions, type SpeechCutOptions } from "./footage/render.js";
436
492
  export {
437
493
  FOOTAGE_DRAFT_CAPTION_COLORS,
494
+ FOOTAGE_DRAFT_OVERLAY_COLORS,
438
495
  FOOTAGE_DRAFT_FONT,
439
496
  FOOTAGE_DRAFT_WIDTH,
440
497
  buildFootageDraftArgs,
package/src/og/index.ts CHANGED
@@ -34,6 +34,7 @@ export {
34
34
  MAX_COVER_KICKER_LENGTH,
35
35
  MAX_COVER_PILL_LENGTH,
36
36
  MIN_COVER_ACCENT_CONTRAST,
37
+ PHOTO_COVER_ACCENT_STYLES,
37
38
  PHOTO_COVER_LAYOUTS,
38
39
  PHOTO_COVER_QUALITY,
39
40
  PHOTO_COVER_SIZE,
@@ -45,6 +46,7 @@ export {
45
46
  type CoverBox,
46
47
  type CoverPoint,
47
48
  type PhotoCover,
49
+ type PhotoCoverAccentStyle,
48
50
  type PhotoCoverInput,
49
51
  type PhotoCoverLayout,
50
52
  type PhotoCoverTone,
@@ -5,7 +5,7 @@ import jpeg from "jpeg-js";
5
5
  import satori from "satori";
6
6
  import { z } from "zod";
7
7
 
8
- import type { BrandColors } from "../config/colors.js";
8
+ import { getContrastRatio, getRelativeLuminance, type BrandColors } from "../config/colors.js";
9
9
  import { h, type OgNode } from "./element.js";
10
10
  import { pickWeight, toFontFamilyCss, type OgFonts } from "./fonts.js";
11
11
  import { describeCharacter, findMissingGlyphs } from "./glyphs.js";
@@ -44,6 +44,15 @@ export const PHOTO_COVER_LAYOUTS = ["photo", "title-bottom", "title-center", "ti
44
44
 
45
45
  export type PhotoCoverLayout = (typeof PHOTO_COVER_LAYOUTS)[number];
46
46
 
47
+ /**
48
+ * How the accent is drawn on `kicker-title` (issue #1199): `text` colours the kicker; `box` sets the kicker on an
49
+ * opaque accent box in the better-reading of the light and dark colour; `auto` draws text when the accent reads as
50
+ * text (3:1 against the scrim) and a box when it does not. The `pill` accent is a box whatever the style.
51
+ */
52
+ export const PHOTO_COVER_ACCENT_STYLES = ["text", "box", "auto"] as const;
53
+
54
+ export type PhotoCoverAccentStyle = (typeof PHOTO_COVER_ACCENT_STYLES)[number];
55
+
47
56
  /** `light`: light text over a dark scrim. `dark`: dark text over a light scrim. */
48
57
  export type PhotoCoverTone = "light" | "dark";
49
58
 
@@ -54,6 +63,9 @@ const CAPTION_BOTTOM_PADDING = 120;
54
63
  const CAPTION_TOP_PADDING = 120;
55
64
  const KICKER_SIZE = 44;
56
65
  const KICKER_GAP = 20;
66
+ /** The boxed kicker's padding (vertical, horizontal) and corner radius. */
67
+ const KICKER_BOX_PADDING: readonly [number, number] = [10, 24];
68
+ const KICKER_BOX_RADIUS = 14;
57
69
  const PILL_SIZE = 56;
58
70
  const PILL_PADDING: readonly [number, number] = [22, 48];
59
71
  /** The pill box's opacity: the box is the pill's scrim. */
@@ -107,6 +119,7 @@ const coverOptionsSchema = z.object({
107
119
  .optional(),
108
120
  tone: z.enum(["light", "dark"]).optional(),
109
121
  accent: z.boolean().optional(),
122
+ accentStyle: z.enum(PHOTO_COVER_ACCENT_STYLES).optional(),
110
123
  quality: z.number().int().min(1).max(100).default(PHOTO_COVER_QUALITY),
111
124
  });
112
125
 
@@ -131,6 +144,8 @@ export interface PhotoCoverInput {
131
144
  * accent's contrast against what it stands on is under 3:1. Off by default.
132
145
  */
133
146
  accent?: boolean;
147
+ /** How the accent is drawn (`PHOTO_COVER_ACCENT_STYLES`); `text` by default. Needs `accent: true`. */
148
+ accentStyle?: PhotoCoverAccentStyle;
134
149
  /** The light colour is the lighter of `foreground` and `background`, the dark colour the darker. */
135
150
  colors: BrandColors;
136
151
  /** The brand's fonts (`loadOgFonts`); the text is set in the heading (display) family. */
@@ -165,6 +180,11 @@ export interface PhotoCover {
165
180
  textBox: CoverBox | null;
166
181
  /** Where the focus point landed on the cover after the crop; off-centre when the photo's edge stops the shift. */
167
182
  focusPoint: CoverPoint;
183
+ /**
184
+ * How the accent was drawn and the contrast it reads at (the kicker text against the scrim, or the text on the
185
+ * accent box); null without the accent.
186
+ */
187
+ accent: { style: "text" | "box"; contrast: number } | null;
168
188
  }
169
189
 
170
190
  /** The text a cover draws, by layout. */
@@ -193,9 +213,16 @@ function getRegionRows(band: CoverBand, region: CoverRegion): { top: number; bot
193
213
  }
194
214
 
195
215
  /** The text the options ask for, or an error when the layout and the texts do not go together. */
196
- function resolveCoverText(options: { layout?: PhotoCoverLayout | undefined; caption?: string | undefined; kicker?: string | undefined; accent?: boolean | undefined }): OgResult<CoverText | null> {
216
+ function resolveCoverText(options: {
217
+ layout?: PhotoCoverLayout | undefined;
218
+ caption?: string | undefined;
219
+ kicker?: string | undefined;
220
+ accent?: boolean | undefined;
221
+ accentStyle?: PhotoCoverAccentStyle | undefined;
222
+ }): OgResult<CoverText | null> {
197
223
  const { caption, kicker } = options;
198
224
  const layout = options.layout ?? (caption === undefined ? "photo" : "title-bottom");
225
+ if (options.accentStyle !== undefined && options.accent !== true) return err("the accentStyle needs accent: true; leave it out or set the accent");
199
226
  if (options.accent === true && layout !== "kicker-title" && layout !== "pill") {
200
227
  return err(`the accent is drawn only by the layouts "kicker-title" and "pill", not "${layout}"; leave it out`);
201
228
  }
@@ -222,22 +249,6 @@ function readPhoto(photo: string | Buffer): OgResult<Buffer> {
222
249
  }
223
250
  }
224
251
 
225
- /** Relative luminance (WCAG) of an opaque `#rrggbb`. */
226
- function getLuminance(color: string): number {
227
- const hex = toOpaqueHex(color);
228
- const channel = (offset: number) => {
229
- const value = Number.parseInt(hex.slice(offset, offset + 2), 16) / 255;
230
- return value <= 0.039_28 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
231
- };
232
- return 0.2126 * channel(1) + 0.7152 * channel(3) + 0.0722 * channel(5);
233
- }
234
-
235
- /** The WCAG contrast ratio of two opaque colours, 1 to 21. */
236
- function getContrast(first: string, second: string): number {
237
- const [lighter, darker] = [getLuminance(first), getLuminance(second)].sort((a, b) => b - a) as [number, number];
238
- return (lighter + 0.05) / (darker + 0.05);
239
- }
240
-
241
252
  /** A contrast ratio as errors write it, rounded down so a ratio just under the bound never reads as the bound. */
242
253
  const describeContrast = (ratio: number) => `${(Math.floor(ratio * 100) / 100).toFixed(2)}:1`;
243
254
 
@@ -248,36 +259,50 @@ interface CoverInk {
248
259
  /** The scrim and the shadow. */
249
260
  shade: string;
250
261
  kicker: string;
262
+ /** The box behind the kicker (a boxed accent); null for none. */
263
+ kickerBox: string | null;
251
264
  pill: { box: string; alpha: number; text: string };
265
+ /** How the accent was drawn and the contrast it reads at; null without the accent. */
266
+ accent: { style: "text" | "box"; contrast: number } | null;
252
267
  }
253
268
 
254
269
  /**
255
270
  * The cover's colours: the text the brand's light colour and the scrim the dark one, swapped for a `dark` tone; with
256
271
  * the accent, the kicker or the pill box in `colors.accent`. An error when the accent reads under 3:1.
257
272
  */
258
- function getCoverInk(colors: BrandColors, options: { tone: PhotoCoverTone; layout: CoverText["layout"] | null; accent: boolean }): OgResult<CoverInk> {
273
+ function getCoverInk(colors: BrandColors, options: { tone: PhotoCoverTone; layout: CoverText["layout"] | null; accent: boolean; accentStyle: PhotoCoverAccentStyle }): OgResult<CoverInk> {
259
274
  const foreground = toOpaqueHex(colors.foreground);
260
275
  const background = toOpaqueHex(colors.background);
261
- const [light, dark] = getLuminance(foreground) >= getLuminance(background) ? [foreground, background] : [background, foreground];
276
+ const [light, dark] = getRelativeLuminance(foreground) >= getRelativeLuminance(background) ? [foreground, background] : [background, foreground];
262
277
  const [text, shade] = options.tone === "light" ? [light, dark] : [dark, light];
263
- const plain: CoverInk = { text, shade, kicker: text, pill: { box: shade, alpha: PILL_ALPHA, text } };
278
+ const plain: CoverInk = { text, shade, kicker: text, kickerBox: null, pill: { box: shade, alpha: PILL_ALPHA, text }, accent: null };
264
279
  if (!options.accent) return ok(plain);
265
280
  const accent = toOpaqueHex(colors.accent);
281
+ // The better-reading of the light and dark colour on the accent, for text set on an accent box.
282
+ const label = getContrastRatio(accent, light) >= getContrastRatio(accent, dark) ? light : dark;
283
+ const boxRatio = getContrastRatio(accent, label);
266
284
  if (options.layout === "kicker-title") {
267
- const ratio = getContrast(accent, shade);
268
- if (ratio < MIN_COVER_ACCENT_CONTRAST) {
269
- return err(`the accent ${accent} has a contrast of ${describeContrast(ratio)} against the scrim ${shade}, under 3:1; pick a ${getLuminance(accent) < getLuminance(shade) ? "darker" : "lighter"} accent or the other tone`);
285
+ const ratio = getContrastRatio(accent, shade);
286
+ const style = options.accentStyle === "auto" ? (ratio >= MIN_COVER_ACCENT_CONTRAST ? "text" : "box") : options.accentStyle;
287
+ if (style === "text") {
288
+ if (ratio < MIN_COVER_ACCENT_CONTRAST) {
289
+ return err(
290
+ `the accent ${accent} has a contrast of ${describeContrast(ratio)} against the scrim ${shade}, under 3:1; pick a ${getRelativeLuminance(accent) < getRelativeLuminance(shade) ? "darker" : "lighter"} accent, the other tone or accentStyle "box"`,
291
+ );
292
+ }
293
+ return ok({ ...plain, kicker: accent, accent: { style: "text", contrast: ratio } });
294
+ }
295
+ if (boxRatio < MIN_COVER_ACCENT_CONTRAST) {
296
+ return err(`the accent ${accent} as a box has a contrast of ${describeContrast(boxRatio)} against the kicker ${label}, under 3:1; pick an accent that reads with the foreground or the background`);
270
297
  }
271
- return ok({ ...plain, kicker: accent });
298
+ return ok({ ...plain, kicker: label, kickerBox: accent, accent: { style: "box", contrast: boxRatio } });
272
299
  }
273
300
  if (options.layout === "pill") {
274
- const label = getContrast(accent, light) >= getContrast(accent, dark) ? light : dark;
275
- const ratio = getContrast(accent, label);
276
- if (ratio < MIN_COVER_ACCENT_CONTRAST) {
277
- return err(`the accent ${accent} has a contrast of ${describeContrast(ratio)} against the pill label ${label}, under 3:1; pick an accent that reads with the foreground or the background`);
301
+ if (boxRatio < MIN_COVER_ACCENT_CONTRAST) {
302
+ return err(`the accent ${accent} has a contrast of ${describeContrast(boxRatio)} against the pill label ${label}, under 3:1; pick an accent that reads with the foreground or the background`);
278
303
  }
279
304
  // Opaque, so the contrast checked is the contrast drawn whatever the photo under it.
280
- return ok({ ...plain, pill: { box: accent, alpha: 0xff, text: label } });
305
+ return ok({ ...plain, pill: { box: accent, alpha: 0xff, text: label }, accent: { style: "box", contrast: boxRatio } });
281
306
  }
282
307
  return ok(plain);
283
308
  }
@@ -336,7 +361,31 @@ function buildTextTree(layout: TextLayout): OgNode {
336
361
  ]
337
362
  : [
338
363
  ...(text.layout === "kicker-title"
339
- ? [line(text.kicker, { color: ink.kicker, fontSize: Math.round(KICKER_SIZE * scale), lineHeight: 1.2, letterSpacing: Math.round(3 * scale), marginBottom: Math.round(KICKER_GAP * scale), textShadow: shadow })]
364
+ ? [
365
+ ink.kickerBox === null
366
+ ? line(text.kicker, { color: ink.kicker, fontSize: Math.round(KICKER_SIZE * scale), lineHeight: 1.2, letterSpacing: Math.round(3 * scale), marginBottom: Math.round(KICKER_GAP * scale), textShadow: shadow })
367
+ : h(
368
+ "div",
369
+ {
370
+ style: {
371
+ display: "flex",
372
+ maxWidth: "100%",
373
+ padding: `${String(Math.round(KICKER_BOX_PADDING[0] * scale))}px ${String(Math.round(KICKER_BOX_PADDING[1] * scale))}px`,
374
+ borderRadius: Math.round(KICKER_BOX_RADIUS * scale),
375
+ backgroundColor: ink.kickerBox,
376
+ textAlign: "center",
377
+ wordBreak: "break-word",
378
+ color: ink.kicker,
379
+ fontSize: Math.round(KICKER_SIZE * scale),
380
+ lineHeight: 1.2,
381
+ letterSpacing: Math.round(3 * scale),
382
+ marginBottom: Math.round(KICKER_GAP * scale),
383
+ ...font,
384
+ },
385
+ },
386
+ text.kicker,
387
+ ),
388
+ ]
340
389
  : []),
341
390
  line(text.caption, { fontSize: Math.round(getCoverCaptionSize(text.caption) * scale), lineHeight: 1.08, textShadow: shadow }),
342
391
  ];
@@ -473,6 +522,7 @@ export async function renderPhotoCover(input: PhotoCoverInput): Promise<OgResult
473
522
  kicker: input.kicker,
474
523
  tone: input.tone,
475
524
  accent: input.accent,
525
+ accentStyle: input.accentStyle,
476
526
  quality: input.quality,
477
527
  });
478
528
  if (!parsed.success) {
@@ -490,7 +540,7 @@ export async function renderPhotoCover(input: PhotoCoverInput): Promise<OgResult
490
540
  const size = options.size;
491
541
  const [width, height] = size;
492
542
  const band = getCoverBand(size);
493
- const ink = getCoverInk(input.colors, { tone: options.tone ?? "light", layout: text.value?.layout ?? null, accent: options.accent ?? false });
543
+ const ink = getCoverInk(input.colors, { tone: options.tone ?? "light", layout: text.value?.layout ?? null, accent: options.accent ?? false, accentStyle: options.accentStyle ?? "text" });
494
544
  if (!ink.ok) return err(`${name}: ${ink.error}.`);
495
545
  const drawn = text.value === null ? null : await layOutText({ size, band, text: text.value, fonts: input.fonts, ink: ink.value });
496
546
  if (drawn !== null && !drawn.ok) return err(`${name}: ${drawn.error}.`);
@@ -514,7 +564,7 @@ export async function renderPhotoCover(input: PhotoCoverInput): Promise<OgResult
514
564
  try {
515
565
  const image = new Resvg(svg, { fitTo: { mode: "original" }, font: { loadSystemFonts: false } }).render();
516
566
  const encoded = jpeg.encode({ data: Buffer.from(image.pixels), width: image.width, height: image.height }, options.quality).data;
517
- return ok({ jpeg: encoded, width: image.width, height: image.height, bytes: encoded.length, textBox: drawn === null ? null : { ...drawn.value.box }, focusPoint });
567
+ return ok({ jpeg: encoded, width: image.width, height: image.height, bytes: encoded.length, textBox: drawn === null ? null : { ...drawn.value.box }, focusPoint, accent: ink.value.accent });
518
568
  } catch (error) {
519
569
  return err(`${name}: drawing the cover failed: ${error instanceof Error ? error.message : String(error)}.`);
520
570
  }
@@ -8,7 +8,7 @@ import { dirname, join } from "node:path";
8
8
  * with the current Node, never through `npx`.
9
9
  */
10
10
 
11
- export const HYPERFRAMES_VERSION = "0.9.6";
11
+ export const HYPERFRAMES_VERSION = "0.9.20";
12
12
 
13
13
  const require = createRequire(import.meta.url);
14
14