@tradalab/mediakit 1.0.0 → 1.2.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.
@@ -0,0 +1,152 @@
1
+ // src/layout.ts
2
+ var TRANSITIONS = [
3
+ "cut",
4
+ "fade",
5
+ "fadeThrough",
6
+ "slideLeft",
7
+ "slideRight",
8
+ "slideUp",
9
+ "slideDown",
10
+ "pushLeft",
11
+ "pushRight",
12
+ "wipeLeft",
13
+ "wipeRight",
14
+ "iris",
15
+ "zoom"
16
+ ];
17
+ var BLEND_MODES = ["normal", "add", "screen", "multiply", "overlay", "darken", "lighten"];
18
+ var FITS = ["stretch", "contain", "cover"];
19
+ var SHAPES = ["rect", "rounded", "ellipse"];
20
+ var DEG = Math.PI / 180;
21
+ function coreLayer(l, slot) {
22
+ const s = l.source === void 0 ? -1 : slot(l.source);
23
+ const missing = l.source !== void 0 && s < 0;
24
+ const kind = l.source !== void 0 ? 0 : l.color2 !== void 0 ? 2 : 1;
25
+ const fit = FITS.indexOf(l.fit ?? "cover");
26
+ const sh = l.shadow;
27
+ return {
28
+ id: l.id,
29
+ kind,
30
+ source: Math.max(0, s),
31
+ x: l.x,
32
+ y: l.y,
33
+ w: l.w,
34
+ h: l.h,
35
+ rotation: (l.rotation ?? 0) * DEG,
36
+ opacity: l.hidden || missing ? 0 : l.opacity ?? 1,
37
+ fit: fit < 0 ? FITS.indexOf("cover") : fit,
38
+ cropLeft: l.crop?.left ?? 0,
39
+ cropTop: l.crop?.top ?? 0,
40
+ cropRight: l.crop?.right ?? 0,
41
+ cropBottom: l.crop?.bottom ?? 0,
42
+ flipX: !!l.flipX,
43
+ flipY: !!l.flipY,
44
+ shape: Math.max(0, SHAPES.indexOf(l.shape ?? "rect")),
45
+ radius: l.radius ?? 0,
46
+ border: l.border?.width ?? 0,
47
+ borderColor: l.border ? parseColor(l.border.color) : [0, 0, 0, 0],
48
+ shadow: sh?.blur ?? 0,
49
+ shadowX: sh?.x ?? 0,
50
+ shadowY: sh?.y ?? 0,
51
+ shadowAlpha: sh ? sh.opacity ?? 0.5 : 0,
52
+ blend: Math.max(0, BLEND_MODES.indexOf(l.blend ?? "normal")),
53
+ color: l.color !== void 0 ? parseColor(l.color) : [0, 0, 0, 1],
54
+ color2: l.color2 !== void 0 ? parseColor(l.color2) : [0, 0, 0, 1],
55
+ angle: (l.gradientAngle ?? 0) * DEG,
56
+ exposure: l.tone?.exposure ?? 0,
57
+ contrast: l.tone?.contrast ?? 0,
58
+ saturation: l.tone?.saturation ?? 0,
59
+ warmth: l.tone?.warmth ?? 0,
60
+ key: !!l.key,
61
+ keyColor: l.key ? parseColor(l.key.color).slice(0, 3) : [0, 0, 0],
62
+ keyTolerance: l.key?.tolerance ?? 0
63
+ };
64
+ }
65
+ function parseColor(c) {
66
+ if (Array.isArray(c)) return [c[0] ?? 0, c[1] ?? 0, c[2] ?? 0, c[3] ?? 1];
67
+ let h = c.trim().replace(/^#/, "");
68
+ if (h.length === 3 || h.length === 4) h = [...h].map((x) => x + x).join("");
69
+ if (!/^[0-9a-f]{6}([0-9a-f]{2})?$/i.test(h)) return [0, 0, 0, 1];
70
+ const n = (i) => parseInt(h.slice(i, i + 2), 16) / 255;
71
+ return [n(0), n(2), n(4), h.length === 8 ? n(6) : 1];
72
+ }
73
+ function hitTest(layers, x, y, aspect) {
74
+ for (let i = layers.length - 1; i >= 0; i--) {
75
+ const l = layers[i];
76
+ if (l.hidden || (l.opacity ?? 1) <= 0) continue;
77
+ const cx = (l.x + l.w / 2) * aspect;
78
+ const cy = l.y + l.h / 2;
79
+ const a = (l.rotation ?? 0) * DEG;
80
+ const dx = x * aspect - cx;
81
+ const dy = y - cy;
82
+ const lx = Math.cos(a) * dx + Math.sin(a) * dy;
83
+ const ly = -Math.sin(a) * dx + Math.cos(a) * dy;
84
+ if (Math.abs(lx) <= l.w * aspect / 2 && Math.abs(ly) <= l.h / 2) return l;
85
+ }
86
+ return void 0;
87
+ }
88
+ var layouts = {
89
+ full() {
90
+ return { x: 0, y: 0, w: 1, h: 1 };
91
+ },
92
+ /**
93
+ * A picture in picture in one corner. `size` is the inset's height as a share of the output,
94
+ * `aspect` its width over height (16:9 by default, 1 for a circle), `margin` the gap to the
95
+ * edges in output heights. `outputAspect` is the output's width over height.
96
+ */
97
+ pip(corner = "bottom-right", size = 0.28, aspect = 16 / 9, margin = 0.03, outputAspect = 16 / 9) {
98
+ const h = size;
99
+ const w = size * aspect / outputAspect;
100
+ const mx = margin / outputAspect;
101
+ const x = corner.endsWith("left") ? mx : 1 - mx - w;
102
+ const y = corner.startsWith("top") ? margin : 1 - margin - h;
103
+ return { x, y, w, h };
104
+ },
105
+ /** The i-th of n equal columns, with a gap between them in output widths. */
106
+ columns(i, n = 2, gap = 0) {
107
+ const w = (1 - gap * (n - 1)) / n;
108
+ return { x: i * (w + gap), y: 0, w, h: 1 };
109
+ },
110
+ /** The i-th cell of the most square grid that holds n, filled row by row. */
111
+ grid(i, n, gap = 0.01) {
112
+ n = Math.max(1, n);
113
+ const cols = Math.ceil(Math.sqrt(n));
114
+ const rows = Math.ceil(n / cols);
115
+ const w = (1 - gap * (cols + 1)) / cols;
116
+ const h = (1 - gap * (rows + 1)) / rows;
117
+ const c = i % cols;
118
+ const r = Math.floor(i / cols);
119
+ const inRow = r === rows - 1 ? n - cols * (rows - 1) : cols;
120
+ const offset = (cols - inRow) * (w + gap) / 2;
121
+ return { x: gap + offset + c * (w + gap), y: gap + r * (h + gap), w, h };
122
+ },
123
+ /** A name bar across the lower part of the picture, broadcast style. */
124
+ lowerThird(width = 0.45, height = 0.11, margin = 0.04) {
125
+ return { x: margin, y: 1 - margin - height, w: width, h: height };
126
+ },
127
+ /**
128
+ * Presenter: the shared content large on one side, the presenter on the other. With a
129
+ * `cutout` camera the presenter stands over the content's edge.
130
+ *
131
+ * The person's rect has the camera's own shape (`cameraAspect`) and sits on the bottom edge:
132
+ * any other shape makes `contain` shrink the picture, and its bottom then cuts across the
133
+ * shoulders in mid-air.
134
+ */
135
+ presenter(side = "right", cameraAspect = 16 / 9, outputAspect = 16 / 9) {
136
+ const content = { x: side === "right" ? 0.02 : 0.3, y: 0.08, w: 0.68, h: 0.84 };
137
+ const h = 0.6;
138
+ const w = h * cameraAspect / outputAspect;
139
+ const person = { x: side === "right" ? 0.97 - w * 0.75 : 0.03 - w * 0.25, y: 1 - h, w, h };
140
+ return { content, person };
141
+ }
142
+ };
143
+
144
+ export {
145
+ TRANSITIONS,
146
+ BLEND_MODES,
147
+ coreLayer,
148
+ parseColor,
149
+ hitTest,
150
+ layouts
151
+ };
152
+ //# sourceMappingURL=chunk-BMIOUOT3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/layout.ts"],"sourcesContent":["/**\n * The vocabulary of a {@link Scene}: layers, transitions and ready-made layouts.\n *\n * Its own entry point (`@tradalab/mediakit/layout`) for the reason `recipe` is one: a layout\n * picker or a layer list is UI, and reaching this through the root would pull the wasm loader and\n * MediaPipe into every module that only wants to name a corner.\n */\n\n/** A colour: CSS hex (`#rgb`, `#rrggbb`, `#rrggbbaa`) or channels 0..1. */\nexport type Color = string | [number, number, number] | [number, number, number, number]\n\nexport type BlendMode = \"normal\" | \"add\" | \"screen\" | \"multiply\" | \"overlay\" | \"darken\" | \"lighten\"\n\n/** A placement in fractions of the output, origin top left. */\nexport interface Rect {\n x: number\n y: number\n w: number\n h: number\n}\n\n/**\n * One thing drawn on the output. Three kinds, told apart by what is set: `source` shows a\n * source, `color2` makes a gradient, otherwise `color` fills the shape.\n */\nexport interface SceneLayer extends Rect {\n /** Stable across changes: an animation moves the layer with the same id. */\n id: number\n /** A source id given to `Scene.addSource`. */\n source?: string\n color?: Color\n color2?: Color\n /** Gradient direction in degrees, 0 running left to right. */\n gradientAngle?: number\n /** Degrees, clockwise, about the centre. */\n rotation?: number\n /** 0..1, default 1. */\n opacity?: number\n /**\n * How a source fills the rect. Default `cover`: never distorted, never letterboxed. `contain`\n * shrinks the rect to the picture, so shape, border and shadow follow the picture.\n */\n fit?: \"stretch\" | \"contain\" | \"cover\"\n /** Fractions of the source to cut off, before fitting. */\n crop?: { left?: number; top?: number; right?: number; bottom?: number }\n flipX?: boolean\n flipY?: boolean\n shape?: \"rect\" | \"rounded\" | \"ellipse\"\n /** Corner radius for `rounded`, as a share of the shorter side, 0..0.5. */\n radius?: number\n /** Width in output heights: 0.005 is about 4 px at 720p. */\n border?: { width: number; color: Color }\n /** Softness and offset in output heights. */\n shadow?: { blur: number; x?: number; y?: number; opacity?: number }\n blend?: BlendMode\n /** -1..1 each, the camera recipe's colour knobs. */\n tone?: { exposure?: number; contrast?: number; saturation?: number; warmth?: number }\n /** Remove a colour from the source - a green-screen clip, say. Tolerance -1..1. */\n key?: { color: Color; tolerance?: number }\n hidden?: boolean\n}\n\nexport type TransitionKind =\n | \"cut\"\n | \"fade\"\n | \"fadeThrough\"\n | \"slideLeft\"\n | \"slideRight\"\n | \"slideUp\"\n | \"slideDown\"\n | \"pushLeft\"\n | \"pushRight\"\n | \"wipeLeft\"\n | \"wipeRight\"\n | \"iris\"\n | \"zoom\"\n\n/** In the order of `scene.Transition` in core/scene/scene.go. */\nexport const TRANSITIONS: readonly TransitionKind[] = [\n \"cut\",\n \"fade\",\n \"fadeThrough\",\n \"slideLeft\",\n \"slideRight\",\n \"slideUp\",\n \"slideDown\",\n \"pushLeft\",\n \"pushRight\",\n \"wipeLeft\",\n \"wipeRight\",\n \"iris\",\n \"zoom\",\n]\n\n/** In the order of `scene.Blend`. */\nexport const BLEND_MODES: readonly BlendMode[] = [\"normal\", \"add\", \"screen\", \"multiply\", \"overlay\", \"darken\", \"lighten\"]\n\nconst FITS = [\"stretch\", \"contain\", \"cover\"] as const\nconst SHAPES = [\"rect\", \"rounded\", \"ellipse\"] as const\n\n/** The layer in the shape the Go core takes. Field names must match `readLayers` in wasmjs/main.go. */\nexport interface CoreLayer {\n id: number\n kind: number\n source: number\n x: number\n y: number\n w: number\n h: number\n rotation: number\n opacity: number\n fit: number\n cropLeft: number\n cropTop: number\n cropRight: number\n cropBottom: number\n flipX: boolean\n flipY: boolean\n shape: number\n radius: number\n border: number\n borderColor: number[]\n shadow: number\n shadowX: number\n shadowY: number\n shadowAlpha: number\n blend: number\n color: number[]\n color2: number[]\n angle: number\n exposure: number\n contrast: number\n saturation: number\n warmth: number\n key: boolean\n keyColor: number[]\n keyTolerance: number\n}\n\nconst DEG = Math.PI / 180\n\n/**\n * `slot` maps a source id to its slot, or -1 when the source is not there. Such a layer is sent\n * with opacity 0: sending its slot as 0 would show whatever source happens to sit in slot 0.\n */\nexport function coreLayer(l: SceneLayer, slot: (id: string) => number): CoreLayer {\n const s = l.source === undefined ? -1 : slot(l.source)\n const missing = l.source !== undefined && s < 0\n const kind = l.source !== undefined ? 0 : l.color2 !== undefined ? 2 : 1\n // An unknown name takes the documented default, cover - not whatever -1 becomes in Go.\n const fit = FITS.indexOf(l.fit ?? \"cover\")\n const sh = l.shadow\n return {\n id: l.id,\n kind,\n source: Math.max(0, s),\n x: l.x,\n y: l.y,\n w: l.w,\n h: l.h,\n rotation: (l.rotation ?? 0) * DEG,\n opacity: l.hidden || missing ? 0 : (l.opacity ?? 1),\n fit: fit < 0 ? FITS.indexOf(\"cover\") : fit,\n cropLeft: l.crop?.left ?? 0,\n cropTop: l.crop?.top ?? 0,\n cropRight: l.crop?.right ?? 0,\n cropBottom: l.crop?.bottom ?? 0,\n flipX: !!l.flipX,\n flipY: !!l.flipY,\n shape: Math.max(0, SHAPES.indexOf(l.shape ?? \"rect\")),\n radius: l.radius ?? 0,\n border: l.border?.width ?? 0,\n borderColor: l.border ? parseColor(l.border.color) : [0, 0, 0, 0],\n shadow: sh?.blur ?? 0,\n shadowX: sh?.x ?? 0,\n shadowY: sh?.y ?? 0,\n shadowAlpha: sh ? (sh.opacity ?? 0.5) : 0,\n blend: Math.max(0, BLEND_MODES.indexOf(l.blend ?? \"normal\")),\n color: l.color !== undefined ? parseColor(l.color) : [0, 0, 0, 1],\n color2: l.color2 !== undefined ? parseColor(l.color2) : [0, 0, 0, 1],\n angle: (l.gradientAngle ?? 0) * DEG,\n exposure: l.tone?.exposure ?? 0,\n contrast: l.tone?.contrast ?? 0,\n saturation: l.tone?.saturation ?? 0,\n warmth: l.tone?.warmth ?? 0,\n key: !!l.key,\n keyColor: l.key ? parseColor(l.key.color).slice(0, 3) : [0, 0, 0],\n keyTolerance: l.key?.tolerance ?? 0,\n }\n}\n\n/** A colour as four channels 0..1. Unreadable input is opaque black, never a throw mid-frame. */\nexport function parseColor(c: Color): [number, number, number, number] {\n if (Array.isArray(c)) return [c[0] ?? 0, c[1] ?? 0, c[2] ?? 0, c[3] ?? 1]\n let h = c.trim().replace(/^#/, \"\")\n if (h.length === 3 || h.length === 4) h = [...h].map((x) => x + x).join(\"\")\n if (!/^[0-9a-f]{6}([0-9a-f]{2})?$/i.test(h)) return [0, 0, 0, 1]\n const n = (i: number) => parseInt(h.slice(i, i + 2), 16) / 255\n return [n(0), n(2), n(4), h.length === 8 ? n(6) : 1]\n}\n\n/**\n * The topmost visible layer under a point of the output (fractions, top left), rotation\n * included, for a host that lets people pick and drag layers. `aspect` is the output's\n * width over height, needed because rotation turns in pixels, not fractions.\n */\nexport function hitTest(layers: readonly SceneLayer[], x: number, y: number, aspect: number): SceneLayer | undefined {\n for (let i = layers.length - 1; i >= 0; i--) {\n const l = layers[i]!\n if (l.hidden || (l.opacity ?? 1) <= 0) continue\n const cx = (l.x + l.w / 2) * aspect\n const cy = l.y + l.h / 2\n const a = (l.rotation ?? 0) * DEG\n const dx = x * aspect - cx\n const dy = y - cy\n const lx = Math.cos(a) * dx + Math.sin(a) * dy\n const ly = -Math.sin(a) * dx + Math.cos(a) * dy\n if (Math.abs(lx) <= (l.w * aspect) / 2 && Math.abs(ly) <= l.h / 2) return l\n }\n return undefined\n}\n\n/** Ready-made placements. Every one returns a {@link Rect}; spread it into a layer. */\nexport const layouts = {\n full(): Rect {\n return { x: 0, y: 0, w: 1, h: 1 }\n },\n\n /**\n * A picture in picture in one corner. `size` is the inset's height as a share of the output,\n * `aspect` its width over height (16:9 by default, 1 for a circle), `margin` the gap to the\n * edges in output heights. `outputAspect` is the output's width over height.\n */\n pip(\n corner: \"top-left\" | \"top-right\" | \"bottom-left\" | \"bottom-right\" = \"bottom-right\",\n size = 0.28,\n aspect = 16 / 9,\n margin = 0.03,\n outputAspect = 16 / 9,\n ): Rect {\n const h = size\n const w = (size * aspect) / outputAspect\n const mx = margin / outputAspect\n const x = corner.endsWith(\"left\") ? mx : 1 - mx - w\n const y = corner.startsWith(\"top\") ? margin : 1 - margin - h\n return { x, y, w, h }\n },\n\n /** The i-th of n equal columns, with a gap between them in output widths. */\n columns(i: number, n = 2, gap = 0): Rect {\n const w = (1 - gap * (n - 1)) / n\n return { x: i * (w + gap), y: 0, w, h: 1 }\n },\n\n /** The i-th cell of the most square grid that holds n, filled row by row. */\n grid(i: number, n: number, gap = 0.01): Rect {\n n = Math.max(1, n)\n const cols = Math.ceil(Math.sqrt(n))\n const rows = Math.ceil(n / cols)\n const w = (1 - gap * (cols + 1)) / cols\n const h = (1 - gap * (rows + 1)) / rows\n const c = i % cols\n const r = Math.floor(i / cols)\n // The last row centres whatever it holds, as a video call grid does.\n const inRow = r === rows - 1 ? n - cols * (rows - 1) : cols\n const offset = ((cols - inRow) * (w + gap)) / 2\n return { x: gap + offset + c * (w + gap), y: gap + r * (h + gap), w, h }\n },\n\n /** A name bar across the lower part of the picture, broadcast style. */\n lowerThird(width = 0.45, height = 0.11, margin = 0.04): Rect {\n return { x: margin, y: 1 - margin - height, w: width, h: height }\n },\n\n /**\n * Presenter: the shared content large on one side, the presenter on the other. With a\n * `cutout` camera the presenter stands over the content's edge.\n *\n * The person's rect has the camera's own shape (`cameraAspect`) and sits on the bottom edge:\n * any other shape makes `contain` shrink the picture, and its bottom then cuts across the\n * shoulders in mid-air.\n */\n presenter(side: \"left\" | \"right\" = \"right\", cameraAspect = 16 / 9, outputAspect = 16 / 9): { content: Rect; person: Rect } {\n const content = { x: side === \"right\" ? 0.02 : 0.3, y: 0.08, w: 0.68, h: 0.84 }\n const h = 0.6\n const w = (h * cameraAspect) / outputAspect\n const person = { x: side === \"right\" ? 0.97 - w * 0.75 : 0.03 - w * 0.25, y: 1 - h, w, h }\n return { content, person }\n },\n}\n"],"mappings":";AA8EO,IAAM,cAAyC;AAAA,EAClD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ;AAGO,IAAM,cAAoC,CAAC,UAAU,OAAO,UAAU,YAAY,WAAW,UAAU,SAAS;AAEvH,IAAM,OAAO,CAAC,WAAW,WAAW,OAAO;AAC3C,IAAM,SAAS,CAAC,QAAQ,WAAW,SAAS;AAyC5C,IAAM,MAAM,KAAK,KAAK;AAMf,SAAS,UAAU,GAAe,MAAyC;AAC9E,QAAM,IAAI,EAAE,WAAW,SAAY,KAAK,KAAK,EAAE,MAAM;AACrD,QAAM,UAAU,EAAE,WAAW,UAAa,IAAI;AAC9C,QAAM,OAAO,EAAE,WAAW,SAAY,IAAI,EAAE,WAAW,SAAY,IAAI;AAEvE,QAAM,MAAM,KAAK,QAAQ,EAAE,OAAO,OAAO;AACzC,QAAM,KAAK,EAAE;AACb,SAAO;AAAA,IACH,IAAI,EAAE;AAAA,IACN;AAAA,IACA,QAAQ,KAAK,IAAI,GAAG,CAAC;AAAA,IACrB,GAAG,EAAE;AAAA,IACL,GAAG,EAAE;AAAA,IACL,GAAG,EAAE;AAAA,IACL,GAAG,EAAE;AAAA,IACL,WAAW,EAAE,YAAY,KAAK;AAAA,IAC9B,SAAS,EAAE,UAAU,UAAU,IAAK,EAAE,WAAW;AAAA,IACjD,KAAK,MAAM,IAAI,KAAK,QAAQ,OAAO,IAAI;AAAA,IACvC,UAAU,EAAE,MAAM,QAAQ;AAAA,IAC1B,SAAS,EAAE,MAAM,OA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AM,SAAS,MAAM,SAAS,MAAY;AACzD,WAAO,EAAE,GAAG,QAAQ,GAAG,IAAI,SAAS,QAAQ,GAAG,OAAO,GAAG,OAAO;AAAA,EACpE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,UAAU,OAAyB,SAAS,eAAe,KAAK,GAAG,eAAe,KAAK,GAAoC;AACvH,UAAM,UAAU,EAAE,GAAG,SAAS,UAAU,OAAO,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK;AAC9E,UAAM,IAAI;AACV,UAAM,IAAK,IAAI,eAAgB;AAC/B,UAAM,SAAS,EAAE,GAAG,SAAS,UAAU,OAAO,IAAI,OAAO,OAAO,IAAI,MAAM,GAAG,IAAI,GAAG,GAAG,EAAE;AACzF,WAAO,EAAE,SAAS,OAAO;AAAA,EAC7B;AACJ;","names":[]}
@@ -0,0 +1,128 @@
1
+ // src/recipe.ts
2
+ var NO_EFFECTS = {
3
+ beautify: 0,
4
+ exposure: 0,
5
+ contrast: 0,
6
+ saturation: 0,
7
+ warmth: 0,
8
+ autoframe: false,
9
+ teeth: 0,
10
+ eyeBright: 0,
11
+ underEye: 0,
12
+ smileLines: 0,
13
+ lips: 0,
14
+ lipColor: [0.55, 0.18, 0.24],
15
+ blush: 0,
16
+ blushColor: [0.9, 0.5, 0.42],
17
+ iris: 0,
18
+ irisColor: [0.3, 0.5, 0.75],
19
+ lut: "",
20
+ grade: 0,
21
+ chromaKey: false,
22
+ keyColor: [0, 0, 0],
23
+ keyTolerance: 0,
24
+ autoLight: false,
25
+ mirror: false,
26
+ slimFace: 0,
27
+ enlargeEyes: 0,
28
+ noseSlim: 0,
29
+ chin: 0
30
+ };
31
+ function touchUp(amount) {
32
+ const a = Math.min(1, Math.max(0, amount));
33
+ return {
34
+ beautify: a * TOUCH_UP.beautify,
35
+ eyeBright: a * TOUCH_UP.eyeBright,
36
+ underEye: a * TOUCH_UP.underEye,
37
+ smileLines: a * TOUCH_UP.smileLines,
38
+ teeth: a * TOUCH_UP.teeth
39
+ };
40
+ }
41
+ var TOUCH_UP = {
42
+ beautify: 0.6,
43
+ eyeBright: 0.5,
44
+ underEye: 0.45,
45
+ smileLines: 0.5,
46
+ teeth: 0.4
47
+ };
48
+ function touchUpAmount(e) {
49
+ let a = 0;
50
+ for (const k of Object.keys(TOUCH_UP)) {
51
+ a = Math.max(a, (e[k] ?? 0) / TOUCH_UP[k]);
52
+ }
53
+ return Math.min(1, a);
54
+ }
55
+ var MODE_NONE = 0;
56
+ var MODE_BLUR = 1;
57
+ var MODE_IMAGE = 2;
58
+ var MODE_CUTOUT = 3;
59
+ function backgroundMode(f) {
60
+ switch (f.kind) {
61
+ case "blur":
62
+ return MODE_BLUR;
63
+ case "image":
64
+ return MODE_IMAGE;
65
+ case "cutout":
66
+ return MODE_CUTOUT;
67
+ default:
68
+ return MODE_NONE;
69
+ }
70
+ }
71
+ function needsMask(f, e) {
72
+ return f.kind !== "none" || e.beautify > 0 || e.autoframe;
73
+ }
74
+ function needsSegmentation(f, e) {
75
+ return needsMask(f, e) && !e.chromaKey;
76
+ }
77
+ function needsFace(e) {
78
+ return e.teeth > 0 || e.eyeBright > 0 || e.underEye > 0 || e.smileLines > 0 || e.lips > 0 || e.blush > 0 || e.iris > 0 || e.slimFace > 0 || e.enlargeEyes > 0 || e.noseSlim > 0 || e.chin !== 0;
79
+ }
80
+ function coreRecipe(f, e) {
81
+ return {
82
+ background: backgroundMode(f),
83
+ blurRadius: f.kind === "blur" ? f.blurRadius : 0,
84
+ beautify: e.beautify,
85
+ exposure: e.exposure,
86
+ contrast: e.contrast,
87
+ saturation: e.saturation,
88
+ warmth: e.warmth,
89
+ autoframe: e.autoframe,
90
+ teeth: e.teeth,
91
+ eyeBright: e.eyeBright,
92
+ underEye: e.underEye,
93
+ smileLines: e.smileLines,
94
+ lips: e.lips,
95
+ lipColor: e.lipColor,
96
+ blush: e.blush,
97
+ blushColor: e.blushColor,
98
+ iris: e.iris,
99
+ irisColor: e.irisColor,
100
+ grade: e.grade,
101
+ chromaKey: e.chromaKey,
102
+ keyColor: e.keyColor,
103
+ keyTolerance: e.keyTolerance,
104
+ autoLight: e.autoLight,
105
+ mirror: e.mirror,
106
+ slimFace: e.slimFace,
107
+ enlargeEyes: e.enlargeEyes,
108
+ noseSlim: e.noseSlim,
109
+ chin: e.chin
110
+ };
111
+ }
112
+
113
+ export {
114
+ NO_EFFECTS,
115
+ touchUp,
116
+ TOUCH_UP,
117
+ touchUpAmount,
118
+ MODE_NONE,
119
+ MODE_BLUR,
120
+ MODE_IMAGE,
121
+ MODE_CUTOUT,
122
+ backgroundMode,
123
+ needsMask,
124
+ needsSegmentation,
125
+ needsFace,
126
+ coreRecipe
127
+ };
128
+ //# sourceMappingURL=chunk-V47SDU4L.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/recipe.ts"],"sourcesContent":["/**\n * The bridge between what the user picked and the recipe the Go core takes.\n *\n * Both halves live here because both map onto `core.Recipe` field for field: BgFilter carries\n * the background mode and its one parameter, Effects carries everything else. They are two\n * types rather than one because the UI edits them from two different places - a preset picker\n * and a slider panel - not because they belong to different layers.\n */\n\n/**\n * What replaces the background.\n *\n * `imagePath` is a URL the consuming app serves: a path under its own public root, or a data\n * URL for something the user uploaded. The Engine fetches it and cover-crops it to the frame\n * aspect, so any shape is safe to pass.\n */\nexport type BgFilter =\n | { kind: \"none\" }\n | { kind: \"blur\"; blurRadius: number }\n | { kind: \"image\"; imagePath: string }\n /**\n * The background becomes TRANSPARENT and the person stays: the output canvas carries the\n * mask as alpha. For a {@link Scene} to put the person over another source; a plain video\n * track has no alpha, so on its own this shows the person over black.\n */\n | { kind: \"cutout\" }\n\n/** A colour as red, green, blue, each 0..1. */\nexport type Rgb = [number, number, number]\n\nexport interface Effects {\n /** Skin smoothing, 0..1. Needs the person mask, so it pulls in the segmentation cost. */\n beautify: number\n /** Exposure, -1..1. Positive lifts the shadows more than the highlights. */\n exposure: number\n /** Contrast, -1..1. */\n contrast: number\n /** Saturation, -1..1. */\n saturation: number\n /** Warm (positive) or cool (negative), -1..1. */\n warmth: number\n /** Keep the person framed. Needs the person mask. */\n autoframe: boolean\n\n // ── Need FACE landmarks ──────────────────────────────────────────────────────────\n /** Teeth whitening, 0..1. */\n teeth: number\n /** Brighten the whites of the eyes, 0..1. */\n eyeBright: number\n /** Reduce under-eye shadow, 0..1. */\n underEye: number\n /** Soften the nasolabial folds, 0..1. */\n smileLines: number\n\n /**\n * Makeup, 0..1 each, in its colour. Drawn against the full landmark mesh, so the lip tint\n * follows the lip line rather than an ellipse. Not offered in meet, like reshaping.\n */\n lips: number\n lipColor: Rgb\n blush: number\n blushColor: Rgb\n /** Iris colour: the ring only, clipped by the eyelids, the pupil left black. */\n iris: number\n irisColor: Rgb\n\n /**\n * A colour LUT: `lut` is a URL the host serves (a 512x512 \"lookup\" PNG, 64 levels, 8x8 tiles,\n * row 0 at the top), `grade` how strongly it applies. \"\" means none.\n */\n lut: string\n grade: number\n\n /**\n * Take the person mask from a coloured screen instead of segmentation. Cheaper - MediaPipe\n * is never loaded - and the edge keeps hair the model loses. `keyColor` is the screen's\n * colour; [0, 0, 0] means \"find it\" from the frame's border. `keyTolerance` widens (+) or\n * narrows (-) what counts as screen, -1..1 around a tuned default.\n */\n chromaKey: boolean\n keyColor: Rgb\n keyTolerance: number\n\n /**\n * Lift exposure when the room is dark, on top of `exposure`. Only ever brightens. Needs no\n * detector: it reads the frame's own brightness.\n */\n autoLight: boolean\n\n /**\n * Flip the picture left to right, as a selfie preview shows it. Costs nothing on top of any\n * other effect; on its own it is one pass. Text on a whiteboard then reads backwards to\n * everyone watching, which is why it is a choice and not the default.\n */\n mirror: boolean\n\n /**\n * Jawline slimming, 0..1.\n *\n * Deliberately NOT offered in meet: Zoom, Google Meet and Teams all ship without face\n * reshaping, and in a work setting it reads as unserious. The field is here because the\n * second consumer of mediakit is slate, where reshaping is ordinary.\n */\n slimFace: number\n /** Eye enlargement, 0..1. Withheld from meet for the same reason as slimFace. */\n enlargeEyes: number\n /** Nose narrowing, 0..1. Withheld from meet like slimFace. */\n noseSlim: number\n /** Chin length, -1 (shorter) .. 1 (longer). Withheld from meet like slimFace. */\n chin: number\n}\n\nexport const NO_EFFECTS: Effects = {\n beautify: 0,\n exposure: 0,\n contrast: 0,\n saturation: 0,\n warmth: 0,\n autoframe: false,\n teeth: 0,\n eyeBright: 0,\n underEye: 0,\n smileLines: 0,\n lips: 0,\n lipColor: [0.55, 0.18, 0.24],\n blush: 0,\n blushColor: [0.9, 0.5, 0.42],\n iris: 0,\n irisColor: [0.3, 0.5, 0.75],\n lut: \"\",\n grade: 0,\n chromaKey: false,\n keyColor: [0, 0, 0],\n keyTolerance: 0,\n autoLight: false,\n mirror: false,\n slimFace: 0,\n enlargeEyes: 0,\n noseSlim: 0,\n chin: 0,\n}\n\n/**\n * One knob for \"look a little fresher\": skin, eyes, under-eyes, smile lines and teeth, moved\n * together in proportions tuned to read as rested rather than filtered at 1.\n *\n * A host that shows this instead of five sliders gets the shape Zoom and TikTok ship - people\n * reach for one control, not five, and five half-understood knobs mostly get set too high. The\n * ratios live here, next to the fields they drive, so every host means the same thing by it.\n */\nexport function touchUp(amount: number): Pick<Effects, \"beautify\" | \"eyeBright\" | \"underEye\" | \"smileLines\" | \"teeth\"> {\n const a = Math.min(1, Math.max(0, amount))\n return {\n beautify: a * TOUCH_UP.beautify,\n eyeBright: a * TOUCH_UP.eyeBright,\n underEye: a * TOUCH_UP.underEye,\n smileLines: a * TOUCH_UP.smileLines,\n teeth: a * TOUCH_UP.teeth,\n }\n}\n\n/** What `touchUp(1)` sets. Exported so a host can read a stored recipe back into one knob. */\nexport const TOUCH_UP = {\n beautify: 0.6,\n eyeBright: 0.5,\n underEye: 0.45,\n smileLines: 0.5,\n teeth: 0.4,\n} as const\n\n/**\n * The touch-up position a recipe corresponds to: the LARGEST of its five fields relative to\n * `touchUp(1)`. A recipe whose fields were set one by one has no single answer, and reading one\n * field only would show 0 for a recipe still whitening teeth - a knob at 0 that cannot turn off\n * what is running. Taking the largest, any effect still on shows, and moving the knob rewrites\n * all five consistently.\n */\nexport function touchUpAmount(e: Effects): number {\n let a = 0\n for (const k of Object.keys(TOUCH_UP) as (keyof typeof TOUCH_UP)[]) {\n a = Math.max(a, (e[k] ?? 0) / TOUCH_UP[k])\n }\n return Math.min(1, a)\n}\n\n/** Go-side `BackgroundMode`. Must match `core/recipe.go`. */\nexport const MODE_NONE = 0\nexport const MODE_BLUR = 1\nexport const MODE_IMAGE = 2\nexport const MODE_CUTOUT = 3\n\nexport function backgroundMode(f: BgFilter): number {\n switch (f.kind) {\n case \"blur\":\n return MODE_BLUR\n case \"image\":\n return MODE_IMAGE\n case \"cutout\":\n return MODE_CUTOUT\n default:\n return MODE_NONE\n }\n}\n\n/**\n * Whether this recipe needs the person mask.\n *\n * Must match `Recipe.NeedsMask` on the Go side. This is the single biggest saving in the\n * module: a colour-only recipe skips MediaPipe entirely - the most expensive part of a frame,\n * and 9 MB of wasm the user then never downloads.\n *\n * The Go version is authoritative; this one exists so the JS side knows whether to load the\n * segmenter at all, BEFORE it can ask Go.\n */\nexport function needsMask(f: BgFilter, e: Effects): boolean {\n return f.kind !== \"none\" || e.beautify > 0 || e.autoframe\n}\n\n/**\n * Whether this recipe needs the SEGMENTER: a mask, and not one a colour key already gives.\n * Must match `Recipe.NeedsSegmentation` on the Go side. This, not {@link needsMask}, decides\n * whether MediaPipe is loaded - with `chromaKey` on, its 9 MB are never fetched.\n */\nexport function needsSegmentation(f: BgFilter, e: Effects): boolean {\n return needsMask(f, e) && !e.chromaKey\n}\n\n/**\n * Whether this recipe needs face landmarks.\n *\n * Must match `Recipe.NeedsFace` on the Go side. Split from {@link needsMask} because the two\n * detectors are independent costs, and the landmark model is 15 times the size of the\n * segmentation one - making someone who only wants a blurred background download it is waste\n * that shows up on the first load.\n */\nexport function needsFace(e: Effects): boolean {\n return (\n e.teeth > 0 ||\n e.eyeBright > 0 ||\n e.underEye > 0 ||\n e.smileLines > 0 ||\n e.lips > 0 ||\n e.blush > 0 ||\n e.iris > 0 ||\n e.slimFace > 0 ||\n e.enlargeEyes > 0 ||\n e.noseSlim > 0 ||\n e.chin !== 0\n )\n}\n\n/** The recipe in the shape the Go core takes. Field names must match `setRecipe` in wasmjs/main.go. */\nexport interface CoreRecipe {\n background: number\n blurRadius: number\n beautify: number\n exposure: number\n contrast: number\n saturation: number\n warmth: number\n autoframe: boolean\n teeth: number\n eyeBright: number\n underEye: number\n smileLines: number\n lips: number\n lipColor: Rgb\n blush: number\n blushColor: Rgb\n iris: number\n irisColor: Rgb\n grade: number\n chromaKey: boolean\n keyColor: Rgb\n keyTolerance: number\n autoLight: boolean\n mirror: boolean\n slimFace: number\n enlargeEyes: number\n noseSlim: number\n chin: number\n}\n\nexport function coreRecipe(f: BgFilter, e: Effects): CoreRecipe {\n return {\n background: backgroundMode(f),\n blurRadius: f.kind === \"blur\" ? f.blurRadius : 0,\n beautify: e.beautify,\n exposure: e.exposure,\n contrast: e.contrast,\n saturation: e.saturation,\n warmth: e.warmth,\n autoframe: e.autoframe,\n teeth: e.teeth,\n eyeBright: e.eyeBright,\n underEye: e.underEye,\n smileLines: e.smileLines,\n lips: e.lips,\n lipColor: e.lipColor,\n blush: e.blush,\n blushColor: e.blushColor,\n iris: e.iris,\n irisColor: e.irisColor,\n grade: e.grade,\n chromaKey: e.chromaKey,\n keyColor: e.keyColor,\n keyTolerance: e.keyTolerance,\n autoLight: e.autoLight,\n mirror: e.mirror,\n slimFace: e.slimFace,\n enlargeEyes: e.enlargeEyes,\n noseSlim: e.noseSlim,\n chin: e.chin,\n }\n}\n"],"mappings":";AAgHO,IAAM,aAAsB;AAAA,EAC/B,UAAU;AAAA,EACV,UAAU;AAAA,EACV,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,OAAO;AAAA,EACP,WAAW;AAAA,EACX,UAAU;AAAA,EACV,YAAY;AAAA,EACZ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.js';
2
- export { NO_EFFECTS, needsFace, needsMask } from './recipe.js';
2
+ export { NO_EFFECTS, Rgb, TOUCH_UP, needsFace, needsMask, needsSegmentation, touchUp, touchUpAmount } from './recipe.js';
3
+ import { Color, SceneLayer, TransitionKind } from './layout.js';
4
+ export { BLEND_MODES, BlendMode, Rect, TRANSITIONS, hitTest, layouts, parseColor } from './layout.js';
3
5
 
4
6
  /**
5
7
  * One mediakit pipeline: canvas plus WebGL2 plus the Go core plus the detectors, which is
@@ -33,6 +35,10 @@ interface FrameStats {
33
35
  faceSize: number;
34
36
  /** Whether the current recipe needs face landmarks. */
35
37
  needsFace: boolean;
38
+ /** The exposure lift auto light is applying, 0 when it is off or the room is bright. */
39
+ autoExposure: number;
40
+ /** How many faces are being tracked. */
41
+ faces: number;
36
42
  }
