@tradalab/mediakit 2.7.0 → 2.9.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/README.md +86 -2
- package/dist/assets-node.d.ts +27 -0
- package/dist/assets-node.js +9 -0
- package/dist/assets-node.js.map +1 -0
- package/dist/assets.d.ts +32 -0
- package/dist/assets.js +17 -0
- package/dist/assets.js.map +1 -0
- package/dist/chunk-KIULIJZL.js +223 -0
- package/dist/chunk-KIULIJZL.js.map +1 -0
- package/dist/chunk-T7YS2EQE.js +52 -0
- package/dist/chunk-T7YS2EQE.js.map +1 -0
- package/dist/detect-worker.js +51 -8
- package/dist/detect-worker.js.map +1 -1
- package/dist/index.d.ts +30 -3
- package/dist/index.js +137 -25
- package/dist/index.js.map +1 -1
- package/dist/mediakit-assets.js +58 -0
- package/dist/mediakit-assets.js.map +1 -0
- package/dist/mediakit.wasm +0 -0
- package/dist/worker.js +67 -10
- package/dist/worker.js.map +1 -1
- package/package.json +14 -2
package/README.md
CHANGED
|
@@ -6,6 +6,61 @@ face retouching.
|
|
|
6
6
|
|
|
7
7
|
The examples named below live in the repository under `web/example/`; `make example` serves them.
|
|
8
8
|
|
|
9
|
+
### Upgrading to 2.9.0
|
|
10
|
+
|
|
11
|
+
No change for an app that does not read the new fields; serve the new `worker.js`,
|
|
12
|
+
`detect-worker.js` and `mediakit.wasm`.
|
|
13
|
+
|
|
14
|
+
**New: what each detector is doing, in `health.parts` and `FrameStats.parts`.** One state per
|
|
15
|
+
part - `person`, `classes`, `face` and `cover` (the face cover behind `occluders`) - each `"off"`
|
|
16
|
+
(the recipe does not need it), `"loading"`, `"ready"` or `"failed"`, and `partErrors` with the
|
|
17
|
+
reason for each failed part ("" for the others). An app can show "filter ready" before going live,
|
|
18
|
+
or "getting the filter ready" while a part loads, without guessing from which effects show. On a
|
|
19
|
+
fake camera with lipstick, smoothing and `occluders`: all four `"off"` before the first frame,
|
|
20
|
+
`person`, `face` and `cover` `"loading"` at 0.5 s and `"ready"` at 1 s. `cover` follows `face`:
|
|
21
|
+
`"loading"` while landmarks load, `"failed"` when they fail, with their reason.
|
|
22
|
+
|
|
23
|
+
**Fix: a detector that failed was told to nobody unless it timed out.** Only a load over 60 s
|
|
24
|
+
reached `effectError`; a 404 on a model, a wasm error, or a face cover that did not load turned
|
|
25
|
+
the effects off with nothing but a console line - for the cover, makeup on hands for the whole
|
|
26
|
+
session. Now the part turns `"failed"`, `partErrors` says why (`mediakit: face detection did not
|
|
27
|
+
load: Failed to fetch model: /mediakit/face_landmarker.task (404); face effects stay off`,
|
|
28
|
+
`mediakit: the face cover model did not load: ...; occluders stays off`) and `onIssue` fires the
|
|
29
|
+
new code `part-off` once per reason, unless `effect-off` already said the same. Without the detect
|
|
30
|
+
worker the cover is `"failed"` too: it runs only there. The cover model now also gives up after
|
|
31
|
+
60 s, as the MediaPipe models do. With `syncFaces`, `cover` is the state of the first face worker;
|
|
32
|
+
the second one's cover does not change it.
|
|
33
|
+
|
|
34
|
+
**New: `preloadDetectors(parts, onProgress)`** reports the download as it goes:
|
|
35
|
+
`{ loaded, total, done, files }` - bytes so far, the sum of the files' sizes, and files finished out
|
|
36
|
+
of files asked for. `total` is 0 until every file's headers are in, and stays 0 when one of them
|
|
37
|
+
gives no usable size (no `Content-Length`, or a compressed response, whose `Content-Length` is
|
|
38
|
+
not the size the browser hands over); show `done`/`files` then. `loaded` never passes a known
|
|
39
|
+
`total`. It is called at the start, at most every 100 ms while bytes arrive, and once per finished
|
|
40
|
+
file, the last call with `done === files`. A file that fails, or answers with an error status,
|
|
41
|
+
counts as done and adds no bytes. A callback that throws is not called again. The MediaPipe
|
|
42
|
+
runtime and onnxruntime load in workers that report nothing, so this is the only progress there
|
|
43
|
+
is: an app that wants a progress line calls `preloadDetectors` when the camera screen opens and
|
|
44
|
+
shows it, and the detectors then load from the HTTP cache.
|
|
45
|
+
|
|
46
|
+
### Upgrading to 2.8.0
|
|
47
|
+
|
|
48
|
+
No change at runtime for a recipe that already works: serve the new `worker.js`,
|
|
49
|
+
`detect-worker.js` and `mediakit.wasm`, as with every release.
|
|
50
|
+
|
|
51
|
+
**New: `mediakit-assets` copies what has to be served.** Every app kept its own script with the
|
|
52
|
+
list of files under `/mediakit/`, so each release that added one (2.7.0 added `face_cover.onnx`
|
|
53
|
+
and onnxruntime-web's wasm) had to be followed in every app by hand, and a file left out showed
|
|
54
|
+
only as an effect that did nothing. The list now ships with the package and the command copies it,
|
|
55
|
+
with the version rules for the MediaPipe and onnxruntime wasm; see "Serve the assets first".
|
|
56
|
+
Replace the app's script with `mediakit-assets <public dir>/mediakit --parts=... --models=skip` in
|
|
57
|
+
`predev` and `prebuild` (`--models=fetch` once, where the network is there), and `--check` where a
|
|
58
|
+
build has to fail on a missing file.
|
|
59
|
+
|
|
60
|
+
**New: `preloadDetectors({ cover: true })`** also fetches `face_cover.onnx` and the onnxruntime
|
|
61
|
+
wasm (15 MB) at low priority, whether or not the MediaPipe runtime loads. Without it the first recipe with `occluders` on a machine draws
|
|
62
|
+
makeup over a hand for the seconds that download takes.
|
|
63
|
+
|
|
9
64
|
### Upgrading to 2.7.0
|
|
10
65
|
|
|
11
66
|
Upgrade the package and serve its `mediakit.wasm`; the one new recipe field, `occluders`, is off by
|
|
@@ -230,7 +285,7 @@ with the new JS.
|
|
|
230
285
|
detector is not retried in the frame thread, which would wait on the same network: its effects
|
|
231
286
|
stay off, `effectError` says `... did not load within 60 s; face effects stay off`, and
|
|
232
287
|
`onIssue` fires `effect-off`. A failed load is no longer retried on every frame.
|
|
233
|
-
- **`preloadDetectors({ person, classes, face })`** fetches the MediaPipe runtime and those models
|
|
288
|
+
- **`preloadDetectors({ person, classes, face })`** (and `cover` since 2.8.0) fetches the MediaPipe runtime and those models
|
|
234
289
|
at low priority, to warm the HTTP cache before the first recipe that needs them (call it when the
|
|
235
290
|
camera screen opens). It never rejects. It only helps when `/mediakit/` is served cacheable.
|
|
236
291
|
- **GPU guard: a lost context is not repeated.** Chromium blocks WebGL for the whole site after a
|
|
@@ -287,6 +342,7 @@ Taken from what Tencent Beauty AR Web, BytePlus's web beauty extension and GPUPi
|
|
|
287
342
|
| `stall` | no frame out for 2 s with the camera live (also `onStall`) | fall back to the raw camera after a grace period |
|
|
288
343
|
| `slow` | frames or face detection over 150 ms for 3 s (Tencent's 50005) | suggest a lower resolution or fewer effects |
|
|
289
344
|
| `effect-off` | some effects are off, the rest runs (`health.effectError`) | say which ones and why |
|
|
345
|
+
| `part-off` | a detector failed and `effect-off` has not said so, once per reason (`health.parts`, `health.partErrors`) | say what is off; for `cover`, that makeup may land on a hand |
|
|
290
346
|
| `worker-moved` | the worker failed, the pipeline moved to the main thread | install the track from `onTrackReplaced` |
|
|
291
347
|
| `gpu-lost` | the WebGL context was lost | nothing: the pipeline rebuilds itself (up to twice; once without makeup after a makeup link loss, never after a loss building the shaders) and fires `onTrackReplaced` |
|
|
292
348
|
|
|
@@ -309,6 +365,7 @@ Taken from what Tencent Beauty AR Web, BytePlus's web beauty extension and GPUPi
|
|
|
309
365
|
| Software renderer (SwiftShader, llvmpipe) | runs, slowly; `checkSupport().softwareRenderer` | warn |
|
|
310
366
|
| Makeup shader slow or failing to link, or losing the context linking | makeup off, rest runs, `effect-off`; remembered per GPU after a loss | show that makeup is off, keep the camera on |
|
|
311
367
|
| A detector does not load within 60 s | its effects off, rest runs, `effect-off` | say the network is slow; `preloadDetectors()` earlier helps the next time |
|
|
368
|
+
| The face cover model or its runtime does not load, or face detection runs without the detect worker | `occluders` off, rest runs, `part-off`, `health.parts.cover` `"failed"` | say that makeup may land on a hand or a cup; offer to turn makeup off |
|
|
312
369
|
| Overloaded machine | `slow`, then `stall` | lower the load, then fall back to the raw camera |
|
|
313
370
|
| GPU context lost while running | rebuilds, `gpu-lost`, `onTrackReplaced` | install the new track |
|
|
314
371
|
| `start()` throws `GpuLostError` | lost the context building the shaders; remembered | use the raw camera; do not retry, mediakit would refuse anyway |
|
|
@@ -436,10 +493,37 @@ ever fetched from a third party while a frame is being processed.
|
|
|
436
493
|
| `/mediakit/selfie_multiclass_256x256.tflite` | MediaPipe model, 16 MB | `needsSkinClasses()` is true; without it those recipes fall back to skin measured on the face |
|
|
437
494
|
| `/mediakit/face_cover.onnx` | this package's `dist/`, 0.6 MB | `occluders` with a face effect; without it makeup is drawn over a hand or a cup |
|
|
438
495
|
| `/mediakit/ort/ort-wasm-simd-threaded.wasm` and `.mjs` | `onnxruntime-web/dist/` of exactly 1.31.1 (an optional peer dependency: the worker bundles its JS, so another release's wasm does not fit), 15 MB | the same recipes: the runtime of `face_cover.onnx` |
|
|
496
|
+
| `/mediakit/NOTICE` | this package's `dist/` | not fetched; the licence of the tables in `whiten_pink.png`, served beside it |
|
|
439
497
|
|
|
440
498
|
`worker.js` is **fetched**, not imported, so no bundler will pick it up for you. The models are
|
|
441
499
|
not shipped in the package; fetch them once and serve them yourself.
|
|
442
500
|
|
|
501
|
+
The package does all of this with one command, run before the app's dev server and build:
|
|
502
|
+
|
|
503
|
+
```sh
|
|
504
|
+
mediakit-assets public/mediakit --parts=person,classes,face,cover --models=skip
|
|
505
|
+
```
|
|
506
|
+
|
|
507
|
+
- `--parts`: which detectors besides the core (`mediakit.wasm`, `wasm_exec.js`, both workers,
|
|
508
|
+
`whiten_pink.png`, `NOTICE`, `mp/`). `person`, `classes` and `face` are the three MediaPipe
|
|
509
|
+
models, `cover` is `face_cover.onnx` with onnxruntime-web for `occluders`. Default
|
|
510
|
+
`person,classes,face`: the cover model's licence is not cleared, so it is copied only when asked for.
|
|
511
|
+
- `--models`: `fetch` (the default) downloads a missing MediaPipe model from Google (a model
|
|
512
|
+
already there is kept), `skip` leaves them out, `<dir>` copies them from a local folder. A build
|
|
513
|
+
that must not depend on the network runs `skip`, with the models fetched once beforehand.
|
|
514
|
+
- `--check` writes nothing and exits 1 when a file is missing or is not the one of the installed
|
|
515
|
+
release (a `mediakit.wasm` left from another version is exactly that), naming each one. With
|
|
516
|
+
`--models=skip` it does not ask for the models either.
|
|
517
|
+
|
|
518
|
+
It copies the MediaPipe and onnxruntime files from the releases this package resolves; when one is
|
|
519
|
+
not of the release its peer dependencies ask for, that file is reported missing with the version
|
|
520
|
+
found, the rest is still copied, and the exit code is 1. Every file is written under a `.part` name
|
|
521
|
+
and renamed, so an interrupted run leaves no half file behind. Exit code 1 means a file could not
|
|
522
|
+
be written or is missing, 2 a wrong argument. From a script, `syncAssets()` in
|
|
523
|
+
`@tradalab/mediakit/assets/node` does the same and returns what it wrote, kept, skipped and missed;
|
|
524
|
+
`@tradalab/mediakit/assets` is the list itself (`ASSETS`, `assetsFor(parts)`), safe to import in
|
|
525
|
+
the browser.
|
|
526
|
+
|
|
443
527
|
## Run it
|
|
444
528
|
|
|
445
529
|
```ts
|
|
@@ -656,7 +740,7 @@ const pipeline = new VideoPipeline(filter, effects, {
|
|
|
656
740
|
onTrackReplaced: (track) => sender.replaceTrack(track),
|
|
657
741
|
})
|
|
658
742
|
const stop = pipeline.subscribeFrames((frame) => { draw(frame); frame.close() })
|
|
659
|
-
pipeline.health // { transport, frames, sinceMs, stalled }
|
|
743
|
+
pipeline.health // { transport, frames, sinceMs, stalled, effectError, parts, partErrors }
|
|
660
744
|
```
|
|
661
745
|
|
|
662
746
|
- No frame for two seconds fires `onStall` (a machine too slow for the recipe, or a hang). A worker
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
type AssetPart = "core" | "person" | "classes" | "face" | "cover";
|
|
2
|
+
|
|
3
|
+
type ModelMode = "fetch" | "skip" | {
|
|
4
|
+
dir: string;
|
|
5
|
+
};
|
|
6
|
+
interface SyncOptions {
|
|
7
|
+
out: string;
|
|
8
|
+
parts?: readonly AssetPart[];
|
|
9
|
+
models?: ModelMode;
|
|
10
|
+
check?: boolean;
|
|
11
|
+
log?: (line: string) => void;
|
|
12
|
+
}
|
|
13
|
+
interface Missing {
|
|
14
|
+
path: string;
|
|
15
|
+
why: string;
|
|
16
|
+
}
|
|
17
|
+
interface SyncResult {
|
|
18
|
+
version: string;
|
|
19
|
+
written: string[];
|
|
20
|
+
current: string[];
|
|
21
|
+
skipped: string[];
|
|
22
|
+
missing: Missing[];
|
|
23
|
+
}
|
|
24
|
+
declare function satisfies(version: string, range: string): boolean;
|
|
25
|
+
declare function syncAssets(opts: SyncOptions): Promise<SyncResult>;
|
|
26
|
+
|
|
27
|
+
export { type Missing, type ModelMode, type SyncOptions, type SyncResult, satisfies, syncAssets };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/assets.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
declare const ASSET_BASE = "/mediakit/";
|
|
2
|
+
type AssetPart = "core" | "person" | "classes" | "face" | "cover";
|
|
3
|
+
type PeerPackage = "@mediapipe/tasks-vision" | "onnxruntime-web";
|
|
4
|
+
type AssetSource = {
|
|
5
|
+
from: "dist";
|
|
6
|
+
file: string;
|
|
7
|
+
} | {
|
|
8
|
+
from: "peer";
|
|
9
|
+
name: PeerPackage;
|
|
10
|
+
file: string;
|
|
11
|
+
} | {
|
|
12
|
+
from: "peer-dir";
|
|
13
|
+
name: PeerPackage;
|
|
14
|
+
dir: string;
|
|
15
|
+
skip: string;
|
|
16
|
+
} | {
|
|
17
|
+
from: "model";
|
|
18
|
+
url: string;
|
|
19
|
+
};
|
|
20
|
+
interface Asset {
|
|
21
|
+
path: string;
|
|
22
|
+
part: AssetPart;
|
|
23
|
+
source: AssetSource;
|
|
24
|
+
debug?: boolean;
|
|
25
|
+
}
|
|
26
|
+
declare const OPTIONAL_PARTS: readonly ["person", "classes", "face", "cover"];
|
|
27
|
+
declare const DEFAULT_PARTS: readonly AssetPart[];
|
|
28
|
+
declare const ASSETS: readonly Asset[];
|
|
29
|
+
declare function assetUrl(path: string): string;
|
|
30
|
+
declare function assetsFor(parts: readonly AssetPart[]): Asset[];
|
|
31
|
+
|
|
32
|
+
export { ASSETS, ASSET_BASE, type Asset, type AssetPart, type AssetSource, DEFAULT_PARTS, OPTIONAL_PARTS, type PeerPackage, assetUrl, assetsFor };
|
package/dist/assets.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ASSETS,
|
|
3
|
+
ASSET_BASE,
|
|
4
|
+
DEFAULT_PARTS,
|
|
5
|
+
OPTIONAL_PARTS,
|
|
6
|
+
assetUrl,
|
|
7
|
+
assetsFor
|
|
8
|
+
} from "./chunk-T7YS2EQE.js";
|
|
9
|
+
export {
|
|
10
|
+
ASSETS,
|
|
11
|
+
ASSET_BASE,
|
|
12
|
+
DEFAULT_PARTS,
|
|
13
|
+
OPTIONAL_PARTS,
|
|
14
|
+
assetUrl,
|
|
15
|
+
assetsFor
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=assets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
// src/node/assets.ts
|
|
2
|
+
import { createWriteStream } from "fs";
|
|
3
|
+
import { copyFile, mkdir, readFile, readdir, rename, rm, stat } from "fs/promises";
|
|
4
|
+
import { createRequire } from "module";
|
|
5
|
+
import { dirname, join, resolve } from "path";
|
|
6
|
+
import { Readable } from "stream";
|
|
7
|
+
import { pipeline } from "stream/promises";
|
|
8
|
+
import { fileURLToPath } from "url";
|
|
9
|
+
|
|
10
|
+
// src/assets.ts
|
|
11
|
+
var OPTIONAL_PARTS = ["person", "classes", "face", "cover"];
|
|
12
|
+
var DEFAULT_PARTS = ["person", "classes", "face"];
|
|
13
|
+
var ASSETS = [
|
|
14
|
+
{ path: "mediakit.wasm", part: "core", source: { from: "dist", file: "mediakit.wasm" } },
|
|
15
|
+
{ path: "wasm_exec.js", part: "core", source: { from: "dist", file: "wasm_exec.js" } },
|
|
16
|
+
{ path: "worker.js", part: "core", source: { from: "dist", file: "worker.js" } },
|
|
17
|
+
{ path: "worker.js.map", part: "core", source: { from: "dist", file: "worker.js.map" }, debug: true },
|
|
18
|
+
{ path: "detect-worker.js", part: "core", source: { from: "dist", file: "detect-worker.js" } },
|
|
19
|
+
{ path: "detect-worker.js.map", part: "core", source: { from: "dist", file: "detect-worker.js.map" }, debug: true },
|
|
20
|
+
{ path: "whiten_pink.png", part: "core", source: { from: "dist", file: "whiten_pink.png" } },
|
|
21
|
+
{ path: "NOTICE", part: "core", source: { from: "dist", file: "NOTICE" } },
|
|
22
|
+
{ path: "mp/", part: "core", source: { from: "peer-dir", name: "@mediapipe/tasks-vision", dir: "wasm", skip: "_module_" } },
|
|
23
|
+
{
|
|
24
|
+
path: "selfie_segmenter.tflite",
|
|
25
|
+
part: "person",
|
|
26
|
+
source: { from: "model", url: "https://storage.googleapis.com/mediapipe-models/image_segmenter/selfie_segmenter/float16/latest/selfie_segmenter.tflite" }
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
path: "selfie_multiclass_256x256.tflite",
|
|
30
|
+
part: "classes",
|
|
31
|
+
source: {
|
|
32
|
+
from: "model",
|
|
33
|
+
url: "https://storage.googleapis.com/mediapipe-models/image_segmenter/selfie_multiclass_256x256/float32/latest/selfie_multiclass_256x256.tflite"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
path: "face_landmarker.task",
|
|
38
|
+
part: "face",
|
|
39
|
+
source: { from: "model", url: "https://storage.googleapis.com/mediapipe-models/face_landmarker/face_landmarker/float16/latest/face_landmarker.task" }
|
|
40
|
+
},
|
|
41
|
+
{ path: "face_cover.onnx", part: "cover", source: { from: "dist", file: "face_cover.onnx" } },
|
|
42
|
+
{ path: "ort/ort-wasm-simd-threaded.wasm", part: "cover", source: { from: "peer", name: "onnxruntime-web", file: "dist/ort-wasm-simd-threaded.wasm" } },
|
|
43
|
+
{ path: "ort/ort-wasm-simd-threaded.mjs", part: "cover", source: { from: "peer", name: "onnxruntime-web", file: "dist/ort-wasm-simd-threaded.mjs" } }
|
|
44
|
+
];
|
|
45
|
+
function assetsFor(parts) {
|
|
46
|
+
return ASSETS.filter((a) => a.part === "core" || parts.includes(a.part));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// src/node/assets.ts
|
|
50
|
+
var PACKAGE_DIR = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
51
|
+
var DIST_DIR = join(PACKAGE_DIR, "dist");
|
|
52
|
+
var AssetError = class extends Error {
|
|
53
|
+
};
|
|
54
|
+
async function exists(p) {
|
|
55
|
+
try {
|
|
56
|
+
await stat(p);
|
|
57
|
+
return true;
|
|
58
|
+
} catch {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async function sameBytes(a, b) {
|
|
63
|
+
try {
|
|
64
|
+
const [sa, sb] = await Promise.all([stat(a), stat(b)]);
|
|
65
|
+
if (sa.size !== sb.size) return false;
|
|
66
|
+
const [ba, bb] = await Promise.all([readFile(a), readFile(b)]);
|
|
67
|
+
return ba.equals(bb);
|
|
68
|
+
} catch {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async function readJson(p) {
|
|
73
|
+
return JSON.parse(await readFile(p, "utf8"));
|
|
74
|
+
}
|
|
75
|
+
function satisfies(version, range) {
|
|
76
|
+
return range.split("||").some((r) => satisfiesOne(version, r));
|
|
77
|
+
}
|
|
78
|
+
function satisfiesOne(version, range) {
|
|
79
|
+
const want = /^([~^]?)(\d+)\.(\d+)\.(\d+)$/.exec(range.trim());
|
|
80
|
+
const have = /^(\d+)\.(\d+)\.(\d+)/.exec(version);
|
|
81
|
+
if (!want || !have) return false;
|
|
82
|
+
const [, op, ...w] = want;
|
|
83
|
+
const [wMajor, wMinor, wPatch] = w.map(Number);
|
|
84
|
+
const [hMajor, hMinor, hPatch] = have.slice(1).map(Number);
|
|
85
|
+
if (op === "") return hMajor === wMajor && hMinor === wMinor && hPatch === wPatch;
|
|
86
|
+
if (hMajor !== wMajor) return false;
|
|
87
|
+
if (op === "~" || wMajor === 0) return hMinor === wMinor && hPatch >= wPatch;
|
|
88
|
+
return hMinor > wMinor || hMinor === wMinor && hPatch >= wPatch;
|
|
89
|
+
}
|
|
90
|
+
async function peerRoot(name) {
|
|
91
|
+
const pkg = await readJson(join(PACKAGE_DIR, "package.json"));
|
|
92
|
+
const range = pkg.peerDependencies?.[name];
|
|
93
|
+
if (!range) throw new AssetError(`${name} is not a peer dependency of this mediakit`);
|
|
94
|
+
let dir;
|
|
95
|
+
try {
|
|
96
|
+
dir = dirname(createRequire(join(PACKAGE_DIR, "package.json")).resolve(name));
|
|
97
|
+
} catch {
|
|
98
|
+
throw new AssetError(`${name} is not installed: add ${name}@${range} to the app`);
|
|
99
|
+
}
|
|
100
|
+
for (; ; ) {
|
|
101
|
+
const file = join(dir, "package.json");
|
|
102
|
+
if (await exists(file)) {
|
|
103
|
+
const peer = await readJson(file);
|
|
104
|
+
if (peer.name === name) {
|
|
105
|
+
if (!peer.version || !satisfies(peer.version, range)) {
|
|
106
|
+
throw new AssetError(`${name} ${peer.version} is installed, this mediakit needs ${range}`);
|
|
107
|
+
}
|
|
108
|
+
return dir;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const up = dirname(dir);
|
|
112
|
+
if (up === dir) throw new AssetError(`${name} has no package.json above ${dir}`);
|
|
113
|
+
dir = up;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async function planOf(asset, out) {
|
|
117
|
+
const s = asset.source;
|
|
118
|
+
if (s.from === "dist") {
|
|
119
|
+
const from = join(DIST_DIR, s.file);
|
|
120
|
+
if (!await exists(from)) {
|
|
121
|
+
if (asset.debug) return null;
|
|
122
|
+
throw new AssetError(`${s.file} is missing from ${DIST_DIR}`);
|
|
123
|
+
}
|
|
124
|
+
return { files: [{ from, to: join(out, asset.path) }] };
|
|
125
|
+
}
|
|
126
|
+
if (s.from === "peer") {
|
|
127
|
+
const from = join(await peerRoot(s.name), s.file);
|
|
128
|
+
if (!await exists(from)) throw new AssetError(`${s.file} is missing from ${s.name}`);
|
|
129
|
+
return { files: [{ from, to: join(out, asset.path) }] };
|
|
130
|
+
}
|
|
131
|
+
if (s.from === "peer-dir") {
|
|
132
|
+
const src = join(await peerRoot(s.name), s.dir);
|
|
133
|
+
const names = (await readdir(src)).filter((n) => !n.includes(s.skip)).sort();
|
|
134
|
+
if (names.length === 0) throw new AssetError(`${s.name}/${s.dir} is empty`);
|
|
135
|
+
return { files: names.map((n) => ({ from: join(src, n), to: join(out, asset.path, n) })) };
|
|
136
|
+
}
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
async function writeWhole(to, write) {
|
|
140
|
+
const part = `${to}.part`;
|
|
141
|
+
try {
|
|
142
|
+
await write(part);
|
|
143
|
+
await rename(part, to);
|
|
144
|
+
} catch (e) {
|
|
145
|
+
await rm(part, { force: true });
|
|
146
|
+
throw e;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
async function download(url, to) {
|
|
150
|
+
const res = await fetch(url);
|
|
151
|
+
if (!res.ok || !res.body) throw new AssetError(`HTTP ${res.status} from ${url}`);
|
|
152
|
+
const body = res.body;
|
|
153
|
+
await writeWhole(to, (part) => pipeline(Readable.fromWeb(body), createWriteStream(part)));
|
|
154
|
+
}
|
|
155
|
+
async function syncModel(asset, url, out, mode, check, r) {
|
|
156
|
+
const to = join(out, asset.path);
|
|
157
|
+
if (await exists(to)) {
|
|
158
|
+
r.current.push(asset.path);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (mode === "skip") {
|
|
162
|
+
r.skipped.push(asset.path);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (check) {
|
|
166
|
+
r.missing.push({ path: asset.path, why: "not there" });
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (mode === "fetch") {
|
|
170
|
+
await download(url, to);
|
|
171
|
+
} else {
|
|
172
|
+
const from = join(mode.dir, asset.path);
|
|
173
|
+
if (!await exists(from)) throw new AssetError(`not in ${mode.dir}`);
|
|
174
|
+
await writeWhole(to, (part) => copyFile(from, part));
|
|
175
|
+
}
|
|
176
|
+
r.written.push(asset.path);
|
|
177
|
+
}
|
|
178
|
+
async function syncAssets(opts) {
|
|
179
|
+
const out = resolve(opts.out);
|
|
180
|
+
const parts = opts.parts ?? DEFAULT_PARTS;
|
|
181
|
+
const mode = opts.models ?? "fetch";
|
|
182
|
+
const check = opts.check ?? false;
|
|
183
|
+
const log = opts.log ?? (() => {
|
|
184
|
+
});
|
|
185
|
+
const version = (await readJson(join(PACKAGE_DIR, "package.json"))).version ?? "?";
|
|
186
|
+
const r = { version, written: [], current: [], skipped: [], missing: [] };
|
|
187
|
+
if (!check) await mkdir(out, { recursive: true });
|
|
188
|
+
for (const asset of assetsFor(parts)) {
|
|
189
|
+
try {
|
|
190
|
+
if (asset.source.from === "model") {
|
|
191
|
+
await syncModel(asset, asset.source.url, out, mode, check, r);
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
const plan = await planOf(asset, out);
|
|
195
|
+
if (!plan) continue;
|
|
196
|
+
let stale = false;
|
|
197
|
+
for (const f of plan.files) {
|
|
198
|
+
if (await sameBytes(f.from, f.to)) continue;
|
|
199
|
+
stale = true;
|
|
200
|
+
if (check) break;
|
|
201
|
+
await mkdir(dirname(f.to), { recursive: true });
|
|
202
|
+
await writeWhole(f.to, (part) => copyFile(f.from, part));
|
|
203
|
+
}
|
|
204
|
+
if (!stale) r.current.push(asset.path);
|
|
205
|
+
else if (check) r.missing.push({ path: asset.path, why: `not the copy in @tradalab/mediakit@${version}` });
|
|
206
|
+
else r.written.push(asset.path);
|
|
207
|
+
} catch (e) {
|
|
208
|
+
r.missing.push({ path: asset.path, why: e instanceof Error ? e.message : String(e) });
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
for (const p of r.written) log(`written ${p}`);
|
|
212
|
+
for (const p of r.skipped) log(`skipped ${p}`);
|
|
213
|
+
for (const m of r.missing) log(`MISSING ${m.path}: ${m.why}`);
|
|
214
|
+
return r;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export {
|
|
218
|
+
OPTIONAL_PARTS,
|
|
219
|
+
DEFAULT_PARTS,
|
|
220
|
+
satisfies,
|
|
221
|
+
syncAssets
|
|
222
|
+
};
|
|
223
|
+
//# sourceMappingURL=chunk-KIULIJZL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/node/assets.ts","../src/assets.ts"],"sourcesContent":["import { createWriteStream } from \"node:fs\"\nimport { copyFile, mkdir, readFile, readdir, rename, rm, stat } from \"node:fs/promises\"\nimport { createRequire } from \"node:module\"\nimport { dirname, join, resolve } from \"node:path\"\nimport { Readable } from \"node:stream\"\nimport { pipeline } from \"node:stream/promises\"\nimport { fileURLToPath } from \"node:url\"\nimport { DEFAULT_PARTS, assetsFor, type Asset, type AssetPart, type PeerPackage } from \"../assets\"\n\nexport type ModelMode = \"fetch\" | \"skip\" | { dir: string }\n\nexport interface SyncOptions {\n out: string\n parts?: readonly AssetPart[]\n models?: ModelMode\n check?: boolean\n log?: (line: string) => void\n}\n\nexport interface Missing {\n path: string\n why: string\n}\n\nexport interface SyncResult {\n version: string\n written: string[]\n current: string[]\n skipped: string[]\n missing: Missing[]\n}\n\nconst PACKAGE_DIR = resolve(dirname(fileURLToPath(import.meta.url)), \"..\")\nconst DIST_DIR = join(PACKAGE_DIR, \"dist\")\n\nclass AssetError extends Error {}\n\nasync function exists(p: string): Promise<boolean> {\n try {\n await stat(p)\n return true\n } catch {\n return false\n }\n}\n\nasync function sameBytes(a: string, b: string): Promise<boolean> {\n try {\n const [sa, sb] = await Promise.all([stat(a), stat(b)])\n if (sa.size !== sb.size) return false\n const [ba, bb] = await Promise.all([readFile(a), readFile(b)])\n return ba.equals(bb)\n } catch {\n return false\n }\n}\n\nasync function readJson(p: string): Promise<{ name?: string; version?: string; peerDependencies?: Record<string, string> }> {\n return JSON.parse(await readFile(p, \"utf8\"))\n}\n\nexport function satisfies(version: string, range: string): boolean {\n return range.split(\"||\").some((r) => satisfiesOne(version, r))\n}\n\nfunction satisfiesOne(version: string, range: string): boolean {\n const want = /^([~^]?)(\\d+)\\.(\\d+)\\.(\\d+)$/.exec(range.trim())\n const have = /^(\\d+)\\.(\\d+)\\.(\\d+)/.exec(version)\n if (!want || !have) return false\n const [, op, ...w] = want\n const [wMajor, wMinor, wPatch] = w.map(Number)\n const [hMajor, hMinor, hPatch] = have.slice(1).map(Number)\n if (op === \"\") return hMajor === wMajor && hMinor === wMinor && hPatch === wPatch\n if (hMajor !== wMajor) return false\n if (op === \"~\" || wMajor === 0) return hMinor === wMinor && hPatch >= wPatch\n return hMinor > wMinor || (hMinor === wMinor && hPatch >= wPatch)\n}\n\nasync function peerRoot(name: PeerPackage): Promise<string> {\n const pkg = await readJson(join(PACKAGE_DIR, \"package.json\"))\n const range = pkg.peerDependencies?.[name]\n if (!range) throw new AssetError(`${name} is not a peer dependency of this mediakit`)\n let dir: string\n try {\n dir = dirname(createRequire(join(PACKAGE_DIR, \"package.json\")).resolve(name))\n } catch {\n throw new AssetError(`${name} is not installed: add ${name}@${range} to the app`)\n }\n for (;;) {\n const file = join(dir, \"package.json\")\n if (await exists(file)) {\n const peer = await readJson(file)\n if (peer.name === name) {\n if (!peer.version || !satisfies(peer.version, range)) {\n throw new AssetError(`${name} ${peer.version} is installed, this mediakit needs ${range}`)\n }\n return dir\n }\n }\n const up = dirname(dir)\n if (up === dir) throw new AssetError(`${name} has no package.json above ${dir}`)\n dir = up\n }\n}\n\ninterface Plan {\n files: { from: string; to: string }[]\n}\n\nasync function planOf(asset: Asset, out: string): Promise<Plan | null> {\n const s = asset.source\n if (s.from === \"dist\") {\n const from = join(DIST_DIR, s.file)\n if (!(await exists(from))) {\n if (asset.debug) return null\n throw new AssetError(`${s.file} is missing from ${DIST_DIR}`)\n }\n return { files: [{ from, to: join(out, asset.path) }] }\n }\n if (s.from === \"peer\") {\n const from = join(await peerRoot(s.name), s.file)\n if (!(await exists(from))) throw new AssetError(`${s.file} is missing from ${s.name}`)\n return { files: [{ from, to: join(out, asset.path) }] }\n }\n if (s.from === \"peer-dir\") {\n const src = join(await peerRoot(s.name), s.dir)\n const names = (await readdir(src)).filter((n) => !n.includes(s.skip)).sort()\n if (names.length === 0) throw new AssetError(`${s.name}/${s.dir} is empty`)\n return { files: names.map((n) => ({ from: join(src, n), to: join(out, asset.path, n) })) }\n }\n return null\n}\n\nasync function writeWhole(to: string, write: (part: string) => Promise<void>): Promise<void> {\n const part = `${to}.part`\n try {\n await write(part)\n await rename(part, to)\n } catch (e) {\n await rm(part, { force: true })\n throw e\n }\n}\n\nasync function download(url: string, to: string): Promise<void> {\n const res = await fetch(url)\n if (!res.ok || !res.body) throw new AssetError(`HTTP ${res.status} from ${url}`)\n const body = res.body as Parameters<typeof Readable.fromWeb>[0]\n await writeWhole(to, (part) => pipeline(Readable.fromWeb(body), createWriteStream(part)))\n}\n\nasync function syncModel(asset: Asset, url: string, out: string, mode: ModelMode, check: boolean, r: SyncResult): Promise<void> {\n const to = join(out, asset.path)\n if (await exists(to)) {\n r.current.push(asset.path)\n return\n }\n if (mode === \"skip\") {\n r.skipped.push(asset.path)\n return\n }\n if (check) {\n r.missing.push({ path: asset.path, why: \"not there\" })\n return\n }\n if (mode === \"fetch\") {\n await download(url, to)\n } else {\n const from = join(mode.dir, asset.path)\n if (!(await exists(from))) throw new AssetError(`not in ${mode.dir}`)\n await writeWhole(to, (part) => copyFile(from, part))\n }\n r.written.push(asset.path)\n}\n\nexport async function syncAssets(opts: SyncOptions): Promise<SyncResult> {\n const out = resolve(opts.out)\n const parts = opts.parts ?? DEFAULT_PARTS\n const mode = opts.models ?? \"fetch\"\n const check = opts.check ?? false\n const log = opts.log ?? (() => {})\n const version = (await readJson(join(PACKAGE_DIR, \"package.json\"))).version ?? \"?\"\n const r: SyncResult = { version, written: [], current: [], skipped: [], missing: [] }\n if (!check) await mkdir(out, { recursive: true })\n for (const asset of assetsFor(parts)) {\n try {\n if (asset.source.from === \"model\") {\n await syncModel(asset, asset.source.url, out, mode, check, r)\n continue\n }\n const plan = await planOf(asset, out)\n if (!plan) continue\n let stale = false\n for (const f of plan.files) {\n if (await sameBytes(f.from, f.to)) continue\n stale = true\n if (check) break\n await mkdir(dirname(f.to), { recursive: true })\n await writeWhole(f.to, (part) => copyFile(f.from, part))\n }\n if (!stale) r.current.push(asset.path)\n else if (check) r.missing.push({ path: asset.path, why: `not the copy in @tradalab/mediakit@${version}` })\n else r.written.push(asset.path)\n } catch (e) {\n r.missing.push({ path: asset.path, why: e instanceof Error ? e.message : String(e) })\n }\n }\n for (const p of r.written) log(`written ${p}`)\n for (const p of r.skipped) log(`skipped ${p}`)\n for (const m of r.missing) log(`MISSING ${m.path}: ${m.why}`)\n return r\n}\n","export const ASSET_BASE = \"/mediakit/\"\n\nexport type AssetPart = \"core\" | \"person\" | \"classes\" | \"face\" | \"cover\"\n\nexport type PeerPackage = \"@mediapipe/tasks-vision\" | \"onnxruntime-web\"\n\nexport type AssetSource =\n | { from: \"dist\"; file: string }\n | { from: \"peer\"; name: PeerPackage; file: string }\n | { from: \"peer-dir\"; name: PeerPackage; dir: string; skip: string }\n | { from: \"model\"; url: string }\n\nexport interface Asset {\n path: string\n part: AssetPart\n source: AssetSource\n debug?: boolean\n}\n\nexport const OPTIONAL_PARTS = [\"person\", \"classes\", \"face\", \"cover\"] as const satisfies readonly AssetPart[]\n\nexport const DEFAULT_PARTS: readonly AssetPart[] = [\"person\", \"classes\", \"face\"]\n\nexport const ASSETS: readonly Asset[] = [\n { path: \"mediakit.wasm\", part: \"core\", source: { from: \"dist\", file: \"mediakit.wasm\" } },\n { path: \"wasm_exec.js\", part: \"core\", source: { from: \"dist\", file: \"wasm_exec.js\" } },\n { path: \"worker.js\", part: \"core\", source: { from: \"dist\", file: \"worker.js\" } },\n { path: \"worker.js.map\", part: \"core\", source: { from: \"dist\", file: \"worker.js.map\" }, debug: true },\n { path: \"detect-worker.js\", part: \"core\", source: { from: \"dist\", file: \"detect-worker.js\" } },\n { path: \"detect-worker.js.map\", part: \"core\", source: { from: \"dist\", file: \"detect-worker.js.map\" }, debug: true },\n { path: \"whiten_pink.png\", part: \"core\", source: { from: \"dist\", file: \"whiten_pink.png\" } },\n { path: \"NOTICE\", part: \"core\", source: { from: \"dist\", file: \"NOTICE\" } },\n { path: \"mp/\", part: \"core\", source: { from: \"peer-dir\", name: \"@mediapipe/tasks-vision\", dir: \"wasm\", skip: \"_module_\" } },\n {\n path: \"selfie_segmenter.tflite\",\n part: \"person\",\n source: { from: \"model\", url: \"https://storage.googleapis.com/mediapipe-models/image_segmenter/selfie_segmenter/float16/latest/selfie_segmenter.tflite\" },\n },\n {\n path: \"selfie_multiclass_256x256.tflite\",\n part: \"classes\",\n source: {\n from: \"model\",\n url: \"https://storage.googleapis.com/mediapipe-models/image_segmenter/selfie_multiclass_256x256/float32/latest/selfie_multiclass_256x256.tflite\",\n },\n },\n {\n path: \"face_landmarker.task\",\n part: \"face\",\n source: { from: \"model\", url: \"https://storage.googleapis.com/mediapipe-models/face_landmarker/face_landmarker/float16/latest/face_landmarker.task\" },\n },\n { path: \"face_cover.onnx\", part: \"cover\", source: { from: \"dist\", file: \"face_cover.onnx\" } },\n { path: \"ort/ort-wasm-simd-threaded.wasm\", part: \"cover\", source: { from: \"peer\", name: \"onnxruntime-web\", file: \"dist/ort-wasm-simd-threaded.wasm\" } },\n { path: \"ort/ort-wasm-simd-threaded.mjs\", part: \"cover\", source: { from: \"peer\", name: \"onnxruntime-web\", file: \"dist/ort-wasm-simd-threaded.mjs\" } },\n]\n\nexport function assetUrl(path: string): string {\n return ASSET_BASE + path\n}\n\nexport function assetsFor(parts: readonly AssetPart[]): Asset[] {\n return ASSETS.filter((a) => a.part === \"core\" || parts.includes(a.part))\n}\n"],"mappings":";AAAA,SAAS,yBAAyB;AAClC,SAAS,UAAU,OAAO,UAAU,SAAS,QAAQ,IAAI,YAAY;AACrE,SA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AW,EAAE,IAAI,CAAC,SAAS,SAAS,EAAE,MAAM,IAAI,CAAC;AAAA,MAC3D;AACA,UAAI,CAAC,MAAO,GAAE,QAAQ,KAAK,MAAM,IAAI;AAAA,eAC5B,MAAO,GAAE,QAAQ,KAAK,EAAE,MAAM,MAAM,MAAM,KAAK,sCAAsC,OAAO,GAAG,CAAC;AAAA,UACpG,GAAE,QAAQ,KAAK,MAAM,IAAI;AAAA,IAClC,SAAS,GAAG;AACR,QAAE,QAAQ,KAAK,EAAE,MAAM,MAAM,MAAM,KAAK,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,EAAE,CAAC;AAAA,IACxF;AAAA,EACJ;AACA,aAAW,KAAK,EAAE,QAAS,KAAI,YAAY,CAAC,EAAE;AAC9C,aAAW,KAAK,EAAE,QAAS,KAAI,YAAY,CAAC,EAAE;AAC9C,aAAW,KAAK,EAAE,QAAS,KAAI,YAAY,EAAE,IAAI,KAAK,EAAE,GAAG,EAAE;AAC7D,SAAO;AACX;","names":[]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// src/assets.ts
|
|
2
|
+
var ASSET_BASE = "/mediakit/";
|
|
3
|
+
var OPTIONAL_PARTS = ["person", "classes", "face", "cover"];
|
|
4
|
+
var DEFAULT_PARTS = ["person", "classes", "face"];
|
|
5
|
+
var ASSETS = [
|
|
6
|
+
{ path: "mediakit.wasm", part: "core", source: { from: "dist", file: "mediakit.wasm" } },
|
|
7
|
+
{ path: "wasm_exec.js", part: "core", source: { from: "dist", file: "wasm_exec.js" } },
|
|
8
|
+
{ path: "worker.js", part: "core", source: { from: "dist", file: "worker.js" } },
|
|
9
|
+
{ path: "worker.js.map", part: "core", source: { from: "dist", file: "worker.js.map" }, debug: true },
|
|
10
|
+
{ path: "detect-worker.js", part: "core", source: { from: "dist", file: "detect-worker.js" } },
|
|
11
|
+
{ path: "detect-worker.js.map", part: "core", source: { from: "dist", file: "detect-worker.js.map" }, debug: true },
|
|
12
|
+
{ path: "whiten_pink.png", part: "core", source: { from: "dist", file: "whiten_pink.png" } },
|
|
13
|
+
{ path: "NOTICE", part: "core", source: { from: "dist", file: "NOTICE" } },
|
|
14
|
+
{ path: "mp/", part: "core", source: { from: "peer-dir", name: "@mediapipe/tasks-vision", dir: "wasm", skip: "_module_" } },
|
|
15
|
+
{
|
|
16
|
+
path: "selfie_segmenter.tflite",
|
|
17
|
+
part: "person",
|
|
18
|
+
source: { from: "model", url: "https://storage.googleapis.com/mediapipe-models/image_segmenter/selfie_segmenter/float16/latest/selfie_segmenter.tflite" }
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
path: "selfie_multiclass_256x256.tflite",
|
|
22
|
+
part: "classes",
|
|
23
|
+
source: {
|
|
24
|
+
from: "model",
|
|
25
|
+
url: "https://storage.googleapis.com/mediapipe-models/image_segmenter/selfie_multiclass_256x256/float32/latest/selfie_multiclass_256x256.tflite"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
path: "face_landmarker.task",
|
|
30
|
+
part: "face",
|
|
31
|
+
source: { from: "model", url: "https://storage.googleapis.com/mediapipe-models/face_landmarker/face_landmarker/float16/latest/face_landmarker.task" }
|
|
32
|
+
},
|
|
33
|
+
{ path: "face_cover.onnx", part: "cover", source: { from: "dist", file: "face_cover.onnx" } },
|
|
34
|
+
{ path: "ort/ort-wasm-simd-threaded.wasm", part: "cover", source: { from: "peer", name: "onnxruntime-web", file: "dist/ort-wasm-simd-threaded.wasm" } },
|
|
35
|
+
{ path: "ort/ort-wasm-simd-threaded.mjs", part: "cover", source: { from: "peer", name: "onnxruntime-web", file: "dist/ort-wasm-simd-threaded.mjs" } }
|
|
36
|
+
];
|
|
37
|
+
function assetUrl(path) {
|
|
38
|
+
return ASSET_BASE + path;
|
|
39
|
+
}
|
|
40
|
+
function assetsFor(parts) {
|
|
41
|
+
return ASSETS.filter((a) => a.part === "core" || parts.includes(a.part));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export {
|
|
45
|
+
ASSET_BASE,
|
|
46
|
+
OPTIONAL_PARTS,
|
|
47
|
+
DEFAULT_PARTS,
|
|
48
|
+
ASSETS,
|
|
49
|
+
assetUrl,
|
|
50
|
+
assetsFor
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=chunk-T7YS2EQE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/assets.ts"],"sourcesContent":["export const ASSET_BASE = \"/mediakit/\"\n\nexport type AssetPart = \"core\" | \"person\" | \"classes\" | \"face\" | \"cover\"\n\nexport type PeerPackage = \"@mediapipe/tasks-vision\" | \"onnxruntime-web\"\n\nexport type AssetSource =\n | { from: \"dist\"; file: string }\n | { from: \"peer\"; name: PeerPackage; file: string }\n | { from: \"peer-dir\"; name: PeerPackage; dir: string; skip: string }\n | { from: \"model\"; url: string }\n\nexport interface Asset {\n path: string\n part: AssetPart\n source: AssetSource\n debug?: boolean\n}\n\nexport const OPTIONAL_PARTS = [\"person\", \"classes\", \"face\", \"cover\"] as const satisfies readonly AssetPart[]\n\nexport const DEFAULT_PARTS: readonly AssetPart[] = [\"person\", \"classes\", \"face\"]\n\nexport const ASSETS: readonly Asset[] = [\n { path: \"mediakit.wasm\", part: \"core\", source: { from: \"dist\", file: \"mediakit.wasm\" } },\n { path: \"wasm_exec.js\", part: \"core\", source: { from: \"dist\", file: \"wasm_exec.js\" } },\n { path: \"worker.js\", part: \"core\", source: { from: \"dist\", file: \"worker.js\" } },\n { path: \"worker.js.map\", part: \"core\", source: { from: \"dist\", file: \"worker.js.map\" }, debug: true },\n { path: \"detect-worker.js\", part: \"core\", source: { from: \"dist\", file: \"detect-worker.js\" } },\n { path: \"detect-worker.js.map\", part: \"core\", source: { from: \"dist\", file: \"detect-worker.js.map\" }, debug: true },\n { path: \"whiten_pink.png\", part: \"core\", source: { from: \"dist\", file: \"whiten_pink.png\" } },\n { path: \"NOTICE\", part: \"core\", source: { from: \"dist\", file: \"NOTICE\" } },\n { path: \"mp/\", part: \"core\", source: { from: \"peer-dir\", name: \"@mediapipe/tasks-vision\", dir: \"wasm\", skip: \"_module_\" } },\n {\n path: \"selfie_segmenter.tflite\",\n part: \"person\",\n source: { from: \"model\", url: \"https://storage.googleapis.com/mediapipe-models/image_segmenter/selfie_segmenter/float16/latest/selfie_segmenter.tflite\" },\n },\n {\n path: \"selfie_multiclass_256x256.tflite\",\n part: \"classes\",\n source: {\n from: \"model\",\n url: \"https://storage.googleapis.com/mediapipe-models/image_segmenter/selfie_multiclass_256x256/float32/latest/selfie_multiclass_256x256.tflite\",\n },\n },\n {\n path: \"face_landmarker.task\",\n part: \"face\",\n source: { from: \"model\", url: \"https://storage.googleapis.com/mediapipe-models/face_landmarker/face_landmarker/float16/latest/face_landmarker.task\" },\n },\n { path: \"face_cover.onnx\", part: \"cover\", source: { from: \"dist\", file: \"face_cover.onnx\" } },\n { path: \"ort/ort-wasm-simd-threaded.wasm\", part: \"cover\", source: { from: \"peer\", name: \"onnxruntime-web\", file: \"dist/ort-wasm-simd-threaded.wasm\" } },\n { path: \"ort/ort-wasm-simd-threaded.mjs\", part: \"cover\", source: { from: \"peer\", name: \"onnxruntime-web\", file: \"dist/ort-wasm-simd-threaded.mjs\" } },\n]\n\nexport function assetUrl(path: string): string {\n return ASSET_BASE + path\n}\n\nexport function assetsFor(parts: readonly AssetPart[]): Asset[] {\n return ASSETS.filter((a) => a.part === \"core\" || parts.includes(a.part))\n}\n"],"mappings":";AAAO,IAAM,aAAa;AAmBnB,IAAM,iBAAiB,CAAC,UAAU,WAAW,QAAQ,OAAO;AAE5D,IAAM,gBAAsC,CAAC,UAAU,WAAW,MAAM;AAExE,IAAM,SAA2B;AAAA,EACpC,EAAE,MAAM,iBAAiB,MAAM,QAAQ,QAAQ,EAAE,MAAM,QAAQ,MAAM,gBAAgB,EAAE;AAAA,EACvF,EAAE,MAAM,gBAAgB,MAAM,QAAQ,QAAQ,EAAE,MAAM,QAAQ,MAAM,eAAe,EAAE;AA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