@microblink/blinkid-core 7.1.0 → 7.2.1
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/blinkid-core.js +592 -361
- package/dist/blinkid-core.js.map +1 -0
- package/dist/resources/blinkid-worker.js +638 -469
- package/dist/resources/full/advanced/BlinkIdModule.js +2 -2
- package/dist/resources/full/advanced/BlinkIdModule.wasm +0 -0
- package/dist/resources/full/advanced-threads/BlinkIdModule.js +2 -2
- package/dist/resources/full/advanced-threads/BlinkIdModule.wasm +0 -0
- package/dist/resources/full/basic/BlinkIdModule.js +2 -2
- package/dist/resources/full/basic/BlinkIdModule.wasm +0 -0
- package/dist/resources/lightweight/advanced/BlinkIdModule.js +2 -2
- package/dist/resources/lightweight/advanced/BlinkIdModule.wasm +0 -0
- package/dist/resources/lightweight/advanced-threads/BlinkIdModule.js +2 -2
- package/dist/resources/lightweight/advanced-threads/BlinkIdModule.wasm +0 -0
- package/dist/resources/lightweight/basic/BlinkIdModule.js +2 -2
- package/dist/resources/lightweight/basic/BlinkIdModule.wasm +0 -0
- package/package.json +1 -1
- package/types/BlinkIdCore.d.ts.map +1 -1
- package/types/defaultSessionSettings.d.ts +6 -0
- package/types/defaultSessionSettings.d.ts.map +1 -0
- package/types/index.d.ts +1 -0
- package/types/index.d.ts.map +1 -1
- package/types/index.rollup.d.ts +9 -1
package/dist/blinkid-core.js
CHANGED
|
@@ -3,279 +3,380 @@
|
|
|
3
3
|
* Copyright 2019 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
const proxyMarker = Symbol("Comlink.proxy");
|
|
7
|
+
const createEndpoint = Symbol("Comlink.endpoint");
|
|
8
|
+
const releaseProxy = Symbol("Comlink.releaseProxy");
|
|
9
|
+
const finalizer = Symbol("Comlink.finalizer");
|
|
10
|
+
const throwMarker = Symbol("Comlink.thrown");
|
|
11
|
+
const isObject = (val) => typeof val === "object" && val !== null || typeof val === "function";
|
|
12
|
+
const proxyTransferHandler = {
|
|
13
|
+
canHandle: (val) => isObject(val) && val[proxyMarker],
|
|
14
|
+
serialize(obj) {
|
|
15
|
+
const { port1, port2 } = new MessageChannel();
|
|
16
|
+
expose(obj, port1);
|
|
17
|
+
return [port2, [port2]];
|
|
11
18
|
},
|
|
12
|
-
deserialize(
|
|
13
|
-
|
|
19
|
+
deserialize(port) {
|
|
20
|
+
port.start();
|
|
21
|
+
return wrap(port);
|
|
14
22
|
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
};
|
|
24
|
+
const throwTransferHandler = {
|
|
25
|
+
canHandle: (value) => isObject(value) && throwMarker in value,
|
|
26
|
+
serialize({ value }) {
|
|
27
|
+
let serialized;
|
|
28
|
+
if (value instanceof Error) {
|
|
29
|
+
serialized = {
|
|
30
|
+
isError: true,
|
|
31
|
+
value: {
|
|
32
|
+
message: value.message,
|
|
33
|
+
name: value.name,
|
|
34
|
+
stack: value.stack
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
} else {
|
|
38
|
+
serialized = { isError: false, value };
|
|
39
|
+
}
|
|
40
|
+
return [serialized, []];
|
|
27
41
|
},
|
|
28
|
-
deserialize(
|
|
29
|
-
|
|
42
|
+
deserialize(serialized) {
|
|
43
|
+
if (serialized.isError) {
|
|
44
|
+
throw Object.assign(new Error(serialized.value.message), serialized.value);
|
|
45
|
+
}
|
|
46
|
+
throw serialized.value;
|
|
30
47
|
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
["
|
|
48
|
+
};
|
|
49
|
+
const transferHandlers = /* @__PURE__ */ new Map([
|
|
50
|
+
["proxy", proxyTransferHandler],
|
|
51
|
+
["throw", throwTransferHandler]
|
|
34
52
|
]);
|
|
35
|
-
function
|
|
36
|
-
for (const
|
|
37
|
-
if (
|
|
38
|
-
return
|
|
39
|
-
|
|
53
|
+
function isAllowedOrigin(allowedOrigins, origin) {
|
|
54
|
+
for (const allowedOrigin of allowedOrigins) {
|
|
55
|
+
if (origin === allowedOrigin || allowedOrigin === "*") {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
if (allowedOrigin instanceof RegExp && allowedOrigin.test(origin)) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
40
63
|
}
|
|
41
|
-
function
|
|
42
|
-
|
|
43
|
-
if (!
|
|
64
|
+
function expose(obj, ep = globalThis, allowedOrigins = ["*"]) {
|
|
65
|
+
ep.addEventListener("message", function callback(ev) {
|
|
66
|
+
if (!ev || !ev.data) {
|
|
44
67
|
return;
|
|
45
|
-
|
|
46
|
-
|
|
68
|
+
}
|
|
69
|
+
if (!isAllowedOrigin(allowedOrigins, ev.origin)) {
|
|
70
|
+
console.warn(`Invalid origin '${ev.origin}' for comlink proxy`);
|
|
47
71
|
return;
|
|
48
72
|
}
|
|
49
|
-
const { id
|
|
50
|
-
|
|
73
|
+
const { id, type: type2, path } = Object.assign({ path: [] }, ev.data);
|
|
74
|
+
const argumentList = (ev.data.argumentList || []).map(fromWireValue);
|
|
75
|
+
let returnValue;
|
|
51
76
|
try {
|
|
52
|
-
const
|
|
53
|
-
|
|
77
|
+
const parent = path.slice(0, -1).reduce((obj2, prop) => obj2[prop], obj);
|
|
78
|
+
const rawValue = path.reduce((obj2, prop) => obj2[prop], obj);
|
|
79
|
+
switch (type2) {
|
|
54
80
|
case "GET":
|
|
55
|
-
|
|
81
|
+
{
|
|
82
|
+
returnValue = rawValue;
|
|
83
|
+
}
|
|
56
84
|
break;
|
|
57
85
|
case "SET":
|
|
58
|
-
|
|
86
|
+
{
|
|
87
|
+
parent[path.slice(-1)[0]] = fromWireValue(ev.data.value);
|
|
88
|
+
returnValue = true;
|
|
89
|
+
}
|
|
59
90
|
break;
|
|
60
91
|
case "APPLY":
|
|
61
|
-
|
|
92
|
+
{
|
|
93
|
+
returnValue = rawValue.apply(parent, argumentList);
|
|
94
|
+
}
|
|
62
95
|
break;
|
|
63
96
|
case "CONSTRUCT":
|
|
64
97
|
{
|
|
65
|
-
const
|
|
66
|
-
|
|
98
|
+
const value = new rawValue(...argumentList);
|
|
99
|
+
returnValue = proxy(value);
|
|
67
100
|
}
|
|
68
101
|
break;
|
|
69
102
|
case "ENDPOINT":
|
|
70
103
|
{
|
|
71
|
-
const { port1
|
|
72
|
-
|
|
104
|
+
const { port1, port2 } = new MessageChannel();
|
|
105
|
+
expose(obj, port2);
|
|
106
|
+
returnValue = transfer(port1, [port1]);
|
|
73
107
|
}
|
|
74
108
|
break;
|
|
75
109
|
case "RELEASE":
|
|
76
|
-
|
|
110
|
+
{
|
|
111
|
+
returnValue = void 0;
|
|
112
|
+
}
|
|
77
113
|
break;
|
|
78
114
|
default:
|
|
79
115
|
return;
|
|
80
116
|
}
|
|
81
|
-
} catch (
|
|
82
|
-
|
|
117
|
+
} catch (value) {
|
|
118
|
+
returnValue = { value, [throwMarker]: 0 };
|
|
83
119
|
}
|
|
84
|
-
Promise.resolve(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
120
|
+
Promise.resolve(returnValue).catch((value) => {
|
|
121
|
+
return { value, [throwMarker]: 0 };
|
|
122
|
+
}).then((returnValue2) => {
|
|
123
|
+
const [wireValue, transferables] = toWireValue(returnValue2);
|
|
124
|
+
ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);
|
|
125
|
+
if (type2 === "RELEASE") {
|
|
126
|
+
ep.removeEventListener("message", callback);
|
|
127
|
+
closeEndPoint(ep);
|
|
128
|
+
if (finalizer in obj && typeof obj[finalizer] === "function") {
|
|
129
|
+
obj[finalizer]();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}).catch((error) => {
|
|
133
|
+
const [wireValue, transferables] = toWireValue({
|
|
89
134
|
value: new TypeError("Unserializable return value"),
|
|
90
|
-
[
|
|
135
|
+
[throwMarker]: 0
|
|
91
136
|
});
|
|
92
|
-
|
|
137
|
+
ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);
|
|
93
138
|
});
|
|
94
|
-
})
|
|
139
|
+
});
|
|
140
|
+
if (ep.start) {
|
|
141
|
+
ep.start();
|
|
142
|
+
}
|
|
95
143
|
}
|
|
96
|
-
function
|
|
97
|
-
return
|
|
144
|
+
function isMessagePort(endpoint) {
|
|
145
|
+
return endpoint.constructor.name === "MessagePort";
|
|
98
146
|
}
|
|
99
|
-
function
|
|
100
|
-
|
|
147
|
+
function closeEndPoint(endpoint) {
|
|
148
|
+
if (isMessagePort(endpoint))
|
|
149
|
+
endpoint.close();
|
|
101
150
|
}
|
|
102
|
-
function
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
const { data
|
|
106
|
-
if (!
|
|
151
|
+
function wrap(ep, target) {
|
|
152
|
+
const pendingListeners = /* @__PURE__ */ new Map();
|
|
153
|
+
ep.addEventListener("message", function handleMessage(ev) {
|
|
154
|
+
const { data } = ev;
|
|
155
|
+
if (!data || !data.id) {
|
|
107
156
|
return;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
157
|
+
}
|
|
158
|
+
const resolver = pendingListeners.get(data.id);
|
|
159
|
+
if (!resolver) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
try {
|
|
163
|
+
resolver(data);
|
|
164
|
+
} finally {
|
|
165
|
+
pendingListeners.delete(data.id);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
return createProxy(ep, pendingListeners, [], target);
|
|
116
169
|
}
|
|
117
|
-
function
|
|
118
|
-
if (
|
|
170
|
+
function throwIfProxyReleased(isReleased) {
|
|
171
|
+
if (isReleased) {
|
|
119
172
|
throw new Error("Proxy has been released and is not useable");
|
|
173
|
+
}
|
|
120
174
|
}
|
|
121
|
-
function
|
|
122
|
-
return
|
|
175
|
+
function releaseEndpoint(ep) {
|
|
176
|
+
return requestResponseMessage(ep, /* @__PURE__ */ new Map(), {
|
|
123
177
|
type: "RELEASE"
|
|
124
178
|
}).then(() => {
|
|
125
|
-
|
|
179
|
+
closeEndPoint(ep);
|
|
126
180
|
});
|
|
127
181
|
}
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
182
|
+
const proxyCounter = /* @__PURE__ */ new WeakMap();
|
|
183
|
+
const proxyFinalizers = "FinalizationRegistry" in globalThis && new FinalizationRegistry((ep) => {
|
|
184
|
+
const newCount = (proxyCounter.get(ep) || 0) - 1;
|
|
185
|
+
proxyCounter.set(ep, newCount);
|
|
186
|
+
if (newCount === 0) {
|
|
187
|
+
releaseEndpoint(ep);
|
|
188
|
+
}
|
|
131
189
|
});
|
|
132
|
-
function
|
|
133
|
-
const
|
|
134
|
-
|
|
190
|
+
function registerProxy(proxy2, ep) {
|
|
191
|
+
const newCount = (proxyCounter.get(ep) || 0) + 1;
|
|
192
|
+
proxyCounter.set(ep, newCount);
|
|
193
|
+
if (proxyFinalizers) {
|
|
194
|
+
proxyFinalizers.register(proxy2, ep, proxy2);
|
|
195
|
+
}
|
|
135
196
|
}
|
|
136
|
-
function
|
|
137
|
-
|
|
197
|
+
function unregisterProxy(proxy2) {
|
|
198
|
+
if (proxyFinalizers) {
|
|
199
|
+
proxyFinalizers.unregister(proxy2);
|
|
200
|
+
}
|
|
138
201
|
}
|
|
139
|
-
function
|
|
202
|
+
function createProxy(ep, pendingListeners, path = [], target = function() {
|
|
140
203
|
}) {
|
|
141
|
-
let
|
|
142
|
-
const
|
|
143
|
-
get(
|
|
144
|
-
|
|
204
|
+
let isProxyReleased = false;
|
|
205
|
+
const proxy2 = new Proxy(target, {
|
|
206
|
+
get(_target, prop) {
|
|
207
|
+
throwIfProxyReleased(isProxyReleased);
|
|
208
|
+
if (prop === releaseProxy) {
|
|
145
209
|
return () => {
|
|
146
|
-
|
|
210
|
+
unregisterProxy(proxy2);
|
|
211
|
+
releaseEndpoint(ep);
|
|
212
|
+
pendingListeners.clear();
|
|
213
|
+
isProxyReleased = true;
|
|
147
214
|
};
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
215
|
+
}
|
|
216
|
+
if (prop === "then") {
|
|
217
|
+
if (path.length === 0) {
|
|
218
|
+
return { then: () => proxy2 };
|
|
219
|
+
}
|
|
220
|
+
const r = requestResponseMessage(ep, pendingListeners, {
|
|
152
221
|
type: "GET",
|
|
153
|
-
path:
|
|
154
|
-
}).then(
|
|
155
|
-
return
|
|
222
|
+
path: path.map((p) => p.toString())
|
|
223
|
+
}).then(fromWireValue);
|
|
224
|
+
return r.then.bind(r);
|
|
156
225
|
}
|
|
157
|
-
return
|
|
226
|
+
return createProxy(ep, pendingListeners, [...path, prop]);
|
|
158
227
|
},
|
|
159
|
-
set(
|
|
160
|
-
|
|
161
|
-
const [
|
|
162
|
-
return
|
|
228
|
+
set(_target, prop, rawValue) {
|
|
229
|
+
throwIfProxyReleased(isProxyReleased);
|
|
230
|
+
const [value, transferables] = toWireValue(rawValue);
|
|
231
|
+
return requestResponseMessage(ep, pendingListeners, {
|
|
163
232
|
type: "SET",
|
|
164
|
-
path: [...
|
|
165
|
-
value
|
|
166
|
-
},
|
|
233
|
+
path: [...path, prop].map((p) => p.toString()),
|
|
234
|
+
value
|
|
235
|
+
}, transferables).then(fromWireValue);
|
|
167
236
|
},
|
|
168
|
-
apply(
|
|
169
|
-
|
|
170
|
-
const
|
|
171
|
-
if (
|
|
172
|
-
return
|
|
237
|
+
apply(_target, _thisArg, rawArgumentList) {
|
|
238
|
+
throwIfProxyReleased(isProxyReleased);
|
|
239
|
+
const last = path[path.length - 1];
|
|
240
|
+
if (last === createEndpoint) {
|
|
241
|
+
return requestResponseMessage(ep, pendingListeners, {
|
|
173
242
|
type: "ENDPOINT"
|
|
174
|
-
}).then(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
243
|
+
}).then(fromWireValue);
|
|
244
|
+
}
|
|
245
|
+
if (last === "bind") {
|
|
246
|
+
return createProxy(ep, pendingListeners, path.slice(0, -1));
|
|
247
|
+
}
|
|
248
|
+
const [argumentList, transferables] = processArguments(rawArgumentList);
|
|
249
|
+
return requestResponseMessage(ep, pendingListeners, {
|
|
179
250
|
type: "APPLY",
|
|
180
|
-
path:
|
|
181
|
-
argumentList
|
|
182
|
-
},
|
|
251
|
+
path: path.map((p) => p.toString()),
|
|
252
|
+
argumentList
|
|
253
|
+
}, transferables).then(fromWireValue);
|
|
183
254
|
},
|
|
184
|
-
construct(
|
|
185
|
-
|
|
186
|
-
const [
|
|
187
|
-
return
|
|
255
|
+
construct(_target, rawArgumentList) {
|
|
256
|
+
throwIfProxyReleased(isProxyReleased);
|
|
257
|
+
const [argumentList, transferables] = processArguments(rawArgumentList);
|
|
258
|
+
return requestResponseMessage(ep, pendingListeners, {
|
|
188
259
|
type: "CONSTRUCT",
|
|
189
|
-
path:
|
|
190
|
-
argumentList
|
|
191
|
-
},
|
|
260
|
+
path: path.map((p) => p.toString()),
|
|
261
|
+
argumentList
|
|
262
|
+
}, transferables).then(fromWireValue);
|
|
192
263
|
}
|
|
193
264
|
});
|
|
194
|
-
|
|
265
|
+
registerProxy(proxy2, ep);
|
|
266
|
+
return proxy2;
|
|
195
267
|
}
|
|
196
|
-
function
|
|
197
|
-
return Array.prototype.concat.apply([],
|
|
268
|
+
function myFlat(arr) {
|
|
269
|
+
return Array.prototype.concat.apply([], arr);
|
|
198
270
|
}
|
|
199
|
-
function
|
|
200
|
-
const
|
|
201
|
-
return [
|
|
271
|
+
function processArguments(argumentList) {
|
|
272
|
+
const processed = argumentList.map(toWireValue);
|
|
273
|
+
return [processed.map((v) => v[0]), myFlat(processed.map((v) => v[1]))];
|
|
202
274
|
}
|
|
203
|
-
const
|
|
204
|
-
function
|
|
205
|
-
|
|
275
|
+
const transferCache = /* @__PURE__ */ new WeakMap();
|
|
276
|
+
function transfer(obj, transfers) {
|
|
277
|
+
transferCache.set(obj, transfers);
|
|
278
|
+
return obj;
|
|
206
279
|
}
|
|
207
|
-
function
|
|
208
|
-
return Object.assign(
|
|
280
|
+
function proxy(obj) {
|
|
281
|
+
return Object.assign(obj, { [proxyMarker]: true });
|
|
209
282
|
}
|
|
210
|
-
function
|
|
211
|
-
for (const [
|
|
212
|
-
if (
|
|
213
|
-
const [
|
|
283
|
+
function toWireValue(value) {
|
|
284
|
+
for (const [name, handler] of transferHandlers) {
|
|
285
|
+
if (handler.canHandle(value)) {
|
|
286
|
+
const [serializedValue, transferables] = handler.serialize(value);
|
|
214
287
|
return [
|
|
215
288
|
{
|
|
216
289
|
type: "HANDLER",
|
|
217
|
-
name
|
|
218
|
-
value:
|
|
290
|
+
name,
|
|
291
|
+
value: serializedValue
|
|
219
292
|
},
|
|
220
|
-
|
|
293
|
+
transferables
|
|
221
294
|
];
|
|
222
295
|
}
|
|
296
|
+
}
|
|
223
297
|
return [
|
|
224
298
|
{
|
|
225
299
|
type: "RAW",
|
|
226
|
-
value
|
|
300
|
+
value
|
|
227
301
|
},
|
|
228
|
-
|
|
302
|
+
transferCache.get(value) || []
|
|
229
303
|
];
|
|
230
304
|
}
|
|
231
|
-
function
|
|
232
|
-
switch (
|
|
305
|
+
function fromWireValue(value) {
|
|
306
|
+
switch (value.type) {
|
|
233
307
|
case "HANDLER":
|
|
234
|
-
return
|
|
308
|
+
return transferHandlers.get(value.name).deserialize(value.value);
|
|
235
309
|
case "RAW":
|
|
236
|
-
return
|
|
310
|
+
return value.value;
|
|
237
311
|
}
|
|
238
312
|
}
|
|
239
|
-
function
|
|
240
|
-
return new Promise((
|
|
241
|
-
const
|
|
242
|
-
|
|
313
|
+
function requestResponseMessage(ep, pendingListeners, msg, transfers) {
|
|
314
|
+
return new Promise((resolve) => {
|
|
315
|
+
const id = generateUUID();
|
|
316
|
+
pendingListeners.set(id, resolve);
|
|
317
|
+
if (ep.start) {
|
|
318
|
+
ep.start();
|
|
319
|
+
}
|
|
320
|
+
ep.postMessage(Object.assign({ id }, msg), transfers);
|
|
243
321
|
});
|
|
244
322
|
}
|
|
245
|
-
function
|
|
323
|
+
function generateUUID() {
|
|
246
324
|
return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
|
|
247
325
|
}
|
|
248
|
-
var
|
|
249
|
-
function
|
|
250
|
-
for (var
|
|
251
|
-
var
|
|
252
|
-
|
|
326
|
+
var _createClass = /* @__PURE__ */ function() {
|
|
327
|
+
function defineProperties(target, props) {
|
|
328
|
+
for (var i = 0; i < props.length; i++) {
|
|
329
|
+
var descriptor = props[i];
|
|
330
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
331
|
+
descriptor.configurable = true;
|
|
332
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
333
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
253
334
|
}
|
|
254
335
|
}
|
|
255
|
-
return function(
|
|
256
|
-
|
|
336
|
+
return function(Constructor, protoProps, staticProps) {
|
|
337
|
+
if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
|
338
|
+
if (staticProps) defineProperties(Constructor, staticProps);
|
|
339
|
+
return Constructor;
|
|
257
340
|
};
|
|
258
|
-
}()
|
|
259
|
-
|
|
260
|
-
|
|
341
|
+
}();
|
|
342
|
+
var _templateObject = _taggedTemplateLiteral(["", ""], ["", ""]);
|
|
343
|
+
function _taggedTemplateLiteral(strings, raw) {
|
|
344
|
+
return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } }));
|
|
261
345
|
}
|
|
262
|
-
function
|
|
263
|
-
if (!(
|
|
346
|
+
function _classCallCheck(instance, Constructor) {
|
|
347
|
+
if (!(instance instanceof Constructor)) {
|
|
264
348
|
throw new TypeError("Cannot call a class as a function");
|
|
349
|
+
}
|
|
265
350
|
}
|
|
266
|
-
var
|
|
267
|
-
function
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
351
|
+
var TemplateTag = function() {
|
|
352
|
+
function TemplateTag2() {
|
|
353
|
+
var _this = this;
|
|
354
|
+
for (var _len = arguments.length, transformers = Array(_len), _key = 0; _key < _len; _key++) {
|
|
355
|
+
transformers[_key] = arguments[_key];
|
|
356
|
+
}
|
|
357
|
+
_classCallCheck(this, TemplateTag2);
|
|
358
|
+
this.tag = function(strings) {
|
|
359
|
+
for (var _len2 = arguments.length, expressions = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
360
|
+
expressions[_key2 - 1] = arguments[_key2];
|
|
361
|
+
}
|
|
362
|
+
if (typeof strings === "function") {
|
|
363
|
+
return _this.interimTag.bind(_this, strings);
|
|
364
|
+
}
|
|
365
|
+
if (typeof strings === "string") {
|
|
366
|
+
return _this.transformEndResult(strings);
|
|
367
|
+
}
|
|
368
|
+
strings = strings.map(_this.transformString.bind(_this));
|
|
369
|
+
return _this.transformEndResult(strings.reduce(_this.processSubstitutions.bind(_this, expressions)));
|
|
370
|
+
};
|
|
371
|
+
if (transformers.length > 0 && Array.isArray(transformers[0])) {
|
|
372
|
+
transformers = transformers[0];
|
|
373
|
+
}
|
|
374
|
+
this.transformers = transformers.map(function(transformer) {
|
|
375
|
+
return typeof transformer === "function" ? transformer() : transformer;
|
|
376
|
+
});
|
|
377
|
+
return this.tag;
|
|
277
378
|
}
|
|
278
|
-
|
|
379
|
+
_createClass(TemplateTag2, [{
|
|
279
380
|
key: "interimTag",
|
|
280
381
|
/**
|
|
281
382
|
* An intermediary template tag that receives a template tag and passes the result of calling the template with the received
|
|
@@ -285,10 +386,11 @@ var m = function() {
|
|
|
285
386
|
* @param {...*} ...substitutions - `substitutions` is an array of all substitutions in the template
|
|
286
387
|
* @return {*} - the final processed value
|
|
287
388
|
*/
|
|
288
|
-
value: function(
|
|
289
|
-
for (var
|
|
290
|
-
|
|
291
|
-
|
|
389
|
+
value: function interimTag(previousTag, template) {
|
|
390
|
+
for (var _len3 = arguments.length, substitutions = Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
391
|
+
substitutions[_key3 - 2] = arguments[_key3];
|
|
392
|
+
}
|
|
393
|
+
return this.tag(_templateObject, previousTag.apply(void 0, [template].concat(substitutions)));
|
|
292
394
|
}
|
|
293
395
|
/**
|
|
294
396
|
* Performs bulk processing on the tagged template, transforming each substitution and then
|
|
@@ -300,9 +402,9 @@ var m = function() {
|
|
|
300
402
|
*/
|
|
301
403
|
}, {
|
|
302
404
|
key: "processSubstitutions",
|
|
303
|
-
value: function(
|
|
304
|
-
var
|
|
305
|
-
return "".concat(
|
|
405
|
+
value: function processSubstitutions(substitutions, resultSoFar, remainingPart) {
|
|
406
|
+
var substitution = this.transformSubstitution(substitutions.shift(), resultSoFar);
|
|
407
|
+
return "".concat(resultSoFar, substitution, remainingPart);
|
|
306
408
|
}
|
|
307
409
|
/**
|
|
308
410
|
* Iterate through each transformer, applying the transformer's `onString` method to the template
|
|
@@ -312,11 +414,11 @@ var m = function() {
|
|
|
312
414
|
*/
|
|
313
415
|
}, {
|
|
314
416
|
key: "transformString",
|
|
315
|
-
value: function(
|
|
316
|
-
var
|
|
317
|
-
return
|
|
417
|
+
value: function transformString(str) {
|
|
418
|
+
var cb = function cb2(res, transform) {
|
|
419
|
+
return transform.onString ? transform.onString(res) : res;
|
|
318
420
|
};
|
|
319
|
-
return this.transformers.reduce(
|
|
421
|
+
return this.transformers.reduce(cb, str);
|
|
320
422
|
}
|
|
321
423
|
/**
|
|
322
424
|
* When a substitution is encountered, iterates through each transformer and applies the transformer's
|
|
@@ -327,11 +429,11 @@ var m = function() {
|
|
|
327
429
|
*/
|
|
328
430
|
}, {
|
|
329
431
|
key: "transformSubstitution",
|
|
330
|
-
value: function(
|
|
331
|
-
var
|
|
332
|
-
return
|
|
432
|
+
value: function transformSubstitution(substitution, resultSoFar) {
|
|
433
|
+
var cb = function cb2(res, transform) {
|
|
434
|
+
return transform.onSubstitution ? transform.onSubstitution(res, resultSoFar) : res;
|
|
333
435
|
};
|
|
334
|
-
return this.transformers.reduce(
|
|
436
|
+
return this.transformers.reduce(cb, substitution);
|
|
335
437
|
}
|
|
336
438
|
/**
|
|
337
439
|
* Iterates through each transformer, applying the transformer's `onEndResult` method to the
|
|
@@ -341,240 +443,369 @@ var m = function() {
|
|
|
341
443
|
*/
|
|
342
444
|
}, {
|
|
343
445
|
key: "transformEndResult",
|
|
344
|
-
value: function(
|
|
345
|
-
var
|
|
346
|
-
return
|
|
446
|
+
value: function transformEndResult(endResult) {
|
|
447
|
+
var cb = function cb2(res, transform) {
|
|
448
|
+
return transform.onEndResult ? transform.onEndResult(res) : res;
|
|
347
449
|
};
|
|
348
|
-
return this.transformers.reduce(
|
|
450
|
+
return this.transformers.reduce(cb, endResult);
|
|
349
451
|
}
|
|
350
|
-
}])
|
|
351
|
-
|
|
352
|
-
|
|
452
|
+
}]);
|
|
453
|
+
return TemplateTag2;
|
|
454
|
+
}();
|
|
455
|
+
var trimResultTransformer = function trimResultTransformer2() {
|
|
456
|
+
var side = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "";
|
|
353
457
|
return {
|
|
354
|
-
onEndResult: function(
|
|
355
|
-
if (
|
|
356
|
-
return
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
if (
|
|
360
|
-
return
|
|
361
|
-
|
|
458
|
+
onEndResult: function onEndResult(endResult) {
|
|
459
|
+
if (side === "") {
|
|
460
|
+
return endResult.trim();
|
|
461
|
+
}
|
|
462
|
+
side = side.toLowerCase();
|
|
463
|
+
if (side === "start" || side === "left") {
|
|
464
|
+
return endResult.replace(/^\s*/, "");
|
|
465
|
+
}
|
|
466
|
+
if (side === "end" || side === "right") {
|
|
467
|
+
return endResult.replace(/\s*$/, "");
|
|
468
|
+
}
|
|
469
|
+
throw new Error("Side not supported: " + side);
|
|
362
470
|
}
|
|
363
471
|
};
|
|
364
472
|
};
|
|
365
|
-
function
|
|
366
|
-
if (Array.isArray(
|
|
367
|
-
for (var
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
473
|
+
function _toConsumableArray(arr) {
|
|
474
|
+
if (Array.isArray(arr)) {
|
|
475
|
+
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {
|
|
476
|
+
arr2[i] = arr[i];
|
|
477
|
+
}
|
|
478
|
+
return arr2;
|
|
479
|
+
} else {
|
|
480
|
+
return Array.from(arr);
|
|
481
|
+
}
|
|
372
482
|
}
|
|
373
|
-
var
|
|
374
|
-
var
|
|
483
|
+
var stripIndentTransformer = function stripIndentTransformer2() {
|
|
484
|
+
var type2 = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "initial";
|
|
375
485
|
return {
|
|
376
|
-
onEndResult: function(
|
|
377
|
-
if (
|
|
378
|
-
var
|
|
379
|
-
|
|
486
|
+
onEndResult: function onEndResult(endResult) {
|
|
487
|
+
if (type2 === "initial") {
|
|
488
|
+
var match = endResult.match(/^[^\S\n]*(?=\S)/gm);
|
|
489
|
+
var indent = match && Math.min.apply(Math, _toConsumableArray(match.map(function(el) {
|
|
490
|
+
return el.length;
|
|
380
491
|
})));
|
|
381
|
-
if (
|
|
382
|
-
var
|
|
383
|
-
return
|
|
492
|
+
if (indent) {
|
|
493
|
+
var regexp = new RegExp("^.{" + indent + "}", "gm");
|
|
494
|
+
return endResult.replace(regexp, "");
|
|
384
495
|
}
|
|
385
|
-
return
|
|
496
|
+
return endResult;
|
|
497
|
+
}
|
|
498
|
+
if (type2 === "all") {
|
|
499
|
+
return endResult.replace(/^[^\S\n]+/gm, "");
|
|
386
500
|
}
|
|
387
|
-
|
|
388
|
-
return n.replace(/^[^\S\n]+/gm, "");
|
|
389
|
-
throw new Error("Unknown type: " + r);
|
|
501
|
+
throw new Error("Unknown type: " + type2);
|
|
390
502
|
}
|
|
391
503
|
};
|
|
392
|
-
}
|
|
504
|
+
};
|
|
505
|
+
var replaceResultTransformer = function replaceResultTransformer2(replaceWhat, replaceWith) {
|
|
393
506
|
return {
|
|
394
|
-
onEndResult: function(
|
|
395
|
-
if (
|
|
507
|
+
onEndResult: function onEndResult(endResult) {
|
|
508
|
+
if (replaceWhat == null || replaceWith == null) {
|
|
396
509
|
throw new Error("replaceResultTransformer requires at least 2 arguments.");
|
|
397
|
-
|
|
510
|
+
}
|
|
511
|
+
return endResult.replace(replaceWhat, replaceWith);
|
|
398
512
|
}
|
|
399
513
|
};
|
|
400
|
-
}
|
|
514
|
+
};
|
|
515
|
+
var replaceSubstitutionTransformer = function replaceSubstitutionTransformer2(replaceWhat, replaceWith) {
|
|
401
516
|
return {
|
|
402
|
-
onSubstitution: function(
|
|
403
|
-
if (
|
|
517
|
+
onSubstitution: function onSubstitution(substitution, resultSoFar) {
|
|
518
|
+
if (replaceWhat == null || replaceWith == null) {
|
|
404
519
|
throw new Error("replaceSubstitutionTransformer requires at least 2 arguments.");
|
|
405
|
-
|
|
520
|
+
}
|
|
521
|
+
if (substitution == null) {
|
|
522
|
+
return substitution;
|
|
523
|
+
} else {
|
|
524
|
+
return substitution.toString().replace(replaceWhat, replaceWith);
|
|
525
|
+
}
|
|
406
526
|
}
|
|
407
527
|
};
|
|
408
|
-
}
|
|
528
|
+
};
|
|
529
|
+
var defaults = {
|
|
409
530
|
separator: "",
|
|
410
531
|
conjunction: "",
|
|
411
|
-
serial:
|
|
412
|
-
}
|
|
413
|
-
|
|
532
|
+
serial: false
|
|
533
|
+
};
|
|
534
|
+
var inlineArrayTransformer = function inlineArrayTransformer2() {
|
|
535
|
+
var opts = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : defaults;
|
|
414
536
|
return {
|
|
415
|
-
onSubstitution: function(
|
|
416
|
-
if (Array.isArray(
|
|
417
|
-
var
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
537
|
+
onSubstitution: function onSubstitution(substitution, resultSoFar) {
|
|
538
|
+
if (Array.isArray(substitution)) {
|
|
539
|
+
var arrayLength = substitution.length;
|
|
540
|
+
var separator = opts.separator;
|
|
541
|
+
var conjunction = opts.conjunction;
|
|
542
|
+
var serial = opts.serial;
|
|
543
|
+
var indent = resultSoFar.match(/(\n?[^\S\n]+)$/);
|
|
544
|
+
if (indent) {
|
|
545
|
+
substitution = substitution.join(separator + indent[1]);
|
|
546
|
+
} else {
|
|
547
|
+
substitution = substitution.join(separator + " ");
|
|
548
|
+
}
|
|
549
|
+
if (conjunction && arrayLength > 1) {
|
|
550
|
+
var separatorIndex = substitution.lastIndexOf(separator);
|
|
551
|
+
substitution = substitution.slice(0, separatorIndex) + (serial ? separator : "") + " " + conjunction + substitution.slice(separatorIndex + 1);
|
|
421
552
|
}
|
|
422
553
|
}
|
|
423
|
-
return
|
|
554
|
+
return substitution;
|
|
424
555
|
}
|
|
425
556
|
};
|
|
426
|
-
}
|
|
557
|
+
};
|
|
558
|
+
var splitStringTransformer = function splitStringTransformer2(splitBy) {
|
|
427
559
|
return {
|
|
428
|
-
onSubstitution: function(
|
|
429
|
-
|
|
560
|
+
onSubstitution: function onSubstitution(substitution, resultSoFar) {
|
|
561
|
+
{
|
|
562
|
+
if (typeof substitution === "string" && substitution.includes(splitBy)) {
|
|
563
|
+
substitution = substitution.split(splitBy);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
return substitution;
|
|
430
567
|
}
|
|
431
568
|
};
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
|
|
569
|
+
};
|
|
570
|
+
var isValidValue = function isValidValue2(x) {
|
|
571
|
+
return x != null && !Number.isNaN(x) && typeof x !== "boolean";
|
|
572
|
+
};
|
|
573
|
+
var removeNonPrintingValuesTransformer = function removeNonPrintingValuesTransformer2() {
|
|
435
574
|
return {
|
|
436
|
-
onSubstitution: function(
|
|
437
|
-
|
|
575
|
+
onSubstitution: function onSubstitution(substitution) {
|
|
576
|
+
if (Array.isArray(substitution)) {
|
|
577
|
+
return substitution.filter(isValidValue);
|
|
578
|
+
}
|
|
579
|
+
if (isValidValue(substitution)) {
|
|
580
|
+
return substitution;
|
|
581
|
+
}
|
|
582
|
+
return "";
|
|
438
583
|
}
|
|
439
584
|
};
|
|
440
585
|
};
|
|
441
|
-
new
|
|
442
|
-
new
|
|
443
|
-
new
|
|
444
|
-
new
|
|
445
|
-
|
|
446
|
-
new
|
|
447
|
-
|
|
448
|
-
new
|
|
449
|
-
|
|
450
|
-
new
|
|
451
|
-
new
|
|
452
|
-
new
|
|
453
|
-
new
|
|
454
|
-
new
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
const
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
...r
|
|
586
|
+
new TemplateTag(inlineArrayTransformer({ separator: "," }), stripIndentTransformer, trimResultTransformer);
|
|
587
|
+
new TemplateTag(inlineArrayTransformer({ separator: ",", conjunction: "and" }), stripIndentTransformer, trimResultTransformer);
|
|
588
|
+
new TemplateTag(inlineArrayTransformer({ separator: ",", conjunction: "or" }), stripIndentTransformer, trimResultTransformer);
|
|
589
|
+
new TemplateTag(splitStringTransformer("\n"), removeNonPrintingValuesTransformer, inlineArrayTransformer, stripIndentTransformer, trimResultTransformer);
|
|
590
|
+
new TemplateTag(splitStringTransformer("\n"), inlineArrayTransformer, stripIndentTransformer, trimResultTransformer, replaceSubstitutionTransformer(/&/g, "&"), replaceSubstitutionTransformer(/</g, "<"), replaceSubstitutionTransformer(/>/g, ">"), replaceSubstitutionTransformer(/"/g, """), replaceSubstitutionTransformer(/'/g, "'"), replaceSubstitutionTransformer(/`/g, "`"));
|
|
591
|
+
new TemplateTag(replaceResultTransformer(/(?:\n(?:\s*))+/g, " "), trimResultTransformer);
|
|
592
|
+
var oneLineTrim = new TemplateTag(replaceResultTransformer(/(?:\n\s*)/g, ""), trimResultTransformer);
|
|
593
|
+
new TemplateTag(inlineArrayTransformer({ separator: "," }), replaceResultTransformer(/(?:\s+)/g, " "), trimResultTransformer);
|
|
594
|
+
new TemplateTag(inlineArrayTransformer({ separator: ",", conjunction: "or" }), replaceResultTransformer(/(?:\s+)/g, " "), trimResultTransformer);
|
|
595
|
+
new TemplateTag(inlineArrayTransformer({ separator: ",", conjunction: "and" }), replaceResultTransformer(/(?:\s+)/g, " "), trimResultTransformer);
|
|
596
|
+
new TemplateTag(inlineArrayTransformer, stripIndentTransformer, trimResultTransformer);
|
|
597
|
+
new TemplateTag(inlineArrayTransformer, replaceResultTransformer(/(?:\s+)/g, " "), trimResultTransformer);
|
|
598
|
+
new TemplateTag(stripIndentTransformer, trimResultTransformer);
|
|
599
|
+
var stripIndents = new TemplateTag(stripIndentTransformer("all"), trimResultTransformer);
|
|
600
|
+
const type = "application/javascript";
|
|
601
|
+
const getCrossOriginWorkerURL = (originalWorkerUrl, _options = {}) => {
|
|
602
|
+
const options = {
|
|
603
|
+
skipSameOrigin: true,
|
|
604
|
+
useBlob: true,
|
|
605
|
+
..._options
|
|
462
606
|
};
|
|
463
|
-
if (
|
|
464
|
-
return Promise.resolve(
|
|
465
|
-
|
|
607
|
+
if (options.skipSameOrigin && new URL(originalWorkerUrl).origin === self.location.origin) {
|
|
608
|
+
return Promise.resolve(originalWorkerUrl);
|
|
609
|
+
}
|
|
610
|
+
let signal;
|
|
466
611
|
try {
|
|
467
|
-
const
|
|
468
|
-
|
|
469
|
-
const
|
|
470
|
-
|
|
471
|
-
}, 3e3)
|
|
472
|
-
|
|
612
|
+
const controller = new AbortController();
|
|
613
|
+
signal = controller.signal;
|
|
614
|
+
const timeout = setTimeout(() => {
|
|
615
|
+
controller.abort();
|
|
616
|
+
}, 3e3);
|
|
617
|
+
const cleanup = () => {
|
|
618
|
+
clearTimeout(timeout);
|
|
619
|
+
controller.abort();
|
|
473
620
|
};
|
|
474
|
-
|
|
475
|
-
} catch {
|
|
621
|
+
signal.addEventListener("abort", cleanup);
|
|
622
|
+
} catch (error) {
|
|
476
623
|
}
|
|
477
624
|
return new Promise(
|
|
478
|
-
(
|
|
625
|
+
(resolve, reject) => void fetch(originalWorkerUrl, {
|
|
479
626
|
// abort if the worker is not fetched in a reasonable time
|
|
480
|
-
signal
|
|
481
|
-
}).then((
|
|
482
|
-
const
|
|
483
|
-
|
|
484
|
-
const
|
|
627
|
+
signal
|
|
628
|
+
}).then((res) => res.text()).then((codeString) => {
|
|
629
|
+
const workerPath = new URL(originalWorkerUrl).href.split("/");
|
|
630
|
+
workerPath.pop();
|
|
631
|
+
const importScriptsFix = stripIndents`
|
|
485
632
|
const _importScripts = importScripts;
|
|
486
|
-
const _fixImports = (url) => new URL(url, '${
|
|
633
|
+
const _fixImports = (url) => new URL(url, '${workerPath.join("/") + "/"}').href;
|
|
487
634
|
importScripts = (...urls) => _importScripts(...urls.map(_fixImports));
|
|
488
635
|
`;
|
|
489
|
-
let
|
|
490
|
-
if (
|
|
491
|
-
const
|
|
492
|
-
|
|
493
|
-
} else
|
|
494
|
-
|
|
495
|
-
|
|
636
|
+
let finalURL = "";
|
|
637
|
+
if (options.useBlob) {
|
|
638
|
+
const blob = new Blob([importScriptsFix + codeString], { type });
|
|
639
|
+
finalURL = URL.createObjectURL(blob);
|
|
640
|
+
} else {
|
|
641
|
+
finalURL = `data:${type},` + encodeURIComponent(importScriptsFix + codeString);
|
|
642
|
+
}
|
|
643
|
+
resolve(finalURL);
|
|
496
644
|
}).catch(() => {
|
|
497
|
-
|
|
645
|
+
reject(new Error(`Failed to fetch worker from ${originalWorkerUrl}`));
|
|
498
646
|
})
|
|
499
647
|
);
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
648
|
+
};
|
|
649
|
+
const createProxyWorker = async (resourcesLocation = window.location.href) => {
|
|
650
|
+
const workerUrl = await getCrossOriginWorkerURL(
|
|
651
|
+
new URL("resources/blinkid-worker.js", resourcesLocation).toString()
|
|
652
|
+
);
|
|
653
|
+
const response = await fetch(workerUrl, { method: "HEAD" });
|
|
654
|
+
const contentType = response.headers.get("content-type");
|
|
655
|
+
const isJavascript = contentType?.includes("javascript");
|
|
656
|
+
const isHtml = contentType?.includes("html");
|
|
657
|
+
if (isHtml) {
|
|
505
658
|
throw new Error(
|
|
506
|
-
|
|
659
|
+
oneLineTrim`${workerUrl} resolved to a resource with the content type ${contentType}.
|
|
507
660
|
This is likely an issue with the server configuration redirecting to an index.html file.
|
|
508
661
|
Check that your resources are properly hosted`
|
|
509
662
|
);
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
663
|
+
}
|
|
664
|
+
if (!isJavascript) {
|
|
665
|
+
throw new Error(`Worker file is not a JavaScript file: ${contentType}`);
|
|
666
|
+
}
|
|
667
|
+
if (!response.ok) {
|
|
513
668
|
throw new Error(
|
|
514
|
-
`Worker file not found or inaccessible: ${
|
|
669
|
+
`Worker file not found or inaccessible: ${response.status} ${response.statusText}`
|
|
515
670
|
);
|
|
516
|
-
|
|
671
|
+
}
|
|
672
|
+
const worker = new Worker(workerUrl, {
|
|
517
673
|
type: "module"
|
|
518
674
|
});
|
|
519
|
-
|
|
520
|
-
console.error("Worker error:",
|
|
675
|
+
worker.onerror = (e) => {
|
|
676
|
+
console.error("Worker error:", e);
|
|
677
|
+
proxyWorker[releaseProxy]();
|
|
521
678
|
};
|
|
522
|
-
const
|
|
523
|
-
return
|
|
679
|
+
const proxyWorker = wrap(worker);
|
|
680
|
+
return proxyWorker;
|
|
524
681
|
};
|
|
525
|
-
let
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
if (
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
682
|
+
let nanoid = (size = 21) => crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
|
|
683
|
+
byte &= 63;
|
|
684
|
+
if (byte < 36) {
|
|
685
|
+
id += byte.toString(36);
|
|
686
|
+
} else if (byte < 62) {
|
|
687
|
+
id += (byte - 26).toString(36).toUpperCase();
|
|
688
|
+
} else if (byte > 62) {
|
|
689
|
+
id += "-";
|
|
690
|
+
} else {
|
|
691
|
+
id += "_";
|
|
692
|
+
}
|
|
693
|
+
return id;
|
|
694
|
+
}, "");
|
|
695
|
+
const key = "blinkid-userid";
|
|
696
|
+
function getUserId() {
|
|
697
|
+
const hasLocalStorage = testLocalStorage();
|
|
698
|
+
if (!hasLocalStorage) {
|
|
699
|
+
return nanoid();
|
|
700
|
+
}
|
|
701
|
+
const previousId = localStorage.getItem(key);
|
|
702
|
+
if (previousId) {
|
|
703
|
+
return previousId;
|
|
704
|
+
}
|
|
705
|
+
const randomId = nanoid();
|
|
706
|
+
localStorage.setItem(key, randomId);
|
|
707
|
+
return randomId;
|
|
535
708
|
}
|
|
536
|
-
function
|
|
709
|
+
function testLocalStorage() {
|
|
537
710
|
try {
|
|
538
|
-
|
|
711
|
+
localStorage.setItem("test", "test");
|
|
712
|
+
localStorage.removeItem("test");
|
|
713
|
+
return true;
|
|
539
714
|
} catch {
|
|
540
|
-
return
|
|
715
|
+
return false;
|
|
541
716
|
}
|
|
542
717
|
}
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
718
|
+
const defaultSessionSettings = {
|
|
719
|
+
inputImageSource: "video",
|
|
720
|
+
scanningMode: "automatic",
|
|
721
|
+
scanningSettings: {
|
|
722
|
+
allowUncertainFrontSideScan: false,
|
|
723
|
+
blurDetectionLevel: "mid",
|
|
724
|
+
glareDetectionLevel: "mid",
|
|
725
|
+
tiltDetectionLevel: "mid",
|
|
726
|
+
skipImagesWithBlur: true,
|
|
727
|
+
skipImagesWithGlare: true,
|
|
728
|
+
skipImagesOccludedByHand: true,
|
|
729
|
+
skipImagesWithInadequateLightingConditions: true,
|
|
730
|
+
combineResultsFromMultipleInputImages: true,
|
|
731
|
+
croppedImageSettings: {
|
|
732
|
+
dotsPerInch: 250,
|
|
733
|
+
extensionFactor: 0,
|
|
734
|
+
returnDocumentImage: false,
|
|
735
|
+
returnFaceImage: false,
|
|
736
|
+
returnSignatureImage: false
|
|
737
|
+
},
|
|
738
|
+
customDocumentAnonymizationSettings: [],
|
|
739
|
+
customDocumentRules: [],
|
|
740
|
+
enableBarcodeScanOnly: false,
|
|
741
|
+
enableCharacterValidation: true,
|
|
742
|
+
inputImageMargin: 0.02,
|
|
743
|
+
maxAllowedMismatchesPerField: 0,
|
|
744
|
+
recognitionModeFilter: {
|
|
745
|
+
enableBarcodeId: true,
|
|
746
|
+
enableFullDocumentRecognition: true,
|
|
747
|
+
enableMrzId: true,
|
|
748
|
+
enableMrzPassport: true,
|
|
749
|
+
enableMrzVisa: true,
|
|
750
|
+
enablePhotoId: true
|
|
751
|
+
},
|
|
752
|
+
returnInputImages: false,
|
|
753
|
+
scanCroppedDocumentImage: false,
|
|
754
|
+
scanPassportDataPageOnly: true,
|
|
755
|
+
scanUnsupportedBack: false,
|
|
756
|
+
anonymizationMode: "full-result"
|
|
757
|
+
}
|
|
758
|
+
};
|
|
759
|
+
async function loadBlinkIdCore(settings, progressCallback) {
|
|
760
|
+
const remoteWorker = await createProxyWorker(settings.resourcesLocation);
|
|
761
|
+
if (!settings.userId) {
|
|
762
|
+
settings.userId = getUserId();
|
|
763
|
+
}
|
|
764
|
+
if (!settings.resourcesLocation) {
|
|
765
|
+
settings.resourcesLocation = window.location.href;
|
|
766
|
+
}
|
|
767
|
+
if (settings.useLightweightBuild === void 0) {
|
|
768
|
+
settings.useLightweightBuild = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
|
|
769
|
+
navigator.userAgent
|
|
770
|
+
);
|
|
771
|
+
}
|
|
772
|
+
const proxyProgressCallback = progressCallback ? proxy(progressCallback) : void 0;
|
|
549
773
|
try {
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
774
|
+
await remoteWorker.initBlinkId(
|
|
775
|
+
settings,
|
|
776
|
+
defaultSessionSettings,
|
|
777
|
+
proxyProgressCallback
|
|
778
|
+
);
|
|
779
|
+
return remoteWorker;
|
|
780
|
+
} catch (error) {
|
|
555
781
|
throw new Error("Failed to initialize BlinkID", {
|
|
556
|
-
cause:
|
|
782
|
+
cause: error
|
|
557
783
|
});
|
|
558
784
|
}
|
|
559
785
|
}
|
|
560
|
-
function
|
|
561
|
-
|
|
562
|
-
data:
|
|
563
|
-
width:
|
|
564
|
-
height:
|
|
565
|
-
colorSpace:
|
|
786
|
+
function createCustomImageData(imageData) {
|
|
787
|
+
const customImageData = {
|
|
788
|
+
data: imageData.data,
|
|
789
|
+
width: imageData.width,
|
|
790
|
+
height: imageData.height,
|
|
791
|
+
colorSpace: imageData.colorSpace
|
|
566
792
|
};
|
|
793
|
+
return customImageData;
|
|
794
|
+
}
|
|
795
|
+
const testSymbol = Symbol();
|
|
796
|
+
globalThis.__BLINKID_CORE__ ||= testSymbol;
|
|
797
|
+
if (globalThis.__BLINKID_CORE__ !== testSymbol) {
|
|
798
|
+
console.warn(
|
|
799
|
+
"Detected multiple instances of @microblink/blinkid-core. This can lead to unexpected behavior."
|
|
800
|
+
);
|
|
567
801
|
}
|
|
568
|
-
const W = Symbol();
|
|
569
|
-
globalThis.__BLINKID_CORE__ ||= W;
|
|
570
|
-
globalThis.__BLINKID_CORE__ !== W && console.warn(
|
|
571
|
-
"Detected multiple instances of @microblink/blinkid-core. This can lead to unexpected behavior."
|
|
572
|
-
);
|
|
573
802
|
export {
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
803
|
+
createCustomImageData,
|
|
804
|
+
createProxyWorker,
|
|
805
|
+
defaultSessionSettings,
|
|
806
|
+
getCrossOriginWorkerURL,
|
|
807
|
+
getUserId,
|
|
808
|
+
loadBlinkIdCore,
|
|
809
|
+
testLocalStorage
|
|
580
810
|
};
|
|
811
|
+
//# sourceMappingURL=blinkid-core.js.map
|