idmission-web-sdk 2.3.224 → 2.3.225-feature-per-runtime-capability-probe-e2ff01d
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/lib/models/CapabilityProbing.d.ts +11 -2
- package/dist/lib/models/CapabilityProbing.d.ts.map +1 -1
- package/dist/lib/models/preloadModels.d.ts.map +1 -1
- package/dist/lib/models/providers/mediapipe/BarcodeReadability.d.ts.map +1 -1
- package/dist/lib/models/providers/mediapipe/DocumentDetection.d.ts.map +1 -1
- package/dist/lib/models/providers/mediapipe/FaceDetection.d.ts.map +1 -1
- package/dist/lib/models/providers/mediapipe/FaceLandmarker.d.ts.map +1 -1
- package/dist/lib/models/providers/mediapipe/Focus.d.ts.map +1 -1
- package/dist/sdk2.cjs.development.js +284 -178
- package/dist/sdk2.cjs.development.js.map +1 -1
- package/dist/sdk2.cjs.production.js +1 -1
- package/dist/sdk2.cjs.production.js.map +1 -1
- package/dist/sdk2.esm.js +284 -178
- package/dist/sdk2.esm.js.map +1 -1
- package/dist/sdk2.umd.development.js +286 -180
- package/dist/sdk2.umd.development.js.map +1 -1
- package/dist/sdk2.umd.production.js +1 -1
- package/dist/sdk2.umd.production.js.map +1 -1
- package/package.json +1 -1
|
@@ -4084,204 +4084,188 @@
|
|
|
4084
4084
|
return [value, setWithStamp, capturedAt];
|
|
4085
4085
|
}
|
|
4086
4086
|
|
|
4087
|
-
var
|
|
4088
|
-
var
|
|
4089
|
-
var
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
};
|
|
4121
|
-
}
|
|
4122
|
-
return [2 /*return*/, fn()["finally"](function () {
|
|
4123
|
-
if (--quietWasmRefCount === 0) {
|
|
4124
|
-
console.error = savedNativeError; // eslint-disable-line no-console
|
|
4125
|
-
savedNativeError = null;
|
|
4126
|
-
}
|
|
4127
|
-
})];
|
|
4128
|
-
});
|
|
4129
|
-
});
|
|
4130
|
-
}
|
|
4131
|
-
var visionRuntimePreloading = false;
|
|
4132
|
-
function preloadVisionRuntime() {
|
|
4087
|
+
var RUNTIME_NAMES = ['mediapipe', 'litert'];
|
|
4088
|
+
var defaultImageSegmenterModelPath = 'https://websdk-cdn-dev.idmission.com/assets/models/selfiesegmenter20240524/selfie_segmenter.tflite';
|
|
4089
|
+
var defaultImageSegmenterModelHash = 'A2bQ8+iZyQM3KIGVBUf0FyetqxuynyKpjsjCE8uzoJEnj1ghCu6ge2daiRffAiS5';
|
|
4090
|
+
var imageSegmenterModelSizeInBytes = 256440.32;
|
|
4091
|
+
// We globally set a cache key based on the time at page load so the built-in
|
|
4092
|
+
// speed test isn't fooled by cache hits, but subsequent downloads of the
|
|
4093
|
+
// vision runtime do load from the cache.
|
|
4094
|
+
var tinyModelCacheKey = new Date().getTime();
|
|
4095
|
+
function makeInitialModelCapabilities() {
|
|
4096
|
+
return {
|
|
4097
|
+
networkProbeState: 'notProbed',
|
|
4098
|
+
networkTier: 'untested',
|
|
4099
|
+
networkSpeed: 0,
|
|
4100
|
+
networkTestTime: 0,
|
|
4101
|
+
delegateByRuntime: Object.fromEntries(RUNTIME_NAMES.map(function (name) {
|
|
4102
|
+
return [name, {
|
|
4103
|
+
probeState: 'notProbed',
|
|
4104
|
+
delegate: 'GPU'
|
|
4105
|
+
}];
|
|
4106
|
+
}))
|
|
4107
|
+
};
|
|
4108
|
+
}
|
|
4109
|
+
var modelCapabilities = makeInitialModelCapabilities();
|
|
4110
|
+
function getDelegate(runtime) {
|
|
4111
|
+
return modelCapabilities.delegateByRuntime[runtime].delegate;
|
|
4112
|
+
}
|
|
4113
|
+
function setDelegate(runtime, delegate) {
|
|
4114
|
+
modelCapabilities.delegateByRuntime[runtime].delegate = delegate;
|
|
4115
|
+
}
|
|
4116
|
+
// Network speed probe. Runtime-agnostic — just times an HTTP fetch of a
|
|
4117
|
+
// small known artifact. Idempotent across concurrent callers via the
|
|
4118
|
+
// 'probing' wait loop.
|
|
4119
|
+
function probeNetworkSpeed() {
|
|
4133
4120
|
return __awaiter(this, void 0, void 0, function () {
|
|
4134
|
-
|
|
4135
|
-
var detail = event.detail;
|
|
4136
|
-
if (detail.url !== url) return;
|
|
4137
|
-
progressByUseCase.visionRuntime = sumUpProgressForDependencies([url]);
|
|
4138
|
-
document.dispatchEvent(new CustomEvent('idmission.preloadProgress.visionRuntime', {
|
|
4139
|
-
detail: progressByUseCase.visionRuntime
|
|
4140
|
-
}));
|
|
4141
|
-
}
|
|
4142
|
-
var url;
|
|
4121
|
+
var modelAssetPath, startedAt, e_1, time, speedMbps;
|
|
4143
4122
|
return __generator(this, function (_a) {
|
|
4144
4123
|
switch (_a.label) {
|
|
4145
4124
|
case 0:
|
|
4146
|
-
if (
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4125
|
+
if (modelCapabilities.networkProbeState === 'probed') return [2 /*return*/];
|
|
4126
|
+
if (modelCapabilities.networkProbeState === 'probing') {
|
|
4127
|
+
return [2 /*return*/, new Promise(function (resolve) {
|
|
4128
|
+
var id = setInterval(function () {
|
|
4129
|
+
if (modelCapabilities.networkProbeState === 'probed') {
|
|
4130
|
+
clearInterval(id);
|
|
4131
|
+
resolve();
|
|
4132
|
+
}
|
|
4133
|
+
}, 100);
|
|
4134
|
+
})];
|
|
4135
|
+
}
|
|
4136
|
+
modelCapabilities.networkProbeState = 'probing';
|
|
4154
4137
|
_a.label = 1;
|
|
4155
4138
|
case 1:
|
|
4156
|
-
_a.trys.push([1,,
|
|
4157
|
-
|
|
4139
|
+
_a.trys.push([1,, 6, 7]);
|
|
4140
|
+
modelAssetPath = "".concat(defaultImageSegmenterModelPath, "?_=").concat(tinyModelCacheKey);
|
|
4141
|
+
startedAt = new Date();
|
|
4142
|
+
_a.label = 2;
|
|
4158
4143
|
case 2:
|
|
4159
|
-
_a.
|
|
4160
|
-
return [
|
|
4144
|
+
_a.trys.push([2, 4,, 5]);
|
|
4145
|
+
return [4 /*yield*/, Promise.race([preloadDependency(modelAssetPath, defaultImageSegmenterModelHash), giveUpAfter(10000)])];
|
|
4161
4146
|
case 3:
|
|
4162
|
-
|
|
4163
|
-
|
|
4164
|
-
return [7 /*endfinally*/];
|
|
4147
|
+
_a.sent();
|
|
4148
|
+
return [3 /*break*/, 5];
|
|
4165
4149
|
case 4:
|
|
4150
|
+
e_1 = _a.sent();
|
|
4151
|
+
error('speed test failed', e_1);
|
|
4152
|
+
modelCapabilities.networkTier = 'unusable';
|
|
4153
|
+
return [2 /*return*/];
|
|
4154
|
+
case 5:
|
|
4155
|
+
time = (new Date().getTime() - startedAt.getTime()) / 1000.0;
|
|
4156
|
+
modelCapabilities.networkTestTime || (modelCapabilities.networkTestTime = time);
|
|
4157
|
+
modelCapabilities.networkSpeed || (modelCapabilities.networkSpeed = imageSegmenterModelSizeInBytes / time);
|
|
4158
|
+
modelCapabilities.networkTier = time < 0.5 ? 'fast' : time < 2 ? 'medium' : 'slow';
|
|
4159
|
+
speedMbps = modelCapabilities.networkSpeed / 1024 / 1024;
|
|
4160
|
+
log('Model Probing: network speed', speedMbps.toFixed(3), 'Mbps');
|
|
4161
|
+
log('Model Probing: network test took', time);
|
|
4162
|
+
log('Model Probing: network tier', modelCapabilities.networkTier);
|
|
4163
|
+
return [3 /*break*/, 7];
|
|
4164
|
+
case 6:
|
|
4165
|
+
modelCapabilities.networkProbeState = 'probed';
|
|
4166
|
+
return [7 /*endfinally*/];
|
|
4167
|
+
case 7:
|
|
4166
4168
|
return [2 /*return*/];
|
|
4167
4169
|
}
|
|
4168
4170
|
});
|
|
4169
4171
|
});
|
|
4170
4172
|
}
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
|
|
4174
|
-
|
|
4175
|
-
// The idea here is that we globally set a cache key based on the time at page load. That way our built-in speed test
|
|
4176
|
-
// isn't fooled by cache times, but subsequent downloads of the vision runtime still do load from the cache.
|
|
4177
|
-
var tinyModelCacheKey = new Date().getTime();
|
|
4178
|
-
var initialModelCapabilities = {
|
|
4179
|
-
probeState: 'notProbed',
|
|
4180
|
-
delegate: 'GPU',
|
|
4181
|
-
networkTier: 'untested',
|
|
4182
|
-
networkSpeed: 0,
|
|
4183
|
-
networkTestTime: 0
|
|
4184
|
-
};
|
|
4185
|
-
var modelCapabilities = _assign({}, initialModelCapabilities);
|
|
4186
|
-
function probeModelCapabilities() {
|
|
4173
|
+
// Probe a specific runtime's GPU/CPU delegate. Lazily dispatches to the
|
|
4174
|
+
// runtime-specific verifier via dynamic import so a customer who never
|
|
4175
|
+
// invokes a particular runtime never loads its WASM payload.
|
|
4176
|
+
function probeDelegateForRuntime(runtime) {
|
|
4187
4177
|
return __awaiter(this, void 0, void 0, function () {
|
|
4188
|
-
var
|
|
4178
|
+
var state, firstError_1, secondError_1;
|
|
4189
4179
|
return __generator(this, function (_a) {
|
|
4190
4180
|
switch (_a.label) {
|
|
4191
4181
|
case 0:
|
|
4192
|
-
|
|
4193
|
-
if (
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
4202
|
-
|
|
4182
|
+
state = modelCapabilities.delegateByRuntime[runtime];
|
|
4183
|
+
if (state.probeState === 'probed') return [2 /*return*/];
|
|
4184
|
+
if (state.probeState === 'probing') {
|
|
4185
|
+
return [2 /*return*/, new Promise(function (resolve) {
|
|
4186
|
+
var id = setInterval(function () {
|
|
4187
|
+
if (state.probeState === 'probed') {
|
|
4188
|
+
clearInterval(id);
|
|
4189
|
+
resolve();
|
|
4190
|
+
}
|
|
4191
|
+
}, 100);
|
|
4192
|
+
})];
|
|
4193
|
+
}
|
|
4194
|
+
state.probeState = 'probing';
|
|
4195
|
+
_a.label = 1;
|
|
4203
4196
|
case 1:
|
|
4204
|
-
_a.
|
|
4205
|
-
|
|
4197
|
+
_a.trys.push([1,, 11, 12]);
|
|
4198
|
+
// Need network speed first because the delegate verifier reuses the
|
|
4199
|
+
// segmenter test model bytes.
|
|
4200
|
+
return [4 /*yield*/, probeNetworkSpeed()];
|
|
4206
4201
|
case 2:
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
|
|
4202
|
+
// Need network speed first because the delegate verifier reuses the
|
|
4203
|
+
// segmenter test model bytes.
|
|
4204
|
+
_a.sent();
|
|
4205
|
+
if (modelCapabilities.networkTier === 'unusable') {
|
|
4206
|
+
state.delegate = 'NONE';
|
|
4207
|
+
return [2 /*return*/];
|
|
4208
|
+
}
|
|
4209
|
+
_a.label = 3;
|
|
4210
4210
|
case 3:
|
|
4211
|
+
_a.trys.push([3, 5,, 10]);
|
|
4212
|
+
log("Model Probing: testing ".concat(runtime, " GPU capabilities..."));
|
|
4213
|
+
return [4 /*yield*/, verifyDelegate(runtime, 'GPU')];
|
|
4214
|
+
case 4:
|
|
4211
4215
|
_a.sent();
|
|
4212
|
-
log(
|
|
4216
|
+
log("Model Probing: ".concat(runtime, " GPU is capable."));
|
|
4213
4217
|
return [3 /*break*/, 10];
|
|
4214
|
-
case 4:
|
|
4215
|
-
error_1 = _a.sent();
|
|
4216
|
-
warn('Model Probing: GPU delegate could not be loaded', error_1);
|
|
4217
|
-
modelCapabilities.delegate = 'CPU';
|
|
4218
|
-
_a.label = 5;
|
|
4219
4218
|
case 5:
|
|
4220
|
-
_a.
|
|
4221
|
-
|
|
4222
|
-
|
|
4219
|
+
firstError_1 = _a.sent();
|
|
4220
|
+
warn("Model Probing: ".concat(runtime, " GPU delegate could not be loaded"), firstError_1);
|
|
4221
|
+
state.delegate = 'CPU';
|
|
4222
|
+
_a.label = 6;
|
|
4223
4223
|
case 6:
|
|
4224
|
-
_a.
|
|
4225
|
-
log(
|
|
4226
|
-
return [
|
|
4224
|
+
_a.trys.push([6, 8,, 9]);
|
|
4225
|
+
log("Model Probing: testing ".concat(runtime, " CPU capabilities..."));
|
|
4226
|
+
return [4 /*yield*/, verifyDelegate(runtime, 'CPU')];
|
|
4227
4227
|
case 7:
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
return [3 /*break*/, 8];
|
|
4228
|
+
_a.sent();
|
|
4229
|
+
log("Model Probing: ".concat(runtime, " CPU is capable."));
|
|
4230
|
+
return [3 /*break*/, 9];
|
|
4232
4231
|
case 8:
|
|
4233
|
-
|
|
4232
|
+
secondError_1 = _a.sent();
|
|
4233
|
+
warn("Model Probing: ".concat(runtime, " CPU delegate could not be loaded"), secondError_1);
|
|
4234
|
+
state.delegate = 'NONE';
|
|
4235
|
+
return [3 /*break*/, 9];
|
|
4234
4236
|
case 9:
|
|
4235
|
-
|
|
4236
|
-
return [7 /*endfinally*/];
|
|
4237
|
+
return [3 /*break*/, 10];
|
|
4237
4238
|
case 10:
|
|
4239
|
+
return [3 /*break*/, 12];
|
|
4240
|
+
case 11:
|
|
4241
|
+
state.probeState = 'probed';
|
|
4242
|
+
return [7 /*endfinally*/];
|
|
4243
|
+
case 12:
|
|
4238
4244
|
return [2 /*return*/];
|
|
4239
4245
|
}
|
|
4240
4246
|
});
|
|
4241
4247
|
});
|
|
4242
4248
|
}
|
|
4243
|
-
function
|
|
4244
|
-
return __awaiter(this,
|
|
4245
|
-
var modelAssetPath,
|
|
4246
|
-
if (delegate === void 0) {
|
|
4247
|
-
delegate = 'GPU';
|
|
4248
|
-
}
|
|
4249
|
-
if (maxTime === void 0) {
|
|
4250
|
-
maxTime = 10000;
|
|
4251
|
-
}
|
|
4249
|
+
function verifyDelegate(runtime, delegate) {
|
|
4250
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
4251
|
+
var modelAssetPath, preloadVisionRuntime, verifyMediaPipeDelegate, exhaustive;
|
|
4252
4252
|
return __generator(this, function (_a) {
|
|
4253
4253
|
switch (_a.label) {
|
|
4254
4254
|
case 0:
|
|
4255
4255
|
modelAssetPath = "".concat(defaultImageSegmenterModelPath, "?_=").concat(tinyModelCacheKey);
|
|
4256
|
-
|
|
4257
|
-
_a.label = 1;
|
|
4256
|
+
return [4 /*yield*/, Promise.resolve().then(function () { return VisionRuntime; })];
|
|
4258
4257
|
case 1:
|
|
4259
|
-
_a.
|
|
4260
|
-
return [4 /*yield*/,
|
|
4258
|
+
preloadVisionRuntime = _a.sent().preloadVisionRuntime;
|
|
4259
|
+
return [4 /*yield*/, preloadVisionRuntime()];
|
|
4261
4260
|
case 2:
|
|
4262
4261
|
_a.sent();
|
|
4263
|
-
return [3 /*break*/, 4];
|
|
4264
|
-
case 3:
|
|
4265
|
-
e_1 = _a.sent();
|
|
4266
|
-
error('speed test failed', e_1);
|
|
4267
|
-
modelCapabilities.networkTier = 'unusable';
|
|
4268
|
-
return [2 /*return*/];
|
|
4269
|
-
case 4:
|
|
4270
|
-
time = (new Date().getTime() - startedAt.getTime()) / 1000.0;
|
|
4271
|
-
modelCapabilities.networkTestTime || (modelCapabilities.networkTestTime = time);
|
|
4272
|
-
modelCapabilities.networkSpeed || (modelCapabilities.networkSpeed = imageSegmenterModelSizeInBytes / time);
|
|
4273
|
-
modelCapabilities.networkTier = time < 0.5 ? 'fast' : time < 2 ? 'medium' : 'slow';
|
|
4274
|
-
speedMbps = modelCapabilities.networkSpeed / 1024 / 1024;
|
|
4275
|
-
log('Model Probing: network speed', speedMbps.toFixed(3), 'Mbps');
|
|
4276
|
-
log('Model Probing: network test took', time);
|
|
4277
|
-
log('Model Probing: network tier', modelCapabilities.networkTier);
|
|
4278
4262
|
return [4 /*yield*/, Promise.resolve().then(function () { return CapabilityProbe; })];
|
|
4279
|
-
case
|
|
4263
|
+
case 3:
|
|
4280
4264
|
verifyMediaPipeDelegate = _a.sent().verifyMediaPipeDelegate;
|
|
4281
|
-
return [
|
|
4282
|
-
case
|
|
4283
|
-
|
|
4284
|
-
|
|
4265
|
+
return [2 /*return*/, verifyMediaPipeDelegate(delegate, modelAssetPath)];
|
|
4266
|
+
case 4:
|
|
4267
|
+
exhaustive = runtime;
|
|
4268
|
+
throw new Error("Unknown runtime: ".concat(exhaustive));
|
|
4285
4269
|
}
|
|
4286
4270
|
});
|
|
4287
4271
|
});
|
|
@@ -4326,7 +4310,7 @@
|
|
|
4326
4310
|
|
|
4327
4311
|
var preloadModels = function preloadModels(_a) {
|
|
4328
4312
|
return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
4329
|
-
var preloadTasks;
|
|
4313
|
+
var needsMediaPipe, preloadTasks;
|
|
4330
4314
|
var _c = _b.documentDetectionModel,
|
|
4331
4315
|
documentDetectionModel = _c === void 0 ? true : _c,
|
|
4332
4316
|
_d = _b.focusModel,
|
|
@@ -4340,9 +4324,24 @@
|
|
|
4340
4324
|
return __generator(this, function (_h) {
|
|
4341
4325
|
switch (_h.label) {
|
|
4342
4326
|
case 0:
|
|
4343
|
-
|
|
4327
|
+
// Network probe is runtime-agnostic. The delegate probe is per-runtime;
|
|
4328
|
+
// every model preloaded by this function is currently MediaPipe-backed,
|
|
4329
|
+
// so probe MP only when at least one such model is in the config. If a
|
|
4330
|
+
// future caller passes only LiteRT-backed models, MP will not be probed.
|
|
4331
|
+
return [4 /*yield*/, probeNetworkSpeed()];
|
|
4344
4332
|
case 1:
|
|
4333
|
+
// Network probe is runtime-agnostic. The delegate probe is per-runtime;
|
|
4334
|
+
// every model preloaded by this function is currently MediaPipe-backed,
|
|
4335
|
+
// so probe MP only when at least one such model is in the config. If a
|
|
4336
|
+
// future caller passes only LiteRT-backed models, MP will not be probed.
|
|
4337
|
+
_h.sent();
|
|
4338
|
+
needsMediaPipe = !!documentDetectionModel || !!focusModel || !!faceDetectionModel || !!faceLandmarkerModel || !!barcodeReadabilityModel;
|
|
4339
|
+
if (!needsMediaPipe) return [3 /*break*/, 3];
|
|
4340
|
+
return [4 /*yield*/, probeDelegateForRuntime('mediapipe')];
|
|
4341
|
+
case 2:
|
|
4345
4342
|
_h.sent();
|
|
4343
|
+
_h.label = 3;
|
|
4344
|
+
case 3:
|
|
4346
4345
|
preloadTasks = [];
|
|
4347
4346
|
if (documentDetectionModel) {
|
|
4348
4347
|
preloadTasks.push(preloadDocumentDetectorDependencies);
|
|
@@ -4360,7 +4359,7 @@
|
|
|
4360
4359
|
preloadTasks.push(preloadBarcodeReadabilityModelDependencies);
|
|
4361
4360
|
}
|
|
4362
4361
|
return [4 /*yield*/, Promise.all(preloadTasks)];
|
|
4363
|
-
case
|
|
4362
|
+
case 4:
|
|
4364
4363
|
_h.sent();
|
|
4365
4364
|
return [2 /*return*/];
|
|
4366
4365
|
}
|
|
@@ -4521,10 +4520,19 @@
|
|
|
4521
4520
|
}, 100);
|
|
4522
4521
|
})];
|
|
4523
4522
|
modelsPreloading[model] = true;
|
|
4524
|
-
|
|
4523
|
+
// All five models in this function are MediaPipe-backed; probe MP's
|
|
4524
|
+
// delegate to surface NONE before we waste bandwidth downloading bytes
|
|
4525
|
+
// for a model the device can't run.
|
|
4526
|
+
return [4 /*yield*/, probeNetworkSpeed()];
|
|
4525
4527
|
case 1:
|
|
4528
|
+
// All five models in this function are MediaPipe-backed; probe MP's
|
|
4529
|
+
// delegate to surface NONE before we waste bandwidth downloading bytes
|
|
4530
|
+
// for a model the device can't run.
|
|
4526
4531
|
_a.sent();
|
|
4527
|
-
|
|
4532
|
+
return [4 /*yield*/, probeDelegateForRuntime('mediapipe')];
|
|
4533
|
+
case 2:
|
|
4534
|
+
_a.sent();
|
|
4535
|
+
if (getDelegate('mediapipe') === 'NONE') {
|
|
4528
4536
|
throw new Error("No available delegate for ".concat(model, " model."));
|
|
4529
4537
|
}
|
|
4530
4538
|
dependencies = [{
|
|
@@ -4532,20 +4540,20 @@
|
|
|
4532
4540
|
hash: defaultModelPaths[model + 'Hash']
|
|
4533
4541
|
}];
|
|
4534
4542
|
document.addEventListener('idmission.preloadProgress', handleModelDownloadProgress);
|
|
4535
|
-
_a.label =
|
|
4536
|
-
case
|
|
4537
|
-
_a.trys.push([
|
|
4543
|
+
_a.label = 3;
|
|
4544
|
+
case 3:
|
|
4545
|
+
_a.trys.push([3,, 5, 6]);
|
|
4538
4546
|
return [4 /*yield*/, Promise.all(dependencies.map(function (d) {
|
|
4539
4547
|
return preloadDependency(d.url, d.hash);
|
|
4540
4548
|
}))];
|
|
4541
|
-
case 3:
|
|
4542
|
-
_a.sent();
|
|
4543
|
-
return [3 /*break*/, 5];
|
|
4544
4549
|
case 4:
|
|
4550
|
+
_a.sent();
|
|
4551
|
+
return [3 /*break*/, 6];
|
|
4552
|
+
case 5:
|
|
4545
4553
|
document.removeEventListener('idmission.preloadProgress', handleModelDownloadProgress);
|
|
4546
4554
|
modelsPreloading[model] = false;
|
|
4547
4555
|
return [7 /*endfinally*/];
|
|
4548
|
-
case
|
|
4556
|
+
case 6:
|
|
4549
4557
|
return [2 /*return*/];
|
|
4550
4558
|
}
|
|
4551
4559
|
});
|
|
@@ -21554,7 +21562,7 @@
|
|
|
21554
21562
|
top: top - 2
|
|
21555
21563
|
}
|
|
21556
21564
|
});
|
|
21557
|
-
})))), debugMode && (/*#__PURE__*/React.createElement(DebugStatsPane, null, camera ? (/*#__PURE__*/React.createElement(React.Fragment, null, "\u2705 Camera: ", camera.label, " (", camera.width, "x", camera.height, ")")) : '❌ Camera not ready', /*#__PURE__*/React.createElement("br", null),
|
|
21565
|
+
})))), debugMode && (/*#__PURE__*/React.createElement(DebugStatsPane, null, camera ? (/*#__PURE__*/React.createElement(React.Fragment, null, "\u2705 Camera: ", camera.label, " (", camera.width, "x", camera.height, ")")) : '❌ Camera not ready', /*#__PURE__*/React.createElement("br", null), getDelegate('mediapipe') !== 'NONE' ? '✅' : '❌', " Delegate:", ' ', getDelegate('mediapipe'), /*#__PURE__*/React.createElement("br", null), !(prediction === null || prediction === void 0 ? void 0 : prediction.faceNotDetected) ? '✅' : '❌', " Face Detected", /*#__PURE__*/React.createElement("br", null), !(prediction === null || prediction === void 0 ? void 0 : prediction.faceNotCentered) ? '✅' : '❌', " Face Centered", /*#__PURE__*/React.createElement("br", null), !(prediction === null || prediction === void 0 ? void 0 : prediction.faceTooClose) && !(prediction === null || prediction === void 0 ? void 0 : prediction.faceTooFar) ? '✅' : '❌', ' ', "Face", ' ', (prediction === null || prediction === void 0 ? void 0 : prediction.faceTooClose) ? 'Too Close' : (prediction === null || prediction === void 0 ? void 0 : prediction.faceTooFar) ? 'Too Far' : 'Distance Correct', /*#__PURE__*/React.createElement("br", null), !(prediction === null || prediction === void 0 ? void 0 : prediction.faceLookingAway) ? '✅' : '❌', " Face Looking Forward", /*#__PURE__*/React.createElement("br", null), !(prediction === null || prediction === void 0 ? void 0 : prediction.faceIsStable) ? '✅' : '❌', " Face Is Stable", /*#__PURE__*/React.createElement("br", null), !(prediction === null || prediction === void 0 ? void 0 : prediction.noseIsStable) ? '✅' : '❌', " Nose Is Stable", /*#__PURE__*/React.createElement("br", null), !timedOut ? '✅' : '❌', " Time Remaining:", ' ', Math.max(0, timeoutDurationMs - (new Date().getTime() - (timeoutStartedAt !== null && timeoutStartedAt !== void 0 ? timeoutStartedAt : new Date()).getTime())), "ms", /*#__PURE__*/React.createElement("br", null), (prediction === null || prediction === void 0 ? void 0 : prediction.faceVisibilityTooLow) ? '❌' : '✅', " Visibility", minCaptureBrightnessThreshold !== undefined && (/*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("br", null), "\xA0\xA0Brightness:", ' ', (_e = (_d = prediction === null || prediction === void 0 ? void 0 : prediction.brightness) === null || _d === void 0 ? void 0 : _d.toFixed(1)) !== null && _e !== void 0 ? _e : '—', " (min:", ' ', minCaptureBrightnessThreshold, ")")), minCaptureRangeThreshold !== undefined && (/*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("br", null), "\xA0\xA0Range: ", (_g = (_f = prediction === null || prediction === void 0 ? void 0 : prediction.range) === null || _f === void 0 ? void 0 : _f.toFixed(1)) !== null && _g !== void 0 ? _g : '—', " (min: ", minCaptureRangeThreshold, ")")), minCaptureVarianceThreshold !== undefined && (/*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("br", null), "\xA0\xA0Variance: ", (_j = (_h = prediction === null || prediction === void 0 ? void 0 : prediction.variance) === null || _h === void 0 ? void 0 : _h.toFixed(1)) !== null && _j !== void 0 ? _j : '—', ' ', "(min: ", minCaptureVarianceThreshold, ")")))), allowManualCapture && (/*#__PURE__*/React.createElement(CaptureButtonContainer$1, {
|
|
21558
21566
|
className: classNames.manualCaptureBtnContainer
|
|
21559
21567
|
}, /*#__PURE__*/React.createElement(CaptureButton$1, {
|
|
21560
21568
|
className: classNames.manualCaptureBtn,
|
|
@@ -31105,6 +31113,99 @@
|
|
|
31105
31113
|
stopAll: stopAll
|
|
31106
31114
|
});
|
|
31107
31115
|
|
|
31116
|
+
var visionTasksBasePath = "https://websdk-cdn-dev.idmission.com/assets/vision_wasm_internal_0.10.7";
|
|
31117
|
+
var visionRuntimeHash = 'tdLjRcm8XLETT+lUxF1oNst5jULaTGDUc2YtazwbGnLVGD0D/4A274KuJF+adneW';
|
|
31118
|
+
var wasmStderrPatterns = ['TensorFlow Lite', 'static-sized tensors', 'Attempting to use a delegate'];
|
|
31119
|
+
function isWasmStderr(msg) {
|
|
31120
|
+
return wasmStderrPatterns.some(function (p) {
|
|
31121
|
+
return msg.includes(p);
|
|
31122
|
+
});
|
|
31123
|
+
}
|
|
31124
|
+
var quietWasmRefCount = 0;
|
|
31125
|
+
var savedNativeError = null;
|
|
31126
|
+
/**
|
|
31127
|
+
* Wraps an async operation that initializes WASM/TFLite models, temporarily
|
|
31128
|
+
* intercepting console.error to downgrade known-benign TF Lite stderr messages
|
|
31129
|
+
* (routed through Emscripten's fd_write -> console.error) to debug level.
|
|
31130
|
+
*
|
|
31131
|
+
* Uses a reference count so overlapping calls share a single patched handler
|
|
31132
|
+
* and only restore the original console.error when the last one completes.
|
|
31133
|
+
*/
|
|
31134
|
+
function withQuietWasm(fn) {
|
|
31135
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
31136
|
+
return __generator(this, function (_a) {
|
|
31137
|
+
if (quietWasmRefCount++ === 0) {
|
|
31138
|
+
savedNativeError = console.error; // eslint-disable-line no-console
|
|
31139
|
+
console.error = function () {
|
|
31140
|
+
var args = [];
|
|
31141
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
31142
|
+
args[_i] = arguments[_i];
|
|
31143
|
+
}
|
|
31144
|
+
if (isWasmStderr(String(args[0]))) {
|
|
31145
|
+
debug.apply(void 0, args);
|
|
31146
|
+
return;
|
|
31147
|
+
}
|
|
31148
|
+
savedNativeError.apply(void 0, args);
|
|
31149
|
+
};
|
|
31150
|
+
}
|
|
31151
|
+
return [2 /*return*/, fn()["finally"](function () {
|
|
31152
|
+
if (--quietWasmRefCount === 0) {
|
|
31153
|
+
console.error = savedNativeError; // eslint-disable-line no-console
|
|
31154
|
+
savedNativeError = null;
|
|
31155
|
+
}
|
|
31156
|
+
})];
|
|
31157
|
+
});
|
|
31158
|
+
});
|
|
31159
|
+
}
|
|
31160
|
+
var visionRuntimePreloading = false;
|
|
31161
|
+
function preloadVisionRuntime() {
|
|
31162
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
31163
|
+
function handleDownloadProgress(event) {
|
|
31164
|
+
var detail = event.detail;
|
|
31165
|
+
if (detail.url !== url) return;
|
|
31166
|
+
progressByUseCase.visionRuntime = sumUpProgressForDependencies([url]);
|
|
31167
|
+
document.dispatchEvent(new CustomEvent('idmission.preloadProgress.visionRuntime', {
|
|
31168
|
+
detail: progressByUseCase.visionRuntime
|
|
31169
|
+
}));
|
|
31170
|
+
}
|
|
31171
|
+
var url;
|
|
31172
|
+
return __generator(this, function (_a) {
|
|
31173
|
+
switch (_a.label) {
|
|
31174
|
+
case 0:
|
|
31175
|
+
if (visionRuntimePreloading) return [2 /*return*/, new Promise(function (resolve) {
|
|
31176
|
+
setInterval(function () {
|
|
31177
|
+
if (!visionRuntimePreloading) resolve();
|
|
31178
|
+
}, 100);
|
|
31179
|
+
})];
|
|
31180
|
+
visionRuntimePreloading = true;
|
|
31181
|
+
url = "".concat(visionTasksBasePath, "/vision_wasm_internal.wasm");
|
|
31182
|
+
document.addEventListener('idmission.preloadProgress', handleDownloadProgress);
|
|
31183
|
+
_a.label = 1;
|
|
31184
|
+
case 1:
|
|
31185
|
+
_a.trys.push([1,, 3, 4]);
|
|
31186
|
+
return [4 /*yield*/, preloadDependency(url, visionRuntimeHash)];
|
|
31187
|
+
case 2:
|
|
31188
|
+
_a.sent();
|
|
31189
|
+
return [3 /*break*/, 4];
|
|
31190
|
+
case 3:
|
|
31191
|
+
document.removeEventListener('idmission.preloadProgress', handleDownloadProgress);
|
|
31192
|
+
visionRuntimePreloading = false;
|
|
31193
|
+
return [7 /*endfinally*/];
|
|
31194
|
+
case 4:
|
|
31195
|
+
return [2 /*return*/];
|
|
31196
|
+
}
|
|
31197
|
+
});
|
|
31198
|
+
});
|
|
31199
|
+
}
|
|
31200
|
+
|
|
31201
|
+
var VisionRuntime = /*#__PURE__*/Object.freeze({
|
|
31202
|
+
__proto__: null,
|
|
31203
|
+
preloadVisionRuntime: preloadVisionRuntime,
|
|
31204
|
+
visionRuntimeHash: visionRuntimeHash,
|
|
31205
|
+
visionTasksBasePath: visionTasksBasePath,
|
|
31206
|
+
withQuietWasm: withQuietWasm
|
|
31207
|
+
});
|
|
31208
|
+
|
|
31108
31209
|
function _taggedTemplateLiteralLoose(e, t) {
|
|
31109
31210
|
return t || (t = e.slice(0)), e.raw = t, e;
|
|
31110
31211
|
}
|
|
@@ -36513,11 +36614,12 @@
|
|
|
36513
36614
|
verifyMediaPipeDelegate: verifyMediaPipeDelegate
|
|
36514
36615
|
});
|
|
36515
36616
|
|
|
36617
|
+
var RUNTIME$3 = 'mediapipe';
|
|
36516
36618
|
var detector = null;
|
|
36517
36619
|
var detectorSettings = null;
|
|
36518
36620
|
function load$3(_a) {
|
|
36519
36621
|
return __awaiter(this, arguments, void 0, function (_b) {
|
|
36520
|
-
var
|
|
36622
|
+
var delegate, cachedBuffer;
|
|
36521
36623
|
var _this = this;
|
|
36522
36624
|
var modelAssetPath = _b.modelAssetPath,
|
|
36523
36625
|
scoreThreshold = _b.scoreThreshold;
|
|
@@ -36526,11 +36628,11 @@
|
|
|
36526
36628
|
case 0:
|
|
36527
36629
|
if (detector && (detectorSettings === null || detectorSettings === void 0 ? void 0 : detectorSettings.modelAssetPath) === modelAssetPath && (detectorSettings === null || detectorSettings === void 0 ? void 0 : detectorSettings.scoreThreshold) === scoreThreshold) return [2 /*return*/];
|
|
36528
36630
|
close$3();
|
|
36529
|
-
|
|
36631
|
+
delegate = getDelegate(RUNTIME$3);
|
|
36632
|
+
if (delegate === 'NONE') {
|
|
36530
36633
|
throw new Error('No available delegate for document detector.');
|
|
36531
36634
|
}
|
|
36532
36635
|
cachedBuffer = getCachedModelBuffer(modelAssetPath);
|
|
36533
|
-
delegate = modelCapabilities.delegate;
|
|
36534
36636
|
return [4 /*yield*/, withQuietWasm(function () {
|
|
36535
36637
|
return __awaiter(_this, void 0, void 0, function () {
|
|
36536
36638
|
var _a, _b;
|
|
@@ -36639,11 +36741,12 @@
|
|
|
36639
36741
|
testAgainstKnownImage: testAgainstKnownImage
|
|
36640
36742
|
});
|
|
36641
36743
|
|
|
36744
|
+
var RUNTIME$2 = 'mediapipe';
|
|
36642
36745
|
var classifier$1 = null;
|
|
36643
36746
|
var classifierSettings$1 = null;
|
|
36644
36747
|
function load$2(_a) {
|
|
36645
36748
|
return __awaiter(this, arguments, void 0, function (_b) {
|
|
36646
|
-
var
|
|
36749
|
+
var delegate, cachedBuffer;
|
|
36647
36750
|
var _this = this;
|
|
36648
36751
|
var modelAssetPath = _b.modelAssetPath;
|
|
36649
36752
|
return __generator(this, function (_c) {
|
|
@@ -36651,11 +36754,11 @@
|
|
|
36651
36754
|
case 0:
|
|
36652
36755
|
if (classifier$1 && (classifierSettings$1 === null || classifierSettings$1 === void 0 ? void 0 : classifierSettings$1.modelAssetPath) === modelAssetPath) return [2 /*return*/];
|
|
36653
36756
|
close$2();
|
|
36654
|
-
|
|
36757
|
+
delegate = getDelegate(RUNTIME$2);
|
|
36758
|
+
if (delegate === 'NONE') {
|
|
36655
36759
|
throw new Error('No available delegate for focus detector.');
|
|
36656
36760
|
}
|
|
36657
36761
|
cachedBuffer = getCachedModelBuffer(modelAssetPath);
|
|
36658
|
-
delegate = modelCapabilities.delegate;
|
|
36659
36762
|
return [4 /*yield*/, withQuietWasm(function () {
|
|
36660
36763
|
return __awaiter(_this, void 0, void 0, function () {
|
|
36661
36764
|
var _a, _b;
|
|
@@ -36722,6 +36825,7 @@
|
|
|
36722
36825
|
predict: predict$2
|
|
36723
36826
|
});
|
|
36724
36827
|
|
|
36828
|
+
var RUNTIME$1 = 'mediapipe';
|
|
36725
36829
|
var classifier = null;
|
|
36726
36830
|
var classifierSettings = null;
|
|
36727
36831
|
function load$1(_a) {
|
|
@@ -36734,7 +36838,7 @@
|
|
|
36734
36838
|
case 0:
|
|
36735
36839
|
if (classifier && (classifierSettings === null || classifierSettings === void 0 ? void 0 : classifierSettings.modelAssetPath) === modelAssetPath) return [2 /*return*/];
|
|
36736
36840
|
close$1();
|
|
36737
|
-
if (
|
|
36841
|
+
if (getDelegate(RUNTIME$1) === 'NONE') {
|
|
36738
36842
|
throw new Error('No available delegate for barcode readability model.');
|
|
36739
36843
|
}
|
|
36740
36844
|
cachedBuffer = getCachedModelBuffer(modelAssetPath);
|
|
@@ -36806,6 +36910,7 @@
|
|
|
36806
36910
|
predict: predict$1
|
|
36807
36911
|
});
|
|
36808
36912
|
|
|
36913
|
+
var RUNTIME = 'mediapipe';
|
|
36809
36914
|
// MediaPipe canonical face mesh (468-point) indices used to construct the
|
|
36810
36915
|
// BlazeFace-style 6-keypoint Face shape. Order matches FaceDetection.ts:
|
|
36811
36916
|
// [0] right eye [1] left eye [2] nose tip
|
|
@@ -36874,29 +36979,30 @@
|
|
|
36874
36979
|
});
|
|
36875
36980
|
});
|
|
36876
36981
|
}
|
|
36877
|
-
var cachedBuffer, firstError_1;
|
|
36982
|
+
var initialDelegate, cachedBuffer, firstError_1;
|
|
36878
36983
|
var modelAssetPath = _b.modelAssetPath;
|
|
36879
36984
|
return __generator(this, function (_c) {
|
|
36880
36985
|
switch (_c.label) {
|
|
36881
36986
|
case 0:
|
|
36882
36987
|
if (landmarker && (landmarkerSettings === null || landmarkerSettings === void 0 ? void 0 : landmarkerSettings.modelAssetPath) === modelAssetPath) return [2 /*return*/];
|
|
36883
36988
|
close();
|
|
36884
|
-
|
|
36989
|
+
initialDelegate = getDelegate(RUNTIME);
|
|
36990
|
+
if (initialDelegate === 'NONE') {
|
|
36885
36991
|
throw new Error('No available delegate for face landmarker.');
|
|
36886
36992
|
}
|
|
36887
36993
|
cachedBuffer = getCachedModelBuffer(modelAssetPath);
|
|
36888
36994
|
_c.label = 1;
|
|
36889
36995
|
case 1:
|
|
36890
36996
|
_c.trys.push([1, 3,, 7]);
|
|
36891
|
-
return [4 /*yield*/, tryDelegate(
|
|
36997
|
+
return [4 /*yield*/, tryDelegate(initialDelegate)];
|
|
36892
36998
|
case 2:
|
|
36893
36999
|
landmarker = _c.sent();
|
|
36894
37000
|
return [3 /*break*/, 7];
|
|
36895
37001
|
case 3:
|
|
36896
37002
|
firstError_1 = _c.sent();
|
|
36897
|
-
if (!(
|
|
37003
|
+
if (!(initialDelegate === 'GPU')) return [3 /*break*/, 5];
|
|
36898
37004
|
warn('face landmarker failed known-good frame validation on GPU; falling back to CPU', firstError_1);
|
|
36899
|
-
|
|
37005
|
+
setDelegate(RUNTIME, 'CPU');
|
|
36900
37006
|
return [4 /*yield*/, tryDelegate('CPU')];
|
|
36901
37007
|
case 4:
|
|
36902
37008
|
landmarker = _c.sent();
|