q5 2.2.1 → 2.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,7 +4,7 @@ A sequel to p5.js that's smaller, faster, and optimized for interactive art!
4
4
 
5
5
  **q5.js** implements all of [p5][]'s 2D drawing, math, and user input functionality.
6
6
 
7
- It's a drop-in replacement that's ~70x smaller than p5, while packing exclusive new features: HDR color support, modular use, top-level global mode, namespace mode, text image caching, dimension agnostic mode, and more.
7
+ It's a drop-in replacement that's 98% smaller than p5, while packing exclusive new features: HDR color support, modular use, top-level global mode, namespace mode, text image caching, dimension agnostic mode, and more.
8
8
 
9
9
  ## Typical Use
10
10
 
@@ -339,13 +339,13 @@ Unminified:
339
339
 
340
340
  - p5.js **5112kb** ⚠️
341
341
  - p5.sound.js 488kb
342
- - q5.js 74kb
342
+ - q5.js 83kb
343
343
 
344
344
  Minified:
345
345
 
346
346
  - p5.min.js 1034kb ⚠️
347
347
  - p5.sound.min.js 200kb
348
- - q5.min.js **48kb** 🎉
348
+ - q5.min.js **54kb** 🎉
349
349
 
350
350
  ## Benchmarks
351
351
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q5",
3
- "version": "2.2.1",
3
+ "version": "2.2.3",
4
4
  "description": "A sequel to p5.js that's smaller and faster",
5
5
  "author": "quinton-ashley",
