From cc98aba1e592063c51bf844950db92afc06a1efd Mon Sep 17 00:00:00 2001 From: Anthony <62391911+ajwood1965@users.noreply.github.com> Date: Tue, 26 Mar 2024 09:18:14 -0500 Subject: [PATCH] rename api executeC to callC --- azure/examples/balls/async.html | 4 +- azure/examples/balls/dist/async.html | 2 +- azure/examples/balls/dist/index.528b9ee5.js | 2 +- .../examples/balls/dist/index.528b9ee5.js.map | 2 +- azure/examples/balls/dist/index.html | 2 +- .../balls/dist/twrmodworker.2165e649.js | 2 +- .../balls/dist/twrmodworker.2165e649.js.map | 2 +- azure/examples/balls/index.html | 4 +- azure/examples/fft/dist/index.html | 2 +- .../fft/dist/twrmodworker.2165e649.js | 2 +- .../fft/dist/twrmodworker.2165e649.js.map | 2 +- azure/examples/fft/fft-script.js | 8 +-- azure/examples/fft/fft-script.ts | 8 +-- azure/examples/function-calls/async.html | 8 +-- azure/examples/function-calls/dist/async.html | 2 +- .../function-calls/dist/index.528b9ee5.js | 2 +- .../function-calls/dist/index.528b9ee5.js.map | 2 +- azure/examples/function-calls/dist/index.html | 2 +- .../dist/twrmodworker.2165e649.js | 2 +- .../dist/twrmodworker.2165e649.js.map | 2 +- azure/examples/function-calls/index.html | 8 +-- azure/examples/helloworld/dist/index.html | 2 +- .../helloworld/dist/twrmodworker.2165e649.js | 2 +- .../dist/twrmodworker.2165e649.js.map | 2 +- azure/examples/helloworld/index.html | 2 +- azure/examples/maze/dist/index.html | 2 +- .../maze/dist/twrmodworker.2165e649.js | 2 +- .../maze/dist/twrmodworker.2165e649.js.map | 2 +- azure/examples/maze/maze-script.js | 6 +-- azure/examples/maze/maze-script.ts | 6 +-- azure/examples/stdio-canvas/dist/index.html | 2 +- .../dist/twrmodworker.2165e649.js | 2 +- .../dist/twrmodworker.2165e649.js.map | 2 +- azure/examples/stdio-canvas/index.html | 4 +- azure/examples/stdio-div/dist/index.html | 2 +- .../stdio-div/dist/twrmodworker.2165e649.js | 2 +- .../dist/twrmodworker.2165e649.js.map | 2 +- azure/examples/stdio-div/index.html | 2 +- azure/examples/tests/dist/index.html | 2 +- .../tests/dist/twrmodworker.2165e649.js | 2 +- .../tests/dist/twrmodworker.2165e649.js.map | 2 +- azure/examples/tests/index.html | 4 +- azure/lib-js/twrmodasync.d.ts | 8 +-- azure/lib-js/twrmodasync.js | 34 ++++++------ azure/lib-js/twrmodbase.d.ts | 4 +- azure/lib-js/twrmodbase.js | 22 ++++---- azure/lib-js/twrmodworker.js | 10 ++-- .../twr-wasm-ts/twr-wasm-ts/twrmodasync.ts | 34 ++++++------ .../twr-wasm-ts/twr-wasm-ts/twrmodbase.ts | 22 ++++---- .../twr-wasm-ts/twr-wasm-ts/twrmodworker.ts | 10 ++-- examples/balls/async.html | 4 +- examples/balls/index.html | 4 +- examples/fft/fft-script.ts | 8 +-- examples/function-calls/async.html | 8 +-- examples/function-calls/index.html | 8 +-- examples/helloworld/index.html | 2 +- examples/maze/maze-script.ts | 6 +-- examples/stdio-canvas/index.html | 4 +- examples/stdio-div/index.html | 2 +- examples/tests/index.html | 4 +- lib-js/twrcanvas.js | 2 +- lib-js/twrcanvas.js.map | 2 +- lib-js/twrmodasync.d.ts | 8 +-- lib-js/twrmodasync.d.ts.map | 2 +- lib-js/twrmodasync.js | 34 ++++++------ lib-js/twrmodasync.js.map | 2 +- lib-js/twrmodbase.d.ts | 4 +- lib-js/twrmodbase.d.ts.map | 2 +- lib-js/twrmodbase.js | 22 ++++---- lib-js/twrmodbase.js.map | 2 +- lib-js/twrmodworker.js | 10 ++-- lib-js/twrmodworker.js.map | 2 +- notes-to-self.txt | 6 +-- readme.md | 52 ++++++++++--------- source/twr-wasm-ts/twrmodasync.ts | 34 ++++++------ source/twr-wasm-ts/twrmodbase.ts | 22 ++++---- source/twr-wasm-ts/twrmodworker.ts | 10 ++-- 77 files changed, 267 insertions(+), 267 deletions(-) diff --git a/azure/examples/balls/async.html b/azure/examples/balls/async.html index 112a732b..cba68c73 100644 --- a/azure/examples/balls/async.html +++ b/azure/examples/balls/async.html @@ -64,7 +64,7 @@

tiny-wasm-runtime

const mod=new twrWasmModuleAsync(); await mod.loadWasm('balls-a.wasm'); - await mod.executeC(["bounce_balls_init", ballSpeed]); + await mod.callC(["bounce_balls_init", ballSpeed]); let lastTime; @@ -75,7 +75,7 @@

tiny-wasm-runtime

else intervalTimeMs=timeStamp-lastTime; lastTime=timeStamp; - mod.executeC(["bounce_balls_move", intervalTimeMs]).then(()=>{ + mod.callC(["bounce_balls_move", intervalTimeMs]).then(()=>{ window.requestAnimationFrame(moveBalls); }); } diff --git a/azure/examples/balls/dist/async.html b/azure/examples/balls/dist/async.html index 7469231c..42742955 100644 --- a/azure/examples/balls/dist/async.html +++ b/azure/examples/balls/dist/async.html @@ -5,4 +5,4 @@ "whatkey": "../../lib-js/whatkey.js" } } -

Bouncing Balls

tiny-wasm-runtime


\ No newline at end of file +

Bouncing Balls

tiny-wasm-runtime


\ No newline at end of file diff --git a/azure/examples/balls/dist/index.528b9ee5.js b/azure/examples/balls/dist/index.528b9ee5.js index 9e933366..b6682d4b 100644 --- a/azure/examples/balls/dist/index.528b9ee5.js +++ b/azure/examples/balls/dist/index.528b9ee5.js @@ -1,2 +1,2 @@ -function e(e,t,r,i){Object.defineProperty(e,t,{get:r,set:i,enumerable:!0,configurable:!0})}var t=globalThis,r={},i={},s=t.parcelRequire94c2;null==s&&((s=function(e){if(e in r)return r[e].exports;if(e in i){var t=i[e];delete i[e];var s={id:e,exports:{}};return r[e]=s,t.call(s.exports,s,s.exports),s.exports}var o=Error("Cannot find module '"+e+"'");throw o.code="MODULE_NOT_FOUND",o}).register=function(e,t){i[e]=t},t.parcelRequire94c2=s);var o=s.register;o("eZoLj",function(t,r){e(t.exports,"register",()=>i,e=>i=e);var i,s=new Map;i=function(e,t){for(var r=0;rs("3bkoq").twrWasmModule),e(t.exports,"twrWasmModuleAsync",()=>s("baOio").twrWasmModuleAsync),s("3bkoq"),s("baOio")}),o("3bkoq",function(t,r){e(t.exports,"twrWasmModule",()=>a);var i=s("9FI45"),o=s("aGUWE"),n=s("lsUl2");class a extends o.twrWasmModuleInJSMain{malloc;constructor(e={}){let t;super(e,!0),this.malloc=e=>{throw Error("error - un-init malloc called")},t=this.d2dcanvas.isValid()?this.d2dcanvas:this.iocanvas,this.modParams.imports={twrDebugLog:i.twrDebugLogImpl,twrTime:n.twrTimeImpl,twrDivCharOut:this.iodiv.charOut.bind(this.iodiv),twrCanvasGetProp:t.getProp.bind(t),twrCanvasDrawSeq:t.drawSeq.bind(t),twrCanvasCharIn:this.null,twrCanvasInkey:this.null,twrDivCharIn:this.null,twrSleep:this.null,twrSin:Math.sin,twrCos:Math.cos,twrTan:Math.tan,twrFAbs:Math.abs,twrACos:Math.acos,twrASin:Math.asin,twrATan:Math.atan,twrExp:Math.exp,twrFloor:Math.floor,twrCeil:Math.ceil,twrFMod:function(e,t){return e%t},twrLog:Math.log,twrPow:Math.pow,twrSqrt:Math.sqrt,twrTrunc:Math.trunc,twrDtoa:this.floatUtil.dtoa.bind(this.floatUtil),twrToFixed:this.floatUtil.toFixed.bind(this.floatUtil),twrToExponential:this.floatUtil.toExponential.bind(this.floatUtil),twrAtod:this.floatUtil.atod.bind(this.floatUtil),twrFcvtS:this.floatUtil.fcvtS.bind(this.floatUtil)}}null(e){throw Error("call to unimplemented twrXXX import in twrWasmModule. Use twrWasmModuleAsync ?")}}}),o("9FI45",function(t,r){e(t.exports,"twrDebugLogImpl",()=>s);let i="";function s(e){10==e||3==e?(console.log(i),i=""):(i+=String.fromCharCode(e)).length>=200&&(console.log(i),i="")}}),o("aGUWE",function(t,r){e(t.exports,"twrWasmModuleInJSMain",()=>a);var i=s("fDEU7"),o=s("5hO33"),n=s("5LsZ0");class a extends o.twrWasmModuleBase{iocanvas;d2dcanvas;iodiv;modParams;constructor(e={},t=!1){if(super(t),"undefined"==typeof document)throw Error("twrWasmModuleJSMain should only be created in JavaScript Main.");let r=document.getElementById("twr_iodiv"),s=document.getElementById("twr_iocanvas"),o=document.getElementById("twr_d2dcanvas");if(s&&o)throw Error("Both twr_iocanvas and twr_d2dcanvas defined. Currently only one canvas allowed.");if("div"==e.stdio&&!r)throw Error("twrWasmModuleBase opts=='div' but twr_iodiv not defined");if("canvas"==e.stdio&&!s)throw Error("twrWasmModuleBase, opts=='canvas' but twr_iocanvas not defined");if(e.isd2dcanvas&&!o)throw Error("twrWasmModuleBase, opts.isdrawcanvas==true but twr_d2dcanvas not defined");e=r?{stdio:"div",...e}:s?{stdio:"canvas",...e}:{stdio:"debug",...e},r||s?console.log("tiny-wasm-runtime: stdio set to: ",e.stdio):console.log("Since neither twr_iocanvas nor twr_iodiv is defined, stdout directed to debug console."),(e=s?{windim:[64,16],...e}:{windim:[0,0],...e}).imports||(e.imports={});let a=!1;e.backcolor||(a=!0,e.backcolor="black"),e.forecolor||(a=!0,e.forecolor="white"),e.fontsize||(a=!0,e.fontsize=16),void 0===e.isd2dcanvas&&(o?e.isd2dcanvas=!0:e.isd2dcanvas=!1),this.modParams={stdio:e.stdio,windim:e.windim,imports:e.imports,forecolor:e.forecolor,backcolor:e.backcolor,styleIsDefault:a,fontsize:e.fontsize,isd2dcanvas:e.isd2dcanvas},this.iodiv=new i.twrDiv(r,this.modParams,this),this.iocanvas=new n.twrCanvas(s,this.modParams,this),this.d2dcanvas=new n.twrCanvas(o,this.modParams,this)}divLog(...e){for(var t=0;to);var i=s("ghrAp");class o{div;divKeys;CURSOR=String.fromCharCode(9611);cursorOn=!1;lastChar=0;extraBR=!1;owner;constructor(e,t,r){this.div=e,this.owner=r,this.owner.isWasmModule||(this.divKeys=new i.twrSharedCircularBuffer),this.div&&!t.styleIsDefault&&(this.div.style.backgroundColor=t.backcolor,this.div.style.color=t.forecolor,this.div.style.font=t.fontsize.toString()+"px arial")}isValid(){return!!this.div}getProxyParams(){if(!this.divKeys)throw Error("internal error in getProxyParams.");return[this.divKeys.sharedArray]}charOut(e){if(this.div){switch(this.extraBR&&(this.extraBR=!1,this.cursorOn&&(this.div.innerHTML=this.div.innerHTML.slice(0,-1)),this.div.innerHTML=this.div.innerHTML.slice(0,-4),this.cursorOn&&(this.div.innerHTML+=this.CURSOR)),e){case 10:case 13:if(10==e&&13==this.lastChar)break;this.cursorOn&&(this.div.innerHTML=this.div.innerHTML.slice(0,-1)),this.div.innerHTML+="

",this.extraBR=!0,this.cursorOn&&(this.div.innerHTML+=this.CURSOR);let t=this.div.getBoundingClientRect();window.scrollTo(0,t.height+100);break;case 8:this.cursorOn&&(this.div.innerHTML=this.div.innerHTML.slice(0,-1)),this.div.innerHTML=this.div.innerHTML.slice(0,-1),this.cursorOn&&(this.div.innerHTML+=this.CURSOR);break;case 14:this.cursorOn||(this.cursorOn=!0,this.div.innerHTML+=this.CURSOR,this.div.focus());break;case 15:this.cursorOn&&(this.cursorOn=!1,this.div.innerHTML=this.div.innerHTML.slice(0,-1));break;default:this.cursorOn&&(this.div.innerHTML=this.div.innerHTML.slice(0,-1)),this.div.innerHTML+=String.fromCharCode(e),this.cursorOn&&(this.div.innerHTML+=this.CURSOR)}this.lastChar=e}}stringOut(e){for(let t=0;ti);class i{sharedArray;buf;constructor(e){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSharedCircularBuffer constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");e?this.sharedArray=e:this.sharedArray=new SharedArrayBuffer(1032),this.buf=new Int32Array(this.sharedArray),this.buf[256]=0,this.buf[257]=0}write(e){let t=this.buf[257];this.buf[t]=e,256==++t&&(t=0),this.buf[257]=t,Atomics.notify(this.buf,257)}read(){if(this.isEmpty())return -1;{let e=this.buf[256],t=this.buf[e];return e++,this.buf[256]=e,t}}readWait(){if(this.isEmpty()){let e=this.buf[256];Atomics.wait(this.buf,257,e)}return this.read()}isEmpty(){return this.buf[256]==this.buf[257]}}}),o("5hO33",function(t,r){e(t.exports,"twrWasmModuleBase",()=>o);var i=s("2Xdsi");class o{memory;mem8;mem32;memD;exports;isWorker=!1;isWasmModule;floatUtil;constructor(e=!1){this.isWasmModule=e,this.mem8=new Uint8Array,this.mem32=new Uint32Array,this.memD=new Float64Array,this.floatUtil=new i.twrFloatUtil(this)}async loadWasm(e){let t;try{t=await fetch(e)}catch(t){throw console.log("loadWasm() failed to fetch: "+e),t}if(!t.ok)throw Error("fetch response error on file '"+e+"'\n"+t.statusText);try{let e=await t.arrayBuffer(),r={...this.modParams.imports},i=await WebAssembly.instantiate(e,{env:r});if(this.exports=i.instance.exports,!this.exports)throw Error("Unexpected error - undefined instance.exports");if(this.memory)throw Error("unexpected error -- this.memory already set");if(this.memory=this.exports.memory,!this.memory)throw Error("Unexpected error - undefined exports.memory");this.mem8=new Uint8Array(this.memory.buffer),this.mem32=new Uint32Array(this.memory.buffer),this.memD=new Float64Array(this.memory.buffer),this.isWorker&&(this.memory.buffer instanceof ArrayBuffer&&console.log("twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)"),postMessage(["setmemory",this.memory])),!this.isWasmModule||this.memory.buffer instanceof ArrayBuffer||console.log("twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features"),this.malloc=e=>new Promise(t=>{let r=this.exports.twr_malloc;t(r(e))}),this.init()}catch(e){throw console.log("WASM instantiate error: "+e+(e.stack?"\n"+e.stack:"")),e}}init(){let e;switch(this.modParams.stdio){case"debug":default:e=0;break;case"div":e=1;break;case"canvas":e=2;break;case"null":e=3}(0,this.exports.twr_wasm_init)(e,this.mem8.length)}async executeC(e){let t=await this.preCallC(e),r=this.executeCImpl(e[0],t);return this.postCallC(t,e),r}async executeCImpl(e,t=[]){if(!this.exports)throw Error("this.exports undefined");if(!this.exports[e])throw Error("executeC: function '"+e+"' not in export table. Use --export wasm-ld flag.");return(0,this.exports[e])(...t)}async preCallC(e){if(e.constructor!==Array)throw Error("executeC: params must be array, first arg is function name");if(0==e.length)throw Error("executeC: missing function name");let t=[],r=0;for(let i=1;i=this.mem32.length)throw Error("invalid index passed to getLong: "+e+", this.mem32.length: "+this.mem32.length);return this.mem32[t]}setLong(e,t){let r=Math.floor(e/4);if(4*r!=e)throw Error("setLong passed non long aligned address");if(r<0||r>=this.mem32.length)throw Error("invalid index passed to setLong: "+e+", this.mem32.length: "+this.mem32.length);this.mem32[r]=t}getDouble(e){let t=Math.floor(e/8);if(8*t!=e)throw Error("getLong passed non Float64 aligned address");return this.memD[t]}setDouble(e,t){let r=Math.floor(e/8);if(8*r!=e)throw Error("setDouble passed non Float64 aligned address");this.memD[r]=t}getShort(e){if(e<0||e>=this.mem8.length)throw Error("invalid index passed to getShort: "+e);return this.mem8[e]+256*this.mem8[e+1]}getString(e,t){let r="",i=0;for(;this.mem8[e+i]&&(void 0===t||i=this.mem8.length)throw Error("invalid index passed to getU8: "+e);let t=new Uint32Array(this.mem8.slice(e,e+8).buffer),r=t[0],i=t[1];if(i<0||i>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU8");if(r<0||r>this.mem8.length-i)throw Error("invalid idx.size passed to getU8");return this.mem8.slice(i,i+r)}getU32Arr(e){if(e<0||e>=this.mem8.length)throw Error("invalid index passed to getU32: "+e);let t=new Uint32Array(this.mem8.slice(e,e+8).buffer),r=t[0],i=t[1];if(i<0||i>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU32");if(r<0||r>this.mem8.length-i)throw Error("invalid idx.size passed to getU32");if(r%4!=0)throw Error("idx.size is not an integer number of 32 bit words");return new Uint32Array(this.mem8.slice(i,i+r).buffer)}}}),o("2Xdsi",function(t,r){e(t.exports,"twrFloatUtil",()=>i);class i{mod;constructor(e){this.mod=e}atod(e){let t=this.mod.getString(e),r=t.trimStart().toUpperCase();return"INF"==r||"+INF"==r?Number.POSITIVE_INFINITY:"-INF"==r?Number.NEGATIVE_INFINITY:Number.parseFloat(t.replaceAll("D","e").replaceAll("d","e"))}dtoa(e,t,r,i){if(-1==i){let i=r.toString();this.mod.copyString(e,t,i)}else{let s=r.toString();s.length>i&&(s=r.toPrecision(i)),this.mod.copyString(e,t,s)}}toFixed(e,t,r,i){let s=r.toFixed(i);this.mod.copyString(e,t,s)}toExponential(e,t,r,i){let s=r.toExponential(i);this.mod.copyString(e,t,s)}fcvtS(e,t,r,i,s,o){let n,a;if(0==e||0==o||0==s||t<1)return 1;let l=0;if(Number.isNaN(r))n="1#QNAN00000000000000000000000000000".slice(0,i+1),a=1;else if(Number.isFinite(r)){if(0==r)n="000000000000000000000000000000000000".slice(0,i),a=0;else{if(r<0&&(l=1,r=Math.abs(r)),i>100||r>1e21||r<1e-99)return this.mod.copyString(e,t,""),this.mod.mem32[s]=0,1;let[o="",h=""]=r.toFixed(i).split(".");"0"==o&&(o=""),o.length>0?(a=o.length,n=o+h):a=(n=h.replace(/^0+/,"")).length-h.length}}else n="1#INF00000000000000000000000000000".slice(0,i+1),a=1;return t-1l);var i,o,n=s("ghrAp"),a=s("47Wdp");(i=o||(o={}))[i.D2D_FILLRECT=1]="D2D_FILLRECT",i[i.D2D_FILLCHAR=5]="D2D_FILLCHAR",i[i.D2D_SETLINEWIDTH=10]="D2D_SETLINEWIDTH",i[i.D2D_SETFILLSTYLERGBA=11]="D2D_SETFILLSTYLERGBA",i[i.D2D_SETFONT=12]="D2D_SETFONT",i[i.D2D_BEGINPATH=13]="D2D_BEGINPATH",i[i.D2D_MOVETO=14]="D2D_MOVETO",i[i.D2D_LINETO=15]="D2D_LINETO",i[i.D2D_FILL=16]="D2D_FILL",i[i.D2D_STROKE=17]="D2D_STROKE",i[i.D2D_SETSTROKESTYLERGBA=18]="D2D_SETSTROKESTYLERGBA",i[i.D2D_ARC=19]="D2D_ARC",i[i.D2D_STROKERECT=20]="D2D_STROKERECT",i[i.D2D_FILLTEXT=21]="D2D_FILLTEXT",i[i.D2D_IMAGEDATA=22]="D2D_IMAGEDATA",i[i.D2D_PUTIMAGEDATA=23]="D2D_PUTIMAGEDATA",i[i.D2D_BEZIERTO=24]="D2D_BEZIERTO",i[i.D2D_MEASURETEXT=25]="D2D_MEASURETEXT",i[i.D2D_SAVE=26]="D2D_SAVE",i[i.D2D_RESTORE=27]="D2D_RESTORE",i[i.D2D_CREATERADIALGRADIENT=28]="D2D_CREATERADIALGRADIENT",i[i.D2D_SETCOLORSTOP=29]="D2D_SETCOLORSTOP",i[i.D2D_SETFILLSTYLEGRADIENT=30]="D2D_SETFILLSTYLEGRADIENT",i[i.D2D_RELEASEID=31]="D2D_RELEASEID",i[i.D2D_CREATELINEARGRADIENT=32]="D2D_CREATELINEARGRADIENT",i[i.D2D_SETFILLSTYLE=33]="D2D_SETFILLSTYLE",i[i.D2D_SETSTROKESTYLE=34]="D2D_SETSTROKESTYLE";class l{ctx;props={charWidth:0,charHeight:0,foreColor:0,backColor:0,widthInChars:0,heightInChars:0,canvasHeight:0,canvasWidth:0};owner;cmdCompleteSignal;canvasKeys;precomputedObjects;constructor(e,t,r){let{forecolor:i,backcolor:s,fontsize:o,isd2dcanvas:l}=t;if(this.owner=r,this.props.widthInChars=t.windim[0],this.props.heightInChars=t.windim[1],this.owner.isWasmModule||(this.cmdCompleteSignal=new a.twrSignal,this.canvasKeys=new n.twrSharedCircularBuffer),this.precomputedObjects={},e){if(!e.getContext)throw Error("attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement");let t=e.getContext("2d");if(!t)throw Error("canvas 2D context not found in twrCanvasConstructor");t.font=o.toString()+"px Courier New",t.textBaseline="top";let r=" ",n=t.measureText(r);this.props.charWidth=Math.ceil(n.width/r.length);let a=t.measureText("X");this.props.charHeight=Math.ceil(a.fontBoundingBoxAscent+a.fontBoundingBoxDescent),l||(e.width=this.props.charWidth*this.props.widthInChars,e.height=this.props.charHeight*this.props.heightInChars),this.props.canvasHeight=e.height,this.props.canvasWidth=e.width;let h=e.getContext("2d");if(!h)throw Error("canvas 2D context not found in twrCanvas.constructor (2nd time)");this.ctx=h,this.ctx.font=o.toString()+"px Courier New",this.ctx.textBaseline="top",h.fillStyle=s,this.props.backColor=Number("0x"+h.fillStyle.slice(1)),h.fillStyle=i,this.props.foreColor=Number("0x"+h.fillStyle.slice(1))}}isValid(){return!!this.ctx}getProxyParams(){if(!this.cmdCompleteSignal||!this.canvasKeys)throw Error("internal error in getProxyParams.");return[this.props,this.cmdCompleteSignal.sharedArray,this.canvasKeys.sharedArray]}getProp(e){this.isValid()||console.log("internal error - getProp called on invalid twrCanvas");let t=this.owner.getString(e);return this.props[t]}drawSeq(e){let t;if(this.isValid()||console.log("internal error - drawSeq called on invalid twrCanvas"),!this.ctx)return;let r=this.owner.getLong(e),i=this.owner.getLong(e+4);for(;;){let e=this.owner.getLong(r+4);switch(e){case o.D2D_FILLRECT:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16),i=this.owner.getDouble(r+24),s=this.owner.getDouble(r+32);this.ctx.fillRect(e,t,i,s)}break;case o.D2D_STROKERECT:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16),i=this.owner.getDouble(r+24),s=this.owner.getDouble(r+32);this.ctx.strokeRect(e,t,i,s)}break;case o.D2D_FILLCHAR:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16),i=String.fromCharCode(this.owner.getShort(r+24));this.ctx.fillText(i,e,t)}break;case o.D2D_FILLTEXT:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16),i=this.owner.getString(this.owner.getLong(r+24));this.ctx.fillText(i,e,t)}break;case o.D2D_MEASURETEXT:{let e=this.owner.getString(this.owner.getLong(r+8)),t=this.owner.getLong(r+12),i=this.ctx.measureText(e);this.owner.setDouble(t+0,i.actualBoundingBoxAscent),this.owner.setDouble(t+8,i.actualBoundingBoxDescent),this.owner.setDouble(t+16,i.actualBoundingBoxLeft),this.owner.setDouble(t+24,i.actualBoundingBoxRight),this.owner.setDouble(t+32,i.fontBoundingBoxAscent),this.owner.setDouble(t+40,i.fontBoundingBoxDescent),this.owner.setDouble(t+48,i.width)}break;case o.D2D_SETFONT:{let e=this.owner.getString(this.owner.getLong(r+8));this.ctx.font=e}break;case o.D2D_SETFILLSTYLERGBA:{let e="#"+("00000000"+this.owner.getLong(r+8).toString(16)).slice(-8);this.ctx.fillStyle=e}break;case o.D2D_SETSTROKESTYLERGBA:{let e="#"+("00000000"+this.owner.getLong(r+8).toString(16)).slice(-8);this.ctx.strokeStyle=e}break;case o.D2D_SETFILLSTYLE:{let e=this.owner.getString(this.owner.getLong(r+8));this.ctx.fillStyle=e}break;case o.D2D_SETSTROKESTYLE:{let e=this.owner.getString(this.owner.getLong(r+8));this.ctx.strokeStyle=e}break;case o.D2D_SETLINEWIDTH:{let e=this.owner.getShort(r+8);this.ctx.lineWidth=e}break;case o.D2D_MOVETO:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16);this.ctx.moveTo(e,t)}break;case o.D2D_LINETO:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16);this.ctx.lineTo(e,t)}break;case o.D2D_BEZIERTO:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16),i=this.owner.getDouble(r+24),s=this.owner.getDouble(r+32),o=this.owner.getDouble(r+40),n=this.owner.getDouble(r+48);this.ctx.bezierCurveTo(e,t,i,s,o,n)}break;case o.D2D_BEGINPATH:this.ctx.beginPath();break;case o.D2D_FILL:this.ctx.fill();break;case o.D2D_SAVE:this.ctx.save();break;case o.D2D_RESTORE:this.ctx.restore();break;case o.D2D_STROKE:this.ctx.stroke();break;case o.D2D_ARC:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16),i=this.owner.getDouble(r+24),s=this.owner.getDouble(r+32),o=this.owner.getDouble(r+40),n=0!=this.owner.getLong(r+48);this.ctx.arc(e,t,i,s,o,n)}break;case o.D2D_IMAGEDATA:{let e=this.owner.getLong(r+8),t=this.owner.getLong(r+12),i=this.owner.getLong(r+16),s=this.owner.getLong(r+20),o=this.owner.getLong(r+24);if(o in this.precomputedObjects&&console.log("warning: D2D_IMAGEDATA ID already exists."),this.owner.isWasmModule){let r=new Uint8ClampedArray(this.owner.memory.buffer,e,t);this.precomputedObjects[o]=new ImageData(r,i,s)}else this.precomputedObjects[o]={mem8:new Uint8Array(this.owner.memory.buffer,e,t),width:i,height:s}}break;case o.D2D_CREATERADIALGRADIENT:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16),i=this.owner.getDouble(r+24),s=this.owner.getDouble(r+32),o=this.owner.getDouble(r+40),n=this.owner.getDouble(r+48),a=this.owner.getLong(r+56),l=this.ctx.createRadialGradient(e,t,i,s,o,n);a in this.precomputedObjects&&console.log("warning: D2D_CREATERADIALGRADIENT ID already exists."),this.precomputedObjects[a]=l}break;case o.D2D_CREATELINEARGRADIENT:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16),i=this.owner.getDouble(r+24),s=this.owner.getDouble(r+32),o=this.owner.getLong(r+40),n=this.ctx.createLinearGradient(e,t,i,s);o in this.precomputedObjects&&console.log("warning: D2D_CREATELINEARGRADIENT ID already exists."),this.precomputedObjects[o]=n}break;case o.D2D_SETCOLORSTOP:{let e=this.owner.getLong(r+8),t=this.owner.getLong(r+12),i=this.owner.getString(this.owner.getLong(r+16));if(!(e in this.precomputedObjects))throw Error("D2D_SETCOLORSTOP with invalid ID: "+e);this.precomputedObjects[e].addColorStop(t,i)}break;case o.D2D_SETFILLSTYLEGRADIENT:{let e=this.owner.getLong(r+8);if(!(e in this.precomputedObjects))throw Error("D2D_SETFILLSTYLEGRADIENT with invalid ID: "+e);let t=this.precomputedObjects[e];this.ctx.fillStyle=t}break;case o.D2D_RELEASEID:{let e=this.owner.getLong(r+8);this.precomputedObjects[e]?delete this.precomputedObjects[e]:console.log("warning: D2D_RELEASEID with undefined ID ",e)}break;case o.D2D_PUTIMAGEDATA:{let e;let t=this.owner.getLong(r+8),i=this.owner.getLong(r+12),s=this.owner.getLong(r+16),o=this.owner.getLong(r+20),n=this.owner.getLong(r+24),a=this.owner.getLong(r+28),l=this.owner.getLong(r+32);if(!(t in this.precomputedObjects))throw Error("D2D_PUTIMAGEDATA with invalid ID: "+t);if(this.owner.isWasmModule)e=this.precomputedObjects[t];else{let r=this.precomputedObjects[t];e=new ImageData(Uint8ClampedArray.from(r.mem8),r.width,r.height)}0==a&&0==l?this.ctx.putImageData(e,i,s):this.ctx.putImageData(e,i,s,o,n,a,l)}break;default:throw Error("unimplemented or unknown Sequence Type in drawSeq: "+e)}if(0==(t=this.owner.getLong(r))){if(r!=i)throw Error("assert type error in twrcanvas, ins!=lastins");break}r=t}this.cmdCompleteSignal&&this.cmdCompleteSignal.signal()}}}),o("47Wdp",function(t,r){var i,s;e(t.exports,"twrSignal",()=>o),(s=i||(i={}))[s.WAITING=0]="WAITING",s[s.SIGNALED=1]="SIGNALED";class o{sharedArray;buf;constructor(e){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSignal constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");e?this.sharedArray=e:this.sharedArray=new SharedArrayBuffer(4),this.buf=new Int32Array(this.sharedArray),this.buf[0]=i.WAITING}signal(){this.buf[0]=i.SIGNALED,Atomics.notify(this.buf,0)}wait(){this.buf[0]==i.WAITING&&Atomics.wait(this.buf,0,i.WAITING)}isSignaled(){return this.buf[0]==i.SIGNALED}reset(){this.buf[0]=i.WAITING}}}),o("lsUl2",function(t,r){e(t.exports,"twrTimeImpl",()=>i);function i(){return Date.now()}}),o("baOio",function(t,r){e(t.exports,"twrWasmModuleAsync",()=>l);var i=s("9FI45"),o=s("aGUWE"),n=s("2vKdq"),a=s("bqeaG");class l extends o.twrWasmModuleInJSMain{myWorker;malloc;loadWasmResolve;loadWasmReject;executeCResolve;executeCReject;initLW=!1;waitingcalls;constructor(e){if(super(e),this.malloc=e=>{throw Error("Error - un-init malloc called.")},!window.Worker)throw Error("This browser doesn't support web workers.");this.myWorker=new Worker(s("aRHnW")),this.myWorker.onmessage=this.processMsg.bind(this)}async loadWasm(e){if(this.initLW)throw Error("twrWasmAsyncModule::loadWasm can only be called once per twrWasmAsyncModule instance");return this.initLW=!0,new Promise((t,r)=>{let i;this.loadWasmResolve=t,this.loadWasmReject=r,this.malloc=e=>this.executeCImpl("twr_malloc",[e]),this.waitingcalls=new n.twrWaitingCalls,i=this.d2dcanvas.isValid()?this.d2dcanvas:this.iocanvas;let s={divProxyParams:this.iodiv.getProxyParams(),canvasProxyParams:i.getProxyParams(),waitingCallsProxyParams:this.waitingcalls.getProxyParams()},o={urlToLoad:new URL(e,document.URL).href,modWorkerParams:s,modParams:this.modParams};this.myWorker.postMessage(["startup",o])})}async executeC(e){let t=await this.preCallC(e);return this.executeCImpl(e[0],t)}async executeCImpl(e,t=[]){return new Promise((r,i)=>{this.executeCResolve=r,this.executeCReject=i,this.myWorker.postMessage(["executeC",e,t])})}keyDownDiv(e){if(!this.iodiv||!this.iodiv.divKeys)throw Error("unexpected undefined twrWasmAsyncModule.divKeys");this.iodiv.divKeys.write((0,a.default)(e).char.charCodeAt(0))}keyDownCanvas(e){if(!this.iocanvas||!this.iocanvas.canvasKeys)throw Error("unexpected undefined twrWasmAsyncModule.canvasKeys");this.iocanvas.canvasKeys.write((0,a.default)(e).char.charCodeAt(0))}processMsg(e){let t=e.data[0],r=e.data[1];switch(t){case"divout":this.iodiv.isValid()?this.iodiv.charOut(r):console.log("error - msg divout received but iodiv is undefined.");break;case"debug":(0,i.twrDebugLogImpl)(r);break;case"drawseq":{let[e]=r;if(this.iocanvas.isValid())this.iocanvas.drawSeq(e);else if(this.d2dcanvas.isValid())this.d2dcanvas.drawSeq(e);else throw Error("msg drawseq received but canvas is undefined.");break}case"setmemory":if(this.memory=r,!this.memory)throw Error("unexpected error - undefined memory in startupOkay msg");this.mem8=new Uint8Array(this.memory.buffer),this.mem32=new Uint32Array(this.memory.buffer),this.memD=new Float64Array(this.memory.buffer);break;case"startupFail":if(this.loadWasmReject)this.loadWasmReject(r);else throw Error("twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmReject)");break;case"startupOkay":if(this.loadWasmResolve)this.loadWasmResolve(void 0);else throw Error("twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmResolve)");break;case"executeCFail":if(this.executeCReject)this.executeCReject(r);else throw Error("twrWasmAsyncModule.processMsg unexpected error (undefined executeCReject)");break;case"executeCOkay":if(this.executeCResolve)this.executeCResolve(r);else throw Error("twrWasmAsyncModule.processMsg unexpected error (undefined executeCResolve)");break;default:if(!this.waitingcalls)throw Error("internal error: this.waitingcalls undefined.");if(!this.waitingcalls.processMessage(t,r))throw Error("twrWasmAsyncModule - unknown and unexpected msgType: "+t)}}}}),o("2vKdq",function(t,r){e(t.exports,"twrWaitingCalls",()=>n);var i=s("47Wdp"),o=s("lsUl2");class n{callCompleteSignal;parameters;constructor(){this.callCompleteSignal=new i.twrSignal,this.parameters=new Uint32Array(new SharedArrayBuffer(4))}startSleep(e){setTimeout(()=>{this.callCompleteSignal.signal()},e)}time(){let e=(0,o.twrTimeImpl)();this.parameters[0]=e,this.callCompleteSignal.signal()}getProxyParams(){return[this.callCompleteSignal.sharedArray,this.parameters.buffer]}processMessage(e,t){switch(e){case"sleep":let[r]=t;this.startSleep(r);break;case"time":this.time();break;default:return!1}return!0}}}),o("bqeaG",function(t,r){e(t.exports,"default",()=>m);let i={a:"selectAll",c:"copy",s:"save",v:"paste",x:"cut",y:"redo",z:"undo"},s={"/":"?",".":">",",":"<","'":'"',";":":","[":"{","]":"}","\\":"|","`":"~","=":"+","-":"_",1:"!",2:"@",3:"#",4:"$",5:"%",6:"^",7:"&",8:"*",9:"(",0:")",a:"A",b:"B",c:"C",d:"D",e:"E",f:"F",g:"G",h:"H",i:"I",j:"J",k:"K",l:"L",m:"M",n:"N",o:"O",p:"P",q:"q",r:"R",s:"S",t:"T",u:"U",v:"V",w:"W",x:"X",y:"Y",z:"Z"},o={};for(let e in s)o[s[e]]=e;let n={0:"\\",8:"backspace",9:"tab",12:"num",13:"enter",16:"shift",17:"ctrl",18:"alt",19:"pause",20:"caps",27:"esc",32:" ",33:"pageup",34:"pagedown",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",44:"print",45:"insert",46:"delete",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"a",66:"b",67:"c",68:"d",69:"e",70:"f",71:"g",72:"h",73:"i",74:"j",75:"k",76:"l",77:"m",78:"n",79:"o",80:"p",81:"q",82:"r",83:"s",84:"t",85:"u",86:"v",87:"w",88:"x",89:"y",90:"z",91:"meta",92:"meta",93:"meta",96:"num0",97:"num1",98:"num2",99:"num3",100:"num4",101:"num5",102:"num6",103:"num7",104:"num8",105:"num9",106:"*",107:"+",108:"num_enter",109:"num_subtract",110:"num_decimal",111:"num_divide",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12",124:"print",144:"num",145:"scroll",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'",223:"`",224:"cmd",225:"alt",57392:"ctrl",63289:"num"},a={"\r":"enter"},l=JSON.parse(JSON.stringify(n));for(let e of Object.keys(a))l[e]=a[e];let h={num_subtract:"-",num_enter:"\n",num_decimal:".",num_divide:"/",enter:"\n",tab:" ",backspace:"\b"},c=["keydown","keyup"],d=()=>{let e=navigator.userAgent;return 0!==(/IEMobile|Windows Phone|Lumia/i.test(e)?"w":/iPhone|iP[oa]d/.test(e)?"i":/Android/.test(e)?"a":/BlackBerry|PlayBook|BB10/.test(e)?"b":/Mobile Safari/.test(e)?"s":/webOS|Mobile|Tablet|Opera Mini|\bCrMo\/|Opera Mobi/i.test(e)?1:0)};function u(e){let t=String.fromCharCode(e);return d()?t:t in o?o[t]:t in l?l[t]:t}function m(e){let t;if("keypress"!==e.type||d()){if("keypress"===e.type&&d())t=u(e.keyCode);else{if(!(c.indexOf(e.type)>-1))return!1;t=void 0!==e.which?n[e.which]:void 0!==e.keyCode?n[e.keyCode]:"enter"}}else t=u(e.charCode);let r=t;return e.shiftKey&&t in s?r=s[t]:e.ctrlKey&&t in i?r=i[t]:t in h&&(r=h[t]),{char:r,key:t}}}),o("aRHnW",function(e,t){var r=s("hoqmg");let i=new URL("twrmodworker.2165e649.js",import.meta.url);e.exports=r(i.toString(),i.origin,!0)}),o("hoqmg",function(e,t){e.exports=function(e,t,r){if(t===self.location.origin)return e;var i=r?"import "+JSON.stringify(e)+";":"importScripts("+JSON.stringify(e)+");";return URL.createObjectURL(new Blob([i],{type:"application/javascript"}))}}),s("eZoLj").register(new URL("",import.meta.url).toString(),JSON.parse('["kjr0c","index.528b9ee5.js","cTHdP","twrmodworker.2165e649.js"]')); +function e(e,t,r,i){Object.defineProperty(e,t,{get:r,set:i,enumerable:!0,configurable:!0})}var t=globalThis,r={},i={},s=t.parcelRequire94c2;null==s&&((s=function(e){if(e in r)return r[e].exports;if(e in i){var t=i[e];delete i[e];var s={id:e,exports:{}};return r[e]=s,t.call(s.exports,s,s.exports),s.exports}var o=Error("Cannot find module '"+e+"'");throw o.code="MODULE_NOT_FOUND",o}).register=function(e,t){i[e]=t},t.parcelRequire94c2=s);var o=s.register;o("eZoLj",function(t,r){e(t.exports,"register",()=>i,e=>i=e);var i,s=new Map;i=function(e,t){for(var r=0;rs("3bkoq").twrWasmModule),e(t.exports,"twrWasmModuleAsync",()=>s("baOio").twrWasmModuleAsync),s("3bkoq"),s("baOio")}),o("3bkoq",function(t,r){e(t.exports,"twrWasmModule",()=>a);var i=s("9FI45"),o=s("aGUWE"),n=s("lsUl2");class a extends o.twrWasmModuleInJSMain{malloc;constructor(e={}){let t;super(e,!0),this.malloc=e=>{throw Error("error - un-init malloc called")},t=this.d2dcanvas.isValid()?this.d2dcanvas:this.iocanvas,this.modParams.imports={twrDebugLog:i.twrDebugLogImpl,twrTime:n.twrTimeImpl,twrDivCharOut:this.iodiv.charOut.bind(this.iodiv),twrCanvasGetProp:t.getProp.bind(t),twrCanvasDrawSeq:t.drawSeq.bind(t),twrCanvasCharIn:this.null,twrCanvasInkey:this.null,twrDivCharIn:this.null,twrSleep:this.null,twrSin:Math.sin,twrCos:Math.cos,twrTan:Math.tan,twrFAbs:Math.abs,twrACos:Math.acos,twrASin:Math.asin,twrATan:Math.atan,twrExp:Math.exp,twrFloor:Math.floor,twrCeil:Math.ceil,twrFMod:function(e,t){return e%t},twrLog:Math.log,twrPow:Math.pow,twrSqrt:Math.sqrt,twrTrunc:Math.trunc,twrDtoa:this.floatUtil.dtoa.bind(this.floatUtil),twrToFixed:this.floatUtil.toFixed.bind(this.floatUtil),twrToExponential:this.floatUtil.toExponential.bind(this.floatUtil),twrAtod:this.floatUtil.atod.bind(this.floatUtil),twrFcvtS:this.floatUtil.fcvtS.bind(this.floatUtil)}}null(e){throw Error("call to unimplemented twrXXX import in twrWasmModule. Use twrWasmModuleAsync ?")}}}),o("9FI45",function(t,r){e(t.exports,"twrDebugLogImpl",()=>s);let i="";function s(e){10==e||3==e?(console.log(i),i=""):(i+=String.fromCharCode(e)).length>=200&&(console.log(i),i="")}}),o("aGUWE",function(t,r){e(t.exports,"twrWasmModuleInJSMain",()=>a);var i=s("fDEU7"),o=s("5hO33"),n=s("5LsZ0");class a extends o.twrWasmModuleBase{iocanvas;d2dcanvas;iodiv;modParams;constructor(e={},t=!1){if(super(t),"undefined"==typeof document)throw Error("twrWasmModuleJSMain should only be created in JavaScript Main.");let r=document.getElementById("twr_iodiv"),s=document.getElementById("twr_iocanvas"),o=document.getElementById("twr_d2dcanvas");if(s&&o)throw Error("Both twr_iocanvas and twr_d2dcanvas defined. Currently only one canvas allowed.");if("div"==e.stdio&&!r)throw Error("twrWasmModuleBase opts=='div' but twr_iodiv not defined");if("canvas"==e.stdio&&!s)throw Error("twrWasmModuleBase, opts=='canvas' but twr_iocanvas not defined");if(e.isd2dcanvas&&!o)throw Error("twrWasmModuleBase, opts.isdrawcanvas==true but twr_d2dcanvas not defined");e=r?{stdio:"div",...e}:s?{stdio:"canvas",...e}:{stdio:"debug",...e},r||s?console.log("tiny-wasm-runtime: stdio set to: ",e.stdio):console.log("Since neither twr_iocanvas nor twr_iodiv is defined, stdout directed to debug console."),(e=s?{windim:[64,16],...e}:{windim:[0,0],...e}).imports||(e.imports={});let a=!1;e.backcolor||(a=!0,e.backcolor="black"),e.forecolor||(a=!0,e.forecolor="white"),e.fontsize||(a=!0,e.fontsize=16),void 0===e.isd2dcanvas&&(o?e.isd2dcanvas=!0:e.isd2dcanvas=!1),this.modParams={stdio:e.stdio,windim:e.windim,imports:e.imports,forecolor:e.forecolor,backcolor:e.backcolor,styleIsDefault:a,fontsize:e.fontsize,isd2dcanvas:e.isd2dcanvas},this.iodiv=new i.twrDiv(r,this.modParams,this),this.iocanvas=new n.twrCanvas(s,this.modParams,this),this.d2dcanvas=new n.twrCanvas(o,this.modParams,this)}divLog(...e){for(var t=0;to);var i=s("ghrAp");class o{div;divKeys;CURSOR=String.fromCharCode(9611);cursorOn=!1;lastChar=0;extraBR=!1;owner;constructor(e,t,r){this.div=e,this.owner=r,this.owner.isWasmModule||(this.divKeys=new i.twrSharedCircularBuffer),this.div&&!t.styleIsDefault&&(this.div.style.backgroundColor=t.backcolor,this.div.style.color=t.forecolor,this.div.style.font=t.fontsize.toString()+"px arial")}isValid(){return!!this.div}getProxyParams(){if(!this.divKeys)throw Error("internal error in getProxyParams.");return[this.divKeys.sharedArray]}charOut(e){if(this.div){switch(this.extraBR&&(this.extraBR=!1,this.cursorOn&&(this.div.innerHTML=this.div.innerHTML.slice(0,-1)),this.div.innerHTML=this.div.innerHTML.slice(0,-4),this.cursorOn&&(this.div.innerHTML+=this.CURSOR)),e){case 10:case 13:if(10==e&&13==this.lastChar)break;this.cursorOn&&(this.div.innerHTML=this.div.innerHTML.slice(0,-1)),this.div.innerHTML+="

",this.extraBR=!0,this.cursorOn&&(this.div.innerHTML+=this.CURSOR);let t=this.div.getBoundingClientRect();window.scrollTo(0,t.height+100);break;case 8:this.cursorOn&&(this.div.innerHTML=this.div.innerHTML.slice(0,-1)),this.div.innerHTML=this.div.innerHTML.slice(0,-1),this.cursorOn&&(this.div.innerHTML+=this.CURSOR);break;case 14:this.cursorOn||(this.cursorOn=!0,this.div.innerHTML+=this.CURSOR,this.div.focus());break;case 15:this.cursorOn&&(this.cursorOn=!1,this.div.innerHTML=this.div.innerHTML.slice(0,-1));break;default:this.cursorOn&&(this.div.innerHTML=this.div.innerHTML.slice(0,-1)),this.div.innerHTML+=String.fromCharCode(e),this.cursorOn&&(this.div.innerHTML+=this.CURSOR)}this.lastChar=e}}stringOut(e){for(let t=0;ti);class i{sharedArray;buf;constructor(e){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSharedCircularBuffer constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");e?this.sharedArray=e:this.sharedArray=new SharedArrayBuffer(1032),this.buf=new Int32Array(this.sharedArray),this.buf[256]=0,this.buf[257]=0}write(e){let t=this.buf[257];this.buf[t]=e,256==++t&&(t=0),this.buf[257]=t,Atomics.notify(this.buf,257)}read(){if(this.isEmpty())return -1;{let e=this.buf[256],t=this.buf[e];return e++,this.buf[256]=e,t}}readWait(){if(this.isEmpty()){let e=this.buf[256];Atomics.wait(this.buf,257,e)}return this.read()}isEmpty(){return this.buf[256]==this.buf[257]}}}),o("5hO33",function(t,r){e(t.exports,"twrWasmModuleBase",()=>o);var i=s("2Xdsi");class o{memory;mem8;mem32;memD;exports;isWorker=!1;isWasmModule;floatUtil;constructor(e=!1){this.isWasmModule=e,this.mem8=new Uint8Array,this.mem32=new Uint32Array,this.memD=new Float64Array,this.floatUtil=new i.twrFloatUtil(this)}async loadWasm(e){let t;try{t=await fetch(e)}catch(t){throw console.log("loadWasm() failed to fetch: "+e),t}if(!t.ok)throw Error("fetch response error on file '"+e+"'\n"+t.statusText);try{let e=await t.arrayBuffer(),r={...this.modParams.imports},i=await WebAssembly.instantiate(e,{env:r});if(this.exports=i.instance.exports,!this.exports)throw Error("Unexpected error - undefined instance.exports");if(this.memory)throw Error("unexpected error -- this.memory already set");if(this.memory=this.exports.memory,!this.memory)throw Error("Unexpected error - undefined exports.memory");this.mem8=new Uint8Array(this.memory.buffer),this.mem32=new Uint32Array(this.memory.buffer),this.memD=new Float64Array(this.memory.buffer),this.isWorker&&(this.memory.buffer instanceof ArrayBuffer&&console.log("twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)"),postMessage(["setmemory",this.memory])),!this.isWasmModule||this.memory.buffer instanceof ArrayBuffer||console.log("twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features"),this.malloc=e=>new Promise(t=>{let r=this.exports.twr_malloc;t(r(e))}),this.init()}catch(e){throw console.log("WASM instantiate error: "+e+(e.stack?"\n"+e.stack:"")),e}}init(){let e;switch(this.modParams.stdio){case"debug":default:e=0;break;case"div":e=1;break;case"canvas":e=2;break;case"null":e=3}(0,this.exports.twr_wasm_init)(e,this.mem8.length)}async callC(e){let t=await this.preCallC(e),r=this.callCImpl(e[0],t);return this.postCallC(t,e),r}async callCImpl(e,t=[]){if(!this.exports)throw Error("this.exports undefined");if(!this.exports[e])throw Error("callC: function '"+e+"' not in export table. Use --export wasm-ld flag.");return(0,this.exports[e])(...t)}async preCallC(e){if(e.constructor!==Array)throw Error("callC: params must be array, first arg is function name");if(0==e.length)throw Error("callC: missing function name");let t=[],r=0;for(let i=1;i=this.mem32.length)throw Error("invalid index passed to getLong: "+e+", this.mem32.length: "+this.mem32.length);return this.mem32[t]}setLong(e,t){let r=Math.floor(e/4);if(4*r!=e)throw Error("setLong passed non long aligned address");if(r<0||r>=this.mem32.length)throw Error("invalid index passed to setLong: "+e+", this.mem32.length: "+this.mem32.length);this.mem32[r]=t}getDouble(e){let t=Math.floor(e/8);if(8*t!=e)throw Error("getLong passed non Float64 aligned address");return this.memD[t]}setDouble(e,t){let r=Math.floor(e/8);if(8*r!=e)throw Error("setDouble passed non Float64 aligned address");this.memD[r]=t}getShort(e){if(e<0||e>=this.mem8.length)throw Error("invalid index passed to getShort: "+e);return this.mem8[e]+256*this.mem8[e+1]}getString(e,t){let r="",i=0;for(;this.mem8[e+i]&&(void 0===t||i=this.mem8.length)throw Error("invalid index passed to getU8: "+e);let t=new Uint32Array(this.mem8.slice(e,e+8).buffer),r=t[0],i=t[1];if(i<0||i>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU8");if(r<0||r>this.mem8.length-i)throw Error("invalid idx.size passed to getU8");return this.mem8.slice(i,i+r)}getU32Arr(e){if(e<0||e>=this.mem8.length)throw Error("invalid index passed to getU32: "+e);let t=new Uint32Array(this.mem8.slice(e,e+8).buffer),r=t[0],i=t[1];if(i<0||i>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU32");if(r<0||r>this.mem8.length-i)throw Error("invalid idx.size passed to getU32");if(r%4!=0)throw Error("idx.size is not an integer number of 32 bit words");return new Uint32Array(this.mem8.slice(i,i+r).buffer)}}}),o("2Xdsi",function(t,r){e(t.exports,"twrFloatUtil",()=>i);class i{mod;constructor(e){this.mod=e}atod(e){let t=this.mod.getString(e),r=t.trimStart().toUpperCase();return"INF"==r||"+INF"==r?Number.POSITIVE_INFINITY:"-INF"==r?Number.NEGATIVE_INFINITY:Number.parseFloat(t.replaceAll("D","e").replaceAll("d","e"))}dtoa(e,t,r,i){if(-1==i){let i=r.toString();this.mod.copyString(e,t,i)}else{let s=r.toString();s.length>i&&(s=r.toPrecision(i)),this.mod.copyString(e,t,s)}}toFixed(e,t,r,i){let s=r.toFixed(i);this.mod.copyString(e,t,s)}toExponential(e,t,r,i){let s=r.toExponential(i);this.mod.copyString(e,t,s)}fcvtS(e,t,r,i,s,o){let n,a;if(0==e||0==o||0==s||t<1)return 1;let l=0;if(Number.isNaN(r))n="1#QNAN00000000000000000000000000000".slice(0,i+1),a=1;else if(Number.isFinite(r)){if(0==r)n="000000000000000000000000000000000000".slice(0,i),a=0;else{if(r<0&&(l=1,r=Math.abs(r)),i>100||r>1e21||r<1e-99)return this.mod.copyString(e,t,""),this.mod.mem32[s]=0,1;let[o="",h=""]=r.toFixed(i).split(".");"0"==o&&(o=""),o.length>0?(a=o.length,n=o+h):a=(n=h.replace(/^0+/,"")).length-h.length}}else n="1#INF00000000000000000000000000000".slice(0,i+1),a=1;return t-1l);var i,o,n=s("ghrAp"),a=s("47Wdp");(i=o||(o={}))[i.D2D_FILLRECT=1]="D2D_FILLRECT",i[i.D2D_FILLCHAR=5]="D2D_FILLCHAR",i[i.D2D_SETLINEWIDTH=10]="D2D_SETLINEWIDTH",i[i.D2D_SETFILLSTYLERGBA=11]="D2D_SETFILLSTYLERGBA",i[i.D2D_SETFONT=12]="D2D_SETFONT",i[i.D2D_BEGINPATH=13]="D2D_BEGINPATH",i[i.D2D_MOVETO=14]="D2D_MOVETO",i[i.D2D_LINETO=15]="D2D_LINETO",i[i.D2D_FILL=16]="D2D_FILL",i[i.D2D_STROKE=17]="D2D_STROKE",i[i.D2D_SETSTROKESTYLERGBA=18]="D2D_SETSTROKESTYLERGBA",i[i.D2D_ARC=19]="D2D_ARC",i[i.D2D_STROKERECT=20]="D2D_STROKERECT",i[i.D2D_FILLTEXT=21]="D2D_FILLTEXT",i[i.D2D_IMAGEDATA=22]="D2D_IMAGEDATA",i[i.D2D_PUTIMAGEDATA=23]="D2D_PUTIMAGEDATA",i[i.D2D_BEZIERTO=24]="D2D_BEZIERTO",i[i.D2D_MEASURETEXT=25]="D2D_MEASURETEXT",i[i.D2D_SAVE=26]="D2D_SAVE",i[i.D2D_RESTORE=27]="D2D_RESTORE",i[i.D2D_CREATERADIALGRADIENT=28]="D2D_CREATERADIALGRADIENT",i[i.D2D_SETCOLORSTOP=29]="D2D_SETCOLORSTOP",i[i.D2D_SETFILLSTYLEGRADIENT=30]="D2D_SETFILLSTYLEGRADIENT",i[i.D2D_RELEASEID=31]="D2D_RELEASEID",i[i.D2D_CREATELINEARGRADIENT=32]="D2D_CREATELINEARGRADIENT",i[i.D2D_SETFILLSTYLE=33]="D2D_SETFILLSTYLE",i[i.D2D_SETSTROKESTYLE=34]="D2D_SETSTROKESTYLE";class l{ctx;props={charWidth:0,charHeight:0,foreColor:0,backColor:0,widthInChars:0,heightInChars:0,canvasHeight:0,canvasWidth:0};owner;cmdCompleteSignal;canvasKeys;precomputedObjects;constructor(e,t,r){let{forecolor:i,backcolor:s,fontsize:o,isd2dcanvas:l}=t;if(this.owner=r,this.props.widthInChars=t.windim[0],this.props.heightInChars=t.windim[1],this.owner.isWasmModule||(this.cmdCompleteSignal=new a.twrSignal,this.canvasKeys=new n.twrSharedCircularBuffer),this.precomputedObjects={},e){if(!e.getContext)throw Error("attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement");let t=e.getContext("2d");if(!t)throw Error("canvas 2D context not found in twrCanvasConstructor");t.font=o.toString()+"px Courier New",t.textBaseline="top";let r=" ",n=t.measureText(r);this.props.charWidth=Math.ceil(n.width/r.length);let a=t.measureText("X");this.props.charHeight=Math.ceil(a.fontBoundingBoxAscent+a.fontBoundingBoxDescent),l||(e.width=this.props.charWidth*this.props.widthInChars,e.height=this.props.charHeight*this.props.heightInChars),this.props.canvasHeight=e.height,this.props.canvasWidth=e.width;let h=e.getContext("2d");if(!h)throw Error("canvas 2D context not found in twrCanvas.constructor (2nd time)");this.ctx=h,this.ctx.font=o.toString()+"px Courier New",this.ctx.textBaseline="top",h.fillStyle=s,this.props.backColor=Number("0x"+h.fillStyle.slice(1)),h.fillStyle=i,this.props.foreColor=Number("0x"+h.fillStyle.slice(1))}}isValid(){return!!this.ctx}getProxyParams(){if(!this.cmdCompleteSignal||!this.canvasKeys)throw Error("internal error in getProxyParams.");return[this.props,this.cmdCompleteSignal.sharedArray,this.canvasKeys.sharedArray]}getProp(e){this.isValid()||console.log("internal error - getProp called on invalid twrCanvas");let t=this.owner.getString(e);return this.props[t]}drawSeq(e){let t;if(this.isValid()||console.log("internal error - drawSeq called on invalid twrCanvas"),!this.ctx)return;let r=this.owner.getLong(e),i=this.owner.getLong(e+4);for(;;){let e=this.owner.getLong(r+4);switch(e){case o.D2D_FILLRECT:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16),i=this.owner.getDouble(r+24),s=this.owner.getDouble(r+32);this.ctx.fillRect(e,t,i,s)}break;case o.D2D_STROKERECT:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16),i=this.owner.getDouble(r+24),s=this.owner.getDouble(r+32);this.ctx.strokeRect(e,t,i,s)}break;case o.D2D_FILLCHAR:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16),i=String.fromCharCode(this.owner.getShort(r+24));this.ctx.fillText(i,e,t)}break;case o.D2D_FILLTEXT:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16),i=this.owner.getString(this.owner.getLong(r+24));this.ctx.fillText(i,e,t)}break;case o.D2D_MEASURETEXT:{let e=this.owner.getString(this.owner.getLong(r+8)),t=this.owner.getLong(r+12),i=this.ctx.measureText(e);this.owner.setDouble(t+0,i.actualBoundingBoxAscent),this.owner.setDouble(t+8,i.actualBoundingBoxDescent),this.owner.setDouble(t+16,i.actualBoundingBoxLeft),this.owner.setDouble(t+24,i.actualBoundingBoxRight),this.owner.setDouble(t+32,i.fontBoundingBoxAscent),this.owner.setDouble(t+40,i.fontBoundingBoxDescent),this.owner.setDouble(t+48,i.width)}break;case o.D2D_SETFONT:{let e=this.owner.getString(this.owner.getLong(r+8));this.ctx.font=e}break;case o.D2D_SETFILLSTYLERGBA:{let e="#"+("00000000"+this.owner.getLong(r+8).toString(16)).slice(-8);this.ctx.fillStyle=e}break;case o.D2D_SETSTROKESTYLERGBA:{let e="#"+("00000000"+this.owner.getLong(r+8).toString(16)).slice(-8);this.ctx.strokeStyle=e}break;case o.D2D_SETFILLSTYLE:{let e=this.owner.getString(this.owner.getLong(r+8));this.ctx.fillStyle=e}break;case o.D2D_SETSTROKESTYLE:{let e=this.owner.getString(this.owner.getLong(r+8));this.ctx.strokeStyle=e}break;case o.D2D_SETLINEWIDTH:{let e=this.owner.getShort(r+8);this.ctx.lineWidth=e}break;case o.D2D_MOVETO:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16);this.ctx.moveTo(e,t)}break;case o.D2D_LINETO:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16);this.ctx.lineTo(e,t)}break;case o.D2D_BEZIERTO:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16),i=this.owner.getDouble(r+24),s=this.owner.getDouble(r+32),o=this.owner.getDouble(r+40),n=this.owner.getDouble(r+48);this.ctx.bezierCurveTo(e,t,i,s,o,n)}break;case o.D2D_BEGINPATH:this.ctx.beginPath();break;case o.D2D_FILL:this.ctx.fill();break;case o.D2D_SAVE:this.ctx.save();break;case o.D2D_RESTORE:this.ctx.restore();break;case o.D2D_STROKE:this.ctx.stroke();break;case o.D2D_ARC:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16),i=this.owner.getDouble(r+24),s=this.owner.getDouble(r+32),o=this.owner.getDouble(r+40),n=0!=this.owner.getLong(r+48);this.ctx.arc(e,t,i,s,o,n)}break;case o.D2D_IMAGEDATA:{let e=this.owner.getLong(r+8),t=this.owner.getLong(r+12),i=this.owner.getLong(r+16),s=this.owner.getLong(r+20),o=this.owner.getLong(r+24);if(o in this.precomputedObjects&&console.log("warning: D2D_IMAGEDATA ID already exists."),this.owner.isWasmModule){let r=new Uint8ClampedArray(this.owner.memory.buffer,e,t);this.precomputedObjects[o]=new ImageData(r,i,s)}else this.precomputedObjects[o]={mem8:new Uint8Array(this.owner.memory.buffer,e,t),width:i,height:s}}break;case o.D2D_CREATERADIALGRADIENT:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16),i=this.owner.getDouble(r+24),s=this.owner.getDouble(r+32),o=this.owner.getDouble(r+40),n=this.owner.getDouble(r+48),a=this.owner.getLong(r+56),l=this.ctx.createRadialGradient(e,t,i,s,o,n);a in this.precomputedObjects&&console.log("warning: D2D_CREATERADIALGRADIENT ID already exists."),this.precomputedObjects[a]=l}break;case o.D2D_CREATELINEARGRADIENT:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16),i=this.owner.getDouble(r+24),s=this.owner.getDouble(r+32),o=this.owner.getLong(r+40),n=this.ctx.createLinearGradient(e,t,i,s);o in this.precomputedObjects&&console.log("warning: D2D_CREATELINEARGRADIENT ID already exists."),this.precomputedObjects[o]=n}break;case o.D2D_SETCOLORSTOP:{let e=this.owner.getLong(r+8),t=this.owner.getLong(r+12),i=this.owner.getString(this.owner.getLong(r+16));if(!(e in this.precomputedObjects))throw Error("D2D_SETCOLORSTOP with invalid ID: "+e);this.precomputedObjects[e].addColorStop(t,i)}break;case o.D2D_SETFILLSTYLEGRADIENT:{let e=this.owner.getLong(r+8);if(!(e in this.precomputedObjects))throw Error("D2D_SETFILLSTYLEGRADIENT with invalid ID: "+e);let t=this.precomputedObjects[e];this.ctx.fillStyle=t}break;case o.D2D_RELEASEID:{let e=this.owner.getLong(r+8);this.precomputedObjects[e]?delete this.precomputedObjects[e]:console.log("warning: D2D_RELEASEID with undefined ID ",e)}break;case o.D2D_PUTIMAGEDATA:{let e;let t=this.owner.getLong(r+8),i=this.owner.getLong(r+12),s=this.owner.getLong(r+16),o=this.owner.getLong(r+20),n=this.owner.getLong(r+24),a=this.owner.getLong(r+28),l=this.owner.getLong(r+32);if(!(t in this.precomputedObjects))throw Error("D2D_PUTIMAGEDATA with invalid ID: "+t);if(this.owner.isWasmModule)e=this.precomputedObjects[t];else{let r=this.precomputedObjects[t];e=new ImageData(Uint8ClampedArray.from(r.mem8),r.width,r.height)}0==a&&0==l?this.ctx.putImageData(e,i,s):this.ctx.putImageData(e,i,s,o,n,a,l)}break;default:throw Error("unimplemented or unknown Sequence Type in drawSeq: "+e)}if(0==(t=this.owner.getLong(r))){if(r!=i)throw Error("assert type error in twrcanvas, ins!=lastins");break}r=t}this.cmdCompleteSignal&&this.cmdCompleteSignal.signal()}}}),o("47Wdp",function(t,r){var i,s;e(t.exports,"twrSignal",()=>o),(s=i||(i={}))[s.WAITING=0]="WAITING",s[s.SIGNALED=1]="SIGNALED";class o{sharedArray;buf;constructor(e){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSignal constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");e?this.sharedArray=e:this.sharedArray=new SharedArrayBuffer(4),this.buf=new Int32Array(this.sharedArray),this.buf[0]=i.WAITING}signal(){this.buf[0]=i.SIGNALED,Atomics.notify(this.buf,0)}wait(){this.buf[0]==i.WAITING&&Atomics.wait(this.buf,0,i.WAITING)}isSignaled(){return this.buf[0]==i.SIGNALED}reset(){this.buf[0]=i.WAITING}}}),o("lsUl2",function(t,r){e(t.exports,"twrTimeImpl",()=>i);function i(){return Date.now()}}),o("baOio",function(t,r){e(t.exports,"twrWasmModuleAsync",()=>l);var i=s("9FI45"),o=s("aGUWE"),n=s("2vKdq"),a=s("bqeaG");class l extends o.twrWasmModuleInJSMain{myWorker;malloc;loadWasmResolve;loadWasmReject;callCResolve;callCReject;initLW=!1;waitingcalls;constructor(e){if(super(e),this.malloc=e=>{throw Error("Error - un-init malloc called.")},!window.Worker)throw Error("This browser doesn't support web workers.");this.myWorker=new Worker(s("aRHnW")),this.myWorker.onmessage=this.processMsg.bind(this)}async loadWasm(e){if(this.initLW)throw Error("twrWasmAsyncModule::loadWasm can only be called once per twrWasmAsyncModule instance");return this.initLW=!0,new Promise((t,r)=>{let i;this.loadWasmResolve=t,this.loadWasmReject=r,this.malloc=e=>this.callCImpl("twr_malloc",[e]),this.waitingcalls=new n.twrWaitingCalls,i=this.d2dcanvas.isValid()?this.d2dcanvas:this.iocanvas;let s={divProxyParams:this.iodiv.getProxyParams(),canvasProxyParams:i.getProxyParams(),waitingCallsProxyParams:this.waitingcalls.getProxyParams()},o={urlToLoad:new URL(e,document.URL).href,modWorkerParams:s,modParams:this.modParams};this.myWorker.postMessage(["startup",o])})}async callC(e){let t=await this.preCallC(e);return this.callCImpl(e[0],t)}async callCImpl(e,t=[]){return new Promise((r,i)=>{this.callCResolve=r,this.callCReject=i,this.myWorker.postMessage(["callC",e,t])})}keyDownDiv(e){if(!this.iodiv||!this.iodiv.divKeys)throw Error("unexpected undefined twrWasmAsyncModule.divKeys");this.iodiv.divKeys.write((0,a.default)(e).char.charCodeAt(0))}keyDownCanvas(e){if(!this.iocanvas||!this.iocanvas.canvasKeys)throw Error("unexpected undefined twrWasmAsyncModule.canvasKeys");this.iocanvas.canvasKeys.write((0,a.default)(e).char.charCodeAt(0))}processMsg(e){let t=e.data[0],r=e.data[1];switch(t){case"divout":this.iodiv.isValid()?this.iodiv.charOut(r):console.log("error - msg divout received but iodiv is undefined.");break;case"debug":(0,i.twrDebugLogImpl)(r);break;case"drawseq":{let[e]=r;if(this.iocanvas.isValid())this.iocanvas.drawSeq(e);else if(this.d2dcanvas.isValid())this.d2dcanvas.drawSeq(e);else throw Error("msg drawseq received but canvas is undefined.");break}case"setmemory":if(this.memory=r,!this.memory)throw Error("unexpected error - undefined memory in startupOkay msg");this.mem8=new Uint8Array(this.memory.buffer),this.mem32=new Uint32Array(this.memory.buffer),this.memD=new Float64Array(this.memory.buffer);break;case"startupFail":if(this.loadWasmReject)this.loadWasmReject(r);else throw Error("twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmReject)");break;case"startupOkay":if(this.loadWasmResolve)this.loadWasmResolve(void 0);else throw Error("twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmResolve)");break;case"callCFail":if(this.callCReject)this.callCReject(r);else throw Error("twrWasmAsyncModule.processMsg unexpected error (undefined callCReject)");break;case"callCOkay":if(this.callCResolve)this.callCResolve(r);else throw Error("twrWasmAsyncModule.processMsg unexpected error (undefined callCResolve)");break;default:if(!this.waitingcalls)throw Error("internal error: this.waitingcalls undefined.");if(!this.waitingcalls.processMessage(t,r))throw Error("twrWasmAsyncModule - unknown and unexpected msgType: "+t)}}}}),o("2vKdq",function(t,r){e(t.exports,"twrWaitingCalls",()=>n);var i=s("47Wdp"),o=s("lsUl2");class n{callCompleteSignal;parameters;constructor(){this.callCompleteSignal=new i.twrSignal,this.parameters=new Uint32Array(new SharedArrayBuffer(4))}startSleep(e){setTimeout(()=>{this.callCompleteSignal.signal()},e)}time(){let e=(0,o.twrTimeImpl)();this.parameters[0]=e,this.callCompleteSignal.signal()}getProxyParams(){return[this.callCompleteSignal.sharedArray,this.parameters.buffer]}processMessage(e,t){switch(e){case"sleep":let[r]=t;this.startSleep(r);break;case"time":this.time();break;default:return!1}return!0}}}),o("bqeaG",function(t,r){e(t.exports,"default",()=>m);let i={a:"selectAll",c:"copy",s:"save",v:"paste",x:"cut",y:"redo",z:"undo"},s={"/":"?",".":">",",":"<","'":'"',";":":","[":"{","]":"}","\\":"|","`":"~","=":"+","-":"_",1:"!",2:"@",3:"#",4:"$",5:"%",6:"^",7:"&",8:"*",9:"(",0:")",a:"A",b:"B",c:"C",d:"D",e:"E",f:"F",g:"G",h:"H",i:"I",j:"J",k:"K",l:"L",m:"M",n:"N",o:"O",p:"P",q:"q",r:"R",s:"S",t:"T",u:"U",v:"V",w:"W",x:"X",y:"Y",z:"Z"},o={};for(let e in s)o[s[e]]=e;let n={0:"\\",8:"backspace",9:"tab",12:"num",13:"enter",16:"shift",17:"ctrl",18:"alt",19:"pause",20:"caps",27:"esc",32:" ",33:"pageup",34:"pagedown",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",44:"print",45:"insert",46:"delete",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"a",66:"b",67:"c",68:"d",69:"e",70:"f",71:"g",72:"h",73:"i",74:"j",75:"k",76:"l",77:"m",78:"n",79:"o",80:"p",81:"q",82:"r",83:"s",84:"t",85:"u",86:"v",87:"w",88:"x",89:"y",90:"z",91:"meta",92:"meta",93:"meta",96:"num0",97:"num1",98:"num2",99:"num3",100:"num4",101:"num5",102:"num6",103:"num7",104:"num8",105:"num9",106:"*",107:"+",108:"num_enter",109:"num_subtract",110:"num_decimal",111:"num_divide",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12",124:"print",144:"num",145:"scroll",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'",223:"`",224:"cmd",225:"alt",57392:"ctrl",63289:"num"},a={"\r":"enter"},l=JSON.parse(JSON.stringify(n));for(let e of Object.keys(a))l[e]=a[e];let h={num_subtract:"-",num_enter:"\n",num_decimal:".",num_divide:"/",enter:"\n",tab:" ",backspace:"\b"},c=["keydown","keyup"],d=()=>{let e=navigator.userAgent;return 0!==(/IEMobile|Windows Phone|Lumia/i.test(e)?"w":/iPhone|iP[oa]d/.test(e)?"i":/Android/.test(e)?"a":/BlackBerry|PlayBook|BB10/.test(e)?"b":/Mobile Safari/.test(e)?"s":/webOS|Mobile|Tablet|Opera Mini|\bCrMo\/|Opera Mobi/i.test(e)?1:0)};function u(e){let t=String.fromCharCode(e);return d()?t:t in o?o[t]:t in l?l[t]:t}function m(e){let t;if("keypress"!==e.type||d()){if("keypress"===e.type&&d())t=u(e.keyCode);else{if(!(c.indexOf(e.type)>-1))return!1;t=void 0!==e.which?n[e.which]:void 0!==e.keyCode?n[e.keyCode]:"enter"}}else t=u(e.charCode);let r=t;return e.shiftKey&&t in s?r=s[t]:e.ctrlKey&&t in i?r=i[t]:t in h&&(r=h[t]),{char:r,key:t}}}),o("aRHnW",function(e,t){var r=s("hoqmg");let i=new URL("twrmodworker.2165e649.js",import.meta.url);e.exports=r(i.toString(),i.origin,!0)}),o("hoqmg",function(e,t){e.exports=function(e,t,r){if(t===self.location.origin)return e;var i=r?"import "+JSON.stringify(e)+";":"importScripts("+JSON.stringify(e)+");";return URL.createObjectURL(new Blob([i],{type:"application/javascript"}))}}),s("eZoLj").register(new URL("",import.meta.url).toString(),JSON.parse('["kjr0c","index.528b9ee5.js","cTHdP","twrmodworker.2165e649.js"]')); //# sourceMappingURL=index.528b9ee5.js.map diff --git a/azure/examples/bal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I,AAAJ,EAGtB,CACL,KAAA,EACA,IAAA,CACF,CACF,C,G,E,Q,S,C,C,C,E,I,E,E,SCjRA,IAAI,EAAA,IAAA,IAA0B,4CAA9B,YAAA,GAAA,CACA,CAAA,EAAA,OAAA,CAAiB,EAAU,EAAI,QAAQ,GAAI,EAAI,MAAM,CAAE,CAAA,E,G,E,Q,S,C,C,C,ECAvD,EAAA,OAAA,CAAiB,SAAU,CAAS,CAAE,CAAM,CAAE,CAAK,EACjD,GAAI,IAAW,KAAK,QAAQ,CAAC,MAAM,CAGjC,OAAO,EAGP,IAAI,EAAS,EAAQ,UAAY,KAAK,SAAS,CAAC,GAAa,IAAM,iBAAmB,KAAK,SAAS,CAAC,GAAa,KAClH,OAAO,IAAI,eAAe,CAAC,IAAI,KAAK,CAAC,EAAO,CAAE,CAC5C,KAAM,wBACR,GAEJ,C,GCdA,AAAA,EAAA,SAAA,QAAA,CAA8C,IAAA,IAAoB,GAAA,YAAA,GAAA,EAAI,QAAQ,GAAG,KAAK,KAAK,CAAC","sources":["","../../../../Users/awood/AppData/Roaming/npm/node_modules/parcel/node_modules/@parcel/runtime-js/lib/helpers/bundle-manifest.js","../../source/twr-wasm-ts/index.ts","../../lib-js/twrmod.js","../../source/twr-wasm-ts/twrmod.ts","../../lib-js/twrdebug.js","../../source/twr-wasm-ts/twrdebug.ts","../../lib-js/twrmodjsmain.js","../../source/twr-wasm-ts/twrmodjsmain.ts","../../lib-js/twrdiv.js","../../source/twr-wasm-ts/twrdiv.ts","../../lib-js/twrcircular.js","../../source/twr-wasm-ts/twrcircular.ts","../../lib-js/twrmodbase.js","../../source/twr-wasm-ts/twrmodbase.ts","../../lib-js/twrfloat.js","../../source/twr-wasm-ts/twrfloat.ts","../../lib-js/twrcanvas.js","../../source/twr-wasm-ts/twrcanvas.ts","../../lib-js/twrsignal.js","../../source/twr-wasm-ts/twrsignal.ts","../../lib-js/twrdate.js","../../source/twr-wasm-ts/twrdate.ts","../../lib-js/twrmodasync.js","../../source/twr-wasm-ts/twrmodasync.ts","../../lib-js/twrwaitingcalls.js","../../source/twr-wasm-ts/twrwaitingcalls.ts","../../lib-js/whatkey.js","../../../../Users/awood/AppData/Roaming/npm/node_modules/parcel/node_modules/@parcel/runtime-js/lib/runtime-f762b97648513f2d.js","../../../../Users/awood/AppData/Roaming/npm/node_modules/parcel/node_modules/@parcel/runtime-js/lib/helpers/get-worker-url.js","../../../../Users/awood/AppData/Roaming/npm/node_modules/parcel/node_modules/@parcel/runtime-js/lib/runtime-8b48cd52cfa83e88.js"],"sourcesContent":["\nfunction $parcel$export(e, n, v, s) {\n Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});\n}\n\n var $parcel$global = globalThis;\n \nvar $parcel$modules = {};\nvar $parcel$inits = {};\n\nvar parcelRequire = $parcel$global[\"parcelRequire94c2\"];\n\nif (parcelRequire == null) {\n parcelRequire = function(id) {\n if (id in $parcel$modules) {\n return $parcel$modules[id].exports;\n }\n if (id in $parcel$inits) {\n var init = $parcel$inits[id];\n delete $parcel$inits[id];\n var module = {id: id, exports: {}};\n $parcel$modules[id] = module;\n init.call(module.exports, module, module.exports);\n return module.exports;\n }\n var err = new Error(\"Cannot find module '\" + id + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n };\n\n parcelRequire.register = function register(id, init) {\n $parcel$inits[id] = init;\n };\n\n $parcel$global[\"parcelRequire94c2\"] = parcelRequire;\n}\n\nvar parcelRegister = parcelRequire.register;\nparcelRegister(\"eZoLj\", function(module, exports) {\n\n$parcel$export(module.exports, \"register\", () => $ae99f86db55f9acd$export$6503ec6e8aabbaf, (v) => $ae99f86db55f9acd$export$6503ec6e8aabbaf = v);\nvar $ae99f86db55f9acd$export$6503ec6e8aabbaf;\nvar $ae99f86db55f9acd$export$f7ad0328861e2f03;\n\"use strict\";\nvar $ae99f86db55f9acd$var$mapping = new Map();\nfunction $ae99f86db55f9acd$var$register(baseUrl, manifest) {\n for(var i = 0; i < manifest.length - 1; i += 2)$ae99f86db55f9acd$var$mapping.set(manifest[i], {\n baseUrl: baseUrl,\n path: manifest[i + 1]\n });\n}\nfunction $ae99f86db55f9acd$var$resolve(id) {\n var resolved = $ae99f86db55f9acd$var$mapping.get(id);\n if (resolved == null) throw new Error(\"Could not resolve bundle with id \" + id);\n return new URL(resolved.path, resolved.baseUrl).toString();\n}\n$ae99f86db55f9acd$export$6503ec6e8aabbaf = $ae99f86db55f9acd$var$register;\n$ae99f86db55f9acd$export$f7ad0328861e2f03 = $ae99f86db55f9acd$var$resolve;\n\n});\n\nparcelRegister(\"4mNsm\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrWasmModule\", () => (parcelRequire(\"3bkoq\")).twrWasmModule);\n$parcel$export(module.exports, \"twrWasmModuleAsync\", () => (parcelRequire(\"baOio\")).twrWasmModuleAsync);\n\nvar $3bkoq = parcelRequire(\"3bkoq\");\n\nvar $baOio = parcelRequire(\"baOio\");\n\n});\nparcelRegister(\"3bkoq\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrWasmModule\", () => $251237c7cf144eb4$export$3298af74d75b595c);\n\nvar $9FI45 = parcelRequire(\"9FI45\");\n\nvar $aGUWE = parcelRequire(\"aGUWE\");\n\nvar $lsUl2 = parcelRequire(\"lsUl2\");\nclass $251237c7cf144eb4$export$3298af74d75b595c extends (0, $aGUWE.twrWasmModuleInJSMain) {\n malloc;\n constructor(opts = {}){\n super(opts, true);\n this.malloc = (size)=>{\n throw new Error(\"error - un-init malloc called\");\n };\n let canvas;\n if (this.d2dcanvas.isValid()) canvas = this.d2dcanvas;\n else canvas = this.iocanvas;\n this.modParams.imports = {\n twrDebugLog: (0, $9FI45.twrDebugLogImpl),\n twrTime: (0, $lsUl2.twrTimeImpl),\n twrDivCharOut: this.iodiv.charOut.bind(this.iodiv),\n twrCanvasGetProp: canvas.getProp.bind(canvas),\n twrCanvasDrawSeq: canvas.drawSeq.bind(canvas),\n twrCanvasCharIn: this.null,\n twrCanvasInkey: this.null,\n twrDivCharIn: this.null,\n twrSleep: this.null,\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function(x, y) {\n return x % y;\n },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n null(inval) {\n throw new Error(\"call to unimplemented twrXXX import in twrWasmModule. Use twrWasmModuleAsync ?\");\n }\n}\n\n});\nparcelRegister(\"9FI45\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrDebugLogImpl\", () => $70aa1fbe63deeaae$export$16b4216ec014493d);\nlet $70aa1fbe63deeaae$var$logline = \"\";\nfunction $70aa1fbe63deeaae$export$16b4216ec014493d(char) {\n if (char == 10 || char == 3) {\n console.log($70aa1fbe63deeaae$var$logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n $70aa1fbe63deeaae$var$logline = \"\";\n } else {\n $70aa1fbe63deeaae$var$logline = $70aa1fbe63deeaae$var$logline + String.fromCharCode(char);\n if ($70aa1fbe63deeaae$var$logline.length >= 200) {\n console.log($70aa1fbe63deeaae$var$logline);\n $70aa1fbe63deeaae$var$logline = \"\";\n }\n }\n}\nfunction $70aa1fbe63deeaae$export$485af4d0039b3389(ch) {\n postMessage([\n \"debug\",\n ch\n ]);\n}\n\n});\n\nparcelRegister(\"aGUWE\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrWasmModuleInJSMain\", () => $7c89ffbd74fdad5b$export$2366c14363f3adb5);\n// This class extends base to handle options when called in the main Java Script thread\n\nvar $fDEU7 = parcelRequire(\"fDEU7\");\n\nvar $5hO33 = parcelRequire(\"5hO33\");\n\nvar $5LsZ0 = parcelRequire(\"5LsZ0\");\nclass $7c89ffbd74fdad5b$export$2366c14363f3adb5 extends (0, $5hO33.twrWasmModuleBase) {\n iocanvas;\n d2dcanvas;\n iodiv;\n modParams;\n constructor(opts = {}, isWasmModule = false){\n super(isWasmModule);\n if (typeof document === \"undefined\") throw new Error(\"twrWasmModuleJSMain should only be created in JavaScript Main.\");\n const eiodiv = document.getElementById(\"twr_iodiv\");\n const eiocanvas = document.getElementById(\"twr_iocanvas\");\n const ed2dcanvas = document.getElementById(\"twr_d2dcanvas\");\n if (eiocanvas && ed2dcanvas) throw new Error(\"Both twr_iocanvas and twr_d2dcanvas defined. Currently only one canvas allowed.\");\n if (opts.stdio == \"div\" && !eiodiv) throw new Error(\"twrWasmModuleBase opts=='div' but twr_iodiv not defined\");\n if (opts.stdio == \"canvas\" && !eiocanvas) throw new Error(\"twrWasmModuleBase, opts=='canvas' but twr_iocanvas not defined\");\n if (opts.isd2dcanvas && !ed2dcanvas) throw new Error(\"twrWasmModuleBase, opts.isdrawcanvas==true but twr_d2dcanvas not defined\");\n // set default opts based on elements found\n if (eiodiv) opts = {\n stdio: \"div\",\n ...opts\n };\n else if (eiocanvas) opts = {\n stdio: \"canvas\",\n ...opts\n };\n else opts = {\n stdio: \"debug\",\n ...opts\n };\n if (!eiodiv && !eiocanvas) console.log(\"Since neither twr_iocanvas nor twr_iodiv is defined, stdout directed to debug console.\");\n else console.log(\"tiny-wasm-runtime: stdio set to: \", opts.stdio);\n if (eiocanvas) opts = {\n windim: [\n 64,\n 16\n ],\n ...opts\n };\n else opts = {\n windim: [\n 0,\n 0\n ],\n ...opts\n };\n if (!opts.imports) opts.imports = {};\n let styleIsDefault = false;\n if (!opts.backcolor) {\n styleIsDefault = true;\n opts.backcolor = \"black\";\n }\n if (!opts.forecolor) {\n styleIsDefault = true;\n opts.forecolor = \"white\";\n }\n if (!opts.fontsize) {\n styleIsDefault = true;\n opts.fontsize = 16;\n }\n if (opts.isd2dcanvas === undefined) {\n if (ed2dcanvas) opts.isd2dcanvas = true;\n else opts.isd2dcanvas = false;\n }\n this.modParams = {\n stdio: opts.stdio,\n windim: opts.windim,\n imports: opts.imports,\n forecolor: opts.forecolor,\n backcolor: opts.backcolor,\n styleIsDefault: styleIsDefault,\n fontsize: opts.fontsize,\n isd2dcanvas: opts.isd2dcanvas\n };\n this.iodiv = new (0, $fDEU7.twrDiv)(eiodiv, this.modParams, this);\n this.iocanvas = new (0, $5LsZ0.twrCanvas)(eiocanvas, this.modParams, this);\n this.d2dcanvas = new (0, $5LsZ0.twrCanvas)(ed2dcanvas, this.modParams, this);\n }\n divLog(...params) {\n for(var i = 0; i < params.length; i++){\n this.iodiv.stringOut(params[i].toString());\n this.iodiv.charOut(32); // space\n }\n this.iodiv.charOut(10);\n }\n}\n\n});\nparcelRegister(\"fDEU7\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrDiv\", () => $b62a3a4493ce3043$export$dd376bb3f10f6896);\n\nvar $ghrAp = parcelRequire(\"ghrAp\");\nclass $b62a3a4493ce3043$export$dd376bb3f10f6896 {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611);\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase){\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) this.divKeys = new (0, $ghrAp.twrSharedCircularBuffer)(); // tsconfig, lib must be set to 2017 or higher\n if (this.div && !modParams.styleIsDefault) {\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.divKeys.sharedArray\n ];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */ charOut(ch) {\n if (!this.div) return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n }\n switch(ch){\n case 10:\n case 13:\n if (ch == 10 && this.lastChar == 13) break; // detect CR LF and treat as single new line\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n case 0xE:\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF:\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for(let i = 0; i < str.length; i++)this.charOut(str.charCodeAt(i));\n }\n}\nclass $b62a3a4493ce3043$export$b377f0bbf2c7581e {\n divKeys;\n constructor(params){\n const [divKeysBuffer] = params;\n this.divKeys = new (0, $ghrAp.twrSharedCircularBuffer)(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n charOut(ch) {\n postMessage([\n \"divout\",\n ch\n ]);\n }\n}\n\n});\nparcelRegister(\"ghrAp\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrSharedCircularBuffer\", () => $bda3a1eb26e567b5$export$a01cca24f011573a);\n//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst $bda3a1eb26e567b5$var$RDIDX = 256;\nconst $bda3a1eb26e567b5$var$WRIDX = 257;\nconst $bda3a1eb26e567b5$var$LEN = 256;\nclass $bda3a1eb26e567b5$export$a01cca24f011573a {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(1032);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[$bda3a1eb26e567b5$var$RDIDX] = 0;\n this.buf[$bda3a1eb26e567b5$var$WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[$bda3a1eb26e567b5$var$WRIDX];\n this.buf[i] = n;\n i++;\n if (i == $bda3a1eb26e567b5$var$LEN) i = 0;\n this.buf[$bda3a1eb26e567b5$var$WRIDX] = i;\n Atomics.notify(this.buf, $bda3a1eb26e567b5$var$WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[$bda3a1eb26e567b5$var$RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[$bda3a1eb26e567b5$var$RDIDX] = i;\n return n;\n } else return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[$bda3a1eb26e567b5$var$RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, $bda3a1eb26e567b5$var$WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[$bda3a1eb26e567b5$var$RDIDX] == this.buf[$bda3a1eb26e567b5$var$WRIDX];\n }\n}\n\n});\n\n\nparcelRegister(\"5hO33\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrWasmModuleBase\", () => $3d955ccf8fb141b7$export$c83a0a3bffe07399);\n\nvar $2Xdsi = parcelRequire(\"2Xdsi\");\nclass $3d955ccf8fb141b7$export$c83a0a3bffe07399 {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule;\n floatUtil;\n constructor(isWasmModule = false){\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new (0, $2Xdsi.twrFloatUtil)(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/ /*********************************************************************/ async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n } catch (err) {\n console.log(\"loadWasm() failed to fetch: \" + pathToLoad);\n throw err;\n }\n if (!response.ok) throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, {\n env: allimports\n });\n this.exports = instance.instance.exports;\n if (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory) throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer) console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\n \"setmemory\",\n this.memory\n ]);\n }\n if (this.isWasmModule) // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n {\n if (!(this.memory.buffer instanceof ArrayBuffer)) console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size)=>{\n return new Promise((resolve)=>{\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n } catch (err) {\n console.log(\"WASM instantiate error: \" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch(this.modParams.stdio){\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* executeC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */ async executeC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.executeCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async executeCImpl(fname, cparams = []) {\n if (!this.exports) throw new Error(\"this.exports undefined\");\n if (!this.exports[fname]) throw new Error(\"executeC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array)) throw new Error(\"executeC: params must be array, first arg is function name\");\n if (params.length == 0) throw new Error(\"executeC: missing function name\");\n let cparams = [];\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n cparams[ci++] = p;\n break;\n case \"string\":\n cparams[ci++] = await this.putString(p);\n break;\n case \"object\":\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n } else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"executeC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n ci++;\n break;\n case \"string\":\n this.executeCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n case \"object\":\n if (p instanceof URL) {\n this.executeCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci = ci + 2;\n break;\n } else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for(let j = 0; j < u8.length; j++)u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.executeCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n } else throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/ /*********************************************************************/ // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for(i = 0; i < sin.length && i < buffer_size - 1; i++)this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for(let i = 0; i < u8a.length; i++)this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === \"object\" && fnin instanceof URL)) throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [\n dest,\n src.length\n ];\n } catch (err) {\n console.log(\"fetchAndPutURL Error. URL: \" + fnin + \"\\n\" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while(this.mem8[strIndex + i] && (len === undefined ? true : i < len) && strIndex + i < this.mem8.length){\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array(this.mem8.slice(dataptr, dataptr + size).buffer);\n return u32;\n }\n}\n\n});\nparcelRegister(\"2Xdsi\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrFloatUtil\", () => $226b87658a7c840f$export$918ffb7e046a537b);\nclass $226b87658a7c840f$export$918ffb7e046a537b {\n mod;\n constructor(mod){\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\") return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\") return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll(\"D\", \"e\").replaceAll(\"d\", \"e\"));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n } else {\n let r = value.toString();\n if (r.length > max_precision) r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, sizeInBytes, value, fracpart_numdigits, dec, sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1) return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) {\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (!Number.isFinite(value)) {\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n } else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split(\".\");\n if (intPart == \"0\") intPart = \"\";\n if (intPart.length > 0) {\n decpos = intPart.length;\n digits = intPart + fracPart;\n } else {\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length) return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */ }\n}\n\n});\n\n\nparcelRegister(\"5LsZ0\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrCanvas\", () => $4327d2f23f608609$export$2f298dd69cef3c34);\n\nvar $ghrAp = parcelRequire(\"ghrAp\");\n\nvar $47Wdp = parcelRequire(\"47Wdp\");\nvar $4327d2f23f608609$var$D2DType;\n(function(D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})($4327d2f23f608609$var$D2DType || ($4327d2f23f608609$var$D2DType = {}));\nclass $4327d2f23f608609$export$2f298dd69cef3c34 {\n ctx;\n props = {\n charWidth: 0,\n charHeight: 0,\n foreColor: 0,\n backColor: 0,\n widthInChars: 0,\n heightInChars: 0,\n canvasHeight: 0,\n canvasWidth: 0\n };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase){\n const { forecolor: forecolor, backcolor: backcolor, fontsize: fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new (0, $47Wdp.twrSignal)();\n this.canvasKeys = new (0, $ghrAp.twrSharedCircularBuffer)(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.props,\n this.cmdCompleteSignal.sharedArray,\n this.canvasKeys.sharedArray\n ];\n }\n getProp(pn) {\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */ drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx) return;\n let ins = this.owner.getLong(ds); /* ds->start */ \n const lastins = this.owner.getLong(ds + 4); /* ds->last */ \n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while(true){\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */ \n switch(type){\n case $4327d2f23f608609$var$D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_BEGINPATH:\n this.ctx.beginPath();\n break;\n case $4327d2f23f608609$var$D2DType.D2D_FILL:\n this.ctx.fill();\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SAVE:\n this.ctx.save();\n break;\n case $4327d2f23f608609$var$D2DType.D2D_RESTORE:\n this.ctx.restore();\n break;\n case $4327d2f23f608609$var$D2DType.D2D_STROKE:\n this.ctx.stroke();\n break;\n case $4327d2f23f608609$var$D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = this.owner.getLong(ins + 48) != 0;\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n } else this.precomputedObjects[id] = {\n mem8: new Uint8Array(this.owner.memory.buffer, start, length),\n width: width,\n height: height\n };\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id]) delete this.precomputedObjects[id];\n else console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n else {\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) this.ctx.putImageData(imgData, dx, dy);\n else this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */ \n if (next == 0) {\n if (ins != lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nclass $4327d2f23f608609$export$c779b2cd00544976 {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner){\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new (0, $47Wdp.twrSignal)(signalBuffer);\n this.canvasKeys = new (0, $ghrAp.twrSharedCircularBuffer)(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\n \"drawseq\",\n [\n ds\n ]\n ]);\n this.drawCompleteSignal.wait();\n }\n}\n\n});\nparcelRegister(\"47Wdp\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrSignal\", () => $3014f93b5ceae902$export$e37a7b7b851b97f3);\n//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar $3014f93b5ceae902$var$twrSignalState;\n(function(twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})($3014f93b5ceae902$var$twrSignalState || ($3014f93b5ceae902$var$twrSignalState = {}));\nclass $3014f93b5ceae902$export$e37a7b7b851b97f3 {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = $3014f93b5ceae902$var$twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = $3014f93b5ceae902$var$twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == $3014f93b5ceae902$var$twrSignalState.WAITING) //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, $3014f93b5ceae902$var$twrSignalState.WAITING);\n }\n isSignaled() {\n return this.buf[0] == $3014f93b5ceae902$var$twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = $3014f93b5ceae902$var$twrSignalState.WAITING;\n }\n}\n\n});\n\n\n\nparcelRegister(\"lsUl2\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrTimeImpl\", () => $fa07ea1a08a5d6be$export$78724cdcf7ebea1d);\nfunction $fa07ea1a08a5d6be$export$78724cdcf7ebea1d() {\n return Date.now();\n}\n\n});\n\n\nparcelRegister(\"baOio\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrWasmModuleAsync\", () => $8227a48f951b1cca$export$678fe6e36ab9a6ff);\n\nvar $9FI45 = parcelRequire(\"9FI45\");\n\nvar $aGUWE = parcelRequire(\"aGUWE\");\n\nvar $2vKdq = parcelRequire(\"2vKdq\");\n\nvar $bqeaG = parcelRequire(\"bqeaG\");\n\nclass $8227a48f951b1cca$export$678fe6e36ab9a6ff extends (0, $aGUWE.twrWasmModuleInJSMain) {\n myWorker;\n malloc;\n loadWasmResolve;\n loadWasmReject;\n executeCResolve;\n executeCReject;\n initLW = false;\n waitingcalls;\n constructor(opts){\n super(opts);\n this.malloc = (size)=>{\n throw new Error(\"Error - un-init malloc called.\");\n };\n if (!window.Worker) throw new Error(\"This browser doesn't support web workers.\");\n this.myWorker = new Worker((parcelRequire(\"aRHnW\")));\n this.myWorker.onmessage = this.processMsg.bind(this);\n }\n // overrides base implementation\n async loadWasm(pathToLoad) {\n if (this.initLW) throw new Error(\"twrWasmAsyncModule::loadWasm can only be called once per twrWasmAsyncModule instance\");\n this.initLW = true;\n return new Promise((resolve, reject)=>{\n this.loadWasmResolve = resolve;\n this.loadWasmReject = reject;\n this.malloc = (size)=>{\n return this.executeCImpl(\"twr_malloc\", [\n size\n ]);\n };\n this.waitingcalls = new (0, $2vKdq.twrWaitingCalls)(); // handle's calls that cross the worker thread - main js thread boundary\n let canvas;\n if (this.d2dcanvas.isValid()) canvas = this.d2dcanvas;\n else canvas = this.iocanvas;\n const modWorkerParams = {\n divProxyParams: this.iodiv.getProxyParams(),\n canvasProxyParams: canvas.getProxyParams(),\n waitingCallsProxyParams: this.waitingcalls.getProxyParams()\n };\n const urlToLoad = new URL(pathToLoad, document.URL);\n const startMsg = {\n urlToLoad: urlToLoad.href,\n modWorkerParams: modWorkerParams,\n modParams: this.modParams\n };\n this.myWorker.postMessage([\n \"startup\",\n startMsg\n ]);\n });\n }\n async executeC(params) {\n const cparams = await this.preCallC(params); // will also validate params[0]\n return this.executeCImpl(params[0], cparams);\n }\n async executeCImpl(fname, cparams = []) {\n return new Promise((resolve, reject)=>{\n this.executeCResolve = resolve;\n this.executeCReject = reject;\n this.myWorker.postMessage([\n \"executeC\",\n fname,\n cparams\n ]);\n });\n }\n // this function should be called from HTML \"keydown\" event from
\n keyDownDiv(ev) {\n if (!this.iodiv || !this.iodiv.divKeys) throw new Error(\"unexpected undefined twrWasmAsyncModule.divKeys\");\n this.iodiv.divKeys.write((0, $bqeaG.default)(ev).char.charCodeAt(0));\n }\n // this function should be called from HTML \"keydown\" event from \n keyDownCanvas(ev) {\n if (!this.iocanvas || !this.iocanvas.canvasKeys) throw new Error(\"unexpected undefined twrWasmAsyncModule.canvasKeys\");\n this.iocanvas.canvasKeys.write((0, $bqeaG.default)(ev).char.charCodeAt(0));\n }\n processMsg(event) {\n const msgType = event.data[0];\n const d = event.data[1];\n //console.log(\"twrWasmAsyncModule - got message: \"+event.data)\n switch(msgType){\n case \"divout\":\n if (this.iodiv.isValid()) this.iodiv.charOut(d);\n else console.log(\"error - msg divout received but iodiv is undefined.\");\n break;\n case \"debug\":\n (0, $9FI45.twrDebugLogImpl)(d);\n break;\n case \"drawseq\":\n {\n //console.log(\"twrModAsync got message drawseq\");\n const [ds] = d;\n if (this.iocanvas.isValid()) this.iocanvas.drawSeq(ds);\n else if (this.d2dcanvas.isValid()) this.d2dcanvas.drawSeq(ds);\n else throw new Error(\"msg drawseq received but canvas is undefined.\");\n break;\n }\n case \"setmemory\":\n this.memory = d;\n if (!this.memory) throw new Error(\"unexpected error - undefined memory in startupOkay msg\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n break;\n case \"startupFail\":\n if (this.loadWasmReject) this.loadWasmReject(d);\n else throw new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmReject)\");\n break;\n case \"startupOkay\":\n if (this.loadWasmResolve) this.loadWasmResolve(undefined);\n else throw new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmResolve)\");\n break;\n case \"executeCFail\":\n if (this.executeCReject) this.executeCReject(d);\n else throw new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined executeCReject)\");\n break;\n case \"executeCOkay\":\n if (this.executeCResolve) this.executeCResolve(d);\n else throw new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined executeCResolve)\");\n break;\n default:\n if (!this.waitingcalls) throw new Error(\"internal error: this.waitingcalls undefined.\");\n if (!this.waitingcalls.processMessage(msgType, d)) throw new Error(\"twrWasmAsyncModule - unknown and unexpected msgType: \" + msgType);\n }\n }\n}\n\n});\nparcelRegister(\"2vKdq\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrWaitingCalls\", () => $1d42537681d02be3$export$9e37856d1928d388);\n\nvar $47Wdp = parcelRequire(\"47Wdp\");\n\nvar $lsUl2 = parcelRequire(\"lsUl2\");\nclass $1d42537681d02be3$export$9e37856d1928d388 {\n callCompleteSignal;\n parameters;\n constructor(){\n this.callCompleteSignal = new (0, $47Wdp.twrSignal)();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(()=>{\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = (0, $lsUl2.twrTimeImpl)();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [\n this.callCompleteSignal.sharedArray,\n this.parameters.buffer\n ];\n }\n processMessage(msgType, data) {\n switch(msgType){\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\nclass $1d42537681d02be3$export$78d2a4633fe89379 {\n callCompleteSignal;\n parameters;\n constructor(params){\n this.callCompleteSignal = new (0, $47Wdp.twrSignal)(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\n \"sleep\",\n [\n ms\n ]\n ]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\n \"time\"\n ]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n\n});\n\nparcelRegister(\"bqeaG\", function(module, exports) {\n\n$parcel$export(module.exports, \"default\", () => $850d1d8f0aa1ea8f$export$2e2bcd8739ae039);\nconst $850d1d8f0aa1ea8f$var$keycodeCtrlKeys = {\n \"a\": \"selectAll\",\n \"c\": \"copy\",\n \"s\": \"save\",\n \"v\": \"paste\",\n \"x\": \"cut\",\n \"y\": \"redo\",\n \"z\": \"undo\"\n};\nconst $850d1d8f0aa1ea8f$var$keycodeShiftedKeys = {\n \"/\": \"?\",\n \".\": \">\",\n \",\": \"<\",\n \"'\": '\"',\n \";\": \":\",\n \"[\": \"{\",\n \"]\": \"}\",\n \"\\\\\": \"|\",\n \"`\": \"~\",\n \"=\": \"+\",\n \"-\": \"_\",\n \"1\": \"!\",\n \"2\": \"@\",\n \"3\": \"#\",\n \"4\": \"$\",\n \"5\": \"%\",\n \"6\": \"^\",\n \"7\": \"&\",\n \"8\": \"*\",\n \"9\": \"(\",\n \"0\": \")\",\n \"a\": \"A\",\n \"b\": \"B\",\n \"c\": \"C\",\n \"d\": \"D\",\n \"e\": \"E\",\n \"f\": \"F\",\n \"g\": \"G\",\n \"h\": \"H\",\n \"i\": \"I\",\n \"j\": \"J\",\n \"k\": \"K\",\n \"l\": \"L\",\n \"m\": \"M\",\n \"n\": \"N\",\n \"o\": \"O\",\n \"p\": \"P\",\n \"q\": \"q\",\n \"r\": \"R\",\n \"s\": \"S\",\n \"t\": \"T\",\n \"u\": \"U\",\n \"v\": \"V\",\n \"w\": \"W\",\n \"x\": \"X\",\n \"y\": \"Y\",\n \"z\": \"Z\"\n};\nconst $850d1d8f0aa1ea8f$var$keyCodeUnshiftedKeys = {};\nfor(const x in $850d1d8f0aa1ea8f$var$keycodeShiftedKeys){\n const shiftedKey = $850d1d8f0aa1ea8f$var$keycodeShiftedKeys[x];\n $850d1d8f0aa1ea8f$var$keyCodeUnshiftedKeys[shiftedKey] = x;\n}\nconst $850d1d8f0aa1ea8f$var$keydownKeycodeDictionary = {\n 0: \"\\\\\",\n 8: \"backspace\",\n 9: \"tab\",\n 12: \"num\",\n 13: \"enter\",\n 16: \"shift\",\n 17: \"ctrl\",\n 18: \"alt\",\n 19: \"pause\",\n 20: \"caps\",\n 27: \"esc\",\n 32: \" \",\n 33: \"pageup\",\n 34: \"pagedown\",\n 35: \"end\",\n 36: \"home\",\n 37: \"left\",\n 38: \"up\",\n 39: \"right\",\n 40: \"down\",\n 44: \"print\",\n 45: \"insert\",\n 46: \"delete\",\n 48: \"0\",\n 49: \"1\",\n 50: \"2\",\n 51: \"3\",\n 52: \"4\",\n 53: \"5\",\n 54: \"6\",\n 55: \"7\",\n 56: \"8\",\n 57: \"9\",\n 59: \";\",\n 61: \"=\",\n 65: \"a\",\n 66: \"b\",\n 67: \"c\",\n 68: \"d\",\n 69: \"e\",\n 70: \"f\",\n 71: \"g\",\n 72: \"h\",\n 73: \"i\",\n 74: \"j\",\n 75: \"k\",\n 76: \"l\",\n 77: \"m\",\n 78: \"n\",\n 79: \"o\",\n 80: \"p\",\n 81: \"q\",\n 82: \"r\",\n 83: \"s\",\n 84: \"t\",\n 85: \"u\",\n 86: \"v\",\n 87: \"w\",\n 88: \"x\",\n 89: \"y\",\n 90: \"z\",\n 91: \"meta\",\n 92: \"meta\",\n 93: \"meta\",\n 96: \"num0\",\n 97: \"num1\",\n 98: \"num2\",\n 99: \"num3\",\n 100: \"num4\",\n 101: \"num5\",\n 102: \"num6\",\n 103: \"num7\",\n 104: \"num8\",\n 105: \"num9\",\n 106: \"*\",\n 107: \"+\",\n 108: \"num_enter\",\n 109: \"num_subtract\",\n 110: \"num_decimal\",\n 111: \"num_divide\",\n 112: \"f1\",\n 113: \"f2\",\n 114: \"f3\",\n 115: \"f4\",\n 116: \"f5\",\n 117: \"f6\",\n 118: \"f7\",\n 119: \"f8\",\n 120: \"f9\",\n 121: \"f10\",\n 122: \"f11\",\n 123: \"f12\",\n 124: \"print\",\n 144: \"num\",\n 145: \"scroll\",\n 173: \"-\",\n 186: \";\",\n 187: \"=\",\n 188: \",\",\n 189: \"-\",\n 190: \".\",\n 191: \"/\",\n 192: \"`\",\n 219: \"[\",\n 220: \"\\\\\",\n 221: \"]\",\n 222: \"'\",\n 223: \"`\",\n 224: \"cmd\",\n 225: \"alt\",\n 57392: \"ctrl\",\n 63289: \"num\"\n};\nconst $850d1d8f0aa1ea8f$var$keypressCharacterMapOverides = {\n \"\\r\": \"enter\"\n};\nconst $850d1d8f0aa1ea8f$var$keypressCharacterMap = JSON.parse(JSON.stringify($850d1d8f0aa1ea8f$var$keydownKeycodeDictionary));\nfor (const key of Object.keys($850d1d8f0aa1ea8f$var$keypressCharacterMapOverides))$850d1d8f0aa1ea8f$var$keypressCharacterMap[key] = $850d1d8f0aa1ea8f$var$keypressCharacterMapOverides[key];\nconst $850d1d8f0aa1ea8f$var$keydownCharacterMap = {\n \"num_subtract\": \"-\",\n \"num_enter\": \"\\n\",\n \"num_decimal\": \".\",\n \"num_divide\": \"/\",\n \"enter\": \"\\n\",\n \"tab\": \"\t\",\n \"backspace\": \"\\b\"\n};\nconst $850d1d8f0aa1ea8f$export$d1477772898aaa70 = [\n \"backspace\",\n \"enter\",\n \"tab\",\n \"num\",\n \"shift\",\n \"meta\",\n \"alt\",\n \"pause\",\n \"caps\",\n \"esc\",\n \"pageup\",\n \"pagedown\",\n \"end\",\n \"home\",\n \"left\",\n \"up\",\n \"right\",\n \"down\",\n \"print\",\n \"insert\",\n \"delete\",\n \"cmd\",\n \"f1\",\n \"f2\",\n \"f3\",\n \"f4\",\n \"f5\",\n \"f6\",\n \"f7\",\n \"f8\",\n \"f9\",\n \"f10\",\n \"f11\",\n \"f12\",\n \"scroll\",\n \"ctrl\"\n];\nconst $850d1d8f0aa1ea8f$var$validEvents = [\n \"keydown\",\n \"keyup\"\n];\nconst $850d1d8f0aa1ea8f$var$isMobile = ()=>{\n const ua = navigator.userAgent;\n const mobile = /IEMobile|Windows Phone|Lumia/i.test(ua) ? \"w\" : /iPhone|iP[oa]d/.test(ua) ? \"i\" : /Android/.test(ua) ? \"a\" : /BlackBerry|PlayBook|BB10/.test(ua) ? \"b\" : /Mobile Safari/.test(ua) ? \"s\" : /webOS|Mobile|Tablet|Opera Mini|\\bCrMo\\/|Opera Mobi/i.test(ua) ? 1 : 0;\n return mobile !== 0;\n};\nfunction $850d1d8f0aa1ea8f$var$getKeypressKeycodeValue(charcode) {\n const character = String.fromCharCode(charcode);\n if ($850d1d8f0aa1ea8f$var$isMobile()) return character;\n if (character in $850d1d8f0aa1ea8f$var$keyCodeUnshiftedKeys) return $850d1d8f0aa1ea8f$var$keyCodeUnshiftedKeys[character];\n else if (character in $850d1d8f0aa1ea8f$var$keypressCharacterMap) return $850d1d8f0aa1ea8f$var$keypressCharacterMap[character];\n return character;\n}\nfunction $850d1d8f0aa1ea8f$export$2e2bcd8739ae039(event) {\n let key;\n if (event.type === \"keypress\" && !$850d1d8f0aa1ea8f$var$isMobile()) key = $850d1d8f0aa1ea8f$var$getKeypressKeycodeValue(event.charCode);\n else if (event.type === \"keypress\" && $850d1d8f0aa1ea8f$var$isMobile()) key = $850d1d8f0aa1ea8f$var$getKeypressKeycodeValue(event.keyCode);\n else if ($850d1d8f0aa1ea8f$var$validEvents.indexOf(event.type) > -1) {\n if (event.which !== undefined) key = $850d1d8f0aa1ea8f$var$keydownKeycodeDictionary[event.which];\n else if (event.keyCode !== undefined) key = $850d1d8f0aa1ea8f$var$keydownKeycodeDictionary[event.keyCode];\n else key = \"enter\";\n } else return false;\n let char = key;\n if (event.shiftKey && key in $850d1d8f0aa1ea8f$var$keycodeShiftedKeys) char = $850d1d8f0aa1ea8f$var$keycodeShiftedKeys[key];\n else if (event.ctrlKey && key in $850d1d8f0aa1ea8f$var$keycodeCtrlKeys) char = $850d1d8f0aa1ea8f$var$keycodeCtrlKeys[key];\n else if (key in $850d1d8f0aa1ea8f$var$keydownCharacterMap) char = $850d1d8f0aa1ea8f$var$keydownCharacterMap[key];\n return {\n char: char,\n key: key\n };\n}\n\n});\n\nparcelRegister(\"aRHnW\", function(module, exports) {\n\nvar $hoqmg = parcelRequire(\"hoqmg\");\nlet $7e9081fcee88b005$var$url = new URL(\"twrmodworker.2165e649.js\", import.meta.url);\nmodule.exports = $hoqmg($7e9081fcee88b005$var$url.toString(), $7e9081fcee88b005$var$url.origin, true);\n\n});\nparcelRegister(\"hoqmg\", function(module, exports) {\n\"use strict\";\nmodule.exports = function(workerUrl, origin, isESM) {\n if (origin === self.location.origin) // If the worker bundle's url is on the same origin as the document,\n // use the worker bundle's own url.\n return workerUrl;\n else {\n // Otherwise, create a blob URL which loads the worker bundle with `importScripts`.\n var source = isESM ? \"import \" + JSON.stringify(workerUrl) + \";\" : \"importScripts(\" + JSON.stringify(workerUrl) + \");\";\n return URL.createObjectURL(new Blob([\n source\n ], {\n type: \"application/javascript\"\n }));\n }\n};\n\n});\n\n\n\n\nvar $49087e929fab6e62$exports = {};\n\n(parcelRequire(\"eZoLj\")).register(new URL(\"\", import.meta.url).toString(), JSON.parse('[\"kjr0c\",\"index.528b9ee5.js\",\"cTHdP\",\"twrmodworker.2165e649.js\"]'));\n\n\n//# sourceMappingURL=index.528b9ee5.js.map\n","\"use strict\";\n\nvar mapping = new Map();\nfunction register(baseUrl, manifest) {\n for (var i = 0; i < manifest.length - 1; i += 2) {\n mapping.set(manifest[i], {\n baseUrl: baseUrl,\n path: manifest[i + 1]\n });\n }\n}\nfunction resolve(id) {\n var resolved = mapping.get(id);\n if (resolved == null) {\n throw new Error('Could not resolve bundle with id ' + id);\n }\n return new URL(resolved.path, resolved.baseUrl).toString();\n}\nmodule.exports.register = register;\nmodule.exports.resolve = resolve;","import {twrWasmModule} from \"./twrmod.js\";\r\nimport {IModOpts, IModInWorkerParams, TStdioVals} from \"./twrmodbase.js\"\r\nimport {twrWasmModuleAsync} from \"./twrmodasync.js\";\r\n\r\nexport {IModOpts, TStdioVals, IModInWorkerParams};\r\nexport {twrWasmModule};\r\nexport {twrWasmModuleAsync};\r\n\r\n","import { twrDebugLogImpl } from \"./twrdebug.js\";\nimport { twrWasmModuleInJSMain } from \"./twrmodjsmain.js\";\nimport { twrTimeImpl } from \"./twrdate.js\";\nexport class twrWasmModule extends twrWasmModuleInJSMain {\n malloc;\n constructor(opts = {}) {\n super(opts, true);\n this.malloc = (size) => { throw new Error(\"error - un-init malloc called\"); };\n let canvas;\n if (this.d2dcanvas.isValid())\n canvas = this.d2dcanvas;\n else\n canvas = this.iocanvas;\n this.modParams.imports = {\n twrDebugLog: twrDebugLogImpl,\n twrTime: twrTimeImpl,\n twrDivCharOut: this.iodiv.charOut.bind(this.iodiv),\n twrCanvasGetProp: canvas.getProp.bind(canvas),\n twrCanvasDrawSeq: canvas.drawSeq.bind(canvas),\n twrCanvasCharIn: this.null,\n twrCanvasInkey: this.null,\n twrDivCharIn: this.null,\n twrSleep: this.null,\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function (x, y) { return x % y; },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil),\n };\n }\n null(inval) {\n throw new Error(\"call to unimplemented twrXXX import in twrWasmModule. Use twrWasmModuleAsync ?\");\n }\n}\n//# sourceMappingURL=twrmod.js.map","import {twrDebugLogImpl} from \"./twrdebug.js\"\r\nimport {IModOpts} from \"./twrmodbase.js\";\r\nimport {twrWasmModuleInJSMain} from \"./twrmodjsmain.js\"\r\nimport {twrCanvas} from \"./twrcanvas.js\";\r\nimport {twrTimeImpl} from \"./twrdate.js\"\r\n\r\n\r\n\r\nexport class twrWasmModule extends twrWasmModuleInJSMain {\r\n\t malloc:(size:number)=>Promise;\r\n\r\n\r\n\tconstructor(opts:IModOpts={}) {\r\n\t\tsuper(opts, true);\r\n\t\tthis.malloc=(size:number)=>{throw new Error(\"error - un-init malloc called\")};\r\n\t\t\r\n\t\tlet canvas:twrCanvas;\r\n\t\tif (this.d2dcanvas.isValid()) canvas=this.d2dcanvas;\r\n\t\telse canvas=this.iocanvas;\r\n\r\n\t\tthis.modParams.imports={\r\n\t\t\ttwrDebugLog:twrDebugLogImpl,\r\n\t\t\ttwrTime:twrTimeImpl,\r\n\t\t\ttwrDivCharOut:this.iodiv.charOut.bind(this.iodiv),\r\n\t\t\ttwrCanvasGetProp:canvas.getProp.bind(canvas),\r\n\t\t\ttwrCanvasDrawSeq:canvas.drawSeq.bind(canvas),\r\n\t\t\ttwrCanvasCharIn:this.null,\r\n\t\t\ttwrCanvasInkey:this.null,\r\n\t\t\ttwrDivCharIn:this.null,\r\n\t\t\ttwrSleep:this.null,\r\n\r\n\t\t\ttwrSin:Math.sin,\r\n\t\t\ttwrCos:Math.cos,\r\n\t\t\ttwrTan: Math.tan,\r\n\t\t\ttwrFAbs: Math.abs,\r\n\t\t\ttwrACos: Math.acos,\r\n\t\t\ttwrASin: Math.asin,\r\n\t\t\ttwrATan: Math.atan,\r\n\t\t\ttwrExp: Math.exp,\r\n\t\t\ttwrFloor: Math.floor,\r\n\t\t\ttwrCeil: Math.ceil,\r\n\t\t\ttwrFMod: function(x:number, y:number) {return x%y},\r\n\t\t\ttwrLog: Math.log,\r\n\t\t\ttwrPow: Math.pow,\r\n\t\t\ttwrSqrt: Math.sqrt,\r\n\t\t\ttwrTrunc: Math.trunc,\r\n\r\n\t\t\ttwrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\r\n\t\t\ttwrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\r\n\t\t\ttwrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\r\n\t\t\ttwrAtod: this.floatUtil.atod.bind(this.floatUtil),\r\n\t\t\ttwrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil),\r\n\t\t}\r\n\t}\r\n\r\n\tnull(inval?:any) {\r\n\t\tthrow new Error(\"call to unimplemented twrXXX import in twrWasmModule. Use twrWasmModuleAsync ?\");\r\n\t}\r\n}\r\n\r\n\r\n\r\n\r\n","let logline = \"\";\nexport function twrDebugLogImpl(char) {\n if (char == 10 || char == 3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\n console.log(logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n logline = \"\";\n }\n else {\n logline = logline + String.fromCharCode(char);\n if (logline.length >= 200) {\n console.log(logline);\n logline = \"\";\n }\n }\n}\n// ************************************************************************\n// debugLog doesn't currently wait for the message to log, it returns immediately.\n// I could move this to be in the twrWaitingCalls class\nexport function twrDebugLogProxy(ch) {\n postMessage([\"debug\", ch]);\n}\n//# sourceMappingURL=twrdebug.js.map","\r\nlet logline=\"\";\r\nexport function twrDebugLogImpl(char:number) {\r\n\tif (char==10 || char==3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\r\n\t\tconsole.log(logline);\t// ideally without a linefeed, but there is no way to not have a LF with console.log API.\r\n\t\tlogline=\"\";\r\n\t}\r\n\telse {\r\n\t\tlogline=logline+String.fromCharCode(char);\r\n\t\tif (logline.length>=200) {\r\n\t\t\tconsole.log(logline);\r\n\t\t\tlogline=\"\";\r\n\t\t}\r\n\t}\r\n}\r\n\r\n// ************************************************************************\r\n// debugLog doesn't currently wait for the message to log, it returns immediately.\r\n// I could move this to be in the twrWaitingCalls class\r\nexport function twrDebugLogProxy(ch:number) {\r\n postMessage([\"debug\", ch]);\r\n}\r\n\r\n","// This class extends base to handle options when called in the main Java Script thread\nimport { twrDiv } from \"./twrdiv.js\";\nimport { twrWasmModuleBase } from \"./twrmodbase.js\";\nimport { twrCanvas } from \"./twrcanvas.js\";\nexport class twrWasmModuleInJSMain extends twrWasmModuleBase {\n iocanvas;\n d2dcanvas;\n iodiv;\n modParams;\n constructor(opts = {}, isWasmModule = false) {\n super(isWasmModule);\n if (typeof document === 'undefined')\n throw new Error(\"twrWasmModuleJSMain should only be created in JavaScript Main.\");\n const eiodiv = document.getElementById(\"twr_iodiv\");\n const eiocanvas = document.getElementById(\"twr_iocanvas\");\n const ed2dcanvas = document.getElementById(\"twr_d2dcanvas\");\n if (eiocanvas && ed2dcanvas)\n throw new Error(\"Both twr_iocanvas and twr_d2dcanvas defined. Currently only one canvas allowed.\");\n if (opts.stdio == 'div' && !eiodiv)\n throw new Error(\"twrWasmModuleBase opts=='div' but twr_iodiv not defined\");\n if (opts.stdio == 'canvas' && !eiocanvas)\n throw new Error(\"twrWasmModuleBase, opts=='canvas' but twr_iocanvas not defined\");\n if (opts.isd2dcanvas && !ed2dcanvas)\n throw new Error(\"twrWasmModuleBase, opts.isdrawcanvas==true but twr_d2dcanvas not defined\");\n // set default opts based on elements found\n if (eiodiv)\n opts = { stdio: \"div\", ...opts };\n else if (eiocanvas)\n opts = { stdio: \"canvas\", ...opts };\n else\n opts = { stdio: \"debug\", ...opts };\n if (!eiodiv && !eiocanvas)\n console.log(\"Since neither twr_iocanvas nor twr_iodiv is defined, stdout directed to debug console.\");\n else\n console.log('tiny-wasm-runtime: stdio set to: ', opts.stdio);\n if (eiocanvas)\n opts = { windim: [64, 16], ...opts };\n else\n opts = { windim: [0, 0], ...opts };\n if (!opts.imports)\n opts.imports = {};\n let styleIsDefault = false;\n if (!opts.backcolor) {\n styleIsDefault = true;\n opts.backcolor = \"black\";\n }\n if (!opts.forecolor) {\n styleIsDefault = true;\n opts.forecolor = \"white\";\n }\n if (!opts.fontsize) {\n styleIsDefault = true;\n opts.fontsize = 16;\n }\n if (opts.isd2dcanvas === undefined) {\n if (ed2dcanvas)\n opts.isd2dcanvas = true;\n else\n opts.isd2dcanvas = false;\n }\n this.modParams = {\n stdio: opts.stdio,\n windim: opts.windim,\n imports: opts.imports,\n forecolor: opts.forecolor,\n backcolor: opts.backcolor,\n styleIsDefault: styleIsDefault,\n fontsize: opts.fontsize,\n isd2dcanvas: opts.isd2dcanvas\n };\n this.iodiv = new twrDiv(eiodiv, this.modParams, this);\n this.iocanvas = new twrCanvas(eiocanvas, this.modParams, this);\n this.d2dcanvas = new twrCanvas(ed2dcanvas, this.modParams, this);\n }\n divLog(...params) {\n for (var i = 0; i < params.length; i++) {\n this.iodiv.stringOut(params[i].toString());\n this.iodiv.charOut(32); // space\n }\n this.iodiv.charOut(10);\n }\n}\n//# sourceMappingURL=twrmodjsmain.js.map","// This class extends base to handle options when called in the main Java Script thread\r\n\r\nimport {twrDiv} from \"./twrdiv.js\"\r\nimport {IModParams, IModOpts, twrWasmModuleBase} from \"./twrmodbase.js\"\r\nimport {twrCanvas} from \"./twrcanvas.js\"\r\n\r\n\r\nexport abstract class twrWasmModuleInJSMain extends twrWasmModuleBase {\r\n\tiocanvas:twrCanvas;\r\n\td2dcanvas:twrCanvas;\r\n\tiodiv:twrDiv;\r\n\tmodParams:IModParams;\r\n\r\n constructor(opts:IModOpts={}, isWasmModule=false) {\r\n\t\tsuper(isWasmModule);\r\n\t\tif (typeof document === 'undefined')\r\n\t\t\tthrow new Error (\"twrWasmModuleJSMain should only be created in JavaScript Main.\");\r\n\r\n\t\tconst eiodiv=document.getElementById(\"twr_iodiv\") as HTMLDivElement;\r\n\t\tconst eiocanvas=document.getElementById(\"twr_iocanvas\") as HTMLCanvasElement;\r\n\t\tconst ed2dcanvas=document.getElementById(\"twr_d2dcanvas\") as HTMLCanvasElement;\r\n\r\n\t\tif (eiocanvas && ed2dcanvas) throw new Error (\"Both twr_iocanvas and twr_d2dcanvas defined. Currently only one canvas allowed.\");\r\n\t\tif (opts.stdio=='div' && !eiodiv) throw new Error(\"twrWasmModuleBase opts=='div' but twr_iodiv not defined\");\r\n\t\tif (opts.stdio=='canvas' && !eiocanvas) throw new Error(\"twrWasmModuleBase, opts=='canvas' but twr_iocanvas not defined\");\r\n\t\tif (opts.isd2dcanvas && !ed2dcanvas) throw new Error(\"twrWasmModuleBase, opts.isdrawcanvas==true but twr_d2dcanvas not defined\");\r\n\r\n\t\t// set default opts based on elements found\r\n\t\tif (eiodiv) opts={stdio:\"div\", ...opts};\r\n\t\telse if (eiocanvas) opts={stdio:\"canvas\", ...opts};\r\n\t\telse opts={stdio:\"debug\", ...opts};\r\n\r\n\t\tif (!eiodiv && !eiocanvas) console.log(\"Since neither twr_iocanvas nor twr_iodiv is defined, stdout directed to debug console.\");\r\n\t\telse console.log('tiny-wasm-runtime: stdio set to: ', opts.stdio);\r\n\r\n\t\tif (eiocanvas) opts={windim:[64, 16], ...opts};\r\n\t\telse opts={windim:[0, 0], ...opts};\r\n\r\n\t\tif (!opts.imports) opts.imports={};\r\n\r\n\t\tlet styleIsDefault=false;\r\n\t\tif (!opts.backcolor) {styleIsDefault=true; opts.backcolor=\"black\";}\r\n\t\tif (!opts.forecolor) {styleIsDefault=true; opts.forecolor=\"white\";}\r\n\t\tif (!opts.fontsize) {styleIsDefault=true; opts.fontsize=16;}\r\n\r\n\t\tif (opts.isd2dcanvas===undefined) {\r\n\t\t\tif (ed2dcanvas) \r\n\t\t\t\topts.isd2dcanvas=true;\r\n\t\t\telse\r\n\t\t\t\topts.isd2dcanvas=false;\r\n\t\t}\r\n\r\n\t\tthis.modParams={\r\n\t\t\tstdio:opts.stdio!, \r\n\t\t\twindim:opts.windim!, \r\n\t\t\timports:opts.imports, \r\n\t\t\tforecolor:opts.forecolor, \r\n\t\t\tbackcolor:opts.backcolor, \r\n\t\t\tstyleIsDefault: styleIsDefault,\r\n\t\t\tfontsize:opts.fontsize,\r\n\t\t\tisd2dcanvas:opts.isd2dcanvas\r\n\t\t};\r\n\r\n\t\tthis.iodiv=new twrDiv(eiodiv, this.modParams, this);\r\n\t\tthis.iocanvas=new twrCanvas(eiocanvas, this.modParams, this);\r\n\t\tthis.d2dcanvas=new twrCanvas(ed2dcanvas, this.modParams, this);\r\n\r\n\t}\r\n\r\n\tdivLog(...params: string[]) {\r\n\t\tfor (var i = 0; i < params.length; i++) {\r\n\t\t\tthis.iodiv.stringOut(params[i].toString());\r\n\t\t\tthis.iodiv.charOut(32); // space\r\n\t\t}\r\n\t\tthis.iodiv.charOut(10);\r\n\t }\r\n}","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nexport class twrDiv {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase) {\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\n this.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n if (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.divKeys.sharedArray];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */\n charOut(ch) {\n if (!this.div)\n return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n }\n switch (ch) {\n case 10: // newline\n case 13: // return\n if (ch == 10 && this.lastChar == 13)\n break; // detect CR LF and treat as single new line\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8: // backspace\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n case 0xE: // cursor on\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF: // cursor off\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for (let i = 0; i < str.length; i++)\n this.charOut(str.charCodeAt(i));\n }\n}\nexport class twrDivProxy {\n divKeys;\n constructor(params) {\n const [divKeysBuffer] = params;\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n charOut(ch) {\n postMessage([\"divout\", ch]);\n }\n}\n//# sourceMappingURL=twrdiv.js.map","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\r\nimport { IModParams } from \"./twrmodbase.js\";\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\";\r\n\r\nexport type TDivProxyParams = [SharedArrayBuffer];\r\n\r\nexport interface IDiv {\r\n charOut: (ds:number)=>void,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TDivProxyParams,\r\n }\r\n\r\n\r\nexport class twrDiv implements IDiv {\r\n\tdiv:HTMLDivElement|null|undefined;\r\n\tdivKeys?:twrSharedCircularBuffer;\r\n\tCURSOR=String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\r\n\tcursorOn:boolean=false;\r\n\tlastChar:number=0;\r\n\textraBR:boolean=false;\r\n\towner:twrWasmModuleBase;\r\n\r\n constructor(element:HTMLDivElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n\t\tthis.div=element;\r\n\t\tthis.owner=modbase;\r\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\r\n\t\t\tthis.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n\t\t}\r\n\r\n\t\tif (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\r\n\t\t\tthis.div.style.backgroundColor = modParams.backcolor;\r\n\t\t\tthis.div.style.color = modParams.forecolor;\r\n\t\t\tthis.div.style.font=modParams.fontsize.toString()+\"px arial\"\r\n\t\t}\r\n }\r\n\r\n\tisValid() {\r\n\t\treturn !!this.div;\r\n\t}\r\n\r\n getProxyParams() : TDivProxyParams {\r\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [ this.divKeys.sharedArray];\r\n }\r\n\r\n\r\n/* \r\n * add character to div. Supports the following control codes:\r\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\r\n * 0xE cursor on \r\n * 0x8 backspace\r\n * 0xF cursor off \r\n*/\r\n\tcharOut(ch:number) {\r\n\r\n\t\tif (!this.div) return;\r\n\r\n\t\t//console.log(\"div::charout: \", ch);\r\n\r\n\t\tif (this.extraBR) {\r\n\t\t\tthis.extraBR=false;\r\n\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -4);\r\n\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t}\r\n\r\n\t\tswitch (ch) {\r\n\t\t\tcase 10: // newline\r\n\t\t\tcase 13: // return\r\n\t\t\t\tif (ch==10 && this.lastChar==13) break; // detect CR LF and treat as single new line\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\r\n\t\t\t\tthis.extraBR=true;\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\t//element.scrollIntoView();\r\n\t\t\t\t//element.scrollTop = element.scrollHeight;\r\n\t\t\t\tlet p = this.div.getBoundingClientRect();\r\n\t\t\t\twindow.scrollTo(0, p.height+100);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 8: // backspace\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xE: // cursor on\r\n\t\t\t\tif (!this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=true;\r\n\t\t\t\t\tthis.div.innerHTML += this.CURSOR;\r\n\t\t\t\t\tthis.div.focus();\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xF: // cursor off\r\n\t\t\t\tif (this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=false;\r\n\t\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += String.fromCharCode(ch);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\tthis.lastChar=ch;\r\n\t}\r\n\r\n\tstringOut(str:string) {\r\n\t\tfor (let i=0; i < str.length; i++)\r\n\t\t\tthis.charOut(str.charCodeAt(i));\r\n\t}\r\n}\r\n\r\n\r\nexport class twrDivProxy implements IDiv {\r\n divKeys: twrSharedCircularBuffer;\r\n\r\n constructor(params:TDivProxyParams) {\r\n const [divKeysBuffer] = params;\r\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\r\n }\r\n\r\n charIn() { \r\n return this.divKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.divKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n\tcharOut(ch:number) {\r\n\t\tpostMessage([\"divout\", ch]);\r\n\t}\r\n}\r\n\r\n","//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst RDIDX = 256;\nconst WRIDX = 257;\nconst LEN = 256;\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\n// the first 256 array entries are the circular buffer\n// the next two are used for the read and write index\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\nexport class twrSharedCircularBuffer {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(258 * 4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[RDIDX] = 0;\n this.buf[WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[WRIDX];\n this.buf[i] = n;\n i++;\n if (i == LEN)\n i = 0;\n this.buf[WRIDX] = i;\n Atomics.notify(this.buf, WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[RDIDX] = i;\n return n;\n }\n else\n return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[RDIDX] == this.buf[WRIDX];\n }\n}\n//# sourceMappingURL=twrcircular.js.map","//\r\n// This class implements a circular buffer that the main javascript thread can write to, \r\n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\r\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \r\n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\r\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\r\n//\r\n\r\nconst RDIDX=256;\r\nconst WRIDX=257;\r\nconst LEN=256;\r\n\r\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\r\n// the first 256 array entries are the circular buffer\r\n// the next two are used for the read and write index\r\n\r\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\r\n\r\nexport class twrSharedCircularBuffer {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n \r\n\tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(258*4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[RDIDX]=0;\r\n this.buf[WRIDX]=0;\r\n\t}\r\n\r\n\twrite(n:number) {\r\n let i=this.buf[WRIDX];\r\n this.buf[i]=n;\r\n i++;\r\n if (i==LEN) i=0;\r\n this.buf[WRIDX]=i; \r\n Atomics.notify(this.buf, WRIDX); \r\n\t}\r\n\r\n\tread():number {\r\n if (!this.isEmpty()) {\r\n let i=this.buf[RDIDX];\r\n let n=this.buf[i];\r\n i++;\r\n this.buf[RDIDX]=i;\r\n return n;\r\n }\r\n\t\telse\r\n return -1;\r\n\t}\r\n\r\n readWait():number {\r\n if (this.isEmpty()) {\r\n const rdptr=this.buf[RDIDX];\r\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\r\n Atomics.wait(this.buf, WRIDX, rdptr);\r\n }\r\n return this.read();\r\n\t}\r\n\r\n isEmpty():boolean {\r\n return this.buf[RDIDX]==this.buf[WRIDX];\r\n }\r\n}\r\n","import { twrFloatUtil } from \"./twrfloat.js\";\n/*********************************************************************/\n/*********************************************************************/\n/*********************************************************************/\nexport class twrWasmModuleBase {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\n floatUtil;\n constructor(isWasmModule = false) {\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new twrFloatUtil(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/\n /*********************************************************************/\n async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n }\n catch (err) {\n console.log('loadWasm() failed to fetch: ' + pathToLoad);\n throw err;\n }\n if (!response.ok)\n throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, { env: allimports });\n this.exports = instance.instance.exports;\n if (!this.exports)\n throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory)\n throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory)\n throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer)\n console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\"setmemory\", this.memory]);\n }\n if (this.isWasmModule) {\n // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (!(this.memory.buffer instanceof ArrayBuffer))\n console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size) => {\n return new Promise(resolve => {\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n }\n catch (err) {\n console.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch (this.modParams.stdio) {\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* executeC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */\n async executeC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.executeCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async executeCImpl(fname, cparams = []) {\n if (!this.exports)\n throw new Error(\"this.exports undefined\");\n if (!this.exports[fname])\n throw new Error(\"executeC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array))\n throw new Error(\"executeC: params must be array, first arg is function name\");\n if (params.length == 0)\n throw new Error(\"executeC: missing function name\");\n let cparams = [];\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n cparams[ci++] = p;\n break;\n case 'string':\n cparams[ci++] = await this.putString(p);\n break;\n case 'object':\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n }\n else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"executeC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n ci++;\n break;\n case 'string':\n this.executeCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n case 'object':\n if (p instanceof URL) {\n this.executeCImpl('twr_free', [cparams[ci]]);\n ci = ci + 2;\n break;\n }\n else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for (let j = 0; j < u8.length; j++)\n u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.executeCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n }\n else\n throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/\n /*********************************************************************/\n // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for (i = 0; i < sin.length && i < buffer_size - 1; i++)\n this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for (let i = 0; i < u8a.length; i++)\n this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === 'object' && fnin instanceof URL))\n throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [dest, src.length];\n }\n catch (err) {\n console.log('fetchAndPutURL Error. URL: ' + fnin + '\\n' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while (this.mem8[strIndex + i] && (len === undefined ? true : i < len) && (strIndex + i) < this.mem8.length) {\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0)\n throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array((this.mem8.slice(dataptr, dataptr + size)).buffer);\n return u32;\n }\n}\n//# sourceMappingURL=twrmodbase.js.map","\r\nimport {TCanvasProxyParams} from \"./twrcanvas.js\"\r\nimport {TDivProxyParams} from \"./twrdiv.js\";\r\nimport {TWaitingCallsProxyParams} from \"./twrwaitingcalls.js\"\r\nimport {twrDebugLogImpl} from \"./twrdebug.js\";\r\nimport {twrFloatUtil} from \"./twrfloat.js\";\r\n\r\n\r\nexport type TStdioVals=\"div\"|\"canvas\"|\"null\"|\"debug\";\r\n\r\nexport interface IModOpts {\r\n\tstdio?:TStdioVals, \r\n\twindim?:[number, number],\r\n\tforecolor?:string,\r\n\tbackcolor?:string,\r\n\tfontsize?:number,\r\n\tisd2dcanvas?:boolean,\r\n\timports?:{},\r\n}\r\n\r\nexport interface IModParams {\r\n\tstdio:TStdioVals, \r\n\twindim:[number, number],\r\n\tforecolor:string,\r\n\tbackcolor:string,\r\n\tfontsize:number,\r\n\tstyleIsDefault: boolean\r\n\tisd2dcanvas:boolean,\r\n\timports:{[index:string]:Function},\r\n}\r\n\r\nexport interface IModInWorkerParams {\r\n\tdivProxyParams:TDivProxyParams,\r\n\tcanvasProxyParams:TCanvasProxyParams,\r\n\twaitingCallsProxyParams:TWaitingCallsProxyParams,\r\n}\r\n\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n\r\nexport abstract class twrWasmModuleBase {\r\n\tmemory?:WebAssembly.Memory;\r\n\tmem8:Uint8Array;\r\n\tmem32:Uint32Array;\r\n\tmemD:Float64Array;\r\n\tabstract malloc:(size:number)=>Promise;\r\n\tabstract modParams:IModParams;\r\n\texports?:WebAssembly.Exports;\r\n\tisWorker=false;\r\n\tisWasmModule:boolean; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\r\n\tfloatUtil:twrFloatUtil;\r\n\r\n\tconstructor(isWasmModule=false) {\r\n\t\tthis.isWasmModule=isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\r\n\t\tthis.mem8=new Uint8Array(); \t// avoid type errors\r\n\t\tthis.mem32=new Uint32Array(); // avoid type errors\r\n\t\tthis.memD=new Float64Array(); // avoid type errors\r\n\t\tthis.floatUtil=new twrFloatUtil(this);\r\n\t\t//console.log(\"size of mem8 after constructor\",this.mem8.length);\r\n\t}\r\n\r\n\t/*********************************************************************/\r\n\t/*********************************************************************/\r\n\r\n\tasync loadWasm(pathToLoad:string) {\r\n\t\t//console.log(\"fileToLoad\",fileToLoad)\r\n\r\n\t\tlet response;\r\n\t\ttry {\r\n\t\t\tresponse=await fetch(pathToLoad);\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('loadWasm() failed to fetch: '+pathToLoad);\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t\t\r\n\t\tif (!response.ok) throw new Error(\"fetch response error on file '\"+pathToLoad+\"'\\n\"+response.statusText);\r\n\r\n\t\ttry {\r\n\t\t\tlet wasmBytes = await response.arrayBuffer();\r\n\r\n\t\t\tlet allimports:WebAssembly.ModuleImports = { \r\n\t\t\t\t...this.modParams.imports\r\n\t\t\t};\r\n\r\n\t\t\tlet instance = await WebAssembly.instantiate(wasmBytes, {env: allimports});\r\n\r\n\t\t\tthis.exports=instance.instance.exports;\r\n\t\t\tif (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\r\n\r\n\t\t\tif (this.memory) throw new Error (\"unexpected error -- this.memory already set\");\r\n\t\t\tthis.memory=this.exports.memory as WebAssembly.Memory;\r\n\t\t\tif (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\r\n\t\t\tthis.mem8 = new Uint8Array(this.memory.buffer);\r\n\t\t\tthis.mem32 = new Uint32Array(this.memory.buffer);\r\n\t\t\tthis.memD = new Float64Array(this.memory.buffer);\r\n\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\tif (this.isWorker) {\r\n\t\t\t\tif (this.memory.buffer instanceof ArrayBuffer)\r\n\t\t\t\t\tconsole.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\r\n\t\t\t\t\r\n\t\t\t\tpostMessage([\"setmemory\",this.memory]);\r\n\t\t\t}\r\n\t\t\tif (this.isWasmModule) {\r\n\t\t\t\t// here if twrWasmModule, twrWasmModuleAsync overrides this function\r\n\t\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\t\tif (!(this.memory.buffer instanceof ArrayBuffer))\r\n\t\t\t\t\tconsole.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\r\n\t\t\t}\r\n\r\n\t\t\tthis.malloc=(size:number)=>{\r\n\t\t\t\treturn new Promise(resolve => {\r\n\t\t\t\t\tconst m=this.exports!.twr_malloc as (size:number)=>number;\r\n\t\t\t\t\tresolve(m(size));\r\n\t\t\t\t});\r\n\t\t };\r\n\r\n\t\t\tthis.init();\r\n\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t}\r\n\r\n\tprivate init() {\r\n\t\t//console.log(\"loadWasm.init() enter\")\r\n\t\t\tlet p:number;\r\n\t\t\tswitch (this.modParams.stdio) {\r\n\t\t\t\tcase \"debug\":\r\n\t\t\t\t\tp=0;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"div\":\r\n\t\t\t\t\tp=1;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"canvas\":\r\n\t\t\t\t\tp=2;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"null\":\r\n\t\t\t\t\tp=3;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tp=0; // debug\r\n\t\t\t}\r\n\r\n\t\t\tconst twrInit=this.exports!.twr_wasm_init as CallableFunction;\r\n\t\t\t//console.log(\"twrInit:\",twrInit)\r\n\t\t\ttwrInit(p, this.mem8.length);\r\n\t}\r\n\r\n\t/* executeC takes an array where:\r\n\t* the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\r\n\t* and the next entries are a variable number of parameters to pass to the C function, of type\r\n\t* number - converted to int32 or float64 as appropriate\r\n\t* string - converted to a an index (ptr) into a module Memory returned via stringToMem()\r\n\t* URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\r\n\t* Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\r\n */\r\n\r\n\tasync executeC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\t\tconst cparams=await this.preCallC(params);\r\n\t\tlet retval = this.executeCImpl(params[0], cparams);\r\n\t\tthis.postCallC(cparams, params);\r\n\t\treturn retval;\r\n\t}\r\n\r\n\tasync executeCImpl(fname:string, cparams:number[]=[]) {\r\n\t\tif (!this.exports) throw new Error(\"this.exports undefined\");\r\n\t\tif (!this.exports[fname]) throw new Error(\"executeC: function '\"+fname+\"' not in export table. Use --export wasm-ld flag.\");\r\n\r\n\t\tconst f = this.exports[fname] as CallableFunction;\r\n\t\tlet cr=f(...cparams);\r\n\r\n\t\treturn cr;\r\n\t}\r\n\r\n\t// convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\r\n\tasync preCallC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tif (!(params.constructor === Array)) throw new Error (\"executeC: params must be array, first arg is function name\");\r\n\t\tif (params.length==0) throw new Error(\"executeC: missing function name\");\r\n\r\n\t\tlet cparams:number[]=[];\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tcparams[ci++]=p;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tcparams[ci++]=await this.putString(p);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tconst r=await this.fetchAndPutURL(p);\r\n\t\t\t\t\t\tcparams[ci++]=r[0]; // mem index\r\n\t\t\t\t\t\tcparams[ci++]=r[1]; // len\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tconst r=await this.putArrayBuffer(p);\r\n\t\t\t\t\t\tcparams[ci++]=r; // mem index\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tthrow new Error (\"executeC: invalid object type passed in\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn cparams;\r\n\t}\r\n\r\n\t// free the mallocs; copy array buffer data from malloc back to arraybuffer\r\n\tasync postCallC(cparams:number[], params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tthis.executeCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t\t\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tthis.executeCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\t\tci=ci+2;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tlet u8=new Uint8Array(p);\r\n\t\t\t\t\t\tfor (let j=0; j= this.mem32.length) throw new Error(\"invalid index passed to getLong: \"+idx+\", this.mem32.length: \"+this.mem32.length);\r\n\t\tconst long:number = this.mem32[idx32];\r\n\t\treturn long;\r\n\t}\r\n\t\r\n\tsetLong(idx:number, value:number) {\r\n const idx32 = Math.floor(idx / 4);\r\n if (idx32 * 4 != idx)\r\n throw new Error(\"setLong passed non long aligned address\");\r\n if (idx32 < 0 || idx32 >= this.mem32.length)\r\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\r\n this.mem32[idx32]=value;\r\n }\r\n\r\n\tgetDouble(idx:number): number {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"getLong passed non Float64 aligned address\")\r\n\t\tconst long:number = this.memD[idx64];\r\n\t\treturn long;\r\n\t}\r\n\r\n\tsetDouble(idx:number, value:number) {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"setDouble passed non Float64 aligned address\")\r\n\t\tthis.memD[idx64]=value;\r\n\t}\r\n\r\n\tgetShort(idx:number): number {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getShort: \"+idx);\r\n\t\tconst short:number = this.mem8[idx]+this.mem8[idx+1]*256;\r\n\t\treturn short;\r\n\t}\r\n\r\n\t// get a string out of module memory\r\n\t// null terminated, up until max of (optional) len\r\n\tgetString(strIndex:number, len?:number): string {\r\n\t\tlet sout=\"\";\r\n\r\n\t\tlet i=0;\r\n\t\twhile (this.mem8[strIndex+i] && (len===undefined?true:i= this.mem8.length) throw new Error(\"invalid index passed to getU8: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU8\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU8\")\r\n\r\n\t\tconst u8=this.mem8.slice(dataptr, dataptr+size);\r\n\t\treturn u8;\r\n\t}\r\n\r\n\t// get a int32 array out of module memory when passed in index to [size, dataptr]\r\n\tgetU32Arr(idx:number): Uint32Array {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getU32: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU32\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU32\")\r\n\r\n\t\tif (size%4!=0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\r\n\r\n\t\tconst u32 = new Uint32Array( (this.mem8.slice(dataptr, dataptr+size)).buffer );\r\n\t\treturn u32;\r\n\t}\r\n}\r\n","export class twrFloatUtil {\n mod;\n constructor(mod) {\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\")\n return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\")\n return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll('D', 'e').replaceAll('d', 'e'));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n }\n else {\n let r = value.toString();\n if (r.length > max_precision)\n r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, // char *\n sizeInBytes, //size_t\n value, // double\n fracpart_numdigits, //int\n dec, // int *\n sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1)\n return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) { /* nan */\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (!Number.isFinite(value)) { /* infinity */\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n }\n else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split('.');\n if (intPart == \"0\")\n intPart = \"\";\n if (intPart.length > 0) { // has integer part\n decpos = intPart.length;\n digits = intPart + fracPart;\n }\n else { // only a fraction\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length)\n return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */\n }\n}\n//# sourceMappingURL=twrfloat.js.map","\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\"\r\n\r\nexport class twrFloatUtil {\r\n mod: twrWasmModuleBase;\r\n\r\n constructor(mod: twrWasmModuleBase) {\r\n this.mod=mod;\r\n }\r\n\r\n atod(strptr:number):number {\r\n const str=this.mod.getString(strptr);\r\n\r\n const upper=str.trimStart().toUpperCase();\r\n if (upper==\"INF\" || upper==\"+INF\")\r\n return Number.POSITIVE_INFINITY;\r\n else if (upper==\"-INF\")\r\n return Number.NEGATIVE_INFINITY\r\n else {\r\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\r\n const r=Number.parseFloat(str.replaceAll('D','e').replaceAll('d','e'));\r\n return r;\r\n }\r\n }\r\n\r\n dtoa(buffer:number, buffer_size:number, value:number, max_precision:number):void {\r\n if (max_precision==-1) {\r\n const r=value.toString();\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n else {\r\n let r=value.toString();\r\n if (r.length>max_precision)\r\n r=value.toPrecision(max_precision);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n }\r\n\r\n toFixed(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toFixed(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n toExponential(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toExponential(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\r\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\r\n // Negative exponents must be now smaller than 1e-99\r\n // fully-function C version also int he source, but this is the version enabled by default\r\n fcvtS(\r\n buffer:number, // char *\r\n sizeInBytes:number, //size_t\r\n value:number, // double\r\n fracpart_numdigits:number, //int\r\n dec:number, // int *\r\n sign:number // int *\r\n ):number {\r\n\r\n if (buffer==0 ||sign==0 || dec==0 || sizeInBytes<1) return 1;\r\n\r\n let digits:string;\r\n let decpos:number;\r\n let s=0; // default to positive\r\n\r\n\r\n if (Number.isNaN(value)) { /* nan */\r\n digits=\"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (!Number.isFinite(value)) { /* infinity */\r\n digits=\"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (value==0) { \r\n digits=\"000000000000000000000000000000000000\".slice(0,fracpart_numdigits);\r\n decpos=0;\r\n }\r\n \r\n else {\r\n\r\n if (value<0) {\r\n s=1; // negative\r\n value=Math.abs(value);\r\n }\r\n\r\n if (fracpart_numdigits>100 || value > 1e+21 || value < 1e-99) { \r\n this.mod.copyString(buffer, sizeInBytes, \"\");\r\n this.mod.mem32[dec]=0;\r\n return 1;\r\n }\r\n\r\n const roundValStr=value.toFixed(fracpart_numdigits);\r\n let [intPart=\"\", fracPart=\"\"] = roundValStr.split('.');\r\n if (intPart==\"0\") intPart=\"\";\r\n\r\n if (intPart.length>0) { // has integer part\r\n decpos=intPart.length;\r\n digits=intPart+fracPart;\r\n }\r\n else { // only a fraction\r\n digits=fracPart.replace(/^0+/,\"\"); // remove leading zeros\r\n decpos=digits.length-fracPart.length;\r\n }\r\n }\r\n\r\n if (sizeInBytes-1 < digits.length) return 1; \r\n this.mod.copyString(buffer, sizeInBytes, digits);\r\n this.mod.setLong(dec, decpos);\r\n this.mod.setLong(sign, s);\r\n\r\n return 0;\r\n\r\n /*\r\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\r\n\r\n let decpos=0;\r\n let digits:string;\r\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\r\n \r\n if (decpos>0) { // has integer part\r\n const intlen=Math.max(decpos, 0);\r\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\r\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\r\n }\r\n else { // only a fraction\r\n const intpart=Math.trunc(value);\r\n const fracpart=value-intpart;\r\n const prec=fracpart_numdigits- (-decpos);\r\n console.log(\"prec=\",prec);\r\n if (prec<1) {\r\n digits=\"\";\r\n }\r\n else {\r\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\");\r\n }\r\n }\r\n\r\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\r\n console.log('digits=',digits);\r\n console.log('dec=',decpos);\r\n console.log(\"sign=\",s);\r\n */\r\n\r\n\r\n }\r\n}","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nimport { twrSignal } from \"./twrsignal.js\";\nvar D2DType;\n(function (D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})(D2DType || (D2DType = {}));\nexport class twrCanvas {\n ctx;\n props = { charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight: 0, canvasWidth: 0 };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase) {\n const { forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new twrSignal();\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext)\n throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c)\n throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2)\n throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\n }\n getProp(pn) {\n if (!this.isValid())\n console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */\n drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid())\n console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx)\n return;\n let ins = this.owner.getLong(ds); /* ds->start */\n const lastins = this.owner.getLong(ds + 4); /* ds->last */\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while (1) {\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */\n if (0 /*type!=D2DType.D2D_FILLRECT*/) {\n console.log(\"ins\", ins);\n console.log(\"hdr.next\", this.owner.mem8[ins], this.owner.mem8[ins + 1], this.owner.mem8[ins + 2], this.owner.mem8[ins + 3]);\n console.log(\"hdr.type\", this.owner.mem8[ins + 4], this.owner.mem8[ins + 5]);\n console.log(\"next 4 bytes\", this.owner.mem8[ins + 6], this.owner.mem8[ins + 7], this.owner.mem8[ins + 8], this.owner.mem8[ins + 9]);\n console.log(\"and 4 more \", this.owner.mem8[ins + 10], this.owner.mem8[ins + 11], this.owner.mem8[ins + 12], this.owner.mem8[ins + 13]);\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\n }\n switch (type) {\n case D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case D2DType.D2D_BEGINPATH:\n {\n this.ctx.beginPath();\n }\n break;\n case D2DType.D2D_FILL:\n {\n this.ctx.fill();\n }\n break;\n case D2DType.D2D_SAVE:\n {\n this.ctx.save();\n }\n break;\n case D2DType.D2D_RESTORE:\n {\n this.ctx.restore();\n }\n break;\n case D2DType.D2D_STROKE:\n {\n this.ctx.stroke();\n }\n break;\n case D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = (this.owner.getLong(ins + 48) != 0);\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n }\n else { // Uint8ClampedArray doesn't support shared memory\n this.precomputedObjects[id] = { mem8: new Uint8Array(this.owner.memory.buffer, start, length), width: width, height: height };\n }\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id])\n delete this.precomputedObjects[id];\n else\n console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) {\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n }\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) {\n this.ctx.putImageData(imgData, dx, dy);\n }\n else {\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */\n if (next == 0) {\n if (ins != lastins)\n throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal)\n this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nexport class twrCanvasProxy {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner) {\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new twrSignal(signalBuffer);\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\"drawseq\", [ds]]);\n this.drawCompleteSignal.wait();\n }\n}\n//# sourceMappingURL=twrcanvas.js.map","import {twrWasmModuleBase, IModParams} from \"./twrmodbase.js\"\r\nimport {twrSharedCircularBuffer} from \"./twrcircular.js\";\r\nimport {twrSignal} from \"./twrsignal.js\";\r\n\r\n\r\n// Canvas have a size that will be set based on the character width x height\r\n// The display size for a canvas will default to this size, but can be changed in the HTML/JS via\r\n// canvas.style.width = \"700px\";\r\n// canvas.style.height = \"500px\";\r\n\r\nexport interface ICanvasProps {\r\n\tcharWidth: number,\r\n\tcharHeight: number,\r\n\tforeColor: number,\r\n\tbackColor: number,\r\n widthInChars: number,\r\n heightInChars: number,\r\n canvasWidth:number,\r\n canvasHeight:number\r\n}\r\n\r\nenum D2DType {\r\n D2D_FILLRECT=1,\r\n D2D_FILLCHAR=5,\r\n D2D_SETLINEWIDTH=10,\r\n D2D_SETFILLSTYLERGBA=11,\r\n D2D_SETFONT=12,\r\n D2D_BEGINPATH=13,\r\n D2D_MOVETO=14,\r\n D2D_LINETO=15,\r\n D2D_FILL=16,\r\n D2D_STROKE=17,\r\n D2D_SETSTROKESTYLERGBA=18,\r\n D2D_ARC=19,\r\n D2D_STROKERECT=20,\r\n D2D_FILLTEXT=21,\r\n D2D_IMAGEDATA=22,\r\n D2D_PUTIMAGEDATA=23,\r\n D2D_BEZIERTO=24,\r\n D2D_MEASURETEXT=25,\r\n D2D_SAVE=26,\r\n D2D_RESTORE=27,\r\n D2D_CREATERADIALGRADIENT=28,\r\n D2D_SETCOLORSTOP=29,\r\n D2D_SETFILLSTYLEGRADIENT=30,\r\n D2D_RELEASEID=31,\r\n D2D_CREATELINEARGRADIENT=32,\r\n D2D_SETFILLSTYLE=33,\r\n D2D_SETSTROKESTYLE=34\r\n\r\n}\r\n\r\nexport type TCanvasProxyParams = [ICanvasProps, SharedArrayBuffer, SharedArrayBuffer];\r\n\r\nexport interface ICanvas {\r\n props: ICanvasProps,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TCanvasProxyParams,\r\n drawSeq: (ds:number)=>void,\r\n }\r\n \r\nexport class twrCanvas implements ICanvas {\r\n ctx:CanvasRenderingContext2D|undefined;\r\n props:ICanvasProps={charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight:0, canvasWidth:0};\r\n owner: twrWasmModuleBase;\r\n cmdCompleteSignal?:twrSignal;\r\n canvasKeys?: twrSharedCircularBuffer;\r\n precomputedObjects: { [index: number]: \r\n (ImageData | {mem8:Uint8Array, width:number, height:number}) |\r\n CanvasGradient\r\n };\r\n\r\n constructor(element:HTMLCanvasElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n const {forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas} = modParams; \r\n this.owner=modbase;\r\n this.props.widthInChars=modParams.windim[0];\r\n this.props.heightInChars=modParams.windim[1];\r\n\r\n if (!this.owner.isWasmModule) {\r\n this.cmdCompleteSignal=new twrSignal();\r\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n }\r\n\r\n this.precomputedObjects={};\r\n \r\n if (element) {\r\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\r\n let c=element.getContext(\"2d\");\r\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\r\n\r\n c.font = fontsize.toString()+\"px Courier New\";\r\n c.textBaseline=\"top\";\r\n const sampleText=\" \";\r\n const tm=c.measureText(sampleText);\r\n this.props.charWidth=Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\r\n let fM = c.measureText(\"X\"); \r\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\r\n\r\n if (!isd2dcanvas) {\r\n element.width=this.props.charWidth*this.props.widthInChars;\r\n element.height=this.props.charHeight*this.props.heightInChars;\r\n }\r\n\r\n this.props.canvasHeight=element.height;\r\n this.props.canvasWidth=element.width;\r\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\r\n\r\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\r\n let c2=element.getContext(\"2d\");\r\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\r\n this.ctx=c2;\r\n this.ctx.font = fontsize.toString()+\"px Courier New\";\r\n this.ctx.textBaseline=\"top\";\r\n\r\n c2.fillStyle=backcolor;\r\n this.props.backColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n c2.fillStyle=forecolor;\r\n this.props.foreColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n }\r\n\r\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\r\n\r\n //console.log(\"twrCanvas.constructor props: \", this.props);\r\n }\r\n\r\n isValid() {\r\n return !!this.ctx;\r\n }\r\n\r\n getProxyParams() : TCanvasProxyParams {\r\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\r\n }\r\n\r\n getProp(pn:number): number {\r\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n\r\n/* see draw2d.h for structs that match */\r\n\r\n drawSeq(ds:number) {\r\n //console.log(\"twr::Canvas enter drawSeq\");\r\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\r\n if (!this.ctx) return;\r\n\r\n let ins=this.owner.getLong(ds); /* ds->start */\r\n const lastins=this.owner.getLong(ds+4); /* ds->last */\r\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\r\n\r\n let next:number;\r\n //let insCount=0;\r\n\r\n while (1) {\r\n\r\n //insCount++;\r\n\r\n const type:D2DType=this.owner.getLong(ins+4); /* hdr->type */\r\n if (0/*type!=D2DType.D2D_FILLRECT*/) {\r\n console.log(\"ins\",ins)\r\n console.log(\"hdr.next\",this.owner.mem8[ins],this.owner.mem8[ins+1],this.owner.mem8[ins+2],this.owner.mem8[ins+3]);\r\n console.log(\"hdr.type\",this.owner.mem8[ins+4],this.owner.mem8[ins+5]);\r\n console.log(\"next 4 bytes\", this.owner.mem8[ins+6],this.owner.mem8[ins+7],this.owner.mem8[ins+8],this.owner.mem8[ins+9]);\r\n console.log(\"and 4 more \", this.owner.mem8[ins+10],this.owner.mem8[ins+11],this.owner.mem8[ins+12],this.owner.mem8[ins+13]);\r\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\r\n }\r\n switch (type) {\r\n case D2DType.D2D_FILLRECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.fillRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKERECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.strokeRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILLCHAR:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const c=this.owner.getShort(ins+24);\r\n let txt=String.fromCharCode(c);\r\n this.ctx.fillText(txt, x, y);\r\n }\r\n break;\r\n\r\n \r\n case D2DType.D2D_FILLTEXT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const str=this.owner.getString(this.owner.getLong(ins+24));\r\n\r\n //console.log(\"filltext \",x,y,str)\r\n \r\n this.ctx.fillText(str, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MEASURETEXT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n const tmidx=this.owner.getLong(ins+12);\r\n \r\n const tm=this.ctx.measureText(str);\r\n this.owner.setDouble(tmidx+0, tm.actualBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+8, tm.actualBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+16, tm.actualBoundingBoxLeft);\r\n this.owner.setDouble(tmidx+24, tm.actualBoundingBoxRight);\r\n this.owner.setDouble(tmidx+32, tm.fontBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+40, tm.fontBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+48, tm.width);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFONT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.font=str;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.fillStyle = cssColor;\r\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETSTROKESTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.fillStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETSTROKESTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETLINEWIDTH:\r\n {\r\n const width=this.owner.getShort(ins+8); \r\n this.ctx.lineWidth=width;\r\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MOVETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.moveTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_LINETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.lineTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEZIERTO:\r\n {\r\n const cp1x=this.owner.getDouble(ins+8);\r\n const cp1y=this.owner.getDouble(ins+16);\r\n const cp2x=this.owner.getDouble(ins+24);\r\n const cp2y=this.owner.getDouble(ins+32);\r\n const x=this.owner.getDouble(ins+40);\r\n const y=this.owner.getDouble(ins+48);\r\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEGINPATH:\r\n {\r\n this.ctx.beginPath();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILL:\r\n {\r\n this.ctx.fill();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SAVE:\r\n {\r\n this.ctx.save();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_RESTORE:\r\n {\r\n this.ctx.restore();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKE:\r\n {\r\n this.ctx.stroke();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_ARC:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const radius=this.owner.getDouble(ins+24);\r\n const startAngle=this.owner.getDouble(ins+32);\r\n const endAngle=this.owner.getDouble(ins+40);\r\n const counterClockwise= (this.owner.getLong(ins+48)!=0);\r\n\r\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_IMAGEDATA:\r\n {\r\n const start=this.owner.getLong(ins+8);\r\n const length=this.owner.getLong(ins+12);\r\n const width=this.owner.getLong(ins+16);\r\n const height=this.owner.getLong(ins+20);\r\n const id=this.owner.getLong(ins+24);\r\n\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\r\n\r\n if (this.owner.isWasmModule) {\r\n const z = new Uint8ClampedArray(this.owner.memory!.buffer, start, length);\r\n this.precomputedObjects[id]=new ImageData(z, width, height);\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory\r\n this.precomputedObjects[id]={mem8: new Uint8Array(this.owner.memory!.buffer, start, length), width:width, height:height};\r\n }\r\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_CREATERADIALGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const radius0=this.owner.getDouble(ins+24);\r\n const x1=this.owner.getDouble(ins+32);\r\n const y1=this.owner.getDouble(ins+40);\r\n const radius1=this.owner.getDouble(ins+48);\r\n const id= this.owner.getLong(ins+56);\r\n\r\n let gradient=this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_CREATELINEARGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const x1=this.owner.getDouble(ins+24);\r\n const y1=this.owner.getDouble(ins+32);\r\n const id= this.owner.getLong(ins+40);\r\n \r\n let gradient=this.ctx.createLinearGradient(x0, y0, x1, y1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETCOLORSTOP:\r\n {\r\n const id = this.owner.getLong(ins+8);\r\n const pos=this.owner.getLong(ins+12);\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+16));\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n gradient.addColorStop(pos, cssColor);\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n this.ctx.fillStyle=gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_RELEASEID:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (this.precomputedObjects[id])\r\n delete this.precomputedObjects[id];\r\n else\r\n console.log(\"warning: D2D_RELEASEID with undefined ID \",id);\r\n }\r\n break\r\n\r\n \r\n\r\n case D2DType.D2D_PUTIMAGEDATA:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n const dx=this.owner.getLong(ins+12);\r\n const dy=this.owner.getLong(ins+16);\r\n const dirtyX=this.owner.getLong(ins+20);\r\n const dirtyY=this.owner.getLong(ins+24);\r\n const dirtyWidth=this.owner.getLong(ins+28);\r\n const dirtyHeight=this.owner.getLong(ins+32);\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \"+id);\r\n\r\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\r\n\r\n let imgData:ImageData;\r\n if (this.owner.isWasmModule) {\r\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\r\n imgData=this.precomputedObjects[id] as ImageData;\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\r\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\r\n const z = this.precomputedObjects[id] as {mem8:Uint8Array, width:number, height:number}; // Uint8Array\r\n const ca=Uint8ClampedArray.from(z.mem8); // shallow copy\r\n imgData=new ImageData(ca, z.width, z.height);\r\n }\r\n \r\n if (dirtyWidth==0 && dirtyHeight==0) {\r\n this.ctx.putImageData(imgData, dx, dy);\r\n }\r\n else {\r\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\r\n }\r\n }\r\n break;\r\n\r\n default:\r\n throw new Error (\"unimplemented or unknown Sequence Type in drawSeq: \"+type);\r\n }\r\n next=this.owner.getLong(ins); /* hdr->next */\r\n if (next==0) {\r\n if (ins!=lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\r\n break;\r\n }\r\n ins=next;\r\n }\r\n\r\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\r\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\r\n }\r\n}\r\n\r\nexport class twrCanvasProxy implements ICanvas {\r\n canvasKeys: twrSharedCircularBuffer;\r\n drawCompleteSignal:twrSignal;\r\n props: ICanvasProps;\r\n owner: twrWasmModuleBase;\r\n\r\n constructor(params:TCanvasProxyParams, owner:twrWasmModuleBase) {\r\n const [props, signalBuffer, canvasKeysBuffer] = params;\r\n this.drawCompleteSignal = new twrSignal(signalBuffer);\r\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\r\n this.props=props;\r\n this.owner=owner;\r\n\r\n //console.log(\"Create New twrCanvasProxy: \",this.props)\r\n\r\n }\r\n\r\n charIn() { \r\n //ctx.commit(); not avail in chrome\r\n \r\n //postMessage([\"debug\", 'x']);\r\n \r\n return this.canvasKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.canvasKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n getProp(pn:number): number {\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n \r\n drawSeq(ds:number) {\r\n this.drawCompleteSignal.reset();\r\n postMessage([\"drawseq\", [ds]]);\r\n this.drawCompleteSignal.wait();\r\n }\r\n}\r\n","//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar twrSignalState;\n(function (twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})(twrSignalState || (twrSignalState = {}));\n;\nexport class twrSignal {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window valid\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == twrSignalState.WAITING) {\n //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\n //console.log(\"released...\");\n }\n }\n isSignaled() {\n return this.buf[0] == twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = twrSignalState.WAITING;\n }\n}\n//# sourceMappingURL=twrsignal.js.map","//\r\n// This class implements a simple signal/wait mechanism\r\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\r\n//\r\n\r\nenum twrSignalState {\r\n WAITING=0,\r\n SIGNALED=1\r\n};\r\n\r\nexport class twrSignal {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n\r\n \tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window valid\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) \r\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[0]=twrSignalState.WAITING;\r\n\t}\r\n\r\n\tsignal() {\r\n this.buf[0]=twrSignalState.SIGNALED; \r\n //console.log(\"about to signal\");\r\n Atomics.notify(this.buf, 0); \r\n\t}\r\n\r\n wait() {\r\n if (this.buf[0]==twrSignalState.WAITING) {\r\n //console.log(\"waiting...\");\r\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\r\n //console.log(\"released...\");\r\n\r\n }\r\n\t}\r\n isSignaled():boolean {\r\n return this.buf[0]==twrSignalState.SIGNALED;\r\n }\r\n\r\n reset() {\r\n this.buf[0]=twrSignalState.WAITING;\r\n }\r\n}\r\n","export function twrTimeImpl() {\n return Date.now();\n}\n//# sourceMappingURL=twrdate.js.map","\r\nexport function twrTimeImpl() {\r\n\r\n return Date.now();\r\n\r\n}","import { twrDebugLogImpl } from \"./twrdebug.js\";\nimport { twrWasmModuleInJSMain } from \"./twrmodjsmain.js\";\nimport { twrWaitingCalls } from \"./twrwaitingcalls.js\";\nimport whatkey from \"whatkey\";\nexport class twrWasmModuleAsync extends twrWasmModuleInJSMain {\n myWorker;\n malloc;\n loadWasmResolve;\n loadWasmReject;\n executeCResolve;\n executeCReject;\n initLW = false;\n waitingcalls;\n constructor(opts) {\n super(opts);\n this.malloc = (size) => { throw new Error(\"Error - un-init malloc called.\"); };\n if (!window.Worker)\n throw new Error(\"This browser doesn't support web workers.\");\n this.myWorker = new Worker(new URL('twrmodworker.js', import.meta.url), { type: \"module\" });\n this.myWorker.onmessage = this.processMsg.bind(this);\n }\n // overrides base implementation\n async loadWasm(pathToLoad) {\n if (this.initLW)\n throw new Error(\"twrWasmAsyncModule::loadWasm can only be called once per twrWasmAsyncModule instance\");\n this.initLW = true;\n return new Promise((resolve, reject) => {\n this.loadWasmResolve = resolve;\n this.loadWasmReject = reject;\n this.malloc = (size) => {\n return this.executeCImpl(\"twr_malloc\", [size]);\n };\n this.waitingcalls = new twrWaitingCalls(); // handle's calls that cross the worker thread - main js thread boundary\n let canvas;\n if (this.d2dcanvas.isValid())\n canvas = this.d2dcanvas;\n else\n canvas = this.iocanvas;\n const modWorkerParams = {\n divProxyParams: this.iodiv.getProxyParams(),\n canvasProxyParams: canvas.getProxyParams(),\n waitingCallsProxyParams: this.waitingcalls.getProxyParams(),\n };\n const urlToLoad = new URL(pathToLoad, document.URL);\n const startMsg = { urlToLoad: urlToLoad.href, modWorkerParams: modWorkerParams, modParams: this.modParams };\n this.myWorker.postMessage(['startup', startMsg]);\n });\n }\n async executeC(params) {\n const cparams = await this.preCallC(params); // will also validate params[0]\n return this.executeCImpl(params[0], cparams);\n }\n async executeCImpl(fname, cparams = []) {\n return new Promise((resolve, reject) => {\n this.executeCResolve = resolve;\n this.executeCReject = reject;\n this.myWorker.postMessage(['executeC', fname, cparams]);\n });\n }\n // this function should be called from HTML \"keydown\" event from
\n keyDownDiv(ev) {\n if (!this.iodiv || !this.iodiv.divKeys)\n throw new Error(\"unexpected undefined twrWasmAsyncModule.divKeys\");\n this.iodiv.divKeys.write(whatkey(ev).char.charCodeAt(0));\n }\n // this function should be called from HTML \"keydown\" event from \n keyDownCanvas(ev) {\n if (!this.iocanvas || !this.iocanvas.canvasKeys)\n throw new Error(\"unexpected undefined twrWasmAsyncModule.canvasKeys\");\n this.iocanvas.canvasKeys.write(whatkey(ev).char.charCodeAt(0));\n }\n processMsg(event) {\n const msgType = event.data[0];\n const d = event.data[1];\n //console.log(\"twrWasmAsyncModule - got message: \"+event.data)\n switch (msgType) {\n case \"divout\":\n if (this.iodiv.isValid())\n this.iodiv.charOut(d);\n else\n console.log('error - msg divout received but iodiv is undefined.');\n break;\n case \"debug\":\n twrDebugLogImpl(d);\n break;\n case \"drawseq\":\n {\n //console.log(\"twrModAsync got message drawseq\");\n const [ds] = d;\n if (this.iocanvas.isValid())\n this.iocanvas.drawSeq(ds);\n else if (this.d2dcanvas.isValid())\n this.d2dcanvas.drawSeq(ds);\n else\n throw new Error('msg drawseq received but canvas is undefined.');\n break;\n }\n case \"setmemory\":\n this.memory = d;\n if (!this.memory)\n throw new Error(\"unexpected error - undefined memory in startupOkay msg\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n //console.log(\"memory set\",this.mem8.length);\n break;\n case \"startupFail\":\n if (this.loadWasmReject)\n this.loadWasmReject(d);\n else\n throw new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmReject)\");\n break;\n case \"startupOkay\":\n if (this.loadWasmResolve)\n this.loadWasmResolve(undefined);\n else\n throw new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmResolve)\");\n break;\n case \"executeCFail\":\n if (this.executeCReject)\n this.executeCReject(d);\n else\n throw new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined executeCReject)\");\n break;\n case \"executeCOkay\":\n if (this.executeCResolve)\n this.executeCResolve(d);\n else\n throw new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined executeCResolve)\");\n break;\n default:\n if (!this.waitingcalls)\n throw new Error(\"internal error: this.waitingcalls undefined.\");\n if (!this.waitingcalls.processMessage(msgType, d))\n throw new Error(\"twrWasmAsyncModule - unknown and unexpected msgType: \" + msgType);\n }\n }\n}\n//# sourceMappingURL=twrmodasync.js.map","import {IModOpts, IModParams, IModInWorkerParams} from \"./twrmodbase.js\";\r\nimport {twrDebugLogImpl} from \"./twrdebug.js\";\r\nimport {twrWasmModuleInJSMain} from \"./twrmodjsmain.js\"\r\nimport {twrWaitingCalls} from \"./twrwaitingcalls.js\"\r\nimport {twrCanvas} from \"./twrcanvas.js\";\r\n\r\nimport whatkey from \"whatkey\";\r\n\r\nexport type TAsyncModStartupMsg = {\r\n\turlToLoad: string,\r\n\tmodWorkerParams: IModInWorkerParams,\r\n\tmodParams: IModParams \r\n};\r\n\t\t\r\nexport class twrWasmModuleAsync extends twrWasmModuleInJSMain {\r\n\tmyWorker:Worker;\r\n\tmalloc:(size:number)=>Promise;\r\n\tloadWasmResolve?: (value: void) => void;\r\n\tloadWasmReject?: (reason?: any) => void;\r\n\texecuteCResolve?: (value: unknown) => void;\r\n\texecuteCReject?: (reason?: any) => void;\r\n\tinitLW=false;\r\n\twaitingcalls?:twrWaitingCalls;\r\n\r\n\r\n\tconstructor(opts?:IModOpts) {\r\n\t\tsuper(opts);\r\n\r\n\t\tthis.malloc=(size:number)=>{throw new Error(\"Error - un-init malloc called.\")};\r\n\r\n\t\tif (!window.Worker) throw new Error(\"This browser doesn't support web workers.\");\r\n\t\tthis.myWorker = new Worker(new URL('twrmodworker.js', import.meta.url), {type: \"module\" });\r\n\t\tthis.myWorker.onmessage= this.processMsg.bind(this);\r\n\t}\r\n\r\n\t// overrides base implementation\r\n\tasync loadWasm(pathToLoad:string) {\r\n\t\tif (this.initLW) \tthrow new Error(\"twrWasmAsyncModule::loadWasm can only be called once per twrWasmAsyncModule instance\");\r\n\t\tthis.initLW=true;\r\n\r\n\t\treturn new Promise((resolve, reject)=>{\r\n\t\t\tthis.loadWasmResolve=resolve;\r\n\t\t\tthis.loadWasmReject=reject;\r\n\r\n\t\t\tthis.malloc = (size:number) => {\r\n\t\t\t\treturn this.executeCImpl(\"twr_malloc\", [size]) as Promise;\r\n\t\t\t}\r\n\r\n\t\t\tthis.waitingcalls=new twrWaitingCalls(); // handle's calls that cross the worker thread - main js thread boundary\r\n\r\n\t\t\tlet canvas:twrCanvas;\r\n\t\t\tif (this.d2dcanvas.isValid()) canvas=this.d2dcanvas;\r\n\t\t\telse canvas=this.iocanvas;\r\n\r\n\t\t\tconst modWorkerParams={\r\n\t\t\t\tdivProxyParams: this.iodiv.getProxyParams(), \r\n\t\t\t\tcanvasProxyParams: canvas.getProxyParams(),\r\n\t\t\t\twaitingCallsProxyParams: this.waitingcalls.getProxyParams(),\r\n\t\t\t};\r\n\t\t\tconst urlToLoad = new URL(pathToLoad, document.URL);\r\n\t\t\tconst startMsg:TAsyncModStartupMsg={ urlToLoad: urlToLoad.href, modWorkerParams: modWorkerParams, modParams: this.modParams};\r\n\t\t\tthis.myWorker.postMessage(['startup', startMsg]);\r\n\t\t});\r\n\t}\r\n\r\n\tasync executeC(params:[string, ...(string|number|Uint8Array)[]]) {\r\n\t\tconst cparams=await this.preCallC(params); // will also validate params[0]\r\n\t\treturn this.executeCImpl(params[0], cparams);\r\n\t}\t\r\n\r\n\tasync executeCImpl(fname:string, cparams:number[]=[]) {\r\n\t\treturn new Promise((resolve, reject)=>{\r\n\t\t\tthis.executeCResolve=resolve;\r\n\t\t\tthis.executeCReject=reject;\r\n\t\t\tthis.myWorker.postMessage(['executeC', fname, cparams]);\r\n\t\t});\r\n\t}\r\n\t\r\n\t// this function should be called from HTML \"keydown\" event from
\r\n\tkeyDownDiv(ev:KeyboardEvent) {\r\n\t\tif (!this.iodiv || !this.iodiv.divKeys) throw new Error(\"unexpected undefined twrWasmAsyncModule.divKeys\");\r\n\t\tthis.iodiv.divKeys.write(whatkey(ev).char.charCodeAt(0));\r\n\t}\r\n\r\n\t// this function should be called from HTML \"keydown\" event from \r\n\tkeyDownCanvas(ev:KeyboardEvent) {\r\n\t\tif (!this.iocanvas || !this.iocanvas.canvasKeys) throw new Error(\"unexpected undefined twrWasmAsyncModule.canvasKeys\");\r\n\t\tthis.iocanvas.canvasKeys.write(whatkey(ev).char.charCodeAt(0));\r\n\t}\r\n\r\n\tprocessMsg(event: MessageEvent) {\r\n\t\tconst msgType=event.data[0];\r\n\t\tconst d=event.data[1];\r\n\r\n\t\t//console.log(\"twrWasmAsyncModule - got message: \"+event.data)\r\n\r\n\t\tswitch (msgType) {\r\n\t\t\tcase \"divout\":\r\n\t\t\t\tif (this.iodiv.isValid())\r\n\t\t\t\t\tthis.iodiv.charOut(d);\r\n\t\t\t\telse\r\n\t\t\t\t\tconsole.log('error - msg divout received but iodiv is undefined.')\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"debug\":\r\n\t\t\t\ttwrDebugLogImpl(d);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"drawseq\":\r\n\t\t\t{\r\n\t\t\t\t//console.log(\"twrModAsync got message drawseq\");\r\n\t\t\t\tconst [ds] = d;\r\n\t\t\t\tif (this.iocanvas.isValid())\r\n\t\t\t\t\tthis.iocanvas.drawSeq(ds);\r\n\t\t\t\telse if (this.d2dcanvas.isValid())\r\n\t\t\t\t\tthis.d2dcanvas.drawSeq(ds);\r\n\t\t\t\telse\r\n\t\t\t\t\tthrow new Error('msg drawseq received but canvas is undefined.')\r\n\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\t\tcase \"setmemory\":\r\n\t\t\t\tthis.memory=d;\r\n\t\t\t\tif (!this.memory) throw new Error(\"unexpected error - undefined memory in startupOkay msg\");\r\n\t\t\t\tthis.mem8 = new Uint8Array(this.memory.buffer);\r\n\t\t\t\tthis.mem32 = new Uint32Array(this.memory.buffer);\r\n\t\t\t\tthis.memD = new Float64Array(this.memory.buffer);\r\n\t\t\t\t//console.log(\"memory set\",this.mem8.length);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"startupFail\":\r\n\t\t\t\tif (this.loadWasmReject)\r\n\t\t\t\t\tthis.loadWasmReject(d);\r\n\t\t\t\telse\r\n\t\t\t\t\tthrow new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmReject)\");\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"startupOkay\":\r\n\r\n\t\t\t\tif (this.loadWasmResolve)\r\n\t\t\t\t\tthis.loadWasmResolve(undefined);\r\n\t\t\t\telse\r\n\t\t\t\t\tthrow new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmResolve)\");\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"executeCFail\":\r\n\t\t\t\tif (this.executeCReject)\r\n\t\t\t\t\tthis.executeCReject(d);\r\n\t\t\t\telse\r\n\t\t\t\t\tthrow new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined executeCReject)\");\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"executeCOkay\":\r\n\t\t\t\tif (this.executeCResolve)\r\n\t\t\t\t\tthis.executeCResolve(d);\r\n\t\t\t\telse\r\n\t\t\t\t\tthrow new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined executeCResolve)\");\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tdefault:\r\n\t\t\t\tif (!this.waitingcalls) throw new Error (\"internal error: this.waitingcalls undefined.\")\r\n\t\t\t\tif (!this.waitingcalls.processMessage(msgType, d))\r\n\t\t\t\t\tthrow new Error(\"twrWasmAsyncModule - unknown and unexpected msgType: \"+msgType);\r\n\t\t}\r\n\t}\r\n}\r\n","import { twrSignal } from \"./twrsignal.js\";\nimport { twrTimeImpl } from \"./twrdate.js\";\n// This class is used in the Main JS thread \nexport class twrWaitingCalls {\n callCompleteSignal;\n parameters;\n constructor() {\n this.callCompleteSignal = new twrSignal();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(() => {\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = twrTimeImpl();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [this.callCompleteSignal.sharedArray, this.parameters.buffer];\n }\n processMessage(msgType, data) {\n switch (msgType) {\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\n// This class is used in the worker thread \nexport class twrWaitingCallsProxy {\n callCompleteSignal;\n parameters;\n constructor(params) {\n this.callCompleteSignal = new twrSignal(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\"sleep\", [ms]]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\"time\"]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n//# sourceMappingURL=twrwaitingcalls.js.map","import { twrSignal } from \"./twrsignal.js\";\r\nimport {twrTimeImpl} from \"./twrdate.js\"\r\n\r\n// These classes are used to proxy a call across the worker thread - main thread boundary and wait for the result\r\n\r\nexport type TWaitingCallsProxyParams = [SharedArrayBuffer, SharedArrayBuffer]; // twrSignal, parameters \r\n\r\n// This class is used in the Main JS thread \r\nexport class twrWaitingCalls {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor() {\r\n\t\tthis.callCompleteSignal=new twrSignal();\r\n\t\tthis.parameters=new Uint32Array(new SharedArrayBuffer(4));\r\n\t}\r\n\r\n\tprivate startSleep(ms:number) {\r\n\r\n\t\tsetTimeout(()=>{\r\n\t\t\tthis.callCompleteSignal.signal();\r\n\t\t}, ms);\r\n\t\t\r\n\t}\r\n\r\n\tprivate time() {\r\n\t\tconst ms=twrTimeImpl();\r\n\t\tthis.parameters[0]=ms;\r\n\t\tthis.callCompleteSignal.signal();\r\n\t}\r\n\r\n\tgetProxyParams():TWaitingCallsProxyParams {\r\n\t\treturn [this.callCompleteSignal.sharedArray, this.parameters.buffer as SharedArrayBuffer];\t\r\n\t}\r\n\r\n\tprocessMessage(msgType:string, data:any[]):boolean {\r\n\t\tswitch (msgType) {\r\n\t\t\tcase \"sleep\":\r\n\t\t\t\tconst [ms] = data;\r\n\t\t\t\tthis.startSleep(ms);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"time\":\r\n\t\t\t\tthis.time();\r\n\t\t\t\tbreak;\r\n\t\t\t\r\n\t\t\tdefault:\r\n\t\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\treturn true;\r\n\t}\r\n\r\n}\r\n\r\n// This class is used in the worker thread \r\nexport class twrWaitingCallsProxy {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor(params:TWaitingCallsProxyParams) {\r\n\t\tthis.callCompleteSignal=new twrSignal(params[0]);\r\n\t\tthis.parameters=new Uint32Array(params[1]);\r\n\t}\r\n\r\n\tsleep(ms:number) {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"sleep\", [ms]]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t}\r\n\r\n\ttime() {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"time\"]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t\treturn this.parameters[0];\r\n\t}\r\n\r\n}\r\n","const keycodeCtrlKeys = {\n 'a': 'selectAll',\n 'c': 'copy',\n 's': 'save',\n 'v': 'paste',\n 'x': 'cut',\n 'y': 'redo',\n 'z': 'undo'\n};\n\nconst keycodeShiftedKeys = {\n '/': '?',\n '.': '>',\n ',': '<',\n '\\'': '\\\"',\n ';': ':',\n '[': '{',\n ']': '}',\n '\\\\': '|',\n '`': '~',\n '=': '+',\n '-': '_',\n '1': '!',\n '2': '@',\n '3': '#',\n '4': '$',\n '5': '%',\n '6': '^',\n '7': '&',\n '8': '*',\n '9': '(',\n '0': ')',\n 'a': 'A',\n 'b': 'B',\n 'c': 'C',\n 'd': 'D',\n 'e': 'E',\n 'f': 'F',\n 'g': 'G',\n 'h': 'H',\n 'i': 'I',\n 'j': 'J',\n 'k': 'K',\n 'l': 'L',\n 'm': 'M',\n 'n': 'N',\n 'o': 'O',\n 'p': 'P',\n 'q': 'q',\n 'r': 'R',\n 's': 'S',\n 't': 'T',\n 'u': 'U',\n 'v': 'V',\n 'w': 'W',\n 'x': 'X',\n 'y': 'Y',\n 'z': 'Z'\n};\n\nconst keyCodeUnshiftedKeys = {};\nfor (const x in keycodeShiftedKeys) {\n const shiftedKey = keycodeShiftedKeys[x];\n keyCodeUnshiftedKeys[shiftedKey] = x;\n}\n\nconst keydownKeycodeDictionary = {\n 0: '\\\\',\n\n 8: 'backspace',\n 9: 'tab',\n\n 12: 'num',\n 13: 'enter',\n\n 16: 'shift',\n 17: 'ctrl',\n 18: 'alt', // aka 'option'\n 19: 'pause', // or sometimes 'break'?\n 20: 'caps',\n\n 27: 'esc',\n\n 32: ' ',\n 33: 'pageup',\n 34: 'pagedown',\n 35: 'end',\n 36: 'home',\n 37: 'left',\n 38: 'up',\n 39: 'right',\n 40: 'down',\n\n 44: 'print',\n 45: 'insert',\n 46: 'delete',\n\n 48: '0',\n 49: '1',\n 50: '2',\n 51: '3',\n 52: '4',\n 53: '5',\n 54: '6',\n 55: '7',\n 56: '8',\n 57: '9',\n\n 59: ';',\n\n 61: '=',\n\n 65: 'a',\n 66: 'b',\n 67: 'c',\n 68: 'd',\n 69: 'e',\n 70: 'f',\n 71: 'g',\n 72: 'h',\n 73: 'i',\n 74: 'j',\n 75: 'k',\n 76: 'l',\n 77: 'm',\n 78: 'n',\n 79: 'o',\n 80: 'p',\n 81: 'q',\n 82: 'r',\n 83: 's',\n 84: 't',\n 85: 'u',\n 86: 'v',\n 87: 'w',\n 88: 'x',\n 89: 'y',\n 90: 'z',\n 91: 'meta', // 'left window key'\n 92: 'meta', // 'right window key'\n 93: 'meta', // 'select key'\n\n 96: 'num0',\n 97: 'num1',\n 98: 'num2',\n 99: 'num3',\n 100: 'num4',\n 101: 'num5',\n 102: 'num6',\n 103: 'num7',\n 104: 'num8',\n 105: 'num9',\n 106: '*',\n 107: '+',\n 108: 'num_enter',\n 109: 'num_subtract',\n 110: 'num_decimal',\n 111: 'num_divide',\n 112: 'f1',\n 113: 'f2',\n 114: 'f3',\n 115: 'f4',\n 116: 'f5',\n 117: 'f6',\n 118: 'f7',\n 119: 'f8',\n 120: 'f9',\n 121: 'f10',\n 122: 'f11',\n 123: 'f12',\n 124: 'print',\n\n 144: 'num', // num lock\n 145: 'scroll', // scroll lock\n\n 173: '-',\n\n 186: ';',\n 187: '=',\n 188: ',',\n 189: '-',\n 190: '.',\n 191: '/',\n 192: '`',\n 219: '[',\n 220: '\\\\',\n 221: ']',\n 222: '\\'',\n 223: '`',\n 224: 'cmd',\n 225: 'alt',\n\n 57392: 'ctrl',\n 63289: 'num'\n};\n\nconst keypressCharacterMapOverides = {\n '\\r': 'enter'\n};\nconst keypressCharacterMap = JSON.parse(JSON.stringify(keydownKeycodeDictionary));\nfor (const key of Object.keys(keypressCharacterMapOverides)) {\n keypressCharacterMap[key] = keypressCharacterMapOverides[key];\n}\n\nconst keydownCharacterMap = {\n 'num_subtract': '-',\n 'num_enter': '\\n',\n 'num_decimal': '.',\n 'num_divide': '/',\n 'enter': '\\n',\n 'tab': '\\t',\n 'backspace': '\\b'\n};\n\nexport const unprintableKeys = [\n 'backspace','enter','tab','num',\n 'shift','meta','alt','pause','caps','esc',\n 'pageup','pagedown','end','home',\n 'left','up','right','down',\n 'print','insert','delete','cmd',\n 'f1','f2','f3','f4','f5','f6','f7','f8','f9','f10','f11','f12',\n 'scroll','ctrl'\n];\n\nconst validEvents = ['keydown', 'keyup'];\n\nconst isMobile = () => {\n const ua = navigator.userAgent;\n const mobile = /IEMobile|Windows Phone|Lumia/i.test(ua) ? 'w' : /iPhone|iP[oa]d/.test(ua) ? 'i' : /Android/.test(ua) ? 'a' : /BlackBerry|PlayBook|BB10/.test(ua) ? 'b' : /Mobile Safari/.test(ua) ? 's' : /webOS|Mobile|Tablet|Opera Mini|\\bCrMo\\/|Opera Mobi/i.test(ua) ? 1 : 0;\n return mobile !== 0;\n};\n\nfunction getKeypressKeycodeValue(charcode) {\n const character = String.fromCharCode(charcode);\n if (isMobile()) { return character }\n if (character in keyCodeUnshiftedKeys) {\n return keyCodeUnshiftedKeys[character];\n } else if (character in keypressCharacterMap) {\n return keypressCharacterMap[character];\n }\n return character;\n}\n\nexport default function(event) {\n let key;\n if (event.type === 'keypress' && !isMobile()) {\n key = getKeypressKeycodeValue(event.charCode);\n } else if (event.type === 'keypress' && isMobile()) {\n key = getKeypressKeycodeValue(event.keyCode);\n } else if (validEvents.indexOf(event.type) > -1) {\n if (event.which !== undefined) {\n key = keydownKeycodeDictionary[event.which];\n } else if (event.keyCode !== undefined) {\n key = keydownKeycodeDictionary[event.keyCode];\n } else {\n key = 'enter';\n }\n } else {\n return false;\n }\n\n let char = key;\n if (event.shiftKey && key in keycodeShiftedKeys) {\n char = keycodeShiftedKeys[key];\n } else if (event.ctrlKey && key in keycodeCtrlKeys) {\n char = keycodeCtrlKeys[key];\n } else if (key in keydownCharacterMap) {\n char = keydownCharacterMap[key];\n }\n\n return {\n char,\n key\n };\n}\n","let workerURL = require('./helpers/get-worker-url');\nlet url = new __parcel__URL__(\"twrmodworker.2165e649.js\");\nmodule.exports = workerURL(url.toString(), url.origin, true);","\"use strict\";\n\nmodule.exports = function (workerUrl, origin, isESM) {\n if (origin === self.location.origin) {\n // If the worker bundle's url is on the same origin as the document,\n // use the worker bundle's own url.\n return workerUrl;\n } else {\n // Otherwise, create a blob URL which loads the worker bundle with `importScripts`.\n var source = isESM ? 'import ' + JSON.stringify(workerUrl) + ';' : 'importScripts(' + JSON.stringify(workerUrl) + ');';\n return URL.createObjectURL(new Blob([source], {\n type: 'application/javascript'\n }));\n }\n};","require('./helpers/bundle-manifest').register(new __parcel__URL__(\"\").toString(),JSON.parse(\"[\\\"kjr0c\\\",\\\"index.528b9ee5.js\\\",\\\"cTHdP\\\",\\\"twrmodworker.2165e649.js\\\"]\"));"],"names":["$parcel$export","e","n","v","s","Object","defineProperty","get","set","enumerable","configurable","$parcel$global","globalThis","$parcel$modules","$parcel$inits","parcelRequire","id","exports","init","module","call","err","Error","code","register","parcelRegister","$ae99f86db55f9acd$export$6503ec6e8aabbaf","$ae99f86db55f9acd$var$mapping","Map","baseUrl","manifest","i","length","path","twrWasmModule","twrWasmModuleAsync","$251237c7cf144eb4$export$3298af74d75b595c","$9FI45","$aGUWE","$lsUl2","twrWasmModuleInJSMain","malloc","constructor","opts","canvas","size","d2dcanvas","isValid","iocanvas","modParams","imports","twrDebugLog","twrDebugLogImpl","twrTime","twrTimeImpl","twrDivCharOut","iodiv","charOut","bind","twrCanvasGetProp","getProp","twrCanvasDrawSeq","drawSeq","twrCanvasCharIn","null","twrCanvasInkey","twrDivCharIn","twrSleep","twrSin","Math","sin","twrCos","cos","twrTan","tan","twrFAbs","abs","twrACos","acos","twrASin","asin","twrATan","atan","twrExp","exp","twrFloor","floor","twrCeil","ceil","twrFMod","x","y","twrLog","log","twrPow","pow","twrSqrt","sqrt","twrTrunc","trunc","twrDtoa","floatUtil","dtoa","twrToFixed","toFixed","twrToExponential","toExponential","twrAtod","atod","twrFcvtS","fcvtS","inval","$70aa1fbe63deeaae$export$16b4216ec014493d","$70aa1fbe63deeaae$var$logline","char","console","String","fromCharCode","$7c89ffbd74fdad5b$export$2366c14363f3adb5","$fDEU7","$5hO33","$5LsZ0","twrWasmModuleBase","isWasmModule","document","eiodiv","getElementById","eiocanvas","ed2dcanvas","stdio","isd2dcanvas","windim","styleIsDefault","backcolor","forecolor","fontsize","undefined","twrDiv","twrCanvas","divLog","params","stringOut","toString","$b62a3a4493ce3043$export$dd376bb3f10f6896","$ghrAp","div","divKeys","CURSOR","cursorOn","lastChar","extraBR","owner","element","modbase","twrSharedCircularBuffer","style","backgroundColor","color","font","getProxyParams","sharedArray","ch","innerHTML","slice","p","getBoundingClientRect","window","scrollTo","height","focus","str","charCodeAt","$bda3a1eb26e567b5$export$a01cca24f011573a","buf","sa","crossOriginIsolated","location","protocol","SharedArrayBuffer","Int32Array","write","Atomics","notify","read","isEmpty","readWait","rdptr","wait","$3d955ccf8fb141b7$export$c83a0a3bffe07399","$2Xdsi","memory","mem8","mem32","memD","isWorker","Uint8Array","Uint32Array","Float64Array","twrFloatUtil","loadWasm","pathToLoad","response","fetch","ok","statusText","wasmBytes","arrayBuffer","allimports","instance","WebAssembly","instantiate","env","buffer","ArrayBuffer","postMessage","Promise","resolve","m","twr_malloc","stack","twrInit","twr_wasm_init","executeC","cparams","preCallC","retval","executeCImpl","postCallC","fname","f","Array","ci","putString","URL","r","fetchAndPutURL","putArrayBuffer","u8","j","copyString","buffer_size","strIndex","putU8","u8a","dest","ab","fnin","src","getLong","idx","idx32","setLong","value","getDouble","idx64","setDouble","getShort","getString","len","sout","getU8Arr","rv","dataptr","getU32Arr","$226b87658a7c840f$export$918ffb7e046a537b","mod","strptr","upper","trimStart","toUpperCase","Number","POSITIVE_INFINITY","NEGATIVE_INFINITY","parseFloat","replaceAll","max_precision","toPrecision","decdigits","sizeInBytes","fracpart_numdigits","dec","sign","digits","decpos","isNaN","isFinite","intPart","fracPart","roundValStr","split","replace","$4327d2f23f608609$export$2f298dd69cef3c34","D2DType","$4327d2f23f608609$var$D2DType","$47Wdp","ctx","props","charWidth","charHeight","foreColor","backColor","widthInChars","heightInChars","canvasHeight","canvasWidth","cmdCompleteSignal","canvasKeys","precomputedObjects","twrSignal","getContext","c","textBaseline","sampleText","tm","measureText","width","fM","fontBoundingBoxAscent","fontBoundingBoxDescent","c2","fillStyle","pn","propName","ds","next","ins","lastins","type","D2D_FILLRECT","w","h","fillRect","D2D_STROKERECT","strokeRect","D2D_FILLCHAR","txt","fillText","D2D_FILLTEXT","D2D_MEASURETEXT","tmidx","actualBoundingBoxAscent","actualBoundingBoxDescent","actualBoundingBoxLeft","actualBoundingBoxRight","D2D_SETFONT","D2D_SETFILLSTYLERGBA","cssColor","D2D_SETSTROKESTYLERGBA","strokeStyle","D2D_SETFILLSTYLE","D2D_SETSTROKESTYLE","D2D_SETLINEWIDTH","lineWidth","D2D_MOVETO","moveTo","D2D_LINETO","lineTo","D2D_BEZIERTO","cp1x","cp1y","cp2x","cp2y","bezierCurveTo","D2D_BEGINPATH","beginPath","D2D_FILL","fill","D2D_SAVE","save","D2D_RESTORE","restore","D2D_STROKE","stroke","D2D_ARC","radius","startAngle","endAngle","counterClockwise","arc","D2D_IMAGEDATA","start","z","Uint8ClampedArray","ImageData","D2D_CREATERADIALGRADIENT","x0","y0","radius0","x1","y1","radius1","gradient","createRadialGradient","D2D_CREATELINEARGRADIENT","createLinearGradient","D2D_SETCOLORSTOP","pos","addColorStop","D2D_SETFILLSTYLEGRADIENT","D2D_RELEASEID","D2D_PUTIMAGEDATA","imgData","dx","dy","dirtyX","dirtyY","dirtyWidth","dirtyHeight","from","putImageData","signal","$3014f93b5ceae902$var$twrSignalState","twrSignalState","$3014f93b5ceae902$export$e37a7b7b851b97f3","WAITING","SIGNALED","isSignaled","reset","$fa07ea1a08a5d6be$export$78724cdcf7ebea1d","Date","now","$8227a48f951b1cca$export$678fe6e36ab9a6ff","$2vKdq","$bqeaG","myWorker","loadWasmResolve","loadWasmReject","executeCResolve","executeCReject","initLW","waitingcalls","Worker","onmessage","processMsg","reject","twrWaitingCalls","modWorkerParams","divProxyParams","canvasProxyParams","waitingCallsProxyParams","startMsg","urlToLoad","href","keyDownDiv","ev","default","keyDownCanvas","event","msgType","data","d","processMessage","$1d42537681d02be3$export$9e37856d1928d388","callCompleteSignal","parameters","startSleep","ms","setTimeout","time","$850d1d8f0aa1ea8f$export$2e2bcd8739ae039","$850d1d8f0aa1ea8f$var$keycodeCtrlKeys","$850d1d8f0aa1ea8f$var$keycodeShiftedKeys","$850d1d8f0aa1ea8f$var$keyCodeUnshiftedKeys","$850d1d8f0aa1ea8f$var$keydownKeycodeDictionary","$850d1d8f0aa1ea8f$var$keypressCharacterMapOverides","$850d1d8f0aa1ea8f$var$keypressCharacterMap","JSON","parse","stringify","key","keys","$850d1d8f0aa1ea8f$var$keydownCharacterMap","$850d1d8f0aa1ea8f$var$validEvents","$850d1d8f0aa1ea8f$var$isMobile","ua","navigator","userAgent","mobile","test","$850d1d8f0aa1ea8f$var$getKeypressKeycodeValue","charcode","character","keyCode","indexOf","which","charCode","shiftKey","ctrlKey","$hoqmg","$7e9081fcee88b005$var$url","url","origin","workerUrl","isESM","self","source","createObjectURL","Blob"],"version":3,"file":"index.528b9ee5.js.map"} \ No newline at end of file +{"mappings":"A,S,E,C,C,C,C,C,C,C,E,O,c,C,E,E,C,I,E,I,E,W,C,E,a,C,C,E,C,I,E,W,E,C,E,E,C,E,E,E,iB,A,O,I,A,C,E,S,C,E,G,K,E,O,C,C,E,C,O,C,G,K,E,C,I,E,C,C,E,A,Q,C,C,E,C,I,E,C,G,E,Q,C,C,E,O,C,C,E,C,E,E,I,C,E,O,C,E,E,O,E,E,O,A,C,I,E,A,M,uB,E,I,O,E,I,C,mB,C,C,E,Q,C,S,C,C,C,E,C,C,E,C,C,E,E,iB,C,G,I,E,E,Q,C,E,Q,S,C,C,C,E,E,E,O,C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A,EAAA,SAAA,QAAA,CAA8C,IAAA,IAAoB,GAAA,YAAA,GAAA,EAAI,QAAQ,GAAG,KAAK,KAAK,CAAC","sources":["","../../../../Users/awood/AppData/Roaming/npm/node_modules/parcel/node_modules/@parcel/runtime-js/lib/helpers/bundle-manifest.js","../../source/twr-wasm-ts/index.ts","../../lib-js/twrmod.js","../../source/twr-wasm-ts/twrmod.ts","../../lib-js/twrdebug.js","../../source/twr-wasm-ts/twrdebug.ts","../../lib-js/twrmodjsmain.js","../../source/twr-wasm-ts/twrmodjsmain.ts","../../lib-js/twrdiv.js","../../source/twr-wasm-ts/twrdiv.ts","../../lib-js/twrcircular.js","../../source/twr-wasm-ts/twrcircular.ts","../../lib-js/twrmodbase.js","../../source/twr-wasm-ts/twrmodbase.ts","../../lib-js/twrfloat.js","../../source/twr-wasm-ts/twrfloat.ts","../../lib-js/twrcanvas.js","../../source/twr-wasm-ts/twrcanvas.ts","../../lib-js/twrsignal.js","../../source/twr-wasm-ts/twrsignal.ts","../../lib-js/twrdate.js","../../source/twr-wasm-ts/twrdate.ts","../../lib-js/twrmodasync.js","../../source/twr-wasm-ts/twrmodasync.ts","../../lib-js/twrwaitingcalls.js","../../source/twr-wasm-ts/twrwaitingcalls.ts","../../lib-js/whatkey.js","../../../../Users/awood/AppData/Roaming/npm/node_modules/parcel/node_modules/@parcel/runtime-js/lib/runtime-f762b97648513f2d.js","../../../../Users/awood/AppData/Roaming/npm/node_modules/parcel/node_modules/@parcel/runtime-js/lib/helpers/get-worker-url.js","../../../../Users/awood/AppData/Roaming/npm/node_modules/parcel/node_modules/@parcel/runtime-js/lib/runtime-8b48cd52cfa83e88.js"],"sourcesContent":["\nfunction $parcel$export(e, n, v, s) {\n Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});\n}\n\n var $parcel$global = globalThis;\n \nvar $parcel$modules = {};\nvar $parcel$inits = {};\n\nvar parcelRequire = $parcel$global[\"parcelRequire94c2\"];\n\nif (parcelRequire == null) {\n parcelRequire = function(id) {\n if (id in $parcel$modules) {\n return $parcel$modules[id].exports;\n }\n if (id in $parcel$inits) {\n var init = $parcel$inits[id];\n delete $parcel$inits[id];\n var module = {id: id, exports: {}};\n $parcel$modules[id] = module;\n init.call(module.exports, module, module.exports);\n return module.exports;\n }\n var err = new Error(\"Cannot find module '\" + id + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n };\n\n parcelRequire.register = function register(id, init) {\n $parcel$inits[id] = init;\n };\n\n $parcel$global[\"parcelRequire94c2\"] = parcelRequire;\n}\n\nvar parcelRegister = parcelRequire.register;\nparcelRegister(\"eZoLj\", function(module, exports) {\n\n$parcel$export(module.exports, \"register\", () => $ae99f86db55f9acd$export$6503ec6e8aabbaf, (v) => $ae99f86db55f9acd$export$6503ec6e8aabbaf = v);\nvar $ae99f86db55f9acd$export$6503ec6e8aabbaf;\nvar $ae99f86db55f9acd$export$f7ad0328861e2f03;\n\"use strict\";\nvar $ae99f86db55f9acd$var$mapping = new Map();\nfunction $ae99f86db55f9acd$var$register(baseUrl, manifest) {\n for(var i = 0; i < manifest.length - 1; i += 2)$ae99f86db55f9acd$var$mapping.set(manifest[i], {\n baseUrl: baseUrl,\n path: manifest[i + 1]\n });\n}\nfunction $ae99f86db55f9acd$var$resolve(id) {\n var resolved = $ae99f86db55f9acd$var$mapping.get(id);\n if (resolved == null) throw new Error(\"Could not resolve bundle with id \" + id);\n return new URL(resolved.path, resolved.baseUrl).toString();\n}\n$ae99f86db55f9acd$export$6503ec6e8aabbaf = $ae99f86db55f9acd$var$register;\n$ae99f86db55f9acd$export$f7ad0328861e2f03 = $ae99f86db55f9acd$var$resolve;\n\n});\n\nparcelRegister(\"4mNsm\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrWasmModule\", () => (parcelRequire(\"3bkoq\")).twrWasmModule);\n$parcel$export(module.exports, \"twrWasmModuleAsync\", () => (parcelRequire(\"baOio\")).twrWasmModuleAsync);\n\nvar $3bkoq = parcelRequire(\"3bkoq\");\n\nvar $baOio = parcelRequire(\"baOio\");\n\n});\nparcelRegister(\"3bkoq\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrWasmModule\", () => $251237c7cf144eb4$export$3298af74d75b595c);\n\nvar $9FI45 = parcelRequire(\"9FI45\");\n\nvar $aGUWE = parcelRequire(\"aGUWE\");\n\nvar $lsUl2 = parcelRequire(\"lsUl2\");\nclass $251237c7cf144eb4$export$3298af74d75b595c extends (0, $aGUWE.twrWasmModuleInJSMain) {\n malloc;\n constructor(opts = {}){\n super(opts, true);\n this.malloc = (size)=>{\n throw new Error(\"error - un-init malloc called\");\n };\n let canvas;\n if (this.d2dcanvas.isValid()) canvas = this.d2dcanvas;\n else canvas = this.iocanvas;\n this.modParams.imports = {\n twrDebugLog: (0, $9FI45.twrDebugLogImpl),\n twrTime: (0, $lsUl2.twrTimeImpl),\n twrDivCharOut: this.iodiv.charOut.bind(this.iodiv),\n twrCanvasGetProp: canvas.getProp.bind(canvas),\n twrCanvasDrawSeq: canvas.drawSeq.bind(canvas),\n twrCanvasCharIn: this.null,\n twrCanvasInkey: this.null,\n twrDivCharIn: this.null,\n twrSleep: this.null,\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function(x, y) {\n return x % y;\n },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n null(inval) {\n throw new Error(\"call to unimplemented twrXXX import in twrWasmModule. Use twrWasmModuleAsync ?\");\n }\n}\n\n});\nparcelRegister(\"9FI45\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrDebugLogImpl\", () => $70aa1fbe63deeaae$export$16b4216ec014493d);\nlet $70aa1fbe63deeaae$var$logline = \"\";\nfunction $70aa1fbe63deeaae$export$16b4216ec014493d(char) {\n if (char == 10 || char == 3) {\n console.log($70aa1fbe63deeaae$var$logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n $70aa1fbe63deeaae$var$logline = \"\";\n } else {\n $70aa1fbe63deeaae$var$logline = $70aa1fbe63deeaae$var$logline + String.fromCharCode(char);\n if ($70aa1fbe63deeaae$var$logline.length >= 200) {\n console.log($70aa1fbe63deeaae$var$logline);\n $70aa1fbe63deeaae$var$logline = \"\";\n }\n }\n}\nfunction $70aa1fbe63deeaae$export$485af4d0039b3389(ch) {\n postMessage([\n \"debug\",\n ch\n ]);\n}\n\n});\n\nparcelRegister(\"aGUWE\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrWasmModuleInJSMain\", () => $7c89ffbd74fdad5b$export$2366c14363f3adb5);\n// This class extends base to handle options when called in the main Java Script thread\n\nvar $fDEU7 = parcelRequire(\"fDEU7\");\n\nvar $5hO33 = parcelRequire(\"5hO33\");\n\nvar $5LsZ0 = parcelRequire(\"5LsZ0\");\nclass $7c89ffbd74fdad5b$export$2366c14363f3adb5 extends (0, $5hO33.twrWasmModuleBase) {\n iocanvas;\n d2dcanvas;\n iodiv;\n modParams;\n constructor(opts = {}, isWasmModule = false){\n super(isWasmModule);\n if (typeof document === \"undefined\") throw new Error(\"twrWasmModuleJSMain should only be created in JavaScript Main.\");\n const eiodiv = document.getElementById(\"twr_iodiv\");\n const eiocanvas = document.getElementById(\"twr_iocanvas\");\n const ed2dcanvas = document.getElementById(\"twr_d2dcanvas\");\n if (eiocanvas && ed2dcanvas) throw new Error(\"Both twr_iocanvas and twr_d2dcanvas defined. Currently only one canvas allowed.\");\n if (opts.stdio == \"div\" && !eiodiv) throw new Error(\"twrWasmModuleBase opts=='div' but twr_iodiv not defined\");\n if (opts.stdio == \"canvas\" && !eiocanvas) throw new Error(\"twrWasmModuleBase, opts=='canvas' but twr_iocanvas not defined\");\n if (opts.isd2dcanvas && !ed2dcanvas) throw new Error(\"twrWasmModuleBase, opts.isdrawcanvas==true but twr_d2dcanvas not defined\");\n // set default opts based on elements found\n if (eiodiv) opts = {\n stdio: \"div\",\n ...opts\n };\n else if (eiocanvas) opts = {\n stdio: \"canvas\",\n ...opts\n };\n else opts = {\n stdio: \"debug\",\n ...opts\n };\n if (!eiodiv && !eiocanvas) console.log(\"Since neither twr_iocanvas nor twr_iodiv is defined, stdout directed to debug console.\");\n else console.log(\"tiny-wasm-runtime: stdio set to: \", opts.stdio);\n if (eiocanvas) opts = {\n windim: [\n 64,\n 16\n ],\n ...opts\n };\n else opts = {\n windim: [\n 0,\n 0\n ],\n ...opts\n };\n if (!opts.imports) opts.imports = {};\n let styleIsDefault = false;\n if (!opts.backcolor) {\n styleIsDefault = true;\n opts.backcolor = \"black\";\n }\n if (!opts.forecolor) {\n styleIsDefault = true;\n opts.forecolor = \"white\";\n }\n if (!opts.fontsize) {\n styleIsDefault = true;\n opts.fontsize = 16;\n }\n if (opts.isd2dcanvas === undefined) {\n if (ed2dcanvas) opts.isd2dcanvas = true;\n else opts.isd2dcanvas = false;\n }\n this.modParams = {\n stdio: opts.stdio,\n windim: opts.windim,\n imports: opts.imports,\n forecolor: opts.forecolor,\n backcolor: opts.backcolor,\n styleIsDefault: styleIsDefault,\n fontsize: opts.fontsize,\n isd2dcanvas: opts.isd2dcanvas\n };\n this.iodiv = new (0, $fDEU7.twrDiv)(eiodiv, this.modParams, this);\n this.iocanvas = new (0, $5LsZ0.twrCanvas)(eiocanvas, this.modParams, this);\n this.d2dcanvas = new (0, $5LsZ0.twrCanvas)(ed2dcanvas, this.modParams, this);\n }\n divLog(...params) {\n for(var i = 0; i < params.length; i++){\n this.iodiv.stringOut(params[i].toString());\n this.iodiv.charOut(32); // space\n }\n this.iodiv.charOut(10);\n }\n}\n\n});\nparcelRegister(\"fDEU7\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrDiv\", () => $b62a3a4493ce3043$export$dd376bb3f10f6896);\n\nvar $ghrAp = parcelRequire(\"ghrAp\");\nclass $b62a3a4493ce3043$export$dd376bb3f10f6896 {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611);\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase){\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) this.divKeys = new (0, $ghrAp.twrSharedCircularBuffer)(); // tsconfig, lib must be set to 2017 or higher\n if (this.div && !modParams.styleIsDefault) {\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.divKeys.sharedArray\n ];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */ charOut(ch) {\n if (!this.div) return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n }\n switch(ch){\n case 10:\n case 13:\n if (ch == 10 && this.lastChar == 13) break; // detect CR LF and treat as single new line\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n case 0xE:\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF:\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for(let i = 0; i < str.length; i++)this.charOut(str.charCodeAt(i));\n }\n}\nclass $b62a3a4493ce3043$export$b377f0bbf2c7581e {\n divKeys;\n constructor(params){\n const [divKeysBuffer] = params;\n this.divKeys = new (0, $ghrAp.twrSharedCircularBuffer)(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n charOut(ch) {\n postMessage([\n \"divout\",\n ch\n ]);\n }\n}\n\n});\nparcelRegister(\"ghrAp\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrSharedCircularBuffer\", () => $bda3a1eb26e567b5$export$a01cca24f011573a);\n//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst $bda3a1eb26e567b5$var$RDIDX = 256;\nconst $bda3a1eb26e567b5$var$WRIDX = 257;\nconst $bda3a1eb26e567b5$var$LEN = 256;\nclass $bda3a1eb26e567b5$export$a01cca24f011573a {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(1032);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[$bda3a1eb26e567b5$var$RDIDX] = 0;\n this.buf[$bda3a1eb26e567b5$var$WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[$bda3a1eb26e567b5$var$WRIDX];\n this.buf[i] = n;\n i++;\n if (i == $bda3a1eb26e567b5$var$LEN) i = 0;\n this.buf[$bda3a1eb26e567b5$var$WRIDX] = i;\n Atomics.notify(this.buf, $bda3a1eb26e567b5$var$WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[$bda3a1eb26e567b5$var$RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[$bda3a1eb26e567b5$var$RDIDX] = i;\n return n;\n } else return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[$bda3a1eb26e567b5$var$RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, $bda3a1eb26e567b5$var$WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[$bda3a1eb26e567b5$var$RDIDX] == this.buf[$bda3a1eb26e567b5$var$WRIDX];\n }\n}\n\n});\n\n\nparcelRegister(\"5hO33\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrWasmModuleBase\", () => $3d955ccf8fb141b7$export$c83a0a3bffe07399);\n\nvar $2Xdsi = parcelRequire(\"2Xdsi\");\nclass $3d955ccf8fb141b7$export$c83a0a3bffe07399 {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule;\n floatUtil;\n constructor(isWasmModule = false){\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new (0, $2Xdsi.twrFloatUtil)(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/ /*********************************************************************/ async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n } catch (err) {\n console.log(\"loadWasm() failed to fetch: \" + pathToLoad);\n throw err;\n }\n if (!response.ok) throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, {\n env: allimports\n });\n this.exports = instance.instance.exports;\n if (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory) throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer) console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\n \"setmemory\",\n this.memory\n ]);\n }\n if (this.isWasmModule) // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n {\n if (!(this.memory.buffer instanceof ArrayBuffer)) console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size)=>{\n return new Promise((resolve)=>{\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n } catch (err) {\n console.log(\"WASM instantiate error: \" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch(this.modParams.stdio){\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* callC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */ async callC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.callCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async callCImpl(fname, cparams = []) {\n if (!this.exports) throw new Error(\"this.exports undefined\");\n if (!this.exports[fname]) throw new Error(\"callC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array)) throw new Error(\"callC: params must be array, first arg is function name\");\n if (params.length == 0) throw new Error(\"callC: missing function name\");\n let cparams = [];\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n cparams[ci++] = p;\n break;\n case \"string\":\n cparams[ci++] = await this.putString(p);\n break;\n case \"object\":\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n } else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"callC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n ci++;\n break;\n case \"string\":\n this.callCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n case \"object\":\n if (p instanceof URL) {\n this.callCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci = ci + 2;\n break;\n } else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for(let j = 0; j < u8.length; j++)u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.callCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n } else throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/ /*********************************************************************/ // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for(i = 0; i < sin.length && i < buffer_size - 1; i++)this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for(let i = 0; i < u8a.length; i++)this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === \"object\" && fnin instanceof URL)) throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [\n dest,\n src.length\n ];\n } catch (err) {\n console.log(\"fetchAndPutURL Error. URL: \" + fnin + \"\\n\" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while(this.mem8[strIndex + i] && (len === undefined ? true : i < len) && strIndex + i < this.mem8.length){\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array(this.mem8.slice(dataptr, dataptr + size).buffer);\n return u32;\n }\n}\n\n});\nparcelRegister(\"2Xdsi\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrFloatUtil\", () => $226b87658a7c840f$export$918ffb7e046a537b);\nclass $226b87658a7c840f$export$918ffb7e046a537b {\n mod;\n constructor(mod){\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\") return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\") return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll(\"D\", \"e\").replaceAll(\"d\", \"e\"));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n } else {\n let r = value.toString();\n if (r.length > max_precision) r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, sizeInBytes, value, fracpart_numdigits, dec, sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1) return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) {\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (!Number.isFinite(value)) {\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n } else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split(\".\");\n if (intPart == \"0\") intPart = \"\";\n if (intPart.length > 0) {\n decpos = intPart.length;\n digits = intPart + fracPart;\n } else {\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length) return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */ }\n}\n\n});\n\n\nparcelRegister(\"5LsZ0\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrCanvas\", () => $4327d2f23f608609$export$2f298dd69cef3c34);\n\nvar $ghrAp = parcelRequire(\"ghrAp\");\n\nvar $47Wdp = parcelRequire(\"47Wdp\");\nvar $4327d2f23f608609$var$D2DType;\n(function(D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})($4327d2f23f608609$var$D2DType || ($4327d2f23f608609$var$D2DType = {}));\nclass $4327d2f23f608609$export$2f298dd69cef3c34 {\n ctx;\n props = {\n charWidth: 0,\n charHeight: 0,\n foreColor: 0,\n backColor: 0,\n widthInChars: 0,\n heightInChars: 0,\n canvasHeight: 0,\n canvasWidth: 0\n };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase){\n const { forecolor: forecolor, backcolor: backcolor, fontsize: fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new (0, $47Wdp.twrSignal)();\n this.canvasKeys = new (0, $ghrAp.twrSharedCircularBuffer)(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.props,\n this.cmdCompleteSignal.sharedArray,\n this.canvasKeys.sharedArray\n ];\n }\n getProp(pn) {\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */ drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx) return;\n let ins = this.owner.getLong(ds); /* ds->start */ \n const lastins = this.owner.getLong(ds + 4); /* ds->last */ \n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while(true){\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */ \n switch(type){\n case $4327d2f23f608609$var$D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_BEGINPATH:\n this.ctx.beginPath();\n break;\n case $4327d2f23f608609$var$D2DType.D2D_FILL:\n this.ctx.fill();\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SAVE:\n this.ctx.save();\n break;\n case $4327d2f23f608609$var$D2DType.D2D_RESTORE:\n this.ctx.restore();\n break;\n case $4327d2f23f608609$var$D2DType.D2D_STROKE:\n this.ctx.stroke();\n break;\n case $4327d2f23f608609$var$D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = this.owner.getLong(ins + 48) != 0;\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n } else this.precomputedObjects[id] = {\n mem8: new Uint8Array(this.owner.memory.buffer, start, length),\n width: width,\n height: height\n };\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id]) delete this.precomputedObjects[id];\n else console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n else {\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) this.ctx.putImageData(imgData, dx, dy);\n else this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */ \n if (next == 0) {\n if (ins != lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nclass $4327d2f23f608609$export$c779b2cd00544976 {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner){\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new (0, $47Wdp.twrSignal)(signalBuffer);\n this.canvasKeys = new (0, $ghrAp.twrSharedCircularBuffer)(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\n \"drawseq\",\n [\n ds\n ]\n ]);\n this.drawCompleteSignal.wait();\n }\n}\n\n});\nparcelRegister(\"47Wdp\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrSignal\", () => $3014f93b5ceae902$export$e37a7b7b851b97f3);\n//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar $3014f93b5ceae902$var$twrSignalState;\n(function(twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})($3014f93b5ceae902$var$twrSignalState || ($3014f93b5ceae902$var$twrSignalState = {}));\nclass $3014f93b5ceae902$export$e37a7b7b851b97f3 {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = $3014f93b5ceae902$var$twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = $3014f93b5ceae902$var$twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == $3014f93b5ceae902$var$twrSignalState.WAITING) //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, $3014f93b5ceae902$var$twrSignalState.WAITING);\n }\n isSignaled() {\n return this.buf[0] == $3014f93b5ceae902$var$twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = $3014f93b5ceae902$var$twrSignalState.WAITING;\n }\n}\n\n});\n\n\n\nparcelRegister(\"lsUl2\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrTimeImpl\", () => $fa07ea1a08a5d6be$export$78724cdcf7ebea1d);\nfunction $fa07ea1a08a5d6be$export$78724cdcf7ebea1d() {\n return Date.now();\n}\n\n});\n\n\nparcelRegister(\"baOio\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrWasmModuleAsync\", () => $8227a48f951b1cca$export$678fe6e36ab9a6ff);\n\nvar $9FI45 = parcelRequire(\"9FI45\");\n\nvar $aGUWE = parcelRequire(\"aGUWE\");\n\nvar $2vKdq = parcelRequire(\"2vKdq\");\n\nvar $bqeaG = parcelRequire(\"bqeaG\");\n\nclass $8227a48f951b1cca$export$678fe6e36ab9a6ff extends (0, $aGUWE.twrWasmModuleInJSMain) {\n myWorker;\n malloc;\n loadWasmResolve;\n loadWasmReject;\n callCResolve;\n callCReject;\n initLW = false;\n waitingcalls;\n constructor(opts){\n super(opts);\n this.malloc = (size)=>{\n throw new Error(\"Error - un-init malloc called.\");\n };\n if (!window.Worker) throw new Error(\"This browser doesn't support web workers.\");\n this.myWorker = new Worker((parcelRequire(\"aRHnW\")));\n this.myWorker.onmessage = this.processMsg.bind(this);\n }\n // overrides base implementation\n async loadWasm(pathToLoad) {\n if (this.initLW) throw new Error(\"twrWasmAsyncModule::loadWasm can only be called once per twrWasmAsyncModule instance\");\n this.initLW = true;\n return new Promise((resolve, reject)=>{\n this.loadWasmResolve = resolve;\n this.loadWasmReject = reject;\n this.malloc = (size)=>{\n return this.callCImpl(\"twr_malloc\", [\n size\n ]);\n };\n this.waitingcalls = new (0, $2vKdq.twrWaitingCalls)(); // handle's calls that cross the worker thread - main js thread boundary\n let canvas;\n if (this.d2dcanvas.isValid()) canvas = this.d2dcanvas;\n else canvas = this.iocanvas;\n const modWorkerParams = {\n divProxyParams: this.iodiv.getProxyParams(),\n canvasProxyParams: canvas.getProxyParams(),\n waitingCallsProxyParams: this.waitingcalls.getProxyParams()\n };\n const urlToLoad = new URL(pathToLoad, document.URL);\n const startMsg = {\n urlToLoad: urlToLoad.href,\n modWorkerParams: modWorkerParams,\n modParams: this.modParams\n };\n this.myWorker.postMessage([\n \"startup\",\n startMsg\n ]);\n });\n }\n async callC(params) {\n const cparams = await this.preCallC(params); // will also validate params[0]\n return this.callCImpl(params[0], cparams);\n }\n async callCImpl(fname, cparams = []) {\n return new Promise((resolve, reject)=>{\n this.callCResolve = resolve;\n this.callCReject = reject;\n this.myWorker.postMessage([\n \"callC\",\n fname,\n cparams\n ]);\n });\n }\n // this function should be called from HTML \"keydown\" event from
\n keyDownDiv(ev) {\n if (!this.iodiv || !this.iodiv.divKeys) throw new Error(\"unexpected undefined twrWasmAsyncModule.divKeys\");\n this.iodiv.divKeys.write((0, $bqeaG.default)(ev).char.charCodeAt(0));\n }\n // this function should be called from HTML \"keydown\" event from \n keyDownCanvas(ev) {\n if (!this.iocanvas || !this.iocanvas.canvasKeys) throw new Error(\"unexpected undefined twrWasmAsyncModule.canvasKeys\");\n this.iocanvas.canvasKeys.write((0, $bqeaG.default)(ev).char.charCodeAt(0));\n }\n processMsg(event) {\n const msgType = event.data[0];\n const d = event.data[1];\n //console.log(\"twrWasmAsyncModule - got message: \"+event.data)\n switch(msgType){\n case \"divout\":\n if (this.iodiv.isValid()) this.iodiv.charOut(d);\n else console.log(\"error - msg divout received but iodiv is undefined.\");\n break;\n case \"debug\":\n (0, $9FI45.twrDebugLogImpl)(d);\n break;\n case \"drawseq\":\n {\n //console.log(\"twrModAsync got message drawseq\");\n const [ds] = d;\n if (this.iocanvas.isValid()) this.iocanvas.drawSeq(ds);\n else if (this.d2dcanvas.isValid()) this.d2dcanvas.drawSeq(ds);\n else throw new Error(\"msg drawseq received but canvas is undefined.\");\n break;\n }\n case \"setmemory\":\n this.memory = d;\n if (!this.memory) throw new Error(\"unexpected error - undefined memory in startupOkay msg\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n break;\n case \"startupFail\":\n if (this.loadWasmReject) this.loadWasmReject(d);\n else throw new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmReject)\");\n break;\n case \"startupOkay\":\n if (this.loadWasmResolve) this.loadWasmResolve(undefined);\n else throw new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmResolve)\");\n break;\n case \"callCFail\":\n if (this.callCReject) this.callCReject(d);\n else throw new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined callCReject)\");\n break;\n case \"callCOkay\":\n if (this.callCResolve) this.callCResolve(d);\n else throw new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined callCResolve)\");\n break;\n default:\n if (!this.waitingcalls) throw new Error(\"internal error: this.waitingcalls undefined.\");\n if (!this.waitingcalls.processMessage(msgType, d)) throw new Error(\"twrWasmAsyncModule - unknown and unexpected msgType: \" + msgType);\n }\n }\n}\n\n});\nparcelRegister(\"2vKdq\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrWaitingCalls\", () => $1d42537681d02be3$export$9e37856d1928d388);\n\nvar $47Wdp = parcelRequire(\"47Wdp\");\n\nvar $lsUl2 = parcelRequire(\"lsUl2\");\nclass $1d42537681d02be3$export$9e37856d1928d388 {\n callCompleteSignal;\n parameters;\n constructor(){\n this.callCompleteSignal = new (0, $47Wdp.twrSignal)();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(()=>{\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = (0, $lsUl2.twrTimeImpl)();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [\n this.callCompleteSignal.sharedArray,\n this.parameters.buffer\n ];\n }\n processMessage(msgType, data) {\n switch(msgType){\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\nclass $1d42537681d02be3$export$78d2a4633fe89379 {\n callCompleteSignal;\n parameters;\n constructor(params){\n this.callCompleteSignal = new (0, $47Wdp.twrSignal)(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\n \"sleep\",\n [\n ms\n ]\n ]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\n \"time\"\n ]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n\n});\n\nparcelRegister(\"bqeaG\", function(module, exports) {\n\n$parcel$export(module.exports, \"default\", () => $850d1d8f0aa1ea8f$export$2e2bcd8739ae039);\nconst $850d1d8f0aa1ea8f$var$keycodeCtrlKeys = {\n \"a\": \"selectAll\",\n \"c\": \"copy\",\n \"s\": \"save\",\n \"v\": \"paste\",\n \"x\": \"cut\",\n \"y\": \"redo\",\n \"z\": \"undo\"\n};\nconst $850d1d8f0aa1ea8f$var$keycodeShiftedKeys = {\n \"/\": \"?\",\n \".\": \">\",\n \",\": \"<\",\n \"'\": '\"',\n \";\": \":\",\n \"[\": \"{\",\n \"]\": \"}\",\n \"\\\\\": \"|\",\n \"`\": \"~\",\n \"=\": \"+\",\n \"-\": \"_\",\n \"1\": \"!\",\n \"2\": \"@\",\n \"3\": \"#\",\n \"4\": \"$\",\n \"5\": \"%\",\n \"6\": \"^\",\n \"7\": \"&\",\n \"8\": \"*\",\n \"9\": \"(\",\n \"0\": \")\",\n \"a\": \"A\",\n \"b\": \"B\",\n \"c\": \"C\",\n \"d\": \"D\",\n \"e\": \"E\",\n \"f\": \"F\",\n \"g\": \"G\",\n \"h\": \"H\",\n \"i\": \"I\",\n \"j\": \"J\",\n \"k\": \"K\",\n \"l\": \"L\",\n \"m\": \"M\",\n \"n\": \"N\",\n \"o\": \"O\",\n \"p\": \"P\",\n \"q\": \"q\",\n \"r\": \"R\",\n \"s\": \"S\",\n \"t\": \"T\",\n \"u\": \"U\",\n \"v\": \"V\",\n \"w\": \"W\",\n \"x\": \"X\",\n \"y\": \"Y\",\n \"z\": \"Z\"\n};\nconst $850d1d8f0aa1ea8f$var$keyCodeUnshiftedKeys = {};\nfor(const x in $850d1d8f0aa1ea8f$var$keycodeShiftedKeys){\n const shiftedKey = $850d1d8f0aa1ea8f$var$keycodeShiftedKeys[x];\n $850d1d8f0aa1ea8f$var$keyCodeUnshiftedKeys[shiftedKey] = x;\n}\nconst $850d1d8f0aa1ea8f$var$keydownKeycodeDictionary = {\n 0: \"\\\\\",\n 8: \"backspace\",\n 9: \"tab\",\n 12: \"num\",\n 13: \"enter\",\n 16: \"shift\",\n 17: \"ctrl\",\n 18: \"alt\",\n 19: \"pause\",\n 20: \"caps\",\n 27: \"esc\",\n 32: \" \",\n 33: \"pageup\",\n 34: \"pagedown\",\n 35: \"end\",\n 36: \"home\",\n 37: \"left\",\n 38: \"up\",\n 39: \"right\",\n 40: \"down\",\n 44: \"print\",\n 45: \"insert\",\n 46: \"delete\",\n 48: \"0\",\n 49: \"1\",\n 50: \"2\",\n 51: \"3\",\n 52: \"4\",\n 53: \"5\",\n 54: \"6\",\n 55: \"7\",\n 56: \"8\",\n 57: \"9\",\n 59: \";\",\n 61: \"=\",\n 65: \"a\",\n 66: \"b\",\n 67: \"c\",\n 68: \"d\",\n 69: \"e\",\n 70: \"f\",\n 71: \"g\",\n 72: \"h\",\n 73: \"i\",\n 74: \"j\",\n 75: \"k\",\n 76: \"l\",\n 77: \"m\",\n 78: \"n\",\n 79: \"o\",\n 80: \"p\",\n 81: \"q\",\n 82: \"r\",\n 83: \"s\",\n 84: \"t\",\n 85: \"u\",\n 86: \"v\",\n 87: \"w\",\n 88: \"x\",\n 89: \"y\",\n 90: \"z\",\n 91: \"meta\",\n 92: \"meta\",\n 93: \"meta\",\n 96: \"num0\",\n 97: \"num1\",\n 98: \"num2\",\n 99: \"num3\",\n 100: \"num4\",\n 101: \"num5\",\n 102: \"num6\",\n 103: \"num7\",\n 104: \"num8\",\n 105: \"num9\",\n 106: \"*\",\n 107: \"+\",\n 108: \"num_enter\",\n 109: \"num_subtract\",\n 110: \"num_decimal\",\n 111: \"num_divide\",\n 112: \"f1\",\n 113: \"f2\",\n 114: \"f3\",\n 115: \"f4\",\n 116: \"f5\",\n 117: \"f6\",\n 118: \"f7\",\n 119: \"f8\",\n 120: \"f9\",\n 121: \"f10\",\n 122: \"f11\",\n 123: \"f12\",\n 124: \"print\",\n 144: \"num\",\n 145: \"scroll\",\n 173: \"-\",\n 186: \";\",\n 187: \"=\",\n 188: \",\",\n 189: \"-\",\n 190: \".\",\n 191: \"/\",\n 192: \"`\",\n 219: \"[\",\n 220: \"\\\\\",\n 221: \"]\",\n 222: \"'\",\n 223: \"`\",\n 224: \"cmd\",\n 225: \"alt\",\n 57392: \"ctrl\",\n 63289: \"num\"\n};\nconst $850d1d8f0aa1ea8f$var$keypressCharacterMapOverides = {\n \"\\r\": \"enter\"\n};\nconst $850d1d8f0aa1ea8f$var$keypressCharacterMap = JSON.parse(JSON.stringify($850d1d8f0aa1ea8f$var$keydownKeycodeDictionary));\nfor (const key of Object.keys($850d1d8f0aa1ea8f$var$keypressCharacterMapOverides))$850d1d8f0aa1ea8f$var$keypressCharacterMap[key] = $850d1d8f0aa1ea8f$var$keypressCharacterMapOverides[key];\nconst $850d1d8f0aa1ea8f$var$keydownCharacterMap = {\n \"num_subtract\": \"-\",\n \"num_enter\": \"\\n\",\n \"num_decimal\": \".\",\n \"num_divide\": \"/\",\n \"enter\": \"\\n\",\n \"tab\": \"\t\",\n \"backspace\": \"\\b\"\n};\nconst $850d1d8f0aa1ea8f$export$d1477772898aaa70 = [\n \"backspace\",\n \"enter\",\n \"tab\",\n \"num\",\n \"shift\",\n \"meta\",\n \"alt\",\n \"pause\",\n \"caps\",\n \"esc\",\n \"pageup\",\n \"pagedown\",\n \"end\",\n \"home\",\n \"left\",\n \"up\",\n \"right\",\n \"down\",\n \"print\",\n \"insert\",\n \"delete\",\n \"cmd\",\n \"f1\",\n \"f2\",\n \"f3\",\n \"f4\",\n \"f5\",\n \"f6\",\n \"f7\",\n \"f8\",\n \"f9\",\n \"f10\",\n \"f11\",\n \"f12\",\n \"scroll\",\n \"ctrl\"\n];\nconst $850d1d8f0aa1ea8f$var$validEvents = [\n \"keydown\",\n \"keyup\"\n];\nconst $850d1d8f0aa1ea8f$var$isMobile = ()=>{\n const ua = navigator.userAgent;\n const mobile = /IEMobile|Windows Phone|Lumia/i.test(ua) ? \"w\" : /iPhone|iP[oa]d/.test(ua) ? \"i\" : /Android/.test(ua) ? \"a\" : /BlackBerry|PlayBook|BB10/.test(ua) ? \"b\" : /Mobile Safari/.test(ua) ? \"s\" : /webOS|Mobile|Tablet|Opera Mini|\\bCrMo\\/|Opera Mobi/i.test(ua) ? 1 : 0;\n return mobile !== 0;\n};\nfunction $850d1d8f0aa1ea8f$var$getKeypressKeycodeValue(charcode) {\n const character = String.fromCharCode(charcode);\n if ($850d1d8f0aa1ea8f$var$isMobile()) return character;\n if (character in $850d1d8f0aa1ea8f$var$keyCodeUnshiftedKeys) return $850d1d8f0aa1ea8f$var$keyCodeUnshiftedKeys[character];\n else if (character in $850d1d8f0aa1ea8f$var$keypressCharacterMap) return $850d1d8f0aa1ea8f$var$keypressCharacterMap[character];\n return character;\n}\nfunction $850d1d8f0aa1ea8f$export$2e2bcd8739ae039(event) {\n let key;\n if (event.type === \"keypress\" && !$850d1d8f0aa1ea8f$var$isMobile()) key = $850d1d8f0aa1ea8f$var$getKeypressKeycodeValue(event.charCode);\n else if (event.type === \"keypress\" && $850d1d8f0aa1ea8f$var$isMobile()) key = $850d1d8f0aa1ea8f$var$getKeypressKeycodeValue(event.keyCode);\n else if ($850d1d8f0aa1ea8f$var$validEvents.indexOf(event.type) > -1) {\n if (event.which !== undefined) key = $850d1d8f0aa1ea8f$var$keydownKeycodeDictionary[event.which];\n else if (event.keyCode !== undefined) key = $850d1d8f0aa1ea8f$var$keydownKeycodeDictionary[event.keyCode];\n else key = \"enter\";\n } else return false;\n let char = key;\n if (event.shiftKey && key in $850d1d8f0aa1ea8f$var$keycodeShiftedKeys) char = $850d1d8f0aa1ea8f$var$keycodeShiftedKeys[key];\n else if (event.ctrlKey && key in $850d1d8f0aa1ea8f$var$keycodeCtrlKeys) char = $850d1d8f0aa1ea8f$var$keycodeCtrlKeys[key];\n else if (key in $850d1d8f0aa1ea8f$var$keydownCharacterMap) char = $850d1d8f0aa1ea8f$var$keydownCharacterMap[key];\n return {\n char: char,\n key: key\n };\n}\n\n});\n\nparcelRegister(\"aRHnW\", function(module, exports) {\n\nvar $hoqmg = parcelRequire(\"hoqmg\");\nlet $7e9081fcee88b005$var$url = new URL(\"twrmodworker.2165e649.js\", import.meta.url);\nmodule.exports = $hoqmg($7e9081fcee88b005$var$url.toString(), $7e9081fcee88b005$var$url.origin, true);\n\n});\nparcelRegister(\"hoqmg\", function(module, exports) {\n\"use strict\";\nmodule.exports = function(workerUrl, origin, isESM) {\n if (origin === self.location.origin) // If the worker bundle's url is on the same origin as the document,\n // use the worker bundle's own url.\n return workerUrl;\n else {\n // Otherwise, create a blob URL which loads the worker bundle with `importScripts`.\n var source = isESM ? \"import \" + JSON.stringify(workerUrl) + \";\" : \"importScripts(\" + JSON.stringify(workerUrl) + \");\";\n return URL.createObjectURL(new Blob([\n source\n ], {\n type: \"application/javascript\"\n }));\n }\n};\n\n});\n\n\n\n\nvar $49087e929fab6e62$exports = {};\n\n(parcelRequire(\"eZoLj\")).register(new URL(\"\", import.meta.url).toString(), JSON.parse('[\"kjr0c\",\"index.528b9ee5.js\",\"cTHdP\",\"twrmodworker.2165e649.js\"]'));\n\n\n//# sourceMappingURL=index.528b9ee5.js.map\n","\"use strict\";\n\nvar mapping = new Map();\nfunction register(baseUrl, manifest) {\n for (var i = 0; i < manifest.length - 1; i += 2) {\n mapping.set(manifest[i], {\n baseUrl: baseUrl,\n path: manifest[i + 1]\n });\n }\n}\nfunction resolve(id) {\n var resolved = mapping.get(id);\n if (resolved == null) {\n throw new Error('Could not resolve bundle with id ' + id);\n }\n return new URL(resolved.path, resolved.baseUrl).toString();\n}\nmodule.exports.register = register;\nmodule.exports.resolve = resolve;","import {twrWasmModule} from \"./twrmod.js\";\r\nimport {IModOpts, IModInWorkerParams, TStdioVals} from \"./twrmodbase.js\"\r\nimport {twrWasmModuleAsync} from \"./twrmodasync.js\";\r\n\r\nexport {IModOpts, TStdioVals, IModInWorkerParams};\r\nexport {twrWasmModule};\r\nexport {twrWasmModuleAsync};\r\n\r\n","import { twrDebugLogImpl } from \"./twrdebug.js\";\nimport { twrWasmModuleInJSMain } from \"./twrmodjsmain.js\";\nimport { twrTimeImpl } from \"./twrdate.js\";\nexport class twrWasmModule extends twrWasmModuleInJSMain {\n malloc;\n constructor(opts = {}) {\n super(opts, true);\n this.malloc = (size) => { throw new Error(\"error - un-init malloc called\"); };\n let canvas;\n if (this.d2dcanvas.isValid())\n canvas = this.d2dcanvas;\n else\n canvas = this.iocanvas;\n this.modParams.imports = {\n twrDebugLog: twrDebugLogImpl,\n twrTime: twrTimeImpl,\n twrDivCharOut: this.iodiv.charOut.bind(this.iodiv),\n twrCanvasGetProp: canvas.getProp.bind(canvas),\n twrCanvasDrawSeq: canvas.drawSeq.bind(canvas),\n twrCanvasCharIn: this.null,\n twrCanvasInkey: this.null,\n twrDivCharIn: this.null,\n twrSleep: this.null,\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function (x, y) { return x % y; },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil),\n };\n }\n null(inval) {\n throw new Error(\"call to unimplemented twrXXX import in twrWasmModule. Use twrWasmModuleAsync ?\");\n }\n}\n//# sourceMappingURL=twrmod.js.map","import {twrDebugLogImpl} from \"./twrdebug.js\"\r\nimport {IModOpts} from \"./twrmodbase.js\";\r\nimport {twrWasmModuleInJSMain} from \"./twrmodjsmain.js\"\r\nimport {twrCanvas} from \"./twrcanvas.js\";\r\nimport {twrTimeImpl} from \"./twrdate.js\"\r\n\r\n\r\n\r\nexport class twrWasmModule extends twrWasmModuleInJSMain {\r\n\t malloc:(size:number)=>Promise;\r\n\r\n\r\n\tconstructor(opts:IModOpts={}) {\r\n\t\tsuper(opts, true);\r\n\t\tthis.malloc=(size:number)=>{throw new Error(\"error - un-init malloc called\")};\r\n\t\t\r\n\t\tlet canvas:twrCanvas;\r\n\t\tif (this.d2dcanvas.isValid()) canvas=this.d2dcanvas;\r\n\t\telse canvas=this.iocanvas;\r\n\r\n\t\tthis.modParams.imports={\r\n\t\t\ttwrDebugLog:twrDebugLogImpl,\r\n\t\t\ttwrTime:twrTimeImpl,\r\n\t\t\ttwrDivCharOut:this.iodiv.charOut.bind(this.iodiv),\r\n\t\t\ttwrCanvasGetProp:canvas.getProp.bind(canvas),\r\n\t\t\ttwrCanvasDrawSeq:canvas.drawSeq.bind(canvas),\r\n\t\t\ttwrCanvasCharIn:this.null,\r\n\t\t\ttwrCanvasInkey:this.null,\r\n\t\t\ttwrDivCharIn:this.null,\r\n\t\t\ttwrSleep:this.null,\r\n\r\n\t\t\ttwrSin:Math.sin,\r\n\t\t\ttwrCos:Math.cos,\r\n\t\t\ttwrTan: Math.tan,\r\n\t\t\ttwrFAbs: Math.abs,\r\n\t\t\ttwrACos: Math.acos,\r\n\t\t\ttwrASin: Math.asin,\r\n\t\t\ttwrATan: Math.atan,\r\n\t\t\ttwrExp: Math.exp,\r\n\t\t\ttwrFloor: Math.floor,\r\n\t\t\ttwrCeil: Math.ceil,\r\n\t\t\ttwrFMod: function(x:number, y:number) {return x%y},\r\n\t\t\ttwrLog: Math.log,\r\n\t\t\ttwrPow: Math.pow,\r\n\t\t\ttwrSqrt: Math.sqrt,\r\n\t\t\ttwrTrunc: Math.trunc,\r\n\r\n\t\t\ttwrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\r\n\t\t\ttwrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\r\n\t\t\ttwrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\r\n\t\t\ttwrAtod: this.floatUtil.atod.bind(this.floatUtil),\r\n\t\t\ttwrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil),\r\n\t\t}\r\n\t}\r\n\r\n\tnull(inval?:any) {\r\n\t\tthrow new Error(\"call to unimplemented twrXXX import in twrWasmModule. Use twrWasmModuleAsync ?\");\r\n\t}\r\n}\r\n\r\n\r\n\r\n\r\n","let logline = \"\";\nexport function twrDebugLogImpl(char) {\n if (char == 10 || char == 3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\n console.log(logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n logline = \"\";\n }\n else {\n logline = logline + String.fromCharCode(char);\n if (logline.length >= 200) {\n console.log(logline);\n logline = \"\";\n }\n }\n}\n// ************************************************************************\n// debugLog doesn't currently wait for the message to log, it returns immediately.\n// I could move this to be in the twrWaitingCalls class\nexport function twrDebugLogProxy(ch) {\n postMessage([\"debug\", ch]);\n}\n//# sourceMappingURL=twrdebug.js.map","\r\nlet logline=\"\";\r\nexport function twrDebugLogImpl(char:number) {\r\n\tif (char==10 || char==3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\r\n\t\tconsole.log(logline);\t// ideally without a linefeed, but there is no way to not have a LF with console.log API.\r\n\t\tlogline=\"\";\r\n\t}\r\n\telse {\r\n\t\tlogline=logline+String.fromCharCode(char);\r\n\t\tif (logline.length>=200) {\r\n\t\t\tconsole.log(logline);\r\n\t\t\tlogline=\"\";\r\n\t\t}\r\n\t}\r\n}\r\n\r\n// ************************************************************************\r\n// debugLog doesn't currently wait for the message to log, it returns immediately.\r\n// I could move this to be in the twrWaitingCalls class\r\nexport function twrDebugLogProxy(ch:number) {\r\n postMessage([\"debug\", ch]);\r\n}\r\n\r\n","// This class extends base to handle options when called in the main Java Script thread\nimport { twrDiv } from \"./twrdiv.js\";\nimport { twrWasmModuleBase } from \"./twrmodbase.js\";\nimport { twrCanvas } from \"./twrcanvas.js\";\nexport class twrWasmModuleInJSMain extends twrWasmModuleBase {\n iocanvas;\n d2dcanvas;\n iodiv;\n modParams;\n constructor(opts = {}, isWasmModule = false) {\n super(isWasmModule);\n if (typeof document === 'undefined')\n throw new Error(\"twrWasmModuleJSMain should only be created in JavaScript Main.\");\n const eiodiv = document.getElementById(\"twr_iodiv\");\n const eiocanvas = document.getElementById(\"twr_iocanvas\");\n const ed2dcanvas = document.getElementById(\"twr_d2dcanvas\");\n if (eiocanvas && ed2dcanvas)\n throw new Error(\"Both twr_iocanvas and twr_d2dcanvas defined. Currently only one canvas allowed.\");\n if (opts.stdio == 'div' && !eiodiv)\n throw new Error(\"twrWasmModuleBase opts=='div' but twr_iodiv not defined\");\n if (opts.stdio == 'canvas' && !eiocanvas)\n throw new Error(\"twrWasmModuleBase, opts=='canvas' but twr_iocanvas not defined\");\n if (opts.isd2dcanvas && !ed2dcanvas)\n throw new Error(\"twrWasmModuleBase, opts.isdrawcanvas==true but twr_d2dcanvas not defined\");\n // set default opts based on elements found\n if (eiodiv)\n opts = { stdio: \"div\", ...opts };\n else if (eiocanvas)\n opts = { stdio: \"canvas\", ...opts };\n else\n opts = { stdio: \"debug\", ...opts };\n if (!eiodiv && !eiocanvas)\n console.log(\"Since neither twr_iocanvas nor twr_iodiv is defined, stdout directed to debug console.\");\n else\n console.log('tiny-wasm-runtime: stdio set to: ', opts.stdio);\n if (eiocanvas)\n opts = { windim: [64, 16], ...opts };\n else\n opts = { windim: [0, 0], ...opts };\n if (!opts.imports)\n opts.imports = {};\n let styleIsDefault = false;\n if (!opts.backcolor) {\n styleIsDefault = true;\n opts.backcolor = \"black\";\n }\n if (!opts.forecolor) {\n styleIsDefault = true;\n opts.forecolor = \"white\";\n }\n if (!opts.fontsize) {\n styleIsDefault = true;\n opts.fontsize = 16;\n }\n if (opts.isd2dcanvas === undefined) {\n if (ed2dcanvas)\n opts.isd2dcanvas = true;\n else\n opts.isd2dcanvas = false;\n }\n this.modParams = {\n stdio: opts.stdio,\n windim: opts.windim,\n imports: opts.imports,\n forecolor: opts.forecolor,\n backcolor: opts.backcolor,\n styleIsDefault: styleIsDefault,\n fontsize: opts.fontsize,\n isd2dcanvas: opts.isd2dcanvas\n };\n this.iodiv = new twrDiv(eiodiv, this.modParams, this);\n this.iocanvas = new twrCanvas(eiocanvas, this.modParams, this);\n this.d2dcanvas = new twrCanvas(ed2dcanvas, this.modParams, this);\n }\n divLog(...params) {\n for (var i = 0; i < params.length; i++) {\n this.iodiv.stringOut(params[i].toString());\n this.iodiv.charOut(32); // space\n }\n this.iodiv.charOut(10);\n }\n}\n//# sourceMappingURL=twrmodjsmain.js.map","// This class extends base to handle options when called in the main Java Script thread\r\n\r\nimport {twrDiv} from \"./twrdiv.js\"\r\nimport {IModParams, IModOpts, twrWasmModuleBase} from \"./twrmodbase.js\"\r\nimport {twrCanvas} from \"./twrcanvas.js\"\r\n\r\n\r\nexport abstract class twrWasmModuleInJSMain extends twrWasmModuleBase {\r\n\tiocanvas:twrCanvas;\r\n\td2dcanvas:twrCanvas;\r\n\tiodiv:twrDiv;\r\n\tmodParams:IModParams;\r\n\r\n constructor(opts:IModOpts={}, isWasmModule=false) {\r\n\t\tsuper(isWasmModule);\r\n\t\tif (typeof document === 'undefined')\r\n\t\t\tthrow new Error (\"twrWasmModuleJSMain should only be created in JavaScript Main.\");\r\n\r\n\t\tconst eiodiv=document.getElementById(\"twr_iodiv\") as HTMLDivElement;\r\n\t\tconst eiocanvas=document.getElementById(\"twr_iocanvas\") as HTMLCanvasElement;\r\n\t\tconst ed2dcanvas=document.getElementById(\"twr_d2dcanvas\") as HTMLCanvasElement;\r\n\r\n\t\tif (eiocanvas && ed2dcanvas) throw new Error (\"Both twr_iocanvas and twr_d2dcanvas defined. Currently only one canvas allowed.\");\r\n\t\tif (opts.stdio=='div' && !eiodiv) throw new Error(\"twrWasmModuleBase opts=='div' but twr_iodiv not defined\");\r\n\t\tif (opts.stdio=='canvas' && !eiocanvas) throw new Error(\"twrWasmModuleBase, opts=='canvas' but twr_iocanvas not defined\");\r\n\t\tif (opts.isd2dcanvas && !ed2dcanvas) throw new Error(\"twrWasmModuleBase, opts.isdrawcanvas==true but twr_d2dcanvas not defined\");\r\n\r\n\t\t// set default opts based on elements found\r\n\t\tif (eiodiv) opts={stdio:\"div\", ...opts};\r\n\t\telse if (eiocanvas) opts={stdio:\"canvas\", ...opts};\r\n\t\telse opts={stdio:\"debug\", ...opts};\r\n\r\n\t\tif (!eiodiv && !eiocanvas) console.log(\"Since neither twr_iocanvas nor twr_iodiv is defined, stdout directed to debug console.\");\r\n\t\telse console.log('tiny-wasm-runtime: stdio set to: ', opts.stdio);\r\n\r\n\t\tif (eiocanvas) opts={windim:[64, 16], ...opts};\r\n\t\telse opts={windim:[0, 0], ...opts};\r\n\r\n\t\tif (!opts.imports) opts.imports={};\r\n\r\n\t\tlet styleIsDefault=false;\r\n\t\tif (!opts.backcolor) {styleIsDefault=true; opts.backcolor=\"black\";}\r\n\t\tif (!opts.forecolor) {styleIsDefault=true; opts.forecolor=\"white\";}\r\n\t\tif (!opts.fontsize) {styleIsDefault=true; opts.fontsize=16;}\r\n\r\n\t\tif (opts.isd2dcanvas===undefined) {\r\n\t\t\tif (ed2dcanvas) \r\n\t\t\t\topts.isd2dcanvas=true;\r\n\t\t\telse\r\n\t\t\t\topts.isd2dcanvas=false;\r\n\t\t}\r\n\r\n\t\tthis.modParams={\r\n\t\t\tstdio:opts.stdio!, \r\n\t\t\twindim:opts.windim!, \r\n\t\t\timports:opts.imports, \r\n\t\t\tforecolor:opts.forecolor, \r\n\t\t\tbackcolor:opts.backcolor, \r\n\t\t\tstyleIsDefault: styleIsDefault,\r\n\t\t\tfontsize:opts.fontsize,\r\n\t\t\tisd2dcanvas:opts.isd2dcanvas\r\n\t\t};\r\n\r\n\t\tthis.iodiv=new twrDiv(eiodiv, this.modParams, this);\r\n\t\tthis.iocanvas=new twrCanvas(eiocanvas, this.modParams, this);\r\n\t\tthis.d2dcanvas=new twrCanvas(ed2dcanvas, this.modParams, this);\r\n\r\n\t}\r\n\r\n\tdivLog(...params: string[]) {\r\n\t\tfor (var i = 0; i < params.length; i++) {\r\n\t\t\tthis.iodiv.stringOut(params[i].toString());\r\n\t\t\tthis.iodiv.charOut(32); // space\r\n\t\t}\r\n\t\tthis.iodiv.charOut(10);\r\n\t }\r\n}","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nexport class twrDiv {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase) {\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\n this.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n if (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.divKeys.sharedArray];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */\n charOut(ch) {\n if (!this.div)\n return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n }\n switch (ch) {\n case 10: // newline\n case 13: // return\n if (ch == 10 && this.lastChar == 13)\n break; // detect CR LF and treat as single new line\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8: // backspace\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n case 0xE: // cursor on\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF: // cursor off\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for (let i = 0; i < str.length; i++)\n this.charOut(str.charCodeAt(i));\n }\n}\nexport class twrDivProxy {\n divKeys;\n constructor(params) {\n const [divKeysBuffer] = params;\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n charOut(ch) {\n postMessage([\"divout\", ch]);\n }\n}\n//# sourceMappingURL=twrdiv.js.map","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\r\nimport { IModParams } from \"./twrmodbase.js\";\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\";\r\n\r\nexport type TDivProxyParams = [SharedArrayBuffer];\r\n\r\nexport interface IDiv {\r\n charOut: (ds:number)=>void,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TDivProxyParams,\r\n }\r\n\r\n\r\nexport class twrDiv implements IDiv {\r\n\tdiv:HTMLDivElement|null|undefined;\r\n\tdivKeys?:twrSharedCircularBuffer;\r\n\tCURSOR=String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\r\n\tcursorOn:boolean=false;\r\n\tlastChar:number=0;\r\n\textraBR:boolean=false;\r\n\towner:twrWasmModuleBase;\r\n\r\n constructor(element:HTMLDivElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n\t\tthis.div=element;\r\n\t\tthis.owner=modbase;\r\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\r\n\t\t\tthis.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n\t\t}\r\n\r\n\t\tif (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\r\n\t\t\tthis.div.style.backgroundColor = modParams.backcolor;\r\n\t\t\tthis.div.style.color = modParams.forecolor;\r\n\t\t\tthis.div.style.font=modParams.fontsize.toString()+\"px arial\"\r\n\t\t}\r\n }\r\n\r\n\tisValid() {\r\n\t\treturn !!this.div;\r\n\t}\r\n\r\n getProxyParams() : TDivProxyParams {\r\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [ this.divKeys.sharedArray];\r\n }\r\n\r\n\r\n/* \r\n * add character to div. Supports the following control codes:\r\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\r\n * 0xE cursor on \r\n * 0x8 backspace\r\n * 0xF cursor off \r\n*/\r\n\tcharOut(ch:number) {\r\n\r\n\t\tif (!this.div) return;\r\n\r\n\t\t//console.log(\"div::charout: \", ch);\r\n\r\n\t\tif (this.extraBR) {\r\n\t\t\tthis.extraBR=false;\r\n\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -4);\r\n\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t}\r\n\r\n\t\tswitch (ch) {\r\n\t\t\tcase 10: // newline\r\n\t\t\tcase 13: // return\r\n\t\t\t\tif (ch==10 && this.lastChar==13) break; // detect CR LF and treat as single new line\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\r\n\t\t\t\tthis.extraBR=true;\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\t//element.scrollIntoView();\r\n\t\t\t\t//element.scrollTop = element.scrollHeight;\r\n\t\t\t\tlet p = this.div.getBoundingClientRect();\r\n\t\t\t\twindow.scrollTo(0, p.height+100);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 8: // backspace\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xE: // cursor on\r\n\t\t\t\tif (!this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=true;\r\n\t\t\t\t\tthis.div.innerHTML += this.CURSOR;\r\n\t\t\t\t\tthis.div.focus();\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xF: // cursor off\r\n\t\t\t\tif (this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=false;\r\n\t\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += String.fromCharCode(ch);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\tthis.lastChar=ch;\r\n\t}\r\n\r\n\tstringOut(str:string) {\r\n\t\tfor (let i=0; i < str.length; i++)\r\n\t\t\tthis.charOut(str.charCodeAt(i));\r\n\t}\r\n}\r\n\r\n\r\nexport class twrDivProxy implements IDiv {\r\n divKeys: twrSharedCircularBuffer;\r\n\r\n constructor(params:TDivProxyParams) {\r\n const [divKeysBuffer] = params;\r\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\r\n }\r\n\r\n charIn() { \r\n return this.divKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.divKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n\tcharOut(ch:number) {\r\n\t\tpostMessage([\"divout\", ch]);\r\n\t}\r\n}\r\n\r\n","//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst RDIDX = 256;\nconst WRIDX = 257;\nconst LEN = 256;\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\n// the first 256 array entries are the circular buffer\n// the next two are used for the read and write index\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\nexport class twrSharedCircularBuffer {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(258 * 4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[RDIDX] = 0;\n this.buf[WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[WRIDX];\n this.buf[i] = n;\n i++;\n if (i == LEN)\n i = 0;\n this.buf[WRIDX] = i;\n Atomics.notify(this.buf, WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[RDIDX] = i;\n return n;\n }\n else\n return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[RDIDX] == this.buf[WRIDX];\n }\n}\n//# sourceMappingURL=twrcircular.js.map","//\r\n// This class implements a circular buffer that the main javascript thread can write to, \r\n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\r\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \r\n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\r\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\r\n//\r\n\r\nconst RDIDX=256;\r\nconst WRIDX=257;\r\nconst LEN=256;\r\n\r\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\r\n// the first 256 array entries are the circular buffer\r\n// the next two are used for the read and write index\r\n\r\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\r\n\r\nexport class twrSharedCircularBuffer {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n \r\n\tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(258*4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[RDIDX]=0;\r\n this.buf[WRIDX]=0;\r\n\t}\r\n\r\n\twrite(n:number) {\r\n let i=this.buf[WRIDX];\r\n this.buf[i]=n;\r\n i++;\r\n if (i==LEN) i=0;\r\n this.buf[WRIDX]=i; \r\n Atomics.notify(this.buf, WRIDX); \r\n\t}\r\n\r\n\tread():number {\r\n if (!this.isEmpty()) {\r\n let i=this.buf[RDIDX];\r\n let n=this.buf[i];\r\n i++;\r\n this.buf[RDIDX]=i;\r\n return n;\r\n }\r\n\t\telse\r\n return -1;\r\n\t}\r\n\r\n readWait():number {\r\n if (this.isEmpty()) {\r\n const rdptr=this.buf[RDIDX];\r\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\r\n Atomics.wait(this.buf, WRIDX, rdptr);\r\n }\r\n return this.read();\r\n\t}\r\n\r\n isEmpty():boolean {\r\n return this.buf[RDIDX]==this.buf[WRIDX];\r\n }\r\n}\r\n","import { twrFloatUtil } from \"./twrfloat.js\";\n/*********************************************************************/\n/*********************************************************************/\n/*********************************************************************/\nexport class twrWasmModuleBase {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\n floatUtil;\n constructor(isWasmModule = false) {\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new twrFloatUtil(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/\n /*********************************************************************/\n async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n }\n catch (err) {\n console.log('loadWasm() failed to fetch: ' + pathToLoad);\n throw err;\n }\n if (!response.ok)\n throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, { env: allimports });\n this.exports = instance.instance.exports;\n if (!this.exports)\n throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory)\n throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory)\n throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer)\n console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\"setmemory\", this.memory]);\n }\n if (this.isWasmModule) {\n // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (!(this.memory.buffer instanceof ArrayBuffer))\n console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size) => {\n return new Promise(resolve => {\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n }\n catch (err) {\n console.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch (this.modParams.stdio) {\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* callC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */\n async callC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.callCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async callCImpl(fname, cparams = []) {\n if (!this.exports)\n throw new Error(\"this.exports undefined\");\n if (!this.exports[fname])\n throw new Error(\"callC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array))\n throw new Error(\"callC: params must be array, first arg is function name\");\n if (params.length == 0)\n throw new Error(\"callC: missing function name\");\n let cparams = [];\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n cparams[ci++] = p;\n break;\n case 'string':\n cparams[ci++] = await this.putString(p);\n break;\n case 'object':\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n }\n else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"callC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n ci++;\n break;\n case 'string':\n this.callCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n case 'object':\n if (p instanceof URL) {\n this.callCImpl('twr_free', [cparams[ci]]);\n ci = ci + 2;\n break;\n }\n else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for (let j = 0; j < u8.length; j++)\n u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.callCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n }\n else\n throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/\n /*********************************************************************/\n // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for (i = 0; i < sin.length && i < buffer_size - 1; i++)\n this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for (let i = 0; i < u8a.length; i++)\n this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === 'object' && fnin instanceof URL))\n throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [dest, src.length];\n }\n catch (err) {\n console.log('fetchAndPutURL Error. URL: ' + fnin + '\\n' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while (this.mem8[strIndex + i] && (len === undefined ? true : i < len) && (strIndex + i) < this.mem8.length) {\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0)\n throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array((this.mem8.slice(dataptr, dataptr + size)).buffer);\n return u32;\n }\n}\n//# sourceMappingURL=twrmodbase.js.map","\r\nimport {TCanvasProxyParams} from \"./twrcanvas.js\"\r\nimport {TDivProxyParams} from \"./twrdiv.js\";\r\nimport {TWaitingCallsProxyParams} from \"./twrwaitingcalls.js\"\r\nimport {twrDebugLogImpl} from \"./twrdebug.js\";\r\nimport {twrFloatUtil} from \"./twrfloat.js\";\r\n\r\n\r\nexport type TStdioVals=\"div\"|\"canvas\"|\"null\"|\"debug\";\r\n\r\nexport interface IModOpts {\r\n\tstdio?:TStdioVals, \r\n\twindim?:[number, number],\r\n\tforecolor?:string,\r\n\tbackcolor?:string,\r\n\tfontsize?:number,\r\n\tisd2dcanvas?:boolean,\r\n\timports?:{},\r\n}\r\n\r\nexport interface IModParams {\r\n\tstdio:TStdioVals, \r\n\twindim:[number, number],\r\n\tforecolor:string,\r\n\tbackcolor:string,\r\n\tfontsize:number,\r\n\tstyleIsDefault: boolean\r\n\tisd2dcanvas:boolean,\r\n\timports:{[index:string]:Function},\r\n}\r\n\r\nexport interface IModInWorkerParams {\r\n\tdivProxyParams:TDivProxyParams,\r\n\tcanvasProxyParams:TCanvasProxyParams,\r\n\twaitingCallsProxyParams:TWaitingCallsProxyParams,\r\n}\r\n\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n\r\nexport abstract class twrWasmModuleBase {\r\n\tmemory?:WebAssembly.Memory;\r\n\tmem8:Uint8Array;\r\n\tmem32:Uint32Array;\r\n\tmemD:Float64Array;\r\n\tabstract malloc:(size:number)=>Promise;\r\n\tabstract modParams:IModParams;\r\n\texports?:WebAssembly.Exports;\r\n\tisWorker=false;\r\n\tisWasmModule:boolean; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\r\n\tfloatUtil:twrFloatUtil;\r\n\r\n\tconstructor(isWasmModule=false) {\r\n\t\tthis.isWasmModule=isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\r\n\t\tthis.mem8=new Uint8Array(); \t// avoid type errors\r\n\t\tthis.mem32=new Uint32Array(); // avoid type errors\r\n\t\tthis.memD=new Float64Array(); // avoid type errors\r\n\t\tthis.floatUtil=new twrFloatUtil(this);\r\n\t\t//console.log(\"size of mem8 after constructor\",this.mem8.length);\r\n\t}\r\n\r\n\t/*********************************************************************/\r\n\t/*********************************************************************/\r\n\r\n\tasync loadWasm(pathToLoad:string) {\r\n\t\t//console.log(\"fileToLoad\",fileToLoad)\r\n\r\n\t\tlet response;\r\n\t\ttry {\r\n\t\t\tresponse=await fetch(pathToLoad);\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('loadWasm() failed to fetch: '+pathToLoad);\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t\t\r\n\t\tif (!response.ok) throw new Error(\"fetch response error on file '\"+pathToLoad+\"'\\n\"+response.statusText);\r\n\r\n\t\ttry {\r\n\t\t\tlet wasmBytes = await response.arrayBuffer();\r\n\r\n\t\t\tlet allimports:WebAssembly.ModuleImports = { \r\n\t\t\t\t...this.modParams.imports\r\n\t\t\t};\r\n\r\n\t\t\tlet instance = await WebAssembly.instantiate(wasmBytes, {env: allimports});\r\n\r\n\t\t\tthis.exports=instance.instance.exports;\r\n\t\t\tif (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\r\n\r\n\t\t\tif (this.memory) throw new Error (\"unexpected error -- this.memory already set\");\r\n\t\t\tthis.memory=this.exports.memory as WebAssembly.Memory;\r\n\t\t\tif (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\r\n\t\t\tthis.mem8 = new Uint8Array(this.memory.buffer);\r\n\t\t\tthis.mem32 = new Uint32Array(this.memory.buffer);\r\n\t\t\tthis.memD = new Float64Array(this.memory.buffer);\r\n\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\tif (this.isWorker) {\r\n\t\t\t\tif (this.memory.buffer instanceof ArrayBuffer)\r\n\t\t\t\t\tconsole.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\r\n\t\t\t\t\r\n\t\t\t\tpostMessage([\"setmemory\",this.memory]);\r\n\t\t\t}\r\n\t\t\tif (this.isWasmModule) {\r\n\t\t\t\t// here if twrWasmModule, twrWasmModuleAsync overrides this function\r\n\t\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\t\tif (!(this.memory.buffer instanceof ArrayBuffer))\r\n\t\t\t\t\tconsole.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\r\n\t\t\t}\r\n\r\n\t\t\tthis.malloc=(size:number)=>{\r\n\t\t\t\treturn new Promise(resolve => {\r\n\t\t\t\t\tconst m=this.exports!.twr_malloc as (size:number)=>number;\r\n\t\t\t\t\tresolve(m(size));\r\n\t\t\t\t});\r\n\t\t };\r\n\r\n\t\t\tthis.init();\r\n\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t}\r\n\r\n\tprivate init() {\r\n\t\t//console.log(\"loadWasm.init() enter\")\r\n\t\t\tlet p:number;\r\n\t\t\tswitch (this.modParams.stdio) {\r\n\t\t\t\tcase \"debug\":\r\n\t\t\t\t\tp=0;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"div\":\r\n\t\t\t\t\tp=1;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"canvas\":\r\n\t\t\t\t\tp=2;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"null\":\r\n\t\t\t\t\tp=3;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tp=0; // debug\r\n\t\t\t}\r\n\r\n\t\t\tconst twrInit=this.exports!.twr_wasm_init as CallableFunction;\r\n\t\t\t//console.log(\"twrInit:\",twrInit)\r\n\t\t\ttwrInit(p, this.mem8.length);\r\n\t}\r\n\r\n\t/* callC takes an array where:\r\n\t* the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\r\n\t* and the next entries are a variable number of parameters to pass to the C function, of type\r\n\t* number - converted to int32 or float64 as appropriate\r\n\t* string - converted to a an index (ptr) into a module Memory returned via stringToMem()\r\n\t* URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\r\n\t* Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\r\n */\r\n\r\n\tasync callC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\t\tconst cparams=await this.preCallC(params);\r\n\t\tlet retval = this.callCImpl(params[0], cparams);\r\n\t\tthis.postCallC(cparams, params);\r\n\t\treturn retval;\r\n\t}\r\n\r\n\tasync callCImpl(fname:string, cparams:number[]=[]) {\r\n\t\tif (!this.exports) throw new Error(\"this.exports undefined\");\r\n\t\tif (!this.exports[fname]) throw new Error(\"callC: function '\"+fname+\"' not in export table. Use --export wasm-ld flag.\");\r\n\r\n\t\tconst f = this.exports[fname] as CallableFunction;\r\n\t\tlet cr=f(...cparams);\r\n\r\n\t\treturn cr;\r\n\t}\r\n\r\n\t// convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\r\n\tasync preCallC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tif (!(params.constructor === Array)) throw new Error (\"callC: params must be array, first arg is function name\");\r\n\t\tif (params.length==0) throw new Error(\"callC: missing function name\");\r\n\r\n\t\tlet cparams:number[]=[];\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tcparams[ci++]=p;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tcparams[ci++]=await this.putString(p);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tconst r=await this.fetchAndPutURL(p);\r\n\t\t\t\t\t\tcparams[ci++]=r[0]; // mem index\r\n\t\t\t\t\t\tcparams[ci++]=r[1]; // len\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tconst r=await this.putArrayBuffer(p);\r\n\t\t\t\t\t\tcparams[ci++]=r; // mem index\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tthrow new Error (\"callC: invalid object type passed in\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn cparams;\r\n\t}\r\n\r\n\t// free the mallocs; copy array buffer data from malloc back to arraybuffer\r\n\tasync postCallC(cparams:number[], params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tthis.callCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t\t\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tthis.callCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\t\tci=ci+2;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tlet u8=new Uint8Array(p);\r\n\t\t\t\t\t\tfor (let j=0; j= this.mem32.length) throw new Error(\"invalid index passed to getLong: \"+idx+\", this.mem32.length: \"+this.mem32.length);\r\n\t\tconst long:number = this.mem32[idx32];\r\n\t\treturn long;\r\n\t}\r\n\t\r\n\tsetLong(idx:number, value:number) {\r\n const idx32 = Math.floor(idx / 4);\r\n if (idx32 * 4 != idx)\r\n throw new Error(\"setLong passed non long aligned address\");\r\n if (idx32 < 0 || idx32 >= this.mem32.length)\r\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\r\n this.mem32[idx32]=value;\r\n }\r\n\r\n\tgetDouble(idx:number): number {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"getLong passed non Float64 aligned address\")\r\n\t\tconst long:number = this.memD[idx64];\r\n\t\treturn long;\r\n\t}\r\n\r\n\tsetDouble(idx:number, value:number) {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"setDouble passed non Float64 aligned address\")\r\n\t\tthis.memD[idx64]=value;\r\n\t}\r\n\r\n\tgetShort(idx:number): number {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getShort: \"+idx);\r\n\t\tconst short:number = this.mem8[idx]+this.mem8[idx+1]*256;\r\n\t\treturn short;\r\n\t}\r\n\r\n\t// get a string out of module memory\r\n\t// null terminated, up until max of (optional) len\r\n\tgetString(strIndex:number, len?:number): string {\r\n\t\tlet sout=\"\";\r\n\r\n\t\tlet i=0;\r\n\t\twhile (this.mem8[strIndex+i] && (len===undefined?true:i= this.mem8.length) throw new Error(\"invalid index passed to getU8: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU8\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU8\")\r\n\r\n\t\tconst u8=this.mem8.slice(dataptr, dataptr+size);\r\n\t\treturn u8;\r\n\t}\r\n\r\n\t// get a int32 array out of module memory when passed in index to [size, dataptr]\r\n\tgetU32Arr(idx:number): Uint32Array {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getU32: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU32\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU32\")\r\n\r\n\t\tif (size%4!=0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\r\n\r\n\t\tconst u32 = new Uint32Array( (this.mem8.slice(dataptr, dataptr+size)).buffer );\r\n\t\treturn u32;\r\n\t}\r\n}\r\n","export class twrFloatUtil {\n mod;\n constructor(mod) {\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\")\n return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\")\n return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll('D', 'e').replaceAll('d', 'e'));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n }\n else {\n let r = value.toString();\n if (r.length > max_precision)\n r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, // char *\n sizeInBytes, //size_t\n value, // double\n fracpart_numdigits, //int\n dec, // int *\n sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1)\n return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) { /* nan */\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (!Number.isFinite(value)) { /* infinity */\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n }\n else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split('.');\n if (intPart == \"0\")\n intPart = \"\";\n if (intPart.length > 0) { // has integer part\n decpos = intPart.length;\n digits = intPart + fracPart;\n }\n else { // only a fraction\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length)\n return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */\n }\n}\n//# sourceMappingURL=twrfloat.js.map","\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\"\r\n\r\nexport class twrFloatUtil {\r\n mod: twrWasmModuleBase;\r\n\r\n constructor(mod: twrWasmModuleBase) {\r\n this.mod=mod;\r\n }\r\n\r\n atod(strptr:number):number {\r\n const str=this.mod.getString(strptr);\r\n\r\n const upper=str.trimStart().toUpperCase();\r\n if (upper==\"INF\" || upper==\"+INF\")\r\n return Number.POSITIVE_INFINITY;\r\n else if (upper==\"-INF\")\r\n return Number.NEGATIVE_INFINITY\r\n else {\r\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\r\n const r=Number.parseFloat(str.replaceAll('D','e').replaceAll('d','e'));\r\n return r;\r\n }\r\n }\r\n\r\n dtoa(buffer:number, buffer_size:number, value:number, max_precision:number):void {\r\n if (max_precision==-1) {\r\n const r=value.toString();\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n else {\r\n let r=value.toString();\r\n if (r.length>max_precision)\r\n r=value.toPrecision(max_precision);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n }\r\n\r\n toFixed(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toFixed(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n toExponential(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toExponential(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\r\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\r\n // Negative exponents must be now smaller than 1e-99\r\n // fully-function C version also int he source, but this is the version enabled by default\r\n fcvtS(\r\n buffer:number, // char *\r\n sizeInBytes:number, //size_t\r\n value:number, // double\r\n fracpart_numdigits:number, //int\r\n dec:number, // int *\r\n sign:number // int *\r\n ):number {\r\n\r\n if (buffer==0 ||sign==0 || dec==0 || sizeInBytes<1) return 1;\r\n\r\n let digits:string;\r\n let decpos:number;\r\n let s=0; // default to positive\r\n\r\n\r\n if (Number.isNaN(value)) { /* nan */\r\n digits=\"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (!Number.isFinite(value)) { /* infinity */\r\n digits=\"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (value==0) { \r\n digits=\"000000000000000000000000000000000000\".slice(0,fracpart_numdigits);\r\n decpos=0;\r\n }\r\n \r\n else {\r\n\r\n if (value<0) {\r\n s=1; // negative\r\n value=Math.abs(value);\r\n }\r\n\r\n if (fracpart_numdigits>100 || value > 1e+21 || value < 1e-99) { \r\n this.mod.copyString(buffer, sizeInBytes, \"\");\r\n this.mod.mem32[dec]=0;\r\n return 1;\r\n }\r\n\r\n const roundValStr=value.toFixed(fracpart_numdigits);\r\n let [intPart=\"\", fracPart=\"\"] = roundValStr.split('.');\r\n if (intPart==\"0\") intPart=\"\";\r\n\r\n if (intPart.length>0) { // has integer part\r\n decpos=intPart.length;\r\n digits=intPart+fracPart;\r\n }\r\n else { // only a fraction\r\n digits=fracPart.replace(/^0+/,\"\"); // remove leading zeros\r\n decpos=digits.length-fracPart.length;\r\n }\r\n }\r\n\r\n if (sizeInBytes-1 < digits.length) return 1; \r\n this.mod.copyString(buffer, sizeInBytes, digits);\r\n this.mod.setLong(dec, decpos);\r\n this.mod.setLong(sign, s);\r\n\r\n return 0;\r\n\r\n /*\r\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\r\n\r\n let decpos=0;\r\n let digits:string;\r\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\r\n \r\n if (decpos>0) { // has integer part\r\n const intlen=Math.max(decpos, 0);\r\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\r\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\r\n }\r\n else { // only a fraction\r\n const intpart=Math.trunc(value);\r\n const fracpart=value-intpart;\r\n const prec=fracpart_numdigits- (-decpos);\r\n console.log(\"prec=\",prec);\r\n if (prec<1) {\r\n digits=\"\";\r\n }\r\n else {\r\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\");\r\n }\r\n }\r\n\r\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\r\n console.log('digits=',digits);\r\n console.log('dec=',decpos);\r\n console.log(\"sign=\",s);\r\n */\r\n\r\n\r\n }\r\n}","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nimport { twrSignal } from \"./twrsignal.js\";\nvar D2DType;\n(function (D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})(D2DType || (D2DType = {}));\nexport class twrCanvas {\n ctx;\n props = { charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight: 0, canvasWidth: 0 };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase) {\n const { forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new twrSignal();\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext)\n throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c)\n throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2)\n throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\n }\n getProp(pn) {\n if (!this.isValid())\n console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */\n drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid())\n console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx)\n return;\n let ins = this.owner.getLong(ds); /* ds->start */\n const lastins = this.owner.getLong(ds + 4); /* ds->last */\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while (1) {\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */\n if (0 /*type!=D2DType.D2D_FILLRECT*/) {\n console.log(\"ins\", ins);\n console.log(\"hdr.next\", this.owner.mem8[ins], this.owner.mem8[ins + 1], this.owner.mem8[ins + 2], this.owner.mem8[ins + 3]);\n console.log(\"hdr.type\", this.owner.mem8[ins + 4], this.owner.mem8[ins + 5]);\n console.log(\"next 4 bytes\", this.owner.mem8[ins + 6], this.owner.mem8[ins + 7], this.owner.mem8[ins + 8], this.owner.mem8[ins + 9]);\n console.log(\"and 4 more \", this.owner.mem8[ins + 10], this.owner.mem8[ins + 11], this.owner.mem8[ins + 12], this.owner.mem8[ins + 13]);\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\n }\n switch (type) {\n case D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case D2DType.D2D_BEGINPATH:\n {\n this.ctx.beginPath();\n }\n break;\n case D2DType.D2D_FILL:\n {\n this.ctx.fill();\n }\n break;\n case D2DType.D2D_SAVE:\n {\n this.ctx.save();\n }\n break;\n case D2DType.D2D_RESTORE:\n {\n this.ctx.restore();\n }\n break;\n case D2DType.D2D_STROKE:\n {\n this.ctx.stroke();\n }\n break;\n case D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = (this.owner.getLong(ins + 48) != 0);\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n }\n else { // Uint8ClampedArray doesn't support shared memory\n this.precomputedObjects[id] = { mem8: new Uint8Array(this.owner.memory.buffer, start, length), width: width, height: height };\n }\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id])\n delete this.precomputedObjects[id];\n else\n console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) {\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n }\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) {\n this.ctx.putImageData(imgData, dx, dy);\n }\n else {\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */\n if (next == 0) {\n if (ins != lastins)\n throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal)\n this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nexport class twrCanvasProxy {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner) {\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new twrSignal(signalBuffer);\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\"drawseq\", [ds]]);\n this.drawCompleteSignal.wait();\n }\n}\n//# sourceMappingURL=twrcanvas.js.map","import {twrWasmModuleBase, IModParams} from \"./twrmodbase.js\"\r\nimport {twrSharedCircularBuffer} from \"./twrcircular.js\";\r\nimport {twrSignal} from \"./twrsignal.js\";\r\n\r\n\r\n// Canvas have a size that will be set based on the character width x height\r\n// The display size for a canvas will default to this size, but can be changed in the HTML/JS via\r\n// canvas.style.width = \"700px\";\r\n// canvas.style.height = \"500px\";\r\n\r\nexport interface ICanvasProps {\r\n\tcharWidth: number,\r\n\tcharHeight: number,\r\n\tforeColor: number,\r\n\tbackColor: number,\r\n widthInChars: number,\r\n heightInChars: number,\r\n canvasWidth:number,\r\n canvasHeight:number\r\n}\r\n\r\nenum D2DType {\r\n D2D_FILLRECT=1,\r\n D2D_FILLCHAR=5,\r\n D2D_SETLINEWIDTH=10,\r\n D2D_SETFILLSTYLERGBA=11,\r\n D2D_SETFONT=12,\r\n D2D_BEGINPATH=13,\r\n D2D_MOVETO=14,\r\n D2D_LINETO=15,\r\n D2D_FILL=16,\r\n D2D_STROKE=17,\r\n D2D_SETSTROKESTYLERGBA=18,\r\n D2D_ARC=19,\r\n D2D_STROKERECT=20,\r\n D2D_FILLTEXT=21,\r\n D2D_IMAGEDATA=22,\r\n D2D_PUTIMAGEDATA=23,\r\n D2D_BEZIERTO=24,\r\n D2D_MEASURETEXT=25,\r\n D2D_SAVE=26,\r\n D2D_RESTORE=27,\r\n D2D_CREATERADIALGRADIENT=28,\r\n D2D_SETCOLORSTOP=29,\r\n D2D_SETFILLSTYLEGRADIENT=30,\r\n D2D_RELEASEID=31,\r\n D2D_CREATELINEARGRADIENT=32,\r\n D2D_SETFILLSTYLE=33,\r\n D2D_SETSTROKESTYLE=34\r\n\r\n}\r\n\r\nexport type TCanvasProxyParams = [ICanvasProps, SharedArrayBuffer, SharedArrayBuffer];\r\n\r\nexport interface ICanvas {\r\n props: ICanvasProps,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TCanvasProxyParams,\r\n drawSeq: (ds:number)=>void,\r\n }\r\n \r\nexport class twrCanvas implements ICanvas {\r\n ctx:CanvasRenderingContext2D|undefined;\r\n props:ICanvasProps={charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight:0, canvasWidth:0};\r\n owner: twrWasmModuleBase;\r\n cmdCompleteSignal?:twrSignal;\r\n canvasKeys?: twrSharedCircularBuffer;\r\n precomputedObjects: { [index: number]: \r\n (ImageData | {mem8:Uint8Array, width:number, height:number}) |\r\n CanvasGradient\r\n };\r\n\r\n constructor(element:HTMLCanvasElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n const {forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas} = modParams; \r\n this.owner=modbase;\r\n this.props.widthInChars=modParams.windim[0];\r\n this.props.heightInChars=modParams.windim[1];\r\n\r\n if (!this.owner.isWasmModule) {\r\n this.cmdCompleteSignal=new twrSignal();\r\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n }\r\n\r\n this.precomputedObjects={};\r\n \r\n if (element) {\r\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\r\n let c=element.getContext(\"2d\");\r\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\r\n\r\n c.font = fontsize.toString()+\"px Courier New\";\r\n c.textBaseline=\"top\";\r\n const sampleText=\" \";\r\n const tm=c.measureText(sampleText);\r\n this.props.charWidth=Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\r\n let fM = c.measureText(\"X\"); \r\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\r\n\r\n if (!isd2dcanvas) {\r\n element.width=this.props.charWidth*this.props.widthInChars;\r\n element.height=this.props.charHeight*this.props.heightInChars;\r\n }\r\n\r\n this.props.canvasHeight=element.height;\r\n this.props.canvasWidth=element.width;\r\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\r\n\r\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\r\n let c2=element.getContext(\"2d\");\r\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\r\n this.ctx=c2;\r\n this.ctx.font = fontsize.toString()+\"px Courier New\";\r\n this.ctx.textBaseline=\"top\";\r\n\r\n c2.fillStyle=backcolor;\r\n this.props.backColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n c2.fillStyle=forecolor;\r\n this.props.foreColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n }\r\n\r\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\r\n\r\n //console.log(\"twrCanvas.constructor props: \", this.props);\r\n }\r\n\r\n isValid() {\r\n return !!this.ctx;\r\n }\r\n\r\n getProxyParams() : TCanvasProxyParams {\r\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\r\n }\r\n\r\n getProp(pn:number): number {\r\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n\r\n/* see draw2d.h for structs that match */\r\n\r\n drawSeq(ds:number) {\r\n //console.log(\"twr::Canvas enter drawSeq\");\r\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\r\n if (!this.ctx) return;\r\n\r\n let ins=this.owner.getLong(ds); /* ds->start */\r\n const lastins=this.owner.getLong(ds+4); /* ds->last */\r\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\r\n\r\n let next:number;\r\n //let insCount=0;\r\n\r\n while (1) {\r\n\r\n //insCount++;\r\n\r\n const type:D2DType=this.owner.getLong(ins+4); /* hdr->type */\r\n if (0/*type!=D2DType.D2D_FILLRECT*/) {\r\n console.log(\"ins\",ins)\r\n console.log(\"hdr.next\",this.owner.mem8[ins],this.owner.mem8[ins+1],this.owner.mem8[ins+2],this.owner.mem8[ins+3]);\r\n console.log(\"hdr.type\",this.owner.mem8[ins+4],this.owner.mem8[ins+5]);\r\n console.log(\"next 4 bytes\", this.owner.mem8[ins+6],this.owner.mem8[ins+7],this.owner.mem8[ins+8],this.owner.mem8[ins+9]);\r\n console.log(\"and 4 more \", this.owner.mem8[ins+10],this.owner.mem8[ins+11],this.owner.mem8[ins+12],this.owner.mem8[ins+13]);\r\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\r\n }\r\n switch (type) {\r\n case D2DType.D2D_FILLRECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.fillRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKERECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.strokeRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILLCHAR:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const c=this.owner.getShort(ins+24);\r\n let txt=String.fromCharCode(c);\r\n this.ctx.fillText(txt, x, y);\r\n }\r\n break;\r\n\r\n \r\n case D2DType.D2D_FILLTEXT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const str=this.owner.getString(this.owner.getLong(ins+24));\r\n\r\n //console.log(\"filltext \",x,y,str)\r\n \r\n this.ctx.fillText(str, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MEASURETEXT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n const tmidx=this.owner.getLong(ins+12);\r\n \r\n const tm=this.ctx.measureText(str);\r\n this.owner.setDouble(tmidx+0, tm.actualBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+8, tm.actualBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+16, tm.actualBoundingBoxLeft);\r\n this.owner.setDouble(tmidx+24, tm.actualBoundingBoxRight);\r\n this.owner.setDouble(tmidx+32, tm.fontBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+40, tm.fontBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+48, tm.width);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFONT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.font=str;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.fillStyle = cssColor;\r\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETSTROKESTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.fillStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETSTROKESTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETLINEWIDTH:\r\n {\r\n const width=this.owner.getShort(ins+8); \r\n this.ctx.lineWidth=width;\r\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MOVETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.moveTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_LINETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.lineTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEZIERTO:\r\n {\r\n const cp1x=this.owner.getDouble(ins+8);\r\n const cp1y=this.owner.getDouble(ins+16);\r\n const cp2x=this.owner.getDouble(ins+24);\r\n const cp2y=this.owner.getDouble(ins+32);\r\n const x=this.owner.getDouble(ins+40);\r\n const y=this.owner.getDouble(ins+48);\r\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEGINPATH:\r\n {\r\n this.ctx.beginPath();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILL:\r\n {\r\n this.ctx.fill();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SAVE:\r\n {\r\n this.ctx.save();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_RESTORE:\r\n {\r\n this.ctx.restore();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKE:\r\n {\r\n this.ctx.stroke();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_ARC:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const radius=this.owner.getDouble(ins+24);\r\n const startAngle=this.owner.getDouble(ins+32);\r\n const endAngle=this.owner.getDouble(ins+40);\r\n const counterClockwise= (this.owner.getLong(ins+48)!=0);\r\n\r\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_IMAGEDATA:\r\n {\r\n const start=this.owner.getLong(ins+8);\r\n const length=this.owner.getLong(ins+12);\r\n const width=this.owner.getLong(ins+16);\r\n const height=this.owner.getLong(ins+20);\r\n const id=this.owner.getLong(ins+24);\r\n\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\r\n\r\n if (this.owner.isWasmModule) {\r\n const z = new Uint8ClampedArray(this.owner.memory!.buffer, start, length);\r\n this.precomputedObjects[id]=new ImageData(z, width, height);\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory\r\n this.precomputedObjects[id]={mem8: new Uint8Array(this.owner.memory!.buffer, start, length), width:width, height:height};\r\n }\r\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_CREATERADIALGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const radius0=this.owner.getDouble(ins+24);\r\n const x1=this.owner.getDouble(ins+32);\r\n const y1=this.owner.getDouble(ins+40);\r\n const radius1=this.owner.getDouble(ins+48);\r\n const id= this.owner.getLong(ins+56);\r\n\r\n let gradient=this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_CREATELINEARGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const x1=this.owner.getDouble(ins+24);\r\n const y1=this.owner.getDouble(ins+32);\r\n const id= this.owner.getLong(ins+40);\r\n \r\n let gradient=this.ctx.createLinearGradient(x0, y0, x1, y1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETCOLORSTOP:\r\n {\r\n const id = this.owner.getLong(ins+8);\r\n const pos=this.owner.getLong(ins+12);\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+16));\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n gradient.addColorStop(pos, cssColor);\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n this.ctx.fillStyle=gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_RELEASEID:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (this.precomputedObjects[id])\r\n delete this.precomputedObjects[id];\r\n else\r\n console.log(\"warning: D2D_RELEASEID with undefined ID \",id);\r\n }\r\n break\r\n\r\n \r\n\r\n case D2DType.D2D_PUTIMAGEDATA:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n const dx=this.owner.getLong(ins+12);\r\n const dy=this.owner.getLong(ins+16);\r\n const dirtyX=this.owner.getLong(ins+20);\r\n const dirtyY=this.owner.getLong(ins+24);\r\n const dirtyWidth=this.owner.getLong(ins+28);\r\n const dirtyHeight=this.owner.getLong(ins+32);\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \"+id);\r\n\r\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\r\n\r\n let imgData:ImageData;\r\n if (this.owner.isWasmModule) {\r\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\r\n imgData=this.precomputedObjects[id] as ImageData;\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\r\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\r\n const z = this.precomputedObjects[id] as {mem8:Uint8Array, width:number, height:number}; // Uint8Array\r\n const ca=Uint8ClampedArray.from(z.mem8); // shallow copy\r\n imgData=new ImageData(ca, z.width, z.height);\r\n }\r\n \r\n if (dirtyWidth==0 && dirtyHeight==0) {\r\n this.ctx.putImageData(imgData, dx, dy);\r\n }\r\n else {\r\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\r\n }\r\n }\r\n break;\r\n\r\n default:\r\n throw new Error (\"unimplemented or unknown Sequence Type in drawSeq: \"+type);\r\n }\r\n next=this.owner.getLong(ins); /* hdr->next */\r\n if (next==0) {\r\n if (ins!=lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\r\n break;\r\n }\r\n ins=next;\r\n }\r\n\r\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\r\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\r\n }\r\n}\r\n\r\nexport class twrCanvasProxy implements ICanvas {\r\n canvasKeys: twrSharedCircularBuffer;\r\n drawCompleteSignal:twrSignal;\r\n props: ICanvasProps;\r\n owner: twrWasmModuleBase;\r\n\r\n constructor(params:TCanvasProxyParams, owner:twrWasmModuleBase) {\r\n const [props, signalBuffer, canvasKeysBuffer] = params;\r\n this.drawCompleteSignal = new twrSignal(signalBuffer);\r\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\r\n this.props=props;\r\n this.owner=owner;\r\n\r\n //console.log(\"Create New twrCanvasProxy: \",this.props)\r\n\r\n }\r\n\r\n charIn() { \r\n //ctx.commit(); not avail in chrome\r\n \r\n //postMessage([\"debug\", 'x']);\r\n \r\n return this.canvasKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.canvasKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n getProp(pn:number): number {\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n \r\n drawSeq(ds:number) {\r\n this.drawCompleteSignal.reset();\r\n postMessage([\"drawseq\", [ds]]);\r\n this.drawCompleteSignal.wait();\r\n }\r\n}\r\n","//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar twrSignalState;\n(function (twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})(twrSignalState || (twrSignalState = {}));\n;\nexport class twrSignal {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window valid\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == twrSignalState.WAITING) {\n //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\n //console.log(\"released...\");\n }\n }\n isSignaled() {\n return this.buf[0] == twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = twrSignalState.WAITING;\n }\n}\n//# sourceMappingURL=twrsignal.js.map","//\r\n// This class implements a simple signal/wait mechanism\r\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\r\n//\r\n\r\nenum twrSignalState {\r\n WAITING=0,\r\n SIGNALED=1\r\n};\r\n\r\nexport class twrSignal {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n\r\n \tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window valid\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) \r\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[0]=twrSignalState.WAITING;\r\n\t}\r\n\r\n\tsignal() {\r\n this.buf[0]=twrSignalState.SIGNALED; \r\n //console.log(\"about to signal\");\r\n Atomics.notify(this.buf, 0); \r\n\t}\r\n\r\n wait() {\r\n if (this.buf[0]==twrSignalState.WAITING) {\r\n //console.log(\"waiting...\");\r\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\r\n //console.log(\"released...\");\r\n\r\n }\r\n\t}\r\n isSignaled():boolean {\r\n return this.buf[0]==twrSignalState.SIGNALED;\r\n }\r\n\r\n reset() {\r\n this.buf[0]=twrSignalState.WAITING;\r\n }\r\n}\r\n","export function twrTimeImpl() {\n return Date.now();\n}\n//# sourceMappingURL=twrdate.js.map","\r\nexport function twrTimeImpl() {\r\n\r\n return Date.now();\r\n\r\n}","import { twrDebugLogImpl } from \"./twrdebug.js\";\nimport { twrWasmModuleInJSMain } from \"./twrmodjsmain.js\";\nimport { twrWaitingCalls } from \"./twrwaitingcalls.js\";\nimport whatkey from \"whatkey\";\nexport class twrWasmModuleAsync extends twrWasmModuleInJSMain {\n myWorker;\n malloc;\n loadWasmResolve;\n loadWasmReject;\n callCResolve;\n callCReject;\n initLW = false;\n waitingcalls;\n constructor(opts) {\n super(opts);\n this.malloc = (size) => { throw new Error(\"Error - un-init malloc called.\"); };\n if (!window.Worker)\n throw new Error(\"This browser doesn't support web workers.\");\n this.myWorker = new Worker(new URL('twrmodworker.js', import.meta.url), { type: \"module\" });\n this.myWorker.onmessage = this.processMsg.bind(this);\n }\n // overrides base implementation\n async loadWasm(pathToLoad) {\n if (this.initLW)\n throw new Error(\"twrWasmAsyncModule::loadWasm can only be called once per twrWasmAsyncModule instance\");\n this.initLW = true;\n return new Promise((resolve, reject) => {\n this.loadWasmResolve = resolve;\n this.loadWasmReject = reject;\n this.malloc = (size) => {\n return this.callCImpl(\"twr_malloc\", [size]);\n };\n this.waitingcalls = new twrWaitingCalls(); // handle's calls that cross the worker thread - main js thread boundary\n let canvas;\n if (this.d2dcanvas.isValid())\n canvas = this.d2dcanvas;\n else\n canvas = this.iocanvas;\n const modWorkerParams = {\n divProxyParams: this.iodiv.getProxyParams(),\n canvasProxyParams: canvas.getProxyParams(),\n waitingCallsProxyParams: this.waitingcalls.getProxyParams(),\n };\n const urlToLoad = new URL(pathToLoad, document.URL);\n const startMsg = { urlToLoad: urlToLoad.href, modWorkerParams: modWorkerParams, modParams: this.modParams };\n this.myWorker.postMessage(['startup', startMsg]);\n });\n }\n async callC(params) {\n const cparams = await this.preCallC(params); // will also validate params[0]\n return this.callCImpl(params[0], cparams);\n }\n async callCImpl(fname, cparams = []) {\n return new Promise((resolve, reject) => {\n this.callCResolve = resolve;\n this.callCReject = reject;\n this.myWorker.postMessage(['callC', fname, cparams]);\n });\n }\n // this function should be called from HTML \"keydown\" event from
\n keyDownDiv(ev) {\n if (!this.iodiv || !this.iodiv.divKeys)\n throw new Error(\"unexpected undefined twrWasmAsyncModule.divKeys\");\n this.iodiv.divKeys.write(whatkey(ev).char.charCodeAt(0));\n }\n // this function should be called from HTML \"keydown\" event from \n keyDownCanvas(ev) {\n if (!this.iocanvas || !this.iocanvas.canvasKeys)\n throw new Error(\"unexpected undefined twrWasmAsyncModule.canvasKeys\");\n this.iocanvas.canvasKeys.write(whatkey(ev).char.charCodeAt(0));\n }\n processMsg(event) {\n const msgType = event.data[0];\n const d = event.data[1];\n //console.log(\"twrWasmAsyncModule - got message: \"+event.data)\n switch (msgType) {\n case \"divout\":\n if (this.iodiv.isValid())\n this.iodiv.charOut(d);\n else\n console.log('error - msg divout received but iodiv is undefined.');\n break;\n case \"debug\":\n twrDebugLogImpl(d);\n break;\n case \"drawseq\":\n {\n //console.log(\"twrModAsync got message drawseq\");\n const [ds] = d;\n if (this.iocanvas.isValid())\n this.iocanvas.drawSeq(ds);\n else if (this.d2dcanvas.isValid())\n this.d2dcanvas.drawSeq(ds);\n else\n throw new Error('msg drawseq received but canvas is undefined.');\n break;\n }\n case \"setmemory\":\n this.memory = d;\n if (!this.memory)\n throw new Error(\"unexpected error - undefined memory in startupOkay msg\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n //console.log(\"memory set\",this.mem8.length);\n break;\n case \"startupFail\":\n if (this.loadWasmReject)\n this.loadWasmReject(d);\n else\n throw new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmReject)\");\n break;\n case \"startupOkay\":\n if (this.loadWasmResolve)\n this.loadWasmResolve(undefined);\n else\n throw new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmResolve)\");\n break;\n case \"callCFail\":\n if (this.callCReject)\n this.callCReject(d);\n else\n throw new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined callCReject)\");\n break;\n case \"callCOkay\":\n if (this.callCResolve)\n this.callCResolve(d);\n else\n throw new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined callCResolve)\");\n break;\n default:\n if (!this.waitingcalls)\n throw new Error(\"internal error: this.waitingcalls undefined.\");\n if (!this.waitingcalls.processMessage(msgType, d))\n throw new Error(\"twrWasmAsyncModule - unknown and unexpected msgType: \" + msgType);\n }\n }\n}\n//# sourceMappingURL=twrmodasync.js.map","import {IModOpts, IModParams, IModInWorkerParams} from \"./twrmodbase.js\";\r\nimport {twrDebugLogImpl} from \"./twrdebug.js\";\r\nimport {twrWasmModuleInJSMain} from \"./twrmodjsmain.js\"\r\nimport {twrWaitingCalls} from \"./twrwaitingcalls.js\"\r\nimport {twrCanvas} from \"./twrcanvas.js\";\r\n\r\nimport whatkey from \"whatkey\";\r\n\r\nexport type TAsyncModStartupMsg = {\r\n\turlToLoad: string,\r\n\tmodWorkerParams: IModInWorkerParams,\r\n\tmodParams: IModParams \r\n};\r\n\t\t\r\nexport class twrWasmModuleAsync extends twrWasmModuleInJSMain {\r\n\tmyWorker:Worker;\r\n\tmalloc:(size:number)=>Promise;\r\n\tloadWasmResolve?: (value: void) => void;\r\n\tloadWasmReject?: (reason?: any) => void;\r\n\tcallCResolve?: (value: unknown) => void;\r\n\tcallCReject?: (reason?: any) => void;\r\n\tinitLW=false;\r\n\twaitingcalls?:twrWaitingCalls;\r\n\r\n\r\n\tconstructor(opts?:IModOpts) {\r\n\t\tsuper(opts);\r\n\r\n\t\tthis.malloc=(size:number)=>{throw new Error(\"Error - un-init malloc called.\")};\r\n\r\n\t\tif (!window.Worker) throw new Error(\"This browser doesn't support web workers.\");\r\n\t\tthis.myWorker = new Worker(new URL('twrmodworker.js', import.meta.url), {type: \"module\" });\r\n\t\tthis.myWorker.onmessage= this.processMsg.bind(this);\r\n\t}\r\n\r\n\t// overrides base implementation\r\n\tasync loadWasm(pathToLoad:string) {\r\n\t\tif (this.initLW) \tthrow new Error(\"twrWasmAsyncModule::loadWasm can only be called once per twrWasmAsyncModule instance\");\r\n\t\tthis.initLW=true;\r\n\r\n\t\treturn new Promise((resolve, reject)=>{\r\n\t\t\tthis.loadWasmResolve=resolve;\r\n\t\t\tthis.loadWasmReject=reject;\r\n\r\n\t\t\tthis.malloc = (size:number) => {\r\n\t\t\t\treturn this.callCImpl(\"twr_malloc\", [size]) as Promise;\r\n\t\t\t}\r\n\r\n\t\t\tthis.waitingcalls=new twrWaitingCalls(); // handle's calls that cross the worker thread - main js thread boundary\r\n\r\n\t\t\tlet canvas:twrCanvas;\r\n\t\t\tif (this.d2dcanvas.isValid()) canvas=this.d2dcanvas;\r\n\t\t\telse canvas=this.iocanvas;\r\n\r\n\t\t\tconst modWorkerParams={\r\n\t\t\t\tdivProxyParams: this.iodiv.getProxyParams(), \r\n\t\t\t\tcanvasProxyParams: canvas.getProxyParams(),\r\n\t\t\t\twaitingCallsProxyParams: this.waitingcalls.getProxyParams(),\r\n\t\t\t};\r\n\t\t\tconst urlToLoad = new URL(pathToLoad, document.URL);\r\n\t\t\tconst startMsg:TAsyncModStartupMsg={ urlToLoad: urlToLoad.href, modWorkerParams: modWorkerParams, modParams: this.modParams};\r\n\t\t\tthis.myWorker.postMessage(['startup', startMsg]);\r\n\t\t});\r\n\t}\r\n\r\n\tasync callC(params:[string, ...(string|number|Uint8Array)[]]) {\r\n\t\tconst cparams=await this.preCallC(params); // will also validate params[0]\r\n\t\treturn this.callCImpl(params[0], cparams);\r\n\t}\t\r\n\r\n\tasync callCImpl(fname:string, cparams:number[]=[]) {\r\n\t\treturn new Promise((resolve, reject)=>{\r\n\t\t\tthis.callCResolve=resolve;\r\n\t\t\tthis.callCReject=reject;\r\n\t\t\tthis.myWorker.postMessage(['callC', fname, cparams]);\r\n\t\t});\r\n\t}\r\n\t\r\n\t// this function should be called from HTML \"keydown\" event from
\r\n\tkeyDownDiv(ev:KeyboardEvent) {\r\n\t\tif (!this.iodiv || !this.iodiv.divKeys) throw new Error(\"unexpected undefined twrWasmAsyncModule.divKeys\");\r\n\t\tthis.iodiv.divKeys.write(whatkey(ev).char.charCodeAt(0));\r\n\t}\r\n\r\n\t// this function should be called from HTML \"keydown\" event from \r\n\tkeyDownCanvas(ev:KeyboardEvent) {\r\n\t\tif (!this.iocanvas || !this.iocanvas.canvasKeys) throw new Error(\"unexpected undefined twrWasmAsyncModule.canvasKeys\");\r\n\t\tthis.iocanvas.canvasKeys.write(whatkey(ev).char.charCodeAt(0));\r\n\t}\r\n\r\n\tprocessMsg(event: MessageEvent) {\r\n\t\tconst msgType=event.data[0];\r\n\t\tconst d=event.data[1];\r\n\r\n\t\t//console.log(\"twrWasmAsyncModule - got message: \"+event.data)\r\n\r\n\t\tswitch (msgType) {\r\n\t\t\tcase \"divout\":\r\n\t\t\t\tif (this.iodiv.isValid())\r\n\t\t\t\t\tthis.iodiv.charOut(d);\r\n\t\t\t\telse\r\n\t\t\t\t\tconsole.log('error - msg divout received but iodiv is undefined.')\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"debug\":\r\n\t\t\t\ttwrDebugLogImpl(d);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"drawseq\":\r\n\t\t\t{\r\n\t\t\t\t//console.log(\"twrModAsync got message drawseq\");\r\n\t\t\t\tconst [ds] = d;\r\n\t\t\t\tif (this.iocanvas.isValid())\r\n\t\t\t\t\tthis.iocanvas.drawSeq(ds);\r\n\t\t\t\telse if (this.d2dcanvas.isValid())\r\n\t\t\t\t\tthis.d2dcanvas.drawSeq(ds);\r\n\t\t\t\telse\r\n\t\t\t\t\tthrow new Error('msg drawseq received but canvas is undefined.')\r\n\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\t\tcase \"setmemory\":\r\n\t\t\t\tthis.memory=d;\r\n\t\t\t\tif (!this.memory) throw new Error(\"unexpected error - undefined memory in startupOkay msg\");\r\n\t\t\t\tthis.mem8 = new Uint8Array(this.memory.buffer);\r\n\t\t\t\tthis.mem32 = new Uint32Array(this.memory.buffer);\r\n\t\t\t\tthis.memD = new Float64Array(this.memory.buffer);\r\n\t\t\t\t//console.log(\"memory set\",this.mem8.length);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"startupFail\":\r\n\t\t\t\tif (this.loadWasmReject)\r\n\t\t\t\t\tthis.loadWasmReject(d);\r\n\t\t\t\telse\r\n\t\t\t\t\tthrow new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmReject)\");\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"startupOkay\":\r\n\r\n\t\t\t\tif (this.loadWasmResolve)\r\n\t\t\t\t\tthis.loadWasmResolve(undefined);\r\n\t\t\t\telse\r\n\t\t\t\t\tthrow new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmResolve)\");\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"callCFail\":\r\n\t\t\t\tif (this.callCReject)\r\n\t\t\t\t\tthis.callCReject(d);\r\n\t\t\t\telse\r\n\t\t\t\t\tthrow new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined callCReject)\");\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"callCOkay\":\r\n\t\t\t\tif (this.callCResolve)\r\n\t\t\t\t\tthis.callCResolve(d);\r\n\t\t\t\telse\r\n\t\t\t\t\tthrow new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined callCResolve)\");\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tdefault:\r\n\t\t\t\tif (!this.waitingcalls) throw new Error (\"internal error: this.waitingcalls undefined.\")\r\n\t\t\t\tif (!this.waitingcalls.processMessage(msgType, d))\r\n\t\t\t\t\tthrow new Error(\"twrWasmAsyncModule - unknown and unexpected msgType: \"+msgType);\r\n\t\t}\r\n\t}\r\n}\r\n","import { twrSignal } from \"./twrsignal.js\";\nimport { twrTimeImpl } from \"./twrdate.js\";\n// This class is used in the Main JS thread \nexport class twrWaitingCalls {\n callCompleteSignal;\n parameters;\n constructor() {\n this.callCompleteSignal = new twrSignal();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(() => {\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = twrTimeImpl();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [this.callCompleteSignal.sharedArray, this.parameters.buffer];\n }\n processMessage(msgType, data) {\n switch (msgType) {\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\n// This class is used in the worker thread \nexport class twrWaitingCallsProxy {\n callCompleteSignal;\n parameters;\n constructor(params) {\n this.callCompleteSignal = new twrSignal(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\"sleep\", [ms]]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\"time\"]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n//# sourceMappingURL=twrwaitingcalls.js.map","import { twrSignal } from \"./twrsignal.js\";\r\nimport {twrTimeImpl} from \"./twrdate.js\"\r\n\r\n// These classes are used to proxy a call across the worker thread - main thread boundary and wait for the result\r\n\r\nexport type TWaitingCallsProxyParams = [SharedArrayBuffer, SharedArrayBuffer]; // twrSignal, parameters \r\n\r\n// This class is used in the Main JS thread \r\nexport class twrWaitingCalls {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor() {\r\n\t\tthis.callCompleteSignal=new twrSignal();\r\n\t\tthis.parameters=new Uint32Array(new SharedArrayBuffer(4));\r\n\t}\r\n\r\n\tprivate startSleep(ms:number) {\r\n\r\n\t\tsetTimeout(()=>{\r\n\t\t\tthis.callCompleteSignal.signal();\r\n\t\t}, ms);\r\n\t\t\r\n\t}\r\n\r\n\tprivate time() {\r\n\t\tconst ms=twrTimeImpl();\r\n\t\tthis.parameters[0]=ms;\r\n\t\tthis.callCompleteSignal.signal();\r\n\t}\r\n\r\n\tgetProxyParams():TWaitingCallsProxyParams {\r\n\t\treturn [this.callCompleteSignal.sharedArray, this.parameters.buffer as SharedArrayBuffer];\t\r\n\t}\r\n\r\n\tprocessMessage(msgType:string, data:any[]):boolean {\r\n\t\tswitch (msgType) {\r\n\t\t\tcase \"sleep\":\r\n\t\t\t\tconst [ms] = data;\r\n\t\t\t\tthis.startSleep(ms);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"time\":\r\n\t\t\t\tthis.time();\r\n\t\t\t\tbreak;\r\n\t\t\t\r\n\t\t\tdefault:\r\n\t\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\treturn true;\r\n\t}\r\n\r\n}\r\n\r\n// This class is used in the worker thread \r\nexport class twrWaitingCallsProxy {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor(params:TWaitingCallsProxyParams) {\r\n\t\tthis.callCompleteSignal=new twrSignal(params[0]);\r\n\t\tthis.parameters=new Uint32Array(params[1]);\r\n\t}\r\n\r\n\tsleep(ms:number) {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"sleep\", [ms]]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t}\r\n\r\n\ttime() {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"time\"]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t\treturn this.parameters[0];\r\n\t}\r\n\r\n}\r\n","const keycodeCtrlKeys = {\n 'a': 'selectAll',\n 'c': 'copy',\n 's': 'save',\n 'v': 'paste',\n 'x': 'cut',\n 'y': 'redo',\n 'z': 'undo'\n};\n\nconst keycodeShiftedKeys = {\n '/': '?',\n '.': '>',\n ',': '<',\n '\\'': '\\\"',\n ';': ':',\n '[': '{',\n ']': '}',\n '\\\\': '|',\n '`': '~',\n '=': '+',\n '-': '_',\n '1': '!',\n '2': '@',\n '3': '#',\n '4': '$',\n '5': '%',\n '6': '^',\n '7': '&',\n '8': '*',\n '9': '(',\n '0': ')',\n 'a': 'A',\n 'b': 'B',\n 'c': 'C',\n 'd': 'D',\n 'e': 'E',\n 'f': 'F',\n 'g': 'G',\n 'h': 'H',\n 'i': 'I',\n 'j': 'J',\n 'k': 'K',\n 'l': 'L',\n 'm': 'M',\n 'n': 'N',\n 'o': 'O',\n 'p': 'P',\n 'q': 'q',\n 'r': 'R',\n 's': 'S',\n 't': 'T',\n 'u': 'U',\n 'v': 'V',\n 'w': 'W',\n 'x': 'X',\n 'y': 'Y',\n 'z': 'Z'\n};\n\nconst keyCodeUnshiftedKeys = {};\nfor (const x in keycodeShiftedKeys) {\n const shiftedKey = keycodeShiftedKeys[x];\n keyCodeUnshiftedKeys[shiftedKey] = x;\n}\n\nconst keydownKeycodeDictionary = {\n 0: '\\\\',\n\n 8: 'backspace',\n 9: 'tab',\n\n 12: 'num',\n 13: 'enter',\n\n 16: 'shift',\n 17: 'ctrl',\n 18: 'alt', // aka 'option'\n 19: 'pause', // or sometimes 'break'?\n 20: 'caps',\n\n 27: 'esc',\n\n 32: ' ',\n 33: 'pageup',\n 34: 'pagedown',\n 35: 'end',\n 36: 'home',\n 37: 'left',\n 38: 'up',\n 39: 'right',\n 40: 'down',\n\n 44: 'print',\n 45: 'insert',\n 46: 'delete',\n\n 48: '0',\n 49: '1',\n 50: '2',\n 51: '3',\n 52: '4',\n 53: '5',\n 54: '6',\n 55: '7',\n 56: '8',\n 57: '9',\n\n 59: ';',\n\n 61: '=',\n\n 65: 'a',\n 66: 'b',\n 67: 'c',\n 68: 'd',\n 69: 'e',\n 70: 'f',\n 71: 'g',\n 72: 'h',\n 73: 'i',\n 74: 'j',\n 75: 'k',\n 76: 'l',\n 77: 'm',\n 78: 'n',\n 79: 'o',\n 80: 'p',\n 81: 'q',\n 82: 'r',\n 83: 's',\n 84: 't',\n 85: 'u',\n 86: 'v',\n 87: 'w',\n 88: 'x',\n 89: 'y',\n 90: 'z',\n 91: 'meta', // 'left window key'\n 92: 'meta', // 'right window key'\n 93: 'meta', // 'select key'\n\n 96: 'num0',\n 97: 'num1',\n 98: 'num2',\n 99: 'num3',\n 100: 'num4',\n 101: 'num5',\n 102: 'num6',\n 103: 'num7',\n 104: 'num8',\n 105: 'num9',\n 106: '*',\n 107: '+',\n 108: 'num_enter',\n 109: 'num_subtract',\n 110: 'num_decimal',\n 111: 'num_divide',\n 112: 'f1',\n 113: 'f2',\n 114: 'f3',\n 115: 'f4',\n 116: 'f5',\n 117: 'f6',\n 118: 'f7',\n 119: 'f8',\n 120: 'f9',\n 121: 'f10',\n 122: 'f11',\n 123: 'f12',\n 124: 'print',\n\n 144: 'num', // num lock\n 145: 'scroll', // scroll lock\n\n 173: '-',\n\n 186: ';',\n 187: '=',\n 188: ',',\n 189: '-',\n 190: '.',\n 191: '/',\n 192: '`',\n 219: '[',\n 220: '\\\\',\n 221: ']',\n 222: '\\'',\n 223: '`',\n 224: 'cmd',\n 225: 'alt',\n\n 57392: 'ctrl',\n 63289: 'num'\n};\n\nconst keypressCharacterMapOverides = {\n '\\r': 'enter'\n};\nconst keypressCharacterMap = JSON.parse(JSON.stringify(keydownKeycodeDictionary));\nfor (const key of Object.keys(keypressCharacterMapOverides)) {\n keypressCharacterMap[key] = keypressCharacterMapOverides[key];\n}\n\nconst keydownCharacterMap = {\n 'num_subtract': '-',\n 'num_enter': '\\n',\n 'num_decimal': '.',\n 'num_divide': '/',\n 'enter': '\\n',\n 'tab': '\\t',\n 'backspace': '\\b'\n};\n\nexport const unprintableKeys = [\n 'backspace','enter','tab','num',\n 'shift','meta','alt','pause','caps','esc',\n 'pageup','pagedown','end','home',\n 'left','up','right','down',\n 'print','insert','delete','cmd',\n 'f1','f2','f3','f4','f5','f6','f7','f8','f9','f10','f11','f12',\n 'scroll','ctrl'\n];\n\nconst validEvents = ['keydown', 'keyup'];\n\nconst isMobile = () => {\n const ua = navigator.userAgent;\n const mobile = /IEMobile|Windows Phone|Lumia/i.test(ua) ? 'w' : /iPhone|iP[oa]d/.test(ua) ? 'i' : /Android/.test(ua) ? 'a' : /BlackBerry|PlayBook|BB10/.test(ua) ? 'b' : /Mobile Safari/.test(ua) ? 's' : /webOS|Mobile|Tablet|Opera Mini|\\bCrMo\\/|Opera Mobi/i.test(ua) ? 1 : 0;\n return mobile !== 0;\n};\n\nfunction getKeypressKeycodeValue(charcode) {\n const character = String.fromCharCode(charcode);\n if (isMobile()) { return character }\n if (character in keyCodeUnshiftedKeys) {\n return keyCodeUnshiftedKeys[character];\n } else if (character in keypressCharacterMap) {\n return keypressCharacterMap[character];\n }\n return character;\n}\n\nexport default function(event) {\n let key;\n if (event.type === 'keypress' && !isMobile()) {\n key = getKeypressKeycodeValue(event.charCode);\n } else if (event.type === 'keypress' && isMobile()) {\n key = getKeypressKeycodeValue(event.keyCode);\n } else if (validEvents.indexOf(event.type) > -1) {\n if (event.which !== undefined) {\n key = keydownKeycodeDictionary[event.which];\n } else if (event.keyCode !== undefined) {\n key = keydownKeycodeDictionary[event.keyCode];\n } else {\n key = 'enter';\n }\n } else {\n return false;\n }\n\n let char = key;\n if (event.shiftKey && key in keycodeShiftedKeys) {\n char = keycodeShiftedKeys[key];\n } else if (event.ctrlKey && key in keycodeCtrlKeys) {\n char = keycodeCtrlKeys[key];\n } else if (key in keydownCharacterMap) {\n char = keydownCharacterMap[key];\n }\n\n return {\n char,\n key\n };\n}\n","let workerURL = require('./helpers/get-worker-url');\nlet url = new __parcel__URL__(\"twrmodworker.2165e649.js\");\nmodule.exports = workerURL(url.toString(), url.origin, true);","\"use strict\";\n\nmodule.exports = function (workerUrl, origin, isESM) {\n if (origin === self.location.origin) {\n // If the worker bundle's url is on the same origin as the document,\n // use the worker bundle's own url.\n return workerUrl;\n } else {\n // Otherwise, create a blob URL which loads the worker bundle with `importScripts`.\n var source = isESM ? 'import ' + JSON.stringify(workerUrl) + ';' : 'importScripts(' + JSON.stringify(workerUrl) + ');';\n return URL.createObjectURL(new Blob([source], {\n type: 'application/javascript'\n }));\n }\n};","require('./helpers/bundle-manifest').register(new __parcel__URL__(\"\").toString(),JSON.parse(\"[\\\"kjr0c\\\",\\\"index.528b9ee5.js\\\",\\\"cTHdP\\\",\\\"twrmodworker.2165e649.js\\\"]\"));"],"names":["$parcel$export","e","n","v","s","Object","defineProperty","get","set","enumerable","configurable","$parcel$global","globalThis","$parcel$modules","$parcel$inits","parcelRequire","id","exports","init","module","call","err","Error","code","register","parcelRegister","$ae99f86db55f9acd$export$6503ec6e8aabbaf","$ae99f86db55f9acd$var$mapping","Map","baseUrl","manifest","i","length","path","twrWasmModule","twrWasmModuleAsync","$251237c7cf144eb4$export$3298af74d75b595c","$9FI45","$aGUWE","$lsUl2","twrWasmModuleInJSMain","malloc","constructor","opts","canvas","size","d2dcanvas","isValid","iocanvas","modParams","imports","twrDebugLog","twrDebugLogImpl","twrTime","twrTimeImpl","twrDivCharOut","iodiv","charOut","bind","twrCanvasGetProp","getProp","twrCanvasDrawSeq","drawSeq","twrCanvasCharIn","null","twrCanvasInkey","twrDivCharIn","twrSleep","twrSin","Math","sin","twrCos","cos","twrTan","tan","twrFAbs","abs","twrACos","acos","twrASin","asin","twrATan","atan","twrExp","exp","twrFloor","floor","twrCeil","ceil","twrFMod","x","y","twrLog","log","twrPow","pow","twrSqrt","sqrt","twrTrunc","trunc","twrDtoa","floatUtil","dtoa","twrToFixed","toFixed","twrToExponential","toExponential","twrAtod","atod","twrFcvtS","fcvtS","inval","$70aa1fbe63deeaae$export$16b4216ec014493d","$70aa1fbe63deeaae$var$logline","char","console","String","fromCharCode","$7c89ffbd74fdad5b$export$2366c14363f3adb5","$fDEU7","$5hO33","$5LsZ0","twrWasmModuleBase","isWasmModule","document","eiodiv","getElementById","eiocanvas","ed2dcanvas","stdio","isd2dcanvas","windim","styleIsDefault","backcolor","forecolor","fontsize","undefined","twrDiv","twrCanvas","divLog","params","stringOut","toString","$b62a3a4493ce3043$export$dd376bb3f10f6896","$ghrAp","div","divKeys","CURSOR","cursorOn","lastChar","extraBR","owner","element","modbase","twrSharedCircularBuffer","style","backgroundColor","color","font","getProxyParams","sharedArray","ch","innerHTML","slice","p","getBoundingClientRect","window","scrollTo","height","focus","str","charCodeAt","$bda3a1eb26e567b5$export$a01cca24f011573a","buf","sa","crossOriginIsolated","location","protocol","SharedArrayBuffer","Int32Array","write","Atomics","notify","read","isEmpty","readWait","rdptr","wait","$3d955ccf8fb141b7$export$c83a0a3bffe07399","$2Xdsi","memory","mem8","mem32","memD","isWorker","Uint8Array","Uint32Array","Float64Array","twrFloatUtil","loadWasm","pathToLoad","response","fetch","ok","statusText","wasmBytes","arrayBuffer","allimports","instance","WebAssembly","instantiate","env","buffer","ArrayBuffer","postMessage","Promise","resolve","m","twr_malloc","stack","twrInit","twr_wasm_init","callC","cparams","preCallC","retval","callCImpl","postCallC","fname","f","Array","ci","putString","URL","r","fetchAndPutURL","putArrayBuffer","u8","j","copyString","buffer_size","strIndex","putU8","u8a","dest","ab","fnin","src","getLong","idx","idx32","setLong","value","getDouble","idx64","setDouble","getShort","getString","len","sout","getU8Arr","rv","dataptr","getU32Arr","$226b87658a7c840f$export$918ffb7e046a537b","mod","strptr","upper","trimStart","toUpperCase","Number","POSITIVE_INFINITY","NEGATIVE_INFINITY","parseFloat","replaceAll","max_precision","toPrecision","decdigits","sizeInBytes","fracpart_numdigits","dec","sign","digits","decpos","isNaN","isFinite","intPart","fracPart","roundValStr","split","replace","$4327d2f23f608609$export$2f298dd69cef3c34","D2DType","$4327d2f23f608609$var$D2DType","$47Wdp","ctx","props","charWidth","charHeight","foreColor","backColor","widthInChars","heightInChars","canvasHeight","canvasWidth","cmdCompleteSignal","canvasKeys","precomputedObjects","twrSignal","getContext","c","textBaseline","sampleText","tm","measureText","width","fM","fontBoundingBoxAscent","fontBoundingBoxDescent","c2","fillStyle","pn","propName","ds","next","ins","lastins","type","D2D_FILLRECT","w","h","fillRect","D2D_STROKERECT","strokeRect","D2D_FILLCHAR","txt","fillText","D2D_FILLTEXT","D2D_MEASURETEXT","tmidx","actualBoundingBoxAscent","actualBoundingBoxDescent","actualBoundingBoxLeft","actualBoundingBoxRight","D2D_SETFONT","D2D_SETFILLSTYLERGBA","cssColor","D2D_SETSTROKESTYLERGBA","strokeStyle","D2D_SETFILLSTYLE","D2D_SETSTROKESTYLE","D2D_SETLINEWIDTH","lineWidth","D2D_MOVETO","moveTo","D2D_LINETO","lineTo","D2D_BEZIERTO","cp1x","cp1y","cp2x","cp2y","bezierCurveTo","D2D_BEGINPATH","beginPath","D2D_FILL","fill","D2D_SAVE","save","D2D_RESTORE","restore","D2D_STROKE","stroke","D2D_ARC","radius","startAngle","endAngle","counterClockwise","arc","D2D_IMAGEDATA","start","z","Uint8ClampedArray","ImageData","D2D_CREATERADIALGRADIENT","x0","y0","radius0","x1","y1","radius1","gradient","createRadialGradient","D2D_CREATELINEARGRADIENT","createLinearGradient","D2D_SETCOLORSTOP","pos","addColorStop","D2D_SETFILLSTYLEGRADIENT","D2D_RELEASEID","D2D_PUTIMAGEDATA","imgData","dx","dy","dirtyX","dirtyY","dirtyWidth","dirtyHeight","from","putImageData","signal","$3014f93b5ceae902$var$twrSignalState","twrSignalState","$3014f93b5ceae902$export$e37a7b7b851b97f3","WAITING","SIGNALED","isSignaled","reset","$fa07ea1a08a5d6be$export$78724cdcf7ebea1d","Date","now","$8227a48f951b1cca$export$678fe6e36ab9a6ff","$2vKdq","$bqeaG","myWorker","loadWasmResolve","loadWasmReject","callCResolve","callCReject","initLW","waitingcalls","Worker","onmessage","processMsg","reject","twrWaitingCalls","modWorkerParams","divProxyParams","canvasProxyParams","waitingCallsProxyParams","startMsg","urlToLoad","href","keyDownDiv","ev","default","keyDownCanvas","event","msgType","data","d","processMessage","$1d42537681d02be3$export$9e37856d1928d388","callCompleteSignal","parameters","startSleep","ms","setTimeout","time","$850d1d8f0aa1ea8f$export$2e2bcd8739ae039","$850d1d8f0aa1ea8f$var$keycodeCtrlKeys","$850d1d8f0aa1ea8f$var$keycodeShiftedKeys","$850d1d8f0aa1ea8f$var$keyCodeUnshiftedKeys","$850d1d8f0aa1ea8f$var$keydownKeycodeDictionary","$850d1d8f0aa1ea8f$var$keypressCharacterMapOverides","$850d1d8f0aa1ea8f$var$keypressCharacterMap","JSON","parse","stringify","key","keys","$850d1d8f0aa1ea8f$var$keydownCharacterMap","$850d1d8f0aa1ea8f$var$validEvents","$850d1d8f0aa1ea8f$var$isMobile","ua","navigator","userAgent","mobile","test","$850d1d8f0aa1ea8f$var$getKeypressKeycodeValue","charcode","character","keyCode","indexOf","which","charCode","shiftKey","ctrlKey","$hoqmg","$7e9081fcee88b005$var$url","url","origin","workerUrl","isESM","self","source","createObjectURL","Blob"],"version":3,"file":"index.528b9ee5.js.map"} \ No newline at end of file diff --git a/azure/examples/balls/dist/index.html b/azure/examples/balls/dist/index.html index 95b30a76..1b14c7d3 100644 --- a/azure/examples/balls/dist/index.html +++ b/azure/examples/balls/dist/index.html @@ -5,4 +5,4 @@ "whatkey": "../../lib-js/whatkey.js" } } -

Bouncing Balls

tiny-wasm-runtime


\ No newline at end of file +

Bouncing Balls

tiny-wasm-runtime


\ No newline at end of file diff --git a/azure/examples/balls/dist/twrmodworker.2165e649.js b/azure/examples/balls/dist/twrmodworker.2165e649.js index 3744680c..d8d07779 100644 --- a/azure/examples/balls/dist/twrmodworker.2165e649.js +++ b/azure/examples/balls/dist/twrmodworker.2165e649.js @@ -1,2 +1,2 @@ -(()=>{var t,e,r,s;let i;class a{sharedArray;buf;constructor(t){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSharedCircularBuffer constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");t?this.sharedArray=t:this.sharedArray=new SharedArrayBuffer(1032),this.buf=new Int32Array(this.sharedArray),this.buf[256]=0,this.buf[257]=0}write(t){let e=this.buf[257];this.buf[e]=t,256==++e&&(e=0),this.buf[257]=e,Atomics.notify(this.buf,257)}read(){if(this.isEmpty())return -1;{let t=this.buf[256],e=this.buf[t];return t++,this.buf[256]=t,e}}readWait(){if(this.isEmpty()){let t=this.buf[256];Atomics.wait(this.buf,257,t)}return this.read()}isEmpty(){return this.buf[256]==this.buf[257]}}(r=t||(t={}))[r.WAITING=0]="WAITING",r[r.SIGNALED=1]="SIGNALED";class o{sharedArray;buf;constructor(e){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSignal constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");e?this.sharedArray=e:this.sharedArray=new SharedArrayBuffer(4),this.buf=new Int32Array(this.sharedArray),this.buf[0]=t.WAITING}signal(){this.buf[0]=t.SIGNALED,Atomics.notify(this.buf,0)}wait(){this.buf[0]==t.WAITING&&Atomics.wait(this.buf,0,t.WAITING)}isSignaled(){return this.buf[0]==t.SIGNALED}reset(){this.buf[0]=t.WAITING}}(s=e||(e={}))[s.D2D_FILLRECT=1]="D2D_FILLRECT",s[s.D2D_FILLCHAR=5]="D2D_FILLCHAR",s[s.D2D_SETLINEWIDTH=10]="D2D_SETLINEWIDTH",s[s.D2D_SETFILLSTYLERGBA=11]="D2D_SETFILLSTYLERGBA",s[s.D2D_SETFONT=12]="D2D_SETFONT",s[s.D2D_BEGINPATH=13]="D2D_BEGINPATH",s[s.D2D_MOVETO=14]="D2D_MOVETO",s[s.D2D_LINETO=15]="D2D_LINETO",s[s.D2D_FILL=16]="D2D_FILL",s[s.D2D_STROKE=17]="D2D_STROKE",s[s.D2D_SETSTROKESTYLERGBA=18]="D2D_SETSTROKESTYLERGBA",s[s.D2D_ARC=19]="D2D_ARC",s[s.D2D_STROKERECT=20]="D2D_STROKERECT",s[s.D2D_FILLTEXT=21]="D2D_FILLTEXT",s[s.D2D_IMAGEDATA=22]="D2D_IMAGEDATA",s[s.D2D_PUTIMAGEDATA=23]="D2D_PUTIMAGEDATA",s[s.D2D_BEZIERTO=24]="D2D_BEZIERTO",s[s.D2D_MEASURETEXT=25]="D2D_MEASURETEXT",s[s.D2D_SAVE=26]="D2D_SAVE",s[s.D2D_RESTORE=27]="D2D_RESTORE",s[s.D2D_CREATERADIALGRADIENT=28]="D2D_CREATERADIALGRADIENT",s[s.D2D_SETCOLORSTOP=29]="D2D_SETCOLORSTOP",s[s.D2D_SETFILLSTYLEGRADIENT=30]="D2D_SETFILLSTYLEGRADIENT",s[s.D2D_RELEASEID=31]="D2D_RELEASEID",s[s.D2D_CREATELINEARGRADIENT=32]="D2D_CREATELINEARGRADIENT",s[s.D2D_SETFILLSTYLE=33]="D2D_SETFILLSTYLE",s[s.D2D_SETSTROKESTYLE=34]="D2D_SETSTROKESTYLE";class n{canvasKeys;drawCompleteSignal;props;owner;constructor(t,e){let[r,s,i]=t;this.drawCompleteSignal=new o(s),this.canvasKeys=new a(i),this.props=r,this.owner=e}charIn(){return this.canvasKeys.readWait()}inkey(){return this.canvasKeys.isEmpty()?0:this.charIn()}getProp(t){let e=this.owner.getString(t);return this.props[e]}drawSeq(t){this.drawCompleteSignal.reset(),postMessage(["drawseq",[t]]),this.drawCompleteSignal.wait()}}class l{divKeys;constructor(t){let[e]=t;this.divKeys=new a(e)}charIn(){return this.divKeys.readWait()}inkey(){return this.divKeys.isEmpty()?0:this.charIn()}charOut(t){postMessage(["divout",t])}}function h(t){postMessage(["debug",t])}class m{mod;constructor(t){this.mod=t}atod(t){let e=this.mod.getString(t),r=e.trimStart().toUpperCase();return"INF"==r||"+INF"==r?Number.POSITIVE_INFINITY:"-INF"==r?Number.NEGATIVE_INFINITY:Number.parseFloat(e.replaceAll("D","e").replaceAll("d","e"))}dtoa(t,e,r,s){if(-1==s){let s=r.toString();this.mod.copyString(t,e,s)}else{let i=r.toString();i.length>s&&(i=r.toPrecision(s)),this.mod.copyString(t,e,i)}}toFixed(t,e,r,s){let i=r.toFixed(s);this.mod.copyString(t,e,i)}toExponential(t,e,r,s){let i=r.toExponential(s);this.mod.copyString(t,e,i)}fcvtS(t,e,r,s,i,a){let o,n;if(0==t||0==a||0==i||e<1)return 1;let l=0;if(Number.isNaN(r))o="1#QNAN00000000000000000000000000000".slice(0,s+1),n=1;else if(Number.isFinite(r)){if(0==r)o="000000000000000000000000000000000000".slice(0,s),n=0;else{if(r<0&&(l=1,r=Math.abs(r)),s>100||r>1e21||r<1e-99)return this.mod.copyString(t,e,""),this.mod.mem32[i]=0,1;let[a="",h=""]=r.toFixed(s).split(".");"0"==a&&(a=""),a.length>0?(n=a.length,o=a+h):n=(o=h.replace(/^0+/,"")).length-h.length}}else o="1#INF00000000000000000000000000000".slice(0,s+1),n=1;return e-1new Promise(e=>{let r=this.exports.twr_malloc;e(r(t))}),this.init()}catch(t){throw console.log("WASM instantiate error: "+t+(t.stack?"\n"+t.stack:"")),t}}init(){let t;switch(this.modParams.stdio){case"debug":default:t=0;break;case"div":t=1;break;case"canvas":t=2;break;case"null":t=3}(0,this.exports.twr_wasm_init)(t,this.mem8.length)}async executeC(t){let e=await this.preCallC(t),r=this.executeCImpl(t[0],e);return this.postCallC(e,t),r}async executeCImpl(t,e=[]){if(!this.exports)throw Error("this.exports undefined");if(!this.exports[t])throw Error("executeC: function '"+t+"' not in export table. Use --export wasm-ld flag.");return(0,this.exports[t])(...e)}async preCallC(t){if(t.constructor!==Array)throw Error("executeC: params must be array, first arg is function name");if(0==t.length)throw Error("executeC: missing function name");let e=[],r=0;for(let s=1;s=this.mem32.length)throw Error("invalid index passed to getLong: "+t+", this.mem32.length: "+this.mem32.length);return this.mem32[e]}setLong(t,e){let r=Math.floor(t/4);if(4*r!=t)throw Error("setLong passed non long aligned address");if(r<0||r>=this.mem32.length)throw Error("invalid index passed to setLong: "+t+", this.mem32.length: "+this.mem32.length);this.mem32[r]=e}getDouble(t){let e=Math.floor(t/8);if(8*e!=t)throw Error("getLong passed non Float64 aligned address");return this.memD[e]}setDouble(t,e){let r=Math.floor(t/8);if(8*r!=t)throw Error("setDouble passed non Float64 aligned address");this.memD[r]=e}getShort(t){if(t<0||t>=this.mem8.length)throw Error("invalid index passed to getShort: "+t);return this.mem8[t]+256*this.mem8[t+1]}getString(t,e){let r="",s=0;for(;this.mem8[t+s]&&(void 0===e||s=this.mem8.length)throw Error("invalid index passed to getU8: "+t);let e=new Uint32Array(this.mem8.slice(t,t+8).buffer),r=e[0],s=e[1];if(s<0||s>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU8");if(r<0||r>this.mem8.length-s)throw Error("invalid idx.size passed to getU8");return this.mem8.slice(s,s+r)}getU32Arr(t){if(t<0||t>=this.mem8.length)throw Error("invalid index passed to getU32: "+t);let e=new Uint32Array(this.mem8.slice(t,t+8).buffer),r=e[0],s=e[1];if(s<0||s>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU32");if(r<0||r>this.mem8.length-s)throw Error("invalid idx.size passed to getU32");if(r%4!=0)throw Error("idx.size is not an integer number of 32 bit words");return new Uint32Array(this.mem8.slice(s,s+r).buffer)}}class d{callCompleteSignal;parameters;constructor(t){this.callCompleteSignal=new o(t[0]),this.parameters=new Uint32Array(t[1])}sleep(t){this.callCompleteSignal.reset(),postMessage(["sleep",[t]]),this.callCompleteSignal.wait()}time(){return this.callCompleteSignal.reset(),postMessage(["time"]),this.callCompleteSignal.wait(),this.parameters[0]}}onmessage=function(t){if("startup"==t.data[0]){let e=t.data[1];(i=new f(e.modParams,e.modWorkerParams)).loadWasm(e.urlToLoad).then(()=>{postMessage(["startupOkay"])}).catch(t=>{console.log(".catch: ",t),postMessage(["startupFail",t])})}else"executeC"==t.data[0]?i.executeCImpl(t.data[1],t.data[2]).then(t=>{postMessage(["executeCOkay",t])}).catch(t=>{console.log("exception in executeC twrworker.js\n"),console.log(t),postMessage(["executeCFail",t])}):console.log("twrworker.js: unknown message: "+t)};class f extends c{malloc;modParams;constructor(t,e){super(),this.isWorker=!0,this.malloc=t=>{throw Error("error - un-init malloc called")},this.modParams=t;let r=new n(e.canvasProxyParams,this),s=new l(e.divProxyParams),i=new d(e.waitingCallsProxyParams);this.modParams.imports={twrDebugLog:h,twrSleep:i.sleep.bind(i),twrTime:i.time.bind(i),twrDivCharOut:s.charOut.bind(s),twrDivCharIn:s.charIn.bind(s),twrCanvasCharIn:r.charIn.bind(r),twrCanvasInkey:r.inkey.bind(r),twrCanvasGetProp:r.getProp.bind(r),twrCanvasDrawSeq:r.drawSeq.bind(r),twrSin:Math.sin,twrCos:Math.cos,twrTan:Math.tan,twrFAbs:Math.abs,twrACos:Math.acos,twrASin:Math.asin,twrATan:Math.atan,twrExp:Math.exp,twrFloor:Math.floor,twrCeil:Math.ceil,twrFMod:function(t,e){return t%e},twrLog:Math.log,twrPow:Math.pow,twrSqrt:Math.sqrt,twrTrunc:Math.trunc,twrDtoa:this.floatUtil.dtoa.bind(this.floatUtil),twrToFixed:this.floatUtil.toFixed.bind(this.floatUtil),twrToExponential:this.floatUtil.toExponential.bind(this.floatUtil),twrAtod:this.floatUtil.atod.bind(this.floatUtil),twrFcvtS:this.floatUtil.fcvtS.bind(this.floatUtil)}}}})(); +(()=>{var t,e,r,s;let i;class a{sharedArray;buf;constructor(t){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSharedCircularBuffer constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");t?this.sharedArray=t:this.sharedArray=new SharedArrayBuffer(1032),this.buf=new Int32Array(this.sharedArray),this.buf[256]=0,this.buf[257]=0}write(t){let e=this.buf[257];this.buf[e]=t,256==++e&&(e=0),this.buf[257]=e,Atomics.notify(this.buf,257)}read(){if(this.isEmpty())return -1;{let t=this.buf[256],e=this.buf[t];return t++,this.buf[256]=t,e}}readWait(){if(this.isEmpty()){let t=this.buf[256];Atomics.wait(this.buf,257,t)}return this.read()}isEmpty(){return this.buf[256]==this.buf[257]}}(r=t||(t={}))[r.WAITING=0]="WAITING",r[r.SIGNALED=1]="SIGNALED";class o{sharedArray;buf;constructor(e){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSignal constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");e?this.sharedArray=e:this.sharedArray=new SharedArrayBuffer(4),this.buf=new Int32Array(this.sharedArray),this.buf[0]=t.WAITING}signal(){this.buf[0]=t.SIGNALED,Atomics.notify(this.buf,0)}wait(){this.buf[0]==t.WAITING&&Atomics.wait(this.buf,0,t.WAITING)}isSignaled(){return this.buf[0]==t.SIGNALED}reset(){this.buf[0]=t.WAITING}}(s=e||(e={}))[s.D2D_FILLRECT=1]="D2D_FILLRECT",s[s.D2D_FILLCHAR=5]="D2D_FILLCHAR",s[s.D2D_SETLINEWIDTH=10]="D2D_SETLINEWIDTH",s[s.D2D_SETFILLSTYLERGBA=11]="D2D_SETFILLSTYLERGBA",s[s.D2D_SETFONT=12]="D2D_SETFONT",s[s.D2D_BEGINPATH=13]="D2D_BEGINPATH",s[s.D2D_MOVETO=14]="D2D_MOVETO",s[s.D2D_LINETO=15]="D2D_LINETO",s[s.D2D_FILL=16]="D2D_FILL",s[s.D2D_STROKE=17]="D2D_STROKE",s[s.D2D_SETSTROKESTYLERGBA=18]="D2D_SETSTROKESTYLERGBA",s[s.D2D_ARC=19]="D2D_ARC",s[s.D2D_STROKERECT=20]="D2D_STROKERECT",s[s.D2D_FILLTEXT=21]="D2D_FILLTEXT",s[s.D2D_IMAGEDATA=22]="D2D_IMAGEDATA",s[s.D2D_PUTIMAGEDATA=23]="D2D_PUTIMAGEDATA",s[s.D2D_BEZIERTO=24]="D2D_BEZIERTO",s[s.D2D_MEASURETEXT=25]="D2D_MEASURETEXT",s[s.D2D_SAVE=26]="D2D_SAVE",s[s.D2D_RESTORE=27]="D2D_RESTORE",s[s.D2D_CREATERADIALGRADIENT=28]="D2D_CREATERADIALGRADIENT",s[s.D2D_SETCOLORSTOP=29]="D2D_SETCOLORSTOP",s[s.D2D_SETFILLSTYLEGRADIENT=30]="D2D_SETFILLSTYLEGRADIENT",s[s.D2D_RELEASEID=31]="D2D_RELEASEID",s[s.D2D_CREATELINEARGRADIENT=32]="D2D_CREATELINEARGRADIENT",s[s.D2D_SETFILLSTYLE=33]="D2D_SETFILLSTYLE",s[s.D2D_SETSTROKESTYLE=34]="D2D_SETSTROKESTYLE";class n{canvasKeys;drawCompleteSignal;props;owner;constructor(t,e){let[r,s,i]=t;this.drawCompleteSignal=new o(s),this.canvasKeys=new a(i),this.props=r,this.owner=e}charIn(){return this.canvasKeys.readWait()}inkey(){return this.canvasKeys.isEmpty()?0:this.charIn()}getProp(t){let e=this.owner.getString(t);return this.props[e]}drawSeq(t){this.drawCompleteSignal.reset(),postMessage(["drawseq",[t]]),this.drawCompleteSignal.wait()}}class l{divKeys;constructor(t){let[e]=t;this.divKeys=new a(e)}charIn(){return this.divKeys.readWait()}inkey(){return this.divKeys.isEmpty()?0:this.charIn()}charOut(t){postMessage(["divout",t])}}function h(t){postMessage(["debug",t])}class m{mod;constructor(t){this.mod=t}atod(t){let e=this.mod.getString(t),r=e.trimStart().toUpperCase();return"INF"==r||"+INF"==r?Number.POSITIVE_INFINITY:"-INF"==r?Number.NEGATIVE_INFINITY:Number.parseFloat(e.replaceAll("D","e").replaceAll("d","e"))}dtoa(t,e,r,s){if(-1==s){let s=r.toString();this.mod.copyString(t,e,s)}else{let i=r.toString();i.length>s&&(i=r.toPrecision(s)),this.mod.copyString(t,e,i)}}toFixed(t,e,r,s){let i=r.toFixed(s);this.mod.copyString(t,e,i)}toExponential(t,e,r,s){let i=r.toExponential(s);this.mod.copyString(t,e,i)}fcvtS(t,e,r,s,i,a){let o,n;if(0==t||0==a||0==i||e<1)return 1;let l=0;if(Number.isNaN(r))o="1#QNAN00000000000000000000000000000".slice(0,s+1),n=1;else if(Number.isFinite(r)){if(0==r)o="000000000000000000000000000000000000".slice(0,s),n=0;else{if(r<0&&(l=1,r=Math.abs(r)),s>100||r>1e21||r<1e-99)return this.mod.copyString(t,e,""),this.mod.mem32[i]=0,1;let[a="",h=""]=r.toFixed(s).split(".");"0"==a&&(a=""),a.length>0?(n=a.length,o=a+h):n=(o=h.replace(/^0+/,"")).length-h.length}}else o="1#INF00000000000000000000000000000".slice(0,s+1),n=1;return e-1new Promise(e=>{let r=this.exports.twr_malloc;e(r(t))}),this.init()}catch(t){throw console.log("WASM instantiate error: "+t+(t.stack?"\n"+t.stack:"")),t}}init(){let t;switch(this.modParams.stdio){case"debug":default:t=0;break;case"div":t=1;break;case"canvas":t=2;break;case"null":t=3}(0,this.exports.twr_wasm_init)(t,this.mem8.length)}async callC(t){let e=await this.preCallC(t),r=this.callCImpl(t[0],e);return this.postCallC(e,t),r}async callCImpl(t,e=[]){if(!this.exports)throw Error("this.exports undefined");if(!this.exports[t])throw Error("callC: function '"+t+"' not in export table. Use --export wasm-ld flag.");return(0,this.exports[t])(...e)}async preCallC(t){if(t.constructor!==Array)throw Error("callC: params must be array, first arg is function name");if(0==t.length)throw Error("callC: missing function name");let e=[],r=0;for(let s=1;s=this.mem32.length)throw Error("invalid index passed to getLong: "+t+", this.mem32.length: "+this.mem32.length);return this.mem32[e]}setLong(t,e){let r=Math.floor(t/4);if(4*r!=t)throw Error("setLong passed non long aligned address");if(r<0||r>=this.mem32.length)throw Error("invalid index passed to setLong: "+t+", this.mem32.length: "+this.mem32.length);this.mem32[r]=e}getDouble(t){let e=Math.floor(t/8);if(8*e!=t)throw Error("getLong passed non Float64 aligned address");return this.memD[e]}setDouble(t,e){let r=Math.floor(t/8);if(8*r!=t)throw Error("setDouble passed non Float64 aligned address");this.memD[r]=e}getShort(t){if(t<0||t>=this.mem8.length)throw Error("invalid index passed to getShort: "+t);return this.mem8[t]+256*this.mem8[t+1]}getString(t,e){let r="",s=0;for(;this.mem8[t+s]&&(void 0===e||s=this.mem8.length)throw Error("invalid index passed to getU8: "+t);let e=new Uint32Array(this.mem8.slice(t,t+8).buffer),r=e[0],s=e[1];if(s<0||s>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU8");if(r<0||r>this.mem8.length-s)throw Error("invalid idx.size passed to getU8");return this.mem8.slice(s,s+r)}getU32Arr(t){if(t<0||t>=this.mem8.length)throw Error("invalid index passed to getU32: "+t);let e=new Uint32Array(this.mem8.slice(t,t+8).buffer),r=e[0],s=e[1];if(s<0||s>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU32");if(r<0||r>this.mem8.length-s)throw Error("invalid idx.size passed to getU32");if(r%4!=0)throw Error("idx.size is not an integer number of 32 bit words");return new Uint32Array(this.mem8.slice(s,s+r).buffer)}}class d{callCompleteSignal;parameters;constructor(t){this.callCompleteSignal=new o(t[0]),this.parameters=new Uint32Array(t[1])}sleep(t){this.callCompleteSignal.reset(),postMessage(["sleep",[t]]),this.callCompleteSignal.wait()}time(){return this.callCompleteSignal.reset(),postMessage(["time"]),this.callCompleteSignal.wait(),this.parameters[0]}}onmessage=function(t){if("startup"==t.data[0]){let e=t.data[1];(i=new f(e.modParams,e.modWorkerParams)).loadWasm(e.urlToLoad).then(()=>{postMessage(["startupOkay"])}).catch(t=>{console.log(".catch: ",t),postMessage(["startupFail",t])})}else"callC"==t.data[0]?i.callCImpl(t.data[1],t.data[2]).then(t=>{postMessage(["callCOkay",t])}).catch(t=>{console.log("exception in callC twrworker.js\n"),console.log(t),postMessage(["callCFail",t])}):console.log("twrworker.js: unknown message: "+t)};class f extends c{malloc;modParams;constructor(t,e){super(),this.isWorker=!0,this.malloc=t=>{throw Error("error - un-init malloc called")},this.modParams=t;let r=new n(e.canvasProxyParams,this),s=new l(e.divProxyParams),i=new d(e.waitingCallsProxyParams);this.modParams.imports={twrDebugLog:h,twrSleep:i.sleep.bind(i),twrTime:i.time.bind(i),twrDivCharOut:s.charOut.bind(s),twrDivCharIn:s.charIn.bind(s),twrCanvasCharIn:r.charIn.bind(r),twrCanvasInkey:r.inkey.bind(r),twrCanvasGetProp:r.getProp.bind(r),twrCanvasDrawSeq:r.drawSeq.bind(r),twrSin:Math.sin,twrCos:Math.cos,twrTan:Math.tan,twrFAbs:Math.abs,twrACos:Math.acos,twrASin:Math.asin,twrATan:Math.atan,twrExp:Math.exp,twrFloor:Math.floor,twrCeil:Math.ceil,twrFMod:function(t,e){return t%e},twrLog:Math.log,twrPow:Math.pow,twrSqrt:Math.sqrt,twrTrunc:Math.trunc,twrDtoa:this.floatUtil.dtoa.bind(this.floatUtil),twrToFixed:this.floatUtil.toFixed.bind(this.floatUtil),twrToExponential:this.floatUtil.toExponential.bind(this.floatUtil),twrAtod:this.floatUtil.atod.bind(this.floatUtil),twrFcvtS:this.floatUtil.fcvtS.bind(this.floatUtil)}}}})(); //# sourceMappingURL=twrmodworker.2165e649.js.map diff --git a/azure/examples/balls/dist/twrmodworker.2165e649.js.map b/azure/examples/balls/dist/twrmodworker.2165e649.js.map index 29a4d41e..77745e98 100644 --- a/azure/examples/balls/dist/twrmodworker.2165e649.js.map +++ b/azure/examples/balls/dist/twrmodworker.2165e649.js.map @@ -1 +1 @@ -{"mappings":"A,C,SQKK,EJgBA,EIhBA,EJgBA,MFZD,CISE,OAAO,EACZ,WAA8B,AAC9B,CAAA,GAAe,AAEf,aAAa,CAAqB,CAAlC,CACO,GAAI,AAAkB,aAAlB,OAAO,QACH,CAAC,qBAAuB,AAA+B,UAA7B,OAAO,QAAQ,CAAC,QAAQ,CAAe,MAAM,AAAI,MAAM,4DAA4D,oBAAoB,iCAErK,EAAI,IAAI,CAAC,WAAW,CAAC,EACpB,IAAI,CAAC,WAAW,CAAC,IAAI,kBAAkB,MAClD,IAAI,CAAC,GAAG,CAAC,IAAI,WAAW,IAAI,CAAC,WAAW,EAClC,IAAI,CAAC,GAAG,CArBJ,IAqBW,CAAC,EAChB,IAAI,CAAC,GAAG,CArBJ,IAqBW,CAAC,CACvB,CAEA,MAAM,CAAQ,CAAd,CACO,IAAI,EAAE,IAAI,CAAC,GAAG,CAzBV,IAyBiB,AACrB,CAAA,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAzBV,OA2BE,GAAQ,CAAA,EAAE,CAAA,EACd,IAAI,CAAC,GAAG,CA7BJ,IA6BW,CAAC,EAChB,QAAQ,MAAM,CAAC,IAAI,CAAC,GAAG,CA9BnB,IA+BX,CAEA,MAAA,CACO,GAAK,IAAI,CAAC,OAAO,GAQb,OAAO,EARU,EACjB,IAAI,EAAE,IAAI,CAAC,GAAG,CApCd,IAoCqB,CACjB,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,CAGjB,OAFA,IACA,IAAI,CAAC,GAAG,CAvCR,IAuCe,CAAC,EACT,CACV,CA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Ae,EAAY,KAAK,CAAC,IAAI,CAAC,GACtC,iBAAiB,EAAY,OAAO,CAAC,IAAI,CAAC,GAC1C,iBAAiB,EAAY,OAAO,CAAC,IAAI,CAAC,GAEnD,OAAO,KAAK,GAAG,CACf,OAAO,KAAK,GAAG,CACf,OAAQ,KAAK,GAAG,CAChB,QAAS,KAAK,GAAG,CACjB,QAAS,KAAK,IAAI,CAClB,QAAS,KAAK,IAAI,CAClB,QAAS,KAAK,IAAI,CAClB,OAAQ,KAAK,GAAG,CAChB,SAAU,KAAK,KAAK,CACpB,QAAS,KAAK,IAAI,CAClB,QAAS,SAAS,CAAQ,CAAE,CAAQ,EAAG,OAAO,EAAE,CAAC,EACjD,OAAQ,KAAK,GAAG,CAChB,OAAQ,KAAK,GAAG,CAChB,QAAS,KAAK,IAAI,CAClB,SAAU,KAAK,KAAK,CAEX,QAAS,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EACzD,WAAY,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EACtD,iBAAkB,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAClE,QAAS,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAChD,SAAU,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAE5C,CACN,CACF,C,C","sources":["","../../lib-js/twrmodworker.js","../../source/twr-wasm-ts/twrmodworker.ts","../../lib-js/twrcanvas.js","../../source/twr-wasm-ts/twrcanvas.ts","../../lib-js/twrcircular.js","../../source/twr-wasm-ts/twrcircular.ts","../../lib-js/twrsignal.js","../../source/twr-wasm-ts/twrsignal.ts","../../lib-js/twrdiv.js","../../source/twr-wasm-ts/twrdiv.ts","../../lib-js/twrdebug.js","../../source/twr-wasm-ts/twrdebug.ts","../../lib-js/twrmodbase.js","../../source/twr-wasm-ts/twrmodbase.ts","../../lib-js/twrfloat.js","../../source/twr-wasm-ts/twrfloat.ts","../../lib-js/twrwaitingcalls.js","../../source/twr-wasm-ts/twrwaitingcalls.ts","../../lib-js/twrdate.js","../../source/twr-wasm-ts/twrdate.ts"],"sourcesContent":["(() => {\nvar $3e39efa823870787$exports = {};\n// this script is the WebWorker thead used by class twrWasmAsyncModule\n//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst $892fccfc812d5e20$var$RDIDX = 256;\nconst $892fccfc812d5e20$var$WRIDX = 257;\nconst $892fccfc812d5e20$var$LEN = 256;\nclass $892fccfc812d5e20$export$a01cca24f011573a {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(1032);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[$892fccfc812d5e20$var$RDIDX] = 0;\n this.buf[$892fccfc812d5e20$var$WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[$892fccfc812d5e20$var$WRIDX];\n this.buf[i] = n;\n i++;\n if (i == $892fccfc812d5e20$var$LEN) i = 0;\n this.buf[$892fccfc812d5e20$var$WRIDX] = i;\n Atomics.notify(this.buf, $892fccfc812d5e20$var$WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[$892fccfc812d5e20$var$RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[$892fccfc812d5e20$var$RDIDX] = i;\n return n;\n } else return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[$892fccfc812d5e20$var$RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, $892fccfc812d5e20$var$WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[$892fccfc812d5e20$var$RDIDX] == this.buf[$892fccfc812d5e20$var$WRIDX];\n }\n}\n\n\n//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar $b93f1fdf40141def$var$twrSignalState;\n(function(twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})($b93f1fdf40141def$var$twrSignalState || ($b93f1fdf40141def$var$twrSignalState = {}));\nclass $b93f1fdf40141def$export$e37a7b7b851b97f3 {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == $b93f1fdf40141def$var$twrSignalState.WAITING) //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, $b93f1fdf40141def$var$twrSignalState.WAITING);\n }\n isSignaled() {\n return this.buf[0] == $b93f1fdf40141def$var$twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.WAITING;\n }\n}\n\n\nvar $c4741cac81d14197$var$D2DType;\n(function(D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})($c4741cac81d14197$var$D2DType || ($c4741cac81d14197$var$D2DType = {}));\nclass $c4741cac81d14197$export$2f298dd69cef3c34 {\n ctx;\n props = {\n charWidth: 0,\n charHeight: 0,\n foreColor: 0,\n backColor: 0,\n widthInChars: 0,\n heightInChars: 0,\n canvasHeight: 0,\n canvasWidth: 0\n };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase){\n const { forecolor: forecolor, backcolor: backcolor, fontsize: fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)();\n this.canvasKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.props,\n this.cmdCompleteSignal.sharedArray,\n this.canvasKeys.sharedArray\n ];\n }\n getProp(pn) {\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */ drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx) return;\n let ins = this.owner.getLong(ds); /* ds->start */ \n const lastins = this.owner.getLong(ds + 4); /* ds->last */ \n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while(true){\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */ \n switch(type){\n case $c4741cac81d14197$var$D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_BEGINPATH:\n this.ctx.beginPath();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILL:\n this.ctx.fill();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SAVE:\n this.ctx.save();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_RESTORE:\n this.ctx.restore();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_STROKE:\n this.ctx.stroke();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = this.owner.getLong(ins + 48) != 0;\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n } else this.precomputedObjects[id] = {\n mem8: new Uint8Array(this.owner.memory.buffer, start, length),\n width: width,\n height: height\n };\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id]) delete this.precomputedObjects[id];\n else console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n else {\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) this.ctx.putImageData(imgData, dx, dy);\n else this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */ \n if (next == 0) {\n if (ins != lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nclass $c4741cac81d14197$export$c779b2cd00544976 {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner){\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)(signalBuffer);\n this.canvasKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\n \"drawseq\",\n [\n ds\n ]\n ]);\n this.drawCompleteSignal.wait();\n }\n}\n\n\n\nclass $8963973702ae5462$export$dd376bb3f10f6896 {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611);\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase){\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) this.divKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(); // tsconfig, lib must be set to 2017 or higher\n if (this.div && !modParams.styleIsDefault) {\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.divKeys.sharedArray\n ];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */ charOut(ch) {\n if (!this.div) return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n }\n switch(ch){\n case 10:\n case 13:\n if (ch == 10 && this.lastChar == 13) break; // detect CR LF and treat as single new line\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n case 0xE:\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF:\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for(let i = 0; i < str.length; i++)this.charOut(str.charCodeAt(i));\n }\n}\nclass $8963973702ae5462$export$b377f0bbf2c7581e {\n divKeys;\n constructor(params){\n const [divKeysBuffer] = params;\n this.divKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n charOut(ch) {\n postMessage([\n \"divout\",\n ch\n ]);\n }\n}\n\n\nlet $8ac0b786da854328$var$logline = \"\";\nfunction $8ac0b786da854328$export$16b4216ec014493d(char) {\n if (char == 10 || char == 3) {\n console.log($8ac0b786da854328$var$logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n $8ac0b786da854328$var$logline = \"\";\n } else {\n $8ac0b786da854328$var$logline = $8ac0b786da854328$var$logline + String.fromCharCode(char);\n if ($8ac0b786da854328$var$logline.length >= 200) {\n console.log($8ac0b786da854328$var$logline);\n $8ac0b786da854328$var$logline = \"\";\n }\n }\n}\nfunction $8ac0b786da854328$export$485af4d0039b3389(ch) {\n postMessage([\n \"debug\",\n ch\n ]);\n}\n\n\nclass $e72303a1db04bdfa$export$918ffb7e046a537b {\n mod;\n constructor(mod){\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\") return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\") return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll(\"D\", \"e\").replaceAll(\"d\", \"e\"));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n } else {\n let r = value.toString();\n if (r.length > max_precision) r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, sizeInBytes, value, fracpart_numdigits, dec, sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1) return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) {\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (!Number.isFinite(value)) {\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n } else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split(\".\");\n if (intPart == \"0\") intPart = \"\";\n if (intPart.length > 0) {\n decpos = intPart.length;\n digits = intPart + fracPart;\n } else {\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length) return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */ }\n}\n\n\nclass $ece7fa3ed770778a$export$c83a0a3bffe07399 {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule;\n floatUtil;\n constructor(isWasmModule = false){\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new (0, $e72303a1db04bdfa$export$918ffb7e046a537b)(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/ /*********************************************************************/ async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n } catch (err) {\n console.log(\"loadWasm() failed to fetch: \" + pathToLoad);\n throw err;\n }\n if (!response.ok) throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, {\n env: allimports\n });\n this.exports = instance.instance.exports;\n if (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory) throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer) console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\n \"setmemory\",\n this.memory\n ]);\n }\n if (this.isWasmModule) // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n {\n if (!(this.memory.buffer instanceof ArrayBuffer)) console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size)=>{\n return new Promise((resolve)=>{\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n } catch (err) {\n console.log(\"WASM instantiate error: \" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch(this.modParams.stdio){\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* executeC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */ async executeC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.executeCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async executeCImpl(fname, cparams = []) {\n if (!this.exports) throw new Error(\"this.exports undefined\");\n if (!this.exports[fname]) throw new Error(\"executeC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array)) throw new Error(\"executeC: params must be array, first arg is function name\");\n if (params.length == 0) throw new Error(\"executeC: missing function name\");\n let cparams = [];\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n cparams[ci++] = p;\n break;\n case \"string\":\n cparams[ci++] = await this.putString(p);\n break;\n case \"object\":\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n } else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"executeC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n ci++;\n break;\n case \"string\":\n this.executeCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n case \"object\":\n if (p instanceof URL) {\n this.executeCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci = ci + 2;\n break;\n } else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for(let j = 0; j < u8.length; j++)u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.executeCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n } else throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/ /*********************************************************************/ // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for(i = 0; i < sin.length && i < buffer_size - 1; i++)this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for(let i = 0; i < u8a.length; i++)this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === \"object\" && fnin instanceof URL)) throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [\n dest,\n src.length\n ];\n } catch (err) {\n console.log(\"fetchAndPutURL Error. URL: \" + fnin + \"\\n\" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while(this.mem8[strIndex + i] && (len === undefined ? true : i < len) && strIndex + i < this.mem8.length){\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array(this.mem8.slice(dataptr, dataptr + size).buffer);\n return u32;\n }\n}\n\n\n\nfunction $4af5689abbc8d01b$export$78724cdcf7ebea1d() {\n return Date.now();\n}\n\n\nclass $aff9c2c494d23fe3$export$9e37856d1928d388 {\n callCompleteSignal;\n parameters;\n constructor(){\n this.callCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(()=>{\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = (0, $4af5689abbc8d01b$export$78724cdcf7ebea1d)();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [\n this.callCompleteSignal.sharedArray,\n this.parameters.buffer\n ];\n }\n processMessage(msgType, data) {\n switch(msgType){\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\nclass $aff9c2c494d23fe3$export$78d2a4633fe89379 {\n callCompleteSignal;\n parameters;\n constructor(params){\n this.callCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\n \"sleep\",\n [\n ms\n ]\n ]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\n \"time\"\n ]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n\n\nlet $3e39efa823870787$var$mod;\nonmessage = function(e) {\n //console.log('twrworker.js: message received from main script: '+e.data);\n if (e.data[0] == \"startup\") {\n const params = e.data[1];\n //console.log(\"Worker startup params:\",params);\n $3e39efa823870787$var$mod = new $3e39efa823870787$var$twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\n $3e39efa823870787$var$mod.loadWasm(params.urlToLoad).then(()=>{\n postMessage([\n \"startupOkay\"\n ]);\n }).catch((ex)=>{\n console.log(\".catch: \", ex);\n postMessage([\n \"startupFail\",\n ex\n ]);\n });\n } else if (e.data[0] == \"executeC\") $3e39efa823870787$var$mod.executeCImpl(e.data[1], e.data[2]).then((rc)=>{\n postMessage([\n \"executeCOkay\",\n rc\n ]);\n }).catch((e)=>{\n console.log(\"exception in executeC twrworker.js\\n\");\n console.log(e);\n postMessage([\n \"executeCFail\",\n e\n ]);\n });\n else console.log(\"twrworker.js: unknown message: \" + e);\n};\n// ************************************************************************\nclass $3e39efa823870787$var$twrWasmModuleInWorker extends (0, $ece7fa3ed770778a$export$c83a0a3bffe07399) {\n malloc;\n modParams;\n constructor(modParams, modInWorkerParams){\n super();\n this.isWorker = true;\n this.malloc = (size)=>{\n throw new Error(\"error - un-init malloc called\");\n };\n this.modParams = modParams;\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\n const canvasProxy = new (0, $c4741cac81d14197$export$c779b2cd00544976)(modInWorkerParams.canvasProxyParams, this);\n const divProxy = new (0, $8963973702ae5462$export$b377f0bbf2c7581e)(modInWorkerParams.divProxyParams);\n const waitingCallsProxy = new (0, $aff9c2c494d23fe3$export$78d2a4633fe89379)(modInWorkerParams.waitingCallsProxyParams);\n this.modParams.imports = {\n twrDebugLog: (0, $8ac0b786da854328$export$485af4d0039b3389),\n twrSleep: waitingCallsProxy.sleep.bind(waitingCallsProxy),\n twrTime: waitingCallsProxy.time.bind(waitingCallsProxy),\n twrDivCharOut: divProxy.charOut.bind(divProxy),\n twrDivCharIn: divProxy.charIn.bind(divProxy),\n twrCanvasCharIn: canvasProxy.charIn.bind(canvasProxy),\n twrCanvasInkey: canvasProxy.inkey.bind(canvasProxy),\n twrCanvasGetProp: canvasProxy.getProp.bind(canvasProxy),\n twrCanvasDrawSeq: canvasProxy.drawSeq.bind(canvasProxy),\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function(x, y) {\n return x % y;\n },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n}\n\n})();\n//# sourceMappingURL=twrmodworker.2165e649.js.map\n","// this script is the WebWorker thead used by class twrWasmAsyncModule\nimport { twrCanvasProxy } from \"./twrcanvas.js\";\nimport { twrDivProxy } from \"./twrdiv.js\";\nimport { twrDebugLogProxy } from \"./twrdebug.js\";\nimport { twrWasmModuleBase } from \"./twrmodbase.js\";\nimport { twrWaitingCallsProxy } from \"./twrwaitingcalls.js\";\nlet mod;\nonmessage = function (e) {\n //console.log('twrworker.js: message received from main script: '+e.data);\n if (e.data[0] == 'startup') {\n const params = e.data[1];\n //console.log(\"Worker startup params:\",params);\n mod = new twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\n mod.loadWasm(params.urlToLoad).then(() => {\n postMessage([\"startupOkay\"]);\n }).catch((ex) => {\n console.log(\".catch: \", ex);\n postMessage([\"startupFail\", ex]);\n });\n }\n else if (e.data[0] == 'executeC') {\n mod.executeCImpl(e.data[1], e.data[2]).then((rc) => {\n postMessage([\"executeCOkay\", rc]);\n }).catch(e => {\n console.log(\"exception in executeC twrworker.js\\n\");\n console.log(e);\n postMessage([\"executeCFail\", e]);\n });\n }\n else {\n console.log(\"twrworker.js: unknown message: \" + e);\n }\n};\n// ************************************************************************\nclass twrWasmModuleInWorker extends twrWasmModuleBase {\n malloc;\n modParams;\n constructor(modParams, modInWorkerParams) {\n super();\n this.isWorker = true;\n this.malloc = (size) => { throw new Error(\"error - un-init malloc called\"); };\n this.modParams = modParams;\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\n const canvasProxy = new twrCanvasProxy(modInWorkerParams.canvasProxyParams, this);\n const divProxy = new twrDivProxy(modInWorkerParams.divProxyParams);\n const waitingCallsProxy = new twrWaitingCallsProxy(modInWorkerParams.waitingCallsProxyParams);\n this.modParams.imports = {\n twrDebugLog: twrDebugLogProxy,\n twrSleep: waitingCallsProxy.sleep.bind(waitingCallsProxy),\n twrTime: waitingCallsProxy.time.bind(waitingCallsProxy),\n twrDivCharOut: divProxy.charOut.bind(divProxy),\n twrDivCharIn: divProxy.charIn.bind(divProxy),\n twrCanvasCharIn: canvasProxy.charIn.bind(canvasProxy),\n twrCanvasInkey: canvasProxy.inkey.bind(canvasProxy),\n twrCanvasGetProp: canvasProxy.getProp.bind(canvasProxy),\n twrCanvasDrawSeq: canvasProxy.drawSeq.bind(canvasProxy),\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function (x, y) { return x % y; },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n}\n//# sourceMappingURL=twrmodworker.js.map","// this script is the WebWorker thead used by class twrWasmAsyncModule\r\n\r\nimport {twrCanvasProxy} from \"./twrcanvas.js\";\r\nimport {twrDivProxy} from \"./twrdiv.js\";\r\nimport {twrDebugLogProxy} from \"./twrdebug.js\";\r\nimport {TAsyncModStartupMsg} from \"./twrmodasync.js\"\r\nimport {twrWasmModuleBase, IModInWorkerParams, IModParams} from \"./twrmodbase.js\"\r\nimport {twrWaitingCallsProxy} from \"./twrwaitingcalls.js\";\r\n\r\nlet mod:twrWasmModuleInWorker;\r\n\r\nonmessage = function(e) {\r\n //console.log('twrworker.js: message received from main script: '+e.data);\r\n\r\n if (e.data[0]=='startup') {\r\n const params:TAsyncModStartupMsg=e.data[1];\r\n //console.log(\"Worker startup params:\",params);\r\n mod=new twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\r\n\r\n mod.loadWasm(params.urlToLoad).then( ()=> {\r\n postMessage([\"startupOkay\"]);\r\n }).catch( (ex)=> {\r\n console.log(\".catch: \", ex);\r\n postMessage([\"startupFail\", ex]);\r\n });\r\n }\r\n else if (e.data[0]=='executeC') {\r\n mod.executeCImpl(e.data[1], e.data[2]).then( (rc)=> {\r\n postMessage([\"executeCOkay\", rc]);\r\n }).catch(e => {\r\n console.log(\"exception in executeC twrworker.js\\n\");\r\n console.log(e);\r\n postMessage([\"executeCFail\", e]);\r\n });\r\n }\r\n else {\r\n console.log(\"twrworker.js: unknown message: \"+e);\r\n }\r\n}\r\n\r\n\r\n// ************************************************************************\r\n\r\nclass twrWasmModuleInWorker extends twrWasmModuleBase {\r\n\tmalloc:(size:number)=>Promise;\r\n modParams: IModParams;\r\n\r\n\r\n constructor(modParams:IModParams, modInWorkerParams:IModInWorkerParams) {\r\n super();\r\n this.isWorker=true;\r\n this.malloc=(size:number)=>{throw new Error(\"error - un-init malloc called\")};\r\n this.modParams=modParams;\r\n\r\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\r\n const canvasProxy = new twrCanvasProxy(modInWorkerParams.canvasProxyParams, this);\r\n const divProxy = new twrDivProxy(modInWorkerParams.divProxyParams);\r\n const waitingCallsProxy = new twrWaitingCallsProxy(modInWorkerParams.waitingCallsProxyParams);\r\n\r\n this.modParams.imports={\r\n twrDebugLog:twrDebugLogProxy,\r\n twrSleep:waitingCallsProxy.sleep.bind(waitingCallsProxy),\r\n twrTime:waitingCallsProxy.time.bind(waitingCallsProxy),\r\n\r\n twrDivCharOut:divProxy.charOut.bind(divProxy), \r\n twrDivCharIn:divProxy.charIn.bind(divProxy), \r\n\r\n twrCanvasCharIn:canvasProxy.charIn.bind(canvasProxy),\r\n twrCanvasInkey:canvasProxy.inkey.bind(canvasProxy),\r\n twrCanvasGetProp:canvasProxy.getProp.bind(canvasProxy),\r\n twrCanvasDrawSeq:canvasProxy.drawSeq.bind(canvasProxy),\r\n\r\n\t\t\ttwrSin:Math.sin,\r\n\t\t\ttwrCos:Math.cos,\r\n\t\t\ttwrTan: Math.tan,\r\n\t\t\ttwrFAbs: Math.abs,\r\n\t\t\ttwrACos: Math.acos,\r\n\t\t\ttwrASin: Math.asin,\r\n\t\t\ttwrATan: Math.atan,\r\n\t\t\ttwrExp: Math.exp,\r\n\t\t\ttwrFloor: Math.floor,\r\n\t\t\ttwrCeil: Math.ceil,\r\n\t\t\ttwrFMod: function(x:number, y:number) {return x%y},\r\n\t\t\ttwrLog: Math.log,\r\n\t\t\ttwrPow: Math.pow,\r\n\t\t\ttwrSqrt: Math.sqrt,\r\n\t\t\ttwrTrunc: Math.trunc,\r\n\r\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\r\n\t\t\ttwrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\r\n\t\t\ttwrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\r\n\t\t\ttwrAtod: this.floatUtil.atod.bind(this.floatUtil),\r\n\t\t\ttwrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\r\n \r\n }\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nimport { twrSignal } from \"./twrsignal.js\";\nvar D2DType;\n(function (D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})(D2DType || (D2DType = {}));\nexport class twrCanvas {\n ctx;\n props = { charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight: 0, canvasWidth: 0 };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase) {\n const { forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new twrSignal();\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext)\n throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c)\n throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2)\n throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\n }\n getProp(pn) {\n if (!this.isValid())\n console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */\n drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid())\n console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx)\n return;\n let ins = this.owner.getLong(ds); /* ds->start */\n const lastins = this.owner.getLong(ds + 4); /* ds->last */\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while (1) {\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */\n if (0 /*type!=D2DType.D2D_FILLRECT*/) {\n console.log(\"ins\", ins);\n console.log(\"hdr.next\", this.owner.mem8[ins], this.owner.mem8[ins + 1], this.owner.mem8[ins + 2], this.owner.mem8[ins + 3]);\n console.log(\"hdr.type\", this.owner.mem8[ins + 4], this.owner.mem8[ins + 5]);\n console.log(\"next 4 bytes\", this.owner.mem8[ins + 6], this.owner.mem8[ins + 7], this.owner.mem8[ins + 8], this.owner.mem8[ins + 9]);\n console.log(\"and 4 more \", this.owner.mem8[ins + 10], this.owner.mem8[ins + 11], this.owner.mem8[ins + 12], this.owner.mem8[ins + 13]);\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\n }\n switch (type) {\n case D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case D2DType.D2D_BEGINPATH:\n {\n this.ctx.beginPath();\n }\n break;\n case D2DType.D2D_FILL:\n {\n this.ctx.fill();\n }\n break;\n case D2DType.D2D_SAVE:\n {\n this.ctx.save();\n }\n break;\n case D2DType.D2D_RESTORE:\n {\n this.ctx.restore();\n }\n break;\n case D2DType.D2D_STROKE:\n {\n this.ctx.stroke();\n }\n break;\n case D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = (this.owner.getLong(ins + 48) != 0);\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n }\n else { // Uint8ClampedArray doesn't support shared memory\n this.precomputedObjects[id] = { mem8: new Uint8Array(this.owner.memory.buffer, start, length), width: width, height: height };\n }\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id])\n delete this.precomputedObjects[id];\n else\n console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) {\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n }\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) {\n this.ctx.putImageData(imgData, dx, dy);\n }\n else {\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */\n if (next == 0) {\n if (ins != lastins)\n throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal)\n this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nexport class twrCanvasProxy {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner) {\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new twrSignal(signalBuffer);\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\"drawseq\", [ds]]);\n this.drawCompleteSignal.wait();\n }\n}\n//# sourceMappingURL=twrcanvas.js.map","import {twrWasmModuleBase, IModParams} from \"./twrmodbase.js\"\r\nimport {twrSharedCircularBuffer} from \"./twrcircular.js\";\r\nimport {twrSignal} from \"./twrsignal.js\";\r\n\r\n\r\n// Canvas have a size that will be set based on the character width x height\r\n// The display size for a canvas will default to this size, but can be changed in the HTML/JS via\r\n// canvas.style.width = \"700px\";\r\n// canvas.style.height = \"500px\";\r\n\r\nexport interface ICanvasProps {\r\n\tcharWidth: number,\r\n\tcharHeight: number,\r\n\tforeColor: number,\r\n\tbackColor: number,\r\n widthInChars: number,\r\n heightInChars: number,\r\n canvasWidth:number,\r\n canvasHeight:number\r\n}\r\n\r\nenum D2DType {\r\n D2D_FILLRECT=1,\r\n D2D_FILLCHAR=5,\r\n D2D_SETLINEWIDTH=10,\r\n D2D_SETFILLSTYLERGBA=11,\r\n D2D_SETFONT=12,\r\n D2D_BEGINPATH=13,\r\n D2D_MOVETO=14,\r\n D2D_LINETO=15,\r\n D2D_FILL=16,\r\n D2D_STROKE=17,\r\n D2D_SETSTROKESTYLERGBA=18,\r\n D2D_ARC=19,\r\n D2D_STROKERECT=20,\r\n D2D_FILLTEXT=21,\r\n D2D_IMAGEDATA=22,\r\n D2D_PUTIMAGEDATA=23,\r\n D2D_BEZIERTO=24,\r\n D2D_MEASURETEXT=25,\r\n D2D_SAVE=26,\r\n D2D_RESTORE=27,\r\n D2D_CREATERADIALGRADIENT=28,\r\n D2D_SETCOLORSTOP=29,\r\n D2D_SETFILLSTYLEGRADIENT=30,\r\n D2D_RELEASEID=31,\r\n D2D_CREATELINEARGRADIENT=32,\r\n D2D_SETFILLSTYLE=33,\r\n D2D_SETSTROKESTYLE=34\r\n\r\n}\r\n\r\nexport type TCanvasProxyParams = [ICanvasProps, SharedArrayBuffer, SharedArrayBuffer];\r\n\r\nexport interface ICanvas {\r\n props: ICanvasProps,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TCanvasProxyParams,\r\n drawSeq: (ds:number)=>void,\r\n }\r\n \r\nexport class twrCanvas implements ICanvas {\r\n ctx:CanvasRenderingContext2D|undefined;\r\n props:ICanvasProps={charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight:0, canvasWidth:0};\r\n owner: twrWasmModuleBase;\r\n cmdCompleteSignal?:twrSignal;\r\n canvasKeys?: twrSharedCircularBuffer;\r\n precomputedObjects: { [index: number]: \r\n (ImageData | {mem8:Uint8Array, width:number, height:number}) |\r\n CanvasGradient\r\n };\r\n\r\n constructor(element:HTMLCanvasElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n const {forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas} = modParams; \r\n this.owner=modbase;\r\n this.props.widthInChars=modParams.windim[0];\r\n this.props.heightInChars=modParams.windim[1];\r\n\r\n if (!this.owner.isWasmModule) {\r\n this.cmdCompleteSignal=new twrSignal();\r\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n }\r\n\r\n this.precomputedObjects={};\r\n \r\n if (element) {\r\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\r\n let c=element.getContext(\"2d\");\r\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\r\n\r\n c.font = fontsize.toString()+\"px Courier New\";\r\n c.textBaseline=\"top\";\r\n const sampleText=\" \";\r\n const tm=c.measureText(sampleText);\r\n this.props.charWidth=Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\r\n let fM = c.measureText(\"X\"); \r\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\r\n\r\n if (!isd2dcanvas) {\r\n element.width=this.props.charWidth*this.props.widthInChars;\r\n element.height=this.props.charHeight*this.props.heightInChars;\r\n }\r\n\r\n this.props.canvasHeight=element.height;\r\n this.props.canvasWidth=element.width;\r\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\r\n\r\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\r\n let c2=element.getContext(\"2d\");\r\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\r\n this.ctx=c2;\r\n this.ctx.font = fontsize.toString()+\"px Courier New\";\r\n this.ctx.textBaseline=\"top\";\r\n\r\n c2.fillStyle=backcolor;\r\n this.props.backColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n c2.fillStyle=forecolor;\r\n this.props.foreColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n }\r\n\r\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\r\n\r\n //console.log(\"twrCanvas.constructor props: \", this.props);\r\n }\r\n\r\n isValid() {\r\n return !!this.ctx;\r\n }\r\n\r\n getProxyParams() : TCanvasProxyParams {\r\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\r\n }\r\n\r\n getProp(pn:number): number {\r\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n\r\n/* see draw2d.h for structs that match */\r\n\r\n drawSeq(ds:number) {\r\n //console.log(\"twr::Canvas enter drawSeq\");\r\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\r\n if (!this.ctx) return;\r\n\r\n let ins=this.owner.getLong(ds); /* ds->start */\r\n const lastins=this.owner.getLong(ds+4); /* ds->last */\r\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\r\n\r\n let next:number;\r\n //let insCount=0;\r\n\r\n while (1) {\r\n\r\n //insCount++;\r\n\r\n const type:D2DType=this.owner.getLong(ins+4); /* hdr->type */\r\n if (0/*type!=D2DType.D2D_FILLRECT*/) {\r\n console.log(\"ins\",ins)\r\n console.log(\"hdr.next\",this.owner.mem8[ins],this.owner.mem8[ins+1],this.owner.mem8[ins+2],this.owner.mem8[ins+3]);\r\n console.log(\"hdr.type\",this.owner.mem8[ins+4],this.owner.mem8[ins+5]);\r\n console.log(\"next 4 bytes\", this.owner.mem8[ins+6],this.owner.mem8[ins+7],this.owner.mem8[ins+8],this.owner.mem8[ins+9]);\r\n console.log(\"and 4 more \", this.owner.mem8[ins+10],this.owner.mem8[ins+11],this.owner.mem8[ins+12],this.owner.mem8[ins+13]);\r\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\r\n }\r\n switch (type) {\r\n case D2DType.D2D_FILLRECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.fillRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKERECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.strokeRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILLCHAR:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const c=this.owner.getShort(ins+24);\r\n let txt=String.fromCharCode(c);\r\n this.ctx.fillText(txt, x, y);\r\n }\r\n break;\r\n\r\n \r\n case D2DType.D2D_FILLTEXT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const str=this.owner.getString(this.owner.getLong(ins+24));\r\n\r\n //console.log(\"filltext \",x,y,str)\r\n \r\n this.ctx.fillText(str, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MEASURETEXT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n const tmidx=this.owner.getLong(ins+12);\r\n \r\n const tm=this.ctx.measureText(str);\r\n this.owner.setDouble(tmidx+0, tm.actualBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+8, tm.actualBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+16, tm.actualBoundingBoxLeft);\r\n this.owner.setDouble(tmidx+24, tm.actualBoundingBoxRight);\r\n this.owner.setDouble(tmidx+32, tm.fontBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+40, tm.fontBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+48, tm.width);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFONT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.font=str;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.fillStyle = cssColor;\r\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETSTROKESTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.fillStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETSTROKESTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETLINEWIDTH:\r\n {\r\n const width=this.owner.getShort(ins+8); \r\n this.ctx.lineWidth=width;\r\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MOVETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.moveTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_LINETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.lineTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEZIERTO:\r\n {\r\n const cp1x=this.owner.getDouble(ins+8);\r\n const cp1y=this.owner.getDouble(ins+16);\r\n const cp2x=this.owner.getDouble(ins+24);\r\n const cp2y=this.owner.getDouble(ins+32);\r\n const x=this.owner.getDouble(ins+40);\r\n const y=this.owner.getDouble(ins+48);\r\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEGINPATH:\r\n {\r\n this.ctx.beginPath();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILL:\r\n {\r\n this.ctx.fill();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SAVE:\r\n {\r\n this.ctx.save();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_RESTORE:\r\n {\r\n this.ctx.restore();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKE:\r\n {\r\n this.ctx.stroke();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_ARC:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const radius=this.owner.getDouble(ins+24);\r\n const startAngle=this.owner.getDouble(ins+32);\r\n const endAngle=this.owner.getDouble(ins+40);\r\n const counterClockwise= (this.owner.getLong(ins+48)!=0);\r\n\r\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_IMAGEDATA:\r\n {\r\n const start=this.owner.getLong(ins+8);\r\n const length=this.owner.getLong(ins+12);\r\n const width=this.owner.getLong(ins+16);\r\n const height=this.owner.getLong(ins+20);\r\n const id=this.owner.getLong(ins+24);\r\n\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\r\n\r\n if (this.owner.isWasmModule) {\r\n const z = new Uint8ClampedArray(this.owner.memory!.buffer, start, length);\r\n this.precomputedObjects[id]=new ImageData(z, width, height);\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory\r\n this.precomputedObjects[id]={mem8: new Uint8Array(this.owner.memory!.buffer, start, length), width:width, height:height};\r\n }\r\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_CREATERADIALGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const radius0=this.owner.getDouble(ins+24);\r\n const x1=this.owner.getDouble(ins+32);\r\n const y1=this.owner.getDouble(ins+40);\r\n const radius1=this.owner.getDouble(ins+48);\r\n const id= this.owner.getLong(ins+56);\r\n\r\n let gradient=this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_CREATELINEARGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const x1=this.owner.getDouble(ins+24);\r\n const y1=this.owner.getDouble(ins+32);\r\n const id= this.owner.getLong(ins+40);\r\n \r\n let gradient=this.ctx.createLinearGradient(x0, y0, x1, y1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETCOLORSTOP:\r\n {\r\n const id = this.owner.getLong(ins+8);\r\n const pos=this.owner.getLong(ins+12);\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+16));\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n gradient.addColorStop(pos, cssColor);\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n this.ctx.fillStyle=gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_RELEASEID:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (this.precomputedObjects[id])\r\n delete this.precomputedObjects[id];\r\n else\r\n console.log(\"warning: D2D_RELEASEID with undefined ID \",id);\r\n }\r\n break\r\n\r\n \r\n\r\n case D2DType.D2D_PUTIMAGEDATA:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n const dx=this.owner.getLong(ins+12);\r\n const dy=this.owner.getLong(ins+16);\r\n const dirtyX=this.owner.getLong(ins+20);\r\n const dirtyY=this.owner.getLong(ins+24);\r\n const dirtyWidth=this.owner.getLong(ins+28);\r\n const dirtyHeight=this.owner.getLong(ins+32);\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \"+id);\r\n\r\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\r\n\r\n let imgData:ImageData;\r\n if (this.owner.isWasmModule) {\r\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\r\n imgData=this.precomputedObjects[id] as ImageData;\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\r\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\r\n const z = this.precomputedObjects[id] as {mem8:Uint8Array, width:number, height:number}; // Uint8Array\r\n const ca=Uint8ClampedArray.from(z.mem8); // shallow copy\r\n imgData=new ImageData(ca, z.width, z.height);\r\n }\r\n \r\n if (dirtyWidth==0 && dirtyHeight==0) {\r\n this.ctx.putImageData(imgData, dx, dy);\r\n }\r\n else {\r\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\r\n }\r\n }\r\n break;\r\n\r\n default:\r\n throw new Error (\"unimplemented or unknown Sequence Type in drawSeq: \"+type);\r\n }\r\n next=this.owner.getLong(ins); /* hdr->next */\r\n if (next==0) {\r\n if (ins!=lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\r\n break;\r\n }\r\n ins=next;\r\n }\r\n\r\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\r\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\r\n }\r\n}\r\n\r\nexport class twrCanvasProxy implements ICanvas {\r\n canvasKeys: twrSharedCircularBuffer;\r\n drawCompleteSignal:twrSignal;\r\n props: ICanvasProps;\r\n owner: twrWasmModuleBase;\r\n\r\n constructor(params:TCanvasProxyParams, owner:twrWasmModuleBase) {\r\n const [props, signalBuffer, canvasKeysBuffer] = params;\r\n this.drawCompleteSignal = new twrSignal(signalBuffer);\r\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\r\n this.props=props;\r\n this.owner=owner;\r\n\r\n //console.log(\"Create New twrCanvasProxy: \",this.props)\r\n\r\n }\r\n\r\n charIn() { \r\n //ctx.commit(); not avail in chrome\r\n \r\n //postMessage([\"debug\", 'x']);\r\n \r\n return this.canvasKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.canvasKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n getProp(pn:number): number {\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n \r\n drawSeq(ds:number) {\r\n this.drawCompleteSignal.reset();\r\n postMessage([\"drawseq\", [ds]]);\r\n this.drawCompleteSignal.wait();\r\n }\r\n}\r\n","//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst RDIDX = 256;\nconst WRIDX = 257;\nconst LEN = 256;\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\n// the first 256 array entries are the circular buffer\n// the next two are used for the read and write index\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\nexport class twrSharedCircularBuffer {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(258 * 4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[RDIDX] = 0;\n this.buf[WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[WRIDX];\n this.buf[i] = n;\n i++;\n if (i == LEN)\n i = 0;\n this.buf[WRIDX] = i;\n Atomics.notify(this.buf, WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[RDIDX] = i;\n return n;\n }\n else\n return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[RDIDX] == this.buf[WRIDX];\n }\n}\n//# sourceMappingURL=twrcircular.js.map","//\r\n// This class implements a circular buffer that the main javascript thread can write to, \r\n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\r\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \r\n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\r\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\r\n//\r\n\r\nconst RDIDX=256;\r\nconst WRIDX=257;\r\nconst LEN=256;\r\n\r\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\r\n// the first 256 array entries are the circular buffer\r\n// the next two are used for the read and write index\r\n\r\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\r\n\r\nexport class twrSharedCircularBuffer {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n \r\n\tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(258*4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[RDIDX]=0;\r\n this.buf[WRIDX]=0;\r\n\t}\r\n\r\n\twrite(n:number) {\r\n let i=this.buf[WRIDX];\r\n this.buf[i]=n;\r\n i++;\r\n if (i==LEN) i=0;\r\n this.buf[WRIDX]=i; \r\n Atomics.notify(this.buf, WRIDX); \r\n\t}\r\n\r\n\tread():number {\r\n if (!this.isEmpty()) {\r\n let i=this.buf[RDIDX];\r\n let n=this.buf[i];\r\n i++;\r\n this.buf[RDIDX]=i;\r\n return n;\r\n }\r\n\t\telse\r\n return -1;\r\n\t}\r\n\r\n readWait():number {\r\n if (this.isEmpty()) {\r\n const rdptr=this.buf[RDIDX];\r\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\r\n Atomics.wait(this.buf, WRIDX, rdptr);\r\n }\r\n return this.read();\r\n\t}\r\n\r\n isEmpty():boolean {\r\n return this.buf[RDIDX]==this.buf[WRIDX];\r\n }\r\n}\r\n","//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar twrSignalState;\n(function (twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})(twrSignalState || (twrSignalState = {}));\n;\nexport class twrSignal {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window valid\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == twrSignalState.WAITING) {\n //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\n //console.log(\"released...\");\n }\n }\n isSignaled() {\n return this.buf[0] == twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = twrSignalState.WAITING;\n }\n}\n//# sourceMappingURL=twrsignal.js.map","//\r\n// This class implements a simple signal/wait mechanism\r\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\r\n//\r\n\r\nenum twrSignalState {\r\n WAITING=0,\r\n SIGNALED=1\r\n};\r\n\r\nexport class twrSignal {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n\r\n \tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window valid\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) \r\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[0]=twrSignalState.WAITING;\r\n\t}\r\n\r\n\tsignal() {\r\n this.buf[0]=twrSignalState.SIGNALED; \r\n //console.log(\"about to signal\");\r\n Atomics.notify(this.buf, 0); \r\n\t}\r\n\r\n wait() {\r\n if (this.buf[0]==twrSignalState.WAITING) {\r\n //console.log(\"waiting...\");\r\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\r\n //console.log(\"released...\");\r\n\r\n }\r\n\t}\r\n isSignaled():boolean {\r\n return this.buf[0]==twrSignalState.SIGNALED;\r\n }\r\n\r\n reset() {\r\n this.buf[0]=twrSignalState.WAITING;\r\n }\r\n}\r\n","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nexport class twrDiv {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase) {\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\n this.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n if (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.divKeys.sharedArray];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */\n charOut(ch) {\n if (!this.div)\n return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n }\n switch (ch) {\n case 10: // newline\n case 13: // return\n if (ch == 10 && this.lastChar == 13)\n break; // detect CR LF and treat as single new line\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8: // backspace\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n case 0xE: // cursor on\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF: // cursor off\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for (let i = 0; i < str.length; i++)\n this.charOut(str.charCodeAt(i));\n }\n}\nexport class twrDivProxy {\n divKeys;\n constructor(params) {\n const [divKeysBuffer] = params;\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n charOut(ch) {\n postMessage([\"divout\", ch]);\n }\n}\n//# sourceMappingURL=twrdiv.js.map","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\r\nimport { IModParams } from \"./twrmodbase.js\";\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\";\r\n\r\nexport type TDivProxyParams = [SharedArrayBuffer];\r\n\r\nexport interface IDiv {\r\n charOut: (ds:number)=>void,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TDivProxyParams,\r\n }\r\n\r\n\r\nexport class twrDiv implements IDiv {\r\n\tdiv:HTMLDivElement|null|undefined;\r\n\tdivKeys?:twrSharedCircularBuffer;\r\n\tCURSOR=String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\r\n\tcursorOn:boolean=false;\r\n\tlastChar:number=0;\r\n\textraBR:boolean=false;\r\n\towner:twrWasmModuleBase;\r\n\r\n constructor(element:HTMLDivElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n\t\tthis.div=element;\r\n\t\tthis.owner=modbase;\r\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\r\n\t\t\tthis.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n\t\t}\r\n\r\n\t\tif (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\r\n\t\t\tthis.div.style.backgroundColor = modParams.backcolor;\r\n\t\t\tthis.div.style.color = modParams.forecolor;\r\n\t\t\tthis.div.style.font=modParams.fontsize.toString()+\"px arial\"\r\n\t\t}\r\n }\r\n\r\n\tisValid() {\r\n\t\treturn !!this.div;\r\n\t}\r\n\r\n getProxyParams() : TDivProxyParams {\r\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [ this.divKeys.sharedArray];\r\n }\r\n\r\n\r\n/* \r\n * add character to div. Supports the following control codes:\r\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\r\n * 0xE cursor on \r\n * 0x8 backspace\r\n * 0xF cursor off \r\n*/\r\n\tcharOut(ch:number) {\r\n\r\n\t\tif (!this.div) return;\r\n\r\n\t\t//console.log(\"div::charout: \", ch);\r\n\r\n\t\tif (this.extraBR) {\r\n\t\t\tthis.extraBR=false;\r\n\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -4);\r\n\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t}\r\n\r\n\t\tswitch (ch) {\r\n\t\t\tcase 10: // newline\r\n\t\t\tcase 13: // return\r\n\t\t\t\tif (ch==10 && this.lastChar==13) break; // detect CR LF and treat as single new line\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\r\n\t\t\t\tthis.extraBR=true;\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\t//element.scrollIntoView();\r\n\t\t\t\t//element.scrollTop = element.scrollHeight;\r\n\t\t\t\tlet p = this.div.getBoundingClientRect();\r\n\t\t\t\twindow.scrollTo(0, p.height+100);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 8: // backspace\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xE: // cursor on\r\n\t\t\t\tif (!this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=true;\r\n\t\t\t\t\tthis.div.innerHTML += this.CURSOR;\r\n\t\t\t\t\tthis.div.focus();\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xF: // cursor off\r\n\t\t\t\tif (this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=false;\r\n\t\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += String.fromCharCode(ch);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\tthis.lastChar=ch;\r\n\t}\r\n\r\n\tstringOut(str:string) {\r\n\t\tfor (let i=0; i < str.length; i++)\r\n\t\t\tthis.charOut(str.charCodeAt(i));\r\n\t}\r\n}\r\n\r\n\r\nexport class twrDivProxy implements IDiv {\r\n divKeys: twrSharedCircularBuffer;\r\n\r\n constructor(params:TDivProxyParams) {\r\n const [divKeysBuffer] = params;\r\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\r\n }\r\n\r\n charIn() { \r\n return this.divKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.divKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n\tcharOut(ch:number) {\r\n\t\tpostMessage([\"divout\", ch]);\r\n\t}\r\n}\r\n\r\n","let logline = \"\";\nexport function twrDebugLogImpl(char) {\n if (char == 10 || char == 3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\n console.log(logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n logline = \"\";\n }\n else {\n logline = logline + String.fromCharCode(char);\n if (logline.length >= 200) {\n console.log(logline);\n logline = \"\";\n }\n }\n}\n// ************************************************************************\n// debugLog doesn't currently wait for the message to log, it returns immediately.\n// I could move this to be in the twrWaitingCalls class\nexport function twrDebugLogProxy(ch) {\n postMessage([\"debug\", ch]);\n}\n//# sourceMappingURL=twrdebug.js.map","\r\nlet logline=\"\";\r\nexport function twrDebugLogImpl(char:number) {\r\n\tif (char==10 || char==3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\r\n\t\tconsole.log(logline);\t// ideally without a linefeed, but there is no way to not have a LF with console.log API.\r\n\t\tlogline=\"\";\r\n\t}\r\n\telse {\r\n\t\tlogline=logline+String.fromCharCode(char);\r\n\t\tif (logline.length>=200) {\r\n\t\t\tconsole.log(logline);\r\n\t\t\tlogline=\"\";\r\n\t\t}\r\n\t}\r\n}\r\n\r\n// ************************************************************************\r\n// debugLog doesn't currently wait for the message to log, it returns immediately.\r\n// I could move this to be in the twrWaitingCalls class\r\nexport function twrDebugLogProxy(ch:number) {\r\n postMessage([\"debug\", ch]);\r\n}\r\n\r\n","import { twrFloatUtil } from \"./twrfloat.js\";\n/*********************************************************************/\n/*********************************************************************/\n/*********************************************************************/\nexport class twrWasmModuleBase {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\n floatUtil;\n constructor(isWasmModule = false) {\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new twrFloatUtil(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/\n /*********************************************************************/\n async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n }\n catch (err) {\n console.log('loadWasm() failed to fetch: ' + pathToLoad);\n throw err;\n }\n if (!response.ok)\n throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, { env: allimports });\n this.exports = instance.instance.exports;\n if (!this.exports)\n throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory)\n throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory)\n throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer)\n console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\"setmemory\", this.memory]);\n }\n if (this.isWasmModule) {\n // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (!(this.memory.buffer instanceof ArrayBuffer))\n console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size) => {\n return new Promise(resolve => {\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n }\n catch (err) {\n console.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch (this.modParams.stdio) {\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* executeC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */\n async executeC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.executeCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async executeCImpl(fname, cparams = []) {\n if (!this.exports)\n throw new Error(\"this.exports undefined\");\n if (!this.exports[fname])\n throw new Error(\"executeC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array))\n throw new Error(\"executeC: params must be array, first arg is function name\");\n if (params.length == 0)\n throw new Error(\"executeC: missing function name\");\n let cparams = [];\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n cparams[ci++] = p;\n break;\n case 'string':\n cparams[ci++] = await this.putString(p);\n break;\n case 'object':\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n }\n else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"executeC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n ci++;\n break;\n case 'string':\n this.executeCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n case 'object':\n if (p instanceof URL) {\n this.executeCImpl('twr_free', [cparams[ci]]);\n ci = ci + 2;\n break;\n }\n else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for (let j = 0; j < u8.length; j++)\n u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.executeCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n }\n else\n throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/\n /*********************************************************************/\n // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for (i = 0; i < sin.length && i < buffer_size - 1; i++)\n this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for (let i = 0; i < u8a.length; i++)\n this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === 'object' && fnin instanceof URL))\n throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [dest, src.length];\n }\n catch (err) {\n console.log('fetchAndPutURL Error. URL: ' + fnin + '\\n' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while (this.mem8[strIndex + i] && (len === undefined ? true : i < len) && (strIndex + i) < this.mem8.length) {\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0)\n throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array((this.mem8.slice(dataptr, dataptr + size)).buffer);\n return u32;\n }\n}\n//# sourceMappingURL=twrmodbase.js.map","\r\nimport {TCanvasProxyParams} from \"./twrcanvas.js\"\r\nimport {TDivProxyParams} from \"./twrdiv.js\";\r\nimport {TWaitingCallsProxyParams} from \"./twrwaitingcalls.js\"\r\nimport {twrDebugLogImpl} from \"./twrdebug.js\";\r\nimport {twrFloatUtil} from \"./twrfloat.js\";\r\n\r\n\r\nexport type TStdioVals=\"div\"|\"canvas\"|\"null\"|\"debug\";\r\n\r\nexport interface IModOpts {\r\n\tstdio?:TStdioVals, \r\n\twindim?:[number, number],\r\n\tforecolor?:string,\r\n\tbackcolor?:string,\r\n\tfontsize?:number,\r\n\tisd2dcanvas?:boolean,\r\n\timports?:{},\r\n}\r\n\r\nexport interface IModParams {\r\n\tstdio:TStdioVals, \r\n\twindim:[number, number],\r\n\tforecolor:string,\r\n\tbackcolor:string,\r\n\tfontsize:number,\r\n\tstyleIsDefault: boolean\r\n\tisd2dcanvas:boolean,\r\n\timports:{[index:string]:Function},\r\n}\r\n\r\nexport interface IModInWorkerParams {\r\n\tdivProxyParams:TDivProxyParams,\r\n\tcanvasProxyParams:TCanvasProxyParams,\r\n\twaitingCallsProxyParams:TWaitingCallsProxyParams,\r\n}\r\n\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n\r\nexport abstract class twrWasmModuleBase {\r\n\tmemory?:WebAssembly.Memory;\r\n\tmem8:Uint8Array;\r\n\tmem32:Uint32Array;\r\n\tmemD:Float64Array;\r\n\tabstract malloc:(size:number)=>Promise;\r\n\tabstract modParams:IModParams;\r\n\texports?:WebAssembly.Exports;\r\n\tisWorker=false;\r\n\tisWasmModule:boolean; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\r\n\tfloatUtil:twrFloatUtil;\r\n\r\n\tconstructor(isWasmModule=false) {\r\n\t\tthis.isWasmModule=isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\r\n\t\tthis.mem8=new Uint8Array(); \t// avoid type errors\r\n\t\tthis.mem32=new Uint32Array(); // avoid type errors\r\n\t\tthis.memD=new Float64Array(); // avoid type errors\r\n\t\tthis.floatUtil=new twrFloatUtil(this);\r\n\t\t//console.log(\"size of mem8 after constructor\",this.mem8.length);\r\n\t}\r\n\r\n\t/*********************************************************************/\r\n\t/*********************************************************************/\r\n\r\n\tasync loadWasm(pathToLoad:string) {\r\n\t\t//console.log(\"fileToLoad\",fileToLoad)\r\n\r\n\t\tlet response;\r\n\t\ttry {\r\n\t\t\tresponse=await fetch(pathToLoad);\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('loadWasm() failed to fetch: '+pathToLoad);\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t\t\r\n\t\tif (!response.ok) throw new Error(\"fetch response error on file '\"+pathToLoad+\"'\\n\"+response.statusText);\r\n\r\n\t\ttry {\r\n\t\t\tlet wasmBytes = await response.arrayBuffer();\r\n\r\n\t\t\tlet allimports:WebAssembly.ModuleImports = { \r\n\t\t\t\t...this.modParams.imports\r\n\t\t\t};\r\n\r\n\t\t\tlet instance = await WebAssembly.instantiate(wasmBytes, {env: allimports});\r\n\r\n\t\t\tthis.exports=instance.instance.exports;\r\n\t\t\tif (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\r\n\r\n\t\t\tif (this.memory) throw new Error (\"unexpected error -- this.memory already set\");\r\n\t\t\tthis.memory=this.exports.memory as WebAssembly.Memory;\r\n\t\t\tif (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\r\n\t\t\tthis.mem8 = new Uint8Array(this.memory.buffer);\r\n\t\t\tthis.mem32 = new Uint32Array(this.memory.buffer);\r\n\t\t\tthis.memD = new Float64Array(this.memory.buffer);\r\n\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\tif (this.isWorker) {\r\n\t\t\t\tif (this.memory.buffer instanceof ArrayBuffer)\r\n\t\t\t\t\tconsole.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\r\n\t\t\t\t\r\n\t\t\t\tpostMessage([\"setmemory\",this.memory]);\r\n\t\t\t}\r\n\t\t\tif (this.isWasmModule) {\r\n\t\t\t\t// here if twrWasmModule, twrWasmModuleAsync overrides this function\r\n\t\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\t\tif (!(this.memory.buffer instanceof ArrayBuffer))\r\n\t\t\t\t\tconsole.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\r\n\t\t\t}\r\n\r\n\t\t\tthis.malloc=(size:number)=>{\r\n\t\t\t\treturn new Promise(resolve => {\r\n\t\t\t\t\tconst m=this.exports!.twr_malloc as (size:number)=>number;\r\n\t\t\t\t\tresolve(m(size));\r\n\t\t\t\t});\r\n\t\t };\r\n\r\n\t\t\tthis.init();\r\n\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t}\r\n\r\n\tprivate init() {\r\n\t\t//console.log(\"loadWasm.init() enter\")\r\n\t\t\tlet p:number;\r\n\t\t\tswitch (this.modParams.stdio) {\r\n\t\t\t\tcase \"debug\":\r\n\t\t\t\t\tp=0;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"div\":\r\n\t\t\t\t\tp=1;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"canvas\":\r\n\t\t\t\t\tp=2;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"null\":\r\n\t\t\t\t\tp=3;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tp=0; // debug\r\n\t\t\t}\r\n\r\n\t\t\tconst twrInit=this.exports!.twr_wasm_init as CallableFunction;\r\n\t\t\t//console.log(\"twrInit:\",twrInit)\r\n\t\t\ttwrInit(p, this.mem8.length);\r\n\t}\r\n\r\n\t/* executeC takes an array where:\r\n\t* the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\r\n\t* and the next entries are a variable number of parameters to pass to the C function, of type\r\n\t* number - converted to int32 or float64 as appropriate\r\n\t* string - converted to a an index (ptr) into a module Memory returned via stringToMem()\r\n\t* URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\r\n\t* Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\r\n */\r\n\r\n\tasync executeC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\t\tconst cparams=await this.preCallC(params);\r\n\t\tlet retval = this.executeCImpl(params[0], cparams);\r\n\t\tthis.postCallC(cparams, params);\r\n\t\treturn retval;\r\n\t}\r\n\r\n\tasync executeCImpl(fname:string, cparams:number[]=[]) {\r\n\t\tif (!this.exports) throw new Error(\"this.exports undefined\");\r\n\t\tif (!this.exports[fname]) throw new Error(\"executeC: function '\"+fname+\"' not in export table. Use --export wasm-ld flag.\");\r\n\r\n\t\tconst f = this.exports[fname] as CallableFunction;\r\n\t\tlet cr=f(...cparams);\r\n\r\n\t\treturn cr;\r\n\t}\r\n\r\n\t// convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\r\n\tasync preCallC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tif (!(params.constructor === Array)) throw new Error (\"executeC: params must be array, first arg is function name\");\r\n\t\tif (params.length==0) throw new Error(\"executeC: missing function name\");\r\n\r\n\t\tlet cparams:number[]=[];\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tcparams[ci++]=p;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tcparams[ci++]=await this.putString(p);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tconst r=await this.fetchAndPutURL(p);\r\n\t\t\t\t\t\tcparams[ci++]=r[0]; // mem index\r\n\t\t\t\t\t\tcparams[ci++]=r[1]; // len\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tconst r=await this.putArrayBuffer(p);\r\n\t\t\t\t\t\tcparams[ci++]=r; // mem index\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tthrow new Error (\"executeC: invalid object type passed in\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn cparams;\r\n\t}\r\n\r\n\t// free the mallocs; copy array buffer data from malloc back to arraybuffer\r\n\tasync postCallC(cparams:number[], params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tthis.executeCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t\t\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tthis.executeCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\t\tci=ci+2;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tlet u8=new Uint8Array(p);\r\n\t\t\t\t\t\tfor (let j=0; j= this.mem32.length) throw new Error(\"invalid index passed to getLong: \"+idx+\", this.mem32.length: \"+this.mem32.length);\r\n\t\tconst long:number = this.mem32[idx32];\r\n\t\treturn long;\r\n\t}\r\n\t\r\n\tsetLong(idx:number, value:number) {\r\n const idx32 = Math.floor(idx / 4);\r\n if (idx32 * 4 != idx)\r\n throw new Error(\"setLong passed non long aligned address\");\r\n if (idx32 < 0 || idx32 >= this.mem32.length)\r\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\r\n this.mem32[idx32]=value;\r\n }\r\n\r\n\tgetDouble(idx:number): number {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"getLong passed non Float64 aligned address\")\r\n\t\tconst long:number = this.memD[idx64];\r\n\t\treturn long;\r\n\t}\r\n\r\n\tsetDouble(idx:number, value:number) {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"setDouble passed non Float64 aligned address\")\r\n\t\tthis.memD[idx64]=value;\r\n\t}\r\n\r\n\tgetShort(idx:number): number {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getShort: \"+idx);\r\n\t\tconst short:number = this.mem8[idx]+this.mem8[idx+1]*256;\r\n\t\treturn short;\r\n\t}\r\n\r\n\t// get a string out of module memory\r\n\t// null terminated, up until max of (optional) len\r\n\tgetString(strIndex:number, len?:number): string {\r\n\t\tlet sout=\"\";\r\n\r\n\t\tlet i=0;\r\n\t\twhile (this.mem8[strIndex+i] && (len===undefined?true:i= this.mem8.length) throw new Error(\"invalid index passed to getU8: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU8\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU8\")\r\n\r\n\t\tconst u8=this.mem8.slice(dataptr, dataptr+size);\r\n\t\treturn u8;\r\n\t}\r\n\r\n\t// get a int32 array out of module memory when passed in index to [size, dataptr]\r\n\tgetU32Arr(idx:number): Uint32Array {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getU32: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU32\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU32\")\r\n\r\n\t\tif (size%4!=0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\r\n\r\n\t\tconst u32 = new Uint32Array( (this.mem8.slice(dataptr, dataptr+size)).buffer );\r\n\t\treturn u32;\r\n\t}\r\n}\r\n","export class twrFloatUtil {\n mod;\n constructor(mod) {\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\")\n return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\")\n return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll('D', 'e').replaceAll('d', 'e'));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n }\n else {\n let r = value.toString();\n if (r.length > max_precision)\n r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, // char *\n sizeInBytes, //size_t\n value, // double\n fracpart_numdigits, //int\n dec, // int *\n sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1)\n return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) { /* nan */\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (!Number.isFinite(value)) { /* infinity */\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n }\n else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split('.');\n if (intPart == \"0\")\n intPart = \"\";\n if (intPart.length > 0) { // has integer part\n decpos = intPart.length;\n digits = intPart + fracPart;\n }\n else { // only a fraction\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length)\n return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */\n }\n}\n//# sourceMappingURL=twrfloat.js.map","\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\"\r\n\r\nexport class twrFloatUtil {\r\n mod: twrWasmModuleBase;\r\n\r\n constructor(mod: twrWasmModuleBase) {\r\n this.mod=mod;\r\n }\r\n\r\n atod(strptr:number):number {\r\n const str=this.mod.getString(strptr);\r\n\r\n const upper=str.trimStart().toUpperCase();\r\n if (upper==\"INF\" || upper==\"+INF\")\r\n return Number.POSITIVE_INFINITY;\r\n else if (upper==\"-INF\")\r\n return Number.NEGATIVE_INFINITY\r\n else {\r\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\r\n const r=Number.parseFloat(str.replaceAll('D','e').replaceAll('d','e'));\r\n return r;\r\n }\r\n }\r\n\r\n dtoa(buffer:number, buffer_size:number, value:number, max_precision:number):void {\r\n if (max_precision==-1) {\r\n const r=value.toString();\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n else {\r\n let r=value.toString();\r\n if (r.length>max_precision)\r\n r=value.toPrecision(max_precision);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n }\r\n\r\n toFixed(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toFixed(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n toExponential(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toExponential(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\r\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\r\n // Negative exponents must be now smaller than 1e-99\r\n // fully-function C version also int he source, but this is the version enabled by default\r\n fcvtS(\r\n buffer:number, // char *\r\n sizeInBytes:number, //size_t\r\n value:number, // double\r\n fracpart_numdigits:number, //int\r\n dec:number, // int *\r\n sign:number // int *\r\n ):number {\r\n\r\n if (buffer==0 ||sign==0 || dec==0 || sizeInBytes<1) return 1;\r\n\r\n let digits:string;\r\n let decpos:number;\r\n let s=0; // default to positive\r\n\r\n\r\n if (Number.isNaN(value)) { /* nan */\r\n digits=\"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (!Number.isFinite(value)) { /* infinity */\r\n digits=\"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (value==0) { \r\n digits=\"000000000000000000000000000000000000\".slice(0,fracpart_numdigits);\r\n decpos=0;\r\n }\r\n \r\n else {\r\n\r\n if (value<0) {\r\n s=1; // negative\r\n value=Math.abs(value);\r\n }\r\n\r\n if (fracpart_numdigits>100 || value > 1e+21 || value < 1e-99) { \r\n this.mod.copyString(buffer, sizeInBytes, \"\");\r\n this.mod.mem32[dec]=0;\r\n return 1;\r\n }\r\n\r\n const roundValStr=value.toFixed(fracpart_numdigits);\r\n let [intPart=\"\", fracPart=\"\"] = roundValStr.split('.');\r\n if (intPart==\"0\") intPart=\"\";\r\n\r\n if (intPart.length>0) { // has integer part\r\n decpos=intPart.length;\r\n digits=intPart+fracPart;\r\n }\r\n else { // only a fraction\r\n digits=fracPart.replace(/^0+/,\"\"); // remove leading zeros\r\n decpos=digits.length-fracPart.length;\r\n }\r\n }\r\n\r\n if (sizeInBytes-1 < digits.length) return 1; \r\n this.mod.copyString(buffer, sizeInBytes, digits);\r\n this.mod.setLong(dec, decpos);\r\n this.mod.setLong(sign, s);\r\n\r\n return 0;\r\n\r\n /*\r\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\r\n\r\n let decpos=0;\r\n let digits:string;\r\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\r\n \r\n if (decpos>0) { // has integer part\r\n const intlen=Math.max(decpos, 0);\r\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\r\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\r\n }\r\n else { // only a fraction\r\n const intpart=Math.trunc(value);\r\n const fracpart=value-intpart;\r\n const prec=fracpart_numdigits- (-decpos);\r\n console.log(\"prec=\",prec);\r\n if (prec<1) {\r\n digits=\"\";\r\n }\r\n else {\r\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\");\r\n }\r\n }\r\n\r\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\r\n console.log('digits=',digits);\r\n console.log('dec=',decpos);\r\n console.log(\"sign=\",s);\r\n */\r\n\r\n\r\n }\r\n}","import { twrSignal } from \"./twrsignal.js\";\nimport { twrTimeImpl } from \"./twrdate.js\";\n// This class is used in the Main JS thread \nexport class twrWaitingCalls {\n callCompleteSignal;\n parameters;\n constructor() {\n this.callCompleteSignal = new twrSignal();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(() => {\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = twrTimeImpl();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [this.callCompleteSignal.sharedArray, this.parameters.buffer];\n }\n processMessage(msgType, data) {\n switch (msgType) {\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\n// This class is used in the worker thread \nexport class twrWaitingCallsProxy {\n callCompleteSignal;\n parameters;\n constructor(params) {\n this.callCompleteSignal = new twrSignal(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\"sleep\", [ms]]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\"time\"]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n//# sourceMappingURL=twrwaitingcalls.js.map","import { twrSignal } from \"./twrsignal.js\";\r\nimport {twrTimeImpl} from \"./twrdate.js\"\r\n\r\n// These classes are used to proxy a call across the worker thread - main thread boundary and wait for the result\r\n\r\nexport type TWaitingCallsProxyParams = [SharedArrayBuffer, SharedArrayBuffer]; // twrSignal, parameters \r\n\r\n// This class is used in the Main JS thread \r\nexport class twrWaitingCalls {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor() {\r\n\t\tthis.callCompleteSignal=new twrSignal();\r\n\t\tthis.parameters=new Uint32Array(new SharedArrayBuffer(4));\r\n\t}\r\n\r\n\tprivate startSleep(ms:number) {\r\n\r\n\t\tsetTimeout(()=>{\r\n\t\t\tthis.callCompleteSignal.signal();\r\n\t\t}, ms);\r\n\t\t\r\n\t}\r\n\r\n\tprivate time() {\r\n\t\tconst ms=twrTimeImpl();\r\n\t\tthis.parameters[0]=ms;\r\n\t\tthis.callCompleteSignal.signal();\r\n\t}\r\n\r\n\tgetProxyParams():TWaitingCallsProxyParams {\r\n\t\treturn [this.callCompleteSignal.sharedArray, this.parameters.buffer as SharedArrayBuffer];\t\r\n\t}\r\n\r\n\tprocessMessage(msgType:string, data:any[]):boolean {\r\n\t\tswitch (msgType) {\r\n\t\t\tcase \"sleep\":\r\n\t\t\t\tconst [ms] = data;\r\n\t\t\t\tthis.startSleep(ms);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"time\":\r\n\t\t\t\tthis.time();\r\n\t\t\t\tbreak;\r\n\t\t\t\r\n\t\t\tdefault:\r\n\t\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\treturn true;\r\n\t}\r\n\r\n}\r\n\r\n// This class is used in the worker thread \r\nexport class twrWaitingCallsProxy {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor(params:TWaitingCallsProxyParams) {\r\n\t\tthis.callCompleteSignal=new twrSignal(params[0]);\r\n\t\tthis.parameters=new Uint32Array(params[1]);\r\n\t}\r\n\r\n\tsleep(ms:number) {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"sleep\", [ms]]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t}\r\n\r\n\ttime() {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"time\"]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t\treturn this.parameters[0];\r\n\t}\r\n\r\n}\r\n","export function twrTimeImpl() {\n return Date.now();\n}\n//# sourceMappingURL=twrdate.js.map","\r\nexport function twrTimeImpl() {\r\n\r\n return Date.now();\r\n\r\n}"],"names":["$b93f1fdf40141def$var$twrSignalState","$c4741cac81d14197$var$D2DType","twrSignalState","D2DType","$3e39efa823870787$var$mod","$892fccfc812d5e20$export$a01cca24f011573a","sharedArray","buf","constructor","sa","window","crossOriginIsolated","location","protocol","Error","SharedArrayBuffer","Int32Array","write","n","i","Atomics","notify","read","isEmpty","readWait","rdptr","wait","$b93f1fdf40141def$export$e37a7b7b851b97f3","WAITING","signal","SIGNALED","isSignaled","reset","$c4741cac81d14197$export$c779b2cd00544976","canvasKeys","drawCompleteSignal","props","owner","params","signalBuffer","canvasKeysBuffer","charIn","inkey","getProp","pn","propName","getString","drawSeq","ds","postMessage","$8963973702ae5462$export$b377f0bbf2c7581e","divKeys","divKeysBuffer","charOut","ch","$8ac0b786da854328$export$485af4d0039b3389","$e72303a1db04bdfa$export$918ffb7e046a537b","mod","atod","strptr","str","upper","trimStart","toUpperCase","Number","POSITIVE_INFINITY","NEGATIVE_INFINITY","parseFloat","replaceAll","dtoa","buffer","buffer_size","value","max_precision","r","toString","copyString","length","toPrecision","toFixed","decdigits","toExponential","fcvtS","sizeInBytes","fracpart_numdigits","dec","sign","digits","decpos","s","isNaN","slice","isFinite","Math","abs","mem32","intPart","fracPart","roundValStr","split","replace","setLong","$ece7fa3ed770778a$export$c83a0a3bffe07399","memory","mem8","memD","exports","isWorker","isWasmModule","floatUtil","Uint8Array","Uint32Array","Float64Array","loadWasm","pathToLoad","response","fetch","err","console","log","ok","statusText","wasmBytes","arrayBuffer","allimports","modParams","imports","instance","WebAssembly","instantiate","env","ArrayBuffer","malloc","size","Promise","resolve","m","twr_malloc","init","stack","p","stdio","twrInit","twr_wasm_init","executeC","cparams","preCallC","retval","executeCImpl","postCallC","fname","f","Array","ci","putString","URL","fetchAndPutURL","putArrayBuffer","u8","j","sin","charCodeAt","strIndex","putU8","u8a","dest","ab","fnin","src","getLong","idx","idx32","floor","getDouble","idx64","setDouble","getShort","len","sout","undefined","String","fromCharCode","getU8Arr","rv","dataptr","getU32Arr","$aff9c2c494d23fe3$export$78d2a4633fe89379","callCompleteSignal","parameters","sleep","ms","time","onmessage","e","data","$3e39efa823870787$var$twrWasmModuleInWorker","modWorkerParams","urlToLoad","then","catch","ex","rc","modInWorkerParams","canvasProxy","canvasProxyParams","divProxy","divProxyParams","waitingCallsProxy","waitingCallsProxyParams","twrDebugLog","twrSleep","bind","twrTime","twrDivCharOut","twrDivCharIn","twrCanvasCharIn","twrCanvasInkey","twrCanvasGetProp","twrCanvasDrawSeq","twrSin","twrCos","cos","twrTan","tan","twrFAbs","twrACos","acos","twrASin","asin","twrATan","atan","twrExp","exp","twrFloor","twrCeil","ceil","twrFMod","x","y","twrLog","twrPow","pow","twrSqrt","sqrt","twrTrunc","trunc","twrDtoa","twrToFixed","twrToExponential","twrAtod","twrFcvtS"],"version":3,"file":"twrmodworker.2165e649.js.map"} \ No newline at end of file +{"mappings":"A,C,SQKK,EJgBA,EIhBA,EJgBA,MFZD,CISE,OAAO,EACZ,WAA8B,AAC9B,CAAA,GAAe,AAEf,aAAa,CAAqB,CAAlC,CACO,GAAI,AAAkB,aAAlB,OAAO,QACH,CAAC,qBAAuB,AAA+B,UAA7B,OAAO,QAAQ,CAAC,QAAQ,CAAe,MAAM,AAAI,MAAM,4DAA4D,oBAAoB,iCAErK,EAAI,IAAI,CAAC,WAAW,CAAC,EACpB,IAAI,CAAC,WAAW,CAAC,IAAI,kBAAkB,MAClD,IAAI,CAAC,GAAG,CAAC,IAAI,WAAW,IAAI,CAAC,WAAW,EAClC,IAAI,CAAC,GAAG,CArBJ,IAqBW,CAAC,EAChB,IAAI,CAAC,GAAG,CArBJ,IAqBW,CAAC,CACvB,CAEA,MAAM,CAAQ,CAAd,CACO,IAAI,EAAE,IAAI,CAAC,GAAG,CAzBV,IAyBiB,AACrB,CAAA,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAzBV,OA2BE,GAAQ,CAAA,EAAE,CAAA,EACd,IAAI,CAAC,GAAG,CA7BJ,IA6BW,CAAC,EAChB,QAAQ,MAAM,CAAC,IAAI,CAAC,GAAG,CA9BnB,IA+BX,CAEA,MAAA,CACO,GAAK,IAAI,CAAC,OAAO,GAQb,OAAO,EARU,EACjB,IAAI,EAAE,IAAI,CAAC,GAAG,CApCd,IAoCqB,CACjB,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,CAGjB,OAFA,IACA,IAAI,CAAC,GAAG,CAvCR,IAuCe,CAAC,EACT,CACV,CAGR,CAEG,UAAA,CACI,GAAI,IAAI,CAAC,OAAO,GAAI,CAChB,IAAM,EAAM,IAAI,CAAC,GAAG,CAhDpB,IAgD2B,CAE3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AC,IAAI,CAAC,GAEnD,OAAO,KAAK,GAAG,CACf,OAAO,KAAK,GAAG,CACf,OAAQ,KAAK,GAAG,CAChB,QAAS,KAAK,GAAG,CACjB,QAAS,KAAK,IAAI,CAClB,QAAS,KAAK,IAAI,CAClB,QAAS,KAAK,IAAI,CAClB,OAAQ,KAAK,GAAG,CAChB,SAAU,KAAK,KAAK,CACpB,QAAS,KAAK,IAAI,CAClB,QAAS,SAAS,CAAQ,CAAE,CAAQ,EAAG,OAAO,EAAE,CAAC,EACjD,OAAQ,KAAK,GAAG,CAChB,OAAQ,KAAK,GAAG,CAChB,QAAS,KAAK,IAAI,CAClB,SAAU,KAAK,KAAK,CAEX,QAAS,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EACzD,WAAY,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EACtD,iBAAkB,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAClE,QAAS,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAChD,SAAU,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAE5C,CACN,CACF,C,C","sources":["","../../lib-js/twrmodworker.js","../../source/twr-wasm-ts/twrmodworker.ts","../../lib-js/twrcanvas.js","../../source/twr-wasm-ts/twrcanvas.ts","../../lib-js/twrcircular.js","../../source/twr-wasm-ts/twrcircular.ts","../../lib-js/twrsignal.js","../../source/twr-wasm-ts/twrsignal.ts","../../lib-js/twrdiv.js","../../source/twr-wasm-ts/twrdiv.ts","../../lib-js/twrdebug.js","../../source/twr-wasm-ts/twrdebug.ts","../../lib-js/twrmodbase.js","../../source/twr-wasm-ts/twrmodbase.ts","../../lib-js/twrfloat.js","../../source/twr-wasm-ts/twrfloat.ts","../../lib-js/twrwaitingcalls.js","../../source/twr-wasm-ts/twrwaitingcalls.ts","../../lib-js/twrdate.js","../../source/twr-wasm-ts/twrdate.ts"],"sourcesContent":["(() => {\nvar $3e39efa823870787$exports = {};\n// this script is the WebWorker thead used by class twrWasmAsyncModule\n//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst $892fccfc812d5e20$var$RDIDX = 256;\nconst $892fccfc812d5e20$var$WRIDX = 257;\nconst $892fccfc812d5e20$var$LEN = 256;\nclass $892fccfc812d5e20$export$a01cca24f011573a {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(1032);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[$892fccfc812d5e20$var$RDIDX] = 0;\n this.buf[$892fccfc812d5e20$var$WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[$892fccfc812d5e20$var$WRIDX];\n this.buf[i] = n;\n i++;\n if (i == $892fccfc812d5e20$var$LEN) i = 0;\n this.buf[$892fccfc812d5e20$var$WRIDX] = i;\n Atomics.notify(this.buf, $892fccfc812d5e20$var$WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[$892fccfc812d5e20$var$RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[$892fccfc812d5e20$var$RDIDX] = i;\n return n;\n } else return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[$892fccfc812d5e20$var$RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, $892fccfc812d5e20$var$WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[$892fccfc812d5e20$var$RDIDX] == this.buf[$892fccfc812d5e20$var$WRIDX];\n }\n}\n\n\n//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar $b93f1fdf40141def$var$twrSignalState;\n(function(twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})($b93f1fdf40141def$var$twrSignalState || ($b93f1fdf40141def$var$twrSignalState = {}));\nclass $b93f1fdf40141def$export$e37a7b7b851b97f3 {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == $b93f1fdf40141def$var$twrSignalState.WAITING) //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, $b93f1fdf40141def$var$twrSignalState.WAITING);\n }\n isSignaled() {\n return this.buf[0] == $b93f1fdf40141def$var$twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.WAITING;\n }\n}\n\n\nvar $c4741cac81d14197$var$D2DType;\n(function(D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})($c4741cac81d14197$var$D2DType || ($c4741cac81d14197$var$D2DType = {}));\nclass $c4741cac81d14197$export$2f298dd69cef3c34 {\n ctx;\n props = {\n charWidth: 0,\n charHeight: 0,\n foreColor: 0,\n backColor: 0,\n widthInChars: 0,\n heightInChars: 0,\n canvasHeight: 0,\n canvasWidth: 0\n };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase){\n const { forecolor: forecolor, backcolor: backcolor, fontsize: fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)();\n this.canvasKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.props,\n this.cmdCompleteSignal.sharedArray,\n this.canvasKeys.sharedArray\n ];\n }\n getProp(pn) {\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */ drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx) return;\n let ins = this.owner.getLong(ds); /* ds->start */ \n const lastins = this.owner.getLong(ds + 4); /* ds->last */ \n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while(true){\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */ \n switch(type){\n case $c4741cac81d14197$var$D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_BEGINPATH:\n this.ctx.beginPath();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILL:\n this.ctx.fill();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SAVE:\n this.ctx.save();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_RESTORE:\n this.ctx.restore();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_STROKE:\n this.ctx.stroke();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = this.owner.getLong(ins + 48) != 0;\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n } else this.precomputedObjects[id] = {\n mem8: new Uint8Array(this.owner.memory.buffer, start, length),\n width: width,\n height: height\n };\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id]) delete this.precomputedObjects[id];\n else console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n else {\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) this.ctx.putImageData(imgData, dx, dy);\n else this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */ \n if (next == 0) {\n if (ins != lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nclass $c4741cac81d14197$export$c779b2cd00544976 {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner){\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)(signalBuffer);\n this.canvasKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\n \"drawseq\",\n [\n ds\n ]\n ]);\n this.drawCompleteSignal.wait();\n }\n}\n\n\n\nclass $8963973702ae5462$export$dd376bb3f10f6896 {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611);\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase){\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) this.divKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(); // tsconfig, lib must be set to 2017 or higher\n if (this.div && !modParams.styleIsDefault) {\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.divKeys.sharedArray\n ];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */ charOut(ch) {\n if (!this.div) return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n }\n switch(ch){\n case 10:\n case 13:\n if (ch == 10 && this.lastChar == 13) break; // detect CR LF and treat as single new line\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n case 0xE:\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF:\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for(let i = 0; i < str.length; i++)this.charOut(str.charCodeAt(i));\n }\n}\nclass $8963973702ae5462$export$b377f0bbf2c7581e {\n divKeys;\n constructor(params){\n const [divKeysBuffer] = params;\n this.divKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n charOut(ch) {\n postMessage([\n \"divout\",\n ch\n ]);\n }\n}\n\n\nlet $8ac0b786da854328$var$logline = \"\";\nfunction $8ac0b786da854328$export$16b4216ec014493d(char) {\n if (char == 10 || char == 3) {\n console.log($8ac0b786da854328$var$logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n $8ac0b786da854328$var$logline = \"\";\n } else {\n $8ac0b786da854328$var$logline = $8ac0b786da854328$var$logline + String.fromCharCode(char);\n if ($8ac0b786da854328$var$logline.length >= 200) {\n console.log($8ac0b786da854328$var$logline);\n $8ac0b786da854328$var$logline = \"\";\n }\n }\n}\nfunction $8ac0b786da854328$export$485af4d0039b3389(ch) {\n postMessage([\n \"debug\",\n ch\n ]);\n}\n\n\nclass $e72303a1db04bdfa$export$918ffb7e046a537b {\n mod;\n constructor(mod){\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\") return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\") return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll(\"D\", \"e\").replaceAll(\"d\", \"e\"));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n } else {\n let r = value.toString();\n if (r.length > max_precision) r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, sizeInBytes, value, fracpart_numdigits, dec, sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1) return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) {\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (!Number.isFinite(value)) {\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n } else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split(\".\");\n if (intPart == \"0\") intPart = \"\";\n if (intPart.length > 0) {\n decpos = intPart.length;\n digits = intPart + fracPart;\n } else {\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length) return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */ }\n}\n\n\nclass $ece7fa3ed770778a$export$c83a0a3bffe07399 {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule;\n floatUtil;\n constructor(isWasmModule = false){\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new (0, $e72303a1db04bdfa$export$918ffb7e046a537b)(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/ /*********************************************************************/ async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n } catch (err) {\n console.log(\"loadWasm() failed to fetch: \" + pathToLoad);\n throw err;\n }\n if (!response.ok) throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, {\n env: allimports\n });\n this.exports = instance.instance.exports;\n if (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory) throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer) console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\n \"setmemory\",\n this.memory\n ]);\n }\n if (this.isWasmModule) // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n {\n if (!(this.memory.buffer instanceof ArrayBuffer)) console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size)=>{\n return new Promise((resolve)=>{\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n } catch (err) {\n console.log(\"WASM instantiate error: \" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch(this.modParams.stdio){\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* callC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */ async callC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.callCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async callCImpl(fname, cparams = []) {\n if (!this.exports) throw new Error(\"this.exports undefined\");\n if (!this.exports[fname]) throw new Error(\"callC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array)) throw new Error(\"callC: params must be array, first arg is function name\");\n if (params.length == 0) throw new Error(\"callC: missing function name\");\n let cparams = [];\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n cparams[ci++] = p;\n break;\n case \"string\":\n cparams[ci++] = await this.putString(p);\n break;\n case \"object\":\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n } else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"callC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n ci++;\n break;\n case \"string\":\n this.callCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n case \"object\":\n if (p instanceof URL) {\n this.callCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci = ci + 2;\n break;\n } else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for(let j = 0; j < u8.length; j++)u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.callCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n } else throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/ /*********************************************************************/ // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for(i = 0; i < sin.length && i < buffer_size - 1; i++)this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for(let i = 0; i < u8a.length; i++)this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === \"object\" && fnin instanceof URL)) throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [\n dest,\n src.length\n ];\n } catch (err) {\n console.log(\"fetchAndPutURL Error. URL: \" + fnin + \"\\n\" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while(this.mem8[strIndex + i] && (len === undefined ? true : i < len) && strIndex + i < this.mem8.length){\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array(this.mem8.slice(dataptr, dataptr + size).buffer);\n return u32;\n }\n}\n\n\n\nfunction $4af5689abbc8d01b$export$78724cdcf7ebea1d() {\n return Date.now();\n}\n\n\nclass $aff9c2c494d23fe3$export$9e37856d1928d388 {\n callCompleteSignal;\n parameters;\n constructor(){\n this.callCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(()=>{\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = (0, $4af5689abbc8d01b$export$78724cdcf7ebea1d)();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [\n this.callCompleteSignal.sharedArray,\n this.parameters.buffer\n ];\n }\n processMessage(msgType, data) {\n switch(msgType){\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\nclass $aff9c2c494d23fe3$export$78d2a4633fe89379 {\n callCompleteSignal;\n parameters;\n constructor(params){\n this.callCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\n \"sleep\",\n [\n ms\n ]\n ]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\n \"time\"\n ]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n\n\nlet $3e39efa823870787$var$mod;\nonmessage = function(e) {\n //console.log('twrworker.js: message received from main script: '+e.data);\n if (e.data[0] == \"startup\") {\n const params = e.data[1];\n //console.log(\"Worker startup params:\",params);\n $3e39efa823870787$var$mod = new $3e39efa823870787$var$twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\n $3e39efa823870787$var$mod.loadWasm(params.urlToLoad).then(()=>{\n postMessage([\n \"startupOkay\"\n ]);\n }).catch((ex)=>{\n console.log(\".catch: \", ex);\n postMessage([\n \"startupFail\",\n ex\n ]);\n });\n } else if (e.data[0] == \"callC\") $3e39efa823870787$var$mod.callCImpl(e.data[1], e.data[2]).then((rc)=>{\n postMessage([\n \"callCOkay\",\n rc\n ]);\n }).catch((e)=>{\n console.log(\"exception in callC twrworker.js\\n\");\n console.log(e);\n postMessage([\n \"callCFail\",\n e\n ]);\n });\n else console.log(\"twrworker.js: unknown message: \" + e);\n};\n// ************************************************************************\nclass $3e39efa823870787$var$twrWasmModuleInWorker extends (0, $ece7fa3ed770778a$export$c83a0a3bffe07399) {\n malloc;\n modParams;\n constructor(modParams, modInWorkerParams){\n super();\n this.isWorker = true;\n this.malloc = (size)=>{\n throw new Error(\"error - un-init malloc called\");\n };\n this.modParams = modParams;\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\n const canvasProxy = new (0, $c4741cac81d14197$export$c779b2cd00544976)(modInWorkerParams.canvasProxyParams, this);\n const divProxy = new (0, $8963973702ae5462$export$b377f0bbf2c7581e)(modInWorkerParams.divProxyParams);\n const waitingCallsProxy = new (0, $aff9c2c494d23fe3$export$78d2a4633fe89379)(modInWorkerParams.waitingCallsProxyParams);\n this.modParams.imports = {\n twrDebugLog: (0, $8ac0b786da854328$export$485af4d0039b3389),\n twrSleep: waitingCallsProxy.sleep.bind(waitingCallsProxy),\n twrTime: waitingCallsProxy.time.bind(waitingCallsProxy),\n twrDivCharOut: divProxy.charOut.bind(divProxy),\n twrDivCharIn: divProxy.charIn.bind(divProxy),\n twrCanvasCharIn: canvasProxy.charIn.bind(canvasProxy),\n twrCanvasInkey: canvasProxy.inkey.bind(canvasProxy),\n twrCanvasGetProp: canvasProxy.getProp.bind(canvasProxy),\n twrCanvasDrawSeq: canvasProxy.drawSeq.bind(canvasProxy),\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function(x, y) {\n return x % y;\n },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n}\n\n})();\n//# sourceMappingURL=twrmodworker.2165e649.js.map\n","// this script is the WebWorker thead used by class twrWasmAsyncModule\nimport { twrCanvasProxy } from \"./twrcanvas.js\";\nimport { twrDivProxy } from \"./twrdiv.js\";\nimport { twrDebugLogProxy } from \"./twrdebug.js\";\nimport { twrWasmModuleBase } from \"./twrmodbase.js\";\nimport { twrWaitingCallsProxy } from \"./twrwaitingcalls.js\";\nlet mod;\nonmessage = function (e) {\n //console.log('twrworker.js: message received from main script: '+e.data);\n if (e.data[0] == 'startup') {\n const params = e.data[1];\n //console.log(\"Worker startup params:\",params);\n mod = new twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\n mod.loadWasm(params.urlToLoad).then(() => {\n postMessage([\"startupOkay\"]);\n }).catch((ex) => {\n console.log(\".catch: \", ex);\n postMessage([\"startupFail\", ex]);\n });\n }\n else if (e.data[0] == 'callC') {\n mod.callCImpl(e.data[1], e.data[2]).then((rc) => {\n postMessage([\"callCOkay\", rc]);\n }).catch(e => {\n console.log(\"exception in callC twrworker.js\\n\");\n console.log(e);\n postMessage([\"callCFail\", e]);\n });\n }\n else {\n console.log(\"twrworker.js: unknown message: \" + e);\n }\n};\n// ************************************************************************\nclass twrWasmModuleInWorker extends twrWasmModuleBase {\n malloc;\n modParams;\n constructor(modParams, modInWorkerParams) {\n super();\n this.isWorker = true;\n this.malloc = (size) => { throw new Error(\"error - un-init malloc called\"); };\n this.modParams = modParams;\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\n const canvasProxy = new twrCanvasProxy(modInWorkerParams.canvasProxyParams, this);\n const divProxy = new twrDivProxy(modInWorkerParams.divProxyParams);\n const waitingCallsProxy = new twrWaitingCallsProxy(modInWorkerParams.waitingCallsProxyParams);\n this.modParams.imports = {\n twrDebugLog: twrDebugLogProxy,\n twrSleep: waitingCallsProxy.sleep.bind(waitingCallsProxy),\n twrTime: waitingCallsProxy.time.bind(waitingCallsProxy),\n twrDivCharOut: divProxy.charOut.bind(divProxy),\n twrDivCharIn: divProxy.charIn.bind(divProxy),\n twrCanvasCharIn: canvasProxy.charIn.bind(canvasProxy),\n twrCanvasInkey: canvasProxy.inkey.bind(canvasProxy),\n twrCanvasGetProp: canvasProxy.getProp.bind(canvasProxy),\n twrCanvasDrawSeq: canvasProxy.drawSeq.bind(canvasProxy),\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function (x, y) { return x % y; },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n}\n//# sourceMappingURL=twrmodworker.js.map","// this script is the WebWorker thead used by class twrWasmAsyncModule\r\n\r\nimport {twrCanvasProxy} from \"./twrcanvas.js\";\r\nimport {twrDivProxy} from \"./twrdiv.js\";\r\nimport {twrDebugLogProxy} from \"./twrdebug.js\";\r\nimport {TAsyncModStartupMsg} from \"./twrmodasync.js\"\r\nimport {twrWasmModuleBase, IModInWorkerParams, IModParams} from \"./twrmodbase.js\"\r\nimport {twrWaitingCallsProxy} from \"./twrwaitingcalls.js\";\r\n\r\nlet mod:twrWasmModuleInWorker;\r\n\r\nonmessage = function(e) {\r\n //console.log('twrworker.js: message received from main script: '+e.data);\r\n\r\n if (e.data[0]=='startup') {\r\n const params:TAsyncModStartupMsg=e.data[1];\r\n //console.log(\"Worker startup params:\",params);\r\n mod=new twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\r\n\r\n mod.loadWasm(params.urlToLoad).then( ()=> {\r\n postMessage([\"startupOkay\"]);\r\n }).catch( (ex)=> {\r\n console.log(\".catch: \", ex);\r\n postMessage([\"startupFail\", ex]);\r\n });\r\n }\r\n else if (e.data[0]=='callC') {\r\n mod.callCImpl(e.data[1], e.data[2]).then( (rc)=> {\r\n postMessage([\"callCOkay\", rc]);\r\n }).catch(e => {\r\n console.log(\"exception in callC twrworker.js\\n\");\r\n console.log(e);\r\n postMessage([\"callCFail\", e]);\r\n });\r\n }\r\n else {\r\n console.log(\"twrworker.js: unknown message: \"+e);\r\n }\r\n}\r\n\r\n\r\n// ************************************************************************\r\n\r\nclass twrWasmModuleInWorker extends twrWasmModuleBase {\r\n\tmalloc:(size:number)=>Promise;\r\n modParams: IModParams;\r\n\r\n\r\n constructor(modParams:IModParams, modInWorkerParams:IModInWorkerParams) {\r\n super();\r\n this.isWorker=true;\r\n this.malloc=(size:number)=>{throw new Error(\"error - un-init malloc called\")};\r\n this.modParams=modParams;\r\n\r\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\r\n const canvasProxy = new twrCanvasProxy(modInWorkerParams.canvasProxyParams, this);\r\n const divProxy = new twrDivProxy(modInWorkerParams.divProxyParams);\r\n const waitingCallsProxy = new twrWaitingCallsProxy(modInWorkerParams.waitingCallsProxyParams);\r\n\r\n this.modParams.imports={\r\n twrDebugLog:twrDebugLogProxy,\r\n twrSleep:waitingCallsProxy.sleep.bind(waitingCallsProxy),\r\n twrTime:waitingCallsProxy.time.bind(waitingCallsProxy),\r\n\r\n twrDivCharOut:divProxy.charOut.bind(divProxy), \r\n twrDivCharIn:divProxy.charIn.bind(divProxy), \r\n\r\n twrCanvasCharIn:canvasProxy.charIn.bind(canvasProxy),\r\n twrCanvasInkey:canvasProxy.inkey.bind(canvasProxy),\r\n twrCanvasGetProp:canvasProxy.getProp.bind(canvasProxy),\r\n twrCanvasDrawSeq:canvasProxy.drawSeq.bind(canvasProxy),\r\n\r\n\t\t\ttwrSin:Math.sin,\r\n\t\t\ttwrCos:Math.cos,\r\n\t\t\ttwrTan: Math.tan,\r\n\t\t\ttwrFAbs: Math.abs,\r\n\t\t\ttwrACos: Math.acos,\r\n\t\t\ttwrASin: Math.asin,\r\n\t\t\ttwrATan: Math.atan,\r\n\t\t\ttwrExp: Math.exp,\r\n\t\t\ttwrFloor: Math.floor,\r\n\t\t\ttwrCeil: Math.ceil,\r\n\t\t\ttwrFMod: function(x:number, y:number) {return x%y},\r\n\t\t\ttwrLog: Math.log,\r\n\t\t\ttwrPow: Math.pow,\r\n\t\t\ttwrSqrt: Math.sqrt,\r\n\t\t\ttwrTrunc: Math.trunc,\r\n\r\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\r\n\t\t\ttwrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\r\n\t\t\ttwrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\r\n\t\t\ttwrAtod: this.floatUtil.atod.bind(this.floatUtil),\r\n\t\t\ttwrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\r\n \r\n }\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nimport { twrSignal } from \"./twrsignal.js\";\nvar D2DType;\n(function (D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})(D2DType || (D2DType = {}));\nexport class twrCanvas {\n ctx;\n props = { charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight: 0, canvasWidth: 0 };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase) {\n const { forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new twrSignal();\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext)\n throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c)\n throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2)\n throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\n }\n getProp(pn) {\n if (!this.isValid())\n console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */\n drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid())\n console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx)\n return;\n let ins = this.owner.getLong(ds); /* ds->start */\n const lastins = this.owner.getLong(ds + 4); /* ds->last */\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while (1) {\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */\n if (0 /*type!=D2DType.D2D_FILLRECT*/) {\n console.log(\"ins\", ins);\n console.log(\"hdr.next\", this.owner.mem8[ins], this.owner.mem8[ins + 1], this.owner.mem8[ins + 2], this.owner.mem8[ins + 3]);\n console.log(\"hdr.type\", this.owner.mem8[ins + 4], this.owner.mem8[ins + 5]);\n console.log(\"next 4 bytes\", this.owner.mem8[ins + 6], this.owner.mem8[ins + 7], this.owner.mem8[ins + 8], this.owner.mem8[ins + 9]);\n console.log(\"and 4 more \", this.owner.mem8[ins + 10], this.owner.mem8[ins + 11], this.owner.mem8[ins + 12], this.owner.mem8[ins + 13]);\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\n }\n switch (type) {\n case D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case D2DType.D2D_BEGINPATH:\n {\n this.ctx.beginPath();\n }\n break;\n case D2DType.D2D_FILL:\n {\n this.ctx.fill();\n }\n break;\n case D2DType.D2D_SAVE:\n {\n this.ctx.save();\n }\n break;\n case D2DType.D2D_RESTORE:\n {\n this.ctx.restore();\n }\n break;\n case D2DType.D2D_STROKE:\n {\n this.ctx.stroke();\n }\n break;\n case D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = (this.owner.getLong(ins + 48) != 0);\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n }\n else { // Uint8ClampedArray doesn't support shared memory\n this.precomputedObjects[id] = { mem8: new Uint8Array(this.owner.memory.buffer, start, length), width: width, height: height };\n }\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id])\n delete this.precomputedObjects[id];\n else\n console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) {\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n }\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) {\n this.ctx.putImageData(imgData, dx, dy);\n }\n else {\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */\n if (next == 0) {\n if (ins != lastins)\n throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal)\n this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nexport class twrCanvasProxy {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner) {\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new twrSignal(signalBuffer);\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\"drawseq\", [ds]]);\n this.drawCompleteSignal.wait();\n }\n}\n//# sourceMappingURL=twrcanvas.js.map","import {twrWasmModuleBase, IModParams} from \"./twrmodbase.js\"\r\nimport {twrSharedCircularBuffer} from \"./twrcircular.js\";\r\nimport {twrSignal} from \"./twrsignal.js\";\r\n\r\n\r\n// Canvas have a size that will be set based on the character width x height\r\n// The display size for a canvas will default to this size, but can be changed in the HTML/JS via\r\n// canvas.style.width = \"700px\";\r\n// canvas.style.height = \"500px\";\r\n\r\nexport interface ICanvasProps {\r\n\tcharWidth: number,\r\n\tcharHeight: number,\r\n\tforeColor: number,\r\n\tbackColor: number,\r\n widthInChars: number,\r\n heightInChars: number,\r\n canvasWidth:number,\r\n canvasHeight:number\r\n}\r\n\r\nenum D2DType {\r\n D2D_FILLRECT=1,\r\n D2D_FILLCHAR=5,\r\n D2D_SETLINEWIDTH=10,\r\n D2D_SETFILLSTYLERGBA=11,\r\n D2D_SETFONT=12,\r\n D2D_BEGINPATH=13,\r\n D2D_MOVETO=14,\r\n D2D_LINETO=15,\r\n D2D_FILL=16,\r\n D2D_STROKE=17,\r\n D2D_SETSTROKESTYLERGBA=18,\r\n D2D_ARC=19,\r\n D2D_STROKERECT=20,\r\n D2D_FILLTEXT=21,\r\n D2D_IMAGEDATA=22,\r\n D2D_PUTIMAGEDATA=23,\r\n D2D_BEZIERTO=24,\r\n D2D_MEASURETEXT=25,\r\n D2D_SAVE=26,\r\n D2D_RESTORE=27,\r\n D2D_CREATERADIALGRADIENT=28,\r\n D2D_SETCOLORSTOP=29,\r\n D2D_SETFILLSTYLEGRADIENT=30,\r\n D2D_RELEASEID=31,\r\n D2D_CREATELINEARGRADIENT=32,\r\n D2D_SETFILLSTYLE=33,\r\n D2D_SETSTROKESTYLE=34\r\n\r\n}\r\n\r\nexport type TCanvasProxyParams = [ICanvasProps, SharedArrayBuffer, SharedArrayBuffer];\r\n\r\nexport interface ICanvas {\r\n props: ICanvasProps,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TCanvasProxyParams,\r\n drawSeq: (ds:number)=>void,\r\n }\r\n \r\nexport class twrCanvas implements ICanvas {\r\n ctx:CanvasRenderingContext2D|undefined;\r\n props:ICanvasProps={charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight:0, canvasWidth:0};\r\n owner: twrWasmModuleBase;\r\n cmdCompleteSignal?:twrSignal;\r\n canvasKeys?: twrSharedCircularBuffer;\r\n precomputedObjects: { [index: number]: \r\n (ImageData | {mem8:Uint8Array, width:number, height:number}) |\r\n CanvasGradient\r\n };\r\n\r\n constructor(element:HTMLCanvasElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n const {forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas} = modParams; \r\n this.owner=modbase;\r\n this.props.widthInChars=modParams.windim[0];\r\n this.props.heightInChars=modParams.windim[1];\r\n\r\n if (!this.owner.isWasmModule) {\r\n this.cmdCompleteSignal=new twrSignal();\r\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n }\r\n\r\n this.precomputedObjects={};\r\n \r\n if (element) {\r\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\r\n let c=element.getContext(\"2d\");\r\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\r\n\r\n c.font = fontsize.toString()+\"px Courier New\";\r\n c.textBaseline=\"top\";\r\n const sampleText=\" \";\r\n const tm=c.measureText(sampleText);\r\n this.props.charWidth=Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\r\n let fM = c.measureText(\"X\"); \r\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\r\n\r\n if (!isd2dcanvas) {\r\n element.width=this.props.charWidth*this.props.widthInChars;\r\n element.height=this.props.charHeight*this.props.heightInChars;\r\n }\r\n\r\n this.props.canvasHeight=element.height;\r\n this.props.canvasWidth=element.width;\r\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\r\n\r\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\r\n let c2=element.getContext(\"2d\");\r\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\r\n this.ctx=c2;\r\n this.ctx.font = fontsize.toString()+\"px Courier New\";\r\n this.ctx.textBaseline=\"top\";\r\n\r\n c2.fillStyle=backcolor;\r\n this.props.backColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n c2.fillStyle=forecolor;\r\n this.props.foreColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n }\r\n\r\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\r\n\r\n //console.log(\"twrCanvas.constructor props: \", this.props);\r\n }\r\n\r\n isValid() {\r\n return !!this.ctx;\r\n }\r\n\r\n getProxyParams() : TCanvasProxyParams {\r\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\r\n }\r\n\r\n getProp(pn:number): number {\r\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n\r\n/* see draw2d.h for structs that match */\r\n\r\n drawSeq(ds:number) {\r\n //console.log(\"twr::Canvas enter drawSeq\");\r\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\r\n if (!this.ctx) return;\r\n\r\n let ins=this.owner.getLong(ds); /* ds->start */\r\n const lastins=this.owner.getLong(ds+4); /* ds->last */\r\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\r\n\r\n let next:number;\r\n //let insCount=0;\r\n\r\n while (1) {\r\n\r\n //insCount++;\r\n\r\n const type:D2DType=this.owner.getLong(ins+4); /* hdr->type */\r\n if (0/*type!=D2DType.D2D_FILLRECT*/) {\r\n console.log(\"ins\",ins)\r\n console.log(\"hdr.next\",this.owner.mem8[ins],this.owner.mem8[ins+1],this.owner.mem8[ins+2],this.owner.mem8[ins+3]);\r\n console.log(\"hdr.type\",this.owner.mem8[ins+4],this.owner.mem8[ins+5]);\r\n console.log(\"next 4 bytes\", this.owner.mem8[ins+6],this.owner.mem8[ins+7],this.owner.mem8[ins+8],this.owner.mem8[ins+9]);\r\n console.log(\"and 4 more \", this.owner.mem8[ins+10],this.owner.mem8[ins+11],this.owner.mem8[ins+12],this.owner.mem8[ins+13]);\r\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\r\n }\r\n switch (type) {\r\n case D2DType.D2D_FILLRECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.fillRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKERECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.strokeRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILLCHAR:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const c=this.owner.getShort(ins+24);\r\n let txt=String.fromCharCode(c);\r\n this.ctx.fillText(txt, x, y);\r\n }\r\n break;\r\n\r\n \r\n case D2DType.D2D_FILLTEXT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const str=this.owner.getString(this.owner.getLong(ins+24));\r\n\r\n //console.log(\"filltext \",x,y,str)\r\n \r\n this.ctx.fillText(str, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MEASURETEXT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n const tmidx=this.owner.getLong(ins+12);\r\n \r\n const tm=this.ctx.measureText(str);\r\n this.owner.setDouble(tmidx+0, tm.actualBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+8, tm.actualBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+16, tm.actualBoundingBoxLeft);\r\n this.owner.setDouble(tmidx+24, tm.actualBoundingBoxRight);\r\n this.owner.setDouble(tmidx+32, tm.fontBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+40, tm.fontBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+48, tm.width);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFONT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.font=str;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.fillStyle = cssColor;\r\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETSTROKESTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.fillStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETSTROKESTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETLINEWIDTH:\r\n {\r\n const width=this.owner.getShort(ins+8); \r\n this.ctx.lineWidth=width;\r\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MOVETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.moveTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_LINETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.lineTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEZIERTO:\r\n {\r\n const cp1x=this.owner.getDouble(ins+8);\r\n const cp1y=this.owner.getDouble(ins+16);\r\n const cp2x=this.owner.getDouble(ins+24);\r\n const cp2y=this.owner.getDouble(ins+32);\r\n const x=this.owner.getDouble(ins+40);\r\n const y=this.owner.getDouble(ins+48);\r\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEGINPATH:\r\n {\r\n this.ctx.beginPath();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILL:\r\n {\r\n this.ctx.fill();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SAVE:\r\n {\r\n this.ctx.save();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_RESTORE:\r\n {\r\n this.ctx.restore();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKE:\r\n {\r\n this.ctx.stroke();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_ARC:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const radius=this.owner.getDouble(ins+24);\r\n const startAngle=this.owner.getDouble(ins+32);\r\n const endAngle=this.owner.getDouble(ins+40);\r\n const counterClockwise= (this.owner.getLong(ins+48)!=0);\r\n\r\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_IMAGEDATA:\r\n {\r\n const start=this.owner.getLong(ins+8);\r\n const length=this.owner.getLong(ins+12);\r\n const width=this.owner.getLong(ins+16);\r\n const height=this.owner.getLong(ins+20);\r\n const id=this.owner.getLong(ins+24);\r\n\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\r\n\r\n if (this.owner.isWasmModule) {\r\n const z = new Uint8ClampedArray(this.owner.memory!.buffer, start, length);\r\n this.precomputedObjects[id]=new ImageData(z, width, height);\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory\r\n this.precomputedObjects[id]={mem8: new Uint8Array(this.owner.memory!.buffer, start, length), width:width, height:height};\r\n }\r\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_CREATERADIALGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const radius0=this.owner.getDouble(ins+24);\r\n const x1=this.owner.getDouble(ins+32);\r\n const y1=this.owner.getDouble(ins+40);\r\n const radius1=this.owner.getDouble(ins+48);\r\n const id= this.owner.getLong(ins+56);\r\n\r\n let gradient=this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_CREATELINEARGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const x1=this.owner.getDouble(ins+24);\r\n const y1=this.owner.getDouble(ins+32);\r\n const id= this.owner.getLong(ins+40);\r\n \r\n let gradient=this.ctx.createLinearGradient(x0, y0, x1, y1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETCOLORSTOP:\r\n {\r\n const id = this.owner.getLong(ins+8);\r\n const pos=this.owner.getLong(ins+12);\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+16));\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n gradient.addColorStop(pos, cssColor);\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n this.ctx.fillStyle=gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_RELEASEID:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (this.precomputedObjects[id])\r\n delete this.precomputedObjects[id];\r\n else\r\n console.log(\"warning: D2D_RELEASEID with undefined ID \",id);\r\n }\r\n break\r\n\r\n \r\n\r\n case D2DType.D2D_PUTIMAGEDATA:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n const dx=this.owner.getLong(ins+12);\r\n const dy=this.owner.getLong(ins+16);\r\n const dirtyX=this.owner.getLong(ins+20);\r\n const dirtyY=this.owner.getLong(ins+24);\r\n const dirtyWidth=this.owner.getLong(ins+28);\r\n const dirtyHeight=this.owner.getLong(ins+32);\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \"+id);\r\n\r\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\r\n\r\n let imgData:ImageData;\r\n if (this.owner.isWasmModule) {\r\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\r\n imgData=this.precomputedObjects[id] as ImageData;\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\r\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\r\n const z = this.precomputedObjects[id] as {mem8:Uint8Array, width:number, height:number}; // Uint8Array\r\n const ca=Uint8ClampedArray.from(z.mem8); // shallow copy\r\n imgData=new ImageData(ca, z.width, z.height);\r\n }\r\n \r\n if (dirtyWidth==0 && dirtyHeight==0) {\r\n this.ctx.putImageData(imgData, dx, dy);\r\n }\r\n else {\r\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\r\n }\r\n }\r\n break;\r\n\r\n default:\r\n throw new Error (\"unimplemented or unknown Sequence Type in drawSeq: \"+type);\r\n }\r\n next=this.owner.getLong(ins); /* hdr->next */\r\n if (next==0) {\r\n if (ins!=lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\r\n break;\r\n }\r\n ins=next;\r\n }\r\n\r\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\r\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\r\n }\r\n}\r\n\r\nexport class twrCanvasProxy implements ICanvas {\r\n canvasKeys: twrSharedCircularBuffer;\r\n drawCompleteSignal:twrSignal;\r\n props: ICanvasProps;\r\n owner: twrWasmModuleBase;\r\n\r\n constructor(params:TCanvasProxyParams, owner:twrWasmModuleBase) {\r\n const [props, signalBuffer, canvasKeysBuffer] = params;\r\n this.drawCompleteSignal = new twrSignal(signalBuffer);\r\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\r\n this.props=props;\r\n this.owner=owner;\r\n\r\n //console.log(\"Create New twrCanvasProxy: \",this.props)\r\n\r\n }\r\n\r\n charIn() { \r\n //ctx.commit(); not avail in chrome\r\n \r\n //postMessage([\"debug\", 'x']);\r\n \r\n return this.canvasKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.canvasKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n getProp(pn:number): number {\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n \r\n drawSeq(ds:number) {\r\n this.drawCompleteSignal.reset();\r\n postMessage([\"drawseq\", [ds]]);\r\n this.drawCompleteSignal.wait();\r\n }\r\n}\r\n","//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst RDIDX = 256;\nconst WRIDX = 257;\nconst LEN = 256;\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\n// the first 256 array entries are the circular buffer\n// the next two are used for the read and write index\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\nexport class twrSharedCircularBuffer {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(258 * 4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[RDIDX] = 0;\n this.buf[WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[WRIDX];\n this.buf[i] = n;\n i++;\n if (i == LEN)\n i = 0;\n this.buf[WRIDX] = i;\n Atomics.notify(this.buf, WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[RDIDX] = i;\n return n;\n }\n else\n return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[RDIDX] == this.buf[WRIDX];\n }\n}\n//# sourceMappingURL=twrcircular.js.map","//\r\n// This class implements a circular buffer that the main javascript thread can write to, \r\n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\r\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \r\n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\r\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\r\n//\r\n\r\nconst RDIDX=256;\r\nconst WRIDX=257;\r\nconst LEN=256;\r\n\r\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\r\n// the first 256 array entries are the circular buffer\r\n// the next two are used for the read and write index\r\n\r\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\r\n\r\nexport class twrSharedCircularBuffer {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n \r\n\tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(258*4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[RDIDX]=0;\r\n this.buf[WRIDX]=0;\r\n\t}\r\n\r\n\twrite(n:number) {\r\n let i=this.buf[WRIDX];\r\n this.buf[i]=n;\r\n i++;\r\n if (i==LEN) i=0;\r\n this.buf[WRIDX]=i; \r\n Atomics.notify(this.buf, WRIDX); \r\n\t}\r\n\r\n\tread():number {\r\n if (!this.isEmpty()) {\r\n let i=this.buf[RDIDX];\r\n let n=this.buf[i];\r\n i++;\r\n this.buf[RDIDX]=i;\r\n return n;\r\n }\r\n\t\telse\r\n return -1;\r\n\t}\r\n\r\n readWait():number {\r\n if (this.isEmpty()) {\r\n const rdptr=this.buf[RDIDX];\r\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\r\n Atomics.wait(this.buf, WRIDX, rdptr);\r\n }\r\n return this.read();\r\n\t}\r\n\r\n isEmpty():boolean {\r\n return this.buf[RDIDX]==this.buf[WRIDX];\r\n }\r\n}\r\n","//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar twrSignalState;\n(function (twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})(twrSignalState || (twrSignalState = {}));\n;\nexport class twrSignal {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window valid\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == twrSignalState.WAITING) {\n //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\n //console.log(\"released...\");\n }\n }\n isSignaled() {\n return this.buf[0] == twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = twrSignalState.WAITING;\n }\n}\n//# sourceMappingURL=twrsignal.js.map","//\r\n// This class implements a simple signal/wait mechanism\r\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\r\n//\r\n\r\nenum twrSignalState {\r\n WAITING=0,\r\n SIGNALED=1\r\n};\r\n\r\nexport class twrSignal {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n\r\n \tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window valid\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) \r\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[0]=twrSignalState.WAITING;\r\n\t}\r\n\r\n\tsignal() {\r\n this.buf[0]=twrSignalState.SIGNALED; \r\n //console.log(\"about to signal\");\r\n Atomics.notify(this.buf, 0); \r\n\t}\r\n\r\n wait() {\r\n if (this.buf[0]==twrSignalState.WAITING) {\r\n //console.log(\"waiting...\");\r\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\r\n //console.log(\"released...\");\r\n\r\n }\r\n\t}\r\n isSignaled():boolean {\r\n return this.buf[0]==twrSignalState.SIGNALED;\r\n }\r\n\r\n reset() {\r\n this.buf[0]=twrSignalState.WAITING;\r\n }\r\n}\r\n","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nexport class twrDiv {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase) {\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\n this.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n if (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.divKeys.sharedArray];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */\n charOut(ch) {\n if (!this.div)\n return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n }\n switch (ch) {\n case 10: // newline\n case 13: // return\n if (ch == 10 && this.lastChar == 13)\n break; // detect CR LF and treat as single new line\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8: // backspace\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n case 0xE: // cursor on\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF: // cursor off\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for (let i = 0; i < str.length; i++)\n this.charOut(str.charCodeAt(i));\n }\n}\nexport class twrDivProxy {\n divKeys;\n constructor(params) {\n const [divKeysBuffer] = params;\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n charOut(ch) {\n postMessage([\"divout\", ch]);\n }\n}\n//# sourceMappingURL=twrdiv.js.map","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\r\nimport { IModParams } from \"./twrmodbase.js\";\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\";\r\n\r\nexport type TDivProxyParams = [SharedArrayBuffer];\r\n\r\nexport interface IDiv {\r\n charOut: (ds:number)=>void,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TDivProxyParams,\r\n }\r\n\r\n\r\nexport class twrDiv implements IDiv {\r\n\tdiv:HTMLDivElement|null|undefined;\r\n\tdivKeys?:twrSharedCircularBuffer;\r\n\tCURSOR=String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\r\n\tcursorOn:boolean=false;\r\n\tlastChar:number=0;\r\n\textraBR:boolean=false;\r\n\towner:twrWasmModuleBase;\r\n\r\n constructor(element:HTMLDivElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n\t\tthis.div=element;\r\n\t\tthis.owner=modbase;\r\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\r\n\t\t\tthis.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n\t\t}\r\n\r\n\t\tif (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\r\n\t\t\tthis.div.style.backgroundColor = modParams.backcolor;\r\n\t\t\tthis.div.style.color = modParams.forecolor;\r\n\t\t\tthis.div.style.font=modParams.fontsize.toString()+\"px arial\"\r\n\t\t}\r\n }\r\n\r\n\tisValid() {\r\n\t\treturn !!this.div;\r\n\t}\r\n\r\n getProxyParams() : TDivProxyParams {\r\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [ this.divKeys.sharedArray];\r\n }\r\n\r\n\r\n/* \r\n * add character to div. Supports the following control codes:\r\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\r\n * 0xE cursor on \r\n * 0x8 backspace\r\n * 0xF cursor off \r\n*/\r\n\tcharOut(ch:number) {\r\n\r\n\t\tif (!this.div) return;\r\n\r\n\t\t//console.log(\"div::charout: \", ch);\r\n\r\n\t\tif (this.extraBR) {\r\n\t\t\tthis.extraBR=false;\r\n\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -4);\r\n\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t}\r\n\r\n\t\tswitch (ch) {\r\n\t\t\tcase 10: // newline\r\n\t\t\tcase 13: // return\r\n\t\t\t\tif (ch==10 && this.lastChar==13) break; // detect CR LF and treat as single new line\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\r\n\t\t\t\tthis.extraBR=true;\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\t//element.scrollIntoView();\r\n\t\t\t\t//element.scrollTop = element.scrollHeight;\r\n\t\t\t\tlet p = this.div.getBoundingClientRect();\r\n\t\t\t\twindow.scrollTo(0, p.height+100);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 8: // backspace\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xE: // cursor on\r\n\t\t\t\tif (!this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=true;\r\n\t\t\t\t\tthis.div.innerHTML += this.CURSOR;\r\n\t\t\t\t\tthis.div.focus();\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xF: // cursor off\r\n\t\t\t\tif (this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=false;\r\n\t\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += String.fromCharCode(ch);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\tthis.lastChar=ch;\r\n\t}\r\n\r\n\tstringOut(str:string) {\r\n\t\tfor (let i=0; i < str.length; i++)\r\n\t\t\tthis.charOut(str.charCodeAt(i));\r\n\t}\r\n}\r\n\r\n\r\nexport class twrDivProxy implements IDiv {\r\n divKeys: twrSharedCircularBuffer;\r\n\r\n constructor(params:TDivProxyParams) {\r\n const [divKeysBuffer] = params;\r\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\r\n }\r\n\r\n charIn() { \r\n return this.divKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.divKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n\tcharOut(ch:number) {\r\n\t\tpostMessage([\"divout\", ch]);\r\n\t}\r\n}\r\n\r\n","let logline = \"\";\nexport function twrDebugLogImpl(char) {\n if (char == 10 || char == 3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\n console.log(logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n logline = \"\";\n }\n else {\n logline = logline + String.fromCharCode(char);\n if (logline.length >= 200) {\n console.log(logline);\n logline = \"\";\n }\n }\n}\n// ************************************************************************\n// debugLog doesn't currently wait for the message to log, it returns immediately.\n// I could move this to be in the twrWaitingCalls class\nexport function twrDebugLogProxy(ch) {\n postMessage([\"debug\", ch]);\n}\n//# sourceMappingURL=twrdebug.js.map","\r\nlet logline=\"\";\r\nexport function twrDebugLogImpl(char:number) {\r\n\tif (char==10 || char==3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\r\n\t\tconsole.log(logline);\t// ideally without a linefeed, but there is no way to not have a LF with console.log API.\r\n\t\tlogline=\"\";\r\n\t}\r\n\telse {\r\n\t\tlogline=logline+String.fromCharCode(char);\r\n\t\tif (logline.length>=200) {\r\n\t\t\tconsole.log(logline);\r\n\t\t\tlogline=\"\";\r\n\t\t}\r\n\t}\r\n}\r\n\r\n// ************************************************************************\r\n// debugLog doesn't currently wait for the message to log, it returns immediately.\r\n// I could move this to be in the twrWaitingCalls class\r\nexport function twrDebugLogProxy(ch:number) {\r\n postMessage([\"debug\", ch]);\r\n}\r\n\r\n","import { twrFloatUtil } from \"./twrfloat.js\";\n/*********************************************************************/\n/*********************************************************************/\n/*********************************************************************/\nexport class twrWasmModuleBase {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\n floatUtil;\n constructor(isWasmModule = false) {\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new twrFloatUtil(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/\n /*********************************************************************/\n async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n }\n catch (err) {\n console.log('loadWasm() failed to fetch: ' + pathToLoad);\n throw err;\n }\n if (!response.ok)\n throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, { env: allimports });\n this.exports = instance.instance.exports;\n if (!this.exports)\n throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory)\n throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory)\n throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer)\n console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\"setmemory\", this.memory]);\n }\n if (this.isWasmModule) {\n // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (!(this.memory.buffer instanceof ArrayBuffer))\n console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size) => {\n return new Promise(resolve => {\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n }\n catch (err) {\n console.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch (this.modParams.stdio) {\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* callC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */\n async callC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.callCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async callCImpl(fname, cparams = []) {\n if (!this.exports)\n throw new Error(\"this.exports undefined\");\n if (!this.exports[fname])\n throw new Error(\"callC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array))\n throw new Error(\"callC: params must be array, first arg is function name\");\n if (params.length == 0)\n throw new Error(\"callC: missing function name\");\n let cparams = [];\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n cparams[ci++] = p;\n break;\n case 'string':\n cparams[ci++] = await this.putString(p);\n break;\n case 'object':\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n }\n else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"callC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n ci++;\n break;\n case 'string':\n this.callCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n case 'object':\n if (p instanceof URL) {\n this.callCImpl('twr_free', [cparams[ci]]);\n ci = ci + 2;\n break;\n }\n else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for (let j = 0; j < u8.length; j++)\n u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.callCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n }\n else\n throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/\n /*********************************************************************/\n // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for (i = 0; i < sin.length && i < buffer_size - 1; i++)\n this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for (let i = 0; i < u8a.length; i++)\n this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === 'object' && fnin instanceof URL))\n throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [dest, src.length];\n }\n catch (err) {\n console.log('fetchAndPutURL Error. URL: ' + fnin + '\\n' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while (this.mem8[strIndex + i] && (len === undefined ? true : i < len) && (strIndex + i) < this.mem8.length) {\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0)\n throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array((this.mem8.slice(dataptr, dataptr + size)).buffer);\n return u32;\n }\n}\n//# sourceMappingURL=twrmodbase.js.map","\r\nimport {TCanvasProxyParams} from \"./twrcanvas.js\"\r\nimport {TDivProxyParams} from \"./twrdiv.js\";\r\nimport {TWaitingCallsProxyParams} from \"./twrwaitingcalls.js\"\r\nimport {twrDebugLogImpl} from \"./twrdebug.js\";\r\nimport {twrFloatUtil} from \"./twrfloat.js\";\r\n\r\n\r\nexport type TStdioVals=\"div\"|\"canvas\"|\"null\"|\"debug\";\r\n\r\nexport interface IModOpts {\r\n\tstdio?:TStdioVals, \r\n\twindim?:[number, number],\r\n\tforecolor?:string,\r\n\tbackcolor?:string,\r\n\tfontsize?:number,\r\n\tisd2dcanvas?:boolean,\r\n\timports?:{},\r\n}\r\n\r\nexport interface IModParams {\r\n\tstdio:TStdioVals, \r\n\twindim:[number, number],\r\n\tforecolor:string,\r\n\tbackcolor:string,\r\n\tfontsize:number,\r\n\tstyleIsDefault: boolean\r\n\tisd2dcanvas:boolean,\r\n\timports:{[index:string]:Function},\r\n}\r\n\r\nexport interface IModInWorkerParams {\r\n\tdivProxyParams:TDivProxyParams,\r\n\tcanvasProxyParams:TCanvasProxyParams,\r\n\twaitingCallsProxyParams:TWaitingCallsProxyParams,\r\n}\r\n\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n\r\nexport abstract class twrWasmModuleBase {\r\n\tmemory?:WebAssembly.Memory;\r\n\tmem8:Uint8Array;\r\n\tmem32:Uint32Array;\r\n\tmemD:Float64Array;\r\n\tabstract malloc:(size:number)=>Promise;\r\n\tabstract modParams:IModParams;\r\n\texports?:WebAssembly.Exports;\r\n\tisWorker=false;\r\n\tisWasmModule:boolean; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\r\n\tfloatUtil:twrFloatUtil;\r\n\r\n\tconstructor(isWasmModule=false) {\r\n\t\tthis.isWasmModule=isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\r\n\t\tthis.mem8=new Uint8Array(); \t// avoid type errors\r\n\t\tthis.mem32=new Uint32Array(); // avoid type errors\r\n\t\tthis.memD=new Float64Array(); // avoid type errors\r\n\t\tthis.floatUtil=new twrFloatUtil(this);\r\n\t\t//console.log(\"size of mem8 after constructor\",this.mem8.length);\r\n\t}\r\n\r\n\t/*********************************************************************/\r\n\t/*********************************************************************/\r\n\r\n\tasync loadWasm(pathToLoad:string) {\r\n\t\t//console.log(\"fileToLoad\",fileToLoad)\r\n\r\n\t\tlet response;\r\n\t\ttry {\r\n\t\t\tresponse=await fetch(pathToLoad);\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('loadWasm() failed to fetch: '+pathToLoad);\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t\t\r\n\t\tif (!response.ok) throw new Error(\"fetch response error on file '\"+pathToLoad+\"'\\n\"+response.statusText);\r\n\r\n\t\ttry {\r\n\t\t\tlet wasmBytes = await response.arrayBuffer();\r\n\r\n\t\t\tlet allimports:WebAssembly.ModuleImports = { \r\n\t\t\t\t...this.modParams.imports\r\n\t\t\t};\r\n\r\n\t\t\tlet instance = await WebAssembly.instantiate(wasmBytes, {env: allimports});\r\n\r\n\t\t\tthis.exports=instance.instance.exports;\r\n\t\t\tif (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\r\n\r\n\t\t\tif (this.memory) throw new Error (\"unexpected error -- this.memory already set\");\r\n\t\t\tthis.memory=this.exports.memory as WebAssembly.Memory;\r\n\t\t\tif (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\r\n\t\t\tthis.mem8 = new Uint8Array(this.memory.buffer);\r\n\t\t\tthis.mem32 = new Uint32Array(this.memory.buffer);\r\n\t\t\tthis.memD = new Float64Array(this.memory.buffer);\r\n\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\tif (this.isWorker) {\r\n\t\t\t\tif (this.memory.buffer instanceof ArrayBuffer)\r\n\t\t\t\t\tconsole.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\r\n\t\t\t\t\r\n\t\t\t\tpostMessage([\"setmemory\",this.memory]);\r\n\t\t\t}\r\n\t\t\tif (this.isWasmModule) {\r\n\t\t\t\t// here if twrWasmModule, twrWasmModuleAsync overrides this function\r\n\t\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\t\tif (!(this.memory.buffer instanceof ArrayBuffer))\r\n\t\t\t\t\tconsole.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\r\n\t\t\t}\r\n\r\n\t\t\tthis.malloc=(size:number)=>{\r\n\t\t\t\treturn new Promise(resolve => {\r\n\t\t\t\t\tconst m=this.exports!.twr_malloc as (size:number)=>number;\r\n\t\t\t\t\tresolve(m(size));\r\n\t\t\t\t});\r\n\t\t };\r\n\r\n\t\t\tthis.init();\r\n\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t}\r\n\r\n\tprivate init() {\r\n\t\t//console.log(\"loadWasm.init() enter\")\r\n\t\t\tlet p:number;\r\n\t\t\tswitch (this.modParams.stdio) {\r\n\t\t\t\tcase \"debug\":\r\n\t\t\t\t\tp=0;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"div\":\r\n\t\t\t\t\tp=1;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"canvas\":\r\n\t\t\t\t\tp=2;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"null\":\r\n\t\t\t\t\tp=3;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tp=0; // debug\r\n\t\t\t}\r\n\r\n\t\t\tconst twrInit=this.exports!.twr_wasm_init as CallableFunction;\r\n\t\t\t//console.log(\"twrInit:\",twrInit)\r\n\t\t\ttwrInit(p, this.mem8.length);\r\n\t}\r\n\r\n\t/* callC takes an array where:\r\n\t* the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\r\n\t* and the next entries are a variable number of parameters to pass to the C function, of type\r\n\t* number - converted to int32 or float64 as appropriate\r\n\t* string - converted to a an index (ptr) into a module Memory returned via stringToMem()\r\n\t* URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\r\n\t* Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\r\n */\r\n\r\n\tasync callC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\t\tconst cparams=await this.preCallC(params);\r\n\t\tlet retval = this.callCImpl(params[0], cparams);\r\n\t\tthis.postCallC(cparams, params);\r\n\t\treturn retval;\r\n\t}\r\n\r\n\tasync callCImpl(fname:string, cparams:number[]=[]) {\r\n\t\tif (!this.exports) throw new Error(\"this.exports undefined\");\r\n\t\tif (!this.exports[fname]) throw new Error(\"callC: function '\"+fname+\"' not in export table. Use --export wasm-ld flag.\");\r\n\r\n\t\tconst f = this.exports[fname] as CallableFunction;\r\n\t\tlet cr=f(...cparams);\r\n\r\n\t\treturn cr;\r\n\t}\r\n\r\n\t// convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\r\n\tasync preCallC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tif (!(params.constructor === Array)) throw new Error (\"callC: params must be array, first arg is function name\");\r\n\t\tif (params.length==0) throw new Error(\"callC: missing function name\");\r\n\r\n\t\tlet cparams:number[]=[];\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tcparams[ci++]=p;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tcparams[ci++]=await this.putString(p);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tconst r=await this.fetchAndPutURL(p);\r\n\t\t\t\t\t\tcparams[ci++]=r[0]; // mem index\r\n\t\t\t\t\t\tcparams[ci++]=r[1]; // len\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tconst r=await this.putArrayBuffer(p);\r\n\t\t\t\t\t\tcparams[ci++]=r; // mem index\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tthrow new Error (\"callC: invalid object type passed in\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn cparams;\r\n\t}\r\n\r\n\t// free the mallocs; copy array buffer data from malloc back to arraybuffer\r\n\tasync postCallC(cparams:number[], params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tthis.callCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t\t\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tthis.callCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\t\tci=ci+2;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tlet u8=new Uint8Array(p);\r\n\t\t\t\t\t\tfor (let j=0; j= this.mem32.length) throw new Error(\"invalid index passed to getLong: \"+idx+\", this.mem32.length: \"+this.mem32.length);\r\n\t\tconst long:number = this.mem32[idx32];\r\n\t\treturn long;\r\n\t}\r\n\t\r\n\tsetLong(idx:number, value:number) {\r\n const idx32 = Math.floor(idx / 4);\r\n if (idx32 * 4 != idx)\r\n throw new Error(\"setLong passed non long aligned address\");\r\n if (idx32 < 0 || idx32 >= this.mem32.length)\r\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\r\n this.mem32[idx32]=value;\r\n }\r\n\r\n\tgetDouble(idx:number): number {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"getLong passed non Float64 aligned address\")\r\n\t\tconst long:number = this.memD[idx64];\r\n\t\treturn long;\r\n\t}\r\n\r\n\tsetDouble(idx:number, value:number) {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"setDouble passed non Float64 aligned address\")\r\n\t\tthis.memD[idx64]=value;\r\n\t}\r\n\r\n\tgetShort(idx:number): number {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getShort: \"+idx);\r\n\t\tconst short:number = this.mem8[idx]+this.mem8[idx+1]*256;\r\n\t\treturn short;\r\n\t}\r\n\r\n\t// get a string out of module memory\r\n\t// null terminated, up until max of (optional) len\r\n\tgetString(strIndex:number, len?:number): string {\r\n\t\tlet sout=\"\";\r\n\r\n\t\tlet i=0;\r\n\t\twhile (this.mem8[strIndex+i] && (len===undefined?true:i= this.mem8.length) throw new Error(\"invalid index passed to getU8: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU8\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU8\")\r\n\r\n\t\tconst u8=this.mem8.slice(dataptr, dataptr+size);\r\n\t\treturn u8;\r\n\t}\r\n\r\n\t// get a int32 array out of module memory when passed in index to [size, dataptr]\r\n\tgetU32Arr(idx:number): Uint32Array {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getU32: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU32\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU32\")\r\n\r\n\t\tif (size%4!=0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\r\n\r\n\t\tconst u32 = new Uint32Array( (this.mem8.slice(dataptr, dataptr+size)).buffer );\r\n\t\treturn u32;\r\n\t}\r\n}\r\n","export class twrFloatUtil {\n mod;\n constructor(mod) {\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\")\n return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\")\n return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll('D', 'e').replaceAll('d', 'e'));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n }\n else {\n let r = value.toString();\n if (r.length > max_precision)\n r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, // char *\n sizeInBytes, //size_t\n value, // double\n fracpart_numdigits, //int\n dec, // int *\n sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1)\n return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) { /* nan */\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (!Number.isFinite(value)) { /* infinity */\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n }\n else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split('.');\n if (intPart == \"0\")\n intPart = \"\";\n if (intPart.length > 0) { // has integer part\n decpos = intPart.length;\n digits = intPart + fracPart;\n }\n else { // only a fraction\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length)\n return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */\n }\n}\n//# sourceMappingURL=twrfloat.js.map","\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\"\r\n\r\nexport class twrFloatUtil {\r\n mod: twrWasmModuleBase;\r\n\r\n constructor(mod: twrWasmModuleBase) {\r\n this.mod=mod;\r\n }\r\n\r\n atod(strptr:number):number {\r\n const str=this.mod.getString(strptr);\r\n\r\n const upper=str.trimStart().toUpperCase();\r\n if (upper==\"INF\" || upper==\"+INF\")\r\n return Number.POSITIVE_INFINITY;\r\n else if (upper==\"-INF\")\r\n return Number.NEGATIVE_INFINITY\r\n else {\r\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\r\n const r=Number.parseFloat(str.replaceAll('D','e').replaceAll('d','e'));\r\n return r;\r\n }\r\n }\r\n\r\n dtoa(buffer:number, buffer_size:number, value:number, max_precision:number):void {\r\n if (max_precision==-1) {\r\n const r=value.toString();\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n else {\r\n let r=value.toString();\r\n if (r.length>max_precision)\r\n r=value.toPrecision(max_precision);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n }\r\n\r\n toFixed(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toFixed(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n toExponential(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toExponential(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\r\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\r\n // Negative exponents must be now smaller than 1e-99\r\n // fully-function C version also int he source, but this is the version enabled by default\r\n fcvtS(\r\n buffer:number, // char *\r\n sizeInBytes:number, //size_t\r\n value:number, // double\r\n fracpart_numdigits:number, //int\r\n dec:number, // int *\r\n sign:number // int *\r\n ):number {\r\n\r\n if (buffer==0 ||sign==0 || dec==0 || sizeInBytes<1) return 1;\r\n\r\n let digits:string;\r\n let decpos:number;\r\n let s=0; // default to positive\r\n\r\n\r\n if (Number.isNaN(value)) { /* nan */\r\n digits=\"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (!Number.isFinite(value)) { /* infinity */\r\n digits=\"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (value==0) { \r\n digits=\"000000000000000000000000000000000000\".slice(0,fracpart_numdigits);\r\n decpos=0;\r\n }\r\n \r\n else {\r\n\r\n if (value<0) {\r\n s=1; // negative\r\n value=Math.abs(value);\r\n }\r\n\r\n if (fracpart_numdigits>100 || value > 1e+21 || value < 1e-99) { \r\n this.mod.copyString(buffer, sizeInBytes, \"\");\r\n this.mod.mem32[dec]=0;\r\n return 1;\r\n }\r\n\r\n const roundValStr=value.toFixed(fracpart_numdigits);\r\n let [intPart=\"\", fracPart=\"\"] = roundValStr.split('.');\r\n if (intPart==\"0\") intPart=\"\";\r\n\r\n if (intPart.length>0) { // has integer part\r\n decpos=intPart.length;\r\n digits=intPart+fracPart;\r\n }\r\n else { // only a fraction\r\n digits=fracPart.replace(/^0+/,\"\"); // remove leading zeros\r\n decpos=digits.length-fracPart.length;\r\n }\r\n }\r\n\r\n if (sizeInBytes-1 < digits.length) return 1; \r\n this.mod.copyString(buffer, sizeInBytes, digits);\r\n this.mod.setLong(dec, decpos);\r\n this.mod.setLong(sign, s);\r\n\r\n return 0;\r\n\r\n /*\r\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\r\n\r\n let decpos=0;\r\n let digits:string;\r\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\r\n \r\n if (decpos>0) { // has integer part\r\n const intlen=Math.max(decpos, 0);\r\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\r\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\r\n }\r\n else { // only a fraction\r\n const intpart=Math.trunc(value);\r\n const fracpart=value-intpart;\r\n const prec=fracpart_numdigits- (-decpos);\r\n console.log(\"prec=\",prec);\r\n if (prec<1) {\r\n digits=\"\";\r\n }\r\n else {\r\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\");\r\n }\r\n }\r\n\r\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\r\n console.log('digits=',digits);\r\n console.log('dec=',decpos);\r\n console.log(\"sign=\",s);\r\n */\r\n\r\n\r\n }\r\n}","import { twrSignal } from \"./twrsignal.js\";\nimport { twrTimeImpl } from \"./twrdate.js\";\n// This class is used in the Main JS thread \nexport class twrWaitingCalls {\n callCompleteSignal;\n parameters;\n constructor() {\n this.callCompleteSignal = new twrSignal();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(() => {\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = twrTimeImpl();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [this.callCompleteSignal.sharedArray, this.parameters.buffer];\n }\n processMessage(msgType, data) {\n switch (msgType) {\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\n// This class is used in the worker thread \nexport class twrWaitingCallsProxy {\n callCompleteSignal;\n parameters;\n constructor(params) {\n this.callCompleteSignal = new twrSignal(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\"sleep\", [ms]]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\"time\"]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n//# sourceMappingURL=twrwaitingcalls.js.map","import { twrSignal } from \"./twrsignal.js\";\r\nimport {twrTimeImpl} from \"./twrdate.js\"\r\n\r\n// These classes are used to proxy a call across the worker thread - main thread boundary and wait for the result\r\n\r\nexport type TWaitingCallsProxyParams = [SharedArrayBuffer, SharedArrayBuffer]; // twrSignal, parameters \r\n\r\n// This class is used in the Main JS thread \r\nexport class twrWaitingCalls {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor() {\r\n\t\tthis.callCompleteSignal=new twrSignal();\r\n\t\tthis.parameters=new Uint32Array(new SharedArrayBuffer(4));\r\n\t}\r\n\r\n\tprivate startSleep(ms:number) {\r\n\r\n\t\tsetTimeout(()=>{\r\n\t\t\tthis.callCompleteSignal.signal();\r\n\t\t}, ms);\r\n\t\t\r\n\t}\r\n\r\n\tprivate time() {\r\n\t\tconst ms=twrTimeImpl();\r\n\t\tthis.parameters[0]=ms;\r\n\t\tthis.callCompleteSignal.signal();\r\n\t}\r\n\r\n\tgetProxyParams():TWaitingCallsProxyParams {\r\n\t\treturn [this.callCompleteSignal.sharedArray, this.parameters.buffer as SharedArrayBuffer];\t\r\n\t}\r\n\r\n\tprocessMessage(msgType:string, data:any[]):boolean {\r\n\t\tswitch (msgType) {\r\n\t\t\tcase \"sleep\":\r\n\t\t\t\tconst [ms] = data;\r\n\t\t\t\tthis.startSleep(ms);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"time\":\r\n\t\t\t\tthis.time();\r\n\t\t\t\tbreak;\r\n\t\t\t\r\n\t\t\tdefault:\r\n\t\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\treturn true;\r\n\t}\r\n\r\n}\r\n\r\n// This class is used in the worker thread \r\nexport class twrWaitingCallsProxy {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor(params:TWaitingCallsProxyParams) {\r\n\t\tthis.callCompleteSignal=new twrSignal(params[0]);\r\n\t\tthis.parameters=new Uint32Array(params[1]);\r\n\t}\r\n\r\n\tsleep(ms:number) {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"sleep\", [ms]]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t}\r\n\r\n\ttime() {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"time\"]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t\treturn this.parameters[0];\r\n\t}\r\n\r\n}\r\n","export function twrTimeImpl() {\n return Date.now();\n}\n//# sourceMappingURL=twrdate.js.map","\r\nexport function twrTimeImpl() {\r\n\r\n return Date.now();\r\n\r\n}"],"names":["$b93f1fdf40141def$var$twrSignalState","$c4741cac81d14197$var$D2DType","twrSignalState","D2DType","$3e39efa823870787$var$mod","$892fccfc812d5e20$export$a01cca24f011573a","sharedArray","buf","constructor","sa","window","crossOriginIsolated","location","protocol","Error","SharedArrayBuffer","Int32Array","write","n","i","Atomics","notify","read","isEmpty","readWait","rdptr","wait","$b93f1fdf40141def$export$e37a7b7b851b97f3","WAITING","signal","SIGNALED","isSignaled","reset","$c4741cac81d14197$export$c779b2cd00544976","canvasKeys","drawCompleteSignal","props","owner","params","signalBuffer","canvasKeysBuffer","charIn","inkey","getProp","pn","propName","getString","drawSeq","ds","postMessage","$8963973702ae5462$export$b377f0bbf2c7581e","divKeys","divKeysBuffer","charOut","ch","$8ac0b786da854328$export$485af4d0039b3389","$e72303a1db04bdfa$export$918ffb7e046a537b","mod","atod","strptr","str","upper","trimStart","toUpperCase","Number","POSITIVE_INFINITY","NEGATIVE_INFINITY","parseFloat","replaceAll","dtoa","buffer","buffer_size","value","max_precision","r","toString","copyString","length","toPrecision","toFixed","decdigits","toExponential","fcvtS","sizeInBytes","fracpart_numdigits","dec","sign","digits","decpos","s","isNaN","slice","isFinite","Math","abs","mem32","intPart","fracPart","roundValStr","split","replace","setLong","$ece7fa3ed770778a$export$c83a0a3bffe07399","memory","mem8","memD","exports","isWorker","isWasmModule","floatUtil","Uint8Array","Uint32Array","Float64Array","loadWasm","pathToLoad","response","fetch","err","console","log","ok","statusText","wasmBytes","arrayBuffer","allimports","modParams","imports","instance","WebAssembly","instantiate","env","ArrayBuffer","malloc","size","Promise","resolve","m","twr_malloc","init","stack","p","stdio","twrInit","twr_wasm_init","callC","cparams","preCallC","retval","callCImpl","postCallC","fname","f","Array","ci","putString","URL","fetchAndPutURL","putArrayBuffer","u8","j","sin","charCodeAt","strIndex","putU8","u8a","dest","ab","fnin","src","getLong","idx","idx32","floor","getDouble","idx64","setDouble","getShort","len","sout","undefined","String","fromCharCode","getU8Arr","rv","dataptr","getU32Arr","$aff9c2c494d23fe3$export$78d2a4633fe89379","callCompleteSignal","parameters","sleep","ms","time","onmessage","e","data","$3e39efa823870787$var$twrWasmModuleInWorker","modWorkerParams","urlToLoad","then","catch","ex","rc","modInWorkerParams","canvasProxy","canvasProxyParams","divProxy","divProxyParams","waitingCallsProxy","waitingCallsProxyParams","twrDebugLog","twrSleep","bind","twrTime","twrDivCharOut","twrDivCharIn","twrCanvasCharIn","twrCanvasInkey","twrCanvasGetProp","twrCanvasDrawSeq","twrSin","twrCos","cos","twrTan","tan","twrFAbs","twrACos","acos","twrASin","asin","twrATan","atan","twrExp","exp","twrFloor","twrCeil","ceil","twrFMod","x","y","twrLog","twrPow","pow","twrSqrt","sqrt","twrTrunc","trunc","twrDtoa","twrToFixed","twrToExponential","twrAtod","twrFcvtS"],"version":3,"file":"twrmodworker.2165e649.js.map"} \ No newline at end of file diff --git a/azure/examples/balls/index.html b/azure/examples/balls/index.html index 35808995..2ea7b973 100644 --- a/azure/examples/balls/index.html +++ b/azure/examples/balls/index.html @@ -64,7 +64,7 @@

tiny-wasm-runtime

const mod=new twrWasmModule(); await mod.loadWasm('balls.wasm'); - await mod.executeC(["bounce_balls_init", ballSpeed]); + await mod.callC(["bounce_balls_init", ballSpeed]); let lastTime; @@ -75,7 +75,7 @@

tiny-wasm-runtime

else intervalTimeMs=timeStamp-lastTime; lastTime=timeStamp; - mod.executeC(["bounce_balls_move", intervalTimeMs]).then(()=>{ + mod.callC(["bounce_balls_move", intervalTimeMs]).then(()=>{ window.requestAnimationFrame(moveBalls); }); } diff --git a/azure/examples/fft/dist/index.html b/azure/examples/fft/dist/index.html index 3932b37f..340ae2a3 100644 --- a/azure/examples/fft/dist/index.html +++ b/azure/examples/fft/dist/index.html @@ -5,4 +5,4 @@ "whatkey": "../../lib-js/whatkey.js" } } -
Input Signal



FFT Output
\ No newline at end of file +
Input Signal



FFT Output
\ No newline at end of file diff --git a/azure/examples/fft/dist/twrmodworker.2165e649.js b/azure/examples/fft/dist/twrmodworker.2165e649.js index 3744680c..d8d07779 100644 --- a/azure/examples/fft/dist/twrmodworker.2165e649.js +++ b/azure/examples/fft/dist/twrmodworker.2165e649.js @@ -1,2 +1,2 @@ -(()=>{var t,e,r,s;let i;class a{sharedArray;buf;constructor(t){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSharedCircularBuffer constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");t?this.sharedArray=t:this.sharedArray=new SharedArrayBuffer(1032),this.buf=new Int32Array(this.sharedArray),this.buf[256]=0,this.buf[257]=0}write(t){let e=this.buf[257];this.buf[e]=t,256==++e&&(e=0),this.buf[257]=e,Atomics.notify(this.buf,257)}read(){if(this.isEmpty())return -1;{let t=this.buf[256],e=this.buf[t];return t++,this.buf[256]=t,e}}readWait(){if(this.isEmpty()){let t=this.buf[256];Atomics.wait(this.buf,257,t)}return this.read()}isEmpty(){return this.buf[256]==this.buf[257]}}(r=t||(t={}))[r.WAITING=0]="WAITING",r[r.SIGNALED=1]="SIGNALED";class o{sharedArray;buf;constructor(e){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSignal constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");e?this.sharedArray=e:this.sharedArray=new SharedArrayBuffer(4),this.buf=new Int32Array(this.sharedArray),this.buf[0]=t.WAITING}signal(){this.buf[0]=t.SIGNALED,Atomics.notify(this.buf,0)}wait(){this.buf[0]==t.WAITING&&Atomics.wait(this.buf,0,t.WAITING)}isSignaled(){return this.buf[0]==t.SIGNALED}reset(){this.buf[0]=t.WAITING}}(s=e||(e={}))[s.D2D_FILLRECT=1]="D2D_FILLRECT",s[s.D2D_FILLCHAR=5]="D2D_FILLCHAR",s[s.D2D_SETLINEWIDTH=10]="D2D_SETLINEWIDTH",s[s.D2D_SETFILLSTYLERGBA=11]="D2D_SETFILLSTYLERGBA",s[s.D2D_SETFONT=12]="D2D_SETFONT",s[s.D2D_BEGINPATH=13]="D2D_BEGINPATH",s[s.D2D_MOVETO=14]="D2D_MOVETO",s[s.D2D_LINETO=15]="D2D_LINETO",s[s.D2D_FILL=16]="D2D_FILL",s[s.D2D_STROKE=17]="D2D_STROKE",s[s.D2D_SETSTROKESTYLERGBA=18]="D2D_SETSTROKESTYLERGBA",s[s.D2D_ARC=19]="D2D_ARC",s[s.D2D_STROKERECT=20]="D2D_STROKERECT",s[s.D2D_FILLTEXT=21]="D2D_FILLTEXT",s[s.D2D_IMAGEDATA=22]="D2D_IMAGEDATA",s[s.D2D_PUTIMAGEDATA=23]="D2D_PUTIMAGEDATA",s[s.D2D_BEZIERTO=24]="D2D_BEZIERTO",s[s.D2D_MEASURETEXT=25]="D2D_MEASURETEXT",s[s.D2D_SAVE=26]="D2D_SAVE",s[s.D2D_RESTORE=27]="D2D_RESTORE",s[s.D2D_CREATERADIALGRADIENT=28]="D2D_CREATERADIALGRADIENT",s[s.D2D_SETCOLORSTOP=29]="D2D_SETCOLORSTOP",s[s.D2D_SETFILLSTYLEGRADIENT=30]="D2D_SETFILLSTYLEGRADIENT",s[s.D2D_RELEASEID=31]="D2D_RELEASEID",s[s.D2D_CREATELINEARGRADIENT=32]="D2D_CREATELINEARGRADIENT",s[s.D2D_SETFILLSTYLE=33]="D2D_SETFILLSTYLE",s[s.D2D_SETSTROKESTYLE=34]="D2D_SETSTROKESTYLE";class n{canvasKeys;drawCompleteSignal;props;owner;constructor(t,e){let[r,s,i]=t;this.drawCompleteSignal=new o(s),this.canvasKeys=new a(i),this.props=r,this.owner=e}charIn(){return this.canvasKeys.readWait()}inkey(){return this.canvasKeys.isEmpty()?0:this.charIn()}getProp(t){let e=this.owner.getString(t);return this.props[e]}drawSeq(t){this.drawCompleteSignal.reset(),postMessage(["drawseq",[t]]),this.drawCompleteSignal.wait()}}class l{divKeys;constructor(t){let[e]=t;this.divKeys=new a(e)}charIn(){return this.divKeys.readWait()}inkey(){return this.divKeys.isEmpty()?0:this.charIn()}charOut(t){postMessage(["divout",t])}}function h(t){postMessage(["debug",t])}class m{mod;constructor(t){this.mod=t}atod(t){let e=this.mod.getString(t),r=e.trimStart().toUpperCase();return"INF"==r||"+INF"==r?Number.POSITIVE_INFINITY:"-INF"==r?Number.NEGATIVE_INFINITY:Number.parseFloat(e.replaceAll("D","e").replaceAll("d","e"))}dtoa(t,e,r,s){if(-1==s){let s=r.toString();this.mod.copyString(t,e,s)}else{let i=r.toString();i.length>s&&(i=r.toPrecision(s)),this.mod.copyString(t,e,i)}}toFixed(t,e,r,s){let i=r.toFixed(s);this.mod.copyString(t,e,i)}toExponential(t,e,r,s){let i=r.toExponential(s);this.mod.copyString(t,e,i)}fcvtS(t,e,r,s,i,a){let o,n;if(0==t||0==a||0==i||e<1)return 1;let l=0;if(Number.isNaN(r))o="1#QNAN00000000000000000000000000000".slice(0,s+1),n=1;else if(Number.isFinite(r)){if(0==r)o="000000000000000000000000000000000000".slice(0,s),n=0;else{if(r<0&&(l=1,r=Math.abs(r)),s>100||r>1e21||r<1e-99)return this.mod.copyString(t,e,""),this.mod.mem32[i]=0,1;let[a="",h=""]=r.toFixed(s).split(".");"0"==a&&(a=""),a.length>0?(n=a.length,o=a+h):n=(o=h.replace(/^0+/,"")).length-h.length}}else o="1#INF00000000000000000000000000000".slice(0,s+1),n=1;return e-1new Promise(e=>{let r=this.exports.twr_malloc;e(r(t))}),this.init()}catch(t){throw console.log("WASM instantiate error: "+t+(t.stack?"\n"+t.stack:"")),t}}init(){let t;switch(this.modParams.stdio){case"debug":default:t=0;break;case"div":t=1;break;case"canvas":t=2;break;case"null":t=3}(0,this.exports.twr_wasm_init)(t,this.mem8.length)}async executeC(t){let e=await this.preCallC(t),r=this.executeCImpl(t[0],e);return this.postCallC(e,t),r}async executeCImpl(t,e=[]){if(!this.exports)throw Error("this.exports undefined");if(!this.exports[t])throw Error("executeC: function '"+t+"' not in export table. Use --export wasm-ld flag.");return(0,this.exports[t])(...e)}async preCallC(t){if(t.constructor!==Array)throw Error("executeC: params must be array, first arg is function name");if(0==t.length)throw Error("executeC: missing function name");let e=[],r=0;for(let s=1;s=this.mem32.length)throw Error("invalid index passed to getLong: "+t+", this.mem32.length: "+this.mem32.length);return this.mem32[e]}setLong(t,e){let r=Math.floor(t/4);if(4*r!=t)throw Error("setLong passed non long aligned address");if(r<0||r>=this.mem32.length)throw Error("invalid index passed to setLong: "+t+", this.mem32.length: "+this.mem32.length);this.mem32[r]=e}getDouble(t){let e=Math.floor(t/8);if(8*e!=t)throw Error("getLong passed non Float64 aligned address");return this.memD[e]}setDouble(t,e){let r=Math.floor(t/8);if(8*r!=t)throw Error("setDouble passed non Float64 aligned address");this.memD[r]=e}getShort(t){if(t<0||t>=this.mem8.length)throw Error("invalid index passed to getShort: "+t);return this.mem8[t]+256*this.mem8[t+1]}getString(t,e){let r="",s=0;for(;this.mem8[t+s]&&(void 0===e||s=this.mem8.length)throw Error("invalid index passed to getU8: "+t);let e=new Uint32Array(this.mem8.slice(t,t+8).buffer),r=e[0],s=e[1];if(s<0||s>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU8");if(r<0||r>this.mem8.length-s)throw Error("invalid idx.size passed to getU8");return this.mem8.slice(s,s+r)}getU32Arr(t){if(t<0||t>=this.mem8.length)throw Error("invalid index passed to getU32: "+t);let e=new Uint32Array(this.mem8.slice(t,t+8).buffer),r=e[0],s=e[1];if(s<0||s>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU32");if(r<0||r>this.mem8.length-s)throw Error("invalid idx.size passed to getU32");if(r%4!=0)throw Error("idx.size is not an integer number of 32 bit words");return new Uint32Array(this.mem8.slice(s,s+r).buffer)}}class d{callCompleteSignal;parameters;constructor(t){this.callCompleteSignal=new o(t[0]),this.parameters=new Uint32Array(t[1])}sleep(t){this.callCompleteSignal.reset(),postMessage(["sleep",[t]]),this.callCompleteSignal.wait()}time(){return this.callCompleteSignal.reset(),postMessage(["time"]),this.callCompleteSignal.wait(),this.parameters[0]}}onmessage=function(t){if("startup"==t.data[0]){let e=t.data[1];(i=new f(e.modParams,e.modWorkerParams)).loadWasm(e.urlToLoad).then(()=>{postMessage(["startupOkay"])}).catch(t=>{console.log(".catch: ",t),postMessage(["startupFail",t])})}else"executeC"==t.data[0]?i.executeCImpl(t.data[1],t.data[2]).then(t=>{postMessage(["executeCOkay",t])}).catch(t=>{console.log("exception in executeC twrworker.js\n"),console.log(t),postMessage(["executeCFail",t])}):console.log("twrworker.js: unknown message: "+t)};class f extends c{malloc;modParams;constructor(t,e){super(),this.isWorker=!0,this.malloc=t=>{throw Error("error - un-init malloc called")},this.modParams=t;let r=new n(e.canvasProxyParams,this),s=new l(e.divProxyParams),i=new d(e.waitingCallsProxyParams);this.modParams.imports={twrDebugLog:h,twrSleep:i.sleep.bind(i),twrTime:i.time.bind(i),twrDivCharOut:s.charOut.bind(s),twrDivCharIn:s.charIn.bind(s),twrCanvasCharIn:r.charIn.bind(r),twrCanvasInkey:r.inkey.bind(r),twrCanvasGetProp:r.getProp.bind(r),twrCanvasDrawSeq:r.drawSeq.bind(r),twrSin:Math.sin,twrCos:Math.cos,twrTan:Math.tan,twrFAbs:Math.abs,twrACos:Math.acos,twrASin:Math.asin,twrATan:Math.atan,twrExp:Math.exp,twrFloor:Math.floor,twrCeil:Math.ceil,twrFMod:function(t,e){return t%e},twrLog:Math.log,twrPow:Math.pow,twrSqrt:Math.sqrt,twrTrunc:Math.trunc,twrDtoa:this.floatUtil.dtoa.bind(this.floatUtil),twrToFixed:this.floatUtil.toFixed.bind(this.floatUtil),twrToExponential:this.floatUtil.toExponential.bind(this.floatUtil),twrAtod:this.floatUtil.atod.bind(this.floatUtil),twrFcvtS:this.floatUtil.fcvtS.bind(this.floatUtil)}}}})(); +(()=>{var t,e,r,s;let i;class a{sharedArray;buf;constructor(t){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSharedCircularBuffer constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");t?this.sharedArray=t:this.sharedArray=new SharedArrayBuffer(1032),this.buf=new Int32Array(this.sharedArray),this.buf[256]=0,this.buf[257]=0}write(t){let e=this.buf[257];this.buf[e]=t,256==++e&&(e=0),this.buf[257]=e,Atomics.notify(this.buf,257)}read(){if(this.isEmpty())return -1;{let t=this.buf[256],e=this.buf[t];return t++,this.buf[256]=t,e}}readWait(){if(this.isEmpty()){let t=this.buf[256];Atomics.wait(this.buf,257,t)}return this.read()}isEmpty(){return this.buf[256]==this.buf[257]}}(r=t||(t={}))[r.WAITING=0]="WAITING",r[r.SIGNALED=1]="SIGNALED";class o{sharedArray;buf;constructor(e){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSignal constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");e?this.sharedArray=e:this.sharedArray=new SharedArrayBuffer(4),this.buf=new Int32Array(this.sharedArray),this.buf[0]=t.WAITING}signal(){this.buf[0]=t.SIGNALED,Atomics.notify(this.buf,0)}wait(){this.buf[0]==t.WAITING&&Atomics.wait(this.buf,0,t.WAITING)}isSignaled(){return this.buf[0]==t.SIGNALED}reset(){this.buf[0]=t.WAITING}}(s=e||(e={}))[s.D2D_FILLRECT=1]="D2D_FILLRECT",s[s.D2D_FILLCHAR=5]="D2D_FILLCHAR",s[s.D2D_SETLINEWIDTH=10]="D2D_SETLINEWIDTH",s[s.D2D_SETFILLSTYLERGBA=11]="D2D_SETFILLSTYLERGBA",s[s.D2D_SETFONT=12]="D2D_SETFONT",s[s.D2D_BEGINPATH=13]="D2D_BEGINPATH",s[s.D2D_MOVETO=14]="D2D_MOVETO",s[s.D2D_LINETO=15]="D2D_LINETO",s[s.D2D_FILL=16]="D2D_FILL",s[s.D2D_STROKE=17]="D2D_STROKE",s[s.D2D_SETSTROKESTYLERGBA=18]="D2D_SETSTROKESTYLERGBA",s[s.D2D_ARC=19]="D2D_ARC",s[s.D2D_STROKERECT=20]="D2D_STROKERECT",s[s.D2D_FILLTEXT=21]="D2D_FILLTEXT",s[s.D2D_IMAGEDATA=22]="D2D_IMAGEDATA",s[s.D2D_PUTIMAGEDATA=23]="D2D_PUTIMAGEDATA",s[s.D2D_BEZIERTO=24]="D2D_BEZIERTO",s[s.D2D_MEASURETEXT=25]="D2D_MEASURETEXT",s[s.D2D_SAVE=26]="D2D_SAVE",s[s.D2D_RESTORE=27]="D2D_RESTORE",s[s.D2D_CREATERADIALGRADIENT=28]="D2D_CREATERADIALGRADIENT",s[s.D2D_SETCOLORSTOP=29]="D2D_SETCOLORSTOP",s[s.D2D_SETFILLSTYLEGRADIENT=30]="D2D_SETFILLSTYLEGRADIENT",s[s.D2D_RELEASEID=31]="D2D_RELEASEID",s[s.D2D_CREATELINEARGRADIENT=32]="D2D_CREATELINEARGRADIENT",s[s.D2D_SETFILLSTYLE=33]="D2D_SETFILLSTYLE",s[s.D2D_SETSTROKESTYLE=34]="D2D_SETSTROKESTYLE";class n{canvasKeys;drawCompleteSignal;props;owner;constructor(t,e){let[r,s,i]=t;this.drawCompleteSignal=new o(s),this.canvasKeys=new a(i),this.props=r,this.owner=e}charIn(){return this.canvasKeys.readWait()}inkey(){return this.canvasKeys.isEmpty()?0:this.charIn()}getProp(t){let e=this.owner.getString(t);return this.props[e]}drawSeq(t){this.drawCompleteSignal.reset(),postMessage(["drawseq",[t]]),this.drawCompleteSignal.wait()}}class l{divKeys;constructor(t){let[e]=t;this.divKeys=new a(e)}charIn(){return this.divKeys.readWait()}inkey(){return this.divKeys.isEmpty()?0:this.charIn()}charOut(t){postMessage(["divout",t])}}function h(t){postMessage(["debug",t])}class m{mod;constructor(t){this.mod=t}atod(t){let e=this.mod.getString(t),r=e.trimStart().toUpperCase();return"INF"==r||"+INF"==r?Number.POSITIVE_INFINITY:"-INF"==r?Number.NEGATIVE_INFINITY:Number.parseFloat(e.replaceAll("D","e").replaceAll("d","e"))}dtoa(t,e,r,s){if(-1==s){let s=r.toString();this.mod.copyString(t,e,s)}else{let i=r.toString();i.length>s&&(i=r.toPrecision(s)),this.mod.copyString(t,e,i)}}toFixed(t,e,r,s){let i=r.toFixed(s);this.mod.copyString(t,e,i)}toExponential(t,e,r,s){let i=r.toExponential(s);this.mod.copyString(t,e,i)}fcvtS(t,e,r,s,i,a){let o,n;if(0==t||0==a||0==i||e<1)return 1;let l=0;if(Number.isNaN(r))o="1#QNAN00000000000000000000000000000".slice(0,s+1),n=1;else if(Number.isFinite(r)){if(0==r)o="000000000000000000000000000000000000".slice(0,s),n=0;else{if(r<0&&(l=1,r=Math.abs(r)),s>100||r>1e21||r<1e-99)return this.mod.copyString(t,e,""),this.mod.mem32[i]=0,1;let[a="",h=""]=r.toFixed(s).split(".");"0"==a&&(a=""),a.length>0?(n=a.length,o=a+h):n=(o=h.replace(/^0+/,"")).length-h.length}}else o="1#INF00000000000000000000000000000".slice(0,s+1),n=1;return e-1new Promise(e=>{let r=this.exports.twr_malloc;e(r(t))}),this.init()}catch(t){throw console.log("WASM instantiate error: "+t+(t.stack?"\n"+t.stack:"")),t}}init(){let t;switch(this.modParams.stdio){case"debug":default:t=0;break;case"div":t=1;break;case"canvas":t=2;break;case"null":t=3}(0,this.exports.twr_wasm_init)(t,this.mem8.length)}async callC(t){let e=await this.preCallC(t),r=this.callCImpl(t[0],e);return this.postCallC(e,t),r}async callCImpl(t,e=[]){if(!this.exports)throw Error("this.exports undefined");if(!this.exports[t])throw Error("callC: function '"+t+"' not in export table. Use --export wasm-ld flag.");return(0,this.exports[t])(...e)}async preCallC(t){if(t.constructor!==Array)throw Error("callC: params must be array, first arg is function name");if(0==t.length)throw Error("callC: missing function name");let e=[],r=0;for(let s=1;s=this.mem32.length)throw Error("invalid index passed to getLong: "+t+", this.mem32.length: "+this.mem32.length);return this.mem32[e]}setLong(t,e){let r=Math.floor(t/4);if(4*r!=t)throw Error("setLong passed non long aligned address");if(r<0||r>=this.mem32.length)throw Error("invalid index passed to setLong: "+t+", this.mem32.length: "+this.mem32.length);this.mem32[r]=e}getDouble(t){let e=Math.floor(t/8);if(8*e!=t)throw Error("getLong passed non Float64 aligned address");return this.memD[e]}setDouble(t,e){let r=Math.floor(t/8);if(8*r!=t)throw Error("setDouble passed non Float64 aligned address");this.memD[r]=e}getShort(t){if(t<0||t>=this.mem8.length)throw Error("invalid index passed to getShort: "+t);return this.mem8[t]+256*this.mem8[t+1]}getString(t,e){let r="",s=0;for(;this.mem8[t+s]&&(void 0===e||s=this.mem8.length)throw Error("invalid index passed to getU8: "+t);let e=new Uint32Array(this.mem8.slice(t,t+8).buffer),r=e[0],s=e[1];if(s<0||s>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU8");if(r<0||r>this.mem8.length-s)throw Error("invalid idx.size passed to getU8");return this.mem8.slice(s,s+r)}getU32Arr(t){if(t<0||t>=this.mem8.length)throw Error("invalid index passed to getU32: "+t);let e=new Uint32Array(this.mem8.slice(t,t+8).buffer),r=e[0],s=e[1];if(s<0||s>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU32");if(r<0||r>this.mem8.length-s)throw Error("invalid idx.size passed to getU32");if(r%4!=0)throw Error("idx.size is not an integer number of 32 bit words");return new Uint32Array(this.mem8.slice(s,s+r).buffer)}}class d{callCompleteSignal;parameters;constructor(t){this.callCompleteSignal=new o(t[0]),this.parameters=new Uint32Array(t[1])}sleep(t){this.callCompleteSignal.reset(),postMessage(["sleep",[t]]),this.callCompleteSignal.wait()}time(){return this.callCompleteSignal.reset(),postMessage(["time"]),this.callCompleteSignal.wait(),this.parameters[0]}}onmessage=function(t){if("startup"==t.data[0]){let e=t.data[1];(i=new f(e.modParams,e.modWorkerParams)).loadWasm(e.urlToLoad).then(()=>{postMessage(["startupOkay"])}).catch(t=>{console.log(".catch: ",t),postMessage(["startupFail",t])})}else"callC"==t.data[0]?i.callCImpl(t.data[1],t.data[2]).then(t=>{postMessage(["callCOkay",t])}).catch(t=>{console.log("exception in callC twrworker.js\n"),console.log(t),postMessage(["callCFail",t])}):console.log("twrworker.js: unknown message: "+t)};class f extends c{malloc;modParams;constructor(t,e){super(),this.isWorker=!0,this.malloc=t=>{throw Error("error - un-init malloc called")},this.modParams=t;let r=new n(e.canvasProxyParams,this),s=new l(e.divProxyParams),i=new d(e.waitingCallsProxyParams);this.modParams.imports={twrDebugLog:h,twrSleep:i.sleep.bind(i),twrTime:i.time.bind(i),twrDivCharOut:s.charOut.bind(s),twrDivCharIn:s.charIn.bind(s),twrCanvasCharIn:r.charIn.bind(r),twrCanvasInkey:r.inkey.bind(r),twrCanvasGetProp:r.getProp.bind(r),twrCanvasDrawSeq:r.drawSeq.bind(r),twrSin:Math.sin,twrCos:Math.cos,twrTan:Math.tan,twrFAbs:Math.abs,twrACos:Math.acos,twrASin:Math.asin,twrATan:Math.atan,twrExp:Math.exp,twrFloor:Math.floor,twrCeil:Math.ceil,twrFMod:function(t,e){return t%e},twrLog:Math.log,twrPow:Math.pow,twrSqrt:Math.sqrt,twrTrunc:Math.trunc,twrDtoa:this.floatUtil.dtoa.bind(this.floatUtil),twrToFixed:this.floatUtil.toFixed.bind(this.floatUtil),twrToExponential:this.floatUtil.toExponential.bind(this.floatUtil),twrAtod:this.floatUtil.atod.bind(this.floatUtil),twrFcvtS:this.floatUtil.fcvtS.bind(this.floatUtil)}}}})(); //# sourceMappingURL=twrmodworker.2165e649.js.map diff --git a/azure/examples/fft/dist/twrmodworker.2165e649.js.map b/azure/examples/fft/dist/twrmodworker.2165e649.js.map index 29a4d41e..77745e98 100644 --- a/azure/examples/fft/dist/twrmodworker.2165e649.js.map +++ b/azure/examples/fft/dist/twrmodworker.2165e649.js.map @@ -1 +1 @@ -{"mappings":"A,C,SQKK,EJgBA,EIhBA,EJgBA,MFZD,CISE,OAAO,EACZ,WAA8B,AAC9B,CAAA,GAAe,AAEf,aAAa,CAAqB,CAAlC,CACO,GAAI,AAAkB,aAAlB,OAAO,QACH,CAAC,qBAAuB,AAA+B,UAA7B,OAAO,QAAQ,CAAC,QAAQ,CAAe,MAAM,AAAI,MAAM,4DAA4D,oBAAoB,iCAErK,EAAI,IAAI,CAAC,WAAW,CAAC,EACpB,IAAI,CAAC,WAAW,CAAC,IAAI,kBAAkB,MAClD,IAAI,CAAC,GAAG,CAAC,IAAI,WAAW,IAAI,CAAC,WAAW,EAClC,IAAI,CAAC,GAAG,CArBJ,IAqBW,CAAC,EAChB,IAAI,CAAC,GAAG,CArBJ,IAqBW,CAAC,CACvB,CAEA,MAAM,CAAQ,CAAd,CACO,IAAI,EAAE,IAAI,CAAC,GAAG,CAzBV,IAyBiB,AACrB,CAAA,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAzBV,OA2BE,GAAQ,CAAA,EAAE,CAAA,EACd,IAAI,CAAC,GAAG,CA7BJ,IA6BW,CAAC,EAChB,QAAQ,MAAM,CAAC,IAAI,CAAC,GAAG,CA9BnB,IA+BX,CAEA,MAAA,CACO,GAAK,IAAI,CAAC,OA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js/twrcircular.js","../../source/twr-wasm-ts/twrcircular.ts","../../lib-js/twrsignal.js","../../source/twr-wasm-ts/twrsignal.ts","../../lib-js/twrdiv.js","../../source/twr-wasm-ts/twrdiv.ts","../../lib-js/twrdebug.js","../../source/twr-wasm-ts/twrdebug.ts","../../lib-js/twrmodbase.js","../../source/twr-wasm-ts/twrmodbase.ts","../../lib-js/twrfloat.js","../../source/twr-wasm-ts/twrfloat.ts","../../lib-js/twrwaitingcalls.js","../../source/twr-wasm-ts/twrwaitingcalls.ts","../../lib-js/twrdate.js","../../source/twr-wasm-ts/twrdate.ts"],"sourcesContent":["(() => {\nvar $3e39efa823870787$exports = {};\n// this script is the WebWorker thead used by class twrWasmAsyncModule\n//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst $892fccfc812d5e20$var$RDIDX = 256;\nconst $892fccfc812d5e20$var$WRIDX = 257;\nconst $892fccfc812d5e20$var$LEN = 256;\nclass $892fccfc812d5e20$export$a01cca24f011573a {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(1032);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[$892fccfc812d5e20$var$RDIDX] = 0;\n this.buf[$892fccfc812d5e20$var$WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[$892fccfc812d5e20$var$WRIDX];\n this.buf[i] = n;\n i++;\n if (i == $892fccfc812d5e20$var$LEN) i = 0;\n this.buf[$892fccfc812d5e20$var$WRIDX] = i;\n Atomics.notify(this.buf, $892fccfc812d5e20$var$WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[$892fccfc812d5e20$var$RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[$892fccfc812d5e20$var$RDIDX] = i;\n return n;\n } else return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[$892fccfc812d5e20$var$RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, $892fccfc812d5e20$var$WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[$892fccfc812d5e20$var$RDIDX] == this.buf[$892fccfc812d5e20$var$WRIDX];\n }\n}\n\n\n//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar $b93f1fdf40141def$var$twrSignalState;\n(function(twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})($b93f1fdf40141def$var$twrSignalState || ($b93f1fdf40141def$var$twrSignalState = {}));\nclass $b93f1fdf40141def$export$e37a7b7b851b97f3 {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == $b93f1fdf40141def$var$twrSignalState.WAITING) //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, $b93f1fdf40141def$var$twrSignalState.WAITING);\n }\n isSignaled() {\n return this.buf[0] == $b93f1fdf40141def$var$twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.WAITING;\n }\n}\n\n\nvar $c4741cac81d14197$var$D2DType;\n(function(D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})($c4741cac81d14197$var$D2DType || ($c4741cac81d14197$var$D2DType = {}));\nclass $c4741cac81d14197$export$2f298dd69cef3c34 {\n ctx;\n props = {\n charWidth: 0,\n charHeight: 0,\n foreColor: 0,\n backColor: 0,\n widthInChars: 0,\n heightInChars: 0,\n canvasHeight: 0,\n canvasWidth: 0\n };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase){\n const { forecolor: forecolor, backcolor: backcolor, fontsize: fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)();\n this.canvasKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.props,\n this.cmdCompleteSignal.sharedArray,\n this.canvasKeys.sharedArray\n ];\n }\n getProp(pn) {\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */ drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx) return;\n let ins = this.owner.getLong(ds); /* ds->start */ \n const lastins = this.owner.getLong(ds + 4); /* ds->last */ \n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while(true){\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */ \n switch(type){\n case $c4741cac81d14197$var$D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_BEGINPATH:\n this.ctx.beginPath();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILL:\n this.ctx.fill();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SAVE:\n this.ctx.save();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_RESTORE:\n this.ctx.restore();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_STROKE:\n this.ctx.stroke();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = this.owner.getLong(ins + 48) != 0;\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n } else this.precomputedObjects[id] = {\n mem8: new Uint8Array(this.owner.memory.buffer, start, length),\n width: width,\n height: height\n };\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id]) delete this.precomputedObjects[id];\n else console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n else {\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) this.ctx.putImageData(imgData, dx, dy);\n else this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */ \n if (next == 0) {\n if (ins != lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nclass $c4741cac81d14197$export$c779b2cd00544976 {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner){\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)(signalBuffer);\n this.canvasKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\n \"drawseq\",\n [\n ds\n ]\n ]);\n this.drawCompleteSignal.wait();\n }\n}\n\n\n\nclass $8963973702ae5462$export$dd376bb3f10f6896 {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611);\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase){\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) this.divKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(); // tsconfig, lib must be set to 2017 or higher\n if (this.div && !modParams.styleIsDefault) {\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.divKeys.sharedArray\n ];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */ charOut(ch) {\n if (!this.div) return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n }\n switch(ch){\n case 10:\n case 13:\n if (ch == 10 && this.lastChar == 13) break; // detect CR LF and treat as single new line\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n case 0xE:\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF:\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for(let i = 0; i < str.length; i++)this.charOut(str.charCodeAt(i));\n }\n}\nclass $8963973702ae5462$export$b377f0bbf2c7581e {\n divKeys;\n constructor(params){\n const [divKeysBuffer] = params;\n this.divKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n charOut(ch) {\n postMessage([\n \"divout\",\n ch\n ]);\n }\n}\n\n\nlet $8ac0b786da854328$var$logline = \"\";\nfunction $8ac0b786da854328$export$16b4216ec014493d(char) {\n if (char == 10 || char == 3) {\n console.log($8ac0b786da854328$var$logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n $8ac0b786da854328$var$logline = \"\";\n } else {\n $8ac0b786da854328$var$logline = $8ac0b786da854328$var$logline + String.fromCharCode(char);\n if ($8ac0b786da854328$var$logline.length >= 200) {\n console.log($8ac0b786da854328$var$logline);\n $8ac0b786da854328$var$logline = \"\";\n }\n }\n}\nfunction $8ac0b786da854328$export$485af4d0039b3389(ch) {\n postMessage([\n \"debug\",\n ch\n ]);\n}\n\n\nclass $e72303a1db04bdfa$export$918ffb7e046a537b {\n mod;\n constructor(mod){\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\") return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\") return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll(\"D\", \"e\").replaceAll(\"d\", \"e\"));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n } else {\n let r = value.toString();\n if (r.length > max_precision) r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, sizeInBytes, value, fracpart_numdigits, dec, sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1) return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) {\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (!Number.isFinite(value)) {\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n } else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split(\".\");\n if (intPart == \"0\") intPart = \"\";\n if (intPart.length > 0) {\n decpos = intPart.length;\n digits = intPart + fracPart;\n } else {\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length) return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */ }\n}\n\n\nclass $ece7fa3ed770778a$export$c83a0a3bffe07399 {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule;\n floatUtil;\n constructor(isWasmModule = false){\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new (0, $e72303a1db04bdfa$export$918ffb7e046a537b)(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/ /*********************************************************************/ async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n } catch (err) {\n console.log(\"loadWasm() failed to fetch: \" + pathToLoad);\n throw err;\n }\n if (!response.ok) throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, {\n env: allimports\n });\n this.exports = instance.instance.exports;\n if (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory) throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer) console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\n \"setmemory\",\n this.memory\n ]);\n }\n if (this.isWasmModule) // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n {\n if (!(this.memory.buffer instanceof ArrayBuffer)) console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size)=>{\n return new Promise((resolve)=>{\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n } catch (err) {\n console.log(\"WASM instantiate error: \" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch(this.modParams.stdio){\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* executeC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */ async executeC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.executeCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async executeCImpl(fname, cparams = []) {\n if (!this.exports) throw new Error(\"this.exports undefined\");\n if (!this.exports[fname]) throw new Error(\"executeC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array)) throw new Error(\"executeC: params must be array, first arg is function name\");\n if (params.length == 0) throw new Error(\"executeC: missing function name\");\n let cparams = [];\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n cparams[ci++] = p;\n break;\n case \"string\":\n cparams[ci++] = await this.putString(p);\n break;\n case \"object\":\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n } else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"executeC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n ci++;\n break;\n case \"string\":\n this.executeCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n case \"object\":\n if (p instanceof URL) {\n this.executeCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci = ci + 2;\n break;\n } else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for(let j = 0; j < u8.length; j++)u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.executeCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n } else throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/ /*********************************************************************/ // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for(i = 0; i < sin.length && i < buffer_size - 1; i++)this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for(let i = 0; i < u8a.length; i++)this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === \"object\" && fnin instanceof URL)) throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [\n dest,\n src.length\n ];\n } catch (err) {\n console.log(\"fetchAndPutURL Error. URL: \" + fnin + \"\\n\" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while(this.mem8[strIndex + i] && (len === undefined ? true : i < len) && strIndex + i < this.mem8.length){\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array(this.mem8.slice(dataptr, dataptr + size).buffer);\n return u32;\n }\n}\n\n\n\nfunction $4af5689abbc8d01b$export$78724cdcf7ebea1d() {\n return Date.now();\n}\n\n\nclass $aff9c2c494d23fe3$export$9e37856d1928d388 {\n callCompleteSignal;\n parameters;\n constructor(){\n this.callCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(()=>{\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = (0, $4af5689abbc8d01b$export$78724cdcf7ebea1d)();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [\n this.callCompleteSignal.sharedArray,\n this.parameters.buffer\n ];\n }\n processMessage(msgType, data) {\n switch(msgType){\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\nclass $aff9c2c494d23fe3$export$78d2a4633fe89379 {\n callCompleteSignal;\n parameters;\n constructor(params){\n this.callCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\n \"sleep\",\n [\n ms\n ]\n ]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\n \"time\"\n ]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n\n\nlet $3e39efa823870787$var$mod;\nonmessage = function(e) {\n //console.log('twrworker.js: message received from main script: '+e.data);\n if (e.data[0] == \"startup\") {\n const params = e.data[1];\n //console.log(\"Worker startup params:\",params);\n $3e39efa823870787$var$mod = new $3e39efa823870787$var$twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\n $3e39efa823870787$var$mod.loadWasm(params.urlToLoad).then(()=>{\n postMessage([\n \"startupOkay\"\n ]);\n }).catch((ex)=>{\n console.log(\".catch: \", ex);\n postMessage([\n \"startupFail\",\n ex\n ]);\n });\n } else if (e.data[0] == \"executeC\") $3e39efa823870787$var$mod.executeCImpl(e.data[1], e.data[2]).then((rc)=>{\n postMessage([\n \"executeCOkay\",\n rc\n ]);\n }).catch((e)=>{\n console.log(\"exception in executeC twrworker.js\\n\");\n console.log(e);\n postMessage([\n \"executeCFail\",\n e\n ]);\n });\n else console.log(\"twrworker.js: unknown message: \" + e);\n};\n// ************************************************************************\nclass $3e39efa823870787$var$twrWasmModuleInWorker extends (0, $ece7fa3ed770778a$export$c83a0a3bffe07399) {\n malloc;\n modParams;\n constructor(modParams, modInWorkerParams){\n super();\n this.isWorker = true;\n this.malloc = (size)=>{\n throw new Error(\"error - un-init malloc called\");\n };\n this.modParams = modParams;\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\n const canvasProxy = new (0, $c4741cac81d14197$export$c779b2cd00544976)(modInWorkerParams.canvasProxyParams, this);\n const divProxy = new (0, $8963973702ae5462$export$b377f0bbf2c7581e)(modInWorkerParams.divProxyParams);\n const waitingCallsProxy = new (0, $aff9c2c494d23fe3$export$78d2a4633fe89379)(modInWorkerParams.waitingCallsProxyParams);\n this.modParams.imports = {\n twrDebugLog: (0, $8ac0b786da854328$export$485af4d0039b3389),\n twrSleep: waitingCallsProxy.sleep.bind(waitingCallsProxy),\n twrTime: waitingCallsProxy.time.bind(waitingCallsProxy),\n twrDivCharOut: divProxy.charOut.bind(divProxy),\n twrDivCharIn: divProxy.charIn.bind(divProxy),\n twrCanvasCharIn: canvasProxy.charIn.bind(canvasProxy),\n twrCanvasInkey: canvasProxy.inkey.bind(canvasProxy),\n twrCanvasGetProp: canvasProxy.getProp.bind(canvasProxy),\n twrCanvasDrawSeq: canvasProxy.drawSeq.bind(canvasProxy),\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function(x, y) {\n return x % y;\n },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n}\n\n})();\n//# sourceMappingURL=twrmodworker.2165e649.js.map\n","// this script is the WebWorker thead used by class twrWasmAsyncModule\nimport { twrCanvasProxy } from \"./twrcanvas.js\";\nimport { twrDivProxy } from \"./twrdiv.js\";\nimport { twrDebugLogProxy } from \"./twrdebug.js\";\nimport { twrWasmModuleBase } from \"./twrmodbase.js\";\nimport { twrWaitingCallsProxy } from \"./twrwaitingcalls.js\";\nlet mod;\nonmessage = function (e) {\n //console.log('twrworker.js: message received from main script: '+e.data);\n if (e.data[0] == 'startup') {\n const params = e.data[1];\n //console.log(\"Worker startup params:\",params);\n mod = new twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\n mod.loadWasm(params.urlToLoad).then(() => {\n postMessage([\"startupOkay\"]);\n }).catch((ex) => {\n console.log(\".catch: \", ex);\n postMessage([\"startupFail\", ex]);\n });\n }\n else if (e.data[0] == 'executeC') {\n mod.executeCImpl(e.data[1], e.data[2]).then((rc) => {\n postMessage([\"executeCOkay\", rc]);\n }).catch(e => {\n console.log(\"exception in executeC twrworker.js\\n\");\n console.log(e);\n postMessage([\"executeCFail\", e]);\n });\n }\n else {\n console.log(\"twrworker.js: unknown message: \" + e);\n }\n};\n// ************************************************************************\nclass twrWasmModuleInWorker extends twrWasmModuleBase {\n malloc;\n modParams;\n constructor(modParams, modInWorkerParams) {\n super();\n this.isWorker = true;\n this.malloc = (size) => { throw new Error(\"error - un-init malloc called\"); };\n this.modParams = modParams;\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\n const canvasProxy = new twrCanvasProxy(modInWorkerParams.canvasProxyParams, this);\n const divProxy = new twrDivProxy(modInWorkerParams.divProxyParams);\n const waitingCallsProxy = new twrWaitingCallsProxy(modInWorkerParams.waitingCallsProxyParams);\n this.modParams.imports = {\n twrDebugLog: twrDebugLogProxy,\n twrSleep: waitingCallsProxy.sleep.bind(waitingCallsProxy),\n twrTime: waitingCallsProxy.time.bind(waitingCallsProxy),\n twrDivCharOut: divProxy.charOut.bind(divProxy),\n twrDivCharIn: divProxy.charIn.bind(divProxy),\n twrCanvasCharIn: canvasProxy.charIn.bind(canvasProxy),\n twrCanvasInkey: canvasProxy.inkey.bind(canvasProxy),\n twrCanvasGetProp: canvasProxy.getProp.bind(canvasProxy),\n twrCanvasDrawSeq: canvasProxy.drawSeq.bind(canvasProxy),\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function (x, y) { return x % y; },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n}\n//# sourceMappingURL=twrmodworker.js.map","// this script is the WebWorker thead used by class twrWasmAsyncModule\r\n\r\nimport {twrCanvasProxy} from \"./twrcanvas.js\";\r\nimport {twrDivProxy} from \"./twrdiv.js\";\r\nimport {twrDebugLogProxy} from \"./twrdebug.js\";\r\nimport {TAsyncModStartupMsg} from \"./twrmodasync.js\"\r\nimport {twrWasmModuleBase, IModInWorkerParams, IModParams} from \"./twrmodbase.js\"\r\nimport {twrWaitingCallsProxy} from \"./twrwaitingcalls.js\";\r\n\r\nlet mod:twrWasmModuleInWorker;\r\n\r\nonmessage = function(e) {\r\n //console.log('twrworker.js: message received from main script: '+e.data);\r\n\r\n if (e.data[0]=='startup') {\r\n const params:TAsyncModStartupMsg=e.data[1];\r\n //console.log(\"Worker startup params:\",params);\r\n mod=new twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\r\n\r\n mod.loadWasm(params.urlToLoad).then( ()=> {\r\n postMessage([\"startupOkay\"]);\r\n }).catch( (ex)=> {\r\n console.log(\".catch: \", ex);\r\n postMessage([\"startupFail\", ex]);\r\n });\r\n }\r\n else if (e.data[0]=='executeC') {\r\n mod.executeCImpl(e.data[1], e.data[2]).then( (rc)=> {\r\n postMessage([\"executeCOkay\", rc]);\r\n }).catch(e => {\r\n console.log(\"exception in executeC twrworker.js\\n\");\r\n console.log(e);\r\n postMessage([\"executeCFail\", e]);\r\n });\r\n }\r\n else {\r\n console.log(\"twrworker.js: unknown message: \"+e);\r\n }\r\n}\r\n\r\n\r\n// ************************************************************************\r\n\r\nclass twrWasmModuleInWorker extends twrWasmModuleBase {\r\n\tmalloc:(size:number)=>Promise;\r\n modParams: IModParams;\r\n\r\n\r\n constructor(modParams:IModParams, modInWorkerParams:IModInWorkerParams) {\r\n super();\r\n this.isWorker=true;\r\n this.malloc=(size:number)=>{throw new Error(\"error - un-init malloc called\")};\r\n this.modParams=modParams;\r\n\r\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\r\n const canvasProxy = new twrCanvasProxy(modInWorkerParams.canvasProxyParams, this);\r\n const divProxy = new twrDivProxy(modInWorkerParams.divProxyParams);\r\n const waitingCallsProxy = new twrWaitingCallsProxy(modInWorkerParams.waitingCallsProxyParams);\r\n\r\n this.modParams.imports={\r\n twrDebugLog:twrDebugLogProxy,\r\n twrSleep:waitingCallsProxy.sleep.bind(waitingCallsProxy),\r\n twrTime:waitingCallsProxy.time.bind(waitingCallsProxy),\r\n\r\n twrDivCharOut:divProxy.charOut.bind(divProxy), \r\n twrDivCharIn:divProxy.charIn.bind(divProxy), \r\n\r\n twrCanvasCharIn:canvasProxy.charIn.bind(canvasProxy),\r\n twrCanvasInkey:canvasProxy.inkey.bind(canvasProxy),\r\n twrCanvasGetProp:canvasProxy.getProp.bind(canvasProxy),\r\n twrCanvasDrawSeq:canvasProxy.drawSeq.bind(canvasProxy),\r\n\r\n\t\t\ttwrSin:Math.sin,\r\n\t\t\ttwrCos:Math.cos,\r\n\t\t\ttwrTan: Math.tan,\r\n\t\t\ttwrFAbs: Math.abs,\r\n\t\t\ttwrACos: Math.acos,\r\n\t\t\ttwrASin: Math.asin,\r\n\t\t\ttwrATan: Math.atan,\r\n\t\t\ttwrExp: Math.exp,\r\n\t\t\ttwrFloor: Math.floor,\r\n\t\t\ttwrCeil: Math.ceil,\r\n\t\t\ttwrFMod: function(x:number, y:number) {return x%y},\r\n\t\t\ttwrLog: Math.log,\r\n\t\t\ttwrPow: Math.pow,\r\n\t\t\ttwrSqrt: Math.sqrt,\r\n\t\t\ttwrTrunc: Math.trunc,\r\n\r\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\r\n\t\t\ttwrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\r\n\t\t\ttwrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\r\n\t\t\ttwrAtod: this.floatUtil.atod.bind(this.floatUtil),\r\n\t\t\ttwrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\r\n \r\n }\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nimport { twrSignal } from \"./twrsignal.js\";\nvar D2DType;\n(function (D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})(D2DType || (D2DType = {}));\nexport class twrCanvas {\n ctx;\n props = { charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight: 0, canvasWidth: 0 };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase) {\n const { forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new twrSignal();\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext)\n throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c)\n throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2)\n throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\n }\n getProp(pn) {\n if (!this.isValid())\n console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */\n drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid())\n console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx)\n return;\n let ins = this.owner.getLong(ds); /* ds->start */\n const lastins = this.owner.getLong(ds + 4); /* ds->last */\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while (1) {\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */\n if (0 /*type!=D2DType.D2D_FILLRECT*/) {\n console.log(\"ins\", ins);\n console.log(\"hdr.next\", this.owner.mem8[ins], this.owner.mem8[ins + 1], this.owner.mem8[ins + 2], this.owner.mem8[ins + 3]);\n console.log(\"hdr.type\", this.owner.mem8[ins + 4], this.owner.mem8[ins + 5]);\n console.log(\"next 4 bytes\", this.owner.mem8[ins + 6], this.owner.mem8[ins + 7], this.owner.mem8[ins + 8], this.owner.mem8[ins + 9]);\n console.log(\"and 4 more \", this.owner.mem8[ins + 10], this.owner.mem8[ins + 11], this.owner.mem8[ins + 12], this.owner.mem8[ins + 13]);\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\n }\n switch (type) {\n case D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case D2DType.D2D_BEGINPATH:\n {\n this.ctx.beginPath();\n }\n break;\n case D2DType.D2D_FILL:\n {\n this.ctx.fill();\n }\n break;\n case D2DType.D2D_SAVE:\n {\n this.ctx.save();\n }\n break;\n case D2DType.D2D_RESTORE:\n {\n this.ctx.restore();\n }\n break;\n case D2DType.D2D_STROKE:\n {\n this.ctx.stroke();\n }\n break;\n case D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = (this.owner.getLong(ins + 48) != 0);\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n }\n else { // Uint8ClampedArray doesn't support shared memory\n this.precomputedObjects[id] = { mem8: new Uint8Array(this.owner.memory.buffer, start, length), width: width, height: height };\n }\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id])\n delete this.precomputedObjects[id];\n else\n console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) {\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n }\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) {\n this.ctx.putImageData(imgData, dx, dy);\n }\n else {\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */\n if (next == 0) {\n if (ins != lastins)\n throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal)\n this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nexport class twrCanvasProxy {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner) {\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new twrSignal(signalBuffer);\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\"drawseq\", [ds]]);\n this.drawCompleteSignal.wait();\n }\n}\n//# sourceMappingURL=twrcanvas.js.map","import {twrWasmModuleBase, IModParams} from \"./twrmodbase.js\"\r\nimport {twrSharedCircularBuffer} from \"./twrcircular.js\";\r\nimport {twrSignal} from \"./twrsignal.js\";\r\n\r\n\r\n// Canvas have a size that will be set based on the character width x height\r\n// The display size for a canvas will default to this size, but can be changed in the HTML/JS via\r\n// canvas.style.width = \"700px\";\r\n// canvas.style.height = \"500px\";\r\n\r\nexport interface ICanvasProps {\r\n\tcharWidth: number,\r\n\tcharHeight: number,\r\n\tforeColor: number,\r\n\tbackColor: number,\r\n widthInChars: number,\r\n heightInChars: number,\r\n canvasWidth:number,\r\n canvasHeight:number\r\n}\r\n\r\nenum D2DType {\r\n D2D_FILLRECT=1,\r\n D2D_FILLCHAR=5,\r\n D2D_SETLINEWIDTH=10,\r\n D2D_SETFILLSTYLERGBA=11,\r\n D2D_SETFONT=12,\r\n D2D_BEGINPATH=13,\r\n D2D_MOVETO=14,\r\n D2D_LINETO=15,\r\n D2D_FILL=16,\r\n D2D_STROKE=17,\r\n D2D_SETSTROKESTYLERGBA=18,\r\n D2D_ARC=19,\r\n D2D_STROKERECT=20,\r\n D2D_FILLTEXT=21,\r\n D2D_IMAGEDATA=22,\r\n D2D_PUTIMAGEDATA=23,\r\n D2D_BEZIERTO=24,\r\n D2D_MEASURETEXT=25,\r\n D2D_SAVE=26,\r\n D2D_RESTORE=27,\r\n D2D_CREATERADIALGRADIENT=28,\r\n D2D_SETCOLORSTOP=29,\r\n D2D_SETFILLSTYLEGRADIENT=30,\r\n D2D_RELEASEID=31,\r\n D2D_CREATELINEARGRADIENT=32,\r\n D2D_SETFILLSTYLE=33,\r\n D2D_SETSTROKESTYLE=34\r\n\r\n}\r\n\r\nexport type TCanvasProxyParams = [ICanvasProps, SharedArrayBuffer, SharedArrayBuffer];\r\n\r\nexport interface ICanvas {\r\n props: ICanvasProps,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TCanvasProxyParams,\r\n drawSeq: (ds:number)=>void,\r\n }\r\n \r\nexport class twrCanvas implements ICanvas {\r\n ctx:CanvasRenderingContext2D|undefined;\r\n props:ICanvasProps={charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight:0, canvasWidth:0};\r\n owner: twrWasmModuleBase;\r\n cmdCompleteSignal?:twrSignal;\r\n canvasKeys?: twrSharedCircularBuffer;\r\n precomputedObjects: { [index: number]: \r\n (ImageData | {mem8:Uint8Array, width:number, height:number}) |\r\n CanvasGradient\r\n };\r\n\r\n constructor(element:HTMLCanvasElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n const {forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas} = modParams; \r\n this.owner=modbase;\r\n this.props.widthInChars=modParams.windim[0];\r\n this.props.heightInChars=modParams.windim[1];\r\n\r\n if (!this.owner.isWasmModule) {\r\n this.cmdCompleteSignal=new twrSignal();\r\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n }\r\n\r\n this.precomputedObjects={};\r\n \r\n if (element) {\r\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\r\n let c=element.getContext(\"2d\");\r\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\r\n\r\n c.font = fontsize.toString()+\"px Courier New\";\r\n c.textBaseline=\"top\";\r\n const sampleText=\" \";\r\n const tm=c.measureText(sampleText);\r\n this.props.charWidth=Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\r\n let fM = c.measureText(\"X\"); \r\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\r\n\r\n if (!isd2dcanvas) {\r\n element.width=this.props.charWidth*this.props.widthInChars;\r\n element.height=this.props.charHeight*this.props.heightInChars;\r\n }\r\n\r\n this.props.canvasHeight=element.height;\r\n this.props.canvasWidth=element.width;\r\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\r\n\r\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\r\n let c2=element.getContext(\"2d\");\r\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\r\n this.ctx=c2;\r\n this.ctx.font = fontsize.toString()+\"px Courier New\";\r\n this.ctx.textBaseline=\"top\";\r\n\r\n c2.fillStyle=backcolor;\r\n this.props.backColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n c2.fillStyle=forecolor;\r\n this.props.foreColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n }\r\n\r\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\r\n\r\n //console.log(\"twrCanvas.constructor props: \", this.props);\r\n }\r\n\r\n isValid() {\r\n return !!this.ctx;\r\n }\r\n\r\n getProxyParams() : TCanvasProxyParams {\r\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\r\n }\r\n\r\n getProp(pn:number): number {\r\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n\r\n/* see draw2d.h for structs that match */\r\n\r\n drawSeq(ds:number) {\r\n //console.log(\"twr::Canvas enter drawSeq\");\r\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\r\n if (!this.ctx) return;\r\n\r\n let ins=this.owner.getLong(ds); /* ds->start */\r\n const lastins=this.owner.getLong(ds+4); /* ds->last */\r\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\r\n\r\n let next:number;\r\n //let insCount=0;\r\n\r\n while (1) {\r\n\r\n //insCount++;\r\n\r\n const type:D2DType=this.owner.getLong(ins+4); /* hdr->type */\r\n if (0/*type!=D2DType.D2D_FILLRECT*/) {\r\n console.log(\"ins\",ins)\r\n console.log(\"hdr.next\",this.owner.mem8[ins],this.owner.mem8[ins+1],this.owner.mem8[ins+2],this.owner.mem8[ins+3]);\r\n console.log(\"hdr.type\",this.owner.mem8[ins+4],this.owner.mem8[ins+5]);\r\n console.log(\"next 4 bytes\", this.owner.mem8[ins+6],this.owner.mem8[ins+7],this.owner.mem8[ins+8],this.owner.mem8[ins+9]);\r\n console.log(\"and 4 more \", this.owner.mem8[ins+10],this.owner.mem8[ins+11],this.owner.mem8[ins+12],this.owner.mem8[ins+13]);\r\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\r\n }\r\n switch (type) {\r\n case D2DType.D2D_FILLRECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.fillRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKERECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.strokeRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILLCHAR:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const c=this.owner.getShort(ins+24);\r\n let txt=String.fromCharCode(c);\r\n this.ctx.fillText(txt, x, y);\r\n }\r\n break;\r\n\r\n \r\n case D2DType.D2D_FILLTEXT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const str=this.owner.getString(this.owner.getLong(ins+24));\r\n\r\n //console.log(\"filltext \",x,y,str)\r\n \r\n this.ctx.fillText(str, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MEASURETEXT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n const tmidx=this.owner.getLong(ins+12);\r\n \r\n const tm=this.ctx.measureText(str);\r\n this.owner.setDouble(tmidx+0, tm.actualBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+8, tm.actualBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+16, tm.actualBoundingBoxLeft);\r\n this.owner.setDouble(tmidx+24, tm.actualBoundingBoxRight);\r\n this.owner.setDouble(tmidx+32, tm.fontBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+40, tm.fontBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+48, tm.width);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFONT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.font=str;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.fillStyle = cssColor;\r\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETSTROKESTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.fillStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETSTROKESTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETLINEWIDTH:\r\n {\r\n const width=this.owner.getShort(ins+8); \r\n this.ctx.lineWidth=width;\r\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MOVETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.moveTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_LINETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.lineTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEZIERTO:\r\n {\r\n const cp1x=this.owner.getDouble(ins+8);\r\n const cp1y=this.owner.getDouble(ins+16);\r\n const cp2x=this.owner.getDouble(ins+24);\r\n const cp2y=this.owner.getDouble(ins+32);\r\n const x=this.owner.getDouble(ins+40);\r\n const y=this.owner.getDouble(ins+48);\r\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEGINPATH:\r\n {\r\n this.ctx.beginPath();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILL:\r\n {\r\n this.ctx.fill();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SAVE:\r\n {\r\n this.ctx.save();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_RESTORE:\r\n {\r\n this.ctx.restore();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKE:\r\n {\r\n this.ctx.stroke();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_ARC:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const radius=this.owner.getDouble(ins+24);\r\n const startAngle=this.owner.getDouble(ins+32);\r\n const endAngle=this.owner.getDouble(ins+40);\r\n const counterClockwise= (this.owner.getLong(ins+48)!=0);\r\n\r\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_IMAGEDATA:\r\n {\r\n const start=this.owner.getLong(ins+8);\r\n const length=this.owner.getLong(ins+12);\r\n const width=this.owner.getLong(ins+16);\r\n const height=this.owner.getLong(ins+20);\r\n const id=this.owner.getLong(ins+24);\r\n\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\r\n\r\n if (this.owner.isWasmModule) {\r\n const z = new Uint8ClampedArray(this.owner.memory!.buffer, start, length);\r\n this.precomputedObjects[id]=new ImageData(z, width, height);\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory\r\n this.precomputedObjects[id]={mem8: new Uint8Array(this.owner.memory!.buffer, start, length), width:width, height:height};\r\n }\r\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_CREATERADIALGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const radius0=this.owner.getDouble(ins+24);\r\n const x1=this.owner.getDouble(ins+32);\r\n const y1=this.owner.getDouble(ins+40);\r\n const radius1=this.owner.getDouble(ins+48);\r\n const id= this.owner.getLong(ins+56);\r\n\r\n let gradient=this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_CREATELINEARGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const x1=this.owner.getDouble(ins+24);\r\n const y1=this.owner.getDouble(ins+32);\r\n const id= this.owner.getLong(ins+40);\r\n \r\n let gradient=this.ctx.createLinearGradient(x0, y0, x1, y1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETCOLORSTOP:\r\n {\r\n const id = this.owner.getLong(ins+8);\r\n const pos=this.owner.getLong(ins+12);\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+16));\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n gradient.addColorStop(pos, cssColor);\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n this.ctx.fillStyle=gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_RELEASEID:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (this.precomputedObjects[id])\r\n delete this.precomputedObjects[id];\r\n else\r\n console.log(\"warning: D2D_RELEASEID with undefined ID \",id);\r\n }\r\n break\r\n\r\n \r\n\r\n case D2DType.D2D_PUTIMAGEDATA:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n const dx=this.owner.getLong(ins+12);\r\n const dy=this.owner.getLong(ins+16);\r\n const dirtyX=this.owner.getLong(ins+20);\r\n const dirtyY=this.owner.getLong(ins+24);\r\n const dirtyWidth=this.owner.getLong(ins+28);\r\n const dirtyHeight=this.owner.getLong(ins+32);\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \"+id);\r\n\r\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\r\n\r\n let imgData:ImageData;\r\n if (this.owner.isWasmModule) {\r\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\r\n imgData=this.precomputedObjects[id] as ImageData;\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\r\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\r\n const z = this.precomputedObjects[id] as {mem8:Uint8Array, width:number, height:number}; // Uint8Array\r\n const ca=Uint8ClampedArray.from(z.mem8); // shallow copy\r\n imgData=new ImageData(ca, z.width, z.height);\r\n }\r\n \r\n if (dirtyWidth==0 && dirtyHeight==0) {\r\n this.ctx.putImageData(imgData, dx, dy);\r\n }\r\n else {\r\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\r\n }\r\n }\r\n break;\r\n\r\n default:\r\n throw new Error (\"unimplemented or unknown Sequence Type in drawSeq: \"+type);\r\n }\r\n next=this.owner.getLong(ins); /* hdr->next */\r\n if (next==0) {\r\n if (ins!=lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\r\n break;\r\n }\r\n ins=next;\r\n }\r\n\r\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\r\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\r\n }\r\n}\r\n\r\nexport class twrCanvasProxy implements ICanvas {\r\n canvasKeys: twrSharedCircularBuffer;\r\n drawCompleteSignal:twrSignal;\r\n props: ICanvasProps;\r\n owner: twrWasmModuleBase;\r\n\r\n constructor(params:TCanvasProxyParams, owner:twrWasmModuleBase) {\r\n const [props, signalBuffer, canvasKeysBuffer] = params;\r\n this.drawCompleteSignal = new twrSignal(signalBuffer);\r\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\r\n this.props=props;\r\n this.owner=owner;\r\n\r\n //console.log(\"Create New twrCanvasProxy: \",this.props)\r\n\r\n }\r\n\r\n charIn() { \r\n //ctx.commit(); not avail in chrome\r\n \r\n //postMessage([\"debug\", 'x']);\r\n \r\n return this.canvasKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.canvasKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n getProp(pn:number): number {\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n \r\n drawSeq(ds:number) {\r\n this.drawCompleteSignal.reset();\r\n postMessage([\"drawseq\", [ds]]);\r\n this.drawCompleteSignal.wait();\r\n }\r\n}\r\n","//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst RDIDX = 256;\nconst WRIDX = 257;\nconst LEN = 256;\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\n// the first 256 array entries are the circular buffer\n// the next two are used for the read and write index\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\nexport class twrSharedCircularBuffer {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(258 * 4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[RDIDX] = 0;\n this.buf[WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[WRIDX];\n this.buf[i] = n;\n i++;\n if (i == LEN)\n i = 0;\n this.buf[WRIDX] = i;\n Atomics.notify(this.buf, WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[RDIDX] = i;\n return n;\n }\n else\n return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[RDIDX] == this.buf[WRIDX];\n }\n}\n//# sourceMappingURL=twrcircular.js.map","//\r\n// This class implements a circular buffer that the main javascript thread can write to, \r\n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\r\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \r\n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\r\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\r\n//\r\n\r\nconst RDIDX=256;\r\nconst WRIDX=257;\r\nconst LEN=256;\r\n\r\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\r\n// the first 256 array entries are the circular buffer\r\n// the next two are used for the read and write index\r\n\r\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\r\n\r\nexport class twrSharedCircularBuffer {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n \r\n\tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(258*4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[RDIDX]=0;\r\n this.buf[WRIDX]=0;\r\n\t}\r\n\r\n\twrite(n:number) {\r\n let i=this.buf[WRIDX];\r\n this.buf[i]=n;\r\n i++;\r\n if (i==LEN) i=0;\r\n this.buf[WRIDX]=i; \r\n Atomics.notify(this.buf, WRIDX); \r\n\t}\r\n\r\n\tread():number {\r\n if (!this.isEmpty()) {\r\n let i=this.buf[RDIDX];\r\n let n=this.buf[i];\r\n i++;\r\n this.buf[RDIDX]=i;\r\n return n;\r\n }\r\n\t\telse\r\n return -1;\r\n\t}\r\n\r\n readWait():number {\r\n if (this.isEmpty()) {\r\n const rdptr=this.buf[RDIDX];\r\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\r\n Atomics.wait(this.buf, WRIDX, rdptr);\r\n }\r\n return this.read();\r\n\t}\r\n\r\n isEmpty():boolean {\r\n return this.buf[RDIDX]==this.buf[WRIDX];\r\n }\r\n}\r\n","//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar twrSignalState;\n(function (twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})(twrSignalState || (twrSignalState = {}));\n;\nexport class twrSignal {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window valid\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == twrSignalState.WAITING) {\n //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\n //console.log(\"released...\");\n }\n }\n isSignaled() {\n return this.buf[0] == twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = twrSignalState.WAITING;\n }\n}\n//# sourceMappingURL=twrsignal.js.map","//\r\n// This class implements a simple signal/wait mechanism\r\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\r\n//\r\n\r\nenum twrSignalState {\r\n WAITING=0,\r\n SIGNALED=1\r\n};\r\n\r\nexport class twrSignal {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n\r\n \tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window valid\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) \r\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[0]=twrSignalState.WAITING;\r\n\t}\r\n\r\n\tsignal() {\r\n this.buf[0]=twrSignalState.SIGNALED; \r\n //console.log(\"about to signal\");\r\n Atomics.notify(this.buf, 0); \r\n\t}\r\n\r\n wait() {\r\n if (this.buf[0]==twrSignalState.WAITING) {\r\n //console.log(\"waiting...\");\r\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\r\n //console.log(\"released...\");\r\n\r\n }\r\n\t}\r\n isSignaled():boolean {\r\n return this.buf[0]==twrSignalState.SIGNALED;\r\n }\r\n\r\n reset() {\r\n this.buf[0]=twrSignalState.WAITING;\r\n }\r\n}\r\n","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nexport class twrDiv {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase) {\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\n this.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n if (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.divKeys.sharedArray];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */\n charOut(ch) {\n if (!this.div)\n return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n }\n switch (ch) {\n case 10: // newline\n case 13: // return\n if (ch == 10 && this.lastChar == 13)\n break; // detect CR LF and treat as single new line\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8: // backspace\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n case 0xE: // cursor on\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF: // cursor off\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for (let i = 0; i < str.length; i++)\n this.charOut(str.charCodeAt(i));\n }\n}\nexport class twrDivProxy {\n divKeys;\n constructor(params) {\n const [divKeysBuffer] = params;\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n charOut(ch) {\n postMessage([\"divout\", ch]);\n }\n}\n//# sourceMappingURL=twrdiv.js.map","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\r\nimport { IModParams } from \"./twrmodbase.js\";\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\";\r\n\r\nexport type TDivProxyParams = [SharedArrayBuffer];\r\n\r\nexport interface IDiv {\r\n charOut: (ds:number)=>void,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TDivProxyParams,\r\n }\r\n\r\n\r\nexport class twrDiv implements IDiv {\r\n\tdiv:HTMLDivElement|null|undefined;\r\n\tdivKeys?:twrSharedCircularBuffer;\r\n\tCURSOR=String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\r\n\tcursorOn:boolean=false;\r\n\tlastChar:number=0;\r\n\textraBR:boolean=false;\r\n\towner:twrWasmModuleBase;\r\n\r\n constructor(element:HTMLDivElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n\t\tthis.div=element;\r\n\t\tthis.owner=modbase;\r\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\r\n\t\t\tthis.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n\t\t}\r\n\r\n\t\tif (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\r\n\t\t\tthis.div.style.backgroundColor = modParams.backcolor;\r\n\t\t\tthis.div.style.color = modParams.forecolor;\r\n\t\t\tthis.div.style.font=modParams.fontsize.toString()+\"px arial\"\r\n\t\t}\r\n }\r\n\r\n\tisValid() {\r\n\t\treturn !!this.div;\r\n\t}\r\n\r\n getProxyParams() : TDivProxyParams {\r\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [ this.divKeys.sharedArray];\r\n }\r\n\r\n\r\n/* \r\n * add character to div. Supports the following control codes:\r\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\r\n * 0xE cursor on \r\n * 0x8 backspace\r\n * 0xF cursor off \r\n*/\r\n\tcharOut(ch:number) {\r\n\r\n\t\tif (!this.div) return;\r\n\r\n\t\t//console.log(\"div::charout: \", ch);\r\n\r\n\t\tif (this.extraBR) {\r\n\t\t\tthis.extraBR=false;\r\n\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -4);\r\n\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t}\r\n\r\n\t\tswitch (ch) {\r\n\t\t\tcase 10: // newline\r\n\t\t\tcase 13: // return\r\n\t\t\t\tif (ch==10 && this.lastChar==13) break; // detect CR LF and treat as single new line\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\r\n\t\t\t\tthis.extraBR=true;\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\t//element.scrollIntoView();\r\n\t\t\t\t//element.scrollTop = element.scrollHeight;\r\n\t\t\t\tlet p = this.div.getBoundingClientRect();\r\n\t\t\t\twindow.scrollTo(0, p.height+100);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 8: // backspace\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xE: // cursor on\r\n\t\t\t\tif (!this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=true;\r\n\t\t\t\t\tthis.div.innerHTML += this.CURSOR;\r\n\t\t\t\t\tthis.div.focus();\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xF: // cursor off\r\n\t\t\t\tif (this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=false;\r\n\t\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += String.fromCharCode(ch);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\tthis.lastChar=ch;\r\n\t}\r\n\r\n\tstringOut(str:string) {\r\n\t\tfor (let i=0; i < str.length; i++)\r\n\t\t\tthis.charOut(str.charCodeAt(i));\r\n\t}\r\n}\r\n\r\n\r\nexport class twrDivProxy implements IDiv {\r\n divKeys: twrSharedCircularBuffer;\r\n\r\n constructor(params:TDivProxyParams) {\r\n const [divKeysBuffer] = params;\r\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\r\n }\r\n\r\n charIn() { \r\n return this.divKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.divKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n\tcharOut(ch:number) {\r\n\t\tpostMessage([\"divout\", ch]);\r\n\t}\r\n}\r\n\r\n","let logline = \"\";\nexport function twrDebugLogImpl(char) {\n if (char == 10 || char == 3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\n console.log(logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n logline = \"\";\n }\n else {\n logline = logline + String.fromCharCode(char);\n if (logline.length >= 200) {\n console.log(logline);\n logline = \"\";\n }\n }\n}\n// ************************************************************************\n// debugLog doesn't currently wait for the message to log, it returns immediately.\n// I could move this to be in the twrWaitingCalls class\nexport function twrDebugLogProxy(ch) {\n postMessage([\"debug\", ch]);\n}\n//# sourceMappingURL=twrdebug.js.map","\r\nlet logline=\"\";\r\nexport function twrDebugLogImpl(char:number) {\r\n\tif (char==10 || char==3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\r\n\t\tconsole.log(logline);\t// ideally without a linefeed, but there is no way to not have a LF with console.log API.\r\n\t\tlogline=\"\";\r\n\t}\r\n\telse {\r\n\t\tlogline=logline+String.fromCharCode(char);\r\n\t\tif (logline.length>=200) {\r\n\t\t\tconsole.log(logline);\r\n\t\t\tlogline=\"\";\r\n\t\t}\r\n\t}\r\n}\r\n\r\n// ************************************************************************\r\n// debugLog doesn't currently wait for the message to log, it returns immediately.\r\n// I could move this to be in the twrWaitingCalls class\r\nexport function twrDebugLogProxy(ch:number) {\r\n postMessage([\"debug\", ch]);\r\n}\r\n\r\n","import { twrFloatUtil } from \"./twrfloat.js\";\n/*********************************************************************/\n/*********************************************************************/\n/*********************************************************************/\nexport class twrWasmModuleBase {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\n floatUtil;\n constructor(isWasmModule = false) {\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new twrFloatUtil(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/\n /*********************************************************************/\n async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n }\n catch (err) {\n console.log('loadWasm() failed to fetch: ' + pathToLoad);\n throw err;\n }\n if (!response.ok)\n throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, { env: allimports });\n this.exports = instance.instance.exports;\n if (!this.exports)\n throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory)\n throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory)\n throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer)\n console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\"setmemory\", this.memory]);\n }\n if (this.isWasmModule) {\n // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (!(this.memory.buffer instanceof ArrayBuffer))\n console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size) => {\n return new Promise(resolve => {\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n }\n catch (err) {\n console.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch (this.modParams.stdio) {\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* executeC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */\n async executeC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.executeCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async executeCImpl(fname, cparams = []) {\n if (!this.exports)\n throw new Error(\"this.exports undefined\");\n if (!this.exports[fname])\n throw new Error(\"executeC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array))\n throw new Error(\"executeC: params must be array, first arg is function name\");\n if (params.length == 0)\n throw new Error(\"executeC: missing function name\");\n let cparams = [];\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n cparams[ci++] = p;\n break;\n case 'string':\n cparams[ci++] = await this.putString(p);\n break;\n case 'object':\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n }\n else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"executeC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n ci++;\n break;\n case 'string':\n this.executeCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n case 'object':\n if (p instanceof URL) {\n this.executeCImpl('twr_free', [cparams[ci]]);\n ci = ci + 2;\n break;\n }\n else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for (let j = 0; j < u8.length; j++)\n u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.executeCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n }\n else\n throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/\n /*********************************************************************/\n // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for (i = 0; i < sin.length && i < buffer_size - 1; i++)\n this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for (let i = 0; i < u8a.length; i++)\n this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === 'object' && fnin instanceof URL))\n throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [dest, src.length];\n }\n catch (err) {\n console.log('fetchAndPutURL Error. URL: ' + fnin + '\\n' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while (this.mem8[strIndex + i] && (len === undefined ? true : i < len) && (strIndex + i) < this.mem8.length) {\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0)\n throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array((this.mem8.slice(dataptr, dataptr + size)).buffer);\n return u32;\n }\n}\n//# sourceMappingURL=twrmodbase.js.map","\r\nimport {TCanvasProxyParams} from \"./twrcanvas.js\"\r\nimport {TDivProxyParams} from \"./twrdiv.js\";\r\nimport {TWaitingCallsProxyParams} from \"./twrwaitingcalls.js\"\r\nimport {twrDebugLogImpl} from \"./twrdebug.js\";\r\nimport {twrFloatUtil} from \"./twrfloat.js\";\r\n\r\n\r\nexport type TStdioVals=\"div\"|\"canvas\"|\"null\"|\"debug\";\r\n\r\nexport interface IModOpts {\r\n\tstdio?:TStdioVals, \r\n\twindim?:[number, number],\r\n\tforecolor?:string,\r\n\tbackcolor?:string,\r\n\tfontsize?:number,\r\n\tisd2dcanvas?:boolean,\r\n\timports?:{},\r\n}\r\n\r\nexport interface IModParams {\r\n\tstdio:TStdioVals, \r\n\twindim:[number, number],\r\n\tforecolor:string,\r\n\tbackcolor:string,\r\n\tfontsize:number,\r\n\tstyleIsDefault: boolean\r\n\tisd2dcanvas:boolean,\r\n\timports:{[index:string]:Function},\r\n}\r\n\r\nexport interface IModInWorkerParams {\r\n\tdivProxyParams:TDivProxyParams,\r\n\tcanvasProxyParams:TCanvasProxyParams,\r\n\twaitingCallsProxyParams:TWaitingCallsProxyParams,\r\n}\r\n\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n\r\nexport abstract class twrWasmModuleBase {\r\n\tmemory?:WebAssembly.Memory;\r\n\tmem8:Uint8Array;\r\n\tmem32:Uint32Array;\r\n\tmemD:Float64Array;\r\n\tabstract malloc:(size:number)=>Promise;\r\n\tabstract modParams:IModParams;\r\n\texports?:WebAssembly.Exports;\r\n\tisWorker=false;\r\n\tisWasmModule:boolean; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\r\n\tfloatUtil:twrFloatUtil;\r\n\r\n\tconstructor(isWasmModule=false) {\r\n\t\tthis.isWasmModule=isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\r\n\t\tthis.mem8=new Uint8Array(); \t// avoid type errors\r\n\t\tthis.mem32=new Uint32Array(); // avoid type errors\r\n\t\tthis.memD=new Float64Array(); // avoid type errors\r\n\t\tthis.floatUtil=new twrFloatUtil(this);\r\n\t\t//console.log(\"size of mem8 after constructor\",this.mem8.length);\r\n\t}\r\n\r\n\t/*********************************************************************/\r\n\t/*********************************************************************/\r\n\r\n\tasync loadWasm(pathToLoad:string) {\r\n\t\t//console.log(\"fileToLoad\",fileToLoad)\r\n\r\n\t\tlet response;\r\n\t\ttry {\r\n\t\t\tresponse=await fetch(pathToLoad);\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('loadWasm() failed to fetch: '+pathToLoad);\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t\t\r\n\t\tif (!response.ok) throw new Error(\"fetch response error on file '\"+pathToLoad+\"'\\n\"+response.statusText);\r\n\r\n\t\ttry {\r\n\t\t\tlet wasmBytes = await response.arrayBuffer();\r\n\r\n\t\t\tlet allimports:WebAssembly.ModuleImports = { \r\n\t\t\t\t...this.modParams.imports\r\n\t\t\t};\r\n\r\n\t\t\tlet instance = await WebAssembly.instantiate(wasmBytes, {env: allimports});\r\n\r\n\t\t\tthis.exports=instance.instance.exports;\r\n\t\t\tif (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\r\n\r\n\t\t\tif (this.memory) throw new Error (\"unexpected error -- this.memory already set\");\r\n\t\t\tthis.memory=this.exports.memory as WebAssembly.Memory;\r\n\t\t\tif (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\r\n\t\t\tthis.mem8 = new Uint8Array(this.memory.buffer);\r\n\t\t\tthis.mem32 = new Uint32Array(this.memory.buffer);\r\n\t\t\tthis.memD = new Float64Array(this.memory.buffer);\r\n\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\tif (this.isWorker) {\r\n\t\t\t\tif (this.memory.buffer instanceof ArrayBuffer)\r\n\t\t\t\t\tconsole.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\r\n\t\t\t\t\r\n\t\t\t\tpostMessage([\"setmemory\",this.memory]);\r\n\t\t\t}\r\n\t\t\tif (this.isWasmModule) {\r\n\t\t\t\t// here if twrWasmModule, twrWasmModuleAsync overrides this function\r\n\t\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\t\tif (!(this.memory.buffer instanceof ArrayBuffer))\r\n\t\t\t\t\tconsole.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\r\n\t\t\t}\r\n\r\n\t\t\tthis.malloc=(size:number)=>{\r\n\t\t\t\treturn new Promise(resolve => {\r\n\t\t\t\t\tconst m=this.exports!.twr_malloc as (size:number)=>number;\r\n\t\t\t\t\tresolve(m(size));\r\n\t\t\t\t});\r\n\t\t };\r\n\r\n\t\t\tthis.init();\r\n\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t}\r\n\r\n\tprivate init() {\r\n\t\t//console.log(\"loadWasm.init() enter\")\r\n\t\t\tlet p:number;\r\n\t\t\tswitch (this.modParams.stdio) {\r\n\t\t\t\tcase \"debug\":\r\n\t\t\t\t\tp=0;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"div\":\r\n\t\t\t\t\tp=1;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"canvas\":\r\n\t\t\t\t\tp=2;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"null\":\r\n\t\t\t\t\tp=3;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tp=0; // debug\r\n\t\t\t}\r\n\r\n\t\t\tconst twrInit=this.exports!.twr_wasm_init as CallableFunction;\r\n\t\t\t//console.log(\"twrInit:\",twrInit)\r\n\t\t\ttwrInit(p, this.mem8.length);\r\n\t}\r\n\r\n\t/* executeC takes an array where:\r\n\t* the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\r\n\t* and the next entries are a variable number of parameters to pass to the C function, of type\r\n\t* number - converted to int32 or float64 as appropriate\r\n\t* string - converted to a an index (ptr) into a module Memory returned via stringToMem()\r\n\t* URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\r\n\t* Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\r\n */\r\n\r\n\tasync executeC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\t\tconst cparams=await this.preCallC(params);\r\n\t\tlet retval = this.executeCImpl(params[0], cparams);\r\n\t\tthis.postCallC(cparams, params);\r\n\t\treturn retval;\r\n\t}\r\n\r\n\tasync executeCImpl(fname:string, cparams:number[]=[]) {\r\n\t\tif (!this.exports) throw new Error(\"this.exports undefined\");\r\n\t\tif (!this.exports[fname]) throw new Error(\"executeC: function '\"+fname+\"' not in export table. Use --export wasm-ld flag.\");\r\n\r\n\t\tconst f = this.exports[fname] as CallableFunction;\r\n\t\tlet cr=f(...cparams);\r\n\r\n\t\treturn cr;\r\n\t}\r\n\r\n\t// convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\r\n\tasync preCallC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tif (!(params.constructor === Array)) throw new Error (\"executeC: params must be array, first arg is function name\");\r\n\t\tif (params.length==0) throw new Error(\"executeC: missing function name\");\r\n\r\n\t\tlet cparams:number[]=[];\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tcparams[ci++]=p;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tcparams[ci++]=await this.putString(p);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tconst r=await this.fetchAndPutURL(p);\r\n\t\t\t\t\t\tcparams[ci++]=r[0]; // mem index\r\n\t\t\t\t\t\tcparams[ci++]=r[1]; // len\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tconst r=await this.putArrayBuffer(p);\r\n\t\t\t\t\t\tcparams[ci++]=r; // mem index\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tthrow new Error (\"executeC: invalid object type passed in\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn cparams;\r\n\t}\r\n\r\n\t// free the mallocs; copy array buffer data from malloc back to arraybuffer\r\n\tasync postCallC(cparams:number[], params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tthis.executeCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t\t\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tthis.executeCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\t\tci=ci+2;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tlet u8=new Uint8Array(p);\r\n\t\t\t\t\t\tfor (let j=0; j= this.mem32.length) throw new Error(\"invalid index passed to getLong: \"+idx+\", this.mem32.length: \"+this.mem32.length);\r\n\t\tconst long:number = this.mem32[idx32];\r\n\t\treturn long;\r\n\t}\r\n\t\r\n\tsetLong(idx:number, value:number) {\r\n const idx32 = Math.floor(idx / 4);\r\n if (idx32 * 4 != idx)\r\n throw new Error(\"setLong passed non long aligned address\");\r\n if (idx32 < 0 || idx32 >= this.mem32.length)\r\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\r\n this.mem32[idx32]=value;\r\n }\r\n\r\n\tgetDouble(idx:number): number {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"getLong passed non Float64 aligned address\")\r\n\t\tconst long:number = this.memD[idx64];\r\n\t\treturn long;\r\n\t}\r\n\r\n\tsetDouble(idx:number, value:number) {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"setDouble passed non Float64 aligned address\")\r\n\t\tthis.memD[idx64]=value;\r\n\t}\r\n\r\n\tgetShort(idx:number): number {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getShort: \"+idx);\r\n\t\tconst short:number = this.mem8[idx]+this.mem8[idx+1]*256;\r\n\t\treturn short;\r\n\t}\r\n\r\n\t// get a string out of module memory\r\n\t// null terminated, up until max of (optional) len\r\n\tgetString(strIndex:number, len?:number): string {\r\n\t\tlet sout=\"\";\r\n\r\n\t\tlet i=0;\r\n\t\twhile (this.mem8[strIndex+i] && (len===undefined?true:i= this.mem8.length) throw new Error(\"invalid index passed to getU8: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU8\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU8\")\r\n\r\n\t\tconst u8=this.mem8.slice(dataptr, dataptr+size);\r\n\t\treturn u8;\r\n\t}\r\n\r\n\t// get a int32 array out of module memory when passed in index to [size, dataptr]\r\n\tgetU32Arr(idx:number): Uint32Array {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getU32: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU32\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU32\")\r\n\r\n\t\tif (size%4!=0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\r\n\r\n\t\tconst u32 = new Uint32Array( (this.mem8.slice(dataptr, dataptr+size)).buffer );\r\n\t\treturn u32;\r\n\t}\r\n}\r\n","export class twrFloatUtil {\n mod;\n constructor(mod) {\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\")\n return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\")\n return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll('D', 'e').replaceAll('d', 'e'));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n }\n else {\n let r = value.toString();\n if (r.length > max_precision)\n r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, // char *\n sizeInBytes, //size_t\n value, // double\n fracpart_numdigits, //int\n dec, // int *\n sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1)\n return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) { /* nan */\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (!Number.isFinite(value)) { /* infinity */\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n }\n else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split('.');\n if (intPart == \"0\")\n intPart = \"\";\n if (intPart.length > 0) { // has integer part\n decpos = intPart.length;\n digits = intPart + fracPart;\n }\n else { // only a fraction\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length)\n return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */\n }\n}\n//# sourceMappingURL=twrfloat.js.map","\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\"\r\n\r\nexport class twrFloatUtil {\r\n mod: twrWasmModuleBase;\r\n\r\n constructor(mod: twrWasmModuleBase) {\r\n this.mod=mod;\r\n }\r\n\r\n atod(strptr:number):number {\r\n const str=this.mod.getString(strptr);\r\n\r\n const upper=str.trimStart().toUpperCase();\r\n if (upper==\"INF\" || upper==\"+INF\")\r\n return Number.POSITIVE_INFINITY;\r\n else if (upper==\"-INF\")\r\n return Number.NEGATIVE_INFINITY\r\n else {\r\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\r\n const r=Number.parseFloat(str.replaceAll('D','e').replaceAll('d','e'));\r\n return r;\r\n }\r\n }\r\n\r\n dtoa(buffer:number, buffer_size:number, value:number, max_precision:number):void {\r\n if (max_precision==-1) {\r\n const r=value.toString();\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n else {\r\n let r=value.toString();\r\n if (r.length>max_precision)\r\n r=value.toPrecision(max_precision);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n }\r\n\r\n toFixed(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toFixed(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n toExponential(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toExponential(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\r\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\r\n // Negative exponents must be now smaller than 1e-99\r\n // fully-function C version also int he source, but this is the version enabled by default\r\n fcvtS(\r\n buffer:number, // char *\r\n sizeInBytes:number, //size_t\r\n value:number, // double\r\n fracpart_numdigits:number, //int\r\n dec:number, // int *\r\n sign:number // int *\r\n ):number {\r\n\r\n if (buffer==0 ||sign==0 || dec==0 || sizeInBytes<1) return 1;\r\n\r\n let digits:string;\r\n let decpos:number;\r\n let s=0; // default to positive\r\n\r\n\r\n if (Number.isNaN(value)) { /* nan */\r\n digits=\"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (!Number.isFinite(value)) { /* infinity */\r\n digits=\"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (value==0) { \r\n digits=\"000000000000000000000000000000000000\".slice(0,fracpart_numdigits);\r\n decpos=0;\r\n }\r\n \r\n else {\r\n\r\n if (value<0) {\r\n s=1; // negative\r\n value=Math.abs(value);\r\n }\r\n\r\n if (fracpart_numdigits>100 || value > 1e+21 || value < 1e-99) { \r\n this.mod.copyString(buffer, sizeInBytes, \"\");\r\n this.mod.mem32[dec]=0;\r\n return 1;\r\n }\r\n\r\n const roundValStr=value.toFixed(fracpart_numdigits);\r\n let [intPart=\"\", fracPart=\"\"] = roundValStr.split('.');\r\n if (intPart==\"0\") intPart=\"\";\r\n\r\n if (intPart.length>0) { // has integer part\r\n decpos=intPart.length;\r\n digits=intPart+fracPart;\r\n }\r\n else { // only a fraction\r\n digits=fracPart.replace(/^0+/,\"\"); // remove leading zeros\r\n decpos=digits.length-fracPart.length;\r\n }\r\n }\r\n\r\n if (sizeInBytes-1 < digits.length) return 1; \r\n this.mod.copyString(buffer, sizeInBytes, digits);\r\n this.mod.setLong(dec, decpos);\r\n this.mod.setLong(sign, s);\r\n\r\n return 0;\r\n\r\n /*\r\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\r\n\r\n let decpos=0;\r\n let digits:string;\r\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\r\n \r\n if (decpos>0) { // has integer part\r\n const intlen=Math.max(decpos, 0);\r\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\r\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\r\n }\r\n else { // only a fraction\r\n const intpart=Math.trunc(value);\r\n const fracpart=value-intpart;\r\n const prec=fracpart_numdigits- (-decpos);\r\n console.log(\"prec=\",prec);\r\n if (prec<1) {\r\n digits=\"\";\r\n }\r\n else {\r\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\");\r\n }\r\n }\r\n\r\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\r\n console.log('digits=',digits);\r\n console.log('dec=',decpos);\r\n console.log(\"sign=\",s);\r\n */\r\n\r\n\r\n }\r\n}","import { twrSignal } from \"./twrsignal.js\";\nimport { twrTimeImpl } from \"./twrdate.js\";\n// This class is used in the Main JS thread \nexport class twrWaitingCalls {\n callCompleteSignal;\n parameters;\n constructor() {\n this.callCompleteSignal = new twrSignal();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(() => {\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = twrTimeImpl();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [this.callCompleteSignal.sharedArray, this.parameters.buffer];\n }\n processMessage(msgType, data) {\n switch (msgType) {\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\n// This class is used in the worker thread \nexport class twrWaitingCallsProxy {\n callCompleteSignal;\n parameters;\n constructor(params) {\n this.callCompleteSignal = new twrSignal(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\"sleep\", [ms]]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\"time\"]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n//# sourceMappingURL=twrwaitingcalls.js.map","import { twrSignal } from \"./twrsignal.js\";\r\nimport {twrTimeImpl} from \"./twrdate.js\"\r\n\r\n// These classes are used to proxy a call across the worker thread - main thread boundary and wait for the result\r\n\r\nexport type TWaitingCallsProxyParams = [SharedArrayBuffer, SharedArrayBuffer]; // twrSignal, parameters \r\n\r\n// This class is used in the Main JS thread \r\nexport class twrWaitingCalls {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor() {\r\n\t\tthis.callCompleteSignal=new twrSignal();\r\n\t\tthis.parameters=new Uint32Array(new SharedArrayBuffer(4));\r\n\t}\r\n\r\n\tprivate startSleep(ms:number) {\r\n\r\n\t\tsetTimeout(()=>{\r\n\t\t\tthis.callCompleteSignal.signal();\r\n\t\t}, ms);\r\n\t\t\r\n\t}\r\n\r\n\tprivate time() {\r\n\t\tconst ms=twrTimeImpl();\r\n\t\tthis.parameters[0]=ms;\r\n\t\tthis.callCompleteSignal.signal();\r\n\t}\r\n\r\n\tgetProxyParams():TWaitingCallsProxyParams {\r\n\t\treturn [this.callCompleteSignal.sharedArray, this.parameters.buffer as SharedArrayBuffer];\t\r\n\t}\r\n\r\n\tprocessMessage(msgType:string, data:any[]):boolean {\r\n\t\tswitch (msgType) {\r\n\t\t\tcase \"sleep\":\r\n\t\t\t\tconst [ms] = data;\r\n\t\t\t\tthis.startSleep(ms);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"time\":\r\n\t\t\t\tthis.time();\r\n\t\t\t\tbreak;\r\n\t\t\t\r\n\t\t\tdefault:\r\n\t\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\treturn true;\r\n\t}\r\n\r\n}\r\n\r\n// This class is used in the worker thread \r\nexport class twrWaitingCallsProxy {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor(params:TWaitingCallsProxyParams) {\r\n\t\tthis.callCompleteSignal=new twrSignal(params[0]);\r\n\t\tthis.parameters=new Uint32Array(params[1]);\r\n\t}\r\n\r\n\tsleep(ms:number) {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"sleep\", [ms]]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t}\r\n\r\n\ttime() {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"time\"]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t\treturn this.parameters[0];\r\n\t}\r\n\r\n}\r\n","export function twrTimeImpl() {\n return Date.now();\n}\n//# sourceMappingURL=twrdate.js.map","\r\nexport function twrTimeImpl() {\r\n\r\n return Date.now();\r\n\r\n}"],"names":["$b93f1fdf40141def$var$twrSignalState","$c4741cac81d14197$var$D2DType","twrSignalState","D2DType","$3e39efa823870787$var$mod","$892fccfc812d5e20$export$a01cca24f011573a","sharedArray","buf","constructor","sa","window","crossOriginIsolated","location","protocol","Error","SharedArrayBuffer","Int32Array","write","n","i","Atomics","notify","read","isEmpty","readWait","rdptr","wait","$b93f1fdf40141def$export$e37a7b7b851b97f3","WAITING","signal","SIGNALED","isSignaled","reset","$c4741cac81d14197$export$c779b2cd00544976","canvasKeys","drawCompleteSignal","props","owner","params","signalBuffer","canvasKeysBuffer","charIn","inkey","getProp","pn","propName","getString","drawSeq","ds","postMessage","$8963973702ae5462$export$b377f0bbf2c7581e","divKeys","divKeysBuffer","charOut","ch","$8ac0b786da854328$export$485af4d0039b3389","$e72303a1db04bdfa$export$918ffb7e046a537b","mod","atod","strptr","str","upper","trimStart","toUpperCase","Number","POSITIVE_INFINITY","NEGATIVE_INFINITY","parseFloat","replaceAll","dtoa","buffer","buffer_size","value","max_precision","r","toString","copyString","length","toPrecision","toFixed","decdigits","toExponential","fcvtS","sizeInBytes","fracpart_numdigits","dec","sign","digits","decpos","s","isNaN","slice","isFinite","Math","abs","mem32","intPart","fracPart","roundValStr","split","replace","setLong","$ece7fa3ed770778a$export$c83a0a3bffe07399","memory","mem8","memD","exports","isWorker","isWasmModule","floatUtil","Uint8Array","Uint32Array","Float64Array","loadWasm","pathToLoad","response","fetch","err","console","log","ok","statusText","wasmBytes","arrayBuffer","allimports","modParams","imports","instance","WebAssembly","instantiate","env","ArrayBuffer","malloc","size","Promise","resolve","m","twr_malloc","init","stack","p","stdio","twrInit","twr_wasm_init","executeC","cparams","preCallC","retval","executeCImpl","postCallC","fname","f","Array","ci","putString","URL","fetchAndPutURL","putArrayBuffer","u8","j","sin","charCodeAt","strIndex","putU8","u8a","dest","ab","fnin","src","getLong","idx","idx32","floor","getDouble","idx64","setDouble","getShort","len","sout","undefined","String","fromCharCode","getU8Arr","rv","dataptr","getU32Arr","$aff9c2c494d23fe3$export$78d2a4633fe89379","callCompleteSignal","parameters","sleep","ms","time","onmessage","e","data","$3e39efa823870787$var$twrWasmModuleInWorker","modWorkerParams","urlToLoad","then","catch","ex","rc","modInWorkerParams","canvasProxy","canvasProxyParams","divProxy","divProxyParams","waitingCallsProxy","waitingCallsProxyParams","twrDebugLog","twrSleep","bind","twrTime","twrDivCharOut","twrDivCharIn","twrCanvasCharIn","twrCanvasInkey","twrCanvasGetProp","twrCanvasDrawSeq","twrSin","twrCos","cos","twrTan","tan","twrFAbs","twrACos","acos","twrASin","asin","twrATan","atan","twrExp","exp","twrFloor","twrCeil","ceil","twrFMod","x","y","twrLog","twrPow","pow","twrSqrt","sqrt","twrTrunc","trunc","twrDtoa","twrToFixed","twrToExponential","twrAtod","twrFcvtS"],"version":3,"file":"twrmodworker.2165e649.js.map"} \ No newline at end of file +{"mappings":"A,C,SQKK,EJgBA,EIhBA,EJgBA,MFZD,CISE,OAAO,EACZ,WAA8B,AAC9B,CAAA,GAAe,AAEf,aAAa,CAAqB,CAAlC,CACO,GAAI,AAAkB,aAAlB,OAAO,QACH,CAAC,qBAAuB,AAA+B,UAA7B,OAAO,QAAQ,CAAC,QAAQ,CAAe,MAAM,AAAI,MAAM,4DAA4D,oBAAoB,iCAErK,EAAI,IAAI,CAAC,WAAW,CAAC,EACpB,IAAI,CAAC,WAAW,CAAC,IAAI,kBAAkB,MAClD,IAAI,CAAC,GAAG,CAAC,IAAI,WAAW,IAAI,CAAC,WAAW,EAClC,IAAI,CAAC,GAAG,CArBJ,IAqBW,CAAC,EAChB,IAAI,CAAC,GAAG,CArBJ,IAqBW,CAAC,CACvB,CAEA,MAAM,CAAQ,CAAd,CACO,IAAI,EAAE,IAAI,CAAC,GAAG,CAzBV,IAyBiB,AACrB,CAAA,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAzBV,OA2BE,GAAQ,CAAA,EAAE,CAAA,EACd,IAAI,CAAC,GAAG,CA7BJ,IA6BW,CAAC,EAChB,QAAQ,MAAM,CAAC,IAAI,CAAC,GAAG,CA9BnB,IA+BX,CAEA,MAAA,CACO,GAAK,IAAI,CAAC,OAAO,GAQb,OAAO,EARU,EACjB,IAAI,EAAE,IAAI,CAAC,GAAG,CApCd,IAoCqB,CACjB,EAAE,IAAI,CAAC,GAAG,CAAC,E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M,CAAC,IAAI,CAAC,GAElC,gBAAgB,EAAY,MAAM,CAAC,IAAI,CAAC,GACxC,eAAe,EAAY,KAAK,CAAC,IAAI,CAAC,GACtC,iBAAiB,EAAY,OAAO,CAAC,IAAI,CAAC,GAC1C,iBAAiB,EAAY,OAAO,CAAC,IAAI,CAAC,GAEnD,OAAO,KAAK,GAAG,CACf,OAAO,KAAK,GAAG,CACf,OAAQ,KAAK,GAAG,CAChB,QAAS,KAAK,GAAG,CACjB,QAAS,KAAK,IAAI,CAClB,QAAS,KAAK,IAAI,CAClB,QAAS,KAAK,IAAI,CAClB,OAAQ,KAAK,GAAG,CAChB,SAAU,KAAK,KAAK,CACpB,QAAS,KAAK,IAAI,CAClB,QAAS,SAAS,CAAQ,CAAE,CAAQ,EAAG,OAAO,EAAE,CAAC,EACjD,OAAQ,KAAK,GAAG,CAChB,OAAQ,KAAK,GAAG,CAChB,QAAS,KAAK,IAAI,CAClB,SAAU,KAAK,KAAK,CAEX,QAAS,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EACzD,WAAY,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EACtD,iBAAkB,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAClE,QAAS,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAChD,SAAU,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAE5C,CACN,CACF,C,C","sources":["","../../lib-js/twrmodworker.js","../../source/twr-wasm-ts/twrmodworker.ts","../../lib-js/twrcanvas.js","../../source/twr-wasm-ts/twrcanvas.ts","../../lib-js/twrcircular.js","../../source/twr-wasm-ts/twrcircular.ts","../../lib-js/twrsignal.js","../../source/twr-wasm-ts/twrsignal.ts","../../lib-js/twrdiv.js","../../source/twr-wasm-ts/twrdiv.ts","../../lib-js/twrdebug.js","../../source/twr-wasm-ts/twrdebug.ts","../../lib-js/twrmodbase.js","../../source/twr-wasm-ts/twrmodbase.ts","../../lib-js/twrfloat.js","../../source/twr-wasm-ts/twrfloat.ts","../../lib-js/twrwaitingcalls.js","../../source/twr-wasm-ts/twrwaitingcalls.ts","../../lib-js/twrdate.js","../../source/twr-wasm-ts/twrdate.ts"],"sourcesContent":["(() => {\nvar $3e39efa823870787$exports = {};\n// this script is the WebWorker thead used by class twrWasmAsyncModule\n//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst $892fccfc812d5e20$var$RDIDX = 256;\nconst $892fccfc812d5e20$var$WRIDX = 257;\nconst $892fccfc812d5e20$var$LEN = 256;\nclass $892fccfc812d5e20$export$a01cca24f011573a {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(1032);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[$892fccfc812d5e20$var$RDIDX] = 0;\n this.buf[$892fccfc812d5e20$var$WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[$892fccfc812d5e20$var$WRIDX];\n this.buf[i] = n;\n i++;\n if (i == $892fccfc812d5e20$var$LEN) i = 0;\n this.buf[$892fccfc812d5e20$var$WRIDX] = i;\n Atomics.notify(this.buf, $892fccfc812d5e20$var$WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[$892fccfc812d5e20$var$RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[$892fccfc812d5e20$var$RDIDX] = i;\n return n;\n } else return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[$892fccfc812d5e20$var$RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, $892fccfc812d5e20$var$WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[$892fccfc812d5e20$var$RDIDX] == this.buf[$892fccfc812d5e20$var$WRIDX];\n }\n}\n\n\n//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar $b93f1fdf40141def$var$twrSignalState;\n(function(twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})($b93f1fdf40141def$var$twrSignalState || ($b93f1fdf40141def$var$twrSignalState = {}));\nclass $b93f1fdf40141def$export$e37a7b7b851b97f3 {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == $b93f1fdf40141def$var$twrSignalState.WAITING) //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, $b93f1fdf40141def$var$twrSignalState.WAITING);\n }\n isSignaled() {\n return this.buf[0] == $b93f1fdf40141def$var$twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.WAITING;\n }\n}\n\n\nvar $c4741cac81d14197$var$D2DType;\n(function(D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})($c4741cac81d14197$var$D2DType || ($c4741cac81d14197$var$D2DType = {}));\nclass $c4741cac81d14197$export$2f298dd69cef3c34 {\n ctx;\n props = {\n charWidth: 0,\n charHeight: 0,\n foreColor: 0,\n backColor: 0,\n widthInChars: 0,\n heightInChars: 0,\n canvasHeight: 0,\n canvasWidth: 0\n };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase){\n const { forecolor: forecolor, backcolor: backcolor, fontsize: fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)();\n this.canvasKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.props,\n this.cmdCompleteSignal.sharedArray,\n this.canvasKeys.sharedArray\n ];\n }\n getProp(pn) {\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */ drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx) return;\n let ins = this.owner.getLong(ds); /* ds->start */ \n const lastins = this.owner.getLong(ds + 4); /* ds->last */ \n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while(true){\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */ \n switch(type){\n case $c4741cac81d14197$var$D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_BEGINPATH:\n this.ctx.beginPath();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILL:\n this.ctx.fill();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SAVE:\n this.ctx.save();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_RESTORE:\n this.ctx.restore();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_STROKE:\n this.ctx.stroke();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = this.owner.getLong(ins + 48) != 0;\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n } else this.precomputedObjects[id] = {\n mem8: new Uint8Array(this.owner.memory.buffer, start, length),\n width: width,\n height: height\n };\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id]) delete this.precomputedObjects[id];\n else console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n else {\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) this.ctx.putImageData(imgData, dx, dy);\n else this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */ \n if (next == 0) {\n if (ins != lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nclass $c4741cac81d14197$export$c779b2cd00544976 {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner){\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)(signalBuffer);\n this.canvasKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\n \"drawseq\",\n [\n ds\n ]\n ]);\n this.drawCompleteSignal.wait();\n }\n}\n\n\n\nclass $8963973702ae5462$export$dd376bb3f10f6896 {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611);\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase){\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) this.divKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(); // tsconfig, lib must be set to 2017 or higher\n if (this.div && !modParams.styleIsDefault) {\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.divKeys.sharedArray\n ];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */ charOut(ch) {\n if (!this.div) return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n }\n switch(ch){\n case 10:\n case 13:\n if (ch == 10 && this.lastChar == 13) break; // detect CR LF and treat as single new line\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n case 0xE:\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF:\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for(let i = 0; i < str.length; i++)this.charOut(str.charCodeAt(i));\n }\n}\nclass $8963973702ae5462$export$b377f0bbf2c7581e {\n divKeys;\n constructor(params){\n const [divKeysBuffer] = params;\n this.divKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n charOut(ch) {\n postMessage([\n \"divout\",\n ch\n ]);\n }\n}\n\n\nlet $8ac0b786da854328$var$logline = \"\";\nfunction $8ac0b786da854328$export$16b4216ec014493d(char) {\n if (char == 10 || char == 3) {\n console.log($8ac0b786da854328$var$logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n $8ac0b786da854328$var$logline = \"\";\n } else {\n $8ac0b786da854328$var$logline = $8ac0b786da854328$var$logline + String.fromCharCode(char);\n if ($8ac0b786da854328$var$logline.length >= 200) {\n console.log($8ac0b786da854328$var$logline);\n $8ac0b786da854328$var$logline = \"\";\n }\n }\n}\nfunction $8ac0b786da854328$export$485af4d0039b3389(ch) {\n postMessage([\n \"debug\",\n ch\n ]);\n}\n\n\nclass $e72303a1db04bdfa$export$918ffb7e046a537b {\n mod;\n constructor(mod){\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\") return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\") return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll(\"D\", \"e\").replaceAll(\"d\", \"e\"));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n } else {\n let r = value.toString();\n if (r.length > max_precision) r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, sizeInBytes, value, fracpart_numdigits, dec, sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1) return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) {\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (!Number.isFinite(value)) {\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n } else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split(\".\");\n if (intPart == \"0\") intPart = \"\";\n if (intPart.length > 0) {\n decpos = intPart.length;\n digits = intPart + fracPart;\n } else {\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length) return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */ }\n}\n\n\nclass $ece7fa3ed770778a$export$c83a0a3bffe07399 {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule;\n floatUtil;\n constructor(isWasmModule = false){\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new (0, $e72303a1db04bdfa$export$918ffb7e046a537b)(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/ /*********************************************************************/ async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n } catch (err) {\n console.log(\"loadWasm() failed to fetch: \" + pathToLoad);\n throw err;\n }\n if (!response.ok) throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, {\n env: allimports\n });\n this.exports = instance.instance.exports;\n if (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory) throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer) console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\n \"setmemory\",\n this.memory\n ]);\n }\n if (this.isWasmModule) // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n {\n if (!(this.memory.buffer instanceof ArrayBuffer)) console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size)=>{\n return new Promise((resolve)=>{\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n } catch (err) {\n console.log(\"WASM instantiate error: \" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch(this.modParams.stdio){\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* callC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */ async callC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.callCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async callCImpl(fname, cparams = []) {\n if (!this.exports) throw new Error(\"this.exports undefined\");\n if (!this.exports[fname]) throw new Error(\"callC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array)) throw new Error(\"callC: params must be array, first arg is function name\");\n if (params.length == 0) throw new Error(\"callC: missing function name\");\n let cparams = [];\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n cparams[ci++] = p;\n break;\n case \"string\":\n cparams[ci++] = await this.putString(p);\n break;\n case \"object\":\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n } else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"callC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n ci++;\n break;\n case \"string\":\n this.callCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n case \"object\":\n if (p instanceof URL) {\n this.callCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci = ci + 2;\n break;\n } else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for(let j = 0; j < u8.length; j++)u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.callCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n } else throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/ /*********************************************************************/ // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for(i = 0; i < sin.length && i < buffer_size - 1; i++)this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for(let i = 0; i < u8a.length; i++)this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === \"object\" && fnin instanceof URL)) throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [\n dest,\n src.length\n ];\n } catch (err) {\n console.log(\"fetchAndPutURL Error. URL: \" + fnin + \"\\n\" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while(this.mem8[strIndex + i] && (len === undefined ? true : i < len) && strIndex + i < this.mem8.length){\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array(this.mem8.slice(dataptr, dataptr + size).buffer);\n return u32;\n }\n}\n\n\n\nfunction $4af5689abbc8d01b$export$78724cdcf7ebea1d() {\n return Date.now();\n}\n\n\nclass $aff9c2c494d23fe3$export$9e37856d1928d388 {\n callCompleteSignal;\n parameters;\n constructor(){\n this.callCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(()=>{\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = (0, $4af5689abbc8d01b$export$78724cdcf7ebea1d)();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [\n this.callCompleteSignal.sharedArray,\n this.parameters.buffer\n ];\n }\n processMessage(msgType, data) {\n switch(msgType){\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\nclass $aff9c2c494d23fe3$export$78d2a4633fe89379 {\n callCompleteSignal;\n parameters;\n constructor(params){\n this.callCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\n \"sleep\",\n [\n ms\n ]\n ]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\n \"time\"\n ]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n\n\nlet $3e39efa823870787$var$mod;\nonmessage = function(e) {\n //console.log('twrworker.js: message received from main script: '+e.data);\n if (e.data[0] == \"startup\") {\n const params = e.data[1];\n //console.log(\"Worker startup params:\",params);\n $3e39efa823870787$var$mod = new $3e39efa823870787$var$twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\n $3e39efa823870787$var$mod.loadWasm(params.urlToLoad).then(()=>{\n postMessage([\n \"startupOkay\"\n ]);\n }).catch((ex)=>{\n console.log(\".catch: \", ex);\n postMessage([\n \"startupFail\",\n ex\n ]);\n });\n } else if (e.data[0] == \"callC\") $3e39efa823870787$var$mod.callCImpl(e.data[1], e.data[2]).then((rc)=>{\n postMessage([\n \"callCOkay\",\n rc\n ]);\n }).catch((e)=>{\n console.log(\"exception in callC twrworker.js\\n\");\n console.log(e);\n postMessage([\n \"callCFail\",\n e\n ]);\n });\n else console.log(\"twrworker.js: unknown message: \" + e);\n};\n// ************************************************************************\nclass $3e39efa823870787$var$twrWasmModuleInWorker extends (0, $ece7fa3ed770778a$export$c83a0a3bffe07399) {\n malloc;\n modParams;\n constructor(modParams, modInWorkerParams){\n super();\n this.isWorker = true;\n this.malloc = (size)=>{\n throw new Error(\"error - un-init malloc called\");\n };\n this.modParams = modParams;\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\n const canvasProxy = new (0, $c4741cac81d14197$export$c779b2cd00544976)(modInWorkerParams.canvasProxyParams, this);\n const divProxy = new (0, $8963973702ae5462$export$b377f0bbf2c7581e)(modInWorkerParams.divProxyParams);\n const waitingCallsProxy = new (0, $aff9c2c494d23fe3$export$78d2a4633fe89379)(modInWorkerParams.waitingCallsProxyParams);\n this.modParams.imports = {\n twrDebugLog: (0, $8ac0b786da854328$export$485af4d0039b3389),\n twrSleep: waitingCallsProxy.sleep.bind(waitingCallsProxy),\n twrTime: waitingCallsProxy.time.bind(waitingCallsProxy),\n twrDivCharOut: divProxy.charOut.bind(divProxy),\n twrDivCharIn: divProxy.charIn.bind(divProxy),\n twrCanvasCharIn: canvasProxy.charIn.bind(canvasProxy),\n twrCanvasInkey: canvasProxy.inkey.bind(canvasProxy),\n twrCanvasGetProp: canvasProxy.getProp.bind(canvasProxy),\n twrCanvasDrawSeq: canvasProxy.drawSeq.bind(canvasProxy),\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function(x, y) {\n return x % y;\n },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n}\n\n})();\n//# sourceMappingURL=twrmodworker.2165e649.js.map\n","// this script is the WebWorker thead used by class twrWasmAsyncModule\nimport { twrCanvasProxy } from \"./twrcanvas.js\";\nimport { twrDivProxy } from \"./twrdiv.js\";\nimport { twrDebugLogProxy } from \"./twrdebug.js\";\nimport { twrWasmModuleBase } from \"./twrmodbase.js\";\nimport { twrWaitingCallsProxy } from \"./twrwaitingcalls.js\";\nlet mod;\nonmessage = function (e) {\n //console.log('twrworker.js: message received from main script: '+e.data);\n if (e.data[0] == 'startup') {\n const params = e.data[1];\n //console.log(\"Worker startup params:\",params);\n mod = new twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\n mod.loadWasm(params.urlToLoad).then(() => {\n postMessage([\"startupOkay\"]);\n }).catch((ex) => {\n console.log(\".catch: \", ex);\n postMessage([\"startupFail\", ex]);\n });\n }\n else if (e.data[0] == 'callC') {\n mod.callCImpl(e.data[1], e.data[2]).then((rc) => {\n postMessage([\"callCOkay\", rc]);\n }).catch(e => {\n console.log(\"exception in callC twrworker.js\\n\");\n console.log(e);\n postMessage([\"callCFail\", e]);\n });\n }\n else {\n console.log(\"twrworker.js: unknown message: \" + e);\n }\n};\n// ************************************************************************\nclass twrWasmModuleInWorker extends twrWasmModuleBase {\n malloc;\n modParams;\n constructor(modParams, modInWorkerParams) {\n super();\n this.isWorker = true;\n this.malloc = (size) => { throw new Error(\"error - un-init malloc called\"); };\n this.modParams = modParams;\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\n const canvasProxy = new twrCanvasProxy(modInWorkerParams.canvasProxyParams, this);\n const divProxy = new twrDivProxy(modInWorkerParams.divProxyParams);\n const waitingCallsProxy = new twrWaitingCallsProxy(modInWorkerParams.waitingCallsProxyParams);\n this.modParams.imports = {\n twrDebugLog: twrDebugLogProxy,\n twrSleep: waitingCallsProxy.sleep.bind(waitingCallsProxy),\n twrTime: waitingCallsProxy.time.bind(waitingCallsProxy),\n twrDivCharOut: divProxy.charOut.bind(divProxy),\n twrDivCharIn: divProxy.charIn.bind(divProxy),\n twrCanvasCharIn: canvasProxy.charIn.bind(canvasProxy),\n twrCanvasInkey: canvasProxy.inkey.bind(canvasProxy),\n twrCanvasGetProp: canvasProxy.getProp.bind(canvasProxy),\n twrCanvasDrawSeq: canvasProxy.drawSeq.bind(canvasProxy),\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function (x, y) { return x % y; },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n}\n//# sourceMappingURL=twrmodworker.js.map","// this script is the WebWorker thead used by class twrWasmAsyncModule\r\n\r\nimport {twrCanvasProxy} from \"./twrcanvas.js\";\r\nimport {twrDivProxy} from \"./twrdiv.js\";\r\nimport {twrDebugLogProxy} from \"./twrdebug.js\";\r\nimport {TAsyncModStartupMsg} from \"./twrmodasync.js\"\r\nimport {twrWasmModuleBase, IModInWorkerParams, IModParams} from \"./twrmodbase.js\"\r\nimport {twrWaitingCallsProxy} from \"./twrwaitingcalls.js\";\r\n\r\nlet mod:twrWasmModuleInWorker;\r\n\r\nonmessage = function(e) {\r\n //console.log('twrworker.js: message received from main script: '+e.data);\r\n\r\n if (e.data[0]=='startup') {\r\n const params:TAsyncModStartupMsg=e.data[1];\r\n //console.log(\"Worker startup params:\",params);\r\n mod=new twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\r\n\r\n mod.loadWasm(params.urlToLoad).then( ()=> {\r\n postMessage([\"startupOkay\"]);\r\n }).catch( (ex)=> {\r\n console.log(\".catch: \", ex);\r\n postMessage([\"startupFail\", ex]);\r\n });\r\n }\r\n else if (e.data[0]=='callC') {\r\n mod.callCImpl(e.data[1], e.data[2]).then( (rc)=> {\r\n postMessage([\"callCOkay\", rc]);\r\n }).catch(e => {\r\n console.log(\"exception in callC twrworker.js\\n\");\r\n console.log(e);\r\n postMessage([\"callCFail\", e]);\r\n });\r\n }\r\n else {\r\n console.log(\"twrworker.js: unknown message: \"+e);\r\n }\r\n}\r\n\r\n\r\n// ************************************************************************\r\n\r\nclass twrWasmModuleInWorker extends twrWasmModuleBase {\r\n\tmalloc:(size:number)=>Promise;\r\n modParams: IModParams;\r\n\r\n\r\n constructor(modParams:IModParams, modInWorkerParams:IModInWorkerParams) {\r\n super();\r\n this.isWorker=true;\r\n this.malloc=(size:number)=>{throw new Error(\"error - un-init malloc called\")};\r\n this.modParams=modParams;\r\n\r\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\r\n const canvasProxy = new twrCanvasProxy(modInWorkerParams.canvasProxyParams, this);\r\n const divProxy = new twrDivProxy(modInWorkerParams.divProxyParams);\r\n const waitingCallsProxy = new twrWaitingCallsProxy(modInWorkerParams.waitingCallsProxyParams);\r\n\r\n this.modParams.imports={\r\n twrDebugLog:twrDebugLogProxy,\r\n twrSleep:waitingCallsProxy.sleep.bind(waitingCallsProxy),\r\n twrTime:waitingCallsProxy.time.bind(waitingCallsProxy),\r\n\r\n twrDivCharOut:divProxy.charOut.bind(divProxy), \r\n twrDivCharIn:divProxy.charIn.bind(divProxy), \r\n\r\n twrCanvasCharIn:canvasProxy.charIn.bind(canvasProxy),\r\n twrCanvasInkey:canvasProxy.inkey.bind(canvasProxy),\r\n twrCanvasGetProp:canvasProxy.getProp.bind(canvasProxy),\r\n twrCanvasDrawSeq:canvasProxy.drawSeq.bind(canvasProxy),\r\n\r\n\t\t\ttwrSin:Math.sin,\r\n\t\t\ttwrCos:Math.cos,\r\n\t\t\ttwrTan: Math.tan,\r\n\t\t\ttwrFAbs: Math.abs,\r\n\t\t\ttwrACos: Math.acos,\r\n\t\t\ttwrASin: Math.asin,\r\n\t\t\ttwrATan: Math.atan,\r\n\t\t\ttwrExp: Math.exp,\r\n\t\t\ttwrFloor: Math.floor,\r\n\t\t\ttwrCeil: Math.ceil,\r\n\t\t\ttwrFMod: function(x:number, y:number) {return x%y},\r\n\t\t\ttwrLog: Math.log,\r\n\t\t\ttwrPow: Math.pow,\r\n\t\t\ttwrSqrt: Math.sqrt,\r\n\t\t\ttwrTrunc: Math.trunc,\r\n\r\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\r\n\t\t\ttwrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\r\n\t\t\ttwrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\r\n\t\t\ttwrAtod: this.floatUtil.atod.bind(this.floatUtil),\r\n\t\t\ttwrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\r\n \r\n }\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nimport { twrSignal } from \"./twrsignal.js\";\nvar D2DType;\n(function (D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})(D2DType || (D2DType = {}));\nexport class twrCanvas {\n ctx;\n props = { charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight: 0, canvasWidth: 0 };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase) {\n const { forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new twrSignal();\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext)\n throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c)\n throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2)\n throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\n }\n getProp(pn) {\n if (!this.isValid())\n console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */\n drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid())\n console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx)\n return;\n let ins = this.owner.getLong(ds); /* ds->start */\n const lastins = this.owner.getLong(ds + 4); /* ds->last */\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while (1) {\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */\n if (0 /*type!=D2DType.D2D_FILLRECT*/) {\n console.log(\"ins\", ins);\n console.log(\"hdr.next\", this.owner.mem8[ins], this.owner.mem8[ins + 1], this.owner.mem8[ins + 2], this.owner.mem8[ins + 3]);\n console.log(\"hdr.type\", this.owner.mem8[ins + 4], this.owner.mem8[ins + 5]);\n console.log(\"next 4 bytes\", this.owner.mem8[ins + 6], this.owner.mem8[ins + 7], this.owner.mem8[ins + 8], this.owner.mem8[ins + 9]);\n console.log(\"and 4 more \", this.owner.mem8[ins + 10], this.owner.mem8[ins + 11], this.owner.mem8[ins + 12], this.owner.mem8[ins + 13]);\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\n }\n switch (type) {\n case D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case D2DType.D2D_BEGINPATH:\n {\n this.ctx.beginPath();\n }\n break;\n case D2DType.D2D_FILL:\n {\n this.ctx.fill();\n }\n break;\n case D2DType.D2D_SAVE:\n {\n this.ctx.save();\n }\n break;\n case D2DType.D2D_RESTORE:\n {\n this.ctx.restore();\n }\n break;\n case D2DType.D2D_STROKE:\n {\n this.ctx.stroke();\n }\n break;\n case D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = (this.owner.getLong(ins + 48) != 0);\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n }\n else { // Uint8ClampedArray doesn't support shared memory\n this.precomputedObjects[id] = { mem8: new Uint8Array(this.owner.memory.buffer, start, length), width: width, height: height };\n }\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id])\n delete this.precomputedObjects[id];\n else\n console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) {\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n }\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) {\n this.ctx.putImageData(imgData, dx, dy);\n }\n else {\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */\n if (next == 0) {\n if (ins != lastins)\n throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal)\n this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nexport class twrCanvasProxy {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner) {\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new twrSignal(signalBuffer);\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\"drawseq\", [ds]]);\n this.drawCompleteSignal.wait();\n }\n}\n//# sourceMappingURL=twrcanvas.js.map","import {twrWasmModuleBase, IModParams} from \"./twrmodbase.js\"\r\nimport {twrSharedCircularBuffer} from \"./twrcircular.js\";\r\nimport {twrSignal} from \"./twrsignal.js\";\r\n\r\n\r\n// Canvas have a size that will be set based on the character width x height\r\n// The display size for a canvas will default to this size, but can be changed in the HTML/JS via\r\n// canvas.style.width = \"700px\";\r\n// canvas.style.height = \"500px\";\r\n\r\nexport interface ICanvasProps {\r\n\tcharWidth: number,\r\n\tcharHeight: number,\r\n\tforeColor: number,\r\n\tbackColor: number,\r\n widthInChars: number,\r\n heightInChars: number,\r\n canvasWidth:number,\r\n canvasHeight:number\r\n}\r\n\r\nenum D2DType {\r\n D2D_FILLRECT=1,\r\n D2D_FILLCHAR=5,\r\n D2D_SETLINEWIDTH=10,\r\n D2D_SETFILLSTYLERGBA=11,\r\n D2D_SETFONT=12,\r\n D2D_BEGINPATH=13,\r\n D2D_MOVETO=14,\r\n D2D_LINETO=15,\r\n D2D_FILL=16,\r\n D2D_STROKE=17,\r\n D2D_SETSTROKESTYLERGBA=18,\r\n D2D_ARC=19,\r\n D2D_STROKERECT=20,\r\n D2D_FILLTEXT=21,\r\n D2D_IMAGEDATA=22,\r\n D2D_PUTIMAGEDATA=23,\r\n D2D_BEZIERTO=24,\r\n D2D_MEASURETEXT=25,\r\n D2D_SAVE=26,\r\n D2D_RESTORE=27,\r\n D2D_CREATERADIALGRADIENT=28,\r\n D2D_SETCOLORSTOP=29,\r\n D2D_SETFILLSTYLEGRADIENT=30,\r\n D2D_RELEASEID=31,\r\n D2D_CREATELINEARGRADIENT=32,\r\n D2D_SETFILLSTYLE=33,\r\n D2D_SETSTROKESTYLE=34\r\n\r\n}\r\n\r\nexport type TCanvasProxyParams = [ICanvasProps, SharedArrayBuffer, SharedArrayBuffer];\r\n\r\nexport interface ICanvas {\r\n props: ICanvasProps,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TCanvasProxyParams,\r\n drawSeq: (ds:number)=>void,\r\n }\r\n \r\nexport class twrCanvas implements ICanvas {\r\n ctx:CanvasRenderingContext2D|undefined;\r\n props:ICanvasProps={charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight:0, canvasWidth:0};\r\n owner: twrWasmModuleBase;\r\n cmdCompleteSignal?:twrSignal;\r\n canvasKeys?: twrSharedCircularBuffer;\r\n precomputedObjects: { [index: number]: \r\n (ImageData | {mem8:Uint8Array, width:number, height:number}) |\r\n CanvasGradient\r\n };\r\n\r\n constructor(element:HTMLCanvasElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n const {forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas} = modParams; \r\n this.owner=modbase;\r\n this.props.widthInChars=modParams.windim[0];\r\n this.props.heightInChars=modParams.windim[1];\r\n\r\n if (!this.owner.isWasmModule) {\r\n this.cmdCompleteSignal=new twrSignal();\r\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n }\r\n\r\n this.precomputedObjects={};\r\n \r\n if (element) {\r\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\r\n let c=element.getContext(\"2d\");\r\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\r\n\r\n c.font = fontsize.toString()+\"px Courier New\";\r\n c.textBaseline=\"top\";\r\n const sampleText=\" \";\r\n const tm=c.measureText(sampleText);\r\n this.props.charWidth=Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\r\n let fM = c.measureText(\"X\"); \r\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\r\n\r\n if (!isd2dcanvas) {\r\n element.width=this.props.charWidth*this.props.widthInChars;\r\n element.height=this.props.charHeight*this.props.heightInChars;\r\n }\r\n\r\n this.props.canvasHeight=element.height;\r\n this.props.canvasWidth=element.width;\r\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\r\n\r\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\r\n let c2=element.getContext(\"2d\");\r\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\r\n this.ctx=c2;\r\n this.ctx.font = fontsize.toString()+\"px Courier New\";\r\n this.ctx.textBaseline=\"top\";\r\n\r\n c2.fillStyle=backcolor;\r\n this.props.backColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n c2.fillStyle=forecolor;\r\n this.props.foreColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n }\r\n\r\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\r\n\r\n //console.log(\"twrCanvas.constructor props: \", this.props);\r\n }\r\n\r\n isValid() {\r\n return !!this.ctx;\r\n }\r\n\r\n getProxyParams() : TCanvasProxyParams {\r\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\r\n }\r\n\r\n getProp(pn:number): number {\r\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n\r\n/* see draw2d.h for structs that match */\r\n\r\n drawSeq(ds:number) {\r\n //console.log(\"twr::Canvas enter drawSeq\");\r\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\r\n if (!this.ctx) return;\r\n\r\n let ins=this.owner.getLong(ds); /* ds->start */\r\n const lastins=this.owner.getLong(ds+4); /* ds->last */\r\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\r\n\r\n let next:number;\r\n //let insCount=0;\r\n\r\n while (1) {\r\n\r\n //insCount++;\r\n\r\n const type:D2DType=this.owner.getLong(ins+4); /* hdr->type */\r\n if (0/*type!=D2DType.D2D_FILLRECT*/) {\r\n console.log(\"ins\",ins)\r\n console.log(\"hdr.next\",this.owner.mem8[ins],this.owner.mem8[ins+1],this.owner.mem8[ins+2],this.owner.mem8[ins+3]);\r\n console.log(\"hdr.type\",this.owner.mem8[ins+4],this.owner.mem8[ins+5]);\r\n console.log(\"next 4 bytes\", this.owner.mem8[ins+6],this.owner.mem8[ins+7],this.owner.mem8[ins+8],this.owner.mem8[ins+9]);\r\n console.log(\"and 4 more \", this.owner.mem8[ins+10],this.owner.mem8[ins+11],this.owner.mem8[ins+12],this.owner.mem8[ins+13]);\r\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\r\n }\r\n switch (type) {\r\n case D2DType.D2D_FILLRECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.fillRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKERECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.strokeRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILLCHAR:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const c=this.owner.getShort(ins+24);\r\n let txt=String.fromCharCode(c);\r\n this.ctx.fillText(txt, x, y);\r\n }\r\n break;\r\n\r\n \r\n case D2DType.D2D_FILLTEXT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const str=this.owner.getString(this.owner.getLong(ins+24));\r\n\r\n //console.log(\"filltext \",x,y,str)\r\n \r\n this.ctx.fillText(str, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MEASURETEXT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n const tmidx=this.owner.getLong(ins+12);\r\n \r\n const tm=this.ctx.measureText(str);\r\n this.owner.setDouble(tmidx+0, tm.actualBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+8, tm.actualBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+16, tm.actualBoundingBoxLeft);\r\n this.owner.setDouble(tmidx+24, tm.actualBoundingBoxRight);\r\n this.owner.setDouble(tmidx+32, tm.fontBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+40, tm.fontBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+48, tm.width);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFONT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.font=str;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.fillStyle = cssColor;\r\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETSTROKESTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.fillStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETSTROKESTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETLINEWIDTH:\r\n {\r\n const width=this.owner.getShort(ins+8); \r\n this.ctx.lineWidth=width;\r\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MOVETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.moveTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_LINETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.lineTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEZIERTO:\r\n {\r\n const cp1x=this.owner.getDouble(ins+8);\r\n const cp1y=this.owner.getDouble(ins+16);\r\n const cp2x=this.owner.getDouble(ins+24);\r\n const cp2y=this.owner.getDouble(ins+32);\r\n const x=this.owner.getDouble(ins+40);\r\n const y=this.owner.getDouble(ins+48);\r\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEGINPATH:\r\n {\r\n this.ctx.beginPath();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILL:\r\n {\r\n this.ctx.fill();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SAVE:\r\n {\r\n this.ctx.save();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_RESTORE:\r\n {\r\n this.ctx.restore();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKE:\r\n {\r\n this.ctx.stroke();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_ARC:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const radius=this.owner.getDouble(ins+24);\r\n const startAngle=this.owner.getDouble(ins+32);\r\n const endAngle=this.owner.getDouble(ins+40);\r\n const counterClockwise= (this.owner.getLong(ins+48)!=0);\r\n\r\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_IMAGEDATA:\r\n {\r\n const start=this.owner.getLong(ins+8);\r\n const length=this.owner.getLong(ins+12);\r\n const width=this.owner.getLong(ins+16);\r\n const height=this.owner.getLong(ins+20);\r\n const id=this.owner.getLong(ins+24);\r\n\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\r\n\r\n if (this.owner.isWasmModule) {\r\n const z = new Uint8ClampedArray(this.owner.memory!.buffer, start, length);\r\n this.precomputedObjects[id]=new ImageData(z, width, height);\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory\r\n this.precomputedObjects[id]={mem8: new Uint8Array(this.owner.memory!.buffer, start, length), width:width, height:height};\r\n }\r\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_CREATERADIALGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const radius0=this.owner.getDouble(ins+24);\r\n const x1=this.owner.getDouble(ins+32);\r\n const y1=this.owner.getDouble(ins+40);\r\n const radius1=this.owner.getDouble(ins+48);\r\n const id= this.owner.getLong(ins+56);\r\n\r\n let gradient=this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_CREATELINEARGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const x1=this.owner.getDouble(ins+24);\r\n const y1=this.owner.getDouble(ins+32);\r\n const id= this.owner.getLong(ins+40);\r\n \r\n let gradient=this.ctx.createLinearGradient(x0, y0, x1, y1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETCOLORSTOP:\r\n {\r\n const id = this.owner.getLong(ins+8);\r\n const pos=this.owner.getLong(ins+12);\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+16));\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n gradient.addColorStop(pos, cssColor);\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n this.ctx.fillStyle=gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_RELEASEID:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (this.precomputedObjects[id])\r\n delete this.precomputedObjects[id];\r\n else\r\n console.log(\"warning: D2D_RELEASEID with undefined ID \",id);\r\n }\r\n break\r\n\r\n \r\n\r\n case D2DType.D2D_PUTIMAGEDATA:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n const dx=this.owner.getLong(ins+12);\r\n const dy=this.owner.getLong(ins+16);\r\n const dirtyX=this.owner.getLong(ins+20);\r\n const dirtyY=this.owner.getLong(ins+24);\r\n const dirtyWidth=this.owner.getLong(ins+28);\r\n const dirtyHeight=this.owner.getLong(ins+32);\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \"+id);\r\n\r\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\r\n\r\n let imgData:ImageData;\r\n if (this.owner.isWasmModule) {\r\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\r\n imgData=this.precomputedObjects[id] as ImageData;\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\r\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\r\n const z = this.precomputedObjects[id] as {mem8:Uint8Array, width:number, height:number}; // Uint8Array\r\n const ca=Uint8ClampedArray.from(z.mem8); // shallow copy\r\n imgData=new ImageData(ca, z.width, z.height);\r\n }\r\n \r\n if (dirtyWidth==0 && dirtyHeight==0) {\r\n this.ctx.putImageData(imgData, dx, dy);\r\n }\r\n else {\r\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\r\n }\r\n }\r\n break;\r\n\r\n default:\r\n throw new Error (\"unimplemented or unknown Sequence Type in drawSeq: \"+type);\r\n }\r\n next=this.owner.getLong(ins); /* hdr->next */\r\n if (next==0) {\r\n if (ins!=lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\r\n break;\r\n }\r\n ins=next;\r\n }\r\n\r\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\r\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\r\n }\r\n}\r\n\r\nexport class twrCanvasProxy implements ICanvas {\r\n canvasKeys: twrSharedCircularBuffer;\r\n drawCompleteSignal:twrSignal;\r\n props: ICanvasProps;\r\n owner: twrWasmModuleBase;\r\n\r\n constructor(params:TCanvasProxyParams, owner:twrWasmModuleBase) {\r\n const [props, signalBuffer, canvasKeysBuffer] = params;\r\n this.drawCompleteSignal = new twrSignal(signalBuffer);\r\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\r\n this.props=props;\r\n this.owner=owner;\r\n\r\n //console.log(\"Create New twrCanvasProxy: \",this.props)\r\n\r\n }\r\n\r\n charIn() { \r\n //ctx.commit(); not avail in chrome\r\n \r\n //postMessage([\"debug\", 'x']);\r\n \r\n return this.canvasKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.canvasKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n getProp(pn:number): number {\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n \r\n drawSeq(ds:number) {\r\n this.drawCompleteSignal.reset();\r\n postMessage([\"drawseq\", [ds]]);\r\n this.drawCompleteSignal.wait();\r\n }\r\n}\r\n","//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst RDIDX = 256;\nconst WRIDX = 257;\nconst LEN = 256;\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\n// the first 256 array entries are the circular buffer\n// the next two are used for the read and write index\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\nexport class twrSharedCircularBuffer {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(258 * 4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[RDIDX] = 0;\n this.buf[WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[WRIDX];\n this.buf[i] = n;\n i++;\n if (i == LEN)\n i = 0;\n this.buf[WRIDX] = i;\n Atomics.notify(this.buf, WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[RDIDX] = i;\n return n;\n }\n else\n return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[RDIDX] == this.buf[WRIDX];\n }\n}\n//# sourceMappingURL=twrcircular.js.map","//\r\n// This class implements a circular buffer that the main javascript thread can write to, \r\n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\r\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \r\n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\r\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\r\n//\r\n\r\nconst RDIDX=256;\r\nconst WRIDX=257;\r\nconst LEN=256;\r\n\r\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\r\n// the first 256 array entries are the circular buffer\r\n// the next two are used for the read and write index\r\n\r\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\r\n\r\nexport class twrSharedCircularBuffer {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n \r\n\tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(258*4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[RDIDX]=0;\r\n this.buf[WRIDX]=0;\r\n\t}\r\n\r\n\twrite(n:number) {\r\n let i=this.buf[WRIDX];\r\n this.buf[i]=n;\r\n i++;\r\n if (i==LEN) i=0;\r\n this.buf[WRIDX]=i; \r\n Atomics.notify(this.buf, WRIDX); \r\n\t}\r\n\r\n\tread():number {\r\n if (!this.isEmpty()) {\r\n let i=this.buf[RDIDX];\r\n let n=this.buf[i];\r\n i++;\r\n this.buf[RDIDX]=i;\r\n return n;\r\n }\r\n\t\telse\r\n return -1;\r\n\t}\r\n\r\n readWait():number {\r\n if (this.isEmpty()) {\r\n const rdptr=this.buf[RDIDX];\r\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\r\n Atomics.wait(this.buf, WRIDX, rdptr);\r\n }\r\n return this.read();\r\n\t}\r\n\r\n isEmpty():boolean {\r\n return this.buf[RDIDX]==this.buf[WRIDX];\r\n }\r\n}\r\n","//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar twrSignalState;\n(function (twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})(twrSignalState || (twrSignalState = {}));\n;\nexport class twrSignal {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window valid\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == twrSignalState.WAITING) {\n //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\n //console.log(\"released...\");\n }\n }\n isSignaled() {\n return this.buf[0] == twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = twrSignalState.WAITING;\n }\n}\n//# sourceMappingURL=twrsignal.js.map","//\r\n// This class implements a simple signal/wait mechanism\r\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\r\n//\r\n\r\nenum twrSignalState {\r\n WAITING=0,\r\n SIGNALED=1\r\n};\r\n\r\nexport class twrSignal {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n\r\n \tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window valid\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) \r\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[0]=twrSignalState.WAITING;\r\n\t}\r\n\r\n\tsignal() {\r\n this.buf[0]=twrSignalState.SIGNALED; \r\n //console.log(\"about to signal\");\r\n Atomics.notify(this.buf, 0); \r\n\t}\r\n\r\n wait() {\r\n if (this.buf[0]==twrSignalState.WAITING) {\r\n //console.log(\"waiting...\");\r\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\r\n //console.log(\"released...\");\r\n\r\n }\r\n\t}\r\n isSignaled():boolean {\r\n return this.buf[0]==twrSignalState.SIGNALED;\r\n }\r\n\r\n reset() {\r\n this.buf[0]=twrSignalState.WAITING;\r\n }\r\n}\r\n","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nexport class twrDiv {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase) {\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\n this.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n if (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.divKeys.sharedArray];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */\n charOut(ch) {\n if (!this.div)\n return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n }\n switch (ch) {\n case 10: // newline\n case 13: // return\n if (ch == 10 && this.lastChar == 13)\n break; // detect CR LF and treat as single new line\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8: // backspace\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n case 0xE: // cursor on\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF: // cursor off\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for (let i = 0; i < str.length; i++)\n this.charOut(str.charCodeAt(i));\n }\n}\nexport class twrDivProxy {\n divKeys;\n constructor(params) {\n const [divKeysBuffer] = params;\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n charOut(ch) {\n postMessage([\"divout\", ch]);\n }\n}\n//# sourceMappingURL=twrdiv.js.map","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\r\nimport { IModParams } from \"./twrmodbase.js\";\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\";\r\n\r\nexport type TDivProxyParams = [SharedArrayBuffer];\r\n\r\nexport interface IDiv {\r\n charOut: (ds:number)=>void,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TDivProxyParams,\r\n }\r\n\r\n\r\nexport class twrDiv implements IDiv {\r\n\tdiv:HTMLDivElement|null|undefined;\r\n\tdivKeys?:twrSharedCircularBuffer;\r\n\tCURSOR=String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\r\n\tcursorOn:boolean=false;\r\n\tlastChar:number=0;\r\n\textraBR:boolean=false;\r\n\towner:twrWasmModuleBase;\r\n\r\n constructor(element:HTMLDivElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n\t\tthis.div=element;\r\n\t\tthis.owner=modbase;\r\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\r\n\t\t\tthis.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n\t\t}\r\n\r\n\t\tif (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\r\n\t\t\tthis.div.style.backgroundColor = modParams.backcolor;\r\n\t\t\tthis.div.style.color = modParams.forecolor;\r\n\t\t\tthis.div.style.font=modParams.fontsize.toString()+\"px arial\"\r\n\t\t}\r\n }\r\n\r\n\tisValid() {\r\n\t\treturn !!this.div;\r\n\t}\r\n\r\n getProxyParams() : TDivProxyParams {\r\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [ this.divKeys.sharedArray];\r\n }\r\n\r\n\r\n/* \r\n * add character to div. Supports the following control codes:\r\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\r\n * 0xE cursor on \r\n * 0x8 backspace\r\n * 0xF cursor off \r\n*/\r\n\tcharOut(ch:number) {\r\n\r\n\t\tif (!this.div) return;\r\n\r\n\t\t//console.log(\"div::charout: \", ch);\r\n\r\n\t\tif (this.extraBR) {\r\n\t\t\tthis.extraBR=false;\r\n\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -4);\r\n\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t}\r\n\r\n\t\tswitch (ch) {\r\n\t\t\tcase 10: // newline\r\n\t\t\tcase 13: // return\r\n\t\t\t\tif (ch==10 && this.lastChar==13) break; // detect CR LF and treat as single new line\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\r\n\t\t\t\tthis.extraBR=true;\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\t//element.scrollIntoView();\r\n\t\t\t\t//element.scrollTop = element.scrollHeight;\r\n\t\t\t\tlet p = this.div.getBoundingClientRect();\r\n\t\t\t\twindow.scrollTo(0, p.height+100);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 8: // backspace\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xE: // cursor on\r\n\t\t\t\tif (!this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=true;\r\n\t\t\t\t\tthis.div.innerHTML += this.CURSOR;\r\n\t\t\t\t\tthis.div.focus();\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xF: // cursor off\r\n\t\t\t\tif (this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=false;\r\n\t\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += String.fromCharCode(ch);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\tthis.lastChar=ch;\r\n\t}\r\n\r\n\tstringOut(str:string) {\r\n\t\tfor (let i=0; i < str.length; i++)\r\n\t\t\tthis.charOut(str.charCodeAt(i));\r\n\t}\r\n}\r\n\r\n\r\nexport class twrDivProxy implements IDiv {\r\n divKeys: twrSharedCircularBuffer;\r\n\r\n constructor(params:TDivProxyParams) {\r\n const [divKeysBuffer] = params;\r\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\r\n }\r\n\r\n charIn() { \r\n return this.divKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.divKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n\tcharOut(ch:number) {\r\n\t\tpostMessage([\"divout\", ch]);\r\n\t}\r\n}\r\n\r\n","let logline = \"\";\nexport function twrDebugLogImpl(char) {\n if (char == 10 || char == 3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\n console.log(logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n logline = \"\";\n }\n else {\n logline = logline + String.fromCharCode(char);\n if (logline.length >= 200) {\n console.log(logline);\n logline = \"\";\n }\n }\n}\n// ************************************************************************\n// debugLog doesn't currently wait for the message to log, it returns immediately.\n// I could move this to be in the twrWaitingCalls class\nexport function twrDebugLogProxy(ch) {\n postMessage([\"debug\", ch]);\n}\n//# sourceMappingURL=twrdebug.js.map","\r\nlet logline=\"\";\r\nexport function twrDebugLogImpl(char:number) {\r\n\tif (char==10 || char==3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\r\n\t\tconsole.log(logline);\t// ideally without a linefeed, but there is no way to not have a LF with console.log API.\r\n\t\tlogline=\"\";\r\n\t}\r\n\telse {\r\n\t\tlogline=logline+String.fromCharCode(char);\r\n\t\tif (logline.length>=200) {\r\n\t\t\tconsole.log(logline);\r\n\t\t\tlogline=\"\";\r\n\t\t}\r\n\t}\r\n}\r\n\r\n// ************************************************************************\r\n// debugLog doesn't currently wait for the message to log, it returns immediately.\r\n// I could move this to be in the twrWaitingCalls class\r\nexport function twrDebugLogProxy(ch:number) {\r\n postMessage([\"debug\", ch]);\r\n}\r\n\r\n","import { twrFloatUtil } from \"./twrfloat.js\";\n/*********************************************************************/\n/*********************************************************************/\n/*********************************************************************/\nexport class twrWasmModuleBase {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\n floatUtil;\n constructor(isWasmModule = false) {\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new twrFloatUtil(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/\n /*********************************************************************/\n async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n }\n catch (err) {\n console.log('loadWasm() failed to fetch: ' + pathToLoad);\n throw err;\n }\n if (!response.ok)\n throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, { env: allimports });\n this.exports = instance.instance.exports;\n if (!this.exports)\n throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory)\n throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory)\n throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer)\n console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\"setmemory\", this.memory]);\n }\n if (this.isWasmModule) {\n // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (!(this.memory.buffer instanceof ArrayBuffer))\n console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size) => {\n return new Promise(resolve => {\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n }\n catch (err) {\n console.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch (this.modParams.stdio) {\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* callC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */\n async callC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.callCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async callCImpl(fname, cparams = []) {\n if (!this.exports)\n throw new Error(\"this.exports undefined\");\n if (!this.exports[fname])\n throw new Error(\"callC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array))\n throw new Error(\"callC: params must be array, first arg is function name\");\n if (params.length == 0)\n throw new Error(\"callC: missing function name\");\n let cparams = [];\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n cparams[ci++] = p;\n break;\n case 'string':\n cparams[ci++] = await this.putString(p);\n break;\n case 'object':\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n }\n else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"callC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n ci++;\n break;\n case 'string':\n this.callCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n case 'object':\n if (p instanceof URL) {\n this.callCImpl('twr_free', [cparams[ci]]);\n ci = ci + 2;\n break;\n }\n else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for (let j = 0; j < u8.length; j++)\n u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.callCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n }\n else\n throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/\n /*********************************************************************/\n // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for (i = 0; i < sin.length && i < buffer_size - 1; i++)\n this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for (let i = 0; i < u8a.length; i++)\n this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === 'object' && fnin instanceof URL))\n throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [dest, src.length];\n }\n catch (err) {\n console.log('fetchAndPutURL Error. URL: ' + fnin + '\\n' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while (this.mem8[strIndex + i] && (len === undefined ? true : i < len) && (strIndex + i) < this.mem8.length) {\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0)\n throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array((this.mem8.slice(dataptr, dataptr + size)).buffer);\n return u32;\n }\n}\n//# sourceMappingURL=twrmodbase.js.map","\r\nimport {TCanvasProxyParams} from \"./twrcanvas.js\"\r\nimport {TDivProxyParams} from \"./twrdiv.js\";\r\nimport {TWaitingCallsProxyParams} from \"./twrwaitingcalls.js\"\r\nimport {twrDebugLogImpl} from \"./twrdebug.js\";\r\nimport {twrFloatUtil} from \"./twrfloat.js\";\r\n\r\n\r\nexport type TStdioVals=\"div\"|\"canvas\"|\"null\"|\"debug\";\r\n\r\nexport interface IModOpts {\r\n\tstdio?:TStdioVals, \r\n\twindim?:[number, number],\r\n\tforecolor?:string,\r\n\tbackcolor?:string,\r\n\tfontsize?:number,\r\n\tisd2dcanvas?:boolean,\r\n\timports?:{},\r\n}\r\n\r\nexport interface IModParams {\r\n\tstdio:TStdioVals, \r\n\twindim:[number, number],\r\n\tforecolor:string,\r\n\tbackcolor:string,\r\n\tfontsize:number,\r\n\tstyleIsDefault: boolean\r\n\tisd2dcanvas:boolean,\r\n\timports:{[index:string]:Function},\r\n}\r\n\r\nexport interface IModInWorkerParams {\r\n\tdivProxyParams:TDivProxyParams,\r\n\tcanvasProxyParams:TCanvasProxyParams,\r\n\twaitingCallsProxyParams:TWaitingCallsProxyParams,\r\n}\r\n\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n\r\nexport abstract class twrWasmModuleBase {\r\n\tmemory?:WebAssembly.Memory;\r\n\tmem8:Uint8Array;\r\n\tmem32:Uint32Array;\r\n\tmemD:Float64Array;\r\n\tabstract malloc:(size:number)=>Promise;\r\n\tabstract modParams:IModParams;\r\n\texports?:WebAssembly.Exports;\r\n\tisWorker=false;\r\n\tisWasmModule:boolean; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\r\n\tfloatUtil:twrFloatUtil;\r\n\r\n\tconstructor(isWasmModule=false) {\r\n\t\tthis.isWasmModule=isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\r\n\t\tthis.mem8=new Uint8Array(); \t// avoid type errors\r\n\t\tthis.mem32=new Uint32Array(); // avoid type errors\r\n\t\tthis.memD=new Float64Array(); // avoid type errors\r\n\t\tthis.floatUtil=new twrFloatUtil(this);\r\n\t\t//console.log(\"size of mem8 after constructor\",this.mem8.length);\r\n\t}\r\n\r\n\t/*********************************************************************/\r\n\t/*********************************************************************/\r\n\r\n\tasync loadWasm(pathToLoad:string) {\r\n\t\t//console.log(\"fileToLoad\",fileToLoad)\r\n\r\n\t\tlet response;\r\n\t\ttry {\r\n\t\t\tresponse=await fetch(pathToLoad);\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('loadWasm() failed to fetch: '+pathToLoad);\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t\t\r\n\t\tif (!response.ok) throw new Error(\"fetch response error on file '\"+pathToLoad+\"'\\n\"+response.statusText);\r\n\r\n\t\ttry {\r\n\t\t\tlet wasmBytes = await response.arrayBuffer();\r\n\r\n\t\t\tlet allimports:WebAssembly.ModuleImports = { \r\n\t\t\t\t...this.modParams.imports\r\n\t\t\t};\r\n\r\n\t\t\tlet instance = await WebAssembly.instantiate(wasmBytes, {env: allimports});\r\n\r\n\t\t\tthis.exports=instance.instance.exports;\r\n\t\t\tif (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\r\n\r\n\t\t\tif (this.memory) throw new Error (\"unexpected error -- this.memory already set\");\r\n\t\t\tthis.memory=this.exports.memory as WebAssembly.Memory;\r\n\t\t\tif (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\r\n\t\t\tthis.mem8 = new Uint8Array(this.memory.buffer);\r\n\t\t\tthis.mem32 = new Uint32Array(this.memory.buffer);\r\n\t\t\tthis.memD = new Float64Array(this.memory.buffer);\r\n\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\tif (this.isWorker) {\r\n\t\t\t\tif (this.memory.buffer instanceof ArrayBuffer)\r\n\t\t\t\t\tconsole.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\r\n\t\t\t\t\r\n\t\t\t\tpostMessage([\"setmemory\",this.memory]);\r\n\t\t\t}\r\n\t\t\tif (this.isWasmModule) {\r\n\t\t\t\t// here if twrWasmModule, twrWasmModuleAsync overrides this function\r\n\t\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\t\tif (!(this.memory.buffer instanceof ArrayBuffer))\r\n\t\t\t\t\tconsole.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\r\n\t\t\t}\r\n\r\n\t\t\tthis.malloc=(size:number)=>{\r\n\t\t\t\treturn new Promise(resolve => {\r\n\t\t\t\t\tconst m=this.exports!.twr_malloc as (size:number)=>number;\r\n\t\t\t\t\tresolve(m(size));\r\n\t\t\t\t});\r\n\t\t };\r\n\r\n\t\t\tthis.init();\r\n\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t}\r\n\r\n\tprivate init() {\r\n\t\t//console.log(\"loadWasm.init() enter\")\r\n\t\t\tlet p:number;\r\n\t\t\tswitch (this.modParams.stdio) {\r\n\t\t\t\tcase \"debug\":\r\n\t\t\t\t\tp=0;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"div\":\r\n\t\t\t\t\tp=1;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"canvas\":\r\n\t\t\t\t\tp=2;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"null\":\r\n\t\t\t\t\tp=3;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tp=0; // debug\r\n\t\t\t}\r\n\r\n\t\t\tconst twrInit=this.exports!.twr_wasm_init as CallableFunction;\r\n\t\t\t//console.log(\"twrInit:\",twrInit)\r\n\t\t\ttwrInit(p, this.mem8.length);\r\n\t}\r\n\r\n\t/* callC takes an array where:\r\n\t* the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\r\n\t* and the next entries are a variable number of parameters to pass to the C function, of type\r\n\t* number - converted to int32 or float64 as appropriate\r\n\t* string - converted to a an index (ptr) into a module Memory returned via stringToMem()\r\n\t* URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\r\n\t* Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\r\n */\r\n\r\n\tasync callC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\t\tconst cparams=await this.preCallC(params);\r\n\t\tlet retval = this.callCImpl(params[0], cparams);\r\n\t\tthis.postCallC(cparams, params);\r\n\t\treturn retval;\r\n\t}\r\n\r\n\tasync callCImpl(fname:string, cparams:number[]=[]) {\r\n\t\tif (!this.exports) throw new Error(\"this.exports undefined\");\r\n\t\tif (!this.exports[fname]) throw new Error(\"callC: function '\"+fname+\"' not in export table. Use --export wasm-ld flag.\");\r\n\r\n\t\tconst f = this.exports[fname] as CallableFunction;\r\n\t\tlet cr=f(...cparams);\r\n\r\n\t\treturn cr;\r\n\t}\r\n\r\n\t// convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\r\n\tasync preCallC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tif (!(params.constructor === Array)) throw new Error (\"callC: params must be array, first arg is function name\");\r\n\t\tif (params.length==0) throw new Error(\"callC: missing function name\");\r\n\r\n\t\tlet cparams:number[]=[];\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tcparams[ci++]=p;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tcparams[ci++]=await this.putString(p);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tconst r=await this.fetchAndPutURL(p);\r\n\t\t\t\t\t\tcparams[ci++]=r[0]; // mem index\r\n\t\t\t\t\t\tcparams[ci++]=r[1]; // len\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tconst r=await this.putArrayBuffer(p);\r\n\t\t\t\t\t\tcparams[ci++]=r; // mem index\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tthrow new Error (\"callC: invalid object type passed in\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn cparams;\r\n\t}\r\n\r\n\t// free the mallocs; copy array buffer data from malloc back to arraybuffer\r\n\tasync postCallC(cparams:number[], params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tthis.callCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t\t\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tthis.callCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\t\tci=ci+2;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tlet u8=new Uint8Array(p);\r\n\t\t\t\t\t\tfor (let j=0; j= this.mem32.length) throw new Error(\"invalid index passed to getLong: \"+idx+\", this.mem32.length: \"+this.mem32.length);\r\n\t\tconst long:number = this.mem32[idx32];\r\n\t\treturn long;\r\n\t}\r\n\t\r\n\tsetLong(idx:number, value:number) {\r\n const idx32 = Math.floor(idx / 4);\r\n if (idx32 * 4 != idx)\r\n throw new Error(\"setLong passed non long aligned address\");\r\n if (idx32 < 0 || idx32 >= this.mem32.length)\r\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\r\n this.mem32[idx32]=value;\r\n }\r\n\r\n\tgetDouble(idx:number): number {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"getLong passed non Float64 aligned address\")\r\n\t\tconst long:number = this.memD[idx64];\r\n\t\treturn long;\r\n\t}\r\n\r\n\tsetDouble(idx:number, value:number) {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"setDouble passed non Float64 aligned address\")\r\n\t\tthis.memD[idx64]=value;\r\n\t}\r\n\r\n\tgetShort(idx:number): number {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getShort: \"+idx);\r\n\t\tconst short:number = this.mem8[idx]+this.mem8[idx+1]*256;\r\n\t\treturn short;\r\n\t}\r\n\r\n\t// get a string out of module memory\r\n\t// null terminated, up until max of (optional) len\r\n\tgetString(strIndex:number, len?:number): string {\r\n\t\tlet sout=\"\";\r\n\r\n\t\tlet i=0;\r\n\t\twhile (this.mem8[strIndex+i] && (len===undefined?true:i= this.mem8.length) throw new Error(\"invalid index passed to getU8: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU8\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU8\")\r\n\r\n\t\tconst u8=this.mem8.slice(dataptr, dataptr+size);\r\n\t\treturn u8;\r\n\t}\r\n\r\n\t// get a int32 array out of module memory when passed in index to [size, dataptr]\r\n\tgetU32Arr(idx:number): Uint32Array {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getU32: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU32\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU32\")\r\n\r\n\t\tif (size%4!=0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\r\n\r\n\t\tconst u32 = new Uint32Array( (this.mem8.slice(dataptr, dataptr+size)).buffer );\r\n\t\treturn u32;\r\n\t}\r\n}\r\n","export class twrFloatUtil {\n mod;\n constructor(mod) {\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\")\n return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\")\n return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll('D', 'e').replaceAll('d', 'e'));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n }\n else {\n let r = value.toString();\n if (r.length > max_precision)\n r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, // char *\n sizeInBytes, //size_t\n value, // double\n fracpart_numdigits, //int\n dec, // int *\n sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1)\n return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) { /* nan */\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (!Number.isFinite(value)) { /* infinity */\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n }\n else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split('.');\n if (intPart == \"0\")\n intPart = \"\";\n if (intPart.length > 0) { // has integer part\n decpos = intPart.length;\n digits = intPart + fracPart;\n }\n else { // only a fraction\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length)\n return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */\n }\n}\n//# sourceMappingURL=twrfloat.js.map","\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\"\r\n\r\nexport class twrFloatUtil {\r\n mod: twrWasmModuleBase;\r\n\r\n constructor(mod: twrWasmModuleBase) {\r\n this.mod=mod;\r\n }\r\n\r\n atod(strptr:number):number {\r\n const str=this.mod.getString(strptr);\r\n\r\n const upper=str.trimStart().toUpperCase();\r\n if (upper==\"INF\" || upper==\"+INF\")\r\n return Number.POSITIVE_INFINITY;\r\n else if (upper==\"-INF\")\r\n return Number.NEGATIVE_INFINITY\r\n else {\r\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\r\n const r=Number.parseFloat(str.replaceAll('D','e').replaceAll('d','e'));\r\n return r;\r\n }\r\n }\r\n\r\n dtoa(buffer:number, buffer_size:number, value:number, max_precision:number):void {\r\n if (max_precision==-1) {\r\n const r=value.toString();\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n else {\r\n let r=value.toString();\r\n if (r.length>max_precision)\r\n r=value.toPrecision(max_precision);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n }\r\n\r\n toFixed(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toFixed(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n toExponential(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toExponential(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\r\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\r\n // Negative exponents must be now smaller than 1e-99\r\n // fully-function C version also int he source, but this is the version enabled by default\r\n fcvtS(\r\n buffer:number, // char *\r\n sizeInBytes:number, //size_t\r\n value:number, // double\r\n fracpart_numdigits:number, //int\r\n dec:number, // int *\r\n sign:number // int *\r\n ):number {\r\n\r\n if (buffer==0 ||sign==0 || dec==0 || sizeInBytes<1) return 1;\r\n\r\n let digits:string;\r\n let decpos:number;\r\n let s=0; // default to positive\r\n\r\n\r\n if (Number.isNaN(value)) { /* nan */\r\n digits=\"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (!Number.isFinite(value)) { /* infinity */\r\n digits=\"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (value==0) { \r\n digits=\"000000000000000000000000000000000000\".slice(0,fracpart_numdigits);\r\n decpos=0;\r\n }\r\n \r\n else {\r\n\r\n if (value<0) {\r\n s=1; // negative\r\n value=Math.abs(value);\r\n }\r\n\r\n if (fracpart_numdigits>100 || value > 1e+21 || value < 1e-99) { \r\n this.mod.copyString(buffer, sizeInBytes, \"\");\r\n this.mod.mem32[dec]=0;\r\n return 1;\r\n }\r\n\r\n const roundValStr=value.toFixed(fracpart_numdigits);\r\n let [intPart=\"\", fracPart=\"\"] = roundValStr.split('.');\r\n if (intPart==\"0\") intPart=\"\";\r\n\r\n if (intPart.length>0) { // has integer part\r\n decpos=intPart.length;\r\n digits=intPart+fracPart;\r\n }\r\n else { // only a fraction\r\n digits=fracPart.replace(/^0+/,\"\"); // remove leading zeros\r\n decpos=digits.length-fracPart.length;\r\n }\r\n }\r\n\r\n if (sizeInBytes-1 < digits.length) return 1; \r\n this.mod.copyString(buffer, sizeInBytes, digits);\r\n this.mod.setLong(dec, decpos);\r\n this.mod.setLong(sign, s);\r\n\r\n return 0;\r\n\r\n /*\r\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\r\n\r\n let decpos=0;\r\n let digits:string;\r\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\r\n \r\n if (decpos>0) { // has integer part\r\n const intlen=Math.max(decpos, 0);\r\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\r\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\r\n }\r\n else { // only a fraction\r\n const intpart=Math.trunc(value);\r\n const fracpart=value-intpart;\r\n const prec=fracpart_numdigits- (-decpos);\r\n console.log(\"prec=\",prec);\r\n if (prec<1) {\r\n digits=\"\";\r\n }\r\n else {\r\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\");\r\n }\r\n }\r\n\r\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\r\n console.log('digits=',digits);\r\n console.log('dec=',decpos);\r\n console.log(\"sign=\",s);\r\n */\r\n\r\n\r\n }\r\n}","import { twrSignal } from \"./twrsignal.js\";\nimport { twrTimeImpl } from \"./twrdate.js\";\n// This class is used in the Main JS thread \nexport class twrWaitingCalls {\n callCompleteSignal;\n parameters;\n constructor() {\n this.callCompleteSignal = new twrSignal();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(() => {\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = twrTimeImpl();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [this.callCompleteSignal.sharedArray, this.parameters.buffer];\n }\n processMessage(msgType, data) {\n switch (msgType) {\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\n// This class is used in the worker thread \nexport class twrWaitingCallsProxy {\n callCompleteSignal;\n parameters;\n constructor(params) {\n this.callCompleteSignal = new twrSignal(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\"sleep\", [ms]]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\"time\"]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n//# sourceMappingURL=twrwaitingcalls.js.map","import { twrSignal } from \"./twrsignal.js\";\r\nimport {twrTimeImpl} from \"./twrdate.js\"\r\n\r\n// These classes are used to proxy a call across the worker thread - main thread boundary and wait for the result\r\n\r\nexport type TWaitingCallsProxyParams = [SharedArrayBuffer, SharedArrayBuffer]; // twrSignal, parameters \r\n\r\n// This class is used in the Main JS thread \r\nexport class twrWaitingCalls {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor() {\r\n\t\tthis.callCompleteSignal=new twrSignal();\r\n\t\tthis.parameters=new Uint32Array(new SharedArrayBuffer(4));\r\n\t}\r\n\r\n\tprivate startSleep(ms:number) {\r\n\r\n\t\tsetTimeout(()=>{\r\n\t\t\tthis.callCompleteSignal.signal();\r\n\t\t}, ms);\r\n\t\t\r\n\t}\r\n\r\n\tprivate time() {\r\n\t\tconst ms=twrTimeImpl();\r\n\t\tthis.parameters[0]=ms;\r\n\t\tthis.callCompleteSignal.signal();\r\n\t}\r\n\r\n\tgetProxyParams():TWaitingCallsProxyParams {\r\n\t\treturn [this.callCompleteSignal.sharedArray, this.parameters.buffer as SharedArrayBuffer];\t\r\n\t}\r\n\r\n\tprocessMessage(msgType:string, data:any[]):boolean {\r\n\t\tswitch (msgType) {\r\n\t\t\tcase \"sleep\":\r\n\t\t\t\tconst [ms] = data;\r\n\t\t\t\tthis.startSleep(ms);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"time\":\r\n\t\t\t\tthis.time();\r\n\t\t\t\tbreak;\r\n\t\t\t\r\n\t\t\tdefault:\r\n\t\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\treturn true;\r\n\t}\r\n\r\n}\r\n\r\n// This class is used in the worker thread \r\nexport class twrWaitingCallsProxy {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor(params:TWaitingCallsProxyParams) {\r\n\t\tthis.callCompleteSignal=new twrSignal(params[0]);\r\n\t\tthis.parameters=new Uint32Array(params[1]);\r\n\t}\r\n\r\n\tsleep(ms:number) {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"sleep\", [ms]]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t}\r\n\r\n\ttime() {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"time\"]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t\treturn this.parameters[0];\r\n\t}\r\n\r\n}\r\n","export function twrTimeImpl() {\n return Date.now();\n}\n//# sourceMappingURL=twrdate.js.map","\r\nexport function twrTimeImpl() {\r\n\r\n return Date.now();\r\n\r\n}"],"names":["$b93f1fdf40141def$var$twrSignalState","$c4741cac81d14197$var$D2DType","twrSignalState","D2DType","$3e39efa823870787$var$mod","$892fccfc812d5e20$export$a01cca24f011573a","sharedArray","buf","constructor","sa","window","crossOriginIsolated","location","protocol","Error","SharedArrayBuffer","Int32Array","write","n","i","Atomics","notify","read","isEmpty","readWait","rdptr","wait","$b93f1fdf40141def$export$e37a7b7b851b97f3","WAITING","signal","SIGNALED","isSignaled","reset","$c4741cac81d14197$export$c779b2cd00544976","canvasKeys","drawCompleteSignal","props","owner","params","signalBuffer","canvasKeysBuffer","charIn","inkey","getProp","pn","propName","getString","drawSeq","ds","postMessage","$8963973702ae5462$export$b377f0bbf2c7581e","divKeys","divKeysBuffer","charOut","ch","$8ac0b786da854328$export$485af4d0039b3389","$e72303a1db04bdfa$export$918ffb7e046a537b","mod","atod","strptr","str","upper","trimStart","toUpperCase","Number","POSITIVE_INFINITY","NEGATIVE_INFINITY","parseFloat","replaceAll","dtoa","buffer","buffer_size","value","max_precision","r","toString","copyString","length","toPrecision","toFixed","decdigits","toExponential","fcvtS","sizeInBytes","fracpart_numdigits","dec","sign","digits","decpos","s","isNaN","slice","isFinite","Math","abs","mem32","intPart","fracPart","roundValStr","split","replace","setLong","$ece7fa3ed770778a$export$c83a0a3bffe07399","memory","mem8","memD","exports","isWorker","isWasmModule","floatUtil","Uint8Array","Uint32Array","Float64Array","loadWasm","pathToLoad","response","fetch","err","console","log","ok","statusText","wasmBytes","arrayBuffer","allimports","modParams","imports","instance","WebAssembly","instantiate","env","ArrayBuffer","malloc","size","Promise","resolve","m","twr_malloc","init","stack","p","stdio","twrInit","twr_wasm_init","callC","cparams","preCallC","retval","callCImpl","postCallC","fname","f","Array","ci","putString","URL","fetchAndPutURL","putArrayBuffer","u8","j","sin","charCodeAt","strIndex","putU8","u8a","dest","ab","fnin","src","getLong","idx","idx32","floor","getDouble","idx64","setDouble","getShort","len","sout","undefined","String","fromCharCode","getU8Arr","rv","dataptr","getU32Arr","$aff9c2c494d23fe3$export$78d2a4633fe89379","callCompleteSignal","parameters","sleep","ms","time","onmessage","e","data","$3e39efa823870787$var$twrWasmModuleInWorker","modWorkerParams","urlToLoad","then","catch","ex","rc","modInWorkerParams","canvasProxy","canvasProxyParams","divProxy","divProxyParams","waitingCallsProxy","waitingCallsProxyParams","twrDebugLog","twrSleep","bind","twrTime","twrDivCharOut","twrDivCharIn","twrCanvasCharIn","twrCanvasInkey","twrCanvasGetProp","twrCanvasDrawSeq","twrSin","twrCos","cos","twrTan","tan","twrFAbs","twrACos","acos","twrASin","asin","twrATan","atan","twrExp","exp","twrFloor","twrCeil","ceil","twrFMod","x","y","twrLog","twrPow","pow","twrSqrt","sqrt","twrTrunc","trunc","twrDtoa","twrToFixed","twrToExponential","twrAtod","twrFcvtS"],"version":3,"file":"twrmodworker.2165e649.js.map"} \ No newline at end of file diff --git a/azure/examples/fft/fft-script.js b/azure/examples/fft/fft-script.js index a0518cb9..e79bad4d 100644 --- a/azure/examples/fft/fft-script.js +++ b/azure/examples/fft/fft-script.js @@ -13,7 +13,7 @@ export async function fftDemo() { // kiss_fft_alloc() returns a malloced structure. Pointers are numbers (index into wasm module memory) in JS land // //kiss_fft_cfg cfg = kiss_fft_alloc( nfft ,is_inverse_fft ,0,0 ); - let cfg = await mod.executeC(["kiss_fft_alloc", fft.nfft, 0, 0, 0]); + let cfg = await mod.callC(["kiss_fft_alloc", fft.nfft, 0, 0, 0]); // The FFT input and output data are C arrays of complex numbers. // typedef struct { // kiss_fft_scalar r; @@ -24,13 +24,13 @@ export async function fftDemo() { // define kiss_fft_scalar float // So if the FFT data has 1024 bins, then 1024 * 2 floats (r & i) * 4 bytes per float are needed. // I use a JS Float32Array view on the ArrayBuffer to access the floats - // When an arrayBuffer is passed in as an argument to mod.executeC, executeC will malloc memory in the wasm module of a size that matches the array buffer, then + // When an arrayBuffer is passed in as an argument to mod.callC, callC will malloc memory in the wasm module of a size that matches the array buffer, then // copy the arraybuffer into the malloc'd memory prior to the function call, then copy the malloc'd memory contents back into the arrayBuffer post call. // The malloc'd memory is free'd post call. // void kiss_fft(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout); - await mod.executeC(["kiss_fft", cfg, fft.inArrayBuf, fft.outArrayBuf]); + await mod.callC(["kiss_fft", cfg, fft.inArrayBuf, fft.outArrayBuf]); fft.graphOut("c-output"); - await mod.executeC(["twr_free", cfg]); // not much point to this since all the module memory is about to disappear + await mod.callC(["twr_free", cfg]); // not much point to this since all the module memory is about to disappear } // this class holds the in and out data, // and provides functions generate sine waves diff --git a/azure/examples/fft/fft-script.ts b/azure/examples/fft/fft-script.ts index 99db96f9..bcb20842 100644 --- a/azure/examples/fft/fft-script.ts +++ b/azure/examples/fft/fft-script.ts @@ -19,7 +19,7 @@ export async function fftDemo() { // kiss_fft_alloc() returns a malloced structure. Pointers are numbers (index into wasm module memory) in JS land // //kiss_fft_cfg cfg = kiss_fft_alloc( nfft ,is_inverse_fft ,0,0 ); - let cfg:number = await mod.executeC(["kiss_fft_alloc", fft.nfft, 0, 0, 0 ]); + let cfg:number = await mod.callC(["kiss_fft_alloc", fft.nfft, 0, 0, 0 ]); // The FFT input and output data are C arrays of complex numbers. // typedef struct { @@ -33,16 +33,16 @@ export async function fftDemo() { // So if the FFT data has 1024 bins, then 1024 * 2 floats (r & i) * 4 bytes per float are needed. // I use a JS Float32Array view on the ArrayBuffer to access the floats - // When an arrayBuffer is passed in as an argument to mod.executeC, executeC will malloc memory in the wasm module of a size that matches the array buffer, then + // When an arrayBuffer is passed in as an argument to mod.callC, callC will malloc memory in the wasm module of a size that matches the array buffer, then // copy the arraybuffer into the malloc'd memory prior to the function call, then copy the malloc'd memory contents back into the arrayBuffer post call. // The malloc'd memory is free'd post call. // void kiss_fft(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout); - await mod.executeC(["kiss_fft", cfg, fft.inArrayBuf, fft.outArrayBuf]); + await mod.callC(["kiss_fft", cfg, fft.inArrayBuf, fft.outArrayBuf]); fft.graphOut("c-output"); - await mod.executeC(["twr_free", cfg]); // not much point to this since all the module memory is about to disappear + await mod.callC(["twr_free", cfg]); // not much point to this since all the module memory is about to disappear } // this class holds the in and out data, diff --git a/azure/examples/function-calls/async.html b/azure/examples/function-calls/async.html index d12470b8..a2e37db4 100644 --- a/azure/examples/function-calls/async.html +++ b/azure/examples/function-calls/async.html @@ -31,7 +31,7 @@ await amod.loadWasm("./function-calls-a.wasm"); // this output goes to the console - await amod.executeC(["twr_wasm_print_mem_debug_stats"]); + await amod.callC(["twr_wasm_print_mem_debug_stats"]); const s="This is a string."; @@ -42,20 +42,20 @@ amod.divLog("module type is twrWasmModuleAsync\n"); amod.divLog("--- begin C call ---"); - let r=await amod.executeC(["function_calls", s, ba.buffer, ba.length, url]); + let r=await amod.callC(["function_calls", s, ba.buffer, ba.length, url]); amod.divLog("--- end C call ---\n"); amod.divLog("function_calls() returned: "+r); amod.divLog("as string: ", amod.getString(r)); if (amod.getString(r)!="forty-two - if only it were that simple") throw new Error("42 error"); - r=await amod.executeC(["get_structu32"]); + r=await amod.callC(["get_structu32"]); amod.divLog("get_struct32() returned: "+r); const ba32=amod.getU32Arr(r); amod.divLog("three 32 bit ints are: ", ba32[0], ba32[1], ba32[2]); if (ba32[0]!=1 || ba32[1]!=2000 || ba32[2]!=3) throw new Error("error"); - r=await amod.executeC(["get_structu8"]); + r=await amod.callC(["get_structu8"]); amod.divLog("get_struct8() returned: "+r); const ba8=amod.getU8Arr(r); amod.divLog("three 8 bit ints are: ", ba8[0], ba8[1], ba8[2]); diff --git a/azure/examples/function-calls/dist/async.html b/azure/examples/function-calls/dist/async.html index 1be59e01..b72805e7 100644 --- a/azure/examples/function-calls/dist/async.html +++ b/azure/examples/function-calls/dist/async.html @@ -5,4 +5,4 @@ "whatkey": "../../lib-js/whatkey.js" } } -
Loading...
\ No newline at end of file +
Loading...
\ No newline at end of file diff --git a/azure/examples/function-calls/dist/index.528b9ee5.js b/azure/examples/function-calls/dist/index.528b9ee5.js index 9e933366..b6682d4b 100644 --- a/azure/examples/function-calls/dist/index.528b9ee5.js +++ b/azure/examples/function-calls/dist/index.528b9ee5.js @@ -1,2 +1,2 @@ -function e(e,t,r,i){Object.defineProperty(e,t,{get:r,set:i,enumerable:!0,configurable:!0})}var t=globalThis,r={},i={},s=t.parcelRequire94c2;null==s&&((s=function(e){if(e in r)return r[e].exports;if(e in i){var t=i[e];delete i[e];var s={id:e,exports:{}};return r[e]=s,t.call(s.exports,s,s.exports),s.exports}var o=Error("Cannot find module '"+e+"'");throw o.code="MODULE_NOT_FOUND",o}).register=function(e,t){i[e]=t},t.parcelRequire94c2=s);var o=s.register;o("eZoLj",function(t,r){e(t.exports,"register",()=>i,e=>i=e);var i,s=new Map;i=function(e,t){for(var r=0;rs("3bkoq").twrWasmModule),e(t.exports,"twrWasmModuleAsync",()=>s("baOio").twrWasmModuleAsync),s("3bkoq"),s("baOio")}),o("3bkoq",function(t,r){e(t.exports,"twrWasmModule",()=>a);var i=s("9FI45"),o=s("aGUWE"),n=s("lsUl2");class a extends o.twrWasmModuleInJSMain{malloc;constructor(e={}){let t;super(e,!0),this.malloc=e=>{throw Error("error - un-init malloc called")},t=this.d2dcanvas.isValid()?this.d2dcanvas:this.iocanvas,this.modParams.imports={twrDebugLog:i.twrDebugLogImpl,twrTime:n.twrTimeImpl,twrDivCharOut:this.iodiv.charOut.bind(this.iodiv),twrCanvasGetProp:t.getProp.bind(t),twrCanvasDrawSeq:t.drawSeq.bind(t),twrCanvasCharIn:this.null,twrCanvasInkey:this.null,twrDivCharIn:this.null,twrSleep:this.null,twrSin:Math.sin,twrCos:Math.cos,twrTan:Math.tan,twrFAbs:Math.abs,twrACos:Math.acos,twrASin:Math.asin,twrATan:Math.atan,twrExp:Math.exp,twrFloor:Math.floor,twrCeil:Math.ceil,twrFMod:function(e,t){return e%t},twrLog:Math.log,twrPow:Math.pow,twrSqrt:Math.sqrt,twrTrunc:Math.trunc,twrDtoa:this.floatUtil.dtoa.bind(this.floatUtil),twrToFixed:this.floatUtil.toFixed.bind(this.floatUtil),twrToExponential:this.floatUtil.toExponential.bind(this.floatUtil),twrAtod:this.floatUtil.atod.bind(this.floatUtil),twrFcvtS:this.floatUtil.fcvtS.bind(this.floatUtil)}}null(e){throw Error("call to unimplemented twrXXX import in twrWasmModule. Use twrWasmModuleAsync ?")}}}),o("9FI45",function(t,r){e(t.exports,"twrDebugLogImpl",()=>s);let i="";function s(e){10==e||3==e?(console.log(i),i=""):(i+=String.fromCharCode(e)).length>=200&&(console.log(i),i="")}}),o("aGUWE",function(t,r){e(t.exports,"twrWasmModuleInJSMain",()=>a);var i=s("fDEU7"),o=s("5hO33"),n=s("5LsZ0");class a extends o.twrWasmModuleBase{iocanvas;d2dcanvas;iodiv;modParams;constructor(e={},t=!1){if(super(t),"undefined"==typeof document)throw Error("twrWasmModuleJSMain should only be created in JavaScript Main.");let r=document.getElementById("twr_iodiv"),s=document.getElementById("twr_iocanvas"),o=document.getElementById("twr_d2dcanvas");if(s&&o)throw Error("Both twr_iocanvas and twr_d2dcanvas defined. Currently only one canvas allowed.");if("div"==e.stdio&&!r)throw Error("twrWasmModuleBase opts=='div' but twr_iodiv not defined");if("canvas"==e.stdio&&!s)throw Error("twrWasmModuleBase, opts=='canvas' but twr_iocanvas not defined");if(e.isd2dcanvas&&!o)throw Error("twrWasmModuleBase, opts.isdrawcanvas==true but twr_d2dcanvas not defined");e=r?{stdio:"div",...e}:s?{stdio:"canvas",...e}:{stdio:"debug",...e},r||s?console.log("tiny-wasm-runtime: stdio set to: ",e.stdio):console.log("Since neither twr_iocanvas nor twr_iodiv is defined, stdout directed to debug console."),(e=s?{windim:[64,16],...e}:{windim:[0,0],...e}).imports||(e.imports={});let a=!1;e.backcolor||(a=!0,e.backcolor="black"),e.forecolor||(a=!0,e.forecolor="white"),e.fontsize||(a=!0,e.fontsize=16),void 0===e.isd2dcanvas&&(o?e.isd2dcanvas=!0:e.isd2dcanvas=!1),this.modParams={stdio:e.stdio,windim:e.windim,imports:e.imports,forecolor:e.forecolor,backcolor:e.backcolor,styleIsDefault:a,fontsize:e.fontsize,isd2dcanvas:e.isd2dcanvas},this.iodiv=new i.twrDiv(r,this.modParams,this),this.iocanvas=new n.twrCanvas(s,this.modParams,this),this.d2dcanvas=new n.twrCanvas(o,this.modParams,this)}divLog(...e){for(var t=0;to);var i=s("ghrAp");class o{div;divKeys;CURSOR=String.fromCharCode(9611);cursorOn=!1;lastChar=0;extraBR=!1;owner;constructor(e,t,r){this.div=e,this.owner=r,this.owner.isWasmModule||(this.divKeys=new i.twrSharedCircularBuffer),this.div&&!t.styleIsDefault&&(this.div.style.backgroundColor=t.backcolor,this.div.style.color=t.forecolor,this.div.style.font=t.fontsize.toString()+"px arial")}isValid(){return!!this.div}getProxyParams(){if(!this.divKeys)throw Error("internal error in getProxyParams.");return[this.divKeys.sharedArray]}charOut(e){if(this.div){switch(this.extraBR&&(this.extraBR=!1,this.cursorOn&&(this.div.innerHTML=this.div.innerHTML.slice(0,-1)),this.div.innerHTML=this.div.innerHTML.slice(0,-4),this.cursorOn&&(this.div.innerHTML+=this.CURSOR)),e){case 10:case 13:if(10==e&&13==this.lastChar)break;this.cursorOn&&(this.div.innerHTML=this.div.innerHTML.slice(0,-1)),this.div.innerHTML+="

",this.extraBR=!0,this.cursorOn&&(this.div.innerHTML+=this.CURSOR);let t=this.div.getBoundingClientRect();window.scrollTo(0,t.height+100);break;case 8:this.cursorOn&&(this.div.innerHTML=this.div.innerHTML.slice(0,-1)),this.div.innerHTML=this.div.innerHTML.slice(0,-1),this.cursorOn&&(this.div.innerHTML+=this.CURSOR);break;case 14:this.cursorOn||(this.cursorOn=!0,this.div.innerHTML+=this.CURSOR,this.div.focus());break;case 15:this.cursorOn&&(this.cursorOn=!1,this.div.innerHTML=this.div.innerHTML.slice(0,-1));break;default:this.cursorOn&&(this.div.innerHTML=this.div.innerHTML.slice(0,-1)),this.div.innerHTML+=String.fromCharCode(e),this.cursorOn&&(this.div.innerHTML+=this.CURSOR)}this.lastChar=e}}stringOut(e){for(let t=0;ti);class i{sharedArray;buf;constructor(e){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSharedCircularBuffer constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");e?this.sharedArray=e:this.sharedArray=new SharedArrayBuffer(1032),this.buf=new Int32Array(this.sharedArray),this.buf[256]=0,this.buf[257]=0}write(e){let t=this.buf[257];this.buf[t]=e,256==++t&&(t=0),this.buf[257]=t,Atomics.notify(this.buf,257)}read(){if(this.isEmpty())return -1;{let e=this.buf[256],t=this.buf[e];return e++,this.buf[256]=e,t}}readWait(){if(this.isEmpty()){let e=this.buf[256];Atomics.wait(this.buf,257,e)}return this.read()}isEmpty(){return this.buf[256]==this.buf[257]}}}),o("5hO33",function(t,r){e(t.exports,"twrWasmModuleBase",()=>o);var i=s("2Xdsi");class o{memory;mem8;mem32;memD;exports;isWorker=!1;isWasmModule;floatUtil;constructor(e=!1){this.isWasmModule=e,this.mem8=new Uint8Array,this.mem32=new Uint32Array,this.memD=new Float64Array,this.floatUtil=new i.twrFloatUtil(this)}async loadWasm(e){let t;try{t=await fetch(e)}catch(t){throw console.log("loadWasm() failed to fetch: "+e),t}if(!t.ok)throw Error("fetch response error on file '"+e+"'\n"+t.statusText);try{let e=await t.arrayBuffer(),r={...this.modParams.imports},i=await WebAssembly.instantiate(e,{env:r});if(this.exports=i.instance.exports,!this.exports)throw Error("Unexpected error - undefined instance.exports");if(this.memory)throw Error("unexpected error -- this.memory already set");if(this.memory=this.exports.memory,!this.memory)throw Error("Unexpected error - undefined exports.memory");this.mem8=new Uint8Array(this.memory.buffer),this.mem32=new Uint32Array(this.memory.buffer),this.memD=new Float64Array(this.memory.buffer),this.isWorker&&(this.memory.buffer instanceof ArrayBuffer&&console.log("twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)"),postMessage(["setmemory",this.memory])),!this.isWasmModule||this.memory.buffer instanceof ArrayBuffer||console.log("twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features"),this.malloc=e=>new Promise(t=>{let r=this.exports.twr_malloc;t(r(e))}),this.init()}catch(e){throw console.log("WASM instantiate error: "+e+(e.stack?"\n"+e.stack:"")),e}}init(){let e;switch(this.modParams.stdio){case"debug":default:e=0;break;case"div":e=1;break;case"canvas":e=2;break;case"null":e=3}(0,this.exports.twr_wasm_init)(e,this.mem8.length)}async executeC(e){let t=await this.preCallC(e),r=this.executeCImpl(e[0],t);return this.postCallC(t,e),r}async executeCImpl(e,t=[]){if(!this.exports)throw Error("this.exports undefined");if(!this.exports[e])throw Error("executeC: function '"+e+"' not in export table. Use --export wasm-ld flag.");return(0,this.exports[e])(...t)}async preCallC(e){if(e.constructor!==Array)throw Error("executeC: params must be array, first arg is function name");if(0==e.length)throw Error("executeC: missing function name");let t=[],r=0;for(let i=1;i=this.mem32.length)throw Error("invalid index passed to getLong: "+e+", this.mem32.length: "+this.mem32.length);return this.mem32[t]}setLong(e,t){let r=Math.floor(e/4);if(4*r!=e)throw Error("setLong passed non long aligned address");if(r<0||r>=this.mem32.length)throw Error("invalid index passed to setLong: "+e+", this.mem32.length: "+this.mem32.length);this.mem32[r]=t}getDouble(e){let t=Math.floor(e/8);if(8*t!=e)throw Error("getLong passed non Float64 aligned address");return this.memD[t]}setDouble(e,t){let r=Math.floor(e/8);if(8*r!=e)throw Error("setDouble passed non Float64 aligned address");this.memD[r]=t}getShort(e){if(e<0||e>=this.mem8.length)throw Error("invalid index passed to getShort: "+e);return this.mem8[e]+256*this.mem8[e+1]}getString(e,t){let r="",i=0;for(;this.mem8[e+i]&&(void 0===t||i=this.mem8.length)throw Error("invalid index passed to getU8: "+e);let t=new Uint32Array(this.mem8.slice(e,e+8).buffer),r=t[0],i=t[1];if(i<0||i>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU8");if(r<0||r>this.mem8.length-i)throw Error("invalid idx.size passed to getU8");return this.mem8.slice(i,i+r)}getU32Arr(e){if(e<0||e>=this.mem8.length)throw Error("invalid index passed to getU32: "+e);let t=new Uint32Array(this.mem8.slice(e,e+8).buffer),r=t[0],i=t[1];if(i<0||i>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU32");if(r<0||r>this.mem8.length-i)throw Error("invalid idx.size passed to getU32");if(r%4!=0)throw Error("idx.size is not an integer number of 32 bit words");return new Uint32Array(this.mem8.slice(i,i+r).buffer)}}}),o("2Xdsi",function(t,r){e(t.exports,"twrFloatUtil",()=>i);class i{mod;constructor(e){this.mod=e}atod(e){let t=this.mod.getString(e),r=t.trimStart().toUpperCase();return"INF"==r||"+INF"==r?Number.POSITIVE_INFINITY:"-INF"==r?Number.NEGATIVE_INFINITY:Number.parseFloat(t.replaceAll("D","e").replaceAll("d","e"))}dtoa(e,t,r,i){if(-1==i){let i=r.toString();this.mod.copyString(e,t,i)}else{let s=r.toString();s.length>i&&(s=r.toPrecision(i)),this.mod.copyString(e,t,s)}}toFixed(e,t,r,i){let s=r.toFixed(i);this.mod.copyString(e,t,s)}toExponential(e,t,r,i){let s=r.toExponential(i);this.mod.copyString(e,t,s)}fcvtS(e,t,r,i,s,o){let n,a;if(0==e||0==o||0==s||t<1)return 1;let l=0;if(Number.isNaN(r))n="1#QNAN00000000000000000000000000000".slice(0,i+1),a=1;else if(Number.isFinite(r)){if(0==r)n="000000000000000000000000000000000000".slice(0,i),a=0;else{if(r<0&&(l=1,r=Math.abs(r)),i>100||r>1e21||r<1e-99)return this.mod.copyString(e,t,""),this.mod.mem32[s]=0,1;let[o="",h=""]=r.toFixed(i).split(".");"0"==o&&(o=""),o.length>0?(a=o.length,n=o+h):a=(n=h.replace(/^0+/,"")).length-h.length}}else n="1#INF00000000000000000000000000000".slice(0,i+1),a=1;return t-1l);var i,o,n=s("ghrAp"),a=s("47Wdp");(i=o||(o={}))[i.D2D_FILLRECT=1]="D2D_FILLRECT",i[i.D2D_FILLCHAR=5]="D2D_FILLCHAR",i[i.D2D_SETLINEWIDTH=10]="D2D_SETLINEWIDTH",i[i.D2D_SETFILLSTYLERGBA=11]="D2D_SETFILLSTYLERGBA",i[i.D2D_SETFONT=12]="D2D_SETFONT",i[i.D2D_BEGINPATH=13]="D2D_BEGINPATH",i[i.D2D_MOVETO=14]="D2D_MOVETO",i[i.D2D_LINETO=15]="D2D_LINETO",i[i.D2D_FILL=16]="D2D_FILL",i[i.D2D_STROKE=17]="D2D_STROKE",i[i.D2D_SETSTROKESTYLERGBA=18]="D2D_SETSTROKESTYLERGBA",i[i.D2D_ARC=19]="D2D_ARC",i[i.D2D_STROKERECT=20]="D2D_STROKERECT",i[i.D2D_FILLTEXT=21]="D2D_FILLTEXT",i[i.D2D_IMAGEDATA=22]="D2D_IMAGEDATA",i[i.D2D_PUTIMAGEDATA=23]="D2D_PUTIMAGEDATA",i[i.D2D_BEZIERTO=24]="D2D_BEZIERTO",i[i.D2D_MEASURETEXT=25]="D2D_MEASURETEXT",i[i.D2D_SAVE=26]="D2D_SAVE",i[i.D2D_RESTORE=27]="D2D_RESTORE",i[i.D2D_CREATERADIALGRADIENT=28]="D2D_CREATERADIALGRADIENT",i[i.D2D_SETCOLORSTOP=29]="D2D_SETCOLORSTOP",i[i.D2D_SETFILLSTYLEGRADIENT=30]="D2D_SETFILLSTYLEGRADIENT",i[i.D2D_RELEASEID=31]="D2D_RELEASEID",i[i.D2D_CREATELINEARGRADIENT=32]="D2D_CREATELINEARGRADIENT",i[i.D2D_SETFILLSTYLE=33]="D2D_SETFILLSTYLE",i[i.D2D_SETSTROKESTYLE=34]="D2D_SETSTROKESTYLE";class l{ctx;props={charWidth:0,charHeight:0,foreColor:0,backColor:0,widthInChars:0,heightInChars:0,canvasHeight:0,canvasWidth:0};owner;cmdCompleteSignal;canvasKeys;precomputedObjects;constructor(e,t,r){let{forecolor:i,backcolor:s,fontsize:o,isd2dcanvas:l}=t;if(this.owner=r,this.props.widthInChars=t.windim[0],this.props.heightInChars=t.windim[1],this.owner.isWasmModule||(this.cmdCompleteSignal=new a.twrSignal,this.canvasKeys=new n.twrSharedCircularBuffer),this.precomputedObjects={},e){if(!e.getContext)throw Error("attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement");let t=e.getContext("2d");if(!t)throw Error("canvas 2D context not found in twrCanvasConstructor");t.font=o.toString()+"px Courier New",t.textBaseline="top";let r=" ",n=t.measureText(r);this.props.charWidth=Math.ceil(n.width/r.length);let a=t.measureText("X");this.props.charHeight=Math.ceil(a.fontBoundingBoxAscent+a.fontBoundingBoxDescent),l||(e.width=this.props.charWidth*this.props.widthInChars,e.height=this.props.charHeight*this.props.heightInChars),this.props.canvasHeight=e.height,this.props.canvasWidth=e.width;let h=e.getContext("2d");if(!h)throw Error("canvas 2D context not found in twrCanvas.constructor (2nd time)");this.ctx=h,this.ctx.font=o.toString()+"px Courier New",this.ctx.textBaseline="top",h.fillStyle=s,this.props.backColor=Number("0x"+h.fillStyle.slice(1)),h.fillStyle=i,this.props.foreColor=Number("0x"+h.fillStyle.slice(1))}}isValid(){return!!this.ctx}getProxyParams(){if(!this.cmdCompleteSignal||!this.canvasKeys)throw Error("internal error in getProxyParams.");return[this.props,this.cmdCompleteSignal.sharedArray,this.canvasKeys.sharedArray]}getProp(e){this.isValid()||console.log("internal error - getProp called on invalid twrCanvas");let t=this.owner.getString(e);return this.props[t]}drawSeq(e){let t;if(this.isValid()||console.log("internal error - drawSeq called on invalid twrCanvas"),!this.ctx)return;let r=this.owner.getLong(e),i=this.owner.getLong(e+4);for(;;){let e=this.owner.getLong(r+4);switch(e){case o.D2D_FILLRECT:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16),i=this.owner.getDouble(r+24),s=this.owner.getDouble(r+32);this.ctx.fillRect(e,t,i,s)}break;case o.D2D_STROKERECT:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16),i=this.owner.getDouble(r+24),s=this.owner.getDouble(r+32);this.ctx.strokeRect(e,t,i,s)}break;case o.D2D_FILLCHAR:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16),i=String.fromCharCode(this.owner.getShort(r+24));this.ctx.fillText(i,e,t)}break;case o.D2D_FILLTEXT:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16),i=this.owner.getString(this.owner.getLong(r+24));this.ctx.fillText(i,e,t)}break;case o.D2D_MEASURETEXT:{let e=this.owner.getString(this.owner.getLong(r+8)),t=this.owner.getLong(r+12),i=this.ctx.measureText(e);this.owner.setDouble(t+0,i.actualBoundingBoxAscent),this.owner.setDouble(t+8,i.actualBoundingBoxDescent),this.owner.setDouble(t+16,i.actualBoundingBoxLeft),this.owner.setDouble(t+24,i.actualBoundingBoxRight),this.owner.setDouble(t+32,i.fontBoundingBoxAscent),this.owner.setDouble(t+40,i.fontBoundingBoxDescent),this.owner.setDouble(t+48,i.width)}break;case o.D2D_SETFONT:{let e=this.owner.getString(this.owner.getLong(r+8));this.ctx.font=e}break;case o.D2D_SETFILLSTYLERGBA:{let e="#"+("00000000"+this.owner.getLong(r+8).toString(16)).slice(-8);this.ctx.fillStyle=e}break;case o.D2D_SETSTROKESTYLERGBA:{let e="#"+("00000000"+this.owner.getLong(r+8).toString(16)).slice(-8);this.ctx.strokeStyle=e}break;case o.D2D_SETFILLSTYLE:{let e=this.owner.getString(this.owner.getLong(r+8));this.ctx.fillStyle=e}break;case o.D2D_SETSTROKESTYLE:{let e=this.owner.getString(this.owner.getLong(r+8));this.ctx.strokeStyle=e}break;case o.D2D_SETLINEWIDTH:{let e=this.owner.getShort(r+8);this.ctx.lineWidth=e}break;case o.D2D_MOVETO:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16);this.ctx.moveTo(e,t)}break;case o.D2D_LINETO:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16);this.ctx.lineTo(e,t)}break;case o.D2D_BEZIERTO:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16),i=this.owner.getDouble(r+24),s=this.owner.getDouble(r+32),o=this.owner.getDouble(r+40),n=this.owner.getDouble(r+48);this.ctx.bezierCurveTo(e,t,i,s,o,n)}break;case o.D2D_BEGINPATH:this.ctx.beginPath();break;case o.D2D_FILL:this.ctx.fill();break;case o.D2D_SAVE:this.ctx.save();break;case o.D2D_RESTORE:this.ctx.restore();break;case o.D2D_STROKE:this.ctx.stroke();break;case o.D2D_ARC:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16),i=this.owner.getDouble(r+24),s=this.owner.getDouble(r+32),o=this.owner.getDouble(r+40),n=0!=this.owner.getLong(r+48);this.ctx.arc(e,t,i,s,o,n)}break;case o.D2D_IMAGEDATA:{let e=this.owner.getLong(r+8),t=this.owner.getLong(r+12),i=this.owner.getLong(r+16),s=this.owner.getLong(r+20),o=this.owner.getLong(r+24);if(o in this.precomputedObjects&&console.log("warning: D2D_IMAGEDATA ID already exists."),this.owner.isWasmModule){let r=new Uint8ClampedArray(this.owner.memory.buffer,e,t);this.precomputedObjects[o]=new ImageData(r,i,s)}else this.precomputedObjects[o]={mem8:new Uint8Array(this.owner.memory.buffer,e,t),width:i,height:s}}break;case o.D2D_CREATERADIALGRADIENT:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16),i=this.owner.getDouble(r+24),s=this.owner.getDouble(r+32),o=this.owner.getDouble(r+40),n=this.owner.getDouble(r+48),a=this.owner.getLong(r+56),l=this.ctx.createRadialGradient(e,t,i,s,o,n);a in this.precomputedObjects&&console.log("warning: D2D_CREATERADIALGRADIENT ID already exists."),this.precomputedObjects[a]=l}break;case o.D2D_CREATELINEARGRADIENT:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16),i=this.owner.getDouble(r+24),s=this.owner.getDouble(r+32),o=this.owner.getLong(r+40),n=this.ctx.createLinearGradient(e,t,i,s);o in this.precomputedObjects&&console.log("warning: D2D_CREATELINEARGRADIENT ID already exists."),this.precomputedObjects[o]=n}break;case o.D2D_SETCOLORSTOP:{let e=this.owner.getLong(r+8),t=this.owner.getLong(r+12),i=this.owner.getString(this.owner.getLong(r+16));if(!(e in this.precomputedObjects))throw Error("D2D_SETCOLORSTOP with invalid ID: "+e);this.precomputedObjects[e].addColorStop(t,i)}break;case o.D2D_SETFILLSTYLEGRADIENT:{let e=this.owner.getLong(r+8);if(!(e in this.precomputedObjects))throw Error("D2D_SETFILLSTYLEGRADIENT with invalid ID: "+e);let t=this.precomputedObjects[e];this.ctx.fillStyle=t}break;case o.D2D_RELEASEID:{let e=this.owner.getLong(r+8);this.precomputedObjects[e]?delete this.precomputedObjects[e]:console.log("warning: D2D_RELEASEID with undefined ID ",e)}break;case o.D2D_PUTIMAGEDATA:{let e;let t=this.owner.getLong(r+8),i=this.owner.getLong(r+12),s=this.owner.getLong(r+16),o=this.owner.getLong(r+20),n=this.owner.getLong(r+24),a=this.owner.getLong(r+28),l=this.owner.getLong(r+32);if(!(t in this.precomputedObjects))throw Error("D2D_PUTIMAGEDATA with invalid ID: "+t);if(this.owner.isWasmModule)e=this.precomputedObjects[t];else{let r=this.precomputedObjects[t];e=new ImageData(Uint8ClampedArray.from(r.mem8),r.width,r.height)}0==a&&0==l?this.ctx.putImageData(e,i,s):this.ctx.putImageData(e,i,s,o,n,a,l)}break;default:throw Error("unimplemented or unknown Sequence Type in drawSeq: "+e)}if(0==(t=this.owner.getLong(r))){if(r!=i)throw Error("assert type error in twrcanvas, ins!=lastins");break}r=t}this.cmdCompleteSignal&&this.cmdCompleteSignal.signal()}}}),o("47Wdp",function(t,r){var i,s;e(t.exports,"twrSignal",()=>o),(s=i||(i={}))[s.WAITING=0]="WAITING",s[s.SIGNALED=1]="SIGNALED";class o{sharedArray;buf;constructor(e){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSignal constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");e?this.sharedArray=e:this.sharedArray=new SharedArrayBuffer(4),this.buf=new Int32Array(this.sharedArray),this.buf[0]=i.WAITING}signal(){this.buf[0]=i.SIGNALED,Atomics.notify(this.buf,0)}wait(){this.buf[0]==i.WAITING&&Atomics.wait(this.buf,0,i.WAITING)}isSignaled(){return this.buf[0]==i.SIGNALED}reset(){this.buf[0]=i.WAITING}}}),o("lsUl2",function(t,r){e(t.exports,"twrTimeImpl",()=>i);function i(){return Date.now()}}),o("baOio",function(t,r){e(t.exports,"twrWasmModuleAsync",()=>l);var i=s("9FI45"),o=s("aGUWE"),n=s("2vKdq"),a=s("bqeaG");class l extends o.twrWasmModuleInJSMain{myWorker;malloc;loadWasmResolve;loadWasmReject;executeCResolve;executeCReject;initLW=!1;waitingcalls;constructor(e){if(super(e),this.malloc=e=>{throw Error("Error - un-init malloc called.")},!window.Worker)throw Error("This browser doesn't support web workers.");this.myWorker=new Worker(s("aRHnW")),this.myWorker.onmessage=this.processMsg.bind(this)}async loadWasm(e){if(this.initLW)throw Error("twrWasmAsyncModule::loadWasm can only be called once per twrWasmAsyncModule instance");return this.initLW=!0,new Promise((t,r)=>{let i;this.loadWasmResolve=t,this.loadWasmReject=r,this.malloc=e=>this.executeCImpl("twr_malloc",[e]),this.waitingcalls=new n.twrWaitingCalls,i=this.d2dcanvas.isValid()?this.d2dcanvas:this.iocanvas;let s={divProxyParams:this.iodiv.getProxyParams(),canvasProxyParams:i.getProxyParams(),waitingCallsProxyParams:this.waitingcalls.getProxyParams()},o={urlToLoad:new URL(e,document.URL).href,modWorkerParams:s,modParams:this.modParams};this.myWorker.postMessage(["startup",o])})}async executeC(e){let t=await this.preCallC(e);return this.executeCImpl(e[0],t)}async executeCImpl(e,t=[]){return new Promise((r,i)=>{this.executeCResolve=r,this.executeCReject=i,this.myWorker.postMessage(["executeC",e,t])})}keyDownDiv(e){if(!this.iodiv||!this.iodiv.divKeys)throw Error("unexpected undefined twrWasmAsyncModule.divKeys");this.iodiv.divKeys.write((0,a.default)(e).char.charCodeAt(0))}keyDownCanvas(e){if(!this.iocanvas||!this.iocanvas.canvasKeys)throw Error("unexpected undefined twrWasmAsyncModule.canvasKeys");this.iocanvas.canvasKeys.write((0,a.default)(e).char.charCodeAt(0))}processMsg(e){let t=e.data[0],r=e.data[1];switch(t){case"divout":this.iodiv.isValid()?this.iodiv.charOut(r):console.log("error - msg divout received but iodiv is undefined.");break;case"debug":(0,i.twrDebugLogImpl)(r);break;case"drawseq":{let[e]=r;if(this.iocanvas.isValid())this.iocanvas.drawSeq(e);else if(this.d2dcanvas.isValid())this.d2dcanvas.drawSeq(e);else throw Error("msg drawseq received but canvas is undefined.");break}case"setmemory":if(this.memory=r,!this.memory)throw Error("unexpected error - undefined memory in startupOkay msg");this.mem8=new Uint8Array(this.memory.buffer),this.mem32=new Uint32Array(this.memory.buffer),this.memD=new Float64Array(this.memory.buffer);break;case"startupFail":if(this.loadWasmReject)this.loadWasmReject(r);else throw Error("twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmReject)");break;case"startupOkay":if(this.loadWasmResolve)this.loadWasmResolve(void 0);else throw Error("twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmResolve)");break;case"executeCFail":if(this.executeCReject)this.executeCReject(r);else throw Error("twrWasmAsyncModule.processMsg unexpected error (undefined executeCReject)");break;case"executeCOkay":if(this.executeCResolve)this.executeCResolve(r);else throw Error("twrWasmAsyncModule.processMsg unexpected error (undefined executeCResolve)");break;default:if(!this.waitingcalls)throw Error("internal error: this.waitingcalls undefined.");if(!this.waitingcalls.processMessage(t,r))throw Error("twrWasmAsyncModule - unknown and unexpected msgType: "+t)}}}}),o("2vKdq",function(t,r){e(t.exports,"twrWaitingCalls",()=>n);var i=s("47Wdp"),o=s("lsUl2");class n{callCompleteSignal;parameters;constructor(){this.callCompleteSignal=new i.twrSignal,this.parameters=new Uint32Array(new SharedArrayBuffer(4))}startSleep(e){setTimeout(()=>{this.callCompleteSignal.signal()},e)}time(){let e=(0,o.twrTimeImpl)();this.parameters[0]=e,this.callCompleteSignal.signal()}getProxyParams(){return[this.callCompleteSignal.sharedArray,this.parameters.buffer]}processMessage(e,t){switch(e){case"sleep":let[r]=t;this.startSleep(r);break;case"time":this.time();break;default:return!1}return!0}}}),o("bqeaG",function(t,r){e(t.exports,"default",()=>m);let i={a:"selectAll",c:"copy",s:"save",v:"paste",x:"cut",y:"redo",z:"undo"},s={"/":"?",".":">",",":"<","'":'"',";":":","[":"{","]":"}","\\":"|","`":"~","=":"+","-":"_",1:"!",2:"@",3:"#",4:"$",5:"%",6:"^",7:"&",8:"*",9:"(",0:")",a:"A",b:"B",c:"C",d:"D",e:"E",f:"F",g:"G",h:"H",i:"I",j:"J",k:"K",l:"L",m:"M",n:"N",o:"O",p:"P",q:"q",r:"R",s:"S",t:"T",u:"U",v:"V",w:"W",x:"X",y:"Y",z:"Z"},o={};for(let e in s)o[s[e]]=e;let n={0:"\\",8:"backspace",9:"tab",12:"num",13:"enter",16:"shift",17:"ctrl",18:"alt",19:"pause",20:"caps",27:"esc",32:" ",33:"pageup",34:"pagedown",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",44:"print",45:"insert",46:"delete",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"a",66:"b",67:"c",68:"d",69:"e",70:"f",71:"g",72:"h",73:"i",74:"j",75:"k",76:"l",77:"m",78:"n",79:"o",80:"p",81:"q",82:"r",83:"s",84:"t",85:"u",86:"v",87:"w",88:"x",89:"y",90:"z",91:"meta",92:"meta",93:"meta",96:"num0",97:"num1",98:"num2",99:"num3",100:"num4",101:"num5",102:"num6",103:"num7",104:"num8",105:"num9",106:"*",107:"+",108:"num_enter",109:"num_subtract",110:"num_decimal",111:"num_divide",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12",124:"print",144:"num",145:"scroll",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'",223:"`",224:"cmd",225:"alt",57392:"ctrl",63289:"num"},a={"\r":"enter"},l=JSON.parse(JSON.stringify(n));for(let e of Object.keys(a))l[e]=a[e];let h={num_subtract:"-",num_enter:"\n",num_decimal:".",num_divide:"/",enter:"\n",tab:" ",backspace:"\b"},c=["keydown","keyup"],d=()=>{let e=navigator.userAgent;return 0!==(/IEMobile|Windows Phone|Lumia/i.test(e)?"w":/iPhone|iP[oa]d/.test(e)?"i":/Android/.test(e)?"a":/BlackBerry|PlayBook|BB10/.test(e)?"b":/Mobile Safari/.test(e)?"s":/webOS|Mobile|Tablet|Opera Mini|\bCrMo\/|Opera Mobi/i.test(e)?1:0)};function u(e){let t=String.fromCharCode(e);return d()?t:t in o?o[t]:t in l?l[t]:t}function m(e){let t;if("keypress"!==e.type||d()){if("keypress"===e.type&&d())t=u(e.keyCode);else{if(!(c.indexOf(e.type)>-1))return!1;t=void 0!==e.which?n[e.which]:void 0!==e.keyCode?n[e.keyCode]:"enter"}}else t=u(e.charCode);let r=t;return e.shiftKey&&t in s?r=s[t]:e.ctrlKey&&t in i?r=i[t]:t in h&&(r=h[t]),{char:r,key:t}}}),o("aRHnW",function(e,t){var r=s("hoqmg");let i=new URL("twrmodworker.2165e649.js",import.meta.url);e.exports=r(i.toString(),i.origin,!0)}),o("hoqmg",function(e,t){e.exports=function(e,t,r){if(t===self.location.origin)return e;var i=r?"import "+JSON.stringify(e)+";":"importScripts("+JSON.stringify(e)+");";return URL.createObjectURL(new Blob([i],{type:"application/javascript"}))}}),s("eZoLj").register(new URL("",import.meta.url).toString(),JSON.parse('["kjr0c","index.528b9ee5.js","cTHdP","twrmodworker.2165e649.js"]')); +function e(e,t,r,i){Object.defineProperty(e,t,{get:r,set:i,enumerable:!0,configurable:!0})}var t=globalThis,r={},i={},s=t.parcelRequire94c2;null==s&&((s=function(e){if(e in r)return r[e].exports;if(e in i){var t=i[e];delete i[e];var s={id:e,exports:{}};return r[e]=s,t.call(s.exports,s,s.exports),s.exports}var o=Error("Cannot find module '"+e+"'");throw o.code="MODULE_NOT_FOUND",o}).register=function(e,t){i[e]=t},t.parcelRequire94c2=s);var o=s.register;o("eZoLj",function(t,r){e(t.exports,"register",()=>i,e=>i=e);var i,s=new Map;i=function(e,t){for(var r=0;rs("3bkoq").twrWasmModule),e(t.exports,"twrWasmModuleAsync",()=>s("baOio").twrWasmModuleAsync),s("3bkoq"),s("baOio")}),o("3bkoq",function(t,r){e(t.exports,"twrWasmModule",()=>a);var i=s("9FI45"),o=s("aGUWE"),n=s("lsUl2");class a extends o.twrWasmModuleInJSMain{malloc;constructor(e={}){let t;super(e,!0),this.malloc=e=>{throw Error("error - un-init malloc called")},t=this.d2dcanvas.isValid()?this.d2dcanvas:this.iocanvas,this.modParams.imports={twrDebugLog:i.twrDebugLogImpl,twrTime:n.twrTimeImpl,twrDivCharOut:this.iodiv.charOut.bind(this.iodiv),twrCanvasGetProp:t.getProp.bind(t),twrCanvasDrawSeq:t.drawSeq.bind(t),twrCanvasCharIn:this.null,twrCanvasInkey:this.null,twrDivCharIn:this.null,twrSleep:this.null,twrSin:Math.sin,twrCos:Math.cos,twrTan:Math.tan,twrFAbs:Math.abs,twrACos:Math.acos,twrASin:Math.asin,twrATan:Math.atan,twrExp:Math.exp,twrFloor:Math.floor,twrCeil:Math.ceil,twrFMod:function(e,t){return e%t},twrLog:Math.log,twrPow:Math.pow,twrSqrt:Math.sqrt,twrTrunc:Math.trunc,twrDtoa:this.floatUtil.dtoa.bind(this.floatUtil),twrToFixed:this.floatUtil.toFixed.bind(this.floatUtil),twrToExponential:this.floatUtil.toExponential.bind(this.floatUtil),twrAtod:this.floatUtil.atod.bind(this.floatUtil),twrFcvtS:this.floatUtil.fcvtS.bind(this.floatUtil)}}null(e){throw Error("call to unimplemented twrXXX import in twrWasmModule. Use twrWasmModuleAsync ?")}}}),o("9FI45",function(t,r){e(t.exports,"twrDebugLogImpl",()=>s);let i="";function s(e){10==e||3==e?(console.log(i),i=""):(i+=String.fromCharCode(e)).length>=200&&(console.log(i),i="")}}),o("aGUWE",function(t,r){e(t.exports,"twrWasmModuleInJSMain",()=>a);var i=s("fDEU7"),o=s("5hO33"),n=s("5LsZ0");class a extends o.twrWasmModuleBase{iocanvas;d2dcanvas;iodiv;modParams;constructor(e={},t=!1){if(super(t),"undefined"==typeof document)throw Error("twrWasmModuleJSMain should only be created in JavaScript Main.");let r=document.getElementById("twr_iodiv"),s=document.getElementById("twr_iocanvas"),o=document.getElementById("twr_d2dcanvas");if(s&&o)throw Error("Both twr_iocanvas and twr_d2dcanvas defined. Currently only one canvas allowed.");if("div"==e.stdio&&!r)throw Error("twrWasmModuleBase opts=='div' but twr_iodiv not defined");if("canvas"==e.stdio&&!s)throw Error("twrWasmModuleBase, opts=='canvas' but twr_iocanvas not defined");if(e.isd2dcanvas&&!o)throw Error("twrWasmModuleBase, opts.isdrawcanvas==true but twr_d2dcanvas not defined");e=r?{stdio:"div",...e}:s?{stdio:"canvas",...e}:{stdio:"debug",...e},r||s?console.log("tiny-wasm-runtime: stdio set to: ",e.stdio):console.log("Since neither twr_iocanvas nor twr_iodiv is defined, stdout directed to debug console."),(e=s?{windim:[64,16],...e}:{windim:[0,0],...e}).imports||(e.imports={});let a=!1;e.backcolor||(a=!0,e.backcolor="black"),e.forecolor||(a=!0,e.forecolor="white"),e.fontsize||(a=!0,e.fontsize=16),void 0===e.isd2dcanvas&&(o?e.isd2dcanvas=!0:e.isd2dcanvas=!1),this.modParams={stdio:e.stdio,windim:e.windim,imports:e.imports,forecolor:e.forecolor,backcolor:e.backcolor,styleIsDefault:a,fontsize:e.fontsize,isd2dcanvas:e.isd2dcanvas},this.iodiv=new i.twrDiv(r,this.modParams,this),this.iocanvas=new n.twrCanvas(s,this.modParams,this),this.d2dcanvas=new n.twrCanvas(o,this.modParams,this)}divLog(...e){for(var t=0;to);var i=s("ghrAp");class o{div;divKeys;CURSOR=String.fromCharCode(9611);cursorOn=!1;lastChar=0;extraBR=!1;owner;constructor(e,t,r){this.div=e,this.owner=r,this.owner.isWasmModule||(this.divKeys=new i.twrSharedCircularBuffer),this.div&&!t.styleIsDefault&&(this.div.style.backgroundColor=t.backcolor,this.div.style.color=t.forecolor,this.div.style.font=t.fontsize.toString()+"px arial")}isValid(){return!!this.div}getProxyParams(){if(!this.divKeys)throw Error("internal error in getProxyParams.");return[this.divKeys.sharedArray]}charOut(e){if(this.div){switch(this.extraBR&&(this.extraBR=!1,this.cursorOn&&(this.div.innerHTML=this.div.innerHTML.slice(0,-1)),this.div.innerHTML=this.div.innerHTML.slice(0,-4),this.cursorOn&&(this.div.innerHTML+=this.CURSOR)),e){case 10:case 13:if(10==e&&13==this.lastChar)break;this.cursorOn&&(this.div.innerHTML=this.div.innerHTML.slice(0,-1)),this.div.innerHTML+="

",this.extraBR=!0,this.cursorOn&&(this.div.innerHTML+=this.CURSOR);let t=this.div.getBoundingClientRect();window.scrollTo(0,t.height+100);break;case 8:this.cursorOn&&(this.div.innerHTML=this.div.innerHTML.slice(0,-1)),this.div.innerHTML=this.div.innerHTML.slice(0,-1),this.cursorOn&&(this.div.innerHTML+=this.CURSOR);break;case 14:this.cursorOn||(this.cursorOn=!0,this.div.innerHTML+=this.CURSOR,this.div.focus());break;case 15:this.cursorOn&&(this.cursorOn=!1,this.div.innerHTML=this.div.innerHTML.slice(0,-1));break;default:this.cursorOn&&(this.div.innerHTML=this.div.innerHTML.slice(0,-1)),this.div.innerHTML+=String.fromCharCode(e),this.cursorOn&&(this.div.innerHTML+=this.CURSOR)}this.lastChar=e}}stringOut(e){for(let t=0;ti);class i{sharedArray;buf;constructor(e){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSharedCircularBuffer constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");e?this.sharedArray=e:this.sharedArray=new SharedArrayBuffer(1032),this.buf=new Int32Array(this.sharedArray),this.buf[256]=0,this.buf[257]=0}write(e){let t=this.buf[257];this.buf[t]=e,256==++t&&(t=0),this.buf[257]=t,Atomics.notify(this.buf,257)}read(){if(this.isEmpty())return -1;{let e=this.buf[256],t=this.buf[e];return e++,this.buf[256]=e,t}}readWait(){if(this.isEmpty()){let e=this.buf[256];Atomics.wait(this.buf,257,e)}return this.read()}isEmpty(){return this.buf[256]==this.buf[257]}}}),o("5hO33",function(t,r){e(t.exports,"twrWasmModuleBase",()=>o);var i=s("2Xdsi");class o{memory;mem8;mem32;memD;exports;isWorker=!1;isWasmModule;floatUtil;constructor(e=!1){this.isWasmModule=e,this.mem8=new Uint8Array,this.mem32=new Uint32Array,this.memD=new Float64Array,this.floatUtil=new i.twrFloatUtil(this)}async loadWasm(e){let t;try{t=await fetch(e)}catch(t){throw console.log("loadWasm() failed to fetch: "+e),t}if(!t.ok)throw Error("fetch response error on file '"+e+"'\n"+t.statusText);try{let e=await t.arrayBuffer(),r={...this.modParams.imports},i=await WebAssembly.instantiate(e,{env:r});if(this.exports=i.instance.exports,!this.exports)throw Error("Unexpected error - undefined instance.exports");if(this.memory)throw Error("unexpected error -- this.memory already set");if(this.memory=this.exports.memory,!this.memory)throw Error("Unexpected error - undefined exports.memory");this.mem8=new Uint8Array(this.memory.buffer),this.mem32=new Uint32Array(this.memory.buffer),this.memD=new Float64Array(this.memory.buffer),this.isWorker&&(this.memory.buffer instanceof ArrayBuffer&&console.log("twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)"),postMessage(["setmemory",this.memory])),!this.isWasmModule||this.memory.buffer instanceof ArrayBuffer||console.log("twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features"),this.malloc=e=>new Promise(t=>{let r=this.exports.twr_malloc;t(r(e))}),this.init()}catch(e){throw console.log("WASM instantiate error: "+e+(e.stack?"\n"+e.stack:"")),e}}init(){let e;switch(this.modParams.stdio){case"debug":default:e=0;break;case"div":e=1;break;case"canvas":e=2;break;case"null":e=3}(0,this.exports.twr_wasm_init)(e,this.mem8.length)}async callC(e){let t=await this.preCallC(e),r=this.callCImpl(e[0],t);return this.postCallC(t,e),r}async callCImpl(e,t=[]){if(!this.exports)throw Error("this.exports undefined");if(!this.exports[e])throw Error("callC: function '"+e+"' not in export table. Use --export wasm-ld flag.");return(0,this.exports[e])(...t)}async preCallC(e){if(e.constructor!==Array)throw Error("callC: params must be array, first arg is function name");if(0==e.length)throw Error("callC: missing function name");let t=[],r=0;for(let i=1;i=this.mem32.length)throw Error("invalid index passed to getLong: "+e+", this.mem32.length: "+this.mem32.length);return this.mem32[t]}setLong(e,t){let r=Math.floor(e/4);if(4*r!=e)throw Error("setLong passed non long aligned address");if(r<0||r>=this.mem32.length)throw Error("invalid index passed to setLong: "+e+", this.mem32.length: "+this.mem32.length);this.mem32[r]=t}getDouble(e){let t=Math.floor(e/8);if(8*t!=e)throw Error("getLong passed non Float64 aligned address");return this.memD[t]}setDouble(e,t){let r=Math.floor(e/8);if(8*r!=e)throw Error("setDouble passed non Float64 aligned address");this.memD[r]=t}getShort(e){if(e<0||e>=this.mem8.length)throw Error("invalid index passed to getShort: "+e);return this.mem8[e]+256*this.mem8[e+1]}getString(e,t){let r="",i=0;for(;this.mem8[e+i]&&(void 0===t||i=this.mem8.length)throw Error("invalid index passed to getU8: "+e);let t=new Uint32Array(this.mem8.slice(e,e+8).buffer),r=t[0],i=t[1];if(i<0||i>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU8");if(r<0||r>this.mem8.length-i)throw Error("invalid idx.size passed to getU8");return this.mem8.slice(i,i+r)}getU32Arr(e){if(e<0||e>=this.mem8.length)throw Error("invalid index passed to getU32: "+e);let t=new Uint32Array(this.mem8.slice(e,e+8).buffer),r=t[0],i=t[1];if(i<0||i>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU32");if(r<0||r>this.mem8.length-i)throw Error("invalid idx.size passed to getU32");if(r%4!=0)throw Error("idx.size is not an integer number of 32 bit words");return new Uint32Array(this.mem8.slice(i,i+r).buffer)}}}),o("2Xdsi",function(t,r){e(t.exports,"twrFloatUtil",()=>i);class i{mod;constructor(e){this.mod=e}atod(e){let t=this.mod.getString(e),r=t.trimStart().toUpperCase();return"INF"==r||"+INF"==r?Number.POSITIVE_INFINITY:"-INF"==r?Number.NEGATIVE_INFINITY:Number.parseFloat(t.replaceAll("D","e").replaceAll("d","e"))}dtoa(e,t,r,i){if(-1==i){let i=r.toString();this.mod.copyString(e,t,i)}else{let s=r.toString();s.length>i&&(s=r.toPrecision(i)),this.mod.copyString(e,t,s)}}toFixed(e,t,r,i){let s=r.toFixed(i);this.mod.copyString(e,t,s)}toExponential(e,t,r,i){let s=r.toExponential(i);this.mod.copyString(e,t,s)}fcvtS(e,t,r,i,s,o){let n,a;if(0==e||0==o||0==s||t<1)return 1;let l=0;if(Number.isNaN(r))n="1#QNAN00000000000000000000000000000".slice(0,i+1),a=1;else if(Number.isFinite(r)){if(0==r)n="000000000000000000000000000000000000".slice(0,i),a=0;else{if(r<0&&(l=1,r=Math.abs(r)),i>100||r>1e21||r<1e-99)return this.mod.copyString(e,t,""),this.mod.mem32[s]=0,1;let[o="",h=""]=r.toFixed(i).split(".");"0"==o&&(o=""),o.length>0?(a=o.length,n=o+h):a=(n=h.replace(/^0+/,"")).length-h.length}}else n="1#INF00000000000000000000000000000".slice(0,i+1),a=1;return t-1l);var i,o,n=s("ghrAp"),a=s("47Wdp");(i=o||(o={}))[i.D2D_FILLRECT=1]="D2D_FILLRECT",i[i.D2D_FILLCHAR=5]="D2D_FILLCHAR",i[i.D2D_SETLINEWIDTH=10]="D2D_SETLINEWIDTH",i[i.D2D_SETFILLSTYLERGBA=11]="D2D_SETFILLSTYLERGBA",i[i.D2D_SETFONT=12]="D2D_SETFONT",i[i.D2D_BEGINPATH=13]="D2D_BEGINPATH",i[i.D2D_MOVETO=14]="D2D_MOVETO",i[i.D2D_LINETO=15]="D2D_LINETO",i[i.D2D_FILL=16]="D2D_FILL",i[i.D2D_STROKE=17]="D2D_STROKE",i[i.D2D_SETSTROKESTYLERGBA=18]="D2D_SETSTROKESTYLERGBA",i[i.D2D_ARC=19]="D2D_ARC",i[i.D2D_STROKERECT=20]="D2D_STROKERECT",i[i.D2D_FILLTEXT=21]="D2D_FILLTEXT",i[i.D2D_IMAGEDATA=22]="D2D_IMAGEDATA",i[i.D2D_PUTIMAGEDATA=23]="D2D_PUTIMAGEDATA",i[i.D2D_BEZIERTO=24]="D2D_BEZIERTO",i[i.D2D_MEASURETEXT=25]="D2D_MEASURETEXT",i[i.D2D_SAVE=26]="D2D_SAVE",i[i.D2D_RESTORE=27]="D2D_RESTORE",i[i.D2D_CREATERADIALGRADIENT=28]="D2D_CREATERADIALGRADIENT",i[i.D2D_SETCOLORSTOP=29]="D2D_SETCOLORSTOP",i[i.D2D_SETFILLSTYLEGRADIENT=30]="D2D_SETFILLSTYLEGRADIENT",i[i.D2D_RELEASEID=31]="D2D_RELEASEID",i[i.D2D_CREATELINEARGRADIENT=32]="D2D_CREATELINEARGRADIENT",i[i.D2D_SETFILLSTYLE=33]="D2D_SETFILLSTYLE",i[i.D2D_SETSTROKESTYLE=34]="D2D_SETSTROKESTYLE";class l{ctx;props={charWidth:0,charHeight:0,foreColor:0,backColor:0,widthInChars:0,heightInChars:0,canvasHeight:0,canvasWidth:0};owner;cmdCompleteSignal;canvasKeys;precomputedObjects;constructor(e,t,r){let{forecolor:i,backcolor:s,fontsize:o,isd2dcanvas:l}=t;if(this.owner=r,this.props.widthInChars=t.windim[0],this.props.heightInChars=t.windim[1],this.owner.isWasmModule||(this.cmdCompleteSignal=new a.twrSignal,this.canvasKeys=new n.twrSharedCircularBuffer),this.precomputedObjects={},e){if(!e.getContext)throw Error("attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement");let t=e.getContext("2d");if(!t)throw Error("canvas 2D context not found in twrCanvasConstructor");t.font=o.toString()+"px Courier New",t.textBaseline="top";let r=" ",n=t.measureText(r);this.props.charWidth=Math.ceil(n.width/r.length);let a=t.measureText("X");this.props.charHeight=Math.ceil(a.fontBoundingBoxAscent+a.fontBoundingBoxDescent),l||(e.width=this.props.charWidth*this.props.widthInChars,e.height=this.props.charHeight*this.props.heightInChars),this.props.canvasHeight=e.height,this.props.canvasWidth=e.width;let h=e.getContext("2d");if(!h)throw Error("canvas 2D context not found in twrCanvas.constructor (2nd time)");this.ctx=h,this.ctx.font=o.toString()+"px Courier New",this.ctx.textBaseline="top",h.fillStyle=s,this.props.backColor=Number("0x"+h.fillStyle.slice(1)),h.fillStyle=i,this.props.foreColor=Number("0x"+h.fillStyle.slice(1))}}isValid(){return!!this.ctx}getProxyParams(){if(!this.cmdCompleteSignal||!this.canvasKeys)throw Error("internal error in getProxyParams.");return[this.props,this.cmdCompleteSignal.sharedArray,this.canvasKeys.sharedArray]}getProp(e){this.isValid()||console.log("internal error - getProp called on invalid twrCanvas");let t=this.owner.getString(e);return this.props[t]}drawSeq(e){let t;if(this.isValid()||console.log("internal error - drawSeq called on invalid twrCanvas"),!this.ctx)return;let r=this.owner.getLong(e),i=this.owner.getLong(e+4);for(;;){let e=this.owner.getLong(r+4);switch(e){case o.D2D_FILLRECT:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16),i=this.owner.getDouble(r+24),s=this.owner.getDouble(r+32);this.ctx.fillRect(e,t,i,s)}break;case o.D2D_STROKERECT:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16),i=this.owner.getDouble(r+24),s=this.owner.getDouble(r+32);this.ctx.strokeRect(e,t,i,s)}break;case o.D2D_FILLCHAR:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16),i=String.fromCharCode(this.owner.getShort(r+24));this.ctx.fillText(i,e,t)}break;case o.D2D_FILLTEXT:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16),i=this.owner.getString(this.owner.getLong(r+24));this.ctx.fillText(i,e,t)}break;case o.D2D_MEASURETEXT:{let e=this.owner.getString(this.owner.getLong(r+8)),t=this.owner.getLong(r+12),i=this.ctx.measureText(e);this.owner.setDouble(t+0,i.actualBoundingBoxAscent),this.owner.setDouble(t+8,i.actualBoundingBoxDescent),this.owner.setDouble(t+16,i.actualBoundingBoxLeft),this.owner.setDouble(t+24,i.actualBoundingBoxRight),this.owner.setDouble(t+32,i.fontBoundingBoxAscent),this.owner.setDouble(t+40,i.fontBoundingBoxDescent),this.owner.setDouble(t+48,i.width)}break;case o.D2D_SETFONT:{let e=this.owner.getString(this.owner.getLong(r+8));this.ctx.font=e}break;case o.D2D_SETFILLSTYLERGBA:{let e="#"+("00000000"+this.owner.getLong(r+8).toString(16)).slice(-8);this.ctx.fillStyle=e}break;case o.D2D_SETSTROKESTYLERGBA:{let e="#"+("00000000"+this.owner.getLong(r+8).toString(16)).slice(-8);this.ctx.strokeStyle=e}break;case o.D2D_SETFILLSTYLE:{let e=this.owner.getString(this.owner.getLong(r+8));this.ctx.fillStyle=e}break;case o.D2D_SETSTROKESTYLE:{let e=this.owner.getString(this.owner.getLong(r+8));this.ctx.strokeStyle=e}break;case o.D2D_SETLINEWIDTH:{let e=this.owner.getShort(r+8);this.ctx.lineWidth=e}break;case o.D2D_MOVETO:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16);this.ctx.moveTo(e,t)}break;case o.D2D_LINETO:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16);this.ctx.lineTo(e,t)}break;case o.D2D_BEZIERTO:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16),i=this.owner.getDouble(r+24),s=this.owner.getDouble(r+32),o=this.owner.getDouble(r+40),n=this.owner.getDouble(r+48);this.ctx.bezierCurveTo(e,t,i,s,o,n)}break;case o.D2D_BEGINPATH:this.ctx.beginPath();break;case o.D2D_FILL:this.ctx.fill();break;case o.D2D_SAVE:this.ctx.save();break;case o.D2D_RESTORE:this.ctx.restore();break;case o.D2D_STROKE:this.ctx.stroke();break;case o.D2D_ARC:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16),i=this.owner.getDouble(r+24),s=this.owner.getDouble(r+32),o=this.owner.getDouble(r+40),n=0!=this.owner.getLong(r+48);this.ctx.arc(e,t,i,s,o,n)}break;case o.D2D_IMAGEDATA:{let e=this.owner.getLong(r+8),t=this.owner.getLong(r+12),i=this.owner.getLong(r+16),s=this.owner.getLong(r+20),o=this.owner.getLong(r+24);if(o in this.precomputedObjects&&console.log("warning: D2D_IMAGEDATA ID already exists."),this.owner.isWasmModule){let r=new Uint8ClampedArray(this.owner.memory.buffer,e,t);this.precomputedObjects[o]=new ImageData(r,i,s)}else this.precomputedObjects[o]={mem8:new Uint8Array(this.owner.memory.buffer,e,t),width:i,height:s}}break;case o.D2D_CREATERADIALGRADIENT:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16),i=this.owner.getDouble(r+24),s=this.owner.getDouble(r+32),o=this.owner.getDouble(r+40),n=this.owner.getDouble(r+48),a=this.owner.getLong(r+56),l=this.ctx.createRadialGradient(e,t,i,s,o,n);a in this.precomputedObjects&&console.log("warning: D2D_CREATERADIALGRADIENT ID already exists."),this.precomputedObjects[a]=l}break;case o.D2D_CREATELINEARGRADIENT:{let e=this.owner.getDouble(r+8),t=this.owner.getDouble(r+16),i=this.owner.getDouble(r+24),s=this.owner.getDouble(r+32),o=this.owner.getLong(r+40),n=this.ctx.createLinearGradient(e,t,i,s);o in this.precomputedObjects&&console.log("warning: D2D_CREATELINEARGRADIENT ID already exists."),this.precomputedObjects[o]=n}break;case o.D2D_SETCOLORSTOP:{let e=this.owner.getLong(r+8),t=this.owner.getLong(r+12),i=this.owner.getString(this.owner.getLong(r+16));if(!(e in this.precomputedObjects))throw Error("D2D_SETCOLORSTOP with invalid ID: "+e);this.precomputedObjects[e].addColorStop(t,i)}break;case o.D2D_SETFILLSTYLEGRADIENT:{let e=this.owner.getLong(r+8);if(!(e in this.precomputedObjects))throw Error("D2D_SETFILLSTYLEGRADIENT with invalid ID: "+e);let t=this.precomputedObjects[e];this.ctx.fillStyle=t}break;case o.D2D_RELEASEID:{let e=this.owner.getLong(r+8);this.precomputedObjects[e]?delete this.precomputedObjects[e]:console.log("warning: D2D_RELEASEID with undefined ID ",e)}break;case o.D2D_PUTIMAGEDATA:{let e;let t=this.owner.getLong(r+8),i=this.owner.getLong(r+12),s=this.owner.getLong(r+16),o=this.owner.getLong(r+20),n=this.owner.getLong(r+24),a=this.owner.getLong(r+28),l=this.owner.getLong(r+32);if(!(t in this.precomputedObjects))throw Error("D2D_PUTIMAGEDATA with invalid ID: "+t);if(this.owner.isWasmModule)e=this.precomputedObjects[t];else{let r=this.precomputedObjects[t];e=new ImageData(Uint8ClampedArray.from(r.mem8),r.width,r.height)}0==a&&0==l?this.ctx.putImageData(e,i,s):this.ctx.putImageData(e,i,s,o,n,a,l)}break;default:throw Error("unimplemented or unknown Sequence Type in drawSeq: "+e)}if(0==(t=this.owner.getLong(r))){if(r!=i)throw Error("assert type error in twrcanvas, ins!=lastins");break}r=t}this.cmdCompleteSignal&&this.cmdCompleteSignal.signal()}}}),o("47Wdp",function(t,r){var i,s;e(t.exports,"twrSignal",()=>o),(s=i||(i={}))[s.WAITING=0]="WAITING",s[s.SIGNALED=1]="SIGNALED";class o{sharedArray;buf;constructor(e){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSignal constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");e?this.sharedArray=e:this.sharedArray=new SharedArrayBuffer(4),this.buf=new Int32Array(this.sharedArray),this.buf[0]=i.WAITING}signal(){this.buf[0]=i.SIGNALED,Atomics.notify(this.buf,0)}wait(){this.buf[0]==i.WAITING&&Atomics.wait(this.buf,0,i.WAITING)}isSignaled(){return this.buf[0]==i.SIGNALED}reset(){this.buf[0]=i.WAITING}}}),o("lsUl2",function(t,r){e(t.exports,"twrTimeImpl",()=>i);function i(){return Date.now()}}),o("baOio",function(t,r){e(t.exports,"twrWasmModuleAsync",()=>l);var i=s("9FI45"),o=s("aGUWE"),n=s("2vKdq"),a=s("bqeaG");class l extends o.twrWasmModuleInJSMain{myWorker;malloc;loadWasmResolve;loadWasmReject;callCResolve;callCReject;initLW=!1;waitingcalls;constructor(e){if(super(e),this.malloc=e=>{throw Error("Error - un-init malloc called.")},!window.Worker)throw Error("This browser doesn't support web workers.");this.myWorker=new Worker(s("aRHnW")),this.myWorker.onmessage=this.processMsg.bind(this)}async loadWasm(e){if(this.initLW)throw Error("twrWasmAsyncModule::loadWasm can only be called once per twrWasmAsyncModule instance");return this.initLW=!0,new Promise((t,r)=>{let i;this.loadWasmResolve=t,this.loadWasmReject=r,this.malloc=e=>this.callCImpl("twr_malloc",[e]),this.waitingcalls=new n.twrWaitingCalls,i=this.d2dcanvas.isValid()?this.d2dcanvas:this.iocanvas;let s={divProxyParams:this.iodiv.getProxyParams(),canvasProxyParams:i.getProxyParams(),waitingCallsProxyParams:this.waitingcalls.getProxyParams()},o={urlToLoad:new URL(e,document.URL).href,modWorkerParams:s,modParams:this.modParams};this.myWorker.postMessage(["startup",o])})}async callC(e){let t=await this.preCallC(e);return this.callCImpl(e[0],t)}async callCImpl(e,t=[]){return new Promise((r,i)=>{this.callCResolve=r,this.callCReject=i,this.myWorker.postMessage(["callC",e,t])})}keyDownDiv(e){if(!this.iodiv||!this.iodiv.divKeys)throw Error("unexpected undefined twrWasmAsyncModule.divKeys");this.iodiv.divKeys.write((0,a.default)(e).char.charCodeAt(0))}keyDownCanvas(e){if(!this.iocanvas||!this.iocanvas.canvasKeys)throw Error("unexpected undefined twrWasmAsyncModule.canvasKeys");this.iocanvas.canvasKeys.write((0,a.default)(e).char.charCodeAt(0))}processMsg(e){let t=e.data[0],r=e.data[1];switch(t){case"divout":this.iodiv.isValid()?this.iodiv.charOut(r):console.log("error - msg divout received but iodiv is undefined.");break;case"debug":(0,i.twrDebugLogImpl)(r);break;case"drawseq":{let[e]=r;if(this.iocanvas.isValid())this.iocanvas.drawSeq(e);else if(this.d2dcanvas.isValid())this.d2dcanvas.drawSeq(e);else throw Error("msg drawseq received but canvas is undefined.");break}case"setmemory":if(this.memory=r,!this.memory)throw Error("unexpected error - undefined memory in startupOkay msg");this.mem8=new Uint8Array(this.memory.buffer),this.mem32=new Uint32Array(this.memory.buffer),this.memD=new Float64Array(this.memory.buffer);break;case"startupFail":if(this.loadWasmReject)this.loadWasmReject(r);else throw Error("twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmReject)");break;case"startupOkay":if(this.loadWasmResolve)this.loadWasmResolve(void 0);else throw Error("twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmResolve)");break;case"callCFail":if(this.callCReject)this.callCReject(r);else throw Error("twrWasmAsyncModule.processMsg unexpected error (undefined callCReject)");break;case"callCOkay":if(this.callCResolve)this.callCResolve(r);else throw Error("twrWasmAsyncModule.processMsg unexpected error (undefined callCResolve)");break;default:if(!this.waitingcalls)throw Error("internal error: this.waitingcalls undefined.");if(!this.waitingcalls.processMessage(t,r))throw Error("twrWasmAsyncModule - unknown and unexpected msgType: "+t)}}}}),o("2vKdq",function(t,r){e(t.exports,"twrWaitingCalls",()=>n);var i=s("47Wdp"),o=s("lsUl2");class n{callCompleteSignal;parameters;constructor(){this.callCompleteSignal=new i.twrSignal,this.parameters=new Uint32Array(new SharedArrayBuffer(4))}startSleep(e){setTimeout(()=>{this.callCompleteSignal.signal()},e)}time(){let e=(0,o.twrTimeImpl)();this.parameters[0]=e,this.callCompleteSignal.signal()}getProxyParams(){return[this.callCompleteSignal.sharedArray,this.parameters.buffer]}processMessage(e,t){switch(e){case"sleep":let[r]=t;this.startSleep(r);break;case"time":this.time();break;default:return!1}return!0}}}),o("bqeaG",function(t,r){e(t.exports,"default",()=>m);let i={a:"selectAll",c:"copy",s:"save",v:"paste",x:"cut",y:"redo",z:"undo"},s={"/":"?",".":">",",":"<","'":'"',";":":","[":"{","]":"}","\\":"|","`":"~","=":"+","-":"_",1:"!",2:"@",3:"#",4:"$",5:"%",6:"^",7:"&",8:"*",9:"(",0:")",a:"A",b:"B",c:"C",d:"D",e:"E",f:"F",g:"G",h:"H",i:"I",j:"J",k:"K",l:"L",m:"M",n:"N",o:"O",p:"P",q:"q",r:"R",s:"S",t:"T",u:"U",v:"V",w:"W",x:"X",y:"Y",z:"Z"},o={};for(let e in s)o[s[e]]=e;let n={0:"\\",8:"backspace",9:"tab",12:"num",13:"enter",16:"shift",17:"ctrl",18:"alt",19:"pause",20:"caps",27:"esc",32:" ",33:"pageup",34:"pagedown",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",44:"print",45:"insert",46:"delete",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"a",66:"b",67:"c",68:"d",69:"e",70:"f",71:"g",72:"h",73:"i",74:"j",75:"k",76:"l",77:"m",78:"n",79:"o",80:"p",81:"q",82:"r",83:"s",84:"t",85:"u",86:"v",87:"w",88:"x",89:"y",90:"z",91:"meta",92:"meta",93:"meta",96:"num0",97:"num1",98:"num2",99:"num3",100:"num4",101:"num5",102:"num6",103:"num7",104:"num8",105:"num9",106:"*",107:"+",108:"num_enter",109:"num_subtract",110:"num_decimal",111:"num_divide",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12",124:"print",144:"num",145:"scroll",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'",223:"`",224:"cmd",225:"alt",57392:"ctrl",63289:"num"},a={"\r":"enter"},l=JSON.parse(JSON.stringify(n));for(let e of Object.keys(a))l[e]=a[e];let h={num_subtract:"-",num_enter:"\n",num_decimal:".",num_divide:"/",enter:"\n",tab:" ",backspace:"\b"},c=["keydown","keyup"],d=()=>{let e=navigator.userAgent;return 0!==(/IEMobile|Windows Phone|Lumia/i.test(e)?"w":/iPhone|iP[oa]d/.test(e)?"i":/Android/.test(e)?"a":/BlackBerry|PlayBook|BB10/.test(e)?"b":/Mobile Safari/.test(e)?"s":/webOS|Mobile|Tablet|Opera Mini|\bCrMo\/|Opera Mobi/i.test(e)?1:0)};function u(e){let t=String.fromCharCode(e);return d()?t:t in o?o[t]:t in l?l[t]:t}function m(e){let t;if("keypress"!==e.type||d()){if("keypress"===e.type&&d())t=u(e.keyCode);else{if(!(c.indexOf(e.type)>-1))return!1;t=void 0!==e.which?n[e.which]:void 0!==e.keyCode?n[e.keyCode]:"enter"}}else t=u(e.charCode);let r=t;return e.shiftKey&&t in s?r=s[t]:e.ctrlKey&&t in i?r=i[t]:t in h&&(r=h[t]),{char:r,key:t}}}),o("aRHnW",function(e,t){var r=s("hoqmg");let i=new URL("twrmodworker.2165e649.js",import.meta.url);e.exports=r(i.toString(),i.origin,!0)}),o("hoqmg",function(e,t){e.exports=function(e,t,r){if(t===self.location.origin)return e;var i=r?"import "+JSON.stringify(e)+";":"importScripts("+JSON.stringify(e)+");";return URL.createObjectURL(new Blob([i],{type:"application/javascript"}))}}),s("eZoLj").register(new URL("",import.meta.url).toString(),JSON.parse('["kjr0c","index.528b9ee5.js","cTHdP","twrmodworker.2165e649.js"]')); //# sourceMappingURL=index.528b9ee5.js.map diff --git a/azure/examples/function-calls/dist/index.528b9ee5.js.map b/azure/examples/function-calls/dist/index.528b9ee5.js.map index 15cd86a4..717bc7c2 100644 --- a/azure/examples/function-calls/dist/index.528b9ee5.js.map +++ b/azure/examples/function-calls/dist/index.528b9ee5.js.map @@ -1 +1 @@ -{"mappings":"A,S,E,C,C,C,C,C,C,C,E,O,c,C,E,E,C,I,E,I,E,W,C,E,a,C,C,E,C,I,E,W,E,C,E,E,C,E,E,E,iB,A,O,I,A,C,E,S,C,E,G,K,E,O,C,C,E,C,O,C,G,K,E,C,I,E,C,C,E,A,Q,C,C,E,C,I,E,C,G,E,Q,C,C,E,O,C,C,E,C,E,E,I,C,E,O,C,E,E,O,E,E,O,A,C,I,E,A,M,uB,E,I,O,E,I,C,mB,C,C,E,Q,C,S,C,C,C,E,C,C,E,C,C,E,E,iB,C,G,I,E,E,Q,C,E,Q,S,C,C,C,E,E,E,O,C,W,I,E,A,G,E,GCEA,IAgBA,EAhBI,EAAU,IAAI,IAgBlB,EAfA,SAAkB,CAAO,CAAE,CAAQ,EACjC,IAAK,IAAI,EAAI,EAAG,EAAI,EAAS,MAAM,CAAG,EAAG,GAAK,EAC5C,EAAQ,GAAG,CAAC,CAAQ,CAAC,EAAE,CAAE,CACvB,QAAS,EACT,KAAM,CAAQ,CAAC,EAAI,EAAE,AACvB,EAEJ,C,G,E,Q,S,C,C,C,E,E,E,O,C,gB,I,A,E,S,a,E,E,E,O,C,qB,I,A,E,S,kB,E,E,S,E,Q,G,E,Q,S,C,C,C,E,E,E,O,C,gB,I,G,I,E,E,S,E,E,S,E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AAO,CAChB,CAAwB,CAAC,EAAM,OAAO,CAAC,CAEvC,cATR,EAAM,EAAwB,EAAM,QAAQ,EAe9C,IAAI,EAAO,EASX,OARI,EAAM,QAAQ,EAAI,KAAO,EAC3B,EAAO,CAAkB,CAAC,EAAI,CACrB,EAAM,OAAO,EAAI,KAAO,EACjC,EAAO,CAAe,CAAC,EAAI,CAClB,KAAO,GAChB,CAAA,EAAO,CAAmB,CAAC,EAAI,AAAJ,EAGtB,CACL,KAAA,EACA,IAAA,CACF,CACF,C,G,E,Q,S,C,C,C,E,I,E,E,SCjRA,IAAI,EAAA,IAAA,IAA0B,4CAA9B,YAAA,GAAA,CACA,CAAA,EAAA,OAAA,CAAiB,EAAU,EAAI,QAAQ,GAAI,EAAI,MAAM,CAAE,CAAA,E,G,E,Q,S,C,C,C,ECAvD,EAAA,OAAA,CAAiB,SAAU,CAAS,CAAE,CAAM,CAAE,CAAK,EACjD,GAAI,IAAW,KAAK,QAAQ,CAAC,MAAM,CAGjC,OAAO,EAGP,IAAI,EAAS,EAAQ,UAAY,KAAK,SAAS,CAAC,GAAa,IAAM,iBAAmB,KAAK,SAAS,CAAC,GAAa,KAClH,OAAO,IAAI,eAAe,CAAC,IAAI,KAAK,CAAC,EAAO,CAAE,CAC5C,KAAM,wBACR,GAEJ,C,GCdA,AAAA,EAAA,SAAA,QAAA,CAA8C,IAAA,IAAoB,GAAA,YAAA,GAAA,EAAI,QAAQ,GAAG,KAAK,KAAK,CAAC","sources":["","../../../../Users/awood/AppData/Roaming/npm/node_modules/parcel/node_modules/@parcel/runtime-js/lib/helpers/bundle-manifest.js","../../source/twr-wasm-ts/index.ts","../../lib-js/twrmod.js","../../source/twr-wasm-ts/twrmod.ts","../../lib-js/twrdebug.js","../../source/twr-wasm-ts/twrdebug.ts","../../lib-js/twrmodjsmain.js","../../source/twr-wasm-ts/twrmodjsmain.ts","../../lib-js/twrdiv.js","../../source/twr-wasm-ts/twrdiv.ts","../../lib-js/twrcircular.js","../../source/twr-wasm-ts/twrcircular.ts","../../lib-js/twrmodbase.js","../../source/twr-wasm-ts/twrmodbase.ts","../../lib-js/twrfloat.js","../../source/twr-wasm-ts/twrfloat.ts","../../lib-js/twrcanvas.js","../../source/twr-wasm-ts/twrcanvas.ts","../../lib-js/twrsignal.js","../../source/twr-wasm-ts/twrsignal.ts","../../lib-js/twrdate.js","../../source/twr-wasm-ts/twrdate.ts","../../lib-js/twrmodasync.js","../../source/twr-wasm-ts/twrmodasync.ts","../../lib-js/twrwaitingcalls.js","../../source/twr-wasm-ts/twrwaitingcalls.ts","../../lib-js/whatkey.js","../../../../Users/awood/AppData/Roaming/npm/node_modules/parcel/node_modules/@parcel/runtime-js/lib/runtime-f762b97648513f2d.js","../../../../Users/awood/AppData/Roaming/npm/node_modules/parcel/node_modules/@parcel/runtime-js/lib/helpers/get-worker-url.js","../../../../Users/awood/AppData/Roaming/npm/node_modules/parcel/node_modules/@parcel/runtime-js/lib/runtime-8b48cd52cfa83e88.js"],"sourcesContent":["\nfunction $parcel$export(e, n, v, s) {\n Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});\n}\n\n var $parcel$global = globalThis;\n \nvar $parcel$modules = {};\nvar $parcel$inits = {};\n\nvar parcelRequire = $parcel$global[\"parcelRequire94c2\"];\n\nif (parcelRequire == null) {\n parcelRequire = function(id) {\n if (id in $parcel$modules) {\n return $parcel$modules[id].exports;\n }\n if (id in $parcel$inits) {\n var init = $parcel$inits[id];\n delete $parcel$inits[id];\n var module = {id: id, exports: {}};\n $parcel$modules[id] = module;\n init.call(module.exports, module, module.exports);\n return module.exports;\n }\n var err = new Error(\"Cannot find module '\" + id + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n };\n\n parcelRequire.register = function register(id, init) {\n $parcel$inits[id] = init;\n };\n\n $parcel$global[\"parcelRequire94c2\"] = parcelRequire;\n}\n\nvar parcelRegister = parcelRequire.register;\nparcelRegister(\"eZoLj\", function(module, exports) {\n\n$parcel$export(module.exports, \"register\", () => $ae99f86db55f9acd$export$6503ec6e8aabbaf, (v) => $ae99f86db55f9acd$export$6503ec6e8aabbaf = v);\nvar $ae99f86db55f9acd$export$6503ec6e8aabbaf;\nvar $ae99f86db55f9acd$export$f7ad0328861e2f03;\n\"use strict\";\nvar $ae99f86db55f9acd$var$mapping = new Map();\nfunction $ae99f86db55f9acd$var$register(baseUrl, manifest) {\n for(var i = 0; i < manifest.length - 1; i += 2)$ae99f86db55f9acd$var$mapping.set(manifest[i], {\n baseUrl: baseUrl,\n path: manifest[i + 1]\n });\n}\nfunction $ae99f86db55f9acd$var$resolve(id) {\n var resolved = $ae99f86db55f9acd$var$mapping.get(id);\n if (resolved == null) throw new Error(\"Could not resolve bundle with id \" + id);\n return new URL(resolved.path, resolved.baseUrl).toString();\n}\n$ae99f86db55f9acd$export$6503ec6e8aabbaf = $ae99f86db55f9acd$var$register;\n$ae99f86db55f9acd$export$f7ad0328861e2f03 = $ae99f86db55f9acd$var$resolve;\n\n});\n\nparcelRegister(\"4mNsm\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrWasmModule\", () => (parcelRequire(\"3bkoq\")).twrWasmModule);\n$parcel$export(module.exports, \"twrWasmModuleAsync\", () => (parcelRequire(\"baOio\")).twrWasmModuleAsync);\n\nvar $3bkoq = parcelRequire(\"3bkoq\");\n\nvar $baOio = parcelRequire(\"baOio\");\n\n});\nparcelRegister(\"3bkoq\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrWasmModule\", () => $251237c7cf144eb4$export$3298af74d75b595c);\n\nvar $9FI45 = parcelRequire(\"9FI45\");\n\nvar $aGUWE = parcelRequire(\"aGUWE\");\n\nvar $lsUl2 = parcelRequire(\"lsUl2\");\nclass $251237c7cf144eb4$export$3298af74d75b595c extends (0, $aGUWE.twrWasmModuleInJSMain) {\n malloc;\n constructor(opts = {}){\n super(opts, true);\n this.malloc = (size)=>{\n throw new Error(\"error - un-init malloc called\");\n };\n let canvas;\n if (this.d2dcanvas.isValid()) canvas = this.d2dcanvas;\n else canvas = this.iocanvas;\n this.modParams.imports = {\n twrDebugLog: (0, $9FI45.twrDebugLogImpl),\n twrTime: (0, $lsUl2.twrTimeImpl),\n twrDivCharOut: this.iodiv.charOut.bind(this.iodiv),\n twrCanvasGetProp: canvas.getProp.bind(canvas),\n twrCanvasDrawSeq: canvas.drawSeq.bind(canvas),\n twrCanvasCharIn: this.null,\n twrCanvasInkey: this.null,\n twrDivCharIn: this.null,\n twrSleep: this.null,\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function(x, y) {\n return x % y;\n },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n null(inval) {\n throw new Error(\"call to unimplemented twrXXX import in twrWasmModule. Use twrWasmModuleAsync ?\");\n }\n}\n\n});\nparcelRegister(\"9FI45\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrDebugLogImpl\", () => $70aa1fbe63deeaae$export$16b4216ec014493d);\nlet $70aa1fbe63deeaae$var$logline = \"\";\nfunction $70aa1fbe63deeaae$export$16b4216ec014493d(char) {\n if (char == 10 || char == 3) {\n console.log($70aa1fbe63deeaae$var$logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n $70aa1fbe63deeaae$var$logline = \"\";\n } else {\n $70aa1fbe63deeaae$var$logline = $70aa1fbe63deeaae$var$logline + String.fromCharCode(char);\n if ($70aa1fbe63deeaae$var$logline.length >= 200) {\n console.log($70aa1fbe63deeaae$var$logline);\n $70aa1fbe63deeaae$var$logline = \"\";\n }\n }\n}\nfunction $70aa1fbe63deeaae$export$485af4d0039b3389(ch) {\n postMessage([\n \"debug\",\n ch\n ]);\n}\n\n});\n\nparcelRegister(\"aGUWE\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrWasmModuleInJSMain\", () => $7c89ffbd74fdad5b$export$2366c14363f3adb5);\n// This class extends base to handle options when called in the main Java Script thread\n\nvar $fDEU7 = parcelRequire(\"fDEU7\");\n\nvar $5hO33 = parcelRequire(\"5hO33\");\n\nvar $5LsZ0 = parcelRequire(\"5LsZ0\");\nclass $7c89ffbd74fdad5b$export$2366c14363f3adb5 extends (0, $5hO33.twrWasmModuleBase) {\n iocanvas;\n d2dcanvas;\n iodiv;\n modParams;\n constructor(opts = {}, isWasmModule = false){\n super(isWasmModule);\n if (typeof document === \"undefined\") throw new Error(\"twrWasmModuleJSMain should only be created in JavaScript Main.\");\n const eiodiv = document.getElementById(\"twr_iodiv\");\n const eiocanvas = document.getElementById(\"twr_iocanvas\");\n const ed2dcanvas = document.getElementById(\"twr_d2dcanvas\");\n if (eiocanvas && ed2dcanvas) throw new Error(\"Both twr_iocanvas and twr_d2dcanvas defined. Currently only one canvas allowed.\");\n if (opts.stdio == \"div\" && !eiodiv) throw new Error(\"twrWasmModuleBase opts=='div' but twr_iodiv not defined\");\n if (opts.stdio == \"canvas\" && !eiocanvas) throw new Error(\"twrWasmModuleBase, opts=='canvas' but twr_iocanvas not defined\");\n if (opts.isd2dcanvas && !ed2dcanvas) throw new Error(\"twrWasmModuleBase, opts.isdrawcanvas==true but twr_d2dcanvas not defined\");\n // set default opts based on elements found\n if (eiodiv) opts = {\n stdio: \"div\",\n ...opts\n };\n else if (eiocanvas) opts = {\n stdio: \"canvas\",\n ...opts\n };\n else opts = {\n stdio: \"debug\",\n ...opts\n };\n if (!eiodiv && !eiocanvas) console.log(\"Since neither twr_iocanvas nor twr_iodiv is defined, stdout directed to debug console.\");\n else console.log(\"tiny-wasm-runtime: stdio set to: \", opts.stdio);\n if (eiocanvas) opts = {\n windim: [\n 64,\n 16\n ],\n ...opts\n };\n else opts = {\n windim: [\n 0,\n 0\n ],\n ...opts\n };\n if (!opts.imports) opts.imports = {};\n let styleIsDefault = false;\n if (!opts.backcolor) {\n styleIsDefault = true;\n opts.backcolor = \"black\";\n }\n if (!opts.forecolor) {\n styleIsDefault = true;\n opts.forecolor = \"white\";\n }\n if (!opts.fontsize) {\n styleIsDefault = true;\n opts.fontsize = 16;\n }\n if (opts.isd2dcanvas === undefined) {\n if (ed2dcanvas) opts.isd2dcanvas = true;\n else opts.isd2dcanvas = false;\n }\n this.modParams = {\n stdio: opts.stdio,\n windim: opts.windim,\n imports: opts.imports,\n forecolor: opts.forecolor,\n backcolor: opts.backcolor,\n styleIsDefault: styleIsDefault,\n fontsize: opts.fontsize,\n isd2dcanvas: opts.isd2dcanvas\n };\n this.iodiv = new (0, $fDEU7.twrDiv)(eiodiv, this.modParams, this);\n this.iocanvas = new (0, $5LsZ0.twrCanvas)(eiocanvas, this.modParams, this);\n this.d2dcanvas = new (0, $5LsZ0.twrCanvas)(ed2dcanvas, this.modParams, this);\n }\n divLog(...params) {\n for(var i = 0; i < params.length; i++){\n this.iodiv.stringOut(params[i].toString());\n this.iodiv.charOut(32); // space\n }\n this.iodiv.charOut(10);\n }\n}\n\n});\nparcelRegister(\"fDEU7\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrDiv\", () => $b62a3a4493ce3043$export$dd376bb3f10f6896);\n\nvar $ghrAp = parcelRequire(\"ghrAp\");\nclass $b62a3a4493ce3043$export$dd376bb3f10f6896 {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611);\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase){\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) this.divKeys = new (0, $ghrAp.twrSharedCircularBuffer)(); // tsconfig, lib must be set to 2017 or higher\n if (this.div && !modParams.styleIsDefault) {\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.divKeys.sharedArray\n ];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */ charOut(ch) {\n if (!this.div) return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n }\n switch(ch){\n case 10:\n case 13:\n if (ch == 10 && this.lastChar == 13) break; // detect CR LF and treat as single new line\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n case 0xE:\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF:\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for(let i = 0; i < str.length; i++)this.charOut(str.charCodeAt(i));\n }\n}\nclass $b62a3a4493ce3043$export$b377f0bbf2c7581e {\n divKeys;\n constructor(params){\n const [divKeysBuffer] = params;\n this.divKeys = new (0, $ghrAp.twrSharedCircularBuffer)(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n charOut(ch) {\n postMessage([\n \"divout\",\n ch\n ]);\n }\n}\n\n});\nparcelRegister(\"ghrAp\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrSharedCircularBuffer\", () => $bda3a1eb26e567b5$export$a01cca24f011573a);\n//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst $bda3a1eb26e567b5$var$RDIDX = 256;\nconst $bda3a1eb26e567b5$var$WRIDX = 257;\nconst $bda3a1eb26e567b5$var$LEN = 256;\nclass $bda3a1eb26e567b5$export$a01cca24f011573a {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(1032);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[$bda3a1eb26e567b5$var$RDIDX] = 0;\n this.buf[$bda3a1eb26e567b5$var$WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[$bda3a1eb26e567b5$var$WRIDX];\n this.buf[i] = n;\n i++;\n if (i == $bda3a1eb26e567b5$var$LEN) i = 0;\n this.buf[$bda3a1eb26e567b5$var$WRIDX] = i;\n Atomics.notify(this.buf, $bda3a1eb26e567b5$var$WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[$bda3a1eb26e567b5$var$RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[$bda3a1eb26e567b5$var$RDIDX] = i;\n return n;\n } else return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[$bda3a1eb26e567b5$var$RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, $bda3a1eb26e567b5$var$WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[$bda3a1eb26e567b5$var$RDIDX] == this.buf[$bda3a1eb26e567b5$var$WRIDX];\n }\n}\n\n});\n\n\nparcelRegister(\"5hO33\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrWasmModuleBase\", () => $3d955ccf8fb141b7$export$c83a0a3bffe07399);\n\nvar $2Xdsi = parcelRequire(\"2Xdsi\");\nclass $3d955ccf8fb141b7$export$c83a0a3bffe07399 {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule;\n floatUtil;\n constructor(isWasmModule = false){\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new (0, $2Xdsi.twrFloatUtil)(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/ /*********************************************************************/ async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n } catch (err) {\n console.log(\"loadWasm() failed to fetch: \" + pathToLoad);\n throw err;\n }\n if (!response.ok) throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, {\n env: allimports\n });\n this.exports = instance.instance.exports;\n if (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory) throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer) console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\n \"setmemory\",\n this.memory\n ]);\n }\n if (this.isWasmModule) // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n {\n if (!(this.memory.buffer instanceof ArrayBuffer)) console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size)=>{\n return new Promise((resolve)=>{\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n } catch (err) {\n console.log(\"WASM instantiate error: \" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch(this.modParams.stdio){\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* executeC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */ async executeC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.executeCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async executeCImpl(fname, cparams = []) {\n if (!this.exports) throw new Error(\"this.exports undefined\");\n if (!this.exports[fname]) throw new Error(\"executeC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array)) throw new Error(\"executeC: params must be array, first arg is function name\");\n if (params.length == 0) throw new Error(\"executeC: missing function name\");\n let cparams = [];\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n cparams[ci++] = p;\n break;\n case \"string\":\n cparams[ci++] = await this.putString(p);\n break;\n case \"object\":\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n } else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"executeC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n ci++;\n break;\n case \"string\":\n this.executeCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n case \"object\":\n if (p instanceof URL) {\n this.executeCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci = ci + 2;\n break;\n } else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for(let j = 0; j < u8.length; j++)u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.executeCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n } else throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/ /*********************************************************************/ // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for(i = 0; i < sin.length && i < buffer_size - 1; i++)this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for(let i = 0; i < u8a.length; i++)this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === \"object\" && fnin instanceof URL)) throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [\n dest,\n src.length\n ];\n } catch (err) {\n console.log(\"fetchAndPutURL Error. URL: \" + fnin + \"\\n\" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while(this.mem8[strIndex + i] && (len === undefined ? true : i < len) && strIndex + i < this.mem8.length){\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array(this.mem8.slice(dataptr, dataptr + size).buffer);\n return u32;\n }\n}\n\n});\nparcelRegister(\"2Xdsi\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrFloatUtil\", () => $226b87658a7c840f$export$918ffb7e046a537b);\nclass $226b87658a7c840f$export$918ffb7e046a537b {\n mod;\n constructor(mod){\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\") return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\") return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll(\"D\", \"e\").replaceAll(\"d\", \"e\"));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n } else {\n let r = value.toString();\n if (r.length > max_precision) r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, sizeInBytes, value, fracpart_numdigits, dec, sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1) return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) {\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (!Number.isFinite(value)) {\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n } else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split(\".\");\n if (intPart == \"0\") intPart = \"\";\n if (intPart.length > 0) {\n decpos = intPart.length;\n digits = intPart + fracPart;\n } else {\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length) return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */ }\n}\n\n});\n\n\nparcelRegister(\"5LsZ0\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrCanvas\", () => $4327d2f23f608609$export$2f298dd69cef3c34);\n\nvar $ghrAp = parcelRequire(\"ghrAp\");\n\nvar $47Wdp = parcelRequire(\"47Wdp\");\nvar $4327d2f23f608609$var$D2DType;\n(function(D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})($4327d2f23f608609$var$D2DType || ($4327d2f23f608609$var$D2DType = {}));\nclass $4327d2f23f608609$export$2f298dd69cef3c34 {\n ctx;\n props = {\n charWidth: 0,\n charHeight: 0,\n foreColor: 0,\n backColor: 0,\n widthInChars: 0,\n heightInChars: 0,\n canvasHeight: 0,\n canvasWidth: 0\n };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase){\n const { forecolor: forecolor, backcolor: backcolor, fontsize: fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new (0, $47Wdp.twrSignal)();\n this.canvasKeys = new (0, $ghrAp.twrSharedCircularBuffer)(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.props,\n this.cmdCompleteSignal.sharedArray,\n this.canvasKeys.sharedArray\n ];\n }\n getProp(pn) {\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */ drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx) return;\n let ins = this.owner.getLong(ds); /* ds->start */ \n const lastins = this.owner.getLong(ds + 4); /* ds->last */ \n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while(true){\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */ \n switch(type){\n case $4327d2f23f608609$var$D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_BEGINPATH:\n this.ctx.beginPath();\n break;\n case $4327d2f23f608609$var$D2DType.D2D_FILL:\n this.ctx.fill();\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SAVE:\n this.ctx.save();\n break;\n case $4327d2f23f608609$var$D2DType.D2D_RESTORE:\n this.ctx.restore();\n break;\n case $4327d2f23f608609$var$D2DType.D2D_STROKE:\n this.ctx.stroke();\n break;\n case $4327d2f23f608609$var$D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = this.owner.getLong(ins + 48) != 0;\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n } else this.precomputedObjects[id] = {\n mem8: new Uint8Array(this.owner.memory.buffer, start, length),\n width: width,\n height: height\n };\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id]) delete this.precomputedObjects[id];\n else console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n else {\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) this.ctx.putImageData(imgData, dx, dy);\n else this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */ \n if (next == 0) {\n if (ins != lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nclass $4327d2f23f608609$export$c779b2cd00544976 {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner){\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new (0, $47Wdp.twrSignal)(signalBuffer);\n this.canvasKeys = new (0, $ghrAp.twrSharedCircularBuffer)(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\n \"drawseq\",\n [\n ds\n ]\n ]);\n this.drawCompleteSignal.wait();\n }\n}\n\n});\nparcelRegister(\"47Wdp\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrSignal\", () => $3014f93b5ceae902$export$e37a7b7b851b97f3);\n//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar $3014f93b5ceae902$var$twrSignalState;\n(function(twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})($3014f93b5ceae902$var$twrSignalState || ($3014f93b5ceae902$var$twrSignalState = {}));\nclass $3014f93b5ceae902$export$e37a7b7b851b97f3 {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = $3014f93b5ceae902$var$twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = $3014f93b5ceae902$var$twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == $3014f93b5ceae902$var$twrSignalState.WAITING) //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, $3014f93b5ceae902$var$twrSignalState.WAITING);\n }\n isSignaled() {\n return this.buf[0] == $3014f93b5ceae902$var$twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = $3014f93b5ceae902$var$twrSignalState.WAITING;\n }\n}\n\n});\n\n\n\nparcelRegister(\"lsUl2\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrTimeImpl\", () => $fa07ea1a08a5d6be$export$78724cdcf7ebea1d);\nfunction $fa07ea1a08a5d6be$export$78724cdcf7ebea1d() {\n return Date.now();\n}\n\n});\n\n\nparcelRegister(\"baOio\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrWasmModuleAsync\", () => $8227a48f951b1cca$export$678fe6e36ab9a6ff);\n\nvar $9FI45 = parcelRequire(\"9FI45\");\n\nvar $aGUWE = parcelRequire(\"aGUWE\");\n\nvar $2vKdq = parcelRequire(\"2vKdq\");\n\nvar $bqeaG = parcelRequire(\"bqeaG\");\n\nclass $8227a48f951b1cca$export$678fe6e36ab9a6ff extends (0, $aGUWE.twrWasmModuleInJSMain) {\n myWorker;\n malloc;\n loadWasmResolve;\n loadWasmReject;\n executeCResolve;\n executeCReject;\n initLW = false;\n waitingcalls;\n constructor(opts){\n super(opts);\n this.malloc = (size)=>{\n throw new Error(\"Error - un-init malloc called.\");\n };\n if (!window.Worker) throw new Error(\"This browser doesn't support web workers.\");\n this.myWorker = new Worker((parcelRequire(\"aRHnW\")));\n this.myWorker.onmessage = this.processMsg.bind(this);\n }\n // overrides base implementation\n async loadWasm(pathToLoad) {\n if (this.initLW) throw new Error(\"twrWasmAsyncModule::loadWasm can only be called once per twrWasmAsyncModule instance\");\n this.initLW = true;\n return new Promise((resolve, reject)=>{\n this.loadWasmResolve = resolve;\n this.loadWasmReject = reject;\n this.malloc = (size)=>{\n return this.executeCImpl(\"twr_malloc\", [\n size\n ]);\n };\n this.waitingcalls = new (0, $2vKdq.twrWaitingCalls)(); // handle's calls that cross the worker thread - main js thread boundary\n let canvas;\n if (this.d2dcanvas.isValid()) canvas = this.d2dcanvas;\n else canvas = this.iocanvas;\n const modWorkerParams = {\n divProxyParams: this.iodiv.getProxyParams(),\n canvasProxyParams: canvas.getProxyParams(),\n waitingCallsProxyParams: this.waitingcalls.getProxyParams()\n };\n const urlToLoad = new URL(pathToLoad, document.URL);\n const startMsg = {\n urlToLoad: urlToLoad.href,\n modWorkerParams: modWorkerParams,\n modParams: this.modParams\n };\n this.myWorker.postMessage([\n \"startup\",\n startMsg\n ]);\n });\n }\n async executeC(params) {\n const cparams = await this.preCallC(params); // will also validate params[0]\n return this.executeCImpl(params[0], cparams);\n }\n async executeCImpl(fname, cparams = []) {\n return new Promise((resolve, reject)=>{\n this.executeCResolve = resolve;\n this.executeCReject = reject;\n this.myWorker.postMessage([\n \"executeC\",\n fname,\n cparams\n ]);\n });\n }\n // this function should be called from HTML \"keydown\" event from
\n keyDownDiv(ev) {\n if (!this.iodiv || !this.iodiv.divKeys) throw new Error(\"unexpected undefined twrWasmAsyncModule.divKeys\");\n this.iodiv.divKeys.write((0, $bqeaG.default)(ev).char.charCodeAt(0));\n }\n // this function should be called from HTML \"keydown\" event from \n keyDownCanvas(ev) {\n if (!this.iocanvas || !this.iocanvas.canvasKeys) throw new Error(\"unexpected undefined twrWasmAsyncModule.canvasKeys\");\n this.iocanvas.canvasKeys.write((0, $bqeaG.default)(ev).char.charCodeAt(0));\n }\n processMsg(event) {\n const msgType = event.data[0];\n const d = event.data[1];\n //console.log(\"twrWasmAsyncModule - got message: \"+event.data)\n switch(msgType){\n case \"divout\":\n if (this.iodiv.isValid()) this.iodiv.charOut(d);\n else console.log(\"error - msg divout received but iodiv is undefined.\");\n break;\n case \"debug\":\n (0, $9FI45.twrDebugLogImpl)(d);\n break;\n case \"drawseq\":\n {\n //console.log(\"twrModAsync got message drawseq\");\n const [ds] = d;\n if (this.iocanvas.isValid()) this.iocanvas.drawSeq(ds);\n else if (this.d2dcanvas.isValid()) this.d2dcanvas.drawSeq(ds);\n else throw new Error(\"msg drawseq received but canvas is undefined.\");\n break;\n }\n case \"setmemory\":\n this.memory = d;\n if (!this.memory) throw new Error(\"unexpected error - undefined memory in startupOkay msg\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n break;\n case \"startupFail\":\n if (this.loadWasmReject) this.loadWasmReject(d);\n else throw new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmReject)\");\n break;\n case \"startupOkay\":\n if (this.loadWasmResolve) this.loadWasmResolve(undefined);\n else throw new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmResolve)\");\n break;\n case \"executeCFail\":\n if (this.executeCReject) this.executeCReject(d);\n else throw new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined executeCReject)\");\n break;\n case \"executeCOkay\":\n if (this.executeCResolve) this.executeCResolve(d);\n else throw new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined executeCResolve)\");\n break;\n default:\n if (!this.waitingcalls) throw new Error(\"internal error: this.waitingcalls undefined.\");\n if (!this.waitingcalls.processMessage(msgType, d)) throw new Error(\"twrWasmAsyncModule - unknown and unexpected msgType: \" + msgType);\n }\n }\n}\n\n});\nparcelRegister(\"2vKdq\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrWaitingCalls\", () => $1d42537681d02be3$export$9e37856d1928d388);\n\nvar $47Wdp = parcelRequire(\"47Wdp\");\n\nvar $lsUl2 = parcelRequire(\"lsUl2\");\nclass $1d42537681d02be3$export$9e37856d1928d388 {\n callCompleteSignal;\n parameters;\n constructor(){\n this.callCompleteSignal = new (0, $47Wdp.twrSignal)();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(()=>{\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = (0, $lsUl2.twrTimeImpl)();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [\n this.callCompleteSignal.sharedArray,\n this.parameters.buffer\n ];\n }\n processMessage(msgType, data) {\n switch(msgType){\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\nclass $1d42537681d02be3$export$78d2a4633fe89379 {\n callCompleteSignal;\n parameters;\n constructor(params){\n this.callCompleteSignal = new (0, $47Wdp.twrSignal)(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\n \"sleep\",\n [\n ms\n ]\n ]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\n \"time\"\n ]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n\n});\n\nparcelRegister(\"bqeaG\", function(module, exports) {\n\n$parcel$export(module.exports, \"default\", () => $850d1d8f0aa1ea8f$export$2e2bcd8739ae039);\nconst $850d1d8f0aa1ea8f$var$keycodeCtrlKeys = {\n \"a\": \"selectAll\",\n \"c\": \"copy\",\n \"s\": \"save\",\n \"v\": \"paste\",\n \"x\": \"cut\",\n \"y\": \"redo\",\n \"z\": \"undo\"\n};\nconst $850d1d8f0aa1ea8f$var$keycodeShiftedKeys = {\n \"/\": \"?\",\n \".\": \">\",\n \",\": \"<\",\n \"'\": '\"',\n \";\": \":\",\n \"[\": \"{\",\n \"]\": \"}\",\n \"\\\\\": \"|\",\n \"`\": \"~\",\n \"=\": \"+\",\n \"-\": \"_\",\n \"1\": \"!\",\n \"2\": \"@\",\n \"3\": \"#\",\n \"4\": \"$\",\n \"5\": \"%\",\n \"6\": \"^\",\n \"7\": \"&\",\n \"8\": \"*\",\n \"9\": \"(\",\n \"0\": \")\",\n \"a\": \"A\",\n \"b\": \"B\",\n \"c\": \"C\",\n \"d\": \"D\",\n \"e\": \"E\",\n \"f\": \"F\",\n \"g\": \"G\",\n \"h\": \"H\",\n \"i\": \"I\",\n \"j\": \"J\",\n \"k\": \"K\",\n \"l\": \"L\",\n \"m\": \"M\",\n \"n\": \"N\",\n \"o\": \"O\",\n \"p\": \"P\",\n \"q\": \"q\",\n \"r\": \"R\",\n \"s\": \"S\",\n \"t\": \"T\",\n \"u\": \"U\",\n \"v\": \"V\",\n \"w\": \"W\",\n \"x\": \"X\",\n \"y\": \"Y\",\n \"z\": \"Z\"\n};\nconst $850d1d8f0aa1ea8f$var$keyCodeUnshiftedKeys = {};\nfor(const x in $850d1d8f0aa1ea8f$var$keycodeShiftedKeys){\n const shiftedKey = $850d1d8f0aa1ea8f$var$keycodeShiftedKeys[x];\n $850d1d8f0aa1ea8f$var$keyCodeUnshiftedKeys[shiftedKey] = x;\n}\nconst $850d1d8f0aa1ea8f$var$keydownKeycodeDictionary = {\n 0: \"\\\\\",\n 8: \"backspace\",\n 9: \"tab\",\n 12: \"num\",\n 13: \"enter\",\n 16: \"shift\",\n 17: \"ctrl\",\n 18: \"alt\",\n 19: \"pause\",\n 20: \"caps\",\n 27: \"esc\",\n 32: \" \",\n 33: \"pageup\",\n 34: \"pagedown\",\n 35: \"end\",\n 36: \"home\",\n 37: \"left\",\n 38: \"up\",\n 39: \"right\",\n 40: \"down\",\n 44: \"print\",\n 45: \"insert\",\n 46: \"delete\",\n 48: \"0\",\n 49: \"1\",\n 50: \"2\",\n 51: \"3\",\n 52: \"4\",\n 53: \"5\",\n 54: \"6\",\n 55: \"7\",\n 56: \"8\",\n 57: \"9\",\n 59: \";\",\n 61: \"=\",\n 65: \"a\",\n 66: \"b\",\n 67: \"c\",\n 68: \"d\",\n 69: \"e\",\n 70: \"f\",\n 71: \"g\",\n 72: \"h\",\n 73: \"i\",\n 74: \"j\",\n 75: \"k\",\n 76: \"l\",\n 77: \"m\",\n 78: \"n\",\n 79: \"o\",\n 80: \"p\",\n 81: \"q\",\n 82: \"r\",\n 83: \"s\",\n 84: \"t\",\n 85: \"u\",\n 86: \"v\",\n 87: \"w\",\n 88: \"x\",\n 89: \"y\",\n 90: \"z\",\n 91: \"meta\",\n 92: \"meta\",\n 93: \"meta\",\n 96: \"num0\",\n 97: \"num1\",\n 98: \"num2\",\n 99: \"num3\",\n 100: \"num4\",\n 101: \"num5\",\n 102: \"num6\",\n 103: \"num7\",\n 104: \"num8\",\n 105: \"num9\",\n 106: \"*\",\n 107: \"+\",\n 108: \"num_enter\",\n 109: \"num_subtract\",\n 110: \"num_decimal\",\n 111: \"num_divide\",\n 112: \"f1\",\n 113: \"f2\",\n 114: \"f3\",\n 115: \"f4\",\n 116: \"f5\",\n 117: \"f6\",\n 118: \"f7\",\n 119: \"f8\",\n 120: \"f9\",\n 121: \"f10\",\n 122: \"f11\",\n 123: \"f12\",\n 124: \"print\",\n 144: \"num\",\n 145: \"scroll\",\n 173: \"-\",\n 186: \";\",\n 187: \"=\",\n 188: \",\",\n 189: \"-\",\n 190: \".\",\n 191: \"/\",\n 192: \"`\",\n 219: \"[\",\n 220: \"\\\\\",\n 221: \"]\",\n 222: \"'\",\n 223: \"`\",\n 224: \"cmd\",\n 225: \"alt\",\n 57392: \"ctrl\",\n 63289: \"num\"\n};\nconst $850d1d8f0aa1ea8f$var$keypressCharacterMapOverides = {\n \"\\r\": \"enter\"\n};\nconst $850d1d8f0aa1ea8f$var$keypressCharacterMap = JSON.parse(JSON.stringify($850d1d8f0aa1ea8f$var$keydownKeycodeDictionary));\nfor (const key of Object.keys($850d1d8f0aa1ea8f$var$keypressCharacterMapOverides))$850d1d8f0aa1ea8f$var$keypressCharacterMap[key] = $850d1d8f0aa1ea8f$var$keypressCharacterMapOverides[key];\nconst $850d1d8f0aa1ea8f$var$keydownCharacterMap = {\n \"num_subtract\": \"-\",\n \"num_enter\": \"\\n\",\n \"num_decimal\": \".\",\n \"num_divide\": \"/\",\n \"enter\": \"\\n\",\n \"tab\": \"\t\",\n \"backspace\": \"\\b\"\n};\nconst $850d1d8f0aa1ea8f$export$d1477772898aaa70 = [\n \"backspace\",\n \"enter\",\n \"tab\",\n \"num\",\n \"shift\",\n \"meta\",\n \"alt\",\n \"pause\",\n \"caps\",\n \"esc\",\n \"pageup\",\n \"pagedown\",\n \"end\",\n \"home\",\n \"left\",\n \"up\",\n \"right\",\n \"down\",\n \"print\",\n \"insert\",\n \"delete\",\n \"cmd\",\n \"f1\",\n \"f2\",\n \"f3\",\n \"f4\",\n \"f5\",\n \"f6\",\n \"f7\",\n \"f8\",\n \"f9\",\n \"f10\",\n \"f11\",\n \"f12\",\n \"scroll\",\n \"ctrl\"\n];\nconst $850d1d8f0aa1ea8f$var$validEvents = [\n \"keydown\",\n \"keyup\"\n];\nconst $850d1d8f0aa1ea8f$var$isMobile = ()=>{\n const ua = navigator.userAgent;\n const mobile = /IEMobile|Windows Phone|Lumia/i.test(ua) ? \"w\" : /iPhone|iP[oa]d/.test(ua) ? \"i\" : /Android/.test(ua) ? \"a\" : /BlackBerry|PlayBook|BB10/.test(ua) ? \"b\" : /Mobile Safari/.test(ua) ? \"s\" : /webOS|Mobile|Tablet|Opera Mini|\\bCrMo\\/|Opera Mobi/i.test(ua) ? 1 : 0;\n return mobile !== 0;\n};\nfunction $850d1d8f0aa1ea8f$var$getKeypressKeycodeValue(charcode) {\n const character = String.fromCharCode(charcode);\n if ($850d1d8f0aa1ea8f$var$isMobile()) return character;\n if (character in $850d1d8f0aa1ea8f$var$keyCodeUnshiftedKeys) return $850d1d8f0aa1ea8f$var$keyCodeUnshiftedKeys[character];\n else if (character in $850d1d8f0aa1ea8f$var$keypressCharacterMap) return $850d1d8f0aa1ea8f$var$keypressCharacterMap[character];\n return character;\n}\nfunction $850d1d8f0aa1ea8f$export$2e2bcd8739ae039(event) {\n let key;\n if (event.type === \"keypress\" && !$850d1d8f0aa1ea8f$var$isMobile()) key = $850d1d8f0aa1ea8f$var$getKeypressKeycodeValue(event.charCode);\n else if (event.type === \"keypress\" && $850d1d8f0aa1ea8f$var$isMobile()) key = $850d1d8f0aa1ea8f$var$getKeypressKeycodeValue(event.keyCode);\n else if ($850d1d8f0aa1ea8f$var$validEvents.indexOf(event.type) > -1) {\n if (event.which !== undefined) key = $850d1d8f0aa1ea8f$var$keydownKeycodeDictionary[event.which];\n else if (event.keyCode !== undefined) key = $850d1d8f0aa1ea8f$var$keydownKeycodeDictionary[event.keyCode];\n else key = \"enter\";\n } else return false;\n let char = key;\n if (event.shiftKey && key in $850d1d8f0aa1ea8f$var$keycodeShiftedKeys) char = $850d1d8f0aa1ea8f$var$keycodeShiftedKeys[key];\n else if (event.ctrlKey && key in $850d1d8f0aa1ea8f$var$keycodeCtrlKeys) char = $850d1d8f0aa1ea8f$var$keycodeCtrlKeys[key];\n else if (key in $850d1d8f0aa1ea8f$var$keydownCharacterMap) char = $850d1d8f0aa1ea8f$var$keydownCharacterMap[key];\n return {\n char: char,\n key: key\n };\n}\n\n});\n\nparcelRegister(\"aRHnW\", function(module, exports) {\n\nvar $hoqmg = parcelRequire(\"hoqmg\");\nlet $7e9081fcee88b005$var$url = new URL(\"twrmodworker.2165e649.js\", import.meta.url);\nmodule.exports = $hoqmg($7e9081fcee88b005$var$url.toString(), $7e9081fcee88b005$var$url.origin, true);\n\n});\nparcelRegister(\"hoqmg\", function(module, exports) {\n\"use strict\";\nmodule.exports = function(workerUrl, origin, isESM) {\n if (origin === self.location.origin) // If the worker bundle's url is on the same origin as the document,\n // use the worker bundle's own url.\n return workerUrl;\n else {\n // Otherwise, create a blob URL which loads the worker bundle with `importScripts`.\n var source = isESM ? \"import \" + JSON.stringify(workerUrl) + \";\" : \"importScripts(\" + JSON.stringify(workerUrl) + \");\";\n return URL.createObjectURL(new Blob([\n source\n ], {\n type: \"application/javascript\"\n }));\n }\n};\n\n});\n\n\n\n\nvar $49087e929fab6e62$exports = {};\n\n(parcelRequire(\"eZoLj\")).register(new URL(\"\", import.meta.url).toString(), JSON.parse('[\"kjr0c\",\"index.528b9ee5.js\",\"cTHdP\",\"twrmodworker.2165e649.js\"]'));\n\n\n//# sourceMappingURL=index.528b9ee5.js.map\n","\"use strict\";\n\nvar mapping = new Map();\nfunction register(baseUrl, manifest) {\n for (var i = 0; i < manifest.length - 1; i += 2) {\n mapping.set(manifest[i], {\n baseUrl: baseUrl,\n path: manifest[i + 1]\n });\n }\n}\nfunction resolve(id) {\n var resolved = mapping.get(id);\n if (resolved == null) {\n throw new Error('Could not resolve bundle with id ' + id);\n }\n return new URL(resolved.path, resolved.baseUrl).toString();\n}\nmodule.exports.register = register;\nmodule.exports.resolve = resolve;","import {twrWasmModule} from \"./twrmod.js\";\r\nimport {IModOpts, IModInWorkerParams, TStdioVals} from \"./twrmodbase.js\"\r\nimport {twrWasmModuleAsync} from \"./twrmodasync.js\";\r\n\r\nexport {IModOpts, TStdioVals, IModInWorkerParams};\r\nexport {twrWasmModule};\r\nexport {twrWasmModuleAsync};\r\n\r\n","import { twrDebugLogImpl } from \"./twrdebug.js\";\nimport { twrWasmModuleInJSMain } from \"./twrmodjsmain.js\";\nimport { twrTimeImpl } from \"./twrdate.js\";\nexport class twrWasmModule extends twrWasmModuleInJSMain {\n malloc;\n constructor(opts = {}) {\n super(opts, true);\n this.malloc = (size) => { throw new Error(\"error - un-init malloc called\"); };\n let canvas;\n if (this.d2dcanvas.isValid())\n canvas = this.d2dcanvas;\n else\n canvas = this.iocanvas;\n this.modParams.imports = {\n twrDebugLog: twrDebugLogImpl,\n twrTime: twrTimeImpl,\n twrDivCharOut: this.iodiv.charOut.bind(this.iodiv),\n twrCanvasGetProp: canvas.getProp.bind(canvas),\n twrCanvasDrawSeq: canvas.drawSeq.bind(canvas),\n twrCanvasCharIn: this.null,\n twrCanvasInkey: this.null,\n twrDivCharIn: this.null,\n twrSleep: this.null,\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function (x, y) { return x % y; },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil),\n };\n }\n null(inval) {\n throw new Error(\"call to unimplemented twrXXX import in twrWasmModule. Use twrWasmModuleAsync ?\");\n }\n}\n//# sourceMappingURL=twrmod.js.map","import {twrDebugLogImpl} from \"./twrdebug.js\"\r\nimport {IModOpts} from \"./twrmodbase.js\";\r\nimport {twrWasmModuleInJSMain} from \"./twrmodjsmain.js\"\r\nimport {twrCanvas} from \"./twrcanvas.js\";\r\nimport {twrTimeImpl} from \"./twrdate.js\"\r\n\r\n\r\n\r\nexport class twrWasmModule extends twrWasmModuleInJSMain {\r\n\t malloc:(size:number)=>Promise;\r\n\r\n\r\n\tconstructor(opts:IModOpts={}) {\r\n\t\tsuper(opts, true);\r\n\t\tthis.malloc=(size:number)=>{throw new Error(\"error - un-init malloc called\")};\r\n\t\t\r\n\t\tlet canvas:twrCanvas;\r\n\t\tif (this.d2dcanvas.isValid()) canvas=this.d2dcanvas;\r\n\t\telse canvas=this.iocanvas;\r\n\r\n\t\tthis.modParams.imports={\r\n\t\t\ttwrDebugLog:twrDebugLogImpl,\r\n\t\t\ttwrTime:twrTimeImpl,\r\n\t\t\ttwrDivCharOut:this.iodiv.charOut.bind(this.iodiv),\r\n\t\t\ttwrCanvasGetProp:canvas.getProp.bind(canvas),\r\n\t\t\ttwrCanvasDrawSeq:canvas.drawSeq.bind(canvas),\r\n\t\t\ttwrCanvasCharIn:this.null,\r\n\t\t\ttwrCanvasInkey:this.null,\r\n\t\t\ttwrDivCharIn:this.null,\r\n\t\t\ttwrSleep:this.null,\r\n\r\n\t\t\ttwrSin:Math.sin,\r\n\t\t\ttwrCos:Math.cos,\r\n\t\t\ttwrTan: Math.tan,\r\n\t\t\ttwrFAbs: Math.abs,\r\n\t\t\ttwrACos: Math.acos,\r\n\t\t\ttwrASin: Math.asin,\r\n\t\t\ttwrATan: Math.atan,\r\n\t\t\ttwrExp: Math.exp,\r\n\t\t\ttwrFloor: Math.floor,\r\n\t\t\ttwrCeil: Math.ceil,\r\n\t\t\ttwrFMod: function(x:number, y:number) {return x%y},\r\n\t\t\ttwrLog: Math.log,\r\n\t\t\ttwrPow: Math.pow,\r\n\t\t\ttwrSqrt: Math.sqrt,\r\n\t\t\ttwrTrunc: Math.trunc,\r\n\r\n\t\t\ttwrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\r\n\t\t\ttwrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\r\n\t\t\ttwrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\r\n\t\t\ttwrAtod: this.floatUtil.atod.bind(this.floatUtil),\r\n\t\t\ttwrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil),\r\n\t\t}\r\n\t}\r\n\r\n\tnull(inval?:any) {\r\n\t\tthrow new Error(\"call to unimplemented twrXXX import in twrWasmModule. Use twrWasmModuleAsync ?\");\r\n\t}\r\n}\r\n\r\n\r\n\r\n\r\n","let logline = \"\";\nexport function twrDebugLogImpl(char) {\n if (char == 10 || char == 3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\n console.log(logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n logline = \"\";\n }\n else {\n logline = logline + String.fromCharCode(char);\n if (logline.length >= 200) {\n console.log(logline);\n logline = \"\";\n }\n }\n}\n// ************************************************************************\n// debugLog doesn't currently wait for the message to log, it returns immediately.\n// I could move this to be in the twrWaitingCalls class\nexport function twrDebugLogProxy(ch) {\n postMessage([\"debug\", ch]);\n}\n//# sourceMappingURL=twrdebug.js.map","\r\nlet logline=\"\";\r\nexport function twrDebugLogImpl(char:number) {\r\n\tif (char==10 || char==3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\r\n\t\tconsole.log(logline);\t// ideally without a linefeed, but there is no way to not have a LF with console.log API.\r\n\t\tlogline=\"\";\r\n\t}\r\n\telse {\r\n\t\tlogline=logline+String.fromCharCode(char);\r\n\t\tif (logline.length>=200) {\r\n\t\t\tconsole.log(logline);\r\n\t\t\tlogline=\"\";\r\n\t\t}\r\n\t}\r\n}\r\n\r\n// ************************************************************************\r\n// debugLog doesn't currently wait for the message to log, it returns immediately.\r\n// I could move this to be in the twrWaitingCalls class\r\nexport function twrDebugLogProxy(ch:number) {\r\n postMessage([\"debug\", ch]);\r\n}\r\n\r\n","// This class extends base to handle options when called in the main Java Script thread\nimport { twrDiv } from \"./twrdiv.js\";\nimport { twrWasmModuleBase } from \"./twrmodbase.js\";\nimport { twrCanvas } from \"./twrcanvas.js\";\nexport class twrWasmModuleInJSMain extends twrWasmModuleBase {\n iocanvas;\n d2dcanvas;\n iodiv;\n modParams;\n constructor(opts = {}, isWasmModule = false) {\n super(isWasmModule);\n if (typeof document === 'undefined')\n throw new Error(\"twrWasmModuleJSMain should only be created in JavaScript Main.\");\n const eiodiv = document.getElementById(\"twr_iodiv\");\n const eiocanvas = document.getElementById(\"twr_iocanvas\");\n const ed2dcanvas = document.getElementById(\"twr_d2dcanvas\");\n if (eiocanvas && ed2dcanvas)\n throw new Error(\"Both twr_iocanvas and twr_d2dcanvas defined. Currently only one canvas allowed.\");\n if (opts.stdio == 'div' && !eiodiv)\n throw new Error(\"twrWasmModuleBase opts=='div' but twr_iodiv not defined\");\n if (opts.stdio == 'canvas' && !eiocanvas)\n throw new Error(\"twrWasmModuleBase, opts=='canvas' but twr_iocanvas not defined\");\n if (opts.isd2dcanvas && !ed2dcanvas)\n throw new Error(\"twrWasmModuleBase, opts.isdrawcanvas==true but twr_d2dcanvas not defined\");\n // set default opts based on elements found\n if (eiodiv)\n opts = { stdio: \"div\", ...opts };\n else if (eiocanvas)\n opts = { stdio: \"canvas\", ...opts };\n else\n opts = { stdio: \"debug\", ...opts };\n if (!eiodiv && !eiocanvas)\n console.log(\"Since neither twr_iocanvas nor twr_iodiv is defined, stdout directed to debug console.\");\n else\n console.log('tiny-wasm-runtime: stdio set to: ', opts.stdio);\n if (eiocanvas)\n opts = { windim: [64, 16], ...opts };\n else\n opts = { windim: [0, 0], ...opts };\n if (!opts.imports)\n opts.imports = {};\n let styleIsDefault = false;\n if (!opts.backcolor) {\n styleIsDefault = true;\n opts.backcolor = \"black\";\n }\n if (!opts.forecolor) {\n styleIsDefault = true;\n opts.forecolor = \"white\";\n }\n if (!opts.fontsize) {\n styleIsDefault = true;\n opts.fontsize = 16;\n }\n if (opts.isd2dcanvas === undefined) {\n if (ed2dcanvas)\n opts.isd2dcanvas = true;\n else\n opts.isd2dcanvas = false;\n }\n this.modParams = {\n stdio: opts.stdio,\n windim: opts.windim,\n imports: opts.imports,\n forecolor: opts.forecolor,\n backcolor: opts.backcolor,\n styleIsDefault: styleIsDefault,\n fontsize: opts.fontsize,\n isd2dcanvas: opts.isd2dcanvas\n };\n this.iodiv = new twrDiv(eiodiv, this.modParams, this);\n this.iocanvas = new twrCanvas(eiocanvas, this.modParams, this);\n this.d2dcanvas = new twrCanvas(ed2dcanvas, this.modParams, this);\n }\n divLog(...params) {\n for (var i = 0; i < params.length; i++) {\n this.iodiv.stringOut(params[i].toString());\n this.iodiv.charOut(32); // space\n }\n this.iodiv.charOut(10);\n }\n}\n//# sourceMappingURL=twrmodjsmain.js.map","// This class extends base to handle options when called in the main Java Script thread\r\n\r\nimport {twrDiv} from \"./twrdiv.js\"\r\nimport {IModParams, IModOpts, twrWasmModuleBase} from \"./twrmodbase.js\"\r\nimport {twrCanvas} from \"./twrcanvas.js\"\r\n\r\n\r\nexport abstract class twrWasmModuleInJSMain extends twrWasmModuleBase {\r\n\tiocanvas:twrCanvas;\r\n\td2dcanvas:twrCanvas;\r\n\tiodiv:twrDiv;\r\n\tmodParams:IModParams;\r\n\r\n constructor(opts:IModOpts={}, isWasmModule=false) {\r\n\t\tsuper(isWasmModule);\r\n\t\tif (typeof document === 'undefined')\r\n\t\t\tthrow new Error (\"twrWasmModuleJSMain should only be created in JavaScript Main.\");\r\n\r\n\t\tconst eiodiv=document.getElementById(\"twr_iodiv\") as HTMLDivElement;\r\n\t\tconst eiocanvas=document.getElementById(\"twr_iocanvas\") as HTMLCanvasElement;\r\n\t\tconst ed2dcanvas=document.getElementById(\"twr_d2dcanvas\") as HTMLCanvasElement;\r\n\r\n\t\tif (eiocanvas && ed2dcanvas) throw new Error (\"Both twr_iocanvas and twr_d2dcanvas defined. Currently only one canvas allowed.\");\r\n\t\tif (opts.stdio=='div' && !eiodiv) throw new Error(\"twrWasmModuleBase opts=='div' but twr_iodiv not defined\");\r\n\t\tif (opts.stdio=='canvas' && !eiocanvas) throw new Error(\"twrWasmModuleBase, opts=='canvas' but twr_iocanvas not defined\");\r\n\t\tif (opts.isd2dcanvas && !ed2dcanvas) throw new Error(\"twrWasmModuleBase, opts.isdrawcanvas==true but twr_d2dcanvas not defined\");\r\n\r\n\t\t// set default opts based on elements found\r\n\t\tif (eiodiv) opts={stdio:\"div\", ...opts};\r\n\t\telse if (eiocanvas) opts={stdio:\"canvas\", ...opts};\r\n\t\telse opts={stdio:\"debug\", ...opts};\r\n\r\n\t\tif (!eiodiv && !eiocanvas) console.log(\"Since neither twr_iocanvas nor twr_iodiv is defined, stdout directed to debug console.\");\r\n\t\telse console.log('tiny-wasm-runtime: stdio set to: ', opts.stdio);\r\n\r\n\t\tif (eiocanvas) opts={windim:[64, 16], ...opts};\r\n\t\telse opts={windim:[0, 0], ...opts};\r\n\r\n\t\tif (!opts.imports) opts.imports={};\r\n\r\n\t\tlet styleIsDefault=false;\r\n\t\tif (!opts.backcolor) {styleIsDefault=true; opts.backcolor=\"black\";}\r\n\t\tif (!opts.forecolor) {styleIsDefault=true; opts.forecolor=\"white\";}\r\n\t\tif (!opts.fontsize) {styleIsDefault=true; opts.fontsize=16;}\r\n\r\n\t\tif (opts.isd2dcanvas===undefined) {\r\n\t\t\tif (ed2dcanvas) \r\n\t\t\t\topts.isd2dcanvas=true;\r\n\t\t\telse\r\n\t\t\t\topts.isd2dcanvas=false;\r\n\t\t}\r\n\r\n\t\tthis.modParams={\r\n\t\t\tstdio:opts.stdio!, \r\n\t\t\twindim:opts.windim!, \r\n\t\t\timports:opts.imports, \r\n\t\t\tforecolor:opts.forecolor, \r\n\t\t\tbackcolor:opts.backcolor, \r\n\t\t\tstyleIsDefault: styleIsDefault,\r\n\t\t\tfontsize:opts.fontsize,\r\n\t\t\tisd2dcanvas:opts.isd2dcanvas\r\n\t\t};\r\n\r\n\t\tthis.iodiv=new twrDiv(eiodiv, this.modParams, this);\r\n\t\tthis.iocanvas=new twrCanvas(eiocanvas, this.modParams, this);\r\n\t\tthis.d2dcanvas=new twrCanvas(ed2dcanvas, this.modParams, this);\r\n\r\n\t}\r\n\r\n\tdivLog(...params: string[]) {\r\n\t\tfor (var i = 0; i < params.length; i++) {\r\n\t\t\tthis.iodiv.stringOut(params[i].toString());\r\n\t\t\tthis.iodiv.charOut(32); // space\r\n\t\t}\r\n\t\tthis.iodiv.charOut(10);\r\n\t }\r\n}","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nexport class twrDiv {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase) {\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\n this.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n if (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.divKeys.sharedArray];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */\n charOut(ch) {\n if (!this.div)\n return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n }\n switch (ch) {\n case 10: // newline\n case 13: // return\n if (ch == 10 && this.lastChar == 13)\n break; // detect CR LF and treat as single new line\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8: // backspace\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n case 0xE: // cursor on\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF: // cursor off\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for (let i = 0; i < str.length; i++)\n this.charOut(str.charCodeAt(i));\n }\n}\nexport class twrDivProxy {\n divKeys;\n constructor(params) {\n const [divKeysBuffer] = params;\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n charOut(ch) {\n postMessage([\"divout\", ch]);\n }\n}\n//# sourceMappingURL=twrdiv.js.map","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\r\nimport { IModParams } from \"./twrmodbase.js\";\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\";\r\n\r\nexport type TDivProxyParams = [SharedArrayBuffer];\r\n\r\nexport interface IDiv {\r\n charOut: (ds:number)=>void,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TDivProxyParams,\r\n }\r\n\r\n\r\nexport class twrDiv implements IDiv {\r\n\tdiv:HTMLDivElement|null|undefined;\r\n\tdivKeys?:twrSharedCircularBuffer;\r\n\tCURSOR=String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\r\n\tcursorOn:boolean=false;\r\n\tlastChar:number=0;\r\n\textraBR:boolean=false;\r\n\towner:twrWasmModuleBase;\r\n\r\n constructor(element:HTMLDivElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n\t\tthis.div=element;\r\n\t\tthis.owner=modbase;\r\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\r\n\t\t\tthis.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n\t\t}\r\n\r\n\t\tif (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\r\n\t\t\tthis.div.style.backgroundColor = modParams.backcolor;\r\n\t\t\tthis.div.style.color = modParams.forecolor;\r\n\t\t\tthis.div.style.font=modParams.fontsize.toString()+\"px arial\"\r\n\t\t}\r\n }\r\n\r\n\tisValid() {\r\n\t\treturn !!this.div;\r\n\t}\r\n\r\n getProxyParams() : TDivProxyParams {\r\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [ this.divKeys.sharedArray];\r\n }\r\n\r\n\r\n/* \r\n * add character to div. Supports the following control codes:\r\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\r\n * 0xE cursor on \r\n * 0x8 backspace\r\n * 0xF cursor off \r\n*/\r\n\tcharOut(ch:number) {\r\n\r\n\t\tif (!this.div) return;\r\n\r\n\t\t//console.log(\"div::charout: \", ch);\r\n\r\n\t\tif (this.extraBR) {\r\n\t\t\tthis.extraBR=false;\r\n\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -4);\r\n\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t}\r\n\r\n\t\tswitch (ch) {\r\n\t\t\tcase 10: // newline\r\n\t\t\tcase 13: // return\r\n\t\t\t\tif (ch==10 && this.lastChar==13) break; // detect CR LF and treat as single new line\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\r\n\t\t\t\tthis.extraBR=true;\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\t//element.scrollIntoView();\r\n\t\t\t\t//element.scrollTop = element.scrollHeight;\r\n\t\t\t\tlet p = this.div.getBoundingClientRect();\r\n\t\t\t\twindow.scrollTo(0, p.height+100);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 8: // backspace\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xE: // cursor on\r\n\t\t\t\tif (!this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=true;\r\n\t\t\t\t\tthis.div.innerHTML += this.CURSOR;\r\n\t\t\t\t\tthis.div.focus();\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xF: // cursor off\r\n\t\t\t\tif (this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=false;\r\n\t\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += String.fromCharCode(ch);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\tthis.lastChar=ch;\r\n\t}\r\n\r\n\tstringOut(str:string) {\r\n\t\tfor (let i=0; i < str.length; i++)\r\n\t\t\tthis.charOut(str.charCodeAt(i));\r\n\t}\r\n}\r\n\r\n\r\nexport class twrDivProxy implements IDiv {\r\n divKeys: twrSharedCircularBuffer;\r\n\r\n constructor(params:TDivProxyParams) {\r\n const [divKeysBuffer] = params;\r\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\r\n }\r\n\r\n charIn() { \r\n return this.divKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.divKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n\tcharOut(ch:number) {\r\n\t\tpostMessage([\"divout\", ch]);\r\n\t}\r\n}\r\n\r\n","//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst RDIDX = 256;\nconst WRIDX = 257;\nconst LEN = 256;\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\n// the first 256 array entries are the circular buffer\n// the next two are used for the read and write index\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\nexport class twrSharedCircularBuffer {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(258 * 4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[RDIDX] = 0;\n this.buf[WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[WRIDX];\n this.buf[i] = n;\n i++;\n if (i == LEN)\n i = 0;\n this.buf[WRIDX] = i;\n Atomics.notify(this.buf, WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[RDIDX] = i;\n return n;\n }\n else\n return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[RDIDX] == this.buf[WRIDX];\n }\n}\n//# sourceMappingURL=twrcircular.js.map","//\r\n// This class implements a circular buffer that the main javascript thread can write to, \r\n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\r\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \r\n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\r\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\r\n//\r\n\r\nconst RDIDX=256;\r\nconst WRIDX=257;\r\nconst LEN=256;\r\n\r\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\r\n// the first 256 array entries are the circular buffer\r\n// the next two are used for the read and write index\r\n\r\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\r\n\r\nexport class twrSharedCircularBuffer {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n \r\n\tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(258*4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[RDIDX]=0;\r\n this.buf[WRIDX]=0;\r\n\t}\r\n\r\n\twrite(n:number) {\r\n let i=this.buf[WRIDX];\r\n this.buf[i]=n;\r\n i++;\r\n if (i==LEN) i=0;\r\n this.buf[WRIDX]=i; \r\n Atomics.notify(this.buf, WRIDX); \r\n\t}\r\n\r\n\tread():number {\r\n if (!this.isEmpty()) {\r\n let i=this.buf[RDIDX];\r\n let n=this.buf[i];\r\n i++;\r\n this.buf[RDIDX]=i;\r\n return n;\r\n }\r\n\t\telse\r\n return -1;\r\n\t}\r\n\r\n readWait():number {\r\n if (this.isEmpty()) {\r\n const rdptr=this.buf[RDIDX];\r\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\r\n Atomics.wait(this.buf, WRIDX, rdptr);\r\n }\r\n return this.read();\r\n\t}\r\n\r\n isEmpty():boolean {\r\n return this.buf[RDIDX]==this.buf[WRIDX];\r\n }\r\n}\r\n","import { twrFloatUtil } from \"./twrfloat.js\";\n/*********************************************************************/\n/*********************************************************************/\n/*********************************************************************/\nexport class twrWasmModuleBase {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\n floatUtil;\n constructor(isWasmModule = false) {\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new twrFloatUtil(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/\n /*********************************************************************/\n async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n }\n catch (err) {\n console.log('loadWasm() failed to fetch: ' + pathToLoad);\n throw err;\n }\n if (!response.ok)\n throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, { env: allimports });\n this.exports = instance.instance.exports;\n if (!this.exports)\n throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory)\n throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory)\n throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer)\n console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\"setmemory\", this.memory]);\n }\n if (this.isWasmModule) {\n // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (!(this.memory.buffer instanceof ArrayBuffer))\n console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size) => {\n return new Promise(resolve => {\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n }\n catch (err) {\n console.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch (this.modParams.stdio) {\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* executeC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */\n async executeC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.executeCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async executeCImpl(fname, cparams = []) {\n if (!this.exports)\n throw new Error(\"this.exports undefined\");\n if (!this.exports[fname])\n throw new Error(\"executeC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array))\n throw new Error(\"executeC: params must be array, first arg is function name\");\n if (params.length == 0)\n throw new Error(\"executeC: missing function name\");\n let cparams = [];\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n cparams[ci++] = p;\n break;\n case 'string':\n cparams[ci++] = await this.putString(p);\n break;\n case 'object':\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n }\n else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"executeC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n ci++;\n break;\n case 'string':\n this.executeCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n case 'object':\n if (p instanceof URL) {\n this.executeCImpl('twr_free', [cparams[ci]]);\n ci = ci + 2;\n break;\n }\n else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for (let j = 0; j < u8.length; j++)\n u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.executeCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n }\n else\n throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/\n /*********************************************************************/\n // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for (i = 0; i < sin.length && i < buffer_size - 1; i++)\n this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for (let i = 0; i < u8a.length; i++)\n this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === 'object' && fnin instanceof URL))\n throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [dest, src.length];\n }\n catch (err) {\n console.log('fetchAndPutURL Error. URL: ' + fnin + '\\n' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while (this.mem8[strIndex + i] && (len === undefined ? true : i < len) && (strIndex + i) < this.mem8.length) {\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0)\n throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array((this.mem8.slice(dataptr, dataptr + size)).buffer);\n return u32;\n }\n}\n//# sourceMappingURL=twrmodbase.js.map","\r\nimport {TCanvasProxyParams} from \"./twrcanvas.js\"\r\nimport {TDivProxyParams} from \"./twrdiv.js\";\r\nimport {TWaitingCallsProxyParams} from \"./twrwaitingcalls.js\"\r\nimport {twrDebugLogImpl} from \"./twrdebug.js\";\r\nimport {twrFloatUtil} from \"./twrfloat.js\";\r\n\r\n\r\nexport type TStdioVals=\"div\"|\"canvas\"|\"null\"|\"debug\";\r\n\r\nexport interface IModOpts {\r\n\tstdio?:TStdioVals, \r\n\twindim?:[number, number],\r\n\tforecolor?:string,\r\n\tbackcolor?:string,\r\n\tfontsize?:number,\r\n\tisd2dcanvas?:boolean,\r\n\timports?:{},\r\n}\r\n\r\nexport interface IModParams {\r\n\tstdio:TStdioVals, \r\n\twindim:[number, number],\r\n\tforecolor:string,\r\n\tbackcolor:string,\r\n\tfontsize:number,\r\n\tstyleIsDefault: boolean\r\n\tisd2dcanvas:boolean,\r\n\timports:{[index:string]:Function},\r\n}\r\n\r\nexport interface IModInWorkerParams {\r\n\tdivProxyParams:TDivProxyParams,\r\n\tcanvasProxyParams:TCanvasProxyParams,\r\n\twaitingCallsProxyParams:TWaitingCallsProxyParams,\r\n}\r\n\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n\r\nexport abstract class twrWasmModuleBase {\r\n\tmemory?:WebAssembly.Memory;\r\n\tmem8:Uint8Array;\r\n\tmem32:Uint32Array;\r\n\tmemD:Float64Array;\r\n\tabstract malloc:(size:number)=>Promise;\r\n\tabstract modParams:IModParams;\r\n\texports?:WebAssembly.Exports;\r\n\tisWorker=false;\r\n\tisWasmModule:boolean; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\r\n\tfloatUtil:twrFloatUtil;\r\n\r\n\tconstructor(isWasmModule=false) {\r\n\t\tthis.isWasmModule=isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\r\n\t\tthis.mem8=new Uint8Array(); \t// avoid type errors\r\n\t\tthis.mem32=new Uint32Array(); // avoid type errors\r\n\t\tthis.memD=new Float64Array(); // avoid type errors\r\n\t\tthis.floatUtil=new twrFloatUtil(this);\r\n\t\t//console.log(\"size of mem8 after constructor\",this.mem8.length);\r\n\t}\r\n\r\n\t/*********************************************************************/\r\n\t/*********************************************************************/\r\n\r\n\tasync loadWasm(pathToLoad:string) {\r\n\t\t//console.log(\"fileToLoad\",fileToLoad)\r\n\r\n\t\tlet response;\r\n\t\ttry {\r\n\t\t\tresponse=await fetch(pathToLoad);\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('loadWasm() failed to fetch: '+pathToLoad);\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t\t\r\n\t\tif (!response.ok) throw new Error(\"fetch response error on file '\"+pathToLoad+\"'\\n\"+response.statusText);\r\n\r\n\t\ttry {\r\n\t\t\tlet wasmBytes = await response.arrayBuffer();\r\n\r\n\t\t\tlet allimports:WebAssembly.ModuleImports = { \r\n\t\t\t\t...this.modParams.imports\r\n\t\t\t};\r\n\r\n\t\t\tlet instance = await WebAssembly.instantiate(wasmBytes, {env: allimports});\r\n\r\n\t\t\tthis.exports=instance.instance.exports;\r\n\t\t\tif (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\r\n\r\n\t\t\tif (this.memory) throw new Error (\"unexpected error -- this.memory already set\");\r\n\t\t\tthis.memory=this.exports.memory as WebAssembly.Memory;\r\n\t\t\tif (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\r\n\t\t\tthis.mem8 = new Uint8Array(this.memory.buffer);\r\n\t\t\tthis.mem32 = new Uint32Array(this.memory.buffer);\r\n\t\t\tthis.memD = new Float64Array(this.memory.buffer);\r\n\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\tif (this.isWorker) {\r\n\t\t\t\tif (this.memory.buffer instanceof ArrayBuffer)\r\n\t\t\t\t\tconsole.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\r\n\t\t\t\t\r\n\t\t\t\tpostMessage([\"setmemory\",this.memory]);\r\n\t\t\t}\r\n\t\t\tif (this.isWasmModule) {\r\n\t\t\t\t// here if twrWasmModule, twrWasmModuleAsync overrides this function\r\n\t\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\t\tif (!(this.memory.buffer instanceof ArrayBuffer))\r\n\t\t\t\t\tconsole.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\r\n\t\t\t}\r\n\r\n\t\t\tthis.malloc=(size:number)=>{\r\n\t\t\t\treturn new Promise(resolve => {\r\n\t\t\t\t\tconst m=this.exports!.twr_malloc as (size:number)=>number;\r\n\t\t\t\t\tresolve(m(size));\r\n\t\t\t\t});\r\n\t\t };\r\n\r\n\t\t\tthis.init();\r\n\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t}\r\n\r\n\tprivate init() {\r\n\t\t//console.log(\"loadWasm.init() enter\")\r\n\t\t\tlet p:number;\r\n\t\t\tswitch (this.modParams.stdio) {\r\n\t\t\t\tcase \"debug\":\r\n\t\t\t\t\tp=0;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"div\":\r\n\t\t\t\t\tp=1;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"canvas\":\r\n\t\t\t\t\tp=2;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"null\":\r\n\t\t\t\t\tp=3;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tp=0; // debug\r\n\t\t\t}\r\n\r\n\t\t\tconst twrInit=this.exports!.twr_wasm_init as CallableFunction;\r\n\t\t\t//console.log(\"twrInit:\",twrInit)\r\n\t\t\ttwrInit(p, this.mem8.length);\r\n\t}\r\n\r\n\t/* executeC takes an array where:\r\n\t* the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\r\n\t* and the next entries are a variable number of parameters to pass to the C function, of type\r\n\t* number - converted to int32 or float64 as appropriate\r\n\t* string - converted to a an index (ptr) into a module Memory returned via stringToMem()\r\n\t* URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\r\n\t* Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\r\n */\r\n\r\n\tasync executeC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\t\tconst cparams=await this.preCallC(params);\r\n\t\tlet retval = this.executeCImpl(params[0], cparams);\r\n\t\tthis.postCallC(cparams, params);\r\n\t\treturn retval;\r\n\t}\r\n\r\n\tasync executeCImpl(fname:string, cparams:number[]=[]) {\r\n\t\tif (!this.exports) throw new Error(\"this.exports undefined\");\r\n\t\tif (!this.exports[fname]) throw new Error(\"executeC: function '\"+fname+\"' not in export table. Use --export wasm-ld flag.\");\r\n\r\n\t\tconst f = this.exports[fname] as CallableFunction;\r\n\t\tlet cr=f(...cparams);\r\n\r\n\t\treturn cr;\r\n\t}\r\n\r\n\t// convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\r\n\tasync preCallC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tif (!(params.constructor === Array)) throw new Error (\"executeC: params must be array, first arg is function name\");\r\n\t\tif (params.length==0) throw new Error(\"executeC: missing function name\");\r\n\r\n\t\tlet cparams:number[]=[];\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tcparams[ci++]=p;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tcparams[ci++]=await this.putString(p);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tconst r=await this.fetchAndPutURL(p);\r\n\t\t\t\t\t\tcparams[ci++]=r[0]; // mem index\r\n\t\t\t\t\t\tcparams[ci++]=r[1]; // len\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tconst r=await this.putArrayBuffer(p);\r\n\t\t\t\t\t\tcparams[ci++]=r; // mem index\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tthrow new Error (\"executeC: invalid object type passed in\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn cparams;\r\n\t}\r\n\r\n\t// free the mallocs; copy array buffer data from malloc back to arraybuffer\r\n\tasync postCallC(cparams:number[], params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tthis.executeCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t\t\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tthis.executeCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\t\tci=ci+2;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tlet u8=new Uint8Array(p);\r\n\t\t\t\t\t\tfor (let j=0; j= this.mem32.length) throw new Error(\"invalid index passed to getLong: \"+idx+\", this.mem32.length: \"+this.mem32.length);\r\n\t\tconst long:number = this.mem32[idx32];\r\n\t\treturn long;\r\n\t}\r\n\t\r\n\tsetLong(idx:number, value:number) {\r\n const idx32 = Math.floor(idx / 4);\r\n if (idx32 * 4 != idx)\r\n throw new Error(\"setLong passed non long aligned address\");\r\n if (idx32 < 0 || idx32 >= this.mem32.length)\r\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\r\n this.mem32[idx32]=value;\r\n }\r\n\r\n\tgetDouble(idx:number): number {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"getLong passed non Float64 aligned address\")\r\n\t\tconst long:number = this.memD[idx64];\r\n\t\treturn long;\r\n\t}\r\n\r\n\tsetDouble(idx:number, value:number) {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"setDouble passed non Float64 aligned address\")\r\n\t\tthis.memD[idx64]=value;\r\n\t}\r\n\r\n\tgetShort(idx:number): number {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getShort: \"+idx);\r\n\t\tconst short:number = this.mem8[idx]+this.mem8[idx+1]*256;\r\n\t\treturn short;\r\n\t}\r\n\r\n\t// get a string out of module memory\r\n\t// null terminated, up until max of (optional) len\r\n\tgetString(strIndex:number, len?:number): string {\r\n\t\tlet sout=\"\";\r\n\r\n\t\tlet i=0;\r\n\t\twhile (this.mem8[strIndex+i] && (len===undefined?true:i= this.mem8.length) throw new Error(\"invalid index passed to getU8: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU8\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU8\")\r\n\r\n\t\tconst u8=this.mem8.slice(dataptr, dataptr+size);\r\n\t\treturn u8;\r\n\t}\r\n\r\n\t// get a int32 array out of module memory when passed in index to [size, dataptr]\r\n\tgetU32Arr(idx:number): Uint32Array {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getU32: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU32\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU32\")\r\n\r\n\t\tif (size%4!=0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\r\n\r\n\t\tconst u32 = new Uint32Array( (this.mem8.slice(dataptr, dataptr+size)).buffer );\r\n\t\treturn u32;\r\n\t}\r\n}\r\n","export class twrFloatUtil {\n mod;\n constructor(mod) {\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\")\n return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\")\n return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll('D', 'e').replaceAll('d', 'e'));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n }\n else {\n let r = value.toString();\n if (r.length > max_precision)\n r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, // char *\n sizeInBytes, //size_t\n value, // double\n fracpart_numdigits, //int\n dec, // int *\n sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1)\n return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) { /* nan */\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (!Number.isFinite(value)) { /* infinity */\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n }\n else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split('.');\n if (intPart == \"0\")\n intPart = \"\";\n if (intPart.length > 0) { // has integer part\n decpos = intPart.length;\n digits = intPart + fracPart;\n }\n else { // only a fraction\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length)\n return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */\n }\n}\n//# sourceMappingURL=twrfloat.js.map","\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\"\r\n\r\nexport class twrFloatUtil {\r\n mod: twrWasmModuleBase;\r\n\r\n constructor(mod: twrWasmModuleBase) {\r\n this.mod=mod;\r\n }\r\n\r\n atod(strptr:number):number {\r\n const str=this.mod.getString(strptr);\r\n\r\n const upper=str.trimStart().toUpperCase();\r\n if (upper==\"INF\" || upper==\"+INF\")\r\n return Number.POSITIVE_INFINITY;\r\n else if (upper==\"-INF\")\r\n return Number.NEGATIVE_INFINITY\r\n else {\r\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\r\n const r=Number.parseFloat(str.replaceAll('D','e').replaceAll('d','e'));\r\n return r;\r\n }\r\n }\r\n\r\n dtoa(buffer:number, buffer_size:number, value:number, max_precision:number):void {\r\n if (max_precision==-1) {\r\n const r=value.toString();\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n else {\r\n let r=value.toString();\r\n if (r.length>max_precision)\r\n r=value.toPrecision(max_precision);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n }\r\n\r\n toFixed(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toFixed(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n toExponential(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toExponential(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\r\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\r\n // Negative exponents must be now smaller than 1e-99\r\n // fully-function C version also int he source, but this is the version enabled by default\r\n fcvtS(\r\n buffer:number, // char *\r\n sizeInBytes:number, //size_t\r\n value:number, // double\r\n fracpart_numdigits:number, //int\r\n dec:number, // int *\r\n sign:number // int *\r\n ):number {\r\n\r\n if (buffer==0 ||sign==0 || dec==0 || sizeInBytes<1) return 1;\r\n\r\n let digits:string;\r\n let decpos:number;\r\n let s=0; // default to positive\r\n\r\n\r\n if (Number.isNaN(value)) { /* nan */\r\n digits=\"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (!Number.isFinite(value)) { /* infinity */\r\n digits=\"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (value==0) { \r\n digits=\"000000000000000000000000000000000000\".slice(0,fracpart_numdigits);\r\n decpos=0;\r\n }\r\n \r\n else {\r\n\r\n if (value<0) {\r\n s=1; // negative\r\n value=Math.abs(value);\r\n }\r\n\r\n if (fracpart_numdigits>100 || value > 1e+21 || value < 1e-99) { \r\n this.mod.copyString(buffer, sizeInBytes, \"\");\r\n this.mod.mem32[dec]=0;\r\n return 1;\r\n }\r\n\r\n const roundValStr=value.toFixed(fracpart_numdigits);\r\n let [intPart=\"\", fracPart=\"\"] = roundValStr.split('.');\r\n if (intPart==\"0\") intPart=\"\";\r\n\r\n if (intPart.length>0) { // has integer part\r\n decpos=intPart.length;\r\n digits=intPart+fracPart;\r\n }\r\n else { // only a fraction\r\n digits=fracPart.replace(/^0+/,\"\"); // remove leading zeros\r\n decpos=digits.length-fracPart.length;\r\n }\r\n }\r\n\r\n if (sizeInBytes-1 < digits.length) return 1; \r\n this.mod.copyString(buffer, sizeInBytes, digits);\r\n this.mod.setLong(dec, decpos);\r\n this.mod.setLong(sign, s);\r\n\r\n return 0;\r\n\r\n /*\r\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\r\n\r\n let decpos=0;\r\n let digits:string;\r\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\r\n \r\n if (decpos>0) { // has integer part\r\n const intlen=Math.max(decpos, 0);\r\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\r\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\r\n }\r\n else { // only a fraction\r\n const intpart=Math.trunc(value);\r\n const fracpart=value-intpart;\r\n const prec=fracpart_numdigits- (-decpos);\r\n console.log(\"prec=\",prec);\r\n if (prec<1) {\r\n digits=\"\";\r\n }\r\n else {\r\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\");\r\n }\r\n }\r\n\r\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\r\n console.log('digits=',digits);\r\n console.log('dec=',decpos);\r\n console.log(\"sign=\",s);\r\n */\r\n\r\n\r\n }\r\n}","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nimport { twrSignal } from \"./twrsignal.js\";\nvar D2DType;\n(function (D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})(D2DType || (D2DType = {}));\nexport class twrCanvas {\n ctx;\n props = { charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight: 0, canvasWidth: 0 };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase) {\n const { forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new twrSignal();\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext)\n throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c)\n throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2)\n throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\n }\n getProp(pn) {\n if (!this.isValid())\n console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */\n drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid())\n console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx)\n return;\n let ins = this.owner.getLong(ds); /* ds->start */\n const lastins = this.owner.getLong(ds + 4); /* ds->last */\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while (1) {\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */\n if (0 /*type!=D2DType.D2D_FILLRECT*/) {\n console.log(\"ins\", ins);\n console.log(\"hdr.next\", this.owner.mem8[ins], this.owner.mem8[ins + 1], this.owner.mem8[ins + 2], this.owner.mem8[ins + 3]);\n console.log(\"hdr.type\", this.owner.mem8[ins + 4], this.owner.mem8[ins + 5]);\n console.log(\"next 4 bytes\", this.owner.mem8[ins + 6], this.owner.mem8[ins + 7], this.owner.mem8[ins + 8], this.owner.mem8[ins + 9]);\n console.log(\"and 4 more \", this.owner.mem8[ins + 10], this.owner.mem8[ins + 11], this.owner.mem8[ins + 12], this.owner.mem8[ins + 13]);\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\n }\n switch (type) {\n case D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case D2DType.D2D_BEGINPATH:\n {\n this.ctx.beginPath();\n }\n break;\n case D2DType.D2D_FILL:\n {\n this.ctx.fill();\n }\n break;\n case D2DType.D2D_SAVE:\n {\n this.ctx.save();\n }\n break;\n case D2DType.D2D_RESTORE:\n {\n this.ctx.restore();\n }\n break;\n case D2DType.D2D_STROKE:\n {\n this.ctx.stroke();\n }\n break;\n case D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = (this.owner.getLong(ins + 48) != 0);\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n }\n else { // Uint8ClampedArray doesn't support shared memory\n this.precomputedObjects[id] = { mem8: new Uint8Array(this.owner.memory.buffer, start, length), width: width, height: height };\n }\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id])\n delete this.precomputedObjects[id];\n else\n console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) {\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n }\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) {\n this.ctx.putImageData(imgData, dx, dy);\n }\n else {\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */\n if (next == 0) {\n if (ins != lastins)\n throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal)\n this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nexport class twrCanvasProxy {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner) {\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new twrSignal(signalBuffer);\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\"drawseq\", [ds]]);\n this.drawCompleteSignal.wait();\n }\n}\n//# sourceMappingURL=twrcanvas.js.map","import {twrWasmModuleBase, IModParams} from \"./twrmodbase.js\"\r\nimport {twrSharedCircularBuffer} from \"./twrcircular.js\";\r\nimport {twrSignal} from \"./twrsignal.js\";\r\n\r\n\r\n// Canvas have a size that will be set based on the character width x height\r\n// The display size for a canvas will default to this size, but can be changed in the HTML/JS via\r\n// canvas.style.width = \"700px\";\r\n// canvas.style.height = \"500px\";\r\n\r\nexport interface ICanvasProps {\r\n\tcharWidth: number,\r\n\tcharHeight: number,\r\n\tforeColor: number,\r\n\tbackColor: number,\r\n widthInChars: number,\r\n heightInChars: number,\r\n canvasWidth:number,\r\n canvasHeight:number\r\n}\r\n\r\nenum D2DType {\r\n D2D_FILLRECT=1,\r\n D2D_FILLCHAR=5,\r\n D2D_SETLINEWIDTH=10,\r\n D2D_SETFILLSTYLERGBA=11,\r\n D2D_SETFONT=12,\r\n D2D_BEGINPATH=13,\r\n D2D_MOVETO=14,\r\n D2D_LINETO=15,\r\n D2D_FILL=16,\r\n D2D_STROKE=17,\r\n D2D_SETSTROKESTYLERGBA=18,\r\n D2D_ARC=19,\r\n D2D_STROKERECT=20,\r\n D2D_FILLTEXT=21,\r\n D2D_IMAGEDATA=22,\r\n D2D_PUTIMAGEDATA=23,\r\n D2D_BEZIERTO=24,\r\n D2D_MEASURETEXT=25,\r\n D2D_SAVE=26,\r\n D2D_RESTORE=27,\r\n D2D_CREATERADIALGRADIENT=28,\r\n D2D_SETCOLORSTOP=29,\r\n D2D_SETFILLSTYLEGRADIENT=30,\r\n D2D_RELEASEID=31,\r\n D2D_CREATELINEARGRADIENT=32,\r\n D2D_SETFILLSTYLE=33,\r\n D2D_SETSTROKESTYLE=34\r\n\r\n}\r\n\r\nexport type TCanvasProxyParams = [ICanvasProps, SharedArrayBuffer, SharedArrayBuffer];\r\n\r\nexport interface ICanvas {\r\n props: ICanvasProps,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TCanvasProxyParams,\r\n drawSeq: (ds:number)=>void,\r\n }\r\n \r\nexport class twrCanvas implements ICanvas {\r\n ctx:CanvasRenderingContext2D|undefined;\r\n props:ICanvasProps={charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight:0, canvasWidth:0};\r\n owner: twrWasmModuleBase;\r\n cmdCompleteSignal?:twrSignal;\r\n canvasKeys?: twrSharedCircularBuffer;\r\n precomputedObjects: { [index: number]: \r\n (ImageData | {mem8:Uint8Array, width:number, height:number}) |\r\n CanvasGradient\r\n };\r\n\r\n constructor(element:HTMLCanvasElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n const {forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas} = modParams; \r\n this.owner=modbase;\r\n this.props.widthInChars=modParams.windim[0];\r\n this.props.heightInChars=modParams.windim[1];\r\n\r\n if (!this.owner.isWasmModule) {\r\n this.cmdCompleteSignal=new twrSignal();\r\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n }\r\n\r\n this.precomputedObjects={};\r\n \r\n if (element) {\r\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\r\n let c=element.getContext(\"2d\");\r\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\r\n\r\n c.font = fontsize.toString()+\"px Courier New\";\r\n c.textBaseline=\"top\";\r\n const sampleText=\" \";\r\n const tm=c.measureText(sampleText);\r\n this.props.charWidth=Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\r\n let fM = c.measureText(\"X\"); \r\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\r\n\r\n if (!isd2dcanvas) {\r\n element.width=this.props.charWidth*this.props.widthInChars;\r\n element.height=this.props.charHeight*this.props.heightInChars;\r\n }\r\n\r\n this.props.canvasHeight=element.height;\r\n this.props.canvasWidth=element.width;\r\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\r\n\r\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\r\n let c2=element.getContext(\"2d\");\r\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\r\n this.ctx=c2;\r\n this.ctx.font = fontsize.toString()+\"px Courier New\";\r\n this.ctx.textBaseline=\"top\";\r\n\r\n c2.fillStyle=backcolor;\r\n this.props.backColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n c2.fillStyle=forecolor;\r\n this.props.foreColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n }\r\n\r\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\r\n\r\n //console.log(\"twrCanvas.constructor props: \", this.props);\r\n }\r\n\r\n isValid() {\r\n return !!this.ctx;\r\n }\r\n\r\n getProxyParams() : TCanvasProxyParams {\r\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\r\n }\r\n\r\n getProp(pn:number): number {\r\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n\r\n/* see draw2d.h for structs that match */\r\n\r\n drawSeq(ds:number) {\r\n //console.log(\"twr::Canvas enter drawSeq\");\r\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\r\n if (!this.ctx) return;\r\n\r\n let ins=this.owner.getLong(ds); /* ds->start */\r\n const lastins=this.owner.getLong(ds+4); /* ds->last */\r\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\r\n\r\n let next:number;\r\n //let insCount=0;\r\n\r\n while (1) {\r\n\r\n //insCount++;\r\n\r\n const type:D2DType=this.owner.getLong(ins+4); /* hdr->type */\r\n if (0/*type!=D2DType.D2D_FILLRECT*/) {\r\n console.log(\"ins\",ins)\r\n console.log(\"hdr.next\",this.owner.mem8[ins],this.owner.mem8[ins+1],this.owner.mem8[ins+2],this.owner.mem8[ins+3]);\r\n console.log(\"hdr.type\",this.owner.mem8[ins+4],this.owner.mem8[ins+5]);\r\n console.log(\"next 4 bytes\", this.owner.mem8[ins+6],this.owner.mem8[ins+7],this.owner.mem8[ins+8],this.owner.mem8[ins+9]);\r\n console.log(\"and 4 more \", this.owner.mem8[ins+10],this.owner.mem8[ins+11],this.owner.mem8[ins+12],this.owner.mem8[ins+13]);\r\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\r\n }\r\n switch (type) {\r\n case D2DType.D2D_FILLRECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.fillRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKERECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.strokeRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILLCHAR:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const c=this.owner.getShort(ins+24);\r\n let txt=String.fromCharCode(c);\r\n this.ctx.fillText(txt, x, y);\r\n }\r\n break;\r\n\r\n \r\n case D2DType.D2D_FILLTEXT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const str=this.owner.getString(this.owner.getLong(ins+24));\r\n\r\n //console.log(\"filltext \",x,y,str)\r\n \r\n this.ctx.fillText(str, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MEASURETEXT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n const tmidx=this.owner.getLong(ins+12);\r\n \r\n const tm=this.ctx.measureText(str);\r\n this.owner.setDouble(tmidx+0, tm.actualBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+8, tm.actualBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+16, tm.actualBoundingBoxLeft);\r\n this.owner.setDouble(tmidx+24, tm.actualBoundingBoxRight);\r\n this.owner.setDouble(tmidx+32, tm.fontBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+40, tm.fontBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+48, tm.width);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFONT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.font=str;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.fillStyle = cssColor;\r\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETSTROKESTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.fillStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETSTROKESTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETLINEWIDTH:\r\n {\r\n const width=this.owner.getShort(ins+8); \r\n this.ctx.lineWidth=width;\r\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MOVETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.moveTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_LINETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.lineTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEZIERTO:\r\n {\r\n const cp1x=this.owner.getDouble(ins+8);\r\n const cp1y=this.owner.getDouble(ins+16);\r\n const cp2x=this.owner.getDouble(ins+24);\r\n const cp2y=this.owner.getDouble(ins+32);\r\n const x=this.owner.getDouble(ins+40);\r\n const y=this.owner.getDouble(ins+48);\r\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEGINPATH:\r\n {\r\n this.ctx.beginPath();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILL:\r\n {\r\n this.ctx.fill();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SAVE:\r\n {\r\n this.ctx.save();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_RESTORE:\r\n {\r\n this.ctx.restore();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKE:\r\n {\r\n this.ctx.stroke();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_ARC:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const radius=this.owner.getDouble(ins+24);\r\n const startAngle=this.owner.getDouble(ins+32);\r\n const endAngle=this.owner.getDouble(ins+40);\r\n const counterClockwise= (this.owner.getLong(ins+48)!=0);\r\n\r\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_IMAGEDATA:\r\n {\r\n const start=this.owner.getLong(ins+8);\r\n const length=this.owner.getLong(ins+12);\r\n const width=this.owner.getLong(ins+16);\r\n const height=this.owner.getLong(ins+20);\r\n const id=this.owner.getLong(ins+24);\r\n\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\r\n\r\n if (this.owner.isWasmModule) {\r\n const z = new Uint8ClampedArray(this.owner.memory!.buffer, start, length);\r\n this.precomputedObjects[id]=new ImageData(z, width, height);\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory\r\n this.precomputedObjects[id]={mem8: new Uint8Array(this.owner.memory!.buffer, start, length), width:width, height:height};\r\n }\r\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_CREATERADIALGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const radius0=this.owner.getDouble(ins+24);\r\n const x1=this.owner.getDouble(ins+32);\r\n const y1=this.owner.getDouble(ins+40);\r\n const radius1=this.owner.getDouble(ins+48);\r\n const id= this.owner.getLong(ins+56);\r\n\r\n let gradient=this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_CREATELINEARGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const x1=this.owner.getDouble(ins+24);\r\n const y1=this.owner.getDouble(ins+32);\r\n const id= this.owner.getLong(ins+40);\r\n \r\n let gradient=this.ctx.createLinearGradient(x0, y0, x1, y1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETCOLORSTOP:\r\n {\r\n const id = this.owner.getLong(ins+8);\r\n const pos=this.owner.getLong(ins+12);\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+16));\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n gradient.addColorStop(pos, cssColor);\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n this.ctx.fillStyle=gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_RELEASEID:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (this.precomputedObjects[id])\r\n delete this.precomputedObjects[id];\r\n else\r\n console.log(\"warning: D2D_RELEASEID with undefined ID \",id);\r\n }\r\n break\r\n\r\n \r\n\r\n case D2DType.D2D_PUTIMAGEDATA:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n const dx=this.owner.getLong(ins+12);\r\n const dy=this.owner.getLong(ins+16);\r\n const dirtyX=this.owner.getLong(ins+20);\r\n const dirtyY=this.owner.getLong(ins+24);\r\n const dirtyWidth=this.owner.getLong(ins+28);\r\n const dirtyHeight=this.owner.getLong(ins+32);\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \"+id);\r\n\r\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\r\n\r\n let imgData:ImageData;\r\n if (this.owner.isWasmModule) {\r\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\r\n imgData=this.precomputedObjects[id] as ImageData;\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\r\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\r\n const z = this.precomputedObjects[id] as {mem8:Uint8Array, width:number, height:number}; // Uint8Array\r\n const ca=Uint8ClampedArray.from(z.mem8); // shallow copy\r\n imgData=new ImageData(ca, z.width, z.height);\r\n }\r\n \r\n if (dirtyWidth==0 && dirtyHeight==0) {\r\n this.ctx.putImageData(imgData, dx, dy);\r\n }\r\n else {\r\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\r\n }\r\n }\r\n break;\r\n\r\n default:\r\n throw new Error (\"unimplemented or unknown Sequence Type in drawSeq: \"+type);\r\n }\r\n next=this.owner.getLong(ins); /* hdr->next */\r\n if (next==0) {\r\n if (ins!=lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\r\n break;\r\n }\r\n ins=next;\r\n }\r\n\r\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\r\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\r\n }\r\n}\r\n\r\nexport class twrCanvasProxy implements ICanvas {\r\n canvasKeys: twrSharedCircularBuffer;\r\n drawCompleteSignal:twrSignal;\r\n props: ICanvasProps;\r\n owner: twrWasmModuleBase;\r\n\r\n constructor(params:TCanvasProxyParams, owner:twrWasmModuleBase) {\r\n const [props, signalBuffer, canvasKeysBuffer] = params;\r\n this.drawCompleteSignal = new twrSignal(signalBuffer);\r\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\r\n this.props=props;\r\n this.owner=owner;\r\n\r\n //console.log(\"Create New twrCanvasProxy: \",this.props)\r\n\r\n }\r\n\r\n charIn() { \r\n //ctx.commit(); not avail in chrome\r\n \r\n //postMessage([\"debug\", 'x']);\r\n \r\n return this.canvasKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.canvasKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n getProp(pn:number): number {\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n \r\n drawSeq(ds:number) {\r\n this.drawCompleteSignal.reset();\r\n postMessage([\"drawseq\", [ds]]);\r\n this.drawCompleteSignal.wait();\r\n }\r\n}\r\n","//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar twrSignalState;\n(function (twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})(twrSignalState || (twrSignalState = {}));\n;\nexport class twrSignal {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window valid\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == twrSignalState.WAITING) {\n //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\n //console.log(\"released...\");\n }\n }\n isSignaled() {\n return this.buf[0] == twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = twrSignalState.WAITING;\n }\n}\n//# sourceMappingURL=twrsignal.js.map","//\r\n// This class implements a simple signal/wait mechanism\r\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\r\n//\r\n\r\nenum twrSignalState {\r\n WAITING=0,\r\n SIGNALED=1\r\n};\r\n\r\nexport class twrSignal {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n\r\n \tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window valid\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) \r\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[0]=twrSignalState.WAITING;\r\n\t}\r\n\r\n\tsignal() {\r\n this.buf[0]=twrSignalState.SIGNALED; \r\n //console.log(\"about to signal\");\r\n Atomics.notify(this.buf, 0); \r\n\t}\r\n\r\n wait() {\r\n if (this.buf[0]==twrSignalState.WAITING) {\r\n //console.log(\"waiting...\");\r\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\r\n //console.log(\"released...\");\r\n\r\n }\r\n\t}\r\n isSignaled():boolean {\r\n return this.buf[0]==twrSignalState.SIGNALED;\r\n }\r\n\r\n reset() {\r\n this.buf[0]=twrSignalState.WAITING;\r\n }\r\n}\r\n","export function twrTimeImpl() {\n return Date.now();\n}\n//# sourceMappingURL=twrdate.js.map","\r\nexport function twrTimeImpl() {\r\n\r\n return Date.now();\r\n\r\n}","import { twrDebugLogImpl } from \"./twrdebug.js\";\nimport { twrWasmModuleInJSMain } from \"./twrmodjsmain.js\";\nimport { twrWaitingCalls } from \"./twrwaitingcalls.js\";\nimport whatkey from \"whatkey\";\nexport class twrWasmModuleAsync extends twrWasmModuleInJSMain {\n myWorker;\n malloc;\n loadWasmResolve;\n loadWasmReject;\n executeCResolve;\n executeCReject;\n initLW = false;\n waitingcalls;\n constructor(opts) {\n super(opts);\n this.malloc = (size) => { throw new Error(\"Error - un-init malloc called.\"); };\n if (!window.Worker)\n throw new Error(\"This browser doesn't support web workers.\");\n this.myWorker = new Worker(new URL('twrmodworker.js', import.meta.url), { type: \"module\" });\n this.myWorker.onmessage = this.processMsg.bind(this);\n }\n // overrides base implementation\n async loadWasm(pathToLoad) {\n if (this.initLW)\n throw new Error(\"twrWasmAsyncModule::loadWasm can only be called once per twrWasmAsyncModule instance\");\n this.initLW = true;\n return new Promise((resolve, reject) => {\n this.loadWasmResolve = resolve;\n this.loadWasmReject = reject;\n this.malloc = (size) => {\n return this.executeCImpl(\"twr_malloc\", [size]);\n };\n this.waitingcalls = new twrWaitingCalls(); // handle's calls that cross the worker thread - main js thread boundary\n let canvas;\n if (this.d2dcanvas.isValid())\n canvas = this.d2dcanvas;\n else\n canvas = this.iocanvas;\n const modWorkerParams = {\n divProxyParams: this.iodiv.getProxyParams(),\n canvasProxyParams: canvas.getProxyParams(),\n waitingCallsProxyParams: this.waitingcalls.getProxyParams(),\n };\n const urlToLoad = new URL(pathToLoad, document.URL);\n const startMsg = { urlToLoad: urlToLoad.href, modWorkerParams: modWorkerParams, modParams: this.modParams };\n this.myWorker.postMessage(['startup', startMsg]);\n });\n }\n async executeC(params) {\n const cparams = await this.preCallC(params); // will also validate params[0]\n return this.executeCImpl(params[0], cparams);\n }\n async executeCImpl(fname, cparams = []) {\n return new Promise((resolve, reject) => {\n this.executeCResolve = resolve;\n this.executeCReject = reject;\n this.myWorker.postMessage(['executeC', fname, cparams]);\n });\n }\n // this function should be called from HTML \"keydown\" event from
\n keyDownDiv(ev) {\n if (!this.iodiv || !this.iodiv.divKeys)\n throw new Error(\"unexpected undefined twrWasmAsyncModule.divKeys\");\n this.iodiv.divKeys.write(whatkey(ev).char.charCodeAt(0));\n }\n // this function should be called from HTML \"keydown\" event from \n keyDownCanvas(ev) {\n if (!this.iocanvas || !this.iocanvas.canvasKeys)\n throw new Error(\"unexpected undefined twrWasmAsyncModule.canvasKeys\");\n this.iocanvas.canvasKeys.write(whatkey(ev).char.charCodeAt(0));\n }\n processMsg(event) {\n const msgType = event.data[0];\n const d = event.data[1];\n //console.log(\"twrWasmAsyncModule - got message: \"+event.data)\n switch (msgType) {\n case \"divout\":\n if (this.iodiv.isValid())\n this.iodiv.charOut(d);\n else\n console.log('error - msg divout received but iodiv is undefined.');\n break;\n case \"debug\":\n twrDebugLogImpl(d);\n break;\n case \"drawseq\":\n {\n //console.log(\"twrModAsync got message drawseq\");\n const [ds] = d;\n if (this.iocanvas.isValid())\n this.iocanvas.drawSeq(ds);\n else if (this.d2dcanvas.isValid())\n this.d2dcanvas.drawSeq(ds);\n else\n throw new Error('msg drawseq received but canvas is undefined.');\n break;\n }\n case \"setmemory\":\n this.memory = d;\n if (!this.memory)\n throw new Error(\"unexpected error - undefined memory in startupOkay msg\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n //console.log(\"memory set\",this.mem8.length);\n break;\n case \"startupFail\":\n if (this.loadWasmReject)\n this.loadWasmReject(d);\n else\n throw new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmReject)\");\n break;\n case \"startupOkay\":\n if (this.loadWasmResolve)\n this.loadWasmResolve(undefined);\n else\n throw new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmResolve)\");\n break;\n case \"executeCFail\":\n if (this.executeCReject)\n this.executeCReject(d);\n else\n throw new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined executeCReject)\");\n break;\n case \"executeCOkay\":\n if (this.executeCResolve)\n this.executeCResolve(d);\n else\n throw new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined executeCResolve)\");\n break;\n default:\n if (!this.waitingcalls)\n throw new Error(\"internal error: this.waitingcalls undefined.\");\n if (!this.waitingcalls.processMessage(msgType, d))\n throw new Error(\"twrWasmAsyncModule - unknown and unexpected msgType: \" + msgType);\n }\n }\n}\n//# sourceMappingURL=twrmodasync.js.map","import {IModOpts, IModParams, IModInWorkerParams} from \"./twrmodbase.js\";\r\nimport {twrDebugLogImpl} from \"./twrdebug.js\";\r\nimport {twrWasmModuleInJSMain} from \"./twrmodjsmain.js\"\r\nimport {twrWaitingCalls} from \"./twrwaitingcalls.js\"\r\nimport {twrCanvas} from \"./twrcanvas.js\";\r\n\r\nimport whatkey from \"whatkey\";\r\n\r\nexport type TAsyncModStartupMsg = {\r\n\turlToLoad: string,\r\n\tmodWorkerParams: IModInWorkerParams,\r\n\tmodParams: IModParams \r\n};\r\n\t\t\r\nexport class twrWasmModuleAsync extends twrWasmModuleInJSMain {\r\n\tmyWorker:Worker;\r\n\tmalloc:(size:number)=>Promise;\r\n\tloadWasmResolve?: (value: void) => void;\r\n\tloadWasmReject?: (reason?: any) => void;\r\n\texecuteCResolve?: (value: unknown) => void;\r\n\texecuteCReject?: (reason?: any) => void;\r\n\tinitLW=false;\r\n\twaitingcalls?:twrWaitingCalls;\r\n\r\n\r\n\tconstructor(opts?:IModOpts) {\r\n\t\tsuper(opts);\r\n\r\n\t\tthis.malloc=(size:number)=>{throw new Error(\"Error - un-init malloc called.\")};\r\n\r\n\t\tif (!window.Worker) throw new Error(\"This browser doesn't support web workers.\");\r\n\t\tthis.myWorker = new Worker(new URL('twrmodworker.js', import.meta.url), {type: \"module\" });\r\n\t\tthis.myWorker.onmessage= this.processMsg.bind(this);\r\n\t}\r\n\r\n\t// overrides base implementation\r\n\tasync loadWasm(pathToLoad:string) {\r\n\t\tif (this.initLW) \tthrow new Error(\"twrWasmAsyncModule::loadWasm can only be called once per twrWasmAsyncModule instance\");\r\n\t\tthis.initLW=true;\r\n\r\n\t\treturn new Promise((resolve, reject)=>{\r\n\t\t\tthis.loadWasmResolve=resolve;\r\n\t\t\tthis.loadWasmReject=reject;\r\n\r\n\t\t\tthis.malloc = (size:number) => {\r\n\t\t\t\treturn this.executeCImpl(\"twr_malloc\", [size]) as Promise;\r\n\t\t\t}\r\n\r\n\t\t\tthis.waitingcalls=new twrWaitingCalls(); // handle's calls that cross the worker thread - main js thread boundary\r\n\r\n\t\t\tlet canvas:twrCanvas;\r\n\t\t\tif (this.d2dcanvas.isValid()) canvas=this.d2dcanvas;\r\n\t\t\telse canvas=this.iocanvas;\r\n\r\n\t\t\tconst modWorkerParams={\r\n\t\t\t\tdivProxyParams: this.iodiv.getProxyParams(), \r\n\t\t\t\tcanvasProxyParams: canvas.getProxyParams(),\r\n\t\t\t\twaitingCallsProxyParams: this.waitingcalls.getProxyParams(),\r\n\t\t\t};\r\n\t\t\tconst urlToLoad = new URL(pathToLoad, document.URL);\r\n\t\t\tconst startMsg:TAsyncModStartupMsg={ urlToLoad: urlToLoad.href, modWorkerParams: modWorkerParams, modParams: this.modParams};\r\n\t\t\tthis.myWorker.postMessage(['startup', startMsg]);\r\n\t\t});\r\n\t}\r\n\r\n\tasync executeC(params:[string, ...(string|number|Uint8Array)[]]) {\r\n\t\tconst cparams=await this.preCallC(params); // will also validate params[0]\r\n\t\treturn this.executeCImpl(params[0], cparams);\r\n\t}\t\r\n\r\n\tasync executeCImpl(fname:string, cparams:number[]=[]) {\r\n\t\treturn new Promise((resolve, reject)=>{\r\n\t\t\tthis.executeCResolve=resolve;\r\n\t\t\tthis.executeCReject=reject;\r\n\t\t\tthis.myWorker.postMessage(['executeC', fname, cparams]);\r\n\t\t});\r\n\t}\r\n\t\r\n\t// this function should be called from HTML \"keydown\" event from
\r\n\tkeyDownDiv(ev:KeyboardEvent) {\r\n\t\tif (!this.iodiv || !this.iodiv.divKeys) throw new Error(\"unexpected undefined twrWasmAsyncModule.divKeys\");\r\n\t\tthis.iodiv.divKeys.write(whatkey(ev).char.charCodeAt(0));\r\n\t}\r\n\r\n\t// this function should be called from HTML \"keydown\" event from \r\n\tkeyDownCanvas(ev:KeyboardEvent) {\r\n\t\tif (!this.iocanvas || !this.iocanvas.canvasKeys) throw new Error(\"unexpected undefined twrWasmAsyncModule.canvasKeys\");\r\n\t\tthis.iocanvas.canvasKeys.write(whatkey(ev).char.charCodeAt(0));\r\n\t}\r\n\r\n\tprocessMsg(event: MessageEvent) {\r\n\t\tconst msgType=event.data[0];\r\n\t\tconst d=event.data[1];\r\n\r\n\t\t//console.log(\"twrWasmAsyncModule - got message: \"+event.data)\r\n\r\n\t\tswitch (msgType) {\r\n\t\t\tcase \"divout\":\r\n\t\t\t\tif (this.iodiv.isValid())\r\n\t\t\t\t\tthis.iodiv.charOut(d);\r\n\t\t\t\telse\r\n\t\t\t\t\tconsole.log('error - msg divout received but iodiv is undefined.')\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"debug\":\r\n\t\t\t\ttwrDebugLogImpl(d);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"drawseq\":\r\n\t\t\t{\r\n\t\t\t\t//console.log(\"twrModAsync got message drawseq\");\r\n\t\t\t\tconst [ds] = d;\r\n\t\t\t\tif (this.iocanvas.isValid())\r\n\t\t\t\t\tthis.iocanvas.drawSeq(ds);\r\n\t\t\t\telse if (this.d2dcanvas.isValid())\r\n\t\t\t\t\tthis.d2dcanvas.drawSeq(ds);\r\n\t\t\t\telse\r\n\t\t\t\t\tthrow new Error('msg drawseq received but canvas is undefined.')\r\n\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\t\tcase \"setmemory\":\r\n\t\t\t\tthis.memory=d;\r\n\t\t\t\tif (!this.memory) throw new Error(\"unexpected error - undefined memory in startupOkay msg\");\r\n\t\t\t\tthis.mem8 = new Uint8Array(this.memory.buffer);\r\n\t\t\t\tthis.mem32 = new Uint32Array(this.memory.buffer);\r\n\t\t\t\tthis.memD = new Float64Array(this.memory.buffer);\r\n\t\t\t\t//console.log(\"memory set\",this.mem8.length);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"startupFail\":\r\n\t\t\t\tif (this.loadWasmReject)\r\n\t\t\t\t\tthis.loadWasmReject(d);\r\n\t\t\t\telse\r\n\t\t\t\t\tthrow new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmReject)\");\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"startupOkay\":\r\n\r\n\t\t\t\tif (this.loadWasmResolve)\r\n\t\t\t\t\tthis.loadWasmResolve(undefined);\r\n\t\t\t\telse\r\n\t\t\t\t\tthrow new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmResolve)\");\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"executeCFail\":\r\n\t\t\t\tif (this.executeCReject)\r\n\t\t\t\t\tthis.executeCReject(d);\r\n\t\t\t\telse\r\n\t\t\t\t\tthrow new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined executeCReject)\");\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"executeCOkay\":\r\n\t\t\t\tif (this.executeCResolve)\r\n\t\t\t\t\tthis.executeCResolve(d);\r\n\t\t\t\telse\r\n\t\t\t\t\tthrow new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined executeCResolve)\");\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tdefault:\r\n\t\t\t\tif (!this.waitingcalls) throw new Error (\"internal error: this.waitingcalls undefined.\")\r\n\t\t\t\tif (!this.waitingcalls.processMessage(msgType, d))\r\n\t\t\t\t\tthrow new Error(\"twrWasmAsyncModule - unknown and unexpected msgType: \"+msgType);\r\n\t\t}\r\n\t}\r\n}\r\n","import { twrSignal } from \"./twrsignal.js\";\nimport { twrTimeImpl } from \"./twrdate.js\";\n// This class is used in the Main JS thread \nexport class twrWaitingCalls {\n callCompleteSignal;\n parameters;\n constructor() {\n this.callCompleteSignal = new twrSignal();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(() => {\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = twrTimeImpl();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [this.callCompleteSignal.sharedArray, this.parameters.buffer];\n }\n processMessage(msgType, data) {\n switch (msgType) {\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\n// This class is used in the worker thread \nexport class twrWaitingCallsProxy {\n callCompleteSignal;\n parameters;\n constructor(params) {\n this.callCompleteSignal = new twrSignal(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\"sleep\", [ms]]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\"time\"]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n//# sourceMappingURL=twrwaitingcalls.js.map","import { twrSignal } from \"./twrsignal.js\";\r\nimport {twrTimeImpl} from \"./twrdate.js\"\r\n\r\n// These classes are used to proxy a call across the worker thread - main thread boundary and wait for the result\r\n\r\nexport type TWaitingCallsProxyParams = [SharedArrayBuffer, SharedArrayBuffer]; // twrSignal, parameters \r\n\r\n// This class is used in the Main JS thread \r\nexport class twrWaitingCalls {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor() {\r\n\t\tthis.callCompleteSignal=new twrSignal();\r\n\t\tthis.parameters=new Uint32Array(new SharedArrayBuffer(4));\r\n\t}\r\n\r\n\tprivate startSleep(ms:number) {\r\n\r\n\t\tsetTimeout(()=>{\r\n\t\t\tthis.callCompleteSignal.signal();\r\n\t\t}, ms);\r\n\t\t\r\n\t}\r\n\r\n\tprivate time() {\r\n\t\tconst ms=twrTimeImpl();\r\n\t\tthis.parameters[0]=ms;\r\n\t\tthis.callCompleteSignal.signal();\r\n\t}\r\n\r\n\tgetProxyParams():TWaitingCallsProxyParams {\r\n\t\treturn [this.callCompleteSignal.sharedArray, this.parameters.buffer as SharedArrayBuffer];\t\r\n\t}\r\n\r\n\tprocessMessage(msgType:string, data:any[]):boolean {\r\n\t\tswitch (msgType) {\r\n\t\t\tcase \"sleep\":\r\n\t\t\t\tconst [ms] = data;\r\n\t\t\t\tthis.startSleep(ms);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"time\":\r\n\t\t\t\tthis.time();\r\n\t\t\t\tbreak;\r\n\t\t\t\r\n\t\t\tdefault:\r\n\t\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\treturn true;\r\n\t}\r\n\r\n}\r\n\r\n// This class is used in the worker thread \r\nexport class twrWaitingCallsProxy {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor(params:TWaitingCallsProxyParams) {\r\n\t\tthis.callCompleteSignal=new twrSignal(params[0]);\r\n\t\tthis.parameters=new Uint32Array(params[1]);\r\n\t}\r\n\r\n\tsleep(ms:number) {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"sleep\", [ms]]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t}\r\n\r\n\ttime() {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"time\"]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t\treturn this.parameters[0];\r\n\t}\r\n\r\n}\r\n","const keycodeCtrlKeys = {\n 'a': 'selectAll',\n 'c': 'copy',\n 's': 'save',\n 'v': 'paste',\n 'x': 'cut',\n 'y': 'redo',\n 'z': 'undo'\n};\n\nconst keycodeShiftedKeys = {\n '/': '?',\n '.': '>',\n ',': '<',\n '\\'': '\\\"',\n ';': ':',\n '[': '{',\n ']': '}',\n '\\\\': '|',\n '`': '~',\n '=': '+',\n '-': '_',\n '1': '!',\n '2': '@',\n '3': '#',\n '4': '$',\n '5': '%',\n '6': '^',\n '7': '&',\n '8': '*',\n '9': '(',\n '0': ')',\n 'a': 'A',\n 'b': 'B',\n 'c': 'C',\n 'd': 'D',\n 'e': 'E',\n 'f': 'F',\n 'g': 'G',\n 'h': 'H',\n 'i': 'I',\n 'j': 'J',\n 'k': 'K',\n 'l': 'L',\n 'm': 'M',\n 'n': 'N',\n 'o': 'O',\n 'p': 'P',\n 'q': 'q',\n 'r': 'R',\n 's': 'S',\n 't': 'T',\n 'u': 'U',\n 'v': 'V',\n 'w': 'W',\n 'x': 'X',\n 'y': 'Y',\n 'z': 'Z'\n};\n\nconst keyCodeUnshiftedKeys = {};\nfor (const x in keycodeShiftedKeys) {\n const shiftedKey = keycodeShiftedKeys[x];\n keyCodeUnshiftedKeys[shiftedKey] = x;\n}\n\nconst keydownKeycodeDictionary = {\n 0: '\\\\',\n\n 8: 'backspace',\n 9: 'tab',\n\n 12: 'num',\n 13: 'enter',\n\n 16: 'shift',\n 17: 'ctrl',\n 18: 'alt', // aka 'option'\n 19: 'pause', // or sometimes 'break'?\n 20: 'caps',\n\n 27: 'esc',\n\n 32: ' ',\n 33: 'pageup',\n 34: 'pagedown',\n 35: 'end',\n 36: 'home',\n 37: 'left',\n 38: 'up',\n 39: 'right',\n 40: 'down',\n\n 44: 'print',\n 45: 'insert',\n 46: 'delete',\n\n 48: '0',\n 49: '1',\n 50: '2',\n 51: '3',\n 52: '4',\n 53: '5',\n 54: '6',\n 55: '7',\n 56: '8',\n 57: '9',\n\n 59: ';',\n\n 61: '=',\n\n 65: 'a',\n 66: 'b',\n 67: 'c',\n 68: 'd',\n 69: 'e',\n 70: 'f',\n 71: 'g',\n 72: 'h',\n 73: 'i',\n 74: 'j',\n 75: 'k',\n 76: 'l',\n 77: 'm',\n 78: 'n',\n 79: 'o',\n 80: 'p',\n 81: 'q',\n 82: 'r',\n 83: 's',\n 84: 't',\n 85: 'u',\n 86: 'v',\n 87: 'w',\n 88: 'x',\n 89: 'y',\n 90: 'z',\n 91: 'meta', // 'left window key'\n 92: 'meta', // 'right window key'\n 93: 'meta', // 'select key'\n\n 96: 'num0',\n 97: 'num1',\n 98: 'num2',\n 99: 'num3',\n 100: 'num4',\n 101: 'num5',\n 102: 'num6',\n 103: 'num7',\n 104: 'num8',\n 105: 'num9',\n 106: '*',\n 107: '+',\n 108: 'num_enter',\n 109: 'num_subtract',\n 110: 'num_decimal',\n 111: 'num_divide',\n 112: 'f1',\n 113: 'f2',\n 114: 'f3',\n 115: 'f4',\n 116: 'f5',\n 117: 'f6',\n 118: 'f7',\n 119: 'f8',\n 120: 'f9',\n 121: 'f10',\n 122: 'f11',\n 123: 'f12',\n 124: 'print',\n\n 144: 'num', // num lock\n 145: 'scroll', // scroll lock\n\n 173: '-',\n\n 186: ';',\n 187: '=',\n 188: ',',\n 189: '-',\n 190: '.',\n 191: '/',\n 192: '`',\n 219: '[',\n 220: '\\\\',\n 221: ']',\n 222: '\\'',\n 223: '`',\n 224: 'cmd',\n 225: 'alt',\n\n 57392: 'ctrl',\n 63289: 'num'\n};\n\nconst keypressCharacterMapOverides = {\n '\\r': 'enter'\n};\nconst keypressCharacterMap = JSON.parse(JSON.stringify(keydownKeycodeDictionary));\nfor (const key of Object.keys(keypressCharacterMapOverides)) {\n keypressCharacterMap[key] = keypressCharacterMapOverides[key];\n}\n\nconst keydownCharacterMap = {\n 'num_subtract': '-',\n 'num_enter': '\\n',\n 'num_decimal': '.',\n 'num_divide': '/',\n 'enter': '\\n',\n 'tab': '\\t',\n 'backspace': '\\b'\n};\n\nexport const unprintableKeys = [\n 'backspace','enter','tab','num',\n 'shift','meta','alt','pause','caps','esc',\n 'pageup','pagedown','end','home',\n 'left','up','right','down',\n 'print','insert','delete','cmd',\n 'f1','f2','f3','f4','f5','f6','f7','f8','f9','f10','f11','f12',\n 'scroll','ctrl'\n];\n\nconst validEvents = ['keydown', 'keyup'];\n\nconst isMobile = () => {\n const ua = navigator.userAgent;\n const mobile = /IEMobile|Windows Phone|Lumia/i.test(ua) ? 'w' : /iPhone|iP[oa]d/.test(ua) ? 'i' : /Android/.test(ua) ? 'a' : /BlackBerry|PlayBook|BB10/.test(ua) ? 'b' : /Mobile Safari/.test(ua) ? 's' : /webOS|Mobile|Tablet|Opera Mini|\\bCrMo\\/|Opera Mobi/i.test(ua) ? 1 : 0;\n return mobile !== 0;\n};\n\nfunction getKeypressKeycodeValue(charcode) {\n const character = String.fromCharCode(charcode);\n if (isMobile()) { return character }\n if (character in keyCodeUnshiftedKeys) {\n return keyCodeUnshiftedKeys[character];\n } else if (character in keypressCharacterMap) {\n return keypressCharacterMap[character];\n }\n return character;\n}\n\nexport default function(event) {\n let key;\n if (event.type === 'keypress' && !isMobile()) {\n key = getKeypressKeycodeValue(event.charCode);\n } else if (event.type === 'keypress' && isMobile()) {\n key = getKeypressKeycodeValue(event.keyCode);\n } else if (validEvents.indexOf(event.type) > -1) {\n if (event.which !== undefined) {\n key = keydownKeycodeDictionary[event.which];\n } else if (event.keyCode !== undefined) {\n key = keydownKeycodeDictionary[event.keyCode];\n } else {\n key = 'enter';\n }\n } else {\n return false;\n }\n\n let char = key;\n if (event.shiftKey && key in keycodeShiftedKeys) {\n char = keycodeShiftedKeys[key];\n } else if (event.ctrlKey && key in keycodeCtrlKeys) {\n char = keycodeCtrlKeys[key];\n } else if (key in keydownCharacterMap) {\n char = keydownCharacterMap[key];\n }\n\n return {\n char,\n key\n };\n}\n","let workerURL = require('./helpers/get-worker-url');\nlet url = new __parcel__URL__(\"twrmodworker.2165e649.js\");\nmodule.exports = workerURL(url.toString(), url.origin, true);","\"use strict\";\n\nmodule.exports = function (workerUrl, origin, isESM) {\n if (origin === self.location.origin) {\n // If the worker bundle's url is on the same origin as the document,\n // use the worker bundle's own url.\n return workerUrl;\n } else {\n // Otherwise, create a blob URL which loads the worker bundle with `importScripts`.\n var source = isESM ? 'import ' + JSON.stringify(workerUrl) + ';' : 'importScripts(' + JSON.stringify(workerUrl) + ');';\n return URL.createObjectURL(new Blob([source], {\n type: 'application/javascript'\n }));\n }\n};","require('./helpers/bundle-manifest').register(new __parcel__URL__(\"\").toString(),JSON.parse(\"[\\\"kjr0c\\\",\\\"index.528b9ee5.js\\\",\\\"cTHdP\\\",\\\"twrmodworker.2165e649.js\\\"]\"));"],"names":["$parcel$export","e","n","v","s","Object","defineProperty","get","set","enumerable","configurable","$parcel$global","globalThis","$parcel$modules","$parcel$inits","parcelRequire","id","exports","init","module","call","err","Error","code","register","parcelRegister","$ae99f86db55f9acd$export$6503ec6e8aabbaf","$ae99f86db55f9acd$var$mapping","Map","baseUrl","manifest","i","length","path","twrWasmModule","twrWasmModuleAsync","$251237c7cf144eb4$export$3298af74d75b595c","$9FI45","$aGUWE","$lsUl2","twrWasmModuleInJSMain","malloc","constructor","opts","canvas","size","d2dcanvas","isValid","iocanvas","modParams","imports","twrDebugLog","twrDebugLogImpl","twrTime","twrTimeImpl","twrDivCharOut","iodiv","charOut","bind","twrCanvasGetProp","getProp","twrCanvasDrawSeq","drawSeq","twrCanvasCharIn","null","twrCanvasInkey","twrDivCharIn","twrSleep","twrSin","Math","sin","twrCos","cos","twrTan","tan","twrFAbs","abs","twrACos","acos","twrASin","asin","twrATan","atan","twrExp","exp","twrFloor","floor","twrCeil","ceil","twrFMod","x","y","twrLog","log","twrPow","pow","twrSqrt","sqrt","twrTrunc","trunc","twrDtoa","floatUtil","dtoa","twrToFixed","toFixed","twrToExponential","toExponential","twrAtod","atod","twrFcvtS","fcvtS","inval","$70aa1fbe63deeaae$export$16b4216ec014493d","$70aa1fbe63deeaae$var$logline","char","console","String","fromCharCode","$7c89ffbd74fdad5b$export$2366c14363f3adb5","$fDEU7","$5hO33","$5LsZ0","twrWasmModuleBase","isWasmModule","document","eiodiv","getElementById","eiocanvas","ed2dcanvas","stdio","isd2dcanvas","windim","styleIsDefault","backcolor","forecolor","fontsize","undefined","twrDiv","twrCanvas","divLog","params","stringOut","toString","$b62a3a4493ce3043$export$dd376bb3f10f6896","$ghrAp","div","divKeys","CURSOR","cursorOn","lastChar","extraBR","owner","element","modbase","twrSharedCircularBuffer","style","backgroundColor","color","font","getProxyParams","sharedArray","ch","innerHTML","slice","p","getBoundingClientRect","window","scrollTo","height","focus","str","charCodeAt","$bda3a1eb26e567b5$export$a01cca24f011573a","buf","sa","crossOriginIsolated","location","protocol","SharedArrayBuffer","Int32Array","write","Atomics","notify","read","isEmpty","readWait","rdptr","wait","$3d955ccf8fb141b7$export$c83a0a3bffe07399","$2Xdsi","memory","mem8","mem32","memD","isWorker","Uint8Array","Uint32Array","Float64Array","twrFloatUtil","loadWasm","pathToLoad","response","fetch","ok","statusText","wasmBytes","arrayBuffer","allimports","instance","WebAssembly","instantiate","env","buffer","ArrayBuffer","postMessage","Promise","resolve","m","twr_malloc","stack","twrInit","twr_wasm_init","executeC","cparams","preCallC","retval","executeCImpl","postCallC","fname","f","Array","ci","putString","URL","r","fetchAndPutURL","putArrayBuffer","u8","j","copyString","buffer_size","strIndex","putU8","u8a","dest","ab","fnin","src","getLong","idx","idx32","setLong","value","getDouble","idx64","setDouble","getShort","getString","len","sout","getU8Arr","rv","dataptr","getU32Arr","$226b87658a7c840f$export$918ffb7e046a537b","mod","strptr","upper","trimStart","toUpperCase","Number","POSITIVE_INFINITY","NEGATIVE_INFINITY","parseFloat","replaceAll","max_precision","toPrecision","decdigits","sizeInBytes","fracpart_numdigits","dec","sign","digits","decpos","isNaN","isFinite","intPart","fracPart","roundValStr","split","replace","$4327d2f23f608609$export$2f298dd69cef3c34","D2DType","$4327d2f23f608609$var$D2DType","$47Wdp","ctx","props","charWidth","charHeight","foreColor","backColor","widthInChars","heightInChars","canvasHeight","canvasWidth","cmdCompleteSignal","canvasKeys","precomputedObjects","twrSignal","getContext","c","textBaseline","sampleText","tm","measureText","width","fM","fontBoundingBoxAscent","fontBoundingBoxDescent","c2","fillStyle","pn","propName","ds","next","ins","lastins","type","D2D_FILLRECT","w","h","fillRect","D2D_STROKERECT","strokeRect","D2D_FILLCHAR","txt","fillText","D2D_FILLTEXT","D2D_MEASURETEXT","tmidx","actualBoundingBoxAscent","actualBoundingBoxDescent","actualBoundingBoxLeft","actualBoundingBoxRight","D2D_SETFONT","D2D_SETFILLSTYLERGBA","cssColor","D2D_SETSTROKESTYLERGBA","strokeStyle","D2D_SETFILLSTYLE","D2D_SETSTROKESTYLE","D2D_SETLINEWIDTH","lineWidth","D2D_MOVETO","moveTo","D2D_LINETO","lineTo","D2D_BEZIERTO","cp1x","cp1y","cp2x","cp2y","bezierCurveTo","D2D_BEGINPATH","beginPath","D2D_FILL","fill","D2D_SAVE","save","D2D_RESTORE","restore","D2D_STROKE","stroke","D2D_ARC","radius","startAngle","endAngle","counterClockwise","arc","D2D_IMAGEDATA","start","z","Uint8ClampedArray","ImageData","D2D_CREATERADIALGRADIENT","x0","y0","radius0","x1","y1","radius1","gradient","createRadialGradient","D2D_CREATELINEARGRADIENT","createLinearGradient","D2D_SETCOLORSTOP","pos","addColorStop","D2D_SETFILLSTYLEGRADIENT","D2D_RELEASEID","D2D_PUTIMAGEDATA","imgData","dx","dy","dirtyX","dirtyY","dirtyWidth","dirtyHeight","from","putImageData","signal","$3014f93b5ceae902$var$twrSignalState","twrSignalState","$3014f93b5ceae902$export$e37a7b7b851b97f3","WAITING","SIGNALED","isSignaled","reset","$fa07ea1a08a5d6be$export$78724cdcf7ebea1d","Date","now","$8227a48f951b1cca$export$678fe6e36ab9a6ff","$2vKdq","$bqeaG","myWorker","loadWasmResolve","loadWasmReject","executeCResolve","executeCReject","initLW","waitingcalls","Worker","onmessage","processMsg","reject","twrWaitingCalls","modWorkerParams","divProxyParams","canvasProxyParams","waitingCallsProxyParams","startMsg","urlToLoad","href","keyDownDiv","ev","default","keyDownCanvas","event","msgType","data","d","processMessage","$1d42537681d02be3$export$9e37856d1928d388","callCompleteSignal","parameters","startSleep","ms","setTimeout","time","$850d1d8f0aa1ea8f$export$2e2bcd8739ae039","$850d1d8f0aa1ea8f$var$keycodeCtrlKeys","$850d1d8f0aa1ea8f$var$keycodeShiftedKeys","$850d1d8f0aa1ea8f$var$keyCodeUnshiftedKeys","$850d1d8f0aa1ea8f$var$keydownKeycodeDictionary","$850d1d8f0aa1ea8f$var$keypressCharacterMapOverides","$850d1d8f0aa1ea8f$var$keypressCharacterMap","JSON","parse","stringify","key","keys","$850d1d8f0aa1ea8f$var$keydownCharacterMap","$850d1d8f0aa1ea8f$var$validEvents","$850d1d8f0aa1ea8f$var$isMobile","ua","navigator","userAgent","mobile","test","$850d1d8f0aa1ea8f$var$getKeypressKeycodeValue","charcode","character","keyCode","indexOf","which","charCode","shiftKey","ctrlKey","$hoqmg","$7e9081fcee88b005$var$url","url","origin","workerUrl","isESM","self","source","createObjectURL","Blob"],"version":3,"file":"index.528b9ee5.js.map"} \ No newline at end of file +{"mappings":"A,S,E,C,C,C,C,C,C,C,E,O,c,C,E,E,C,I,E,I,E,W,C,E,a,C,C,E,C,I,E,W,E,C,E,E,C,E,E,E,iB,A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,CAAE,CAAM,CAAE,CAAK,EACjD,GAAI,IAAW,KAAK,QAAQ,CAAC,MAAM,CAGjC,OAAO,EAGP,IAAI,EAAS,EAAQ,UAAY,KAAK,SAAS,CAAC,GAAa,IAAM,iBAAmB,KAAK,SAAS,CAAC,GAAa,KAClH,OAAO,IAAI,eAAe,CAAC,IAAI,KAAK,CAAC,EAAO,CAAE,CAC5C,KAAM,wBACR,GAEJ,C,GCdA,AAAA,EAAA,SAAA,QAAA,CAA8C,IAAA,IAAoB,GAAA,YAAA,GAAA,EAAI,QAAQ,GAAG,KAAK,KAAK,CAAC","sources":["","../../../../Users/awood/AppData/Roaming/npm/node_modules/parcel/node_modules/@parcel/runtime-js/lib/helpers/bundle-manifest.js","../../source/twr-wasm-ts/index.ts","../../lib-js/twrmod.js","../../source/twr-wasm-ts/twrmod.ts","../../lib-js/twrdebug.js","../../source/twr-wasm-ts/twrdebug.ts","../../lib-js/twrmodjsmain.js","../../source/twr-wasm-ts/twrmodjsmain.ts","../../lib-js/twrdiv.js","../../source/twr-wasm-ts/twrdiv.ts","../../lib-js/twrcircular.js","../../source/twr-wasm-ts/twrcircular.ts","../../lib-js/twrmodbase.js","../../source/twr-wasm-ts/twrmodbase.ts","../../lib-js/twrfloat.js","../../source/twr-wasm-ts/twrfloat.ts","../../lib-js/twrcanvas.js","../../source/twr-wasm-ts/twrcanvas.ts","../../lib-js/twrsignal.js","../../source/twr-wasm-ts/twrsignal.ts","../../lib-js/twrdate.js","../../source/twr-wasm-ts/twrdate.ts","../../lib-js/twrmodasync.js","../../source/twr-wasm-ts/twrmodasync.ts","../../lib-js/twrwaitingcalls.js","../../source/twr-wasm-ts/twrwaitingcalls.ts","../../lib-js/whatkey.js","../../../../Users/awood/AppData/Roaming/npm/node_modules/parcel/node_modules/@parcel/runtime-js/lib/runtime-f762b97648513f2d.js","../../../../Users/awood/AppData/Roaming/npm/node_modules/parcel/node_modules/@parcel/runtime-js/lib/helpers/get-worker-url.js","../../../../Users/awood/AppData/Roaming/npm/node_modules/parcel/node_modules/@parcel/runtime-js/lib/runtime-8b48cd52cfa83e88.js"],"sourcesContent":["\nfunction $parcel$export(e, n, v, s) {\n Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});\n}\n\n var $parcel$global = globalThis;\n \nvar $parcel$modules = {};\nvar $parcel$inits = {};\n\nvar parcelRequire = $parcel$global[\"parcelRequire94c2\"];\n\nif (parcelRequire == null) {\n parcelRequire = function(id) {\n if (id in $parcel$modules) {\n return $parcel$modules[id].exports;\n }\n if (id in $parcel$inits) {\n var init = $parcel$inits[id];\n delete $parcel$inits[id];\n var module = {id: id, exports: {}};\n $parcel$modules[id] = module;\n init.call(module.exports, module, module.exports);\n return module.exports;\n }\n var err = new Error(\"Cannot find module '\" + id + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n };\n\n parcelRequire.register = function register(id, init) {\n $parcel$inits[id] = init;\n };\n\n $parcel$global[\"parcelRequire94c2\"] = parcelRequire;\n}\n\nvar parcelRegister = parcelRequire.register;\nparcelRegister(\"eZoLj\", function(module, exports) {\n\n$parcel$export(module.exports, \"register\", () => $ae99f86db55f9acd$export$6503ec6e8aabbaf, (v) => $ae99f86db55f9acd$export$6503ec6e8aabbaf = v);\nvar $ae99f86db55f9acd$export$6503ec6e8aabbaf;\nvar $ae99f86db55f9acd$export$f7ad0328861e2f03;\n\"use strict\";\nvar $ae99f86db55f9acd$var$mapping = new Map();\nfunction $ae99f86db55f9acd$var$register(baseUrl, manifest) {\n for(var i = 0; i < manifest.length - 1; i += 2)$ae99f86db55f9acd$var$mapping.set(manifest[i], {\n baseUrl: baseUrl,\n path: manifest[i + 1]\n });\n}\nfunction $ae99f86db55f9acd$var$resolve(id) {\n var resolved = $ae99f86db55f9acd$var$mapping.get(id);\n if (resolved == null) throw new Error(\"Could not resolve bundle with id \" + id);\n return new URL(resolved.path, resolved.baseUrl).toString();\n}\n$ae99f86db55f9acd$export$6503ec6e8aabbaf = $ae99f86db55f9acd$var$register;\n$ae99f86db55f9acd$export$f7ad0328861e2f03 = $ae99f86db55f9acd$var$resolve;\n\n});\n\nparcelRegister(\"4mNsm\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrWasmModule\", () => (parcelRequire(\"3bkoq\")).twrWasmModule);\n$parcel$export(module.exports, \"twrWasmModuleAsync\", () => (parcelRequire(\"baOio\")).twrWasmModuleAsync);\n\nvar $3bkoq = parcelRequire(\"3bkoq\");\n\nvar $baOio = parcelRequire(\"baOio\");\n\n});\nparcelRegister(\"3bkoq\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrWasmModule\", () => $251237c7cf144eb4$export$3298af74d75b595c);\n\nvar $9FI45 = parcelRequire(\"9FI45\");\n\nvar $aGUWE = parcelRequire(\"aGUWE\");\n\nvar $lsUl2 = parcelRequire(\"lsUl2\");\nclass $251237c7cf144eb4$export$3298af74d75b595c extends (0, $aGUWE.twrWasmModuleInJSMain) {\n malloc;\n constructor(opts = {}){\n super(opts, true);\n this.malloc = (size)=>{\n throw new Error(\"error - un-init malloc called\");\n };\n let canvas;\n if (this.d2dcanvas.isValid()) canvas = this.d2dcanvas;\n else canvas = this.iocanvas;\n this.modParams.imports = {\n twrDebugLog: (0, $9FI45.twrDebugLogImpl),\n twrTime: (0, $lsUl2.twrTimeImpl),\n twrDivCharOut: this.iodiv.charOut.bind(this.iodiv),\n twrCanvasGetProp: canvas.getProp.bind(canvas),\n twrCanvasDrawSeq: canvas.drawSeq.bind(canvas),\n twrCanvasCharIn: this.null,\n twrCanvasInkey: this.null,\n twrDivCharIn: this.null,\n twrSleep: this.null,\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function(x, y) {\n return x % y;\n },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n null(inval) {\n throw new Error(\"call to unimplemented twrXXX import in twrWasmModule. Use twrWasmModuleAsync ?\");\n }\n}\n\n});\nparcelRegister(\"9FI45\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrDebugLogImpl\", () => $70aa1fbe63deeaae$export$16b4216ec014493d);\nlet $70aa1fbe63deeaae$var$logline = \"\";\nfunction $70aa1fbe63deeaae$export$16b4216ec014493d(char) {\n if (char == 10 || char == 3) {\n console.log($70aa1fbe63deeaae$var$logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n $70aa1fbe63deeaae$var$logline = \"\";\n } else {\n $70aa1fbe63deeaae$var$logline = $70aa1fbe63deeaae$var$logline + String.fromCharCode(char);\n if ($70aa1fbe63deeaae$var$logline.length >= 200) {\n console.log($70aa1fbe63deeaae$var$logline);\n $70aa1fbe63deeaae$var$logline = \"\";\n }\n }\n}\nfunction $70aa1fbe63deeaae$export$485af4d0039b3389(ch) {\n postMessage([\n \"debug\",\n ch\n ]);\n}\n\n});\n\nparcelRegister(\"aGUWE\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrWasmModuleInJSMain\", () => $7c89ffbd74fdad5b$export$2366c14363f3adb5);\n// This class extends base to handle options when called in the main Java Script thread\n\nvar $fDEU7 = parcelRequire(\"fDEU7\");\n\nvar $5hO33 = parcelRequire(\"5hO33\");\n\nvar $5LsZ0 = parcelRequire(\"5LsZ0\");\nclass $7c89ffbd74fdad5b$export$2366c14363f3adb5 extends (0, $5hO33.twrWasmModuleBase) {\n iocanvas;\n d2dcanvas;\n iodiv;\n modParams;\n constructor(opts = {}, isWasmModule = false){\n super(isWasmModule);\n if (typeof document === \"undefined\") throw new Error(\"twrWasmModuleJSMain should only be created in JavaScript Main.\");\n const eiodiv = document.getElementById(\"twr_iodiv\");\n const eiocanvas = document.getElementById(\"twr_iocanvas\");\n const ed2dcanvas = document.getElementById(\"twr_d2dcanvas\");\n if (eiocanvas && ed2dcanvas) throw new Error(\"Both twr_iocanvas and twr_d2dcanvas defined. Currently only one canvas allowed.\");\n if (opts.stdio == \"div\" && !eiodiv) throw new Error(\"twrWasmModuleBase opts=='div' but twr_iodiv not defined\");\n if (opts.stdio == \"canvas\" && !eiocanvas) throw new Error(\"twrWasmModuleBase, opts=='canvas' but twr_iocanvas not defined\");\n if (opts.isd2dcanvas && !ed2dcanvas) throw new Error(\"twrWasmModuleBase, opts.isdrawcanvas==true but twr_d2dcanvas not defined\");\n // set default opts based on elements found\n if (eiodiv) opts = {\n stdio: \"div\",\n ...opts\n };\n else if (eiocanvas) opts = {\n stdio: \"canvas\",\n ...opts\n };\n else opts = {\n stdio: \"debug\",\n ...opts\n };\n if (!eiodiv && !eiocanvas) console.log(\"Since neither twr_iocanvas nor twr_iodiv is defined, stdout directed to debug console.\");\n else console.log(\"tiny-wasm-runtime: stdio set to: \", opts.stdio);\n if (eiocanvas) opts = {\n windim: [\n 64,\n 16\n ],\n ...opts\n };\n else opts = {\n windim: [\n 0,\n 0\n ],\n ...opts\n };\n if (!opts.imports) opts.imports = {};\n let styleIsDefault = false;\n if (!opts.backcolor) {\n styleIsDefault = true;\n opts.backcolor = \"black\";\n }\n if (!opts.forecolor) {\n styleIsDefault = true;\n opts.forecolor = \"white\";\n }\n if (!opts.fontsize) {\n styleIsDefault = true;\n opts.fontsize = 16;\n }\n if (opts.isd2dcanvas === undefined) {\n if (ed2dcanvas) opts.isd2dcanvas = true;\n else opts.isd2dcanvas = false;\n }\n this.modParams = {\n stdio: opts.stdio,\n windim: opts.windim,\n imports: opts.imports,\n forecolor: opts.forecolor,\n backcolor: opts.backcolor,\n styleIsDefault: styleIsDefault,\n fontsize: opts.fontsize,\n isd2dcanvas: opts.isd2dcanvas\n };\n this.iodiv = new (0, $fDEU7.twrDiv)(eiodiv, this.modParams, this);\n this.iocanvas = new (0, $5LsZ0.twrCanvas)(eiocanvas, this.modParams, this);\n this.d2dcanvas = new (0, $5LsZ0.twrCanvas)(ed2dcanvas, this.modParams, this);\n }\n divLog(...params) {\n for(var i = 0; i < params.length; i++){\n this.iodiv.stringOut(params[i].toString());\n this.iodiv.charOut(32); // space\n }\n this.iodiv.charOut(10);\n }\n}\n\n});\nparcelRegister(\"fDEU7\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrDiv\", () => $b62a3a4493ce3043$export$dd376bb3f10f6896);\n\nvar $ghrAp = parcelRequire(\"ghrAp\");\nclass $b62a3a4493ce3043$export$dd376bb3f10f6896 {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611);\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase){\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) this.divKeys = new (0, $ghrAp.twrSharedCircularBuffer)(); // tsconfig, lib must be set to 2017 or higher\n if (this.div && !modParams.styleIsDefault) {\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.divKeys.sharedArray\n ];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */ charOut(ch) {\n if (!this.div) return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n }\n switch(ch){\n case 10:\n case 13:\n if (ch == 10 && this.lastChar == 13) break; // detect CR LF and treat as single new line\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n case 0xE:\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF:\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for(let i = 0; i < str.length; i++)this.charOut(str.charCodeAt(i));\n }\n}\nclass $b62a3a4493ce3043$export$b377f0bbf2c7581e {\n divKeys;\n constructor(params){\n const [divKeysBuffer] = params;\n this.divKeys = new (0, $ghrAp.twrSharedCircularBuffer)(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n charOut(ch) {\n postMessage([\n \"divout\",\n ch\n ]);\n }\n}\n\n});\nparcelRegister(\"ghrAp\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrSharedCircularBuffer\", () => $bda3a1eb26e567b5$export$a01cca24f011573a);\n//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst $bda3a1eb26e567b5$var$RDIDX = 256;\nconst $bda3a1eb26e567b5$var$WRIDX = 257;\nconst $bda3a1eb26e567b5$var$LEN = 256;\nclass $bda3a1eb26e567b5$export$a01cca24f011573a {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(1032);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[$bda3a1eb26e567b5$var$RDIDX] = 0;\n this.buf[$bda3a1eb26e567b5$var$WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[$bda3a1eb26e567b5$var$WRIDX];\n this.buf[i] = n;\n i++;\n if (i == $bda3a1eb26e567b5$var$LEN) i = 0;\n this.buf[$bda3a1eb26e567b5$var$WRIDX] = i;\n Atomics.notify(this.buf, $bda3a1eb26e567b5$var$WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[$bda3a1eb26e567b5$var$RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[$bda3a1eb26e567b5$var$RDIDX] = i;\n return n;\n } else return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[$bda3a1eb26e567b5$var$RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, $bda3a1eb26e567b5$var$WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[$bda3a1eb26e567b5$var$RDIDX] == this.buf[$bda3a1eb26e567b5$var$WRIDX];\n }\n}\n\n});\n\n\nparcelRegister(\"5hO33\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrWasmModuleBase\", () => $3d955ccf8fb141b7$export$c83a0a3bffe07399);\n\nvar $2Xdsi = parcelRequire(\"2Xdsi\");\nclass $3d955ccf8fb141b7$export$c83a0a3bffe07399 {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule;\n floatUtil;\n constructor(isWasmModule = false){\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new (0, $2Xdsi.twrFloatUtil)(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/ /*********************************************************************/ async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n } catch (err) {\n console.log(\"loadWasm() failed to fetch: \" + pathToLoad);\n throw err;\n }\n if (!response.ok) throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, {\n env: allimports\n });\n this.exports = instance.instance.exports;\n if (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory) throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer) console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\n \"setmemory\",\n this.memory\n ]);\n }\n if (this.isWasmModule) // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n {\n if (!(this.memory.buffer instanceof ArrayBuffer)) console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size)=>{\n return new Promise((resolve)=>{\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n } catch (err) {\n console.log(\"WASM instantiate error: \" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch(this.modParams.stdio){\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* callC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */ async callC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.callCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async callCImpl(fname, cparams = []) {\n if (!this.exports) throw new Error(\"this.exports undefined\");\n if (!this.exports[fname]) throw new Error(\"callC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array)) throw new Error(\"callC: params must be array, first arg is function name\");\n if (params.length == 0) throw new Error(\"callC: missing function name\");\n let cparams = [];\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n cparams[ci++] = p;\n break;\n case \"string\":\n cparams[ci++] = await this.putString(p);\n break;\n case \"object\":\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n } else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"callC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n ci++;\n break;\n case \"string\":\n this.callCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n case \"object\":\n if (p instanceof URL) {\n this.callCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci = ci + 2;\n break;\n } else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for(let j = 0; j < u8.length; j++)u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.callCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n } else throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/ /*********************************************************************/ // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for(i = 0; i < sin.length && i < buffer_size - 1; i++)this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for(let i = 0; i < u8a.length; i++)this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === \"object\" && fnin instanceof URL)) throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [\n dest,\n src.length\n ];\n } catch (err) {\n console.log(\"fetchAndPutURL Error. URL: \" + fnin + \"\\n\" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while(this.mem8[strIndex + i] && (len === undefined ? true : i < len) && strIndex + i < this.mem8.length){\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array(this.mem8.slice(dataptr, dataptr + size).buffer);\n return u32;\n }\n}\n\n});\nparcelRegister(\"2Xdsi\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrFloatUtil\", () => $226b87658a7c840f$export$918ffb7e046a537b);\nclass $226b87658a7c840f$export$918ffb7e046a537b {\n mod;\n constructor(mod){\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\") return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\") return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll(\"D\", \"e\").replaceAll(\"d\", \"e\"));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n } else {\n let r = value.toString();\n if (r.length > max_precision) r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, sizeInBytes, value, fracpart_numdigits, dec, sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1) return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) {\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (!Number.isFinite(value)) {\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n } else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split(\".\");\n if (intPart == \"0\") intPart = \"\";\n if (intPart.length > 0) {\n decpos = intPart.length;\n digits = intPart + fracPart;\n } else {\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length) return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */ }\n}\n\n});\n\n\nparcelRegister(\"5LsZ0\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrCanvas\", () => $4327d2f23f608609$export$2f298dd69cef3c34);\n\nvar $ghrAp = parcelRequire(\"ghrAp\");\n\nvar $47Wdp = parcelRequire(\"47Wdp\");\nvar $4327d2f23f608609$var$D2DType;\n(function(D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})($4327d2f23f608609$var$D2DType || ($4327d2f23f608609$var$D2DType = {}));\nclass $4327d2f23f608609$export$2f298dd69cef3c34 {\n ctx;\n props = {\n charWidth: 0,\n charHeight: 0,\n foreColor: 0,\n backColor: 0,\n widthInChars: 0,\n heightInChars: 0,\n canvasHeight: 0,\n canvasWidth: 0\n };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase){\n const { forecolor: forecolor, backcolor: backcolor, fontsize: fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new (0, $47Wdp.twrSignal)();\n this.canvasKeys = new (0, $ghrAp.twrSharedCircularBuffer)(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.props,\n this.cmdCompleteSignal.sharedArray,\n this.canvasKeys.sharedArray\n ];\n }\n getProp(pn) {\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */ drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx) return;\n let ins = this.owner.getLong(ds); /* ds->start */ \n const lastins = this.owner.getLong(ds + 4); /* ds->last */ \n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while(true){\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */ \n switch(type){\n case $4327d2f23f608609$var$D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_BEGINPATH:\n this.ctx.beginPath();\n break;\n case $4327d2f23f608609$var$D2DType.D2D_FILL:\n this.ctx.fill();\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SAVE:\n this.ctx.save();\n break;\n case $4327d2f23f608609$var$D2DType.D2D_RESTORE:\n this.ctx.restore();\n break;\n case $4327d2f23f608609$var$D2DType.D2D_STROKE:\n this.ctx.stroke();\n break;\n case $4327d2f23f608609$var$D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = this.owner.getLong(ins + 48) != 0;\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n } else this.precomputedObjects[id] = {\n mem8: new Uint8Array(this.owner.memory.buffer, start, length),\n width: width,\n height: height\n };\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id]) delete this.precomputedObjects[id];\n else console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case $4327d2f23f608609$var$D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n else {\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) this.ctx.putImageData(imgData, dx, dy);\n else this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */ \n if (next == 0) {\n if (ins != lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nclass $4327d2f23f608609$export$c779b2cd00544976 {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner){\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new (0, $47Wdp.twrSignal)(signalBuffer);\n this.canvasKeys = new (0, $ghrAp.twrSharedCircularBuffer)(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\n \"drawseq\",\n [\n ds\n ]\n ]);\n this.drawCompleteSignal.wait();\n }\n}\n\n});\nparcelRegister(\"47Wdp\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrSignal\", () => $3014f93b5ceae902$export$e37a7b7b851b97f3);\n//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar $3014f93b5ceae902$var$twrSignalState;\n(function(twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})($3014f93b5ceae902$var$twrSignalState || ($3014f93b5ceae902$var$twrSignalState = {}));\nclass $3014f93b5ceae902$export$e37a7b7b851b97f3 {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = $3014f93b5ceae902$var$twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = $3014f93b5ceae902$var$twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == $3014f93b5ceae902$var$twrSignalState.WAITING) //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, $3014f93b5ceae902$var$twrSignalState.WAITING);\n }\n isSignaled() {\n return this.buf[0] == $3014f93b5ceae902$var$twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = $3014f93b5ceae902$var$twrSignalState.WAITING;\n }\n}\n\n});\n\n\n\nparcelRegister(\"lsUl2\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrTimeImpl\", () => $fa07ea1a08a5d6be$export$78724cdcf7ebea1d);\nfunction $fa07ea1a08a5d6be$export$78724cdcf7ebea1d() {\n return Date.now();\n}\n\n});\n\n\nparcelRegister(\"baOio\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrWasmModuleAsync\", () => $8227a48f951b1cca$export$678fe6e36ab9a6ff);\n\nvar $9FI45 = parcelRequire(\"9FI45\");\n\nvar $aGUWE = parcelRequire(\"aGUWE\");\n\nvar $2vKdq = parcelRequire(\"2vKdq\");\n\nvar $bqeaG = parcelRequire(\"bqeaG\");\n\nclass $8227a48f951b1cca$export$678fe6e36ab9a6ff extends (0, $aGUWE.twrWasmModuleInJSMain) {\n myWorker;\n malloc;\n loadWasmResolve;\n loadWasmReject;\n callCResolve;\n callCReject;\n initLW = false;\n waitingcalls;\n constructor(opts){\n super(opts);\n this.malloc = (size)=>{\n throw new Error(\"Error - un-init malloc called.\");\n };\n if (!window.Worker) throw new Error(\"This browser doesn't support web workers.\");\n this.myWorker = new Worker((parcelRequire(\"aRHnW\")));\n this.myWorker.onmessage = this.processMsg.bind(this);\n }\n // overrides base implementation\n async loadWasm(pathToLoad) {\n if (this.initLW) throw new Error(\"twrWasmAsyncModule::loadWasm can only be called once per twrWasmAsyncModule instance\");\n this.initLW = true;\n return new Promise((resolve, reject)=>{\n this.loadWasmResolve = resolve;\n this.loadWasmReject = reject;\n this.malloc = (size)=>{\n return this.callCImpl(\"twr_malloc\", [\n size\n ]);\n };\n this.waitingcalls = new (0, $2vKdq.twrWaitingCalls)(); // handle's calls that cross the worker thread - main js thread boundary\n let canvas;\n if (this.d2dcanvas.isValid()) canvas = this.d2dcanvas;\n else canvas = this.iocanvas;\n const modWorkerParams = {\n divProxyParams: this.iodiv.getProxyParams(),\n canvasProxyParams: canvas.getProxyParams(),\n waitingCallsProxyParams: this.waitingcalls.getProxyParams()\n };\n const urlToLoad = new URL(pathToLoad, document.URL);\n const startMsg = {\n urlToLoad: urlToLoad.href,\n modWorkerParams: modWorkerParams,\n modParams: this.modParams\n };\n this.myWorker.postMessage([\n \"startup\",\n startMsg\n ]);\n });\n }\n async callC(params) {\n const cparams = await this.preCallC(params); // will also validate params[0]\n return this.callCImpl(params[0], cparams);\n }\n async callCImpl(fname, cparams = []) {\n return new Promise((resolve, reject)=>{\n this.callCResolve = resolve;\n this.callCReject = reject;\n this.myWorker.postMessage([\n \"callC\",\n fname,\n cparams\n ]);\n });\n }\n // this function should be called from HTML \"keydown\" event from
\n keyDownDiv(ev) {\n if (!this.iodiv || !this.iodiv.divKeys) throw new Error(\"unexpected undefined twrWasmAsyncModule.divKeys\");\n this.iodiv.divKeys.write((0, $bqeaG.default)(ev).char.charCodeAt(0));\n }\n // this function should be called from HTML \"keydown\" event from \n keyDownCanvas(ev) {\n if (!this.iocanvas || !this.iocanvas.canvasKeys) throw new Error(\"unexpected undefined twrWasmAsyncModule.canvasKeys\");\n this.iocanvas.canvasKeys.write((0, $bqeaG.default)(ev).char.charCodeAt(0));\n }\n processMsg(event) {\n const msgType = event.data[0];\n const d = event.data[1];\n //console.log(\"twrWasmAsyncModule - got message: \"+event.data)\n switch(msgType){\n case \"divout\":\n if (this.iodiv.isValid()) this.iodiv.charOut(d);\n else console.log(\"error - msg divout received but iodiv is undefined.\");\n break;\n case \"debug\":\n (0, $9FI45.twrDebugLogImpl)(d);\n break;\n case \"drawseq\":\n {\n //console.log(\"twrModAsync got message drawseq\");\n const [ds] = d;\n if (this.iocanvas.isValid()) this.iocanvas.drawSeq(ds);\n else if (this.d2dcanvas.isValid()) this.d2dcanvas.drawSeq(ds);\n else throw new Error(\"msg drawseq received but canvas is undefined.\");\n break;\n }\n case \"setmemory\":\n this.memory = d;\n if (!this.memory) throw new Error(\"unexpected error - undefined memory in startupOkay msg\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n break;\n case \"startupFail\":\n if (this.loadWasmReject) this.loadWasmReject(d);\n else throw new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmReject)\");\n break;\n case \"startupOkay\":\n if (this.loadWasmResolve) this.loadWasmResolve(undefined);\n else throw new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmResolve)\");\n break;\n case \"callCFail\":\n if (this.callCReject) this.callCReject(d);\n else throw new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined callCReject)\");\n break;\n case \"callCOkay\":\n if (this.callCResolve) this.callCResolve(d);\n else throw new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined callCResolve)\");\n break;\n default:\n if (!this.waitingcalls) throw new Error(\"internal error: this.waitingcalls undefined.\");\n if (!this.waitingcalls.processMessage(msgType, d)) throw new Error(\"twrWasmAsyncModule - unknown and unexpected msgType: \" + msgType);\n }\n }\n}\n\n});\nparcelRegister(\"2vKdq\", function(module, exports) {\n\n$parcel$export(module.exports, \"twrWaitingCalls\", () => $1d42537681d02be3$export$9e37856d1928d388);\n\nvar $47Wdp = parcelRequire(\"47Wdp\");\n\nvar $lsUl2 = parcelRequire(\"lsUl2\");\nclass $1d42537681d02be3$export$9e37856d1928d388 {\n callCompleteSignal;\n parameters;\n constructor(){\n this.callCompleteSignal = new (0, $47Wdp.twrSignal)();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(()=>{\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = (0, $lsUl2.twrTimeImpl)();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [\n this.callCompleteSignal.sharedArray,\n this.parameters.buffer\n ];\n }\n processMessage(msgType, data) {\n switch(msgType){\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\nclass $1d42537681d02be3$export$78d2a4633fe89379 {\n callCompleteSignal;\n parameters;\n constructor(params){\n this.callCompleteSignal = new (0, $47Wdp.twrSignal)(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\n \"sleep\",\n [\n ms\n ]\n ]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\n \"time\"\n ]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n\n});\n\nparcelRegister(\"bqeaG\", function(module, exports) {\n\n$parcel$export(module.exports, \"default\", () => $850d1d8f0aa1ea8f$export$2e2bcd8739ae039);\nconst $850d1d8f0aa1ea8f$var$keycodeCtrlKeys = {\n \"a\": \"selectAll\",\n \"c\": \"copy\",\n \"s\": \"save\",\n \"v\": \"paste\",\n \"x\": \"cut\",\n \"y\": \"redo\",\n \"z\": \"undo\"\n};\nconst $850d1d8f0aa1ea8f$var$keycodeShiftedKeys = {\n \"/\": \"?\",\n \".\": \">\",\n \",\": \"<\",\n \"'\": '\"',\n \";\": \":\",\n \"[\": \"{\",\n \"]\": \"}\",\n \"\\\\\": \"|\",\n \"`\": \"~\",\n \"=\": \"+\",\n \"-\": \"_\",\n \"1\": \"!\",\n \"2\": \"@\",\n \"3\": \"#\",\n \"4\": \"$\",\n \"5\": \"%\",\n \"6\": \"^\",\n \"7\": \"&\",\n \"8\": \"*\",\n \"9\": \"(\",\n \"0\": \")\",\n \"a\": \"A\",\n \"b\": \"B\",\n \"c\": \"C\",\n \"d\": \"D\",\n \"e\": \"E\",\n \"f\": \"F\",\n \"g\": \"G\",\n \"h\": \"H\",\n \"i\": \"I\",\n \"j\": \"J\",\n \"k\": \"K\",\n \"l\": \"L\",\n \"m\": \"M\",\n \"n\": \"N\",\n \"o\": \"O\",\n \"p\": \"P\",\n \"q\": \"q\",\n \"r\": \"R\",\n \"s\": \"S\",\n \"t\": \"T\",\n \"u\": \"U\",\n \"v\": \"V\",\n \"w\": \"W\",\n \"x\": \"X\",\n \"y\": \"Y\",\n \"z\": \"Z\"\n};\nconst $850d1d8f0aa1ea8f$var$keyCodeUnshiftedKeys = {};\nfor(const x in $850d1d8f0aa1ea8f$var$keycodeShiftedKeys){\n const shiftedKey = $850d1d8f0aa1ea8f$var$keycodeShiftedKeys[x];\n $850d1d8f0aa1ea8f$var$keyCodeUnshiftedKeys[shiftedKey] = x;\n}\nconst $850d1d8f0aa1ea8f$var$keydownKeycodeDictionary = {\n 0: \"\\\\\",\n 8: \"backspace\",\n 9: \"tab\",\n 12: \"num\",\n 13: \"enter\",\n 16: \"shift\",\n 17: \"ctrl\",\n 18: \"alt\",\n 19: \"pause\",\n 20: \"caps\",\n 27: \"esc\",\n 32: \" \",\n 33: \"pageup\",\n 34: \"pagedown\",\n 35: \"end\",\n 36: \"home\",\n 37: \"left\",\n 38: \"up\",\n 39: \"right\",\n 40: \"down\",\n 44: \"print\",\n 45: \"insert\",\n 46: \"delete\",\n 48: \"0\",\n 49: \"1\",\n 50: \"2\",\n 51: \"3\",\n 52: \"4\",\n 53: \"5\",\n 54: \"6\",\n 55: \"7\",\n 56: \"8\",\n 57: \"9\",\n 59: \";\",\n 61: \"=\",\n 65: \"a\",\n 66: \"b\",\n 67: \"c\",\n 68: \"d\",\n 69: \"e\",\n 70: \"f\",\n 71: \"g\",\n 72: \"h\",\n 73: \"i\",\n 74: \"j\",\n 75: \"k\",\n 76: \"l\",\n 77: \"m\",\n 78: \"n\",\n 79: \"o\",\n 80: \"p\",\n 81: \"q\",\n 82: \"r\",\n 83: \"s\",\n 84: \"t\",\n 85: \"u\",\n 86: \"v\",\n 87: \"w\",\n 88: \"x\",\n 89: \"y\",\n 90: \"z\",\n 91: \"meta\",\n 92: \"meta\",\n 93: \"meta\",\n 96: \"num0\",\n 97: \"num1\",\n 98: \"num2\",\n 99: \"num3\",\n 100: \"num4\",\n 101: \"num5\",\n 102: \"num6\",\n 103: \"num7\",\n 104: \"num8\",\n 105: \"num9\",\n 106: \"*\",\n 107: \"+\",\n 108: \"num_enter\",\n 109: \"num_subtract\",\n 110: \"num_decimal\",\n 111: \"num_divide\",\n 112: \"f1\",\n 113: \"f2\",\n 114: \"f3\",\n 115: \"f4\",\n 116: \"f5\",\n 117: \"f6\",\n 118: \"f7\",\n 119: \"f8\",\n 120: \"f9\",\n 121: \"f10\",\n 122: \"f11\",\n 123: \"f12\",\n 124: \"print\",\n 144: \"num\",\n 145: \"scroll\",\n 173: \"-\",\n 186: \";\",\n 187: \"=\",\n 188: \",\",\n 189: \"-\",\n 190: \".\",\n 191: \"/\",\n 192: \"`\",\n 219: \"[\",\n 220: \"\\\\\",\n 221: \"]\",\n 222: \"'\",\n 223: \"`\",\n 224: \"cmd\",\n 225: \"alt\",\n 57392: \"ctrl\",\n 63289: \"num\"\n};\nconst $850d1d8f0aa1ea8f$var$keypressCharacterMapOverides = {\n \"\\r\": \"enter\"\n};\nconst $850d1d8f0aa1ea8f$var$keypressCharacterMap = JSON.parse(JSON.stringify($850d1d8f0aa1ea8f$var$keydownKeycodeDictionary));\nfor (const key of Object.keys($850d1d8f0aa1ea8f$var$keypressCharacterMapOverides))$850d1d8f0aa1ea8f$var$keypressCharacterMap[key] = $850d1d8f0aa1ea8f$var$keypressCharacterMapOverides[key];\nconst $850d1d8f0aa1ea8f$var$keydownCharacterMap = {\n \"num_subtract\": \"-\",\n \"num_enter\": \"\\n\",\n \"num_decimal\": \".\",\n \"num_divide\": \"/\",\n \"enter\": \"\\n\",\n \"tab\": \"\t\",\n \"backspace\": \"\\b\"\n};\nconst $850d1d8f0aa1ea8f$export$d1477772898aaa70 = [\n \"backspace\",\n \"enter\",\n \"tab\",\n \"num\",\n \"shift\",\n \"meta\",\n \"alt\",\n \"pause\",\n \"caps\",\n \"esc\",\n \"pageup\",\n \"pagedown\",\n \"end\",\n \"home\",\n \"left\",\n \"up\",\n \"right\",\n \"down\",\n \"print\",\n \"insert\",\n \"delete\",\n \"cmd\",\n \"f1\",\n \"f2\",\n \"f3\",\n \"f4\",\n \"f5\",\n \"f6\",\n \"f7\",\n \"f8\",\n \"f9\",\n \"f10\",\n \"f11\",\n \"f12\",\n \"scroll\",\n \"ctrl\"\n];\nconst $850d1d8f0aa1ea8f$var$validEvents = [\n \"keydown\",\n \"keyup\"\n];\nconst $850d1d8f0aa1ea8f$var$isMobile = ()=>{\n const ua = navigator.userAgent;\n const mobile = /IEMobile|Windows Phone|Lumia/i.test(ua) ? \"w\" : /iPhone|iP[oa]d/.test(ua) ? \"i\" : /Android/.test(ua) ? \"a\" : /BlackBerry|PlayBook|BB10/.test(ua) ? \"b\" : /Mobile Safari/.test(ua) ? \"s\" : /webOS|Mobile|Tablet|Opera Mini|\\bCrMo\\/|Opera Mobi/i.test(ua) ? 1 : 0;\n return mobile !== 0;\n};\nfunction $850d1d8f0aa1ea8f$var$getKeypressKeycodeValue(charcode) {\n const character = String.fromCharCode(charcode);\n if ($850d1d8f0aa1ea8f$var$isMobile()) return character;\n if (character in $850d1d8f0aa1ea8f$var$keyCodeUnshiftedKeys) return $850d1d8f0aa1ea8f$var$keyCodeUnshiftedKeys[character];\n else if (character in $850d1d8f0aa1ea8f$var$keypressCharacterMap) return $850d1d8f0aa1ea8f$var$keypressCharacterMap[character];\n return character;\n}\nfunction $850d1d8f0aa1ea8f$export$2e2bcd8739ae039(event) {\n let key;\n if (event.type === \"keypress\" && !$850d1d8f0aa1ea8f$var$isMobile()) key = $850d1d8f0aa1ea8f$var$getKeypressKeycodeValue(event.charCode);\n else if (event.type === \"keypress\" && $850d1d8f0aa1ea8f$var$isMobile()) key = $850d1d8f0aa1ea8f$var$getKeypressKeycodeValue(event.keyCode);\n else if ($850d1d8f0aa1ea8f$var$validEvents.indexOf(event.type) > -1) {\n if (event.which !== undefined) key = $850d1d8f0aa1ea8f$var$keydownKeycodeDictionary[event.which];\n else if (event.keyCode !== undefined) key = $850d1d8f0aa1ea8f$var$keydownKeycodeDictionary[event.keyCode];\n else key = \"enter\";\n } else return false;\n let char = key;\n if (event.shiftKey && key in $850d1d8f0aa1ea8f$var$keycodeShiftedKeys) char = $850d1d8f0aa1ea8f$var$keycodeShiftedKeys[key];\n else if (event.ctrlKey && key in $850d1d8f0aa1ea8f$var$keycodeCtrlKeys) char = $850d1d8f0aa1ea8f$var$keycodeCtrlKeys[key];\n else if (key in $850d1d8f0aa1ea8f$var$keydownCharacterMap) char = $850d1d8f0aa1ea8f$var$keydownCharacterMap[key];\n return {\n char: char,\n key: key\n };\n}\n\n});\n\nparcelRegister(\"aRHnW\", function(module, exports) {\n\nvar $hoqmg = parcelRequire(\"hoqmg\");\nlet $7e9081fcee88b005$var$url = new URL(\"twrmodworker.2165e649.js\", import.meta.url);\nmodule.exports = $hoqmg($7e9081fcee88b005$var$url.toString(), $7e9081fcee88b005$var$url.origin, true);\n\n});\nparcelRegister(\"hoqmg\", function(module, exports) {\n\"use strict\";\nmodule.exports = function(workerUrl, origin, isESM) {\n if (origin === self.location.origin) // If the worker bundle's url is on the same origin as the document,\n // use the worker bundle's own url.\n return workerUrl;\n else {\n // Otherwise, create a blob URL which loads the worker bundle with `importScripts`.\n var source = isESM ? \"import \" + JSON.stringify(workerUrl) + \";\" : \"importScripts(\" + JSON.stringify(workerUrl) + \");\";\n return URL.createObjectURL(new Blob([\n source\n ], {\n type: \"application/javascript\"\n }));\n }\n};\n\n});\n\n\n\n\nvar $49087e929fab6e62$exports = {};\n\n(parcelRequire(\"eZoLj\")).register(new URL(\"\", import.meta.url).toString(), JSON.parse('[\"kjr0c\",\"index.528b9ee5.js\",\"cTHdP\",\"twrmodworker.2165e649.js\"]'));\n\n\n//# sourceMappingURL=index.528b9ee5.js.map\n","\"use strict\";\n\nvar mapping = new Map();\nfunction register(baseUrl, manifest) {\n for (var i = 0; i < manifest.length - 1; i += 2) {\n mapping.set(manifest[i], {\n baseUrl: baseUrl,\n path: manifest[i + 1]\n });\n }\n}\nfunction resolve(id) {\n var resolved = mapping.get(id);\n if (resolved == null) {\n throw new Error('Could not resolve bundle with id ' + id);\n }\n return new URL(resolved.path, resolved.baseUrl).toString();\n}\nmodule.exports.register = register;\nmodule.exports.resolve = resolve;","import {twrWasmModule} from \"./twrmod.js\";\r\nimport {IModOpts, IModInWorkerParams, TStdioVals} from \"./twrmodbase.js\"\r\nimport {twrWasmModuleAsync} from \"./twrmodasync.js\";\r\n\r\nexport {IModOpts, TStdioVals, IModInWorkerParams};\r\nexport {twrWasmModule};\r\nexport {twrWasmModuleAsync};\r\n\r\n","import { twrDebugLogImpl } from \"./twrdebug.js\";\nimport { twrWasmModuleInJSMain } from \"./twrmodjsmain.js\";\nimport { twrTimeImpl } from \"./twrdate.js\";\nexport class twrWasmModule extends twrWasmModuleInJSMain {\n malloc;\n constructor(opts = {}) {\n super(opts, true);\n this.malloc = (size) => { throw new Error(\"error - un-init malloc called\"); };\n let canvas;\n if (this.d2dcanvas.isValid())\n canvas = this.d2dcanvas;\n else\n canvas = this.iocanvas;\n this.modParams.imports = {\n twrDebugLog: twrDebugLogImpl,\n twrTime: twrTimeImpl,\n twrDivCharOut: this.iodiv.charOut.bind(this.iodiv),\n twrCanvasGetProp: canvas.getProp.bind(canvas),\n twrCanvasDrawSeq: canvas.drawSeq.bind(canvas),\n twrCanvasCharIn: this.null,\n twrCanvasInkey: this.null,\n twrDivCharIn: this.null,\n twrSleep: this.null,\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function (x, y) { return x % y; },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil),\n };\n }\n null(inval) {\n throw new Error(\"call to unimplemented twrXXX import in twrWasmModule. Use twrWasmModuleAsync ?\");\n }\n}\n//# sourceMappingURL=twrmod.js.map","import {twrDebugLogImpl} from \"./twrdebug.js\"\r\nimport {IModOpts} from \"./twrmodbase.js\";\r\nimport {twrWasmModuleInJSMain} from \"./twrmodjsmain.js\"\r\nimport {twrCanvas} from \"./twrcanvas.js\";\r\nimport {twrTimeImpl} from \"./twrdate.js\"\r\n\r\n\r\n\r\nexport class twrWasmModule extends twrWasmModuleInJSMain {\r\n\t malloc:(size:number)=>Promise;\r\n\r\n\r\n\tconstructor(opts:IModOpts={}) {\r\n\t\tsuper(opts, true);\r\n\t\tthis.malloc=(size:number)=>{throw new Error(\"error - un-init malloc called\")};\r\n\t\t\r\n\t\tlet canvas:twrCanvas;\r\n\t\tif (this.d2dcanvas.isValid()) canvas=this.d2dcanvas;\r\n\t\telse canvas=this.iocanvas;\r\n\r\n\t\tthis.modParams.imports={\r\n\t\t\ttwrDebugLog:twrDebugLogImpl,\r\n\t\t\ttwrTime:twrTimeImpl,\r\n\t\t\ttwrDivCharOut:this.iodiv.charOut.bind(this.iodiv),\r\n\t\t\ttwrCanvasGetProp:canvas.getProp.bind(canvas),\r\n\t\t\ttwrCanvasDrawSeq:canvas.drawSeq.bind(canvas),\r\n\t\t\ttwrCanvasCharIn:this.null,\r\n\t\t\ttwrCanvasInkey:this.null,\r\n\t\t\ttwrDivCharIn:this.null,\r\n\t\t\ttwrSleep:this.null,\r\n\r\n\t\t\ttwrSin:Math.sin,\r\n\t\t\ttwrCos:Math.cos,\r\n\t\t\ttwrTan: Math.tan,\r\n\t\t\ttwrFAbs: Math.abs,\r\n\t\t\ttwrACos: Math.acos,\r\n\t\t\ttwrASin: Math.asin,\r\n\t\t\ttwrATan: Math.atan,\r\n\t\t\ttwrExp: Math.exp,\r\n\t\t\ttwrFloor: Math.floor,\r\n\t\t\ttwrCeil: Math.ceil,\r\n\t\t\ttwrFMod: function(x:number, y:number) {return x%y},\r\n\t\t\ttwrLog: Math.log,\r\n\t\t\ttwrPow: Math.pow,\r\n\t\t\ttwrSqrt: Math.sqrt,\r\n\t\t\ttwrTrunc: Math.trunc,\r\n\r\n\t\t\ttwrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\r\n\t\t\ttwrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\r\n\t\t\ttwrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\r\n\t\t\ttwrAtod: this.floatUtil.atod.bind(this.floatUtil),\r\n\t\t\ttwrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil),\r\n\t\t}\r\n\t}\r\n\r\n\tnull(inval?:any) {\r\n\t\tthrow new Error(\"call to unimplemented twrXXX import in twrWasmModule. Use twrWasmModuleAsync ?\");\r\n\t}\r\n}\r\n\r\n\r\n\r\n\r\n","let logline = \"\";\nexport function twrDebugLogImpl(char) {\n if (char == 10 || char == 3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\n console.log(logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n logline = \"\";\n }\n else {\n logline = logline + String.fromCharCode(char);\n if (logline.length >= 200) {\n console.log(logline);\n logline = \"\";\n }\n }\n}\n// ************************************************************************\n// debugLog doesn't currently wait for the message to log, it returns immediately.\n// I could move this to be in the twrWaitingCalls class\nexport function twrDebugLogProxy(ch) {\n postMessage([\"debug\", ch]);\n}\n//# sourceMappingURL=twrdebug.js.map","\r\nlet logline=\"\";\r\nexport function twrDebugLogImpl(char:number) {\r\n\tif (char==10 || char==3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\r\n\t\tconsole.log(logline);\t// ideally without a linefeed, but there is no way to not have a LF with console.log API.\r\n\t\tlogline=\"\";\r\n\t}\r\n\telse {\r\n\t\tlogline=logline+String.fromCharCode(char);\r\n\t\tif (logline.length>=200) {\r\n\t\t\tconsole.log(logline);\r\n\t\t\tlogline=\"\";\r\n\t\t}\r\n\t}\r\n}\r\n\r\n// ************************************************************************\r\n// debugLog doesn't currently wait for the message to log, it returns immediately.\r\n// I could move this to be in the twrWaitingCalls class\r\nexport function twrDebugLogProxy(ch:number) {\r\n postMessage([\"debug\", ch]);\r\n}\r\n\r\n","// This class extends base to handle options when called in the main Java Script thread\nimport { twrDiv } from \"./twrdiv.js\";\nimport { twrWasmModuleBase } from \"./twrmodbase.js\";\nimport { twrCanvas } from \"./twrcanvas.js\";\nexport class twrWasmModuleInJSMain extends twrWasmModuleBase {\n iocanvas;\n d2dcanvas;\n iodiv;\n modParams;\n constructor(opts = {}, isWasmModule = false) {\n super(isWasmModule);\n if (typeof document === 'undefined')\n throw new Error(\"twrWasmModuleJSMain should only be created in JavaScript Main.\");\n const eiodiv = document.getElementById(\"twr_iodiv\");\n const eiocanvas = document.getElementById(\"twr_iocanvas\");\n const ed2dcanvas = document.getElementById(\"twr_d2dcanvas\");\n if (eiocanvas && ed2dcanvas)\n throw new Error(\"Both twr_iocanvas and twr_d2dcanvas defined. Currently only one canvas allowed.\");\n if (opts.stdio == 'div' && !eiodiv)\n throw new Error(\"twrWasmModuleBase opts=='div' but twr_iodiv not defined\");\n if (opts.stdio == 'canvas' && !eiocanvas)\n throw new Error(\"twrWasmModuleBase, opts=='canvas' but twr_iocanvas not defined\");\n if (opts.isd2dcanvas && !ed2dcanvas)\n throw new Error(\"twrWasmModuleBase, opts.isdrawcanvas==true but twr_d2dcanvas not defined\");\n // set default opts based on elements found\n if (eiodiv)\n opts = { stdio: \"div\", ...opts };\n else if (eiocanvas)\n opts = { stdio: \"canvas\", ...opts };\n else\n opts = { stdio: \"debug\", ...opts };\n if (!eiodiv && !eiocanvas)\n console.log(\"Since neither twr_iocanvas nor twr_iodiv is defined, stdout directed to debug console.\");\n else\n console.log('tiny-wasm-runtime: stdio set to: ', opts.stdio);\n if (eiocanvas)\n opts = { windim: [64, 16], ...opts };\n else\n opts = { windim: [0, 0], ...opts };\n if (!opts.imports)\n opts.imports = {};\n let styleIsDefault = false;\n if (!opts.backcolor) {\n styleIsDefault = true;\n opts.backcolor = \"black\";\n }\n if (!opts.forecolor) {\n styleIsDefault = true;\n opts.forecolor = \"white\";\n }\n if (!opts.fontsize) {\n styleIsDefault = true;\n opts.fontsize = 16;\n }\n if (opts.isd2dcanvas === undefined) {\n if (ed2dcanvas)\n opts.isd2dcanvas = true;\n else\n opts.isd2dcanvas = false;\n }\n this.modParams = {\n stdio: opts.stdio,\n windim: opts.windim,\n imports: opts.imports,\n forecolor: opts.forecolor,\n backcolor: opts.backcolor,\n styleIsDefault: styleIsDefault,\n fontsize: opts.fontsize,\n isd2dcanvas: opts.isd2dcanvas\n };\n this.iodiv = new twrDiv(eiodiv, this.modParams, this);\n this.iocanvas = new twrCanvas(eiocanvas, this.modParams, this);\n this.d2dcanvas = new twrCanvas(ed2dcanvas, this.modParams, this);\n }\n divLog(...params) {\n for (var i = 0; i < params.length; i++) {\n this.iodiv.stringOut(params[i].toString());\n this.iodiv.charOut(32); // space\n }\n this.iodiv.charOut(10);\n }\n}\n//# sourceMappingURL=twrmodjsmain.js.map","// This class extends base to handle options when called in the main Java Script thread\r\n\r\nimport {twrDiv} from \"./twrdiv.js\"\r\nimport {IModParams, IModOpts, twrWasmModuleBase} from \"./twrmodbase.js\"\r\nimport {twrCanvas} from \"./twrcanvas.js\"\r\n\r\n\r\nexport abstract class twrWasmModuleInJSMain extends twrWasmModuleBase {\r\n\tiocanvas:twrCanvas;\r\n\td2dcanvas:twrCanvas;\r\n\tiodiv:twrDiv;\r\n\tmodParams:IModParams;\r\n\r\n constructor(opts:IModOpts={}, isWasmModule=false) {\r\n\t\tsuper(isWasmModule);\r\n\t\tif (typeof document === 'undefined')\r\n\t\t\tthrow new Error (\"twrWasmModuleJSMain should only be created in JavaScript Main.\");\r\n\r\n\t\tconst eiodiv=document.getElementById(\"twr_iodiv\") as HTMLDivElement;\r\n\t\tconst eiocanvas=document.getElementById(\"twr_iocanvas\") as HTMLCanvasElement;\r\n\t\tconst ed2dcanvas=document.getElementById(\"twr_d2dcanvas\") as HTMLCanvasElement;\r\n\r\n\t\tif (eiocanvas && ed2dcanvas) throw new Error (\"Both twr_iocanvas and twr_d2dcanvas defined. Currently only one canvas allowed.\");\r\n\t\tif (opts.stdio=='div' && !eiodiv) throw new Error(\"twrWasmModuleBase opts=='div' but twr_iodiv not defined\");\r\n\t\tif (opts.stdio=='canvas' && !eiocanvas) throw new Error(\"twrWasmModuleBase, opts=='canvas' but twr_iocanvas not defined\");\r\n\t\tif (opts.isd2dcanvas && !ed2dcanvas) throw new Error(\"twrWasmModuleBase, opts.isdrawcanvas==true but twr_d2dcanvas not defined\");\r\n\r\n\t\t// set default opts based on elements found\r\n\t\tif (eiodiv) opts={stdio:\"div\", ...opts};\r\n\t\telse if (eiocanvas) opts={stdio:\"canvas\", ...opts};\r\n\t\telse opts={stdio:\"debug\", ...opts};\r\n\r\n\t\tif (!eiodiv && !eiocanvas) console.log(\"Since neither twr_iocanvas nor twr_iodiv is defined, stdout directed to debug console.\");\r\n\t\telse console.log('tiny-wasm-runtime: stdio set to: ', opts.stdio);\r\n\r\n\t\tif (eiocanvas) opts={windim:[64, 16], ...opts};\r\n\t\telse opts={windim:[0, 0], ...opts};\r\n\r\n\t\tif (!opts.imports) opts.imports={};\r\n\r\n\t\tlet styleIsDefault=false;\r\n\t\tif (!opts.backcolor) {styleIsDefault=true; opts.backcolor=\"black\";}\r\n\t\tif (!opts.forecolor) {styleIsDefault=true; opts.forecolor=\"white\";}\r\n\t\tif (!opts.fontsize) {styleIsDefault=true; opts.fontsize=16;}\r\n\r\n\t\tif (opts.isd2dcanvas===undefined) {\r\n\t\t\tif (ed2dcanvas) \r\n\t\t\t\topts.isd2dcanvas=true;\r\n\t\t\telse\r\n\t\t\t\topts.isd2dcanvas=false;\r\n\t\t}\r\n\r\n\t\tthis.modParams={\r\n\t\t\tstdio:opts.stdio!, \r\n\t\t\twindim:opts.windim!, \r\n\t\t\timports:opts.imports, \r\n\t\t\tforecolor:opts.forecolor, \r\n\t\t\tbackcolor:opts.backcolor, \r\n\t\t\tstyleIsDefault: styleIsDefault,\r\n\t\t\tfontsize:opts.fontsize,\r\n\t\t\tisd2dcanvas:opts.isd2dcanvas\r\n\t\t};\r\n\r\n\t\tthis.iodiv=new twrDiv(eiodiv, this.modParams, this);\r\n\t\tthis.iocanvas=new twrCanvas(eiocanvas, this.modParams, this);\r\n\t\tthis.d2dcanvas=new twrCanvas(ed2dcanvas, this.modParams, this);\r\n\r\n\t}\r\n\r\n\tdivLog(...params: string[]) {\r\n\t\tfor (var i = 0; i < params.length; i++) {\r\n\t\t\tthis.iodiv.stringOut(params[i].toString());\r\n\t\t\tthis.iodiv.charOut(32); // space\r\n\t\t}\r\n\t\tthis.iodiv.charOut(10);\r\n\t }\r\n}","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nexport class twrDiv {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase) {\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\n this.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n if (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.divKeys.sharedArray];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */\n charOut(ch) {\n if (!this.div)\n return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n }\n switch (ch) {\n case 10: // newline\n case 13: // return\n if (ch == 10 && this.lastChar == 13)\n break; // detect CR LF and treat as single new line\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8: // backspace\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n case 0xE: // cursor on\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF: // cursor off\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for (let i = 0; i < str.length; i++)\n this.charOut(str.charCodeAt(i));\n }\n}\nexport class twrDivProxy {\n divKeys;\n constructor(params) {\n const [divKeysBuffer] = params;\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n charOut(ch) {\n postMessage([\"divout\", ch]);\n }\n}\n//# sourceMappingURL=twrdiv.js.map","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\r\nimport { IModParams } from \"./twrmodbase.js\";\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\";\r\n\r\nexport type TDivProxyParams = [SharedArrayBuffer];\r\n\r\nexport interface IDiv {\r\n charOut: (ds:number)=>void,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TDivProxyParams,\r\n }\r\n\r\n\r\nexport class twrDiv implements IDiv {\r\n\tdiv:HTMLDivElement|null|undefined;\r\n\tdivKeys?:twrSharedCircularBuffer;\r\n\tCURSOR=String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\r\n\tcursorOn:boolean=false;\r\n\tlastChar:number=0;\r\n\textraBR:boolean=false;\r\n\towner:twrWasmModuleBase;\r\n\r\n constructor(element:HTMLDivElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n\t\tthis.div=element;\r\n\t\tthis.owner=modbase;\r\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\r\n\t\t\tthis.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n\t\t}\r\n\r\n\t\tif (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\r\n\t\t\tthis.div.style.backgroundColor = modParams.backcolor;\r\n\t\t\tthis.div.style.color = modParams.forecolor;\r\n\t\t\tthis.div.style.font=modParams.fontsize.toString()+\"px arial\"\r\n\t\t}\r\n }\r\n\r\n\tisValid() {\r\n\t\treturn !!this.div;\r\n\t}\r\n\r\n getProxyParams() : TDivProxyParams {\r\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [ this.divKeys.sharedArray];\r\n }\r\n\r\n\r\n/* \r\n * add character to div. Supports the following control codes:\r\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\r\n * 0xE cursor on \r\n * 0x8 backspace\r\n * 0xF cursor off \r\n*/\r\n\tcharOut(ch:number) {\r\n\r\n\t\tif (!this.div) return;\r\n\r\n\t\t//console.log(\"div::charout: \", ch);\r\n\r\n\t\tif (this.extraBR) {\r\n\t\t\tthis.extraBR=false;\r\n\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -4);\r\n\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t}\r\n\r\n\t\tswitch (ch) {\r\n\t\t\tcase 10: // newline\r\n\t\t\tcase 13: // return\r\n\t\t\t\tif (ch==10 && this.lastChar==13) break; // detect CR LF and treat as single new line\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\r\n\t\t\t\tthis.extraBR=true;\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\t//element.scrollIntoView();\r\n\t\t\t\t//element.scrollTop = element.scrollHeight;\r\n\t\t\t\tlet p = this.div.getBoundingClientRect();\r\n\t\t\t\twindow.scrollTo(0, p.height+100);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 8: // backspace\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xE: // cursor on\r\n\t\t\t\tif (!this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=true;\r\n\t\t\t\t\tthis.div.innerHTML += this.CURSOR;\r\n\t\t\t\t\tthis.div.focus();\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xF: // cursor off\r\n\t\t\t\tif (this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=false;\r\n\t\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += String.fromCharCode(ch);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\tthis.lastChar=ch;\r\n\t}\r\n\r\n\tstringOut(str:string) {\r\n\t\tfor (let i=0; i < str.length; i++)\r\n\t\t\tthis.charOut(str.charCodeAt(i));\r\n\t}\r\n}\r\n\r\n\r\nexport class twrDivProxy implements IDiv {\r\n divKeys: twrSharedCircularBuffer;\r\n\r\n constructor(params:TDivProxyParams) {\r\n const [divKeysBuffer] = params;\r\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\r\n }\r\n\r\n charIn() { \r\n return this.divKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.divKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n\tcharOut(ch:number) {\r\n\t\tpostMessage([\"divout\", ch]);\r\n\t}\r\n}\r\n\r\n","//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst RDIDX = 256;\nconst WRIDX = 257;\nconst LEN = 256;\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\n// the first 256 array entries are the circular buffer\n// the next two are used for the read and write index\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\nexport class twrSharedCircularBuffer {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(258 * 4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[RDIDX] = 0;\n this.buf[WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[WRIDX];\n this.buf[i] = n;\n i++;\n if (i == LEN)\n i = 0;\n this.buf[WRIDX] = i;\n Atomics.notify(this.buf, WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[RDIDX] = i;\n return n;\n }\n else\n return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[RDIDX] == this.buf[WRIDX];\n }\n}\n//# sourceMappingURL=twrcircular.js.map","//\r\n// This class implements a circular buffer that the main javascript thread can write to, \r\n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\r\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \r\n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\r\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\r\n//\r\n\r\nconst RDIDX=256;\r\nconst WRIDX=257;\r\nconst LEN=256;\r\n\r\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\r\n// the first 256 array entries are the circular buffer\r\n// the next two are used for the read and write index\r\n\r\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\r\n\r\nexport class twrSharedCircularBuffer {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n \r\n\tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(258*4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[RDIDX]=0;\r\n this.buf[WRIDX]=0;\r\n\t}\r\n\r\n\twrite(n:number) {\r\n let i=this.buf[WRIDX];\r\n this.buf[i]=n;\r\n i++;\r\n if (i==LEN) i=0;\r\n this.buf[WRIDX]=i; \r\n Atomics.notify(this.buf, WRIDX); \r\n\t}\r\n\r\n\tread():number {\r\n if (!this.isEmpty()) {\r\n let i=this.buf[RDIDX];\r\n let n=this.buf[i];\r\n i++;\r\n this.buf[RDIDX]=i;\r\n return n;\r\n }\r\n\t\telse\r\n return -1;\r\n\t}\r\n\r\n readWait():number {\r\n if (this.isEmpty()) {\r\n const rdptr=this.buf[RDIDX];\r\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\r\n Atomics.wait(this.buf, WRIDX, rdptr);\r\n }\r\n return this.read();\r\n\t}\r\n\r\n isEmpty():boolean {\r\n return this.buf[RDIDX]==this.buf[WRIDX];\r\n }\r\n}\r\n","import { twrFloatUtil } from \"./twrfloat.js\";\n/*********************************************************************/\n/*********************************************************************/\n/*********************************************************************/\nexport class twrWasmModuleBase {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\n floatUtil;\n constructor(isWasmModule = false) {\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new twrFloatUtil(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/\n /*********************************************************************/\n async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n }\n catch (err) {\n console.log('loadWasm() failed to fetch: ' + pathToLoad);\n throw err;\n }\n if (!response.ok)\n throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, { env: allimports });\n this.exports = instance.instance.exports;\n if (!this.exports)\n throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory)\n throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory)\n throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer)\n console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\"setmemory\", this.memory]);\n }\n if (this.isWasmModule) {\n // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (!(this.memory.buffer instanceof ArrayBuffer))\n console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size) => {\n return new Promise(resolve => {\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n }\n catch (err) {\n console.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch (this.modParams.stdio) {\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* callC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */\n async callC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.callCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async callCImpl(fname, cparams = []) {\n if (!this.exports)\n throw new Error(\"this.exports undefined\");\n if (!this.exports[fname])\n throw new Error(\"callC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array))\n throw new Error(\"callC: params must be array, first arg is function name\");\n if (params.length == 0)\n throw new Error(\"callC: missing function name\");\n let cparams = [];\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n cparams[ci++] = p;\n break;\n case 'string':\n cparams[ci++] = await this.putString(p);\n break;\n case 'object':\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n }\n else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"callC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n ci++;\n break;\n case 'string':\n this.callCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n case 'object':\n if (p instanceof URL) {\n this.callCImpl('twr_free', [cparams[ci]]);\n ci = ci + 2;\n break;\n }\n else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for (let j = 0; j < u8.length; j++)\n u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.callCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n }\n else\n throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/\n /*********************************************************************/\n // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for (i = 0; i < sin.length && i < buffer_size - 1; i++)\n this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for (let i = 0; i < u8a.length; i++)\n this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === 'object' && fnin instanceof URL))\n throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [dest, src.length];\n }\n catch (err) {\n console.log('fetchAndPutURL Error. URL: ' + fnin + '\\n' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while (this.mem8[strIndex + i] && (len === undefined ? true : i < len) && (strIndex + i) < this.mem8.length) {\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0)\n throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array((this.mem8.slice(dataptr, dataptr + size)).buffer);\n return u32;\n }\n}\n//# sourceMappingURL=twrmodbase.js.map","\r\nimport {TCanvasProxyParams} from \"./twrcanvas.js\"\r\nimport {TDivProxyParams} from \"./twrdiv.js\";\r\nimport {TWaitingCallsProxyParams} from \"./twrwaitingcalls.js\"\r\nimport {twrDebugLogImpl} from \"./twrdebug.js\";\r\nimport {twrFloatUtil} from \"./twrfloat.js\";\r\n\r\n\r\nexport type TStdioVals=\"div\"|\"canvas\"|\"null\"|\"debug\";\r\n\r\nexport interface IModOpts {\r\n\tstdio?:TStdioVals, \r\n\twindim?:[number, number],\r\n\tforecolor?:string,\r\n\tbackcolor?:string,\r\n\tfontsize?:number,\r\n\tisd2dcanvas?:boolean,\r\n\timports?:{},\r\n}\r\n\r\nexport interface IModParams {\r\n\tstdio:TStdioVals, \r\n\twindim:[number, number],\r\n\tforecolor:string,\r\n\tbackcolor:string,\r\n\tfontsize:number,\r\n\tstyleIsDefault: boolean\r\n\tisd2dcanvas:boolean,\r\n\timports:{[index:string]:Function},\r\n}\r\n\r\nexport interface IModInWorkerParams {\r\n\tdivProxyParams:TDivProxyParams,\r\n\tcanvasProxyParams:TCanvasProxyParams,\r\n\twaitingCallsProxyParams:TWaitingCallsProxyParams,\r\n}\r\n\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n\r\nexport abstract class twrWasmModuleBase {\r\n\tmemory?:WebAssembly.Memory;\r\n\tmem8:Uint8Array;\r\n\tmem32:Uint32Array;\r\n\tmemD:Float64Array;\r\n\tabstract malloc:(size:number)=>Promise;\r\n\tabstract modParams:IModParams;\r\n\texports?:WebAssembly.Exports;\r\n\tisWorker=false;\r\n\tisWasmModule:boolean; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\r\n\tfloatUtil:twrFloatUtil;\r\n\r\n\tconstructor(isWasmModule=false) {\r\n\t\tthis.isWasmModule=isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\r\n\t\tthis.mem8=new Uint8Array(); \t// avoid type errors\r\n\t\tthis.mem32=new Uint32Array(); // avoid type errors\r\n\t\tthis.memD=new Float64Array(); // avoid type errors\r\n\t\tthis.floatUtil=new twrFloatUtil(this);\r\n\t\t//console.log(\"size of mem8 after constructor\",this.mem8.length);\r\n\t}\r\n\r\n\t/*********************************************************************/\r\n\t/*********************************************************************/\r\n\r\n\tasync loadWasm(pathToLoad:string) {\r\n\t\t//console.log(\"fileToLoad\",fileToLoad)\r\n\r\n\t\tlet response;\r\n\t\ttry {\r\n\t\t\tresponse=await fetch(pathToLoad);\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('loadWasm() failed to fetch: '+pathToLoad);\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t\t\r\n\t\tif (!response.ok) throw new Error(\"fetch response error on file '\"+pathToLoad+\"'\\n\"+response.statusText);\r\n\r\n\t\ttry {\r\n\t\t\tlet wasmBytes = await response.arrayBuffer();\r\n\r\n\t\t\tlet allimports:WebAssembly.ModuleImports = { \r\n\t\t\t\t...this.modParams.imports\r\n\t\t\t};\r\n\r\n\t\t\tlet instance = await WebAssembly.instantiate(wasmBytes, {env: allimports});\r\n\r\n\t\t\tthis.exports=instance.instance.exports;\r\n\t\t\tif (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\r\n\r\n\t\t\tif (this.memory) throw new Error (\"unexpected error -- this.memory already set\");\r\n\t\t\tthis.memory=this.exports.memory as WebAssembly.Memory;\r\n\t\t\tif (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\r\n\t\t\tthis.mem8 = new Uint8Array(this.memory.buffer);\r\n\t\t\tthis.mem32 = new Uint32Array(this.memory.buffer);\r\n\t\t\tthis.memD = new Float64Array(this.memory.buffer);\r\n\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\tif (this.isWorker) {\r\n\t\t\t\tif (this.memory.buffer instanceof ArrayBuffer)\r\n\t\t\t\t\tconsole.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\r\n\t\t\t\t\r\n\t\t\t\tpostMessage([\"setmemory\",this.memory]);\r\n\t\t\t}\r\n\t\t\tif (this.isWasmModule) {\r\n\t\t\t\t// here if twrWasmModule, twrWasmModuleAsync overrides this function\r\n\t\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\t\tif (!(this.memory.buffer instanceof ArrayBuffer))\r\n\t\t\t\t\tconsole.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\r\n\t\t\t}\r\n\r\n\t\t\tthis.malloc=(size:number)=>{\r\n\t\t\t\treturn new Promise(resolve => {\r\n\t\t\t\t\tconst m=this.exports!.twr_malloc as (size:number)=>number;\r\n\t\t\t\t\tresolve(m(size));\r\n\t\t\t\t});\r\n\t\t };\r\n\r\n\t\t\tthis.init();\r\n\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t}\r\n\r\n\tprivate init() {\r\n\t\t//console.log(\"loadWasm.init() enter\")\r\n\t\t\tlet p:number;\r\n\t\t\tswitch (this.modParams.stdio) {\r\n\t\t\t\tcase \"debug\":\r\n\t\t\t\t\tp=0;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"div\":\r\n\t\t\t\t\tp=1;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"canvas\":\r\n\t\t\t\t\tp=2;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"null\":\r\n\t\t\t\t\tp=3;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tp=0; // debug\r\n\t\t\t}\r\n\r\n\t\t\tconst twrInit=this.exports!.twr_wasm_init as CallableFunction;\r\n\t\t\t//console.log(\"twrInit:\",twrInit)\r\n\t\t\ttwrInit(p, this.mem8.length);\r\n\t}\r\n\r\n\t/* callC takes an array where:\r\n\t* the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\r\n\t* and the next entries are a variable number of parameters to pass to the C function, of type\r\n\t* number - converted to int32 or float64 as appropriate\r\n\t* string - converted to a an index (ptr) into a module Memory returned via stringToMem()\r\n\t* URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\r\n\t* Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\r\n */\r\n\r\n\tasync callC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\t\tconst cparams=await this.preCallC(params);\r\n\t\tlet retval = this.callCImpl(params[0], cparams);\r\n\t\tthis.postCallC(cparams, params);\r\n\t\treturn retval;\r\n\t}\r\n\r\n\tasync callCImpl(fname:string, cparams:number[]=[]) {\r\n\t\tif (!this.exports) throw new Error(\"this.exports undefined\");\r\n\t\tif (!this.exports[fname]) throw new Error(\"callC: function '\"+fname+\"' not in export table. Use --export wasm-ld flag.\");\r\n\r\n\t\tconst f = this.exports[fname] as CallableFunction;\r\n\t\tlet cr=f(...cparams);\r\n\r\n\t\treturn cr;\r\n\t}\r\n\r\n\t// convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\r\n\tasync preCallC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tif (!(params.constructor === Array)) throw new Error (\"callC: params must be array, first arg is function name\");\r\n\t\tif (params.length==0) throw new Error(\"callC: missing function name\");\r\n\r\n\t\tlet cparams:number[]=[];\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tcparams[ci++]=p;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tcparams[ci++]=await this.putString(p);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tconst r=await this.fetchAndPutURL(p);\r\n\t\t\t\t\t\tcparams[ci++]=r[0]; // mem index\r\n\t\t\t\t\t\tcparams[ci++]=r[1]; // len\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tconst r=await this.putArrayBuffer(p);\r\n\t\t\t\t\t\tcparams[ci++]=r; // mem index\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tthrow new Error (\"callC: invalid object type passed in\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn cparams;\r\n\t}\r\n\r\n\t// free the mallocs; copy array buffer data from malloc back to arraybuffer\r\n\tasync postCallC(cparams:number[], params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tthis.callCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t\t\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tthis.callCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\t\tci=ci+2;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tlet u8=new Uint8Array(p);\r\n\t\t\t\t\t\tfor (let j=0; j= this.mem32.length) throw new Error(\"invalid index passed to getLong: \"+idx+\", this.mem32.length: \"+this.mem32.length);\r\n\t\tconst long:number = this.mem32[idx32];\r\n\t\treturn long;\r\n\t}\r\n\t\r\n\tsetLong(idx:number, value:number) {\r\n const idx32 = Math.floor(idx / 4);\r\n if (idx32 * 4 != idx)\r\n throw new Error(\"setLong passed non long aligned address\");\r\n if (idx32 < 0 || idx32 >= this.mem32.length)\r\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\r\n this.mem32[idx32]=value;\r\n }\r\n\r\n\tgetDouble(idx:number): number {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"getLong passed non Float64 aligned address\")\r\n\t\tconst long:number = this.memD[idx64];\r\n\t\treturn long;\r\n\t}\r\n\r\n\tsetDouble(idx:number, value:number) {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"setDouble passed non Float64 aligned address\")\r\n\t\tthis.memD[idx64]=value;\r\n\t}\r\n\r\n\tgetShort(idx:number): number {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getShort: \"+idx);\r\n\t\tconst short:number = this.mem8[idx]+this.mem8[idx+1]*256;\r\n\t\treturn short;\r\n\t}\r\n\r\n\t// get a string out of module memory\r\n\t// null terminated, up until max of (optional) len\r\n\tgetString(strIndex:number, len?:number): string {\r\n\t\tlet sout=\"\";\r\n\r\n\t\tlet i=0;\r\n\t\twhile (this.mem8[strIndex+i] && (len===undefined?true:i= this.mem8.length) throw new Error(\"invalid index passed to getU8: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU8\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU8\")\r\n\r\n\t\tconst u8=this.mem8.slice(dataptr, dataptr+size);\r\n\t\treturn u8;\r\n\t}\r\n\r\n\t// get a int32 array out of module memory when passed in index to [size, dataptr]\r\n\tgetU32Arr(idx:number): Uint32Array {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getU32: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU32\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU32\")\r\n\r\n\t\tif (size%4!=0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\r\n\r\n\t\tconst u32 = new Uint32Array( (this.mem8.slice(dataptr, dataptr+size)).buffer );\r\n\t\treturn u32;\r\n\t}\r\n}\r\n","export class twrFloatUtil {\n mod;\n constructor(mod) {\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\")\n return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\")\n return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll('D', 'e').replaceAll('d', 'e'));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n }\n else {\n let r = value.toString();\n if (r.length > max_precision)\n r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, // char *\n sizeInBytes, //size_t\n value, // double\n fracpart_numdigits, //int\n dec, // int *\n sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1)\n return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) { /* nan */\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (!Number.isFinite(value)) { /* infinity */\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n }\n else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split('.');\n if (intPart == \"0\")\n intPart = \"\";\n if (intPart.length > 0) { // has integer part\n decpos = intPart.length;\n digits = intPart + fracPart;\n }\n else { // only a fraction\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length)\n return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */\n }\n}\n//# sourceMappingURL=twrfloat.js.map","\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\"\r\n\r\nexport class twrFloatUtil {\r\n mod: twrWasmModuleBase;\r\n\r\n constructor(mod: twrWasmModuleBase) {\r\n this.mod=mod;\r\n }\r\n\r\n atod(strptr:number):number {\r\n const str=this.mod.getString(strptr);\r\n\r\n const upper=str.trimStart().toUpperCase();\r\n if (upper==\"INF\" || upper==\"+INF\")\r\n return Number.POSITIVE_INFINITY;\r\n else if (upper==\"-INF\")\r\n return Number.NEGATIVE_INFINITY\r\n else {\r\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\r\n const r=Number.parseFloat(str.replaceAll('D','e').replaceAll('d','e'));\r\n return r;\r\n }\r\n }\r\n\r\n dtoa(buffer:number, buffer_size:number, value:number, max_precision:number):void {\r\n if (max_precision==-1) {\r\n const r=value.toString();\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n else {\r\n let r=value.toString();\r\n if (r.length>max_precision)\r\n r=value.toPrecision(max_precision);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n }\r\n\r\n toFixed(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toFixed(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n toExponential(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toExponential(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\r\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\r\n // Negative exponents must be now smaller than 1e-99\r\n // fully-function C version also int he source, but this is the version enabled by default\r\n fcvtS(\r\n buffer:number, // char *\r\n sizeInBytes:number, //size_t\r\n value:number, // double\r\n fracpart_numdigits:number, //int\r\n dec:number, // int *\r\n sign:number // int *\r\n ):number {\r\n\r\n if (buffer==0 ||sign==0 || dec==0 || sizeInBytes<1) return 1;\r\n\r\n let digits:string;\r\n let decpos:number;\r\n let s=0; // default to positive\r\n\r\n\r\n if (Number.isNaN(value)) { /* nan */\r\n digits=\"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (!Number.isFinite(value)) { /* infinity */\r\n digits=\"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (value==0) { \r\n digits=\"000000000000000000000000000000000000\".slice(0,fracpart_numdigits);\r\n decpos=0;\r\n }\r\n \r\n else {\r\n\r\n if (value<0) {\r\n s=1; // negative\r\n value=Math.abs(value);\r\n }\r\n\r\n if (fracpart_numdigits>100 || value > 1e+21 || value < 1e-99) { \r\n this.mod.copyString(buffer, sizeInBytes, \"\");\r\n this.mod.mem32[dec]=0;\r\n return 1;\r\n }\r\n\r\n const roundValStr=value.toFixed(fracpart_numdigits);\r\n let [intPart=\"\", fracPart=\"\"] = roundValStr.split('.');\r\n if (intPart==\"0\") intPart=\"\";\r\n\r\n if (intPart.length>0) { // has integer part\r\n decpos=intPart.length;\r\n digits=intPart+fracPart;\r\n }\r\n else { // only a fraction\r\n digits=fracPart.replace(/^0+/,\"\"); // remove leading zeros\r\n decpos=digits.length-fracPart.length;\r\n }\r\n }\r\n\r\n if (sizeInBytes-1 < digits.length) return 1; \r\n this.mod.copyString(buffer, sizeInBytes, digits);\r\n this.mod.setLong(dec, decpos);\r\n this.mod.setLong(sign, s);\r\n\r\n return 0;\r\n\r\n /*\r\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\r\n\r\n let decpos=0;\r\n let digits:string;\r\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\r\n \r\n if (decpos>0) { // has integer part\r\n const intlen=Math.max(decpos, 0);\r\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\r\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\r\n }\r\n else { // only a fraction\r\n const intpart=Math.trunc(value);\r\n const fracpart=value-intpart;\r\n const prec=fracpart_numdigits- (-decpos);\r\n console.log(\"prec=\",prec);\r\n if (prec<1) {\r\n digits=\"\";\r\n }\r\n else {\r\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\");\r\n }\r\n }\r\n\r\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\r\n console.log('digits=',digits);\r\n console.log('dec=',decpos);\r\n console.log(\"sign=\",s);\r\n */\r\n\r\n\r\n }\r\n}","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nimport { twrSignal } from \"./twrsignal.js\";\nvar D2DType;\n(function (D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})(D2DType || (D2DType = {}));\nexport class twrCanvas {\n ctx;\n props = { charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight: 0, canvasWidth: 0 };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase) {\n const { forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new twrSignal();\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext)\n throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c)\n throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2)\n throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\n }\n getProp(pn) {\n if (!this.isValid())\n console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */\n drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid())\n console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx)\n return;\n let ins = this.owner.getLong(ds); /* ds->start */\n const lastins = this.owner.getLong(ds + 4); /* ds->last */\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while (1) {\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */\n if (0 /*type!=D2DType.D2D_FILLRECT*/) {\n console.log(\"ins\", ins);\n console.log(\"hdr.next\", this.owner.mem8[ins], this.owner.mem8[ins + 1], this.owner.mem8[ins + 2], this.owner.mem8[ins + 3]);\n console.log(\"hdr.type\", this.owner.mem8[ins + 4], this.owner.mem8[ins + 5]);\n console.log(\"next 4 bytes\", this.owner.mem8[ins + 6], this.owner.mem8[ins + 7], this.owner.mem8[ins + 8], this.owner.mem8[ins + 9]);\n console.log(\"and 4 more \", this.owner.mem8[ins + 10], this.owner.mem8[ins + 11], this.owner.mem8[ins + 12], this.owner.mem8[ins + 13]);\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\n }\n switch (type) {\n case D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case D2DType.D2D_BEGINPATH:\n {\n this.ctx.beginPath();\n }\n break;\n case D2DType.D2D_FILL:\n {\n this.ctx.fill();\n }\n break;\n case D2DType.D2D_SAVE:\n {\n this.ctx.save();\n }\n break;\n case D2DType.D2D_RESTORE:\n {\n this.ctx.restore();\n }\n break;\n case D2DType.D2D_STROKE:\n {\n this.ctx.stroke();\n }\n break;\n case D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = (this.owner.getLong(ins + 48) != 0);\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n }\n else { // Uint8ClampedArray doesn't support shared memory\n this.precomputedObjects[id] = { mem8: new Uint8Array(this.owner.memory.buffer, start, length), width: width, height: height };\n }\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id])\n delete this.precomputedObjects[id];\n else\n console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) {\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n }\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) {\n this.ctx.putImageData(imgData, dx, dy);\n }\n else {\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */\n if (next == 0) {\n if (ins != lastins)\n throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal)\n this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nexport class twrCanvasProxy {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner) {\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new twrSignal(signalBuffer);\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\"drawseq\", [ds]]);\n this.drawCompleteSignal.wait();\n }\n}\n//# sourceMappingURL=twrcanvas.js.map","import {twrWasmModuleBase, IModParams} from \"./twrmodbase.js\"\r\nimport {twrSharedCircularBuffer} from \"./twrcircular.js\";\r\nimport {twrSignal} from \"./twrsignal.js\";\r\n\r\n\r\n// Canvas have a size that will be set based on the character width x height\r\n// The display size for a canvas will default to this size, but can be changed in the HTML/JS via\r\n// canvas.style.width = \"700px\";\r\n// canvas.style.height = \"500px\";\r\n\r\nexport interface ICanvasProps {\r\n\tcharWidth: number,\r\n\tcharHeight: number,\r\n\tforeColor: number,\r\n\tbackColor: number,\r\n widthInChars: number,\r\n heightInChars: number,\r\n canvasWidth:number,\r\n canvasHeight:number\r\n}\r\n\r\nenum D2DType {\r\n D2D_FILLRECT=1,\r\n D2D_FILLCHAR=5,\r\n D2D_SETLINEWIDTH=10,\r\n D2D_SETFILLSTYLERGBA=11,\r\n D2D_SETFONT=12,\r\n D2D_BEGINPATH=13,\r\n D2D_MOVETO=14,\r\n D2D_LINETO=15,\r\n D2D_FILL=16,\r\n D2D_STROKE=17,\r\n D2D_SETSTROKESTYLERGBA=18,\r\n D2D_ARC=19,\r\n D2D_STROKERECT=20,\r\n D2D_FILLTEXT=21,\r\n D2D_IMAGEDATA=22,\r\n D2D_PUTIMAGEDATA=23,\r\n D2D_BEZIERTO=24,\r\n D2D_MEASURETEXT=25,\r\n D2D_SAVE=26,\r\n D2D_RESTORE=27,\r\n D2D_CREATERADIALGRADIENT=28,\r\n D2D_SETCOLORSTOP=29,\r\n D2D_SETFILLSTYLEGRADIENT=30,\r\n D2D_RELEASEID=31,\r\n D2D_CREATELINEARGRADIENT=32,\r\n D2D_SETFILLSTYLE=33,\r\n D2D_SETSTROKESTYLE=34\r\n\r\n}\r\n\r\nexport type TCanvasProxyParams = [ICanvasProps, SharedArrayBuffer, SharedArrayBuffer];\r\n\r\nexport interface ICanvas {\r\n props: ICanvasProps,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TCanvasProxyParams,\r\n drawSeq: (ds:number)=>void,\r\n }\r\n \r\nexport class twrCanvas implements ICanvas {\r\n ctx:CanvasRenderingContext2D|undefined;\r\n props:ICanvasProps={charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight:0, canvasWidth:0};\r\n owner: twrWasmModuleBase;\r\n cmdCompleteSignal?:twrSignal;\r\n canvasKeys?: twrSharedCircularBuffer;\r\n precomputedObjects: { [index: number]: \r\n (ImageData | {mem8:Uint8Array, width:number, height:number}) |\r\n CanvasGradient\r\n };\r\n\r\n constructor(element:HTMLCanvasElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n const {forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas} = modParams; \r\n this.owner=modbase;\r\n this.props.widthInChars=modParams.windim[0];\r\n this.props.heightInChars=modParams.windim[1];\r\n\r\n if (!this.owner.isWasmModule) {\r\n this.cmdCompleteSignal=new twrSignal();\r\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n }\r\n\r\n this.precomputedObjects={};\r\n \r\n if (element) {\r\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\r\n let c=element.getContext(\"2d\");\r\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\r\n\r\n c.font = fontsize.toString()+\"px Courier New\";\r\n c.textBaseline=\"top\";\r\n const sampleText=\" \";\r\n const tm=c.measureText(sampleText);\r\n this.props.charWidth=Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\r\n let fM = c.measureText(\"X\"); \r\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\r\n\r\n if (!isd2dcanvas) {\r\n element.width=this.props.charWidth*this.props.widthInChars;\r\n element.height=this.props.charHeight*this.props.heightInChars;\r\n }\r\n\r\n this.props.canvasHeight=element.height;\r\n this.props.canvasWidth=element.width;\r\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\r\n\r\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\r\n let c2=element.getContext(\"2d\");\r\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\r\n this.ctx=c2;\r\n this.ctx.font = fontsize.toString()+\"px Courier New\";\r\n this.ctx.textBaseline=\"top\";\r\n\r\n c2.fillStyle=backcolor;\r\n this.props.backColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n c2.fillStyle=forecolor;\r\n this.props.foreColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n }\r\n\r\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\r\n\r\n //console.log(\"twrCanvas.constructor props: \", this.props);\r\n }\r\n\r\n isValid() {\r\n return !!this.ctx;\r\n }\r\n\r\n getProxyParams() : TCanvasProxyParams {\r\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\r\n }\r\n\r\n getProp(pn:number): number {\r\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n\r\n/* see draw2d.h for structs that match */\r\n\r\n drawSeq(ds:number) {\r\n //console.log(\"twr::Canvas enter drawSeq\");\r\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\r\n if (!this.ctx) return;\r\n\r\n let ins=this.owner.getLong(ds); /* ds->start */\r\n const lastins=this.owner.getLong(ds+4); /* ds->last */\r\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\r\n\r\n let next:number;\r\n //let insCount=0;\r\n\r\n while (1) {\r\n\r\n //insCount++;\r\n\r\n const type:D2DType=this.owner.getLong(ins+4); /* hdr->type */\r\n if (0/*type!=D2DType.D2D_FILLRECT*/) {\r\n console.log(\"ins\",ins)\r\n console.log(\"hdr.next\",this.owner.mem8[ins],this.owner.mem8[ins+1],this.owner.mem8[ins+2],this.owner.mem8[ins+3]);\r\n console.log(\"hdr.type\",this.owner.mem8[ins+4],this.owner.mem8[ins+5]);\r\n console.log(\"next 4 bytes\", this.owner.mem8[ins+6],this.owner.mem8[ins+7],this.owner.mem8[ins+8],this.owner.mem8[ins+9]);\r\n console.log(\"and 4 more \", this.owner.mem8[ins+10],this.owner.mem8[ins+11],this.owner.mem8[ins+12],this.owner.mem8[ins+13]);\r\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\r\n }\r\n switch (type) {\r\n case D2DType.D2D_FILLRECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.fillRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKERECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.strokeRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILLCHAR:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const c=this.owner.getShort(ins+24);\r\n let txt=String.fromCharCode(c);\r\n this.ctx.fillText(txt, x, y);\r\n }\r\n break;\r\n\r\n \r\n case D2DType.D2D_FILLTEXT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const str=this.owner.getString(this.owner.getLong(ins+24));\r\n\r\n //console.log(\"filltext \",x,y,str)\r\n \r\n this.ctx.fillText(str, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MEASURETEXT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n const tmidx=this.owner.getLong(ins+12);\r\n \r\n const tm=this.ctx.measureText(str);\r\n this.owner.setDouble(tmidx+0, tm.actualBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+8, tm.actualBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+16, tm.actualBoundingBoxLeft);\r\n this.owner.setDouble(tmidx+24, tm.actualBoundingBoxRight);\r\n this.owner.setDouble(tmidx+32, tm.fontBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+40, tm.fontBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+48, tm.width);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFONT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.font=str;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.fillStyle = cssColor;\r\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETSTROKESTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.fillStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETSTROKESTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETLINEWIDTH:\r\n {\r\n const width=this.owner.getShort(ins+8); \r\n this.ctx.lineWidth=width;\r\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MOVETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.moveTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_LINETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.lineTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEZIERTO:\r\n {\r\n const cp1x=this.owner.getDouble(ins+8);\r\n const cp1y=this.owner.getDouble(ins+16);\r\n const cp2x=this.owner.getDouble(ins+24);\r\n const cp2y=this.owner.getDouble(ins+32);\r\n const x=this.owner.getDouble(ins+40);\r\n const y=this.owner.getDouble(ins+48);\r\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEGINPATH:\r\n {\r\n this.ctx.beginPath();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILL:\r\n {\r\n this.ctx.fill();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SAVE:\r\n {\r\n this.ctx.save();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_RESTORE:\r\n {\r\n this.ctx.restore();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKE:\r\n {\r\n this.ctx.stroke();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_ARC:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const radius=this.owner.getDouble(ins+24);\r\n const startAngle=this.owner.getDouble(ins+32);\r\n const endAngle=this.owner.getDouble(ins+40);\r\n const counterClockwise= (this.owner.getLong(ins+48)!=0);\r\n\r\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_IMAGEDATA:\r\n {\r\n const start=this.owner.getLong(ins+8);\r\n const length=this.owner.getLong(ins+12);\r\n const width=this.owner.getLong(ins+16);\r\n const height=this.owner.getLong(ins+20);\r\n const id=this.owner.getLong(ins+24);\r\n\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\r\n\r\n if (this.owner.isWasmModule) {\r\n const z = new Uint8ClampedArray(this.owner.memory!.buffer, start, length);\r\n this.precomputedObjects[id]=new ImageData(z, width, height);\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory\r\n this.precomputedObjects[id]={mem8: new Uint8Array(this.owner.memory!.buffer, start, length), width:width, height:height};\r\n }\r\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_CREATERADIALGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const radius0=this.owner.getDouble(ins+24);\r\n const x1=this.owner.getDouble(ins+32);\r\n const y1=this.owner.getDouble(ins+40);\r\n const radius1=this.owner.getDouble(ins+48);\r\n const id= this.owner.getLong(ins+56);\r\n\r\n let gradient=this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_CREATELINEARGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const x1=this.owner.getDouble(ins+24);\r\n const y1=this.owner.getDouble(ins+32);\r\n const id= this.owner.getLong(ins+40);\r\n \r\n let gradient=this.ctx.createLinearGradient(x0, y0, x1, y1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETCOLORSTOP:\r\n {\r\n const id = this.owner.getLong(ins+8);\r\n const pos=this.owner.getLong(ins+12);\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+16));\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n gradient.addColorStop(pos, cssColor);\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n this.ctx.fillStyle=gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_RELEASEID:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (this.precomputedObjects[id])\r\n delete this.precomputedObjects[id];\r\n else\r\n console.log(\"warning: D2D_RELEASEID with undefined ID \",id);\r\n }\r\n break\r\n\r\n \r\n\r\n case D2DType.D2D_PUTIMAGEDATA:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n const dx=this.owner.getLong(ins+12);\r\n const dy=this.owner.getLong(ins+16);\r\n const dirtyX=this.owner.getLong(ins+20);\r\n const dirtyY=this.owner.getLong(ins+24);\r\n const dirtyWidth=this.owner.getLong(ins+28);\r\n const dirtyHeight=this.owner.getLong(ins+32);\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \"+id);\r\n\r\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\r\n\r\n let imgData:ImageData;\r\n if (this.owner.isWasmModule) {\r\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\r\n imgData=this.precomputedObjects[id] as ImageData;\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\r\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\r\n const z = this.precomputedObjects[id] as {mem8:Uint8Array, width:number, height:number}; // Uint8Array\r\n const ca=Uint8ClampedArray.from(z.mem8); // shallow copy\r\n imgData=new ImageData(ca, z.width, z.height);\r\n }\r\n \r\n if (dirtyWidth==0 && dirtyHeight==0) {\r\n this.ctx.putImageData(imgData, dx, dy);\r\n }\r\n else {\r\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\r\n }\r\n }\r\n break;\r\n\r\n default:\r\n throw new Error (\"unimplemented or unknown Sequence Type in drawSeq: \"+type);\r\n }\r\n next=this.owner.getLong(ins); /* hdr->next */\r\n if (next==0) {\r\n if (ins!=lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\r\n break;\r\n }\r\n ins=next;\r\n }\r\n\r\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\r\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\r\n }\r\n}\r\n\r\nexport class twrCanvasProxy implements ICanvas {\r\n canvasKeys: twrSharedCircularBuffer;\r\n drawCompleteSignal:twrSignal;\r\n props: ICanvasProps;\r\n owner: twrWasmModuleBase;\r\n\r\n constructor(params:TCanvasProxyParams, owner:twrWasmModuleBase) {\r\n const [props, signalBuffer, canvasKeysBuffer] = params;\r\n this.drawCompleteSignal = new twrSignal(signalBuffer);\r\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\r\n this.props=props;\r\n this.owner=owner;\r\n\r\n //console.log(\"Create New twrCanvasProxy: \",this.props)\r\n\r\n }\r\n\r\n charIn() { \r\n //ctx.commit(); not avail in chrome\r\n \r\n //postMessage([\"debug\", 'x']);\r\n \r\n return this.canvasKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.canvasKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n getProp(pn:number): number {\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n \r\n drawSeq(ds:number) {\r\n this.drawCompleteSignal.reset();\r\n postMessage([\"drawseq\", [ds]]);\r\n this.drawCompleteSignal.wait();\r\n }\r\n}\r\n","//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar twrSignalState;\n(function (twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})(twrSignalState || (twrSignalState = {}));\n;\nexport class twrSignal {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window valid\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == twrSignalState.WAITING) {\n //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\n //console.log(\"released...\");\n }\n }\n isSignaled() {\n return this.buf[0] == twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = twrSignalState.WAITING;\n }\n}\n//# sourceMappingURL=twrsignal.js.map","//\r\n// This class implements a simple signal/wait mechanism\r\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\r\n//\r\n\r\nenum twrSignalState {\r\n WAITING=0,\r\n SIGNALED=1\r\n};\r\n\r\nexport class twrSignal {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n\r\n \tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window valid\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) \r\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[0]=twrSignalState.WAITING;\r\n\t}\r\n\r\n\tsignal() {\r\n this.buf[0]=twrSignalState.SIGNALED; \r\n //console.log(\"about to signal\");\r\n Atomics.notify(this.buf, 0); \r\n\t}\r\n\r\n wait() {\r\n if (this.buf[0]==twrSignalState.WAITING) {\r\n //console.log(\"waiting...\");\r\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\r\n //console.log(\"released...\");\r\n\r\n }\r\n\t}\r\n isSignaled():boolean {\r\n return this.buf[0]==twrSignalState.SIGNALED;\r\n }\r\n\r\n reset() {\r\n this.buf[0]=twrSignalState.WAITING;\r\n }\r\n}\r\n","export function twrTimeImpl() {\n return Date.now();\n}\n//# sourceMappingURL=twrdate.js.map","\r\nexport function twrTimeImpl() {\r\n\r\n return Date.now();\r\n\r\n}","import { twrDebugLogImpl } from \"./twrdebug.js\";\nimport { twrWasmModuleInJSMain } from \"./twrmodjsmain.js\";\nimport { twrWaitingCalls } from \"./twrwaitingcalls.js\";\nimport whatkey from \"whatkey\";\nexport class twrWasmModuleAsync extends twrWasmModuleInJSMain {\n myWorker;\n malloc;\n loadWasmResolve;\n loadWasmReject;\n callCResolve;\n callCReject;\n initLW = false;\n waitingcalls;\n constructor(opts) {\n super(opts);\n this.malloc = (size) => { throw new Error(\"Error - un-init malloc called.\"); };\n if (!window.Worker)\n throw new Error(\"This browser doesn't support web workers.\");\n this.myWorker = new Worker(new URL('twrmodworker.js', import.meta.url), { type: \"module\" });\n this.myWorker.onmessage = this.processMsg.bind(this);\n }\n // overrides base implementation\n async loadWasm(pathToLoad) {\n if (this.initLW)\n throw new Error(\"twrWasmAsyncModule::loadWasm can only be called once per twrWasmAsyncModule instance\");\n this.initLW = true;\n return new Promise((resolve, reject) => {\n this.loadWasmResolve = resolve;\n this.loadWasmReject = reject;\n this.malloc = (size) => {\n return this.callCImpl(\"twr_malloc\", [size]);\n };\n this.waitingcalls = new twrWaitingCalls(); // handle's calls that cross the worker thread - main js thread boundary\n let canvas;\n if (this.d2dcanvas.isValid())\n canvas = this.d2dcanvas;\n else\n canvas = this.iocanvas;\n const modWorkerParams = {\n divProxyParams: this.iodiv.getProxyParams(),\n canvasProxyParams: canvas.getProxyParams(),\n waitingCallsProxyParams: this.waitingcalls.getProxyParams(),\n };\n const urlToLoad = new URL(pathToLoad, document.URL);\n const startMsg = { urlToLoad: urlToLoad.href, modWorkerParams: modWorkerParams, modParams: this.modParams };\n this.myWorker.postMessage(['startup', startMsg]);\n });\n }\n async callC(params) {\n const cparams = await this.preCallC(params); // will also validate params[0]\n return this.callCImpl(params[0], cparams);\n }\n async callCImpl(fname, cparams = []) {\n return new Promise((resolve, reject) => {\n this.callCResolve = resolve;\n this.callCReject = reject;\n this.myWorker.postMessage(['callC', fname, cparams]);\n });\n }\n // this function should be called from HTML \"keydown\" event from
\n keyDownDiv(ev) {\n if (!this.iodiv || !this.iodiv.divKeys)\n throw new Error(\"unexpected undefined twrWasmAsyncModule.divKeys\");\n this.iodiv.divKeys.write(whatkey(ev).char.charCodeAt(0));\n }\n // this function should be called from HTML \"keydown\" event from \n keyDownCanvas(ev) {\n if (!this.iocanvas || !this.iocanvas.canvasKeys)\n throw new Error(\"unexpected undefined twrWasmAsyncModule.canvasKeys\");\n this.iocanvas.canvasKeys.write(whatkey(ev).char.charCodeAt(0));\n }\n processMsg(event) {\n const msgType = event.data[0];\n const d = event.data[1];\n //console.log(\"twrWasmAsyncModule - got message: \"+event.data)\n switch (msgType) {\n case \"divout\":\n if (this.iodiv.isValid())\n this.iodiv.charOut(d);\n else\n console.log('error - msg divout received but iodiv is undefined.');\n break;\n case \"debug\":\n twrDebugLogImpl(d);\n break;\n case \"drawseq\":\n {\n //console.log(\"twrModAsync got message drawseq\");\n const [ds] = d;\n if (this.iocanvas.isValid())\n this.iocanvas.drawSeq(ds);\n else if (this.d2dcanvas.isValid())\n this.d2dcanvas.drawSeq(ds);\n else\n throw new Error('msg drawseq received but canvas is undefined.');\n break;\n }\n case \"setmemory\":\n this.memory = d;\n if (!this.memory)\n throw new Error(\"unexpected error - undefined memory in startupOkay msg\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n //console.log(\"memory set\",this.mem8.length);\n break;\n case \"startupFail\":\n if (this.loadWasmReject)\n this.loadWasmReject(d);\n else\n throw new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmReject)\");\n break;\n case \"startupOkay\":\n if (this.loadWasmResolve)\n this.loadWasmResolve(undefined);\n else\n throw new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmResolve)\");\n break;\n case \"callCFail\":\n if (this.callCReject)\n this.callCReject(d);\n else\n throw new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined callCReject)\");\n break;\n case \"callCOkay\":\n if (this.callCResolve)\n this.callCResolve(d);\n else\n throw new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined callCResolve)\");\n break;\n default:\n if (!this.waitingcalls)\n throw new Error(\"internal error: this.waitingcalls undefined.\");\n if (!this.waitingcalls.processMessage(msgType, d))\n throw new Error(\"twrWasmAsyncModule - unknown and unexpected msgType: \" + msgType);\n }\n }\n}\n//# sourceMappingURL=twrmodasync.js.map","import {IModOpts, IModParams, IModInWorkerParams} from \"./twrmodbase.js\";\r\nimport {twrDebugLogImpl} from \"./twrdebug.js\";\r\nimport {twrWasmModuleInJSMain} from \"./twrmodjsmain.js\"\r\nimport {twrWaitingCalls} from \"./twrwaitingcalls.js\"\r\nimport {twrCanvas} from \"./twrcanvas.js\";\r\n\r\nimport whatkey from \"whatkey\";\r\n\r\nexport type TAsyncModStartupMsg = {\r\n\turlToLoad: string,\r\n\tmodWorkerParams: IModInWorkerParams,\r\n\tmodParams: IModParams \r\n};\r\n\t\t\r\nexport class twrWasmModuleAsync extends twrWasmModuleInJSMain {\r\n\tmyWorker:Worker;\r\n\tmalloc:(size:number)=>Promise;\r\n\tloadWasmResolve?: (value: void) => void;\r\n\tloadWasmReject?: (reason?: any) => void;\r\n\tcallCResolve?: (value: unknown) => void;\r\n\tcallCReject?: (reason?: any) => void;\r\n\tinitLW=false;\r\n\twaitingcalls?:twrWaitingCalls;\r\n\r\n\r\n\tconstructor(opts?:IModOpts) {\r\n\t\tsuper(opts);\r\n\r\n\t\tthis.malloc=(size:number)=>{throw new Error(\"Error - un-init malloc called.\")};\r\n\r\n\t\tif (!window.Worker) throw new Error(\"This browser doesn't support web workers.\");\r\n\t\tthis.myWorker = new Worker(new URL('twrmodworker.js', import.meta.url), {type: \"module\" });\r\n\t\tthis.myWorker.onmessage= this.processMsg.bind(this);\r\n\t}\r\n\r\n\t// overrides base implementation\r\n\tasync loadWasm(pathToLoad:string) {\r\n\t\tif (this.initLW) \tthrow new Error(\"twrWasmAsyncModule::loadWasm can only be called once per twrWasmAsyncModule instance\");\r\n\t\tthis.initLW=true;\r\n\r\n\t\treturn new Promise((resolve, reject)=>{\r\n\t\t\tthis.loadWasmResolve=resolve;\r\n\t\t\tthis.loadWasmReject=reject;\r\n\r\n\t\t\tthis.malloc = (size:number) => {\r\n\t\t\t\treturn this.callCImpl(\"twr_malloc\", [size]) as Promise;\r\n\t\t\t}\r\n\r\n\t\t\tthis.waitingcalls=new twrWaitingCalls(); // handle's calls that cross the worker thread - main js thread boundary\r\n\r\n\t\t\tlet canvas:twrCanvas;\r\n\t\t\tif (this.d2dcanvas.isValid()) canvas=this.d2dcanvas;\r\n\t\t\telse canvas=this.iocanvas;\r\n\r\n\t\t\tconst modWorkerParams={\r\n\t\t\t\tdivProxyParams: this.iodiv.getProxyParams(), \r\n\t\t\t\tcanvasProxyParams: canvas.getProxyParams(),\r\n\t\t\t\twaitingCallsProxyParams: this.waitingcalls.getProxyParams(),\r\n\t\t\t};\r\n\t\t\tconst urlToLoad = new URL(pathToLoad, document.URL);\r\n\t\t\tconst startMsg:TAsyncModStartupMsg={ urlToLoad: urlToLoad.href, modWorkerParams: modWorkerParams, modParams: this.modParams};\r\n\t\t\tthis.myWorker.postMessage(['startup', startMsg]);\r\n\t\t});\r\n\t}\r\n\r\n\tasync callC(params:[string, ...(string|number|Uint8Array)[]]) {\r\n\t\tconst cparams=await this.preCallC(params); // will also validate params[0]\r\n\t\treturn this.callCImpl(params[0], cparams);\r\n\t}\t\r\n\r\n\tasync callCImpl(fname:string, cparams:number[]=[]) {\r\n\t\treturn new Promise((resolve, reject)=>{\r\n\t\t\tthis.callCResolve=resolve;\r\n\t\t\tthis.callCReject=reject;\r\n\t\t\tthis.myWorker.postMessage(['callC', fname, cparams]);\r\n\t\t});\r\n\t}\r\n\t\r\n\t// this function should be called from HTML \"keydown\" event from
\r\n\tkeyDownDiv(ev:KeyboardEvent) {\r\n\t\tif (!this.iodiv || !this.iodiv.divKeys) throw new Error(\"unexpected undefined twrWasmAsyncModule.divKeys\");\r\n\t\tthis.iodiv.divKeys.write(whatkey(ev).char.charCodeAt(0));\r\n\t}\r\n\r\n\t// this function should be called from HTML \"keydown\" event from \r\n\tkeyDownCanvas(ev:KeyboardEvent) {\r\n\t\tif (!this.iocanvas || !this.iocanvas.canvasKeys) throw new Error(\"unexpected undefined twrWasmAsyncModule.canvasKeys\");\r\n\t\tthis.iocanvas.canvasKeys.write(whatkey(ev).char.charCodeAt(0));\r\n\t}\r\n\r\n\tprocessMsg(event: MessageEvent) {\r\n\t\tconst msgType=event.data[0];\r\n\t\tconst d=event.data[1];\r\n\r\n\t\t//console.log(\"twrWasmAsyncModule - got message: \"+event.data)\r\n\r\n\t\tswitch (msgType) {\r\n\t\t\tcase \"divout\":\r\n\t\t\t\tif (this.iodiv.isValid())\r\n\t\t\t\t\tthis.iodiv.charOut(d);\r\n\t\t\t\telse\r\n\t\t\t\t\tconsole.log('error - msg divout received but iodiv is undefined.')\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"debug\":\r\n\t\t\t\ttwrDebugLogImpl(d);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"drawseq\":\r\n\t\t\t{\r\n\t\t\t\t//console.log(\"twrModAsync got message drawseq\");\r\n\t\t\t\tconst [ds] = d;\r\n\t\t\t\tif (this.iocanvas.isValid())\r\n\t\t\t\t\tthis.iocanvas.drawSeq(ds);\r\n\t\t\t\telse if (this.d2dcanvas.isValid())\r\n\t\t\t\t\tthis.d2dcanvas.drawSeq(ds);\r\n\t\t\t\telse\r\n\t\t\t\t\tthrow new Error('msg drawseq received but canvas is undefined.')\r\n\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\t\tcase \"setmemory\":\r\n\t\t\t\tthis.memory=d;\r\n\t\t\t\tif (!this.memory) throw new Error(\"unexpected error - undefined memory in startupOkay msg\");\r\n\t\t\t\tthis.mem8 = new Uint8Array(this.memory.buffer);\r\n\t\t\t\tthis.mem32 = new Uint32Array(this.memory.buffer);\r\n\t\t\t\tthis.memD = new Float64Array(this.memory.buffer);\r\n\t\t\t\t//console.log(\"memory set\",this.mem8.length);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"startupFail\":\r\n\t\t\t\tif (this.loadWasmReject)\r\n\t\t\t\t\tthis.loadWasmReject(d);\r\n\t\t\t\telse\r\n\t\t\t\t\tthrow new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmReject)\");\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"startupOkay\":\r\n\r\n\t\t\t\tif (this.loadWasmResolve)\r\n\t\t\t\t\tthis.loadWasmResolve(undefined);\r\n\t\t\t\telse\r\n\t\t\t\t\tthrow new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmResolve)\");\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"callCFail\":\r\n\t\t\t\tif (this.callCReject)\r\n\t\t\t\t\tthis.callCReject(d);\r\n\t\t\t\telse\r\n\t\t\t\t\tthrow new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined callCReject)\");\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"callCOkay\":\r\n\t\t\t\tif (this.callCResolve)\r\n\t\t\t\t\tthis.callCResolve(d);\r\n\t\t\t\telse\r\n\t\t\t\t\tthrow new Error(\"twrWasmAsyncModule.processMsg unexpected error (undefined callCResolve)\");\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tdefault:\r\n\t\t\t\tif (!this.waitingcalls) throw new Error (\"internal error: this.waitingcalls undefined.\")\r\n\t\t\t\tif (!this.waitingcalls.processMessage(msgType, d))\r\n\t\t\t\t\tthrow new Error(\"twrWasmAsyncModule - unknown and unexpected msgType: \"+msgType);\r\n\t\t}\r\n\t}\r\n}\r\n","import { twrSignal } from \"./twrsignal.js\";\nimport { twrTimeImpl } from \"./twrdate.js\";\n// This class is used in the Main JS thread \nexport class twrWaitingCalls {\n callCompleteSignal;\n parameters;\n constructor() {\n this.callCompleteSignal = new twrSignal();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(() => {\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = twrTimeImpl();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [this.callCompleteSignal.sharedArray, this.parameters.buffer];\n }\n processMessage(msgType, data) {\n switch (msgType) {\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\n// This class is used in the worker thread \nexport class twrWaitingCallsProxy {\n callCompleteSignal;\n parameters;\n constructor(params) {\n this.callCompleteSignal = new twrSignal(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\"sleep\", [ms]]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\"time\"]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n//# sourceMappingURL=twrwaitingcalls.js.map","import { twrSignal } from \"./twrsignal.js\";\r\nimport {twrTimeImpl} from \"./twrdate.js\"\r\n\r\n// These classes are used to proxy a call across the worker thread - main thread boundary and wait for the result\r\n\r\nexport type TWaitingCallsProxyParams = [SharedArrayBuffer, SharedArrayBuffer]; // twrSignal, parameters \r\n\r\n// This class is used in the Main JS thread \r\nexport class twrWaitingCalls {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor() {\r\n\t\tthis.callCompleteSignal=new twrSignal();\r\n\t\tthis.parameters=new Uint32Array(new SharedArrayBuffer(4));\r\n\t}\r\n\r\n\tprivate startSleep(ms:number) {\r\n\r\n\t\tsetTimeout(()=>{\r\n\t\t\tthis.callCompleteSignal.signal();\r\n\t\t}, ms);\r\n\t\t\r\n\t}\r\n\r\n\tprivate time() {\r\n\t\tconst ms=twrTimeImpl();\r\n\t\tthis.parameters[0]=ms;\r\n\t\tthis.callCompleteSignal.signal();\r\n\t}\r\n\r\n\tgetProxyParams():TWaitingCallsProxyParams {\r\n\t\treturn [this.callCompleteSignal.sharedArray, this.parameters.buffer as SharedArrayBuffer];\t\r\n\t}\r\n\r\n\tprocessMessage(msgType:string, data:any[]):boolean {\r\n\t\tswitch (msgType) {\r\n\t\t\tcase \"sleep\":\r\n\t\t\t\tconst [ms] = data;\r\n\t\t\t\tthis.startSleep(ms);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"time\":\r\n\t\t\t\tthis.time();\r\n\t\t\t\tbreak;\r\n\t\t\t\r\n\t\t\tdefault:\r\n\t\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\treturn true;\r\n\t}\r\n\r\n}\r\n\r\n// This class is used in the worker thread \r\nexport class twrWaitingCallsProxy {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor(params:TWaitingCallsProxyParams) {\r\n\t\tthis.callCompleteSignal=new twrSignal(params[0]);\r\n\t\tthis.parameters=new Uint32Array(params[1]);\r\n\t}\r\n\r\n\tsleep(ms:number) {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"sleep\", [ms]]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t}\r\n\r\n\ttime() {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"time\"]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t\treturn this.parameters[0];\r\n\t}\r\n\r\n}\r\n","const keycodeCtrlKeys = {\n 'a': 'selectAll',\n 'c': 'copy',\n 's': 'save',\n 'v': 'paste',\n 'x': 'cut',\n 'y': 'redo',\n 'z': 'undo'\n};\n\nconst keycodeShiftedKeys = {\n '/': '?',\n '.': '>',\n ',': '<',\n '\\'': '\\\"',\n ';': ':',\n '[': '{',\n ']': '}',\n '\\\\': '|',\n '`': '~',\n '=': '+',\n '-': '_',\n '1': '!',\n '2': '@',\n '3': '#',\n '4': '$',\n '5': '%',\n '6': '^',\n '7': '&',\n '8': '*',\n '9': '(',\n '0': ')',\n 'a': 'A',\n 'b': 'B',\n 'c': 'C',\n 'd': 'D',\n 'e': 'E',\n 'f': 'F',\n 'g': 'G',\n 'h': 'H',\n 'i': 'I',\n 'j': 'J',\n 'k': 'K',\n 'l': 'L',\n 'm': 'M',\n 'n': 'N',\n 'o': 'O',\n 'p': 'P',\n 'q': 'q',\n 'r': 'R',\n 's': 'S',\n 't': 'T',\n 'u': 'U',\n 'v': 'V',\n 'w': 'W',\n 'x': 'X',\n 'y': 'Y',\n 'z': 'Z'\n};\n\nconst keyCodeUnshiftedKeys = {};\nfor (const x in keycodeShiftedKeys) {\n const shiftedKey = keycodeShiftedKeys[x];\n keyCodeUnshiftedKeys[shiftedKey] = x;\n}\n\nconst keydownKeycodeDictionary = {\n 0: '\\\\',\n\n 8: 'backspace',\n 9: 'tab',\n\n 12: 'num',\n 13: 'enter',\n\n 16: 'shift',\n 17: 'ctrl',\n 18: 'alt', // aka 'option'\n 19: 'pause', // or sometimes 'break'?\n 20: 'caps',\n\n 27: 'esc',\n\n 32: ' ',\n 33: 'pageup',\n 34: 'pagedown',\n 35: 'end',\n 36: 'home',\n 37: 'left',\n 38: 'up',\n 39: 'right',\n 40: 'down',\n\n 44: 'print',\n 45: 'insert',\n 46: 'delete',\n\n 48: '0',\n 49: '1',\n 50: '2',\n 51: '3',\n 52: '4',\n 53: '5',\n 54: '6',\n 55: '7',\n 56: '8',\n 57: '9',\n\n 59: ';',\n\n 61: '=',\n\n 65: 'a',\n 66: 'b',\n 67: 'c',\n 68: 'd',\n 69: 'e',\n 70: 'f',\n 71: 'g',\n 72: 'h',\n 73: 'i',\n 74: 'j',\n 75: 'k',\n 76: 'l',\n 77: 'm',\n 78: 'n',\n 79: 'o',\n 80: 'p',\n 81: 'q',\n 82: 'r',\n 83: 's',\n 84: 't',\n 85: 'u',\n 86: 'v',\n 87: 'w',\n 88: 'x',\n 89: 'y',\n 90: 'z',\n 91: 'meta', // 'left window key'\n 92: 'meta', // 'right window key'\n 93: 'meta', // 'select key'\n\n 96: 'num0',\n 97: 'num1',\n 98: 'num2',\n 99: 'num3',\n 100: 'num4',\n 101: 'num5',\n 102: 'num6',\n 103: 'num7',\n 104: 'num8',\n 105: 'num9',\n 106: '*',\n 107: '+',\n 108: 'num_enter',\n 109: 'num_subtract',\n 110: 'num_decimal',\n 111: 'num_divide',\n 112: 'f1',\n 113: 'f2',\n 114: 'f3',\n 115: 'f4',\n 116: 'f5',\n 117: 'f6',\n 118: 'f7',\n 119: 'f8',\n 120: 'f9',\n 121: 'f10',\n 122: 'f11',\n 123: 'f12',\n 124: 'print',\n\n 144: 'num', // num lock\n 145: 'scroll', // scroll lock\n\n 173: '-',\n\n 186: ';',\n 187: '=',\n 188: ',',\n 189: '-',\n 190: '.',\n 191: '/',\n 192: '`',\n 219: '[',\n 220: '\\\\',\n 221: ']',\n 222: '\\'',\n 223: '`',\n 224: 'cmd',\n 225: 'alt',\n\n 57392: 'ctrl',\n 63289: 'num'\n};\n\nconst keypressCharacterMapOverides = {\n '\\r': 'enter'\n};\nconst keypressCharacterMap = JSON.parse(JSON.stringify(keydownKeycodeDictionary));\nfor (const key of Object.keys(keypressCharacterMapOverides)) {\n keypressCharacterMap[key] = keypressCharacterMapOverides[key];\n}\n\nconst keydownCharacterMap = {\n 'num_subtract': '-',\n 'num_enter': '\\n',\n 'num_decimal': '.',\n 'num_divide': '/',\n 'enter': '\\n',\n 'tab': '\\t',\n 'backspace': '\\b'\n};\n\nexport const unprintableKeys = [\n 'backspace','enter','tab','num',\n 'shift','meta','alt','pause','caps','esc',\n 'pageup','pagedown','end','home',\n 'left','up','right','down',\n 'print','insert','delete','cmd',\n 'f1','f2','f3','f4','f5','f6','f7','f8','f9','f10','f11','f12',\n 'scroll','ctrl'\n];\n\nconst validEvents = ['keydown', 'keyup'];\n\nconst isMobile = () => {\n const ua = navigator.userAgent;\n const mobile = /IEMobile|Windows Phone|Lumia/i.test(ua) ? 'w' : /iPhone|iP[oa]d/.test(ua) ? 'i' : /Android/.test(ua) ? 'a' : /BlackBerry|PlayBook|BB10/.test(ua) ? 'b' : /Mobile Safari/.test(ua) ? 's' : /webOS|Mobile|Tablet|Opera Mini|\\bCrMo\\/|Opera Mobi/i.test(ua) ? 1 : 0;\n return mobile !== 0;\n};\n\nfunction getKeypressKeycodeValue(charcode) {\n const character = String.fromCharCode(charcode);\n if (isMobile()) { return character }\n if (character in keyCodeUnshiftedKeys) {\n return keyCodeUnshiftedKeys[character];\n } else if (character in keypressCharacterMap) {\n return keypressCharacterMap[character];\n }\n return character;\n}\n\nexport default function(event) {\n let key;\n if (event.type === 'keypress' && !isMobile()) {\n key = getKeypressKeycodeValue(event.charCode);\n } else if (event.type === 'keypress' && isMobile()) {\n key = getKeypressKeycodeValue(event.keyCode);\n } else if (validEvents.indexOf(event.type) > -1) {\n if (event.which !== undefined) {\n key = keydownKeycodeDictionary[event.which];\n } else if (event.keyCode !== undefined) {\n key = keydownKeycodeDictionary[event.keyCode];\n } else {\n key = 'enter';\n }\n } else {\n return false;\n }\n\n let char = key;\n if (event.shiftKey && key in keycodeShiftedKeys) {\n char = keycodeShiftedKeys[key];\n } else if (event.ctrlKey && key in keycodeCtrlKeys) {\n char = keycodeCtrlKeys[key];\n } else if (key in keydownCharacterMap) {\n char = keydownCharacterMap[key];\n }\n\n return {\n char,\n key\n };\n}\n","let workerURL = require('./helpers/get-worker-url');\nlet url = new __parcel__URL__(\"twrmodworker.2165e649.js\");\nmodule.exports = workerURL(url.toString(), url.origin, true);","\"use strict\";\n\nmodule.exports = function (workerUrl, origin, isESM) {\n if (origin === self.location.origin) {\n // If the worker bundle's url is on the same origin as the document,\n // use the worker bundle's own url.\n return workerUrl;\n } else {\n // Otherwise, create a blob URL which loads the worker bundle with `importScripts`.\n var source = isESM ? 'import ' + JSON.stringify(workerUrl) + ';' : 'importScripts(' + JSON.stringify(workerUrl) + ');';\n return URL.createObjectURL(new Blob([source], {\n type: 'application/javascript'\n }));\n }\n};","require('./helpers/bundle-manifest').register(new __parcel__URL__(\"\").toString(),JSON.parse(\"[\\\"kjr0c\\\",\\\"index.528b9ee5.js\\\",\\\"cTHdP\\\",\\\"twrmodworker.2165e649.js\\\"]\"));"],"names":["$parcel$export","e","n","v","s","Object","defineProperty","get","set","enumerable","configurable","$parcel$global","globalThis","$parcel$modules","$parcel$inits","parcelRequire","id","exports","init","module","call","err","Error","code","register","parcelRegister","$ae99f86db55f9acd$export$6503ec6e8aabbaf","$ae99f86db55f9acd$var$mapping","Map","baseUrl","manifest","i","length","path","twrWasmModule","twrWasmModuleAsync","$251237c7cf144eb4$export$3298af74d75b595c","$9FI45","$aGUWE","$lsUl2","twrWasmModuleInJSMain","malloc","constructor","opts","canvas","size","d2dcanvas","isValid","iocanvas","modParams","imports","twrDebugLog","twrDebugLogImpl","twrTime","twrTimeImpl","twrDivCharOut","iodiv","charOut","bind","twrCanvasGetProp","getProp","twrCanvasDrawSeq","drawSeq","twrCanvasCharIn","null","twrCanvasInkey","twrDivCharIn","twrSleep","twrSin","Math","sin","twrCos","cos","twrTan","tan","twrFAbs","abs","twrACos","acos","twrASin","asin","twrATan","atan","twrExp","exp","twrFloor","floor","twrCeil","ceil","twrFMod","x","y","twrLog","log","twrPow","pow","twrSqrt","sqrt","twrTrunc","trunc","twrDtoa","floatUtil","dtoa","twrToFixed","toFixed","twrToExponential","toExponential","twrAtod","atod","twrFcvtS","fcvtS","inval","$70aa1fbe63deeaae$export$16b4216ec014493d","$70aa1fbe63deeaae$var$logline","char","console","String","fromCharCode","$7c89ffbd74fdad5b$export$2366c14363f3adb5","$fDEU7","$5hO33","$5LsZ0","twrWasmModuleBase","isWasmModule","document","eiodiv","getElementById","eiocanvas","ed2dcanvas","stdio","isd2dcanvas","windim","styleIsDefault","backcolor","forecolor","fontsize","undefined","twrDiv","twrCanvas","divLog","params","stringOut","toString","$b62a3a4493ce3043$export$dd376bb3f10f6896","$ghrAp","div","divKeys","CURSOR","cursorOn","lastChar","extraBR","owner","element","modbase","twrSharedCircularBuffer","style","backgroundColor","color","font","getProxyParams","sharedArray","ch","innerHTML","slice","p","getBoundingClientRect","window","scrollTo","height","focus","str","charCodeAt","$bda3a1eb26e567b5$export$a01cca24f011573a","buf","sa","crossOriginIsolated","location","protocol","SharedArrayBuffer","Int32Array","write","Atomics","notify","read","isEmpty","readWait","rdptr","wait","$3d955ccf8fb141b7$export$c83a0a3bffe07399","$2Xdsi","memory","mem8","mem32","memD","isWorker","Uint8Array","Uint32Array","Float64Array","twrFloatUtil","loadWasm","pathToLoad","response","fetch","ok","statusText","wasmBytes","arrayBuffer","allimports","instance","WebAssembly","instantiate","env","buffer","ArrayBuffer","postMessage","Promise","resolve","m","twr_malloc","stack","twrInit","twr_wasm_init","callC","cparams","preCallC","retval","callCImpl","postCallC","fname","f","Array","ci","putString","URL","r","fetchAndPutURL","putArrayBuffer","u8","j","copyString","buffer_size","strIndex","putU8","u8a","dest","ab","fnin","src","getLong","idx","idx32","setLong","value","getDouble","idx64","setDouble","getShort","getString","len","sout","getU8Arr","rv","dataptr","getU32Arr","$226b87658a7c840f$export$918ffb7e046a537b","mod","strptr","upper","trimStart","toUpperCase","Number","POSITIVE_INFINITY","NEGATIVE_INFINITY","parseFloat","replaceAll","max_precision","toPrecision","decdigits","sizeInBytes","fracpart_numdigits","dec","sign","digits","decpos","isNaN","isFinite","intPart","fracPart","roundValStr","split","replace","$4327d2f23f608609$export$2f298dd69cef3c34","D2DType","$4327d2f23f608609$var$D2DType","$47Wdp","ctx","props","charWidth","charHeight","foreColor","backColor","widthInChars","heightInChars","canvasHeight","canvasWidth","cmdCompleteSignal","canvasKeys","precomputedObjects","twrSignal","getContext","c","textBaseline","sampleText","tm","measureText","width","fM","fontBoundingBoxAscent","fontBoundingBoxDescent","c2","fillStyle","pn","propName","ds","next","ins","lastins","type","D2D_FILLRECT","w","h","fillRect","D2D_STROKERECT","strokeRect","D2D_FILLCHAR","txt","fillText","D2D_FILLTEXT","D2D_MEASURETEXT","tmidx","actualBoundingBoxAscent","actualBoundingBoxDescent","actualBoundingBoxLeft","actualBoundingBoxRight","D2D_SETFONT","D2D_SETFILLSTYLERGBA","cssColor","D2D_SETSTROKESTYLERGBA","strokeStyle","D2D_SETFILLSTYLE","D2D_SETSTROKESTYLE","D2D_SETLINEWIDTH","lineWidth","D2D_MOVETO","moveTo","D2D_LINETO","lineTo","D2D_BEZIERTO","cp1x","cp1y","cp2x","cp2y","bezierCurveTo","D2D_BEGINPATH","beginPath","D2D_FILL","fill","D2D_SAVE","save","D2D_RESTORE","restore","D2D_STROKE","stroke","D2D_ARC","radius","startAngle","endAngle","counterClockwise","arc","D2D_IMAGEDATA","start","z","Uint8ClampedArray","ImageData","D2D_CREATERADIALGRADIENT","x0","y0","radius0","x1","y1","radius1","gradient","createRadialGradient","D2D_CREATELINEARGRADIENT","createLinearGradient","D2D_SETCOLORSTOP","pos","addColorStop","D2D_SETFILLSTYLEGRADIENT","D2D_RELEASEID","D2D_PUTIMAGEDATA","imgData","dx","dy","dirtyX","dirtyY","dirtyWidth","dirtyHeight","from","putImageData","signal","$3014f93b5ceae902$var$twrSignalState","twrSignalState","$3014f93b5ceae902$export$e37a7b7b851b97f3","WAITING","SIGNALED","isSignaled","reset","$fa07ea1a08a5d6be$export$78724cdcf7ebea1d","Date","now","$8227a48f951b1cca$export$678fe6e36ab9a6ff","$2vKdq","$bqeaG","myWorker","loadWasmResolve","loadWasmReject","callCResolve","callCReject","initLW","waitingcalls","Worker","onmessage","processMsg","reject","twrWaitingCalls","modWorkerParams","divProxyParams","canvasProxyParams","waitingCallsProxyParams","startMsg","urlToLoad","href","keyDownDiv","ev","default","keyDownCanvas","event","msgType","data","d","processMessage","$1d42537681d02be3$export$9e37856d1928d388","callCompleteSignal","parameters","startSleep","ms","setTimeout","time","$850d1d8f0aa1ea8f$export$2e2bcd8739ae039","$850d1d8f0aa1ea8f$var$keycodeCtrlKeys","$850d1d8f0aa1ea8f$var$keycodeShiftedKeys","$850d1d8f0aa1ea8f$var$keyCodeUnshiftedKeys","$850d1d8f0aa1ea8f$var$keydownKeycodeDictionary","$850d1d8f0aa1ea8f$var$keypressCharacterMapOverides","$850d1d8f0aa1ea8f$var$keypressCharacterMap","JSON","parse","stringify","key","keys","$850d1d8f0aa1ea8f$var$keydownCharacterMap","$850d1d8f0aa1ea8f$var$validEvents","$850d1d8f0aa1ea8f$var$isMobile","ua","navigator","userAgent","mobile","test","$850d1d8f0aa1ea8f$var$getKeypressKeycodeValue","charcode","character","keyCode","indexOf","which","charCode","shiftKey","ctrlKey","$hoqmg","$7e9081fcee88b005$var$url","url","origin","workerUrl","isESM","self","source","createObjectURL","Blob"],"version":3,"file":"index.528b9ee5.js.map"} \ No newline at end of file diff --git a/azure/examples/function-calls/dist/index.html b/azure/examples/function-calls/dist/index.html index 424c209c..0119cafd 100644 --- a/azure/examples/function-calls/dist/index.html +++ b/azure/examples/function-calls/dist/index.html @@ -5,4 +5,4 @@ "whatkey": "../../lib-js/whatkey.js" } } -
Loading...
\ No newline at end of file +
Loading...
\ No newline at end of file diff --git a/azure/examples/function-calls/dist/twrmodworker.2165e649.js b/azure/examples/function-calls/dist/twrmodworker.2165e649.js index 3744680c..d8d07779 100644 --- a/azure/examples/function-calls/dist/twrmodworker.2165e649.js +++ b/azure/examples/function-calls/dist/twrmodworker.2165e649.js @@ -1,2 +1,2 @@ -(()=>{var t,e,r,s;let i;class a{sharedArray;buf;constructor(t){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSharedCircularBuffer constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");t?this.sharedArray=t:this.sharedArray=new SharedArrayBuffer(1032),this.buf=new Int32Array(this.sharedArray),this.buf[256]=0,this.buf[257]=0}write(t){let e=this.buf[257];this.buf[e]=t,256==++e&&(e=0),this.buf[257]=e,Atomics.notify(this.buf,257)}read(){if(this.isEmpty())return -1;{let t=this.buf[256],e=this.buf[t];return t++,this.buf[256]=t,e}}readWait(){if(this.isEmpty()){let t=this.buf[256];Atomics.wait(this.buf,257,t)}return this.read()}isEmpty(){return this.buf[256]==this.buf[257]}}(r=t||(t={}))[r.WAITING=0]="WAITING",r[r.SIGNALED=1]="SIGNALED";class o{sharedArray;buf;constructor(e){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSignal constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");e?this.sharedArray=e:this.sharedArray=new SharedArrayBuffer(4),this.buf=new Int32Array(this.sharedArray),this.buf[0]=t.WAITING}signal(){this.buf[0]=t.SIGNALED,Atomics.notify(this.buf,0)}wait(){this.buf[0]==t.WAITING&&Atomics.wait(this.buf,0,t.WAITING)}isSignaled(){return this.buf[0]==t.SIGNALED}reset(){this.buf[0]=t.WAITING}}(s=e||(e={}))[s.D2D_FILLRECT=1]="D2D_FILLRECT",s[s.D2D_FILLCHAR=5]="D2D_FILLCHAR",s[s.D2D_SETLINEWIDTH=10]="D2D_SETLINEWIDTH",s[s.D2D_SETFILLSTYLERGBA=11]="D2D_SETFILLSTYLERGBA",s[s.D2D_SETFONT=12]="D2D_SETFONT",s[s.D2D_BEGINPATH=13]="D2D_BEGINPATH",s[s.D2D_MOVETO=14]="D2D_MOVETO",s[s.D2D_LINETO=15]="D2D_LINETO",s[s.D2D_FILL=16]="D2D_FILL",s[s.D2D_STROKE=17]="D2D_STROKE",s[s.D2D_SETSTROKESTYLERGBA=18]="D2D_SETSTROKESTYLERGBA",s[s.D2D_ARC=19]="D2D_ARC",s[s.D2D_STROKERECT=20]="D2D_STROKERECT",s[s.D2D_FILLTEXT=21]="D2D_FILLTEXT",s[s.D2D_IMAGEDATA=22]="D2D_IMAGEDATA",s[s.D2D_PUTIMAGEDATA=23]="D2D_PUTIMAGEDATA",s[s.D2D_BEZIERTO=24]="D2D_BEZIERTO",s[s.D2D_MEASURETEXT=25]="D2D_MEASURETEXT",s[s.D2D_SAVE=26]="D2D_SAVE",s[s.D2D_RESTORE=27]="D2D_RESTORE",s[s.D2D_CREATERADIALGRADIENT=28]="D2D_CREATERADIALGRADIENT",s[s.D2D_SETCOLORSTOP=29]="D2D_SETCOLORSTOP",s[s.D2D_SETFILLSTYLEGRADIENT=30]="D2D_SETFILLSTYLEGRADIENT",s[s.D2D_RELEASEID=31]="D2D_RELEASEID",s[s.D2D_CREATELINEARGRADIENT=32]="D2D_CREATELINEARGRADIENT",s[s.D2D_SETFILLSTYLE=33]="D2D_SETFILLSTYLE",s[s.D2D_SETSTROKESTYLE=34]="D2D_SETSTROKESTYLE";class n{canvasKeys;drawCompleteSignal;props;owner;constructor(t,e){let[r,s,i]=t;this.drawCompleteSignal=new o(s),this.canvasKeys=new a(i),this.props=r,this.owner=e}charIn(){return this.canvasKeys.readWait()}inkey(){return this.canvasKeys.isEmpty()?0:this.charIn()}getProp(t){let e=this.owner.getString(t);return this.props[e]}drawSeq(t){this.drawCompleteSignal.reset(),postMessage(["drawseq",[t]]),this.drawCompleteSignal.wait()}}class l{divKeys;constructor(t){let[e]=t;this.divKeys=new a(e)}charIn(){return this.divKeys.readWait()}inkey(){return this.divKeys.isEmpty()?0:this.charIn()}charOut(t){postMessage(["divout",t])}}function h(t){postMessage(["debug",t])}class m{mod;constructor(t){this.mod=t}atod(t){let e=this.mod.getString(t),r=e.trimStart().toUpperCase();return"INF"==r||"+INF"==r?Number.POSITIVE_INFINITY:"-INF"==r?Number.NEGATIVE_INFINITY:Number.parseFloat(e.replaceAll("D","e").replaceAll("d","e"))}dtoa(t,e,r,s){if(-1==s){let s=r.toString();this.mod.copyString(t,e,s)}else{let i=r.toString();i.length>s&&(i=r.toPrecision(s)),this.mod.copyString(t,e,i)}}toFixed(t,e,r,s){let i=r.toFixed(s);this.mod.copyString(t,e,i)}toExponential(t,e,r,s){let i=r.toExponential(s);this.mod.copyString(t,e,i)}fcvtS(t,e,r,s,i,a){let o,n;if(0==t||0==a||0==i||e<1)return 1;let l=0;if(Number.isNaN(r))o="1#QNAN00000000000000000000000000000".slice(0,s+1),n=1;else if(Number.isFinite(r)){if(0==r)o="000000000000000000000000000000000000".slice(0,s),n=0;else{if(r<0&&(l=1,r=Math.abs(r)),s>100||r>1e21||r<1e-99)return this.mod.copyString(t,e,""),this.mod.mem32[i]=0,1;let[a="",h=""]=r.toFixed(s).split(".");"0"==a&&(a=""),a.length>0?(n=a.length,o=a+h):n=(o=h.replace(/^0+/,"")).length-h.length}}else o="1#INF00000000000000000000000000000".slice(0,s+1),n=1;return e-1new Promise(e=>{let r=this.exports.twr_malloc;e(r(t))}),this.init()}catch(t){throw console.log("WASM instantiate error: "+t+(t.stack?"\n"+t.stack:"")),t}}init(){let t;switch(this.modParams.stdio){case"debug":default:t=0;break;case"div":t=1;break;case"canvas":t=2;break;case"null":t=3}(0,this.exports.twr_wasm_init)(t,this.mem8.length)}async executeC(t){let e=await this.preCallC(t),r=this.executeCImpl(t[0],e);return this.postCallC(e,t),r}async executeCImpl(t,e=[]){if(!this.exports)throw Error("this.exports undefined");if(!this.exports[t])throw Error("executeC: function '"+t+"' not in export table. Use --export wasm-ld flag.");return(0,this.exports[t])(...e)}async preCallC(t){if(t.constructor!==Array)throw Error("executeC: params must be array, first arg is function name");if(0==t.length)throw Error("executeC: missing function name");let e=[],r=0;for(let s=1;s=this.mem32.length)throw Error("invalid index passed to getLong: "+t+", this.mem32.length: "+this.mem32.length);return this.mem32[e]}setLong(t,e){let r=Math.floor(t/4);if(4*r!=t)throw Error("setLong passed non long aligned address");if(r<0||r>=this.mem32.length)throw Error("invalid index passed to setLong: "+t+", this.mem32.length: "+this.mem32.length);this.mem32[r]=e}getDouble(t){let e=Math.floor(t/8);if(8*e!=t)throw Error("getLong passed non Float64 aligned address");return this.memD[e]}setDouble(t,e){let r=Math.floor(t/8);if(8*r!=t)throw Error("setDouble passed non Float64 aligned address");this.memD[r]=e}getShort(t){if(t<0||t>=this.mem8.length)throw Error("invalid index passed to getShort: "+t);return this.mem8[t]+256*this.mem8[t+1]}getString(t,e){let r="",s=0;for(;this.mem8[t+s]&&(void 0===e||s=this.mem8.length)throw Error("invalid index passed to getU8: "+t);let e=new Uint32Array(this.mem8.slice(t,t+8).buffer),r=e[0],s=e[1];if(s<0||s>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU8");if(r<0||r>this.mem8.length-s)throw Error("invalid idx.size passed to getU8");return this.mem8.slice(s,s+r)}getU32Arr(t){if(t<0||t>=this.mem8.length)throw Error("invalid index passed to getU32: "+t);let e=new Uint32Array(this.mem8.slice(t,t+8).buffer),r=e[0],s=e[1];if(s<0||s>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU32");if(r<0||r>this.mem8.length-s)throw Error("invalid idx.size passed to getU32");if(r%4!=0)throw Error("idx.size is not an integer number of 32 bit words");return new Uint32Array(this.mem8.slice(s,s+r).buffer)}}class d{callCompleteSignal;parameters;constructor(t){this.callCompleteSignal=new o(t[0]),this.parameters=new Uint32Array(t[1])}sleep(t){this.callCompleteSignal.reset(),postMessage(["sleep",[t]]),this.callCompleteSignal.wait()}time(){return this.callCompleteSignal.reset(),postMessage(["time"]),this.callCompleteSignal.wait(),this.parameters[0]}}onmessage=function(t){if("startup"==t.data[0]){let e=t.data[1];(i=new f(e.modParams,e.modWorkerParams)).loadWasm(e.urlToLoad).then(()=>{postMessage(["startupOkay"])}).catch(t=>{console.log(".catch: ",t),postMessage(["startupFail",t])})}else"executeC"==t.data[0]?i.executeCImpl(t.data[1],t.data[2]).then(t=>{postMessage(["executeCOkay",t])}).catch(t=>{console.log("exception in executeC twrworker.js\n"),console.log(t),postMessage(["executeCFail",t])}):console.log("twrworker.js: unknown message: "+t)};class f extends c{malloc;modParams;constructor(t,e){super(),this.isWorker=!0,this.malloc=t=>{throw Error("error - un-init malloc called")},this.modParams=t;let r=new n(e.canvasProxyParams,this),s=new l(e.divProxyParams),i=new d(e.waitingCallsProxyParams);this.modParams.imports={twrDebugLog:h,twrSleep:i.sleep.bind(i),twrTime:i.time.bind(i),twrDivCharOut:s.charOut.bind(s),twrDivCharIn:s.charIn.bind(s),twrCanvasCharIn:r.charIn.bind(r),twrCanvasInkey:r.inkey.bind(r),twrCanvasGetProp:r.getProp.bind(r),twrCanvasDrawSeq:r.drawSeq.bind(r),twrSin:Math.sin,twrCos:Math.cos,twrTan:Math.tan,twrFAbs:Math.abs,twrACos:Math.acos,twrASin:Math.asin,twrATan:Math.atan,twrExp:Math.exp,twrFloor:Math.floor,twrCeil:Math.ceil,twrFMod:function(t,e){return t%e},twrLog:Math.log,twrPow:Math.pow,twrSqrt:Math.sqrt,twrTrunc:Math.trunc,twrDtoa:this.floatUtil.dtoa.bind(this.floatUtil),twrToFixed:this.floatUtil.toFixed.bind(this.floatUtil),twrToExponential:this.floatUtil.toExponential.bind(this.floatUtil),twrAtod:this.floatUtil.atod.bind(this.floatUtil),twrFcvtS:this.floatUtil.fcvtS.bind(this.floatUtil)}}}})(); +(()=>{var t,e,r,s;let i;class a{sharedArray;buf;constructor(t){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSharedCircularBuffer constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");t?this.sharedArray=t:this.sharedArray=new SharedArrayBuffer(1032),this.buf=new Int32Array(this.sharedArray),this.buf[256]=0,this.buf[257]=0}write(t){let e=this.buf[257];this.buf[e]=t,256==++e&&(e=0),this.buf[257]=e,Atomics.notify(this.buf,257)}read(){if(this.isEmpty())return -1;{let t=this.buf[256],e=this.buf[t];return t++,this.buf[256]=t,e}}readWait(){if(this.isEmpty()){let t=this.buf[256];Atomics.wait(this.buf,257,t)}return this.read()}isEmpty(){return this.buf[256]==this.buf[257]}}(r=t||(t={}))[r.WAITING=0]="WAITING",r[r.SIGNALED=1]="SIGNALED";class o{sharedArray;buf;constructor(e){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSignal constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");e?this.sharedArray=e:this.sharedArray=new SharedArrayBuffer(4),this.buf=new Int32Array(this.sharedArray),this.buf[0]=t.WAITING}signal(){this.buf[0]=t.SIGNALED,Atomics.notify(this.buf,0)}wait(){this.buf[0]==t.WAITING&&Atomics.wait(this.buf,0,t.WAITING)}isSignaled(){return this.buf[0]==t.SIGNALED}reset(){this.buf[0]=t.WAITING}}(s=e||(e={}))[s.D2D_FILLRECT=1]="D2D_FILLRECT",s[s.D2D_FILLCHAR=5]="D2D_FILLCHAR",s[s.D2D_SETLINEWIDTH=10]="D2D_SETLINEWIDTH",s[s.D2D_SETFILLSTYLERGBA=11]="D2D_SETFILLSTYLERGBA",s[s.D2D_SETFONT=12]="D2D_SETFONT",s[s.D2D_BEGINPATH=13]="D2D_BEGINPATH",s[s.D2D_MOVETO=14]="D2D_MOVETO",s[s.D2D_LINETO=15]="D2D_LINETO",s[s.D2D_FILL=16]="D2D_FILL",s[s.D2D_STROKE=17]="D2D_STROKE",s[s.D2D_SETSTROKESTYLERGBA=18]="D2D_SETSTROKESTYLERGBA",s[s.D2D_ARC=19]="D2D_ARC",s[s.D2D_STROKERECT=20]="D2D_STROKERECT",s[s.D2D_FILLTEXT=21]="D2D_FILLTEXT",s[s.D2D_IMAGEDATA=22]="D2D_IMAGEDATA",s[s.D2D_PUTIMAGEDATA=23]="D2D_PUTIMAGEDATA",s[s.D2D_BEZIERTO=24]="D2D_BEZIERTO",s[s.D2D_MEASURETEXT=25]="D2D_MEASURETEXT",s[s.D2D_SAVE=26]="D2D_SAVE",s[s.D2D_RESTORE=27]="D2D_RESTORE",s[s.D2D_CREATERADIALGRADIENT=28]="D2D_CREATERADIALGRADIENT",s[s.D2D_SETCOLORSTOP=29]="D2D_SETCOLORSTOP",s[s.D2D_SETFILLSTYLEGRADIENT=30]="D2D_SETFILLSTYLEGRADIENT",s[s.D2D_RELEASEID=31]="D2D_RELEASEID",s[s.D2D_CREATELINEARGRADIENT=32]="D2D_CREATELINEARGRADIENT",s[s.D2D_SETFILLSTYLE=33]="D2D_SETFILLSTYLE",s[s.D2D_SETSTROKESTYLE=34]="D2D_SETSTROKESTYLE";class n{canvasKeys;drawCompleteSignal;props;owner;constructor(t,e){let[r,s,i]=t;this.drawCompleteSignal=new o(s),this.canvasKeys=new a(i),this.props=r,this.owner=e}charIn(){return this.canvasKeys.readWait()}inkey(){return this.canvasKeys.isEmpty()?0:this.charIn()}getProp(t){let e=this.owner.getString(t);return this.props[e]}drawSeq(t){this.drawCompleteSignal.reset(),postMessage(["drawseq",[t]]),this.drawCompleteSignal.wait()}}class l{divKeys;constructor(t){let[e]=t;this.divKeys=new a(e)}charIn(){return this.divKeys.readWait()}inkey(){return this.divKeys.isEmpty()?0:this.charIn()}charOut(t){postMessage(["divout",t])}}function h(t){postMessage(["debug",t])}class m{mod;constructor(t){this.mod=t}atod(t){let e=this.mod.getString(t),r=e.trimStart().toUpperCase();return"INF"==r||"+INF"==r?Number.POSITIVE_INFINITY:"-INF"==r?Number.NEGATIVE_INFINITY:Number.parseFloat(e.replaceAll("D","e").replaceAll("d","e"))}dtoa(t,e,r,s){if(-1==s){let s=r.toString();this.mod.copyString(t,e,s)}else{let i=r.toString();i.length>s&&(i=r.toPrecision(s)),this.mod.copyString(t,e,i)}}toFixed(t,e,r,s){let i=r.toFixed(s);this.mod.copyString(t,e,i)}toExponential(t,e,r,s){let i=r.toExponential(s);this.mod.copyString(t,e,i)}fcvtS(t,e,r,s,i,a){let o,n;if(0==t||0==a||0==i||e<1)return 1;let l=0;if(Number.isNaN(r))o="1#QNAN00000000000000000000000000000".slice(0,s+1),n=1;else if(Number.isFinite(r)){if(0==r)o="000000000000000000000000000000000000".slice(0,s),n=0;else{if(r<0&&(l=1,r=Math.abs(r)),s>100||r>1e21||r<1e-99)return this.mod.copyString(t,e,""),this.mod.mem32[i]=0,1;let[a="",h=""]=r.toFixed(s).split(".");"0"==a&&(a=""),a.length>0?(n=a.length,o=a+h):n=(o=h.replace(/^0+/,"")).length-h.length}}else o="1#INF00000000000000000000000000000".slice(0,s+1),n=1;return e-1new Promise(e=>{let r=this.exports.twr_malloc;e(r(t))}),this.init()}catch(t){throw console.log("WASM instantiate error: "+t+(t.stack?"\n"+t.stack:"")),t}}init(){let t;switch(this.modParams.stdio){case"debug":default:t=0;break;case"div":t=1;break;case"canvas":t=2;break;case"null":t=3}(0,this.exports.twr_wasm_init)(t,this.mem8.length)}async callC(t){let e=await this.preCallC(t),r=this.callCImpl(t[0],e);return this.postCallC(e,t),r}async callCImpl(t,e=[]){if(!this.exports)throw Error("this.exports undefined");if(!this.exports[t])throw Error("callC: function '"+t+"' not in export table. Use --export wasm-ld flag.");return(0,this.exports[t])(...e)}async preCallC(t){if(t.constructor!==Array)throw Error("callC: params must be array, first arg is function name");if(0==t.length)throw Error("callC: missing function name");let e=[],r=0;for(let s=1;s=this.mem32.length)throw Error("invalid index passed to getLong: "+t+", this.mem32.length: "+this.mem32.length);return this.mem32[e]}setLong(t,e){let r=Math.floor(t/4);if(4*r!=t)throw Error("setLong passed non long aligned address");if(r<0||r>=this.mem32.length)throw Error("invalid index passed to setLong: "+t+", this.mem32.length: "+this.mem32.length);this.mem32[r]=e}getDouble(t){let e=Math.floor(t/8);if(8*e!=t)throw Error("getLong passed non Float64 aligned address");return this.memD[e]}setDouble(t,e){let r=Math.floor(t/8);if(8*r!=t)throw Error("setDouble passed non Float64 aligned address");this.memD[r]=e}getShort(t){if(t<0||t>=this.mem8.length)throw Error("invalid index passed to getShort: "+t);return this.mem8[t]+256*this.mem8[t+1]}getString(t,e){let r="",s=0;for(;this.mem8[t+s]&&(void 0===e||s=this.mem8.length)throw Error("invalid index passed to getU8: "+t);let e=new Uint32Array(this.mem8.slice(t,t+8).buffer),r=e[0],s=e[1];if(s<0||s>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU8");if(r<0||r>this.mem8.length-s)throw Error("invalid idx.size passed to getU8");return this.mem8.slice(s,s+r)}getU32Arr(t){if(t<0||t>=this.mem8.length)throw Error("invalid index passed to getU32: "+t);let e=new Uint32Array(this.mem8.slice(t,t+8).buffer),r=e[0],s=e[1];if(s<0||s>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU32");if(r<0||r>this.mem8.length-s)throw Error("invalid idx.size passed to getU32");if(r%4!=0)throw Error("idx.size is not an integer number of 32 bit words");return new Uint32Array(this.mem8.slice(s,s+r).buffer)}}class d{callCompleteSignal;parameters;constructor(t){this.callCompleteSignal=new o(t[0]),this.parameters=new Uint32Array(t[1])}sleep(t){this.callCompleteSignal.reset(),postMessage(["sleep",[t]]),this.callCompleteSignal.wait()}time(){return this.callCompleteSignal.reset(),postMessage(["time"]),this.callCompleteSignal.wait(),this.parameters[0]}}onmessage=function(t){if("startup"==t.data[0]){let e=t.data[1];(i=new f(e.modParams,e.modWorkerParams)).loadWasm(e.urlToLoad).then(()=>{postMessage(["startupOkay"])}).catch(t=>{console.log(".catch: ",t),postMessage(["startupFail",t])})}else"callC"==t.data[0]?i.callCImpl(t.data[1],t.data[2]).then(t=>{postMessage(["callCOkay",t])}).catch(t=>{console.log("exception in callC twrworker.js\n"),console.log(t),postMessage(["callCFail",t])}):console.log("twrworker.js: unknown message: "+t)};class f extends c{malloc;modParams;constructor(t,e){super(),this.isWorker=!0,this.malloc=t=>{throw Error("error - un-init malloc called")},this.modParams=t;let r=new n(e.canvasProxyParams,this),s=new l(e.divProxyParams),i=new d(e.waitingCallsProxyParams);this.modParams.imports={twrDebugLog:h,twrSleep:i.sleep.bind(i),twrTime:i.time.bind(i),twrDivCharOut:s.charOut.bind(s),twrDivCharIn:s.charIn.bind(s),twrCanvasCharIn:r.charIn.bind(r),twrCanvasInkey:r.inkey.bind(r),twrCanvasGetProp:r.getProp.bind(r),twrCanvasDrawSeq:r.drawSeq.bind(r),twrSin:Math.sin,twrCos:Math.cos,twrTan:Math.tan,twrFAbs:Math.abs,twrACos:Math.acos,twrASin:Math.asin,twrATan:Math.atan,twrExp:Math.exp,twrFloor:Math.floor,twrCeil:Math.ceil,twrFMod:function(t,e){return t%e},twrLog:Math.log,twrPow:Math.pow,twrSqrt:Math.sqrt,twrTrunc:Math.trunc,twrDtoa:this.floatUtil.dtoa.bind(this.floatUtil),twrToFixed:this.floatUtil.toFixed.bind(this.floatUtil),twrToExponential:this.floatUtil.toExponential.bind(this.floatUtil),twrAtod:this.floatUtil.atod.bind(this.floatUtil),twrFcvtS:this.floatUtil.fcvtS.bind(this.floatUtil)}}}})(); //# sourceMappingURL=twrmodworker.2165e649.js.map diff --git a/azure/examples/function-calls/dist/twrmodworker.2165e649.js.map b/azure/examples/function-calls/dist/twrmodworker.2165e649.js.map index 29a4d41e..77745e98 100644 --- a/azure/examples/function-calls/dist/twrmodworker.2165e649.js.map +++ b/azure/examples/function-calls/dist/twrmodworker.2165e649.js.map @@ -1 +1 @@ -{"mappings":"A,C,SQKK,EJgBA,EIhBA,EJgBA,MFZD,CISE,OAAO,EACZ,WAA8B,AAC9B,CAAA,GAAe,AAEf,aAAa,CAAqB,CAAlC,CACO,GAAI,AAAkB,aAAlB,OAAO,QACH,CAAC,qBAAuB,AAA+B,UAA7B,OAAO,QAAQ,CAAC,QAAQ,CAAe,MAAM,AAAI,MAAM,4DAA4D,oBAAoB,iCAErK,EAAI,IAAI,CAAC,WAAW,CAAC,EACpB,IAAI,CAAC,WAAW,CAAC,IAAI,kBAAkB,MAClD,IAAI,CAAC,GAAG,CAAC,IAAI,WAAW,IAAI,CAAC,WAAW,EAClC,IAAI,CAAC,GAAG,CArBJ,IAqBW,CAAC,EAChB,IAAI,CAAC,GAAG,CArBJ,IAqBW,CAAC,CACvB,CAEA,MAAM,CAAQ,CAAd,CACO,IAAI,EAAE,IAAI,CAAC,GAAG,CAzBV,IAyBiB,AACrB,CAAA,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAzBV,OA2BE,GAAQ,CAAA,EAAE,CAAA,EACd,IAAI,CAAC,GAAG,CA7BJ,IA6BW,CAAC,EAChB,QAAQ,MAA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/twr-wasm-ts/twrmodworker.ts","../../lib-js/twrcanvas.js","../../source/twr-wasm-ts/twrcanvas.ts","../../lib-js/twrcircular.js","../../source/twr-wasm-ts/twrcircular.ts","../../lib-js/twrsignal.js","../../source/twr-wasm-ts/twrsignal.ts","../../lib-js/twrdiv.js","../../source/twr-wasm-ts/twrdiv.ts","../../lib-js/twrdebug.js","../../source/twr-wasm-ts/twrdebug.ts","../../lib-js/twrmodbase.js","../../source/twr-wasm-ts/twrmodbase.ts","../../lib-js/twrfloat.js","../../source/twr-wasm-ts/twrfloat.ts","../../lib-js/twrwaitingcalls.js","../../source/twr-wasm-ts/twrwaitingcalls.ts","../../lib-js/twrdate.js","../../source/twr-wasm-ts/twrdate.ts"],"sourcesContent":["(() => {\nvar $3e39efa823870787$exports = {};\n// this script is the WebWorker thead used by class twrWasmAsyncModule\n//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst $892fccfc812d5e20$var$RDIDX = 256;\nconst $892fccfc812d5e20$var$WRIDX = 257;\nconst $892fccfc812d5e20$var$LEN = 256;\nclass $892fccfc812d5e20$export$a01cca24f011573a {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(1032);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[$892fccfc812d5e20$var$RDIDX] = 0;\n this.buf[$892fccfc812d5e20$var$WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[$892fccfc812d5e20$var$WRIDX];\n this.buf[i] = n;\n i++;\n if (i == $892fccfc812d5e20$var$LEN) i = 0;\n this.buf[$892fccfc812d5e20$var$WRIDX] = i;\n Atomics.notify(this.buf, $892fccfc812d5e20$var$WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[$892fccfc812d5e20$var$RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[$892fccfc812d5e20$var$RDIDX] = i;\n return n;\n } else return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[$892fccfc812d5e20$var$RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, $892fccfc812d5e20$var$WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[$892fccfc812d5e20$var$RDIDX] == this.buf[$892fccfc812d5e20$var$WRIDX];\n }\n}\n\n\n//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar $b93f1fdf40141def$var$twrSignalState;\n(function(twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})($b93f1fdf40141def$var$twrSignalState || ($b93f1fdf40141def$var$twrSignalState = {}));\nclass $b93f1fdf40141def$export$e37a7b7b851b97f3 {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == $b93f1fdf40141def$var$twrSignalState.WAITING) //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, $b93f1fdf40141def$var$twrSignalState.WAITING);\n }\n isSignaled() {\n return this.buf[0] == $b93f1fdf40141def$var$twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.WAITING;\n }\n}\n\n\nvar $c4741cac81d14197$var$D2DType;\n(function(D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})($c4741cac81d14197$var$D2DType || ($c4741cac81d14197$var$D2DType = {}));\nclass $c4741cac81d14197$export$2f298dd69cef3c34 {\n ctx;\n props = {\n charWidth: 0,\n charHeight: 0,\n foreColor: 0,\n backColor: 0,\n widthInChars: 0,\n heightInChars: 0,\n canvasHeight: 0,\n canvasWidth: 0\n };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase){\n const { forecolor: forecolor, backcolor: backcolor, fontsize: fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)();\n this.canvasKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.props,\n this.cmdCompleteSignal.sharedArray,\n this.canvasKeys.sharedArray\n ];\n }\n getProp(pn) {\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */ drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx) return;\n let ins = this.owner.getLong(ds); /* ds->start */ \n const lastins = this.owner.getLong(ds + 4); /* ds->last */ \n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while(true){\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */ \n switch(type){\n case $c4741cac81d14197$var$D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_BEGINPATH:\n this.ctx.beginPath();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILL:\n this.ctx.fill();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SAVE:\n this.ctx.save();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_RESTORE:\n this.ctx.restore();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_STROKE:\n this.ctx.stroke();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = this.owner.getLong(ins + 48) != 0;\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n } else this.precomputedObjects[id] = {\n mem8: new Uint8Array(this.owner.memory.buffer, start, length),\n width: width,\n height: height\n };\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id]) delete this.precomputedObjects[id];\n else console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n else {\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) this.ctx.putImageData(imgData, dx, dy);\n else this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */ \n if (next == 0) {\n if (ins != lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nclass $c4741cac81d14197$export$c779b2cd00544976 {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner){\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)(signalBuffer);\n this.canvasKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\n \"drawseq\",\n [\n ds\n ]\n ]);\n this.drawCompleteSignal.wait();\n }\n}\n\n\n\nclass $8963973702ae5462$export$dd376bb3f10f6896 {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611);\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase){\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) this.divKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(); // tsconfig, lib must be set to 2017 or higher\n if (this.div && !modParams.styleIsDefault) {\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.divKeys.sharedArray\n ];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */ charOut(ch) {\n if (!this.div) return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n }\n switch(ch){\n case 10:\n case 13:\n if (ch == 10 && this.lastChar == 13) break; // detect CR LF and treat as single new line\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n case 0xE:\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF:\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for(let i = 0; i < str.length; i++)this.charOut(str.charCodeAt(i));\n }\n}\nclass $8963973702ae5462$export$b377f0bbf2c7581e {\n divKeys;\n constructor(params){\n const [divKeysBuffer] = params;\n this.divKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n charOut(ch) {\n postMessage([\n \"divout\",\n ch\n ]);\n }\n}\n\n\nlet $8ac0b786da854328$var$logline = \"\";\nfunction $8ac0b786da854328$export$16b4216ec014493d(char) {\n if (char == 10 || char == 3) {\n console.log($8ac0b786da854328$var$logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n $8ac0b786da854328$var$logline = \"\";\n } else {\n $8ac0b786da854328$var$logline = $8ac0b786da854328$var$logline + String.fromCharCode(char);\n if ($8ac0b786da854328$var$logline.length >= 200) {\n console.log($8ac0b786da854328$var$logline);\n $8ac0b786da854328$var$logline = \"\";\n }\n }\n}\nfunction $8ac0b786da854328$export$485af4d0039b3389(ch) {\n postMessage([\n \"debug\",\n ch\n ]);\n}\n\n\nclass $e72303a1db04bdfa$export$918ffb7e046a537b {\n mod;\n constructor(mod){\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\") return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\") return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll(\"D\", \"e\").replaceAll(\"d\", \"e\"));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n } else {\n let r = value.toString();\n if (r.length > max_precision) r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, sizeInBytes, value, fracpart_numdigits, dec, sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1) return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) {\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (!Number.isFinite(value)) {\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n } else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split(\".\");\n if (intPart == \"0\") intPart = \"\";\n if (intPart.length > 0) {\n decpos = intPart.length;\n digits = intPart + fracPart;\n } else {\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length) return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */ }\n}\n\n\nclass $ece7fa3ed770778a$export$c83a0a3bffe07399 {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule;\n floatUtil;\n constructor(isWasmModule = false){\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new (0, $e72303a1db04bdfa$export$918ffb7e046a537b)(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/ /*********************************************************************/ async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n } catch (err) {\n console.log(\"loadWasm() failed to fetch: \" + pathToLoad);\n throw err;\n }\n if (!response.ok) throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, {\n env: allimports\n });\n this.exports = instance.instance.exports;\n if (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory) throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer) console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\n \"setmemory\",\n this.memory\n ]);\n }\n if (this.isWasmModule) // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n {\n if (!(this.memory.buffer instanceof ArrayBuffer)) console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size)=>{\n return new Promise((resolve)=>{\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n } catch (err) {\n console.log(\"WASM instantiate error: \" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch(this.modParams.stdio){\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* executeC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */ async executeC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.executeCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async executeCImpl(fname, cparams = []) {\n if (!this.exports) throw new Error(\"this.exports undefined\");\n if (!this.exports[fname]) throw new Error(\"executeC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array)) throw new Error(\"executeC: params must be array, first arg is function name\");\n if (params.length == 0) throw new Error(\"executeC: missing function name\");\n let cparams = [];\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n cparams[ci++] = p;\n break;\n case \"string\":\n cparams[ci++] = await this.putString(p);\n break;\n case \"object\":\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n } else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"executeC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n ci++;\n break;\n case \"string\":\n this.executeCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n case \"object\":\n if (p instanceof URL) {\n this.executeCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci = ci + 2;\n break;\n } else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for(let j = 0; j < u8.length; j++)u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.executeCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n } else throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/ /*********************************************************************/ // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for(i = 0; i < sin.length && i < buffer_size - 1; i++)this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for(let i = 0; i < u8a.length; i++)this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === \"object\" && fnin instanceof URL)) throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [\n dest,\n src.length\n ];\n } catch (err) {\n console.log(\"fetchAndPutURL Error. URL: \" + fnin + \"\\n\" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while(this.mem8[strIndex + i] && (len === undefined ? true : i < len) && strIndex + i < this.mem8.length){\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array(this.mem8.slice(dataptr, dataptr + size).buffer);\n return u32;\n }\n}\n\n\n\nfunction $4af5689abbc8d01b$export$78724cdcf7ebea1d() {\n return Date.now();\n}\n\n\nclass $aff9c2c494d23fe3$export$9e37856d1928d388 {\n callCompleteSignal;\n parameters;\n constructor(){\n this.callCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(()=>{\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = (0, $4af5689abbc8d01b$export$78724cdcf7ebea1d)();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [\n this.callCompleteSignal.sharedArray,\n this.parameters.buffer\n ];\n }\n processMessage(msgType, data) {\n switch(msgType){\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\nclass $aff9c2c494d23fe3$export$78d2a4633fe89379 {\n callCompleteSignal;\n parameters;\n constructor(params){\n this.callCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\n \"sleep\",\n [\n ms\n ]\n ]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\n \"time\"\n ]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n\n\nlet $3e39efa823870787$var$mod;\nonmessage = function(e) {\n //console.log('twrworker.js: message received from main script: '+e.data);\n if (e.data[0] == \"startup\") {\n const params = e.data[1];\n //console.log(\"Worker startup params:\",params);\n $3e39efa823870787$var$mod = new $3e39efa823870787$var$twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\n $3e39efa823870787$var$mod.loadWasm(params.urlToLoad).then(()=>{\n postMessage([\n \"startupOkay\"\n ]);\n }).catch((ex)=>{\n console.log(\".catch: \", ex);\n postMessage([\n \"startupFail\",\n ex\n ]);\n });\n } else if (e.data[0] == \"executeC\") $3e39efa823870787$var$mod.executeCImpl(e.data[1], e.data[2]).then((rc)=>{\n postMessage([\n \"executeCOkay\",\n rc\n ]);\n }).catch((e)=>{\n console.log(\"exception in executeC twrworker.js\\n\");\n console.log(e);\n postMessage([\n \"executeCFail\",\n e\n ]);\n });\n else console.log(\"twrworker.js: unknown message: \" + e);\n};\n// ************************************************************************\nclass $3e39efa823870787$var$twrWasmModuleInWorker extends (0, $ece7fa3ed770778a$export$c83a0a3bffe07399) {\n malloc;\n modParams;\n constructor(modParams, modInWorkerParams){\n super();\n this.isWorker = true;\n this.malloc = (size)=>{\n throw new Error(\"error - un-init malloc called\");\n };\n this.modParams = modParams;\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\n const canvasProxy = new (0, $c4741cac81d14197$export$c779b2cd00544976)(modInWorkerParams.canvasProxyParams, this);\n const divProxy = new (0, $8963973702ae5462$export$b377f0bbf2c7581e)(modInWorkerParams.divProxyParams);\n const waitingCallsProxy = new (0, $aff9c2c494d23fe3$export$78d2a4633fe89379)(modInWorkerParams.waitingCallsProxyParams);\n this.modParams.imports = {\n twrDebugLog: (0, $8ac0b786da854328$export$485af4d0039b3389),\n twrSleep: waitingCallsProxy.sleep.bind(waitingCallsProxy),\n twrTime: waitingCallsProxy.time.bind(waitingCallsProxy),\n twrDivCharOut: divProxy.charOut.bind(divProxy),\n twrDivCharIn: divProxy.charIn.bind(divProxy),\n twrCanvasCharIn: canvasProxy.charIn.bind(canvasProxy),\n twrCanvasInkey: canvasProxy.inkey.bind(canvasProxy),\n twrCanvasGetProp: canvasProxy.getProp.bind(canvasProxy),\n twrCanvasDrawSeq: canvasProxy.drawSeq.bind(canvasProxy),\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function(x, y) {\n return x % y;\n },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n}\n\n})();\n//# sourceMappingURL=twrmodworker.2165e649.js.map\n","// this script is the WebWorker thead used by class twrWasmAsyncModule\nimport { twrCanvasProxy } from \"./twrcanvas.js\";\nimport { twrDivProxy } from \"./twrdiv.js\";\nimport { twrDebugLogProxy } from \"./twrdebug.js\";\nimport { twrWasmModuleBase } from \"./twrmodbase.js\";\nimport { twrWaitingCallsProxy } from \"./twrwaitingcalls.js\";\nlet mod;\nonmessage = function (e) {\n //console.log('twrworker.js: message received from main script: '+e.data);\n if (e.data[0] == 'startup') {\n const params = e.data[1];\n //console.log(\"Worker startup params:\",params);\n mod = new twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\n mod.loadWasm(params.urlToLoad).then(() => {\n postMessage([\"startupOkay\"]);\n }).catch((ex) => {\n console.log(\".catch: \", ex);\n postMessage([\"startupFail\", ex]);\n });\n }\n else if (e.data[0] == 'executeC') {\n mod.executeCImpl(e.data[1], e.data[2]).then((rc) => {\n postMessage([\"executeCOkay\", rc]);\n }).catch(e => {\n console.log(\"exception in executeC twrworker.js\\n\");\n console.log(e);\n postMessage([\"executeCFail\", e]);\n });\n }\n else {\n console.log(\"twrworker.js: unknown message: \" + e);\n }\n};\n// ************************************************************************\nclass twrWasmModuleInWorker extends twrWasmModuleBase {\n malloc;\n modParams;\n constructor(modParams, modInWorkerParams) {\n super();\n this.isWorker = true;\n this.malloc = (size) => { throw new Error(\"error - un-init malloc called\"); };\n this.modParams = modParams;\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\n const canvasProxy = new twrCanvasProxy(modInWorkerParams.canvasProxyParams, this);\n const divProxy = new twrDivProxy(modInWorkerParams.divProxyParams);\n const waitingCallsProxy = new twrWaitingCallsProxy(modInWorkerParams.waitingCallsProxyParams);\n this.modParams.imports = {\n twrDebugLog: twrDebugLogProxy,\n twrSleep: waitingCallsProxy.sleep.bind(waitingCallsProxy),\n twrTime: waitingCallsProxy.time.bind(waitingCallsProxy),\n twrDivCharOut: divProxy.charOut.bind(divProxy),\n twrDivCharIn: divProxy.charIn.bind(divProxy),\n twrCanvasCharIn: canvasProxy.charIn.bind(canvasProxy),\n twrCanvasInkey: canvasProxy.inkey.bind(canvasProxy),\n twrCanvasGetProp: canvasProxy.getProp.bind(canvasProxy),\n twrCanvasDrawSeq: canvasProxy.drawSeq.bind(canvasProxy),\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function (x, y) { return x % y; },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n}\n//# sourceMappingURL=twrmodworker.js.map","// this script is the WebWorker thead used by class twrWasmAsyncModule\r\n\r\nimport {twrCanvasProxy} from \"./twrcanvas.js\";\r\nimport {twrDivProxy} from \"./twrdiv.js\";\r\nimport {twrDebugLogProxy} from \"./twrdebug.js\";\r\nimport {TAsyncModStartupMsg} from \"./twrmodasync.js\"\r\nimport {twrWasmModuleBase, IModInWorkerParams, IModParams} from \"./twrmodbase.js\"\r\nimport {twrWaitingCallsProxy} from \"./twrwaitingcalls.js\";\r\n\r\nlet mod:twrWasmModuleInWorker;\r\n\r\nonmessage = function(e) {\r\n //console.log('twrworker.js: message received from main script: '+e.data);\r\n\r\n if (e.data[0]=='startup') {\r\n const params:TAsyncModStartupMsg=e.data[1];\r\n //console.log(\"Worker startup params:\",params);\r\n mod=new twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\r\n\r\n mod.loadWasm(params.urlToLoad).then( ()=> {\r\n postMessage([\"startupOkay\"]);\r\n }).catch( (ex)=> {\r\n console.log(\".catch: \", ex);\r\n postMessage([\"startupFail\", ex]);\r\n });\r\n }\r\n else if (e.data[0]=='executeC') {\r\n mod.executeCImpl(e.data[1], e.data[2]).then( (rc)=> {\r\n postMessage([\"executeCOkay\", rc]);\r\n }).catch(e => {\r\n console.log(\"exception in executeC twrworker.js\\n\");\r\n console.log(e);\r\n postMessage([\"executeCFail\", e]);\r\n });\r\n }\r\n else {\r\n console.log(\"twrworker.js: unknown message: \"+e);\r\n }\r\n}\r\n\r\n\r\n// ************************************************************************\r\n\r\nclass twrWasmModuleInWorker extends twrWasmModuleBase {\r\n\tmalloc:(size:number)=>Promise;\r\n modParams: IModParams;\r\n\r\n\r\n constructor(modParams:IModParams, modInWorkerParams:IModInWorkerParams) {\r\n super();\r\n this.isWorker=true;\r\n this.malloc=(size:number)=>{throw new Error(\"error - un-init malloc called\")};\r\n this.modParams=modParams;\r\n\r\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\r\n const canvasProxy = new twrCanvasProxy(modInWorkerParams.canvasProxyParams, this);\r\n const divProxy = new twrDivProxy(modInWorkerParams.divProxyParams);\r\n const waitingCallsProxy = new twrWaitingCallsProxy(modInWorkerParams.waitingCallsProxyParams);\r\n\r\n this.modParams.imports={\r\n twrDebugLog:twrDebugLogProxy,\r\n twrSleep:waitingCallsProxy.sleep.bind(waitingCallsProxy),\r\n twrTime:waitingCallsProxy.time.bind(waitingCallsProxy),\r\n\r\n twrDivCharOut:divProxy.charOut.bind(divProxy), \r\n twrDivCharIn:divProxy.charIn.bind(divProxy), \r\n\r\n twrCanvasCharIn:canvasProxy.charIn.bind(canvasProxy),\r\n twrCanvasInkey:canvasProxy.inkey.bind(canvasProxy),\r\n twrCanvasGetProp:canvasProxy.getProp.bind(canvasProxy),\r\n twrCanvasDrawSeq:canvasProxy.drawSeq.bind(canvasProxy),\r\n\r\n\t\t\ttwrSin:Math.sin,\r\n\t\t\ttwrCos:Math.cos,\r\n\t\t\ttwrTan: Math.tan,\r\n\t\t\ttwrFAbs: Math.abs,\r\n\t\t\ttwrACos: Math.acos,\r\n\t\t\ttwrASin: Math.asin,\r\n\t\t\ttwrATan: Math.atan,\r\n\t\t\ttwrExp: Math.exp,\r\n\t\t\ttwrFloor: Math.floor,\r\n\t\t\ttwrCeil: Math.ceil,\r\n\t\t\ttwrFMod: function(x:number, y:number) {return x%y},\r\n\t\t\ttwrLog: Math.log,\r\n\t\t\ttwrPow: Math.pow,\r\n\t\t\ttwrSqrt: Math.sqrt,\r\n\t\t\ttwrTrunc: Math.trunc,\r\n\r\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\r\n\t\t\ttwrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\r\n\t\t\ttwrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\r\n\t\t\ttwrAtod: this.floatUtil.atod.bind(this.floatUtil),\r\n\t\t\ttwrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\r\n \r\n }\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nimport { twrSignal } from \"./twrsignal.js\";\nvar D2DType;\n(function (D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})(D2DType || (D2DType = {}));\nexport class twrCanvas {\n ctx;\n props = { charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight: 0, canvasWidth: 0 };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase) {\n const { forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new twrSignal();\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext)\n throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c)\n throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2)\n throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\n }\n getProp(pn) {\n if (!this.isValid())\n console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */\n drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid())\n console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx)\n return;\n let ins = this.owner.getLong(ds); /* ds->start */\n const lastins = this.owner.getLong(ds + 4); /* ds->last */\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while (1) {\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */\n if (0 /*type!=D2DType.D2D_FILLRECT*/) {\n console.log(\"ins\", ins);\n console.log(\"hdr.next\", this.owner.mem8[ins], this.owner.mem8[ins + 1], this.owner.mem8[ins + 2], this.owner.mem8[ins + 3]);\n console.log(\"hdr.type\", this.owner.mem8[ins + 4], this.owner.mem8[ins + 5]);\n console.log(\"next 4 bytes\", this.owner.mem8[ins + 6], this.owner.mem8[ins + 7], this.owner.mem8[ins + 8], this.owner.mem8[ins + 9]);\n console.log(\"and 4 more \", this.owner.mem8[ins + 10], this.owner.mem8[ins + 11], this.owner.mem8[ins + 12], this.owner.mem8[ins + 13]);\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\n }\n switch (type) {\n case D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case D2DType.D2D_BEGINPATH:\n {\n this.ctx.beginPath();\n }\n break;\n case D2DType.D2D_FILL:\n {\n this.ctx.fill();\n }\n break;\n case D2DType.D2D_SAVE:\n {\n this.ctx.save();\n }\n break;\n case D2DType.D2D_RESTORE:\n {\n this.ctx.restore();\n }\n break;\n case D2DType.D2D_STROKE:\n {\n this.ctx.stroke();\n }\n break;\n case D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = (this.owner.getLong(ins + 48) != 0);\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n }\n else { // Uint8ClampedArray doesn't support shared memory\n this.precomputedObjects[id] = { mem8: new Uint8Array(this.owner.memory.buffer, start, length), width: width, height: height };\n }\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id])\n delete this.precomputedObjects[id];\n else\n console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) {\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n }\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) {\n this.ctx.putImageData(imgData, dx, dy);\n }\n else {\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */\n if (next == 0) {\n if (ins != lastins)\n throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal)\n this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nexport class twrCanvasProxy {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner) {\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new twrSignal(signalBuffer);\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\"drawseq\", [ds]]);\n this.drawCompleteSignal.wait();\n }\n}\n//# sourceMappingURL=twrcanvas.js.map","import {twrWasmModuleBase, IModParams} from \"./twrmodbase.js\"\r\nimport {twrSharedCircularBuffer} from \"./twrcircular.js\";\r\nimport {twrSignal} from \"./twrsignal.js\";\r\n\r\n\r\n// Canvas have a size that will be set based on the character width x height\r\n// The display size for a canvas will default to this size, but can be changed in the HTML/JS via\r\n// canvas.style.width = \"700px\";\r\n// canvas.style.height = \"500px\";\r\n\r\nexport interface ICanvasProps {\r\n\tcharWidth: number,\r\n\tcharHeight: number,\r\n\tforeColor: number,\r\n\tbackColor: number,\r\n widthInChars: number,\r\n heightInChars: number,\r\n canvasWidth:number,\r\n canvasHeight:number\r\n}\r\n\r\nenum D2DType {\r\n D2D_FILLRECT=1,\r\n D2D_FILLCHAR=5,\r\n D2D_SETLINEWIDTH=10,\r\n D2D_SETFILLSTYLERGBA=11,\r\n D2D_SETFONT=12,\r\n D2D_BEGINPATH=13,\r\n D2D_MOVETO=14,\r\n D2D_LINETO=15,\r\n D2D_FILL=16,\r\n D2D_STROKE=17,\r\n D2D_SETSTROKESTYLERGBA=18,\r\n D2D_ARC=19,\r\n D2D_STROKERECT=20,\r\n D2D_FILLTEXT=21,\r\n D2D_IMAGEDATA=22,\r\n D2D_PUTIMAGEDATA=23,\r\n D2D_BEZIERTO=24,\r\n D2D_MEASURETEXT=25,\r\n D2D_SAVE=26,\r\n D2D_RESTORE=27,\r\n D2D_CREATERADIALGRADIENT=28,\r\n D2D_SETCOLORSTOP=29,\r\n D2D_SETFILLSTYLEGRADIENT=30,\r\n D2D_RELEASEID=31,\r\n D2D_CREATELINEARGRADIENT=32,\r\n D2D_SETFILLSTYLE=33,\r\n D2D_SETSTROKESTYLE=34\r\n\r\n}\r\n\r\nexport type TCanvasProxyParams = [ICanvasProps, SharedArrayBuffer, SharedArrayBuffer];\r\n\r\nexport interface ICanvas {\r\n props: ICanvasProps,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TCanvasProxyParams,\r\n drawSeq: (ds:number)=>void,\r\n }\r\n \r\nexport class twrCanvas implements ICanvas {\r\n ctx:CanvasRenderingContext2D|undefined;\r\n props:ICanvasProps={charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight:0, canvasWidth:0};\r\n owner: twrWasmModuleBase;\r\n cmdCompleteSignal?:twrSignal;\r\n canvasKeys?: twrSharedCircularBuffer;\r\n precomputedObjects: { [index: number]: \r\n (ImageData | {mem8:Uint8Array, width:number, height:number}) |\r\n CanvasGradient\r\n };\r\n\r\n constructor(element:HTMLCanvasElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n const {forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas} = modParams; \r\n this.owner=modbase;\r\n this.props.widthInChars=modParams.windim[0];\r\n this.props.heightInChars=modParams.windim[1];\r\n\r\n if (!this.owner.isWasmModule) {\r\n this.cmdCompleteSignal=new twrSignal();\r\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n }\r\n\r\n this.precomputedObjects={};\r\n \r\n if (element) {\r\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\r\n let c=element.getContext(\"2d\");\r\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\r\n\r\n c.font = fontsize.toString()+\"px Courier New\";\r\n c.textBaseline=\"top\";\r\n const sampleText=\" \";\r\n const tm=c.measureText(sampleText);\r\n this.props.charWidth=Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\r\n let fM = c.measureText(\"X\"); \r\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\r\n\r\n if (!isd2dcanvas) {\r\n element.width=this.props.charWidth*this.props.widthInChars;\r\n element.height=this.props.charHeight*this.props.heightInChars;\r\n }\r\n\r\n this.props.canvasHeight=element.height;\r\n this.props.canvasWidth=element.width;\r\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\r\n\r\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\r\n let c2=element.getContext(\"2d\");\r\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\r\n this.ctx=c2;\r\n this.ctx.font = fontsize.toString()+\"px Courier New\";\r\n this.ctx.textBaseline=\"top\";\r\n\r\n c2.fillStyle=backcolor;\r\n this.props.backColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n c2.fillStyle=forecolor;\r\n this.props.foreColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n }\r\n\r\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\r\n\r\n //console.log(\"twrCanvas.constructor props: \", this.props);\r\n }\r\n\r\n isValid() {\r\n return !!this.ctx;\r\n }\r\n\r\n getProxyParams() : TCanvasProxyParams {\r\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\r\n }\r\n\r\n getProp(pn:number): number {\r\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n\r\n/* see draw2d.h for structs that match */\r\n\r\n drawSeq(ds:number) {\r\n //console.log(\"twr::Canvas enter drawSeq\");\r\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\r\n if (!this.ctx) return;\r\n\r\n let ins=this.owner.getLong(ds); /* ds->start */\r\n const lastins=this.owner.getLong(ds+4); /* ds->last */\r\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\r\n\r\n let next:number;\r\n //let insCount=0;\r\n\r\n while (1) {\r\n\r\n //insCount++;\r\n\r\n const type:D2DType=this.owner.getLong(ins+4); /* hdr->type */\r\n if (0/*type!=D2DType.D2D_FILLRECT*/) {\r\n console.log(\"ins\",ins)\r\n console.log(\"hdr.next\",this.owner.mem8[ins],this.owner.mem8[ins+1],this.owner.mem8[ins+2],this.owner.mem8[ins+3]);\r\n console.log(\"hdr.type\",this.owner.mem8[ins+4],this.owner.mem8[ins+5]);\r\n console.log(\"next 4 bytes\", this.owner.mem8[ins+6],this.owner.mem8[ins+7],this.owner.mem8[ins+8],this.owner.mem8[ins+9]);\r\n console.log(\"and 4 more \", this.owner.mem8[ins+10],this.owner.mem8[ins+11],this.owner.mem8[ins+12],this.owner.mem8[ins+13]);\r\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\r\n }\r\n switch (type) {\r\n case D2DType.D2D_FILLRECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.fillRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKERECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.strokeRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILLCHAR:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const c=this.owner.getShort(ins+24);\r\n let txt=String.fromCharCode(c);\r\n this.ctx.fillText(txt, x, y);\r\n }\r\n break;\r\n\r\n \r\n case D2DType.D2D_FILLTEXT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const str=this.owner.getString(this.owner.getLong(ins+24));\r\n\r\n //console.log(\"filltext \",x,y,str)\r\n \r\n this.ctx.fillText(str, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MEASURETEXT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n const tmidx=this.owner.getLong(ins+12);\r\n \r\n const tm=this.ctx.measureText(str);\r\n this.owner.setDouble(tmidx+0, tm.actualBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+8, tm.actualBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+16, tm.actualBoundingBoxLeft);\r\n this.owner.setDouble(tmidx+24, tm.actualBoundingBoxRight);\r\n this.owner.setDouble(tmidx+32, tm.fontBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+40, tm.fontBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+48, tm.width);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFONT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.font=str;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.fillStyle = cssColor;\r\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETSTROKESTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.fillStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETSTROKESTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETLINEWIDTH:\r\n {\r\n const width=this.owner.getShort(ins+8); \r\n this.ctx.lineWidth=width;\r\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MOVETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.moveTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_LINETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.lineTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEZIERTO:\r\n {\r\n const cp1x=this.owner.getDouble(ins+8);\r\n const cp1y=this.owner.getDouble(ins+16);\r\n const cp2x=this.owner.getDouble(ins+24);\r\n const cp2y=this.owner.getDouble(ins+32);\r\n const x=this.owner.getDouble(ins+40);\r\n const y=this.owner.getDouble(ins+48);\r\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEGINPATH:\r\n {\r\n this.ctx.beginPath();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILL:\r\n {\r\n this.ctx.fill();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SAVE:\r\n {\r\n this.ctx.save();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_RESTORE:\r\n {\r\n this.ctx.restore();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKE:\r\n {\r\n this.ctx.stroke();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_ARC:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const radius=this.owner.getDouble(ins+24);\r\n const startAngle=this.owner.getDouble(ins+32);\r\n const endAngle=this.owner.getDouble(ins+40);\r\n const counterClockwise= (this.owner.getLong(ins+48)!=0);\r\n\r\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_IMAGEDATA:\r\n {\r\n const start=this.owner.getLong(ins+8);\r\n const length=this.owner.getLong(ins+12);\r\n const width=this.owner.getLong(ins+16);\r\n const height=this.owner.getLong(ins+20);\r\n const id=this.owner.getLong(ins+24);\r\n\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\r\n\r\n if (this.owner.isWasmModule) {\r\n const z = new Uint8ClampedArray(this.owner.memory!.buffer, start, length);\r\n this.precomputedObjects[id]=new ImageData(z, width, height);\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory\r\n this.precomputedObjects[id]={mem8: new Uint8Array(this.owner.memory!.buffer, start, length), width:width, height:height};\r\n }\r\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_CREATERADIALGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const radius0=this.owner.getDouble(ins+24);\r\n const x1=this.owner.getDouble(ins+32);\r\n const y1=this.owner.getDouble(ins+40);\r\n const radius1=this.owner.getDouble(ins+48);\r\n const id= this.owner.getLong(ins+56);\r\n\r\n let gradient=this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_CREATELINEARGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const x1=this.owner.getDouble(ins+24);\r\n const y1=this.owner.getDouble(ins+32);\r\n const id= this.owner.getLong(ins+40);\r\n \r\n let gradient=this.ctx.createLinearGradient(x0, y0, x1, y1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETCOLORSTOP:\r\n {\r\n const id = this.owner.getLong(ins+8);\r\n const pos=this.owner.getLong(ins+12);\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+16));\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n gradient.addColorStop(pos, cssColor);\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n this.ctx.fillStyle=gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_RELEASEID:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (this.precomputedObjects[id])\r\n delete this.precomputedObjects[id];\r\n else\r\n console.log(\"warning: D2D_RELEASEID with undefined ID \",id);\r\n }\r\n break\r\n\r\n \r\n\r\n case D2DType.D2D_PUTIMAGEDATA:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n const dx=this.owner.getLong(ins+12);\r\n const dy=this.owner.getLong(ins+16);\r\n const dirtyX=this.owner.getLong(ins+20);\r\n const dirtyY=this.owner.getLong(ins+24);\r\n const dirtyWidth=this.owner.getLong(ins+28);\r\n const dirtyHeight=this.owner.getLong(ins+32);\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \"+id);\r\n\r\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\r\n\r\n let imgData:ImageData;\r\n if (this.owner.isWasmModule) {\r\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\r\n imgData=this.precomputedObjects[id] as ImageData;\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\r\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\r\n const z = this.precomputedObjects[id] as {mem8:Uint8Array, width:number, height:number}; // Uint8Array\r\n const ca=Uint8ClampedArray.from(z.mem8); // shallow copy\r\n imgData=new ImageData(ca, z.width, z.height);\r\n }\r\n \r\n if (dirtyWidth==0 && dirtyHeight==0) {\r\n this.ctx.putImageData(imgData, dx, dy);\r\n }\r\n else {\r\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\r\n }\r\n }\r\n break;\r\n\r\n default:\r\n throw new Error (\"unimplemented or unknown Sequence Type in drawSeq: \"+type);\r\n }\r\n next=this.owner.getLong(ins); /* hdr->next */\r\n if (next==0) {\r\n if (ins!=lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\r\n break;\r\n }\r\n ins=next;\r\n }\r\n\r\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\r\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\r\n }\r\n}\r\n\r\nexport class twrCanvasProxy implements ICanvas {\r\n canvasKeys: twrSharedCircularBuffer;\r\n drawCompleteSignal:twrSignal;\r\n props: ICanvasProps;\r\n owner: twrWasmModuleBase;\r\n\r\n constructor(params:TCanvasProxyParams, owner:twrWasmModuleBase) {\r\n const [props, signalBuffer, canvasKeysBuffer] = params;\r\n this.drawCompleteSignal = new twrSignal(signalBuffer);\r\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\r\n this.props=props;\r\n this.owner=owner;\r\n\r\n //console.log(\"Create New twrCanvasProxy: \",this.props)\r\n\r\n }\r\n\r\n charIn() { \r\n //ctx.commit(); not avail in chrome\r\n \r\n //postMessage([\"debug\", 'x']);\r\n \r\n return this.canvasKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.canvasKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n getProp(pn:number): number {\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n \r\n drawSeq(ds:number) {\r\n this.drawCompleteSignal.reset();\r\n postMessage([\"drawseq\", [ds]]);\r\n this.drawCompleteSignal.wait();\r\n }\r\n}\r\n","//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst RDIDX = 256;\nconst WRIDX = 257;\nconst LEN = 256;\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\n// the first 256 array entries are the circular buffer\n// the next two are used for the read and write index\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\nexport class twrSharedCircularBuffer {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(258 * 4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[RDIDX] = 0;\n this.buf[WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[WRIDX];\n this.buf[i] = n;\n i++;\n if (i == LEN)\n i = 0;\n this.buf[WRIDX] = i;\n Atomics.notify(this.buf, WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[RDIDX] = i;\n return n;\n }\n else\n return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[RDIDX] == this.buf[WRIDX];\n }\n}\n//# sourceMappingURL=twrcircular.js.map","//\r\n// This class implements a circular buffer that the main javascript thread can write to, \r\n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\r\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \r\n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\r\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\r\n//\r\n\r\nconst RDIDX=256;\r\nconst WRIDX=257;\r\nconst LEN=256;\r\n\r\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\r\n// the first 256 array entries are the circular buffer\r\n// the next two are used for the read and write index\r\n\r\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\r\n\r\nexport class twrSharedCircularBuffer {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n \r\n\tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(258*4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[RDIDX]=0;\r\n this.buf[WRIDX]=0;\r\n\t}\r\n\r\n\twrite(n:number) {\r\n let i=this.buf[WRIDX];\r\n this.buf[i]=n;\r\n i++;\r\n if (i==LEN) i=0;\r\n this.buf[WRIDX]=i; \r\n Atomics.notify(this.buf, WRIDX); \r\n\t}\r\n\r\n\tread():number {\r\n if (!this.isEmpty()) {\r\n let i=this.buf[RDIDX];\r\n let n=this.buf[i];\r\n i++;\r\n this.buf[RDIDX]=i;\r\n return n;\r\n }\r\n\t\telse\r\n return -1;\r\n\t}\r\n\r\n readWait():number {\r\n if (this.isEmpty()) {\r\n const rdptr=this.buf[RDIDX];\r\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\r\n Atomics.wait(this.buf, WRIDX, rdptr);\r\n }\r\n return this.read();\r\n\t}\r\n\r\n isEmpty():boolean {\r\n return this.buf[RDIDX]==this.buf[WRIDX];\r\n }\r\n}\r\n","//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar twrSignalState;\n(function (twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})(twrSignalState || (twrSignalState = {}));\n;\nexport class twrSignal {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window valid\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == twrSignalState.WAITING) {\n //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\n //console.log(\"released...\");\n }\n }\n isSignaled() {\n return this.buf[0] == twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = twrSignalState.WAITING;\n }\n}\n//# sourceMappingURL=twrsignal.js.map","//\r\n// This class implements a simple signal/wait mechanism\r\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\r\n//\r\n\r\nenum twrSignalState {\r\n WAITING=0,\r\n SIGNALED=1\r\n};\r\n\r\nexport class twrSignal {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n\r\n \tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window valid\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) \r\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[0]=twrSignalState.WAITING;\r\n\t}\r\n\r\n\tsignal() {\r\n this.buf[0]=twrSignalState.SIGNALED; \r\n //console.log(\"about to signal\");\r\n Atomics.notify(this.buf, 0); \r\n\t}\r\n\r\n wait() {\r\n if (this.buf[0]==twrSignalState.WAITING) {\r\n //console.log(\"waiting...\");\r\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\r\n //console.log(\"released...\");\r\n\r\n }\r\n\t}\r\n isSignaled():boolean {\r\n return this.buf[0]==twrSignalState.SIGNALED;\r\n }\r\n\r\n reset() {\r\n this.buf[0]=twrSignalState.WAITING;\r\n }\r\n}\r\n","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nexport class twrDiv {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase) {\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\n this.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n if (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.divKeys.sharedArray];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */\n charOut(ch) {\n if (!this.div)\n return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n }\n switch (ch) {\n case 10: // newline\n case 13: // return\n if (ch == 10 && this.lastChar == 13)\n break; // detect CR LF and treat as single new line\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8: // backspace\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n case 0xE: // cursor on\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF: // cursor off\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for (let i = 0; i < str.length; i++)\n this.charOut(str.charCodeAt(i));\n }\n}\nexport class twrDivProxy {\n divKeys;\n constructor(params) {\n const [divKeysBuffer] = params;\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n charOut(ch) {\n postMessage([\"divout\", ch]);\n }\n}\n//# sourceMappingURL=twrdiv.js.map","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\r\nimport { IModParams } from \"./twrmodbase.js\";\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\";\r\n\r\nexport type TDivProxyParams = [SharedArrayBuffer];\r\n\r\nexport interface IDiv {\r\n charOut: (ds:number)=>void,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TDivProxyParams,\r\n }\r\n\r\n\r\nexport class twrDiv implements IDiv {\r\n\tdiv:HTMLDivElement|null|undefined;\r\n\tdivKeys?:twrSharedCircularBuffer;\r\n\tCURSOR=String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\r\n\tcursorOn:boolean=false;\r\n\tlastChar:number=0;\r\n\textraBR:boolean=false;\r\n\towner:twrWasmModuleBase;\r\n\r\n constructor(element:HTMLDivElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n\t\tthis.div=element;\r\n\t\tthis.owner=modbase;\r\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\r\n\t\t\tthis.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n\t\t}\r\n\r\n\t\tif (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\r\n\t\t\tthis.div.style.backgroundColor = modParams.backcolor;\r\n\t\t\tthis.div.style.color = modParams.forecolor;\r\n\t\t\tthis.div.style.font=modParams.fontsize.toString()+\"px arial\"\r\n\t\t}\r\n }\r\n\r\n\tisValid() {\r\n\t\treturn !!this.div;\r\n\t}\r\n\r\n getProxyParams() : TDivProxyParams {\r\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [ this.divKeys.sharedArray];\r\n }\r\n\r\n\r\n/* \r\n * add character to div. Supports the following control codes:\r\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\r\n * 0xE cursor on \r\n * 0x8 backspace\r\n * 0xF cursor off \r\n*/\r\n\tcharOut(ch:number) {\r\n\r\n\t\tif (!this.div) return;\r\n\r\n\t\t//console.log(\"div::charout: \", ch);\r\n\r\n\t\tif (this.extraBR) {\r\n\t\t\tthis.extraBR=false;\r\n\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -4);\r\n\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t}\r\n\r\n\t\tswitch (ch) {\r\n\t\t\tcase 10: // newline\r\n\t\t\tcase 13: // return\r\n\t\t\t\tif (ch==10 && this.lastChar==13) break; // detect CR LF and treat as single new line\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\r\n\t\t\t\tthis.extraBR=true;\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\t//element.scrollIntoView();\r\n\t\t\t\t//element.scrollTop = element.scrollHeight;\r\n\t\t\t\tlet p = this.div.getBoundingClientRect();\r\n\t\t\t\twindow.scrollTo(0, p.height+100);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 8: // backspace\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xE: // cursor on\r\n\t\t\t\tif (!this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=true;\r\n\t\t\t\t\tthis.div.innerHTML += this.CURSOR;\r\n\t\t\t\t\tthis.div.focus();\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xF: // cursor off\r\n\t\t\t\tif (this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=false;\r\n\t\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += String.fromCharCode(ch);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\tthis.lastChar=ch;\r\n\t}\r\n\r\n\tstringOut(str:string) {\r\n\t\tfor (let i=0; i < str.length; i++)\r\n\t\t\tthis.charOut(str.charCodeAt(i));\r\n\t}\r\n}\r\n\r\n\r\nexport class twrDivProxy implements IDiv {\r\n divKeys: twrSharedCircularBuffer;\r\n\r\n constructor(params:TDivProxyParams) {\r\n const [divKeysBuffer] = params;\r\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\r\n }\r\n\r\n charIn() { \r\n return this.divKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.divKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n\tcharOut(ch:number) {\r\n\t\tpostMessage([\"divout\", ch]);\r\n\t}\r\n}\r\n\r\n","let logline = \"\";\nexport function twrDebugLogImpl(char) {\n if (char == 10 || char == 3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\n console.log(logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n logline = \"\";\n }\n else {\n logline = logline + String.fromCharCode(char);\n if (logline.length >= 200) {\n console.log(logline);\n logline = \"\";\n }\n }\n}\n// ************************************************************************\n// debugLog doesn't currently wait for the message to log, it returns immediately.\n// I could move this to be in the twrWaitingCalls class\nexport function twrDebugLogProxy(ch) {\n postMessage([\"debug\", ch]);\n}\n//# sourceMappingURL=twrdebug.js.map","\r\nlet logline=\"\";\r\nexport function twrDebugLogImpl(char:number) {\r\n\tif (char==10 || char==3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\r\n\t\tconsole.log(logline);\t// ideally without a linefeed, but there is no way to not have a LF with console.log API.\r\n\t\tlogline=\"\";\r\n\t}\r\n\telse {\r\n\t\tlogline=logline+String.fromCharCode(char);\r\n\t\tif (logline.length>=200) {\r\n\t\t\tconsole.log(logline);\r\n\t\t\tlogline=\"\";\r\n\t\t}\r\n\t}\r\n}\r\n\r\n// ************************************************************************\r\n// debugLog doesn't currently wait for the message to log, it returns immediately.\r\n// I could move this to be in the twrWaitingCalls class\r\nexport function twrDebugLogProxy(ch:number) {\r\n postMessage([\"debug\", ch]);\r\n}\r\n\r\n","import { twrFloatUtil } from \"./twrfloat.js\";\n/*********************************************************************/\n/*********************************************************************/\n/*********************************************************************/\nexport class twrWasmModuleBase {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\n floatUtil;\n constructor(isWasmModule = false) {\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new twrFloatUtil(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/\n /*********************************************************************/\n async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n }\n catch (err) {\n console.log('loadWasm() failed to fetch: ' + pathToLoad);\n throw err;\n }\n if (!response.ok)\n throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, { env: allimports });\n this.exports = instance.instance.exports;\n if (!this.exports)\n throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory)\n throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory)\n throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer)\n console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\"setmemory\", this.memory]);\n }\n if (this.isWasmModule) {\n // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (!(this.memory.buffer instanceof ArrayBuffer))\n console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size) => {\n return new Promise(resolve => {\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n }\n catch (err) {\n console.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch (this.modParams.stdio) {\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* executeC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */\n async executeC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.executeCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async executeCImpl(fname, cparams = []) {\n if (!this.exports)\n throw new Error(\"this.exports undefined\");\n if (!this.exports[fname])\n throw new Error(\"executeC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array))\n throw new Error(\"executeC: params must be array, first arg is function name\");\n if (params.length == 0)\n throw new Error(\"executeC: missing function name\");\n let cparams = [];\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n cparams[ci++] = p;\n break;\n case 'string':\n cparams[ci++] = await this.putString(p);\n break;\n case 'object':\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n }\n else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"executeC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n ci++;\n break;\n case 'string':\n this.executeCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n case 'object':\n if (p instanceof URL) {\n this.executeCImpl('twr_free', [cparams[ci]]);\n ci = ci + 2;\n break;\n }\n else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for (let j = 0; j < u8.length; j++)\n u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.executeCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n }\n else\n throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/\n /*********************************************************************/\n // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for (i = 0; i < sin.length && i < buffer_size - 1; i++)\n this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for (let i = 0; i < u8a.length; i++)\n this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === 'object' && fnin instanceof URL))\n throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [dest, src.length];\n }\n catch (err) {\n console.log('fetchAndPutURL Error. URL: ' + fnin + '\\n' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while (this.mem8[strIndex + i] && (len === undefined ? true : i < len) && (strIndex + i) < this.mem8.length) {\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0)\n throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array((this.mem8.slice(dataptr, dataptr + size)).buffer);\n return u32;\n }\n}\n//# sourceMappingURL=twrmodbase.js.map","\r\nimport {TCanvasProxyParams} from \"./twrcanvas.js\"\r\nimport {TDivProxyParams} from \"./twrdiv.js\";\r\nimport {TWaitingCallsProxyParams} from \"./twrwaitingcalls.js\"\r\nimport {twrDebugLogImpl} from \"./twrdebug.js\";\r\nimport {twrFloatUtil} from \"./twrfloat.js\";\r\n\r\n\r\nexport type TStdioVals=\"div\"|\"canvas\"|\"null\"|\"debug\";\r\n\r\nexport interface IModOpts {\r\n\tstdio?:TStdioVals, \r\n\twindim?:[number, number],\r\n\tforecolor?:string,\r\n\tbackcolor?:string,\r\n\tfontsize?:number,\r\n\tisd2dcanvas?:boolean,\r\n\timports?:{},\r\n}\r\n\r\nexport interface IModParams {\r\n\tstdio:TStdioVals, \r\n\twindim:[number, number],\r\n\tforecolor:string,\r\n\tbackcolor:string,\r\n\tfontsize:number,\r\n\tstyleIsDefault: boolean\r\n\tisd2dcanvas:boolean,\r\n\timports:{[index:string]:Function},\r\n}\r\n\r\nexport interface IModInWorkerParams {\r\n\tdivProxyParams:TDivProxyParams,\r\n\tcanvasProxyParams:TCanvasProxyParams,\r\n\twaitingCallsProxyParams:TWaitingCallsProxyParams,\r\n}\r\n\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n\r\nexport abstract class twrWasmModuleBase {\r\n\tmemory?:WebAssembly.Memory;\r\n\tmem8:Uint8Array;\r\n\tmem32:Uint32Array;\r\n\tmemD:Float64Array;\r\n\tabstract malloc:(size:number)=>Promise;\r\n\tabstract modParams:IModParams;\r\n\texports?:WebAssembly.Exports;\r\n\tisWorker=false;\r\n\tisWasmModule:boolean; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\r\n\tfloatUtil:twrFloatUtil;\r\n\r\n\tconstructor(isWasmModule=false) {\r\n\t\tthis.isWasmModule=isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\r\n\t\tthis.mem8=new Uint8Array(); \t// avoid type errors\r\n\t\tthis.mem32=new Uint32Array(); // avoid type errors\r\n\t\tthis.memD=new Float64Array(); // avoid type errors\r\n\t\tthis.floatUtil=new twrFloatUtil(this);\r\n\t\t//console.log(\"size of mem8 after constructor\",this.mem8.length);\r\n\t}\r\n\r\n\t/*********************************************************************/\r\n\t/*********************************************************************/\r\n\r\n\tasync loadWasm(pathToLoad:string) {\r\n\t\t//console.log(\"fileToLoad\",fileToLoad)\r\n\r\n\t\tlet response;\r\n\t\ttry {\r\n\t\t\tresponse=await fetch(pathToLoad);\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('loadWasm() failed to fetch: '+pathToLoad);\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t\t\r\n\t\tif (!response.ok) throw new Error(\"fetch response error on file '\"+pathToLoad+\"'\\n\"+response.statusText);\r\n\r\n\t\ttry {\r\n\t\t\tlet wasmBytes = await response.arrayBuffer();\r\n\r\n\t\t\tlet allimports:WebAssembly.ModuleImports = { \r\n\t\t\t\t...this.modParams.imports\r\n\t\t\t};\r\n\r\n\t\t\tlet instance = await WebAssembly.instantiate(wasmBytes, {env: allimports});\r\n\r\n\t\t\tthis.exports=instance.instance.exports;\r\n\t\t\tif (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\r\n\r\n\t\t\tif (this.memory) throw new Error (\"unexpected error -- this.memory already set\");\r\n\t\t\tthis.memory=this.exports.memory as WebAssembly.Memory;\r\n\t\t\tif (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\r\n\t\t\tthis.mem8 = new Uint8Array(this.memory.buffer);\r\n\t\t\tthis.mem32 = new Uint32Array(this.memory.buffer);\r\n\t\t\tthis.memD = new Float64Array(this.memory.buffer);\r\n\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\tif (this.isWorker) {\r\n\t\t\t\tif (this.memory.buffer instanceof ArrayBuffer)\r\n\t\t\t\t\tconsole.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\r\n\t\t\t\t\r\n\t\t\t\tpostMessage([\"setmemory\",this.memory]);\r\n\t\t\t}\r\n\t\t\tif (this.isWasmModule) {\r\n\t\t\t\t// here if twrWasmModule, twrWasmModuleAsync overrides this function\r\n\t\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\t\tif (!(this.memory.buffer instanceof ArrayBuffer))\r\n\t\t\t\t\tconsole.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\r\n\t\t\t}\r\n\r\n\t\t\tthis.malloc=(size:number)=>{\r\n\t\t\t\treturn new Promise(resolve => {\r\n\t\t\t\t\tconst m=this.exports!.twr_malloc as (size:number)=>number;\r\n\t\t\t\t\tresolve(m(size));\r\n\t\t\t\t});\r\n\t\t };\r\n\r\n\t\t\tthis.init();\r\n\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t}\r\n\r\n\tprivate init() {\r\n\t\t//console.log(\"loadWasm.init() enter\")\r\n\t\t\tlet p:number;\r\n\t\t\tswitch (this.modParams.stdio) {\r\n\t\t\t\tcase \"debug\":\r\n\t\t\t\t\tp=0;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"div\":\r\n\t\t\t\t\tp=1;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"canvas\":\r\n\t\t\t\t\tp=2;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"null\":\r\n\t\t\t\t\tp=3;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tp=0; // debug\r\n\t\t\t}\r\n\r\n\t\t\tconst twrInit=this.exports!.twr_wasm_init as CallableFunction;\r\n\t\t\t//console.log(\"twrInit:\",twrInit)\r\n\t\t\ttwrInit(p, this.mem8.length);\r\n\t}\r\n\r\n\t/* executeC takes an array where:\r\n\t* the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\r\n\t* and the next entries are a variable number of parameters to pass to the C function, of type\r\n\t* number - converted to int32 or float64 as appropriate\r\n\t* string - converted to a an index (ptr) into a module Memory returned via stringToMem()\r\n\t* URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\r\n\t* Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\r\n */\r\n\r\n\tasync executeC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\t\tconst cparams=await this.preCallC(params);\r\n\t\tlet retval = this.executeCImpl(params[0], cparams);\r\n\t\tthis.postCallC(cparams, params);\r\n\t\treturn retval;\r\n\t}\r\n\r\n\tasync executeCImpl(fname:string, cparams:number[]=[]) {\r\n\t\tif (!this.exports) throw new Error(\"this.exports undefined\");\r\n\t\tif (!this.exports[fname]) throw new Error(\"executeC: function '\"+fname+\"' not in export table. Use --export wasm-ld flag.\");\r\n\r\n\t\tconst f = this.exports[fname] as CallableFunction;\r\n\t\tlet cr=f(...cparams);\r\n\r\n\t\treturn cr;\r\n\t}\r\n\r\n\t// convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\r\n\tasync preCallC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tif (!(params.constructor === Array)) throw new Error (\"executeC: params must be array, first arg is function name\");\r\n\t\tif (params.length==0) throw new Error(\"executeC: missing function name\");\r\n\r\n\t\tlet cparams:number[]=[];\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tcparams[ci++]=p;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tcparams[ci++]=await this.putString(p);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tconst r=await this.fetchAndPutURL(p);\r\n\t\t\t\t\t\tcparams[ci++]=r[0]; // mem index\r\n\t\t\t\t\t\tcparams[ci++]=r[1]; // len\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tconst r=await this.putArrayBuffer(p);\r\n\t\t\t\t\t\tcparams[ci++]=r; // mem index\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tthrow new Error (\"executeC: invalid object type passed in\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn cparams;\r\n\t}\r\n\r\n\t// free the mallocs; copy array buffer data from malloc back to arraybuffer\r\n\tasync postCallC(cparams:number[], params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tthis.executeCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t\t\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tthis.executeCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\t\tci=ci+2;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tlet u8=new Uint8Array(p);\r\n\t\t\t\t\t\tfor (let j=0; j= this.mem32.length) throw new Error(\"invalid index passed to getLong: \"+idx+\", this.mem32.length: \"+this.mem32.length);\r\n\t\tconst long:number = this.mem32[idx32];\r\n\t\treturn long;\r\n\t}\r\n\t\r\n\tsetLong(idx:number, value:number) {\r\n const idx32 = Math.floor(idx / 4);\r\n if (idx32 * 4 != idx)\r\n throw new Error(\"setLong passed non long aligned address\");\r\n if (idx32 < 0 || idx32 >= this.mem32.length)\r\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\r\n this.mem32[idx32]=value;\r\n }\r\n\r\n\tgetDouble(idx:number): number {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"getLong passed non Float64 aligned address\")\r\n\t\tconst long:number = this.memD[idx64];\r\n\t\treturn long;\r\n\t}\r\n\r\n\tsetDouble(idx:number, value:number) {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"setDouble passed non Float64 aligned address\")\r\n\t\tthis.memD[idx64]=value;\r\n\t}\r\n\r\n\tgetShort(idx:number): number {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getShort: \"+idx);\r\n\t\tconst short:number = this.mem8[idx]+this.mem8[idx+1]*256;\r\n\t\treturn short;\r\n\t}\r\n\r\n\t// get a string out of module memory\r\n\t// null terminated, up until max of (optional) len\r\n\tgetString(strIndex:number, len?:number): string {\r\n\t\tlet sout=\"\";\r\n\r\n\t\tlet i=0;\r\n\t\twhile (this.mem8[strIndex+i] && (len===undefined?true:i= this.mem8.length) throw new Error(\"invalid index passed to getU8: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU8\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU8\")\r\n\r\n\t\tconst u8=this.mem8.slice(dataptr, dataptr+size);\r\n\t\treturn u8;\r\n\t}\r\n\r\n\t// get a int32 array out of module memory when passed in index to [size, dataptr]\r\n\tgetU32Arr(idx:number): Uint32Array {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getU32: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU32\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU32\")\r\n\r\n\t\tif (size%4!=0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\r\n\r\n\t\tconst u32 = new Uint32Array( (this.mem8.slice(dataptr, dataptr+size)).buffer );\r\n\t\treturn u32;\r\n\t}\r\n}\r\n","export class twrFloatUtil {\n mod;\n constructor(mod) {\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\")\n return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\")\n return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll('D', 'e').replaceAll('d', 'e'));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n }\n else {\n let r = value.toString();\n if (r.length > max_precision)\n r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, // char *\n sizeInBytes, //size_t\n value, // double\n fracpart_numdigits, //int\n dec, // int *\n sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1)\n return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) { /* nan */\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (!Number.isFinite(value)) { /* infinity */\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n }\n else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split('.');\n if (intPart == \"0\")\n intPart = \"\";\n if (intPart.length > 0) { // has integer part\n decpos = intPart.length;\n digits = intPart + fracPart;\n }\n else { // only a fraction\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length)\n return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */\n }\n}\n//# sourceMappingURL=twrfloat.js.map","\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\"\r\n\r\nexport class twrFloatUtil {\r\n mod: twrWasmModuleBase;\r\n\r\n constructor(mod: twrWasmModuleBase) {\r\n this.mod=mod;\r\n }\r\n\r\n atod(strptr:number):number {\r\n const str=this.mod.getString(strptr);\r\n\r\n const upper=str.trimStart().toUpperCase();\r\n if (upper==\"INF\" || upper==\"+INF\")\r\n return Number.POSITIVE_INFINITY;\r\n else if (upper==\"-INF\")\r\n return Number.NEGATIVE_INFINITY\r\n else {\r\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\r\n const r=Number.parseFloat(str.replaceAll('D','e').replaceAll('d','e'));\r\n return r;\r\n }\r\n }\r\n\r\n dtoa(buffer:number, buffer_size:number, value:number, max_precision:number):void {\r\n if (max_precision==-1) {\r\n const r=value.toString();\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n else {\r\n let r=value.toString();\r\n if (r.length>max_precision)\r\n r=value.toPrecision(max_precision);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n }\r\n\r\n toFixed(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toFixed(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n toExponential(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toExponential(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\r\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\r\n // Negative exponents must be now smaller than 1e-99\r\n // fully-function C version also int he source, but this is the version enabled by default\r\n fcvtS(\r\n buffer:number, // char *\r\n sizeInBytes:number, //size_t\r\n value:number, // double\r\n fracpart_numdigits:number, //int\r\n dec:number, // int *\r\n sign:number // int *\r\n ):number {\r\n\r\n if (buffer==0 ||sign==0 || dec==0 || sizeInBytes<1) return 1;\r\n\r\n let digits:string;\r\n let decpos:number;\r\n let s=0; // default to positive\r\n\r\n\r\n if (Number.isNaN(value)) { /* nan */\r\n digits=\"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (!Number.isFinite(value)) { /* infinity */\r\n digits=\"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (value==0) { \r\n digits=\"000000000000000000000000000000000000\".slice(0,fracpart_numdigits);\r\n decpos=0;\r\n }\r\n \r\n else {\r\n\r\n if (value<0) {\r\n s=1; // negative\r\n value=Math.abs(value);\r\n }\r\n\r\n if (fracpart_numdigits>100 || value > 1e+21 || value < 1e-99) { \r\n this.mod.copyString(buffer, sizeInBytes, \"\");\r\n this.mod.mem32[dec]=0;\r\n return 1;\r\n }\r\n\r\n const roundValStr=value.toFixed(fracpart_numdigits);\r\n let [intPart=\"\", fracPart=\"\"] = roundValStr.split('.');\r\n if (intPart==\"0\") intPart=\"\";\r\n\r\n if (intPart.length>0) { // has integer part\r\n decpos=intPart.length;\r\n digits=intPart+fracPart;\r\n }\r\n else { // only a fraction\r\n digits=fracPart.replace(/^0+/,\"\"); // remove leading zeros\r\n decpos=digits.length-fracPart.length;\r\n }\r\n }\r\n\r\n if (sizeInBytes-1 < digits.length) return 1; \r\n this.mod.copyString(buffer, sizeInBytes, digits);\r\n this.mod.setLong(dec, decpos);\r\n this.mod.setLong(sign, s);\r\n\r\n return 0;\r\n\r\n /*\r\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\r\n\r\n let decpos=0;\r\n let digits:string;\r\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\r\n \r\n if (decpos>0) { // has integer part\r\n const intlen=Math.max(decpos, 0);\r\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\r\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\r\n }\r\n else { // only a fraction\r\n const intpart=Math.trunc(value);\r\n const fracpart=value-intpart;\r\n const prec=fracpart_numdigits- (-decpos);\r\n console.log(\"prec=\",prec);\r\n if (prec<1) {\r\n digits=\"\";\r\n }\r\n else {\r\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\");\r\n }\r\n }\r\n\r\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\r\n console.log('digits=',digits);\r\n console.log('dec=',decpos);\r\n console.log(\"sign=\",s);\r\n */\r\n\r\n\r\n }\r\n}","import { twrSignal } from \"./twrsignal.js\";\nimport { twrTimeImpl } from \"./twrdate.js\";\n// This class is used in the Main JS thread \nexport class twrWaitingCalls {\n callCompleteSignal;\n parameters;\n constructor() {\n this.callCompleteSignal = new twrSignal();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(() => {\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = twrTimeImpl();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [this.callCompleteSignal.sharedArray, this.parameters.buffer];\n }\n processMessage(msgType, data) {\n switch (msgType) {\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\n// This class is used in the worker thread \nexport class twrWaitingCallsProxy {\n callCompleteSignal;\n parameters;\n constructor(params) {\n this.callCompleteSignal = new twrSignal(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\"sleep\", [ms]]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\"time\"]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n//# sourceMappingURL=twrwaitingcalls.js.map","import { twrSignal } from \"./twrsignal.js\";\r\nimport {twrTimeImpl} from \"./twrdate.js\"\r\n\r\n// These classes are used to proxy a call across the worker thread - main thread boundary and wait for the result\r\n\r\nexport type TWaitingCallsProxyParams = [SharedArrayBuffer, SharedArrayBuffer]; // twrSignal, parameters \r\n\r\n// This class is used in the Main JS thread \r\nexport class twrWaitingCalls {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor() {\r\n\t\tthis.callCompleteSignal=new twrSignal();\r\n\t\tthis.parameters=new Uint32Array(new SharedArrayBuffer(4));\r\n\t}\r\n\r\n\tprivate startSleep(ms:number) {\r\n\r\n\t\tsetTimeout(()=>{\r\n\t\t\tthis.callCompleteSignal.signal();\r\n\t\t}, ms);\r\n\t\t\r\n\t}\r\n\r\n\tprivate time() {\r\n\t\tconst ms=twrTimeImpl();\r\n\t\tthis.parameters[0]=ms;\r\n\t\tthis.callCompleteSignal.signal();\r\n\t}\r\n\r\n\tgetProxyParams():TWaitingCallsProxyParams {\r\n\t\treturn [this.callCompleteSignal.sharedArray, this.parameters.buffer as SharedArrayBuffer];\t\r\n\t}\r\n\r\n\tprocessMessage(msgType:string, data:any[]):boolean {\r\n\t\tswitch (msgType) {\r\n\t\t\tcase \"sleep\":\r\n\t\t\t\tconst [ms] = data;\r\n\t\t\t\tthis.startSleep(ms);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"time\":\r\n\t\t\t\tthis.time();\r\n\t\t\t\tbreak;\r\n\t\t\t\r\n\t\t\tdefault:\r\n\t\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\treturn true;\r\n\t}\r\n\r\n}\r\n\r\n// This class is used in the worker thread \r\nexport class twrWaitingCallsProxy {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor(params:TWaitingCallsProxyParams) {\r\n\t\tthis.callCompleteSignal=new twrSignal(params[0]);\r\n\t\tthis.parameters=new Uint32Array(params[1]);\r\n\t}\r\n\r\n\tsleep(ms:number) {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"sleep\", [ms]]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t}\r\n\r\n\ttime() {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"time\"]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t\treturn this.parameters[0];\r\n\t}\r\n\r\n}\r\n","export function twrTimeImpl() {\n return Date.now();\n}\n//# sourceMappingURL=twrdate.js.map","\r\nexport function twrTimeImpl() {\r\n\r\n return Date.now();\r\n\r\n}"],"names":["$b93f1fdf40141def$var$twrSignalState","$c4741cac81d14197$var$D2DType","twrSignalState","D2DType","$3e39efa823870787$var$mod","$892fccfc812d5e20$export$a01cca24f011573a","sharedArray","buf","constructor","sa","window","crossOriginIsolated","location","protocol","Error","SharedArrayBuffer","Int32Array","write","n","i","Atomics","notify","read","isEmpty","readWait","rdptr","wait","$b93f1fdf40141def$export$e37a7b7b851b97f3","WAITING","signal","SIGNALED","isSignaled","reset","$c4741cac81d14197$export$c779b2cd00544976","canvasKeys","drawCompleteSignal","props","owner","params","signalBuffer","canvasKeysBuffer","charIn","inkey","getProp","pn","propName","getString","drawSeq","ds","postMessage","$8963973702ae5462$export$b377f0bbf2c7581e","divKeys","divKeysBuffer","charOut","ch","$8ac0b786da854328$export$485af4d0039b3389","$e72303a1db04bdfa$export$918ffb7e046a537b","mod","atod","strptr","str","upper","trimStart","toUpperCase","Number","POSITIVE_INFINITY","NEGATIVE_INFINITY","parseFloat","replaceAll","dtoa","buffer","buffer_size","value","max_precision","r","toString","copyString","length","toPrecision","toFixed","decdigits","toExponential","fcvtS","sizeInBytes","fracpart_numdigits","dec","sign","digits","decpos","s","isNaN","slice","isFinite","Math","abs","mem32","intPart","fracPart","roundValStr","split","replace","setLong","$ece7fa3ed770778a$export$c83a0a3bffe07399","memory","mem8","memD","exports","isWorker","isWasmModule","floatUtil","Uint8Array","Uint32Array","Float64Array","loadWasm","pathToLoad","response","fetch","err","console","log","ok","statusText","wasmBytes","arrayBuffer","allimports","modParams","imports","instance","WebAssembly","instantiate","env","ArrayBuffer","malloc","size","Promise","resolve","m","twr_malloc","init","stack","p","stdio","twrInit","twr_wasm_init","executeC","cparams","preCallC","retval","executeCImpl","postCallC","fname","f","Array","ci","putString","URL","fetchAndPutURL","putArrayBuffer","u8","j","sin","charCodeAt","strIndex","putU8","u8a","dest","ab","fnin","src","getLong","idx","idx32","floor","getDouble","idx64","setDouble","getShort","len","sout","undefined","String","fromCharCode","getU8Arr","rv","dataptr","getU32Arr","$aff9c2c494d23fe3$export$78d2a4633fe89379","callCompleteSignal","parameters","sleep","ms","time","onmessage","e","data","$3e39efa823870787$var$twrWasmModuleInWorker","modWorkerParams","urlToLoad","then","catch","ex","rc","modInWorkerParams","canvasProxy","canvasProxyParams","divProxy","divProxyParams","waitingCallsProxy","waitingCallsProxyParams","twrDebugLog","twrSleep","bind","twrTime","twrDivCharOut","twrDivCharIn","twrCanvasCharIn","twrCanvasInkey","twrCanvasGetProp","twrCanvasDrawSeq","twrSin","twrCos","cos","twrTan","tan","twrFAbs","twrACos","acos","twrASin","asin","twrATan","atan","twrExp","exp","twrFloor","twrCeil","ceil","twrFMod","x","y","twrLog","twrPow","pow","twrSqrt","sqrt","twrTrunc","trunc","twrDtoa","twrToFixed","twrToExponential","twrAtod","twrFcvtS"],"version":3,"file":"twrmodworker.2165e649.js.map"} \ No newline at end of file +{"mappings":"A,C,SQKK,EJgBA,EIhBA,EJgBA,MFZD,CISE,OAAO,EACZ,WAA8B,AAC9B,CAAA,GAAe,AAEf,aAAa,CAAqB,CAAlC,CACO,GAAI,AAAkB,aAAlB,OAAO,QACH,CAAC,qBAAuB,AAA+B,UAA7B,OAAO,QAAQ,CAAC,QAAQ,CAAe,MAAM,AAAI,MAAM,4DAA4D,oBAAoB,iCAErK,EAAI,IAAI,CAAC,WAAW,CAAC,EACpB,IAAI,CAAC,WAAW,CAAC,IAAI,kBAAkB,MAClD,IAAI,CAAC,GAAG,CAAC,IAAI,WAAW,IAAI,CAAC,WAAW,EAClC,IAAI,CAAC,GAAG,CArBJ,IAqBW,CAAC,EAChB,IAAI,CAAC,GAAG,CArBJ,IAqBW,CAAC,CACvB,CAEA,MAAM,CAAQ,CAAd,CACO,IAAI,EAAE,IAAI,CAAC,GAAG,CAzBV,IAyBiB,AACrB,CAAA,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAzBV,OA2BE,GAAQ,CAAA,EAAE,CAAA,EACd,IAAI,CAAC,GAAG,CA7BJ,IA6BW,CAAC,EAChB,QAAQ,MAAM,CAAC,IAAI,CAAC,GAAG,CA9BnB,IA+BX,CAEA,MAAA,CACO,GAAK,IAAI,CAAC,OAAO,GAQb,OAAO,EARU,EACjB,IA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C,IAAI,CAAC,GAEpC,cAAc,EAAS,OAAO,CAAC,IAAI,CAAC,GACpC,aAAa,EAAS,MAAM,CAAC,IAAI,CAAC,GAElC,gBAAgB,EAAY,MAAM,CAAC,IAAI,CAAC,GACxC,eAAe,EAAY,KAAK,CAAC,IAAI,CAAC,GACtC,iBAAiB,EAAY,OAAO,CAAC,IAAI,CAAC,GAC1C,iBAAiB,EAAY,OAAO,CAAC,IAAI,CAAC,GAEnD,OAAO,KAAK,GAAG,CACf,OAAO,KAAK,GAAG,CACf,OAAQ,KAAK,GAAG,CAChB,QAAS,KAAK,GAAG,CACjB,QAAS,KAAK,IAAI,CAClB,QAAS,KAAK,IAAI,CAClB,QAAS,KAAK,IAAI,CAClB,OAAQ,KAAK,GAAG,CAChB,SAAU,KAAK,KAAK,CACpB,QAAS,KAAK,IAAI,CAClB,QAAS,SAAS,CAAQ,CAAE,CAAQ,EAAG,OAAO,EAAE,CAAC,EACjD,OAAQ,KAAK,GAAG,CAChB,OAAQ,KAAK,GAAG,CAChB,QAAS,KAAK,IAAI,CAClB,SAAU,KAAK,KAAK,CAEX,QAAS,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EACzD,WAAY,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EACtD,iBAAkB,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAClE,QAAS,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAChD,SAAU,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAE5C,CACN,CACF,C,C","sources":["","../../lib-js/twrmodworker.js","../../source/twr-wasm-ts/twrmodworker.ts","../../lib-js/twrcanvas.js","../../source/twr-wasm-ts/twrcanvas.ts","../../lib-js/twrcircular.js","../../source/twr-wasm-ts/twrcircular.ts","../../lib-js/twrsignal.js","../../source/twr-wasm-ts/twrsignal.ts","../../lib-js/twrdiv.js","../../source/twr-wasm-ts/twrdiv.ts","../../lib-js/twrdebug.js","../../source/twr-wasm-ts/twrdebug.ts","../../lib-js/twrmodbase.js","../../source/twr-wasm-ts/twrmodbase.ts","../../lib-js/twrfloat.js","../../source/twr-wasm-ts/twrfloat.ts","../../lib-js/twrwaitingcalls.js","../../source/twr-wasm-ts/twrwaitingcalls.ts","../../lib-js/twrdate.js","../../source/twr-wasm-ts/twrdate.ts"],"sourcesContent":["(() => {\nvar $3e39efa823870787$exports = {};\n// this script is the WebWorker thead used by class twrWasmAsyncModule\n//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst $892fccfc812d5e20$var$RDIDX = 256;\nconst $892fccfc812d5e20$var$WRIDX = 257;\nconst $892fccfc812d5e20$var$LEN = 256;\nclass $892fccfc812d5e20$export$a01cca24f011573a {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(1032);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[$892fccfc812d5e20$var$RDIDX] = 0;\n this.buf[$892fccfc812d5e20$var$WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[$892fccfc812d5e20$var$WRIDX];\n this.buf[i] = n;\n i++;\n if (i == $892fccfc812d5e20$var$LEN) i = 0;\n this.buf[$892fccfc812d5e20$var$WRIDX] = i;\n Atomics.notify(this.buf, $892fccfc812d5e20$var$WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[$892fccfc812d5e20$var$RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[$892fccfc812d5e20$var$RDIDX] = i;\n return n;\n } else return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[$892fccfc812d5e20$var$RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, $892fccfc812d5e20$var$WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[$892fccfc812d5e20$var$RDIDX] == this.buf[$892fccfc812d5e20$var$WRIDX];\n }\n}\n\n\n//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar $b93f1fdf40141def$var$twrSignalState;\n(function(twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})($b93f1fdf40141def$var$twrSignalState || ($b93f1fdf40141def$var$twrSignalState = {}));\nclass $b93f1fdf40141def$export$e37a7b7b851b97f3 {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == $b93f1fdf40141def$var$twrSignalState.WAITING) //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, $b93f1fdf40141def$var$twrSignalState.WAITING);\n }\n isSignaled() {\n return this.buf[0] == $b93f1fdf40141def$var$twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.WAITING;\n }\n}\n\n\nvar $c4741cac81d14197$var$D2DType;\n(function(D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})($c4741cac81d14197$var$D2DType || ($c4741cac81d14197$var$D2DType = {}));\nclass $c4741cac81d14197$export$2f298dd69cef3c34 {\n ctx;\n props = {\n charWidth: 0,\n charHeight: 0,\n foreColor: 0,\n backColor: 0,\n widthInChars: 0,\n heightInChars: 0,\n canvasHeight: 0,\n canvasWidth: 0\n };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase){\n const { forecolor: forecolor, backcolor: backcolor, fontsize: fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)();\n this.canvasKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.props,\n this.cmdCompleteSignal.sharedArray,\n this.canvasKeys.sharedArray\n ];\n }\n getProp(pn) {\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */ drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx) return;\n let ins = this.owner.getLong(ds); /* ds->start */ \n const lastins = this.owner.getLong(ds + 4); /* ds->last */ \n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while(true){\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */ \n switch(type){\n case $c4741cac81d14197$var$D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_BEGINPATH:\n this.ctx.beginPath();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILL:\n this.ctx.fill();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SAVE:\n this.ctx.save();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_RESTORE:\n this.ctx.restore();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_STROKE:\n this.ctx.stroke();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = this.owner.getLong(ins + 48) != 0;\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n } else this.precomputedObjects[id] = {\n mem8: new Uint8Array(this.owner.memory.buffer, start, length),\n width: width,\n height: height\n };\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id]) delete this.precomputedObjects[id];\n else console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n else {\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) this.ctx.putImageData(imgData, dx, dy);\n else this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */ \n if (next == 0) {\n if (ins != lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nclass $c4741cac81d14197$export$c779b2cd00544976 {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner){\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)(signalBuffer);\n this.canvasKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\n \"drawseq\",\n [\n ds\n ]\n ]);\n this.drawCompleteSignal.wait();\n }\n}\n\n\n\nclass $8963973702ae5462$export$dd376bb3f10f6896 {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611);\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase){\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) this.divKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(); // tsconfig, lib must be set to 2017 or higher\n if (this.div && !modParams.styleIsDefault) {\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.divKeys.sharedArray\n ];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */ charOut(ch) {\n if (!this.div) return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n }\n switch(ch){\n case 10:\n case 13:\n if (ch == 10 && this.lastChar == 13) break; // detect CR LF and treat as single new line\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n case 0xE:\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF:\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for(let i = 0; i < str.length; i++)this.charOut(str.charCodeAt(i));\n }\n}\nclass $8963973702ae5462$export$b377f0bbf2c7581e {\n divKeys;\n constructor(params){\n const [divKeysBuffer] = params;\n this.divKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n charOut(ch) {\n postMessage([\n \"divout\",\n ch\n ]);\n }\n}\n\n\nlet $8ac0b786da854328$var$logline = \"\";\nfunction $8ac0b786da854328$export$16b4216ec014493d(char) {\n if (char == 10 || char == 3) {\n console.log($8ac0b786da854328$var$logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n $8ac0b786da854328$var$logline = \"\";\n } else {\n $8ac0b786da854328$var$logline = $8ac0b786da854328$var$logline + String.fromCharCode(char);\n if ($8ac0b786da854328$var$logline.length >= 200) {\n console.log($8ac0b786da854328$var$logline);\n $8ac0b786da854328$var$logline = \"\";\n }\n }\n}\nfunction $8ac0b786da854328$export$485af4d0039b3389(ch) {\n postMessage([\n \"debug\",\n ch\n ]);\n}\n\n\nclass $e72303a1db04bdfa$export$918ffb7e046a537b {\n mod;\n constructor(mod){\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\") return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\") return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll(\"D\", \"e\").replaceAll(\"d\", \"e\"));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n } else {\n let r = value.toString();\n if (r.length > max_precision) r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, sizeInBytes, value, fracpart_numdigits, dec, sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1) return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) {\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (!Number.isFinite(value)) {\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n } else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split(\".\");\n if (intPart == \"0\") intPart = \"\";\n if (intPart.length > 0) {\n decpos = intPart.length;\n digits = intPart + fracPart;\n } else {\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length) return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */ }\n}\n\n\nclass $ece7fa3ed770778a$export$c83a0a3bffe07399 {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule;\n floatUtil;\n constructor(isWasmModule = false){\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new (0, $e72303a1db04bdfa$export$918ffb7e046a537b)(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/ /*********************************************************************/ async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n } catch (err) {\n console.log(\"loadWasm() failed to fetch: \" + pathToLoad);\n throw err;\n }\n if (!response.ok) throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, {\n env: allimports\n });\n this.exports = instance.instance.exports;\n if (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory) throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer) console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\n \"setmemory\",\n this.memory\n ]);\n }\n if (this.isWasmModule) // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n {\n if (!(this.memory.buffer instanceof ArrayBuffer)) console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size)=>{\n return new Promise((resolve)=>{\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n } catch (err) {\n console.log(\"WASM instantiate error: \" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch(this.modParams.stdio){\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* callC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */ async callC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.callCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async callCImpl(fname, cparams = []) {\n if (!this.exports) throw new Error(\"this.exports undefined\");\n if (!this.exports[fname]) throw new Error(\"callC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array)) throw new Error(\"callC: params must be array, first arg is function name\");\n if (params.length == 0) throw new Error(\"callC: missing function name\");\n let cparams = [];\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n cparams[ci++] = p;\n break;\n case \"string\":\n cparams[ci++] = await this.putString(p);\n break;\n case \"object\":\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n } else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"callC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n ci++;\n break;\n case \"string\":\n this.callCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n case \"object\":\n if (p instanceof URL) {\n this.callCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci = ci + 2;\n break;\n } else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for(let j = 0; j < u8.length; j++)u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.callCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n } else throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/ /*********************************************************************/ // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for(i = 0; i < sin.length && i < buffer_size - 1; i++)this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for(let i = 0; i < u8a.length; i++)this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === \"object\" && fnin instanceof URL)) throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [\n dest,\n src.length\n ];\n } catch (err) {\n console.log(\"fetchAndPutURL Error. URL: \" + fnin + \"\\n\" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while(this.mem8[strIndex + i] && (len === undefined ? true : i < len) && strIndex + i < this.mem8.length){\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array(this.mem8.slice(dataptr, dataptr + size).buffer);\n return u32;\n }\n}\n\n\n\nfunction $4af5689abbc8d01b$export$78724cdcf7ebea1d() {\n return Date.now();\n}\n\n\nclass $aff9c2c494d23fe3$export$9e37856d1928d388 {\n callCompleteSignal;\n parameters;\n constructor(){\n this.callCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(()=>{\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = (0, $4af5689abbc8d01b$export$78724cdcf7ebea1d)();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [\n this.callCompleteSignal.sharedArray,\n this.parameters.buffer\n ];\n }\n processMessage(msgType, data) {\n switch(msgType){\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\nclass $aff9c2c494d23fe3$export$78d2a4633fe89379 {\n callCompleteSignal;\n parameters;\n constructor(params){\n this.callCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\n \"sleep\",\n [\n ms\n ]\n ]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\n \"time\"\n ]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n\n\nlet $3e39efa823870787$var$mod;\nonmessage = function(e) {\n //console.log('twrworker.js: message received from main script: '+e.data);\n if (e.data[0] == \"startup\") {\n const params = e.data[1];\n //console.log(\"Worker startup params:\",params);\n $3e39efa823870787$var$mod = new $3e39efa823870787$var$twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\n $3e39efa823870787$var$mod.loadWasm(params.urlToLoad).then(()=>{\n postMessage([\n \"startupOkay\"\n ]);\n }).catch((ex)=>{\n console.log(\".catch: \", ex);\n postMessage([\n \"startupFail\",\n ex\n ]);\n });\n } else if (e.data[0] == \"callC\") $3e39efa823870787$var$mod.callCImpl(e.data[1], e.data[2]).then((rc)=>{\n postMessage([\n \"callCOkay\",\n rc\n ]);\n }).catch((e)=>{\n console.log(\"exception in callC twrworker.js\\n\");\n console.log(e);\n postMessage([\n \"callCFail\",\n e\n ]);\n });\n else console.log(\"twrworker.js: unknown message: \" + e);\n};\n// ************************************************************************\nclass $3e39efa823870787$var$twrWasmModuleInWorker extends (0, $ece7fa3ed770778a$export$c83a0a3bffe07399) {\n malloc;\n modParams;\n constructor(modParams, modInWorkerParams){\n super();\n this.isWorker = true;\n this.malloc = (size)=>{\n throw new Error(\"error - un-init malloc called\");\n };\n this.modParams = modParams;\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\n const canvasProxy = new (0, $c4741cac81d14197$export$c779b2cd00544976)(modInWorkerParams.canvasProxyParams, this);\n const divProxy = new (0, $8963973702ae5462$export$b377f0bbf2c7581e)(modInWorkerParams.divProxyParams);\n const waitingCallsProxy = new (0, $aff9c2c494d23fe3$export$78d2a4633fe89379)(modInWorkerParams.waitingCallsProxyParams);\n this.modParams.imports = {\n twrDebugLog: (0, $8ac0b786da854328$export$485af4d0039b3389),\n twrSleep: waitingCallsProxy.sleep.bind(waitingCallsProxy),\n twrTime: waitingCallsProxy.time.bind(waitingCallsProxy),\n twrDivCharOut: divProxy.charOut.bind(divProxy),\n twrDivCharIn: divProxy.charIn.bind(divProxy),\n twrCanvasCharIn: canvasProxy.charIn.bind(canvasProxy),\n twrCanvasInkey: canvasProxy.inkey.bind(canvasProxy),\n twrCanvasGetProp: canvasProxy.getProp.bind(canvasProxy),\n twrCanvasDrawSeq: canvasProxy.drawSeq.bind(canvasProxy),\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function(x, y) {\n return x % y;\n },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n}\n\n})();\n//# sourceMappingURL=twrmodworker.2165e649.js.map\n","// this script is the WebWorker thead used by class twrWasmAsyncModule\nimport { twrCanvasProxy } from \"./twrcanvas.js\";\nimport { twrDivProxy } from \"./twrdiv.js\";\nimport { twrDebugLogProxy } from \"./twrdebug.js\";\nimport { twrWasmModuleBase } from \"./twrmodbase.js\";\nimport { twrWaitingCallsProxy } from \"./twrwaitingcalls.js\";\nlet mod;\nonmessage = function (e) {\n //console.log('twrworker.js: message received from main script: '+e.data);\n if (e.data[0] == 'startup') {\n const params = e.data[1];\n //console.log(\"Worker startup params:\",params);\n mod = new twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\n mod.loadWasm(params.urlToLoad).then(() => {\n postMessage([\"startupOkay\"]);\n }).catch((ex) => {\n console.log(\".catch: \", ex);\n postMessage([\"startupFail\", ex]);\n });\n }\n else if (e.data[0] == 'callC') {\n mod.callCImpl(e.data[1], e.data[2]).then((rc) => {\n postMessage([\"callCOkay\", rc]);\n }).catch(e => {\n console.log(\"exception in callC twrworker.js\\n\");\n console.log(e);\n postMessage([\"callCFail\", e]);\n });\n }\n else {\n console.log(\"twrworker.js: unknown message: \" + e);\n }\n};\n// ************************************************************************\nclass twrWasmModuleInWorker extends twrWasmModuleBase {\n malloc;\n modParams;\n constructor(modParams, modInWorkerParams) {\n super();\n this.isWorker = true;\n this.malloc = (size) => { throw new Error(\"error - un-init malloc called\"); };\n this.modParams = modParams;\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\n const canvasProxy = new twrCanvasProxy(modInWorkerParams.canvasProxyParams, this);\n const divProxy = new twrDivProxy(modInWorkerParams.divProxyParams);\n const waitingCallsProxy = new twrWaitingCallsProxy(modInWorkerParams.waitingCallsProxyParams);\n this.modParams.imports = {\n twrDebugLog: twrDebugLogProxy,\n twrSleep: waitingCallsProxy.sleep.bind(waitingCallsProxy),\n twrTime: waitingCallsProxy.time.bind(waitingCallsProxy),\n twrDivCharOut: divProxy.charOut.bind(divProxy),\n twrDivCharIn: divProxy.charIn.bind(divProxy),\n twrCanvasCharIn: canvasProxy.charIn.bind(canvasProxy),\n twrCanvasInkey: canvasProxy.inkey.bind(canvasProxy),\n twrCanvasGetProp: canvasProxy.getProp.bind(canvasProxy),\n twrCanvasDrawSeq: canvasProxy.drawSeq.bind(canvasProxy),\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function (x, y) { return x % y; },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n}\n//# sourceMappingURL=twrmodworker.js.map","// this script is the WebWorker thead used by class twrWasmAsyncModule\r\n\r\nimport {twrCanvasProxy} from \"./twrcanvas.js\";\r\nimport {twrDivProxy} from \"./twrdiv.js\";\r\nimport {twrDebugLogProxy} from \"./twrdebug.js\";\r\nimport {TAsyncModStartupMsg} from \"./twrmodasync.js\"\r\nimport {twrWasmModuleBase, IModInWorkerParams, IModParams} from \"./twrmodbase.js\"\r\nimport {twrWaitingCallsProxy} from \"./twrwaitingcalls.js\";\r\n\r\nlet mod:twrWasmModuleInWorker;\r\n\r\nonmessage = function(e) {\r\n //console.log('twrworker.js: message received from main script: '+e.data);\r\n\r\n if (e.data[0]=='startup') {\r\n const params:TAsyncModStartupMsg=e.data[1];\r\n //console.log(\"Worker startup params:\",params);\r\n mod=new twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\r\n\r\n mod.loadWasm(params.urlToLoad).then( ()=> {\r\n postMessage([\"startupOkay\"]);\r\n }).catch( (ex)=> {\r\n console.log(\".catch: \", ex);\r\n postMessage([\"startupFail\", ex]);\r\n });\r\n }\r\n else if (e.data[0]=='callC') {\r\n mod.callCImpl(e.data[1], e.data[2]).then( (rc)=> {\r\n postMessage([\"callCOkay\", rc]);\r\n }).catch(e => {\r\n console.log(\"exception in callC twrworker.js\\n\");\r\n console.log(e);\r\n postMessage([\"callCFail\", e]);\r\n });\r\n }\r\n else {\r\n console.log(\"twrworker.js: unknown message: \"+e);\r\n }\r\n}\r\n\r\n\r\n// ************************************************************************\r\n\r\nclass twrWasmModuleInWorker extends twrWasmModuleBase {\r\n\tmalloc:(size:number)=>Promise;\r\n modParams: IModParams;\r\n\r\n\r\n constructor(modParams:IModParams, modInWorkerParams:IModInWorkerParams) {\r\n super();\r\n this.isWorker=true;\r\n this.malloc=(size:number)=>{throw new Error(\"error - un-init malloc called\")};\r\n this.modParams=modParams;\r\n\r\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\r\n const canvasProxy = new twrCanvasProxy(modInWorkerParams.canvasProxyParams, this);\r\n const divProxy = new twrDivProxy(modInWorkerParams.divProxyParams);\r\n const waitingCallsProxy = new twrWaitingCallsProxy(modInWorkerParams.waitingCallsProxyParams);\r\n\r\n this.modParams.imports={\r\n twrDebugLog:twrDebugLogProxy,\r\n twrSleep:waitingCallsProxy.sleep.bind(waitingCallsProxy),\r\n twrTime:waitingCallsProxy.time.bind(waitingCallsProxy),\r\n\r\n twrDivCharOut:divProxy.charOut.bind(divProxy), \r\n twrDivCharIn:divProxy.charIn.bind(divProxy), \r\n\r\n twrCanvasCharIn:canvasProxy.charIn.bind(canvasProxy),\r\n twrCanvasInkey:canvasProxy.inkey.bind(canvasProxy),\r\n twrCanvasGetProp:canvasProxy.getProp.bind(canvasProxy),\r\n twrCanvasDrawSeq:canvasProxy.drawSeq.bind(canvasProxy),\r\n\r\n\t\t\ttwrSin:Math.sin,\r\n\t\t\ttwrCos:Math.cos,\r\n\t\t\ttwrTan: Math.tan,\r\n\t\t\ttwrFAbs: Math.abs,\r\n\t\t\ttwrACos: Math.acos,\r\n\t\t\ttwrASin: Math.asin,\r\n\t\t\ttwrATan: Math.atan,\r\n\t\t\ttwrExp: Math.exp,\r\n\t\t\ttwrFloor: Math.floor,\r\n\t\t\ttwrCeil: Math.ceil,\r\n\t\t\ttwrFMod: function(x:number, y:number) {return x%y},\r\n\t\t\ttwrLog: Math.log,\r\n\t\t\ttwrPow: Math.pow,\r\n\t\t\ttwrSqrt: Math.sqrt,\r\n\t\t\ttwrTrunc: Math.trunc,\r\n\r\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\r\n\t\t\ttwrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\r\n\t\t\ttwrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\r\n\t\t\ttwrAtod: this.floatUtil.atod.bind(this.floatUtil),\r\n\t\t\ttwrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\r\n \r\n }\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nimport { twrSignal } from \"./twrsignal.js\";\nvar D2DType;\n(function (D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})(D2DType || (D2DType = {}));\nexport class twrCanvas {\n ctx;\n props = { charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight: 0, canvasWidth: 0 };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase) {\n const { forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new twrSignal();\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext)\n throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c)\n throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2)\n throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\n }\n getProp(pn) {\n if (!this.isValid())\n console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */\n drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid())\n console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx)\n return;\n let ins = this.owner.getLong(ds); /* ds->start */\n const lastins = this.owner.getLong(ds + 4); /* ds->last */\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while (1) {\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */\n if (0 /*type!=D2DType.D2D_FILLRECT*/) {\n console.log(\"ins\", ins);\n console.log(\"hdr.next\", this.owner.mem8[ins], this.owner.mem8[ins + 1], this.owner.mem8[ins + 2], this.owner.mem8[ins + 3]);\n console.log(\"hdr.type\", this.owner.mem8[ins + 4], this.owner.mem8[ins + 5]);\n console.log(\"next 4 bytes\", this.owner.mem8[ins + 6], this.owner.mem8[ins + 7], this.owner.mem8[ins + 8], this.owner.mem8[ins + 9]);\n console.log(\"and 4 more \", this.owner.mem8[ins + 10], this.owner.mem8[ins + 11], this.owner.mem8[ins + 12], this.owner.mem8[ins + 13]);\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\n }\n switch (type) {\n case D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case D2DType.D2D_BEGINPATH:\n {\n this.ctx.beginPath();\n }\n break;\n case D2DType.D2D_FILL:\n {\n this.ctx.fill();\n }\n break;\n case D2DType.D2D_SAVE:\n {\n this.ctx.save();\n }\n break;\n case D2DType.D2D_RESTORE:\n {\n this.ctx.restore();\n }\n break;\n case D2DType.D2D_STROKE:\n {\n this.ctx.stroke();\n }\n break;\n case D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = (this.owner.getLong(ins + 48) != 0);\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n }\n else { // Uint8ClampedArray doesn't support shared memory\n this.precomputedObjects[id] = { mem8: new Uint8Array(this.owner.memory.buffer, start, length), width: width, height: height };\n }\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id])\n delete this.precomputedObjects[id];\n else\n console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) {\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n }\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) {\n this.ctx.putImageData(imgData, dx, dy);\n }\n else {\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */\n if (next == 0) {\n if (ins != lastins)\n throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal)\n this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nexport class twrCanvasProxy {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner) {\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new twrSignal(signalBuffer);\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\"drawseq\", [ds]]);\n this.drawCompleteSignal.wait();\n }\n}\n//# sourceMappingURL=twrcanvas.js.map","import {twrWasmModuleBase, IModParams} from \"./twrmodbase.js\"\r\nimport {twrSharedCircularBuffer} from \"./twrcircular.js\";\r\nimport {twrSignal} from \"./twrsignal.js\";\r\n\r\n\r\n// Canvas have a size that will be set based on the character width x height\r\n// The display size for a canvas will default to this size, but can be changed in the HTML/JS via\r\n// canvas.style.width = \"700px\";\r\n// canvas.style.height = \"500px\";\r\n\r\nexport interface ICanvasProps {\r\n\tcharWidth: number,\r\n\tcharHeight: number,\r\n\tforeColor: number,\r\n\tbackColor: number,\r\n widthInChars: number,\r\n heightInChars: number,\r\n canvasWidth:number,\r\n canvasHeight:number\r\n}\r\n\r\nenum D2DType {\r\n D2D_FILLRECT=1,\r\n D2D_FILLCHAR=5,\r\n D2D_SETLINEWIDTH=10,\r\n D2D_SETFILLSTYLERGBA=11,\r\n D2D_SETFONT=12,\r\n D2D_BEGINPATH=13,\r\n D2D_MOVETO=14,\r\n D2D_LINETO=15,\r\n D2D_FILL=16,\r\n D2D_STROKE=17,\r\n D2D_SETSTROKESTYLERGBA=18,\r\n D2D_ARC=19,\r\n D2D_STROKERECT=20,\r\n D2D_FILLTEXT=21,\r\n D2D_IMAGEDATA=22,\r\n D2D_PUTIMAGEDATA=23,\r\n D2D_BEZIERTO=24,\r\n D2D_MEASURETEXT=25,\r\n D2D_SAVE=26,\r\n D2D_RESTORE=27,\r\n D2D_CREATERADIALGRADIENT=28,\r\n D2D_SETCOLORSTOP=29,\r\n D2D_SETFILLSTYLEGRADIENT=30,\r\n D2D_RELEASEID=31,\r\n D2D_CREATELINEARGRADIENT=32,\r\n D2D_SETFILLSTYLE=33,\r\n D2D_SETSTROKESTYLE=34\r\n\r\n}\r\n\r\nexport type TCanvasProxyParams = [ICanvasProps, SharedArrayBuffer, SharedArrayBuffer];\r\n\r\nexport interface ICanvas {\r\n props: ICanvasProps,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TCanvasProxyParams,\r\n drawSeq: (ds:number)=>void,\r\n }\r\n \r\nexport class twrCanvas implements ICanvas {\r\n ctx:CanvasRenderingContext2D|undefined;\r\n props:ICanvasProps={charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight:0, canvasWidth:0};\r\n owner: twrWasmModuleBase;\r\n cmdCompleteSignal?:twrSignal;\r\n canvasKeys?: twrSharedCircularBuffer;\r\n precomputedObjects: { [index: number]: \r\n (ImageData | {mem8:Uint8Array, width:number, height:number}) |\r\n CanvasGradient\r\n };\r\n\r\n constructor(element:HTMLCanvasElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n const {forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas} = modParams; \r\n this.owner=modbase;\r\n this.props.widthInChars=modParams.windim[0];\r\n this.props.heightInChars=modParams.windim[1];\r\n\r\n if (!this.owner.isWasmModule) {\r\n this.cmdCompleteSignal=new twrSignal();\r\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n }\r\n\r\n this.precomputedObjects={};\r\n \r\n if (element) {\r\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\r\n let c=element.getContext(\"2d\");\r\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\r\n\r\n c.font = fontsize.toString()+\"px Courier New\";\r\n c.textBaseline=\"top\";\r\n const sampleText=\" \";\r\n const tm=c.measureText(sampleText);\r\n this.props.charWidth=Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\r\n let fM = c.measureText(\"X\"); \r\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\r\n\r\n if (!isd2dcanvas) {\r\n element.width=this.props.charWidth*this.props.widthInChars;\r\n element.height=this.props.charHeight*this.props.heightInChars;\r\n }\r\n\r\n this.props.canvasHeight=element.height;\r\n this.props.canvasWidth=element.width;\r\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\r\n\r\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\r\n let c2=element.getContext(\"2d\");\r\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\r\n this.ctx=c2;\r\n this.ctx.font = fontsize.toString()+\"px Courier New\";\r\n this.ctx.textBaseline=\"top\";\r\n\r\n c2.fillStyle=backcolor;\r\n this.props.backColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n c2.fillStyle=forecolor;\r\n this.props.foreColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n }\r\n\r\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\r\n\r\n //console.log(\"twrCanvas.constructor props: \", this.props);\r\n }\r\n\r\n isValid() {\r\n return !!this.ctx;\r\n }\r\n\r\n getProxyParams() : TCanvasProxyParams {\r\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\r\n }\r\n\r\n getProp(pn:number): number {\r\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n\r\n/* see draw2d.h for structs that match */\r\n\r\n drawSeq(ds:number) {\r\n //console.log(\"twr::Canvas enter drawSeq\");\r\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\r\n if (!this.ctx) return;\r\n\r\n let ins=this.owner.getLong(ds); /* ds->start */\r\n const lastins=this.owner.getLong(ds+4); /* ds->last */\r\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\r\n\r\n let next:number;\r\n //let insCount=0;\r\n\r\n while (1) {\r\n\r\n //insCount++;\r\n\r\n const type:D2DType=this.owner.getLong(ins+4); /* hdr->type */\r\n if (0/*type!=D2DType.D2D_FILLRECT*/) {\r\n console.log(\"ins\",ins)\r\n console.log(\"hdr.next\",this.owner.mem8[ins],this.owner.mem8[ins+1],this.owner.mem8[ins+2],this.owner.mem8[ins+3]);\r\n console.log(\"hdr.type\",this.owner.mem8[ins+4],this.owner.mem8[ins+5]);\r\n console.log(\"next 4 bytes\", this.owner.mem8[ins+6],this.owner.mem8[ins+7],this.owner.mem8[ins+8],this.owner.mem8[ins+9]);\r\n console.log(\"and 4 more \", this.owner.mem8[ins+10],this.owner.mem8[ins+11],this.owner.mem8[ins+12],this.owner.mem8[ins+13]);\r\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\r\n }\r\n switch (type) {\r\n case D2DType.D2D_FILLRECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.fillRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKERECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.strokeRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILLCHAR:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const c=this.owner.getShort(ins+24);\r\n let txt=String.fromCharCode(c);\r\n this.ctx.fillText(txt, x, y);\r\n }\r\n break;\r\n\r\n \r\n case D2DType.D2D_FILLTEXT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const str=this.owner.getString(this.owner.getLong(ins+24));\r\n\r\n //console.log(\"filltext \",x,y,str)\r\n \r\n this.ctx.fillText(str, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MEASURETEXT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n const tmidx=this.owner.getLong(ins+12);\r\n \r\n const tm=this.ctx.measureText(str);\r\n this.owner.setDouble(tmidx+0, tm.actualBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+8, tm.actualBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+16, tm.actualBoundingBoxLeft);\r\n this.owner.setDouble(tmidx+24, tm.actualBoundingBoxRight);\r\n this.owner.setDouble(tmidx+32, tm.fontBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+40, tm.fontBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+48, tm.width);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFONT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.font=str;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.fillStyle = cssColor;\r\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETSTROKESTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.fillStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETSTROKESTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETLINEWIDTH:\r\n {\r\n const width=this.owner.getShort(ins+8); \r\n this.ctx.lineWidth=width;\r\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MOVETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.moveTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_LINETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.lineTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEZIERTO:\r\n {\r\n const cp1x=this.owner.getDouble(ins+8);\r\n const cp1y=this.owner.getDouble(ins+16);\r\n const cp2x=this.owner.getDouble(ins+24);\r\n const cp2y=this.owner.getDouble(ins+32);\r\n const x=this.owner.getDouble(ins+40);\r\n const y=this.owner.getDouble(ins+48);\r\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEGINPATH:\r\n {\r\n this.ctx.beginPath();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILL:\r\n {\r\n this.ctx.fill();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SAVE:\r\n {\r\n this.ctx.save();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_RESTORE:\r\n {\r\n this.ctx.restore();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKE:\r\n {\r\n this.ctx.stroke();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_ARC:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const radius=this.owner.getDouble(ins+24);\r\n const startAngle=this.owner.getDouble(ins+32);\r\n const endAngle=this.owner.getDouble(ins+40);\r\n const counterClockwise= (this.owner.getLong(ins+48)!=0);\r\n\r\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_IMAGEDATA:\r\n {\r\n const start=this.owner.getLong(ins+8);\r\n const length=this.owner.getLong(ins+12);\r\n const width=this.owner.getLong(ins+16);\r\n const height=this.owner.getLong(ins+20);\r\n const id=this.owner.getLong(ins+24);\r\n\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\r\n\r\n if (this.owner.isWasmModule) {\r\n const z = new Uint8ClampedArray(this.owner.memory!.buffer, start, length);\r\n this.precomputedObjects[id]=new ImageData(z, width, height);\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory\r\n this.precomputedObjects[id]={mem8: new Uint8Array(this.owner.memory!.buffer, start, length), width:width, height:height};\r\n }\r\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_CREATERADIALGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const radius0=this.owner.getDouble(ins+24);\r\n const x1=this.owner.getDouble(ins+32);\r\n const y1=this.owner.getDouble(ins+40);\r\n const radius1=this.owner.getDouble(ins+48);\r\n const id= this.owner.getLong(ins+56);\r\n\r\n let gradient=this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_CREATELINEARGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const x1=this.owner.getDouble(ins+24);\r\n const y1=this.owner.getDouble(ins+32);\r\n const id= this.owner.getLong(ins+40);\r\n \r\n let gradient=this.ctx.createLinearGradient(x0, y0, x1, y1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETCOLORSTOP:\r\n {\r\n const id = this.owner.getLong(ins+8);\r\n const pos=this.owner.getLong(ins+12);\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+16));\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n gradient.addColorStop(pos, cssColor);\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n this.ctx.fillStyle=gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_RELEASEID:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (this.precomputedObjects[id])\r\n delete this.precomputedObjects[id];\r\n else\r\n console.log(\"warning: D2D_RELEASEID with undefined ID \",id);\r\n }\r\n break\r\n\r\n \r\n\r\n case D2DType.D2D_PUTIMAGEDATA:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n const dx=this.owner.getLong(ins+12);\r\n const dy=this.owner.getLong(ins+16);\r\n const dirtyX=this.owner.getLong(ins+20);\r\n const dirtyY=this.owner.getLong(ins+24);\r\n const dirtyWidth=this.owner.getLong(ins+28);\r\n const dirtyHeight=this.owner.getLong(ins+32);\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \"+id);\r\n\r\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\r\n\r\n let imgData:ImageData;\r\n if (this.owner.isWasmModule) {\r\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\r\n imgData=this.precomputedObjects[id] as ImageData;\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\r\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\r\n const z = this.precomputedObjects[id] as {mem8:Uint8Array, width:number, height:number}; // Uint8Array\r\n const ca=Uint8ClampedArray.from(z.mem8); // shallow copy\r\n imgData=new ImageData(ca, z.width, z.height);\r\n }\r\n \r\n if (dirtyWidth==0 && dirtyHeight==0) {\r\n this.ctx.putImageData(imgData, dx, dy);\r\n }\r\n else {\r\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\r\n }\r\n }\r\n break;\r\n\r\n default:\r\n throw new Error (\"unimplemented or unknown Sequence Type in drawSeq: \"+type);\r\n }\r\n next=this.owner.getLong(ins); /* hdr->next */\r\n if (next==0) {\r\n if (ins!=lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\r\n break;\r\n }\r\n ins=next;\r\n }\r\n\r\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\r\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\r\n }\r\n}\r\n\r\nexport class twrCanvasProxy implements ICanvas {\r\n canvasKeys: twrSharedCircularBuffer;\r\n drawCompleteSignal:twrSignal;\r\n props: ICanvasProps;\r\n owner: twrWasmModuleBase;\r\n\r\n constructor(params:TCanvasProxyParams, owner:twrWasmModuleBase) {\r\n const [props, signalBuffer, canvasKeysBuffer] = params;\r\n this.drawCompleteSignal = new twrSignal(signalBuffer);\r\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\r\n this.props=props;\r\n this.owner=owner;\r\n\r\n //console.log(\"Create New twrCanvasProxy: \",this.props)\r\n\r\n }\r\n\r\n charIn() { \r\n //ctx.commit(); not avail in chrome\r\n \r\n //postMessage([\"debug\", 'x']);\r\n \r\n return this.canvasKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.canvasKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n getProp(pn:number): number {\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n \r\n drawSeq(ds:number) {\r\n this.drawCompleteSignal.reset();\r\n postMessage([\"drawseq\", [ds]]);\r\n this.drawCompleteSignal.wait();\r\n }\r\n}\r\n","//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst RDIDX = 256;\nconst WRIDX = 257;\nconst LEN = 256;\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\n// the first 256 array entries are the circular buffer\n// the next two are used for the read and write index\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\nexport class twrSharedCircularBuffer {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(258 * 4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[RDIDX] = 0;\n this.buf[WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[WRIDX];\n this.buf[i] = n;\n i++;\n if (i == LEN)\n i = 0;\n this.buf[WRIDX] = i;\n Atomics.notify(this.buf, WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[RDIDX] = i;\n return n;\n }\n else\n return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[RDIDX] == this.buf[WRIDX];\n }\n}\n//# sourceMappingURL=twrcircular.js.map","//\r\n// This class implements a circular buffer that the main javascript thread can write to, \r\n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\r\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \r\n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\r\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\r\n//\r\n\r\nconst RDIDX=256;\r\nconst WRIDX=257;\r\nconst LEN=256;\r\n\r\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\r\n// the first 256 array entries are the circular buffer\r\n// the next two are used for the read and write index\r\n\r\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\r\n\r\nexport class twrSharedCircularBuffer {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n \r\n\tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(258*4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[RDIDX]=0;\r\n this.buf[WRIDX]=0;\r\n\t}\r\n\r\n\twrite(n:number) {\r\n let i=this.buf[WRIDX];\r\n this.buf[i]=n;\r\n i++;\r\n if (i==LEN) i=0;\r\n this.buf[WRIDX]=i; \r\n Atomics.notify(this.buf, WRIDX); \r\n\t}\r\n\r\n\tread():number {\r\n if (!this.isEmpty()) {\r\n let i=this.buf[RDIDX];\r\n let n=this.buf[i];\r\n i++;\r\n this.buf[RDIDX]=i;\r\n return n;\r\n }\r\n\t\telse\r\n return -1;\r\n\t}\r\n\r\n readWait():number {\r\n if (this.isEmpty()) {\r\n const rdptr=this.buf[RDIDX];\r\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\r\n Atomics.wait(this.buf, WRIDX, rdptr);\r\n }\r\n return this.read();\r\n\t}\r\n\r\n isEmpty():boolean {\r\n return this.buf[RDIDX]==this.buf[WRIDX];\r\n }\r\n}\r\n","//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar twrSignalState;\n(function (twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})(twrSignalState || (twrSignalState = {}));\n;\nexport class twrSignal {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window valid\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == twrSignalState.WAITING) {\n //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\n //console.log(\"released...\");\n }\n }\n isSignaled() {\n return this.buf[0] == twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = twrSignalState.WAITING;\n }\n}\n//# sourceMappingURL=twrsignal.js.map","//\r\n// This class implements a simple signal/wait mechanism\r\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\r\n//\r\n\r\nenum twrSignalState {\r\n WAITING=0,\r\n SIGNALED=1\r\n};\r\n\r\nexport class twrSignal {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n\r\n \tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window valid\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) \r\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[0]=twrSignalState.WAITING;\r\n\t}\r\n\r\n\tsignal() {\r\n this.buf[0]=twrSignalState.SIGNALED; \r\n //console.log(\"about to signal\");\r\n Atomics.notify(this.buf, 0); \r\n\t}\r\n\r\n wait() {\r\n if (this.buf[0]==twrSignalState.WAITING) {\r\n //console.log(\"waiting...\");\r\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\r\n //console.log(\"released...\");\r\n\r\n }\r\n\t}\r\n isSignaled():boolean {\r\n return this.buf[0]==twrSignalState.SIGNALED;\r\n }\r\n\r\n reset() {\r\n this.buf[0]=twrSignalState.WAITING;\r\n }\r\n}\r\n","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nexport class twrDiv {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase) {\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\n this.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n if (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.divKeys.sharedArray];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */\n charOut(ch) {\n if (!this.div)\n return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n }\n switch (ch) {\n case 10: // newline\n case 13: // return\n if (ch == 10 && this.lastChar == 13)\n break; // detect CR LF and treat as single new line\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8: // backspace\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n case 0xE: // cursor on\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF: // cursor off\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for (let i = 0; i < str.length; i++)\n this.charOut(str.charCodeAt(i));\n }\n}\nexport class twrDivProxy {\n divKeys;\n constructor(params) {\n const [divKeysBuffer] = params;\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n charOut(ch) {\n postMessage([\"divout\", ch]);\n }\n}\n//# sourceMappingURL=twrdiv.js.map","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\r\nimport { IModParams } from \"./twrmodbase.js\";\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\";\r\n\r\nexport type TDivProxyParams = [SharedArrayBuffer];\r\n\r\nexport interface IDiv {\r\n charOut: (ds:number)=>void,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TDivProxyParams,\r\n }\r\n\r\n\r\nexport class twrDiv implements IDiv {\r\n\tdiv:HTMLDivElement|null|undefined;\r\n\tdivKeys?:twrSharedCircularBuffer;\r\n\tCURSOR=String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\r\n\tcursorOn:boolean=false;\r\n\tlastChar:number=0;\r\n\textraBR:boolean=false;\r\n\towner:twrWasmModuleBase;\r\n\r\n constructor(element:HTMLDivElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n\t\tthis.div=element;\r\n\t\tthis.owner=modbase;\r\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\r\n\t\t\tthis.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n\t\t}\r\n\r\n\t\tif (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\r\n\t\t\tthis.div.style.backgroundColor = modParams.backcolor;\r\n\t\t\tthis.div.style.color = modParams.forecolor;\r\n\t\t\tthis.div.style.font=modParams.fontsize.toString()+\"px arial\"\r\n\t\t}\r\n }\r\n\r\n\tisValid() {\r\n\t\treturn !!this.div;\r\n\t}\r\n\r\n getProxyParams() : TDivProxyParams {\r\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [ this.divKeys.sharedArray];\r\n }\r\n\r\n\r\n/* \r\n * add character to div. Supports the following control codes:\r\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\r\n * 0xE cursor on \r\n * 0x8 backspace\r\n * 0xF cursor off \r\n*/\r\n\tcharOut(ch:number) {\r\n\r\n\t\tif (!this.div) return;\r\n\r\n\t\t//console.log(\"div::charout: \", ch);\r\n\r\n\t\tif (this.extraBR) {\r\n\t\t\tthis.extraBR=false;\r\n\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -4);\r\n\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t}\r\n\r\n\t\tswitch (ch) {\r\n\t\t\tcase 10: // newline\r\n\t\t\tcase 13: // return\r\n\t\t\t\tif (ch==10 && this.lastChar==13) break; // detect CR LF and treat as single new line\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\r\n\t\t\t\tthis.extraBR=true;\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\t//element.scrollIntoView();\r\n\t\t\t\t//element.scrollTop = element.scrollHeight;\r\n\t\t\t\tlet p = this.div.getBoundingClientRect();\r\n\t\t\t\twindow.scrollTo(0, p.height+100);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 8: // backspace\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xE: // cursor on\r\n\t\t\t\tif (!this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=true;\r\n\t\t\t\t\tthis.div.innerHTML += this.CURSOR;\r\n\t\t\t\t\tthis.div.focus();\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xF: // cursor off\r\n\t\t\t\tif (this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=false;\r\n\t\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += String.fromCharCode(ch);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\tthis.lastChar=ch;\r\n\t}\r\n\r\n\tstringOut(str:string) {\r\n\t\tfor (let i=0; i < str.length; i++)\r\n\t\t\tthis.charOut(str.charCodeAt(i));\r\n\t}\r\n}\r\n\r\n\r\nexport class twrDivProxy implements IDiv {\r\n divKeys: twrSharedCircularBuffer;\r\n\r\n constructor(params:TDivProxyParams) {\r\n const [divKeysBuffer] = params;\r\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\r\n }\r\n\r\n charIn() { \r\n return this.divKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.divKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n\tcharOut(ch:number) {\r\n\t\tpostMessage([\"divout\", ch]);\r\n\t}\r\n}\r\n\r\n","let logline = \"\";\nexport function twrDebugLogImpl(char) {\n if (char == 10 || char == 3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\n console.log(logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n logline = \"\";\n }\n else {\n logline = logline + String.fromCharCode(char);\n if (logline.length >= 200) {\n console.log(logline);\n logline = \"\";\n }\n }\n}\n// ************************************************************************\n// debugLog doesn't currently wait for the message to log, it returns immediately.\n// I could move this to be in the twrWaitingCalls class\nexport function twrDebugLogProxy(ch) {\n postMessage([\"debug\", ch]);\n}\n//# sourceMappingURL=twrdebug.js.map","\r\nlet logline=\"\";\r\nexport function twrDebugLogImpl(char:number) {\r\n\tif (char==10 || char==3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\r\n\t\tconsole.log(logline);\t// ideally without a linefeed, but there is no way to not have a LF with console.log API.\r\n\t\tlogline=\"\";\r\n\t}\r\n\telse {\r\n\t\tlogline=logline+String.fromCharCode(char);\r\n\t\tif (logline.length>=200) {\r\n\t\t\tconsole.log(logline);\r\n\t\t\tlogline=\"\";\r\n\t\t}\r\n\t}\r\n}\r\n\r\n// ************************************************************************\r\n// debugLog doesn't currently wait for the message to log, it returns immediately.\r\n// I could move this to be in the twrWaitingCalls class\r\nexport function twrDebugLogProxy(ch:number) {\r\n postMessage([\"debug\", ch]);\r\n}\r\n\r\n","import { twrFloatUtil } from \"./twrfloat.js\";\n/*********************************************************************/\n/*********************************************************************/\n/*********************************************************************/\nexport class twrWasmModuleBase {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\n floatUtil;\n constructor(isWasmModule = false) {\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new twrFloatUtil(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/\n /*********************************************************************/\n async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n }\n catch (err) {\n console.log('loadWasm() failed to fetch: ' + pathToLoad);\n throw err;\n }\n if (!response.ok)\n throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, { env: allimports });\n this.exports = instance.instance.exports;\n if (!this.exports)\n throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory)\n throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory)\n throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer)\n console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\"setmemory\", this.memory]);\n }\n if (this.isWasmModule) {\n // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (!(this.memory.buffer instanceof ArrayBuffer))\n console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size) => {\n return new Promise(resolve => {\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n }\n catch (err) {\n console.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch (this.modParams.stdio) {\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* callC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */\n async callC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.callCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async callCImpl(fname, cparams = []) {\n if (!this.exports)\n throw new Error(\"this.exports undefined\");\n if (!this.exports[fname])\n throw new Error(\"callC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array))\n throw new Error(\"callC: params must be array, first arg is function name\");\n if (params.length == 0)\n throw new Error(\"callC: missing function name\");\n let cparams = [];\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n cparams[ci++] = p;\n break;\n case 'string':\n cparams[ci++] = await this.putString(p);\n break;\n case 'object':\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n }\n else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"callC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n ci++;\n break;\n case 'string':\n this.callCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n case 'object':\n if (p instanceof URL) {\n this.callCImpl('twr_free', [cparams[ci]]);\n ci = ci + 2;\n break;\n }\n else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for (let j = 0; j < u8.length; j++)\n u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.callCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n }\n else\n throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/\n /*********************************************************************/\n // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for (i = 0; i < sin.length && i < buffer_size - 1; i++)\n this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for (let i = 0; i < u8a.length; i++)\n this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === 'object' && fnin instanceof URL))\n throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [dest, src.length];\n }\n catch (err) {\n console.log('fetchAndPutURL Error. URL: ' + fnin + '\\n' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while (this.mem8[strIndex + i] && (len === undefined ? true : i < len) && (strIndex + i) < this.mem8.length) {\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0)\n throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array((this.mem8.slice(dataptr, dataptr + size)).buffer);\n return u32;\n }\n}\n//# sourceMappingURL=twrmodbase.js.map","\r\nimport {TCanvasProxyParams} from \"./twrcanvas.js\"\r\nimport {TDivProxyParams} from \"./twrdiv.js\";\r\nimport {TWaitingCallsProxyParams} from \"./twrwaitingcalls.js\"\r\nimport {twrDebugLogImpl} from \"./twrdebug.js\";\r\nimport {twrFloatUtil} from \"./twrfloat.js\";\r\n\r\n\r\nexport type TStdioVals=\"div\"|\"canvas\"|\"null\"|\"debug\";\r\n\r\nexport interface IModOpts {\r\n\tstdio?:TStdioVals, \r\n\twindim?:[number, number],\r\n\tforecolor?:string,\r\n\tbackcolor?:string,\r\n\tfontsize?:number,\r\n\tisd2dcanvas?:boolean,\r\n\timports?:{},\r\n}\r\n\r\nexport interface IModParams {\r\n\tstdio:TStdioVals, \r\n\twindim:[number, number],\r\n\tforecolor:string,\r\n\tbackcolor:string,\r\n\tfontsize:number,\r\n\tstyleIsDefault: boolean\r\n\tisd2dcanvas:boolean,\r\n\timports:{[index:string]:Function},\r\n}\r\n\r\nexport interface IModInWorkerParams {\r\n\tdivProxyParams:TDivProxyParams,\r\n\tcanvasProxyParams:TCanvasProxyParams,\r\n\twaitingCallsProxyParams:TWaitingCallsProxyParams,\r\n}\r\n\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n\r\nexport abstract class twrWasmModuleBase {\r\n\tmemory?:WebAssembly.Memory;\r\n\tmem8:Uint8Array;\r\n\tmem32:Uint32Array;\r\n\tmemD:Float64Array;\r\n\tabstract malloc:(size:number)=>Promise;\r\n\tabstract modParams:IModParams;\r\n\texports?:WebAssembly.Exports;\r\n\tisWorker=false;\r\n\tisWasmModule:boolean; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\r\n\tfloatUtil:twrFloatUtil;\r\n\r\n\tconstructor(isWasmModule=false) {\r\n\t\tthis.isWasmModule=isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\r\n\t\tthis.mem8=new Uint8Array(); \t// avoid type errors\r\n\t\tthis.mem32=new Uint32Array(); // avoid type errors\r\n\t\tthis.memD=new Float64Array(); // avoid type errors\r\n\t\tthis.floatUtil=new twrFloatUtil(this);\r\n\t\t//console.log(\"size of mem8 after constructor\",this.mem8.length);\r\n\t}\r\n\r\n\t/*********************************************************************/\r\n\t/*********************************************************************/\r\n\r\n\tasync loadWasm(pathToLoad:string) {\r\n\t\t//console.log(\"fileToLoad\",fileToLoad)\r\n\r\n\t\tlet response;\r\n\t\ttry {\r\n\t\t\tresponse=await fetch(pathToLoad);\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('loadWasm() failed to fetch: '+pathToLoad);\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t\t\r\n\t\tif (!response.ok) throw new Error(\"fetch response error on file '\"+pathToLoad+\"'\\n\"+response.statusText);\r\n\r\n\t\ttry {\r\n\t\t\tlet wasmBytes = await response.arrayBuffer();\r\n\r\n\t\t\tlet allimports:WebAssembly.ModuleImports = { \r\n\t\t\t\t...this.modParams.imports\r\n\t\t\t};\r\n\r\n\t\t\tlet instance = await WebAssembly.instantiate(wasmBytes, {env: allimports});\r\n\r\n\t\t\tthis.exports=instance.instance.exports;\r\n\t\t\tif (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\r\n\r\n\t\t\tif (this.memory) throw new Error (\"unexpected error -- this.memory already set\");\r\n\t\t\tthis.memory=this.exports.memory as WebAssembly.Memory;\r\n\t\t\tif (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\r\n\t\t\tthis.mem8 = new Uint8Array(this.memory.buffer);\r\n\t\t\tthis.mem32 = new Uint32Array(this.memory.buffer);\r\n\t\t\tthis.memD = new Float64Array(this.memory.buffer);\r\n\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\tif (this.isWorker) {\r\n\t\t\t\tif (this.memory.buffer instanceof ArrayBuffer)\r\n\t\t\t\t\tconsole.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\r\n\t\t\t\t\r\n\t\t\t\tpostMessage([\"setmemory\",this.memory]);\r\n\t\t\t}\r\n\t\t\tif (this.isWasmModule) {\r\n\t\t\t\t// here if twrWasmModule, twrWasmModuleAsync overrides this function\r\n\t\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\t\tif (!(this.memory.buffer instanceof ArrayBuffer))\r\n\t\t\t\t\tconsole.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\r\n\t\t\t}\r\n\r\n\t\t\tthis.malloc=(size:number)=>{\r\n\t\t\t\treturn new Promise(resolve => {\r\n\t\t\t\t\tconst m=this.exports!.twr_malloc as (size:number)=>number;\r\n\t\t\t\t\tresolve(m(size));\r\n\t\t\t\t});\r\n\t\t };\r\n\r\n\t\t\tthis.init();\r\n\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t}\r\n\r\n\tprivate init() {\r\n\t\t//console.log(\"loadWasm.init() enter\")\r\n\t\t\tlet p:number;\r\n\t\t\tswitch (this.modParams.stdio) {\r\n\t\t\t\tcase \"debug\":\r\n\t\t\t\t\tp=0;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"div\":\r\n\t\t\t\t\tp=1;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"canvas\":\r\n\t\t\t\t\tp=2;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"null\":\r\n\t\t\t\t\tp=3;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tp=0; // debug\r\n\t\t\t}\r\n\r\n\t\t\tconst twrInit=this.exports!.twr_wasm_init as CallableFunction;\r\n\t\t\t//console.log(\"twrInit:\",twrInit)\r\n\t\t\ttwrInit(p, this.mem8.length);\r\n\t}\r\n\r\n\t/* callC takes an array where:\r\n\t* the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\r\n\t* and the next entries are a variable number of parameters to pass to the C function, of type\r\n\t* number - converted to int32 or float64 as appropriate\r\n\t* string - converted to a an index (ptr) into a module Memory returned via stringToMem()\r\n\t* URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\r\n\t* Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\r\n */\r\n\r\n\tasync callC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\t\tconst cparams=await this.preCallC(params);\r\n\t\tlet retval = this.callCImpl(params[0], cparams);\r\n\t\tthis.postCallC(cparams, params);\r\n\t\treturn retval;\r\n\t}\r\n\r\n\tasync callCImpl(fname:string, cparams:number[]=[]) {\r\n\t\tif (!this.exports) throw new Error(\"this.exports undefined\");\r\n\t\tif (!this.exports[fname]) throw new Error(\"callC: function '\"+fname+\"' not in export table. Use --export wasm-ld flag.\");\r\n\r\n\t\tconst f = this.exports[fname] as CallableFunction;\r\n\t\tlet cr=f(...cparams);\r\n\r\n\t\treturn cr;\r\n\t}\r\n\r\n\t// convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\r\n\tasync preCallC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tif (!(params.constructor === Array)) throw new Error (\"callC: params must be array, first arg is function name\");\r\n\t\tif (params.length==0) throw new Error(\"callC: missing function name\");\r\n\r\n\t\tlet cparams:number[]=[];\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tcparams[ci++]=p;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tcparams[ci++]=await this.putString(p);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tconst r=await this.fetchAndPutURL(p);\r\n\t\t\t\t\t\tcparams[ci++]=r[0]; // mem index\r\n\t\t\t\t\t\tcparams[ci++]=r[1]; // len\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tconst r=await this.putArrayBuffer(p);\r\n\t\t\t\t\t\tcparams[ci++]=r; // mem index\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tthrow new Error (\"callC: invalid object type passed in\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn cparams;\r\n\t}\r\n\r\n\t// free the mallocs; copy array buffer data from malloc back to arraybuffer\r\n\tasync postCallC(cparams:number[], params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tthis.callCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t\t\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tthis.callCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\t\tci=ci+2;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tlet u8=new Uint8Array(p);\r\n\t\t\t\t\t\tfor (let j=0; j= this.mem32.length) throw new Error(\"invalid index passed to getLong: \"+idx+\", this.mem32.length: \"+this.mem32.length);\r\n\t\tconst long:number = this.mem32[idx32];\r\n\t\treturn long;\r\n\t}\r\n\t\r\n\tsetLong(idx:number, value:number) {\r\n const idx32 = Math.floor(idx / 4);\r\n if (idx32 * 4 != idx)\r\n throw new Error(\"setLong passed non long aligned address\");\r\n if (idx32 < 0 || idx32 >= this.mem32.length)\r\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\r\n this.mem32[idx32]=value;\r\n }\r\n\r\n\tgetDouble(idx:number): number {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"getLong passed non Float64 aligned address\")\r\n\t\tconst long:number = this.memD[idx64];\r\n\t\treturn long;\r\n\t}\r\n\r\n\tsetDouble(idx:number, value:number) {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"setDouble passed non Float64 aligned address\")\r\n\t\tthis.memD[idx64]=value;\r\n\t}\r\n\r\n\tgetShort(idx:number): number {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getShort: \"+idx);\r\n\t\tconst short:number = this.mem8[idx]+this.mem8[idx+1]*256;\r\n\t\treturn short;\r\n\t}\r\n\r\n\t// get a string out of module memory\r\n\t// null terminated, up until max of (optional) len\r\n\tgetString(strIndex:number, len?:number): string {\r\n\t\tlet sout=\"\";\r\n\r\n\t\tlet i=0;\r\n\t\twhile (this.mem8[strIndex+i] && (len===undefined?true:i= this.mem8.length) throw new Error(\"invalid index passed to getU8: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU8\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU8\")\r\n\r\n\t\tconst u8=this.mem8.slice(dataptr, dataptr+size);\r\n\t\treturn u8;\r\n\t}\r\n\r\n\t// get a int32 array out of module memory when passed in index to [size, dataptr]\r\n\tgetU32Arr(idx:number): Uint32Array {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getU32: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU32\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU32\")\r\n\r\n\t\tif (size%4!=0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\r\n\r\n\t\tconst u32 = new Uint32Array( (this.mem8.slice(dataptr, dataptr+size)).buffer );\r\n\t\treturn u32;\r\n\t}\r\n}\r\n","export class twrFloatUtil {\n mod;\n constructor(mod) {\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\")\n return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\")\n return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll('D', 'e').replaceAll('d', 'e'));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n }\n else {\n let r = value.toString();\n if (r.length > max_precision)\n r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, // char *\n sizeInBytes, //size_t\n value, // double\n fracpart_numdigits, //int\n dec, // int *\n sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1)\n return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) { /* nan */\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (!Number.isFinite(value)) { /* infinity */\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n }\n else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split('.');\n if (intPart == \"0\")\n intPart = \"\";\n if (intPart.length > 0) { // has integer part\n decpos = intPart.length;\n digits = intPart + fracPart;\n }\n else { // only a fraction\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length)\n return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */\n }\n}\n//# sourceMappingURL=twrfloat.js.map","\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\"\r\n\r\nexport class twrFloatUtil {\r\n mod: twrWasmModuleBase;\r\n\r\n constructor(mod: twrWasmModuleBase) {\r\n this.mod=mod;\r\n }\r\n\r\n atod(strptr:number):number {\r\n const str=this.mod.getString(strptr);\r\n\r\n const upper=str.trimStart().toUpperCase();\r\n if (upper==\"INF\" || upper==\"+INF\")\r\n return Number.POSITIVE_INFINITY;\r\n else if (upper==\"-INF\")\r\n return Number.NEGATIVE_INFINITY\r\n else {\r\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\r\n const r=Number.parseFloat(str.replaceAll('D','e').replaceAll('d','e'));\r\n return r;\r\n }\r\n }\r\n\r\n dtoa(buffer:number, buffer_size:number, value:number, max_precision:number):void {\r\n if (max_precision==-1) {\r\n const r=value.toString();\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n else {\r\n let r=value.toString();\r\n if (r.length>max_precision)\r\n r=value.toPrecision(max_precision);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n }\r\n\r\n toFixed(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toFixed(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n toExponential(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toExponential(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\r\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\r\n // Negative exponents must be now smaller than 1e-99\r\n // fully-function C version also int he source, but this is the version enabled by default\r\n fcvtS(\r\n buffer:number, // char *\r\n sizeInBytes:number, //size_t\r\n value:number, // double\r\n fracpart_numdigits:number, //int\r\n dec:number, // int *\r\n sign:number // int *\r\n ):number {\r\n\r\n if (buffer==0 ||sign==0 || dec==0 || sizeInBytes<1) return 1;\r\n\r\n let digits:string;\r\n let decpos:number;\r\n let s=0; // default to positive\r\n\r\n\r\n if (Number.isNaN(value)) { /* nan */\r\n digits=\"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (!Number.isFinite(value)) { /* infinity */\r\n digits=\"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (value==0) { \r\n digits=\"000000000000000000000000000000000000\".slice(0,fracpart_numdigits);\r\n decpos=0;\r\n }\r\n \r\n else {\r\n\r\n if (value<0) {\r\n s=1; // negative\r\n value=Math.abs(value);\r\n }\r\n\r\n if (fracpart_numdigits>100 || value > 1e+21 || value < 1e-99) { \r\n this.mod.copyString(buffer, sizeInBytes, \"\");\r\n this.mod.mem32[dec]=0;\r\n return 1;\r\n }\r\n\r\n const roundValStr=value.toFixed(fracpart_numdigits);\r\n let [intPart=\"\", fracPart=\"\"] = roundValStr.split('.');\r\n if (intPart==\"0\") intPart=\"\";\r\n\r\n if (intPart.length>0) { // has integer part\r\n decpos=intPart.length;\r\n digits=intPart+fracPart;\r\n }\r\n else { // only a fraction\r\n digits=fracPart.replace(/^0+/,\"\"); // remove leading zeros\r\n decpos=digits.length-fracPart.length;\r\n }\r\n }\r\n\r\n if (sizeInBytes-1 < digits.length) return 1; \r\n this.mod.copyString(buffer, sizeInBytes, digits);\r\n this.mod.setLong(dec, decpos);\r\n this.mod.setLong(sign, s);\r\n\r\n return 0;\r\n\r\n /*\r\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\r\n\r\n let decpos=0;\r\n let digits:string;\r\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\r\n \r\n if (decpos>0) { // has integer part\r\n const intlen=Math.max(decpos, 0);\r\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\r\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\r\n }\r\n else { // only a fraction\r\n const intpart=Math.trunc(value);\r\n const fracpart=value-intpart;\r\n const prec=fracpart_numdigits- (-decpos);\r\n console.log(\"prec=\",prec);\r\n if (prec<1) {\r\n digits=\"\";\r\n }\r\n else {\r\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\");\r\n }\r\n }\r\n\r\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\r\n console.log('digits=',digits);\r\n console.log('dec=',decpos);\r\n console.log(\"sign=\",s);\r\n */\r\n\r\n\r\n }\r\n}","import { twrSignal } from \"./twrsignal.js\";\nimport { twrTimeImpl } from \"./twrdate.js\";\n// This class is used in the Main JS thread \nexport class twrWaitingCalls {\n callCompleteSignal;\n parameters;\n constructor() {\n this.callCompleteSignal = new twrSignal();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(() => {\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = twrTimeImpl();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [this.callCompleteSignal.sharedArray, this.parameters.buffer];\n }\n processMessage(msgType, data) {\n switch (msgType) {\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\n// This class is used in the worker thread \nexport class twrWaitingCallsProxy {\n callCompleteSignal;\n parameters;\n constructor(params) {\n this.callCompleteSignal = new twrSignal(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\"sleep\", [ms]]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\"time\"]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n//# sourceMappingURL=twrwaitingcalls.js.map","import { twrSignal } from \"./twrsignal.js\";\r\nimport {twrTimeImpl} from \"./twrdate.js\"\r\n\r\n// These classes are used to proxy a call across the worker thread - main thread boundary and wait for the result\r\n\r\nexport type TWaitingCallsProxyParams = [SharedArrayBuffer, SharedArrayBuffer]; // twrSignal, parameters \r\n\r\n// This class is used in the Main JS thread \r\nexport class twrWaitingCalls {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor() {\r\n\t\tthis.callCompleteSignal=new twrSignal();\r\n\t\tthis.parameters=new Uint32Array(new SharedArrayBuffer(4));\r\n\t}\r\n\r\n\tprivate startSleep(ms:number) {\r\n\r\n\t\tsetTimeout(()=>{\r\n\t\t\tthis.callCompleteSignal.signal();\r\n\t\t}, ms);\r\n\t\t\r\n\t}\r\n\r\n\tprivate time() {\r\n\t\tconst ms=twrTimeImpl();\r\n\t\tthis.parameters[0]=ms;\r\n\t\tthis.callCompleteSignal.signal();\r\n\t}\r\n\r\n\tgetProxyParams():TWaitingCallsProxyParams {\r\n\t\treturn [this.callCompleteSignal.sharedArray, this.parameters.buffer as SharedArrayBuffer];\t\r\n\t}\r\n\r\n\tprocessMessage(msgType:string, data:any[]):boolean {\r\n\t\tswitch (msgType) {\r\n\t\t\tcase \"sleep\":\r\n\t\t\t\tconst [ms] = data;\r\n\t\t\t\tthis.startSleep(ms);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"time\":\r\n\t\t\t\tthis.time();\r\n\t\t\t\tbreak;\r\n\t\t\t\r\n\t\t\tdefault:\r\n\t\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\treturn true;\r\n\t}\r\n\r\n}\r\n\r\n// This class is used in the worker thread \r\nexport class twrWaitingCallsProxy {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor(params:TWaitingCallsProxyParams) {\r\n\t\tthis.callCompleteSignal=new twrSignal(params[0]);\r\n\t\tthis.parameters=new Uint32Array(params[1]);\r\n\t}\r\n\r\n\tsleep(ms:number) {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"sleep\", [ms]]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t}\r\n\r\n\ttime() {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"time\"]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t\treturn this.parameters[0];\r\n\t}\r\n\r\n}\r\n","export function twrTimeImpl() {\n return Date.now();\n}\n//# sourceMappingURL=twrdate.js.map","\r\nexport function twrTimeImpl() {\r\n\r\n return Date.now();\r\n\r\n}"],"names":["$b93f1fdf40141def$var$twrSignalState","$c4741cac81d14197$var$D2DType","twrSignalState","D2DType","$3e39efa823870787$var$mod","$892fccfc812d5e20$export$a01cca24f011573a","sharedArray","buf","constructor","sa","window","crossOriginIsolated","location","protocol","Error","SharedArrayBuffer","Int32Array","write","n","i","Atomics","notify","read","isEmpty","readWait","rdptr","wait","$b93f1fdf40141def$export$e37a7b7b851b97f3","WAITING","signal","SIGNALED","isSignaled","reset","$c4741cac81d14197$export$c779b2cd00544976","canvasKeys","drawCompleteSignal","props","owner","params","signalBuffer","canvasKeysBuffer","charIn","inkey","getProp","pn","propName","getString","drawSeq","ds","postMessage","$8963973702ae5462$export$b377f0bbf2c7581e","divKeys","divKeysBuffer","charOut","ch","$8ac0b786da854328$export$485af4d0039b3389","$e72303a1db04bdfa$export$918ffb7e046a537b","mod","atod","strptr","str","upper","trimStart","toUpperCase","Number","POSITIVE_INFINITY","NEGATIVE_INFINITY","parseFloat","replaceAll","dtoa","buffer","buffer_size","value","max_precision","r","toString","copyString","length","toPrecision","toFixed","decdigits","toExponential","fcvtS","sizeInBytes","fracpart_numdigits","dec","sign","digits","decpos","s","isNaN","slice","isFinite","Math","abs","mem32","intPart","fracPart","roundValStr","split","replace","setLong","$ece7fa3ed770778a$export$c83a0a3bffe07399","memory","mem8","memD","exports","isWorker","isWasmModule","floatUtil","Uint8Array","Uint32Array","Float64Array","loadWasm","pathToLoad","response","fetch","err","console","log","ok","statusText","wasmBytes","arrayBuffer","allimports","modParams","imports","instance","WebAssembly","instantiate","env","ArrayBuffer","malloc","size","Promise","resolve","m","twr_malloc","init","stack","p","stdio","twrInit","twr_wasm_init","callC","cparams","preCallC","retval","callCImpl","postCallC","fname","f","Array","ci","putString","URL","fetchAndPutURL","putArrayBuffer","u8","j","sin","charCodeAt","strIndex","putU8","u8a","dest","ab","fnin","src","getLong","idx","idx32","floor","getDouble","idx64","setDouble","getShort","len","sout","undefined","String","fromCharCode","getU8Arr","rv","dataptr","getU32Arr","$aff9c2c494d23fe3$export$78d2a4633fe89379","callCompleteSignal","parameters","sleep","ms","time","onmessage","e","data","$3e39efa823870787$var$twrWasmModuleInWorker","modWorkerParams","urlToLoad","then","catch","ex","rc","modInWorkerParams","canvasProxy","canvasProxyParams","divProxy","divProxyParams","waitingCallsProxy","waitingCallsProxyParams","twrDebugLog","twrSleep","bind","twrTime","twrDivCharOut","twrDivCharIn","twrCanvasCharIn","twrCanvasInkey","twrCanvasGetProp","twrCanvasDrawSeq","twrSin","twrCos","cos","twrTan","tan","twrFAbs","twrACos","acos","twrASin","asin","twrATan","atan","twrExp","exp","twrFloor","twrCeil","ceil","twrFMod","x","y","twrLog","twrPow","pow","twrSqrt","sqrt","twrTrunc","trunc","twrDtoa","twrToFixed","twrToExponential","twrAtod","twrFcvtS"],"version":3,"file":"twrmodworker.2165e649.js.map"} \ No newline at end of file diff --git a/azure/examples/function-calls/index.html b/azure/examples/function-calls/index.html index c1f7d100..670139d6 100644 --- a/azure/examples/function-calls/index.html +++ b/azure/examples/function-calls/index.html @@ -30,7 +30,7 @@ await mod.loadWasm("./function-calls.wasm"); // this output goes to the console - await mod.executeC(["twr_wasm_print_mem_debug_stats"]); + await mod.callC(["twr_wasm_print_mem_debug_stats"]); const s="This is a string."; @@ -41,20 +41,20 @@ mod.divLog("module type is twrWasmModule\n"); mod.divLog("--- begin C call ---"); - let r=await mod.executeC(["function_calls", s, ba.buffer, ba.length, url]); + let r=await mod.callC(["function_calls", s, ba.buffer, ba.length, url]); mod.divLog("--- end C call ---\n"); mod.divLog("function_calls() returned: "+r); mod.divLog("as string: ", mod.getString(r)); if (mod.getString(r)!="forty-two - if only it were that simple") throw new Error("42 error"); - r=await mod.executeC(["get_structu32"]); + r=await mod.callC(["get_structu32"]); mod.divLog("get_struct32() returned: "+r); const ba32=mod.getU32Arr(r); mod.divLog("three 32 bit ints are: ", ba32[0], ba32[1], ba32[2]); if (ba32[0]!=1 || ba32[1]!=2000 || ba32[2]!=3) throw new Error("error"); - r=await mod.executeC(["get_structu8"]); + r=await mod.callC(["get_structu8"]); mod.divLog("get_struct8() returned: "+r); const ba8=mod.getU8Arr(r); mod.divLog("three 8 bit ints are: ", ba8[0], ba8[1], ba8[2]); diff --git a/azure/examples/helloworld/dist/index.html b/azure/examples/helloworld/dist/index.html index 3bb1fbec..3c3f8bd7 100644 --- a/azure/examples/helloworld/dist/index.html +++ b/azure/examples/helloworld/dist/index.html @@ -5,4 +5,4 @@ "whatkey": "../../lib-js/whatkey.js" } } -
\ No newline at end of file +
\ No newline at end of file diff --git a/azure/examples/helloworld/dist/twrmodworker.2165e649.js b/azure/examples/helloworld/dist/twrmodworker.2165e649.js index 3744680c..d8d07779 100644 --- a/azure/examples/helloworld/dist/twrmodworker.2165e649.js +++ b/azure/examples/helloworld/dist/twrmodworker.2165e649.js @@ -1,2 +1,2 @@ -(()=>{var t,e,r,s;let i;class a{sharedArray;buf;constructor(t){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSharedCircularBuffer constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");t?this.sharedArray=t:this.sharedArray=new SharedArrayBuffer(1032),this.buf=new Int32Array(this.sharedArray),this.buf[256]=0,this.buf[257]=0}write(t){let e=this.buf[257];this.buf[e]=t,256==++e&&(e=0),this.buf[257]=e,Atomics.notify(this.buf,257)}read(){if(this.isEmpty())return -1;{let t=this.buf[256],e=this.buf[t];return t++,this.buf[256]=t,e}}readWait(){if(this.isEmpty()){let t=this.buf[256];Atomics.wait(this.buf,257,t)}return this.read()}isEmpty(){return this.buf[256]==this.buf[257]}}(r=t||(t={}))[r.WAITING=0]="WAITING",r[r.SIGNALED=1]="SIGNALED";class o{sharedArray;buf;constructor(e){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSignal constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");e?this.sharedArray=e:this.sharedArray=new SharedArrayBuffer(4),this.buf=new Int32Array(this.sharedArray),this.buf[0]=t.WAITING}signal(){this.buf[0]=t.SIGNALED,Atomics.notify(this.buf,0)}wait(){this.buf[0]==t.WAITING&&Atomics.wait(this.buf,0,t.WAITING)}isSignaled(){return this.buf[0]==t.SIGNALED}reset(){this.buf[0]=t.WAITING}}(s=e||(e={}))[s.D2D_FILLRECT=1]="D2D_FILLRECT",s[s.D2D_FILLCHAR=5]="D2D_FILLCHAR",s[s.D2D_SETLINEWIDTH=10]="D2D_SETLINEWIDTH",s[s.D2D_SETFILLSTYLERGBA=11]="D2D_SETFILLSTYLERGBA",s[s.D2D_SETFONT=12]="D2D_SETFONT",s[s.D2D_BEGINPATH=13]="D2D_BEGINPATH",s[s.D2D_MOVETO=14]="D2D_MOVETO",s[s.D2D_LINETO=15]="D2D_LINETO",s[s.D2D_FILL=16]="D2D_FILL",s[s.D2D_STROKE=17]="D2D_STROKE",s[s.D2D_SETSTROKESTYLERGBA=18]="D2D_SETSTROKESTYLERGBA",s[s.D2D_ARC=19]="D2D_ARC",s[s.D2D_STROKERECT=20]="D2D_STROKERECT",s[s.D2D_FILLTEXT=21]="D2D_FILLTEXT",s[s.D2D_IMAGEDATA=22]="D2D_IMAGEDATA",s[s.D2D_PUTIMAGEDATA=23]="D2D_PUTIMAGEDATA",s[s.D2D_BEZIERTO=24]="D2D_BEZIERTO",s[s.D2D_MEASURETEXT=25]="D2D_MEASURETEXT",s[s.D2D_SAVE=26]="D2D_SAVE",s[s.D2D_RESTORE=27]="D2D_RESTORE",s[s.D2D_CREATERADIALGRADIENT=28]="D2D_CREATERADIALGRADIENT",s[s.D2D_SETCOLORSTOP=29]="D2D_SETCOLORSTOP",s[s.D2D_SETFILLSTYLEGRADIENT=30]="D2D_SETFILLSTYLEGRADIENT",s[s.D2D_RELEASEID=31]="D2D_RELEASEID",s[s.D2D_CREATELINEARGRADIENT=32]="D2D_CREATELINEARGRADIENT",s[s.D2D_SETFILLSTYLE=33]="D2D_SETFILLSTYLE",s[s.D2D_SETSTROKESTYLE=34]="D2D_SETSTROKESTYLE";class n{canvasKeys;drawCompleteSignal;props;owner;constructor(t,e){let[r,s,i]=t;this.drawCompleteSignal=new o(s),this.canvasKeys=new a(i),this.props=r,this.owner=e}charIn(){return this.canvasKeys.readWait()}inkey(){return this.canvasKeys.isEmpty()?0:this.charIn()}getProp(t){let e=this.owner.getString(t);return this.props[e]}drawSeq(t){this.drawCompleteSignal.reset(),postMessage(["drawseq",[t]]),this.drawCompleteSignal.wait()}}class l{divKeys;constructor(t){let[e]=t;this.divKeys=new a(e)}charIn(){return this.divKeys.readWait()}inkey(){return this.divKeys.isEmpty()?0:this.charIn()}charOut(t){postMessage(["divout",t])}}function h(t){postMessage(["debug",t])}class m{mod;constructor(t){this.mod=t}atod(t){let e=this.mod.getString(t),r=e.trimStart().toUpperCase();return"INF"==r||"+INF"==r?Number.POSITIVE_INFINITY:"-INF"==r?Number.NEGATIVE_INFINITY:Number.parseFloat(e.replaceAll("D","e").replaceAll("d","e"))}dtoa(t,e,r,s){if(-1==s){let s=r.toString();this.mod.copyString(t,e,s)}else{let i=r.toString();i.length>s&&(i=r.toPrecision(s)),this.mod.copyString(t,e,i)}}toFixed(t,e,r,s){let i=r.toFixed(s);this.mod.copyString(t,e,i)}toExponential(t,e,r,s){let i=r.toExponential(s);this.mod.copyString(t,e,i)}fcvtS(t,e,r,s,i,a){let o,n;if(0==t||0==a||0==i||e<1)return 1;let l=0;if(Number.isNaN(r))o="1#QNAN00000000000000000000000000000".slice(0,s+1),n=1;else if(Number.isFinite(r)){if(0==r)o="000000000000000000000000000000000000".slice(0,s),n=0;else{if(r<0&&(l=1,r=Math.abs(r)),s>100||r>1e21||r<1e-99)return this.mod.copyString(t,e,""),this.mod.mem32[i]=0,1;let[a="",h=""]=r.toFixed(s).split(".");"0"==a&&(a=""),a.length>0?(n=a.length,o=a+h):n=(o=h.replace(/^0+/,"")).length-h.length}}else o="1#INF00000000000000000000000000000".slice(0,s+1),n=1;return e-1new Promise(e=>{let r=this.exports.twr_malloc;e(r(t))}),this.init()}catch(t){throw console.log("WASM instantiate error: "+t+(t.stack?"\n"+t.stack:"")),t}}init(){let t;switch(this.modParams.stdio){case"debug":default:t=0;break;case"div":t=1;break;case"canvas":t=2;break;case"null":t=3}(0,this.exports.twr_wasm_init)(t,this.mem8.length)}async executeC(t){let e=await this.preCallC(t),r=this.executeCImpl(t[0],e);return this.postCallC(e,t),r}async executeCImpl(t,e=[]){if(!this.exports)throw Error("this.exports undefined");if(!this.exports[t])throw Error("executeC: function '"+t+"' not in export table. Use --export wasm-ld flag.");return(0,this.exports[t])(...e)}async preCallC(t){if(t.constructor!==Array)throw Error("executeC: params must be array, first arg is function name");if(0==t.length)throw Error("executeC: missing function name");let e=[],r=0;for(let s=1;s=this.mem32.length)throw Error("invalid index passed to getLong: "+t+", this.mem32.length: "+this.mem32.length);return this.mem32[e]}setLong(t,e){let r=Math.floor(t/4);if(4*r!=t)throw Error("setLong passed non long aligned address");if(r<0||r>=this.mem32.length)throw Error("invalid index passed to setLong: "+t+", this.mem32.length: "+this.mem32.length);this.mem32[r]=e}getDouble(t){let e=Math.floor(t/8);if(8*e!=t)throw Error("getLong passed non Float64 aligned address");return this.memD[e]}setDouble(t,e){let r=Math.floor(t/8);if(8*r!=t)throw Error("setDouble passed non Float64 aligned address");this.memD[r]=e}getShort(t){if(t<0||t>=this.mem8.length)throw Error("invalid index passed to getShort: "+t);return this.mem8[t]+256*this.mem8[t+1]}getString(t,e){let r="",s=0;for(;this.mem8[t+s]&&(void 0===e||s=this.mem8.length)throw Error("invalid index passed to getU8: "+t);let e=new Uint32Array(this.mem8.slice(t,t+8).buffer),r=e[0],s=e[1];if(s<0||s>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU8");if(r<0||r>this.mem8.length-s)throw Error("invalid idx.size passed to getU8");return this.mem8.slice(s,s+r)}getU32Arr(t){if(t<0||t>=this.mem8.length)throw Error("invalid index passed to getU32: "+t);let e=new Uint32Array(this.mem8.slice(t,t+8).buffer),r=e[0],s=e[1];if(s<0||s>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU32");if(r<0||r>this.mem8.length-s)throw Error("invalid idx.size passed to getU32");if(r%4!=0)throw Error("idx.size is not an integer number of 32 bit words");return new Uint32Array(this.mem8.slice(s,s+r).buffer)}}class d{callCompleteSignal;parameters;constructor(t){this.callCompleteSignal=new o(t[0]),this.parameters=new Uint32Array(t[1])}sleep(t){this.callCompleteSignal.reset(),postMessage(["sleep",[t]]),this.callCompleteSignal.wait()}time(){return this.callCompleteSignal.reset(),postMessage(["time"]),this.callCompleteSignal.wait(),this.parameters[0]}}onmessage=function(t){if("startup"==t.data[0]){let e=t.data[1];(i=new f(e.modParams,e.modWorkerParams)).loadWasm(e.urlToLoad).then(()=>{postMessage(["startupOkay"])}).catch(t=>{console.log(".catch: ",t),postMessage(["startupFail",t])})}else"executeC"==t.data[0]?i.executeCImpl(t.data[1],t.data[2]).then(t=>{postMessage(["executeCOkay",t])}).catch(t=>{console.log("exception in executeC twrworker.js\n"),console.log(t),postMessage(["executeCFail",t])}):console.log("twrworker.js: unknown message: "+t)};class f extends c{malloc;modParams;constructor(t,e){super(),this.isWorker=!0,this.malloc=t=>{throw Error("error - un-init malloc called")},this.modParams=t;let r=new n(e.canvasProxyParams,this),s=new l(e.divProxyParams),i=new d(e.waitingCallsProxyParams);this.modParams.imports={twrDebugLog:h,twrSleep:i.sleep.bind(i),twrTime:i.time.bind(i),twrDivCharOut:s.charOut.bind(s),twrDivCharIn:s.charIn.bind(s),twrCanvasCharIn:r.charIn.bind(r),twrCanvasInkey:r.inkey.bind(r),twrCanvasGetProp:r.getProp.bind(r),twrCanvasDrawSeq:r.drawSeq.bind(r),twrSin:Math.sin,twrCos:Math.cos,twrTan:Math.tan,twrFAbs:Math.abs,twrACos:Math.acos,twrASin:Math.asin,twrATan:Math.atan,twrExp:Math.exp,twrFloor:Math.floor,twrCeil:Math.ceil,twrFMod:function(t,e){return t%e},twrLog:Math.log,twrPow:Math.pow,twrSqrt:Math.sqrt,twrTrunc:Math.trunc,twrDtoa:this.floatUtil.dtoa.bind(this.floatUtil),twrToFixed:this.floatUtil.toFixed.bind(this.floatUtil),twrToExponential:this.floatUtil.toExponential.bind(this.floatUtil),twrAtod:this.floatUtil.atod.bind(this.floatUtil),twrFcvtS:this.floatUtil.fcvtS.bind(this.floatUtil)}}}})(); +(()=>{var t,e,r,s;let i;class a{sharedArray;buf;constructor(t){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSharedCircularBuffer constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");t?this.sharedArray=t:this.sharedArray=new SharedArrayBuffer(1032),this.buf=new Int32Array(this.sharedArray),this.buf[256]=0,this.buf[257]=0}write(t){let e=this.buf[257];this.buf[e]=t,256==++e&&(e=0),this.buf[257]=e,Atomics.notify(this.buf,257)}read(){if(this.isEmpty())return -1;{let t=this.buf[256],e=this.buf[t];return t++,this.buf[256]=t,e}}readWait(){if(this.isEmpty()){let t=this.buf[256];Atomics.wait(this.buf,257,t)}return this.read()}isEmpty(){return this.buf[256]==this.buf[257]}}(r=t||(t={}))[r.WAITING=0]="WAITING",r[r.SIGNALED=1]="SIGNALED";class o{sharedArray;buf;constructor(e){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSignal constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");e?this.sharedArray=e:this.sharedArray=new SharedArrayBuffer(4),this.buf=new Int32Array(this.sharedArray),this.buf[0]=t.WAITING}signal(){this.buf[0]=t.SIGNALED,Atomics.notify(this.buf,0)}wait(){this.buf[0]==t.WAITING&&Atomics.wait(this.buf,0,t.WAITING)}isSignaled(){return this.buf[0]==t.SIGNALED}reset(){this.buf[0]=t.WAITING}}(s=e||(e={}))[s.D2D_FILLRECT=1]="D2D_FILLRECT",s[s.D2D_FILLCHAR=5]="D2D_FILLCHAR",s[s.D2D_SETLINEWIDTH=10]="D2D_SETLINEWIDTH",s[s.D2D_SETFILLSTYLERGBA=11]="D2D_SETFILLSTYLERGBA",s[s.D2D_SETFONT=12]="D2D_SETFONT",s[s.D2D_BEGINPATH=13]="D2D_BEGINPATH",s[s.D2D_MOVETO=14]="D2D_MOVETO",s[s.D2D_LINETO=15]="D2D_LINETO",s[s.D2D_FILL=16]="D2D_FILL",s[s.D2D_STROKE=17]="D2D_STROKE",s[s.D2D_SETSTROKESTYLERGBA=18]="D2D_SETSTROKESTYLERGBA",s[s.D2D_ARC=19]="D2D_ARC",s[s.D2D_STROKERECT=20]="D2D_STROKERECT",s[s.D2D_FILLTEXT=21]="D2D_FILLTEXT",s[s.D2D_IMAGEDATA=22]="D2D_IMAGEDATA",s[s.D2D_PUTIMAGEDATA=23]="D2D_PUTIMAGEDATA",s[s.D2D_BEZIERTO=24]="D2D_BEZIERTO",s[s.D2D_MEASURETEXT=25]="D2D_MEASURETEXT",s[s.D2D_SAVE=26]="D2D_SAVE",s[s.D2D_RESTORE=27]="D2D_RESTORE",s[s.D2D_CREATERADIALGRADIENT=28]="D2D_CREATERADIALGRADIENT",s[s.D2D_SETCOLORSTOP=29]="D2D_SETCOLORSTOP",s[s.D2D_SETFILLSTYLEGRADIENT=30]="D2D_SETFILLSTYLEGRADIENT",s[s.D2D_RELEASEID=31]="D2D_RELEASEID",s[s.D2D_CREATELINEARGRADIENT=32]="D2D_CREATELINEARGRADIENT",s[s.D2D_SETFILLSTYLE=33]="D2D_SETFILLSTYLE",s[s.D2D_SETSTROKESTYLE=34]="D2D_SETSTROKESTYLE";class n{canvasKeys;drawCompleteSignal;props;owner;constructor(t,e){let[r,s,i]=t;this.drawCompleteSignal=new o(s),this.canvasKeys=new a(i),this.props=r,this.owner=e}charIn(){return this.canvasKeys.readWait()}inkey(){return this.canvasKeys.isEmpty()?0:this.charIn()}getProp(t){let e=this.owner.getString(t);return this.props[e]}drawSeq(t){this.drawCompleteSignal.reset(),postMessage(["drawseq",[t]]),this.drawCompleteSignal.wait()}}class l{divKeys;constructor(t){let[e]=t;this.divKeys=new a(e)}charIn(){return this.divKeys.readWait()}inkey(){return this.divKeys.isEmpty()?0:this.charIn()}charOut(t){postMessage(["divout",t])}}function h(t){postMessage(["debug",t])}class m{mod;constructor(t){this.mod=t}atod(t){let e=this.mod.getString(t),r=e.trimStart().toUpperCase();return"INF"==r||"+INF"==r?Number.POSITIVE_INFINITY:"-INF"==r?Number.NEGATIVE_INFINITY:Number.parseFloat(e.replaceAll("D","e").replaceAll("d","e"))}dtoa(t,e,r,s){if(-1==s){let s=r.toString();this.mod.copyString(t,e,s)}else{let i=r.toString();i.length>s&&(i=r.toPrecision(s)),this.mod.copyString(t,e,i)}}toFixed(t,e,r,s){let i=r.toFixed(s);this.mod.copyString(t,e,i)}toExponential(t,e,r,s){let i=r.toExponential(s);this.mod.copyString(t,e,i)}fcvtS(t,e,r,s,i,a){let o,n;if(0==t||0==a||0==i||e<1)return 1;let l=0;if(Number.isNaN(r))o="1#QNAN00000000000000000000000000000".slice(0,s+1),n=1;else if(Number.isFinite(r)){if(0==r)o="000000000000000000000000000000000000".slice(0,s),n=0;else{if(r<0&&(l=1,r=Math.abs(r)),s>100||r>1e21||r<1e-99)return this.mod.copyString(t,e,""),this.mod.mem32[i]=0,1;let[a="",h=""]=r.toFixed(s).split(".");"0"==a&&(a=""),a.length>0?(n=a.length,o=a+h):n=(o=h.replace(/^0+/,"")).length-h.length}}else o="1#INF00000000000000000000000000000".slice(0,s+1),n=1;return e-1new Promise(e=>{let r=this.exports.twr_malloc;e(r(t))}),this.init()}catch(t){throw console.log("WASM instantiate error: "+t+(t.stack?"\n"+t.stack:"")),t}}init(){let t;switch(this.modParams.stdio){case"debug":default:t=0;break;case"div":t=1;break;case"canvas":t=2;break;case"null":t=3}(0,this.exports.twr_wasm_init)(t,this.mem8.length)}async callC(t){let e=await this.preCallC(t),r=this.callCImpl(t[0],e);return this.postCallC(e,t),r}async callCImpl(t,e=[]){if(!this.exports)throw Error("this.exports undefined");if(!this.exports[t])throw Error("callC: function '"+t+"' not in export table. Use --export wasm-ld flag.");return(0,this.exports[t])(...e)}async preCallC(t){if(t.constructor!==Array)throw Error("callC: params must be array, first arg is function name");if(0==t.length)throw Error("callC: missing function name");let e=[],r=0;for(let s=1;s=this.mem32.length)throw Error("invalid index passed to getLong: "+t+", this.mem32.length: "+this.mem32.length);return this.mem32[e]}setLong(t,e){let r=Math.floor(t/4);if(4*r!=t)throw Error("setLong passed non long aligned address");if(r<0||r>=this.mem32.length)throw Error("invalid index passed to setLong: "+t+", this.mem32.length: "+this.mem32.length);this.mem32[r]=e}getDouble(t){let e=Math.floor(t/8);if(8*e!=t)throw Error("getLong passed non Float64 aligned address");return this.memD[e]}setDouble(t,e){let r=Math.floor(t/8);if(8*r!=t)throw Error("setDouble passed non Float64 aligned address");this.memD[r]=e}getShort(t){if(t<0||t>=this.mem8.length)throw Error("invalid index passed to getShort: "+t);return this.mem8[t]+256*this.mem8[t+1]}getString(t,e){let r="",s=0;for(;this.mem8[t+s]&&(void 0===e||s=this.mem8.length)throw Error("invalid index passed to getU8: "+t);let e=new Uint32Array(this.mem8.slice(t,t+8).buffer),r=e[0],s=e[1];if(s<0||s>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU8");if(r<0||r>this.mem8.length-s)throw Error("invalid idx.size passed to getU8");return this.mem8.slice(s,s+r)}getU32Arr(t){if(t<0||t>=this.mem8.length)throw Error("invalid index passed to getU32: "+t);let e=new Uint32Array(this.mem8.slice(t,t+8).buffer),r=e[0],s=e[1];if(s<0||s>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU32");if(r<0||r>this.mem8.length-s)throw Error("invalid idx.size passed to getU32");if(r%4!=0)throw Error("idx.size is not an integer number of 32 bit words");return new Uint32Array(this.mem8.slice(s,s+r).buffer)}}class d{callCompleteSignal;parameters;constructor(t){this.callCompleteSignal=new o(t[0]),this.parameters=new Uint32Array(t[1])}sleep(t){this.callCompleteSignal.reset(),postMessage(["sleep",[t]]),this.callCompleteSignal.wait()}time(){return this.callCompleteSignal.reset(),postMessage(["time"]),this.callCompleteSignal.wait(),this.parameters[0]}}onmessage=function(t){if("startup"==t.data[0]){let e=t.data[1];(i=new f(e.modParams,e.modWorkerParams)).loadWasm(e.urlToLoad).then(()=>{postMessage(["startupOkay"])}).catch(t=>{console.log(".catch: ",t),postMessage(["startupFail",t])})}else"callC"==t.data[0]?i.callCImpl(t.data[1],t.data[2]).then(t=>{postMessage(["callCOkay",t])}).catch(t=>{console.log("exception in callC twrworker.js\n"),console.log(t),postMessage(["callCFail",t])}):console.log("twrworker.js: unknown message: "+t)};class f extends c{malloc;modParams;constructor(t,e){super(),this.isWorker=!0,this.malloc=t=>{throw Error("error - un-init malloc called")},this.modParams=t;let r=new n(e.canvasProxyParams,this),s=new l(e.divProxyParams),i=new d(e.waitingCallsProxyParams);this.modParams.imports={twrDebugLog:h,twrSleep:i.sleep.bind(i),twrTime:i.time.bind(i),twrDivCharOut:s.charOut.bind(s),twrDivCharIn:s.charIn.bind(s),twrCanvasCharIn:r.charIn.bind(r),twrCanvasInkey:r.inkey.bind(r),twrCanvasGetProp:r.getProp.bind(r),twrCanvasDrawSeq:r.drawSeq.bind(r),twrSin:Math.sin,twrCos:Math.cos,twrTan:Math.tan,twrFAbs:Math.abs,twrACos:Math.acos,twrASin:Math.asin,twrATan:Math.atan,twrExp:Math.exp,twrFloor:Math.floor,twrCeil:Math.ceil,twrFMod:function(t,e){return t%e},twrLog:Math.log,twrPow:Math.pow,twrSqrt:Math.sqrt,twrTrunc:Math.trunc,twrDtoa:this.floatUtil.dtoa.bind(this.floatUtil),twrToFixed:this.floatUtil.toFixed.bind(this.floatUtil),twrToExponential:this.floatUtil.toExponential.bind(this.floatUtil),twrAtod:this.floatUtil.atod.bind(this.floatUtil),twrFcvtS:this.floatUtil.fcvtS.bind(this.floatUtil)}}}})(); //# sourceMappingURL=twrmodworker.2165e649.js.map diff --git a/azure/examples/helloworld/dist/twrmodworker.2165e649.js.map b/azure/examples/helloworld/dist/twrmodworker.2165e649.js.map index 29a4d41e..77745e98 100644 --- a/azure/examples/helloworld/dist/twrmodworker.2165e649.js.map +++ b/azure/examples/helloworld/dist/twrmodworker.2165e649.js.map @@ -1 +1 @@ -{"mappings":"A,C,SQKK,EJgBA,EIhBA,EJgBA,MFZD,CISE,OAAO,EACZ,WAA8B,AAC9B,CAAA,GAAe,AAEf,aAAa,CAAqB,CAAl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AS,SAAS,CAAQ,CAAE,CAAQ,EAAG,OAAO,EAAE,CAAC,EACjD,OAAQ,KAAK,GAAG,CAChB,OAAQ,KAAK,GAAG,CAChB,QAAS,KAAK,IAAI,CAClB,SAAU,KAAK,KAAK,CAEX,QAAS,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EACzD,WAAY,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EACtD,iBAAkB,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAClE,QAAS,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAChD,SAAU,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAE5C,CACN,CACF,C,C","sources":["","../../lib-js/twrmodworker.js","../../source/twr-wasm-ts/twrmodworker.ts","../../lib-js/twrcanvas.js","../../source/twr-wasm-ts/twrcanvas.ts","../../lib-js/twrcircular.js","../../source/twr-wasm-ts/twrcircular.ts","../../lib-js/twrsignal.js","../../source/twr-wasm-ts/twrsignal.ts","../../lib-js/twrdiv.js","../../source/twr-wasm-ts/twrdiv.ts","../../lib-js/twrdebug.js","../../source/twr-wasm-ts/twrdebug.ts","../../lib-js/twrmodbase.js","../../source/twr-wasm-ts/twrmodbase.ts","../../lib-js/twrfloat.js","../../source/twr-wasm-ts/twrfloat.ts","../../lib-js/twrwaitingcalls.js","../../source/twr-wasm-ts/twrwaitingcalls.ts","../../lib-js/twrdate.js","../../source/twr-wasm-ts/twrdate.ts"],"sourcesContent":["(() => {\nvar $3e39efa823870787$exports = {};\n// this script is the WebWorker thead used by class twrWasmAsyncModule\n//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst $892fccfc812d5e20$var$RDIDX = 256;\nconst $892fccfc812d5e20$var$WRIDX = 257;\nconst $892fccfc812d5e20$var$LEN = 256;\nclass $892fccfc812d5e20$export$a01cca24f011573a {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(1032);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[$892fccfc812d5e20$var$RDIDX] = 0;\n this.buf[$892fccfc812d5e20$var$WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[$892fccfc812d5e20$var$WRIDX];\n this.buf[i] = n;\n i++;\n if (i == $892fccfc812d5e20$var$LEN) i = 0;\n this.buf[$892fccfc812d5e20$var$WRIDX] = i;\n Atomics.notify(this.buf, $892fccfc812d5e20$var$WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[$892fccfc812d5e20$var$RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[$892fccfc812d5e20$var$RDIDX] = i;\n return n;\n } else return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[$892fccfc812d5e20$var$RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, $892fccfc812d5e20$var$WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[$892fccfc812d5e20$var$RDIDX] == this.buf[$892fccfc812d5e20$var$WRIDX];\n }\n}\n\n\n//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar $b93f1fdf40141def$var$twrSignalState;\n(function(twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})($b93f1fdf40141def$var$twrSignalState || ($b93f1fdf40141def$var$twrSignalState = {}));\nclass $b93f1fdf40141def$export$e37a7b7b851b97f3 {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == $b93f1fdf40141def$var$twrSignalState.WAITING) //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, $b93f1fdf40141def$var$twrSignalState.WAITING);\n }\n isSignaled() {\n return this.buf[0] == $b93f1fdf40141def$var$twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.WAITING;\n }\n}\n\n\nvar $c4741cac81d14197$var$D2DType;\n(function(D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})($c4741cac81d14197$var$D2DType || ($c4741cac81d14197$var$D2DType = {}));\nclass $c4741cac81d14197$export$2f298dd69cef3c34 {\n ctx;\n props = {\n charWidth: 0,\n charHeight: 0,\n foreColor: 0,\n backColor: 0,\n widthInChars: 0,\n heightInChars: 0,\n canvasHeight: 0,\n canvasWidth: 0\n };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase){\n const { forecolor: forecolor, backcolor: backcolor, fontsize: fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)();\n this.canvasKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.props,\n this.cmdCompleteSignal.sharedArray,\n this.canvasKeys.sharedArray\n ];\n }\n getProp(pn) {\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */ drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx) return;\n let ins = this.owner.getLong(ds); /* ds->start */ \n const lastins = this.owner.getLong(ds + 4); /* ds->last */ \n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while(true){\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */ \n switch(type){\n case $c4741cac81d14197$var$D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_BEGINPATH:\n this.ctx.beginPath();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILL:\n this.ctx.fill();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SAVE:\n this.ctx.save();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_RESTORE:\n this.ctx.restore();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_STROKE:\n this.ctx.stroke();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = this.owner.getLong(ins + 48) != 0;\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n } else this.precomputedObjects[id] = {\n mem8: new Uint8Array(this.owner.memory.buffer, start, length),\n width: width,\n height: height\n };\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id]) delete this.precomputedObjects[id];\n else console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n else {\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) this.ctx.putImageData(imgData, dx, dy);\n else this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */ \n if (next == 0) {\n if (ins != lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nclass $c4741cac81d14197$export$c779b2cd00544976 {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner){\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)(signalBuffer);\n this.canvasKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\n \"drawseq\",\n [\n ds\n ]\n ]);\n this.drawCompleteSignal.wait();\n }\n}\n\n\n\nclass $8963973702ae5462$export$dd376bb3f10f6896 {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611);\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase){\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) this.divKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(); // tsconfig, lib must be set to 2017 or higher\n if (this.div && !modParams.styleIsDefault) {\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.divKeys.sharedArray\n ];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */ charOut(ch) {\n if (!this.div) return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n }\n switch(ch){\n case 10:\n case 13:\n if (ch == 10 && this.lastChar == 13) break; // detect CR LF and treat as single new line\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n case 0xE:\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF:\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for(let i = 0; i < str.length; i++)this.charOut(str.charCodeAt(i));\n }\n}\nclass $8963973702ae5462$export$b377f0bbf2c7581e {\n divKeys;\n constructor(params){\n const [divKeysBuffer] = params;\n this.divKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n charOut(ch) {\n postMessage([\n \"divout\",\n ch\n ]);\n }\n}\n\n\nlet $8ac0b786da854328$var$logline = \"\";\nfunction $8ac0b786da854328$export$16b4216ec014493d(char) {\n if (char == 10 || char == 3) {\n console.log($8ac0b786da854328$var$logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n $8ac0b786da854328$var$logline = \"\";\n } else {\n $8ac0b786da854328$var$logline = $8ac0b786da854328$var$logline + String.fromCharCode(char);\n if ($8ac0b786da854328$var$logline.length >= 200) {\n console.log($8ac0b786da854328$var$logline);\n $8ac0b786da854328$var$logline = \"\";\n }\n }\n}\nfunction $8ac0b786da854328$export$485af4d0039b3389(ch) {\n postMessage([\n \"debug\",\n ch\n ]);\n}\n\n\nclass $e72303a1db04bdfa$export$918ffb7e046a537b {\n mod;\n constructor(mod){\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\") return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\") return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll(\"D\", \"e\").replaceAll(\"d\", \"e\"));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n } else {\n let r = value.toString();\n if (r.length > max_precision) r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, sizeInBytes, value, fracpart_numdigits, dec, sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1) return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) {\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (!Number.isFinite(value)) {\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n } else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split(\".\");\n if (intPart == \"0\") intPart = \"\";\n if (intPart.length > 0) {\n decpos = intPart.length;\n digits = intPart + fracPart;\n } else {\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length) return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */ }\n}\n\n\nclass $ece7fa3ed770778a$export$c83a0a3bffe07399 {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule;\n floatUtil;\n constructor(isWasmModule = false){\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new (0, $e72303a1db04bdfa$export$918ffb7e046a537b)(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/ /*********************************************************************/ async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n } catch (err) {\n console.log(\"loadWasm() failed to fetch: \" + pathToLoad);\n throw err;\n }\n if (!response.ok) throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, {\n env: allimports\n });\n this.exports = instance.instance.exports;\n if (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory) throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer) console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\n \"setmemory\",\n this.memory\n ]);\n }\n if (this.isWasmModule) // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n {\n if (!(this.memory.buffer instanceof ArrayBuffer)) console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size)=>{\n return new Promise((resolve)=>{\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n } catch (err) {\n console.log(\"WASM instantiate error: \" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch(this.modParams.stdio){\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* executeC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */ async executeC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.executeCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async executeCImpl(fname, cparams = []) {\n if (!this.exports) throw new Error(\"this.exports undefined\");\n if (!this.exports[fname]) throw new Error(\"executeC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array)) throw new Error(\"executeC: params must be array, first arg is function name\");\n if (params.length == 0) throw new Error(\"executeC: missing function name\");\n let cparams = [];\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n cparams[ci++] = p;\n break;\n case \"string\":\n cparams[ci++] = await this.putString(p);\n break;\n case \"object\":\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n } else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"executeC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n ci++;\n break;\n case \"string\":\n this.executeCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n case \"object\":\n if (p instanceof URL) {\n this.executeCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci = ci + 2;\n break;\n } else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for(let j = 0; j < u8.length; j++)u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.executeCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n } else throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/ /*********************************************************************/ // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for(i = 0; i < sin.length && i < buffer_size - 1; i++)this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for(let i = 0; i < u8a.length; i++)this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === \"object\" && fnin instanceof URL)) throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [\n dest,\n src.length\n ];\n } catch (err) {\n console.log(\"fetchAndPutURL Error. URL: \" + fnin + \"\\n\" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while(this.mem8[strIndex + i] && (len === undefined ? true : i < len) && strIndex + i < this.mem8.length){\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array(this.mem8.slice(dataptr, dataptr + size).buffer);\n return u32;\n }\n}\n\n\n\nfunction $4af5689abbc8d01b$export$78724cdcf7ebea1d() {\n return Date.now();\n}\n\n\nclass $aff9c2c494d23fe3$export$9e37856d1928d388 {\n callCompleteSignal;\n parameters;\n constructor(){\n this.callCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(()=>{\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = (0, $4af5689abbc8d01b$export$78724cdcf7ebea1d)();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [\n this.callCompleteSignal.sharedArray,\n this.parameters.buffer\n ];\n }\n processMessage(msgType, data) {\n switch(msgType){\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\nclass $aff9c2c494d23fe3$export$78d2a4633fe89379 {\n callCompleteSignal;\n parameters;\n constructor(params){\n this.callCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\n \"sleep\",\n [\n ms\n ]\n ]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\n \"time\"\n ]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n\n\nlet $3e39efa823870787$var$mod;\nonmessage = function(e) {\n //console.log('twrworker.js: message received from main script: '+e.data);\n if (e.data[0] == \"startup\") {\n const params = e.data[1];\n //console.log(\"Worker startup params:\",params);\n $3e39efa823870787$var$mod = new $3e39efa823870787$var$twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\n $3e39efa823870787$var$mod.loadWasm(params.urlToLoad).then(()=>{\n postMessage([\n \"startupOkay\"\n ]);\n }).catch((ex)=>{\n console.log(\".catch: \", ex);\n postMessage([\n \"startupFail\",\n ex\n ]);\n });\n } else if (e.data[0] == \"executeC\") $3e39efa823870787$var$mod.executeCImpl(e.data[1], e.data[2]).then((rc)=>{\n postMessage([\n \"executeCOkay\",\n rc\n ]);\n }).catch((e)=>{\n console.log(\"exception in executeC twrworker.js\\n\");\n console.log(e);\n postMessage([\n \"executeCFail\",\n e\n ]);\n });\n else console.log(\"twrworker.js: unknown message: \" + e);\n};\n// ************************************************************************\nclass $3e39efa823870787$var$twrWasmModuleInWorker extends (0, $ece7fa3ed770778a$export$c83a0a3bffe07399) {\n malloc;\n modParams;\n constructor(modParams, modInWorkerParams){\n super();\n this.isWorker = true;\n this.malloc = (size)=>{\n throw new Error(\"error - un-init malloc called\");\n };\n this.modParams = modParams;\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\n const canvasProxy = new (0, $c4741cac81d14197$export$c779b2cd00544976)(modInWorkerParams.canvasProxyParams, this);\n const divProxy = new (0, $8963973702ae5462$export$b377f0bbf2c7581e)(modInWorkerParams.divProxyParams);\n const waitingCallsProxy = new (0, $aff9c2c494d23fe3$export$78d2a4633fe89379)(modInWorkerParams.waitingCallsProxyParams);\n this.modParams.imports = {\n twrDebugLog: (0, $8ac0b786da854328$export$485af4d0039b3389),\n twrSleep: waitingCallsProxy.sleep.bind(waitingCallsProxy),\n twrTime: waitingCallsProxy.time.bind(waitingCallsProxy),\n twrDivCharOut: divProxy.charOut.bind(divProxy),\n twrDivCharIn: divProxy.charIn.bind(divProxy),\n twrCanvasCharIn: canvasProxy.charIn.bind(canvasProxy),\n twrCanvasInkey: canvasProxy.inkey.bind(canvasProxy),\n twrCanvasGetProp: canvasProxy.getProp.bind(canvasProxy),\n twrCanvasDrawSeq: canvasProxy.drawSeq.bind(canvasProxy),\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function(x, y) {\n return x % y;\n },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n}\n\n})();\n//# sourceMappingURL=twrmodworker.2165e649.js.map\n","// this script is the WebWorker thead used by class twrWasmAsyncModule\nimport { twrCanvasProxy } from \"./twrcanvas.js\";\nimport { twrDivProxy } from \"./twrdiv.js\";\nimport { twrDebugLogProxy } from \"./twrdebug.js\";\nimport { twrWasmModuleBase } from \"./twrmodbase.js\";\nimport { twrWaitingCallsProxy } from \"./twrwaitingcalls.js\";\nlet mod;\nonmessage = function (e) {\n //console.log('twrworker.js: message received from main script: '+e.data);\n if (e.data[0] == 'startup') {\n const params = e.data[1];\n //console.log(\"Worker startup params:\",params);\n mod = new twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\n mod.loadWasm(params.urlToLoad).then(() => {\n postMessage([\"startupOkay\"]);\n }).catch((ex) => {\n console.log(\".catch: \", ex);\n postMessage([\"startupFail\", ex]);\n });\n }\n else if (e.data[0] == 'executeC') {\n mod.executeCImpl(e.data[1], e.data[2]).then((rc) => {\n postMessage([\"executeCOkay\", rc]);\n }).catch(e => {\n console.log(\"exception in executeC twrworker.js\\n\");\n console.log(e);\n postMessage([\"executeCFail\", e]);\n });\n }\n else {\n console.log(\"twrworker.js: unknown message: \" + e);\n }\n};\n// ************************************************************************\nclass twrWasmModuleInWorker extends twrWasmModuleBase {\n malloc;\n modParams;\n constructor(modParams, modInWorkerParams) {\n super();\n this.isWorker = true;\n this.malloc = (size) => { throw new Error(\"error - un-init malloc called\"); };\n this.modParams = modParams;\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\n const canvasProxy = new twrCanvasProxy(modInWorkerParams.canvasProxyParams, this);\n const divProxy = new twrDivProxy(modInWorkerParams.divProxyParams);\n const waitingCallsProxy = new twrWaitingCallsProxy(modInWorkerParams.waitingCallsProxyParams);\n this.modParams.imports = {\n twrDebugLog: twrDebugLogProxy,\n twrSleep: waitingCallsProxy.sleep.bind(waitingCallsProxy),\n twrTime: waitingCallsProxy.time.bind(waitingCallsProxy),\n twrDivCharOut: divProxy.charOut.bind(divProxy),\n twrDivCharIn: divProxy.charIn.bind(divProxy),\n twrCanvasCharIn: canvasProxy.charIn.bind(canvasProxy),\n twrCanvasInkey: canvasProxy.inkey.bind(canvasProxy),\n twrCanvasGetProp: canvasProxy.getProp.bind(canvasProxy),\n twrCanvasDrawSeq: canvasProxy.drawSeq.bind(canvasProxy),\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function (x, y) { return x % y; },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n}\n//# sourceMappingURL=twrmodworker.js.map","// this script is the WebWorker thead used by class twrWasmAsyncModule\r\n\r\nimport {twrCanvasProxy} from \"./twrcanvas.js\";\r\nimport {twrDivProxy} from \"./twrdiv.js\";\r\nimport {twrDebugLogProxy} from \"./twrdebug.js\";\r\nimport {TAsyncModStartupMsg} from \"./twrmodasync.js\"\r\nimport {twrWasmModuleBase, IModInWorkerParams, IModParams} from \"./twrmodbase.js\"\r\nimport {twrWaitingCallsProxy} from \"./twrwaitingcalls.js\";\r\n\r\nlet mod:twrWasmModuleInWorker;\r\n\r\nonmessage = function(e) {\r\n //console.log('twrworker.js: message received from main script: '+e.data);\r\n\r\n if (e.data[0]=='startup') {\r\n const params:TAsyncModStartupMsg=e.data[1];\r\n //console.log(\"Worker startup params:\",params);\r\n mod=new twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\r\n\r\n mod.loadWasm(params.urlToLoad).then( ()=> {\r\n postMessage([\"startupOkay\"]);\r\n }).catch( (ex)=> {\r\n console.log(\".catch: \", ex);\r\n postMessage([\"startupFail\", ex]);\r\n });\r\n }\r\n else if (e.data[0]=='executeC') {\r\n mod.executeCImpl(e.data[1], e.data[2]).then( (rc)=> {\r\n postMessage([\"executeCOkay\", rc]);\r\n }).catch(e => {\r\n console.log(\"exception in executeC twrworker.js\\n\");\r\n console.log(e);\r\n postMessage([\"executeCFail\", e]);\r\n });\r\n }\r\n else {\r\n console.log(\"twrworker.js: unknown message: \"+e);\r\n }\r\n}\r\n\r\n\r\n// ************************************************************************\r\n\r\nclass twrWasmModuleInWorker extends twrWasmModuleBase {\r\n\tmalloc:(size:number)=>Promise;\r\n modParams: IModParams;\r\n\r\n\r\n constructor(modParams:IModParams, modInWorkerParams:IModInWorkerParams) {\r\n super();\r\n this.isWorker=true;\r\n this.malloc=(size:number)=>{throw new Error(\"error - un-init malloc called\")};\r\n this.modParams=modParams;\r\n\r\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\r\n const canvasProxy = new twrCanvasProxy(modInWorkerParams.canvasProxyParams, this);\r\n const divProxy = new twrDivProxy(modInWorkerParams.divProxyParams);\r\n const waitingCallsProxy = new twrWaitingCallsProxy(modInWorkerParams.waitingCallsProxyParams);\r\n\r\n this.modParams.imports={\r\n twrDebugLog:twrDebugLogProxy,\r\n twrSleep:waitingCallsProxy.sleep.bind(waitingCallsProxy),\r\n twrTime:waitingCallsProxy.time.bind(waitingCallsProxy),\r\n\r\n twrDivCharOut:divProxy.charOut.bind(divProxy), \r\n twrDivCharIn:divProxy.charIn.bind(divProxy), \r\n\r\n twrCanvasCharIn:canvasProxy.charIn.bind(canvasProxy),\r\n twrCanvasInkey:canvasProxy.inkey.bind(canvasProxy),\r\n twrCanvasGetProp:canvasProxy.getProp.bind(canvasProxy),\r\n twrCanvasDrawSeq:canvasProxy.drawSeq.bind(canvasProxy),\r\n\r\n\t\t\ttwrSin:Math.sin,\r\n\t\t\ttwrCos:Math.cos,\r\n\t\t\ttwrTan: Math.tan,\r\n\t\t\ttwrFAbs: Math.abs,\r\n\t\t\ttwrACos: Math.acos,\r\n\t\t\ttwrASin: Math.asin,\r\n\t\t\ttwrATan: Math.atan,\r\n\t\t\ttwrExp: Math.exp,\r\n\t\t\ttwrFloor: Math.floor,\r\n\t\t\ttwrCeil: Math.ceil,\r\n\t\t\ttwrFMod: function(x:number, y:number) {return x%y},\r\n\t\t\ttwrLog: Math.log,\r\n\t\t\ttwrPow: Math.pow,\r\n\t\t\ttwrSqrt: Math.sqrt,\r\n\t\t\ttwrTrunc: Math.trunc,\r\n\r\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\r\n\t\t\ttwrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\r\n\t\t\ttwrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\r\n\t\t\ttwrAtod: this.floatUtil.atod.bind(this.floatUtil),\r\n\t\t\ttwrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\r\n \r\n }\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nimport { twrSignal } from \"./twrsignal.js\";\nvar D2DType;\n(function (D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})(D2DType || (D2DType = {}));\nexport class twrCanvas {\n ctx;\n props = { charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight: 0, canvasWidth: 0 };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase) {\n const { forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new twrSignal();\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext)\n throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c)\n throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2)\n throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\n }\n getProp(pn) {\n if (!this.isValid())\n console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */\n drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid())\n console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx)\n return;\n let ins = this.owner.getLong(ds); /* ds->start */\n const lastins = this.owner.getLong(ds + 4); /* ds->last */\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while (1) {\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */\n if (0 /*type!=D2DType.D2D_FILLRECT*/) {\n console.log(\"ins\", ins);\n console.log(\"hdr.next\", this.owner.mem8[ins], this.owner.mem8[ins + 1], this.owner.mem8[ins + 2], this.owner.mem8[ins + 3]);\n console.log(\"hdr.type\", this.owner.mem8[ins + 4], this.owner.mem8[ins + 5]);\n console.log(\"next 4 bytes\", this.owner.mem8[ins + 6], this.owner.mem8[ins + 7], this.owner.mem8[ins + 8], this.owner.mem8[ins + 9]);\n console.log(\"and 4 more \", this.owner.mem8[ins + 10], this.owner.mem8[ins + 11], this.owner.mem8[ins + 12], this.owner.mem8[ins + 13]);\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\n }\n switch (type) {\n case D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case D2DType.D2D_BEGINPATH:\n {\n this.ctx.beginPath();\n }\n break;\n case D2DType.D2D_FILL:\n {\n this.ctx.fill();\n }\n break;\n case D2DType.D2D_SAVE:\n {\n this.ctx.save();\n }\n break;\n case D2DType.D2D_RESTORE:\n {\n this.ctx.restore();\n }\n break;\n case D2DType.D2D_STROKE:\n {\n this.ctx.stroke();\n }\n break;\n case D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = (this.owner.getLong(ins + 48) != 0);\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n }\n else { // Uint8ClampedArray doesn't support shared memory\n this.precomputedObjects[id] = { mem8: new Uint8Array(this.owner.memory.buffer, start, length), width: width, height: height };\n }\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id])\n delete this.precomputedObjects[id];\n else\n console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) {\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n }\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) {\n this.ctx.putImageData(imgData, dx, dy);\n }\n else {\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */\n if (next == 0) {\n if (ins != lastins)\n throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal)\n this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nexport class twrCanvasProxy {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner) {\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new twrSignal(signalBuffer);\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\"drawseq\", [ds]]);\n this.drawCompleteSignal.wait();\n }\n}\n//# sourceMappingURL=twrcanvas.js.map","import {twrWasmModuleBase, IModParams} from \"./twrmodbase.js\"\r\nimport {twrSharedCircularBuffer} from \"./twrcircular.js\";\r\nimport {twrSignal} from \"./twrsignal.js\";\r\n\r\n\r\n// Canvas have a size that will be set based on the character width x height\r\n// The display size for a canvas will default to this size, but can be changed in the HTML/JS via\r\n// canvas.style.width = \"700px\";\r\n// canvas.style.height = \"500px\";\r\n\r\nexport interface ICanvasProps {\r\n\tcharWidth: number,\r\n\tcharHeight: number,\r\n\tforeColor: number,\r\n\tbackColor: number,\r\n widthInChars: number,\r\n heightInChars: number,\r\n canvasWidth:number,\r\n canvasHeight:number\r\n}\r\n\r\nenum D2DType {\r\n D2D_FILLRECT=1,\r\n D2D_FILLCHAR=5,\r\n D2D_SETLINEWIDTH=10,\r\n D2D_SETFILLSTYLERGBA=11,\r\n D2D_SETFONT=12,\r\n D2D_BEGINPATH=13,\r\n D2D_MOVETO=14,\r\n D2D_LINETO=15,\r\n D2D_FILL=16,\r\n D2D_STROKE=17,\r\n D2D_SETSTROKESTYLERGBA=18,\r\n D2D_ARC=19,\r\n D2D_STROKERECT=20,\r\n D2D_FILLTEXT=21,\r\n D2D_IMAGEDATA=22,\r\n D2D_PUTIMAGEDATA=23,\r\n D2D_BEZIERTO=24,\r\n D2D_MEASURETEXT=25,\r\n D2D_SAVE=26,\r\n D2D_RESTORE=27,\r\n D2D_CREATERADIALGRADIENT=28,\r\n D2D_SETCOLORSTOP=29,\r\n D2D_SETFILLSTYLEGRADIENT=30,\r\n D2D_RELEASEID=31,\r\n D2D_CREATELINEARGRADIENT=32,\r\n D2D_SETFILLSTYLE=33,\r\n D2D_SETSTROKESTYLE=34\r\n\r\n}\r\n\r\nexport type TCanvasProxyParams = [ICanvasProps, SharedArrayBuffer, SharedArrayBuffer];\r\n\r\nexport interface ICanvas {\r\n props: ICanvasProps,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TCanvasProxyParams,\r\n drawSeq: (ds:number)=>void,\r\n }\r\n \r\nexport class twrCanvas implements ICanvas {\r\n ctx:CanvasRenderingContext2D|undefined;\r\n props:ICanvasProps={charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight:0, canvasWidth:0};\r\n owner: twrWasmModuleBase;\r\n cmdCompleteSignal?:twrSignal;\r\n canvasKeys?: twrSharedCircularBuffer;\r\n precomputedObjects: { [index: number]: \r\n (ImageData | {mem8:Uint8Array, width:number, height:number}) |\r\n CanvasGradient\r\n };\r\n\r\n constructor(element:HTMLCanvasElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n const {forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas} = modParams; \r\n this.owner=modbase;\r\n this.props.widthInChars=modParams.windim[0];\r\n this.props.heightInChars=modParams.windim[1];\r\n\r\n if (!this.owner.isWasmModule) {\r\n this.cmdCompleteSignal=new twrSignal();\r\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n }\r\n\r\n this.precomputedObjects={};\r\n \r\n if (element) {\r\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\r\n let c=element.getContext(\"2d\");\r\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\r\n\r\n c.font = fontsize.toString()+\"px Courier New\";\r\n c.textBaseline=\"top\";\r\n const sampleText=\" \";\r\n const tm=c.measureText(sampleText);\r\n this.props.charWidth=Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\r\n let fM = c.measureText(\"X\"); \r\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\r\n\r\n if (!isd2dcanvas) {\r\n element.width=this.props.charWidth*this.props.widthInChars;\r\n element.height=this.props.charHeight*this.props.heightInChars;\r\n }\r\n\r\n this.props.canvasHeight=element.height;\r\n this.props.canvasWidth=element.width;\r\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\r\n\r\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\r\n let c2=element.getContext(\"2d\");\r\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\r\n this.ctx=c2;\r\n this.ctx.font = fontsize.toString()+\"px Courier New\";\r\n this.ctx.textBaseline=\"top\";\r\n\r\n c2.fillStyle=backcolor;\r\n this.props.backColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n c2.fillStyle=forecolor;\r\n this.props.foreColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n }\r\n\r\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\r\n\r\n //console.log(\"twrCanvas.constructor props: \", this.props);\r\n }\r\n\r\n isValid() {\r\n return !!this.ctx;\r\n }\r\n\r\n getProxyParams() : TCanvasProxyParams {\r\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\r\n }\r\n\r\n getProp(pn:number): number {\r\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n\r\n/* see draw2d.h for structs that match */\r\n\r\n drawSeq(ds:number) {\r\n //console.log(\"twr::Canvas enter drawSeq\");\r\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\r\n if (!this.ctx) return;\r\n\r\n let ins=this.owner.getLong(ds); /* ds->start */\r\n const lastins=this.owner.getLong(ds+4); /* ds->last */\r\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\r\n\r\n let next:number;\r\n //let insCount=0;\r\n\r\n while (1) {\r\n\r\n //insCount++;\r\n\r\n const type:D2DType=this.owner.getLong(ins+4); /* hdr->type */\r\n if (0/*type!=D2DType.D2D_FILLRECT*/) {\r\n console.log(\"ins\",ins)\r\n console.log(\"hdr.next\",this.owner.mem8[ins],this.owner.mem8[ins+1],this.owner.mem8[ins+2],this.owner.mem8[ins+3]);\r\n console.log(\"hdr.type\",this.owner.mem8[ins+4],this.owner.mem8[ins+5]);\r\n console.log(\"next 4 bytes\", this.owner.mem8[ins+6],this.owner.mem8[ins+7],this.owner.mem8[ins+8],this.owner.mem8[ins+9]);\r\n console.log(\"and 4 more \", this.owner.mem8[ins+10],this.owner.mem8[ins+11],this.owner.mem8[ins+12],this.owner.mem8[ins+13]);\r\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\r\n }\r\n switch (type) {\r\n case D2DType.D2D_FILLRECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.fillRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKERECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.strokeRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILLCHAR:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const c=this.owner.getShort(ins+24);\r\n let txt=String.fromCharCode(c);\r\n this.ctx.fillText(txt, x, y);\r\n }\r\n break;\r\n\r\n \r\n case D2DType.D2D_FILLTEXT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const str=this.owner.getString(this.owner.getLong(ins+24));\r\n\r\n //console.log(\"filltext \",x,y,str)\r\n \r\n this.ctx.fillText(str, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MEASURETEXT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n const tmidx=this.owner.getLong(ins+12);\r\n \r\n const tm=this.ctx.measureText(str);\r\n this.owner.setDouble(tmidx+0, tm.actualBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+8, tm.actualBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+16, tm.actualBoundingBoxLeft);\r\n this.owner.setDouble(tmidx+24, tm.actualBoundingBoxRight);\r\n this.owner.setDouble(tmidx+32, tm.fontBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+40, tm.fontBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+48, tm.width);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFONT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.font=str;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.fillStyle = cssColor;\r\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETSTROKESTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.fillStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETSTROKESTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETLINEWIDTH:\r\n {\r\n const width=this.owner.getShort(ins+8); \r\n this.ctx.lineWidth=width;\r\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MOVETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.moveTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_LINETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.lineTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEZIERTO:\r\n {\r\n const cp1x=this.owner.getDouble(ins+8);\r\n const cp1y=this.owner.getDouble(ins+16);\r\n const cp2x=this.owner.getDouble(ins+24);\r\n const cp2y=this.owner.getDouble(ins+32);\r\n const x=this.owner.getDouble(ins+40);\r\n const y=this.owner.getDouble(ins+48);\r\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEGINPATH:\r\n {\r\n this.ctx.beginPath();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILL:\r\n {\r\n this.ctx.fill();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SAVE:\r\n {\r\n this.ctx.save();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_RESTORE:\r\n {\r\n this.ctx.restore();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKE:\r\n {\r\n this.ctx.stroke();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_ARC:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const radius=this.owner.getDouble(ins+24);\r\n const startAngle=this.owner.getDouble(ins+32);\r\n const endAngle=this.owner.getDouble(ins+40);\r\n const counterClockwise= (this.owner.getLong(ins+48)!=0);\r\n\r\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_IMAGEDATA:\r\n {\r\n const start=this.owner.getLong(ins+8);\r\n const length=this.owner.getLong(ins+12);\r\n const width=this.owner.getLong(ins+16);\r\n const height=this.owner.getLong(ins+20);\r\n const id=this.owner.getLong(ins+24);\r\n\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\r\n\r\n if (this.owner.isWasmModule) {\r\n const z = new Uint8ClampedArray(this.owner.memory!.buffer, start, length);\r\n this.precomputedObjects[id]=new ImageData(z, width, height);\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory\r\n this.precomputedObjects[id]={mem8: new Uint8Array(this.owner.memory!.buffer, start, length), width:width, height:height};\r\n }\r\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_CREATERADIALGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const radius0=this.owner.getDouble(ins+24);\r\n const x1=this.owner.getDouble(ins+32);\r\n const y1=this.owner.getDouble(ins+40);\r\n const radius1=this.owner.getDouble(ins+48);\r\n const id= this.owner.getLong(ins+56);\r\n\r\n let gradient=this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_CREATELINEARGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const x1=this.owner.getDouble(ins+24);\r\n const y1=this.owner.getDouble(ins+32);\r\n const id= this.owner.getLong(ins+40);\r\n \r\n let gradient=this.ctx.createLinearGradient(x0, y0, x1, y1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETCOLORSTOP:\r\n {\r\n const id = this.owner.getLong(ins+8);\r\n const pos=this.owner.getLong(ins+12);\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+16));\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n gradient.addColorStop(pos, cssColor);\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n this.ctx.fillStyle=gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_RELEASEID:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (this.precomputedObjects[id])\r\n delete this.precomputedObjects[id];\r\n else\r\n console.log(\"warning: D2D_RELEASEID with undefined ID \",id);\r\n }\r\n break\r\n\r\n \r\n\r\n case D2DType.D2D_PUTIMAGEDATA:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n const dx=this.owner.getLong(ins+12);\r\n const dy=this.owner.getLong(ins+16);\r\n const dirtyX=this.owner.getLong(ins+20);\r\n const dirtyY=this.owner.getLong(ins+24);\r\n const dirtyWidth=this.owner.getLong(ins+28);\r\n const dirtyHeight=this.owner.getLong(ins+32);\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \"+id);\r\n\r\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\r\n\r\n let imgData:ImageData;\r\n if (this.owner.isWasmModule) {\r\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\r\n imgData=this.precomputedObjects[id] as ImageData;\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\r\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\r\n const z = this.precomputedObjects[id] as {mem8:Uint8Array, width:number, height:number}; // Uint8Array\r\n const ca=Uint8ClampedArray.from(z.mem8); // shallow copy\r\n imgData=new ImageData(ca, z.width, z.height);\r\n }\r\n \r\n if (dirtyWidth==0 && dirtyHeight==0) {\r\n this.ctx.putImageData(imgData, dx, dy);\r\n }\r\n else {\r\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\r\n }\r\n }\r\n break;\r\n\r\n default:\r\n throw new Error (\"unimplemented or unknown Sequence Type in drawSeq: \"+type);\r\n }\r\n next=this.owner.getLong(ins); /* hdr->next */\r\n if (next==0) {\r\n if (ins!=lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\r\n break;\r\n }\r\n ins=next;\r\n }\r\n\r\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\r\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\r\n }\r\n}\r\n\r\nexport class twrCanvasProxy implements ICanvas {\r\n canvasKeys: twrSharedCircularBuffer;\r\n drawCompleteSignal:twrSignal;\r\n props: ICanvasProps;\r\n owner: twrWasmModuleBase;\r\n\r\n constructor(params:TCanvasProxyParams, owner:twrWasmModuleBase) {\r\n const [props, signalBuffer, canvasKeysBuffer] = params;\r\n this.drawCompleteSignal = new twrSignal(signalBuffer);\r\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\r\n this.props=props;\r\n this.owner=owner;\r\n\r\n //console.log(\"Create New twrCanvasProxy: \",this.props)\r\n\r\n }\r\n\r\n charIn() { \r\n //ctx.commit(); not avail in chrome\r\n \r\n //postMessage([\"debug\", 'x']);\r\n \r\n return this.canvasKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.canvasKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n getProp(pn:number): number {\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n \r\n drawSeq(ds:number) {\r\n this.drawCompleteSignal.reset();\r\n postMessage([\"drawseq\", [ds]]);\r\n this.drawCompleteSignal.wait();\r\n }\r\n}\r\n","//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst RDIDX = 256;\nconst WRIDX = 257;\nconst LEN = 256;\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\n// the first 256 array entries are the circular buffer\n// the next two are used for the read and write index\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\nexport class twrSharedCircularBuffer {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(258 * 4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[RDIDX] = 0;\n this.buf[WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[WRIDX];\n this.buf[i] = n;\n i++;\n if (i == LEN)\n i = 0;\n this.buf[WRIDX] = i;\n Atomics.notify(this.buf, WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[RDIDX] = i;\n return n;\n }\n else\n return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[RDIDX] == this.buf[WRIDX];\n }\n}\n//# sourceMappingURL=twrcircular.js.map","//\r\n// This class implements a circular buffer that the main javascript thread can write to, \r\n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\r\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \r\n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\r\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\r\n//\r\n\r\nconst RDIDX=256;\r\nconst WRIDX=257;\r\nconst LEN=256;\r\n\r\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\r\n// the first 256 array entries are the circular buffer\r\n// the next two are used for the read and write index\r\n\r\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\r\n\r\nexport class twrSharedCircularBuffer {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n \r\n\tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(258*4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[RDIDX]=0;\r\n this.buf[WRIDX]=0;\r\n\t}\r\n\r\n\twrite(n:number) {\r\n let i=this.buf[WRIDX];\r\n this.buf[i]=n;\r\n i++;\r\n if (i==LEN) i=0;\r\n this.buf[WRIDX]=i; \r\n Atomics.notify(this.buf, WRIDX); \r\n\t}\r\n\r\n\tread():number {\r\n if (!this.isEmpty()) {\r\n let i=this.buf[RDIDX];\r\n let n=this.buf[i];\r\n i++;\r\n this.buf[RDIDX]=i;\r\n return n;\r\n }\r\n\t\telse\r\n return -1;\r\n\t}\r\n\r\n readWait():number {\r\n if (this.isEmpty()) {\r\n const rdptr=this.buf[RDIDX];\r\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\r\n Atomics.wait(this.buf, WRIDX, rdptr);\r\n }\r\n return this.read();\r\n\t}\r\n\r\n isEmpty():boolean {\r\n return this.buf[RDIDX]==this.buf[WRIDX];\r\n }\r\n}\r\n","//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar twrSignalState;\n(function (twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})(twrSignalState || (twrSignalState = {}));\n;\nexport class twrSignal {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window valid\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == twrSignalState.WAITING) {\n //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\n //console.log(\"released...\");\n }\n }\n isSignaled() {\n return this.buf[0] == twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = twrSignalState.WAITING;\n }\n}\n//# sourceMappingURL=twrsignal.js.map","//\r\n// This class implements a simple signal/wait mechanism\r\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\r\n//\r\n\r\nenum twrSignalState {\r\n WAITING=0,\r\n SIGNALED=1\r\n};\r\n\r\nexport class twrSignal {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n\r\n \tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window valid\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) \r\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[0]=twrSignalState.WAITING;\r\n\t}\r\n\r\n\tsignal() {\r\n this.buf[0]=twrSignalState.SIGNALED; \r\n //console.log(\"about to signal\");\r\n Atomics.notify(this.buf, 0); \r\n\t}\r\n\r\n wait() {\r\n if (this.buf[0]==twrSignalState.WAITING) {\r\n //console.log(\"waiting...\");\r\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\r\n //console.log(\"released...\");\r\n\r\n }\r\n\t}\r\n isSignaled():boolean {\r\n return this.buf[0]==twrSignalState.SIGNALED;\r\n }\r\n\r\n reset() {\r\n this.buf[0]=twrSignalState.WAITING;\r\n }\r\n}\r\n","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nexport class twrDiv {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase) {\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\n this.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n if (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.divKeys.sharedArray];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */\n charOut(ch) {\n if (!this.div)\n return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n }\n switch (ch) {\n case 10: // newline\n case 13: // return\n if (ch == 10 && this.lastChar == 13)\n break; // detect CR LF and treat as single new line\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8: // backspace\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n case 0xE: // cursor on\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF: // cursor off\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for (let i = 0; i < str.length; i++)\n this.charOut(str.charCodeAt(i));\n }\n}\nexport class twrDivProxy {\n divKeys;\n constructor(params) {\n const [divKeysBuffer] = params;\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n charOut(ch) {\n postMessage([\"divout\", ch]);\n }\n}\n//# sourceMappingURL=twrdiv.js.map","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\r\nimport { IModParams } from \"./twrmodbase.js\";\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\";\r\n\r\nexport type TDivProxyParams = [SharedArrayBuffer];\r\n\r\nexport interface IDiv {\r\n charOut: (ds:number)=>void,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TDivProxyParams,\r\n }\r\n\r\n\r\nexport class twrDiv implements IDiv {\r\n\tdiv:HTMLDivElement|null|undefined;\r\n\tdivKeys?:twrSharedCircularBuffer;\r\n\tCURSOR=String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\r\n\tcursorOn:boolean=false;\r\n\tlastChar:number=0;\r\n\textraBR:boolean=false;\r\n\towner:twrWasmModuleBase;\r\n\r\n constructor(element:HTMLDivElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n\t\tthis.div=element;\r\n\t\tthis.owner=modbase;\r\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\r\n\t\t\tthis.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n\t\t}\r\n\r\n\t\tif (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\r\n\t\t\tthis.div.style.backgroundColor = modParams.backcolor;\r\n\t\t\tthis.div.style.color = modParams.forecolor;\r\n\t\t\tthis.div.style.font=modParams.fontsize.toString()+\"px arial\"\r\n\t\t}\r\n }\r\n\r\n\tisValid() {\r\n\t\treturn !!this.div;\r\n\t}\r\n\r\n getProxyParams() : TDivProxyParams {\r\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [ this.divKeys.sharedArray];\r\n }\r\n\r\n\r\n/* \r\n * add character to div. Supports the following control codes:\r\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\r\n * 0xE cursor on \r\n * 0x8 backspace\r\n * 0xF cursor off \r\n*/\r\n\tcharOut(ch:number) {\r\n\r\n\t\tif (!this.div) return;\r\n\r\n\t\t//console.log(\"div::charout: \", ch);\r\n\r\n\t\tif (this.extraBR) {\r\n\t\t\tthis.extraBR=false;\r\n\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -4);\r\n\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t}\r\n\r\n\t\tswitch (ch) {\r\n\t\t\tcase 10: // newline\r\n\t\t\tcase 13: // return\r\n\t\t\t\tif (ch==10 && this.lastChar==13) break; // detect CR LF and treat as single new line\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\r\n\t\t\t\tthis.extraBR=true;\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\t//element.scrollIntoView();\r\n\t\t\t\t//element.scrollTop = element.scrollHeight;\r\n\t\t\t\tlet p = this.div.getBoundingClientRect();\r\n\t\t\t\twindow.scrollTo(0, p.height+100);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 8: // backspace\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xE: // cursor on\r\n\t\t\t\tif (!this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=true;\r\n\t\t\t\t\tthis.div.innerHTML += this.CURSOR;\r\n\t\t\t\t\tthis.div.focus();\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xF: // cursor off\r\n\t\t\t\tif (this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=false;\r\n\t\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += String.fromCharCode(ch);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\tthis.lastChar=ch;\r\n\t}\r\n\r\n\tstringOut(str:string) {\r\n\t\tfor (let i=0; i < str.length; i++)\r\n\t\t\tthis.charOut(str.charCodeAt(i));\r\n\t}\r\n}\r\n\r\n\r\nexport class twrDivProxy implements IDiv {\r\n divKeys: twrSharedCircularBuffer;\r\n\r\n constructor(params:TDivProxyParams) {\r\n const [divKeysBuffer] = params;\r\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\r\n }\r\n\r\n charIn() { \r\n return this.divKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.divKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n\tcharOut(ch:number) {\r\n\t\tpostMessage([\"divout\", ch]);\r\n\t}\r\n}\r\n\r\n","let logline = \"\";\nexport function twrDebugLogImpl(char) {\n if (char == 10 || char == 3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\n console.log(logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n logline = \"\";\n }\n else {\n logline = logline + String.fromCharCode(char);\n if (logline.length >= 200) {\n console.log(logline);\n logline = \"\";\n }\n }\n}\n// ************************************************************************\n// debugLog doesn't currently wait for the message to log, it returns immediately.\n// I could move this to be in the twrWaitingCalls class\nexport function twrDebugLogProxy(ch) {\n postMessage([\"debug\", ch]);\n}\n//# sourceMappingURL=twrdebug.js.map","\r\nlet logline=\"\";\r\nexport function twrDebugLogImpl(char:number) {\r\n\tif (char==10 || char==3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\r\n\t\tconsole.log(logline);\t// ideally without a linefeed, but there is no way to not have a LF with console.log API.\r\n\t\tlogline=\"\";\r\n\t}\r\n\telse {\r\n\t\tlogline=logline+String.fromCharCode(char);\r\n\t\tif (logline.length>=200) {\r\n\t\t\tconsole.log(logline);\r\n\t\t\tlogline=\"\";\r\n\t\t}\r\n\t}\r\n}\r\n\r\n// ************************************************************************\r\n// debugLog doesn't currently wait for the message to log, it returns immediately.\r\n// I could move this to be in the twrWaitingCalls class\r\nexport function twrDebugLogProxy(ch:number) {\r\n postMessage([\"debug\", ch]);\r\n}\r\n\r\n","import { twrFloatUtil } from \"./twrfloat.js\";\n/*********************************************************************/\n/*********************************************************************/\n/*********************************************************************/\nexport class twrWasmModuleBase {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\n floatUtil;\n constructor(isWasmModule = false) {\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new twrFloatUtil(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/\n /*********************************************************************/\n async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n }\n catch (err) {\n console.log('loadWasm() failed to fetch: ' + pathToLoad);\n throw err;\n }\n if (!response.ok)\n throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, { env: allimports });\n this.exports = instance.instance.exports;\n if (!this.exports)\n throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory)\n throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory)\n throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer)\n console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\"setmemory\", this.memory]);\n }\n if (this.isWasmModule) {\n // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (!(this.memory.buffer instanceof ArrayBuffer))\n console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size) => {\n return new Promise(resolve => {\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n }\n catch (err) {\n console.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch (this.modParams.stdio) {\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* executeC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */\n async executeC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.executeCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async executeCImpl(fname, cparams = []) {\n if (!this.exports)\n throw new Error(\"this.exports undefined\");\n if (!this.exports[fname])\n throw new Error(\"executeC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array))\n throw new Error(\"executeC: params must be array, first arg is function name\");\n if (params.length == 0)\n throw new Error(\"executeC: missing function name\");\n let cparams = [];\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n cparams[ci++] = p;\n break;\n case 'string':\n cparams[ci++] = await this.putString(p);\n break;\n case 'object':\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n }\n else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"executeC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n ci++;\n break;\n case 'string':\n this.executeCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n case 'object':\n if (p instanceof URL) {\n this.executeCImpl('twr_free', [cparams[ci]]);\n ci = ci + 2;\n break;\n }\n else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for (let j = 0; j < u8.length; j++)\n u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.executeCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n }\n else\n throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/\n /*********************************************************************/\n // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for (i = 0; i < sin.length && i < buffer_size - 1; i++)\n this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for (let i = 0; i < u8a.length; i++)\n this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === 'object' && fnin instanceof URL))\n throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [dest, src.length];\n }\n catch (err) {\n console.log('fetchAndPutURL Error. URL: ' + fnin + '\\n' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while (this.mem8[strIndex + i] && (len === undefined ? true : i < len) && (strIndex + i) < this.mem8.length) {\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0)\n throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array((this.mem8.slice(dataptr, dataptr + size)).buffer);\n return u32;\n }\n}\n//# sourceMappingURL=twrmodbase.js.map","\r\nimport {TCanvasProxyParams} from \"./twrcanvas.js\"\r\nimport {TDivProxyParams} from \"./twrdiv.js\";\r\nimport {TWaitingCallsProxyParams} from \"./twrwaitingcalls.js\"\r\nimport {twrDebugLogImpl} from \"./twrdebug.js\";\r\nimport {twrFloatUtil} from \"./twrfloat.js\";\r\n\r\n\r\nexport type TStdioVals=\"div\"|\"canvas\"|\"null\"|\"debug\";\r\n\r\nexport interface IModOpts {\r\n\tstdio?:TStdioVals, \r\n\twindim?:[number, number],\r\n\tforecolor?:string,\r\n\tbackcolor?:string,\r\n\tfontsize?:number,\r\n\tisd2dcanvas?:boolean,\r\n\timports?:{},\r\n}\r\n\r\nexport interface IModParams {\r\n\tstdio:TStdioVals, \r\n\twindim:[number, number],\r\n\tforecolor:string,\r\n\tbackcolor:string,\r\n\tfontsize:number,\r\n\tstyleIsDefault: boolean\r\n\tisd2dcanvas:boolean,\r\n\timports:{[index:string]:Function},\r\n}\r\n\r\nexport interface IModInWorkerParams {\r\n\tdivProxyParams:TDivProxyParams,\r\n\tcanvasProxyParams:TCanvasProxyParams,\r\n\twaitingCallsProxyParams:TWaitingCallsProxyParams,\r\n}\r\n\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n\r\nexport abstract class twrWasmModuleBase {\r\n\tmemory?:WebAssembly.Memory;\r\n\tmem8:Uint8Array;\r\n\tmem32:Uint32Array;\r\n\tmemD:Float64Array;\r\n\tabstract malloc:(size:number)=>Promise;\r\n\tabstract modParams:IModParams;\r\n\texports?:WebAssembly.Exports;\r\n\tisWorker=false;\r\n\tisWasmModule:boolean; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\r\n\tfloatUtil:twrFloatUtil;\r\n\r\n\tconstructor(isWasmModule=false) {\r\n\t\tthis.isWasmModule=isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\r\n\t\tthis.mem8=new Uint8Array(); \t// avoid type errors\r\n\t\tthis.mem32=new Uint32Array(); // avoid type errors\r\n\t\tthis.memD=new Float64Array(); // avoid type errors\r\n\t\tthis.floatUtil=new twrFloatUtil(this);\r\n\t\t//console.log(\"size of mem8 after constructor\",this.mem8.length);\r\n\t}\r\n\r\n\t/*********************************************************************/\r\n\t/*********************************************************************/\r\n\r\n\tasync loadWasm(pathToLoad:string) {\r\n\t\t//console.log(\"fileToLoad\",fileToLoad)\r\n\r\n\t\tlet response;\r\n\t\ttry {\r\n\t\t\tresponse=await fetch(pathToLoad);\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('loadWasm() failed to fetch: '+pathToLoad);\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t\t\r\n\t\tif (!response.ok) throw new Error(\"fetch response error on file '\"+pathToLoad+\"'\\n\"+response.statusText);\r\n\r\n\t\ttry {\r\n\t\t\tlet wasmBytes = await response.arrayBuffer();\r\n\r\n\t\t\tlet allimports:WebAssembly.ModuleImports = { \r\n\t\t\t\t...this.modParams.imports\r\n\t\t\t};\r\n\r\n\t\t\tlet instance = await WebAssembly.instantiate(wasmBytes, {env: allimports});\r\n\r\n\t\t\tthis.exports=instance.instance.exports;\r\n\t\t\tif (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\r\n\r\n\t\t\tif (this.memory) throw new Error (\"unexpected error -- this.memory already set\");\r\n\t\t\tthis.memory=this.exports.memory as WebAssembly.Memory;\r\n\t\t\tif (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\r\n\t\t\tthis.mem8 = new Uint8Array(this.memory.buffer);\r\n\t\t\tthis.mem32 = new Uint32Array(this.memory.buffer);\r\n\t\t\tthis.memD = new Float64Array(this.memory.buffer);\r\n\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\tif (this.isWorker) {\r\n\t\t\t\tif (this.memory.buffer instanceof ArrayBuffer)\r\n\t\t\t\t\tconsole.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\r\n\t\t\t\t\r\n\t\t\t\tpostMessage([\"setmemory\",this.memory]);\r\n\t\t\t}\r\n\t\t\tif (this.isWasmModule) {\r\n\t\t\t\t// here if twrWasmModule, twrWasmModuleAsync overrides this function\r\n\t\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\t\tif (!(this.memory.buffer instanceof ArrayBuffer))\r\n\t\t\t\t\tconsole.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\r\n\t\t\t}\r\n\r\n\t\t\tthis.malloc=(size:number)=>{\r\n\t\t\t\treturn new Promise(resolve => {\r\n\t\t\t\t\tconst m=this.exports!.twr_malloc as (size:number)=>number;\r\n\t\t\t\t\tresolve(m(size));\r\n\t\t\t\t});\r\n\t\t };\r\n\r\n\t\t\tthis.init();\r\n\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t}\r\n\r\n\tprivate init() {\r\n\t\t//console.log(\"loadWasm.init() enter\")\r\n\t\t\tlet p:number;\r\n\t\t\tswitch (this.modParams.stdio) {\r\n\t\t\t\tcase \"debug\":\r\n\t\t\t\t\tp=0;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"div\":\r\n\t\t\t\t\tp=1;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"canvas\":\r\n\t\t\t\t\tp=2;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"null\":\r\n\t\t\t\t\tp=3;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tp=0; // debug\r\n\t\t\t}\r\n\r\n\t\t\tconst twrInit=this.exports!.twr_wasm_init as CallableFunction;\r\n\t\t\t//console.log(\"twrInit:\",twrInit)\r\n\t\t\ttwrInit(p, this.mem8.length);\r\n\t}\r\n\r\n\t/* executeC takes an array where:\r\n\t* the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\r\n\t* and the next entries are a variable number of parameters to pass to the C function, of type\r\n\t* number - converted to int32 or float64 as appropriate\r\n\t* string - converted to a an index (ptr) into a module Memory returned via stringToMem()\r\n\t* URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\r\n\t* Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\r\n */\r\n\r\n\tasync executeC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\t\tconst cparams=await this.preCallC(params);\r\n\t\tlet retval = this.executeCImpl(params[0], cparams);\r\n\t\tthis.postCallC(cparams, params);\r\n\t\treturn retval;\r\n\t}\r\n\r\n\tasync executeCImpl(fname:string, cparams:number[]=[]) {\r\n\t\tif (!this.exports) throw new Error(\"this.exports undefined\");\r\n\t\tif (!this.exports[fname]) throw new Error(\"executeC: function '\"+fname+\"' not in export table. Use --export wasm-ld flag.\");\r\n\r\n\t\tconst f = this.exports[fname] as CallableFunction;\r\n\t\tlet cr=f(...cparams);\r\n\r\n\t\treturn cr;\r\n\t}\r\n\r\n\t// convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\r\n\tasync preCallC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tif (!(params.constructor === Array)) throw new Error (\"executeC: params must be array, first arg is function name\");\r\n\t\tif (params.length==0) throw new Error(\"executeC: missing function name\");\r\n\r\n\t\tlet cparams:number[]=[];\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tcparams[ci++]=p;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tcparams[ci++]=await this.putString(p);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tconst r=await this.fetchAndPutURL(p);\r\n\t\t\t\t\t\tcparams[ci++]=r[0]; // mem index\r\n\t\t\t\t\t\tcparams[ci++]=r[1]; // len\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tconst r=await this.putArrayBuffer(p);\r\n\t\t\t\t\t\tcparams[ci++]=r; // mem index\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tthrow new Error (\"executeC: invalid object type passed in\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn cparams;\r\n\t}\r\n\r\n\t// free the mallocs; copy array buffer data from malloc back to arraybuffer\r\n\tasync postCallC(cparams:number[], params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tthis.executeCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t\t\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tthis.executeCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\t\tci=ci+2;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tlet u8=new Uint8Array(p);\r\n\t\t\t\t\t\tfor (let j=0; j= this.mem32.length) throw new Error(\"invalid index passed to getLong: \"+idx+\", this.mem32.length: \"+this.mem32.length);\r\n\t\tconst long:number = this.mem32[idx32];\r\n\t\treturn long;\r\n\t}\r\n\t\r\n\tsetLong(idx:number, value:number) {\r\n const idx32 = Math.floor(idx / 4);\r\n if (idx32 * 4 != idx)\r\n throw new Error(\"setLong passed non long aligned address\");\r\n if (idx32 < 0 || idx32 >= this.mem32.length)\r\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\r\n this.mem32[idx32]=value;\r\n }\r\n\r\n\tgetDouble(idx:number): number {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"getLong passed non Float64 aligned address\")\r\n\t\tconst long:number = this.memD[idx64];\r\n\t\treturn long;\r\n\t}\r\n\r\n\tsetDouble(idx:number, value:number) {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"setDouble passed non Float64 aligned address\")\r\n\t\tthis.memD[idx64]=value;\r\n\t}\r\n\r\n\tgetShort(idx:number): number {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getShort: \"+idx);\r\n\t\tconst short:number = this.mem8[idx]+this.mem8[idx+1]*256;\r\n\t\treturn short;\r\n\t}\r\n\r\n\t// get a string out of module memory\r\n\t// null terminated, up until max of (optional) len\r\n\tgetString(strIndex:number, len?:number): string {\r\n\t\tlet sout=\"\";\r\n\r\n\t\tlet i=0;\r\n\t\twhile (this.mem8[strIndex+i] && (len===undefined?true:i= this.mem8.length) throw new Error(\"invalid index passed to getU8: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU8\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU8\")\r\n\r\n\t\tconst u8=this.mem8.slice(dataptr, dataptr+size);\r\n\t\treturn u8;\r\n\t}\r\n\r\n\t// get a int32 array out of module memory when passed in index to [size, dataptr]\r\n\tgetU32Arr(idx:number): Uint32Array {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getU32: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU32\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU32\")\r\n\r\n\t\tif (size%4!=0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\r\n\r\n\t\tconst u32 = new Uint32Array( (this.mem8.slice(dataptr, dataptr+size)).buffer );\r\n\t\treturn u32;\r\n\t}\r\n}\r\n","export class twrFloatUtil {\n mod;\n constructor(mod) {\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\")\n return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\")\n return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll('D', 'e').replaceAll('d', 'e'));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n }\n else {\n let r = value.toString();\n if (r.length > max_precision)\n r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, // char *\n sizeInBytes, //size_t\n value, // double\n fracpart_numdigits, //int\n dec, // int *\n sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1)\n return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) { /* nan */\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (!Number.isFinite(value)) { /* infinity */\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n }\n else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split('.');\n if (intPart == \"0\")\n intPart = \"\";\n if (intPart.length > 0) { // has integer part\n decpos = intPart.length;\n digits = intPart + fracPart;\n }\n else { // only a fraction\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length)\n return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */\n }\n}\n//# sourceMappingURL=twrfloat.js.map","\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\"\r\n\r\nexport class twrFloatUtil {\r\n mod: twrWasmModuleBase;\r\n\r\n constructor(mod: twrWasmModuleBase) {\r\n this.mod=mod;\r\n }\r\n\r\n atod(strptr:number):number {\r\n const str=this.mod.getString(strptr);\r\n\r\n const upper=str.trimStart().toUpperCase();\r\n if (upper==\"INF\" || upper==\"+INF\")\r\n return Number.POSITIVE_INFINITY;\r\n else if (upper==\"-INF\")\r\n return Number.NEGATIVE_INFINITY\r\n else {\r\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\r\n const r=Number.parseFloat(str.replaceAll('D','e').replaceAll('d','e'));\r\n return r;\r\n }\r\n }\r\n\r\n dtoa(buffer:number, buffer_size:number, value:number, max_precision:number):void {\r\n if (max_precision==-1) {\r\n const r=value.toString();\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n else {\r\n let r=value.toString();\r\n if (r.length>max_precision)\r\n r=value.toPrecision(max_precision);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n }\r\n\r\n toFixed(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toFixed(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n toExponential(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toExponential(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\r\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\r\n // Negative exponents must be now smaller than 1e-99\r\n // fully-function C version also int he source, but this is the version enabled by default\r\n fcvtS(\r\n buffer:number, // char *\r\n sizeInBytes:number, //size_t\r\n value:number, // double\r\n fracpart_numdigits:number, //int\r\n dec:number, // int *\r\n sign:number // int *\r\n ):number {\r\n\r\n if (buffer==0 ||sign==0 || dec==0 || sizeInBytes<1) return 1;\r\n\r\n let digits:string;\r\n let decpos:number;\r\n let s=0; // default to positive\r\n\r\n\r\n if (Number.isNaN(value)) { /* nan */\r\n digits=\"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (!Number.isFinite(value)) { /* infinity */\r\n digits=\"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (value==0) { \r\n digits=\"000000000000000000000000000000000000\".slice(0,fracpart_numdigits);\r\n decpos=0;\r\n }\r\n \r\n else {\r\n\r\n if (value<0) {\r\n s=1; // negative\r\n value=Math.abs(value);\r\n }\r\n\r\n if (fracpart_numdigits>100 || value > 1e+21 || value < 1e-99) { \r\n this.mod.copyString(buffer, sizeInBytes, \"\");\r\n this.mod.mem32[dec]=0;\r\n return 1;\r\n }\r\n\r\n const roundValStr=value.toFixed(fracpart_numdigits);\r\n let [intPart=\"\", fracPart=\"\"] = roundValStr.split('.');\r\n if (intPart==\"0\") intPart=\"\";\r\n\r\n if (intPart.length>0) { // has integer part\r\n decpos=intPart.length;\r\n digits=intPart+fracPart;\r\n }\r\n else { // only a fraction\r\n digits=fracPart.replace(/^0+/,\"\"); // remove leading zeros\r\n decpos=digits.length-fracPart.length;\r\n }\r\n }\r\n\r\n if (sizeInBytes-1 < digits.length) return 1; \r\n this.mod.copyString(buffer, sizeInBytes, digits);\r\n this.mod.setLong(dec, decpos);\r\n this.mod.setLong(sign, s);\r\n\r\n return 0;\r\n\r\n /*\r\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\r\n\r\n let decpos=0;\r\n let digits:string;\r\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\r\n \r\n if (decpos>0) { // has integer part\r\n const intlen=Math.max(decpos, 0);\r\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\r\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\r\n }\r\n else { // only a fraction\r\n const intpart=Math.trunc(value);\r\n const fracpart=value-intpart;\r\n const prec=fracpart_numdigits- (-decpos);\r\n console.log(\"prec=\",prec);\r\n if (prec<1) {\r\n digits=\"\";\r\n }\r\n else {\r\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\");\r\n }\r\n }\r\n\r\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\r\n console.log('digits=',digits);\r\n console.log('dec=',decpos);\r\n console.log(\"sign=\",s);\r\n */\r\n\r\n\r\n }\r\n}","import { twrSignal } from \"./twrsignal.js\";\nimport { twrTimeImpl } from \"./twrdate.js\";\n// This class is used in the Main JS thread \nexport class twrWaitingCalls {\n callCompleteSignal;\n parameters;\n constructor() {\n this.callCompleteSignal = new twrSignal();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(() => {\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = twrTimeImpl();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [this.callCompleteSignal.sharedArray, this.parameters.buffer];\n }\n processMessage(msgType, data) {\n switch (msgType) {\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\n// This class is used in the worker thread \nexport class twrWaitingCallsProxy {\n callCompleteSignal;\n parameters;\n constructor(params) {\n this.callCompleteSignal = new twrSignal(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\"sleep\", [ms]]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\"time\"]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n//# sourceMappingURL=twrwaitingcalls.js.map","import { twrSignal } from \"./twrsignal.js\";\r\nimport {twrTimeImpl} from \"./twrdate.js\"\r\n\r\n// These classes are used to proxy a call across the worker thread - main thread boundary and wait for the result\r\n\r\nexport type TWaitingCallsProxyParams = [SharedArrayBuffer, SharedArrayBuffer]; // twrSignal, parameters \r\n\r\n// This class is used in the Main JS thread \r\nexport class twrWaitingCalls {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor() {\r\n\t\tthis.callCompleteSignal=new twrSignal();\r\n\t\tthis.parameters=new Uint32Array(new SharedArrayBuffer(4));\r\n\t}\r\n\r\n\tprivate startSleep(ms:number) {\r\n\r\n\t\tsetTimeout(()=>{\r\n\t\t\tthis.callCompleteSignal.signal();\r\n\t\t}, ms);\r\n\t\t\r\n\t}\r\n\r\n\tprivate time() {\r\n\t\tconst ms=twrTimeImpl();\r\n\t\tthis.parameters[0]=ms;\r\n\t\tthis.callCompleteSignal.signal();\r\n\t}\r\n\r\n\tgetProxyParams():TWaitingCallsProxyParams {\r\n\t\treturn [this.callCompleteSignal.sharedArray, this.parameters.buffer as SharedArrayBuffer];\t\r\n\t}\r\n\r\n\tprocessMessage(msgType:string, data:any[]):boolean {\r\n\t\tswitch (msgType) {\r\n\t\t\tcase \"sleep\":\r\n\t\t\t\tconst [ms] = data;\r\n\t\t\t\tthis.startSleep(ms);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"time\":\r\n\t\t\t\tthis.time();\r\n\t\t\t\tbreak;\r\n\t\t\t\r\n\t\t\tdefault:\r\n\t\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\treturn true;\r\n\t}\r\n\r\n}\r\n\r\n// This class is used in the worker thread \r\nexport class twrWaitingCallsProxy {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor(params:TWaitingCallsProxyParams) {\r\n\t\tthis.callCompleteSignal=new twrSignal(params[0]);\r\n\t\tthis.parameters=new Uint32Array(params[1]);\r\n\t}\r\n\r\n\tsleep(ms:number) {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"sleep\", [ms]]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t}\r\n\r\n\ttime() {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"time\"]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t\treturn this.parameters[0];\r\n\t}\r\n\r\n}\r\n","export function twrTimeImpl() {\n return Date.now();\n}\n//# sourceMappingURL=twrdate.js.map","\r\nexport function twrTimeImpl() {\r\n\r\n return Date.now();\r\n\r\n}"],"names":["$b93f1fdf40141def$var$twrSignalState","$c4741cac81d14197$var$D2DType","twrSignalState","D2DType","$3e39efa823870787$var$mod","$892fccfc812d5e20$export$a01cca24f011573a","sharedArray","buf","constructor","sa","window","crossOriginIsolated","location","protocol","Error","SharedArrayBuffer","Int32Array","write","n","i","Atomics","notify","read","isEmpty","readWait","rdptr","wait","$b93f1fdf40141def$export$e37a7b7b851b97f3","WAITING","signal","SIGNALED","isSignaled","reset","$c4741cac81d14197$export$c779b2cd00544976","canvasKeys","drawCompleteSignal","props","owner","params","signalBuffer","canvasKeysBuffer","charIn","inkey","getProp","pn","propName","getString","drawSeq","ds","postMessage","$8963973702ae5462$export$b377f0bbf2c7581e","divKeys","divKeysBuffer","charOut","ch","$8ac0b786da854328$export$485af4d0039b3389","$e72303a1db04bdfa$export$918ffb7e046a537b","mod","atod","strptr","str","upper","trimStart","toUpperCase","Number","POSITIVE_INFINITY","NEGATIVE_INFINITY","parseFloat","replaceAll","dtoa","buffer","buffer_size","value","max_precision","r","toString","copyString","length","toPrecision","toFixed","decdigits","toExponential","fcvtS","sizeInBytes","fracpart_numdigits","dec","sign","digits","decpos","s","isNaN","slice","isFinite","Math","abs","mem32","intPart","fracPart","roundValStr","split","replace","setLong","$ece7fa3ed770778a$export$c83a0a3bffe07399","memory","mem8","memD","exports","isWorker","isWasmModule","floatUtil","Uint8Array","Uint32Array","Float64Array","loadWasm","pathToLoad","response","fetch","err","console","log","ok","statusText","wasmBytes","arrayBuffer","allimports","modParams","imports","instance","WebAssembly","instantiate","env","ArrayBuffer","malloc","size","Promise","resolve","m","twr_malloc","init","stack","p","stdio","twrInit","twr_wasm_init","executeC","cparams","preCallC","retval","executeCImpl","postCallC","fname","f","Array","ci","putString","URL","fetchAndPutURL","putArrayBuffer","u8","j","sin","charCodeAt","strIndex","putU8","u8a","dest","ab","fnin","src","getLong","idx","idx32","floor","getDouble","idx64","setDouble","getShort","len","sout","undefined","String","fromCharCode","getU8Arr","rv","dataptr","getU32Arr","$aff9c2c494d23fe3$export$78d2a4633fe89379","callCompleteSignal","parameters","sleep","ms","time","onmessage","e","data","$3e39efa823870787$var$twrWasmModuleInWorker","modWorkerParams","urlToLoad","then","catch","ex","rc","modInWorkerParams","canvasProxy","canvasProxyParams","divProxy","divProxyParams","waitingCallsProxy","waitingCallsProxyParams","twrDebugLog","twrSleep","bind","twrTime","twrDivCharOut","twrDivCharIn","twrCanvasCharIn","twrCanvasInkey","twrCanvasGetProp","twrCanvasDrawSeq","twrSin","twrCos","cos","twrTan","tan","twrFAbs","twrACos","acos","twrASin","asin","twrATan","atan","twrExp","exp","twrFloor","twrCeil","ceil","twrFMod","x","y","twrLog","twrPow","pow","twrSqrt","sqrt","twrTrunc","trunc","twrDtoa","twrToFixed","twrToExponential","twrAtod","twrFcvtS"],"version":3,"file":"twrmodworker.2165e649.js.map"} \ No newline at end of file +{"mappings":"A,C,SQKK,EJgBA,EIhBA,EJgBA,MFZD,CISE,OAAO,EACZ,WAA8B,AAC9B,CAAA,GAAe,AAEf,aAAa,CAAqB,CAAlC,CACO,GAAI,AAAkB,aAAlB,OAAO,QACH,CAAC,qBAAuB,AAA+B,UAA7B,OAAO,QAAQ,CAAC,QAAQ,CAAe,MAAM,AA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B,QAAS,KAAK,IAAI,CAClB,SAAU,KAAK,KAAK,CAEX,QAAS,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EACzD,WAAY,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EACtD,iBAAkB,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAClE,QAAS,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAChD,SAAU,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAE5C,CACN,CACF,C,C","sources":["","../../lib-js/twrmodworker.js","../../source/twr-wasm-ts/twrmodworker.ts","../../lib-js/twrcanvas.js","../../source/twr-wasm-ts/twrcanvas.ts","../../lib-js/twrcircular.js","../../source/twr-wasm-ts/twrcircular.ts","../../lib-js/twrsignal.js","../../source/twr-wasm-ts/twrsignal.ts","../../lib-js/twrdiv.js","../../source/twr-wasm-ts/twrdiv.ts","../../lib-js/twrdebug.js","../../source/twr-wasm-ts/twrdebug.ts","../../lib-js/twrmodbase.js","../../source/twr-wasm-ts/twrmodbase.ts","../../lib-js/twrfloat.js","../../source/twr-wasm-ts/twrfloat.ts","../../lib-js/twrwaitingcalls.js","../../source/twr-wasm-ts/twrwaitingcalls.ts","../../lib-js/twrdate.js","../../source/twr-wasm-ts/twrdate.ts"],"sourcesContent":["(() => {\nvar $3e39efa823870787$exports = {};\n// this script is the WebWorker thead used by class twrWasmAsyncModule\n//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst $892fccfc812d5e20$var$RDIDX = 256;\nconst $892fccfc812d5e20$var$WRIDX = 257;\nconst $892fccfc812d5e20$var$LEN = 256;\nclass $892fccfc812d5e20$export$a01cca24f011573a {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(1032);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[$892fccfc812d5e20$var$RDIDX] = 0;\n this.buf[$892fccfc812d5e20$var$WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[$892fccfc812d5e20$var$WRIDX];\n this.buf[i] = n;\n i++;\n if (i == $892fccfc812d5e20$var$LEN) i = 0;\n this.buf[$892fccfc812d5e20$var$WRIDX] = i;\n Atomics.notify(this.buf, $892fccfc812d5e20$var$WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[$892fccfc812d5e20$var$RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[$892fccfc812d5e20$var$RDIDX] = i;\n return n;\n } else return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[$892fccfc812d5e20$var$RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, $892fccfc812d5e20$var$WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[$892fccfc812d5e20$var$RDIDX] == this.buf[$892fccfc812d5e20$var$WRIDX];\n }\n}\n\n\n//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar $b93f1fdf40141def$var$twrSignalState;\n(function(twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})($b93f1fdf40141def$var$twrSignalState || ($b93f1fdf40141def$var$twrSignalState = {}));\nclass $b93f1fdf40141def$export$e37a7b7b851b97f3 {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == $b93f1fdf40141def$var$twrSignalState.WAITING) //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, $b93f1fdf40141def$var$twrSignalState.WAITING);\n }\n isSignaled() {\n return this.buf[0] == $b93f1fdf40141def$var$twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.WAITING;\n }\n}\n\n\nvar $c4741cac81d14197$var$D2DType;\n(function(D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})($c4741cac81d14197$var$D2DType || ($c4741cac81d14197$var$D2DType = {}));\nclass $c4741cac81d14197$export$2f298dd69cef3c34 {\n ctx;\n props = {\n charWidth: 0,\n charHeight: 0,\n foreColor: 0,\n backColor: 0,\n widthInChars: 0,\n heightInChars: 0,\n canvasHeight: 0,\n canvasWidth: 0\n };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase){\n const { forecolor: forecolor, backcolor: backcolor, fontsize: fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)();\n this.canvasKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.props,\n this.cmdCompleteSignal.sharedArray,\n this.canvasKeys.sharedArray\n ];\n }\n getProp(pn) {\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */ drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx) return;\n let ins = this.owner.getLong(ds); /* ds->start */ \n const lastins = this.owner.getLong(ds + 4); /* ds->last */ \n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while(true){\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */ \n switch(type){\n case $c4741cac81d14197$var$D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_BEGINPATH:\n this.ctx.beginPath();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILL:\n this.ctx.fill();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SAVE:\n this.ctx.save();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_RESTORE:\n this.ctx.restore();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_STROKE:\n this.ctx.stroke();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = this.owner.getLong(ins + 48) != 0;\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n } else this.precomputedObjects[id] = {\n mem8: new Uint8Array(this.owner.memory.buffer, start, length),\n width: width,\n height: height\n };\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id]) delete this.precomputedObjects[id];\n else console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n else {\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) this.ctx.putImageData(imgData, dx, dy);\n else this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */ \n if (next == 0) {\n if (ins != lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nclass $c4741cac81d14197$export$c779b2cd00544976 {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner){\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)(signalBuffer);\n this.canvasKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\n \"drawseq\",\n [\n ds\n ]\n ]);\n this.drawCompleteSignal.wait();\n }\n}\n\n\n\nclass $8963973702ae5462$export$dd376bb3f10f6896 {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611);\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase){\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) this.divKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(); // tsconfig, lib must be set to 2017 or higher\n if (this.div && !modParams.styleIsDefault) {\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.divKeys.sharedArray\n ];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */ charOut(ch) {\n if (!this.div) return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n }\n switch(ch){\n case 10:\n case 13:\n if (ch == 10 && this.lastChar == 13) break; // detect CR LF and treat as single new line\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n case 0xE:\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF:\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for(let i = 0; i < str.length; i++)this.charOut(str.charCodeAt(i));\n }\n}\nclass $8963973702ae5462$export$b377f0bbf2c7581e {\n divKeys;\n constructor(params){\n const [divKeysBuffer] = params;\n this.divKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n charOut(ch) {\n postMessage([\n \"divout\",\n ch\n ]);\n }\n}\n\n\nlet $8ac0b786da854328$var$logline = \"\";\nfunction $8ac0b786da854328$export$16b4216ec014493d(char) {\n if (char == 10 || char == 3) {\n console.log($8ac0b786da854328$var$logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n $8ac0b786da854328$var$logline = \"\";\n } else {\n $8ac0b786da854328$var$logline = $8ac0b786da854328$var$logline + String.fromCharCode(char);\n if ($8ac0b786da854328$var$logline.length >= 200) {\n console.log($8ac0b786da854328$var$logline);\n $8ac0b786da854328$var$logline = \"\";\n }\n }\n}\nfunction $8ac0b786da854328$export$485af4d0039b3389(ch) {\n postMessage([\n \"debug\",\n ch\n ]);\n}\n\n\nclass $e72303a1db04bdfa$export$918ffb7e046a537b {\n mod;\n constructor(mod){\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\") return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\") return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll(\"D\", \"e\").replaceAll(\"d\", \"e\"));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n } else {\n let r = value.toString();\n if (r.length > max_precision) r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, sizeInBytes, value, fracpart_numdigits, dec, sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1) return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) {\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (!Number.isFinite(value)) {\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n } else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split(\".\");\n if (intPart == \"0\") intPart = \"\";\n if (intPart.length > 0) {\n decpos = intPart.length;\n digits = intPart + fracPart;\n } else {\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length) return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */ }\n}\n\n\nclass $ece7fa3ed770778a$export$c83a0a3bffe07399 {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule;\n floatUtil;\n constructor(isWasmModule = false){\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new (0, $e72303a1db04bdfa$export$918ffb7e046a537b)(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/ /*********************************************************************/ async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n } catch (err) {\n console.log(\"loadWasm() failed to fetch: \" + pathToLoad);\n throw err;\n }\n if (!response.ok) throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, {\n env: allimports\n });\n this.exports = instance.instance.exports;\n if (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory) throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer) console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\n \"setmemory\",\n this.memory\n ]);\n }\n if (this.isWasmModule) // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n {\n if (!(this.memory.buffer instanceof ArrayBuffer)) console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size)=>{\n return new Promise((resolve)=>{\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n } catch (err) {\n console.log(\"WASM instantiate error: \" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch(this.modParams.stdio){\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* callC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */ async callC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.callCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async callCImpl(fname, cparams = []) {\n if (!this.exports) throw new Error(\"this.exports undefined\");\n if (!this.exports[fname]) throw new Error(\"callC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array)) throw new Error(\"callC: params must be array, first arg is function name\");\n if (params.length == 0) throw new Error(\"callC: missing function name\");\n let cparams = [];\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n cparams[ci++] = p;\n break;\n case \"string\":\n cparams[ci++] = await this.putString(p);\n break;\n case \"object\":\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n } else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"callC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n ci++;\n break;\n case \"string\":\n this.callCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n case \"object\":\n if (p instanceof URL) {\n this.callCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci = ci + 2;\n break;\n } else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for(let j = 0; j < u8.length; j++)u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.callCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n } else throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/ /*********************************************************************/ // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for(i = 0; i < sin.length && i < buffer_size - 1; i++)this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for(let i = 0; i < u8a.length; i++)this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === \"object\" && fnin instanceof URL)) throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [\n dest,\n src.length\n ];\n } catch (err) {\n console.log(\"fetchAndPutURL Error. URL: \" + fnin + \"\\n\" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while(this.mem8[strIndex + i] && (len === undefined ? true : i < len) && strIndex + i < this.mem8.length){\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array(this.mem8.slice(dataptr, dataptr + size).buffer);\n return u32;\n }\n}\n\n\n\nfunction $4af5689abbc8d01b$export$78724cdcf7ebea1d() {\n return Date.now();\n}\n\n\nclass $aff9c2c494d23fe3$export$9e37856d1928d388 {\n callCompleteSignal;\n parameters;\n constructor(){\n this.callCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(()=>{\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = (0, $4af5689abbc8d01b$export$78724cdcf7ebea1d)();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [\n this.callCompleteSignal.sharedArray,\n this.parameters.buffer\n ];\n }\n processMessage(msgType, data) {\n switch(msgType){\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\nclass $aff9c2c494d23fe3$export$78d2a4633fe89379 {\n callCompleteSignal;\n parameters;\n constructor(params){\n this.callCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\n \"sleep\",\n [\n ms\n ]\n ]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\n \"time\"\n ]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n\n\nlet $3e39efa823870787$var$mod;\nonmessage = function(e) {\n //console.log('twrworker.js: message received from main script: '+e.data);\n if (e.data[0] == \"startup\") {\n const params = e.data[1];\n //console.log(\"Worker startup params:\",params);\n $3e39efa823870787$var$mod = new $3e39efa823870787$var$twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\n $3e39efa823870787$var$mod.loadWasm(params.urlToLoad).then(()=>{\n postMessage([\n \"startupOkay\"\n ]);\n }).catch((ex)=>{\n console.log(\".catch: \", ex);\n postMessage([\n \"startupFail\",\n ex\n ]);\n });\n } else if (e.data[0] == \"callC\") $3e39efa823870787$var$mod.callCImpl(e.data[1], e.data[2]).then((rc)=>{\n postMessage([\n \"callCOkay\",\n rc\n ]);\n }).catch((e)=>{\n console.log(\"exception in callC twrworker.js\\n\");\n console.log(e);\n postMessage([\n \"callCFail\",\n e\n ]);\n });\n else console.log(\"twrworker.js: unknown message: \" + e);\n};\n// ************************************************************************\nclass $3e39efa823870787$var$twrWasmModuleInWorker extends (0, $ece7fa3ed770778a$export$c83a0a3bffe07399) {\n malloc;\n modParams;\n constructor(modParams, modInWorkerParams){\n super();\n this.isWorker = true;\n this.malloc = (size)=>{\n throw new Error(\"error - un-init malloc called\");\n };\n this.modParams = modParams;\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\n const canvasProxy = new (0, $c4741cac81d14197$export$c779b2cd00544976)(modInWorkerParams.canvasProxyParams, this);\n const divProxy = new (0, $8963973702ae5462$export$b377f0bbf2c7581e)(modInWorkerParams.divProxyParams);\n const waitingCallsProxy = new (0, $aff9c2c494d23fe3$export$78d2a4633fe89379)(modInWorkerParams.waitingCallsProxyParams);\n this.modParams.imports = {\n twrDebugLog: (0, $8ac0b786da854328$export$485af4d0039b3389),\n twrSleep: waitingCallsProxy.sleep.bind(waitingCallsProxy),\n twrTime: waitingCallsProxy.time.bind(waitingCallsProxy),\n twrDivCharOut: divProxy.charOut.bind(divProxy),\n twrDivCharIn: divProxy.charIn.bind(divProxy),\n twrCanvasCharIn: canvasProxy.charIn.bind(canvasProxy),\n twrCanvasInkey: canvasProxy.inkey.bind(canvasProxy),\n twrCanvasGetProp: canvasProxy.getProp.bind(canvasProxy),\n twrCanvasDrawSeq: canvasProxy.drawSeq.bind(canvasProxy),\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function(x, y) {\n return x % y;\n },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n}\n\n})();\n//# sourceMappingURL=twrmodworker.2165e649.js.map\n","// this script is the WebWorker thead used by class twrWasmAsyncModule\nimport { twrCanvasProxy } from \"./twrcanvas.js\";\nimport { twrDivProxy } from \"./twrdiv.js\";\nimport { twrDebugLogProxy } from \"./twrdebug.js\";\nimport { twrWasmModuleBase } from \"./twrmodbase.js\";\nimport { twrWaitingCallsProxy } from \"./twrwaitingcalls.js\";\nlet mod;\nonmessage = function (e) {\n //console.log('twrworker.js: message received from main script: '+e.data);\n if (e.data[0] == 'startup') {\n const params = e.data[1];\n //console.log(\"Worker startup params:\",params);\n mod = new twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\n mod.loadWasm(params.urlToLoad).then(() => {\n postMessage([\"startupOkay\"]);\n }).catch((ex) => {\n console.log(\".catch: \", ex);\n postMessage([\"startupFail\", ex]);\n });\n }\n else if (e.data[0] == 'callC') {\n mod.callCImpl(e.data[1], e.data[2]).then((rc) => {\n postMessage([\"callCOkay\", rc]);\n }).catch(e => {\n console.log(\"exception in callC twrworker.js\\n\");\n console.log(e);\n postMessage([\"callCFail\", e]);\n });\n }\n else {\n console.log(\"twrworker.js: unknown message: \" + e);\n }\n};\n// ************************************************************************\nclass twrWasmModuleInWorker extends twrWasmModuleBase {\n malloc;\n modParams;\n constructor(modParams, modInWorkerParams) {\n super();\n this.isWorker = true;\n this.malloc = (size) => { throw new Error(\"error - un-init malloc called\"); };\n this.modParams = modParams;\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\n const canvasProxy = new twrCanvasProxy(modInWorkerParams.canvasProxyParams, this);\n const divProxy = new twrDivProxy(modInWorkerParams.divProxyParams);\n const waitingCallsProxy = new twrWaitingCallsProxy(modInWorkerParams.waitingCallsProxyParams);\n this.modParams.imports = {\n twrDebugLog: twrDebugLogProxy,\n twrSleep: waitingCallsProxy.sleep.bind(waitingCallsProxy),\n twrTime: waitingCallsProxy.time.bind(waitingCallsProxy),\n twrDivCharOut: divProxy.charOut.bind(divProxy),\n twrDivCharIn: divProxy.charIn.bind(divProxy),\n twrCanvasCharIn: canvasProxy.charIn.bind(canvasProxy),\n twrCanvasInkey: canvasProxy.inkey.bind(canvasProxy),\n twrCanvasGetProp: canvasProxy.getProp.bind(canvasProxy),\n twrCanvasDrawSeq: canvasProxy.drawSeq.bind(canvasProxy),\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function (x, y) { return x % y; },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n}\n//# sourceMappingURL=twrmodworker.js.map","// this script is the WebWorker thead used by class twrWasmAsyncModule\r\n\r\nimport {twrCanvasProxy} from \"./twrcanvas.js\";\r\nimport {twrDivProxy} from \"./twrdiv.js\";\r\nimport {twrDebugLogProxy} from \"./twrdebug.js\";\r\nimport {TAsyncModStartupMsg} from \"./twrmodasync.js\"\r\nimport {twrWasmModuleBase, IModInWorkerParams, IModParams} from \"./twrmodbase.js\"\r\nimport {twrWaitingCallsProxy} from \"./twrwaitingcalls.js\";\r\n\r\nlet mod:twrWasmModuleInWorker;\r\n\r\nonmessage = function(e) {\r\n //console.log('twrworker.js: message received from main script: '+e.data);\r\n\r\n if (e.data[0]=='startup') {\r\n const params:TAsyncModStartupMsg=e.data[1];\r\n //console.log(\"Worker startup params:\",params);\r\n mod=new twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\r\n\r\n mod.loadWasm(params.urlToLoad).then( ()=> {\r\n postMessage([\"startupOkay\"]);\r\n }).catch( (ex)=> {\r\n console.log(\".catch: \", ex);\r\n postMessage([\"startupFail\", ex]);\r\n });\r\n }\r\n else if (e.data[0]=='callC') {\r\n mod.callCImpl(e.data[1], e.data[2]).then( (rc)=> {\r\n postMessage([\"callCOkay\", rc]);\r\n }).catch(e => {\r\n console.log(\"exception in callC twrworker.js\\n\");\r\n console.log(e);\r\n postMessage([\"callCFail\", e]);\r\n });\r\n }\r\n else {\r\n console.log(\"twrworker.js: unknown message: \"+e);\r\n }\r\n}\r\n\r\n\r\n// ************************************************************************\r\n\r\nclass twrWasmModuleInWorker extends twrWasmModuleBase {\r\n\tmalloc:(size:number)=>Promise;\r\n modParams: IModParams;\r\n\r\n\r\n constructor(modParams:IModParams, modInWorkerParams:IModInWorkerParams) {\r\n super();\r\n this.isWorker=true;\r\n this.malloc=(size:number)=>{throw new Error(\"error - un-init malloc called\")};\r\n this.modParams=modParams;\r\n\r\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\r\n const canvasProxy = new twrCanvasProxy(modInWorkerParams.canvasProxyParams, this);\r\n const divProxy = new twrDivProxy(modInWorkerParams.divProxyParams);\r\n const waitingCallsProxy = new twrWaitingCallsProxy(modInWorkerParams.waitingCallsProxyParams);\r\n\r\n this.modParams.imports={\r\n twrDebugLog:twrDebugLogProxy,\r\n twrSleep:waitingCallsProxy.sleep.bind(waitingCallsProxy),\r\n twrTime:waitingCallsProxy.time.bind(waitingCallsProxy),\r\n\r\n twrDivCharOut:divProxy.charOut.bind(divProxy), \r\n twrDivCharIn:divProxy.charIn.bind(divProxy), \r\n\r\n twrCanvasCharIn:canvasProxy.charIn.bind(canvasProxy),\r\n twrCanvasInkey:canvasProxy.inkey.bind(canvasProxy),\r\n twrCanvasGetProp:canvasProxy.getProp.bind(canvasProxy),\r\n twrCanvasDrawSeq:canvasProxy.drawSeq.bind(canvasProxy),\r\n\r\n\t\t\ttwrSin:Math.sin,\r\n\t\t\ttwrCos:Math.cos,\r\n\t\t\ttwrTan: Math.tan,\r\n\t\t\ttwrFAbs: Math.abs,\r\n\t\t\ttwrACos: Math.acos,\r\n\t\t\ttwrASin: Math.asin,\r\n\t\t\ttwrATan: Math.atan,\r\n\t\t\ttwrExp: Math.exp,\r\n\t\t\ttwrFloor: Math.floor,\r\n\t\t\ttwrCeil: Math.ceil,\r\n\t\t\ttwrFMod: function(x:number, y:number) {return x%y},\r\n\t\t\ttwrLog: Math.log,\r\n\t\t\ttwrPow: Math.pow,\r\n\t\t\ttwrSqrt: Math.sqrt,\r\n\t\t\ttwrTrunc: Math.trunc,\r\n\r\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\r\n\t\t\ttwrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\r\n\t\t\ttwrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\r\n\t\t\ttwrAtod: this.floatUtil.atod.bind(this.floatUtil),\r\n\t\t\ttwrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\r\n \r\n }\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nimport { twrSignal } from \"./twrsignal.js\";\nvar D2DType;\n(function (D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})(D2DType || (D2DType = {}));\nexport class twrCanvas {\n ctx;\n props = { charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight: 0, canvasWidth: 0 };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase) {\n const { forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new twrSignal();\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext)\n throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c)\n throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2)\n throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\n }\n getProp(pn) {\n if (!this.isValid())\n console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */\n drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid())\n console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx)\n return;\n let ins = this.owner.getLong(ds); /* ds->start */\n const lastins = this.owner.getLong(ds + 4); /* ds->last */\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while (1) {\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */\n if (0 /*type!=D2DType.D2D_FILLRECT*/) {\n console.log(\"ins\", ins);\n console.log(\"hdr.next\", this.owner.mem8[ins], this.owner.mem8[ins + 1], this.owner.mem8[ins + 2], this.owner.mem8[ins + 3]);\n console.log(\"hdr.type\", this.owner.mem8[ins + 4], this.owner.mem8[ins + 5]);\n console.log(\"next 4 bytes\", this.owner.mem8[ins + 6], this.owner.mem8[ins + 7], this.owner.mem8[ins + 8], this.owner.mem8[ins + 9]);\n console.log(\"and 4 more \", this.owner.mem8[ins + 10], this.owner.mem8[ins + 11], this.owner.mem8[ins + 12], this.owner.mem8[ins + 13]);\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\n }\n switch (type) {\n case D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case D2DType.D2D_BEGINPATH:\n {\n this.ctx.beginPath();\n }\n break;\n case D2DType.D2D_FILL:\n {\n this.ctx.fill();\n }\n break;\n case D2DType.D2D_SAVE:\n {\n this.ctx.save();\n }\n break;\n case D2DType.D2D_RESTORE:\n {\n this.ctx.restore();\n }\n break;\n case D2DType.D2D_STROKE:\n {\n this.ctx.stroke();\n }\n break;\n case D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = (this.owner.getLong(ins + 48) != 0);\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n }\n else { // Uint8ClampedArray doesn't support shared memory\n this.precomputedObjects[id] = { mem8: new Uint8Array(this.owner.memory.buffer, start, length), width: width, height: height };\n }\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id])\n delete this.precomputedObjects[id];\n else\n console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) {\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n }\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) {\n this.ctx.putImageData(imgData, dx, dy);\n }\n else {\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */\n if (next == 0) {\n if (ins != lastins)\n throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal)\n this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nexport class twrCanvasProxy {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner) {\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new twrSignal(signalBuffer);\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\"drawseq\", [ds]]);\n this.drawCompleteSignal.wait();\n }\n}\n//# sourceMappingURL=twrcanvas.js.map","import {twrWasmModuleBase, IModParams} from \"./twrmodbase.js\"\r\nimport {twrSharedCircularBuffer} from \"./twrcircular.js\";\r\nimport {twrSignal} from \"./twrsignal.js\";\r\n\r\n\r\n// Canvas have a size that will be set based on the character width x height\r\n// The display size for a canvas will default to this size, but can be changed in the HTML/JS via\r\n// canvas.style.width = \"700px\";\r\n// canvas.style.height = \"500px\";\r\n\r\nexport interface ICanvasProps {\r\n\tcharWidth: number,\r\n\tcharHeight: number,\r\n\tforeColor: number,\r\n\tbackColor: number,\r\n widthInChars: number,\r\n heightInChars: number,\r\n canvasWidth:number,\r\n canvasHeight:number\r\n}\r\n\r\nenum D2DType {\r\n D2D_FILLRECT=1,\r\n D2D_FILLCHAR=5,\r\n D2D_SETLINEWIDTH=10,\r\n D2D_SETFILLSTYLERGBA=11,\r\n D2D_SETFONT=12,\r\n D2D_BEGINPATH=13,\r\n D2D_MOVETO=14,\r\n D2D_LINETO=15,\r\n D2D_FILL=16,\r\n D2D_STROKE=17,\r\n D2D_SETSTROKESTYLERGBA=18,\r\n D2D_ARC=19,\r\n D2D_STROKERECT=20,\r\n D2D_FILLTEXT=21,\r\n D2D_IMAGEDATA=22,\r\n D2D_PUTIMAGEDATA=23,\r\n D2D_BEZIERTO=24,\r\n D2D_MEASURETEXT=25,\r\n D2D_SAVE=26,\r\n D2D_RESTORE=27,\r\n D2D_CREATERADIALGRADIENT=28,\r\n D2D_SETCOLORSTOP=29,\r\n D2D_SETFILLSTYLEGRADIENT=30,\r\n D2D_RELEASEID=31,\r\n D2D_CREATELINEARGRADIENT=32,\r\n D2D_SETFILLSTYLE=33,\r\n D2D_SETSTROKESTYLE=34\r\n\r\n}\r\n\r\nexport type TCanvasProxyParams = [ICanvasProps, SharedArrayBuffer, SharedArrayBuffer];\r\n\r\nexport interface ICanvas {\r\n props: ICanvasProps,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TCanvasProxyParams,\r\n drawSeq: (ds:number)=>void,\r\n }\r\n \r\nexport class twrCanvas implements ICanvas {\r\n ctx:CanvasRenderingContext2D|undefined;\r\n props:ICanvasProps={charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight:0, canvasWidth:0};\r\n owner: twrWasmModuleBase;\r\n cmdCompleteSignal?:twrSignal;\r\n canvasKeys?: twrSharedCircularBuffer;\r\n precomputedObjects: { [index: number]: \r\n (ImageData | {mem8:Uint8Array, width:number, height:number}) |\r\n CanvasGradient\r\n };\r\n\r\n constructor(element:HTMLCanvasElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n const {forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas} = modParams; \r\n this.owner=modbase;\r\n this.props.widthInChars=modParams.windim[0];\r\n this.props.heightInChars=modParams.windim[1];\r\n\r\n if (!this.owner.isWasmModule) {\r\n this.cmdCompleteSignal=new twrSignal();\r\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n }\r\n\r\n this.precomputedObjects={};\r\n \r\n if (element) {\r\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\r\n let c=element.getContext(\"2d\");\r\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\r\n\r\n c.font = fontsize.toString()+\"px Courier New\";\r\n c.textBaseline=\"top\";\r\n const sampleText=\" \";\r\n const tm=c.measureText(sampleText);\r\n this.props.charWidth=Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\r\n let fM = c.measureText(\"X\"); \r\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\r\n\r\n if (!isd2dcanvas) {\r\n element.width=this.props.charWidth*this.props.widthInChars;\r\n element.height=this.props.charHeight*this.props.heightInChars;\r\n }\r\n\r\n this.props.canvasHeight=element.height;\r\n this.props.canvasWidth=element.width;\r\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\r\n\r\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\r\n let c2=element.getContext(\"2d\");\r\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\r\n this.ctx=c2;\r\n this.ctx.font = fontsize.toString()+\"px Courier New\";\r\n this.ctx.textBaseline=\"top\";\r\n\r\n c2.fillStyle=backcolor;\r\n this.props.backColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n c2.fillStyle=forecolor;\r\n this.props.foreColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n }\r\n\r\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\r\n\r\n //console.log(\"twrCanvas.constructor props: \", this.props);\r\n }\r\n\r\n isValid() {\r\n return !!this.ctx;\r\n }\r\n\r\n getProxyParams() : TCanvasProxyParams {\r\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\r\n }\r\n\r\n getProp(pn:number): number {\r\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n\r\n/* see draw2d.h for structs that match */\r\n\r\n drawSeq(ds:number) {\r\n //console.log(\"twr::Canvas enter drawSeq\");\r\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\r\n if (!this.ctx) return;\r\n\r\n let ins=this.owner.getLong(ds); /* ds->start */\r\n const lastins=this.owner.getLong(ds+4); /* ds->last */\r\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\r\n\r\n let next:number;\r\n //let insCount=0;\r\n\r\n while (1) {\r\n\r\n //insCount++;\r\n\r\n const type:D2DType=this.owner.getLong(ins+4); /* hdr->type */\r\n if (0/*type!=D2DType.D2D_FILLRECT*/) {\r\n console.log(\"ins\",ins)\r\n console.log(\"hdr.next\",this.owner.mem8[ins],this.owner.mem8[ins+1],this.owner.mem8[ins+2],this.owner.mem8[ins+3]);\r\n console.log(\"hdr.type\",this.owner.mem8[ins+4],this.owner.mem8[ins+5]);\r\n console.log(\"next 4 bytes\", this.owner.mem8[ins+6],this.owner.mem8[ins+7],this.owner.mem8[ins+8],this.owner.mem8[ins+9]);\r\n console.log(\"and 4 more \", this.owner.mem8[ins+10],this.owner.mem8[ins+11],this.owner.mem8[ins+12],this.owner.mem8[ins+13]);\r\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\r\n }\r\n switch (type) {\r\n case D2DType.D2D_FILLRECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.fillRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKERECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.strokeRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILLCHAR:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const c=this.owner.getShort(ins+24);\r\n let txt=String.fromCharCode(c);\r\n this.ctx.fillText(txt, x, y);\r\n }\r\n break;\r\n\r\n \r\n case D2DType.D2D_FILLTEXT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const str=this.owner.getString(this.owner.getLong(ins+24));\r\n\r\n //console.log(\"filltext \",x,y,str)\r\n \r\n this.ctx.fillText(str, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MEASURETEXT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n const tmidx=this.owner.getLong(ins+12);\r\n \r\n const tm=this.ctx.measureText(str);\r\n this.owner.setDouble(tmidx+0, tm.actualBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+8, tm.actualBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+16, tm.actualBoundingBoxLeft);\r\n this.owner.setDouble(tmidx+24, tm.actualBoundingBoxRight);\r\n this.owner.setDouble(tmidx+32, tm.fontBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+40, tm.fontBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+48, tm.width);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFONT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.font=str;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.fillStyle = cssColor;\r\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETSTROKESTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.fillStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETSTROKESTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETLINEWIDTH:\r\n {\r\n const width=this.owner.getShort(ins+8); \r\n this.ctx.lineWidth=width;\r\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MOVETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.moveTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_LINETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.lineTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEZIERTO:\r\n {\r\n const cp1x=this.owner.getDouble(ins+8);\r\n const cp1y=this.owner.getDouble(ins+16);\r\n const cp2x=this.owner.getDouble(ins+24);\r\n const cp2y=this.owner.getDouble(ins+32);\r\n const x=this.owner.getDouble(ins+40);\r\n const y=this.owner.getDouble(ins+48);\r\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEGINPATH:\r\n {\r\n this.ctx.beginPath();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILL:\r\n {\r\n this.ctx.fill();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SAVE:\r\n {\r\n this.ctx.save();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_RESTORE:\r\n {\r\n this.ctx.restore();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKE:\r\n {\r\n this.ctx.stroke();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_ARC:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const radius=this.owner.getDouble(ins+24);\r\n const startAngle=this.owner.getDouble(ins+32);\r\n const endAngle=this.owner.getDouble(ins+40);\r\n const counterClockwise= (this.owner.getLong(ins+48)!=0);\r\n\r\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_IMAGEDATA:\r\n {\r\n const start=this.owner.getLong(ins+8);\r\n const length=this.owner.getLong(ins+12);\r\n const width=this.owner.getLong(ins+16);\r\n const height=this.owner.getLong(ins+20);\r\n const id=this.owner.getLong(ins+24);\r\n\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\r\n\r\n if (this.owner.isWasmModule) {\r\n const z = new Uint8ClampedArray(this.owner.memory!.buffer, start, length);\r\n this.precomputedObjects[id]=new ImageData(z, width, height);\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory\r\n this.precomputedObjects[id]={mem8: new Uint8Array(this.owner.memory!.buffer, start, length), width:width, height:height};\r\n }\r\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_CREATERADIALGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const radius0=this.owner.getDouble(ins+24);\r\n const x1=this.owner.getDouble(ins+32);\r\n const y1=this.owner.getDouble(ins+40);\r\n const radius1=this.owner.getDouble(ins+48);\r\n const id= this.owner.getLong(ins+56);\r\n\r\n let gradient=this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_CREATELINEARGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const x1=this.owner.getDouble(ins+24);\r\n const y1=this.owner.getDouble(ins+32);\r\n const id= this.owner.getLong(ins+40);\r\n \r\n let gradient=this.ctx.createLinearGradient(x0, y0, x1, y1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETCOLORSTOP:\r\n {\r\n const id = this.owner.getLong(ins+8);\r\n const pos=this.owner.getLong(ins+12);\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+16));\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n gradient.addColorStop(pos, cssColor);\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n this.ctx.fillStyle=gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_RELEASEID:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (this.precomputedObjects[id])\r\n delete this.precomputedObjects[id];\r\n else\r\n console.log(\"warning: D2D_RELEASEID with undefined ID \",id);\r\n }\r\n break\r\n\r\n \r\n\r\n case D2DType.D2D_PUTIMAGEDATA:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n const dx=this.owner.getLong(ins+12);\r\n const dy=this.owner.getLong(ins+16);\r\n const dirtyX=this.owner.getLong(ins+20);\r\n const dirtyY=this.owner.getLong(ins+24);\r\n const dirtyWidth=this.owner.getLong(ins+28);\r\n const dirtyHeight=this.owner.getLong(ins+32);\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \"+id);\r\n\r\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\r\n\r\n let imgData:ImageData;\r\n if (this.owner.isWasmModule) {\r\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\r\n imgData=this.precomputedObjects[id] as ImageData;\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\r\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\r\n const z = this.precomputedObjects[id] as {mem8:Uint8Array, width:number, height:number}; // Uint8Array\r\n const ca=Uint8ClampedArray.from(z.mem8); // shallow copy\r\n imgData=new ImageData(ca, z.width, z.height);\r\n }\r\n \r\n if (dirtyWidth==0 && dirtyHeight==0) {\r\n this.ctx.putImageData(imgData, dx, dy);\r\n }\r\n else {\r\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\r\n }\r\n }\r\n break;\r\n\r\n default:\r\n throw new Error (\"unimplemented or unknown Sequence Type in drawSeq: \"+type);\r\n }\r\n next=this.owner.getLong(ins); /* hdr->next */\r\n if (next==0) {\r\n if (ins!=lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\r\n break;\r\n }\r\n ins=next;\r\n }\r\n\r\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\r\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\r\n }\r\n}\r\n\r\nexport class twrCanvasProxy implements ICanvas {\r\n canvasKeys: twrSharedCircularBuffer;\r\n drawCompleteSignal:twrSignal;\r\n props: ICanvasProps;\r\n owner: twrWasmModuleBase;\r\n\r\n constructor(params:TCanvasProxyParams, owner:twrWasmModuleBase) {\r\n const [props, signalBuffer, canvasKeysBuffer] = params;\r\n this.drawCompleteSignal = new twrSignal(signalBuffer);\r\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\r\n this.props=props;\r\n this.owner=owner;\r\n\r\n //console.log(\"Create New twrCanvasProxy: \",this.props)\r\n\r\n }\r\n\r\n charIn() { \r\n //ctx.commit(); not avail in chrome\r\n \r\n //postMessage([\"debug\", 'x']);\r\n \r\n return this.canvasKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.canvasKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n getProp(pn:number): number {\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n \r\n drawSeq(ds:number) {\r\n this.drawCompleteSignal.reset();\r\n postMessage([\"drawseq\", [ds]]);\r\n this.drawCompleteSignal.wait();\r\n }\r\n}\r\n","//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst RDIDX = 256;\nconst WRIDX = 257;\nconst LEN = 256;\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\n// the first 256 array entries are the circular buffer\n// the next two are used for the read and write index\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\nexport class twrSharedCircularBuffer {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(258 * 4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[RDIDX] = 0;\n this.buf[WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[WRIDX];\n this.buf[i] = n;\n i++;\n if (i == LEN)\n i = 0;\n this.buf[WRIDX] = i;\n Atomics.notify(this.buf, WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[RDIDX] = i;\n return n;\n }\n else\n return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[RDIDX] == this.buf[WRIDX];\n }\n}\n//# sourceMappingURL=twrcircular.js.map","//\r\n// This class implements a circular buffer that the main javascript thread can write to, \r\n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\r\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \r\n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\r\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\r\n//\r\n\r\nconst RDIDX=256;\r\nconst WRIDX=257;\r\nconst LEN=256;\r\n\r\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\r\n// the first 256 array entries are the circular buffer\r\n// the next two are used for the read and write index\r\n\r\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\r\n\r\nexport class twrSharedCircularBuffer {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n \r\n\tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(258*4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[RDIDX]=0;\r\n this.buf[WRIDX]=0;\r\n\t}\r\n\r\n\twrite(n:number) {\r\n let i=this.buf[WRIDX];\r\n this.buf[i]=n;\r\n i++;\r\n if (i==LEN) i=0;\r\n this.buf[WRIDX]=i; \r\n Atomics.notify(this.buf, WRIDX); \r\n\t}\r\n\r\n\tread():number {\r\n if (!this.isEmpty()) {\r\n let i=this.buf[RDIDX];\r\n let n=this.buf[i];\r\n i++;\r\n this.buf[RDIDX]=i;\r\n return n;\r\n }\r\n\t\telse\r\n return -1;\r\n\t}\r\n\r\n readWait():number {\r\n if (this.isEmpty()) {\r\n const rdptr=this.buf[RDIDX];\r\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\r\n Atomics.wait(this.buf, WRIDX, rdptr);\r\n }\r\n return this.read();\r\n\t}\r\n\r\n isEmpty():boolean {\r\n return this.buf[RDIDX]==this.buf[WRIDX];\r\n }\r\n}\r\n","//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar twrSignalState;\n(function (twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})(twrSignalState || (twrSignalState = {}));\n;\nexport class twrSignal {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window valid\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == twrSignalState.WAITING) {\n //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\n //console.log(\"released...\");\n }\n }\n isSignaled() {\n return this.buf[0] == twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = twrSignalState.WAITING;\n }\n}\n//# sourceMappingURL=twrsignal.js.map","//\r\n// This class implements a simple signal/wait mechanism\r\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\r\n//\r\n\r\nenum twrSignalState {\r\n WAITING=0,\r\n SIGNALED=1\r\n};\r\n\r\nexport class twrSignal {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n\r\n \tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window valid\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) \r\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[0]=twrSignalState.WAITING;\r\n\t}\r\n\r\n\tsignal() {\r\n this.buf[0]=twrSignalState.SIGNALED; \r\n //console.log(\"about to signal\");\r\n Atomics.notify(this.buf, 0); \r\n\t}\r\n\r\n wait() {\r\n if (this.buf[0]==twrSignalState.WAITING) {\r\n //console.log(\"waiting...\");\r\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\r\n //console.log(\"released...\");\r\n\r\n }\r\n\t}\r\n isSignaled():boolean {\r\n return this.buf[0]==twrSignalState.SIGNALED;\r\n }\r\n\r\n reset() {\r\n this.buf[0]=twrSignalState.WAITING;\r\n }\r\n}\r\n","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nexport class twrDiv {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase) {\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\n this.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n if (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.divKeys.sharedArray];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */\n charOut(ch) {\n if (!this.div)\n return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n }\n switch (ch) {\n case 10: // newline\n case 13: // return\n if (ch == 10 && this.lastChar == 13)\n break; // detect CR LF and treat as single new line\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8: // backspace\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n case 0xE: // cursor on\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF: // cursor off\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for (let i = 0; i < str.length; i++)\n this.charOut(str.charCodeAt(i));\n }\n}\nexport class twrDivProxy {\n divKeys;\n constructor(params) {\n const [divKeysBuffer] = params;\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n charOut(ch) {\n postMessage([\"divout\", ch]);\n }\n}\n//# sourceMappingURL=twrdiv.js.map","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\r\nimport { IModParams } from \"./twrmodbase.js\";\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\";\r\n\r\nexport type TDivProxyParams = [SharedArrayBuffer];\r\n\r\nexport interface IDiv {\r\n charOut: (ds:number)=>void,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TDivProxyParams,\r\n }\r\n\r\n\r\nexport class twrDiv implements IDiv {\r\n\tdiv:HTMLDivElement|null|undefined;\r\n\tdivKeys?:twrSharedCircularBuffer;\r\n\tCURSOR=String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\r\n\tcursorOn:boolean=false;\r\n\tlastChar:number=0;\r\n\textraBR:boolean=false;\r\n\towner:twrWasmModuleBase;\r\n\r\n constructor(element:HTMLDivElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n\t\tthis.div=element;\r\n\t\tthis.owner=modbase;\r\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\r\n\t\t\tthis.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n\t\t}\r\n\r\n\t\tif (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\r\n\t\t\tthis.div.style.backgroundColor = modParams.backcolor;\r\n\t\t\tthis.div.style.color = modParams.forecolor;\r\n\t\t\tthis.div.style.font=modParams.fontsize.toString()+\"px arial\"\r\n\t\t}\r\n }\r\n\r\n\tisValid() {\r\n\t\treturn !!this.div;\r\n\t}\r\n\r\n getProxyParams() : TDivProxyParams {\r\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [ this.divKeys.sharedArray];\r\n }\r\n\r\n\r\n/* \r\n * add character to div. Supports the following control codes:\r\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\r\n * 0xE cursor on \r\n * 0x8 backspace\r\n * 0xF cursor off \r\n*/\r\n\tcharOut(ch:number) {\r\n\r\n\t\tif (!this.div) return;\r\n\r\n\t\t//console.log(\"div::charout: \", ch);\r\n\r\n\t\tif (this.extraBR) {\r\n\t\t\tthis.extraBR=false;\r\n\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -4);\r\n\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t}\r\n\r\n\t\tswitch (ch) {\r\n\t\t\tcase 10: // newline\r\n\t\t\tcase 13: // return\r\n\t\t\t\tif (ch==10 && this.lastChar==13) break; // detect CR LF and treat as single new line\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\r\n\t\t\t\tthis.extraBR=true;\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\t//element.scrollIntoView();\r\n\t\t\t\t//element.scrollTop = element.scrollHeight;\r\n\t\t\t\tlet p = this.div.getBoundingClientRect();\r\n\t\t\t\twindow.scrollTo(0, p.height+100);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 8: // backspace\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xE: // cursor on\r\n\t\t\t\tif (!this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=true;\r\n\t\t\t\t\tthis.div.innerHTML += this.CURSOR;\r\n\t\t\t\t\tthis.div.focus();\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xF: // cursor off\r\n\t\t\t\tif (this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=false;\r\n\t\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += String.fromCharCode(ch);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\tthis.lastChar=ch;\r\n\t}\r\n\r\n\tstringOut(str:string) {\r\n\t\tfor (let i=0; i < str.length; i++)\r\n\t\t\tthis.charOut(str.charCodeAt(i));\r\n\t}\r\n}\r\n\r\n\r\nexport class twrDivProxy implements IDiv {\r\n divKeys: twrSharedCircularBuffer;\r\n\r\n constructor(params:TDivProxyParams) {\r\n const [divKeysBuffer] = params;\r\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\r\n }\r\n\r\n charIn() { \r\n return this.divKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.divKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n\tcharOut(ch:number) {\r\n\t\tpostMessage([\"divout\", ch]);\r\n\t}\r\n}\r\n\r\n","let logline = \"\";\nexport function twrDebugLogImpl(char) {\n if (char == 10 || char == 3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\n console.log(logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n logline = \"\";\n }\n else {\n logline = logline + String.fromCharCode(char);\n if (logline.length >= 200) {\n console.log(logline);\n logline = \"\";\n }\n }\n}\n// ************************************************************************\n// debugLog doesn't currently wait for the message to log, it returns immediately.\n// I could move this to be in the twrWaitingCalls class\nexport function twrDebugLogProxy(ch) {\n postMessage([\"debug\", ch]);\n}\n//# sourceMappingURL=twrdebug.js.map","\r\nlet logline=\"\";\r\nexport function twrDebugLogImpl(char:number) {\r\n\tif (char==10 || char==3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\r\n\t\tconsole.log(logline);\t// ideally without a linefeed, but there is no way to not have a LF with console.log API.\r\n\t\tlogline=\"\";\r\n\t}\r\n\telse {\r\n\t\tlogline=logline+String.fromCharCode(char);\r\n\t\tif (logline.length>=200) {\r\n\t\t\tconsole.log(logline);\r\n\t\t\tlogline=\"\";\r\n\t\t}\r\n\t}\r\n}\r\n\r\n// ************************************************************************\r\n// debugLog doesn't currently wait for the message to log, it returns immediately.\r\n// I could move this to be in the twrWaitingCalls class\r\nexport function twrDebugLogProxy(ch:number) {\r\n postMessage([\"debug\", ch]);\r\n}\r\n\r\n","import { twrFloatUtil } from \"./twrfloat.js\";\n/*********************************************************************/\n/*********************************************************************/\n/*********************************************************************/\nexport class twrWasmModuleBase {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\n floatUtil;\n constructor(isWasmModule = false) {\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new twrFloatUtil(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/\n /*********************************************************************/\n async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n }\n catch (err) {\n console.log('loadWasm() failed to fetch: ' + pathToLoad);\n throw err;\n }\n if (!response.ok)\n throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, { env: allimports });\n this.exports = instance.instance.exports;\n if (!this.exports)\n throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory)\n throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory)\n throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer)\n console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\"setmemory\", this.memory]);\n }\n if (this.isWasmModule) {\n // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (!(this.memory.buffer instanceof ArrayBuffer))\n console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size) => {\n return new Promise(resolve => {\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n }\n catch (err) {\n console.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch (this.modParams.stdio) {\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* callC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */\n async callC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.callCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async callCImpl(fname, cparams = []) {\n if (!this.exports)\n throw new Error(\"this.exports undefined\");\n if (!this.exports[fname])\n throw new Error(\"callC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array))\n throw new Error(\"callC: params must be array, first arg is function name\");\n if (params.length == 0)\n throw new Error(\"callC: missing function name\");\n let cparams = [];\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n cparams[ci++] = p;\n break;\n case 'string':\n cparams[ci++] = await this.putString(p);\n break;\n case 'object':\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n }\n else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"callC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n ci++;\n break;\n case 'string':\n this.callCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n case 'object':\n if (p instanceof URL) {\n this.callCImpl('twr_free', [cparams[ci]]);\n ci = ci + 2;\n break;\n }\n else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for (let j = 0; j < u8.length; j++)\n u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.callCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n }\n else\n throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/\n /*********************************************************************/\n // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for (i = 0; i < sin.length && i < buffer_size - 1; i++)\n this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for (let i = 0; i < u8a.length; i++)\n this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === 'object' && fnin instanceof URL))\n throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [dest, src.length];\n }\n catch (err) {\n console.log('fetchAndPutURL Error. URL: ' + fnin + '\\n' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while (this.mem8[strIndex + i] && (len === undefined ? true : i < len) && (strIndex + i) < this.mem8.length) {\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0)\n throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array((this.mem8.slice(dataptr, dataptr + size)).buffer);\n return u32;\n }\n}\n//# sourceMappingURL=twrmodbase.js.map","\r\nimport {TCanvasProxyParams} from \"./twrcanvas.js\"\r\nimport {TDivProxyParams} from \"./twrdiv.js\";\r\nimport {TWaitingCallsProxyParams} from \"./twrwaitingcalls.js\"\r\nimport {twrDebugLogImpl} from \"./twrdebug.js\";\r\nimport {twrFloatUtil} from \"./twrfloat.js\";\r\n\r\n\r\nexport type TStdioVals=\"div\"|\"canvas\"|\"null\"|\"debug\";\r\n\r\nexport interface IModOpts {\r\n\tstdio?:TStdioVals, \r\n\twindim?:[number, number],\r\n\tforecolor?:string,\r\n\tbackcolor?:string,\r\n\tfontsize?:number,\r\n\tisd2dcanvas?:boolean,\r\n\timports?:{},\r\n}\r\n\r\nexport interface IModParams {\r\n\tstdio:TStdioVals, \r\n\twindim:[number, number],\r\n\tforecolor:string,\r\n\tbackcolor:string,\r\n\tfontsize:number,\r\n\tstyleIsDefault: boolean\r\n\tisd2dcanvas:boolean,\r\n\timports:{[index:string]:Function},\r\n}\r\n\r\nexport interface IModInWorkerParams {\r\n\tdivProxyParams:TDivProxyParams,\r\n\tcanvasProxyParams:TCanvasProxyParams,\r\n\twaitingCallsProxyParams:TWaitingCallsProxyParams,\r\n}\r\n\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n\r\nexport abstract class twrWasmModuleBase {\r\n\tmemory?:WebAssembly.Memory;\r\n\tmem8:Uint8Array;\r\n\tmem32:Uint32Array;\r\n\tmemD:Float64Array;\r\n\tabstract malloc:(size:number)=>Promise;\r\n\tabstract modParams:IModParams;\r\n\texports?:WebAssembly.Exports;\r\n\tisWorker=false;\r\n\tisWasmModule:boolean; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\r\n\tfloatUtil:twrFloatUtil;\r\n\r\n\tconstructor(isWasmModule=false) {\r\n\t\tthis.isWasmModule=isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\r\n\t\tthis.mem8=new Uint8Array(); \t// avoid type errors\r\n\t\tthis.mem32=new Uint32Array(); // avoid type errors\r\n\t\tthis.memD=new Float64Array(); // avoid type errors\r\n\t\tthis.floatUtil=new twrFloatUtil(this);\r\n\t\t//console.log(\"size of mem8 after constructor\",this.mem8.length);\r\n\t}\r\n\r\n\t/*********************************************************************/\r\n\t/*********************************************************************/\r\n\r\n\tasync loadWasm(pathToLoad:string) {\r\n\t\t//console.log(\"fileToLoad\",fileToLoad)\r\n\r\n\t\tlet response;\r\n\t\ttry {\r\n\t\t\tresponse=await fetch(pathToLoad);\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('loadWasm() failed to fetch: '+pathToLoad);\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t\t\r\n\t\tif (!response.ok) throw new Error(\"fetch response error on file '\"+pathToLoad+\"'\\n\"+response.statusText);\r\n\r\n\t\ttry {\r\n\t\t\tlet wasmBytes = await response.arrayBuffer();\r\n\r\n\t\t\tlet allimports:WebAssembly.ModuleImports = { \r\n\t\t\t\t...this.modParams.imports\r\n\t\t\t};\r\n\r\n\t\t\tlet instance = await WebAssembly.instantiate(wasmBytes, {env: allimports});\r\n\r\n\t\t\tthis.exports=instance.instance.exports;\r\n\t\t\tif (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\r\n\r\n\t\t\tif (this.memory) throw new Error (\"unexpected error -- this.memory already set\");\r\n\t\t\tthis.memory=this.exports.memory as WebAssembly.Memory;\r\n\t\t\tif (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\r\n\t\t\tthis.mem8 = new Uint8Array(this.memory.buffer);\r\n\t\t\tthis.mem32 = new Uint32Array(this.memory.buffer);\r\n\t\t\tthis.memD = new Float64Array(this.memory.buffer);\r\n\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\tif (this.isWorker) {\r\n\t\t\t\tif (this.memory.buffer instanceof ArrayBuffer)\r\n\t\t\t\t\tconsole.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\r\n\t\t\t\t\r\n\t\t\t\tpostMessage([\"setmemory\",this.memory]);\r\n\t\t\t}\r\n\t\t\tif (this.isWasmModule) {\r\n\t\t\t\t// here if twrWasmModule, twrWasmModuleAsync overrides this function\r\n\t\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\t\tif (!(this.memory.buffer instanceof ArrayBuffer))\r\n\t\t\t\t\tconsole.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\r\n\t\t\t}\r\n\r\n\t\t\tthis.malloc=(size:number)=>{\r\n\t\t\t\treturn new Promise(resolve => {\r\n\t\t\t\t\tconst m=this.exports!.twr_malloc as (size:number)=>number;\r\n\t\t\t\t\tresolve(m(size));\r\n\t\t\t\t});\r\n\t\t };\r\n\r\n\t\t\tthis.init();\r\n\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t}\r\n\r\n\tprivate init() {\r\n\t\t//console.log(\"loadWasm.init() enter\")\r\n\t\t\tlet p:number;\r\n\t\t\tswitch (this.modParams.stdio) {\r\n\t\t\t\tcase \"debug\":\r\n\t\t\t\t\tp=0;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"div\":\r\n\t\t\t\t\tp=1;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"canvas\":\r\n\t\t\t\t\tp=2;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"null\":\r\n\t\t\t\t\tp=3;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tp=0; // debug\r\n\t\t\t}\r\n\r\n\t\t\tconst twrInit=this.exports!.twr_wasm_init as CallableFunction;\r\n\t\t\t//console.log(\"twrInit:\",twrInit)\r\n\t\t\ttwrInit(p, this.mem8.length);\r\n\t}\r\n\r\n\t/* callC takes an array where:\r\n\t* the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\r\n\t* and the next entries are a variable number of parameters to pass to the C function, of type\r\n\t* number - converted to int32 or float64 as appropriate\r\n\t* string - converted to a an index (ptr) into a module Memory returned via stringToMem()\r\n\t* URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\r\n\t* Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\r\n */\r\n\r\n\tasync callC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\t\tconst cparams=await this.preCallC(params);\r\n\t\tlet retval = this.callCImpl(params[0], cparams);\r\n\t\tthis.postCallC(cparams, params);\r\n\t\treturn retval;\r\n\t}\r\n\r\n\tasync callCImpl(fname:string, cparams:number[]=[]) {\r\n\t\tif (!this.exports) throw new Error(\"this.exports undefined\");\r\n\t\tif (!this.exports[fname]) throw new Error(\"callC: function '\"+fname+\"' not in export table. Use --export wasm-ld flag.\");\r\n\r\n\t\tconst f = this.exports[fname] as CallableFunction;\r\n\t\tlet cr=f(...cparams);\r\n\r\n\t\treturn cr;\r\n\t}\r\n\r\n\t// convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\r\n\tasync preCallC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tif (!(params.constructor === Array)) throw new Error (\"callC: params must be array, first arg is function name\");\r\n\t\tif (params.length==0) throw new Error(\"callC: missing function name\");\r\n\r\n\t\tlet cparams:number[]=[];\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tcparams[ci++]=p;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tcparams[ci++]=await this.putString(p);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tconst r=await this.fetchAndPutURL(p);\r\n\t\t\t\t\t\tcparams[ci++]=r[0]; // mem index\r\n\t\t\t\t\t\tcparams[ci++]=r[1]; // len\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tconst r=await this.putArrayBuffer(p);\r\n\t\t\t\t\t\tcparams[ci++]=r; // mem index\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tthrow new Error (\"callC: invalid object type passed in\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn cparams;\r\n\t}\r\n\r\n\t// free the mallocs; copy array buffer data from malloc back to arraybuffer\r\n\tasync postCallC(cparams:number[], params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tthis.callCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t\t\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tthis.callCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\t\tci=ci+2;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tlet u8=new Uint8Array(p);\r\n\t\t\t\t\t\tfor (let j=0; j= this.mem32.length) throw new Error(\"invalid index passed to getLong: \"+idx+\", this.mem32.length: \"+this.mem32.length);\r\n\t\tconst long:number = this.mem32[idx32];\r\n\t\treturn long;\r\n\t}\r\n\t\r\n\tsetLong(idx:number, value:number) {\r\n const idx32 = Math.floor(idx / 4);\r\n if (idx32 * 4 != idx)\r\n throw new Error(\"setLong passed non long aligned address\");\r\n if (idx32 < 0 || idx32 >= this.mem32.length)\r\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\r\n this.mem32[idx32]=value;\r\n }\r\n\r\n\tgetDouble(idx:number): number {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"getLong passed non Float64 aligned address\")\r\n\t\tconst long:number = this.memD[idx64];\r\n\t\treturn long;\r\n\t}\r\n\r\n\tsetDouble(idx:number, value:number) {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"setDouble passed non Float64 aligned address\")\r\n\t\tthis.memD[idx64]=value;\r\n\t}\r\n\r\n\tgetShort(idx:number): number {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getShort: \"+idx);\r\n\t\tconst short:number = this.mem8[idx]+this.mem8[idx+1]*256;\r\n\t\treturn short;\r\n\t}\r\n\r\n\t// get a string out of module memory\r\n\t// null terminated, up until max of (optional) len\r\n\tgetString(strIndex:number, len?:number): string {\r\n\t\tlet sout=\"\";\r\n\r\n\t\tlet i=0;\r\n\t\twhile (this.mem8[strIndex+i] && (len===undefined?true:i= this.mem8.length) throw new Error(\"invalid index passed to getU8: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU8\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU8\")\r\n\r\n\t\tconst u8=this.mem8.slice(dataptr, dataptr+size);\r\n\t\treturn u8;\r\n\t}\r\n\r\n\t// get a int32 array out of module memory when passed in index to [size, dataptr]\r\n\tgetU32Arr(idx:number): Uint32Array {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getU32: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU32\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU32\")\r\n\r\n\t\tif (size%4!=0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\r\n\r\n\t\tconst u32 = new Uint32Array( (this.mem8.slice(dataptr, dataptr+size)).buffer );\r\n\t\treturn u32;\r\n\t}\r\n}\r\n","export class twrFloatUtil {\n mod;\n constructor(mod) {\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\")\n return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\")\n return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll('D', 'e').replaceAll('d', 'e'));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n }\n else {\n let r = value.toString();\n if (r.length > max_precision)\n r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, // char *\n sizeInBytes, //size_t\n value, // double\n fracpart_numdigits, //int\n dec, // int *\n sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1)\n return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) { /* nan */\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (!Number.isFinite(value)) { /* infinity */\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n }\n else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split('.');\n if (intPart == \"0\")\n intPart = \"\";\n if (intPart.length > 0) { // has integer part\n decpos = intPart.length;\n digits = intPart + fracPart;\n }\n else { // only a fraction\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length)\n return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */\n }\n}\n//# sourceMappingURL=twrfloat.js.map","\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\"\r\n\r\nexport class twrFloatUtil {\r\n mod: twrWasmModuleBase;\r\n\r\n constructor(mod: twrWasmModuleBase) {\r\n this.mod=mod;\r\n }\r\n\r\n atod(strptr:number):number {\r\n const str=this.mod.getString(strptr);\r\n\r\n const upper=str.trimStart().toUpperCase();\r\n if (upper==\"INF\" || upper==\"+INF\")\r\n return Number.POSITIVE_INFINITY;\r\n else if (upper==\"-INF\")\r\n return Number.NEGATIVE_INFINITY\r\n else {\r\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\r\n const r=Number.parseFloat(str.replaceAll('D','e').replaceAll('d','e'));\r\n return r;\r\n }\r\n }\r\n\r\n dtoa(buffer:number, buffer_size:number, value:number, max_precision:number):void {\r\n if (max_precision==-1) {\r\n const r=value.toString();\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n else {\r\n let r=value.toString();\r\n if (r.length>max_precision)\r\n r=value.toPrecision(max_precision);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n }\r\n\r\n toFixed(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toFixed(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n toExponential(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toExponential(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\r\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\r\n // Negative exponents must be now smaller than 1e-99\r\n // fully-function C version also int he source, but this is the version enabled by default\r\n fcvtS(\r\n buffer:number, // char *\r\n sizeInBytes:number, //size_t\r\n value:number, // double\r\n fracpart_numdigits:number, //int\r\n dec:number, // int *\r\n sign:number // int *\r\n ):number {\r\n\r\n if (buffer==0 ||sign==0 || dec==0 || sizeInBytes<1) return 1;\r\n\r\n let digits:string;\r\n let decpos:number;\r\n let s=0; // default to positive\r\n\r\n\r\n if (Number.isNaN(value)) { /* nan */\r\n digits=\"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (!Number.isFinite(value)) { /* infinity */\r\n digits=\"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (value==0) { \r\n digits=\"000000000000000000000000000000000000\".slice(0,fracpart_numdigits);\r\n decpos=0;\r\n }\r\n \r\n else {\r\n\r\n if (value<0) {\r\n s=1; // negative\r\n value=Math.abs(value);\r\n }\r\n\r\n if (fracpart_numdigits>100 || value > 1e+21 || value < 1e-99) { \r\n this.mod.copyString(buffer, sizeInBytes, \"\");\r\n this.mod.mem32[dec]=0;\r\n return 1;\r\n }\r\n\r\n const roundValStr=value.toFixed(fracpart_numdigits);\r\n let [intPart=\"\", fracPart=\"\"] = roundValStr.split('.');\r\n if (intPart==\"0\") intPart=\"\";\r\n\r\n if (intPart.length>0) { // has integer part\r\n decpos=intPart.length;\r\n digits=intPart+fracPart;\r\n }\r\n else { // only a fraction\r\n digits=fracPart.replace(/^0+/,\"\"); // remove leading zeros\r\n decpos=digits.length-fracPart.length;\r\n }\r\n }\r\n\r\n if (sizeInBytes-1 < digits.length) return 1; \r\n this.mod.copyString(buffer, sizeInBytes, digits);\r\n this.mod.setLong(dec, decpos);\r\n this.mod.setLong(sign, s);\r\n\r\n return 0;\r\n\r\n /*\r\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\r\n\r\n let decpos=0;\r\n let digits:string;\r\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\r\n \r\n if (decpos>0) { // has integer part\r\n const intlen=Math.max(decpos, 0);\r\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\r\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\r\n }\r\n else { // only a fraction\r\n const intpart=Math.trunc(value);\r\n const fracpart=value-intpart;\r\n const prec=fracpart_numdigits- (-decpos);\r\n console.log(\"prec=\",prec);\r\n if (prec<1) {\r\n digits=\"\";\r\n }\r\n else {\r\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\");\r\n }\r\n }\r\n\r\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\r\n console.log('digits=',digits);\r\n console.log('dec=',decpos);\r\n console.log(\"sign=\",s);\r\n */\r\n\r\n\r\n }\r\n}","import { twrSignal } from \"./twrsignal.js\";\nimport { twrTimeImpl } from \"./twrdate.js\";\n// This class is used in the Main JS thread \nexport class twrWaitingCalls {\n callCompleteSignal;\n parameters;\n constructor() {\n this.callCompleteSignal = new twrSignal();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(() => {\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = twrTimeImpl();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [this.callCompleteSignal.sharedArray, this.parameters.buffer];\n }\n processMessage(msgType, data) {\n switch (msgType) {\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\n// This class is used in the worker thread \nexport class twrWaitingCallsProxy {\n callCompleteSignal;\n parameters;\n constructor(params) {\n this.callCompleteSignal = new twrSignal(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\"sleep\", [ms]]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\"time\"]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n//# sourceMappingURL=twrwaitingcalls.js.map","import { twrSignal } from \"./twrsignal.js\";\r\nimport {twrTimeImpl} from \"./twrdate.js\"\r\n\r\n// These classes are used to proxy a call across the worker thread - main thread boundary and wait for the result\r\n\r\nexport type TWaitingCallsProxyParams = [SharedArrayBuffer, SharedArrayBuffer]; // twrSignal, parameters \r\n\r\n// This class is used in the Main JS thread \r\nexport class twrWaitingCalls {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor() {\r\n\t\tthis.callCompleteSignal=new twrSignal();\r\n\t\tthis.parameters=new Uint32Array(new SharedArrayBuffer(4));\r\n\t}\r\n\r\n\tprivate startSleep(ms:number) {\r\n\r\n\t\tsetTimeout(()=>{\r\n\t\t\tthis.callCompleteSignal.signal();\r\n\t\t}, ms);\r\n\t\t\r\n\t}\r\n\r\n\tprivate time() {\r\n\t\tconst ms=twrTimeImpl();\r\n\t\tthis.parameters[0]=ms;\r\n\t\tthis.callCompleteSignal.signal();\r\n\t}\r\n\r\n\tgetProxyParams():TWaitingCallsProxyParams {\r\n\t\treturn [this.callCompleteSignal.sharedArray, this.parameters.buffer as SharedArrayBuffer];\t\r\n\t}\r\n\r\n\tprocessMessage(msgType:string, data:any[]):boolean {\r\n\t\tswitch (msgType) {\r\n\t\t\tcase \"sleep\":\r\n\t\t\t\tconst [ms] = data;\r\n\t\t\t\tthis.startSleep(ms);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"time\":\r\n\t\t\t\tthis.time();\r\n\t\t\t\tbreak;\r\n\t\t\t\r\n\t\t\tdefault:\r\n\t\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\treturn true;\r\n\t}\r\n\r\n}\r\n\r\n// This class is used in the worker thread \r\nexport class twrWaitingCallsProxy {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor(params:TWaitingCallsProxyParams) {\r\n\t\tthis.callCompleteSignal=new twrSignal(params[0]);\r\n\t\tthis.parameters=new Uint32Array(params[1]);\r\n\t}\r\n\r\n\tsleep(ms:number) {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"sleep\", [ms]]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t}\r\n\r\n\ttime() {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"time\"]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t\treturn this.parameters[0];\r\n\t}\r\n\r\n}\r\n","export function twrTimeImpl() {\n return Date.now();\n}\n//# sourceMappingURL=twrdate.js.map","\r\nexport function twrTimeImpl() {\r\n\r\n return Date.now();\r\n\r\n}"],"names":["$b93f1fdf40141def$var$twrSignalState","$c4741cac81d14197$var$D2DType","twrSignalState","D2DType","$3e39efa823870787$var$mod","$892fccfc812d5e20$export$a01cca24f011573a","sharedArray","buf","constructor","sa","window","crossOriginIsolated","location","protocol","Error","SharedArrayBuffer","Int32Array","write","n","i","Atomics","notify","read","isEmpty","readWait","rdptr","wait","$b93f1fdf40141def$export$e37a7b7b851b97f3","WAITING","signal","SIGNALED","isSignaled","reset","$c4741cac81d14197$export$c779b2cd00544976","canvasKeys","drawCompleteSignal","props","owner","params","signalBuffer","canvasKeysBuffer","charIn","inkey","getProp","pn","propName","getString","drawSeq","ds","postMessage","$8963973702ae5462$export$b377f0bbf2c7581e","divKeys","divKeysBuffer","charOut","ch","$8ac0b786da854328$export$485af4d0039b3389","$e72303a1db04bdfa$export$918ffb7e046a537b","mod","atod","strptr","str","upper","trimStart","toUpperCase","Number","POSITIVE_INFINITY","NEGATIVE_INFINITY","parseFloat","replaceAll","dtoa","buffer","buffer_size","value","max_precision","r","toString","copyString","length","toPrecision","toFixed","decdigits","toExponential","fcvtS","sizeInBytes","fracpart_numdigits","dec","sign","digits","decpos","s","isNaN","slice","isFinite","Math","abs","mem32","intPart","fracPart","roundValStr","split","replace","setLong","$ece7fa3ed770778a$export$c83a0a3bffe07399","memory","mem8","memD","exports","isWorker","isWasmModule","floatUtil","Uint8Array","Uint32Array","Float64Array","loadWasm","pathToLoad","response","fetch","err","console","log","ok","statusText","wasmBytes","arrayBuffer","allimports","modParams","imports","instance","WebAssembly","instantiate","env","ArrayBuffer","malloc","size","Promise","resolve","m","twr_malloc","init","stack","p","stdio","twrInit","twr_wasm_init","callC","cparams","preCallC","retval","callCImpl","postCallC","fname","f","Array","ci","putString","URL","fetchAndPutURL","putArrayBuffer","u8","j","sin","charCodeAt","strIndex","putU8","u8a","dest","ab","fnin","src","getLong","idx","idx32","floor","getDouble","idx64","setDouble","getShort","len","sout","undefined","String","fromCharCode","getU8Arr","rv","dataptr","getU32Arr","$aff9c2c494d23fe3$export$78d2a4633fe89379","callCompleteSignal","parameters","sleep","ms","time","onmessage","e","data","$3e39efa823870787$var$twrWasmModuleInWorker","modWorkerParams","urlToLoad","then","catch","ex","rc","modInWorkerParams","canvasProxy","canvasProxyParams","divProxy","divProxyParams","waitingCallsProxy","waitingCallsProxyParams","twrDebugLog","twrSleep","bind","twrTime","twrDivCharOut","twrDivCharIn","twrCanvasCharIn","twrCanvasInkey","twrCanvasGetProp","twrCanvasDrawSeq","twrSin","twrCos","cos","twrTan","tan","twrFAbs","twrACos","acos","twrASin","asin","twrATan","atan","twrExp","exp","twrFloor","twrCeil","ceil","twrFMod","x","y","twrLog","twrPow","pow","twrSqrt","sqrt","twrTrunc","trunc","twrDtoa","twrToFixed","twrToExponential","twrAtod","twrFcvtS"],"version":3,"file":"twrmodworker.2165e649.js.map"} \ No newline at end of file diff --git a/azure/examples/helloworld/index.html b/azure/examples/helloworld/index.html index 91082df6..3801ba5c 100644 --- a/azure/examples/helloworld/index.html +++ b/azure/examples/helloworld/index.html @@ -22,7 +22,7 @@ const mod = new twrWasmModule(); await mod.loadWasm("./helloworld.wasm"); - await mod.executeC(["hello"]); + await mod.callC(["hello"]); diff --git a/azure/examples/maze/dist/index.html b/azure/examples/maze/dist/index.html index 6508f611..98342376 100644 --- a/azure/examples/maze/dist/index.html +++ b/azure/examples/maze/dist/index.html @@ -5,4 +5,4 @@ "whatkey": "../../lib-js/whatkey.js" } } - \ No newline at end of file + \ No newline at end of file diff --git a/azure/examples/maze/dist/twrmodworker.2165e649.js b/azure/examples/maze/dist/twrmodworker.2165e649.js index 3744680c..d8d07779 100644 --- a/azure/examples/maze/dist/twrmodworker.2165e649.js +++ b/azure/examples/maze/dist/twrmodworker.2165e649.js @@ -1,2 +1,2 @@ -(()=>{var t,e,r,s;let i;class a{sharedArray;buf;constructor(t){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSharedCircularBuffer constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");t?this.sharedArray=t:this.sharedArray=new SharedArrayBuffer(1032),this.buf=new Int32Array(this.sharedArray),this.buf[256]=0,this.buf[257]=0}write(t){let e=this.buf[257];this.buf[e]=t,256==++e&&(e=0),this.buf[257]=e,Atomics.notify(this.buf,257)}read(){if(this.isEmpty())return -1;{let t=this.buf[256],e=this.buf[t];return t++,this.buf[256]=t,e}}readWait(){if(this.isEmpty()){let t=this.buf[256];Atomics.wait(this.buf,257,t)}return this.read()}isEmpty(){return this.buf[256]==this.buf[257]}}(r=t||(t={}))[r.WAITING=0]="WAITING",r[r.SIGNALED=1]="SIGNALED";class o{sharedArray;buf;constructor(e){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSignal constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");e?this.sharedArray=e:this.sharedArray=new SharedArrayBuffer(4),this.buf=new Int32Array(this.sharedArray),this.buf[0]=t.WAITING}signal(){this.buf[0]=t.SIGNALED,Atomics.notify(this.buf,0)}wait(){this.buf[0]==t.WAITING&&Atomics.wait(this.buf,0,t.WAITING)}isSignaled(){return this.buf[0]==t.SIGNALED}reset(){this.buf[0]=t.WAITING}}(s=e||(e={}))[s.D2D_FILLRECT=1]="D2D_FILLRECT",s[s.D2D_FILLCHAR=5]="D2D_FILLCHAR",s[s.D2D_SETLINEWIDTH=10]="D2D_SETLINEWIDTH",s[s.D2D_SETFILLSTYLERGBA=11]="D2D_SETFILLSTYLERGBA",s[s.D2D_SETFONT=12]="D2D_SETFONT",s[s.D2D_BEGINPATH=13]="D2D_BEGINPATH",s[s.D2D_MOVETO=14]="D2D_MOVETO",s[s.D2D_LINETO=15]="D2D_LINETO",s[s.D2D_FILL=16]="D2D_FILL",s[s.D2D_STROKE=17]="D2D_STROKE",s[s.D2D_SETSTROKESTYLERGBA=18]="D2D_SETSTROKESTYLERGBA",s[s.D2D_ARC=19]="D2D_ARC",s[s.D2D_STROKERECT=20]="D2D_STROKERECT",s[s.D2D_FILLTEXT=21]="D2D_FILLTEXT",s[s.D2D_IMAGEDATA=22]="D2D_IMAGEDATA",s[s.D2D_PUTIMAGEDATA=23]="D2D_PUTIMAGEDATA",s[s.D2D_BEZIERTO=24]="D2D_BEZIERTO",s[s.D2D_MEASURETEXT=25]="D2D_MEASURETEXT",s[s.D2D_SAVE=26]="D2D_SAVE",s[s.D2D_RESTORE=27]="D2D_RESTORE",s[s.D2D_CREATERADIALGRADIENT=28]="D2D_CREATERADIALGRADIENT",s[s.D2D_SETCOLORSTOP=29]="D2D_SETCOLORSTOP",s[s.D2D_SETFILLSTYLEGRADIENT=30]="D2D_SETFILLSTYLEGRADIENT",s[s.D2D_RELEASEID=31]="D2D_RELEASEID",s[s.D2D_CREATELINEARGRADIENT=32]="D2D_CREATELINEARGRADIENT",s[s.D2D_SETFILLSTYLE=33]="D2D_SETFILLSTYLE",s[s.D2D_SETSTROKESTYLE=34]="D2D_SETSTROKESTYLE";class n{canvasKeys;drawCompleteSignal;props;owner;constructor(t,e){let[r,s,i]=t;this.drawCompleteSignal=new o(s),this.canvasKeys=new a(i),this.props=r,this.owner=e}charIn(){return this.canvasKeys.readWait()}inkey(){return this.canvasKeys.isEmpty()?0:this.charIn()}getProp(t){let e=this.owner.getString(t);return this.props[e]}drawSeq(t){this.drawCompleteSignal.reset(),postMessage(["drawseq",[t]]),this.drawCompleteSignal.wait()}}class l{divKeys;constructor(t){let[e]=t;this.divKeys=new a(e)}charIn(){return this.divKeys.readWait()}inkey(){return this.divKeys.isEmpty()?0:this.charIn()}charOut(t){postMessage(["divout",t])}}function h(t){postMessage(["debug",t])}class m{mod;constructor(t){this.mod=t}atod(t){let e=this.mod.getString(t),r=e.trimStart().toUpperCase();return"INF"==r||"+INF"==r?Number.POSITIVE_INFINITY:"-INF"==r?Number.NEGATIVE_INFINITY:Number.parseFloat(e.replaceAll("D","e").replaceAll("d","e"))}dtoa(t,e,r,s){if(-1==s){let s=r.toString();this.mod.copyString(t,e,s)}else{let i=r.toString();i.length>s&&(i=r.toPrecision(s)),this.mod.copyString(t,e,i)}}toFixed(t,e,r,s){let i=r.toFixed(s);this.mod.copyString(t,e,i)}toExponential(t,e,r,s){let i=r.toExponential(s);this.mod.copyString(t,e,i)}fcvtS(t,e,r,s,i,a){let o,n;if(0==t||0==a||0==i||e<1)return 1;let l=0;if(Number.isNaN(r))o="1#QNAN00000000000000000000000000000".slice(0,s+1),n=1;else if(Number.isFinite(r)){if(0==r)o="000000000000000000000000000000000000".slice(0,s),n=0;else{if(r<0&&(l=1,r=Math.abs(r)),s>100||r>1e21||r<1e-99)return this.mod.copyString(t,e,""),this.mod.mem32[i]=0,1;let[a="",h=""]=r.toFixed(s).split(".");"0"==a&&(a=""),a.length>0?(n=a.length,o=a+h):n=(o=h.replace(/^0+/,"")).length-h.length}}else o="1#INF00000000000000000000000000000".slice(0,s+1),n=1;return e-1new Promise(e=>{let r=this.exports.twr_malloc;e(r(t))}),this.init()}catch(t){throw console.log("WASM instantiate error: "+t+(t.stack?"\n"+t.stack:"")),t}}init(){let t;switch(this.modParams.stdio){case"debug":default:t=0;break;case"div":t=1;break;case"canvas":t=2;break;case"null":t=3}(0,this.exports.twr_wasm_init)(t,this.mem8.length)}async executeC(t){let e=await this.preCallC(t),r=this.executeCImpl(t[0],e);return this.postCallC(e,t),r}async executeCImpl(t,e=[]){if(!this.exports)throw Error("this.exports undefined");if(!this.exports[t])throw Error("executeC: function '"+t+"' not in export table. Use --export wasm-ld flag.");return(0,this.exports[t])(...e)}async preCallC(t){if(t.constructor!==Array)throw Error("executeC: params must be array, first arg is function name");if(0==t.length)throw Error("executeC: missing function name");let e=[],r=0;for(let s=1;s=this.mem32.length)throw Error("invalid index passed to getLong: "+t+", this.mem32.length: "+this.mem32.length);return this.mem32[e]}setLong(t,e){let r=Math.floor(t/4);if(4*r!=t)throw Error("setLong passed non long aligned address");if(r<0||r>=this.mem32.length)throw Error("invalid index passed to setLong: "+t+", this.mem32.length: "+this.mem32.length);this.mem32[r]=e}getDouble(t){let e=Math.floor(t/8);if(8*e!=t)throw Error("getLong passed non Float64 aligned address");return this.memD[e]}setDouble(t,e){let r=Math.floor(t/8);if(8*r!=t)throw Error("setDouble passed non Float64 aligned address");this.memD[r]=e}getShort(t){if(t<0||t>=this.mem8.length)throw Error("invalid index passed to getShort: "+t);return this.mem8[t]+256*this.mem8[t+1]}getString(t,e){let r="",s=0;for(;this.mem8[t+s]&&(void 0===e||s=this.mem8.length)throw Error("invalid index passed to getU8: "+t);let e=new Uint32Array(this.mem8.slice(t,t+8).buffer),r=e[0],s=e[1];if(s<0||s>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU8");if(r<0||r>this.mem8.length-s)throw Error("invalid idx.size passed to getU8");return this.mem8.slice(s,s+r)}getU32Arr(t){if(t<0||t>=this.mem8.length)throw Error("invalid index passed to getU32: "+t);let e=new Uint32Array(this.mem8.slice(t,t+8).buffer),r=e[0],s=e[1];if(s<0||s>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU32");if(r<0||r>this.mem8.length-s)throw Error("invalid idx.size passed to getU32");if(r%4!=0)throw Error("idx.size is not an integer number of 32 bit words");return new Uint32Array(this.mem8.slice(s,s+r).buffer)}}class d{callCompleteSignal;parameters;constructor(t){this.callCompleteSignal=new o(t[0]),this.parameters=new Uint32Array(t[1])}sleep(t){this.callCompleteSignal.reset(),postMessage(["sleep",[t]]),this.callCompleteSignal.wait()}time(){return this.callCompleteSignal.reset(),postMessage(["time"]),this.callCompleteSignal.wait(),this.parameters[0]}}onmessage=function(t){if("startup"==t.data[0]){let e=t.data[1];(i=new f(e.modParams,e.modWorkerParams)).loadWasm(e.urlToLoad).then(()=>{postMessage(["startupOkay"])}).catch(t=>{console.log(".catch: ",t),postMessage(["startupFail",t])})}else"executeC"==t.data[0]?i.executeCImpl(t.data[1],t.data[2]).then(t=>{postMessage(["executeCOkay",t])}).catch(t=>{console.log("exception in executeC twrworker.js\n"),console.log(t),postMessage(["executeCFail",t])}):console.log("twrworker.js: unknown message: "+t)};class f extends c{malloc;modParams;constructor(t,e){super(),this.isWorker=!0,this.malloc=t=>{throw Error("error - un-init malloc called")},this.modParams=t;let r=new n(e.canvasProxyParams,this),s=new l(e.divProxyParams),i=new d(e.waitingCallsProxyParams);this.modParams.imports={twrDebugLog:h,twrSleep:i.sleep.bind(i),twrTime:i.time.bind(i),twrDivCharOut:s.charOut.bind(s),twrDivCharIn:s.charIn.bind(s),twrCanvasCharIn:r.charIn.bind(r),twrCanvasInkey:r.inkey.bind(r),twrCanvasGetProp:r.getProp.bind(r),twrCanvasDrawSeq:r.drawSeq.bind(r),twrSin:Math.sin,twrCos:Math.cos,twrTan:Math.tan,twrFAbs:Math.abs,twrACos:Math.acos,twrASin:Math.asin,twrATan:Math.atan,twrExp:Math.exp,twrFloor:Math.floor,twrCeil:Math.ceil,twrFMod:function(t,e){return t%e},twrLog:Math.log,twrPow:Math.pow,twrSqrt:Math.sqrt,twrTrunc:Math.trunc,twrDtoa:this.floatUtil.dtoa.bind(this.floatUtil),twrToFixed:this.floatUtil.toFixed.bind(this.floatUtil),twrToExponential:this.floatUtil.toExponential.bind(this.floatUtil),twrAtod:this.floatUtil.atod.bind(this.floatUtil),twrFcvtS:this.floatUtil.fcvtS.bind(this.floatUtil)}}}})(); +(()=>{var t,e,r,s;let i;class a{sharedArray;buf;constructor(t){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSharedCircularBuffer constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");t?this.sharedArray=t:this.sharedArray=new SharedArrayBuffer(1032),this.buf=new Int32Array(this.sharedArray),this.buf[256]=0,this.buf[257]=0}write(t){let e=this.buf[257];this.buf[e]=t,256==++e&&(e=0),this.buf[257]=e,Atomics.notify(this.buf,257)}read(){if(this.isEmpty())return -1;{let t=this.buf[256],e=this.buf[t];return t++,this.buf[256]=t,e}}readWait(){if(this.isEmpty()){let t=this.buf[256];Atomics.wait(this.buf,257,t)}return this.read()}isEmpty(){return this.buf[256]==this.buf[257]}}(r=t||(t={}))[r.WAITING=0]="WAITING",r[r.SIGNALED=1]="SIGNALED";class o{sharedArray;buf;constructor(e){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSignal constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");e?this.sharedArray=e:this.sharedArray=new SharedArrayBuffer(4),this.buf=new Int32Array(this.sharedArray),this.buf[0]=t.WAITING}signal(){this.buf[0]=t.SIGNALED,Atomics.notify(this.buf,0)}wait(){this.buf[0]==t.WAITING&&Atomics.wait(this.buf,0,t.WAITING)}isSignaled(){return this.buf[0]==t.SIGNALED}reset(){this.buf[0]=t.WAITING}}(s=e||(e={}))[s.D2D_FILLRECT=1]="D2D_FILLRECT",s[s.D2D_FILLCHAR=5]="D2D_FILLCHAR",s[s.D2D_SETLINEWIDTH=10]="D2D_SETLINEWIDTH",s[s.D2D_SETFILLSTYLERGBA=11]="D2D_SETFILLSTYLERGBA",s[s.D2D_SETFONT=12]="D2D_SETFONT",s[s.D2D_BEGINPATH=13]="D2D_BEGINPATH",s[s.D2D_MOVETO=14]="D2D_MOVETO",s[s.D2D_LINETO=15]="D2D_LINETO",s[s.D2D_FILL=16]="D2D_FILL",s[s.D2D_STROKE=17]="D2D_STROKE",s[s.D2D_SETSTROKESTYLERGBA=18]="D2D_SETSTROKESTYLERGBA",s[s.D2D_ARC=19]="D2D_ARC",s[s.D2D_STROKERECT=20]="D2D_STROKERECT",s[s.D2D_FILLTEXT=21]="D2D_FILLTEXT",s[s.D2D_IMAGEDATA=22]="D2D_IMAGEDATA",s[s.D2D_PUTIMAGEDATA=23]="D2D_PUTIMAGEDATA",s[s.D2D_BEZIERTO=24]="D2D_BEZIERTO",s[s.D2D_MEASURETEXT=25]="D2D_MEASURETEXT",s[s.D2D_SAVE=26]="D2D_SAVE",s[s.D2D_RESTORE=27]="D2D_RESTORE",s[s.D2D_CREATERADIALGRADIENT=28]="D2D_CREATERADIALGRADIENT",s[s.D2D_SETCOLORSTOP=29]="D2D_SETCOLORSTOP",s[s.D2D_SETFILLSTYLEGRADIENT=30]="D2D_SETFILLSTYLEGRADIENT",s[s.D2D_RELEASEID=31]="D2D_RELEASEID",s[s.D2D_CREATELINEARGRADIENT=32]="D2D_CREATELINEARGRADIENT",s[s.D2D_SETFILLSTYLE=33]="D2D_SETFILLSTYLE",s[s.D2D_SETSTROKESTYLE=34]="D2D_SETSTROKESTYLE";class n{canvasKeys;drawCompleteSignal;props;owner;constructor(t,e){let[r,s,i]=t;this.drawCompleteSignal=new o(s),this.canvasKeys=new a(i),this.props=r,this.owner=e}charIn(){return this.canvasKeys.readWait()}inkey(){return this.canvasKeys.isEmpty()?0:this.charIn()}getProp(t){let e=this.owner.getString(t);return this.props[e]}drawSeq(t){this.drawCompleteSignal.reset(),postMessage(["drawseq",[t]]),this.drawCompleteSignal.wait()}}class l{divKeys;constructor(t){let[e]=t;this.divKeys=new a(e)}charIn(){return this.divKeys.readWait()}inkey(){return this.divKeys.isEmpty()?0:this.charIn()}charOut(t){postMessage(["divout",t])}}function h(t){postMessage(["debug",t])}class m{mod;constructor(t){this.mod=t}atod(t){let e=this.mod.getString(t),r=e.trimStart().toUpperCase();return"INF"==r||"+INF"==r?Number.POSITIVE_INFINITY:"-INF"==r?Number.NEGATIVE_INFINITY:Number.parseFloat(e.replaceAll("D","e").replaceAll("d","e"))}dtoa(t,e,r,s){if(-1==s){let s=r.toString();this.mod.copyString(t,e,s)}else{let i=r.toString();i.length>s&&(i=r.toPrecision(s)),this.mod.copyString(t,e,i)}}toFixed(t,e,r,s){let i=r.toFixed(s);this.mod.copyString(t,e,i)}toExponential(t,e,r,s){let i=r.toExponential(s);this.mod.copyString(t,e,i)}fcvtS(t,e,r,s,i,a){let o,n;if(0==t||0==a||0==i||e<1)return 1;let l=0;if(Number.isNaN(r))o="1#QNAN00000000000000000000000000000".slice(0,s+1),n=1;else if(Number.isFinite(r)){if(0==r)o="000000000000000000000000000000000000".slice(0,s),n=0;else{if(r<0&&(l=1,r=Math.abs(r)),s>100||r>1e21||r<1e-99)return this.mod.copyString(t,e,""),this.mod.mem32[i]=0,1;let[a="",h=""]=r.toFixed(s).split(".");"0"==a&&(a=""),a.length>0?(n=a.length,o=a+h):n=(o=h.replace(/^0+/,"")).length-h.length}}else o="1#INF00000000000000000000000000000".slice(0,s+1),n=1;return e-1new Promise(e=>{let r=this.exports.twr_malloc;e(r(t))}),this.init()}catch(t){throw console.log("WASM instantiate error: "+t+(t.stack?"\n"+t.stack:"")),t}}init(){let t;switch(this.modParams.stdio){case"debug":default:t=0;break;case"div":t=1;break;case"canvas":t=2;break;case"null":t=3}(0,this.exports.twr_wasm_init)(t,this.mem8.length)}async callC(t){let e=await this.preCallC(t),r=this.callCImpl(t[0],e);return this.postCallC(e,t),r}async callCImpl(t,e=[]){if(!this.exports)throw Error("this.exports undefined");if(!this.exports[t])throw Error("callC: function '"+t+"' not in export table. Use --export wasm-ld flag.");return(0,this.exports[t])(...e)}async preCallC(t){if(t.constructor!==Array)throw Error("callC: params must be array, first arg is function name");if(0==t.length)throw Error("callC: missing function name");let e=[],r=0;for(let s=1;s=this.mem32.length)throw Error("invalid index passed to getLong: "+t+", this.mem32.length: "+this.mem32.length);return this.mem32[e]}setLong(t,e){let r=Math.floor(t/4);if(4*r!=t)throw Error("setLong passed non long aligned address");if(r<0||r>=this.mem32.length)throw Error("invalid index passed to setLong: "+t+", this.mem32.length: "+this.mem32.length);this.mem32[r]=e}getDouble(t){let e=Math.floor(t/8);if(8*e!=t)throw Error("getLong passed non Float64 aligned address");return this.memD[e]}setDouble(t,e){let r=Math.floor(t/8);if(8*r!=t)throw Error("setDouble passed non Float64 aligned address");this.memD[r]=e}getShort(t){if(t<0||t>=this.mem8.length)throw Error("invalid index passed to getShort: "+t);return this.mem8[t]+256*this.mem8[t+1]}getString(t,e){let r="",s=0;for(;this.mem8[t+s]&&(void 0===e||s=this.mem8.length)throw Error("invalid index passed to getU8: "+t);let e=new Uint32Array(this.mem8.slice(t,t+8).buffer),r=e[0],s=e[1];if(s<0||s>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU8");if(r<0||r>this.mem8.length-s)throw Error("invalid idx.size passed to getU8");return this.mem8.slice(s,s+r)}getU32Arr(t){if(t<0||t>=this.mem8.length)throw Error("invalid index passed to getU32: "+t);let e=new Uint32Array(this.mem8.slice(t,t+8).buffer),r=e[0],s=e[1];if(s<0||s>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU32");if(r<0||r>this.mem8.length-s)throw Error("invalid idx.size passed to getU32");if(r%4!=0)throw Error("idx.size is not an integer number of 32 bit words");return new Uint32Array(this.mem8.slice(s,s+r).buffer)}}class d{callCompleteSignal;parameters;constructor(t){this.callCompleteSignal=new o(t[0]),this.parameters=new Uint32Array(t[1])}sleep(t){this.callCompleteSignal.reset(),postMessage(["sleep",[t]]),this.callCompleteSignal.wait()}time(){return this.callCompleteSignal.reset(),postMessage(["time"]),this.callCompleteSignal.wait(),this.parameters[0]}}onmessage=function(t){if("startup"==t.data[0]){let e=t.data[1];(i=new f(e.modParams,e.modWorkerParams)).loadWasm(e.urlToLoad).then(()=>{postMessage(["startupOkay"])}).catch(t=>{console.log(".catch: ",t),postMessage(["startupFail",t])})}else"callC"==t.data[0]?i.callCImpl(t.data[1],t.data[2]).then(t=>{postMessage(["callCOkay",t])}).catch(t=>{console.log("exception in callC twrworker.js\n"),console.log(t),postMessage(["callCFail",t])}):console.log("twrworker.js: unknown message: "+t)};class f extends c{malloc;modParams;constructor(t,e){super(),this.isWorker=!0,this.malloc=t=>{throw Error("error - un-init malloc called")},this.modParams=t;let r=new n(e.canvasProxyParams,this),s=new l(e.divProxyParams),i=new d(e.waitingCallsProxyParams);this.modParams.imports={twrDebugLog:h,twrSleep:i.sleep.bind(i),twrTime:i.time.bind(i),twrDivCharOut:s.charOut.bind(s),twrDivCharIn:s.charIn.bind(s),twrCanvasCharIn:r.charIn.bind(r),twrCanvasInkey:r.inkey.bind(r),twrCanvasGetProp:r.getProp.bind(r),twrCanvasDrawSeq:r.drawSeq.bind(r),twrSin:Math.sin,twrCos:Math.cos,twrTan:Math.tan,twrFAbs:Math.abs,twrACos:Math.acos,twrASin:Math.asin,twrATan:Math.atan,twrExp:Math.exp,twrFloor:Math.floor,twrCeil:Math.ceil,twrFMod:function(t,e){return t%e},twrLog:Math.log,twrPow:Math.pow,twrSqrt:Math.sqrt,twrTrunc:Math.trunc,twrDtoa:this.floatUtil.dtoa.bind(this.floatUtil),twrToFixed:this.floatUtil.toFixed.bind(this.floatUtil),twrToExponential:this.floatUtil.toExponential.bind(this.floatUtil),twrAtod:this.floatUtil.atod.bind(this.floatUtil),twrFcvtS:this.floatUtil.fcvtS.bind(this.floatUtil)}}}})(); //# sourceMappingURL=twrmodworker.2165e649.js.map diff --git a/azure/examples/maze/dist/twrmodworker.2165e649.js.map b/azure/examples/maze/dist/twrmodworker.2165e649.js.map index 29a4d41e..77745e98 100644 --- a/azure/examples/maze/dist/twrmodworker.2165e649.js.map +++ b/azure/examples/maze/dist/twrmodworker.2165e649.js.map @@ -1 +1 @@ -{"mappings":"A,C,SQKK,EJgBA,EIhBA,EJgBA,MFZD,CISE,OAAO,EACZ,WAA8B,AAC9B,CAAA,GAAe,AAEf,aAAa,CAAqB,CAAlC,CACO,GAAI,AAAkB,aAAlB,OAAO,QACH,CAAC,qBAAuB,AAA+B,UAA7B,OAA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K,GAAG,CAChB,OAAQ,KAAK,GAAG,CAChB,QAAS,KAAK,IAAI,CAClB,SAAU,KAAK,KAAK,CAEX,QAAS,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EACzD,WAAY,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EACtD,iBAAkB,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAClE,QAAS,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAChD,SAAU,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAE5C,CACN,CACF,C,C","sources":["","../../lib-js/twrmodworker.js","../../source/twr-wasm-ts/twrmodworker.ts","../../lib-js/twrcanvas.js","../../source/twr-wasm-ts/twrcanvas.ts","../../lib-js/twrcircular.js","../../source/twr-wasm-ts/twrcircular.ts","../../lib-js/twrsignal.js","../../source/twr-wasm-ts/twrsignal.ts","../../lib-js/twrdiv.js","../../source/twr-wasm-ts/twrdiv.ts","../../lib-js/twrdebug.js","../../source/twr-wasm-ts/twrdebug.ts","../../lib-js/twrmodbase.js","../../source/twr-wasm-ts/twrmodbase.ts","../../lib-js/twrfloat.js","../../source/twr-wasm-ts/twrfloat.ts","../../lib-js/twrwaitingcalls.js","../../source/twr-wasm-ts/twrwaitingcalls.ts","../../lib-js/twrdate.js","../../source/twr-wasm-ts/twrdate.ts"],"sourcesContent":["(() => {\nvar $3e39efa823870787$exports = {};\n// this script is the WebWorker thead used by class twrWasmAsyncModule\n//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst $892fccfc812d5e20$var$RDIDX = 256;\nconst $892fccfc812d5e20$var$WRIDX = 257;\nconst $892fccfc812d5e20$var$LEN = 256;\nclass $892fccfc812d5e20$export$a01cca24f011573a {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(1032);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[$892fccfc812d5e20$var$RDIDX] = 0;\n this.buf[$892fccfc812d5e20$var$WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[$892fccfc812d5e20$var$WRIDX];\n this.buf[i] = n;\n i++;\n if (i == $892fccfc812d5e20$var$LEN) i = 0;\n this.buf[$892fccfc812d5e20$var$WRIDX] = i;\n Atomics.notify(this.buf, $892fccfc812d5e20$var$WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[$892fccfc812d5e20$var$RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[$892fccfc812d5e20$var$RDIDX] = i;\n return n;\n } else return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[$892fccfc812d5e20$var$RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, $892fccfc812d5e20$var$WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[$892fccfc812d5e20$var$RDIDX] == this.buf[$892fccfc812d5e20$var$WRIDX];\n }\n}\n\n\n//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar $b93f1fdf40141def$var$twrSignalState;\n(function(twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})($b93f1fdf40141def$var$twrSignalState || ($b93f1fdf40141def$var$twrSignalState = {}));\nclass $b93f1fdf40141def$export$e37a7b7b851b97f3 {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == $b93f1fdf40141def$var$twrSignalState.WAITING) //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, $b93f1fdf40141def$var$twrSignalState.WAITING);\n }\n isSignaled() {\n return this.buf[0] == $b93f1fdf40141def$var$twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.WAITING;\n }\n}\n\n\nvar $c4741cac81d14197$var$D2DType;\n(function(D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})($c4741cac81d14197$var$D2DType || ($c4741cac81d14197$var$D2DType = {}));\nclass $c4741cac81d14197$export$2f298dd69cef3c34 {\n ctx;\n props = {\n charWidth: 0,\n charHeight: 0,\n foreColor: 0,\n backColor: 0,\n widthInChars: 0,\n heightInChars: 0,\n canvasHeight: 0,\n canvasWidth: 0\n };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase){\n const { forecolor: forecolor, backcolor: backcolor, fontsize: fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)();\n this.canvasKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.props,\n this.cmdCompleteSignal.sharedArray,\n this.canvasKeys.sharedArray\n ];\n }\n getProp(pn) {\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */ drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx) return;\n let ins = this.owner.getLong(ds); /* ds->start */ \n const lastins = this.owner.getLong(ds + 4); /* ds->last */ \n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while(true){\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */ \n switch(type){\n case $c4741cac81d14197$var$D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_BEGINPATH:\n this.ctx.beginPath();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILL:\n this.ctx.fill();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SAVE:\n this.ctx.save();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_RESTORE:\n this.ctx.restore();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_STROKE:\n this.ctx.stroke();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = this.owner.getLong(ins + 48) != 0;\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n } else this.precomputedObjects[id] = {\n mem8: new Uint8Array(this.owner.memory.buffer, start, length),\n width: width,\n height: height\n };\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id]) delete this.precomputedObjects[id];\n else console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n else {\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) this.ctx.putImageData(imgData, dx, dy);\n else this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */ \n if (next == 0) {\n if (ins != lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nclass $c4741cac81d14197$export$c779b2cd00544976 {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner){\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)(signalBuffer);\n this.canvasKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\n \"drawseq\",\n [\n ds\n ]\n ]);\n this.drawCompleteSignal.wait();\n }\n}\n\n\n\nclass $8963973702ae5462$export$dd376bb3f10f6896 {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611);\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase){\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) this.divKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(); // tsconfig, lib must be set to 2017 or higher\n if (this.div && !modParams.styleIsDefault) {\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.divKeys.sharedArray\n ];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */ charOut(ch) {\n if (!this.div) return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n }\n switch(ch){\n case 10:\n case 13:\n if (ch == 10 && this.lastChar == 13) break; // detect CR LF and treat as single new line\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n case 0xE:\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF:\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for(let i = 0; i < str.length; i++)this.charOut(str.charCodeAt(i));\n }\n}\nclass $8963973702ae5462$export$b377f0bbf2c7581e {\n divKeys;\n constructor(params){\n const [divKeysBuffer] = params;\n this.divKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n charOut(ch) {\n postMessage([\n \"divout\",\n ch\n ]);\n }\n}\n\n\nlet $8ac0b786da854328$var$logline = \"\";\nfunction $8ac0b786da854328$export$16b4216ec014493d(char) {\n if (char == 10 || char == 3) {\n console.log($8ac0b786da854328$var$logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n $8ac0b786da854328$var$logline = \"\";\n } else {\n $8ac0b786da854328$var$logline = $8ac0b786da854328$var$logline + String.fromCharCode(char);\n if ($8ac0b786da854328$var$logline.length >= 200) {\n console.log($8ac0b786da854328$var$logline);\n $8ac0b786da854328$var$logline = \"\";\n }\n }\n}\nfunction $8ac0b786da854328$export$485af4d0039b3389(ch) {\n postMessage([\n \"debug\",\n ch\n ]);\n}\n\n\nclass $e72303a1db04bdfa$export$918ffb7e046a537b {\n mod;\n constructor(mod){\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\") return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\") return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll(\"D\", \"e\").replaceAll(\"d\", \"e\"));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n } else {\n let r = value.toString();\n if (r.length > max_precision) r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, sizeInBytes, value, fracpart_numdigits, dec, sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1) return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) {\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (!Number.isFinite(value)) {\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n } else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split(\".\");\n if (intPart == \"0\") intPart = \"\";\n if (intPart.length > 0) {\n decpos = intPart.length;\n digits = intPart + fracPart;\n } else {\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length) return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */ }\n}\n\n\nclass $ece7fa3ed770778a$export$c83a0a3bffe07399 {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule;\n floatUtil;\n constructor(isWasmModule = false){\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new (0, $e72303a1db04bdfa$export$918ffb7e046a537b)(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/ /*********************************************************************/ async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n } catch (err) {\n console.log(\"loadWasm() failed to fetch: \" + pathToLoad);\n throw err;\n }\n if (!response.ok) throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, {\n env: allimports\n });\n this.exports = instance.instance.exports;\n if (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory) throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer) console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\n \"setmemory\",\n this.memory\n ]);\n }\n if (this.isWasmModule) // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n {\n if (!(this.memory.buffer instanceof ArrayBuffer)) console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size)=>{\n return new Promise((resolve)=>{\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n } catch (err) {\n console.log(\"WASM instantiate error: \" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch(this.modParams.stdio){\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* executeC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */ async executeC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.executeCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async executeCImpl(fname, cparams = []) {\n if (!this.exports) throw new Error(\"this.exports undefined\");\n if (!this.exports[fname]) throw new Error(\"executeC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array)) throw new Error(\"executeC: params must be array, first arg is function name\");\n if (params.length == 0) throw new Error(\"executeC: missing function name\");\n let cparams = [];\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n cparams[ci++] = p;\n break;\n case \"string\":\n cparams[ci++] = await this.putString(p);\n break;\n case \"object\":\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n } else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"executeC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n ci++;\n break;\n case \"string\":\n this.executeCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n case \"object\":\n if (p instanceof URL) {\n this.executeCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci = ci + 2;\n break;\n } else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for(let j = 0; j < u8.length; j++)u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.executeCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n } else throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/ /*********************************************************************/ // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for(i = 0; i < sin.length && i < buffer_size - 1; i++)this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for(let i = 0; i < u8a.length; i++)this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === \"object\" && fnin instanceof URL)) throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [\n dest,\n src.length\n ];\n } catch (err) {\n console.log(\"fetchAndPutURL Error. URL: \" + fnin + \"\\n\" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while(this.mem8[strIndex + i] && (len === undefined ? true : i < len) && strIndex + i < this.mem8.length){\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array(this.mem8.slice(dataptr, dataptr + size).buffer);\n return u32;\n }\n}\n\n\n\nfunction $4af5689abbc8d01b$export$78724cdcf7ebea1d() {\n return Date.now();\n}\n\n\nclass $aff9c2c494d23fe3$export$9e37856d1928d388 {\n callCompleteSignal;\n parameters;\n constructor(){\n this.callCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(()=>{\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = (0, $4af5689abbc8d01b$export$78724cdcf7ebea1d)();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [\n this.callCompleteSignal.sharedArray,\n this.parameters.buffer\n ];\n }\n processMessage(msgType, data) {\n switch(msgType){\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\nclass $aff9c2c494d23fe3$export$78d2a4633fe89379 {\n callCompleteSignal;\n parameters;\n constructor(params){\n this.callCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\n \"sleep\",\n [\n ms\n ]\n ]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\n \"time\"\n ]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n\n\nlet $3e39efa823870787$var$mod;\nonmessage = function(e) {\n //console.log('twrworker.js: message received from main script: '+e.data);\n if (e.data[0] == \"startup\") {\n const params = e.data[1];\n //console.log(\"Worker startup params:\",params);\n $3e39efa823870787$var$mod = new $3e39efa823870787$var$twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\n $3e39efa823870787$var$mod.loadWasm(params.urlToLoad).then(()=>{\n postMessage([\n \"startupOkay\"\n ]);\n }).catch((ex)=>{\n console.log(\".catch: \", ex);\n postMessage([\n \"startupFail\",\n ex\n ]);\n });\n } else if (e.data[0] == \"executeC\") $3e39efa823870787$var$mod.executeCImpl(e.data[1], e.data[2]).then((rc)=>{\n postMessage([\n \"executeCOkay\",\n rc\n ]);\n }).catch((e)=>{\n console.log(\"exception in executeC twrworker.js\\n\");\n console.log(e);\n postMessage([\n \"executeCFail\",\n e\n ]);\n });\n else console.log(\"twrworker.js: unknown message: \" + e);\n};\n// ************************************************************************\nclass $3e39efa823870787$var$twrWasmModuleInWorker extends (0, $ece7fa3ed770778a$export$c83a0a3bffe07399) {\n malloc;\n modParams;\n constructor(modParams, modInWorkerParams){\n super();\n this.isWorker = true;\n this.malloc = (size)=>{\n throw new Error(\"error - un-init malloc called\");\n };\n this.modParams = modParams;\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\n const canvasProxy = new (0, $c4741cac81d14197$export$c779b2cd00544976)(modInWorkerParams.canvasProxyParams, this);\n const divProxy = new (0, $8963973702ae5462$export$b377f0bbf2c7581e)(modInWorkerParams.divProxyParams);\n const waitingCallsProxy = new (0, $aff9c2c494d23fe3$export$78d2a4633fe89379)(modInWorkerParams.waitingCallsProxyParams);\n this.modParams.imports = {\n twrDebugLog: (0, $8ac0b786da854328$export$485af4d0039b3389),\n twrSleep: waitingCallsProxy.sleep.bind(waitingCallsProxy),\n twrTime: waitingCallsProxy.time.bind(waitingCallsProxy),\n twrDivCharOut: divProxy.charOut.bind(divProxy),\n twrDivCharIn: divProxy.charIn.bind(divProxy),\n twrCanvasCharIn: canvasProxy.charIn.bind(canvasProxy),\n twrCanvasInkey: canvasProxy.inkey.bind(canvasProxy),\n twrCanvasGetProp: canvasProxy.getProp.bind(canvasProxy),\n twrCanvasDrawSeq: canvasProxy.drawSeq.bind(canvasProxy),\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function(x, y) {\n return x % y;\n },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n}\n\n})();\n//# sourceMappingURL=twrmodworker.2165e649.js.map\n","// this script is the WebWorker thead used by class twrWasmAsyncModule\nimport { twrCanvasProxy } from \"./twrcanvas.js\";\nimport { twrDivProxy } from \"./twrdiv.js\";\nimport { twrDebugLogProxy } from \"./twrdebug.js\";\nimport { twrWasmModuleBase } from \"./twrmodbase.js\";\nimport { twrWaitingCallsProxy } from \"./twrwaitingcalls.js\";\nlet mod;\nonmessage = function (e) {\n //console.log('twrworker.js: message received from main script: '+e.data);\n if (e.data[0] == 'startup') {\n const params = e.data[1];\n //console.log(\"Worker startup params:\",params);\n mod = new twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\n mod.loadWasm(params.urlToLoad).then(() => {\n postMessage([\"startupOkay\"]);\n }).catch((ex) => {\n console.log(\".catch: \", ex);\n postMessage([\"startupFail\", ex]);\n });\n }\n else if (e.data[0] == 'executeC') {\n mod.executeCImpl(e.data[1], e.data[2]).then((rc) => {\n postMessage([\"executeCOkay\", rc]);\n }).catch(e => {\n console.log(\"exception in executeC twrworker.js\\n\");\n console.log(e);\n postMessage([\"executeCFail\", e]);\n });\n }\n else {\n console.log(\"twrworker.js: unknown message: \" + e);\n }\n};\n// ************************************************************************\nclass twrWasmModuleInWorker extends twrWasmModuleBase {\n malloc;\n modParams;\n constructor(modParams, modInWorkerParams) {\n super();\n this.isWorker = true;\n this.malloc = (size) => { throw new Error(\"error - un-init malloc called\"); };\n this.modParams = modParams;\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\n const canvasProxy = new twrCanvasProxy(modInWorkerParams.canvasProxyParams, this);\n const divProxy = new twrDivProxy(modInWorkerParams.divProxyParams);\n const waitingCallsProxy = new twrWaitingCallsProxy(modInWorkerParams.waitingCallsProxyParams);\n this.modParams.imports = {\n twrDebugLog: twrDebugLogProxy,\n twrSleep: waitingCallsProxy.sleep.bind(waitingCallsProxy),\n twrTime: waitingCallsProxy.time.bind(waitingCallsProxy),\n twrDivCharOut: divProxy.charOut.bind(divProxy),\n twrDivCharIn: divProxy.charIn.bind(divProxy),\n twrCanvasCharIn: canvasProxy.charIn.bind(canvasProxy),\n twrCanvasInkey: canvasProxy.inkey.bind(canvasProxy),\n twrCanvasGetProp: canvasProxy.getProp.bind(canvasProxy),\n twrCanvasDrawSeq: canvasProxy.drawSeq.bind(canvasProxy),\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function (x, y) { return x % y; },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n}\n//# sourceMappingURL=twrmodworker.js.map","// this script is the WebWorker thead used by class twrWasmAsyncModule\r\n\r\nimport {twrCanvasProxy} from \"./twrcanvas.js\";\r\nimport {twrDivProxy} from \"./twrdiv.js\";\r\nimport {twrDebugLogProxy} from \"./twrdebug.js\";\r\nimport {TAsyncModStartupMsg} from \"./twrmodasync.js\"\r\nimport {twrWasmModuleBase, IModInWorkerParams, IModParams} from \"./twrmodbase.js\"\r\nimport {twrWaitingCallsProxy} from \"./twrwaitingcalls.js\";\r\n\r\nlet mod:twrWasmModuleInWorker;\r\n\r\nonmessage = function(e) {\r\n //console.log('twrworker.js: message received from main script: '+e.data);\r\n\r\n if (e.data[0]=='startup') {\r\n const params:TAsyncModStartupMsg=e.data[1];\r\n //console.log(\"Worker startup params:\",params);\r\n mod=new twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\r\n\r\n mod.loadWasm(params.urlToLoad).then( ()=> {\r\n postMessage([\"startupOkay\"]);\r\n }).catch( (ex)=> {\r\n console.log(\".catch: \", ex);\r\n postMessage([\"startupFail\", ex]);\r\n });\r\n }\r\n else if (e.data[0]=='executeC') {\r\n mod.executeCImpl(e.data[1], e.data[2]).then( (rc)=> {\r\n postMessage([\"executeCOkay\", rc]);\r\n }).catch(e => {\r\n console.log(\"exception in executeC twrworker.js\\n\");\r\n console.log(e);\r\n postMessage([\"executeCFail\", e]);\r\n });\r\n }\r\n else {\r\n console.log(\"twrworker.js: unknown message: \"+e);\r\n }\r\n}\r\n\r\n\r\n// ************************************************************************\r\n\r\nclass twrWasmModuleInWorker extends twrWasmModuleBase {\r\n\tmalloc:(size:number)=>Promise;\r\n modParams: IModParams;\r\n\r\n\r\n constructor(modParams:IModParams, modInWorkerParams:IModInWorkerParams) {\r\n super();\r\n this.isWorker=true;\r\n this.malloc=(size:number)=>{throw new Error(\"error - un-init malloc called\")};\r\n this.modParams=modParams;\r\n\r\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\r\n const canvasProxy = new twrCanvasProxy(modInWorkerParams.canvasProxyParams, this);\r\n const divProxy = new twrDivProxy(modInWorkerParams.divProxyParams);\r\n const waitingCallsProxy = new twrWaitingCallsProxy(modInWorkerParams.waitingCallsProxyParams);\r\n\r\n this.modParams.imports={\r\n twrDebugLog:twrDebugLogProxy,\r\n twrSleep:waitingCallsProxy.sleep.bind(waitingCallsProxy),\r\n twrTime:waitingCallsProxy.time.bind(waitingCallsProxy),\r\n\r\n twrDivCharOut:divProxy.charOut.bind(divProxy), \r\n twrDivCharIn:divProxy.charIn.bind(divProxy), \r\n\r\n twrCanvasCharIn:canvasProxy.charIn.bind(canvasProxy),\r\n twrCanvasInkey:canvasProxy.inkey.bind(canvasProxy),\r\n twrCanvasGetProp:canvasProxy.getProp.bind(canvasProxy),\r\n twrCanvasDrawSeq:canvasProxy.drawSeq.bind(canvasProxy),\r\n\r\n\t\t\ttwrSin:Math.sin,\r\n\t\t\ttwrCos:Math.cos,\r\n\t\t\ttwrTan: Math.tan,\r\n\t\t\ttwrFAbs: Math.abs,\r\n\t\t\ttwrACos: Math.acos,\r\n\t\t\ttwrASin: Math.asin,\r\n\t\t\ttwrATan: Math.atan,\r\n\t\t\ttwrExp: Math.exp,\r\n\t\t\ttwrFloor: Math.floor,\r\n\t\t\ttwrCeil: Math.ceil,\r\n\t\t\ttwrFMod: function(x:number, y:number) {return x%y},\r\n\t\t\ttwrLog: Math.log,\r\n\t\t\ttwrPow: Math.pow,\r\n\t\t\ttwrSqrt: Math.sqrt,\r\n\t\t\ttwrTrunc: Math.trunc,\r\n\r\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\r\n\t\t\ttwrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\r\n\t\t\ttwrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\r\n\t\t\ttwrAtod: this.floatUtil.atod.bind(this.floatUtil),\r\n\t\t\ttwrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\r\n \r\n }\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nimport { twrSignal } from \"./twrsignal.js\";\nvar D2DType;\n(function (D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})(D2DType || (D2DType = {}));\nexport class twrCanvas {\n ctx;\n props = { charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight: 0, canvasWidth: 0 };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase) {\n const { forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new twrSignal();\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext)\n throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c)\n throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2)\n throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\n }\n getProp(pn) {\n if (!this.isValid())\n console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */\n drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid())\n console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx)\n return;\n let ins = this.owner.getLong(ds); /* ds->start */\n const lastins = this.owner.getLong(ds + 4); /* ds->last */\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while (1) {\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */\n if (0 /*type!=D2DType.D2D_FILLRECT*/) {\n console.log(\"ins\", ins);\n console.log(\"hdr.next\", this.owner.mem8[ins], this.owner.mem8[ins + 1], this.owner.mem8[ins + 2], this.owner.mem8[ins + 3]);\n console.log(\"hdr.type\", this.owner.mem8[ins + 4], this.owner.mem8[ins + 5]);\n console.log(\"next 4 bytes\", this.owner.mem8[ins + 6], this.owner.mem8[ins + 7], this.owner.mem8[ins + 8], this.owner.mem8[ins + 9]);\n console.log(\"and 4 more \", this.owner.mem8[ins + 10], this.owner.mem8[ins + 11], this.owner.mem8[ins + 12], this.owner.mem8[ins + 13]);\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\n }\n switch (type) {\n case D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case D2DType.D2D_BEGINPATH:\n {\n this.ctx.beginPath();\n }\n break;\n case D2DType.D2D_FILL:\n {\n this.ctx.fill();\n }\n break;\n case D2DType.D2D_SAVE:\n {\n this.ctx.save();\n }\n break;\n case D2DType.D2D_RESTORE:\n {\n this.ctx.restore();\n }\n break;\n case D2DType.D2D_STROKE:\n {\n this.ctx.stroke();\n }\n break;\n case D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = (this.owner.getLong(ins + 48) != 0);\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n }\n else { // Uint8ClampedArray doesn't support shared memory\n this.precomputedObjects[id] = { mem8: new Uint8Array(this.owner.memory.buffer, start, length), width: width, height: height };\n }\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id])\n delete this.precomputedObjects[id];\n else\n console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) {\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n }\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) {\n this.ctx.putImageData(imgData, dx, dy);\n }\n else {\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */\n if (next == 0) {\n if (ins != lastins)\n throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal)\n this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nexport class twrCanvasProxy {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner) {\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new twrSignal(signalBuffer);\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\"drawseq\", [ds]]);\n this.drawCompleteSignal.wait();\n }\n}\n//# sourceMappingURL=twrcanvas.js.map","import {twrWasmModuleBase, IModParams} from \"./twrmodbase.js\"\r\nimport {twrSharedCircularBuffer} from \"./twrcircular.js\";\r\nimport {twrSignal} from \"./twrsignal.js\";\r\n\r\n\r\n// Canvas have a size that will be set based on the character width x height\r\n// The display size for a canvas will default to this size, but can be changed in the HTML/JS via\r\n// canvas.style.width = \"700px\";\r\n// canvas.style.height = \"500px\";\r\n\r\nexport interface ICanvasProps {\r\n\tcharWidth: number,\r\n\tcharHeight: number,\r\n\tforeColor: number,\r\n\tbackColor: number,\r\n widthInChars: number,\r\n heightInChars: number,\r\n canvasWidth:number,\r\n canvasHeight:number\r\n}\r\n\r\nenum D2DType {\r\n D2D_FILLRECT=1,\r\n D2D_FILLCHAR=5,\r\n D2D_SETLINEWIDTH=10,\r\n D2D_SETFILLSTYLERGBA=11,\r\n D2D_SETFONT=12,\r\n D2D_BEGINPATH=13,\r\n D2D_MOVETO=14,\r\n D2D_LINETO=15,\r\n D2D_FILL=16,\r\n D2D_STROKE=17,\r\n D2D_SETSTROKESTYLERGBA=18,\r\n D2D_ARC=19,\r\n D2D_STROKERECT=20,\r\n D2D_FILLTEXT=21,\r\n D2D_IMAGEDATA=22,\r\n D2D_PUTIMAGEDATA=23,\r\n D2D_BEZIERTO=24,\r\n D2D_MEASURETEXT=25,\r\n D2D_SAVE=26,\r\n D2D_RESTORE=27,\r\n D2D_CREATERADIALGRADIENT=28,\r\n D2D_SETCOLORSTOP=29,\r\n D2D_SETFILLSTYLEGRADIENT=30,\r\n D2D_RELEASEID=31,\r\n D2D_CREATELINEARGRADIENT=32,\r\n D2D_SETFILLSTYLE=33,\r\n D2D_SETSTROKESTYLE=34\r\n\r\n}\r\n\r\nexport type TCanvasProxyParams = [ICanvasProps, SharedArrayBuffer, SharedArrayBuffer];\r\n\r\nexport interface ICanvas {\r\n props: ICanvasProps,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TCanvasProxyParams,\r\n drawSeq: (ds:number)=>void,\r\n }\r\n \r\nexport class twrCanvas implements ICanvas {\r\n ctx:CanvasRenderingContext2D|undefined;\r\n props:ICanvasProps={charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight:0, canvasWidth:0};\r\n owner: twrWasmModuleBase;\r\n cmdCompleteSignal?:twrSignal;\r\n canvasKeys?: twrSharedCircularBuffer;\r\n precomputedObjects: { [index: number]: \r\n (ImageData | {mem8:Uint8Array, width:number, height:number}) |\r\n CanvasGradient\r\n };\r\n\r\n constructor(element:HTMLCanvasElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n const {forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas} = modParams; \r\n this.owner=modbase;\r\n this.props.widthInChars=modParams.windim[0];\r\n this.props.heightInChars=modParams.windim[1];\r\n\r\n if (!this.owner.isWasmModule) {\r\n this.cmdCompleteSignal=new twrSignal();\r\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n }\r\n\r\n this.precomputedObjects={};\r\n \r\n if (element) {\r\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\r\n let c=element.getContext(\"2d\");\r\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\r\n\r\n c.font = fontsize.toString()+\"px Courier New\";\r\n c.textBaseline=\"top\";\r\n const sampleText=\" \";\r\n const tm=c.measureText(sampleText);\r\n this.props.charWidth=Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\r\n let fM = c.measureText(\"X\"); \r\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\r\n\r\n if (!isd2dcanvas) {\r\n element.width=this.props.charWidth*this.props.widthInChars;\r\n element.height=this.props.charHeight*this.props.heightInChars;\r\n }\r\n\r\n this.props.canvasHeight=element.height;\r\n this.props.canvasWidth=element.width;\r\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\r\n\r\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\r\n let c2=element.getContext(\"2d\");\r\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\r\n this.ctx=c2;\r\n this.ctx.font = fontsize.toString()+\"px Courier New\";\r\n this.ctx.textBaseline=\"top\";\r\n\r\n c2.fillStyle=backcolor;\r\n this.props.backColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n c2.fillStyle=forecolor;\r\n this.props.foreColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n }\r\n\r\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\r\n\r\n //console.log(\"twrCanvas.constructor props: \", this.props);\r\n }\r\n\r\n isValid() {\r\n return !!this.ctx;\r\n }\r\n\r\n getProxyParams() : TCanvasProxyParams {\r\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\r\n }\r\n\r\n getProp(pn:number): number {\r\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n\r\n/* see draw2d.h for structs that match */\r\n\r\n drawSeq(ds:number) {\r\n //console.log(\"twr::Canvas enter drawSeq\");\r\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\r\n if (!this.ctx) return;\r\n\r\n let ins=this.owner.getLong(ds); /* ds->start */\r\n const lastins=this.owner.getLong(ds+4); /* ds->last */\r\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\r\n\r\n let next:number;\r\n //let insCount=0;\r\n\r\n while (1) {\r\n\r\n //insCount++;\r\n\r\n const type:D2DType=this.owner.getLong(ins+4); /* hdr->type */\r\n if (0/*type!=D2DType.D2D_FILLRECT*/) {\r\n console.log(\"ins\",ins)\r\n console.log(\"hdr.next\",this.owner.mem8[ins],this.owner.mem8[ins+1],this.owner.mem8[ins+2],this.owner.mem8[ins+3]);\r\n console.log(\"hdr.type\",this.owner.mem8[ins+4],this.owner.mem8[ins+5]);\r\n console.log(\"next 4 bytes\", this.owner.mem8[ins+6],this.owner.mem8[ins+7],this.owner.mem8[ins+8],this.owner.mem8[ins+9]);\r\n console.log(\"and 4 more \", this.owner.mem8[ins+10],this.owner.mem8[ins+11],this.owner.mem8[ins+12],this.owner.mem8[ins+13]);\r\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\r\n }\r\n switch (type) {\r\n case D2DType.D2D_FILLRECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.fillRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKERECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.strokeRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILLCHAR:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const c=this.owner.getShort(ins+24);\r\n let txt=String.fromCharCode(c);\r\n this.ctx.fillText(txt, x, y);\r\n }\r\n break;\r\n\r\n \r\n case D2DType.D2D_FILLTEXT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const str=this.owner.getString(this.owner.getLong(ins+24));\r\n\r\n //console.log(\"filltext \",x,y,str)\r\n \r\n this.ctx.fillText(str, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MEASURETEXT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n const tmidx=this.owner.getLong(ins+12);\r\n \r\n const tm=this.ctx.measureText(str);\r\n this.owner.setDouble(tmidx+0, tm.actualBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+8, tm.actualBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+16, tm.actualBoundingBoxLeft);\r\n this.owner.setDouble(tmidx+24, tm.actualBoundingBoxRight);\r\n this.owner.setDouble(tmidx+32, tm.fontBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+40, tm.fontBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+48, tm.width);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFONT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.font=str;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.fillStyle = cssColor;\r\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETSTROKESTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.fillStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETSTROKESTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETLINEWIDTH:\r\n {\r\n const width=this.owner.getShort(ins+8); \r\n this.ctx.lineWidth=width;\r\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MOVETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.moveTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_LINETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.lineTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEZIERTO:\r\n {\r\n const cp1x=this.owner.getDouble(ins+8);\r\n const cp1y=this.owner.getDouble(ins+16);\r\n const cp2x=this.owner.getDouble(ins+24);\r\n const cp2y=this.owner.getDouble(ins+32);\r\n const x=this.owner.getDouble(ins+40);\r\n const y=this.owner.getDouble(ins+48);\r\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEGINPATH:\r\n {\r\n this.ctx.beginPath();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILL:\r\n {\r\n this.ctx.fill();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SAVE:\r\n {\r\n this.ctx.save();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_RESTORE:\r\n {\r\n this.ctx.restore();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKE:\r\n {\r\n this.ctx.stroke();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_ARC:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const radius=this.owner.getDouble(ins+24);\r\n const startAngle=this.owner.getDouble(ins+32);\r\n const endAngle=this.owner.getDouble(ins+40);\r\n const counterClockwise= (this.owner.getLong(ins+48)!=0);\r\n\r\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_IMAGEDATA:\r\n {\r\n const start=this.owner.getLong(ins+8);\r\n const length=this.owner.getLong(ins+12);\r\n const width=this.owner.getLong(ins+16);\r\n const height=this.owner.getLong(ins+20);\r\n const id=this.owner.getLong(ins+24);\r\n\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\r\n\r\n if (this.owner.isWasmModule) {\r\n const z = new Uint8ClampedArray(this.owner.memory!.buffer, start, length);\r\n this.precomputedObjects[id]=new ImageData(z, width, height);\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory\r\n this.precomputedObjects[id]={mem8: new Uint8Array(this.owner.memory!.buffer, start, length), width:width, height:height};\r\n }\r\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_CREATERADIALGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const radius0=this.owner.getDouble(ins+24);\r\n const x1=this.owner.getDouble(ins+32);\r\n const y1=this.owner.getDouble(ins+40);\r\n const radius1=this.owner.getDouble(ins+48);\r\n const id= this.owner.getLong(ins+56);\r\n\r\n let gradient=this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_CREATELINEARGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const x1=this.owner.getDouble(ins+24);\r\n const y1=this.owner.getDouble(ins+32);\r\n const id= this.owner.getLong(ins+40);\r\n \r\n let gradient=this.ctx.createLinearGradient(x0, y0, x1, y1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETCOLORSTOP:\r\n {\r\n const id = this.owner.getLong(ins+8);\r\n const pos=this.owner.getLong(ins+12);\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+16));\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n gradient.addColorStop(pos, cssColor);\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n this.ctx.fillStyle=gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_RELEASEID:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (this.precomputedObjects[id])\r\n delete this.precomputedObjects[id];\r\n else\r\n console.log(\"warning: D2D_RELEASEID with undefined ID \",id);\r\n }\r\n break\r\n\r\n \r\n\r\n case D2DType.D2D_PUTIMAGEDATA:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n const dx=this.owner.getLong(ins+12);\r\n const dy=this.owner.getLong(ins+16);\r\n const dirtyX=this.owner.getLong(ins+20);\r\n const dirtyY=this.owner.getLong(ins+24);\r\n const dirtyWidth=this.owner.getLong(ins+28);\r\n const dirtyHeight=this.owner.getLong(ins+32);\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \"+id);\r\n\r\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\r\n\r\n let imgData:ImageData;\r\n if (this.owner.isWasmModule) {\r\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\r\n imgData=this.precomputedObjects[id] as ImageData;\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\r\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\r\n const z = this.precomputedObjects[id] as {mem8:Uint8Array, width:number, height:number}; // Uint8Array\r\n const ca=Uint8ClampedArray.from(z.mem8); // shallow copy\r\n imgData=new ImageData(ca, z.width, z.height);\r\n }\r\n \r\n if (dirtyWidth==0 && dirtyHeight==0) {\r\n this.ctx.putImageData(imgData, dx, dy);\r\n }\r\n else {\r\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\r\n }\r\n }\r\n break;\r\n\r\n default:\r\n throw new Error (\"unimplemented or unknown Sequence Type in drawSeq: \"+type);\r\n }\r\n next=this.owner.getLong(ins); /* hdr->next */\r\n if (next==0) {\r\n if (ins!=lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\r\n break;\r\n }\r\n ins=next;\r\n }\r\n\r\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\r\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\r\n }\r\n}\r\n\r\nexport class twrCanvasProxy implements ICanvas {\r\n canvasKeys: twrSharedCircularBuffer;\r\n drawCompleteSignal:twrSignal;\r\n props: ICanvasProps;\r\n owner: twrWasmModuleBase;\r\n\r\n constructor(params:TCanvasProxyParams, owner:twrWasmModuleBase) {\r\n const [props, signalBuffer, canvasKeysBuffer] = params;\r\n this.drawCompleteSignal = new twrSignal(signalBuffer);\r\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\r\n this.props=props;\r\n this.owner=owner;\r\n\r\n //console.log(\"Create New twrCanvasProxy: \",this.props)\r\n\r\n }\r\n\r\n charIn() { \r\n //ctx.commit(); not avail in chrome\r\n \r\n //postMessage([\"debug\", 'x']);\r\n \r\n return this.canvasKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.canvasKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n getProp(pn:number): number {\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n \r\n drawSeq(ds:number) {\r\n this.drawCompleteSignal.reset();\r\n postMessage([\"drawseq\", [ds]]);\r\n this.drawCompleteSignal.wait();\r\n }\r\n}\r\n","//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst RDIDX = 256;\nconst WRIDX = 257;\nconst LEN = 256;\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\n// the first 256 array entries are the circular buffer\n// the next two are used for the read and write index\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\nexport class twrSharedCircularBuffer {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(258 * 4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[RDIDX] = 0;\n this.buf[WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[WRIDX];\n this.buf[i] = n;\n i++;\n if (i == LEN)\n i = 0;\n this.buf[WRIDX] = i;\n Atomics.notify(this.buf, WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[RDIDX] = i;\n return n;\n }\n else\n return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[RDIDX] == this.buf[WRIDX];\n }\n}\n//# sourceMappingURL=twrcircular.js.map","//\r\n// This class implements a circular buffer that the main javascript thread can write to, \r\n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\r\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \r\n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\r\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\r\n//\r\n\r\nconst RDIDX=256;\r\nconst WRIDX=257;\r\nconst LEN=256;\r\n\r\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\r\n// the first 256 array entries are the circular buffer\r\n// the next two are used for the read and write index\r\n\r\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\r\n\r\nexport class twrSharedCircularBuffer {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n \r\n\tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(258*4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[RDIDX]=0;\r\n this.buf[WRIDX]=0;\r\n\t}\r\n\r\n\twrite(n:number) {\r\n let i=this.buf[WRIDX];\r\n this.buf[i]=n;\r\n i++;\r\n if (i==LEN) i=0;\r\n this.buf[WRIDX]=i; \r\n Atomics.notify(this.buf, WRIDX); \r\n\t}\r\n\r\n\tread():number {\r\n if (!this.isEmpty()) {\r\n let i=this.buf[RDIDX];\r\n let n=this.buf[i];\r\n i++;\r\n this.buf[RDIDX]=i;\r\n return n;\r\n }\r\n\t\telse\r\n return -1;\r\n\t}\r\n\r\n readWait():number {\r\n if (this.isEmpty()) {\r\n const rdptr=this.buf[RDIDX];\r\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\r\n Atomics.wait(this.buf, WRIDX, rdptr);\r\n }\r\n return this.read();\r\n\t}\r\n\r\n isEmpty():boolean {\r\n return this.buf[RDIDX]==this.buf[WRIDX];\r\n }\r\n}\r\n","//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar twrSignalState;\n(function (twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})(twrSignalState || (twrSignalState = {}));\n;\nexport class twrSignal {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window valid\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == twrSignalState.WAITING) {\n //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\n //console.log(\"released...\");\n }\n }\n isSignaled() {\n return this.buf[0] == twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = twrSignalState.WAITING;\n }\n}\n//# sourceMappingURL=twrsignal.js.map","//\r\n// This class implements a simple signal/wait mechanism\r\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\r\n//\r\n\r\nenum twrSignalState {\r\n WAITING=0,\r\n SIGNALED=1\r\n};\r\n\r\nexport class twrSignal {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n\r\n \tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window valid\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) \r\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[0]=twrSignalState.WAITING;\r\n\t}\r\n\r\n\tsignal() {\r\n this.buf[0]=twrSignalState.SIGNALED; \r\n //console.log(\"about to signal\");\r\n Atomics.notify(this.buf, 0); \r\n\t}\r\n\r\n wait() {\r\n if (this.buf[0]==twrSignalState.WAITING) {\r\n //console.log(\"waiting...\");\r\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\r\n //console.log(\"released...\");\r\n\r\n }\r\n\t}\r\n isSignaled():boolean {\r\n return this.buf[0]==twrSignalState.SIGNALED;\r\n }\r\n\r\n reset() {\r\n this.buf[0]=twrSignalState.WAITING;\r\n }\r\n}\r\n","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nexport class twrDiv {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase) {\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\n this.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n if (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.divKeys.sharedArray];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */\n charOut(ch) {\n if (!this.div)\n return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n }\n switch (ch) {\n case 10: // newline\n case 13: // return\n if (ch == 10 && this.lastChar == 13)\n break; // detect CR LF and treat as single new line\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8: // backspace\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n case 0xE: // cursor on\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF: // cursor off\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for (let i = 0; i < str.length; i++)\n this.charOut(str.charCodeAt(i));\n }\n}\nexport class twrDivProxy {\n divKeys;\n constructor(params) {\n const [divKeysBuffer] = params;\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n charOut(ch) {\n postMessage([\"divout\", ch]);\n }\n}\n//# sourceMappingURL=twrdiv.js.map","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\r\nimport { IModParams } from \"./twrmodbase.js\";\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\";\r\n\r\nexport type TDivProxyParams = [SharedArrayBuffer];\r\n\r\nexport interface IDiv {\r\n charOut: (ds:number)=>void,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TDivProxyParams,\r\n }\r\n\r\n\r\nexport class twrDiv implements IDiv {\r\n\tdiv:HTMLDivElement|null|undefined;\r\n\tdivKeys?:twrSharedCircularBuffer;\r\n\tCURSOR=String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\r\n\tcursorOn:boolean=false;\r\n\tlastChar:number=0;\r\n\textraBR:boolean=false;\r\n\towner:twrWasmModuleBase;\r\n\r\n constructor(element:HTMLDivElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n\t\tthis.div=element;\r\n\t\tthis.owner=modbase;\r\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\r\n\t\t\tthis.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n\t\t}\r\n\r\n\t\tif (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\r\n\t\t\tthis.div.style.backgroundColor = modParams.backcolor;\r\n\t\t\tthis.div.style.color = modParams.forecolor;\r\n\t\t\tthis.div.style.font=modParams.fontsize.toString()+\"px arial\"\r\n\t\t}\r\n }\r\n\r\n\tisValid() {\r\n\t\treturn !!this.div;\r\n\t}\r\n\r\n getProxyParams() : TDivProxyParams {\r\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [ this.divKeys.sharedArray];\r\n }\r\n\r\n\r\n/* \r\n * add character to div. Supports the following control codes:\r\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\r\n * 0xE cursor on \r\n * 0x8 backspace\r\n * 0xF cursor off \r\n*/\r\n\tcharOut(ch:number) {\r\n\r\n\t\tif (!this.div) return;\r\n\r\n\t\t//console.log(\"div::charout: \", ch);\r\n\r\n\t\tif (this.extraBR) {\r\n\t\t\tthis.extraBR=false;\r\n\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -4);\r\n\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t}\r\n\r\n\t\tswitch (ch) {\r\n\t\t\tcase 10: // newline\r\n\t\t\tcase 13: // return\r\n\t\t\t\tif (ch==10 && this.lastChar==13) break; // detect CR LF and treat as single new line\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\r\n\t\t\t\tthis.extraBR=true;\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\t//element.scrollIntoView();\r\n\t\t\t\t//element.scrollTop = element.scrollHeight;\r\n\t\t\t\tlet p = this.div.getBoundingClientRect();\r\n\t\t\t\twindow.scrollTo(0, p.height+100);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 8: // backspace\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xE: // cursor on\r\n\t\t\t\tif (!this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=true;\r\n\t\t\t\t\tthis.div.innerHTML += this.CURSOR;\r\n\t\t\t\t\tthis.div.focus();\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xF: // cursor off\r\n\t\t\t\tif (this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=false;\r\n\t\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += String.fromCharCode(ch);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\tthis.lastChar=ch;\r\n\t}\r\n\r\n\tstringOut(str:string) {\r\n\t\tfor (let i=0; i < str.length; i++)\r\n\t\t\tthis.charOut(str.charCodeAt(i));\r\n\t}\r\n}\r\n\r\n\r\nexport class twrDivProxy implements IDiv {\r\n divKeys: twrSharedCircularBuffer;\r\n\r\n constructor(params:TDivProxyParams) {\r\n const [divKeysBuffer] = params;\r\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\r\n }\r\n\r\n charIn() { \r\n return this.divKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.divKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n\tcharOut(ch:number) {\r\n\t\tpostMessage([\"divout\", ch]);\r\n\t}\r\n}\r\n\r\n","let logline = \"\";\nexport function twrDebugLogImpl(char) {\n if (char == 10 || char == 3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\n console.log(logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n logline = \"\";\n }\n else {\n logline = logline + String.fromCharCode(char);\n if (logline.length >= 200) {\n console.log(logline);\n logline = \"\";\n }\n }\n}\n// ************************************************************************\n// debugLog doesn't currently wait for the message to log, it returns immediately.\n// I could move this to be in the twrWaitingCalls class\nexport function twrDebugLogProxy(ch) {\n postMessage([\"debug\", ch]);\n}\n//# sourceMappingURL=twrdebug.js.map","\r\nlet logline=\"\";\r\nexport function twrDebugLogImpl(char:number) {\r\n\tif (char==10 || char==3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\r\n\t\tconsole.log(logline);\t// ideally without a linefeed, but there is no way to not have a LF with console.log API.\r\n\t\tlogline=\"\";\r\n\t}\r\n\telse {\r\n\t\tlogline=logline+String.fromCharCode(char);\r\n\t\tif (logline.length>=200) {\r\n\t\t\tconsole.log(logline);\r\n\t\t\tlogline=\"\";\r\n\t\t}\r\n\t}\r\n}\r\n\r\n// ************************************************************************\r\n// debugLog doesn't currently wait for the message to log, it returns immediately.\r\n// I could move this to be in the twrWaitingCalls class\r\nexport function twrDebugLogProxy(ch:number) {\r\n postMessage([\"debug\", ch]);\r\n}\r\n\r\n","import { twrFloatUtil } from \"./twrfloat.js\";\n/*********************************************************************/\n/*********************************************************************/\n/*********************************************************************/\nexport class twrWasmModuleBase {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\n floatUtil;\n constructor(isWasmModule = false) {\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new twrFloatUtil(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/\n /*********************************************************************/\n async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n }\n catch (err) {\n console.log('loadWasm() failed to fetch: ' + pathToLoad);\n throw err;\n }\n if (!response.ok)\n throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, { env: allimports });\n this.exports = instance.instance.exports;\n if (!this.exports)\n throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory)\n throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory)\n throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer)\n console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\"setmemory\", this.memory]);\n }\n if (this.isWasmModule) {\n // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (!(this.memory.buffer instanceof ArrayBuffer))\n console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size) => {\n return new Promise(resolve => {\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n }\n catch (err) {\n console.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch (this.modParams.stdio) {\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* executeC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */\n async executeC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.executeCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async executeCImpl(fname, cparams = []) {\n if (!this.exports)\n throw new Error(\"this.exports undefined\");\n if (!this.exports[fname])\n throw new Error(\"executeC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array))\n throw new Error(\"executeC: params must be array, first arg is function name\");\n if (params.length == 0)\n throw new Error(\"executeC: missing function name\");\n let cparams = [];\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n cparams[ci++] = p;\n break;\n case 'string':\n cparams[ci++] = await this.putString(p);\n break;\n case 'object':\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n }\n else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"executeC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n ci++;\n break;\n case 'string':\n this.executeCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n case 'object':\n if (p instanceof URL) {\n this.executeCImpl('twr_free', [cparams[ci]]);\n ci = ci + 2;\n break;\n }\n else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for (let j = 0; j < u8.length; j++)\n u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.executeCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n }\n else\n throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/\n /*********************************************************************/\n // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for (i = 0; i < sin.length && i < buffer_size - 1; i++)\n this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for (let i = 0; i < u8a.length; i++)\n this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === 'object' && fnin instanceof URL))\n throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [dest, src.length];\n }\n catch (err) {\n console.log('fetchAndPutURL Error. URL: ' + fnin + '\\n' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while (this.mem8[strIndex + i] && (len === undefined ? true : i < len) && (strIndex + i) < this.mem8.length) {\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0)\n throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array((this.mem8.slice(dataptr, dataptr + size)).buffer);\n return u32;\n }\n}\n//# sourceMappingURL=twrmodbase.js.map","\r\nimport {TCanvasProxyParams} from \"./twrcanvas.js\"\r\nimport {TDivProxyParams} from \"./twrdiv.js\";\r\nimport {TWaitingCallsProxyParams} from \"./twrwaitingcalls.js\"\r\nimport {twrDebugLogImpl} from \"./twrdebug.js\";\r\nimport {twrFloatUtil} from \"./twrfloat.js\";\r\n\r\n\r\nexport type TStdioVals=\"div\"|\"canvas\"|\"null\"|\"debug\";\r\n\r\nexport interface IModOpts {\r\n\tstdio?:TStdioVals, \r\n\twindim?:[number, number],\r\n\tforecolor?:string,\r\n\tbackcolor?:string,\r\n\tfontsize?:number,\r\n\tisd2dcanvas?:boolean,\r\n\timports?:{},\r\n}\r\n\r\nexport interface IModParams {\r\n\tstdio:TStdioVals, \r\n\twindim:[number, number],\r\n\tforecolor:string,\r\n\tbackcolor:string,\r\n\tfontsize:number,\r\n\tstyleIsDefault: boolean\r\n\tisd2dcanvas:boolean,\r\n\timports:{[index:string]:Function},\r\n}\r\n\r\nexport interface IModInWorkerParams {\r\n\tdivProxyParams:TDivProxyParams,\r\n\tcanvasProxyParams:TCanvasProxyParams,\r\n\twaitingCallsProxyParams:TWaitingCallsProxyParams,\r\n}\r\n\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n\r\nexport abstract class twrWasmModuleBase {\r\n\tmemory?:WebAssembly.Memory;\r\n\tmem8:Uint8Array;\r\n\tmem32:Uint32Array;\r\n\tmemD:Float64Array;\r\n\tabstract malloc:(size:number)=>Promise;\r\n\tabstract modParams:IModParams;\r\n\texports?:WebAssembly.Exports;\r\n\tisWorker=false;\r\n\tisWasmModule:boolean; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\r\n\tfloatUtil:twrFloatUtil;\r\n\r\n\tconstructor(isWasmModule=false) {\r\n\t\tthis.isWasmModule=isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\r\n\t\tthis.mem8=new Uint8Array(); \t// avoid type errors\r\n\t\tthis.mem32=new Uint32Array(); // avoid type errors\r\n\t\tthis.memD=new Float64Array(); // avoid type errors\r\n\t\tthis.floatUtil=new twrFloatUtil(this);\r\n\t\t//console.log(\"size of mem8 after constructor\",this.mem8.length);\r\n\t}\r\n\r\n\t/*********************************************************************/\r\n\t/*********************************************************************/\r\n\r\n\tasync loadWasm(pathToLoad:string) {\r\n\t\t//console.log(\"fileToLoad\",fileToLoad)\r\n\r\n\t\tlet response;\r\n\t\ttry {\r\n\t\t\tresponse=await fetch(pathToLoad);\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('loadWasm() failed to fetch: '+pathToLoad);\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t\t\r\n\t\tif (!response.ok) throw new Error(\"fetch response error on file '\"+pathToLoad+\"'\\n\"+response.statusText);\r\n\r\n\t\ttry {\r\n\t\t\tlet wasmBytes = await response.arrayBuffer();\r\n\r\n\t\t\tlet allimports:WebAssembly.ModuleImports = { \r\n\t\t\t\t...this.modParams.imports\r\n\t\t\t};\r\n\r\n\t\t\tlet instance = await WebAssembly.instantiate(wasmBytes, {env: allimports});\r\n\r\n\t\t\tthis.exports=instance.instance.exports;\r\n\t\t\tif (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\r\n\r\n\t\t\tif (this.memory) throw new Error (\"unexpected error -- this.memory already set\");\r\n\t\t\tthis.memory=this.exports.memory as WebAssembly.Memory;\r\n\t\t\tif (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\r\n\t\t\tthis.mem8 = new Uint8Array(this.memory.buffer);\r\n\t\t\tthis.mem32 = new Uint32Array(this.memory.buffer);\r\n\t\t\tthis.memD = new Float64Array(this.memory.buffer);\r\n\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\tif (this.isWorker) {\r\n\t\t\t\tif (this.memory.buffer instanceof ArrayBuffer)\r\n\t\t\t\t\tconsole.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\r\n\t\t\t\t\r\n\t\t\t\tpostMessage([\"setmemory\",this.memory]);\r\n\t\t\t}\r\n\t\t\tif (this.isWasmModule) {\r\n\t\t\t\t// here if twrWasmModule, twrWasmModuleAsync overrides this function\r\n\t\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\t\tif (!(this.memory.buffer instanceof ArrayBuffer))\r\n\t\t\t\t\tconsole.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\r\n\t\t\t}\r\n\r\n\t\t\tthis.malloc=(size:number)=>{\r\n\t\t\t\treturn new Promise(resolve => {\r\n\t\t\t\t\tconst m=this.exports!.twr_malloc as (size:number)=>number;\r\n\t\t\t\t\tresolve(m(size));\r\n\t\t\t\t});\r\n\t\t };\r\n\r\n\t\t\tthis.init();\r\n\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t}\r\n\r\n\tprivate init() {\r\n\t\t//console.log(\"loadWasm.init() enter\")\r\n\t\t\tlet p:number;\r\n\t\t\tswitch (this.modParams.stdio) {\r\n\t\t\t\tcase \"debug\":\r\n\t\t\t\t\tp=0;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"div\":\r\n\t\t\t\t\tp=1;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"canvas\":\r\n\t\t\t\t\tp=2;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"null\":\r\n\t\t\t\t\tp=3;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tp=0; // debug\r\n\t\t\t}\r\n\r\n\t\t\tconst twrInit=this.exports!.twr_wasm_init as CallableFunction;\r\n\t\t\t//console.log(\"twrInit:\",twrInit)\r\n\t\t\ttwrInit(p, this.mem8.length);\r\n\t}\r\n\r\n\t/* executeC takes an array where:\r\n\t* the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\r\n\t* and the next entries are a variable number of parameters to pass to the C function, of type\r\n\t* number - converted to int32 or float64 as appropriate\r\n\t* string - converted to a an index (ptr) into a module Memory returned via stringToMem()\r\n\t* URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\r\n\t* Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\r\n */\r\n\r\n\tasync executeC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\t\tconst cparams=await this.preCallC(params);\r\n\t\tlet retval = this.executeCImpl(params[0], cparams);\r\n\t\tthis.postCallC(cparams, params);\r\n\t\treturn retval;\r\n\t}\r\n\r\n\tasync executeCImpl(fname:string, cparams:number[]=[]) {\r\n\t\tif (!this.exports) throw new Error(\"this.exports undefined\");\r\n\t\tif (!this.exports[fname]) throw new Error(\"executeC: function '\"+fname+\"' not in export table. Use --export wasm-ld flag.\");\r\n\r\n\t\tconst f = this.exports[fname] as CallableFunction;\r\n\t\tlet cr=f(...cparams);\r\n\r\n\t\treturn cr;\r\n\t}\r\n\r\n\t// convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\r\n\tasync preCallC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tif (!(params.constructor === Array)) throw new Error (\"executeC: params must be array, first arg is function name\");\r\n\t\tif (params.length==0) throw new Error(\"executeC: missing function name\");\r\n\r\n\t\tlet cparams:number[]=[];\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tcparams[ci++]=p;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tcparams[ci++]=await this.putString(p);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tconst r=await this.fetchAndPutURL(p);\r\n\t\t\t\t\t\tcparams[ci++]=r[0]; // mem index\r\n\t\t\t\t\t\tcparams[ci++]=r[1]; // len\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tconst r=await this.putArrayBuffer(p);\r\n\t\t\t\t\t\tcparams[ci++]=r; // mem index\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tthrow new Error (\"executeC: invalid object type passed in\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn cparams;\r\n\t}\r\n\r\n\t// free the mallocs; copy array buffer data from malloc back to arraybuffer\r\n\tasync postCallC(cparams:number[], params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tthis.executeCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t\t\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tthis.executeCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\t\tci=ci+2;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tlet u8=new Uint8Array(p);\r\n\t\t\t\t\t\tfor (let j=0; j= this.mem32.length) throw new Error(\"invalid index passed to getLong: \"+idx+\", this.mem32.length: \"+this.mem32.length);\r\n\t\tconst long:number = this.mem32[idx32];\r\n\t\treturn long;\r\n\t}\r\n\t\r\n\tsetLong(idx:number, value:number) {\r\n const idx32 = Math.floor(idx / 4);\r\n if (idx32 * 4 != idx)\r\n throw new Error(\"setLong passed non long aligned address\");\r\n if (idx32 < 0 || idx32 >= this.mem32.length)\r\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\r\n this.mem32[idx32]=value;\r\n }\r\n\r\n\tgetDouble(idx:number): number {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"getLong passed non Float64 aligned address\")\r\n\t\tconst long:number = this.memD[idx64];\r\n\t\treturn long;\r\n\t}\r\n\r\n\tsetDouble(idx:number, value:number) {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"setDouble passed non Float64 aligned address\")\r\n\t\tthis.memD[idx64]=value;\r\n\t}\r\n\r\n\tgetShort(idx:number): number {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getShort: \"+idx);\r\n\t\tconst short:number = this.mem8[idx]+this.mem8[idx+1]*256;\r\n\t\treturn short;\r\n\t}\r\n\r\n\t// get a string out of module memory\r\n\t// null terminated, up until max of (optional) len\r\n\tgetString(strIndex:number, len?:number): string {\r\n\t\tlet sout=\"\";\r\n\r\n\t\tlet i=0;\r\n\t\twhile (this.mem8[strIndex+i] && (len===undefined?true:i= this.mem8.length) throw new Error(\"invalid index passed to getU8: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU8\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU8\")\r\n\r\n\t\tconst u8=this.mem8.slice(dataptr, dataptr+size);\r\n\t\treturn u8;\r\n\t}\r\n\r\n\t// get a int32 array out of module memory when passed in index to [size, dataptr]\r\n\tgetU32Arr(idx:number): Uint32Array {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getU32: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU32\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU32\")\r\n\r\n\t\tif (size%4!=0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\r\n\r\n\t\tconst u32 = new Uint32Array( (this.mem8.slice(dataptr, dataptr+size)).buffer );\r\n\t\treturn u32;\r\n\t}\r\n}\r\n","export class twrFloatUtil {\n mod;\n constructor(mod) {\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\")\n return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\")\n return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll('D', 'e').replaceAll('d', 'e'));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n }\n else {\n let r = value.toString();\n if (r.length > max_precision)\n r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, // char *\n sizeInBytes, //size_t\n value, // double\n fracpart_numdigits, //int\n dec, // int *\n sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1)\n return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) { /* nan */\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (!Number.isFinite(value)) { /* infinity */\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n }\n else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split('.');\n if (intPart == \"0\")\n intPart = \"\";\n if (intPart.length > 0) { // has integer part\n decpos = intPart.length;\n digits = intPart + fracPart;\n }\n else { // only a fraction\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length)\n return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */\n }\n}\n//# sourceMappingURL=twrfloat.js.map","\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\"\r\n\r\nexport class twrFloatUtil {\r\n mod: twrWasmModuleBase;\r\n\r\n constructor(mod: twrWasmModuleBase) {\r\n this.mod=mod;\r\n }\r\n\r\n atod(strptr:number):number {\r\n const str=this.mod.getString(strptr);\r\n\r\n const upper=str.trimStart().toUpperCase();\r\n if (upper==\"INF\" || upper==\"+INF\")\r\n return Number.POSITIVE_INFINITY;\r\n else if (upper==\"-INF\")\r\n return Number.NEGATIVE_INFINITY\r\n else {\r\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\r\n const r=Number.parseFloat(str.replaceAll('D','e').replaceAll('d','e'));\r\n return r;\r\n }\r\n }\r\n\r\n dtoa(buffer:number, buffer_size:number, value:number, max_precision:number):void {\r\n if (max_precision==-1) {\r\n const r=value.toString();\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n else {\r\n let r=value.toString();\r\n if (r.length>max_precision)\r\n r=value.toPrecision(max_precision);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n }\r\n\r\n toFixed(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toFixed(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n toExponential(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toExponential(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\r\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\r\n // Negative exponents must be now smaller than 1e-99\r\n // fully-function C version also int he source, but this is the version enabled by default\r\n fcvtS(\r\n buffer:number, // char *\r\n sizeInBytes:number, //size_t\r\n value:number, // double\r\n fracpart_numdigits:number, //int\r\n dec:number, // int *\r\n sign:number // int *\r\n ):number {\r\n\r\n if (buffer==0 ||sign==0 || dec==0 || sizeInBytes<1) return 1;\r\n\r\n let digits:string;\r\n let decpos:number;\r\n let s=0; // default to positive\r\n\r\n\r\n if (Number.isNaN(value)) { /* nan */\r\n digits=\"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (!Number.isFinite(value)) { /* infinity */\r\n digits=\"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (value==0) { \r\n digits=\"000000000000000000000000000000000000\".slice(0,fracpart_numdigits);\r\n decpos=0;\r\n }\r\n \r\n else {\r\n\r\n if (value<0) {\r\n s=1; // negative\r\n value=Math.abs(value);\r\n }\r\n\r\n if (fracpart_numdigits>100 || value > 1e+21 || value < 1e-99) { \r\n this.mod.copyString(buffer, sizeInBytes, \"\");\r\n this.mod.mem32[dec]=0;\r\n return 1;\r\n }\r\n\r\n const roundValStr=value.toFixed(fracpart_numdigits);\r\n let [intPart=\"\", fracPart=\"\"] = roundValStr.split('.');\r\n if (intPart==\"0\") intPart=\"\";\r\n\r\n if (intPart.length>0) { // has integer part\r\n decpos=intPart.length;\r\n digits=intPart+fracPart;\r\n }\r\n else { // only a fraction\r\n digits=fracPart.replace(/^0+/,\"\"); // remove leading zeros\r\n decpos=digits.length-fracPart.length;\r\n }\r\n }\r\n\r\n if (sizeInBytes-1 < digits.length) return 1; \r\n this.mod.copyString(buffer, sizeInBytes, digits);\r\n this.mod.setLong(dec, decpos);\r\n this.mod.setLong(sign, s);\r\n\r\n return 0;\r\n\r\n /*\r\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\r\n\r\n let decpos=0;\r\n let digits:string;\r\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\r\n \r\n if (decpos>0) { // has integer part\r\n const intlen=Math.max(decpos, 0);\r\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\r\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\r\n }\r\n else { // only a fraction\r\n const intpart=Math.trunc(value);\r\n const fracpart=value-intpart;\r\n const prec=fracpart_numdigits- (-decpos);\r\n console.log(\"prec=\",prec);\r\n if (prec<1) {\r\n digits=\"\";\r\n }\r\n else {\r\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\");\r\n }\r\n }\r\n\r\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\r\n console.log('digits=',digits);\r\n console.log('dec=',decpos);\r\n console.log(\"sign=\",s);\r\n */\r\n\r\n\r\n }\r\n}","import { twrSignal } from \"./twrsignal.js\";\nimport { twrTimeImpl } from \"./twrdate.js\";\n// This class is used in the Main JS thread \nexport class twrWaitingCalls {\n callCompleteSignal;\n parameters;\n constructor() {\n this.callCompleteSignal = new twrSignal();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(() => {\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = twrTimeImpl();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [this.callCompleteSignal.sharedArray, this.parameters.buffer];\n }\n processMessage(msgType, data) {\n switch (msgType) {\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\n// This class is used in the worker thread \nexport class twrWaitingCallsProxy {\n callCompleteSignal;\n parameters;\n constructor(params) {\n this.callCompleteSignal = new twrSignal(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\"sleep\", [ms]]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\"time\"]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n//# sourceMappingURL=twrwaitingcalls.js.map","import { twrSignal } from \"./twrsignal.js\";\r\nimport {twrTimeImpl} from \"./twrdate.js\"\r\n\r\n// These classes are used to proxy a call across the worker thread - main thread boundary and wait for the result\r\n\r\nexport type TWaitingCallsProxyParams = [SharedArrayBuffer, SharedArrayBuffer]; // twrSignal, parameters \r\n\r\n// This class is used in the Main JS thread \r\nexport class twrWaitingCalls {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor() {\r\n\t\tthis.callCompleteSignal=new twrSignal();\r\n\t\tthis.parameters=new Uint32Array(new SharedArrayBuffer(4));\r\n\t}\r\n\r\n\tprivate startSleep(ms:number) {\r\n\r\n\t\tsetTimeout(()=>{\r\n\t\t\tthis.callCompleteSignal.signal();\r\n\t\t}, ms);\r\n\t\t\r\n\t}\r\n\r\n\tprivate time() {\r\n\t\tconst ms=twrTimeImpl();\r\n\t\tthis.parameters[0]=ms;\r\n\t\tthis.callCompleteSignal.signal();\r\n\t}\r\n\r\n\tgetProxyParams():TWaitingCallsProxyParams {\r\n\t\treturn [this.callCompleteSignal.sharedArray, this.parameters.buffer as SharedArrayBuffer];\t\r\n\t}\r\n\r\n\tprocessMessage(msgType:string, data:any[]):boolean {\r\n\t\tswitch (msgType) {\r\n\t\t\tcase \"sleep\":\r\n\t\t\t\tconst [ms] = data;\r\n\t\t\t\tthis.startSleep(ms);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"time\":\r\n\t\t\t\tthis.time();\r\n\t\t\t\tbreak;\r\n\t\t\t\r\n\t\t\tdefault:\r\n\t\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\treturn true;\r\n\t}\r\n\r\n}\r\n\r\n// This class is used in the worker thread \r\nexport class twrWaitingCallsProxy {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor(params:TWaitingCallsProxyParams) {\r\n\t\tthis.callCompleteSignal=new twrSignal(params[0]);\r\n\t\tthis.parameters=new Uint32Array(params[1]);\r\n\t}\r\n\r\n\tsleep(ms:number) {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"sleep\", [ms]]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t}\r\n\r\n\ttime() {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"time\"]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t\treturn this.parameters[0];\r\n\t}\r\n\r\n}\r\n","export function twrTimeImpl() {\n return Date.now();\n}\n//# sourceMappingURL=twrdate.js.map","\r\nexport function twrTimeImpl() {\r\n\r\n return Date.now();\r\n\r\n}"],"names":["$b93f1fdf40141def$var$twrSignalState","$c4741cac81d14197$var$D2DType","twrSignalState","D2DType","$3e39efa823870787$var$mod","$892fccfc812d5e20$export$a01cca24f011573a","sharedArray","buf","constructor","sa","window","crossOriginIsolated","location","protocol","Error","SharedArrayBuffer","Int32Array","write","n","i","Atomics","notify","read","isEmpty","readWait","rdptr","wait","$b93f1fdf40141def$export$e37a7b7b851b97f3","WAITING","signal","SIGNALED","isSignaled","reset","$c4741cac81d14197$export$c779b2cd00544976","canvasKeys","drawCompleteSignal","props","owner","params","signalBuffer","canvasKeysBuffer","charIn","inkey","getProp","pn","propName","getString","drawSeq","ds","postMessage","$8963973702ae5462$export$b377f0bbf2c7581e","divKeys","divKeysBuffer","charOut","ch","$8ac0b786da854328$export$485af4d0039b3389","$e72303a1db04bdfa$export$918ffb7e046a537b","mod","atod","strptr","str","upper","trimStart","toUpperCase","Number","POSITIVE_INFINITY","NEGATIVE_INFINITY","parseFloat","replaceAll","dtoa","buffer","buffer_size","value","max_precision","r","toString","copyString","length","toPrecision","toFixed","decdigits","toExponential","fcvtS","sizeInBytes","fracpart_numdigits","dec","sign","digits","decpos","s","isNaN","slice","isFinite","Math","abs","mem32","intPart","fracPart","roundValStr","split","replace","setLong","$ece7fa3ed770778a$export$c83a0a3bffe07399","memory","mem8","memD","exports","isWorker","isWasmModule","floatUtil","Uint8Array","Uint32Array","Float64Array","loadWasm","pathToLoad","response","fetch","err","console","log","ok","statusText","wasmBytes","arrayBuffer","allimports","modParams","imports","instance","WebAssembly","instantiate","env","ArrayBuffer","malloc","size","Promise","resolve","m","twr_malloc","init","stack","p","stdio","twrInit","twr_wasm_init","executeC","cparams","preCallC","retval","executeCImpl","postCallC","fname","f","Array","ci","putString","URL","fetchAndPutURL","putArrayBuffer","u8","j","sin","charCodeAt","strIndex","putU8","u8a","dest","ab","fnin","src","getLong","idx","idx32","floor","getDouble","idx64","setDouble","getShort","len","sout","undefined","String","fromCharCode","getU8Arr","rv","dataptr","getU32Arr","$aff9c2c494d23fe3$export$78d2a4633fe89379","callCompleteSignal","parameters","sleep","ms","time","onmessage","e","data","$3e39efa823870787$var$twrWasmModuleInWorker","modWorkerParams","urlToLoad","then","catch","ex","rc","modInWorkerParams","canvasProxy","canvasProxyParams","divProxy","divProxyParams","waitingCallsProxy","waitingCallsProxyParams","twrDebugLog","twrSleep","bind","twrTime","twrDivCharOut","twrDivCharIn","twrCanvasCharIn","twrCanvasInkey","twrCanvasGetProp","twrCanvasDrawSeq","twrSin","twrCos","cos","twrTan","tan","twrFAbs","twrACos","acos","twrASin","asin","twrATan","atan","twrExp","exp","twrFloor","twrCeil","ceil","twrFMod","x","y","twrLog","twrPow","pow","twrSqrt","sqrt","twrTrunc","trunc","twrDtoa","twrToFixed","twrToExponential","twrAtod","twrFcvtS"],"version":3,"file":"twrmodworker.2165e649.js.map"} \ No newline at end of file +{"mappings":"A,C,SQKK,EJgBA,EIhBA,EJgBA,MFZD,CISE,OAAO,EACZ,WAA8B,AAC9B,CAAA,GAAe,AAEf,aAAa,CAAqB,CAAlC,CACO,GAAI,AAAkB,aAAlB,OAAO,QACH,CAAC,qBAAuB,AAA+B,UAA7B,OAAO,QAAQ,CAAC,QAAQ,CAAe,MAAM,AAAI,MAAM,4DAA4D,oBAAoB,iCAErK,EAAI,IAAI,CAAC,WAAW,CAAC,EACpB,I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AS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EACzD,WAAY,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EACtD,iBAAkB,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAClE,QAAS,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAChD,SAAU,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAE5C,CACN,CACF,C,C","sources":["","../../lib-js/twrmodworker.js","../../source/twr-wasm-ts/twrmodworker.ts","../../lib-js/twrcanvas.js","../../source/twr-wasm-ts/twrcanvas.ts","../../lib-js/twrcircular.js","../../source/twr-wasm-ts/twrcircular.ts","../../lib-js/twrsignal.js","../../source/twr-wasm-ts/twrsignal.ts","../../lib-js/twrdiv.js","../../source/twr-wasm-ts/twrdiv.ts","../../lib-js/twrdebug.js","../../source/twr-wasm-ts/twrdebug.ts","../../lib-js/twrmodbase.js","../../source/twr-wasm-ts/twrmodbase.ts","../../lib-js/twrfloat.js","../../source/twr-wasm-ts/twrfloat.ts","../../lib-js/twrwaitingcalls.js","../../source/twr-wasm-ts/twrwaitingcalls.ts","../../lib-js/twrdate.js","../../source/twr-wasm-ts/twrdate.ts"],"sourcesContent":["(() => {\nvar $3e39efa823870787$exports = {};\n// this script is the WebWorker thead used by class twrWasmAsyncModule\n//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst $892fccfc812d5e20$var$RDIDX = 256;\nconst $892fccfc812d5e20$var$WRIDX = 257;\nconst $892fccfc812d5e20$var$LEN = 256;\nclass $892fccfc812d5e20$export$a01cca24f011573a {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(1032);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[$892fccfc812d5e20$var$RDIDX] = 0;\n this.buf[$892fccfc812d5e20$var$WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[$892fccfc812d5e20$var$WRIDX];\n this.buf[i] = n;\n i++;\n if (i == $892fccfc812d5e20$var$LEN) i = 0;\n this.buf[$892fccfc812d5e20$var$WRIDX] = i;\n Atomics.notify(this.buf, $892fccfc812d5e20$var$WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[$892fccfc812d5e20$var$RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[$892fccfc812d5e20$var$RDIDX] = i;\n return n;\n } else return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[$892fccfc812d5e20$var$RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, $892fccfc812d5e20$var$WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[$892fccfc812d5e20$var$RDIDX] == this.buf[$892fccfc812d5e20$var$WRIDX];\n }\n}\n\n\n//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar $b93f1fdf40141def$var$twrSignalState;\n(function(twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})($b93f1fdf40141def$var$twrSignalState || ($b93f1fdf40141def$var$twrSignalState = {}));\nclass $b93f1fdf40141def$export$e37a7b7b851b97f3 {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == $b93f1fdf40141def$var$twrSignalState.WAITING) //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, $b93f1fdf40141def$var$twrSignalState.WAITING);\n }\n isSignaled() {\n return this.buf[0] == $b93f1fdf40141def$var$twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.WAITING;\n }\n}\n\n\nvar $c4741cac81d14197$var$D2DType;\n(function(D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})($c4741cac81d14197$var$D2DType || ($c4741cac81d14197$var$D2DType = {}));\nclass $c4741cac81d14197$export$2f298dd69cef3c34 {\n ctx;\n props = {\n charWidth: 0,\n charHeight: 0,\n foreColor: 0,\n backColor: 0,\n widthInChars: 0,\n heightInChars: 0,\n canvasHeight: 0,\n canvasWidth: 0\n };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase){\n const { forecolor: forecolor, backcolor: backcolor, fontsize: fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)();\n this.canvasKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.props,\n this.cmdCompleteSignal.sharedArray,\n this.canvasKeys.sharedArray\n ];\n }\n getProp(pn) {\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */ drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx) return;\n let ins = this.owner.getLong(ds); /* ds->start */ \n const lastins = this.owner.getLong(ds + 4); /* ds->last */ \n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while(true){\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */ \n switch(type){\n case $c4741cac81d14197$var$D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_BEGINPATH:\n this.ctx.beginPath();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILL:\n this.ctx.fill();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SAVE:\n this.ctx.save();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_RESTORE:\n this.ctx.restore();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_STROKE:\n this.ctx.stroke();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = this.owner.getLong(ins + 48) != 0;\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n } else this.precomputedObjects[id] = {\n mem8: new Uint8Array(this.owner.memory.buffer, start, length),\n width: width,\n height: height\n };\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id]) delete this.precomputedObjects[id];\n else console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n else {\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) this.ctx.putImageData(imgData, dx, dy);\n else this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */ \n if (next == 0) {\n if (ins != lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nclass $c4741cac81d14197$export$c779b2cd00544976 {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner){\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)(signalBuffer);\n this.canvasKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\n \"drawseq\",\n [\n ds\n ]\n ]);\n this.drawCompleteSignal.wait();\n }\n}\n\n\n\nclass $8963973702ae5462$export$dd376bb3f10f6896 {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611);\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase){\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) this.divKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(); // tsconfig, lib must be set to 2017 or higher\n if (this.div && !modParams.styleIsDefault) {\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.divKeys.sharedArray\n ];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */ charOut(ch) {\n if (!this.div) return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n }\n switch(ch){\n case 10:\n case 13:\n if (ch == 10 && this.lastChar == 13) break; // detect CR LF and treat as single new line\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n case 0xE:\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF:\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for(let i = 0; i < str.length; i++)this.charOut(str.charCodeAt(i));\n }\n}\nclass $8963973702ae5462$export$b377f0bbf2c7581e {\n divKeys;\n constructor(params){\n const [divKeysBuffer] = params;\n this.divKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n charOut(ch) {\n postMessage([\n \"divout\",\n ch\n ]);\n }\n}\n\n\nlet $8ac0b786da854328$var$logline = \"\";\nfunction $8ac0b786da854328$export$16b4216ec014493d(char) {\n if (char == 10 || char == 3) {\n console.log($8ac0b786da854328$var$logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n $8ac0b786da854328$var$logline = \"\";\n } else {\n $8ac0b786da854328$var$logline = $8ac0b786da854328$var$logline + String.fromCharCode(char);\n if ($8ac0b786da854328$var$logline.length >= 200) {\n console.log($8ac0b786da854328$var$logline);\n $8ac0b786da854328$var$logline = \"\";\n }\n }\n}\nfunction $8ac0b786da854328$export$485af4d0039b3389(ch) {\n postMessage([\n \"debug\",\n ch\n ]);\n}\n\n\nclass $e72303a1db04bdfa$export$918ffb7e046a537b {\n mod;\n constructor(mod){\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\") return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\") return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll(\"D\", \"e\").replaceAll(\"d\", \"e\"));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n } else {\n let r = value.toString();\n if (r.length > max_precision) r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, sizeInBytes, value, fracpart_numdigits, dec, sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1) return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) {\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (!Number.isFinite(value)) {\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n } else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split(\".\");\n if (intPart == \"0\") intPart = \"\";\n if (intPart.length > 0) {\n decpos = intPart.length;\n digits = intPart + fracPart;\n } else {\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length) return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */ }\n}\n\n\nclass $ece7fa3ed770778a$export$c83a0a3bffe07399 {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule;\n floatUtil;\n constructor(isWasmModule = false){\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new (0, $e72303a1db04bdfa$export$918ffb7e046a537b)(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/ /*********************************************************************/ async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n } catch (err) {\n console.log(\"loadWasm() failed to fetch: \" + pathToLoad);\n throw err;\n }\n if (!response.ok) throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, {\n env: allimports\n });\n this.exports = instance.instance.exports;\n if (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory) throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer) console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\n \"setmemory\",\n this.memory\n ]);\n }\n if (this.isWasmModule) // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n {\n if (!(this.memory.buffer instanceof ArrayBuffer)) console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size)=>{\n return new Promise((resolve)=>{\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n } catch (err) {\n console.log(\"WASM instantiate error: \" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch(this.modParams.stdio){\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* callC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */ async callC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.callCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async callCImpl(fname, cparams = []) {\n if (!this.exports) throw new Error(\"this.exports undefined\");\n if (!this.exports[fname]) throw new Error(\"callC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array)) throw new Error(\"callC: params must be array, first arg is function name\");\n if (params.length == 0) throw new Error(\"callC: missing function name\");\n let cparams = [];\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n cparams[ci++] = p;\n break;\n case \"string\":\n cparams[ci++] = await this.putString(p);\n break;\n case \"object\":\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n } else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"callC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n ci++;\n break;\n case \"string\":\n this.callCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n case \"object\":\n if (p instanceof URL) {\n this.callCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci = ci + 2;\n break;\n } else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for(let j = 0; j < u8.length; j++)u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.callCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n } else throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/ /*********************************************************************/ // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for(i = 0; i < sin.length && i < buffer_size - 1; i++)this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for(let i = 0; i < u8a.length; i++)this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === \"object\" && fnin instanceof URL)) throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [\n dest,\n src.length\n ];\n } catch (err) {\n console.log(\"fetchAndPutURL Error. URL: \" + fnin + \"\\n\" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while(this.mem8[strIndex + i] && (len === undefined ? true : i < len) && strIndex + i < this.mem8.length){\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array(this.mem8.slice(dataptr, dataptr + size).buffer);\n return u32;\n }\n}\n\n\n\nfunction $4af5689abbc8d01b$export$78724cdcf7ebea1d() {\n return Date.now();\n}\n\n\nclass $aff9c2c494d23fe3$export$9e37856d1928d388 {\n callCompleteSignal;\n parameters;\n constructor(){\n this.callCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(()=>{\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = (0, $4af5689abbc8d01b$export$78724cdcf7ebea1d)();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [\n this.callCompleteSignal.sharedArray,\n this.parameters.buffer\n ];\n }\n processMessage(msgType, data) {\n switch(msgType){\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\nclass $aff9c2c494d23fe3$export$78d2a4633fe89379 {\n callCompleteSignal;\n parameters;\n constructor(params){\n this.callCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\n \"sleep\",\n [\n ms\n ]\n ]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\n \"time\"\n ]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n\n\nlet $3e39efa823870787$var$mod;\nonmessage = function(e) {\n //console.log('twrworker.js: message received from main script: '+e.data);\n if (e.data[0] == \"startup\") {\n const params = e.data[1];\n //console.log(\"Worker startup params:\",params);\n $3e39efa823870787$var$mod = new $3e39efa823870787$var$twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\n $3e39efa823870787$var$mod.loadWasm(params.urlToLoad).then(()=>{\n postMessage([\n \"startupOkay\"\n ]);\n }).catch((ex)=>{\n console.log(\".catch: \", ex);\n postMessage([\n \"startupFail\",\n ex\n ]);\n });\n } else if (e.data[0] == \"callC\") $3e39efa823870787$var$mod.callCImpl(e.data[1], e.data[2]).then((rc)=>{\n postMessage([\n \"callCOkay\",\n rc\n ]);\n }).catch((e)=>{\n console.log(\"exception in callC twrworker.js\\n\");\n console.log(e);\n postMessage([\n \"callCFail\",\n e\n ]);\n });\n else console.log(\"twrworker.js: unknown message: \" + e);\n};\n// ************************************************************************\nclass $3e39efa823870787$var$twrWasmModuleInWorker extends (0, $ece7fa3ed770778a$export$c83a0a3bffe07399) {\n malloc;\n modParams;\n constructor(modParams, modInWorkerParams){\n super();\n this.isWorker = true;\n this.malloc = (size)=>{\n throw new Error(\"error - un-init malloc called\");\n };\n this.modParams = modParams;\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\n const canvasProxy = new (0, $c4741cac81d14197$export$c779b2cd00544976)(modInWorkerParams.canvasProxyParams, this);\n const divProxy = new (0, $8963973702ae5462$export$b377f0bbf2c7581e)(modInWorkerParams.divProxyParams);\n const waitingCallsProxy = new (0, $aff9c2c494d23fe3$export$78d2a4633fe89379)(modInWorkerParams.waitingCallsProxyParams);\n this.modParams.imports = {\n twrDebugLog: (0, $8ac0b786da854328$export$485af4d0039b3389),\n twrSleep: waitingCallsProxy.sleep.bind(waitingCallsProxy),\n twrTime: waitingCallsProxy.time.bind(waitingCallsProxy),\n twrDivCharOut: divProxy.charOut.bind(divProxy),\n twrDivCharIn: divProxy.charIn.bind(divProxy),\n twrCanvasCharIn: canvasProxy.charIn.bind(canvasProxy),\n twrCanvasInkey: canvasProxy.inkey.bind(canvasProxy),\n twrCanvasGetProp: canvasProxy.getProp.bind(canvasProxy),\n twrCanvasDrawSeq: canvasProxy.drawSeq.bind(canvasProxy),\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function(x, y) {\n return x % y;\n },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n}\n\n})();\n//# sourceMappingURL=twrmodworker.2165e649.js.map\n","// this script is the WebWorker thead used by class twrWasmAsyncModule\nimport { twrCanvasProxy } from \"./twrcanvas.js\";\nimport { twrDivProxy } from \"./twrdiv.js\";\nimport { twrDebugLogProxy } from \"./twrdebug.js\";\nimport { twrWasmModuleBase } from \"./twrmodbase.js\";\nimport { twrWaitingCallsProxy } from \"./twrwaitingcalls.js\";\nlet mod;\nonmessage = function (e) {\n //console.log('twrworker.js: message received from main script: '+e.data);\n if (e.data[0] == 'startup') {\n const params = e.data[1];\n //console.log(\"Worker startup params:\",params);\n mod = new twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\n mod.loadWasm(params.urlToLoad).then(() => {\n postMessage([\"startupOkay\"]);\n }).catch((ex) => {\n console.log(\".catch: \", ex);\n postMessage([\"startupFail\", ex]);\n });\n }\n else if (e.data[0] == 'callC') {\n mod.callCImpl(e.data[1], e.data[2]).then((rc) => {\n postMessage([\"callCOkay\", rc]);\n }).catch(e => {\n console.log(\"exception in callC twrworker.js\\n\");\n console.log(e);\n postMessage([\"callCFail\", e]);\n });\n }\n else {\n console.log(\"twrworker.js: unknown message: \" + e);\n }\n};\n// ************************************************************************\nclass twrWasmModuleInWorker extends twrWasmModuleBase {\n malloc;\n modParams;\n constructor(modParams, modInWorkerParams) {\n super();\n this.isWorker = true;\n this.malloc = (size) => { throw new Error(\"error - un-init malloc called\"); };\n this.modParams = modParams;\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\n const canvasProxy = new twrCanvasProxy(modInWorkerParams.canvasProxyParams, this);\n const divProxy = new twrDivProxy(modInWorkerParams.divProxyParams);\n const waitingCallsProxy = new twrWaitingCallsProxy(modInWorkerParams.waitingCallsProxyParams);\n this.modParams.imports = {\n twrDebugLog: twrDebugLogProxy,\n twrSleep: waitingCallsProxy.sleep.bind(waitingCallsProxy),\n twrTime: waitingCallsProxy.time.bind(waitingCallsProxy),\n twrDivCharOut: divProxy.charOut.bind(divProxy),\n twrDivCharIn: divProxy.charIn.bind(divProxy),\n twrCanvasCharIn: canvasProxy.charIn.bind(canvasProxy),\n twrCanvasInkey: canvasProxy.inkey.bind(canvasProxy),\n twrCanvasGetProp: canvasProxy.getProp.bind(canvasProxy),\n twrCanvasDrawSeq: canvasProxy.drawSeq.bind(canvasProxy),\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function (x, y) { return x % y; },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n}\n//# sourceMappingURL=twrmodworker.js.map","// this script is the WebWorker thead used by class twrWasmAsyncModule\r\n\r\nimport {twrCanvasProxy} from \"./twrcanvas.js\";\r\nimport {twrDivProxy} from \"./twrdiv.js\";\r\nimport {twrDebugLogProxy} from \"./twrdebug.js\";\r\nimport {TAsyncModStartupMsg} from \"./twrmodasync.js\"\r\nimport {twrWasmModuleBase, IModInWorkerParams, IModParams} from \"./twrmodbase.js\"\r\nimport {twrWaitingCallsProxy} from \"./twrwaitingcalls.js\";\r\n\r\nlet mod:twrWasmModuleInWorker;\r\n\r\nonmessage = function(e) {\r\n //console.log('twrworker.js: message received from main script: '+e.data);\r\n\r\n if (e.data[0]=='startup') {\r\n const params:TAsyncModStartupMsg=e.data[1];\r\n //console.log(\"Worker startup params:\",params);\r\n mod=new twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\r\n\r\n mod.loadWasm(params.urlToLoad).then( ()=> {\r\n postMessage([\"startupOkay\"]);\r\n }).catch( (ex)=> {\r\n console.log(\".catch: \", ex);\r\n postMessage([\"startupFail\", ex]);\r\n });\r\n }\r\n else if (e.data[0]=='callC') {\r\n mod.callCImpl(e.data[1], e.data[2]).then( (rc)=> {\r\n postMessage([\"callCOkay\", rc]);\r\n }).catch(e => {\r\n console.log(\"exception in callC twrworker.js\\n\");\r\n console.log(e);\r\n postMessage([\"callCFail\", e]);\r\n });\r\n }\r\n else {\r\n console.log(\"twrworker.js: unknown message: \"+e);\r\n }\r\n}\r\n\r\n\r\n// ************************************************************************\r\n\r\nclass twrWasmModuleInWorker extends twrWasmModuleBase {\r\n\tmalloc:(size:number)=>Promise;\r\n modParams: IModParams;\r\n\r\n\r\n constructor(modParams:IModParams, modInWorkerParams:IModInWorkerParams) {\r\n super();\r\n this.isWorker=true;\r\n this.malloc=(size:number)=>{throw new Error(\"error - un-init malloc called\")};\r\n this.modParams=modParams;\r\n\r\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\r\n const canvasProxy = new twrCanvasProxy(modInWorkerParams.canvasProxyParams, this);\r\n const divProxy = new twrDivProxy(modInWorkerParams.divProxyParams);\r\n const waitingCallsProxy = new twrWaitingCallsProxy(modInWorkerParams.waitingCallsProxyParams);\r\n\r\n this.modParams.imports={\r\n twrDebugLog:twrDebugLogProxy,\r\n twrSleep:waitingCallsProxy.sleep.bind(waitingCallsProxy),\r\n twrTime:waitingCallsProxy.time.bind(waitingCallsProxy),\r\n\r\n twrDivCharOut:divProxy.charOut.bind(divProxy), \r\n twrDivCharIn:divProxy.charIn.bind(divProxy), \r\n\r\n twrCanvasCharIn:canvasProxy.charIn.bind(canvasProxy),\r\n twrCanvasInkey:canvasProxy.inkey.bind(canvasProxy),\r\n twrCanvasGetProp:canvasProxy.getProp.bind(canvasProxy),\r\n twrCanvasDrawSeq:canvasProxy.drawSeq.bind(canvasProxy),\r\n\r\n\t\t\ttwrSin:Math.sin,\r\n\t\t\ttwrCos:Math.cos,\r\n\t\t\ttwrTan: Math.tan,\r\n\t\t\ttwrFAbs: Math.abs,\r\n\t\t\ttwrACos: Math.acos,\r\n\t\t\ttwrASin: Math.asin,\r\n\t\t\ttwrATan: Math.atan,\r\n\t\t\ttwrExp: Math.exp,\r\n\t\t\ttwrFloor: Math.floor,\r\n\t\t\ttwrCeil: Math.ceil,\r\n\t\t\ttwrFMod: function(x:number, y:number) {return x%y},\r\n\t\t\ttwrLog: Math.log,\r\n\t\t\ttwrPow: Math.pow,\r\n\t\t\ttwrSqrt: Math.sqrt,\r\n\t\t\ttwrTrunc: Math.trunc,\r\n\r\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\r\n\t\t\ttwrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\r\n\t\t\ttwrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\r\n\t\t\ttwrAtod: this.floatUtil.atod.bind(this.floatUtil),\r\n\t\t\ttwrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\r\n \r\n }\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nimport { twrSignal } from \"./twrsignal.js\";\nvar D2DType;\n(function (D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})(D2DType || (D2DType = {}));\nexport class twrCanvas {\n ctx;\n props = { charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight: 0, canvasWidth: 0 };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase) {\n const { forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new twrSignal();\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext)\n throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c)\n throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2)\n throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\n }\n getProp(pn) {\n if (!this.isValid())\n console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */\n drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid())\n console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx)\n return;\n let ins = this.owner.getLong(ds); /* ds->start */\n const lastins = this.owner.getLong(ds + 4); /* ds->last */\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while (1) {\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */\n if (0 /*type!=D2DType.D2D_FILLRECT*/) {\n console.log(\"ins\", ins);\n console.log(\"hdr.next\", this.owner.mem8[ins], this.owner.mem8[ins + 1], this.owner.mem8[ins + 2], this.owner.mem8[ins + 3]);\n console.log(\"hdr.type\", this.owner.mem8[ins + 4], this.owner.mem8[ins + 5]);\n console.log(\"next 4 bytes\", this.owner.mem8[ins + 6], this.owner.mem8[ins + 7], this.owner.mem8[ins + 8], this.owner.mem8[ins + 9]);\n console.log(\"and 4 more \", this.owner.mem8[ins + 10], this.owner.mem8[ins + 11], this.owner.mem8[ins + 12], this.owner.mem8[ins + 13]);\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\n }\n switch (type) {\n case D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case D2DType.D2D_BEGINPATH:\n {\n this.ctx.beginPath();\n }\n break;\n case D2DType.D2D_FILL:\n {\n this.ctx.fill();\n }\n break;\n case D2DType.D2D_SAVE:\n {\n this.ctx.save();\n }\n break;\n case D2DType.D2D_RESTORE:\n {\n this.ctx.restore();\n }\n break;\n case D2DType.D2D_STROKE:\n {\n this.ctx.stroke();\n }\n break;\n case D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = (this.owner.getLong(ins + 48) != 0);\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n }\n else { // Uint8ClampedArray doesn't support shared memory\n this.precomputedObjects[id] = { mem8: new Uint8Array(this.owner.memory.buffer, start, length), width: width, height: height };\n }\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id])\n delete this.precomputedObjects[id];\n else\n console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) {\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n }\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) {\n this.ctx.putImageData(imgData, dx, dy);\n }\n else {\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */\n if (next == 0) {\n if (ins != lastins)\n throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal)\n this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nexport class twrCanvasProxy {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner) {\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new twrSignal(signalBuffer);\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\"drawseq\", [ds]]);\n this.drawCompleteSignal.wait();\n }\n}\n//# sourceMappingURL=twrcanvas.js.map","import {twrWasmModuleBase, IModParams} from \"./twrmodbase.js\"\r\nimport {twrSharedCircularBuffer} from \"./twrcircular.js\";\r\nimport {twrSignal} from \"./twrsignal.js\";\r\n\r\n\r\n// Canvas have a size that will be set based on the character width x height\r\n// The display size for a canvas will default to this size, but can be changed in the HTML/JS via\r\n// canvas.style.width = \"700px\";\r\n// canvas.style.height = \"500px\";\r\n\r\nexport interface ICanvasProps {\r\n\tcharWidth: number,\r\n\tcharHeight: number,\r\n\tforeColor: number,\r\n\tbackColor: number,\r\n widthInChars: number,\r\n heightInChars: number,\r\n canvasWidth:number,\r\n canvasHeight:number\r\n}\r\n\r\nenum D2DType {\r\n D2D_FILLRECT=1,\r\n D2D_FILLCHAR=5,\r\n D2D_SETLINEWIDTH=10,\r\n D2D_SETFILLSTYLERGBA=11,\r\n D2D_SETFONT=12,\r\n D2D_BEGINPATH=13,\r\n D2D_MOVETO=14,\r\n D2D_LINETO=15,\r\n D2D_FILL=16,\r\n D2D_STROKE=17,\r\n D2D_SETSTROKESTYLERGBA=18,\r\n D2D_ARC=19,\r\n D2D_STROKERECT=20,\r\n D2D_FILLTEXT=21,\r\n D2D_IMAGEDATA=22,\r\n D2D_PUTIMAGEDATA=23,\r\n D2D_BEZIERTO=24,\r\n D2D_MEASURETEXT=25,\r\n D2D_SAVE=26,\r\n D2D_RESTORE=27,\r\n D2D_CREATERADIALGRADIENT=28,\r\n D2D_SETCOLORSTOP=29,\r\n D2D_SETFILLSTYLEGRADIENT=30,\r\n D2D_RELEASEID=31,\r\n D2D_CREATELINEARGRADIENT=32,\r\n D2D_SETFILLSTYLE=33,\r\n D2D_SETSTROKESTYLE=34\r\n\r\n}\r\n\r\nexport type TCanvasProxyParams = [ICanvasProps, SharedArrayBuffer, SharedArrayBuffer];\r\n\r\nexport interface ICanvas {\r\n props: ICanvasProps,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TCanvasProxyParams,\r\n drawSeq: (ds:number)=>void,\r\n }\r\n \r\nexport class twrCanvas implements ICanvas {\r\n ctx:CanvasRenderingContext2D|undefined;\r\n props:ICanvasProps={charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight:0, canvasWidth:0};\r\n owner: twrWasmModuleBase;\r\n cmdCompleteSignal?:twrSignal;\r\n canvasKeys?: twrSharedCircularBuffer;\r\n precomputedObjects: { [index: number]: \r\n (ImageData | {mem8:Uint8Array, width:number, height:number}) |\r\n CanvasGradient\r\n };\r\n\r\n constructor(element:HTMLCanvasElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n const {forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas} = modParams; \r\n this.owner=modbase;\r\n this.props.widthInChars=modParams.windim[0];\r\n this.props.heightInChars=modParams.windim[1];\r\n\r\n if (!this.owner.isWasmModule) {\r\n this.cmdCompleteSignal=new twrSignal();\r\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n }\r\n\r\n this.precomputedObjects={};\r\n \r\n if (element) {\r\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\r\n let c=element.getContext(\"2d\");\r\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\r\n\r\n c.font = fontsize.toString()+\"px Courier New\";\r\n c.textBaseline=\"top\";\r\n const sampleText=\" \";\r\n const tm=c.measureText(sampleText);\r\n this.props.charWidth=Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\r\n let fM = c.measureText(\"X\"); \r\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\r\n\r\n if (!isd2dcanvas) {\r\n element.width=this.props.charWidth*this.props.widthInChars;\r\n element.height=this.props.charHeight*this.props.heightInChars;\r\n }\r\n\r\n this.props.canvasHeight=element.height;\r\n this.props.canvasWidth=element.width;\r\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\r\n\r\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\r\n let c2=element.getContext(\"2d\");\r\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\r\n this.ctx=c2;\r\n this.ctx.font = fontsize.toString()+\"px Courier New\";\r\n this.ctx.textBaseline=\"top\";\r\n\r\n c2.fillStyle=backcolor;\r\n this.props.backColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n c2.fillStyle=forecolor;\r\n this.props.foreColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n }\r\n\r\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\r\n\r\n //console.log(\"twrCanvas.constructor props: \", this.props);\r\n }\r\n\r\n isValid() {\r\n return !!this.ctx;\r\n }\r\n\r\n getProxyParams() : TCanvasProxyParams {\r\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\r\n }\r\n\r\n getProp(pn:number): number {\r\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n\r\n/* see draw2d.h for structs that match */\r\n\r\n drawSeq(ds:number) {\r\n //console.log(\"twr::Canvas enter drawSeq\");\r\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\r\n if (!this.ctx) return;\r\n\r\n let ins=this.owner.getLong(ds); /* ds->start */\r\n const lastins=this.owner.getLong(ds+4); /* ds->last */\r\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\r\n\r\n let next:number;\r\n //let insCount=0;\r\n\r\n while (1) {\r\n\r\n //insCount++;\r\n\r\n const type:D2DType=this.owner.getLong(ins+4); /* hdr->type */\r\n if (0/*type!=D2DType.D2D_FILLRECT*/) {\r\n console.log(\"ins\",ins)\r\n console.log(\"hdr.next\",this.owner.mem8[ins],this.owner.mem8[ins+1],this.owner.mem8[ins+2],this.owner.mem8[ins+3]);\r\n console.log(\"hdr.type\",this.owner.mem8[ins+4],this.owner.mem8[ins+5]);\r\n console.log(\"next 4 bytes\", this.owner.mem8[ins+6],this.owner.mem8[ins+7],this.owner.mem8[ins+8],this.owner.mem8[ins+9]);\r\n console.log(\"and 4 more \", this.owner.mem8[ins+10],this.owner.mem8[ins+11],this.owner.mem8[ins+12],this.owner.mem8[ins+13]);\r\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\r\n }\r\n switch (type) {\r\n case D2DType.D2D_FILLRECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.fillRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKERECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.strokeRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILLCHAR:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const c=this.owner.getShort(ins+24);\r\n let txt=String.fromCharCode(c);\r\n this.ctx.fillText(txt, x, y);\r\n }\r\n break;\r\n\r\n \r\n case D2DType.D2D_FILLTEXT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const str=this.owner.getString(this.owner.getLong(ins+24));\r\n\r\n //console.log(\"filltext \",x,y,str)\r\n \r\n this.ctx.fillText(str, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MEASURETEXT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n const tmidx=this.owner.getLong(ins+12);\r\n \r\n const tm=this.ctx.measureText(str);\r\n this.owner.setDouble(tmidx+0, tm.actualBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+8, tm.actualBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+16, tm.actualBoundingBoxLeft);\r\n this.owner.setDouble(tmidx+24, tm.actualBoundingBoxRight);\r\n this.owner.setDouble(tmidx+32, tm.fontBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+40, tm.fontBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+48, tm.width);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFONT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.font=str;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.fillStyle = cssColor;\r\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETSTROKESTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.fillStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETSTROKESTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETLINEWIDTH:\r\n {\r\n const width=this.owner.getShort(ins+8); \r\n this.ctx.lineWidth=width;\r\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MOVETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.moveTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_LINETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.lineTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEZIERTO:\r\n {\r\n const cp1x=this.owner.getDouble(ins+8);\r\n const cp1y=this.owner.getDouble(ins+16);\r\n const cp2x=this.owner.getDouble(ins+24);\r\n const cp2y=this.owner.getDouble(ins+32);\r\n const x=this.owner.getDouble(ins+40);\r\n const y=this.owner.getDouble(ins+48);\r\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEGINPATH:\r\n {\r\n this.ctx.beginPath();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILL:\r\n {\r\n this.ctx.fill();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SAVE:\r\n {\r\n this.ctx.save();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_RESTORE:\r\n {\r\n this.ctx.restore();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKE:\r\n {\r\n this.ctx.stroke();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_ARC:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const radius=this.owner.getDouble(ins+24);\r\n const startAngle=this.owner.getDouble(ins+32);\r\n const endAngle=this.owner.getDouble(ins+40);\r\n const counterClockwise= (this.owner.getLong(ins+48)!=0);\r\n\r\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_IMAGEDATA:\r\n {\r\n const start=this.owner.getLong(ins+8);\r\n const length=this.owner.getLong(ins+12);\r\n const width=this.owner.getLong(ins+16);\r\n const height=this.owner.getLong(ins+20);\r\n const id=this.owner.getLong(ins+24);\r\n\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\r\n\r\n if (this.owner.isWasmModule) {\r\n const z = new Uint8ClampedArray(this.owner.memory!.buffer, start, length);\r\n this.precomputedObjects[id]=new ImageData(z, width, height);\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory\r\n this.precomputedObjects[id]={mem8: new Uint8Array(this.owner.memory!.buffer, start, length), width:width, height:height};\r\n }\r\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_CREATERADIALGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const radius0=this.owner.getDouble(ins+24);\r\n const x1=this.owner.getDouble(ins+32);\r\n const y1=this.owner.getDouble(ins+40);\r\n const radius1=this.owner.getDouble(ins+48);\r\n const id= this.owner.getLong(ins+56);\r\n\r\n let gradient=this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_CREATELINEARGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const x1=this.owner.getDouble(ins+24);\r\n const y1=this.owner.getDouble(ins+32);\r\n const id= this.owner.getLong(ins+40);\r\n \r\n let gradient=this.ctx.createLinearGradient(x0, y0, x1, y1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETCOLORSTOP:\r\n {\r\n const id = this.owner.getLong(ins+8);\r\n const pos=this.owner.getLong(ins+12);\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+16));\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n gradient.addColorStop(pos, cssColor);\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n this.ctx.fillStyle=gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_RELEASEID:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (this.precomputedObjects[id])\r\n delete this.precomputedObjects[id];\r\n else\r\n console.log(\"warning: D2D_RELEASEID with undefined ID \",id);\r\n }\r\n break\r\n\r\n \r\n\r\n case D2DType.D2D_PUTIMAGEDATA:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n const dx=this.owner.getLong(ins+12);\r\n const dy=this.owner.getLong(ins+16);\r\n const dirtyX=this.owner.getLong(ins+20);\r\n const dirtyY=this.owner.getLong(ins+24);\r\n const dirtyWidth=this.owner.getLong(ins+28);\r\n const dirtyHeight=this.owner.getLong(ins+32);\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \"+id);\r\n\r\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\r\n\r\n let imgData:ImageData;\r\n if (this.owner.isWasmModule) {\r\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\r\n imgData=this.precomputedObjects[id] as ImageData;\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\r\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\r\n const z = this.precomputedObjects[id] as {mem8:Uint8Array, width:number, height:number}; // Uint8Array\r\n const ca=Uint8ClampedArray.from(z.mem8); // shallow copy\r\n imgData=new ImageData(ca, z.width, z.height);\r\n }\r\n \r\n if (dirtyWidth==0 && dirtyHeight==0) {\r\n this.ctx.putImageData(imgData, dx, dy);\r\n }\r\n else {\r\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\r\n }\r\n }\r\n break;\r\n\r\n default:\r\n throw new Error (\"unimplemented or unknown Sequence Type in drawSeq: \"+type);\r\n }\r\n next=this.owner.getLong(ins); /* hdr->next */\r\n if (next==0) {\r\n if (ins!=lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\r\n break;\r\n }\r\n ins=next;\r\n }\r\n\r\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\r\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\r\n }\r\n}\r\n\r\nexport class twrCanvasProxy implements ICanvas {\r\n canvasKeys: twrSharedCircularBuffer;\r\n drawCompleteSignal:twrSignal;\r\n props: ICanvasProps;\r\n owner: twrWasmModuleBase;\r\n\r\n constructor(params:TCanvasProxyParams, owner:twrWasmModuleBase) {\r\n const [props, signalBuffer, canvasKeysBuffer] = params;\r\n this.drawCompleteSignal = new twrSignal(signalBuffer);\r\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\r\n this.props=props;\r\n this.owner=owner;\r\n\r\n //console.log(\"Create New twrCanvasProxy: \",this.props)\r\n\r\n }\r\n\r\n charIn() { \r\n //ctx.commit(); not avail in chrome\r\n \r\n //postMessage([\"debug\", 'x']);\r\n \r\n return this.canvasKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.canvasKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n getProp(pn:number): number {\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n \r\n drawSeq(ds:number) {\r\n this.drawCompleteSignal.reset();\r\n postMessage([\"drawseq\", [ds]]);\r\n this.drawCompleteSignal.wait();\r\n }\r\n}\r\n","//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst RDIDX = 256;\nconst WRIDX = 257;\nconst LEN = 256;\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\n// the first 256 array entries are the circular buffer\n// the next two are used for the read and write index\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\nexport class twrSharedCircularBuffer {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(258 * 4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[RDIDX] = 0;\n this.buf[WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[WRIDX];\n this.buf[i] = n;\n i++;\n if (i == LEN)\n i = 0;\n this.buf[WRIDX] = i;\n Atomics.notify(this.buf, WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[RDIDX] = i;\n return n;\n }\n else\n return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[RDIDX] == this.buf[WRIDX];\n }\n}\n//# sourceMappingURL=twrcircular.js.map","//\r\n// This class implements a circular buffer that the main javascript thread can write to, \r\n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\r\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \r\n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\r\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\r\n//\r\n\r\nconst RDIDX=256;\r\nconst WRIDX=257;\r\nconst LEN=256;\r\n\r\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\r\n// the first 256 array entries are the circular buffer\r\n// the next two are used for the read and write index\r\n\r\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\r\n\r\nexport class twrSharedCircularBuffer {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n \r\n\tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(258*4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[RDIDX]=0;\r\n this.buf[WRIDX]=0;\r\n\t}\r\n\r\n\twrite(n:number) {\r\n let i=this.buf[WRIDX];\r\n this.buf[i]=n;\r\n i++;\r\n if (i==LEN) i=0;\r\n this.buf[WRIDX]=i; \r\n Atomics.notify(this.buf, WRIDX); \r\n\t}\r\n\r\n\tread():number {\r\n if (!this.isEmpty()) {\r\n let i=this.buf[RDIDX];\r\n let n=this.buf[i];\r\n i++;\r\n this.buf[RDIDX]=i;\r\n return n;\r\n }\r\n\t\telse\r\n return -1;\r\n\t}\r\n\r\n readWait():number {\r\n if (this.isEmpty()) {\r\n const rdptr=this.buf[RDIDX];\r\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\r\n Atomics.wait(this.buf, WRIDX, rdptr);\r\n }\r\n return this.read();\r\n\t}\r\n\r\n isEmpty():boolean {\r\n return this.buf[RDIDX]==this.buf[WRIDX];\r\n }\r\n}\r\n","//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar twrSignalState;\n(function (twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})(twrSignalState || (twrSignalState = {}));\n;\nexport class twrSignal {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window valid\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == twrSignalState.WAITING) {\n //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\n //console.log(\"released...\");\n }\n }\n isSignaled() {\n return this.buf[0] == twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = twrSignalState.WAITING;\n }\n}\n//# sourceMappingURL=twrsignal.js.map","//\r\n// This class implements a simple signal/wait mechanism\r\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\r\n//\r\n\r\nenum twrSignalState {\r\n WAITING=0,\r\n SIGNALED=1\r\n};\r\n\r\nexport class twrSignal {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n\r\n \tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window valid\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) \r\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[0]=twrSignalState.WAITING;\r\n\t}\r\n\r\n\tsignal() {\r\n this.buf[0]=twrSignalState.SIGNALED; \r\n //console.log(\"about to signal\");\r\n Atomics.notify(this.buf, 0); \r\n\t}\r\n\r\n wait() {\r\n if (this.buf[0]==twrSignalState.WAITING) {\r\n //console.log(\"waiting...\");\r\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\r\n //console.log(\"released...\");\r\n\r\n }\r\n\t}\r\n isSignaled():boolean {\r\n return this.buf[0]==twrSignalState.SIGNALED;\r\n }\r\n\r\n reset() {\r\n this.buf[0]=twrSignalState.WAITING;\r\n }\r\n}\r\n","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nexport class twrDiv {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase) {\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\n this.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n if (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.divKeys.sharedArray];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */\n charOut(ch) {\n if (!this.div)\n return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n }\n switch (ch) {\n case 10: // newline\n case 13: // return\n if (ch == 10 && this.lastChar == 13)\n break; // detect CR LF and treat as single new line\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8: // backspace\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n case 0xE: // cursor on\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF: // cursor off\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for (let i = 0; i < str.length; i++)\n this.charOut(str.charCodeAt(i));\n }\n}\nexport class twrDivProxy {\n divKeys;\n constructor(params) {\n const [divKeysBuffer] = params;\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n charOut(ch) {\n postMessage([\"divout\", ch]);\n }\n}\n//# sourceMappingURL=twrdiv.js.map","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\r\nimport { IModParams } from \"./twrmodbase.js\";\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\";\r\n\r\nexport type TDivProxyParams = [SharedArrayBuffer];\r\n\r\nexport interface IDiv {\r\n charOut: (ds:number)=>void,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TDivProxyParams,\r\n }\r\n\r\n\r\nexport class twrDiv implements IDiv {\r\n\tdiv:HTMLDivElement|null|undefined;\r\n\tdivKeys?:twrSharedCircularBuffer;\r\n\tCURSOR=String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\r\n\tcursorOn:boolean=false;\r\n\tlastChar:number=0;\r\n\textraBR:boolean=false;\r\n\towner:twrWasmModuleBase;\r\n\r\n constructor(element:HTMLDivElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n\t\tthis.div=element;\r\n\t\tthis.owner=modbase;\r\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\r\n\t\t\tthis.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n\t\t}\r\n\r\n\t\tif (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\r\n\t\t\tthis.div.style.backgroundColor = modParams.backcolor;\r\n\t\t\tthis.div.style.color = modParams.forecolor;\r\n\t\t\tthis.div.style.font=modParams.fontsize.toString()+\"px arial\"\r\n\t\t}\r\n }\r\n\r\n\tisValid() {\r\n\t\treturn !!this.div;\r\n\t}\r\n\r\n getProxyParams() : TDivProxyParams {\r\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [ this.divKeys.sharedArray];\r\n }\r\n\r\n\r\n/* \r\n * add character to div. Supports the following control codes:\r\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\r\n * 0xE cursor on \r\n * 0x8 backspace\r\n * 0xF cursor off \r\n*/\r\n\tcharOut(ch:number) {\r\n\r\n\t\tif (!this.div) return;\r\n\r\n\t\t//console.log(\"div::charout: \", ch);\r\n\r\n\t\tif (this.extraBR) {\r\n\t\t\tthis.extraBR=false;\r\n\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -4);\r\n\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t}\r\n\r\n\t\tswitch (ch) {\r\n\t\t\tcase 10: // newline\r\n\t\t\tcase 13: // return\r\n\t\t\t\tif (ch==10 && this.lastChar==13) break; // detect CR LF and treat as single new line\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\r\n\t\t\t\tthis.extraBR=true;\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\t//element.scrollIntoView();\r\n\t\t\t\t//element.scrollTop = element.scrollHeight;\r\n\t\t\t\tlet p = this.div.getBoundingClientRect();\r\n\t\t\t\twindow.scrollTo(0, p.height+100);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 8: // backspace\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xE: // cursor on\r\n\t\t\t\tif (!this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=true;\r\n\t\t\t\t\tthis.div.innerHTML += this.CURSOR;\r\n\t\t\t\t\tthis.div.focus();\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xF: // cursor off\r\n\t\t\t\tif (this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=false;\r\n\t\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += String.fromCharCode(ch);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\tthis.lastChar=ch;\r\n\t}\r\n\r\n\tstringOut(str:string) {\r\n\t\tfor (let i=0; i < str.length; i++)\r\n\t\t\tthis.charOut(str.charCodeAt(i));\r\n\t}\r\n}\r\n\r\n\r\nexport class twrDivProxy implements IDiv {\r\n divKeys: twrSharedCircularBuffer;\r\n\r\n constructor(params:TDivProxyParams) {\r\n const [divKeysBuffer] = params;\r\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\r\n }\r\n\r\n charIn() { \r\n return this.divKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.divKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n\tcharOut(ch:number) {\r\n\t\tpostMessage([\"divout\", ch]);\r\n\t}\r\n}\r\n\r\n","let logline = \"\";\nexport function twrDebugLogImpl(char) {\n if (char == 10 || char == 3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\n console.log(logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n logline = \"\";\n }\n else {\n logline = logline + String.fromCharCode(char);\n if (logline.length >= 200) {\n console.log(logline);\n logline = \"\";\n }\n }\n}\n// ************************************************************************\n// debugLog doesn't currently wait for the message to log, it returns immediately.\n// I could move this to be in the twrWaitingCalls class\nexport function twrDebugLogProxy(ch) {\n postMessage([\"debug\", ch]);\n}\n//# sourceMappingURL=twrdebug.js.map","\r\nlet logline=\"\";\r\nexport function twrDebugLogImpl(char:number) {\r\n\tif (char==10 || char==3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\r\n\t\tconsole.log(logline);\t// ideally without a linefeed, but there is no way to not have a LF with console.log API.\r\n\t\tlogline=\"\";\r\n\t}\r\n\telse {\r\n\t\tlogline=logline+String.fromCharCode(char);\r\n\t\tif (logline.length>=200) {\r\n\t\t\tconsole.log(logline);\r\n\t\t\tlogline=\"\";\r\n\t\t}\r\n\t}\r\n}\r\n\r\n// ************************************************************************\r\n// debugLog doesn't currently wait for the message to log, it returns immediately.\r\n// I could move this to be in the twrWaitingCalls class\r\nexport function twrDebugLogProxy(ch:number) {\r\n postMessage([\"debug\", ch]);\r\n}\r\n\r\n","import { twrFloatUtil } from \"./twrfloat.js\";\n/*********************************************************************/\n/*********************************************************************/\n/*********************************************************************/\nexport class twrWasmModuleBase {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\n floatUtil;\n constructor(isWasmModule = false) {\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new twrFloatUtil(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/\n /*********************************************************************/\n async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n }\n catch (err) {\n console.log('loadWasm() failed to fetch: ' + pathToLoad);\n throw err;\n }\n if (!response.ok)\n throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, { env: allimports });\n this.exports = instance.instance.exports;\n if (!this.exports)\n throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory)\n throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory)\n throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer)\n console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\"setmemory\", this.memory]);\n }\n if (this.isWasmModule) {\n // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (!(this.memory.buffer instanceof ArrayBuffer))\n console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size) => {\n return new Promise(resolve => {\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n }\n catch (err) {\n console.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch (this.modParams.stdio) {\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* callC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */\n async callC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.callCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async callCImpl(fname, cparams = []) {\n if (!this.exports)\n throw new Error(\"this.exports undefined\");\n if (!this.exports[fname])\n throw new Error(\"callC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array))\n throw new Error(\"callC: params must be array, first arg is function name\");\n if (params.length == 0)\n throw new Error(\"callC: missing function name\");\n let cparams = [];\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n cparams[ci++] = p;\n break;\n case 'string':\n cparams[ci++] = await this.putString(p);\n break;\n case 'object':\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n }\n else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"callC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n ci++;\n break;\n case 'string':\n this.callCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n case 'object':\n if (p instanceof URL) {\n this.callCImpl('twr_free', [cparams[ci]]);\n ci = ci + 2;\n break;\n }\n else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for (let j = 0; j < u8.length; j++)\n u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.callCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n }\n else\n throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/\n /*********************************************************************/\n // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for (i = 0; i < sin.length && i < buffer_size - 1; i++)\n this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for (let i = 0; i < u8a.length; i++)\n this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === 'object' && fnin instanceof URL))\n throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [dest, src.length];\n }\n catch (err) {\n console.log('fetchAndPutURL Error. URL: ' + fnin + '\\n' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while (this.mem8[strIndex + i] && (len === undefined ? true : i < len) && (strIndex + i) < this.mem8.length) {\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0)\n throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array((this.mem8.slice(dataptr, dataptr + size)).buffer);\n return u32;\n }\n}\n//# sourceMappingURL=twrmodbase.js.map","\r\nimport {TCanvasProxyParams} from \"./twrcanvas.js\"\r\nimport {TDivProxyParams} from \"./twrdiv.js\";\r\nimport {TWaitingCallsProxyParams} from \"./twrwaitingcalls.js\"\r\nimport {twrDebugLogImpl} from \"./twrdebug.js\";\r\nimport {twrFloatUtil} from \"./twrfloat.js\";\r\n\r\n\r\nexport type TStdioVals=\"div\"|\"canvas\"|\"null\"|\"debug\";\r\n\r\nexport interface IModOpts {\r\n\tstdio?:TStdioVals, \r\n\twindim?:[number, number],\r\n\tforecolor?:string,\r\n\tbackcolor?:string,\r\n\tfontsize?:number,\r\n\tisd2dcanvas?:boolean,\r\n\timports?:{},\r\n}\r\n\r\nexport interface IModParams {\r\n\tstdio:TStdioVals, \r\n\twindim:[number, number],\r\n\tforecolor:string,\r\n\tbackcolor:string,\r\n\tfontsize:number,\r\n\tstyleIsDefault: boolean\r\n\tisd2dcanvas:boolean,\r\n\timports:{[index:string]:Function},\r\n}\r\n\r\nexport interface IModInWorkerParams {\r\n\tdivProxyParams:TDivProxyParams,\r\n\tcanvasProxyParams:TCanvasProxyParams,\r\n\twaitingCallsProxyParams:TWaitingCallsProxyParams,\r\n}\r\n\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n\r\nexport abstract class twrWasmModuleBase {\r\n\tmemory?:WebAssembly.Memory;\r\n\tmem8:Uint8Array;\r\n\tmem32:Uint32Array;\r\n\tmemD:Float64Array;\r\n\tabstract malloc:(size:number)=>Promise;\r\n\tabstract modParams:IModParams;\r\n\texports?:WebAssembly.Exports;\r\n\tisWorker=false;\r\n\tisWasmModule:boolean; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\r\n\tfloatUtil:twrFloatUtil;\r\n\r\n\tconstructor(isWasmModule=false) {\r\n\t\tthis.isWasmModule=isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\r\n\t\tthis.mem8=new Uint8Array(); \t// avoid type errors\r\n\t\tthis.mem32=new Uint32Array(); // avoid type errors\r\n\t\tthis.memD=new Float64Array(); // avoid type errors\r\n\t\tthis.floatUtil=new twrFloatUtil(this);\r\n\t\t//console.log(\"size of mem8 after constructor\",this.mem8.length);\r\n\t}\r\n\r\n\t/*********************************************************************/\r\n\t/*********************************************************************/\r\n\r\n\tasync loadWasm(pathToLoad:string) {\r\n\t\t//console.log(\"fileToLoad\",fileToLoad)\r\n\r\n\t\tlet response;\r\n\t\ttry {\r\n\t\t\tresponse=await fetch(pathToLoad);\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('loadWasm() failed to fetch: '+pathToLoad);\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t\t\r\n\t\tif (!response.ok) throw new Error(\"fetch response error on file '\"+pathToLoad+\"'\\n\"+response.statusText);\r\n\r\n\t\ttry {\r\n\t\t\tlet wasmBytes = await response.arrayBuffer();\r\n\r\n\t\t\tlet allimports:WebAssembly.ModuleImports = { \r\n\t\t\t\t...this.modParams.imports\r\n\t\t\t};\r\n\r\n\t\t\tlet instance = await WebAssembly.instantiate(wasmBytes, {env: allimports});\r\n\r\n\t\t\tthis.exports=instance.instance.exports;\r\n\t\t\tif (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\r\n\r\n\t\t\tif (this.memory) throw new Error (\"unexpected error -- this.memory already set\");\r\n\t\t\tthis.memory=this.exports.memory as WebAssembly.Memory;\r\n\t\t\tif (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\r\n\t\t\tthis.mem8 = new Uint8Array(this.memory.buffer);\r\n\t\t\tthis.mem32 = new Uint32Array(this.memory.buffer);\r\n\t\t\tthis.memD = new Float64Array(this.memory.buffer);\r\n\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\tif (this.isWorker) {\r\n\t\t\t\tif (this.memory.buffer instanceof ArrayBuffer)\r\n\t\t\t\t\tconsole.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\r\n\t\t\t\t\r\n\t\t\t\tpostMessage([\"setmemory\",this.memory]);\r\n\t\t\t}\r\n\t\t\tif (this.isWasmModule) {\r\n\t\t\t\t// here if twrWasmModule, twrWasmModuleAsync overrides this function\r\n\t\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\t\tif (!(this.memory.buffer instanceof ArrayBuffer))\r\n\t\t\t\t\tconsole.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\r\n\t\t\t}\r\n\r\n\t\t\tthis.malloc=(size:number)=>{\r\n\t\t\t\treturn new Promise(resolve => {\r\n\t\t\t\t\tconst m=this.exports!.twr_malloc as (size:number)=>number;\r\n\t\t\t\t\tresolve(m(size));\r\n\t\t\t\t});\r\n\t\t };\r\n\r\n\t\t\tthis.init();\r\n\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t}\r\n\r\n\tprivate init() {\r\n\t\t//console.log(\"loadWasm.init() enter\")\r\n\t\t\tlet p:number;\r\n\t\t\tswitch (this.modParams.stdio) {\r\n\t\t\t\tcase \"debug\":\r\n\t\t\t\t\tp=0;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"div\":\r\n\t\t\t\t\tp=1;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"canvas\":\r\n\t\t\t\t\tp=2;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"null\":\r\n\t\t\t\t\tp=3;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tp=0; // debug\r\n\t\t\t}\r\n\r\n\t\t\tconst twrInit=this.exports!.twr_wasm_init as CallableFunction;\r\n\t\t\t//console.log(\"twrInit:\",twrInit)\r\n\t\t\ttwrInit(p, this.mem8.length);\r\n\t}\r\n\r\n\t/* callC takes an array where:\r\n\t* the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\r\n\t* and the next entries are a variable number of parameters to pass to the C function, of type\r\n\t* number - converted to int32 or float64 as appropriate\r\n\t* string - converted to a an index (ptr) into a module Memory returned via stringToMem()\r\n\t* URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\r\n\t* Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\r\n */\r\n\r\n\tasync callC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\t\tconst cparams=await this.preCallC(params);\r\n\t\tlet retval = this.callCImpl(params[0], cparams);\r\n\t\tthis.postCallC(cparams, params);\r\n\t\treturn retval;\r\n\t}\r\n\r\n\tasync callCImpl(fname:string, cparams:number[]=[]) {\r\n\t\tif (!this.exports) throw new Error(\"this.exports undefined\");\r\n\t\tif (!this.exports[fname]) throw new Error(\"callC: function '\"+fname+\"' not in export table. Use --export wasm-ld flag.\");\r\n\r\n\t\tconst f = this.exports[fname] as CallableFunction;\r\n\t\tlet cr=f(...cparams);\r\n\r\n\t\treturn cr;\r\n\t}\r\n\r\n\t// convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\r\n\tasync preCallC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tif (!(params.constructor === Array)) throw new Error (\"callC: params must be array, first arg is function name\");\r\n\t\tif (params.length==0) throw new Error(\"callC: missing function name\");\r\n\r\n\t\tlet cparams:number[]=[];\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tcparams[ci++]=p;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tcparams[ci++]=await this.putString(p);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tconst r=await this.fetchAndPutURL(p);\r\n\t\t\t\t\t\tcparams[ci++]=r[0]; // mem index\r\n\t\t\t\t\t\tcparams[ci++]=r[1]; // len\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tconst r=await this.putArrayBuffer(p);\r\n\t\t\t\t\t\tcparams[ci++]=r; // mem index\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tthrow new Error (\"callC: invalid object type passed in\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn cparams;\r\n\t}\r\n\r\n\t// free the mallocs; copy array buffer data from malloc back to arraybuffer\r\n\tasync postCallC(cparams:number[], params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tthis.callCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t\t\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tthis.callCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\t\tci=ci+2;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tlet u8=new Uint8Array(p);\r\n\t\t\t\t\t\tfor (let j=0; j= this.mem32.length) throw new Error(\"invalid index passed to getLong: \"+idx+\", this.mem32.length: \"+this.mem32.length);\r\n\t\tconst long:number = this.mem32[idx32];\r\n\t\treturn long;\r\n\t}\r\n\t\r\n\tsetLong(idx:number, value:number) {\r\n const idx32 = Math.floor(idx / 4);\r\n if (idx32 * 4 != idx)\r\n throw new Error(\"setLong passed non long aligned address\");\r\n if (idx32 < 0 || idx32 >= this.mem32.length)\r\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\r\n this.mem32[idx32]=value;\r\n }\r\n\r\n\tgetDouble(idx:number): number {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"getLong passed non Float64 aligned address\")\r\n\t\tconst long:number = this.memD[idx64];\r\n\t\treturn long;\r\n\t}\r\n\r\n\tsetDouble(idx:number, value:number) {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"setDouble passed non Float64 aligned address\")\r\n\t\tthis.memD[idx64]=value;\r\n\t}\r\n\r\n\tgetShort(idx:number): number {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getShort: \"+idx);\r\n\t\tconst short:number = this.mem8[idx]+this.mem8[idx+1]*256;\r\n\t\treturn short;\r\n\t}\r\n\r\n\t// get a string out of module memory\r\n\t// null terminated, up until max of (optional) len\r\n\tgetString(strIndex:number, len?:number): string {\r\n\t\tlet sout=\"\";\r\n\r\n\t\tlet i=0;\r\n\t\twhile (this.mem8[strIndex+i] && (len===undefined?true:i= this.mem8.length) throw new Error(\"invalid index passed to getU8: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU8\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU8\")\r\n\r\n\t\tconst u8=this.mem8.slice(dataptr, dataptr+size);\r\n\t\treturn u8;\r\n\t}\r\n\r\n\t// get a int32 array out of module memory when passed in index to [size, dataptr]\r\n\tgetU32Arr(idx:number): Uint32Array {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getU32: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU32\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU32\")\r\n\r\n\t\tif (size%4!=0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\r\n\r\n\t\tconst u32 = new Uint32Array( (this.mem8.slice(dataptr, dataptr+size)).buffer );\r\n\t\treturn u32;\r\n\t}\r\n}\r\n","export class twrFloatUtil {\n mod;\n constructor(mod) {\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\")\n return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\")\n return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll('D', 'e').replaceAll('d', 'e'));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n }\n else {\n let r = value.toString();\n if (r.length > max_precision)\n r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, // char *\n sizeInBytes, //size_t\n value, // double\n fracpart_numdigits, //int\n dec, // int *\n sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1)\n return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) { /* nan */\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (!Number.isFinite(value)) { /* infinity */\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n }\n else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split('.');\n if (intPart == \"0\")\n intPart = \"\";\n if (intPart.length > 0) { // has integer part\n decpos = intPart.length;\n digits = intPart + fracPart;\n }\n else { // only a fraction\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length)\n return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */\n }\n}\n//# sourceMappingURL=twrfloat.js.map","\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\"\r\n\r\nexport class twrFloatUtil {\r\n mod: twrWasmModuleBase;\r\n\r\n constructor(mod: twrWasmModuleBase) {\r\n this.mod=mod;\r\n }\r\n\r\n atod(strptr:number):number {\r\n const str=this.mod.getString(strptr);\r\n\r\n const upper=str.trimStart().toUpperCase();\r\n if (upper==\"INF\" || upper==\"+INF\")\r\n return Number.POSITIVE_INFINITY;\r\n else if (upper==\"-INF\")\r\n return Number.NEGATIVE_INFINITY\r\n else {\r\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\r\n const r=Number.parseFloat(str.replaceAll('D','e').replaceAll('d','e'));\r\n return r;\r\n }\r\n }\r\n\r\n dtoa(buffer:number, buffer_size:number, value:number, max_precision:number):void {\r\n if (max_precision==-1) {\r\n const r=value.toString();\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n else {\r\n let r=value.toString();\r\n if (r.length>max_precision)\r\n r=value.toPrecision(max_precision);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n }\r\n\r\n toFixed(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toFixed(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n toExponential(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toExponential(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\r\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\r\n // Negative exponents must be now smaller than 1e-99\r\n // fully-function C version also int he source, but this is the version enabled by default\r\n fcvtS(\r\n buffer:number, // char *\r\n sizeInBytes:number, //size_t\r\n value:number, // double\r\n fracpart_numdigits:number, //int\r\n dec:number, // int *\r\n sign:number // int *\r\n ):number {\r\n\r\n if (buffer==0 ||sign==0 || dec==0 || sizeInBytes<1) return 1;\r\n\r\n let digits:string;\r\n let decpos:number;\r\n let s=0; // default to positive\r\n\r\n\r\n if (Number.isNaN(value)) { /* nan */\r\n digits=\"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (!Number.isFinite(value)) { /* infinity */\r\n digits=\"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (value==0) { \r\n digits=\"000000000000000000000000000000000000\".slice(0,fracpart_numdigits);\r\n decpos=0;\r\n }\r\n \r\n else {\r\n\r\n if (value<0) {\r\n s=1; // negative\r\n value=Math.abs(value);\r\n }\r\n\r\n if (fracpart_numdigits>100 || value > 1e+21 || value < 1e-99) { \r\n this.mod.copyString(buffer, sizeInBytes, \"\");\r\n this.mod.mem32[dec]=0;\r\n return 1;\r\n }\r\n\r\n const roundValStr=value.toFixed(fracpart_numdigits);\r\n let [intPart=\"\", fracPart=\"\"] = roundValStr.split('.');\r\n if (intPart==\"0\") intPart=\"\";\r\n\r\n if (intPart.length>0) { // has integer part\r\n decpos=intPart.length;\r\n digits=intPart+fracPart;\r\n }\r\n else { // only a fraction\r\n digits=fracPart.replace(/^0+/,\"\"); // remove leading zeros\r\n decpos=digits.length-fracPart.length;\r\n }\r\n }\r\n\r\n if (sizeInBytes-1 < digits.length) return 1; \r\n this.mod.copyString(buffer, sizeInBytes, digits);\r\n this.mod.setLong(dec, decpos);\r\n this.mod.setLong(sign, s);\r\n\r\n return 0;\r\n\r\n /*\r\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\r\n\r\n let decpos=0;\r\n let digits:string;\r\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\r\n \r\n if (decpos>0) { // has integer part\r\n const intlen=Math.max(decpos, 0);\r\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\r\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\r\n }\r\n else { // only a fraction\r\n const intpart=Math.trunc(value);\r\n const fracpart=value-intpart;\r\n const prec=fracpart_numdigits- (-decpos);\r\n console.log(\"prec=\",prec);\r\n if (prec<1) {\r\n digits=\"\";\r\n }\r\n else {\r\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\");\r\n }\r\n }\r\n\r\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\r\n console.log('digits=',digits);\r\n console.log('dec=',decpos);\r\n console.log(\"sign=\",s);\r\n */\r\n\r\n\r\n }\r\n}","import { twrSignal } from \"./twrsignal.js\";\nimport { twrTimeImpl } from \"./twrdate.js\";\n// This class is used in the Main JS thread \nexport class twrWaitingCalls {\n callCompleteSignal;\n parameters;\n constructor() {\n this.callCompleteSignal = new twrSignal();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(() => {\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = twrTimeImpl();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [this.callCompleteSignal.sharedArray, this.parameters.buffer];\n }\n processMessage(msgType, data) {\n switch (msgType) {\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\n// This class is used in the worker thread \nexport class twrWaitingCallsProxy {\n callCompleteSignal;\n parameters;\n constructor(params) {\n this.callCompleteSignal = new twrSignal(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\"sleep\", [ms]]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\"time\"]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n//# sourceMappingURL=twrwaitingcalls.js.map","import { twrSignal } from \"./twrsignal.js\";\r\nimport {twrTimeImpl} from \"./twrdate.js\"\r\n\r\n// These classes are used to proxy a call across the worker thread - main thread boundary and wait for the result\r\n\r\nexport type TWaitingCallsProxyParams = [SharedArrayBuffer, SharedArrayBuffer]; // twrSignal, parameters \r\n\r\n// This class is used in the Main JS thread \r\nexport class twrWaitingCalls {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor() {\r\n\t\tthis.callCompleteSignal=new twrSignal();\r\n\t\tthis.parameters=new Uint32Array(new SharedArrayBuffer(4));\r\n\t}\r\n\r\n\tprivate startSleep(ms:number) {\r\n\r\n\t\tsetTimeout(()=>{\r\n\t\t\tthis.callCompleteSignal.signal();\r\n\t\t}, ms);\r\n\t\t\r\n\t}\r\n\r\n\tprivate time() {\r\n\t\tconst ms=twrTimeImpl();\r\n\t\tthis.parameters[0]=ms;\r\n\t\tthis.callCompleteSignal.signal();\r\n\t}\r\n\r\n\tgetProxyParams():TWaitingCallsProxyParams {\r\n\t\treturn [this.callCompleteSignal.sharedArray, this.parameters.buffer as SharedArrayBuffer];\t\r\n\t}\r\n\r\n\tprocessMessage(msgType:string, data:any[]):boolean {\r\n\t\tswitch (msgType) {\r\n\t\t\tcase \"sleep\":\r\n\t\t\t\tconst [ms] = data;\r\n\t\t\t\tthis.startSleep(ms);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"time\":\r\n\t\t\t\tthis.time();\r\n\t\t\t\tbreak;\r\n\t\t\t\r\n\t\t\tdefault:\r\n\t\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\treturn true;\r\n\t}\r\n\r\n}\r\n\r\n// This class is used in the worker thread \r\nexport class twrWaitingCallsProxy {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor(params:TWaitingCallsProxyParams) {\r\n\t\tthis.callCompleteSignal=new twrSignal(params[0]);\r\n\t\tthis.parameters=new Uint32Array(params[1]);\r\n\t}\r\n\r\n\tsleep(ms:number) {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"sleep\", [ms]]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t}\r\n\r\n\ttime() {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"time\"]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t\treturn this.parameters[0];\r\n\t}\r\n\r\n}\r\n","export function twrTimeImpl() {\n return Date.now();\n}\n//# sourceMappingURL=twrdate.js.map","\r\nexport function twrTimeImpl() {\r\n\r\n return Date.now();\r\n\r\n}"],"names":["$b93f1fdf40141def$var$twrSignalState","$c4741cac81d14197$var$D2DType","twrSignalState","D2DType","$3e39efa823870787$var$mod","$892fccfc812d5e20$export$a01cca24f011573a","sharedArray","buf","constructor","sa","window","crossOriginIsolated","location","protocol","Error","SharedArrayBuffer","Int32Array","write","n","i","Atomics","notify","read","isEmpty","readWait","rdptr","wait","$b93f1fdf40141def$export$e37a7b7b851b97f3","WAITING","signal","SIGNALED","isSignaled","reset","$c4741cac81d14197$export$c779b2cd00544976","canvasKeys","drawCompleteSignal","props","owner","params","signalBuffer","canvasKeysBuffer","charIn","inkey","getProp","pn","propName","getString","drawSeq","ds","postMessage","$8963973702ae5462$export$b377f0bbf2c7581e","divKeys","divKeysBuffer","charOut","ch","$8ac0b786da854328$export$485af4d0039b3389","$e72303a1db04bdfa$export$918ffb7e046a537b","mod","atod","strptr","str","upper","trimStart","toUpperCase","Number","POSITIVE_INFINITY","NEGATIVE_INFINITY","parseFloat","replaceAll","dtoa","buffer","buffer_size","value","max_precision","r","toString","copyString","length","toPrecision","toFixed","decdigits","toExponential","fcvtS","sizeInBytes","fracpart_numdigits","dec","sign","digits","decpos","s","isNaN","slice","isFinite","Math","abs","mem32","intPart","fracPart","roundValStr","split","replace","setLong","$ece7fa3ed770778a$export$c83a0a3bffe07399","memory","mem8","memD","exports","isWorker","isWasmModule","floatUtil","Uint8Array","Uint32Array","Float64Array","loadWasm","pathToLoad","response","fetch","err","console","log","ok","statusText","wasmBytes","arrayBuffer","allimports","modParams","imports","instance","WebAssembly","instantiate","env","ArrayBuffer","malloc","size","Promise","resolve","m","twr_malloc","init","stack","p","stdio","twrInit","twr_wasm_init","callC","cparams","preCallC","retval","callCImpl","postCallC","fname","f","Array","ci","putString","URL","fetchAndPutURL","putArrayBuffer","u8","j","sin","charCodeAt","strIndex","putU8","u8a","dest","ab","fnin","src","getLong","idx","idx32","floor","getDouble","idx64","setDouble","getShort","len","sout","undefined","String","fromCharCode","getU8Arr","rv","dataptr","getU32Arr","$aff9c2c494d23fe3$export$78d2a4633fe89379","callCompleteSignal","parameters","sleep","ms","time","onmessage","e","data","$3e39efa823870787$var$twrWasmModuleInWorker","modWorkerParams","urlToLoad","then","catch","ex","rc","modInWorkerParams","canvasProxy","canvasProxyParams","divProxy","divProxyParams","waitingCallsProxy","waitingCallsProxyParams","twrDebugLog","twrSleep","bind","twrTime","twrDivCharOut","twrDivCharIn","twrCanvasCharIn","twrCanvasInkey","twrCanvasGetProp","twrCanvasDrawSeq","twrSin","twrCos","cos","twrTan","tan","twrFAbs","twrACos","acos","twrASin","asin","twrATan","atan","twrExp","exp","twrFloor","twrCeil","ceil","twrFMod","x","y","twrLog","twrPow","pow","twrSqrt","sqrt","twrTrunc","trunc","twrDtoa","twrToFixed","twrToExponential","twrAtod","twrFcvtS"],"version":3,"file":"twrmodworker.2165e649.js.map"} \ No newline at end of file diff --git a/azure/examples/maze/maze-script.js b/azure/examples/maze/maze-script.js index 8a25e632..71be9c14 100644 --- a/azure/examples/maze/maze-script.js +++ b/azure/examples/maze/maze-script.js @@ -12,10 +12,10 @@ export async function mazeRunner() { const amod = new twrWasmModuleAsync(); await amod.loadWasm('maze.wasm'); //void CalcMaze(HWND hWnd, LONG cell_size, LONG is_black_bg, LONG isd - slow draw) - await amod.executeC(["CalcMaze", 0, 7, 0, 1]); - await amod.executeC(["SolveBegin"]); + await amod.callC(["CalcMaze", 0, 7, 0, 1]); + await amod.callC(["SolveBegin"]); let timer = setInterval(async () => { - let isdone = await amod.executeC(["SolveStep", 0]); //SolveStep(hwnd)) + let isdone = await amod.callC(["SolveStep", 0]); //SolveStep(hwnd)) if (isdone) clearInterval(timer); }, 50); diff --git a/azure/examples/maze/maze-script.ts b/azure/examples/maze/maze-script.ts index 80061f70..3aeed3b1 100644 --- a/azure/examples/maze/maze-script.ts +++ b/azure/examples/maze/maze-script.ts @@ -17,11 +17,11 @@ export async function mazeRunner() { await amod.loadWasm('maze.wasm'); //void CalcMaze(HWND hWnd, LONG cell_size, LONG is_black_bg, LONG isd - slow draw) - await amod.executeC(["CalcMaze", 0, 7, 0, 1]); - await amod.executeC(["SolveBegin"]); + await amod.callC(["CalcMaze", 0, 7, 0, 1]); + await amod.callC(["SolveBegin"]); let timer = setInterval(async ()=>{ - let isdone=await amod.executeC(["SolveStep", 0]); //SolveStep(hwnd)) + let isdone=await amod.callC(["SolveStep", 0]); //SolveStep(hwnd)) if (isdone) clearInterval(timer); }, 50); } diff --git a/azure/examples/stdio-canvas/dist/index.html b/azure/examples/stdio-canvas/dist/index.html index 3a31a092..1c4ff4a7 100644 --- a/azure/examples/stdio-canvas/dist/index.html +++ b/azure/examples/stdio-canvas/dist/index.html @@ -5,4 +5,4 @@ "whatkey": "../../lib-js/whatkey.js" } } - \ No newline at end of file + \ No newline at end of file diff --git a/azure/examples/stdio-canvas/dist/twrmodworker.2165e649.js b/azure/examples/stdio-canvas/dist/twrmodworker.2165e649.js index 3744680c..d8d07779 100644 --- a/azure/examples/stdio-canvas/dist/twrmodworker.2165e649.js +++ b/azure/examples/stdio-canvas/dist/twrmodworker.2165e649.js @@ -1,2 +1,2 @@ -(()=>{var t,e,r,s;let i;class a{sharedArray;buf;constructor(t){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSharedCircularBuffer constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");t?this.sharedArray=t:this.sharedArray=new SharedArrayBuffer(1032),this.buf=new Int32Array(this.sharedArray),this.buf[256]=0,this.buf[257]=0}write(t){let e=this.buf[257];this.buf[e]=t,256==++e&&(e=0),this.buf[257]=e,Atomics.notify(this.buf,257)}read(){if(this.isEmpty())return -1;{let t=this.buf[256],e=this.buf[t];return t++,this.buf[256]=t,e}}readWait(){if(this.isEmpty()){let t=this.buf[256];Atomics.wait(this.buf,257,t)}return this.read()}isEmpty(){return this.buf[256]==this.buf[257]}}(r=t||(t={}))[r.WAITING=0]="WAITING",r[r.SIGNALED=1]="SIGNALED";class o{sharedArray;buf;constructor(e){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSignal constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");e?this.sharedArray=e:this.sharedArray=new SharedArrayBuffer(4),this.buf=new Int32Array(this.sharedArray),this.buf[0]=t.WAITING}signal(){this.buf[0]=t.SIGNALED,Atomics.notify(this.buf,0)}wait(){this.buf[0]==t.WAITING&&Atomics.wait(this.buf,0,t.WAITING)}isSignaled(){return this.buf[0]==t.SIGNALED}reset(){this.buf[0]=t.WAITING}}(s=e||(e={}))[s.D2D_FILLRECT=1]="D2D_FILLRECT",s[s.D2D_FILLCHAR=5]="D2D_FILLCHAR",s[s.D2D_SETLINEWIDTH=10]="D2D_SETLINEWIDTH",s[s.D2D_SETFILLSTYLERGBA=11]="D2D_SETFILLSTYLERGBA",s[s.D2D_SETFONT=12]="D2D_SETFONT",s[s.D2D_BEGINPATH=13]="D2D_BEGINPATH",s[s.D2D_MOVETO=14]="D2D_MOVETO",s[s.D2D_LINETO=15]="D2D_LINETO",s[s.D2D_FILL=16]="D2D_FILL",s[s.D2D_STROKE=17]="D2D_STROKE",s[s.D2D_SETSTROKESTYLERGBA=18]="D2D_SETSTROKESTYLERGBA",s[s.D2D_ARC=19]="D2D_ARC",s[s.D2D_STROKERECT=20]="D2D_STROKERECT",s[s.D2D_FILLTEXT=21]="D2D_FILLTEXT",s[s.D2D_IMAGEDATA=22]="D2D_IMAGEDATA",s[s.D2D_PUTIMAGEDATA=23]="D2D_PUTIMAGEDATA",s[s.D2D_BEZIERTO=24]="D2D_BEZIERTO",s[s.D2D_MEASURETEXT=25]="D2D_MEASURETEXT",s[s.D2D_SAVE=26]="D2D_SAVE",s[s.D2D_RESTORE=27]="D2D_RESTORE",s[s.D2D_CREATERADIALGRADIENT=28]="D2D_CREATERADIALGRADIENT",s[s.D2D_SETCOLORSTOP=29]="D2D_SETCOLORSTOP",s[s.D2D_SETFILLSTYLEGRADIENT=30]="D2D_SETFILLSTYLEGRADIENT",s[s.D2D_RELEASEID=31]="D2D_RELEASEID",s[s.D2D_CREATELINEARGRADIENT=32]="D2D_CREATELINEARGRADIENT",s[s.D2D_SETFILLSTYLE=33]="D2D_SETFILLSTYLE",s[s.D2D_SETSTROKESTYLE=34]="D2D_SETSTROKESTYLE";class n{canvasKeys;drawCompleteSignal;props;owner;constructor(t,e){let[r,s,i]=t;this.drawCompleteSignal=new o(s),this.canvasKeys=new a(i),this.props=r,this.owner=e}charIn(){return this.canvasKeys.readWait()}inkey(){return this.canvasKeys.isEmpty()?0:this.charIn()}getProp(t){let e=this.owner.getString(t);return this.props[e]}drawSeq(t){this.drawCompleteSignal.reset(),postMessage(["drawseq",[t]]),this.drawCompleteSignal.wait()}}class l{divKeys;constructor(t){let[e]=t;this.divKeys=new a(e)}charIn(){return this.divKeys.readWait()}inkey(){return this.divKeys.isEmpty()?0:this.charIn()}charOut(t){postMessage(["divout",t])}}function h(t){postMessage(["debug",t])}class m{mod;constructor(t){this.mod=t}atod(t){let e=this.mod.getString(t),r=e.trimStart().toUpperCase();return"INF"==r||"+INF"==r?Number.POSITIVE_INFINITY:"-INF"==r?Number.NEGATIVE_INFINITY:Number.parseFloat(e.replaceAll("D","e").replaceAll("d","e"))}dtoa(t,e,r,s){if(-1==s){let s=r.toString();this.mod.copyString(t,e,s)}else{let i=r.toString();i.length>s&&(i=r.toPrecision(s)),this.mod.copyString(t,e,i)}}toFixed(t,e,r,s){let i=r.toFixed(s);this.mod.copyString(t,e,i)}toExponential(t,e,r,s){let i=r.toExponential(s);this.mod.copyString(t,e,i)}fcvtS(t,e,r,s,i,a){let o,n;if(0==t||0==a||0==i||e<1)return 1;let l=0;if(Number.isNaN(r))o="1#QNAN00000000000000000000000000000".slice(0,s+1),n=1;else if(Number.isFinite(r)){if(0==r)o="000000000000000000000000000000000000".slice(0,s),n=0;else{if(r<0&&(l=1,r=Math.abs(r)),s>100||r>1e21||r<1e-99)return this.mod.copyString(t,e,""),this.mod.mem32[i]=0,1;let[a="",h=""]=r.toFixed(s).split(".");"0"==a&&(a=""),a.length>0?(n=a.length,o=a+h):n=(o=h.replace(/^0+/,"")).length-h.length}}else o="1#INF00000000000000000000000000000".slice(0,s+1),n=1;return e-1new Promise(e=>{let r=this.exports.twr_malloc;e(r(t))}),this.init()}catch(t){throw console.log("WASM instantiate error: "+t+(t.stack?"\n"+t.stack:"")),t}}init(){let t;switch(this.modParams.stdio){case"debug":default:t=0;break;case"div":t=1;break;case"canvas":t=2;break;case"null":t=3}(0,this.exports.twr_wasm_init)(t,this.mem8.length)}async executeC(t){let e=await this.preCallC(t),r=this.executeCImpl(t[0],e);return this.postCallC(e,t),r}async executeCImpl(t,e=[]){if(!this.exports)throw Error("this.exports undefined");if(!this.exports[t])throw Error("executeC: function '"+t+"' not in export table. Use --export wasm-ld flag.");return(0,this.exports[t])(...e)}async preCallC(t){if(t.constructor!==Array)throw Error("executeC: params must be array, first arg is function name");if(0==t.length)throw Error("executeC: missing function name");let e=[],r=0;for(let s=1;s=this.mem32.length)throw Error("invalid index passed to getLong: "+t+", this.mem32.length: "+this.mem32.length);return this.mem32[e]}setLong(t,e){let r=Math.floor(t/4);if(4*r!=t)throw Error("setLong passed non long aligned address");if(r<0||r>=this.mem32.length)throw Error("invalid index passed to setLong: "+t+", this.mem32.length: "+this.mem32.length);this.mem32[r]=e}getDouble(t){let e=Math.floor(t/8);if(8*e!=t)throw Error("getLong passed non Float64 aligned address");return this.memD[e]}setDouble(t,e){let r=Math.floor(t/8);if(8*r!=t)throw Error("setDouble passed non Float64 aligned address");this.memD[r]=e}getShort(t){if(t<0||t>=this.mem8.length)throw Error("invalid index passed to getShort: "+t);return this.mem8[t]+256*this.mem8[t+1]}getString(t,e){let r="",s=0;for(;this.mem8[t+s]&&(void 0===e||s=this.mem8.length)throw Error("invalid index passed to getU8: "+t);let e=new Uint32Array(this.mem8.slice(t,t+8).buffer),r=e[0],s=e[1];if(s<0||s>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU8");if(r<0||r>this.mem8.length-s)throw Error("invalid idx.size passed to getU8");return this.mem8.slice(s,s+r)}getU32Arr(t){if(t<0||t>=this.mem8.length)throw Error("invalid index passed to getU32: "+t);let e=new Uint32Array(this.mem8.slice(t,t+8).buffer),r=e[0],s=e[1];if(s<0||s>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU32");if(r<0||r>this.mem8.length-s)throw Error("invalid idx.size passed to getU32");if(r%4!=0)throw Error("idx.size is not an integer number of 32 bit words");return new Uint32Array(this.mem8.slice(s,s+r).buffer)}}class d{callCompleteSignal;parameters;constructor(t){this.callCompleteSignal=new o(t[0]),this.parameters=new Uint32Array(t[1])}sleep(t){this.callCompleteSignal.reset(),postMessage(["sleep",[t]]),this.callCompleteSignal.wait()}time(){return this.callCompleteSignal.reset(),postMessage(["time"]),this.callCompleteSignal.wait(),this.parameters[0]}}onmessage=function(t){if("startup"==t.data[0]){let e=t.data[1];(i=new f(e.modParams,e.modWorkerParams)).loadWasm(e.urlToLoad).then(()=>{postMessage(["startupOkay"])}).catch(t=>{console.log(".catch: ",t),postMessage(["startupFail",t])})}else"executeC"==t.data[0]?i.executeCImpl(t.data[1],t.data[2]).then(t=>{postMessage(["executeCOkay",t])}).catch(t=>{console.log("exception in executeC twrworker.js\n"),console.log(t),postMessage(["executeCFail",t])}):console.log("twrworker.js: unknown message: "+t)};class f extends c{malloc;modParams;constructor(t,e){super(),this.isWorker=!0,this.malloc=t=>{throw Error("error - un-init malloc called")},this.modParams=t;let r=new n(e.canvasProxyParams,this),s=new l(e.divProxyParams),i=new d(e.waitingCallsProxyParams);this.modParams.imports={twrDebugLog:h,twrSleep:i.sleep.bind(i),twrTime:i.time.bind(i),twrDivCharOut:s.charOut.bind(s),twrDivCharIn:s.charIn.bind(s),twrCanvasCharIn:r.charIn.bind(r),twrCanvasInkey:r.inkey.bind(r),twrCanvasGetProp:r.getProp.bind(r),twrCanvasDrawSeq:r.drawSeq.bind(r),twrSin:Math.sin,twrCos:Math.cos,twrTan:Math.tan,twrFAbs:Math.abs,twrACos:Math.acos,twrASin:Math.asin,twrATan:Math.atan,twrExp:Math.exp,twrFloor:Math.floor,twrCeil:Math.ceil,twrFMod:function(t,e){return t%e},twrLog:Math.log,twrPow:Math.pow,twrSqrt:Math.sqrt,twrTrunc:Math.trunc,twrDtoa:this.floatUtil.dtoa.bind(this.floatUtil),twrToFixed:this.floatUtil.toFixed.bind(this.floatUtil),twrToExponential:this.floatUtil.toExponential.bind(this.floatUtil),twrAtod:this.floatUtil.atod.bind(this.floatUtil),twrFcvtS:this.floatUtil.fcvtS.bind(this.floatUtil)}}}})(); +(()=>{var t,e,r,s;let i;class a{sharedArray;buf;constructor(t){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSharedCircularBuffer constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");t?this.sharedArray=t:this.sharedArray=new SharedArrayBuffer(1032),this.buf=new Int32Array(this.sharedArray),this.buf[256]=0,this.buf[257]=0}write(t){let e=this.buf[257];this.buf[e]=t,256==++e&&(e=0),this.buf[257]=e,Atomics.notify(this.buf,257)}read(){if(this.isEmpty())return -1;{let t=this.buf[256],e=this.buf[t];return t++,this.buf[256]=t,e}}readWait(){if(this.isEmpty()){let t=this.buf[256];Atomics.wait(this.buf,257,t)}return this.read()}isEmpty(){return this.buf[256]==this.buf[257]}}(r=t||(t={}))[r.WAITING=0]="WAITING",r[r.SIGNALED=1]="SIGNALED";class o{sharedArray;buf;constructor(e){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSignal constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");e?this.sharedArray=e:this.sharedArray=new SharedArrayBuffer(4),this.buf=new Int32Array(this.sharedArray),this.buf[0]=t.WAITING}signal(){this.buf[0]=t.SIGNALED,Atomics.notify(this.buf,0)}wait(){this.buf[0]==t.WAITING&&Atomics.wait(this.buf,0,t.WAITING)}isSignaled(){return this.buf[0]==t.SIGNALED}reset(){this.buf[0]=t.WAITING}}(s=e||(e={}))[s.D2D_FILLRECT=1]="D2D_FILLRECT",s[s.D2D_FILLCHAR=5]="D2D_FILLCHAR",s[s.D2D_SETLINEWIDTH=10]="D2D_SETLINEWIDTH",s[s.D2D_SETFILLSTYLERGBA=11]="D2D_SETFILLSTYLERGBA",s[s.D2D_SETFONT=12]="D2D_SETFONT",s[s.D2D_BEGINPATH=13]="D2D_BEGINPATH",s[s.D2D_MOVETO=14]="D2D_MOVETO",s[s.D2D_LINETO=15]="D2D_LINETO",s[s.D2D_FILL=16]="D2D_FILL",s[s.D2D_STROKE=17]="D2D_STROKE",s[s.D2D_SETSTROKESTYLERGBA=18]="D2D_SETSTROKESTYLERGBA",s[s.D2D_ARC=19]="D2D_ARC",s[s.D2D_STROKERECT=20]="D2D_STROKERECT",s[s.D2D_FILLTEXT=21]="D2D_FILLTEXT",s[s.D2D_IMAGEDATA=22]="D2D_IMAGEDATA",s[s.D2D_PUTIMAGEDATA=23]="D2D_PUTIMAGEDATA",s[s.D2D_BEZIERTO=24]="D2D_BEZIERTO",s[s.D2D_MEASURETEXT=25]="D2D_MEASURETEXT",s[s.D2D_SAVE=26]="D2D_SAVE",s[s.D2D_RESTORE=27]="D2D_RESTORE",s[s.D2D_CREATERADIALGRADIENT=28]="D2D_CREATERADIALGRADIENT",s[s.D2D_SETCOLORSTOP=29]="D2D_SETCOLORSTOP",s[s.D2D_SETFILLSTYLEGRADIENT=30]="D2D_SETFILLSTYLEGRADIENT",s[s.D2D_RELEASEID=31]="D2D_RELEASEID",s[s.D2D_CREATELINEARGRADIENT=32]="D2D_CREATELINEARGRADIENT",s[s.D2D_SETFILLSTYLE=33]="D2D_SETFILLSTYLE",s[s.D2D_SETSTROKESTYLE=34]="D2D_SETSTROKESTYLE";class n{canvasKeys;drawCompleteSignal;props;owner;constructor(t,e){let[r,s,i]=t;this.drawCompleteSignal=new o(s),this.canvasKeys=new a(i),this.props=r,this.owner=e}charIn(){return this.canvasKeys.readWait()}inkey(){return this.canvasKeys.isEmpty()?0:this.charIn()}getProp(t){let e=this.owner.getString(t);return this.props[e]}drawSeq(t){this.drawCompleteSignal.reset(),postMessage(["drawseq",[t]]),this.drawCompleteSignal.wait()}}class l{divKeys;constructor(t){let[e]=t;this.divKeys=new a(e)}charIn(){return this.divKeys.readWait()}inkey(){return this.divKeys.isEmpty()?0:this.charIn()}charOut(t){postMessage(["divout",t])}}function h(t){postMessage(["debug",t])}class m{mod;constructor(t){this.mod=t}atod(t){let e=this.mod.getString(t),r=e.trimStart().toUpperCase();return"INF"==r||"+INF"==r?Number.POSITIVE_INFINITY:"-INF"==r?Number.NEGATIVE_INFINITY:Number.parseFloat(e.replaceAll("D","e").replaceAll("d","e"))}dtoa(t,e,r,s){if(-1==s){let s=r.toString();this.mod.copyString(t,e,s)}else{let i=r.toString();i.length>s&&(i=r.toPrecision(s)),this.mod.copyString(t,e,i)}}toFixed(t,e,r,s){let i=r.toFixed(s);this.mod.copyString(t,e,i)}toExponential(t,e,r,s){let i=r.toExponential(s);this.mod.copyString(t,e,i)}fcvtS(t,e,r,s,i,a){let o,n;if(0==t||0==a||0==i||e<1)return 1;let l=0;if(Number.isNaN(r))o="1#QNAN00000000000000000000000000000".slice(0,s+1),n=1;else if(Number.isFinite(r)){if(0==r)o="000000000000000000000000000000000000".slice(0,s),n=0;else{if(r<0&&(l=1,r=Math.abs(r)),s>100||r>1e21||r<1e-99)return this.mod.copyString(t,e,""),this.mod.mem32[i]=0,1;let[a="",h=""]=r.toFixed(s).split(".");"0"==a&&(a=""),a.length>0?(n=a.length,o=a+h):n=(o=h.replace(/^0+/,"")).length-h.length}}else o="1#INF00000000000000000000000000000".slice(0,s+1),n=1;return e-1new Promise(e=>{let r=this.exports.twr_malloc;e(r(t))}),this.init()}catch(t){throw console.log("WASM instantiate error: "+t+(t.stack?"\n"+t.stack:"")),t}}init(){let t;switch(this.modParams.stdio){case"debug":default:t=0;break;case"div":t=1;break;case"canvas":t=2;break;case"null":t=3}(0,this.exports.twr_wasm_init)(t,this.mem8.length)}async callC(t){let e=await this.preCallC(t),r=this.callCImpl(t[0],e);return this.postCallC(e,t),r}async callCImpl(t,e=[]){if(!this.exports)throw Error("this.exports undefined");if(!this.exports[t])throw Error("callC: function '"+t+"' not in export table. Use --export wasm-ld flag.");return(0,this.exports[t])(...e)}async preCallC(t){if(t.constructor!==Array)throw Error("callC: params must be array, first arg is function name");if(0==t.length)throw Error("callC: missing function name");let e=[],r=0;for(let s=1;s=this.mem32.length)throw Error("invalid index passed to getLong: "+t+", this.mem32.length: "+this.mem32.length);return this.mem32[e]}setLong(t,e){let r=Math.floor(t/4);if(4*r!=t)throw Error("setLong passed non long aligned address");if(r<0||r>=this.mem32.length)throw Error("invalid index passed to setLong: "+t+", this.mem32.length: "+this.mem32.length);this.mem32[r]=e}getDouble(t){let e=Math.floor(t/8);if(8*e!=t)throw Error("getLong passed non Float64 aligned address");return this.memD[e]}setDouble(t,e){let r=Math.floor(t/8);if(8*r!=t)throw Error("setDouble passed non Float64 aligned address");this.memD[r]=e}getShort(t){if(t<0||t>=this.mem8.length)throw Error("invalid index passed to getShort: "+t);return this.mem8[t]+256*this.mem8[t+1]}getString(t,e){let r="",s=0;for(;this.mem8[t+s]&&(void 0===e||s=this.mem8.length)throw Error("invalid index passed to getU8: "+t);let e=new Uint32Array(this.mem8.slice(t,t+8).buffer),r=e[0],s=e[1];if(s<0||s>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU8");if(r<0||r>this.mem8.length-s)throw Error("invalid idx.size passed to getU8");return this.mem8.slice(s,s+r)}getU32Arr(t){if(t<0||t>=this.mem8.length)throw Error("invalid index passed to getU32: "+t);let e=new Uint32Array(this.mem8.slice(t,t+8).buffer),r=e[0],s=e[1];if(s<0||s>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU32");if(r<0||r>this.mem8.length-s)throw Error("invalid idx.size passed to getU32");if(r%4!=0)throw Error("idx.size is not an integer number of 32 bit words");return new Uint32Array(this.mem8.slice(s,s+r).buffer)}}class d{callCompleteSignal;parameters;constructor(t){this.callCompleteSignal=new o(t[0]),this.parameters=new Uint32Array(t[1])}sleep(t){this.callCompleteSignal.reset(),postMessage(["sleep",[t]]),this.callCompleteSignal.wait()}time(){return this.callCompleteSignal.reset(),postMessage(["time"]),this.callCompleteSignal.wait(),this.parameters[0]}}onmessage=function(t){if("startup"==t.data[0]){let e=t.data[1];(i=new f(e.modParams,e.modWorkerParams)).loadWasm(e.urlToLoad).then(()=>{postMessage(["startupOkay"])}).catch(t=>{console.log(".catch: ",t),postMessage(["startupFail",t])})}else"callC"==t.data[0]?i.callCImpl(t.data[1],t.data[2]).then(t=>{postMessage(["callCOkay",t])}).catch(t=>{console.log("exception in callC twrworker.js\n"),console.log(t),postMessage(["callCFail",t])}):console.log("twrworker.js: unknown message: "+t)};class f extends c{malloc;modParams;constructor(t,e){super(),this.isWorker=!0,this.malloc=t=>{throw Error("error - un-init malloc called")},this.modParams=t;let r=new n(e.canvasProxyParams,this),s=new l(e.divProxyParams),i=new d(e.waitingCallsProxyParams);this.modParams.imports={twrDebugLog:h,twrSleep:i.sleep.bind(i),twrTime:i.time.bind(i),twrDivCharOut:s.charOut.bind(s),twrDivCharIn:s.charIn.bind(s),twrCanvasCharIn:r.charIn.bind(r),twrCanvasInkey:r.inkey.bind(r),twrCanvasGetProp:r.getProp.bind(r),twrCanvasDrawSeq:r.drawSeq.bind(r),twrSin:Math.sin,twrCos:Math.cos,twrTan:Math.tan,twrFAbs:Math.abs,twrACos:Math.acos,twrASin:Math.asin,twrATan:Math.atan,twrExp:Math.exp,twrFloor:Math.floor,twrCeil:Math.ceil,twrFMod:function(t,e){return t%e},twrLog:Math.log,twrPow:Math.pow,twrSqrt:Math.sqrt,twrTrunc:Math.trunc,twrDtoa:this.floatUtil.dtoa.bind(this.floatUtil),twrToFixed:this.floatUtil.toFixed.bind(this.floatUtil),twrToExponential:this.floatUtil.toExponential.bind(this.floatUtil),twrAtod:this.floatUtil.atod.bind(this.floatUtil),twrFcvtS:this.floatUtil.fcvtS.bind(this.floatUtil)}}}})(); //# sourceMappingURL=twrmodworker.2165e649.js.map diff --git a/azure/examples/stdio-canvas/dist/twrmodworker.2165e649.js.map b/azure/examples/stdio-canvas/dist/twrmodworker.2165e649.js.map index 29a4d41e..77745e98 100644 --- a/azure/examples/stdio-canvas/dist/twrmodworker.2165e649.js.map +++ b/azure/examples/stdio-canvas/dist/twrmodworker.2165e649.js.map @@ -1 +1 @@ -{"mappings":"A,C,SQKK,EJgBA,EIhBA,EJgBA,MFZD,CISE,OAAO,EACZ,WAA8B,AAC9B,CAAA,GAAe,AAEf,aAAa,CAAqB,CAAlC,CACO,GAAI,AAAkB,aAAlB,OAAO,QACH,CAAC,qBAAuB,AAA+B,UAA7B,OAAO,QAAQ,CAAC,QAAQ,CAAe,MAAM,AAAI,MAAM,4DAA4D,oBAAoB,iCAErK,EAAI,IAAI,CAAC,WAAW,CAAC,EACpB,IAAI,CAAC,WAAW,CAAC,IAAI,kBAAkB,MAClD,IAAI,CAAC,GAAG,CAAC,IAAI,WAAW,IAAI,CAAC,WAAW,EAClC,IAAI,CAAC,GAAG,CArBJ,IAqBW,CAAC,EAChB,IAAI,CAAC,GAAG,CArBJ,IAqBW,CAAC,CACvB,CAEA,MAAM,CAAQ,CAAd,CACO,IAAI,EAAE,IAAI,CAAC,GAAG,CAzBV,IAyBiB,AACrB,CAAA,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAzBV,OA2BE,GAAQ,CAAA,EAAE,C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AI,CAAC,SAAS,CAE5C,CACN,CACF,C,C","sources":["","../../lib-js/twrmodworker.js","../../source/twr-wasm-ts/twrmodworker.ts","../../lib-js/twrcanvas.js","../../source/twr-wasm-ts/twrcanvas.ts","../../lib-js/twrcircular.js","../../source/twr-wasm-ts/twrcircular.ts","../../lib-js/twrsignal.js","../../source/twr-wasm-ts/twrsignal.ts","../../lib-js/twrdiv.js","../../source/twr-wasm-ts/twrdiv.ts","../../lib-js/twrdebug.js","../../source/twr-wasm-ts/twrdebug.ts","../../lib-js/twrmodbase.js","../../source/twr-wasm-ts/twrmodbase.ts","../../lib-js/twrfloat.js","../../source/twr-wasm-ts/twrfloat.ts","../../lib-js/twrwaitingcalls.js","../../source/twr-wasm-ts/twrwaitingcalls.ts","../../lib-js/twrdate.js","../../source/twr-wasm-ts/twrdate.ts"],"sourcesContent":["(() => {\nvar $3e39efa823870787$exports = {};\n// this script is the WebWorker thead used by class twrWasmAsyncModule\n//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst $892fccfc812d5e20$var$RDIDX = 256;\nconst $892fccfc812d5e20$var$WRIDX = 257;\nconst $892fccfc812d5e20$var$LEN = 256;\nclass $892fccfc812d5e20$export$a01cca24f011573a {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(1032);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[$892fccfc812d5e20$var$RDIDX] = 0;\n this.buf[$892fccfc812d5e20$var$WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[$892fccfc812d5e20$var$WRIDX];\n this.buf[i] = n;\n i++;\n if (i == $892fccfc812d5e20$var$LEN) i = 0;\n this.buf[$892fccfc812d5e20$var$WRIDX] = i;\n Atomics.notify(this.buf, $892fccfc812d5e20$var$WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[$892fccfc812d5e20$var$RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[$892fccfc812d5e20$var$RDIDX] = i;\n return n;\n } else return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[$892fccfc812d5e20$var$RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, $892fccfc812d5e20$var$WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[$892fccfc812d5e20$var$RDIDX] == this.buf[$892fccfc812d5e20$var$WRIDX];\n }\n}\n\n\n//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar $b93f1fdf40141def$var$twrSignalState;\n(function(twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})($b93f1fdf40141def$var$twrSignalState || ($b93f1fdf40141def$var$twrSignalState = {}));\nclass $b93f1fdf40141def$export$e37a7b7b851b97f3 {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == $b93f1fdf40141def$var$twrSignalState.WAITING) //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, $b93f1fdf40141def$var$twrSignalState.WAITING);\n }\n isSignaled() {\n return this.buf[0] == $b93f1fdf40141def$var$twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.WAITING;\n }\n}\n\n\nvar $c4741cac81d14197$var$D2DType;\n(function(D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})($c4741cac81d14197$var$D2DType || ($c4741cac81d14197$var$D2DType = {}));\nclass $c4741cac81d14197$export$2f298dd69cef3c34 {\n ctx;\n props = {\n charWidth: 0,\n charHeight: 0,\n foreColor: 0,\n backColor: 0,\n widthInChars: 0,\n heightInChars: 0,\n canvasHeight: 0,\n canvasWidth: 0\n };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase){\n const { forecolor: forecolor, backcolor: backcolor, fontsize: fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)();\n this.canvasKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.props,\n this.cmdCompleteSignal.sharedArray,\n this.canvasKeys.sharedArray\n ];\n }\n getProp(pn) {\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */ drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx) return;\n let ins = this.owner.getLong(ds); /* ds->start */ \n const lastins = this.owner.getLong(ds + 4); /* ds->last */ \n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while(true){\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */ \n switch(type){\n case $c4741cac81d14197$var$D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_BEGINPATH:\n this.ctx.beginPath();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILL:\n this.ctx.fill();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SAVE:\n this.ctx.save();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_RESTORE:\n this.ctx.restore();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_STROKE:\n this.ctx.stroke();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = this.owner.getLong(ins + 48) != 0;\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n } else this.precomputedObjects[id] = {\n mem8: new Uint8Array(this.owner.memory.buffer, start, length),\n width: width,\n height: height\n };\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id]) delete this.precomputedObjects[id];\n else console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n else {\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) this.ctx.putImageData(imgData, dx, dy);\n else this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */ \n if (next == 0) {\n if (ins != lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nclass $c4741cac81d14197$export$c779b2cd00544976 {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner){\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)(signalBuffer);\n this.canvasKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\n \"drawseq\",\n [\n ds\n ]\n ]);\n this.drawCompleteSignal.wait();\n }\n}\n\n\n\nclass $8963973702ae5462$export$dd376bb3f10f6896 {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611);\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase){\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) this.divKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(); // tsconfig, lib must be set to 2017 or higher\n if (this.div && !modParams.styleIsDefault) {\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.divKeys.sharedArray\n ];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */ charOut(ch) {\n if (!this.div) return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n }\n switch(ch){\n case 10:\n case 13:\n if (ch == 10 && this.lastChar == 13) break; // detect CR LF and treat as single new line\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n case 0xE:\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF:\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for(let i = 0; i < str.length; i++)this.charOut(str.charCodeAt(i));\n }\n}\nclass $8963973702ae5462$export$b377f0bbf2c7581e {\n divKeys;\n constructor(params){\n const [divKeysBuffer] = params;\n this.divKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n charOut(ch) {\n postMessage([\n \"divout\",\n ch\n ]);\n }\n}\n\n\nlet $8ac0b786da854328$var$logline = \"\";\nfunction $8ac0b786da854328$export$16b4216ec014493d(char) {\n if (char == 10 || char == 3) {\n console.log($8ac0b786da854328$var$logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n $8ac0b786da854328$var$logline = \"\";\n } else {\n $8ac0b786da854328$var$logline = $8ac0b786da854328$var$logline + String.fromCharCode(char);\n if ($8ac0b786da854328$var$logline.length >= 200) {\n console.log($8ac0b786da854328$var$logline);\n $8ac0b786da854328$var$logline = \"\";\n }\n }\n}\nfunction $8ac0b786da854328$export$485af4d0039b3389(ch) {\n postMessage([\n \"debug\",\n ch\n ]);\n}\n\n\nclass $e72303a1db04bdfa$export$918ffb7e046a537b {\n mod;\n constructor(mod){\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\") return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\") return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll(\"D\", \"e\").replaceAll(\"d\", \"e\"));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n } else {\n let r = value.toString();\n if (r.length > max_precision) r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, sizeInBytes, value, fracpart_numdigits, dec, sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1) return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) {\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (!Number.isFinite(value)) {\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n } else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split(\".\");\n if (intPart == \"0\") intPart = \"\";\n if (intPart.length > 0) {\n decpos = intPart.length;\n digits = intPart + fracPart;\n } else {\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length) return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */ }\n}\n\n\nclass $ece7fa3ed770778a$export$c83a0a3bffe07399 {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule;\n floatUtil;\n constructor(isWasmModule = false){\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new (0, $e72303a1db04bdfa$export$918ffb7e046a537b)(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/ /*********************************************************************/ async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n } catch (err) {\n console.log(\"loadWasm() failed to fetch: \" + pathToLoad);\n throw err;\n }\n if (!response.ok) throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, {\n env: allimports\n });\n this.exports = instance.instance.exports;\n if (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory) throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer) console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\n \"setmemory\",\n this.memory\n ]);\n }\n if (this.isWasmModule) // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n {\n if (!(this.memory.buffer instanceof ArrayBuffer)) console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size)=>{\n return new Promise((resolve)=>{\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n } catch (err) {\n console.log(\"WASM instantiate error: \" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch(this.modParams.stdio){\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* executeC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */ async executeC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.executeCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async executeCImpl(fname, cparams = []) {\n if (!this.exports) throw new Error(\"this.exports undefined\");\n if (!this.exports[fname]) throw new Error(\"executeC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array)) throw new Error(\"executeC: params must be array, first arg is function name\");\n if (params.length == 0) throw new Error(\"executeC: missing function name\");\n let cparams = [];\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n cparams[ci++] = p;\n break;\n case \"string\":\n cparams[ci++] = await this.putString(p);\n break;\n case \"object\":\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n } else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"executeC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n ci++;\n break;\n case \"string\":\n this.executeCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n case \"object\":\n if (p instanceof URL) {\n this.executeCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci = ci + 2;\n break;\n } else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for(let j = 0; j < u8.length; j++)u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.executeCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n } else throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/ /*********************************************************************/ // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for(i = 0; i < sin.length && i < buffer_size - 1; i++)this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for(let i = 0; i < u8a.length; i++)this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === \"object\" && fnin instanceof URL)) throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [\n dest,\n src.length\n ];\n } catch (err) {\n console.log(\"fetchAndPutURL Error. URL: \" + fnin + \"\\n\" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while(this.mem8[strIndex + i] && (len === undefined ? true : i < len) && strIndex + i < this.mem8.length){\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array(this.mem8.slice(dataptr, dataptr + size).buffer);\n return u32;\n }\n}\n\n\n\nfunction $4af5689abbc8d01b$export$78724cdcf7ebea1d() {\n return Date.now();\n}\n\n\nclass $aff9c2c494d23fe3$export$9e37856d1928d388 {\n callCompleteSignal;\n parameters;\n constructor(){\n this.callCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(()=>{\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = (0, $4af5689abbc8d01b$export$78724cdcf7ebea1d)();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [\n this.callCompleteSignal.sharedArray,\n this.parameters.buffer\n ];\n }\n processMessage(msgType, data) {\n switch(msgType){\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\nclass $aff9c2c494d23fe3$export$78d2a4633fe89379 {\n callCompleteSignal;\n parameters;\n constructor(params){\n this.callCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\n \"sleep\",\n [\n ms\n ]\n ]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\n \"time\"\n ]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n\n\nlet $3e39efa823870787$var$mod;\nonmessage = function(e) {\n //console.log('twrworker.js: message received from main script: '+e.data);\n if (e.data[0] == \"startup\") {\n const params = e.data[1];\n //console.log(\"Worker startup params:\",params);\n $3e39efa823870787$var$mod = new $3e39efa823870787$var$twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\n $3e39efa823870787$var$mod.loadWasm(params.urlToLoad).then(()=>{\n postMessage([\n \"startupOkay\"\n ]);\n }).catch((ex)=>{\n console.log(\".catch: \", ex);\n postMessage([\n \"startupFail\",\n ex\n ]);\n });\n } else if (e.data[0] == \"executeC\") $3e39efa823870787$var$mod.executeCImpl(e.data[1], e.data[2]).then((rc)=>{\n postMessage([\n \"executeCOkay\",\n rc\n ]);\n }).catch((e)=>{\n console.log(\"exception in executeC twrworker.js\\n\");\n console.log(e);\n postMessage([\n \"executeCFail\",\n e\n ]);\n });\n else console.log(\"twrworker.js: unknown message: \" + e);\n};\n// ************************************************************************\nclass $3e39efa823870787$var$twrWasmModuleInWorker extends (0, $ece7fa3ed770778a$export$c83a0a3bffe07399) {\n malloc;\n modParams;\n constructor(modParams, modInWorkerParams){\n super();\n this.isWorker = true;\n this.malloc = (size)=>{\n throw new Error(\"error - un-init malloc called\");\n };\n this.modParams = modParams;\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\n const canvasProxy = new (0, $c4741cac81d14197$export$c779b2cd00544976)(modInWorkerParams.canvasProxyParams, this);\n const divProxy = new (0, $8963973702ae5462$export$b377f0bbf2c7581e)(modInWorkerParams.divProxyParams);\n const waitingCallsProxy = new (0, $aff9c2c494d23fe3$export$78d2a4633fe89379)(modInWorkerParams.waitingCallsProxyParams);\n this.modParams.imports = {\n twrDebugLog: (0, $8ac0b786da854328$export$485af4d0039b3389),\n twrSleep: waitingCallsProxy.sleep.bind(waitingCallsProxy),\n twrTime: waitingCallsProxy.time.bind(waitingCallsProxy),\n twrDivCharOut: divProxy.charOut.bind(divProxy),\n twrDivCharIn: divProxy.charIn.bind(divProxy),\n twrCanvasCharIn: canvasProxy.charIn.bind(canvasProxy),\n twrCanvasInkey: canvasProxy.inkey.bind(canvasProxy),\n twrCanvasGetProp: canvasProxy.getProp.bind(canvasProxy),\n twrCanvasDrawSeq: canvasProxy.drawSeq.bind(canvasProxy),\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function(x, y) {\n return x % y;\n },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n}\n\n})();\n//# sourceMappingURL=twrmodworker.2165e649.js.map\n","// this script is the WebWorker thead used by class twrWasmAsyncModule\nimport { twrCanvasProxy } from \"./twrcanvas.js\";\nimport { twrDivProxy } from \"./twrdiv.js\";\nimport { twrDebugLogProxy } from \"./twrdebug.js\";\nimport { twrWasmModuleBase } from \"./twrmodbase.js\";\nimport { twrWaitingCallsProxy } from \"./twrwaitingcalls.js\";\nlet mod;\nonmessage = function (e) {\n //console.log('twrworker.js: message received from main script: '+e.data);\n if (e.data[0] == 'startup') {\n const params = e.data[1];\n //console.log(\"Worker startup params:\",params);\n mod = new twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\n mod.loadWasm(params.urlToLoad).then(() => {\n postMessage([\"startupOkay\"]);\n }).catch((ex) => {\n console.log(\".catch: \", ex);\n postMessage([\"startupFail\", ex]);\n });\n }\n else if (e.data[0] == 'executeC') {\n mod.executeCImpl(e.data[1], e.data[2]).then((rc) => {\n postMessage([\"executeCOkay\", rc]);\n }).catch(e => {\n console.log(\"exception in executeC twrworker.js\\n\");\n console.log(e);\n postMessage([\"executeCFail\", e]);\n });\n }\n else {\n console.log(\"twrworker.js: unknown message: \" + e);\n }\n};\n// ************************************************************************\nclass twrWasmModuleInWorker extends twrWasmModuleBase {\n malloc;\n modParams;\n constructor(modParams, modInWorkerParams) {\n super();\n this.isWorker = true;\n this.malloc = (size) => { throw new Error(\"error - un-init malloc called\"); };\n this.modParams = modParams;\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\n const canvasProxy = new twrCanvasProxy(modInWorkerParams.canvasProxyParams, this);\n const divProxy = new twrDivProxy(modInWorkerParams.divProxyParams);\n const waitingCallsProxy = new twrWaitingCallsProxy(modInWorkerParams.waitingCallsProxyParams);\n this.modParams.imports = {\n twrDebugLog: twrDebugLogProxy,\n twrSleep: waitingCallsProxy.sleep.bind(waitingCallsProxy),\n twrTime: waitingCallsProxy.time.bind(waitingCallsProxy),\n twrDivCharOut: divProxy.charOut.bind(divProxy),\n twrDivCharIn: divProxy.charIn.bind(divProxy),\n twrCanvasCharIn: canvasProxy.charIn.bind(canvasProxy),\n twrCanvasInkey: canvasProxy.inkey.bind(canvasProxy),\n twrCanvasGetProp: canvasProxy.getProp.bind(canvasProxy),\n twrCanvasDrawSeq: canvasProxy.drawSeq.bind(canvasProxy),\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function (x, y) { return x % y; },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n}\n//# sourceMappingURL=twrmodworker.js.map","// this script is the WebWorker thead used by class twrWasmAsyncModule\r\n\r\nimport {twrCanvasProxy} from \"./twrcanvas.js\";\r\nimport {twrDivProxy} from \"./twrdiv.js\";\r\nimport {twrDebugLogProxy} from \"./twrdebug.js\";\r\nimport {TAsyncModStartupMsg} from \"./twrmodasync.js\"\r\nimport {twrWasmModuleBase, IModInWorkerParams, IModParams} from \"./twrmodbase.js\"\r\nimport {twrWaitingCallsProxy} from \"./twrwaitingcalls.js\";\r\n\r\nlet mod:twrWasmModuleInWorker;\r\n\r\nonmessage = function(e) {\r\n //console.log('twrworker.js: message received from main script: '+e.data);\r\n\r\n if (e.data[0]=='startup') {\r\n const params:TAsyncModStartupMsg=e.data[1];\r\n //console.log(\"Worker startup params:\",params);\r\n mod=new twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\r\n\r\n mod.loadWasm(params.urlToLoad).then( ()=> {\r\n postMessage([\"startupOkay\"]);\r\n }).catch( (ex)=> {\r\n console.log(\".catch: \", ex);\r\n postMessage([\"startupFail\", ex]);\r\n });\r\n }\r\n else if (e.data[0]=='executeC') {\r\n mod.executeCImpl(e.data[1], e.data[2]).then( (rc)=> {\r\n postMessage([\"executeCOkay\", rc]);\r\n }).catch(e => {\r\n console.log(\"exception in executeC twrworker.js\\n\");\r\n console.log(e);\r\n postMessage([\"executeCFail\", e]);\r\n });\r\n }\r\n else {\r\n console.log(\"twrworker.js: unknown message: \"+e);\r\n }\r\n}\r\n\r\n\r\n// ************************************************************************\r\n\r\nclass twrWasmModuleInWorker extends twrWasmModuleBase {\r\n\tmalloc:(size:number)=>Promise;\r\n modParams: IModParams;\r\n\r\n\r\n constructor(modParams:IModParams, modInWorkerParams:IModInWorkerParams) {\r\n super();\r\n this.isWorker=true;\r\n this.malloc=(size:number)=>{throw new Error(\"error - un-init malloc called\")};\r\n this.modParams=modParams;\r\n\r\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\r\n const canvasProxy = new twrCanvasProxy(modInWorkerParams.canvasProxyParams, this);\r\n const divProxy = new twrDivProxy(modInWorkerParams.divProxyParams);\r\n const waitingCallsProxy = new twrWaitingCallsProxy(modInWorkerParams.waitingCallsProxyParams);\r\n\r\n this.modParams.imports={\r\n twrDebugLog:twrDebugLogProxy,\r\n twrSleep:waitingCallsProxy.sleep.bind(waitingCallsProxy),\r\n twrTime:waitingCallsProxy.time.bind(waitingCallsProxy),\r\n\r\n twrDivCharOut:divProxy.charOut.bind(divProxy), \r\n twrDivCharIn:divProxy.charIn.bind(divProxy), \r\n\r\n twrCanvasCharIn:canvasProxy.charIn.bind(canvasProxy),\r\n twrCanvasInkey:canvasProxy.inkey.bind(canvasProxy),\r\n twrCanvasGetProp:canvasProxy.getProp.bind(canvasProxy),\r\n twrCanvasDrawSeq:canvasProxy.drawSeq.bind(canvasProxy),\r\n\r\n\t\t\ttwrSin:Math.sin,\r\n\t\t\ttwrCos:Math.cos,\r\n\t\t\ttwrTan: Math.tan,\r\n\t\t\ttwrFAbs: Math.abs,\r\n\t\t\ttwrACos: Math.acos,\r\n\t\t\ttwrASin: Math.asin,\r\n\t\t\ttwrATan: Math.atan,\r\n\t\t\ttwrExp: Math.exp,\r\n\t\t\ttwrFloor: Math.floor,\r\n\t\t\ttwrCeil: Math.ceil,\r\n\t\t\ttwrFMod: function(x:number, y:number) {return x%y},\r\n\t\t\ttwrLog: Math.log,\r\n\t\t\ttwrPow: Math.pow,\r\n\t\t\ttwrSqrt: Math.sqrt,\r\n\t\t\ttwrTrunc: Math.trunc,\r\n\r\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\r\n\t\t\ttwrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\r\n\t\t\ttwrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\r\n\t\t\ttwrAtod: this.floatUtil.atod.bind(this.floatUtil),\r\n\t\t\ttwrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\r\n \r\n }\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nimport { twrSignal } from \"./twrsignal.js\";\nvar D2DType;\n(function (D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})(D2DType || (D2DType = {}));\nexport class twrCanvas {\n ctx;\n props = { charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight: 0, canvasWidth: 0 };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase) {\n const { forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new twrSignal();\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext)\n throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c)\n throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2)\n throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\n }\n getProp(pn) {\n if (!this.isValid())\n console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */\n drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid())\n console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx)\n return;\n let ins = this.owner.getLong(ds); /* ds->start */\n const lastins = this.owner.getLong(ds + 4); /* ds->last */\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while (1) {\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */\n if (0 /*type!=D2DType.D2D_FILLRECT*/) {\n console.log(\"ins\", ins);\n console.log(\"hdr.next\", this.owner.mem8[ins], this.owner.mem8[ins + 1], this.owner.mem8[ins + 2], this.owner.mem8[ins + 3]);\n console.log(\"hdr.type\", this.owner.mem8[ins + 4], this.owner.mem8[ins + 5]);\n console.log(\"next 4 bytes\", this.owner.mem8[ins + 6], this.owner.mem8[ins + 7], this.owner.mem8[ins + 8], this.owner.mem8[ins + 9]);\n console.log(\"and 4 more \", this.owner.mem8[ins + 10], this.owner.mem8[ins + 11], this.owner.mem8[ins + 12], this.owner.mem8[ins + 13]);\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\n }\n switch (type) {\n case D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case D2DType.D2D_BEGINPATH:\n {\n this.ctx.beginPath();\n }\n break;\n case D2DType.D2D_FILL:\n {\n this.ctx.fill();\n }\n break;\n case D2DType.D2D_SAVE:\n {\n this.ctx.save();\n }\n break;\n case D2DType.D2D_RESTORE:\n {\n this.ctx.restore();\n }\n break;\n case D2DType.D2D_STROKE:\n {\n this.ctx.stroke();\n }\n break;\n case D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = (this.owner.getLong(ins + 48) != 0);\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n }\n else { // Uint8ClampedArray doesn't support shared memory\n this.precomputedObjects[id] = { mem8: new Uint8Array(this.owner.memory.buffer, start, length), width: width, height: height };\n }\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id])\n delete this.precomputedObjects[id];\n else\n console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) {\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n }\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) {\n this.ctx.putImageData(imgData, dx, dy);\n }\n else {\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */\n if (next == 0) {\n if (ins != lastins)\n throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal)\n this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nexport class twrCanvasProxy {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner) {\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new twrSignal(signalBuffer);\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\"drawseq\", [ds]]);\n this.drawCompleteSignal.wait();\n }\n}\n//# sourceMappingURL=twrcanvas.js.map","import {twrWasmModuleBase, IModParams} from \"./twrmodbase.js\"\r\nimport {twrSharedCircularBuffer} from \"./twrcircular.js\";\r\nimport {twrSignal} from \"./twrsignal.js\";\r\n\r\n\r\n// Canvas have a size that will be set based on the character width x height\r\n// The display size for a canvas will default to this size, but can be changed in the HTML/JS via\r\n// canvas.style.width = \"700px\";\r\n// canvas.style.height = \"500px\";\r\n\r\nexport interface ICanvasProps {\r\n\tcharWidth: number,\r\n\tcharHeight: number,\r\n\tforeColor: number,\r\n\tbackColor: number,\r\n widthInChars: number,\r\n heightInChars: number,\r\n canvasWidth:number,\r\n canvasHeight:number\r\n}\r\n\r\nenum D2DType {\r\n D2D_FILLRECT=1,\r\n D2D_FILLCHAR=5,\r\n D2D_SETLINEWIDTH=10,\r\n D2D_SETFILLSTYLERGBA=11,\r\n D2D_SETFONT=12,\r\n D2D_BEGINPATH=13,\r\n D2D_MOVETO=14,\r\n D2D_LINETO=15,\r\n D2D_FILL=16,\r\n D2D_STROKE=17,\r\n D2D_SETSTROKESTYLERGBA=18,\r\n D2D_ARC=19,\r\n D2D_STROKERECT=20,\r\n D2D_FILLTEXT=21,\r\n D2D_IMAGEDATA=22,\r\n D2D_PUTIMAGEDATA=23,\r\n D2D_BEZIERTO=24,\r\n D2D_MEASURETEXT=25,\r\n D2D_SAVE=26,\r\n D2D_RESTORE=27,\r\n D2D_CREATERADIALGRADIENT=28,\r\n D2D_SETCOLORSTOP=29,\r\n D2D_SETFILLSTYLEGRADIENT=30,\r\n D2D_RELEASEID=31,\r\n D2D_CREATELINEARGRADIENT=32,\r\n D2D_SETFILLSTYLE=33,\r\n D2D_SETSTROKESTYLE=34\r\n\r\n}\r\n\r\nexport type TCanvasProxyParams = [ICanvasProps, SharedArrayBuffer, SharedArrayBuffer];\r\n\r\nexport interface ICanvas {\r\n props: ICanvasProps,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TCanvasProxyParams,\r\n drawSeq: (ds:number)=>void,\r\n }\r\n \r\nexport class twrCanvas implements ICanvas {\r\n ctx:CanvasRenderingContext2D|undefined;\r\n props:ICanvasProps={charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight:0, canvasWidth:0};\r\n owner: twrWasmModuleBase;\r\n cmdCompleteSignal?:twrSignal;\r\n canvasKeys?: twrSharedCircularBuffer;\r\n precomputedObjects: { [index: number]: \r\n (ImageData | {mem8:Uint8Array, width:number, height:number}) |\r\n CanvasGradient\r\n };\r\n\r\n constructor(element:HTMLCanvasElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n const {forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas} = modParams; \r\n this.owner=modbase;\r\n this.props.widthInChars=modParams.windim[0];\r\n this.props.heightInChars=modParams.windim[1];\r\n\r\n if (!this.owner.isWasmModule) {\r\n this.cmdCompleteSignal=new twrSignal();\r\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n }\r\n\r\n this.precomputedObjects={};\r\n \r\n if (element) {\r\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\r\n let c=element.getContext(\"2d\");\r\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\r\n\r\n c.font = fontsize.toString()+\"px Courier New\";\r\n c.textBaseline=\"top\";\r\n const sampleText=\" \";\r\n const tm=c.measureText(sampleText);\r\n this.props.charWidth=Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\r\n let fM = c.measureText(\"X\"); \r\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\r\n\r\n if (!isd2dcanvas) {\r\n element.width=this.props.charWidth*this.props.widthInChars;\r\n element.height=this.props.charHeight*this.props.heightInChars;\r\n }\r\n\r\n this.props.canvasHeight=element.height;\r\n this.props.canvasWidth=element.width;\r\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\r\n\r\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\r\n let c2=element.getContext(\"2d\");\r\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\r\n this.ctx=c2;\r\n this.ctx.font = fontsize.toString()+\"px Courier New\";\r\n this.ctx.textBaseline=\"top\";\r\n\r\n c2.fillStyle=backcolor;\r\n this.props.backColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n c2.fillStyle=forecolor;\r\n this.props.foreColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n }\r\n\r\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\r\n\r\n //console.log(\"twrCanvas.constructor props: \", this.props);\r\n }\r\n\r\n isValid() {\r\n return !!this.ctx;\r\n }\r\n\r\n getProxyParams() : TCanvasProxyParams {\r\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\r\n }\r\n\r\n getProp(pn:number): number {\r\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n\r\n/* see draw2d.h for structs that match */\r\n\r\n drawSeq(ds:number) {\r\n //console.log(\"twr::Canvas enter drawSeq\");\r\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\r\n if (!this.ctx) return;\r\n\r\n let ins=this.owner.getLong(ds); /* ds->start */\r\n const lastins=this.owner.getLong(ds+4); /* ds->last */\r\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\r\n\r\n let next:number;\r\n //let insCount=0;\r\n\r\n while (1) {\r\n\r\n //insCount++;\r\n\r\n const type:D2DType=this.owner.getLong(ins+4); /* hdr->type */\r\n if (0/*type!=D2DType.D2D_FILLRECT*/) {\r\n console.log(\"ins\",ins)\r\n console.log(\"hdr.next\",this.owner.mem8[ins],this.owner.mem8[ins+1],this.owner.mem8[ins+2],this.owner.mem8[ins+3]);\r\n console.log(\"hdr.type\",this.owner.mem8[ins+4],this.owner.mem8[ins+5]);\r\n console.log(\"next 4 bytes\", this.owner.mem8[ins+6],this.owner.mem8[ins+7],this.owner.mem8[ins+8],this.owner.mem8[ins+9]);\r\n console.log(\"and 4 more \", this.owner.mem8[ins+10],this.owner.mem8[ins+11],this.owner.mem8[ins+12],this.owner.mem8[ins+13]);\r\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\r\n }\r\n switch (type) {\r\n case D2DType.D2D_FILLRECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.fillRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKERECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.strokeRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILLCHAR:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const c=this.owner.getShort(ins+24);\r\n let txt=String.fromCharCode(c);\r\n this.ctx.fillText(txt, x, y);\r\n }\r\n break;\r\n\r\n \r\n case D2DType.D2D_FILLTEXT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const str=this.owner.getString(this.owner.getLong(ins+24));\r\n\r\n //console.log(\"filltext \",x,y,str)\r\n \r\n this.ctx.fillText(str, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MEASURETEXT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n const tmidx=this.owner.getLong(ins+12);\r\n \r\n const tm=this.ctx.measureText(str);\r\n this.owner.setDouble(tmidx+0, tm.actualBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+8, tm.actualBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+16, tm.actualBoundingBoxLeft);\r\n this.owner.setDouble(tmidx+24, tm.actualBoundingBoxRight);\r\n this.owner.setDouble(tmidx+32, tm.fontBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+40, tm.fontBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+48, tm.width);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFONT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.font=str;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.fillStyle = cssColor;\r\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETSTROKESTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.fillStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETSTROKESTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETLINEWIDTH:\r\n {\r\n const width=this.owner.getShort(ins+8); \r\n this.ctx.lineWidth=width;\r\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MOVETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.moveTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_LINETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.lineTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEZIERTO:\r\n {\r\n const cp1x=this.owner.getDouble(ins+8);\r\n const cp1y=this.owner.getDouble(ins+16);\r\n const cp2x=this.owner.getDouble(ins+24);\r\n const cp2y=this.owner.getDouble(ins+32);\r\n const x=this.owner.getDouble(ins+40);\r\n const y=this.owner.getDouble(ins+48);\r\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEGINPATH:\r\n {\r\n this.ctx.beginPath();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILL:\r\n {\r\n this.ctx.fill();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SAVE:\r\n {\r\n this.ctx.save();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_RESTORE:\r\n {\r\n this.ctx.restore();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKE:\r\n {\r\n this.ctx.stroke();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_ARC:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const radius=this.owner.getDouble(ins+24);\r\n const startAngle=this.owner.getDouble(ins+32);\r\n const endAngle=this.owner.getDouble(ins+40);\r\n const counterClockwise= (this.owner.getLong(ins+48)!=0);\r\n\r\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_IMAGEDATA:\r\n {\r\n const start=this.owner.getLong(ins+8);\r\n const length=this.owner.getLong(ins+12);\r\n const width=this.owner.getLong(ins+16);\r\n const height=this.owner.getLong(ins+20);\r\n const id=this.owner.getLong(ins+24);\r\n\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\r\n\r\n if (this.owner.isWasmModule) {\r\n const z = new Uint8ClampedArray(this.owner.memory!.buffer, start, length);\r\n this.precomputedObjects[id]=new ImageData(z, width, height);\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory\r\n this.precomputedObjects[id]={mem8: new Uint8Array(this.owner.memory!.buffer, start, length), width:width, height:height};\r\n }\r\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_CREATERADIALGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const radius0=this.owner.getDouble(ins+24);\r\n const x1=this.owner.getDouble(ins+32);\r\n const y1=this.owner.getDouble(ins+40);\r\n const radius1=this.owner.getDouble(ins+48);\r\n const id= this.owner.getLong(ins+56);\r\n\r\n let gradient=this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_CREATELINEARGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const x1=this.owner.getDouble(ins+24);\r\n const y1=this.owner.getDouble(ins+32);\r\n const id= this.owner.getLong(ins+40);\r\n \r\n let gradient=this.ctx.createLinearGradient(x0, y0, x1, y1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETCOLORSTOP:\r\n {\r\n const id = this.owner.getLong(ins+8);\r\n const pos=this.owner.getLong(ins+12);\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+16));\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n gradient.addColorStop(pos, cssColor);\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n this.ctx.fillStyle=gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_RELEASEID:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (this.precomputedObjects[id])\r\n delete this.precomputedObjects[id];\r\n else\r\n console.log(\"warning: D2D_RELEASEID with undefined ID \",id);\r\n }\r\n break\r\n\r\n \r\n\r\n case D2DType.D2D_PUTIMAGEDATA:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n const dx=this.owner.getLong(ins+12);\r\n const dy=this.owner.getLong(ins+16);\r\n const dirtyX=this.owner.getLong(ins+20);\r\n const dirtyY=this.owner.getLong(ins+24);\r\n const dirtyWidth=this.owner.getLong(ins+28);\r\n const dirtyHeight=this.owner.getLong(ins+32);\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \"+id);\r\n\r\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\r\n\r\n let imgData:ImageData;\r\n if (this.owner.isWasmModule) {\r\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\r\n imgData=this.precomputedObjects[id] as ImageData;\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\r\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\r\n const z = this.precomputedObjects[id] as {mem8:Uint8Array, width:number, height:number}; // Uint8Array\r\n const ca=Uint8ClampedArray.from(z.mem8); // shallow copy\r\n imgData=new ImageData(ca, z.width, z.height);\r\n }\r\n \r\n if (dirtyWidth==0 && dirtyHeight==0) {\r\n this.ctx.putImageData(imgData, dx, dy);\r\n }\r\n else {\r\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\r\n }\r\n }\r\n break;\r\n\r\n default:\r\n throw new Error (\"unimplemented or unknown Sequence Type in drawSeq: \"+type);\r\n }\r\n next=this.owner.getLong(ins); /* hdr->next */\r\n if (next==0) {\r\n if (ins!=lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\r\n break;\r\n }\r\n ins=next;\r\n }\r\n\r\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\r\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\r\n }\r\n}\r\n\r\nexport class twrCanvasProxy implements ICanvas {\r\n canvasKeys: twrSharedCircularBuffer;\r\n drawCompleteSignal:twrSignal;\r\n props: ICanvasProps;\r\n owner: twrWasmModuleBase;\r\n\r\n constructor(params:TCanvasProxyParams, owner:twrWasmModuleBase) {\r\n const [props, signalBuffer, canvasKeysBuffer] = params;\r\n this.drawCompleteSignal = new twrSignal(signalBuffer);\r\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\r\n this.props=props;\r\n this.owner=owner;\r\n\r\n //console.log(\"Create New twrCanvasProxy: \",this.props)\r\n\r\n }\r\n\r\n charIn() { \r\n //ctx.commit(); not avail in chrome\r\n \r\n //postMessage([\"debug\", 'x']);\r\n \r\n return this.canvasKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.canvasKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n getProp(pn:number): number {\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n \r\n drawSeq(ds:number) {\r\n this.drawCompleteSignal.reset();\r\n postMessage([\"drawseq\", [ds]]);\r\n this.drawCompleteSignal.wait();\r\n }\r\n}\r\n","//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst RDIDX = 256;\nconst WRIDX = 257;\nconst LEN = 256;\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\n// the first 256 array entries are the circular buffer\n// the next two are used for the read and write index\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\nexport class twrSharedCircularBuffer {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(258 * 4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[RDIDX] = 0;\n this.buf[WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[WRIDX];\n this.buf[i] = n;\n i++;\n if (i == LEN)\n i = 0;\n this.buf[WRIDX] = i;\n Atomics.notify(this.buf, WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[RDIDX] = i;\n return n;\n }\n else\n return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[RDIDX] == this.buf[WRIDX];\n }\n}\n//# sourceMappingURL=twrcircular.js.map","//\r\n// This class implements a circular buffer that the main javascript thread can write to, \r\n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\r\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \r\n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\r\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\r\n//\r\n\r\nconst RDIDX=256;\r\nconst WRIDX=257;\r\nconst LEN=256;\r\n\r\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\r\n// the first 256 array entries are the circular buffer\r\n// the next two are used for the read and write index\r\n\r\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\r\n\r\nexport class twrSharedCircularBuffer {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n \r\n\tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(258*4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[RDIDX]=0;\r\n this.buf[WRIDX]=0;\r\n\t}\r\n\r\n\twrite(n:number) {\r\n let i=this.buf[WRIDX];\r\n this.buf[i]=n;\r\n i++;\r\n if (i==LEN) i=0;\r\n this.buf[WRIDX]=i; \r\n Atomics.notify(this.buf, WRIDX); \r\n\t}\r\n\r\n\tread():number {\r\n if (!this.isEmpty()) {\r\n let i=this.buf[RDIDX];\r\n let n=this.buf[i];\r\n i++;\r\n this.buf[RDIDX]=i;\r\n return n;\r\n }\r\n\t\telse\r\n return -1;\r\n\t}\r\n\r\n readWait():number {\r\n if (this.isEmpty()) {\r\n const rdptr=this.buf[RDIDX];\r\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\r\n Atomics.wait(this.buf, WRIDX, rdptr);\r\n }\r\n return this.read();\r\n\t}\r\n\r\n isEmpty():boolean {\r\n return this.buf[RDIDX]==this.buf[WRIDX];\r\n }\r\n}\r\n","//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar twrSignalState;\n(function (twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})(twrSignalState || (twrSignalState = {}));\n;\nexport class twrSignal {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window valid\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == twrSignalState.WAITING) {\n //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\n //console.log(\"released...\");\n }\n }\n isSignaled() {\n return this.buf[0] == twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = twrSignalState.WAITING;\n }\n}\n//# sourceMappingURL=twrsignal.js.map","//\r\n// This class implements a simple signal/wait mechanism\r\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\r\n//\r\n\r\nenum twrSignalState {\r\n WAITING=0,\r\n SIGNALED=1\r\n};\r\n\r\nexport class twrSignal {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n\r\n \tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window valid\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) \r\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[0]=twrSignalState.WAITING;\r\n\t}\r\n\r\n\tsignal() {\r\n this.buf[0]=twrSignalState.SIGNALED; \r\n //console.log(\"about to signal\");\r\n Atomics.notify(this.buf, 0); \r\n\t}\r\n\r\n wait() {\r\n if (this.buf[0]==twrSignalState.WAITING) {\r\n //console.log(\"waiting...\");\r\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\r\n //console.log(\"released...\");\r\n\r\n }\r\n\t}\r\n isSignaled():boolean {\r\n return this.buf[0]==twrSignalState.SIGNALED;\r\n }\r\n\r\n reset() {\r\n this.buf[0]=twrSignalState.WAITING;\r\n }\r\n}\r\n","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nexport class twrDiv {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase) {\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\n this.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n if (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.divKeys.sharedArray];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */\n charOut(ch) {\n if (!this.div)\n return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n }\n switch (ch) {\n case 10: // newline\n case 13: // return\n if (ch == 10 && this.lastChar == 13)\n break; // detect CR LF and treat as single new line\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8: // backspace\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n case 0xE: // cursor on\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF: // cursor off\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for (let i = 0; i < str.length; i++)\n this.charOut(str.charCodeAt(i));\n }\n}\nexport class twrDivProxy {\n divKeys;\n constructor(params) {\n const [divKeysBuffer] = params;\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n charOut(ch) {\n postMessage([\"divout\", ch]);\n }\n}\n//# sourceMappingURL=twrdiv.js.map","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\r\nimport { IModParams } from \"./twrmodbase.js\";\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\";\r\n\r\nexport type TDivProxyParams = [SharedArrayBuffer];\r\n\r\nexport interface IDiv {\r\n charOut: (ds:number)=>void,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TDivProxyParams,\r\n }\r\n\r\n\r\nexport class twrDiv implements IDiv {\r\n\tdiv:HTMLDivElement|null|undefined;\r\n\tdivKeys?:twrSharedCircularBuffer;\r\n\tCURSOR=String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\r\n\tcursorOn:boolean=false;\r\n\tlastChar:number=0;\r\n\textraBR:boolean=false;\r\n\towner:twrWasmModuleBase;\r\n\r\n constructor(element:HTMLDivElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n\t\tthis.div=element;\r\n\t\tthis.owner=modbase;\r\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\r\n\t\t\tthis.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n\t\t}\r\n\r\n\t\tif (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\r\n\t\t\tthis.div.style.backgroundColor = modParams.backcolor;\r\n\t\t\tthis.div.style.color = modParams.forecolor;\r\n\t\t\tthis.div.style.font=modParams.fontsize.toString()+\"px arial\"\r\n\t\t}\r\n }\r\n\r\n\tisValid() {\r\n\t\treturn !!this.div;\r\n\t}\r\n\r\n getProxyParams() : TDivProxyParams {\r\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [ this.divKeys.sharedArray];\r\n }\r\n\r\n\r\n/* \r\n * add character to div. Supports the following control codes:\r\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\r\n * 0xE cursor on \r\n * 0x8 backspace\r\n * 0xF cursor off \r\n*/\r\n\tcharOut(ch:number) {\r\n\r\n\t\tif (!this.div) return;\r\n\r\n\t\t//console.log(\"div::charout: \", ch);\r\n\r\n\t\tif (this.extraBR) {\r\n\t\t\tthis.extraBR=false;\r\n\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -4);\r\n\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t}\r\n\r\n\t\tswitch (ch) {\r\n\t\t\tcase 10: // newline\r\n\t\t\tcase 13: // return\r\n\t\t\t\tif (ch==10 && this.lastChar==13) break; // detect CR LF and treat as single new line\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\r\n\t\t\t\tthis.extraBR=true;\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\t//element.scrollIntoView();\r\n\t\t\t\t//element.scrollTop = element.scrollHeight;\r\n\t\t\t\tlet p = this.div.getBoundingClientRect();\r\n\t\t\t\twindow.scrollTo(0, p.height+100);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 8: // backspace\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xE: // cursor on\r\n\t\t\t\tif (!this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=true;\r\n\t\t\t\t\tthis.div.innerHTML += this.CURSOR;\r\n\t\t\t\t\tthis.div.focus();\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xF: // cursor off\r\n\t\t\t\tif (this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=false;\r\n\t\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += String.fromCharCode(ch);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\tthis.lastChar=ch;\r\n\t}\r\n\r\n\tstringOut(str:string) {\r\n\t\tfor (let i=0; i < str.length; i++)\r\n\t\t\tthis.charOut(str.charCodeAt(i));\r\n\t}\r\n}\r\n\r\n\r\nexport class twrDivProxy implements IDiv {\r\n divKeys: twrSharedCircularBuffer;\r\n\r\n constructor(params:TDivProxyParams) {\r\n const [divKeysBuffer] = params;\r\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\r\n }\r\n\r\n charIn() { \r\n return this.divKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.divKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n\tcharOut(ch:number) {\r\n\t\tpostMessage([\"divout\", ch]);\r\n\t}\r\n}\r\n\r\n","let logline = \"\";\nexport function twrDebugLogImpl(char) {\n if (char == 10 || char == 3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\n console.log(logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n logline = \"\";\n }\n else {\n logline = logline + String.fromCharCode(char);\n if (logline.length >= 200) {\n console.log(logline);\n logline = \"\";\n }\n }\n}\n// ************************************************************************\n// debugLog doesn't currently wait for the message to log, it returns immediately.\n// I could move this to be in the twrWaitingCalls class\nexport function twrDebugLogProxy(ch) {\n postMessage([\"debug\", ch]);\n}\n//# sourceMappingURL=twrdebug.js.map","\r\nlet logline=\"\";\r\nexport function twrDebugLogImpl(char:number) {\r\n\tif (char==10 || char==3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\r\n\t\tconsole.log(logline);\t// ideally without a linefeed, but there is no way to not have a LF with console.log API.\r\n\t\tlogline=\"\";\r\n\t}\r\n\telse {\r\n\t\tlogline=logline+String.fromCharCode(char);\r\n\t\tif (logline.length>=200) {\r\n\t\t\tconsole.log(logline);\r\n\t\t\tlogline=\"\";\r\n\t\t}\r\n\t}\r\n}\r\n\r\n// ************************************************************************\r\n// debugLog doesn't currently wait for the message to log, it returns immediately.\r\n// I could move this to be in the twrWaitingCalls class\r\nexport function twrDebugLogProxy(ch:number) {\r\n postMessage([\"debug\", ch]);\r\n}\r\n\r\n","import { twrFloatUtil } from \"./twrfloat.js\";\n/*********************************************************************/\n/*********************************************************************/\n/*********************************************************************/\nexport class twrWasmModuleBase {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\n floatUtil;\n constructor(isWasmModule = false) {\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new twrFloatUtil(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/\n /*********************************************************************/\n async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n }\n catch (err) {\n console.log('loadWasm() failed to fetch: ' + pathToLoad);\n throw err;\n }\n if (!response.ok)\n throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, { env: allimports });\n this.exports = instance.instance.exports;\n if (!this.exports)\n throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory)\n throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory)\n throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer)\n console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\"setmemory\", this.memory]);\n }\n if (this.isWasmModule) {\n // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (!(this.memory.buffer instanceof ArrayBuffer))\n console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size) => {\n return new Promise(resolve => {\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n }\n catch (err) {\n console.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch (this.modParams.stdio) {\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* executeC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */\n async executeC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.executeCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async executeCImpl(fname, cparams = []) {\n if (!this.exports)\n throw new Error(\"this.exports undefined\");\n if (!this.exports[fname])\n throw new Error(\"executeC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array))\n throw new Error(\"executeC: params must be array, first arg is function name\");\n if (params.length == 0)\n throw new Error(\"executeC: missing function name\");\n let cparams = [];\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n cparams[ci++] = p;\n break;\n case 'string':\n cparams[ci++] = await this.putString(p);\n break;\n case 'object':\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n }\n else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"executeC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n ci++;\n break;\n case 'string':\n this.executeCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n case 'object':\n if (p instanceof URL) {\n this.executeCImpl('twr_free', [cparams[ci]]);\n ci = ci + 2;\n break;\n }\n else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for (let j = 0; j < u8.length; j++)\n u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.executeCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n }\n else\n throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/\n /*********************************************************************/\n // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for (i = 0; i < sin.length && i < buffer_size - 1; i++)\n this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for (let i = 0; i < u8a.length; i++)\n this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === 'object' && fnin instanceof URL))\n throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [dest, src.length];\n }\n catch (err) {\n console.log('fetchAndPutURL Error. URL: ' + fnin + '\\n' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while (this.mem8[strIndex + i] && (len === undefined ? true : i < len) && (strIndex + i) < this.mem8.length) {\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0)\n throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array((this.mem8.slice(dataptr, dataptr + size)).buffer);\n return u32;\n }\n}\n//# sourceMappingURL=twrmodbase.js.map","\r\nimport {TCanvasProxyParams} from \"./twrcanvas.js\"\r\nimport {TDivProxyParams} from \"./twrdiv.js\";\r\nimport {TWaitingCallsProxyParams} from \"./twrwaitingcalls.js\"\r\nimport {twrDebugLogImpl} from \"./twrdebug.js\";\r\nimport {twrFloatUtil} from \"./twrfloat.js\";\r\n\r\n\r\nexport type TStdioVals=\"div\"|\"canvas\"|\"null\"|\"debug\";\r\n\r\nexport interface IModOpts {\r\n\tstdio?:TStdioVals, \r\n\twindim?:[number, number],\r\n\tforecolor?:string,\r\n\tbackcolor?:string,\r\n\tfontsize?:number,\r\n\tisd2dcanvas?:boolean,\r\n\timports?:{},\r\n}\r\n\r\nexport interface IModParams {\r\n\tstdio:TStdioVals, \r\n\twindim:[number, number],\r\n\tforecolor:string,\r\n\tbackcolor:string,\r\n\tfontsize:number,\r\n\tstyleIsDefault: boolean\r\n\tisd2dcanvas:boolean,\r\n\timports:{[index:string]:Function},\r\n}\r\n\r\nexport interface IModInWorkerParams {\r\n\tdivProxyParams:TDivProxyParams,\r\n\tcanvasProxyParams:TCanvasProxyParams,\r\n\twaitingCallsProxyParams:TWaitingCallsProxyParams,\r\n}\r\n\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n\r\nexport abstract class twrWasmModuleBase {\r\n\tmemory?:WebAssembly.Memory;\r\n\tmem8:Uint8Array;\r\n\tmem32:Uint32Array;\r\n\tmemD:Float64Array;\r\n\tabstract malloc:(size:number)=>Promise;\r\n\tabstract modParams:IModParams;\r\n\texports?:WebAssembly.Exports;\r\n\tisWorker=false;\r\n\tisWasmModule:boolean; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\r\n\tfloatUtil:twrFloatUtil;\r\n\r\n\tconstructor(isWasmModule=false) {\r\n\t\tthis.isWasmModule=isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\r\n\t\tthis.mem8=new Uint8Array(); \t// avoid type errors\r\n\t\tthis.mem32=new Uint32Array(); // avoid type errors\r\n\t\tthis.memD=new Float64Array(); // avoid type errors\r\n\t\tthis.floatUtil=new twrFloatUtil(this);\r\n\t\t//console.log(\"size of mem8 after constructor\",this.mem8.length);\r\n\t}\r\n\r\n\t/*********************************************************************/\r\n\t/*********************************************************************/\r\n\r\n\tasync loadWasm(pathToLoad:string) {\r\n\t\t//console.log(\"fileToLoad\",fileToLoad)\r\n\r\n\t\tlet response;\r\n\t\ttry {\r\n\t\t\tresponse=await fetch(pathToLoad);\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('loadWasm() failed to fetch: '+pathToLoad);\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t\t\r\n\t\tif (!response.ok) throw new Error(\"fetch response error on file '\"+pathToLoad+\"'\\n\"+response.statusText);\r\n\r\n\t\ttry {\r\n\t\t\tlet wasmBytes = await response.arrayBuffer();\r\n\r\n\t\t\tlet allimports:WebAssembly.ModuleImports = { \r\n\t\t\t\t...this.modParams.imports\r\n\t\t\t};\r\n\r\n\t\t\tlet instance = await WebAssembly.instantiate(wasmBytes, {env: allimports});\r\n\r\n\t\t\tthis.exports=instance.instance.exports;\r\n\t\t\tif (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\r\n\r\n\t\t\tif (this.memory) throw new Error (\"unexpected error -- this.memory already set\");\r\n\t\t\tthis.memory=this.exports.memory as WebAssembly.Memory;\r\n\t\t\tif (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\r\n\t\t\tthis.mem8 = new Uint8Array(this.memory.buffer);\r\n\t\t\tthis.mem32 = new Uint32Array(this.memory.buffer);\r\n\t\t\tthis.memD = new Float64Array(this.memory.buffer);\r\n\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\tif (this.isWorker) {\r\n\t\t\t\tif (this.memory.buffer instanceof ArrayBuffer)\r\n\t\t\t\t\tconsole.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\r\n\t\t\t\t\r\n\t\t\t\tpostMessage([\"setmemory\",this.memory]);\r\n\t\t\t}\r\n\t\t\tif (this.isWasmModule) {\r\n\t\t\t\t// here if twrWasmModule, twrWasmModuleAsync overrides this function\r\n\t\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\t\tif (!(this.memory.buffer instanceof ArrayBuffer))\r\n\t\t\t\t\tconsole.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\r\n\t\t\t}\r\n\r\n\t\t\tthis.malloc=(size:number)=>{\r\n\t\t\t\treturn new Promise(resolve => {\r\n\t\t\t\t\tconst m=this.exports!.twr_malloc as (size:number)=>number;\r\n\t\t\t\t\tresolve(m(size));\r\n\t\t\t\t});\r\n\t\t };\r\n\r\n\t\t\tthis.init();\r\n\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t}\r\n\r\n\tprivate init() {\r\n\t\t//console.log(\"loadWasm.init() enter\")\r\n\t\t\tlet p:number;\r\n\t\t\tswitch (this.modParams.stdio) {\r\n\t\t\t\tcase \"debug\":\r\n\t\t\t\t\tp=0;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"div\":\r\n\t\t\t\t\tp=1;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"canvas\":\r\n\t\t\t\t\tp=2;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"null\":\r\n\t\t\t\t\tp=3;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tp=0; // debug\r\n\t\t\t}\r\n\r\n\t\t\tconst twrInit=this.exports!.twr_wasm_init as CallableFunction;\r\n\t\t\t//console.log(\"twrInit:\",twrInit)\r\n\t\t\ttwrInit(p, this.mem8.length);\r\n\t}\r\n\r\n\t/* executeC takes an array where:\r\n\t* the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\r\n\t* and the next entries are a variable number of parameters to pass to the C function, of type\r\n\t* number - converted to int32 or float64 as appropriate\r\n\t* string - converted to a an index (ptr) into a module Memory returned via stringToMem()\r\n\t* URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\r\n\t* Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\r\n */\r\n\r\n\tasync executeC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\t\tconst cparams=await this.preCallC(params);\r\n\t\tlet retval = this.executeCImpl(params[0], cparams);\r\n\t\tthis.postCallC(cparams, params);\r\n\t\treturn retval;\r\n\t}\r\n\r\n\tasync executeCImpl(fname:string, cparams:number[]=[]) {\r\n\t\tif (!this.exports) throw new Error(\"this.exports undefined\");\r\n\t\tif (!this.exports[fname]) throw new Error(\"executeC: function '\"+fname+\"' not in export table. Use --export wasm-ld flag.\");\r\n\r\n\t\tconst f = this.exports[fname] as CallableFunction;\r\n\t\tlet cr=f(...cparams);\r\n\r\n\t\treturn cr;\r\n\t}\r\n\r\n\t// convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\r\n\tasync preCallC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tif (!(params.constructor === Array)) throw new Error (\"executeC: params must be array, first arg is function name\");\r\n\t\tif (params.length==0) throw new Error(\"executeC: missing function name\");\r\n\r\n\t\tlet cparams:number[]=[];\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tcparams[ci++]=p;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tcparams[ci++]=await this.putString(p);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tconst r=await this.fetchAndPutURL(p);\r\n\t\t\t\t\t\tcparams[ci++]=r[0]; // mem index\r\n\t\t\t\t\t\tcparams[ci++]=r[1]; // len\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tconst r=await this.putArrayBuffer(p);\r\n\t\t\t\t\t\tcparams[ci++]=r; // mem index\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tthrow new Error (\"executeC: invalid object type passed in\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn cparams;\r\n\t}\r\n\r\n\t// free the mallocs; copy array buffer data from malloc back to arraybuffer\r\n\tasync postCallC(cparams:number[], params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tthis.executeCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t\t\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tthis.executeCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\t\tci=ci+2;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tlet u8=new Uint8Array(p);\r\n\t\t\t\t\t\tfor (let j=0; j= this.mem32.length) throw new Error(\"invalid index passed to getLong: \"+idx+\", this.mem32.length: \"+this.mem32.length);\r\n\t\tconst long:number = this.mem32[idx32];\r\n\t\treturn long;\r\n\t}\r\n\t\r\n\tsetLong(idx:number, value:number) {\r\n const idx32 = Math.floor(idx / 4);\r\n if (idx32 * 4 != idx)\r\n throw new Error(\"setLong passed non long aligned address\");\r\n if (idx32 < 0 || idx32 >= this.mem32.length)\r\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\r\n this.mem32[idx32]=value;\r\n }\r\n\r\n\tgetDouble(idx:number): number {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"getLong passed non Float64 aligned address\")\r\n\t\tconst long:number = this.memD[idx64];\r\n\t\treturn long;\r\n\t}\r\n\r\n\tsetDouble(idx:number, value:number) {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"setDouble passed non Float64 aligned address\")\r\n\t\tthis.memD[idx64]=value;\r\n\t}\r\n\r\n\tgetShort(idx:number): number {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getShort: \"+idx);\r\n\t\tconst short:number = this.mem8[idx]+this.mem8[idx+1]*256;\r\n\t\treturn short;\r\n\t}\r\n\r\n\t// get a string out of module memory\r\n\t// null terminated, up until max of (optional) len\r\n\tgetString(strIndex:number, len?:number): string {\r\n\t\tlet sout=\"\";\r\n\r\n\t\tlet i=0;\r\n\t\twhile (this.mem8[strIndex+i] && (len===undefined?true:i= this.mem8.length) throw new Error(\"invalid index passed to getU8: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU8\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU8\")\r\n\r\n\t\tconst u8=this.mem8.slice(dataptr, dataptr+size);\r\n\t\treturn u8;\r\n\t}\r\n\r\n\t// get a int32 array out of module memory when passed in index to [size, dataptr]\r\n\tgetU32Arr(idx:number): Uint32Array {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getU32: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU32\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU32\")\r\n\r\n\t\tif (size%4!=0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\r\n\r\n\t\tconst u32 = new Uint32Array( (this.mem8.slice(dataptr, dataptr+size)).buffer );\r\n\t\treturn u32;\r\n\t}\r\n}\r\n","export class twrFloatUtil {\n mod;\n constructor(mod) {\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\")\n return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\")\n return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll('D', 'e').replaceAll('d', 'e'));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n }\n else {\n let r = value.toString();\n if (r.length > max_precision)\n r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, // char *\n sizeInBytes, //size_t\n value, // double\n fracpart_numdigits, //int\n dec, // int *\n sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1)\n return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) { /* nan */\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (!Number.isFinite(value)) { /* infinity */\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n }\n else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split('.');\n if (intPart == \"0\")\n intPart = \"\";\n if (intPart.length > 0) { // has integer part\n decpos = intPart.length;\n digits = intPart + fracPart;\n }\n else { // only a fraction\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length)\n return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */\n }\n}\n//# sourceMappingURL=twrfloat.js.map","\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\"\r\n\r\nexport class twrFloatUtil {\r\n mod: twrWasmModuleBase;\r\n\r\n constructor(mod: twrWasmModuleBase) {\r\n this.mod=mod;\r\n }\r\n\r\n atod(strptr:number):number {\r\n const str=this.mod.getString(strptr);\r\n\r\n const upper=str.trimStart().toUpperCase();\r\n if (upper==\"INF\" || upper==\"+INF\")\r\n return Number.POSITIVE_INFINITY;\r\n else if (upper==\"-INF\")\r\n return Number.NEGATIVE_INFINITY\r\n else {\r\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\r\n const r=Number.parseFloat(str.replaceAll('D','e').replaceAll('d','e'));\r\n return r;\r\n }\r\n }\r\n\r\n dtoa(buffer:number, buffer_size:number, value:number, max_precision:number):void {\r\n if (max_precision==-1) {\r\n const r=value.toString();\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n else {\r\n let r=value.toString();\r\n if (r.length>max_precision)\r\n r=value.toPrecision(max_precision);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n }\r\n\r\n toFixed(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toFixed(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n toExponential(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toExponential(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\r\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\r\n // Negative exponents must be now smaller than 1e-99\r\n // fully-function C version also int he source, but this is the version enabled by default\r\n fcvtS(\r\n buffer:number, // char *\r\n sizeInBytes:number, //size_t\r\n value:number, // double\r\n fracpart_numdigits:number, //int\r\n dec:number, // int *\r\n sign:number // int *\r\n ):number {\r\n\r\n if (buffer==0 ||sign==0 || dec==0 || sizeInBytes<1) return 1;\r\n\r\n let digits:string;\r\n let decpos:number;\r\n let s=0; // default to positive\r\n\r\n\r\n if (Number.isNaN(value)) { /* nan */\r\n digits=\"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (!Number.isFinite(value)) { /* infinity */\r\n digits=\"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (value==0) { \r\n digits=\"000000000000000000000000000000000000\".slice(0,fracpart_numdigits);\r\n decpos=0;\r\n }\r\n \r\n else {\r\n\r\n if (value<0) {\r\n s=1; // negative\r\n value=Math.abs(value);\r\n }\r\n\r\n if (fracpart_numdigits>100 || value > 1e+21 || value < 1e-99) { \r\n this.mod.copyString(buffer, sizeInBytes, \"\");\r\n this.mod.mem32[dec]=0;\r\n return 1;\r\n }\r\n\r\n const roundValStr=value.toFixed(fracpart_numdigits);\r\n let [intPart=\"\", fracPart=\"\"] = roundValStr.split('.');\r\n if (intPart==\"0\") intPart=\"\";\r\n\r\n if (intPart.length>0) { // has integer part\r\n decpos=intPart.length;\r\n digits=intPart+fracPart;\r\n }\r\n else { // only a fraction\r\n digits=fracPart.replace(/^0+/,\"\"); // remove leading zeros\r\n decpos=digits.length-fracPart.length;\r\n }\r\n }\r\n\r\n if (sizeInBytes-1 < digits.length) return 1; \r\n this.mod.copyString(buffer, sizeInBytes, digits);\r\n this.mod.setLong(dec, decpos);\r\n this.mod.setLong(sign, s);\r\n\r\n return 0;\r\n\r\n /*\r\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\r\n\r\n let decpos=0;\r\n let digits:string;\r\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\r\n \r\n if (decpos>0) { // has integer part\r\n const intlen=Math.max(decpos, 0);\r\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\r\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\r\n }\r\n else { // only a fraction\r\n const intpart=Math.trunc(value);\r\n const fracpart=value-intpart;\r\n const prec=fracpart_numdigits- (-decpos);\r\n console.log(\"prec=\",prec);\r\n if (prec<1) {\r\n digits=\"\";\r\n }\r\n else {\r\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\");\r\n }\r\n }\r\n\r\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\r\n console.log('digits=',digits);\r\n console.log('dec=',decpos);\r\n console.log(\"sign=\",s);\r\n */\r\n\r\n\r\n }\r\n}","import { twrSignal } from \"./twrsignal.js\";\nimport { twrTimeImpl } from \"./twrdate.js\";\n// This class is used in the Main JS thread \nexport class twrWaitingCalls {\n callCompleteSignal;\n parameters;\n constructor() {\n this.callCompleteSignal = new twrSignal();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(() => {\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = twrTimeImpl();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [this.callCompleteSignal.sharedArray, this.parameters.buffer];\n }\n processMessage(msgType, data) {\n switch (msgType) {\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\n// This class is used in the worker thread \nexport class twrWaitingCallsProxy {\n callCompleteSignal;\n parameters;\n constructor(params) {\n this.callCompleteSignal = new twrSignal(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\"sleep\", [ms]]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\"time\"]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n//# sourceMappingURL=twrwaitingcalls.js.map","import { twrSignal } from \"./twrsignal.js\";\r\nimport {twrTimeImpl} from \"./twrdate.js\"\r\n\r\n// These classes are used to proxy a call across the worker thread - main thread boundary and wait for the result\r\n\r\nexport type TWaitingCallsProxyParams = [SharedArrayBuffer, SharedArrayBuffer]; // twrSignal, parameters \r\n\r\n// This class is used in the Main JS thread \r\nexport class twrWaitingCalls {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor() {\r\n\t\tthis.callCompleteSignal=new twrSignal();\r\n\t\tthis.parameters=new Uint32Array(new SharedArrayBuffer(4));\r\n\t}\r\n\r\n\tprivate startSleep(ms:number) {\r\n\r\n\t\tsetTimeout(()=>{\r\n\t\t\tthis.callCompleteSignal.signal();\r\n\t\t}, ms);\r\n\t\t\r\n\t}\r\n\r\n\tprivate time() {\r\n\t\tconst ms=twrTimeImpl();\r\n\t\tthis.parameters[0]=ms;\r\n\t\tthis.callCompleteSignal.signal();\r\n\t}\r\n\r\n\tgetProxyParams():TWaitingCallsProxyParams {\r\n\t\treturn [this.callCompleteSignal.sharedArray, this.parameters.buffer as SharedArrayBuffer];\t\r\n\t}\r\n\r\n\tprocessMessage(msgType:string, data:any[]):boolean {\r\n\t\tswitch (msgType) {\r\n\t\t\tcase \"sleep\":\r\n\t\t\t\tconst [ms] = data;\r\n\t\t\t\tthis.startSleep(ms);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"time\":\r\n\t\t\t\tthis.time();\r\n\t\t\t\tbreak;\r\n\t\t\t\r\n\t\t\tdefault:\r\n\t\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\treturn true;\r\n\t}\r\n\r\n}\r\n\r\n// This class is used in the worker thread \r\nexport class twrWaitingCallsProxy {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor(params:TWaitingCallsProxyParams) {\r\n\t\tthis.callCompleteSignal=new twrSignal(params[0]);\r\n\t\tthis.parameters=new Uint32Array(params[1]);\r\n\t}\r\n\r\n\tsleep(ms:number) {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"sleep\", [ms]]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t}\r\n\r\n\ttime() {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"time\"]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t\treturn this.parameters[0];\r\n\t}\r\n\r\n}\r\n","export function twrTimeImpl() {\n return Date.now();\n}\n//# sourceMappingURL=twrdate.js.map","\r\nexport function twrTimeImpl() {\r\n\r\n return Date.now();\r\n\r\n}"],"names":["$b93f1fdf40141def$var$twrSignalState","$c4741cac81d14197$var$D2DType","twrSignalState","D2DType","$3e39efa823870787$var$mod","$892fccfc812d5e20$export$a01cca24f011573a","sharedArray","buf","constructor","sa","window","crossOriginIsolated","location","protocol","Error","SharedArrayBuffer","Int32Array","write","n","i","Atomics","notify","read","isEmpty","readWait","rdptr","wait","$b93f1fdf40141def$export$e37a7b7b851b97f3","WAITING","signal","SIGNALED","isSignaled","reset","$c4741cac81d14197$export$c779b2cd00544976","canvasKeys","drawCompleteSignal","props","owner","params","signalBuffer","canvasKeysBuffer","charIn","inkey","getProp","pn","propName","getString","drawSeq","ds","postMessage","$8963973702ae5462$export$b377f0bbf2c7581e","divKeys","divKeysBuffer","charOut","ch","$8ac0b786da854328$export$485af4d0039b3389","$e72303a1db04bdfa$export$918ffb7e046a537b","mod","atod","strptr","str","upper","trimStart","toUpperCase","Number","POSITIVE_INFINITY","NEGATIVE_INFINITY","parseFloat","replaceAll","dtoa","buffer","buffer_size","value","max_precision","r","toString","copyString","length","toPrecision","toFixed","decdigits","toExponential","fcvtS","sizeInBytes","fracpart_numdigits","dec","sign","digits","decpos","s","isNaN","slice","isFinite","Math","abs","mem32","intPart","fracPart","roundValStr","split","replace","setLong","$ece7fa3ed770778a$export$c83a0a3bffe07399","memory","mem8","memD","exports","isWorker","isWasmModule","floatUtil","Uint8Array","Uint32Array","Float64Array","loadWasm","pathToLoad","response","fetch","err","console","log","ok","statusText","wasmBytes","arrayBuffer","allimports","modParams","imports","instance","WebAssembly","instantiate","env","ArrayBuffer","malloc","size","Promise","resolve","m","twr_malloc","init","stack","p","stdio","twrInit","twr_wasm_init","executeC","cparams","preCallC","retval","executeCImpl","postCallC","fname","f","Array","ci","putString","URL","fetchAndPutURL","putArrayBuffer","u8","j","sin","charCodeAt","strIndex","putU8","u8a","dest","ab","fnin","src","getLong","idx","idx32","floor","getDouble","idx64","setDouble","getShort","len","sout","undefined","String","fromCharCode","getU8Arr","rv","dataptr","getU32Arr","$aff9c2c494d23fe3$export$78d2a4633fe89379","callCompleteSignal","parameters","sleep","ms","time","onmessage","e","data","$3e39efa823870787$var$twrWasmModuleInWorker","modWorkerParams","urlToLoad","then","catch","ex","rc","modInWorkerParams","canvasProxy","canvasProxyParams","divProxy","divProxyParams","waitingCallsProxy","waitingCallsProxyParams","twrDebugLog","twrSleep","bind","twrTime","twrDivCharOut","twrDivCharIn","twrCanvasCharIn","twrCanvasInkey","twrCanvasGetProp","twrCanvasDrawSeq","twrSin","twrCos","cos","twrTan","tan","twrFAbs","twrACos","acos","twrASin","asin","twrATan","atan","twrExp","exp","twrFloor","twrCeil","ceil","twrFMod","x","y","twrLog","twrPow","pow","twrSqrt","sqrt","twrTrunc","trunc","twrDtoa","twrToFixed","twrToExponential","twrAtod","twrFcvtS"],"version":3,"file":"twrmodworker.2165e649.js.map"} \ No newline at end of file +{"mappings":"A,C,SQKK,EJgBA,EIhBA,EJgBA,MFZD,CISE,OAAO,EACZ,WAA8B,AAC9B,CAAA,GAAe,AAEf,aAAa,CAAqB,CAAlC,CACO,GAAI,AAAkB,aAAlB,OAAO,QACH,CAAC,qBAAuB,AAA+B,UAA7B,OAAO,QAAQ,CAAC,QAAQ,CAAe,MAAM,AAAI,MAAM,4DAA4D,oBAAoB,iCAErK,EAAI,IAAI,CAAC,WAAW,CAAC,EACpB,IAAI,CAAC,WAAW,CAAC,IAAI,kBAAkB,MAClD,IAAI,CAAC,GAAG,CAAC,IAAI,WAAW,IAAI,CAAC,WAAW,EAClC,IAAI,CAAC,GAAG,CArBJ,IAqBW,CAAC,EAChB,IAAI,CAAC,GAAG,CArBJ,IAqBW,CAAC,CACvB,CAEA,MAAM,CAAQ,CAAd,CACO,IAAI,EAAE,IAAI,CAAC,GAAG,CAzBV,IAyBiB,AACrB,CAAA,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAzBV,OA2BE,GAAQ,CAAA,EAAE,CAAA,EACd,IAAI,CAAC,GAAG,CA7BJ,IA6BW,CAAC,EAChB,QAAQ,MAAM,CAAC,IAAI,CAAC,GAAG,CA9BnB,IA+BX,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js","../../source/twr-wasm-ts/twrcanvas.ts","../../lib-js/twrcircular.js","../../source/twr-wasm-ts/twrcircular.ts","../../lib-js/twrsignal.js","../../source/twr-wasm-ts/twrsignal.ts","../../lib-js/twrdiv.js","../../source/twr-wasm-ts/twrdiv.ts","../../lib-js/twrdebug.js","../../source/twr-wasm-ts/twrdebug.ts","../../lib-js/twrmodbase.js","../../source/twr-wasm-ts/twrmodbase.ts","../../lib-js/twrfloat.js","../../source/twr-wasm-ts/twrfloat.ts","../../lib-js/twrwaitingcalls.js","../../source/twr-wasm-ts/twrwaitingcalls.ts","../../lib-js/twrdate.js","../../source/twr-wasm-ts/twrdate.ts"],"sourcesContent":["(() => {\nvar $3e39efa823870787$exports = {};\n// this script is the WebWorker thead used by class twrWasmAsyncModule\n//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst $892fccfc812d5e20$var$RDIDX = 256;\nconst $892fccfc812d5e20$var$WRIDX = 257;\nconst $892fccfc812d5e20$var$LEN = 256;\nclass $892fccfc812d5e20$export$a01cca24f011573a {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(1032);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[$892fccfc812d5e20$var$RDIDX] = 0;\n this.buf[$892fccfc812d5e20$var$WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[$892fccfc812d5e20$var$WRIDX];\n this.buf[i] = n;\n i++;\n if (i == $892fccfc812d5e20$var$LEN) i = 0;\n this.buf[$892fccfc812d5e20$var$WRIDX] = i;\n Atomics.notify(this.buf, $892fccfc812d5e20$var$WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[$892fccfc812d5e20$var$RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[$892fccfc812d5e20$var$RDIDX] = i;\n return n;\n } else return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[$892fccfc812d5e20$var$RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, $892fccfc812d5e20$var$WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[$892fccfc812d5e20$var$RDIDX] == this.buf[$892fccfc812d5e20$var$WRIDX];\n }\n}\n\n\n//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar $b93f1fdf40141def$var$twrSignalState;\n(function(twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})($b93f1fdf40141def$var$twrSignalState || ($b93f1fdf40141def$var$twrSignalState = {}));\nclass $b93f1fdf40141def$export$e37a7b7b851b97f3 {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == $b93f1fdf40141def$var$twrSignalState.WAITING) //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, $b93f1fdf40141def$var$twrSignalState.WAITING);\n }\n isSignaled() {\n return this.buf[0] == $b93f1fdf40141def$var$twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.WAITING;\n }\n}\n\n\nvar $c4741cac81d14197$var$D2DType;\n(function(D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})($c4741cac81d14197$var$D2DType || ($c4741cac81d14197$var$D2DType = {}));\nclass $c4741cac81d14197$export$2f298dd69cef3c34 {\n ctx;\n props = {\n charWidth: 0,\n charHeight: 0,\n foreColor: 0,\n backColor: 0,\n widthInChars: 0,\n heightInChars: 0,\n canvasHeight: 0,\n canvasWidth: 0\n };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase){\n const { forecolor: forecolor, backcolor: backcolor, fontsize: fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)();\n this.canvasKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.props,\n this.cmdCompleteSignal.sharedArray,\n this.canvasKeys.sharedArray\n ];\n }\n getProp(pn) {\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */ drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx) return;\n let ins = this.owner.getLong(ds); /* ds->start */ \n const lastins = this.owner.getLong(ds + 4); /* ds->last */ \n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while(true){\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */ \n switch(type){\n case $c4741cac81d14197$var$D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_BEGINPATH:\n this.ctx.beginPath();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILL:\n this.ctx.fill();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SAVE:\n this.ctx.save();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_RESTORE:\n this.ctx.restore();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_STROKE:\n this.ctx.stroke();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = this.owner.getLong(ins + 48) != 0;\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n } else this.precomputedObjects[id] = {\n mem8: new Uint8Array(this.owner.memory.buffer, start, length),\n width: width,\n height: height\n };\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id]) delete this.precomputedObjects[id];\n else console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n else {\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) this.ctx.putImageData(imgData, dx, dy);\n else this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */ \n if (next == 0) {\n if (ins != lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nclass $c4741cac81d14197$export$c779b2cd00544976 {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner){\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)(signalBuffer);\n this.canvasKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\n \"drawseq\",\n [\n ds\n ]\n ]);\n this.drawCompleteSignal.wait();\n }\n}\n\n\n\nclass $8963973702ae5462$export$dd376bb3f10f6896 {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611);\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase){\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) this.divKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(); // tsconfig, lib must be set to 2017 or higher\n if (this.div && !modParams.styleIsDefault) {\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.divKeys.sharedArray\n ];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */ charOut(ch) {\n if (!this.div) return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n }\n switch(ch){\n case 10:\n case 13:\n if (ch == 10 && this.lastChar == 13) break; // detect CR LF and treat as single new line\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n case 0xE:\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF:\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for(let i = 0; i < str.length; i++)this.charOut(str.charCodeAt(i));\n }\n}\nclass $8963973702ae5462$export$b377f0bbf2c7581e {\n divKeys;\n constructor(params){\n const [divKeysBuffer] = params;\n this.divKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n charOut(ch) {\n postMessage([\n \"divout\",\n ch\n ]);\n }\n}\n\n\nlet $8ac0b786da854328$var$logline = \"\";\nfunction $8ac0b786da854328$export$16b4216ec014493d(char) {\n if (char == 10 || char == 3) {\n console.log($8ac0b786da854328$var$logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n $8ac0b786da854328$var$logline = \"\";\n } else {\n $8ac0b786da854328$var$logline = $8ac0b786da854328$var$logline + String.fromCharCode(char);\n if ($8ac0b786da854328$var$logline.length >= 200) {\n console.log($8ac0b786da854328$var$logline);\n $8ac0b786da854328$var$logline = \"\";\n }\n }\n}\nfunction $8ac0b786da854328$export$485af4d0039b3389(ch) {\n postMessage([\n \"debug\",\n ch\n ]);\n}\n\n\nclass $e72303a1db04bdfa$export$918ffb7e046a537b {\n mod;\n constructor(mod){\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\") return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\") return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll(\"D\", \"e\").replaceAll(\"d\", \"e\"));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n } else {\n let r = value.toString();\n if (r.length > max_precision) r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, sizeInBytes, value, fracpart_numdigits, dec, sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1) return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) {\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (!Number.isFinite(value)) {\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n } else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split(\".\");\n if (intPart == \"0\") intPart = \"\";\n if (intPart.length > 0) {\n decpos = intPart.length;\n digits = intPart + fracPart;\n } else {\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length) return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */ }\n}\n\n\nclass $ece7fa3ed770778a$export$c83a0a3bffe07399 {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule;\n floatUtil;\n constructor(isWasmModule = false){\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new (0, $e72303a1db04bdfa$export$918ffb7e046a537b)(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/ /*********************************************************************/ async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n } catch (err) {\n console.log(\"loadWasm() failed to fetch: \" + pathToLoad);\n throw err;\n }\n if (!response.ok) throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, {\n env: allimports\n });\n this.exports = instance.instance.exports;\n if (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory) throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer) console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\n \"setmemory\",\n this.memory\n ]);\n }\n if (this.isWasmModule) // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n {\n if (!(this.memory.buffer instanceof ArrayBuffer)) console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size)=>{\n return new Promise((resolve)=>{\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n } catch (err) {\n console.log(\"WASM instantiate error: \" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch(this.modParams.stdio){\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* callC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */ async callC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.callCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async callCImpl(fname, cparams = []) {\n if (!this.exports) throw new Error(\"this.exports undefined\");\n if (!this.exports[fname]) throw new Error(\"callC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array)) throw new Error(\"callC: params must be array, first arg is function name\");\n if (params.length == 0) throw new Error(\"callC: missing function name\");\n let cparams = [];\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n cparams[ci++] = p;\n break;\n case \"string\":\n cparams[ci++] = await this.putString(p);\n break;\n case \"object\":\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n } else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"callC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n ci++;\n break;\n case \"string\":\n this.callCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n case \"object\":\n if (p instanceof URL) {\n this.callCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci = ci + 2;\n break;\n } else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for(let j = 0; j < u8.length; j++)u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.callCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n } else throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/ /*********************************************************************/ // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for(i = 0; i < sin.length && i < buffer_size - 1; i++)this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for(let i = 0; i < u8a.length; i++)this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === \"object\" && fnin instanceof URL)) throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [\n dest,\n src.length\n ];\n } catch (err) {\n console.log(\"fetchAndPutURL Error. URL: \" + fnin + \"\\n\" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while(this.mem8[strIndex + i] && (len === undefined ? true : i < len) && strIndex + i < this.mem8.length){\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array(this.mem8.slice(dataptr, dataptr + size).buffer);\n return u32;\n }\n}\n\n\n\nfunction $4af5689abbc8d01b$export$78724cdcf7ebea1d() {\n return Date.now();\n}\n\n\nclass $aff9c2c494d23fe3$export$9e37856d1928d388 {\n callCompleteSignal;\n parameters;\n constructor(){\n this.callCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(()=>{\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = (0, $4af5689abbc8d01b$export$78724cdcf7ebea1d)();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [\n this.callCompleteSignal.sharedArray,\n this.parameters.buffer\n ];\n }\n processMessage(msgType, data) {\n switch(msgType){\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\nclass $aff9c2c494d23fe3$export$78d2a4633fe89379 {\n callCompleteSignal;\n parameters;\n constructor(params){\n this.callCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\n \"sleep\",\n [\n ms\n ]\n ]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\n \"time\"\n ]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n\n\nlet $3e39efa823870787$var$mod;\nonmessage = function(e) {\n //console.log('twrworker.js: message received from main script: '+e.data);\n if (e.data[0] == \"startup\") {\n const params = e.data[1];\n //console.log(\"Worker startup params:\",params);\n $3e39efa823870787$var$mod = new $3e39efa823870787$var$twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\n $3e39efa823870787$var$mod.loadWasm(params.urlToLoad).then(()=>{\n postMessage([\n \"startupOkay\"\n ]);\n }).catch((ex)=>{\n console.log(\".catch: \", ex);\n postMessage([\n \"startupFail\",\n ex\n ]);\n });\n } else if (e.data[0] == \"callC\") $3e39efa823870787$var$mod.callCImpl(e.data[1], e.data[2]).then((rc)=>{\n postMessage([\n \"callCOkay\",\n rc\n ]);\n }).catch((e)=>{\n console.log(\"exception in callC twrworker.js\\n\");\n console.log(e);\n postMessage([\n \"callCFail\",\n e\n ]);\n });\n else console.log(\"twrworker.js: unknown message: \" + e);\n};\n// ************************************************************************\nclass $3e39efa823870787$var$twrWasmModuleInWorker extends (0, $ece7fa3ed770778a$export$c83a0a3bffe07399) {\n malloc;\n modParams;\n constructor(modParams, modInWorkerParams){\n super();\n this.isWorker = true;\n this.malloc = (size)=>{\n throw new Error(\"error - un-init malloc called\");\n };\n this.modParams = modParams;\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\n const canvasProxy = new (0, $c4741cac81d14197$export$c779b2cd00544976)(modInWorkerParams.canvasProxyParams, this);\n const divProxy = new (0, $8963973702ae5462$export$b377f0bbf2c7581e)(modInWorkerParams.divProxyParams);\n const waitingCallsProxy = new (0, $aff9c2c494d23fe3$export$78d2a4633fe89379)(modInWorkerParams.waitingCallsProxyParams);\n this.modParams.imports = {\n twrDebugLog: (0, $8ac0b786da854328$export$485af4d0039b3389),\n twrSleep: waitingCallsProxy.sleep.bind(waitingCallsProxy),\n twrTime: waitingCallsProxy.time.bind(waitingCallsProxy),\n twrDivCharOut: divProxy.charOut.bind(divProxy),\n twrDivCharIn: divProxy.charIn.bind(divProxy),\n twrCanvasCharIn: canvasProxy.charIn.bind(canvasProxy),\n twrCanvasInkey: canvasProxy.inkey.bind(canvasProxy),\n twrCanvasGetProp: canvasProxy.getProp.bind(canvasProxy),\n twrCanvasDrawSeq: canvasProxy.drawSeq.bind(canvasProxy),\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function(x, y) {\n return x % y;\n },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n}\n\n})();\n//# sourceMappingURL=twrmodworker.2165e649.js.map\n","// this script is the WebWorker thead used by class twrWasmAsyncModule\nimport { twrCanvasProxy } from \"./twrcanvas.js\";\nimport { twrDivProxy } from \"./twrdiv.js\";\nimport { twrDebugLogProxy } from \"./twrdebug.js\";\nimport { twrWasmModuleBase } from \"./twrmodbase.js\";\nimport { twrWaitingCallsProxy } from \"./twrwaitingcalls.js\";\nlet mod;\nonmessage = function (e) {\n //console.log('twrworker.js: message received from main script: '+e.data);\n if (e.data[0] == 'startup') {\n const params = e.data[1];\n //console.log(\"Worker startup params:\",params);\n mod = new twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\n mod.loadWasm(params.urlToLoad).then(() => {\n postMessage([\"startupOkay\"]);\n }).catch((ex) => {\n console.log(\".catch: \", ex);\n postMessage([\"startupFail\", ex]);\n });\n }\n else if (e.data[0] == 'callC') {\n mod.callCImpl(e.data[1], e.data[2]).then((rc) => {\n postMessage([\"callCOkay\", rc]);\n }).catch(e => {\n console.log(\"exception in callC twrworker.js\\n\");\n console.log(e);\n postMessage([\"callCFail\", e]);\n });\n }\n else {\n console.log(\"twrworker.js: unknown message: \" + e);\n }\n};\n// ************************************************************************\nclass twrWasmModuleInWorker extends twrWasmModuleBase {\n malloc;\n modParams;\n constructor(modParams, modInWorkerParams) {\n super();\n this.isWorker = true;\n this.malloc = (size) => { throw new Error(\"error - un-init malloc called\"); };\n this.modParams = modParams;\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\n const canvasProxy = new twrCanvasProxy(modInWorkerParams.canvasProxyParams, this);\n const divProxy = new twrDivProxy(modInWorkerParams.divProxyParams);\n const waitingCallsProxy = new twrWaitingCallsProxy(modInWorkerParams.waitingCallsProxyParams);\n this.modParams.imports = {\n twrDebugLog: twrDebugLogProxy,\n twrSleep: waitingCallsProxy.sleep.bind(waitingCallsProxy),\n twrTime: waitingCallsProxy.time.bind(waitingCallsProxy),\n twrDivCharOut: divProxy.charOut.bind(divProxy),\n twrDivCharIn: divProxy.charIn.bind(divProxy),\n twrCanvasCharIn: canvasProxy.charIn.bind(canvasProxy),\n twrCanvasInkey: canvasProxy.inkey.bind(canvasProxy),\n twrCanvasGetProp: canvasProxy.getProp.bind(canvasProxy),\n twrCanvasDrawSeq: canvasProxy.drawSeq.bind(canvasProxy),\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function (x, y) { return x % y; },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n}\n//# sourceMappingURL=twrmodworker.js.map","// this script is the WebWorker thead used by class twrWasmAsyncModule\r\n\r\nimport {twrCanvasProxy} from \"./twrcanvas.js\";\r\nimport {twrDivProxy} from \"./twrdiv.js\";\r\nimport {twrDebugLogProxy} from \"./twrdebug.js\";\r\nimport {TAsyncModStartupMsg} from \"./twrmodasync.js\"\r\nimport {twrWasmModuleBase, IModInWorkerParams, IModParams} from \"./twrmodbase.js\"\r\nimport {twrWaitingCallsProxy} from \"./twrwaitingcalls.js\";\r\n\r\nlet mod:twrWasmModuleInWorker;\r\n\r\nonmessage = function(e) {\r\n //console.log('twrworker.js: message received from main script: '+e.data);\r\n\r\n if (e.data[0]=='startup') {\r\n const params:TAsyncModStartupMsg=e.data[1];\r\n //console.log(\"Worker startup params:\",params);\r\n mod=new twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\r\n\r\n mod.loadWasm(params.urlToLoad).then( ()=> {\r\n postMessage([\"startupOkay\"]);\r\n }).catch( (ex)=> {\r\n console.log(\".catch: \", ex);\r\n postMessage([\"startupFail\", ex]);\r\n });\r\n }\r\n else if (e.data[0]=='callC') {\r\n mod.callCImpl(e.data[1], e.data[2]).then( (rc)=> {\r\n postMessage([\"callCOkay\", rc]);\r\n }).catch(e => {\r\n console.log(\"exception in callC twrworker.js\\n\");\r\n console.log(e);\r\n postMessage([\"callCFail\", e]);\r\n });\r\n }\r\n else {\r\n console.log(\"twrworker.js: unknown message: \"+e);\r\n }\r\n}\r\n\r\n\r\n// ************************************************************************\r\n\r\nclass twrWasmModuleInWorker extends twrWasmModuleBase {\r\n\tmalloc:(size:number)=>Promise;\r\n modParams: IModParams;\r\n\r\n\r\n constructor(modParams:IModParams, modInWorkerParams:IModInWorkerParams) {\r\n super();\r\n this.isWorker=true;\r\n this.malloc=(size:number)=>{throw new Error(\"error - un-init malloc called\")};\r\n this.modParams=modParams;\r\n\r\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\r\n const canvasProxy = new twrCanvasProxy(modInWorkerParams.canvasProxyParams, this);\r\n const divProxy = new twrDivProxy(modInWorkerParams.divProxyParams);\r\n const waitingCallsProxy = new twrWaitingCallsProxy(modInWorkerParams.waitingCallsProxyParams);\r\n\r\n this.modParams.imports={\r\n twrDebugLog:twrDebugLogProxy,\r\n twrSleep:waitingCallsProxy.sleep.bind(waitingCallsProxy),\r\n twrTime:waitingCallsProxy.time.bind(waitingCallsProxy),\r\n\r\n twrDivCharOut:divProxy.charOut.bind(divProxy), \r\n twrDivCharIn:divProxy.charIn.bind(divProxy), \r\n\r\n twrCanvasCharIn:canvasProxy.charIn.bind(canvasProxy),\r\n twrCanvasInkey:canvasProxy.inkey.bind(canvasProxy),\r\n twrCanvasGetProp:canvasProxy.getProp.bind(canvasProxy),\r\n twrCanvasDrawSeq:canvasProxy.drawSeq.bind(canvasProxy),\r\n\r\n\t\t\ttwrSin:Math.sin,\r\n\t\t\ttwrCos:Math.cos,\r\n\t\t\ttwrTan: Math.tan,\r\n\t\t\ttwrFAbs: Math.abs,\r\n\t\t\ttwrACos: Math.acos,\r\n\t\t\ttwrASin: Math.asin,\r\n\t\t\ttwrATan: Math.atan,\r\n\t\t\ttwrExp: Math.exp,\r\n\t\t\ttwrFloor: Math.floor,\r\n\t\t\ttwrCeil: Math.ceil,\r\n\t\t\ttwrFMod: function(x:number, y:number) {return x%y},\r\n\t\t\ttwrLog: Math.log,\r\n\t\t\ttwrPow: Math.pow,\r\n\t\t\ttwrSqrt: Math.sqrt,\r\n\t\t\ttwrTrunc: Math.trunc,\r\n\r\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\r\n\t\t\ttwrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\r\n\t\t\ttwrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\r\n\t\t\ttwrAtod: this.floatUtil.atod.bind(this.floatUtil),\r\n\t\t\ttwrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\r\n \r\n }\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nimport { twrSignal } from \"./twrsignal.js\";\nvar D2DType;\n(function (D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})(D2DType || (D2DType = {}));\nexport class twrCanvas {\n ctx;\n props = { charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight: 0, canvasWidth: 0 };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase) {\n const { forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new twrSignal();\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext)\n throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c)\n throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2)\n throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\n }\n getProp(pn) {\n if (!this.isValid())\n console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */\n drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid())\n console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx)\n return;\n let ins = this.owner.getLong(ds); /* ds->start */\n const lastins = this.owner.getLong(ds + 4); /* ds->last */\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while (1) {\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */\n if (0 /*type!=D2DType.D2D_FILLRECT*/) {\n console.log(\"ins\", ins);\n console.log(\"hdr.next\", this.owner.mem8[ins], this.owner.mem8[ins + 1], this.owner.mem8[ins + 2], this.owner.mem8[ins + 3]);\n console.log(\"hdr.type\", this.owner.mem8[ins + 4], this.owner.mem8[ins + 5]);\n console.log(\"next 4 bytes\", this.owner.mem8[ins + 6], this.owner.mem8[ins + 7], this.owner.mem8[ins + 8], this.owner.mem8[ins + 9]);\n console.log(\"and 4 more \", this.owner.mem8[ins + 10], this.owner.mem8[ins + 11], this.owner.mem8[ins + 12], this.owner.mem8[ins + 13]);\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\n }\n switch (type) {\n case D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case D2DType.D2D_BEGINPATH:\n {\n this.ctx.beginPath();\n }\n break;\n case D2DType.D2D_FILL:\n {\n this.ctx.fill();\n }\n break;\n case D2DType.D2D_SAVE:\n {\n this.ctx.save();\n }\n break;\n case D2DType.D2D_RESTORE:\n {\n this.ctx.restore();\n }\n break;\n case D2DType.D2D_STROKE:\n {\n this.ctx.stroke();\n }\n break;\n case D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = (this.owner.getLong(ins + 48) != 0);\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n }\n else { // Uint8ClampedArray doesn't support shared memory\n this.precomputedObjects[id] = { mem8: new Uint8Array(this.owner.memory.buffer, start, length), width: width, height: height };\n }\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id])\n delete this.precomputedObjects[id];\n else\n console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) {\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n }\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) {\n this.ctx.putImageData(imgData, dx, dy);\n }\n else {\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */\n if (next == 0) {\n if (ins != lastins)\n throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal)\n this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nexport class twrCanvasProxy {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner) {\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new twrSignal(signalBuffer);\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\"drawseq\", [ds]]);\n this.drawCompleteSignal.wait();\n }\n}\n//# sourceMappingURL=twrcanvas.js.map","import {twrWasmModuleBase, IModParams} from \"./twrmodbase.js\"\r\nimport {twrSharedCircularBuffer} from \"./twrcircular.js\";\r\nimport {twrSignal} from \"./twrsignal.js\";\r\n\r\n\r\n// Canvas have a size that will be set based on the character width x height\r\n// The display size for a canvas will default to this size, but can be changed in the HTML/JS via\r\n// canvas.style.width = \"700px\";\r\n// canvas.style.height = \"500px\";\r\n\r\nexport interface ICanvasProps {\r\n\tcharWidth: number,\r\n\tcharHeight: number,\r\n\tforeColor: number,\r\n\tbackColor: number,\r\n widthInChars: number,\r\n heightInChars: number,\r\n canvasWidth:number,\r\n canvasHeight:number\r\n}\r\n\r\nenum D2DType {\r\n D2D_FILLRECT=1,\r\n D2D_FILLCHAR=5,\r\n D2D_SETLINEWIDTH=10,\r\n D2D_SETFILLSTYLERGBA=11,\r\n D2D_SETFONT=12,\r\n D2D_BEGINPATH=13,\r\n D2D_MOVETO=14,\r\n D2D_LINETO=15,\r\n D2D_FILL=16,\r\n D2D_STROKE=17,\r\n D2D_SETSTROKESTYLERGBA=18,\r\n D2D_ARC=19,\r\n D2D_STROKERECT=20,\r\n D2D_FILLTEXT=21,\r\n D2D_IMAGEDATA=22,\r\n D2D_PUTIMAGEDATA=23,\r\n D2D_BEZIERTO=24,\r\n D2D_MEASURETEXT=25,\r\n D2D_SAVE=26,\r\n D2D_RESTORE=27,\r\n D2D_CREATERADIALGRADIENT=28,\r\n D2D_SETCOLORSTOP=29,\r\n D2D_SETFILLSTYLEGRADIENT=30,\r\n D2D_RELEASEID=31,\r\n D2D_CREATELINEARGRADIENT=32,\r\n D2D_SETFILLSTYLE=33,\r\n D2D_SETSTROKESTYLE=34\r\n\r\n}\r\n\r\nexport type TCanvasProxyParams = [ICanvasProps, SharedArrayBuffer, SharedArrayBuffer];\r\n\r\nexport interface ICanvas {\r\n props: ICanvasProps,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TCanvasProxyParams,\r\n drawSeq: (ds:number)=>void,\r\n }\r\n \r\nexport class twrCanvas implements ICanvas {\r\n ctx:CanvasRenderingContext2D|undefined;\r\n props:ICanvasProps={charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight:0, canvasWidth:0};\r\n owner: twrWasmModuleBase;\r\n cmdCompleteSignal?:twrSignal;\r\n canvasKeys?: twrSharedCircularBuffer;\r\n precomputedObjects: { [index: number]: \r\n (ImageData | {mem8:Uint8Array, width:number, height:number}) |\r\n CanvasGradient\r\n };\r\n\r\n constructor(element:HTMLCanvasElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n const {forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas} = modParams; \r\n this.owner=modbase;\r\n this.props.widthInChars=modParams.windim[0];\r\n this.props.heightInChars=modParams.windim[1];\r\n\r\n if (!this.owner.isWasmModule) {\r\n this.cmdCompleteSignal=new twrSignal();\r\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n }\r\n\r\n this.precomputedObjects={};\r\n \r\n if (element) {\r\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\r\n let c=element.getContext(\"2d\");\r\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\r\n\r\n c.font = fontsize.toString()+\"px Courier New\";\r\n c.textBaseline=\"top\";\r\n const sampleText=\" \";\r\n const tm=c.measureText(sampleText);\r\n this.props.charWidth=Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\r\n let fM = c.measureText(\"X\"); \r\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\r\n\r\n if (!isd2dcanvas) {\r\n element.width=this.props.charWidth*this.props.widthInChars;\r\n element.height=this.props.charHeight*this.props.heightInChars;\r\n }\r\n\r\n this.props.canvasHeight=element.height;\r\n this.props.canvasWidth=element.width;\r\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\r\n\r\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\r\n let c2=element.getContext(\"2d\");\r\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\r\n this.ctx=c2;\r\n this.ctx.font = fontsize.toString()+\"px Courier New\";\r\n this.ctx.textBaseline=\"top\";\r\n\r\n c2.fillStyle=backcolor;\r\n this.props.backColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n c2.fillStyle=forecolor;\r\n this.props.foreColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n }\r\n\r\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\r\n\r\n //console.log(\"twrCanvas.constructor props: \", this.props);\r\n }\r\n\r\n isValid() {\r\n return !!this.ctx;\r\n }\r\n\r\n getProxyParams() : TCanvasProxyParams {\r\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\r\n }\r\n\r\n getProp(pn:number): number {\r\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n\r\n/* see draw2d.h for structs that match */\r\n\r\n drawSeq(ds:number) {\r\n //console.log(\"twr::Canvas enter drawSeq\");\r\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\r\n if (!this.ctx) return;\r\n\r\n let ins=this.owner.getLong(ds); /* ds->start */\r\n const lastins=this.owner.getLong(ds+4); /* ds->last */\r\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\r\n\r\n let next:number;\r\n //let insCount=0;\r\n\r\n while (1) {\r\n\r\n //insCount++;\r\n\r\n const type:D2DType=this.owner.getLong(ins+4); /* hdr->type */\r\n if (0/*type!=D2DType.D2D_FILLRECT*/) {\r\n console.log(\"ins\",ins)\r\n console.log(\"hdr.next\",this.owner.mem8[ins],this.owner.mem8[ins+1],this.owner.mem8[ins+2],this.owner.mem8[ins+3]);\r\n console.log(\"hdr.type\",this.owner.mem8[ins+4],this.owner.mem8[ins+5]);\r\n console.log(\"next 4 bytes\", this.owner.mem8[ins+6],this.owner.mem8[ins+7],this.owner.mem8[ins+8],this.owner.mem8[ins+9]);\r\n console.log(\"and 4 more \", this.owner.mem8[ins+10],this.owner.mem8[ins+11],this.owner.mem8[ins+12],this.owner.mem8[ins+13]);\r\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\r\n }\r\n switch (type) {\r\n case D2DType.D2D_FILLRECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.fillRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKERECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.strokeRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILLCHAR:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const c=this.owner.getShort(ins+24);\r\n let txt=String.fromCharCode(c);\r\n this.ctx.fillText(txt, x, y);\r\n }\r\n break;\r\n\r\n \r\n case D2DType.D2D_FILLTEXT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const str=this.owner.getString(this.owner.getLong(ins+24));\r\n\r\n //console.log(\"filltext \",x,y,str)\r\n \r\n this.ctx.fillText(str, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MEASURETEXT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n const tmidx=this.owner.getLong(ins+12);\r\n \r\n const tm=this.ctx.measureText(str);\r\n this.owner.setDouble(tmidx+0, tm.actualBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+8, tm.actualBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+16, tm.actualBoundingBoxLeft);\r\n this.owner.setDouble(tmidx+24, tm.actualBoundingBoxRight);\r\n this.owner.setDouble(tmidx+32, tm.fontBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+40, tm.fontBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+48, tm.width);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFONT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.font=str;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.fillStyle = cssColor;\r\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETSTROKESTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.fillStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETSTROKESTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETLINEWIDTH:\r\n {\r\n const width=this.owner.getShort(ins+8); \r\n this.ctx.lineWidth=width;\r\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MOVETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.moveTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_LINETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.lineTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEZIERTO:\r\n {\r\n const cp1x=this.owner.getDouble(ins+8);\r\n const cp1y=this.owner.getDouble(ins+16);\r\n const cp2x=this.owner.getDouble(ins+24);\r\n const cp2y=this.owner.getDouble(ins+32);\r\n const x=this.owner.getDouble(ins+40);\r\n const y=this.owner.getDouble(ins+48);\r\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEGINPATH:\r\n {\r\n this.ctx.beginPath();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILL:\r\n {\r\n this.ctx.fill();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SAVE:\r\n {\r\n this.ctx.save();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_RESTORE:\r\n {\r\n this.ctx.restore();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKE:\r\n {\r\n this.ctx.stroke();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_ARC:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const radius=this.owner.getDouble(ins+24);\r\n const startAngle=this.owner.getDouble(ins+32);\r\n const endAngle=this.owner.getDouble(ins+40);\r\n const counterClockwise= (this.owner.getLong(ins+48)!=0);\r\n\r\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_IMAGEDATA:\r\n {\r\n const start=this.owner.getLong(ins+8);\r\n const length=this.owner.getLong(ins+12);\r\n const width=this.owner.getLong(ins+16);\r\n const height=this.owner.getLong(ins+20);\r\n const id=this.owner.getLong(ins+24);\r\n\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\r\n\r\n if (this.owner.isWasmModule) {\r\n const z = new Uint8ClampedArray(this.owner.memory!.buffer, start, length);\r\n this.precomputedObjects[id]=new ImageData(z, width, height);\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory\r\n this.precomputedObjects[id]={mem8: new Uint8Array(this.owner.memory!.buffer, start, length), width:width, height:height};\r\n }\r\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_CREATERADIALGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const radius0=this.owner.getDouble(ins+24);\r\n const x1=this.owner.getDouble(ins+32);\r\n const y1=this.owner.getDouble(ins+40);\r\n const radius1=this.owner.getDouble(ins+48);\r\n const id= this.owner.getLong(ins+56);\r\n\r\n let gradient=this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_CREATELINEARGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const x1=this.owner.getDouble(ins+24);\r\n const y1=this.owner.getDouble(ins+32);\r\n const id= this.owner.getLong(ins+40);\r\n \r\n let gradient=this.ctx.createLinearGradient(x0, y0, x1, y1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETCOLORSTOP:\r\n {\r\n const id = this.owner.getLong(ins+8);\r\n const pos=this.owner.getLong(ins+12);\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+16));\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n gradient.addColorStop(pos, cssColor);\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n this.ctx.fillStyle=gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_RELEASEID:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (this.precomputedObjects[id])\r\n delete this.precomputedObjects[id];\r\n else\r\n console.log(\"warning: D2D_RELEASEID with undefined ID \",id);\r\n }\r\n break\r\n\r\n \r\n\r\n case D2DType.D2D_PUTIMAGEDATA:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n const dx=this.owner.getLong(ins+12);\r\n const dy=this.owner.getLong(ins+16);\r\n const dirtyX=this.owner.getLong(ins+20);\r\n const dirtyY=this.owner.getLong(ins+24);\r\n const dirtyWidth=this.owner.getLong(ins+28);\r\n const dirtyHeight=this.owner.getLong(ins+32);\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \"+id);\r\n\r\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\r\n\r\n let imgData:ImageData;\r\n if (this.owner.isWasmModule) {\r\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\r\n imgData=this.precomputedObjects[id] as ImageData;\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\r\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\r\n const z = this.precomputedObjects[id] as {mem8:Uint8Array, width:number, height:number}; // Uint8Array\r\n const ca=Uint8ClampedArray.from(z.mem8); // shallow copy\r\n imgData=new ImageData(ca, z.width, z.height);\r\n }\r\n \r\n if (dirtyWidth==0 && dirtyHeight==0) {\r\n this.ctx.putImageData(imgData, dx, dy);\r\n }\r\n else {\r\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\r\n }\r\n }\r\n break;\r\n\r\n default:\r\n throw new Error (\"unimplemented or unknown Sequence Type in drawSeq: \"+type);\r\n }\r\n next=this.owner.getLong(ins); /* hdr->next */\r\n if (next==0) {\r\n if (ins!=lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\r\n break;\r\n }\r\n ins=next;\r\n }\r\n\r\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\r\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\r\n }\r\n}\r\n\r\nexport class twrCanvasProxy implements ICanvas {\r\n canvasKeys: twrSharedCircularBuffer;\r\n drawCompleteSignal:twrSignal;\r\n props: ICanvasProps;\r\n owner: twrWasmModuleBase;\r\n\r\n constructor(params:TCanvasProxyParams, owner:twrWasmModuleBase) {\r\n const [props, signalBuffer, canvasKeysBuffer] = params;\r\n this.drawCompleteSignal = new twrSignal(signalBuffer);\r\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\r\n this.props=props;\r\n this.owner=owner;\r\n\r\n //console.log(\"Create New twrCanvasProxy: \",this.props)\r\n\r\n }\r\n\r\n charIn() { \r\n //ctx.commit(); not avail in chrome\r\n \r\n //postMessage([\"debug\", 'x']);\r\n \r\n return this.canvasKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.canvasKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n getProp(pn:number): number {\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n \r\n drawSeq(ds:number) {\r\n this.drawCompleteSignal.reset();\r\n postMessage([\"drawseq\", [ds]]);\r\n this.drawCompleteSignal.wait();\r\n }\r\n}\r\n","//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst RDIDX = 256;\nconst WRIDX = 257;\nconst LEN = 256;\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\n// the first 256 array entries are the circular buffer\n// the next two are used for the read and write index\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\nexport class twrSharedCircularBuffer {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(258 * 4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[RDIDX] = 0;\n this.buf[WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[WRIDX];\n this.buf[i] = n;\n i++;\n if (i == LEN)\n i = 0;\n this.buf[WRIDX] = i;\n Atomics.notify(this.buf, WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[RDIDX] = i;\n return n;\n }\n else\n return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[RDIDX] == this.buf[WRIDX];\n }\n}\n//# sourceMappingURL=twrcircular.js.map","//\r\n// This class implements a circular buffer that the main javascript thread can write to, \r\n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\r\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \r\n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\r\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\r\n//\r\n\r\nconst RDIDX=256;\r\nconst WRIDX=257;\r\nconst LEN=256;\r\n\r\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\r\n// the first 256 array entries are the circular buffer\r\n// the next two are used for the read and write index\r\n\r\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\r\n\r\nexport class twrSharedCircularBuffer {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n \r\n\tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(258*4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[RDIDX]=0;\r\n this.buf[WRIDX]=0;\r\n\t}\r\n\r\n\twrite(n:number) {\r\n let i=this.buf[WRIDX];\r\n this.buf[i]=n;\r\n i++;\r\n if (i==LEN) i=0;\r\n this.buf[WRIDX]=i; \r\n Atomics.notify(this.buf, WRIDX); \r\n\t}\r\n\r\n\tread():number {\r\n if (!this.isEmpty()) {\r\n let i=this.buf[RDIDX];\r\n let n=this.buf[i];\r\n i++;\r\n this.buf[RDIDX]=i;\r\n return n;\r\n }\r\n\t\telse\r\n return -1;\r\n\t}\r\n\r\n readWait():number {\r\n if (this.isEmpty()) {\r\n const rdptr=this.buf[RDIDX];\r\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\r\n Atomics.wait(this.buf, WRIDX, rdptr);\r\n }\r\n return this.read();\r\n\t}\r\n\r\n isEmpty():boolean {\r\n return this.buf[RDIDX]==this.buf[WRIDX];\r\n }\r\n}\r\n","//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar twrSignalState;\n(function (twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})(twrSignalState || (twrSignalState = {}));\n;\nexport class twrSignal {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window valid\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == twrSignalState.WAITING) {\n //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\n //console.log(\"released...\");\n }\n }\n isSignaled() {\n return this.buf[0] == twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = twrSignalState.WAITING;\n }\n}\n//# sourceMappingURL=twrsignal.js.map","//\r\n// This class implements a simple signal/wait mechanism\r\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\r\n//\r\n\r\nenum twrSignalState {\r\n WAITING=0,\r\n SIGNALED=1\r\n};\r\n\r\nexport class twrSignal {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n\r\n \tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window valid\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) \r\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[0]=twrSignalState.WAITING;\r\n\t}\r\n\r\n\tsignal() {\r\n this.buf[0]=twrSignalState.SIGNALED; \r\n //console.log(\"about to signal\");\r\n Atomics.notify(this.buf, 0); \r\n\t}\r\n\r\n wait() {\r\n if (this.buf[0]==twrSignalState.WAITING) {\r\n //console.log(\"waiting...\");\r\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\r\n //console.log(\"released...\");\r\n\r\n }\r\n\t}\r\n isSignaled():boolean {\r\n return this.buf[0]==twrSignalState.SIGNALED;\r\n }\r\n\r\n reset() {\r\n this.buf[0]=twrSignalState.WAITING;\r\n }\r\n}\r\n","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nexport class twrDiv {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase) {\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\n this.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n if (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.divKeys.sharedArray];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */\n charOut(ch) {\n if (!this.div)\n return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n }\n switch (ch) {\n case 10: // newline\n case 13: // return\n if (ch == 10 && this.lastChar == 13)\n break; // detect CR LF and treat as single new line\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8: // backspace\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n case 0xE: // cursor on\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF: // cursor off\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for (let i = 0; i < str.length; i++)\n this.charOut(str.charCodeAt(i));\n }\n}\nexport class twrDivProxy {\n divKeys;\n constructor(params) {\n const [divKeysBuffer] = params;\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n charOut(ch) {\n postMessage([\"divout\", ch]);\n }\n}\n//# sourceMappingURL=twrdiv.js.map","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\r\nimport { IModParams } from \"./twrmodbase.js\";\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\";\r\n\r\nexport type TDivProxyParams = [SharedArrayBuffer];\r\n\r\nexport interface IDiv {\r\n charOut: (ds:number)=>void,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TDivProxyParams,\r\n }\r\n\r\n\r\nexport class twrDiv implements IDiv {\r\n\tdiv:HTMLDivElement|null|undefined;\r\n\tdivKeys?:twrSharedCircularBuffer;\r\n\tCURSOR=String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\r\n\tcursorOn:boolean=false;\r\n\tlastChar:number=0;\r\n\textraBR:boolean=false;\r\n\towner:twrWasmModuleBase;\r\n\r\n constructor(element:HTMLDivElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n\t\tthis.div=element;\r\n\t\tthis.owner=modbase;\r\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\r\n\t\t\tthis.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n\t\t}\r\n\r\n\t\tif (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\r\n\t\t\tthis.div.style.backgroundColor = modParams.backcolor;\r\n\t\t\tthis.div.style.color = modParams.forecolor;\r\n\t\t\tthis.div.style.font=modParams.fontsize.toString()+\"px arial\"\r\n\t\t}\r\n }\r\n\r\n\tisValid() {\r\n\t\treturn !!this.div;\r\n\t}\r\n\r\n getProxyParams() : TDivProxyParams {\r\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [ this.divKeys.sharedArray];\r\n }\r\n\r\n\r\n/* \r\n * add character to div. Supports the following control codes:\r\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\r\n * 0xE cursor on \r\n * 0x8 backspace\r\n * 0xF cursor off \r\n*/\r\n\tcharOut(ch:number) {\r\n\r\n\t\tif (!this.div) return;\r\n\r\n\t\t//console.log(\"div::charout: \", ch);\r\n\r\n\t\tif (this.extraBR) {\r\n\t\t\tthis.extraBR=false;\r\n\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -4);\r\n\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t}\r\n\r\n\t\tswitch (ch) {\r\n\t\t\tcase 10: // newline\r\n\t\t\tcase 13: // return\r\n\t\t\t\tif (ch==10 && this.lastChar==13) break; // detect CR LF and treat as single new line\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\r\n\t\t\t\tthis.extraBR=true;\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\t//element.scrollIntoView();\r\n\t\t\t\t//element.scrollTop = element.scrollHeight;\r\n\t\t\t\tlet p = this.div.getBoundingClientRect();\r\n\t\t\t\twindow.scrollTo(0, p.height+100);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 8: // backspace\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xE: // cursor on\r\n\t\t\t\tif (!this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=true;\r\n\t\t\t\t\tthis.div.innerHTML += this.CURSOR;\r\n\t\t\t\t\tthis.div.focus();\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xF: // cursor off\r\n\t\t\t\tif (this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=false;\r\n\t\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += String.fromCharCode(ch);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\tthis.lastChar=ch;\r\n\t}\r\n\r\n\tstringOut(str:string) {\r\n\t\tfor (let i=0; i < str.length; i++)\r\n\t\t\tthis.charOut(str.charCodeAt(i));\r\n\t}\r\n}\r\n\r\n\r\nexport class twrDivProxy implements IDiv {\r\n divKeys: twrSharedCircularBuffer;\r\n\r\n constructor(params:TDivProxyParams) {\r\n const [divKeysBuffer] = params;\r\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\r\n }\r\n\r\n charIn() { \r\n return this.divKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.divKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n\tcharOut(ch:number) {\r\n\t\tpostMessage([\"divout\", ch]);\r\n\t}\r\n}\r\n\r\n","let logline = \"\";\nexport function twrDebugLogImpl(char) {\n if (char == 10 || char == 3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\n console.log(logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n logline = \"\";\n }\n else {\n logline = logline + String.fromCharCode(char);\n if (logline.length >= 200) {\n console.log(logline);\n logline = \"\";\n }\n }\n}\n// ************************************************************************\n// debugLog doesn't currently wait for the message to log, it returns immediately.\n// I could move this to be in the twrWaitingCalls class\nexport function twrDebugLogProxy(ch) {\n postMessage([\"debug\", ch]);\n}\n//# sourceMappingURL=twrdebug.js.map","\r\nlet logline=\"\";\r\nexport function twrDebugLogImpl(char:number) {\r\n\tif (char==10 || char==3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\r\n\t\tconsole.log(logline);\t// ideally without a linefeed, but there is no way to not have a LF with console.log API.\r\n\t\tlogline=\"\";\r\n\t}\r\n\telse {\r\n\t\tlogline=logline+String.fromCharCode(char);\r\n\t\tif (logline.length>=200) {\r\n\t\t\tconsole.log(logline);\r\n\t\t\tlogline=\"\";\r\n\t\t}\r\n\t}\r\n}\r\n\r\n// ************************************************************************\r\n// debugLog doesn't currently wait for the message to log, it returns immediately.\r\n// I could move this to be in the twrWaitingCalls class\r\nexport function twrDebugLogProxy(ch:number) {\r\n postMessage([\"debug\", ch]);\r\n}\r\n\r\n","import { twrFloatUtil } from \"./twrfloat.js\";\n/*********************************************************************/\n/*********************************************************************/\n/*********************************************************************/\nexport class twrWasmModuleBase {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\n floatUtil;\n constructor(isWasmModule = false) {\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new twrFloatUtil(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/\n /*********************************************************************/\n async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n }\n catch (err) {\n console.log('loadWasm() failed to fetch: ' + pathToLoad);\n throw err;\n }\n if (!response.ok)\n throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, { env: allimports });\n this.exports = instance.instance.exports;\n if (!this.exports)\n throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory)\n throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory)\n throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer)\n console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\"setmemory\", this.memory]);\n }\n if (this.isWasmModule) {\n // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (!(this.memory.buffer instanceof ArrayBuffer))\n console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size) => {\n return new Promise(resolve => {\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n }\n catch (err) {\n console.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch (this.modParams.stdio) {\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* callC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */\n async callC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.callCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async callCImpl(fname, cparams = []) {\n if (!this.exports)\n throw new Error(\"this.exports undefined\");\n if (!this.exports[fname])\n throw new Error(\"callC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array))\n throw new Error(\"callC: params must be array, first arg is function name\");\n if (params.length == 0)\n throw new Error(\"callC: missing function name\");\n let cparams = [];\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n cparams[ci++] = p;\n break;\n case 'string':\n cparams[ci++] = await this.putString(p);\n break;\n case 'object':\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n }\n else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"callC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n ci++;\n break;\n case 'string':\n this.callCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n case 'object':\n if (p instanceof URL) {\n this.callCImpl('twr_free', [cparams[ci]]);\n ci = ci + 2;\n break;\n }\n else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for (let j = 0; j < u8.length; j++)\n u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.callCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n }\n else\n throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/\n /*********************************************************************/\n // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for (i = 0; i < sin.length && i < buffer_size - 1; i++)\n this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for (let i = 0; i < u8a.length; i++)\n this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === 'object' && fnin instanceof URL))\n throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [dest, src.length];\n }\n catch (err) {\n console.log('fetchAndPutURL Error. URL: ' + fnin + '\\n' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while (this.mem8[strIndex + i] && (len === undefined ? true : i < len) && (strIndex + i) < this.mem8.length) {\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0)\n throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array((this.mem8.slice(dataptr, dataptr + size)).buffer);\n return u32;\n }\n}\n//# sourceMappingURL=twrmodbase.js.map","\r\nimport {TCanvasProxyParams} from \"./twrcanvas.js\"\r\nimport {TDivProxyParams} from \"./twrdiv.js\";\r\nimport {TWaitingCallsProxyParams} from \"./twrwaitingcalls.js\"\r\nimport {twrDebugLogImpl} from \"./twrdebug.js\";\r\nimport {twrFloatUtil} from \"./twrfloat.js\";\r\n\r\n\r\nexport type TStdioVals=\"div\"|\"canvas\"|\"null\"|\"debug\";\r\n\r\nexport interface IModOpts {\r\n\tstdio?:TStdioVals, \r\n\twindim?:[number, number],\r\n\tforecolor?:string,\r\n\tbackcolor?:string,\r\n\tfontsize?:number,\r\n\tisd2dcanvas?:boolean,\r\n\timports?:{},\r\n}\r\n\r\nexport interface IModParams {\r\n\tstdio:TStdioVals, \r\n\twindim:[number, number],\r\n\tforecolor:string,\r\n\tbackcolor:string,\r\n\tfontsize:number,\r\n\tstyleIsDefault: boolean\r\n\tisd2dcanvas:boolean,\r\n\timports:{[index:string]:Function},\r\n}\r\n\r\nexport interface IModInWorkerParams {\r\n\tdivProxyParams:TDivProxyParams,\r\n\tcanvasProxyParams:TCanvasProxyParams,\r\n\twaitingCallsProxyParams:TWaitingCallsProxyParams,\r\n}\r\n\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n\r\nexport abstract class twrWasmModuleBase {\r\n\tmemory?:WebAssembly.Memory;\r\n\tmem8:Uint8Array;\r\n\tmem32:Uint32Array;\r\n\tmemD:Float64Array;\r\n\tabstract malloc:(size:number)=>Promise;\r\n\tabstract modParams:IModParams;\r\n\texports?:WebAssembly.Exports;\r\n\tisWorker=false;\r\n\tisWasmModule:boolean; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\r\n\tfloatUtil:twrFloatUtil;\r\n\r\n\tconstructor(isWasmModule=false) {\r\n\t\tthis.isWasmModule=isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\r\n\t\tthis.mem8=new Uint8Array(); \t// avoid type errors\r\n\t\tthis.mem32=new Uint32Array(); // avoid type errors\r\n\t\tthis.memD=new Float64Array(); // avoid type errors\r\n\t\tthis.floatUtil=new twrFloatUtil(this);\r\n\t\t//console.log(\"size of mem8 after constructor\",this.mem8.length);\r\n\t}\r\n\r\n\t/*********************************************************************/\r\n\t/*********************************************************************/\r\n\r\n\tasync loadWasm(pathToLoad:string) {\r\n\t\t//console.log(\"fileToLoad\",fileToLoad)\r\n\r\n\t\tlet response;\r\n\t\ttry {\r\n\t\t\tresponse=await fetch(pathToLoad);\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('loadWasm() failed to fetch: '+pathToLoad);\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t\t\r\n\t\tif (!response.ok) throw new Error(\"fetch response error on file '\"+pathToLoad+\"'\\n\"+response.statusText);\r\n\r\n\t\ttry {\r\n\t\t\tlet wasmBytes = await response.arrayBuffer();\r\n\r\n\t\t\tlet allimports:WebAssembly.ModuleImports = { \r\n\t\t\t\t...this.modParams.imports\r\n\t\t\t};\r\n\r\n\t\t\tlet instance = await WebAssembly.instantiate(wasmBytes, {env: allimports});\r\n\r\n\t\t\tthis.exports=instance.instance.exports;\r\n\t\t\tif (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\r\n\r\n\t\t\tif (this.memory) throw new Error (\"unexpected error -- this.memory already set\");\r\n\t\t\tthis.memory=this.exports.memory as WebAssembly.Memory;\r\n\t\t\tif (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\r\n\t\t\tthis.mem8 = new Uint8Array(this.memory.buffer);\r\n\t\t\tthis.mem32 = new Uint32Array(this.memory.buffer);\r\n\t\t\tthis.memD = new Float64Array(this.memory.buffer);\r\n\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\tif (this.isWorker) {\r\n\t\t\t\tif (this.memory.buffer instanceof ArrayBuffer)\r\n\t\t\t\t\tconsole.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\r\n\t\t\t\t\r\n\t\t\t\tpostMessage([\"setmemory\",this.memory]);\r\n\t\t\t}\r\n\t\t\tif (this.isWasmModule) {\r\n\t\t\t\t// here if twrWasmModule, twrWasmModuleAsync overrides this function\r\n\t\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\t\tif (!(this.memory.buffer instanceof ArrayBuffer))\r\n\t\t\t\t\tconsole.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\r\n\t\t\t}\r\n\r\n\t\t\tthis.malloc=(size:number)=>{\r\n\t\t\t\treturn new Promise(resolve => {\r\n\t\t\t\t\tconst m=this.exports!.twr_malloc as (size:number)=>number;\r\n\t\t\t\t\tresolve(m(size));\r\n\t\t\t\t});\r\n\t\t };\r\n\r\n\t\t\tthis.init();\r\n\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t}\r\n\r\n\tprivate init() {\r\n\t\t//console.log(\"loadWasm.init() enter\")\r\n\t\t\tlet p:number;\r\n\t\t\tswitch (this.modParams.stdio) {\r\n\t\t\t\tcase \"debug\":\r\n\t\t\t\t\tp=0;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"div\":\r\n\t\t\t\t\tp=1;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"canvas\":\r\n\t\t\t\t\tp=2;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"null\":\r\n\t\t\t\t\tp=3;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tp=0; // debug\r\n\t\t\t}\r\n\r\n\t\t\tconst twrInit=this.exports!.twr_wasm_init as CallableFunction;\r\n\t\t\t//console.log(\"twrInit:\",twrInit)\r\n\t\t\ttwrInit(p, this.mem8.length);\r\n\t}\r\n\r\n\t/* callC takes an array where:\r\n\t* the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\r\n\t* and the next entries are a variable number of parameters to pass to the C function, of type\r\n\t* number - converted to int32 or float64 as appropriate\r\n\t* string - converted to a an index (ptr) into a module Memory returned via stringToMem()\r\n\t* URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\r\n\t* Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\r\n */\r\n\r\n\tasync callC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\t\tconst cparams=await this.preCallC(params);\r\n\t\tlet retval = this.callCImpl(params[0], cparams);\r\n\t\tthis.postCallC(cparams, params);\r\n\t\treturn retval;\r\n\t}\r\n\r\n\tasync callCImpl(fname:string, cparams:number[]=[]) {\r\n\t\tif (!this.exports) throw new Error(\"this.exports undefined\");\r\n\t\tif (!this.exports[fname]) throw new Error(\"callC: function '\"+fname+\"' not in export table. Use --export wasm-ld flag.\");\r\n\r\n\t\tconst f = this.exports[fname] as CallableFunction;\r\n\t\tlet cr=f(...cparams);\r\n\r\n\t\treturn cr;\r\n\t}\r\n\r\n\t// convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\r\n\tasync preCallC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tif (!(params.constructor === Array)) throw new Error (\"callC: params must be array, first arg is function name\");\r\n\t\tif (params.length==0) throw new Error(\"callC: missing function name\");\r\n\r\n\t\tlet cparams:number[]=[];\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tcparams[ci++]=p;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tcparams[ci++]=await this.putString(p);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tconst r=await this.fetchAndPutURL(p);\r\n\t\t\t\t\t\tcparams[ci++]=r[0]; // mem index\r\n\t\t\t\t\t\tcparams[ci++]=r[1]; // len\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tconst r=await this.putArrayBuffer(p);\r\n\t\t\t\t\t\tcparams[ci++]=r; // mem index\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tthrow new Error (\"callC: invalid object type passed in\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn cparams;\r\n\t}\r\n\r\n\t// free the mallocs; copy array buffer data from malloc back to arraybuffer\r\n\tasync postCallC(cparams:number[], params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tthis.callCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t\t\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tthis.callCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\t\tci=ci+2;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tlet u8=new Uint8Array(p);\r\n\t\t\t\t\t\tfor (let j=0; j= this.mem32.length) throw new Error(\"invalid index passed to getLong: \"+idx+\", this.mem32.length: \"+this.mem32.length);\r\n\t\tconst long:number = this.mem32[idx32];\r\n\t\treturn long;\r\n\t}\r\n\t\r\n\tsetLong(idx:number, value:number) {\r\n const idx32 = Math.floor(idx / 4);\r\n if (idx32 * 4 != idx)\r\n throw new Error(\"setLong passed non long aligned address\");\r\n if (idx32 < 0 || idx32 >= this.mem32.length)\r\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\r\n this.mem32[idx32]=value;\r\n }\r\n\r\n\tgetDouble(idx:number): number {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"getLong passed non Float64 aligned address\")\r\n\t\tconst long:number = this.memD[idx64];\r\n\t\treturn long;\r\n\t}\r\n\r\n\tsetDouble(idx:number, value:number) {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"setDouble passed non Float64 aligned address\")\r\n\t\tthis.memD[idx64]=value;\r\n\t}\r\n\r\n\tgetShort(idx:number): number {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getShort: \"+idx);\r\n\t\tconst short:number = this.mem8[idx]+this.mem8[idx+1]*256;\r\n\t\treturn short;\r\n\t}\r\n\r\n\t// get a string out of module memory\r\n\t// null terminated, up until max of (optional) len\r\n\tgetString(strIndex:number, len?:number): string {\r\n\t\tlet sout=\"\";\r\n\r\n\t\tlet i=0;\r\n\t\twhile (this.mem8[strIndex+i] && (len===undefined?true:i= this.mem8.length) throw new Error(\"invalid index passed to getU8: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU8\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU8\")\r\n\r\n\t\tconst u8=this.mem8.slice(dataptr, dataptr+size);\r\n\t\treturn u8;\r\n\t}\r\n\r\n\t// get a int32 array out of module memory when passed in index to [size, dataptr]\r\n\tgetU32Arr(idx:number): Uint32Array {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getU32: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU32\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU32\")\r\n\r\n\t\tif (size%4!=0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\r\n\r\n\t\tconst u32 = new Uint32Array( (this.mem8.slice(dataptr, dataptr+size)).buffer );\r\n\t\treturn u32;\r\n\t}\r\n}\r\n","export class twrFloatUtil {\n mod;\n constructor(mod) {\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\")\n return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\")\n return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll('D', 'e').replaceAll('d', 'e'));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n }\n else {\n let r = value.toString();\n if (r.length > max_precision)\n r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, // char *\n sizeInBytes, //size_t\n value, // double\n fracpart_numdigits, //int\n dec, // int *\n sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1)\n return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) { /* nan */\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (!Number.isFinite(value)) { /* infinity */\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n }\n else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split('.');\n if (intPart == \"0\")\n intPart = \"\";\n if (intPart.length > 0) { // has integer part\n decpos = intPart.length;\n digits = intPart + fracPart;\n }\n else { // only a fraction\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length)\n return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */\n }\n}\n//# sourceMappingURL=twrfloat.js.map","\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\"\r\n\r\nexport class twrFloatUtil {\r\n mod: twrWasmModuleBase;\r\n\r\n constructor(mod: twrWasmModuleBase) {\r\n this.mod=mod;\r\n }\r\n\r\n atod(strptr:number):number {\r\n const str=this.mod.getString(strptr);\r\n\r\n const upper=str.trimStart().toUpperCase();\r\n if (upper==\"INF\" || upper==\"+INF\")\r\n return Number.POSITIVE_INFINITY;\r\n else if (upper==\"-INF\")\r\n return Number.NEGATIVE_INFINITY\r\n else {\r\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\r\n const r=Number.parseFloat(str.replaceAll('D','e').replaceAll('d','e'));\r\n return r;\r\n }\r\n }\r\n\r\n dtoa(buffer:number, buffer_size:number, value:number, max_precision:number):void {\r\n if (max_precision==-1) {\r\n const r=value.toString();\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n else {\r\n let r=value.toString();\r\n if (r.length>max_precision)\r\n r=value.toPrecision(max_precision);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n }\r\n\r\n toFixed(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toFixed(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n toExponential(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toExponential(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\r\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\r\n // Negative exponents must be now smaller than 1e-99\r\n // fully-function C version also int he source, but this is the version enabled by default\r\n fcvtS(\r\n buffer:number, // char *\r\n sizeInBytes:number, //size_t\r\n value:number, // double\r\n fracpart_numdigits:number, //int\r\n dec:number, // int *\r\n sign:number // int *\r\n ):number {\r\n\r\n if (buffer==0 ||sign==0 || dec==0 || sizeInBytes<1) return 1;\r\n\r\n let digits:string;\r\n let decpos:number;\r\n let s=0; // default to positive\r\n\r\n\r\n if (Number.isNaN(value)) { /* nan */\r\n digits=\"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (!Number.isFinite(value)) { /* infinity */\r\n digits=\"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (value==0) { \r\n digits=\"000000000000000000000000000000000000\".slice(0,fracpart_numdigits);\r\n decpos=0;\r\n }\r\n \r\n else {\r\n\r\n if (value<0) {\r\n s=1; // negative\r\n value=Math.abs(value);\r\n }\r\n\r\n if (fracpart_numdigits>100 || value > 1e+21 || value < 1e-99) { \r\n this.mod.copyString(buffer, sizeInBytes, \"\");\r\n this.mod.mem32[dec]=0;\r\n return 1;\r\n }\r\n\r\n const roundValStr=value.toFixed(fracpart_numdigits);\r\n let [intPart=\"\", fracPart=\"\"] = roundValStr.split('.');\r\n if (intPart==\"0\") intPart=\"\";\r\n\r\n if (intPart.length>0) { // has integer part\r\n decpos=intPart.length;\r\n digits=intPart+fracPart;\r\n }\r\n else { // only a fraction\r\n digits=fracPart.replace(/^0+/,\"\"); // remove leading zeros\r\n decpos=digits.length-fracPart.length;\r\n }\r\n }\r\n\r\n if (sizeInBytes-1 < digits.length) return 1; \r\n this.mod.copyString(buffer, sizeInBytes, digits);\r\n this.mod.setLong(dec, decpos);\r\n this.mod.setLong(sign, s);\r\n\r\n return 0;\r\n\r\n /*\r\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\r\n\r\n let decpos=0;\r\n let digits:string;\r\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\r\n \r\n if (decpos>0) { // has integer part\r\n const intlen=Math.max(decpos, 0);\r\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\r\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\r\n }\r\n else { // only a fraction\r\n const intpart=Math.trunc(value);\r\n const fracpart=value-intpart;\r\n const prec=fracpart_numdigits- (-decpos);\r\n console.log(\"prec=\",prec);\r\n if (prec<1) {\r\n digits=\"\";\r\n }\r\n else {\r\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\");\r\n }\r\n }\r\n\r\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\r\n console.log('digits=',digits);\r\n console.log('dec=',decpos);\r\n console.log(\"sign=\",s);\r\n */\r\n\r\n\r\n }\r\n}","import { twrSignal } from \"./twrsignal.js\";\nimport { twrTimeImpl } from \"./twrdate.js\";\n// This class is used in the Main JS thread \nexport class twrWaitingCalls {\n callCompleteSignal;\n parameters;\n constructor() {\n this.callCompleteSignal = new twrSignal();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(() => {\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = twrTimeImpl();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [this.callCompleteSignal.sharedArray, this.parameters.buffer];\n }\n processMessage(msgType, data) {\n switch (msgType) {\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\n// This class is used in the worker thread \nexport class twrWaitingCallsProxy {\n callCompleteSignal;\n parameters;\n constructor(params) {\n this.callCompleteSignal = new twrSignal(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\"sleep\", [ms]]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\"time\"]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n//# sourceMappingURL=twrwaitingcalls.js.map","import { twrSignal } from \"./twrsignal.js\";\r\nimport {twrTimeImpl} from \"./twrdate.js\"\r\n\r\n// These classes are used to proxy a call across the worker thread - main thread boundary and wait for the result\r\n\r\nexport type TWaitingCallsProxyParams = [SharedArrayBuffer, SharedArrayBuffer]; // twrSignal, parameters \r\n\r\n// This class is used in the Main JS thread \r\nexport class twrWaitingCalls {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor() {\r\n\t\tthis.callCompleteSignal=new twrSignal();\r\n\t\tthis.parameters=new Uint32Array(new SharedArrayBuffer(4));\r\n\t}\r\n\r\n\tprivate startSleep(ms:number) {\r\n\r\n\t\tsetTimeout(()=>{\r\n\t\t\tthis.callCompleteSignal.signal();\r\n\t\t}, ms);\r\n\t\t\r\n\t}\r\n\r\n\tprivate time() {\r\n\t\tconst ms=twrTimeImpl();\r\n\t\tthis.parameters[0]=ms;\r\n\t\tthis.callCompleteSignal.signal();\r\n\t}\r\n\r\n\tgetProxyParams():TWaitingCallsProxyParams {\r\n\t\treturn [this.callCompleteSignal.sharedArray, this.parameters.buffer as SharedArrayBuffer];\t\r\n\t}\r\n\r\n\tprocessMessage(msgType:string, data:any[]):boolean {\r\n\t\tswitch (msgType) {\r\n\t\t\tcase \"sleep\":\r\n\t\t\t\tconst [ms] = data;\r\n\t\t\t\tthis.startSleep(ms);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"time\":\r\n\t\t\t\tthis.time();\r\n\t\t\t\tbreak;\r\n\t\t\t\r\n\t\t\tdefault:\r\n\t\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\treturn true;\r\n\t}\r\n\r\n}\r\n\r\n// This class is used in the worker thread \r\nexport class twrWaitingCallsProxy {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor(params:TWaitingCallsProxyParams) {\r\n\t\tthis.callCompleteSignal=new twrSignal(params[0]);\r\n\t\tthis.parameters=new Uint32Array(params[1]);\r\n\t}\r\n\r\n\tsleep(ms:number) {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"sleep\", [ms]]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t}\r\n\r\n\ttime() {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"time\"]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t\treturn this.parameters[0];\r\n\t}\r\n\r\n}\r\n","export function twrTimeImpl() {\n return Date.now();\n}\n//# sourceMappingURL=twrdate.js.map","\r\nexport function twrTimeImpl() {\r\n\r\n return Date.now();\r\n\r\n}"],"names":["$b93f1fdf40141def$var$twrSignalState","$c4741cac81d14197$var$D2DType","twrSignalState","D2DType","$3e39efa823870787$var$mod","$892fccfc812d5e20$export$a01cca24f011573a","sharedArray","buf","constructor","sa","window","crossOriginIsolated","location","protocol","Error","SharedArrayBuffer","Int32Array","write","n","i","Atomics","notify","read","isEmpty","readWait","rdptr","wait","$b93f1fdf40141def$export$e37a7b7b851b97f3","WAITING","signal","SIGNALED","isSignaled","reset","$c4741cac81d14197$export$c779b2cd00544976","canvasKeys","drawCompleteSignal","props","owner","params","signalBuffer","canvasKeysBuffer","charIn","inkey","getProp","pn","propName","getString","drawSeq","ds","postMessage","$8963973702ae5462$export$b377f0bbf2c7581e","divKeys","divKeysBuffer","charOut","ch","$8ac0b786da854328$export$485af4d0039b3389","$e72303a1db04bdfa$export$918ffb7e046a537b","mod","atod","strptr","str","upper","trimStart","toUpperCase","Number","POSITIVE_INFINITY","NEGATIVE_INFINITY","parseFloat","replaceAll","dtoa","buffer","buffer_size","value","max_precision","r","toString","copyString","length","toPrecision","toFixed","decdigits","toExponential","fcvtS","sizeInBytes","fracpart_numdigits","dec","sign","digits","decpos","s","isNaN","slice","isFinite","Math","abs","mem32","intPart","fracPart","roundValStr","split","replace","setLong","$ece7fa3ed770778a$export$c83a0a3bffe07399","memory","mem8","memD","exports","isWorker","isWasmModule","floatUtil","Uint8Array","Uint32Array","Float64Array","loadWasm","pathToLoad","response","fetch","err","console","log","ok","statusText","wasmBytes","arrayBuffer","allimports","modParams","imports","instance","WebAssembly","instantiate","env","ArrayBuffer","malloc","size","Promise","resolve","m","twr_malloc","init","stack","p","stdio","twrInit","twr_wasm_init","callC","cparams","preCallC","retval","callCImpl","postCallC","fname","f","Array","ci","putString","URL","fetchAndPutURL","putArrayBuffer","u8","j","sin","charCodeAt","strIndex","putU8","u8a","dest","ab","fnin","src","getLong","idx","idx32","floor","getDouble","idx64","setDouble","getShort","len","sout","undefined","String","fromCharCode","getU8Arr","rv","dataptr","getU32Arr","$aff9c2c494d23fe3$export$78d2a4633fe89379","callCompleteSignal","parameters","sleep","ms","time","onmessage","e","data","$3e39efa823870787$var$twrWasmModuleInWorker","modWorkerParams","urlToLoad","then","catch","ex","rc","modInWorkerParams","canvasProxy","canvasProxyParams","divProxy","divProxyParams","waitingCallsProxy","waitingCallsProxyParams","twrDebugLog","twrSleep","bind","twrTime","twrDivCharOut","twrDivCharIn","twrCanvasCharIn","twrCanvasInkey","twrCanvasGetProp","twrCanvasDrawSeq","twrSin","twrCos","cos","twrTan","tan","twrFAbs","twrACos","acos","twrASin","asin","twrATan","atan","twrExp","exp","twrFloor","twrCeil","ceil","twrFMod","x","y","twrLog","twrPow","pow","twrSqrt","sqrt","twrTrunc","trunc","twrDtoa","twrToFixed","twrToExponential","twrAtod","twrFcvtS"],"version":3,"file":"twrmodworker.2165e649.js.map"} \ No newline at end of file diff --git a/azure/examples/stdio-canvas/index.html b/azure/examples/stdio-canvas/index.html index fedfb6f6..8ac2322d 100644 --- a/azure/examples/stdio-canvas/index.html +++ b/azure/examples/stdio-canvas/index.html @@ -25,8 +25,8 @@ document.getElementById("twr_iocanvas").addEventListener("keydown",(ev)=>{amod.keyDownCanvas(ev)}); await amod.loadWasm("./stdio-canvas.wasm"); - const r=await amod.executeC(["stdio_canvas"]); - console.log("executeC returned: "+r); + const r=await amod.callC(["stdio_canvas"]); + console.log("callC returned: "+r); } catch(ex) { console.log("unexpected exception"); diff --git a/azure/examples/stdio-div/dist/index.html b/azure/examples/stdio-div/dist/index.html index 5f95c0d0..fc6b98f6 100644 --- a/azure/examples/stdio-div/dist/index.html +++ b/azure/examples/stdio-div/dist/index.html @@ -5,4 +5,4 @@ "whatkey": "../../lib-js/whatkey.js" } } - \ No newline at end of file + \ No newline at end of file diff --git a/azure/examples/stdio-div/dist/twrmodworker.2165e649.js b/azure/examples/stdio-div/dist/twrmodworker.2165e649.js index 3744680c..d8d07779 100644 --- a/azure/examples/stdio-div/dist/twrmodworker.2165e649.js +++ b/azure/examples/stdio-div/dist/twrmodworker.2165e649.js @@ -1,2 +1,2 @@ -(()=>{var t,e,r,s;let i;class a{sharedArray;buf;constructor(t){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSharedCircularBuffer constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");t?this.sharedArray=t:this.sharedArray=new SharedArrayBuffer(1032),this.buf=new Int32Array(this.sharedArray),this.buf[256]=0,this.buf[257]=0}write(t){let e=this.buf[257];this.buf[e]=t,256==++e&&(e=0),this.buf[257]=e,Atomics.notify(this.buf,257)}read(){if(this.isEmpty())return -1;{let t=this.buf[256],e=this.buf[t];return t++,this.buf[256]=t,e}}readWait(){if(this.isEmpty()){let t=this.buf[256];Atomics.wait(this.buf,257,t)}return this.read()}isEmpty(){return this.buf[256]==this.buf[257]}}(r=t||(t={}))[r.WAITING=0]="WAITING",r[r.SIGNALED=1]="SIGNALED";class o{sharedArray;buf;constructor(e){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSignal constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");e?this.sharedArray=e:this.sharedArray=new SharedArrayBuffer(4),this.buf=new Int32Array(this.sharedArray),this.buf[0]=t.WAITING}signal(){this.buf[0]=t.SIGNALED,Atomics.notify(this.buf,0)}wait(){this.buf[0]==t.WAITING&&Atomics.wait(this.buf,0,t.WAITING)}isSignaled(){return this.buf[0]==t.SIGNALED}reset(){this.buf[0]=t.WAITING}}(s=e||(e={}))[s.D2D_FILLRECT=1]="D2D_FILLRECT",s[s.D2D_FILLCHAR=5]="D2D_FILLCHAR",s[s.D2D_SETLINEWIDTH=10]="D2D_SETLINEWIDTH",s[s.D2D_SETFILLSTYLERGBA=11]="D2D_SETFILLSTYLERGBA",s[s.D2D_SETFONT=12]="D2D_SETFONT",s[s.D2D_BEGINPATH=13]="D2D_BEGINPATH",s[s.D2D_MOVETO=14]="D2D_MOVETO",s[s.D2D_LINETO=15]="D2D_LINETO",s[s.D2D_FILL=16]="D2D_FILL",s[s.D2D_STROKE=17]="D2D_STROKE",s[s.D2D_SETSTROKESTYLERGBA=18]="D2D_SETSTROKESTYLERGBA",s[s.D2D_ARC=19]="D2D_ARC",s[s.D2D_STROKERECT=20]="D2D_STROKERECT",s[s.D2D_FILLTEXT=21]="D2D_FILLTEXT",s[s.D2D_IMAGEDATA=22]="D2D_IMAGEDATA",s[s.D2D_PUTIMAGEDATA=23]="D2D_PUTIMAGEDATA",s[s.D2D_BEZIERTO=24]="D2D_BEZIERTO",s[s.D2D_MEASURETEXT=25]="D2D_MEASURETEXT",s[s.D2D_SAVE=26]="D2D_SAVE",s[s.D2D_RESTORE=27]="D2D_RESTORE",s[s.D2D_CREATERADIALGRADIENT=28]="D2D_CREATERADIALGRADIENT",s[s.D2D_SETCOLORSTOP=29]="D2D_SETCOLORSTOP",s[s.D2D_SETFILLSTYLEGRADIENT=30]="D2D_SETFILLSTYLEGRADIENT",s[s.D2D_RELEASEID=31]="D2D_RELEASEID",s[s.D2D_CREATELINEARGRADIENT=32]="D2D_CREATELINEARGRADIENT",s[s.D2D_SETFILLSTYLE=33]="D2D_SETFILLSTYLE",s[s.D2D_SETSTROKESTYLE=34]="D2D_SETSTROKESTYLE";class n{canvasKeys;drawCompleteSignal;props;owner;constructor(t,e){let[r,s,i]=t;this.drawCompleteSignal=new o(s),this.canvasKeys=new a(i),this.props=r,this.owner=e}charIn(){return this.canvasKeys.readWait()}inkey(){return this.canvasKeys.isEmpty()?0:this.charIn()}getProp(t){let e=this.owner.getString(t);return this.props[e]}drawSeq(t){this.drawCompleteSignal.reset(),postMessage(["drawseq",[t]]),this.drawCompleteSignal.wait()}}class l{divKeys;constructor(t){let[e]=t;this.divKeys=new a(e)}charIn(){return this.divKeys.readWait()}inkey(){return this.divKeys.isEmpty()?0:this.charIn()}charOut(t){postMessage(["divout",t])}}function h(t){postMessage(["debug",t])}class m{mod;constructor(t){this.mod=t}atod(t){let e=this.mod.getString(t),r=e.trimStart().toUpperCase();return"INF"==r||"+INF"==r?Number.POSITIVE_INFINITY:"-INF"==r?Number.NEGATIVE_INFINITY:Number.parseFloat(e.replaceAll("D","e").replaceAll("d","e"))}dtoa(t,e,r,s){if(-1==s){let s=r.toString();this.mod.copyString(t,e,s)}else{let i=r.toString();i.length>s&&(i=r.toPrecision(s)),this.mod.copyString(t,e,i)}}toFixed(t,e,r,s){let i=r.toFixed(s);this.mod.copyString(t,e,i)}toExponential(t,e,r,s){let i=r.toExponential(s);this.mod.copyString(t,e,i)}fcvtS(t,e,r,s,i,a){let o,n;if(0==t||0==a||0==i||e<1)return 1;let l=0;if(Number.isNaN(r))o="1#QNAN00000000000000000000000000000".slice(0,s+1),n=1;else if(Number.isFinite(r)){if(0==r)o="000000000000000000000000000000000000".slice(0,s),n=0;else{if(r<0&&(l=1,r=Math.abs(r)),s>100||r>1e21||r<1e-99)return this.mod.copyString(t,e,""),this.mod.mem32[i]=0,1;let[a="",h=""]=r.toFixed(s).split(".");"0"==a&&(a=""),a.length>0?(n=a.length,o=a+h):n=(o=h.replace(/^0+/,"")).length-h.length}}else o="1#INF00000000000000000000000000000".slice(0,s+1),n=1;return e-1new Promise(e=>{let r=this.exports.twr_malloc;e(r(t))}),this.init()}catch(t){throw console.log("WASM instantiate error: "+t+(t.stack?"\n"+t.stack:"")),t}}init(){let t;switch(this.modParams.stdio){case"debug":default:t=0;break;case"div":t=1;break;case"canvas":t=2;break;case"null":t=3}(0,this.exports.twr_wasm_init)(t,this.mem8.length)}async executeC(t){let e=await this.preCallC(t),r=this.executeCImpl(t[0],e);return this.postCallC(e,t),r}async executeCImpl(t,e=[]){if(!this.exports)throw Error("this.exports undefined");if(!this.exports[t])throw Error("executeC: function '"+t+"' not in export table. Use --export wasm-ld flag.");return(0,this.exports[t])(...e)}async preCallC(t){if(t.constructor!==Array)throw Error("executeC: params must be array, first arg is function name");if(0==t.length)throw Error("executeC: missing function name");let e=[],r=0;for(let s=1;s=this.mem32.length)throw Error("invalid index passed to getLong: "+t+", this.mem32.length: "+this.mem32.length);return this.mem32[e]}setLong(t,e){let r=Math.floor(t/4);if(4*r!=t)throw Error("setLong passed non long aligned address");if(r<0||r>=this.mem32.length)throw Error("invalid index passed to setLong: "+t+", this.mem32.length: "+this.mem32.length);this.mem32[r]=e}getDouble(t){let e=Math.floor(t/8);if(8*e!=t)throw Error("getLong passed non Float64 aligned address");return this.memD[e]}setDouble(t,e){let r=Math.floor(t/8);if(8*r!=t)throw Error("setDouble passed non Float64 aligned address");this.memD[r]=e}getShort(t){if(t<0||t>=this.mem8.length)throw Error("invalid index passed to getShort: "+t);return this.mem8[t]+256*this.mem8[t+1]}getString(t,e){let r="",s=0;for(;this.mem8[t+s]&&(void 0===e||s=this.mem8.length)throw Error("invalid index passed to getU8: "+t);let e=new Uint32Array(this.mem8.slice(t,t+8).buffer),r=e[0],s=e[1];if(s<0||s>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU8");if(r<0||r>this.mem8.length-s)throw Error("invalid idx.size passed to getU8");return this.mem8.slice(s,s+r)}getU32Arr(t){if(t<0||t>=this.mem8.length)throw Error("invalid index passed to getU32: "+t);let e=new Uint32Array(this.mem8.slice(t,t+8).buffer),r=e[0],s=e[1];if(s<0||s>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU32");if(r<0||r>this.mem8.length-s)throw Error("invalid idx.size passed to getU32");if(r%4!=0)throw Error("idx.size is not an integer number of 32 bit words");return new Uint32Array(this.mem8.slice(s,s+r).buffer)}}class d{callCompleteSignal;parameters;constructor(t){this.callCompleteSignal=new o(t[0]),this.parameters=new Uint32Array(t[1])}sleep(t){this.callCompleteSignal.reset(),postMessage(["sleep",[t]]),this.callCompleteSignal.wait()}time(){return this.callCompleteSignal.reset(),postMessage(["time"]),this.callCompleteSignal.wait(),this.parameters[0]}}onmessage=function(t){if("startup"==t.data[0]){let e=t.data[1];(i=new f(e.modParams,e.modWorkerParams)).loadWasm(e.urlToLoad).then(()=>{postMessage(["startupOkay"])}).catch(t=>{console.log(".catch: ",t),postMessage(["startupFail",t])})}else"executeC"==t.data[0]?i.executeCImpl(t.data[1],t.data[2]).then(t=>{postMessage(["executeCOkay",t])}).catch(t=>{console.log("exception in executeC twrworker.js\n"),console.log(t),postMessage(["executeCFail",t])}):console.log("twrworker.js: unknown message: "+t)};class f extends c{malloc;modParams;constructor(t,e){super(),this.isWorker=!0,this.malloc=t=>{throw Error("error - un-init malloc called")},this.modParams=t;let r=new n(e.canvasProxyParams,this),s=new l(e.divProxyParams),i=new d(e.waitingCallsProxyParams);this.modParams.imports={twrDebugLog:h,twrSleep:i.sleep.bind(i),twrTime:i.time.bind(i),twrDivCharOut:s.charOut.bind(s),twrDivCharIn:s.charIn.bind(s),twrCanvasCharIn:r.charIn.bind(r),twrCanvasInkey:r.inkey.bind(r),twrCanvasGetProp:r.getProp.bind(r),twrCanvasDrawSeq:r.drawSeq.bind(r),twrSin:Math.sin,twrCos:Math.cos,twrTan:Math.tan,twrFAbs:Math.abs,twrACos:Math.acos,twrASin:Math.asin,twrATan:Math.atan,twrExp:Math.exp,twrFloor:Math.floor,twrCeil:Math.ceil,twrFMod:function(t,e){return t%e},twrLog:Math.log,twrPow:Math.pow,twrSqrt:Math.sqrt,twrTrunc:Math.trunc,twrDtoa:this.floatUtil.dtoa.bind(this.floatUtil),twrToFixed:this.floatUtil.toFixed.bind(this.floatUtil),twrToExponential:this.floatUtil.toExponential.bind(this.floatUtil),twrAtod:this.floatUtil.atod.bind(this.floatUtil),twrFcvtS:this.floatUtil.fcvtS.bind(this.floatUtil)}}}})(); +(()=>{var t,e,r,s;let i;class a{sharedArray;buf;constructor(t){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSharedCircularBuffer constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");t?this.sharedArray=t:this.sharedArray=new SharedArrayBuffer(1032),this.buf=new Int32Array(this.sharedArray),this.buf[256]=0,this.buf[257]=0}write(t){let e=this.buf[257];this.buf[e]=t,256==++e&&(e=0),this.buf[257]=e,Atomics.notify(this.buf,257)}read(){if(this.isEmpty())return -1;{let t=this.buf[256],e=this.buf[t];return t++,this.buf[256]=t,e}}readWait(){if(this.isEmpty()){let t=this.buf[256];Atomics.wait(this.buf,257,t)}return this.read()}isEmpty(){return this.buf[256]==this.buf[257]}}(r=t||(t={}))[r.WAITING=0]="WAITING",r[r.SIGNALED=1]="SIGNALED";class o{sharedArray;buf;constructor(e){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSignal constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");e?this.sharedArray=e:this.sharedArray=new SharedArrayBuffer(4),this.buf=new Int32Array(this.sharedArray),this.buf[0]=t.WAITING}signal(){this.buf[0]=t.SIGNALED,Atomics.notify(this.buf,0)}wait(){this.buf[0]==t.WAITING&&Atomics.wait(this.buf,0,t.WAITING)}isSignaled(){return this.buf[0]==t.SIGNALED}reset(){this.buf[0]=t.WAITING}}(s=e||(e={}))[s.D2D_FILLRECT=1]="D2D_FILLRECT",s[s.D2D_FILLCHAR=5]="D2D_FILLCHAR",s[s.D2D_SETLINEWIDTH=10]="D2D_SETLINEWIDTH",s[s.D2D_SETFILLSTYLERGBA=11]="D2D_SETFILLSTYLERGBA",s[s.D2D_SETFONT=12]="D2D_SETFONT",s[s.D2D_BEGINPATH=13]="D2D_BEGINPATH",s[s.D2D_MOVETO=14]="D2D_MOVETO",s[s.D2D_LINETO=15]="D2D_LINETO",s[s.D2D_FILL=16]="D2D_FILL",s[s.D2D_STROKE=17]="D2D_STROKE",s[s.D2D_SETSTROKESTYLERGBA=18]="D2D_SETSTROKESTYLERGBA",s[s.D2D_ARC=19]="D2D_ARC",s[s.D2D_STROKERECT=20]="D2D_STROKERECT",s[s.D2D_FILLTEXT=21]="D2D_FILLTEXT",s[s.D2D_IMAGEDATA=22]="D2D_IMAGEDATA",s[s.D2D_PUTIMAGEDATA=23]="D2D_PUTIMAGEDATA",s[s.D2D_BEZIERTO=24]="D2D_BEZIERTO",s[s.D2D_MEASURETEXT=25]="D2D_MEASURETEXT",s[s.D2D_SAVE=26]="D2D_SAVE",s[s.D2D_RESTORE=27]="D2D_RESTORE",s[s.D2D_CREATERADIALGRADIENT=28]="D2D_CREATERADIALGRADIENT",s[s.D2D_SETCOLORSTOP=29]="D2D_SETCOLORSTOP",s[s.D2D_SETFILLSTYLEGRADIENT=30]="D2D_SETFILLSTYLEGRADIENT",s[s.D2D_RELEASEID=31]="D2D_RELEASEID",s[s.D2D_CREATELINEARGRADIENT=32]="D2D_CREATELINEARGRADIENT",s[s.D2D_SETFILLSTYLE=33]="D2D_SETFILLSTYLE",s[s.D2D_SETSTROKESTYLE=34]="D2D_SETSTROKESTYLE";class n{canvasKeys;drawCompleteSignal;props;owner;constructor(t,e){let[r,s,i]=t;this.drawCompleteSignal=new o(s),this.canvasKeys=new a(i),this.props=r,this.owner=e}charIn(){return this.canvasKeys.readWait()}inkey(){return this.canvasKeys.isEmpty()?0:this.charIn()}getProp(t){let e=this.owner.getString(t);return this.props[e]}drawSeq(t){this.drawCompleteSignal.reset(),postMessage(["drawseq",[t]]),this.drawCompleteSignal.wait()}}class l{divKeys;constructor(t){let[e]=t;this.divKeys=new a(e)}charIn(){return this.divKeys.readWait()}inkey(){return this.divKeys.isEmpty()?0:this.charIn()}charOut(t){postMessage(["divout",t])}}function h(t){postMessage(["debug",t])}class m{mod;constructor(t){this.mod=t}atod(t){let e=this.mod.getString(t),r=e.trimStart().toUpperCase();return"INF"==r||"+INF"==r?Number.POSITIVE_INFINITY:"-INF"==r?Number.NEGATIVE_INFINITY:Number.parseFloat(e.replaceAll("D","e").replaceAll("d","e"))}dtoa(t,e,r,s){if(-1==s){let s=r.toString();this.mod.copyString(t,e,s)}else{let i=r.toString();i.length>s&&(i=r.toPrecision(s)),this.mod.copyString(t,e,i)}}toFixed(t,e,r,s){let i=r.toFixed(s);this.mod.copyString(t,e,i)}toExponential(t,e,r,s){let i=r.toExponential(s);this.mod.copyString(t,e,i)}fcvtS(t,e,r,s,i,a){let o,n;if(0==t||0==a||0==i||e<1)return 1;let l=0;if(Number.isNaN(r))o="1#QNAN00000000000000000000000000000".slice(0,s+1),n=1;else if(Number.isFinite(r)){if(0==r)o="000000000000000000000000000000000000".slice(0,s),n=0;else{if(r<0&&(l=1,r=Math.abs(r)),s>100||r>1e21||r<1e-99)return this.mod.copyString(t,e,""),this.mod.mem32[i]=0,1;let[a="",h=""]=r.toFixed(s).split(".");"0"==a&&(a=""),a.length>0?(n=a.length,o=a+h):n=(o=h.replace(/^0+/,"")).length-h.length}}else o="1#INF00000000000000000000000000000".slice(0,s+1),n=1;return e-1new Promise(e=>{let r=this.exports.twr_malloc;e(r(t))}),this.init()}catch(t){throw console.log("WASM instantiate error: "+t+(t.stack?"\n"+t.stack:"")),t}}init(){let t;switch(this.modParams.stdio){case"debug":default:t=0;break;case"div":t=1;break;case"canvas":t=2;break;case"null":t=3}(0,this.exports.twr_wasm_init)(t,this.mem8.length)}async callC(t){let e=await this.preCallC(t),r=this.callCImpl(t[0],e);return this.postCallC(e,t),r}async callCImpl(t,e=[]){if(!this.exports)throw Error("this.exports undefined");if(!this.exports[t])throw Error("callC: function '"+t+"' not in export table. Use --export wasm-ld flag.");return(0,this.exports[t])(...e)}async preCallC(t){if(t.constructor!==Array)throw Error("callC: params must be array, first arg is function name");if(0==t.length)throw Error("callC: missing function name");let e=[],r=0;for(let s=1;s=this.mem32.length)throw Error("invalid index passed to getLong: "+t+", this.mem32.length: "+this.mem32.length);return this.mem32[e]}setLong(t,e){let r=Math.floor(t/4);if(4*r!=t)throw Error("setLong passed non long aligned address");if(r<0||r>=this.mem32.length)throw Error("invalid index passed to setLong: "+t+", this.mem32.length: "+this.mem32.length);this.mem32[r]=e}getDouble(t){let e=Math.floor(t/8);if(8*e!=t)throw Error("getLong passed non Float64 aligned address");return this.memD[e]}setDouble(t,e){let r=Math.floor(t/8);if(8*r!=t)throw Error("setDouble passed non Float64 aligned address");this.memD[r]=e}getShort(t){if(t<0||t>=this.mem8.length)throw Error("invalid index passed to getShort: "+t);return this.mem8[t]+256*this.mem8[t+1]}getString(t,e){let r="",s=0;for(;this.mem8[t+s]&&(void 0===e||s=this.mem8.length)throw Error("invalid index passed to getU8: "+t);let e=new Uint32Array(this.mem8.slice(t,t+8).buffer),r=e[0],s=e[1];if(s<0||s>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU8");if(r<0||r>this.mem8.length-s)throw Error("invalid idx.size passed to getU8");return this.mem8.slice(s,s+r)}getU32Arr(t){if(t<0||t>=this.mem8.length)throw Error("invalid index passed to getU32: "+t);let e=new Uint32Array(this.mem8.slice(t,t+8).buffer),r=e[0],s=e[1];if(s<0||s>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU32");if(r<0||r>this.mem8.length-s)throw Error("invalid idx.size passed to getU32");if(r%4!=0)throw Error("idx.size is not an integer number of 32 bit words");return new Uint32Array(this.mem8.slice(s,s+r).buffer)}}class d{callCompleteSignal;parameters;constructor(t){this.callCompleteSignal=new o(t[0]),this.parameters=new Uint32Array(t[1])}sleep(t){this.callCompleteSignal.reset(),postMessage(["sleep",[t]]),this.callCompleteSignal.wait()}time(){return this.callCompleteSignal.reset(),postMessage(["time"]),this.callCompleteSignal.wait(),this.parameters[0]}}onmessage=function(t){if("startup"==t.data[0]){let e=t.data[1];(i=new f(e.modParams,e.modWorkerParams)).loadWasm(e.urlToLoad).then(()=>{postMessage(["startupOkay"])}).catch(t=>{console.log(".catch: ",t),postMessage(["startupFail",t])})}else"callC"==t.data[0]?i.callCImpl(t.data[1],t.data[2]).then(t=>{postMessage(["callCOkay",t])}).catch(t=>{console.log("exception in callC twrworker.js\n"),console.log(t),postMessage(["callCFail",t])}):console.log("twrworker.js: unknown message: "+t)};class f extends c{malloc;modParams;constructor(t,e){super(),this.isWorker=!0,this.malloc=t=>{throw Error("error - un-init malloc called")},this.modParams=t;let r=new n(e.canvasProxyParams,this),s=new l(e.divProxyParams),i=new d(e.waitingCallsProxyParams);this.modParams.imports={twrDebugLog:h,twrSleep:i.sleep.bind(i),twrTime:i.time.bind(i),twrDivCharOut:s.charOut.bind(s),twrDivCharIn:s.charIn.bind(s),twrCanvasCharIn:r.charIn.bind(r),twrCanvasInkey:r.inkey.bind(r),twrCanvasGetProp:r.getProp.bind(r),twrCanvasDrawSeq:r.drawSeq.bind(r),twrSin:Math.sin,twrCos:Math.cos,twrTan:Math.tan,twrFAbs:Math.abs,twrACos:Math.acos,twrASin:Math.asin,twrATan:Math.atan,twrExp:Math.exp,twrFloor:Math.floor,twrCeil:Math.ceil,twrFMod:function(t,e){return t%e},twrLog:Math.log,twrPow:Math.pow,twrSqrt:Math.sqrt,twrTrunc:Math.trunc,twrDtoa:this.floatUtil.dtoa.bind(this.floatUtil),twrToFixed:this.floatUtil.toFixed.bind(this.floatUtil),twrToExponential:this.floatUtil.toExponential.bind(this.floatUtil),twrAtod:this.floatUtil.atod.bind(this.floatUtil),twrFcvtS:this.floatUtil.fcvtS.bind(this.floatUtil)}}}})(); //# sourceMappingURL=twrmodworker.2165e649.js.map diff --git a/azure/examples/stdio-div/dist/twrmodworker.2165e649.js.map b/azure/examples/stdio-div/dist/twrmodworker.2165e649.js.map index 29a4d41e..77745e98 100644 --- a/azure/examples/stdio-div/dist/twrmodworker.2165e649.js.map +++ b/azure/examples/stdio-div/dist/twrmodworker.2165e649.js.map @@ -1 +1 @@ -{"mappings":"A,C,SQKK,EJgBA,EIhBA,EJgBA,MFZD,CISE,OAAO,EACZ,WAA8B,AAC9B,CAAA,GAAe,AAEf,aAAa,CAAqB,CAAlC,CACO,GAAI,AAAkB,aAAlB,OAAO,QACH,CAAC,qBAAuB,AAA+B,UAA7B,OAAO,QAAQ,CAAC,QAAQ,CAAe,MAAM,AAAI,MAAM,4DAA4D,oBAAoB,iCAErK,EAAI,IAAI,CAAC,WAAW,CAAC,EACpB,IAAI,CAAC,WAAW,CAAC,IAAI,kBAAkB,MAClD,IAAI,CAAC,GAAG,CAAC,IAAI,WAAW,IAAI,CAAC,WAAW,EAClC,IAAI,CAAC,GAAG,CArBJ,IAqBW,CAAC,EAChB,IAAI,CAAC,GAAG,CArBJ,IAqBW,CAAC,CACvB,CAEA,MAAM,CAAQ,CAAd,CACO,IAAI,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CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAChD,SAAU,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAE5C,CACN,CACF,C,C","sources":["","../../lib-js/twrmodworker.js","../../source/twr-wasm-ts/twrmodworker.ts","../../lib-js/twrcanvas.js","../../source/twr-wasm-ts/twrcanvas.ts","../../lib-js/twrcircular.js","../../source/twr-wasm-ts/twrcircular.ts","../../lib-js/twrsignal.js","../../source/twr-wasm-ts/twrsignal.ts","../../lib-js/twrdiv.js","../../source/twr-wasm-ts/twrdiv.ts","../../lib-js/twrdebug.js","../../source/twr-wasm-ts/twrdebug.ts","../../lib-js/twrmodbase.js","../../source/twr-wasm-ts/twrmodbase.ts","../../lib-js/twrfloat.js","../../source/twr-wasm-ts/twrfloat.ts","../../lib-js/twrwaitingcalls.js","../../source/twr-wasm-ts/twrwaitingcalls.ts","../../lib-js/twrdate.js","../../source/twr-wasm-ts/twrdate.ts"],"sourcesContent":["(() => {\nvar $3e39efa823870787$exports = {};\n// this script is the WebWorker thead used by class twrWasmAsyncModule\n//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst $892fccfc812d5e20$var$RDIDX = 256;\nconst $892fccfc812d5e20$var$WRIDX = 257;\nconst $892fccfc812d5e20$var$LEN = 256;\nclass $892fccfc812d5e20$export$a01cca24f011573a {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(1032);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[$892fccfc812d5e20$var$RDIDX] = 0;\n this.buf[$892fccfc812d5e20$var$WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[$892fccfc812d5e20$var$WRIDX];\n this.buf[i] = n;\n i++;\n if (i == $892fccfc812d5e20$var$LEN) i = 0;\n this.buf[$892fccfc812d5e20$var$WRIDX] = i;\n Atomics.notify(this.buf, $892fccfc812d5e20$var$WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[$892fccfc812d5e20$var$RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[$892fccfc812d5e20$var$RDIDX] = i;\n return n;\n } else return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[$892fccfc812d5e20$var$RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, $892fccfc812d5e20$var$WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[$892fccfc812d5e20$var$RDIDX] == this.buf[$892fccfc812d5e20$var$WRIDX];\n }\n}\n\n\n//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar $b93f1fdf40141def$var$twrSignalState;\n(function(twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})($b93f1fdf40141def$var$twrSignalState || ($b93f1fdf40141def$var$twrSignalState = {}));\nclass $b93f1fdf40141def$export$e37a7b7b851b97f3 {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == $b93f1fdf40141def$var$twrSignalState.WAITING) //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, $b93f1fdf40141def$var$twrSignalState.WAITING);\n }\n isSignaled() {\n return this.buf[0] == $b93f1fdf40141def$var$twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.WAITING;\n }\n}\n\n\nvar $c4741cac81d14197$var$D2DType;\n(function(D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})($c4741cac81d14197$var$D2DType || ($c4741cac81d14197$var$D2DType = {}));\nclass $c4741cac81d14197$export$2f298dd69cef3c34 {\n ctx;\n props = {\n charWidth: 0,\n charHeight: 0,\n foreColor: 0,\n backColor: 0,\n widthInChars: 0,\n heightInChars: 0,\n canvasHeight: 0,\n canvasWidth: 0\n };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase){\n const { forecolor: forecolor, backcolor: backcolor, fontsize: fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)();\n this.canvasKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.props,\n this.cmdCompleteSignal.sharedArray,\n this.canvasKeys.sharedArray\n ];\n }\n getProp(pn) {\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */ drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx) return;\n let ins = this.owner.getLong(ds); /* ds->start */ \n const lastins = this.owner.getLong(ds + 4); /* ds->last */ \n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while(true){\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */ \n switch(type){\n case $c4741cac81d14197$var$D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_BEGINPATH:\n this.ctx.beginPath();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILL:\n this.ctx.fill();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SAVE:\n this.ctx.save();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_RESTORE:\n this.ctx.restore();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_STROKE:\n this.ctx.stroke();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = this.owner.getLong(ins + 48) != 0;\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n } else this.precomputedObjects[id] = {\n mem8: new Uint8Array(this.owner.memory.buffer, start, length),\n width: width,\n height: height\n };\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id]) delete this.precomputedObjects[id];\n else console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n else {\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) this.ctx.putImageData(imgData, dx, dy);\n else this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */ \n if (next == 0) {\n if (ins != lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nclass $c4741cac81d14197$export$c779b2cd00544976 {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner){\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)(signalBuffer);\n this.canvasKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\n \"drawseq\",\n [\n ds\n ]\n ]);\n this.drawCompleteSignal.wait();\n }\n}\n\n\n\nclass $8963973702ae5462$export$dd376bb3f10f6896 {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611);\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase){\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) this.divKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(); // tsconfig, lib must be set to 2017 or higher\n if (this.div && !modParams.styleIsDefault) {\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.divKeys.sharedArray\n ];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */ charOut(ch) {\n if (!this.div) return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n }\n switch(ch){\n case 10:\n case 13:\n if (ch == 10 && this.lastChar == 13) break; // detect CR LF and treat as single new line\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n case 0xE:\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF:\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for(let i = 0; i < str.length; i++)this.charOut(str.charCodeAt(i));\n }\n}\nclass $8963973702ae5462$export$b377f0bbf2c7581e {\n divKeys;\n constructor(params){\n const [divKeysBuffer] = params;\n this.divKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n charOut(ch) {\n postMessage([\n \"divout\",\n ch\n ]);\n }\n}\n\n\nlet $8ac0b786da854328$var$logline = \"\";\nfunction $8ac0b786da854328$export$16b4216ec014493d(char) {\n if (char == 10 || char == 3) {\n console.log($8ac0b786da854328$var$logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n $8ac0b786da854328$var$logline = \"\";\n } else {\n $8ac0b786da854328$var$logline = $8ac0b786da854328$var$logline + String.fromCharCode(char);\n if ($8ac0b786da854328$var$logline.length >= 200) {\n console.log($8ac0b786da854328$var$logline);\n $8ac0b786da854328$var$logline = \"\";\n }\n }\n}\nfunction $8ac0b786da854328$export$485af4d0039b3389(ch) {\n postMessage([\n \"debug\",\n ch\n ]);\n}\n\n\nclass $e72303a1db04bdfa$export$918ffb7e046a537b {\n mod;\n constructor(mod){\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\") return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\") return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll(\"D\", \"e\").replaceAll(\"d\", \"e\"));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n } else {\n let r = value.toString();\n if (r.length > max_precision) r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, sizeInBytes, value, fracpart_numdigits, dec, sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1) return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) {\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (!Number.isFinite(value)) {\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n } else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split(\".\");\n if (intPart == \"0\") intPart = \"\";\n if (intPart.length > 0) {\n decpos = intPart.length;\n digits = intPart + fracPart;\n } else {\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length) return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */ }\n}\n\n\nclass $ece7fa3ed770778a$export$c83a0a3bffe07399 {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule;\n floatUtil;\n constructor(isWasmModule = false){\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new (0, $e72303a1db04bdfa$export$918ffb7e046a537b)(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/ /*********************************************************************/ async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n } catch (err) {\n console.log(\"loadWasm() failed to fetch: \" + pathToLoad);\n throw err;\n }\n if (!response.ok) throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, {\n env: allimports\n });\n this.exports = instance.instance.exports;\n if (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory) throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer) console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\n \"setmemory\",\n this.memory\n ]);\n }\n if (this.isWasmModule) // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n {\n if (!(this.memory.buffer instanceof ArrayBuffer)) console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size)=>{\n return new Promise((resolve)=>{\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n } catch (err) {\n console.log(\"WASM instantiate error: \" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch(this.modParams.stdio){\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* executeC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */ async executeC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.executeCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async executeCImpl(fname, cparams = []) {\n if (!this.exports) throw new Error(\"this.exports undefined\");\n if (!this.exports[fname]) throw new Error(\"executeC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array)) throw new Error(\"executeC: params must be array, first arg is function name\");\n if (params.length == 0) throw new Error(\"executeC: missing function name\");\n let cparams = [];\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n cparams[ci++] = p;\n break;\n case \"string\":\n cparams[ci++] = await this.putString(p);\n break;\n case \"object\":\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n } else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"executeC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n ci++;\n break;\n case \"string\":\n this.executeCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n case \"object\":\n if (p instanceof URL) {\n this.executeCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci = ci + 2;\n break;\n } else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for(let j = 0; j < u8.length; j++)u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.executeCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n } else throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/ /*********************************************************************/ // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for(i = 0; i < sin.length && i < buffer_size - 1; i++)this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for(let i = 0; i < u8a.length; i++)this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === \"object\" && fnin instanceof URL)) throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [\n dest,\n src.length\n ];\n } catch (err) {\n console.log(\"fetchAndPutURL Error. URL: \" + fnin + \"\\n\" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while(this.mem8[strIndex + i] && (len === undefined ? true : i < len) && strIndex + i < this.mem8.length){\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array(this.mem8.slice(dataptr, dataptr + size).buffer);\n return u32;\n }\n}\n\n\n\nfunction $4af5689abbc8d01b$export$78724cdcf7ebea1d() {\n return Date.now();\n}\n\n\nclass $aff9c2c494d23fe3$export$9e37856d1928d388 {\n callCompleteSignal;\n parameters;\n constructor(){\n this.callCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(()=>{\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = (0, $4af5689abbc8d01b$export$78724cdcf7ebea1d)();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [\n this.callCompleteSignal.sharedArray,\n this.parameters.buffer\n ];\n }\n processMessage(msgType, data) {\n switch(msgType){\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\nclass $aff9c2c494d23fe3$export$78d2a4633fe89379 {\n callCompleteSignal;\n parameters;\n constructor(params){\n this.callCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\n \"sleep\",\n [\n ms\n ]\n ]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\n \"time\"\n ]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n\n\nlet $3e39efa823870787$var$mod;\nonmessage = function(e) {\n //console.log('twrworker.js: message received from main script: '+e.data);\n if (e.data[0] == \"startup\") {\n const params = e.data[1];\n //console.log(\"Worker startup params:\",params);\n $3e39efa823870787$var$mod = new $3e39efa823870787$var$twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\n $3e39efa823870787$var$mod.loadWasm(params.urlToLoad).then(()=>{\n postMessage([\n \"startupOkay\"\n ]);\n }).catch((ex)=>{\n console.log(\".catch: \", ex);\n postMessage([\n \"startupFail\",\n ex\n ]);\n });\n } else if (e.data[0] == \"executeC\") $3e39efa823870787$var$mod.executeCImpl(e.data[1], e.data[2]).then((rc)=>{\n postMessage([\n \"executeCOkay\",\n rc\n ]);\n }).catch((e)=>{\n console.log(\"exception in executeC twrworker.js\\n\");\n console.log(e);\n postMessage([\n \"executeCFail\",\n e\n ]);\n });\n else console.log(\"twrworker.js: unknown message: \" + e);\n};\n// ************************************************************************\nclass $3e39efa823870787$var$twrWasmModuleInWorker extends (0, $ece7fa3ed770778a$export$c83a0a3bffe07399) {\n malloc;\n modParams;\n constructor(modParams, modInWorkerParams){\n super();\n this.isWorker = true;\n this.malloc = (size)=>{\n throw new Error(\"error - un-init malloc called\");\n };\n this.modParams = modParams;\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\n const canvasProxy = new (0, $c4741cac81d14197$export$c779b2cd00544976)(modInWorkerParams.canvasProxyParams, this);\n const divProxy = new (0, $8963973702ae5462$export$b377f0bbf2c7581e)(modInWorkerParams.divProxyParams);\n const waitingCallsProxy = new (0, $aff9c2c494d23fe3$export$78d2a4633fe89379)(modInWorkerParams.waitingCallsProxyParams);\n this.modParams.imports = {\n twrDebugLog: (0, $8ac0b786da854328$export$485af4d0039b3389),\n twrSleep: waitingCallsProxy.sleep.bind(waitingCallsProxy),\n twrTime: waitingCallsProxy.time.bind(waitingCallsProxy),\n twrDivCharOut: divProxy.charOut.bind(divProxy),\n twrDivCharIn: divProxy.charIn.bind(divProxy),\n twrCanvasCharIn: canvasProxy.charIn.bind(canvasProxy),\n twrCanvasInkey: canvasProxy.inkey.bind(canvasProxy),\n twrCanvasGetProp: canvasProxy.getProp.bind(canvasProxy),\n twrCanvasDrawSeq: canvasProxy.drawSeq.bind(canvasProxy),\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function(x, y) {\n return x % y;\n },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n}\n\n})();\n//# sourceMappingURL=twrmodworker.2165e649.js.map\n","// this script is the WebWorker thead used by class twrWasmAsyncModule\nimport { twrCanvasProxy } from \"./twrcanvas.js\";\nimport { twrDivProxy } from \"./twrdiv.js\";\nimport { twrDebugLogProxy } from \"./twrdebug.js\";\nimport { twrWasmModuleBase } from \"./twrmodbase.js\";\nimport { twrWaitingCallsProxy } from \"./twrwaitingcalls.js\";\nlet mod;\nonmessage = function (e) {\n //console.log('twrworker.js: message received from main script: '+e.data);\n if (e.data[0] == 'startup') {\n const params = e.data[1];\n //console.log(\"Worker startup params:\",params);\n mod = new twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\n mod.loadWasm(params.urlToLoad).then(() => {\n postMessage([\"startupOkay\"]);\n }).catch((ex) => {\n console.log(\".catch: \", ex);\n postMessage([\"startupFail\", ex]);\n });\n }\n else if (e.data[0] == 'executeC') {\n mod.executeCImpl(e.data[1], e.data[2]).then((rc) => {\n postMessage([\"executeCOkay\", rc]);\n }).catch(e => {\n console.log(\"exception in executeC twrworker.js\\n\");\n console.log(e);\n postMessage([\"executeCFail\", e]);\n });\n }\n else {\n console.log(\"twrworker.js: unknown message: \" + e);\n }\n};\n// ************************************************************************\nclass twrWasmModuleInWorker extends twrWasmModuleBase {\n malloc;\n modParams;\n constructor(modParams, modInWorkerParams) {\n super();\n this.isWorker = true;\n this.malloc = (size) => { throw new Error(\"error - un-init malloc called\"); };\n this.modParams = modParams;\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\n const canvasProxy = new twrCanvasProxy(modInWorkerParams.canvasProxyParams, this);\n const divProxy = new twrDivProxy(modInWorkerParams.divProxyParams);\n const waitingCallsProxy = new twrWaitingCallsProxy(modInWorkerParams.waitingCallsProxyParams);\n this.modParams.imports = {\n twrDebugLog: twrDebugLogProxy,\n twrSleep: waitingCallsProxy.sleep.bind(waitingCallsProxy),\n twrTime: waitingCallsProxy.time.bind(waitingCallsProxy),\n twrDivCharOut: divProxy.charOut.bind(divProxy),\n twrDivCharIn: divProxy.charIn.bind(divProxy),\n twrCanvasCharIn: canvasProxy.charIn.bind(canvasProxy),\n twrCanvasInkey: canvasProxy.inkey.bind(canvasProxy),\n twrCanvasGetProp: canvasProxy.getProp.bind(canvasProxy),\n twrCanvasDrawSeq: canvasProxy.drawSeq.bind(canvasProxy),\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function (x, y) { return x % y; },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n}\n//# sourceMappingURL=twrmodworker.js.map","// this script is the WebWorker thead used by class twrWasmAsyncModule\r\n\r\nimport {twrCanvasProxy} from \"./twrcanvas.js\";\r\nimport {twrDivProxy} from \"./twrdiv.js\";\r\nimport {twrDebugLogProxy} from \"./twrdebug.js\";\r\nimport {TAsyncModStartupMsg} from \"./twrmodasync.js\"\r\nimport {twrWasmModuleBase, IModInWorkerParams, IModParams} from \"./twrmodbase.js\"\r\nimport {twrWaitingCallsProxy} from \"./twrwaitingcalls.js\";\r\n\r\nlet mod:twrWasmModuleInWorker;\r\n\r\nonmessage = function(e) {\r\n //console.log('twrworker.js: message received from main script: '+e.data);\r\n\r\n if (e.data[0]=='startup') {\r\n const params:TAsyncModStartupMsg=e.data[1];\r\n //console.log(\"Worker startup params:\",params);\r\n mod=new twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\r\n\r\n mod.loadWasm(params.urlToLoad).then( ()=> {\r\n postMessage([\"startupOkay\"]);\r\n }).catch( (ex)=> {\r\n console.log(\".catch: \", ex);\r\n postMessage([\"startupFail\", ex]);\r\n });\r\n }\r\n else if (e.data[0]=='executeC') {\r\n mod.executeCImpl(e.data[1], e.data[2]).then( (rc)=> {\r\n postMessage([\"executeCOkay\", rc]);\r\n }).catch(e => {\r\n console.log(\"exception in executeC twrworker.js\\n\");\r\n console.log(e);\r\n postMessage([\"executeCFail\", e]);\r\n });\r\n }\r\n else {\r\n console.log(\"twrworker.js: unknown message: \"+e);\r\n }\r\n}\r\n\r\n\r\n// ************************************************************************\r\n\r\nclass twrWasmModuleInWorker extends twrWasmModuleBase {\r\n\tmalloc:(size:number)=>Promise;\r\n modParams: IModParams;\r\n\r\n\r\n constructor(modParams:IModParams, modInWorkerParams:IModInWorkerParams) {\r\n super();\r\n this.isWorker=true;\r\n this.malloc=(size:number)=>{throw new Error(\"error - un-init malloc called\")};\r\n this.modParams=modParams;\r\n\r\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\r\n const canvasProxy = new twrCanvasProxy(modInWorkerParams.canvasProxyParams, this);\r\n const divProxy = new twrDivProxy(modInWorkerParams.divProxyParams);\r\n const waitingCallsProxy = new twrWaitingCallsProxy(modInWorkerParams.waitingCallsProxyParams);\r\n\r\n this.modParams.imports={\r\n twrDebugLog:twrDebugLogProxy,\r\n twrSleep:waitingCallsProxy.sleep.bind(waitingCallsProxy),\r\n twrTime:waitingCallsProxy.time.bind(waitingCallsProxy),\r\n\r\n twrDivCharOut:divProxy.charOut.bind(divProxy), \r\n twrDivCharIn:divProxy.charIn.bind(divProxy), \r\n\r\n twrCanvasCharIn:canvasProxy.charIn.bind(canvasProxy),\r\n twrCanvasInkey:canvasProxy.inkey.bind(canvasProxy),\r\n twrCanvasGetProp:canvasProxy.getProp.bind(canvasProxy),\r\n twrCanvasDrawSeq:canvasProxy.drawSeq.bind(canvasProxy),\r\n\r\n\t\t\ttwrSin:Math.sin,\r\n\t\t\ttwrCos:Math.cos,\r\n\t\t\ttwrTan: Math.tan,\r\n\t\t\ttwrFAbs: Math.abs,\r\n\t\t\ttwrACos: Math.acos,\r\n\t\t\ttwrASin: Math.asin,\r\n\t\t\ttwrATan: Math.atan,\r\n\t\t\ttwrExp: Math.exp,\r\n\t\t\ttwrFloor: Math.floor,\r\n\t\t\ttwrCeil: Math.ceil,\r\n\t\t\ttwrFMod: function(x:number, y:number) {return x%y},\r\n\t\t\ttwrLog: Math.log,\r\n\t\t\ttwrPow: Math.pow,\r\n\t\t\ttwrSqrt: Math.sqrt,\r\n\t\t\ttwrTrunc: Math.trunc,\r\n\r\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\r\n\t\t\ttwrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\r\n\t\t\ttwrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\r\n\t\t\ttwrAtod: this.floatUtil.atod.bind(this.floatUtil),\r\n\t\t\ttwrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\r\n \r\n }\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nimport { twrSignal } from \"./twrsignal.js\";\nvar D2DType;\n(function (D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})(D2DType || (D2DType = {}));\nexport class twrCanvas {\n ctx;\n props = { charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight: 0, canvasWidth: 0 };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase) {\n const { forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new twrSignal();\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext)\n throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c)\n throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2)\n throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\n }\n getProp(pn) {\n if (!this.isValid())\n console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */\n drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid())\n console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx)\n return;\n let ins = this.owner.getLong(ds); /* ds->start */\n const lastins = this.owner.getLong(ds + 4); /* ds->last */\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while (1) {\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */\n if (0 /*type!=D2DType.D2D_FILLRECT*/) {\n console.log(\"ins\", ins);\n console.log(\"hdr.next\", this.owner.mem8[ins], this.owner.mem8[ins + 1], this.owner.mem8[ins + 2], this.owner.mem8[ins + 3]);\n console.log(\"hdr.type\", this.owner.mem8[ins + 4], this.owner.mem8[ins + 5]);\n console.log(\"next 4 bytes\", this.owner.mem8[ins + 6], this.owner.mem8[ins + 7], this.owner.mem8[ins + 8], this.owner.mem8[ins + 9]);\n console.log(\"and 4 more \", this.owner.mem8[ins + 10], this.owner.mem8[ins + 11], this.owner.mem8[ins + 12], this.owner.mem8[ins + 13]);\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\n }\n switch (type) {\n case D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case D2DType.D2D_BEGINPATH:\n {\n this.ctx.beginPath();\n }\n break;\n case D2DType.D2D_FILL:\n {\n this.ctx.fill();\n }\n break;\n case D2DType.D2D_SAVE:\n {\n this.ctx.save();\n }\n break;\n case D2DType.D2D_RESTORE:\n {\n this.ctx.restore();\n }\n break;\n case D2DType.D2D_STROKE:\n {\n this.ctx.stroke();\n }\n break;\n case D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = (this.owner.getLong(ins + 48) != 0);\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n }\n else { // Uint8ClampedArray doesn't support shared memory\n this.precomputedObjects[id] = { mem8: new Uint8Array(this.owner.memory.buffer, start, length), width: width, height: height };\n }\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id])\n delete this.precomputedObjects[id];\n else\n console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) {\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n }\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) {\n this.ctx.putImageData(imgData, dx, dy);\n }\n else {\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */\n if (next == 0) {\n if (ins != lastins)\n throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal)\n this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nexport class twrCanvasProxy {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner) {\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new twrSignal(signalBuffer);\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\"drawseq\", [ds]]);\n this.drawCompleteSignal.wait();\n }\n}\n//# sourceMappingURL=twrcanvas.js.map","import {twrWasmModuleBase, IModParams} from \"./twrmodbase.js\"\r\nimport {twrSharedCircularBuffer} from \"./twrcircular.js\";\r\nimport {twrSignal} from \"./twrsignal.js\";\r\n\r\n\r\n// Canvas have a size that will be set based on the character width x height\r\n// The display size for a canvas will default to this size, but can be changed in the HTML/JS via\r\n// canvas.style.width = \"700px\";\r\n// canvas.style.height = \"500px\";\r\n\r\nexport interface ICanvasProps {\r\n\tcharWidth: number,\r\n\tcharHeight: number,\r\n\tforeColor: number,\r\n\tbackColor: number,\r\n widthInChars: number,\r\n heightInChars: number,\r\n canvasWidth:number,\r\n canvasHeight:number\r\n}\r\n\r\nenum D2DType {\r\n D2D_FILLRECT=1,\r\n D2D_FILLCHAR=5,\r\n D2D_SETLINEWIDTH=10,\r\n D2D_SETFILLSTYLERGBA=11,\r\n D2D_SETFONT=12,\r\n D2D_BEGINPATH=13,\r\n D2D_MOVETO=14,\r\n D2D_LINETO=15,\r\n D2D_FILL=16,\r\n D2D_STROKE=17,\r\n D2D_SETSTROKESTYLERGBA=18,\r\n D2D_ARC=19,\r\n D2D_STROKERECT=20,\r\n D2D_FILLTEXT=21,\r\n D2D_IMAGEDATA=22,\r\n D2D_PUTIMAGEDATA=23,\r\n D2D_BEZIERTO=24,\r\n D2D_MEASURETEXT=25,\r\n D2D_SAVE=26,\r\n D2D_RESTORE=27,\r\n D2D_CREATERADIALGRADIENT=28,\r\n D2D_SETCOLORSTOP=29,\r\n D2D_SETFILLSTYLEGRADIENT=30,\r\n D2D_RELEASEID=31,\r\n D2D_CREATELINEARGRADIENT=32,\r\n D2D_SETFILLSTYLE=33,\r\n D2D_SETSTROKESTYLE=34\r\n\r\n}\r\n\r\nexport type TCanvasProxyParams = [ICanvasProps, SharedArrayBuffer, SharedArrayBuffer];\r\n\r\nexport interface ICanvas {\r\n props: ICanvasProps,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TCanvasProxyParams,\r\n drawSeq: (ds:number)=>void,\r\n }\r\n \r\nexport class twrCanvas implements ICanvas {\r\n ctx:CanvasRenderingContext2D|undefined;\r\n props:ICanvasProps={charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight:0, canvasWidth:0};\r\n owner: twrWasmModuleBase;\r\n cmdCompleteSignal?:twrSignal;\r\n canvasKeys?: twrSharedCircularBuffer;\r\n precomputedObjects: { [index: number]: \r\n (ImageData | {mem8:Uint8Array, width:number, height:number}) |\r\n CanvasGradient\r\n };\r\n\r\n constructor(element:HTMLCanvasElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n const {forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas} = modParams; \r\n this.owner=modbase;\r\n this.props.widthInChars=modParams.windim[0];\r\n this.props.heightInChars=modParams.windim[1];\r\n\r\n if (!this.owner.isWasmModule) {\r\n this.cmdCompleteSignal=new twrSignal();\r\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n }\r\n\r\n this.precomputedObjects={};\r\n \r\n if (element) {\r\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\r\n let c=element.getContext(\"2d\");\r\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\r\n\r\n c.font = fontsize.toString()+\"px Courier New\";\r\n c.textBaseline=\"top\";\r\n const sampleText=\" \";\r\n const tm=c.measureText(sampleText);\r\n this.props.charWidth=Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\r\n let fM = c.measureText(\"X\"); \r\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\r\n\r\n if (!isd2dcanvas) {\r\n element.width=this.props.charWidth*this.props.widthInChars;\r\n element.height=this.props.charHeight*this.props.heightInChars;\r\n }\r\n\r\n this.props.canvasHeight=element.height;\r\n this.props.canvasWidth=element.width;\r\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\r\n\r\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\r\n let c2=element.getContext(\"2d\");\r\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\r\n this.ctx=c2;\r\n this.ctx.font = fontsize.toString()+\"px Courier New\";\r\n this.ctx.textBaseline=\"top\";\r\n\r\n c2.fillStyle=backcolor;\r\n this.props.backColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n c2.fillStyle=forecolor;\r\n this.props.foreColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n }\r\n\r\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\r\n\r\n //console.log(\"twrCanvas.constructor props: \", this.props);\r\n }\r\n\r\n isValid() {\r\n return !!this.ctx;\r\n }\r\n\r\n getProxyParams() : TCanvasProxyParams {\r\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\r\n }\r\n\r\n getProp(pn:number): number {\r\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n\r\n/* see draw2d.h for structs that match */\r\n\r\n drawSeq(ds:number) {\r\n //console.log(\"twr::Canvas enter drawSeq\");\r\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\r\n if (!this.ctx) return;\r\n\r\n let ins=this.owner.getLong(ds); /* ds->start */\r\n const lastins=this.owner.getLong(ds+4); /* ds->last */\r\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\r\n\r\n let next:number;\r\n //let insCount=0;\r\n\r\n while (1) {\r\n\r\n //insCount++;\r\n\r\n const type:D2DType=this.owner.getLong(ins+4); /* hdr->type */\r\n if (0/*type!=D2DType.D2D_FILLRECT*/) {\r\n console.log(\"ins\",ins)\r\n console.log(\"hdr.next\",this.owner.mem8[ins],this.owner.mem8[ins+1],this.owner.mem8[ins+2],this.owner.mem8[ins+3]);\r\n console.log(\"hdr.type\",this.owner.mem8[ins+4],this.owner.mem8[ins+5]);\r\n console.log(\"next 4 bytes\", this.owner.mem8[ins+6],this.owner.mem8[ins+7],this.owner.mem8[ins+8],this.owner.mem8[ins+9]);\r\n console.log(\"and 4 more \", this.owner.mem8[ins+10],this.owner.mem8[ins+11],this.owner.mem8[ins+12],this.owner.mem8[ins+13]);\r\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\r\n }\r\n switch (type) {\r\n case D2DType.D2D_FILLRECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.fillRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKERECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.strokeRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILLCHAR:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const c=this.owner.getShort(ins+24);\r\n let txt=String.fromCharCode(c);\r\n this.ctx.fillText(txt, x, y);\r\n }\r\n break;\r\n\r\n \r\n case D2DType.D2D_FILLTEXT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const str=this.owner.getString(this.owner.getLong(ins+24));\r\n\r\n //console.log(\"filltext \",x,y,str)\r\n \r\n this.ctx.fillText(str, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MEASURETEXT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n const tmidx=this.owner.getLong(ins+12);\r\n \r\n const tm=this.ctx.measureText(str);\r\n this.owner.setDouble(tmidx+0, tm.actualBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+8, tm.actualBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+16, tm.actualBoundingBoxLeft);\r\n this.owner.setDouble(tmidx+24, tm.actualBoundingBoxRight);\r\n this.owner.setDouble(tmidx+32, tm.fontBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+40, tm.fontBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+48, tm.width);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFONT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.font=str;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.fillStyle = cssColor;\r\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETSTROKESTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.fillStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETSTROKESTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETLINEWIDTH:\r\n {\r\n const width=this.owner.getShort(ins+8); \r\n this.ctx.lineWidth=width;\r\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MOVETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.moveTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_LINETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.lineTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEZIERTO:\r\n {\r\n const cp1x=this.owner.getDouble(ins+8);\r\n const cp1y=this.owner.getDouble(ins+16);\r\n const cp2x=this.owner.getDouble(ins+24);\r\n const cp2y=this.owner.getDouble(ins+32);\r\n const x=this.owner.getDouble(ins+40);\r\n const y=this.owner.getDouble(ins+48);\r\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEGINPATH:\r\n {\r\n this.ctx.beginPath();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILL:\r\n {\r\n this.ctx.fill();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SAVE:\r\n {\r\n this.ctx.save();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_RESTORE:\r\n {\r\n this.ctx.restore();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKE:\r\n {\r\n this.ctx.stroke();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_ARC:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const radius=this.owner.getDouble(ins+24);\r\n const startAngle=this.owner.getDouble(ins+32);\r\n const endAngle=this.owner.getDouble(ins+40);\r\n const counterClockwise= (this.owner.getLong(ins+48)!=0);\r\n\r\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_IMAGEDATA:\r\n {\r\n const start=this.owner.getLong(ins+8);\r\n const length=this.owner.getLong(ins+12);\r\n const width=this.owner.getLong(ins+16);\r\n const height=this.owner.getLong(ins+20);\r\n const id=this.owner.getLong(ins+24);\r\n\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\r\n\r\n if (this.owner.isWasmModule) {\r\n const z = new Uint8ClampedArray(this.owner.memory!.buffer, start, length);\r\n this.precomputedObjects[id]=new ImageData(z, width, height);\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory\r\n this.precomputedObjects[id]={mem8: new Uint8Array(this.owner.memory!.buffer, start, length), width:width, height:height};\r\n }\r\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_CREATERADIALGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const radius0=this.owner.getDouble(ins+24);\r\n const x1=this.owner.getDouble(ins+32);\r\n const y1=this.owner.getDouble(ins+40);\r\n const radius1=this.owner.getDouble(ins+48);\r\n const id= this.owner.getLong(ins+56);\r\n\r\n let gradient=this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_CREATELINEARGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const x1=this.owner.getDouble(ins+24);\r\n const y1=this.owner.getDouble(ins+32);\r\n const id= this.owner.getLong(ins+40);\r\n \r\n let gradient=this.ctx.createLinearGradient(x0, y0, x1, y1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETCOLORSTOP:\r\n {\r\n const id = this.owner.getLong(ins+8);\r\n const pos=this.owner.getLong(ins+12);\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+16));\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n gradient.addColorStop(pos, cssColor);\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n this.ctx.fillStyle=gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_RELEASEID:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (this.precomputedObjects[id])\r\n delete this.precomputedObjects[id];\r\n else\r\n console.log(\"warning: D2D_RELEASEID with undefined ID \",id);\r\n }\r\n break\r\n\r\n \r\n\r\n case D2DType.D2D_PUTIMAGEDATA:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n const dx=this.owner.getLong(ins+12);\r\n const dy=this.owner.getLong(ins+16);\r\n const dirtyX=this.owner.getLong(ins+20);\r\n const dirtyY=this.owner.getLong(ins+24);\r\n const dirtyWidth=this.owner.getLong(ins+28);\r\n const dirtyHeight=this.owner.getLong(ins+32);\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \"+id);\r\n\r\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\r\n\r\n let imgData:ImageData;\r\n if (this.owner.isWasmModule) {\r\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\r\n imgData=this.precomputedObjects[id] as ImageData;\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\r\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\r\n const z = this.precomputedObjects[id] as {mem8:Uint8Array, width:number, height:number}; // Uint8Array\r\n const ca=Uint8ClampedArray.from(z.mem8); // shallow copy\r\n imgData=new ImageData(ca, z.width, z.height);\r\n }\r\n \r\n if (dirtyWidth==0 && dirtyHeight==0) {\r\n this.ctx.putImageData(imgData, dx, dy);\r\n }\r\n else {\r\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\r\n }\r\n }\r\n break;\r\n\r\n default:\r\n throw new Error (\"unimplemented or unknown Sequence Type in drawSeq: \"+type);\r\n }\r\n next=this.owner.getLong(ins); /* hdr->next */\r\n if (next==0) {\r\n if (ins!=lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\r\n break;\r\n }\r\n ins=next;\r\n }\r\n\r\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\r\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\r\n }\r\n}\r\n\r\nexport class twrCanvasProxy implements ICanvas {\r\n canvasKeys: twrSharedCircularBuffer;\r\n drawCompleteSignal:twrSignal;\r\n props: ICanvasProps;\r\n owner: twrWasmModuleBase;\r\n\r\n constructor(params:TCanvasProxyParams, owner:twrWasmModuleBase) {\r\n const [props, signalBuffer, canvasKeysBuffer] = params;\r\n this.drawCompleteSignal = new twrSignal(signalBuffer);\r\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\r\n this.props=props;\r\n this.owner=owner;\r\n\r\n //console.log(\"Create New twrCanvasProxy: \",this.props)\r\n\r\n }\r\n\r\n charIn() { \r\n //ctx.commit(); not avail in chrome\r\n \r\n //postMessage([\"debug\", 'x']);\r\n \r\n return this.canvasKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.canvasKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n getProp(pn:number): number {\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n \r\n drawSeq(ds:number) {\r\n this.drawCompleteSignal.reset();\r\n postMessage([\"drawseq\", [ds]]);\r\n this.drawCompleteSignal.wait();\r\n }\r\n}\r\n","//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst RDIDX = 256;\nconst WRIDX = 257;\nconst LEN = 256;\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\n// the first 256 array entries are the circular buffer\n// the next two are used for the read and write index\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\nexport class twrSharedCircularBuffer {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(258 * 4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[RDIDX] = 0;\n this.buf[WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[WRIDX];\n this.buf[i] = n;\n i++;\n if (i == LEN)\n i = 0;\n this.buf[WRIDX] = i;\n Atomics.notify(this.buf, WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[RDIDX] = i;\n return n;\n }\n else\n return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[RDIDX] == this.buf[WRIDX];\n }\n}\n//# sourceMappingURL=twrcircular.js.map","//\r\n// This class implements a circular buffer that the main javascript thread can write to, \r\n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\r\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \r\n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\r\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\r\n//\r\n\r\nconst RDIDX=256;\r\nconst WRIDX=257;\r\nconst LEN=256;\r\n\r\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\r\n// the first 256 array entries are the circular buffer\r\n// the next two are used for the read and write index\r\n\r\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\r\n\r\nexport class twrSharedCircularBuffer {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n \r\n\tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(258*4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[RDIDX]=0;\r\n this.buf[WRIDX]=0;\r\n\t}\r\n\r\n\twrite(n:number) {\r\n let i=this.buf[WRIDX];\r\n this.buf[i]=n;\r\n i++;\r\n if (i==LEN) i=0;\r\n this.buf[WRIDX]=i; \r\n Atomics.notify(this.buf, WRIDX); \r\n\t}\r\n\r\n\tread():number {\r\n if (!this.isEmpty()) {\r\n let i=this.buf[RDIDX];\r\n let n=this.buf[i];\r\n i++;\r\n this.buf[RDIDX]=i;\r\n return n;\r\n }\r\n\t\telse\r\n return -1;\r\n\t}\r\n\r\n readWait():number {\r\n if (this.isEmpty()) {\r\n const rdptr=this.buf[RDIDX];\r\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\r\n Atomics.wait(this.buf, WRIDX, rdptr);\r\n }\r\n return this.read();\r\n\t}\r\n\r\n isEmpty():boolean {\r\n return this.buf[RDIDX]==this.buf[WRIDX];\r\n }\r\n}\r\n","//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar twrSignalState;\n(function (twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})(twrSignalState || (twrSignalState = {}));\n;\nexport class twrSignal {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window valid\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == twrSignalState.WAITING) {\n //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\n //console.log(\"released...\");\n }\n }\n isSignaled() {\n return this.buf[0] == twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = twrSignalState.WAITING;\n }\n}\n//# sourceMappingURL=twrsignal.js.map","//\r\n// This class implements a simple signal/wait mechanism\r\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\r\n//\r\n\r\nenum twrSignalState {\r\n WAITING=0,\r\n SIGNALED=1\r\n};\r\n\r\nexport class twrSignal {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n\r\n \tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window valid\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) \r\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[0]=twrSignalState.WAITING;\r\n\t}\r\n\r\n\tsignal() {\r\n this.buf[0]=twrSignalState.SIGNALED; \r\n //console.log(\"about to signal\");\r\n Atomics.notify(this.buf, 0); \r\n\t}\r\n\r\n wait() {\r\n if (this.buf[0]==twrSignalState.WAITING) {\r\n //console.log(\"waiting...\");\r\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\r\n //console.log(\"released...\");\r\n\r\n }\r\n\t}\r\n isSignaled():boolean {\r\n return this.buf[0]==twrSignalState.SIGNALED;\r\n }\r\n\r\n reset() {\r\n this.buf[0]=twrSignalState.WAITING;\r\n }\r\n}\r\n","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nexport class twrDiv {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase) {\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\n this.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n if (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.divKeys.sharedArray];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */\n charOut(ch) {\n if (!this.div)\n return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n }\n switch (ch) {\n case 10: // newline\n case 13: // return\n if (ch == 10 && this.lastChar == 13)\n break; // detect CR LF and treat as single new line\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8: // backspace\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n case 0xE: // cursor on\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF: // cursor off\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for (let i = 0; i < str.length; i++)\n this.charOut(str.charCodeAt(i));\n }\n}\nexport class twrDivProxy {\n divKeys;\n constructor(params) {\n const [divKeysBuffer] = params;\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n charOut(ch) {\n postMessage([\"divout\", ch]);\n }\n}\n//# sourceMappingURL=twrdiv.js.map","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\r\nimport { IModParams } from \"./twrmodbase.js\";\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\";\r\n\r\nexport type TDivProxyParams = [SharedArrayBuffer];\r\n\r\nexport interface IDiv {\r\n charOut: (ds:number)=>void,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TDivProxyParams,\r\n }\r\n\r\n\r\nexport class twrDiv implements IDiv {\r\n\tdiv:HTMLDivElement|null|undefined;\r\n\tdivKeys?:twrSharedCircularBuffer;\r\n\tCURSOR=String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\r\n\tcursorOn:boolean=false;\r\n\tlastChar:number=0;\r\n\textraBR:boolean=false;\r\n\towner:twrWasmModuleBase;\r\n\r\n constructor(element:HTMLDivElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n\t\tthis.div=element;\r\n\t\tthis.owner=modbase;\r\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\r\n\t\t\tthis.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n\t\t}\r\n\r\n\t\tif (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\r\n\t\t\tthis.div.style.backgroundColor = modParams.backcolor;\r\n\t\t\tthis.div.style.color = modParams.forecolor;\r\n\t\t\tthis.div.style.font=modParams.fontsize.toString()+\"px arial\"\r\n\t\t}\r\n }\r\n\r\n\tisValid() {\r\n\t\treturn !!this.div;\r\n\t}\r\n\r\n getProxyParams() : TDivProxyParams {\r\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [ this.divKeys.sharedArray];\r\n }\r\n\r\n\r\n/* \r\n * add character to div. Supports the following control codes:\r\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\r\n * 0xE cursor on \r\n * 0x8 backspace\r\n * 0xF cursor off \r\n*/\r\n\tcharOut(ch:number) {\r\n\r\n\t\tif (!this.div) return;\r\n\r\n\t\t//console.log(\"div::charout: \", ch);\r\n\r\n\t\tif (this.extraBR) {\r\n\t\t\tthis.extraBR=false;\r\n\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -4);\r\n\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t}\r\n\r\n\t\tswitch (ch) {\r\n\t\t\tcase 10: // newline\r\n\t\t\tcase 13: // return\r\n\t\t\t\tif (ch==10 && this.lastChar==13) break; // detect CR LF and treat as single new line\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\r\n\t\t\t\tthis.extraBR=true;\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\t//element.scrollIntoView();\r\n\t\t\t\t//element.scrollTop = element.scrollHeight;\r\n\t\t\t\tlet p = this.div.getBoundingClientRect();\r\n\t\t\t\twindow.scrollTo(0, p.height+100);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 8: // backspace\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xE: // cursor on\r\n\t\t\t\tif (!this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=true;\r\n\t\t\t\t\tthis.div.innerHTML += this.CURSOR;\r\n\t\t\t\t\tthis.div.focus();\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xF: // cursor off\r\n\t\t\t\tif (this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=false;\r\n\t\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += String.fromCharCode(ch);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\tthis.lastChar=ch;\r\n\t}\r\n\r\n\tstringOut(str:string) {\r\n\t\tfor (let i=0; i < str.length; i++)\r\n\t\t\tthis.charOut(str.charCodeAt(i));\r\n\t}\r\n}\r\n\r\n\r\nexport class twrDivProxy implements IDiv {\r\n divKeys: twrSharedCircularBuffer;\r\n\r\n constructor(params:TDivProxyParams) {\r\n const [divKeysBuffer] = params;\r\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\r\n }\r\n\r\n charIn() { \r\n return this.divKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.divKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n\tcharOut(ch:number) {\r\n\t\tpostMessage([\"divout\", ch]);\r\n\t}\r\n}\r\n\r\n","let logline = \"\";\nexport function twrDebugLogImpl(char) {\n if (char == 10 || char == 3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\n console.log(logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n logline = \"\";\n }\n else {\n logline = logline + String.fromCharCode(char);\n if (logline.length >= 200) {\n console.log(logline);\n logline = \"\";\n }\n }\n}\n// ************************************************************************\n// debugLog doesn't currently wait for the message to log, it returns immediately.\n// I could move this to be in the twrWaitingCalls class\nexport function twrDebugLogProxy(ch) {\n postMessage([\"debug\", ch]);\n}\n//# sourceMappingURL=twrdebug.js.map","\r\nlet logline=\"\";\r\nexport function twrDebugLogImpl(char:number) {\r\n\tif (char==10 || char==3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\r\n\t\tconsole.log(logline);\t// ideally without a linefeed, but there is no way to not have a LF with console.log API.\r\n\t\tlogline=\"\";\r\n\t}\r\n\telse {\r\n\t\tlogline=logline+String.fromCharCode(char);\r\n\t\tif (logline.length>=200) {\r\n\t\t\tconsole.log(logline);\r\n\t\t\tlogline=\"\";\r\n\t\t}\r\n\t}\r\n}\r\n\r\n// ************************************************************************\r\n// debugLog doesn't currently wait for the message to log, it returns immediately.\r\n// I could move this to be in the twrWaitingCalls class\r\nexport function twrDebugLogProxy(ch:number) {\r\n postMessage([\"debug\", ch]);\r\n}\r\n\r\n","import { twrFloatUtil } from \"./twrfloat.js\";\n/*********************************************************************/\n/*********************************************************************/\n/*********************************************************************/\nexport class twrWasmModuleBase {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\n floatUtil;\n constructor(isWasmModule = false) {\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new twrFloatUtil(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/\n /*********************************************************************/\n async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n }\n catch (err) {\n console.log('loadWasm() failed to fetch: ' + pathToLoad);\n throw err;\n }\n if (!response.ok)\n throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, { env: allimports });\n this.exports = instance.instance.exports;\n if (!this.exports)\n throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory)\n throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory)\n throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer)\n console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\"setmemory\", this.memory]);\n }\n if (this.isWasmModule) {\n // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (!(this.memory.buffer instanceof ArrayBuffer))\n console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size) => {\n return new Promise(resolve => {\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n }\n catch (err) {\n console.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch (this.modParams.stdio) {\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* executeC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */\n async executeC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.executeCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async executeCImpl(fname, cparams = []) {\n if (!this.exports)\n throw new Error(\"this.exports undefined\");\n if (!this.exports[fname])\n throw new Error(\"executeC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array))\n throw new Error(\"executeC: params must be array, first arg is function name\");\n if (params.length == 0)\n throw new Error(\"executeC: missing function name\");\n let cparams = [];\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n cparams[ci++] = p;\n break;\n case 'string':\n cparams[ci++] = await this.putString(p);\n break;\n case 'object':\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n }\n else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"executeC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n ci++;\n break;\n case 'string':\n this.executeCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n case 'object':\n if (p instanceof URL) {\n this.executeCImpl('twr_free', [cparams[ci]]);\n ci = ci + 2;\n break;\n }\n else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for (let j = 0; j < u8.length; j++)\n u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.executeCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n }\n else\n throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/\n /*********************************************************************/\n // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for (i = 0; i < sin.length && i < buffer_size - 1; i++)\n this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for (let i = 0; i < u8a.length; i++)\n this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === 'object' && fnin instanceof URL))\n throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [dest, src.length];\n }\n catch (err) {\n console.log('fetchAndPutURL Error. URL: ' + fnin + '\\n' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while (this.mem8[strIndex + i] && (len === undefined ? true : i < len) && (strIndex + i) < this.mem8.length) {\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0)\n throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array((this.mem8.slice(dataptr, dataptr + size)).buffer);\n return u32;\n }\n}\n//# sourceMappingURL=twrmodbase.js.map","\r\nimport {TCanvasProxyParams} from \"./twrcanvas.js\"\r\nimport {TDivProxyParams} from \"./twrdiv.js\";\r\nimport {TWaitingCallsProxyParams} from \"./twrwaitingcalls.js\"\r\nimport {twrDebugLogImpl} from \"./twrdebug.js\";\r\nimport {twrFloatUtil} from \"./twrfloat.js\";\r\n\r\n\r\nexport type TStdioVals=\"div\"|\"canvas\"|\"null\"|\"debug\";\r\n\r\nexport interface IModOpts {\r\n\tstdio?:TStdioVals, \r\n\twindim?:[number, number],\r\n\tforecolor?:string,\r\n\tbackcolor?:string,\r\n\tfontsize?:number,\r\n\tisd2dcanvas?:boolean,\r\n\timports?:{},\r\n}\r\n\r\nexport interface IModParams {\r\n\tstdio:TStdioVals, \r\n\twindim:[number, number],\r\n\tforecolor:string,\r\n\tbackcolor:string,\r\n\tfontsize:number,\r\n\tstyleIsDefault: boolean\r\n\tisd2dcanvas:boolean,\r\n\timports:{[index:string]:Function},\r\n}\r\n\r\nexport interface IModInWorkerParams {\r\n\tdivProxyParams:TDivProxyParams,\r\n\tcanvasProxyParams:TCanvasProxyParams,\r\n\twaitingCallsProxyParams:TWaitingCallsProxyParams,\r\n}\r\n\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n\r\nexport abstract class twrWasmModuleBase {\r\n\tmemory?:WebAssembly.Memory;\r\n\tmem8:Uint8Array;\r\n\tmem32:Uint32Array;\r\n\tmemD:Float64Array;\r\n\tabstract malloc:(size:number)=>Promise;\r\n\tabstract modParams:IModParams;\r\n\texports?:WebAssembly.Exports;\r\n\tisWorker=false;\r\n\tisWasmModule:boolean; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\r\n\tfloatUtil:twrFloatUtil;\r\n\r\n\tconstructor(isWasmModule=false) {\r\n\t\tthis.isWasmModule=isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\r\n\t\tthis.mem8=new Uint8Array(); \t// avoid type errors\r\n\t\tthis.mem32=new Uint32Array(); // avoid type errors\r\n\t\tthis.memD=new Float64Array(); // avoid type errors\r\n\t\tthis.floatUtil=new twrFloatUtil(this);\r\n\t\t//console.log(\"size of mem8 after constructor\",this.mem8.length);\r\n\t}\r\n\r\n\t/*********************************************************************/\r\n\t/*********************************************************************/\r\n\r\n\tasync loadWasm(pathToLoad:string) {\r\n\t\t//console.log(\"fileToLoad\",fileToLoad)\r\n\r\n\t\tlet response;\r\n\t\ttry {\r\n\t\t\tresponse=await fetch(pathToLoad);\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('loadWasm() failed to fetch: '+pathToLoad);\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t\t\r\n\t\tif (!response.ok) throw new Error(\"fetch response error on file '\"+pathToLoad+\"'\\n\"+response.statusText);\r\n\r\n\t\ttry {\r\n\t\t\tlet wasmBytes = await response.arrayBuffer();\r\n\r\n\t\t\tlet allimports:WebAssembly.ModuleImports = { \r\n\t\t\t\t...this.modParams.imports\r\n\t\t\t};\r\n\r\n\t\t\tlet instance = await WebAssembly.instantiate(wasmBytes, {env: allimports});\r\n\r\n\t\t\tthis.exports=instance.instance.exports;\r\n\t\t\tif (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\r\n\r\n\t\t\tif (this.memory) throw new Error (\"unexpected error -- this.memory already set\");\r\n\t\t\tthis.memory=this.exports.memory as WebAssembly.Memory;\r\n\t\t\tif (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\r\n\t\t\tthis.mem8 = new Uint8Array(this.memory.buffer);\r\n\t\t\tthis.mem32 = new Uint32Array(this.memory.buffer);\r\n\t\t\tthis.memD = new Float64Array(this.memory.buffer);\r\n\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\tif (this.isWorker) {\r\n\t\t\t\tif (this.memory.buffer instanceof ArrayBuffer)\r\n\t\t\t\t\tconsole.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\r\n\t\t\t\t\r\n\t\t\t\tpostMessage([\"setmemory\",this.memory]);\r\n\t\t\t}\r\n\t\t\tif (this.isWasmModule) {\r\n\t\t\t\t// here if twrWasmModule, twrWasmModuleAsync overrides this function\r\n\t\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\t\tif (!(this.memory.buffer instanceof ArrayBuffer))\r\n\t\t\t\t\tconsole.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\r\n\t\t\t}\r\n\r\n\t\t\tthis.malloc=(size:number)=>{\r\n\t\t\t\treturn new Promise(resolve => {\r\n\t\t\t\t\tconst m=this.exports!.twr_malloc as (size:number)=>number;\r\n\t\t\t\t\tresolve(m(size));\r\n\t\t\t\t});\r\n\t\t };\r\n\r\n\t\t\tthis.init();\r\n\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t}\r\n\r\n\tprivate init() {\r\n\t\t//console.log(\"loadWasm.init() enter\")\r\n\t\t\tlet p:number;\r\n\t\t\tswitch (this.modParams.stdio) {\r\n\t\t\t\tcase \"debug\":\r\n\t\t\t\t\tp=0;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"div\":\r\n\t\t\t\t\tp=1;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"canvas\":\r\n\t\t\t\t\tp=2;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"null\":\r\n\t\t\t\t\tp=3;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tp=0; // debug\r\n\t\t\t}\r\n\r\n\t\t\tconst twrInit=this.exports!.twr_wasm_init as CallableFunction;\r\n\t\t\t//console.log(\"twrInit:\",twrInit)\r\n\t\t\ttwrInit(p, this.mem8.length);\r\n\t}\r\n\r\n\t/* executeC takes an array where:\r\n\t* the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\r\n\t* and the next entries are a variable number of parameters to pass to the C function, of type\r\n\t* number - converted to int32 or float64 as appropriate\r\n\t* string - converted to a an index (ptr) into a module Memory returned via stringToMem()\r\n\t* URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\r\n\t* Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\r\n */\r\n\r\n\tasync executeC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\t\tconst cparams=await this.preCallC(params);\r\n\t\tlet retval = this.executeCImpl(params[0], cparams);\r\n\t\tthis.postCallC(cparams, params);\r\n\t\treturn retval;\r\n\t}\r\n\r\n\tasync executeCImpl(fname:string, cparams:number[]=[]) {\r\n\t\tif (!this.exports) throw new Error(\"this.exports undefined\");\r\n\t\tif (!this.exports[fname]) throw new Error(\"executeC: function '\"+fname+\"' not in export table. Use --export wasm-ld flag.\");\r\n\r\n\t\tconst f = this.exports[fname] as CallableFunction;\r\n\t\tlet cr=f(...cparams);\r\n\r\n\t\treturn cr;\r\n\t}\r\n\r\n\t// convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\r\n\tasync preCallC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tif (!(params.constructor === Array)) throw new Error (\"executeC: params must be array, first arg is function name\");\r\n\t\tif (params.length==0) throw new Error(\"executeC: missing function name\");\r\n\r\n\t\tlet cparams:number[]=[];\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tcparams[ci++]=p;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tcparams[ci++]=await this.putString(p);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tconst r=await this.fetchAndPutURL(p);\r\n\t\t\t\t\t\tcparams[ci++]=r[0]; // mem index\r\n\t\t\t\t\t\tcparams[ci++]=r[1]; // len\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tconst r=await this.putArrayBuffer(p);\r\n\t\t\t\t\t\tcparams[ci++]=r; // mem index\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tthrow new Error (\"executeC: invalid object type passed in\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn cparams;\r\n\t}\r\n\r\n\t// free the mallocs; copy array buffer data from malloc back to arraybuffer\r\n\tasync postCallC(cparams:number[], params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tthis.executeCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t\t\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tthis.executeCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\t\tci=ci+2;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tlet u8=new Uint8Array(p);\r\n\t\t\t\t\t\tfor (let j=0; j= this.mem32.length) throw new Error(\"invalid index passed to getLong: \"+idx+\", this.mem32.length: \"+this.mem32.length);\r\n\t\tconst long:number = this.mem32[idx32];\r\n\t\treturn long;\r\n\t}\r\n\t\r\n\tsetLong(idx:number, value:number) {\r\n const idx32 = Math.floor(idx / 4);\r\n if (idx32 * 4 != idx)\r\n throw new Error(\"setLong passed non long aligned address\");\r\n if (idx32 < 0 || idx32 >= this.mem32.length)\r\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\r\n this.mem32[idx32]=value;\r\n }\r\n\r\n\tgetDouble(idx:number): number {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"getLong passed non Float64 aligned address\")\r\n\t\tconst long:number = this.memD[idx64];\r\n\t\treturn long;\r\n\t}\r\n\r\n\tsetDouble(idx:number, value:number) {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"setDouble passed non Float64 aligned address\")\r\n\t\tthis.memD[idx64]=value;\r\n\t}\r\n\r\n\tgetShort(idx:number): number {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getShort: \"+idx);\r\n\t\tconst short:number = this.mem8[idx]+this.mem8[idx+1]*256;\r\n\t\treturn short;\r\n\t}\r\n\r\n\t// get a string out of module memory\r\n\t// null terminated, up until max of (optional) len\r\n\tgetString(strIndex:number, len?:number): string {\r\n\t\tlet sout=\"\";\r\n\r\n\t\tlet i=0;\r\n\t\twhile (this.mem8[strIndex+i] && (len===undefined?true:i= this.mem8.length) throw new Error(\"invalid index passed to getU8: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU8\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU8\")\r\n\r\n\t\tconst u8=this.mem8.slice(dataptr, dataptr+size);\r\n\t\treturn u8;\r\n\t}\r\n\r\n\t// get a int32 array out of module memory when passed in index to [size, dataptr]\r\n\tgetU32Arr(idx:number): Uint32Array {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getU32: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU32\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU32\")\r\n\r\n\t\tif (size%4!=0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\r\n\r\n\t\tconst u32 = new Uint32Array( (this.mem8.slice(dataptr, dataptr+size)).buffer );\r\n\t\treturn u32;\r\n\t}\r\n}\r\n","export class twrFloatUtil {\n mod;\n constructor(mod) {\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\")\n return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\")\n return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll('D', 'e').replaceAll('d', 'e'));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n }\n else {\n let r = value.toString();\n if (r.length > max_precision)\n r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, // char *\n sizeInBytes, //size_t\n value, // double\n fracpart_numdigits, //int\n dec, // int *\n sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1)\n return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) { /* nan */\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (!Number.isFinite(value)) { /* infinity */\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n }\n else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split('.');\n if (intPart == \"0\")\n intPart = \"\";\n if (intPart.length > 0) { // has integer part\n decpos = intPart.length;\n digits = intPart + fracPart;\n }\n else { // only a fraction\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length)\n return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */\n }\n}\n//# sourceMappingURL=twrfloat.js.map","\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\"\r\n\r\nexport class twrFloatUtil {\r\n mod: twrWasmModuleBase;\r\n\r\n constructor(mod: twrWasmModuleBase) {\r\n this.mod=mod;\r\n }\r\n\r\n atod(strptr:number):number {\r\n const str=this.mod.getString(strptr);\r\n\r\n const upper=str.trimStart().toUpperCase();\r\n if (upper==\"INF\" || upper==\"+INF\")\r\n return Number.POSITIVE_INFINITY;\r\n else if (upper==\"-INF\")\r\n return Number.NEGATIVE_INFINITY\r\n else {\r\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\r\n const r=Number.parseFloat(str.replaceAll('D','e').replaceAll('d','e'));\r\n return r;\r\n }\r\n }\r\n\r\n dtoa(buffer:number, buffer_size:number, value:number, max_precision:number):void {\r\n if (max_precision==-1) {\r\n const r=value.toString();\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n else {\r\n let r=value.toString();\r\n if (r.length>max_precision)\r\n r=value.toPrecision(max_precision);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n }\r\n\r\n toFixed(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toFixed(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n toExponential(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toExponential(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\r\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\r\n // Negative exponents must be now smaller than 1e-99\r\n // fully-function C version also int he source, but this is the version enabled by default\r\n fcvtS(\r\n buffer:number, // char *\r\n sizeInBytes:number, //size_t\r\n value:number, // double\r\n fracpart_numdigits:number, //int\r\n dec:number, // int *\r\n sign:number // int *\r\n ):number {\r\n\r\n if (buffer==0 ||sign==0 || dec==0 || sizeInBytes<1) return 1;\r\n\r\n let digits:string;\r\n let decpos:number;\r\n let s=0; // default to positive\r\n\r\n\r\n if (Number.isNaN(value)) { /* nan */\r\n digits=\"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (!Number.isFinite(value)) { /* infinity */\r\n digits=\"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (value==0) { \r\n digits=\"000000000000000000000000000000000000\".slice(0,fracpart_numdigits);\r\n decpos=0;\r\n }\r\n \r\n else {\r\n\r\n if (value<0) {\r\n s=1; // negative\r\n value=Math.abs(value);\r\n }\r\n\r\n if (fracpart_numdigits>100 || value > 1e+21 || value < 1e-99) { \r\n this.mod.copyString(buffer, sizeInBytes, \"\");\r\n this.mod.mem32[dec]=0;\r\n return 1;\r\n }\r\n\r\n const roundValStr=value.toFixed(fracpart_numdigits);\r\n let [intPart=\"\", fracPart=\"\"] = roundValStr.split('.');\r\n if (intPart==\"0\") intPart=\"\";\r\n\r\n if (intPart.length>0) { // has integer part\r\n decpos=intPart.length;\r\n digits=intPart+fracPart;\r\n }\r\n else { // only a fraction\r\n digits=fracPart.replace(/^0+/,\"\"); // remove leading zeros\r\n decpos=digits.length-fracPart.length;\r\n }\r\n }\r\n\r\n if (sizeInBytes-1 < digits.length) return 1; \r\n this.mod.copyString(buffer, sizeInBytes, digits);\r\n this.mod.setLong(dec, decpos);\r\n this.mod.setLong(sign, s);\r\n\r\n return 0;\r\n\r\n /*\r\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\r\n\r\n let decpos=0;\r\n let digits:string;\r\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\r\n \r\n if (decpos>0) { // has integer part\r\n const intlen=Math.max(decpos, 0);\r\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\r\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\r\n }\r\n else { // only a fraction\r\n const intpart=Math.trunc(value);\r\n const fracpart=value-intpart;\r\n const prec=fracpart_numdigits- (-decpos);\r\n console.log(\"prec=\",prec);\r\n if (prec<1) {\r\n digits=\"\";\r\n }\r\n else {\r\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\");\r\n }\r\n }\r\n\r\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\r\n console.log('digits=',digits);\r\n console.log('dec=',decpos);\r\n console.log(\"sign=\",s);\r\n */\r\n\r\n\r\n }\r\n}","import { twrSignal } from \"./twrsignal.js\";\nimport { twrTimeImpl } from \"./twrdate.js\";\n// This class is used in the Main JS thread \nexport class twrWaitingCalls {\n callCompleteSignal;\n parameters;\n constructor() {\n this.callCompleteSignal = new twrSignal();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(() => {\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = twrTimeImpl();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [this.callCompleteSignal.sharedArray, this.parameters.buffer];\n }\n processMessage(msgType, data) {\n switch (msgType) {\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\n// This class is used in the worker thread \nexport class twrWaitingCallsProxy {\n callCompleteSignal;\n parameters;\n constructor(params) {\n this.callCompleteSignal = new twrSignal(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\"sleep\", [ms]]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\"time\"]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n//# sourceMappingURL=twrwaitingcalls.js.map","import { twrSignal } from \"./twrsignal.js\";\r\nimport {twrTimeImpl} from \"./twrdate.js\"\r\n\r\n// These classes are used to proxy a call across the worker thread - main thread boundary and wait for the result\r\n\r\nexport type TWaitingCallsProxyParams = [SharedArrayBuffer, SharedArrayBuffer]; // twrSignal, parameters \r\n\r\n// This class is used in the Main JS thread \r\nexport class twrWaitingCalls {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor() {\r\n\t\tthis.callCompleteSignal=new twrSignal();\r\n\t\tthis.parameters=new Uint32Array(new SharedArrayBuffer(4));\r\n\t}\r\n\r\n\tprivate startSleep(ms:number) {\r\n\r\n\t\tsetTimeout(()=>{\r\n\t\t\tthis.callCompleteSignal.signal();\r\n\t\t}, ms);\r\n\t\t\r\n\t}\r\n\r\n\tprivate time() {\r\n\t\tconst ms=twrTimeImpl();\r\n\t\tthis.parameters[0]=ms;\r\n\t\tthis.callCompleteSignal.signal();\r\n\t}\r\n\r\n\tgetProxyParams():TWaitingCallsProxyParams {\r\n\t\treturn [this.callCompleteSignal.sharedArray, this.parameters.buffer as SharedArrayBuffer];\t\r\n\t}\r\n\r\n\tprocessMessage(msgType:string, data:any[]):boolean {\r\n\t\tswitch (msgType) {\r\n\t\t\tcase \"sleep\":\r\n\t\t\t\tconst [ms] = data;\r\n\t\t\t\tthis.startSleep(ms);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"time\":\r\n\t\t\t\tthis.time();\r\n\t\t\t\tbreak;\r\n\t\t\t\r\n\t\t\tdefault:\r\n\t\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\treturn true;\r\n\t}\r\n\r\n}\r\n\r\n// This class is used in the worker thread \r\nexport class twrWaitingCallsProxy {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor(params:TWaitingCallsProxyParams) {\r\n\t\tthis.callCompleteSignal=new twrSignal(params[0]);\r\n\t\tthis.parameters=new Uint32Array(params[1]);\r\n\t}\r\n\r\n\tsleep(ms:number) {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"sleep\", [ms]]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t}\r\n\r\n\ttime() {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"time\"]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t\treturn this.parameters[0];\r\n\t}\r\n\r\n}\r\n","export function twrTimeImpl() {\n return Date.now();\n}\n//# sourceMappingURL=twrdate.js.map","\r\nexport function twrTimeImpl() {\r\n\r\n return Date.now();\r\n\r\n}"],"names":["$b93f1fdf40141def$var$twrSignalState","$c4741cac81d14197$var$D2DType","twrSignalState","D2DType","$3e39efa823870787$var$mod","$892fccfc812d5e20$export$a01cca24f011573a","sharedArray","buf","constructor","sa","window","crossOriginIsolated","location","protocol","Error","SharedArrayBuffer","Int32Array","write","n","i","Atomics","notify","read","isEmpty","readWait","rdptr","wait","$b93f1fdf40141def$export$e37a7b7b851b97f3","WAITING","signal","SIGNALED","isSignaled","reset","$c4741cac81d14197$export$c779b2cd00544976","canvasKeys","drawCompleteSignal","props","owner","params","signalBuffer","canvasKeysBuffer","charIn","inkey","getProp","pn","propName","getString","drawSeq","ds","postMessage","$8963973702ae5462$export$b377f0bbf2c7581e","divKeys","divKeysBuffer","charOut","ch","$8ac0b786da854328$export$485af4d0039b3389","$e72303a1db04bdfa$export$918ffb7e046a537b","mod","atod","strptr","str","upper","trimStart","toUpperCase","Number","POSITIVE_INFINITY","NEGATIVE_INFINITY","parseFloat","replaceAll","dtoa","buffer","buffer_size","value","max_precision","r","toString","copyString","length","toPrecision","toFixed","decdigits","toExponential","fcvtS","sizeInBytes","fracpart_numdigits","dec","sign","digits","decpos","s","isNaN","slice","isFinite","Math","abs","mem32","intPart","fracPart","roundValStr","split","replace","setLong","$ece7fa3ed770778a$export$c83a0a3bffe07399","memory","mem8","memD","exports","isWorker","isWasmModule","floatUtil","Uint8Array","Uint32Array","Float64Array","loadWasm","pathToLoad","response","fetch","err","console","log","ok","statusText","wasmBytes","arrayBuffer","allimports","modParams","imports","instance","WebAssembly","instantiate","env","ArrayBuffer","malloc","size","Promise","resolve","m","twr_malloc","init","stack","p","stdio","twrInit","twr_wasm_init","executeC","cparams","preCallC","retval","executeCImpl","postCallC","fname","f","Array","ci","putString","URL","fetchAndPutURL","putArrayBuffer","u8","j","sin","charCodeAt","strIndex","putU8","u8a","dest","ab","fnin","src","getLong","idx","idx32","floor","getDouble","idx64","setDouble","getShort","len","sout","undefined","String","fromCharCode","getU8Arr","rv","dataptr","getU32Arr","$aff9c2c494d23fe3$export$78d2a4633fe89379","callCompleteSignal","parameters","sleep","ms","time","onmessage","e","data","$3e39efa823870787$var$twrWasmModuleInWorker","modWorkerParams","urlToLoad","then","catch","ex","rc","modInWorkerParams","canvasProxy","canvasProxyParams","divProxy","divProxyParams","waitingCallsProxy","waitingCallsProxyParams","twrDebugLog","twrSleep","bind","twrTime","twrDivCharOut","twrDivCharIn","twrCanvasCharIn","twrCanvasInkey","twrCanvasGetProp","twrCanvasDrawSeq","twrSin","twrCos","cos","twrTan","tan","twrFAbs","twrACos","acos","twrASin","asin","twrATan","atan","twrExp","exp","twrFloor","twrCeil","ceil","twrFMod","x","y","twrLog","twrPow","pow","twrSqrt","sqrt","twrTrunc","trunc","twrDtoa","twrToFixed","twrToExponential","twrAtod","twrFcvtS"],"version":3,"file":"twrmodworker.2165e649.js.map"} \ No newline at end of file +{"mappings":"A,C,SQKK,EJgBA,EIhBA,EJgBA,MFZD,CISE,OAAO,EACZ,WAA8B,AAC9B,CAAA,GAAe,AAEf,aAAa,CAAqB,CAAlC,CACO,GAAI,AAAkB,aAAlB,OAAO,QACH,CAAC,qBAAuB,AAA+B,UAA7B,OAAO,QAAQ,CAAC,QAAQ,CAAe,MAAM,AAAI,MAAM,4DAA4D,oBAAoB,iCAErK,EAAI,IAAI,CAAC,WAAW,CAAC,EACpB,IAAI,CAAC,WAAW,CAAC,IAAI,kBAAkB,MAClD,IAAI,CAAC,GAAG,CAAC,IAAI,WAAW,IAAI,CAAC,WAAW,EAClC,IAAI,CAAC,GAAG,CArBJ,IAqBW,CAAC,EAChB,IAAI,CAAC,GAAG,CArBJ,IAqBW,CAAC,CACvB,CAEA,MAAM,CAAQ,CAAd,CACO,IAAI,EAAE,IAAI,CAAC,GAAG,CAzBV,IAyBiB,AACrB,CAAA,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAzBV,OA2BE,GAAQ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IAAI,CAAC,IAAI,CAAC,SAAS,CAE5C,CACN,CACF,C,C","sources":["","../../lib-js/twrmodworker.js","../../source/twr-wasm-ts/twrmodworker.ts","../../lib-js/twrcanvas.js","../../source/twr-wasm-ts/twrcanvas.ts","../../lib-js/twrcircular.js","../../source/twr-wasm-ts/twrcircular.ts","../../lib-js/twrsignal.js","../../source/twr-wasm-ts/twrsignal.ts","../../lib-js/twrdiv.js","../../source/twr-wasm-ts/twrdiv.ts","../../lib-js/twrdebug.js","../../source/twr-wasm-ts/twrdebug.ts","../../lib-js/twrmodbase.js","../../source/twr-wasm-ts/twrmodbase.ts","../../lib-js/twrfloat.js","../../source/twr-wasm-ts/twrfloat.ts","../../lib-js/twrwaitingcalls.js","../../source/twr-wasm-ts/twrwaitingcalls.ts","../../lib-js/twrdate.js","../../source/twr-wasm-ts/twrdate.ts"],"sourcesContent":["(() => {\nvar $3e39efa823870787$exports = {};\n// this script is the WebWorker thead used by class twrWasmAsyncModule\n//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst $892fccfc812d5e20$var$RDIDX = 256;\nconst $892fccfc812d5e20$var$WRIDX = 257;\nconst $892fccfc812d5e20$var$LEN = 256;\nclass $892fccfc812d5e20$export$a01cca24f011573a {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(1032);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[$892fccfc812d5e20$var$RDIDX] = 0;\n this.buf[$892fccfc812d5e20$var$WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[$892fccfc812d5e20$var$WRIDX];\n this.buf[i] = n;\n i++;\n if (i == $892fccfc812d5e20$var$LEN) i = 0;\n this.buf[$892fccfc812d5e20$var$WRIDX] = i;\n Atomics.notify(this.buf, $892fccfc812d5e20$var$WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[$892fccfc812d5e20$var$RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[$892fccfc812d5e20$var$RDIDX] = i;\n return n;\n } else return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[$892fccfc812d5e20$var$RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, $892fccfc812d5e20$var$WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[$892fccfc812d5e20$var$RDIDX] == this.buf[$892fccfc812d5e20$var$WRIDX];\n }\n}\n\n\n//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar $b93f1fdf40141def$var$twrSignalState;\n(function(twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})($b93f1fdf40141def$var$twrSignalState || ($b93f1fdf40141def$var$twrSignalState = {}));\nclass $b93f1fdf40141def$export$e37a7b7b851b97f3 {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == $b93f1fdf40141def$var$twrSignalState.WAITING) //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, $b93f1fdf40141def$var$twrSignalState.WAITING);\n }\n isSignaled() {\n return this.buf[0] == $b93f1fdf40141def$var$twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.WAITING;\n }\n}\n\n\nvar $c4741cac81d14197$var$D2DType;\n(function(D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})($c4741cac81d14197$var$D2DType || ($c4741cac81d14197$var$D2DType = {}));\nclass $c4741cac81d14197$export$2f298dd69cef3c34 {\n ctx;\n props = {\n charWidth: 0,\n charHeight: 0,\n foreColor: 0,\n backColor: 0,\n widthInChars: 0,\n heightInChars: 0,\n canvasHeight: 0,\n canvasWidth: 0\n };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase){\n const { forecolor: forecolor, backcolor: backcolor, fontsize: fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)();\n this.canvasKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.props,\n this.cmdCompleteSignal.sharedArray,\n this.canvasKeys.sharedArray\n ];\n }\n getProp(pn) {\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */ drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx) return;\n let ins = this.owner.getLong(ds); /* ds->start */ \n const lastins = this.owner.getLong(ds + 4); /* ds->last */ \n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while(true){\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */ \n switch(type){\n case $c4741cac81d14197$var$D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_BEGINPATH:\n this.ctx.beginPath();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILL:\n this.ctx.fill();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SAVE:\n this.ctx.save();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_RESTORE:\n this.ctx.restore();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_STROKE:\n this.ctx.stroke();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = this.owner.getLong(ins + 48) != 0;\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n } else this.precomputedObjects[id] = {\n mem8: new Uint8Array(this.owner.memory.buffer, start, length),\n width: width,\n height: height\n };\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id]) delete this.precomputedObjects[id];\n else console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n else {\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) this.ctx.putImageData(imgData, dx, dy);\n else this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */ \n if (next == 0) {\n if (ins != lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nclass $c4741cac81d14197$export$c779b2cd00544976 {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner){\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)(signalBuffer);\n this.canvasKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\n \"drawseq\",\n [\n ds\n ]\n ]);\n this.drawCompleteSignal.wait();\n }\n}\n\n\n\nclass $8963973702ae5462$export$dd376bb3f10f6896 {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611);\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase){\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) this.divKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(); // tsconfig, lib must be set to 2017 or higher\n if (this.div && !modParams.styleIsDefault) {\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.divKeys.sharedArray\n ];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */ charOut(ch) {\n if (!this.div) return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n }\n switch(ch){\n case 10:\n case 13:\n if (ch == 10 && this.lastChar == 13) break; // detect CR LF and treat as single new line\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n case 0xE:\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF:\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for(let i = 0; i < str.length; i++)this.charOut(str.charCodeAt(i));\n }\n}\nclass $8963973702ae5462$export$b377f0bbf2c7581e {\n divKeys;\n constructor(params){\n const [divKeysBuffer] = params;\n this.divKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n charOut(ch) {\n postMessage([\n \"divout\",\n ch\n ]);\n }\n}\n\n\nlet $8ac0b786da854328$var$logline = \"\";\nfunction $8ac0b786da854328$export$16b4216ec014493d(char) {\n if (char == 10 || char == 3) {\n console.log($8ac0b786da854328$var$logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n $8ac0b786da854328$var$logline = \"\";\n } else {\n $8ac0b786da854328$var$logline = $8ac0b786da854328$var$logline + String.fromCharCode(char);\n if ($8ac0b786da854328$var$logline.length >= 200) {\n console.log($8ac0b786da854328$var$logline);\n $8ac0b786da854328$var$logline = \"\";\n }\n }\n}\nfunction $8ac0b786da854328$export$485af4d0039b3389(ch) {\n postMessage([\n \"debug\",\n ch\n ]);\n}\n\n\nclass $e72303a1db04bdfa$export$918ffb7e046a537b {\n mod;\n constructor(mod){\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\") return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\") return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll(\"D\", \"e\").replaceAll(\"d\", \"e\"));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n } else {\n let r = value.toString();\n if (r.length > max_precision) r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, sizeInBytes, value, fracpart_numdigits, dec, sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1) return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) {\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (!Number.isFinite(value)) {\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n } else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split(\".\");\n if (intPart == \"0\") intPart = \"\";\n if (intPart.length > 0) {\n decpos = intPart.length;\n digits = intPart + fracPart;\n } else {\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length) return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */ }\n}\n\n\nclass $ece7fa3ed770778a$export$c83a0a3bffe07399 {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule;\n floatUtil;\n constructor(isWasmModule = false){\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new (0, $e72303a1db04bdfa$export$918ffb7e046a537b)(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/ /*********************************************************************/ async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n } catch (err) {\n console.log(\"loadWasm() failed to fetch: \" + pathToLoad);\n throw err;\n }\n if (!response.ok) throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, {\n env: allimports\n });\n this.exports = instance.instance.exports;\n if (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory) throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer) console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\n \"setmemory\",\n this.memory\n ]);\n }\n if (this.isWasmModule) // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n {\n if (!(this.memory.buffer instanceof ArrayBuffer)) console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size)=>{\n return new Promise((resolve)=>{\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n } catch (err) {\n console.log(\"WASM instantiate error: \" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch(this.modParams.stdio){\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* callC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */ async callC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.callCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async callCImpl(fname, cparams = []) {\n if (!this.exports) throw new Error(\"this.exports undefined\");\n if (!this.exports[fname]) throw new Error(\"callC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array)) throw new Error(\"callC: params must be array, first arg is function name\");\n if (params.length == 0) throw new Error(\"callC: missing function name\");\n let cparams = [];\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n cparams[ci++] = p;\n break;\n case \"string\":\n cparams[ci++] = await this.putString(p);\n break;\n case \"object\":\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n } else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"callC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n ci++;\n break;\n case \"string\":\n this.callCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n case \"object\":\n if (p instanceof URL) {\n this.callCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci = ci + 2;\n break;\n } else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for(let j = 0; j < u8.length; j++)u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.callCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n } else throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/ /*********************************************************************/ // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for(i = 0; i < sin.length && i < buffer_size - 1; i++)this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for(let i = 0; i < u8a.length; i++)this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === \"object\" && fnin instanceof URL)) throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [\n dest,\n src.length\n ];\n } catch (err) {\n console.log(\"fetchAndPutURL Error. URL: \" + fnin + \"\\n\" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while(this.mem8[strIndex + i] && (len === undefined ? true : i < len) && strIndex + i < this.mem8.length){\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array(this.mem8.slice(dataptr, dataptr + size).buffer);\n return u32;\n }\n}\n\n\n\nfunction $4af5689abbc8d01b$export$78724cdcf7ebea1d() {\n return Date.now();\n}\n\n\nclass $aff9c2c494d23fe3$export$9e37856d1928d388 {\n callCompleteSignal;\n parameters;\n constructor(){\n this.callCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(()=>{\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = (0, $4af5689abbc8d01b$export$78724cdcf7ebea1d)();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [\n this.callCompleteSignal.sharedArray,\n this.parameters.buffer\n ];\n }\n processMessage(msgType, data) {\n switch(msgType){\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\nclass $aff9c2c494d23fe3$export$78d2a4633fe89379 {\n callCompleteSignal;\n parameters;\n constructor(params){\n this.callCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\n \"sleep\",\n [\n ms\n ]\n ]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\n \"time\"\n ]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n\n\nlet $3e39efa823870787$var$mod;\nonmessage = function(e) {\n //console.log('twrworker.js: message received from main script: '+e.data);\n if (e.data[0] == \"startup\") {\n const params = e.data[1];\n //console.log(\"Worker startup params:\",params);\n $3e39efa823870787$var$mod = new $3e39efa823870787$var$twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\n $3e39efa823870787$var$mod.loadWasm(params.urlToLoad).then(()=>{\n postMessage([\n \"startupOkay\"\n ]);\n }).catch((ex)=>{\n console.log(\".catch: \", ex);\n postMessage([\n \"startupFail\",\n ex\n ]);\n });\n } else if (e.data[0] == \"callC\") $3e39efa823870787$var$mod.callCImpl(e.data[1], e.data[2]).then((rc)=>{\n postMessage([\n \"callCOkay\",\n rc\n ]);\n }).catch((e)=>{\n console.log(\"exception in callC twrworker.js\\n\");\n console.log(e);\n postMessage([\n \"callCFail\",\n e\n ]);\n });\n else console.log(\"twrworker.js: unknown message: \" + e);\n};\n// ************************************************************************\nclass $3e39efa823870787$var$twrWasmModuleInWorker extends (0, $ece7fa3ed770778a$export$c83a0a3bffe07399) {\n malloc;\n modParams;\n constructor(modParams, modInWorkerParams){\n super();\n this.isWorker = true;\n this.malloc = (size)=>{\n throw new Error(\"error - un-init malloc called\");\n };\n this.modParams = modParams;\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\n const canvasProxy = new (0, $c4741cac81d14197$export$c779b2cd00544976)(modInWorkerParams.canvasProxyParams, this);\n const divProxy = new (0, $8963973702ae5462$export$b377f0bbf2c7581e)(modInWorkerParams.divProxyParams);\n const waitingCallsProxy = new (0, $aff9c2c494d23fe3$export$78d2a4633fe89379)(modInWorkerParams.waitingCallsProxyParams);\n this.modParams.imports = {\n twrDebugLog: (0, $8ac0b786da854328$export$485af4d0039b3389),\n twrSleep: waitingCallsProxy.sleep.bind(waitingCallsProxy),\n twrTime: waitingCallsProxy.time.bind(waitingCallsProxy),\n twrDivCharOut: divProxy.charOut.bind(divProxy),\n twrDivCharIn: divProxy.charIn.bind(divProxy),\n twrCanvasCharIn: canvasProxy.charIn.bind(canvasProxy),\n twrCanvasInkey: canvasProxy.inkey.bind(canvasProxy),\n twrCanvasGetProp: canvasProxy.getProp.bind(canvasProxy),\n twrCanvasDrawSeq: canvasProxy.drawSeq.bind(canvasProxy),\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function(x, y) {\n return x % y;\n },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n}\n\n})();\n//# sourceMappingURL=twrmodworker.2165e649.js.map\n","// this script is the WebWorker thead used by class twrWasmAsyncModule\nimport { twrCanvasProxy } from \"./twrcanvas.js\";\nimport { twrDivProxy } from \"./twrdiv.js\";\nimport { twrDebugLogProxy } from \"./twrdebug.js\";\nimport { twrWasmModuleBase } from \"./twrmodbase.js\";\nimport { twrWaitingCallsProxy } from \"./twrwaitingcalls.js\";\nlet mod;\nonmessage = function (e) {\n //console.log('twrworker.js: message received from main script: '+e.data);\n if (e.data[0] == 'startup') {\n const params = e.data[1];\n //console.log(\"Worker startup params:\",params);\n mod = new twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\n mod.loadWasm(params.urlToLoad).then(() => {\n postMessage([\"startupOkay\"]);\n }).catch((ex) => {\n console.log(\".catch: \", ex);\n postMessage([\"startupFail\", ex]);\n });\n }\n else if (e.data[0] == 'callC') {\n mod.callCImpl(e.data[1], e.data[2]).then((rc) => {\n postMessage([\"callCOkay\", rc]);\n }).catch(e => {\n console.log(\"exception in callC twrworker.js\\n\");\n console.log(e);\n postMessage([\"callCFail\", e]);\n });\n }\n else {\n console.log(\"twrworker.js: unknown message: \" + e);\n }\n};\n// ************************************************************************\nclass twrWasmModuleInWorker extends twrWasmModuleBase {\n malloc;\n modParams;\n constructor(modParams, modInWorkerParams) {\n super();\n this.isWorker = true;\n this.malloc = (size) => { throw new Error(\"error - un-init malloc called\"); };\n this.modParams = modParams;\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\n const canvasProxy = new twrCanvasProxy(modInWorkerParams.canvasProxyParams, this);\n const divProxy = new twrDivProxy(modInWorkerParams.divProxyParams);\n const waitingCallsProxy = new twrWaitingCallsProxy(modInWorkerParams.waitingCallsProxyParams);\n this.modParams.imports = {\n twrDebugLog: twrDebugLogProxy,\n twrSleep: waitingCallsProxy.sleep.bind(waitingCallsProxy),\n twrTime: waitingCallsProxy.time.bind(waitingCallsProxy),\n twrDivCharOut: divProxy.charOut.bind(divProxy),\n twrDivCharIn: divProxy.charIn.bind(divProxy),\n twrCanvasCharIn: canvasProxy.charIn.bind(canvasProxy),\n twrCanvasInkey: canvasProxy.inkey.bind(canvasProxy),\n twrCanvasGetProp: canvasProxy.getProp.bind(canvasProxy),\n twrCanvasDrawSeq: canvasProxy.drawSeq.bind(canvasProxy),\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function (x, y) { return x % y; },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n}\n//# sourceMappingURL=twrmodworker.js.map","// this script is the WebWorker thead used by class twrWasmAsyncModule\r\n\r\nimport {twrCanvasProxy} from \"./twrcanvas.js\";\r\nimport {twrDivProxy} from \"./twrdiv.js\";\r\nimport {twrDebugLogProxy} from \"./twrdebug.js\";\r\nimport {TAsyncModStartupMsg} from \"./twrmodasync.js\"\r\nimport {twrWasmModuleBase, IModInWorkerParams, IModParams} from \"./twrmodbase.js\"\r\nimport {twrWaitingCallsProxy} from \"./twrwaitingcalls.js\";\r\n\r\nlet mod:twrWasmModuleInWorker;\r\n\r\nonmessage = function(e) {\r\n //console.log('twrworker.js: message received from main script: '+e.data);\r\n\r\n if (e.data[0]=='startup') {\r\n const params:TAsyncModStartupMsg=e.data[1];\r\n //console.log(\"Worker startup params:\",params);\r\n mod=new twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\r\n\r\n mod.loadWasm(params.urlToLoad).then( ()=> {\r\n postMessage([\"startupOkay\"]);\r\n }).catch( (ex)=> {\r\n console.log(\".catch: \", ex);\r\n postMessage([\"startupFail\", ex]);\r\n });\r\n }\r\n else if (e.data[0]=='callC') {\r\n mod.callCImpl(e.data[1], e.data[2]).then( (rc)=> {\r\n postMessage([\"callCOkay\", rc]);\r\n }).catch(e => {\r\n console.log(\"exception in callC twrworker.js\\n\");\r\n console.log(e);\r\n postMessage([\"callCFail\", e]);\r\n });\r\n }\r\n else {\r\n console.log(\"twrworker.js: unknown message: \"+e);\r\n }\r\n}\r\n\r\n\r\n// ************************************************************************\r\n\r\nclass twrWasmModuleInWorker extends twrWasmModuleBase {\r\n\tmalloc:(size:number)=>Promise;\r\n modParams: IModParams;\r\n\r\n\r\n constructor(modParams:IModParams, modInWorkerParams:IModInWorkerParams) {\r\n super();\r\n this.isWorker=true;\r\n this.malloc=(size:number)=>{throw new Error(\"error - un-init malloc called\")};\r\n this.modParams=modParams;\r\n\r\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\r\n const canvasProxy = new twrCanvasProxy(modInWorkerParams.canvasProxyParams, this);\r\n const divProxy = new twrDivProxy(modInWorkerParams.divProxyParams);\r\n const waitingCallsProxy = new twrWaitingCallsProxy(modInWorkerParams.waitingCallsProxyParams);\r\n\r\n this.modParams.imports={\r\n twrDebugLog:twrDebugLogProxy,\r\n twrSleep:waitingCallsProxy.sleep.bind(waitingCallsProxy),\r\n twrTime:waitingCallsProxy.time.bind(waitingCallsProxy),\r\n\r\n twrDivCharOut:divProxy.charOut.bind(divProxy), \r\n twrDivCharIn:divProxy.charIn.bind(divProxy), \r\n\r\n twrCanvasCharIn:canvasProxy.charIn.bind(canvasProxy),\r\n twrCanvasInkey:canvasProxy.inkey.bind(canvasProxy),\r\n twrCanvasGetProp:canvasProxy.getProp.bind(canvasProxy),\r\n twrCanvasDrawSeq:canvasProxy.drawSeq.bind(canvasProxy),\r\n\r\n\t\t\ttwrSin:Math.sin,\r\n\t\t\ttwrCos:Math.cos,\r\n\t\t\ttwrTan: Math.tan,\r\n\t\t\ttwrFAbs: Math.abs,\r\n\t\t\ttwrACos: Math.acos,\r\n\t\t\ttwrASin: Math.asin,\r\n\t\t\ttwrATan: Math.atan,\r\n\t\t\ttwrExp: Math.exp,\r\n\t\t\ttwrFloor: Math.floor,\r\n\t\t\ttwrCeil: Math.ceil,\r\n\t\t\ttwrFMod: function(x:number, y:number) {return x%y},\r\n\t\t\ttwrLog: Math.log,\r\n\t\t\ttwrPow: Math.pow,\r\n\t\t\ttwrSqrt: Math.sqrt,\r\n\t\t\ttwrTrunc: Math.trunc,\r\n\r\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\r\n\t\t\ttwrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\r\n\t\t\ttwrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\r\n\t\t\ttwrAtod: this.floatUtil.atod.bind(this.floatUtil),\r\n\t\t\ttwrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\r\n \r\n }\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nimport { twrSignal } from \"./twrsignal.js\";\nvar D2DType;\n(function (D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})(D2DType || (D2DType = {}));\nexport class twrCanvas {\n ctx;\n props = { charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight: 0, canvasWidth: 0 };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase) {\n const { forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new twrSignal();\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext)\n throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c)\n throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2)\n throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\n }\n getProp(pn) {\n if (!this.isValid())\n console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */\n drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid())\n console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx)\n return;\n let ins = this.owner.getLong(ds); /* ds->start */\n const lastins = this.owner.getLong(ds + 4); /* ds->last */\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while (1) {\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */\n if (0 /*type!=D2DType.D2D_FILLRECT*/) {\n console.log(\"ins\", ins);\n console.log(\"hdr.next\", this.owner.mem8[ins], this.owner.mem8[ins + 1], this.owner.mem8[ins + 2], this.owner.mem8[ins + 3]);\n console.log(\"hdr.type\", this.owner.mem8[ins + 4], this.owner.mem8[ins + 5]);\n console.log(\"next 4 bytes\", this.owner.mem8[ins + 6], this.owner.mem8[ins + 7], this.owner.mem8[ins + 8], this.owner.mem8[ins + 9]);\n console.log(\"and 4 more \", this.owner.mem8[ins + 10], this.owner.mem8[ins + 11], this.owner.mem8[ins + 12], this.owner.mem8[ins + 13]);\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\n }\n switch (type) {\n case D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case D2DType.D2D_BEGINPATH:\n {\n this.ctx.beginPath();\n }\n break;\n case D2DType.D2D_FILL:\n {\n this.ctx.fill();\n }\n break;\n case D2DType.D2D_SAVE:\n {\n this.ctx.save();\n }\n break;\n case D2DType.D2D_RESTORE:\n {\n this.ctx.restore();\n }\n break;\n case D2DType.D2D_STROKE:\n {\n this.ctx.stroke();\n }\n break;\n case D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = (this.owner.getLong(ins + 48) != 0);\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n }\n else { // Uint8ClampedArray doesn't support shared memory\n this.precomputedObjects[id] = { mem8: new Uint8Array(this.owner.memory.buffer, start, length), width: width, height: height };\n }\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id])\n delete this.precomputedObjects[id];\n else\n console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) {\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n }\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) {\n this.ctx.putImageData(imgData, dx, dy);\n }\n else {\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */\n if (next == 0) {\n if (ins != lastins)\n throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal)\n this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nexport class twrCanvasProxy {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner) {\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new twrSignal(signalBuffer);\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\"drawseq\", [ds]]);\n this.drawCompleteSignal.wait();\n }\n}\n//# sourceMappingURL=twrcanvas.js.map","import {twrWasmModuleBase, IModParams} from \"./twrmodbase.js\"\r\nimport {twrSharedCircularBuffer} from \"./twrcircular.js\";\r\nimport {twrSignal} from \"./twrsignal.js\";\r\n\r\n\r\n// Canvas have a size that will be set based on the character width x height\r\n// The display size for a canvas will default to this size, but can be changed in the HTML/JS via\r\n// canvas.style.width = \"700px\";\r\n// canvas.style.height = \"500px\";\r\n\r\nexport interface ICanvasProps {\r\n\tcharWidth: number,\r\n\tcharHeight: number,\r\n\tforeColor: number,\r\n\tbackColor: number,\r\n widthInChars: number,\r\n heightInChars: number,\r\n canvasWidth:number,\r\n canvasHeight:number\r\n}\r\n\r\nenum D2DType {\r\n D2D_FILLRECT=1,\r\n D2D_FILLCHAR=5,\r\n D2D_SETLINEWIDTH=10,\r\n D2D_SETFILLSTYLERGBA=11,\r\n D2D_SETFONT=12,\r\n D2D_BEGINPATH=13,\r\n D2D_MOVETO=14,\r\n D2D_LINETO=15,\r\n D2D_FILL=16,\r\n D2D_STROKE=17,\r\n D2D_SETSTROKESTYLERGBA=18,\r\n D2D_ARC=19,\r\n D2D_STROKERECT=20,\r\n D2D_FILLTEXT=21,\r\n D2D_IMAGEDATA=22,\r\n D2D_PUTIMAGEDATA=23,\r\n D2D_BEZIERTO=24,\r\n D2D_MEASURETEXT=25,\r\n D2D_SAVE=26,\r\n D2D_RESTORE=27,\r\n D2D_CREATERADIALGRADIENT=28,\r\n D2D_SETCOLORSTOP=29,\r\n D2D_SETFILLSTYLEGRADIENT=30,\r\n D2D_RELEASEID=31,\r\n D2D_CREATELINEARGRADIENT=32,\r\n D2D_SETFILLSTYLE=33,\r\n D2D_SETSTROKESTYLE=34\r\n\r\n}\r\n\r\nexport type TCanvasProxyParams = [ICanvasProps, SharedArrayBuffer, SharedArrayBuffer];\r\n\r\nexport interface ICanvas {\r\n props: ICanvasProps,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TCanvasProxyParams,\r\n drawSeq: (ds:number)=>void,\r\n }\r\n \r\nexport class twrCanvas implements ICanvas {\r\n ctx:CanvasRenderingContext2D|undefined;\r\n props:ICanvasProps={charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight:0, canvasWidth:0};\r\n owner: twrWasmModuleBase;\r\n cmdCompleteSignal?:twrSignal;\r\n canvasKeys?: twrSharedCircularBuffer;\r\n precomputedObjects: { [index: number]: \r\n (ImageData | {mem8:Uint8Array, width:number, height:number}) |\r\n CanvasGradient\r\n };\r\n\r\n constructor(element:HTMLCanvasElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n const {forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas} = modParams; \r\n this.owner=modbase;\r\n this.props.widthInChars=modParams.windim[0];\r\n this.props.heightInChars=modParams.windim[1];\r\n\r\n if (!this.owner.isWasmModule) {\r\n this.cmdCompleteSignal=new twrSignal();\r\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n }\r\n\r\n this.precomputedObjects={};\r\n \r\n if (element) {\r\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\r\n let c=element.getContext(\"2d\");\r\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\r\n\r\n c.font = fontsize.toString()+\"px Courier New\";\r\n c.textBaseline=\"top\";\r\n const sampleText=\" \";\r\n const tm=c.measureText(sampleText);\r\n this.props.charWidth=Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\r\n let fM = c.measureText(\"X\"); \r\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\r\n\r\n if (!isd2dcanvas) {\r\n element.width=this.props.charWidth*this.props.widthInChars;\r\n element.height=this.props.charHeight*this.props.heightInChars;\r\n }\r\n\r\n this.props.canvasHeight=element.height;\r\n this.props.canvasWidth=element.width;\r\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\r\n\r\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\r\n let c2=element.getContext(\"2d\");\r\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\r\n this.ctx=c2;\r\n this.ctx.font = fontsize.toString()+\"px Courier New\";\r\n this.ctx.textBaseline=\"top\";\r\n\r\n c2.fillStyle=backcolor;\r\n this.props.backColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n c2.fillStyle=forecolor;\r\n this.props.foreColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n }\r\n\r\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\r\n\r\n //console.log(\"twrCanvas.constructor props: \", this.props);\r\n }\r\n\r\n isValid() {\r\n return !!this.ctx;\r\n }\r\n\r\n getProxyParams() : TCanvasProxyParams {\r\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\r\n }\r\n\r\n getProp(pn:number): number {\r\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n\r\n/* see draw2d.h for structs that match */\r\n\r\n drawSeq(ds:number) {\r\n //console.log(\"twr::Canvas enter drawSeq\");\r\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\r\n if (!this.ctx) return;\r\n\r\n let ins=this.owner.getLong(ds); /* ds->start */\r\n const lastins=this.owner.getLong(ds+4); /* ds->last */\r\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\r\n\r\n let next:number;\r\n //let insCount=0;\r\n\r\n while (1) {\r\n\r\n //insCount++;\r\n\r\n const type:D2DType=this.owner.getLong(ins+4); /* hdr->type */\r\n if (0/*type!=D2DType.D2D_FILLRECT*/) {\r\n console.log(\"ins\",ins)\r\n console.log(\"hdr.next\",this.owner.mem8[ins],this.owner.mem8[ins+1],this.owner.mem8[ins+2],this.owner.mem8[ins+3]);\r\n console.log(\"hdr.type\",this.owner.mem8[ins+4],this.owner.mem8[ins+5]);\r\n console.log(\"next 4 bytes\", this.owner.mem8[ins+6],this.owner.mem8[ins+7],this.owner.mem8[ins+8],this.owner.mem8[ins+9]);\r\n console.log(\"and 4 more \", this.owner.mem8[ins+10],this.owner.mem8[ins+11],this.owner.mem8[ins+12],this.owner.mem8[ins+13]);\r\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\r\n }\r\n switch (type) {\r\n case D2DType.D2D_FILLRECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.fillRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKERECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.strokeRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILLCHAR:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const c=this.owner.getShort(ins+24);\r\n let txt=String.fromCharCode(c);\r\n this.ctx.fillText(txt, x, y);\r\n }\r\n break;\r\n\r\n \r\n case D2DType.D2D_FILLTEXT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const str=this.owner.getString(this.owner.getLong(ins+24));\r\n\r\n //console.log(\"filltext \",x,y,str)\r\n \r\n this.ctx.fillText(str, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MEASURETEXT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n const tmidx=this.owner.getLong(ins+12);\r\n \r\n const tm=this.ctx.measureText(str);\r\n this.owner.setDouble(tmidx+0, tm.actualBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+8, tm.actualBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+16, tm.actualBoundingBoxLeft);\r\n this.owner.setDouble(tmidx+24, tm.actualBoundingBoxRight);\r\n this.owner.setDouble(tmidx+32, tm.fontBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+40, tm.fontBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+48, tm.width);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFONT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.font=str;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.fillStyle = cssColor;\r\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETSTROKESTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.fillStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETSTROKESTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETLINEWIDTH:\r\n {\r\n const width=this.owner.getShort(ins+8); \r\n this.ctx.lineWidth=width;\r\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MOVETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.moveTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_LINETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.lineTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEZIERTO:\r\n {\r\n const cp1x=this.owner.getDouble(ins+8);\r\n const cp1y=this.owner.getDouble(ins+16);\r\n const cp2x=this.owner.getDouble(ins+24);\r\n const cp2y=this.owner.getDouble(ins+32);\r\n const x=this.owner.getDouble(ins+40);\r\n const y=this.owner.getDouble(ins+48);\r\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEGINPATH:\r\n {\r\n this.ctx.beginPath();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILL:\r\n {\r\n this.ctx.fill();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SAVE:\r\n {\r\n this.ctx.save();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_RESTORE:\r\n {\r\n this.ctx.restore();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKE:\r\n {\r\n this.ctx.stroke();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_ARC:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const radius=this.owner.getDouble(ins+24);\r\n const startAngle=this.owner.getDouble(ins+32);\r\n const endAngle=this.owner.getDouble(ins+40);\r\n const counterClockwise= (this.owner.getLong(ins+48)!=0);\r\n\r\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_IMAGEDATA:\r\n {\r\n const start=this.owner.getLong(ins+8);\r\n const length=this.owner.getLong(ins+12);\r\n const width=this.owner.getLong(ins+16);\r\n const height=this.owner.getLong(ins+20);\r\n const id=this.owner.getLong(ins+24);\r\n\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\r\n\r\n if (this.owner.isWasmModule) {\r\n const z = new Uint8ClampedArray(this.owner.memory!.buffer, start, length);\r\n this.precomputedObjects[id]=new ImageData(z, width, height);\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory\r\n this.precomputedObjects[id]={mem8: new Uint8Array(this.owner.memory!.buffer, start, length), width:width, height:height};\r\n }\r\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_CREATERADIALGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const radius0=this.owner.getDouble(ins+24);\r\n const x1=this.owner.getDouble(ins+32);\r\n const y1=this.owner.getDouble(ins+40);\r\n const radius1=this.owner.getDouble(ins+48);\r\n const id= this.owner.getLong(ins+56);\r\n\r\n let gradient=this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_CREATELINEARGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const x1=this.owner.getDouble(ins+24);\r\n const y1=this.owner.getDouble(ins+32);\r\n const id= this.owner.getLong(ins+40);\r\n \r\n let gradient=this.ctx.createLinearGradient(x0, y0, x1, y1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETCOLORSTOP:\r\n {\r\n const id = this.owner.getLong(ins+8);\r\n const pos=this.owner.getLong(ins+12);\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+16));\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n gradient.addColorStop(pos, cssColor);\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n this.ctx.fillStyle=gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_RELEASEID:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (this.precomputedObjects[id])\r\n delete this.precomputedObjects[id];\r\n else\r\n console.log(\"warning: D2D_RELEASEID with undefined ID \",id);\r\n }\r\n break\r\n\r\n \r\n\r\n case D2DType.D2D_PUTIMAGEDATA:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n const dx=this.owner.getLong(ins+12);\r\n const dy=this.owner.getLong(ins+16);\r\n const dirtyX=this.owner.getLong(ins+20);\r\n const dirtyY=this.owner.getLong(ins+24);\r\n const dirtyWidth=this.owner.getLong(ins+28);\r\n const dirtyHeight=this.owner.getLong(ins+32);\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \"+id);\r\n\r\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\r\n\r\n let imgData:ImageData;\r\n if (this.owner.isWasmModule) {\r\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\r\n imgData=this.precomputedObjects[id] as ImageData;\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\r\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\r\n const z = this.precomputedObjects[id] as {mem8:Uint8Array, width:number, height:number}; // Uint8Array\r\n const ca=Uint8ClampedArray.from(z.mem8); // shallow copy\r\n imgData=new ImageData(ca, z.width, z.height);\r\n }\r\n \r\n if (dirtyWidth==0 && dirtyHeight==0) {\r\n this.ctx.putImageData(imgData, dx, dy);\r\n }\r\n else {\r\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\r\n }\r\n }\r\n break;\r\n\r\n default:\r\n throw new Error (\"unimplemented or unknown Sequence Type in drawSeq: \"+type);\r\n }\r\n next=this.owner.getLong(ins); /* hdr->next */\r\n if (next==0) {\r\n if (ins!=lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\r\n break;\r\n }\r\n ins=next;\r\n }\r\n\r\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\r\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\r\n }\r\n}\r\n\r\nexport class twrCanvasProxy implements ICanvas {\r\n canvasKeys: twrSharedCircularBuffer;\r\n drawCompleteSignal:twrSignal;\r\n props: ICanvasProps;\r\n owner: twrWasmModuleBase;\r\n\r\n constructor(params:TCanvasProxyParams, owner:twrWasmModuleBase) {\r\n const [props, signalBuffer, canvasKeysBuffer] = params;\r\n this.drawCompleteSignal = new twrSignal(signalBuffer);\r\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\r\n this.props=props;\r\n this.owner=owner;\r\n\r\n //console.log(\"Create New twrCanvasProxy: \",this.props)\r\n\r\n }\r\n\r\n charIn() { \r\n //ctx.commit(); not avail in chrome\r\n \r\n //postMessage([\"debug\", 'x']);\r\n \r\n return this.canvasKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.canvasKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n getProp(pn:number): number {\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n \r\n drawSeq(ds:number) {\r\n this.drawCompleteSignal.reset();\r\n postMessage([\"drawseq\", [ds]]);\r\n this.drawCompleteSignal.wait();\r\n }\r\n}\r\n","//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst RDIDX = 256;\nconst WRIDX = 257;\nconst LEN = 256;\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\n// the first 256 array entries are the circular buffer\n// the next two are used for the read and write index\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\nexport class twrSharedCircularBuffer {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(258 * 4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[RDIDX] = 0;\n this.buf[WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[WRIDX];\n this.buf[i] = n;\n i++;\n if (i == LEN)\n i = 0;\n this.buf[WRIDX] = i;\n Atomics.notify(this.buf, WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[RDIDX] = i;\n return n;\n }\n else\n return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[RDIDX] == this.buf[WRIDX];\n }\n}\n//# sourceMappingURL=twrcircular.js.map","//\r\n// This class implements a circular buffer that the main javascript thread can write to, \r\n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\r\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \r\n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\r\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\r\n//\r\n\r\nconst RDIDX=256;\r\nconst WRIDX=257;\r\nconst LEN=256;\r\n\r\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\r\n// the first 256 array entries are the circular buffer\r\n// the next two are used for the read and write index\r\n\r\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\r\n\r\nexport class twrSharedCircularBuffer {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n \r\n\tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(258*4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[RDIDX]=0;\r\n this.buf[WRIDX]=0;\r\n\t}\r\n\r\n\twrite(n:number) {\r\n let i=this.buf[WRIDX];\r\n this.buf[i]=n;\r\n i++;\r\n if (i==LEN) i=0;\r\n this.buf[WRIDX]=i; \r\n Atomics.notify(this.buf, WRIDX); \r\n\t}\r\n\r\n\tread():number {\r\n if (!this.isEmpty()) {\r\n let i=this.buf[RDIDX];\r\n let n=this.buf[i];\r\n i++;\r\n this.buf[RDIDX]=i;\r\n return n;\r\n }\r\n\t\telse\r\n return -1;\r\n\t}\r\n\r\n readWait():number {\r\n if (this.isEmpty()) {\r\n const rdptr=this.buf[RDIDX];\r\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\r\n Atomics.wait(this.buf, WRIDX, rdptr);\r\n }\r\n return this.read();\r\n\t}\r\n\r\n isEmpty():boolean {\r\n return this.buf[RDIDX]==this.buf[WRIDX];\r\n }\r\n}\r\n","//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar twrSignalState;\n(function (twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})(twrSignalState || (twrSignalState = {}));\n;\nexport class twrSignal {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window valid\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == twrSignalState.WAITING) {\n //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\n //console.log(\"released...\");\n }\n }\n isSignaled() {\n return this.buf[0] == twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = twrSignalState.WAITING;\n }\n}\n//# sourceMappingURL=twrsignal.js.map","//\r\n// This class implements a simple signal/wait mechanism\r\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\r\n//\r\n\r\nenum twrSignalState {\r\n WAITING=0,\r\n SIGNALED=1\r\n};\r\n\r\nexport class twrSignal {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n\r\n \tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window valid\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) \r\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[0]=twrSignalState.WAITING;\r\n\t}\r\n\r\n\tsignal() {\r\n this.buf[0]=twrSignalState.SIGNALED; \r\n //console.log(\"about to signal\");\r\n Atomics.notify(this.buf, 0); \r\n\t}\r\n\r\n wait() {\r\n if (this.buf[0]==twrSignalState.WAITING) {\r\n //console.log(\"waiting...\");\r\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\r\n //console.log(\"released...\");\r\n\r\n }\r\n\t}\r\n isSignaled():boolean {\r\n return this.buf[0]==twrSignalState.SIGNALED;\r\n }\r\n\r\n reset() {\r\n this.buf[0]=twrSignalState.WAITING;\r\n }\r\n}\r\n","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nexport class twrDiv {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase) {\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\n this.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n if (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.divKeys.sharedArray];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */\n charOut(ch) {\n if (!this.div)\n return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n }\n switch (ch) {\n case 10: // newline\n case 13: // return\n if (ch == 10 && this.lastChar == 13)\n break; // detect CR LF and treat as single new line\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8: // backspace\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n case 0xE: // cursor on\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF: // cursor off\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for (let i = 0; i < str.length; i++)\n this.charOut(str.charCodeAt(i));\n }\n}\nexport class twrDivProxy {\n divKeys;\n constructor(params) {\n const [divKeysBuffer] = params;\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n charOut(ch) {\n postMessage([\"divout\", ch]);\n }\n}\n//# sourceMappingURL=twrdiv.js.map","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\r\nimport { IModParams } from \"./twrmodbase.js\";\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\";\r\n\r\nexport type TDivProxyParams = [SharedArrayBuffer];\r\n\r\nexport interface IDiv {\r\n charOut: (ds:number)=>void,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TDivProxyParams,\r\n }\r\n\r\n\r\nexport class twrDiv implements IDiv {\r\n\tdiv:HTMLDivElement|null|undefined;\r\n\tdivKeys?:twrSharedCircularBuffer;\r\n\tCURSOR=String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\r\n\tcursorOn:boolean=false;\r\n\tlastChar:number=0;\r\n\textraBR:boolean=false;\r\n\towner:twrWasmModuleBase;\r\n\r\n constructor(element:HTMLDivElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n\t\tthis.div=element;\r\n\t\tthis.owner=modbase;\r\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\r\n\t\t\tthis.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n\t\t}\r\n\r\n\t\tif (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\r\n\t\t\tthis.div.style.backgroundColor = modParams.backcolor;\r\n\t\t\tthis.div.style.color = modParams.forecolor;\r\n\t\t\tthis.div.style.font=modParams.fontsize.toString()+\"px arial\"\r\n\t\t}\r\n }\r\n\r\n\tisValid() {\r\n\t\treturn !!this.div;\r\n\t}\r\n\r\n getProxyParams() : TDivProxyParams {\r\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [ this.divKeys.sharedArray];\r\n }\r\n\r\n\r\n/* \r\n * add character to div. Supports the following control codes:\r\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\r\n * 0xE cursor on \r\n * 0x8 backspace\r\n * 0xF cursor off \r\n*/\r\n\tcharOut(ch:number) {\r\n\r\n\t\tif (!this.div) return;\r\n\r\n\t\t//console.log(\"div::charout: \", ch);\r\n\r\n\t\tif (this.extraBR) {\r\n\t\t\tthis.extraBR=false;\r\n\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -4);\r\n\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t}\r\n\r\n\t\tswitch (ch) {\r\n\t\t\tcase 10: // newline\r\n\t\t\tcase 13: // return\r\n\t\t\t\tif (ch==10 && this.lastChar==13) break; // detect CR LF and treat as single new line\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\r\n\t\t\t\tthis.extraBR=true;\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\t//element.scrollIntoView();\r\n\t\t\t\t//element.scrollTop = element.scrollHeight;\r\n\t\t\t\tlet p = this.div.getBoundingClientRect();\r\n\t\t\t\twindow.scrollTo(0, p.height+100);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 8: // backspace\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xE: // cursor on\r\n\t\t\t\tif (!this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=true;\r\n\t\t\t\t\tthis.div.innerHTML += this.CURSOR;\r\n\t\t\t\t\tthis.div.focus();\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xF: // cursor off\r\n\t\t\t\tif (this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=false;\r\n\t\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += String.fromCharCode(ch);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\tthis.lastChar=ch;\r\n\t}\r\n\r\n\tstringOut(str:string) {\r\n\t\tfor (let i=0; i < str.length; i++)\r\n\t\t\tthis.charOut(str.charCodeAt(i));\r\n\t}\r\n}\r\n\r\n\r\nexport class twrDivProxy implements IDiv {\r\n divKeys: twrSharedCircularBuffer;\r\n\r\n constructor(params:TDivProxyParams) {\r\n const [divKeysBuffer] = params;\r\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\r\n }\r\n\r\n charIn() { \r\n return this.divKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.divKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n\tcharOut(ch:number) {\r\n\t\tpostMessage([\"divout\", ch]);\r\n\t}\r\n}\r\n\r\n","let logline = \"\";\nexport function twrDebugLogImpl(char) {\n if (char == 10 || char == 3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\n console.log(logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n logline = \"\";\n }\n else {\n logline = logline + String.fromCharCode(char);\n if (logline.length >= 200) {\n console.log(logline);\n logline = \"\";\n }\n }\n}\n// ************************************************************************\n// debugLog doesn't currently wait for the message to log, it returns immediately.\n// I could move this to be in the twrWaitingCalls class\nexport function twrDebugLogProxy(ch) {\n postMessage([\"debug\", ch]);\n}\n//# sourceMappingURL=twrdebug.js.map","\r\nlet logline=\"\";\r\nexport function twrDebugLogImpl(char:number) {\r\n\tif (char==10 || char==3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\r\n\t\tconsole.log(logline);\t// ideally without a linefeed, but there is no way to not have a LF with console.log API.\r\n\t\tlogline=\"\";\r\n\t}\r\n\telse {\r\n\t\tlogline=logline+String.fromCharCode(char);\r\n\t\tif (logline.length>=200) {\r\n\t\t\tconsole.log(logline);\r\n\t\t\tlogline=\"\";\r\n\t\t}\r\n\t}\r\n}\r\n\r\n// ************************************************************************\r\n// debugLog doesn't currently wait for the message to log, it returns immediately.\r\n// I could move this to be in the twrWaitingCalls class\r\nexport function twrDebugLogProxy(ch:number) {\r\n postMessage([\"debug\", ch]);\r\n}\r\n\r\n","import { twrFloatUtil } from \"./twrfloat.js\";\n/*********************************************************************/\n/*********************************************************************/\n/*********************************************************************/\nexport class twrWasmModuleBase {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\n floatUtil;\n constructor(isWasmModule = false) {\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new twrFloatUtil(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/\n /*********************************************************************/\n async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n }\n catch (err) {\n console.log('loadWasm() failed to fetch: ' + pathToLoad);\n throw err;\n }\n if (!response.ok)\n throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, { env: allimports });\n this.exports = instance.instance.exports;\n if (!this.exports)\n throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory)\n throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory)\n throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer)\n console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\"setmemory\", this.memory]);\n }\n if (this.isWasmModule) {\n // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (!(this.memory.buffer instanceof ArrayBuffer))\n console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size) => {\n return new Promise(resolve => {\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n }\n catch (err) {\n console.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch (this.modParams.stdio) {\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* callC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */\n async callC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.callCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async callCImpl(fname, cparams = []) {\n if (!this.exports)\n throw new Error(\"this.exports undefined\");\n if (!this.exports[fname])\n throw new Error(\"callC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array))\n throw new Error(\"callC: params must be array, first arg is function name\");\n if (params.length == 0)\n throw new Error(\"callC: missing function name\");\n let cparams = [];\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n cparams[ci++] = p;\n break;\n case 'string':\n cparams[ci++] = await this.putString(p);\n break;\n case 'object':\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n }\n else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"callC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n ci++;\n break;\n case 'string':\n this.callCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n case 'object':\n if (p instanceof URL) {\n this.callCImpl('twr_free', [cparams[ci]]);\n ci = ci + 2;\n break;\n }\n else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for (let j = 0; j < u8.length; j++)\n u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.callCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n }\n else\n throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/\n /*********************************************************************/\n // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for (i = 0; i < sin.length && i < buffer_size - 1; i++)\n this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for (let i = 0; i < u8a.length; i++)\n this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === 'object' && fnin instanceof URL))\n throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [dest, src.length];\n }\n catch (err) {\n console.log('fetchAndPutURL Error. URL: ' + fnin + '\\n' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while (this.mem8[strIndex + i] && (len === undefined ? true : i < len) && (strIndex + i) < this.mem8.length) {\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0)\n throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array((this.mem8.slice(dataptr, dataptr + size)).buffer);\n return u32;\n }\n}\n//# sourceMappingURL=twrmodbase.js.map","\r\nimport {TCanvasProxyParams} from \"./twrcanvas.js\"\r\nimport {TDivProxyParams} from \"./twrdiv.js\";\r\nimport {TWaitingCallsProxyParams} from \"./twrwaitingcalls.js\"\r\nimport {twrDebugLogImpl} from \"./twrdebug.js\";\r\nimport {twrFloatUtil} from \"./twrfloat.js\";\r\n\r\n\r\nexport type TStdioVals=\"div\"|\"canvas\"|\"null\"|\"debug\";\r\n\r\nexport interface IModOpts {\r\n\tstdio?:TStdioVals, \r\n\twindim?:[number, number],\r\n\tforecolor?:string,\r\n\tbackcolor?:string,\r\n\tfontsize?:number,\r\n\tisd2dcanvas?:boolean,\r\n\timports?:{},\r\n}\r\n\r\nexport interface IModParams {\r\n\tstdio:TStdioVals, \r\n\twindim:[number, number],\r\n\tforecolor:string,\r\n\tbackcolor:string,\r\n\tfontsize:number,\r\n\tstyleIsDefault: boolean\r\n\tisd2dcanvas:boolean,\r\n\timports:{[index:string]:Function},\r\n}\r\n\r\nexport interface IModInWorkerParams {\r\n\tdivProxyParams:TDivProxyParams,\r\n\tcanvasProxyParams:TCanvasProxyParams,\r\n\twaitingCallsProxyParams:TWaitingCallsProxyParams,\r\n}\r\n\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n\r\nexport abstract class twrWasmModuleBase {\r\n\tmemory?:WebAssembly.Memory;\r\n\tmem8:Uint8Array;\r\n\tmem32:Uint32Array;\r\n\tmemD:Float64Array;\r\n\tabstract malloc:(size:number)=>Promise;\r\n\tabstract modParams:IModParams;\r\n\texports?:WebAssembly.Exports;\r\n\tisWorker=false;\r\n\tisWasmModule:boolean; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\r\n\tfloatUtil:twrFloatUtil;\r\n\r\n\tconstructor(isWasmModule=false) {\r\n\t\tthis.isWasmModule=isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\r\n\t\tthis.mem8=new Uint8Array(); \t// avoid type errors\r\n\t\tthis.mem32=new Uint32Array(); // avoid type errors\r\n\t\tthis.memD=new Float64Array(); // avoid type errors\r\n\t\tthis.floatUtil=new twrFloatUtil(this);\r\n\t\t//console.log(\"size of mem8 after constructor\",this.mem8.length);\r\n\t}\r\n\r\n\t/*********************************************************************/\r\n\t/*********************************************************************/\r\n\r\n\tasync loadWasm(pathToLoad:string) {\r\n\t\t//console.log(\"fileToLoad\",fileToLoad)\r\n\r\n\t\tlet response;\r\n\t\ttry {\r\n\t\t\tresponse=await fetch(pathToLoad);\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('loadWasm() failed to fetch: '+pathToLoad);\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t\t\r\n\t\tif (!response.ok) throw new Error(\"fetch response error on file '\"+pathToLoad+\"'\\n\"+response.statusText);\r\n\r\n\t\ttry {\r\n\t\t\tlet wasmBytes = await response.arrayBuffer();\r\n\r\n\t\t\tlet allimports:WebAssembly.ModuleImports = { \r\n\t\t\t\t...this.modParams.imports\r\n\t\t\t};\r\n\r\n\t\t\tlet instance = await WebAssembly.instantiate(wasmBytes, {env: allimports});\r\n\r\n\t\t\tthis.exports=instance.instance.exports;\r\n\t\t\tif (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\r\n\r\n\t\t\tif (this.memory) throw new Error (\"unexpected error -- this.memory already set\");\r\n\t\t\tthis.memory=this.exports.memory as WebAssembly.Memory;\r\n\t\t\tif (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\r\n\t\t\tthis.mem8 = new Uint8Array(this.memory.buffer);\r\n\t\t\tthis.mem32 = new Uint32Array(this.memory.buffer);\r\n\t\t\tthis.memD = new Float64Array(this.memory.buffer);\r\n\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\tif (this.isWorker) {\r\n\t\t\t\tif (this.memory.buffer instanceof ArrayBuffer)\r\n\t\t\t\t\tconsole.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\r\n\t\t\t\t\r\n\t\t\t\tpostMessage([\"setmemory\",this.memory]);\r\n\t\t\t}\r\n\t\t\tif (this.isWasmModule) {\r\n\t\t\t\t// here if twrWasmModule, twrWasmModuleAsync overrides this function\r\n\t\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\t\tif (!(this.memory.buffer instanceof ArrayBuffer))\r\n\t\t\t\t\tconsole.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\r\n\t\t\t}\r\n\r\n\t\t\tthis.malloc=(size:number)=>{\r\n\t\t\t\treturn new Promise(resolve => {\r\n\t\t\t\t\tconst m=this.exports!.twr_malloc as (size:number)=>number;\r\n\t\t\t\t\tresolve(m(size));\r\n\t\t\t\t});\r\n\t\t };\r\n\r\n\t\t\tthis.init();\r\n\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t}\r\n\r\n\tprivate init() {\r\n\t\t//console.log(\"loadWasm.init() enter\")\r\n\t\t\tlet p:number;\r\n\t\t\tswitch (this.modParams.stdio) {\r\n\t\t\t\tcase \"debug\":\r\n\t\t\t\t\tp=0;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"div\":\r\n\t\t\t\t\tp=1;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"canvas\":\r\n\t\t\t\t\tp=2;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"null\":\r\n\t\t\t\t\tp=3;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tp=0; // debug\r\n\t\t\t}\r\n\r\n\t\t\tconst twrInit=this.exports!.twr_wasm_init as CallableFunction;\r\n\t\t\t//console.log(\"twrInit:\",twrInit)\r\n\t\t\ttwrInit(p, this.mem8.length);\r\n\t}\r\n\r\n\t/* callC takes an array where:\r\n\t* the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\r\n\t* and the next entries are a variable number of parameters to pass to the C function, of type\r\n\t* number - converted to int32 or float64 as appropriate\r\n\t* string - converted to a an index (ptr) into a module Memory returned via stringToMem()\r\n\t* URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\r\n\t* Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\r\n */\r\n\r\n\tasync callC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\t\tconst cparams=await this.preCallC(params);\r\n\t\tlet retval = this.callCImpl(params[0], cparams);\r\n\t\tthis.postCallC(cparams, params);\r\n\t\treturn retval;\r\n\t}\r\n\r\n\tasync callCImpl(fname:string, cparams:number[]=[]) {\r\n\t\tif (!this.exports) throw new Error(\"this.exports undefined\");\r\n\t\tif (!this.exports[fname]) throw new Error(\"callC: function '\"+fname+\"' not in export table. Use --export wasm-ld flag.\");\r\n\r\n\t\tconst f = this.exports[fname] as CallableFunction;\r\n\t\tlet cr=f(...cparams);\r\n\r\n\t\treturn cr;\r\n\t}\r\n\r\n\t// convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\r\n\tasync preCallC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tif (!(params.constructor === Array)) throw new Error (\"callC: params must be array, first arg is function name\");\r\n\t\tif (params.length==0) throw new Error(\"callC: missing function name\");\r\n\r\n\t\tlet cparams:number[]=[];\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tcparams[ci++]=p;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tcparams[ci++]=await this.putString(p);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tconst r=await this.fetchAndPutURL(p);\r\n\t\t\t\t\t\tcparams[ci++]=r[0]; // mem index\r\n\t\t\t\t\t\tcparams[ci++]=r[1]; // len\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tconst r=await this.putArrayBuffer(p);\r\n\t\t\t\t\t\tcparams[ci++]=r; // mem index\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tthrow new Error (\"callC: invalid object type passed in\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn cparams;\r\n\t}\r\n\r\n\t// free the mallocs; copy array buffer data from malloc back to arraybuffer\r\n\tasync postCallC(cparams:number[], params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tthis.callCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t\t\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tthis.callCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\t\tci=ci+2;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tlet u8=new Uint8Array(p);\r\n\t\t\t\t\t\tfor (let j=0; j= this.mem32.length) throw new Error(\"invalid index passed to getLong: \"+idx+\", this.mem32.length: \"+this.mem32.length);\r\n\t\tconst long:number = this.mem32[idx32];\r\n\t\treturn long;\r\n\t}\r\n\t\r\n\tsetLong(idx:number, value:number) {\r\n const idx32 = Math.floor(idx / 4);\r\n if (idx32 * 4 != idx)\r\n throw new Error(\"setLong passed non long aligned address\");\r\n if (idx32 < 0 || idx32 >= this.mem32.length)\r\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\r\n this.mem32[idx32]=value;\r\n }\r\n\r\n\tgetDouble(idx:number): number {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"getLong passed non Float64 aligned address\")\r\n\t\tconst long:number = this.memD[idx64];\r\n\t\treturn long;\r\n\t}\r\n\r\n\tsetDouble(idx:number, value:number) {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"setDouble passed non Float64 aligned address\")\r\n\t\tthis.memD[idx64]=value;\r\n\t}\r\n\r\n\tgetShort(idx:number): number {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getShort: \"+idx);\r\n\t\tconst short:number = this.mem8[idx]+this.mem8[idx+1]*256;\r\n\t\treturn short;\r\n\t}\r\n\r\n\t// get a string out of module memory\r\n\t// null terminated, up until max of (optional) len\r\n\tgetString(strIndex:number, len?:number): string {\r\n\t\tlet sout=\"\";\r\n\r\n\t\tlet i=0;\r\n\t\twhile (this.mem8[strIndex+i] && (len===undefined?true:i= this.mem8.length) throw new Error(\"invalid index passed to getU8: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU8\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU8\")\r\n\r\n\t\tconst u8=this.mem8.slice(dataptr, dataptr+size);\r\n\t\treturn u8;\r\n\t}\r\n\r\n\t// get a int32 array out of module memory when passed in index to [size, dataptr]\r\n\tgetU32Arr(idx:number): Uint32Array {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getU32: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU32\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU32\")\r\n\r\n\t\tif (size%4!=0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\r\n\r\n\t\tconst u32 = new Uint32Array( (this.mem8.slice(dataptr, dataptr+size)).buffer );\r\n\t\treturn u32;\r\n\t}\r\n}\r\n","export class twrFloatUtil {\n mod;\n constructor(mod) {\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\")\n return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\")\n return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll('D', 'e').replaceAll('d', 'e'));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n }\n else {\n let r = value.toString();\n if (r.length > max_precision)\n r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, // char *\n sizeInBytes, //size_t\n value, // double\n fracpart_numdigits, //int\n dec, // int *\n sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1)\n return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) { /* nan */\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (!Number.isFinite(value)) { /* infinity */\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n }\n else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split('.');\n if (intPart == \"0\")\n intPart = \"\";\n if (intPart.length > 0) { // has integer part\n decpos = intPart.length;\n digits = intPart + fracPart;\n }\n else { // only a fraction\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length)\n return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */\n }\n}\n//# sourceMappingURL=twrfloat.js.map","\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\"\r\n\r\nexport class twrFloatUtil {\r\n mod: twrWasmModuleBase;\r\n\r\n constructor(mod: twrWasmModuleBase) {\r\n this.mod=mod;\r\n }\r\n\r\n atod(strptr:number):number {\r\n const str=this.mod.getString(strptr);\r\n\r\n const upper=str.trimStart().toUpperCase();\r\n if (upper==\"INF\" || upper==\"+INF\")\r\n return Number.POSITIVE_INFINITY;\r\n else if (upper==\"-INF\")\r\n return Number.NEGATIVE_INFINITY\r\n else {\r\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\r\n const r=Number.parseFloat(str.replaceAll('D','e').replaceAll('d','e'));\r\n return r;\r\n }\r\n }\r\n\r\n dtoa(buffer:number, buffer_size:number, value:number, max_precision:number):void {\r\n if (max_precision==-1) {\r\n const r=value.toString();\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n else {\r\n let r=value.toString();\r\n if (r.length>max_precision)\r\n r=value.toPrecision(max_precision);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n }\r\n\r\n toFixed(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toFixed(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n toExponential(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toExponential(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\r\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\r\n // Negative exponents must be now smaller than 1e-99\r\n // fully-function C version also int he source, but this is the version enabled by default\r\n fcvtS(\r\n buffer:number, // char *\r\n sizeInBytes:number, //size_t\r\n value:number, // double\r\n fracpart_numdigits:number, //int\r\n dec:number, // int *\r\n sign:number // int *\r\n ):number {\r\n\r\n if (buffer==0 ||sign==0 || dec==0 || sizeInBytes<1) return 1;\r\n\r\n let digits:string;\r\n let decpos:number;\r\n let s=0; // default to positive\r\n\r\n\r\n if (Number.isNaN(value)) { /* nan */\r\n digits=\"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (!Number.isFinite(value)) { /* infinity */\r\n digits=\"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (value==0) { \r\n digits=\"000000000000000000000000000000000000\".slice(0,fracpart_numdigits);\r\n decpos=0;\r\n }\r\n \r\n else {\r\n\r\n if (value<0) {\r\n s=1; // negative\r\n value=Math.abs(value);\r\n }\r\n\r\n if (fracpart_numdigits>100 || value > 1e+21 || value < 1e-99) { \r\n this.mod.copyString(buffer, sizeInBytes, \"\");\r\n this.mod.mem32[dec]=0;\r\n return 1;\r\n }\r\n\r\n const roundValStr=value.toFixed(fracpart_numdigits);\r\n let [intPart=\"\", fracPart=\"\"] = roundValStr.split('.');\r\n if (intPart==\"0\") intPart=\"\";\r\n\r\n if (intPart.length>0) { // has integer part\r\n decpos=intPart.length;\r\n digits=intPart+fracPart;\r\n }\r\n else { // only a fraction\r\n digits=fracPart.replace(/^0+/,\"\"); // remove leading zeros\r\n decpos=digits.length-fracPart.length;\r\n }\r\n }\r\n\r\n if (sizeInBytes-1 < digits.length) return 1; \r\n this.mod.copyString(buffer, sizeInBytes, digits);\r\n this.mod.setLong(dec, decpos);\r\n this.mod.setLong(sign, s);\r\n\r\n return 0;\r\n\r\n /*\r\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\r\n\r\n let decpos=0;\r\n let digits:string;\r\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\r\n \r\n if (decpos>0) { // has integer part\r\n const intlen=Math.max(decpos, 0);\r\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\r\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\r\n }\r\n else { // only a fraction\r\n const intpart=Math.trunc(value);\r\n const fracpart=value-intpart;\r\n const prec=fracpart_numdigits- (-decpos);\r\n console.log(\"prec=\",prec);\r\n if (prec<1) {\r\n digits=\"\";\r\n }\r\n else {\r\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\");\r\n }\r\n }\r\n\r\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\r\n console.log('digits=',digits);\r\n console.log('dec=',decpos);\r\n console.log(\"sign=\",s);\r\n */\r\n\r\n\r\n }\r\n}","import { twrSignal } from \"./twrsignal.js\";\nimport { twrTimeImpl } from \"./twrdate.js\";\n// This class is used in the Main JS thread \nexport class twrWaitingCalls {\n callCompleteSignal;\n parameters;\n constructor() {\n this.callCompleteSignal = new twrSignal();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(() => {\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = twrTimeImpl();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [this.callCompleteSignal.sharedArray, this.parameters.buffer];\n }\n processMessage(msgType, data) {\n switch (msgType) {\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\n// This class is used in the worker thread \nexport class twrWaitingCallsProxy {\n callCompleteSignal;\n parameters;\n constructor(params) {\n this.callCompleteSignal = new twrSignal(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\"sleep\", [ms]]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\"time\"]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n//# sourceMappingURL=twrwaitingcalls.js.map","import { twrSignal } from \"./twrsignal.js\";\r\nimport {twrTimeImpl} from \"./twrdate.js\"\r\n\r\n// These classes are used to proxy a call across the worker thread - main thread boundary and wait for the result\r\n\r\nexport type TWaitingCallsProxyParams = [SharedArrayBuffer, SharedArrayBuffer]; // twrSignal, parameters \r\n\r\n// This class is used in the Main JS thread \r\nexport class twrWaitingCalls {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor() {\r\n\t\tthis.callCompleteSignal=new twrSignal();\r\n\t\tthis.parameters=new Uint32Array(new SharedArrayBuffer(4));\r\n\t}\r\n\r\n\tprivate startSleep(ms:number) {\r\n\r\n\t\tsetTimeout(()=>{\r\n\t\t\tthis.callCompleteSignal.signal();\r\n\t\t}, ms);\r\n\t\t\r\n\t}\r\n\r\n\tprivate time() {\r\n\t\tconst ms=twrTimeImpl();\r\n\t\tthis.parameters[0]=ms;\r\n\t\tthis.callCompleteSignal.signal();\r\n\t}\r\n\r\n\tgetProxyParams():TWaitingCallsProxyParams {\r\n\t\treturn [this.callCompleteSignal.sharedArray, this.parameters.buffer as SharedArrayBuffer];\t\r\n\t}\r\n\r\n\tprocessMessage(msgType:string, data:any[]):boolean {\r\n\t\tswitch (msgType) {\r\n\t\t\tcase \"sleep\":\r\n\t\t\t\tconst [ms] = data;\r\n\t\t\t\tthis.startSleep(ms);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"time\":\r\n\t\t\t\tthis.time();\r\n\t\t\t\tbreak;\r\n\t\t\t\r\n\t\t\tdefault:\r\n\t\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\treturn true;\r\n\t}\r\n\r\n}\r\n\r\n// This class is used in the worker thread \r\nexport class twrWaitingCallsProxy {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor(params:TWaitingCallsProxyParams) {\r\n\t\tthis.callCompleteSignal=new twrSignal(params[0]);\r\n\t\tthis.parameters=new Uint32Array(params[1]);\r\n\t}\r\n\r\n\tsleep(ms:number) {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"sleep\", [ms]]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t}\r\n\r\n\ttime() {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"time\"]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t\treturn this.parameters[0];\r\n\t}\r\n\r\n}\r\n","export function twrTimeImpl() {\n return Date.now();\n}\n//# sourceMappingURL=twrdate.js.map","\r\nexport function twrTimeImpl() {\r\n\r\n return Date.now();\r\n\r\n}"],"names":["$b93f1fdf40141def$var$twrSignalState","$c4741cac81d14197$var$D2DType","twrSignalState","D2DType","$3e39efa823870787$var$mod","$892fccfc812d5e20$export$a01cca24f011573a","sharedArray","buf","constructor","sa","window","crossOriginIsolated","location","protocol","Error","SharedArrayBuffer","Int32Array","write","n","i","Atomics","notify","read","isEmpty","readWait","rdptr","wait","$b93f1fdf40141def$export$e37a7b7b851b97f3","WAITING","signal","SIGNALED","isSignaled","reset","$c4741cac81d14197$export$c779b2cd00544976","canvasKeys","drawCompleteSignal","props","owner","params","signalBuffer","canvasKeysBuffer","charIn","inkey","getProp","pn","propName","getString","drawSeq","ds","postMessage","$8963973702ae5462$export$b377f0bbf2c7581e","divKeys","divKeysBuffer","charOut","ch","$8ac0b786da854328$export$485af4d0039b3389","$e72303a1db04bdfa$export$918ffb7e046a537b","mod","atod","strptr","str","upper","trimStart","toUpperCase","Number","POSITIVE_INFINITY","NEGATIVE_INFINITY","parseFloat","replaceAll","dtoa","buffer","buffer_size","value","max_precision","r","toString","copyString","length","toPrecision","toFixed","decdigits","toExponential","fcvtS","sizeInBytes","fracpart_numdigits","dec","sign","digits","decpos","s","isNaN","slice","isFinite","Math","abs","mem32","intPart","fracPart","roundValStr","split","replace","setLong","$ece7fa3ed770778a$export$c83a0a3bffe07399","memory","mem8","memD","exports","isWorker","isWasmModule","floatUtil","Uint8Array","Uint32Array","Float64Array","loadWasm","pathToLoad","response","fetch","err","console","log","ok","statusText","wasmBytes","arrayBuffer","allimports","modParams","imports","instance","WebAssembly","instantiate","env","ArrayBuffer","malloc","size","Promise","resolve","m","twr_malloc","init","stack","p","stdio","twrInit","twr_wasm_init","callC","cparams","preCallC","retval","callCImpl","postCallC","fname","f","Array","ci","putString","URL","fetchAndPutURL","putArrayBuffer","u8","j","sin","charCodeAt","strIndex","putU8","u8a","dest","ab","fnin","src","getLong","idx","idx32","floor","getDouble","idx64","setDouble","getShort","len","sout","undefined","String","fromCharCode","getU8Arr","rv","dataptr","getU32Arr","$aff9c2c494d23fe3$export$78d2a4633fe89379","callCompleteSignal","parameters","sleep","ms","time","onmessage","e","data","$3e39efa823870787$var$twrWasmModuleInWorker","modWorkerParams","urlToLoad","then","catch","ex","rc","modInWorkerParams","canvasProxy","canvasProxyParams","divProxy","divProxyParams","waitingCallsProxy","waitingCallsProxyParams","twrDebugLog","twrSleep","bind","twrTime","twrDivCharOut","twrDivCharIn","twrCanvasCharIn","twrCanvasInkey","twrCanvasGetProp","twrCanvasDrawSeq","twrSin","twrCos","cos","twrTan","tan","twrFAbs","twrACos","acos","twrASin","asin","twrATan","atan","twrExp","exp","twrFloor","twrCeil","ceil","twrFMod","x","y","twrLog","twrPow","pow","twrSqrt","sqrt","twrTrunc","trunc","twrDtoa","twrToFixed","twrToExponential","twrAtod","twrFcvtS"],"version":3,"file":"twrmodworker.2165e649.js.map"} \ No newline at end of file diff --git a/azure/examples/stdio-div/index.html b/azure/examples/stdio-div/index.html index 494d8d2a..38cdead2 100644 --- a/azure/examples/stdio-div/index.html +++ b/azure/examples/stdio-div/index.html @@ -25,7 +25,7 @@ document.getElementById("twr_iodiv").addEventListener("keydown",(ev)=>{amod.keyDownDiv(ev)}); await amod.loadWasm("./stdio-div.wasm"); - await amod.executeC(["stdio_div"]); + await amod.callC(["stdio_div"]); } catch(ex) { console.log("unexpected exception"); diff --git a/azure/examples/tests/dist/index.html b/azure/examples/tests/dist/index.html index 8d113820..e0c4eaed 100644 --- a/azure/examples/tests/dist/index.html +++ b/azure/examples/tests/dist/index.html @@ -5,4 +5,4 @@ "whatkey": "../../lib-js/whatkey.js" } } - \ No newline at end of file + \ No newline at end of file diff --git a/azure/examples/tests/dist/twrmodworker.2165e649.js b/azure/examples/tests/dist/twrmodworker.2165e649.js index 3744680c..d8d07779 100644 --- a/azure/examples/tests/dist/twrmodworker.2165e649.js +++ b/azure/examples/tests/dist/twrmodworker.2165e649.js @@ -1,2 +1,2 @@ -(()=>{var t,e,r,s;let i;class a{sharedArray;buf;constructor(t){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSharedCircularBuffer constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");t?this.sharedArray=t:this.sharedArray=new SharedArrayBuffer(1032),this.buf=new Int32Array(this.sharedArray),this.buf[256]=0,this.buf[257]=0}write(t){let e=this.buf[257];this.buf[e]=t,256==++e&&(e=0),this.buf[257]=e,Atomics.notify(this.buf,257)}read(){if(this.isEmpty())return -1;{let t=this.buf[256],e=this.buf[t];return t++,this.buf[256]=t,e}}readWait(){if(this.isEmpty()){let t=this.buf[256];Atomics.wait(this.buf,257,t)}return this.read()}isEmpty(){return this.buf[256]==this.buf[257]}}(r=t||(t={}))[r.WAITING=0]="WAITING",r[r.SIGNALED=1]="SIGNALED";class o{sharedArray;buf;constructor(e){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSignal constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");e?this.sharedArray=e:this.sharedArray=new SharedArrayBuffer(4),this.buf=new Int32Array(this.sharedArray),this.buf[0]=t.WAITING}signal(){this.buf[0]=t.SIGNALED,Atomics.notify(this.buf,0)}wait(){this.buf[0]==t.WAITING&&Atomics.wait(this.buf,0,t.WAITING)}isSignaled(){return this.buf[0]==t.SIGNALED}reset(){this.buf[0]=t.WAITING}}(s=e||(e={}))[s.D2D_FILLRECT=1]="D2D_FILLRECT",s[s.D2D_FILLCHAR=5]="D2D_FILLCHAR",s[s.D2D_SETLINEWIDTH=10]="D2D_SETLINEWIDTH",s[s.D2D_SETFILLSTYLERGBA=11]="D2D_SETFILLSTYLERGBA",s[s.D2D_SETFONT=12]="D2D_SETFONT",s[s.D2D_BEGINPATH=13]="D2D_BEGINPATH",s[s.D2D_MOVETO=14]="D2D_MOVETO",s[s.D2D_LINETO=15]="D2D_LINETO",s[s.D2D_FILL=16]="D2D_FILL",s[s.D2D_STROKE=17]="D2D_STROKE",s[s.D2D_SETSTROKESTYLERGBA=18]="D2D_SETSTROKESTYLERGBA",s[s.D2D_ARC=19]="D2D_ARC",s[s.D2D_STROKERECT=20]="D2D_STROKERECT",s[s.D2D_FILLTEXT=21]="D2D_FILLTEXT",s[s.D2D_IMAGEDATA=22]="D2D_IMAGEDATA",s[s.D2D_PUTIMAGEDATA=23]="D2D_PUTIMAGEDATA",s[s.D2D_BEZIERTO=24]="D2D_BEZIERTO",s[s.D2D_MEASURETEXT=25]="D2D_MEASURETEXT",s[s.D2D_SAVE=26]="D2D_SAVE",s[s.D2D_RESTORE=27]="D2D_RESTORE",s[s.D2D_CREATERADIALGRADIENT=28]="D2D_CREATERADIALGRADIENT",s[s.D2D_SETCOLORSTOP=29]="D2D_SETCOLORSTOP",s[s.D2D_SETFILLSTYLEGRADIENT=30]="D2D_SETFILLSTYLEGRADIENT",s[s.D2D_RELEASEID=31]="D2D_RELEASEID",s[s.D2D_CREATELINEARGRADIENT=32]="D2D_CREATELINEARGRADIENT",s[s.D2D_SETFILLSTYLE=33]="D2D_SETFILLSTYLE",s[s.D2D_SETSTROKESTYLE=34]="D2D_SETSTROKESTYLE";class n{canvasKeys;drawCompleteSignal;props;owner;constructor(t,e){let[r,s,i]=t;this.drawCompleteSignal=new o(s),this.canvasKeys=new a(i),this.props=r,this.owner=e}charIn(){return this.canvasKeys.readWait()}inkey(){return this.canvasKeys.isEmpty()?0:this.charIn()}getProp(t){let e=this.owner.getString(t);return this.props[e]}drawSeq(t){this.drawCompleteSignal.reset(),postMessage(["drawseq",[t]]),this.drawCompleteSignal.wait()}}class l{divKeys;constructor(t){let[e]=t;this.divKeys=new a(e)}charIn(){return this.divKeys.readWait()}inkey(){return this.divKeys.isEmpty()?0:this.charIn()}charOut(t){postMessage(["divout",t])}}function h(t){postMessage(["debug",t])}class m{mod;constructor(t){this.mod=t}atod(t){let e=this.mod.getString(t),r=e.trimStart().toUpperCase();return"INF"==r||"+INF"==r?Number.POSITIVE_INFINITY:"-INF"==r?Number.NEGATIVE_INFINITY:Number.parseFloat(e.replaceAll("D","e").replaceAll("d","e"))}dtoa(t,e,r,s){if(-1==s){let s=r.toString();this.mod.copyString(t,e,s)}else{let i=r.toString();i.length>s&&(i=r.toPrecision(s)),this.mod.copyString(t,e,i)}}toFixed(t,e,r,s){let i=r.toFixed(s);this.mod.copyString(t,e,i)}toExponential(t,e,r,s){let i=r.toExponential(s);this.mod.copyString(t,e,i)}fcvtS(t,e,r,s,i,a){let o,n;if(0==t||0==a||0==i||e<1)return 1;let l=0;if(Number.isNaN(r))o="1#QNAN00000000000000000000000000000".slice(0,s+1),n=1;else if(Number.isFinite(r)){if(0==r)o="000000000000000000000000000000000000".slice(0,s),n=0;else{if(r<0&&(l=1,r=Math.abs(r)),s>100||r>1e21||r<1e-99)return this.mod.copyString(t,e,""),this.mod.mem32[i]=0,1;let[a="",h=""]=r.toFixed(s).split(".");"0"==a&&(a=""),a.length>0?(n=a.length,o=a+h):n=(o=h.replace(/^0+/,"")).length-h.length}}else o="1#INF00000000000000000000000000000".slice(0,s+1),n=1;return e-1new Promise(e=>{let r=this.exports.twr_malloc;e(r(t))}),this.init()}catch(t){throw console.log("WASM instantiate error: "+t+(t.stack?"\n"+t.stack:"")),t}}init(){let t;switch(this.modParams.stdio){case"debug":default:t=0;break;case"div":t=1;break;case"canvas":t=2;break;case"null":t=3}(0,this.exports.twr_wasm_init)(t,this.mem8.length)}async executeC(t){let e=await this.preCallC(t),r=this.executeCImpl(t[0],e);return this.postCallC(e,t),r}async executeCImpl(t,e=[]){if(!this.exports)throw Error("this.exports undefined");if(!this.exports[t])throw Error("executeC: function '"+t+"' not in export table. Use --export wasm-ld flag.");return(0,this.exports[t])(...e)}async preCallC(t){if(t.constructor!==Array)throw Error("executeC: params must be array, first arg is function name");if(0==t.length)throw Error("executeC: missing function name");let e=[],r=0;for(let s=1;s=this.mem32.length)throw Error("invalid index passed to getLong: "+t+", this.mem32.length: "+this.mem32.length);return this.mem32[e]}setLong(t,e){let r=Math.floor(t/4);if(4*r!=t)throw Error("setLong passed non long aligned address");if(r<0||r>=this.mem32.length)throw Error("invalid index passed to setLong: "+t+", this.mem32.length: "+this.mem32.length);this.mem32[r]=e}getDouble(t){let e=Math.floor(t/8);if(8*e!=t)throw Error("getLong passed non Float64 aligned address");return this.memD[e]}setDouble(t,e){let r=Math.floor(t/8);if(8*r!=t)throw Error("setDouble passed non Float64 aligned address");this.memD[r]=e}getShort(t){if(t<0||t>=this.mem8.length)throw Error("invalid index passed to getShort: "+t);return this.mem8[t]+256*this.mem8[t+1]}getString(t,e){let r="",s=0;for(;this.mem8[t+s]&&(void 0===e||s=this.mem8.length)throw Error("invalid index passed to getU8: "+t);let e=new Uint32Array(this.mem8.slice(t,t+8).buffer),r=e[0],s=e[1];if(s<0||s>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU8");if(r<0||r>this.mem8.length-s)throw Error("invalid idx.size passed to getU8");return this.mem8.slice(s,s+r)}getU32Arr(t){if(t<0||t>=this.mem8.length)throw Error("invalid index passed to getU32: "+t);let e=new Uint32Array(this.mem8.slice(t,t+8).buffer),r=e[0],s=e[1];if(s<0||s>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU32");if(r<0||r>this.mem8.length-s)throw Error("invalid idx.size passed to getU32");if(r%4!=0)throw Error("idx.size is not an integer number of 32 bit words");return new Uint32Array(this.mem8.slice(s,s+r).buffer)}}class d{callCompleteSignal;parameters;constructor(t){this.callCompleteSignal=new o(t[0]),this.parameters=new Uint32Array(t[1])}sleep(t){this.callCompleteSignal.reset(),postMessage(["sleep",[t]]),this.callCompleteSignal.wait()}time(){return this.callCompleteSignal.reset(),postMessage(["time"]),this.callCompleteSignal.wait(),this.parameters[0]}}onmessage=function(t){if("startup"==t.data[0]){let e=t.data[1];(i=new f(e.modParams,e.modWorkerParams)).loadWasm(e.urlToLoad).then(()=>{postMessage(["startupOkay"])}).catch(t=>{console.log(".catch: ",t),postMessage(["startupFail",t])})}else"executeC"==t.data[0]?i.executeCImpl(t.data[1],t.data[2]).then(t=>{postMessage(["executeCOkay",t])}).catch(t=>{console.log("exception in executeC twrworker.js\n"),console.log(t),postMessage(["executeCFail",t])}):console.log("twrworker.js: unknown message: "+t)};class f extends c{malloc;modParams;constructor(t,e){super(),this.isWorker=!0,this.malloc=t=>{throw Error("error - un-init malloc called")},this.modParams=t;let r=new n(e.canvasProxyParams,this),s=new l(e.divProxyParams),i=new d(e.waitingCallsProxyParams);this.modParams.imports={twrDebugLog:h,twrSleep:i.sleep.bind(i),twrTime:i.time.bind(i),twrDivCharOut:s.charOut.bind(s),twrDivCharIn:s.charIn.bind(s),twrCanvasCharIn:r.charIn.bind(r),twrCanvasInkey:r.inkey.bind(r),twrCanvasGetProp:r.getProp.bind(r),twrCanvasDrawSeq:r.drawSeq.bind(r),twrSin:Math.sin,twrCos:Math.cos,twrTan:Math.tan,twrFAbs:Math.abs,twrACos:Math.acos,twrASin:Math.asin,twrATan:Math.atan,twrExp:Math.exp,twrFloor:Math.floor,twrCeil:Math.ceil,twrFMod:function(t,e){return t%e},twrLog:Math.log,twrPow:Math.pow,twrSqrt:Math.sqrt,twrTrunc:Math.trunc,twrDtoa:this.floatUtil.dtoa.bind(this.floatUtil),twrToFixed:this.floatUtil.toFixed.bind(this.floatUtil),twrToExponential:this.floatUtil.toExponential.bind(this.floatUtil),twrAtod:this.floatUtil.atod.bind(this.floatUtil),twrFcvtS:this.floatUtil.fcvtS.bind(this.floatUtil)}}}})(); +(()=>{var t,e,r,s;let i;class a{sharedArray;buf;constructor(t){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSharedCircularBuffer constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");t?this.sharedArray=t:this.sharedArray=new SharedArrayBuffer(1032),this.buf=new Int32Array(this.sharedArray),this.buf[256]=0,this.buf[257]=0}write(t){let e=this.buf[257];this.buf[e]=t,256==++e&&(e=0),this.buf[257]=e,Atomics.notify(this.buf,257)}read(){if(this.isEmpty())return -1;{let t=this.buf[256],e=this.buf[t];return t++,this.buf[256]=t,e}}readWait(){if(this.isEmpty()){let t=this.buf[256];Atomics.wait(this.buf,257,t)}return this.read()}isEmpty(){return this.buf[256]==this.buf[257]}}(r=t||(t={}))[r.WAITING=0]="WAITING",r[r.SIGNALED=1]="SIGNALED";class o{sharedArray;buf;constructor(e){if("undefined"!=typeof window&&!crossOriginIsolated&&"file:"!==window.location.protocol)throw Error("twrSignal constructor, crossOriginIsolated="+crossOriginIsolated+". See SharedArrayBuffer docs.");e?this.sharedArray=e:this.sharedArray=new SharedArrayBuffer(4),this.buf=new Int32Array(this.sharedArray),this.buf[0]=t.WAITING}signal(){this.buf[0]=t.SIGNALED,Atomics.notify(this.buf,0)}wait(){this.buf[0]==t.WAITING&&Atomics.wait(this.buf,0,t.WAITING)}isSignaled(){return this.buf[0]==t.SIGNALED}reset(){this.buf[0]=t.WAITING}}(s=e||(e={}))[s.D2D_FILLRECT=1]="D2D_FILLRECT",s[s.D2D_FILLCHAR=5]="D2D_FILLCHAR",s[s.D2D_SETLINEWIDTH=10]="D2D_SETLINEWIDTH",s[s.D2D_SETFILLSTYLERGBA=11]="D2D_SETFILLSTYLERGBA",s[s.D2D_SETFONT=12]="D2D_SETFONT",s[s.D2D_BEGINPATH=13]="D2D_BEGINPATH",s[s.D2D_MOVETO=14]="D2D_MOVETO",s[s.D2D_LINETO=15]="D2D_LINETO",s[s.D2D_FILL=16]="D2D_FILL",s[s.D2D_STROKE=17]="D2D_STROKE",s[s.D2D_SETSTROKESTYLERGBA=18]="D2D_SETSTROKESTYLERGBA",s[s.D2D_ARC=19]="D2D_ARC",s[s.D2D_STROKERECT=20]="D2D_STROKERECT",s[s.D2D_FILLTEXT=21]="D2D_FILLTEXT",s[s.D2D_IMAGEDATA=22]="D2D_IMAGEDATA",s[s.D2D_PUTIMAGEDATA=23]="D2D_PUTIMAGEDATA",s[s.D2D_BEZIERTO=24]="D2D_BEZIERTO",s[s.D2D_MEASURETEXT=25]="D2D_MEASURETEXT",s[s.D2D_SAVE=26]="D2D_SAVE",s[s.D2D_RESTORE=27]="D2D_RESTORE",s[s.D2D_CREATERADIALGRADIENT=28]="D2D_CREATERADIALGRADIENT",s[s.D2D_SETCOLORSTOP=29]="D2D_SETCOLORSTOP",s[s.D2D_SETFILLSTYLEGRADIENT=30]="D2D_SETFILLSTYLEGRADIENT",s[s.D2D_RELEASEID=31]="D2D_RELEASEID",s[s.D2D_CREATELINEARGRADIENT=32]="D2D_CREATELINEARGRADIENT",s[s.D2D_SETFILLSTYLE=33]="D2D_SETFILLSTYLE",s[s.D2D_SETSTROKESTYLE=34]="D2D_SETSTROKESTYLE";class n{canvasKeys;drawCompleteSignal;props;owner;constructor(t,e){let[r,s,i]=t;this.drawCompleteSignal=new o(s),this.canvasKeys=new a(i),this.props=r,this.owner=e}charIn(){return this.canvasKeys.readWait()}inkey(){return this.canvasKeys.isEmpty()?0:this.charIn()}getProp(t){let e=this.owner.getString(t);return this.props[e]}drawSeq(t){this.drawCompleteSignal.reset(),postMessage(["drawseq",[t]]),this.drawCompleteSignal.wait()}}class l{divKeys;constructor(t){let[e]=t;this.divKeys=new a(e)}charIn(){return this.divKeys.readWait()}inkey(){return this.divKeys.isEmpty()?0:this.charIn()}charOut(t){postMessage(["divout",t])}}function h(t){postMessage(["debug",t])}class m{mod;constructor(t){this.mod=t}atod(t){let e=this.mod.getString(t),r=e.trimStart().toUpperCase();return"INF"==r||"+INF"==r?Number.POSITIVE_INFINITY:"-INF"==r?Number.NEGATIVE_INFINITY:Number.parseFloat(e.replaceAll("D","e").replaceAll("d","e"))}dtoa(t,e,r,s){if(-1==s){let s=r.toString();this.mod.copyString(t,e,s)}else{let i=r.toString();i.length>s&&(i=r.toPrecision(s)),this.mod.copyString(t,e,i)}}toFixed(t,e,r,s){let i=r.toFixed(s);this.mod.copyString(t,e,i)}toExponential(t,e,r,s){let i=r.toExponential(s);this.mod.copyString(t,e,i)}fcvtS(t,e,r,s,i,a){let o,n;if(0==t||0==a||0==i||e<1)return 1;let l=0;if(Number.isNaN(r))o="1#QNAN00000000000000000000000000000".slice(0,s+1),n=1;else if(Number.isFinite(r)){if(0==r)o="000000000000000000000000000000000000".slice(0,s),n=0;else{if(r<0&&(l=1,r=Math.abs(r)),s>100||r>1e21||r<1e-99)return this.mod.copyString(t,e,""),this.mod.mem32[i]=0,1;let[a="",h=""]=r.toFixed(s).split(".");"0"==a&&(a=""),a.length>0?(n=a.length,o=a+h):n=(o=h.replace(/^0+/,"")).length-h.length}}else o="1#INF00000000000000000000000000000".slice(0,s+1),n=1;return e-1new Promise(e=>{let r=this.exports.twr_malloc;e(r(t))}),this.init()}catch(t){throw console.log("WASM instantiate error: "+t+(t.stack?"\n"+t.stack:"")),t}}init(){let t;switch(this.modParams.stdio){case"debug":default:t=0;break;case"div":t=1;break;case"canvas":t=2;break;case"null":t=3}(0,this.exports.twr_wasm_init)(t,this.mem8.length)}async callC(t){let e=await this.preCallC(t),r=this.callCImpl(t[0],e);return this.postCallC(e,t),r}async callCImpl(t,e=[]){if(!this.exports)throw Error("this.exports undefined");if(!this.exports[t])throw Error("callC: function '"+t+"' not in export table. Use --export wasm-ld flag.");return(0,this.exports[t])(...e)}async preCallC(t){if(t.constructor!==Array)throw Error("callC: params must be array, first arg is function name");if(0==t.length)throw Error("callC: missing function name");let e=[],r=0;for(let s=1;s=this.mem32.length)throw Error("invalid index passed to getLong: "+t+", this.mem32.length: "+this.mem32.length);return this.mem32[e]}setLong(t,e){let r=Math.floor(t/4);if(4*r!=t)throw Error("setLong passed non long aligned address");if(r<0||r>=this.mem32.length)throw Error("invalid index passed to setLong: "+t+", this.mem32.length: "+this.mem32.length);this.mem32[r]=e}getDouble(t){let e=Math.floor(t/8);if(8*e!=t)throw Error("getLong passed non Float64 aligned address");return this.memD[e]}setDouble(t,e){let r=Math.floor(t/8);if(8*r!=t)throw Error("setDouble passed non Float64 aligned address");this.memD[r]=e}getShort(t){if(t<0||t>=this.mem8.length)throw Error("invalid index passed to getShort: "+t);return this.mem8[t]+256*this.mem8[t+1]}getString(t,e){let r="",s=0;for(;this.mem8[t+s]&&(void 0===e||s=this.mem8.length)throw Error("invalid index passed to getU8: "+t);let e=new Uint32Array(this.mem8.slice(t,t+8).buffer),r=e[0],s=e[1];if(s<0||s>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU8");if(r<0||r>this.mem8.length-s)throw Error("invalid idx.size passed to getU8");return this.mem8.slice(s,s+r)}getU32Arr(t){if(t<0||t>=this.mem8.length)throw Error("invalid index passed to getU32: "+t);let e=new Uint32Array(this.mem8.slice(t,t+8).buffer),r=e[0],s=e[1];if(s<0||s>=this.mem8.length)throw Error("invalid idx.dataptr passed to getU32");if(r<0||r>this.mem8.length-s)throw Error("invalid idx.size passed to getU32");if(r%4!=0)throw Error("idx.size is not an integer number of 32 bit words");return new Uint32Array(this.mem8.slice(s,s+r).buffer)}}class d{callCompleteSignal;parameters;constructor(t){this.callCompleteSignal=new o(t[0]),this.parameters=new Uint32Array(t[1])}sleep(t){this.callCompleteSignal.reset(),postMessage(["sleep",[t]]),this.callCompleteSignal.wait()}time(){return this.callCompleteSignal.reset(),postMessage(["time"]),this.callCompleteSignal.wait(),this.parameters[0]}}onmessage=function(t){if("startup"==t.data[0]){let e=t.data[1];(i=new f(e.modParams,e.modWorkerParams)).loadWasm(e.urlToLoad).then(()=>{postMessage(["startupOkay"])}).catch(t=>{console.log(".catch: ",t),postMessage(["startupFail",t])})}else"callC"==t.data[0]?i.callCImpl(t.data[1],t.data[2]).then(t=>{postMessage(["callCOkay",t])}).catch(t=>{console.log("exception in callC twrworker.js\n"),console.log(t),postMessage(["callCFail",t])}):console.log("twrworker.js: unknown message: "+t)};class f extends c{malloc;modParams;constructor(t,e){super(),this.isWorker=!0,this.malloc=t=>{throw Error("error - un-init malloc called")},this.modParams=t;let r=new n(e.canvasProxyParams,this),s=new l(e.divProxyParams),i=new d(e.waitingCallsProxyParams);this.modParams.imports={twrDebugLog:h,twrSleep:i.sleep.bind(i),twrTime:i.time.bind(i),twrDivCharOut:s.charOut.bind(s),twrDivCharIn:s.charIn.bind(s),twrCanvasCharIn:r.charIn.bind(r),twrCanvasInkey:r.inkey.bind(r),twrCanvasGetProp:r.getProp.bind(r),twrCanvasDrawSeq:r.drawSeq.bind(r),twrSin:Math.sin,twrCos:Math.cos,twrTan:Math.tan,twrFAbs:Math.abs,twrACos:Math.acos,twrASin:Math.asin,twrATan:Math.atan,twrExp:Math.exp,twrFloor:Math.floor,twrCeil:Math.ceil,twrFMod:function(t,e){return t%e},twrLog:Math.log,twrPow:Math.pow,twrSqrt:Math.sqrt,twrTrunc:Math.trunc,twrDtoa:this.floatUtil.dtoa.bind(this.floatUtil),twrToFixed:this.floatUtil.toFixed.bind(this.floatUtil),twrToExponential:this.floatUtil.toExponential.bind(this.floatUtil),twrAtod:this.floatUtil.atod.bind(this.floatUtil),twrFcvtS:this.floatUtil.fcvtS.bind(this.floatUtil)}}}})(); //# sourceMappingURL=twrmodworker.2165e649.js.map diff --git a/azure/examples/tests/dist/twrmodworker.2165e649.js.map b/azure/examples/tests/dist/twrmodworker.2165e649.js.map index 29a4d41e..77745e98 100644 --- a/azure/examples/tests/dist/twrmodworker.2165e649.js.map +++ b/azure/examples/tests/dist/twrmodworker.2165e649.js.map @@ -1 +1 @@ -{"mappings":"A,C,SQKK,EJgBA,EIhBA,EJgBA,MFZD,CISE,OAAO,EACZ,WAA8B,AAC9B,CAAA,GAAe,AAEf,aAAa,CAAqB,CAAlC,CACO,GAAI,AAAkB,aAAlB,OAAO,QACH,CAAC,qBAAuB,AAA+B,UAA7B,OAAO,QAAQ,CAAC,QAAQ,CAAe,MAAM,AAAI,MAAM,4DAA4D,oBAAoB,iCAErK,EAAI,IAAI,CAAC,WAAW,CAAC,EACpB,IAAI,CAAC,WAAW,CAAC,IAAI,kBAAkB,MAClD,IAAI,CAAC,GAAG,CAAC,IAAI,WAAW,IAAI,CAAC,WAAW,EAClC,IAAI,CAAC,GAAG,CArBJ,IAqBW,CAAC,EAChB,IAAI,CAAC,GAAG,CArBJ,IAqBW,CAAC,CACvB,CAEA,MAAM,CAAQ,CAA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,QAAS,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAChD,SAAU,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAE5C,CACN,CACF,C,C","sources":["","../../lib-js/twrmodworker.js","../../source/twr-wasm-ts/twrmodworker.ts","../../lib-js/twrcanvas.js","../../source/twr-wasm-ts/twrcanvas.ts","../../lib-js/twrcircular.js","../../source/twr-wasm-ts/twrcircular.ts","../../lib-js/twrsignal.js","../../source/twr-wasm-ts/twrsignal.ts","../../lib-js/twrdiv.js","../../source/twr-wasm-ts/twrdiv.ts","../../lib-js/twrdebug.js","../../source/twr-wasm-ts/twrdebug.ts","../../lib-js/twrmodbase.js","../../source/twr-wasm-ts/twrmodbase.ts","../../lib-js/twrfloat.js","../../source/twr-wasm-ts/twrfloat.ts","../../lib-js/twrwaitingcalls.js","../../source/twr-wasm-ts/twrwaitingcalls.ts","../../lib-js/twrdate.js","../../source/twr-wasm-ts/twrdate.ts"],"sourcesContent":["(() => {\nvar $3e39efa823870787$exports = {};\n// this script is the WebWorker thead used by class twrWasmAsyncModule\n//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst $892fccfc812d5e20$var$RDIDX = 256;\nconst $892fccfc812d5e20$var$WRIDX = 257;\nconst $892fccfc812d5e20$var$LEN = 256;\nclass $892fccfc812d5e20$export$a01cca24f011573a {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(1032);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[$892fccfc812d5e20$var$RDIDX] = 0;\n this.buf[$892fccfc812d5e20$var$WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[$892fccfc812d5e20$var$WRIDX];\n this.buf[i] = n;\n i++;\n if (i == $892fccfc812d5e20$var$LEN) i = 0;\n this.buf[$892fccfc812d5e20$var$WRIDX] = i;\n Atomics.notify(this.buf, $892fccfc812d5e20$var$WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[$892fccfc812d5e20$var$RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[$892fccfc812d5e20$var$RDIDX] = i;\n return n;\n } else return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[$892fccfc812d5e20$var$RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, $892fccfc812d5e20$var$WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[$892fccfc812d5e20$var$RDIDX] == this.buf[$892fccfc812d5e20$var$WRIDX];\n }\n}\n\n\n//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar $b93f1fdf40141def$var$twrSignalState;\n(function(twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})($b93f1fdf40141def$var$twrSignalState || ($b93f1fdf40141def$var$twrSignalState = {}));\nclass $b93f1fdf40141def$export$e37a7b7b851b97f3 {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == $b93f1fdf40141def$var$twrSignalState.WAITING) //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, $b93f1fdf40141def$var$twrSignalState.WAITING);\n }\n isSignaled() {\n return this.buf[0] == $b93f1fdf40141def$var$twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.WAITING;\n }\n}\n\n\nvar $c4741cac81d14197$var$D2DType;\n(function(D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})($c4741cac81d14197$var$D2DType || ($c4741cac81d14197$var$D2DType = {}));\nclass $c4741cac81d14197$export$2f298dd69cef3c34 {\n ctx;\n props = {\n charWidth: 0,\n charHeight: 0,\n foreColor: 0,\n backColor: 0,\n widthInChars: 0,\n heightInChars: 0,\n canvasHeight: 0,\n canvasWidth: 0\n };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase){\n const { forecolor: forecolor, backcolor: backcolor, fontsize: fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)();\n this.canvasKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.props,\n this.cmdCompleteSignal.sharedArray,\n this.canvasKeys.sharedArray\n ];\n }\n getProp(pn) {\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */ drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx) return;\n let ins = this.owner.getLong(ds); /* ds->start */ \n const lastins = this.owner.getLong(ds + 4); /* ds->last */ \n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while(true){\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */ \n switch(type){\n case $c4741cac81d14197$var$D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_BEGINPATH:\n this.ctx.beginPath();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILL:\n this.ctx.fill();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SAVE:\n this.ctx.save();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_RESTORE:\n this.ctx.restore();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_STROKE:\n this.ctx.stroke();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = this.owner.getLong(ins + 48) != 0;\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n } else this.precomputedObjects[id] = {\n mem8: new Uint8Array(this.owner.memory.buffer, start, length),\n width: width,\n height: height\n };\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id]) delete this.precomputedObjects[id];\n else console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n else {\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) this.ctx.putImageData(imgData, dx, dy);\n else this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */ \n if (next == 0) {\n if (ins != lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nclass $c4741cac81d14197$export$c779b2cd00544976 {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner){\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)(signalBuffer);\n this.canvasKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\n \"drawseq\",\n [\n ds\n ]\n ]);\n this.drawCompleteSignal.wait();\n }\n}\n\n\n\nclass $8963973702ae5462$export$dd376bb3f10f6896 {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611);\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase){\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) this.divKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(); // tsconfig, lib must be set to 2017 or higher\n if (this.div && !modParams.styleIsDefault) {\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.divKeys.sharedArray\n ];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */ charOut(ch) {\n if (!this.div) return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n }\n switch(ch){\n case 10:\n case 13:\n if (ch == 10 && this.lastChar == 13) break; // detect CR LF and treat as single new line\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n case 0xE:\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF:\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for(let i = 0; i < str.length; i++)this.charOut(str.charCodeAt(i));\n }\n}\nclass $8963973702ae5462$export$b377f0bbf2c7581e {\n divKeys;\n constructor(params){\n const [divKeysBuffer] = params;\n this.divKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n charOut(ch) {\n postMessage([\n \"divout\",\n ch\n ]);\n }\n}\n\n\nlet $8ac0b786da854328$var$logline = \"\";\nfunction $8ac0b786da854328$export$16b4216ec014493d(char) {\n if (char == 10 || char == 3) {\n console.log($8ac0b786da854328$var$logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n $8ac0b786da854328$var$logline = \"\";\n } else {\n $8ac0b786da854328$var$logline = $8ac0b786da854328$var$logline + String.fromCharCode(char);\n if ($8ac0b786da854328$var$logline.length >= 200) {\n console.log($8ac0b786da854328$var$logline);\n $8ac0b786da854328$var$logline = \"\";\n }\n }\n}\nfunction $8ac0b786da854328$export$485af4d0039b3389(ch) {\n postMessage([\n \"debug\",\n ch\n ]);\n}\n\n\nclass $e72303a1db04bdfa$export$918ffb7e046a537b {\n mod;\n constructor(mod){\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\") return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\") return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll(\"D\", \"e\").replaceAll(\"d\", \"e\"));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n } else {\n let r = value.toString();\n if (r.length > max_precision) r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, sizeInBytes, value, fracpart_numdigits, dec, sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1) return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) {\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (!Number.isFinite(value)) {\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n } else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split(\".\");\n if (intPart == \"0\") intPart = \"\";\n if (intPart.length > 0) {\n decpos = intPart.length;\n digits = intPart + fracPart;\n } else {\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length) return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */ }\n}\n\n\nclass $ece7fa3ed770778a$export$c83a0a3bffe07399 {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule;\n floatUtil;\n constructor(isWasmModule = false){\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new (0, $e72303a1db04bdfa$export$918ffb7e046a537b)(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/ /*********************************************************************/ async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n } catch (err) {\n console.log(\"loadWasm() failed to fetch: \" + pathToLoad);\n throw err;\n }\n if (!response.ok) throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, {\n env: allimports\n });\n this.exports = instance.instance.exports;\n if (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory) throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer) console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\n \"setmemory\",\n this.memory\n ]);\n }\n if (this.isWasmModule) // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n {\n if (!(this.memory.buffer instanceof ArrayBuffer)) console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size)=>{\n return new Promise((resolve)=>{\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n } catch (err) {\n console.log(\"WASM instantiate error: \" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch(this.modParams.stdio){\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* executeC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */ async executeC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.executeCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async executeCImpl(fname, cparams = []) {\n if (!this.exports) throw new Error(\"this.exports undefined\");\n if (!this.exports[fname]) throw new Error(\"executeC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array)) throw new Error(\"executeC: params must be array, first arg is function name\");\n if (params.length == 0) throw new Error(\"executeC: missing function name\");\n let cparams = [];\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n cparams[ci++] = p;\n break;\n case \"string\":\n cparams[ci++] = await this.putString(p);\n break;\n case \"object\":\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n } else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"executeC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n ci++;\n break;\n case \"string\":\n this.executeCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n case \"object\":\n if (p instanceof URL) {\n this.executeCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci = ci + 2;\n break;\n } else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for(let j = 0; j < u8.length; j++)u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.executeCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n } else throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/ /*********************************************************************/ // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for(i = 0; i < sin.length && i < buffer_size - 1; i++)this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for(let i = 0; i < u8a.length; i++)this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === \"object\" && fnin instanceof URL)) throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [\n dest,\n src.length\n ];\n } catch (err) {\n console.log(\"fetchAndPutURL Error. URL: \" + fnin + \"\\n\" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while(this.mem8[strIndex + i] && (len === undefined ? true : i < len) && strIndex + i < this.mem8.length){\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array(this.mem8.slice(dataptr, dataptr + size).buffer);\n return u32;\n }\n}\n\n\n\nfunction $4af5689abbc8d01b$export$78724cdcf7ebea1d() {\n return Date.now();\n}\n\n\nclass $aff9c2c494d23fe3$export$9e37856d1928d388 {\n callCompleteSignal;\n parameters;\n constructor(){\n this.callCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(()=>{\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = (0, $4af5689abbc8d01b$export$78724cdcf7ebea1d)();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [\n this.callCompleteSignal.sharedArray,\n this.parameters.buffer\n ];\n }\n processMessage(msgType, data) {\n switch(msgType){\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\nclass $aff9c2c494d23fe3$export$78d2a4633fe89379 {\n callCompleteSignal;\n parameters;\n constructor(params){\n this.callCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\n \"sleep\",\n [\n ms\n ]\n ]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\n \"time\"\n ]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n\n\nlet $3e39efa823870787$var$mod;\nonmessage = function(e) {\n //console.log('twrworker.js: message received from main script: '+e.data);\n if (e.data[0] == \"startup\") {\n const params = e.data[1];\n //console.log(\"Worker startup params:\",params);\n $3e39efa823870787$var$mod = new $3e39efa823870787$var$twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\n $3e39efa823870787$var$mod.loadWasm(params.urlToLoad).then(()=>{\n postMessage([\n \"startupOkay\"\n ]);\n }).catch((ex)=>{\n console.log(\".catch: \", ex);\n postMessage([\n \"startupFail\",\n ex\n ]);\n });\n } else if (e.data[0] == \"executeC\") $3e39efa823870787$var$mod.executeCImpl(e.data[1], e.data[2]).then((rc)=>{\n postMessage([\n \"executeCOkay\",\n rc\n ]);\n }).catch((e)=>{\n console.log(\"exception in executeC twrworker.js\\n\");\n console.log(e);\n postMessage([\n \"executeCFail\",\n e\n ]);\n });\n else console.log(\"twrworker.js: unknown message: \" + e);\n};\n// ************************************************************************\nclass $3e39efa823870787$var$twrWasmModuleInWorker extends (0, $ece7fa3ed770778a$export$c83a0a3bffe07399) {\n malloc;\n modParams;\n constructor(modParams, modInWorkerParams){\n super();\n this.isWorker = true;\n this.malloc = (size)=>{\n throw new Error(\"error - un-init malloc called\");\n };\n this.modParams = modParams;\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\n const canvasProxy = new (0, $c4741cac81d14197$export$c779b2cd00544976)(modInWorkerParams.canvasProxyParams, this);\n const divProxy = new (0, $8963973702ae5462$export$b377f0bbf2c7581e)(modInWorkerParams.divProxyParams);\n const waitingCallsProxy = new (0, $aff9c2c494d23fe3$export$78d2a4633fe89379)(modInWorkerParams.waitingCallsProxyParams);\n this.modParams.imports = {\n twrDebugLog: (0, $8ac0b786da854328$export$485af4d0039b3389),\n twrSleep: waitingCallsProxy.sleep.bind(waitingCallsProxy),\n twrTime: waitingCallsProxy.time.bind(waitingCallsProxy),\n twrDivCharOut: divProxy.charOut.bind(divProxy),\n twrDivCharIn: divProxy.charIn.bind(divProxy),\n twrCanvasCharIn: canvasProxy.charIn.bind(canvasProxy),\n twrCanvasInkey: canvasProxy.inkey.bind(canvasProxy),\n twrCanvasGetProp: canvasProxy.getProp.bind(canvasProxy),\n twrCanvasDrawSeq: canvasProxy.drawSeq.bind(canvasProxy),\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function(x, y) {\n return x % y;\n },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n}\n\n})();\n//# sourceMappingURL=twrmodworker.2165e649.js.map\n","// this script is the WebWorker thead used by class twrWasmAsyncModule\nimport { twrCanvasProxy } from \"./twrcanvas.js\";\nimport { twrDivProxy } from \"./twrdiv.js\";\nimport { twrDebugLogProxy } from \"./twrdebug.js\";\nimport { twrWasmModuleBase } from \"./twrmodbase.js\";\nimport { twrWaitingCallsProxy } from \"./twrwaitingcalls.js\";\nlet mod;\nonmessage = function (e) {\n //console.log('twrworker.js: message received from main script: '+e.data);\n if (e.data[0] == 'startup') {\n const params = e.data[1];\n //console.log(\"Worker startup params:\",params);\n mod = new twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\n mod.loadWasm(params.urlToLoad).then(() => {\n postMessage([\"startupOkay\"]);\n }).catch((ex) => {\n console.log(\".catch: \", ex);\n postMessage([\"startupFail\", ex]);\n });\n }\n else if (e.data[0] == 'executeC') {\n mod.executeCImpl(e.data[1], e.data[2]).then((rc) => {\n postMessage([\"executeCOkay\", rc]);\n }).catch(e => {\n console.log(\"exception in executeC twrworker.js\\n\");\n console.log(e);\n postMessage([\"executeCFail\", e]);\n });\n }\n else {\n console.log(\"twrworker.js: unknown message: \" + e);\n }\n};\n// ************************************************************************\nclass twrWasmModuleInWorker extends twrWasmModuleBase {\n malloc;\n modParams;\n constructor(modParams, modInWorkerParams) {\n super();\n this.isWorker = true;\n this.malloc = (size) => { throw new Error(\"error - un-init malloc called\"); };\n this.modParams = modParams;\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\n const canvasProxy = new twrCanvasProxy(modInWorkerParams.canvasProxyParams, this);\n const divProxy = new twrDivProxy(modInWorkerParams.divProxyParams);\n const waitingCallsProxy = new twrWaitingCallsProxy(modInWorkerParams.waitingCallsProxyParams);\n this.modParams.imports = {\n twrDebugLog: twrDebugLogProxy,\n twrSleep: waitingCallsProxy.sleep.bind(waitingCallsProxy),\n twrTime: waitingCallsProxy.time.bind(waitingCallsProxy),\n twrDivCharOut: divProxy.charOut.bind(divProxy),\n twrDivCharIn: divProxy.charIn.bind(divProxy),\n twrCanvasCharIn: canvasProxy.charIn.bind(canvasProxy),\n twrCanvasInkey: canvasProxy.inkey.bind(canvasProxy),\n twrCanvasGetProp: canvasProxy.getProp.bind(canvasProxy),\n twrCanvasDrawSeq: canvasProxy.drawSeq.bind(canvasProxy),\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function (x, y) { return x % y; },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n}\n//# sourceMappingURL=twrmodworker.js.map","// this script is the WebWorker thead used by class twrWasmAsyncModule\r\n\r\nimport {twrCanvasProxy} from \"./twrcanvas.js\";\r\nimport {twrDivProxy} from \"./twrdiv.js\";\r\nimport {twrDebugLogProxy} from \"./twrdebug.js\";\r\nimport {TAsyncModStartupMsg} from \"./twrmodasync.js\"\r\nimport {twrWasmModuleBase, IModInWorkerParams, IModParams} from \"./twrmodbase.js\"\r\nimport {twrWaitingCallsProxy} from \"./twrwaitingcalls.js\";\r\n\r\nlet mod:twrWasmModuleInWorker;\r\n\r\nonmessage = function(e) {\r\n //console.log('twrworker.js: message received from main script: '+e.data);\r\n\r\n if (e.data[0]=='startup') {\r\n const params:TAsyncModStartupMsg=e.data[1];\r\n //console.log(\"Worker startup params:\",params);\r\n mod=new twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\r\n\r\n mod.loadWasm(params.urlToLoad).then( ()=> {\r\n postMessage([\"startupOkay\"]);\r\n }).catch( (ex)=> {\r\n console.log(\".catch: \", ex);\r\n postMessage([\"startupFail\", ex]);\r\n });\r\n }\r\n else if (e.data[0]=='executeC') {\r\n mod.executeCImpl(e.data[1], e.data[2]).then( (rc)=> {\r\n postMessage([\"executeCOkay\", rc]);\r\n }).catch(e => {\r\n console.log(\"exception in executeC twrworker.js\\n\");\r\n console.log(e);\r\n postMessage([\"executeCFail\", e]);\r\n });\r\n }\r\n else {\r\n console.log(\"twrworker.js: unknown message: \"+e);\r\n }\r\n}\r\n\r\n\r\n// ************************************************************************\r\n\r\nclass twrWasmModuleInWorker extends twrWasmModuleBase {\r\n\tmalloc:(size:number)=>Promise;\r\n modParams: IModParams;\r\n\r\n\r\n constructor(modParams:IModParams, modInWorkerParams:IModInWorkerParams) {\r\n super();\r\n this.isWorker=true;\r\n this.malloc=(size:number)=>{throw new Error(\"error - un-init malloc called\")};\r\n this.modParams=modParams;\r\n\r\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\r\n const canvasProxy = new twrCanvasProxy(modInWorkerParams.canvasProxyParams, this);\r\n const divProxy = new twrDivProxy(modInWorkerParams.divProxyParams);\r\n const waitingCallsProxy = new twrWaitingCallsProxy(modInWorkerParams.waitingCallsProxyParams);\r\n\r\n this.modParams.imports={\r\n twrDebugLog:twrDebugLogProxy,\r\n twrSleep:waitingCallsProxy.sleep.bind(waitingCallsProxy),\r\n twrTime:waitingCallsProxy.time.bind(waitingCallsProxy),\r\n\r\n twrDivCharOut:divProxy.charOut.bind(divProxy), \r\n twrDivCharIn:divProxy.charIn.bind(divProxy), \r\n\r\n twrCanvasCharIn:canvasProxy.charIn.bind(canvasProxy),\r\n twrCanvasInkey:canvasProxy.inkey.bind(canvasProxy),\r\n twrCanvasGetProp:canvasProxy.getProp.bind(canvasProxy),\r\n twrCanvasDrawSeq:canvasProxy.drawSeq.bind(canvasProxy),\r\n\r\n\t\t\ttwrSin:Math.sin,\r\n\t\t\ttwrCos:Math.cos,\r\n\t\t\ttwrTan: Math.tan,\r\n\t\t\ttwrFAbs: Math.abs,\r\n\t\t\ttwrACos: Math.acos,\r\n\t\t\ttwrASin: Math.asin,\r\n\t\t\ttwrATan: Math.atan,\r\n\t\t\ttwrExp: Math.exp,\r\n\t\t\ttwrFloor: Math.floor,\r\n\t\t\ttwrCeil: Math.ceil,\r\n\t\t\ttwrFMod: function(x:number, y:number) {return x%y},\r\n\t\t\ttwrLog: Math.log,\r\n\t\t\ttwrPow: Math.pow,\r\n\t\t\ttwrSqrt: Math.sqrt,\r\n\t\t\ttwrTrunc: Math.trunc,\r\n\r\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\r\n\t\t\ttwrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\r\n\t\t\ttwrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\r\n\t\t\ttwrAtod: this.floatUtil.atod.bind(this.floatUtil),\r\n\t\t\ttwrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\r\n \r\n }\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nimport { twrSignal } from \"./twrsignal.js\";\nvar D2DType;\n(function (D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})(D2DType || (D2DType = {}));\nexport class twrCanvas {\n ctx;\n props = { charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight: 0, canvasWidth: 0 };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase) {\n const { forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new twrSignal();\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext)\n throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c)\n throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2)\n throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\n }\n getProp(pn) {\n if (!this.isValid())\n console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */\n drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid())\n console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx)\n return;\n let ins = this.owner.getLong(ds); /* ds->start */\n const lastins = this.owner.getLong(ds + 4); /* ds->last */\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while (1) {\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */\n if (0 /*type!=D2DType.D2D_FILLRECT*/) {\n console.log(\"ins\", ins);\n console.log(\"hdr.next\", this.owner.mem8[ins], this.owner.mem8[ins + 1], this.owner.mem8[ins + 2], this.owner.mem8[ins + 3]);\n console.log(\"hdr.type\", this.owner.mem8[ins + 4], this.owner.mem8[ins + 5]);\n console.log(\"next 4 bytes\", this.owner.mem8[ins + 6], this.owner.mem8[ins + 7], this.owner.mem8[ins + 8], this.owner.mem8[ins + 9]);\n console.log(\"and 4 more \", this.owner.mem8[ins + 10], this.owner.mem8[ins + 11], this.owner.mem8[ins + 12], this.owner.mem8[ins + 13]);\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\n }\n switch (type) {\n case D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case D2DType.D2D_BEGINPATH:\n {\n this.ctx.beginPath();\n }\n break;\n case D2DType.D2D_FILL:\n {\n this.ctx.fill();\n }\n break;\n case D2DType.D2D_SAVE:\n {\n this.ctx.save();\n }\n break;\n case D2DType.D2D_RESTORE:\n {\n this.ctx.restore();\n }\n break;\n case D2DType.D2D_STROKE:\n {\n this.ctx.stroke();\n }\n break;\n case D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = (this.owner.getLong(ins + 48) != 0);\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n }\n else { // Uint8ClampedArray doesn't support shared memory\n this.precomputedObjects[id] = { mem8: new Uint8Array(this.owner.memory.buffer, start, length), width: width, height: height };\n }\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id])\n delete this.precomputedObjects[id];\n else\n console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) {\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n }\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) {\n this.ctx.putImageData(imgData, dx, dy);\n }\n else {\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */\n if (next == 0) {\n if (ins != lastins)\n throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal)\n this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nexport class twrCanvasProxy {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner) {\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new twrSignal(signalBuffer);\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\"drawseq\", [ds]]);\n this.drawCompleteSignal.wait();\n }\n}\n//# sourceMappingURL=twrcanvas.js.map","import {twrWasmModuleBase, IModParams} from \"./twrmodbase.js\"\r\nimport {twrSharedCircularBuffer} from \"./twrcircular.js\";\r\nimport {twrSignal} from \"./twrsignal.js\";\r\n\r\n\r\n// Canvas have a size that will be set based on the character width x height\r\n// The display size for a canvas will default to this size, but can be changed in the HTML/JS via\r\n// canvas.style.width = \"700px\";\r\n// canvas.style.height = \"500px\";\r\n\r\nexport interface ICanvasProps {\r\n\tcharWidth: number,\r\n\tcharHeight: number,\r\n\tforeColor: number,\r\n\tbackColor: number,\r\n widthInChars: number,\r\n heightInChars: number,\r\n canvasWidth:number,\r\n canvasHeight:number\r\n}\r\n\r\nenum D2DType {\r\n D2D_FILLRECT=1,\r\n D2D_FILLCHAR=5,\r\n D2D_SETLINEWIDTH=10,\r\n D2D_SETFILLSTYLERGBA=11,\r\n D2D_SETFONT=12,\r\n D2D_BEGINPATH=13,\r\n D2D_MOVETO=14,\r\n D2D_LINETO=15,\r\n D2D_FILL=16,\r\n D2D_STROKE=17,\r\n D2D_SETSTROKESTYLERGBA=18,\r\n D2D_ARC=19,\r\n D2D_STROKERECT=20,\r\n D2D_FILLTEXT=21,\r\n D2D_IMAGEDATA=22,\r\n D2D_PUTIMAGEDATA=23,\r\n D2D_BEZIERTO=24,\r\n D2D_MEASURETEXT=25,\r\n D2D_SAVE=26,\r\n D2D_RESTORE=27,\r\n D2D_CREATERADIALGRADIENT=28,\r\n D2D_SETCOLORSTOP=29,\r\n D2D_SETFILLSTYLEGRADIENT=30,\r\n D2D_RELEASEID=31,\r\n D2D_CREATELINEARGRADIENT=32,\r\n D2D_SETFILLSTYLE=33,\r\n D2D_SETSTROKESTYLE=34\r\n\r\n}\r\n\r\nexport type TCanvasProxyParams = [ICanvasProps, SharedArrayBuffer, SharedArrayBuffer];\r\n\r\nexport interface ICanvas {\r\n props: ICanvasProps,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TCanvasProxyParams,\r\n drawSeq: (ds:number)=>void,\r\n }\r\n \r\nexport class twrCanvas implements ICanvas {\r\n ctx:CanvasRenderingContext2D|undefined;\r\n props:ICanvasProps={charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight:0, canvasWidth:0};\r\n owner: twrWasmModuleBase;\r\n cmdCompleteSignal?:twrSignal;\r\n canvasKeys?: twrSharedCircularBuffer;\r\n precomputedObjects: { [index: number]: \r\n (ImageData | {mem8:Uint8Array, width:number, height:number}) |\r\n CanvasGradient\r\n };\r\n\r\n constructor(element:HTMLCanvasElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n const {forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas} = modParams; \r\n this.owner=modbase;\r\n this.props.widthInChars=modParams.windim[0];\r\n this.props.heightInChars=modParams.windim[1];\r\n\r\n if (!this.owner.isWasmModule) {\r\n this.cmdCompleteSignal=new twrSignal();\r\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n }\r\n\r\n this.precomputedObjects={};\r\n \r\n if (element) {\r\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\r\n let c=element.getContext(\"2d\");\r\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\r\n\r\n c.font = fontsize.toString()+\"px Courier New\";\r\n c.textBaseline=\"top\";\r\n const sampleText=\" \";\r\n const tm=c.measureText(sampleText);\r\n this.props.charWidth=Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\r\n let fM = c.measureText(\"X\"); \r\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\r\n\r\n if (!isd2dcanvas) {\r\n element.width=this.props.charWidth*this.props.widthInChars;\r\n element.height=this.props.charHeight*this.props.heightInChars;\r\n }\r\n\r\n this.props.canvasHeight=element.height;\r\n this.props.canvasWidth=element.width;\r\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\r\n\r\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\r\n let c2=element.getContext(\"2d\");\r\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\r\n this.ctx=c2;\r\n this.ctx.font = fontsize.toString()+\"px Courier New\";\r\n this.ctx.textBaseline=\"top\";\r\n\r\n c2.fillStyle=backcolor;\r\n this.props.backColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n c2.fillStyle=forecolor;\r\n this.props.foreColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n }\r\n\r\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\r\n\r\n //console.log(\"twrCanvas.constructor props: \", this.props);\r\n }\r\n\r\n isValid() {\r\n return !!this.ctx;\r\n }\r\n\r\n getProxyParams() : TCanvasProxyParams {\r\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\r\n }\r\n\r\n getProp(pn:number): number {\r\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n\r\n/* see draw2d.h for structs that match */\r\n\r\n drawSeq(ds:number) {\r\n //console.log(\"twr::Canvas enter drawSeq\");\r\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\r\n if (!this.ctx) return;\r\n\r\n let ins=this.owner.getLong(ds); /* ds->start */\r\n const lastins=this.owner.getLong(ds+4); /* ds->last */\r\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\r\n\r\n let next:number;\r\n //let insCount=0;\r\n\r\n while (1) {\r\n\r\n //insCount++;\r\n\r\n const type:D2DType=this.owner.getLong(ins+4); /* hdr->type */\r\n if (0/*type!=D2DType.D2D_FILLRECT*/) {\r\n console.log(\"ins\",ins)\r\n console.log(\"hdr.next\",this.owner.mem8[ins],this.owner.mem8[ins+1],this.owner.mem8[ins+2],this.owner.mem8[ins+3]);\r\n console.log(\"hdr.type\",this.owner.mem8[ins+4],this.owner.mem8[ins+5]);\r\n console.log(\"next 4 bytes\", this.owner.mem8[ins+6],this.owner.mem8[ins+7],this.owner.mem8[ins+8],this.owner.mem8[ins+9]);\r\n console.log(\"and 4 more \", this.owner.mem8[ins+10],this.owner.mem8[ins+11],this.owner.mem8[ins+12],this.owner.mem8[ins+13]);\r\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\r\n }\r\n switch (type) {\r\n case D2DType.D2D_FILLRECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.fillRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKERECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.strokeRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILLCHAR:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const c=this.owner.getShort(ins+24);\r\n let txt=String.fromCharCode(c);\r\n this.ctx.fillText(txt, x, y);\r\n }\r\n break;\r\n\r\n \r\n case D2DType.D2D_FILLTEXT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const str=this.owner.getString(this.owner.getLong(ins+24));\r\n\r\n //console.log(\"filltext \",x,y,str)\r\n \r\n this.ctx.fillText(str, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MEASURETEXT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n const tmidx=this.owner.getLong(ins+12);\r\n \r\n const tm=this.ctx.measureText(str);\r\n this.owner.setDouble(tmidx+0, tm.actualBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+8, tm.actualBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+16, tm.actualBoundingBoxLeft);\r\n this.owner.setDouble(tmidx+24, tm.actualBoundingBoxRight);\r\n this.owner.setDouble(tmidx+32, tm.fontBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+40, tm.fontBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+48, tm.width);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFONT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.font=str;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.fillStyle = cssColor;\r\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETSTROKESTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.fillStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETSTROKESTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETLINEWIDTH:\r\n {\r\n const width=this.owner.getShort(ins+8); \r\n this.ctx.lineWidth=width;\r\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MOVETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.moveTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_LINETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.lineTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEZIERTO:\r\n {\r\n const cp1x=this.owner.getDouble(ins+8);\r\n const cp1y=this.owner.getDouble(ins+16);\r\n const cp2x=this.owner.getDouble(ins+24);\r\n const cp2y=this.owner.getDouble(ins+32);\r\n const x=this.owner.getDouble(ins+40);\r\n const y=this.owner.getDouble(ins+48);\r\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEGINPATH:\r\n {\r\n this.ctx.beginPath();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILL:\r\n {\r\n this.ctx.fill();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SAVE:\r\n {\r\n this.ctx.save();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_RESTORE:\r\n {\r\n this.ctx.restore();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKE:\r\n {\r\n this.ctx.stroke();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_ARC:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const radius=this.owner.getDouble(ins+24);\r\n const startAngle=this.owner.getDouble(ins+32);\r\n const endAngle=this.owner.getDouble(ins+40);\r\n const counterClockwise= (this.owner.getLong(ins+48)!=0);\r\n\r\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_IMAGEDATA:\r\n {\r\n const start=this.owner.getLong(ins+8);\r\n const length=this.owner.getLong(ins+12);\r\n const width=this.owner.getLong(ins+16);\r\n const height=this.owner.getLong(ins+20);\r\n const id=this.owner.getLong(ins+24);\r\n\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\r\n\r\n if (this.owner.isWasmModule) {\r\n const z = new Uint8ClampedArray(this.owner.memory!.buffer, start, length);\r\n this.precomputedObjects[id]=new ImageData(z, width, height);\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory\r\n this.precomputedObjects[id]={mem8: new Uint8Array(this.owner.memory!.buffer, start, length), width:width, height:height};\r\n }\r\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_CREATERADIALGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const radius0=this.owner.getDouble(ins+24);\r\n const x1=this.owner.getDouble(ins+32);\r\n const y1=this.owner.getDouble(ins+40);\r\n const radius1=this.owner.getDouble(ins+48);\r\n const id= this.owner.getLong(ins+56);\r\n\r\n let gradient=this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_CREATELINEARGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const x1=this.owner.getDouble(ins+24);\r\n const y1=this.owner.getDouble(ins+32);\r\n const id= this.owner.getLong(ins+40);\r\n \r\n let gradient=this.ctx.createLinearGradient(x0, y0, x1, y1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETCOLORSTOP:\r\n {\r\n const id = this.owner.getLong(ins+8);\r\n const pos=this.owner.getLong(ins+12);\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+16));\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n gradient.addColorStop(pos, cssColor);\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n this.ctx.fillStyle=gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_RELEASEID:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (this.precomputedObjects[id])\r\n delete this.precomputedObjects[id];\r\n else\r\n console.log(\"warning: D2D_RELEASEID with undefined ID \",id);\r\n }\r\n break\r\n\r\n \r\n\r\n case D2DType.D2D_PUTIMAGEDATA:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n const dx=this.owner.getLong(ins+12);\r\n const dy=this.owner.getLong(ins+16);\r\n const dirtyX=this.owner.getLong(ins+20);\r\n const dirtyY=this.owner.getLong(ins+24);\r\n const dirtyWidth=this.owner.getLong(ins+28);\r\n const dirtyHeight=this.owner.getLong(ins+32);\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \"+id);\r\n\r\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\r\n\r\n let imgData:ImageData;\r\n if (this.owner.isWasmModule) {\r\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\r\n imgData=this.precomputedObjects[id] as ImageData;\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\r\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\r\n const z = this.precomputedObjects[id] as {mem8:Uint8Array, width:number, height:number}; // Uint8Array\r\n const ca=Uint8ClampedArray.from(z.mem8); // shallow copy\r\n imgData=new ImageData(ca, z.width, z.height);\r\n }\r\n \r\n if (dirtyWidth==0 && dirtyHeight==0) {\r\n this.ctx.putImageData(imgData, dx, dy);\r\n }\r\n else {\r\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\r\n }\r\n }\r\n break;\r\n\r\n default:\r\n throw new Error (\"unimplemented or unknown Sequence Type in drawSeq: \"+type);\r\n }\r\n next=this.owner.getLong(ins); /* hdr->next */\r\n if (next==0) {\r\n if (ins!=lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\r\n break;\r\n }\r\n ins=next;\r\n }\r\n\r\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\r\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\r\n }\r\n}\r\n\r\nexport class twrCanvasProxy implements ICanvas {\r\n canvasKeys: twrSharedCircularBuffer;\r\n drawCompleteSignal:twrSignal;\r\n props: ICanvasProps;\r\n owner: twrWasmModuleBase;\r\n\r\n constructor(params:TCanvasProxyParams, owner:twrWasmModuleBase) {\r\n const [props, signalBuffer, canvasKeysBuffer] = params;\r\n this.drawCompleteSignal = new twrSignal(signalBuffer);\r\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\r\n this.props=props;\r\n this.owner=owner;\r\n\r\n //console.log(\"Create New twrCanvasProxy: \",this.props)\r\n\r\n }\r\n\r\n charIn() { \r\n //ctx.commit(); not avail in chrome\r\n \r\n //postMessage([\"debug\", 'x']);\r\n \r\n return this.canvasKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.canvasKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n getProp(pn:number): number {\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n \r\n drawSeq(ds:number) {\r\n this.drawCompleteSignal.reset();\r\n postMessage([\"drawseq\", [ds]]);\r\n this.drawCompleteSignal.wait();\r\n }\r\n}\r\n","//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst RDIDX = 256;\nconst WRIDX = 257;\nconst LEN = 256;\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\n// the first 256 array entries are the circular buffer\n// the next two are used for the read and write index\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\nexport class twrSharedCircularBuffer {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(258 * 4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[RDIDX] = 0;\n this.buf[WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[WRIDX];\n this.buf[i] = n;\n i++;\n if (i == LEN)\n i = 0;\n this.buf[WRIDX] = i;\n Atomics.notify(this.buf, WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[RDIDX] = i;\n return n;\n }\n else\n return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[RDIDX] == this.buf[WRIDX];\n }\n}\n//# sourceMappingURL=twrcircular.js.map","//\r\n// This class implements a circular buffer that the main javascript thread can write to, \r\n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\r\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \r\n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\r\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\r\n//\r\n\r\nconst RDIDX=256;\r\nconst WRIDX=257;\r\nconst LEN=256;\r\n\r\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\r\n// the first 256 array entries are the circular buffer\r\n// the next two are used for the read and write index\r\n\r\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\r\n\r\nexport class twrSharedCircularBuffer {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n \r\n\tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(258*4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[RDIDX]=0;\r\n this.buf[WRIDX]=0;\r\n\t}\r\n\r\n\twrite(n:number) {\r\n let i=this.buf[WRIDX];\r\n this.buf[i]=n;\r\n i++;\r\n if (i==LEN) i=0;\r\n this.buf[WRIDX]=i; \r\n Atomics.notify(this.buf, WRIDX); \r\n\t}\r\n\r\n\tread():number {\r\n if (!this.isEmpty()) {\r\n let i=this.buf[RDIDX];\r\n let n=this.buf[i];\r\n i++;\r\n this.buf[RDIDX]=i;\r\n return n;\r\n }\r\n\t\telse\r\n return -1;\r\n\t}\r\n\r\n readWait():number {\r\n if (this.isEmpty()) {\r\n const rdptr=this.buf[RDIDX];\r\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\r\n Atomics.wait(this.buf, WRIDX, rdptr);\r\n }\r\n return this.read();\r\n\t}\r\n\r\n isEmpty():boolean {\r\n return this.buf[RDIDX]==this.buf[WRIDX];\r\n }\r\n}\r\n","//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar twrSignalState;\n(function (twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})(twrSignalState || (twrSignalState = {}));\n;\nexport class twrSignal {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window valid\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == twrSignalState.WAITING) {\n //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\n //console.log(\"released...\");\n }\n }\n isSignaled() {\n return this.buf[0] == twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = twrSignalState.WAITING;\n }\n}\n//# sourceMappingURL=twrsignal.js.map","//\r\n// This class implements a simple signal/wait mechanism\r\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\r\n//\r\n\r\nenum twrSignalState {\r\n WAITING=0,\r\n SIGNALED=1\r\n};\r\n\r\nexport class twrSignal {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n\r\n \tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window valid\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) \r\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[0]=twrSignalState.WAITING;\r\n\t}\r\n\r\n\tsignal() {\r\n this.buf[0]=twrSignalState.SIGNALED; \r\n //console.log(\"about to signal\");\r\n Atomics.notify(this.buf, 0); \r\n\t}\r\n\r\n wait() {\r\n if (this.buf[0]==twrSignalState.WAITING) {\r\n //console.log(\"waiting...\");\r\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\r\n //console.log(\"released...\");\r\n\r\n }\r\n\t}\r\n isSignaled():boolean {\r\n return this.buf[0]==twrSignalState.SIGNALED;\r\n }\r\n\r\n reset() {\r\n this.buf[0]=twrSignalState.WAITING;\r\n }\r\n}\r\n","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nexport class twrDiv {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase) {\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\n this.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n if (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.divKeys.sharedArray];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */\n charOut(ch) {\n if (!this.div)\n return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n }\n switch (ch) {\n case 10: // newline\n case 13: // return\n if (ch == 10 && this.lastChar == 13)\n break; // detect CR LF and treat as single new line\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8: // backspace\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n case 0xE: // cursor on\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF: // cursor off\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for (let i = 0; i < str.length; i++)\n this.charOut(str.charCodeAt(i));\n }\n}\nexport class twrDivProxy {\n divKeys;\n constructor(params) {\n const [divKeysBuffer] = params;\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n charOut(ch) {\n postMessage([\"divout\", ch]);\n }\n}\n//# sourceMappingURL=twrdiv.js.map","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\r\nimport { IModParams } from \"./twrmodbase.js\";\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\";\r\n\r\nexport type TDivProxyParams = [SharedArrayBuffer];\r\n\r\nexport interface IDiv {\r\n charOut: (ds:number)=>void,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TDivProxyParams,\r\n }\r\n\r\n\r\nexport class twrDiv implements IDiv {\r\n\tdiv:HTMLDivElement|null|undefined;\r\n\tdivKeys?:twrSharedCircularBuffer;\r\n\tCURSOR=String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\r\n\tcursorOn:boolean=false;\r\n\tlastChar:number=0;\r\n\textraBR:boolean=false;\r\n\towner:twrWasmModuleBase;\r\n\r\n constructor(element:HTMLDivElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n\t\tthis.div=element;\r\n\t\tthis.owner=modbase;\r\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\r\n\t\t\tthis.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n\t\t}\r\n\r\n\t\tif (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\r\n\t\t\tthis.div.style.backgroundColor = modParams.backcolor;\r\n\t\t\tthis.div.style.color = modParams.forecolor;\r\n\t\t\tthis.div.style.font=modParams.fontsize.toString()+\"px arial\"\r\n\t\t}\r\n }\r\n\r\n\tisValid() {\r\n\t\treturn !!this.div;\r\n\t}\r\n\r\n getProxyParams() : TDivProxyParams {\r\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [ this.divKeys.sharedArray];\r\n }\r\n\r\n\r\n/* \r\n * add character to div. Supports the following control codes:\r\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\r\n * 0xE cursor on \r\n * 0x8 backspace\r\n * 0xF cursor off \r\n*/\r\n\tcharOut(ch:number) {\r\n\r\n\t\tif (!this.div) return;\r\n\r\n\t\t//console.log(\"div::charout: \", ch);\r\n\r\n\t\tif (this.extraBR) {\r\n\t\t\tthis.extraBR=false;\r\n\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -4);\r\n\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t}\r\n\r\n\t\tswitch (ch) {\r\n\t\t\tcase 10: // newline\r\n\t\t\tcase 13: // return\r\n\t\t\t\tif (ch==10 && this.lastChar==13) break; // detect CR LF and treat as single new line\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\r\n\t\t\t\tthis.extraBR=true;\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\t//element.scrollIntoView();\r\n\t\t\t\t//element.scrollTop = element.scrollHeight;\r\n\t\t\t\tlet p = this.div.getBoundingClientRect();\r\n\t\t\t\twindow.scrollTo(0, p.height+100);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 8: // backspace\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xE: // cursor on\r\n\t\t\t\tif (!this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=true;\r\n\t\t\t\t\tthis.div.innerHTML += this.CURSOR;\r\n\t\t\t\t\tthis.div.focus();\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xF: // cursor off\r\n\t\t\t\tif (this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=false;\r\n\t\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += String.fromCharCode(ch);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\tthis.lastChar=ch;\r\n\t}\r\n\r\n\tstringOut(str:string) {\r\n\t\tfor (let i=0; i < str.length; i++)\r\n\t\t\tthis.charOut(str.charCodeAt(i));\r\n\t}\r\n}\r\n\r\n\r\nexport class twrDivProxy implements IDiv {\r\n divKeys: twrSharedCircularBuffer;\r\n\r\n constructor(params:TDivProxyParams) {\r\n const [divKeysBuffer] = params;\r\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\r\n }\r\n\r\n charIn() { \r\n return this.divKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.divKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n\tcharOut(ch:number) {\r\n\t\tpostMessage([\"divout\", ch]);\r\n\t}\r\n}\r\n\r\n","let logline = \"\";\nexport function twrDebugLogImpl(char) {\n if (char == 10 || char == 3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\n console.log(logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n logline = \"\";\n }\n else {\n logline = logline + String.fromCharCode(char);\n if (logline.length >= 200) {\n console.log(logline);\n logline = \"\";\n }\n }\n}\n// ************************************************************************\n// debugLog doesn't currently wait for the message to log, it returns immediately.\n// I could move this to be in the twrWaitingCalls class\nexport function twrDebugLogProxy(ch) {\n postMessage([\"debug\", ch]);\n}\n//# sourceMappingURL=twrdebug.js.map","\r\nlet logline=\"\";\r\nexport function twrDebugLogImpl(char:number) {\r\n\tif (char==10 || char==3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\r\n\t\tconsole.log(logline);\t// ideally without a linefeed, but there is no way to not have a LF with console.log API.\r\n\t\tlogline=\"\";\r\n\t}\r\n\telse {\r\n\t\tlogline=logline+String.fromCharCode(char);\r\n\t\tif (logline.length>=200) {\r\n\t\t\tconsole.log(logline);\r\n\t\t\tlogline=\"\";\r\n\t\t}\r\n\t}\r\n}\r\n\r\n// ************************************************************************\r\n// debugLog doesn't currently wait for the message to log, it returns immediately.\r\n// I could move this to be in the twrWaitingCalls class\r\nexport function twrDebugLogProxy(ch:number) {\r\n postMessage([\"debug\", ch]);\r\n}\r\n\r\n","import { twrFloatUtil } from \"./twrfloat.js\";\n/*********************************************************************/\n/*********************************************************************/\n/*********************************************************************/\nexport class twrWasmModuleBase {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\n floatUtil;\n constructor(isWasmModule = false) {\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new twrFloatUtil(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/\n /*********************************************************************/\n async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n }\n catch (err) {\n console.log('loadWasm() failed to fetch: ' + pathToLoad);\n throw err;\n }\n if (!response.ok)\n throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, { env: allimports });\n this.exports = instance.instance.exports;\n if (!this.exports)\n throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory)\n throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory)\n throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer)\n console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\"setmemory\", this.memory]);\n }\n if (this.isWasmModule) {\n // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (!(this.memory.buffer instanceof ArrayBuffer))\n console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size) => {\n return new Promise(resolve => {\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n }\n catch (err) {\n console.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch (this.modParams.stdio) {\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* executeC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */\n async executeC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.executeCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async executeCImpl(fname, cparams = []) {\n if (!this.exports)\n throw new Error(\"this.exports undefined\");\n if (!this.exports[fname])\n throw new Error(\"executeC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array))\n throw new Error(\"executeC: params must be array, first arg is function name\");\n if (params.length == 0)\n throw new Error(\"executeC: missing function name\");\n let cparams = [];\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n cparams[ci++] = p;\n break;\n case 'string':\n cparams[ci++] = await this.putString(p);\n break;\n case 'object':\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n }\n else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"executeC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n ci++;\n break;\n case 'string':\n this.executeCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n case 'object':\n if (p instanceof URL) {\n this.executeCImpl('twr_free', [cparams[ci]]);\n ci = ci + 2;\n break;\n }\n else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for (let j = 0; j < u8.length; j++)\n u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.executeCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n }\n else\n throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/\n /*********************************************************************/\n // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for (i = 0; i < sin.length && i < buffer_size - 1; i++)\n this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for (let i = 0; i < u8a.length; i++)\n this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === 'object' && fnin instanceof URL))\n throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [dest, src.length];\n }\n catch (err) {\n console.log('fetchAndPutURL Error. URL: ' + fnin + '\\n' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while (this.mem8[strIndex + i] && (len === undefined ? true : i < len) && (strIndex + i) < this.mem8.length) {\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0)\n throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array((this.mem8.slice(dataptr, dataptr + size)).buffer);\n return u32;\n }\n}\n//# sourceMappingURL=twrmodbase.js.map","\r\nimport {TCanvasProxyParams} from \"./twrcanvas.js\"\r\nimport {TDivProxyParams} from \"./twrdiv.js\";\r\nimport {TWaitingCallsProxyParams} from \"./twrwaitingcalls.js\"\r\nimport {twrDebugLogImpl} from \"./twrdebug.js\";\r\nimport {twrFloatUtil} from \"./twrfloat.js\";\r\n\r\n\r\nexport type TStdioVals=\"div\"|\"canvas\"|\"null\"|\"debug\";\r\n\r\nexport interface IModOpts {\r\n\tstdio?:TStdioVals, \r\n\twindim?:[number, number],\r\n\tforecolor?:string,\r\n\tbackcolor?:string,\r\n\tfontsize?:number,\r\n\tisd2dcanvas?:boolean,\r\n\timports?:{},\r\n}\r\n\r\nexport interface IModParams {\r\n\tstdio:TStdioVals, \r\n\twindim:[number, number],\r\n\tforecolor:string,\r\n\tbackcolor:string,\r\n\tfontsize:number,\r\n\tstyleIsDefault: boolean\r\n\tisd2dcanvas:boolean,\r\n\timports:{[index:string]:Function},\r\n}\r\n\r\nexport interface IModInWorkerParams {\r\n\tdivProxyParams:TDivProxyParams,\r\n\tcanvasProxyParams:TCanvasProxyParams,\r\n\twaitingCallsProxyParams:TWaitingCallsProxyParams,\r\n}\r\n\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n\r\nexport abstract class twrWasmModuleBase {\r\n\tmemory?:WebAssembly.Memory;\r\n\tmem8:Uint8Array;\r\n\tmem32:Uint32Array;\r\n\tmemD:Float64Array;\r\n\tabstract malloc:(size:number)=>Promise;\r\n\tabstract modParams:IModParams;\r\n\texports?:WebAssembly.Exports;\r\n\tisWorker=false;\r\n\tisWasmModule:boolean; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\r\n\tfloatUtil:twrFloatUtil;\r\n\r\n\tconstructor(isWasmModule=false) {\r\n\t\tthis.isWasmModule=isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\r\n\t\tthis.mem8=new Uint8Array(); \t// avoid type errors\r\n\t\tthis.mem32=new Uint32Array(); // avoid type errors\r\n\t\tthis.memD=new Float64Array(); // avoid type errors\r\n\t\tthis.floatUtil=new twrFloatUtil(this);\r\n\t\t//console.log(\"size of mem8 after constructor\",this.mem8.length);\r\n\t}\r\n\r\n\t/*********************************************************************/\r\n\t/*********************************************************************/\r\n\r\n\tasync loadWasm(pathToLoad:string) {\r\n\t\t//console.log(\"fileToLoad\",fileToLoad)\r\n\r\n\t\tlet response;\r\n\t\ttry {\r\n\t\t\tresponse=await fetch(pathToLoad);\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('loadWasm() failed to fetch: '+pathToLoad);\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t\t\r\n\t\tif (!response.ok) throw new Error(\"fetch response error on file '\"+pathToLoad+\"'\\n\"+response.statusText);\r\n\r\n\t\ttry {\r\n\t\t\tlet wasmBytes = await response.arrayBuffer();\r\n\r\n\t\t\tlet allimports:WebAssembly.ModuleImports = { \r\n\t\t\t\t...this.modParams.imports\r\n\t\t\t};\r\n\r\n\t\t\tlet instance = await WebAssembly.instantiate(wasmBytes, {env: allimports});\r\n\r\n\t\t\tthis.exports=instance.instance.exports;\r\n\t\t\tif (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\r\n\r\n\t\t\tif (this.memory) throw new Error (\"unexpected error -- this.memory already set\");\r\n\t\t\tthis.memory=this.exports.memory as WebAssembly.Memory;\r\n\t\t\tif (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\r\n\t\t\tthis.mem8 = new Uint8Array(this.memory.buffer);\r\n\t\t\tthis.mem32 = new Uint32Array(this.memory.buffer);\r\n\t\t\tthis.memD = new Float64Array(this.memory.buffer);\r\n\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\tif (this.isWorker) {\r\n\t\t\t\tif (this.memory.buffer instanceof ArrayBuffer)\r\n\t\t\t\t\tconsole.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\r\n\t\t\t\t\r\n\t\t\t\tpostMessage([\"setmemory\",this.memory]);\r\n\t\t\t}\r\n\t\t\tif (this.isWasmModule) {\r\n\t\t\t\t// here if twrWasmModule, twrWasmModuleAsync overrides this function\r\n\t\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\t\tif (!(this.memory.buffer instanceof ArrayBuffer))\r\n\t\t\t\t\tconsole.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\r\n\t\t\t}\r\n\r\n\t\t\tthis.malloc=(size:number)=>{\r\n\t\t\t\treturn new Promise(resolve => {\r\n\t\t\t\t\tconst m=this.exports!.twr_malloc as (size:number)=>number;\r\n\t\t\t\t\tresolve(m(size));\r\n\t\t\t\t});\r\n\t\t };\r\n\r\n\t\t\tthis.init();\r\n\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t}\r\n\r\n\tprivate init() {\r\n\t\t//console.log(\"loadWasm.init() enter\")\r\n\t\t\tlet p:number;\r\n\t\t\tswitch (this.modParams.stdio) {\r\n\t\t\t\tcase \"debug\":\r\n\t\t\t\t\tp=0;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"div\":\r\n\t\t\t\t\tp=1;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"canvas\":\r\n\t\t\t\t\tp=2;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"null\":\r\n\t\t\t\t\tp=3;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tp=0; // debug\r\n\t\t\t}\r\n\r\n\t\t\tconst twrInit=this.exports!.twr_wasm_init as CallableFunction;\r\n\t\t\t//console.log(\"twrInit:\",twrInit)\r\n\t\t\ttwrInit(p, this.mem8.length);\r\n\t}\r\n\r\n\t/* executeC takes an array where:\r\n\t* the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\r\n\t* and the next entries are a variable number of parameters to pass to the C function, of type\r\n\t* number - converted to int32 or float64 as appropriate\r\n\t* string - converted to a an index (ptr) into a module Memory returned via stringToMem()\r\n\t* URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\r\n\t* Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\r\n */\r\n\r\n\tasync executeC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\t\tconst cparams=await this.preCallC(params);\r\n\t\tlet retval = this.executeCImpl(params[0], cparams);\r\n\t\tthis.postCallC(cparams, params);\r\n\t\treturn retval;\r\n\t}\r\n\r\n\tasync executeCImpl(fname:string, cparams:number[]=[]) {\r\n\t\tif (!this.exports) throw new Error(\"this.exports undefined\");\r\n\t\tif (!this.exports[fname]) throw new Error(\"executeC: function '\"+fname+\"' not in export table. Use --export wasm-ld flag.\");\r\n\r\n\t\tconst f = this.exports[fname] as CallableFunction;\r\n\t\tlet cr=f(...cparams);\r\n\r\n\t\treturn cr;\r\n\t}\r\n\r\n\t// convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\r\n\tasync preCallC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tif (!(params.constructor === Array)) throw new Error (\"executeC: params must be array, first arg is function name\");\r\n\t\tif (params.length==0) throw new Error(\"executeC: missing function name\");\r\n\r\n\t\tlet cparams:number[]=[];\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tcparams[ci++]=p;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tcparams[ci++]=await this.putString(p);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tconst r=await this.fetchAndPutURL(p);\r\n\t\t\t\t\t\tcparams[ci++]=r[0]; // mem index\r\n\t\t\t\t\t\tcparams[ci++]=r[1]; // len\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tconst r=await this.putArrayBuffer(p);\r\n\t\t\t\t\t\tcparams[ci++]=r; // mem index\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tthrow new Error (\"executeC: invalid object type passed in\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn cparams;\r\n\t}\r\n\r\n\t// free the mallocs; copy array buffer data from malloc back to arraybuffer\r\n\tasync postCallC(cparams:number[], params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tthis.executeCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t\t\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tthis.executeCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\t\tci=ci+2;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tlet u8=new Uint8Array(p);\r\n\t\t\t\t\t\tfor (let j=0; j= this.mem32.length) throw new Error(\"invalid index passed to getLong: \"+idx+\", this.mem32.length: \"+this.mem32.length);\r\n\t\tconst long:number = this.mem32[idx32];\r\n\t\treturn long;\r\n\t}\r\n\t\r\n\tsetLong(idx:number, value:number) {\r\n const idx32 = Math.floor(idx / 4);\r\n if (idx32 * 4 != idx)\r\n throw new Error(\"setLong passed non long aligned address\");\r\n if (idx32 < 0 || idx32 >= this.mem32.length)\r\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\r\n this.mem32[idx32]=value;\r\n }\r\n\r\n\tgetDouble(idx:number): number {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"getLong passed non Float64 aligned address\")\r\n\t\tconst long:number = this.memD[idx64];\r\n\t\treturn long;\r\n\t}\r\n\r\n\tsetDouble(idx:number, value:number) {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"setDouble passed non Float64 aligned address\")\r\n\t\tthis.memD[idx64]=value;\r\n\t}\r\n\r\n\tgetShort(idx:number): number {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getShort: \"+idx);\r\n\t\tconst short:number = this.mem8[idx]+this.mem8[idx+1]*256;\r\n\t\treturn short;\r\n\t}\r\n\r\n\t// get a string out of module memory\r\n\t// null terminated, up until max of (optional) len\r\n\tgetString(strIndex:number, len?:number): string {\r\n\t\tlet sout=\"\";\r\n\r\n\t\tlet i=0;\r\n\t\twhile (this.mem8[strIndex+i] && (len===undefined?true:i= this.mem8.length) throw new Error(\"invalid index passed to getU8: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU8\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU8\")\r\n\r\n\t\tconst u8=this.mem8.slice(dataptr, dataptr+size);\r\n\t\treturn u8;\r\n\t}\r\n\r\n\t// get a int32 array out of module memory when passed in index to [size, dataptr]\r\n\tgetU32Arr(idx:number): Uint32Array {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getU32: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU32\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU32\")\r\n\r\n\t\tif (size%4!=0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\r\n\r\n\t\tconst u32 = new Uint32Array( (this.mem8.slice(dataptr, dataptr+size)).buffer );\r\n\t\treturn u32;\r\n\t}\r\n}\r\n","export class twrFloatUtil {\n mod;\n constructor(mod) {\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\")\n return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\")\n return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll('D', 'e').replaceAll('d', 'e'));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n }\n else {\n let r = value.toString();\n if (r.length > max_precision)\n r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, // char *\n sizeInBytes, //size_t\n value, // double\n fracpart_numdigits, //int\n dec, // int *\n sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1)\n return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) { /* nan */\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (!Number.isFinite(value)) { /* infinity */\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n }\n else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split('.');\n if (intPart == \"0\")\n intPart = \"\";\n if (intPart.length > 0) { // has integer part\n decpos = intPart.length;\n digits = intPart + fracPart;\n }\n else { // only a fraction\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length)\n return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */\n }\n}\n//# sourceMappingURL=twrfloat.js.map","\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\"\r\n\r\nexport class twrFloatUtil {\r\n mod: twrWasmModuleBase;\r\n\r\n constructor(mod: twrWasmModuleBase) {\r\n this.mod=mod;\r\n }\r\n\r\n atod(strptr:number):number {\r\n const str=this.mod.getString(strptr);\r\n\r\n const upper=str.trimStart().toUpperCase();\r\n if (upper==\"INF\" || upper==\"+INF\")\r\n return Number.POSITIVE_INFINITY;\r\n else if (upper==\"-INF\")\r\n return Number.NEGATIVE_INFINITY\r\n else {\r\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\r\n const r=Number.parseFloat(str.replaceAll('D','e').replaceAll('d','e'));\r\n return r;\r\n }\r\n }\r\n\r\n dtoa(buffer:number, buffer_size:number, value:number, max_precision:number):void {\r\n if (max_precision==-1) {\r\n const r=value.toString();\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n else {\r\n let r=value.toString();\r\n if (r.length>max_precision)\r\n r=value.toPrecision(max_precision);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n }\r\n\r\n toFixed(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toFixed(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n toExponential(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toExponential(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\r\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\r\n // Negative exponents must be now smaller than 1e-99\r\n // fully-function C version also int he source, but this is the version enabled by default\r\n fcvtS(\r\n buffer:number, // char *\r\n sizeInBytes:number, //size_t\r\n value:number, // double\r\n fracpart_numdigits:number, //int\r\n dec:number, // int *\r\n sign:number // int *\r\n ):number {\r\n\r\n if (buffer==0 ||sign==0 || dec==0 || sizeInBytes<1) return 1;\r\n\r\n let digits:string;\r\n let decpos:number;\r\n let s=0; // default to positive\r\n\r\n\r\n if (Number.isNaN(value)) { /* nan */\r\n digits=\"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (!Number.isFinite(value)) { /* infinity */\r\n digits=\"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (value==0) { \r\n digits=\"000000000000000000000000000000000000\".slice(0,fracpart_numdigits);\r\n decpos=0;\r\n }\r\n \r\n else {\r\n\r\n if (value<0) {\r\n s=1; // negative\r\n value=Math.abs(value);\r\n }\r\n\r\n if (fracpart_numdigits>100 || value > 1e+21 || value < 1e-99) { \r\n this.mod.copyString(buffer, sizeInBytes, \"\");\r\n this.mod.mem32[dec]=0;\r\n return 1;\r\n }\r\n\r\n const roundValStr=value.toFixed(fracpart_numdigits);\r\n let [intPart=\"\", fracPart=\"\"] = roundValStr.split('.');\r\n if (intPart==\"0\") intPart=\"\";\r\n\r\n if (intPart.length>0) { // has integer part\r\n decpos=intPart.length;\r\n digits=intPart+fracPart;\r\n }\r\n else { // only a fraction\r\n digits=fracPart.replace(/^0+/,\"\"); // remove leading zeros\r\n decpos=digits.length-fracPart.length;\r\n }\r\n }\r\n\r\n if (sizeInBytes-1 < digits.length) return 1; \r\n this.mod.copyString(buffer, sizeInBytes, digits);\r\n this.mod.setLong(dec, decpos);\r\n this.mod.setLong(sign, s);\r\n\r\n return 0;\r\n\r\n /*\r\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\r\n\r\n let decpos=0;\r\n let digits:string;\r\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\r\n \r\n if (decpos>0) { // has integer part\r\n const intlen=Math.max(decpos, 0);\r\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\r\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\r\n }\r\n else { // only a fraction\r\n const intpart=Math.trunc(value);\r\n const fracpart=value-intpart;\r\n const prec=fracpart_numdigits- (-decpos);\r\n console.log(\"prec=\",prec);\r\n if (prec<1) {\r\n digits=\"\";\r\n }\r\n else {\r\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\");\r\n }\r\n }\r\n\r\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\r\n console.log('digits=',digits);\r\n console.log('dec=',decpos);\r\n console.log(\"sign=\",s);\r\n */\r\n\r\n\r\n }\r\n}","import { twrSignal } from \"./twrsignal.js\";\nimport { twrTimeImpl } from \"./twrdate.js\";\n// This class is used in the Main JS thread \nexport class twrWaitingCalls {\n callCompleteSignal;\n parameters;\n constructor() {\n this.callCompleteSignal = new twrSignal();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(() => {\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = twrTimeImpl();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [this.callCompleteSignal.sharedArray, this.parameters.buffer];\n }\n processMessage(msgType, data) {\n switch (msgType) {\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\n// This class is used in the worker thread \nexport class twrWaitingCallsProxy {\n callCompleteSignal;\n parameters;\n constructor(params) {\n this.callCompleteSignal = new twrSignal(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\"sleep\", [ms]]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\"time\"]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n//# sourceMappingURL=twrwaitingcalls.js.map","import { twrSignal } from \"./twrsignal.js\";\r\nimport {twrTimeImpl} from \"./twrdate.js\"\r\n\r\n// These classes are used to proxy a call across the worker thread - main thread boundary and wait for the result\r\n\r\nexport type TWaitingCallsProxyParams = [SharedArrayBuffer, SharedArrayBuffer]; // twrSignal, parameters \r\n\r\n// This class is used in the Main JS thread \r\nexport class twrWaitingCalls {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor() {\r\n\t\tthis.callCompleteSignal=new twrSignal();\r\n\t\tthis.parameters=new Uint32Array(new SharedArrayBuffer(4));\r\n\t}\r\n\r\n\tprivate startSleep(ms:number) {\r\n\r\n\t\tsetTimeout(()=>{\r\n\t\t\tthis.callCompleteSignal.signal();\r\n\t\t}, ms);\r\n\t\t\r\n\t}\r\n\r\n\tprivate time() {\r\n\t\tconst ms=twrTimeImpl();\r\n\t\tthis.parameters[0]=ms;\r\n\t\tthis.callCompleteSignal.signal();\r\n\t}\r\n\r\n\tgetProxyParams():TWaitingCallsProxyParams {\r\n\t\treturn [this.callCompleteSignal.sharedArray, this.parameters.buffer as SharedArrayBuffer];\t\r\n\t}\r\n\r\n\tprocessMessage(msgType:string, data:any[]):boolean {\r\n\t\tswitch (msgType) {\r\n\t\t\tcase \"sleep\":\r\n\t\t\t\tconst [ms] = data;\r\n\t\t\t\tthis.startSleep(ms);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"time\":\r\n\t\t\t\tthis.time();\r\n\t\t\t\tbreak;\r\n\t\t\t\r\n\t\t\tdefault:\r\n\t\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\treturn true;\r\n\t}\r\n\r\n}\r\n\r\n// This class is used in the worker thread \r\nexport class twrWaitingCallsProxy {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor(params:TWaitingCallsProxyParams) {\r\n\t\tthis.callCompleteSignal=new twrSignal(params[0]);\r\n\t\tthis.parameters=new Uint32Array(params[1]);\r\n\t}\r\n\r\n\tsleep(ms:number) {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"sleep\", [ms]]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t}\r\n\r\n\ttime() {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"time\"]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t\treturn this.parameters[0];\r\n\t}\r\n\r\n}\r\n","export function twrTimeImpl() {\n return Date.now();\n}\n//# sourceMappingURL=twrdate.js.map","\r\nexport function twrTimeImpl() {\r\n\r\n return Date.now();\r\n\r\n}"],"names":["$b93f1fdf40141def$var$twrSignalState","$c4741cac81d14197$var$D2DType","twrSignalState","D2DType","$3e39efa823870787$var$mod","$892fccfc812d5e20$export$a01cca24f011573a","sharedArray","buf","constructor","sa","window","crossOriginIsolated","location","protocol","Error","SharedArrayBuffer","Int32Array","write","n","i","Atomics","notify","read","isEmpty","readWait","rdptr","wait","$b93f1fdf40141def$export$e37a7b7b851b97f3","WAITING","signal","SIGNALED","isSignaled","reset","$c4741cac81d14197$export$c779b2cd00544976","canvasKeys","drawCompleteSignal","props","owner","params","signalBuffer","canvasKeysBuffer","charIn","inkey","getProp","pn","propName","getString","drawSeq","ds","postMessage","$8963973702ae5462$export$b377f0bbf2c7581e","divKeys","divKeysBuffer","charOut","ch","$8ac0b786da854328$export$485af4d0039b3389","$e72303a1db04bdfa$export$918ffb7e046a537b","mod","atod","strptr","str","upper","trimStart","toUpperCase","Number","POSITIVE_INFINITY","NEGATIVE_INFINITY","parseFloat","replaceAll","dtoa","buffer","buffer_size","value","max_precision","r","toString","copyString","length","toPrecision","toFixed","decdigits","toExponential","fcvtS","sizeInBytes","fracpart_numdigits","dec","sign","digits","decpos","s","isNaN","slice","isFinite","Math","abs","mem32","intPart","fracPart","roundValStr","split","replace","setLong","$ece7fa3ed770778a$export$c83a0a3bffe07399","memory","mem8","memD","exports","isWorker","isWasmModule","floatUtil","Uint8Array","Uint32Array","Float64Array","loadWasm","pathToLoad","response","fetch","err","console","log","ok","statusText","wasmBytes","arrayBuffer","allimports","modParams","imports","instance","WebAssembly","instantiate","env","ArrayBuffer","malloc","size","Promise","resolve","m","twr_malloc","init","stack","p","stdio","twrInit","twr_wasm_init","executeC","cparams","preCallC","retval","executeCImpl","postCallC","fname","f","Array","ci","putString","URL","fetchAndPutURL","putArrayBuffer","u8","j","sin","charCodeAt","strIndex","putU8","u8a","dest","ab","fnin","src","getLong","idx","idx32","floor","getDouble","idx64","setDouble","getShort","len","sout","undefined","String","fromCharCode","getU8Arr","rv","dataptr","getU32Arr","$aff9c2c494d23fe3$export$78d2a4633fe89379","callCompleteSignal","parameters","sleep","ms","time","onmessage","e","data","$3e39efa823870787$var$twrWasmModuleInWorker","modWorkerParams","urlToLoad","then","catch","ex","rc","modInWorkerParams","canvasProxy","canvasProxyParams","divProxy","divProxyParams","waitingCallsProxy","waitingCallsProxyParams","twrDebugLog","twrSleep","bind","twrTime","twrDivCharOut","twrDivCharIn","twrCanvasCharIn","twrCanvasInkey","twrCanvasGetProp","twrCanvasDrawSeq","twrSin","twrCos","cos","twrTan","tan","twrFAbs","twrACos","acos","twrASin","asin","twrATan","atan","twrExp","exp","twrFloor","twrCeil","ceil","twrFMod","x","y","twrLog","twrPow","pow","twrSqrt","sqrt","twrTrunc","trunc","twrDtoa","twrToFixed","twrToExponential","twrAtod","twrFcvtS"],"version":3,"file":"twrmodworker.2165e649.js.map"} \ No newline at end of file +{"mappings":"A,C,SQKK,EJgBA,EIhBA,EJgBA,MFZD,CISE,OAAO,EACZ,WAA8B,AAC9B,CAAA,GAAe,AAEf,aAAa,CAAqB,CAAlC,CACO,GAAI,AAAkB,aAAlB,OAAO,QACH,CAAC,qBAAuB,AAA+B,UAA7B,OAAO,QAAQ,CAAC,QAAQ,CAAe,MAAM,AAAI,MAAM,4DAA4D,oBAAoB,iCAErK,EAAI,IAAI,CAAC,WAAW,CAAC,EACpB,IAAI,CAAC,WAAW,CAAC,IAAI,kBAAkB,MAClD,IAAI,CAAC,GAAG,CAAC,IAAI,WAAW,IAAI,CAAC,WAAW,EAClC,IAAI,CAAC,GAAG,CArBJ,IAqBW,CAAC,EAChB,IAAI,CAAC,GAAG,CArBJ,IAqBW,CAAC,CACvB,CAEA,MAAM,CAAQ,CAAd,CACO,IAAI,EAAE,IAAI,CAAC,GAAG,CAzBV,IAyBiB,AACrB,CAAA,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAzBV,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,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAE5C,CACN,CACF,C,C","sources":["","../../lib-js/twrmodworker.js","../../source/twr-wasm-ts/twrmodworker.ts","../../lib-js/twrcanvas.js","../../source/twr-wasm-ts/twrcanvas.ts","../../lib-js/twrcircular.js","../../source/twr-wasm-ts/twrcircular.ts","../../lib-js/twrsignal.js","../../source/twr-wasm-ts/twrsignal.ts","../../lib-js/twrdiv.js","../../source/twr-wasm-ts/twrdiv.ts","../../lib-js/twrdebug.js","../../source/twr-wasm-ts/twrdebug.ts","../../lib-js/twrmodbase.js","../../source/twr-wasm-ts/twrmodbase.ts","../../lib-js/twrfloat.js","../../source/twr-wasm-ts/twrfloat.ts","../../lib-js/twrwaitingcalls.js","../../source/twr-wasm-ts/twrwaitingcalls.ts","../../lib-js/twrdate.js","../../source/twr-wasm-ts/twrdate.ts"],"sourcesContent":["(() => {\nvar $3e39efa823870787$exports = {};\n// this script is the WebWorker thead used by class twrWasmAsyncModule\n//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst $892fccfc812d5e20$var$RDIDX = 256;\nconst $892fccfc812d5e20$var$WRIDX = 257;\nconst $892fccfc812d5e20$var$LEN = 256;\nclass $892fccfc812d5e20$export$a01cca24f011573a {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(1032);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[$892fccfc812d5e20$var$RDIDX] = 0;\n this.buf[$892fccfc812d5e20$var$WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[$892fccfc812d5e20$var$WRIDX];\n this.buf[i] = n;\n i++;\n if (i == $892fccfc812d5e20$var$LEN) i = 0;\n this.buf[$892fccfc812d5e20$var$WRIDX] = i;\n Atomics.notify(this.buf, $892fccfc812d5e20$var$WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[$892fccfc812d5e20$var$RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[$892fccfc812d5e20$var$RDIDX] = i;\n return n;\n } else return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[$892fccfc812d5e20$var$RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, $892fccfc812d5e20$var$WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[$892fccfc812d5e20$var$RDIDX] == this.buf[$892fccfc812d5e20$var$WRIDX];\n }\n}\n\n\n//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar $b93f1fdf40141def$var$twrSignalState;\n(function(twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})($b93f1fdf40141def$var$twrSignalState || ($b93f1fdf40141def$var$twrSignalState = {}));\nclass $b93f1fdf40141def$export$e37a7b7b851b97f3 {\n sharedArray;\n buf;\n constructor(sa){\n if (typeof window !== \"undefined\") {\n if (!crossOriginIsolated && !(window.location.protocol === \"file:\")) throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa) this.sharedArray = sa;\n else this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == $b93f1fdf40141def$var$twrSignalState.WAITING) //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, $b93f1fdf40141def$var$twrSignalState.WAITING);\n }\n isSignaled() {\n return this.buf[0] == $b93f1fdf40141def$var$twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = $b93f1fdf40141def$var$twrSignalState.WAITING;\n }\n}\n\n\nvar $c4741cac81d14197$var$D2DType;\n(function(D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})($c4741cac81d14197$var$D2DType || ($c4741cac81d14197$var$D2DType = {}));\nclass $c4741cac81d14197$export$2f298dd69cef3c34 {\n ctx;\n props = {\n charWidth: 0,\n charHeight: 0,\n foreColor: 0,\n backColor: 0,\n widthInChars: 0,\n heightInChars: 0,\n canvasHeight: 0,\n canvasWidth: 0\n };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase){\n const { forecolor: forecolor, backcolor: backcolor, fontsize: fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)();\n this.canvasKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.props,\n this.cmdCompleteSignal.sharedArray,\n this.canvasKeys.sharedArray\n ];\n }\n getProp(pn) {\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */ drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx) return;\n let ins = this.owner.getLong(ds); /* ds->start */ \n const lastins = this.owner.getLong(ds + 4); /* ds->last */ \n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while(true){\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */ \n switch(type){\n case $c4741cac81d14197$var$D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_BEGINPATH:\n this.ctx.beginPath();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_FILL:\n this.ctx.fill();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SAVE:\n this.ctx.save();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_RESTORE:\n this.ctx.restore();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_STROKE:\n this.ctx.stroke();\n break;\n case $c4741cac81d14197$var$D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = this.owner.getLong(ins + 48) != 0;\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n } else this.precomputedObjects[id] = {\n mem8: new Uint8Array(this.owner.memory.buffer, start, length),\n width: width,\n height: height\n };\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id]) delete this.precomputedObjects[id];\n else console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case $c4741cac81d14197$var$D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n else {\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) this.ctx.putImageData(imgData, dx, dy);\n else this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */ \n if (next == 0) {\n if (ins != lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nclass $c4741cac81d14197$export$c779b2cd00544976 {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner){\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)(signalBuffer);\n this.canvasKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\n \"drawseq\",\n [\n ds\n ]\n ]);\n this.drawCompleteSignal.wait();\n }\n}\n\n\n\nclass $8963973702ae5462$export$dd376bb3f10f6896 {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611);\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase){\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) this.divKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(); // tsconfig, lib must be set to 2017 or higher\n if (this.div && !modParams.styleIsDefault) {\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\n return [\n this.divKeys.sharedArray\n ];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */ charOut(ch) {\n if (!this.div) return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n }\n switch(ch){\n case 10:\n case 13:\n if (ch == 10 && this.lastChar == 13) break; // detect CR LF and treat as single new line\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n case 0xE:\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF:\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn) this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn) this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for(let i = 0; i < str.length; i++)this.charOut(str.charCodeAt(i));\n }\n}\nclass $8963973702ae5462$export$b377f0bbf2c7581e {\n divKeys;\n constructor(params){\n const [divKeysBuffer] = params;\n this.divKeys = new (0, $892fccfc812d5e20$export$a01cca24f011573a)(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty()) return 0;\n else return this.charIn();\n }\n charOut(ch) {\n postMessage([\n \"divout\",\n ch\n ]);\n }\n}\n\n\nlet $8ac0b786da854328$var$logline = \"\";\nfunction $8ac0b786da854328$export$16b4216ec014493d(char) {\n if (char == 10 || char == 3) {\n console.log($8ac0b786da854328$var$logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n $8ac0b786da854328$var$logline = \"\";\n } else {\n $8ac0b786da854328$var$logline = $8ac0b786da854328$var$logline + String.fromCharCode(char);\n if ($8ac0b786da854328$var$logline.length >= 200) {\n console.log($8ac0b786da854328$var$logline);\n $8ac0b786da854328$var$logline = \"\";\n }\n }\n}\nfunction $8ac0b786da854328$export$485af4d0039b3389(ch) {\n postMessage([\n \"debug\",\n ch\n ]);\n}\n\n\nclass $e72303a1db04bdfa$export$918ffb7e046a537b {\n mod;\n constructor(mod){\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\") return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\") return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll(\"D\", \"e\").replaceAll(\"d\", \"e\"));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n } else {\n let r = value.toString();\n if (r.length > max_precision) r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, sizeInBytes, value, fracpart_numdigits, dec, sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1) return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) {\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (!Number.isFinite(value)) {\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n } else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n } else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split(\".\");\n if (intPart == \"0\") intPart = \"\";\n if (intPart.length > 0) {\n decpos = intPart.length;\n digits = intPart + fracPart;\n } else {\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length) return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */ }\n}\n\n\nclass $ece7fa3ed770778a$export$c83a0a3bffe07399 {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule;\n floatUtil;\n constructor(isWasmModule = false){\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new (0, $e72303a1db04bdfa$export$918ffb7e046a537b)(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/ /*********************************************************************/ async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n } catch (err) {\n console.log(\"loadWasm() failed to fetch: \" + pathToLoad);\n throw err;\n }\n if (!response.ok) throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, {\n env: allimports\n });\n this.exports = instance.instance.exports;\n if (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory) throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer) console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\n \"setmemory\",\n this.memory\n ]);\n }\n if (this.isWasmModule) // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n {\n if (!(this.memory.buffer instanceof ArrayBuffer)) console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size)=>{\n return new Promise((resolve)=>{\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n } catch (err) {\n console.log(\"WASM instantiate error: \" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch(this.modParams.stdio){\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* callC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */ async callC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.callCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async callCImpl(fname, cparams = []) {\n if (!this.exports) throw new Error(\"this.exports undefined\");\n if (!this.exports[fname]) throw new Error(\"callC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array)) throw new Error(\"callC: params must be array, first arg is function name\");\n if (params.length == 0) throw new Error(\"callC: missing function name\");\n let cparams = [];\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n cparams[ci++] = p;\n break;\n case \"string\":\n cparams[ci++] = await this.putString(p);\n break;\n case \"object\":\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n } else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"callC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for(let i = 1; i < params.length; i++){\n const p = params[i];\n switch(typeof p){\n case \"number\":\n ci++;\n break;\n case \"string\":\n this.callCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n case \"object\":\n if (p instanceof URL) {\n this.callCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci = ci + 2;\n break;\n } else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for(let j = 0; j < u8.length; j++)u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.callCImpl(\"twr_free\", [\n cparams[ci]\n ]);\n ci++;\n break;\n } else throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/ /*********************************************************************/ // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for(i = 0; i < sin.length && i < buffer_size - 1; i++)this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for(let i = 0; i < u8a.length; i++)this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === \"object\" && fnin instanceof URL)) throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [\n dest,\n src.length\n ];\n } catch (err) {\n console.log(\"fetchAndPutURL Error. URL: \" + fnin + \"\\n\" + err + (err.stack ? \"\\n\" + err.stack : \"\"));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx) throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length) throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx) throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while(this.mem8[strIndex + i] && (len === undefined ? true : i < len) && strIndex + i < this.mem8.length){\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length) throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array(this.mem8.slice(idx, idx + 8).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= this.mem8.length) throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > this.mem8.length - dataptr) throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array(this.mem8.slice(dataptr, dataptr + size).buffer);\n return u32;\n }\n}\n\n\n\nfunction $4af5689abbc8d01b$export$78724cdcf7ebea1d() {\n return Date.now();\n}\n\n\nclass $aff9c2c494d23fe3$export$9e37856d1928d388 {\n callCompleteSignal;\n parameters;\n constructor(){\n this.callCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(()=>{\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = (0, $4af5689abbc8d01b$export$78724cdcf7ebea1d)();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [\n this.callCompleteSignal.sharedArray,\n this.parameters.buffer\n ];\n }\n processMessage(msgType, data) {\n switch(msgType){\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\nclass $aff9c2c494d23fe3$export$78d2a4633fe89379 {\n callCompleteSignal;\n parameters;\n constructor(params){\n this.callCompleteSignal = new (0, $b93f1fdf40141def$export$e37a7b7b851b97f3)(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\n \"sleep\",\n [\n ms\n ]\n ]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\n \"time\"\n ]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n\n\nlet $3e39efa823870787$var$mod;\nonmessage = function(e) {\n //console.log('twrworker.js: message received from main script: '+e.data);\n if (e.data[0] == \"startup\") {\n const params = e.data[1];\n //console.log(\"Worker startup params:\",params);\n $3e39efa823870787$var$mod = new $3e39efa823870787$var$twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\n $3e39efa823870787$var$mod.loadWasm(params.urlToLoad).then(()=>{\n postMessage([\n \"startupOkay\"\n ]);\n }).catch((ex)=>{\n console.log(\".catch: \", ex);\n postMessage([\n \"startupFail\",\n ex\n ]);\n });\n } else if (e.data[0] == \"callC\") $3e39efa823870787$var$mod.callCImpl(e.data[1], e.data[2]).then((rc)=>{\n postMessage([\n \"callCOkay\",\n rc\n ]);\n }).catch((e)=>{\n console.log(\"exception in callC twrworker.js\\n\");\n console.log(e);\n postMessage([\n \"callCFail\",\n e\n ]);\n });\n else console.log(\"twrworker.js: unknown message: \" + e);\n};\n// ************************************************************************\nclass $3e39efa823870787$var$twrWasmModuleInWorker extends (0, $ece7fa3ed770778a$export$c83a0a3bffe07399) {\n malloc;\n modParams;\n constructor(modParams, modInWorkerParams){\n super();\n this.isWorker = true;\n this.malloc = (size)=>{\n throw new Error(\"error - un-init malloc called\");\n };\n this.modParams = modParams;\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\n const canvasProxy = new (0, $c4741cac81d14197$export$c779b2cd00544976)(modInWorkerParams.canvasProxyParams, this);\n const divProxy = new (0, $8963973702ae5462$export$b377f0bbf2c7581e)(modInWorkerParams.divProxyParams);\n const waitingCallsProxy = new (0, $aff9c2c494d23fe3$export$78d2a4633fe89379)(modInWorkerParams.waitingCallsProxyParams);\n this.modParams.imports = {\n twrDebugLog: (0, $8ac0b786da854328$export$485af4d0039b3389),\n twrSleep: waitingCallsProxy.sleep.bind(waitingCallsProxy),\n twrTime: waitingCallsProxy.time.bind(waitingCallsProxy),\n twrDivCharOut: divProxy.charOut.bind(divProxy),\n twrDivCharIn: divProxy.charIn.bind(divProxy),\n twrCanvasCharIn: canvasProxy.charIn.bind(canvasProxy),\n twrCanvasInkey: canvasProxy.inkey.bind(canvasProxy),\n twrCanvasGetProp: canvasProxy.getProp.bind(canvasProxy),\n twrCanvasDrawSeq: canvasProxy.drawSeq.bind(canvasProxy),\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function(x, y) {\n return x % y;\n },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n}\n\n})();\n//# sourceMappingURL=twrmodworker.2165e649.js.map\n","// this script is the WebWorker thead used by class twrWasmAsyncModule\nimport { twrCanvasProxy } from \"./twrcanvas.js\";\nimport { twrDivProxy } from \"./twrdiv.js\";\nimport { twrDebugLogProxy } from \"./twrdebug.js\";\nimport { twrWasmModuleBase } from \"./twrmodbase.js\";\nimport { twrWaitingCallsProxy } from \"./twrwaitingcalls.js\";\nlet mod;\nonmessage = function (e) {\n //console.log('twrworker.js: message received from main script: '+e.data);\n if (e.data[0] == 'startup') {\n const params = e.data[1];\n //console.log(\"Worker startup params:\",params);\n mod = new twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\n mod.loadWasm(params.urlToLoad).then(() => {\n postMessage([\"startupOkay\"]);\n }).catch((ex) => {\n console.log(\".catch: \", ex);\n postMessage([\"startupFail\", ex]);\n });\n }\n else if (e.data[0] == 'callC') {\n mod.callCImpl(e.data[1], e.data[2]).then((rc) => {\n postMessage([\"callCOkay\", rc]);\n }).catch(e => {\n console.log(\"exception in callC twrworker.js\\n\");\n console.log(e);\n postMessage([\"callCFail\", e]);\n });\n }\n else {\n console.log(\"twrworker.js: unknown message: \" + e);\n }\n};\n// ************************************************************************\nclass twrWasmModuleInWorker extends twrWasmModuleBase {\n malloc;\n modParams;\n constructor(modParams, modInWorkerParams) {\n super();\n this.isWorker = true;\n this.malloc = (size) => { throw new Error(\"error - un-init malloc called\"); };\n this.modParams = modParams;\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\n const canvasProxy = new twrCanvasProxy(modInWorkerParams.canvasProxyParams, this);\n const divProxy = new twrDivProxy(modInWorkerParams.divProxyParams);\n const waitingCallsProxy = new twrWaitingCallsProxy(modInWorkerParams.waitingCallsProxyParams);\n this.modParams.imports = {\n twrDebugLog: twrDebugLogProxy,\n twrSleep: waitingCallsProxy.sleep.bind(waitingCallsProxy),\n twrTime: waitingCallsProxy.time.bind(waitingCallsProxy),\n twrDivCharOut: divProxy.charOut.bind(divProxy),\n twrDivCharIn: divProxy.charIn.bind(divProxy),\n twrCanvasCharIn: canvasProxy.charIn.bind(canvasProxy),\n twrCanvasInkey: canvasProxy.inkey.bind(canvasProxy),\n twrCanvasGetProp: canvasProxy.getProp.bind(canvasProxy),\n twrCanvasDrawSeq: canvasProxy.drawSeq.bind(canvasProxy),\n twrSin: Math.sin,\n twrCos: Math.cos,\n twrTan: Math.tan,\n twrFAbs: Math.abs,\n twrACos: Math.acos,\n twrASin: Math.asin,\n twrATan: Math.atan,\n twrExp: Math.exp,\n twrFloor: Math.floor,\n twrCeil: Math.ceil,\n twrFMod: function (x, y) { return x % y; },\n twrLog: Math.log,\n twrPow: Math.pow,\n twrSqrt: Math.sqrt,\n twrTrunc: Math.trunc,\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\n twrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\n twrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\n twrAtod: this.floatUtil.atod.bind(this.floatUtil),\n twrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\n };\n }\n}\n//# sourceMappingURL=twrmodworker.js.map","// this script is the WebWorker thead used by class twrWasmAsyncModule\r\n\r\nimport {twrCanvasProxy} from \"./twrcanvas.js\";\r\nimport {twrDivProxy} from \"./twrdiv.js\";\r\nimport {twrDebugLogProxy} from \"./twrdebug.js\";\r\nimport {TAsyncModStartupMsg} from \"./twrmodasync.js\"\r\nimport {twrWasmModuleBase, IModInWorkerParams, IModParams} from \"./twrmodbase.js\"\r\nimport {twrWaitingCallsProxy} from \"./twrwaitingcalls.js\";\r\n\r\nlet mod:twrWasmModuleInWorker;\r\n\r\nonmessage = function(e) {\r\n //console.log('twrworker.js: message received from main script: '+e.data);\r\n\r\n if (e.data[0]=='startup') {\r\n const params:TAsyncModStartupMsg=e.data[1];\r\n //console.log(\"Worker startup params:\",params);\r\n mod=new twrWasmModuleInWorker(params.modParams, params.modWorkerParams);\r\n\r\n mod.loadWasm(params.urlToLoad).then( ()=> {\r\n postMessage([\"startupOkay\"]);\r\n }).catch( (ex)=> {\r\n console.log(\".catch: \", ex);\r\n postMessage([\"startupFail\", ex]);\r\n });\r\n }\r\n else if (e.data[0]=='callC') {\r\n mod.callCImpl(e.data[1], e.data[2]).then( (rc)=> {\r\n postMessage([\"callCOkay\", rc]);\r\n }).catch(e => {\r\n console.log(\"exception in callC twrworker.js\\n\");\r\n console.log(e);\r\n postMessage([\"callCFail\", e]);\r\n });\r\n }\r\n else {\r\n console.log(\"twrworker.js: unknown message: \"+e);\r\n }\r\n}\r\n\r\n\r\n// ************************************************************************\r\n\r\nclass twrWasmModuleInWorker extends twrWasmModuleBase {\r\n\tmalloc:(size:number)=>Promise;\r\n modParams: IModParams;\r\n\r\n\r\n constructor(modParams:IModParams, modInWorkerParams:IModInWorkerParams) {\r\n super();\r\n this.isWorker=true;\r\n this.malloc=(size:number)=>{throw new Error(\"error - un-init malloc called\")};\r\n this.modParams=modParams;\r\n\r\n //console.log(\"twrWasmModuleInWorker: \", modInWorkerParams.canvasProxyParams)\r\n const canvasProxy = new twrCanvasProxy(modInWorkerParams.canvasProxyParams, this);\r\n const divProxy = new twrDivProxy(modInWorkerParams.divProxyParams);\r\n const waitingCallsProxy = new twrWaitingCallsProxy(modInWorkerParams.waitingCallsProxyParams);\r\n\r\n this.modParams.imports={\r\n twrDebugLog:twrDebugLogProxy,\r\n twrSleep:waitingCallsProxy.sleep.bind(waitingCallsProxy),\r\n twrTime:waitingCallsProxy.time.bind(waitingCallsProxy),\r\n\r\n twrDivCharOut:divProxy.charOut.bind(divProxy), \r\n twrDivCharIn:divProxy.charIn.bind(divProxy), \r\n\r\n twrCanvasCharIn:canvasProxy.charIn.bind(canvasProxy),\r\n twrCanvasInkey:canvasProxy.inkey.bind(canvasProxy),\r\n twrCanvasGetProp:canvasProxy.getProp.bind(canvasProxy),\r\n twrCanvasDrawSeq:canvasProxy.drawSeq.bind(canvasProxy),\r\n\r\n\t\t\ttwrSin:Math.sin,\r\n\t\t\ttwrCos:Math.cos,\r\n\t\t\ttwrTan: Math.tan,\r\n\t\t\ttwrFAbs: Math.abs,\r\n\t\t\ttwrACos: Math.acos,\r\n\t\t\ttwrASin: Math.asin,\r\n\t\t\ttwrATan: Math.atan,\r\n\t\t\ttwrExp: Math.exp,\r\n\t\t\ttwrFloor: Math.floor,\r\n\t\t\ttwrCeil: Math.ceil,\r\n\t\t\ttwrFMod: function(x:number, y:number) {return x%y},\r\n\t\t\ttwrLog: Math.log,\r\n\t\t\ttwrPow: Math.pow,\r\n\t\t\ttwrSqrt: Math.sqrt,\r\n\t\t\ttwrTrunc: Math.trunc,\r\n\r\n twrDtoa: this.floatUtil.dtoa.bind(this.floatUtil),\r\n\t\t\ttwrToFixed: this.floatUtil.toFixed.bind(this.floatUtil),\r\n\t\t\ttwrToExponential: this.floatUtil.toExponential.bind(this.floatUtil),\r\n\t\t\ttwrAtod: this.floatUtil.atod.bind(this.floatUtil),\r\n\t\t\ttwrFcvtS: this.floatUtil.fcvtS.bind(this.floatUtil)\r\n \r\n }\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nimport { twrSignal } from \"./twrsignal.js\";\nvar D2DType;\n(function (D2DType) {\n D2DType[D2DType[\"D2D_FILLRECT\"] = 1] = \"D2D_FILLRECT\";\n D2DType[D2DType[\"D2D_FILLCHAR\"] = 5] = \"D2D_FILLCHAR\";\n D2DType[D2DType[\"D2D_SETLINEWIDTH\"] = 10] = \"D2D_SETLINEWIDTH\";\n D2DType[D2DType[\"D2D_SETFILLSTYLERGBA\"] = 11] = \"D2D_SETFILLSTYLERGBA\";\n D2DType[D2DType[\"D2D_SETFONT\"] = 12] = \"D2D_SETFONT\";\n D2DType[D2DType[\"D2D_BEGINPATH\"] = 13] = \"D2D_BEGINPATH\";\n D2DType[D2DType[\"D2D_MOVETO\"] = 14] = \"D2D_MOVETO\";\n D2DType[D2DType[\"D2D_LINETO\"] = 15] = \"D2D_LINETO\";\n D2DType[D2DType[\"D2D_FILL\"] = 16] = \"D2D_FILL\";\n D2DType[D2DType[\"D2D_STROKE\"] = 17] = \"D2D_STROKE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLERGBA\"] = 18] = \"D2D_SETSTROKESTYLERGBA\";\n D2DType[D2DType[\"D2D_ARC\"] = 19] = \"D2D_ARC\";\n D2DType[D2DType[\"D2D_STROKERECT\"] = 20] = \"D2D_STROKERECT\";\n D2DType[D2DType[\"D2D_FILLTEXT\"] = 21] = \"D2D_FILLTEXT\";\n D2DType[D2DType[\"D2D_IMAGEDATA\"] = 22] = \"D2D_IMAGEDATA\";\n D2DType[D2DType[\"D2D_PUTIMAGEDATA\"] = 23] = \"D2D_PUTIMAGEDATA\";\n D2DType[D2DType[\"D2D_BEZIERTO\"] = 24] = \"D2D_BEZIERTO\";\n D2DType[D2DType[\"D2D_MEASURETEXT\"] = 25] = \"D2D_MEASURETEXT\";\n D2DType[D2DType[\"D2D_SAVE\"] = 26] = \"D2D_SAVE\";\n D2DType[D2DType[\"D2D_RESTORE\"] = 27] = \"D2D_RESTORE\";\n D2DType[D2DType[\"D2D_CREATERADIALGRADIENT\"] = 28] = \"D2D_CREATERADIALGRADIENT\";\n D2DType[D2DType[\"D2D_SETCOLORSTOP\"] = 29] = \"D2D_SETCOLORSTOP\";\n D2DType[D2DType[\"D2D_SETFILLSTYLEGRADIENT\"] = 30] = \"D2D_SETFILLSTYLEGRADIENT\";\n D2DType[D2DType[\"D2D_RELEASEID\"] = 31] = \"D2D_RELEASEID\";\n D2DType[D2DType[\"D2D_CREATELINEARGRADIENT\"] = 32] = \"D2D_CREATELINEARGRADIENT\";\n D2DType[D2DType[\"D2D_SETFILLSTYLE\"] = 33] = \"D2D_SETFILLSTYLE\";\n D2DType[D2DType[\"D2D_SETSTROKESTYLE\"] = 34] = \"D2D_SETSTROKESTYLE\";\n})(D2DType || (D2DType = {}));\nexport class twrCanvas {\n ctx;\n props = { charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight: 0, canvasWidth: 0 };\n owner;\n cmdCompleteSignal;\n canvasKeys;\n precomputedObjects;\n constructor(element, modParams, modbase) {\n const { forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas } = modParams;\n this.owner = modbase;\n this.props.widthInChars = modParams.windim[0];\n this.props.heightInChars = modParams.windim[1];\n if (!this.owner.isWasmModule) {\n this.cmdCompleteSignal = new twrSignal();\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n this.precomputedObjects = {};\n if (element) {\n if (!element.getContext)\n throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\n let c = element.getContext(\"2d\");\n if (!c)\n throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\n c.font = fontsize.toString() + \"px Courier New\";\n c.textBaseline = \"top\";\n const sampleText = \" \";\n const tm = c.measureText(sampleText);\n this.props.charWidth = Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\n let fM = c.measureText(\"X\");\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\n if (!isd2dcanvas) {\n element.width = this.props.charWidth * this.props.widthInChars;\n element.height = this.props.charHeight * this.props.heightInChars;\n }\n this.props.canvasHeight = element.height;\n this.props.canvasWidth = element.width;\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\n let c2 = element.getContext(\"2d\");\n if (!c2)\n throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\n this.ctx = c2;\n this.ctx.font = fontsize.toString() + \"px Courier New\";\n this.ctx.textBaseline = \"top\";\n c2.fillStyle = backcolor;\n this.props.backColor = Number(\"0x\" + c2.fillStyle.slice(1));\n c2.fillStyle = forecolor;\n this.props.foreColor = Number(\"0x\" + c2.fillStyle.slice(1));\n }\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\n //console.log(\"twrCanvas.constructor props: \", this.props);\n }\n isValid() {\n return !!this.ctx;\n }\n getProxyParams() {\n if (!this.cmdCompleteSignal || !this.canvasKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\n }\n getProp(pn) {\n if (!this.isValid())\n console.log(\"internal error - getProp called on invalid twrCanvas\");\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n /* see draw2d.h for structs that match */\n drawSeq(ds) {\n //console.log(\"twr::Canvas enter drawSeq\");\n if (!this.isValid())\n console.log(\"internal error - drawSeq called on invalid twrCanvas\");\n if (!this.ctx)\n return;\n let ins = this.owner.getLong(ds); /* ds->start */\n const lastins = this.owner.getLong(ds + 4); /* ds->last */\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\n let next;\n //let insCount=0;\n while (1) {\n //insCount++;\n const type = this.owner.getLong(ins + 4); /* hdr->type */\n if (0 /*type!=D2DType.D2D_FILLRECT*/) {\n console.log(\"ins\", ins);\n console.log(\"hdr.next\", this.owner.mem8[ins], this.owner.mem8[ins + 1], this.owner.mem8[ins + 2], this.owner.mem8[ins + 3]);\n console.log(\"hdr.type\", this.owner.mem8[ins + 4], this.owner.mem8[ins + 5]);\n console.log(\"next 4 bytes\", this.owner.mem8[ins + 6], this.owner.mem8[ins + 7], this.owner.mem8[ins + 8], this.owner.mem8[ins + 9]);\n console.log(\"and 4 more \", this.owner.mem8[ins + 10], this.owner.mem8[ins + 11], this.owner.mem8[ins + 12], this.owner.mem8[ins + 13]);\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\n }\n switch (type) {\n case D2DType.D2D_FILLRECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.fillRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_STROKERECT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const w = this.owner.getDouble(ins + 24);\n const h = this.owner.getDouble(ins + 32);\n this.ctx.strokeRect(x, y, w, h);\n }\n break;\n case D2DType.D2D_FILLCHAR:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const c = this.owner.getShort(ins + 24);\n let txt = String.fromCharCode(c);\n this.ctx.fillText(txt, x, y);\n }\n break;\n case D2DType.D2D_FILLTEXT:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const str = this.owner.getString(this.owner.getLong(ins + 24));\n //console.log(\"filltext \",x,y,str)\n this.ctx.fillText(str, x, y);\n }\n break;\n case D2DType.D2D_MEASURETEXT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n const tmidx = this.owner.getLong(ins + 12);\n const tm = this.ctx.measureText(str);\n this.owner.setDouble(tmidx + 0, tm.actualBoundingBoxAscent);\n this.owner.setDouble(tmidx + 8, tm.actualBoundingBoxDescent);\n this.owner.setDouble(tmidx + 16, tm.actualBoundingBoxLeft);\n this.owner.setDouble(tmidx + 24, tm.actualBoundingBoxRight);\n this.owner.setDouble(tmidx + 32, tm.fontBoundingBoxAscent);\n this.owner.setDouble(tmidx + 40, tm.fontBoundingBoxDescent);\n this.owner.setDouble(tmidx + 48, tm.width);\n }\n break;\n case D2DType.D2D_SETFONT:\n {\n const str = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.font = str;\n }\n break;\n case D2DType.D2D_SETFILLSTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.fillStyle = cssColor;\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\n }\n break;\n case D2DType.D2D_SETSTROKESTYLERGBA:\n {\n const color = this.owner.getLong(ins + 8);\n const cssColor = \"#\" + (\"00000000\" + color.toString(16)).slice(-8);\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETFILLSTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.fillStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETSTROKESTYLE:\n {\n const cssColor = this.owner.getString(this.owner.getLong(ins + 8));\n this.ctx.strokeStyle = cssColor;\n }\n break;\n case D2DType.D2D_SETLINEWIDTH:\n {\n const width = this.owner.getShort(ins + 8);\n this.ctx.lineWidth = width;\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\n }\n break;\n case D2DType.D2D_MOVETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.moveTo(x, y);\n }\n break;\n case D2DType.D2D_LINETO:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n this.ctx.lineTo(x, y);\n }\n break;\n case D2DType.D2D_BEZIERTO:\n {\n const cp1x = this.owner.getDouble(ins + 8);\n const cp1y = this.owner.getDouble(ins + 16);\n const cp2x = this.owner.getDouble(ins + 24);\n const cp2y = this.owner.getDouble(ins + 32);\n const x = this.owner.getDouble(ins + 40);\n const y = this.owner.getDouble(ins + 48);\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\n }\n break;\n case D2DType.D2D_BEGINPATH:\n {\n this.ctx.beginPath();\n }\n break;\n case D2DType.D2D_FILL:\n {\n this.ctx.fill();\n }\n break;\n case D2DType.D2D_SAVE:\n {\n this.ctx.save();\n }\n break;\n case D2DType.D2D_RESTORE:\n {\n this.ctx.restore();\n }\n break;\n case D2DType.D2D_STROKE:\n {\n this.ctx.stroke();\n }\n break;\n case D2DType.D2D_ARC:\n {\n const x = this.owner.getDouble(ins + 8);\n const y = this.owner.getDouble(ins + 16);\n const radius = this.owner.getDouble(ins + 24);\n const startAngle = this.owner.getDouble(ins + 32);\n const endAngle = this.owner.getDouble(ins + 40);\n const counterClockwise = (this.owner.getLong(ins + 48) != 0);\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise);\n }\n break;\n case D2DType.D2D_IMAGEDATA:\n {\n const start = this.owner.getLong(ins + 8);\n const length = this.owner.getLong(ins + 12);\n const width = this.owner.getLong(ins + 16);\n const height = this.owner.getLong(ins + 20);\n const id = this.owner.getLong(ins + 24);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\n if (this.owner.isWasmModule) {\n const z = new Uint8ClampedArray(this.owner.memory.buffer, start, length);\n this.precomputedObjects[id] = new ImageData(z, width, height);\n }\n else { // Uint8ClampedArray doesn't support shared memory\n this.precomputedObjects[id] = { mem8: new Uint8Array(this.owner.memory.buffer, start, length), width: width, height: height };\n }\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\n }\n break;\n case D2DType.D2D_CREATERADIALGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const radius0 = this.owner.getDouble(ins + 24);\n const x1 = this.owner.getDouble(ins + 32);\n const y1 = this.owner.getDouble(ins + 40);\n const radius1 = this.owner.getDouble(ins + 48);\n const id = this.owner.getLong(ins + 56);\n let gradient = this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_CREATELINEARGRADIENT:\n {\n const x0 = this.owner.getDouble(ins + 8);\n const y0 = this.owner.getDouble(ins + 16);\n const x1 = this.owner.getDouble(ins + 24);\n const y1 = this.owner.getDouble(ins + 32);\n const id = this.owner.getLong(ins + 40);\n let gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);\n if (id in this.precomputedObjects)\n console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\n this.precomputedObjects[id] = gradient;\n }\n break;\n case D2DType.D2D_SETCOLORSTOP:\n {\n const id = this.owner.getLong(ins + 8);\n const pos = this.owner.getLong(ins + 12);\n const cssColor = this.owner.getString(this.owner.getLong(ins + 16));\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n gradient.addColorStop(pos, cssColor);\n }\n break;\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\n {\n const id = this.owner.getLong(ins + 8);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \" + id);\n const gradient = this.precomputedObjects[id];\n this.ctx.fillStyle = gradient;\n }\n break;\n case D2DType.D2D_RELEASEID:\n {\n const id = this.owner.getLong(ins + 8);\n if (this.precomputedObjects[id])\n delete this.precomputedObjects[id];\n else\n console.log(\"warning: D2D_RELEASEID with undefined ID \", id);\n }\n break;\n case D2DType.D2D_PUTIMAGEDATA:\n {\n const id = this.owner.getLong(ins + 8);\n const dx = this.owner.getLong(ins + 12);\n const dy = this.owner.getLong(ins + 16);\n const dirtyX = this.owner.getLong(ins + 20);\n const dirtyY = this.owner.getLong(ins + 24);\n const dirtyWidth = this.owner.getLong(ins + 28);\n const dirtyHeight = this.owner.getLong(ins + 32);\n if (!(id in this.precomputedObjects))\n throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \" + id);\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\n let imgData;\n if (this.owner.isWasmModule) {\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\n imgData = this.precomputedObjects[id];\n }\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\n const z = this.precomputedObjects[id]; // Uint8Array\n const ca = Uint8ClampedArray.from(z.mem8); // shallow copy\n imgData = new ImageData(ca, z.width, z.height);\n }\n if (dirtyWidth == 0 && dirtyHeight == 0) {\n this.ctx.putImageData(imgData, dx, dy);\n }\n else {\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\n }\n }\n break;\n default:\n throw new Error(\"unimplemented or unknown Sequence Type in drawSeq: \" + type);\n }\n next = this.owner.getLong(ins); /* hdr->next */\n if (next == 0) {\n if (ins != lastins)\n throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\n break;\n }\n ins = next;\n }\n if (this.cmdCompleteSignal)\n this.cmdCompleteSignal.signal();\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\n }\n}\nexport class twrCanvasProxy {\n canvasKeys;\n drawCompleteSignal;\n props;\n owner;\n constructor(params, owner) {\n const [props, signalBuffer, canvasKeysBuffer] = params;\n this.drawCompleteSignal = new twrSignal(signalBuffer);\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\n this.props = props;\n this.owner = owner;\n //console.log(\"Create New twrCanvasProxy: \",this.props)\n }\n charIn() {\n //ctx.commit(); not avail in chrome\n //postMessage([\"debug\", 'x']);\n return this.canvasKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.canvasKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n getProp(pn) {\n const propName = this.owner.getString(pn);\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\n return this.props[propName];\n }\n drawSeq(ds) {\n this.drawCompleteSignal.reset();\n postMessage([\"drawseq\", [ds]]);\n this.drawCompleteSignal.wait();\n }\n}\n//# sourceMappingURL=twrcanvas.js.map","import {twrWasmModuleBase, IModParams} from \"./twrmodbase.js\"\r\nimport {twrSharedCircularBuffer} from \"./twrcircular.js\";\r\nimport {twrSignal} from \"./twrsignal.js\";\r\n\r\n\r\n// Canvas have a size that will be set based on the character width x height\r\n// The display size for a canvas will default to this size, but can be changed in the HTML/JS via\r\n// canvas.style.width = \"700px\";\r\n// canvas.style.height = \"500px\";\r\n\r\nexport interface ICanvasProps {\r\n\tcharWidth: number,\r\n\tcharHeight: number,\r\n\tforeColor: number,\r\n\tbackColor: number,\r\n widthInChars: number,\r\n heightInChars: number,\r\n canvasWidth:number,\r\n canvasHeight:number\r\n}\r\n\r\nenum D2DType {\r\n D2D_FILLRECT=1,\r\n D2D_FILLCHAR=5,\r\n D2D_SETLINEWIDTH=10,\r\n D2D_SETFILLSTYLERGBA=11,\r\n D2D_SETFONT=12,\r\n D2D_BEGINPATH=13,\r\n D2D_MOVETO=14,\r\n D2D_LINETO=15,\r\n D2D_FILL=16,\r\n D2D_STROKE=17,\r\n D2D_SETSTROKESTYLERGBA=18,\r\n D2D_ARC=19,\r\n D2D_STROKERECT=20,\r\n D2D_FILLTEXT=21,\r\n D2D_IMAGEDATA=22,\r\n D2D_PUTIMAGEDATA=23,\r\n D2D_BEZIERTO=24,\r\n D2D_MEASURETEXT=25,\r\n D2D_SAVE=26,\r\n D2D_RESTORE=27,\r\n D2D_CREATERADIALGRADIENT=28,\r\n D2D_SETCOLORSTOP=29,\r\n D2D_SETFILLSTYLEGRADIENT=30,\r\n D2D_RELEASEID=31,\r\n D2D_CREATELINEARGRADIENT=32,\r\n D2D_SETFILLSTYLE=33,\r\n D2D_SETSTROKESTYLE=34\r\n\r\n}\r\n\r\nexport type TCanvasProxyParams = [ICanvasProps, SharedArrayBuffer, SharedArrayBuffer];\r\n\r\nexport interface ICanvas {\r\n props: ICanvasProps,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TCanvasProxyParams,\r\n drawSeq: (ds:number)=>void,\r\n }\r\n \r\nexport class twrCanvas implements ICanvas {\r\n ctx:CanvasRenderingContext2D|undefined;\r\n props:ICanvasProps={charWidth: 0, charHeight: 0, foreColor: 0, backColor: 0, widthInChars: 0, heightInChars: 0, canvasHeight:0, canvasWidth:0};\r\n owner: twrWasmModuleBase;\r\n cmdCompleteSignal?:twrSignal;\r\n canvasKeys?: twrSharedCircularBuffer;\r\n precomputedObjects: { [index: number]: \r\n (ImageData | {mem8:Uint8Array, width:number, height:number}) |\r\n CanvasGradient\r\n };\r\n\r\n constructor(element:HTMLCanvasElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n const {forecolor, backcolor, fontsize, isd2dcanvas: isd2dcanvas} = modParams; \r\n this.owner=modbase;\r\n this.props.widthInChars=modParams.windim[0];\r\n this.props.heightInChars=modParams.windim[1];\r\n\r\n if (!this.owner.isWasmModule) {\r\n this.cmdCompleteSignal=new twrSignal();\r\n this.canvasKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n }\r\n\r\n this.precomputedObjects={};\r\n \r\n if (element) {\r\n if (!element.getContext) throw new Error(\"attempted to create new twrCanvas with an element that is not a valid HTMLCanvasElement\");\r\n let c=element.getContext(\"2d\");\r\n if (!c) throw new Error(\"canvas 2D context not found in twrCanvasConstructor\");\r\n\r\n c.font = fontsize.toString()+\"px Courier New\";\r\n c.textBaseline=\"top\";\r\n const sampleText=\" \";\r\n const tm=c.measureText(sampleText);\r\n this.props.charWidth=Math.ceil(tm.width / sampleText.length); // ceil rounds up (eg .9 -> 1)\r\n let fM = c.measureText(\"X\"); \r\n this.props.charHeight = Math.ceil(fM.fontBoundingBoxAscent + fM.fontBoundingBoxDescent);\r\n\r\n if (!isd2dcanvas) {\r\n element.width=this.props.charWidth*this.props.widthInChars;\r\n element.height=this.props.charHeight*this.props.heightInChars;\r\n }\r\n\r\n this.props.canvasHeight=element.height;\r\n this.props.canvasWidth=element.width;\r\n //console.log(\"this.props.canvasHeight, this.props.canvasWidth\",this.props.canvasHeight,this.props.canvasWidth);\r\n\r\n // reset after dims changed. Not sure if ctx is needed to rest, but others do\r\n let c2=element.getContext(\"2d\");\r\n if (!c2) throw new Error(\"canvas 2D context not found in twrCanvas.constructor (2nd time)\");\r\n this.ctx=c2;\r\n this.ctx.font = fontsize.toString()+\"px Courier New\";\r\n this.ctx.textBaseline=\"top\";\r\n\r\n c2.fillStyle=backcolor;\r\n this.props.backColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n c2.fillStyle=forecolor;\r\n this.props.foreColor=Number(\"0x\"+c2.fillStyle.slice(1));\r\n\r\n }\r\n\r\n //console.log(\"Create New twrCanvas: \",this.isValid(), element, this);\r\n\r\n //console.log(\"twrCanvas.constructor props: \", this.props);\r\n }\r\n\r\n isValid() {\r\n return !!this.ctx;\r\n }\r\n\r\n getProxyParams() : TCanvasProxyParams {\r\n if (!this.cmdCompleteSignal || !this.canvasKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [this.props, this.cmdCompleteSignal.sharedArray, this.canvasKeys.sharedArray];\r\n }\r\n\r\n getProp(pn:number): number {\r\n if (!this.isValid()) console.log(\"internal error - getProp called on invalid twrCanvas\");\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvas.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n\r\n/* see draw2d.h for structs that match */\r\n\r\n drawSeq(ds:number) {\r\n //console.log(\"twr::Canvas enter drawSeq\");\r\n if (!this.isValid()) console.log(\"internal error - drawSeq called on invalid twrCanvas\");\r\n if (!this.ctx) return;\r\n\r\n let ins=this.owner.getLong(ds); /* ds->start */\r\n const lastins=this.owner.getLong(ds+4); /* ds->last */\r\n //console.log(\"instruction start, last \",ins.toString(16), lastins.toString(16));\r\n\r\n let next:number;\r\n //let insCount=0;\r\n\r\n while (1) {\r\n\r\n //insCount++;\r\n\r\n const type:D2DType=this.owner.getLong(ins+4); /* hdr->type */\r\n if (0/*type!=D2DType.D2D_FILLRECT*/) {\r\n console.log(\"ins\",ins)\r\n console.log(\"hdr.next\",this.owner.mem8[ins],this.owner.mem8[ins+1],this.owner.mem8[ins+2],this.owner.mem8[ins+3]);\r\n console.log(\"hdr.type\",this.owner.mem8[ins+4],this.owner.mem8[ins+5]);\r\n console.log(\"next 4 bytes\", this.owner.mem8[ins+6],this.owner.mem8[ins+7],this.owner.mem8[ins+8],this.owner.mem8[ins+9]);\r\n console.log(\"and 4 more \", this.owner.mem8[ins+10],this.owner.mem8[ins+11],this.owner.mem8[ins+12],this.owner.mem8[ins+13]);\r\n //console.log(\"ins, type, next is \", ins.toString(16), type.toString(16), next.toString(16));\r\n }\r\n switch (type) {\r\n case D2DType.D2D_FILLRECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.fillRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKERECT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const w=this.owner.getDouble(ins+24);\r\n const h=this.owner.getDouble(ins+32);\r\n this.ctx.strokeRect(x, y, w, h);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILLCHAR:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const c=this.owner.getShort(ins+24);\r\n let txt=String.fromCharCode(c);\r\n this.ctx.fillText(txt, x, y);\r\n }\r\n break;\r\n\r\n \r\n case D2DType.D2D_FILLTEXT:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const str=this.owner.getString(this.owner.getLong(ins+24));\r\n\r\n //console.log(\"filltext \",x,y,str)\r\n \r\n this.ctx.fillText(str, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MEASURETEXT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n const tmidx=this.owner.getLong(ins+12);\r\n \r\n const tm=this.ctx.measureText(str);\r\n this.owner.setDouble(tmidx+0, tm.actualBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+8, tm.actualBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+16, tm.actualBoundingBoxLeft);\r\n this.owner.setDouble(tmidx+24, tm.actualBoundingBoxRight);\r\n this.owner.setDouble(tmidx+32, tm.fontBoundingBoxAscent);\r\n this.owner.setDouble(tmidx+40, tm.fontBoundingBoxDescent);\r\n this.owner.setDouble(tmidx+48, tm.width);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFONT:\r\n {\r\n const str=this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.font=str;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.fillStyle = cssColor;\r\n //console.log(\"fillstyle: \", this.ctx.fillStyle, \":\", cssColor,\":\", color)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETSTROKESTYLERGBA:\r\n {\r\n const color=this.owner.getLong(ins+8); \r\n const cssColor= \"#\"+(\"00000000\" + color.toString(16)).slice(-8);\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SETFILLSTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.fillStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETSTROKESTYLE:\r\n {\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+8));\r\n this.ctx.strokeStyle = cssColor;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETLINEWIDTH:\r\n {\r\n const width=this.owner.getShort(ins+8); \r\n this.ctx.lineWidth=width;\r\n //console.log(\"twrCanvas D2D_SETLINEWIDTH: \", this.ctx.lineWidth);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_MOVETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.moveTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_LINETO:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n this.ctx.lineTo(x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEZIERTO:\r\n {\r\n const cp1x=this.owner.getDouble(ins+8);\r\n const cp1y=this.owner.getDouble(ins+16);\r\n const cp2x=this.owner.getDouble(ins+24);\r\n const cp2y=this.owner.getDouble(ins+32);\r\n const x=this.owner.getDouble(ins+40);\r\n const y=this.owner.getDouble(ins+48);\r\n this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_BEGINPATH:\r\n {\r\n this.ctx.beginPath();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_FILL:\r\n {\r\n this.ctx.fill();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_SAVE:\r\n {\r\n this.ctx.save();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_RESTORE:\r\n {\r\n this.ctx.restore();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_STROKE:\r\n {\r\n this.ctx.stroke();\r\n }\r\n break;\r\n\r\n case D2DType.D2D_ARC:\r\n {\r\n const x=this.owner.getDouble(ins+8);\r\n const y=this.owner.getDouble(ins+16);\r\n const radius=this.owner.getDouble(ins+24);\r\n const startAngle=this.owner.getDouble(ins+32);\r\n const endAngle=this.owner.getDouble(ins+40);\r\n const counterClockwise= (this.owner.getLong(ins+48)!=0);\r\n\r\n this.ctx.arc(x, y, radius, startAngle, endAngle, counterClockwise)\r\n }\r\n break;\r\n\r\n case D2DType.D2D_IMAGEDATA:\r\n {\r\n const start=this.owner.getLong(ins+8);\r\n const length=this.owner.getLong(ins+12);\r\n const width=this.owner.getLong(ins+16);\r\n const height=this.owner.getLong(ins+20);\r\n const id=this.owner.getLong(ins+24);\r\n\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_IMAGEDATA ID already exists.\");\r\n\r\n if (this.owner.isWasmModule) {\r\n const z = new Uint8ClampedArray(this.owner.memory!.buffer, start, length);\r\n this.precomputedObjects[id]=new ImageData(z, width, height);\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory\r\n this.precomputedObjects[id]={mem8: new Uint8Array(this.owner.memory!.buffer, start, length), width:width, height:height};\r\n }\r\n //console.log(\"D2D_IMAGEDATA\",start, length, width, height, this.imageData[start]);\r\n }\r\n break;\r\n\r\n case D2DType.D2D_CREATERADIALGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const radius0=this.owner.getDouble(ins+24);\r\n const x1=this.owner.getDouble(ins+32);\r\n const y1=this.owner.getDouble(ins+40);\r\n const radius1=this.owner.getDouble(ins+48);\r\n const id= this.owner.getLong(ins+56);\r\n\r\n let gradient=this.ctx.createRadialGradient(x0, y0, radius0, x1, y1, radius1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATERADIALGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_CREATELINEARGRADIENT:\r\n {\r\n const x0=this.owner.getDouble(ins+8);\r\n const y0=this.owner.getDouble(ins+16);\r\n const x1=this.owner.getDouble(ins+24);\r\n const y1=this.owner.getDouble(ins+32);\r\n const id= this.owner.getLong(ins+40);\r\n \r\n let gradient=this.ctx.createLinearGradient(x0, y0, x1, y1);\r\n if ( id in this.precomputedObjects ) console.log(\"warning: D2D_CREATELINEARGRADIENT ID already exists.\");\r\n this.precomputedObjects[id] = gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETCOLORSTOP:\r\n {\r\n const id = this.owner.getLong(ins+8);\r\n const pos=this.owner.getLong(ins+12);\r\n const cssColor= this.owner.getString(this.owner.getLong(ins+16));\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETCOLORSTOP with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n gradient.addColorStop(pos, cssColor);\r\n }\r\n break\r\n\r\n case D2DType.D2D_SETFILLSTYLEGRADIENT:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_SETFILLSTYLEGRADIENT with invalid ID: \"+id);\r\n const gradient=this.precomputedObjects[id] as CanvasGradient;\r\n this.ctx.fillStyle=gradient;\r\n }\r\n break\r\n\r\n case D2DType.D2D_RELEASEID:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n if (this.precomputedObjects[id])\r\n delete this.precomputedObjects[id];\r\n else\r\n console.log(\"warning: D2D_RELEASEID with undefined ID \",id);\r\n }\r\n break\r\n\r\n \r\n\r\n case D2DType.D2D_PUTIMAGEDATA:\r\n {\r\n const id=this.owner.getLong(ins+8);\r\n const dx=this.owner.getLong(ins+12);\r\n const dy=this.owner.getLong(ins+16);\r\n const dirtyX=this.owner.getLong(ins+20);\r\n const dirtyY=this.owner.getLong(ins+24);\r\n const dirtyWidth=this.owner.getLong(ins+28);\r\n const dirtyHeight=this.owner.getLong(ins+32);\r\n\r\n if (!(id in this.precomputedObjects)) throw new Error(\"D2D_PUTIMAGEDATA with invalid ID: \"+id);\r\n\r\n //console.log(\"D2D_PUTIMAGEDATA\",start, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, this.imageData[start]);\r\n\r\n let imgData:ImageData;\r\n if (this.owner.isWasmModule) {\r\n //console.log(\"D2D_PUTIMAGEDATA isWasmModule\");\r\n imgData=this.precomputedObjects[id] as ImageData;\r\n }\r\n else { // Uint8ClampedArray doesn't support shared memory, so copy the memory\r\n //console.log(\"D2D_PUTIMAGEDATA wasmModuleAsync\");\r\n const z = this.precomputedObjects[id] as {mem8:Uint8Array, width:number, height:number}; // Uint8Array\r\n const ca=Uint8ClampedArray.from(z.mem8); // shallow copy\r\n imgData=new ImageData(ca, z.width, z.height);\r\n }\r\n \r\n if (dirtyWidth==0 && dirtyHeight==0) {\r\n this.ctx.putImageData(imgData, dx, dy);\r\n }\r\n else {\r\n this.ctx.putImageData(imgData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);\r\n }\r\n }\r\n break;\r\n\r\n default:\r\n throw new Error (\"unimplemented or unknown Sequence Type in drawSeq: \"+type);\r\n }\r\n next=this.owner.getLong(ins); /* hdr->next */\r\n if (next==0) {\r\n if (ins!=lastins) throw new Error(\"assert type error in twrcanvas, ins!=lastins\");\r\n break;\r\n }\r\n ins=next;\r\n }\r\n\r\n if (this.cmdCompleteSignal) this.cmdCompleteSignal.signal();\r\n //console.log(\"Canvas.drawSeq() completed with instruction count of \", insCount);\r\n }\r\n}\r\n\r\nexport class twrCanvasProxy implements ICanvas {\r\n canvasKeys: twrSharedCircularBuffer;\r\n drawCompleteSignal:twrSignal;\r\n props: ICanvasProps;\r\n owner: twrWasmModuleBase;\r\n\r\n constructor(params:TCanvasProxyParams, owner:twrWasmModuleBase) {\r\n const [props, signalBuffer, canvasKeysBuffer] = params;\r\n this.drawCompleteSignal = new twrSignal(signalBuffer);\r\n this.canvasKeys = new twrSharedCircularBuffer(canvasKeysBuffer);\r\n this.props=props;\r\n this.owner=owner;\r\n\r\n //console.log(\"Create New twrCanvasProxy: \",this.props)\r\n\r\n }\r\n\r\n charIn() { \r\n //ctx.commit(); not avail in chrome\r\n \r\n //postMessage([\"debug\", 'x']);\r\n \r\n return this.canvasKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.canvasKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n getProp(pn:number): number {\r\n const propName=this.owner.getString(pn) as keyof ICanvasProps;\r\n //console.log(\"enter twrCanvasProxy.getprop: \", pn, propName, this.props[propName], this.props);\r\n return this.props[propName];\r\n }\r\n \r\n drawSeq(ds:number) {\r\n this.drawCompleteSignal.reset();\r\n postMessage([\"drawseq\", [ds]]);\r\n this.drawCompleteSignal.wait();\r\n }\r\n}\r\n","//\n// This class implements a circular buffer that the main javascript thread can write to, \n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\n//\nconst RDIDX = 256;\nconst WRIDX = 257;\nconst LEN = 256;\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\n// the first 256 array entries are the circular buffer\n// the next two are used for the read and write index\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\nexport class twrSharedCircularBuffer {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(258 * 4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[RDIDX] = 0;\n this.buf[WRIDX] = 0;\n }\n write(n) {\n let i = this.buf[WRIDX];\n this.buf[i] = n;\n i++;\n if (i == LEN)\n i = 0;\n this.buf[WRIDX] = i;\n Atomics.notify(this.buf, WRIDX);\n }\n read() {\n if (!this.isEmpty()) {\n let i = this.buf[RDIDX];\n let n = this.buf[i];\n i++;\n this.buf[RDIDX] = i;\n return n;\n }\n else\n return -1;\n }\n readWait() {\n if (this.isEmpty()) {\n const rdptr = this.buf[RDIDX];\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\n Atomics.wait(this.buf, WRIDX, rdptr);\n }\n return this.read();\n }\n isEmpty() {\n return this.buf[RDIDX] == this.buf[WRIDX];\n }\n}\n//# sourceMappingURL=twrcircular.js.map","//\r\n// This class implements a circular buffer that the main javascript thread can write to, \r\n// and a blocking WebWorker thread can read from. This allows keyboard characters to be transferred from the main JS thread to a WebWorker thread.\r\n// The WebWorker can use the readWait() function to sleep, w/o participating in the normal \r\n// async callback dispatch method. This allows a C program that is a single blocking loop to receive input from the primary javascript thread.\r\n// readWait() is used used when io_getc() or io_getstr() is called from a C function.\r\n//\r\n\r\nconst RDIDX=256;\r\nconst WRIDX=257;\r\nconst LEN=256;\r\n\r\n// A single thread can read and a separate single thread can write. With these constraints Atomic operations are not needed.\r\n// the first 256 array entries are the circular buffer\r\n// the next two are used for the read and write index\r\n\r\n//!!!! I am using --enable-features=SharedArrayBuffer; see the SharedArrayBuffer docs for COR issues when going to a live web server\r\n\r\nexport class twrSharedCircularBuffer {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n \r\n\tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window defined (not a worker thread)\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) throw new Error(\"twrSharedCircularBuffer constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(258*4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[RDIDX]=0;\r\n this.buf[WRIDX]=0;\r\n\t}\r\n\r\n\twrite(n:number) {\r\n let i=this.buf[WRIDX];\r\n this.buf[i]=n;\r\n i++;\r\n if (i==LEN) i=0;\r\n this.buf[WRIDX]=i; \r\n Atomics.notify(this.buf, WRIDX); \r\n\t}\r\n\r\n\tread():number {\r\n if (!this.isEmpty()) {\r\n let i=this.buf[RDIDX];\r\n let n=this.buf[i];\r\n i++;\r\n this.buf[RDIDX]=i;\r\n return n;\r\n }\r\n\t\telse\r\n return -1;\r\n\t}\r\n\r\n readWait():number {\r\n if (this.isEmpty()) {\r\n const rdptr=this.buf[RDIDX];\r\n // verifies that a shared memory location still contains a given value and if so sleeps until notified.\r\n Atomics.wait(this.buf, WRIDX, rdptr);\r\n }\r\n return this.read();\r\n\t}\r\n\r\n isEmpty():boolean {\r\n return this.buf[RDIDX]==this.buf[WRIDX];\r\n }\r\n}\r\n","//\n// This class implements a simple signal/wait mechanism\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\n//\nvar twrSignalState;\n(function (twrSignalState) {\n twrSignalState[twrSignalState[\"WAITING\"] = 0] = \"WAITING\";\n twrSignalState[twrSignalState[\"SIGNALED\"] = 1] = \"SIGNALED\";\n})(twrSignalState || (twrSignalState = {}));\n;\nexport class twrSignal {\n sharedArray;\n buf;\n constructor(sa) {\n if (typeof window !== 'undefined') { // this check only works if window valid\n if (!crossOriginIsolated && !(window.location.protocol === 'file:'))\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\" + crossOriginIsolated + \". See SharedArrayBuffer docs.\");\n }\n if (sa)\n this.sharedArray = sa;\n else\n this.sharedArray = new SharedArrayBuffer(4);\n this.buf = new Int32Array(this.sharedArray);\n this.buf[0] = twrSignalState.WAITING;\n }\n signal() {\n this.buf[0] = twrSignalState.SIGNALED;\n //console.log(\"about to signal\");\n Atomics.notify(this.buf, 0);\n }\n wait() {\n if (this.buf[0] == twrSignalState.WAITING) {\n //console.log(\"waiting...\");\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\n //console.log(\"released...\");\n }\n }\n isSignaled() {\n return this.buf[0] == twrSignalState.SIGNALED;\n }\n reset() {\n this.buf[0] = twrSignalState.WAITING;\n }\n}\n//# sourceMappingURL=twrsignal.js.map","//\r\n// This class implements a simple signal/wait mechanism\r\n// It is used by the WebWorker thread to block/wait, and the main JS thread to signal when to unblock\r\n//\r\n\r\nenum twrSignalState {\r\n WAITING=0,\r\n SIGNALED=1\r\n};\r\n\r\nexport class twrSignal {\r\n\tsharedArray:SharedArrayBuffer;\r\n\tbuf:Int32Array;\r\n\r\n \tconstructor (sa?:SharedArrayBuffer) {\r\n if (typeof window !== 'undefined') { // this check only works if window valid\r\n if (!crossOriginIsolated && !(window.location.protocol === 'file:')) \r\n throw new Error(\"twrSignal constructor, crossOriginIsolated=\"+crossOriginIsolated+\". See SharedArrayBuffer docs.\");\r\n }\r\n if (sa) this.sharedArray=sa;\r\n else this.sharedArray=new SharedArrayBuffer(4);\r\n\t\tthis.buf=new Int32Array(this.sharedArray);\r\n this.buf[0]=twrSignalState.WAITING;\r\n\t}\r\n\r\n\tsignal() {\r\n this.buf[0]=twrSignalState.SIGNALED; \r\n //console.log(\"about to signal\");\r\n Atomics.notify(this.buf, 0); \r\n\t}\r\n\r\n wait() {\r\n if (this.buf[0]==twrSignalState.WAITING) {\r\n //console.log(\"waiting...\");\r\n Atomics.wait(this.buf, 0, twrSignalState.WAITING);\r\n //console.log(\"released...\");\r\n\r\n }\r\n\t}\r\n isSignaled():boolean {\r\n return this.buf[0]==twrSignalState.SIGNALED;\r\n }\r\n\r\n reset() {\r\n this.buf[0]=twrSignalState.WAITING;\r\n }\r\n}\r\n","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\nexport class twrDiv {\n div;\n divKeys;\n CURSOR = String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\n cursorOn = false;\n lastChar = 0;\n extraBR = false;\n owner;\n constructor(element, modParams, modbase) {\n this.div = element;\n this.owner = modbase;\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\n this.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\n }\n if (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\n this.div.style.backgroundColor = modParams.backcolor;\n this.div.style.color = modParams.forecolor;\n this.div.style.font = modParams.fontsize.toString() + \"px arial\";\n }\n }\n isValid() {\n return !!this.div;\n }\n getProxyParams() {\n if (!this.divKeys)\n throw new Error(\"internal error in getProxyParams.\");\n return [this.divKeys.sharedArray];\n }\n /*\n * add character to div. Supports the following control codes:\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\n * 0xE cursor on\n * 0x8 backspace\n * 0xF cursor off\n */\n charOut(ch) {\n if (!this.div)\n return;\n //console.log(\"div::charout: \", ch);\n if (this.extraBR) {\n this.extraBR = false;\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -4);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n }\n switch (ch) {\n case 10: // newline\n case 13: // return\n if (ch == 10 && this.lastChar == 13)\n break; // detect CR LF and treat as single new line\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\n this.extraBR = true;\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n //element.scrollIntoView();\n //element.scrollTop = element.scrollHeight;\n let p = this.div.getBoundingClientRect();\n window.scrollTo(0, p.height + 100);\n break;\n case 8: // backspace\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n case 0xE: // cursor on\n if (!this.cursorOn) {\n this.cursorOn = true;\n this.div.innerHTML += this.CURSOR;\n this.div.focus();\n }\n break;\n case 0xF: // cursor off\n if (this.cursorOn) {\n this.cursorOn = false;\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n }\n break;\n default:\n if (this.cursorOn)\n this.div.innerHTML = this.div.innerHTML.slice(0, -1);\n this.div.innerHTML += String.fromCharCode(ch);\n if (this.cursorOn)\n this.div.innerHTML += this.CURSOR;\n break;\n }\n this.lastChar = ch;\n }\n stringOut(str) {\n for (let i = 0; i < str.length; i++)\n this.charOut(str.charCodeAt(i));\n }\n}\nexport class twrDivProxy {\n divKeys;\n constructor(params) {\n const [divKeysBuffer] = params;\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\n }\n charIn() {\n return this.divKeys.readWait(); // wait for a key, then read it\n }\n inkey() {\n if (this.divKeys.isEmpty())\n return 0;\n else\n return this.charIn();\n }\n charOut(ch) {\n postMessage([\"divout\", ch]);\n }\n}\n//# sourceMappingURL=twrdiv.js.map","import { twrSharedCircularBuffer } from \"./twrcircular.js\";\r\nimport { IModParams } from \"./twrmodbase.js\";\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\";\r\n\r\nexport type TDivProxyParams = [SharedArrayBuffer];\r\n\r\nexport interface IDiv {\r\n charOut: (ds:number)=>void,\r\n charIn?: ()=>number,\r\n inkey?: ()=>number,\r\n getProxyParams?: ()=>TDivProxyParams,\r\n }\r\n\r\n\r\nexport class twrDiv implements IDiv {\r\n\tdiv:HTMLDivElement|null|undefined;\r\n\tdivKeys?:twrSharedCircularBuffer;\r\n\tCURSOR=String.fromCharCode(9611); // â–‹ see https://daniel-hug.github.io/characters/#k_70\r\n\tcursorOn:boolean=false;\r\n\tlastChar:number=0;\r\n\textraBR:boolean=false;\r\n\towner:twrWasmModuleBase;\r\n\r\n constructor(element:HTMLDivElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {\r\n\t\tthis.div=element;\r\n\t\tthis.owner=modbase;\r\n if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory\r\n\t\t\tthis.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher\r\n\t\t}\r\n\r\n\t\tif (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle\r\n\t\t\tthis.div.style.backgroundColor = modParams.backcolor;\r\n\t\t\tthis.div.style.color = modParams.forecolor;\r\n\t\t\tthis.div.style.font=modParams.fontsize.toString()+\"px arial\"\r\n\t\t}\r\n }\r\n\r\n\tisValid() {\r\n\t\treturn !!this.div;\r\n\t}\r\n\r\n getProxyParams() : TDivProxyParams {\r\n if (!this.divKeys) throw new Error(\"internal error in getProxyParams.\");\r\n return [ this.divKeys.sharedArray];\r\n }\r\n\r\n\r\n/* \r\n * add character to div. Supports the following control codes:\r\n * any of CRLF, CR (/r), or LF(/n) will cause a new line\r\n * 0xE cursor on \r\n * 0x8 backspace\r\n * 0xF cursor off \r\n*/\r\n\tcharOut(ch:number) {\r\n\r\n\t\tif (!this.div) return;\r\n\r\n\t\t//console.log(\"div::charout: \", ch);\r\n\r\n\t\tif (this.extraBR) {\r\n\t\t\tthis.extraBR=false;\r\n\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -4);\r\n\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t}\r\n\r\n\t\tswitch (ch) {\r\n\t\t\tcase 10: // newline\r\n\t\t\tcase 13: // return\r\n\t\t\t\tif (ch==10 && this.lastChar==13) break; // detect CR LF and treat as single new line\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += \"

\"; //2nd break is a place holder for next line (fixes scroll issue at bottom)\r\n\t\t\t\tthis.extraBR=true;\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\t//element.scrollIntoView();\r\n\t\t\t\t//element.scrollTop = element.scrollHeight;\r\n\t\t\t\tlet p = this.div.getBoundingClientRect();\r\n\t\t\t\twindow.scrollTo(0, p.height+100);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 8: // backspace\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xE: // cursor on\r\n\t\t\t\tif (!this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=true;\r\n\t\t\t\t\tthis.div.innerHTML += this.CURSOR;\r\n\t\t\t\t\tthis.div.focus();\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 0xF: // cursor off\r\n\t\t\t\tif (this.cursorOn) {\r\n\t\t\t\t\tthis.cursorOn=false;\r\n\t\t\t\t\tthis.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML=this.div.innerHTML.slice(0, -1);\r\n\t\t\t\tthis.div.innerHTML += String.fromCharCode(ch);\r\n\t\t\t\tif (this.cursorOn) this.div.innerHTML += this.CURSOR;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\tthis.lastChar=ch;\r\n\t}\r\n\r\n\tstringOut(str:string) {\r\n\t\tfor (let i=0; i < str.length; i++)\r\n\t\t\tthis.charOut(str.charCodeAt(i));\r\n\t}\r\n}\r\n\r\n\r\nexport class twrDivProxy implements IDiv {\r\n divKeys: twrSharedCircularBuffer;\r\n\r\n constructor(params:TDivProxyParams) {\r\n const [divKeysBuffer] = params;\r\n this.divKeys = new twrSharedCircularBuffer(divKeysBuffer);\r\n }\r\n\r\n charIn() { \r\n return this.divKeys.readWait(); // wait for a key, then read it\r\n }\r\n \r\n inkey() {\r\n if (this.divKeys.isEmpty())\r\n return 0;\r\n else\r\n return this.charIn(); \r\n }\r\n\r\n\tcharOut(ch:number) {\r\n\t\tpostMessage([\"divout\", ch]);\r\n\t}\r\n}\r\n\r\n","let logline = \"\";\nexport function twrDebugLogImpl(char) {\n if (char == 10 || char == 3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\n console.log(logline); // ideally without a linefeed, but there is no way to not have a LF with console.log API.\n logline = \"\";\n }\n else {\n logline = logline + String.fromCharCode(char);\n if (logline.length >= 200) {\n console.log(logline);\n logline = \"\";\n }\n }\n}\n// ************************************************************************\n// debugLog doesn't currently wait for the message to log, it returns immediately.\n// I could move this to be in the twrWaitingCalls class\nexport function twrDebugLogProxy(ch) {\n postMessage([\"debug\", ch]);\n}\n//# sourceMappingURL=twrdebug.js.map","\r\nlet logline=\"\";\r\nexport function twrDebugLogImpl(char:number) {\r\n\tif (char==10 || char==3) { // ASCII 03 is End-of-Text, and is used here to indicate the preceding char should be printed\r\n\t\tconsole.log(logline);\t// ideally without a linefeed, but there is no way to not have a LF with console.log API.\r\n\t\tlogline=\"\";\r\n\t}\r\n\telse {\r\n\t\tlogline=logline+String.fromCharCode(char);\r\n\t\tif (logline.length>=200) {\r\n\t\t\tconsole.log(logline);\r\n\t\t\tlogline=\"\";\r\n\t\t}\r\n\t}\r\n}\r\n\r\n// ************************************************************************\r\n// debugLog doesn't currently wait for the message to log, it returns immediately.\r\n// I could move this to be in the twrWaitingCalls class\r\nexport function twrDebugLogProxy(ch:number) {\r\n postMessage([\"debug\", ch]);\r\n}\r\n\r\n","import { twrFloatUtil } from \"./twrfloat.js\";\n/*********************************************************************/\n/*********************************************************************/\n/*********************************************************************/\nexport class twrWasmModuleBase {\n memory;\n mem8;\n mem32;\n memD;\n exports;\n isWorker = false;\n isWasmModule; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\n floatUtil;\n constructor(isWasmModule = false) {\n this.isWasmModule = isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\n this.mem8 = new Uint8Array(); // avoid type errors\n this.mem32 = new Uint32Array(); // avoid type errors\n this.memD = new Float64Array(); // avoid type errors\n this.floatUtil = new twrFloatUtil(this);\n //console.log(\"size of mem8 after constructor\",this.mem8.length);\n }\n /*********************************************************************/\n /*********************************************************************/\n async loadWasm(pathToLoad) {\n //console.log(\"fileToLoad\",fileToLoad)\n let response;\n try {\n response = await fetch(pathToLoad);\n }\n catch (err) {\n console.log('loadWasm() failed to fetch: ' + pathToLoad);\n throw err;\n }\n if (!response.ok)\n throw new Error(\"fetch response error on file '\" + pathToLoad + \"'\\n\" + response.statusText);\n try {\n let wasmBytes = await response.arrayBuffer();\n let allimports = {\n ...this.modParams.imports\n };\n let instance = await WebAssembly.instantiate(wasmBytes, { env: allimports });\n this.exports = instance.instance.exports;\n if (!this.exports)\n throw new Error(\"Unexpected error - undefined instance.exports\");\n if (this.memory)\n throw new Error(\"unexpected error -- this.memory already set\");\n this.memory = this.exports.memory;\n if (!this.memory)\n throw new Error(\"Unexpected error - undefined exports.memory\");\n this.mem8 = new Uint8Array(this.memory.buffer);\n this.mem32 = new Uint32Array(this.memory.buffer);\n this.memD = new Float64Array(this.memory.buffer);\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (this.isWorker) {\n if (this.memory.buffer instanceof ArrayBuffer)\n console.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\n postMessage([\"setmemory\", this.memory]);\n }\n if (this.isWasmModule) {\n // here if twrWasmModule, twrWasmModuleAsync overrides this function\n // instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\n if (!(this.memory.buffer instanceof ArrayBuffer))\n console.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\n }\n this.malloc = (size) => {\n return new Promise(resolve => {\n const m = this.exports.twr_malloc;\n resolve(m(size));\n });\n };\n this.init();\n }\n catch (err) {\n console.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n init() {\n //console.log(\"loadWasm.init() enter\")\n let p;\n switch (this.modParams.stdio) {\n case \"debug\":\n p = 0;\n break;\n case \"div\":\n p = 1;\n break;\n case \"canvas\":\n p = 2;\n break;\n case \"null\":\n p = 3;\n break;\n default:\n p = 0; // debug\n }\n const twrInit = this.exports.twr_wasm_init;\n //console.log(\"twrInit:\",twrInit)\n twrInit(p, this.mem8.length);\n }\n /* callC takes an array where:\n * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\n * and the next entries are a variable number of parameters to pass to the C function, of type\n * number - converted to int32 or float64 as appropriate\n * string - converted to a an index (ptr) into a module Memory returned via stringToMem()\n * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\n * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\n */\n async callC(params) {\n const cparams = await this.preCallC(params);\n let retval = this.callCImpl(params[0], cparams);\n this.postCallC(cparams, params);\n return retval;\n }\n async callCImpl(fname, cparams = []) {\n if (!this.exports)\n throw new Error(\"this.exports undefined\");\n if (!this.exports[fname])\n throw new Error(\"callC: function '\" + fname + \"' not in export table. Use --export wasm-ld flag.\");\n const f = this.exports[fname];\n let cr = f(...cparams);\n return cr;\n }\n // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\n async preCallC(params) {\n if (!(params.constructor === Array))\n throw new Error(\"callC: params must be array, first arg is function name\");\n if (params.length == 0)\n throw new Error(\"callC: missing function name\");\n let cparams = [];\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n cparams[ci++] = p;\n break;\n case 'string':\n cparams[ci++] = await this.putString(p);\n break;\n case 'object':\n if (p instanceof URL) {\n const r = await this.fetchAndPutURL(p);\n cparams[ci++] = r[0]; // mem index\n cparams[ci++] = r[1]; // len\n break;\n }\n else if (p instanceof ArrayBuffer) {\n const r = await this.putArrayBuffer(p);\n cparams[ci++] = r; // mem index\n break;\n }\n default:\n throw new Error(\"callC: invalid object type passed in\");\n }\n }\n return cparams;\n }\n // free the mallocs; copy array buffer data from malloc back to arraybuffer\n async postCallC(cparams, params) {\n let ci = 0;\n for (let i = 1; i < params.length; i++) {\n const p = params[i];\n switch (typeof p) {\n case 'number':\n ci++;\n break;\n case 'string':\n this.callCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n case 'object':\n if (p instanceof URL) {\n this.callCImpl('twr_free', [cparams[ci]]);\n ci = ci + 2;\n break;\n }\n else if (p instanceof ArrayBuffer) {\n let u8 = new Uint8Array(p);\n for (let j = 0; j < u8.length; j++)\n u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory\n this.callCImpl('twr_free', [cparams[ci]]);\n ci++;\n break;\n }\n else\n throw new Error(\"postCallC: internal error A\");\n default:\n throw new Error(\"postCallC: internal error B\");\n }\n }\n return cparams;\n }\n /*********************************************************************/\n /*********************************************************************/\n // copy a string into existing buffer in the webassembly module memory\n copyString(buffer, buffer_size, sin) {\n let i;\n for (i = 0; i < sin.length && i < buffer_size - 1; i++)\n this.mem8[buffer + i] = sin.charCodeAt(i);\n this.mem8[buffer + i] = 0;\n }\n // allocate and copy a string into the webassembly module memory\n async putString(sin) {\n let strIndex = await this.malloc(sin.length);\n this.copyString(strIndex, sin.length, sin);\n return strIndex;\n }\n async putU8(u8a) {\n let dest = await this.malloc(u8a.length);\n for (let i = 0; i < u8a.length; i++)\n this.mem8[dest + i] = u8a[i];\n return dest;\n }\n async putArrayBuffer(ab) {\n const u8 = new Uint8Array(ab);\n return this.putU8(u8);\n }\n // given a url, load its contents, and stuff into wasm memory similar to Unint8Array\n async fetchAndPutURL(fnin) {\n if (!(typeof fnin === 'object' && fnin instanceof URL))\n throw new Error(\"fetchAndPutURL param must be URL\");\n try {\n let response = await fetch(fnin);\n let buffer = await response.arrayBuffer();\n let src = new Uint8Array(buffer);\n let dest = await this.putU8(src);\n return [dest, src.length];\n }\n catch (err) {\n console.log('fetchAndPutURL Error. URL: ' + fnin + '\\n' + err + (err.stack ? \"\\n\" + err.stack : ''));\n throw err;\n }\n }\n getLong(idx) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"getLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to getLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n const long = this.mem32[idx32];\n return long;\n }\n setLong(idx, value) {\n const idx32 = Math.floor(idx / 4);\n if (idx32 * 4 != idx)\n throw new Error(\"setLong passed non long aligned address\");\n if (idx32 < 0 || idx32 >= this.mem32.length)\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\n this.mem32[idx32] = value;\n }\n getDouble(idx) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"getLong passed non Float64 aligned address\");\n const long = this.memD[idx64];\n return long;\n }\n setDouble(idx, value) {\n const idx64 = Math.floor(idx / 8);\n if (idx64 * 8 != idx)\n throw new Error(\"setDouble passed non Float64 aligned address\");\n this.memD[idx64] = value;\n }\n getShort(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getShort: \" + idx);\n const short = this.mem8[idx] + this.mem8[idx + 1] * 256;\n return short;\n }\n // get a string out of module memory\n // null terminated, up until max of (optional) len\n getString(strIndex, len) {\n let sout = \"\";\n let i = 0;\n while (this.mem8[strIndex + i] && (len === undefined ? true : i < len) && (strIndex + i) < this.mem8.length) {\n sout = sout + String.fromCharCode(this.mem8[strIndex + i]);\n i++;\n }\n return sout;\n }\n // get a byte array out of module memory when passed in index to [size, dataptr]\n getU8Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU8: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU8\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU8\");\n const u8 = this.mem8.slice(dataptr, dataptr + size);\n return u8;\n }\n // get a int32 array out of module memory when passed in index to [size, dataptr]\n getU32Arr(idx) {\n if (idx < 0 || idx >= this.mem8.length)\n throw new Error(\"invalid index passed to getU32: \" + idx);\n const rv = new Uint32Array((this.mem8.slice(idx, idx + 8)).buffer);\n let size = rv[0];\n let dataptr = rv[1];\n if (dataptr < 0 || dataptr >= (this.mem8.length))\n throw new Error(\"invalid idx.dataptr passed to getU32\");\n if (size < 0 || size > (this.mem8.length - dataptr))\n throw new Error(\"invalid idx.size passed to getU32\");\n if (size % 4 != 0)\n throw new Error(\"idx.size is not an integer number of 32 bit words\");\n const u32 = new Uint32Array((this.mem8.slice(dataptr, dataptr + size)).buffer);\n return u32;\n }\n}\n//# sourceMappingURL=twrmodbase.js.map","\r\nimport {TCanvasProxyParams} from \"./twrcanvas.js\"\r\nimport {TDivProxyParams} from \"./twrdiv.js\";\r\nimport {TWaitingCallsProxyParams} from \"./twrwaitingcalls.js\"\r\nimport {twrDebugLogImpl} from \"./twrdebug.js\";\r\nimport {twrFloatUtil} from \"./twrfloat.js\";\r\n\r\n\r\nexport type TStdioVals=\"div\"|\"canvas\"|\"null\"|\"debug\";\r\n\r\nexport interface IModOpts {\r\n\tstdio?:TStdioVals, \r\n\twindim?:[number, number],\r\n\tforecolor?:string,\r\n\tbackcolor?:string,\r\n\tfontsize?:number,\r\n\tisd2dcanvas?:boolean,\r\n\timports?:{},\r\n}\r\n\r\nexport interface IModParams {\r\n\tstdio:TStdioVals, \r\n\twindim:[number, number],\r\n\tforecolor:string,\r\n\tbackcolor:string,\r\n\tfontsize:number,\r\n\tstyleIsDefault: boolean\r\n\tisd2dcanvas:boolean,\r\n\timports:{[index:string]:Function},\r\n}\r\n\r\nexport interface IModInWorkerParams {\r\n\tdivProxyParams:TDivProxyParams,\r\n\tcanvasProxyParams:TCanvasProxyParams,\r\n\twaitingCallsProxyParams:TWaitingCallsProxyParams,\r\n}\r\n\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n/*********************************************************************/\r\n\r\nexport abstract class twrWasmModuleBase {\r\n\tmemory?:WebAssembly.Memory;\r\n\tmem8:Uint8Array;\r\n\tmem32:Uint32Array;\r\n\tmemD:Float64Array;\r\n\tabstract malloc:(size:number)=>Promise;\r\n\tabstract modParams:IModParams;\r\n\texports?:WebAssembly.Exports;\r\n\tisWorker=false;\r\n\tisWasmModule:boolean; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)\r\n\tfloatUtil:twrFloatUtil;\r\n\r\n\tconstructor(isWasmModule=false) {\r\n\t\tthis.isWasmModule=isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker\r\n\t\tthis.mem8=new Uint8Array(); \t// avoid type errors\r\n\t\tthis.mem32=new Uint32Array(); // avoid type errors\r\n\t\tthis.memD=new Float64Array(); // avoid type errors\r\n\t\tthis.floatUtil=new twrFloatUtil(this);\r\n\t\t//console.log(\"size of mem8 after constructor\",this.mem8.length);\r\n\t}\r\n\r\n\t/*********************************************************************/\r\n\t/*********************************************************************/\r\n\r\n\tasync loadWasm(pathToLoad:string) {\r\n\t\t//console.log(\"fileToLoad\",fileToLoad)\r\n\r\n\t\tlet response;\r\n\t\ttry {\r\n\t\t\tresponse=await fetch(pathToLoad);\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('loadWasm() failed to fetch: '+pathToLoad);\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t\t\r\n\t\tif (!response.ok) throw new Error(\"fetch response error on file '\"+pathToLoad+\"'\\n\"+response.statusText);\r\n\r\n\t\ttry {\r\n\t\t\tlet wasmBytes = await response.arrayBuffer();\r\n\r\n\t\t\tlet allimports:WebAssembly.ModuleImports = { \r\n\t\t\t\t...this.modParams.imports\r\n\t\t\t};\r\n\r\n\t\t\tlet instance = await WebAssembly.instantiate(wasmBytes, {env: allimports});\r\n\r\n\t\t\tthis.exports=instance.instance.exports;\r\n\t\t\tif (!this.exports) throw new Error(\"Unexpected error - undefined instance.exports\");\r\n\r\n\t\t\tif (this.memory) throw new Error (\"unexpected error -- this.memory already set\");\r\n\t\t\tthis.memory=this.exports.memory as WebAssembly.Memory;\r\n\t\t\tif (!this.memory) throw new Error(\"Unexpected error - undefined exports.memory\");\r\n\t\t\tthis.mem8 = new Uint8Array(this.memory.buffer);\r\n\t\t\tthis.mem32 = new Uint32Array(this.memory.buffer);\r\n\t\t\tthis.memD = new Float64Array(this.memory.buffer);\r\n\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\tif (this.isWorker) {\r\n\t\t\t\tif (this.memory.buffer instanceof ArrayBuffer)\r\n\t\t\t\t\tconsole.log(\"twrWasmModuleAsync requires shared Memory. Add wasm-ld --shared-memory --no-check-features (see docs)\");\r\n\t\t\t\t\r\n\t\t\t\tpostMessage([\"setmemory\",this.memory]);\r\n\t\t\t}\r\n\t\t\tif (this.isWasmModule) {\r\n\t\t\t\t// here if twrWasmModule, twrWasmModuleAsync overrides this function\r\n\t\t\t\t// instanceof SharedArrayBuffer doesn't work when crossOriginIsolated not enable, and will cause a runtime error\r\n\t\t\t\tif (!(this.memory.buffer instanceof ArrayBuffer))\r\n\t\t\t\t\tconsole.log(\"twrWasmModule does not require shared Memory. Okay to remove wasm-ld --shared-memory --no-check-features\");\r\n\t\t\t}\r\n\r\n\t\t\tthis.malloc=(size:number)=>{\r\n\t\t\t\treturn new Promise(resolve => {\r\n\t\t\t\t\tconst m=this.exports!.twr_malloc as (size:number)=>number;\r\n\t\t\t\t\tresolve(m(size));\r\n\t\t\t\t});\r\n\t\t };\r\n\r\n\t\t\tthis.init();\r\n\r\n\t\t} catch(err:any) {\r\n\t\t\tconsole.log('WASM instantiate error: ' + err + (err.stack ? \"\\n\" + err.stack : ''));\r\n\t\t\tthrow err;\r\n\t\t}\r\n\t}\r\n\r\n\tprivate init() {\r\n\t\t//console.log(\"loadWasm.init() enter\")\r\n\t\t\tlet p:number;\r\n\t\t\tswitch (this.modParams.stdio) {\r\n\t\t\t\tcase \"debug\":\r\n\t\t\t\t\tp=0;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"div\":\r\n\t\t\t\t\tp=1;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"canvas\":\r\n\t\t\t\t\tp=2;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"null\":\r\n\t\t\t\t\tp=3;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tp=0; // debug\r\n\t\t\t}\r\n\r\n\t\t\tconst twrInit=this.exports!.twr_wasm_init as CallableFunction;\r\n\t\t\t//console.log(\"twrInit:\",twrInit)\r\n\t\t\ttwrInit(p, this.mem8.length);\r\n\t}\r\n\r\n\t/* callC takes an array where:\r\n\t* the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag)\r\n\t* and the next entries are a variable number of parameters to pass to the C function, of type\r\n\t* number - converted to int32 or float64 as appropriate\r\n\t* string - converted to a an index (ptr) into a module Memory returned via stringToMem()\r\n\t* URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length\r\n\t* Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length\r\n */\r\n\r\n\tasync callC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\t\tconst cparams=await this.preCallC(params);\r\n\t\tlet retval = this.callCImpl(params[0], cparams);\r\n\t\tthis.postCallC(cparams, params);\r\n\t\treturn retval;\r\n\t}\r\n\r\n\tasync callCImpl(fname:string, cparams:number[]=[]) {\r\n\t\tif (!this.exports) throw new Error(\"this.exports undefined\");\r\n\t\tif (!this.exports[fname]) throw new Error(\"callC: function '\"+fname+\"' not in export table. Use --export wasm-ld flag.\");\r\n\r\n\t\tconst f = this.exports[fname] as CallableFunction;\r\n\t\tlet cr=f(...cparams);\r\n\r\n\t\treturn cr;\r\n\t}\r\n\r\n\t// convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory\r\n\tasync preCallC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tif (!(params.constructor === Array)) throw new Error (\"callC: params must be array, first arg is function name\");\r\n\t\tif (params.length==0) throw new Error(\"callC: missing function name\");\r\n\r\n\t\tlet cparams:number[]=[];\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tcparams[ci++]=p;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tcparams[ci++]=await this.putString(p);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tconst r=await this.fetchAndPutURL(p);\r\n\t\t\t\t\t\tcparams[ci++]=r[0]; // mem index\r\n\t\t\t\t\t\tcparams[ci++]=r[1]; // len\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tconst r=await this.putArrayBuffer(p);\r\n\t\t\t\t\t\tcparams[ci++]=r; // mem index\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tthrow new Error (\"callC: invalid object type passed in\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn cparams;\r\n\t}\r\n\r\n\t// free the mallocs; copy array buffer data from malloc back to arraybuffer\r\n\tasync postCallC(cparams:number[], params:[string, ...(string|number|ArrayBuffer|URL)[]]) {\r\n\r\n\t\tlet ci=0;\r\n\t\tfor (let i=1; i < params.length; i++) {\r\n\t\t\tconst p=params[i];\r\n\t\t\tswitch (typeof p) {\r\n\t\t\t\tcase 'number':\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\r\n\t\t\t\tcase 'string':\r\n\t\t\t\t\tthis.callCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\tci++;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t\t\r\n\t\t\t\tcase 'object':\r\n\t\t\t\t\tif (p instanceof URL) {\r\n\t\t\t\t\t\tthis.callCImpl('twr_free',[cparams[ci]])\r\n\t\t\t\t\t\tci=ci+2;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (p instanceof ArrayBuffer) {\r\n\t\t\t\t\t\tlet u8=new Uint8Array(p);\r\n\t\t\t\t\t\tfor (let j=0; j= this.mem32.length) throw new Error(\"invalid index passed to getLong: \"+idx+\", this.mem32.length: \"+this.mem32.length);\r\n\t\tconst long:number = this.mem32[idx32];\r\n\t\treturn long;\r\n\t}\r\n\t\r\n\tsetLong(idx:number, value:number) {\r\n const idx32 = Math.floor(idx / 4);\r\n if (idx32 * 4 != idx)\r\n throw new Error(\"setLong passed non long aligned address\");\r\n if (idx32 < 0 || idx32 >= this.mem32.length)\r\n throw new Error(\"invalid index passed to setLong: \" + idx + \", this.mem32.length: \" + this.mem32.length);\r\n this.mem32[idx32]=value;\r\n }\r\n\r\n\tgetDouble(idx:number): number {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"getLong passed non Float64 aligned address\")\r\n\t\tconst long:number = this.memD[idx64];\r\n\t\treturn long;\r\n\t}\r\n\r\n\tsetDouble(idx:number, value:number) {\r\n\t\tconst idx64=Math.floor(idx/8);\r\n\t\tif (idx64*8!=idx) throw new Error(\"setDouble passed non Float64 aligned address\")\r\n\t\tthis.memD[idx64]=value;\r\n\t}\r\n\r\n\tgetShort(idx:number): number {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getShort: \"+idx);\r\n\t\tconst short:number = this.mem8[idx]+this.mem8[idx+1]*256;\r\n\t\treturn short;\r\n\t}\r\n\r\n\t// get a string out of module memory\r\n\t// null terminated, up until max of (optional) len\r\n\tgetString(strIndex:number, len?:number): string {\r\n\t\tlet sout=\"\";\r\n\r\n\t\tlet i=0;\r\n\t\twhile (this.mem8[strIndex+i] && (len===undefined?true:i= this.mem8.length) throw new Error(\"invalid index passed to getU8: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU8\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU8\")\r\n\r\n\t\tconst u8=this.mem8.slice(dataptr, dataptr+size);\r\n\t\treturn u8;\r\n\t}\r\n\r\n\t// get a int32 array out of module memory when passed in index to [size, dataptr]\r\n\tgetU32Arr(idx:number): Uint32Array {\r\n\t\tif (idx<0 || idx>= this.mem8.length) throw new Error(\"invalid index passed to getU32: \"+idx);\r\n\r\n\t\tconst rv = new Uint32Array( (this.mem8.slice(idx, idx+8)).buffer );\r\n\t\tlet size:number=rv[0];\r\n\t\tlet dataptr:number=rv[1];\r\n\r\n\t\tif (dataptr <0 || dataptr >= (this.mem8.length)) throw new Error(\"invalid idx.dataptr passed to getU32\")\r\n\t\tif (size <0 || size > (this.mem8.length-dataptr)) throw new Error(\"invalid idx.size passed to getU32\")\r\n\r\n\t\tif (size%4!=0) throw new Error(\"idx.size is not an integer number of 32 bit words\");\r\n\r\n\t\tconst u32 = new Uint32Array( (this.mem8.slice(dataptr, dataptr+size)).buffer );\r\n\t\treturn u32;\r\n\t}\r\n}\r\n","export class twrFloatUtil {\n mod;\n constructor(mod) {\n this.mod = mod;\n }\n atod(strptr) {\n const str = this.mod.getString(strptr);\n const upper = str.trimStart().toUpperCase();\n if (upper == \"INF\" || upper == \"+INF\")\n return Number.POSITIVE_INFINITY;\n else if (upper == \"-INF\")\n return Number.NEGATIVE_INFINITY;\n else {\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\n const r = Number.parseFloat(str.replaceAll('D', 'e').replaceAll('d', 'e'));\n return r;\n }\n }\n dtoa(buffer, buffer_size, value, max_precision) {\n if (max_precision == -1) {\n const r = value.toString();\n this.mod.copyString(buffer, buffer_size, r);\n }\n else {\n let r = value.toString();\n if (r.length > max_precision)\n r = value.toPrecision(max_precision);\n this.mod.copyString(buffer, buffer_size, r);\n }\n }\n toFixed(buffer, buffer_size, value, decdigits) {\n const r = value.toFixed(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n toExponential(buffer, buffer_size, value, decdigits) {\n const r = value.toExponential(decdigits);\n this.mod.copyString(buffer, buffer_size, r);\n }\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\n // Negative exponents must be now smaller than 1e-99\n // fully-function C version also int he source, but this is the version enabled by default\n fcvtS(buffer, // char *\n sizeInBytes, //size_t\n value, // double\n fracpart_numdigits, //int\n dec, // int *\n sign // int *\n ) {\n if (buffer == 0 || sign == 0 || dec == 0 || sizeInBytes < 1)\n return 1;\n let digits;\n let decpos;\n let s = 0; // default to positive\n if (Number.isNaN(value)) { /* nan */\n digits = \"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (!Number.isFinite(value)) { /* infinity */\n digits = \"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits + 1);\n decpos = 1;\n }\n else if (value == 0) {\n digits = \"000000000000000000000000000000000000\".slice(0, fracpart_numdigits);\n decpos = 0;\n }\n else {\n if (value < 0) {\n s = 1; // negative\n value = Math.abs(value);\n }\n if (fracpart_numdigits > 100 || value > 1e+21 || value < 1e-99) {\n this.mod.copyString(buffer, sizeInBytes, \"\");\n this.mod.mem32[dec] = 0;\n return 1;\n }\n const roundValStr = value.toFixed(fracpart_numdigits);\n let [intPart = \"\", fracPart = \"\"] = roundValStr.split('.');\n if (intPart == \"0\")\n intPart = \"\";\n if (intPart.length > 0) { // has integer part\n decpos = intPart.length;\n digits = intPart + fracPart;\n }\n else { // only a fraction\n digits = fracPart.replace(/^0+/, \"\"); // remove leading zeros\n decpos = digits.length - fracPart.length;\n }\n }\n if (sizeInBytes - 1 < digits.length)\n return 1;\n this.mod.copyString(buffer, sizeInBytes, digits);\n this.mod.setLong(dec, decpos);\n this.mod.setLong(sign, s);\n return 0;\n /*\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\n\n let decpos=0;\n let digits:string;\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\n \n if (decpos>0) { // has integer part\n const intlen=Math.max(decpos, 0);\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\n }\n else { // only a fraction\n const intpart=Math.trunc(value);\n const fracpart=value-intpart;\n const prec=fracpart_numdigits- (-decpos);\n console.log(\"prec=\",prec);\n if (prec<1) {\n digits=\"\";\n }\n else {\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\n digits=nonExponent.replace('.', '');\n digits=digits.replace(/^0+/,\"\");\n }\n }\n\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\n console.log('digits=',digits);\n console.log('dec=',decpos);\n console.log(\"sign=\",s);\n */\n }\n}\n//# sourceMappingURL=twrfloat.js.map","\r\nimport {twrWasmModuleBase} from \"./twrmodbase.js\"\r\n\r\nexport class twrFloatUtil {\r\n mod: twrWasmModuleBase;\r\n\r\n constructor(mod: twrWasmModuleBase) {\r\n this.mod=mod;\r\n }\r\n\r\n atod(strptr:number):number {\r\n const str=this.mod.getString(strptr);\r\n\r\n const upper=str.trimStart().toUpperCase();\r\n if (upper==\"INF\" || upper==\"+INF\")\r\n return Number.POSITIVE_INFINITY;\r\n else if (upper==\"-INF\")\r\n return Number.NEGATIVE_INFINITY\r\n else {\r\n // allow D for exponent -- old microsoft format they still support in fctv and I support in my awbasic\r\n const r=Number.parseFloat(str.replaceAll('D','e').replaceAll('d','e'));\r\n return r;\r\n }\r\n }\r\n\r\n dtoa(buffer:number, buffer_size:number, value:number, max_precision:number):void {\r\n if (max_precision==-1) {\r\n const r=value.toString();\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n else {\r\n let r=value.toString();\r\n if (r.length>max_precision)\r\n r=value.toPrecision(max_precision);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n }\r\n\r\n toFixed(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toFixed(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n toExponential(buffer:number, buffer_size:number, value:number, decdigits:number):void {\r\n const r=value.toExponential(decdigits);\r\n this.mod.copyString(buffer, buffer_size, r);\r\n }\r\n\r\n // emulates the C lib function -fcvt_s, but doesn't support all ranges of number.\r\n // Number.toFixed() has a max size of 100 fractional digits, and values must be less than 1e+21\r\n // Negative exponents must be now smaller than 1e-99\r\n // fully-function C version also int he source, but this is the version enabled by default\r\n fcvtS(\r\n buffer:number, // char *\r\n sizeInBytes:number, //size_t\r\n value:number, // double\r\n fracpart_numdigits:number, //int\r\n dec:number, // int *\r\n sign:number // int *\r\n ):number {\r\n\r\n if (buffer==0 ||sign==0 || dec==0 || sizeInBytes<1) return 1;\r\n\r\n let digits:string;\r\n let decpos:number;\r\n let s=0; // default to positive\r\n\r\n\r\n if (Number.isNaN(value)) { /* nan */\r\n digits=\"1#QNAN00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (!Number.isFinite(value)) { /* infinity */\r\n digits=\"1#INF00000000000000000000000000000\".slice(0, fracpart_numdigits+1);\r\n decpos=1;\r\n }\r\n else if (value==0) { \r\n digits=\"000000000000000000000000000000000000\".slice(0,fracpart_numdigits);\r\n decpos=0;\r\n }\r\n \r\n else {\r\n\r\n if (value<0) {\r\n s=1; // negative\r\n value=Math.abs(value);\r\n }\r\n\r\n if (fracpart_numdigits>100 || value > 1e+21 || value < 1e-99) { \r\n this.mod.copyString(buffer, sizeInBytes, \"\");\r\n this.mod.mem32[dec]=0;\r\n return 1;\r\n }\r\n\r\n const roundValStr=value.toFixed(fracpart_numdigits);\r\n let [intPart=\"\", fracPart=\"\"] = roundValStr.split('.');\r\n if (intPart==\"0\") intPart=\"\";\r\n\r\n if (intPart.length>0) { // has integer part\r\n decpos=intPart.length;\r\n digits=intPart+fracPart;\r\n }\r\n else { // only a fraction\r\n digits=fracPart.replace(/^0+/,\"\"); // remove leading zeros\r\n decpos=digits.length-fracPart.length;\r\n }\r\n }\r\n\r\n if (sizeInBytes-1 < digits.length) return 1; \r\n this.mod.copyString(buffer, sizeInBytes, digits);\r\n this.mod.setLong(dec, decpos);\r\n this.mod.setLong(sign, s);\r\n\r\n return 0;\r\n\r\n /*\r\n this version 'works' with larger numbers than using toFixed, but doesn't round correctly\r\n\r\n let decpos=0;\r\n let digits:string;\r\n if (value!=0) decpos=Math.floor(Math.log10(value))+1;\r\n \r\n if (decpos>0) { // has integer part\r\n const intlen=Math.max(decpos, 0);\r\n console.log(\"intlen=\",intlen, \"decpos=\",decpos);\r\n const [nonExponent, exponent=0] = value.toPrecision(intlen+fracpart_numdigits).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\"); // remove leading zeros\r\n }\r\n else { // only a fraction\r\n const intpart=Math.trunc(value);\r\n const fracpart=value-intpart;\r\n const prec=fracpart_numdigits- (-decpos);\r\n console.log(\"prec=\",prec);\r\n if (prec<1) {\r\n digits=\"\";\r\n }\r\n else {\r\n const [nonExponent, exponent=0] = fracpart.toPrecision(prec).split('e');\r\n digits=nonExponent.replace('.', '');\r\n digits=digits.replace(/^0+/,\"\");\r\n }\r\n }\r\n\r\n console.log(\"fcvtS value\",value,\"fracpart_numdigits\",fracpart_numdigits);\r\n console.log('digits=',digits);\r\n console.log('dec=',decpos);\r\n console.log(\"sign=\",s);\r\n */\r\n\r\n\r\n }\r\n}","import { twrSignal } from \"./twrsignal.js\";\nimport { twrTimeImpl } from \"./twrdate.js\";\n// This class is used in the Main JS thread \nexport class twrWaitingCalls {\n callCompleteSignal;\n parameters;\n constructor() {\n this.callCompleteSignal = new twrSignal();\n this.parameters = new Uint32Array(new SharedArrayBuffer(4));\n }\n startSleep(ms) {\n setTimeout(() => {\n this.callCompleteSignal.signal();\n }, ms);\n }\n time() {\n const ms = twrTimeImpl();\n this.parameters[0] = ms;\n this.callCompleteSignal.signal();\n }\n getProxyParams() {\n return [this.callCompleteSignal.sharedArray, this.parameters.buffer];\n }\n processMessage(msgType, data) {\n switch (msgType) {\n case \"sleep\":\n const [ms] = data;\n this.startSleep(ms);\n break;\n case \"time\":\n this.time();\n break;\n default:\n return false;\n }\n return true;\n }\n}\n// This class is used in the worker thread \nexport class twrWaitingCallsProxy {\n callCompleteSignal;\n parameters;\n constructor(params) {\n this.callCompleteSignal = new twrSignal(params[0]);\n this.parameters = new Uint32Array(params[1]);\n }\n sleep(ms) {\n this.callCompleteSignal.reset();\n postMessage([\"sleep\", [ms]]);\n this.callCompleteSignal.wait();\n }\n time() {\n this.callCompleteSignal.reset();\n postMessage([\"time\"]);\n this.callCompleteSignal.wait();\n return this.parameters[0];\n }\n}\n//# sourceMappingURL=twrwaitingcalls.js.map","import { twrSignal } from \"./twrsignal.js\";\r\nimport {twrTimeImpl} from \"./twrdate.js\"\r\n\r\n// These classes are used to proxy a call across the worker thread - main thread boundary and wait for the result\r\n\r\nexport type TWaitingCallsProxyParams = [SharedArrayBuffer, SharedArrayBuffer]; // twrSignal, parameters \r\n\r\n// This class is used in the Main JS thread \r\nexport class twrWaitingCalls {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor() {\r\n\t\tthis.callCompleteSignal=new twrSignal();\r\n\t\tthis.parameters=new Uint32Array(new SharedArrayBuffer(4));\r\n\t}\r\n\r\n\tprivate startSleep(ms:number) {\r\n\r\n\t\tsetTimeout(()=>{\r\n\t\t\tthis.callCompleteSignal.signal();\r\n\t\t}, ms);\r\n\t\t\r\n\t}\r\n\r\n\tprivate time() {\r\n\t\tconst ms=twrTimeImpl();\r\n\t\tthis.parameters[0]=ms;\r\n\t\tthis.callCompleteSignal.signal();\r\n\t}\r\n\r\n\tgetProxyParams():TWaitingCallsProxyParams {\r\n\t\treturn [this.callCompleteSignal.sharedArray, this.parameters.buffer as SharedArrayBuffer];\t\r\n\t}\r\n\r\n\tprocessMessage(msgType:string, data:any[]):boolean {\r\n\t\tswitch (msgType) {\r\n\t\t\tcase \"sleep\":\r\n\t\t\t\tconst [ms] = data;\r\n\t\t\t\tthis.startSleep(ms);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase \"time\":\r\n\t\t\t\tthis.time();\r\n\t\t\t\tbreak;\r\n\t\t\t\r\n\t\t\tdefault:\r\n\t\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\treturn true;\r\n\t}\r\n\r\n}\r\n\r\n// This class is used in the worker thread \r\nexport class twrWaitingCallsProxy {\r\n\tcallCompleteSignal:twrSignal;\r\n\tparameters:Uint32Array;\r\n\r\n\tconstructor(params:TWaitingCallsProxyParams) {\r\n\t\tthis.callCompleteSignal=new twrSignal(params[0]);\r\n\t\tthis.parameters=new Uint32Array(params[1]);\r\n\t}\r\n\r\n\tsleep(ms:number) {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"sleep\", [ms]]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t}\r\n\r\n\ttime() {\r\n\t\tthis.callCompleteSignal.reset();\r\n\t\tpostMessage([\"time\"]);\r\n\t\tthis.callCompleteSignal.wait();\r\n\t\treturn this.parameters[0];\r\n\t}\r\n\r\n}\r\n","export function twrTimeImpl() {\n return Date.now();\n}\n//# sourceMappingURL=twrdate.js.map","\r\nexport function twrTimeImpl() {\r\n\r\n return Date.now();\r\n\r\n}"],"names":["$b93f1fdf40141def$var$twrSignalState","$c4741cac81d14197$var$D2DType","twrSignalState","D2DType","$3e39efa823870787$var$mod","$892fccfc812d5e20$export$a01cca24f011573a","sharedArray","buf","constructor","sa","window","crossOriginIsolated","location","protocol","Error","SharedArrayBuffer","Int32Array","write","n","i","Atomics","notify","read","isEmpty","readWait","rdptr","wait","$b93f1fdf40141def$export$e37a7b7b851b97f3","WAITING","signal","SIGNALED","isSignaled","reset","$c4741cac81d14197$export$c779b2cd00544976","canvasKeys","drawCompleteSignal","props","owner","params","signalBuffer","canvasKeysBuffer","charIn","inkey","getProp","pn","propName","getString","drawSeq","ds","postMessage","$8963973702ae5462$export$b377f0bbf2c7581e","divKeys","divKeysBuffer","charOut","ch","$8ac0b786da854328$export$485af4d0039b3389","$e72303a1db04bdfa$export$918ffb7e046a537b","mod","atod","strptr","str","upper","trimStart","toUpperCase","Number","POSITIVE_INFINITY","NEGATIVE_INFINITY","parseFloat","replaceAll","dtoa","buffer","buffer_size","value","max_precision","r","toString","copyString","length","toPrecision","toFixed","decdigits","toExponential","fcvtS","sizeInBytes","fracpart_numdigits","dec","sign","digits","decpos","s","isNaN","slice","isFinite","Math","abs","mem32","intPart","fracPart","roundValStr","split","replace","setLong","$ece7fa3ed770778a$export$c83a0a3bffe07399","memory","mem8","memD","exports","isWorker","isWasmModule","floatUtil","Uint8Array","Uint32Array","Float64Array","loadWasm","pathToLoad","response","fetch","err","console","log","ok","statusText","wasmBytes","arrayBuffer","allimports","modParams","imports","instance","WebAssembly","instantiate","env","ArrayBuffer","malloc","size","Promise","resolve","m","twr_malloc","init","stack","p","stdio","twrInit","twr_wasm_init","callC","cparams","preCallC","retval","callCImpl","postCallC","fname","f","Array","ci","putString","URL","fetchAndPutURL","putArrayBuffer","u8","j","sin","charCodeAt","strIndex","putU8","u8a","dest","ab","fnin","src","getLong","idx","idx32","floor","getDouble","idx64","setDouble","getShort","len","sout","undefined","String","fromCharCode","getU8Arr","rv","dataptr","getU32Arr","$aff9c2c494d23fe3$export$78d2a4633fe89379","callCompleteSignal","parameters","sleep","ms","time","onmessage","e","data","$3e39efa823870787$var$twrWasmModuleInWorker","modWorkerParams","urlToLoad","then","catch","ex","rc","modInWorkerParams","canvasProxy","canvasProxyParams","divProxy","divProxyParams","waitingCallsProxy","waitingCallsProxyParams","twrDebugLog","twrSleep","bind","twrTime","twrDivCharOut","twrDivCharIn","twrCanvasCharIn","twrCanvasInkey","twrCanvasGetProp","twrCanvasDrawSeq","twrSin","twrCos","cos","twrTan","tan","twrFAbs","twrACos","acos","twrASin","asin","twrATan","atan","twrExp","exp","twrFloor","twrCeil","ceil","twrFMod","x","y","twrLog","twrPow","pow","twrSqrt","sqrt","twrTrunc","trunc","twrDtoa","twrToFixed","twrToExponential","twrAtod","twrFcvtS"],"version":3,"file":"twrmodworker.2165e649.js.map"} \ No newline at end of file diff --git a/azure/examples/tests/index.html b/azure/examples/tests/index.html index 5966331e..9cddf32d 100644 --- a/azure/examples/tests/index.html +++ b/azure/examples/tests/index.html @@ -20,7 +20,7 @@ const mod = new twrWasmModule(); await mod.loadWasm("./tests.wasm"); - await mod.executeC(["tests"]); + await mod.callC(["tests"]); mod.divLog("\nsin() speed test"); let sum=0; @@ -31,7 +31,7 @@ const endA=Date.now(); - sum=await mod.executeC(["sin_test"]); + sum=await mod.callC(["sin_test"]); const endB=Date.now(); mod.divLog("sum A: ", sum, " in ms: ", endA-start); diff --git a/azure/lib-js/twrmodasync.d.ts b/azure/lib-js/twrmodasync.d.ts index 0a3b6b1f..6dc13836 100644 --- a/azure/lib-js/twrmodasync.d.ts +++ b/azure/lib-js/twrmodasync.d.ts @@ -11,14 +11,14 @@ export declare class twrWasmModuleAsync extends twrWasmModuleInJSMain { malloc: (size: number) => Promise; loadWasmResolve?: (value: void) => void; loadWasmReject?: (reason?: any) => void; - executeCResolve?: (value: unknown) => void; - executeCReject?: (reason?: any) => void; + callCResolve?: (value: unknown) => void; + callCReject?: (reason?: any) => void; initLW: boolean; waitingcalls?: twrWaitingCalls; constructor(opts?: IModOpts); loadWasm(pathToLoad: string): Promise; - executeC(params: [string, ...(string | number | Uint8Array)[]]): Promise; - executeCImpl(fname: string, cparams?: number[]): Promise; + callC(params: [string, ...(string | number | Uint8Array)[]]): Promise; + callCImpl(fname: string, cparams?: number[]): Promise; keyDownDiv(ev: KeyboardEvent): void; keyDownCanvas(ev: KeyboardEvent): void; processMsg(event: MessageEvent): void; diff --git a/azure/lib-js/twrmodasync.js b/azure/lib-js/twrmodasync.js index ebd6d479..e3f0863f 100644 --- a/azure/lib-js/twrmodasync.js +++ b/azure/lib-js/twrmodasync.js @@ -7,8 +7,8 @@ export class twrWasmModuleAsync extends twrWasmModuleInJSMain { malloc; loadWasmResolve; loadWasmReject; - executeCResolve; - executeCReject; + callCResolve; + callCReject; initLW = false; waitingcalls; constructor(opts) { @@ -28,7 +28,7 @@ export class twrWasmModuleAsync extends twrWasmModuleInJSMain { this.loadWasmResolve = resolve; this.loadWasmReject = reject; this.malloc = (size) => { - return this.executeCImpl("twr_malloc", [size]); + return this.callCImpl("twr_malloc", [size]); }; this.waitingcalls = new twrWaitingCalls(); // handle's calls that cross the worker thread - main js thread boundary let canvas; @@ -46,15 +46,15 @@ export class twrWasmModuleAsync extends twrWasmModuleInJSMain { this.myWorker.postMessage(['startup', startMsg]); }); } - async executeC(params) { + async callC(params) { const cparams = await this.preCallC(params); // will also validate params[0] - return this.executeCImpl(params[0], cparams); + return this.callCImpl(params[0], cparams); } - async executeCImpl(fname, cparams = []) { + async callCImpl(fname, cparams = []) { return new Promise((resolve, reject) => { - this.executeCResolve = resolve; - this.executeCReject = reject; - this.myWorker.postMessage(['executeC', fname, cparams]); + this.callCResolve = resolve; + this.callCReject = reject; + this.myWorker.postMessage(['callC', fname, cparams]); }); } // this function should be called from HTML "keydown" event from
@@ -116,17 +116,17 @@ export class twrWasmModuleAsync extends twrWasmModuleInJSMain { else throw new Error("twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmResolve)"); break; - case "executeCFail": - if (this.executeCReject) - this.executeCReject(d); + case "callCFail": + if (this.callCReject) + this.callCReject(d); else - throw new Error("twrWasmAsyncModule.processMsg unexpected error (undefined executeCReject)"); + throw new Error("twrWasmAsyncModule.processMsg unexpected error (undefined callCReject)"); break; - case "executeCOkay": - if (this.executeCResolve) - this.executeCResolve(d); + case "callCOkay": + if (this.callCResolve) + this.callCResolve(d); else - throw new Error("twrWasmAsyncModule.processMsg unexpected error (undefined executeCResolve)"); + throw new Error("twrWasmAsyncModule.processMsg unexpected error (undefined callCResolve)"); break; default: if (!this.waitingcalls) diff --git a/azure/lib-js/twrmodbase.d.ts b/azure/lib-js/twrmodbase.d.ts index 2695a90e..b5ddfaa7 100644 --- a/azure/lib-js/twrmodbase.d.ts +++ b/azure/lib-js/twrmodbase.d.ts @@ -48,8 +48,8 @@ export declare abstract class twrWasmModuleBase { /*********************************************************************/ loadWasm(pathToLoad: string): Promise; private init; - executeC(params: [string, ...(string | number | ArrayBuffer | URL)[]]): Promise; - executeCImpl(fname: string, cparams?: number[]): Promise; + callC(params: [string, ...(string | number | ArrayBuffer | URL)[]]): Promise; + callCImpl(fname: string, cparams?: number[]): Promise; preCallC(params: [string, ...(string | number | ArrayBuffer | URL)[]]): Promise; postCallC(cparams: number[], params: [string, ...(string | number | ArrayBuffer | URL)[]]): Promise; /*********************************************************************/ diff --git a/azure/lib-js/twrmodbase.js b/azure/lib-js/twrmodbase.js index f4d79288..397bb8c8 100644 --- a/azure/lib-js/twrmodbase.js +++ b/azure/lib-js/twrmodbase.js @@ -98,7 +98,7 @@ export class twrWasmModuleBase { //console.log("twrInit:",twrInit) twrInit(p, this.mem8.length); } - /* executeC takes an array where: + /* callC takes an array where: * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag) * and the next entries are a variable number of parameters to pass to the C function, of type * number - converted to int32 or float64 as appropriate @@ -106,17 +106,17 @@ export class twrWasmModuleBase { * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length */ - async executeC(params) { + async callC(params) { const cparams = await this.preCallC(params); - let retval = this.executeCImpl(params[0], cparams); + let retval = this.callCImpl(params[0], cparams); this.postCallC(cparams, params); return retval; } - async executeCImpl(fname, cparams = []) { + async callCImpl(fname, cparams = []) { if (!this.exports) throw new Error("this.exports undefined"); if (!this.exports[fname]) - throw new Error("executeC: function '" + fname + "' not in export table. Use --export wasm-ld flag."); + throw new Error("callC: function '" + fname + "' not in export table. Use --export wasm-ld flag."); const f = this.exports[fname]; let cr = f(...cparams); return cr; @@ -124,9 +124,9 @@ export class twrWasmModuleBase { // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory async preCallC(params) { if (!(params.constructor === Array)) - throw new Error("executeC: params must be array, first arg is function name"); + throw new Error("callC: params must be array, first arg is function name"); if (params.length == 0) - throw new Error("executeC: missing function name"); + throw new Error("callC: missing function name"); let cparams = []; let ci = 0; for (let i = 1; i < params.length; i++) { @@ -151,7 +151,7 @@ export class twrWasmModuleBase { break; } default: - throw new Error("executeC: invalid object type passed in"); + throw new Error("callC: invalid object type passed in"); } } return cparams; @@ -166,12 +166,12 @@ export class twrWasmModuleBase { ci++; break; case 'string': - this.executeCImpl('twr_free', [cparams[ci]]); + this.callCImpl('twr_free', [cparams[ci]]); ci++; break; case 'object': if (p instanceof URL) { - this.executeCImpl('twr_free', [cparams[ci]]); + this.callCImpl('twr_free', [cparams[ci]]); ci = ci + 2; break; } @@ -179,7 +179,7 @@ export class twrWasmModuleBase { let u8 = new Uint8Array(p); for (let j = 0; j < u8.length; j++) u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory - this.executeCImpl('twr_free', [cparams[ci]]); + this.callCImpl('twr_free', [cparams[ci]]); ci++; break; } diff --git a/azure/lib-js/twrmodworker.js b/azure/lib-js/twrmodworker.js index fe0fa755..cf2b5cd9 100644 --- a/azure/lib-js/twrmodworker.js +++ b/azure/lib-js/twrmodworker.js @@ -18,13 +18,13 @@ onmessage = function (e) { postMessage(["startupFail", ex]); }); } - else if (e.data[0] == 'executeC') { - mod.executeCImpl(e.data[1], e.data[2]).then((rc) => { - postMessage(["executeCOkay", rc]); + else if (e.data[0] == 'callC') { + mod.callCImpl(e.data[1], e.data[2]).then((rc) => { + postMessage(["callCOkay", rc]); }).catch(e => { - console.log("exception in executeC twrworker.js\n"); + console.log("exception in callC twrworker.js\n"); console.log(e); - postMessage(["executeCFail", e]); + postMessage(["callCFail", e]); }); } else { diff --git a/azure/source/twr-wasm-ts/twr-wasm-ts/twrmodasync.ts b/azure/source/twr-wasm-ts/twr-wasm-ts/twrmodasync.ts index 983bb2a8..d3d87bc0 100644 --- a/azure/source/twr-wasm-ts/twr-wasm-ts/twrmodasync.ts +++ b/azure/source/twr-wasm-ts/twr-wasm-ts/twrmodasync.ts @@ -17,8 +17,8 @@ export class twrWasmModuleAsync extends twrWasmModuleInJSMain { malloc:(size:number)=>Promise; loadWasmResolve?: (value: void) => void; loadWasmReject?: (reason?: any) => void; - executeCResolve?: (value: unknown) => void; - executeCReject?: (reason?: any) => void; + callCResolve?: (value: unknown) => void; + callCReject?: (reason?: any) => void; initLW=false; waitingcalls?:twrWaitingCalls; @@ -43,7 +43,7 @@ export class twrWasmModuleAsync extends twrWasmModuleInJSMain { this.loadWasmReject=reject; this.malloc = (size:number) => { - return this.executeCImpl("twr_malloc", [size]) as Promise; + return this.callCImpl("twr_malloc", [size]) as Promise; } this.waitingcalls=new twrWaitingCalls(); // handle's calls that cross the worker thread - main js thread boundary @@ -63,16 +63,16 @@ export class twrWasmModuleAsync extends twrWasmModuleInJSMain { }); } - async executeC(params:[string, ...(string|number|Uint8Array)[]]) { + async callC(params:[string, ...(string|number|Uint8Array)[]]) { const cparams=await this.preCallC(params); // will also validate params[0] - return this.executeCImpl(params[0], cparams); + return this.callCImpl(params[0], cparams); } - async executeCImpl(fname:string, cparams:number[]=[]) { + async callCImpl(fname:string, cparams:number[]=[]) { return new Promise((resolve, reject)=>{ - this.executeCResolve=resolve; - this.executeCReject=reject; - this.myWorker.postMessage(['executeC', fname, cparams]); + this.callCResolve=resolve; + this.callCReject=reject; + this.myWorker.postMessage(['callC', fname, cparams]); }); } @@ -144,18 +144,18 @@ export class twrWasmModuleAsync extends twrWasmModuleInJSMain { throw new Error("twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmResolve)"); break; - case "executeCFail": - if (this.executeCReject) - this.executeCReject(d); + case "callCFail": + if (this.callCReject) + this.callCReject(d); else - throw new Error("twrWasmAsyncModule.processMsg unexpected error (undefined executeCReject)"); + throw new Error("twrWasmAsyncModule.processMsg unexpected error (undefined callCReject)"); break; - case "executeCOkay": - if (this.executeCResolve) - this.executeCResolve(d); + case "callCOkay": + if (this.callCResolve) + this.callCResolve(d); else - throw new Error("twrWasmAsyncModule.processMsg unexpected error (undefined executeCResolve)"); + throw new Error("twrWasmAsyncModule.processMsg unexpected error (undefined callCResolve)"); break; default: diff --git a/azure/source/twr-wasm-ts/twr-wasm-ts/twrmodbase.ts b/azure/source/twr-wasm-ts/twr-wasm-ts/twrmodbase.ts index 4ddba187..f9cb78fd 100644 --- a/azure/source/twr-wasm-ts/twr-wasm-ts/twrmodbase.ts +++ b/azure/source/twr-wasm-ts/twr-wasm-ts/twrmodbase.ts @@ -148,7 +148,7 @@ export abstract class twrWasmModuleBase { twrInit(p, this.mem8.length); } - /* executeC takes an array where: + /* callC takes an array where: * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag) * and the next entries are a variable number of parameters to pass to the C function, of type * number - converted to int32 or float64 as appropriate @@ -157,16 +157,16 @@ export abstract class twrWasmModuleBase { * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length */ - async executeC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) { + async callC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) { const cparams=await this.preCallC(params); - let retval = this.executeCImpl(params[0], cparams); + let retval = this.callCImpl(params[0], cparams); this.postCallC(cparams, params); return retval; } - async executeCImpl(fname:string, cparams:number[]=[]) { + async callCImpl(fname:string, cparams:number[]=[]) { if (!this.exports) throw new Error("this.exports undefined"); - if (!this.exports[fname]) throw new Error("executeC: function '"+fname+"' not in export table. Use --export wasm-ld flag."); + if (!this.exports[fname]) throw new Error("callC: function '"+fname+"' not in export table. Use --export wasm-ld flag."); const f = this.exports[fname] as CallableFunction; let cr=f(...cparams); @@ -177,8 +177,8 @@ export abstract class twrWasmModuleBase { // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory async preCallC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) { - if (!(params.constructor === Array)) throw new Error ("executeC: params must be array, first arg is function name"); - if (params.length==0) throw new Error("executeC: missing function name"); + if (!(params.constructor === Array)) throw new Error ("callC: params must be array, first arg is function name"); + if (params.length==0) throw new Error("callC: missing function name"); let cparams:number[]=[]; let ci=0; @@ -204,7 +204,7 @@ export abstract class twrWasmModuleBase { break; } default: - throw new Error ("executeC: invalid object type passed in"); + throw new Error ("callC: invalid object type passed in"); } } @@ -223,13 +223,13 @@ export abstract class twrWasmModuleBase { break; case 'string': - this.executeCImpl('twr_free',[cparams[ci]]) + this.callCImpl('twr_free',[cparams[ci]]) ci++; break; case 'object': if (p instanceof URL) { - this.executeCImpl('twr_free',[cparams[ci]]) + this.callCImpl('twr_free',[cparams[ci]]) ci=ci+2; break; } @@ -237,7 +237,7 @@ export abstract class twrWasmModuleBase { let u8=new Uint8Array(p); for (let j=0; j { - postMessage(["executeCOkay", rc]); + else if (e.data[0]=='callC') { + mod.callCImpl(e.data[1], e.data[2]).then( (rc)=> { + postMessage(["callCOkay", rc]); }).catch(e => { - console.log("exception in executeC twrworker.js\n"); + console.log("exception in callC twrworker.js\n"); console.log(e); - postMessage(["executeCFail", e]); + postMessage(["callCFail", e]); }); } else { diff --git a/examples/balls/async.html b/examples/balls/async.html index 112a732b..cba68c73 100644 --- a/examples/balls/async.html +++ b/examples/balls/async.html @@ -64,7 +64,7 @@

tiny-wasm-runtime

const mod=new twrWasmModuleAsync(); await mod.loadWasm('balls-a.wasm'); - await mod.executeC(["bounce_balls_init", ballSpeed]); + await mod.callC(["bounce_balls_init", ballSpeed]); let lastTime; @@ -75,7 +75,7 @@

tiny-wasm-runtime

else intervalTimeMs=timeStamp-lastTime; lastTime=timeStamp; - mod.executeC(["bounce_balls_move", intervalTimeMs]).then(()=>{ + mod.callC(["bounce_balls_move", intervalTimeMs]).then(()=>{ window.requestAnimationFrame(moveBalls); }); } diff --git a/examples/balls/index.html b/examples/balls/index.html index 35808995..2ea7b973 100644 --- a/examples/balls/index.html +++ b/examples/balls/index.html @@ -64,7 +64,7 @@

tiny-wasm-runtime

const mod=new twrWasmModule(); await mod.loadWasm('balls.wasm'); - await mod.executeC(["bounce_balls_init", ballSpeed]); + await mod.callC(["bounce_balls_init", ballSpeed]); let lastTime; @@ -75,7 +75,7 @@

tiny-wasm-runtime

else intervalTimeMs=timeStamp-lastTime; lastTime=timeStamp; - mod.executeC(["bounce_balls_move", intervalTimeMs]).then(()=>{ + mod.callC(["bounce_balls_move", intervalTimeMs]).then(()=>{ window.requestAnimationFrame(moveBalls); }); } diff --git a/examples/fft/fft-script.ts b/examples/fft/fft-script.ts index 99db96f9..bcb20842 100644 --- a/examples/fft/fft-script.ts +++ b/examples/fft/fft-script.ts @@ -19,7 +19,7 @@ export async function fftDemo() { // kiss_fft_alloc() returns a malloced structure. Pointers are numbers (index into wasm module memory) in JS land // //kiss_fft_cfg cfg = kiss_fft_alloc( nfft ,is_inverse_fft ,0,0 ); - let cfg:number = await mod.executeC(["kiss_fft_alloc", fft.nfft, 0, 0, 0 ]); + let cfg:number = await mod.callC(["kiss_fft_alloc", fft.nfft, 0, 0, 0 ]); // The FFT input and output data are C arrays of complex numbers. // typedef struct { @@ -33,16 +33,16 @@ export async function fftDemo() { // So if the FFT data has 1024 bins, then 1024 * 2 floats (r & i) * 4 bytes per float are needed. // I use a JS Float32Array view on the ArrayBuffer to access the floats - // When an arrayBuffer is passed in as an argument to mod.executeC, executeC will malloc memory in the wasm module of a size that matches the array buffer, then + // When an arrayBuffer is passed in as an argument to mod.callC, callC will malloc memory in the wasm module of a size that matches the array buffer, then // copy the arraybuffer into the malloc'd memory prior to the function call, then copy the malloc'd memory contents back into the arrayBuffer post call. // The malloc'd memory is free'd post call. // void kiss_fft(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout); - await mod.executeC(["kiss_fft", cfg, fft.inArrayBuf, fft.outArrayBuf]); + await mod.callC(["kiss_fft", cfg, fft.inArrayBuf, fft.outArrayBuf]); fft.graphOut("c-output"); - await mod.executeC(["twr_free", cfg]); // not much point to this since all the module memory is about to disappear + await mod.callC(["twr_free", cfg]); // not much point to this since all the module memory is about to disappear } // this class holds the in and out data, diff --git a/examples/function-calls/async.html b/examples/function-calls/async.html index d12470b8..a2e37db4 100644 --- a/examples/function-calls/async.html +++ b/examples/function-calls/async.html @@ -31,7 +31,7 @@ await amod.loadWasm("./function-calls-a.wasm"); // this output goes to the console - await amod.executeC(["twr_wasm_print_mem_debug_stats"]); + await amod.callC(["twr_wasm_print_mem_debug_stats"]); const s="This is a string."; @@ -42,20 +42,20 @@ amod.divLog("module type is twrWasmModuleAsync\n"); amod.divLog("--- begin C call ---"); - let r=await amod.executeC(["function_calls", s, ba.buffer, ba.length, url]); + let r=await amod.callC(["function_calls", s, ba.buffer, ba.length, url]); amod.divLog("--- end C call ---\n"); amod.divLog("function_calls() returned: "+r); amod.divLog("as string: ", amod.getString(r)); if (amod.getString(r)!="forty-two - if only it were that simple") throw new Error("42 error"); - r=await amod.executeC(["get_structu32"]); + r=await amod.callC(["get_structu32"]); amod.divLog("get_struct32() returned: "+r); const ba32=amod.getU32Arr(r); amod.divLog("three 32 bit ints are: ", ba32[0], ba32[1], ba32[2]); if (ba32[0]!=1 || ba32[1]!=2000 || ba32[2]!=3) throw new Error("error"); - r=await amod.executeC(["get_structu8"]); + r=await amod.callC(["get_structu8"]); amod.divLog("get_struct8() returned: "+r); const ba8=amod.getU8Arr(r); amod.divLog("three 8 bit ints are: ", ba8[0], ba8[1], ba8[2]); diff --git a/examples/function-calls/index.html b/examples/function-calls/index.html index c1f7d100..670139d6 100644 --- a/examples/function-calls/index.html +++ b/examples/function-calls/index.html @@ -30,7 +30,7 @@ await mod.loadWasm("./function-calls.wasm"); // this output goes to the console - await mod.executeC(["twr_wasm_print_mem_debug_stats"]); + await mod.callC(["twr_wasm_print_mem_debug_stats"]); const s="This is a string."; @@ -41,20 +41,20 @@ mod.divLog("module type is twrWasmModule\n"); mod.divLog("--- begin C call ---"); - let r=await mod.executeC(["function_calls", s, ba.buffer, ba.length, url]); + let r=await mod.callC(["function_calls", s, ba.buffer, ba.length, url]); mod.divLog("--- end C call ---\n"); mod.divLog("function_calls() returned: "+r); mod.divLog("as string: ", mod.getString(r)); if (mod.getString(r)!="forty-two - if only it were that simple") throw new Error("42 error"); - r=await mod.executeC(["get_structu32"]); + r=await mod.callC(["get_structu32"]); mod.divLog("get_struct32() returned: "+r); const ba32=mod.getU32Arr(r); mod.divLog("three 32 bit ints are: ", ba32[0], ba32[1], ba32[2]); if (ba32[0]!=1 || ba32[1]!=2000 || ba32[2]!=3) throw new Error("error"); - r=await mod.executeC(["get_structu8"]); + r=await mod.callC(["get_structu8"]); mod.divLog("get_struct8() returned: "+r); const ba8=mod.getU8Arr(r); mod.divLog("three 8 bit ints are: ", ba8[0], ba8[1], ba8[2]); diff --git a/examples/helloworld/index.html b/examples/helloworld/index.html index 91082df6..3801ba5c 100644 --- a/examples/helloworld/index.html +++ b/examples/helloworld/index.html @@ -22,7 +22,7 @@ const mod = new twrWasmModule(); await mod.loadWasm("./helloworld.wasm"); - await mod.executeC(["hello"]); + await mod.callC(["hello"]); diff --git a/examples/maze/maze-script.ts b/examples/maze/maze-script.ts index 80061f70..3aeed3b1 100644 --- a/examples/maze/maze-script.ts +++ b/examples/maze/maze-script.ts @@ -17,11 +17,11 @@ export async function mazeRunner() { await amod.loadWasm('maze.wasm'); //void CalcMaze(HWND hWnd, LONG cell_size, LONG is_black_bg, LONG isd - slow draw) - await amod.executeC(["CalcMaze", 0, 7, 0, 1]); - await amod.executeC(["SolveBegin"]); + await amod.callC(["CalcMaze", 0, 7, 0, 1]); + await amod.callC(["SolveBegin"]); let timer = setInterval(async ()=>{ - let isdone=await amod.executeC(["SolveStep", 0]); //SolveStep(hwnd)) + let isdone=await amod.callC(["SolveStep", 0]); //SolveStep(hwnd)) if (isdone) clearInterval(timer); }, 50); } diff --git a/examples/stdio-canvas/index.html b/examples/stdio-canvas/index.html index fedfb6f6..8ac2322d 100644 --- a/examples/stdio-canvas/index.html +++ b/examples/stdio-canvas/index.html @@ -25,8 +25,8 @@ document.getElementById("twr_iocanvas").addEventListener("keydown",(ev)=>{amod.keyDownCanvas(ev)}); await amod.loadWasm("./stdio-canvas.wasm"); - const r=await amod.executeC(["stdio_canvas"]); - console.log("executeC returned: "+r); + const r=await amod.callC(["stdio_canvas"]); + console.log("callC returned: "+r); } catch(ex) { console.log("unexpected exception"); diff --git a/examples/stdio-div/index.html b/examples/stdio-div/index.html index f84776d8..cfe7f021 100644 --- a/examples/stdio-div/index.html +++ b/examples/stdio-div/index.html @@ -28,7 +28,7 @@ document.getElementById("twr_iodiv").addEventListener("keydown",(ev)=>{amod.keyDownDiv(ev)}); await amod.loadWasm("./stdio-div.wasm"); - await amod.executeC(["stdio_div"]); + await amod.callC(["stdio_div"]); } catch(ex) { amod.divLog("Unexpected Exception."); diff --git a/examples/tests/index.html b/examples/tests/index.html index 5966331e..9cddf32d 100644 --- a/examples/tests/index.html +++ b/examples/tests/index.html @@ -20,7 +20,7 @@ const mod = new twrWasmModule(); await mod.loadWasm("./tests.wasm"); - await mod.executeC(["tests"]); + await mod.callC(["tests"]); mod.divLog("\nsin() speed test"); let sum=0; @@ -31,7 +31,7 @@ const endA=Date.now(); - sum=await mod.executeC(["sin_test"]); + sum=await mod.callC(["sin_test"]); const endB=Date.now(); mod.divLog("sum A: ", sum, " in ms: ", endA-start); diff --git a/lib-js/twrcanvas.js b/lib-js/twrcanvas.js index f25f8f8d..5ca21d9e 100644 --- a/lib-js/twrcanvas.js +++ b/lib-js/twrcanvas.js @@ -67,7 +67,7 @@ export class twrCanvas { this.props.canvasHeight = element.height; this.props.canvasWidth = element.width; //console.log("this.props.canvasHeight, this.props.canvasWidth",this.props.canvasHeight,this.props.canvasWidth); - // reset after dims changed. Not sure if ctx is needed to rest, but others do + // reset after dims changed. Not sure if ctx is needed to reset, but others do let c2 = element.getContext("2d"); if (!c2) throw new Error("canvas 2D context not found in twrCanvas.constructor (2nd time)"); diff --git a/lib-js/twrcanvas.js.map b/lib-js/twrcanvas.js.map index cd7a9f52..e1cddefb 100644 --- a/lib-js/twrcanvas.js.map +++ b/lib-js/twrcanvas.js.map @@ -1 +1 @@ -{"version":3,"file":"twrcanvas.js","sourceRoot":"","sources":["../source/twr-wasm-ts/twrcanvas.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,uBAAuB,EAAC,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAC,SAAS,EAAC,MAAM,gBAAgB,CAAC;AAmBzC,IAAK,OA6BJ;AA7BD,WAAK,OAAO;IACR,qDAAc,CAAA;IACd,qDAAc,CAAA;IACd,8DAAmB,CAAA;IACnB,sEAAuB,CAAA;IACvB,oDAAc,CAAA;IACd,wDAAgB,CAAA;IAChB,kDAAa,CAAA;IACb,kDAAa,CAAA;IACb,8CAAW,CAAA;IACX,kDAAa,CAAA;IACb,0EAAyB,CAAA;IACzB,4CAAU,CAAA;IACV,0DAAiB,CAAA;IACjB,sDAAe,CAAA;IACf,wDAAgB,CAAA;IAChB,8DAAmB,CAAA;IACnB,sDAAe,CAAA;IACf,4DAAkB,CAAA;IAClB,8CAAW,CAAA;IACX,oDAAc,CAAA;IACd,8EAA2B,CAAA;IAC3B,8DAAmB,CAAA;IACnB,8EAA2B,CAAA;IAC3B,wDAAgB,CAAA;IAChB,8EAA2B,CAAA;IAC3B,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IAED,MAAM;QACF,mCAAmC;QAEnC,8BAA8B;QAE9B,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAE,+BAA+B;IACvE,CAAC;IAED,KAAK;QACD,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE;YACzB,OAAO,CAAC,CAAC;;YAET,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IAC7B,CAAC;IAED,OAAO,CAAC,EAAS;QACb,MAAM,QAAQ,GAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAuB,CAAC;QAC9D,gGAAgG;QAChG,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC;IAED,OAAO,CAAC,EAAS;QACb,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,CAAC;QAChC,WAAW,CAAC,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC/B,IAAI,CAAC,kBAAkB,CAAC,IAAI,EAAE,CAAC;IACnC,CAAC;CACJ"} \ No newline at end of file +{"version":3,"file":"twrcanvas.js","sourceRoot":"","sources":["../source/twr-wasm-ts/twrcanvas.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,uBAAuB,EAAC,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAC,SAAS,EAAC,MAAM,gBAAgB,CAAC;AAmBzC,IAAK,OA6BJ;AA7BD,WAAK,OAAO;IACR,qDAAc,CAAA;IACd,qDAAc,CAAA;IACd,8DAAmB,CAAA;IACnB,sEAAuB,CAAA;IACvB,oDAAc,CAAA;IACd,wDAAgB,CAAA;IAChB,kDAAa,CAAA;IACb,kDAAa,CAAA;IACb,8CAAW,CAAA;IACX,kDAAa,CAAA;IACb,0EAAyB,CAAA;IACzB,4CAAU,CAAA;IACV,0DAAiB,CAAA;IACjB,sDAAe,CAAA;IACf,wDAAgB,CAAA;IAChB,8DAAmB,CAAA;IACnB,sDAAe,CAAA;IACf,4DAAk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G,IAAI,uBAAuB,CAAC,gBAAgB,CAAC,CAAC;QAChE,IAAI,CAAC,KAAK,GAAC,KAAK,CAAC;QACjB,IAAI,CAAC,KAAK,GAAC,KAAK,CAAC;QAEjB,uDAAuD;IAE3D,CAAC;IAED,MAAM;QACF,mCAAmC;QAEnC,8BAA8B;QAE9B,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAE,+BAA+B;IACvE,CAAC;IAED,KAAK;QACD,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE;YACzB,OAAO,CAAC,CAAC;;YAET,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IAC7B,CAAC;IAED,OAAO,CAAC,EAAS;QACb,MAAM,QAAQ,GAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAuB,CAAC;QAC9D,gGAAgG;QAChG,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC;IAED,OAAO,CAAC,EAAS;QACb,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,CAAC;QAChC,WAAW,CAAC,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC/B,IAAI,CAAC,kBAAkB,CAAC,IAAI,EAAE,CAAC;IACnC,CAAC;CACJ"} \ No newline at end of file diff --git a/lib-js/twrmodasync.d.ts b/lib-js/twrmodasync.d.ts index 0a3b6b1f..6dc13836 100644 --- a/lib-js/twrmodasync.d.ts +++ b/lib-js/twrmodasync.d.ts @@ -11,14 +11,14 @@ export declare class twrWasmModuleAsync extends twrWasmModuleInJSMain { malloc: (size: number) => Promise; loadWasmResolve?: (value: void) => void; loadWasmReject?: (reason?: any) => void; - executeCResolve?: (value: unknown) => void; - executeCReject?: (reason?: any) => void; + callCResolve?: (value: unknown) => void; + callCReject?: (reason?: any) => void; initLW: boolean; waitingcalls?: twrWaitingCalls; constructor(opts?: IModOpts); loadWasm(pathToLoad: string): Promise; - executeC(params: [string, ...(string | number | Uint8Array)[]]): Promise; - executeCImpl(fname: string, cparams?: number[]): Promise; + callC(params: [string, ...(string | number | Uint8Array)[]]): Promise; + callCImpl(fname: string, cparams?: number[]): Promise; keyDownDiv(ev: KeyboardEvent): void; keyDownCanvas(ev: KeyboardEvent): void; processMsg(event: MessageEvent): void; diff --git a/lib-js/twrmodasync.d.ts.map b/lib-js/twrmodasync.d.ts.map index 67898b36..0f3eebce 100644 --- a/lib-js/twrmodasync.d.ts.map +++ b/lib-js/twrmodasync.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"twrmodasync.d.ts","sourceRoot":"","sources":["../source/twr-wasm-ts/twrmodasync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,UAAU,EAAE,kBAAkB,EAAC,MAAM,iBAAiB,CAAC;AAEzE,OAAO,EAAC,qBAAqB,EAAC,MAAM,mBAAmB,CAAA;AACvD,OAAO,EAAC,eAAe,EAAC,MAAM,sBAAsB,CAAA;AAKpD,MAAM,MAAM,mBAAmB,GAAG;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,kBAAkB,CAAC;IACpC,SAAS,EAAE,UAAU,CAAA;CACrB,CAAC;AAEF,qBAAa,kBAAmB,SAAQ,qBAAqB;IAC5D,QAAQ,EAAC,MAAM,CAAC;IAChB,MAAM,EAAC,CAAC,IAAI,EAAC,MAAM,KAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACtC,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,KAAK,IAAI,CAAC;IACxC,cAAc,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;IACxC,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAC3C,cAAc,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;IACxC,MAAM,UAAO;IACb,YAAY,CAAC,EAAC,eAAe,CAAC;g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ACb,YAAY,CAAC,EAAC,eAAe,CAAC;gBAGlB,IAAI,CAAC,EAAC,QAAQ;IAWpB,QAAQ,CAAC,UAAU,EAAC,MAAM;IA6B1B,KAAK,CAAC,MAAM,EAAC,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAC,MAAM,GAAC,UAAU,CAAC,EAAE,CAAC;IAKtD,SAAS,CAAC,KAAK,EAAC,MAAM,EAAE,OAAO,GAAC,MAAM,EAAK;IASjD,UAAU,CAAC,EAAE,EAAC,aAAa;IAM3B,aAAa,CAAC,EAAE,EAAC,aAAa;IAK9B,UAAU,CAAC,KAAK,EAAE,YAAY;CA4E9B"} \ No newline at end of file diff --git a/lib-js/twrmodasync.js b/lib-js/twrmodasync.js index ebd6d479..e3f0863f 100644 --- a/lib-js/twrmodasync.js +++ b/lib-js/twrmodasync.js @@ -7,8 +7,8 @@ export class twrWasmModuleAsync extends twrWasmModuleInJSMain { malloc; loadWasmResolve; loadWasmReject; - executeCResolve; - executeCReject; + callCResolve; + callCReject; initLW = false; waitingcalls; constructor(opts) { @@ -28,7 +28,7 @@ export class twrWasmModuleAsync extends twrWasmModuleInJSMain { this.loadWasmResolve = resolve; this.loadWasmReject = reject; this.malloc = (size) => { - return this.executeCImpl("twr_malloc", [size]); + return this.callCImpl("twr_malloc", [size]); }; this.waitingcalls = new twrWaitingCalls(); // handle's calls that cross the worker thread - main js thread boundary let canvas; @@ -46,15 +46,15 @@ export class twrWasmModuleAsync extends twrWasmModuleInJSMain { this.myWorker.postMessage(['startup', startMsg]); }); } - async executeC(params) { + async callC(params) { const cparams = await this.preCallC(params); // will also validate params[0] - return this.executeCImpl(params[0], cparams); + return this.callCImpl(params[0], cparams); } - async executeCImpl(fname, cparams = []) { + async callCImpl(fname, cparams = []) { return new Promise((resolve, reject) => { - this.executeCResolve = resolve; - this.executeCReject = reject; - this.myWorker.postMessage(['executeC', fname, cparams]); + this.callCResolve = resolve; + this.callCReject = reject; + this.myWorker.postMessage(['callC', fname, cparams]); }); } // this function should be called from HTML "keydown" event from
@@ -116,17 +116,17 @@ export class twrWasmModuleAsync extends twrWasmModuleInJSMain { else throw new Error("twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmResolve)"); break; - case "executeCFail": - if (this.executeCReject) - this.executeCReject(d); + case "callCFail": + if (this.callCReject) + this.callCReject(d); else - throw new Error("twrWasmAsyncModule.processMsg unexpected error (undefined executeCReject)"); + throw new Error("twrWasmAsyncModule.processMsg unexpected error (undefined callCReject)"); break; - case "executeCOkay": - if (this.executeCResolve) - this.executeCResolve(d); + case "callCOkay": + if (this.callCResolve) + this.callCResolve(d); else - throw new Error("twrWasmAsyncModule.processMsg unexpected error (undefined executeCResolve)"); + throw new Error("twrWasmAsyncModule.processMsg unexpected error (undefined callCResolve)"); break; default: if (!this.waitingcalls) diff --git a/lib-js/twrmodasync.js.map b/lib-js/twrmodasync.js.map index 269cbb51..b38110b0 100644 --- a/lib-js/twrmodasync.js.map +++ b/lib-js/twrmodasync.js.map @@ -1 +1 @@ -{"version":3,"file":"twrmodasync.js","sourceRoot":"","sources":["../source/twr-wasm-ts/twrmodasync.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,eAAe,EAAC,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAC,qBAAqB,EAAC,MAAM,mBAAmB,CAAA;AACvD,OAAO,EAAC,eAAe,EAAC,MAAM,sBAAsB,CAAA;AAGpD,OAAO,OAAO,MAAM,SAAS,CAAC;AAQ9B,MAAM,OAAO,kBAAmB,SAAQ,qBAAqB;IAC5D,QAAQ,CAAQ;IAChB,MAAM,CAAgC;IACtC,eAAe,CAAyB;IACxC,cAAc,CAA0B;IACxC,eAAe,CAA4B;IAC3C,cAAc,CAA0B;IACxC,MAAM,GAAC,KAAK,CAAC;IACb,YAAY,CAAkB;IAG9B,YAAY,IAAc;QACzB,KAAK,CAAC,IAAI,CAAC,CAAC;QAEZ,IAAI,CAAC,MAAM,GAAC,CAAC,IAAW,EAAC,EAAE,GAAC,MAA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AAM,CAAC,MAAM,CAAC,CAAC;gBACjD,6CAA6C;gBAC7C,MAAM;YAEP,KAAK,aAAa;gBACjB,IAAI,IAAI,CAAC,cAAc;oBACtB,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;;oBAEvB,MAAM,IAAI,KAAK,CAAC,2EAA2E,CAAC,CAAC;gBAC9F,MAAM;YAEP,KAAK,aAAa;gBAEjB,IAAI,IAAI,CAAC,eAAe;oBACvB,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;;oBAEhC,MAAM,IAAI,KAAK,CAAC,4EAA4E,CAAC,CAAC;gBAC/F,MAAM;YAEP,KAAK,WAAW;gBACf,IAAI,IAAI,CAAC,WAAW;oBACnB,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;;oBAEpB,MAAM,IAAI,KAAK,CAAC,wEAAwE,CAAC,CAAC;gBAC3F,MAAM;YAEP,KAAK,WAAW;gBACf,IAAI,IAAI,CAAC,YAAY;oBACpB,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;;oBAErB,MAAM,IAAI,KAAK,CAAC,yEAAyE,CAAC,CAAC;gBAC5F,MAAM;YAEP;gBACC,IAAI,CAAC,IAAI,CAAC,YAAY;oBAAE,MAAM,IAAI,KAAK,CAAE,8CAA8C,CAAC,CAAA;gBACxF,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC,CAAC;oBAChD,MAAM,IAAI,KAAK,CAAC,uDAAuD,GAAC,OAAO,CAAC,CAAC;SACnF;IACF,CAAC;CACD"} \ No newline at end of file diff --git a/lib-js/twrmodbase.d.ts b/lib-js/twrmodbase.d.ts index 2695a90e..b5ddfaa7 100644 --- a/lib-js/twrmodbase.d.ts +++ b/lib-js/twrmodbase.d.ts @@ -48,8 +48,8 @@ export declare abstract class twrWasmModuleBase { /*********************************************************************/ loadWasm(pathToLoad: string): Promise; private init; - executeC(params: [string, ...(string | number | ArrayBuffer | URL)[]]): Promise; - executeCImpl(fname: string, cparams?: number[]): Promise; + callC(params: [string, ...(string | number | ArrayBuffer | URL)[]]): Promise; + callCImpl(fname: string, cparams?: number[]): Promise; preCallC(params: [string, ...(string | number | ArrayBuffer | URL)[]]): Promise; postCallC(cparams: number[], params: [string, ...(string | number | ArrayBuffer | URL)[]]): Promise; /*********************************************************************/ diff --git a/lib-js/twrmodbase.d.ts.map b/lib-js/twrmodbase.d.ts.map index e43c9a91..bbcc67e0 100644 --- a/lib-js/twrmodbase.d.ts.map +++ b/lib-js/twrmodbase.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"twrmodbase.d.ts","sourceRoot":"","sources":["../source/twr-wasm-ts/twrmodbase.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,kBAAkB,EAAC,MAAM,gBAAgB,CAAA;AACjD,OAAO,EAAC,eAAe,EAAC,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAC,wBAAwB,EAAC,MAAM,sBAAsB,CAAA;AAE7D,OAAO,EAAC,YAAY,EAAC,MAAM,eAAe,CAAC;AAG3C,MAAM,MAAM,UAAU,GAAC,KAAK,GAAC,QAAQ,GAAC,MAAM,GAAC,OAAO,CAAC;AAErD,MAAM,WAAW,QAAQ;IACxB,KAAK,CAAC,EAAC,UAAU,CAAC;IAClB,MAAM,CAAC,EAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzB,SAAS,CAAC,EAAC,MAAM,CAAC;IAClB,SAAS,CAAC,EAAC,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAC,MAAM,CAAC;IACjB,WAAW,CAAC,EAAC,OAAO,CAAC;IACrB,OAAO,CAAC,EAAC,EAAE,CAAC;CACZ;AAED,MAAM,WAAW,UAAU;IAC1B,KAAK,EAAC,UAAU,CAAC;IACjB,MAAM,EAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxB,SAAS,EAAC,MAAM,CAAC;IACjB,SAAS,EAAC,MAAM,CAAC;IACjB,QAAQ,EAA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IAa/C,QAAQ,CAAC,GAAG,EAAC,MAAM,GAAG,UAAU;IAehC,SAAS,CAAC,GAAG,EAAC,MAAM,GAAG,WAAW;CAelC"} \ No newline at end of file diff --git a/lib-js/twrmodbase.js b/lib-js/twrmodbase.js index f4d79288..397bb8c8 100644 --- a/lib-js/twrmodbase.js +++ b/lib-js/twrmodbase.js @@ -98,7 +98,7 @@ export class twrWasmModuleBase { //console.log("twrInit:",twrInit) twrInit(p, this.mem8.length); } - /* executeC takes an array where: + /* callC takes an array where: * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag) * and the next entries are a variable number of parameters to pass to the C function, of type * number - converted to int32 or float64 as appropriate @@ -106,17 +106,17 @@ export class twrWasmModuleBase { * URL - the file contents are loaded into module Memory via urlToMem(), and two C parameters are generated - index (pointer) to the memory, and length * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length */ - async executeC(params) { + async callC(params) { const cparams = await this.preCallC(params); - let retval = this.executeCImpl(params[0], cparams); + let retval = this.callCImpl(params[0], cparams); this.postCallC(cparams, params); return retval; } - async executeCImpl(fname, cparams = []) { + async callCImpl(fname, cparams = []) { if (!this.exports) throw new Error("this.exports undefined"); if (!this.exports[fname]) - throw new Error("executeC: function '" + fname + "' not in export table. Use --export wasm-ld flag."); + throw new Error("callC: function '" + fname + "' not in export table. Use --export wasm-ld flag."); const f = this.exports[fname]; let cr = f(...cparams); return cr; @@ -124,9 +124,9 @@ export class twrWasmModuleBase { // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory async preCallC(params) { if (!(params.constructor === Array)) - throw new Error("executeC: params must be array, first arg is function name"); + throw new Error("callC: params must be array, first arg is function name"); if (params.length == 0) - throw new Error("executeC: missing function name"); + throw new Error("callC: missing function name"); let cparams = []; let ci = 0; for (let i = 1; i < params.length; i++) { @@ -151,7 +151,7 @@ export class twrWasmModuleBase { break; } default: - throw new Error("executeC: invalid object type passed in"); + throw new Error("callC: invalid object type passed in"); } } return cparams; @@ -166,12 +166,12 @@ export class twrWasmModuleBase { ci++; break; case 'string': - this.executeCImpl('twr_free', [cparams[ci]]); + this.callCImpl('twr_free', [cparams[ci]]); ci++; break; case 'object': if (p instanceof URL) { - this.executeCImpl('twr_free', [cparams[ci]]); + this.callCImpl('twr_free', [cparams[ci]]); ci = ci + 2; break; } @@ -179,7 +179,7 @@ export class twrWasmModuleBase { let u8 = new Uint8Array(p); for (let j = 0; j < u8.length; j++) u8[j] = this.mem8[cparams[ci] + j]; // mod.mem8 is a Uint8Array view of the module's Web Assembly Memory - this.executeCImpl('twr_free', [cparams[ci]]); + this.callCImpl('twr_free', [cparams[ci]]); ci++; break; } diff --git a/lib-js/twrmodbase.js.map b/lib-js/twrmodbase.js.map index e784ca6d..31f8f57c 100644 --- a/lib-js/twrmodbase.js.map +++ b/lib-js/twrmodbase.js.map @@ -1 +1 @@ -{"version":3,"file":"twrmodbase.js","sourceRoot":"","sources":["../source/twr-wasm-ts/twrmodbase.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,YAAY,EAAC,MAAM,eAAe,CAAC;AAgC3C,uEAAuE;AACvE,uEAAuE;AACvE,uEAAuE;AAEvE,MAAM,OAAgB,iBAAiB;IACtC,MAAM,CAAqB;IAC3B,IAAI,CAAY;IAChB,KAAK,CAAa;IAClB,IAAI,CAAc;IAGlB,OAAO,CAAsB;IAC7B,QAAQ,GAAC,KAAK,CAAC;IACf,YAAY,CAAS,CAAE,kGAAkG;IACzH,SAAS,CAAc;IAEvB,YAAY,YAAY,GAAC,KAAK;QAC7B,IAAI,CAAC,YAAY,GAAC,YAAY,CAAC,CAAE,0DAA0D;QAC3F,IAAI,CAAC,IAAI,GAAC,IAAI,UAAU,EAAE,CAAC,CAAG,oBAAoB;QAClD,IAAI,CAAC,KAAK,GAAC,IAAI,WAAW,EAAE,CAAC,CAAE,oBAAoB;QACnD,IAAI,CAAC,IAAI,GAAC,IAAI,YAAY,EAAE,CAAC,CAAE,oBAAoB;Q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,CAAC,mDAAmD,CAAC,CAAC;QAEpF,MAAM,GAAG,GAAG,IAAI,WAAW,CAAE,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,GAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAE,CAAC;QAC/E,OAAO,GAAG,CAAC;IACZ,CAAC;CACD"} \ No newline at end of file diff --git a/lib-js/twrmodworker.js b/lib-js/twrmodworker.js index fe0fa755..cf2b5cd9 100644 --- a/lib-js/twrmodworker.js +++ b/lib-js/twrmodworker.js @@ -18,13 +18,13 @@ onmessage = function (e) { postMessage(["startupFail", ex]); }); } - else if (e.data[0] == 'executeC') { - mod.executeCImpl(e.data[1], e.data[2]).then((rc) => { - postMessage(["executeCOkay", rc]); + else if (e.data[0] == 'callC') { + mod.callCImpl(e.data[1], e.data[2]).then((rc) => { + postMessage(["callCOkay", rc]); }).catch(e => { - console.log("exception in executeC twrworker.js\n"); + console.log("exception in callC twrworker.js\n"); console.log(e); - postMessage(["executeCFail", e]); + postMessage(["callCFail", e]); }); } else { diff --git a/lib-js/twrmodworker.js.map b/lib-js/twrmodworker.js.map index 5740ffd0..efc80385 100644 --- a/lib-js/twrmodworker.js.map +++ b/lib-js/twrmodworker.js.map @@ -1 +1 @@ -{"version":3,"file":"twrmodworker.js","sourceRoot":"","sources":["../source/twr-wasm-ts/twrmodworker.ts"],"names":[],"mappings":"AAAA,sEAAsE;AAEtE,OAAO,EAAC,cAAc,EAAC,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAC,WAAW,EAAC,MAAM,aAAa,CAAC;AACxC,OAAO,EAAC,gBAAgB,EAAC,MAAM,eAAe,CAAC;AAE/C,OAAO,EAAC,iBAAiB,EAAiC,MAAM,iBAAiB,CAAA;AACjF,OAAO,EAAC,oBAAoB,EAAC,MAAM,sBAAsB,CAAC;AAE1D,IAAI,GAAyB,CAAC;AAE9B,SAAS,GAAG,UAAS,CAAC;IAClB,0EAA0E;IAE1E,IAAI,CA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AAS,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;SAE7C,CAAA;IACN,CAAC;CACH"} \ No newline at end of file diff --git a/notes-to-self.txt b/notes-to-self.txt index ef0fd84f..b316f1b9 100644 --- a/notes-to-self.txt +++ b/notes-to-self.txt @@ -1,12 +1,10 @@ for 1.0? -struct IoConsole* twr_wasm_get_windowcon(); should this be renamed - create? -change twrWasmModule to not use 'await' on executeC, malloc, etc calls? +change twrWasmModule to not use 'await' on callC, malloc, etc calls? d2d - set default font as current font D2D ImageData should probably not use mem address as index? Address could get reused. get source maps working reliably in bundled builds add source to module, also perhaps this is needed for above in the npm package add source? -rename executeC? ---- add buffer size to io_gets() @@ -52,7 +50,7 @@ malloc is slow check out malloc and other crt at https://github.com/rebol/rebol a form like this can be used to improve GetVALUE() functions in wasmModule: const z = new Uint8ClampedArray(buffer, 1, 4); ? need to improve implementation of getU8Arr/32 -executeC calls are slow (i did a performance test, and way way slower then the import calls) +callC calls are slow (i did a performance test, and way way slower then the import calls) if (twr_strcmp(buffer, "0.100000")!=0) return 0; // see unittests.c comment add overload: fillText(text, x, y, maxWidth) add D2D for textAlign (set) diff --git a/readme.md b/readme.md index 61d1d314..eb88985c 100644 --- a/readme.md +++ b/readme.md @@ -35,7 +35,7 @@ index.html: const mod = new twrWasmModule(); await mod.loadWasm("./helloworld.wasm"); - await mod.executeC(["hello"]); + await mod.callC(["hello"]); @@ -61,7 +61,7 @@ index.html: - [TypeScript-JavaScript API Overview](#typescript-javascript-api-overview) - [twrWasmModule and twrWasmModuleAsync](#twrwasmmodule-and-twrwasmmoduleasync) - [loadWasm](#loadwasm) - - [executeC](#executec) + - [callC](#callc) - [Key input](#key-input) - [Options](#options) - [divLog](#divlog) @@ -181,7 +181,7 @@ With an index.html like the following. This time we are using twrWasmModuleAsyn document.getElementById("twr_iodiv").addEventListener("keydown",(ev)=>{amod.keyDownDiv(ev)}); await amod.loadWasm("./stdio-div.wasm"); - await amod.executeC(["stdio_div"]); + await amod.callC(["stdio_div"]); } catch(ex) { amod.divLog("unexpected exception"); @@ -259,7 +259,7 @@ export async function fftDemo() { // kiss_fft_alloc() returns a malloced structure. Pointers are numbers (index into wasm module memory) in JS land // //kiss_fft_cfg cfg = kiss_fft_alloc( nfft ,is_inverse_fft ,0,0 ); - let cfg:number = await mod.executeC(["kiss_fft_alloc", fft.nfft, 0, 0, 0 ]); + let cfg:number = await mod.callC(["kiss_fft_alloc", fft.nfft, 0, 0, 0 ]); // The FFT input and output data are C arrays of complex numbers. // typedef struct { @@ -273,18 +273,18 @@ export async function fftDemo() { // So if the FFT data has 1024 bins, then 1024 * 2 floats (r & i) * 4 bytes per float are needed. // I use a JS Float32Array view on the ArrayBuffer to access the floats - // When an arrayBuffer is passed in as an argument to mod.executeC, - // executeC will malloc memory in the wasm module of a size that matches the array buffer, then + // When an arrayBuffer is passed in as an argument to mod.callC, + // callC will malloc memory in the wasm module of a size that matches the array buffer, then // copy the arraybuffer into the malloc'd memory prior to the function call, // then copy the malloc'd memory contents back into the arrayBuffer post call. // The malloc'd memory is free'd post call. // void kiss_fft(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout); - await mod.executeC(["kiss_fft", cfg, fft.inArrayBuf, fft.outArrayBuf]); + await mod.callC(["kiss_fft", cfg, fft.inArrayBuf, fft.outArrayBuf]); fft.graphOut("c-output"); - await mod.executeC(["twr_free", cfg]); // not much point to this since all the module memory is about to disappear + await mod.callC(["twr_free", cfg]); // not much point to this since all the module memory is about to disappear } ~~~ @@ -373,10 +373,10 @@ void show_str_centered(struct IoConsoleWindow* iow, int h, const char* str) { document.getElementById("twr_iocanvas").addEventListener("keydown",(ev)=>{amod.keyDownCanvas(ev)}); amod.loadWasm("./stdio-canvas.wasm").then( ()=>{ - amod.executeC(["stdio_canvas"]).then( (r) => { - console.log("executeC returned: "+r); + amod.callC(["stdio_canvas"]).then( (r) => { + console.log("callC returned: "+r); }).catch(ex=>{ - console.log("exception in HTML script loadWasm() or executeC()\n"); + console.log("exception in HTML script loadWasm() or callC()\n"); throw ex; }); }); @@ -426,11 +426,11 @@ export async function mazeRunner() { await amod.loadWasm('maze.wasm'); //void CalcMaze(HWND hWnd, LONG cell_size, LONG is_black_bg, LONG isd - slow draw) - await amod.executeC(["CalcMaze", 0, 7, 0, 1]); - await amod.executeC(["SolveBegin"]); + await amod.callC(["CalcMaze", 0, 7, 0, 1]); + await amod.callC(["SolveBegin"]); let timer = setInterval(async ()=>{ - let isdone=await amod.executeC(["SolveStep", 0]); //SolveStep(hwnd)) + let isdone=await amod.callC(["SolveStep", 0]); //SolveStep(hwnd)) if (isdone) clearInterval(timer); }, 50); } @@ -454,7 +454,7 @@ Here are the general steps to integrate your C with Javascript: 2. On the JavaScript side you: 1. access tiny-wasm-runtime "ES" modules in the normal way with "import". 2. add a \ named 'twr_iodiv' to your HTML (there are other options, this is the simplest) - 3. use "new twrWasmModule()", followed by loadWasm(), then executeC(). + 3. use "new twrWasmModule()", followed by loadWasm(), then callC(). 4. Alternately, use twrWasmModuleAsync() -- it is interchangeable with twrWasmModule, but proxies through a worker thread, and adds blocking support, including blocking char input ## Compiler and Linker Options @@ -535,7 +535,7 @@ You can print your module memory map, heap stats, and stack size using the funct ~~~ You can also call it from JavaScript like this: ~~~ -twrWasmModule/Async.executeC(["twr_wasm_print_mem_debug_stats"]) +twrWasmModule/Async.callC(["twr_wasm_print_mem_debug_stats"]) ~~~ twrWasmModule and twrWasmModuleAsync expose malloc as an async function, as well as the Web Assembly Module memory as: @@ -549,7 +549,7 @@ memD:Float64Array; ~~~ to call free() from JavaScript (you probably won't need to), you can use: ~~~ -twrWasmModule/Async.executeC("twr_free", index); // index to memory to free, as returned by malloc +twrWasmModule/Async.callC("twr_free", index); // index to memory to free, as returned by malloc ~~~ ## Debugging your C code @@ -585,7 +585,7 @@ These two classes implement compatible APIs. Use twrWasmModuleAsync if your C c Use either twrWasmModule or twrWasmModuleAsync to: - 'loadWasm()' to load your .wasm module (your compiled C code). - - 'executeC()' to call a C function + - 'callC()' to call a C function You must use **twrWasmModuleAsync** in order to: - call any blocking C function (meaning it takes "a long time") to return @@ -610,10 +610,10 @@ or await amod.loadWasm("./mycode.wasm") ~~~ -## executeC +## callC You call functions in your C/C++ from TypeScript/JavaScript like this: ~~~ -let result=await amod.executeC(["bounce_balls_move", param1]) +let result=await amod.callC(["bounce_balls_move", param1]) ~~~ If you are calling into C++, you need to use extern "C" like this in your C++ code: @@ -633,7 +633,7 @@ void bounce_balls_move() { See the example makefiles for a more complete list of clang and wasm-ld options needed. -executeC takes an array where: +callC takes an array where: - the first entry is the name of the C function in the wasm module to call - and the next entries are a variable number of parameters to pass to the C function, of type: - number - will be converted to int32 or float64 as appropriate @@ -641,10 +641,12 @@ executeC takes an array where: - ArrayBuffer - the array is loaded into module memory. If you need to pass the length, pass it as a separate parameter. Andy modifications to the memory made by your C code will be refelected back into the JavaScript ArrayBuffer. - URL - the url contents are loaded into module Memory, and two C parameters are generated - index (pointer) to the memory, and length -executeC returns the value returned by the C function that was called. As well int and float, strings and structs (or blocks of memory) can be returned. More details can be found in examples/function-calls. +callC returns the value returned by the C function that was called. As well int and float, strings and structs (or blocks of memory) can be returned. More details can be found in examples/function-calls. The FFT example demonstrates passing a Float32Array view of an ArrayBuffer. +Prior to 1.0, callC was named executeC. + ## Key input In order to receive keyboard input using **twrWasmModuleAsync** you should add a line like the following to your Javascript: @@ -736,14 +738,14 @@ for (let i=0; i<2000000;i++) const endA=Date.now(); -sum=await mod.executeC(["sin_test"]); +sum=await mod.callC(["sin_test"]); const endB=Date.now(); mod.divLog("sum A: ", sum, " in ms: ", endA-start); mod.divLog("sum B: ", sum, " in ms: ", endB-endA); ~~~ ## Accessing Data in the Web Assembly Memory -You probably will not need to use the twrWasmModule/Async functions in this section, as **executeC()** will convert your parameters for you. But if you return or want to pass in more complicated structs, you might need to. The source in source/twr-wasm-ts/canvas.ts is an example of how these are used. +You probably will not need to use the twrWasmModule/Async functions in this section, as **callC()** will convert your parameters for you. But if you return or want to pass in more complicated structs, you might need to. The source in source/twr-wasm-ts/canvas.ts is an example of how these are used. ~~~ async putString(sin:string) // returns index into WebAssembly.Memory async putU8(u8a:Uint8Array) // returns index into WebAssembly.Memory @@ -786,7 +788,7 @@ There are some wasm specific C APIs. These are used by the typescript APIS, an - \tiny-wasm-runtime\include\twr-wasm.h ## Passing strings, arrayBuffers, etc -The WebAssembly module provided in a browser will only pass numbers between C/C++ functions and Javascript functions. This means if you use twrWasmModule.executeC() to call a C function, and pass integers or floats as arguments, they will work as expected. But if you pass a string, arrayBuffer, or the contents or a URL, twrWasmModule/Async will: +The WebAssembly module provided in a browser will only pass numbers between C/C++ functions and Javascript functions. This means if you use twrWasmModule.callC() to call a C function, and pass integers or floats as arguments, they will work as expected. But if you pass a string, arrayBuffer, or the contents or a URL, twrWasmModule/Async will: - allocate memory in your WebAssembly.Memory (using twr_malloc) - copy the string (or arrayBuffer or URL contents) into this memory, - and pass the memory index (aka a pointer in C land) to your C code. diff --git a/source/twr-wasm-ts/twrmodasync.ts b/source/twr-wasm-ts/twrmodasync.ts index 983bb2a8..d3d87bc0 100644 --- a/source/twr-wasm-ts/twrmodasync.ts +++ b/source/twr-wasm-ts/twrmodasync.ts @@ -17,8 +17,8 @@ export class twrWasmModuleAsync extends twrWasmModuleInJSMain { malloc:(size:number)=>Promise; loadWasmResolve?: (value: void) => void; loadWasmReject?: (reason?: any) => void; - executeCResolve?: (value: unknown) => void; - executeCReject?: (reason?: any) => void; + callCResolve?: (value: unknown) => void; + callCReject?: (reason?: any) => void; initLW=false; waitingcalls?:twrWaitingCalls; @@ -43,7 +43,7 @@ export class twrWasmModuleAsync extends twrWasmModuleInJSMain { this.loadWasmReject=reject; this.malloc = (size:number) => { - return this.executeCImpl("twr_malloc", [size]) as Promise; + return this.callCImpl("twr_malloc", [size]) as Promise; } this.waitingcalls=new twrWaitingCalls(); // handle's calls that cross the worker thread - main js thread boundary @@ -63,16 +63,16 @@ export class twrWasmModuleAsync extends twrWasmModuleInJSMain { }); } - async executeC(params:[string, ...(string|number|Uint8Array)[]]) { + async callC(params:[string, ...(string|number|Uint8Array)[]]) { const cparams=await this.preCallC(params); // will also validate params[0] - return this.executeCImpl(params[0], cparams); + return this.callCImpl(params[0], cparams); } - async executeCImpl(fname:string, cparams:number[]=[]) { + async callCImpl(fname:string, cparams:number[]=[]) { return new Promise((resolve, reject)=>{ - this.executeCResolve=resolve; - this.executeCReject=reject; - this.myWorker.postMessage(['executeC', fname, cparams]); + this.callCResolve=resolve; + this.callCReject=reject; + this.myWorker.postMessage(['callC', fname, cparams]); }); } @@ -144,18 +144,18 @@ export class twrWasmModuleAsync extends twrWasmModuleInJSMain { throw new Error("twrWasmAsyncModule.processMsg unexpected error (undefined loadWasmResolve)"); break; - case "executeCFail": - if (this.executeCReject) - this.executeCReject(d); + case "callCFail": + if (this.callCReject) + this.callCReject(d); else - throw new Error("twrWasmAsyncModule.processMsg unexpected error (undefined executeCReject)"); + throw new Error("twrWasmAsyncModule.processMsg unexpected error (undefined callCReject)"); break; - case "executeCOkay": - if (this.executeCResolve) - this.executeCResolve(d); + case "callCOkay": + if (this.callCResolve) + this.callCResolve(d); else - throw new Error("twrWasmAsyncModule.processMsg unexpected error (undefined executeCResolve)"); + throw new Error("twrWasmAsyncModule.processMsg unexpected error (undefined callCResolve)"); break; default: diff --git a/source/twr-wasm-ts/twrmodbase.ts b/source/twr-wasm-ts/twrmodbase.ts index 4ddba187..f9cb78fd 100644 --- a/source/twr-wasm-ts/twrmodbase.ts +++ b/source/twr-wasm-ts/twrmodbase.ts @@ -148,7 +148,7 @@ export abstract class twrWasmModuleBase { twrInit(p, this.mem8.length); } - /* executeC takes an array where: + /* callC takes an array where: * the first entry is the name of the C function in the wasm module to call (must be exported, typically via the --export clang flag) * and the next entries are a variable number of parameters to pass to the C function, of type * number - converted to int32 or float64 as appropriate @@ -157,16 +157,16 @@ export abstract class twrWasmModuleBase { * Uint8Array - the array is loaded into module memory via uint8ArrayToMem(), and two parameters are generated - index (pointer) to the memory, and length */ - async executeC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) { + async callC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) { const cparams=await this.preCallC(params); - let retval = this.executeCImpl(params[0], cparams); + let retval = this.callCImpl(params[0], cparams); this.postCallC(cparams, params); return retval; } - async executeCImpl(fname:string, cparams:number[]=[]) { + async callCImpl(fname:string, cparams:number[]=[]) { if (!this.exports) throw new Error("this.exports undefined"); - if (!this.exports[fname]) throw new Error("executeC: function '"+fname+"' not in export table. Use --export wasm-ld flag."); + if (!this.exports[fname]) throw new Error("callC: function '"+fname+"' not in export table. Use --export wasm-ld flag."); const f = this.exports[fname] as CallableFunction; let cr=f(...cparams); @@ -177,8 +177,8 @@ export abstract class twrWasmModuleBase { // convert an array of parameters to numbers by stuffing contents into malloc'd wasm memory async preCallC(params:[string, ...(string|number|ArrayBuffer|URL)[]]) { - if (!(params.constructor === Array)) throw new Error ("executeC: params must be array, first arg is function name"); - if (params.length==0) throw new Error("executeC: missing function name"); + if (!(params.constructor === Array)) throw new Error ("callC: params must be array, first arg is function name"); + if (params.length==0) throw new Error("callC: missing function name"); let cparams:number[]=[]; let ci=0; @@ -204,7 +204,7 @@ export abstract class twrWasmModuleBase { break; } default: - throw new Error ("executeC: invalid object type passed in"); + throw new Error ("callC: invalid object type passed in"); } } @@ -223,13 +223,13 @@ export abstract class twrWasmModuleBase { break; case 'string': - this.executeCImpl('twr_free',[cparams[ci]]) + this.callCImpl('twr_free',[cparams[ci]]) ci++; break; case 'object': if (p instanceof URL) { - this.executeCImpl('twr_free',[cparams[ci]]) + this.callCImpl('twr_free',[cparams[ci]]) ci=ci+2; break; } @@ -237,7 +237,7 @@ export abstract class twrWasmModuleBase { let u8=new Uint8Array(p); for (let j=0; j { - postMessage(["executeCOkay", rc]); + else if (e.data[0]=='callC') { + mod.callCImpl(e.data[1], e.data[2]).then( (rc)=> { + postMessage(["callCOkay", rc]); }).catch(e => { - console.log("exception in executeC twrworker.js\n"); + console.log("exception in callC twrworker.js\n"); console.log(e); - postMessage(["executeCFail", e]); + postMessage(["callCFail", e]); }); } else {