@softure-ai/marketing-kit 0.21.1 → 0.22.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 +31 -0
- package/NOTICE +11 -0
- package/README.md +35 -4
- package/dist/config/actions-schema.d.ts +35 -35
- package/dist/config/brand.d.ts.map +1 -1
- package/dist/config/brand.js +22 -1
- package/dist/config/brand.js.map +1 -1
- package/dist/config/colors.d.ts +12 -2
- package/dist/config/colors.d.ts.map +1 -1
- package/dist/config/colors.js +32 -0
- package/dist/config/colors.js.map +1 -1
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +2 -0
- package/dist/config/config.js.map +1 -1
- package/dist/config/schema.d.ts +181 -172
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +16 -4
- package/dist/config/schema.js.map +1 -1
- package/dist/config/shot-steps.d.ts +40 -40
- package/dist/footage/caption-highlight.d.ts +44 -0
- package/dist/footage/caption-highlight.d.ts.map +1 -0
- package/dist/footage/caption-highlight.js +29 -0
- package/dist/footage/caption-highlight.js.map +1 -0
- package/dist/footage/compose.d.ts +3 -0
- package/dist/footage/compose.d.ts.map +1 -1
- package/dist/footage/compose.js +33 -6
- package/dist/footage/compose.js.map +1 -1
- package/dist/footage/draft-color.d.ts +6 -0
- package/dist/footage/draft-color.d.ts.map +1 -0
- package/dist/footage/draft-color.js +14 -0
- package/dist/footage/draft-color.js.map +1 -0
- package/dist/footage/draft-overlays.d.ts +12 -0
- package/dist/footage/draft-overlays.d.ts.map +1 -0
- package/dist/footage/draft-overlays.js +83 -0
- package/dist/footage/draft-overlays.js.map +1 -0
- package/dist/footage/draft.d.ts +27 -9
- package/dist/footage/draft.d.ts.map +1 -1
- package/dist/footage/draft.js +99 -37
- package/dist/footage/draft.js.map +1 -1
- package/dist/footage/edl.d.ts +41 -0
- package/dist/footage/edl.d.ts.map +1 -1
- package/dist/footage/edl.js +10 -0
- package/dist/footage/edl.js.map +1 -1
- package/dist/footage/film.d.ts +14 -0
- package/dist/footage/film.d.ts.map +1 -1
- package/dist/footage/film.js +2 -0
- package/dist/footage/film.js.map +1 -1
- package/dist/footage/isolate-ranges.js +1 -1
- package/dist/footage/isolate-ranges.js.map +1 -1
- package/dist/footage/overlay-html.d.ts +29 -0
- package/dist/footage/overlay-html.d.ts.map +1 -0
- package/dist/footage/overlay-html.js +112 -0
- package/dist/footage/overlay-html.js.map +1 -0
- package/dist/footage/overlay-schema.d.ts +97 -0
- package/dist/footage/overlay-schema.d.ts.map +1 -0
- package/dist/footage/overlay-schema.js +104 -0
- package/dist/footage/overlay-schema.js.map +1 -0
- package/dist/footage/overlays.d.ts +112 -0
- package/dist/footage/overlays.d.ts.map +1 -0
- package/dist/footage/overlays.js +222 -0
- package/dist/footage/overlays.js.map +1 -0
- package/dist/footage/pipeline.d.ts.map +1 -1
- package/dist/footage/pipeline.js +10 -1
- package/dist/footage/pipeline.js.map +1 -1
- package/dist/footage/speech-ranges.d.ts +8 -3
- package/dist/footage/speech-ranges.d.ts.map +1 -1
- package/dist/footage/speech-ranges.js +7 -4
- package/dist/footage/speech-ranges.js.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/dist/og/index.d.ts +1 -1
- package/dist/og/index.d.ts.map +1 -1
- package/dist/og/index.js +1 -1
- package/dist/og/index.js.map +1 -1
- package/dist/og/photo-cover.d.ts +18 -1
- package/dist/og/photo-cover.d.ts.map +1 -1
- package/dist/og/photo-cover.js +56 -28
- package/dist/og/photo-cover.js.map +1 -1
- package/dist/render/hyperframes.d.ts +1 -1
- package/dist/render/hyperframes.d.ts.map +1 -1
- package/dist/render/hyperframes.js +1 -1
- package/dist/render/hyperframes.js.map +1 -1
- package/package.json +3 -2
- package/schema/edl.schema.json +130 -0
- package/schema/marketing.schema.json +33 -0
- package/src/config/brand.ts +20 -1
- package/src/config/colors.ts +39 -2
- package/src/config/config.ts +2 -0
- package/src/config/schema.ts +19 -7
- package/src/footage/caption-highlight.ts +52 -0
- package/src/footage/compose.ts +40 -6
- package/src/footage/draft-color.ts +12 -0
- package/src/footage/draft-overlays.ts +91 -0
- package/src/footage/draft.ts +117 -39
- package/src/footage/edl.ts +17 -0
- package/src/footage/film.ts +16 -0
- package/src/footage/isolate-ranges.ts +1 -1
- package/src/footage/overlay-html.ts +127 -0
- package/src/footage/overlay-schema.ts +146 -0
- package/src/footage/overlays.ts +272 -0
- package/src/footage/pipeline.ts +8 -1
- package/src/footage/speech-ranges.ts +8 -5
- package/src/index.ts +56 -1
- package/src/og/index.ts +2 -0
- package/src/og/photo-cover.ts +83 -33
- 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 {
|
|
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";
|
|
@@ -219,6 +271,7 @@ export {
|
|
|
219
271
|
CAPTION_MIN_FONT_SCALE,
|
|
220
272
|
CAPTION_PRESETS,
|
|
221
273
|
CAPTION_STYLES,
|
|
274
|
+
CAPTION_HIGHLIGHT_STYLES,
|
|
222
275
|
DEFAULT_EDIT,
|
|
223
276
|
DEFAULT_END_CARD_SECONDS,
|
|
224
277
|
DEFAULT_LOGO_END_CARD_FADE_SECONDS,
|
|
@@ -230,6 +283,7 @@ export {
|
|
|
230
283
|
getFootageEdit,
|
|
231
284
|
type CaptionPreset,
|
|
232
285
|
type CaptionStyle,
|
|
286
|
+
type CaptionHighlightStyle,
|
|
233
287
|
type FootageEdit,
|
|
234
288
|
type ClipFit,
|
|
235
289
|
type ClipRole,
|
|
@@ -435,6 +489,7 @@ export { buildFilmMixArgs, type FilmMixInput } from "./footage/film-mix.js";
|
|
|
435
489
|
export { buildCutPreviewArgs, buildLastFrameArgs, buildMusicArgs, buildSpeechArgs, getSpeechCutOptions, type SpeechCutOptions } from "./footage/render.js";
|
|
436
490
|
export {
|
|
437
491
|
FOOTAGE_DRAFT_CAPTION_COLORS,
|
|
492
|
+
FOOTAGE_DRAFT_OVERLAY_COLORS,
|
|
438
493
|
FOOTAGE_DRAFT_FONT,
|
|
439
494
|
FOOTAGE_DRAFT_WIDTH,
|
|
440
495
|
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,
|
package/src/og/photo-cover.ts
CHANGED
|
@@ -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
|
|
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: {
|
|
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] =
|
|
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 =
|
|
268
|
-
|
|
269
|
-
|
|
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
|
-
|
|
275
|
-
|
|
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
|
-
? [
|
|
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
|
}
|