q5 2.2.3 → 2.2.4

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
@@ -339,13 +339,13 @@ Unminified:
339
339
 
340
340
  - p5.js **5112kb** ⚠️
341
341
  - p5.sound.js 488kb
342
- - q5.js 83kb
342
+ - q5.js 90kb
343
343
 
344
344
  Minified:
345
345
 
346
346
  - p5.min.js 1034kb ⚠️
347
347
  - p5.sound.min.js 200kb
348
- - q5.min.js **54kb** 🎉
348
+ - q5.min.js **58kb** 🎉
349
349
 
350
350
  ## Benchmarks
351
351
 
@@ -410,6 +410,9 @@ https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline
410
410
  ziggurat:
411
411
  http://ziggurat.glitch.me/
412
412
 
413
+ Vector.slerp:
414
+ https://github.com/processing/p5.js/blob/v1.10.0/src/math/p5.Vector.js#L2803
415
+
413
416
  random:
414
417
  https://github.com/processing/p5.js/blob/1.1.9/src/math/noise.js
415
418
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q5",
3
- "version": "2.2.3",
3
+ "version": "2.2.4",
4
4
  "description": "A sequel to p5.js that's smaller and faster",
5
5
  "author": "quinton-ashley",
6
6
  "contributors": [
@@ -12,9 +12,8 @@
12
12
  "main": "q5-server.js",
13
13
  "scripts": {
14
14
  "bundle": "cat src/q5-core.js src/q5-canvas.js src/q5-2d-canvas.js src/q5-2d-drawing.js src/q5-2d-image.js src/q5-2d-text.js src/q5-ai.js src/q5-color.js src/q5-display.js src/q5-input.js src/q5-math.js src/q5-sound.js src/q5-util.js src/q5-vector.js src/q5-webgpu-canvas.js src/q5-webgpu-drawing.js src/q5-webgpu-image.js src/q5-webgpu-text.js > q5.js",
15
- "bundle-q2d": "cat src/q5-core.js src/q5-canvas.js src/q5-2d-canvas.js src/q5-2d-drawing.js src/q5-2d-image.js src/q5-2d-soft-filters.js src/q5-2d-text.js src/q5-ai.js src/q5-color.js src/q5-display.js src/q5-input.js src/q5-math.js src/q5-sound.js src/q5-util.js src/q5-vector.js > q5-q2d.js",
16
- "min": "terser q5.js --compress ecma=2024 --mangle > q5.min.js && terser q5-q2d.js --compress ecma=2024 --mangle > q5-q2d.min.js",
17
- "dist": "bun bundle && bun bundle-q2d && bun min",
15
+ "min": "terser q5.js --compress ecma=2024 --mangle > q5.min.js",
16
+ "dist": "bun bundle && bun min",
18
17
  "dist-p5play": "bun dist && cp q5.js ../../web/p5play-web/v3/q5.js && cp q5.min.js ../../web/p5play-web/v3/q5.min.js",
19
18
  "v": "npm version patch --force",
20
19
  "V": "npm version minor --force",
package/q5.js CHANGED
@@ -219,7 +219,7 @@ function Q5(scope, parent, renderer) {
219
219
  return t[k]();
220
220
  } catch (e) {
221
221
  if ($._aiErrorAssistance) $._aiErrorAssistance(e);
222
- else console.error(e);
222
+ throw e;
223
223
  }
224
224
  };
225
225
  }
@@ -1603,8 +1603,7 @@ Q5.modules.ai = ($) => {
1603
1603
 
1604
1604
  $._aiErrorAssistance = async (e) => {
1605
1605
  let askAI = e.message?.includes('Ask AI ✨');
1606
- if (!askAI) console.error(e);
1607
- if (Q5.disableFriendlyErrors) return;
1606
+ if (Q5.disableFriendlyErrors && !askAI) return;
1608
1607
  if (askAI || !Q5.errorTolerant) $.noLoop();
1609
1608
  let stackLines = e.stack?.split('\n');
1610
1609
  if (!e.stack || stackLines.length <= 1) return;
@@ -1615,7 +1614,7 @@ Q5.modules.ai = ($) => {
1615
1614
  idx = 0;
1616
1615
  sep = '@';
1617
1616
  }
1618
- while (stackLines[idx].indexOf('q5.js:') >= 0) idx++;
1617
+ while (stackLines[idx].indexOf('q5') >= 0) idx++;
1619
1618
 
1620
1619
  let parts = stackLines[idx].split(sep).at(-1);
1621
1620
  parts = parts.split(':');
@@ -1653,11 +1652,11 @@ Q5.modules.ai = ($) => {
1653
1652
  '%0A%0AExcerpt+for+context%3A%0A%0A' +
1654
1653
  encodeURIComponent(context);
1655
1654
 
1656
- if (!askAI) console.log('Error in ' + fileBase + ' on line ' + lineNum + ':\n\n' + errLine);
1655
+ console.warn('Error in ' + fileBase + ' on line ' + lineNum + ':\n\n' + errLine);
1657
1656
 
1658
1657
  console.warn('Ask AI ✨ ' + url);
1659
1658
 
1660
- if (askAI) window.open(url, '_blank');
1659
+ if (askAI) return window.open(url, '_blank');
1661
1660
  } catch (err) {}
1662
1661
  };
1663
1662
  };
@@ -1750,12 +1749,7 @@ Q5.modules.color = ($, q) => {
1750
1749
  if (c3) c3 /= 255;
1751
1750
  }
1752
1751
  }
1753
- if (Array.isArray(c0)) {
1754
- c1 = c0[1];
1755
- c2 = c0[2];
1756
- c3 = c0[3];
1757
- c0 = c0[0];
1758
- }
1752
+ if (Array.isArray(c0)) [c0, c1, c2, c3] = c0;
1759
1753
  }
1760
1754
 
1761
1755
  if (c2 == undefined) return new C(c0, c0, c0, c1);
