1!function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var r={exports:{}}; 2/** 3 * q5.js 4 * @version 2.9 5 * @author quinton-ashley, Tezumie, and LingDong- 6 * @license LGPL-3.0 7 * @class Q5 8 */function a(t,r,o){let $=this;$._q5=!0,$._parent=r,$._renderer=o||"q2d",$._preloadCount=0;let n,i="auto"==t;if(t??="global","auto"==t){if(!window.setup&&!window.draw)return;t="global"}$._scope=t,"global"==t&&(a._hasGlobal=$._isGlobal=!0,n=a._nodejs?e:window);let s=new Proxy($,{set:(e,t,r)=>($[t]=r,$._isGlobal&&(n[t]=r),!0)});$.canvas=$.ctx=$.drawingContext=null,$.pixels=[];let l=null;$.frameCount=0,$.deltaTime=16,$._targetFrameRate=0,$._targetFrameDuration=16.666666666666668,$._frameRate=$._fps=60,$._loop=!0,$._hooks={postCanvas:[],preRender:[],postRender:[]};let d=0;$.millis=()=>performance.now()-d,$.noCanvas=()=>{$.canvas?.remove&&$.canvas.remove(),$.canvas=0,s.ctx=s.drawingContext=0},window&&($.windowWidth=window.innerWidth,$.windowHeight=window.innerHeight,$.deviceOrientation=window.screen?.orientation?.type),$._incrementPreload=()=>s._preloadCount++,$._decrementPreload=()=>s._preloadCount--,$._draw=e=>{let t=e||performance.now();if($._lastFrameTime??=t-$._targetFrameDuration,$._didResize&&($.windowResized(),$._didResize=!1),$._loop)l=h($._draw);else if($.frameCount&&!$._redraw)return;if(l&&$.frameCount){if(t-$._lastFrameTime<$._targetFrameDuration-4)return}s.deltaTime=t-$._lastFrameTime,$._frameRate=1e3/$.deltaTime,s.frameCount++;let r=performance.now();$.resetMatrix(),$._beginRender&&$._beginRender();for(let e of a.methods.pre)e.call($);try{$.draw()}catch(e){throw!a.disableFriendlyErrors&&$._askAI&&$._askAI(e),a.errorTolerant||$.noLoop(),e}for(let e of a.methods.post)e.call($);$._render&&$._render(),$._finishRender&&$._finishRender(),s.pmouseX=$.mouseX,s.pmouseY=$.mouseY,s.moveX=s.moveY=0,$._lastFrameTime=t;let o=performance.now();$._fps=Math.round(1e3/(o-r))},$.noLoop=()=>{$._loop=!1,l=null},$.loop=()=>{$._loop=!0,null==l&&$._draw()},$.isLooping=()=>$._loop,$.redraw=(e=1)=>{$._redraw=!0;for(let t=0;t<e;t++)$._draw();$._redraw=!1},$.remove=()=>{$.noLoop(),$.canvas.remove()},$.frameRate=e=>(e&&($._targetFrameRate=e,$._targetFrameDuration=1e3/e),$._frameRate),$.getTargetFrameRate=()=>$._targetFrameRate||60,$.getFPS=()=>$._fps,$.Element=function(e){this.elt=e},$._elements=[],$.TWO_PI=$.TAU=2*Math.PI,$.log=$.print=console.log,$.describe=()=>{};for(let e in a.modules)a.modules[e]($,s);let c=a.renderers[$._renderer];for(let e in c)c[e]($,s);for(let e in a)"_"!=e[1]&&e[1]==e[1].toUpperCase()&&($[e]=a[e]);if("graphics"==t)return;"global"==t&&(Object.assign(a,$),delete a.Q5);for(let e of a.methods.init)e.call($);for(let[e,t]of Object.entries(a.prototype))"_"!=e[0]&&"function"==typeof $[e]&&($[e]=t.bind($));if("global"==t){let e=Object.getOwnPropertyNames($);for(let t of e)"_"!=t[0]&&(n[t]=$[t])}"function"==typeof t&&t($),a._instanceCount++;let h=window.requestAnimationFrame||function(e){const t=$._lastFrameTime+$._targetFrameDuration;return setTimeout((()=>{e(t)}),t-performance.now())},u=n||$;$._isTouchAware=u.touchStarted||u.touchMoved||u.mouseReleased,$._isGlobal&&($.preload=u.preload,$.setup=u.setup,$.draw=u.draw),$.preload??=()=>{},$.setup??=()=>{},$.draw??=()=>{};let p=["mouseMoved","mousePressed","mouseReleased","mouseDragged","mouseClicked","keyPressed","keyReleased","keyTyped","touchStarted","touchMoved","touchEnded","windowResized"];for(let e of p)u[e]?$._isGlobal&&($[e]=()=>{try{return u[e]()}catch(e){throw $._askAI&&$._askAI(e),e}}):$[e]=()=>{};async function f(){if($._startDone=!0,$._preloadCount>0)return h(f);d=performance.now(),await $.setup(),$._setupDone=!0,$.frameCount||(null===$.ctx&&$.createCanvas(200,200),$.ctx&&$.resetMatrix(),h($._draw))}function _(){try{$.preload(),$._startDone||f()}catch(e){throw $._askAI&&$._askAI(e),e}}i?_():setTimeout(_,32)}a.renderers={},a.modules={},a._nodejs="object"==typeof process,a._instanceCount=0,a._friendlyError=(e,t)=>
8{a.disableFriendlyErrors||console.error(t+": "+e)},a._validateParameters=()=>!0,a.methods={init:[],pre:[],post:[],remove:[]},a.prototype.registerMethod=(e,t)=>a.methods[e].push(t),a.prototype.registerPreloadMethod=(e,t)=>a.prototype[e]=t[e],a._nodejs?e.p5??=e.Q5=a:"object"==typeof window?window.p5??=window.Q5=a:e.window=0,"object"==typeof document&&document.addEventListener("DOMContentLoaded",(()=>{a._hasGlobal||new a("auto")})),a.modules.canvas=($,e)=>{$.CENTER="center",$.LEFT="left",$.RIGHT="right",$.TOP="top",$.BOTTOM="bottom",$.BASELINE="alphabetic",$.NORMAL="normal",$.ITALIC="italic",$.BOLD="bold",$.BOLDITALIC="italic bold",$.ROUND="round",$.SQUARE="butt",$.PROJECT="square",$.MITER="miter",$.BEVEL="bevel",$.CHORD=0,$.PIE=1,$.OPEN=2,$.RADIUS="radius",$.CORNER="corner",$.CORNERS="corners",$.CLOSE=1,$.LANDSCAPE="landscape",$.PORTRAIT="portrait",$.BLEND="source-over",$.REMOVE="destination-out",$.ADD="lighter",$.DARKEST="darken",$.LIGHTEST="lighten",$.DIFFERENCE="difference",$.SUBTRACT="subtract",$.EXCLUSION="exclusion",$.MULTIPLY="multiply",$.SCREEN="screen",$.REPLACE="copy",$.OVERLAY="overlay",$.HARD_LIGHT="hard-light",$.SOFT_LIGHT="soft-light",$.DODGE="color-dodge",$.BURN="color-burn",$.P2D="2d",$.WEBGL="webgl",$._OffscreenCanvas=window.OffscreenCanvas||function(){return document.createElement("canvas")},a._nodejs?a._createNodeJSCanvas&&(e.canvas=a._createNodeJSCanvas(100,100)):"image"!=$._scope&&"graphics"!=$._scope||(e.canvas=new $._OffscreenCanvas(100,100)),$.canvas||("object"==typeof document?(e.canvas=document.createElement("canvas"),$.canvas.id="q5Canvas"+a._instanceCount,$.canvas.classList.add("q5Canvas")):$.noCanvas());let t=$.canvas;if(t.width=$.width=100,t.height=$.height=100,$._pixelDensity=1,$.displayDensity=()=>window.devicePixelRatio||1,"image"!=$._scope&&(t.renderer=$._renderer,t[$._renderer]=!0,$._pixelDensity=Math.ceil($.displayDensity())),$._adjustDisplay=()=>{t.style&&(t.style.width=t.w+"px",t.style.height=t.h+"px")},$.createCanvas=function(e,r,o){o??=arguments[3];let n=Object.assign({},a.canvasOptions);if("object"==typeof o&&Object.assign(n,o),"image"!=$._scope)if("graphics"==$._scope)$._pixelDensity=this._pixelDensity;else if(window.IntersectionObserver){let e=!1;new IntersectionObserver((r=>{t.visible=r[0].isIntersecting,e||($._wasLooping=$._loop,e=!0),t.visible?$._wasLooping&&!$._loop&&$.loop():($._wasLooping=$._loop,$.noLoop())})).observe(t)}$._setCanvasSize(e,r),Object.assign(t,n);let i=$._createCanvas(t.w,t.h,n);if($._hooks)for(let e of $._hooks.postCanvas)e();return i},$.createGraphics=function(e,t,r){let o=new a("graphics");return r??={},r.alpha??=!0,r.colorSpace??=$.canvas.colorSpace,o.createCanvas.call($,e,t,r),o.defaultWidth=e*$._defaultImageScale,o.defaultHeight=t*$._defaultImageScale,o},$._save=async(e,t,r)=>{if(t=t||"untitled","jpg"==(r=r||"png")||"png"==r||"webp"==r)if(e instanceof OffscreenCanvas){const t=await e.convertToBlob({type:"image/"+r});e=await new Promise((e=>{const r=new FileReader;r.onloadend=()=>e(r.result),r.readAsDataURL(t)}))}else e=e.toDataURL("image/"+r);else{let t="text/plain";"json"==r&&("string"!=typeof e&&(e=JSON.stringify(e)),t="text/json"),e=new Blob([e],{type:t}),e=URL.createObjectURL(e)}let a=document.createElement("a");a.href=e,a.download=t+"."+r,a.click(),URL.revokeObjectURL(a.href)},$.save=(e,t,r)=>{if((!e||"string"==typeof e&&(!t||!r&&t.length<5))&&(r=t,t=e,e=$.canvas),r)return $._save(e,t,r);t?(t=t.split("."),$._save(e,t[0],t.at(-1))):$._save(e)},$._setCanvasSize=(r,a)=>{r??=window.innerWidth,a??=window.innerHeight,t.w=r=Math.ceil(r),t.h=a=Math.ceil(a),t.hw=r/2,t.hh=a/2,t.width=Math.ceil(r*$._pixelDensity),t.height=Math.ceil(a*$._pixelDensity),$._da?$.flexibleCanvas($._dau):(e.width=r,e.height=a),$.displayMode&&!t.displayMode?$.displayMode():$._adjustDisplay()},$._setImageSize=(r,a)=>{e.width=t.w=r,e.height=t.h=a,t.hw=r/2,t.hh=a/2,t.width=Math.ceil(r*$._pixelDensity),t.height=Math.ceil(a*$._pixelDensity)},"image"!=$._scope){if(t&&"graphics"!=$._scope){function r(){let e=$._parent;e??=document.getElementsByTagName("main")[0],e||(e=document.createElement("main"),document.body.append(e)),t.parent(e)}t.parent=e=>{function r(){$.frameCount>1&&($._didResize=!0,$._adjustDisplay())}t.parentElement&&t.parentElement.removeChild(t),"string"==typeof e&&(e=document.getElementById(e)),e.append(t),"function"==typeof ResizeObserver?($._ro&&$._ro.disconnect(),$._ro=new ResizeObserver(r),$._ro.observe(e)):$.frameCount||window.addEventListener("resize",r)},document.body?r():document.addEventListener("DOMContentLoaded",r)}$.resizeCanvas=(e,r)=>{if(!$.ctx)return $.createCanvas(e,r);e==t.w&&r==t.h||$._resizeCanvas(e,r)},$.canvas.resize=$.resizeCanvas,$.canvas.save=$.saveCanvas=$.save,$.pixelDensity=e=>e&&e!=$._pixelDensity?($._pixelDensity=e,$._setCanvasSize(t.w,t.h),e):$._pixelDensity,$.defaultImageScale=e=>e?$._defaultImageScale=e:$._defaultImageScale,$.defaultImageScale(.5),$.flexibleCanvas=(r=400)=>{r?($._da=t.width/(r*$._pixelDensity),e.width=$._dau=r,e.height=t.h/t.w*r):$._da=0},$._styleNames=["_doStroke","_doFill","_strokeSet","_fillSet","_tint","_imageMode","_rectMode","_ellipseMode","_textSize","_textAlign","_textBaseline"],$._styles=[],$.pushStyles=()=>{let e={};for(let t of $._styleNames)e[t]=$[t];$._styles.push(e)},$.popStyles=()=>{let e=$._styles.pop();for(let t of $._styleNames)$[t]=e[t]},window&&"graphics"!=$._scope&&window.addEventListener("resize",(()=>{$._didResize=!0,e.windowWidth=window.innerWidth,e.windowHeight=window.innerHeight,e.deviceOrientation=window.screen?.orientation?.type}))}},a.canvasOptions={alpha:!1,colorSpace:"display-p3"},window.matchMedia&&matchMedia("(dynamic-range: high) and (color-gamut: p3)").matches?a.supportsHDR=!0:a.canvasOptions.colorSpace
8="srgb",a.renderers.q2d={},a.renderers.q2d.canvas=($,e)=>{let t=$.canvas;$.colorMode&&$.colorMode("rgb","integer"),$._createCanvas=function(r,a,o){return e.ctx=e.drawingContext=t.getContext("2d",o),"image"!=$._scope&&($.ctx.fillStyle="white",$.ctx.strokeStyle="black",$.ctx.lineCap="round",$.ctx.lineJoin="miter",$.ctx.textAlign="left"),$.ctx.scale($._pixelDensity,$._pixelDensity),$.ctx.save(),t},$.clear=()=>{$.ctx.save(),$.ctx.resetTransform(),$.ctx.clearRect(0,0,$.canvas.width,$.canvas.height),$.ctx.restore()},"image"!=$._scope&&($._resizeCanvas=(e,r)=>{let a,o={};for(let e in $.ctx)"function"!=typeof $.ctx[e]&&(o[e]=$.ctx[e]);if(delete o.canvas,$.frameCount>1){a=new $._OffscreenCanvas(t.width,t.height),a.w=t.w,a.h=t.h,a.getContext("2d").drawImage(t,0,0)}$._setCanvasSize(e,r);for(let e in o)$.ctx[e]=o[e];$.scale($._pixelDensity),a&&$.ctx.drawImage(a,0,0,a.w,a.h)},$.fill=function(e){if($._doFill=$._fillSet=!0,a.Color&&(e._q5Color||("string"!=typeof e?e=$.color(...arguments):$._namedColors[e]&&(e=$.color(...$._namedColors[e]))),e.a<=0))return $._doFill=!1;$.ctx.fillStyle=$._fill=e.toString()},$.noFill=()=>$._doFill=!1,$.stroke=function(e){if($._doStroke=$._strokeSet=!0,a.Color&&(e._q5Color||("string"!=typeof e?e=$.color(...arguments):$._namedColors[e]&&(e=$.color(...$._namedColors[e]))),e.a<=0))return $._doStroke=!1;$.ctx.strokeStyle=$._stroke=e.toString()},$.strokeWeight=e=>{e||($._doStroke=!1),$._da&&(e*=$._da),$.ctx.lineWidth=$._strokeWeight=e||1e-4},$.noStroke=()=>$._doStroke=!1,$.opacity=e=>$.ctx.globalAlpha=e,$.translate=(e,t)=>
8{$._da&&(e*=$._da,t*=$._da),$.ctx.translate(e,t)},$.rotate=e=>{$._angleMode&&(e=$.radians(e)),$.ctx.rotate(e)},$.scale=(e,t)=>{e.x&&(t=e.y,e=e.x),t??=e,$.ctx.scale(e,t)},$.applyMatrix=(e,t,r,a,o,n)=>$.ctx.transform(e,t,r,a,o,n),$.shearX=e=>$.ctx.transform(1,0,$.tan(e),1,0,0),$.shearY=e=>$.ctx.transform(1,$.tan(e),0,1,0,0),$.resetMatrix=()=>{$.ctx&&($.ctx.resetTransform(),$.scale($._pixelDensity))},$.pushMatrix=()=>$.ctx.save(),$.popMatrix=()=>$.ctx.restore(),$.push=()=>{$.ctx.save(),$.pushStyles()},$.pop=()=>{$.ctx.restore(),$.popStyles()},$.createCapture=e=>{var t=document.createElement("video");return t.playsinline="playsinline",t.autoplay="autoplay",navigator.mediaDevices.getUserMedia(e).then((e=>{t.srcObject=e})),t.style.position="absolute",t.style.opacity=1e-5,t.style.zIndex=-1e3,document.body.append(t),t})},a.renderers.q2d.drawing=$=>{$._doStroke=!0,$._doFill=!0,$._strokeSet=!1,$._fillSet=!1,$._ellipseMode=$.CENTER,$._rectMode=$.CORNER,$._curveDetail=20,$._curveAlpha=0;let e=!0,t=[];function r(){$._doFill&&$.ctx.fill(),$._doStroke&&$.ctx.stroke()}function o(e,t,a,o,n,i,s,l){if(!$._doFill&&!$._doStroke)return;let d=$._angleMode,c=d?360:$.TAU;if((n%=c)<0&&(n+=c),(i%=c)<0&&(i+=c),0!=n||0!=i){if(n>i&&([n,i]=[i,n]),$.ctx.beginPath(),a==o)d&&(n=$.radians(n),i=$.radians(i)),$.ctx.arc(e,t,a/2,n,i);else{for(let r=0;r<l+1;r++){let s=r/l,d=$.lerp(n,i,s),c=$.cos(d)*a/2,h=$.sin(d)*o/2;$.ctx[r?"lineTo":"moveTo"](e+c,t+h)}s==$.CHORD?$.ctx.closePath():s==$.PIE&&($.ctx.lineTo(e,t),$.ctx.closePath())}r()}}function n(e,t,a,o){($._doFill||$._doStroke)&&($._da&&(e*=$._da,t*=$._da,a*=$._da,o*=$._da),$.ctx.beginPath(),$.ctx.ellipse(e,t,a/2,o/2,0,0,$.TAU),r())}function i(e,t,a,o,n,s,l,d){if($._doFill||$._doStroke){if(void 0===n)return function(e,t,a,o){$._da&&(e*=$._da,t*=$._da,a*=$._da,o*=$._da),$.ctx.beginPath(),$.ctx.rect(e,t,a,o),r()}(e,t,a,o);if(void 0===s)return i(e,t,a,o,n,n,n,n);$._da&&(e*=$._da,t*=$._da,a*=$._da,o*=$._da,n*=$._da,s*=$._da,d*=$._da,l*=$._da),$.ctx.roundRect(e,t,a,o,[n,s,l,d]),r()}}$.blendMode=e=>$.ctx.globalCompositeOperation=e,$.strokeCap=e=>$.ctx.lineCap=e,$.strokeJoin=e=>$.ctx.lineJoin=e,$.ellipseMode=e=>$._ellipseMode=e,$.rectMode=e=>$._rectMode=e,$.curveDetail=e=>$._curveDetail=e,$.curveAlpha=e=>$._curveAlpha=e,$.curveTightness=e=>$._curveAlpha=e,$.background=function(e){$.ctx.save(),$.ctx.resetTransform(),$.ctx.globalAlpha=1,e.canvas?$.image(e,0,0,$.canvas.width,$.canvas.height):(a.Color&&!e._q5Color&&("string"!=typeof e?e=$.color(...arguments):$._namedColors[e]&&(e=$.color(...$._namedColors[e]))),$.ctx.fillStyle=e.toString(),$.ctx.fillRect(0,0,$.canvas.width,$.canvas.height)),$.ctx.restore()},$.line=(e,t,r,a)=>{$._doStroke&&($._da&&(e*=$._da,t*=$._da,r*=$._da,a*=$._da),$.ctx.beginPath(),$.ctx.moveTo(e,t),$.ctx.lineTo(r,a),$.ctx.stroke())},$.arc=(e,t,r,a,n,i,s,l=25)=>{if(n==i)return $.ellipse(e,t,r,a);s??=$.PIE,$._ellipseMode==$.CENTER?o(e,t,r,a,n,i,s,l):$._ellipseMode==$.RADIUS?o(e,t,2*r,2*a,n,i,s,l):$._ellipseMode==$.CORNER?o(e+r/2,t+a/2,r,a,n,i,s,l):$._ellipseMode==$.CORNERS&&o((e+r)/2,(t+a)/2,r-e,a-t,n,i,s,l)},$.ellipse=(e,t,r,a)=>{a??=r,$._ellipseMode==$.CENTER?n(e,t,r,a):$._ellipseMode==$.RADIUS?n(e,t,2*r,2*a):$._ellipseMode==$.CORNER?n(e+r/2,t+a/2,r,a):$._ellipseMode==$.CORNERS&&n((e+r)/2,(t+a)/2,r-e,a-t)}
8,$.circle=(e,t,a)=>{$._ellipseMode==$.CENTER?($._da&&(e*=$._da,t*=$._da,a*=$._da),$.ctx.beginPath(),$.ctx.arc(e,t,a/2,0,$.TAU),r()):$.ellipse(e,t,a,a)},$.point=(e,t)=>{$._doStroke&&(e.x&&(t=e.y,e=e.x),$._da&&(e*=$._da,t*=$._da),$.ctx.beginPath(),$.ctx.moveTo(e,t),$.ctx.lineTo(e,t),$.ctx.stroke())},$.rect=(e,t,r,a=r,o,n,s,l)=>{$._rectMode==$.CENTER?i(e-r/2,t-a/2,r,a,o,n,s,l):$._rectMode==$.RADIUS?i(e-r,t-a,2*r,2*a,o,n,s,l):$._rectMode==$.CORNER?i(e,t,r,a,o,n,s,l):$._rectMode==$.CORNERS&&i(e,t,r-e,a-t,o,n,s,l)},$.square=(e,t,r,a,o,n,i)=>$.rect(e,t,r,r,a,o,n,i),$.beginShape=()=>{t=[],$.ctx.beginPath(),e=!0},$.beginContour=()=>{$.ctx.closePath(),t=[],e=!0},$.endContour=()=>{t=[],e=!0},$.vertex=(r,a)=>{$._da&&(r*=$._da,a*=$._da),t=[],e?$.ctx.moveTo(r,a):$.ctx.lineTo(r,a),e=!1},$.bezierVertex=(e,r,a,o,n,i)=>{$._da&&(e*=$._da,r*=$._da,a*=$._da,o*=$._da,n*=$._da,i*=$._da),t=[],$.ctx.bezierCurveTo(e,r,a,o,n,i)},$.quadraticVertex=(e,r,a,o)=>{$._da&&(e*=$._da,r*=$._da,a*=$._da,o*=$._da),t=[],$.ctx.quadraticCurveTo(e,r,a,o)},$.bezier=(e,t,r,a,o,n,i,s)=>{$.beginShape(),$.vertex(e,t),$.bezierVertex(r,a,o,n,i,s),$.endShape()},$.triangle=(e,t,r,a,o,n)=>{$.beginShape(),$.vertex(e,t),$.vertex(r,a),$.vertex(o,n),$.endShape($.CLOSE)},$.quad=(e,t,r,a,o,n,i,s)=>{$.beginShape(),$.vertex(e,t),$.vertex(r,a),$.vertex(o,n),$.vertex(i,s),$.endShape($.CLOSE)},$.endShape=e=>{t=[],e&&$.ctx.closePath(),r()},$.curveVertex=(r,a)=>{if($._da&&(r*=$._da,a*=$._da),t.push([r,a]),t.length<4)return;let o=function(e,t,r,a,o,n,i,s,l,d){function c(e,t,r,a,o,n){let i=Math.pow(a-t,2)+Math.pow(o-r,2);return Math.pow(i,.5*n)+e}let h=[],u=c(0,e,t,r,a,d),p=c(u,r,a,o,n,d),f=c(p,o,n,i,s,d);for(let d=0;d<l;d++){let c=u+d/(l-1)*(p-u),_=[(u-c)/(u-0),(c-0)/(u-0),(p-c)/(p-u),(c-u)/(p-u),(f-c)/(f-p),(c-p)/(f-p),(p-c)/(p-0),(c-0)/(p-0),(f-c)/(f-u),(c-u)/(f-u)];for(let e=0;e<_.length;e+=2)isNaN(_[e])&&(_[e]=1,_[e+1]=0),isFinite(_[e])||(_[e]>0?(_[e]=1,_[e+1]=0):(_[e]=0,_[e+1]=1));let g=e*_[0]+r*_[1],m=t*_[0]+a*_[1],x=r*_[2]+o*_[3],v=a*_[2]+n*_[3],y=o*_[4]+i*_[5],w=n*_[4]+s*_[5],b=g*_[6]+x*_[7],S=m*_[6]+v*_[7],C=x*_[8]+y*_[9],M=v*_[8]+w*_[9],I=b*_[2]+C*_[3],R=S*_[2]+M*_[3];h.push([I,R])}return h}(...t.at(-4),...t.at(-3),...t.at(-2),...t.at(-1),$._curveDetail,$._curveAlpha);for(let t=0;t<o.length;t++)e?$.ctx.moveTo(...o[t]):$.ctx.lineTo(...o[t]),e=!1},$.curve=(e,t,r,a,o,n,i,s)=>{$.beginShape(),$.curveVertex(e,t),$.curveVertex(r,a),$.curveVertex(o,n),$.curveVertex(i,s),$.endShape()},$.curvePoint=(e,t,r,a,o)=>{const n=o*o*o,i=o*o;return e*(-.5*n+i-.5*o)+t*(1.5*n-2.5*i+1)+r*(-1.5*n+2*i+.5*o)+a*(.5*n-.5*i)},$.bezierPoint=(e,t,r,a,o)=>{const n=1-o;return Math.pow(n,3)*e+3*Math.pow(n,2)*o*t+3*n*Math.pow(o,2)*r+Math.pow(o,3)*a},$.curveTangent=(e,t,r,a,o)=>{const n=o*o;return e*(-3*n/2+2*o-.5)+t*(9*n/2-5*o)+r*(-9*n/2+4*o+.5)+a*(3*n/2-o)},$.bezierTangent=(e,t,r,a,o)=>{const n=1-o;return 3*a*Math.pow(o,2)-3*r*Math.pow(o,2)+6*r*n*o-6*t*n*o+3*t*Math.pow(n,2)-3*e*Math.pow(n,2)},$.erase=function(e=255,t=255){$.ctx.save(),$.ctx.globalCompositeOperation="destination-out",$.ctx.fillStyle=`rgba(0, 0, 0, ${e/255})`,$.ctx.strokeStyle=`rgba(0, 0, 0, ${t/255})`},$.noErase=function(){$.ctx.globalCompositeOperation="source-over",$.ctx.restore()},$.inFill=(e,t)=>{const r=$._pixelDensity;return $.ctx.isPointInPath(e*r,t*r)},$.inStroke=(e,t)=>{const r=$._pixelDensity;return $.ctx.isPointInStroke(e*r,t*r)}},a.renderers.q2d.image=($,t)=>{a.Image??=class{constructor(e,t,r){let $=this;$._scope="image",$.canvas=$.ctx=$.drawingContext=null,$.pixels=[],a.modules.canvas($,$);let o=a.renderers.q2d;for(let e of["canvas","image","soft_filters"])o[e]&&o[e]($,$);$._pixelDensity=r.pixelDensity||1,$.createCanvas(e,t,r),delete $.createCanvas,$._loop=!1}get w(){return this.width}get h(){return this.height}},$.createImage=(e,t,r)=>{r??={},r.alpha??=!0,r.colorSpace??=$.canvas.colorSpace||a.canvasOptions.colorSpace;let o=new a.Image(e,t,r);return o.defaultWidth=e*$._defaultImageScale,o.defaultHeight=t*$._defaultImageScale,o},$.loadImage=function(r,o,n){if(r.canvas)return r;if("gif"==r.slice(-3).toLowerCase())throw new Error("q5 doesn't support GIFs due to their impact on performance. Use a video or animation instead.");t._preloadCount++;let i=[...arguments].at(-1);n="object"==typeof i?i:null;let s=$.createImage(1,1,n),l=s._pixelDensity=n?.pixelDensity||1;function d(e){s.defaultWidth=e.width*$._defaultImageScale,s.defaultHeight=e.height*$._defaultImageScale,s.naturalWi
8dth=e.naturalWidth,s.naturalHeight=e.naturalHeight,s._setImageSize(Math.ceil(s.naturalWidth/l),Math.ceil(s.naturalHeight/l)),s.ctx.drawImage(e,0,0),t._preloadCount--,o&&o(s)}if(a._nodejs&&e.CairoCanvas)e.CairoCanvas.loadImage(r).then(d).catch((e=>{throw t._preloadCount--,e}));else{let e=new window.Image;e.src=r,e.crossOrigin="Anonymous",e._pixelDensity=l,e.onload=()=>d(e),e.onerror=e=>{throw t._preloadCount--,e}}return s},$.imageMode=e=>$._imageMode=e,$.image=(e,t,r,o,n,i=0,s=0,l,d)=>{if(!e)return;let c=e?.canvas||e;a._createNodeJSCanvas&&(c=c.context.canvas),o??=e.defaultWidth||c.width||e.videoWidth,n??=e.defaultHeight||c.height||e.videoHeight,"center"==$._imageMode&&(t-=.5*o,r-=.5*n),$._da&&(t*=$._da,r*=$._da,o*=$._da,n*=$._da,i*=$._da,s*=$._da,l*=$._da,d*=$._da);let h=e._pixelDensity||1;l?l*=h:l=c.width||c.videoWidth,d?d*=h:d=c.height||c.videoHeight,$.ctx.drawImage(c,i*h,s*h,l,d,t,r,o,n),$._tint&&($.ctx.globalCompositeOperation="multiply",$.ctx.fillStyle=$._tint.toString(),$.ctx.fillRect(t,r,o,n),$.ctx.globalCompositeOperation="source-over")},$._tint=null;let r=null;$._softFilter=()=>{throw new Error("Load q5-2d-soft-filters.js to use software filters.")},$.filter=(e,t)=>{if(!$.ctx.filter)return $._softFilter(e,t);if("string"==typeof e)f=e;else if(e==a.GRAY)f="saturate(0%)";else if(e==a.INVERT)f="invert(100%)";else if(e==a.BLUR){let e=Math.ceil(t*$._pixelDensity)||1;f=`blur(${e}px)`}else{if(e!=a.THRESHOLD)return $._softFilter(e,t);{t??=.5;let e=Math.floor(.5/Math.max(t,1e-5)*100);f=`saturate(0%) brightness(${e}%) contrast(1000000%)`}}$.ctx.filter=f,$.ctx.drawImage($.canvas,0,0,$.canvas.w,$.canvas.h),$.ctx.filter="none"},"image"==$._scope&&($.resize=(e,t)=>{let r=$.canvas,a=new $._OffscreenCanvas(r.width,r.height);a.getContext("2d",{colorSpace:r.colorSpace}).drawImage(r,0,0),$._setImageSize(e,t),$.ctx.clearRect(0,0,r.width,r.height),$.ctx.drawImage(a,0,0,r.width,r.height)}),$._getImageData=(e,t,r,a)=>$.ctx.getImageData(e,t,r,a,{colorSpace:$.canvas.colorSpace}),$.trim=()=>{let e=$._pixelDensity||1,t=$.canvas.width,r=$.canvas.height,a=$._getImageData(0,0,t,r).data,o=t,n=0,i=r,s=0,l=3;for(let e=0;e<r;e++)for(let r=0;r<t;r++)0!==a[l]&&(r<o&&(o=r),r>n&&(n=r),e<i&&(i=e),e>s&&(s=e)),l+=4;return i=Math.floor(i/e),s=Math.floor(s/e),o=Math.floor(o/e),n=Math.floor(n/e),$.get(o,i,n-o+1,s-i+1)},$.mask=e=>{$.ctx.save(),$.ctx.resetTransform();let t=$.ctx.globalCompositeOperation;$.ctx.globalCompositeOperation="destination-in",$.ctx.drawImage(e.canvas,0,0),$.ctx.globalCompositeOperation=t,$.ctx.restore()},$.inset=(e,t,r,a,o,n,i,s)=>{let l=$._pixelDensity||1;$.ctx.drawImage($.canvas,e*l,t*l,r*l,a*l,o,n,i,s)},$.copy=()=>$.get(),$.get=(e,t,r,a)=>{let o=$._pixelDensity||1;if(void 0!==e&&void 0===r){let r=$._getImageData(e*o,t*o,1,1).data;return[r[0],r[1],r[2],r[3]/255]}e=(e||0)*o,t=(t||0)*o;let n=r=r||$.width,i=a=a||$.height;r*=o,a*=o;let s=$.createImage(r,a);return s.ctx.drawImage($.canvas,e,t,r,a,0,0,r,a),s._pixelDensity=o,s.width=n,s.height=i,s},$.set=(e,t,r)=>{if(r.canvas){let a=$._tint;return $._tint=null,$.image(r,e,t),void($._tint=a)}$.pixels.length||$.loadPixels();let a=$._pixelDensity||1;for(let o=0;o<a;o++)for(let n=0;n<a;n++){let i=4*((t*a+o)*$.canvas.width+e*a+n);$.pixels[i]=r.r,$.pixels[i+1]=r.g,$.pixels[i+2]=r.b,$.pixels[i+3]=r.a}},$.loadPixels=()=>{r=$._getImageData(0,0,$.canvas.width,$.canvas.height),t.pixels=r.data},$.updatePixels=()=>{null!=r&&$.ctx.putImageData(r,0,0)},$.smooth=()=>$.ctx.imageSmoothingEnabled=!0,$.noSmooth=()=>$.ctx.imageSmoothingEnabled=!1,"image"!=$._scope&&($.tint=function(e){$._tint=e._q5Color?e:$.color(...arguments)},$.noTint=()=>$._tint=null)},a.THRESHOLD=1,a.GRAY=2,a.OPAQUE=3,a.INVERT=4,a.POSTERIZE=5,a.DILATE=6,a.ERODE=7,a.BLUR=8,a.renderers.q2d.text=($,e)=>{$._textAlign="left",$._textBaseline="alphabetic",$._textSize=12;let t="sans-serif",r=!1,a=15,o=3,n="normal",i=!1,s=0,l=[],d=!1,c=!1,h=0,u=12e3,p=$._textCache={};$.loadFont=(t,r)=>{e._preloadCount++;let a=t.split("/").pop().split(".")[0].replace(" ",""),o=new FontFace(a,`url(${t})`);return document.fonts.add(o),o.load().then((()=>{e._preloadCount--,r&&r(a)})),a},$.textFont=e=>{if(!e||e==t)return t;t=e,i=!0,s=-1},$.textSize=e=>{if(null==e||e==$._textSize)return $._textSize;$._da&&(e*=$._da),$._textSize=e,i=!0,s=-1,r||(a=1.25*e,o=a-e)},$.textStyle=e=>{if(!e||e==n)return n;n=e,i=!0,s=-1},$.textLeading=e=>{if(r=!0,null==e||e==a)return a;$._da&&(e*=$._da),a=e,o=e-$._textSize,s=-1},$.textAlign=(e,t)=>{$.ctx.textAlign=$._textAlign=e,t&&($.ctx.textBaseline=$._textBaseline=t==$.CENTER?"middle":t)},$.textWidth=e=>$.ctx.measureText(e).width,$.textAscent=e=>$.ctx.measureText(e).actualBoundingBoxAscent,$.textDescent=e=>$.ctx.measureText(e).actualBoundingBoxDescent,$.textFill=$.fill,$.textStroke=$.stroke;$.textCache=(e,t)=>(t&&(u=t),void 0!==e&&(d=e),d),$.createTextImage=(e,t,r)=>(c=!0,img=$.text(e,0,0,t,r),c=!1,img);let f=[];$.text=(e,r,_,g,m)=>{if(void 0===e||!$._doFill&&!$._doStroke)return;e=e.toString(),$._da&&(r*=$._da,_*=$._da);let x,v,y,w,b=$.ctx;if(i&&(b.font=`${n} ${$._textSize}px ${t}`,i=!1),(d||c)&&(-1==s&&(()=>{let e=t+$._textSize+n+a,r=5381;for(let t=0;t<e.length;t++)r=33*r^e.charCodeAt(t);s=r>>>0}
8)(),x=p[e],x&&(x=x[s]),x)){if(x._fill==$._fill&&x._stroke==$._stroke&&x._strokeWeight==$._strokeWeight)return c?x:$.textImage(x,r,_);x.clear()}if(-1==e.indexOf("\n")?f[0]=e:f=e.split("\n"),e.length>g){let e=[];for(let t of f){let r=0;for(;r<t.length;){let a=r+g;if(a>=t.length){e.push(t.slice(r));break}let o=t.lastIndexOf(" ",a);(-1===o||o<r)&&(o=a),e.push(t.slice(r,o)),r=o+1}}f=e}if(d||c){if(v=0,y=a*f.length,!x){let t=b.measureText(" "),r=t.fontBoundingBoxAscent,n=t.fontBoundingBoxDescent;m??=y+n,x=$.createImage.call($,Math.ceil(b.measureText(e).width),Math.ceil(m),{pixelDensity:$._pixelDensity}),x._ascent=r,x._descent=n,x._top=n+o,x._middle=x._top+.5*r,x._bottom=x._top+r,x._leading=a}x._fill=$._fill,x._stroke=$._stroke,x._strokeWeight=$._strokeWeight,x.modified=!0,b=x.ctx,b.font=$.ctx.font,b.fillStyle=$._fill,b.strokeStyle=$._stroke,b.lineWidth=$.ctx.lineWidth}else v=r,y=_;$._fillSet||(w=b.fillStyle,b.fillStyle="black");for(let e of f)if($._doStroke&&$._strokeSet&&b.strokeText(e,v,y),$._doFill&&b.fillText(e,v,y),y+=a,y>m)break;if(f.length=0,$._fillSet||(b.fillStyle=w),d||c){if(l.push(s),(p[e]??={})[s]=x,h++,h>u){let e=Math.ceil(h/2),t=l.splice(0,e);for(let e in p){e=p[e];for(let r of t)delete e[r]}h-=e}if(c)return x;$.textImage(x,r,_)}},$.textImage=(e,t,r)=>{"string"==typeof e&&(e=$.createTextImage(e));let a=$._imageMode;$._imageMode="corner";let o=$._textAlign;"center"==o?t-=e.canvas.hw:"right"==o&&(t-=e.width);let n=$._textBaseline;"alphabetic"==n?r-=e._leading:"middle"==n?r-=e._middle:"bottom"==n?r-=e._bottom:"top"==n&&(r-=e._top),$.image(e,t,r),$._imageMode=a},$.nf=(e,t,r)=>{let a=e<0,o=(e=Math.abs(e)).toFixed(r).split(".");o[0]=o[0].padStart(t,"0");let n=o.join(".");return a&&(n="-"+n),n}},a.modules.ai=$=>{$.askAI=(e="")=>{throw a.disableFriendlyErrors=!1,Error("Ask AI ⨠"+e)},$._askAI=async e=>{let t=e.message?.includes("Ask AI â¨"),r=e.stack?.split("\n");if(!e.stack||r.length<=1)return;let a=1,o="(";for(-1==navigator.userAgent.indexOf("Chrome")&&(a=0,o="@");r[a].indexOf("q5")>=0;)a++;let n=r[a].split(o).at(-1);n.startsWith("blob:")&&(n=n.slice(5));let i=n.split(":"),s=parseInt(i.at(-2));t&&s++,i[3]=i[3].split(")")[0];let l=i.slice(0,2).join(":"),d=l.split("/").at(-1);try{let r=(await(await fetch(l)).text()).split("\n"),a=r[s-1].trim(),o="",n=1;for(;o.length<1600&&(s-n>=0&&(o=r[s-n].trim()+"\n"+o),s+n<r.length);)o+=r[s+n].trim()+"\n",n++;let i="https://chatgpt.com/?q=q5.js+"+(t&&e.message.length>10?e.message.slice(10):"Whats+wrong+with+this+line%3F+short+answer")+(t?"":"%0A%0A"+encodeURIComponent(e.name+": "+e.message))+"%0A%0ALine%3A+"+encodeURIComponent(a)+"%0A%0AExcerpt+for+context%3A%0A%0A"+encodeURIComponent(o);if(console.warn("Error in "+d+" on line "+s+":\n\n"+a),console.warn("Ask AI ⨠"+i),t)return window.open(i,"_blank")}catch(e){}}},a.modules.color=($,e)=>{$.RGB=$.RGBA=$._colorMode="rgb",$.OKLCH="oklch",$.colorMode=(t,r)=>{$._colorMode=t;let o="srgb"==$.canvas.colorSpace||"srgb"==t;if(r??=o?"integer":"float",$._colorFormat="float"==r||1==r?1:255,"oklch"==t)e.Color=a.ColorOKLCH;else{let t="srgb"==$.canvas.colorSpace;255==$._colorFormat?e.Color=t?a.ColorRGBA_8:a.ColorRGBA_P3_8:e.Color=t?a.ColorRGBA:a.ColorRGBA_P3,$._colorMode="rgb"}},$._namedColors={aqua:[0,255,255],black:[0,0,0],blue:[0,0,255],brown:[165,42,42],crimson:[220,20,60],cyan:[0,255,255],darkviolet:[148,0,211],gold:[255,215,0],green:[0,128,0],gray:[128,128,128],grey:[128,128,128],hotpink:[255,105,180],indigo:[75,0,130],khaki:[240,230,140],lightgreen:[144,238,144],lime:[0,255,0],magenta:[255,0,255],navy:[0,0,128],orange:[255,165,0],olive:[128,128,0],peachpuff:[255,218,185],pink:[255,192,203],purple:[128,0,128],red:[255,0,0],skyblue:[135,206,235],tan:[210,180,140],turquoise:[64,224,208],transparent:[0,0,0,0],white:[255,255,255],violet:[238,130,238],yellow:[255,255,0]},$.color=(e,t,r,a)=>{let o=$.Color;if(e._q5Color)return new o(...e.levels);if(null==t){if("string"==typeof e){if("#"==e[0])e.length<=5?(e.length>4&&(a=parseInt(e[4]+e[4],16)),r=parseInt(e[3]+e[3],16),t=parseInt(e[2]+e[2],16),e=parseInt(e[1]+e[1],16)):(e.length>7&&(a=parseInt(e.slice(7,9),16)),r=parseInt(e.slice(5,7),16),t=parseInt(e.slice(3,5),16),e=parseInt(e.slice(1,3),16));else{if(!$._namedColors[e])return console.error("q5 can't parse color: "+e+"\nOnly numeric input, hex, and common named colors are supported."),new o(0,0,0);[e,t,r,a]=$._namedColors[e]}1==$._colorFormat&&(e/=255,t&&(t/=255),r&&(r/=255),a&&(a/=255))}Array.isArray(e)&&([e,t,r,a]=e)}return null==r?new o(e,e,e,t):new o(e,t,r,a)},$.red=e=>e.r,$.green=e=>e.g,$.blue=e=>e.b,$.alpha=e=>e.a,$.lightness=e=>e.l?e.l:100*(.2126*e.r+.7152*e.g+.0722*e.b)/255,$.hue=e=>{if(e.h)return e.h;let t=e.r,r=e.g,a=e.b;255==$._colorFormat&&(t/=255,r/=255,a/=255);let o,n=Math.max(t,r,a),i=Math.min(t,r,a);return o=n==i?0:n==t?60*(r-a)/(n-i):n==r?60*(a-t)/(n-i)+120:60*(t-r)/(n-i)+240,o<0&&(o+=360),o},$.lerpColor=(e,t,r)=>
8{if("rgb"==$._colorMode)return new $.Color($.constrain($.lerp(e.r,t.r,r),0,255),$.constrain($.lerp(e.g,t.g,r),0,255),$.constrain($.lerp(e.b,t.b,r),0,255),$.constrain($.lerp(e.a,t.a,r),0,255));{let a=t.h-e.h;a>180&&(a-=360),a<-180&&(a+=360);let o=e.h+r*a;return o<0&&(o+=360),o>360&&(o-=360),new $.Color($.constrain($.lerp(e.l,t.l,r),0,100),$.constrain($.lerp(e.c,t.c,r),0,100),o,$.constrain($.lerp(e.a,t.a,r),0,255))}}},a.Color=class{constructor(){this._q5Color=!0}},a.ColorOKLCH=class extends a.Color{constructor(e,t,r,a){super(),this.l=e,this.c=t,this.h=r,this.a=a??1}toString(){return`oklch(${this.l} ${this.c} ${this.h} / ${this.a})`}},a.ColorRGBA=class extends a.Color{constructor(e,t,r,a){super(),this.r=e,this.g=t,this.b=r,this.a=a??1}get levels(){return[this.r,this.g,this.b,this.a]}toString(){return`color(srgb ${this.r} ${this.g} ${this.b} / ${this.a})`}},a.ColorRGBA_P3=class extends a.ColorRGBA{toString(){return`color(display-p3 ${this.r} ${this.g} ${this.b} / ${this.a})`}},a.ColorRGBA_8=class extends a.ColorRGBA{constructor(e,t,r,a){super(e,t,r,a??255)}setRed(e){this.r=e}setGreen(e){this.g=e}setBlue(e){this.b=e}setAlpha(e){this.a=e}get levels(){return[this.r,this.g,this.b,this.a]}toString(){return`rgb(${this.r} ${this.g} ${this.b} / ${this.a/255})`}},a.ColorRGBA_P3_8=class extends a.ColorRGBA{constructor(e,t,r,a){super(e,t,r,a??255),this._edited=!0}get r(){return this._r}set r(e){this._r=e,this._edited=!0}get g(){return this._g}set g(e){this._g=e,this._edited=!0}get b(){return this._b}set b(e){this._b=e,this._edited=!0}get a(){return this._a}set a(e){this._a=e,this._edited=!0}toString(){if(this._edited){let e=(this._r/255).toFixed(3),t=(this._g/255).toFixed(3),r=(this._b/255).toFixed(3),a=(this._a/255).toFixed(3);this._css=`color(display-p3 ${e} ${t} ${r} / ${a})`,this._edited=!1}return this._css}},a.modules.display=$=>{if(!$.canvas||"graphics"==$._scope)return;let e=$.canvas;$.CENTERED="centered",$.FULLSCREEN="fullscreen",$.MAXED="maxed",$.PIXELATED="pixelated",0!=a._instanceCount||a._nodejs||document.head.insertAdjacentHTML("beforeend","<style>\nhtml, body {\n\tmargin: 0;\n\tpadding: 0;\n}\n.q5Canvas {\n\toutline: none;\n\t-webkit-touch-callout: none;\n\t-webkit-text-size-adjust: none;\n\t-webkit-user-select: none;
8\n\toverscroll-behavior: none;\n}\n.q5-pixelated {\n\timage-rendering: pixelated;\n\tfont-smooth: never;\n\t-webkit-font-smoothing: none;\n}\n.q5-centered,\n.q5-maxed,\n.q5-fullscreen {\n display: flex;\n\talign-items: center;\n\tjustify-content: center;\n}\nmain.q5-centered,\nmain.q5-maxed,\n.q5-fullscreen {\n\theight: 100vh;\n}\nmain {\n\toverscroll-behavior: none;\n}\n</style>"),$._adjustDisplay=()=>{let t=e.style,r=e.parentElement;t&&r&&e.displayMode&&("pixelated"==e.renderQuality&&(e.classList.add("q5-pixelated"),$.pixelDensity(1),$.defaultImageScale(1),$.noSmooth&&$.noSmooth(),$.textFont&&$.textFont("monospace")),"default"==e.displayMode||"normal"==e.displayMode?(r.classList.remove("q5-centered","q5-maxed","q5-fullscreen"),t.width=e.w*e.displayScale+"px",t.height=e.h*e.displayScale+"px"):(r.classList.add("q5-"+e.displayMode),r=r.getBoundingClientRect(), 9e.w/e.h>r.width/r.height?("centered"==e.displayMode?(t.width=e.w*e.displayScale+"px",t.maxWidth="100%"):t.width="100%",t.height="auto",t.maxHeight=""):(t.width="auto",t.maxWidth="","centered"==e.displayMode?(t.height=e.h*e.displayScale+"px",t.maxHeight="100%"):t.height="100%")))},$.displayMode=(t="normal",r="smooth",a=1)=>{"string"==typeof a&&(a=parseFloat(a.slice(1))),Object.assign(e,{displayMode:t,renderQuality:r,displayScale:a}),$._adjustDisplay()},$.fullscreen=e=>{if(void 0===e)return document.fullscreenElement;e?document.body.requestFullscreen():document.body.exitFullscreen()}},a.modules.input=($,e)=>{if("graphics"==$._scope)return;$.mouseX=0,$.mouseY=0,$.pmouseX=0,$.pmouseY=0,$.touches=[],$.mouseButton="",$.keyIsPressed=!1,$.mouseIsPressed=!1,$.key="",$.keyCode=0,$.UP_ARROW=38,$.DOWN_ARROW=40,$.LEFT_ARROW=37,$.RIGHT_ARROW=39,$.SHIFT=16,$.TAB=9,$.BACKSPACE=8,$.ENTER=$.RETURN=13,$.ALT=$.OPTION=18,$.CONTROL=17,$.DELETE=46,$.ESCAPE=27,$.ARROW="default",$.CROSS="crosshair",$.HAND="pointer",$.MOVE="move",$.TEXT="text";let t={},r=[$.LEFT,$.CENTER,$.RIGHT],a=$.canvas;function o(e){const t=$.canvas.getBoundingClientRect(),r=$.canvas.scrollWidth/$.width||1,a=$.canvas.scrollHeight/$.height||1;return{x:(e.clientX-t.left)/r,y:(e.clientY-t.top)/a,id:e.identifier}}if($._startAudio=()=>{$.getAudioContext&&"suspended"==$.getAudioContext()?.state&&$.userStartAudio()},$._updateMouse=t=>{if(!t.changedTouches){if(a){let r=a.getBoundingClientRect(),o=a.scrollWidth/$.width||1,n=a.scrollHeight/$.height||1;e.mouseX=(t.clientX-r.left)/o,e.mouseY=(t.clientY-r.top)/n,"webgpu"==a.renderer&&(e.mouseX-=a.hw,e.mouseY-=a.hh)}else e.mouseX=t.clientX,e.mouseY=t.clientY;e.moveX=t.movementX,e.moveY=t.movementY}},$._onmousedown=t=>{$._startAudio(),$._updateMouse(t),e.mouseIsPressed=!0,e.mouseButton=r[t.button],$.mousePressed(t)},$._onmousemove=e=>{$._updateMouse(e),$.mouseIsPressed?$.mouseDragged(e):$.mouseMoved(e)},$._onmouseup=t=>{$._updateMouse(t),e.mouseIsPressed=!1,$.mouseReleased(t)},$._onclick=t=>{$._updateMouse(t),e.mouseIsPressed=!0,$.mouseClicked(t),e.mouseIsPressed=!1},$.cursor=(e,t,r)=>{let a="";e.includes(".")&&(e=`url("${e}")`,a=", auto"),void 0!==t&&(e+=" "+t+" "+r),$.canvas.style.cursor=e+a},$.noCursor=()=>{$.canvas.style.cursor="none"},$.requestPointerLock=document.body?.requestPointerLock,$.exitPointerLock=document.exitPointerLock,$._onkeydown=r=>{if(!$.key)return;r.repeat||($._startAudio(),e.keyIsPressed=!0,e.key=r.key,e.keyCode=r.keyCode,t[$.keyCode]=t[$.key.toLowerCase()]=!0,$.keyPressed(r),1==r.key.length&&$.keyTyped(r))},$._onkeyup=r=>{if(!s.key)return;e.keyIsPressed=!1,e.key=r.key,e.keyCode=r.keyCode,t[$.keyCode]=t[$.key.toLowerCase()]=!1,$.keyReleased(r)},$.keyIsDown=e=>!!t["string"==typeof e?e.toLowerCase():e],$._ontouchstart=t=>{$._startAudio(),e.touches=[...t.touches].map(o),$._isTouchAware||(e.mouseX=$.touches[0].x,e.mouseY=$.touches[0].y,e.mouseIsPressed=!0,e.mouseButton=$.LEFT,$.mousePressed(t)||t.preventDefault()),$.touchStarted(t)||t.preventDefault()},$._ontouchmove=t=>{e.touches=[...t.touches].map(o),$._isTouchAware||(e.mouseX=$.touches[0].x,e.mouseY=$.touches[0].y,$.mouseDragged(t)||t.preventDefault()),$.touchMoved(t)||t.preventDefault()},$._ontouchend=t=>{e.touches=[...t.touches].map(o),$._isTouchAware||$.touches.length||(e.mouseIsPressed=!1,$.mouseReleased(t)||t.preventDefault()),$.touchEnded(t)||t.preventDefault()},a&&(a.addEventListener("mousedown",(e=>$._onmousedown(e))),a.addEventListener("mouseup",(e=>$._onmouseup(e))),a.addEventListener("click",(e=>$._onclick(e))),a.addEventListener("touchstart",(e=>$._ontouchstart(e))),a.addEventListener("touchmove",(e=>$._ontouchmove(e))),a.addEventListener("touchcancel",(e=>$._ontouchend(e))),a.addEventListener("touchend",(e=>$._ontouchend(e)))),window){let e=window.addEventListener;e("mousemove",(e=>$._onmousemove(e)),!1),e("keydown",(e=>$._onkeydown(e)),!1),e("keyup",(e=>$._onkeyup(e)),!1)}},a.modules.math=($,e)=>{$.RADIANS=0,$.DEGREES=1,$.PI=Math.PI,$.HALF_PI=Math.PI/2,$.QUARTER_PI=Math.PI/4,$.abs=Math.abs,$.ceil=Math.ceil,$.exp=Math.exp,$.floor=$.int=Math.floor,$.loge=Math.log,$.mag=Math.hypot,$.max=Math.max,$.min=Math.min,$.round=Math.round,$.pow=Math.pow,$.sqrt=M
9ath.sqrt,$.SHR3=1,$.LCG=2;let t=0;$.angleMode=e=>{"radians"==e&&(e=0),t=$._angleMode=e};let r=$._DEGTORAD=Math.PI/180,o=$._RADTODEG=180/Math.PI;function n(){let e,t,r=4294967295;return{setSeed(a){e=t=(null==a?Math.random()*r:a)>>>0},getSeed:()=>t,rand:()=>(e^=e<<17,e^=e>>13,e^=e<<5,(e>>>0)/r)}}$.degrees=e=>e*$._RADTODEG,$.radians=e=>e*$._DEGTORAD,$.map=a.prototype.map=(e,t,r,a,o,n)=>{let i=a+1*(e-t)/(r-t)*(o-a);return n?a<o?Math.min(Math.max(i,a),o):Math.min(Math.max(i,o),a):i},$.lerp=(e,t,r)=>e*(1-r)+t*r,$.constrain=(e,t,r)=>Math.min(Math.max(e,t),r),$.dist=function(){let e=arguments;return 4==e.length?Math.hypot(e[0]-e[2],e[1]-e[3]):Math.hypot(e[0]-e[3],e[1]-e[4],e[2]-e[5])},$.norm=(e,t,r)=>$.map(e,t,r,0,1),$.sq=e=>e*e,$.fract=e=>e-Math.floor(e),$.sin=e=>Math.sin(t?e*r:e),$.cos=e=>Math.cos(t?e*r:e),$.tan=e=>Math.tan(t?e*r:e),$.asin=e=>{let r=Math.asin(e);return t?r*o:r},$.acos=e=>{let r=Math.acos(e);return t?r*o:r},$.atan=e=>{let r=Math.atan(e);return t?r*o:r},$.atan2=(e,r)=>{let a=Math.atan2(e,r);return t?a*o:a};let i=n();i.setSeed(),$.randomSeed=e=>i.setSeed(e),$.random=(e,t)=>void 0===e?i.rand():"number"==typeof e?void 0!==t?i.rand()*(t-e)+e:i.rand()*e:e[Math.trunc(e.length*i.rand())],$.randomGenerator=e=>{e==$.LCG?i=function(){const e=4294967296;let t,r;return{setSeed(a){r=t=(null==a?Math.random()*e:a)>>>0},getSeed:()=>t,rand:()=>(r=(1664525*r+1013904223)%e,r/e)}}():e==$.SHR3&&(i=n()),i.setSeed()};var s=new function(){var e,t,r,a=new Array(128),o=new Array(256),n=new Array(128),s=new Array(128),l=new Array(256),d=new Array(256),c=()=>4294967296*i.rand()-2147483648,h=()=>.5+2.328306e-10*(c()|0),u=()=>{for(var t,o,i,l,d=3.44262;;){if(t=r*n[e],0==e){do{i=h(),l=h(),t=.2904764*-Math.log(i),o=-Math.log(l)}while(o+o<t*t);return r>0?d+t:-d-t}if(s[e]+h()*(s[e-1]-s[e])<Math.exp(-.5*t*t))return t;if(r=c(),e=127&r,Math.abs(r)<a[e])return r*n[e]}},p=()=>{for(var r;;){if(0==e)return 7.69711-Math.log(h());if(r=t*l[e],d[e]+h()*(d[e-1]-d[e])<Math.exp(-r))return r;if((t=c())<o[e=255&t])return t*l[e]}};this.SHR3=c,this.UNI=h,this.RNOR=()=>(r=c(),e=127&r,Math.abs(r)<a[e]?r*n[e]:u()),this.REXP=()=>(t=c()>>>0)<a[e=255&t]?t*l[e]:p(),this.zigset=()=>{var e,t,r=2147483648,i=4294967296,c=3.442619855899,h=c,u=.00991256303526217,p=7.697117470131487,f=p,_=.003949659822581572;for(e=u/Math.exp(-.5*c*c),a[0]=Math.floor(c/e*r),a[1]=0,n[0]=e/r,n[127]=c/r,s[0]=1,s[127]=Math.exp(-.5*c*c),t=126;t>=1;t--)c=Math.sqrt(-2*Math.log(u/c+Math.exp(-.5*c*c))),a[t+1]=Math.floor(c/h*r),h=c,s[t]=Math.exp(-.5*c*c),n[t]=c/r;for(e=_/Math.exp(-p),o[0]=Math.floor(p/e*i),o[1]=0,l[0]=e/i,l[255]=p/i,d[0]=1,d[255]=Math.exp(-p),t=254;t>=1;t--)p=-Math.log(_/p+Math.exp(-p)),o[t+1]=Math.floor(p/f*i),f=p,d[t]=Math.exp(-p),l[t]=p/i}};let l;s.hasInit=!1,$.randomGaussian=(e,t)=>(s.hasInit||(s.zigset(),s.hasInit=!0),s.RNOR()*t+e),$.randomExponential=()=>(s.hasInit||(s.zigset(),s.hasInit=!0),s.REXP()),$.PERLIN="perlin",$.SIMPLEX="simplex",$.BLOCKY="blocky",$.Noise=a.PerlinNoise,$.noiseMode=t=>{e.Noise=a[t[0].toUpperCase()+t.slice(1)+"Noise"],l=null},$.noiseSeed=e=>{l=new $.Noise(e)},$.noise=(e=0,t=0,r=0)=>(l??=new $.Noise,l.noise(e,t,r)),$.noiseDetail=(e,t)=>{l??=new $.Noise,e>0&&(l.octaves=e),t>0&&(l.falloff=t)}},a.Noise=class{},a.PerlinNoise=class extends a.Noise{constructor(e){super(),this.grad3=[[1,1,0],[-1,1,0],[1,-1,0],[-1,-1,0],[1,0,1],[-1,0,1],[1,0,-1],[-1,0,-1],[0,1,1],[0,-1,1],[0,1,-1],[0,-1,-1]],this.octaves=1,this.falloff=.5,this.p=null==e?Array.from({length:256},(()=>Math.floor(256*Math.random()))):this.seedPermutation(e),this.p=this.p.concat(this.p)}seedPermutation(e){let t,r,a=[];for(let e=0;e<256;e++)a[e]=e;for(let o=255;o>0;o--)t=(e=16807*e%2147483647)%(o+1),r=a[o],a[o]=a[t],a[t]=r;return a}dot(e,t,r,a){return e[0]*t+e[1]*r+e[2]*a}mix(e,t,r){return(1-r)*e+r*t}fade(e){return e*e*e*(e*(6*e-15)+10)}noise(e,t,r){let a=this,o=0,n=1,i=1,s=0;for(let l=0;l<a.octaves;l++){const l=255&Math.floor(e*n),d=255&Math.floor(t*n),c=255&Math.floor(r*n),h=e*n-Math.floor(e*n),u=t*n-Math.floor(t*n),p=r*n-Math.floor(r*n),f=a.fade(h),_=a.fade(u),g=a.fade(p),m=a.p[l]+d,x=a.p[m]+c,v=a.p[m+1]+c,y=a.p[l+1]+d,w=a.p[y]+c,b=a.p[y+1]+c,S=a.mix(a.dot(a.grad3[a.p[x]%12],h,u,p),a.dot(a.grad3[a.p[w]%12],h-1,u,p),f),C=a.mix(a.dot(a.grad3[a.p[v]%12],h,u-1,p),a.dot(a.grad3[a.p[b]%12],h-1,u-1,p),f),M=a.mix(a.dot(a.grad3[a.p[x+1]%12],h,u,p-1),a.dot(a.grad3[a.p[w+1]%12],h-1,u,p-1),f),I=a.mix(a.dot(a.grad3[a.p[v+1]%12],h,u-1,p-1),a.dot(a.grad3[a.p[b+1]%12],h-1,u-1,p-1),f),R=a.mix(S,C,_),k=a.mix(M,I,_);o+=a.mix(R,k,g)*i,s+=i,i*=a.falloff,n*=2}return(o/s+1)/2}},a.modules.sound=($,e)=>{$.Sound=a.Sound,$.loadSound=(t,r)=>{e._preloadCount++,a.aud??=new window.AudioContext;let o=new a.Sound(t,r);return o.crossOrigin="Anonymous",o.addEventListener("canplaythrough",(()=>{e._preloadCount--,o.loaded=!0,r&&r(o)})),o},$.getAudioContext=()=>a.aud,$.userStartAudio=()=>a.aud.resume()},a.Sound=class extends Audio{constructor(e){super(e);let t=this;
9t.load(),t.panner=a.aud.createStereoPanner(),t.source=a.aud.createMediaElementSource(t),t.source.connect(t.panner),t.panner.connect(a.aud.destination),Object.defineProperty(t,"pan",{get:()=>t.panner.pan.value,set:e=>t.panner.pan.value=e})}setVolume(e){this.volume=e}setLoop(e){this.loop=e}setPan(e){this.pan=e}isLoaded(){return this.loaded}isPlaying(){return!this.paused}},a.modules.util=($,e)=>{$._loadFile=(t,r,a)=>{e._preloadCount++;let o={};return fetch(t).then((e=>"json"==a?e.json():e.text())).then((t=>{e._preloadCount--,"csv"==a&&(t=$.CSV.parse(t)),Object.assign(o,t),r&&r(t)})),o},$.loadText=(e,t)=>$._loadFile(e,t,"text"),$.loadJSON=(e,t)=>$._loadFile(e,t,"json"),$.loadCSV=(e,t)=>$._loadFile(e,t,"csv"),$.CSV={},$.CSV.parse=(e,t=",",r="\n")=>{let a=[],o=e.split(r),n=o[0].split(t);for(let e=1;e<o.length;e++){let r={},i=o[e].split(t);n.forEach(((e,t)=>r[e]=JSON.parse(i[t]))),a.push(r)}return a},"object"==typeof localStorage&&($.storeItem=localStorage.setItem,$.getItem=localStorage.getItem,$.removeItem=localStorage.removeItem,$.clearStorage=localStorage.clear),$.year=()=>(new Date).getFullYear(),$.day=()=>(new Date).getDay(),$.hour=()=>(new Date).getHours(),$.minute=()=>(new Date).getMinutes(),$.second=()=>(new Date).getSeconds()},a.modules.vector=$=>{$.createVector=(e,t,r)=>new a.Vector(e,t,r,$)},a.Vector=class{constructor(e,t,r,$){this.x=e||0,this.y=t||0,this.z=r||0,this._$=$||window,this._cn=null,this._cnsq=null}set(e,t,r){return this.x=e?.x||e||0,this.y=e?.y||t||0,this.z=e?.z||r||0,this}copy(){return new a.Vector(this.x,this.y,this.z)}_arg2v(e,t,r){return void 0!==e?.x?e:void 0!==t?{x:e,y:t,z:r||0}:{x:e,y:e,z:e}}_calcNorm(){this._cnsq=this.x*this.x+this.y*this.y+this.z*this.z,this._cn=Math.sqrt(this._cnsq)}add(){let e=this._arg2v(...arguments);return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}rem(){let e=this._arg2v(...arguments);return this.x%=e.x,this.y%=e.y,this.z%=e.z,this}sub(){let e=this._arg2v(...arguments);return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}mult(){let e=this._arg2v(...arguments);return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}div(){let e=this._arg2v(...arguments);return e.x?this.x/=e.x:this.x=0,e.y?this.y/=e.y:this.y=0,e.z?this.z/=e.z:this.z=0,this}mag(){return this._calcNorm(),this._cn}magSq(){return this._calcNorm(),this._cnsq}dot(){let e=this._arg2v(...arguments);return this.x*e.x+this.y*e.y+this.z*e.z}dist(){let e=this._arg2v(...arguments),t=this.x-e.x,r=this.y-e.y,a=this.z-e.z;return Math.sqrt(t*t+r*r+a*a)}cross(){let e=this._arg2v(...arguments),t=this.y*e.z-this.z*e.y,r=this.z*e.x-this.x*e.z,a=this.x*e.y-this.y*e.x;return this.x=t,this.y=r,this.z=a,this}normalize(){this._calcNorm();let e=this._cn;return 0!=e&&(this.x/=e,this.y/=e,this.z/=e),this._cn=1,this._cnsq=1,this}limit(e){this._calcNorm();let t=this._cn;if(t>e){let r=e/t;this.x*=r,this.y*=r,this.z*=r,this._cn=e,this._cnsq=e*e}return this}setMag(e){this._calcNorm();let t=e/this._cn;return this.x*=t,this.y*=t,this.z*=t,this._cn=e,this._cnsq=e*e,this}heading(){return this._$.atan2(this.y,this.x)}setHeading(e){let t=this.mag();return this.x=t*this._$.cos(e),this.y=t*this._$.sin(e),this}rotate(e){let t=this._$.cos(e),r=this._$.sin(e),a=this.x*t-this.y*r,o=this.x*r+this.y*t;return this.x=a,this.y=o,this}angleBetween(){let e=this._arg2v(...arguments),t=a.Vector.cross(this,e);return this._$.atan2(t.mag(),this.dot(e))*Math.sign(t.z||1)}lerp(){let e=[...arguments],t=e.at(-1);if(0==t)return this;let r=this._arg2v(...e.slice(0,-1));return this.x+=(r.x-this.x)*t,this.y+=(r.y-this.y)*t,this.z+=(r.z-this.z)*t,this}slerp(){let e=[...arguments],t=e.at(-1);if(0==t)return this;let r=this._arg2v(...e.slice(0,-1));if(1==t)return this.set(r);let o=this.mag(),n=r.mag();if(0==o||0==n)return this.mult(1-t).add(r.mult(t));let i=a.Vector.cross(this,r),s=i.mag(),l=Math.atan2(s,this.dot(r));if(s>0)i.div(s);else{if(l<this._$.HALF_PI)return this.mult(1-t).add(r.mult(t));0==this.z&&0==r.z?i.set(0,0,1):0!=this.x?i.set(this.y,-this.x,0).normalize():i.set(1,0,0)}let d=i.cross(this),c=1-t+t*n/o,h=c*Math.cos(t*l),u=c*Math.sin(t*l);return this.x=this.x*h+d.x*u,this.y=this.y*h+d.y*u,this.z=this.z*h+d.z*u,this}reflect(e){return e.normalize(),this.sub(e.mult(2*this.dot(e)))}array(){return[this.x,this.y,this.z]}equals(e,t){return t??=Number.EPSILON||0,Math.abs(e.x-this.x)<t&&Math.abs(e.y-this.y)<t&&Math.abs(e.z-this.z)<t}fromAngle(e,t){return void 0===t&&(t=1),this._cn=t,this._cnsq=t*t,this.x=t*this._$.cos(e),this.y=t*this._$.sin(e),this.z=0,this}fromAngles(e,t,r){void 0===r&&(r=1),this._cn=r,this._cnsq=r*r;const a=this._$.cos(t),o=this._$.sin(t),n=this._$.cos(e),i=this._$.sin(e);return this.x=r*i*o,this.y=-r*n,this.z=r*i*a,this}random2D(){return this._cn=this._cnsq=1,this.fromAngle(Math.random()*Math.PI*2)}random3D(){return this._cn=this._cnsq=1,this.fromAngles(Math.random()*Math.PI*2,Math.random()*Math.PI*2)}toString(){return`[${this.x}, ${this.y}, ${this.z}]`}},a.Vector.add=(e,t)=>e.copy().add(t),a.Vector.cross=(e,t)=>e.copy().cross(t),a.Vector.dist=(e,t)=>
9Math.hypot(e.x-t.x,e.y-t.y,e.z-t.z),a.Vector.div=(e,t)=>e.copy().div(t),a.Vector.dot=(e,t)=>e.copy().dot(t),a.Vector.equals=(e,t,r)=>e.equals(t,r),a.Vector.lerp=(e,t,r)=>e.copy().lerp(t,r),a.Vector.slerp=(e,t,r)=>e.copy().slerp(t,r),a.Vector.limit=(e,t)=>e.copy().limit(t),a.Vector.heading=e=>(void 0)._$.atan2(e.y,e.x),a.Vector.magSq=e=>e.x*e.x+e.y*e.y+e.z*e.z,a.Vector.mag=e=>Math.sqrt(a.Vector.magSq(e)),a.Vector.mult=(e,t)=>e.copy().mult(t),a.Vector.normalize=e=>e.copy().normalize(),a.Vector.rem=(e,t)=>e.copy().rem(t),a.Vector.sub=(e,t)=>e.copy().sub(t);for(let e of["fromAngle","fromAngles","random2D","random3D"])a.Vector[e]=(t,r,o)=>(new a.Vector)[e](t,r,o);a.renderers.webgpu={},a.renderers.webgpu.canvas=($,e)=>{let t=$.canvas;t.width=$.width=500,t.height=$.height=500,$.colorMode&&$.colorMode("rgb",1);let r,o,n,i=1,s=8;$._pipelineConfigs=[],$._pipelines=[];let l=$.drawStack=[],d=$.colorStack=new Float32Array(1e6);d.set([0,0,0,1,1,1,1,1]),$._transformLayout=a.device.createBindGroupLayout({label:"transformLayout",entries:[{binding:0,visibility:GPUShaderStage.VERTEX,buffer:{type:"uniform",hasDynamicOffset:!1}},{binding:1,visibility:GPUShaderStage.VERTEX,buffer:{type:"read-only-storage",hasDynamicOffset:!1}}]}),n=a.device.createBindGroupLayout({label:"colorsLayout",entries:[{binding:0,visibility:GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT,buffer:{type:"read-only-storage",hasDynamicOffset:!1}}]}),$.bindGroupLayouts=[$._transformLayout,n];let c=a.device.createBuffer({size:8,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),h=()=>{o=a.device.createTexture({size:[$.canvas.width,$.canvas.height],sampleCount:4,format:"bgra8unorm",usage:GPUTextureUsage.RENDER_ATTACHMENT}).createView()};$._createCanvas=(r,o,n)=>(e.ctx=e.drawingContext=t.getContext("webgpu"),n.format??=navigator.gpu.getPreferredCanvasFormat(),n.device??=a.device,$.ctx.configure(n),a.device.queue.writeBuffer(c,0,new Float32Array([$.canvas.hw,$.canvas.hh])),h(),t),$._resizeCanvas=(e,t)=>{$._setCanvasSize(e,t),h()},$.pixelDensity=e=>e&&e!=$._pixelDensity?($._pixelDensity=e,$._setCanvasSize(t.w,t.h),h(),e):$._pixelDensity;let u=(e,t,r,a=1)=>{"string"==typeof e?e=$.color(e):null==r&&(a=t??1,t=r=e),e._q5Color&&(a=e.a,r=e.b,t=e.g,e=e.r);let o=d,n=s;o[n++]=e,o[n++]=t,o[n++]=r,o[n++]=a,s=n,i++};$._fillIndex=$._strokeIndex=0,$._doFill=$._doStroke=!0,$.fill=(e,t,r,a)=>{u(e,t,r,a),$._doFill=$._fillSet=!0,$._fillIndex=i},$.stroke=(e,t,r,a)=>{u(e,t,r,a),$._doStroke=$._strokeSet=!0,$._strokeIndex=i},$.noFill=()=>$._doFill=!1,$.noStroke=()=>$._doStroke=!1,$._strokeWeight=1,$.strokeWeight=e=>$._strokeWeight=Math.abs(e),$.resetMatrix=()=>{$._matrix=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],$._transformIndex=0},$.resetMatrix(),$._matrixDirty=!1;let p=[$._matrix.slice()];$._transformIndexStack=[],$.translate=(e,t,r)=>{(e||t||r)&&($._matrix[12]+=e,$._matrix[13]-=t,$._matrix[14]+=r||0,$._matrixDirty=!0)},$.rotate=e=>{if(!e)return;$._angleMode&&(e*=$._DEGTORAD);let t=Math.cos(e),r=Math.sin(e),a=$._matrix,o=a[0],n=a[1],i=a[4],s=a[5];o||n||i||s?(a[0]=o*t+i*r,a[1]=n*t+s*r,a[4]=i*t-o*r,a[5]=s*t-n*r):(a[0]=t,a[1]=r,a[4]=-r,a[5]=t),$._matrixDirty=!0},$.scale=(e=1,t,r=1)=>{t??=e;let a=$._matrix;a[0]*=e,a[1]*=e,a[2]*=e,a[3]*=e,a[4]*=t,a[5]*=t,a[6]*=t,a[7]*=t,a[8]*=r,a[9]*=r,a[10]*=r,a[11]*=r,$._matrixDirty=!0},$.shearX=e=>{if(!e)return;$._angleMode&&(e*=$._DEGTORAD);let t=Math.tan(e),r=$._matrix[0],a=$._matrix[1],o=$._matrix[4],n=$._matrix[5];$._matrix[0]=r+o*t,$._matrix[1]=a+n*t,$._matrixDirty=!0},$.shearY=e=>{if(!e)return;$._angleMode&&(e*=$._DEGTORAD);let t=Math.tan(e),r=$._matrix[0],a=$._matrix[1],o=$._matrix[4],n=$._matrix[5];$._matrix[4]=o+r*t,$._matrix[5]=n+a*t,$._matrixDirty=!0},$.applyMatrix=(...e)=>{let t;if(t=1==e.length?e[0]:e,9==t.length)t=[t[0],t[1],0,t[2],t[3],t[4],0,t[5],0,0,1,0,t[6],t[7],0,t[8]];else if(16!=t.length)throw new Error("Matrix must be a 3x3 or 4x4 array.");$._matrix=t.slice(),$._matrixDirty=!0},$._saveMatrix=()=>{p.push($._matrix.slice()),$._transformIndex=p.length-1,$._matrixDirty=!1},$.pushMatrix=()=>{$._matrixDirty&&$._saveMatrix(),$._transformIndexStack.push($._transformIndex)},$.popMatrix=()=>
9{if(!$._transformIndexStack.length)return console.warn("Matrix index stack is empty!");let e=$._transformIndexStack.pop();$._matrix=p[e].slice(),$._transformIndex=e,$._matrixDirty=!1},$.push=()=>{$.pushMatrix(),$.pushStyles()},$.pop=()=>{$.popMatrix(),$.popStyles()},$._calcBox=(e,t,r,a,o)=>{let n,i,s,l,d=r/2,c=a/2;return o&&"corner"!=o?"center"==o?(n=e-d,i=e+d,s=-(t-c),l=-(t+c)):(n=e,i=r,s=-t,l=-a):(n=e,i=e+r,s=-t,l=-(t+a)),[n,i,s,l]};let f=["zero","one","src-alpha","one-minus-src-alpha","dst","dst-alpha","one-minus-dst-alpha","one-minus-src"],_=["add","subtract","reverse-subtract","min","max"];const g={normal:[2,3,0,2,3,0],additive:[1,1,0,1,1,0]};$.blendConfigs={};for(const[e,t]of Object.entries(g))$.blendConfigs[e]={color:{srcFactor:f[t[0]],dstFactor:f[t[1]],operation:_[t[2]]},alpha:{srcFactor:f[t[3]],dstFactor:f[t[4]],operation:_[t[5]]}};$._blendMode="normal",$.blendMode=e=>{if(e!=$._blendMode){"source-over"==e&&(e="normal"),"lighter"==e&&(e="additive"),e=e.toLowerCase().replace(/[ -]/g,"_"),$._blendMode=e;for(let t=0;t<$._pipelines.length;t++)$._pipelineConfigs[t].fragment.targets[0].blend=$.blendConfigs[e],$._pipelines[t]=a.device.createRenderPipeline($._pipelineConfigs[t])}},$.clear=()=>{},$._beginRender=()=>{$.encoder=a.device.createCommandEncoder(),r=e.pass=$.encoder.beginRenderPass({label:"q5-webgpu",colorAttachments:[{view:o,resolveTarget:$.ctx.getCurrentTexture().createView(),loadOp:"clear",storeOp:"store"}]})},$._render=()=>{if(p.length>1||!$._transformBindGroup){let e=a.device.createBuffer({size:64*p.length,usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST,mappedAtCreation:!0});new Float32Array(e.getMappedRange()).set(p.flat()),e.unmap(),$._transformBindGroup=a.device.createBindGroup({layout:$._transformLayout,entries:[{binding:0,resource:{buffer:c}},{binding:1,resource:{buffer:e}}]})}r.setBindGroup(0,$._transformBindGroup);let e=a.device.createBuffer({size:4*s,usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST,mappedAtCreation:!0});new Float32Array(e.getMappedRange()).set(d.slice(0,s)),e.unmap(),$._colorsBindGroup=a.device.createBindGroup({layout:n,entries:[{binding:0,resource:{buffer:e}}]}),$.pass.setBindGroup(1,$._colorsBindGroup);for(let e of $._hooks.preRender)e();let t=0,o=0,i=0,h=-1;for(let e=0;e<l.length;e+=2){let a=l[e+1];if(h!=l[e]&&(h=l[e],r.setPipeline($._pipelines[h])),0==h)r.draw(a,1,t),t+=a;else if(1==h)-1!=a&&r.setBindGroup(2,$._textureBindGroups[a]),r.draw(4,1,o),o+=4;else if(2==h){let t=l[e+2];r.setBindGroup(2,$._fonts[t].bindGroup),r.setBindGroup(3,$._textBindGroup),r.draw(4,a,0,i),i+=a,e++}}for(let e of $._hooks.postRender)e()},$._finishRender=()=>{r.end();let t=$.encoder.finish();a.device.queue.submit([t]),e.pass=$.encoder=null,$.drawStack.length=0,i=1,s=8,rotation=0,p.length=1,$._transformIndexStack.length=0}},a.initWebGPU=async()=>{if(!navigator.gpu)return console.warn("q5 WebGPU not supported on this browser!"),!1;if(!a.device){let e=await navigator.gpu.requestAdapter();if(!e)throw new Error("No appropriate GPUAdapter found.");a.device=await e.requestDevice()}return!0},a.webgpu=async function(e,t){if(e&&"global"!=e||(a._hasGlobal=!0),!await a.initWebGPU()){let r=new a(e,t);return r.colorMode("rgb",1),r._beginRender=()=>r.translate(r.canvas.hw,r.canvas.hh),r}return new a(e,t,"webgpu")},a.renderers.webgpu.drawing=($,e)=>{let t,r=$.canvas,o=$.drawStack,n=new Float32Array(1e7),i=0,s=a.device.createShaderModule({label:"drawingVertexShader",code:"\nstruct VertexInput {\n\t@location(0) pos: vec2f,\n\t@location(1) colorIndex: f32,\n\t@location(2) transformIndex: f32\n}\nstruct VertexOutput {\n\t@builtin(position) position: vec4f,\n\t@location(0) color: vec4f\n}\nstruct Uniforms {\n\thalfWidth: f32,\n\thalfHeight: f32\n}\n\n@group(0) @binding(0) var<uniform> uniforms: Uniforms;\n@group(0) @binding(1) var<storage> transforms: array<mat4x4<f32>>;\n\n@group(1) @binding(0) var<storage> colors : array<vec4f>;\n\n@vertex\nfn vertexMain(input: VertexInput) -> VertexOutput {\n\tvar vert = vec4f(input.pos, 0.0, 1.0);\n\tvert = transforms[i32(input.transformIndex)] * vert;\n\tvert.x /= uniforms.halfWidth;\n\tvert.y /= uniforms.halfHeight;\n\n\tvar output: VertexOutput;\n\toutput.position = vert;\n\toutput.color = colors[i32(input.colorIndex)];\n\treturn output;\n}\n"}),l=a.device.createShaderModule({label:"drawingFragmentShader",code:"\n@fragment\nfn fragmentMain(@location(0) color: vec4f) -> @location(0) vec4f {\n\treturn color;\n}\n"}),d=a.device.createPipelineLayout({label:"drawingPipelineLayout",bindGroupLayouts:$.bindGroupLayouts});$._pipelineConfigs[0]={label:"drawingPipeline",layout:d,vertex:{module:s,entryPoint:"vertexMain",buffers:[{arrayStri
9de:16,attributes:[{format:"float32x2",offset:0,shaderLocation:0},{format:"float32",offset:8,shaderLocation:1},{format:"float32",offset:12,shaderLocation:2}]}]},fragment:{module:l,entryPoint:"fragmentMain",targets:[{format:"bgra8unorm",blend:$.blendConfigs.normal}]},primitive:{topology:"triangle-strip",stripIndexFormat:"uint32"},multisample:{count:4}},$._pipelines[0]=a.device.createRenderPipeline($._pipelineConfigs[0]);const c=(e,t,r,a)=>{let o=n,s=i;o[s++]=e,o[s++]=t,o[s++]=r,o[s++]=a,i=s},h=(e,t,r,a,s,l,d,c,h,u)=>{let p=n,f=i;p[f++]=e,p[f++]=t,p[f++]=h,p[f++]=u,p[f++]=r,p[f++]=a,p[f++]=h,p[f++]=u,p[f++]=d,p[f++]=c,p[f++]=h,p[f++]=u,p[f++]=s,p[f++]=l,p[f++]=h,p[f++]=u,i=f,o.push(0,4)},u=(e,t,r,a,s,l,d)=>{let c=0,h=$.TAU/s,u=n,p=i;for(let o=0;o<=s;o++){u[p++]=e,u[p++]=t,u[p++]=l,u[p++]=d;let o=e+r*Math.cos(c),n=t+a*Math.sin(c);u[p++]=o,u[p++]=n,u[p++]=l,u[p++]=d,c+=h}u[p++]=e,u[p++]=t,u[p++]=l,u[p++]=d,u[p++]=e+r,u[p++]=t,u[p++]=l,u[p++]=d,i=p,o.push(0,2*(s+1)+2)};$.rectMode=e=>$._rectMode=e,$.rect=(e,r,a,o)=>{let n,i,[s,l,d,c]=$._calcBox(e,r,a,o,$._rectMode);if($._matrixDirty&&$._saveMatrix(),i=$._transformIndex,$._doStroke){n=$._strokeIndex;let e=$._strokeWeight/2;if($._doFill){let t=d+e,r=c-e,a=s-e,o=l+e;h(a,t,o,t,o,r,a,r,n,i),d-=e,c+=e,s+=e,l-=e}else{let t=s-e,r=l+e,a=d+e,o=c-e,u=s+e,p=l-e,f=d-e,_=c+e;h(t,f,r,f,r,a,t,a,n,i),h(t,o,r,o,r,_,t,_,n,i),h(t,a,u,a,u,o,t,o,n,i),h(p,a,r,a,r,o,p,o,n,i)}}$._doFill&&(n=t??$._fillIndex,h(s,d,l,d,l,c,s,c,n,i))},$.square=(e,t,r)=>$.rect(e,t,r,r);let p;$.ellipseMode=e=>$._ellipseMode=e,$.ellipse=(e,r,a,o)=>{let n=(i=a==o?a:Math.max(a,o))<4?6:i<6?8:i<10?10:i<16?12:i<20?14:i<22?16:i<24?18:i<28?20:i<34?22:i<42?24:i<48?26:i<56?28:i<64?30:i<72?32:i<84?34:i<96?36:i<98?38:i<113?40:i<149?44:i<199?48:i<261?52:i<353?56:i<461?60:i<585?64:i<1200?70:i<1800?80:i<2400?90:100;var i;let s=Math.max(a,1)/2,l=a==o?s:Math.max(o,1)/2;$._matrixDirty&&$._saveMatrix();let d=$._transformIndex;if($._doStroke){let t=$._strokeWeight/2;u(e,r,s+t,l+t,n,$._strokeIndex,d),s-=t,l-=t}$._doFill&&u(e,r,s,l,n,t??$._fillIndex,d)},$.circle=(e,t,r)=>$.ellipse(e,t,r,r),$.point=(e,r)=>{t=$._strokeIndex,$._doStroke=!1;let a=$._strokeWeight;a<2?(a=Math.round(a),$.rect(e,r,a,a)):$.ellipse(e,r,a,a),$._doStroke=!0,t=null},$.line=(e,r,a,o)=>{t=$._strokeIndex,$.push(),$._doStroke=!1,$.translate(e,-r),$.rotate($.atan2(o-r,a-e));let n=Math.sqrt((a-e)**2+(o-r)**2),i=$._strokeWeight,s=i/2;$._rectMode="corner",i<4?$.rect(-s,-s,n+s,i):($._ellipseMode="center",$.ellipse(0,0,i,i),$.ellipse(n,0,i,i),$.rect(0,-s,n,i)),$.pop(),t=null};let f=[];$.beginShape=()=>{p=0,f=[]},$.vertex=(e,t)=>{$._matrixDirty&&$._saveMatrix(),f.push(e,-t,$._fillIndex,$._transformIndex),p++},$.endShape=e=>{if(p<3)throw new Error("A shape must have at least 3 vertices.");if(e){let e=0,t=4*(p-1),r=f[e],a=f[e+1],o=f[t],n=f[t+1];r===o&&a===n||(f.push(r,a,f[e+2],f[e+3]),p++)}if($._doFill){for(let e=1;e<p-1;e++){let t=0,r=4*e,a=4*(e+1);c(f[t],f[t+1],f[t+2],f[t+3]),c(f[r],f[r+1],f[r+2],f[r+3]),c(f[a],f[a+1],f[a+2],f[a+3])}o.push(0,3*(p-2))}if($._doStroke){for(let e=0;e<p-1;e++){let t=4*e,r=4*(e+1);$.line(f[t],f[t+1],f[r],f[r+1])}if(e){let e=4*(p-1),t=0;$.line(f[e],f[e+1],f[t],f[t+1])}}p=0,f=[]},$.triangle=(e,t,r,a,o,n)=>{$.beginShape(),$.vertex(e,t),$.vertex(r,a),$.vertex(o,n),$.endShape(!0)},$.quad=(e,t,r,a,o,n,i,s)=>{$.beginShape(),$.vertex(e,t),$.vertex(r,a),$.vertex(o,n),$.vertex(i,s),$.endShape(!0)},$.background=(e,t,a,o)=>{if($.push(),$.resetMatrix(),$._doStroke=!1,e.src){let t=$._imageMode;$._imageMode="corner",$.image(e,-r.hw,-r.hh,r.w,r.h),$._imageMode=t}else{let n=$._rectMode;$._rectMode="corner",$.fill(e,t,a,o),$.rect(-r.hw,-r.hh,r.w,r.h),$._rectMode=n}$.pop(),$._fillSet||($._fillIndex=1)},$._hooks.preRender.push((()=>{$.pass.setPipeline($._pipelines[0]);let e=a.device.createBuffer({size:4*i,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST,mappedAtCreation:!0});new Float32Array(e.getMappedRange()).set(n.slice(0,i)),e.unmap(),$.pass.setVertexBuffer(0,e)})),$._hooks.postRender.push((()=>{i=0}))},a.renderers.webgpu.image=($,e)=>{$._textureBindGroups=[];let t=[],r=a.device.createShaderModule({label:"imageVertexShader",code:"\nstruct VertexOutput {\n\t@builtin(position) position: vec4f,\n\t@location(0) texCoord: vec2f\n}\nstruct Uniforms {\n\thalfWidth: f32,\n\thalfHeight: f32\n}\n\n@group(0) @binding(0) var<uniform> uniforms: Uniforms;\n@group(0) @binding(1) var<storage> transforms: array<mat4x4<f32>>;\n\n@vertex\nfn vertexMain(@location(0) pos: vec2f, @location(1) texCoord: vec2f, @location(2) transformIndex: f32) -> VertexOutput {\n\tvar vert = vec4f(pos, 0.0, 1.0);\n\tvert = transforms[i32(transformIndex)] * vert;\n\tvert.x /= uniforms.halfWidth;\n\tvert.y /= uniforms.halfHeight;\n\n\tvar output: VertexOutput;\n\toutput.position = vert;\n\toutput.texCoord = texCoord;\n\treturn output;\n}\n\t"}),o=a.device.createShaderModule({label:"imageFragmentShader",code:"\n@group(2) @binding(0) var samp: sampler;\n@group(2) @binding(1) var texture: texture_2d<f32>;\n\n@fragment\nfn fragmentMain(@location(0) texCoord: vec2f) -> @location(0) vec4f {\n\t// Sample the texture using the interpolated texture coordinate\n\treturn textureSample(texture, samp, texCoord);\n}\n\t"}),n=a.device.createBindGroupLayout({label:"textureLayout",entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,sampler:{type:"filtering"}},{binding:1,visibility:GPUShaderStage.FRAGMENT,texture:{viewDimension:"2d",sampleType:"float"}}]});const i=a.device.createPipelineLayout({label:"imagePipelineLayout",bindGroupLayouts:[...$.bindGroupLayouts,n]});$._pipelineConfigs[1]={label:"imagePipeline",layout:i,vertex:{module:r,entryPoint:"vertexMain",buffers:[{arrayStri
9de:0,attributes:[]},{arrayStride:20,attributes:[{shaderLocation:0,offset:0,format:"float32x2"},{shaderLocation:1,offset:8,format:"float32x2"},{shaderLocation:2,offset:16,format:"float32"}]}]},fragment:{module:o,entryPoint:"fragmentMain",targets:[{format:"bgra8unorm",blend:$.blendConfigs.normal}]},primitive:{topology:"triangle-strip",stripIndexFormat:"uint32"},multisample:{count:4}},$._pipelines[1]=a.device.createRenderPipeline($._pipelineConfigs[1]);let s=a.device.createSampler({magFilter:"linear",minFilter:"linear"});$._textures=[];let l=0;$._createTexture=e=>{e.canvas&&(e=e.canvas);let t=[e.width,e.height,1],r=a.device.createTexture({size:t,format:"bgra8unorm",usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.RENDER_ATTACHMENT});a.device.queue.copyExternalImageToTexture({source:e},{texture:r,colorSpace:$.canvas.colorSpace},t),$._textures[l]=r,e.textureIndex=l;const o=a.device.createBindGroup({layout:n,entries:[{binding:0,resource:s},{binding:1,resource:r.createView()}]});$._textureBindGroups[l]=o,l=(l+1)%12e3,$._textures[l]&&($._textures[l].destroy(),delete $._textures[l],delete $._textureBindGroups[l])},$.loadImage=$.loadTexture=t=>{e._preloadCount++;const r=new Image;return r.crossOrigin="Anonymous",r.onload=()=>{r.defaultWidth=r.width*$._defaultImageScale,r.defaultHeight=r.height*$._defaultImageScale,$._createTexture(r),e._preloadCount--},r.src=t,r},$.imageMode=e=>$._imageMode=e,$.image=(e,r,a,o,n)=>{if(e.canvas&&(e=e.canvas),null==e.textureIndex)return;$._matrixDirty&&$._saveMatrix();let i=$._transformIndex;o??=e.defaultWidth,n??=e.defaultHeight;let[s,l,d,c]=$._calcBox(r,a,o,n,$._imageMode);t.push(s,d,0,0,i,l,d,1,0,i,s,c,0,1,i,l,c,1,1,i),$.drawStack.push(1,e.textureIndex)},$._hooks.preRender.push((()=>{if(!$._textureBindGroups.length)return;$.pass.setPipeline($._pipelines[1]);const e=a.device.createBuffer({size:4*t.length,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST,mappedAtCreation:!0});new Float32Array(e.getMappedRange()).set(t),e.unmap(),$.pass.setVertexBuffer(1,e)})),$._hooks.postRender.push((()=>{t.length=0}))},a.THRESHOLD=1,a.GRAY=2,a.OPAQUE=3,a.INVERT=4,a.POSTERIZE=5,a.DILATE=6,a.ERODE=7,a.BLUR=8,a.renderers.webgpu.text=($,e)=>{let t=a.device.createShaderModule({label:"MSDF text shader", 10code:"\n// Positions for simple quad geometry\nconst pos = array(vec2f(0, -1), vec2f(1, -1), vec2f(0, 0), vec2f(1, 0));\n\nstruct VertexInput {\n\t@builtin(vertex_index) vertex : u32,\n\t@builtin(instance_index) instance : u32\n}\nstruct VertexOutput {\n\t@builtin(position) position : vec4f,\n\t@location(0) texCoord : vec2f,\n\t@location(1) fillColor : vec4f\n}\nstruct Char {\n\ttexOffset: vec2f,\n\ttexExtent: vec2f,\n\tsize: vec2f,\n\toffset: vec2f,\n}\nstruct Text {\n\tpos: vec2f,\n\tscale: f32,\n\ttransformIndex: f32,\n\tfillIndex: f32,\n\tstrokeIndex: f32\n}\nstruct Uniforms {\n\thalfWidth: f32,\n\thalfHeight: f32\n}\n\n@group(0) @binding(0) var<uniform> uniforms: Uniforms;\n@group(0) @binding(1) var<storage> transforms: array<mat4x4<f32>>;\n\n@group(1) @binding(0) var<storage> colors : array<vec4f>;\n\n@group(2) @binding(0) var fontTexture: texture_2d<f32>;\n@group(2) @binding(1) var fontSampler: sampler;\n@group(2) @binding(2) var<storage> fontChars: array<Char>;\n\n@group(3) @binding(0) var<storage> textChars: array<vec4f>;\n@group(3) @binding(1) var<storage> textMetadata: array<Text>;\n\n@vertex\nfn vertexMain(input : VertexInput) -> VertexOutput {\n\tlet char = textChars[input.instance];\n\n\tlet text = textMetadata[i32(char.w)];\n\n\tlet fontChar = fontChars[i32(char.z)];\n\n\tlet charPos = ((pos[input.vertex] * fontChar.size + char.xy + fontChar.offset) * text.scale) + text.pos;\n\n\tvar vert = vec4f(charPos, 0.0, 1.0);\n\tvert = transforms[i32(text.transformIndex)] * vert;\n\tvert.x /= uniforms.halfWidth;\n\tvert.y /= uniforms.halfHeight;\n\n\tvar output : VertexOutput;\n\toutput.position = vert;\n\toutput.texCoord = (pos[input.vertex] * vec2f(1, -1)) * fontChar.texExtent + fontChar.texOffset;\n\toutput.fillColor = colors[i32(text.fillIndex)];\n\treturn output;\n}\n\nfn sampleMsdf(texCoord: vec2f) -> f32 {\n\tlet c = textureSample(fontTexture, fontSampler, texCoord);\n\treturn max(min(c.r, c.g), min(max(c.r, c.g), c.b));\n}\n\n@fragment\nfn fragmentMain(input : VertexOutput) -> @location(0) vec4f {\n\t// pxRange (AKA distanceRange) comes from the msdfgen tool,\n\t// uses the default which is 4.\n\tlet pxRange = 4.0;\n\tlet sz = vec2f(textureDimensions(fontTexture, 0));\n\tlet dx = sz.x*length(vec2f(dpdxFine(input.texCoord.x), dpdyFine(input.texCoord.x)));\n\tlet dy = sz.y*length(vec2f(dpdxFine(input.texCoord.y), dpdyFine(input.texCoord.y)));\n\tlet toPixels = pxRange * inverseSqrt(dx * dx + dy * dy);\n\tlet sigDist = sampleMsdf(input.texCoord) - 0.5;\n\tlet pxDist = sigDist * toPixels;\n\tlet edgeWidth = 0.5;\n\tlet alpha = smoothstep(-edgeWidth, edgeWidth, pxDist);\n\tif (alpha < 0.001) {\n\t\tdiscard;\n\t}\n\treturn vec4f(input.fillColor.rgb, input.fillColor.a * alpha);\n}\n"}),r=a.device.createBindGroupLayout({label:"MSDF text group layout",entries:[{binding:0,visibility:GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT,buffer:{type:"read-only-storage"}},{binding:1,visibility:GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT,buffer:{type:"read-only-storage"}}]}),o=a.device.createSampler({minFilter:"linear",magFilter:"linear",mipmapFilter:"linear",maxAnisotropy:16}),n=a.device.createBindGroupLayout({label:"MSDF font group layout",entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:1,visibility:GPUShaderStage.FRAGMENT,sampler:{}},{binding:2,visibility:GPUShaderStage.VERTEX,buffer:{type:"read-only-storage"}}]}),i=a.device.createPipelineLayout({bindGroupLayouts:[...$.bindGroupLayouts,n,r]});$._pipelineConfigs[2]={label:"msdf font pipeline",layout:i,vertex:{module:t,entryPoint:"vertexMain"},fragment:{module:t,entryPoint:"fragmentMain",targets:[{format:"bgra8unorm",blend:$.blendConfigs.normal}]}
10,primitive:{topology:"triangle-strip",stripIndexFormat:"uint32"},multisample:{count:4}},$._pipelines[2]=a.device.createRenderPipeline($._pipelineConfigs[2]);class s{constructor(e,t,r,a){this.bindGroup=e,this.lineHeight=t,this.chars=r,this.kernings=a;let o=Object.values(r);this.charCount=o.length,this.defaultChar=o[0]}getChar(e){return this.chars[e]??this.defaultChar}getXAdvance(e,t=-1){let r=this.getChar(e);if(t>=0){let a=this.kernings.get(e);if(a)return r.xadvance+(a.get(t)??0)}return r.xadvance}}$._fonts=[];let l={},d=$.createGraphics(1,1);d.colorMode($.RGB,1),$.loadFont=(t,r)=>{if("json"!=t.slice(t.lastIndexOf(".")+1))return d.loadFont(t,r);let i=t.slice(t.lastIndexOf("/")+1,t.lastIndexOf("-"));return(async(t,r,i)=>{e._preloadCount++;let d=await fetch(t);if(404==d.status)return e._preloadCount--,"";let c=await d.json(),h=t.lastIndexOf("/"),u=-1!=h?t.substring(0,h+1):"";d=await fetch(u+c.pages[0]);let p=await createImageBitmap(await d.blob()),f=[p.width,p.height,1],_=a.device.createTexture({label:`MSDF ${r}`,size:f,format:"rgba8unorm",usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.RENDER_ATTACHMENT});a.device.queue.copyExternalImageToTexture({source:p},{texture:_},f),"string"==typeof c.chars&&(c.chars=$.CSV.parse(c.chars," "),c.kernings=$.CSV.parse(c.kernings," "));let g=c.chars.length,m=a.device.createBuffer({size:32*g,usage:GPUBufferUsage.STORAGE,mappedAtCreation:!0}),x=new Float32Array(m.getMappedRange()),v=1/c.common.scaleW,y=1/c.common.scaleH,w={},b=0;for(let[e,t]of c.chars.entries())w[t.id]=t,w[t.id].charIndex=e,x[b]=t.x*v,x[b+1]=t.y*y,x[b+2]=t.width*v,x[b+3]=t.height*y,x[b+4]=t.width,x[b+5]=t.height,x[b+6]=t.xoffset,x[b+7]=-t.yoffset,b+=8;m.unmap();let S=a.device.createBindGroup({label:"msdf font bind group",layout:n,entries:[{binding:0,resource:_.createView()},{binding:1,resource:o},{binding:2,resource:{buffer:m}}]}),C=new Map;if(c.kernings)for(let e of c.kernings){let t=C.get(e.first);t||(t=new Map,C.set(e.first,t)),t.set(e.second,e.amount)}$._font=new s(S,c.common.lineHeight,w,C),$._font.index=$._fonts.length,$._fonts.push($._font),l[r]=$._font,e._preloadCount--,i&&i(r)})(t,i,r),i},$._textSize=18,$._textAlign="left",$._textBaseline="alphabetic";let c=!1,h=22.5,u=1.25;$.textFont=e=>{$._font=l[e]},$.textSize=e=>{$._textSize=e,c||(h=e*u)},$.textLeading=e=>{$._font.lineHeight=h=e,$._textSize,u=h/$._textSize,c=!0},$.textAlign=(e,t)=>{$._textAlign=e,t&&($._textBaseline=t)},$._charStack=[],$._textStack=[];let p,f=(e,t,r)=>{let a=0,o=0,n=0,i=0,s=0,l=[],d=t.charCodeAt(0);for(let c=0;c<t.length;++c){let h=d;switch(d=c<t.length-1?t.charCodeAt(c+1):-1,h){case 10:l.push(o),i++,a=Math.max(a,o),o=0,n-=e.lineHeight*u;break;case 13:break;case 32:o+=e.getXAdvance(h);break;case 9:o+=2*e.getXAdvance(h);break;default:r&&r(o,n,i,e.getChar(h)),o+=e.getXAdvance(h,d),s++}}return l.push(o),a=Math.max(a,o),{width:a,height:l.length*e.lineHeight*u,lineWidths:l,printedCharCount:s}};$.text=(e,t,r,a,o)=>{if(!$._font)return void(navigator.onLine&&!p&&(p=!0,$.loadFont("https://q5js.org/fonts/YaHei-msdf.json")));if(e.length>a){let t=[],r=0;for(;r<e.length;){let o=r+a;if(o>=e.length){t.push(e.slice(r));break}let n=e.lastIndexOf(" ",o);(-1==n||n<r)&&(n=o),t.push(e.slice(r,n)),r=n+1}e=t.join("\n")}let n;for(let t=0;t<e.length;t++){if("\n"===e[t])n=!0}let i,s=[],l=$._textAlign,d=$._textBaseline,c=$._textStack.length,u=0;if("left"!=l||n){i=f($._font,e);let t=0;"alphabetic"==d?r-=$._textSize:"center"==d?t=.5*i.height:"bottom"==d&&(t=i.height),f($._font,e,((e,r,a,o)=>{let n=0;"center"==l?n=-.5*i.width- -.5*(i.width-i.lineWidths[a]):"right"==l&&(n=i.width-i.lineWidths[a]),s[u]=e+n,s[u+1]=r+t,s[u+2]=o.charIndex,s[u+3]=c,u+=4}))}else i=f($._font,e,((e,t,r,a)=>{s[u]=e,s[u+1]=t,s[u+2]=a.charIndex,s[u+3]=c,u+=4})),"alphabetic"==d?r-=$._textSize:"center"==d?r-=.5*$._textSize:"bottom"==d&&(r-=h);$._charStack.push(s);let _=[];$._matrixDirty&&$._saveMatrix(),_[0]=t,_[1]=-r,_[2]=$._textSize/44,_[3]=$._transformIndex,_[4]=$._fillSet?$._fillIndex:0,_[5]=$._strokeIndex,$._textStack.push(_),$.drawStack.push(2,i.printedCharCount,$._font.index)},$.textWidth=e=>$._font?f($._font,e).width:0,$.createTextImage=(e,t,r)=>{if(d.textSize($._textSize),$._doFill){let e=4*$._fillIndex;d.fill(colorStack.slice(e,e+4))}if($._doStroke){let e=4*$._strokeIndex;d.stroke(colorStack.slice(e,e+4))}let o=d.createTextImage(e,t,r);if(null==o.canvas.textureIndex)$._createTexture(o);else if(o.modified){let e=o.canvas,t=[e.width,e.height,1],r=$._textures[e.textureIndex];a.device.queue.copyExternalImageToTexture({source:e},{texture:r,colorSpace:$.canvas.colorSpace},t),o.modified=!1}return o},$.textImage=(e,t,r)=>{"string"==typeof e&&(e=$.createTextImage(e));let a=$._imageMode;$._imageMode="corner";let o=$._textAlign;"center"==o?t-=e.canvas.hw:"right"==o&&(t-=e.width);let n=$._textBaseline;
10"alphabetic"==n?r-=e._leading:"center"==n?r-=e._middle:"bottom"==n?r-=e._bottom:"top"==n&&(r-=e._top),$.image(e,t,r),$._imageMode=a},$._hooks.preRender.push((()=>{if(!$._charStack.length)return;let e=0;for(let t of $._charStack)e+=4*t.length;let t=a.device.createBuffer({size:e,usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST,mappedAtCreation:!0});new Float32Array(t.getMappedRange()).set($._charStack.flat()),t.unmap();let o=6*$._textStack.length*4,n=a.device.createBuffer({label:"textBuffer",size:o,usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST,mappedAtCreation:!0});new Float32Array(n.getMappedRange()).set($._textStack.flat()),n.unmap(),$._textBindGroup=a.device.createBindGroup({label:"msdf text bind group",layout:r,entries:[{binding:0,resource:{buffer:t}},{binding:1,resource:{buffer:n}}]})})),$._hooks.postRender.push((()=>{$._charStack.length=0,$._textStack.length=0}))}, 11/** 12 * q5-server.js 13 * @author quinton-ashley 14 * @license LGPL-3.0 15 */ 16function(t){try{e.CairoCanvas??=require("canvas"),e.JSDOM??=require("jsdom").JSDOM}catch(e){return void(t.exports=Q5)}e.window=new JSDOM("",{url:"http://localhost"}).window;{let t=Object.getOwnPropertyNames(window).concat(Object.getOwnPropertyNames(Object.getPrototypeOf(window)));for(let r of t)e[r]||Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(window,r));e.Event=window.Event}Q5._createNodeJSCanvas=function(){let e=CairoCanvas.createCanvas(...arguments),t=window.document.createElement("canvas");return new Proxy(e,{get:function(e,r){let a=r in e?e:t,o=a[r];return"function"==typeof o?o.bind(a):o},set:function(e,r,a){return r in e?e[r]=a:t[r]=a,!0}})},t.exports=Q5}(r);var o=t(r.exports);class n{constructor(e,t,r,a){this.p5=e,this.size=2,this.pos=this.p5.createVector(this.p5.random(this.size,window.innerWidth-this.size),this.p5.random(this.size,window.innerHeight-this.size)),this.statesearch=t.copy(),this.stateresult=r.copy(),this.vel=o.Vector.random2D(),this.acc=this.p5.createVector(),this.hue=a%100,this.colorChroma=.04,this._colorChroma=this.colorChroma,this.colorLightness=.89,this._colorLightness=this.colorLightness,this.state=0,this.maxSpeed=6,this.maxForce=2}draw(){const e=this.p5;e.push(),e.colorMode("oklch",255),e.noStroke(),e.fill(e.color(this._colorLightness,this._colorChroma,this.hue)),e.ellipse(this.pos.x,this.pos.y,this.size*this.state==8?1:2),e.pop()}behaviors(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;if(this.state=e,0===e)return;const t=4===e?this.seek(this.statesearch):this.seek(this.stateresult);this.applyForce(t),this.colorChroma=8===e?.02:.04,this.colorLightness=8===e?.93:4===e?.91:.89}seek(e){const t=o.Vector.sub(e,this.pos);let r=this.maxSpeed;const a=t.mag();a<100&&(r=this.p5.map(a,0,100,0,this.maxSpeed)),t.setMag(r);return o.Vector.sub(t,this.vel)}strokeLine(e){if(!(arguments.length>1&&void 0!==arguments[1]&&arguments[1]))return;const{p5:t,vel:r,pos:{x:a,y:n}}=this;(t.abs(r.x)<.1||t.abs(r.y)<.1)&&(this.vel=o.Vector.random2D()),t.push(),t.stroke("#dddddd"),e.forEach((e=>{const r=o.Vector.dist(this.pos,e.pos);r<65&&r>55&&(t.colorMode("oklch",255),t.stroke(t.color(this._colorLightness,this._colorChroma,this.hue)),t.line(a,n,e.pos.x,e.pos.y))})),t.pop()}edges(){const{pos:{x:e,y:t},p5:{width:r,height:a},size:o}=this;(e>r-o||e<o)&&(this.vel.x*=-1),(t>a-o||t<o)&&(this.vel.y*=-1)}applyForce(e){this.acc.add(e)}update(){this.draw(),this.edges(),this._colorChroma=this._colorChroma+(this.colorChroma>this._colorChroma?.005:-.005),Math.abs(this.colorChroma-this._colorChroma)<.05&&(this._colorChroma=this.colorChroma),this._colorLightness=this._colorLightness+(this.colorLightness>this._colorLightness?.01:-.01),Math.abs(this.colorLightness-this._colorLightness)<.05&&(this._colorLightness=this.colorLightness),this.hue+=1,this.hue>100&&(this.hue-=100),this.pos.add(this.vel),this.vel.add(this.acc),this.acc.mult(0)}}window.sin=Math.sin,window.cos=Math.cos;const i=e=>{let t;const r=[];let a,o;window._setAnimState=e=>{switch(e.toLowerCase()){case"search":return t=4;case"result":return t=8;default:return t=0}},e.setup=()=>{a=e.windowWidth,o=e.windowHeight;e.createCanvas(a,o).parent("app"),e.fill("#f3f3f3");const t=180,i=window.innerWidth,s=i>950?704:608,l=i>950?224:i>650?96:i>420?64:32,d=Math.min(s,i-l),c=(i-d)/2-t,h=i-(i-d)/2+t,u=window.innerHeight,p=i>650?113:62,f=(u-p)/2-32-t,_=u-(u-p)/2-32+t,g=(e,t,r,a)=>({x:Math.random()*(r-e)+e,y:Math.random()*(a-t)+t});for(let t=0;t<200;t++){const o=g(c,f,h,_),i=e.createVector(o.x,o.y),s=e.createVector(t*a/200,50*e.cos(t/10)+80);r.push(new n(e,i,s,t))}},e.draw=()=>{window._firstTimer=performance.now(); 17 if (!window._firstDraw) { 18 window._firstDraw=function(){e.loop()}; // Hack calling Q5 draw if too late 19 setTimeout(() => { 20 if (performance.now() - window._firstTimer > 200) { 21 window._firstDraw(); 22 } 23 }, 250); 24 }e.background("#f3f3f3"),r.forEach(((a,o)=>{a.update(),a.strokeLine(r.slice(o),!e.mouseIsPressed),a.behaviors(t)}))}};var s;s=()=>{new o(i)},"complete"===document.readyState||"interactive"===document.readyState?setTimeout(s,1):document.addEventListener("DOMContentLoaded",s)}();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.