@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.
package/dist/NOTICE ADDED
@@ -0,0 +1,22 @@
1
+ whiten_pink.png
2
+
3
+ A colour lookup table baked from GPUPixel's skin-whitening chain - lookup_gray.png,
4
+ lookup_origin.png, lookup_skin.png and lookup_light.png, combined as in
5
+ src/filter/beauty_face_unit_filter.cc at whitening 0.35 - into mediakit's 512x512 LUT layout.
6
+
7
+ GPUPixel
8
+ Copyright 2021 PixPark
9
+ https://github.com/pixpark/gpupixel
10
+
11
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
12
+ in compliance with the License. You may obtain a copy of the License at
13
+
14
+ http://www.apache.org/licenses/LICENSE-2.0
15
+
16
+ Unless required by applicable law or agreed to in writing, software distributed under the License
17
+ is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
18
+ or implied. See the License for the specific language governing permissions and limitations under
19
+ the License.
20
+
21
+ Changes: the four tables were combined into one, evaluated once per LUT entry with bilinear
22
+ sampling; nothing else.
@@ -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,KA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
+ 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
+ eyeShadow: 0,
20
+ eyeShadowColor: [0.55, 0.42, 0.37],
21
+ lipGloss: 0,
22
+ rosy: 0,
23
+ rosyColor: [0.9, 0.42, 0.49],
24
+ whiten: 0,
25
+ skinLight: 0,
26
+ clarity: 0,
27
+ skinScope: "person",
28
+ lut: "",
29
+ grade: 0,
30
+ gradeScope: "frame",
31
+ chromaKey: false,
32
+ keyColor: [0, 0, 0],
33
+ keyTolerance: 0,
34
+ autoLight: false,
35
+ mirror: false,
36
+ slimFace: 0,
37
+ enlargeEyes: 0,
38
+ noseSlim: 0,
39
+ chin: 0,
40
+ jaw: 0,
41
+ cheekbone: 0,
42
+ forehead: 0,
43
+ brow: 0,
44
+ browColor: [0.36, 0.27, 0.22],
45
+ contour: 0,
46
+ highlight: 0,
47
+ makeupTexture: "",
48
+ makeup: 0,
49
+ makeupBlend: "softLight",
50
+ whitenStyle: "natural"
51
+ };
52
+ function touchUp(amount) {
53
+ const a = Math.min(1, Math.max(0, amount));
54
+ return {
55
+ beautify: a * TOUCH_UP.beautify,
56
+ eyeBright: a * TOUCH_UP.eyeBright,
57
+ underEye: a * TOUCH_UP.underEye,
58
+ smileLines: a * TOUCH_UP.smileLines,
59
+ teeth: a * TOUCH_UP.teeth
60
+ };
61
+ }
62
+ var TOUCH_UP = {
63
+ beautify: 0.6,
64
+ eyeBright: 0.5,
65
+ underEye: 0.45,
66
+ smileLines: 0.5,
67
+ teeth: 0.4
68
+ };
69
+ function touchUpAmount(e) {
70
+ let a = 0;
71
+ for (const k of Object.keys(TOUCH_UP)) {
72
+ a = Math.max(a, (e[k] ?? 0) / TOUCH_UP[k]);
73
+ }
74
+ return Math.min(1, a);
75
+ }
76
+ var MODE_NONE = 0;
77
+ var MODE_BLUR = 1;
78
+ var MODE_IMAGE = 2;
79
+ var MODE_CUTOUT = 3;
80
+ var SKIN_SCOPE = { person: 0, face: 1 };
81
+ var MAKEUP_BLEND = { softLight: 0, multiply: 1, overlay: 2, hardLight: 3, normal: 4 };
82
+ var GRADE_SCOPE = { frame: 0, person: 1, skin: 2 };
83
+ function backgroundMode(f) {
84
+ switch (f.kind) {
85
+ case "blur":
86
+ return MODE_BLUR;
87
+ case "image":
88
+ return MODE_IMAGE;
89
+ case "cutout":
90
+ return MODE_CUTOUT;
91
+ default:
92
+ return MODE_NONE;
93
+ }
94
+ }
95
+ function needsMask(f, e) {
96
+ return f.kind !== "none" || e.beautify > 0 || e.autoframe || hasSkin(e) || e.grade > 0 && (e.gradeScope ?? "frame") !== "frame";
97
+ }
98
+ function hasSkin(e) {
99
+ return (e.whiten ?? 0) > 0 || (e.skinLight ?? 0) > 0 || (e.clarity ?? 0) > 0;
100
+ }
101
+ function needsSegmentation(f, e) {
102
+ return needsMask(f, e) && !e.chromaKey;
103
+ }
104
+ function needsSkinClasses(_f, e) {
105
+ return (e.whiten ?? 0) > 0 || (e.skinLight ?? 0) > 0 || e.grade > 0 && (e.gradeScope ?? "frame") !== "frame";
106
+ }
107
+ function needsFace(e) {
108
+ return e.teeth > 0 || e.eyeBright > 0 || e.underEye > 0 || e.smileLines > 0 || e.lips > 0 || e.blush > 0 || e.iris > 0 || (e.eyeShadow ?? 0) > 0 || (e.lipGloss ?? 0) > 0 || (e.rosy ?? 0) > 0 || e.skinScope === "face" && (e.beautify > 0 || hasSkin(e)) || // Whitening and skin light measure skin on the face; clarity is held to it.
109
+ hasSkin(e) || e.grade > 0 && e.gradeScope === "skin" || e.slimFace > 0 || e.enlargeEyes > 0 || e.noseSlim > 0 || e.chin !== 0 || (e.jaw ?? 0) > 0 || (e.cheekbone ?? 0) > 0 || (e.forehead ?? 0) !== 0 || (e.brow ?? 0) > 0 || (e.contour ?? 0) > 0 || (e.highlight ?? 0) > 0 || (e.makeup ?? 0) > 0 && !!e.makeupTexture;
110
+ }
111
+ function coreRecipe(f, e) {
112
+ return {
113
+ background: backgroundMode(f),
114
+ blurRadius: f.kind === "blur" ? f.blurRadius : 0,
115
+ beautify: e.beautify,
116
+ exposure: e.exposure,
117
+ contrast: e.contrast,
118
+ saturation: e.saturation,
119
+ warmth: e.warmth,
120
+ autoframe: e.autoframe,
121
+ teeth: e.teeth,
122
+ eyeBright: e.eyeBright,
123
+ underEye: e.underEye,
124
+ smileLines: e.smileLines,
125
+ lips: e.lips,
126
+ lipColor: e.lipColor,
127
+ blush: e.blush,
128
+ blushColor: e.blushColor,
129
+ iris: e.iris,
130
+ irisColor: e.irisColor,
131
+ eyeShadow: e.eyeShadow ?? 0,
132
+ eyeShadowColor: e.eyeShadowColor ?? NO_EFFECTS.eyeShadowColor,
133
+ lipGloss: e.lipGloss ?? 0,
134
+ rosy: e.rosy ?? 0,
135
+ rosyColor: e.rosyColor ?? NO_EFFECTS.rosyColor,
136
+ whiten: e.whiten ?? 0,
137
+ skinLight: e.skinLight ?? 0,
138
+ clarity: e.clarity ?? 0,
139
+ skinScope: SKIN_SCOPE[e.skinScope] ?? 0,
140
+ grade: e.grade,
141
+ gradeScope: GRADE_SCOPE[e.gradeScope] ?? 0,
142
+ chromaKey: e.chromaKey,
143
+ keyColor: e.keyColor,
144
+ keyTolerance: e.keyTolerance,
145
+ autoLight: e.autoLight,
146
+ mirror: e.mirror,
147
+ slimFace: e.slimFace,
148
+ enlargeEyes: e.enlargeEyes,
149
+ noseSlim: e.noseSlim,
150
+ chin: e.chin,
151
+ jaw: e.jaw ?? 0,
152
+ cheekbone: e.cheekbone ?? 0,
153
+ forehead: e.forehead ?? 0,
154
+ brow: e.brow ?? 0,
155
+ browColor: e.browColor ?? NO_EFFECTS.browColor,
156
+ contour: e.contour ?? 0,
157
+ highlight: e.highlight ?? 0,
158
+ makeup: e.makeupTexture ? e.makeup ?? 0 : 0,
159
+ makeupBlend: MAKEUP_BLEND[e.makeupBlend] ?? 0,
160
+ whitenStyle: e.whitenStyle === "pink" ? 1 : 0
161
+ };
162
+ }
163
+
164
+ export {
165
+ NO_EFFECTS,
166
+ touchUp,
167
+ TOUCH_UP,
168
+ touchUpAmount,
169
+ MODE_NONE,
170
+ MODE_BLUR,
171
+ MODE_IMAGE,
172
+ MODE_CUTOUT,
173
+ SKIN_SCOPE,
174
+ MAKEUP_BLEND,
175
+ GRADE_SCOPE,
176
+ backgroundMode,
177
+ needsMask,
178
+ needsSegmentation,
179
+ needsSkinClasses,
180
+ needsFace,
181
+ coreRecipe
182
+ };
183
+ //# sourceMappingURL=chunk-WRKQ2NFI.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\n/** Where smoothing (`beautify`) may land. */\nexport type SkinScope = \"person\" | \"face\"\n\n/** Where the colour LUT lands. */\nexport type GradeScope = \"frame\" | \"person\" | \"skin\"\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 /** Eye shadow, 0..1, multiplied into the lower part of the lid-to-brow band. */\n eyeShadow: number\n eyeShadowColor: Rgb\n /** A white highlight across the middle of the lower lip, 0..1. Matte is 0. */\n lipGloss: number\n /** A faint flush over the whole face's skin, 0..1 - the face, where `blush` is the cheeks. */\n rosy: number\n rosyColor: Rgb\n\n // ── Skin, beside beautify.\n /** Lift and cool the skin, 0..1: brighter, less yellow. */\n whiten: number\n /**\n * How `whiten` whitens. `natural` relights the skin and cools its yellow, keeping its colour.\n * `pink` is the \"fair and rosy\" look East Asian beauty apps ship - GPUPixel's tuned skin\n * tables (Apache-2.0, see NOTICE), served as `/mediakit/whiten_pink.png`; it fades out on\n * darker skin, which those tables were not tuned for.\n */\n whitenStyle: \"natural\" | \"pink\"\n /** Exposure on the skin only. */\n skinLight: number\n /** Local contrast on the face. */\n clarity: number\n /** Where smoothing may land. See {@link SkinScope}. */\n skinScope: SkinScope\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 /** Where the LUT lands. See {@link GradeScope}. */\n gradeScope: GradeScope\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 /** Reshaping along the face's own outline. */\n jaw: number\n cheekbone: number\n forehead: number\n /** Brow fill, 0..1, multiplied in so the hairs show; lighter at the inner end. */\n brow: number\n browColor: Rgb\n /** Shading under the cheekbones, along the jaw and beside the nose, 0..1. */\n contour: number\n /** Light on the nose bridge, cheekbone tops, mid forehead and chin, 0..1. */\n highlight: number\n /** A look painted as an image on the canonical face. */\n makeupTexture: string\n makeup: number\n /** How the makeup texture blends: soft light (default), multiply, overlay, hard light, normal. */\n makeupBlend: \"softLight\" | \"multiply\" | \"overlay\" | \"hardLight\" | \"normal\"\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 eyeShadow: 0,\n eyeShadowColor: [0.55, 0.42, 0.37],\n lipGloss: 0,\n rosy: 0,\n rosyColor: [0.9, 0.42, 0.49],\n whiten: 0,\n skinLight: 0,\n clarity: 0,\n skinScope: \"person\",\n lut: \"\",\n grade: 0,\n gradeScope: \"frame\",\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 jaw: 0,\n cheekbone: 0,\n forehead: 0,\n brow: 0,\n browColor: [0.36, 0.27, 0.22],\n contour: 0,\n highlight: 0,\n makeupTexture: \"\",\n makeup: 0,\n makeupBlend: \"softLight\",\n whitenStyle: \"natural\",\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\n/** Go-side `SkinScope` and `Scope`. Must match `core/recipe.go`. */\nexport const SKIN_SCOPE = { person: 0, face: 1 } as const\nexport const MAKEUP_BLEND = { softLight: 0, multiply: 1, overlay: 2, hardLight: 3, normal: 4 } as const\nexport const GRADE_SCOPE = { frame: 0, person: 1, skin: 2 } as const\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 (\n f.kind !== \"none\" ||\n e.beautify > 0 ||\n e.autoframe ||\n hasSkin(e) ||\n (e.grade > 0 && (e.gradeScope ?? \"frame\") !== \"frame\")\n )\n}\n\nfunction hasSkin(e: Effects): boolean {\n return (e.whiten ?? 0) > 0 || (e.skinLight ?? 0) > 0 || (e.clarity ?? 0) > 0\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/** Whether this recipe is better served by the multiclass segmenter. */\nexport function needsSkinClasses(_f: BgFilter, e: Effects): boolean {\n return (e.whiten ?? 0) > 0 || (e.skinLight ?? 0) > 0 || (e.grade > 0 && (e.gradeScope ?? \"frame\") !== \"frame\")\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.eyeShadow ?? 0) > 0 ||\n (e.lipGloss ?? 0) > 0 ||\n (e.rosy ?? 0) > 0 ||\n (e.skinScope === \"face\" && (e.beautify > 0 || hasSkin(e))) ||\n // Whitening and skin light measure skin on the face; clarity is held to it.\n hasSkin(e) ||\n (e.grade > 0 && e.gradeScope === \"skin\") ||\n e.slimFace > 0 ||\n e.enlargeEyes > 0 ||\n e.noseSlim > 0 ||\n e.chin !== 0 ||\n (e.jaw ?? 0) > 0 ||\n (e.cheekbone ?? 0) > 0 ||\n (e.forehead ?? 0) !== 0 ||\n (e.brow ?? 0) > 0 ||\n (e.contour ?? 0) > 0 ||\n (e.highlight ?? 0) > 0 ||\n ((e.makeup ?? 0) > 0 && !!e.makeupTexture)\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 eyeShadow: number\n eyeShadowColor: Rgb\n lipGloss: number\n rosy: number\n rosyColor: Rgb\n whiten: number\n skinLight: number\n clarity: number\n skinScope: number\n grade: number\n gradeScope: 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 jaw: number\n cheekbone: number\n forehead: number\n brow: number\n browColor: Rgb\n contour: number\n highlight: number\n makeup: number\n makeupBlend: number\n whitenStyle: 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 eyeShadow: e.eyeShadow ?? 0,\n eyeShadowColor: e.eyeShadowColor ?? NO_EFFECTS.eyeShadowColor,\n lipGloss: e.lipGloss ?? 0,\n rosy: e.rosy ?? 0,\n rosyColor: e.rosyColor ?? NO_EFFECTS.rosyColor,\n whiten: e.whiten ?? 0,\n skinLight: e.skinLight ?? 0,\n clarity: e.clarity ?? 0,\n skinScope: SKIN_SCOPE[e.skinScope] ?? 0,\n grade: e.grade,\n gradeScope: GRADE_SCOPE[e.gradeScope] ?? 0,\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 jaw: e.jaw ?? 0,\n cheekbone: e.cheekbone ?? 0,\n forehead: e.forehead ?? 0,\n brow: e.brow ?? 0,\n browColor: e.browColor ?? NO_EFFECTS.browColor,\n contour: e.contour ?? 0,\n highlight: e.highlight ?? 0,\n makeup: e.makeupTexture ? (e.makeup ?? 0) : 0,\n makeupBlend: MAKEUP_BLEND[e.makeupBlend] ?? 0,\n whitenStyle: e.whitenStyle === \"pink\" ? 1 : 0,\n }\n}\n"],"mappings":";AAiKO,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,MAAM;AAAA,EACN,UAAU,CAAC,MAAM,MAAM,IAAI;AAAA,EAC3B,OAAO;AAAA,EACP,YAAY,CAAC,KAAK,KAAK,IAAI;AAAA,EAC3B,MAAM;AAAA,EACN,WAAW,CAAC,KAAK,KAAK,IAAI;AAAA,EAC1B,WAAW;AAAA,EACX,gBAAgB,CAAC,MAAM,MAAM,IAAI;AAAA,EACjC,UAAU;AAAA,EACV,MAAM;AAAA,EACN,WAAW,CAAC,KAAK,MAAM,IAAI;AAAA,EAC3B,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,SAAS;AAAA,EACT,WAAW;AAAA,EACX,KAAK;AAAA,EACL,OAAO;AAAA,EACP,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,UAAU,CAAC,GAAG,GAAG,CAAC;AAAA,EAClB,cAAc;AAAA,EACd,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,aAAa;AAAA,EACb,UAAU;AAA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