ranuts 0.1.0-alpha.17 → 0.1.0-alpha.18
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/examples/clone-deep-example.d.ts +1 -0
- package/dist/examples/is-equal-example.d.ts +1 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.js +15 -7
- package/dist/{mimeType-eRf1TlBb.js → mimeType-BEdNg_IR.js} +59 -2
- package/dist/src/arithmetic/index.d.ts +139 -1
- package/dist/src/ml/index.js +1140 -1202
- package/dist/src/node/body.d.ts +0 -1
- package/dist/src/node/command.d.ts +0 -1
- package/dist/src/node/ctx2req.d.ts +0 -1
- package/dist/src/node/fs.d.ts +0 -2
- package/dist/src/node/get.d.ts +1 -1
- package/dist/src/node/index.d.ts +24 -22
- package/dist/src/node/index.js +1 -1
- package/dist/src/node/paresUrl.d.ts +0 -1
- package/dist/src/node/readFile.d.ts +0 -1
- package/dist/src/node/server.d.ts +0 -1
- package/dist/src/node/stream.d.ts +0 -1
- package/dist/src/node/traverse.d.ts +0 -1
- package/dist/src/node/websocket.d.ts +0 -4
- package/dist/src/node/ws.d.ts +0 -1
- package/dist/src/optimize/index.d.ts +4 -12
- package/dist/src/ran/min.d.ts +15 -1
- package/dist/src/utils/behavior.d.ts +5 -0
- package/dist/src/utils/bom.d.ts +8 -1
- package/dist/src/utils/index.d.ts +8 -7
- package/dist/src/utils/index.js +2851 -2585
- package/dist/src/utils/number.d.ts +2 -0
- package/dist/src/utils/obj.d.ts +37 -1
- package/dist/src/utils/signal.d.ts +6 -0
- package/dist/src/utils/str.d.ts +10 -2
- package/dist/src/utils/subscribe.d.ts +10 -11
- package/dist/src/utils/throttle.d.ts +3 -7
- package/dist/src/utils/visual/application.d.ts +9 -5
- package/dist/src/utils/visual/enums.d.ts +23 -17
- package/dist/src/utils/visual/event/index.d.ts +6 -3
- package/dist/src/utils/visual/graphics/graphics.d.ts +67 -8
- package/dist/src/utils/visual/graphics/graphicsData.d.ts +4 -1
- package/dist/src/utils/visual/graphics/graphicsGeometry.d.ts +23 -4
- package/dist/src/utils/visual/graphics/index.d.ts +4 -3
- package/dist/src/utils/visual/index.d.ts +7 -4
- package/dist/src/utils/visual/math/enums.d.ts +1 -0
- package/dist/src/utils/visual/math/index.d.ts +5 -4
- package/dist/src/utils/visual/math/matrix.d.ts +87 -6
- package/dist/src/utils/visual/math/transform.d.ts +12 -10
- package/dist/src/utils/visual/render/batchRenderer.d.ts +72 -0
- package/dist/src/utils/visual/render/canvasRenderer.d.ts +2 -1
- package/dist/src/utils/visual/render/render.d.ts +8 -3
- package/dist/src/utils/visual/render/utils/batch/index.d.ts +90 -0
- package/dist/src/utils/visual/render/utils/float.d.ts +63 -0
- package/dist/src/utils/visual/render/utils/index.d.ts +3 -0
- package/dist/src/utils/visual/render/utils/verticy.d.ts +13 -0
- package/dist/src/utils/visual/render/utils/webgl/batchPool.d.ts +28 -0
- package/dist/src/utils/visual/render/utils/webgl/initShader.d.ts +2 -0
- package/dist/src/utils/visual/render/utils/webgl/shaders.d.ts +2 -0
- package/dist/src/utils/visual/render/utils/webgpu/shaders.d.ts +8 -0
- package/dist/src/utils/visual/render/webGPURenderer.d.ts +49 -0
- package/dist/src/utils/visual/render/webGlRenderer.d.ts +12 -2
- package/dist/src/utils/visual/shape/circle.d.ts +3 -3
- package/dist/src/utils/visual/shape/ellipse.d.ts +2 -2
- package/dist/src/utils/visual/shape/index.d.ts +7 -5
- package/dist/src/utils/visual/shape/polygon.d.ts +5 -4
- package/dist/src/utils/visual/shape/rectangle.d.ts +3 -3
- package/dist/src/utils/visual/shape/roundedRectangle.d.ts +13 -0
- package/dist/src/utils/visual/shape/shape.d.ts +2 -3
- package/dist/src/utils/visual/style/index.d.ts +3 -2
- package/dist/src/utils/visual/style/line.d.ts +4 -3
- package/dist/src/utils/visual/types.d.ts +14 -3
- package/dist/src/utils/visual/vertex/container.d.ts +40 -5
- package/dist/src/utils/visual/vertex/index.d.ts +5 -4
- package/dist/src/utils/visual/vertex/point.d.ts +2 -2
- package/dist/src/utils/visual/vertex/vertex.d.ts +1 -1
- package/dist/src/vnode/modules/index.d.ts +1 -5
- package/dist/src/vnode/modules/listeners.d.ts +1 -3
- package/dist/src/wicket/bridge.d.ts +4 -0
- package/dist/src/wicket/index.d.ts +29 -0
- package/dist/test/cloneDeep.test.d.ts +1 -0
- package/dist/test/is-equal.test.d.ts +1 -0
- package/dist/test/visual/math.test.d.ts +1 -0
- package/dist/tsconfig.json +2 -1
- package/dist/umd/index.umd.cjs +1 -1
- package/dist/umd/ml/ml.umd.cjs +1 -1
- package/dist/umd/node/node.umd.cjs +1 -1
- package/dist/umd/utils/utils.umd.cjs +1 -1
- package/dist/umd/wasm/wasm.umd.cjs +1 -1
- package/dist/{ws-CQA-0Bzm.js → ws-BWkMlufE.js} +81 -81
- package/package.json +23 -19
- package/readme.md +1 -1
- package/dist/src/utils/visual/vertex/application.d.ts +0 -13
package/dist/src/ml/index.js
CHANGED
|
@@ -1,1291 +1,1229 @@
|
|
|
1
1
|
var runtime = { exports: {} };
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
|
|
13
|
-
var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
|
|
14
|
-
function define(obj, key, value) {
|
|
15
|
-
Object.defineProperty(obj, key, {
|
|
16
|
-
value,
|
|
17
|
-
enumerable: true,
|
|
18
|
-
configurable: true,
|
|
19
|
-
writable: true
|
|
20
|
-
});
|
|
21
|
-
return obj[key];
|
|
22
|
-
}
|
|
23
|
-
try {
|
|
24
|
-
define({}, "");
|
|
25
|
-
} catch (err) {
|
|
26
|
-
define = function(obj, key, value) {
|
|
27
|
-
return obj[key] = value;
|
|
2
|
+
var hasRequiredRuntime;
|
|
3
|
+
function requireRuntime() {
|
|
4
|
+
if (hasRequiredRuntime) return runtime.exports;
|
|
5
|
+
hasRequiredRuntime = 1;
|
|
6
|
+
(function(module) {
|
|
7
|
+
var runtime2 = function(exports) {
|
|
8
|
+
var Op = Object.prototype;
|
|
9
|
+
var hasOwn = Op.hasOwnProperty;
|
|
10
|
+
var defineProperty = Object.defineProperty || function(obj, key, desc) {
|
|
11
|
+
obj[key] = desc.value;
|
|
28
12
|
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
var
|
|
32
|
-
var
|
|
33
|
-
var
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
13
|
+
var undefined$1;
|
|
14
|
+
var $Symbol = typeof Symbol === "function" ? Symbol : {};
|
|
15
|
+
var iteratorSymbol = $Symbol.iterator || "@@iterator";
|
|
16
|
+
var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
|
|
17
|
+
var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
|
|
18
|
+
function define(obj, key, value) {
|
|
19
|
+
Object.defineProperty(obj, key, {
|
|
20
|
+
value,
|
|
21
|
+
enumerable: true,
|
|
22
|
+
configurable: true,
|
|
23
|
+
writable: true
|
|
24
|
+
});
|
|
25
|
+
return obj[key];
|
|
26
|
+
}
|
|
39
27
|
try {
|
|
40
|
-
|
|
28
|
+
define({}, "");
|
|
41
29
|
} catch (err) {
|
|
42
|
-
|
|
30
|
+
define = function(obj, key, value) {
|
|
31
|
+
return obj[key] = value;
|
|
32
|
+
};
|
|
43
33
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
GeneratorFunction.displayName = define(
|
|
74
|
-
GeneratorFunctionPrototype,
|
|
75
|
-
toStringTagSymbol,
|
|
76
|
-
"GeneratorFunction"
|
|
77
|
-
);
|
|
78
|
-
function defineIteratorMethods(prototype) {
|
|
79
|
-
["next", "throw", "return"].forEach(function(method) {
|
|
80
|
-
define(prototype, method, function(arg) {
|
|
81
|
-
return this._invoke(method, arg);
|
|
82
|
-
});
|
|
34
|
+
function wrap(innerFn, outerFn, self, tryLocsList) {
|
|
35
|
+
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
|
|
36
|
+
var generator = Object.create(protoGenerator.prototype);
|
|
37
|
+
var context = new Context(tryLocsList || []);
|
|
38
|
+
defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) });
|
|
39
|
+
return generator;
|
|
40
|
+
}
|
|
41
|
+
exports.wrap = wrap;
|
|
42
|
+
function tryCatch(fn, obj, arg) {
|
|
43
|
+
try {
|
|
44
|
+
return { type: "normal", arg: fn.call(obj, arg) };
|
|
45
|
+
} catch (err) {
|
|
46
|
+
return { type: "throw", arg: err };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
var GenStateSuspendedStart = "suspendedStart";
|
|
50
|
+
var GenStateSuspendedYield = "suspendedYield";
|
|
51
|
+
var GenStateExecuting = "executing";
|
|
52
|
+
var GenStateCompleted = "completed";
|
|
53
|
+
var ContinueSentinel = {};
|
|
54
|
+
function Generator() {
|
|
55
|
+
}
|
|
56
|
+
function GeneratorFunction() {
|
|
57
|
+
}
|
|
58
|
+
function GeneratorFunctionPrototype() {
|
|
59
|
+
}
|
|
60
|
+
var IteratorPrototype = {};
|
|
61
|
+
define(IteratorPrototype, iteratorSymbol, function() {
|
|
62
|
+
return this;
|
|
83
63
|
});
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
// do is to check its .name property.
|
|
89
|
-
(ctor.displayName || ctor.name) === "GeneratorFunction" : false;
|
|
90
|
-
};
|
|
91
|
-
exports.mark = function(genFun) {
|
|
92
|
-
if (Object.setPrototypeOf) {
|
|
93
|
-
Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
|
|
94
|
-
} else {
|
|
95
|
-
genFun.__proto__ = GeneratorFunctionPrototype;
|
|
96
|
-
define(genFun, toStringTagSymbol, "GeneratorFunction");
|
|
64
|
+
var getProto = Object.getPrototypeOf;
|
|
65
|
+
var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
|
|
66
|
+
if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
|
|
67
|
+
IteratorPrototype = NativeIteratorPrototype;
|
|
97
68
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
69
|
+
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
|
|
70
|
+
GeneratorFunction.prototype = GeneratorFunctionPrototype;
|
|
71
|
+
defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: true });
|
|
72
|
+
defineProperty(
|
|
73
|
+
GeneratorFunctionPrototype,
|
|
74
|
+
"constructor",
|
|
75
|
+
{ value: GeneratorFunction, configurable: true }
|
|
76
|
+
);
|
|
77
|
+
GeneratorFunction.displayName = define(
|
|
78
|
+
GeneratorFunctionPrototype,
|
|
79
|
+
toStringTagSymbol,
|
|
80
|
+
"GeneratorFunction"
|
|
81
|
+
);
|
|
82
|
+
function defineIteratorMethods(prototype) {
|
|
83
|
+
["next", "throw", "return"].forEach(function(method) {
|
|
84
|
+
define(prototype, method, function(arg) {
|
|
85
|
+
return this._invoke(method, arg);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
exports.isGeneratorFunction = function(genFun) {
|
|
90
|
+
var ctor = typeof genFun === "function" && genFun.constructor;
|
|
91
|
+
return ctor ? ctor === GeneratorFunction || // For the native GeneratorFunction constructor, the best we can
|
|
92
|
+
// do is to check its .name property.
|
|
93
|
+
(ctor.displayName || ctor.name) === "GeneratorFunction" : false;
|
|
94
|
+
};
|
|
95
|
+
exports.mark = function(genFun) {
|
|
96
|
+
if (Object.setPrototypeOf) {
|
|
97
|
+
Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
|
|
109
98
|
} else {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
99
|
+
genFun.__proto__ = GeneratorFunctionPrototype;
|
|
100
|
+
define(genFun, toStringTagSymbol, "GeneratorFunction");
|
|
101
|
+
}
|
|
102
|
+
genFun.prototype = Object.create(Gp);
|
|
103
|
+
return genFun;
|
|
104
|
+
};
|
|
105
|
+
exports.awrap = function(arg) {
|
|
106
|
+
return { __await: arg };
|
|
107
|
+
};
|
|
108
|
+
function AsyncIterator(generator, PromiseImpl) {
|
|
109
|
+
function invoke(method, arg, resolve, reject) {
|
|
110
|
+
var record = tryCatch(generator[method], generator, arg);
|
|
111
|
+
if (record.type === "throw") {
|
|
112
|
+
reject(record.arg);
|
|
113
|
+
} else {
|
|
114
|
+
var result = record.arg;
|
|
115
|
+
var value = result.value;
|
|
116
|
+
if (value && typeof value === "object" && hasOwn.call(value, "__await")) {
|
|
117
|
+
return PromiseImpl.resolve(value.__await).then(function(value2) {
|
|
118
|
+
invoke("next", value2, resolve, reject);
|
|
119
|
+
}, function(err) {
|
|
120
|
+
invoke("throw", err, resolve, reject);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
return PromiseImpl.resolve(value).then(function(unwrapped) {
|
|
124
|
+
result.value = unwrapped;
|
|
125
|
+
resolve(result);
|
|
126
|
+
}, function(error) {
|
|
127
|
+
return invoke("throw", error, resolve, reject);
|
|
117
128
|
});
|
|
118
129
|
}
|
|
119
|
-
return PromiseImpl.resolve(value).then(function(unwrapped) {
|
|
120
|
-
result.value = unwrapped;
|
|
121
|
-
resolve(result);
|
|
122
|
-
}, function(error) {
|
|
123
|
-
return invoke("throw", error, resolve, reject);
|
|
124
|
-
});
|
|
125
130
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
131
|
+
var previousPromise;
|
|
132
|
+
function enqueue(method, arg) {
|
|
133
|
+
function callInvokeWithMethodAndArg() {
|
|
134
|
+
return new PromiseImpl(function(resolve, reject) {
|
|
135
|
+
invoke(method, arg, resolve, reject);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
return previousPromise = // If enqueue has been called before, then we want to wait until
|
|
139
|
+
// all previous Promises have been resolved before calling invoke,
|
|
140
|
+
// so that results are always delivered in the correct order. If
|
|
141
|
+
// enqueue has not been called before, then it is important to
|
|
142
|
+
// call invoke immediately, without waiting on a callback to fire,
|
|
143
|
+
// so that the async generator function has the opportunity to do
|
|
144
|
+
// any necessary setup in a predictable way. This predictability
|
|
145
|
+
// is why the Promise constructor synchronously invokes its
|
|
146
|
+
// executor callback, and why async functions synchronously
|
|
147
|
+
// execute code before the first await. Since we implement simple
|
|
148
|
+
// async functions in terms of async generators, it is especially
|
|
149
|
+
// important to get this right, even though it requires care.
|
|
150
|
+
previousPromise ? previousPromise.then(
|
|
151
|
+
callInvokeWithMethodAndArg,
|
|
152
|
+
// Avoid propagating failures to Promises returned by later
|
|
153
|
+
// invocations of the iterator.
|
|
154
|
+
callInvokeWithMethodAndArg
|
|
155
|
+
) : callInvokeWithMethodAndArg();
|
|
133
156
|
}
|
|
134
|
-
|
|
135
|
-
// all previous Promises have been resolved before calling invoke,
|
|
136
|
-
// so that results are always delivered in the correct order. If
|
|
137
|
-
// enqueue has not been called before, then it is important to
|
|
138
|
-
// call invoke immediately, without waiting on a callback to fire,
|
|
139
|
-
// so that the async generator function has the opportunity to do
|
|
140
|
-
// any necessary setup in a predictable way. This predictability
|
|
141
|
-
// is why the Promise constructor synchronously invokes its
|
|
142
|
-
// executor callback, and why async functions synchronously
|
|
143
|
-
// execute code before the first await. Since we implement simple
|
|
144
|
-
// async functions in terms of async generators, it is especially
|
|
145
|
-
// important to get this right, even though it requires care.
|
|
146
|
-
previousPromise ? previousPromise.then(
|
|
147
|
-
callInvokeWithMethodAndArg,
|
|
148
|
-
// Avoid propagating failures to Promises returned by later
|
|
149
|
-
// invocations of the iterator.
|
|
150
|
-
callInvokeWithMethodAndArg
|
|
151
|
-
) : callInvokeWithMethodAndArg();
|
|
157
|
+
defineProperty(this, "_invoke", { value: enqueue });
|
|
152
158
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
define(AsyncIterator.prototype, asyncIteratorSymbol, function() {
|
|
157
|
-
return this;
|
|
158
|
-
});
|
|
159
|
-
exports.AsyncIterator = AsyncIterator;
|
|
160
|
-
exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
|
|
161
|
-
if (PromiseImpl === void 0) PromiseImpl = Promise;
|
|
162
|
-
var iter = new AsyncIterator(
|
|
163
|
-
wrap(innerFn, outerFn, self, tryLocsList),
|
|
164
|
-
PromiseImpl
|
|
165
|
-
);
|
|
166
|
-
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function(result) {
|
|
167
|
-
return result.done ? result.value : iter.next();
|
|
159
|
+
defineIteratorMethods(AsyncIterator.prototype);
|
|
160
|
+
define(AsyncIterator.prototype, asyncIteratorSymbol, function() {
|
|
161
|
+
return this;
|
|
168
162
|
});
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
163
|
+
exports.AsyncIterator = AsyncIterator;
|
|
164
|
+
exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
|
|
165
|
+
if (PromiseImpl === void 0) PromiseImpl = Promise;
|
|
166
|
+
var iter = new AsyncIterator(
|
|
167
|
+
wrap(innerFn, outerFn, self, tryLocsList),
|
|
168
|
+
PromiseImpl
|
|
169
|
+
);
|
|
170
|
+
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function(result) {
|
|
171
|
+
return result.done ? result.value : iter.next();
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
function makeInvokeMethod(innerFn, self, context) {
|
|
175
|
+
var state = GenStateSuspendedStart;
|
|
176
|
+
return function invoke(method, arg) {
|
|
177
|
+
if (state === GenStateExecuting) {
|
|
178
|
+
throw new Error("Generator is already running");
|
|
179
179
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
context.arg = arg;
|
|
184
|
-
while (true) {
|
|
185
|
-
var delegate = context.delegate;
|
|
186
|
-
if (delegate) {
|
|
187
|
-
var delegateResult = maybeInvokeDelegate(delegate, context);
|
|
188
|
-
if (delegateResult) {
|
|
189
|
-
if (delegateResult === ContinueSentinel) continue;
|
|
190
|
-
return delegateResult;
|
|
180
|
+
if (state === GenStateCompleted) {
|
|
181
|
+
if (method === "throw") {
|
|
182
|
+
throw arg;
|
|
191
183
|
}
|
|
184
|
+
return doneResult();
|
|
192
185
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
186
|
+
context.method = method;
|
|
187
|
+
context.arg = arg;
|
|
188
|
+
while (true) {
|
|
189
|
+
var delegate = context.delegate;
|
|
190
|
+
if (delegate) {
|
|
191
|
+
var delegateResult = maybeInvokeDelegate(delegate, context);
|
|
192
|
+
if (delegateResult) {
|
|
193
|
+
if (delegateResult === ContinueSentinel) continue;
|
|
194
|
+
return delegateResult;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (context.method === "next") {
|
|
198
|
+
context.sent = context._sent = context.arg;
|
|
199
|
+
} else if (context.method === "throw") {
|
|
200
|
+
if (state === GenStateSuspendedStart) {
|
|
201
|
+
state = GenStateCompleted;
|
|
202
|
+
throw context.arg;
|
|
203
|
+
}
|
|
204
|
+
context.dispatchException(context.arg);
|
|
205
|
+
} else if (context.method === "return") {
|
|
206
|
+
context.abrupt("return", context.arg);
|
|
207
|
+
}
|
|
208
|
+
state = GenStateExecuting;
|
|
209
|
+
var record = tryCatch(innerFn, self, context);
|
|
210
|
+
if (record.type === "normal") {
|
|
211
|
+
state = context.done ? GenStateCompleted : GenStateSuspendedYield;
|
|
212
|
+
if (record.arg === ContinueSentinel) {
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
value: record.arg,
|
|
217
|
+
done: context.done
|
|
218
|
+
};
|
|
219
|
+
} else if (record.type === "throw") {
|
|
197
220
|
state = GenStateCompleted;
|
|
198
|
-
|
|
221
|
+
context.method = "throw";
|
|
222
|
+
context.arg = record.arg;
|
|
199
223
|
}
|
|
200
|
-
context.dispatchException(context.arg);
|
|
201
|
-
} else if (context.method === "return") {
|
|
202
|
-
context.abrupt("return", context.arg);
|
|
203
224
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
function maybeInvokeDelegate(delegate, context) {
|
|
228
|
+
var methodName = context.method;
|
|
229
|
+
var method = delegate.iterator[methodName];
|
|
230
|
+
if (method === undefined$1) {
|
|
231
|
+
context.delegate = null;
|
|
232
|
+
if (methodName === "throw" && delegate.iterator["return"]) {
|
|
233
|
+
context.method = "return";
|
|
234
|
+
context.arg = undefined$1;
|
|
235
|
+
maybeInvokeDelegate(delegate, context);
|
|
236
|
+
if (context.method === "throw") {
|
|
237
|
+
return ContinueSentinel;
|
|
210
238
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
done: context.done
|
|
214
|
-
};
|
|
215
|
-
} else if (record.type === "throw") {
|
|
216
|
-
state = GenStateCompleted;
|
|
239
|
+
}
|
|
240
|
+
if (methodName !== "return") {
|
|
217
241
|
context.method = "throw";
|
|
218
|
-
context.arg =
|
|
242
|
+
context.arg = new TypeError(
|
|
243
|
+
"The iterator does not provide a '" + methodName + "' method"
|
|
244
|
+
);
|
|
219
245
|
}
|
|
246
|
+
return ContinueSentinel;
|
|
220
247
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
context.delegate = null;
|
|
228
|
-
if (methodName === "throw" && delegate.iterator["return"]) {
|
|
229
|
-
context.method = "return";
|
|
230
|
-
context.arg = undefined$1;
|
|
231
|
-
maybeInvokeDelegate(delegate, context);
|
|
232
|
-
if (context.method === "throw") {
|
|
233
|
-
return ContinueSentinel;
|
|
234
|
-
}
|
|
248
|
+
var record = tryCatch(method, delegate.iterator, context.arg);
|
|
249
|
+
if (record.type === "throw") {
|
|
250
|
+
context.method = "throw";
|
|
251
|
+
context.arg = record.arg;
|
|
252
|
+
context.delegate = null;
|
|
253
|
+
return ContinueSentinel;
|
|
235
254
|
}
|
|
236
|
-
|
|
255
|
+
var info = record.arg;
|
|
256
|
+
if (!info) {
|
|
237
257
|
context.method = "throw";
|
|
238
|
-
context.arg = new TypeError(
|
|
239
|
-
|
|
240
|
-
|
|
258
|
+
context.arg = new TypeError("iterator result is not an object");
|
|
259
|
+
context.delegate = null;
|
|
260
|
+
return ContinueSentinel;
|
|
261
|
+
}
|
|
262
|
+
if (info.done) {
|
|
263
|
+
context[delegate.resultName] = info.value;
|
|
264
|
+
context.next = delegate.nextLoc;
|
|
265
|
+
if (context.method !== "return") {
|
|
266
|
+
context.method = "next";
|
|
267
|
+
context.arg = undefined$1;
|
|
268
|
+
}
|
|
269
|
+
} else {
|
|
270
|
+
return info;
|
|
241
271
|
}
|
|
242
|
-
return ContinueSentinel;
|
|
243
|
-
}
|
|
244
|
-
var record = tryCatch(method, delegate.iterator, context.arg);
|
|
245
|
-
if (record.type === "throw") {
|
|
246
|
-
context.method = "throw";
|
|
247
|
-
context.arg = record.arg;
|
|
248
|
-
context.delegate = null;
|
|
249
|
-
return ContinueSentinel;
|
|
250
|
-
}
|
|
251
|
-
var info = record.arg;
|
|
252
|
-
if (!info) {
|
|
253
|
-
context.method = "throw";
|
|
254
|
-
context.arg = new TypeError("iterator result is not an object");
|
|
255
272
|
context.delegate = null;
|
|
256
273
|
return ContinueSentinel;
|
|
257
274
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
275
|
+
defineIteratorMethods(Gp);
|
|
276
|
+
define(Gp, toStringTagSymbol, "Generator");
|
|
277
|
+
define(Gp, iteratorSymbol, function() {
|
|
278
|
+
return this;
|
|
279
|
+
});
|
|
280
|
+
define(Gp, "toString", function() {
|
|
281
|
+
return "[object Generator]";
|
|
282
|
+
});
|
|
283
|
+
function pushTryEntry(locs) {
|
|
284
|
+
var entry = { tryLoc: locs[0] };
|
|
285
|
+
if (1 in locs) {
|
|
286
|
+
entry.catchLoc = locs[1];
|
|
264
287
|
}
|
|
265
|
-
|
|
266
|
-
|
|
288
|
+
if (2 in locs) {
|
|
289
|
+
entry.finallyLoc = locs[2];
|
|
290
|
+
entry.afterLoc = locs[3];
|
|
291
|
+
}
|
|
292
|
+
this.tryEntries.push(entry);
|
|
267
293
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
define(Gp, iteratorSymbol, function() {
|
|
274
|
-
return this;
|
|
275
|
-
});
|
|
276
|
-
define(Gp, "toString", function() {
|
|
277
|
-
return "[object Generator]";
|
|
278
|
-
});
|
|
279
|
-
function pushTryEntry(locs) {
|
|
280
|
-
var entry = { tryLoc: locs[0] };
|
|
281
|
-
if (1 in locs) {
|
|
282
|
-
entry.catchLoc = locs[1];
|
|
294
|
+
function resetTryEntry(entry) {
|
|
295
|
+
var record = entry.completion || {};
|
|
296
|
+
record.type = "normal";
|
|
297
|
+
delete record.arg;
|
|
298
|
+
entry.completion = record;
|
|
283
299
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
300
|
+
function Context(tryLocsList) {
|
|
301
|
+
this.tryEntries = [{ tryLoc: "root" }];
|
|
302
|
+
tryLocsList.forEach(pushTryEntry, this);
|
|
303
|
+
this.reset(true);
|
|
287
304
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
delete record.arg;
|
|
294
|
-
entry.completion = record;
|
|
295
|
-
}
|
|
296
|
-
function Context(tryLocsList) {
|
|
297
|
-
this.tryEntries = [{ tryLoc: "root" }];
|
|
298
|
-
tryLocsList.forEach(pushTryEntry, this);
|
|
299
|
-
this.reset(true);
|
|
300
|
-
}
|
|
301
|
-
exports.keys = function(val) {
|
|
302
|
-
var object = Object(val);
|
|
303
|
-
var keys = [];
|
|
304
|
-
for (var key in object) {
|
|
305
|
-
keys.push(key);
|
|
306
|
-
}
|
|
307
|
-
keys.reverse();
|
|
308
|
-
return function next() {
|
|
309
|
-
while (keys.length) {
|
|
310
|
-
var key2 = keys.pop();
|
|
311
|
-
if (key2 in object) {
|
|
312
|
-
next.value = key2;
|
|
313
|
-
next.done = false;
|
|
314
|
-
return next;
|
|
315
|
-
}
|
|
305
|
+
exports.keys = function(val) {
|
|
306
|
+
var object = Object(val);
|
|
307
|
+
var keys = [];
|
|
308
|
+
for (var key in object) {
|
|
309
|
+
keys.push(key);
|
|
316
310
|
}
|
|
317
|
-
|
|
318
|
-
return next
|
|
311
|
+
keys.reverse();
|
|
312
|
+
return function next() {
|
|
313
|
+
while (keys.length) {
|
|
314
|
+
var key2 = keys.pop();
|
|
315
|
+
if (key2 in object) {
|
|
316
|
+
next.value = key2;
|
|
317
|
+
next.done = false;
|
|
318
|
+
return next;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
next.done = true;
|
|
322
|
+
return next;
|
|
323
|
+
};
|
|
319
324
|
};
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
325
|
+
function values(iterable) {
|
|
326
|
+
if (iterable) {
|
|
327
|
+
var iteratorMethod = iterable[iteratorSymbol];
|
|
328
|
+
if (iteratorMethod) {
|
|
329
|
+
return iteratorMethod.call(iterable);
|
|
330
|
+
}
|
|
331
|
+
if (typeof iterable.next === "function") {
|
|
332
|
+
return iterable;
|
|
333
|
+
}
|
|
334
|
+
if (!isNaN(iterable.length)) {
|
|
335
|
+
var i = -1, next = function next2() {
|
|
336
|
+
while (++i < iterable.length) {
|
|
337
|
+
if (hasOwn.call(iterable, i)) {
|
|
338
|
+
next2.value = iterable[i];
|
|
339
|
+
next2.done = false;
|
|
340
|
+
return next2;
|
|
341
|
+
}
|
|
337
342
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
343
|
+
next2.value = undefined$1;
|
|
344
|
+
next2.done = true;
|
|
345
|
+
return next2;
|
|
346
|
+
};
|
|
347
|
+
return next.next = next;
|
|
348
|
+
}
|
|
344
349
|
}
|
|
350
|
+
return { next: doneResult };
|
|
345
351
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
this[name2] = undefined$1;
|
|
352
|
+
exports.values = values;
|
|
353
|
+
function doneResult() {
|
|
354
|
+
return { value: undefined$1, done: true };
|
|
355
|
+
}
|
|
356
|
+
Context.prototype = {
|
|
357
|
+
constructor: Context,
|
|
358
|
+
reset: function(skipTempReset) {
|
|
359
|
+
this.prev = 0;
|
|
360
|
+
this.next = 0;
|
|
361
|
+
this.sent = this._sent = undefined$1;
|
|
362
|
+
this.done = false;
|
|
363
|
+
this.delegate = null;
|
|
364
|
+
this.method = "next";
|
|
365
|
+
this.arg = undefined$1;
|
|
366
|
+
this.tryEntries.forEach(resetTryEntry);
|
|
367
|
+
if (!skipTempReset) {
|
|
368
|
+
for (var name in this) {
|
|
369
|
+
if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) {
|
|
370
|
+
this[name] = undefined$1;
|
|
371
|
+
}
|
|
367
372
|
}
|
|
368
373
|
}
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
throw rootRecord.arg;
|
|
377
|
-
}
|
|
378
|
-
return this.rval;
|
|
379
|
-
},
|
|
380
|
-
dispatchException: function(exception) {
|
|
381
|
-
if (this.done) {
|
|
382
|
-
throw exception;
|
|
383
|
-
}
|
|
384
|
-
var context = this;
|
|
385
|
-
function handle(loc, caught) {
|
|
386
|
-
record.type = "throw";
|
|
387
|
-
record.arg = exception;
|
|
388
|
-
context.next = loc;
|
|
389
|
-
if (caught) {
|
|
390
|
-
context.method = "next";
|
|
391
|
-
context.arg = undefined$1;
|
|
374
|
+
},
|
|
375
|
+
stop: function() {
|
|
376
|
+
this.done = true;
|
|
377
|
+
var rootEntry = this.tryEntries[0];
|
|
378
|
+
var rootRecord = rootEntry.completion;
|
|
379
|
+
if (rootRecord.type === "throw") {
|
|
380
|
+
throw rootRecord.arg;
|
|
392
381
|
}
|
|
393
|
-
return
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
if (entry.tryLoc === "root") {
|
|
399
|
-
return handle("end");
|
|
382
|
+
return this.rval;
|
|
383
|
+
},
|
|
384
|
+
dispatchException: function(exception) {
|
|
385
|
+
if (this.done) {
|
|
386
|
+
throw exception;
|
|
400
387
|
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
388
|
+
var context = this;
|
|
389
|
+
function handle(loc, caught) {
|
|
390
|
+
record.type = "throw";
|
|
391
|
+
record.arg = exception;
|
|
392
|
+
context.next = loc;
|
|
393
|
+
if (caught) {
|
|
394
|
+
context.method = "next";
|
|
395
|
+
context.arg = undefined$1;
|
|
396
|
+
}
|
|
397
|
+
return !!caught;
|
|
398
|
+
}
|
|
399
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
400
|
+
var entry = this.tryEntries[i];
|
|
401
|
+
var record = entry.completion;
|
|
402
|
+
if (entry.tryLoc === "root") {
|
|
403
|
+
return handle("end");
|
|
404
|
+
}
|
|
405
|
+
if (entry.tryLoc <= this.prev) {
|
|
406
|
+
var hasCatch = hasOwn.call(entry, "catchLoc");
|
|
407
|
+
var hasFinally = hasOwn.call(entry, "finallyLoc");
|
|
408
|
+
if (hasCatch && hasFinally) {
|
|
409
|
+
if (this.prev < entry.catchLoc) {
|
|
410
|
+
return handle(entry.catchLoc, true);
|
|
411
|
+
} else if (this.prev < entry.finallyLoc) {
|
|
412
|
+
return handle(entry.finallyLoc);
|
|
413
|
+
}
|
|
414
|
+
} else if (hasCatch) {
|
|
415
|
+
if (this.prev < entry.catchLoc) {
|
|
416
|
+
return handle(entry.catchLoc, true);
|
|
417
|
+
}
|
|
418
|
+
} else if (hasFinally) {
|
|
419
|
+
if (this.prev < entry.finallyLoc) {
|
|
420
|
+
return handle(entry.finallyLoc);
|
|
421
|
+
}
|
|
422
|
+
} else {
|
|
423
|
+
throw new Error("try statement without catch or finally");
|
|
417
424
|
}
|
|
418
|
-
} else {
|
|
419
|
-
throw new Error("try statement without catch or finally");
|
|
420
425
|
}
|
|
421
426
|
}
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
427
|
+
},
|
|
428
|
+
abrupt: function(type, arg) {
|
|
429
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
430
|
+
var entry = this.tryEntries[i];
|
|
431
|
+
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
|
|
432
|
+
var finallyEntry = entry;
|
|
433
|
+
break;
|
|
434
|
+
}
|
|
430
435
|
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
this.next = finallyEntry.finallyLoc;
|
|
441
|
-
return ContinueSentinel;
|
|
442
|
-
}
|
|
443
|
-
return this.complete(record);
|
|
444
|
-
},
|
|
445
|
-
complete: function(record, afterLoc) {
|
|
446
|
-
if (record.type === "throw") {
|
|
447
|
-
throw record.arg;
|
|
448
|
-
}
|
|
449
|
-
if (record.type === "break" || record.type === "continue") {
|
|
450
|
-
this.next = record.arg;
|
|
451
|
-
} else if (record.type === "return") {
|
|
452
|
-
this.rval = this.arg = record.arg;
|
|
453
|
-
this.method = "return";
|
|
454
|
-
this.next = "end";
|
|
455
|
-
} else if (record.type === "normal" && afterLoc) {
|
|
456
|
-
this.next = afterLoc;
|
|
457
|
-
}
|
|
458
|
-
return ContinueSentinel;
|
|
459
|
-
},
|
|
460
|
-
finish: function(finallyLoc) {
|
|
461
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
462
|
-
var entry = this.tryEntries[i];
|
|
463
|
-
if (entry.finallyLoc === finallyLoc) {
|
|
464
|
-
this.complete(entry.completion, entry.afterLoc);
|
|
465
|
-
resetTryEntry(entry);
|
|
436
|
+
if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
|
|
437
|
+
finallyEntry = null;
|
|
438
|
+
}
|
|
439
|
+
var record = finallyEntry ? finallyEntry.completion : {};
|
|
440
|
+
record.type = type;
|
|
441
|
+
record.arg = arg;
|
|
442
|
+
if (finallyEntry) {
|
|
443
|
+
this.method = "next";
|
|
444
|
+
this.next = finallyEntry.finallyLoc;
|
|
466
445
|
return ContinueSentinel;
|
|
467
446
|
}
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
447
|
+
return this.complete(record);
|
|
448
|
+
},
|
|
449
|
+
complete: function(record, afterLoc) {
|
|
450
|
+
if (record.type === "throw") {
|
|
451
|
+
throw record.arg;
|
|
452
|
+
}
|
|
453
|
+
if (record.type === "break" || record.type === "continue") {
|
|
454
|
+
this.next = record.arg;
|
|
455
|
+
} else if (record.type === "return") {
|
|
456
|
+
this.rval = this.arg = record.arg;
|
|
457
|
+
this.method = "return";
|
|
458
|
+
this.next = "end";
|
|
459
|
+
} else if (record.type === "normal" && afterLoc) {
|
|
460
|
+
this.next = afterLoc;
|
|
461
|
+
}
|
|
462
|
+
return ContinueSentinel;
|
|
463
|
+
},
|
|
464
|
+
finish: function(finallyLoc) {
|
|
465
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
466
|
+
var entry = this.tryEntries[i];
|
|
467
|
+
if (entry.finallyLoc === finallyLoc) {
|
|
468
|
+
this.complete(entry.completion, entry.afterLoc);
|
|
477
469
|
resetTryEntry(entry);
|
|
470
|
+
return ContinueSentinel;
|
|
478
471
|
}
|
|
479
|
-
return thrown;
|
|
480
472
|
}
|
|
473
|
+
},
|
|
474
|
+
"catch": function(tryLoc) {
|
|
475
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
476
|
+
var entry = this.tryEntries[i];
|
|
477
|
+
if (entry.tryLoc === tryLoc) {
|
|
478
|
+
var record = entry.completion;
|
|
479
|
+
if (record.type === "throw") {
|
|
480
|
+
var thrown = record.arg;
|
|
481
|
+
resetTryEntry(entry);
|
|
482
|
+
}
|
|
483
|
+
return thrown;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
throw new Error("illegal catch attempt");
|
|
487
|
+
},
|
|
488
|
+
delegateYield: function(iterable, resultName, nextLoc) {
|
|
489
|
+
this.delegate = {
|
|
490
|
+
iterator: values(iterable),
|
|
491
|
+
resultName,
|
|
492
|
+
nextLoc
|
|
493
|
+
};
|
|
494
|
+
if (this.method === "next") {
|
|
495
|
+
this.arg = undefined$1;
|
|
496
|
+
}
|
|
497
|
+
return ContinueSentinel;
|
|
481
498
|
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
499
|
+
};
|
|
500
|
+
return exports;
|
|
501
|
+
}(
|
|
502
|
+
// If this script is executing as a CommonJS module, use module.exports
|
|
503
|
+
// as the regeneratorRuntime namespace. Otherwise create a new empty
|
|
504
|
+
// object. Either way, the resulting object will be used to initialize
|
|
505
|
+
// the regeneratorRuntime variable at the top of this file.
|
|
506
|
+
module.exports
|
|
507
|
+
);
|
|
508
|
+
try {
|
|
509
|
+
regeneratorRuntime = runtime2;
|
|
510
|
+
} catch (accidentalStrictMode) {
|
|
511
|
+
if (typeof globalThis === "object") {
|
|
512
|
+
globalThis.regeneratorRuntime = runtime2;
|
|
513
|
+
} else {
|
|
514
|
+
Function("r", "regeneratorRuntime = r")(runtime2);
|
|
494
515
|
}
|
|
495
|
-
};
|
|
496
|
-
return exports;
|
|
497
|
-
}(
|
|
498
|
-
// If this script is executing as a CommonJS module, use module.exports
|
|
499
|
-
// as the regeneratorRuntime namespace. Otherwise create a new empty
|
|
500
|
-
// object. Either way, the resulting object will be used to initialize
|
|
501
|
-
// the regeneratorRuntime variable at the top of this file.
|
|
502
|
-
module.exports
|
|
503
|
-
);
|
|
504
|
-
try {
|
|
505
|
-
regeneratorRuntime = runtime2;
|
|
506
|
-
} catch (accidentalStrictMode) {
|
|
507
|
-
if (typeof globalThis === "object") {
|
|
508
|
-
globalThis.regeneratorRuntime = runtime2;
|
|
509
|
-
} else {
|
|
510
|
-
Function("r", "regeneratorRuntime = r")(runtime2);
|
|
511
516
|
}
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
517
|
+
})(runtime);
|
|
518
|
+
return runtime.exports;
|
|
519
|
+
}
|
|
520
|
+
var getId;
|
|
521
|
+
var hasRequiredGetId;
|
|
522
|
+
function requireGetId() {
|
|
523
|
+
if (hasRequiredGetId) return getId;
|
|
524
|
+
hasRequiredGetId = 1;
|
|
525
|
+
getId = (prefix, cnt) => `${prefix}-${cnt}-${Math.random().toString(16).slice(3, 8)}`;
|
|
526
|
+
return getId;
|
|
527
|
+
}
|
|
528
|
+
var createJob;
|
|
529
|
+
var hasRequiredCreateJob;
|
|
530
|
+
function requireCreateJob() {
|
|
531
|
+
if (hasRequiredCreateJob) return createJob;
|
|
532
|
+
hasRequiredCreateJob = 1;
|
|
533
|
+
const getId2 = requireGetId();
|
|
534
|
+
let jobCounter = 0;
|
|
535
|
+
createJob = ({
|
|
536
|
+
id: _id,
|
|
529
537
|
action,
|
|
530
|
-
payload
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
log$2.setLogging = (_logging) => {
|
|
537
|
-
logging = _logging;
|
|
538
|
-
};
|
|
539
|
-
log$2.log = (...args) => logging ? console.log.apply(void 0, args) : null;
|
|
540
|
-
const createJob$1 = createJob$2;
|
|
541
|
-
const { log: log$1 } = log$2;
|
|
542
|
-
const getId$1 = getId$3;
|
|
543
|
-
let schedulerCounter = 0;
|
|
544
|
-
var createScheduler$1 = () => {
|
|
545
|
-
const id = getId$1("Scheduler", schedulerCounter);
|
|
546
|
-
const workers = {};
|
|
547
|
-
const runningWorkers = {};
|
|
548
|
-
let jobQueue = [];
|
|
549
|
-
schedulerCounter += 1;
|
|
550
|
-
const getQueueLen = () => jobQueue.length;
|
|
551
|
-
const getNumWorkers = () => Object.keys(workers).length;
|
|
552
|
-
const dequeue = () => {
|
|
553
|
-
if (jobQueue.length !== 0) {
|
|
554
|
-
const wIds = Object.keys(workers);
|
|
555
|
-
for (let i = 0; i < wIds.length; i += 1) {
|
|
556
|
-
if (typeof runningWorkers[wIds[i]] === "undefined") {
|
|
557
|
-
jobQueue[0](workers[wIds[i]]);
|
|
558
|
-
break;
|
|
559
|
-
}
|
|
560
|
-
}
|
|
538
|
+
payload = {}
|
|
539
|
+
}) => {
|
|
540
|
+
let id = _id;
|
|
541
|
+
if (typeof id === "undefined") {
|
|
542
|
+
id = getId2("Job", jobCounter);
|
|
543
|
+
jobCounter += 1;
|
|
561
544
|
}
|
|
545
|
+
return {
|
|
546
|
+
id,
|
|
547
|
+
action,
|
|
548
|
+
payload
|
|
549
|
+
};
|
|
562
550
|
};
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
551
|
+
return createJob;
|
|
552
|
+
}
|
|
553
|
+
var log = {};
|
|
554
|
+
var hasRequiredLog;
|
|
555
|
+
function requireLog() {
|
|
556
|
+
if (hasRequiredLog) return log;
|
|
557
|
+
hasRequiredLog = 1;
|
|
558
|
+
let logging = false;
|
|
559
|
+
log.logging = logging;
|
|
560
|
+
log.setLogging = (_logging) => {
|
|
561
|
+
logging = _logging;
|
|
562
|
+
};
|
|
563
|
+
log.log = (...args) => logging ? console.log.apply(this, args) : null;
|
|
564
|
+
return log;
|
|
565
|
+
}
|
|
566
|
+
var createScheduler;
|
|
567
|
+
var hasRequiredCreateScheduler;
|
|
568
|
+
function requireCreateScheduler() {
|
|
569
|
+
if (hasRequiredCreateScheduler) return createScheduler;
|
|
570
|
+
hasRequiredCreateScheduler = 1;
|
|
571
|
+
const createJob2 = requireCreateJob();
|
|
572
|
+
const { log: log2 } = requireLog();
|
|
573
|
+
const getId2 = requireGetId();
|
|
574
|
+
let schedulerCounter = 0;
|
|
575
|
+
createScheduler = () => {
|
|
576
|
+
const id = getId2("Scheduler", schedulerCounter);
|
|
577
|
+
const workers = {};
|
|
578
|
+
const runningWorkers = {};
|
|
579
|
+
let jobQueue = [];
|
|
580
|
+
schedulerCounter += 1;
|
|
581
|
+
const getQueueLen = () => jobQueue.length;
|
|
582
|
+
const getNumWorkers = () => Object.keys(workers).length;
|
|
583
|
+
const dequeue = () => {
|
|
584
|
+
if (jobQueue.length !== 0) {
|
|
585
|
+
const wIds = Object.keys(workers);
|
|
586
|
+
for (let i = 0; i < wIds.length; i += 1) {
|
|
587
|
+
if (typeof runningWorkers[wIds[i]] === "undefined") {
|
|
588
|
+
jobQueue[0](workers[wIds[i]]);
|
|
589
|
+
break;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
575
592
|
}
|
|
593
|
+
};
|
|
594
|
+
const queue = (action, payload) => new Promise((resolve, reject) => {
|
|
595
|
+
const job = createJob2({ action, payload });
|
|
596
|
+
jobQueue.push(async (w) => {
|
|
597
|
+
jobQueue.shift();
|
|
598
|
+
runningWorkers[w.id] = job;
|
|
599
|
+
try {
|
|
600
|
+
resolve(await w[action].apply(this, [...payload, job.id]));
|
|
601
|
+
} catch (err) {
|
|
602
|
+
reject(err);
|
|
603
|
+
} finally {
|
|
604
|
+
delete runningWorkers[w.id];
|
|
605
|
+
dequeue();
|
|
606
|
+
}
|
|
607
|
+
});
|
|
608
|
+
log2(`[${id}]: Add ${job.id} to JobQueue`);
|
|
609
|
+
log2(`[${id}]: JobQueue length=${jobQueue.length}`);
|
|
610
|
+
dequeue();
|
|
576
611
|
});
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
612
|
+
const addWorker = (w) => {
|
|
613
|
+
workers[w.id] = w;
|
|
614
|
+
log2(`[${id}]: Add ${w.id}`);
|
|
615
|
+
log2(`[${id}]: Number of workers=${getNumWorkers()}`);
|
|
616
|
+
dequeue();
|
|
617
|
+
return w.id;
|
|
618
|
+
};
|
|
619
|
+
const addJob = async (action, ...payload) => {
|
|
620
|
+
if (getNumWorkers() === 0) {
|
|
621
|
+
throw Error(`[${id}]: You need to have at least one worker before adding jobs`);
|
|
622
|
+
}
|
|
623
|
+
return queue(action, payload);
|
|
624
|
+
};
|
|
625
|
+
const terminate = async () => {
|
|
626
|
+
Object.keys(workers).forEach(async (wid) => {
|
|
627
|
+
await workers[wid].terminate();
|
|
628
|
+
});
|
|
629
|
+
jobQueue = [];
|
|
630
|
+
};
|
|
631
|
+
return {
|
|
632
|
+
addWorker,
|
|
633
|
+
addJob,
|
|
634
|
+
terminate,
|
|
635
|
+
getQueueLen,
|
|
636
|
+
getNumWorkers
|
|
637
|
+
};
|
|
587
638
|
};
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
639
|
+
return createScheduler;
|
|
640
|
+
}
|
|
641
|
+
function commonjsRequire(path) {
|
|
642
|
+
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
|
|
643
|
+
}
|
|
644
|
+
var getEnvironment;
|
|
645
|
+
var hasRequiredGetEnvironment;
|
|
646
|
+
function requireGetEnvironment() {
|
|
647
|
+
if (hasRequiredGetEnvironment) return getEnvironment;
|
|
648
|
+
hasRequiredGetEnvironment = 1;
|
|
649
|
+
getEnvironment = (key) => {
|
|
650
|
+
const env = {};
|
|
651
|
+
if (typeof WorkerGlobalScope !== "undefined") {
|
|
652
|
+
env.type = "webworker";
|
|
653
|
+
} else if (typeof document === "object") {
|
|
654
|
+
env.type = "browser";
|
|
655
|
+
} else if (typeof process === "object" && typeof commonjsRequire === "function") {
|
|
656
|
+
env.type = "node";
|
|
591
657
|
}
|
|
592
|
-
|
|
658
|
+
if (typeof key === "undefined") {
|
|
659
|
+
return env;
|
|
660
|
+
}
|
|
661
|
+
return env[key];
|
|
593
662
|
};
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
663
|
+
return getEnvironment;
|
|
664
|
+
}
|
|
665
|
+
var resolvePaths;
|
|
666
|
+
var hasRequiredResolvePaths;
|
|
667
|
+
function requireResolvePaths() {
|
|
668
|
+
if (hasRequiredResolvePaths) return resolvePaths;
|
|
669
|
+
hasRequiredResolvePaths = 1;
|
|
670
|
+
const isBrowser = requireGetEnvironment()("type") === "browser";
|
|
671
|
+
const resolveURL = isBrowser ? (s) => new URL(s, window.location.href).href : (s) => s;
|
|
672
|
+
resolvePaths = (options) => {
|
|
673
|
+
const opts = { ...options };
|
|
674
|
+
["corePath", "workerPath", "langPath"].forEach((key) => {
|
|
675
|
+
if (options[key]) {
|
|
676
|
+
opts[key] = resolveURL(opts[key]);
|
|
677
|
+
}
|
|
597
678
|
});
|
|
598
|
-
|
|
679
|
+
return opts;
|
|
599
680
|
};
|
|
600
|
-
return
|
|
601
|
-
addWorker,
|
|
602
|
-
addJob,
|
|
603
|
-
terminate,
|
|
604
|
-
getQueueLen,
|
|
605
|
-
getNumWorkers
|
|
606
|
-
};
|
|
607
|
-
};
|
|
608
|
-
function commonjsRequire(path) {
|
|
609
|
-
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
|
|
681
|
+
return resolvePaths;
|
|
610
682
|
}
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
683
|
+
var OEM;
|
|
684
|
+
var hasRequiredOEM;
|
|
685
|
+
function requireOEM() {
|
|
686
|
+
if (hasRequiredOEM) return OEM;
|
|
687
|
+
hasRequiredOEM = 1;
|
|
688
|
+
OEM = {
|
|
689
|
+
TESSERACT_ONLY: 0,
|
|
690
|
+
LSTM_ONLY: 1,
|
|
691
|
+
TESSERACT_LSTM_COMBINED: 2,
|
|
692
|
+
DEFAULT: 3
|
|
693
|
+
};
|
|
694
|
+
return OEM;
|
|
622
695
|
}
|
|
623
|
-
|
|
624
|
-
const
|
|
625
|
-
|
|
626
|
-
const env = {};
|
|
627
|
-
if (typeof WorkerGlobalScope !== "undefined") {
|
|
628
|
-
env.type = "webworker";
|
|
629
|
-
} else if (isElectron()) {
|
|
630
|
-
env.type = "electron";
|
|
631
|
-
} else if (typeof document === "object") {
|
|
632
|
-
env.type = "browser";
|
|
633
|
-
} else if (typeof process === "object" && typeof commonjsRequire === "function") {
|
|
634
|
-
env.type = "node";
|
|
635
|
-
}
|
|
636
|
-
if (typeof key === "undefined") {
|
|
637
|
-
return env;
|
|
638
|
-
}
|
|
639
|
-
return env[key];
|
|
696
|
+
const version = "6.0.0";
|
|
697
|
+
const require$$0 = {
|
|
698
|
+
version
|
|
640
699
|
};
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
700
|
+
var defaultOptions;
|
|
701
|
+
var hasRequiredDefaultOptions$1;
|
|
702
|
+
function requireDefaultOptions$1() {
|
|
703
|
+
if (hasRequiredDefaultOptions$1) return defaultOptions;
|
|
704
|
+
hasRequiredDefaultOptions$1 = 1;
|
|
705
|
+
defaultOptions = {
|
|
706
|
+
/*
|
|
707
|
+
* Use BlobURL for worker script by default
|
|
708
|
+
* TODO: remove this option
|
|
709
|
+
*
|
|
710
|
+
*/
|
|
711
|
+
workerBlobURL: true,
|
|
712
|
+
logger: () => {
|
|
648
713
|
}
|
|
649
|
-
}
|
|
650
|
-
return
|
|
651
|
-
}
|
|
652
|
-
var
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
const
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
page,
|
|
676
|
-
block,
|
|
677
|
-
paragraph,
|
|
678
|
-
line
|
|
679
|
-
});
|
|
680
|
-
});
|
|
681
|
-
lines.push({
|
|
682
|
-
...line,
|
|
683
|
-
page,
|
|
684
|
-
block,
|
|
685
|
-
paragraph
|
|
686
|
-
});
|
|
687
|
-
});
|
|
688
|
-
paragraphs.push({
|
|
689
|
-
...paragraph,
|
|
690
|
-
page,
|
|
691
|
-
block
|
|
692
|
-
});
|
|
693
|
-
});
|
|
694
|
-
blocks.push({
|
|
695
|
-
...block,
|
|
696
|
-
page
|
|
714
|
+
};
|
|
715
|
+
return defaultOptions;
|
|
716
|
+
}
|
|
717
|
+
var defaultOptions_1;
|
|
718
|
+
var hasRequiredDefaultOptions;
|
|
719
|
+
function requireDefaultOptions() {
|
|
720
|
+
if (hasRequiredDefaultOptions) return defaultOptions_1;
|
|
721
|
+
hasRequiredDefaultOptions = 1;
|
|
722
|
+
const version2 = require$$0.version;
|
|
723
|
+
const defaultOptions2 = requireDefaultOptions$1();
|
|
724
|
+
defaultOptions_1 = {
|
|
725
|
+
...defaultOptions2,
|
|
726
|
+
workerPath: `https://cdn.jsdelivr.net/npm/tesseract.js@v${version2}/dist/worker.min.js`
|
|
727
|
+
};
|
|
728
|
+
return defaultOptions_1;
|
|
729
|
+
}
|
|
730
|
+
var spawnWorker;
|
|
731
|
+
var hasRequiredSpawnWorker;
|
|
732
|
+
function requireSpawnWorker() {
|
|
733
|
+
if (hasRequiredSpawnWorker) return spawnWorker;
|
|
734
|
+
hasRequiredSpawnWorker = 1;
|
|
735
|
+
spawnWorker = ({ workerPath, workerBlobURL }) => {
|
|
736
|
+
let worker;
|
|
737
|
+
if (Blob && URL && workerBlobURL) {
|
|
738
|
+
const blob = new Blob([`importScripts("${workerPath}");`], {
|
|
739
|
+
type: "application/javascript"
|
|
697
740
|
});
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
paragraphs,
|
|
704
|
-
lines,
|
|
705
|
-
words,
|
|
706
|
-
symbols
|
|
741
|
+
worker = new Worker(URL.createObjectURL(blob));
|
|
742
|
+
} else {
|
|
743
|
+
worker = new Worker(workerPath);
|
|
744
|
+
}
|
|
745
|
+
return worker;
|
|
707
746
|
};
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
const description = "Pure Javascript Multilingual OCR";
|
|
718
|
-
const main = "src/index.js";
|
|
719
|
-
const types = "src/index.d.ts";
|
|
720
|
-
const unpkg = "dist/tesseract.min.js";
|
|
721
|
-
const jsdelivr = "dist/tesseract.min.js";
|
|
722
|
-
const scripts = {
|
|
723
|
-
start: "node scripts/server.js",
|
|
724
|
-
build: "rimraf dist && webpack --config scripts/webpack.config.prod.js && rollup -c scripts/rollup.esm.mjs",
|
|
725
|
-
"profile:tesseract": "webpack-bundle-analyzer dist/tesseract-stats.json",
|
|
726
|
-
"profile:worker": "webpack-bundle-analyzer dist/worker-stats.json",
|
|
727
|
-
prepublishOnly: "npm run build",
|
|
728
|
-
wait: "rimraf dist && wait-on http://localhost:3000/dist/tesseract.min.js",
|
|
729
|
-
test: "npm-run-all -p -r start test:all",
|
|
730
|
-
"test:all": "npm-run-all wait test:browser:* test:node:all",
|
|
731
|
-
"test:node": "nyc mocha --exit --bail --require ./scripts/test-helper.js",
|
|
732
|
-
"test:node:all": "npm run test:node -- ./tests/*.test.js",
|
|
733
|
-
"test:browser-tpl": "mocha-headless-chrome -a incognito -a no-sandbox -a disable-setuid-sandbox -a disable-logging -t 300000",
|
|
734
|
-
"test:browser:detect": "npm run test:browser-tpl -- -f ./tests/detect.test.html",
|
|
735
|
-
"test:browser:recognize": "npm run test:browser-tpl -- -f ./tests/recognize.test.html",
|
|
736
|
-
"test:browser:scheduler": "npm run test:browser-tpl -- -f ./tests/scheduler.test.html",
|
|
737
|
-
"test:browser:FS": "npm run test:browser-tpl -- -f ./tests/FS.test.html",
|
|
738
|
-
lint: "eslint src",
|
|
739
|
-
"lint:fix": "eslint --fix src",
|
|
740
|
-
postinstall: "opencollective-postinstall || true"
|
|
741
|
-
};
|
|
742
|
-
const browser$1 = {
|
|
743
|
-
"./src/worker/node/index.js": "./src/worker/browser/index.js"
|
|
744
|
-
};
|
|
745
|
-
const author = "";
|
|
746
|
-
const contributors = [
|
|
747
|
-
"jeromewu"
|
|
748
|
-
];
|
|
749
|
-
const license = "Apache-2.0";
|
|
750
|
-
const devDependencies = {
|
|
751
|
-
"@babel/core": "^7.21.4",
|
|
752
|
-
"@babel/eslint-parser": "^7.21.3",
|
|
753
|
-
"@babel/preset-env": "^7.21.4",
|
|
754
|
-
"@rollup/plugin-commonjs": "^24.1.0",
|
|
755
|
-
acorn: "^8.8.2",
|
|
756
|
-
"babel-loader": "^9.1.2",
|
|
757
|
-
buffer: "^6.0.3",
|
|
758
|
-
cors: "^2.8.5",
|
|
759
|
-
eslint: "^7.32.0",
|
|
760
|
-
"eslint-config-airbnb-base": "^14.2.1",
|
|
761
|
-
"eslint-plugin-import": "^2.27.5",
|
|
762
|
-
"expect.js": "^0.3.1",
|
|
763
|
-
express: "^4.18.2",
|
|
764
|
-
mocha: "^10.2.0",
|
|
765
|
-
"mocha-headless-chrome": "^4.0.0",
|
|
766
|
-
"npm-run-all": "^4.1.5",
|
|
767
|
-
nyc: "^15.1.0",
|
|
768
|
-
rimraf: "^5.0.0",
|
|
769
|
-
rollup: "^3.20.7",
|
|
770
|
-
"wait-on": "^7.0.1",
|
|
771
|
-
webpack: "^5.79.0",
|
|
772
|
-
"webpack-bundle-analyzer": "^4.8.0",
|
|
773
|
-
"webpack-cli": "^5.0.1",
|
|
774
|
-
"webpack-dev-middleware": "^6.0.2",
|
|
775
|
-
"rollup-plugin-sourcemaps": "^0.6.3"
|
|
776
|
-
};
|
|
777
|
-
const dependencies = {
|
|
778
|
-
"bmp-js": "^0.1.0",
|
|
779
|
-
"idb-keyval": "^6.2.0",
|
|
780
|
-
"is-electron": "^2.2.2",
|
|
781
|
-
"is-url": "^1.2.4",
|
|
782
|
-
"node-fetch": "^2.6.9",
|
|
783
|
-
"opencollective-postinstall": "^2.0.3",
|
|
784
|
-
"regenerator-runtime": "^0.13.3",
|
|
785
|
-
"tesseract.js-core": "^5.1.0",
|
|
786
|
-
"wasm-feature-detect": "^1.2.11",
|
|
787
|
-
zlibjs: "^0.3.1"
|
|
788
|
-
};
|
|
789
|
-
const overrides = {
|
|
790
|
-
"@rollup/pluginutils": "^5.0.2"
|
|
791
|
-
};
|
|
792
|
-
const repository = {
|
|
793
|
-
type: "git",
|
|
794
|
-
url: "https://github.com/naptha/tesseract.js.git"
|
|
795
|
-
};
|
|
796
|
-
const bugs = {
|
|
797
|
-
url: "https://github.com/naptha/tesseract.js/issues"
|
|
798
|
-
};
|
|
799
|
-
const homepage = "https://github.com/naptha/tesseract.js";
|
|
800
|
-
const collective = {
|
|
801
|
-
type: "opencollective",
|
|
802
|
-
url: "https://opencollective.com/tesseractjs"
|
|
803
|
-
};
|
|
804
|
-
const require$$0 = {
|
|
805
|
-
name,
|
|
806
|
-
version: version$1,
|
|
807
|
-
description,
|
|
808
|
-
main,
|
|
809
|
-
types,
|
|
810
|
-
unpkg,
|
|
811
|
-
jsdelivr,
|
|
812
|
-
scripts,
|
|
813
|
-
browser: browser$1,
|
|
814
|
-
author,
|
|
815
|
-
contributors,
|
|
816
|
-
license,
|
|
817
|
-
devDependencies,
|
|
818
|
-
dependencies,
|
|
819
|
-
overrides,
|
|
820
|
-
repository,
|
|
821
|
-
bugs,
|
|
822
|
-
homepage,
|
|
823
|
-
collective
|
|
824
|
-
};
|
|
825
|
-
var defaultOptions$3 = {
|
|
826
|
-
/*
|
|
827
|
-
* Use BlobURL for worker script by default
|
|
828
|
-
* TODO: remove this option
|
|
829
|
-
*
|
|
830
|
-
*/
|
|
831
|
-
workerBlobURL: true,
|
|
832
|
-
logger: () => {
|
|
833
|
-
}
|
|
834
|
-
};
|
|
835
|
-
const version = require$$0.version;
|
|
836
|
-
const defaultOptions$2 = defaultOptions$3;
|
|
837
|
-
var defaultOptions_1 = {
|
|
838
|
-
...defaultOptions$2,
|
|
839
|
-
workerPath: `https://cdn.jsdelivr.net/npm/tesseract.js@v${version}/dist/worker.min.js`
|
|
840
|
-
};
|
|
841
|
-
var spawnWorker$2 = ({ workerPath, workerBlobURL }) => {
|
|
842
|
-
let worker;
|
|
843
|
-
if (Blob && URL && workerBlobURL) {
|
|
844
|
-
const blob = new Blob([`importScripts("${workerPath}");`], {
|
|
845
|
-
type: "application/javascript"
|
|
846
|
-
});
|
|
847
|
-
worker = new Worker(URL.createObjectURL(blob));
|
|
848
|
-
} else {
|
|
849
|
-
worker = new Worker(workerPath);
|
|
850
|
-
}
|
|
851
|
-
return worker;
|
|
852
|
-
};
|
|
853
|
-
var terminateWorker$2 = (worker) => {
|
|
854
|
-
worker.terminate();
|
|
855
|
-
};
|
|
856
|
-
var onMessage$2 = (worker, handler) => {
|
|
857
|
-
worker.onmessage = ({ data }) => {
|
|
858
|
-
handler(data);
|
|
747
|
+
return spawnWorker;
|
|
748
|
+
}
|
|
749
|
+
var terminateWorker;
|
|
750
|
+
var hasRequiredTerminateWorker;
|
|
751
|
+
function requireTerminateWorker() {
|
|
752
|
+
if (hasRequiredTerminateWorker) return terminateWorker;
|
|
753
|
+
hasRequiredTerminateWorker = 1;
|
|
754
|
+
terminateWorker = (worker) => {
|
|
755
|
+
worker.terminate();
|
|
859
756
|
};
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
757
|
+
return terminateWorker;
|
|
758
|
+
}
|
|
759
|
+
var onMessage;
|
|
760
|
+
var hasRequiredOnMessage;
|
|
761
|
+
function requireOnMessage() {
|
|
762
|
+
if (hasRequiredOnMessage) return onMessage;
|
|
763
|
+
hasRequiredOnMessage = 1;
|
|
764
|
+
onMessage = (worker, handler) => {
|
|
765
|
+
worker.onmessage = ({ data }) => {
|
|
766
|
+
handler(data);
|
|
767
|
+
};
|
|
868
768
|
};
|
|
869
|
-
|
|
870
|
-
|
|
769
|
+
return onMessage;
|
|
770
|
+
}
|
|
771
|
+
var send;
|
|
772
|
+
var hasRequiredSend;
|
|
773
|
+
function requireSend() {
|
|
774
|
+
if (hasRequiredSend) return send;
|
|
775
|
+
hasRequiredSend = 1;
|
|
776
|
+
send = async (worker, packet) => {
|
|
777
|
+
worker.postMessage(packet);
|
|
871
778
|
};
|
|
872
|
-
|
|
873
|
-
}
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
779
|
+
return send;
|
|
780
|
+
}
|
|
781
|
+
var loadImage_1;
|
|
782
|
+
var hasRequiredLoadImage;
|
|
783
|
+
function requireLoadImage() {
|
|
784
|
+
if (hasRequiredLoadImage) return loadImage_1;
|
|
785
|
+
hasRequiredLoadImage = 1;
|
|
786
|
+
const readFromBlobOrFile = (blob) => new Promise((resolve, reject) => {
|
|
787
|
+
const fileReader = new FileReader();
|
|
788
|
+
fileReader.onload = () => {
|
|
789
|
+
resolve(fileReader.result);
|
|
790
|
+
};
|
|
791
|
+
fileReader.onerror = ({ target: { error: { code } } }) => {
|
|
792
|
+
reject(Error(`File could not be read! Code=${code}`));
|
|
793
|
+
};
|
|
794
|
+
fileReader.readAsArrayBuffer(blob);
|
|
795
|
+
});
|
|
796
|
+
const loadImage = async (image) => {
|
|
797
|
+
let data = image;
|
|
798
|
+
if (typeof image === "undefined") {
|
|
799
|
+
return "undefined";
|
|
892
800
|
}
|
|
893
|
-
if (image
|
|
894
|
-
|
|
895
|
-
image.
|
|
896
|
-
|
|
897
|
-
|
|
801
|
+
if (typeof image === "string") {
|
|
802
|
+
if (/data:image\/([a-zA-Z]*);base64,([^"]*)/.test(image)) {
|
|
803
|
+
data = atob(image.split(",")[1]).split("").map((c) => c.charCodeAt(0));
|
|
804
|
+
} else {
|
|
805
|
+
const resp = await fetch(image);
|
|
806
|
+
data = await resp.arrayBuffer();
|
|
807
|
+
}
|
|
808
|
+
} else if (typeof HTMLElement !== "undefined" && image instanceof HTMLElement) {
|
|
809
|
+
if (image.tagName === "IMG") {
|
|
810
|
+
data = await loadImage(image.src);
|
|
811
|
+
}
|
|
812
|
+
if (image.tagName === "VIDEO") {
|
|
813
|
+
data = await loadImage(image.poster);
|
|
814
|
+
}
|
|
815
|
+
if (image.tagName === "CANVAS") {
|
|
816
|
+
await new Promise((resolve) => {
|
|
817
|
+
image.toBlob(async (blob) => {
|
|
818
|
+
data = await readFromBlobOrFile(blob);
|
|
819
|
+
resolve();
|
|
820
|
+
});
|
|
898
821
|
});
|
|
899
|
-
}
|
|
822
|
+
}
|
|
823
|
+
} else if (typeof OffscreenCanvas !== "undefined" && image instanceof OffscreenCanvas) {
|
|
824
|
+
const blob = await image.convertToBlob();
|
|
825
|
+
data = await readFromBlobOrFile(blob);
|
|
826
|
+
} else if (image instanceof File || image instanceof Blob) {
|
|
827
|
+
data = await readFromBlobOrFile(image);
|
|
900
828
|
}
|
|
901
|
-
|
|
902
|
-
const blob = await image.convertToBlob();
|
|
903
|
-
data = await readFromBlobOrFile(blob);
|
|
904
|
-
} else if (image instanceof File || image instanceof Blob) {
|
|
905
|
-
data = await readFromBlobOrFile(image);
|
|
906
|
-
}
|
|
907
|
-
return new Uint8Array(data);
|
|
908
|
-
};
|
|
909
|
-
var loadImage_1 = loadImage$2;
|
|
910
|
-
const defaultOptions$1 = defaultOptions_1;
|
|
911
|
-
const spawnWorker$1 = spawnWorker$2;
|
|
912
|
-
const terminateWorker$1 = terminateWorker$2;
|
|
913
|
-
const onMessage$1 = onMessage$2;
|
|
914
|
-
const send$1 = send$2;
|
|
915
|
-
const loadImage$1 = loadImage_1;
|
|
916
|
-
var browser = {
|
|
917
|
-
defaultOptions: defaultOptions$1,
|
|
918
|
-
spawnWorker: spawnWorker$1,
|
|
919
|
-
terminateWorker: terminateWorker$1,
|
|
920
|
-
onMessage: onMessage$1,
|
|
921
|
-
send: send$1,
|
|
922
|
-
loadImage: loadImage$1
|
|
923
|
-
};
|
|
924
|
-
const resolvePaths = resolvePaths$1;
|
|
925
|
-
const circularize = circularize$1;
|
|
926
|
-
const createJob = createJob$2;
|
|
927
|
-
const { log } = log$2;
|
|
928
|
-
const getId = getId$3;
|
|
929
|
-
const OEM$1 = OEM$2;
|
|
930
|
-
const {
|
|
931
|
-
defaultOptions,
|
|
932
|
-
spawnWorker,
|
|
933
|
-
terminateWorker,
|
|
934
|
-
onMessage,
|
|
935
|
-
loadImage,
|
|
936
|
-
send
|
|
937
|
-
} = browser;
|
|
938
|
-
let workerCounter = 0;
|
|
939
|
-
var createWorker$2 = async (langs = "eng", oem = OEM$1.LSTM_ONLY, _options = {}, config = {}) => {
|
|
940
|
-
const id = getId("Worker", workerCounter);
|
|
941
|
-
const {
|
|
942
|
-
logger,
|
|
943
|
-
errorHandler,
|
|
944
|
-
...options
|
|
945
|
-
} = resolvePaths({
|
|
946
|
-
...defaultOptions,
|
|
947
|
-
..._options
|
|
948
|
-
});
|
|
949
|
-
const resolves = {};
|
|
950
|
-
const rejects = {};
|
|
951
|
-
const currentLangs = typeof langs === "string" ? langs.split("+") : langs;
|
|
952
|
-
let currentOem = oem;
|
|
953
|
-
let currentConfig = config;
|
|
954
|
-
const lstmOnlyCore = [OEM$1.DEFAULT, OEM$1.LSTM_ONLY].includes(oem) && !options.legacyCore;
|
|
955
|
-
let workerResReject;
|
|
956
|
-
let workerResResolve;
|
|
957
|
-
const workerRes = new Promise((resolve, reject) => {
|
|
958
|
-
workerResResolve = resolve;
|
|
959
|
-
workerResReject = reject;
|
|
960
|
-
});
|
|
961
|
-
const workerError = (event) => {
|
|
962
|
-
workerResReject(event.message);
|
|
963
|
-
};
|
|
964
|
-
let worker = spawnWorker(options);
|
|
965
|
-
worker.onerror = workerError;
|
|
966
|
-
workerCounter += 1;
|
|
967
|
-
const setResolve = (promiseId, res) => {
|
|
968
|
-
resolves[promiseId] = res;
|
|
829
|
+
return new Uint8Array(data);
|
|
969
830
|
};
|
|
970
|
-
|
|
971
|
-
|
|
831
|
+
loadImage_1 = loadImage;
|
|
832
|
+
return loadImage_1;
|
|
833
|
+
}
|
|
834
|
+
var browser;
|
|
835
|
+
var hasRequiredBrowser;
|
|
836
|
+
function requireBrowser() {
|
|
837
|
+
if (hasRequiredBrowser) return browser;
|
|
838
|
+
hasRequiredBrowser = 1;
|
|
839
|
+
const defaultOptions2 = requireDefaultOptions();
|
|
840
|
+
const spawnWorker2 = requireSpawnWorker();
|
|
841
|
+
const terminateWorker2 = requireTerminateWorker();
|
|
842
|
+
const onMessage2 = requireOnMessage();
|
|
843
|
+
const send2 = requireSend();
|
|
844
|
+
const loadImage = requireLoadImage();
|
|
845
|
+
browser = {
|
|
846
|
+
defaultOptions: defaultOptions2,
|
|
847
|
+
spawnWorker: spawnWorker2,
|
|
848
|
+
terminateWorker: terminateWorker2,
|
|
849
|
+
onMessage: onMessage2,
|
|
850
|
+
send: send2,
|
|
851
|
+
loadImage
|
|
972
852
|
};
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
853
|
+
return browser;
|
|
854
|
+
}
|
|
855
|
+
var createWorker;
|
|
856
|
+
var hasRequiredCreateWorker;
|
|
857
|
+
function requireCreateWorker() {
|
|
858
|
+
if (hasRequiredCreateWorker) return createWorker;
|
|
859
|
+
hasRequiredCreateWorker = 1;
|
|
860
|
+
const resolvePaths2 = requireResolvePaths();
|
|
861
|
+
const createJob2 = requireCreateJob();
|
|
862
|
+
const { log: log2 } = requireLog();
|
|
863
|
+
const getId2 = requireGetId();
|
|
864
|
+
const OEM2 = requireOEM();
|
|
865
|
+
const {
|
|
866
|
+
defaultOptions: defaultOptions2,
|
|
867
|
+
spawnWorker: spawnWorker2,
|
|
868
|
+
terminateWorker: terminateWorker2,
|
|
869
|
+
onMessage: onMessage2,
|
|
870
|
+
loadImage,
|
|
871
|
+
send: send2
|
|
872
|
+
} = requireBrowser();
|
|
873
|
+
let workerCounter = 0;
|
|
874
|
+
createWorker = async (langs = "eng", oem = OEM2.LSTM_ONLY, _options = {}, config = {}) => {
|
|
875
|
+
const id = getId2("Worker", workerCounter);
|
|
876
|
+
const {
|
|
877
|
+
logger,
|
|
878
|
+
errorHandler,
|
|
879
|
+
...options
|
|
880
|
+
} = resolvePaths2({
|
|
881
|
+
...defaultOptions2,
|
|
882
|
+
..._options
|
|
983
883
|
});
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
884
|
+
const promises = {};
|
|
885
|
+
const currentLangs = typeof langs === "string" ? langs.split("+") : langs;
|
|
886
|
+
let currentOem = oem;
|
|
887
|
+
let currentConfig = config;
|
|
888
|
+
const lstmOnlyCore = [OEM2.DEFAULT, OEM2.LSTM_ONLY].includes(oem) && !options.legacyCore;
|
|
889
|
+
let workerResReject;
|
|
890
|
+
let workerResResolve;
|
|
891
|
+
const workerRes = new Promise((resolve, reject) => {
|
|
892
|
+
workerResResolve = resolve;
|
|
893
|
+
workerResReject = reject;
|
|
894
|
+
});
|
|
895
|
+
const workerError = (event) => {
|
|
896
|
+
workerResReject(event.message);
|
|
897
|
+
};
|
|
898
|
+
let worker = spawnWorker2(options);
|
|
899
|
+
worker.onerror = workerError;
|
|
900
|
+
workerCounter += 1;
|
|
901
|
+
const startJob = ({ id: jobId, action, payload }) => new Promise((resolve, reject) => {
|
|
902
|
+
log2(`[${id}]: Start ${jobId}, action=${action}`);
|
|
903
|
+
const promiseId = `${action}-${jobId}`;
|
|
904
|
+
promises[promiseId] = { resolve, reject };
|
|
905
|
+
send2(worker, {
|
|
906
|
+
workerId: id,
|
|
907
|
+
jobId,
|
|
908
|
+
action,
|
|
909
|
+
payload
|
|
910
|
+
});
|
|
911
|
+
});
|
|
912
|
+
const load = () => console.warn("`load` is depreciated and should be removed from code (workers now come pre-loaded)");
|
|
913
|
+
const loadInternal = (jobId) => startJob(createJob2({
|
|
914
|
+
id: jobId,
|
|
915
|
+
action: "load",
|
|
916
|
+
payload: { options: { lstmOnly: lstmOnlyCore, corePath: options.corePath, logging: options.logging } }
|
|
917
|
+
}));
|
|
918
|
+
const writeText = (path, text, jobId) => startJob(createJob2({
|
|
919
|
+
id: jobId,
|
|
920
|
+
action: "FS",
|
|
921
|
+
payload: { method: "writeFile", args: [path, text] }
|
|
922
|
+
}));
|
|
923
|
+
const readText = (path, jobId) => startJob(createJob2({
|
|
924
|
+
id: jobId,
|
|
925
|
+
action: "FS",
|
|
926
|
+
payload: { method: "readFile", args: [path, { encoding: "utf8" }] }
|
|
927
|
+
}));
|
|
928
|
+
const removeFile = (path, jobId) => startJob(createJob2({
|
|
929
|
+
id: jobId,
|
|
930
|
+
action: "FS",
|
|
931
|
+
payload: { method: "unlink", args: [path] }
|
|
932
|
+
}));
|
|
933
|
+
const FS = (method, args, jobId) => startJob(createJob2({
|
|
934
|
+
id: jobId,
|
|
935
|
+
action: "FS",
|
|
936
|
+
payload: { method, args }
|
|
937
|
+
}));
|
|
938
|
+
const loadLanguageInternal = (_langs, jobId) => startJob(createJob2({
|
|
939
|
+
id: jobId,
|
|
940
|
+
action: "loadLanguage",
|
|
941
|
+
payload: {
|
|
942
|
+
langs: _langs,
|
|
943
|
+
options: {
|
|
944
|
+
langPath: options.langPath,
|
|
945
|
+
dataPath: options.dataPath,
|
|
946
|
+
cachePath: options.cachePath,
|
|
947
|
+
cacheMethod: options.cacheMethod,
|
|
948
|
+
gzip: options.gzip,
|
|
949
|
+
lstmOnly: [OEM2.DEFAULT, OEM2.LSTM_ONLY].includes(currentOem) && !options.legacyLang
|
|
950
|
+
}
|
|
1024
951
|
}
|
|
1025
|
-
}
|
|
1026
|
-
|
|
1027
|
-
const initialize = () => console.warn("`initialize` is depreciated and should be removed from code (workers now come pre-initialized)");
|
|
1028
|
-
const initializeInternal = (_langs, _oem, _config, jobId) => startJob(createJob({
|
|
1029
|
-
id: jobId,
|
|
1030
|
-
action: "initialize",
|
|
1031
|
-
payload: { langs: _langs, oem: _oem, config: _config }
|
|
1032
|
-
}));
|
|
1033
|
-
const reinitialize = (langs2 = "eng", oem2, config2, jobId) => {
|
|
1034
|
-
if (lstmOnlyCore && [OEM$1.TESSERACT_ONLY, OEM$1.TESSERACT_LSTM_COMBINED].includes(oem2)) throw Error("Legacy model requested but code missing.");
|
|
1035
|
-
const _oem = oem2 || currentOem;
|
|
1036
|
-
currentOem = _oem;
|
|
1037
|
-
const _config = config2 || currentConfig;
|
|
1038
|
-
currentConfig = _config;
|
|
1039
|
-
const langsArr = typeof langs2 === "string" ? langs2.split("+") : langs2;
|
|
1040
|
-
const _langs = langsArr.filter((x) => !currentLangs.includes(x));
|
|
1041
|
-
currentLangs.push(..._langs);
|
|
1042
|
-
if (_langs.length > 0) {
|
|
1043
|
-
return loadLanguageInternal(_langs, jobId).then(() => initializeInternal(langs2, _oem, _config, jobId));
|
|
1044
|
-
}
|
|
1045
|
-
return initializeInternal(langs2, _oem, _config, jobId);
|
|
1046
|
-
};
|
|
1047
|
-
const setParameters = (params = {}, jobId) => startJob(createJob({
|
|
1048
|
-
id: jobId,
|
|
1049
|
-
action: "setParameters",
|
|
1050
|
-
payload: { params }
|
|
1051
|
-
}));
|
|
1052
|
-
const recognize2 = async (image, opts = {}, output = {
|
|
1053
|
-
blocks: true,
|
|
1054
|
-
text: true,
|
|
1055
|
-
hocr: true,
|
|
1056
|
-
tsv: true
|
|
1057
|
-
}, jobId) => startJob(createJob({
|
|
1058
|
-
id: jobId,
|
|
1059
|
-
action: "recognize",
|
|
1060
|
-
payload: { image: await loadImage(image), options: opts, output }
|
|
1061
|
-
}));
|
|
1062
|
-
const getPDF = (title = "Tesseract OCR Result", textonly = false, jobId) => {
|
|
1063
|
-
return startJob(createJob({
|
|
952
|
+
}));
|
|
953
|
+
const initializeInternal = (_langs, _oem, _config, jobId) => startJob(createJob2({
|
|
1064
954
|
id: jobId,
|
|
1065
|
-
action: "
|
|
1066
|
-
payload: {
|
|
955
|
+
action: "initialize",
|
|
956
|
+
payload: { langs: _langs, oem: _oem, config: _config }
|
|
1067
957
|
}));
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
958
|
+
const reinitialize = (langs2 = "eng", oem2, config2, jobId) => {
|
|
959
|
+
if (lstmOnlyCore && [OEM2.TESSERACT_ONLY, OEM2.TESSERACT_LSTM_COMBINED].includes(oem2)) throw Error("Legacy model requested but code missing.");
|
|
960
|
+
const _oem = oem2 || currentOem;
|
|
961
|
+
currentOem = _oem;
|
|
962
|
+
const _config = config2 || currentConfig;
|
|
963
|
+
currentConfig = _config;
|
|
964
|
+
const langsArr = typeof langs2 === "string" ? langs2.split("+") : langs2;
|
|
965
|
+
const _langs = langsArr.filter((x) => !currentLangs.includes(x));
|
|
966
|
+
currentLangs.push(..._langs);
|
|
967
|
+
if (_langs.length > 0) {
|
|
968
|
+
return loadLanguageInternal(_langs, jobId).then(() => initializeInternal(langs2, _oem, _config, jobId));
|
|
969
|
+
}
|
|
970
|
+
return initializeInternal(langs2, _oem, _config, jobId);
|
|
971
|
+
};
|
|
972
|
+
const setParameters = (params = {}, jobId) => startJob(createJob2({
|
|
1072
973
|
id: jobId,
|
|
1073
|
-
action: "
|
|
1074
|
-
payload: {
|
|
974
|
+
action: "setParameters",
|
|
975
|
+
payload: { params }
|
|
1075
976
|
}));
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
const
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
if (action === "recognize") {
|
|
1096
|
-
d = circularize(data);
|
|
1097
|
-
} else if (action === "getPDF") {
|
|
1098
|
-
d = Array.from({ ...data, length: Object.keys(data).length });
|
|
977
|
+
const recognize = async (image, opts = {}, output = {
|
|
978
|
+
text: true
|
|
979
|
+
}, jobId) => startJob(createJob2({
|
|
980
|
+
id: jobId,
|
|
981
|
+
action: "recognize",
|
|
982
|
+
payload: { image: await loadImage(image), options: opts, output }
|
|
983
|
+
}));
|
|
984
|
+
const detect = async (image, jobId) => {
|
|
985
|
+
if (lstmOnlyCore) throw Error("`worker.detect` requires Legacy model, which was not loaded.");
|
|
986
|
+
return startJob(createJob2({
|
|
987
|
+
id: jobId,
|
|
988
|
+
action: "detect",
|
|
989
|
+
payload: { image: await loadImage(image) }
|
|
990
|
+
}));
|
|
991
|
+
};
|
|
992
|
+
const terminate = async () => {
|
|
993
|
+
if (worker !== null) {
|
|
994
|
+
terminateWorker2(worker);
|
|
995
|
+
worker = null;
|
|
1099
996
|
}
|
|
1100
|
-
|
|
1101
|
-
}
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
997
|
+
return Promise.resolve();
|
|
998
|
+
};
|
|
999
|
+
onMessage2(worker, ({
|
|
1000
|
+
workerId,
|
|
1001
|
+
jobId,
|
|
1002
|
+
status,
|
|
1003
|
+
action,
|
|
1004
|
+
data
|
|
1005
|
+
}) => {
|
|
1006
|
+
const promiseId = `${action}-${jobId}`;
|
|
1007
|
+
if (status === "resolve") {
|
|
1008
|
+
log2(`[${workerId}]: Complete ${jobId}`);
|
|
1009
|
+
promises[promiseId].resolve({ jobId, data });
|
|
1010
|
+
delete promises[promiseId];
|
|
1011
|
+
} else if (status === "reject") {
|
|
1012
|
+
promises[promiseId].reject(data);
|
|
1013
|
+
delete promises[promiseId];
|
|
1014
|
+
if (action === "load") workerResReject(data);
|
|
1015
|
+
if (errorHandler) {
|
|
1016
|
+
errorHandler(data);
|
|
1017
|
+
} else {
|
|
1018
|
+
throw Error(data);
|
|
1019
|
+
}
|
|
1020
|
+
} else if (status === "progress") {
|
|
1021
|
+
logger({ ...data, userJobId: jobId });
|
|
1108
1022
|
}
|
|
1109
|
-
}
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
recognize: recognize2,
|
|
1128
|
-
getPDF,
|
|
1129
|
-
detect: detect2,
|
|
1130
|
-
terminate
|
|
1023
|
+
});
|
|
1024
|
+
const resolveObj = {
|
|
1025
|
+
id,
|
|
1026
|
+
worker,
|
|
1027
|
+
load,
|
|
1028
|
+
writeText,
|
|
1029
|
+
readText,
|
|
1030
|
+
removeFile,
|
|
1031
|
+
FS,
|
|
1032
|
+
reinitialize,
|
|
1033
|
+
setParameters,
|
|
1034
|
+
recognize,
|
|
1035
|
+
detect,
|
|
1036
|
+
terminate
|
|
1037
|
+
};
|
|
1038
|
+
loadInternal().then(() => loadLanguageInternal(langs)).then(() => initializeInternal(langs, oem, config)).then(() => workerResResolve(resolveObj)).catch(() => {
|
|
1039
|
+
});
|
|
1040
|
+
return workerRes;
|
|
1131
1041
|
};
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1042
|
+
return createWorker;
|
|
1043
|
+
}
|
|
1044
|
+
var Tesseract;
|
|
1045
|
+
var hasRequiredTesseract;
|
|
1046
|
+
function requireTesseract() {
|
|
1047
|
+
if (hasRequiredTesseract) return Tesseract;
|
|
1048
|
+
hasRequiredTesseract = 1;
|
|
1049
|
+
const createWorker2 = requireCreateWorker();
|
|
1050
|
+
const recognize = async (image, langs, options) => {
|
|
1051
|
+
const worker = await createWorker2(langs, 1, options);
|
|
1052
|
+
return worker.recognize(image).finally(async () => {
|
|
1053
|
+
await worker.terminate();
|
|
1054
|
+
});
|
|
1055
|
+
};
|
|
1056
|
+
const detect = async (image, options) => {
|
|
1057
|
+
const worker = await createWorker2("osd", 0, options);
|
|
1058
|
+
return worker.detect(image).finally(async () => {
|
|
1059
|
+
await worker.terminate();
|
|
1060
|
+
});
|
|
1061
|
+
};
|
|
1062
|
+
Tesseract = {
|
|
1063
|
+
recognize,
|
|
1064
|
+
detect
|
|
1065
|
+
};
|
|
1066
|
+
return Tesseract;
|
|
1067
|
+
}
|
|
1068
|
+
var languages;
|
|
1069
|
+
var hasRequiredLanguages;
|
|
1070
|
+
function requireLanguages() {
|
|
1071
|
+
if (hasRequiredLanguages) return languages;
|
|
1072
|
+
hasRequiredLanguages = 1;
|
|
1073
|
+
languages = {
|
|
1074
|
+
AFR: "afr",
|
|
1075
|
+
AMH: "amh",
|
|
1076
|
+
ARA: "ara",
|
|
1077
|
+
ASM: "asm",
|
|
1078
|
+
AZE: "aze",
|
|
1079
|
+
AZE_CYRL: "aze_cyrl",
|
|
1080
|
+
BEL: "bel",
|
|
1081
|
+
BEN: "ben",
|
|
1082
|
+
BOD: "bod",
|
|
1083
|
+
BOS: "bos",
|
|
1084
|
+
BUL: "bul",
|
|
1085
|
+
CAT: "cat",
|
|
1086
|
+
CEB: "ceb",
|
|
1087
|
+
CES: "ces",
|
|
1088
|
+
CHI_SIM: "chi_sim",
|
|
1089
|
+
CHI_TRA: "chi_tra",
|
|
1090
|
+
CHR: "chr",
|
|
1091
|
+
CYM: "cym",
|
|
1092
|
+
DAN: "dan",
|
|
1093
|
+
DEU: "deu",
|
|
1094
|
+
DZO: "dzo",
|
|
1095
|
+
ELL: "ell",
|
|
1096
|
+
ENG: "eng",
|
|
1097
|
+
ENM: "enm",
|
|
1098
|
+
EPO: "epo",
|
|
1099
|
+
EST: "est",
|
|
1100
|
+
EUS: "eus",
|
|
1101
|
+
FAS: "fas",
|
|
1102
|
+
FIN: "fin",
|
|
1103
|
+
FRA: "fra",
|
|
1104
|
+
FRK: "frk",
|
|
1105
|
+
FRM: "frm",
|
|
1106
|
+
GLE: "gle",
|
|
1107
|
+
GLG: "glg",
|
|
1108
|
+
GRC: "grc",
|
|
1109
|
+
GUJ: "guj",
|
|
1110
|
+
HAT: "hat",
|
|
1111
|
+
HEB: "heb",
|
|
1112
|
+
HIN: "hin",
|
|
1113
|
+
HRV: "hrv",
|
|
1114
|
+
HUN: "hun",
|
|
1115
|
+
IKU: "iku",
|
|
1116
|
+
IND: "ind",
|
|
1117
|
+
ISL: "isl",
|
|
1118
|
+
ITA: "ita",
|
|
1119
|
+
ITA_OLD: "ita_old",
|
|
1120
|
+
JAV: "jav",
|
|
1121
|
+
JPN: "jpn",
|
|
1122
|
+
KAN: "kan",
|
|
1123
|
+
KAT: "kat",
|
|
1124
|
+
KAT_OLD: "kat_old",
|
|
1125
|
+
KAZ: "kaz",
|
|
1126
|
+
KHM: "khm",
|
|
1127
|
+
KIR: "kir",
|
|
1128
|
+
KOR: "kor",
|
|
1129
|
+
KUR: "kur",
|
|
1130
|
+
LAO: "lao",
|
|
1131
|
+
LAT: "lat",
|
|
1132
|
+
LAV: "lav",
|
|
1133
|
+
LIT: "lit",
|
|
1134
|
+
MAL: "mal",
|
|
1135
|
+
MAR: "mar",
|
|
1136
|
+
MKD: "mkd",
|
|
1137
|
+
MLT: "mlt",
|
|
1138
|
+
MSA: "msa",
|
|
1139
|
+
MYA: "mya",
|
|
1140
|
+
NEP: "nep",
|
|
1141
|
+
NLD: "nld",
|
|
1142
|
+
NOR: "nor",
|
|
1143
|
+
ORI: "ori",
|
|
1144
|
+
PAN: "pan",
|
|
1145
|
+
POL: "pol",
|
|
1146
|
+
POR: "por",
|
|
1147
|
+
PUS: "pus",
|
|
1148
|
+
RON: "ron",
|
|
1149
|
+
RUS: "rus",
|
|
1150
|
+
SAN: "san",
|
|
1151
|
+
SIN: "sin",
|
|
1152
|
+
SLK: "slk",
|
|
1153
|
+
SLV: "slv",
|
|
1154
|
+
SPA: "spa",
|
|
1155
|
+
SPA_OLD: "spa_old",
|
|
1156
|
+
SQI: "sqi",
|
|
1157
|
+
SRP: "srp",
|
|
1158
|
+
SRP_LATN: "srp_latn",
|
|
1159
|
+
SWA: "swa",
|
|
1160
|
+
SWE: "swe",
|
|
1161
|
+
SYR: "syr",
|
|
1162
|
+
TAM: "tam",
|
|
1163
|
+
TEL: "tel",
|
|
1164
|
+
TGK: "tgk",
|
|
1165
|
+
TGL: "tgl",
|
|
1166
|
+
THA: "tha",
|
|
1167
|
+
TIR: "tir",
|
|
1168
|
+
TUR: "tur",
|
|
1169
|
+
UIG: "uig",
|
|
1170
|
+
UKR: "ukr",
|
|
1171
|
+
URD: "urd",
|
|
1172
|
+
UZB: "uzb",
|
|
1173
|
+
UZB_CYRL: "uzb_cyrl",
|
|
1174
|
+
VIE: "vie",
|
|
1175
|
+
YID: "yid"
|
|
1176
|
+
};
|
|
1177
|
+
return languages;
|
|
1178
|
+
}
|
|
1179
|
+
var PSM;
|
|
1180
|
+
var hasRequiredPSM;
|
|
1181
|
+
function requirePSM() {
|
|
1182
|
+
if (hasRequiredPSM) return PSM;
|
|
1183
|
+
hasRequiredPSM = 1;
|
|
1184
|
+
PSM = {
|
|
1185
|
+
OSD_ONLY: "0",
|
|
1186
|
+
AUTO_OSD: "1",
|
|
1187
|
+
AUTO_ONLY: "2",
|
|
1188
|
+
AUTO: "3",
|
|
1189
|
+
SINGLE_COLUMN: "4",
|
|
1190
|
+
SINGLE_BLOCK_VERT_TEXT: "5",
|
|
1191
|
+
SINGLE_BLOCK: "6",
|
|
1192
|
+
SINGLE_LINE: "7",
|
|
1193
|
+
SINGLE_WORD: "8",
|
|
1194
|
+
CIRCLE_WORD: "9",
|
|
1195
|
+
SINGLE_CHAR: "10",
|
|
1196
|
+
SPARSE_TEXT: "11",
|
|
1197
|
+
SPARSE_TEXT_OSD: "12",
|
|
1198
|
+
RAW_LINE: "13"
|
|
1199
|
+
};
|
|
1200
|
+
return PSM;
|
|
1201
|
+
}
|
|
1202
|
+
var src;
|
|
1203
|
+
var hasRequiredSrc;
|
|
1204
|
+
function requireSrc() {
|
|
1205
|
+
if (hasRequiredSrc) return src;
|
|
1206
|
+
hasRequiredSrc = 1;
|
|
1207
|
+
requireRuntime();
|
|
1208
|
+
const createScheduler2 = requireCreateScheduler();
|
|
1209
|
+
const createWorker2 = requireCreateWorker();
|
|
1210
|
+
const Tesseract2 = requireTesseract();
|
|
1211
|
+
const languages2 = requireLanguages();
|
|
1212
|
+
const OEM2 = requireOEM();
|
|
1213
|
+
const PSM2 = requirePSM();
|
|
1214
|
+
const { setLogging } = requireLog();
|
|
1215
|
+
src = {
|
|
1216
|
+
languages: languages2,
|
|
1217
|
+
OEM: OEM2,
|
|
1218
|
+
PSM: PSM2,
|
|
1219
|
+
createScheduler: createScheduler2,
|
|
1220
|
+
createWorker: createWorker2,
|
|
1221
|
+
setLogging,
|
|
1222
|
+
...Tesseract2
|
|
1223
|
+
};
|
|
1224
|
+
return src;
|
|
1225
|
+
}
|
|
1226
|
+
var srcExports = requireSrc();
|
|
1289
1227
|
const ocr = async ({ images = [], language = "eng", langPath = "" }) => {
|
|
1290
1228
|
if (images.length === 0) return { success: false, data: null, message: "images must be a array" };
|
|
1291
1229
|
if (!language) return { success: false, data: null, message: "languages must be a array" };
|
|
@@ -1293,8 +1231,8 @@ const ocr = async ({ images = [], language = "eng", langPath = "" }) => {
|
|
|
1293
1231
|
if (langPath) {
|
|
1294
1232
|
options = { langPath };
|
|
1295
1233
|
}
|
|
1296
|
-
const scheduler =
|
|
1297
|
-
const worker = await
|
|
1234
|
+
const scheduler = srcExports.createScheduler();
|
|
1235
|
+
const worker = await srcExports.createWorker(language, 3, options);
|
|
1298
1236
|
scheduler.addWorker(worker);
|
|
1299
1237
|
const results = await Promise.all(images.map((image) => scheduler.addJob("recognize", image)));
|
|
1300
1238
|
await scheduler.terminate();
|