ranuts 0.1.0-alpha → 0.1.0-alpha-21

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.
Files changed (211) hide show
  1. package/LICENSE +21 -0
  2. package/dist/build/build.es.d.ts +2 -0
  3. package/dist/build/build.umd.d.ts +2 -0
  4. package/dist/build/build.umd.ml.d.ts +2 -0
  5. package/dist/build/build.umd.node.d.ts +2 -0
  6. package/dist/build/build.umd.react.d.ts +2 -0
  7. package/dist/build/build.umd.utils.d.ts +2 -0
  8. package/dist/build/build.umd.wasm.d.ts +2 -0
  9. package/dist/color-BgjAdNyp.js +82296 -0
  10. package/dist/examples/clone-deep-example.d.ts +1 -0
  11. package/dist/examples/is-equal-example.d.ts +1 -0
  12. package/dist/index.d.ts +9 -9
  13. package/dist/index.js +151 -84
  14. package/dist/plugins/vite-plugins-banner.d.ts +2 -0
  15. package/dist/reactify-Z-V9Vblb.js +83 -0
  16. package/dist/src/arithmetic/index.d.ts +186 -0
  17. package/dist/src/cache/expires.d.ts +1 -0
  18. package/dist/src/ml/index.d.ts +2 -0
  19. package/dist/src/ml/index.js +1243 -0
  20. package/dist/src/ml/ocr.d.ts +11 -0
  21. package/dist/src/node/appendFile.d.ts +7 -0
  22. package/dist/src/node/body.d.ts +9 -0
  23. package/dist/src/node/color.d.ts +7 -0
  24. package/dist/src/node/command.d.ts +8 -0
  25. package/dist/src/node/ctx2req.d.ts +5 -0
  26. package/dist/src/node/fileInfo.d.ts +7 -0
  27. package/dist/src/node/fs.d.ts +7 -0
  28. package/dist/src/node/get.d.ts +10 -0
  29. package/dist/src/node/getIPAdress.d.ts +1 -0
  30. package/dist/src/node/index.d.ts +25 -0
  31. package/dist/src/node/index.js +54 -0
  32. package/dist/src/node/isColorSupported.d.ts +2 -0
  33. package/dist/src/node/paresUrl.d.ts +19 -0
  34. package/dist/src/node/readDir.d.ts +6 -0
  35. package/dist/src/node/readFile.d.ts +9 -0
  36. package/dist/src/node/router.d.ts +42 -0
  37. package/dist/src/node/send.d.ts +7 -0
  38. package/dist/src/node/server.d.ts +18 -0
  39. package/dist/src/node/startTask.d.ts +2 -0
  40. package/dist/src/node/stream.d.ts +15 -0
  41. package/dist/src/node/taskEnd.d.ts +2 -0
  42. package/dist/src/node/traverse.d.ts +17 -0
  43. package/dist/src/node/watchFile.d.ts +8 -0
  44. package/dist/src/node/websocket.d.ts +57 -0
  45. package/dist/src/node/writeFile.d.ts +8 -0
  46. package/dist/src/node/ws.d.ts +8 -0
  47. package/dist/src/optimize/index.d.ts +36 -0
  48. package/dist/src/optimize/promise.d.ts +0 -0
  49. package/dist/src/ran/commit.d.ts +0 -0
  50. package/dist/src/ran/dom.d.ts +0 -0
  51. package/dist/src/ran/hooks.d.ts +0 -0
  52. package/dist/src/ran/index.d.ts +20 -0
  53. package/dist/src/ran/min.d.ts +32 -0
  54. package/dist/src/ran/reconcile.d.ts +0 -0
  55. package/dist/src/ran/schedule.d.ts +0 -0
  56. package/dist/src/react/index.d.ts +2 -0
  57. package/dist/src/react/index.js +4 -0
  58. package/dist/src/react/reactify.d.ts +2 -0
  59. package/dist/src/sort/bubble.d.ts +7 -0
  60. package/dist/src/sort/bucket.d.ts +7 -0
  61. package/dist/src/sort/count.d.ts +7 -0
  62. package/dist/src/sort/heap.d.ts +7 -0
  63. package/dist/src/sort/index.d.ts +0 -0
  64. package/dist/src/sort/insert.d.ts +7 -0
  65. package/dist/src/sort/merge.d.ts +7 -0
  66. package/dist/src/sort/quick.d.ts +7 -0
  67. package/dist/src/sort/radix.d.ts +7 -0
  68. package/dist/src/sort/randomArray.d.ts +9 -0
  69. package/dist/src/sort/select.d.ts +7 -0
  70. package/dist/src/sort/shell.d.ts +7 -0
  71. package/dist/src/utils/audioRecorder.d.ts +16 -0
  72. package/dist/src/utils/behavior.d.ts +15 -0
  73. package/dist/src/utils/bom.d.ts +230 -0
  74. package/dist/src/utils/color.d.ts +71 -0
  75. package/dist/src/utils/compose.d.ts +10 -0
  76. package/dist/src/utils/console.d.ts +1 -0
  77. package/dist/src/utils/debounce.d.ts +7 -0
  78. package/dist/src/utils/device.d.ts +25 -0
  79. package/dist/src/utils/dom.d.ts +105 -0
  80. package/dist/src/utils/error.d.ts +1 -0
  81. package/dist/src/utils/func.d.ts +1 -0
  82. package/dist/src/utils/img.d.ts +16 -0
  83. package/dist/src/utils/index.d.ts +35 -0
  84. package/dist/src/utils/index.js +4548 -0
  85. package/dist/src/utils/memoize.d.ts +7 -0
  86. package/dist/src/utils/mimeType.d.ts +9 -0
  87. package/dist/src/utils/monitor.d.ts +38 -0
  88. package/dist/src/utils/network.d.ts +39 -0
  89. package/dist/src/utils/noop.d.ts +2 -0
  90. package/dist/src/utils/number.d.ts +45 -0
  91. package/dist/src/utils/obj.d.ts +83 -0
  92. package/dist/src/utils/performance.d.ts +21 -0
  93. package/dist/src/utils/queue.d.ts +33 -0
  94. package/dist/src/utils/report.d.ts +8 -0
  95. package/dist/src/utils/request.d.ts +17 -0
  96. package/dist/src/utils/script.d.ts +7 -0
  97. package/dist/src/utils/signal.d.ts +6 -0
  98. package/dist/src/utils/storage.d.ts +2 -0
  99. package/dist/src/utils/str.d.ts +212 -0
  100. package/dist/src/utils/subscribe.d.ts +46 -0
  101. package/dist/src/utils/throttle.d.ts +15 -0
  102. package/dist/src/utils/time.d.ts +20 -0
  103. package/dist/src/utils/totp/sha/common.d.ts +151 -0
  104. package/dist/src/utils/totp/sha/converters.d.ts +88 -0
  105. package/dist/src/utils/totp/sha/custom_types.d.ts +60 -0
  106. package/dist/src/utils/totp/sha/primitives_32.d.ts +98 -0
  107. package/dist/src/utils/totp/sha/primitives_64.d.ts +116 -0
  108. package/dist/src/utils/totp/sha/sha.d.ts +103 -0
  109. package/dist/src/utils/totp/sha/sha1.d.ts +18 -0
  110. package/dist/src/utils/totp/sha/sha256.d.ts +20 -0
  111. package/dist/src/utils/totp/sha/sha3.d.ts +53 -0
  112. package/dist/src/utils/totp/sha/sha512.d.ts +21 -0
  113. package/dist/src/utils/totp/totp.d.ts +23 -0
  114. package/dist/src/utils/visual/application.d.ts +14 -0
  115. package/dist/src/utils/visual/demo/index.d.ts +1 -0
  116. package/dist/src/utils/visual/demo/sankey.d.ts +2 -0
  117. package/dist/src/utils/visual/enums.d.ts +27 -0
  118. package/dist/src/utils/visual/event/boundary.d.ts +22 -0
  119. package/dist/src/utils/visual/event/event.d.ts +14 -0
  120. package/dist/src/utils/visual/event/index.d.ts +6 -0
  121. package/dist/src/utils/visual/event/types.d.ts +32 -0
  122. package/dist/src/utils/visual/graphics/graphics.d.ts +81 -0
  123. package/dist/src/utils/visual/graphics/graphicsData.d.ts +13 -0
  124. package/dist/src/utils/visual/graphics/graphicsGeometry.d.ts +35 -0
  125. package/dist/src/utils/visual/graphics/index.d.ts +4 -0
  126. package/dist/src/utils/visual/index.d.ts +7 -0
  127. package/dist/src/utils/visual/math/bezier.d.ts +2 -0
  128. package/dist/src/utils/visual/math/enums.d.ts +3 -0
  129. package/dist/src/utils/visual/math/index.d.ts +5 -0
  130. package/dist/src/utils/visual/math/matrix.d.ts +113 -0
  131. package/dist/src/utils/visual/math/transform.d.ts +29 -0
  132. package/dist/src/utils/visual/render/batchRenderer.d.ts +72 -0
  133. package/dist/src/utils/visual/render/canvasRenderer.d.ts +10 -0
  134. package/dist/src/utils/visual/render/index.d.ts +3 -0
  135. package/dist/src/utils/visual/render/render.d.ts +15 -0
  136. package/dist/src/utils/visual/render/utils/batch/index.d.ts +90 -0
  137. package/dist/src/utils/visual/render/utils/float.d.ts +63 -0
  138. package/dist/src/utils/visual/render/utils/index.d.ts +3 -0
  139. package/dist/src/utils/visual/render/utils/verticy.d.ts +13 -0
  140. package/dist/src/utils/visual/render/utils/webgl/batchPool.d.ts +28 -0
  141. package/dist/src/utils/visual/render/utils/webgl/initShader.d.ts +2 -0
  142. package/dist/src/utils/visual/render/utils/webgl/shaders.d.ts +2 -0
  143. package/dist/src/utils/visual/render/utils/webgpu/shaders.d.ts +8 -0
  144. package/dist/src/utils/visual/render/webGPURenderer.d.ts +49 -0
  145. package/dist/src/utils/visual/render/webGlRenderer.d.ts +17 -0
  146. package/dist/src/utils/visual/shape/circle.d.ts +11 -0
  147. package/dist/src/utils/visual/shape/ellipse.d.ts +12 -0
  148. package/dist/src/utils/visual/shape/index.d.ts +7 -0
  149. package/dist/src/utils/visual/shape/polygon.d.ts +11 -0
  150. package/dist/src/utils/visual/shape/rectangle.d.ts +12 -0
  151. package/dist/src/utils/visual/shape/roundedRectangle.d.ts +13 -0
  152. package/dist/src/utils/visual/shape/shape.d.ts +6 -0
  153. package/dist/src/utils/visual/style/fill.d.ts +8 -0
  154. package/dist/src/utils/visual/style/index.d.ts +3 -0
  155. package/dist/src/utils/visual/style/line.d.ts +10 -0
  156. package/dist/src/utils/visual/types.d.ts +17 -0
  157. package/dist/src/utils/visual/vertex/container.d.ts +73 -0
  158. package/dist/src/utils/visual/vertex/index.d.ts +5 -0
  159. package/dist/src/utils/visual/vertex/point.d.ts +18 -0
  160. package/dist/src/utils/visual/vertex/vertex.d.ts +36 -0
  161. package/dist/src/vnode/chainDom.d.ts +47 -0
  162. package/dist/src/vnode/h.d.ts +6 -0
  163. package/dist/src/vnode/hooks.d.ts +23 -0
  164. package/dist/src/vnode/htmlDomApi.d.ts +33 -0
  165. package/dist/src/vnode/init.d.ts +2 -0
  166. package/dist/src/vnode/is.d.ts +5 -0
  167. package/dist/src/vnode/modules/attributes.d.ts +8 -0
  168. package/dist/src/vnode/modules/class.d.ts +8 -0
  169. package/dist/src/vnode/modules/index.d.ts +3 -0
  170. package/dist/src/vnode/modules/listeners.d.ts +12 -0
  171. package/dist/src/vnode/modules/props.d.ts +8 -0
  172. package/dist/src/vnode/modules/style.d.ts +14 -0
  173. package/dist/src/vnode/vnode.d.ts +31 -0
  174. package/dist/src/wasm/index.d.ts +2 -0
  175. package/dist/src/wasm/index.js +346 -0
  176. package/dist/src/wasm/word.d.ts +17 -0
  177. package/dist/src/wicket/bridge.d.ts +4 -0
  178. package/dist/src/wicket/index.d.ts +29 -0
  179. package/dist/test/arithmetic.test.d.ts +1 -0
  180. package/dist/test/cloneDeep.test.d.ts +1 -0
  181. package/dist/test/encodeUrl.test.d.ts +1 -0
  182. package/dist/test/escapeHtml.test.d.ts +1 -0
  183. package/dist/test/is-equal.test.d.ts +1 -0
  184. package/dist/test/mimeType.test.d.ts +1 -0
  185. package/dist/test/server.test.d.ts +1 -0
  186. package/dist/test/sort.test.d.ts +1 -0
  187. package/dist/test/status.test.d.ts +1 -0
  188. package/dist/test/totp.test.d.ts +1 -0
  189. package/dist/test/utils/compose.test.d.ts +1 -0
  190. package/dist/test/utils/mergeObj.test.d.ts +1 -0
  191. package/dist/test/utils/ocr.test.d.ts +1 -0
  192. package/dist/test/visual/math.test.d.ts +1 -0
  193. package/dist/test/vnode/index.d.ts +1 -0
  194. package/dist/test/vnode/server.d.ts +2 -0
  195. package/dist/test/vnode/vnode.d.ts +1 -0
  196. package/dist/test/websocket.test.d.ts +1 -0
  197. package/dist/test/writeFile.test.d.ts +1 -0
  198. package/dist/umd/index.umd.cjs +1 -0
  199. package/dist/umd/ml/ml.umd.cjs +1 -0
  200. package/dist/umd/node/node.umd.cjs +1 -0
  201. package/dist/umd/react/react.umd.cjs +1 -0
  202. package/dist/umd/utils/utils.umd.cjs +1 -0
  203. package/dist/umd/wasm/wasm.umd.cjs +1 -0
  204. package/dist/vite.config.d.ts +11 -0
  205. package/dist/ws-D7Jt2dzL.js +703 -0
  206. package/package.json +70 -13
  207. package/readme.md +91 -0
  208. package/typings.d.ts +28 -0
  209. package/dist/index.js.map +0 -1
  210. package/dist/index.umd.cjs +0 -2
  211. package/dist/index.umd.cjs.map +0 -1