37
43
  type EngineCanvas = HTMLCanvasElement | OffscreenCanvas;
38
44
  declare class Engine {
@@ -41,6 +47,8 @@ declare class Engine {
41
47
  private core;
42
48
  private background;
43
49
  private backgroundPath;
50
+ /** The LUT the core holds, by path, so a slider drag does not decode it again. */
51
+ private lutPath;
44
52
  private closed;
45
53
  /**
46
54
  * The segmenter loads LAZILY - only once a recipe actually needs a person mask.
@@ -67,10 +75,21 @@ declare class Engine {
67
75
  private constructor();
68
76
  /** Main thread: makes its own canvas. A worker calls `on` with an OffscreenCanvas. */
69
77
  static create(width: number, height: number, filter: BgFilter, effects?: Effects): Promise<Engine>;
70
- static on(canvas: EngineCanvas, filter: BgFilter, effects?: Effects): Promise<Engine>;
78
+ /**
79
+ * `background`: see {@link Engine.setRecipe}. `alpha` keeps the output's alpha channel, which
80
+ * only a `cutout` background writes; it is fixed for the life of the context, so a host that
81
+ * may switch to `cutout` later has to ask for it here.
82
+ */
83
+ static on(canvas: EngineCanvas, filter: BgFilter, effects?: Effects, background?: ImageBitmap, alpha?: boolean): Promise<Engine>;
71
84
  get outputCanvas(): EngineCanvas;
72
- /** Change the recipe without rebuilding the pipeline, so dragging a slider does not flash. */
73
- setRecipe(filter: BgFilter, effects?: Effects): Promise<void>;
85
+ /**
86
+ * Change the recipe without rebuilding the pipeline, so dragging a slider does not flash.
87
+ *
88
+ * `background` is `filter.imagePath` already decoded, and the Engine takes ownership of it.
89
+ * A worker needs it: there is no `Image` there, so an SVG - every background meet bundles -
90
+ * cannot be decoded at all, and the main thread has to do it and transfer the bitmap.
91
+ */
92
+ setRecipe(filter: BgFilter, effects?: Effects, background?: ImageBitmap): Promise<void>;
74
93
  private ensureFace;
75
94
  private ensureSegmenter;
76
95
  /**
@@ -138,6 +157,8 @@ declare class VideoPipeline {
138
157
  private abort;
139
158
  private worker;
140
159
  private workerStats;
160
+ /** The background path the worker already holds; see backgroundForWorker. */
161
+ private workerBackgroundPath;
141
162
  private video;
142
163
  private rvfcHandle;
143
164
  private stopped;
@@ -152,6 +173,12 @@ declare class VideoPipeline {
152
173
  setEffects(effects: Effects): Promise<void>;
153
174
  private pushRecipe;
154
175
  stop(): Promise<void>;
176
+ /**
177
+ * The image background decoded HERE, for the worker: it has no `Image`, so it cannot decode
178
+ * an SVG, which is every background meet bundles. Only when the path changed - the worker
179
+ * Engine keeps the last one by path, and a slider drag must not decode it again.
180
+ */
181
+ private backgroundForWorker;
155
182
  private send;
156
183
  private teardownWorker;
157
184
  /**
@@ -186,4 +213,146 @@ declare class VideoPipeline {
186
213
  private startCanvas;
187
214
  }
188
215
 
189
- export { BgFilter, Effects, Engine, type EngineCanvas, type FrameStats, type Transport, VideoPipeline, mediakitSupported };
216
+ /**
217
+ * Layers several sources onto one output, OBS style: cameras (each with its own mediakit
218
+ * recipe, `cutout` included), screen shares, video files, images, text and any canvas.
219
+ *
220
+ * Main thread only. The layout maths, animations and transitions run in the Go core
221
+ * (`core/scene`); this class owns the sources and their lifetimes and hands each frame's
222
+ * pictures over.
223
+ *
224
+ * Each camera with effects runs its own {@link Engine} on its own WebGL context, and its finished
225
+ * picture is uploaded here like any other source. Browsers cap live contexts at 8-16, so a scene
226
+ * holds at most a handful of processed cameras.
227
+ */
228
+ type SceneSource =
229
+ /** A camera, processed by its own Engine. No filter and no effects means none is created. */
230
+ {
231
+ kind: "camera";
232
+ track: MediaStreamTrack;
233
+ filter?: BgFilter;
234
+ effects?: Effects;
235
+ }
236
+ /** Any video track shown as it is: a screen share, a remote participant, a second camera. */
237
+ | {
238
+ kind: "track";
239
+ track: MediaStreamTrack;
240
+ } | {
241
+ kind: "video";
242
+ url: string;
243
+ loop?: boolean;
244
+ } | {
245
+ kind: "image";
246
+ url: string;
247
+ } | {
248
+ kind: "image";
249
+ bitmap: ImageBitmap;
250
+ } | {
251
+ kind: "text";
252
+ text: string;
253
+ style?: TextStyle;
254
+ }
255
+ /** Uploaded every frame: for anything the host draws itself. */
256
+ | {
257
+ kind: "canvas";
258
+ canvas: HTMLCanvasElement | OffscreenCanvas;
259
+ };
260
+ /** Sizes are in pixels of the text's own picture; the layer then scales it. */
261
+ interface TextStyle {
262
+ /** A CSS font. Default `600 48px sans-serif`. */
263
+ font?: string;
264
+ color?: Color;
265
+ background?: Color;
266
+ padding?: number;
267
+ radius?: number;
268
+ align?: "left" | "center" | "right";
269
+ /** Wraps at this width. Default: no wrapping. */
270
+ maxWidth?: number;
271
+ /** A multiple of the font size. Default 1.25. */
272
+ lineHeight?: number;
273
+ outline?: {
274
+ width: number;
275
+ color: Color;
276
+ };
277
+ }
278
+ interface SceneOptions {
279
+ width: number;
280
+ height: number;
281
+ /** The render loop's rate. Default 30. */
282
+ fps?: number;
283
+ background?: Color;
284
+ }
285
+ interface SceneStats {
286
+ glCalls: number;
287
+ /** Time spent on the last frame, sources included, in milliseconds. */
288
+ frameMs: number;
289
+ sources: number;
290
+ layers: number;
291
+ }
292
+ declare class Scene {
293
+ readonly canvas: HTMLCanvasElement;
294
+ private core;
295
+ private gl;
296
+ private sources;
297
+ private current;
298
+ private fps;
299
+ private timer;
300
+ private closed;
301
+ private recorder;
302
+ private recorded;
303
+ last: SceneStats;
304
+ private constructor();
305
+ static create(opts: SceneOptions): Promise<Scene>;
306
+ setBackground(c: Color): void;
307
+ /** Add a source, or replace the one with this id; it keeps its slot, so layers stay put. */
308
+ addSource(id: string, spec: SceneSource): Promise<void>;
309
+ /**
310
+ * Change a source without replacing it: new text or style for text, a new recipe for a
311
+ * camera. Anything else is the same as {@link addSource}.
312
+ */
313
+ updateSource(id: string, spec: SceneSource): Promise<void>;
314
+ removeSource(id: string): void;
315
+ get layers(): readonly SceneLayer[];
316
+ /** Change the layout in place. With `animate` (ms) layers glide to their new state. */
317
+ setLayers(layers: SceneLayer[], opts?: {
318
+ animate?: number;
319
+ }): void;
320
+ /** Move to another layout through a transition. */
321
+ switchTo(layers: SceneLayer[], transition?: {
322
+ kind: TransitionKind;
323
+ duration?: number;
324
+ }): void;
325
+ /** The topmost layer under a point of the output, in fractions, for picking and dragging. */
326
+ layerAt(x: number, y: number): SceneLayer | undefined;
327
+ start(): void;
328
+ stop(): void;
329
+ /** Draw one frame now. The loop calls this; a host with its own loop can instead. */
330
+ render(): number;
331
+ /** The output as a live stream, for a call, a recorder or a `<video>`. */
332
+ captureStream(fps?: number): MediaStream;
333
+ /** The current frame as an image file. */
334
+ snapshot(type?: string): Promise<Blob>;
335
+ /** Record the output, optionally with an audio track, until {@link stopRecording}. */
336
+ startRecording(opts?: {
337
+ audio?: MediaStreamTrack;
338
+ mimeType?: string;
339
+ videoBitsPerSecond?: number;
340
+ }): void;
341
+ stopRecording(): Promise<Blob>;
342
+ close(): void;
343
+ private freeSlot;
344
+ private coreLayers;
345
+ private push;
346
+ private open;
347
+ /**
348
+ * Build, update or drop a camera's Engine to match its recipe and its current size. An
349
+ * Engine is sized at creation, so a camera that changes resolution needs a new one.
350
+ */
351
+ private ensureEngine;
352
+ private feed;
353
+ private dispose;
354
+ }
355
+ /** Draw text onto its own canvas, sized to fit it. */
356
+ declare function renderText(text: string, style?: TextStyle): HTMLCanvasElement;
357
+
358
+ export { BgFilter, Color, Effects, Engine, type EngineCanvas, type FrameStats, Scene, SceneLayer, type SceneOptions, type SceneSource, type SceneStats, type TextStyle, TransitionKind, type Transport, VideoPipeline, mediakitSupported, renderText };