6
6
  "contributors": [
package/q5-q2d.js CHANGED
@@ -239,7 +239,7 @@ function Q5(scope, parent, renderer) {
239
239
  raf($._draw);
240
240
  }
241
241
 
242
- if ((arguments.length && scope != 'namespace') || preloadDefined) {
242
+ if ((arguments.length && scope != 'namespace' && renderer != 'webgpu') || preloadDefined) {
243
243
  $.preload();
244
244
  _start();
245
245
  } else {
@@ -551,7 +551,12 @@ Q5.renderers.q2d.canvas = ($, q) => {
551
551
  $.ctx.lineWidth = n || 0.0001;
552
552
  };
553
553
  $.noStroke = () => ($._doStroke = false);
554
- $.clear = () => $.ctx.clearRect(0, 0, $.canvas.width, $.canvas.height);
554
+ $.clear = () => {
555
+ $.ctx.save();
556
+ $.ctx.resetTransform();
557
+ $.ctx.clearRect(0, 0, $.canvas.width, $.canvas.height);
558
+ $.ctx.restore();
559
+ };
555
560
 
556
561
  // DRAWING MATRIX
557
562
 
@@ -717,15 +722,17 @@ Q5.renderers.q2d.drawing = ($) => {
717
722
  // DRAWING
718
723
 
719
724
  $.background = function (c) {
720
- if (c.canvas) return $.image(c, 0, 0, $.width, $.height);
721
725
  $.ctx.save();
722
726
  $.ctx.resetTransform();
723
- if (Q5.Color) {
724
- if (!c._q5Color && typeof c != 'string') c = $.color(...arguments);
725
- else if ($._namedColors[c]) c = $.color(...$._namedColors[c]);
727
+ if (c.canvas) $.image(c, 0, 0, $.width, $.height);
728
+ else {
729
+ if (Q5.Color) {
730
+ if (!c._q5Color && typeof c != 'string') c = $.color(...arguments);
731
+ else if ($._namedColors[c]) c = $.color(...$._namedColors[c]);
732
+ }
733
+ $.ctx.fillStyle = c.toString();
734
+ $.ctx.fillRect(0, 0, $.canvas.width, $.canvas.height);
726
735
  }
727
- $.ctx.fillStyle = c.toString();
728
- $.ctx.fillRect(0, 0, $.canvas.width, $.canvas.height);
729
736
  $.ctx.restore();
730
737
  };
731
738
 
@@ -1904,13 +1911,20 @@ Q5.modules.color = ($, q) => {
1904
1911
  c0 = parseInt(c0.slice(1, 3), 16);
1905
1912
  }
1906
1913
  } else if ($._namedColors[c0]) {
1907
- c0 = $._namedColors[c0];
1914
+ [c0, c1, c2, c3] = $._namedColors[c0];
1908
1915
  } else {
1909
1916
  console.error(
1910
1917
  "q5 can't parse color: " + c0 + '\nOnly numeric input, hex, and common named colors are supported.'
1911
1918
  );
1912
1919
  return new C(0, 0, 0);
1913
1920
  }
1921
+
1922
+ if ($._colorFormat == 1) {
1923
+ c0 /= 255;
1924
+ if (c1) c1 /= 255;
1925
+ if (c2) c2 /= 255;
1926
+ if (c3) c3 /= 255;
1927
+ }
1914
1928
  }
1915
1929
  if (Array.isArray(c0)) {
1916
1930
  c1 = c0[1];
@@ -1920,13 +1934,6 @@ Q5.modules.color = ($, q) => {
1920
1934
  }
1921
1935
  }
1922
1936
 
1923
- if ($._colorFormat == 1) {
1924
- c0 /= 255;
1925
- if (c1) c1 /= 255;
1926
- if (c2) c2 /= 255;
1927
- if (c3) c3 /= 255;
1928
- }
1929
-
1930
1937
  if (c2 == undefined) return new C(c0, c0, c0, c1);
1931
1938
  return new C(c0, c1, c2, c3);
1932
1939
  };
@@ -1936,8 +1943,29 @@ Q5.modules.color = ($, q) => {
1936
1943
  $.blue = (c) => c.b;
1937
1944
  $.alpha = (c) => c.a;
1938
1945
  $.lightness = (c) => {
1946
+ if ($._colorMode == 'oklch') return c.l;
1939
1947
  return ((0.2126 * c.r + 0.7152 * c.g + 0.0722 * c.b) * 100) / 255;
1940
1948
  };
1949
+ $.hue = (c) => {
1950
+ if ($._colorMode == 'oklch') return c.h;
1951
+ let r = c.r;
1952
+ let g = c.g;
1953
+ let b = c.b;
1954
+ if ($._colorFormat == 255) {
1955
+ r /= 255;
1956
+ g /= 255;
1957
+ b /= 255;
1958
+ }
1959
+ let max = Math.max(r, g, b);
1960
+ let min = Math.min(r, g, b);
1961
+ let h;
1962
+ if (max == min) h = 0;
1963
+ else if (max == r) h = (60 * (g - b)) / (max - min);
1964
+ else if (max == g) h = (60 * (b - r)) / (max - min) + 120;
1965
+ else h = (60 * (r - g)) / (max - min) + 240;
1966
+ if (h < 0) h += 360;
1967
+ return h;
1968
+ };
1941
1969
 
1942
1970
  $.lerpColor = (a, b, t) => {
1943
1971
  if ($._colorMode == 'rgb') {
@@ -2392,33 +2420,21 @@ Q5.modules.math = ($, q) => {
2392
2420
  $.norm = (value, start, stop) => $.map(value, start, stop, 0, 1);
2393
2421
  $.sq = (x) => x * x;
2394
2422
  $.fract = (x) => x - Math.floor(x);
2395
- $.sin = (a) => {
2396
- if ($._angleMode == 'degrees') a = $.radians(a);
2397
- return Math.sin(a);
2398
- };
2399
- $.cos = (a) => {
2400
- if ($._angleMode == 'degrees') a = $.radians(a);
2401
- return Math.cos(a);
2402
- };
2403
- $.tan = (a) => {
2404
- if ($._angleMode == 'degrees') a = $.radians(a);
2405
- return Math.tan(a);
2406
- };
2407
- $.asin = (x) => {
2408
- let a = Math.asin(x);
2409
- if ($._angleMode == 'degrees') a = $.degrees(a);
2410
- return a;
2411
- };
2412
- $.acos = (x) => {
2413
- let a = Math.acos(x);
2414
- if ($._angleMode == 'degrees') a = $.degrees(a);
2415
- return a;
2416
- };
2417
- $.atan = (x) => {
2418
- let a = Math.atan(x);
2419
- if ($._angleMode == 'degrees') a = $.degrees(a);
2420
- return a;
2421
- };
2423
+
2424
+ for (let fn of ['sin', 'cos', 'tan']) {
2425
+ $[fn] = (a) => {
2426
+ if ($._angleMode == 'degrees') a = $.radians(a);
2427
+ return Math[fn](a);
2428
+ };
2429
+ }
2430
+
2431
+ for (let fn of ['asin', 'acos', 'atan']) {
2432
+ $[fn] = (x) => {
2433
+ let a = Math[fn](x);
2434
+ if ($._angleMode == 'degrees') a = $.degrees(a);
2435
+ return a;
2436
+ };
2437
+ }
2422
2438
  $.atan2 = (y, x) => {
2423
2439
  let a = Math.atan2(y, x);
2424
2440
  if ($._angleMode == 'degrees') a = $.degrees(a);
package/q5-q2d.min.js CHANGED
@@ -5,4 +5,4 @@
5
5
  * @license LGPL-3.0
6
6
  * @class Q5
7
7
  */
8
- function Q5(e,t,o){let a,r=this;if(r._q5=!0,r._parent=t,r._renderer=o||"q2d",r._preloadCount=0,e??="global","auto"==e){if(!window.setup&&!window.draw)return;e="global"}r._scope=e,"global"==e&&(Q5._hasGlobal=r._isGlobal=!0,a=Q5._nodejs?global:window);let n=new Proxy(r,{set:(e,t,o)=>(r[t]=o,r._isGlobal&&(a[t]=o),!0)});r.canvas=r.ctx=r.drawingContext=null,r.pixels=[];let s=null;r.frameCount=0,r.deltaTime=16,r._targetFrameRate=0,r._targetFrameDuration=16.666666666666668,r._frameRate=r._fps=60,r._loop=!0,r._hooks={postCanvas:[],preRender:[]};let i=0;r.millis=()=>performance.now()-i,r.noCanvas=()=>{r.canvas?.remove&&r.canvas.remove(),r.canvas=0,n.ctx=n.drawingContext=0},window&&(r.windowWidth=window.innerWidth,r.windowHeight=window.innerHeight,r.deviceOrientation=window.screen?.orientation?.type),r._incrementPreload=()=>n._preloadCount++,r._decrementPreload=()=>n._preloadCount--,r._draw=e=>{let t=e||performance.now();if(r._lastFrameTime??=t-r._targetFrameDuration,r._shouldResize&&(r.windowResized(),r._shouldResize=!1),r._loop)s=c(r._draw);else if(r.frameCount&&!r._redraw)return;if(s&&r.frameCount){if(t-r._lastFrameTime<r._targetFrameDuration-4)return}n.deltaTime=t-r._lastFrameTime,r._frameRate=1e3/r.deltaTime,n.frameCount++;let o=performance.now();r.ctx&&r.resetMatrix(),r._beginRender&&r._beginRender();for(let e of Q5.methods.pre)e.call(r);r.draw(),r._render&&r._render();for(let e of Q5.methods.post)e.call(r);r._finishRender&&r._finishRender(),n.pmouseX=r.mouseX,n.pmouseY=r.mouseY,r._lastFrameTime=t;let a=performance.now();r._fps=Math.round(1e3/(a-o))},r.noLoop=()=>{r._loop=!1,s=null},r.loop=()=>{r._loop=!0,null==s&&r._draw()},r.isLooping=()=>r._loop,r.redraw=(e=1)=>{r._redraw=!0;for(let t=0;t<e;t++)r._draw();r._redraw=!1},r.remove=()=>{r.noLoop(),r.canvas.remove()},r.frameRate=e=>(e&&(r._targetFrameRate=e,r._targetFrameDuration=1e3/e),r._frameRate),r.getTargetFrameRate=()=>r._targetFrameRate,r.getFPS=()=>r._fps,r.Element=function(e){this.elt=e},r._elements=[],r.TWO_PI=r.TAU=2*Math.PI,r.log=r.print=console.log,r.describe=()=>{};for(let e in Q5.modules)Q5.modules[e](r,n);let l=Q5.renderers[r._renderer];for(let e in l)l[e](r,n);for(let e in Q5)"_"!=e[1]&&e[1]==e[1].toUpperCase()&&(r[e]=Q5[e]);if("graphics"==e)return;"global"==e&&(Object.assign(Q5,r),delete Q5.Q5);for(let e of Q5.methods.init)e.call(r);for(let[e,t]of Object.entries(Q5.prototype))"_"!=e[0]&&"function"==typeof r[e]&&(r[e]=t.bind(r));if("global"==e){let e=Object.getOwnPropertyNames(r);for(let t of e)"_"!=t[0]&&(a[t]=r[t])}"function"==typeof e&&e(r),Q5._instanceCount++;let c=window.requestAnimationFrame||function(e){const t=r._lastFrameTime+r._targetFrameDuration;return setTimeout((()=>{e(t)}),t-performance.now())},d=a||r;r._isTouchAware=d.touchStarted||d.touchMoved||d.mouseReleased;let h=d.preload,u=["setup","draw","preload","mouseMoved","mousePressed","mouseReleased","mouseDragged","mouseClicked","keyPressed","keyReleased","keyTyped","touchStarted","touchMoved","touchEnded","windowResized"];for(let e of u)d[e]?r._isGlobal&&(r[e]=()=>{try{return d[e]()}catch(e){r._aiErrorAssistance?r._aiErrorAssistance(e):console.error(e)}}):r[e]=()=>{};async function _(){if(r._startDone=!0,r._preloadCount>0)return c(_);i=performance.now(),await r.setup(),r.frameCount||(null===r.ctx&&r.createCanvas(100,100),r._setupDone=!0,r.ctx&&r.resetMatrix(),c(r._draw))}(r.setup||r.draw)&&(arguments.length&&"namespace"!=e||h?(r.preload(),_()):(d.preload=r.preload=()=>{r._startDone||_()},setTimeout(r.preload,32)))}Q5.renderers={},Q5.modules={},Q5._nodejs="object"==typeof process,Q5._instanceCount=0,Q5._friendlyError=(e,t)=>{throw Error(t+": "+e)},Q5._validateParameters=()=>!0,Q5.methods={init:[],pre:[],post:[],remove:[]},Q5.prototype.registerMethod=(e,t)=>Q5.methods[e].push(t),Q5.prototype.registerPreloadMethod=(e,t)=>Q5.prototype[e]=t[e],Q5._nodejs?global.p5??=global.Q5=Q5:"object"==typeof window?window.p5??=window.Q5=Q5:global.window=0,"object"==typeof document&&document.addEventListener("DOMContentLoaded",(()=>{Q5._hasGlobal||new Q5("auto")})),Q5.modules.canvas=(e,t)=>{e._OffscreenCanvas=window.OffscreenCanvas||function(){return document.createElement("canvas")},Q5._nodejs?Q5._createNodeJSCanvas&&(t.canvas=Q5._createNodeJSCanvas(100,100)):"image"!=e._scope&&"graphics"!=e._scope||(t.canvas=new e._OffscreenCanvas(100,100)),e.canvas||("object"==typeof document?(t.canvas=document.createElement("canvas"),e.canvas.id="q5Canvas"+Q5._instanceCount,e.canvas.classList.add("q5Canvas")):e.noCanvas());let o=e.canvas;if(o.width=e.width=100,o.height=e.height=100,"image"!=e._scope&&(o.renderer=e._renderer,o[e._renderer]=!0),e._pixelDensity=1,e._adjustDisplay=()=>{o.style&&(o.style.width=o.w+"px",o.style.height=o.h+"px")},e.createCanvas=function(t,a,r){r??=arguments[3];let n=Object.assign({},Q5.canvasOptions);if("object"==typeof r&&Object.assign(n,r),"image"!=e._scope){let t=e.displayDensity();"graphics"==e._scope?t=this._pixelDensity:window.IntersectionObserver&&new IntersectionObserver((e=>{o.visible=e[0].isIntersecting})).observe(o),e._pixelDensity=Math.ceil(t)}e._setCanvasSize(t,a),Object.assign(o,n);let s=e._createCanvas(o.w,o.h,n);if(e._hooks)for(let t of e._hooks.postCanvas)t();return s},e._save=async(e,t,o)=>{if(t=t||"untitled","jpg"==(o=o||"png")||"png"==o||"webp"==o)if(e instanceof OffscreenCanvas){const t=await e.convertToBlob({type:"image/"+o});e=await new Promise((e=>{const o=new FileReader;o.onloadend=()=>e(o.result),o.readAsDataURL(t)}))}else e=e.toDataURL("image/"+o);else{let t="text/plain";"json"==o&&("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+"."+o,a.click(),URL.revokeObjectURL(a.href)},e.save=(t,o,a)=>{if((!t||"string"==typeof t&&(!o||!a&&o.length<5))&&(a=o,o=t,t=e.canvas),a)return e._save(t,o,a);o?(o=o.split("."),e._save(t,o[0],o.at(-1))):e._save(t)},e._setCanvasSize=(a,r)=>{a??=window.innerWidth,r??=window.innerHeight,o.w=a=Math.ceil(a),o.h=r=Math.ceil(r),o.hw=a/2,o.hh=r/2,o.width=Math.ceil(a*e._pixelDensity),o.height=Math.ceil(r*e._pixelDensity),e._da?e.flexibleCanvas(e._dau):(t.width=a,t.height=r),e.displayMode&&!o.displayMode?e.displayMode():e._adjustDisplay()},"image"!=e._scope){if(o&&"graphics"!=e._scope){function a(){let t=e._parent;t??=document.getElementsByTagName("main")[0],t||(t=document.createElement("main"),document.body.append(t)),o.parent(t)}o.parent=t=>{function a(){e.frameCount>1&&(e._shouldResize=!0,e._adjustDisplay())}o.parentElement&&o.parentElement.removeChild(o),"string"==typeof t&&(t=document.getElementById(t)),t.append(o),"function"==typeof ResizeObserver?(e._ro&&e._ro.disconnect(),e._ro=new ResizeObserver(a),e._ro.observe(t)):e.frameCount||window.addEventListener("resize",a)},document.body?a():document.addEventListener("DOMContentLoaded",a)}e.resizeCanvas=(t,a)=>{if(!e.ctx)return e.createCanvas(t,a);t==o.w&&a==o.h||e._resizeCanvas(t,a)},e.canvas.resize=e.resizeCanvas,e.canvas.save=e.saveCanvas=e.save,e.displayDensity=()=>window.devicePixelRatio,e.pixelDensity=t=>t&&t!=e._pixelDensity?(e._pixelDensity=t,e._setCanvasSize(o.w,o.h),t):e._pixelDensity,e.flexibleCanvas=(a=400)=>{a?(e._da=o.width/(a*e._pixelDensity),t.width=e._dau=a,t.height=o.h/o.w*a):e._da=0}}},Q5.canvasOptions={alpha:!1,colorSpace:"display-p3"},window.matchMedia&&matchMedia("(dynamic-range: high) and (color-gamut: p3)").matches?Q5.supportsHDR=!0:Q5.canvasOptions.colorSpace="srgb",Q5.renderers.q2d={},Q5.renderers.q2d.canvas=(e,t)=>{let o=e.canvas;e.colorMode&&e.colorMode("rgb","integer"),e._createCanvas=function(a,r,n){return t.ctx=t.drawingContext=o.getContext("2d",n),"image"!=e._scope&&(e.ctx.fillStyle="white",e.ctx.strokeStyle="black",e.ctx.lineCap="round",e.ctx.lineJoin="miter",e.ctx.textAlign="left"),e.ctx.scale(e._pixelDensity,e._pixelDensity),e.ctx.save(),o},"image"!=e._scope&&(e._resizeCanvas=(t,a)=>{let r={};for(let t in e.ctx)"function"!=typeof e.ctx[t]&&(r[t]=e.ctx[t]);delete r.canvas;let n=new e._OffscreenCanvas(o.width,o.height);n.w=o.w,n.h=o.h,n.getContext("2d").drawImage(o,0,0),e._setCanvasSize(t,a);for(let t in r)e.ctx[t]=r[t];e.scale(e._pixelDensity),e.ctx.drawImage(n,0,0,n.w,n.h)},e.fill=function(t){if(e._doFill=!0,e._fillSet=!0,Q5.Color&&(t._q5Color||"string"==typeof t?e._namedColors[t]&&(t=e.color(...e._namedColors[t])):t=e.color(...arguments),t.a<=0))return e._doFill=!1;e.ctx.fillStyle=t.toString()},e.noFill=()=>e._doFill=!1,e.stroke=function(t){if(e._doStroke=!0,e._strokeSet=!0,Q5.Color&&(t._q5Color||"string"==typeof t?e._namedColors[t]&&(t=e.color(...e._namedColors[t])):t=e.color(...arguments),t.a<=0))return e._doStroke=!1;e.ctx.strokeStyle=t.toString()},e.strokeWeight=t=>{t||(e._doStroke=!1),e._da&&(t*=e._da),e.ctx.lineWidth=t||1e-4},e.noStroke=()=>e._doStroke=!1,e.clear=()=>e.ctx.clearRect(0,0,e.canvas.width,e.canvas.height),e.translate=(t,o)=>{e._da&&(t*=e._da,o*=e._da),e.ctx.translate(t,o)},e.rotate=t=>{"degrees"==e._angleMode&&(t=e.radians(t)),e.ctx.rotate(t)},e.scale=(t,o)=>{o??=t,e.ctx.scale(t,o)},e.opacity=t=>e.ctx.globalAlpha=t,e.applyMatrix=(t,o,a,r,n,s)=>e.ctx.transform(t,o,a,r,n,s),e.shearX=t=>e.ctx.transform(1,0,e.tan(t),1,0,0),e.shearY=t=>e.ctx.transform(1,e.tan(t),0,1,0,0),e.resetMatrix=()=>{e.ctx.resetTransform(),e.scale(e._pixelDensity)},e._styleNames=["_doStroke","_doFill","_strokeSet","_fillSet","_tint","_imageMode","_rectMode","_ellipseMode","_textFont","_textLeading","_leadingSet","_textSize","_textAlign","_textBaseline","_textStyle","_textWrap"],e._styles=[],e.push=e.pushMatrix=()=>{e.ctx.save();let t={};for(let o of e._styleNames)t[o]=e[o];e._styles.push(t)},e.pop=e.popMatrix=()=>{e.ctx.restore();let t=e._styles.pop();for(let o of e._styleNames)e[o]=t[o]},e.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},e.createGraphics=function(t,o,a){let r=new Q5("graphics");return a??={},a.alpha??=!0,a.colorSpace??=e.canvas.colorSpace,r.createCanvas.call(e,t,o,a),r},window&&"graphics"!=e._scope&&window.addEventListener("resize",(()=>{e._shouldResize=!0,t.windowWidth=window.innerWidth,t.windowHeight=window.innerHeight,t.deviceOrientation=window.screen?.orientation?.type})))},Q5.renderers.q2d.drawing=e=>{e.CHORD=0,e.PIE=1,e.OPEN=2,e.RADIUS="radius",e.CORNER="corner",e.CORNERS="corners",e.ROUND="round",e.SQUARE="butt",e.PROJECT="square",e.MITER="miter",e.BEVEL="bevel",e.CLOSE=1,e.CENTER="center",e.LEFT="left",e.RIGHT="right",e.TOP="top",e.BOTTOM="bottom",e.LANDSCAPE="landscape",e.PORTRAIT="portrait",e.BLEND="source-over",e.REMOVE="destination-out",e.ADD="lighter",e.DARKEST="darken",e.LIGHTEST="lighten",e.DIFFERENCE="difference",e.SUBTRACT="subtract",e.EXCLUSION="exclusion",e.MULTIPLY="multiply",e.SCREEN="screen",e.REPLACE="copy",e.OVERLAY="overlay",e.HARD_LIGHT="hard-light",e.SOFT_LIGHT="soft-light",e.DODGE="color-dodge",e.BURN="color-burn",e._doStroke=!0,e._doFill=!0,e._strokeSet=!1,e._fillSet=!1,e._ellipseMode=e.CENTER,e._rectMode=e.CORNER,e._curveDetail=20,e._curveAlpha=0;let t=!0,o=[];function a(){e._doFill&&e.ctx.fill(),e._doStroke&&e.ctx.stroke()}function r(t,o,r,n,s,i,l,c){if(!e._doFill&&!e._doStroke)return;let d="degrees"==e._angleMode,h=d?360:e.TAU;if((s%=h)<0&&(s+=h),(i%=h)<0&&(i+=h),0!=s||0!=i){if(s>i&&([s,i]=[i,s]),e.ctx.beginPath(),r==n)d&&(s=e.radians(s),i=e.radians(i)),e.ctx.arc(t,o,r/2,s,i);else{for(let a=0;a<c+1;a++){let l=a/c,d=e.lerp(s,i,l),h=e.cos(d)*r/2,u=e.sin(d)*n/2;e.ctx[a?"lineTo":"moveTo"](t+h,o+u)}l==e.CHORD?e.ctx.closePath():l==e.PIE&&(e.ctx.lineTo(t,o),e.ctx.closePath())}a()}}function n(t,o,r,n){(e._doFill||e._doStroke)&&(e._da&&(t*=e._da,o*=e._da,r*=e._da,n*=e._da),e.ctx.beginPath(),e.ctx.ellipse(t,o,r/2,n/2,0,0,e.TAU),a())}function s(t,o,r,n,i,l,c,d){if(e._doFill||e._doStroke){if(void 0===i)return function(t,o,r,n){e._da&&(t*=e._da,o*=e._da,r*=e._da,n*=e._da),e.ctx.beginPath(),e.ctx.rect(t,o,r,n),a()}(t,o,r,n);if(void 0===l)return s(t,o,r,n,i,i,i,i);e._da&&(t*=e._da,o*=e._da,r*=e._da,n*=e._da,i*=e._da,l*=e._da,d*=e._da,c*=e._da),e.ctx.roundRect(t,o,r,n,[i,l,c,d]),a()}}e.blendMode=t=>e.ctx.globalCompositeOperation=t,e.strokeCap=t=>e.ctx.lineCap=t,e.strokeJoin=t=>e.ctx.lineJoin=t,e.ellipseMode=t=>e._ellipseMode=t,e.rectMode=t=>e._rectMode=t,e.curveDetail=t=>e._curveDetail=t,e.curveAlpha=t=>e._curveAlpha=t,e.curveTightness=t=>e._curveAlpha=t,e.background=function(t){if(t.canvas)return e.image(t,0,0,e.width,e.height);e.ctx.save(),e.ctx.resetTransform(),Q5.Color&&(t._q5Color||"string"==typeof t?e._namedColors[t]&&(t=e.color(...e._namedColors[t])):t=e.color(...arguments)),e.ctx.fillStyle=t.toString(),e.ctx.fillRect(0,0,e.canvas.width,e.canvas.height),e.ctx.restore()},e.line=(t,o,a,r)=>{e._doStroke&&(e._da&&(t*=e._da,o*=e._da,a*=e._da,r*=e._da),e.ctx.beginPath(),e.ctx.moveTo(t,o),e.ctx.lineTo(a,r),e.ctx.stroke())},e.arc=(t,o,a,n,s,i,l,c=25)=>{if(s==i)return e.ellipse(t,o,a,n);l??=e.PIE,e._ellipseMode==e.CENTER?r(t,o,a,n,s,i,l,c):e._ellipseMode==e.RADIUS?r(t,o,2*a,2*n,s,i,l,c):e._ellipseMode==e.CORNER?r(t+a/2,o+n/2,a,n,s,i,l,c):e._ellipseMode==e.CORNERS&&r((t+a)/2,(o+n)/2,a-t,n-o,s,i,l,c)},e.ellipse=(t,o,a,r)=>{r??=a,e._ellipseMode==e.CENTER?n(t,o,a,r):e._ellipseMode==e.RADIUS?n(t,o,2*a,2*r):e._ellipseMode==e.CORNER?n(t+a/2,o+r/2,a,r):e._ellipseMode==e.CORNERS&&n((t+a)/2,(o+r)/2,a-t,r-o)},e.circle=(t,o,r)=>{e._ellipseMode==e.CENTER?(e._da&&(t*=e._da,o*=e._da,r*=e._da),e.ctx.beginPath(),e.ctx.arc(t,o,r/2,0,e.TAU),a()):e.ellipse(t,o,r,r)},e.point=(t,o)=>{t.x&&(o=t.y,t=t.x),e._da&&(t*=e._da,o*=e._da),e.ctx.save(),e.ctx.beginPath(),e.ctx.arc(t,o,e.ctx.lineWidth/2,0,e.TAU),e.ctx.fillStyle=e.ctx.strokeStyle,e.ctx.fill(),e.ctx.restore()},e.rect=(t,o,a,r=a,n,i,l,c)=>{e._rectMode==e.CENTER?s(t-a/2,o-r/2,a,r,n,i,l,c):e._rectMode==e.RADIUS?s(t-a,o-r,2*a,2*r,n,i,l,c):e._rectMode==e.CORNER?s(t,o,a,r,n,i,l,c):e._rectMode==e.CORNERS&&s(t,o,a-t,r-o,n,i,l,c)},e.square=(t,o,a,r,n,s,i)=>e.rect(t,o,a,a,r,n,s,i),e.beginShape=()=>{o=[],e.ctx.beginPath(),t=!0},e.beginContour=()=>{e.ctx.closePath(),o=[],t=!0},e.endContour=()=>{o=[],t=!0},e.vertex=(a,r)=>{e._da&&(a*=e._da,r*=e._da),o=[],t?e.ctx.moveTo(a,r):e.ctx.lineTo(a,r),t=!1},e.bezierVertex=(t,a,r,n,s,i)=>{e._da&&(t*=e._da,a*=e._da,r*=e._da,n*=e._da,s*=e._da,i*=e._da),o=[],e.ctx.bezierCurveTo(t,a,r,n,s,i)},e.quadraticVertex=(t,a,r,n)=>{e._da&&(t*=e._da,a*=e._da,r*=e._da,n*=e._da),o=[],e.ctx.quadraticCurveTo(t,a,r,n)},e.bezier=(t,o,a,r,n,s,i,l)=>{e.beginShape(),e.vertex(t,o),e.bezierVertex(a,r,n,s,i,l),e.endShape()},e.triangle=(t,o,a,r,n,s)=>{e.beginShape(),e.vertex(t,o),e.vertex(a,r),e.vertex(n,s),e.endShape(e.CLOSE)},e.quad=(t,o,a,r,n,s,i,l)=>{e.beginShape(),e.vertex(t,o),e.vertex(a,r),e.vertex(n,s),e.vertex(i,l),e.endShape(e.CLOSE)},e.endShape=t=>{o=[],t&&e.ctx.closePath(),a()},e.curveVertex=(a,r)=>{if(e._da&&(a*=e._da,r*=e._da),o.push([a,r]),o.length<4)return;let n=function(e,t,o,a,r,n,s,i,l,c){function d(e,t,o,a,r,n){let s=Math.pow(a-t,2)+Math.pow(r-o,2);return Math.pow(s,.5*n)+e}let h=[],u=d(0,e,t,o,a,c),_=d(u,o,a,r,n,c),p=d(_,r,n,s,i,c);for(let c=0;c<l;c++){let d=u+c/(l-1)*(_-u),g=[(u-d)/(u-0),(d-0)/(u-0),(_-d)/(_-u),(d-u)/(_-u),(p-d)/(p-_),(d-_)/(p-_),(_-d)/(_-0),(d-0)/(_-0),(p-d)/(p-u),(d-u)/(p-u)];for(let e=0;e<g.length;e+=2)isNaN(g[e])&&(g[e]=1,g[e+1]=0),isFinite(g[e])||(g[e]>0?(g[e]=1,g[e+1]=0):(g[e]=0,g[e+1]=1));let x=e*g[0]+o*g[1],m=t*g[0]+a*g[1],f=o*g[2]+r*g[3],y=a*g[2]+n*g[3],v=r*g[4]+s*g[5],w=n*g[4]+i*g[5],M=x*g[6]+f*g[7],C=m*g[6]+y*g[7],S=f*g[8]+v*g[9],b=y*g[8]+w*g[9],R=M*g[2]+S*g[3],Q=C*g[2]+b*g[3];h.push([R,Q])}return h}(...o.at(-4),...o.at(-3),...o.at(-2),...o.at(-1),e._curveDetail,e._curveAlpha);for(let o=0;o<n.length;o++)t?e.ctx.moveTo(...n[o]):e.ctx.lineTo(...n[o]),t=!1},e.curve=(t,o,a,r,n,s,i,l)=>{e.beginShape(),e.curveVertex(t,o),e.curveVertex(a,r),e.curveVertex(n,s),e.curveVertex(i,l),e.endShape()},e.curvePoint=(e,t,o,a,r)=>{const n=r*r*r,s=r*r;return e*(-.5*n+s-.5*r)+t*(1.5*n-2.5*s+1)+o*(-1.5*n+2*s+.5*r)+a*(.5*n-.5*s)},e.bezierPoint=(e,t,o,a,r)=>{const n=1-r;return Math.pow(n,3)*e+3*Math.pow(n,2)*r*t+3*n*Math.pow(r,2)*o+Math.pow(r,3)*a},e.curveTangent=(e,t,o,a,r)=>{const n=r*r;return e*(-3*n/2+2*r-.5)+t*(9*n/2-5*r)+o*(-9*n/2+4*r+.5)+a*(3*n/2-r)},e.bezierTangent=(e,t,o,a,r)=>{const n=1-r;return 3*a*Math.pow(r,2)-3*o*Math.pow(r,2)+6*o*n*r-6*t*n*r+3*t*Math.pow(n,2)-3*e*Math.pow(n,2)},e.erase=function(t=255,o=255){e.ctx.save(),e.ctx.globalCompositeOperation="destination-out",e.ctx.fillStyle=`rgba(0, 0, 0, ${t/255})`,e.ctx.strokeStyle=`rgba(0, 0, 0, ${o/255})`},e.noErase=function(){e.ctx.globalCompositeOperation="source-over",e.ctx.restore()},e.inFill=(t,o)=>{const a=e._pixelDensity;return e.ctx.isPointInPath(t*a,o*a)},e.inStroke=(t,o)=>{const a=e._pixelDensity;return e.ctx.isPointInStroke(t*a,o*a)}},Q5.renderers.q2d.image=(e,t)=>{Q5.Image??=class{constructor(e,t,o){let a=this;a._scope="image",a.canvas=a.ctx=a.drawingContext=null,a.pixels=[],Q5.modules.canvas(a,a);let r=Q5.renderers.q2d;for(let e of["canvas","image","soft_filters"])r[e]&&r[e](a,a);a.createCanvas(e,t,o),delete a.createCanvas,a._loop=!1}get w(){return this.width}get h(){return this.height}},e.createImage=(t,o,a)=>(a??={},a.alpha??=!0,a.colorSpace??=e.canvas.colorSpace||Q5.canvasOptions.colorSpace,new Q5.Image(t,o,a)),e.loadImage=function(o,a,r){if(o.canvas)return o;if("gif"==o.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 n=[...arguments].at(-1);r="object"==typeof n?n:null;let s=e.createImage(1,1,r);function i(e){s.resize(e.naturalWidth||e.width,e.naturalHeight||e.height),s.ctx.drawImage(e,0,0),t._preloadCount--,a&&a(s)}if(Q5._nodejs&&global.CairoCanvas)global.CairoCanvas.loadImage(o).then(i).catch((e=>{throw t._preloadCount--,e}));else{let e=new window.Image;e.src=o,e.crossOrigin="Anonymous",e._pixelDensity=1,e.onload=()=>i(e),e.onerror=e=>{throw t._preloadCount--,e}}return s},e.imageMode=t=>e._imageMode=t,e.image=(t,o,a,r,n,s=0,i=0,l,c)=>{let d=t.canvas||t;Q5._createNodeJSCanvas&&(d=d.context.canvas),r??=t.width||t.videoWidth,n??=t.height||t.videoHeight,"center"==e._imageMode&&(o-=.5*r,a-=.5*n),e._da&&(o*=e._da,a*=e._da,r*=e._da,n*=e._da,s*=e._da,i*=e._da,l*=e._da,c*=e._da);let h=t._pixelDensity||1;l?l*=h:l=d.width||d.videoWidth,c?c*=h:c=d.height||d.videoHeight,e.ctx.drawImage(d,s*h,i*h,l,c,o,a,r,n),e._tint&&(e.ctx.globalCompositeOperation="multiply",e.ctx.fillStyle=e._tint.toString(),e.ctx.fillRect(o,a,r,n),e.ctx.globalCompositeOperation="source-over")},e._tint=null;let o=null;e._softFilter=()=>{throw new Error("Load q5-2d-soft-filters.js to use software filters.")},e.filter=(t,o)=>{if(!e.ctx.filter)return e._softFilter(t,o);if("string"==typeof t)f=t;else if(t==Q5.GRAY)f="saturate(0%)";else if(t==Q5.INVERT)f="invert(100%)";else if(t==Q5.BLUR){let t=Math.ceil(o*e._pixelDensity)||1;f=`blur(${t}px)`}else{if(t!=Q5.THRESHOLD)return e._softFilter(t,o);{o??=.5;let e=Math.floor(.5/Math.max(o,1e-5)*100);f=`saturate(0%) brightness(${e}%) contrast(1000000%)`}}e.ctx.filter=f,e.ctx.drawImage(e.canvas,0,0,e.canvas.w,e.canvas.h),e.ctx.filter="none"},"image"==e._scope&&(e.resize=(t,o)=>{let a=new e._OffscreenCanvas(e.canvas.width,e.canvas.height);a.getContext("2d",{colorSpace:e.canvas.colorSpace}).drawImage(e.canvas,0,0),e._setCanvasSize(t,o),e.ctx.clearRect(0,0,e.canvas.width,e.canvas.height),e.ctx.drawImage(a,0,0,e.canvas.width,e.canvas.height)}),e.trim=()=>{let t=e._pixelDensity||1,o=e.canvas.width,a=e.canvas.height,r=e.ctx.getImageData(0,0,o,a).data,n=o,s=0,i=a,l=0,c=3;for(let e=0;e<a;e++)for(let t=0;t<o;t++)0!==r[c]&&(t<n&&(n=t),t>s&&(s=t),e<i&&(i=e),e>l&&(l=e)),c+=4;return i=Math.floor(i/t),l=Math.floor(l/t),n=Math.floor(n/t),s=Math.floor(s/t),e.get(n,i,s-n+1,l-i+1)},e.mask=t=>{e.ctx.save(),e.ctx.resetTransform();let o=e.ctx.globalCompositeOperation;e.ctx.globalCompositeOperation="destination-in",e.ctx.drawImage(t.canvas,0,0),e.ctx.globalCompositeOperation=o,e.ctx.restore()},e.get=(t,o,a,r)=>{let n=e._pixelDensity||1;if(void 0!==t&&void 0===a){let a=e.ctx.getImageData(t*n,o*n,1,1).data;return new e.Color(a[0],a[1],a[2],a[3]/255)}t=(t||0)*n,o=(o||0)*n;let s=a=a||e.width,i=r=r||e.height;a*=n,r*=n;let l=e.createImage(a,r),c=e.ctx.getImageData(t,o,a,r);return l.ctx.putImageData(c,0,0),l._pixelDensity=n,l.width=s,l.height=i,l},e.set=(t,o,a)=>{if(a.canvas){let r=e._tint;return e._tint=null,e.image(a,t,o),void(e._tint=r)}e.pixels.length||e.loadPixels();let r=e._pixelDensity||1;for(let n=0;n<r;n++)for(let s=0;s<r;s++){let i=4*((o*r+n)*e.canvas.width+t*r+s);e.pixels[i]=a.r??a.l,e.pixels[i+1]=a.g??a.c,e.pixels[i+2]=a.b??a.h,e.pixels[i+3]=a.a}},e.loadPixels=()=>{o=e.ctx.getImageData(0,0,e.canvas.width,e.canvas.height),t.pixels=o.data},e.updatePixels=()=>{null!=o&&e.ctx.putImageData(o,0,0)},e.smooth=()=>e.ctx.imageSmoothingEnabled=!0,e.noSmooth=()=>e.ctx.imageSmoothingEnabled=!1,"image"!=e._scope&&(e.tint=function(t){e._tint=t._q5Color?t:e.color(...arguments)},e.noTint=()=>e._tint=null)},Q5.THRESHOLD=1,Q5.GRAY=2,Q5.OPAQUE=3,Q5.INVERT=4,Q5.POSTERIZE=5,Q5.DILATE=6,Q5.ERODE=7,Q5.BLUR=8,Q5.renderers.q2d.soft_filters=e=>{let t=null;function o(){let o=e.canvas.width*e.canvas.height*4;t&&t.length==o||(t=new Uint8ClampedArray(o))}e._softFilter=(a,r)=>{e._filters||(e._filters=[],e._filters[Q5.THRESHOLD]=(e,t)=>{void 0===t?t=127.5:t*=255;for(let o=0;o<e.length;o+=4){const a=.2126*e[o]+.7152*e[o+1]+.0722*e[o+2];e[o]=e[o+1]=e[o+2]=a>=t?255:0}},e._filters[Q5.GRAY]=e=>{for(let t=0;t<e.length;t+=4){const o=.2126*e[t]+.7152*e[t+1]+.0722*e[t+2];e[t]=e[t+1]=e[t+2]=o}},e._filters[Q5.OPAQUE]=e=>{for(let t=0;t<e.length;t+=4)e[t+3]=255},e._filters[Q5.INVERT]=e=>{for(let t=0;t<e.length;t+=4)e[t]=255-e[t],e[t+1]=255-e[t+1],e[t+2]=255-e[t+2]},e._filters[Q5.POSTERIZE]=(e,t=4)=>{let o=t-1;for(let a=0;a<e.length;a+=4)e[a]=255*(e[a]*t>>8)/o,e[a+1]=255*(e[a+1]*t>>8)/o,e[a+2]=255*(e[a+2]*t>>8)/o},e._filters[Q5.DILATE]=a=>{o(),t.set(a);let[r,n]=[e.canvas.width,e.canvas.height];for(let e=0;e<n;e++)for(let o=0;o<r;o++){let s=4*Math.max(o-1,0),i=4*Math.min(o+1,r-1),l=4*Math.max(e-1,0)*r,c=4*Math.min(e+1,n-1)*r,d=4*e*r,h=4*o;for(let e=0;e<4;e++){let o=e+l,r=e+c,n=e+d;a[d+h+e]=Math.max(t[o+h],t[n+s],t[n+h],t[n+i],t[r+h])}}},e._filters[Q5.ERODE]=a=>{o(),t.set(a);let[r,n]=[e.canvas.width,e.canvas.height];for(let e=0;e<n;e++)for(let o=0;o<r;o++){let s=4*Math.max(o-1,0),i=4*Math.min(o+1,r-1),l=4*Math.max(e-1,0)*r,c=4*Math.min(e+1,n-1)*r,d=4*e*r,h=4*o;for(let e=0;e<4;e++){let o=e+l,r=e+c,n=e+d;a[d+h+e]=Math.min(t[o+h],t[n+s],t[n+h],t[n+i],t[r+h])}}},e._filters[Q5.BLUR]=(a,r)=>{r=r||1,r=Math.floor(r*e._pixelDensity),o(),t.set(a);let n=2*r+1,s=function(e){let t=new Float32Array(e),o=.3*r+.8,a=o*o*2;for(let r=0;r<e;r++){let n=r-e/2,s=Math.exp(-n*n/a)/(2.5066282746*o);t[r]=s}return t}(n),[i,l]=[e.canvas.width,e.canvas.height];for(let e=0;e<l;e++)for(let o=0;o<i;o++){let l=0,c=0,d=0,h=0;for(let a=0;a<n;a++){let n=4*(e*i+Math.min(Math.max(o-r+a,0),i-1));l+=t[n]*s[a],c+=t[n+1]*s[a],d+=t[n+2]*s[a],h+=t[n+3]*s[a]}let u=4*(e*i+o);a[u]=l,a[u+1]=c,a[u+2]=d,a[u+3]=h}t.set(a);for(let e=0;e<l;e++)for(let o=0;o<i;o++){let c=0,d=0,h=0,u=0;for(let a=0;a<n;a++){let n=4*(Math.min(Math.max(e-r+a,0),l-1)*i+o);c+=t[n]*s[a],d+=t[n+1]*s[a],h+=t[n+2]*s[a],u+=t[n+3]*s[a]}let _=4*(e*i+o);a[_]=c,a[_+1]=d,a[_+2]=h,a[_+3]=u}});let n=e.ctx.getImageData(0,0,e.canvas.width,e.canvas.height);e._filters[a](n.data,r),e.ctx.putImageData(n,0,0)}},Q5.renderers.q2d.text=(e,t)=>{e.NORMAL="normal",e.ITALIC="italic",e.BOLD="bold",e.BOLDITALIC="italic bold",e.CENTER="center",e.LEFT="left",e.RIGHT="right",e.TOP="top",e.BOTTOM="bottom",e.BASELINE="alphabetic",e._textFont="sans-serif",e._textSize=12,e._textLeading=15,e._textLeadDiff=3,e._textStyle="normal",e.loadFont=(e,o)=>{t._preloadCount++;let a=e.split("/").pop().split(".")[0].replace(" ",""),r=new FontFace(a,`url(${e})`);return document.fonts.add(r),r.load().then((()=>{t._preloadCount--,o&&o(a)})),a},e.textFont=t=>e._textFont=t,e.textSize=t=>{if(void 0===t)return e._textSize;e._da&&(t*=e._da),e._textSize=t,e._leadingSet||(e._textLeading=1.25*t,e._textLeadDiff=e._textLeading-t)},e.textLeading=t=>{if(void 0===t)return e._textLeading;e._da&&(t*=e._da),e._textLeading=t,e._textLeadDiff=t-e._textSize,e._leadingSet=!0},e.textStyle=t=>e._textStyle=t,e.textAlign=(t,o)=>{e.ctx.textAlign=t,o&&(e.ctx.textBaseline=o==e.CENTER?"middle":o)},e.textWidth=t=>(e.ctx.font=`${e._textStyle} ${e._textSize}px ${e._textFont}`,e.ctx.measureText(t).width),e.textAscent=t=>(e.ctx.font=`${e._textStyle} ${e._textSize}px ${e._textFont}`,e.ctx.measureText(t).actualBoundingBoxAscent),e.textDescent=t=>(e.ctx.font=`${e._textStyle} ${e._textSize}px ${e._textFont}`,e.ctx.measureText(t).actualBoundingBoxDescent),e._textCache=!!Q5.Image,e._TimedCache=class extends Map{constructor(){super(),this.maxSize=500}set(e,t){t.lastAccessed=Date.now(),super.set(e,t),this.size>this.maxSize&&this.gc()}get(e){const t=super.get(e);return t&&(t.lastAccessed=Date.now()),t}gc(){let e,t=1/0,o=0;for(const[a,r]of this.entries())r.lastAccessed<t&&(t=r.lastAccessed,e=o),o++;o=e;for(const t of this.keys()){if(0==o){e=t;break}o--}this.delete(e)}},e._tic=new e._TimedCache,e.textCache=(t,o)=>(o&&(e._tic.maxSize=o),void 0!==t&&(e._textCache=t),e._textCache),e._genTextImageKey=(t,o,a)=>t.slice(0,200)+e._textStyle+e._textSize+e._textFont+(e._doFill?e.ctx.fillStyle:"")+"_"+(e._doStroke&&e._strokeSet?e.ctx.lineWidth+e.ctx.strokeStyle+"_":"")+(o||"")+(a?"x"+a:""),e.createTextImage=(t,o,a)=>{let r=e._textCache;e._textCache=!0,e._genTextImage=!0,e.text(t,0,0,o,a),e._genTextImage=!1;let n=e._genTextImageKey(t,o,a);return e._textCache=r,e._tic.get(n)},e.text=(t,o,a,r,n)=>{if(void 0===t)return;if(t=t.toString(),e._da&&(o*=e._da,a*=e._da),!e._doFill&&!e._doStroke)return;let s,i,l,c,d,h,u,_,p=e.ctx.getTransform(),g=e._genTextImage||e._textCache&&(0!=p.b||0!=p.c);if(g){if(c=e._genTextImageKey(t,r,n),i=e._tic.get(c),i&&!e._genTextImage)return void e.textImage(i,o,a);l=e.createGraphics.call(e,1,1),s=l.ctx}else s=e.ctx,d=o,h=a;s.font=`${e._textStyle} ${e._textSize}px ${e._textFont}`;let x=t.split("\n");if(g){d=0,h=e._textLeading*x.length;let o=s.measureText(" ");u=o.fontBoundingBoxAscent,_=o.fontBoundingBoxDescent,n??=h+_,l.resizeCanvas(Math.ceil(s.measureText(t).width),Math.ceil(n)),s.fillStyle=e.ctx.fillStyle,s.strokeStyle=e.ctx.strokeStyle,s.lineWidth=e.ctx.lineWidth}let m=s.fillStyle;e._fillSet||(s.fillStyle="black");for(let t=0;t<x.length&&(e._doStroke&&e._strokeSet&&s.strokeText(x[t],d,h),e._doFill&&s.fillText(x[t],d,h),h+=e._textLeading,!(h>n));t++);e._fillSet||(s.fillStyle=m),g&&(i=l.get(),i._ascent=u,i._descent=_,e._tic.set(c,i),e._genTextImage||e.textImage(i,o,a))},e.textImage=(t,o,a)=>{let r=e._imageMode;e._imageMode="corner","center"==e.ctx.textAlign?o-=.5*t.width:"right"==e.ctx.textAlign&&(o-=t.width),"alphabetic"==e.ctx.textBaseline&&(a-=e._textLeading),"middle"==e.ctx.textBaseline?a-=t._descent+.5*t._ascent+e._textLeadDiff:"bottom"==e.ctx.textBaseline?a-=t._ascent+t._descent+e._textLeadDiff:"top"==e.ctx.textBaseline&&(a-=t._descent+e._textLeadDiff),e.image(t,o,a),e._imageMode=r},e.nf=(e,t,o)=>{let a=e<0,r=(e=Math.abs(e)).toFixed(o).split(".");r[0]=r[0].padStart(t,"0");let n=r.join(".");return a&&(n="-"+n),n}},Q5.modules.ai=e=>{e.askAI=(e="")=>{throw Error("Ask AI ✨ "+e)},e._aiErrorAssistance=async t=>{let o=t.message?.includes("Ask AI ✨");if(o||console.error(t),Q5.disableFriendlyErrors)return;!o&&Q5.errorTolerant||e.noLoop();let a=t.stack?.split("\n");if(!t.stack||a.length<=1)return;let r=1,n="(";for(-1==navigator.userAgent.indexOf("Chrome")&&(r=0,n="@");a[r].indexOf("q5.js:")>=0;)r++;let s=a[r].split(n).at(-1);s=s.split(":");let i=parseInt(s.at(-2));o&&i++;let l=s.slice(0,-2).join(":"),c=l.split("/").at(-1);try{let e=(await(await fetch(l)).text()).split("\n"),a=e[i-1].trim(),r="",n=1;for(;r.length<1600&&(i-n>=0&&(r=e[i-n].trim()+"\n"+r),i+n<e.length);)r+=e[i+n].trim()+"\n",n++;let s="https://chatgpt.com/?q=q5.js+"+(o&&t.message.length>10?t.message.slice(10):"Whats+wrong+with+this+line%3F+short+answer")+(o?"":"%0A%0A"+encodeURIComponent(t.name+": "+t.message))+"%0A%0ALine%3A+"+encodeURIComponent(a)+"%0A%0AExcerpt+for+context%3A%0A%0A"+encodeURIComponent(r);o||console.log("Error in "+c+" on line "+i+":\n\n"+a),console.warn("Ask AI ✨ "+s),o&&window.open(s,"_blank")}catch(e){}}},Q5.modules.color=(e,t)=>{e.RGB=e.RGBA=e._colorMode="rgb",e.OKLCH="oklch",e.colorMode=(o,a)=>{e._colorMode=o;let r="srgb"==e.canvas.colorSpace||"srgb"==o;if(a??=r?"integer":"float",e._colorFormat="float"==a||1==a?1:255,"oklch"==o)t.Color=Q5.ColorOKLCH;else{let o="srgb"==e.canvas.colorSpace;255==e._colorFormat?t.Color=o?Q5.ColorRGBA_8:Q5.ColorRGBA_P3_8:t.Color=o?Q5.ColorRGBA:Q5.ColorRGBA_P3,e._colorMode="rgb"}},e._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]},e.color=(t,o,a,r)=>{let n=e.Color;if(t._q5Color)return new n(...t.levels);if(null==o){if("string"==typeof t)if("#"==t[0])t.length<=5?(t.length>4&&(r=parseInt(t[4]+t[4],16)),a=parseInt(t[3]+t[3],16),o=parseInt(t[2]+t[2],16),t=parseInt(t[1]+t[1],16)):(t.length>7&&(r=parseInt(t.slice(7,9),16)),a=parseInt(t.slice(5,7),16),o=parseInt(t.slice(3,5),16),t=parseInt(t.slice(1,3),16));else{if(!e._namedColors[t])return console.error("q5 can't parse color: "+t+"\nOnly numeric input, hex, and common named colors are supported."),new n(0,0,0);t=e._namedColors[t]}Array.isArray(t)&&(o=t[1],a=t[2],r=t[3],t=t[0])}return 1==e._colorFormat&&(t/=255,o&&(o/=255),a&&(a/=255),r&&(r/=255)),null==a?new n(t,t,t,o):new n(t,o,a,r)},e.red=e=>e.r,e.green=e=>e.g,e.blue=e=>e.b,e.alpha=e=>e.a,e.lightness=e=>100*(.2126*e.r+.7152*e.g+.0722*e.b)/255,e.lerpColor=(t,o,a)=>{if("rgb"==e._colorMode)return new e.Color(e.constrain(e.lerp(t.r,o.r,a),0,255),e.constrain(e.lerp(t.g,o.g,a),0,255),e.constrain(e.lerp(t.b,o.b,a),0,255),e.constrain(e.lerp(t.a,o.a,a),0,255));{let r=o.h-t.h;r>180&&(r-=360),r<-180&&(r+=360);let n=t.h+a*r;return n<0&&(n+=360),n>360&&(n-=360),new e.Color(e.constrain(e.lerp(t.l,o.l,a),0,100),e.constrain(e.lerp(t.c,o.c,a),0,100),n,e.constrain(e.lerp(t.a,o.a,a),0,255))}}},Q5.Color=class{constructor(){this._q5Color=!0}},Q5.ColorOKLCH=class extends Q5.Color{constructor(e,t,o,a){super(),this.l=e,this.c=t,this.h=o,this.a=a??1}toString(){return`oklch(${this.l} ${this.c} ${this.h} / ${this.a})`}},Q5.ColorRGBA=class extends Q5.Color{constructor(e,t,o,a){super(),this.r=e,this.g=t,this.b=o,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})`}},Q5.ColorRGBA_P3=class extends Q5.ColorRGBA{toString(){return`color(display-p3 ${this.r} ${this.g} ${this.b} / ${this.a})`}},Q5.ColorRGBA_8=class extends Q5.ColorRGBA{constructor(e,t,o,a){super(e,t,o,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})`}},Q5.ColorRGBA_P3_8=class extends Q5.ColorRGBA{constructor(e,t,o,a){super(e,t,o,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),o=(this._b/255).toFixed(3),a=(this._a/255).toFixed(3);this._css=`color(display-p3 ${e} ${t} ${o} / ${a})`,this._edited=!1}return this._css}},Q5.modules.display=e=>{if(!e.canvas||"graphics"==e._scope)return;let t=e.canvas;0!=Q5._instanceCount||Q5._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;\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>"),e._adjustDisplay=()=>{let o=t.style,a=t.parentElement;o&&a&&t.displayMode&&("pixelated"==t.renderQuality&&(t.classList.add("q5-pixelated"),e.pixelDensity(1),e.noSmooth&&e.noSmooth(),e.textFont&&e.textFont("monospace")),"normal"==t.displayMode?(a.classList.remove("q5-centered","q5-maxed","q5-fullscreen"),o.width=t.w*t.displayScale+"px",o.height=t.h*t.displayScale+"px"):(a.classList.add("q5-"+t.displayMode),a=a.getBoundingClientRect(),t.w/t.h>a.width/a.height?("centered"==t.displayMode?(o.width=t.w*t.displayScale+"px",o.maxWidth="100%"):o.width="100%",o.height="auto",o.maxHeight=""):(o.width="auto",o.maxWidth="","centered"==t.displayMode?(o.height=t.h*t.displayScale+"px",o.maxHeight="100%"):o.height="100%")))},e.displayMode=(o="normal",a="default",r=1)=>{"string"==typeof r&&(r=parseFloat(r.slice(1))),Object.assign(t,{displayMode:o,renderQuality:a,displayScale:r}),e._adjustDisplay()},e.fullscreen=e=>{if(void 0===e)return document.fullscreenElement;e?document.body.requestFullscreen():document.body.exitFullscreen()}},Q5.modules.input=(e,t)=>{if("graphics"==e._scope)return;e.mouseX=0,e.mouseY=0,e.pmouseX=0,e.pmouseY=0,e.touches=[],e.mouseButton=null,e.keyIsPressed=!1,e.mouseIsPressed=!1,e.key=null,e.keyCode=null,e.UP_ARROW=38,e.DOWN_ARROW=40,e.LEFT_ARROW=37,e.RIGHT_ARROW=39,e.SHIFT=16,e.TAB=9,e.BACKSPACE=8,e.ENTER=e.RETURN=13,e.ALT=e.OPTION=18,e.CONTROL=17,e.DELETE=46,e.ESCAPE=27,e.ARROW="default",e.CROSS="crosshair",e.HAND="pointer",e.MOVE="move",e.TEXT="text";let o={},a=[e.LEFT,e.CENTER,e.RIGHT],r=e.canvas;function n(t){const o=e.canvas.getBoundingClientRect(),a=e.canvas.scrollWidth/e.width||1,r=e.canvas.scrollHeight/e.height||1;return{x:(t.clientX-o.left)/a,y:(t.clientY-o.top)/r,id:t.identifier}}if(e._startAudio=()=>{e.getAudioContext&&"suspended"==e.getAudioContext()?.state&&e.userStartAudio()},e._updateMouse=o=>{if(!o.changedTouches)if(r){let a=r.getBoundingClientRect(),n=r.scrollWidth/e.width||1,s=r.scrollHeight/e.height||1;t.mouseX=(o.clientX-a.left)/n,t.mouseY=(o.clientY-a.top)/s,"webgpu"==r.renderer&&(t.mouseX-=r.hw,t.mouseY-=r.hh)}else t.mouseX=o.clientX,t.mouseY=o.clientY},e._onmousedown=o=>{e._startAudio(),e._updateMouse(o),t.mouseIsPressed=!0,t.mouseButton=a[o.button],e.mousePressed(o)},e._onmousemove=t=>{e._updateMouse(t),e.mouseIsPressed?e.mouseDragged(t):e.mouseMoved(t)},e._onmouseup=o=>{e._updateMouse(o),t.mouseIsPressed=!1,e.mouseReleased(o)},e._onclick=o=>{e._updateMouse(o),t.mouseIsPressed=!0,e.mouseClicked(o),t.mouseIsPressed=!1},e.cursor=(t,o,a)=>{let r="";t.includes(".")&&(t=`url("${t}")`,r=", auto"),void 0!==o&&(t+=" "+o+" "+a),e.canvas.style.cursor=t+r},e.noCursor=()=>{e.canvas.style.cursor="none"},e.requestPointerLock=document.body?.requestPointerLock,e.exitPointerLock=document.exitPointerLock,e._onkeydown=a=>{a.repeat||(e._startAudio(),t.keyIsPressed=!0,t.key=a.key,t.keyCode=a.keyCode,o[e.keyCode]=o[e.key.toLowerCase()]=!0,e.keyPressed(a),1==a.key.length&&e.keyTyped(a))},e._onkeyup=a=>{t.keyIsPressed=!1,t.key=a.key,t.keyCode=a.keyCode,o[e.keyCode]=o[e.key.toLowerCase()]=!1,e.keyReleased(a)},e.keyIsDown=e=>!!o["string"==typeof e?e.toLowerCase():e],e._ontouchstart=o=>{e._startAudio(),t.touches=[...o.touches].map(n),e._isTouchAware||(t.mouseX=e.touches[0].x,t.mouseY=e.touches[0].y,t.mouseIsPressed=!0,t.mouseButton=e.LEFT,e.mousePressed(o)||o.preventDefault()),e.touchStarted(o)||o.preventDefault()},e._ontouchmove=o=>{t.touches=[...o.touches].map(n),e._isTouchAware||(t.mouseX=e.touches[0].x,t.mouseY=e.touches[0].y,e.mouseDragged(o)||o.preventDefault()),e.touchMoved(o)||o.preventDefault()},e._ontouchend=o=>{t.touches=[...o.touches].map(n),e._isTouchAware||e.touches.length||(t.mouseIsPressed=!1,e.mouseReleased(o)||o.preventDefault()),e.touchEnded(o)||o.preventDefault()},r&&(r.addEventListener("mousedown",(t=>e._onmousedown(t))),r.addEventListener("mouseup",(t=>e._onmouseup(t))),r.addEventListener("click",(t=>e._onclick(t))),r.addEventListener("touchstart",(t=>e._ontouchstart(t))),r.addEventListener("touchmove",(t=>e._ontouchmove(t))),r.addEventListener("touchcancel",(t=>e._ontouchend(t))),r.addEventListener("touchend",(t=>e._ontouchend(t)))),window){let t=window.addEventListener;t("mousemove",(t=>e._onmousemove(t)),!1),t("keydown",(t=>e._onkeydown(t)),!1),t("keyup",(t=>e._onkeyup(t)),!1)}},Q5.modules.math=(e,t)=>{function o(){let e,t,o=4294967295;return{setSeed(a){e=t=(a??Math.random()*o)>>>0},getSeed:()=>t,rand:()=>(e^=e<<17,e^=e>>13,e^=e<<5,(e>>>0)/o)}}e.DEGREES="degrees",e.RADIANS="radians",e.PI=Math.PI,e.HALF_PI=Math.PI/2,e.QUARTER_PI=Math.PI/4,e.abs=Math.abs,e.ceil=Math.ceil,e.exp=Math.exp,e.floor=Math.floor,e.loge=Math.log,e.mag=Math.hypot,e.max=Math.max,e.min=Math.min,e.round=Math.round,e.pow=Math.pow,e.sqrt=Math.sqrt,e.SHR3=1,e.LCG=2,e.angleMode=t=>e._angleMode=t,e._DEGTORAD=Math.PI/180,e._RADTODEG=180/Math.PI,e.degrees=t=>t*e._RADTODEG,e.radians=t=>t*e._DEGTORAD,e.map=Q5.prototype.map=(e,t,o,a,r,n)=>{let s=a+1*(e-t)/(o-t)*(r-a);return n?a<r?Math.min(Math.max(s,a),r):Math.min(Math.max(s,r),a):s},e.lerp=(e,t,o)=>e*(1-o)+t*o,e.constrain=(e,t,o)=>Math.min(Math.max(e,t),o),e.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])},e.norm=(t,o,a)=>e.map(t,o,a,0,1),e.sq=e=>e*e,e.fract=e=>e-Math.floor(e),e.sin=t=>("degrees"==e._angleMode&&(t=e.radians(t)),Math.sin(t)),e.cos=t=>("degrees"==e._angleMode&&(t=e.radians(t)),Math.cos(t)),e.tan=t=>("degrees"==e._angleMode&&(t=e.radians(t)),Math.tan(t)),e.asin=t=>{let o=Math.asin(t);return"degrees"==e._angleMode&&(o=e.degrees(o)),o},e.acos=t=>{let o=Math.acos(t);return"degrees"==e._angleMode&&(o=e.degrees(o)),o},e.atan=t=>{let o=Math.atan(t);return"degrees"==e._angleMode&&(o=e.degrees(o)),o},e.atan2=(t,o)=>{let a=Math.atan2(t,o);return"degrees"==e._angleMode&&(a=e.degrees(a)),a};let a=o();a.setSeed(),e.randomSeed=e=>a.setSeed(e),e.random=(e,t)=>void 0===e?a.rand():"number"==typeof e?void 0!==t?a.rand()*(t-e)+e:a.rand()*e:e[Math.trunc(e.length*a.rand())],e.randomGenerator=t=>{t==e.LCG?a=function(){const e=4294967296;let t,o;return{setSeed(a){o=t=(a??Math.random()*e)>>>0},getSeed:()=>t,rand:()=>(o=(1664525*o+1013904223)%e,o/e)}}():t==e.SHR3&&(a=o()),a.setSeed()};var r=new function(){var e,t,o,r=new Array(128),n=new Array(256),s=new Array(128),i=new Array(128),l=new Array(256),c=new Array(256),d=()=>4294967296*a.rand()-2147483648,h=()=>.5+2.328306e-10*(d()|0),u=()=>{for(var t,a,n,l,c=3.44262;;){if(t=o*s[e],0==e){do{n=h(),l=h(),t=.2904764*-Math.log(n),a=-Math.log(l)}while(a+a<t*t);return o>0?c+t:-c-t}if(i[e]+h()*(i[e-1]-i[e])<Math.exp(-.5*t*t))return t;if(o=d(),e=127&o,Math.abs(o)<r[e])return o*s[e]}},_=()=>{for(var o;;){if(0==e)return 7.69711-Math.log(h());if(o=t*l[e],c[e]+h()*(c[e-1]-c[e])<Math.exp(-o))return o;if((t=d())<n[e=255&t])return t*l[e]}};this.SHR3=d,this.UNI=h,this.RNOR=()=>(o=d(),e=127&o,Math.abs(o)<r[e]?o*s[e]:u()),this.REXP=()=>(t=d()>>>0)<r[e=255&t]?t*l[e]:_(),this.zigset=()=>{var e,t,o=2147483648,a=4294967296,d=3.442619855899,h=d,u=.00991256303526217,_=7.697117470131487,p=_,g=.003949659822581572;for(e=u/Math.exp(-.5*d*d),r[0]=Math.floor(d/e*o),r[1]=0,s[0]=e/o,s[127]=d/o,i[0]=1,i[127]=Math.exp(-.5*d*d),t=126;t>=1;t--)d=Math.sqrt(-2*Math.log(u/d+Math.exp(-.5*d*d))),r[t+1]=Math.floor(d/h*o),h=d,i[t]=Math.exp(-.5*d*d),s[t]=d/o;for(e=g/Math.exp(-_),n[0]=Math.floor(_/e*a),n[1]=0,l[0]=e/a,l[255]=_/a,c[0]=1,c[255]=Math.exp(-_),t=254;t>=1;t--)_=-Math.log(g/_+Math.exp(-_)),n[t+1]=Math.floor(_/p*a),p=_,c[t]=Math.exp(-_),l[t]=_/a}};let n;r.hasInit=!1,e.randomGaussian=(e,t)=>(r.hasInit||(r.zigset(),r.hasInit=!0),r.RNOR()*t+e),e.randomExponential=()=>(r.hasInit||(r.zigset(),r.hasInit=!0),r.REXP()),e.PERLIN="perlin",e.SIMPLEX="simplex",e.BLOCKY="blocky",e.Noise=Q5.PerlinNoise,e.noiseMode=e=>{t.Noise=Q5[e[0].toUpperCase()+e.slice(1)+"Noise"],n=null},e.noiseSeed=t=>{n=new e.Noise(t)},e.noise=(t=0,o=0,a=0)=>(n??=new e.Noise,n.noise(t,o,a)),e.noiseDetail=(t,o)=>{n??=new e.Noise,t>0&&(n.octaves=t),o>0&&(n.falloff=o)}},Q5.Noise=class{},Q5.PerlinNoise=class extends Q5.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,o,a=[];for(let e=0;e<256;e++)a[e]=e;for(let r=255;r>0;r--)t=(e=16807*e%2147483647)%(r+1),o=a[r],a[r]=a[t],a[t]=o;return a}dot(e,t,o,a){return e[0]*t+e[1]*o+e[2]*a}mix(e,t,o){return(1-o)*e+o*t}fade(e){return e*e*e*(e*(6*e-15)+10)}noise(e,t,o){let a=this,r=0,n=1,s=1,i=0;for(let l=0;l<a.octaves;l++){const l=255&Math.floor(e*n),c=255&Math.floor(t*n),d=255&Math.floor(o*n),h=e*n-Math.floor(e*n),u=t*n-Math.floor(t*n),_=o*n-Math.floor(o*n),p=a.fade(h),g=a.fade(u),x=a.fade(_),m=a.p[l]+c,f=a.p[m]+d,y=a.p[m+1]+d,v=a.p[l+1]+c,w=a.p[v]+d,M=a.p[v+1]+d,C=a.mix(a.dot(a.grad3[a.p[f]%12],h,u,_),a.dot(a.grad3[a.p[w]%12],h-1,u,_),p),S=a.mix(a.dot(a.grad3[a.p[y]%12],h,u-1,_),a.dot(a.grad3[a.p[M]%12],h-1,u-1,_),p),b=a.mix(a.dot(a.grad3[a.p[f+1]%12],h,u,_-1),a.dot(a.grad3[a.p[w+1]%12],h-1,u,_-1),p),R=a.mix(a.dot(a.grad3[a.p[y+1]%12],h,u-1,_-1),a.dot(a.grad3[a.p[M+1]%12],h-1,u-1,_-1),p),Q=a.mix(C,S,g),E=a.mix(b,R,g);r+=a.mix(Q,E,x)*s,i+=s,s*=a.falloff,n*=2}return(r/i+1)/2}},Q5.modules.sound=(e,t)=>{e.Sound=Q5.Sound,e.loadSound=(e,o)=>{t._preloadCount++,Q5.aud??=new window.AudioContext;let a=new Q5.Sound(e,o);return a.addEventListener("canplaythrough",(()=>{t._preloadCount--,a.loaded=!0,o&&o(a)})),a},e.getAudioContext=()=>Q5.aud,e.userStartAudio=()=>Q5.aud.resume()},Q5.Sound=class extends Audio{constructor(e){super(e);let t=this;t.load(),t.panner=Q5.aud.createStereoPanner(),t.source=Q5.aud.createMediaElementSource(t),t.source.connect(t.panner),t.panner.connect(Q5.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}},Q5.modules.util=(e,t)=>{e._loadFile=(e,o,a)=>{t._preloadCount++;let r={};return fetch(e).then((e=>"json"==a?e.json():"text"==a?e.text():void 0)).then((e=>{t._preloadCount--,Object.assign(r,e),o&&o(e)})),r},e.loadStrings=(t,o)=>e._loadFile(t,o,"text"),e.loadJSON=(t,o)=>e._loadFile(t,o,"json"),"object"==typeof localStorage&&(e.storeItem=localStorage.setItem,e.getItem=localStorage.getItem,e.removeItem=localStorage.removeItem,e.clearStorage=localStorage.clear),e.year=()=>(new Date).getFullYear(),e.day=()=>(new Date).getDay(),e.hour=()=>(new Date).getHours(),e.minute=()=>(new Date).getMinutes(),e.second=()=>(new Date).getSeconds()},Q5.modules.vector=e=>{e.createVector=(t,o,a)=>new Q5.Vector(t,o,a,e)},Q5.Vector=class{constructor(e,t,o,a){this.x=e||0,this.y=t||0,this.z=o||0,this._$=a||window,this._cn=null,this._cnsq=null}set(e,t,o){this.x=e||0,this.y=t||0,this.z=o||0}copy(){return new Q5.Vector(this.x,this.y,this.z)}_arg2v(e,t,o){return void 0!==e?.x?e:void 0!==t?{x:e,y:t,z:o||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,o=this.y-e.y,a=this.z-e.z;return Math.sqrt(t*t+o*o+a*a)}cross(){let e=this._arg2v(...arguments),t=this.y*e.z-this.z*e.y,o=this.z*e.x-this.x*e.z,a=this.x*e.y-this.y*e.x;return this.x=t,this.y=o,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 o=e/t;this.x*=o,this.y*=o,this.z*=o,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)}rotate(e){let t=this._$.cos(e),o=this._$.sin(e),a=this.x*t-this.y*o,r=this.x*o+this.y*t;return this.x=a,this.y=r,this}angleBetween(){let e=this._arg2v(...arguments),t=Q5.Vector.cross(this,e);return this._$.atan2(t.mag(),this.dot(e))*Math.sign(t.z||1)}lerp(){let e=[...arguments],t=this._arg2v(...e.slice(0,-1)),o=e.at(-1);return this.x+=(t.x-this.x)*o,this.y+=(t.y-this.y)*o,this.z+=(t.z-this.z)*o,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,o){void 0===o&&(o=1),this._cn=o,this._cnsq=o*o;const a=this._$.cos(t),r=this._$.sin(t),n=this._$.cos(e),s=this._$.sin(e);return this.x=o*s*r,this.y=-o*n,this.z=o*s*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}]`}},Q5.Vector.add=(e,t)=>e.copy().add(t),Q5.Vector.cross=(e,t)=>e.copy().cross(t),Q5.Vector.dist=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y,e.z-t.z),Q5.Vector.div=(e,t)=>e.copy().div(t),Q5.Vector.dot=(e,t)=>e.copy().dot(t),Q5.Vector.equals=(e,t,o)=>e.equals(t,o),Q5.Vector.lerp=(e,t,o)=>e.copy().lerp(t,o),Q5.Vector.limit=(e,t)=>e.copy().limit(t),Q5.Vector.heading=e=>this._$.atan2(e.y,e.x),Q5.Vector.magSq=e=>e.x*e.x+e.y*e.y+e.z*e.z,Q5.Vector.mag=e=>Math.sqrt(Q5.Vector.magSq(e)),Q5.Vector.mult=(e,t)=>e.copy().mult(t),Q5.Vector.normalize=e=>e.copy().normalize(),Q5.Vector.rem=(e,t)=>e.copy().rem(t),Q5.Vector.sub=(e,t)=>e.copy().sub(t);for(let e of["fromAngle","fromAngles","random2D","random3D"])Q5.Vector[e]=(t,o,a)=>(new Q5.Vector)[e](t,o,a);
8
+ function Q5(e,t,o){let a,r=this;if(r._q5=!0,r._parent=t,r._renderer=o||"q2d",r._preloadCount=0,e??="global","auto"==e){if(!window.setup&&!window.draw)return;e="global"}r._scope=e,"global"==e&&(Q5._hasGlobal=r._isGlobal=!0,a=Q5._nodejs?global:window);let n=new Proxy(r,{set:(e,t,o)=>(r[t]=o,r._isGlobal&&(a[t]=o),!0)});r.canvas=r.ctx=r.drawingContext=null,r.pixels=[];let s=null;r.frameCount=0,r.deltaTime=16,r._targetFrameRate=0,r._targetFrameDuration=16.666666666666668,r._frameRate=r._fps=60,r._loop=!0,r._hooks={postCanvas:[],preRender:[]};let i=0;r.millis=()=>performance.now()-i,r.noCanvas=()=>{r.canvas?.remove&&r.canvas.remove(),r.canvas=0,n.ctx=n.drawingContext=0},window&&(r.windowWidth=window.innerWidth,r.windowHeight=window.innerHeight,r.deviceOrientation=window.screen?.orientation?.type),r._incrementPreload=()=>n._preloadCount++,r._decrementPreload=()=>n._preloadCount--,r._draw=e=>{let t=e||performance.now();if(r._lastFrameTime??=t-r._targetFrameDuration,r._shouldResize&&(r.windowResized(),r._shouldResize=!1),r._loop)s=c(r._draw);else if(r.frameCount&&!r._redraw)return;if(s&&r.frameCount){if(t-r._lastFrameTime<r._targetFrameDuration-4)return}n.deltaTime=t-r._lastFrameTime,r._frameRate=1e3/r.deltaTime,n.frameCount++;let o=performance.now();r.ctx&&r.resetMatrix(),r._beginRender&&r._beginRender();for(let e of Q5.methods.pre)e.call(r);r.draw(),r._render&&r._render();for(let e of Q5.methods.post)e.call(r);r._finishRender&&r._finishRender(),n.pmouseX=r.mouseX,n.pmouseY=r.mouseY,r._lastFrameTime=t;let a=performance.now();r._fps=Math.round(1e3/(a-o))},r.noLoop=()=>{r._loop=!1,s=null},r.loop=()=>{r._loop=!0,null==s&&r._draw()},r.isLooping=()=>r._loop,r.redraw=(e=1)=>{r._redraw=!0;for(let t=0;t<e;t++)r._draw();r._redraw=!1},r.remove=()=>{r.noLoop(),r.canvas.remove()},r.frameRate=e=>(e&&(r._targetFrameRate=e,r._targetFrameDuration=1e3/e),r._frameRate),r.getTargetFrameRate=()=>r._targetFrameRate,r.getFPS=()=>r._fps,r.Element=function(e){this.elt=e},r._elements=[],r.TWO_PI=r.TAU=2*Math.PI,r.log=r.print=console.log,r.describe=()=>{};for(let e in Q5.modules)Q5.modules[e](r,n);let l=Q5.renderers[r._renderer];for(let e in l)l[e](r,n);for(let e in Q5)"_"!=e[1]&&e[1]==e[1].toUpperCase()&&(r[e]=Q5[e]);if("graphics"==e)return;"global"==e&&(Object.assign(Q5,r),delete Q5.Q5);for(let e of Q5.methods.init)e.call(r);for(let[e,t]of Object.entries(Q5.prototype))"_"!=e[0]&&"function"==typeof r[e]&&(r[e]=t.bind(r));if("global"==e){let e=Object.getOwnPropertyNames(r);for(let t of e)"_"!=t[0]&&(a[t]=r[t])}"function"==typeof e&&e(r),Q5._instanceCount++;let c=window.requestAnimationFrame||function(e){const t=r._lastFrameTime+r._targetFrameDuration;return setTimeout((()=>{e(t)}),t-performance.now())},d=a||r;r._isTouchAware=d.touchStarted||d.touchMoved||d.mouseReleased;let h=d.preload,u=["setup","draw","preload","mouseMoved","mousePressed","mouseReleased","mouseDragged","mouseClicked","keyPressed","keyReleased","keyTyped","touchStarted","touchMoved","touchEnded","windowResized"];for(let e of u)d[e]?r._isGlobal&&(r[e]=()=>{try{return d[e]()}catch(e){r._aiErrorAssistance?r._aiErrorAssistance(e):console.error(e)}}):r[e]=()=>{};async function _(){if(r._startDone=!0,r._preloadCount>0)return c(_);i=performance.now(),await r.setup(),r.frameCount||(null===r.ctx&&r.createCanvas(100,100),r._setupDone=!0,r.ctx&&r.resetMatrix(),c(r._draw))}(r.setup||r.draw)&&(arguments.length&&"namespace"!=e&&"webgpu"!=o||h?(r.preload(),_()):(d.preload=r.preload=()=>{r._startDone||_()},setTimeout(r.preload,32)))}Q5.renderers={},Q5.modules={},Q5._nodejs="object"==typeof process,Q5._instanceCount=0,Q5._friendlyError=(e,t)=>{throw Error(t+": "+e)},Q5._validateParameters=()=>!0,Q5.methods={init:[],pre:[],post:[],remove:[]},Q5.prototype.registerMethod=(e,t)=>Q5.methods[e].push(t),Q5.prototype.registerPreloadMethod=(e,t)=>Q5.prototype[e]=t[e],Q5._nodejs?global.p5??=global.Q5=Q5:"object"==typeof window?window.p5??=window.Q5=Q5:global.window=0,"object"==typeof document&&document.addEventListener("DOMContentLoaded",(()=>{Q5._hasGlobal||new Q5("auto")})),Q5.modules.canvas=(e,t)=>{e._OffscreenCanvas=window.OffscreenCanvas||function(){return document.createElement("canvas")},Q5._nodejs?Q5._createNodeJSCanvas&&(t.canvas=Q5._createNodeJSCanvas(100,100)):"image"!=e._scope&&"graphics"!=e._scope||(t.canvas=new e._OffscreenCanvas(100,100)),e.canvas||("object"==typeof document?(t.canvas=document.createElement("canvas"),e.canvas.id="q5Canvas"+Q5._instanceCount,e.canvas.classList.add("q5Canvas")):e.noCanvas());let o=e.canvas;if(o.width=e.width=100,o.height=e.height=100,"image"!=e._scope&&(o.renderer=e._renderer,o[e._renderer]=!0),e._pixelDensity=1,e._adjustDisplay=()=>{o.style&&(o.style.width=o.w+"px",o.style.height=o.h+"px")},e.createCanvas=function(t,a,r){r??=arguments[3];let n=Object.assign({},Q5.canvasOptions);if("object"==typeof r&&Object.assign(n,r),"image"!=e._scope){let t=e.displayDensity();"graphics"==e._scope?t=this._pixelDensity:window.IntersectionObserver&&new IntersectionObserver((e=>{o.visible=e[0].isIntersecting})).observe(o),e._pixelDensity=Math.ceil(t)}e._setCanvasSize(t,a),Object.assign(o,n);let s=e._createCanvas(o.w,o.h,n);if(e._hooks)for(let t of e._hooks.postCanvas)t();return s},e._save=async(e,t,o)=>{if(t=t||"untitled","jpg"==(o=o||"png")||"png"==o||"webp"==o)if(e instanceof OffscreenCanvas){const t=await e.convertToBlob({type:"image/"+o});e=await new Promise((e=>{const o=new FileReader;o.onloadend=()=>e(o.result),o.readAsDataURL(t)}))}else e=e.toDataURL("image/"+o);else{let t="text/plain";"json"==o&&("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+"."+o,a.click(),URL.revokeObjectURL(a.href)},e.save=(t,o,a)=>{if((!t||"string"==typeof t&&(!o||!a&&o.length<5))&&(a=o,o=t,t=e.canvas),a)return e._save(t,o,a);o?(o=o.split("."),e._save(t,o[0],o.at(-1))):e._save(t)},e._setCanvasSize=(a,r)=>{a??=window.innerWidth,r??=window.innerHeight,o.w=a=Math.ceil(a),o.h=r=Math.ceil(r),o.hw=a/2,o.hh=r/2,o.width=Math.ceil(a*e._pixelDensity),o.height=Math.ceil(r*e._pixelDensity),e._da?e.flexibleCanvas(e._dau):(t.width=a,t.height=r),e.displayMode&&!o.displayMode?e.displayMode():e._adjustDisplay()},"image"!=e._scope){if(o&&"graphics"!=e._scope){function a(){let t=e._parent;t??=document.getElementsByTagName("main")[0],t||(t=document.createElement("main"),document.body.append(t)),o.parent(t)}o.parent=t=>{function a(){e.frameCount>1&&(e._shouldResize=!0,e._adjustDisplay())}o.parentElement&&o.parentElement.removeChild(o),"string"==typeof t&&(t=document.getElementById(t)),t.append(o),"function"==typeof ResizeObserver?(e._ro&&e._ro.disconnect(),e._ro=new ResizeObserver(a),e._ro.observe(t)):e.frameCount||window.addEventListener("resize",a)},document.body?a():document.addEventListener("DOMContentLoaded",a)}e.resizeCanvas=(t,a)=>{if(!e.ctx)return e.createCanvas(t,a);t==o.w&&a==o.h||e._resizeCanvas(t,a)},e.canvas.resize=e.resizeCanvas,e.canvas.save=e.saveCanvas=e.save,e.displayDensity=()=>window.devicePixelRatio,e.pixelDensity=t=>t&&t!=e._pixelDensity?(e._pixelDensity=t,e._setCanvasSize(o.w,o.h),t):e._pixelDensity,e.flexibleCanvas=(a=400)=>{a?(e._da=o.width/(a*e._pixelDensity),t.width=e._dau=a,t.height=o.h/o.w*a):e._da=0}}},Q5.canvasOptions={alpha:!1,colorSpace:"display-p3"},window.matchMedia&&matchMedia("(dynamic-range: high) and (color-gamut: p3)").matches?Q5.supportsHDR=!0:Q5.canvasOptions.colorSpace="srgb",Q5.renderers.q2d={},Q5.renderers.q2d.canvas=(e,t)=>{let o=e.canvas;e.colorMode&&e.colorMode("rgb","integer"),e._createCanvas=function(a,r,n){return t.ctx=t.drawingContext=o.getContext("2d",n),"image"!=e._scope&&(e.ctx.fillStyle="white",e.ctx.strokeStyle="black",e.ctx.lineCap="round",e.ctx.lineJoin="miter",e.ctx.textAlign="left"),e.ctx.scale(e._pixelDensity,e._pixelDensity),e.ctx.save(),o},"image"!=e._scope&&(e._resizeCanvas=(t,a)=>{let r={};for(let t in e.ctx)"function"!=typeof e.ctx[t]&&(r[t]=e.ctx[t]);delete r.canvas;let n=new e._OffscreenCanvas(o.width,o.height);n.w=o.w,n.h=o.h,n.getContext("2d").drawImage(o,0,0),e._setCanvasSize(t,a);for(let t in r)e.ctx[t]=r[t];e.scale(e._pixelDensity),e.ctx.drawImage(n,0,0,n.w,n.h)},e.fill=function(t){if(e._doFill=!0,e._fillSet=!0,Q5.Color&&(t._q5Color||"string"==typeof t?e._namedColors[t]&&(t=e.color(...e._namedColors[t])):t=e.color(...arguments),t.a<=0))return e._doFill=!1;e.ctx.fillStyle=t.toString()},e.noFill=()=>e._doFill=!1,e.stroke=function(t){if(e._doStroke=!0,e._strokeSet=!0,Q5.Color&&(t._q5Color||"string"==typeof t?e._namedColors[t]&&(t=e.color(...e._namedColors[t])):t=e.color(...arguments),t.a<=0))return e._doStroke=!1;e.ctx.strokeStyle=t.toString()},e.strokeWeight=t=>{t||(e._doStroke=!1),e._da&&(t*=e._da),e.ctx.lineWidth=t||1e-4},e.noStroke=()=>e._doStroke=!1,e.clear=()=>{e.ctx.save(),e.ctx.resetTransform(),e.ctx.clearRect(0,0,e.canvas.width,e.canvas.height),e.ctx.restore()},e.translate=(t,o)=>{e._da&&(t*=e._da,o*=e._da),e.ctx.translate(t,o)},e.rotate=t=>{"degrees"==e._angleMode&&(t=e.radians(t)),e.ctx.rotate(t)},e.scale=(t,o)=>{o??=t,e.ctx.scale(t,o)},e.opacity=t=>e.ctx.globalAlpha=t,e.applyMatrix=(t,o,a,r,n,s)=>e.ctx.transform(t,o,a,r,n,s),e.shearX=t=>e.ctx.transform(1,0,e.tan(t),1,0,0),e.shearY=t=>e.ctx.transform(1,e.tan(t),0,1,0,0),e.resetMatrix=()=>{e.ctx.resetTransform(),e.scale(e._pixelDensity)},e._styleNames=["_doStroke","_doFill","_strokeSet","_fillSet","_tint","_imageMode","_rectMode","_ellipseMode","_textFont","_textLeading","_leadingSet","_textSize","_textAlign","_textBaseline","_textStyle","_textWrap"],e._styles=[],e.push=e.pushMatrix=()=>{e.ctx.save();let t={};for(let o of e._styleNames)t[o]=e[o];e._styles.push(t)},e.pop=e.popMatrix=()=>{e.ctx.restore();let t=e._styles.pop();for(let o of e._styleNames)e[o]=t[o]},e.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},e.createGraphics=function(t,o,a){let r=new Q5("graphics");return a??={},a.alpha??=!0,a.colorSpace??=e.canvas.colorSpace,r.createCanvas.call(e,t,o,a),r},window&&"graphics"!=e._scope&&window.addEventListener("resize",(()=>{e._shouldResize=!0,t.windowWidth=window.innerWidth,t.windowHeight=window.innerHeight,t.deviceOrientation=window.screen?.orientation?.type})))},Q5.renderers.q2d.drawing=e=>{e.CHORD=0,e.PIE=1,e.OPEN=2,e.RADIUS="radius",e.CORNER="corner",e.CORNERS="corners",e.ROUND="round",e.SQUARE="butt",e.PROJECT="square",e.MITER="miter",e.BEVEL="bevel",e.CLOSE=1,e.CENTER="center",e.LEFT="left",e.RIGHT="right",e.TOP="top",e.BOTTOM="bottom",e.LANDSCAPE="landscape",e.PORTRAIT="portrait",e.BLEND="source-over",e.REMOVE="destination-out",e.ADD="lighter",e.DARKEST="darken",e.LIGHTEST="lighten",e.DIFFERENCE="difference",e.SUBTRACT="subtract",e.EXCLUSION="exclusion",e.MULTIPLY="multiply",e.SCREEN="screen",e.REPLACE="copy",e.OVERLAY="overlay",e.HARD_LIGHT="hard-light",e.SOFT_LIGHT="soft-light",e.DODGE="color-dodge",e.BURN="color-burn",e._doStroke=!0,e._doFill=!0,e._strokeSet=!1,e._fillSet=!1,e._ellipseMode=e.CENTER,e._rectMode=e.CORNER,e._curveDetail=20,e._curveAlpha=0;let t=!0,o=[];function a(){e._doFill&&e.ctx.fill(),e._doStroke&&e.ctx.stroke()}function r(t,o,r,n,s,i,l,c){if(!e._doFill&&!e._doStroke)return;let d="degrees"==e._angleMode,h=d?360:e.TAU;if((s%=h)<0&&(s+=h),(i%=h)<0&&(i+=h),0!=s||0!=i){if(s>i&&([s,i]=[i,s]),e.ctx.beginPath(),r==n)d&&(s=e.radians(s),i=e.radians(i)),e.ctx.arc(t,o,r/2,s,i);else{for(let a=0;a<c+1;a++){let l=a/c,d=e.lerp(s,i,l),h=e.cos(d)*r/2,u=e.sin(d)*n/2;e.ctx[a?"lineTo":"moveTo"](t+h,o+u)}l==e.CHORD?e.ctx.closePath():l==e.PIE&&(e.ctx.lineTo(t,o),e.ctx.closePath())}a()}}function n(t,o,r,n){(e._doFill||e._doStroke)&&(e._da&&(t*=e._da,o*=e._da,r*=e._da,n*=e._da),e.ctx.beginPath(),e.ctx.ellipse(t,o,r/2,n/2,0,0,e.TAU),a())}function s(t,o,r,n,i,l,c,d){if(e._doFill||e._doStroke){if(void 0===i)return function(t,o,r,n){e._da&&(t*=e._da,o*=e._da,r*=e._da,n*=e._da),e.ctx.beginPath(),e.ctx.rect(t,o,r,n),a()}(t,o,r,n);if(void 0===l)return s(t,o,r,n,i,i,i,i);e._da&&(t*=e._da,o*=e._da,r*=e._da,n*=e._da,i*=e._da,l*=e._da,d*=e._da,c*=e._da),e.ctx.roundRect(t,o,r,n,[i,l,c,d]),a()}}e.blendMode=t=>e.ctx.globalCompositeOperation=t,e.strokeCap=t=>e.ctx.lineCap=t,e.strokeJoin=t=>e.ctx.lineJoin=t,e.ellipseMode=t=>e._ellipseMode=t,e.rectMode=t=>e._rectMode=t,e.curveDetail=t=>e._curveDetail=t,e.curveAlpha=t=>e._curveAlpha=t,e.curveTightness=t=>e._curveAlpha=t,e.background=function(t){e.ctx.save(),e.ctx.resetTransform(),t.canvas?e.image(t,0,0,e.width,e.height):(Q5.Color&&(t._q5Color||"string"==typeof t?e._namedColors[t]&&(t=e.color(...e._namedColors[t])):t=e.color(...arguments)),e.ctx.fillStyle=t.toString(),e.ctx.fillRect(0,0,e.canvas.width,e.canvas.height)),e.ctx.restore()},e.line=(t,o,a,r)=>{e._doStroke&&(e._da&&(t*=e._da,o*=e._da,a*=e._da,r*=e._da),e.ctx.beginPath(),e.ctx.moveTo(t,o),e.ctx.lineTo(a,r),e.ctx.stroke())},e.arc=(t,o,a,n,s,i,l,c=25)=>{if(s==i)return e.ellipse(t,o,a,n);l??=e.PIE,e._ellipseMode==e.CENTER?r(t,o,a,n,s,i,l,c):e._ellipseMode==e.RADIUS?r(t,o,2*a,2*n,s,i,l,c):e._ellipseMode==e.CORNER?r(t+a/2,o+n/2,a,n,s,i,l,c):e._ellipseMode==e.CORNERS&&r((t+a)/2,(o+n)/2,a-t,n-o,s,i,l,c)},e.ellipse=(t,o,a,r)=>{r??=a,e._ellipseMode==e.CENTER?n(t,o,a,r):e._ellipseMode==e.RADIUS?n(t,o,2*a,2*r):e._ellipseMode==e.CORNER?n(t+a/2,o+r/2,a,r):e._ellipseMode==e.CORNERS&&n((t+a)/2,(o+r)/2,a-t,r-o)},e.circle=(t,o,r)=>{e._ellipseMode==e.CENTER?(e._da&&(t*=e._da,o*=e._da,r*=e._da),e.ctx.beginPath(),e.ctx.arc(t,o,r/2,0,e.TAU),a()):e.ellipse(t,o,r,r)},e.point=(t,o)=>{t.x&&(o=t.y,t=t.x),e._da&&(t*=e._da,o*=e._da),e.ctx.save(),e.ctx.beginPath(),e.ctx.arc(t,o,e.ctx.lineWidth/2,0,e.TAU),e.ctx.fillStyle=e.ctx.strokeStyle,e.ctx.fill(),e.ctx.restore()},e.rect=(t,o,a,r=a,n,i,l,c)=>{e._rectMode==e.CENTER?s(t-a/2,o-r/2,a,r,n,i,l,c):e._rectMode==e.RADIUS?s(t-a,o-r,2*a,2*r,n,i,l,c):e._rectMode==e.CORNER?s(t,o,a,r,n,i,l,c):e._rectMode==e.CORNERS&&s(t,o,a-t,r-o,n,i,l,c)},e.square=(t,o,a,r,n,s,i)=>e.rect(t,o,a,a,r,n,s,i),e.beginShape=()=>{o=[],e.ctx.beginPath(),t=!0},e.beginContour=()=>{e.ctx.closePath(),o=[],t=!0},e.endContour=()=>{o=[],t=!0},e.vertex=(a,r)=>{e._da&&(a*=e._da,r*=e._da),o=[],t?e.ctx.moveTo(a,r):e.ctx.lineTo(a,r),t=!1},e.bezierVertex=(t,a,r,n,s,i)=>{e._da&&(t*=e._da,a*=e._da,r*=e._da,n*=e._da,s*=e._da,i*=e._da),o=[],e.ctx.bezierCurveTo(t,a,r,n,s,i)},e.quadraticVertex=(t,a,r,n)=>{e._da&&(t*=e._da,a*=e._da,r*=e._da,n*=e._da),o=[],e.ctx.quadraticCurveTo(t,a,r,n)},e.bezier=(t,o,a,r,n,s,i,l)=>{e.beginShape(),e.vertex(t,o),e.bezierVertex(a,r,n,s,i,l),e.endShape()},e.triangle=(t,o,a,r,n,s)=>{e.beginShape(),e.vertex(t,o),e.vertex(a,r),e.vertex(n,s),e.endShape(e.CLOSE)},e.quad=(t,o,a,r,n,s,i,l)=>{e.beginShape(),e.vertex(t,o),e.vertex(a,r),e.vertex(n,s),e.vertex(i,l),e.endShape(e.CLOSE)},e.endShape=t=>{o=[],t&&e.ctx.closePath(),a()},e.curveVertex=(a,r)=>{if(e._da&&(a*=e._da,r*=e._da),o.push([a,r]),o.length<4)return;let n=function(e,t,o,a,r,n,s,i,l,c){function d(e,t,o,a,r,n){let s=Math.pow(a-t,2)+Math.pow(r-o,2);return Math.pow(s,.5*n)+e}let h=[],u=d(0,e,t,o,a,c),_=d(u,o,a,r,n,c),p=d(_,r,n,s,i,c);for(let c=0;c<l;c++){let d=u+c/(l-1)*(_-u),g=[(u-d)/(u-0),(d-0)/(u-0),(_-d)/(_-u),(d-u)/(_-u),(p-d)/(p-_),(d-_)/(p-_),(_-d)/(_-0),(d-0)/(_-0),(p-d)/(p-u),(d-u)/(p-u)];for(let e=0;e<g.length;e+=2)isNaN(g[e])&&(g[e]=1,g[e+1]=0),isFinite(g[e])||(g[e]>0?(g[e]=1,g[e+1]=0):(g[e]=0,g[e+1]=1));let x=e*g[0]+o*g[1],m=t*g[0]+a*g[1],f=o*g[2]+r*g[3],y=a*g[2]+n*g[3],v=r*g[4]+s*g[5],w=n*g[4]+i*g[5],C=x*g[6]+f*g[7],M=m*g[6]+y*g[7],S=f*g[8]+v*g[9],b=y*g[8]+w*g[9],R=C*g[2]+S*g[3],Q=M*g[2]+b*g[3];h.push([R,Q])}return h}(...o.at(-4),...o.at(-3),...o.at(-2),...o.at(-1),e._curveDetail,e._curveAlpha);for(let o=0;o<n.length;o++)t?e.ctx.moveTo(...n[o]):e.ctx.lineTo(...n[o]),t=!1},e.curve=(t,o,a,r,n,s,i,l)=>{e.beginShape(),e.curveVertex(t,o),e.curveVertex(a,r),e.curveVertex(n,s),e.curveVertex(i,l),e.endShape()},e.curvePoint=(e,t,o,a,r)=>{const n=r*r*r,s=r*r;return e*(-.5*n+s-.5*r)+t*(1.5*n-2.5*s+1)+o*(-1.5*n+2*s+.5*r)+a*(.5*n-.5*s)},e.bezierPoint=(e,t,o,a,r)=>{const n=1-r;return Math.pow(n,3)*e+3*Math.pow(n,2)*r*t+3*n*Math.pow(r,2)*o+Math.pow(r,3)*a},e.curveTangent=(e,t,o,a,r)=>{const n=r*r;return e*(-3*n/2+2*r-.5)+t*(9*n/2-5*r)+o*(-9*n/2+4*r+.5)+a*(3*n/2-r)},e.bezierTangent=(e,t,o,a,r)=>{const n=1-r;return 3*a*Math.pow(r,2)-3*o*Math.pow(r,2)+6*o*n*r-6*t*n*r+3*t*Math.pow(n,2)-3*e*Math.pow(n,2)},e.erase=function(t=255,o=255){e.ctx.save(),e.ctx.globalCompositeOperation="destination-out",e.ctx.fillStyle=`rgba(0, 0, 0, ${t/255})`,e.ctx.strokeStyle=`rgba(0, 0, 0, ${o/255})`},e.noErase=function(){e.ctx.globalCompositeOperation="source-over",e.ctx.restore()},e.inFill=(t,o)=>{const a=e._pixelDensity;return e.ctx.isPointInPath(t*a,o*a)},e.inStroke=(t,o)=>{const a=e._pixelDensity;return e.ctx.isPointInStroke(t*a,o*a)}},Q5.renderers.q2d.image=(e,t)=>{Q5.Image??=class{constructor(e,t,o){let a=this;a._scope="image",a.canvas=a.ctx=a.drawingContext=null,a.pixels=[],Q5.modules.canvas(a,a);let r=Q5.renderers.q2d;for(let e of["canvas","image","soft_filters"])r[e]&&r[e](a,a);a.createCanvas(e,t,o),delete a.createCanvas,a._loop=!1}get w(){return this.width}get h(){return this.height}},e.createImage=(t,o,a)=>(a??={},a.alpha??=!0,a.colorSpace??=e.canvas.colorSpace||Q5.canvasOptions.colorSpace,new Q5.Image(t,o,a)),e.loadImage=function(o,a,r){if(o.canvas)return o;if("gif"==o.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 n=[...arguments].at(-1);r="object"==typeof n?n:null;let s=e.createImage(1,1,r);function i(e){s.resize(e.naturalWidth||e.width,e.naturalHeight||e.height),s.ctx.drawImage(e,0,0),t._preloadCount--,a&&a(s)}if(Q5._nodejs&&global.CairoCanvas)global.CairoCanvas.loadImage(o).then(i).catch((e=>{throw t._preloadCount--,e}));else{let e=new window.Image;e.src=o,e.crossOrigin="Anonymous",e._pixelDensity=1,e.onload=()=>i(e),e.onerror=e=>{throw t._preloadCount--,e}}return s},e.imageMode=t=>e._imageMode=t,e.image=(t,o,a,r,n,s=0,i=0,l,c)=>{let d=t.canvas||t;Q5._createNodeJSCanvas&&(d=d.context.canvas),r??=t.width||t.videoWidth,n??=t.height||t.videoHeight,"center"==e._imageMode&&(o-=.5*r,a-=.5*n),e._da&&(o*=e._da,a*=e._da,r*=e._da,n*=e._da,s*=e._da,i*=e._da,l*=e._da,c*=e._da);let h=t._pixelDensity||1;l?l*=h:l=d.width||d.videoWidth,c?c*=h:c=d.height||d.videoHeight,e.ctx.drawImage(d,s*h,i*h,l,c,o,a,r,n),e._tint&&(e.ctx.globalCompositeOperation="multiply",e.ctx.fillStyle=e._tint.toString(),e.ctx.fillRect(o,a,r,n),e.ctx.globalCompositeOperation="source-over")},e._tint=null;let o=null;e._softFilter=()=>{throw new Error("Load q5-2d-soft-filters.js to use software filters.")},e.filter=(t,o)=>{if(!e.ctx.filter)return e._softFilter(t,o);if("string"==typeof t)f=t;else if(t==Q5.GRAY)f="saturate(0%)";else if(t==Q5.INVERT)f="invert(100%)";else if(t==Q5.BLUR){let t=Math.ceil(o*e._pixelDensity)||1;f=`blur(${t}px)`}else{if(t!=Q5.THRESHOLD)return e._softFilter(t,o);{o??=.5;let e=Math.floor(.5/Math.max(o,1e-5)*100);f=`saturate(0%) brightness(${e}%) contrast(1000000%)`}}e.ctx.filter=f,e.ctx.drawImage(e.canvas,0,0,e.canvas.w,e.canvas.h),e.ctx.filter="none"},"image"==e._scope&&(e.resize=(t,o)=>{let a=new e._OffscreenCanvas(e.canvas.width,e.canvas.height);a.getContext("2d",{colorSpace:e.canvas.colorSpace}).drawImage(e.canvas,0,0),e._setCanvasSize(t,o),e.ctx.clearRect(0,0,e.canvas.width,e.canvas.height),e.ctx.drawImage(a,0,0,e.canvas.width,e.canvas.height)}),e.trim=()=>{let t=e._pixelDensity||1,o=e.canvas.width,a=e.canvas.height,r=e.ctx.getImageData(0,0,o,a).data,n=o,s=0,i=a,l=0,c=3;for(let e=0;e<a;e++)for(let t=0;t<o;t++)0!==r[c]&&(t<n&&(n=t),t>s&&(s=t),e<i&&(i=e),e>l&&(l=e)),c+=4;return i=Math.floor(i/t),l=Math.floor(l/t),n=Math.floor(n/t),s=Math.floor(s/t),e.get(n,i,s-n+1,l-i+1)},e.mask=t=>{e.ctx.save(),e.ctx.resetTransform();let o=e.ctx.globalCompositeOperation;e.ctx.globalCompositeOperation="destination-in",e.ctx.drawImage(t.canvas,0,0),e.ctx.globalCompositeOperation=o,e.ctx.restore()},e.get=(t,o,a,r)=>{let n=e._pixelDensity||1;if(void 0!==t&&void 0===a){let a=e.ctx.getImageData(t*n,o*n,1,1).data;return new e.Color(a[0],a[1],a[2],a[3]/255)}t=(t||0)*n,o=(o||0)*n;let s=a=a||e.width,i=r=r||e.height;a*=n,r*=n;let l=e.createImage(a,r),c=e.ctx.getImageData(t,o,a,r);return l.ctx.putImageData(c,0,0),l._pixelDensity=n,l.width=s,l.height=i,l},e.set=(t,o,a)=>{if(a.canvas){let r=e._tint;return e._tint=null,e.image(a,t,o),void(e._tint=r)}e.pixels.length||e.loadPixels();let r=e._pixelDensity||1;for(let n=0;n<r;n++)for(let s=0;s<r;s++){let i=4*((o*r+n)*e.canvas.width+t*r+s);e.pixels[i]=a.r??a.l,e.pixels[i+1]=a.g??a.c,e.pixels[i+2]=a.b??a.h,e.pixels[i+3]=a.a}},e.loadPixels=()=>{o=e.ctx.getImageData(0,0,e.canvas.width,e.canvas.height),t.pixels=o.data},e.updatePixels=()=>{null!=o&&e.ctx.putImageData(o,0,0)},e.smooth=()=>e.ctx.imageSmoothingEnabled=!0,e.noSmooth=()=>e.ctx.imageSmoothingEnabled=!1,"image"!=e._scope&&(e.tint=function(t){e._tint=t._q5Color?t:e.color(...arguments)},e.noTint=()=>e._tint=null)},Q5.THRESHOLD=1,Q5.GRAY=2,Q5.OPAQUE=3,Q5.INVERT=4,Q5.POSTERIZE=5,Q5.DILATE=6,Q5.ERODE=7,Q5.BLUR=8,Q5.renderers.q2d.soft_filters=e=>{let t=null;function o(){let o=e.canvas.width*e.canvas.height*4;t&&t.length==o||(t=new Uint8ClampedArray(o))}e._softFilter=(a,r)=>{e._filters||(e._filters=[],e._filters[Q5.THRESHOLD]=(e,t)=>{void 0===t?t=127.5:t*=255;for(let o=0;o<e.length;o+=4){const a=.2126*e[o]+.7152*e[o+1]+.0722*e[o+2];e[o]=e[o+1]=e[o+2]=a>=t?255:0}},e._filters[Q5.GRAY]=e=>{for(let t=0;t<e.length;t+=4){const o=.2126*e[t]+.7152*e[t+1]+.0722*e[t+2];e[t]=e[t+1]=e[t+2]=o}},e._filters[Q5.OPAQUE]=e=>{for(let t=0;t<e.length;t+=4)e[t+3]=255},e._filters[Q5.INVERT]=e=>{for(let t=0;t<e.length;t+=4)e[t]=255-e[t],e[t+1]=255-e[t+1],e[t+2]=255-e[t+2]},e._filters[Q5.POSTERIZE]=(e,t=4)=>{let o=t-1;for(let a=0;a<e.length;a+=4)e[a]=255*(e[a]*t>>8)/o,e[a+1]=255*(e[a+1]*t>>8)/o,e[a+2]=255*(e[a+2]*t>>8)/o},e._filters[Q5.DILATE]=a=>{o(),t.set(a);let[r,n]=[e.canvas.width,e.canvas.height];for(let e=0;e<n;e++)for(let o=0;o<r;o++){let s=4*Math.max(o-1,0),i=4*Math.min(o+1,r-1),l=4*Math.max(e-1,0)*r,c=4*Math.min(e+1,n-1)*r,d=4*e*r,h=4*o;for(let e=0;e<4;e++){let o=e+l,r=e+c,n=e+d;a[d+h+e]=Math.max(t[o+h],t[n+s],t[n+h],t[n+i],t[r+h])}}},e._filters[Q5.ERODE]=a=>{o(),t.set(a);let[r,n]=[e.canvas.width,e.canvas.height];for(let e=0;e<n;e++)for(let o=0;o<r;o++){let s=4*Math.max(o-1,0),i=4*Math.min(o+1,r-1),l=4*Math.max(e-1,0)*r,c=4*Math.min(e+1,n-1)*r,d=4*e*r,h=4*o;for(let e=0;e<4;e++){let o=e+l,r=e+c,n=e+d;a[d+h+e]=Math.min(t[o+h],t[n+s],t[n+h],t[n+i],t[r+h])}}},e._filters[Q5.BLUR]=(a,r)=>{r=r||1,r=Math.floor(r*e._pixelDensity),o(),t.set(a);let n=2*r+1,s=function(e){let t=new Float32Array(e),o=.3*r+.8,a=o*o*2;for(let r=0;r<e;r++){let n=r-e/2,s=Math.exp(-n*n/a)/(2.5066282746*o);t[r]=s}return t}(n),[i,l]=[e.canvas.width,e.canvas.height];for(let e=0;e<l;e++)for(let o=0;o<i;o++){let l=0,c=0,d=0,h=0;for(let a=0;a<n;a++){let n=4*(e*i+Math.min(Math.max(o-r+a,0),i-1));l+=t[n]*s[a],c+=t[n+1]*s[a],d+=t[n+2]*s[a],h+=t[n+3]*s[a]}let u=4*(e*i+o);a[u]=l,a[u+1]=c,a[u+2]=d,a[u+3]=h}t.set(a);for(let e=0;e<l;e++)for(let o=0;o<i;o++){let c=0,d=0,h=0,u=0;for(let a=0;a<n;a++){let n=4*(Math.min(Math.max(e-r+a,0),l-1)*i+o);c+=t[n]*s[a],d+=t[n+1]*s[a],h+=t[n+2]*s[a],u+=t[n+3]*s[a]}let _=4*(e*i+o);a[_]=c,a[_+1]=d,a[_+2]=h,a[_+3]=u}});let n=e.ctx.getImageData(0,0,e.canvas.width,e.canvas.height);e._filters[a](n.data,r),e.ctx.putImageData(n,0,0)}},Q5.renderers.q2d.text=(e,t)=>{e.NORMAL="normal",e.ITALIC="italic",e.BOLD="bold",e.BOLDITALIC="italic bold",e.CENTER="center",e.LEFT="left",e.RIGHT="right",e.TOP="top",e.BOTTOM="bottom",e.BASELINE="alphabetic",e._textFont="sans-serif",e._textSize=12,e._textLeading=15,e._textLeadDiff=3,e._textStyle="normal",e.loadFont=(e,o)=>{t._preloadCount++;let a=e.split("/").pop().split(".")[0].replace(" ",""),r=new FontFace(a,`url(${e})`);return document.fonts.add(r),r.load().then((()=>{t._preloadCount--,o&&o(a)})),a},e.textFont=t=>e._textFont=t,e.textSize=t=>{if(void 0===t)return e._textSize;e._da&&(t*=e._da),e._textSize=t,e._leadingSet||(e._textLeading=1.25*t,e._textLeadDiff=e._textLeading-t)},e.textLeading=t=>{if(void 0===t)return e._textLeading;e._da&&(t*=e._da),e._textLeading=t,e._textLeadDiff=t-e._textSize,e._leadingSet=!0},e.textStyle=t=>e._textStyle=t,e.textAlign=(t,o)=>{e.ctx.textAlign=t,o&&(e.ctx.textBaseline=o==e.CENTER?"middle":o)},e.textWidth=t=>(e.ctx.font=`${e._textStyle} ${e._textSize}px ${e._textFont}`,e.ctx.measureText(t).width),e.textAscent=t=>(e.ctx.font=`${e._textStyle} ${e._textSize}px ${e._textFont}`,e.ctx.measureText(t).actualBoundingBoxAscent),e.textDescent=t=>(e.ctx.font=`${e._textStyle} ${e._textSize}px ${e._textFont}`,e.ctx.measureText(t).actualBoundingBoxDescent),e._textCache=!!Q5.Image,e._TimedCache=class extends Map{constructor(){super(),this.maxSize=500}set(e,t){t.lastAccessed=Date.now(),super.set(e,t),this.size>this.maxSize&&this.gc()}get(e){const t=super.get(e);return t&&(t.lastAccessed=Date.now()),t}gc(){let e,t=1/0,o=0;for(const[a,r]of this.entries())r.lastAccessed<t&&(t=r.lastAccessed,e=o),o++;o=e;for(const t of this.keys()){if(0==o){e=t;break}o--}this.delete(e)}},e._tic=new e._TimedCache,e.textCache=(t,o)=>(o&&(e._tic.maxSize=o),void 0!==t&&(e._textCache=t),e._textCache),e._genTextImageKey=(t,o,a)=>t.slice(0,200)+e._textStyle+e._textSize+e._textFont+(e._doFill?e.ctx.fillStyle:"")+"_"+(e._doStroke&&e._strokeSet?e.ctx.lineWidth+e.ctx.strokeStyle+"_":"")+(o||"")+(a?"x"+a:""),e.createTextImage=(t,o,a)=>{let r=e._textCache;e._textCache=!0,e._genTextImage=!0,e.text(t,0,0,o,a),e._genTextImage=!1;let n=e._genTextImageKey(t,o,a);return e._textCache=r,e._tic.get(n)},e.text=(t,o,a,r,n)=>{if(void 0===t)return;if(t=t.toString(),e._da&&(o*=e._da,a*=e._da),!e._doFill&&!e._doStroke)return;let s,i,l,c,d,h,u,_,p=e.ctx.getTransform(),g=e._genTextImage||e._textCache&&(0!=p.b||0!=p.c);if(g){if(c=e._genTextImageKey(t,r,n),i=e._tic.get(c),i&&!e._genTextImage)return void e.textImage(i,o,a);l=e.createGraphics.call(e,1,1),s=l.ctx}else s=e.ctx,d=o,h=a;s.font=`${e._textStyle} ${e._textSize}px ${e._textFont}`;let x=t.split("\n");if(g){d=0,h=e._textLeading*x.length;let o=s.measureText(" ");u=o.fontBoundingBoxAscent,_=o.fontBoundingBoxDescent,n??=h+_,l.resizeCanvas(Math.ceil(s.measureText(t).width),Math.ceil(n)),s.fillStyle=e.ctx.fillStyle,s.strokeStyle=e.ctx.strokeStyle,s.lineWidth=e.ctx.lineWidth}let m=s.fillStyle;e._fillSet||(s.fillStyle="black");for(let t=0;t<x.length&&(e._doStroke&&e._strokeSet&&s.strokeText(x[t],d,h),e._doFill&&s.fillText(x[t],d,h),h+=e._textLeading,!(h>n));t++);e._fillSet||(s.fillStyle=m),g&&(i=l.get(),i._ascent=u,i._descent=_,e._tic.set(c,i),e._genTextImage||e.textImage(i,o,a))},e.textImage=(t,o,a)=>{let r=e._imageMode;e._imageMode="corner","center"==e.ctx.textAlign?o-=.5*t.width:"right"==e.ctx.textAlign&&(o-=t.width),"alphabetic"==e.ctx.textBaseline&&(a-=e._textLeading),"middle"==e.ctx.textBaseline?a-=t._descent+.5*t._ascent+e._textLeadDiff:"bottom"==e.ctx.textBaseline?a-=t._ascent+t._descent+e._textLeadDiff:"top"==e.ctx.textBaseline&&(a-=t._descent+e._textLeadDiff),e.image(t,o,a),e._imageMode=r},e.nf=(e,t,o)=>{let a=e<0,r=(e=Math.abs(e)).toFixed(o).split(".");r[0]=r[0].padStart(t,"0");let n=r.join(".");return a&&(n="-"+n),n}},Q5.modules.ai=e=>{e.askAI=(e="")=>{throw Error("Ask AI ✨ "+e)},e._aiErrorAssistance=async t=>{let o=t.message?.includes("Ask AI ✨");if(o||console.error(t),Q5.disableFriendlyErrors)return;!o&&Q5.errorTolerant||e.noLoop();let a=t.stack?.split("\n");if(!t.stack||a.length<=1)return;let r=1,n="(";for(-1==navigator.userAgent.indexOf("Chrome")&&(r=0,n="@");a[r].indexOf("q5.js:")>=0;)r++;let s=a[r].split(n).at(-1);s=s.split(":");let i=parseInt(s.at(-2));o&&i++;let l=s.slice(0,-2).join(":"),c=l.split("/").at(-1);try{let e=(await(await fetch(l)).text()).split("\n"),a=e[i-1].trim(),r="",n=1;for(;r.length<1600&&(i-n>=0&&(r=e[i-n].trim()+"\n"+r),i+n<e.length);)r+=e[i+n].trim()+"\n",n++;let s="https://chatgpt.com/?q=q5.js+"+(o&&t.message.length>10?t.message.slice(10):"Whats+wrong+with+this+line%3F+short+answer")+(o?"":"%0A%0A"+encodeURIComponent(t.name+": "+t.message))+"%0A%0ALine%3A+"+encodeURIComponent(a)+"%0A%0AExcerpt+for+context%3A%0A%0A"+encodeURIComponent(r);o||console.log("Error in "+c+" on line "+i+":\n\n"+a),console.warn("Ask AI ✨ "+s),o&&window.open(s,"_blank")}catch(e){}}},Q5.modules.color=(e,t)=>{e.RGB=e.RGBA=e._colorMode="rgb",e.OKLCH="oklch",e.colorMode=(o,a)=>{e._colorMode=o;let r="srgb"==e.canvas.colorSpace||"srgb"==o;if(a??=r?"integer":"float",e._colorFormat="float"==a||1==a?1:255,"oklch"==o)t.Color=Q5.ColorOKLCH;else{let o="srgb"==e.canvas.colorSpace;255==e._colorFormat?t.Color=o?Q5.ColorRGBA_8:Q5.ColorRGBA_P3_8:t.Color=o?Q5.ColorRGBA:Q5.ColorRGBA_P3,e._colorMode="rgb"}},e._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]},e.color=(t,o,a,r)=>{let n=e.Color;if(t._q5Color)return new n(...t.levels);if(null==o){if("string"==typeof t){if("#"==t[0])t.length<=5?(t.length>4&&(r=parseInt(t[4]+t[4],16)),a=parseInt(t[3]+t[3],16),o=parseInt(t[2]+t[2],16),t=parseInt(t[1]+t[1],16)):(t.length>7&&(r=parseInt(t.slice(7,9),16)),a=parseInt(t.slice(5,7),16),o=parseInt(t.slice(3,5),16),t=parseInt(t.slice(1,3),16));else{if(!e._namedColors[t])return console.error("q5 can't parse color: "+t+"\nOnly numeric input, hex, and common named colors are supported."),new n(0,0,0);[t,o,a,r]=e._namedColors[t]}1==e._colorFormat&&(t/=255,o&&(o/=255),a&&(a/=255),r&&(r/=255))}Array.isArray(t)&&(o=t[1],a=t[2],r=t[3],t=t[0])}return null==a?new n(t,t,t,o):new n(t,o,a,r)},e.red=e=>e.r,e.green=e=>e.g,e.blue=e=>e.b,e.alpha=e=>e.a,e.lightness=t=>"oklch"==e._colorMode?t.l:100*(.2126*t.r+.7152*t.g+.0722*t.b)/255,e.hue=t=>{if("oklch"==e._colorMode)return t.h;let o=t.r,a=t.g,r=t.b;255==e._colorFormat&&(o/=255,a/=255,r/=255);let n,s=Math.max(o,a,r),i=Math.min(o,a,r);return n=s==i?0:s==o?60*(a-r)/(s-i):s==a?60*(r-o)/(s-i)+120:60*(o-a)/(s-i)+240,n<0&&(n+=360),n},e.lerpColor=(t,o,a)=>{if("rgb"==e._colorMode)return new e.Color(e.constrain(e.lerp(t.r,o.r,a),0,255),e.constrain(e.lerp(t.g,o.g,a),0,255),e.constrain(e.lerp(t.b,o.b,a),0,255),e.constrain(e.lerp(t.a,o.a,a),0,255));{let r=o.h-t.h;r>180&&(r-=360),r<-180&&(r+=360);let n=t.h+a*r;return n<0&&(n+=360),n>360&&(n-=360),new e.Color(e.constrain(e.lerp(t.l,o.l,a),0,100),e.constrain(e.lerp(t.c,o.c,a),0,100),n,e.constrain(e.lerp(t.a,o.a,a),0,255))}}},Q5.Color=class{constructor(){this._q5Color=!0}},Q5.ColorOKLCH=class extends Q5.Color{constructor(e,t,o,a){super(),this.l=e,this.c=t,this.h=o,this.a=a??1}toString(){return`oklch(${this.l} ${this.c} ${this.h} / ${this.a})`}},Q5.ColorRGBA=class extends Q5.Color{constructor(e,t,o,a){super(),this.r=e,this.g=t,this.b=o,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})`}},Q5.ColorRGBA_P3=class extends Q5.ColorRGBA{toString(){return`color(display-p3 ${this.r} ${this.g} ${this.b} / ${this.a})`}},Q5.ColorRGBA_8=class extends Q5.ColorRGBA{constructor(e,t,o,a){super(e,t,o,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})`}},Q5.ColorRGBA_P3_8=class extends Q5.ColorRGBA{constructor(e,t,o,a){super(e,t,o,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),o=(this._b/255).toFixed(3),a=(this._a/255).toFixed(3);this._css=`color(display-p3 ${e} ${t} ${o} / ${a})`,this._edited=!1}return this._css}},Q5.modules.display=e=>{if(!e.canvas||"graphics"==e._scope)return;let t=e.canvas;0!=Q5._instanceCount||Q5._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;\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>"),e._adjustDisplay=()=>{let o=t.style,a=t.parentElement;o&&a&&t.displayMode&&("pixelated"==t.renderQuality&&(t.classList.add("q5-pixelated"),e.pixelDensity(1),e.noSmooth&&e.noSmooth(),e.textFont&&e.textFont("monospace")),"normal"==t.displayMode?(a.classList.remove("q5-centered","q5-maxed","q5-fullscreen"),o.width=t.w*t.displayScale+"px",o.height=t.h*t.displayScale+"px"):(a.classList.add("q5-"+t.displayMode),a=a.getBoundingClientRect(),t.w/t.h>a.width/a.height?("centered"==t.displayMode?(o.width=t.w*t.displayScale+"px",o.maxWidth="100%"):o.width="100%",o.height="auto",o.maxHeight=""):(o.width="auto",o.maxWidth="","centered"==t.displayMode?(o.height=t.h*t.displayScale+"px",o.maxHeight="100%"):o.height="100%")))},e.displayMode=(o="normal",a="default",r=1)=>{"string"==typeof r&&(r=parseFloat(r.slice(1))),Object.assign(t,{displayMode:o,renderQuality:a,displayScale:r}),e._adjustDisplay()},e.fullscreen=e=>{if(void 0===e)return document.fullscreenElement;e?document.body.requestFullscreen():document.body.exitFullscreen()}},Q5.modules.input=(e,t)=>{if("graphics"==e._scope)return;e.mouseX=0,e.mouseY=0,e.pmouseX=0,e.pmouseY=0,e.touches=[],e.mouseButton=null,e.keyIsPressed=!1,e.mouseIsPressed=!1,e.key=null,e.keyCode=null,e.UP_ARROW=38,e.DOWN_ARROW=40,e.LEFT_ARROW=37,e.RIGHT_ARROW=39,e.SHIFT=16,e.TAB=9,e.BACKSPACE=8,e.ENTER=e.RETURN=13,e.ALT=e.OPTION=18,e.CONTROL=17,e.DELETE=46,e.ESCAPE=27,e.ARROW="default",e.CROSS="crosshair",e.HAND="pointer",e.MOVE="move",e.TEXT="text";let o={},a=[e.LEFT,e.CENTER,e.RIGHT],r=e.canvas;function n(t){const o=e.canvas.getBoundingClientRect(),a=e.canvas.scrollWidth/e.width||1,r=e.canvas.scrollHeight/e.height||1;return{x:(t.clientX-o.left)/a,y:(t.clientY-o.top)/r,id:t.identifier}}if(e._startAudio=()=>{e.getAudioContext&&"suspended"==e.getAudioContext()?.state&&e.userStartAudio()},e._updateMouse=o=>{if(!o.changedTouches)if(r){let a=r.getBoundingClientRect(),n=r.scrollWidth/e.width||1,s=r.scrollHeight/e.height||1;t.mouseX=(o.clientX-a.left)/n,t.mouseY=(o.clientY-a.top)/s,"webgpu"==r.renderer&&(t.mouseX-=r.hw,t.mouseY-=r.hh)}else t.mouseX=o.clientX,t.mouseY=o.clientY},e._onmousedown=o=>{e._startAudio(),e._updateMouse(o),t.mouseIsPressed=!0,t.mouseButton=a[o.button],e.mousePressed(o)},e._onmousemove=t=>{e._updateMouse(t),e.mouseIsPressed?e.mouseDragged(t):e.mouseMoved(t)},e._onmouseup=o=>{e._updateMouse(o),t.mouseIsPressed=!1,e.mouseReleased(o)},e._onclick=o=>{e._updateMouse(o),t.mouseIsPressed=!0,e.mouseClicked(o),t.mouseIsPressed=!1},e.cursor=(t,o,a)=>{let r="";t.includes(".")&&(t=`url("${t}")`,r=", auto"),void 0!==o&&(t+=" "+o+" "+a),e.canvas.style.cursor=t+r},e.noCursor=()=>{e.canvas.style.cursor="none"},e.requestPointerLock=document.body?.requestPointerLock,e.exitPointerLock=document.exitPointerLock,e._onkeydown=a=>{a.repeat||(e._startAudio(),t.keyIsPressed=!0,t.key=a.key,t.keyCode=a.keyCode,o[e.keyCode]=o[e.key.toLowerCase()]=!0,e.keyPressed(a),1==a.key.length&&e.keyTyped(a))},e._onkeyup=a=>{t.keyIsPressed=!1,t.key=a.key,t.keyCode=a.keyCode,o[e.keyCode]=o[e.key.toLowerCase()]=!1,e.keyReleased(a)},e.keyIsDown=e=>!!o["string"==typeof e?e.toLowerCase():e],e._ontouchstart=o=>{e._startAudio(),t.touches=[...o.touches].map(n),e._isTouchAware||(t.mouseX=e.touches[0].x,t.mouseY=e.touches[0].y,t.mouseIsPressed=!0,t.mouseButton=e.LEFT,e.mousePressed(o)||o.preventDefault()),e.touchStarted(o)||o.preventDefault()},e._ontouchmove=o=>{t.touches=[...o.touches].map(n),e._isTouchAware||(t.mouseX=e.touches[0].x,t.mouseY=e.touches[0].y,e.mouseDragged(o)||o.preventDefault()),e.touchMoved(o)||o.preventDefault()},e._ontouchend=o=>{t.touches=[...o.touches].map(n),e._isTouchAware||e.touches.length||(t.mouseIsPressed=!1,e.mouseReleased(o)||o.preventDefault()),e.touchEnded(o)||o.preventDefault()},r&&(r.addEventListener("mousedown",(t=>e._onmousedown(t))),r.addEventListener("mouseup",(t=>e._onmouseup(t))),r.addEventListener("click",(t=>e._onclick(t))),r.addEventListener("touchstart",(t=>e._ontouchstart(t))),r.addEventListener("touchmove",(t=>e._ontouchmove(t))),r.addEventListener("touchcancel",(t=>e._ontouchend(t))),r.addEventListener("touchend",(t=>e._ontouchend(t)))),window){let t=window.addEventListener;t("mousemove",(t=>e._onmousemove(t)),!1),t("keydown",(t=>e._onkeydown(t)),!1),t("keyup",(t=>e._onkeyup(t)),!1)}},Q5.modules.math=(e,t)=>{e.DEGREES="degrees",e.RADIANS="radians",e.PI=Math.PI,e.HALF_PI=Math.PI/2,e.QUARTER_PI=Math.PI/4,e.abs=Math.abs,e.ceil=Math.ceil,e.exp=Math.exp,e.floor=Math.floor,e.loge=Math.log,e.mag=Math.hypot,e.max=Math.max,e.min=Math.min,e.round=Math.round,e.pow=Math.pow,e.sqrt=Math.sqrt,e.SHR3=1,e.LCG=2,e.angleMode=t=>e._angleMode=t,e._DEGTORAD=Math.PI/180,e._RADTODEG=180/Math.PI,e.degrees=t=>t*e._RADTODEG,e.radians=t=>t*e._DEGTORAD,e.map=Q5.prototype.map=(e,t,o,a,r,n)=>{let s=a+1*(e-t)/(o-t)*(r-a);return n?a<r?Math.min(Math.max(s,a),r):Math.min(Math.max(s,r),a):s},e.lerp=(e,t,o)=>e*(1-o)+t*o,e.constrain=(e,t,o)=>Math.min(Math.max(e,t),o),e.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])},e.norm=(t,o,a)=>e.map(t,o,a,0,1),e.sq=e=>e*e,e.fract=e=>e-Math.floor(e);for(let t of["sin","cos","tan"])e[t]=o=>("degrees"==e._angleMode&&(o=e.radians(o)),Math[t](o));for(let t of["asin","acos","atan"])e[t]=o=>{let a=Math[t](o);return"degrees"==e._angleMode&&(a=e.degrees(a)),a};function o(){let e,t,o=4294967295;return{setSeed(a){e=t=(a??Math.random()*o)>>>0},getSeed:()=>t,rand:()=>(e^=e<<17,e^=e>>13,e^=e<<5,(e>>>0)/o)}}e.atan2=(t,o)=>{let a=Math.atan2(t,o);return"degrees"==e._angleMode&&(a=e.degrees(a)),a};let a=o();a.setSeed(),e.randomSeed=e=>a.setSeed(e),e.random=(e,t)=>void 0===e?a.rand():"number"==typeof e?void 0!==t?a.rand()*(t-e)+e:a.rand()*e:e[Math.trunc(e.length*a.rand())],e.randomGenerator=t=>{t==e.LCG?a=function(){const e=4294967296;let t,o;return{setSeed(a){o=t=(a??Math.random()*e)>>>0},getSeed:()=>t,rand:()=>(o=(1664525*o+1013904223)%e,o/e)}}():t==e.SHR3&&(a=o()),a.setSeed()};var r=new function(){var e,t,o,r=new Array(128),n=new Array(256),s=new Array(128),i=new Array(128),l=new Array(256),c=new Array(256),d=()=>4294967296*a.rand()-2147483648,h=()=>.5+2.328306e-10*(d()|0),u=()=>{for(var t,a,n,l,c=3.44262;;){if(t=o*s[e],0==e){do{n=h(),l=h(),t=.2904764*-Math.log(n),a=-Math.log(l)}while(a+a<t*t);return o>0?c+t:-c-t}if(i[e]+h()*(i[e-1]-i[e])<Math.exp(-.5*t*t))return t;if(o=d(),e=127&o,Math.abs(o)<r[e])return o*s[e]}},_=()=>{for(var o;;){if(0==e)return 7.69711-Math.log(h());if(o=t*l[e],c[e]+h()*(c[e-1]-c[e])<Math.exp(-o))return o;if((t=d())<n[e=255&t])return t*l[e]}};this.SHR3=d,this.UNI=h,this.RNOR=()=>(o=d(),e=127&o,Math.abs(o)<r[e]?o*s[e]:u()),this.REXP=()=>(t=d()>>>0)<r[e=255&t]?t*l[e]:_(),this.zigset=()=>{var e,t,o=2147483648,a=4294967296,d=3.442619855899,h=d,u=.00991256303526217,_=7.697117470131487,p=_,g=.003949659822581572;for(e=u/Math.exp(-.5*d*d),r[0]=Math.floor(d/e*o),r[1]=0,s[0]=e/o,s[127]=d/o,i[0]=1,i[127]=Math.exp(-.5*d*d),t=126;t>=1;t--)d=Math.sqrt(-2*Math.log(u/d+Math.exp(-.5*d*d))),r[t+1]=Math.floor(d/h*o),h=d,i[t]=Math.exp(-.5*d*d),s[t]=d/o;for(e=g/Math.exp(-_),n[0]=Math.floor(_/e*a),n[1]=0,l[0]=e/a,l[255]=_/a,c[0]=1,c[255]=Math.exp(-_),t=254;t>=1;t--)_=-Math.log(g/_+Math.exp(-_)),n[t+1]=Math.floor(_/p*a),p=_,c[t]=Math.exp(-_),l[t]=_/a}};let n;r.hasInit=!1,e.randomGaussian=(e,t)=>(r.hasInit||(r.zigset(),r.hasInit=!0),r.RNOR()*t+e),e.randomExponential=()=>(r.hasInit||(r.zigset(),r.hasInit=!0),r.REXP()),e.PERLIN="perlin",e.SIMPLEX="simplex",e.BLOCKY="blocky",e.Noise=Q5.PerlinNoise,e.noiseMode=e=>{t.Noise=Q5[e[0].toUpperCase()+e.slice(1)+"Noise"],n=null},e.noiseSeed=t=>{n=new e.Noise(t)},e.noise=(t=0,o=0,a=0)=>(n??=new e.Noise,n.noise(t,o,a)),e.noiseDetail=(t,o)=>{n??=new e.Noise,t>0&&(n.octaves=t),o>0&&(n.falloff=o)}},Q5.Noise=class{},Q5.PerlinNoise=class extends Q5.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,o,a=[];for(let e=0;e<256;e++)a[e]=e;for(let r=255;r>0;r--)t=(e=16807*e%2147483647)%(r+1),o=a[r],a[r]=a[t],a[t]=o;return a}dot(e,t,o,a){return e[0]*t+e[1]*o+e[2]*a}mix(e,t,o){return(1-o)*e+o*t}fade(e){return e*e*e*(e*(6*e-15)+10)}noise(e,t,o){let a=this,r=0,n=1,s=1,i=0;for(let l=0;l<a.octaves;l++){const l=255&Math.floor(e*n),c=255&Math.floor(t*n),d=255&Math.floor(o*n),h=e*n-Math.floor(e*n),u=t*n-Math.floor(t*n),_=o*n-Math.floor(o*n),p=a.fade(h),g=a.fade(u),x=a.fade(_),m=a.p[l]+c,f=a.p[m]+d,y=a.p[m+1]+d,v=a.p[l+1]+c,w=a.p[v]+d,C=a.p[v+1]+d,M=a.mix(a.dot(a.grad3[a.p[f]%12],h,u,_),a.dot(a.grad3[a.p[w]%12],h-1,u,_),p),S=a.mix(a.dot(a.grad3[a.p[y]%12],h,u-1,_),a.dot(a.grad3[a.p[C]%12],h-1,u-1,_),p),b=a.mix(a.dot(a.grad3[a.p[f+1]%12],h,u,_-1),a.dot(a.grad3[a.p[w+1]%12],h-1,u,_-1),p),R=a.mix(a.dot(a.grad3[a.p[y+1]%12],h,u-1,_-1),a.dot(a.grad3[a.p[C+1]%12],h-1,u-1,_-1),p),Q=a.mix(M,S,g),E=a.mix(b,R,g);r+=a.mix(Q,E,x)*s,i+=s,s*=a.falloff,n*=2}return(r/i+1)/2}},Q5.modules.sound=(e,t)=>{e.Sound=Q5.Sound,e.loadSound=(e,o)=>{t._preloadCount++,Q5.aud??=new window.AudioContext;let a=new Q5.Sound(e,o);return a.addEventListener("canplaythrough",(()=>{t._preloadCount--,a.loaded=!0,o&&o(a)})),a},e.getAudioContext=()=>Q5.aud,e.userStartAudio=()=>Q5.aud.resume()},Q5.Sound=class extends Audio{constructor(e){super(e);let t=this;t.load(),t.panner=Q5.aud.createStereoPanner(),t.source=Q5.aud.createMediaElementSource(t),t.source.connect(t.panner),t.panner.connect(Q5.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}},Q5.modules.util=(e,t)=>{e._loadFile=(e,o,a)=>{t._preloadCount++;let r={};return fetch(e).then((e=>"json"==a?e.json():"text"==a?e.text():void 0)).then((e=>{t._preloadCount--,Object.assign(r,e),o&&o(e)})),r},e.loadStrings=(t,o)=>e._loadFile(t,o,"text"),e.loadJSON=(t,o)=>e._loadFile(t,o,"json"),"object"==typeof localStorage&&(e.storeItem=localStorage.setItem,e.getItem=localStorage.getItem,e.removeItem=localStorage.removeItem,e.clearStorage=localStorage.clear),e.year=()=>(new Date).getFullYear(),e.day=()=>(new Date).getDay(),e.hour=()=>(new Date).getHours(),e.minute=()=>(new Date).getMinutes(),e.second=()=>(new Date).getSeconds()},Q5.modules.vector=e=>{e.createVector=(t,o,a)=>new Q5.Vector(t,o,a,e)},Q5.Vector=class{constructor(e,t,o,a){this.x=e||0,this.y=t||0,this.z=o||0,this._$=a||window,this._cn=null,this._cnsq=null}set(e,t,o){this.x=e||0,this.y=t||0,this.z=o||0}copy(){return new Q5.Vector(this.x,this.y,this.z)}_arg2v(e,t,o){return void 0!==e?.x?e:void 0!==t?{x:e,y:t,z:o||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,o=this.y-e.y,a=this.z-e.z;return Math.sqrt(t*t+o*o+a*a)}cross(){let e=this._arg2v(...arguments),t=this.y*e.z-this.z*e.y,o=this.z*e.x-this.x*e.z,a=this.x*e.y-this.y*e.x;return this.x=t,this.y=o,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 o=e/t;this.x*=o,this.y*=o,this.z*=o,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)}rotate(e){let t=this._$.cos(e),o=this._$.sin(e),a=this.x*t-this.y*o,r=this.x*o+this.y*t;return this.x=a,this.y=r,this}angleBetween(){let e=this._arg2v(...arguments),t=Q5.Vector.cross(this,e);return this._$.atan2(t.mag(),this.dot(e))*Math.sign(t.z||1)}lerp(){let e=[...arguments],t=this._arg2v(...e.slice(0,-1)),o=e.at(-1);return this.x+=(t.x-this.x)*o,this.y+=(t.y-this.y)*o,this.z+=(t.z-this.z)*o,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,o){void 0===o&&(o=1),this._cn=o,this._cnsq=o*o;const a=this._$.cos(t),r=this._$.sin(t),n=this._$.cos(e),s=this._$.sin(e);return this.x=o*s*r,this.y=-o*n,this.z=o*s*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}]`}},Q5.Vector.add=(e,t)=>e.copy().add(t),Q5.Vector.cross=(e,t)=>e.copy().cross(t),Q5.Vector.dist=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y,e.z-t.z),Q5.Vector.div=(e,t)=>e.copy().div(t),Q5.Vector.dot=(e,t)=>e.copy().dot(t),Q5.Vector.equals=(e,t,o)=>e.equals(t,o),Q5.Vector.lerp=(e,t,o)=>e.copy().lerp(t,o),Q5.Vector.limit=(e,t)=>e.copy().limit(t),Q5.Vector.heading=e=>this._$.atan2(e.y,e.x),Q5.Vector.magSq=e=>e.x*e.x+e.y*e.y+e.z*e.z,Q5.Vector.mag=e=>Math.sqrt(Q5.Vector.magSq(e)),Q5.Vector.mult=(e,t)=>e.copy().mult(t),Q5.Vector.normalize=e=>e.copy().normalize(),Q5.Vector.rem=(e,t)=>e.copy().rem(t),Q5.Vector.sub=(e,t)=>e.copy().sub(t);for(let e of["fromAngle","fromAngles","random2D","random3D"])Q5.Vector[e]=(t,o,a)=>(new Q5.Vector)[e](t,o,a);