@tradalab/mediakit 1.1.0 → 1.3.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,164 @@
1
+ /**
2
+ * The vocabulary of a {@link Scene}: layers, transitions and ready-made layouts.
3
+ *
4
+ * Its own entry point (`@tradalab/mediakit/layout`) for the reason `recipe` is one: a layout
5
+ * picker or a layer list is UI, and reaching this through the root would pull the wasm loader and
6
+ * MediaPipe into every module that only wants to name a corner.
7
+ */
8
+ /** A colour: CSS hex (`#rgb`, `#rrggbb`, `#rrggbbaa`) or channels 0..1. */
9
+ type Color = string | [number, number, number] | [number, number, number, number];
10
+ type BlendMode = "normal" | "add" | "screen" | "multiply" | "overlay" | "darken" | "lighten";
11
+ /** A placement in fractions of the output, origin top left. */
12
+ interface Rect {
13
+ x: number;
14
+ y: number;
15
+ w: number;
16
+ h: number;
17
+ }
18
+ /**
19
+ * One thing drawn on the output. Three kinds, told apart by what is set: `source` shows a
20
+ * source, `color2` makes a gradient, otherwise `color` fills the shape.
21
+ */
22
+ interface SceneLayer extends Rect {
23
+ /** Stable across changes: an animation moves the layer with the same id. */
24
+ id: number;
25
+ /** A source id given to `Scene.addSource`. */
26
+ source?: string;
27
+ color?: Color;
28
+ color2?: Color;
29
+ /** Gradient direction in degrees, 0 running left to right. */
30
+ gradientAngle?: number;
31
+ /** Degrees, clockwise, about the centre. */
32
+ rotation?: number;
33
+ /** 0..1, default 1. */
34
+ opacity?: number;
35
+ /**
36
+ * How a source fills the rect. Default `cover`: never distorted, never letterboxed. `contain`
37
+ * shrinks the rect to the picture, so shape, border and shadow follow the picture.
38
+ */
39
+ fit?: "stretch" | "contain" | "cover";
40
+ /** Fractions of the source to cut off, before fitting. */
41
+ crop?: {
42
+ left?: number;
43
+ top?: number;
44
+ right?: number;
45
+ bottom?: number;
46
+ };
47
+ flipX?: boolean;
48
+ flipY?: boolean;
49
+ shape?: "rect" | "rounded" | "ellipse";
50
+ /** Corner radius for `rounded`, as a share of the shorter side, 0..0.5. */
51
+ radius?: number;
52
+ /** Width in output heights: 0.005 is about 4 px at 720p. */
53
+ border?: {
54
+ width: number;
55
+ color: Color;
56
+ };
57
+ /** Softness and offset in output heights. */
58
+ shadow?: {
59
+ blur: number;
60
+ x?: number;
61
+ y?: number;
62
+ opacity?: number;
63
+ };
64
+ blend?: BlendMode;
65
+ /** -1..1 each, the camera recipe's colour knobs. */
66
+ tone?: {
67
+ exposure?: number;
68
+ contrast?: number;
69
+ saturation?: number;
70
+ warmth?: number;
71
+ };
72
+ /** Remove a colour from the source - a green-screen clip, say. Tolerance -1..1. */
73
+ key?: {
74
+ color: Color;
75
+ tolerance?: number;
76
+ };
77
+ hidden?: boolean;
78
+ }
79
+ type TransitionKind = "cut" | "fade" | "fadeThrough" | "slideLeft" | "slideRight" | "slideUp" | "slideDown" | "pushLeft" | "pushRight" | "wipeLeft" | "wipeRight" | "iris" | "zoom";
80
+ /** In the order of `scene.Transition` in core/scene/scene.go. */
81
+ declare const TRANSITIONS: readonly TransitionKind[];
82
+ /** In the order of `scene.Blend`. */
83
+ declare const BLEND_MODES: readonly BlendMode[];
84
+ /** The layer in the shape the Go core takes. Field names must match `readLayers` in wasmjs/main.go. */
85
+ interface CoreLayer {
86
+ id: number;
87
+ kind: number;
88
+ source: number;
89
+ x: number;
90
+ y: number;
91
+ w: number;
92
+ h: number;
93
+ rotation: number;
94
+ opacity: number;
95
+ fit: number;
96
+ cropLeft: number;
97
+ cropTop: number;
98
+ cropRight: number;
99
+ cropBottom: number;
100
+ flipX: boolean;
101
+ flipY: boolean;
102
+ shape: number;
103
+ radius: number;
104
+ border: number;
105
+ borderColor: number[];
106
+ shadow: number;
107
+ shadowX: number;
108
+ shadowY: number;
109
+ shadowAlpha: number;
110
+ blend: number;
111
+ color: number[];
112
+ color2: number[];
113
+ angle: number;
114
+ exposure: number;
115
+ contrast: number;
116
+ saturation: number;
117
+ warmth: number;
118
+ key: boolean;
119
+ keyColor: number[];
120
+ keyTolerance: number;
121
+ }
122
+ /**
123
+ * `slot` maps a source id to its slot, or -1 when the source is not there. Such a layer is sent
124
+ * with opacity 0: sending its slot as 0 would show whatever source happens to sit in slot 0.
125
+ */
126
+ declare function coreLayer(l: SceneLayer, slot: (id: string) => number): CoreLayer;
127
+ /** A colour as four channels 0..1. Unreadable input is opaque black, never a throw mid-frame. */
128
+ declare function parseColor(c: Color): [number, number, number, number];
129
+ /**
130
+ * The topmost visible layer under a point of the output (fractions, top left), rotation
131
+ * included, for a host that lets people pick and drag layers. `aspect` is the output's
132
+ * width over height, needed because rotation turns in pixels, not fractions.
133
+ */
134
+ declare function hitTest(layers: readonly SceneLayer[], x: number, y: number, aspect: number): SceneLayer | undefined;
135
+ /** Ready-made placements. Every one returns a {@link Rect}; spread it into a layer. */
136
+ declare const layouts: {
137
+ full(): Rect;
138
+ /**
139
+ * A picture in picture in one corner. `size` is the inset's height as a share of the output,
140
+ * `aspect` its width over height (16:9 by default, 1 for a circle), `margin` the gap to the
141
+ * edges in output heights. `outputAspect` is the output's width over height.
142
+ */
143
+ pip(corner?: "top-left" | "top-right" | "bottom-left" | "bottom-right", size?: number, aspect?: number, margin?: number, outputAspect?: number): Rect;
144
+ /** The i-th of n equal columns, with a gap between them in output widths. */
145
+ columns(i: number, n?: number, gap?: number): Rect;
146
+ /** The i-th cell of the most square grid that holds n, filled row by row. */
147
+ grid(i: number, n: number, gap?: number): Rect;
148
+ /** A name bar across the lower part of the picture, broadcast style. */
149
+ lowerThird(width?: number, height?: number, margin?: number): Rect;
150
+ /**
151
+ * Presenter: the shared content large on one side, the presenter on the other. With a
152
+ * `cutout` camera the presenter stands over the content's edge.
153
+ *
154
+ * The person's rect has the camera's own shape (`cameraAspect`) and sits on the bottom edge:
155
+ * any other shape makes `contain` shrink the picture, and its bottom then cuts across the
156
+ * shoulders in mid-air.
157
+ */
158
+ presenter(side?: "left" | "right", cameraAspect?: number, outputAspect?: number): {
159
+ content: Rect;
160
+ person: Rect;
161
+ };
162
+ };
163
+
164
+ export { BLEND_MODES, type BlendMode, type Color, type CoreLayer, type Rect, type SceneLayer, TRANSITIONS, type TransitionKind, coreLayer, hitTest, layouts, parseColor };
package/dist/layout.js ADDED
@@ -0,0 +1,17 @@
1
+ import {
2
+ BLEND_MODES,
3
+ TRANSITIONS,
4
+ coreLayer,
5
+ hitTest,
6
+ layouts,
7
+ parseColor
8
+ } from "./chunk-BMIOUOT3.js";
9
+ export {
10
+ BLEND_MODES,
11
+ TRANSITIONS,
12
+ coreLayer,
13
+ hitTest,
14
+ layouts,
15
+ parseColor
16
+ };
17
+ //# sourceMappingURL=layout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
Binary file
package/dist/recipe.d.ts CHANGED
@@ -21,9 +21,21 @@ type BgFilter = {
21
21
  } | {
22
22
  kind: "image";
23
23
  imagePath: string;
24
+ }
25
+ /**
26
+ * The background becomes TRANSPARENT and the person stays: the output canvas carries the
27
+ * mask as alpha. For a {@link Scene} to put the person over another source; a plain video
28
+ * track has no alpha, so on its own this shows the person over black.
29
+ */
30
+ | {
31
+ kind: "cutout";
24
32
  };