@@ -0,0 +1,1243 @@
1
+ var runtime = { exports: {} };
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;
12
+ };
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
+ }
27
+ try {
28
+ define({}, "");
29
+ } catch (err) {
30
+ define = function(obj, key, value) {
31
+ return obj[key] = value;
32
+ };
33
+ }
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;
63
+ });
64
+ var getProto = Object.getPrototypeOf;
65
+ var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
66
+ if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
67
+ IteratorPrototype = NativeIteratorPrototype;
68
+ }
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);
98
+ } else {
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);
128
+ });
129
+ }
130
+ }
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();
156
+ }
157
+ defineProperty(this, "_invoke", { value: enqueue });
158
+ }
159
+ defineIteratorMethods(AsyncIterator.prototype);
160
+ define(AsyncIterator.prototype, asyncIteratorSymbol, function() {
161
+ return this;
162
+ });
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
+ }
180
+ if (state === GenStateCompleted) {
181
+ if (method === "throw") {
182
+ throw arg;
183
+ }
184
+ return doneResult();
185
+ }
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") {
220
+ state = GenStateCompleted;
221
+ context.method = "throw";
222
+ context.arg = record.arg;
223
+ }
224
+ }
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;
238
+ }
239
+ }
240
+ if (methodName !== "return") {
241
+ context.method = "throw";
242
+ context.arg = new TypeError(
243
+ "The iterator does not provide a '" + methodName + "' method"
244
+ );
245
+ }
246
+ return ContinueSentinel;
247
+ }
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;
254
+ }
255
+ var info = record.arg;
256
+ if (!info) {
257
+ context.method = "throw";
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;
271
+ }
272
+ context.delegate = null;
273
+ return ContinueSentinel;
274
+ }
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];
287
+ }
288
+ if (2 in locs) {
289
+ entry.finallyLoc = locs[2];
290
+ entry.afterLoc = locs[3];
291
+ }
292
+ this.tryEntries.push(entry);
293
+ }
294
+ function resetTryEntry(entry) {
295
+ var record = entry.completion || {};
296
+ record.type = "normal";
297
+ delete record.arg;
298
+ entry.completion = record;
299
+ }
300
+ function Context(tryLocsList) {
301
+ this.tryEntries = [{ tryLoc: "root" }];
302
+ tryLocsList.forEach(pushTryEntry, this);
303
+ this.reset(true);
304
+ }
305
+ exports.keys = function(val) {
306
+ var object = Object(val);
307
+ var keys = [];
308
+ for (var key in object) {
309
+ keys.push(key);
310
+ }
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
+ };
324
+ };
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
+ }
342
+ }
343
+ next2.value = undefined$1;
344
+ next2.done = true;
345
+ return next2;
346
+ };
347
+ return next.next = next;
348
+ }
349
+ }
350
+ return { next: doneResult };
351
+ }
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
+ }
372
+ }
373
+ }
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;
381
+ }
382
+ return this.rval;
383
+ },
384
+ dispatchException: function(exception) {
385
+ if (this.done) {
386
+ throw exception;
387
+ }
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");
424
+ }
425
+ }
426
+ }
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
+ }
435
+ }
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;
445
+ return ContinueSentinel;
446
+ }
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);
469
+ resetTryEntry(entry);
470
+ return ContinueSentinel;
471
+ }
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;
498
+ }
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);
515
+ }
516
+ }
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,
537
+ action,
538
+ payload = {}
539
+ }) => {
540
+ let id = _id;
541
+ if (typeof id === "undefined") {
542
+ id = getId2("Job", jobCounter);
543
+ jobCounter += 1;
544
+ }
545
+ return {
546
+ id,
547
+ action,
548
+ payload
549
+ };
550
+ };
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
+ }
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();
611
+ });
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
+ };
638
+ };
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";
657
+ }
658
+ if (typeof key === "undefined") {
659
+ return env;
660
+ }
661
+ return env[key];
662
+ };
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
+ }
678
+ });
679
+ return opts;
680
+ };
681
+ return resolvePaths;
682
+ }
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;
695
+ }
696
+ const version = "6.0.1";
697
+ const require$$0 = {
698
+ version
699
+ };
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: () => {
713
+ }
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"
740
+ });
741
+ worker = new Worker(URL.createObjectURL(blob));
742
+ } else {
743
+ worker = new Worker(workerPath);
744
+ }
745
+ return worker;
746
+ };
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();
756
+ };
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
+ };
768
+ };
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);
778
+ };
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";
800
+ }
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
+ });
821
+ });
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);
828
+ }
829
+ return new Uint8Array(data);
830
+ };
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
852
+ };
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
883
+ });
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
+ }
951
+ }
952
+ }));
953
+ const initializeInternal = (_langs, _oem, _config, jobId) => startJob(createJob2({
954
+ id: jobId,
955
+ action: "initialize",
956
+ payload: { langs: _langs, oem: _oem, config: _config }
957
+ }));
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({
973
+ id: jobId,
974
+ action: "setParameters",
975
+ payload: { params }
976
+ }));
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;
996
+ }
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 });
1022
+ }
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;
1041
+ };
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();
1227
+ const ocr = async ({ images = [], language = "eng", langPath = "" }) => {
1228
+ if (images.length === 0) return { success: false, data: null, message: "images must be a array" };
1229
+ if (!language) return { success: false, data: null, message: "languages must be a array" };
1230
+ let options = {};
1231
+ if (langPath) {
1232
+ options = { langPath };
1233
+ }
1234
+ const scheduler = srcExports.createScheduler();
1235
+ const worker = await srcExports.createWorker(language, 3, options);
1236
+ scheduler.addWorker(worker);
1237
+ const results = await Promise.all(images.map((image) => scheduler.addJob("recognize", image)));
1238
+ await scheduler.terminate();
1239
+ return { success: true, data: results, message: "success" };
1240
+ };
1241
+ export {
1242
+ ocr
1243
+ };