millirec 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +65 -0
- package/README.md +171 -58
- package/dist/char-cnn/cnn-web.wasm +0 -0
- package/dist/char-cnn/core.d.ts +3 -1
- package/dist/char-cnn/core.js +145 -99
- package/dist/char-cnn/index.d.ts +1 -1
- package/dist/char-cnn/index.js +198 -136
- package/dist/char-cnn/millirec-char-cnn-core.min.js +1 -1
- package/dist/char-cnn/millirec-char-cnn.min.js +1 -1
- package/dist/char-cnn/options/accurate/tiny.head.bin +0 -0
- package/dist/char-cnn/options/accurate.js +2 -2
- package/dist/char-cnn/options/accurate.json +1 -1
- package/dist/char-cnn/options/all/all-base.head.bin +0 -0
- package/dist/char-cnn/options/all/all-base.q4.bin +0 -0
- package/dist/char-cnn/options/all/all-tiny.bin +0 -0
- package/dist/char-cnn/options/all/all-tiny.head.bin +0 -0
- package/dist/char-cnn/options/all-fast/all-base-p25.bin +0 -0
- package/dist/char-cnn/options/all-fast/all-base-p25.head.bin +0 -0
- package/dist/char-cnn/options/all-fast/all-tiny.bin +0 -0
- package/dist/char-cnn/options/all-fast/all-tiny.head.bin +0 -0
- package/dist/char-cnn/options/all-fast.js +17 -0
- package/dist/char-cnn/options/all-fast.json +15 -0
- package/dist/char-cnn/options/all-small/all-tiny-qat4.head.bin +0 -0
- package/dist/char-cnn/options/all-small/all-tiny-qat4.q4.bin +0 -0
- package/dist/char-cnn/options/all-small.js +11 -0
- package/dist/char-cnn/options/all-small.json +9 -0
- package/dist/char-cnn/options/all.js +17 -0
- package/dist/char-cnn/options/all.json +15 -0
- package/dist/char-cnn/options/digits/digits-base.head.bin +0 -0
- package/dist/char-cnn/options/digits/digits-tiny.head.bin +0 -0
- package/dist/char-cnn/options/digits-fast/digits-base-p25.bin +0 -0
- package/dist/char-cnn/options/digits-fast/digits-base-p25.head.bin +0 -0
- package/dist/char-cnn/options/digits-fast/digits-tiny.bin +0 -0
- package/dist/char-cnn/options/digits-fast/digits-tiny.head.bin +0 -0
- package/dist/char-cnn/options/digits-fast.js +17 -0
- package/dist/char-cnn/options/digits-fast.json +15 -0
- package/dist/char-cnn/options/digits-small/digits-tiny-qat4.head.bin +0 -0
- package/dist/char-cnn/options/digits-small/digits-tiny-qat4.q4.bin +0 -0
- package/dist/char-cnn/options/digits-small.js +11 -0
- package/dist/char-cnn/options/digits-small.json +9 -0
- package/dist/char-cnn/options/digits.js +2 -2
- package/dist/char-cnn/options/digits.json +1 -1
- package/dist/char-cnn/options/fast/base-p25.head.bin +0 -0
- package/dist/char-cnn/options/fast/tiny.head.bin +0 -0
- package/dist/char-cnn/options/fast.js +2 -2
- package/dist/char-cnn/options/fast.json +1 -1
- package/dist/char-cnn/options/lowercase/lowercase-tiny.head.bin +0 -0
- package/dist/char-cnn/options/lowercase-fast/lowercase-base-p25.bin +0 -0
- package/dist/char-cnn/options/lowercase-fast/lowercase-base-p25.head.bin +0 -0
- package/dist/char-cnn/options/lowercase-fast/lowercase-tiny.bin +0 -0
- package/dist/char-cnn/options/lowercase-fast/lowercase-tiny.head.bin +0 -0
- package/dist/char-cnn/options/lowercase-fast.js +17 -0
- package/dist/char-cnn/options/lowercase-fast.json +15 -0
- package/dist/char-cnn/options/lowercase-small/lowercase-tiny-qat4.head.bin +0 -0
- package/dist/char-cnn/options/lowercase-small/lowercase-tiny-qat4.q4.bin +0 -0
- package/dist/char-cnn/options/lowercase-small.js +11 -0
- package/dist/char-cnn/options/lowercase-small.json +9 -0
- package/dist/char-cnn/options/lowercase.js +2 -2
- package/dist/char-cnn/options/lowercase.json +1 -1
- package/dist/char-cnn/options/small/tiny.head.bin +0 -0
- package/dist/char-cnn/options/small/tiny.q4.bin +0 -0
- package/dist/char-cnn/options/small.js +2 -2
- package/dist/char-cnn/options/small.json +1 -1
- package/dist/char-lite/core.d.ts +1 -0
- package/dist/char-lite/core.js +628 -0
- package/dist/char-lite/index.d.ts +28 -8
- package/dist/char-lite/index.js +845 -717
- package/dist/char-lite/millirec-char-lite.min.js +1 -1
- package/dist/char-lite/sets.json +17 -17
- package/dist/index.d.ts +35 -0
- package/dist/index.js +88 -0
- package/dist/overlap/millirec-overlap.min.js +7 -7
- package/dist/pad/index.d.ts +8 -0
- package/dist/pad/index.js +482 -0
- package/package.json +21 -7
- package/dist/char-cnn/options/small/tiny.bin +0 -0
|
@@ -0,0 +1,628 @@
|
|
|
1
|
+
// ../../core/pipeline/constants.js
|
|
2
|
+
var POINTS_PER_SHAPE = 50;
|
|
3
|
+
var SECOND_AVERAGE = 1e3;
|
|
4
|
+
|
|
5
|
+
// ../../core/pipeline/calibrate.js
|
|
6
|
+
var CALIBRATION = {
|
|
7
|
+
image: { margin: 0.6884, mag: 0.6846, bias: -1.0768 },
|
|
8
|
+
imageGeom: { margin: 0.6925, mag: 1.0731, bias: -2.4927 }
|
|
9
|
+
};
|
|
10
|
+
function calibratedProb(a, b, { margin, mag, bias }) {
|
|
11
|
+
if (a < 1e-9) return 0.99;
|
|
12
|
+
return 1 / (1 + Math.exp(-(margin * Math.log(Math.max(b, 1e-9) / a) - mag * Math.log(a) - bias)));
|
|
13
|
+
}
|
|
14
|
+
function parseResult(result, charList, mode, secondAverage = SECOND_AVERAGE) {
|
|
15
|
+
const chars = [];
|
|
16
|
+
for (let i = 0; i < 3; i++) chars.push(charList[result[2 * i]]);
|
|
17
|
+
const cal = CALIBRATION[mode];
|
|
18
|
+
if (cal) {
|
|
19
|
+
const costs = [result[1], result[3], result[5]];
|
|
20
|
+
const probs2 = costs.map((c, i) => {
|
|
21
|
+
let rival = Infinity;
|
|
22
|
+
for (let j = 0; j < 3; j++) if (j !== i) rival = Math.min(rival, costs[j]);
|
|
23
|
+
return calibratedProb(c, rival, cal);
|
|
24
|
+
});
|
|
25
|
+
return { chars, probs: probs2 };
|
|
26
|
+
}
|
|
27
|
+
const denom = Math.max(result[1], secondAverage / 1e3);
|
|
28
|
+
let totalProb = Math.exp(-1 * secondAverage / denom);
|
|
29
|
+
for (let i = 0; i < 3; i++) totalProb += Math.exp(-1 * result[2 * i + 1] / denom);
|
|
30
|
+
const probs = [];
|
|
31
|
+
for (let i = 0; i < 3; i++) {
|
|
32
|
+
probs.push(Math.exp(-1 * result[2 * i + 1] / denom) / totalProb);
|
|
33
|
+
}
|
|
34
|
+
return { chars, probs };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// ../../core/format/delta.js
|
|
38
|
+
function decodeSample(sample) {
|
|
39
|
+
const points = [];
|
|
40
|
+
let x = 0;
|
|
41
|
+
let y = 0;
|
|
42
|
+
for (let i = 0; i < sample.x.length; i++) {
|
|
43
|
+
x += sample.x[i];
|
|
44
|
+
y += sample.y[i];
|
|
45
|
+
points.push({ x, y });
|
|
46
|
+
}
|
|
47
|
+
return points;
|
|
48
|
+
}
|
|
49
|
+
function encodeSample(points) {
|
|
50
|
+
const xs = [];
|
|
51
|
+
const ys = [];
|
|
52
|
+
let last = [0, 0];
|
|
53
|
+
for (let i = 0; i < points.length; i++) {
|
|
54
|
+
const x = Math.round(points[i].x);
|
|
55
|
+
const y = Math.round(points[i].y);
|
|
56
|
+
xs.push(i === 0 ? x : x - last[0]);
|
|
57
|
+
ys.push(i === 0 ? y : y - last[1]);
|
|
58
|
+
last = [x, y];
|
|
59
|
+
}
|
|
60
|
+
return { x: xs, y: ys };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ../../core/pipeline/stroke.js
|
|
64
|
+
function orientedPointsFromPolyline(polyline) {
|
|
65
|
+
const n = polyline.length;
|
|
66
|
+
const centroid = [0, 0];
|
|
67
|
+
let lastPoint = [0, 0];
|
|
68
|
+
const points = [];
|
|
69
|
+
for (let i = 0; i < n; i++) {
|
|
70
|
+
const point = polyline[i];
|
|
71
|
+
centroid[0] += point.x;
|
|
72
|
+
centroid[1] += point.y;
|
|
73
|
+
const out = { x: point.x, y: point.y, a: 1.570795 };
|
|
74
|
+
if (i > 0 && point.x !== lastPoint[0]) {
|
|
75
|
+
out.a = Math.atan2(point.y - lastPoint[1], point.x - lastPoint[0]);
|
|
76
|
+
}
|
|
77
|
+
out.s = Math.sin(out.a);
|
|
78
|
+
out.c = Math.cos(out.a);
|
|
79
|
+
if (i === 1) {
|
|
80
|
+
points[0].s = out.s;
|
|
81
|
+
points[0].c = out.c;
|
|
82
|
+
}
|
|
83
|
+
lastPoint = [point.x, point.y];
|
|
84
|
+
points.push(out);
|
|
85
|
+
}
|
|
86
|
+
centroid[0] /= n;
|
|
87
|
+
centroid[1] /= n;
|
|
88
|
+
const tc = [0, 0], bc = [0, 0], lc = [0, 0], rc = [0, 0];
|
|
89
|
+
for (const p of points) {
|
|
90
|
+
if (p.x < centroid[0]) {
|
|
91
|
+
lc[0] += p.x - centroid[0];
|
|
92
|
+
lc[1]++;
|
|
93
|
+
} else {
|
|
94
|
+
rc[0] += p.x - centroid[0];
|
|
95
|
+
rc[1]++;
|
|
96
|
+
}
|
|
97
|
+
if (p.y < centroid[1]) {
|
|
98
|
+
tc[0] += p.y - centroid[1];
|
|
99
|
+
tc[1]++;
|
|
100
|
+
} else {
|
|
101
|
+
bc[0] += p.y - centroid[1];
|
|
102
|
+
bc[1]++;
|
|
103
|
+
}
|
|
104
|
+
p.x -= centroid[0];
|
|
105
|
+
p.y -= centroid[1];
|
|
106
|
+
}
|
|
107
|
+
if (tc[1] > 0) tc[0] /= tc[1];
|
|
108
|
+
if (bc[1] > 0) bc[0] /= bc[1];
|
|
109
|
+
if (lc[1] > 0) lc[0] /= lc[1];
|
|
110
|
+
if (rc[1] > 0) rc[0] /= rc[1];
|
|
111
|
+
const scale = bc[0] - tc[0] < rc[0] - lc[0] ? 100 / (rc[0] - lc[0]) : tc[0] < bc[0] ? 100 / (bc[0] - tc[0]) : 1;
|
|
112
|
+
return { points, scale };
|
|
113
|
+
}
|
|
114
|
+
function resampleStrokes(strokes, n = POINTS_PER_SHAPE) {
|
|
115
|
+
const segs = [];
|
|
116
|
+
let cum = 0;
|
|
117
|
+
for (const raw of strokes) {
|
|
118
|
+
const stroke = raw.length === 1 ? [{ x: raw[0].x - 0.5, y: raw[0].y }, { x: raw[0].x + 0.5, y: raw[0].y }] : raw;
|
|
119
|
+
for (let i = 1; i < stroke.length; i++) {
|
|
120
|
+
const dx = stroke[i].x - stroke[i - 1].x;
|
|
121
|
+
const dy = stroke[i].y - stroke[i - 1].y;
|
|
122
|
+
const len = Math.sqrt(dx * dx + dy * dy);
|
|
123
|
+
segs.push({ ax: stroke[i - 1].x, ay: stroke[i - 1].y, bx: stroke[i].x, by: stroke[i].y, cumStart: cum, cumEnd: cum + len });
|
|
124
|
+
cum += len;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (!cum || !segs.length) return null;
|
|
128
|
+
const out = [];
|
|
129
|
+
let s = 0;
|
|
130
|
+
for (let i = 0; i < n; i++) {
|
|
131
|
+
const target = i * cum / (n - 1);
|
|
132
|
+
while (s < segs.length - 1 && segs[s].cumEnd < target) s++;
|
|
133
|
+
const seg = segs[s];
|
|
134
|
+
const span = seg.cumEnd - seg.cumStart;
|
|
135
|
+
const t = span ? Math.min(1, Math.max(0, (target - seg.cumStart) / span)) : 0;
|
|
136
|
+
out.push({ x: seg.ax + (seg.bx - seg.ax) * t, y: seg.ay + (seg.by - seg.ay) * t });
|
|
137
|
+
}
|
|
138
|
+
return out;
|
|
139
|
+
}
|
|
140
|
+
function polylineToSample(polyline) {
|
|
141
|
+
return encodeSample(polyline);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// ../../core/format/schema.js
|
|
145
|
+
var FORMAT_VERSION = 2;
|
|
146
|
+
var isCloudSample = (sample) => Array.isArray(sample);
|
|
147
|
+
var isSample = (s) => isCloudSample(s) ? s.every((p) => typeof p?.x === "number" && typeof p?.y === "number") : Array.isArray(s?.x) && Array.isArray(s?.y) && s.x.length === s.y.length;
|
|
148
|
+
function isV1(json) {
|
|
149
|
+
return !!json && typeof json === "object" && !json.version && !json.classes && Object.values(json).every(Array.isArray);
|
|
150
|
+
}
|
|
151
|
+
function migrateV1(v1, { mode = "both" } = {}) {
|
|
152
|
+
const classes = {};
|
|
153
|
+
for (const [cls, samples] of Object.entries(v1)) classes[cls] = { samples, geometry: null };
|
|
154
|
+
return { version: FORMAT_VERSION, mode, pointsPerShape: 50, classes, ext: {} };
|
|
155
|
+
}
|
|
156
|
+
function validate(data) {
|
|
157
|
+
const errors = [];
|
|
158
|
+
if (!data || typeof data !== "object") return ["not an object"];
|
|
159
|
+
if (typeof data.version !== "number" || data.version < 2) errors.push("bad version");
|
|
160
|
+
if (!data.classes || typeof data.classes !== "object" || !Object.keys(data.classes).length) {
|
|
161
|
+
errors.push("no classes");
|
|
162
|
+
return errors;
|
|
163
|
+
}
|
|
164
|
+
for (const [cls, entry] of Object.entries(data.classes)) {
|
|
165
|
+
if (!Array.isArray(entry?.samples) || !entry.samples.length) {
|
|
166
|
+
errors.push(`class ${cls}: no samples`);
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
entry.samples.forEach((s, i) => {
|
|
170
|
+
if (!isSample(s)) errors.push(`class ${cls} sample ${i}: bad shape`);
|
|
171
|
+
});
|
|
172
|
+
const g = entry.geometry;
|
|
173
|
+
if (g != null && typeof g !== "object") errors.push(`class ${cls}: bad geometry`);
|
|
174
|
+
}
|
|
175
|
+
if (data.wordList != null && !Array.isArray(data.wordList)) errors.push("bad wordList");
|
|
176
|
+
if (data.params != null && typeof data.params !== "object") errors.push("bad params");
|
|
177
|
+
return errors;
|
|
178
|
+
}
|
|
179
|
+
function decode(json) {
|
|
180
|
+
const data = isV1(json) ? migrateV1(json) : json;
|
|
181
|
+
const errors = validate(data);
|
|
182
|
+
if (errors.length) throw new Error("invalid training data: " + errors.join("; "));
|
|
183
|
+
if (!data.mode) data.mode = "both";
|
|
184
|
+
if (!data.pointsPerShape) data.pointsPerShape = 50;
|
|
185
|
+
if (!data.ext) data.ext = {};
|
|
186
|
+
return data;
|
|
187
|
+
}
|
|
188
|
+
function samplesMap(data) {
|
|
189
|
+
const out = {};
|
|
190
|
+
for (const [cls, entry] of Object.entries(data.classes)) out[cls] = entry.samples;
|
|
191
|
+
return out;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// ../../library/src/assetbase.js
|
|
195
|
+
function assetBaseOf(base) {
|
|
196
|
+
let s = base ? String(base) : "";
|
|
197
|
+
if (!s) return typeof location !== "undefined" ? new URL("./", location.href).href : "";
|
|
198
|
+
if (!s.endsWith("/")) s += "/";
|
|
199
|
+
return typeof location !== "undefined" ? new URL(s, location.href).href : s;
|
|
200
|
+
}
|
|
201
|
+
var notServed = (url2, what, base, recognizer) => new Error(`millirec: ${url2} is not ${what} \u2014 the package files are not served at ${base}; copy node_modules/millirec/dist/${recognizer}/ and pass assetBase (see README "Serving the files")`);
|
|
202
|
+
async function fetchAsset(url2, { as = "json", what, base, recognizer }) {
|
|
203
|
+
const fail = (detail) => {
|
|
204
|
+
const e = notServed(url2, what, base, recognizer);
|
|
205
|
+
if (detail) e.message += ` (${detail})`;
|
|
206
|
+
return e;
|
|
207
|
+
};
|
|
208
|
+
let r;
|
|
209
|
+
try {
|
|
210
|
+
r = await fetch(url2);
|
|
211
|
+
} catch (e) {
|
|
212
|
+
throw fail(e && e.message);
|
|
213
|
+
}
|
|
214
|
+
const type = r.headers && r.headers.get("content-type") || "";
|
|
215
|
+
if (!r.ok) throw fail(`HTTP ${r.status}`);
|
|
216
|
+
if (as === "json") {
|
|
217
|
+
try {
|
|
218
|
+
return await r.json();
|
|
219
|
+
} catch (e) {
|
|
220
|
+
throw fail(/html/i.test(type) ? "an HTML page" : e && e.message);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
const buf = await r.arrayBuffer();
|
|
224
|
+
const head = String.fromCharCode(...new Uint8Array(buf, 0, Math.min(buf.byteLength, 16))).trimStart().toLowerCase();
|
|
225
|
+
if (head.startsWith("<!doctype") || head.startsWith("<html")) throw fail("an HTML page");
|
|
226
|
+
return buf;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// ../../library/src/char-lite-core.js
|
|
230
|
+
function scriptBase() {
|
|
231
|
+
const src = typeof document !== "undefined" && document.currentScript && document.currentScript.src || "";
|
|
232
|
+
return src ? src.slice(0, src.lastIndexOf("/") + 1) : "";
|
|
233
|
+
}
|
|
234
|
+
var ASSET_BASE = scriptBase();
|
|
235
|
+
var CACHE_MAX = 256;
|
|
236
|
+
var StrokeWorker = class {
|
|
237
|
+
constructor({ assetBase, workerName, training, params }) {
|
|
238
|
+
assetBase = assetBaseOf(assetBase);
|
|
239
|
+
const decoded = decode(training);
|
|
240
|
+
this.trainPaths = samplesMap(decoded);
|
|
241
|
+
this.charList = Object.keys(this.trainPaths);
|
|
242
|
+
this.samplesPerChar = Math.max(1, ...this.charList.map((c) => this.trainPaths[c].length));
|
|
243
|
+
this.pointsPerShape = decoded.pointsPerShape || POINTS_PER_SHAPE;
|
|
244
|
+
this.params = params || decoded.params || null;
|
|
245
|
+
this.plugins = [];
|
|
246
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
247
|
+
this.inFlight = /* @__PURE__ */ new Map();
|
|
248
|
+
this.allWaiters = /* @__PURE__ */ new Map();
|
|
249
|
+
this.reqCounter = 0;
|
|
250
|
+
const boot = `self.__MILLIREC_ASSET_BASE=${JSON.stringify(assetBase)};importScripts(${JSON.stringify(assetBase + workerName)});`;
|
|
251
|
+
this.bootUrl = URL.createObjectURL(new Blob([boot], { type: "text/javascript" }));
|
|
252
|
+
this.worker = new Worker(this.bootUrl);
|
|
253
|
+
this.readyPromise = new Promise((resolve, reject) => {
|
|
254
|
+
this.readyResolve = resolve;
|
|
255
|
+
this.readyReject = reject;
|
|
256
|
+
});
|
|
257
|
+
this.worker.onmessage = (evt) => this.onMessage(evt);
|
|
258
|
+
const workerUrl = assetBase + workerName;
|
|
259
|
+
this.worker.onerror = (evt) => {
|
|
260
|
+
if (this.booted) {
|
|
261
|
+
this.flush();
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const e = notServed(workerUrl, "the char-lite worker", assetBase, "char-lite");
|
|
265
|
+
e.message += ` (${evt.message || "script failed to load"})`;
|
|
266
|
+
this.failBoot(e);
|
|
267
|
+
};
|
|
268
|
+
this.assetBase = assetBase;
|
|
269
|
+
}
|
|
270
|
+
onMessage(evt) {
|
|
271
|
+
const d = evt.data;
|
|
272
|
+
if (this.bootUrl) {
|
|
273
|
+
URL.revokeObjectURL(this.bootUrl);
|
|
274
|
+
this.bootUrl = null;
|
|
275
|
+
}
|
|
276
|
+
if (d.type === "getCharList") {
|
|
277
|
+
if (this.params) this.worker.postMessage({ type: "setParams", params: this.params });
|
|
278
|
+
this.worker.postMessage({ type: "charList", charList: this.charList, pointsPerShape: this.pointsPerShape, samplesPerChar: this.samplesPerChar });
|
|
279
|
+
} else if (d.type === "prepAll") {
|
|
280
|
+
this.charList.forEach((c, idx) => {
|
|
281
|
+
this.trainPaths[c].forEach((sample, i) => {
|
|
282
|
+
const { points, scale } = orientedPointsFromPolyline(decodeSample(sample));
|
|
283
|
+
this.worker.postMessage({ type: "addPoints", points, m: idx * this.samplesPerChar + i, scale });
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
this.booted = true;
|
|
287
|
+
this.readyResolve();
|
|
288
|
+
} else if (d.type === "addResult" && d.result) {
|
|
289
|
+
this.cache.delete(d.path);
|
|
290
|
+
this.cache.set(d.path, d.result);
|
|
291
|
+
if (this.cache.size > CACHE_MAX) this.cache.delete(this.cache.keys().next().value);
|
|
292
|
+
const waiters = this.inFlight.get(d.path) || [];
|
|
293
|
+
this.inFlight.delete(d.path);
|
|
294
|
+
for (const resolve of waiters) resolve(this.applyPlugins(d.result, d.path));
|
|
295
|
+
} else if (d.type === "allResult") {
|
|
296
|
+
const waiters = this.allWaiters.get(d.path) || [];
|
|
297
|
+
this.allWaiters.delete(d.path);
|
|
298
|
+
for (const resolve of waiters) resolve(d.costs);
|
|
299
|
+
} else if (d.type === "bootError") {
|
|
300
|
+
const e = notServed(this.assetBase + "millirec.wasm", "the char-lite matcher", this.assetBase, "char-lite");
|
|
301
|
+
e.message += ` (worker boot failed: ${d.message})`;
|
|
302
|
+
this.failBoot(e);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
/** Everyone waiting on the worker gets null, and nothing is left "in flight". */
|
|
306
|
+
flush() {
|
|
307
|
+
for (const map of [this.inFlight, this.allWaiters]) {
|
|
308
|
+
const lists = [...map.values()];
|
|
309
|
+
map.clear();
|
|
310
|
+
for (const list of lists) for (const done of list) done(null);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
/** The worker never came up: create() rejects with `e`, and the worker and its boot URL are released. */
|
|
314
|
+
failBoot(e) {
|
|
315
|
+
this.readyReject(e);
|
|
316
|
+
this.destroyed = true;
|
|
317
|
+
try {
|
|
318
|
+
this.worker.terminate();
|
|
319
|
+
} catch {
|
|
320
|
+
}
|
|
321
|
+
if (this.bootUrl) {
|
|
322
|
+
URL.revokeObjectURL(this.bootUrl);
|
|
323
|
+
this.bootUrl = null;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
applyPlugins(raw, path) {
|
|
327
|
+
let out = parseResult(raw, this.charList, "stroke", SECOND_AVERAGE);
|
|
328
|
+
for (const p of this.plugins) if (p.rerank) out = p.rerank(out, { raw, path, charList: this.charList, mode: "stroke", recognizer: this }) || out;
|
|
329
|
+
return out;
|
|
330
|
+
}
|
|
331
|
+
uploadTest(input) {
|
|
332
|
+
const strokes = Array.isArray(input[0]) ? input : [input];
|
|
333
|
+
const polyline = resampleStrokes(strokes, this.pointsPerShape);
|
|
334
|
+
if (!polyline) return false;
|
|
335
|
+
const { points, scale } = orientedPointsFromPolyline(polyline);
|
|
336
|
+
this.worker.postMessage({ type: "addPoints", points, m: -1, scale });
|
|
337
|
+
return true;
|
|
338
|
+
}
|
|
339
|
+
// The cache key of a drawing. It holds the STROKE BOUNDARIES (the same points split into two
|
|
340
|
+
// strokes resample differently — the pen-up jump is skipped) and hashes x and y separately at
|
|
341
|
+
// 1/1000 of a unit, so 0–1 coordinates do not collapse (the old (x*7919+y)|0 truncated them).
|
|
342
|
+
keyFor(input) {
|
|
343
|
+
const strokes = Array.isArray(input[0]) ? input : [input];
|
|
344
|
+
let h1 = 2166136261, h2 = 16777619, n = 0;
|
|
345
|
+
const mix = (v) => {
|
|
346
|
+
h1 = Math.imul(h1 ^ v, 16777619);
|
|
347
|
+
h2 = Math.imul(h2 ^ v, 2246822519);
|
|
348
|
+
};
|
|
349
|
+
for (const st of strokes) {
|
|
350
|
+
mix(2147483647 ^ st.length);
|
|
351
|
+
for (const p of st) {
|
|
352
|
+
mix(Math.round(p.x * 1e3) | 0);
|
|
353
|
+
mix(Math.round(p.y * 1e3) | 0);
|
|
354
|
+
n++;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return "strokes:" + strokes.length + ":" + n + ":" + (h1 >>> 0).toString(36) + (h2 >>> 0).toString(36);
|
|
358
|
+
}
|
|
359
|
+
async recognize(strokes) {
|
|
360
|
+
if (this.destroyed || !strokes || !strokes.length) return null;
|
|
361
|
+
await this.readyPromise;
|
|
362
|
+
if (this.destroyed) return null;
|
|
363
|
+
const key = this.keyFor(strokes);
|
|
364
|
+
if (this.cache.has(key)) {
|
|
365
|
+
const hit = this.cache.get(key);
|
|
366
|
+
this.cache.delete(key);
|
|
367
|
+
this.cache.set(key, hit);
|
|
368
|
+
return this.applyPlugins(hit, key);
|
|
369
|
+
}
|
|
370
|
+
if (!this.uploadTest(strokes)) return null;
|
|
371
|
+
return new Promise((resolve) => {
|
|
372
|
+
let timer;
|
|
373
|
+
const done = (v) => {
|
|
374
|
+
clearTimeout(timer);
|
|
375
|
+
resolve(v);
|
|
376
|
+
};
|
|
377
|
+
if (this.inFlight.has(key)) this.inFlight.get(key).push(done);
|
|
378
|
+
else {
|
|
379
|
+
this.inFlight.set(key, [done]);
|
|
380
|
+
this.worker.postMessage({ type: "compare", path: key, elementID: "req" + ++this.reqCounter });
|
|
381
|
+
}
|
|
382
|
+
timer = setTimeout(() => {
|
|
383
|
+
const waiting = this.inFlight.get(key);
|
|
384
|
+
if (waiting) {
|
|
385
|
+
const i = waiting.indexOf(done);
|
|
386
|
+
if (i >= 0) waiting.splice(i, 1);
|
|
387
|
+
if (!waiting.length) this.inFlight.delete(key);
|
|
388
|
+
}
|
|
389
|
+
done(null);
|
|
390
|
+
}, 4e3);
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
async rawScores(strokes) {
|
|
394
|
+
if (this.destroyed || !strokes || !strokes.length) return null;
|
|
395
|
+
await this.readyPromise;
|
|
396
|
+
if (this.destroyed) return null;
|
|
397
|
+
if (!this.uploadTest(strokes)) return null;
|
|
398
|
+
const key = "all:" + ++this.reqCounter;
|
|
399
|
+
const costs = await new Promise((resolve) => {
|
|
400
|
+
let timer;
|
|
401
|
+
const done = (v) => {
|
|
402
|
+
clearTimeout(timer);
|
|
403
|
+
resolve(v);
|
|
404
|
+
};
|
|
405
|
+
this.allWaiters.set(key, [done]);
|
|
406
|
+
this.worker.postMessage({ type: "compareAll", path: key, counts: this.charList.map((c) => this.trainPaths[c].length) });
|
|
407
|
+
timer = setTimeout(() => {
|
|
408
|
+
this.allWaiters.delete(key);
|
|
409
|
+
done(null);
|
|
410
|
+
}, 8e3);
|
|
411
|
+
});
|
|
412
|
+
return costs ? { classes: this.charList, costs } : null;
|
|
413
|
+
}
|
|
414
|
+
/** Stop the worker; anything still waiting gets null, and so does every later call. */
|
|
415
|
+
destroy() {
|
|
416
|
+
if (this.destroyed) return;
|
|
417
|
+
this.destroyed = true;
|
|
418
|
+
this.worker.terminate();
|
|
419
|
+
if (this.bootUrl) {
|
|
420
|
+
URL.revokeObjectURL(this.bootUrl);
|
|
421
|
+
this.bootUrl = null;
|
|
422
|
+
}
|
|
423
|
+
this.flush();
|
|
424
|
+
this.cache.clear();
|
|
425
|
+
this.readyResolve();
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
var toPairs = (parsed) => {
|
|
429
|
+
if (!parsed) return null;
|
|
430
|
+
const seen = /* @__PURE__ */ new Set(), out = [];
|
|
431
|
+
parsed.chars.forEach((c, i) => {
|
|
432
|
+
if (c !== void 0 && !seen.has(c)) {
|
|
433
|
+
seen.add(c);
|
|
434
|
+
out.push({ char: c, prob: parsed.probs[i] });
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
return out;
|
|
438
|
+
};
|
|
439
|
+
var classScore = (costs) => {
|
|
440
|
+
let b = Infinity, b2 = Infinity;
|
|
441
|
+
for (const c of costs || []) {
|
|
442
|
+
if (c < b) {
|
|
443
|
+
b2 = b;
|
|
444
|
+
b = c;
|
|
445
|
+
} else if (c < b2) b2 = c;
|
|
446
|
+
}
|
|
447
|
+
return b === Infinity ? Infinity : b2 === Infinity ? 0.9 * b * b * b : b * b * b2;
|
|
448
|
+
};
|
|
449
|
+
function withSamplesOf(training, extra, { replace = false } = {}) {
|
|
450
|
+
const empty = training && training.classes && !Object.keys(training.classes).length;
|
|
451
|
+
const base = empty ? { version: 2, mode: "stroke", ext: {}, ...training, pointsPerShape: training.pointsPerShape || POINTS_PER_SHAPE, classes: {} } : decode({ ...training });
|
|
452
|
+
const n = base.pointsPerShape;
|
|
453
|
+
const toSample = (d) => {
|
|
454
|
+
const strokes = Array.isArray(d) ? Array.isArray(d[0]) ? d : [d] : [decodeSample(d)];
|
|
455
|
+
const polyline = resampleStrokes(strokes, n);
|
|
456
|
+
return polyline ? polylineToSample(polyline) : null;
|
|
457
|
+
};
|
|
458
|
+
const classes = { ...base.classes };
|
|
459
|
+
for (const [cls, drawings] of Object.entries(extra || {})) {
|
|
460
|
+
const own = (drawings || []).map(toSample).filter(Boolean);
|
|
461
|
+
if (!own.length) continue;
|
|
462
|
+
const shipped = classes[cls]?.samples || [];
|
|
463
|
+
classes[cls] = { ...classes[cls] || {}, samples: replace ? own : shipped.concat(own) };
|
|
464
|
+
}
|
|
465
|
+
return { ...base, classes };
|
|
466
|
+
}
|
|
467
|
+
var MillirecCharLiteCore = class {
|
|
468
|
+
/** Drawn strokes → one training sample (resampled points, delta-encoded).
|
|
469
|
+
* Pass the set's pointsPerShape to match it (the shipped sets are 25). */
|
|
470
|
+
static strokesToSample(strokes, pointsPerShape = POINTS_PER_SHAPE) {
|
|
471
|
+
const polyline = resampleStrokes(Array.isArray(strokes[0]) ? strokes : [strokes], pointsPerShape);
|
|
472
|
+
return polyline ? polylineToSample(polyline) : null;
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* A copy of `training` with your own samples added — the way to make a
|
|
476
|
+
* recognizer learn one person's hand. `extra` maps a class (any string: a
|
|
477
|
+
* letter, a digit, an emoji) to drawings: strokes ([[{x,y},...], ...]) or
|
|
478
|
+
* already-encoded samples ({x:[Δ...], y:[Δ...]}). Each is resampled to the
|
|
479
|
+
* set's pointsPerShape. Classes not in `training` are added. `replace: true`
|
|
480
|
+
* drops a class's shipped samples instead of appending to them. `training`
|
|
481
|
+
* is not modified.
|
|
482
|
+
*/
|
|
483
|
+
static withSamples(training, extra, opts) {
|
|
484
|
+
return withSamplesOf(training, extra, opts);
|
|
485
|
+
}
|
|
486
|
+
/** opts: training (default window.MILLIREC_TRAINING), assetBase (default:
|
|
487
|
+
* alongside this script), params (matcher overrides), workerStroke. */
|
|
488
|
+
static async create(opts = {}) {
|
|
489
|
+
const g = typeof window !== "undefined" ? window : globalThis;
|
|
490
|
+
const config = { ...g.MILLIREC_CONFIG || {}, ...opts };
|
|
491
|
+
const training = opts.training || g.MILLIREC_TRAINING;
|
|
492
|
+
if (!training) throw new Error("MillirecCharLite: no training data (training.js missing?)");
|
|
493
|
+
if (typeof Worker === "undefined" || typeof Blob === "undefined") {
|
|
494
|
+
throw new Error("millirec: char-lite needs a browser (Worker, fetch, canvas); importing is SSR-safe but call create() on the client");
|
|
495
|
+
}
|
|
496
|
+
const inst = new this(config, training);
|
|
497
|
+
await inst.ready;
|
|
498
|
+
return inst;
|
|
499
|
+
}
|
|
500
|
+
constructor(config, training) {
|
|
501
|
+
this.config = config;
|
|
502
|
+
this.plugins = [];
|
|
503
|
+
this.shipped = this.stroke = this.newWorker(training);
|
|
504
|
+
this.ready = this.stroke.readyPromise;
|
|
505
|
+
}
|
|
506
|
+
newWorker(training) {
|
|
507
|
+
const w = new StrokeWorker({
|
|
508
|
+
assetBase: this.config.assetBase || ASSET_BASE,
|
|
509
|
+
workerName: this.config.workerStroke || "worker-stroke.js",
|
|
510
|
+
training,
|
|
511
|
+
params: this.config.params?.stroke || this.config.params || null
|
|
512
|
+
});
|
|
513
|
+
w.plugins = this.plugins;
|
|
514
|
+
return w;
|
|
515
|
+
}
|
|
516
|
+
/** Which engine this is (createRecognizer() picks one). */
|
|
517
|
+
get engine() {
|
|
518
|
+
return "char-lite";
|
|
519
|
+
}
|
|
520
|
+
/** The training set's classes (as char-cnn's `classes`: teach() does not change them; it returns the taught names). */
|
|
521
|
+
get classes() {
|
|
522
|
+
return this.shipped.charList;
|
|
523
|
+
}
|
|
524
|
+
get charList() {
|
|
525
|
+
return this.shipped.charList;
|
|
526
|
+
}
|
|
527
|
+
use(plugin) {
|
|
528
|
+
this.plugins.push(plugin);
|
|
529
|
+
return this;
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Recognize drawn strokes ([[{x,y},...], ...] or one polyline) → [{char, prob} x3] | null.
|
|
533
|
+
* `only` (a string, array or Set of classes) answers among those alone, the probabilities taken
|
|
534
|
+
* over them — a box that can only hold a digit gets the likeliest digit. It scores every template
|
|
535
|
+
* exactly (rawScores), so it is slower than a plain recognize(), whose scan gives up early on templates
|
|
536
|
+
* that cannot win: the first answer is the same, the runner-ups and their probabilities can differ.
|
|
537
|
+
* Plugins' rerank does not run on it.
|
|
538
|
+
*/
|
|
539
|
+
async recognize(strokes, { only = null } = {}) {
|
|
540
|
+
if (!only) return toPairs(await this.stroke.recognize(strokes));
|
|
541
|
+
const keep = new Set(typeof only === "string" ? [...only] : only);
|
|
542
|
+
const raw = await this.stroke.rawScores(strokes);
|
|
543
|
+
if (!raw) return null;
|
|
544
|
+
const ranked = raw.classes.map((c, i) => ({ i, c, v: classScore(raw.costs[i]) })).filter((x) => keep.has(x.c) && x.v < Infinity).sort((a, b) => a.v - b.v).slice(0, 3);
|
|
545
|
+
if (!ranked.length) return [];
|
|
546
|
+
while (ranked.length < 3) ranked.push({ ...ranked[0], v: 1e30 });
|
|
547
|
+
return toPairs(parseResult(ranked.flatMap((x) => [x.i, x.v]), raw.classes, "stroke", SECOND_AVERAGE));
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* TEACH: read symbols of your own from a few drawings of each. `examples` is `{ name: [drawing, …] }` — names are
|
|
551
|
+
* any strings, a drawing is strokes as for recognize(). From then on recognize() answers AMONG THE TAUGHT NAMES
|
|
552
|
+
* ONLY, matched against these drawings as templates; `{ add: true }` keeps what was taught before. The same call
|
|
553
|
+
* as char-cnn's teach(). To ADD symbols to a shipped set instead, build the training with withSamples().
|
|
554
|
+
* Starts a second worker for the taught set (the shipped one stays up, so forget() is instant). Resolves
|
|
555
|
+
* { classes, n }, or null when no drawing was usable.
|
|
556
|
+
*/
|
|
557
|
+
async teach(examples, { add = false } = {}) {
|
|
558
|
+
await this.ready;
|
|
559
|
+
if (this.destroyed) return null;
|
|
560
|
+
const base = add && this.taught ? this.taught : { version: 2, mode: "stroke", pointsPerShape: this.shipped.pointsPerShape, classes: {} };
|
|
561
|
+
const training = withSamplesOf(base, examples);
|
|
562
|
+
const n = Object.values(training.classes).reduce((a, c) => a + c.samples.length, 0);
|
|
563
|
+
if (!n) return null;
|
|
564
|
+
const w = this.newWorker(training);
|
|
565
|
+
await w.readyPromise;
|
|
566
|
+
if (this.destroyed) {
|
|
567
|
+
w.destroy();
|
|
568
|
+
return null;
|
|
569
|
+
}
|
|
570
|
+
if (this.stroke !== this.shipped) this.stroke.destroy();
|
|
571
|
+
this.stroke = w;
|
|
572
|
+
this.taught = training;
|
|
573
|
+
return { classes: w.charList, n };
|
|
574
|
+
}
|
|
575
|
+
/** Drop what teach() learned: recognize() reads the training set's classes again. */
|
|
576
|
+
forget() {
|
|
577
|
+
if (this.stroke !== this.shipped) this.stroke.destroy();
|
|
578
|
+
this.stroke = this.shipped;
|
|
579
|
+
this.taught = null;
|
|
580
|
+
}
|
|
581
|
+
/** Raw per-template costs → {classes, costs}. */
|
|
582
|
+
rawScores(strokes) {
|
|
583
|
+
return this.stroke.rawScores(strokes);
|
|
584
|
+
}
|
|
585
|
+
destroy() {
|
|
586
|
+
this.destroyed = true;
|
|
587
|
+
if (this.stroke !== this.shipped) this.stroke.destroy();
|
|
588
|
+
this.shipped.destroy();
|
|
589
|
+
}
|
|
590
|
+
};
|
|
591
|
+
|
|
592
|
+
// src/here.js
|
|
593
|
+
var url = (import.meta.url || "").replace(/[?#].*$/, "");
|
|
594
|
+
var HERE = url.slice(0, url.lastIndexOf("/") + 1);
|
|
595
|
+
function nodeFileUrl(url2, spec) {
|
|
596
|
+
const g = globalThis;
|
|
597
|
+
const node = typeof g.process !== "undefined" && g.process.versions && g.process.versions.node && typeof g.Deno === "undefined" && typeof g.Bun === "undefined";
|
|
598
|
+
if (url2.startsWith("file:") && node && typeof document === "undefined" && typeof WorkerGlobalScope === "undefined") {
|
|
599
|
+
throw new Error(`millirec: cannot fetch ${url2} outside a browser \u2014 in Node, import the JSON instead: import x from '${spec}' with { type: 'json' }`);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
// src/sets.js
|
|
604
|
+
var SETS = ["all", "capitals", "digits", "lowercase", "punctuation"];
|
|
605
|
+
async function loadSet(name, { assetBase = HERE } = {}) {
|
|
606
|
+
if (!SETS.includes(name)) throw new Error(`millirec: no training set "${name}" (one of ${SETS.join(", ")})`);
|
|
607
|
+
const base = assetBaseOf(assetBase);
|
|
608
|
+
const url2 = new URL(`sets/${name}.json`, base).href;
|
|
609
|
+
nodeFileUrl(url2, `millirec/char-lite/sets/${name}.json`);
|
|
610
|
+
return fetchAsset(url2, { what: `the ${name} training set`, base, recognizer: "char-lite" });
|
|
611
|
+
}
|
|
612
|
+
function liteOptions(opts = {}) {
|
|
613
|
+
if (!opts.training) throw new Error('MillirecCharLite.create: pass { training } \u2014 e.g. await loadSet("digits")');
|
|
614
|
+
return { assetBase: HERE, ...opts };
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
// src/char-lite-core.js
|
|
618
|
+
var MillirecCharLiteCore2 = class extends MillirecCharLiteCore {
|
|
619
|
+
/** `training` is required; the worker/wasm are found beside this module unless `assetBase` says otherwise. */
|
|
620
|
+
static create(opts = {}) {
|
|
621
|
+
return super.create(liteOptions(opts));
|
|
622
|
+
}
|
|
623
|
+
};
|
|
624
|
+
export {
|
|
625
|
+
MillirecCharLiteCore2 as MillirecCharLiteCore,
|
|
626
|
+
SETS,
|
|
627
|
+
loadSet
|
|
628
|
+
};
|
|
@@ -30,6 +30,8 @@ export interface CreateOptions {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export interface AttachOptions {
|
|
33
|
+
/** Passed to every recognize() the pad makes, e.g. { only: '0123456789' }. */
|
|
34
|
+
recognizeOptions?: { only?: string | string[] | Set<string> }
|
|
33
35
|
/** Pad size in CSS px (default 240 x 240). */
|
|
34
36
|
width?: number
|
|
35
37
|
height?: number
|
|
@@ -77,23 +79,41 @@ export type SetName = (typeof SETS)[number]
|
|
|
77
79
|
/** Fetch a shipped training set. */
|
|
78
80
|
export declare function loadSet(name: SetName, opts?: { assetBase?: string }): Promise<Training>
|
|
79
81
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
/** What recognize() can be restricted to: a string of one-character classes, or a list/Set of class names. */
|
|
83
|
+
export type Only = string | string[] | Set<string>
|
|
84
|
+
|
|
85
|
+
export declare class MillirecCharLiteCore {
|
|
86
|
+
static create(opts: CreateOptions): Promise<MillirecCharLiteCore>
|
|
82
87
|
/** Strokes → one sample. Pass the set's pointsPerShape (shipped sets: 25). */
|
|
83
88
|
static strokesToSample(strokes: Strokes | Stroke, pointsPerShape?: number): Sample | null
|
|
84
89
|
/** A copy of `training` with your own drawings added per class (new classes allowed). */
|
|
85
90
|
static withSamples(training: Training | Record<string, Sample[]>, extra: Record<string, Array<Strokes | Stroke | Sample>>, opts?: { replace?: boolean }): Training
|
|
86
|
-
|
|
91
|
+
readonly engine: 'char-lite'
|
|
92
|
+
/** The training set's classes (teach() does not change them; it returns the taught names). */
|
|
93
|
+
readonly classes: string[]
|
|
87
94
|
readonly charList: string[]
|
|
88
95
|
readonly ready: Promise<void>
|
|
89
|
-
/** null for an empty drawing, and after destroy().
|
|
90
|
-
recognize(
|
|
96
|
+
/** null for an empty drawing, and after destroy(). `only` answers among those classes alone, scoring every template
|
|
97
|
+
* exactly — slower, and its runner-ups can differ from a plain recognize()'s (the first answer does not); plugins'
|
|
98
|
+
* rerank does not run. Fewer than three readings when fewer classes are possible. */
|
|
99
|
+
recognize(strokes: Strokes | Stroke, opts?: { only?: Only }): Promise<Reading[] | null>
|
|
91
100
|
/** Raw per-template costs: costs[i] holds one cost per training sample of classes[i] (lower is closer). */
|
|
92
101
|
rawScores(strokes: Strokes | Stroke): Promise<{ classes: string[]; costs: number[][] } | null>
|
|
102
|
+
/** Read symbols of your own from a few drawings each: recognize() then answers among the taught names only.
|
|
103
|
+
* `{ add: true }` keeps what was taught before. null when no drawing was usable. To ADD symbols to the
|
|
104
|
+
* training set instead, build it with withSamples(). */
|
|
105
|
+
teach(examples: Record<string, Array<Strokes | Stroke>>, opts?: { add?: boolean }): Promise<{ classes: string[]; n: number } | null>
|
|
106
|
+
/** Drop what teach() learned. */
|
|
107
|
+
forget(): void
|
|
93
108
|
use(plugin: { rerank?: (out: unknown, ctx: unknown) => unknown }): this
|
|
94
|
-
/**
|
|
95
|
-
attach(el: HTMLElement, opts?: AttachOptions): Pad
|
|
96
|
-
/** Stop the instance's Worker (each instance holds one, plus a wasm matcher). Pending and later
|
|
109
|
+
/** Stop the instance's Workers (one, plus one while something is taught). Pending and later
|
|
97
110
|
* recognize()/rawScores() calls resolve null. */
|
|
98
111
|
destroy(): void
|
|
99
112
|
}
|
|
113
|
+
|
|
114
|
+
export declare class MillirecCharLite extends MillirecCharLiteCore {
|
|
115
|
+
static create(opts: CreateOptions): Promise<MillirecCharLite>
|
|
116
|
+
static createDrawCanvas(opts?: object): unknown
|
|
117
|
+
/** Mount a drawing pad in `el`; `el` then fires 'millirec:result' and 'millirec:clear'. */
|
|
118
|
+
attach(el: HTMLElement, opts?: AttachOptions): Pad
|
|
119
|
+
}
|