25
33
  /** A colour as red, green, blue, each 0..1. */
26
34
  type Rgb = [number, number, number];
35
+ /** Where smoothing (`beautify`) may land. */
36
+ type SkinScope = "person" | "face";
37
+ /** Where the colour LUT lands. */
38
+ type GradeScope = "frame" | "person" | "skin";
27
39
  interface Effects {
28
40
  /** Skin smoothing, 0..1. Needs the person mask, so it pulls in the segmentation cost. */
29
41
  beautify: number;
@@ -56,17 +68,57 @@ interface Effects {
56
68
  /** Iris colour: the ring only, clipped by the eyelids, the pupil left black. */
57
69
  iris: number;
58
70
  irisColor: Rgb;
71
+ /** Eye shadow, 0..1, multiplied into the lower part of the lid-to-brow band. */
72
+ eyeShadow: number;
73
+ eyeShadowColor: Rgb;
74
+ /** A white highlight across the middle of the lower lip, 0..1. Matte is 0. */
75
+ lipGloss: number;
76
+ /** A faint flush over the whole face's skin, 0..1 - the face, where `blush` is the cheeks. */
77
+ rosy: number;
78
+ rosyColor: Rgb;
79
+ /** Lift and cool the skin, 0..1: brighter, less yellow. */
80
+ whiten: number;
81
+ /**
82
+ * How `whiten` whitens. `natural` relights the skin and cools its yellow, keeping its colour.
83
+ * `pink` is the "fair and rosy" look East Asian beauty apps ship - GPUPixel's tuned skin
84
+ * tables (Apache-2.0, see NOTICE), served as `/mediakit/whiten_pink.png`; it fades out on
85
+ * darker skin, which those tables were not tuned for.
86
+ */
87
+ whitenStyle: "natural" | "pink";
88
+ /** Exposure on the skin only. */
89
+ skinLight: number;
90
+ /** Local contrast on the face. */
91
+ clarity: number;
92
+ /** Where smoothing may land. See {@link SkinScope}. */
93
+ skinScope: SkinScope;
59
94
  /**
60
95
  * A colour LUT: `lut` is a URL the host serves (a 512x512 "lookup" PNG, 64 levels, 8x8 tiles,
61
96
  * row 0 at the top), `grade` how strongly it applies. "" means none.
62
97
  */
63
98
  lut: string;
64
99
  grade: number;
100
+ /** Where the LUT lands. See {@link GradeScope}. */
101
+ gradeScope: GradeScope;
102
+ /**
103
+ * Take the person mask from a coloured screen instead of segmentation. Cheaper - MediaPipe
104
+ * is never loaded - and the edge keeps hair the model loses. `keyColor` is the screen's
105
+ * colour; [0, 0, 0] means "find it" from the frame's border. `keyTolerance` widens (+) or
106
+ * narrows (-) what counts as screen, -1..1 around a tuned default.
107
+ */
108
+ chromaKey: boolean;
109
+ keyColor: Rgb;
110
+ keyTolerance: number;
65
111
  /**
66
112
  * Lift exposure when the room is dark, on top of `exposure`. Only ever brightens. Needs no
67
113
  * detector: it reads the frame's own brightness.
68
114
  */
69
115
  autoLight: boolean;
116
+ /**
117
+ * Flip the picture left to right, as a selfie preview shows it. Costs nothing on top of any
118
+ * other effect; on its own it is one pass. Text on a whiteboard then reads backwards to
119
+ * everyone watching, which is why it is a choice and not the default.
120
+ */
121
+ mirror: boolean;
70
122
  /**
71
123
  * Jawline slimming, 0..1.
72
124
  *
@@ -81,6 +133,22 @@ interface Effects {
81
133
  noseSlim: number;
82
134
  /** Chin length, -1 (shorter) .. 1 (longer). Withheld from meet like slimFace. */
83
135
  chin: number;
136
+ /** Reshaping along the face's own outline. */
137
+ jaw: number;
138
+ cheekbone: number;
139
+ forehead: number;
140
+ /** Brow fill, 0..1, multiplied in so the hairs show; lighter at the inner end. */
141
+ brow: number;
142
+ browColor: Rgb;
143
+ /** Shading under the cheekbones, along the jaw and beside the nose, 0..1. */
144
+ contour: number;
145
+ /** Light on the nose bridge, cheekbone tops, mid forehead and chin, 0..1. */
146
+ highlight: number;
147
+ /** A look painted as an image on the canonical face. */
148
+ makeupTexture: string;
149
+ makeup: number;
150
+ /** How the makeup texture blends: soft light (default), multiply, overlay, hard light, normal. */
151
+ makeupBlend: "softLight" | "multiply" | "overlay" | "hardLight" | "normal";
84
152
  }
85
153
  declare const NO_EFFECTS: Effects;
86
154
  /**
@@ -112,6 +180,24 @@ declare function touchUpAmount(e: Effects): number;
112
180
  declare const MODE_NONE = 0;
113
181
  declare const MODE_BLUR = 1;
114
182
  declare const MODE_IMAGE = 2;
183
+ declare const MODE_CUTOUT = 3;
184
+ /** Go-side `SkinScope` and `Scope`. Must match `core/recipe.go`. */
185
+ declare const SKIN_SCOPE: {
186
+ readonly person: 0;
187
+ readonly face: 1;
188
+ };
189
+ declare const MAKEUP_BLEND: {
190
+ readonly softLight: 0;
191
+ readonly multiply: 1;
192
+ readonly overlay: 2;
193
+ readonly hardLight: 3;
194
+ readonly normal: 4;
195
+ };
196
+ declare const GRADE_SCOPE: {
197
+ readonly frame: 0;
198
+ readonly person: 1;
199
+ readonly skin: 2;
200
+ };
115
201
  declare function backgroundMode(f: BgFilter): number;
116
202
  /**
117
203
  * Whether this recipe needs the person mask.
@@ -124,6 +210,14 @@ declare function backgroundMode(f: BgFilter): number;
124
210
  * segmenter at all, BEFORE it can ask Go.
125
211
  */
126
212
  declare function needsMask(f: BgFilter, e: Effects): boolean;
213
+ /**
214
+ * Whether this recipe needs the SEGMENTER: a mask, and not one a colour key already gives.
215
+ * Must match `Recipe.NeedsSegmentation` on the Go side. This, not {@link needsMask}, decides
216
+ * whether MediaPipe is loaded - with `chromaKey` on, its 9 MB are never fetched.
217
+ */
218
+ declare function needsSegmentation(f: BgFilter, e: Effects): boolean;
219
+ /** Whether this recipe is better served by the multiclass segmenter. */
220
+ declare function needsSkinClasses(_f: BgFilter, e: Effects): boolean;
127
221
  /**
128
222
  * Whether this recipe needs face landmarks.
129
223
  *
@@ -153,13 +247,37 @@ interface CoreRecipe {
153
247
  blushColor: Rgb;
154
248
  iris: number;
155
249
  irisColor: Rgb;
250
+ eyeShadow: number;
251
+ eyeShadowColor: Rgb;
252
+ lipGloss: number;
253
+ rosy: number;
254
+ rosyColor: Rgb;
255
+ whiten: number;
256
+ skinLight: number;
257
+ clarity: number;
258
+ skinScope: number;
156
259
  grade: number;
260
+ gradeScope: number;
261
+ chromaKey: boolean;
262
+ keyColor: Rgb;
263
+ keyTolerance: number;
157
264
  autoLight: boolean;
265
+ mirror: boolean;
158
266
  slimFace: number;
159
267
  enlargeEyes: number;
160
268
  noseSlim: number;
161
269
  chin: number;
270
+ jaw: number;
271
+ cheekbone: number;
272
+ forehead: number;
273
+ brow: number;
274
+ browColor: Rgb;
275
+ contour: number;
276
+ highlight: number;
277
+ makeup: number;
278
+ makeupBlend: number;
279
+ whitenStyle: number;
162
280
  }
163
281
  declare function coreRecipe(f: BgFilter, e: Effects): CoreRecipe;
164
282
 
165
- export { type BgFilter, type CoreRecipe, type Effects, MODE_BLUR, MODE_IMAGE, MODE_NONE, NO_EFFECTS, type Rgb, TOUCH_UP, backgroundMode, coreRecipe, needsFace, needsMask, touchUp, touchUpAmount };
283
+ export { type BgFilter, type CoreRecipe, type Effects, GRADE_SCOPE, type GradeScope, MAKEUP_BLEND, MODE_BLUR, MODE_CUTOUT, MODE_IMAGE, MODE_NONE, NO_EFFECTS, type Rgb, SKIN_SCOPE, type SkinScope, TOUCH_UP, backgroundMode, coreRecipe, needsFace, needsMask, needsSegmentation, needsSkinClasses, touchUp, touchUpAmount };
package/dist/recipe.js CHANGED
@@ -1,26 +1,38 @@
1
1
  import {
2
+ GRADE_SCOPE,
3
+ MAKEUP_BLEND,
2
4
  MODE_BLUR,
5
+ MODE_CUTOUT,
3
6
  MODE_IMAGE,
4
7
  MODE_NONE,
5
8
  NO_EFFECTS,
9
+ SKIN_SCOPE,
6
10
  TOUCH_UP,
7
11
  backgroundMode,
8
12
  coreRecipe,
9
13
  needsFace,
10
14
  needsMask,
15
+ needsSegmentation,
16
+ needsSkinClasses,
11
17
  touchUp,
12
18
  touchUpAmount
13
- } from "./chunk-XLLQ74JA.js";
19
+ } from "./chunk-WRKQ2NFI.js";
14
20
  export {
21
+ GRADE_SCOPE,
22
+ MAKEUP_BLEND,
15
23
  MODE_BLUR,
24
+ MODE_CUTOUT,
16
25
  MODE_IMAGE,
17
26
  MODE_NONE,
18
27
  NO_EFFECTS,
28
+ SKIN_SCOPE,
19
29
  TOUCH_UP,
20
30
  backgroundMode,
21
31
  coreRecipe,
22
32
  needsFace,
23
33
  needsMask,
34
+ needsSegmentation,
35
+ needsSkinClasses,
24
36
  touchUp,
25
37
  touchUpAmount
26
38
  };
Binary file