millirec 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +156 -2
- package/dist/char-cnn/base-p25.bin +0 -0
- package/dist/char-cnn/base-p25.head.bin +0 -0
- package/dist/char-cnn/base.head.bin +0 -0
- package/dist/char-cnn/base.q4.bin +0 -0
- package/dist/char-cnn/cnn-web.js +8 -0
- package/dist/char-cnn/cnn-web.wasm +0 -0
- package/dist/char-cnn/core.d.ts +35 -0
- package/dist/char-cnn/core.js +536 -0
- package/dist/char-cnn/index.d.ts +9 -0
- package/dist/char-cnn/index.js +1009 -0
- package/dist/char-cnn/millirec-char-cnn-core.min.js +1 -0
- package/dist/char-cnn/millirec-char-cnn.min.js +1 -0
- package/dist/char-cnn/options/accurate.js +17 -0
- package/dist/char-cnn/options/accurate.json +15 -0
- package/dist/char-cnn/options/fast.js +17 -0
- package/dist/char-cnn/options/fast.json +15 -0
- package/dist/char-cnn/options/small.js +11 -0
- package/dist/char-cnn/options/small.json +9 -0
- package/dist/char-cnn/tiny.bin +0 -0
- package/dist/char-cnn/tiny.head.bin +0 -0
- package/dist/char-lite/index.d.ts +77 -0
- package/dist/char-lite/index.js +894 -0
- package/dist/char-lite/millirec-char-lite.min.js +1 -0
- package/dist/char-lite/millirec.wasm +0 -0
- package/dist/char-lite/sets/all.js +2 -0
- package/dist/char-lite/sets/all.json +1 -0
- package/dist/char-lite/sets/capitals.js +2 -0
- package/dist/char-lite/sets/capitals.json +1 -0
- package/dist/char-lite/sets/digits.js +2 -0
- package/dist/char-lite/sets/digits.json +1 -0
- package/dist/char-lite/sets/lowercase.js +2 -0
- package/dist/char-lite/sets/lowercase.json +1 -0
- package/dist/char-lite/sets/punctuation.js +2 -0
- package/dist/char-lite/sets/punctuation.json +1 -0
- package/dist/char-lite/sets.json +163 -0
- package/dist/char-lite/worker-stroke.js +11 -0
- package/dist/overlap/millirec-overlap.min.js +45 -0
- package/dist/overlap/millirec.wasm +0 -0
- package/dist/overlap/training.all.json +1 -0
- package/dist/overlap/training.capitals.json +1 -0
- package/dist/overlap/training.digits.json +1 -0
- package/dist/overlap/training.lowercase.json +1 -0
- package/dist/overlap/training.punctuation.json +1 -0
- package/dist/overlap/words.json +1 -0
- package/package.json +53 -4
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";var ar=Object.defineProperty;var ir=(i,h,m)=>h in i?ar(i,h,{enumerable:!0,configurable:!0,writable:!0,value:m}):i[h]=m;var xe=(i,h,m)=>ir(i,typeof h!="symbol"?h+"":h,m);var ShapeID=(()=>{var i=globalThis.document?.currentScript?.src;return async function(h={}){var m,o=h,S=!!globalThis.window,c=!!globalThis.WorkerGlobalScope,T=globalThis.process?.versions?.node&&globalThis.process?.type!="renderer",V=(e,r)=>{throw r};typeof __filename<"u"?i=__filename:c&&(i=self.location.href);var G="",X,L;if(T){var re=require("fs");G=__dirname+"/",L=e=>(e=te(e)?new URL(e):e,re.readFileSync(e)),X=async e=>(e=te(e)?new URL(e):e,re.readFileSync(e,void 0)),process.argv.slice(2),V=(e,r)=>{throw process.exitCode=e,r}}else if(S||c){try{G=new URL(".",i).href}catch{}c&&(L=e=>{var r=new XMLHttpRequest;return r.open("GET",e,!1),r.responseType="arraybuffer",r.send(null),new Uint8Array(r.response)}),X=async e=>{if(e=await fetch(e,{credentials:"same-origin"}),e.ok)return e.arrayBuffer();throw Error(e.status+" : "+e.url)}}console.log.bind(console);var F=console.error.bind(console),_,Y=!1,te=e=>e.startsWith("file://"),ne,ae,Q,P,O,U,j,w,ie,oe,se,ue,le=!1;function fe(){var e=H.buffer;Q=new Int8Array(e),O=new Int16Array(e),P=new Uint8Array(e),U=new Uint16Array(e),j=new Int32Array(e),w=new Uint32Array(e),ie=new Float32Array(e),oe=new Float64Array(e),se=new BigInt64Array(e),ue=new BigUint64Array(e)}function pe(e){throw o.onAbort?.(e),e="Aborted("+e+")",F(e),Y=!0,e=new WebAssembly.RuntimeError(e+". Build with -sASSERTIONS for more info."),ae?.(e),e}var Z;async function We(e){if(!_)try{var r=await X(e);return new Uint8Array(r)}catch{}if(e==Z&&_)e=new Uint8Array(_);else if(L)e=L(e);else throw"both async and sync fetching of the wasm failed";return e}async function De(e,r){try{var t=await We(e);return await WebAssembly.instantiate(t,r)}catch(n){F(`failed to asynchronously prepare wasm: ${n}`),pe(n)}}async function Te(e){var r=Z;if(!_&&!T)try{var t=fetch(r,{credentials:"same-origin"});return await WebAssembly.instantiateStreaming(t,e)}catch(n){F(`wasm streaming compile failed: ${n}`),F("falling back to ArrayBuffer instantiation")}return De(r,e)}class ce{constructor(r){xe(this,"name","ExitStatus");this.message=`Program terminated with exit(${r})`,this.status=r}}var he=e=>{for(;0<e.length;)e.shift()(o)},de=[],me=[],Fe=()=>{var e=o.preRun.shift();me.push(e)},ye=!0;class _e{constructor(r){this.G=r-24}}var ge=0,be=0,K={},ve=e=>{for(;e.length;){var r=e.pop();e.pop()(r)}};function N(e){return this.A(w[e>>2])}var x={},W={},k={},we=class extends Error{constructor(e){super(e),this.name="InternalError"}},Ae=(e,r,t)=>{function n(u){if(u=t(u),u.length!==e.length)throw new we("Mismatched type converter count");for(var f=0;f<e.length;++f)E(e[f],u[f])}e.forEach(u=>k[u]=r);var a=Array(r.length),s=[],p=0;r.forEach((u,f)=>{W.hasOwnProperty(u)?a[f]=W[u]:(s.push(u),x.hasOwnProperty(u)||(x[u]=[]),x[u].push(()=>{a[f]=W[u],++p,p===s.length&&n(a)}))}),s.length===0&&n(a)},C=e=>{for(var r="";;){var t=P[e++];if(!t)return r;r+=String.fromCharCode(t)}},M=class extends Error{constructor(e){super(e),this.name="BindingError"}},Ge=e=>{throw new M(e)};function Le(e,r,t={}){var n=r.name;if(!e)throw new M(`type "${n}" must have a positive integer typeid pointer`);if(W.hasOwnProperty(e)){if(t.L)return;throw new M(`Cannot register type '${n}' twice`)}W[e]=r,delete k[e],x.hasOwnProperty(e)&&(r=x[e],delete x[e],r.forEach(a=>a()))}function E(e,r,t={}){return Le(e,r,t)}var Ce=(e,r,t)=>{switch(r){case 1:return t?n=>Q[n]:n=>P[n];case 2:return t?n=>O[n>>1]:n=>U[n>>1];case 4:return t?n=>j[n>>2]:n=>w[n>>2];case 8:return t?n=>se[n>>3]:n=>ue[n>>3];default:throw new TypeError(`invalid integer width (${r}): ${e}`)}},Re=[],D=[0,1,,1,null,1,!0,1,!1,1],Oe=e=>{switch(e){case void 0:return 2;case null:return 4;case!0:return 6;case!1:return 8;default:const r=Re.pop()||D.length;return D[r]=e,D[r+1]=1,r}},Ue={name:"emscripten::val",A:e=>{if(!e)throw new M(`Cannot use deleted val. handle = ${e}`);var r=D[e];return 9<e&&--D[e+1]===0&&(D[e]=void 0,Re.push(e)),r},D:(e,r)=>Oe(r),F:N,B:null},je=(e,r)=>{switch(r){case 4:return function(t){return this.A(ie[t>>2])};case 8:return function(t){return this.A(oe[t>>3])};default:throw new TypeError(`invalid float width (${r}): ${e}`)}};function Me(e){for(var r=1;r<e.length;++r)if(e[r]!==null&&e[r].B===void 0)return!0;return!1}var Ke=(e,r)=>{if(o[e].C===void 0){var t=o[e];o[e]=function(...n){if(!o[e].C.hasOwnProperty(n.length))throw new M(`Function '${r}' called with an invalid number of arguments (${n.length}) - expects one of (${o[e].C})!`);return o[e].C[n.length].apply(this,n)},o[e].C=[],o[e].C[t.H]=t}},Ne=(e,r,t)=>{if(o.hasOwnProperty(e)){if(t===void 0||o[e].C!==void 0&&o[e].C[t]!==void 0)throw new M(`Cannot register public name '${e}' twice`);if(Ke(e,e),o[e].C.hasOwnProperty(t))throw new M(`Cannot register multiple overloads of a function with the same number of arguments (${t})!`);o[e].C[t]=r}else o[e]=r,o[e].H=t},ke=(e,r)=>{for(var t=[],n=0;n<e;n++)t.push(w[r+4*n>>2]);return t},b=(e,r)=>{e=C(e);var t=Pe.get(r);if(typeof t!="function")throw new M(`unknown function pointer with signature ${e}: ${r}`);return t};class He extends Error{}var ze=e=>{e=Ee(e);var r=C(e);return B(e),r},Je=(e,r)=>{function t(s){a[s]||W[s]||(k[s]?k[s].forEach(t):(n.push(s),a[s]=!0))}var n=[],a={};throw r.forEach(t),new He(`${e}: `+n.map(ze).join([", "]))},Ve=e=>{e=e.trim();const r=e.indexOf("(");return r===-1?e:e.slice(0,r)},Xe=new TextDecoder,Se=(e,r,t,n)=>{if(t=r+t,n)return t;for(;e[r]&&!(r>=t);)++r;return r},Ye=new TextDecoder("utf-16le"),Qe=(e,r,t)=>(e>>=1,Ye.decode(U.subarray(e,Se(U,e,r/2,t)))),Ze=(e,r,t)=>{if(t??(t=2147483647),2>t)return 0;t-=2;var n=r;t=t<2*e.length?t/2:e.length;for(var a=0;a<t;++a)O[r>>1]=e.charCodeAt(a),r+=2;return O[r>>1]=0,r-n},qe=e=>2*e.length,er=(e,r,t)=>{var n="";e>>=2;for(var a=0;!(a>=r/4);a++){var s=w[e+a];if(!s&&!t)break;n+=String.fromCodePoint(s)}return n},rr=(e,r,t)=>{if(t??(t=2147483647),4>t)return 0;var n=r;t=n+t-4;for(var a=0;a<e.length;++a){var s=e.codePointAt(a);if(65535<s&&a++,j[r>>2]=s,r+=4,r+4>t)break}return j[r>>2]=0,r-n},tr=e=>{for(var r=0,t=0;t<e.length;++t)65535<e.codePointAt(t)&&t++,r+=4;return r};if(o.noExitRuntime&&(ye=o.noExitRuntime),o.printErr&&(F=o.printErr),o.wasmBinary&&(_=o.wasmBinary),o.preInit)for(typeof o.preInit=="function"&&(o.preInit=[o.preInit]);0<o.preInit.length;)o.preInit.shift()();var Ee,$e,q,B,H,Pe,nr={h:(e,r,t)=>{var n=new _e(e);throw w[n.G+16>>2]=0,w[n.G+4>>2]=r,w[n.G+8>>2]=t,ge=e,be++,ge},m:()=>pe(""),p:e=>{var r=K[e];delete K[e];var t=r.elements,n=t.length,a=t.map(u=>u.K).concat(t.map(u=>u.R)),s=r.N,p=r.O;Ae([e],a,u=>(t.forEach((f,l)=>{var g=u[l],R=f.I,d=f.J,$=u[l+n],I=f.P,J=f.S;f.read=y=>g.A(R(d,y)),f.write=(y,A)=>{var v=[];I(J,y,$.D(v,A)),ve(v)}}),[{name:r.name,A:f=>{for(var l=Array(n),g=0;g<n;++g)l[g]=t[g].read(f);return p(f),l},D:(f,l)=>{if(n!==l.length)throw new TypeError(`Incorrect number of tuple elements for ${r.name}: expected=${n}, actual=${l.length}`);for(var g=s(),R=0;R<n;++R)t[R].write(g,l[R]);return f!==null&&f.push(p,g),g},F:N,B:p}]))},f:(e,r,t,n,a)=>{r=C(r),n=n===0n;let s=p=>p;if(n){const p=8*t;s=u=>BigInt.asUintN(p,u),a=s(a)}E(e,{name:r,A:s,D:(p,u)=>(typeof u=="number"&&(u=BigInt(u)),u),F:Ce(r,t,!n),B:null})},k:(e,r,t,n)=>{r=C(r),E(e,{name:r,A:function(a){return!!a},D:function(a,s){return s?t:n},F:function(a){return this.A(P[a])},B:null})},i:e=>E(e,Ue),e:(e,r,t)=>{r=C(r),E(e,{name:r,A:n=>n,D:(n,a)=>a,F:je(r,t),B:null})},c:(e,r,t,n,a,s,p)=>{var u=ke(r,t);e=C(e),e=Ve(e),a=b(n,a),Ne(e,function(){Je(`Cannot call ${e} due to unbound types`,u)},r-1),Ae([],u,f=>{var l=[f[0],null].concat(f.slice(1));f=e;var g=e,R=a,d=l.length;if(2>d)throw new M("argTypes array size mismatch! Must at least get return value and 'this' types!");var $=l[1]!==null&&!1,I=Me(l),J=!l[0].M,y=l[0],A=l[1];for(R=[g,Ge,R,s,ve,y.A.bind(y),A?.D.bind(A)],y=2;y<d;++y)A=l[y],R.push(A.D.bind(A));if(!I)for(y=$?1:2;y<l.length;++y)l[y].B!==null&&R.push(l[y].B);I=Me(l),y=l.length-2;var v=[];for(A=["fn"],$&&A.push("thisWired"),d=0;d<y;++d)v.push(`arg${d}`),A.push(`arg${d}Wired`);v=v.join(","),A=A.join(","),v=`return function (${v}) {
|
|
2
|
+
`,I&&(v+=`var destructors = [];
|
|
3
|
+
`);var Be=I?"destructors":"null",ee="humanName throwBindingError invoker fn runDestructors fromRetWire toClassParamWire".split(" ");for($&&(v+=`var thisWired = toClassParamWire(${Be}, this);
|
|
4
|
+
`),d=0;d<y;++d){var Ie=`toArg${d}Wire`;v+=`var arg${d}Wired = ${Ie}(${Be}, arg${d});
|
|
5
|
+
`,ee.push(Ie)}if(v+=(J||p?"var rv = ":"")+`invoker(${A});
|
|
6
|
+
`,I)v+=`runDestructors(destructors);
|
|
7
|
+
`;else for(d=$?1:2;d<l.length;++d)$=d===1?"thisWired":"arg"+(d-2)+"Wired",l[d].B!==null&&(v+=`${$}_dtor(${$});
|
|
8
|
+
`,ee.push(`${$}_dtor`));if(J&&(v+=`var ret = fromRetWire(rv);
|
|
9
|
+
return ret;
|
|
10
|
+
`),l=new Function(ee,v+`}
|
|
11
|
+
`)(...R),g=Object.defineProperty(l,"name",{value:g}),l=r-1,!o.hasOwnProperty(f))throw new we("Replacing nonexistent public symbol");return o[f].C!==void 0&&l!==void 0?o[f].C[l]=g:(o[f]=g,o[f].H=l),[]})},b:(e,r,t,n,a)=>{r=C(r);let s=u=>u;if(n===0){var p=32-8*t;s=u=>u<<p>>>p,a=s(a)}E(e,{name:r,A:s,D:(u,f)=>f,F:Ce(r,t,n!==0),B:null})},a:(e,r,t)=>{function n(s){return new a(Q.buffer,w[s+4>>2],w[s>>2])}var a=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,BigInt64Array,BigUint64Array][r];t=C(t),E(e,{name:t,A:n,F:n},{L:!0})},j:(e,r)=>{r=C(r),E(e,{name:r,A(t){var n=(n=t+4)?Xe.decode(P.subarray(n,Se(P,n,w[t>>2],!0))):"";return B(t),n},D(t,n){n instanceof ArrayBuffer&&(n=new Uint8Array(n));var a,s=typeof n=="string";if(!(s||ArrayBuffer.isView(n)&&n.BYTES_PER_ELEMENT==1))throw new M("Cannot pass non-string to std::string");var p;if(s)for(a=p=0;a<n.length;++a){var u=n.charCodeAt(a);127>=u?p++:2047>=u?p+=2:55296<=u&&57343>=u?(p+=4,++a):p+=3}else p=n.length;if(a=p,p=q(4+a+1),u=p+4,w[p>>2]=a,s){if(s=u,u=a+1,a=P,0<u){u=s+u-1;for(var f=0;f<n.length;++f){var l=n.codePointAt(f);if(127>=l){if(s>=u)break;a[s++]=l}else if(2047>=l){if(s+1>=u)break;a[s++]=192|l>>6,a[s++]=128|l&63}else if(65535>=l){if(s+2>=u)break;a[s++]=224|l>>12,a[s++]=128|l>>6&63,a[s++]=128|l&63}else{if(s+3>=u)break;a[s++]=240|l>>18,a[s++]=128|l>>12&63,a[s++]=128|l>>6&63,a[s++]=128|l&63,f++}}a[s]=0}}else P.set(n,u);return t!==null&&t.push(B,p),p},F:N,B(t){B(t)}})},d:(e,r,t)=>{if(t=C(t),r===2)var n=Qe,a=Ze,s=qe;else n=er,a=rr,s=tr;E(e,{name:t,A:p=>{var u=n(p+4,w[p>>2]*r,!0);return B(p),u},D:(p,u)=>{if(typeof u!="string")throw new M(`Cannot pass non-string to C++ string type ${t}`);var f=s(u),l=q(4+f+r);return w[l>>2]=f/r,a(u,l+4,f+r),p!==null&&p.push(B,l),l},F:N,B(p){B(p)}})},o:(e,r,t,n,a,s)=>{K[e]={name:C(r),N:b(t,n),O:b(a,s),elements:[]}},g:(e,r,t,n,a,s,p,u,f)=>{K[e].elements.push({K:r,I:b(t,n),J:a,R:s,P:b(p,u),S:f})},l:(e,r)=>{r=C(r),E(e,{M:!0,name:r,A:()=>{},D:()=>{}})},n:e=>{var r=P.length;if(e>>>=0,2147483648<e)return!1;for(var t=1;4>=t;t*=2){var n=r*(1+.2/t);n=Math.min(n,e+100663296);e:{n=(Math.min(2147483648,65536*Math.ceil(Math.max(e,n)/65536))-H.buffer.byteLength+65535)/65536|0;try{H.grow(n),fe();var a=1;break e}catch{}a=void 0}if(a)return!0}return!1}},z;return z=await(async function(){function e(t){return t=z=t.exports,Ee=t.s,$e=o._main=t.u,q=t.v,B=t.w,H=t.q,Pe=t.t,fe(),z}var r={a:nr};return o.instantiateWasm?new Promise(t=>{o.instantiateWasm(r,(n,a)=>{t(e(n,a))})}):(Z??(Z=o.locateFile?o.locateFile("millirec.wasm",G):G+"millirec.wasm"),e((await Te(r)).instance))})(),(function(){function e(){if(o.calledRun=!0,!Y){if(le=!0,z.r(),ne?.(o),o.onRuntimeInitialized?.(),!o.noInitialRun){var r=$e;try{var t=r(0,0);ye||(o.onExit?.(t),Y=!0),V(t,new ce(t))}catch(n){n instanceof ce||n=="unwind"||V(1,n)}}if(o.postRun)for(typeof o.postRun=="function"&&(o.postRun=[o.postRun]);o.postRun.length;)r=o.postRun.shift(),de.push(r);he(de)}}if(o.preRun)for(typeof o.preRun=="function"&&(o.preRun=[o.preRun]);o.preRun.length;)Fe();he(me),o.setStatus?(o.setStatus("Running..."),setTimeout(()=>{setTimeout(()=>o.setStatus(""),1),e()},1)):e()})(),le?m=o:m=new Promise((e,r)=>{ne=e,ae=r}),m}})();typeof exports=="object"&&typeof module=="object"?(module.exports=ShapeID,module.exports.default=ShapeID):typeof define=="function"&&define.amd&&define([],()=>ShapeID);var PARAMS={alpha:1,beta:.003,maxCost:30,divi:1,outliersMul:1,outlierCost:0,scoreMode:0,kappaGamma:0,gateScale:1,kappa0:.02};(typeof importScripts<"u"||typeof WorkerGlobalScope<"u")&&ShapeID({locateFile:function(i){return(self.__MILLIREC_ASSET_BASE||"")+(self.__MILLIREC_WASM_NAME||i)}}).then(function(i){ShapeID=i,postMessage({type:"getCharList"})}).catch(function(i){postMessage({type:"bootError",message:String(i&&i.message||i)})});var pointsPerShape=25,useBatch=!1,testSlot=0,samplesPerChar=10,charList=[];function prepIt(){ShapeID.firstCall&&(useBatch=PARAMS.useBatch!==!1&&!!ShapeID.identifyBatch,testSlot=charList.length*samplesPerChar,ShapeID.firstCall(PARAMS.alpha,PARAMS.beta,PARAMS.maxCost,PARAMS.divi,pointsPerShape,samplesPerChar,charList.length+(useBatch?1:0)),PARAMS.outlierCost&&ShapeID.setOutlierCost(PARAMS.outlierCost),PARAMS.scoreMode&&ShapeID.setScoreMode(PARAMS.scoreMode),PARAMS.kappaGamma&&ShapeID.setKappaGamma&&ShapeID.setKappaGamma(PARAMS.kappaGamma),PARAMS.gateMode!=null&&ShapeID.setGateMode&&ShapeID.setGateMode(PARAMS.gateMode),PARAMS.gateScale!=null&&ShapeID.setGateScale&&ShapeID.setGateScale(PARAMS.gateScale),postMessage({type:"prepAll"}))}function addPoints(i,h,m){for(var o=PARAMS.kappaGamma&&ShapeID.addPointK,S=h===-1&&useBatch?testSlot:-2,c=0;c<i.length;c++)if(i[c].x*=m,i[c].y*=m,o){var T=i[c].k?Math.tanh(i[c].k/PARAMS.kappa0):0;ShapeID.addPointK(h,c,i[c].x,i[c].y,i[c].s,i[c].c,T),S!==-2&&ShapeID.addPointK(S,c,i[c].x,i[c].y,i[c].s,i[c].c,T)}else ShapeID.addPoint(h,c,i[c].x,i[c].y,i[c].s,i[c].c),S!==-2&&ShapeID.addPoint(S,c,i[c].x,i[c].y,i[c].s,i[c].c)}function testOne(i,h){var m=useBatch?ShapeID.identifyBatch(charList.length,0,pointsPerShape,PARAMS.outliersMul,1,charList.length):ShapeID.identify(-1,0,pointsPerShape,0,PARAMS.outliersMul,-2);postMessage({type:"addResult",path:i,result:m,one:!0,elementID:h})}function testOneWrong(i){var h=ShapeID.identify(i.i,i.j,pointsPerShape,0,PARAMS.outliersMul,-1);postMessage({type:"addResult",path:i.path,result:h,one:!0,sid:i.sid,i:i.i,j:i.j})}function compareAll(i){for(var h=[],m=0;m<i.counts.length;m++){for(var o=[],S=0;S<i.counts[m];S++)o.push(ShapeID.getTestScore(m,S,pointsPerShape,PARAMS.outliersMul));h.push(o)}postMessage({type:"allResult",path:i.path,costs:h,elementID:i.elementID})}onmessage=function(i){if(i.data.type=="addPoints")addPoints(i.data.points,i.data.m,i.data.scale);else if(i.data.type=="charList")charList=i.data.charList,pointsPerShape=i.data.pointsPerShape,samplesPerChar=i.data.samplesPerChar,prepIt();else if(i.data.type=="compare")testOne(i.data.path,i.data.elementID);else if(i.data.type=="compareAll")compareAll(i.data);else if(i.data.type=="setParams"){for(var h in i.data.params)PARAMS[h]=i.data.params[h];charList.length&&prepIt()}else if(i.data.type=="compareWrong")testOneWrong(i.data);else if(i.data.type=="compareTrain"){var m=ShapeID.identify(i.data.d,i.data.sid,pointsPerShape,0,PARAMS.outliersMul,-1);postMessage({type:"addResult",path:i.data.path,result:m})}};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";(()=>{var Ue=Object.defineProperty;var je=(u,t,s)=>t in u?Ue(u,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):u[t]=s;var He=(u=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(u,{get:(t,s)=>(typeof require<"u"?require:t)[s]}):u)(function(u){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+u+'" is not supported')});var Zt=(u,t,s)=>je(u,typeof t!="symbol"?t+"":t,s);var ft=(()=>{var u=globalThis.document?.currentScript?.src;return async function(t={}){var s,e=t,o=!!globalThis.window,n=!!globalThis.WorkerGlobalScope,i=globalThis.process?.versions?.node&&globalThis.process?.type!="renderer",l=(r,a)=>{throw a};typeof __filename<"u"?u=__filename:n&&(u=self.location.href);var c="",p,m;if(i){var f=He("fs");c=__dirname+"/",m=r=>(r=v(r)?new URL(r):r,f.readFileSync(r)),p=async r=>(r=v(r)?new URL(r):r,f.readFileSync(r,void 0)),process.argv.slice(2),l=(r,a)=>{throw process.exitCode=r,a}}else if(o||n){try{c=new URL(".",u).href}catch{}n&&(m=r=>{var a=new XMLHttpRequest;return a.open("GET",r,!1),a.responseType="arraybuffer",a.send(null),new Uint8Array(a.response)}),p=async r=>{if(r=await fetch(r,{credentials:"same-origin"}),r.ok)return r.arrayBuffer();throw Error(r.status+" : "+r.url)}}console.log.bind(console);var g=console.error.bind(console),M,L=!1,v=r=>r.startsWith("file://"),O,S,b,E,_,k,P,T,R,z,H,Ct,Lt=!1;function Tt(){var r=ut.buffer;b=new Int8Array(r),_=new Int16Array(r),E=new Uint8Array(r),k=new Uint16Array(r),P=new Int32Array(r),T=new Uint32Array(r),R=new Float32Array(r),z=new Float64Array(r),H=new BigInt64Array(r),Ct=new BigUint64Array(r)}function Ot(r){throw e.onAbort?.(r),r="Aborted("+r+")",g(r),L=!0,r=new WebAssembly.RuntimeError(r+". Build with -sASSERTIONS for more info."),S?.(r),r}var xt;async function we(r){if(!M)try{var a=await p(r);return new Uint8Array(a)}catch{}if(r==xt&&M)r=new Uint8Array(M);else if(m)r=m(r);else throw"both async and sync fetching of the wasm failed";return r}async function ge(r,a){try{var h=await we(r);return await WebAssembly.instantiate(h,a)}catch(d){g(`failed to asynchronously prepare wasm: ${d}`),Ot(d)}}async function ye(r){var a=xt;if(!M&&!i)try{var h=fetch(a,{credentials:"same-origin"});return await WebAssembly.instantiateStreaming(h,r)}catch(d){g(`wasm streaming compile failed: ${d}`),g("falling back to ArrayBuffer instantiation")}return ge(a,r)}class Pt{constructor(a){Zt(this,"name","ExitStatus");this.message=`Program terminated with exit(${a})`,this.status=a}}var Rt=r=>{for(;0<r.length;)r.shift()(e)},zt=[],Wt=[],xe=()=>{var r=e.preRun.shift();Wt.push(r)},Nt=!0;class ve{constructor(a){this.G=a-24}}var $t=0,be=0,ct={},Bt=r=>{for(;r.length;){var a=r.pop();r.pop()(a)}};function lt(r){return this.A(T[r>>2])}var Z={},Y={},ht={},Ft=class extends Error{constructor(r){super(r),this.name="InternalError"}},Gt=(r,a,h)=>{function d(x){if(x=h(x),x.length!==r.length)throw new Ft("Mismatched type converter count");for(var I=0;I<r.length;++I)K(r[I],x[I])}r.forEach(x=>ht[x]=a);var w=Array(a.length),y=[],C=0;a.forEach((x,I)=>{Y.hasOwnProperty(x)?w[I]=Y[x]:(y.push(x),Z.hasOwnProperty(x)||(Z[x]=[]),Z[x].push(()=>{w[I]=Y[x],++C,C===y.length&&d(w)}))}),y.length===0&&d(w)},D=r=>{for(var a="";;){var h=E[r++];if(!h)return a;a+=String.fromCharCode(h)}},j=class extends Error{constructor(r){super(r),this.name="BindingError"}},_e=r=>{throw new j(r)};function ke(r,a,h={}){var d=a.name;if(!r)throw new j(`type "${d}" must have a positive integer typeid pointer`);if(Y.hasOwnProperty(r)){if(h.L)return;throw new j(`Cannot register type '${d}' twice`)}Y[r]=a,delete ht[r],Z.hasOwnProperty(r)&&(a=Z[r],delete Z[r],a.forEach(w=>w()))}function K(r,a,h={}){return ke(r,a,h)}var Dt=(r,a,h)=>{switch(a){case 1:return h?d=>b[d]:d=>E[d];case 2:return h?d=>_[d>>1]:d=>k[d>>1];case 4:return h?d=>P[d>>2]:d=>T[d>>2];case 8:return h?d=>H[d>>3]:d=>Ct[d>>3];default:throw new TypeError(`invalid integer width (${a}): ${r}`)}},Ut=[],Q=[0,1,,1,null,1,!0,1,!1,1],Ae=r=>{switch(r){case void 0:return 2;case null:return 4;case!0:return 6;case!1:return 8;default:let a=Ut.pop()||Q.length;return Q[a]=r,Q[a+1]=1,a}},Se={name:"emscripten::val",A:r=>{if(!r)throw new j(`Cannot use deleted val. handle = ${r}`);var a=Q[r];return 9<r&&--Q[r+1]===0&&(Q[r]=void 0,Ut.push(r)),a},D:(r,a)=>Ae(a),F:lt,B:null},Me=(r,a)=>{switch(a){case 4:return function(h){return this.A(R[h>>2])};case 8:return function(h){return this.A(z[h>>3])};default:throw new TypeError(`invalid float width (${a}): ${r}`)}};function jt(r){for(var a=1;a<r.length;++a)if(r[a]!==null&&r[a].B===void 0)return!0;return!1}var Ee=(r,a)=>{if(e[r].C===void 0){var h=e[r];e[r]=function(...d){if(!e[r].C.hasOwnProperty(d.length))throw new j(`Function '${a}' called with an invalid number of arguments (${d.length}) - expects one of (${e[r].C})!`);return e[r].C[d.length].apply(this,d)},e[r].C=[],e[r].C[h.H]=h}},Ie=(r,a,h)=>{if(e.hasOwnProperty(r)){if(h===void 0||e[r].C!==void 0&&e[r].C[h]!==void 0)throw new j(`Cannot register public name '${r}' twice`);if(Ee(r,r),e[r].C.hasOwnProperty(h))throw new j(`Cannot register multiple overloads of a function with the same number of arguments (${h})!`);e[r].C[h]=a}else e[r]=a,e[r].H=h},Ce=(r,a)=>{for(var h=[],d=0;d<r;d++)h.push(T[a+4*d>>2]);return h},nt=(r,a)=>{r=D(r);var h=Vt.get(a);if(typeof h!="function")throw new j(`unknown function pointer with signature ${r}: ${a}`);return h};class Le extends Error{}var Te=r=>{r=Kt(r);var a=D(r);return V(r),a},Oe=(r,a)=>{function h(y){w[y]||Y[y]||(ht[y]?ht[y].forEach(h):(d.push(y),w[y]=!0))}var d=[],w={};throw a.forEach(h),new Le(`${r}: `+d.map(Te).join([", "]))},Pe=r=>{r=r.trim();let a=r.indexOf("(");return a===-1?r:r.slice(0,a)},Re=new TextDecoder,Ht=(r,a,h,d)=>{if(h=a+h,d)return h;for(;r[a]&&!(a>=h);)++a;return a},ze=new TextDecoder("utf-16le"),We=(r,a,h)=>(r>>=1,ze.decode(k.subarray(r,Ht(k,r,a/2,h)))),Ne=(r,a,h)=>{if(h??(h=2147483647),2>h)return 0;h-=2;var d=a;h=h<2*r.length?h/2:r.length;for(var w=0;w<h;++w)_[a>>1]=r.charCodeAt(w),a+=2;return _[a>>1]=0,a-d},$e=r=>2*r.length,Be=(r,a,h)=>{var d="";r>>=2;for(var w=0;!(w>=a/4);w++){var y=T[r+w];if(!y&&!h)break;d+=String.fromCodePoint(y)}return d},Fe=(r,a,h)=>{if(h??(h=2147483647),4>h)return 0;var d=a;h=d+h-4;for(var w=0;w<r.length;++w){var y=r.codePointAt(w);if(65535<y&&w++,P[a>>2]=y,a+=4,a+4>h)break}return P[a>>2]=0,a-d},Ge=r=>{for(var a=0,h=0;h<r.length;++h)65535<r.codePointAt(h)&&h++,a+=4;return a};if(e.noExitRuntime&&(Nt=e.noExitRuntime),e.printErr&&(g=e.printErr),e.wasmBinary&&(M=e.wasmBinary),e.preInit)for(typeof e.preInit=="function"&&(e.preInit=[e.preInit]);0<e.preInit.length;)e.preInit.shift()();var Kt,Jt,vt,V,ut,Vt,De={h:(r,a,h)=>{var d=new ve(r);throw T[d.G+16>>2]=0,T[d.G+4>>2]=a,T[d.G+8>>2]=h,$t=r,be++,$t},m:()=>Ot(""),p:r=>{var a=ct[r];delete ct[r];var h=a.elements,d=h.length,w=h.map(x=>x.K).concat(h.map(x=>x.R)),y=a.N,C=a.O;Gt([r],w,x=>(h.forEach((I,A)=>{var $=x[A],U=I.I,W=I.J,J=x[A+d],q=I.P,pt=I.S;I.read=N=>$.A(U(W,N)),I.write=(N,G)=>{var B=[];q(pt,N,J.D(B,G)),Bt(B)}}),[{name:a.name,A:I=>{for(var A=Array(d),$=0;$<d;++$)A[$]=h[$].read(I);return C(I),A},D:(I,A)=>{if(d!==A.length)throw new TypeError(`Incorrect number of tuple elements for ${a.name}: expected=${d}, actual=${A.length}`);for(var $=y(),U=0;U<d;++U)h[U].write($,A[U]);return I!==null&&I.push(C,$),$},F:lt,B:C}]))},f:(r,a,h,d,w)=>{a=D(a),d=d===0n;let y=C=>C;if(d){let C=8*h;y=x=>BigInt.asUintN(C,x),w=y(w)}K(r,{name:a,A:y,D:(C,x)=>(typeof x=="number"&&(x=BigInt(x)),x),F:Dt(a,h,!d),B:null})},k:(r,a,h,d)=>{a=D(a),K(r,{name:a,A:function(w){return!!w},D:function(w,y){return y?h:d},F:function(w){return this.A(E[w])},B:null})},i:r=>K(r,Se),e:(r,a,h)=>{a=D(a),K(r,{name:a,A:d=>d,D:(d,w)=>w,F:Me(a,h),B:null})},c:(r,a,h,d,w,y,C)=>{var x=Ce(a,h);r=D(r),r=Pe(r),w=nt(d,w),Ie(r,function(){Oe(`Cannot call ${r} due to unbound types`,x)},a-1),Gt([],x,I=>{var A=[I[0],null].concat(I.slice(1));I=r;var $=r,U=w,W=A.length;if(2>W)throw new j("argTypes array size mismatch! Must at least get return value and 'this' types!");var J=A[1]!==null&&!1,q=jt(A),pt=!A[0].M,N=A[0],G=A[1];for(U=[$,_e,U,y,Bt,N.A.bind(N),G?.D.bind(G)],N=2;N<W;++N)G=A[N],U.push(G.D.bind(G));if(!q)for(N=J?1:2;N<A.length;++N)A[N].B!==null&&U.push(A[N].B);q=jt(A),N=A.length-2;var B=[];for(G=["fn"],J&&G.push("thisWired"),W=0;W<N;++W)B.push(`arg${W}`),G.push(`arg${W}Wired`);B=B.join(","),G=G.join(","),B=`return function (${B}) {
|
|
2
|
+
`,q&&(B+=`var destructors = [];
|
|
3
|
+
`);var qt=q?"destructors":"null",bt="humanName throwBindingError invoker fn runDestructors fromRetWire toClassParamWire".split(" ");for(J&&(B+=`var thisWired = toClassParamWire(${qt}, this);
|
|
4
|
+
`),W=0;W<N;++W){var Xt=`toArg${W}Wire`;B+=`var arg${W}Wired = ${Xt}(${qt}, arg${W});
|
|
5
|
+
`,bt.push(Xt)}if(B+=(pt||C?"var rv = ":"")+`invoker(${G});
|
|
6
|
+
`,q)B+=`runDestructors(destructors);
|
|
7
|
+
`;else for(W=J?1:2;W<A.length;++W)J=W===1?"thisWired":"arg"+(W-2)+"Wired",A[W].B!==null&&(B+=`${J}_dtor(${J});
|
|
8
|
+
`,bt.push(`${J}_dtor`));if(pt&&(B+=`var ret = fromRetWire(rv);
|
|
9
|
+
return ret;
|
|
10
|
+
`),A=new Function(bt,B+`}
|
|
11
|
+
`)(...U),$=Object.defineProperty(A,"name",{value:$}),A=a-1,!e.hasOwnProperty(I))throw new Ft("Replacing nonexistent public symbol");return e[I].C!==void 0&&A!==void 0?e[I].C[A]=$:(e[I]=$,e[I].H=A),[]})},b:(r,a,h,d,w)=>{a=D(a);let y=x=>x;if(d===0){var C=32-8*h;y=x=>x<<C>>>C,w=y(w)}K(r,{name:a,A:y,D:(x,I)=>I,F:Dt(a,h,d!==0),B:null})},a:(r,a,h)=>{function d(y){return new w(b.buffer,T[y+4>>2],T[y>>2])}var w=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,BigInt64Array,BigUint64Array][a];h=D(h),K(r,{name:h,A:d,F:d},{L:!0})},j:(r,a)=>{a=D(a),K(r,{name:a,A(h){var d=(d=h+4)?Re.decode(E.subarray(d,Ht(E,d,T[h>>2],!0))):"";return V(h),d},D(h,d){d instanceof ArrayBuffer&&(d=new Uint8Array(d));var w,y=typeof d=="string";if(!(y||ArrayBuffer.isView(d)&&d.BYTES_PER_ELEMENT==1))throw new j("Cannot pass non-string to std::string");var C;if(y)for(w=C=0;w<d.length;++w){var x=d.charCodeAt(w);127>=x?C++:2047>=x?C+=2:55296<=x&&57343>=x?(C+=4,++w):C+=3}else C=d.length;if(w=C,C=vt(4+w+1),x=C+4,T[C>>2]=w,y){if(y=x,x=w+1,w=E,0<x){x=y+x-1;for(var I=0;I<d.length;++I){var A=d.codePointAt(I);if(127>=A){if(y>=x)break;w[y++]=A}else if(2047>=A){if(y+1>=x)break;w[y++]=192|A>>6,w[y++]=128|A&63}else if(65535>=A){if(y+2>=x)break;w[y++]=224|A>>12,w[y++]=128|A>>6&63,w[y++]=128|A&63}else{if(y+3>=x)break;w[y++]=240|A>>18,w[y++]=128|A>>12&63,w[y++]=128|A>>6&63,w[y++]=128|A&63,I++}}w[y]=0}}else E.set(d,x);return h!==null&&h.push(V,C),C},F:lt,B(h){V(h)}})},d:(r,a,h)=>{if(h=D(h),a===2)var d=We,w=Ne,y=$e;else d=Be,w=Fe,y=Ge;K(r,{name:h,A:C=>{var x=d(C+4,T[C>>2]*a,!0);return V(C),x},D:(C,x)=>{if(typeof x!="string")throw new j(`Cannot pass non-string to C++ string type ${h}`);var I=y(x),A=vt(4+I+a);return T[A>>2]=I/a,w(x,A+4,I+a),C!==null&&C.push(V,A),A},F:lt,B(C){V(C)}})},o:(r,a,h,d,w,y)=>{ct[r]={name:D(a),N:nt(h,d),O:nt(w,y),elements:[]}},g:(r,a,h,d,w,y,C,x,I)=>{ct[r].elements.push({K:a,I:nt(h,d),J:w,R:y,P:nt(C,x),S:I})},l:(r,a)=>{a=D(a),K(r,{M:!0,name:a,A:()=>{},D:()=>{}})},n:r=>{var a=E.length;if(r>>>=0,2147483648<r)return!1;for(var h=1;4>=h;h*=2){var d=a*(1+.2/h);d=Math.min(d,r+100663296);t:{d=(Math.min(2147483648,65536*Math.ceil(Math.max(r,d)/65536))-ut.buffer.byteLength+65535)/65536|0;try{ut.grow(d),Tt();var w=1;break t}catch{}w=void 0}if(w)return!0}return!1}},dt;return dt=await(async function(){function r(h){return h=dt=h.exports,Kt=h.s,Jt=e._main=h.u,vt=h.v,V=h.w,ut=h.q,Vt=h.t,Tt(),dt}var a={a:De};return e.instantiateWasm?new Promise(h=>{e.instantiateWasm(a,(d,w)=>{h(r(d,w))})}):(xt??(xt=e.locateFile?e.locateFile("millirec.wasm",c):c+"millirec.wasm"),r((await ye(a)).instance))})(),(function(){function r(){if(e.calledRun=!0,!L){if(Lt=!0,dt.r(),O?.(e),e.onRuntimeInitialized?.(),!e.noInitialRun){var a=Jt;try{var h=a(0,0);Nt||(e.onExit?.(h),L=!0),l(h,new Pt(h))}catch(d){d instanceof Pt||d=="unwind"||l(1,d)}}if(e.postRun)for(typeof e.postRun=="function"&&(e.postRun=[e.postRun]);e.postRun.length;)a=e.postRun.shift(),zt.push(a);Rt(zt)}}if(e.preRun)for(typeof e.preRun=="function"&&(e.preRun=[e.preRun]);e.preRun.length;)xe();Rt(Wt),e.setStatus?(e.setStatus("Running..."),setTimeout(()=>{setTimeout(()=>e.setStatus(""),1),r()},1)):r()})(),Lt?s=e:s=new Promise((r,a)=>{O=r,S=a}),s}})();typeof exports=="object"&&typeof module=="object"?(module.exports=ft,module.exports.default=ft):typeof define=="function"&&define.amd&&define([],()=>ft);var Yt=ft;var Qt={stroke:{alpha:1,beta:.003,maxCost:30,divi:1,outliersMul:1,outlierCost:0,scoreMode:0,kappaGamma:0,gateScale:1},image:{alpha:5,beta:.002,maxCost:90,divi:1,outliersMul:2,outlierCost:0,scoreMode:0,kappaGamma:3,gateScale:.6}};function te(u){let t=[],s=0,e=0;for(let o=0;o<u.x.length;o++)s+=u.x[o],e+=u.y[o],t.push({x:s,y:e});return t}function _t(u){let t=u.length,s=[0,0],e=[0,0],o=[];for(let m=0;m<t;m++){let f=u[m];s[0]+=f.x,s[1]+=f.y;let g={x:f.x,y:f.y,a:1.570795};m>0&&f.x!==e[0]&&(g.a=Math.atan2(f.y-e[1],f.x-e[0])),g.s=Math.sin(g.a),g.c=Math.cos(g.a),m===1&&(o[0].s=g.s,o[0].c=g.c),e=[f.x,f.y],o.push(g)}s[0]/=t,s[1]/=t;let n=[0,0],i=[0,0],l=[0,0],c=[0,0];for(let m of o)m.x<s[0]?(l[0]+=m.x-s[0],l[1]++):(c[0]+=m.x-s[0],c[1]++),m.y<s[1]?(n[0]+=m.y-s[1],n[1]++):(i[0]+=m.y-s[1],i[1]++),m.x-=s[0],m.y-=s[1];n[1]>0&&(n[0]/=n[1]),i[1]>0&&(i[0]/=i[1]),l[1]>0&&(l[0]/=l[1]),c[1]>0&&(c[0]/=c[1]);let p=i[0]-n[0]<c[0]-l[0]?100/(c[0]-l[0]):n[0]<i[0]?100/(i[0]-n[0]):1;return{points:o,scale:p}}function ee(u,t=50){let s=[],e=0;for(let i of u)for(let l=1;l<i.length;l++){let c=i[l].x-i[l-1].x,p=i[l].y-i[l-1].y,m=Math.sqrt(c*c+p*p);s.push({ax:i[l-1].x,ay:i[l-1].y,bx:i[l].x,by:i[l].y,cumStart:e,cumEnd:e+m}),e+=m}if(!e||!s.length)return null;let o=[],n=0;for(let i=0;i<t;i++){let l=i*e/(t-1);for(;n<s.length-1&&s[n].cumEnd<l;)n++;let c=s[n],p=c.cumEnd-c.cumStart,m=p?Math.min(1,Math.max(0,(l-c.cumStart)/p)):0;o.push({x:c.ax+(c.bx-c.ax)*m,y:c.ay+(c.by-c.ay)*m})}return o}var F={capitals:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",lowercase:"abcdefghijklmnopqrstuvwxyz",digits:"0123456789",punctuation:",.:/'-%$"};F.all=F.capitals+F.lowercase+F.digits+F.punctuation;var kt=["capitals","lowercase","digits","punctuation","all"],re=",.:",fs="don't can't won't isn't aren't wasn't weren't hasn't haven't hadn't doesn't didn't wouldn't couldn't shouldn't i'm i've i'll i'd you're you've you'll you'd he's he'll he'd she's she'll she'd it's we're we've we'll we'd they're they've they'll they'd that's there's here's what's who's where's when's how's let's o'clock ain't y'all ma'am".split(" "),ne=F.capitals;function et(u="capitals"){if(Array.isArray(u))return[...new Set(u.map(e=>String(e)).filter(e=>e.length===1))];let t=String(u??"capitals").trim();if(!t)return[...F.capitals];let s=t.split(/[,+\s]+/).filter(Boolean);return s.every(e=>F[e])?[...new Set(s.flatMap(e=>[...F[e]]))]:[...new Set([...t.replace(/\s+/g,"")])]}function it(u){let t=[...u].join("");for(let s of kt)if([...new Set([...F[s]])].join("")===t)return s;return null}var oe=u=>u.some(t=>t!==t.toLowerCase()),ie=u=>u.some(t=>t!==t.toUpperCase());function ae(u,t,s=null){let e=t,o=s||new Map(e.map((c,p)=>[c,p])),n=String(u??"").trim();if(!n)return null;let i=oe(e),l=ie(e);i&&!l?n=n.toUpperCase():l&&!i&&(n=n.toLowerCase());for(let c of n)if(!o.has(c))return null;return n}function st(u,{alphabet:t="capitals",weightOf:s=n=>1/(n+1),topK:e=8,variants:o="auto"}={}){let n=et(t),i=new Map(n.map((_,k)=>[_,k])),l=n.length,c=0,p=_=>({id:c++,ch:new Array(l).fill(null),mass:0,end:0,depth:_,word:null,top:[],logMass:0}),m=p(0),f=new Set,g=[],M=0,L=oe(n)&&ie(n),v=o===!0||o==="auto"&&L,O=(_,k)=>{if(f.has(_))return;f.add(_),g.push(_);let P=m,T=[m];for(let R of _){let z=i.get(R);P=P.ch[z]||(P.ch[z]=p(T.length)),T.push(P)}P.end+=k,P.word=_;for(let R of T){R.mass+=k;let z=R.top;if(z.length<e||k>z[z.length-1].wt){let H=z.length;for(;H>0&&z[H-1].wt<k;)H--;z.splice(H,0,{word:_,wt:k}),z.length>e&&z.pop()}}};for(let _ of u||[]){let k=ae(_,n,i);if(!k)continue;let P=s(M,k);if(M++,O(k,P),v&&k===k.toLowerCase()&&k!==k.toUpperCase()){let T=k[0].toUpperCase()+k.slice(1);[...T].every(z=>i.has(z))&&O(T,P/3);let R=k.toUpperCase();[...R].every(z=>i.has(z))&&O(R,P/10)}}let S=[m];for(;S.length;){let _=S.pop();_.logMass=_.mass>0?Math.log(_.mass):-1/0;for(let k of _.ch)k&&S.push(k)}let b={id:-2,ch:new Array(l).fill(null),mass:1,end:1,depth:-1,word:null,top:[],logMass:0,mark:!0},E=_=>{let k=m,P=String(_);for(let T=0;T<P.length;T++){let R=P[T],z=i.get(R),H=z==null?null:k.ch[z];if(!H)return T===P.length-1&&re.includes(R)&&k.end>0?b:null;k=H}return k};return{root:m,size:g.length,words:g,lookup:E,alphabet:n,idx:i,free:g.length===0,markNode:b}}function rt(u){return String(u||"").split(/[\s,;]+/).map(t=>t.trim()).filter(Boolean)}async function ce(u,t,{params:s=null,locateFile:e=null,alphabet:o=null}={}){let n={...Qt.stroke,...s||{}},i=await u(e?{locateFile:e}:{}),l=o?new Set(et(o)):null,c=Object.keys(t.classes).filter(b=>!l||l.has(b[0]));if(!c.length)throw new Error("createMatcher: no template class matches the alphabet");let p=new Map(c.map((b,E)=>[b,E])),m=Math.max(1,...c.map(b=>t.classes[b].length)),f=t.pointsPerShape;i.firstCall(n.alpha,n.beta,n.maxCost,n.divi,f,m,c.length),n.outlierCost&&i.setOutlierCost(n.outlierCost),n.scoreMode&&i.setScoreMode(n.scoreMode),n.kappaGamma&&i.setKappaGamma&&i.setKappaGamma(n.kappaGamma),n.gateMode!=null&&i.setGateMode&&i.setGateMode(n.gateMode),n.gateScale!=null&&i.setGateScale&&i.setGateScale(n.gateScale);let g=0,M=new Map,L=1;c.forEach((b,E)=>t.classes[b].forEach((_,k)=>{let{points:P,scale:T}=_t(te(_));if(P.forEach((R,z)=>i.addPoint(E*m+k,z,R.x*T,R.y*T,R.s,R.c)),g++,b.length===1&&_.strokes>0){M.has(b)||M.set(b,{n:0,hist:new Map});let R=M.get(b);R.n++,R.hist.set(_.strokes,(R.hist.get(_.strokes)||0)+1),_.strokes>L&&(L=_.strokes)}}));let v=L+2,O=.5,S=0;return{pps:f,keys:c,spc:m,training:t,params:n,templates:g,current:null,alphabet:[...new Set(c.map(b=>b[0]))],has:b=>p.has(b),strokeLogP(b,E){let _=M.get(b);if(!_)return 0;let k=Math.min(Math.max(1,E),v),P=((_.hist.get(k)||0)+O)/(_.n+O*v);return Math.log(P*v)},get calls(){return S},upload(b,E=null){this.current=E;let _=ee(b,f);if(!_)return!1;let{points:k,scale:P}=_t(_);for(let T=0;T<k.length;T++){let R=k[T];i.addPoint(-1,T,R.x*P,R.y*P,R.s,R.c)}return!0},costs(b){let E=p.get(b),_=new Array(t.classes[b].length);for(let k=0;k<_.length;k++)_[k]=i.getTestScore(E,k,f,n.outliersMul),S++;return _}}}function se(u,t="prod"){let s=1/0,e=1/0;for(let o of u)o<s?(e=s,s=o):o<e&&(e=o);return t==="min"||s===1/0?s:e===1/0?Math.cbrt(.9)*s:Math.cbrt(s*s*e)}var At={maxStrokes:5,costRef:.5,costEps:.02,temp:.4,shMax:4,lmW:1,commitMargin:5,beamMargin:12,beamK:32,oovPen:15,endFloor:-10,doneBoost:1,combine:"prod",combinePart:"min",pruneClasses:!0,oovTrigger:0,sizeW:1,sizeCap:8,tinyShape:1,freeMarkShare:.15,sizeRef0:160,sizeSd0:.35,sizeSd:.15,markP:.3,tinyRatio:.5,tinyPen:8,strokeCountW:"auto"},ot=class{constructor({matcher:t,lexicon:s,opts:e={}}){this.m=t,this.opts={...At,...e},this._useLexicon(s),this.reset()}_useLexicon(t){this.lex=t,this.A=t.alphabet,this.idx=t.idx,this.NA=this.A.length,this.LOGA=-Math.log(this.NA),this.ALL=Array.from({length:this.NA},(c,p)=>p),this.markIdx=[...re].map(c=>this.idx.get(c)).filter(c=>c!=null);let s=this.m.training&&this.m.training.sizes||{},e=this.m.training&&this.m.training.capRef||84;this.capRef=e,this.sizes=this.A.map(c=>s[c]?{mu:s[c].mu,sd:Math.max(.15,s[c].sd||0),eligible:Math.exp(s[c].mu)>=.4*e,minStroke:s[c].minStroke||0,tiny:Math.exp(s[c].mu)<.2*e}:null);let o=this.A.map(c=>F.punctuation.includes(c)),n=o.filter(Boolean).length,i=this.NA-n;this.freeLogP=this.A.map((c,p)=>n&&i?Math.log(o[p]?this.opts.freeMarkShare/n:(1-this.opts.freeMarkShare)/i):this.LOGA);let l=this.A.filter(c=>!this.m.has(c));l.length&&console.warn("OverlapRecognizer: no templates for "+JSON.stringify(l.join("")))}_sizeRef(){let t=[],s=o=>{for(let n of o){let i=this.idx.get(n.ch),l=i==null?null:this.sizes[i];!l||!l.eligible||!n.dim||t.push(n.dim/Math.exp(l.mu))}};for(let o of this.words)s(o.groups);s(this.beam[0].groups);let e=t.slice(-12).sort((o,n)=>o-n);return e.length?{scale:e[Math.floor(e.length/2)],known:!0}:{scale:this.opts.sizeRef0/this.capRef,known:!1}}_sizeScore(t,s){let e=this.sizes[s];if(!e||!t.dim)return 0;let o=0;if(this.opts.sizeW){let n=this._sizeZ(t,s);o-=this.opts.sizeW*Math.min(this.opts.sizeCap,.5*n*n)}return t.k>1&&e.minStroke&&t.minFrac<this.opts.tinyRatio*e.minStroke&&(o-=this.opts.tinyPen),o}get free(){return this.lex.size===0}get scw(){let t=this.opts.strokeCountW;return t==="auto"||t==null?this.free?1:.25:Number(t)}reset(){return this.strokes=[],this.erased=[],this.beam=[this._rootEntry()],this.words=[],this.cache=new Map,this.history=[],this.nextId=1,this.last=this._state([],null,0),this.last}setLexicon(t){this._snapshot();let s=this.beam[0].text,e=t.alphabet.join("")===this.A.join("");this._useLexicon(t),e||this.cache.clear();let o=t.size?t.lookup(s):null;return this.beam=[{text:s,node:t.size?o:null,score:0,groups:this.beam[0].groups}],this._report(null)}setOpts(t){return this.opts={...this.opts,...t},this._report(null)}_rootEntry(){return{text:"",node:this.lex.size?this.lex.root:null,score:0,groups:[]}}_snapshot(){this.history.push({strokes:this.strokes.slice(),erased:this.erased.slice(),beam:this.beam.slice(),words:this.words.slice()}),this.history.length>200&&this.history.shift()}clearWord(){return this._snapshot(),this.strokes=[],this.erased=[],this.beam=[this._rootEntry()],this._report(null)}undo(){let t=this.history.pop();return t?(this.strokes=t.strokes,this.erased=t.erased,this.beam=t.beam,this.words=t.words,this._report(null)):this.last}addStroke(t,{t0:s=0,t1:e=0}={}){return!t||t.length<2?this.last:(this._snapshot(),this.strokes.push({id:this.nextId++,pts:t.map(o=>({x:o.x,y:o.y})),t0:s,t1:e}),this._step())}finishWord({word:t=null}={}){if(t)return this.selectWord(t,{finish:!0});this._snapshot();let s=tt(),e=this.opts,o=null,n=new Map,i=(p,m,f,g)=>{let M=m+e.lmW*this._endLogP(f);(!n.has(p)||n.get(p).score<M)&&n.set(p,{text:p,score:M,groups:g,inList:!!(f&&f.end)}),(!o||M>o.score)&&(o=n.get(p))};if(this.strokes.length===0)for(let p of this.beam)i(p.text,p.score,p.node,p.groups);else{let{hyps:p}=this._dp(),m=(f,g)=>this.beam[g.beam].groups.concat(g.groups,[this._mkGroup(f.i,this.strokes.length,f.L,f.shapeFull)]);for(let f of p){if(f.shapeFull===-1/0)continue;let g=this._path(f);i(f.text,f.score-f.shape+f.shapeFull,f.node,m(f,g))}if(!o)for(let f of p){let g=this._path(f);i(f.text,f.score,f.node,m(f,g))}}o||(o={text:this.beam[0].text,score:0,groups:this.beam[0].groups,inList:!1});let l=[...n.values()].sort((p,m)=>m.score-p.score).slice(0,6).map(p=>({text:p.text,score:p.score,inList:p.inList})),c={word:o.text,groups:o.groups,alternatives:l,inList:o.inList,selected:!1};return this._finish(c,tt()-s)}_finish(t,s){return t.word&&this.words.push(t),this._ref=null,this.strokes=[],this.erased=[],this.beam=[this._rootEntry()],this.cache.clear(),this.last=this._state([],null,s,{finished:t}),this.last}fitToWord(t){let s=ae(t,this.A,this.idx),e=this.erased.concat(this.strokes),o=e.length;if(!s||!o)return null;let n=[...s].map(v=>this.idx.get(v)),i=this.opts,l=Math.min(n.length,o),c=-1/0,p=Array.from({length:l+1},()=>new Float64Array(o+1).fill(c)),m=Array.from({length:l+1},()=>new Int32Array(o+1).fill(-1));p[0][0]=0;for(let v=1;v<=l;v++){let O=n[v-1];for(let S=v;S<o;S++)for(let b=Math.max(v-1,S-i.maxStrokes);b<S;b++){if(p[v-1][b]===c)continue;let E=this._groupOf(e,b,S);this._cost(E,O);let _=this._closedScore(E,O);if(_===c)continue;let k=p[v-1][b]+_;k>p[v][S]&&(p[v][S]=k,m[v][S]=b)}}let f=null;for(let v=1;v<=l;v++){let O=n[v-1];for(let S=Math.max(v-1,o-i.maxStrokes);S<o;S++){if(p[v-1][S]===c)continue;let b=this._groupOf(e,S,o);this._cost(b,O);let{full:E,part:_,best:k}=this._openScore(b,O);if(k===c)continue;let P=p[v-1][S]+k;(!f||P>f.score)&&(f={score:P,m:v,i:S,partial:_>E,sF:E})}}if(!f)return null;let g=[],M=f.i;for(let v=f.m-1;v>=1;v--){let O=m[v][M];g.push(this._mkGroupOf(e,O,M,n[v-1])),M=O}return g.reverse(),g.push({...this._mkGroupOf(e,f.i,o,n[f.m-1],f.sF),open:!0,partial:f.partial}),{text:s.slice(0,f.m),groups:g,m:f.m,complete:f.m===n.length&&!f.partial,score:f.score,word:s}}selectWord(t,{finish:s=!0}={}){let e=this.fitToWord(t);if(!e)return this.last;this._snapshot();let o=tt();if(s){let p=e.groups.map(g=>({ch:g.ch,ids:g.ids,strokes:g.strokes,sh:g.sh}));for(let g=e.m;g<e.word.length;g++)p.push({ch:e.word[g],ids:[],strokes:[],sh:null});let m=this.lex.size?this.lex.lookup(e.word):null,f={word:e.word,groups:p,alternatives:[],inList:!!(m&&m.end),selected:!0,complete:e.complete};return this._finish(f,tt()-o)}let n=e.groups.slice(0,-1),i=e.groups[e.groups.length-1],l=n.map(p=>p.ch).join("");this.beam=[{text:l,node:this.lex.size?this.lex.lookup(l):null,score:0,groups:n.map(p=>({ch:p.ch,ids:p.ids,strokes:p.strokes,sh:p.sh}))}];let c=this.erased.concat(this.strokes);return this.erased=c.slice(0,c.length-i.ids.length),this.strokes=c.slice(c.length-i.ids.length),this._report({b:0,margin:1/0,erased:[],selected:e.word})}_sh(t){if(t===1/0)return-1/0;let s=(Math.log(this.opts.costRef)-Math.log(t+this.opts.costEps))/this.opts.temp,e=this.opts.shMax;return s>0&&e>0?e*Math.tanh(s/e):s}_next(t,s){if(t===null)return{node:null,lm:this.free?this.freeLogP[s]:this.LOGA};let e=t.ch[s];return e?{node:e,lm:e.logMass-t.logMass}:t.end>0&&!t.mark&&this.markIdx.includes(s)?{node:this.lex.markNode,lm:Math.log(t.end)-t.logMass+Math.log(this.opts.markP)}:{node:null,lm:this.LOGA-this.opts.oovPen}}_endLogP(t){return t===null?this.free?0:-this.opts.oovPen:t.end?Math.log(t.end)-t.logMass:this.opts.endFloor}_groupOf(t,s,e){let o=t.slice(s,e).map(M=>M.id).join(","),n=this.cache.get(o);if(n)return n;let i=t.slice(s,e).map(M=>M.pts),l=1/0,c=1/0,p=-1/0,m=-1/0;for(let M of i)for(let L of M)L.x<l&&(l=L.x),L.y<c&&(c=L.y),L.x>p&&(p=L.x),L.y>m&&(m=L.y);let f=Math.max(p-l,m-c,1),g=1/0;for(let M of i){let L=1/0,v=1/0,O=-1/0,S=-1/0;for(let E of M)E.x<L&&(L=E.x),E.y<v&&(v=E.y),E.x>O&&(O=E.x),E.y>S&&(S=E.y);let b=Math.max(O-L,S-v,1);b<g&&(g=b)}return n={key:o,k:e-s,pts:i,dim:f,minFrac:g/f,full:new Float64Array(this.NA).fill(NaN),part:new Float64Array(this.NA).fill(NaN),scored:[],ok:null},this.cache.set(o,n),n}_cost(t,s){if(Number.isNaN(t.full[s])){(t.ok===null||this.m.current!==t.key)&&(t.ok=this.m.upload(t.pts,t.key));let e=this.A[s];t.full[s]=t.ok&&this.m.has(e)?se(this.m.costs(e),this.opts.combine):1/0;let o=e+"/"+t.k;t.part[s]=t.ok&&this.m.has(o)?se(this.m.costs(o),this.opts.combinePart):1/0,t.scored.push(s)}return{full:t.full[s],part:t.part[s]}}_sizeZ(t,s){let e=this.sizes[s];if(!e||!t.dim)return 0;this._ref||(this._ref=this._sizeRef());let o=Math.sqrt(e.sd*e.sd+(this._ref.known?this.opts.sizeSd:this.opts.sizeSd0)**2);return(Math.log(t.dim/this._ref.scale)-e.mu)/o}_shOf(t,s){if(t.full[s]===1/0)return-1/0;let e=this.sizes[s];return e&&e.tiny?this._sizeZ(t,s)<3?this.opts.tinyShape:-1/0:this._sh(t.full[s])}_closedScore(t,s){let e=this._shOf(t,s);return e===-1/0?-1/0:e*t.k+this.scw*this.m.strokeLogP(this.A[s],t.k)+this._sizeScore(t,s)}_openScore(t,s){let e=this._shOf(t,s),o=this._sh(t.part[s]),n=e===-1/0?-1/0:e*t.k+this.scw*this.m.strokeLogP(this.A[s],t.k)+this._sizeScore(t,s),i=o===-1/0?-1/0:o*t.k;return{full:n,part:i,best:Math.max(n,i)}}_scoreGroup(t,s,e){if(s===this.ALL||!this.opts.pruneClasses){for(let n of this.ALL)this._cost(t,n);return t.scored}let o=-1/0;for(let n of s){let i=this._cost(t,n),l=e?Math.max(this._sh(i.full),this._sh(i.part)):this._sh(i.full);l>o&&(o=l)}if(o<this.opts.oovTrigger)for(let n of this.ALL)this._cost(t,n);return t.scored}_allowed(t){if(!this.opts.pruneClasses)return this.ALL;let s=new Set;for(let e of t){if(e.node===null)return this.ALL;let o=e.node.ch;for(let n=0;n<this.NA;n++)o[n]&&s.add(n);if(e.node.end>0&&!e.node.mark)for(let n of this.markIdx)s.add(n)}return[...s]}_group(t,s){return this._groupOf(this.strokes,t,s)}_dp(t=-1){let s=this.strokes,e=s.length,o=this.opts,n=new Array(e+1);n[0]=this.beam.map((c,p)=>({score:c.score,node:c.node,text:c.text,beam:p,back:null,pos:0}));let i=new Array(e+1);i[0]=this._allowed(n[0]);for(let c=1;c<=e;c++){let p=new Map;if(c!==t&&c<e)for(let m=Math.max(0,c-o.maxStrokes);m<c;m++){if(!n[m].length)continue;let f=this._group(m,c),g=this._scoreGroup(f,i[m],!1);for(let M of n[m])for(let L of g){let v=this._closedScore(f,L);if(v===-1/0)continue;let O=this._next(M.node,L),S=M.score+v+o.lmW*O.lm,b=M.text+this.A[L],E=O.node?O.node.id:"off:"+b,_=p.get(E);(!_||_.score<S)&&p.set(E,{score:S,node:O.node,text:b,beam:M.beam,back:{i:m,st:M,L,sh:v},pos:c})}}n[c]=[...p.values()].sort((m,f)=>f.score-m.score).slice(0,o.beamK),i[c]=this._allowed(n[c])}let l=[];for(let c=Math.max(0,e-o.maxStrokes);c<e;c++){if(!n[c].length)continue;let p=this._group(c,e),m=this._scoreGroup(p,i[c],!0);for(let f of n[c])for(let g of m){let{full:M,part:L,best:v}=this._openScore(p,g);if(v===-1/0)continue;let O=this._next(f.node,g);l.push({score:f.score+v+o.lmW*O.lm,i:c,st:f,L:g,node:O.node,text:f.text+this.A[g],partial:L>M,shape:v,shapeFull:M,shapePart:L,lm:O.lm})}}return l.sort((c,p)=>p.score-c.score),{states:n,hyps:l}}_path(t){let s=[],e=t.st;for(;e.back;)s.push(this._mkGroup(e.back.i,e.pos,e.back.L,e.back.sh)),e=e.back.st;return s.reverse(),{beam:e.beam,groups:s,bounds:s.map(o=>o.j)}}_mkGroupOf(t,s,e,o,n=null){let i=t.slice(s,e);return{ch:this.A[o],ids:i.map(l=>l.id),strokes:i.map(l=>l.pts),sh:n,j:e,dim:this._groupOf(t,s,e).dim}}_mkGroup(t,s,e,o=null){return this._mkGroupOf(this.strokes,t,s,e,o)}_step(){let t=tt();this._ref=null;let{hyps:s}=this._dp(),e=null;if(s.length){let o=s[0],n=this._path(o),i=[o.i,...n.bounds.slice().reverse()].filter((l,c,p)=>l>0&&p.indexOf(l)===c);for(let l of i){let c=this._dp(l),p=c.hyps.length?c.hyps[0].score:-1/0,m=o.score-p;if(m>=this.opts.commitMargin){e={b:l,margin:m};break}}}return e&&(e.erased=this._commit(e.b,s),this._ref=null,{hyps:s}=this._dp()),this.last=this._state(s,e,tt()-t),this.last}_commit(t,s){let e=this.opts,o=s[0].score,n=new Map;for(let m of s){if(m.score<o-e.beamMargin)break;let f=m.st;if(m.i<t)continue;for(;f&&f.pos>t;)f=f.back?f.back.st:null;if(!f||f.pos!==t)continue;let g=f.node?f.node.id:"off:"+f.text,M=n.get(g);(!M||M.total<m.score)&&n.set(g,{st:f,total:m.score})}let i=[...n.values()].sort((m,f)=>f.total-m.total).slice(0,e.beamK),l=this.beam,c=this.strokes.slice(0,t),p=i[0].st.score;return this.beam=i.map(({st:m})=>{let f=[],g=m;for(;g.back;)f.push(this._mkGroup(g.back.i,g.pos,g.back.L,g.back.sh)),g=g.back.st;return f.reverse(),{text:m.text,node:m.node,score:m.score-p,groups:l[g.beam].groups.concat(f)}}),this.erased=this.erased.concat(c),this.strokes=this.strokes.slice(t),c}_report(t){this._ref=null;let{hyps:s}=this._dp();return this.last=this._state(s,t,0),this.last}_candidates(t){let s=this.opts,e=new Map,o=(l,c,p)=>{let m=e.get(l);(!m||m.score<c)&&e.set(l,{word:l,score:c,kind:p,complete:p==="done"})},n=t.length?t:this.beam.map(l=>({score:l.score,node:l.node,text:l.text})),i=n.length?n[0].score:0;for(let l of n){if(l.score<i-s.beamMargin)break;if(l.node===null){l.text&&o(l.text,l.score-(this.free?0:s.oovPen),this.free?"free":"oov");continue}if(l.node.mark){o(l.text,l.score+s.doneBoost,"done");continue}l.node.end&&o(l.text,l.score+s.lmW*(Math.log(l.node.end)-l.node.logMass)+s.doneBoost,"done");for(let c of l.node.top)o(c.word,l.score+s.lmW*(Math.log(c.wt)-l.node.logMass),c.word===l.text?"done":"more")}return[...e.values()].sort((l,c)=>c.score-l.score).slice(0,8)}_state(t,s,e,o={}){let n=t[0]||null,i=[];n?i=this._path(n).groups.map(p=>({ch:p.ch,ids:p.ids,strokes:p.strokes,open:!1})).concat([{ch:this.A[n.L],ids:this.strokes.slice(n.i).map(p=>p.id),strokes:this.strokes.slice(n.i).map(p=>p.pts),open:!0,partial:n.partial}]):this.strokes.length&&(i=[{ch:"",ids:this.strokes.map(c=>c.id),strokes:this.strokes.map(c=>c.pts),open:!0,partial:!0}]);let l=c=>{let p=this._path(c);return{text:c.text,score:c.score,i:c.i,partial:c.partial,shape:c.shape,lm:c.lm,groups:p.groups.map(m=>m.ch+"("+m.ids.length+")").concat([c.partial?c.text.slice(-1)+"\u2026":c.text.slice(-1)]),beam:p.beam}};return{n:this.strokes.length,text:n?n.text:this.beam[0].text,committed:this.beam[0].text,pending:n?n.text.slice(this.beam[0].text.length):"",ambiguous:this.beam.length>1,beam:this.beam.map(c=>({text:c.text,score:c.score,oov:c.node===null&&!this.free})),groups:this.beam[0].groups,hyps:t.slice(0,10).map(l),assignment:i,candidates:this._candidates(t),commit:s?{b:s.b,margin:s.margin,erased:s.erased,selected:s.selected||null}:null,words:this.words,strokes:this.strokes,alphabet:this.A,free:this.free,sizeRef:this._ref||this._sizeRef(),ms:e,...o}}},tt=()=>typeof performance<"u"?performance.now():Date.now();var Je="1.0.0",It="__MILLIREC_BASE_URL__",de=!It.startsWith("__"),Ve=(()=>{let u=typeof document<"u"&&document.currentScript&&document.currentScript.src||"";return u?u.slice(0,u.lastIndexOf("/")+1):""})(),Mt=typeof window<"u"?window:globalThis,gt=()=>Mt.MILLIREC_OVERLAP||{},yt=u=>u.assetBase||gt().assetBase||(de?It+"/overlap/":Ve),qe=u=>(u.apiBase||gt().apiBase||(de?It:"")).replace(/\/$/,""),mt=new Map;function Et(u,t){let s=et(t),o=`training.${it(s)||"all"}.json`,n=u+"|"+s.join("");return mt.has(n)||mt.set(n,(async()=>{let i=await fetch(u+o);if(!i.ok)throw new Error(`MillirecOverlap: could not load ${u}${o} (${i.status})`);let l=await i.json(),c=await ce(Yt,l,{locateFile:p=>u+p,alphabet:s});return{training:l,matcher:c,alphabet:s}})().catch(i=>{throw mt.delete(n),i})),mt.get(n)}async function le(u){if(Array.isArray(u.words))return{words:u.words,source:"words"};if(typeof u.words=="string"&&u.words.trim())return{words:rt(u.words),source:"words"};if(u.list){let s=qe(u);if(!s)throw new Error("MillirecOverlap: a hosted list (data-list) needs apiBase \u2014 the millirec server this list lives on");let e=await fetch(`${s}/api/overlap/lists/${encodeURIComponent(u.list)}`);if(!e.ok)throw new Error(`MillirecOverlap: word list ${u.list} not found (${e.status})`);let o=await e.json();return{words:o.words,source:"list",list:u.list,name:o.name}}if(u.wordsSrc){let s=await fetch(u.wordsSrc);if(!s.ok)throw new Error(`MillirecOverlap: could not load ${u.wordsSrc} (${s.status})`);let e=await s.text(),o;try{let n=JSON.parse(e);o=Array.isArray(n)?n:n.words}catch{o=rt(e)}return{words:o,source:"src"}}if(Array.isArray(gt().words))return{words:gt().words,source:"global"};if(Array.isArray(Mt.MILLIREC_WORDS))return{words:Mt.MILLIREC_WORDS,source:"global"};let t=await fetch(yt(u)+"words.json");if(!t.ok)throw new Error("MillirecOverlap: no word list given and the default words.json is missing");return{words:await t.json(),source:"default"}}var Xe=`
|
|
12
|
+
:host { display: inline-block; box-sizing: border-box; font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--mo-ink, #111827);
|
|
13
|
+
--_ink: var(--mo-ink, #111827); --_bg: var(--mo-bg, #ffffff); --_line: var(--mo-line, #d4d4d8); --_muted: var(--mo-muted, #9ca3af);
|
|
14
|
+
--_accent: var(--mo-accent, #2563eb); --_grey: var(--mo-suspect, #b6b6bb); --_chip: var(--mo-chip, #f3f4f6); --_radius: var(--mo-radius, 10px); }
|
|
15
|
+
:host([data-theme="dark"]) { --_ink: var(--mo-ink, #f5f5f4); --_bg: var(--mo-bg, #1c1c1b); --_line: var(--mo-line, #3f3f46); --_muted: var(--mo-muted, #8a8a93);
|
|
16
|
+
--_accent: var(--mo-accent, #60a5fa); --_grey: var(--mo-suspect, #55555c); --_chip: var(--mo-chip, #2a2a2e); }
|
|
17
|
+
@media (prefers-color-scheme: dark) { :host([data-theme="auto"]) { --_ink: var(--mo-ink, #f5f5f4); --_bg: var(--mo-bg, #1c1c1b); --_line: var(--mo-line, #3f3f46); --_muted: var(--mo-muted, #8a8a93);
|
|
18
|
+
--_accent: var(--mo-accent, #60a5fa); --_grey: var(--mo-suspect, #55555c); --_chip: var(--mo-chip, #2a2a2e); } }
|
|
19
|
+
* { box-sizing: border-box; }
|
|
20
|
+
.mo { display: flex; flex-direction: column; gap: 8px; color: var(--_ink); }
|
|
21
|
+
.mo.row { flex-direction: row; align-items: flex-start; flex-wrap: wrap; }
|
|
22
|
+
.mo.row .side { flex: 1 1 200px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
|
|
23
|
+
.box { display: block; border: 1.5px dashed var(--_line); border-radius: var(--_radius); background: var(--_bg); touch-action: none; cursor: crosshair; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
|
|
24
|
+
.box.busy { opacity: .5; cursor: progress; }
|
|
25
|
+
.text { min-height: 1.5em; font-size: 20px; font-weight: 600; letter-spacing: .04em; word-break: break-word; }
|
|
26
|
+
.text .done { color: var(--_ink); }
|
|
27
|
+
.text .cur { color: var(--_accent); }
|
|
28
|
+
.text .pend { color: var(--_muted); }
|
|
29
|
+
.text .ph { color: var(--_muted); font-weight: 400; font-size: 14px; letter-spacing: 0; }
|
|
30
|
+
.hw { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; min-height: 34px; }
|
|
31
|
+
.hw canvas { display: block; }
|
|
32
|
+
.hw .prev { opacity: .55; }
|
|
33
|
+
.words { display: flex; flex-wrap: wrap; gap: 6px; min-height: 1.6em; }
|
|
34
|
+
.chip { border: 1px solid var(--_line); background: var(--_chip); color: var(--_ink); border-radius: 999px; padding: 3px 10px; font: inherit; font-size: 13px; font-weight: 600; letter-spacing: .04em; cursor: pointer; }
|
|
35
|
+
.chip.best { border-color: var(--_accent); color: var(--_accent); }
|
|
36
|
+
.chip.complete::after { content: " \u2713"; font-weight: 400; color: var(--_muted); }
|
|
37
|
+
.chip.oov { font-style: italic; color: var(--_muted); }
|
|
38
|
+
.chip:hover { border-color: var(--_ink); }
|
|
39
|
+
.bar { display: flex; gap: 6px; flex-wrap: wrap; }
|
|
40
|
+
.bar button { border: 1px solid var(--_line); background: var(--_bg); color: var(--_ink); border-radius: 6px; padding: 4px 10px; font: inherit; font-size: 13px; cursor: pointer; }
|
|
41
|
+
.bar button.primary { background: var(--_ink); color: var(--_bg); border-color: var(--_ink); }
|
|
42
|
+
.bar button:disabled { opacity: .4; cursor: default; }
|
|
43
|
+
.err { color: #dc2626; font-size: 12px; }
|
|
44
|
+
[hidden] { display: none !important; }
|
|
45
|
+
`,Ze=["ready","stroke","change","word","select","error"],at=class u{constructor(t,s={}){let e=typeof t=="string"?document.querySelector(t):t;if(!e)throw new Error("MillirecOverlap: host element not found");this.el=e,this.opts={...Ye(e),...s},this.listeners=new Map;for(let o of Ze){let n=this.opts["on"+o[0].toUpperCase()+o.slice(1)];typeof n=="function"&&this.on(o,n)}this.rec=null,this.state=null,this.words=[],this.wordSource=null,this.fading=[],this.cur=null,this.activeId=null,this.idleTimer=0,this.raf=0,this.destroyed=!1,this._build(),e.__millirecOverlap=this,this.ready=this._boot()}static create(t,s={}){let e=new u(t,s);return e.ready.then(()=>e)}on(t,s){return this.listeners.has(t)||this.listeners.set(t,new Set),this.listeners.get(t).add(s),()=>this.listeners.get(t).delete(s)}_emit(t,s){s={...s,widget:this};for(let e of this.listeners.get(t)||[])try{e(s)}catch(o){console.error(o)}this.el.dispatchEvent(new CustomEvent("millirec-overlap:"+t,{detail:s,bubbles:!0}))}_build(){let t=this.opts,s=Number(t.size)||240;this.size=s;let e=this.el.attachShadow?this.el.shadowRoot||this.el.attachShadow({mode:"open"}):this.el;this.root=e,this.el.setAttribute("data-theme",t.theme||"auto"),e.innerHTML="";let o=document.createElement("style");o.textContent=Xe,e.appendChild(o);let n=document.createElement("div");n.className="mo"+(t.layout==="row"?" row":""),n.setAttribute("part","root");let i=new Set(rt(t.hide||""));this.box=document.createElement("canvas"),this.box.className="box busy",this.box.setAttribute("part","box");let l=window.devicePixelRatio||1;this.dpr=l,this.box.width=s*l,this.box.height=s*l,this.box.style.width=this.box.style.height=s+"px",this.ctx=this.box.getContext("2d"),this.ctx.scale(l,l),n.appendChild(this.box);let c=document.createElement("div");c.className="side",this.textEl=document.createElement("div"),this.textEl.className="text",this.textEl.setAttribute("part","text"),this.textEl.hidden=i.has("text"),this.hwEl=document.createElement("div"),this.hwEl.className="hw",this.hwEl.setAttribute("part","handwriting"),this.hwEl.hidden=i.has("handwriting"),this.wordsEl=document.createElement("div"),this.wordsEl.className="words",this.wordsEl.setAttribute("part","words"),this.wordsEl.hidden=i.has("words"),this.barEl=document.createElement("div"),this.barEl.className="bar",this.barEl.setAttribute("part","buttons"),this.barEl.hidden=i.has("buttons"),this.barEl.innerHTML='<button class="primary" data-act="done" title="finish this word">done</button><button data-act="undo" title="undo the last stroke">undo</button><button data-act="clear" title="clear the box">clear</button>',this.errEl=document.createElement("div"),this.errEl.className="err",this.errEl.hidden=!0;for(let p of[this.textEl,this.hwEl,this.wordsEl,this.barEl,this.errEl])c.appendChild(p);n.appendChild(c),e.appendChild(n),this.wrap=n,this._bindPointer(),this.barEl.addEventListener("click",p=>{let m=p.target&&p.target.dataset&&p.target.dataset.act;m==="done"?this.finishWord():m==="undo"?this.undo():m==="clear"&&this.clearWord()}),this.wordsEl.addEventListener("click",p=>{let m=p.target.closest?p.target.closest(".chip"):null;m&&m.dataset.word&&this.selectWord(m.dataset.word)}),this._renderText()}_engineOpts(){return{sizeRef0:this.size*.55,...this.opts.engine||{}}}get alphabet(){return et(this.opts.alphabet||this.opts.set||"capitals")}async _boot(){try{let t=yt(this.opts),s=this.alphabet,[{matcher:e},o]=await Promise.all([Et(t,s),le(this.opts)]);if(this.destroyed)return;this.words=o.words,this.wordSource=o,this.lexicon=st(this.words,{alphabet:s}),this.rec=new ot({matcher:e,lexicon:this.lexicon,opts:this._engineOpts()}),this.state=this.rec.last,this.box.classList.remove("busy"),this._render(),this._emit("ready",{words:this.lexicon.size,source:o.source,list:o.list||null,alphabet:s.join(""),set:it(s),free:this.lexicon.size===0})}catch(t){throw this.errEl.textContent=String(t.message||t),this.errEl.hidden=!1,this._emit("error",{error:t}),t}}_bindPointer(){let t=this.box,s=this.size,e=n=>{let i=t.getBoundingClientRect();return{x:(n.clientX-i.left)*s/i.width,y:(n.clientY-i.top)*s/i.height}};t.addEventListener("pointerdown",n=>{if(!(n.button>0||!this.rec)&&!(this.activeId!==null&&n.pointerType!=="pen"&&this.activeId!==n.pointerId)){n.preventDefault(),this.activeId=n.pointerId;try{t.setPointerCapture(n.pointerId)}catch{}clearTimeout(this.idleTimer),this.cur=[e(n)],this.curT0=performance.now(),this._repaint()}},{passive:!1}),t.addEventListener("pointermove",n=>{if(this.activeId!==n.pointerId||!this.cur)return;n.preventDefault();let i=n.getCoalescedEvents?n.getCoalescedEvents():null;for(let l of i&&i.length?i:[n])this.cur.push(e(l));this._repaint()},{passive:!1});let o=n=>{if(this.activeId!==n.pointerId)return;try{t.releasePointerCapture(n.pointerId)}catch{}if(this.activeId=null,!this.cur)return;let i=this.cur;if(this.cur=null,i.length===1){let l=i[0];i=[{x:l.x-1,y:l.y},{x:l.x+1,y:l.y}]}this._apply(this.rec.addStroke(i,{t0:this.curT0,t1:performance.now()}),"stroke"),this._armIdle()};t.addEventListener("pointerup",o),t.addEventListener("pointercancel",o);for(let n of["touchstart","touchmove"])t.addEventListener(n,i=>i.preventDefault(),{passive:!1});t.addEventListener("contextmenu",n=>n.preventDefault())}_armIdle(){clearTimeout(this.idleTimer);let t=Number(this.opts.idleFinish)||0;!t||!this.rec||!this.rec.strokes.length||(this.idleTimer=setTimeout(()=>{this.rec&&this.rec.strokes.length&&this.finishWord()},t*1e3))}getText(){return this.rec?this.rec.words.map(t=>t.word).join(" "):""}getLiveText(){let t=this.getText(),s=this.state?this.state.text:"";return s?t?t+" "+s:s:t}getWords(){return this.rec?this.rec.words.map(ue):[]}getCandidates(){return this.state?this.state.candidates.map(he):[]}getState(){return this.state}getWordList(){return this.words.slice()}getHandwriting({scope:t="word",index:s=-1,capHeight:e=44}={}){if(!this.rec)return null;if(t==="word"&&s<0)return X(this._currentGroups(),e,this._colors());if(t==="word"){let i=this.rec.words[s];return i?X(i.groups,e,this._colors()):null}let o=this.rec.words.map(i=>i.groups),n=this._currentGroups();return n.length&&o.push(n),pe(o,e,this._colors())}setWords(t){return this.words=Array.isArray(t)?t.slice():rt(t),this.wordSource={source:"words"},this.lexicon=st(this.words,{alphabet:this.alphabet}),this.rec&&this._apply(this.rec.setLexicon(this.lexicon),"change"),this.lexicon.size}async loadList(t){let s=await le({...this.opts,list:t,words:void 0});return this.words=s.words,this.wordSource=s,this.lexicon=st(this.words,{alphabet:this.alphabet}),this.rec&&this._apply(this.rec.setLexicon(this.lexicon),"change"),this.lexicon.size}getLexiconSize(){return this.lexicon?this.lexicon.size:0}async setAlphabet(t){t&&F[t]?(this.opts.set=t,delete this.opts.alphabet):(this.opts.alphabet=t,delete this.opts.set);let s=this.alphabet,{matcher:e}=await Et(yt(this.opts),s);if(!this.destroyed)return this.lexicon=st(this.words,{alphabet:s}),this.rec=new ot({matcher:e,lexicon:this.lexicon,opts:this._engineOpts()}),this.fading=[],this.state=this.rec.last,this._render(),this._emit("change",this._detail(this.state)),this._pushTarget(),s.join("")}finishWord(t=null){this.rec&&this._apply(this.rec.finishWord({word:t}),"word")}selectWord(t,{finish:s=!0}={}){if(!this.rec)return;let e=this.rec.selectWord(t,{finish:s});this._emit("select",{word:String(t).toUpperCase(),finish:s}),this._apply(e,s?"word":"change")}undo(){this.rec&&this._apply(this.rec.undo(),"change")}clearWord(){this.rec&&(this.fading=[],this._apply(this.rec.clearWord(),"change"))}clear(){this.rec&&(this.fading=[],this._apply(this.rec.reset(),"change"))}setOptions(t){this.rec&&this._apply(this.rec.setOpts(t),"change")}destroy(){this.destroyed=!0,clearTimeout(this.idleTimer),cancelAnimationFrame(this.raf),this.root.innerHTML="",delete this.el.__millirecOverlap}_apply(t,s){this.state=t,t.commit&&t.commit.erased&&t.commit.erased.length&&this.fading.push({strokes:t.commit.erased,t0:performance.now()}),this._render();let e=this._detail(t);s==="stroke"&&this._emit("stroke",e),t.finished&&this._emit("word",{...e,...ue(t.finished),canvas:X(t.finished.groups,44,this._colors())}),this._emit("change",e),this._pushTarget()}_detail(t){return{text:this.getText(),live:this.getLiveText(),current:t.text,committed:t.committed,pending:t.pending,candidates:t.candidates.map(he),strokes:t.n,erased:t.commit?t.commit.erased.length:0,canvas:this.hwCanvas||null}}_pushTarget(){let t=this.opts.target;if(!t)return;let s=typeof t=="string"?document.querySelector(t):t;if(!s)return;let e=this.opts.targetMode==="words"?this.getText():this.getLiveText();"value"in s&&/^(INPUT|TEXTAREA)$/.test(s.tagName)?(s.value=e,s.dispatchEvent(new Event("input",{bubbles:!0}))):s.textContent=e}_colors(){let t=getComputedStyle(this.el),s=(n,i)=>(t.getPropertyValue(n)||"").trim()||i,e=this.wrap?getComputedStyle(this.wrap):t,o=(n,i)=>(e.getPropertyValue(n)||"").trim()||i;return{ink:o("--_ink",s("--mo-ink","#111827")),grey:o("--_grey","#b6b6bb"),accent:o("--_accent","#2563eb"),muted:o("--_muted","#9ca3af")}}_currentGroups(){let t=this.state;return t?(t.groups||[]).map(s=>({ch:s.ch,strokes:s.strokes,state:"done"})).concat((t.assignment||[]).map(s=>({ch:s.ch,strokes:s.strokes,state:s.open?"open":"closed"}))):[]}_render(){this._repaint(),this._renderText(),this._renderHandwriting(),this._renderWords()}_renderText(){let t=this.state,s=this.getText();if(!t||!s&&!t.text){let e={capitals:"a capital letter",lowercase:"a lowercase letter",digits:"a digit",punctuation:"a punctuation mark",all:"a character"}[it(this.alphabet)]||"a character";this.textEl.innerHTML=`<span class="ph">${wt(this.opts.placeholder||`write ${e}, then the next one over it`)}</span>`;return}this.textEl.innerHTML=(s?`<span class="done">${wt(s)}</span> `:"")+`<span class="cur">${wt(t.committed)}</span><span class="pend">${wt(t.pending)}</span>`}_renderHandwriting(){let t=this.hwEl;if(t.innerHTML="",!this.rec)return;let s=this._colors(),e=Math.max(0,Number(this.opts.history??1)),o=this.rec.words.slice(-e);for(let i of o){let l=X(i.groups,34,s);l.className="prev",l.title=i.word,t.appendChild(l)}let n=this._currentGroups();this.hwCanvas=n.length?X(n,44,s):null,this.hwCanvas&&t.appendChild(this.hwCanvas)}_renderWords(){let t=this.wordsEl;if(t.innerHTML="",!this.state)return;let s=Math.max(0,Number(this.opts.chips??6));this.state.candidates.slice(0,s).forEach((e,o)=>{let n=document.createElement("button");n.type="button",n.className="chip"+(o===0?" best":"")+(e.kind==="done"?" complete":"")+(e.kind==="oov"?" oov":"")+(e.kind==="free"?" free":""),n.dataset.word=e.word,n.textContent=e.word,n.title=e.kind==="done"?"a complete word \u2014 tap to accept it":e.kind==="oov"?"not in the word list":e.kind==="free"?"the reading so far \u2014 tap to accept it":"tap to accept this word",n.setAttribute("part","chip"),t.appendChild(n)})}_repaint(){let t=this.ctx,s=this.size;t.clearRect(0,0,s,s);let e=this._colors(),o=performance.now();this.fading=this.fading.filter(i=>o-i.t0<500);for(let i of this.fading){let l=1-(o-i.t0)/500;for(let c of i.strokes)St(t,c.pts,e.grey,3,.9*l)}let n=new Set;for(let i of this.state&&this.state.assignment||[])if(!i.open)for(let l of i.ids)n.add(l);for(let i of this.rec?this.rec.strokes:[])St(t,i.pts,n.has(i.id)?e.grey:e.ink,3,1);this.cur&&St(t,this.cur,e.ink,3,1),cancelAnimationFrame(this.raf),this.fading.length&&(this.raf=requestAnimationFrame(()=>this._repaint()))}},wt=u=>String(u).replace(/[&<>]/g,t=>({"&":"&","<":"<",">":">"})[t]),he=u=>({word:u.word,score:u.score,complete:u.kind==="done",inList:u.kind!=="oov"}),ue=u=>({word:u.word,letters:u.groups.map(t=>({ch:t.ch,strokes:t.strokes})),inList:!!u.inList,selected:!!u.selected,alternatives:(u.alternatives||[]).map(t=>({word:t.text,score:t.score,inList:t.inList}))});function Ye(u){let t={},s={"millirec-overlap":null,set:"set",alphabet:"alphabet",list:"list",words:"words","words-src":"wordsSrc",target:"target","target-mode":"targetMode",size:"size",layout:"layout",chips:"chips",history:"history","idle-finish":"idleFinish",theme:"theme",hide:"hide",placeholder:"placeholder","asset-base":"assetBase","api-base":"apiBase"};for(let[n,i]of Object.entries(s)){let l=u.getAttribute("data-"+n);l==null||!i||(t[i]=l)}let e=u.getAttribute("data-engine");if(e)try{t.engine=JSON.parse(e)}catch{console.warn("MillirecOverlap: data-engine is not JSON")}let o=u.getAttribute("data-millirec-overlap");return o&&!t.list&&!t.words&&(t.list=o),t}function St(u,t,s,e,o){if(!(!t||t.length<2)){u.globalAlpha=o,u.strokeStyle=s,u.lineWidth=e,u.lineCap="round",u.lineJoin="round",u.beginPath(),u.moveTo(t[0].x,t[0].y);for(let n=1;n<t.length;n++)u.lineTo(t[n].x,t[n].y);u.stroke(),u.globalAlpha=1}}function Qe(u){let t=1/0,s=1/0,e=-1/0,o=-1/0;for(let n of u)for(let i of n)i.x<t&&(t=i.x),i.y<s&&(s=i.y),i.x>e&&(e=i.x),i.y>o&&(o=i.y);return t===1/0?null:{x0:t,y0:s,w:Math.max(1,e-t),h:Math.max(1,o-s)}}function X(u,t=44,s={},{gap:e=8,pad:o=6,dpr:n=window.devicePixelRatio||1}={}){let i=s.ink||"#111827",l=u.map(S=>Qe(S.strokes||[])),c=l.filter(Boolean).map(S=>S.h).sort((S,b)=>S-b),p=c.length?c[Math.floor(c.length/2)]:1,m=t/p,f=l.map(S=>S?S.w*m:t*.35),g=f.reduce((S,b)=>S+b,0)+e*Math.max(0,u.length-1)+2*o,M=Math.max(t,...l.filter(Boolean).map(S=>S.h*m))+2*o,L=document.createElement("canvas");L.width=Math.ceil(g*n),L.height=Math.ceil(M*n),L.style.width=Math.ceil(g)+"px",L.style.height=Math.ceil(M)+"px";let v=L.getContext("2d");v.scale(n,n),v.lineWidth=Math.max(1.6,t/18),v.lineCap=v.lineJoin="round";let O=o;return u.forEach((S,b)=>{let E=l[b];if(E){let _=M-o-E.h*m;v.strokeStyle=S.state==="open"&&s.openInk||i;for(let k of S.strokes)v.beginPath(),k.forEach((P,T)=>{let R=O+(P.x-E.x0)*m,z=_+(P.y-E.y0)*m;T?v.lineTo(R,z):v.moveTo(R,z)}),v.stroke()}O+=f[b]+e}),L}function pe(u,t=44,s={}){let e=u.map(f=>X(f,t,s)),o=window.devicePixelRatio||1,n=t*.6,i=e.reduce((f,g)=>f+g.width/o,0)+n*Math.max(0,e.length-1),l=Math.max(1,...e.map(f=>f.height/o)),c=document.createElement("canvas");c.width=Math.ceil(i*o),c.height=Math.ceil(l*o),c.style.width=Math.ceil(i)+"px",c.style.height=Math.ceil(l)+"px";let p=c.getContext("2d"),m=0;for(let f of e)p.drawImage(f,m*o,l*o-f.height),m+=f.width/o+n;return c}function fe(u=document){let t=u.querySelectorAll?u.querySelectorAll("[data-millirec-overlap]"):[],s=[];for(let e of t)e.__millirecOverlap||s.push(new at(e));return s}var me={version:Je,create:(u,t)=>at.create(u,t),scan:fe,Widget:at,buildLexicon:st,splitWords:rt,wordStrip:X,sentenceStrip:pe,alphabetOf:et,setNameOf:it,DEFAULTS:At,LETTERS:ne,SETS:F,SET_NAMES:kt,preload:(u="capitals",t)=>Et(t||yt({}),u)};if(typeof window<"u"&&!window.MillirecOverlap){window.MillirecOverlap=me;let u=()=>{try{fe(document)}catch(t){console.error(t)}};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",u):u()}var ys=me;})();
|
|
Binary file
|