@@ -1767,11 +1761,11 @@ Q5.modules.color = ($, q) => {
1767
1761
  $.blue = (c) => c.b;
1768
1762
  $.alpha = (c) => c.a;
1769
1763
  $.lightness = (c) => {
1770
- if ($._colorMode == 'oklch') return c.l;
1764
+ if (c.l) return c.l;
1771
1765
  return ((0.2126 * c.r + 0.7152 * c.g + 0.0722 * c.b) * 100) / 255;
1772
1766
  };
1773
1767
  $.hue = (c) => {
1774
- if ($._colorMode == 'oklch') return c.h;
1768
+ if (c.h) return c.h;
1775
1769
  let r = c.r;
1776
1770
  let g = c.g;
1777
1771
  let b = c.b;
@@ -2687,18 +2681,19 @@ Q5.modules.vector = ($) => {
2687
2681
  };
2688
2682
 
2689
2683
  Q5.Vector = class {
2690
- constructor(_x, _y, _z, _$) {
2691
- this.x = _x || 0;
2692
- this.y = _y || 0;
2693
- this.z = _z || 0;
2694
- this._$ = _$ || window;
2684
+ constructor(x, y, z, $) {
2685
+ this.x = x || 0;
2686
+ this.y = y || 0;
2687
+ this.z = z || 0;
2688
+ this._$ = $ || window;
2695
2689
  this._cn = null;
2696
2690
  this._cnsq = null;
2697
2691
  }
2698
- set(_x, _y, _z) {
2699
- this.x = _x || 0;
2700
- this.y = _y || 0;
2701
- this.z = _z || 0;
2692
+ set(x, y, z) {
2693
+ this.x = x?.x || x || 0;
2694
+ this.y = x?.y || y || 0;
2695
+ this.z = x?.z || z || 0;
2696
+ return this;
2702
2697
  }
2703
2698
  copy() {
2704
2699
  return new Q5.Vector(this.x, this.y, this.z);
@@ -2820,6 +2815,12 @@ Q5.Vector = class {
2820
2815
  heading() {
2821
2816
  return this._$.atan2(this.y, this.x);
2822
2817
  }
2818
+ setHeading(ang) {
2819
+ let mag = this.mag(); // Calculate the magnitude of the vector
2820
+ this.x = mag * this._$.cos(ang); // Set the new x component
2821
+ this.y = mag * this._$.sin(ang); // Set the new y component
2822
+ return this;
2823
+ }
2823
2824
  rotate(ang) {
2824
2825
  let costh = this._$.cos(ang);
2825
2826
  let sinth = this._$.sin(ang);
@@ -2837,13 +2838,52 @@ Q5.Vector = class {
2837
2838
  }
2838
2839
  lerp() {
2839
2840
  let args = [...arguments];
2840
- let u = this._arg2v(...args.slice(0, -1));
2841
2841
  let amt = args.at(-1);
2842
+ if (amt == 0) return this;
2843
+ let u = this._arg2v(...args.slice(0, -1));
2842
2844
  this.x += (u.x - this.x) * amt;
2843
2845
  this.y += (u.y - this.y) * amt;
2844
2846
  this.z += (u.z - this.z) * amt;
2845
2847
  return this;
2846
2848
  }
2849
+ slerp() {
2850
+ let args = [...arguments];
2851
+ let amt = args.at(-1);
2852
+ if (amt == 0) return this;
2853
+ let u = this._arg2v(...args.slice(0, -1));
2854
+ if (amt == 1) return this.set(u);
2855
+
2856
+ let v0Mag = this.mag();
2857
+ let v1Mag = u.mag();
2858
+
2859
+ if (v0Mag == 0 || v1Mag == 0) {
2860
+ return this.mult(1 - amt).add(u.mult(amt));
2861
+ }
2862
+
2863
+ let axis = Q5.Vector.cross(this, u);
2864
+ let axisMag = axis.mag();
2865
+ let theta = Math.atan2(axisMag, this.dot(u));
2866
+
2867
+ if (axisMag > 0) {
2868
+ axis.div(axisMag);
2869
+ } else if (theta < this._$.HALF_PI) {
2870
+ return this.mult(1 - amt).add(u.mult(amt));
2871
+ } else {
2872
+ if (this.z == 0 && u.z == 0) axis.set(0, 0, 1);
2873
+ else if (this.x != 0) axis.set(this.y, -this.x, 0).normalize();
2874
+ else axis.set(1, 0, 0);
2875
+ }
2876
+
2877
+ let ey = axis.cross(this);
2878
+ let lerpedMagFactor = 1 - amt + (amt * v1Mag) / v0Mag;
2879
+ let cosMultiplier = lerpedMagFactor * Math.cos(amt * theta);
2880
+ let sinMultiplier = lerpedMagFactor * Math.sin(amt * theta);
2881
+
2882
+ this.x = this.x * cosMultiplier + ey.x * sinMultiplier;
2883
+ this.y = this.y * cosMultiplier + ey.y * sinMultiplier;
2884
+ this.z = this.z * cosMultiplier + ey.z * sinMultiplier;
2885
+ return this;
2886
+ }
2847
2887
  reflect(n) {
2848
2888
  n.normalize();
2849
2889
  return this.sub(n.mult(2 * this.dot(n)));
@@ -2896,6 +2936,7 @@ Q5.Vector.div = (v, u) => v.copy().div(u);
2896
2936
  Q5.Vector.dot = (v, u) => v.copy().dot(u);
2897
2937
  Q5.Vector.equals = (v, u, epsilon) => v.equals(u, epsilon);
2898
2938
  Q5.Vector.lerp = (v, u, amt) => v.copy().lerp(u, amt);
2939
+ Q5.Vector.slerp = (v, u, amt) => v.copy().slerp(u, amt);
2899
2940
  Q5.Vector.limit = (v, m) => v.copy().limit(m);
2900
2941
  Q5.Vector.heading = (v) => this._$.atan2(v.y, v.x);
2901
2942
  Q5.Vector.magSq = (v) => v.x * v.x + v.y * v.y + v.z * v.z;
@@ -3684,7 +3725,6 @@ fn fragmentMain(@location(0) texCoord: vec2<f32>, @location(1) textureIndex: f32
3684
3725
  img.index = $.textures.length;
3685
3726
  $.textures.push(texture);
3686
3727
  };
3687
- img.onerror = reject;
3688
3728
  img.src = src;
3689
3729
  return img;
3690
3730
  };
package/q5.min.js CHANGED
@@ -5,4 +5,4 @@
5
5
  * @license LGPL-3.0
6
6
  * @class Q5
7
7
  */
8
- function Q5(e,t,r){let o,a=this;if(a._q5=!0,a._parent=t,a._renderer=r||"q2d",a._preloadCount=0,e??="global","auto"==e){if(!window.setup&&!window.draw)return;e="global"}a._scope=e,"global"==e&&(Q5._hasGlobal=a._isGlobal=!0,o=Q5._nodejs?global:window);let n=new Proxy(a,{set:(e,t,r)=>(a[t]=r,a._isGlobal&&(o[t]=r),!0)});a.canvas=a.ctx=a.drawingContext=null,a.pixels=[];let i=null;a.frameCount=0,a.deltaTime=16,a._targetFrameRate=0,a._targetFrameDuration=16.666666666666668,a._frameRate=a._fps=60,a._loop=!0,a._hooks={postCanvas:[],preRender:[]};let s=0;a.millis=()=>performance.now()-s,a.noCanvas=()=>{a.canvas?.remove&&a.canvas.remove(),a.canvas=0,n.ctx=n.drawingContext=0},window&&(a.windowWidth=window.innerWidth,a.windowHeight=window.innerHeight,a.deviceOrientation=window.screen?.orientation?.type),a._incrementPreload=()=>n._preloadCount++,a._decrementPreload=()=>n._preloadCount--,a._draw=e=>{let t=e||performance.now();if(a._lastFrameTime??=t-a._targetFrameDuration,a._shouldResize&&(a.windowResized(),a._shouldResize=!1),a._loop)i=c(a._draw);else if(a.frameCount&&!a._redraw)return;if(i&&a.frameCount){if(t-a._lastFrameTime<a._targetFrameDuration-4)return}n.deltaTime=t-a._lastFrameTime,a._frameRate=1e3/a.deltaTime,n.frameCount++;let r=performance.now();a.ctx&&a.resetMatrix(),a._beginRender&&a._beginRender();for(let e of Q5.methods.pre)e.call(a);a.draw(),a._render&&a._render();for(let e of Q5.methods.post)e.call(a);a._finishRender&&a._finishRender(),n.pmouseX=a.mouseX,n.pmouseY=a.mouseY,a._lastFrameTime=t;let o=performance.now();a._fps=Math.round(1e3/(o-r))},a.noLoop=()=>{a._loop=!1,i=null},a.loop=()=>{a._loop=!0,null==i&&a._draw()},a.isLooping=()=>a._loop,a.redraw=(e=1)=>{a._redraw=!0;for(let t=0;t<e;t++)a._draw();a._redraw=!1},a.remove=()=>{a.noLoop(),a.canvas.remove()},a.frameRate=e=>(e&&(a._targetFrameRate=e,a._targetFrameDuration=1e3/e),a._frameRate),a.getTargetFrameRate=()=>a._targetFrameRate,a.getFPS=()=>a._fps,a.Element=function(e){this.elt=e},a._elements=[],a.TWO_PI=a.TAU=2*Math.PI,a.log=a.print=console.log,a.describe=()=>{};for(let e in Q5.modules)Q5.modules[e](a,n);let l=Q5.renderers[a._renderer];for(let e in l)l[e](a,n);for(let e in Q5)"_"!=e[1]&&e[1]==e[1].toUpperCase()&&(a[e]=Q5[e]);if("graphics"==e)return;"global"==e&&(Object.assign(Q5,a),delete Q5.Q5);for(let e of Q5.methods.init)e.call(a);for(let[e,t]of Object.entries(Q5.prototype))"_"!=e[0]&&"function"==typeof a[e]&&(a[e]=t.bind(a));if("global"==e){let e=Object.getOwnPropertyNames(a);for(let t of e)"_"!=t[0]&&(o[t]=a[t])}"function"==typeof e&&e(a),Q5._instanceCount++;let c=window.requestAnimationFrame||function(e){const t=a._lastFrameTime+a._targetFrameDuration;return setTimeout((()=>{e(t)}),t-performance.now())},d=o||a;a._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]?a._isGlobal&&(a[e]=()=>{try{return d[e]()}catch(e){a._aiErrorAssistance?a._aiErrorAssistance(e):console.error(e)}}):a[e]=()=>{};async function p(){if(a._startDone=!0,a._preloadCount>0)return c(p);s=performance.now(),await a.setup(),a.frameCount||(null===a.ctx&&a.createCanvas(100,100),a._setupDone=!0,a.ctx&&a.resetMatrix(),c(a._draw))}(a.setup||a.draw)&&(arguments.length&&"namespace"!=e&&"webgpu"!=r||h?(a.preload(),p()):(d.preload=a.preload=()=>{a._startDone||p()},setTimeout(a.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 r=e.canvas;if(r.width=e.width=100,r.height=e.height=100,"image"!=e._scope&&(r.renderer=e._renderer,r[e._renderer]=!0),e._pixelDensity=1,e._adjustDisplay=()=>{r.style&&(r.style.width=r.w+"px",r.style.height=r.h+"px")},e.createCanvas=function(t,o,a){a??=arguments[3];let n=Object.assign({},Q5.canvasOptions);if("object"==typeof a&&Object.assign(n,a),"image"!=e._scope){let t=e.displayDensity();"graphics"==e._scope?t=this._pixelDensity:window.IntersectionObserver&&new IntersectionObserver((e=>{r.visible=e[0].isIntersecting})).observe(r),e._pixelDensity=Math.ceil(t)}e._setCanvasSize(t,o),Object.assign(r,n);let i=e._createCanvas(r.w,r.h,n);if(e._hooks)for(let t of e._hooks.postCanvas)t();return i},e._save=async(e,t,r)=>{if(t=t||"untitled","jpg"==(r=r||"png")||"png"==r||"webp"==r)if(e instanceof OffscreenCanvas){const t=await e.convertToBlob({type:"image/"+r});e=await new Promise((e=>{const r=new FileReader;r.onloadend=()=>e(r.result),r.readAsDataURL(t)}))}else e=e.toDataURL("image/"+r);else{let t="text/plain";"json"==r&&("string"!=typeof e&&(e=JSON.stringify(e)),t="text/json"),e=new Blob([e],{type:t}),e=URL.createObjectURL(e)}let o=document.createElement("a");o.href=e,o.download=t+"."+r,o.click(),URL.revokeObjectURL(o.href)},e.save=(t,r,o)=>{if((!t||"string"==typeof t&&(!r||!o&&r.length<5))&&(o=r,r=t,t=e.canvas),o)return e._save(t,r,o);r?(r=r.split("."),e._save(t,r[0],r.at(-1))):e._save(t)},e._setCanvasSize=(o,a)=>{o??=window.innerWidth,a??=window.innerHeight,r.w=o=Math.ceil(o),r.h=a=Math.ceil(a),r.hw=o/2,r.hh=a/2,r.width=Math.ceil(o*e._pixelDensity),r.height=Math.ceil(a*e._pixelDensity),e._da?e.flexibleCanvas(e._dau):(t.width=o,t.height=a),e.displayMode&&!r.displayMode?e.displayMode():e._adjustDisplay()},"image"!=e._scope){if(r&&"graphics"!=e._scope){function o(){let t=e._parent;t??=document.getElementsByTagName("main")[0],t||(t=document.createElement("main"),document.body.append(t)),r.parent(t)}r.parent=t=>{function o(){e.frameCount>1&&(e._shouldResize=!0,e._adjustDisplay())}r.parentElement&&r.parentElement.removeChild(r),"string"==typeof t&&(t=document.getElementById(t)),t.append(r),"function"==typeof ResizeObserver?(e._ro&&e._ro.disconnect(),e._ro=new ResizeObserver(o),e._ro.observe(t)):e.frameCount||window.addEventListener("resize",o)},document.body?o():document.addEventListener("DOMContentLoaded",o)}e.resizeCanvas=(t,o)=>{if(!e.ctx)return e.createCanvas(t,o);t==r.w&&o==r.h||e._resizeCanvas(t,o)},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(r.w,r.h),t):e._pixelDensity,e.flexibleCanvas=(o=400)=>{o?(e._da=r.width/(o*e._pixelDensity),t.width=e._dau=o,t.height=r.h/r.w*o):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 r=e.canvas;e.colorMode&&e.colorMode("rgb","integer"),e._createCanvas=function(o,a,n){return t.ctx=t.drawingContext=r.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(),r},"image"!=e._scope&&(e._resizeCanvas=(t,o)=>{let a={};for(let t in e.ctx)"function"!=typeof e.ctx[t]&&(a[t]=e.ctx[t]);delete a.canvas;let n=new e._OffscreenCanvas(r.width,r.height);n.w=r.w,n.h=r.h,n.getContext("2d").drawImage(r,0,0),e._setCanvasSize(t,o);for(let t in a)e.ctx[t]=a[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,r)=>{e._da&&(t*=e._da,r*=e._da),e.ctx.translate(t,r)},e.rotate=t=>{"degrees"==e._angleMode&&(t=e.radians(t)),e.ctx.rotate(t)},e.scale=(t,r)=>{r??=t,e.ctx.scale(t,r)},e.opacity=t=>e.ctx.globalAlpha=t,e.applyMatrix=(t,r,o,a,n,i)=>e.ctx.transform(t,r,o,a,n,i),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 r of e._styleNames)t[r]=e[r];e._styles.push(t)},e.pop=e.popMatrix=()=>{e.ctx.restore();let t=e._styles.pop();for(let r of e._styleNames)e[r]=t[r]},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,r,o){let a=new Q5("graphics");return o??={},o.alpha??=!0,o.colorSpace??=e.canvas.colorSpace,a.createCanvas.call(e,t,r,o),a},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,r=[];function o(){e._doFill&&e.ctx.fill(),e._doStroke&&e.ctx.stroke()}function a(t,r,a,n,i,s,l,c){if(!e._doFill&&!e._doStroke)return;let d="degrees"==e._angleMode,h=d?360:e.TAU;if((i%=h)<0&&(i+=h),(s%=h)<0&&(s+=h),0!=i||0!=s){if(i>s&&([i,s]=[s,i]),e.ctx.beginPath(),a==n)d&&(i=e.radians(i),s=e.radians(s)),e.ctx.arc(t,r,a/2,i,s);else{for(let o=0;o<c+1;o++){let l=o/c,d=e.lerp(i,s,l),h=e.cos(d)*a/2,u=e.sin(d)*n/2;e.ctx[o?"lineTo":"moveTo"](t+h,r+u)}l==e.CHORD?e.ctx.closePath():l==e.PIE&&(e.ctx.lineTo(t,r),e.ctx.closePath())}o()}}function n(t,r,a,n){(e._doFill||e._doStroke)&&(e._da&&(t*=e._da,r*=e._da,a*=e._da,n*=e._da),e.ctx.beginPath(),e.ctx.ellipse(t,r,a/2,n/2,0,0,e.TAU),o())}function i(t,r,a,n,s,l,c,d){if(e._doFill||e._doStroke){if(void 0===s)return function(t,r,a,n){e._da&&(t*=e._da,r*=e._da,a*=e._da,n*=e._da),e.ctx.beginPath(),e.ctx.rect(t,r,a,n),o()}(t,r,a,n);if(void 0===l)return i(t,r,a,n,s,s,s,s);e._da&&(t*=e._da,r*=e._da,a*=e._da,n*=e._da,s*=e._da,l*=e._da,d*=e._da,c*=e._da),e.ctx.roundRect(t,r,a,n,[s,l,c,d]),o()}}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,r,o,a)=>{e._doStroke&&(e._da&&(t*=e._da,r*=e._da,o*=e._da,a*=e._da),e.ctx.beginPath(),e.ctx.moveTo(t,r),e.ctx.lineTo(o,a),e.ctx.stroke())},e.arc=(t,r,o,n,i,s,l,c=25)=>{if(i==s)return e.ellipse(t,r,o,n);l??=e.PIE,e._ellipseMode==e.CENTER?a(t,r,o,n,i,s,l,c):e._ellipseMode==e.RADIUS?a(t,r,2*o,2*n,i,s,l,c):e._ellipseMode==e.CORNER?a(t+o/2,r+n/2,o,n,i,s,l,c):e._ellipseMode==e.CORNERS&&a((t+o)/2,(r+n)/2,o-t,n-r,i,s,l,c)},e.ellipse=(t,r,o,a)=>{a??=o,e._ellipseMode==e.CENTER?n(t,r,o,a):e._ellipseMode==e.RADIUS?n(t,r,2*o,2*a):e._ellipseMode==e.CORNER?n(t+o/2,r+a/2,o,a):e._ellipseMode==e.CORNERS&&n((t+o)/2,(r+a)/2,o-t,a-r)},e.circle=(t,r,a)=>{e._ellipseMode==e.CENTER?(e._da&&(t*=e._da,r*=e._da,a*=e._da),e.ctx.beginPath(),e.ctx.arc(t,r,a/2,0,e.TAU),o()):e.ellipse(t,r,a,a)},e.point=(t,r)=>{t.x&&(r=t.y,t=t.x),e._da&&(t*=e._da,r*=e._da),e.ctx.save(),e.ctx.beginPath(),e.ctx.arc(t,r,e.ctx.lineWidth/2,0,e.TAU),e.ctx.fillStyle=e.ctx.strokeStyle,e.ctx.fill(),e.ctx.restore()},e.rect=(t,r,o,a=o,n,s,l,c)=>{e._rectMode==e.CENTER?i(t-o/2,r-a/2,o,a,n,s,l,c):e._rectMode==e.RADIUS?i(t-o,r-a,2*o,2*a,n,s,l,c):e._rectMode==e.CORNER?i(t,r,o,a,n,s,l,c):e._rectMode==e.CORNERS&&i(t,r,o-t,a-r,n,s,l,c)},e.square=(t,r,o,a,n,i,s)=>e.rect(t,r,o,o,a,n,i,s),e.beginShape=()=>{r=[],e.ctx.beginPath(),t=!0},e.beginContour=()=>{e.ctx.closePath(),r=[],t=!0},e.endContour=()=>{r=[],t=!0},e.vertex=(o,a)=>{e._da&&(o*=e._da,a*=e._da),r=[],t?e.ctx.moveTo(o,a):e.ctx.lineTo(o,a),t=!1},e.bezierVertex=(t,o,a,n,i,s)=>{e._da&&(t*=e._da,o*=e._da,a*=e._da,n*=e._da,i*=e._da,s*=e._da),r=[],e.ctx.bezierCurveTo(t,o,a,n,i,s)},e.quadraticVertex=(t,o,a,n)=>{e._da&&(t*=e._da,o*=e._da,a*=e._da,n*=e._da),r=[],e.ctx.quadraticCurveTo(t,o,a,n)},e.bezier=(t,r,o,a,n,i,s,l)=>{e.beginShape(),e.vertex(t,r),e.bezierVertex(o,a,n,i,s,l),e.endShape()},e.triangle=(t,r,o,a,n,i)=>{e.beginShape(),e.vertex(t,r),e.vertex(o,a),e.vertex(n,i),e.endShape(e.CLOSE)},e.quad=(t,r,o,a,n,i,s,l)=>{e.beginShape(),e.vertex(t,r),e.vertex(o,a),e.vertex(n,i),e.vertex(s,l),e.endShape(e.CLOSE)},e.endShape=t=>{r=[],t&&e.ctx.closePath(),o()},e.curveVertex=(o,a)=>{if(e._da&&(o*=e._da,a*=e._da),r.push([o,a]),r.length<4)return;let n=function(e,t,r,o,a,n,i,s,l,c){function d(e,t,r,o,a,n){let i=Math.pow(o-t,2)+Math.pow(a-r,2);return Math.pow(i,.5*n)+e}let h=[],u=d(0,e,t,r,o,c),p=d(u,r,o,a,n,c),_=d(p,a,n,i,s,c);for(let c=0;c<l;c++){let d=u+c/(l-1)*(p-u),g=[(u-d)/(u-0),(d-0)/(u-0),(p-d)/(p-u),(d-u)/(p-u),(_-d)/(_-p),(d-p)/(_-p),(p-d)/(p-0),(d-0)/(p-0),(_-d)/(_-u),(d-u)/(_-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]+r*g[1],f=t*g[0]+o*g[1],m=r*g[2]+a*g[3],v=o*g[2]+n*g[3],y=a*g[4]+i*g[5],w=n*g[4]+s*g[5],S=x*g[6]+m*g[7],b=f*g[6]+v*g[7],C=m*g[8]+y*g[9],M=v*g[8]+w*g[9],Q=S*g[2]+C*g[3],R=b*g[2]+M*g[3];h.push([Q,R])}return h}(...r.at(-4),...r.at(-3),...r.at(-2),...r.at(-1),e._curveDetail,e._curveAlpha);for(let r=0;r<n.length;r++)t?e.ctx.moveTo(...n[r]):e.ctx.lineTo(...n[r]),t=!1},e.curve=(t,r,o,a,n,i,s,l)=>{e.beginShape(),e.curveVertex(t,r),e.curveVertex(o,a),e.curveVertex(n,i),e.curveVertex(s,l),e.endShape()},e.curvePoint=(e,t,r,o,a)=>{const n=a*a*a,i=a*a;return e*(-.5*n+i-.5*a)+t*(1.5*n-2.5*i+1)+r*(-1.5*n+2*i+.5*a)+o*(.5*n-.5*i)},e.bezierPoint=(e,t,r,o,a)=>{const n=1-a;return Math.pow(n,3)*e+3*Math.pow(n,2)*a*t+3*n*Math.pow(a,2)*r+Math.pow(a,3)*o},e.curveTangent=(e,t,r,o,a)=>{const n=a*a;return e*(-3*n/2+2*a-.5)+t*(9*n/2-5*a)+r*(-9*n/2+4*a+.5)+o*(3*n/2-a)},e.bezierTangent=(e,t,r,o,a)=>{const n=1-a;return 3*o*Math.pow(a,2)-3*r*Math.pow(a,2)+6*r*n*a-6*t*n*a+3*t*Math.pow(n,2)-3*e*Math.pow(n,2)},e.erase=function(t=255,r=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, ${r/255})`},e.noErase=function(){e.ctx.globalCompositeOperation="source-over",e.ctx.restore()},e.inFill=(t,r)=>{const o=e._pixelDensity;return e.ctx.isPointInPath(t*o,r*o)},e.inStroke=(t,r)=>{const o=e._pixelDensity;return e.ctx.isPointInStroke(t*o,r*o)}},Q5.renderers.q2d.image=(e,t)=>{Q5.Image??=class{constructor(e,t,r){let o=this;o._scope="image",o.canvas=o.ctx=o.drawingContext=null,o.pixels=[],Q5.modules.canvas(o,o);let a=Q5.renderers.q2d;for(let e of["canvas","image","soft_filters"])a[e]&&a[e](o,o);o.createCanvas(e,t,r),delete o.createCanvas,o._loop=!1}get w(){return this.width}get h(){return this.height}},e.createImage=(t,r,o)=>(o??={},o.alpha??=!0,o.colorSpace??=e.canvas.colorSpace||Q5.canvasOptions.colorSpace,new Q5.Image(t,r,o)),e.loadImage=function(r,o,a){if(r.canvas)return r;if("gif"==r.slice(-3).toLowerCase())throw new Error("q5 doesn't support GIFs due to their impact on performance. Use a video or animation instead.");t._preloadCount++;let n=[...arguments].at(-1);a="object"==typeof n?n:null;let i=e.createImage(1,1,a);function s(e){i.resize(e.naturalWidth||e.width,e.naturalHeight||e.height),i.ctx.drawImage(e,0,0),t._preloadCount--,o&&o(i)}if(Q5._nodejs&&global.CairoCanvas)global.CairoCanvas.loadImage(r).then(s).catch((e=>{throw t._preloadCount--,e}));else{let e=new window.Image;e.src=r,e.crossOrigin="Anonymous",e._pixelDensity=1,e.onload=()=>s(e),e.onerror=e=>{throw t._preloadCount--,e}}return i},e.imageMode=t=>e._imageMode=t,e.image=(t,r,o,a,n,i=0,s=0,l,c)=>{let d=t.canvas||t;Q5._createNodeJSCanvas&&(d=d.context.canvas),a??=t.width||t.videoWidth,n??=t.height||t.videoHeight,"center"==e._imageMode&&(r-=.5*a,o-=.5*n),e._da&&(r*=e._da,o*=e._da,a*=e._da,n*=e._da,i*=e._da,s*=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,i*h,s*h,l,c,r,o,a,n),e._tint&&(e.ctx.globalCompositeOperation="multiply",e.ctx.fillStyle=e._tint.toString(),e.ctx.fillRect(r,o,a,n),e.ctx.globalCompositeOperation="source-over")},e._tint=null;let r=null;e._softFilter=()=>{throw new Error("Load q5-2d-soft-filters.js to use software filters.")},e.filter=(t,r)=>{if(!e.ctx.filter)return e._softFilter(t,r);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(r*e._pixelDensity)||1;f=`blur(${t}px)`}else{if(t!=Q5.THRESHOLD)return e._softFilter(t,r);{r??=.5;let e=Math.floor(.5/Math.max(r,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,r)=>{let o=new e._OffscreenCanvas(e.canvas.width,e.canvas.height);o.getContext("2d",{colorSpace:e.canvas.colorSpace}).drawImage(e.canvas,0,0),e._setCanvasSize(t,r),e.ctx.clearRect(0,0,e.canvas.width,e.canvas.height),e.ctx.drawImage(o,0,0,e.canvas.width,e.canvas.height)}),e.trim=()=>{let t=e._pixelDensity||1,r=e.canvas.width,o=e.canvas.height,a=e.ctx.getImageData(0,0,r,o).data,n=r,i=0,s=o,l=0,c=3;for(let e=0;e<o;e++)for(let t=0;t<r;t++)0!==a[c]&&(t<n&&(n=t),t>i&&(i=t),e<s&&(s=e),e>l&&(l=e)),c+=4;return s=Math.floor(s/t),l=Math.floor(l/t),n=Math.floor(n/t),i=Math.floor(i/t),e.get(n,s,i-n+1,l-s+1)},e.mask=t=>{e.ctx.save(),e.ctx.resetTransform();let r=e.ctx.globalCompositeOperation;e.ctx.globalCompositeOperation="destination-in",e.ctx.drawImage(t.canvas,0,0),e.ctx.globalCompositeOperation=r,e.ctx.restore()},e.get=(t,r,o,a)=>{let n=e._pixelDensity||1;if(void 0!==t&&void 0===o){let o=e.ctx.getImageData(t*n,r*n,1,1).data;return new e.Color(o[0],o[1],o[2],o[3]/255)}t=(t||0)*n,r=(r||0)*n;let i=o=o||e.width,s=a=a||e.height;o*=n,a*=n;let l=e.createImage(o,a),c=e.ctx.getImageData(t,r,o,a);return l.ctx.putImageData(c,0,0),l._pixelDensity=n,l.width=i,l.height=s,l},e.set=(t,r,o)=>{if(o.canvas){let a=e._tint;return e._tint=null,e.image(o,t,r),void(e._tint=a)}e.pixels.length||e.loadPixels();let a=e._pixelDensity||1;for(let n=0;n<a;n++)for(let i=0;i<a;i++){let s=4*((r*a+n)*e.canvas.width+t*a+i);e.pixels[s]=o.r??o.l,e.pixels[s+1]=o.g??o.c,e.pixels[s+2]=o.b??o.h,e.pixels[s+3]=o.a}},e.loadPixels=()=>{r=e.ctx.getImageData(0,0,e.canvas.width,e.canvas.height),t.pixels=r.data},e.updatePixels=()=>{null!=r&&e.ctx.putImageData(r,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.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,r)=>{t._preloadCount++;let o=e.split("/").pop().split(".")[0].replace(" ",""),a=new FontFace(o,`url(${e})`);return document.fonts.add(a),a.load().then((()=>{t._preloadCount--,r&&r(o)})),o},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,r)=>{e.ctx.textAlign=t,r&&(e.ctx.textBaseline=r==e.CENTER?"middle":r)},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,r=0;for(const[o,a]of this.entries())a.lastAccessed<t&&(t=a.lastAccessed,e=r),r++;r=e;for(const t of this.keys()){if(0==r){e=t;break}r--}this.delete(e)}},e._tic=new e._TimedCache,e.textCache=(t,r)=>(r&&(e._tic.maxSize=r),void 0!==t&&(e._textCache=t),e._textCache),e._genTextImageKey=(t,r,o)=>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+"_":"")+(r||"")+(o?"x"+o:""),e.createTextImage=(t,r,o)=>{let a=e._textCache;e._textCache=!0,e._genTextImage=!0,e.text(t,0,0,r,o),e._genTextImage=!1;let n=e._genTextImageKey(t,r,o);return e._textCache=a,e._tic.get(n)},e.text=(t,r,o,a,n)=>{if(void 0===t)return;if(t=t.toString(),e._da&&(r*=e._da,o*=e._da),!e._doFill&&!e._doStroke)return;let i,s,l,c,d,h,u,p,_=e.ctx.getTransform(),g=e._genTextImage||e._textCache&&(0!=_.b||0!=_.c);if(g){if(c=e._genTextImageKey(t,a,n),s=e._tic.get(c),s&&!e._genTextImage)return void e.textImage(s,r,o);l=e.createGraphics.call(e,1,1),i=l.ctx}else i=e.ctx,d=r,h=o;i.font=`${e._textStyle} ${e._textSize}px ${e._textFont}`;let x=t.split("\n");if(g){d=0,h=e._textLeading*x.length;let r=i.measureText(" ");u=r.fontBoundingBoxAscent,p=r.fontBoundingBoxDescent,n??=h+p,l.resizeCanvas(Math.ceil(i.measureText(t).width),Math.ceil(n)),i.fillStyle=e.ctx.fillStyle,i.strokeStyle=e.ctx.strokeStyle,i.lineWidth=e.ctx.lineWidth}let f=i.fillStyle;e._fillSet||(i.fillStyle="black");for(let t=0;t<x.length&&(e._doStroke&&e._strokeSet&&i.strokeText(x[t],d,h),e._doFill&&i.fillText(x[t],d,h),h+=e._textLeading,!(h>n));t++);e._fillSet||(i.fillStyle=f),g&&(s=l.get(),s._ascent=u,s._descent=p,e._tic.set(c,s),e._genTextImage||e.textImage(s,r,o))},e.textImage=(t,r,o)=>{let a=e._imageMode;e._imageMode="corner","center"==e.ctx.textAlign?r-=.5*t.width:"right"==e.ctx.textAlign&&(r-=t.width),"alphabetic"==e.ctx.textBaseline&&(o-=e._textLeading),"middle"==e.ctx.textBaseline?o-=t._descent+.5*t._ascent+e._textLeadDiff:"bottom"==e.ctx.textBaseline?o-=t._ascent+t._descent+e._textLeadDiff:"top"==e.ctx.textBaseline&&(o-=t._descent+e._textLeadDiff),e.image(t,r,o),e._imageMode=a},e.nf=(e,t,r)=>{let o=e<0,a=(e=Math.abs(e)).toFixed(r).split(".");a[0]=a[0].padStart(t,"0");let n=a.join(".");return o&&(n="-"+n),n}},Q5.modules.ai=e=>{e.askAI=(e="")=>{throw Error("Ask AI ✨ "+e)},e._aiErrorAssistance=async t=>{let r=t.message?.includes("Ask AI ✨");if(r||console.error(t),Q5.disableFriendlyErrors)return;!r&&Q5.errorTolerant||e.noLoop();let o=t.stack?.split("\n");if(!t.stack||o.length<=1)return;let a=1,n="(";for(-1==navigator.userAgent.indexOf("Chrome")&&(a=0,n="@");o[a].indexOf("q5.js:")>=0;)a++;let i=o[a].split(n).at(-1);i=i.split(":");let s=parseInt(i.at(-2));r&&s++;let l=i.slice(0,-2).join(":"),c=l.split("/").at(-1);try{let e=(await(await fetch(l)).text()).split("\n"),o=e[s-1].trim(),a="",n=1;for(;a.length<1600&&(s-n>=0&&(a=e[s-n].trim()+"\n"+a),s+n<e.length);)a+=e[s+n].trim()+"\n",n++;let i="https://chatgpt.com/?q=q5.js+"+(r&&t.message.length>10?t.message.slice(10):"Whats+wrong+with+this+line%3F+short+answer")+(r?"":"%0A%0A"+encodeURIComponent(t.name+": "+t.message))+"%0A%0ALine%3A+"+encodeURIComponent(o)+"%0A%0AExcerpt+for+context%3A%0A%0A"+encodeURIComponent(a);r||console.log("Error in "+c+" on line "+s+":\n\n"+o),console.warn("Ask AI ✨ "+i),r&&window.open(i,"_blank")}catch(e){}}},Q5.modules.color=(e,t)=>{e.RGB=e.RGBA=e._colorMode="rgb",e.OKLCH="oklch",e.colorMode=(r,o)=>{e._colorMode=r;let a="srgb"==e.canvas.colorSpace||"srgb"==r;if(o??=a?"integer":"float",e._colorFormat="float"==o||1==o?1:255,"oklch"==r)t.Color=Q5.ColorOKLCH;else{let r="srgb"==e.canvas.colorSpace;255==e._colorFormat?t.Color=r?Q5.ColorRGBA_8:Q5.ColorRGBA_P3_8:t.Color=r?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,r,o,a)=>{let n=e.Color;if(t._q5Color)return new n(...t.levels);if(null==r){if("string"==typeof t){if("#"==t[0])t.length<=5?(t.length>4&&(a=parseInt(t[4]+t[4],16)),o=parseInt(t[3]+t[3],16),r=parseInt(t[2]+t[2],16),t=parseInt(t[1]+t[1],16)):(t.length>7&&(a=parseInt(t.slice(7,9),16)),o=parseInt(t.slice(5,7),16),r=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,r,o,a]=e._namedColors[t]}1==e._colorFormat&&(t/=255,r&&(r/=255),o&&(o/=255),a&&(a/=255))}Array.isArray(t)&&(r=t[1],o=t[2],a=t[3],t=t[0])}return null==o?new n(t,t,t,r):new n(t,r,o,a)},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 r=t.r,o=t.g,a=t.b;255==e._colorFormat&&(r/=255,o/=255,a/=255);let n,i=Math.max(r,o,a),s=Math.min(r,o,a);return n=i==s?0:i==r?60*(o-a)/(i-s):i==o?60*(a-r)/(i-s)+120:60*(r-o)/(i-s)+240,n<0&&(n+=360),n},e.lerpColor=(t,r,o)=>{if("rgb"==e._colorMode)return new e.Color(e.constrain(e.lerp(t.r,r.r,o),0,255),e.constrain(e.lerp(t.g,r.g,o),0,255),e.constrain(e.lerp(t.b,r.b,o),0,255),e.constrain(e.lerp(t.a,r.a,o),0,255));{let a=r.h-t.h;a>180&&(a-=360),a<-180&&(a+=360);let n=t.h+o*a;return n<0&&(n+=360),n>360&&(n-=360),new e.Color(e.constrain(e.lerp(t.l,r.l,o),0,100),e.constrain(e.lerp(t.c,r.c,o),0,100),n,e.constrain(e.lerp(t.a,r.a,o),0,255))}}},Q5.Color=class{constructor(){this._q5Color=!0}},Q5.ColorOKLCH=class extends Q5.Color{constructor(e,t,r,o){super(),this.l=e,this.c=t,this.h=r,this.a=o??1}toString(){return`oklch(${this.l} ${this.c} ${this.h} / ${this.a})`}},Q5.ColorRGBA=class extends Q5.Color{constructor(e,t,r,o){super(),this.r=e,this.g=t,this.b=r,this.a=o??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,r,o){super(e,t,r,o??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,r,o){super(e,t,r,o??255),this._edited=!0}get r(){return this._r}set r(e){this._r=e,this._edited=!0}get g(){return this._g}set g(e){this._g=e,this._edited=!0}get b(){return this._b}set b(e){this._b=e,this._edited=!0}get a(){return this._a}set a(e){this._a=e,this._edited=!0}toString(){if(this._edited){let e=(this._r/255).toFixed(3),t=(this._g/255).toFixed(3),r=(this._b/255).toFixed(3),o=(this._a/255).toFixed(3);this._css=`color(display-p3 ${e} ${t} ${r} / ${o})`,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 r=t.style,o=t.parentElement;r&&o&&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?(o.classList.remove("q5-centered","q5-maxed","q5-fullscreen"),r.width=t.w*t.displayScale+"px",r.height=t.h*t.displayScale+"px"):(o.classList.add("q5-"+t.displayMode),o=o.getBoundingClientRect(),t.w/t.h>o.width/o.height?("centered"==t.displayMode?(r.width=t.w*t.displayScale+"px",r.maxWidth="100%"):r.width="100%",r.height="auto",r.maxHeight=""):(r.width="auto",r.maxWidth="","centered"==t.displayMode?(r.height=t.h*t.displayScale+"px",r.maxHeight="100%"):r.height="100%")))},e.displayMode=(r="normal",o="default",a=1)=>{"string"==typeof a&&(a=parseFloat(a.slice(1))),Object.assign(t,{displayMode:r,renderQuality:o,displayScale:a}),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 r={},o=[e.LEFT,e.CENTER,e.RIGHT],a=e.canvas;function n(t){const r=e.canvas.getBoundingClientRect(),o=e.canvas.scrollWidth/e.width||1,a=e.canvas.scrollHeight/e.height||1;return{x:(t.clientX-r.left)/o,y:(t.clientY-r.top)/a,id:t.identifier}}if(e._startAudio=()=>{e.getAudioContext&&"suspended"==e.getAudioContext()?.state&&e.userStartAudio()},e._updateMouse=r=>{if(!r.changedTouches)if(a){let o=a.getBoundingClientRect(),n=a.scrollWidth/e.width||1,i=a.scrollHeight/e.height||1;t.mouseX=(r.clientX-o.left)/n,t.mouseY=(r.clientY-o.top)/i,"webgpu"==a.renderer&&(t.mouseX-=a.hw,t.mouseY-=a.hh)}else t.mouseX=r.clientX,t.mouseY=r.clientY},e._onmousedown=r=>{e._startAudio(),e._updateMouse(r),t.mouseIsPressed=!0,t.mouseButton=o[r.button],e.mousePressed(r)},e._onmousemove=t=>{e._updateMouse(t),e.mouseIsPressed?e.mouseDragged(t):e.mouseMoved(t)},e._onmouseup=r=>{e._updateMouse(r),t.mouseIsPressed=!1,e.mouseReleased(r)},e._onclick=r=>{e._updateMouse(r),t.mouseIsPressed=!0,e.mouseClicked(r),t.mouseIsPressed=!1},e.cursor=(t,r,o)=>{let a="";t.includes(".")&&(t=`url("${t}")`,a=", auto"),void 0!==r&&(t+=" "+r+" "+o),e.canvas.style.cursor=t+a},e.noCursor=()=>{e.canvas.style.cursor="none"},e.requestPointerLock=document.body?.requestPointerLock,e.exitPointerLock=document.exitPointerLock,e._onkeydown=o=>{o.repeat||(e._startAudio(),t.keyIsPressed=!0,t.key=o.key,t.keyCode=o.keyCode,r[e.keyCode]=r[e.key.toLowerCase()]=!0,e.keyPressed(o),1==o.key.length&&e.keyTyped(o))},e._onkeyup=o=>{t.keyIsPressed=!1,t.key=o.key,t.keyCode=o.keyCode,r[e.keyCode]=r[e.key.toLowerCase()]=!1,e.keyReleased(o)},e.keyIsDown=e=>!!r["string"==typeof e?e.toLowerCase():e],e._ontouchstart=r=>{e._startAudio(),t.touches=[...r.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(r)||r.preventDefault()),e.touchStarted(r)||r.preventDefault()},e._ontouchmove=r=>{t.touches=[...r.touches].map(n),e._isTouchAware||(t.mouseX=e.touches[0].x,t.mouseY=e.touches[0].y,e.mouseDragged(r)||r.preventDefault()),e.touchMoved(r)||r.preventDefault()},e._ontouchend=r=>{t.touches=[...r.touches].map(n),e._isTouchAware||e.touches.length||(t.mouseIsPressed=!1,e.mouseReleased(r)||r.preventDefault()),e.touchEnded(r)||r.preventDefault()},a&&(a.addEventListener("mousedown",(t=>e._onmousedown(t))),a.addEventListener("mouseup",(t=>e._onmouseup(t))),a.addEventListener("click",(t=>e._onclick(t))),a.addEventListener("touchstart",(t=>e._ontouchstart(t))),a.addEventListener("touchmove",(t=>e._ontouchmove(t))),a.addEventListener("touchcancel",(t=>e._ontouchend(t))),a.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,r,o,a,n)=>{let i=o+1*(e-t)/(r-t)*(a-o);return n?o<a?Math.min(Math.max(i,o),a):Math.min(Math.max(i,a),o):i},e.lerp=(e,t,r)=>e*(1-r)+t*r,e.constrain=(e,t,r)=>Math.min(Math.max(e,t),r),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,r,o)=>e.map(t,r,o,0,1),e.sq=e=>e*e,e.fract=e=>e-Math.floor(e);for(let t of["sin","cos","tan"])e[t]=r=>("degrees"==e._angleMode&&(r=e.radians(r)),Math[t](r));for(let t of["asin","acos","atan"])e[t]=r=>{let o=Math[t](r);return"degrees"==e._angleMode&&(o=e.degrees(o)),o};function r(){let e,t,r=4294967295;return{setSeed(o){e=t=(o??Math.random()*r)>>>0},getSeed:()=>t,rand:()=>(e^=e<<17,e^=e>>13,e^=e<<5,(e>>>0)/r)}}e.atan2=(t,r)=>{let o=Math.atan2(t,r);return"degrees"==e._angleMode&&(o=e.degrees(o)),o};let o=r();o.setSeed(),e.randomSeed=e=>o.setSeed(e),e.random=(e,t)=>void 0===e?o.rand():"number"==typeof e?void 0!==t?o.rand()*(t-e)+e:o.rand()*e:e[Math.trunc(e.length*o.rand())],e.randomGenerator=t=>{t==e.LCG?o=function(){const e=4294967296;let t,r;return{setSeed(o){r=t=(o??Math.random()*e)>>>0},getSeed:()=>t,rand:()=>(r=(1664525*r+1013904223)%e,r/e)}}():t==e.SHR3&&(o=r()),o.setSeed()};var a=new function(){var e,t,r,a=new Array(128),n=new Array(256),i=new Array(128),s=new Array(128),l=new Array(256),c=new Array(256),d=()=>4294967296*o.rand()-2147483648,h=()=>.5+2.328306e-10*(d()|0),u=()=>{for(var t,o,n,l,c=3.44262;;){if(t=r*i[e],0==e){do{n=h(),l=h(),t=.2904764*-Math.log(n),o=-Math.log(l)}while(o+o<t*t);return r>0?c+t:-c-t}if(s[e]+h()*(s[e-1]-s[e])<Math.exp(-.5*t*t))return t;if(r=d(),e=127&r,Math.abs(r)<a[e])return r*i[e]}},p=()=>{for(var r;;){if(0==e)return 7.69711-Math.log(h());if(r=t*l[e],c[e]+h()*(c[e-1]-c[e])<Math.exp(-r))return r;if((t=d())<n[e=255&t])return t*l[e]}};this.SHR3=d,this.UNI=h,this.RNOR=()=>(r=d(),e=127&r,Math.abs(r)<a[e]?r*i[e]:u()),this.REXP=()=>(t=d()>>>0)<a[e=255&t]?t*l[e]:p(),this.zigset=()=>{var e,t,r=2147483648,o=4294967296,d=3.442619855899,h=d,u=.00991256303526217,p=7.697117470131487,_=p,g=.003949659822581572;for(e=u/Math.exp(-.5*d*d),a[0]=Math.floor(d/e*r),a[1]=0,i[0]=e/r,i[127]=d/r,s[0]=1,s[127]=Math.exp(-.5*d*d),t=126;t>=1;t--)d=Math.sqrt(-2*Math.log(u/d+Math.exp(-.5*d*d))),a[t+1]=Math.floor(d/h*r),h=d,s[t]=Math.exp(-.5*d*d),i[t]=d/r;for(e=g/Math.exp(-p),n[0]=Math.floor(p/e*o),n[1]=0,l[0]=e/o,l[255]=p/o,c[0]=1,c[255]=Math.exp(-p),t=254;t>=1;t--)p=-Math.log(g/p+Math.exp(-p)),n[t+1]=Math.floor(p/_*o),_=p,c[t]=Math.exp(-p),l[t]=p/o}};let n;a.hasInit=!1,e.randomGaussian=(e,t)=>(a.hasInit||(a.zigset(),a.hasInit=!0),a.RNOR()*t+e),e.randomExponential=()=>(a.hasInit||(a.zigset(),a.hasInit=!0),a.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,r=0,o=0)=>(n??=new e.Noise,n.noise(t,r,o)),e.noiseDetail=(t,r)=>{n??=new e.Noise,t>0&&(n.octaves=t),r>0&&(n.falloff=r)}},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,r,o=[];for(let e=0;e<256;e++)o[e]=e;for(let a=255;a>0;a--)t=(e=16807*e%2147483647)%(a+1),r=o[a],o[a]=o[t],o[t]=r;return o}dot(e,t,r,o){return e[0]*t+e[1]*r+e[2]*o}mix(e,t,r){return(1-r)*e+r*t}fade(e){return e*e*e*(e*(6*e-15)+10)}noise(e,t,r){let o=this,a=0,n=1,i=1,s=0;for(let l=0;l<o.octaves;l++){const l=255&Math.floor(e*n),c=255&Math.floor(t*n),d=255&Math.floor(r*n),h=e*n-Math.floor(e*n),u=t*n-Math.floor(t*n),p=r*n-Math.floor(r*n),_=o.fade(h),g=o.fade(u),x=o.fade(p),f=o.p[l]+c,m=o.p[f]+d,v=o.p[f+1]+d,y=o.p[l+1]+c,w=o.p[y]+d,S=o.p[y+1]+d,b=o.mix(o.dot(o.grad3[o.p[m]%12],h,u,p),o.dot(o.grad3[o.p[w]%12],h-1,u,p),_),C=o.mix(o.dot(o.grad3[o.p[v]%12],h,u-1,p),o.dot(o.grad3[o.p[S]%12],h-1,u-1,p),_),M=o.mix(o.dot(o.grad3[o.p[m+1]%12],h,u,p-1),o.dot(o.grad3[o.p[w+1]%12],h-1,u,p-1),_),Q=o.mix(o.dot(o.grad3[o.p[v+1]%12],h,u-1,p-1),o.dot(o.grad3[o.p[S+1]%12],h-1,u-1,p-1),_),R=o.mix(b,C,g),I=o.mix(M,Q,g);a+=o.mix(R,I,x)*i,s+=i,i*=o.falloff,n*=2}return(a/s+1)/2}},Q5.modules.sound=(e,t)=>{e.Sound=Q5.Sound,e.loadSound=(e,r)=>{t._preloadCount++,Q5.aud??=new window.AudioContext;let o=new Q5.Sound(e,r);return o.addEventListener("canplaythrough",(()=>{t._preloadCount--,o.loaded=!0,r&&r(o)})),o},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,r,o)=>{t._preloadCount++;let a={};return fetch(e).then((e=>"json"==o?e.json():"text"==o?e.text():void 0)).then((e=>{t._preloadCount--,Object.assign(a,e),r&&r(e)})),a},e.loadStrings=(t,r)=>e._loadFile(t,r,"text"),e.loadJSON=(t,r)=>e._loadFile(t,r,"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,r,o)=>new Q5.Vector(t,r,o,e)},Q5.Vector=class{constructor(e,t,r,o){this.x=e||0,this.y=t||0,this.z=r||0,this._$=o||window,this._cn=null,this._cnsq=null}set(e,t,r){this.x=e||0,this.y=t||0,this.z=r||0}copy(){return new Q5.Vector(this.x,this.y,this.z)}_arg2v(e,t,r){return void 0!==e?.x?e:void 0!==t?{x:e,y:t,z:r||0}:{x:e,y:e,z:e}}_calcNorm(){this._cnsq=this.x*this.x+this.y*this.y+this.z*this.z,this._cn=Math.sqrt(this._cnsq)}add(){let e=this._arg2v(...arguments);return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}rem(){let e=this._arg2v(...arguments);return this.x%=e.x,this.y%=e.y,this.z%=e.z,this}sub(){let e=this._arg2v(...arguments);return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}mult(){let e=this._arg2v(...arguments);return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}div(){let e=this._arg2v(...arguments);return e.x?this.x/=e.x:this.x=0,e.y?this.y/=e.y:this.y=0,e.z?this.z/=e.z:this.z=0,this}mag(){return this._calcNorm(),this._cn}magSq(){return this._calcNorm(),this._cnsq}dot(){let e=this._arg2v(...arguments);return this.x*e.x+this.y*e.y+this.z*e.z}dist(){let e=this._arg2v(...arguments),t=this.x-e.x,r=this.y-e.y,o=this.z-e.z;return Math.sqrt(t*t+r*r+o*o)}cross(){let e=this._arg2v(...arguments),t=this.y*e.z-this.z*e.y,r=this.z*e.x-this.x*e.z,o=this.x*e.y-this.y*e.x;return this.x=t,this.y=r,this.z=o,this}normalize(){this._calcNorm();let e=this._cn;return 0!=e&&(this.x/=e,this.y/=e,this.z/=e),this._cn=1,this._cnsq=1,this}limit(e){this._calcNorm();let t=this._cn;if(t>e){let r=e/t;this.x*=r,this.y*=r,this.z*=r,this._cn=e,this._cnsq=e*e}return this}setMag(e){this._calcNorm();let t=e/this._cn;return this.x*=t,this.y*=t,this.z*=t,this._cn=e,this._cnsq=e*e,this}heading(){return this._$.atan2(this.y,this.x)}rotate(e){let t=this._$.cos(e),r=this._$.sin(e),o=this.x*t-this.y*r,a=this.x*r+this.y*t;return this.x=o,this.y=a,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)),r=e.at(-1);return this.x+=(t.x-this.x)*r,this.y+=(t.y-this.y)*r,this.z+=(t.z-this.z)*r,this}reflect(e){return e.normalize(),this.sub(e.mult(2*this.dot(e)))}array(){return[this.x,this.y,this.z]}equals(e,t){return t??=Number.EPSILON||0,Math.abs(e.x-this.x)<t&&Math.abs(e.y-this.y)<t&&Math.abs(e.z-this.z)<t}fromAngle(e,t){return void 0===t&&(t=1),this._cn=t,this._cnsq=t*t,this.x=t*this._$.cos(e),this.y=t*this._$.sin(e),this.z=0,this}fromAngles(e,t,r){void 0===r&&(r=1),this._cn=r,this._cnsq=r*r;const o=this._$.cos(t),a=this._$.sin(t),n=this._$.cos(e),i=this._$.sin(e);return this.x=r*i*a,this.y=-r*n,this.z=r*i*o,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,r)=>e.equals(t,r),Q5.Vector.lerp=(e,t,r)=>e.copy().lerp(t,r),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,r,o)=>(new Q5.Vector)[e](t,r,o);Q5.renderers.webgpu={},Q5.renderers.webgpu.canvas=(e,t)=>{let r,o,a,n,i=e.canvas;function s(t,r,a,n=1){"string"==typeof t&&(t=Q5.color(t)),null==a&&(n=r,r=a=t),t._q5Color?o.push(...t.levels):o.push(t,r,a,n),e._colorIndex++}i.width=e.width=500,i.height=e.height=500,e.colorMode&&e.colorMode("rgb","float"),e._createCanvas=(r,n,s)=>{t.ctx=t.drawingContext=i.getContext("webgpu"),s.format=navigator.gpu.getPreferredCanvasFormat(),s.device=Q5.device,e.ctx.configure(s),e.pipelines=[],e.pipelinesStack=[],e.verticesStack=[],e.drawStack=[],o=e.colorsStack=[1,1,1,1],e._colorIndex=0;let l=Q5.device.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX,buffer:{type:"uniform",hasDynamicOffset:!1}}]}),c=Q5.device.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX,buffer:{type:"read-only-storage",hasDynamicOffset:!1}}]});e.bindGroupLayouts=[l,c];const d=Q5.device.createBuffer({size:8,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});Q5.device.queue.writeBuffer(d,0,new Float32Array([e.canvas.hw,e.canvas.hh])),a=Q5.device.createBindGroup({layout:l,entries:[{binding:0,resource:{buffer:d}}]})},e._resizeCanvas=(t,r)=>{e._setCanvasSize(t,r)},e.resetMatrix=()=>{e._matrix=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],e._transformIndex=0},e.resetMatrix(),e._matrixDirty=!1,e.transformStates=[e._matrix.slice()],e._transformIndexStack=[],e.push=()=>{e._transformIndexStack.push(e._transformIndex)},e.pop=()=>{if(e._transformIndexStack.length>0){let t=e._transformIndexStack.pop();e._matrix=e.transformStates[t].slice(),e._transformIndex=t}else console.warn("Matrix index stack is empty!")},e.translate=(t,r,o)=>{(t||r||o)&&(e._matrix[3]+=t,e._matrix[7]+=r,e._matrix[11]+=o||0,e._matrixDirty=!0)},e.rotate=t=>{if(!t)return;"degrees"==e._angleMode&&(t=e.radians(t));let r=Math.cos(t),o=Math.sin(t),a=e._matrix[0],n=e._matrix[1],i=e._matrix[4],s=e._matrix[5];a||n||i||s?(e._matrix[0]=a*r+i*o,e._matrix[1]=n*r+s*o,e._matrix[4]=a*-o+i*r,e._matrix[5]=n*-o+s*r):(e._matrix[0]=r,e._matrix[1]=o,e._matrix[4]=-o,e._matrix[5]=r),e._matrixDirty=!0},e.scale=(t=1,r,o=1)=>{r??=t,e._matrix[0]*=t,e._matrix[5]*=r,e._matrix[10]*=o,e._matrixDirty=!0},e._saveMatrix=()=>{e.transformStates.push(e._matrix.slice()),e._transformIndex=e.transformStates.length-1,e._matrixDirty=!1},e._beginRender=()=>{e.encoder=Q5.device.createCommandEncoder(),r=t.pass=e.encoder.beginRenderPass({colorAttachments:[{view:ctx.getCurrentTexture().createView(),loadOp:"clear",storeOp:"store"}]})},e._render=()=>{if(r.setBindGroup(0,a),transformStates.length>1||!n){const t=Q5.device.createBuffer({size:64*transformStates.length,usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST});Q5.device.queue.writeBuffer(t,0,new Float32Array(transformStates.flat())),n=Q5.device.createBindGroup({layout:e.bindGroupLayouts[1],entries:[{binding:0,resource:{buffer:t}}]})}r.setBindGroup(1,n);for(let t of e._hooks.preRender)t();let t=e.drawStack,o=0,i=-1;for(let a=0;a<t.length;a+=2){i!=t[a]&&(i=t[a],r.setPipeline(e.pipelines[i]));let n=t[a+1];r.draw(n,1,o,0),o+=n}},e._finishRender=()=>{r.end();const o=e.encoder.finish();Q5.device.queue.submit([o]),t.pass=e.encoder=null,e.verticesStack.length=0,e.drawStack.length=0,e.colorsStack.length=4,e.pipelinesStack.length=0,e._colorIndex=0,rotation=0,e.resetMatrix(),e._matrixDirty=!1,e.transformStates.length=1,e._transformIndexStack.length=0},e.fill=function(){s(...arguments),e._doFill=!0,e._fillIndex=e._colorIndex},e.stroke=function(){s(...arguments),e._doStroke=!0,e._fillIndex=e._colorIndex},e.noFill=()=>e._doFill=!1,e.noStroke=()=>e._doStroke=!1,e._strokeWeight=1,e.strokeWeight=t=>e._strokeWeight=t,e.clear=()=>{}},Q5.webgpu=async function(e,t){if(e&&"global"!=e||(Q5._hasGlobal=!0),!navigator.gpu){console.warn("q5 WebGPU not supported on this browser!");let r=new Q5(e,t);return r.colorMode("rgb",1),r._beginRender=()=>r.translate(r.canvas.hw,r.canvas.hh),r}let r=await navigator.gpu.requestAdapter();if(!r)throw new Error("No appropriate GPUAdapter found.");return Q5.device=await r.requestDevice(),new Q5(e,t,"webgpu")},Q5.renderers.webgpu.drawing=(e,t)=>{let r,o,a;e.CLOSE=1,e._hooks.postCanvas.push((()=>{let t=Q5.device.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,buffer:{type:"read-only-storage",hasDynamicOffset:!1}}]});e.bindGroupLayouts.push(t),r=e.verticesStack,o=e.drawStack,a=e.colorsStack;let n={arrayStride:16,attributes:[{format:"float32x2",offset:0,shaderLocation:0},{format:"float32",offset:8,shaderLocation:1},{format:"float32",offset:12,shaderLocation:2}]},i=Q5.device.createShaderModule({code:"\nstruct VertexOutput {\n\t@builtin(position) position: vec4<f32>,\n\t@location(1) colorIndex: f32\n};\n\nstruct Uniforms {\n\thalfWidth: f32,\n\thalfHeight: f32\n};\n\n@group(0) @binding(0) var<uniform> uniforms: Uniforms;\n@group(1) @binding(0) var<storage, read> transforms: array<mat4x4<f32>>;\n\n@vertex\nfn vertexMain(@location(0) pos: vec2<f32>, @location(1) colorIndex: f32, @location(2) transformIndex: f32) -> VertexOutput {\n\tvar vert = vec4<f32>(pos, 0.0, 1.0);\n\tvert *= transforms[i32(transformIndex)];\n\tvert.x /= uniforms.halfWidth;\n\tvert.y /= uniforms.halfHeight;\n\n\tvar output: VertexOutput;\n\toutput.position = vert;\n\toutput.colorIndex = colorIndex;\n\treturn output;\n}\n"}),s=Q5.device.createShaderModule({code:"\n@group(2) @binding(0) var<storage, read> uColors : array<vec4<f32>>;\n\n@fragment\nfn fragmentMain(@location(1) colorIndex: f32) -> @location(0) vec4<f32> {\n\tlet index = u32(colorIndex);\n\treturn mix(uColors[index], uColors[index + 1u], fract(colorIndex));\n}\n"}),l=Q5.device.createPipelineLayout({bindGroupLayouts:e.bindGroupLayouts});e._createPipeline=e=>Q5.device.createRenderPipeline({layout:l,vertex:{module:i,entryPoint:"vertexMain",buffers:[n]},fragment:{module:s,entryPoint:"fragmentMain",targets:[{format:"bgra8unorm",blend:e}]},primitive:{topology:"triangle-list"}}),e.pipelines[0]=e._createPipeline(blendConfigs.normal)}));let n=["zero","one","src-alpha","one-minus-src-alpha","dst","dst-alpha","one-minus-dst-alpha","one-minus-src"],i=["add","subtract","reverse-subtract","min","max"];let s;e.blendConfigs={},Object.entries({normal:[2,3,0,2,3,0],lighter:[2,1,0,2,1,0],subtract:[2,1,2,2,1,2],multiply:[4,0,0,5,0,0],screen:[1,3,0,1,3,0],darken:[1,3,3,1,3,3],lighten:[1,3,4,1,3,4],overlay:[2,3,0,2,3,0],hard_light:[2,3,0,2,3,0],soft_light:[2,3,0,2,3,0],difference:[2,3,2,2,3,2],exclusion:[2,3,0,2,3,0],color_dodge:[1,7,0,1,7,0],color_burn:[6,1,0,6,1,0],linear_dodge:[2,1,0,2,1,0],linear_burn:[2,7,1,2,7,1],vivid_light:[2,7,0,2,7,0],pin_light:[2,7,0,2,7,0],hard_mix:[2,7,0,2,7,0]}).forEach((([t,r])=>{e.blendConfigs[t]={color:{srcFactor:n[r[0]],dstFactor:n[r[1]],operation:i[r[2]]},alpha:{srcFactor:n[r[3]],dstFactor:n[r[4]],operation:i[r[5]]}}})),e._blendMode="normal",e.blendMode=t=>{t!=e._blendMode&&("source-over"==t&&(t="normal"),t=t.toLowerCase().replace(/[ -]/g,"_"),e._blendMode=t,e.pipelines[0]=e._createPipeline(e.blendConfigs[t]))},e.beginShape=()=>{s=[]},e.vertex=(t,r)=>{e._matrixDirty&&e._saveMatrix(),s.push(t,-r,e._colorIndex,e._transformIndex)},e.endShape=e=>{let t=s;if(t.length<12)throw new Error("A shape must have at least 3 vertices.");e&&t.push(t[0],t[1],t[2],t[3]);let a=[];for(let e=4;e<t.length;e+=4)a.push(t[0],t[1],t[2],t[3],t[e-4],t[e-3],t[e-2],t[e-1],t[e],t[e+1],t[e+2],t[e+3]);r.push(...a),o.push(0,a.length/4),s=[]},e.triangle=(t,r,o,a,n,i)=>{e.beginShape(),e.vertex(t,r),e.vertex(o,a),e.vertex(n,i),e.endShape(1)},e.rect=(t,a,n,i)=>{let s=n/2,l=i/2,c=t-s,d=t+s,h=-(a-l),u=-(a+l),p=e._colorIndex;e._matrixDirty&&e._saveMatrix();let _=e._transformIndex;r.push(c,h,p,_,d,h,p,_,c,u,p,_,d,h,p,_,c,u,p,_,d,u,p,_),o.push(0,6)},e.point=(t,r)=>{let o=e._strokeWeight;1==o?e.rect(t,r,1,1):e.ellipse(t,r,o,o)},e.background=()=>{};e.ellipse=(t,a,n,i)=>{const s=(l=n==i?n:Math.max(n,i))<14?8:l<16?10:l<18?12:l<20?14:l<22?16:l<24?18:l<28?20:l<34?22:l<42?24:l<48?26:l<56?28:l<64?30:l<72?32:l<84?34:l<96?36:l<98?38:l<113?40:l<149?44:l<199?48:l<261?52:l<353?56:l<461?60:l<585?64:l<1200?70:l<1800?80:l<2400?90:100;var l;let c=Math.max(n,1)/2,d=n==i?c:Math.max(i,1)/2,h=0;const u=e.TAU/s,p=e._colorIndex;e._matrixDirty&&e._saveMatrix();const _=e._transformIndex;let g,x,f,m;for(let e=0;e<=s;e++)g=f,x=m,f=t+c*Math.cos(h),m=a+d*Math.sin(h),h+=u,0!=e&&r.push(t,a,p,_,g,x,p,_,f,m,p,_);o.push(0,3*s)},e.circle=(t,r,o)=>e.ellipse(t,r,o,o),e._hooks.preRender.push((()=>{const t=Q5.device.createBuffer({size:6*r.length,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST});Q5.device.queue.writeBuffer(t,0,new Float32Array(r)),e.pass.setVertexBuffer(0,t);const o=Q5.device.createBuffer({size:4*a.length,usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST});Q5.device.queue.writeBuffer(o,0,new Float32Array(a));const n=Q5.device.createBindGroup({layout:e.bindGroupLayouts[2],entries:[{binding:0,resource:{buffer:o,offset:0,size:4*a.length}}]});e.pass.setBindGroup(2,n)}))},Q5.renderers.webgpu.image=(e,t)=>{e.imageStack=[],e.textures=[],e._hooks.postCanvas.push((()=>{let t=Q5.device.createShaderModule({code:"\nstruct VertexOutput {\n @builtin(position) position: vec4<f32>,\n @location(0) texCoord: vec2<f32>,\n @location(1) textureIndex: f32\n};\n\nstruct Uniforms {\n halfWidth: f32,\n halfHeight: f32\n};\n\n@group(0) @binding(0) var<uniform> uniforms: Uniforms;\n@group(1) @binding(0) var<storage, read> transforms: array<mat4x4<f32>>;\n\n@vertex\nfn vertexMain(@location(0) pos: vec2<f32>, @location(1) texCoord: vec2<f32>, @location(2) transformIndex: f32, @location(3) textureIndex: f32) -> VertexOutput {\n var vert = vec4<f32>(pos, 0.0, 1.0);\n vert *= transforms[i32(transformIndex)];\n vert.x /= uniforms.halfWidth;\n vert.y /= uniforms.halfHeight;\n\n var output: VertexOutput;\n output.position = vert;\n output.texCoord = texCoord;\n output.textureIndex = textureIndex;\n return output;\n}\n"}),r=Q5.device.createShaderModule({code:"\n@group(0) @binding(0) var samp: sampler;\n@group(0) @binding(1) var textures: array<texture_2d<f32>>;\n\n@fragment\nfn fragmentMain(@location(0) texCoord: vec2<f32>, @location(1) textureIndex: f32) -> @location(0) vec4<f32> {\n return textureSample(textures[i32(textureIndex)], samp, texCoord);\n}\n"});const o=[Q5.device.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX,buffer:{type:"uniform"}},{binding:1,visibility:GPUShaderStage.FRAGMENT,sampler:{}},{binding:2,visibility:GPUShaderStage.FRAGMENT,texture:{viewDimension:"2d",sampleType:"float"}}]}),Q5.device.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX,buffer:{type:"read-only-storage"}}]})],a=Q5.device.createPipelineLayout({bindGroupLayouts:o});e.pipelines[1]=Q5.device.createRenderPipeline({layout:a,vertex:{module:t,entryPoint:"vertexMain",buffers:[{arrayStride:20,attributes:[{shaderLocation:0,offset:0,format:"float32x2"},{shaderLocation:1,offset:8,format:"float32x2"},{shaderLocation:2,offset:16,format:"float32"}]}]},fragment:{module:r,entryPoint:"fragmentMain",targets:[{format:"bgra8unorm"}]},primitive:{topology:"triangle-list"}}),e.sampler=Q5.device.createSampler({magFilter:"linear",minFilter:"linear"})})),e.loadImage=async t=>{const r=new Image;return r.onload=async()=>{const t=await createImageBitmap(r),o=Q5.device.createTexture({size:[r.width,r.height,1],format:"bgra8unorm",usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.RENDER_ATTACHMENT});Q5.device.queue.copyExternalImageToTexture({source:t},{texture:o},[r.width,r.height,1]),r.texture=o,r.index=e.textures.length,e.textures.push(o)},r.onerror=reject,r.src=t,r},e._hooks.preRender.push((()=>{if(!e.imageStack.length)return;e.pass.setPipeline(e.pipelines[1]);const t=new Float32Array(e.vertexStack),r=Q5.device.createBuffer({size:t.byteLength,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST});if(Q5.device.queue.writeBuffer(r,0,t),e.pass.setVertexBuffer(0,r),e.textures.length!==previousTextureCount){previousTextureCount=e.textures.length;const t=e.textures.map((e=>e.createView()));e.textureBindGroup=Q5.device.createBindGroup({layout:e.pipelines[1].getBindGroupLayout(0),entries:[{binding:0,resource:e.sampler},...t.map(((e,t)=>({binding:t+1,resource:e})))]})}e.pass.setBindGroup(0,e.textureBindGroup)})),e.image=(t,r,o,a,n)=>{e._matrixDirty&&e._saveMatrix();let i=e._transformIndex;e.imageStack.push(t.index);let s=a/2,l=n/2,c=r-s,d=r+s,h=-(o-l),u=-(o+l),p=t.index;e.vertexStack.push(c,h,0,0,i,p,d,h,1,0,i,p,c,u,0,1,i,p,d,h,1,0,i,p,c,u,0,1,i,p,d,u,1,1,i,p),e.drawStack.push(6)}},Q5.renderers.webgpu.text=(e,t)=>{};
8
+ function Q5(e,t,r){let o,a=this;if(a._q5=!0,a._parent=t,a._renderer=r||"q2d",a._preloadCount=0,e??="global","auto"==e){if(!window.setup&&!window.draw)return;e="global"}a._scope=e,"global"==e&&(Q5._hasGlobal=a._isGlobal=!0,o=Q5._nodejs?global:window);let n=new Proxy(a,{set:(e,t,r)=>(a[t]=r,a._isGlobal&&(o[t]=r),!0)});a.canvas=a.ctx=a.drawingContext=null,a.pixels=[];let i=null;a.frameCount=0,a.deltaTime=16,a._targetFrameRate=0,a._targetFrameDuration=16.666666666666668,a._frameRate=a._fps=60,a._loop=!0,a._hooks={postCanvas:[],preRender:[]};let s=0;a.millis=()=>performance.now()-s,a.noCanvas=()=>{a.canvas?.remove&&a.canvas.remove(),a.canvas=0,n.ctx=n.drawingContext=0},window&&(a.windowWidth=window.innerWidth,a.windowHeight=window.innerHeight,a.deviceOrientation=window.screen?.orientation?.type),a._incrementPreload=()=>n._preloadCount++,a._decrementPreload=()=>n._preloadCount--,a._draw=e=>{let t=e||performance.now();if(a._lastFrameTime??=t-a._targetFrameDuration,a._shouldResize&&(a.windowResized(),a._shouldResize=!1),a._loop)i=d(a._draw);else if(a.frameCount&&!a._redraw)return;if(i&&a.frameCount){if(t-a._lastFrameTime<a._targetFrameDuration-4)return}n.deltaTime=t-a._lastFrameTime,a._frameRate=1e3/a.deltaTime,n.frameCount++;let r=performance.now();a.ctx&&a.resetMatrix(),a._beginRender&&a._beginRender();for(let e of Q5.methods.pre)e.call(a);a.draw(),a._render&&a._render();for(let e of Q5.methods.post)e.call(a);a._finishRender&&a._finishRender(),n.pmouseX=a.mouseX,n.pmouseY=a.mouseY,a._lastFrameTime=t;let o=performance.now();a._fps=Math.round(1e3/(o-r))},a.noLoop=()=>{a._loop=!1,i=null},a.loop=()=>{a._loop=!0,null==i&&a._draw()},a.isLooping=()=>a._loop,a.redraw=(e=1)=>{a._redraw=!0;for(let t=0;t<e;t++)a._draw();a._redraw=!1},a.remove=()=>{a.noLoop(),a.canvas.remove()},a.frameRate=e=>(e&&(a._targetFrameRate=e,a._targetFrameDuration=1e3/e),a._frameRate),a.getTargetFrameRate=()=>a._targetFrameRate,a.getFPS=()=>a._fps,a.Element=function(e){this.elt=e},a._elements=[],a.TWO_PI=a.TAU=2*Math.PI,a.log=a.print=console.log,a.describe=()=>{};for(let e in Q5.modules)Q5.modules[e](a,n);let l=Q5.renderers[a._renderer];for(let e in l)l[e](a,n);for(let e in Q5)"_"!=e[1]&&e[1]==e[1].toUpperCase()&&(a[e]=Q5[e]);if("graphics"==e)return;"global"==e&&(Object.assign(Q5,a),delete Q5.Q5);for(let e of Q5.methods.init)e.call(a);for(let[e,t]of Object.entries(Q5.prototype))"_"!=e[0]&&"function"==typeof a[e]&&(a[e]=t.bind(a));if("global"==e){let e=Object.getOwnPropertyNames(a);for(let t of e)"_"!=t[0]&&(o[t]=a[t])}"function"==typeof e&&e(a),Q5._instanceCount++;let d=window.requestAnimationFrame||function(e){const t=a._lastFrameTime+a._targetFrameDuration;return setTimeout((()=>{e(t)}),t-performance.now())},c=o||a;a._isTouchAware=c.touchStarted||c.touchMoved||c.mouseReleased;let h=c.preload,u=["setup","draw","preload","mouseMoved","mousePressed","mouseReleased","mouseDragged","mouseClicked","keyPressed","keyReleased","keyTyped","touchStarted","touchMoved","touchEnded","windowResized"];for(let e of u)c[e]?a._isGlobal&&(a[e]=()=>{try{return c[e]()}catch(e){throw a._aiErrorAssistance&&a._aiErrorAssistance(e),e}}):a[e]=()=>{};async function p(){if(a._startDone=!0,a._preloadCount>0)return d(p);s=performance.now(),await a.setup(),a.frameCount||(null===a.ctx&&a.createCanvas(100,100),a._setupDone=!0,a.ctx&&a.resetMatrix(),d(a._draw))}(a.setup||a.draw)&&(arguments.length&&"namespace"!=e&&"webgpu"!=r||h?(a.preload(),p()):(c.preload=a.preload=()=>{a._startDone||p()},setTimeout(a.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 r=e.canvas;if(r.width=e.width=100,r.height=e.height=100,"image"!=e._scope&&(r.renderer=e._renderer,r[e._renderer]=!0),e._pixelDensity=1,e._adjustDisplay=()=>{r.style&&(r.style.width=r.w+"px",r.style.height=r.h+"px")},e.createCanvas=function(t,o,a){a??=arguments[3];let n=Object.assign({},Q5.canvasOptions);if("object"==typeof a&&Object.assign(n,a),"image"!=e._scope){let t=e.displayDensity();"graphics"==e._scope?t=this._pixelDensity:window.IntersectionObserver&&new IntersectionObserver((e=>{r.visible=e[0].isIntersecting})).observe(r),e._pixelDensity=Math.ceil(t)}e._setCanvasSize(t,o),Object.assign(r,n);let i=e._createCanvas(r.w,r.h,n);if(e._hooks)for(let t of e._hooks.postCanvas)t();return i},e._save=async(e,t,r)=>{if(t=t||"untitled","jpg"==(r=r||"png")||"png"==r||"webp"==r)if(e instanceof OffscreenCanvas){const t=await e.convertToBlob({type:"image/"+r});e=await new Promise((e=>{const r=new FileReader;r.onloadend=()=>e(r.result),r.readAsDataURL(t)}))}else e=e.toDataURL("image/"+r);else{let t="text/plain";"json"==r&&("string"!=typeof e&&(e=JSON.stringify(e)),t="text/json"),e=new Blob([e],{type:t}),e=URL.createObjectURL(e)}let o=document.createElement("a");o.href=e,o.download=t+"."+r,o.click(),URL.revokeObjectURL(o.href)},e.save=(t,r,o)=>{if((!t||"string"==typeof t&&(!r||!o&&r.length<5))&&(o=r,r=t,t=e.canvas),o)return e._save(t,r,o);r?(r=r.split("."),e._save(t,r[0],r.at(-1))):e._save(t)},e._setCanvasSize=(o,a)=>{o??=window.innerWidth,a??=window.innerHeight,r.w=o=Math.ceil(o),r.h=a=Math.ceil(a),r.hw=o/2,r.hh=a/2,r.width=Math.ceil(o*e._pixelDensity),r.height=Math.ceil(a*e._pixelDensity),e._da?e.flexibleCanvas(e._dau):(t.width=o,t.height=a),e.displayMode&&!r.displayMode?e.displayMode():e._adjustDisplay()},"image"!=e._scope){if(r&&"graphics"!=e._scope){function o(){let t=e._parent;t??=document.getElementsByTagName("main")[0],t||(t=document.createElement("main"),document.body.append(t)),r.parent(t)}r.parent=t=>{function o(){e.frameCount>1&&(e._shouldResize=!0,e._adjustDisplay())}r.parentElement&&r.parentElement.removeChild(r),"string"==typeof t&&(t=document.getElementById(t)),t.append(r),"function"==typeof ResizeObserver?(e._ro&&e._ro.disconnect(),e._ro=new ResizeObserver(o),e._ro.observe(t)):e.frameCount||window.addEventListener("resize",o)},document.body?o():document.addEventListener("DOMContentLoaded",o)}e.resizeCanvas=(t,o)=>{if(!e.ctx)return e.createCanvas(t,o);t==r.w&&o==r.h||e._resizeCanvas(t,o)},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(r.w,r.h),t):e._pixelDensity,e.flexibleCanvas=(o=400)=>{o?(e._da=r.width/(o*e._pixelDensity),t.width=e._dau=o,t.height=r.h/r.w*o):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 r=e.canvas;e.colorMode&&e.colorMode("rgb","integer"),e._createCanvas=function(o,a,n){return t.ctx=t.drawingContext=r.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(),r},"image"!=e._scope&&(e._resizeCanvas=(t,o)=>{let a={};for(let t in e.ctx)"function"!=typeof e.ctx[t]&&(a[t]=e.ctx[t]);delete a.canvas;let n=new e._OffscreenCanvas(r.width,r.height);n.w=r.w,n.h=r.h,n.getContext("2d").drawImage(r,0,0),e._setCanvasSize(t,o);for(let t in a)e.ctx[t]=a[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,r)=>{e._da&&(t*=e._da,r*=e._da),e.ctx.translate(t,r)},e.rotate=t=>{"degrees"==e._angleMode&&(t=e.radians(t)),e.ctx.rotate(t)},e.scale=(t,r)=>{r??=t,e.ctx.scale(t,r)},e.opacity=t=>e.ctx.globalAlpha=t,e.applyMatrix=(t,r,o,a,n,i)=>e.ctx.transform(t,r,o,a,n,i),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 r of e._styleNames)t[r]=e[r];e._styles.push(t)},e.pop=e.popMatrix=()=>{e.ctx.restore();let t=e._styles.pop();for(let r of e._styleNames)e[r]=t[r]},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,r,o){let a=new Q5("graphics");return o??={},o.alpha??=!0,o.colorSpace??=e.canvas.colorSpace,a.createCanvas.call(e,t,r,o),a},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,r=[];function o(){e._doFill&&e.ctx.fill(),e._doStroke&&e.ctx.stroke()}function a(t,r,a,n,i,s,l,d){if(!e._doFill&&!e._doStroke)return;let c="degrees"==e._angleMode,h=c?360:e.TAU;if((i%=h)<0&&(i+=h),(s%=h)<0&&(s+=h),0!=i||0!=s){if(i>s&&([i,s]=[s,i]),e.ctx.beginPath(),a==n)c&&(i=e.radians(i),s=e.radians(s)),e.ctx.arc(t,r,a/2,i,s);else{for(let o=0;o<d+1;o++){let l=o/d,c=e.lerp(i,s,l),h=e.cos(c)*a/2,u=e.sin(c)*n/2;e.ctx[o?"lineTo":"moveTo"](t+h,r+u)}l==e.CHORD?e.ctx.closePath():l==e.PIE&&(e.ctx.lineTo(t,r),e.ctx.closePath())}o()}}function n(t,r,a,n){(e._doFill||e._doStroke)&&(e._da&&(t*=e._da,r*=e._da,a*=e._da,n*=e._da),e.ctx.beginPath(),e.ctx.ellipse(t,r,a/2,n/2,0,0,e.TAU),o())}function i(t,r,a,n,s,l,d,c){if(e._doFill||e._doStroke){if(void 0===s)return function(t,r,a,n){e._da&&(t*=e._da,r*=e._da,a*=e._da,n*=e._da),e.ctx.beginPath(),e.ctx.rect(t,r,a,n),o()}(t,r,a,n);if(void 0===l)return i(t,r,a,n,s,s,s,s);e._da&&(t*=e._da,r*=e._da,a*=e._da,n*=e._da,s*=e._da,l*=e._da,c*=e._da,d*=e._da),e.ctx.roundRect(t,r,a,n,[s,l,d,c]),o()}}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,r,o,a)=>{e._doStroke&&(e._da&&(t*=e._da,r*=e._da,o*=e._da,a*=e._da),e.ctx.beginPath(),e.ctx.moveTo(t,r),e.ctx.lineTo(o,a),e.ctx.stroke())},e.arc=(t,r,o,n,i,s,l,d=25)=>{if(i==s)return e.ellipse(t,r,o,n);l??=e.PIE,e._ellipseMode==e.CENTER?a(t,r,o,n,i,s,l,d):e._ellipseMode==e.RADIUS?a(t,r,2*o,2*n,i,s,l,d):e._ellipseMode==e.CORNER?a(t+o/2,r+n/2,o,n,i,s,l,d):e._ellipseMode==e.CORNERS&&a((t+o)/2,(r+n)/2,o-t,n-r,i,s,l,d)},e.ellipse=(t,r,o,a)=>{a??=o,e._ellipseMode==e.CENTER?n(t,r,o,a):e._ellipseMode==e.RADIUS?n(t,r,2*o,2*a):e._ellipseMode==e.CORNER?n(t+o/2,r+a/2,o,a):e._ellipseMode==e.CORNERS&&n((t+o)/2,(r+a)/2,o-t,a-r)},e.circle=(t,r,a)=>{e._ellipseMode==e.CENTER?(e._da&&(t*=e._da,r*=e._da,a*=e._da),e.ctx.beginPath(),e.ctx.arc(t,r,a/2,0,e.TAU),o()):e.ellipse(t,r,a,a)},e.point=(t,r)=>{t.x&&(r=t.y,t=t.x),e._da&&(t*=e._da,r*=e._da),e.ctx.save(),e.ctx.beginPath(),e.ctx.arc(t,r,e.ctx.lineWidth/2,0,e.TAU),e.ctx.fillStyle=e.ctx.strokeStyle,e.ctx.fill(),e.ctx.restore()},e.rect=(t,r,o,a=o,n,s,l,d)=>{e._rectMode==e.CENTER?i(t-o/2,r-a/2,o,a,n,s,l,d):e._rectMode==e.RADIUS?i(t-o,r-a,2*o,2*a,n,s,l,d):e._rectMode==e.CORNER?i(t,r,o,a,n,s,l,d):e._rectMode==e.CORNERS&&i(t,r,o-t,a-r,n,s,l,d)},e.square=(t,r,o,a,n,i,s)=>e.rect(t,r,o,o,a,n,i,s),e.beginShape=()=>{r=[],e.ctx.beginPath(),t=!0},e.beginContour=()=>{e.ctx.closePath(),r=[],t=!0},e.endContour=()=>{r=[],t=!0},e.vertex=(o,a)=>{e._da&&(o*=e._da,a*=e._da),r=[],t?e.ctx.moveTo(o,a):e.ctx.lineTo(o,a),t=!1},e.bezierVertex=(t,o,a,n,i,s)=>{e._da&&(t*=e._da,o*=e._da,a*=e._da,n*=e._da,i*=e._da,s*=e._da),r=[],e.ctx.bezierCurveTo(t,o,a,n,i,s)},e.quadraticVertex=(t,o,a,n)=>{e._da&&(t*=e._da,o*=e._da,a*=e._da,n*=e._da),r=[],e.ctx.quadraticCurveTo(t,o,a,n)},e.bezier=(t,r,o,a,n,i,s,l)=>{e.beginShape(),e.vertex(t,r),e.bezierVertex(o,a,n,i,s,l),e.endShape()},e.triangle=(t,r,o,a,n,i)=>{e.beginShape(),e.vertex(t,r),e.vertex(o,a),e.vertex(n,i),e.endShape(e.CLOSE)},e.quad=(t,r,o,a,n,i,s,l)=>{e.beginShape(),e.vertex(t,r),e.vertex(o,a),e.vertex(n,i),e.vertex(s,l),e.endShape(e.CLOSE)},e.endShape=t=>{r=[],t&&e.ctx.closePath(),o()},e.curveVertex=(o,a)=>{if(e._da&&(o*=e._da,a*=e._da),r.push([o,a]),r.length<4)return;let n=function(e,t,r,o,a,n,i,s,l,d){function c(e,t,r,o,a,n){let i=Math.pow(o-t,2)+Math.pow(a-r,2);return Math.pow(i,.5*n)+e}let h=[],u=c(0,e,t,r,o,d),p=c(u,r,o,a,n,d),_=c(p,a,n,i,s,d);for(let d=0;d<l;d++){let c=u+d/(l-1)*(p-u),g=[(u-c)/(u-0),(c-0)/(u-0),(p-c)/(p-u),(c-u)/(p-u),(_-c)/(_-p),(c-p)/(_-p),(p-c)/(p-0),(c-0)/(p-0),(_-c)/(_-u),(c-u)/(_-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]+r*g[1],f=t*g[0]+o*g[1],m=r*g[2]+a*g[3],v=o*g[2]+n*g[3],y=a*g[4]+i*g[5],w=n*g[4]+s*g[5],S=x*g[6]+m*g[7],b=f*g[6]+v*g[7],C=m*g[8]+y*g[9],M=v*g[8]+w*g[9],Q=S*g[2]+C*g[3],R=b*g[2]+M*g[3];h.push([Q,R])}return h}(...r.at(-4),...r.at(-3),...r.at(-2),...r.at(-1),e._curveDetail,e._curveAlpha);for(let r=0;r<n.length;r++)t?e.ctx.moveTo(...n[r]):e.ctx.lineTo(...n[r]),t=!1},e.curve=(t,r,o,a,n,i,s,l)=>{e.beginShape(),e.curveVertex(t,r),e.curveVertex(o,a),e.curveVertex(n,i),e.curveVertex(s,l),e.endShape()},e.curvePoint=(e,t,r,o,a)=>{const n=a*a*a,i=a*a;return e*(-.5*n+i-.5*a)+t*(1.5*n-2.5*i+1)+r*(-1.5*n+2*i+.5*a)+o*(.5*n-.5*i)},e.bezierPoint=(e,t,r,o,a)=>{const n=1-a;return Math.pow(n,3)*e+3*Math.pow(n,2)*a*t+3*n*Math.pow(a,2)*r+Math.pow(a,3)*o},e.curveTangent=(e,t,r,o,a)=>{const n=a*a;return e*(-3*n/2+2*a-.5)+t*(9*n/2-5*a)+r*(-9*n/2+4*a+.5)+o*(3*n/2-a)},e.bezierTangent=(e,t,r,o,a)=>{const n=1-a;return 3*o*Math.pow(a,2)-3*r*Math.pow(a,2)+6*r*n*a-6*t*n*a+3*t*Math.pow(n,2)-3*e*Math.pow(n,2)},e.erase=function(t=255,r=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, ${r/255})`},e.noErase=function(){e.ctx.globalCompositeOperation="source-over",e.ctx.restore()},e.inFill=(t,r)=>{const o=e._pixelDensity;return e.ctx.isPointInPath(t*o,r*o)},e.inStroke=(t,r)=>{const o=e._pixelDensity;return e.ctx.isPointInStroke(t*o,r*o)}},Q5.renderers.q2d.image=(e,t)=>{Q5.Image??=class{constructor(e,t,r){let o=this;o._scope="image",o.canvas=o.ctx=o.drawingContext=null,o.pixels=[],Q5.modules.canvas(o,o);let a=Q5.renderers.q2d;for(let e of["canvas","image","soft_filters"])a[e]&&a[e](o,o);o.createCanvas(e,t,r),delete o.createCanvas,o._loop=!1}get w(){return this.width}get h(){return this.height}},e.createImage=(t,r,o)=>(o??={},o.alpha??=!0,o.colorSpace??=e.canvas.colorSpace||Q5.canvasOptions.colorSpace,new Q5.Image(t,r,o)),e.loadImage=function(r,o,a){if(r.canvas)return r;if("gif"==r.slice(-3).toLowerCase())throw new Error("q5 doesn't support GIFs due to their impact on performance. Use a video or animation instead.");t._preloadCount++;let n=[...arguments].at(-1);a="object"==typeof n?n:null;let i=e.createImage(1,1,a);function s(e){i.resize(e.naturalWidth||e.width,e.naturalHeight||e.height),i.ctx.drawImage(e,0,0),t._preloadCount--,o&&o(i)}if(Q5._nodejs&&global.CairoCanvas)global.CairoCanvas.loadImage(r).then(s).catch((e=>{throw t._preloadCount--,e}));else{let e=new window.Image;e.src=r,e.crossOrigin="Anonymous",e._pixelDensity=1,e.onload=()=>s(e),e.onerror=e=>{throw t._preloadCount--,e}}return i},e.imageMode=t=>e._imageMode=t,e.image=(t,r,o,a,n,i=0,s=0,l,d)=>{let c=t.canvas||t;Q5._createNodeJSCanvas&&(c=c.context.canvas),a??=t.width||t.videoWidth,n??=t.height||t.videoHeight,"center"==e._imageMode&&(r-=.5*a,o-=.5*n),e._da&&(r*=e._da,o*=e._da,a*=e._da,n*=e._da,i*=e._da,s*=e._da,l*=e._da,d*=e._da);let h=t._pixelDensity||1;l?l*=h:l=c.width||c.videoWidth,d?d*=h:d=c.height||c.videoHeight,e.ctx.drawImage(c,i*h,s*h,l,d,r,o,a,n),e._tint&&(e.ctx.globalCompositeOperation="multiply",e.ctx.fillStyle=e._tint.toString(),e.ctx.fillRect(r,o,a,n),e.ctx.globalCompositeOperation="source-over")},e._tint=null;let r=null;e._softFilter=()=>{throw new Error("Load q5-2d-soft-filters.js to use software filters.")},e.filter=(t,r)=>{if(!e.ctx.filter)return e._softFilter(t,r);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(r*e._pixelDensity)||1;f=`blur(${t}px)`}else{if(t!=Q5.THRESHOLD)return e._softFilter(t,r);{r??=.5;let e=Math.floor(.5/Math.max(r,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,r)=>{let o=new e._OffscreenCanvas(e.canvas.width,e.canvas.height);o.getContext("2d",{colorSpace:e.canvas.colorSpace}).drawImage(e.canvas,0,0),e._setCanvasSize(t,r),e.ctx.clearRect(0,0,e.canvas.width,e.canvas.height),e.ctx.drawImage(o,0,0,e.canvas.width,e.canvas.height)}),e.trim=()=>{let t=e._pixelDensity||1,r=e.canvas.width,o=e.canvas.height,a=e.ctx.getImageData(0,0,r,o).data,n=r,i=0,s=o,l=0,d=3;for(let e=0;e<o;e++)for(let t=0;t<r;t++)0!==a[d]&&(t<n&&(n=t),t>i&&(i=t),e<s&&(s=e),e>l&&(l=e)),d+=4;return s=Math.floor(s/t),l=Math.floor(l/t),n=Math.floor(n/t),i=Math.floor(i/t),e.get(n,s,i-n+1,l-s+1)},e.mask=t=>{e.ctx.save(),e.ctx.resetTransform();let r=e.ctx.globalCompositeOperation;e.ctx.globalCompositeOperation="destination-in",e.ctx.drawImage(t.canvas,0,0),e.ctx.globalCompositeOperation=r,e.ctx.restore()},e.get=(t,r,o,a)=>{let n=e._pixelDensity||1;if(void 0!==t&&void 0===o){let o=e.ctx.getImageData(t*n,r*n,1,1).data;return new e.Color(o[0],o[1],o[2],o[3]/255)}t=(t||0)*n,r=(r||0)*n;let i=o=o||e.width,s=a=a||e.height;o*=n,a*=n;let l=e.createImage(o,a),d=e.ctx.getImageData(t,r,o,a);return l.ctx.putImageData(d,0,0),l._pixelDensity=n,l.width=i,l.height=s,l},e.set=(t,r,o)=>{if(o.canvas){let a=e._tint;return e._tint=null,e.image(o,t,r),void(e._tint=a)}e.pixels.length||e.loadPixels();let a=e._pixelDensity||1;for(let n=0;n<a;n++)for(let i=0;i<a;i++){let s=4*((r*a+n)*e.canvas.width+t*a+i);e.pixels[s]=o.r??o.l,e.pixels[s+1]=o.g??o.c,e.pixels[s+2]=o.b??o.h,e.pixels[s+3]=o.a}},e.loadPixels=()=>{r=e.ctx.getImageData(0,0,e.canvas.width,e.canvas.height),t.pixels=r.data},e.updatePixels=()=>{null!=r&&e.ctx.putImageData(r,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.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,r)=>{t._preloadCount++;let o=e.split("/").pop().split(".")[0].replace(" ",""),a=new FontFace(o,`url(${e})`);return document.fonts.add(a),a.load().then((()=>{t._preloadCount--,r&&r(o)})),o},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,r)=>{e.ctx.textAlign=t,r&&(e.ctx.textBaseline=r==e.CENTER?"middle":r)},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,r=0;for(const[o,a]of this.entries())a.lastAccessed<t&&(t=a.lastAccessed,e=r),r++;r=e;for(const t of this.keys()){if(0==r){e=t;break}r--}this.delete(e)}},e._tic=new e._TimedCache,e.textCache=(t,r)=>(r&&(e._tic.maxSize=r),void 0!==t&&(e._textCache=t),e._textCache),e._genTextImageKey=(t,r,o)=>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+"_":"")+(r||"")+(o?"x"+o:""),e.createTextImage=(t,r,o)=>{let a=e._textCache;e._textCache=!0,e._genTextImage=!0,e.text(t,0,0,r,o),e._genTextImage=!1;let n=e._genTextImageKey(t,r,o);return e._textCache=a,e._tic.get(n)},e.text=(t,r,o,a,n)=>{if(void 0===t)return;if(t=t.toString(),e._da&&(r*=e._da,o*=e._da),!e._doFill&&!e._doStroke)return;let i,s,l,d,c,h,u,p,_=e.ctx.getTransform(),g=e._genTextImage||e._textCache&&(0!=_.b||0!=_.c);if(g){if(d=e._genTextImageKey(t,a,n),s=e._tic.get(d),s&&!e._genTextImage)return void e.textImage(s,r,o);l=e.createGraphics.call(e,1,1),i=l.ctx}else i=e.ctx,c=r,h=o;i.font=`${e._textStyle} ${e._textSize}px ${e._textFont}`;let x=t.split("\n");if(g){c=0,h=e._textLeading*x.length;let r=i.measureText(" ");u=r.fontBoundingBoxAscent,p=r.fontBoundingBoxDescent,n??=h+p,l.resizeCanvas(Math.ceil(i.measureText(t).width),Math.ceil(n)),i.fillStyle=e.ctx.fillStyle,i.strokeStyle=e.ctx.strokeStyle,i.lineWidth=e.ctx.lineWidth}let f=i.fillStyle;e._fillSet||(i.fillStyle="black");for(let t=0;t<x.length&&(e._doStroke&&e._strokeSet&&i.strokeText(x[t],c,h),e._doFill&&i.fillText(x[t],c,h),h+=e._textLeading,!(h>n));t++);e._fillSet||(i.fillStyle=f),g&&(s=l.get(),s._ascent=u,s._descent=p,e._tic.set(d,s),e._genTextImage||e.textImage(s,r,o))},e.textImage=(t,r,o)=>{let a=e._imageMode;e._imageMode="corner","center"==e.ctx.textAlign?r-=.5*t.width:"right"==e.ctx.textAlign&&(r-=t.width),"alphabetic"==e.ctx.textBaseline&&(o-=e._textLeading),"middle"==e.ctx.textBaseline?o-=t._descent+.5*t._ascent+e._textLeadDiff:"bottom"==e.ctx.textBaseline?o-=t._ascent+t._descent+e._textLeadDiff:"top"==e.ctx.textBaseline&&(o-=t._descent+e._textLeadDiff),e.image(t,r,o),e._imageMode=a},e.nf=(e,t,r)=>{let o=e<0,a=(e=Math.abs(e)).toFixed(r).split(".");a[0]=a[0].padStart(t,"0");let n=a.join(".");return o&&(n="-"+n),n}},Q5.modules.ai=e=>{e.askAI=(e="")=>{throw Error("Ask AI ✨ "+e)},e._aiErrorAssistance=async t=>{let r=t.message?.includes("Ask AI ✨");if(Q5.disableFriendlyErrors&&!r)return;!r&&Q5.errorTolerant||e.noLoop();let o=t.stack?.split("\n");if(!t.stack||o.length<=1)return;let a=1,n="(";for(-1==navigator.userAgent.indexOf("Chrome")&&(a=0,n="@");o[a].indexOf("q5")>=0;)a++;let i=o[a].split(n).at(-1);i=i.split(":");let s=parseInt(i.at(-2));r&&s++;let l=i.slice(0,-2).join(":"),d=l.split("/").at(-1);try{let e=(await(await fetch(l)).text()).split("\n"),o=e[s-1].trim(),a="",n=1;for(;a.length<1600&&(s-n>=0&&(a=e[s-n].trim()+"\n"+a),s+n<e.length);)a+=e[s+n].trim()+"\n",n++;let i="https://chatgpt.com/?q=q5.js+"+(r&&t.message.length>10?t.message.slice(10):"Whats+wrong+with+this+line%3F+short+answer")+(r?"":"%0A%0A"+encodeURIComponent(t.name+": "+t.message))+"%0A%0ALine%3A+"+encodeURIComponent(o)+"%0A%0AExcerpt+for+context%3A%0A%0A"+encodeURIComponent(a);if(console.warn("Error in "+d+" on line "+s+":\n\n"+o),console.warn("Ask AI ✨ "+i),r)return window.open(i,"_blank")}catch(e){}}},Q5.modules.color=(e,t)=>{e.RGB=e.RGBA=e._colorMode="rgb",e.OKLCH="oklch",e.colorMode=(r,o)=>{e._colorMode=r;let a="srgb"==e.canvas.colorSpace||"srgb"==r;if(o??=a?"integer":"float",e._colorFormat="float"==o||1==o?1:255,"oklch"==r)t.Color=Q5.ColorOKLCH;else{let r="srgb"==e.canvas.colorSpace;255==e._colorFormat?t.Color=r?Q5.ColorRGBA_8:Q5.ColorRGBA_P3_8:t.Color=r?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,r,o,a)=>{let n=e.Color;if(t._q5Color)return new n(...t.levels);if(null==r){if("string"==typeof t){if("#"==t[0])t.length<=5?(t.length>4&&(a=parseInt(t[4]+t[4],16)),o=parseInt(t[3]+t[3],16),r=parseInt(t[2]+t[2],16),t=parseInt(t[1]+t[1],16)):(t.length>7&&(a=parseInt(t.slice(7,9),16)),o=parseInt(t.slice(5,7),16),r=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,r,o,a]=e._namedColors[t]}1==e._colorFormat&&(t/=255,r&&(r/=255),o&&(o/=255),a&&(a/=255))}Array.isArray(t)&&([t,r,o,a]=t)}return null==o?new n(t,t,t,r):new n(t,r,o,a)},e.red=e=>e.r,e.green=e=>e.g,e.blue=e=>e.b,e.alpha=e=>e.a,e.lightness=e=>e.l?e.l:100*(.2126*e.r+.7152*e.g+.0722*e.b)/255,e.hue=t=>{if(t.h)return t.h;let r=t.r,o=t.g,a=t.b;255==e._colorFormat&&(r/=255,o/=255,a/=255);let n,i=Math.max(r,o,a),s=Math.min(r,o,a);return n=i==s?0:i==r?60*(o-a)/(i-s):i==o?60*(a-r)/(i-s)+120:60*(r-o)/(i-s)+240,n<0&&(n+=360),n},e.lerpColor=(t,r,o)=>{if("rgb"==e._colorMode)return new e.Color(e.constrain(e.lerp(t.r,r.r,o),0,255),e.constrain(e.lerp(t.g,r.g,o),0,255),e.constrain(e.lerp(t.b,r.b,o),0,255),e.constrain(e.lerp(t.a,r.a,o),0,255));{let a=r.h-t.h;a>180&&(a-=360),a<-180&&(a+=360);let n=t.h+o*a;return n<0&&(n+=360),n>360&&(n-=360),new e.Color(e.constrain(e.lerp(t.l,r.l,o),0,100),e.constrain(e.lerp(t.c,r.c,o),0,100),n,e.constrain(e.lerp(t.a,r.a,o),0,255))}}},Q5.Color=class{constructor(){this._q5Color=!0}},Q5.ColorOKLCH=class extends Q5.Color{constructor(e,t,r,o){super(),this.l=e,this.c=t,this.h=r,this.a=o??1}toString(){return`oklch(${this.l} ${this.c} ${this.h} / ${this.a})`}},Q5.ColorRGBA=class extends Q5.Color{constructor(e,t,r,o){super(),this.r=e,this.g=t,this.b=r,this.a=o??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,r,o){super(e,t,r,o??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,r,o){super(e,t,r,o??255),this._edited=!0}get r(){return this._r}set r(e){this._r=e,this._edited=!0}get g(){return this._g}set g(e){this._g=e,this._edited=!0}get b(){return this._b}set b(e){this._b=e,this._edited=!0}get a(){return this._a}set a(e){this._a=e,this._edited=!0}toString(){if(this._edited){let e=(this._r/255).toFixed(3),t=(this._g/255).toFixed(3),r=(this._b/255).toFixed(3),o=(this._a/255).toFixed(3);this._css=`color(display-p3 ${e} ${t} ${r} / ${o})`,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 r=t.style,o=t.parentElement;r&&o&&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?(o.classList.remove("q5-centered","q5-maxed","q5-fullscreen"),r.width=t.w*t.displayScale+"px",r.height=t.h*t.displayScale+"px"):(o.classList.add("q5-"+t.displayMode),o=o.getBoundingClientRect(),t.w/t.h>o.width/o.height?("centered"==t.displayMode?(r.width=t.w*t.displayScale+"px",r.maxWidth="100%"):r.width="100%",r.height="auto",r.maxHeight=""):(r.width="auto",r.maxWidth="","centered"==t.displayMode?(r.height=t.h*t.displayScale+"px",r.maxHeight="100%"):r.height="100%")))},e.displayMode=(r="normal",o="default",a=1)=>{"string"==typeof a&&(a=parseFloat(a.slice(1))),Object.assign(t,{displayMode:r,renderQuality:o,displayScale:a}),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 r={},o=[e.LEFT,e.CENTER,e.RIGHT],a=e.canvas;function n(t){const r=e.canvas.getBoundingClientRect(),o=e.canvas.scrollWidth/e.width||1,a=e.canvas.scrollHeight/e.height||1;return{x:(t.clientX-r.left)/o,y:(t.clientY-r.top)/a,id:t.identifier}}if(e._startAudio=()=>{e.getAudioContext&&"suspended"==e.getAudioContext()?.state&&e.userStartAudio()},e._updateMouse=r=>{if(!r.changedTouches)if(a){let o=a.getBoundingClientRect(),n=a.scrollWidth/e.width||1,i=a.scrollHeight/e.height||1;t.mouseX=(r.clientX-o.left)/n,t.mouseY=(r.clientY-o.top)/i,"webgpu"==a.renderer&&(t.mouseX-=a.hw,t.mouseY-=a.hh)}else t.mouseX=r.clientX,t.mouseY=r.clientY},e._onmousedown=r=>{e._startAudio(),e._updateMouse(r),t.mouseIsPressed=!0,t.mouseButton=o[r.button],e.mousePressed(r)},e._onmousemove=t=>{e._updateMouse(t),e.mouseIsPressed?e.mouseDragged(t):e.mouseMoved(t)},e._onmouseup=r=>{e._updateMouse(r),t.mouseIsPressed=!1,e.mouseReleased(r)},e._onclick=r=>{e._updateMouse(r),t.mouseIsPressed=!0,e.mouseClicked(r),t.mouseIsPressed=!1},e.cursor=(t,r,o)=>{let a="";t.includes(".")&&(t=`url("${t}")`,a=", auto"),void 0!==r&&(t+=" "+r+" "+o),e.canvas.style.cursor=t+a},e.noCursor=()=>{e.canvas.style.cursor="none"},e.requestPointerLock=document.body?.requestPointerLock,e.exitPointerLock=document.exitPointerLock,e._onkeydown=o=>{o.repeat||(e._startAudio(),t.keyIsPressed=!0,t.key=o.key,t.keyCode=o.keyCode,r[e.keyCode]=r[e.key.toLowerCase()]=!0,e.keyPressed(o),1==o.key.length&&e.keyTyped(o))},e._onkeyup=o=>{t.keyIsPressed=!1,t.key=o.key,t.keyCode=o.keyCode,r[e.keyCode]=r[e.key.toLowerCase()]=!1,e.keyReleased(o)},e.keyIsDown=e=>!!r["string"==typeof e?e.toLowerCase():e],e._ontouchstart=r=>{e._startAudio(),t.touches=[...r.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(r)||r.preventDefault()),e.touchStarted(r)||r.preventDefault()},e._ontouchmove=r=>{t.touches=[...r.touches].map(n),e._isTouchAware||(t.mouseX=e.touches[0].x,t.mouseY=e.touches[0].y,e.mouseDragged(r)||r.preventDefault()),e.touchMoved(r)||r.preventDefault()},e._ontouchend=r=>{t.touches=[...r.touches].map(n),e._isTouchAware||e.touches.length||(t.mouseIsPressed=!1,e.mouseReleased(r)||r.preventDefault()),e.touchEnded(r)||r.preventDefault()},a&&(a.addEventListener("mousedown",(t=>e._onmousedown(t))),a.addEventListener("mouseup",(t=>e._onmouseup(t))),a.addEventListener("click",(t=>e._onclick(t))),a.addEventListener("touchstart",(t=>e._ontouchstart(t))),a.addEventListener("touchmove",(t=>e._ontouchmove(t))),a.addEventListener("touchcancel",(t=>e._ontouchend(t))),a.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,r,o,a,n)=>{let i=o+1*(e-t)/(r-t)*(a-o);return n?o<a?Math.min(Math.max(i,o),a):Math.min(Math.max(i,a),o):i},e.lerp=(e,t,r)=>e*(1-r)+t*r,e.constrain=(e,t,r)=>Math.min(Math.max(e,t),r),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,r,o)=>e.map(t,r,o,0,1),e.sq=e=>e*e,e.fract=e=>e-Math.floor(e);for(let t of["sin","cos","tan"])e[t]=r=>("degrees"==e._angleMode&&(r=e.radians(r)),Math[t](r));for(let t of["asin","acos","atan"])e[t]=r=>{let o=Math[t](r);return"degrees"==e._angleMode&&(o=e.degrees(o)),o};function r(){let e,t,r=4294967295;return{setSeed(o){e=t=(o??Math.random()*r)>>>0},getSeed:()=>t,rand:()=>(e^=e<<17,e^=e>>13,e^=e<<5,(e>>>0)/r)}}e.atan2=(t,r)=>{let o=Math.atan2(t,r);return"degrees"==e._angleMode&&(o=e.degrees(o)),o};let o=r();o.setSeed(),e.randomSeed=e=>o.setSeed(e),e.random=(e,t)=>void 0===e?o.rand():"number"==typeof e?void 0!==t?o.rand()*(t-e)+e:o.rand()*e:e[Math.trunc(e.length*o.rand())],e.randomGenerator=t=>{t==e.LCG?o=function(){const e=4294967296;let t,r;return{setSeed(o){r=t=(o??Math.random()*e)>>>0},getSeed:()=>t,rand:()=>(r=(1664525*r+1013904223)%e,r/e)}}():t==e.SHR3&&(o=r()),o.setSeed()};var a=new function(){var e,t,r,a=new Array(128),n=new Array(256),i=new Array(128),s=new Array(128),l=new Array(256),d=new Array(256),c=()=>4294967296*o.rand()-2147483648,h=()=>.5+2.328306e-10*(c()|0),u=()=>{for(var t,o,n,l,d=3.44262;;){if(t=r*i[e],0==e){do{n=h(),l=h(),t=.2904764*-Math.log(n),o=-Math.log(l)}while(o+o<t*t);return r>0?d+t:-d-t}if(s[e]+h()*(s[e-1]-s[e])<Math.exp(-.5*t*t))return t;if(r=c(),e=127&r,Math.abs(r)<a[e])return r*i[e]}},p=()=>{for(var r;;){if(0==e)return 7.69711-Math.log(h());if(r=t*l[e],d[e]+h()*(d[e-1]-d[e])<Math.exp(-r))return r;if((t=c())<n[e=255&t])return t*l[e]}};this.SHR3=c,this.UNI=h,this.RNOR=()=>(r=c(),e=127&r,Math.abs(r)<a[e]?r*i[e]:u()),this.REXP=()=>(t=c()>>>0)<a[e=255&t]?t*l[e]:p(),this.zigset=()=>{var e,t,r=2147483648,o=4294967296,c=3.442619855899,h=c,u=.00991256303526217,p=7.697117470131487,_=p,g=.003949659822581572;for(e=u/Math.exp(-.5*c*c),a[0]=Math.floor(c/e*r),a[1]=0,i[0]=e/r,i[127]=c/r,s[0]=1,s[127]=Math.exp(-.5*c*c),t=126;t>=1;t--)c=Math.sqrt(-2*Math.log(u/c+Math.exp(-.5*c*c))),a[t+1]=Math.floor(c/h*r),h=c,s[t]=Math.exp(-.5*c*c),i[t]=c/r;for(e=g/Math.exp(-p),n[0]=Math.floor(p/e*o),n[1]=0,l[0]=e/o,l[255]=p/o,d[0]=1,d[255]=Math.exp(-p),t=254;t>=1;t--)p=-Math.log(g/p+Math.exp(-p)),n[t+1]=Math.floor(p/_*o),_=p,d[t]=Math.exp(-p),l[t]=p/o}};let n;a.hasInit=!1,e.randomGaussian=(e,t)=>(a.hasInit||(a.zigset(),a.hasInit=!0),a.RNOR()*t+e),e.randomExponential=()=>(a.hasInit||(a.zigset(),a.hasInit=!0),a.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,r=0,o=0)=>(n??=new e.Noise,n.noise(t,r,o)),e.noiseDetail=(t,r)=>{n??=new e.Noise,t>0&&(n.octaves=t),r>0&&(n.falloff=r)}},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,r,o=[];for(let e=0;e<256;e++)o[e]=e;for(let a=255;a>0;a--)t=(e=16807*e%2147483647)%(a+1),r=o[a],o[a]=o[t],o[t]=r;return o}dot(e,t,r,o){return e[0]*t+e[1]*r+e[2]*o}mix(e,t,r){return(1-r)*e+r*t}fade(e){return e*e*e*(e*(6*e-15)+10)}noise(e,t,r){let o=this,a=0,n=1,i=1,s=0;for(let l=0;l<o.octaves;l++){const l=255&Math.floor(e*n),d=255&Math.floor(t*n),c=255&Math.floor(r*n),h=e*n-Math.floor(e*n),u=t*n-Math.floor(t*n),p=r*n-Math.floor(r*n),_=o.fade(h),g=o.fade(u),x=o.fade(p),f=o.p[l]+d,m=o.p[f]+c,v=o.p[f+1]+c,y=o.p[l+1]+d,w=o.p[y]+c,S=o.p[y+1]+c,b=o.mix(o.dot(o.grad3[o.p[m]%12],h,u,p),o.dot(o.grad3[o.p[w]%12],h-1,u,p),_),C=o.mix(o.dot(o.grad3[o.p[v]%12],h,u-1,p),o.dot(o.grad3[o.p[S]%12],h-1,u-1,p),_),M=o.mix(o.dot(o.grad3[o.p[m+1]%12],h,u,p-1),o.dot(o.grad3[o.p[w+1]%12],h-1,u,p-1),_),Q=o.mix(o.dot(o.grad3[o.p[v+1]%12],h,u-1,p-1),o.dot(o.grad3[o.p[S+1]%12],h-1,u-1,p-1),_),R=o.mix(b,C,g),I=o.mix(M,Q,g);a+=o.mix(R,I,x)*i,s+=i,i*=o.falloff,n*=2}return(a/s+1)/2}},Q5.modules.sound=(e,t)=>{e.Sound=Q5.Sound,e.loadSound=(e,r)=>{t._preloadCount++,Q5.aud??=new window.AudioContext;let o=new Q5.Sound(e,r);return o.addEventListener("canplaythrough",(()=>{t._preloadCount--,o.loaded=!0,r&&r(o)})),o},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,r,o)=>{t._preloadCount++;let a={};return fetch(e).then((e=>"json"==o?e.json():"text"==o?e.text():void 0)).then((e=>{t._preloadCount--,Object.assign(a,e),r&&r(e)})),a},e.loadStrings=(t,r)=>e._loadFile(t,r,"text"),e.loadJSON=(t,r)=>e._loadFile(t,r,"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,r,o)=>new Q5.Vector(t,r,o,e)},Q5.Vector=class{constructor(e,t,r,o){this.x=e||0,this.y=t||0,this.z=r||0,this._$=o||window,this._cn=null,this._cnsq=null}set(e,t,r){return this.x=e?.x||e||0,this.y=e?.y||t||0,this.z=e?.z||r||0,this}copy(){return new Q5.Vector(this.x,this.y,this.z)}_arg2v(e,t,r){return void 0!==e?.x?e:void 0!==t?{x:e,y:t,z:r||0}:{x:e,y:e,z:e}}_calcNorm(){this._cnsq=this.x*this.x+this.y*this.y+this.z*this.z,this._cn=Math.sqrt(this._cnsq)}add(){let e=this._arg2v(...arguments);return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}rem(){let e=this._arg2v(...arguments);return this.x%=e.x,this.y%=e.y,this.z%=e.z,this}sub(){let e=this._arg2v(...arguments);return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}mult(){let e=this._arg2v(...arguments);return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}div(){let e=this._arg2v(...arguments);return e.x?this.x/=e.x:this.x=0,e.y?this.y/=e.y:this.y=0,e.z?this.z/=e.z:this.z=0,this}mag(){return this._calcNorm(),this._cn}magSq(){return this._calcNorm(),this._cnsq}dot(){let e=this._arg2v(...arguments);return this.x*e.x+this.y*e.y+this.z*e.z}dist(){let e=this._arg2v(...arguments),t=this.x-e.x,r=this.y-e.y,o=this.z-e.z;return Math.sqrt(t*t+r*r+o*o)}cross(){let e=this._arg2v(...arguments),t=this.y*e.z-this.z*e.y,r=this.z*e.x-this.x*e.z,o=this.x*e.y-this.y*e.x;return this.x=t,this.y=r,this.z=o,this}normalize(){this._calcNorm();let e=this._cn;return 0!=e&&(this.x/=e,this.y/=e,this.z/=e),this._cn=1,this._cnsq=1,this}limit(e){this._calcNorm();let t=this._cn;if(t>e){let r=e/t;this.x*=r,this.y*=r,this.z*=r,this._cn=e,this._cnsq=e*e}return this}setMag(e){this._calcNorm();let t=e/this._cn;return this.x*=t,this.y*=t,this.z*=t,this._cn=e,this._cnsq=e*e,this}heading(){return this._$.atan2(this.y,this.x)}setHeading(e){let t=this.mag();return this.x=t*this._$.cos(e),this.y=t*this._$.sin(e),this}rotate(e){let t=this._$.cos(e),r=this._$.sin(e),o=this.x*t-this.y*r,a=this.x*r+this.y*t;return this.x=o,this.y=a,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=e.at(-1);if(0==t)return this;let r=this._arg2v(...e.slice(0,-1));return this.x+=(r.x-this.x)*t,this.y+=(r.y-this.y)*t,this.z+=(r.z-this.z)*t,this}slerp(){let e=[...arguments],t=e.at(-1);if(0==t)return this;let r=this._arg2v(...e.slice(0,-1));if(1==t)return this.set(r);let o=this.mag(),a=r.mag();if(0==o||0==a)return this.mult(1-t).add(r.mult(t));let n=Q5.Vector.cross(this,r),i=n.mag(),s=Math.atan2(i,this.dot(r));if(i>0)n.div(i);else{if(s<this._$.HALF_PI)return this.mult(1-t).add(r.mult(t));0==this.z&&0==r.z?n.set(0,0,1):0!=this.x?n.set(this.y,-this.x,0).normalize():n.set(1,0,0)}let l=n.cross(this),d=1-t+t*a/o,c=d*Math.cos(t*s),h=d*Math.sin(t*s);return this.x=this.x*c+l.x*h,this.y=this.y*c+l.y*h,this.z=this.z*c+l.z*h,this}reflect(e){return e.normalize(),this.sub(e.mult(2*this.dot(e)))}array(){return[this.x,this.y,this.z]}equals(e,t){return t??=Number.EPSILON||0,Math.abs(e.x-this.x)<t&&Math.abs(e.y-this.y)<t&&Math.abs(e.z-this.z)<t}fromAngle(e,t){return void 0===t&&(t=1),this._cn=t,this._cnsq=t*t,this.x=t*this._$.cos(e),this.y=t*this._$.sin(e),this.z=0,this}fromAngles(e,t,r){void 0===r&&(r=1),this._cn=r,this._cnsq=r*r;const o=this._$.cos(t),a=this._$.sin(t),n=this._$.cos(e),i=this._$.sin(e);return this.x=r*i*a,this.y=-r*n,this.z=r*i*o,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,r)=>e.equals(t,r),Q5.Vector.lerp=(e,t,r)=>e.copy().lerp(t,r),Q5.Vector.slerp=(e,t,r)=>e.copy().slerp(t,r),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,r,o)=>(new Q5.Vector)[e](t,r,o);Q5.renderers.webgpu={},Q5.renderers.webgpu.canvas=(e,t)=>{let r,o,a,n,i=e.canvas;function s(t,r,a,n=1){"string"==typeof t&&(t=Q5.color(t)),null==a&&(n=r,r=a=t),t._q5Color?o.push(...t.levels):o.push(t,r,a,n),e._colorIndex++}i.width=e.width=500,i.height=e.height=500,e.colorMode&&e.colorMode("rgb","float"),e._createCanvas=(r,n,s)=>{t.ctx=t.drawingContext=i.getContext("webgpu"),s.format=navigator.gpu.getPreferredCanvasFormat(),s.device=Q5.device,e.ctx.configure(s),e.pipelines=[],e.pipelinesStack=[],e.verticesStack=[],e.drawStack=[],o=e.colorsStack=[1,1,1,1],e._colorIndex=0;let l=Q5.device.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX,buffer:{type:"uniform",hasDynamicOffset:!1}}]}),d=Q5.device.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX,buffer:{type:"read-only-storage",hasDynamicOffset:!1}}]});e.bindGroupLayouts=[l,d];const c=Q5.device.createBuffer({size:8,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});Q5.device.queue.writeBuffer(c,0,new Float32Array([e.canvas.hw,e.canvas.hh])),a=Q5.device.createBindGroup({layout:l,entries:[{binding:0,resource:{buffer:c}}]})},e._resizeCanvas=(t,r)=>{e._setCanvasSize(t,r)},e.resetMatrix=()=>{e._matrix=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],e._transformIndex=0},e.resetMatrix(),e._matrixDirty=!1,e.transformStates=[e._matrix.slice()],e._transformIndexStack=[],e.push=()=>{e._transformIndexStack.push(e._transformIndex)},e.pop=()=>{if(e._transformIndexStack.length>0){let t=e._transformIndexStack.pop();e._matrix=e.transformStates[t].slice(),e._transformIndex=t}else console.warn("Matrix index stack is empty!")},e.translate=(t,r,o)=>{(t||r||o)&&(e._matrix[3]+=t,e._matrix[7]+=r,e._matrix[11]+=o||0,e._matrixDirty=!0)},e.rotate=t=>{if(!t)return;"degrees"==e._angleMode&&(t=e.radians(t));let r=Math.cos(t),o=Math.sin(t),a=e._matrix[0],n=e._matrix[1],i=e._matrix[4],s=e._matrix[5];a||n||i||s?(e._matrix[0]=a*r+i*o,e._matrix[1]=n*r+s*o,e._matrix[4]=a*-o+i*r,e._matrix[5]=n*-o+s*r):(e._matrix[0]=r,e._matrix[1]=o,e._matrix[4]=-o,e._matrix[5]=r),e._matrixDirty=!0},e.scale=(t=1,r,o=1)=>{r??=t,e._matrix[0]*=t,e._matrix[5]*=r,e._matrix[10]*=o,e._matrixDirty=!0},e._saveMatrix=()=>{e.transformStates.push(e._matrix.slice()),e._transformIndex=e.transformStates.length-1,e._matrixDirty=!1},e._beginRender=()=>{e.encoder=Q5.device.createCommandEncoder(),r=t.pass=e.encoder.beginRenderPass({colorAttachments:[{view:ctx.getCurrentTexture().createView(),loadOp:"clear",storeOp:"store"}]})},e._render=()=>{if(r.setBindGroup(0,a),transformStates.length>1||!n){const t=Q5.device.createBuffer({size:64*transformStates.length,usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST});Q5.device.queue.writeBuffer(t,0,new Float32Array(transformStates.flat())),n=Q5.device.createBindGroup({layout:e.bindGroupLayouts[1],entries:[{binding:0,resource:{buffer:t}}]})}r.setBindGroup(1,n);for(let t of e._hooks.preRender)t();let t=e.drawStack,o=0,i=-1;for(let a=0;a<t.length;a+=2){i!=t[a]&&(i=t[a],r.setPipeline(e.pipelines[i]));let n=t[a+1];r.draw(n,1,o,0),o+=n}},e._finishRender=()=>{r.end();const o=e.encoder.finish();Q5.device.queue.submit([o]),t.pass=e.encoder=null,e.verticesStack.length=0,e.drawStack.length=0,e.colorsStack.length=4,e.pipelinesStack.length=0,e._colorIndex=0,rotation=0,e.resetMatrix(),e._matrixDirty=!1,e.transformStates.length=1,e._transformIndexStack.length=0},e.fill=function(){s(...arguments),e._doFill=!0,e._fillIndex=e._colorIndex},e.stroke=function(){s(...arguments),e._doStroke=!0,e._fillIndex=e._colorIndex},e.noFill=()=>e._doFill=!1,e.noStroke=()=>e._doStroke=!1,e._strokeWeight=1,e.strokeWeight=t=>e._strokeWeight=t,e.clear=()=>{}},Q5.webgpu=async function(e,t){if(e&&"global"!=e||(Q5._hasGlobal=!0),!navigator.gpu){console.warn("q5 WebGPU not supported on this browser!");let r=new Q5(e,t);return r.colorMode("rgb",1),r._beginRender=()=>r.translate(r.canvas.hw,r.canvas.hh),r}let r=await navigator.gpu.requestAdapter();if(!r)throw new Error("No appropriate GPUAdapter found.");return Q5.device=await r.requestDevice(),new Q5(e,t,"webgpu")},Q5.renderers.webgpu.drawing=(e,t)=>{let r,o,a;e.CLOSE=1,e._hooks.postCanvas.push((()=>{let t=Q5.device.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,buffer:{type:"read-only-storage",hasDynamicOffset:!1}}]});e.bindGroupLayouts.push(t),r=e.verticesStack,o=e.drawStack,a=e.colorsStack;let n={arrayStride:16,attributes:[{format:"float32x2",offset:0,shaderLocation:0},{format:"float32",offset:8,shaderLocation:1},{format:"float32",offset:12,shaderLocation:2}]},i=Q5.device.createShaderModule({code:"\nstruct VertexOutput {\n\t@builtin(position) position: vec4<f32>,\n\t@location(1) colorIndex: f32\n};\n\nstruct Uniforms {\n\thalfWidth: f32,\n\thalfHeight: f32\n};\n\n@group(0) @binding(0) var<uniform> uniforms: Uniforms;\n@group(1) @binding(0) var<storage, read> transforms: array<mat4x4<f32>>;\n\n@vertex\nfn vertexMain(@location(0) pos: vec2<f32>, @location(1) colorIndex: f32, @location(2) transformIndex: f32) -> VertexOutput {\n\tvar vert = vec4<f32>(pos, 0.0, 1.0);\n\tvert *= transforms[i32(transformIndex)];\n\tvert.x /= uniforms.halfWidth;\n\tvert.y /= uniforms.halfHeight;\n\n\tvar output: VertexOutput;\n\toutput.position = vert;\n\toutput.colorIndex = colorIndex;\n\treturn output;\n}\n"}),s=Q5.device.createShaderModule({code:"\n@group(2) @binding(0) var<storage, read> uColors : array<vec4<f32>>;\n\n@fragment\nfn fragmentMain(@location(1) colorIndex: f32) -> @location(0) vec4<f32> {\n\tlet index = u32(colorIndex);\n\treturn mix(uColors[index], uColors[index + 1u], fract(colorIndex));\n}\n"}),l=Q5.device.createPipelineLayout({bindGroupLayouts:e.bindGroupLayouts});e._createPipeline=e=>Q5.device.createRenderPipeline({layout:l,vertex:{module:i,entryPoint:"vertexMain",buffers:[n]},fragment:{module:s,entryPoint:"fragmentMain",targets:[{format:"bgra8unorm",blend:e}]},primitive:{topology:"triangle-list"}}),e.pipelines[0]=e._createPipeline(blendConfigs.normal)}));let n=["zero","one","src-alpha","one-minus-src-alpha","dst","dst-alpha","one-minus-dst-alpha","one-minus-src"],i=["add","subtract","reverse-subtract","min","max"];let s;e.blendConfigs={},Object.entries({normal:[2,3,0,2,3,0],lighter:[2,1,0,2,1,0],subtract:[2,1,2,2,1,2],multiply:[4,0,0,5,0,0],screen:[1,3,0,1,3,0],darken:[1,3,3,1,3,3],lighten:[1,3,4,1,3,4],overlay:[2,3,0,2,3,0],hard_light:[2,3,0,2,3,0],soft_light:[2,3,0,2,3,0],difference:[2,3,2,2,3,2],exclusion:[2,3,0,2,3,0],color_dodge:[1,7,0,1,7,0],color_burn:[6,1,0,6,1,0],linear_dodge:[2,1,0,2,1,0],linear_burn:[2,7,1,2,7,1],vivid_light:[2,7,0,2,7,0],pin_light:[2,7,0,2,7,0],hard_mix:[2,7,0,2,7,0]}).forEach((([t,r])=>{e.blendConfigs[t]={color:{srcFactor:n[r[0]],dstFactor:n[r[1]],operation:i[r[2]]},alpha:{srcFactor:n[r[3]],dstFactor:n[r[4]],operation:i[r[5]]}}})),e._blendMode="normal",e.blendMode=t=>{t!=e._blendMode&&("source-over"==t&&(t="normal"),t=t.toLowerCase().replace(/[ -]/g,"_"),e._blendMode=t,e.pipelines[0]=e._createPipeline(e.blendConfigs[t]))},e.beginShape=()=>{s=[]},e.vertex=(t,r)=>{e._matrixDirty&&e._saveMatrix(),s.push(t,-r,e._colorIndex,e._transformIndex)},e.endShape=e=>{let t=s;if(t.length<12)throw new Error("A shape must have at least 3 vertices.");e&&t.push(t[0],t[1],t[2],t[3]);let a=[];for(let e=4;e<t.length;e+=4)a.push(t[0],t[1],t[2],t[3],t[e-4],t[e-3],t[e-2],t[e-1],t[e],t[e+1],t[e+2],t[e+3]);r.push(...a),o.push(0,a.length/4),s=[]},e.triangle=(t,r,o,a,n,i)=>{e.beginShape(),e.vertex(t,r),e.vertex(o,a),e.vertex(n,i),e.endShape(1)},e.rect=(t,a,n,i)=>{let s=n/2,l=i/2,d=t-s,c=t+s,h=-(a-l),u=-(a+l),p=e._colorIndex;e._matrixDirty&&e._saveMatrix();let _=e._transformIndex;r.push(d,h,p,_,c,h,p,_,d,u,p,_,c,h,p,_,d,u,p,_,c,u,p,_),o.push(0,6)},e.point=(t,r)=>{let o=e._strokeWeight;1==o?e.rect(t,r,1,1):e.ellipse(t,r,o,o)},e.background=()=>{};e.ellipse=(t,a,n,i)=>{const s=(l=n==i?n:Math.max(n,i))<14?8:l<16?10:l<18?12:l<20?14:l<22?16:l<24?18:l<28?20:l<34?22:l<42?24:l<48?26:l<56?28:l<64?30:l<72?32:l<84?34:l<96?36:l<98?38:l<113?40:l<149?44:l<199?48:l<261?52:l<353?56:l<461?60:l<585?64:l<1200?70:l<1800?80:l<2400?90:100;var l;let d=Math.max(n,1)/2,c=n==i?d:Math.max(i,1)/2,h=0;const u=e.TAU/s,p=e._colorIndex;e._matrixDirty&&e._saveMatrix();const _=e._transformIndex;let g,x,f,m;for(let e=0;e<=s;e++)g=f,x=m,f=t+d*Math.cos(h),m=a+c*Math.sin(h),h+=u,0!=e&&r.push(t,a,p,_,g,x,p,_,f,m,p,_);o.push(0,3*s)},e.circle=(t,r,o)=>e.ellipse(t,r,o,o),e._hooks.preRender.push((()=>{const t=Q5.device.createBuffer({size:6*r.length,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST});Q5.device.queue.writeBuffer(t,0,new Float32Array(r)),e.pass.setVertexBuffer(0,t);const o=Q5.device.createBuffer({size:4*a.length,usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST});Q5.device.queue.writeBuffer(o,0,new Float32Array(a));const n=Q5.device.createBindGroup({layout:e.bindGroupLayouts[2],entries:[{binding:0,resource:{buffer:o,offset:0,size:4*a.length}}]});e.pass.setBindGroup(2,n)}))},Q5.renderers.webgpu.image=(e,t)=>{e.imageStack=[],e.textures=[],e._hooks.postCanvas.push((()=>{let t=Q5.device.createShaderModule({code:"\nstruct VertexOutput {\n @builtin(position) position: vec4<f32>,\n @location(0) texCoord: vec2<f32>,\n @location(1) textureIndex: f32\n};\n\nstruct Uniforms {\n halfWidth: f32,\n halfHeight: f32\n};\n\n@group(0) @binding(0) var<uniform> uniforms: Uniforms;\n@group(1) @binding(0) var<storage, read> transforms: array<mat4x4<f32>>;\n\n@vertex\nfn vertexMain(@location(0) pos: vec2<f32>, @location(1) texCoord: vec2<f32>, @location(2) transformIndex: f32, @location(3) textureIndex: f32) -> VertexOutput {\n var vert = vec4<f32>(pos, 0.0, 1.0);\n vert *= transforms[i32(transformIndex)];\n vert.x /= uniforms.halfWidth;\n vert.y /= uniforms.halfHeight;\n\n var output: VertexOutput;\n output.position = vert;\n output.texCoord = texCoord;\n output.textureIndex = textureIndex;\n return output;\n}\n"}),r=Q5.device.createShaderModule({code:"\n@group(0) @binding(0) var samp: sampler;\n@group(0) @binding(1) var textures: array<texture_2d<f32>>;\n\n@fragment\nfn fragmentMain(@location(0) texCoord: vec2<f32>, @location(1) textureIndex: f32) -> @location(0) vec4<f32> {\n return textureSample(textures[i32(textureIndex)], samp, texCoord);\n}\n"});const o=[Q5.device.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX,buffer:{type:"uniform"}},{binding:1,visibility:GPUShaderStage.FRAGMENT,sampler:{}},{binding:2,visibility:GPUShaderStage.FRAGMENT,texture:{viewDimension:"2d",sampleType:"float"}}]}),Q5.device.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX,buffer:{type:"read-only-storage"}}]})],a=Q5.device.createPipelineLayout({bindGroupLayouts:o});e.pipelines[1]=Q5.device.createRenderPipeline({layout:a,vertex:{module:t,entryPoint:"vertexMain",buffers:[{arrayStride:20,attributes:[{shaderLocation:0,offset:0,format:"float32x2"},{shaderLocation:1,offset:8,format:"float32x2"},{shaderLocation:2,offset:16,format:"float32"}]}]},fragment:{module:r,entryPoint:"fragmentMain",targets:[{format:"bgra8unorm"}]},primitive:{topology:"triangle-list"}}),e.sampler=Q5.device.createSampler({magFilter:"linear",minFilter:"linear"})})),e.loadImage=async t=>{const r=new Image;return r.onload=async()=>{const t=await createImageBitmap(r),o=Q5.device.createTexture({size:[r.width,r.height,1],format:"bgra8unorm",usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.RENDER_ATTACHMENT});Q5.device.queue.copyExternalImageToTexture({source:t},{texture:o},[r.width,r.height,1]),r.texture=o,r.index=e.textures.length,e.textures.push(o)},r.src=t,r},e._hooks.preRender.push((()=>{if(!e.imageStack.length)return;e.pass.setPipeline(e.pipelines[1]);const t=new Float32Array(e.vertexStack),r=Q5.device.createBuffer({size:t.byteLength,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST});if(Q5.device.queue.writeBuffer(r,0,t),e.pass.setVertexBuffer(0,r),e.textures.length!==previousTextureCount){previousTextureCount=e.textures.length;const t=e.textures.map((e=>e.createView()));e.textureBindGroup=Q5.device.createBindGroup({layout:e.pipelines[1].getBindGroupLayout(0),entries:[{binding:0,resource:e.sampler},...t.map(((e,t)=>({binding:t+1,resource:e})))]})}e.pass.setBindGroup(0,e.textureBindGroup)})),e.image=(t,r,o,a,n)=>{e._matrixDirty&&e._saveMatrix();let i=e._transformIndex;e.imageStack.push(t.index);let s=a/2,l=n/2,d=r-s,c=r+s,h=-(o-l),u=-(o+l),p=t.index;e.vertexStack.push(d,h,0,0,i,p,c,h,1,0,i,p,d,u,0,1,i,p,c,h,1,0,i,p,d,u,0,1,i,p,c,u,1,1,i,p),e.drawStack.push(6)}},Q5.renderers.webgpu.text=(e,t)=>{};
package/src/q5-ai.js CHANGED
@@ -5,8 +5,7 @@ Q5.modules.ai = ($) => {
5
5
 
6
6
  $._aiErrorAssistance = async (e) => {
7
7
  let askAI = e.message?.includes('Ask AI ✨');
8
- if (!askAI) console.error(e);
9
- if (Q5.disableFriendlyErrors) return;
8
+ if (Q5.disableFriendlyErrors && !askAI) return;
10
9
  if (askAI || !Q5.errorTolerant) $.noLoop();
11
10
  let stackLines = e.stack?.split('\n');
12
11
  if (!e.stack || stackLines.length <= 1) return;
@@ -17,7 +16,7 @@ Q5.modules.ai = ($) => {
17
16
  idx = 0;
18
17
  sep = '@';
19
18
  }
20
- while (stackLines[idx].indexOf('q5.js:') >= 0) idx++;
19
+ while (stackLines[idx].indexOf('q5') >= 0) idx++;
21
20
 
22
21
  let parts = stackLines[idx].split(sep).at(-1);
23
22
  parts = parts.split(':');
@@ -55,11 +54,11 @@ Q5.modules.ai = ($) => {
55
54
  '%0A%0AExcerpt+for+context%3A%0A%0A' +
56
55
  encodeURIComponent(context);
57
56
 
58
- if (!askAI) console.log('Error in ' + fileBase + ' on line ' + lineNum + ':\n\n' + errLine);
57
+ console.warn('Error in ' + fileBase + ' on line ' + lineNum + ':\n\n' + errLine);
59
58
 
60
59
  console.warn('Ask AI ✨ ' + url);
61
60
 
62
- if (askAI) window.open(url, '_blank');
61
+ if (askAI) return window.open(url, '_blank');
63
62
  } catch (err) {}
64
63
  };
65
64
  };
package/src/q5-core.js CHANGED
@@ -219,7 +219,7 @@ function Q5(scope, parent, renderer) {
219
219
  return t[k]();
220
220
  } catch (e) {
221
221
  if ($._aiErrorAssistance) $._aiErrorAssistance(e);
222
- else console.error(e);
222
+ throw e;
223
223
  }
224
224
  };
225
225
  }