@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 +22 -0
- package/dist/chunk-BMIOUOT3.js +152 -0
- package/dist/chunk-BMIOUOT3.js.map +1 -0
- package/dist/chunk-WRKQ2NFI.js +183 -0
- package/dist/chunk-WRKQ2NFI.js.map +1 -0
- package/dist/index.d.ts +215 -7
- package/dist/index.js +1667 -36
- package/dist/index.js.map +1 -1
- package/dist/layout.d.ts +164 -0
- package/dist/layout.js +17 -0
- package/dist/layout.js.map +1 -0
- package/dist/mediakit.wasm +0 -0
- package/dist/recipe.d.ts +119 -1
- package/dist/recipe.js +13 -1
- package/dist/whiten_pink.png +0 -0
- package/dist/worker.js +212 -26
- package/dist/worker.js.map +1 -1
- package/package.json +6 -2
- package/dist/chunk-XLLQ74JA.js +0 -112
- package/dist/chunk-XLLQ74JA.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -4,19 +4,32 @@ import {
|
|
|
4
4
|
coreRecipe,
|
|
5
5
|
needsFace,
|
|
6
6
|
needsMask,
|
|
7
|
+
needsSegmentation,
|
|
8
|
+
needsSkinClasses,
|
|
7
9
|
touchUp,
|
|
8
10
|
touchUpAmount
|
|
9
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-WRKQ2NFI.js";
|
|
12
|
+
import {
|
|
13
|
+
BLEND_MODES,
|
|
14
|
+
TRANSITIONS,
|
|
15
|
+
coreLayer,
|
|
16
|
+
hitTest,
|
|
17
|
+
layouts,
|
|
18
|
+
parseColor
|
|
19
|
+
} from "./chunk-BMIOUOT3.js";
|
|
10
20
|
|
|
11
21
|
// src/segmenter.ts
|
|
12
22
|
import { FilesetResolver, ImageSegmenter } from "@mediapipe/tasks-vision";
|
|
13
23
|
var WASM_DIR = "/mediakit/mp";
|
|
14
|
-
var MODEL_URL =
|
|
15
|
-
|
|
24
|
+
var MODEL_URL = {
|
|
25
|
+
person: "/mediakit/selfie_segmenter.tflite",
|
|
26
|
+
classes: "/mediakit/selfie_multiclass_256x256.tflite"
|
|
27
|
+
};
|
|
28
|
+
async function createSegmenter(canvas, model = "person") {
|
|
16
29
|
const fileset = await FilesetResolver.forVisionTasks(WASM_DIR);
|
|
17
30
|
const segmenter = await ImageSegmenter.createFromOptions(fileset, {
|
|
18
31
|
baseOptions: {
|
|
19
|
-
modelAssetPath: MODEL_URL,
|
|
32
|
+
modelAssetPath: MODEL_URL[model],
|
|
20
33
|
// MediaPipe's GPU delegate runs on WebGL2, which Chrome, Safari and Firefox all
|
|
21
34
|
// have. That is why mediakit picked MediaPipe over ONNX Runtime Web at P1: ORT's
|
|
22
35
|
// fast path is WebGPU, which Firefox only has on Windows.
|
|
@@ -196,6 +209,10 @@ var Engine = class _Engine {
|
|
|
196
209
|
backgroundPath = null;
|
|
197
210
|
/** The LUT the core holds, by path, so a slider drag does not decode it again. */
|
|
198
211
|
lutPath = "";
|
|
212
|
+
/** The makeup texture the core holds, by path - see setRecipe. */
|
|
213
|
+
makeupPath = "";
|
|
214
|
+
/** Whether the core holds the pink whitening table. */
|
|
215
|
+
skinLutState = "none";
|
|
199
216
|
closed = false;
|
|
200
217
|
/**
|
|
201
218
|
* The segmenter loads LAZILY - only once a recipe actually needs a person mask.
|
|
@@ -205,6 +222,11 @@ var Engine = class _Engine {
|
|
|
205
222
|
*/
|
|
206
223
|
segmenter = null;
|
|
207
224
|
segmenterLoading = null;
|
|
225
|
+
/** The multiclass segmenter, for recipes that tell skin from clothes (`needsSkinClasses`). */
|
|
226
|
+
classSegmenter = null;
|
|
227
|
+
classLoading = null;
|
|
228
|
+
/** The segmenter whose result this frame borrowed, to give it back after process(). */
|
|
229
|
+
used = null;
|
|
208
230
|
/**
|
|
209
231
|
* The landmark detector, also lazy and independent of the segmenter.
|
|
210
232
|
*
|
|
@@ -227,18 +249,22 @@ var Engine = class _Engine {
|
|
|
227
249
|
this.core = core;
|
|
228
250
|
}
|
|
229
251
|
/** Main thread: makes its own canvas. A worker calls `on` with an OffscreenCanvas. */
|
|
230
|
-
static async create(width, height, filter, effects = NO_EFFECTS) {
|
|
252
|
+
static async create(width, height, filter, effects = NO_EFFECTS, alpha = false) {
|
|
231
253
|
const canvas = document.createElement("canvas");
|
|
232
254
|
canvas.width = width;
|
|
233
255
|
canvas.height = height;
|
|
234
|
-
return _Engine.on(canvas, filter, effects);
|
|
256
|
+
return _Engine.on(canvas, filter, effects, void 0, alpha);
|
|
235
257
|
}
|
|
236
|
-
/**
|
|
237
|
-
|
|
258
|
+
/**
|
|
259
|
+
* `background`: see {@link Engine.setRecipe}. `alpha` keeps the output's alpha channel, which
|
|
260
|
+
* only a `cutout` background writes; it is fixed for the life of the context, so a host that
|
|
261
|
+
* may switch to `cutout` later has to ask for it here.
|
|
262
|
+
*/
|
|
263
|
+
static async on(canvas, filter, effects = NO_EFFECTS, background, alpha = false) {
|
|
238
264
|
const width = canvas.width;
|
|
239
265
|
const height = canvas.height;
|
|
240
266
|
const gl = canvas.getContext("webgl2", {
|
|
241
|
-
alpha
|
|
267
|
+
alpha,
|
|
242
268
|
premultipliedAlpha: false,
|
|
243
269
|
antialias: false,
|
|
244
270
|
depth: false,
|
|
@@ -266,6 +292,9 @@ var Engine = class _Engine {
|
|
|
266
292
|
throw err;
|
|
267
293
|
}
|
|
268
294
|
}
|
|
295
|
+
get loading() {
|
|
296
|
+
return this.segmenterLoading !== null || this.classLoading !== null || this.faceLoading !== null;
|
|
297
|
+
}
|
|
269
298
|
get outputCanvas() {
|
|
270
299
|
return this.canvas;
|
|
271
300
|
}
|
|
@@ -311,8 +340,44 @@ var Engine = class _Engine {
|
|
|
311
340
|
}
|
|
312
341
|
this.lutPath = effects.lut;
|
|
313
342
|
}
|
|
343
|
+
if (effects.whitenStyle === "pink" && this.skinLutState === "none") {
|
|
344
|
+
this.skinLutState = "loading";
|
|
345
|
+
decodeImage("/mediakit/whiten_pink.png", { colorSpaceConversion: "none", premultiplyAlpha: "none" }).then((bmp) => {
|
|
346
|
+
if (this.closed) {
|
|
347
|
+
bmp.close();
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
this.core.setSkinLut(bmp);
|
|
351
|
+
bmp.close();
|
|
352
|
+
this.skinLutState = "ready";
|
|
353
|
+
}).catch((err) => {
|
|
354
|
+
console.error("mediakit: pink whitening table failed to load", err);
|
|
355
|
+
this.skinLutState = "failed";
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
const makeupTexture = effects.makeupTexture ?? "";
|
|
359
|
+
if (makeupTexture !== this.makeupPath) {
|
|
360
|
+
if (makeupTexture) {
|
|
361
|
+
let bmp = null;
|
|
362
|
+
try {
|
|
363
|
+
bmp = await decodeImage(makeupTexture, { premultiplyAlpha: "none" });
|
|
364
|
+
} catch (e) {
|
|
365
|
+
console.error("mediakit: makeup texture failed to load", e);
|
|
366
|
+
}
|
|
367
|
+
if (this.closed || this.filter !== filter || this.effects !== effects) {
|
|
368
|
+
bmp?.close();
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
this.core.setMakeup(bmp);
|
|
372
|
+
bmp?.close();
|
|
373
|
+
} else {
|
|
374
|
+
this.core.setMakeup(null);
|
|
375
|
+
}
|
|
376
|
+
this.makeupPath = makeupTexture;
|
|
377
|
+
}
|
|
314
378
|
this.core.setRecipe(coreRecipe(filter, effects));
|
|
315
|
-
if (
|
|
379
|
+
if (needsSegmentation(filter, effects)) void this.ensureSegmenter();
|
|
380
|
+
if (needsSkinClasses(filter, effects)) void this.ensureClassSegmenter();
|
|
316
381
|
if (needsFace(effects)) void this.ensureFace();
|
|
317
382
|
}
|
|
318
383
|
ensureFace() {
|
|
@@ -334,6 +399,22 @@ var Engine = class _Engine {
|
|
|
334
399
|
});
|
|
335
400
|
return this.faceLoading;
|
|
336
401
|
}
|
|
402
|
+
ensureClassSegmenter() {
|
|
403
|
+
if (this.classSegmenter || this.closed) return Promise.resolve();
|
|
404
|
+
if (this.classLoading) return this.classLoading;
|
|
405
|
+
this.classLoading = createSegmenter(this.canvas, "classes").then((s) => {
|
|
406
|
+
if (this.closed) {
|
|
407
|
+
s.close();
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
this.classSegmenter = s;
|
|
411
|
+
}).catch((e) => {
|
|
412
|
+
console.error("mediakit: multiclass segmenter failed to load", e);
|
|
413
|
+
}).finally(() => {
|
|
414
|
+
this.classLoading = null;
|
|
415
|
+
});
|
|
416
|
+
return this.classLoading;
|
|
417
|
+
}
|
|
337
418
|
ensureSegmenter() {
|
|
338
419
|
if (this.segmenter || this.closed) return Promise.resolve();
|
|
339
420
|
if (this.segmenterLoading) return this.segmenterLoading;
|
|
@@ -369,14 +450,20 @@ var Engine = class _Engine {
|
|
|
369
450
|
const [lo, hi] = splitMicros(timestampUs);
|
|
370
451
|
const needSeg = this.core.decide(lo, hi, this.prevTotalMs, this.prevSegMs) === 1;
|
|
371
452
|
let mask = null;
|
|
453
|
+
let maskKind = 0;
|
|
372
454
|
let segMs = 0;
|
|
455
|
+
this.used = null;
|
|
373
456
|
if (needSeg) {
|
|
374
|
-
|
|
457
|
+
const classes = this.classSegmenter !== null && needsSkinClasses(this.filter, this.effects);
|
|
458
|
+
const seg = classes ? this.classSegmenter : this.segmenter;
|
|
459
|
+
if (!seg) {
|
|
375
460
|
void this.ensureSegmenter();
|
|
376
461
|
} else {
|
|
377
462
|
const s0 = performance.now();
|
|
378
|
-
mask =
|
|
463
|
+
mask = seg.segment(source, timestampUs / 1e3);
|
|
379
464
|
segMs = performance.now() - s0;
|
|
465
|
+
this.used = seg;
|
|
466
|
+
maskKind = classes ? 1 : 0;
|
|
380
467
|
}
|
|
381
468
|
}
|
|
382
469
|
if (this.core.decideFace() === 1) {
|
|
@@ -387,8 +474,9 @@ var Engine = class _Engine {
|
|
|
387
474
|
this.core.setFace(lo, hi, n);
|
|
388
475
|
}
|
|
389
476
|
}
|
|
390
|
-
const glCalls = this.core.process(source, mask, this.background);
|
|
391
|
-
if (mask) this.
|
|
477
|
+
const glCalls = this.core.process(source, mask, this.background, maskKind);
|
|
478
|
+
if (mask) this.used?.release();
|
|
479
|
+
this.used = null;
|
|
392
480
|
this.prevSegMs = segMs;
|
|
393
481
|
this.prevTotalMs = performance.now() - t0;
|
|
394
482
|
const s = this.core.stats();
|
|
@@ -420,14 +508,16 @@ var Engine = class _Engine {
|
|
|
420
508
|
* for the governor and the graph to decide with. See the ToMicros comment in
|
|
421
509
|
* `core/clock.go`.
|
|
422
510
|
*/
|
|
423
|
-
capture(timestampUs) {
|
|
424
|
-
return new VideoFrame(this.canvas, { timestamp: timestampUs, alpha: "discard" });
|
|
511
|
+
capture(timestampUs, keepAlpha = false) {
|
|
512
|
+
return new VideoFrame(this.canvas, { timestamp: timestampUs, alpha: keepAlpha ? "keep" : "discard" });
|
|
425
513
|
}
|
|
426
514
|
close() {
|
|
427
515
|
if (this.closed) return;
|
|
428
516
|
this.closed = true;
|
|
429
517
|
this.segmenter?.close();
|
|
430
518
|
this.segmenter = null;
|
|
519
|
+
this.classSegmenter?.close();
|
|
520
|
+
this.classSegmenter = null;
|
|
431
521
|
this.face?.close();
|
|
432
522
|
this.face = null;
|
|
433
523
|
this.lmBuf = null;
|
|
@@ -436,6 +526,7 @@ var Engine = class _Engine {
|
|
|
436
526
|
this.background = null;
|
|
437
527
|
this.backgroundPath = null;
|
|
438
528
|
this.lutPath = "";
|
|
529
|
+
this.makeupPath = "";
|
|
439
530
|
this.gl.getExtension("WEBGL_lose_context")?.loseContext();
|
|
440
531
|
}
|
|
441
532
|
};
|
|
@@ -491,6 +582,9 @@ async function coverCrop(src, w, h) {
|
|
|
491
582
|
|
|
492
583
|
// src/pipeline.ts
|
|
493
584
|
var WORKER_READY_MS = 8e3;
|
|
585
|
+
var STALL_MS = 2e3;
|
|
586
|
+
var LOADING_STALL_MS = 2e4;
|
|
587
|
+
var WORKER_DEAD_MS = 8e3;
|
|
494
588
|
function hasInsertableStreams() {
|
|
495
589
|
return typeof window !== "undefined" && "MediaStreamTrackProcessor" in window && "MediaStreamTrackGenerator" in window;
|
|
496
590
|
}
|
|
@@ -505,6 +599,19 @@ var VideoPipeline = class {
|
|
|
505
599
|
processedTrack;
|
|
506
600
|
filter;
|
|
507
601
|
effects;
|
|
602
|
+
opts;
|
|
603
|
+
// Health: a beat per frame out.
|
|
604
|
+
source = null;
|
|
605
|
+
size = { width: 1280, height: 720, fps: 30 };
|
|
606
|
+
lastBeat = 0;
|
|
607
|
+
frames = 0;
|
|
608
|
+
stalled = false;
|
|
609
|
+
watchdog = null;
|
|
610
|
+
movedOff = false;
|
|
611
|
+
/** What the worker last said about loading detectors. */
|
|
612
|
+
workerLoading = false;
|
|
613
|
+
// Frames handed out alongside the track - see subscribeFrames.
|
|
614
|
+
frameSubs = /* @__PURE__ */ new Set();
|
|
508
615
|
engine = null;
|
|
509
616
|
transport = "insertable";
|
|
510
617
|
// insertable path
|
|
@@ -518,9 +625,93 @@ var VideoPipeline = class {
|
|
|
518
625
|
video = null;
|
|
519
626
|
rvfcHandle = 0;
|
|
520
627
|
stopped = false;
|
|
521
|
-
constructor(filter, effects = NO_EFFECTS) {
|
|
628
|
+
constructor(filter, effects = NO_EFFECTS, opts = {}) {
|
|
522
629
|
this.filter = filter;
|
|
523
630
|
this.effects = effects;
|
|
631
|
+
this.opts = opts;
|
|
632
|
+
}
|
|
633
|
+
/** Whether frames are coming out, and how long since the last one. */
|
|
634
|
+
get health() {
|
|
635
|
+
return {
|
|
636
|
+
transport: this.transport,
|
|
637
|
+
frames: this.frames,
|
|
638
|
+
sinceMs: this.lastBeat ? performance.now() - this.lastBeat : 0,
|
|
639
|
+
stalled: this.stalled
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
/** Every processed frame. */
|
|
643
|
+
subscribeFrames(cb) {
|
|
644
|
+
this.frameSubs.add(cb);
|
|
645
|
+
if (this.frameSubs.size === 1) this.send({ t: "frames", on: true });
|
|
646
|
+
return () => {
|
|
647
|
+
this.frameSubs.delete(cb);
|
|
648
|
+
if (this.frameSubs.size === 0) this.send({ t: "frames", on: false });
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
deliver(frame) {
|
|
652
|
+
const subs = [...this.frameSubs];
|
|
653
|
+
if (subs.length === 0) {
|
|
654
|
+
frame.close();
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
subs.forEach((cb, i) => {
|
|
658
|
+
try {
|
|
659
|
+
cb(i === subs.length - 1 ? frame : frame.clone());
|
|
660
|
+
} catch (e) {
|
|
661
|
+
console.error("mediakit: frame subscriber threw", e);
|
|
662
|
+
}
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
beat() {
|
|
666
|
+
this.lastBeat = performance.now();
|
|
667
|
+
this.frames++;
|
|
668
|
+
this.stalled = false;
|
|
669
|
+
}
|
|
670
|
+
startWatchdog() {
|
|
671
|
+
this.stopWatchdog();
|
|
672
|
+
this.lastBeat = performance.now();
|
|
673
|
+
this.watchdog = setInterval(() => {
|
|
674
|
+
if (this.stopped || !this.source) return;
|
|
675
|
+
if (this.source.readyState !== "live" || this.source.muted) {
|
|
676
|
+
this.lastBeat = performance.now();
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
if (this.transport === "canvas" && typeof document !== "undefined" && document.visibilityState !== "visible") {
|
|
680
|
+
this.lastBeat = performance.now();
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
const since = performance.now() - this.lastBeat;
|
|
684
|
+
const loading = this.transport === "worker" ? this.workerLoading : this.engine?.loading ?? false;
|
|
685
|
+
const transport = this.transport;
|
|
686
|
+
if (since >= (loading ? LOADING_STALL_MS : STALL_MS) && !this.stalled) {
|
|
687
|
+
this.stalled = true;
|
|
688
|
+
console.warn(`mediakit: no frame out for ${Math.round(since)}ms on the ${transport} transport`);
|
|
689
|
+
this.opts.onStall?.({ transport, sinceMs: since });
|
|
690
|
+
}
|
|
691
|
+
if (transport === "worker" && since >= (loading ? LOADING_STALL_MS : WORKER_DEAD_MS)) {
|
|
692
|
+
void this.moveOffWorker("silent");
|
|
693
|
+
}
|
|
694
|
+
}, 1e3);
|
|
695
|
+
}
|
|
696
|
+
stopWatchdog() {
|
|
697
|
+
if (this.watchdog) clearInterval(this.watchdog);
|
|
698
|
+
this.watchdog = null;
|
|
699
|
+
}
|
|
700
|
+
/** The worker failed or stalled AFTER the host published its track. */
|
|
701
|
+
async moveOffWorker(reason) {
|
|
702
|
+
if (this.movedOff || this.stopped || !this.source) return;
|
|
703
|
+
this.movedOff = true;
|
|
704
|
+
console.warn(`mediakit: worker ${reason} after start, moving to the main thread`);
|
|
705
|
+
const previous = this.processedTrack;
|
|
706
|
+
this.teardownWorker();
|
|
707
|
+
try {
|
|
708
|
+
await this.startMain(this.source);
|
|
709
|
+
} catch (e) {
|
|
710
|
+
console.error("mediakit: main-thread fallback failed", e);
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
previous?.stop();
|
|
714
|
+
if (this.processedTrack) this.opts.onTrackReplaced?.(this.processedTrack, previous);
|
|
524
715
|
}
|
|
525
716
|
get stats() {
|
|
526
717
|
return this.transport === "worker" ? this.workerStats : this.engine?.last ?? null;
|
|
@@ -534,6 +725,10 @@ var VideoPipeline = class {
|
|
|
534
725
|
const width = settings.width ?? 1280;
|
|
535
726
|
const height = settings.height ?? 720;
|
|
536
727
|
this.stopped = false;
|
|
728
|
+
this.source = source;
|
|
729
|
+
this.size = { width, height, fps: settings.frameRate ?? 30 };
|
|
730
|
+
this.frames = 0;
|
|
731
|
+
this.startWatchdog();
|
|
537
732
|
if (hasInsertableStreams() && typeof Worker !== "undefined" && typeof OffscreenCanvas !== "undefined") {
|
|
538
733
|
try {
|
|
539
734
|
await this.startWorker(source, width, height, await this.backgroundForWorker(this.filter));
|
|
@@ -543,13 +738,29 @@ var VideoPipeline = class {
|
|
|
543
738
|
this.teardownWorker();
|
|
544
739
|
console.warn("mediakit: worker unusable, falling back to the main thread", e);
|
|
545
740
|
}
|
|
741
|
+
} else if (typeof Worker !== "undefined" && typeof OffscreenCanvas !== "undefined") {
|
|
742
|
+
try {
|
|
743
|
+
await this.startWorkerWithTrack(source, width, height, await this.backgroundForWorker(this.filter));
|
|
744
|
+
this.transport = "worker";
|
|
745
|
+
return;
|
|
746
|
+
} catch (e) {
|
|
747
|
+
this.teardownWorker();
|
|
748
|
+
console.warn("mediakit: no worker transport in this browser, staying on the main thread", e);
|
|
749
|
+
}
|
|
546
750
|
}
|
|
547
|
-
|
|
751
|
+
await this.startMain(source);
|
|
752
|
+
}
|
|
753
|
+
async startMain(source) {
|
|
754
|
+
const { width, height, fps } = this.size;
|
|
755
|
+
this.engine = await Engine.create(width, height, this.filter, this.effects, this.opts.alpha ?? false);
|
|
548
756
|
this.transport = hasInsertableStreams() ? "insertable" : "canvas";
|
|
757
|
+
this.frames = 0;
|
|
758
|
+
this.lastBeat = performance.now();
|
|
759
|
+
this.stalled = false;
|
|
549
760
|
if (this.transport === "insertable") {
|
|
550
761
|
this.startInsertable(source);
|
|
551
762
|
} else {
|
|
552
|
-
await this.startCanvas(source,
|
|
763
|
+
await this.startCanvas(source, fps);
|
|
553
764
|
}
|
|
554
765
|
}
|
|
555
766
|
/** Swap the background in place - no pipeline rebuild, so the picture does not flash. */
|
|
@@ -573,6 +784,8 @@ var VideoPipeline = class {
|
|
|
573
784
|
}
|
|
574
785
|
async stop() {
|
|
575
786
|
this.stopped = true;
|
|
787
|
+
this.stopWatchdog();
|
|
788
|
+
this.source = null;
|
|
576
789
|
this.abort?.abort();
|
|
577
790
|
this.abort = null;
|
|
578
791
|
if (this.rvfcHandle && this.video) {
|
|
@@ -612,6 +825,7 @@ var VideoPipeline = class {
|
|
|
612
825
|
this.worker.terminate();
|
|
613
826
|
this.worker = null;
|
|
614
827
|
this.workerStats = null;
|
|
828
|
+
this.workerLoading = false;
|
|
615
829
|
this.workerBackgroundPath = null;
|
|
616
830
|
}
|
|
617
831
|
/**
|
|
@@ -647,6 +861,53 @@ var VideoPipeline = class {
|
|
|
647
861
|
kind: "video",
|
|
648
862
|
signalTarget: source
|
|
649
863
|
});
|
|
864
|
+
return this.attachWorker(
|
|
865
|
+
(ready) => {
|
|
866
|
+
this.processedTrack = ready.track ?? generator;
|
|
867
|
+
},
|
|
868
|
+
() => generator.stop(),
|
|
869
|
+
() => this.send(
|
|
870
|
+
{
|
|
871
|
+
t: "start",
|
|
872
|
+
readable: processor.readable,
|
|
873
|
+
writable: generator.writable,
|
|
874
|
+
width,
|
|
875
|
+
height,
|
|
876
|
+
filter: this.filter,
|
|
877
|
+
effects: this.effects,
|
|
878
|
+
background,
|
|
879
|
+
alpha: this.opts.alpha
|
|
880
|
+
},
|
|
881
|
+
background ? [processor.readable, generator.writable, background] : [processor.readable, generator.writable]
|
|
882
|
+
)
|
|
883
|
+
);
|
|
884
|
+
}
|
|
885
|
+
/** Safari's dialect (see `startTrack` in worker/entry.ts). */
|
|
886
|
+
startWorkerWithTrack(source, width, height, background) {
|
|
887
|
+
const clone = source.clone();
|
|
888
|
+
return this.attachWorker(
|
|
889
|
+
(ready) => {
|
|
890
|
+
if (!ready.track) throw new Error("mediakit: the worker sent no track");
|
|
891
|
+
this.processedTrack = ready.track;
|
|
892
|
+
},
|
|
893
|
+
() => clone.stop(),
|
|
894
|
+
() => this.send(
|
|
895
|
+
{
|
|
896
|
+
t: "startTrack",
|
|
897
|
+
track: clone,
|
|
898
|
+
width,
|
|
899
|
+
height,
|
|
900
|
+
filter: this.filter,
|
|
901
|
+
effects: this.effects,
|
|
902
|
+
background,
|
|
903
|
+
alpha: this.opts.alpha
|
|
904
|
+
},
|
|
905
|
+
background ? [clone, background] : [clone]
|
|
906
|
+
)
|
|
907
|
+
);
|
|
908
|
+
}
|
|
909
|
+
/** Starts the worker and waits for its "ready". */
|
|
910
|
+
attachWorker(onReady, cleanup, post) {
|
|
650
911
|
const worker = new Worker("/mediakit/worker.js");
|
|
651
912
|
this.worker = worker;
|
|
652
913
|
return new Promise((resolve, reject) => {
|
|
@@ -655,47 +916,57 @@ var VideoPipeline = class {
|
|
|
655
916
|
if (settled) return;
|
|
656
917
|
settled = true;
|
|
657
918
|
clearTimeout(timer);
|
|
658
|
-
|
|
919
|
+
cleanup();
|
|
659
920
|
reject(err);
|
|
660
921
|
};
|
|
661
922
|
const timer = setTimeout(
|
|
662
923
|
() => fail(new Error(`mediakit: worker silent for more than ${WORKER_READY_MS}ms`)),
|
|
663
924
|
WORKER_READY_MS
|
|
664
925
|
);
|
|
665
|
-
worker.onerror = (e) =>
|
|
926
|
+
worker.onerror = (e) => {
|
|
927
|
+
if (settled) {
|
|
928
|
+
void this.moveOffWorker(e.message || "crashed");
|
|
929
|
+
return;
|
|
930
|
+
}
|
|
931
|
+
fail(new Error(e.message || "mediakit: worker failed to load"));
|
|
932
|
+
};
|
|
666
933
|
worker.onmessage = (e) => {
|
|
667
934
|
const m = e.data;
|
|
668
935
|
if (m.t === "stats") {
|
|
669
936
|
this.workerStats = m.stats;
|
|
937
|
+
this.lastBeat = performance.now();
|
|
938
|
+
if (m.frames >= 0) this.frames = m.frames;
|
|
939
|
+
this.workerLoading = m.loading;
|
|
940
|
+
this.stalled = false;
|
|
941
|
+
return;
|
|
942
|
+
}
|
|
943
|
+
if (m.t === "frame") {
|
|
944
|
+
this.deliver(m.frame);
|
|
670
945
|
return;
|
|
671
946
|
}
|
|
672
947
|
if (m.t === "error") {
|
|
673
948
|
if (settled) {
|
|
674
949
|
console.error("mediakit: worker failed after start", m.message);
|
|
950
|
+
void this.moveOffWorker("failed");
|
|
675
951
|
return;
|
|
676
952
|
}
|
|
677
953
|
fail(new Error(m.message));
|
|
678
954
|
return;
|
|
679
955
|
}
|
|
956
|
+
this.workerLoading = m.loading;
|
|
957
|
+
try {
|
|
958
|
+
onReady(m);
|
|
959
|
+
} catch (err) {
|
|
960
|
+
fail(err instanceof Error ? err : new Error(String(err)));
|
|
961
|
+
return;
|
|
962
|
+
}
|
|
680
963
|
settled = true;
|
|
681
964
|
clearTimeout(timer);
|
|
682
|
-
this.
|
|
965
|
+
if (this.frameSubs.size > 0) this.send({ t: "frames", on: true });
|
|
683
966
|
resolve();
|
|
684
967
|
};
|
|
685
968
|
try {
|
|
686
|
-
|
|
687
|
-
{
|
|
688
|
-
t: "start",
|
|
689
|
-
readable: processor.readable,
|
|
690
|
-
writable: generator.writable,
|
|
691
|
-
width,
|
|
692
|
-
height,
|
|
693
|
-
filter: this.filter,
|
|
694
|
-
effects: this.effects,
|
|
695
|
-
background
|
|
696
|
-
},
|
|
697
|
-
background ? [processor.readable, generator.writable, background] : [processor.readable, generator.writable]
|
|
698
|
-
);
|
|
969
|
+
post();
|
|
699
970
|
} catch (err) {
|
|
700
971
|
fail(err instanceof Error ? err : new Error(String(err)));
|
|
701
972
|
}
|
|
@@ -713,10 +984,13 @@ var VideoPipeline = class {
|
|
|
713
984
|
});
|
|
714
985
|
const transform = new TransformStream({
|
|
715
986
|
transform: (frame, controller) => {
|
|
987
|
+
this.beat();
|
|
716
988
|
try {
|
|
717
989
|
if (engine.render(frame, frame.timestamp)) {
|
|
718
990
|
controller.enqueue(engine.capture(frame.timestamp));
|
|
991
|
+
if (this.frameSubs.size > 0) this.deliver(engine.capture(frame.timestamp, true));
|
|
719
992
|
} else {
|
|
993
|
+
if (this.frameSubs.size > 0) this.deliver(frame.clone());
|
|
720
994
|
controller.enqueue(frame);
|
|
721
995
|
return;
|
|
722
996
|
}
|
|
@@ -758,8 +1032,13 @@ var VideoPipeline = class {
|
|
|
758
1032
|
this.processedTrack = stream.getVideoTracks()[0];
|
|
759
1033
|
const pump = (_now, meta) => {
|
|
760
1034
|
if (this.stopped || !this.engine) return;
|
|
1035
|
+
this.beat();
|
|
761
1036
|
try {
|
|
762
|
-
|
|
1037
|
+
const ts = Math.round(meta.mediaTime * 1e6);
|
|
1038
|
+
const drew = this.engine.render(video, ts);
|
|
1039
|
+
if (this.frameSubs.size > 0) {
|
|
1040
|
+
this.deliver(drew ? this.engine.capture(ts, true) : new VideoFrame(video, { timestamp: ts }));
|
|
1041
|
+
}
|
|
763
1042
|
} catch (e) {
|
|
764
1043
|
console.error("mediakit: frame processing failed", e);
|
|
765
1044
|
}
|
|
@@ -773,14 +1052,1366 @@ var VideoPipeline = class {
|
|
|
773
1052
|
this.rvfcHandle = video.requestVideoFrameCallback(pump);
|
|
774
1053
|
}
|
|
775
1054
|
};
|
|
1055
|
+
|
|
1056
|
+
// src/scene.ts
|
|
1057
|
+
var MAX_SOURCES = 8;
|
|
1058
|
+
var Scene = class _Scene {
|
|
1059
|
+
canvas;
|
|
1060
|
+
core;
|
|
1061
|
+
gl;
|
|
1062
|
+
sources = /* @__PURE__ */ new Map();
|
|
1063
|
+
current = [];
|
|
1064
|
+
fps;
|
|
1065
|
+
timer = null;
|
|
1066
|
+
closed = false;
|
|
1067
|
+
recorder = null;
|
|
1068
|
+
recorded = [];
|
|
1069
|
+
last = { glCalls: 0, frameMs: 0, sources: 0, layers: 0 };
|
|
1070
|
+
constructor(canvas, gl, core, fps) {
|
|
1071
|
+
this.canvas = canvas;
|
|
1072
|
+
this.gl = gl;
|
|
1073
|
+
this.core = core;
|
|
1074
|
+
this.fps = fps;
|
|
1075
|
+
}
|
|
1076
|
+
static async create(opts) {
|
|
1077
|
+
const canvas = document.createElement("canvas");
|
|
1078
|
+
canvas.width = opts.width;
|
|
1079
|
+
canvas.height = opts.height;
|
|
1080
|
+
const gl = canvas.getContext("webgl2", {
|
|
1081
|
+
alpha: false,
|
|
1082
|
+
premultipliedAlpha: false,
|
|
1083
|
+
antialias: false,
|
|
1084
|
+
depth: false,
|
|
1085
|
+
stencil: false,
|
|
1086
|
+
preserveDrawingBuffer: true
|
|
1087
|
+
});
|
|
1088
|
+
if (!gl) throw new Error("mediakit: no WebGL2 in this browser");
|
|
1089
|
+
let core;
|
|
1090
|
+
try {
|
|
1091
|
+
core = await loadCore();
|
|
1092
|
+
const err = core.sceneInit(gl, opts.width, opts.height);
|
|
1093
|
+
if (err) throw new Error(`mediakit: ${err}`);
|
|
1094
|
+
} catch (err) {
|
|
1095
|
+
core?.sceneClose();
|
|
1096
|
+
gl.getExtension("WEBGL_lose_context")?.loseContext();
|
|
1097
|
+
throw err;
|
|
1098
|
+
}
|
|
1099
|
+
const scene = new _Scene(canvas, gl, core, opts.fps ?? 30);
|
|
1100
|
+
scene.setBackground(opts.background ?? "#000");
|
|
1101
|
+
return scene;
|
|
1102
|
+
}
|
|
1103
|
+
setBackground(c) {
|
|
1104
|
+
const [r, g, b] = parseColor(c);
|
|
1105
|
+
this.core.sceneBackground(r, g, b);
|
|
1106
|
+
}
|
|
1107
|
+
/** Add a source, or replace the one with this id; it keeps its slot, so layers stay put. */
|
|
1108
|
+
async addSource(id, spec) {
|
|
1109
|
+
if (this.closed) return;
|
|
1110
|
+
const old = this.sources.get(id);
|
|
1111
|
+
const slot = old ? old.slot : this.freeSlot();
|
|
1112
|
+
if (slot < 0) throw new Error(`mediakit: a scene holds at most ${MAX_SOURCES} sources`);
|
|
1113
|
+
if (old) this.dispose(old);
|
|
1114
|
+
const live = { slot, spec, dirty: false, fresh: false };
|
|
1115
|
+
this.sources.set(id, live);
|
|
1116
|
+
try {
|
|
1117
|
+
await this.open(live);
|
|
1118
|
+
} catch (err) {
|
|
1119
|
+
this.dispose(live);
|
|
1120
|
+
if (this.sources.get(id) === live) {
|
|
1121
|
+
this.sources.delete(id);
|
|
1122
|
+
this.core.sceneUpload(slot, null, 0, 0);
|
|
1123
|
+
}
|
|
1124
|
+
throw err;
|
|
1125
|
+
}
|
|
1126
|
+
if (this.closed || this.sources.get(id) !== live) {
|
|
1127
|
+
this.dispose(live);
|
|
1128
|
+
return;
|
|
1129
|
+
}
|
|
1130
|
+
this.push(0);
|
|
1131
|
+
}
|
|
1132
|
+
/**
|
|
1133
|
+
* Change a source without replacing it: new text or style for text, a new recipe for a
|
|
1134
|
+
* camera. Anything else is the same as {@link addSource}.
|
|
1135
|
+
*/
|
|
1136
|
+
async updateSource(id, spec) {
|
|
1137
|
+
const live = this.sources.get(id);
|
|
1138
|
+
if (!live || this.closed) return;
|
|
1139
|
+
if (spec.kind === "text" && live.spec.kind === "text") {
|
|
1140
|
+
live.spec = spec;
|
|
1141
|
+
live.picture = renderText(spec.text, spec.style);
|
|
1142
|
+
live.dirty = true;
|
|
1143
|
+
return;
|
|
1144
|
+
}
|
|
1145
|
+
if (spec.kind === "camera" && live.spec.kind === "camera" && spec.track === live.spec.track) {
|
|
1146
|
+
live.spec = spec;
|
|
1147
|
+
await this.ensureEngine(live);
|
|
1148
|
+
return;
|
|
1149
|
+
}
|
|
1150
|
+
return this.addSource(id, spec);
|
|
1151
|
+
}
|
|
1152
|
+
removeSource(id) {
|
|
1153
|
+
const live = this.sources.get(id);
|
|
1154
|
+
if (!live) return;
|
|
1155
|
+
this.dispose(live);
|
|
1156
|
+
this.sources.delete(id);
|
|
1157
|
+
this.core.sceneUpload(live.slot, null, 0, 0);
|
|
1158
|
+
this.push(0);
|
|
1159
|
+
}
|
|
1160
|
+
get layers() {
|
|
1161
|
+
return this.current;
|
|
1162
|
+
}
|
|
1163
|
+
/** Change the layout in place. With `animate` (ms) layers glide to their new state. */
|
|
1164
|
+
setLayers(layers, opts = {}) {
|
|
1165
|
+
this.current = layers.slice();
|
|
1166
|
+
this.push(opts.animate ?? 0);
|
|
1167
|
+
}
|
|
1168
|
+
/** Move to another layout through a transition. */
|
|
1169
|
+
switchTo(layers, transition = { kind: "cut" }) {
|
|
1170
|
+
if (this.closed) return;
|
|
1171
|
+
this.current = layers.slice();
|
|
1172
|
+
const [lo, hi] = splitMicros(now());
|
|
1173
|
+
this.core.sceneSwitch(this.coreLayers(), lo, hi, Math.max(0, TRANSITIONS.indexOf(transition.kind)), transition.duration ?? 500);
|
|
1174
|
+
}
|
|
1175
|
+
/** The topmost layer under a point of the output, in fractions, for picking and dragging. */
|
|
1176
|
+
layerAt(x, y) {
|
|
1177
|
+
return hitTest(this.current, x, y, this.canvas.width / this.canvas.height);
|
|
1178
|
+
}
|
|
1179
|
+
start() {
|
|
1180
|
+
if (this.timer || this.closed) return;
|
|
1181
|
+
const period = 1e3 / this.fps;
|
|
1182
|
+
let next = performance.now();
|
|
1183
|
+
let failed = false;
|
|
1184
|
+
const tick = () => {
|
|
1185
|
+
try {
|
|
1186
|
+
this.render();
|
|
1187
|
+
} catch (err) {
|
|
1188
|
+
if (!failed) console.error("mediakit: scene frame failed", err);
|
|
1189
|
+
failed = true;
|
|
1190
|
+
}
|
|
1191
|
+
next += period;
|
|
1192
|
+
const t = performance.now();
|
|
1193
|
+
if (next < t) next = t;
|
|
1194
|
+
this.timer = setTimeout(tick, next - t);
|
|
1195
|
+
};
|
|
1196
|
+
tick();
|
|
1197
|
+
}
|
|
1198
|
+
stop() {
|
|
1199
|
+
if (this.timer) clearTimeout(this.timer);
|
|
1200
|
+
this.timer = null;
|
|
1201
|
+
}
|
|
1202
|
+
/** Draw one frame now. The loop calls this; a host with its own loop can instead. */
|
|
1203
|
+
render() {
|
|
1204
|
+
if (this.closed) return 0;
|
|
1205
|
+
const t0 = performance.now();
|
|
1206
|
+
const us = now();
|
|
1207
|
+
for (const live of this.sources.values()) this.feed(live, us);
|
|
1208
|
+
const [lo, hi] = splitMicros(us);
|
|
1209
|
+
const calls = this.core.sceneRender(lo, hi);
|
|
1210
|
+
this.last = { glCalls: calls, frameMs: performance.now() - t0, sources: this.sources.size, layers: this.current.length };
|
|
1211
|
+
return calls;
|
|
1212
|
+
}
|
|
1213
|
+
/** The output as a live stream, for a call, a recorder or a `<video>`. */
|
|
1214
|
+
captureStream(fps = this.fps) {
|
|
1215
|
+
return this.canvas.captureStream(fps);
|
|
1216
|
+
}
|
|
1217
|
+
/** The current frame as an image file. */
|
|
1218
|
+
snapshot(type = "image/png") {
|
|
1219
|
+
return new Promise(
|
|
1220
|
+
(resolve, reject) => this.canvas.toBlob((b) => b ? resolve(b) : reject(new Error("mediakit: snapshot failed")), type)
|
|
1221
|
+
);
|
|
1222
|
+
}
|
|
1223
|
+
/** Record the output, optionally with an audio track, until {@link stopRecording}. */
|
|
1224
|
+
startRecording(opts = {}) {
|
|
1225
|
+
if (this.recorder) return;
|
|
1226
|
+
const stream = this.captureStream();
|
|
1227
|
+
if (opts.audio) stream.addTrack(opts.audio);
|
|
1228
|
+
const rec = new MediaRecorder(stream, { mimeType: opts.mimeType, videoBitsPerSecond: opts.videoBitsPerSecond });
|
|
1229
|
+
const chunks = [];
|
|
1230
|
+
rec.ondataavailable = (e) => chunks.push(e.data);
|
|
1231
|
+
this.recorder = rec;
|
|
1232
|
+
this.recorded = chunks;
|
|
1233
|
+
rec.start(1e3);
|
|
1234
|
+
}
|
|
1235
|
+
stopRecording() {
|
|
1236
|
+
const rec = this.recorder;
|
|
1237
|
+
if (!rec) return Promise.reject(new Error("mediakit: not recording"));
|
|
1238
|
+
const chunks = this.recorded;
|
|
1239
|
+
this.recorder = null;
|
|
1240
|
+
this.recorded = [];
|
|
1241
|
+
return new Promise((resolve) => {
|
|
1242
|
+
rec.onstop = () => {
|
|
1243
|
+
for (const t of rec.stream.getVideoTracks()) t.stop();
|
|
1244
|
+
resolve(new Blob(chunks, { type: rec.mimeType }));
|
|
1245
|
+
};
|
|
1246
|
+
rec.stop();
|
|
1247
|
+
});
|
|
1248
|
+
}
|
|
1249
|
+
close() {
|
|
1250
|
+
if (this.closed) return;
|
|
1251
|
+
this.stop();
|
|
1252
|
+
if (this.recorder && this.recorder.state !== "inactive") this.recorder.stop();
|
|
1253
|
+
for (const t of this.recorder?.stream.getVideoTracks() ?? []) t.stop();
|
|
1254
|
+
this.recorder = null;
|
|
1255
|
+
this.recorded = [];
|
|
1256
|
+
for (const live of this.sources.values()) this.dispose(live);
|
|
1257
|
+
this.sources.clear();
|
|
1258
|
+
this.closed = true;
|
|
1259
|
+
this.core.sceneClose();
|
|
1260
|
+
this.gl.getExtension("WEBGL_lose_context")?.loseContext();
|
|
1261
|
+
}
|
|
1262
|
+
freeSlot() {
|
|
1263
|
+
const used = new Set([...this.sources.values()].map((s) => s.slot));
|
|
1264
|
+
for (let i = 0; i < MAX_SOURCES; i++) if (!used.has(i)) return i;
|
|
1265
|
+
return -1;
|
|
1266
|
+
}
|
|
1267
|
+
coreLayers() {
|
|
1268
|
+
return this.current.map((l) => coreLayer(l, (id) => this.sources.get(id)?.slot ?? -1));
|
|
1269
|
+
}
|
|
1270
|
+
push(animateMs) {
|
|
1271
|
+
if (this.closed) return;
|
|
1272
|
+
const [lo, hi] = splitMicros(now());
|
|
1273
|
+
this.core.sceneSet(this.coreLayers(), lo, hi, animateMs);
|
|
1274
|
+
}
|
|
1275
|
+
async open(live) {
|
|
1276
|
+
const s = live.spec;
|
|
1277
|
+
switch (s.kind) {
|
|
1278
|
+
case "camera":
|
|
1279
|
+
case "track":
|
|
1280
|
+
live.video = await playVideo((v) => v.srcObject = new MediaStream([s.track]));
|
|
1281
|
+
watchFrames(live);
|
|
1282
|
+
if (s.kind === "camera") await this.ensureEngine(live);
|
|
1283
|
+
return;
|
|
1284
|
+
case "video":
|
|
1285
|
+
live.video = await playVideo((v) => {
|
|
1286
|
+
v.src = s.url;
|
|
1287
|
+
v.loop = s.loop ?? true;
|
|
1288
|
+
v.crossOrigin = "anonymous";
|
|
1289
|
+
});
|
|
1290
|
+
watchFrames(live);
|
|
1291
|
+
return;
|
|
1292
|
+
case "image":
|
|
1293
|
+
live.picture = "bitmap" in s ? s.bitmap : await decodeImage(s.url);
|
|
1294
|
+
live.dirty = true;
|
|
1295
|
+
return;
|
|
1296
|
+
case "text":
|
|
1297
|
+
live.picture = renderText(s.text, s.style);
|
|
1298
|
+
live.dirty = true;
|
|
1299
|
+
return;
|
|
1300
|
+
case "canvas":
|
|
1301
|
+
live.picture = s.canvas;
|
|
1302
|
+
return;
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
/**
|
|
1306
|
+
* Build, update or drop a camera's Engine to match its recipe and its current size. An
|
|
1307
|
+
* Engine is sized at creation, so a camera that changes resolution needs a new one.
|
|
1308
|
+
*/
|
|
1309
|
+
async ensureEngine(live) {
|
|
1310
|
+
const s = live.spec;
|
|
1311
|
+
const v = live.video;
|
|
1312
|
+
if (s.kind !== "camera" || !v || live.engineBusy) return;
|
|
1313
|
+
const filter = s.filter ?? { kind: "none" };
|
|
1314
|
+
const effects = s.effects ?? NO_EFFECTS;
|
|
1315
|
+
const wanted = filter.kind !== "none" || active(effects);
|
|
1316
|
+
const w = v.videoWidth;
|
|
1317
|
+
const h = v.videoHeight;
|
|
1318
|
+
const e = live.engine;
|
|
1319
|
+
if (e && wanted && e.outputCanvas.width === w && e.outputCanvas.height === h) {
|
|
1320
|
+
await e.setRecipe(filter, effects);
|
|
1321
|
+
return;
|
|
1322
|
+
}
|
|
1323
|
+
e?.close();
|
|
1324
|
+
live.engine = void 0;
|
|
1325
|
+
if (!wanted || !w || !h) return;
|
|
1326
|
+
live.engineBusy = true;
|
|
1327
|
+
try {
|
|
1328
|
+
const canvas = document.createElement("canvas");
|
|
1329
|
+
canvas.width = w;
|
|
1330
|
+
canvas.height = h;
|
|
1331
|
+
const engine = await Engine.on(canvas, filter, effects, void 0, true);
|
|
1332
|
+
if (this.closed || ![...this.sources.values()].includes(live)) engine.close();
|
|
1333
|
+
else live.engine = engine;
|
|
1334
|
+
} finally {
|
|
1335
|
+
live.engineBusy = false;
|
|
1336
|
+
}
|
|
1337
|
+
if (live.engine && live.spec !== s) await this.ensureEngine(live);
|
|
1338
|
+
}
|
|
1339
|
+
feed(live, us) {
|
|
1340
|
+
const v = live.video;
|
|
1341
|
+
if (v) {
|
|
1342
|
+
if (live.rvfc && !live.fresh || v.readyState < 2 || !v.videoWidth) return;
|
|
1343
|
+
live.fresh = false;
|
|
1344
|
+
const e = live.engine;
|
|
1345
|
+
if (e && (e.outputCanvas.width !== v.videoWidth || e.outputCanvas.height !== v.videoHeight)) {
|
|
1346
|
+
void this.ensureEngine(live);
|
|
1347
|
+
} else if (e && e.render(v, us)) {
|
|
1348
|
+
this.core.sceneUpload(live.slot, e.outputCanvas, e.outputCanvas.width, e.outputCanvas.height);
|
|
1349
|
+
return;
|
|
1350
|
+
}
|
|
1351
|
+
this.core.sceneUpload(live.slot, v, v.videoWidth, v.videoHeight);
|
|
1352
|
+
return;
|
|
1353
|
+
}
|
|
1354
|
+
const p = live.picture;
|
|
1355
|
+
if (!p) return;
|
|
1356
|
+
if (live.spec.kind === "canvas" || live.dirty) {
|
|
1357
|
+
live.dirty = false;
|
|
1358
|
+
this.core.sceneUpload(live.slot, p, p.width, p.height);
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
dispose(live) {
|
|
1362
|
+
live.engine?.close();
|
|
1363
|
+
live.engine = void 0;
|
|
1364
|
+
if (live.video) {
|
|
1365
|
+
live.video.pause();
|
|
1366
|
+
live.video.srcObject = null;
|
|
1367
|
+
live.video.removeAttribute("src");
|
|
1368
|
+
live.video.load();
|
|
1369
|
+
live.video = void 0;
|
|
1370
|
+
}
|
|
1371
|
+
const s = live.spec;
|
|
1372
|
+
if (live.picture instanceof ImageBitmap && !(s.kind === "image" && "bitmap" in s)) live.picture.close();
|
|
1373
|
+
live.picture = void 0;
|
|
1374
|
+
}
|
|
1375
|
+
};
|
|
1376
|
+
function now() {
|
|
1377
|
+
return Math.round(performance.now() * 1e3);
|
|
1378
|
+
}
|
|
1379
|
+
function active(e) {
|
|
1380
|
+
const r = coreRecipe({ kind: "none" }, e);
|
|
1381
|
+
return Object.entries(r).some(([k, v]) => k !== "background" && (typeof v === "number" ? v !== 0 : v === true));
|
|
1382
|
+
}
|
|
1383
|
+
async function playVideo(setup) {
|
|
1384
|
+
const v = document.createElement("video");
|
|
1385
|
+
v.muted = true;
|
|
1386
|
+
v.playsInline = true;
|
|
1387
|
+
setup(v);
|
|
1388
|
+
await v.play();
|
|
1389
|
+
return v;
|
|
1390
|
+
}
|
|
1391
|
+
function watchFrames(live) {
|
|
1392
|
+
const v = live.video;
|
|
1393
|
+
if (!v || !("requestVideoFrameCallback" in v)) return;
|
|
1394
|
+
live.rvfc = true;
|
|
1395
|
+
const on = () => {
|
|
1396
|
+
if (live.video !== v) return;
|
|
1397
|
+
live.fresh = true;
|
|
1398
|
+
v.requestVideoFrameCallback(on);
|
|
1399
|
+
};
|
|
1400
|
+
v.requestVideoFrameCallback(on);
|
|
1401
|
+
}
|
|
1402
|
+
function renderText(text, style = {}) {
|
|
1403
|
+
const font = style.font ?? "600 48px sans-serif";
|
|
1404
|
+
const pad = style.padding ?? 16;
|
|
1405
|
+
const c = document.createElement("canvas");
|
|
1406
|
+
const ctx = c.getContext("2d");
|
|
1407
|
+
ctx.font = font;
|
|
1408
|
+
const size = ctx.measureText("M").width * 1.2;
|
|
1409
|
+
const lineH = size * (style.lineHeight ?? 1.25);
|
|
1410
|
+
const lines = [];
|
|
1411
|
+
for (const para of text.split("\n")) {
|
|
1412
|
+
if (!style.maxWidth) {
|
|
1413
|
+
lines.push(para);
|
|
1414
|
+
continue;
|
|
1415
|
+
}
|
|
1416
|
+
let line = "";
|
|
1417
|
+
for (const word of para.split(/\s+/)) {
|
|
1418
|
+
const next = line ? `${line} ${word}` : word;
|
|
1419
|
+
if (line && ctx.measureText(next).width > style.maxWidth) {
|
|
1420
|
+
lines.push(line);
|
|
1421
|
+
line = word;
|
|
1422
|
+
} else line = next;
|
|
1423
|
+
}
|
|
1424
|
+
lines.push(line);
|
|
1425
|
+
}
|
|
1426
|
+
const outline = style.outline?.width ?? 0;
|
|
1427
|
+
const textW = Math.max(1, ...lines.map((l) => ctx.measureText(l).width));
|
|
1428
|
+
c.width = Math.ceil(textW + 2 * pad + 2 * outline);
|
|
1429
|
+
c.height = Math.ceil(lines.length * lineH + 2 * pad + 2 * outline);
|
|
1430
|
+
ctx.font = font;
|
|
1431
|
+
if (style.background !== void 0) {
|
|
1432
|
+
ctx.fillStyle = css(style.background);
|
|
1433
|
+
ctx.beginPath();
|
|
1434
|
+
ctx.roundRect(0, 0, c.width, c.height, style.radius ?? 0);
|
|
1435
|
+
ctx.fill();
|
|
1436
|
+
}
|
|
1437
|
+
const align = style.align ?? "left";
|
|
1438
|
+
ctx.textAlign = align;
|
|
1439
|
+
ctx.textBaseline = "middle";
|
|
1440
|
+
const x = align === "left" ? pad + outline : align === "right" ? c.width - pad - outline : c.width / 2;
|
|
1441
|
+
lines.forEach((line, i) => {
|
|
1442
|
+
const y = pad + outline + lineH * (i + 0.5);
|
|
1443
|
+
if (outline > 0) {
|
|
1444
|
+
ctx.lineWidth = outline * 2;
|
|
1445
|
+
ctx.lineJoin = "round";
|
|
1446
|
+
ctx.strokeStyle = css(style.outline.color);
|
|
1447
|
+
ctx.strokeText(line, x, y);
|
|
1448
|
+
}
|
|
1449
|
+
ctx.fillStyle = css(style.color ?? "#fff");
|
|
1450
|
+
ctx.fillText(line, x, y);
|
|
1451
|
+
});
|
|
1452
|
+
return c;
|
|
1453
|
+
}
|
|
1454
|
+
function css(c) {
|
|
1455
|
+
const [r, g, b, a] = parseColor(c);
|
|
1456
|
+
return `rgba(${Math.round(r * 255)},${Math.round(g * 255)},${Math.round(b * 255)},${a})`;
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
// src/facemesh.ts
|
|
1460
|
+
var FACE_UV = new Float32Array([
|
|
1461
|
+
0.49998,
|
|
1462
|
+
0.65253,
|
|
1463
|
+
0.50003,
|
|
1464
|
+
0.54749,
|
|
1465
|
+
0.49997,
|
|
1466
|
+
0.60237,
|
|
1467
|
+
0.48211,
|
|
1468
|
+
0.47198,
|
|
1469
|
+
0.50015,
|
|
1470
|
+
0.52716,
|
|
1471
|
+
0.49991,
|
|
1472
|
+
0.49825,
|
|
1473
|
+
0.49952,
|
|
1474
|
+
0.40106,
|
|
1475
|
+
0.28971,
|
|
1476
|
+
0.38076,
|
|
1477
|
+
0.49995,
|
|
1478
|
+
0.3124,
|
|
1479
|
+
0.49999,
|
|
1480
|
+
0.26992,
|
|
1481
|
+
0.50002,
|
|
1482
|
+
0.10705,
|
|
1483
|
+
0.50002,
|
|
1484
|
+
0.66623,
|
|
1485
|
+
0.50002,
|
|
1486
|
+
0.67922,
|
|
1487
|
+
0.50002,
|
|
1488
|
+
0.69235,
|
|
1489
|
+
0.49998,
|
|
1490
|
+
0.69528,
|
|
1491
|
+
0.49998,
|
|
1492
|
+
0.70593,
|
|
1493
|
+
0.49998,
|
|
1494
|
+
0.71938,
|
|
1495
|
+
0.49998,
|
|
1496
|
+
0.73702,
|
|
1497
|
+
0.49997,
|
|
1498
|
+
0.78137,
|
|
1499
|
+
0.49982,
|
|
1500
|
+
0.56298,
|
|
1501
|
+
0.47377,
|
|
1502
|
+
0.57391,
|
|
1503
|
+
0.10491,
|
|
1504
|
+
0.25414,
|
|
1505
|
+
0.36593,
|
|
1506
|
+
0.40958,
|
|
1507
|
+
0.33876,
|
|
1508
|
+
0.41302,
|
|
1509
|
+
0.31112,
|
|
1510
|
+
0.40946,
|
|
1511
|
+
0.27466,
|
|
1512
|
+
0.38913,
|
|
1513
|
+
0.39336,
|
|
1514
|
+
0.40371,
|
|
1515
|
+
0.34523,
|
|
1516
|
+
0.34401,
|
|
1517
|
+
0.37009,
|
|
1518
|
+
0.34608,
|
|
1519
|
+
0.31932,
|
|
1520
|
+
0.34727,
|
|
1521
|
+
0.2979,
|
|
1522
|
+
0.35359,
|
|
1523
|
+
0.24779,
|
|
1524
|
+
0.41081,
|
|
1525
|
+
0.39689,
|
|
1526
|
+
0.84276,
|
|
1527
|
+
0.2801,
|
|
1528
|
+
0.3756,
|
|
1529
|
+
0.10631,
|
|
1530
|
+
0.39996,
|
|
1531
|
+
0.20993,
|
|
1532
|
+
0.39135,
|
|
1533
|
+
0.35581,
|
|
1534
|
+
0.53441,
|
|
1535
|
+
0.47175,
|
|
1536
|
+
0.6504,
|
|
1537
|
+
0.47415,
|
|
1538
|
+
0.68019,
|
|
1539
|
+
0.43978,
|
|
1540
|
+
0.65723,
|
|
1541
|
+
0.41462,
|
|
1542
|
+
0.66654,
|
|
1543
|
+
0.45037,
|
|
1544
|
+
0.68086,
|
|
1545
|
+
0.42877,
|
|
1546
|
+
0.68269,
|
|
1547
|
+
0.37497,
|
|
1548
|
+
0.72781,
|
|
1549
|
+
0.48672,
|
|
1550
|
+
0.54763,
|
|
1551
|
+
0.4853,
|
|
1552
|
+
0.5274,
|
|
1553
|
+
0.25777,
|
|
1554
|
+
0.31449,
|
|
1555
|
+
0.40122,
|
|
1556
|
+
0.45517,
|
|
1557
|
+
0.42982,
|
|
1558
|
+
0.54862,
|
|
1559
|
+
0.42135,
|
|
1560
|
+
0.53374,
|
|
1561
|
+
0.2769,
|
|
1562
|
+
0.53206,
|
|
1563
|
+
0.48337,
|
|
1564
|
+
0.49959,
|
|
1565
|
+
0.33721,
|
|
1566
|
+
0.28288,
|
|
1567
|
+
0.29639,
|
|
1568
|
+
0.29324,
|
|
1569
|
+
0.1693,
|
|
1570
|
+
0.19381,
|
|
1571
|
+
0.44758,
|
|
1572
|
+
0.30261,
|
|
1573
|
+
0.39239,
|
|
1574
|
+
0.35389,
|
|
1575
|
+
0.35449,
|
|
1576
|
+
0.69678,
|
|
1577
|
+
0.06731,
|
|
1578
|
+
0.73011,
|
|
1579
|
+
0.44274,
|
|
1580
|
+
0.57283,
|
|
1581
|
+
0.4571,
|
|
1582
|
+
0.58479,
|
|
1583
|
+
0.38197,
|
|
1584
|
+
0.69471,
|
|
1585
|
+
0.39239,
|
|
1586
|
+
0.6942,
|
|
1587
|
+
0.27708,
|
|
1588
|
+
0.27193,
|
|
1589
|
+
0.42255,
|
|
1590
|
+
0.56323,
|
|
1591
|
+
0.38592,
|
|
1592
|
+
0.28136,
|
|
1593
|
+
0.3831,
|
|
1594
|
+
0.25584,
|
|
1595
|
+
0.33143,
|
|
1596
|
+
0.11971,
|
|
1597
|
+
0.22992,
|
|
1598
|
+
0.232,
|
|
1599
|
+
0.3645,
|
|
1600
|
+
0.18911,
|
|
1601
|
+
0.22962,
|
|
1602
|
+
0.29954,
|
|
1603
|
+
0.17329,
|
|
1604
|
+
0.27875,
|
|
1605
|
+
0.47288,
|
|
1606
|
+
0.6662,
|
|
1607
|
+
0.44683,
|
|
1608
|
+
0.66853,
|
|
1609
|
+
0.42276,
|
|
1610
|
+
0.67389,
|
|
1611
|
+
0.44531,
|
|
1612
|
+
0.58007,
|
|
1613
|
+
0.3881,
|
|
1614
|
+
0.69396,
|
|
1615
|
+
0.40304,
|
|
1616
|
+
0.70654,
|
|
1617
|
+
0.40363,
|
|
1618
|
+
0.69395,
|
|
1619
|
+
0.46004,
|
|
1620
|
+
0.55714,
|
|
1621
|
+
0.43116,
|
|
1622
|
+
0.69237,
|
|
1623
|
+
0.45218,
|
|
1624
|
+
0.69237,
|
|
1625
|
+
0.47539,
|
|
1626
|
+
0.69237,
|
|
1627
|
+
0.46583,
|
|
1628
|
+
0.77919,
|
|
1629
|
+
0.47233,
|
|
1630
|
+
0.73623,
|
|
1631
|
+
0.47309,
|
|
1632
|
+
0.71786,
|
|
1633
|
+
0.47312,
|
|
1634
|
+
0.70463,
|
|
1635
|
+
0.47303,
|
|
1636
|
+
0.69528,
|
|
1637
|
+
0.42794,
|
|
1638
|
+
0.69528,
|
|
1639
|
+
0.42648,
|
|
1640
|
+
0.70354,
|
|
1641
|
+
0.42316,
|
|
1642
|
+
0.71185,
|
|
1643
|
+
0.41831,
|
|
1644
|
+
0.72006,
|
|
1645
|
+
0.3901,
|
|
1646
|
+
0.63957,
|
|
1647
|
+
0.01395,
|
|
1648
|
+
0.56003,
|
|
1649
|
+
0.49991,
|
|
1650
|
+
0.58015,
|
|
1651
|
+
0.4132,
|
|
1652
|
+
0.6954,
|
|
1653
|
+
0.40963,
|
|
1654
|
+
0.70182,
|
|
1655
|
+
0.46808,
|
|
1656
|
+
0.60153,
|
|
1657
|
+
0.42273,
|
|
1658
|
+
0.58598,
|
|
1659
|
+
0.46308,
|
|
1660
|
+
0.59378,
|
|
1661
|
+
0.37212,
|
|
1662
|
+
0.47341,
|
|
1663
|
+
0.33456,
|
|
1664
|
+
0.49607,
|
|
1665
|
+
0.41167,
|
|
1666
|
+
0.54696,
|
|
1667
|
+
0.24218,
|
|
1668
|
+
0.14768,
|
|
1669
|
+
0.29078,
|
|
1670
|
+
0.20145,
|
|
1671
|
+
0.32734,
|
|
1672
|
+
0.25653,
|
|
1673
|
+
0.39951,
|
|
1674
|
+
0.74892,
|
|
1675
|
+
0.44173,
|
|
1676
|
+
0.26168,
|
|
1677
|
+
0.42977,
|
|
1678
|
+
0.18783,
|
|
1679
|
+
0.4122,
|
|
1680
|
+
0.1089,
|
|
1681
|
+
0.28896,
|
|
1682
|
+
0.39895,
|
|
1683
|
+
0.21894,
|
|
1684
|
+
0.43541,
|
|
1685
|
+
0.41278,
|
|
1686
|
+
0.39897,
|
|
1687
|
+
0.25714,
|
|
1688
|
+
0.35544,
|
|
1689
|
+
0.42768,
|
|
1690
|
+
0.43796,
|
|
1691
|
+
0.44834,
|
|
1692
|
+
0.53694,
|
|
1693
|
+
0.17856,
|
|
1694
|
+
0.45755,
|
|
1695
|
+
0.24731,
|
|
1696
|
+
0.45719,
|
|
1697
|
+
0.28627,
|
|
1698
|
+
0.46767,
|
|
1699
|
+
0.33283,
|
|
1700
|
+
0.46071,
|
|
1701
|
+
0.36876,
|
|
1702
|
+
0.44721,
|
|
1703
|
+
0.39896,
|
|
1704
|
+
0.43266,
|
|
1705
|
+
0.47641,
|
|
1706
|
+
0.40581,
|
|
1707
|
+
0.18924,
|
|
1708
|
+
0.52392,
|
|
1709
|
+
0.22896,
|
|
1710
|
+
0.34895,
|
|
1711
|
+
0.49073,
|
|
1712
|
+
0.5624,
|
|
1713
|
+
0.40467,
|
|
1714
|
+
0.48513,
|
|
1715
|
+
0.01947,
|
|
1716
|
+
0.40156,
|
|
1717
|
+
0.42624,
|
|
1718
|
+
0.42043,
|
|
1719
|
+
0.39699,
|
|
1720
|
+
0.5488,
|
|
1721
|
+
0.26647,
|
|
1722
|
+
0.37698,
|
|
1723
|
+
0.43912,
|
|
1724
|
+
0.51896,
|
|
1725
|
+
0.03231,
|
|
1726
|
+
0.64436,
|
|
1727
|
+
0.41905,
|
|
1728
|
+
0.38716,
|
|
1729
|
+
0.46278,
|
|
1730
|
+
0.50575,
|
|
1731
|
+
0.23898,
|
|
1732
|
+
0.77975,
|
|
1733
|
+
0.19822,
|
|
1734
|
+
0.83194,
|
|
1735
|
+
0.10755,
|
|
1736
|
+
0.54075,
|
|
1737
|
+
0.18361,
|
|
1738
|
+
0.74026,
|
|
1739
|
+
0.13441,
|
|
1740
|
+
0.33368,
|
|
1741
|
+
0.38576,
|
|
1742
|
+
0.88315,
|
|
1743
|
+
0.49097,
|
|
1744
|
+
0.57938,
|
|
1745
|
+
0.38238,
|
|
1746
|
+
0.50857,
|
|
1747
|
+
0.1744,
|
|
1748
|
+
0.39767,
|
|
1749
|
+
0.31878,
|
|
1750
|
+
0.39624,
|
|
1751
|
+
0.34336,
|
|
1752
|
+
0.4006,
|
|
1753
|
+
0.3961,
|
|
1754
|
+
0.71022,
|
|
1755
|
+
0.18788,
|
|
1756
|
+
0.58854,
|
|
1757
|
+
0.43099,
|
|
1758
|
+
0.94407,
|
|
1759
|
+
0.31899,
|
|
1760
|
+
0.89829,
|
|
1761
|
+
0.26625,
|
|
1762
|
+
0.8697,
|
|
1763
|
+
0.50002,
|
|
1764
|
+
0.19058,
|
|
1765
|
+
0.49998,
|
|
1766
|
+
0.95445,
|
|
1767
|
+
0.36617,
|
|
1768
|
+
0.39882,
|
|
1769
|
+
0.39321,
|
|
1770
|
+
0.39554,
|
|
1771
|
+
0.41037,
|
|
1772
|
+
0.39108,
|
|
1773
|
+
0.19499,
|
|
1774
|
+
0.3421,
|
|
1775
|
+
0.38866,
|
|
1776
|
+
0.36228,
|
|
1777
|
+
0.36596,
|
|
1778
|
+
0.35597,
|
|
1779
|
+
0.34336,
|
|
1780
|
+
0.35536,
|
|
1781
|
+
0.31878,
|
|
1782
|
+
0.35834,
|
|
1783
|
+
0.30141,
|
|
1784
|
+
0.36316,
|
|
1785
|
+
0.05813,
|
|
1786
|
+
0.31908,
|
|
1787
|
+
0.30141,
|
|
1788
|
+
0.38745,
|
|
1789
|
+
0.49999,
|
|
1790
|
+
0.61843,
|
|
1791
|
+
0.41584,
|
|
1792
|
+
0.6242,
|
|
1793
|
+
0.44568,
|
|
1794
|
+
0.56608,
|
|
1795
|
+
0.46584,
|
|
1796
|
+
0.62064,
|
|
1797
|
+
0.49992,
|
|
1798
|
+
0.35152,
|
|
1799
|
+
0.28872,
|
|
1800
|
+
0.81995,
|
|
1801
|
+
0.33528,
|
|
1802
|
+
0.85282,
|
|
1803
|
+
0.44051,
|
|
1804
|
+
0.90242,
|
|
1805
|
+
0.12829,
|
|
1806
|
+
0.79194,
|
|
1807
|
+
0.40877,
|
|
1808
|
+
0.37389,
|
|
1809
|
+
0.45561,
|
|
1810
|
+
0.4518,
|
|
1811
|
+
0.49988,
|
|
1812
|
+
0.90899,
|
|
1813
|
+
0.37544,
|
|
1814
|
+
0.92419,
|
|
1815
|
+
0.11421,
|
|
1816
|
+
0.61502,
|
|
1817
|
+
0.44866,
|
|
1818
|
+
0.69528,
|
|
1819
|
+
0.44802,
|
|
1820
|
+
0.70463,
|
|
1821
|
+
0.44711,
|
|
1822
|
+
0.71581,
|
|
1823
|
+
0.44483,
|
|
1824
|
+
0.73079,
|
|
1825
|
+
0.43001,
|
|
1826
|
+
0.76681,
|
|
1827
|
+
0.40679,
|
|
1828
|
+
0.68567,
|
|
1829
|
+
0.40074,
|
|
1830
|
+
0.68107,
|
|
1831
|
+
0.3924,
|
|
1832
|
+
0.6777,
|
|
1833
|
+
0.36786,
|
|
1834
|
+
0.66392,
|
|
1835
|
+
0.24792,
|
|
1836
|
+
0.60133,
|
|
1837
|
+
0.45277,
|
|
1838
|
+
0.42085,
|
|
1839
|
+
0.43639,
|
|
1840
|
+
0.35989,
|
|
1841
|
+
0.41616,
|
|
1842
|
+
0.36871,
|
|
1843
|
+
0.41339,
|
|
1844
|
+
0.69237,
|
|
1845
|
+
0.22802,
|
|
1846
|
+
0.68357,
|
|
1847
|
+
0.46827,
|
|
1848
|
+
0.35267,
|
|
1849
|
+
0.41136,
|
|
1850
|
+
0.80433,
|
|
1851
|
+
0.49999,
|
|
1852
|
+
0.46983,
|
|
1853
|
+
0.47915,
|
|
1854
|
+
0.44265,
|
|
1855
|
+
0.49997,
|
|
1856
|
+
0.43964,
|
|
1857
|
+
0.43211,
|
|
1858
|
+
0.49359,
|
|
1859
|
+
0.49989,
|
|
1860
|
+
0.86692,
|
|
1861
|
+
0.49991,
|
|
1862
|
+
0.82173,
|
|
1863
|
+
0.45655,
|
|
1864
|
+
0.8192,
|
|
1865
|
+
0.34455,
|
|
1866
|
+
0.74544,
|
|
1867
|
+
0.37891,
|
|
1868
|
+
0.57401,
|
|
1869
|
+
0.37429,
|
|
1870
|
+
0.78019,
|
|
1871
|
+
0.31969,
|
|
1872
|
+
0.57074,
|
|
1873
|
+
0.35716,
|
|
1874
|
+
0.60427,
|
|
1875
|
+
0.29528,
|
|
1876
|
+
0.62158,
|
|
1877
|
+
0.44775,
|
|
1878
|
+
0.86248,
|
|
1879
|
+
0.41099,
|
|
1880
|
+
0.50872,
|
|
1881
|
+
0.31395,
|
|
1882
|
+
0.77531,
|
|
1883
|
+
0.35413,
|
|
1884
|
+
0.81255,
|
|
1885
|
+
0.32455,
|
|
1886
|
+
0.70399,
|
|
1887
|
+
0.1891,
|
|
1888
|
+
0.6463,
|
|
1889
|
+
0.27978,
|
|
1890
|
+
0.71466,
|
|
1891
|
+
0.13382,
|
|
1892
|
+
0.6827,
|
|
1893
|
+
0.33677,
|
|
1894
|
+
0.64473,
|
|
1895
|
+
0.42988,
|
|
1896
|
+
0.46652,
|
|
1897
|
+
0.45553,
|
|
1898
|
+
0.54862,
|
|
1899
|
+
0.43711,
|
|
1900
|
+
0.5589,
|
|
1901
|
+
0.46729,
|
|
1902
|
+
0.52992,
|
|
1903
|
+
0.41471,
|
|
1904
|
+
0.33522,
|
|
1905
|
+
0.37705,
|
|
1906
|
+
0.32278,
|
|
1907
|
+
0.34411,
|
|
1908
|
+
0.32015,
|
|
1909
|
+
0.31288,
|
|
1910
|
+
0.32233,
|
|
1911
|
+
0.28353,
|
|
1912
|
+
0.33319,
|
|
1913
|
+
0.24125,
|
|
1914
|
+
0.38279,
|
|
1915
|
+
0.10299,
|
|
1916
|
+
0.46876,
|
|
1917
|
+
0.26761,
|
|
1918
|
+
0.42456,
|
|
1919
|
+
0.29788,
|
|
1920
|
+
0.43318,
|
|
1921
|
+
0.33343,
|
|
1922
|
+
0.43388,
|
|
1923
|
+
0.36643,
|
|
1924
|
+
0.42612,
|
|
1925
|
+
0.39601,
|
|
1926
|
+
0.4167,
|
|
1927
|
+
0.42012,
|
|
1928
|
+
0.41023,
|
|
1929
|
+
756e-5,
|
|
1930
|
+
0.48078,
|
|
1931
|
+
0.43295,
|
|
1932
|
+
0.56952,
|
|
1933
|
+
0.45864,
|
|
1934
|
+
0.47909,
|
|
1935
|
+
0.47347,
|
|
1936
|
+
0.54574,
|
|
1937
|
+
0.47609,
|
|
1938
|
+
0.56383,
|
|
1939
|
+
0.46847,
|
|
1940
|
+
0.55506,
|
|
1941
|
+
0.43399,
|
|
1942
|
+
0.58236,
|
|
1943
|
+
0.48352,
|
|
1944
|
+
0.56298,
|
|
1945
|
+
0.48248,
|
|
1946
|
+
0.57785,
|
|
1947
|
+
0.42645,
|
|
1948
|
+
0.3898,
|
|
1949
|
+
0.439,
|
|
1950
|
+
0.3965,
|
|
1951
|
+
0.45007,
|
|
1952
|
+
0.40043,
|
|
1953
|
+
0.28971,
|
|
1954
|
+
0.36825,
|
|
1955
|
+
0.27667,
|
|
1956
|
+
0.36337,
|
|
1957
|
+
0.51786,
|
|
1958
|
+
0.47195,
|
|
1959
|
+
0.71029,
|
|
1960
|
+
0.38076,
|
|
1961
|
+
0.52623,
|
|
1962
|
+
0.57391,
|
|
1963
|
+
0.89509,
|
|
1964
|
+
0.25414,
|
|
1965
|
+
0.63407,
|
|
1966
|
+
0.40958,
|
|
1967
|
+
0.66124,
|
|
1968
|
+
0.41302,
|
|
1969
|
+
0.68888,
|
|
1970
|
+
0.40946,
|
|
1971
|
+
0.72534,
|
|
1972
|
+
0.38913,
|
|
1973
|
+
0.60663,
|
|
1974
|
+
0.4037,
|
|
1975
|
+
0.65477,
|
|
1976
|
+
0.34401,
|
|
1977
|
+
0.62991,
|
|
1978
|
+
0.34608,
|
|
1979
|
+
0.68068,
|
|
1980
|
+
0.34727,
|
|
1981
|
+
0.7021,
|
|
1982
|
+
0.35359,
|
|
1983
|
+
0.75221,
|
|
1984
|
+
0.4108,
|
|
1985
|
+
0.60292,
|
|
1986
|
+
0.84286,
|
|
1987
|
+
0.7199,
|
|
1988
|
+
0.3756,
|
|
1989
|
+
0.89369,
|
|
1990
|
+
0.39996,
|
|
1991
|
+
0.79008,
|
|
1992
|
+
0.39135,
|
|
1993
|
+
0.644,
|
|
1994
|
+
0.53449,
|
|
1995
|
+
0.52825,
|
|
1996
|
+
0.6504,
|
|
1997
|
+
0.52585,
|
|
1998
|
+
0.68019,
|
|
1999
|
+
0.56022,
|
|
2000
|
+
0.65723,
|
|
2001
|
+
0.58538,
|
|
2002
|
+
0.66654,
|
|
2003
|
+
0.54963,
|
|
2004
|
+
0.68086,
|
|
2005
|
+
0.57123,
|
|
2006
|
+
0.68269,
|
|
2007
|
+
0.62485,
|
|
2008
|
+
0.7281,
|
|
2009
|
+
0.51305,
|
|
2010
|
+
0.54728,
|
|
2011
|
+
0.5151,
|
|
2012
|
+
0.52725,
|
|
2013
|
+
0.74225,
|
|
2014
|
+
0.31451,
|
|
2015
|
+
0.59863,
|
|
2016
|
+
0.45498,
|
|
2017
|
+
0.57034,
|
|
2018
|
+
0.54858,
|
|
2019
|
+
0.57863,
|
|
2020
|
+
0.53362,
|
|
2021
|
+
0.72309,
|
|
2022
|
+
0.53205,
|
|
2023
|
+
0.51645,
|
|
2024
|
+
0.49964,
|
|
2025
|
+
0.6628,
|
|
2026
|
+
0.28292,
|
|
2027
|
+
0.70362,
|
|
2028
|
+
0.29327,
|
|
2029
|
+
0.83071,
|
|
2030
|
+
0.19381,
|
|
2031
|
+
0.55239,
|
|
2032
|
+
0.30257,
|
|
2033
|
+
0.60761,
|
|
2034
|
+
0.35389,
|
|
2035
|
+
0.64543,
|
|
2036
|
+
0.69671,
|
|
2037
|
+
0.9327,
|
|
2038
|
+
0.73011,
|
|
2039
|
+
0.55726,
|
|
2040
|
+
0.57283,
|
|
2041
|
+
0.5429,
|
|
2042
|
+
0.58479,
|
|
2043
|
+
0.61803,
|
|
2044
|
+
0.69471,
|
|
2045
|
+
0.60759,
|
|
2046
|
+
0.6942,
|
|
2047
|
+
0.72294,
|
|
2048
|
+
0.27196,
|
|
2049
|
+
0.57741,
|
|
2050
|
+
0.56317,
|
|
2051
|
+
0.61408,
|
|
2052
|
+
0.28139,
|
|
2053
|
+
0.61691,
|
|
2054
|
+
0.25589,
|
|
2055
|
+
0.66851,
|
|
2056
|
+
0.11991,
|
|
2057
|
+
0.77009,
|
|
2058
|
+
0.23202,
|
|
2059
|
+
0.63554,
|
|
2060
|
+
0.18925,
|
|
2061
|
+
0.77039,
|
|
2062
|
+
0.29956,
|
|
2063
|
+
0.82672,
|
|
2064
|
+
0.27875,
|
|
2065
|
+
0.52712,
|
|
2066
|
+
0.6662,
|
|
2067
|
+
0.55317,
|
|
2068
|
+
0.66853,
|
|
2069
|
+
0.57724,
|
|
2070
|
+
0.67389,
|
|
2071
|
+
0.55469,
|
|
2072
|
+
0.58007,
|
|
2073
|
+
0.6119,
|
|
2074
|
+
0.69396,
|
|
2075
|
+
0.59696,
|
|
2076
|
+
0.70654,
|
|
2077
|
+
0.59637,
|
|
2078
|
+
0.69395,
|
|
2079
|
+
0.53996,
|
|
2080
|
+
0.55714,
|
|
2081
|
+
0.56884,
|
|
2082
|
+
0.69237,
|
|
2083
|
+
0.54782,
|
|
2084
|
+
0.69237,
|
|
2085
|
+
0.52461,
|
|
2086
|
+
0.69237,
|
|
2087
|
+
0.53409,
|
|
2088
|
+
0.77914,
|
|
2089
|
+
0.52767,
|
|
2090
|
+
0.73623,
|
|
2091
|
+
0.52691,
|
|
2092
|
+
0.71786,
|
|
2093
|
+
0.52688,
|
|
2094
|
+
0.70463,
|
|
2095
|
+
0.52697,
|
|
2096
|
+
0.69528,
|
|
2097
|
+
0.57206,
|
|
2098
|
+
0.69528,
|
|
2099
|
+
0.57352,
|
|
2100
|
+
0.70354,
|
|
2101
|
+
0.57684,
|
|
2102
|
+
0.71185,
|
|
2103
|
+
0.58169,
|
|
2104
|
+
0.72006,
|
|
2105
|
+
0.60994,
|
|
2106
|
+
0.63991,
|
|
2107
|
+
0.98605,
|
|
2108
|
+
0.56003,
|
|
2109
|
+
0.5868,
|
|
2110
|
+
0.6954,
|
|
2111
|
+
0.59037,
|
|
2112
|
+
0.70182,
|
|
2113
|
+
0.53192,
|
|
2114
|
+
0.60154,
|
|
2115
|
+
0.57727,
|
|
2116
|
+
0.58593,
|
|
2117
|
+
0.53692,
|
|
2118
|
+
0.59379,
|
|
2119
|
+
0.62754,
|
|
2120
|
+
0.47335,
|
|
2121
|
+
0.66559,
|
|
2122
|
+
0.49595,
|
|
2123
|
+
0.58835,
|
|
2124
|
+
0.54686,
|
|
2125
|
+
0.75782,
|
|
2126
|
+
0.14768,
|
|
2127
|
+
0.70925,
|
|
2128
|
+
0.20151,
|
|
2129
|
+
0.67268,
|
|
2130
|
+
0.25658,
|
|
2131
|
+
0.60041,
|
|
2132
|
+
0.749,
|
|
2133
|
+
0.55827,
|
|
2134
|
+
0.26167,
|
|
2135
|
+
0.5703,
|
|
2136
|
+
0.18787,
|
|
2137
|
+
0.58817,
|
|
2138
|
+
0.10904,
|
|
2139
|
+
0.71105,
|
|
2140
|
+
0.39895,
|
|
2141
|
+
0.78107,
|
|
2142
|
+
0.43541,
|
|
2143
|
+
0.58725,
|
|
2144
|
+
0.39893,
|
|
2145
|
+
0.74287,
|
|
2146
|
+
0.35545,
|
|
2147
|
+
0.57216,
|
|
2148
|
+
0.43765,
|
|
2149
|
+
0.55187,
|
|
2150
|
+
0.53657,
|
|
2151
|
+
0.82144,
|
|
2152
|
+
0.45756,
|
|
2153
|
+
0.7527,
|
|
2154
|
+
0.45718,
|
|
2155
|
+
0.71376,
|
|
2156
|
+
0.46763,
|
|
2157
|
+
0.66711,
|
|
2158
|
+
0.46067,
|
|
2159
|
+
0.6311,
|
|
2160
|
+
0.44715,
|
|
2161
|
+
0.60086,
|
|
2162
|
+
0.43247,
|
|
2163
|
+
0.52348,
|
|
2164
|
+
0.40563,
|
|
2165
|
+
0.81075,
|
|
2166
|
+
0.52393,
|
|
2167
|
+
0.77105,
|
|
2168
|
+
0.34896,
|
|
2169
|
+
0.50913,
|
|
2170
|
+
0.56272,
|
|
2171
|
+
0.59529,
|
|
2172
|
+
0.48502,
|
|
2173
|
+
0.98053,
|
|
2174
|
+
0.40156,
|
|
2175
|
+
0.5735,
|
|
2176
|
+
0.42,
|
|
2177
|
+
0.60299,
|
|
2178
|
+
0.54869,
|
|
2179
|
+
0.73353,
|
|
2180
|
+
0.37698,
|
|
2181
|
+
0.56061,
|
|
2182
|
+
0.51902,
|
|
2183
|
+
0.96769,
|
|
2184
|
+
0.64436,
|
|
2185
|
+
0.58098,
|
|
2186
|
+
0.38716,
|
|
2187
|
+
0.53773,
|
|
2188
|
+
0.50538,
|
|
2189
|
+
0.76097,
|
|
2190
|
+
0.77975,
|
|
2191
|
+
0.80178,
|
|
2192
|
+
0.83194,
|
|
2193
|
+
0.89244,
|
|
2194
|
+
0.54076,
|
|
2195
|
+
0.81635,
|
|
2196
|
+
0.74026,
|
|
2197
|
+
0.8656,
|
|
2198
|
+
0.33369,
|
|
2199
|
+
0.61407,
|
|
2200
|
+
0.88325,
|
|
2201
|
+
0.50895,
|
|
2202
|
+
0.57944,
|
|
2203
|
+
0.61794,
|
|
2204
|
+
0.50832,
|
|
2205
|
+
0.82561,
|
|
2206
|
+
0.39768,
|
|
2207
|
+
0.68122,
|
|
2208
|
+
0.39624,
|
|
2209
|
+
0.65664,
|
|
2210
|
+
0.4006,
|
|
2211
|
+
0.6039,
|
|
2212
|
+
0.71022,
|
|
2213
|
+
0.81209,
|
|
2214
|
+
0.58854,
|
|
2215
|
+
0.56801,
|
|
2216
|
+
0.94456,
|
|
2217
|
+
0.68101,
|
|
2218
|
+
0.89829,
|
|
2219
|
+
0.73375,
|
|
2220
|
+
0.8697,
|
|
2221
|
+
0.63383,
|
|
2222
|
+
0.39882,
|
|
2223
|
+
0.60679,
|
|
2224
|
+
0.39554,
|
|
2225
|
+
0.58966,
|
|
2226
|
+
0.39106,
|
|
2227
|
+
0.80502,
|
|
2228
|
+
0.34211,
|
|
2229
|
+
0.61133,
|
|
2230
|
+
0.36228,
|
|
2231
|
+
0.63404,
|
|
2232
|
+
0.35597,
|
|
2233
|
+
0.65664,
|
|
2234
|
+
0.35536,
|
|
2235
|
+
0.68122,
|
|
2236
|
+
0.35834,
|
|
2237
|
+
0.69859,
|
|
2238
|
+
0.36316,
|
|
2239
|
+
0.94187,
|
|
2240
|
+
0.31908,
|
|
2241
|
+
0.69859,
|
|
2242
|
+
0.38745,
|
|
2243
|
+
0.58418,
|
|
2244
|
+
0.62411,
|
|
2245
|
+
0.55432,
|
|
2246
|
+
0.56608,
|
|
2247
|
+
0.53415,
|
|
2248
|
+
0.62064,
|
|
2249
|
+
0.71122,
|
|
2250
|
+
0.81998,
|
|
2251
|
+
0.66463,
|
|
2252
|
+
0.85287,
|
|
2253
|
+
0.5591,
|
|
2254
|
+
0.90263,
|
|
2255
|
+
0.87171,
|
|
2256
|
+
0.79194,
|
|
2257
|
+
0.59123,
|
|
2258
|
+
0.37389,
|
|
2259
|
+
0.54434,
|
|
2260
|
+
0.45158,
|
|
2261
|
+
0.62456,
|
|
2262
|
+
0.92419,
|
|
2263
|
+
0.88577,
|
|
2264
|
+
0.61503,
|
|
2265
|
+
0.55134,
|
|
2266
|
+
0.69528,
|
|
2267
|
+
0.55198,
|
|
2268
|
+
0.70463,
|
|
2269
|
+
0.55289,
|
|
2270
|
+
0.71581,
|
|
2271
|
+
0.55517,
|
|
2272
|
+
0.73079,
|
|
2273
|
+
0.56994,
|
|
2274
|
+
0.76704,
|
|
2275
|
+
0.5932,
|
|
2276
|
+
0.68568,
|
|
2277
|
+
0.59926,
|
|
2278
|
+
0.68107,
|
|
2279
|
+
0.6076,
|
|
2280
|
+
0.6777,
|
|
2281
|
+
0.63194,
|
|
2282
|
+
0.6635,
|
|
2283
|
+
0.75203,
|
|
2284
|
+
0.60132,
|
|
2285
|
+
0.54723,
|
|
2286
|
+
0.42039,
|
|
2287
|
+
0.56354,
|
|
2288
|
+
0.35983,
|
|
2289
|
+
0.58384,
|
|
2290
|
+
0.36871,
|
|
2291
|
+
0.58661,
|
|
2292
|
+
0.69237,
|
|
2293
|
+
0.77192,
|
|
2294
|
+
0.68358,
|
|
2295
|
+
0.5316,
|
|
2296
|
+
0.35248,
|
|
2297
|
+
0.58837,
|
|
2298
|
+
0.80444,
|
|
2299
|
+
0.5208,
|
|
2300
|
+
0.44256,
|
|
2301
|
+
0.56798,
|
|
2302
|
+
0.49348,
|
|
2303
|
+
0.54328,
|
|
2304
|
+
0.81926,
|
|
2305
|
+
0.65532,
|
|
2306
|
+
0.74551,
|
|
2307
|
+
0.62101,
|
|
2308
|
+
0.57402,
|
|
2309
|
+
0.62556,
|
|
2310
|
+
0.78031,
|
|
2311
|
+
0.6802,
|
|
2312
|
+
0.57072,
|
|
2313
|
+
0.64276,
|
|
2314
|
+
0.60434,
|
|
2315
|
+
0.70466,
|
|
2316
|
+
0.62153,
|
|
2317
|
+
0.55201,
|
|
2318
|
+
0.86259,
|
|
2319
|
+
0.58907,
|
|
2320
|
+
0.50864,
|
|
2321
|
+
0.68595,
|
|
2322
|
+
0.77536,
|
|
2323
|
+
0.64573,
|
|
2324
|
+
0.81264,
|
|
2325
|
+
0.67534,
|
|
2326
|
+
0.70398,
|
|
2327
|
+
0.81086,
|
|
2328
|
+
0.64631,
|
|
2329
|
+
0.72012,
|
|
2330
|
+
0.71467,
|
|
2331
|
+
0.86615,
|
|
2332
|
+
0.68271,
|
|
2333
|
+
0.66319,
|
|
2334
|
+
0.6446,
|
|
2335
|
+
0.57008,
|
|
2336
|
+
0.46633,
|
|
2337
|
+
0.54456,
|
|
2338
|
+
0.54838,
|
|
2339
|
+
0.56276,
|
|
2340
|
+
0.55878,
|
|
2341
|
+
0.53199,
|
|
2342
|
+
0.53014,
|
|
2343
|
+
0.58527,
|
|
2344
|
+
0.33518,
|
|
2345
|
+
0.62295,
|
|
2346
|
+
0.32278,
|
|
2347
|
+
0.6559,
|
|
2348
|
+
0.32016,
|
|
2349
|
+
0.68713,
|
|
2350
|
+
0.32235,
|
|
2351
|
+
0.71648,
|
|
2352
|
+
0.3332,
|
|
2353
|
+
0.75876,
|
|
2354
|
+
0.38279,
|
|
2355
|
+
0.89701,
|
|
2356
|
+
0.46877,
|
|
2357
|
+
0.73239,
|
|
2358
|
+
0.42455,
|
|
2359
|
+
0.70211,
|
|
2360
|
+
0.43316,
|
|
2361
|
+
0.66653,
|
|
2362
|
+
0.43387,
|
|
2363
|
+
0.6335,
|
|
2364
|
+
0.42609,
|
|
2365
|
+
0.60388,
|
|
2366
|
+
0.41659,
|
|
2367
|
+
0.57966,
|
|
2368
|
+
0.40995,
|
|
2369
|
+
0.99244,
|
|
2370
|
+
0.48078,
|
|
2371
|
+
0.56719,
|
|
2372
|
+
0.56942,
|
|
2373
|
+
0.54137,
|
|
2374
|
+
0.4789,
|
|
2375
|
+
0.52656,
|
|
2376
|
+
0.54612,
|
|
2377
|
+
0.52391,
|
|
2378
|
+
0.56383,
|
|
2379
|
+
0.53153,
|
|
2380
|
+
0.55506,
|
|
2381
|
+
0.56604,
|
|
2382
|
+
0.58233,
|
|
2383
|
+
0.51631,
|
|
2384
|
+
0.56305,
|
|
2385
|
+
0.51747,
|
|
2386
|
+
0.57788,
|
|
2387
|
+
0.57359,
|
|
2388
|
+
0.38981,
|
|
2389
|
+
0.5607,
|
|
2390
|
+
0.39533,
|
|
2391
|
+
0.54976,
|
|
2392
|
+
0.39975,
|
|
2393
|
+
0.71029,
|
|
2394
|
+
0.36825,
|
|
2395
|
+
0.72333,
|
|
2396
|
+
0.36337
|
|
2397
|
+
]);
|
|
776
2398
|
export {
|
|
2399
|
+
BLEND_MODES,
|
|
777
2400
|
Engine,
|
|
2401
|
+
FACE_UV,
|
|
778
2402
|
NO_EFFECTS,
|
|
2403
|
+
Scene,
|
|
779
2404
|
TOUCH_UP,
|
|
2405
|
+
TRANSITIONS,
|
|
780
2406
|
VideoPipeline,
|
|
2407
|
+
hitTest,
|
|
2408
|
+
layouts,
|
|
781
2409
|
mediakitSupported,
|
|
782
2410
|
needsFace,
|
|
783
2411
|
needsMask,
|
|
2412
|
+
needsSegmentation,
|
|
2413
|
+
parseColor,
|
|
2414
|
+
renderText,
|
|
784
2415
|
touchUp,
|
|
785
2416
|
touchUpAmount
|
|
786
2417
|
};
|