@fabiplay/engine 0.0.0-stage → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +78 -0
- package/README.md +113 -2
- package/dist/fabi-play-engine.d.ts +2423 -0
- package/dist/fabi-play-engine.js +1 -0
- package/dist/fabi-play-engine.lite.d.ts +2423 -0
- package/dist/fabi-play-engine.lite.js +1 -0
- package/dist/fabi-play-engine.lite.umd.js +6969 -0
- package/dist/fabi-play-engine.lite.umd.min.js +1 -0
- package/dist/fabi-play-engine.umd.js +9340 -0
- package/dist/fabi-play-engine.umd.min.js +1 -0
- package/dist/index.d.ts +2406 -0
- package/dist/index.development.js +6850 -0
- package/dist/index.js +105 -0
- package/dist/integrity.json +15 -0
- package/package.json +80 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! @fabiplay/engine 0.9.1 (full) | Fabi Play Kit License | https://docs.fabiplay.app */(function(Zn,Re){var Ss=typeof document!="undefined"?document.currentScript:null;typeof define=="function"&&define.amd?define([],function(){return Re(Ss)}):typeof module=="object"&&module&&module.exports?module.exports=Re(Ss):Zn.FabiEngine=Re(Ss)})(typeof globalThis!="undefined"?globalThis:typeof self!="undefined"?self:this,function(Zn){"use strict";var Re={exports:{}},Ss=Re.exports,Ts=Object.defineProperty,Wa=Object.defineProperties,ja=Object.getOwnPropertyDescriptor,Ya=Object.getOwnPropertyDescriptors,Qa=Object.getOwnPropertyNames,Cs=Object.getOwnPropertySymbols,ln=Object.prototype.hasOwnProperty,Jn=Object.prototype.propertyIsEnumerable,qe=Math.pow,cn=(t,e,s)=>e in t?Ts(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s,A=(t,e)=>{for(var s in e||(e={}))ln.call(e,s)&&cn(t,s,e[s]);if(Cs)for(var s of Cs(e))Jn.call(e,s)&&cn(t,s,e[s]);return t},We=(t,e)=>Wa(t,Ya(e)),hn=(t,e)=>{var s={};for(var n in t)ln.call(t,n)&&e.indexOf(n)<0&&(s[n]=t[n]);if(t!=null&&Cs)for(var n of Cs(t))e.indexOf(n)<0&&Jn.call(t,n)&&(s[n]=t[n]);return s},Va=(t,e)=>{for(var s in e)Ts(t,s,{get:e[s],enumerable:!0})},Ka=(t,e,s,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Qa(e))!ln.call(t,i)&&i!==s&&Ts(t,i,{get:()=>e[i],enumerable:!(n=ja(e,i))||n.enumerable});return t},Za=t=>Ka(Ts({},"__esModule",{value:!0}),t),p=(t,e,s)=>cn(t,typeof e!="symbol"?e+"":e,s),je=(t,e,s)=>new Promise((n,i)=>{var a=h=>{try{r(s.next(h))}catch(l){i(l)}},o=h=>{try{r(s.throw(h))}catch(l){i(l)}},r=h=>h.done?n(h.value):Promise.resolve(h.value).then(a,o);r((s=s.apply(t,e)).next())}),$n={};Va($n,{AnimatedSprite:()=>Oe,Atlas:()=>Tn,AvatarPainter:()=>Xn,AvatarsNode:()=>Sa,BitmapFont:()=>qn,DEFAULT_FONT:()=>ca,EASE:()=>fs,Group:()=>An,HALO:()=>bs,MAX_LAYERS:()=>_n,NameTags:()=>Hn,Node:()=>Ne,NodePool:()=>Oa,Particles:()=>Bi,STAGE_HEIGHT:()=>Ft,Shape:()=>ys,ShelfPacker:()=>Ui,Sound:()=>ba,Sprite:()=>Ke,TIERS:()=>fe,Text:()=>vs,Timeline:()=>Ea,Tweens:()=>Aa,avatarPortrait:()=>sl,blur:()=>oc,brightness:()=>$l,colorMatrix:()=>rc,contrast:()=>tc,createAvatarRenderer:()=>el,createEngine:()=>Ml,createRenderer:()=>Bn,dropShadow:()=>lc,grayscale:()=>sc,handsOf:()=>ya,hits:()=>Wn,hueRotate:()=>ic,invert:()=>ac,nodePool:()=>yc,packColor:()=>Ve,parseBMFont:()=>Vs,parseColor:()=>ne,pickTier:()=>ga,playerColor:()=>Ks,rendererOrder:()=>la,rng:()=>ho,saturate:()=>ec,sepia:()=>nc,shader:()=>cc,shapeBounds:()=>Gn,tier:()=>ze,tint:()=>Jl,touching:()=>ma,wrists:()=>pa}),Re.exports=Za($n);var le=typeof self!="undefined"?self:typeof window!="undefined"?window:typeof global!="undefined"?global:{},ti=33,J={nose:0,leftShoulder:11,rightShoulder:12,leftElbow:13,rightElbow:14,leftWrist:15,rightWrist:16,leftHip:23,rightHip:24,leftKnee:25,rightKnee:26,leftAnkle:27,rightAnkle:28},Ja=["3-5","6-8","9-12"],$a=t=>Ja.includes(t),tr=4,Rs=["#EE6A43","#6FA0E0","#8CC9A0","#C49BE0"],ei={"3-5":["bunny","bear","panda","penguin"],"6-8":["fox","lion","dragon","unicorn"],"9-12":["robot","astronaut","ninja","skater"]},er=ei["6-8"],si=(t,e)=>{const s=$a(e)?ei[e]:er;return s[Number.isInteger(t)&&t>=0?t%s.length:0]},ni=(t,e)=>t?{x:t.x+e.x*t.w,y:t.y+e.y*t.h}:{x:e.x,y:e.y},sr=.5,Fs={left:1.6,top:1.6,w:3.2,h:3},nr=1.2;function ir(t,e,s={}){const n=Array.isArray(t)?t:t.body;if(!Array.isArray(n))return null;const i=e==="left"?J.leftWrist:J.rightWrist,a=x=>{var g;return as(n[x*3])&&as(n[x*3+1])&&((g=n[x*3+2])!=null?g:0)>=sr?x:-1};if(a(i)<0)return null;const o=n[i*3],r=n[i*3+1];if(s.orientation!=="portrait")return ni(s.view,{x:o,y:r});if(a(J.leftShoulder)<0||a(J.rightShoulder)<0)return null;const h=J.leftShoulder*3,l=J.rightShoulder*3,c=(n[h]+n[l])/2,f=(n[h+1]+n[l+1])/2,u=J.leftHip*3,y=J.rightHip*3,d=(n[u]+n[y])/2,b=(n[u+1]+n[y+1])/2;let m=as(d)&&as(b)?Math.hypot(d-c,b-f):0;return(a(J.leftHip)<0||a(J.rightHip)<0)&&(m=Math.max(m,nr*Math.hypot(n[h]-n[l],n[h+1]-n[l+1]))),m=Math.max(m,.01),{x:ai((o-c+Fs.left*m)/(Fs.w*m)),y:ai((r-f+Fs.top*m)/(Fs.h*m))}}var ar=300,ii=class{constructor(t=ar){p(this,"holdMs",t),p(this,"last",new Map)}static key(t,e){return t*2+(e==="right"?1:0)}at(t,e,s){const n=this.last.get(t);return e?(n?(n.x=e.x,n.y=e.y,n.t=s):this.last.set(t,{x:e.x,y:e.y,t:s}),e):n?s-n.t<=this.holdMs?{x:n.x,y:n.y}:(this.last.delete(t),null):null}clear(){this.last.clear()}},rr=.25,or=Object.freeze({top:0,bottom:0,left:0,right:0});function lr(t){if(!cr(t))return;const e=s=>as(s)?Math.min(Math.max(s,0),rr):0;return{top:e(t.top),bottom:e(t.bottom),left:e(t.left),right:e(t.right)}}var kc=16/9,cr=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),as=t=>typeof t=="number"&&Number.isFinite(t),ai=t=>Math.min(Math.max(t,0),1),hr=12,fr=ti*4,ur=t=>hr+t*fr,wc=ur(tr),dr=t=>t.startsWith("fabi-play.")?"fablee-play.".concat(t.slice(10)):null;function pr(t,e,s=dr(e)){if(!(!t||!s))try{const n=t.getItem(s);if(n===null)return;t.getItem(e)===null&&t.setItem(e,n),t.removeItem(s)}catch(n){}}var Ut="#4a382c",Ct="#2b2118",Qt="#1c1f2b",ri="#fbefe3",Jt="#f4897a",rs="#3a2a22",oi=[{id:"fox",name:{en:"Fox",it:"Volpe"},band:"6-8",palette:{body:"#ee6a43",limbs:"#ee6a43",belly:ri,accent:"#ffd9c2",outline:Ct,hands:"#5a3426",feet:"#5a3426"},head:"wide",ears:"pointy",face:{eyes:"dot",mouth:"cat",nose:rs,muzzle:"cheeks"},tail:"fluffy",headExtras:[],bodyExtras:[]},{id:"mascot",name:{en:"Fabi",it:"Fabi"},band:"all",special:!0,palette:{body:"#ee6a43",limbs:"#ee6a43",belly:ri,accent:"#5a3426",outline:Ct,hands:"#5a3426",feet:"#5a3426"},head:"wide",ears:"pointy",face:{eyes:"bead",mouth:"open",nose:rs,muzzle:"band",cheeks:Jt},tail:"brush",headExtras:[],bodyExtras:["star"],extraColors:["#ffd84a"]},{id:"bunny",name:{en:"Bunny",it:"Coniglietto"},band:"3-5",palette:{body:"#f9d0de",limbs:"#f9d0de",belly:"#fff6f8",accent:"#f4a0b9",outline:Ut},head:"round",ears:"long",face:{eyes:"dot",mouth:"cat",nose:"#e0607e",muzzle:"none",cheeks:Jt},tail:"pom",headExtras:[],bodyExtras:[]},{id:"bear",name:{en:"Bear",it:"Orsetto"},band:"3-5",palette:{body:"#cf9f78",limbs:"#cf9f78",belly:"#f7e0bf",accent:"#f7e0bf",outline:Ut},head:"round",ears:"round",face:{eyes:"dot",mouth:"smile",nose:rs,muzzle:"oval",cheeks:Jt},tail:"none",headExtras:[],bodyExtras:[]},{id:"cat",name:{en:"Cat",it:"Gattino"},band:"3-5",palette:{body:"#c8b6ee",limbs:"#c8b6ee",belly:"#f4eeff",accent:"#f7b3c8",outline:Ut,hands:"#f4eeff",feet:"#f4eeff"},head:"wide",ears:"pointy",face:{eyes:"big",eyeColor:"#3f9a5a",mouth:"cat",nose:"#f07a9a",muzzle:"none",cheeks:Jt},tail:"long",headExtras:["whiskers"],bodyExtras:[]},{id:"panda",name:{en:"Panda",it:"Panda"},band:"3-5",palette:{body:"#ffffff",limbs:"#6e6674",belly:"#ffffff",accent:"#6e6674",outline:Ut,ears:"#6e6674"},head:"wide",ears:"round",face:{eyes:"mask",mouth:"smile",nose:"#2f2a2c",muzzle:"none",cheeks:"#f6a3a3"},tail:"none",headExtras:[],bodyExtras:[]},{id:"penguin",name:{en:"Penguin",it:"Pinguino"},band:"3-5",palette:{body:"#6c8fca",limbs:"#6c8fca",belly:"#ffffff",accent:"#f9b95c",outline:Ut,feet:"#f9b95c"},head:"tall",ears:"none",face:{eyes:"dot",mouth:"beak",muzzle:"heart",cheeks:"#f6a3a3"},tail:"none",headExtras:[],bodyExtras:["flippers","scarf"],extraColors:["#f6907a"]},{id:"frog",name:{en:"Frog",it:"Ranocchio"},band:"3-5",palette:{body:"#8fd487",limbs:"#8fd487",belly:"#e6f7cc",accent:"#62ad62",outline:Ut},head:"wide",ears:"none",face:{eyes:"big",eyesOnTop:!0,mouth:"open",muzzle:"none",cheeks:"#f59b8f"},tail:"none",headExtras:[],bodyExtras:["flippers","spots"],extraColors:["#62ad62","#b0e6a4"]},{id:"lion",name:{en:"Lion",it:"Leoncino"},band:"6-8",alsoIn:["3-5"],palette:{body:"#f6c454",limbs:"#f6c454",belly:"#fde7b0",accent:"#fde7b0",outline:Ct},head:"round",ears:"round",face:{eyes:"dot",mouth:"cat",nose:"#8a4b2a",muzzle:"oval",cheeks:Jt},tail:"tuft",headExtras:["mane"],bodyExtras:[],extraColors:["#c8692e"]},{id:"unicorn",name:{en:"Unicorn",it:"Unicorno"},band:"6-8",palette:{body:"#fbf5ff",limbs:"#fbf5ff",belly:"#efe0ff",accent:"#fbd46a",outline:Ct,hands:"#c9a6f2",feet:"#c9a6f2"},head:"tall",ears:"unicorn",face:{eyes:"dot",mouth:"smile",muzzle:"none",cheeks:"#f7a6c8"},tail:"none",headExtras:["rainbow-mane"],bodyExtras:[],extraColors:["#f58cc0","#8fd3f4","#a98ff2"]},{id:"dragon",name:{en:"Little Dragon",it:"Draghetto"},band:"6-8",palette:{body:"#8a63d2",limbs:"#8a63d2",belly:"#fbd46a",accent:"#5fd0b5",outline:Ct},head:"wide",ears:"horns",face:{eyes:"big",eyeColor:"#3a2a6a",mouth:"teeth",muzzle:"none",cheeks:"#f59bc0"},tail:"arrow",headExtras:[],bodyExtras:["wings"]},{id:"robot",name:{en:"Robot",it:"Robot"},band:"9-12",palette:{body:"#b9c7d2",limbs:"#8b9aa6",belly:"#b9c7d2",accent:"#ee6a43",outline:Qt,hands:"#ee6a43",feet:"#6b7a86"},head:"square",ears:"antenna",face:{eyes:"screen",eyeColor:"#7ff0ff",mouth:"grill",muzzle:"none"},tail:"none",headExtras:["bolts"],bodyExtras:["panel","joints","boots"],extraColors:["#ff7a6b","#fbd46a","#7ff0ff"]},{id:"astronaut",name:{en:"Astronaut",it:"Astronauta"},band:"9-12",palette:{body:"#f4f1ec",limbs:"#f4f1ec",belly:"#f4f1ec",accent:"#ee6a43",outline:Qt,hands:"#9fb0bd",feet:"#9fb0bd"},head:"round",ears:"none",face:{eyes:"visor",mouth:"smile",muzzle:"none"},tail:"none",headExtras:["helmet"],bodyExtras:["backpack","badge","boots"],extraColors:["#c9d3db"]},{id:"dinosaur",name:{en:"Dinosaur",it:"Dinosauro"},band:"6-8",palette:{body:"#3fb3a6",limbs:"#3fb3a6",belly:"#c9f0d6",accent:"#f79a3e",outline:Ct},head:"wide",ears:"none",face:{eyes:"dot",mouth:"teeth",muzzle:"none",cheeks:"#f59b8f"},tail:"spiky",headExtras:["spikes","spots"],bodyExtras:[],extraColors:["#2b8f84","#7fd3c6"]},{id:"monkey",name:{en:"Monkey",it:"Scimmietta"},band:"6-8",palette:{body:"#7b5234",limbs:"#7b5234",belly:"#f2c9a0",accent:"#f2c9a0",outline:Ct,hands:"#f2c9a0",feet:"#f2c9a0"},head:"round",ears:"side",face:{eyes:"dot",mouth:"open",nose:"#5a3a26",muzzle:"monkey",cheeks:Jt},tail:"curl",headExtras:["tuft"],bodyExtras:[]},{id:"koala",name:{en:"Koala",it:"Koala"},band:"3-5",palette:{body:"#b7bcc6",limbs:"#b7bcc6",belly:"#eef0f3",accent:"#f4dbe2",outline:Ut},head:"wide",ears:"big-round",face:{eyes:"dot",mouth:"smile",nose:"#3b3438",muzzle:"none",cheeks:"#f4a3b0"},tail:"none",headExtras:[],bodyExtras:[]},{id:"tiger",name:{en:"Tiger",it:"Tigrotto"},band:"6-8",palette:{body:"#f9a33a",limbs:"#f9a33a",belly:"#fff1dc",accent:"#fff1dc",outline:Ct},head:"wide",ears:"round",face:{eyes:"dot",mouth:"cat",nose:"#e2607a",muzzle:"oval",cheeks:Jt},tail:"striped",headExtras:["stripes","whiskers"],bodyExtras:[],extraColors:["#3a2a22"]},{id:"owl",name:{en:"Owl",it:"Gufetto"},band:"3-5",palette:{body:"#8ec0e6",limbs:"#8ec0e6",belly:"#e3f2fc",accent:"#639cc9",outline:Ut,feet:"#f9b95c",hands:"#639cc9"},head:"tall",ears:"tufts",face:{eyes:"big",eyeColor:Ut,eyeRing:"#fde08a",mouth:"beak",muzzle:"none",cheeks:"#f6a8b4"},tail:"none",headExtras:[],bodyExtras:["feathers"]},{id:"alien",name:{en:"Alien",it:"Alieno"},band:"9-12",palette:{body:"#9ee05a",limbs:"#9ee05a",belly:"#d8f5a8",accent:"#b07cf2",outline:Qt},head:"bulb",ears:"antennae",face:{eyes:"almond",eyeColor:"#1e1838",mouth:"smirk",muzzle:"none"},tail:"none",headExtras:[],bodyExtras:["spots"],extraColors:["#7cc23e","#7cc23e"]},{id:"ghost",name:{en:"Friendly Ghost",it:"Fantasmino"},band:"6-8",palette:{body:"#e6f4ff",limbs:"#e6f4ff",belly:"#e6f4ff",accent:"#bcd9f2",outline:Ct},head:"round",ears:"none",face:{eyes:"dot",mouth:"open",muzzle:"none",cheeks:"#f7a6c8"},tail:"none",headExtras:["curl"],bodyExtras:["sheet"]},{id:"octopus",name:{en:"Octopus",it:"Polpetto"},band:"6-8",palette:{body:"#e0578a",limbs:"#e0578a",belly:"#f7b3cc",accent:"#f7b3cc",outline:Ct,hands:"#f7b3cc",feet:"#f7b3cc"},head:"tall",ears:"none",face:{eyes:"big",eyeColor:"#3a2140",mouth:"smile",muzzle:"none",cheeks:"#ffd0a0"},tail:"none",headExtras:["spots"],bodyExtras:["tentacles"],extraColors:["#f7b3cc","#f7b3cc"]},{id:"chick",name:{en:"Chick",it:"Pulcino"},band:"3-5",palette:{body:"#ffd45e",limbs:"#ffd45e",belly:"#fff2c2",accent:"#ffa04a",outline:Ut,hands:"#ffc23d",feet:"#ffa04a"},head:"round",ears:"none",face:{eyes:"dot",mouth:"beak",muzzle:"none",cheeks:Jt},tail:"none",headExtras:["eggshell"],bodyExtras:[],extraColors:["#fffaf0"]},{id:"puppy",name:{en:"Puppy",it:"Cucciolo"},band:"3-5",palette:{body:"#f4e4cf",limbs:"#f4e4cf",belly:"#fffaf2",accent:"#f29aa4",outline:Ut,ears:"#b58262",hands:"#e6caa6",feet:"#e6caa6"},head:"wide",ears:"floppy",face:{eyes:"dot",mouth:"open",nose:rs,muzzle:"oval",cheeks:Jt},tail:"curl",headExtras:["eye-spot"],bodyExtras:[]},{id:"lamb",name:{en:"Lamb",it:"Agnellino"},band:"3-5",palette:{body:"#fdf8ee",limbs:"#e3d1c2",belly:"#fffdf8",accent:"#f6bcc2",outline:Ut,skin:"#f7dccb",hands:"#a58c7e",feet:"#a58c7e"},head:"round",ears:"droopy",face:{eyes:"dot",mouth:"smile",nose:"#e591a0",muzzle:"none",cheeks:Jt},tail:"pom",headExtras:["wool"],bodyExtras:["wool"]},{id:"duckling",name:{en:"Duckling",it:"Anatroccolo"},band:"3-5",palette:{body:"#fff1a6",limbs:"#fff1a6",belly:"#fffbe0",accent:"#ff9f43",outline:Ut,feet:"#ff9f43"},head:"tall",ears:"none",face:{eyes:"dot",mouth:"bill",muzzle:"none",cheeks:Jt},tail:"none",headExtras:["curl"],bodyExtras:["flippers","scarf"],extraColors:["#86cfe0"]},{id:"shark",name:{en:"Shark",it:"Squalo"},band:"6-8",palette:{body:"#6c95c4",limbs:"#6c95c4",belly:"#eef5fb",accent:"#4c76a8",outline:Ct,hands:"#eef5fb",feet:"#4c76a8"},head:"wide",ears:"fin",face:{eyes:"dot",mouth:"jaws",muzzle:"none",cheeks:"#f59bb0"},tail:"fish",headExtras:["gills"],bodyExtras:[]},{id:"wolf",name:{en:"Wolf",it:"Lupo"},band:"6-8",palette:{body:"#8f9bb3",limbs:"#8f9bb3",belly:"#eef1f6",accent:"#f3b8c4",outline:Ct,hands:"#5a647a",feet:"#5a647a"},head:"round",ears:"pointy",face:{eyes:"dot",mouth:"open",nose:rs,muzzle:"oval",cheeks:"#f4a3b0"},tail:"fluffy",headExtras:["ruff","forehead"],bodyExtras:[],extraColors:["#636d84"]},{id:"parrot",name:{en:"Parrot",it:"Pappagallo"},band:"6-8",palette:{body:"#e8503f",limbs:"#e8503f",belly:"#ffd25a",accent:"#f6e6c4",outline:Ct,hands:"#3a9bdc",feet:"#8a7a70"},head:"round",ears:"none",face:{eyes:"big",eyeColor:Ct,eyeRing:"#ffffff",mouth:"hook",muzzle:"none",cheeks:"#ffb0a0"},tail:"plume",headExtras:["crest"],bodyExtras:["feathers"],extraColors:["#ffd25a","#3fae5a","#3a9bdc"]},{id:"ninja",name:{en:"Ninja",it:"Ninja"},band:"9-12",palette:{body:"#2f3a56",limbs:"#2f3a56",belly:"#2f3a56",accent:"#36c9bb",outline:Qt,skin:"#b07a52",hands:"#222a40",feet:"#222a40"},head:"round",ears:"none",face:{eyes:"calm",mouth:"none",muzzle:"none",brows:"#2a1d16"},tail:"none",headExtras:["ninja-hood"],bodyExtras:["belt"],extraColors:["#36c9bb","#36c9bb","#36c9bb"]},{id:"skater",name:{en:"Skater",it:"Skater"},band:"9-12",palette:{body:"#3a8fc0",limbs:"#2c3e57",belly:"#2f7aa6",accent:"#ffcf3a",outline:Qt,skin:"#f2c9a5",hair:"#7a4a2a",hands:"#f2c9a5",feet:"#eef1f5"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smirk",muzzle:"none",brows:"#5a3520"},tail:"none",headExtras:["hair","cap"],bodyExtras:["pocket","joints"],extraColors:["#ff5d73"]},{id:"explorer",name:{en:"Explorer",it:"Giramondo"},band:"9-12",palette:{body:"#5f8f5b",limbs:"#5f8f5b",belly:"#5f8f5b",accent:"#d9bb7e",outline:Qt,skin:"#7a4a30",hair:"#1d1410",hands:"#7a4a30",feet:"#6b4a2a"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smile",muzzle:"none",brows:"#1d1410"},tail:"none",headExtras:["curls","safari-hat"],bodyExtras:["backpack","straps","boots"],extraColors:["#e07b39","#6b4a2a"]},{id:"wizard",name:{en:"Wizard",it:"Mago"},band:"9-12",palette:{body:"#5b3fa0",limbs:"#5b3fa0",belly:"#5b3fa0",accent:"#3d5fc8",outline:Qt,skin:"#c98d62",hair:"#a8452a",hands:"#c98d62",feet:"#33255e"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smile",muzzle:"none",brows:"#7a301c"},tail:"none",headExtras:["locks","wizard-hat"],bodyExtras:["robe","belt"],extraColors:["#ffd84a","#ffd84a","#ffd84a"]},{id:"knight",name:{en:"Knight",it:"Cavaliere"},band:"9-12",palette:{body:"#bcc7d3",limbs:"#8e9aa8",belly:"#dce3ea",accent:"#d8443a",outline:Qt,hands:"#6c7786",feet:"#6c7786"},head:"bucket",ears:"none",face:{eyes:"slit",eyeColor:"#bfefff",mouth:"none",muzzle:"none"},tail:"none",headExtras:["plume"],bodyExtras:["pauldrons","emblem","boots"],extraColors:["#d8443a"]},{id:"racer",name:{en:"Racer",it:"Pilota"},band:"9-12",palette:{body:"#ff6a2b",limbs:"#ff6a2b",belly:"#ffffff",accent:"#ffffff",outline:Qt,hands:"#232838",feet:"#232838"},head:"round",ears:"none",face:{eyes:"goggle",eyeColor:"#7fd6ff",mouth:"none",muzzle:"none"},tail:"none",headExtras:["stripe"],bodyExtras:["racing-stripe","boots"]},{id:"pirate",name:{en:"Pirate",it:"Pirata"},band:"9-12",palette:{body:"#f2efe6",limbs:"#2a3d6e",belly:"#f2efe6",accent:"#d94545",outline:Qt,skin:"#d9a072",hair:"#2b1a12",hands:"#d9a072",feet:"#3a2a20"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smirk",muzzle:"none",brows:"#2b1a12"},tail:"none",headExtras:["locks","bandana","eye-patch"],bodyExtras:["stripes","belt","boots"],extraColors:["#d94545","#2a3d6e","#4a3426"]},{id:"diver",name:{en:"Diver",it:"Sub"},band:"9-12",palette:{body:"#1f6582",limbs:"#1f6582",belly:"#1f6582",accent:"#ffb020",outline:Qt,skin:"#e8b48a",hair:"#c98f2e",hands:"#1b4f66",feet:"#ffb020"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smile",muzzle:"none",brows:"#8a5a1a"},tail:"none",headExtras:["curls","dive-mask"],bodyExtras:["tank","fins"],extraColors:["#c9d3db"]},{id:"hero",name:{en:"Hero",it:"Supereroe"},band:"9-12",palette:{body:"#3557c8",limbs:"#3557c8",belly:"#3557c8",accent:"#e0403a",outline:Qt,skin:"#5a3825",hair:"#141010",hands:"#e0403a",feet:"#e0403a"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smirk",muzzle:"none",brows:"#141010"},tail:"none",headExtras:["hair","domino"],bodyExtras:["cape","emblem","boots"],extraColors:["#ffd84a"]},{id:"trex",name:{en:"T-Rex",it:"T-Rex"},band:"6-8",alsoIn:["3-5"],palette:{body:"#6cb84e",limbs:"#6cb84e",belly:"#f4e8a8",accent:"#f4e8a8",outline:Ct},head:"snout-long",ears:"none",face:{eyes:"dot",mouth:"toothy",muzzle:"none",cheeks:"#f59b8f"},tail:"thick",headExtras:["stripes"],bodyExtras:["tiny-arms","strong-legs"],extraColors:["#4a9235","#58a23f"]},{id:"fairy",name:{en:"Fairy",it:"Fatina"},band:"6-8",alsoIn:["3-5"],palette:{body:"#b99af0",limbs:"#a8693f",belly:"#b99af0",accent:"#ffd84a",outline:Ct,skin:"#a8693f",hair:"#2e1d17",hands:"#a8693f",feet:"#f58cbc"},head:"round",ears:"pixie",face:{eyes:"dot",mouth:"smile",muzzle:"none",cheeks:"#f0857a"},tail:"none",headExtras:["bun","flower-crown"],bodyExtras:["wings-fairy","petals","wand"],extraColors:["#c4ecff","#f7a8cf","#fff3a0","#ffffff"]}],_t={M:0,L:1,Q:2,C:3,Z:4},li=[2,2,4,6,0];function fn(t,e){for(const s of e)yr(t,s)}function yr(t,e){var s,n,i,a,o;if(e.k==="group"){t.save(),t.translate(e.x,e.y),e.rot&&t.rotate(e.rot),e.s!==void 0&&e.s!==1&&t.scale(e.s,e.s),e.alpha!==void 0&&(t.globalAlpha*=e.alpha),fn(t,e.items),t.restore();return}switch(t.save(),e.alpha!==void 0&&(t.globalAlpha*=e.alpha),t.beginPath(),e.k){case"circle":t.arc(e.x,e.y,Math.max(e.r,0),0,Math.PI*2);break;case"ellipse":t.ellipse(e.x,e.y,Math.max(e.rx,0),Math.max(e.ry,0),(s=e.rot)!=null?s:0,0,Math.PI*2);break;case"rect":mr(t,e);break;case"path":typeof e.d=="string"?gr(t,e.d):xr(t,e.d);break;case"line":t.moveTo((n=e.pts[0])!=null?n:0,(i=e.pts[1])!=null?i:0);for(let r=2;r+1<e.pts.length;r+=2)t.lineTo(e.pts[r],e.pts[r+1]);break}t.lineCap="round",t.lineJoin="round",e.fill&&e.k!=="line"&&(t.fillStyle=e.fill,t.fill()),e.stroke&&((a=e.lw)!=null?a:1)>0&&(t.strokeStyle=e.stroke,t.lineWidth=(o=e.lw)!=null?o:1,t.stroke()),t.restore()}function mr(t,e){const s=Math.max(0,Math.min(e.r,e.w/2,e.h/2));t.translate(e.x,e.y),e.rot&&t.rotate(e.rot);const n=-e.w/2,i=-e.h/2;t.moveTo(n+s,i),t.lineTo(n+e.w-s,i),t.quadraticCurveTo(n+e.w,i,n+e.w,i+s),t.lineTo(n+e.w,i+e.h-s),t.quadraticCurveTo(n+e.w,i+e.h,n+e.w-s,i+e.h),t.lineTo(n+s,i+e.h),t.quadraticCurveTo(n,i+e.h,n,i+e.h-s),t.lineTo(n,i+s),t.quadraticCurveTo(n,i,n+s,i),t.closePath()}function xr(t,e){for(let s=0;s<e.length;){const n=e[s++];if(n===_t.M)t.moveTo(e[s],e[s+1]);else if(n===_t.L)t.lineTo(e[s],e[s+1]);else if(n===_t.Q)t.quadraticCurveTo(e[s],e[s+1],e[s+2],e[s+3]);else if(n===_t.C)t.bezierCurveTo(e[s],e[s+1],e[s+2],e[s+3],e[s+4],e[s+5]);else if(n===_t.Z)t.closePath();else return;s+=li[n]}}function br(t){var e;if(typeof t=="string")return((e=t.match(/-?\d*\.?\d+(?:e-?\d+)?/gi))!=null?e:[]).map(Number);const s=[];for(let n=0;n<t.length;){const i=li[t[n++]];if(i===void 0)break;for(let a=0;a<i;a++)s.push(t[n+a]);n+=i}return s}function gr(t,e){var s;const n=(s=e.match(/[MLQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi))!=null?s:[];let i="",a=0;const o=()=>Number(n[a++]);for(;a<n.length;){const r=n[a];if(/[MLQCZ]/i.test(r)&&(i=r.toUpperCase(),a++,i==="Z")){t.closePath();continue}i==="M"?(t.moveTo(o(),o()),i="L"):i==="L"?t.lineTo(o(),o()):i==="Q"?t.quadraticCurveTo(o(),o(),o(),o()):i==="C"?t.bezierCurveTo(o(),o(),o(),o(),o(),o()):a++}}var ut=t=>{const e=Math.round(t*100)/100;return e===0?0:e};function pt(t,e=.5){const s=t.length;if(s<3)return[];const n=(r,h,l)=>({x:r.x+(h.x-r.x)*l,y:r.y+(h.y-r.y)*l}),i=Math.min(Math.max(e,0),.5),a=n(t[0],t[1],i),o=[_t.M,ut(a.x),ut(a.y)];for(let r=1;r<=s;r++){const h=t[(r-1)%s],l=t[r%s],c=t[(r+1)%s],f=n(h,l,1-i),u=n(l,c,i);o.push(_t.L,ut(f.x),ut(f.y),_t.Q,ut(l.x),ut(l.y),ut(u.x),ut(u.y))}return o.push(_t.Z),o}function dt(t,e=1){const s=t.length;if(s<3)return[];const n=[_t.M,ut(t[0].x),ut(t[0].y)],i=e/6;for(let a=0;a<s;a++){const o=t[(a-1+s)%s],r=t[a],h=t[(a+1)%s],l=t[(a+2)%s];n.push(_t.C,ut(r.x+(h.x-o.x)*i),ut(r.y+(h.y-o.y)*i),ut(h.x-(l.x-r.x)*i),ut(h.y-(l.y-r.y)*i),ut(h.x),ut(h.y))}return n.push(_t.Z),n}function os(t){const e=t.length;if(e<2)return[];const s=[_t.M,ut(t[0].x),ut(t[0].y)];for(let n=0;n<e-1;n++){const i=t[Math.max(n-1,0)],a=t[n],o=t[n+1],r=t[Math.min(n+2,e-1)];s.push(_t.C,ut(a.x+(o.x-i.x)/6),ut(a.y+(o.y-i.y)/6),ut(o.x-(r.x-a.x)/6),ut(o.y-(r.y-a.y)/6),ut(o.x),ut(o.y))}return s}var Ye="M0 -1 L0.29 -0.4 L0.95 -0.31 L0.47 0.15 L0.59 0.81 L0 0.5 L-0.59 0.81 L-0.47 0.15 L-0.95 -0.31 L-0.29 -0.4 Z",Mt="#ffffff",tt=[-1,1],ci="#3a2420",hi="#f2808f",un="#26324a",vr="#ffd84a",vt=(...t)=>{const e=[];for(let s=0;s+1<t.length;s+=2)e.push({x:t[s],y:t[s+1]});return e};function fi(t,e){var s,n,i,a,o,r,h;const l=t.palette,c=[],f={stroke:l.outline,lw:e},u=x=>t.headExtras.includes(x),y=(x,g)=>{var v,_;return(_=(v=t.extraColors)==null?void 0:v[x])!=null?_:g};if(u("mane")){for(let g=0;g<12;g++){const v=g/12*Math.PI*2;c.push(A({k:"circle",x:Math.cos(v)*1.02,y:Math.sin(v)*1+.04,r:.42,fill:y(0,l.accent)},f))}c.push({k:"circle",x:0,y:.04,r:1.08,fill:y(0,l.accent)})}if(u("rainbow-mane")){const x=(s=t.extraColors)!=null?s:["#f59ac0","#fbd46a","#8fd3f4"];[[.98,.05,.3,.5,-.25],[.92,.58,.26,.42,-.1],[.62,.92,.22,.32,.4]].forEach(([v,_,T,N,R],M)=>c.push(A({k:"ellipse",x:v,y:_,rx:T,ry:N,rot:R,fill:x[M%x.length]},f)))}if(u("spikes"))for(const x of[-.55,0,.55]){const g=Fe(x,1.48),v=Fe(x-.32,.86),_=Fe(x+.32,.86);c.push(A({k:"path",d:pt([v,g,_],.22),fill:l.accent},f))}if(u("curl")&&c.push(A({k:"path",d:dt([{x:-.2,y:-.9},{x:-.05,y:-1.3},{x:.32,y:-1.42},{x:.16,y:-1.18},{x:.2,y:-.9}]),fill:l.body},f)),u("wool"))for(let x=0;x<=8;x++){const g=-1.75+x/8*3.5;c.push(A({k:"circle",x:Math.sin(g)*.98,y:-Math.cos(g)*.92-.04,r:.34,fill:l.body},f))}if(u("crest")&&[-.38,0,.38].forEach((x,g)=>{const v=Fe(x,1.12);c.push(A({k:"ellipse",x:v.x,y:v.y,rx:.15,ry:.42,rot:x,fill:y(g,l.accent)},f))}),u("plume")&&c.push(A({k:"path",d:dt(vt(-.12,-.92,-.2,-1.42,.1,-1.78,.62,-1.74,.36,-1.46,.16,-.98)),fill:l.accent},f)),u("locks")&&c.push(A({k:"path",d:dt(vt(-1.14,.58,-1.24,-.2,-.86,-.98,0,-1.2,.86,-.98,1.24,-.2,1.14,.58,.8,.66,0,.2,-.8,.66)),fill:(n=l.hair)!=null?n:l.outline},f)),u("bun")&&c.push(A({k:"circle",x:.04,y:-1.14,r:.4,fill:(i=l.hair)!=null?i:l.outline},f)),u("ninja-hood"))for(const[x,g]of[[.35,.5],[.85,.42]])c.push(A({k:"ellipse",x:1+Math.cos(x)*g*.8,y:-.5+Math.sin(x)*g*.8,rx:g,ry:.11,rot:x,fill:l.accent},f));if(u("bandana"))for(const[x,g]of[[Math.PI-.5,.42],[Math.PI-1,.36]])c.push(A({k:"ellipse",x:-.98+Math.cos(x)*g*.8,y:-.36+Math.sin(x)*g*.8,rx:g,ry:.12,rot:x,fill:l.accent},f));if(u("ruff"))for(const x of tt)c.push(A({k:"path",d:pt(vt(x*.7,-.3,x*1.32,0,x*1.02,.18,x*1.26,.46,x*.86,.56,x*.98,.84,x*.4,.7),.25),fill:l.body},f));if(t.face.eyesOnTop)for(const x of tt)c.push(A({k:"circle",x:x*.46,y:-.72,r:.38,fill:l.body},f));c.push(...Ar(t,e)),c.push(kr(t,f));const d=t.face.muzzle,b=l.belly;if(d==="oval"&&c.push({k:"ellipse",x:0,y:.4,rx:.46,ry:.32,fill:b}),d==="monkey"){for(const x of tt)c.push({k:"circle",x:x*.32,y:-.04,r:.38,fill:b});c.push({k:"ellipse",x:0,y:.4,rx:.56,ry:.4,fill:b})}if(d==="heart"){for(const x of tt)c.push({k:"circle",x:x*.36,y:.02,r:.5,fill:b});c.push({k:"ellipse",x:0,y:.38,rx:.66,ry:.48,fill:b})}if(d==="disc")for(const x of tt)c.push({k:"circle",x:x*.4,y:.02,r:.44,fill:b});if(d==="cheeks")for(const x of tt)c.push({k:"ellipse",x:x*.4,y:.44,rx:.44,ry:.32,fill:b});if(d==="band"&&c.push({k:"path",d:Er(t,e),fill:b}),u("stripes")&&t.head==="snout-long"){const x=y(0,l.outline);for(const[g,v,_,T]of[[.46,-.94,.36,-.66],[.8,-.72,.62,-.5],[1,-.36,.78,-.24]])c.push({k:"line",pts:[g,v,_,T],stroke:x,lw:.11})}else if(u("stripes")){const x=y(0,l.outline);c.push({k:"line",pts:[0,-.97,0,-.66],stroke:x,lw:.13});for(const g of tt)c.push({k:"line",pts:[g*.3,-.93,g*.24,-.7],stroke:x,lw:.1}),c.push({k:"line",pts:[g*.98,-.05,g*.74,0],stroke:x,lw:.1}),c.push({k:"line",pts:[g*.94,.22,g*.74,.22],stroke:x,lw:.09})}if(u("spots")){const x=y(1,l.belly);c.push({k:"circle",x:-.55,y:-.5,r:.15,fill:x}),c.push({k:"circle",x:.58,y:-.42,r:.11,fill:x}),c.push({k:"circle",x:.22,y:-.76,r:.09,fill:x})}if(t.head==="snout-long")for(const[x,g,v]of[[-1.38,-.14,.06],[-1.14,-.22,.055]])c.push({k:"ellipse",x,y:g,rx:v,ry:v*.8,rot:-.3,fill:l.outline,alpha:.85});if(u("forehead")&&c.push({k:"path",d:dt(vt(-.62,-.66,0,-.86,.62,-.66,.26,-.36,0,-.1,-.26,-.36),.9),fill:y(0,l.accent)}),u("eye-spot")&&c.push({k:"ellipse",x:.42,y:-.06,rx:.3,ry:.33,rot:.3,fill:(a=l.ears)!=null?a:l.accent}),u("gills"))for(const x of tt)for(const g of[0,.12,.24])c.push({k:"path",d:"M".concat(x*(.66+g)," 0.06 Q").concat(x*(.6+g)," 0.22 ").concat(x*(.66+g)," 0.38"),stroke:l.accent,lw:e*.9});const m=(o=l.hair)!=null?o:l.outline;if(u("hair")&&c.push(A({k:"path",d:dt(vt(-1.02,-.06,-1.02,-.58,-.62,-1.04,.08,-1.14,.76,-.92,1.05,-.42,1,-.06,.84,-.4,.42,-.5,.06,-.4,-.34,-.56,-.74,-.38)),fill:m},f)),u("locks")&&c.push(A({k:"path",d:dt(vt(-1,-.08,-.98,-.62,-.56,-1.02,0,-1.1,.56,-1.02,.98,-.62,1,-.08,.8,-.38,.36,-.44,0,-.4,-.36,-.44,-.8,-.38)),fill:m},f)),u("bun")&&c.push(A({k:"path",d:dt(vt(-1.02,-.1,-.98,-.62,-.56,-1.02,0,-1.1,.56,-1.02,.98,-.62,1.02,-.1,.84,-.36,.5,-.56,.12,-.48,-.22,-.6,-.6,-.5,-.86,-.36)),fill:m},f)),u("curls")){for(let x=0;x<7;x++){const g=Fe(-1.3+x/6*2.6,.86);c.push(A({k:"circle",x:g.x,y:g.y,r:.3,fill:m},f))}c.push({k:"ellipse",x:0,y:-.64,rx:.8,ry:.36,fill:m})}if(u("ninja-hood")&&(c.push({k:"rect",x:0,y:0,w:1.56,h:.6,r:.28,fill:(r=l.skin)!=null?r:Mt,stroke:l.outline,lw:e*.8}),c.push(A({k:"path",d:"M-0.98 -0.42 Q0 -0.74 0.98 -0.42 L1.0 -0.62 Q0 -0.94 -1.0 -0.62 Z",fill:l.accent},f))),u("domino")){c.push(A({k:"path",d:dt(vt(-.86,-.04,-.62,-.3,-.18,-.24,0,-.16,.18,-.24,.62,-.3,.86,-.04,.6,.22,.16,.16,0,.1,-.16,.16,-.6,.22),.9),fill:l.accent},f));for(const x of tt)c.push({k:"ellipse",x:x*.38,y:0,rx:.19,ry:.13,fill:Mt})}if(c.push(...Sr(t,e)),u("brows"))for(const x of tt)c.push({k:"line",pts:[x*.72,-.5,x*.14,-.3],stroke:l.accent,lw:.16});if(t.face.brows)for(const x of tt)c.push({k:"line",pts:[x*.2,-.2,x*.54,-.28],stroke:t.face.brows,lw:.09});if(c.push(...Tr(t,e)),t.face.cheeks)for(const x of _r(t))c.push({k:"ellipse",x:x.x,y:x.y,rx:.15,ry:.1,fill:t.face.cheeks,alpha:.8});if(u("whiskers"))for(const x of tt)for(const g of[-.1,.06])c.push({k:"line",pts:[x*.62,.38+g,x*1.06,.3+g*2.2],stroke:l.outline,lw:e*.7,alpha:.75});if(u("rainbow-mane")){const x=(h=t.extraColors)!=null?h:["#f59ac0","#fbd46a","#8fd3f4"];c.push(A({k:"ellipse",x:.42,y:-.82,rx:.34,ry:.22,rot:.5,fill:x[0]},f)),c.push(A({k:"ellipse",x:.1,y:-.92,rx:.3,ry:.2,rot:.25,fill:x[1%x.length]},f))}if(t.ears==="unicorn"){const x=[{x:-.18,y:-.84},{x:.02,y:-1.72},{x:.18,y:-.84}];c.push(A({k:"path",d:pt(x,.12),fill:l.accent},f));for(const g of[-1,-1.2,-1.4]){const v=.16*((g+1.72)/.88);c.push({k:"line",pts:[-v,g+.04,v,g-.04],stroke:l.outline,lw:e*.7,alpha:.6})}}if(u("flower-crown")){const x=[y(1,"#f7a8cf"),y(2,"#fff3a0"),y(3,Mt)];for(const g of[-.84,-.28,.28,.84]){const v=Fe(g,.9);c.push({k:"ellipse",x:v.x,y:v.y,rx:.14,ry:.07,rot:g+.5,fill:"#7cc76a",stroke:l.outline,lw:e*.7})}[-1.12,-.56,0,.56,1.12].forEach((g,v)=>{const _=Fe(g,.9),T=v===2?.13:.11;for(let N=0;N<5;N++){const R=g+N/5*Math.PI*2;c.push({k:"circle",x:_.x+Math.sin(R)*T,y:_.y-Math.cos(R)*T,r:T*.82,fill:x[v%x.length],stroke:l.outline,lw:e*.7})}c.push({k:"circle",x:_.x,y:_.y,r:T*.62,fill:x[v%x.length]}),c.push({k:"circle",x:_.x,y:_.y,r:T*.42,fill:l.accent})})}if(u("helmet")){for(const x of tt)c.push(A({k:"rect",x:x*1,y:.05,w:.26,h:.56,r:.12,fill:l.accent},f));c.push({k:"path",d:"M-0.62 -0.62 Q-0.3 -0.92 0.12 -0.9",stroke:Mt,lw:.1,alpha:.9})}if(u("bolts"))for(const x of tt)c.push(A({k:"rect",x:x*1.08,y:.08,w:.2,h:.44,r:.08,fill:l.accent},f));if(u("tuft")&&c.push(A({k:"path",d:dt([{x:-.26,y:-.95},{x:-.12,y:-1.22},{x:.02,y:-1.04},{x:.16,y:-1.28},{x:.28,y:-.95},{x:0,y:-.86}]),fill:l.body},f)),u("eggshell")&&c.push(A({k:"path",d:"M-0.88 -0.5 C-0.88 -1.12 -0.46 -1.42 0 -1.42 C0.46 -1.42 0.88 -1.12 0.88 -0.5 L0.66 -0.66 L0.44 -0.48 L0.22 -0.66 L0 -0.48 L-0.22 -0.66 L-0.44 -0.48 L-0.66 -0.66 Z",fill:y(0,Mt)},f)),u("wool"))for(const[x,g]of[[-.36,-.84],[.02,-.94],[.4,-.82]])c.push(A({k:"circle",x,y:g,r:.27,fill:l.body},f));if(u("stripe")&&c.push({k:"rect",x:0,y:-.64,w:.38,h:.62,r:.06,fill:l.accent}),u("eye-patch")&&(c.push({k:"line",pts:[-.97,-.5,.97,.13],stroke:l.outline,lw:.07}),c.push({k:"ellipse",x:.38,y:.02,rx:.21,ry:.19,fill:l.outline})),u("bandana")){c.push(A({k:"path",d:dt(vt(-1.05,-.22,-.96,-.72,-.5,-1.08,.1,-1.14,.72,-.96,1.04,-.56,1.05,-.22,.5,-.46,-.5,-.46)),fill:l.accent},f));for(const[x,g]of[[-.5,-.8],[.08,-.92],[.6,-.74],[-.12,-.62],[.36,-.6]])c.push({k:"circle",x,y:g,r:.06,fill:Mt,alpha:.85});c.push(A({k:"circle",x:-.98,y:-.34,r:.15,fill:l.accent},f))}if(u("cap")){for(const x of tt)c.push({k:"line",pts:[x*.98,-.2,x*.5,.82,-x*.05,.98],stroke:l.outline,lw:.06});c.push(A({k:"path",d:dt(vt(-1.1,-.16,-1.04,-.66,-.6,-1.12,0,-1.24,.6,-1.12,1.04,-.66,1.1,-.16,.5,-.4,-.5,-.4)),fill:l.accent},f)),c.push(A({k:"path",d:"M-0.74 -0.4 Q0 -0.6 0.74 -0.4 Q0.8 -0.24 0.6 -0.22 Q0 -0.36 -0.6 -0.22 Q-0.8 -0.24 -0.74 -0.4 Z",fill:l.accent},f)),c.push(A({k:"circle",x:.5,y:-.82,r:.15,fill:y(0,Mt)},f));for(const x of[-.42,-.14])c.push({k:"line",pts:[x,-1.04,x+.02,-.78],stroke:l.outline,lw:.07,alpha:.7})}if(u("safari-hat")&&(c.push(A({k:"ellipse",x:0,y:-.56,rx:1.48,ry:.3,fill:l.accent},f)),c.push(A({k:"path",d:dt(vt(-.78,-.58,-.7,-1.1,-.3,-1.38,.3,-1.38,.7,-1.1,.78,-.58,0,-.5),.8),fill:l.accent},f)),c.push({k:"path",d:"M-0.77 -0.72 Q0 -0.62 0.77 -0.72 L0.74 -0.9 Q0 -0.8 -0.74 -0.9 Z",fill:y(1,l.outline),stroke:l.outline,lw:e*.8})),u("wizard-hat")){c.push(A({k:"ellipse",x:0,y:-.62,rx:1.32,ry:.26,fill:l.accent},f)),c.push(A({k:"path",d:pt(vt(-.8,-.66,-.36,-1.5,.5,-2.2,.3,-1.46,.8,-.66),.3),fill:l.accent},f));const x=y(0,vr);for(const[g,v,_]of[[.02,-1.08,.18],[-.38,-.84,.1],[.36,-1.5,.11]])c.push({k:"group",x:g,y:v,s:_,items:[{k:"path",d:Ye,fill:x}]})}if(u("dive-mask")){for(const g of tt)c.push({k:"line",pts:[g*.7,-.04,g*1,-.12],stroke:l.outline,lw:.2},{k:"line",pts:[g*.7,-.04,g*1,-.12],stroke:l.accent,lw:.11});c.push({k:"rect",x:0,y:0,w:1.42,h:.62,r:.28,fill:"#bfe9f5",alpha:.35}),c.push({k:"rect",x:0,y:0,w:1.42,h:.62,r:.28,stroke:l.outline,lw:.2}),c.push({k:"rect",x:0,y:0,w:1.42,h:.62,r:.28,stroke:l.accent,lw:.11}),c.push({k:"path",d:"M-0.5 -0.16 Q-0.4 -0.24 -0.22 -0.24",stroke:Mt,lw:.06,alpha:.9});const x="M0.5 0.52 Q0.98 0.56 1.04 0.1 L1.12 -0.92";c.push({k:"path",d:x,stroke:l.outline,lw:.24},{k:"path",d:x,stroke:l.accent,lw:.13})}return c}function kr(t,e){var s;const n=t.headExtras.includes("ninja-hood")?t.palette.body:(s=t.palette.skin)!=null?s:t.palette.body;switch(t.head){case"round":return A({k:"circle",x:0,y:0,r:1,fill:n},e);case"wide":return A({k:"ellipse",x:0,y:.03,rx:1.12,ry:.94,fill:n},e);case"tall":return A({k:"ellipse",x:0,y:-.02,rx:.94,ry:1.04,fill:n},e);case"square":return A({k:"rect",x:0,y:0,w:2,h:1.8,r:.46,fill:n},e);case"bucket":return A({k:"path",d:pt(vt(-.94,.96,-.98,-.36,-.62,-1.04,.62,-1.04,.98,-.36,.94,.96),.42),fill:n},e);case"snout-long":return A({k:"path",d:dt(wr,.95),fill:n},e);case"bulb":return A({k:"path",d:dt([{x:0,y:-1.02},{x:.86,y:-.74},{x:1.08,y:-.12},{x:.72,y:.62},{x:0,y:.92},{x:-.72,y:.62},{x:-1.08,y:-.12},{x:-.86,y:-.74}]),fill:n},e)}}var wr=vt(.7,-.88,.12,-1.04,-.3,-.98,-.72,-.74,-1.2,-.56,-1.5,-.32,-1.6,.04,-1.44,.42,-.9,.72,-.2,.92,.5,.88,.96,.56,1.08,0,.98,-.5);function ui(t,e,s){return t.head==="snout-long"?[{x:-.36,y:-.5,k:.95},{x:.26,y:-.48,k:1.1}]:tt.map(n=>({x:n*e,y:s,k:1}))}function _r(t){return t.head==="snout-long"?vt(-.66,-.14,.66,.1):tt.map(e=>({x:e*.64,y:.3}))}function Mr(t){return t.head==="round"?{cy:0,rx:1,ry:1}:t.head==="tall"?{cy:-.02,rx:.94,ry:1.04}:{cy:.03,rx:1.12,ry:.94}}function Er(t,e){const{cy:s,rx:n,ry:i}=Mr(t),a=n-e/2,o=i-e/2,r=.15,h=Math.asin(Math.min(1,(r-s)/o)),l=Math.cos(h)*a,c=d=>Math.round(d*100)/100||0,f=[_t.M,c(-l),r],u=[[-.84*l,.02,-.53*l,.06,-.32*l,.24],[-.17*l,.11,.17*l,.11,.32*l,.24],[.53*l,.06,.84*l,.02,l,r]];for(const d of u)f.push(_t.C,...d.map(c));const y=24;for(let d=1;d<=y;d++){const b=h+(Math.PI-2*h)*d/y;f.push(_t.L,c(Math.cos(b)*a),c(s+Math.sin(b)*o))}return f.push(_t.Z),f}function Ar(t,e){var s,n,i,a,o;const r=t.palette,h={stroke:r.outline,lw:e},l=[];for(const c of tt)switch(t.ears){case"pointy":case"unicorn":{const f=t.ears==="unicorn"?.8:1,u={x:c*.3,y:-.82},y={x:c*.86,y:-.82-.62*f},d={x:c*.94,y:-.36};l.push(A({k:"path",d:pt([u,y,d],.2),fill:r.body},h));const b={x:(u.x+y.x+d.x)/3,y:(u.y+y.y+d.y)/3},m=[u,y,d].map(x=>({x:b.x+(x.x-b.x)*.55,y:b.y+(x.y-b.y)*.55+.04}));l.push({k:"path",d:pt(m,.25),fill:r.accent});break}case"round":l.push(A({k:"circle",x:c*.72,y:-.72,r:.36,fill:(s=r.ears)!=null?s:r.body},h)),r.ears||l.push({k:"circle",x:c*.74,y:-.74,r:.19,fill:r.accent});break;case"big-round":l.push(A({k:"circle",x:c*.96,y:-.46,r:.52,fill:r.body},h)),l.push({k:"circle",x:c*1,y:-.44,r:.32,fill:r.accent});break;case"long":l.push(A({k:"ellipse",x:c*.38,y:-1.42,rx:.25,ry:.68,rot:c*.14,fill:r.body},h)),l.push({k:"ellipse",x:c*.39,y:-1.36,rx:.12,ry:.48,rot:c*.14,fill:r.accent});break;case"side":l.push(A({k:"circle",x:c*1,y:.02,r:.34,fill:r.body},h)),l.push({k:"circle",x:c*1.02,y:.02,r:.2,fill:r.belly});break;case"tufts":l.push(A({k:"path",d:pt([{x:c*.3,y:-.84},{x:c*1.22,y:-1.12},{x:c*.92,y:-.42}],.16),fill:r.body},h)),l.push({k:"line",pts:[c*.62,-.78,c*1,-.98],stroke:r.accent,lw:.08});break;case"antennae":{const f={x:c*.62,y:-1.42};l.push({k:"path",d:"M".concat(c*.3," -0.8 Q").concat(c*.36," -1.2 ").concat(f.x," ").concat(f.y),stroke:r.outline,lw:e*2.6}),l.push({k:"path",d:"M".concat(c*.3," -0.8 Q").concat(c*.36," -1.2 ").concat(f.x," ").concat(f.y),stroke:r.body,lw:e*1.2}),l.push(A({k:"circle",x:f.x,y:f.y,r:.17,fill:r.accent},h));break}case"floppy":l.push(A({k:"ellipse",x:c*.96,y:.02,rx:.3,ry:.62,rot:-c*.36,fill:(n=r.ears)!=null?n:r.body},h));break;case"droopy":l.push(A({k:"ellipse",x:c*1.04,y:-.22,rx:.4,ry:.18,rot:c*.32,fill:(i=r.skin)!=null?i:r.body},h)),l.push({k:"ellipse",x:c*1.08,y:-.2,rx:.24,ry:.08,rot:c*.32,fill:r.accent});break;case"pixie":l.push(A({k:"path",d:pt(vt(c*.86,-.22,c*1.36,-.5,c*1.02,.26),.28),fill:(a=r.skin)!=null?a:r.body},h)),l.push({k:"line",pts:[c*.98,-.12,c*1.16,-.3],stroke:r.accent,lw:e*.8,alpha:.5});break;case"human":l.push(A({k:"ellipse",x:c*.98,y:.06,rx:.17,ry:.23,fill:(o=r.skin)!=null?o:r.body},h));break;case"horns":{const f=[{x:c*.3,y:-.84},{x:c*.6,y:-1.5},{x:c*.66,y:-.68}];l.push(A({k:"path",d:pt(f,.18),fill:r.accent},h));break}}return t.ears==="fin"&&l.push(A({k:"path",d:pt(vt(-.4,-.82,.2,-1.62,.46,-.78),.2),fill:r.body},h)),t.ears==="antenna"&&(l.push({k:"line",pts:[0,-.85,0,-1.42],stroke:r.outline,lw:e*2.6}),l.push({k:"line",pts:[0,-.85,0,-1.42],stroke:r.limbs,lw:e*1.2}),l.push(A({k:"circle",x:0,y:-1.5,r:.18,fill:r.accent},h))),l}function Sr(t,e){var s,n,i,a,o,r,h;const l=t.palette,c=t.face,f=[],u=l.outline,y=c.eyesOnTop?.46:.4,d=c.eyesOnTop?-.72:-.04,b=(m,x,g)=>({k:"circle",x:m,y:x,r:g,fill:Mt});switch(c.eyes){case"dot":for(const m of ui(t,y,d))f.push({k:"ellipse",x:m.x,y:m.y,rx:.12*m.k,ry:.155*m.k,fill:u}),f.push(b(m.x+.04*m.k,m.y-.06*m.k,.045*m.k));break;case"bead":for(const m of ui(t,y,d))f.push({k:"ellipse",x:m.x,y:m.y,rx:.16*m.k,ry:.22*m.k,fill:u}),f.push(b(m.x+.05*m.k,m.y-.08*m.k,.065*m.k));break;case"big":for(const m of tt)c.eyeRing&&f.push({k:"circle",x:m*y,y:d,r:.36,fill:c.eyeRing,stroke:u,lw:e*.8}),f.push({k:"circle",x:m*y,y:d,r:.25,fill:Mt,stroke:u,lw:e*.8}),f.push({k:"circle",x:m*y+m*-.03,y:d+.03,r:.14,fill:(s=c.eyeColor)!=null?s:u}),f.push(b(m*y+m*-.03+.05,d-.03,.05));break;case"mask":for(const m of tt)f.push({k:"ellipse",x:m*.4,y:0,rx:.24,ry:.32,rot:m*-.55,fill:l.limbs}),f.push({k:"circle",x:m*.4,y:-.02,r:.11,fill:Mt}),f.push({k:"circle",x:m*.39,y:-0,r:.065,fill:u});break;case"screen":f.push({k:"rect",x:0,y:0,w:1.5,h:.66,r:.26,fill:"#24323d",stroke:u,lw:e*.8});for(const m of tt)f.push({k:"ellipse",x:m*.36,y:0,rx:.2,ry:.24,fill:(n=c.eyeColor)!=null?n:"#7ff0ff",alpha:.3}),f.push({k:"ellipse",x:m*.36,y:0,rx:.12,ry:.16,fill:(i=c.eyeColor)!=null?i:"#7ff0ff"});break;case"almond":for(const m of tt)f.push({k:"ellipse",x:m*.42,y:-.02,rx:.3,ry:.2,rot:-m*.5,fill:(a=c.eyeColor)!=null?a:u}),f.push(b(m*.42-m*.07,-.08,.07));break;case"calm":for(const m of tt)f.push({k:"ellipse",x:m*.38,y:.02,rx:.085,ry:.12,fill:u}),f.push(b(m*.38+.03,-.02,.03));break;case"slit":f.push({k:"line",pts:[0,-.98,0,-.2],stroke:u,lw:e*.8,alpha:.5}),f.push({k:"rect",x:0,y:-.04,w:1.56,h:.26,r:.1,fill:un,stroke:u,lw:e*.8}),f.push({k:"rect",x:0,y:.3,w:.22,h:.46,r:.08,fill:un,stroke:u,lw:e*.8});for(const m of tt){f.push({k:"ellipse",x:m*.4,y:-.04,rx:.12,ry:.07,fill:(o=c.eyeColor)!=null?o:Mt});for(const x of[.36,.56])f.push({k:"circle",x:m*.42,y:x,r:.05,fill:u,alpha:.6})}break;case"goggle":for(const m of tt)f.push({k:"circle",x:m*.9,y:0,r:.13,fill:l.accent,stroke:u,lw:e*.8});f.push({k:"rect",x:0,y:0,w:1.66,h:.62,r:.3,fill:un,stroke:u,lw:e*.8}),f.push({k:"path",d:"M-0.6 -0.16 Q-0.42 -0.24 -0.12 -0.24",stroke:Mt,lw:.07,alpha:.8});for(const m of tt)f.push({k:"path",d:"M".concat(m*.5," 0.04 Q").concat(m*.34," -0.08 ").concat(m*.16," 0.02"),stroke:(r=c.eyeColor)!=null?r:"#7fd6ff",lw:.08});for(const m of[-.18,0,.18])f.push({k:"line",pts:[m,.56,m,.72],stroke:u,lw:e*.8,alpha:.6});break;case"visor":f.push({k:"ellipse",x:0,y:.08,rx:.8,ry:.64,fill:"#2a3f6b",stroke:u,lw:e*.8}),f.push({k:"path",d:"M-0.56 -0.14 Q-0.46 -0.4 -0.16 -0.46",stroke:Mt,lw:.08,alpha:.7});for(const m of tt)f.push({k:"ellipse",x:m*.28,y:.04,rx:.1,ry:.14,fill:(h=c.eyeColor)!=null?h:"#cfeeff"});break}return f}function Tr(t,e){const s=t.palette,n=t.face,i=[],a=n.eyes==="visor"?"#cfeeff":ci,o=e*1.05;switch(n.nose&&n.mouth!=="beak"&&(n.mouth==="cat"?i.push({k:"path",d:pt([{x:-.1,y:.22},{x:.1,y:.22},{x:0,y:.33}],.3),fill:n.nose,stroke:n.nose,lw:e*.6}):t.ears==="big-round"?i.push({k:"ellipse",x:0,y:.22,rx:.2,ry:.25,fill:n.nose}):i.push({k:"ellipse",x:0,y:.25,rx:.13,ry:.085,fill:n.nose})),n.mouth){case"smile":i.push({k:"path",d:n.eyes==="visor"?"M-0.16 0.32 Q0 0.46 0.16 0.32":"M-0.17 0.42 Q0 0.58 0.17 0.42",stroke:a,lw:o});break;case"open":i.push({k:"path",d:"M-0.21 0.4 Q0 0.46 0.21 0.4 Q0.19 0.68 0 0.68 Q-0.19 0.68 -0.21 0.4 Z",fill:a,stroke:a,lw:e*.5}),i.push({k:"ellipse",x:0,y:.6,rx:.1,ry:.06,fill:hi});break;case"cat":i.push({k:"path",d:"M-0.19 0.4 Q-0.1 0.5 0 0.37 Q0.1 0.5 0.19 0.4",stroke:a,lw:o});break;case"beak":i.push({k:"path",d:pt([{x:-.17,y:.2},{x:.17,y:.2},{x:0,y:.48}],.25),fill:s.accent,stroke:s.outline,lw:e*.8});break;case"teeth":i.push({k:"path",d:"M-0.36 0.34 Q0 0.44 0.36 0.34 Q0.28 0.66 0 0.66 Q-0.28 0.66 -0.36 0.34 Z",fill:a,stroke:a,lw:e*.5});for(const r of tt)i.push({k:"rect",x:r*.12,y:.43,w:.1,h:.1,r:.03,fill:Mt});break;case"grill":i.push({k:"rect",x:0,y:.56,w:.62,h:.2,r:.08,fill:"#24323d",stroke:s.outline,lw:e*.7});for(const r of[-.15,0,.15])i.push({k:"line",pts:[r,.51,r,.61],stroke:"#9fb0bd",lw:e*.6});break;case"tiny":i.push({k:"ellipse",x:0,y:.44,rx:.08,ry:.1,fill:a});break;case"smirk":i.push({k:"path",d:"M-0.16 0.46 Q0.06 0.54 0.22 0.38",stroke:a,lw:o});break;case"bill":i.push({k:"ellipse",x:0,y:.36,rx:.44,ry:.2,fill:s.accent,stroke:s.outline,lw:e*.8}),i.push({k:"path",d:"M-0.36 0.38 Q0 0.46 0.36 0.38",stroke:s.outline,lw:e*.7});for(const r of tt)i.push({k:"circle",x:r*.1,y:.28,r:.03,fill:s.outline});break;case"hook":i.push({k:"ellipse",x:0,y:.48,rx:.16,ry:.11,fill:ci}),i.push({k:"path",d:"M-0.3 0.12 Q0 -0.02 0.3 0.12 Q0.36 0.52 0.04 0.76 Q0.08 0.52 -0.08 0.46 Q-0.28 0.38 -0.3 0.12 Z",fill:s.accent,stroke:s.outline,lw:e*.8});break;case"toothy":{i.push({k:"path",d:"M-1.4 0.1 Q-0.5 0.36 0.5 0.2 Q0.64 0.16 0.68 0.02 Q0.78 0.28 0.52 0.38 Q-0.4 0.78 -1.3 0.26 Z",fill:a,stroke:a,lw:e*.6}),i.push({k:"ellipse",x:-.38,y:.5,rx:.24,ry:.08,fill:hi});for(const r of[.12,.27,.42,.57,.72,.86]){const h=(1-r)*(1-r)*-1.4+2*(1-r)*r*-.5+r*r*.5,l=(1-r)*(1-r)*.1+2*(1-r)*r*.36+r*r*.2-.01;i.push({k:"path",d:pt(vt(h-.08,l,h+.08,l,h,l+.14),.3),fill:Mt})}for(const r of[.3,.7]){const h=(1-r)*(1-r)*.52+2*(1-r)*r*-.4+r*r*-1.3,l=(1-r)*(1-r)*.38+2*(1-r)*r*.78+r*r*.26+.01;i.push({k:"path",d:pt(vt(h-.07,l,h+.07,l,h,l-.12),.3),fill:Mt})}break}case"jaws":{i.push({k:"path",d:"M-0.5 0.3 Q0 0.5 0.5 0.3 Q0.38 0.72 0 0.72 Q-0.38 0.72 -0.5 0.3 Z",fill:a,stroke:a,lw:e*.5});for(const r of[-.34,-.17,0,.17,.34]){const h=.3+.4*(r+.5)*(.5-r)-.01;i.push({k:"path",d:pt(vt(r-.075,h,r+.075,h,r,h+.13),.15),fill:Mt})}break}}return i}var Fe=(t,e)=>({x:Math.sin(t)*e,y:-Math.cos(t)*e}),Cr=.5,be={leftEye:2,rightEye:5,leftEar:7,rightEar:8},Pe={"3-5":{head:.75,neck:.74,arm:.3,leg:.36,hand:.19,foot:1.2,shoulderMin:.4,shoulderPad:.07,hipMin:.5,hipPad:.22,bottom:.26,bulge:1.12,armsOverHead:!0},"6-8":{head:.6,neck:.78,arm:.22,leg:.28,hand:.15,foot:1,shoulderMin:.34,shoulderPad:.04,hipMin:.4,hipPad:.16,bottom:.14,bulge:1.04,armsOverHead:!1},"9-12":{head:.5,neck:.92,arm:.17,leg:.21,hand:.125,foot:.9,shoulderMin:.36,shoulderPad:.07,hipMin:.32,hipPad:.08,bottom:.1,bulge:1,armsOverHead:!1}},Ps="6-8",di=(t,e)=>{var s;return e!==void 0&&t.band!=="all"&&((s=t.alsoIn)!=null&&s.includes(e))&&e in Pe?e:t.band in Pe?t.band:Ps},_c=Pe[Ps].head,Rr=.3,Fr=.12,Pr=.9,pi=.5,yi=.65,Lr=.35,Nr=.2,Ir=.25,$t=(t,e)=>({x:t.x-e.x,y:t.y-e.y}),xt=(t,e)=>({x:t.x+e.x,y:t.y+e.y}),ht=(t,e)=>({x:t.x*e,y:t.y*e}),Le=t=>Math.hypot(t.x,t.y),mi=(t,e)=>({x:(t.x+e.x)/2,y:(t.y+e.y)/2}),Ls=t=>{const e=Le(t);return e>1e-9?{x:t.x/e,y:t.y/e}:{x:0,y:1}},Or=(...t)=>t.every(Number.isFinite),zr=t=>Math.atan2(Math.sin(t),Math.cos(t)),Dr=(t,e,s)=>Math.min(Math.max(t,e),s);function xi(t,e,s=!1){return n=>{const i=t[n*3],a=t[n*3+1],o=t[n*3+2];return i===void 0||a===void 0||o===void 0||!Or(i,a,o)?{x:0,y:0,ok:!1}:{x:e.x+(s?1-i:i)*e.w,y:e.y+a*e.h,ok:o>=Cr}}}function dn(t,e,s={}){var n,i;const a=xi(t,e,s.mirrored),o=a(J.leftShoulder),r=a(J.rightShoulder);if(!o.ok||!r.ok)return null;const h=a(J.leftHip),l=a(J.rightHip),c=mi(o,r),f=Le($t(r,o)),u=h.ok&&l.ok;let y=Ls($t(r,o));f<1e-6&&(y={x:1,y:0});let d,b,m;if(u){const M=mi(h,l);b=Le($t(M,c)),b>=f*Ir?d=Ls($t(M,c)):(d={x:-y.y,y:y.x},d.y<0&&(d=ht(d,-1))),m=Math.max(b,f*1.15)}else d={x:-y.y,y:y.x},d.y<0&&(d=ht(d,-1)),m=f*1.15,b=m;m=Math.max(m,1e-6);const x={x:d.y,y:-d.x},g=Math.atan2(x.y,x.x),v=ht(d,-1),_=(i=Pe[(n=s.band)!=null?n:Ps])!=null?i:Pe[Ps],T=_.head*m;let N=xt(c,ht(v,T*_.neck));const R=a(J.nose);if(R.ok){const M=xt(R,ht(v,T*.15)),P=ht($t(M,N),Lr),z=Math.min(1,T*Nr/Math.max(Le(P),1e-6));N=xt(N,ht(P,z))}return{S:c,r:x,d,U:m,L:b,hipsOk:u,head:N,headR:T,headRot:g+Br(t,a,g,m),angle:g}}function Br(t,e,s,n){const i=[[be.leftEar,be.rightEar],[be.leftEye,be.rightEye]];for(const[a,o]of i){const r=e(a),h=e(o);if(!r.ok||!h.ok||!(t[a*3+2]>=yi&&t[o*3+2]>=yi)||Le($t(h,r))<n*.05)continue;const l=zr(Math.atan2(h.y-r.y,h.x-r.x)-s),c=Math.max(Math.abs(l)-Fr,0),f=Dr((Pr+pi-Math.abs(l))/pi,0,1);return Math.sign(l)*Math.min(c,Rr)*f}return 0}function bi(t,e,s,n={}){var i,a,o,r,h,l,c,f,u,y,d,b,m,x,g,v,_,T,N,R,M,P,z;const U=di(e,n.band),G=Pe[U],O=dn(t,s,We(A({},n),{band:U}));if(!O)return[];const X=xi(t,s,n.mirrored),L=e.palette,{S:lt,r:yt,d:$,U:w,L:H}=O,W=C=>e.bodyExtras.includes(C),bt=Math.max(1.2,w*.045),Z={stroke:L.outline,lw:bt},j=(C,B)=>({x:lt.x+yt.x*C+$.x*B,y:lt.y+yt.y*C+$.y*B}),se=C=>C.map(([B,Y])=>j(B,Y)),Ae=X(J.leftShoulder),At=X(J.rightShoulder),Ot=X(J.leftHip),Kt=X(J.rightHip),sn=Le($t(At,Ae)),qt=O.hipsOk?Le($t(Kt,Ot)):sn*.7,K=Math.max(sn/2+G.shoulderPad*w,G.shoulderMin*w),gt=Math.max(qt/2+G.hipPad*w,G.hipMin*w),mt=-.1*w,St=H+G.bottom*w,et=[],pe=[],it=[],De=[],ws=[],Be=(C,B,Y,st)=>{const at=B.flatMap(Pt=>[Pt.x,Pt.y]);C.push({k:"line",pts:at,stroke:L.outline,lw:Y+bt*2}),C.push({k:"line",pts:at,stroke:st,lw:Y})},Ue=G.leg*w*(W("strong-legs")?1.3:1),_s=G.arm*w*(W("tiny-arms")?.6:1),Ms=Math.max(G.arm/.22,.9);if(O.hipsOk)for(const[C,B,Y,st]of[[Ot,J.leftKnee,J.leftAnkle,-1],[Kt,J.rightKnee,J.rightAnkle,1]]){const at=X(B),Pt=X(Y);if(!at.ok)continue;const Se=xt(C,ht($,-.12*w)),zt=Pt.ok?[Se,at,Pt]:[Se,at];Be(pe,zt,Ue,L.limbs),W("joints")&&pe.push(A({k:"circle",x:at.x,y:at.y,r:.15*w*Ms,fill:L.accent},Z)),Pt.ok&&pe.push(...Gr(e,Pt,O,st,bt,G.foot))}for(const[C,B,Y,st]of[[Ae,J.leftElbow,J.leftWrist,-1],[At,J.rightElbow,J.rightWrist,1]]){const at=X(B),Pt=X(Y);if(W("pauldrons")){const Lt=xt(C,ht($,.02*w));De.push(A({k:"ellipse",x:Lt.x,y:Lt.y,rx:.25*w,ry:.17*w,rot:O.angle+st*.25,fill:L.body},Z));const Yt=xt(Lt,ht($,.05*w));De.push({k:"ellipse",x:Yt.x,y:Yt.y,rx:.17*w,ry:.07*w,rot:O.angle+st*.25,fill:L.belly})}if(!at.ok)continue;const zt=G.armsOverHead&&(at.x-lt.x)*$.x+(at.y-lt.y)*$.y<-.25*w?ws:De,nn=xt(C,ht($,.04*w));if(Be(zt,Pt.ok?[nn,at,Pt]:[nn,at],_s,L.limbs),W("joints")&&zt.push(A({k:"circle",x:at.x,y:at.y,r:.13*w*Ms,fill:L.accent},Z)),!Pt.ok)continue;const Zt=Ls($t(Pt,at)),re=xt(Pt,ht(Zt,.05*w));if(W("feathers"))for(const Lt of[-.55,0,.55]){const Yt=Math.cos(Lt),me=Math.sin(Lt)*st,Nt={x:Zt.x*Yt-Zt.y*me,y:Zt.x*me+Zt.y*Yt},oe=xt(re,ht(Nt,.16*w));zt.push(A({k:"ellipse",x:oe.x,y:oe.y,rx:.2*w,ry:.09*w,rot:Math.atan2(Nt.y,Nt.x),fill:(i=L.hands)!=null?i:L.accent},Z))}W("wand")&&st===1&&!n.portrait&&zt.push(...Wr(e,re,Ls(xt(ht(Zt,.4),$t(ht(yt,.6),$))),w,bt));const ye=G.hand*w*(W("tiny-arms")?.72:1);if(W("tiny-arms"))for(const Lt of[-.45,.45]){const Yt=Math.cos(Lt),me=Math.sin(Lt),Nt={x:Zt.x*Yt-Zt.y*me,y:Zt.x*me+Zt.y*Yt},oe=xt(re,ht(Nt,ye*.75)),xe=xt(re,ht(Nt,ye*1.6)),He={x:-Nt.y*ye*.32,y:Nt.x*ye*.32};zt.push(A({k:"path",d:pt([xt(oe,He),xe,$t(oe,He)],.2),fill:L.belly},Z))}zt.push(A({k:"circle",x:re.x,y:re.y,r:ye,fill:(a=L.hands)!=null?a:L.limbs},Z))}if(W("wings"))for(const C of[-1,1]){const B=se([[C*K*.5,.05*w],[C*(K+.85*w),-.6*w],[C*(K+.72*w),.05*w],[C*(K+.45*w),-.02*w],[C*(K+.3*w),.32*w],[C*K*.6,.55*w]]);et.push(A({k:"path",d:pt(B,.18),fill:L.accent},Z))}if(W("wings-fairy")&&et.push(...jr(e,j,K,w,bt)),W("cape")){const C=H+.8*w,B=gt+.36*w,Y=se([[-K*.92,mt+.04*w],[K*.92,mt+.04*w],[K+.16*w,H*.5],[B,C],[B*.5,C-.1*w],[0,C],[-B*.5,C-.1*w],[-B,C],[-K-.16*w,H*.5]]);et.push(A({k:"path",d:dt(Y,.6),fill:L.accent},Z))}if(W("backpack")){const C=j(0,.35*w);et.push(A({k:"rect",x:C.x,y:C.y,w:K*2+.34*w,h:.8*w,r:.16*w,rot:O.angle,fill:(r=(o=e.extraColors)==null?void 0:o[0])!=null?r:L.limbs},Z))}if(W("tank")){const C=j(K*.95,.24*w),B=(l=(h=e.extraColors)==null?void 0:h[0])!=null?l:L.accent,Y=j(K*.95,-.3*w);et.push({k:"rect",x:Y.x,y:Y.y,w:.14*w,h:.16*w,r:.04*w,rot:O.angle,fill:L.outline}),et.push(A({k:"rect",x:C.x,y:C.y,w:.34*w,h:1*w,r:.17*w,rot:O.angle,fill:B},Z))}if(O.hipsOk&&!n.portrait&&et.push(...qr(e,O,gt,bt)),W("tentacles")&&O.hipsOk)for(const C of[-1,1]){const B=se([[C*gt*.7,H*.9],[C*(gt+.22*w),H+.3*w],[C*(gt+.48*w),H+.22*w],[C*(gt+.5*w),H-.02*w],[C*(gt+.34*w),H-.06*w]]);et.push({k:"path",d:os(B),stroke:L.outline,lw:.2*w+bt*2}),et.push({k:"path",d:os(B),stroke:L.limbs,lw:.2*w})}const Wt=Math.max(K,gt)*G.bulge;if(W("wool")){for(const[B,Y]of[[K*.7,mt+.02*w],[Wt,H*.3],[Wt*1.02,H*.62],[(Wt+gt)/2,H*.92],[gt*.55,St]])for(const st of[-1,1]){const at=j(st*B,Y);it.push(A({k:"circle",x:at.x,y:at.y,r:.2*w,fill:L.body},Z))}const C=j(0,St+.02*w);it.push(A({k:"circle",x:C.x,y:C.y,r:.2*w,fill:L.body},Z))}if(W("robe")){const C=H+.58*w,B=gt*1.4;it.push(A({k:"path",d:dt(se([[-K,mt],[0,mt-.04*w],[K,mt],[Wt,H*.55],[B,C],[0,C+.06*w],[-B,C],[-Wt,H*.55]]),.7),fill:L.body},Z));const Y=se([[-B*.94,C-.1*w],[0,C-.04*w],[B*.94,C-.1*w]]);it.push({k:"path",d:os(Y),stroke:(f=(c=e.extraColors)==null?void 0:c[0])!=null?f:L.accent,lw:.07*w})}else if(W("sheet")){const C=H+.78*w,B=gt*1.3;it.push(A({k:"path",d:dt(se([[-K,mt],[K,mt],[Wt,H*.55],[B,C],[B*.5,C-.2*w],[0,C],[-B*.5,C-.2*w],[-B,C],[-Wt,H*.55]]),.9),fill:L.body},Z))}else it.push(A({k:"path",d:dt(se([[-K,mt],[0,mt-.04*w],[K,mt],[Wt,H*.55],[gt,St],[0,St+.03*w],[-gt,St],[-Wt,H*.55]]),.85),fill:L.body},Z));const jt=Math.min(K,gt);if(W("pocket")){const C=j(0,H*.74);it.push({k:"rect",x:C.x,y:C.y,w:jt*1.3,h:.3*w,r:.1*w,rot:O.angle,fill:L.belly,stroke:L.outline,lw:bt*.8})}else if(W("racing-stripe"))for(const C of[-.1,.1]){const B=j(C*w,mt+.02*w),Y=j(C*w,St-.04*w);it.push({k:"line",pts:[B.x,B.y,Y.x,Y.y],stroke:L.belly,lw:.1*w})}else if(L.belly&&L.belly!==L.body&&!W("panel")&&!W("sheet")&&!W("stripes")){const C=j(0,H*.58);it.push({k:"ellipse",x:C.x,y:C.y,rx:jt*.64,ry:Math.max(H*.36,.2*w),rot:O.angle,fill:L.belly})}if(W("spots")){const C=(y=(u=e.extraColors)==null?void 0:u[1])!=null?y:L.belly;for(const[B,Y,st]of[[-.55,.35,.09],[.5,.62,.11],[-.35,.86,.07]]){const at=j(B*jt,Y*H);it.push({k:"circle",x:at.x,y:at.y,r:st*w,fill:C})}}if(W("stripes")){const C=(b=(d=e.extraColors)==null?void 0:d[1])!=null?b:L.accent;for(const B of[.22,.44,.66]){const Y=j(-jt*.98,H*B),st=j(jt*.98,H*B);it.push({k:"line",pts:[Y.x,Y.y,st.x,st.y],stroke:C,lw:.1*w})}}if(W("straps")){const C=(x=(m=e.extraColors)==null?void 0:m[1])!=null?x:L.outline;for(const B of[-1,1]){const Y=j(B*K*.62,mt+.02*w),st=j(B*jt*.62,H*.72);it.push({k:"line",pts:[Y.x,Y.y,st.x,st.y],stroke:L.outline,lw:.13*w+bt*2}),it.push({k:"line",pts:[Y.x,Y.y,st.x,st.y],stroke:C,lw:.13*w})}}if(W("belt")){const C=j(0,H*.9);it.push(A({k:"rect",x:C.x,y:C.y,w:gt*1.92,h:.17*w,r:.06*w,rot:O.angle,fill:(v=(g=e.extraColors)==null?void 0:g[2])!=null?v:"#4a3426"},Z)),it.push(A({k:"rect",x:C.x,y:C.y,w:.2*w,h:.19*w,r:.04*w,rot:O.angle,fill:"#ffd84a"},Z))}if(W("emblem")){const C=j(0,H*.4),B=(T=(_=e.extraColors)==null?void 0:_[0])!=null?T:L.accent,Y=pt([{x:-.22,y:-.2},{x:.22,y:-.2},{x:.22,y:.04},{x:0,y:.26},{x:-.22,y:.04}],.25);it.push({k:"group",x:C.x,y:C.y,rot:O.angle,s:w,items:[{k:"path",d:Y,fill:B,stroke:L.outline,lw:bt/w},{k:"group",x:0,y:.01,s:.12,items:[{k:"path",d:Ye,fill:B===L.accent?"#ffffff":L.accent}]}]})}if(W("panel")){const C=j(0,H*.5);it.push(A({k:"rect",x:C.x,y:C.y,w:jt*1.2,h:.38*w,r:.1*w,rot:O.angle,fill:"#24323d"},Z)),((N=e.extraColors)!=null?N:["#ff7a6b","#fbd46a","#7ff0ff"]).slice(0,3).forEach((Y,st)=>{const at=j((st-1)*jt*.34,H*.5);it.push({k:"circle",x:at.x,y:at.y,r:.075*w,fill:Y})})}if(W("badge")){const C=j(-jt*.42,H*.36);it.push(A({k:"circle",x:C.x,y:C.y,r:.15*w,fill:L.accent},Z)),it.push({k:"group",x:C.x,y:C.y,rot:O.angle,s:.09*w,items:[{k:"path",d:Ye,fill:"#ffffff"}]})}if(W("star")){const C=j(-jt*.5,H*.3),B=.15*w;it.push({k:"group",x:C.x,y:C.y,rot:O.angle-.2,s:B,items:[{k:"path",d:Ye,fill:(M=(R=e.extraColors)==null?void 0:R[0])!=null?M:"#ffd84a",stroke:L.outline,lw:bt*.8/B}]})}if(W("petals")&&it.push(...Yr(e,j,K,gt,Wt,H,St,w,bt,G)),W("scarf")){const C=Math.max(.04,G.head*(1-G.neck)-.06)*w,B=j(0,C),Y=(z=(P=e.extraColors)==null?void 0:P[0])!=null?z:L.accent,st=j(K*.45,C+.28*w);it.push(A({k:"rect",x:st.x,y:st.y,w:.16*w,h:.42*w,r:.06*w,rot:O.angle+.15,fill:Y},Z)),it.push(A({k:"rect",x:B.x,y:B.y,w:K*2.05,h:.2*w,r:.1*w,rot:O.angle,fill:Y},Z))}const is={k:"group",x:O.head.x,y:O.head.y,rot:O.headRot,s:O.headR,items:Hr(e,bt/O.headR)};return[...et,...pe,...it,...De,is,...ws]}var gi=new WeakMap,Ur=64;function Hr(t,e){const s=Number(e.toPrecision(4));let n=gi.get(t);n||gi.set(t,n=new Map);let i=n.get(s);return i||(n.size>=Ur&&n.clear(),n.set(s,i=fi(t,s))),i}function Gr(t,e,s,n,i,a){const o=Xr(t,e,s,n,i,a);if(!t.bodyExtras.includes("strong-legs"))return[o];const r=s.U*a,h=xt(xt(e,ht(s.d,.07*r)),ht(s.r,n*.06*r)),l=[o];for(const c of[-1,0,1]){const f=xt(xt(h,ht(s.r,c*.12*r)),ht(s.d,.09*r));l.push({k:"ellipse",x:f.x,y:f.y,rx:.05*r,ry:.045*r,rot:s.angle,fill:t.palette.belly,stroke:t.palette.outline,lw:i*.8})}return l}function Xr(t,e,s,n,i,a){var o;const r=t.palette,{d:h,r:l}=s,c=s.U*a,f=xt(xt(e,ht(h,.07*c)),ht(l,n*.06*c)),u={stroke:r.outline,lw:i},y=(o=r.feet)!=null?o:r.limbs;if(t.bodyExtras.includes("fins")){const d=pt([{x:-.13,y:-.06},{x:.13,y:-.06},{x:.24,y:.46},{x:-.24,y:.46}],.22);return{k:"group",x:f.x,y:f.y,rot:s.angle,s:c,items:[{k:"path",d,fill:y,stroke:r.outline,lw:i/c},{k:"line",pts:[0,.06,0,.38],stroke:r.outline,lw:i/c,alpha:.5}]}}return t.bodyExtras.includes("flippers")?A({k:"ellipse",x:f.x,y:f.y,rx:.27*c,ry:.11*c,rot:s.angle,fill:y},u):t.bodyExtras.includes("boots")?A({k:"rect",x:f.x,y:f.y,w:.4*c,h:.24*c,r:.09*c,rot:s.angle,fill:y},u):A({k:"ellipse",x:f.x,y:f.y,rx:.2*c,ry:.13*c,rot:s.angle,fill:y},u)}function qr(t,e,s,n){var i,a,o,r,h,l,c,f,u;const y=t.palette,{U:d,L:b,S:m,r:x,d:g}=e,v=(M,P)=>({x:m.x+x.x*M+g.x*P,y:m.y+x.y*M+g.y*P}),_=M=>M.map(([P,z])=>v(P,z)),T={stroke:y.outline,lw:n},N=(M,P,z)=>[{k:"path",d:os(M),stroke:y.outline,lw:P+n*2},{k:"path",d:os(M),stroke:z,lw:P}],R=[];switch(t.tail){case"none":break;case"fluffy":{const M=_([[s*.5,b*.95],[s+.28*d,b*1],[s+.72*d,b*.62],[s+.78*d,b*.12],[s+.52*d,b*.32],[s+.3*d,b*.6],[s*.6,b*.7]]);R.push(A({k:"path",d:dt(M),fill:y.body},T));const P=v(s+.72*d,b*.2);R.push(A({k:"ellipse",x:P.x,y:P.y,rx:.13*d,ry:.2*d,rot:e.angle+.25,fill:y.belly},T));break}case"brush":{const M=_([[s*.4,b*.98],[s+.42*d,b*1.06],[s+.98*d,b*.66],[s+1.06*d,b*.12],[s+.86*d,-.04*d],[s+.66*d,b*.36],[s+.3*d,b*.66],[s*.5,b*.68]]);R.push(A({k:"path",d:dt(M),fill:y.body},T));const P=_([[s+1.03*d,b*.36],[s+1.06*d,b*.12],[s+.86*d,-.04*d],[s+.72*d,b*.24],[s+.86*d,b*.34]]);R.push(A({k:"path",d:dt(P),fill:y.belly},T));break}case"pom":{const M=v(s+.06*d,b*.88);R.push(A({k:"circle",x:M.x,y:M.y,r:.2*d,fill:y.belly},T));break}case"long":case"striped":case"tuft":{const M=_([[s*.6,b*.9],[s+.35*d,b*.85],[s+.58*d,b*.4],[s+.5*d,-.02*d]]);if(R.push(...N(M,.14*d,y.body)),t.tail==="tuft"){const P=M[M.length-1];R.push(A({k:"circle",x:P.x,y:P.y,r:.16*d,fill:(a=(i=t.extraColors)==null?void 0:i[0])!=null?a:y.accent},T))}if(t.tail==="striped"){for(const z of[.35,.6,.85]){const U=v(s+.35*d+.22999999999999998*d*(z*1.4>1?1:z*1.4),b*(.85-.85*z));R.push({k:"line",pts:[U.x-x.x*.08*d,U.y-x.y*.08*d,U.x+x.x*.08*d,U.y+x.y*.08*d],stroke:(r=(o=t.extraColors)==null?void 0:o[0])!=null?r:y.outline,lw:.06*d})}const P=M[M.length-1];R.push({k:"circle",x:P.x,y:P.y,r:.07*d,fill:(l=(h=t.extraColors)==null?void 0:h[0])!=null?l:y.outline})}break}case"curl":{const M=_([[s*.6,b*.9],[s+.4*d,b*.88],[s+.62*d,b*.45],[s+.5*d,b*.12],[s+.3*d,b*.24],[s+.36*d,b*.42]]);R.push(...N(M,.12*d,y.limbs));break}case"fish":{const M=_([[s*.6,b*.9],[s+.36*d,b*.86],[s+.6*d,b*.5]]);R.push(...N(M,.17*d,y.body));const P=M[M.length-1],z=pt([{x:0,y:.06},{x:-.26,y:-.34},{x:.02,y:-.12},{x:.32,y:-.3}],.2);R.push({k:"group",x:P.x,y:P.y,rot:e.angle+.35,s:d,items:[{k:"path",d:z,fill:y.body,stroke:y.outline,lw:n/d}]});break}case"plume":{const M=(c=t.extraColors)!=null?c:[y.accent];[0,1,2].forEach(P=>{const z=v(s+(.12+P*.13)*d,b+(.32-P*.06)*d);R.push(A({k:"ellipse",x:z.x,y:z.y,rx:.11*d,ry:.44*d,rot:e.angle-.55+P*.28,fill:M[(P+1)%M.length]},T))});break}case"thick":{const M=_([[s*.3,b*.42],[s+.42*d,b*.62],[s+.92*d,b*.96],[s+1.32*d,b*1.08],[s+1.44*d,b*.98],[s+.98*d,b*1.2],[s+.4*d,b*1.22],[s*.3,b*1.12]]);R.push(A({k:"path",d:dt(M,.8),fill:y.body},T));const P=(u=(f=t.extraColors)==null?void 0:f[0])!=null?u:y.accent;for(const[z,U,G]of[[.28,.58,.26],[.62,.8,.22],[.96,1,.16]]){const O=v(s+z*d,b*U+.03*d),X=v(s+(z-.1)*d,b*U+G*d);R.push({k:"line",pts:[O.x,O.y,X.x,X.y],stroke:P,lw:.09*d})}break}case"spiky":case"arrow":{const M=_([[s*.3,b*.55],[s+.35*d,b*.68],[s+.95*d,b*.86],[s+.35*d,b*1.08],[s*.3,b*1.08]]);if(t.tail==="spiky"){for(const P of[.15,.45,.72]){const z=s+(.2+P*.7)*d,U=b*(.66+P*.19);R.push(A({k:"path",d:pt(_([[z-.12*d,U+.05*d],[z,U-.2*d],[z+.12*d,U+.07*d]]),.2),fill:y.accent},T))}R.push(A({k:"path",d:dt(M,.7),fill:y.body},T))}else{const P=_([[s*.6,b*.9],[s+.4*d,b*.92],[s+.62*d,b*.5],[s+.62*d,b*.18]]);R.push(...N(P,.13*d,y.body));const z=P[P.length-1];R.push({k:"group",x:z.x,y:z.y,rot:e.angle,s:d,items:[{k:"path",d:pt([{x:-.15,y:.04},{x:0,y:-.22},{x:.15,y:.04}],.2),fill:y.accent,stroke:y.outline,lw:n/d}]})}break}}return R}function Wr(t,e,s,n,i){const a=t.palette,o=xt(e,ht(s,-.08*n)),r=xt(e,ht(s,.52*n)),h=.2*n;return[{k:"line",pts:[o.x,o.y,r.x,r.y],stroke:a.outline,lw:.06*n+i*2},{k:"line",pts:[o.x,o.y,r.x,r.y],stroke:"#fff3d6",lw:.06*n},{k:"circle",x:r.x,y:r.y,r:.24*n,fill:a.accent,alpha:.28},{k:"group",x:r.x,y:r.y,rot:Math.atan2(s.y,s.x)+Math.PI/2,s:h,items:[{k:"path",d:Ye,fill:a.accent,stroke:a.outline,lw:i*.9/h}]}]}function jr(t,e,s,n,i){var a,o;const r=t.palette,h=(o=(a=t.extraColors)==null?void 0:a[0])!=null?o:"#cdeeff",l=[];for(const c of[-1,1]){const f=[[[c*s*.3,.12*n],[c*(s+.42*n),-.66*n],[c*(s+1*n),-.74*n],[c*(s+1.02*n),-.18*n],[c*(s+.5*n),.26*n]],[[c*s*.4,.3*n],[c*(s+.6*n),.36*n],[c*(s+.74*n),.78*n],[c*(s+.3*n),.9*n]]];for(const u of f){const y=dt(u.map(([x,g])=>e(x,g)),.9);l.push({k:"path",d:y,fill:h,alpha:.6}),l.push({k:"path",d:y,stroke:r.outline,lw:i*.9});const d=u[Math.floor(u.length/2)],b=e(u[0][0],u[0][1]),m=e(u[0][0]+(d[0]-u[0][0])*.75,u[0][1]+(d[1]-u[0][1])*.75);l.push({k:"line",pts:[b.x,b.y,m.x,m.y],stroke:"#ffffff",lw:i*.9,alpha:.85})}for(const[u,y,d]of[[s+.72*n,-.42*n,.075*n],[s+.44*n,-.16*n,.05*n],[s+.5*n,.6*n,.055*n]]){const b=e(c*u,y);l.push({k:"group",x:b.x,y:b.y,s:d,items:[{k:"path",d:Ye,fill:"#ffffff"}]})}}return l}function Yr(t,e,s,n,i,a,o,r,h,l){var c,f;const u=t.palette,y=(f=(c=t.extraColors)==null?void 0:c[1])!=null?f:u.belly,d=[],b=Math.atan2(e(1,0).y-e(0,0).y,e(1,0).x-e(0,0).x),m=5,x=Math.max(n,i*.92)*1.08,g=(a*.8+o)/2,v=[0,4,1,3,2];for(const T of v){const N=T/(m-1)-.5,R=e(N*2*x,g+(.5-Math.abs(N))*.1*r);d.push({k:"ellipse",x:R.x,y:R.y,rx:x*.3,ry:.34*r,rot:b-N*.6,fill:T%2?y:u.body,stroke:u.outline,lw:h})}const _=Math.max(.04,l.head*(1-l.neck)-.04)*r;for(const T of[-1,1,0]){const N=e(T*s*.32,_+(T?0:.05*r));d.push({k:"ellipse",x:N.x,y:N.y,rx:s*.26,ry:.12*r,rot:b+T*.5,fill:T?y:u.body,stroke:u.outline,lw:h*.9})}return d}var Qr={nose:[0,-.62],leftShoulder:[-.42,0],rightShoulder:[.42,0],leftElbow:[-.58,.5],rightElbow:[.58,.5],leftWrist:[-.66,.98],rightWrist:[.66,.98],leftHip:[-.27,1],rightHip:[.27,1],leftKnee:[-.31,1.6],rightKnee:[.31,1.6],leftAnkle:[-.33,2.18],rightAnkle:[.33,2.18]};function Vr(t,{cx:e=.5,cy:s=.36,T:n=.18}={}){var i;const a=A(A({},Qr),t),o=new Array(ti*3).fill(0),r=(c,[f,u],y=.99)=>{o[c*3]=e+f*n,o[c*3+1]=s+u*n,o[c*3+2]=y};for(const c of Object.keys(J))r(J[c],a[c]);const h=(i=a.tilt)!=null?i:0,l=(c,f)=>[a.nose[0]+c*Math.cos(h)-f*Math.sin(h),a.nose[1]+c*Math.sin(h)+f*Math.cos(h)];return r(be.leftEye,l(-.1,-.08)),r(be.rightEye,l(.1,-.08)),r(be.leftEar,l(-.22,-.02)),r(be.rightEar,l(.22,-.02)),o}var Kr=()=>Vr({}),vi=.5,Zr=.15,Jr=Object.freeze({lag:.5,extrapolate:.75,maxExtrapolateMs:50}),ki=class{constructor(t={}){p(this,"tracks",new Map),p(this,"offset",NaN),p(this,"lastArrival",NaN),p(this,"interval",33),p(this,"lastT",NaN),p(this,"lostMs"),p(this,"maxExtrapolateMs"),p(this,"lag"),p(this,"extrapolate");var e,s;this.lostMs=(e=t.lostMs)!=null?e:250,this.maxExtrapolateMs=(s=t.maxExtrapolateMs)!=null?s:25,this.lag=_i(t.lag,1),this.extrapolate=_i(t.extrapolate,.5)}get delayMs(){return this.interval*this.lag}push(t,e,s,n=wi()){Number.isFinite(e)||(e=n),this.clock(e,n);const i=this.tracks.get(t);if(!i||e-i.tb>this.lostMs||e<i.tb-this.lostMs||s.length!==i.b.length){this.tracks.set(t,{a:null,ta:e,b:s,tb:e,out:null,outAt:NaN});return}if(s===i.b||e<=i.tb){e===i.tb&&s!==i.b&&(i.b=s,i.out=null);return}i.a=i.b,i.ta=i.tb,i.b=s,i.tb=e,i.out=null}at(t,e=wi()){const s=this.tracks.get(t);if(!s)return null;if(!s.a)return s.b;if(s.out&&s.outAt===e)return s.out;const n=e-this.offset-this.interval*this.lag,i=s.tb-s.ta,a=Math.min(i*this.extrapolate,this.maxExtrapolateMs),o=Math.min(Math.max((n-s.ta)/i,0),1+a/i);return s.out=$r(s.a,s.b,o),s.outAt=e,s.out}forget(t){this.tracks.delete(t)}clear(){this.tracks.clear()}clock(t,e){const s=e-t;if(!Number.isFinite(this.offset)||s<this.offset||s>this.offset+1e3?this.offset=s:Number.isFinite(this.lastArrival)&&(this.offset+=Math.min(s-this.offset,(e-this.lastArrival)/1e3)),this.lastArrival=e,Number.isFinite(this.lastT)&&t>this.lastT){const n=t-this.lastT;n<this.interval*3+20&&(this.interval+=(Math.min(Math.max(n,8),100)-this.interval)*.1)}t<=this.lastT||(this.lastT=t)}},wi=()=>{var t,e;return(e=(t=le.performance)==null?void 0:t.now())!=null?e:Date.now()},_i=(t,e)=>typeof t=="number"&&Number.isFinite(t)?Math.min(Math.max(t,0),1):e;function $r(t,e,s){const n=e.slice(),i=s<.5?t:e;for(let a=0;a+2<e.length;a+=3){const o=t[a],r=t[a+1],h=e[a],l=e[a+1];t[a+2]>=vi&&e[a+2]>=vi&&Math.abs(h-o)+Math.abs(l-r)<Zr?(n[a]=o+(h-o)*s,n[a+1]=r+(l-r)*s,n[a+2]=t[a+2]+(e[a+2]-t[a+2])*Math.min(s,1)):(n[a]=i[a],n[a+1]=i[a+1],n[a+2]=i[a+2])}return n}var Mc=oi.map(t=>t.id),Ns=new Map(oi.map(t=>[t.id,t])),ls=Ns.get("fox"),to=t=>typeof t=="string"&&Ns.has(t),Is=t=>Ns.get(t),eo=t=>{var e;return typeof t=="string"?(e=Ns.get(t))!=null?e:ls:t};function so(t,e,s){const n=eo(t),i=Kr(),a=di(n,s),o=dn(i,{x:0,y:0,w:1,h:1},{band:a}),r=Ei(fi(n,.05)),h=-r.minY,l=Math.min(.27,.43/Math.max(h,1))*e,c=n.head==="snout-long"?(r.minX+r.maxX)/2*l:0,f=l/Pe[a].head/o.U,u=.5*e+Math.min(0,(h-1.6)*.06*e),y={x:e/2-c-o.head.x*f,y:u-o.head.y*f,w:f,h:f};return bi(i,n,y,{portrait:!0,band:a})}function no(t,e,s=.5){if(!t||t.length!==e.length)return e.slice();const n=e.slice();for(let i=0;i+2<e.length;i+=3){const a=t[i+2],o=e[i+2],r=a>=.5,h=o>=.5;r&&o>=.3&&(n[i+2]=Math.max(o,.5));const l=Math.hypot(e[i]-t[i],e[i+1]-t[i+1]);if(r&&h&&l<.15){const c=s*Math.min(1,Mi+(1-Mi)*l/ao);n[i]=t[i]+(e[i]-t[i])*c,n[i+1]=t[i+1]+(e[i+1]-t[i+1])*c}else r&&!h&&n[i+2]>=.5&&(n[i]=t[i],n[i+1]=t[i+1])}return lo(t,e,n,s*ro),n}var io=.8,Mi=.1,ao=.03,ro=.35,oo=11;function lo(t,e,s,n){const i=J.leftShoulder*3,a=J.rightShoulder*3,o=(f,u)=>f[u+2]>=.5;if(!o(t,i)||!o(t,a)||!o(e,i)||!o(e,a))return;const r=(f,u)=>(f[i+u]+f[a+u])/2,h=[r(t,0),r(t,1)],l=[r(e,0),r(e,1)],c=[r(s,0),r(s,1)];for(let f=0;f<oo&&f*3+2<e.length;f++){const u=f*3;if(!o(t,u)||!o(e,u))continue;const y=[t[u]-h[0],t[u+1]-h[1]],d=[e[u]-l[0],e[u+1]-l[1]];Math.hypot(d[0]-y[0],d[1]-y[1])>=.15||(s[u]=c[0]+y[0]+(d[0]-y[0])*n,s[u+1]=c[1]+y[1]+(d[1]-y[1])*n)}}function Ei(t){var e,s,n,i;const a={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},o=(r,h)=>{a.minX=Math.min(a.minX,r),a.minY=Math.min(a.minY,h),a.maxX=Math.max(a.maxX,r),a.maxY=Math.max(a.maxY,h)};for(const r of t){const h="lw"in r&&r.stroke?((e=r.lw)!=null?e:1)/2:0;switch(r.k){case"circle":o(r.x-r.r-h,r.y-r.r-h),o(r.x+r.r+h,r.y+r.r+h);break;case"ellipse":case"rect":{const l=r.k==="ellipse"?r.rx:r.w/2,c=r.k==="ellipse"?r.ry:r.h/2,f=Math.max(l,c)+h;o(r.x-f,r.y-f),o(r.x+f,r.y+f);break}case"path":{const l=br(r.d);for(let c=0;c+1<l.length;c+=2)o(l[c]-h,l[c+1]-h),o(l[c]+h,l[c+1]+h);break}case"line":for(let l=0;l+1<r.pts.length;l+=2)o(r.pts[l]-h,r.pts[l+1]-h),o(r.pts[l]+h,r.pts[l+1]+h);break;case"group":{const l=Ei(r.items);if(!Number.isFinite(l.minX))break;const c=(s=r.s)!=null?s:1,f=Math.cos((n=r.rot)!=null?n:0),u=Math.sin((i=r.rot)!=null?i:0);for(const[y,d]of[[l.minX,l.minY],[l.maxX,l.minY],[l.minX,l.maxY],[l.maxX,l.maxY]])o(r.x+(y*f-d*u)*c,r.y+(y*u+d*f)*c);break}}}return a}var Qe=()=>Float64Array.of(1,0,0,1,0,0);function ce(t,e,s,n,i,a,o){const r=i?Math.cos(i):1,h=i?Math.sin(i):0,l=r*a,c=h*a,f=-h*o,u=r*o;if(!e)return t[0]=l,t[1]=c,t[2]=f,t[3]=u,t[4]=s,t[5]=n,t;const y=e[0],d=e[1],b=e[2],m=e[3];return t[0]=y*l+b*c,t[1]=d*l+m*c,t[2]=y*f+b*u,t[3]=d*f+m*u,t[4]=y*s+b*n+e[4],t[5]=d*s+m*n+e[5],t}function co(t,e,s){const n=t[0]*t[3]-t[1]*t[2];if(Math.abs(n)<1e-12)return null;const i=e-t[4],a=s-t[5];return[(t[3]*i-t[2]*a)/n,(-t[1]*i+t[0]*a)/n]}var Ai={white:16777215,black:0,red:16711680,transparent:0},cs=new Map;function ne(t){var e,s;if(typeof t=="number")return[t&16777215,1];const n=cs.get(t);if(n)return n;let i=[16777215,1];const a=t.trim().toLowerCase();if(a[0]==="#"){const o=a.slice(1),r=o.length<=4?[...o].map(l=>l+l).join(""):o,h=parseInt(r.slice(0,6),16);Number.isFinite(h)&&(i=[h,r.length===8?parseInt(r.slice(6,8),16)/255:1])}else if(a.startsWith("rgb")){const o=(s=(e=a.match(/-?\d*\.?\d+%?/g))==null?void 0:e.map(f=>f.endsWith("%")?parseFloat(f)/100*255:parseFloat(f)))!=null?s:[],[r=255,h=255,l=255]=o,c=o[3]===void 0?1:a.match(/,\s*[\d.]+%\s*\)$/)?o[3]/255:o[3];i=[(pn(r)<<16|pn(h)<<8|pn(l))>>>0,Math.min(Math.max(c,0),1)]}else if(a in Ai)i=[Ai[a],a==="transparent"?0:1];else if(typeof document!="undefined"){const o=document.createElement("canvas").getContext("2d");if(o){o.fillStyle="#ffffff",o.fillStyle=a;const r=o.fillStyle;if(r!==a)return cs.set(t,i=ne(r)),i}}return cs.size>512&&cs.clear(),cs.set(t,i),i}var pn=t=>Math.min(Math.max(Math.round(t),0),255);function Ve(t,e,s=!1){const n=Math.min(Math.max(e,0),1),i=(t>>16&255)*n,a=(t>>8&255)*n,o=(t&255)*n,r=s?0:n*255;return(Math.round(r)<<24|Math.round(o)<<16|Math.round(a)<<8|Math.round(i))>>>0}var hs=(t,e=1)=>"rgba(".concat(t>>16&255,",").concat(t>>8&255,",").concat(t&255,",").concat(e,")");function Si(t,e){if(t===16777215)return e;if(e===16777215)return t;const s=n=>Math.round((t>>n&255)*(e>>n&255)/255);return(s(16)<<16|s(8)<<8|s(0))>>>0}var fs={linear:t=>t,quadIn:t=>t*t,quadOut:t=>t*(2-t),quadInOut:t=>t<.5?2*t*t:-1+(4-2*t)*t,cubicOut:t=>1-qe(1-t,3),sineInOut:t=>-(Math.cos(Math.PI*t)-1)/2,backOut:t=>1+(1.70158+1)*qe(t-1,3)+1.70158*qe(t-1,2),elasticOut:t=>t===0||t===1?t:qe(2,-10*t)*Math.sin((t*10-.75)*(2*Math.PI/3))+1,bounceOut:t=>t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375};function ho(t){let e=t>>>0;return()=>{e=e+1831565813>>>0;let s=e;return s=Math.imul(s^s>>>15,s|1),s^=s+Math.imul(s^s>>>7,s|61),((s^s>>>14)>>>0)/4294967296}}var us=1,Ti=2,Os=0,te=1,fo=4294967295,F={cap:0,epoch:0,x:new Float64Array(0),y:new Float64Array(0),rot:new Float64Array(0),sx:new Float64Array(0),sy:new Float64Array(0),alpha:new Float64Array(0),la:new Float64Array(0),lb:new Float64Array(0),lc:new Float64Array(0),ld:new Float64Array(0),world:new Float64Array(0),tint:new Uint32Array(0),flags:new Uint8Array(0),moved:new Uint8Array(0),dirty:new Uint8Array(0),gen:new Uint32Array(0),parent:new Int32Array(0),first:new Int32Array(0),next:new Int32Array(0),prev:new Int32Array(0),stamp:new Uint32Array(0),pass:0,free:new Int32Array(0),freeHead:0,freeCount:0,top:2},ge=[],uo="x y rot sx sy alpha la lb lc ld world tint flags moved dirty gen parent first next prev stamp".split(" ");function Ci(t){const e=F;for(const n of uo){const i=e[n],a=new i.constructor(n==="world"?t*6:t);a.set(i),e[n]=a}const s=new Int32Array(t);for(let n=0;n<F.freeCount;n++)s[n]=F.free[(F.freeHead+n)%F.cap];for(F.free=s,F.freeHead=0,F.cap=t,F.epoch++;ge.length<t;)ge.push(null)}function yn(t){F.x[t]=F.y[t]=F.rot[t]=0,F.sx[t]=F.sy[t]=F.alpha[t]=1,F.la[t]=F.ld[t]=1,F.lb[t]=F.lc[t]=0;const e=t*6,s=F.world;s[e]=s[e+3]=1,s[e+1]=s[e+2]=s[e+4]=s[e+5]=0,F.tint[t]=16777215,F.flags[t]=us|Ti,F.moved[t]=1,F.dirty[t]=0,F.parent[t]=F.first[t]=F.next[t]=F.prev[t]=-1}Ci(256),yn(Os),F.flags[Os]=0,yn(te),F.flags[te]=0;function po(){let t;if(F.freeCount){t=F.free[F.freeHead],F.freeHead=(F.freeHead+1)%F.cap,F.freeCount--;const e=ge[t];e&&(e._i=Os,e._g=-1,ge[t]=null)}else F.top===F.cap&&Ci(F.cap*2),t=F.top++;return yn(t),t}function Ri(t,e){mn(t);for(let n=F.first[t];n>=0;){const i=F.next[n];F.parent[n]=F.next[n]=F.prev[n]=-1,n=i}F.first[t]=-1,F.flags[t]=F.flags[t]&~Ti,F.moved[t]=0;const s=F.gen[t]+1;F.gen[t]=s,s!==fo&&(e&&(ge[t]=e),F.free[(F.freeHead+F.freeCount)%F.cap]=t,F.freeCount++)}function yo(t){for(let e=0;e<ge.length;e++){const s=ge[e];s&&t(s)&&(s._i=Os,s._g=-1,ge[e]=null)}}function mo(t,e){mn(t);const s=F.first[e];F.parent[t]=e,F.next[t]=s,F.prev[t]=-1,s>=0&&(F.prev[s]=t),F.first[e]=t,F.moved[t]=1}function mn(t){const e=F.parent[t];if(e<0)return;const s=F.next[t],n=F.prev[t];n>=0?F.next[n]=s:F.first[e]=s,s>=0&&(F.prev[s]=n),F.parent[t]=F.next[t]=F.prev[t]=-1}var ds={root:-1,gen:-1,world:new Float64Array(6)};function xo(t){const e=++F.pass,s=F.world,n=t*6,i=ds.world;let a=ds.root!==t||ds.gen!==F.gen[t];for(let o=0;o<6;o++)i[o]!==s[n+o]&&(a=!0),i[o]=s[n+o];ds.root=t,ds.gen=F.gen[t],F.stamp[t]=a?e:e-1}function bo(t){F.stamp[t]=F.pass}function Fi(t){for(let e=F.first[t];e>=0;){const s=F.next[e];Fi(e),e=s}Ri(t)}var xn=typeof FinalizationRegistry=="function"?new FinalizationRegistry(t=>F.gen[t.i]===t.g&&Fi(t.i)):null;function Pi(t){t._reg||!xn||(t._reg=!0,xn.register(t,{i:t._i,g:t._g},t))}function go(t){t._reg&&xn.unregister(t)}var bn=1,gn=2,vn=3,kn=4;function wn(t){if(t){for(let e=0;e<t.length;e++)if(t[e].enabled)return!0}return!1}function vo(t,e){let s=0;for(let n=0;n<t.length;n++){const i=t[n];i.enabled&&i.pad&&(s+=i.pad(e))}return s}var ie={gl:null,c2d:null,live:null},ft=new Float64Array(3),_n=4,ko=1,Mn=()=>ko++,Et=Qe(),D=F,Ne=class{constructor(t){p(this,"kernel",t),p(this,"_i",po()),p(this,"_g",D.gen[this._i]),p(this,"_wv",null),p(this,"_wi",-1),p(this,"_we",-1),p(this,"blend","normal"),p(this,"_data",null),p(this,"parent",null),p(this,"hitRadius",null),p(this,"clip",null),p(this,"mask",null),p(this,"filters",null),p(this,"_z",0),p(this,"anchorX",0),p(this,"anchorY",0),p(this,"_pool",null),p(this,"_free",!1),p(this,"_reg",!1)}get x(){return D.x[this._i]}set x(t){const e=this._i||te;D.x[e]=t,D.moved[e]=1}get y(){return D.y[this._i]}set y(t){const e=this._i||te;D.y[e]=t,D.moved[e]=1}get rotation(){return D.rot[this._i]}set rotation(t){const e=this._i||te;D.rot[e]=t,D.dirty[e]=D.moved[e]=1}get scaleX(){return D.sx[this._i]}set scaleX(t){const e=this._i||te;D.sx[e]=t,D.dirty[e]=D.moved[e]=1}get scaleY(){return D.sy[this._i]}set scaleY(t){const e=this._i||te;D.sy[e]=t,D.dirty[e]=D.moved[e]=1}get alpha(){return D.alpha[this._i]}set alpha(t){const e=this._i||te;D.alpha[e]=t,D.moved[e]=1}get visible(){return(D.flags[this._i]&us)!==0}set visible(t){const e=this._i||te;t?D.flags[e]=D.flags[e]|us:D.flags[e]=D.flags[e]&~us,D.moved[e]=1}get destroyed(){return D.gen[this._i]!==this._g}get world(){const t=this._i||te;return(this._wi!==t||this._we!==D.epoch)&&(this._wv=D.world.subarray(t*6,t*6+6),this._wi=t,this._we=D.epoch),this._wv}get data(){var t;return(t=this._data)!=null?t:this._data={}}set data(t){this._data=t}get scale(){return this.scaleX}set scale(t){this.scaleX=this.scaleY=t}get z(){return this._z}set z(t){t!==this._z&&(this._z=t,this.parent&&(this.parent.sortDirty=!0))}get tint(){return D.tint[this._i]}set tint(t){D.tint[this._i||te]=typeof t=="number"?t&16777215:ne(t)[0]}set anchor(t){typeof t=="number"?this.anchorX=this.anchorY=t:(this.anchorX=t.x,this.anchorY=t.y)}get width(){return 0}set width(t){}get height(){return 0}set height(t){}set(t){for(const e in t){const s=t[e];s!==void 0&&(this[e]=s)}return this}destroy(){var t;this.destroyed||(this.visible=!1,this.parent&&(this.parent.dead=!0,this.parent=null),Ri(this._i,this),go(this),this.kernel.tweens.stopAll(this),(t=this._pool)==null||t.forget(this))}updateWorld(){const t=this.parent?this.parent.updateWorld():null;return ce(this.world,t,this.x,this.y,this.rotation,this.scaleX,this.scaleY)}draw(t,e,s){}};function wo(t){yo(e=>e.kernel===t)}var En=!1,Li=Object.freeze([]),An=class qa extends Ne{constructor(e){super(e),p(this,"children",Li),p(this,"sortDirty",!1),p(this,"dead",!1),Pi(this)}add(e,...s){this.adopt(e);for(let n=0;n<s.length;n++)this.adopt(s[n]);return e}adopt(e){e.parent&&e.parent.detach(e),e.parent=this,!e.destroyed&&!this.destroyed&&mo(e._i,this._i),this.children===Li&&(this.children=[]),this.children.push(e),(e.z!==0||this.sortDirty)&&(this.sortDirty=!0)}remove(e){this.detach(e),e._pool||Pi(e)}detach(e){const s=this.children,n=s.indexOf(e);if(n>=0){for(let i=n+1;i<s.length;i++)s[i-1]=s[i];s.pop()}e.parent===this&&(e.parent=null,e.destroyed||mn(e._i))}clear(){for(const e of this.children)e.destroy()}destroy(){for(const e of this.children)e.destroy();super.destroy()}sweep(){if(this.dead){this.dead=!1;let e=0;for(const s of this.children)s.destroyed?s.parent===this&&(s.parent=null):this.children[e++]=s;this.children.length=e}for(const e of this.children)e instanceof qa&&e.sweep()}draw(e,s,n){if(En)return D.parent[this._i]<0&&!this.destroyed&&bo(this._i),this.drawChildren(e,s,n);En=!0;try{this.destroyed||xo(this._i),this.drawChildren(e,s,n)}finally{En=!1}}drawChildren(e,s,n){if(this.sortDirty){const r=new Map(this.children.map((h,l)=>[h,l]));this.children.sort((h,l)=>h.z-l.z||r.get(h)-r.get(l)),this.sortDirty=!1}const i=this.children,a=this._i,o=D.stamp[a]===D.pass;for(let r=0;r<i.length;r++){const h=i[r],l=h._i,c=D.alpha[l];if(D.gen[l]!==h._g||!(D.flags[l]&us)||c<=0)continue;if(o||D.moved[l]){D.moved[l]=0,D.stamp[l]=D.pass;let y,d,b,m;if(D.dirty[l]){D.dirty[l]=0;const z=D.rot[l],U=z?Math.cos(z):1,G=z?Math.sin(z):0,O=D.sx[l],X=D.sy[l];D.la[l]=y=U*O,D.lb[l]=d=G*O,D.lc[l]=b=-G*X,D.ld[l]=m=U*X}else y=D.la[l],d=D.lb[l],b=D.lc[l],m=D.ld[l];const x=D.world,g=D.x[l],v=D.y[l],_=l*6,T=a*6,N=x[T],R=x[T+1],M=x[T+2],P=x[T+3];x[_]=N*y+M*d,x[_+1]=R*y+P*d,x[_+2]=N*b+M*m,x[_+3]=R*b+P*m,x[_+4]=N*g+M*v+x[T+4],x[_+5]=R*g+P*v+x[T+5]}const f=s*c,u=Si(n,D.tint[l]);h.clip||h.mask||h.filters?Ii(e,h,f,u):h.draw(e,f,u)}}},It=new Float64Array(128),Ie=0,Sn=new Float64Array(8);function Ni(t,e,s,n){e.clip||e.mask||e.filters?Ii(t,e,s,n):e.draw(t,s,n)}function Ii(t,e,s,n){const i=t.r,a=e.world,o=e.clip;let r=!1,h=!1;if(o)if(Math.abs(a[1])<1e-9&&Math.abs(a[2])<1e-9&&Ie<32){const f=a[0]*o.x+a[4],u=a[0]*(o.x+o.width)+a[4],y=a[3]*o.y+a[5],d=a[3]*(o.y+o.height)+a[5];let b=Math.min(f,u),m=Math.max(f,u),x=Math.min(y,d),g=Math.max(y,d);if(Ie){const _=(Ie-1)*4;b=Math.max(b,It[_]),x=Math.max(x,It[_+1]),m=Math.min(m,It[_+2]),g=Math.min(g,It[_+3])}const v=Ie++*4;It[v]=b,It[v+1]=x,It[v+2]=m,It[v+3]=g,i.clip(b,x,Math.max(m-b,0),Math.max(g-x,0)),h=!0}else r=!0;const l=e.mask&&e.mask.visible?e.mask:null,c=wn(e.filters)?e.filters:null;try{if(r&&i.beginLayer(),l&&i.beginLayer(),c?(e.draw(t,i.beginLayer()?1:s,n),i.endLayer(s,c)):e.draw(t,s,n),l&&(i.beginMask(),ce(l.world,a,l.x,l.y,l.rotation,l.scaleX,l.scaleY),Ni(t,l,l.alpha,16777215),i.endLayer(1)),r&&o){i.beginMask();for(let f=0;f<4;f++){const u=f===1||f===2?o.x+o.width:o.x,y=f>1?o.y+o.height:o.y;Sn[f*2]=a[0]*u+a[2]*y+a[4],Sn[f*2+1]=a[1]*u+a[3]*y+a[5]}i.polygon(Sn,4,16777215,1),i.endLayer(1)}}finally{if(h)if(Ie--,Ie){const f=(Ie-1)*4;i.clip(It[f],It[f+1],It[f+2]-It[f],It[f+3]-It[f+1])}else i.unclip()}}var Ke=class extends Ne{constructor(t,e,s){super(t),p(this,"_frame",null),p(this,"_w",null),p(this,"_h",null),p(this,"slice",0),p(this,"autoAnchor",!0),p(this,"frameName",null),e&&(this.frame=e),(s==null?void 0:s.anchor)===void 0&&this.useFrameAnchor(),s&&this.set(s)}get frame(){return this._frame}set frame(t){this.frameName=typeof t=="string"?t:null,this._frame=typeof t=="string"?this.kernel.frame(t):t,this.autoAnchor&&this.useFrameAnchor()}set anchor(t){this.autoAnchor=!1,super.anchor=t}get naturalWidth(){var t;const e=this.frameNow();return e?((t=e.sw)!=null?t:e.w)/e.scale-e.margin*2:0}get naturalHeight(){var t;const e=this.frameNow();return e?((t=e.sh)!=null?t:e.h)/e.scale-e.margin*2:0}get width(){var t;return(t=this._w)!=null?t:this.naturalWidth}set width(t){this._w=t}get height(){var t;return(t=this._h)!=null?t:this.naturalHeight}set height(t){this._h=t}sizeQ(t){var e,s,n,i;$e[0]=(s=this._w)!=null?s:((e=t.sw)!=null?e:t.w)/t.scale-t.margin*2,$e[1]=(i=this._h)!=null?i:((n=t.sh)!=null?n:t.h)/t.scale-t.margin*2}frameNow(){return this.frameName&&!this.kernel.atlas.valid(this._frame)&&(this._frame=this.kernel.frame(this.frameName)),this._frame}useFrameAnchor(){var t,e;const s=this._frame;if(!s)return;const n=((t=s.sw)!=null?t:s.w)/s.scale-s.margin*2,i=((e=s.sh)!=null?e:s.h)/s.scale-s.margin*2;this.anchorX=n>0?(s.ox-s.margin)/n:0,this.anchorY=i>0?(s.oy-s.margin)/i:0}draw(t,e,s){const n=this.frameNow();if(!n)return;const i=$e;this.sizeQ(n),i[2]=this.anchorX,i[3]=this.anchorY,i[4]=e,_o(t,n,this.world,this.slice,s,this.blend)}},Ze=new Float64Array(12),Je=new Float64Array(12),ps={x:0,y:0,w:0,h:0};function Oi(t,e,s,n,i,a){e=Math.max(e,0),s=Math.max(s,0),n=Math.max(n,0);const o=s+n>i?s*i/(s+n):s,r=s+n>i?n*i/(s+n):n;let h=o/a,l=r/a;if(h+l>e){const c=e/(h+l);h*=c,l*=c}t[0]=0,t[1]=h,t[2]=0,t[3]=o,t[4]=h,t[5]=e-h-l,t[6]=o,t[7]=i-o-r,t[8]=e-l,t[9]=l,t[10]=i-r,t[11]=r}var $e=new Float64Array(5);function _o(t,e,s,n,i,a){var o,r,h,l,c,f,u,y,d,b,m;const x=$e,g=x[0],v=x[1],_=x[2],T=x[3],N=x[4],R=t.tex(e.surface),M=n===0?(o=e.slice)!=null?o:0:n;if(M===0){const L=((r=e.sw)!=null?r:e.w)/e.scale-e.margin*2,lt=((h=e.sh)!=null?h:e.h)/e.scale-e.margin*2,yt=L>0?g/L:1,$=lt>0?v/lt:1,w=-_*g+(((l=e.tx)!=null?l:0)/e.scale-e.margin)*yt,H=-T*v+(((c=e.ty)!=null?c:0)/e.scale-e.margin)*$;zs(s,w,H),ft[0]=e.w/e.scale*yt,ft[1]=e.h/e.scale*$,ft[2]=N,t.r.quadQ(R,e,Et,i,a);return}const P=(f=e.tx)!=null?f:0,z=(u=e.ty)!=null?u:0,U=((y=e.sw)!=null?y:e.w)-e.w-P,G=((d=e.sh)!=null?d:e.h)-e.h-z,O=-_*g-e.margin+P/e.scale,X=-T*v-e.margin+z/e.scale;if(Oi(Ze,g+e.margin*2-(P+U)/e.scale,(typeof M=="number"?M:M[3])-P,(typeof M=="number"?M:M[1])-U,e.w,e.scale),Oi(Je,v+e.margin*2-(z+G)/e.scale,(typeof M=="number"?M:M[0])-z,(typeof M=="number"?M:M[2])-G,e.h,e.scale),zs(s,O,X),ft[2]=N,!((m=(b=t.r).nineQ)!=null&&m.call(b,R,e,Ze,Je,Et,i,a)))for(let L=0;L<12;L+=4){const lt=Je[L+1],yt=Je[L+3];if(!(lt<=0||yt<=0))for(let $=0;$<12;$+=4){const w=Ze[$+1],H=Ze[$+3];w<=0||H<=0||(ps.x=e.x+Ze[$+2],ps.y=e.y+Je[L+2],ps.w=H,ps.h=yt,zs(s,O+Ze[$],X+Je[L]),ft[0]=w,ft[1]=lt,ft[2]=N,t.r.quadQ(R,ps,Et,i,a))}}}function zs(t,e,s){Et[0]=t[0],Et[1]=t[1],Et[2]=t[2],Et[3]=t[3],Et[4]=t[0]*e+t[2]*s+t[4],Et[5]=t[1]*e+t[3]*s+t[5]}var ys=class extends Ke{constructor(t,e,s={}){super(t,null),p(this,"_spec"),p(this,"baked",null),p(this,"bakedEffects",!0),this._spec=e,this.bake(),s.anchor===void 0&&this.useFrameAnchor(),this.set(s)}get spec(){return this._spec}set spec(t){this._spec=t,this.baked=null,this._w=this._h=null,this.bake()}bake(){const t=this.kernel;return this.baked&&t.atlas.valid(this.baked.frame)&&this.baked.frame.scale===t.pixelScale&&this.bakedEffects===t.effects?this.baked:(this.bakedEffects=t.effects,this.baked=t.shape(this._spec),this._frame=this.baked.frame,this.slice=this.baked.slice,this.autoAnchor&&this.useFrameAnchor(),this.baked)}frameNow(){return this.bake().frame}sizeQ(){var t,e;const s=this.bake();$e[0]=(t=this._w)!=null?t:s.w,$e[1]=(e=this._h)!=null?e:s.h}get width(){var t;return(t=this._w)!=null?t:this.bake().w}set width(t){this._w=t}get height(){var t;return(t=this._h)!=null?t:this.bake().h}set height(t){this._h=t}},zi=(t,e,s)=>t===void 0?e:typeof t=="number"?t:t[0]+(t[1]-t[0])*s(),Di=class As extends Ne{constructor(e,s,n={}){var i,a,o,r;super(e),p(this,"max"),p(this,"f"),p(this,"tints"),p(this,"count",0),p(this,"gravity"),p(this,"drag"),p(this,"frameRef"),p(this,"random",Math.random),this.frameRef=s,this.max=Math.max(1,Math.floor((i=n.max)!=null?i:200)),this.f=new Float32Array(this.max*As.W),this.tints=new Uint32Array(this.max),this.blend=(a=n.blend)!=null?a:"normal",this.gravity=(o=n.gravity)!=null?o:0,this.drag=(r=n.drag)!=null?r:1}get alive(){return this.count}burst(e,s,n,i={}){var a,o,r,h,l;const c=As.W,f=this.random,u=i.tint===void 0?16777215:ne(i.tint)[0];for(let y=0;y<n;y++){let d=this.count;if(d>=this.max){let _=0,T=1/0;for(let N=0;N<this.max;N++){const R=this.f[N*c+5]-this.f[N*c+4];R<T&&(T=R,_=N)}d=_}else this.count++;const b=((a=i.angle)!=null?a:0)+(i.spread===void 0?f()*Math.PI*2:(f()-.5)*i.spread),m=zi(i.speed,200,f),x=Array.isArray(i.scale)?i.scale[0]:(o=i.scale)!=null?o:1,g=Array.isArray(i.scale)?i.scale[1]:(r=i.scale)!=null?r:1,v=d*c;this.f[v]=e,this.f[v+1]=s,this.f[v+2]=Math.cos(b)*m,this.f[v+3]=Math.sin(b)*m,this.f[v+4]=0,this.f[v+5]=Math.max(zi(i.life,.8,f),.01),this.f[v+6]=f()*Math.PI*2,this.f[v+7]=(f()-.5)*2*((h=i.spin)!=null?h:0),this.f[v+8]=x,this.f[v+9]=g,this.f[v+10]=(l=i.alpha)!=null?l:1,this.tints[d]=u}}update(e){const s=As.W,n=this.f,i=this.drag>=1?1:Math.pow(Math.max(this.drag,0),e);for(let a=0;a<this.count;){const o=a*s;if(n[o+4]=n[o+4]+e,n[o+4]>=n[o+5]){const r=--this.count;a!==r&&(n.copyWithin(o,r*s,r*s+s),this.tints[a]=this.tints[r]);continue}n[o+3]=(n[o+3]+this.gravity*e)*i,n[o+2]=n[o+2]*i,n[o]=n[o]+n[o+2]*e,n[o+1]=n[o+1]+n[o+3]*e,n[o+6]=n[o+6]+n[o+7]*e,a++}}clear(){this.count=0}draw(e,s,n){if(!this.count)return;const i=typeof this.frameRef=="string"?this.frameRef=this.kernel.frame(this.frameRef):this.frameRef,a=As.W,o=this.f,r=this.world,h=i.w/i.scale,l=i.h/i.scale;for(let c=0;c<this.count;c++){const f=c*a,u=o[f+4]/o[f+5],y=o[f+8]+(o[f+9]-o[f+8])*u,d=s*o[f+10]*(1-u*u),b=o[f+6],m=Math.cos(b)*y,x=Math.sin(b)*y,g=o[f],v=o[f+1],_=r[0],T=r[1],N=r[2],R=r[3],M=_*m+N*x,P=T*m+R*x,z=N*m-_*x,U=R*m-T*x;Et[0]=M,Et[1]=P,Et[2]=z,Et[3]=U,Et[4]=_*g+N*v+r[4]-(M*h+z*l)/2,Et[5]=T*g+R*v+r[5]-(P*h+U*l)/2,ft[0]=h,ft[1]=l,ft[2]=d,e.r.quadQ(e.tex(i.surface),i,Et,Si(n,this.tints[c]),this.blend)}}};p(Di,"W",11);var Bi=Di,Oe=class extends Ke{constructor(t,e,s={}){const n=s,{fps:i,loop:a,playing:o,speed:r,onComplete:h}=n,l=hn(n,["fps","loop","playing","speed","onComplete"]);if(!e.frames.length)throw new Error("[engine] an animation needs at least one frame");super(t,e.frames[0],l),p(this,"frames"),p(this,"durations"),p(this,"fps"),p(this,"loop"),p(this,"speed"),p(this,"onComplete"),p(this,"_playing"),p(this,"index",0),p(this,"t",0),this.frames=e.frames,this.durations=e.durations&&i===void 0?e.durations:null,this.fps=i!=null?i:12,this.loop=a!==!1,this.speed=r!=null?r:1,this.onComplete=h!=null?h:null,this._playing=o!==!1,this.speed<0&&this.show(e.frames.length-1)}get frameIndex(){return this.index}get frameCount(){return this.frames.length}get playing(){return this._playing}play(){return!this.loop&&!this._playing&&this.index===(this.speed<0?0:this.frames.length-1)&&this.show(this.speed<0?this.frames.length-1:0),this._playing=!0,this}stop(){return this._playing=!1,this}gotoFrame(t){const e=this.frames.length;return this.show((Math.floor(t)%e+e)%e),this.t=0,this}gotoAndPlay(t){return this._playing=!0,this.gotoFrame(t)}gotoAndStop(t){return this._playing=!1,this.gotoFrame(t)}show(t){t===this.index&&this._frame||(this.index=t,this.frame=this.frames[t])}secondsOf(t){var e;const s=(e=this.durations)==null?void 0:e[t];return s!==void 0&&s>0?s:1/Math.max(this.fps,.001)}update(t){var e;if(!this._playing||this.destroyed||this.speed===0)return;const s=this.frames.length,n=this.speed<0;this.t+=t*Math.abs(this.speed);let i=this.index;for(let a=0;a<1e3;a++){const o=this.secondsOf(i);if(this.t<o)break;this.t-=o;const r=n?i-1:i+1;if(r<0||r>=s){if(!this.loop){this.t=0,this._playing=!1,this.show(i),(e=this.onComplete)==null||e.call(this);return}i=n?s-1:0}else i=r}this.show(i)}},Mo=(t,e)=>t.localeCompare(e,void 0,{numeric:!0}),Ui=class{constructor(t,e,s=2){p(this,"width",t),p(this,"height",e),p(this,"padding",s),p(this,"shelves",[]),p(this,"free",[]),p(this,"bottom",0)}alloc(t,e){const s=Math.ceil(t)+this.padding*2,n=Math.ceil(e)+this.padding*2;if(s>this.width||n>this.height)return null;for(let o=0;o<this.free.length;o++){const r=this.free[o];if(r.w>=s&&r.h>=n&&r.w*r.h<=s*n*2)return this.free.splice(o,1),We(A({},this.inner(r.x,r.y,t,e)),{slot:r})}let i=null;for(const o of this.shelves)o.h>=n&&o.h<=n*1.5+8&&this.width-o.x>=s&&(!i||o.h<i.h)&&(i=o);if(!i)if(this.bottom+n>this.height){for(const o of this.shelves)o.h>=n&&this.width-o.x>=s&&(i=o);if(!i)return null}else i={y:this.bottom,h:n,x:0},this.shelves.push(i),this.bottom+=n;const a=i.x;return i.x+=s,this.inner(a,i.y,t,e)}release(t){this.free.push({x:t.x-this.padding,y:t.y-this.padding,w:Math.ceil(t.w)+this.padding*2,h:Math.ceil(t.h)+this.padding*2})}get fill(){return this.bottom/this.height}reset(){this.shelves=[],this.free=[],this.bottom=0}inner(t,e,s,n){return{x:t+this.padding,y:e+this.padding,w:s,h:n}}},Ds=t=>({source:t,texture:null,pending:[]}),Tn=class{constructor(t=2048,e=4){p(this,"pageSize",t),p(this,"maxPages",e),p(this,"pages",[]),p(this,"gen",1),p(this,"onPage",()=>{}),p(this,"onDrop",()=>{})}valid(t){return!!t&&(t.gen===this.gen||t.gen===0)}bake(t,e,s,n=1,i=0,a=0,o=0){const r=Math.max(1,Math.ceil(t)),h=Math.max(1,Math.ceil(e)),l=document.createElement("canvas");l.width=r,l.height=h;const c=l.getContext("2d");return s(c),this.put(l,r,h,n,i,a,o)}add(t,e=1,s=0,n=0){const i=document.createElement("canvas");return i.width=Math.max(1,t.width),i.height=Math.max(1,t.height),i.getContext("2d").drawImage(t,0,0),this.put(i,i.width,i.height,e,s,n,0)}release(t){if(t.gen!==this.gen)return;const e=this.pages.find(s=>s.surface===t.surface);e==null||e.packer.release(t)}rebake(t,e,s,n,i=t.w,a=t.h){if(!this.valid(t)||e>i||s>a)return null;const o=Math.max(1,Math.ceil(e)),r=Math.max(1,Math.ceil(s)),h=this.pages.find(c=>c.surface===t.surface);if(!h)return null;const l=document.createElement("canvas");return l.width=Math.ceil(i),l.height=Math.ceil(a),n(l.getContext("2d")),h.ctx.clearRect(t.x,t.y,l.width,l.height),h.ctx.drawImage(l,t.x,t.y),t.surface.pending.push([l,t.x,t.y]),t.w=o,t.h=r,t}put(t,e,s,n,i,a,o){let r=null,h=this.pages.find(c=>(r=c.packer.alloc(e,s))!==null);if(h||(!(Math.max(e,s)+4>this.pageSize)&&this.pages.length>=this.maxPages&&(this.wipe(),h=this.pages[0],r=h?h.packer.alloc(e,s):null),(!h||!r)&&(h=this.newPage(Math.max(e,s)),r=h.packer.alloc(e,s))),!r)throw new Error("[engine] ".concat(e,"\xD7").concat(s," does not fit an atlas page"));const l=r;if(l.slot){const c=l.slot;h.ctx.clearRect(c.x,c.y,c.w,c.h);const f=document.createElement("canvas");f.width=c.w,f.height=c.h,f.getContext("2d").drawImage(t,l.x-c.x,l.y-c.y),h.surface.pending.push([f,c.x,c.y])}else h.surface.pending.push([t,l.x,l.y]);return h.ctx.drawImage(t,l.x,l.y),{surface:h.surface,x:l.x,y:l.y,w:e,h:s,scale:n,gen:this.gen,ox:i,oy:a,margin:o}}newPage(t){let e=this.pageSize;for(;e<t+4;)e*=2;const s=document.createElement("canvas");s.width=s.height=e;const n=s.getContext("2d"),i=Ds(s),a={surface:i,packer:new Ui(e,e),ctx:n};return this.pages.push(a),this.onPage(i),a}wipe(){this.gen++;let t=0;for(let e=0;e<this.pages.length;e++){const s=this.pages[e];if(t<this.maxPages&&s.surface.source.width===this.pageSize){this.pages[t++]=s;continue}s.surface.pending=[],this.onDrop(s.surface)}this.pages.length=t;for(const e of this.pages)e.packer.reset(),e.ctx.clearRect(0,0,e.surface.source.width,e.surface.source.height),e.surface.pending=[],e.surface.pending.push([e.surface.source,0,0])}},Eo=()=>{var t,e,s;const n=typeof document!="undefined"?(t=document.timeline)==null?void 0:t.currentTime:null;return typeof n=="number"&&Number.isFinite(n)?n:(s=(e=le.performance)==null?void 0:e.now())!=null?s:Date.now()},Hi=()=>{var t,e;return(e=(t=le.performance)==null?void 0:t.now())!=null?e:Date.now()},Ao=class{constructor(t=Eo){p(this,"now",t),p(this,"known",new Map),p(this,"smoothed",new Map),p(this,"times",new WeakMap),p(this,"lerp",new ki),p(this,"amount",Cn),p(this,"drawnAt",NaN),p(this,"drawn",0),p(this,"smoothedBody",(e,s={})=>{var n;const i=s.interpolate!==!1;if(typeof e=="number"){const a=this.smoothed.get(e);return a?i&&(n=this.lerp.at(e,this.tick()))!=null?n:a.body:null}return typeof e!="object"||e===null||!Array.isArray(e.body)?null:this.posed(e.id,e.body,So(s.smooth,this.defaultAmount),i)})}setLocal(t){this.amount=t?io:Cn,this.lerp=new ki(t?Jr:{}),this.smoothed.clear()}get defaultAmount(){return this.amount}note(t,e,s=Hi()){for(const n of t)this.known.set(n.id,this.resolve(n.id,n.avatar)),e!==void 0&&Number.isFinite(e)&&Array.isArray(n.body)&&this.times.set(n.body,{t:e,arrival:s})}of(t){var e;return typeof t=="object"&&t!==null?t.avatar!==void 0?this.resolve(t.id,t.avatar):this.of(t.id):(e=this.known.get(t))!=null?e:si(t-1)}posed(t,e,s,n=!0){var i;const a=this.smooth(t,e,s);return n&&(i=this.lerp.at(t,this.tick()))!=null?i:a}smooth(t,e,s){var n,i;const a=this.smoothed.get(t);if(a&&a.raw===e&&a.amount===s)return a.body;a&&a.amount!==s&&this.lerp.forget(t);const o=s<1?no(a==null?void 0:a.body,e,s):e;this.smoothed.set(t,{raw:e,body:o,amount:s});const r=this.times.get(e),h=(n=r==null?void 0:r.arrival)!=null?n:Hi();return this.lerp.push(t,(i=r==null?void 0:r.t)!=null?i:h,o,h),o}takeDrawn(){const t=this.drawn;return this.drawn=0,t}tick(){const t=this.now();return t!==this.drawnAt&&(this.drawnAt=t,this.drawn++),t}resolve(t,e){return to(e)?e:si(t-1)}},Cn=.5,So=(t,e=Cn)=>t===!1?1:typeof t=="number"?Math.min(Math.max(t,.05),1):e,Gi=new Float64Array(1),Xi=new Int32Array(Gi.buffer),ts=(t,e)=>(t=Math.imul(t^e,1540483477),t^t>>>15);function ve(t,e=2538058380){return t!==t?ts(e,2146959360):(Gi[0]=t===0?0:t,ts(ts(e,Xi[0]),Xi[1]))}function qi(t,e=2166136261){for(let s=0;s<t.length;s++)e=Math.imul(e^t.charCodeAt(s),16777619);return e}function ke(t){switch(typeof t){case"number":return ve(t);case"string":return qi(t);case"boolean":return t?1013904242:461845907;case"object":{if(t===null)return 625341585;if(Array.isArray(t)||t instanceof Float64Array){let n=1779033703^t.length;for(let i=0;i<t.length;i++){const a=t[i];n=ts(n,typeof a=="number"?ve(a):ke(a))}return n}let e=1359893119;const s=t;for(const n in s){const i=s[n];i!==void 0&&(e=e+ts(qi(n),ke(i))|0)}return ts(e,2600822924)}default:return 0}}function ms(t,e){if(t===e)return!0;if(typeof t!="object"||typeof e!="object"||t===null||e===null)return typeof t=="number"&&typeof e=="number"&&t!==t&&e!==e;const s=Array.isArray(t)||t instanceof Float64Array;if(s!==(Array.isArray(e)||e instanceof Float64Array))return!1;if(s){const a=t,o=e;if(a.length!==o.length)return!1;for(let r=0;r<a.length;r++)if(a[r]!==o[r]&&!ms(a[r],o[r]))return!1;return!0}const n=t,i=e;for(const a in n)if(n[a]!==void 0&&!ms(n[a],i[a]))return!1;for(const a in i)if(i[a]!==void 0&&n[a]===void 0)return!1;return!0}function Bs(t){if(typeof t!="object"||t===null)return t;if(Array.isArray(t))return t.map(Bs);if(t instanceof Float64Array)return t.slice();const e={};for(const s in t)t[s]!==void 0&&(e[s]=Bs(t[s]));return e}var Wi=class{constructor(t=1/0){p(this,"max",t),p(this,"buckets",new Map),p(this,"n",0)}get size(){return this.n}get(t,e=ke(t)){const s=this.buckets.get(e);if(s){for(let n=0;n<s.length;n++)if(ms(s[n].key,t))return s[n].value}}set(t,e,s=ke(t)){let n=this.buckets.get(s);if(n){for(const i of n)if(ms(i.key,t)){i.value=e;return}}this.n>=this.max&&this.clear(),(!n||!this.buckets.has(s))&&this.buckets.set(s,n=[]),n.push({key:Bs(t),value:e}),this.n++}clear(){this.buckets.clear(),this.n=0}},Rn=0,ji=1,Us=2,Fn=3,Yi=class{constructor(){p(this,"scale",1),p(this,"cOn",!1),p(this,"px0",0),p(this,"py0",0),p(this,"px1",0),p(this,"py1",0),p(this,"clipVer",0),p(this,"stack",[]),p(this,"sp",0),p(this,"real",0),p(this,"mute",0),p(this,"bnd",new Float64Array(4*(_n+1))),p(this,"rx0",0),p(this,"ry0",0),p(this,"rx1",0),p(this,"ry1",0),p(this,"maxBlur",1/0),p(this,"time",0),p(this,"skipped",0),p(this,"gq",new Float64Array(4))}resetLayers(t){this.scale=t,this.sp=this.real=this.mute=0,this.skipped=0,this.cOn=!1,this.clipVer++}growQ(){const t=this.gq;this.grow(t[0],t[1],t[2],t[3])}grow(t,e,s,n){if(!this.real)return;const i=this.bnd,a=(this.real-1)*4;t<i[a]&&(i[a]=t),e<i[a+1]&&(i[a+1]=e),s>i[a+2]&&(i[a+2]=s),n>i[a+3]&&(i[a+3]=n)}area(t,e){const s=this.bnd,n=t*4,i=this.scale;return this.rx0=Math.max(Math.floor((s[n]-e)*i)-1,0),this.ry0=Math.max(Math.floor((s[n+1]-e)*i)-1,0),this.rx1=Math.min(Math.ceil((s[n+2]+e)*i)+1,this.canvas.width),this.ry1=Math.min(Math.ceil((s[n+3]+e)*i)+1,this.canvas.height),this.rx1>this.rx0&&this.ry1>this.ry0}clip(t,e,s,n){const i=this.scale,a=this.canvas.width,o=this.canvas.height,r=Math.min(Math.max(Math.round(t*i),0),a),h=Math.min(Math.max(Math.round(e*i),0),o),l=Math.min(Math.max(Math.round((t+s)*i),r),a),c=Math.min(Math.max(Math.round((e+n)*i),h),o);this.cOn&&r===this.px0&&h===this.py0&&l===this.px1&&c===this.py1||(this.cOn=!0,this.px0=r,this.py0=h,this.px1=l,this.py1=c,this.clipVer++)}unclip(){this.cOn&&(this.cOn=!1,this.clipVer++)}push(t){if(t<Us&&(this.mute||this.real>=_n||!this.pushLayer())&&(t+=2),t===Fn)this.mute++;else if(t!==Us){const e=this.real*4;this.bnd[e]=this.bnd[e+1]=1/0,this.bnd[e+2]=this.bnd[e+3]=-1/0,this.real++}return this.stack[this.sp++]=t,t<Us}beginLayer(){return this.push(Rn)}beginMask(){this.push(this.sp&&this.stack[this.sp-1]===Rn?ji:Fn)}endLayer(t,e){if(!this.sp)return;let s=this.stack[--this.sp];if(s===Fn){if(this.mute--,!this.sp)return;s=this.stack[--this.sp]}if(s===ji){const n=--this.real,i=this.popLayer();this.area(n-1,0)&&this.composite(i,!0,1,null);const a=this.bnd,o=(n-1)*4,r=n*4;a[o]=Math.max(a[o],a[r]),a[o+1]=Math.max(a[o+1],a[r+1]),a[o+2]=Math.min(a[o+2],a[r+2]),a[o+3]=Math.min(a[o+3],a[r+3]),s=this.stack[--this.sp]}if(s===Us)wn(e)&&(this.skipped+=e.length);else if(s===Rn){const n=--this.real,i=wn(e)?e:null,a=this.popLayer();if(this.area(n,i?vo(i,this.maxBlur):0)){this.composite(a,!1,t,i);const o=this.scale;this.grow(this.rx0/o,this.ry0/o,this.rx1/o,this.ry1/o)}}}closeLayers(){for(;this.sp;)this.endLayer(1)}},To=256,Qi=8<<20,Ht=new Float64Array(32),Gt={x:0,y:0,w:0,h:0};function Co(t){if(typeof t.filter!="string")return!1;t.filter="blur(1px)";const e=t.filter==="blur(1px)";return t.filter="none",e}function Pn(t){const e=t.getContext("2d",{alpha:!0});return e?new Ro(t,e):null}var Ro=class extends Yi{constructor(t,e){super(),p(this,"canvas",t),p(this,"ctx",e),p(this,"kind","canvas2d"),p(this,"maxTextureSize",4096),p(this,"features",{}),p(this,"info",{renderer:"canvas2d"}),p(this,"support"),p(this,"lost",!1),p(this,"fxr",null),p(this,"quads",0),p(this,"stats",{drawCalls:0,quads:0,filtersSkipped:0}),p(this,"tinted",new Map),p(this,"tintedN",0),p(this,"lostListeners",[]),p(this,"restoredListeners",[]),p(this,"base"),p(this,"top"),p(this,"layers",[]),p(this,"scratch",[]),p(this,"nines",new Map),p(this,"ninePx",0),p(this,"frame",0),p(this,"hit",!1),p(this,"missed",new Map),this.support={filters:Co(e),shaders:!1},this.base=this.top={ctx:e,clipped:!1,ver:0},t.addEventListener("contextlost",()=>{this.lost=!0,this.lostListeners.forEach(s=>s())}),t.addEventListener("contextrestored",()=>{this.lost=!1,this.tinted.clear(),this.tintedN=0,this.dropNines(),this.restoredListeners.forEach(s=>s())})}resize(t,e){this.canvas.width!==t&&(this.canvas.width=t),this.canvas.height!==e&&(this.canvas.height=e)}createTexture(t){return{id:Mn(),width:t.width,height:t.height,source:t}}updateTexture(t,e,s=0,n=0){const i=e?s+e.width:1/0,a=e?n+e.height:1/0;for(const o of this.nines.values()){const r=o.key;r[0]===t.id&&r[1]<i&&r[1]+r[3]>s&&r[2]<a&&r[2]+r[4]>n&&this.dropNine(o)}for(const[o,r]of this.tinted){const h=r.filter(l=>l.id!==t.id);this.tintedN-=r.length-h.length,h.length?this.tinted.set(o,h):this.tinted.delete(o)}}destroyTexture(t){this.updateTexture(t)}begin(t,e,s){var n;this.resetLayers(s),(n=this.fxr)==null||n.tick(),this.frame++,this.quads=0,this.top=this.base,this.ctx=this.base.ctx;const i=this.ctx;this.base.clipped&&i.restore(),this.base.clipped=!1,this.base.ver=this.clipVer,i.setTransform(1,0,0,1,0,0),i.globalAlpha=1,i.globalCompositeOperation="source-over",i.clearRect(0,0,this.canvas.width,this.canvas.height),e>0&&(i.fillStyle=hs(t,e),i.fillRect(0,0,this.canvas.width,this.canvas.height))}quad(t,e,s,n,i,a,o,r){ft[0]=n,ft[1]=i,ft[2]=o,this.quadQ(t,e,s,a,r)}quadQ(t,e,s,n,i){e.w<=0||e.h<=0||(n===16777215?this.blit(t.source,e.x,e.y,e.w,e.h,s,i):this.blit(this.tint(t,e,n),0,0,e.w,e.h,s,i))}blit(t,e,s,n,i,a,o){const r=ft[0],h=ft[1],l=ft[2];if(l<=0||this.mute)return;this.sync();const c=this.ctx,f=this.scale;if(this.real){const u=a[0]*r,y=a[1]*r,d=a[2]*h,b=a[3]*h;this.grow(a[4]+Math.min(0,u,d,u+d),a[5]+Math.min(0,y,b,y+b),a[4]+Math.max(0,u,d,u+d),a[5]+Math.max(0,y,b,y+b))}c.setTransform(a[0]*f,a[1]*f,a[2]*f,a[3]*f,a[4]*f,a[5]*f),c.globalAlpha=Math.min(l,1),o==="add"&&(c.globalCompositeOperation="lighter"),c.drawImage(t,e,s,n,i,0,0,r,h),o==="add"&&(c.globalCompositeOperation="source-over"),this.quads++}nineQ(t,e,s,n,i,a,o){var r,h,l;const c=s[8]+s[9],f=n[8]+n[9],u=Math.ceil(c*Math.hypot(i[0],i[1])*this.scale-1e-6),y=Math.ceil(f*Math.hypot(i[2],i[3])*this.scale-1e-6);if(i[1]===0&&i[2]===0||u>4096||y>4096)return!1;if(!(u>0&&y>0&&ft[2]>0)||this.mute)return!0;let d=this.kept(t,e,s,n,u,y,a);const b=(d!=null?d:d=(l=(r=this.scratch)[h=13*Math.ceil(Math.log2(u))+Math.ceil(Math.log2(y))])!=null?l:r[h]=document.createElement("canvas").getContext("2d")).canvas;if(b.width<u&&(b.width=u),b.height<y&&(b.height=y),!this.hit){d.clearRect(0,0,u+2,y+2);for(let m=0;m<12;m+=4){const x=Math.round(n[m]*y/f),g=Math.round((n[m]+n[m+1])*y/f);for(let v=0;v<12;v+=4){const _=Math.round(s[v]*u/c),T=Math.round((s[v]+s[v+1])*u/c);Gt.x=e.x+s[v+2],Gt.y=e.y+n[m+2],Gt.w=s[v+3],Gt.h=n[m+3],!(T<=_||g<=x||Gt.w<=0||Gt.h<=0)&&(a===16777215?d.drawImage(t.source,Gt.x,Gt.y,Gt.w,Gt.h,_,x,T-_,g-x):d.drawImage(this.tint(t,Gt,a),0,0,Gt.w,Gt.h,_,x,T-_,g-x))}}}return ft[0]=c,ft[1]=f,this.blit(b,0,0,u,y,i,o),!0}kept(t,e,s,n,i,a,o){Ht[0]=t.id,Ht[1]=e.x,Ht[2]=e.y,Ht[3]=e.w,Ht[4]=e.h,Ht[5]=i,Ht[6]=a,Ht[7]=o,Ht.set(s,8),Ht.set(n,20);const r=ke(Ht),h=this.nines.get(r);if(this.hit=!1,h)return ms(h.key,Ht)?(h.used=this.frame,this.hit=!0,h.ctx):null;const l=this.missed,c=l.get(r);l.size>4096&&l.clear(),l.set(r,this.frame);const f=i*a;if(c!==this.frame-1||f>Qi)return null;let u;for(;this.ninePx+f>Qi;){let b;for(const g of this.nines.values())g.used<this.frame-1&&!(b&&b.used<=g.used)&&(b=g);if(!b)return null;const m=b.ctx.canvas,x=!u&&m.width>=i&&m.height>=a&&m.width*m.height<=2*f;this.dropNine(b,x),x&&(u=b.ctx)}const y=u!=null?u:document.createElement("canvas").getContext("2d"),d=y.canvas;return u||(d.width=i,d.height=a),this.ninePx+=d.width*d.height,this.nines.set(r,{key:Bs(Ht),ctx:y,used:this.frame}),y}dropNine(t,e=!1){this.nines.delete(ke(t.key));const s=t.ctx.canvas;this.ninePx-=s.width*s.height,e||(s.width=0)}dropNines(){for(const t of this.nines.values())this.dropNine(t)}tint(t,e,s){const n=ve(s,ve(e.h,ve(e.w,ve(e.y,ve(e.x,ve(t.id))))));let i=this.tinted.get(n);if(i)for(let r=0;r<i.length;r++){const h=i[r];if(h.id===t.id&&h.x===e.x&&h.y===e.y&&h.w===e.w&&h.h===e.h&&h.color===s)return h.canvas}this.tintedN>=To&&(this.tinted.clear(),this.tintedN=0,i=void 0);const a=document.createElement("canvas");a.width=Math.ceil(e.w),a.height=Math.ceil(e.h);const o=a.getContext("2d");return o.drawImage(t.source,e.x,e.y,e.w,e.h,0,0,e.w,e.h),o.globalCompositeOperation="multiply",o.fillStyle=hs(s),o.fillRect(0,0,e.w,e.h),o.globalCompositeOperation="destination-in",o.drawImage(t.source,e.x,e.y,e.w,e.h,0,0,e.w,e.h),i||this.tinted.set(n,i=[]),i.push({id:t.id,x:e.x,y:e.y,w:e.w,h:e.h,color:s,canvas:a}),this.tintedN++,a}paint(t,e){this.sync();const s=this.ctx,n=this.scale;return s.setTransform(n,0,0,n,0,0),s.globalAlpha=Math.min(e,1),hs(t)}ellipse(t,e,s,n,i,a,o){if(o<=0||s<=0||n<=0||this.mute)return;const r=Math.max(s,n);this.grow(t-r,e-r,t+r,e+r);const h=this.ctx;h.fillStyle=this.paint(a,o),h.beginPath(),h.ellipse(t,e,s,n,i,0,Math.PI*2),h.fill(),this.quads++}trace(t,e,s=0){if(this.real)for(let i=0;i<e;i++)this.grow(t[i*2]-s,t[i*2+1]-s,t[i*2]+s,t[i*2+1]+s);const n=this.ctx;n.beginPath(),n.moveTo(t[0],t[1]);for(let i=1;i<e;i++)n.lineTo(t[i*2],t[i*2+1])}polygon(t,e,s,n){if(n<=0||e<3||this.mute)return;const i=this.ctx;i.fillStyle=this.paint(s,n),this.trace(t,e),i.closePath(),i.fill(),this.quads++}stroke(t,e,s,n,i,a){if(i<=0||s<=0||e<1||this.mute)return;const o=this.ctx;o.strokeStyle=this.paint(n,i),o.lineWidth=s,o.lineCap="round",o.lineJoin="round",this.trace(t,e,s/2),e===1&&o.lineTo(t[0],t[1]),a&&o.closePath(),o.stroke(),this.quads++}sync(){const t=this.top;if(t.ver===this.clipVer)return;const e=t.ctx;t.clipped&&e.restore(),t.clipped=this.cOn,t.ver=this.clipVer,this.cOn&&(e.save(),e.setTransform(1,0,0,1,0,0),e.beginPath(),e.rect(this.px0,this.py0,this.px1-this.px0,this.py1-this.py0),e.clip())}pushLayer(){const t=this.canvas.width,e=this.canvas.height;let s=this.layers[this.real];if(!s||s.ctx.canvas.width!==t||s.ctx.canvas.height!==e){const i=document.createElement("canvas");i.width=t,i.height=e;const a=i.getContext("2d");if(!a)return!1;s=this.layers[this.real]={ctx:a,clipped:!1,ver:-1}}const n=s.ctx;return s.clipped&&n.restore(),s.clipped=!1,s.ver=-1,n.setTransform(1,0,0,1,0,0),n.globalAlpha=1,n.globalCompositeOperation="source-over",n.clearRect(0,0,t,e),this.top=s,this.ctx=n,!0}popLayer(){return this.top=this.real>0?this.layers[this.real-1]:this.base,this.ctx=this.top.ctx,this.layers[this.real].ctx.canvas}composite(t,e,s,n){var i;let a=t,o="none";const r=n&&ie.c2d?(i=this.fxr)!=null?i:this.fxr=ie.c2d(this):null;r&&(a=r.chain(t,n),o=r.css),this.sync();const h=this.ctx,l=this.rx0,c=this.ry0,f=this.rx1-l,u=this.ry1-c;h.setTransform(1,0,0,1,0,0),h.globalAlpha=Math.min(s,1),h.globalCompositeOperation=e?"destination-in":"source-over",o!=="none"&&(h.filter=o),h.drawImage(a,l,c,f,u,l,c,f,u),o!=="none"&&(h.filter="none"),h.globalCompositeOperation="source-over",this.quads++}end(){this.closeLayers();const t=this.stats;return t.drawCalls=t.quads=this.quads,t.filtersSkipped=this.skipped,t}onLost(t){this.lostListeners.push(t)}onRestored(t){this.restoredListeners.push(t)}destroy(){var t;this.tinted.clear(),this.dropNines(),this.layers=[],this.scratch=[],(t=this.fxr)==null||t.destroy(),this.fxr=null}},xs=14,es=6,Vi=8192,Fo=class{constructor(t,e,s=Vi){p(this,"instanced",t),p(this,"slots",e),p(this,"capacity",s),p(this,"f32"),p(this,"u32"),p(this,"quads",0),p(this,"textures"),p(this,"bound",0),this.textures=new Array(e).fill(null);const n=s*(t?xs:es*4),i=new ArrayBuffer(n*4);this.f32=new Float32Array(i),this.u32=new Uint32Array(i)}slot(t){const e=this.textures;for(let s=0;s<this.bound;s++)if(e[s]===t)return s;return this.bound>=this.slots?-1:(e[this.bound]=t,this.bound++)}has(t){for(let e=0;e<this.bound;e++)if(this.textures[e]===t)return!0;return!1}get full(){return this.quads>=this.capacity}get words(){return this.quads*(this.instanced?xs:es*4)}reset(){this.quads=0;for(let t=0;t<this.bound;t++)this.textures[t]=null;this.bound=0}push(t,e,s,n,i,a,o,r,h,l,c,f,u,y){const d=this.f32;if(this.instanced){let b=this.quads*xs;d[b++]=t,d[b++]=e,d[b++]=s,d[b++]=n,d[b++]=i,d[b++]=a,d[b++]=o,d[b++]=r,d[b++]=h,d[b++]=l,d[b++]=c,d[b++]=f,this.u32[b++]=u,d[b]=y}else{const b=this.quads*es*4;this.vertex(b,t,e,h,l,u,y),this.vertex(b+6,s,n,c,l,u,y),this.vertex(b+12,i,a,c,f,u,y),this.vertex(b+18,o,r,h,f,u,y)}this.quads++}pushQ(t,e){const s=this.f32;if(this.instanced){const n=this.quads*xs;for(let i=0;i<12;i++)s[n+i]=t[i];this.u32[n+12]=t[12],s[n+13]=e}else{let n=this.quads*es*4;const i=t[12];for(let a=0;a<4;a++,n+=es)s[n]=t[a*2],s[n+1]=t[a*2+1],s[n+2]=a===1||a===2?t[10]:t[8],s[n+3]=a>=2?t[11]:t[9],this.u32[n+4]=i,s[n+5]=e}this.quads++}vertex(t,e,s,n,i,a,o){const r=this.f32;r[t]=e,r[t+1]=s,r[t+2]=n,r[t+3]=i,this.u32[t+4]=a,r[t+5]=o}};function Po(t){const e=new Uint16Array(t*6);for(let s=0,n=0,i=0;s<t;s++,n+=6,i+=4)e[n]=i,e[n+1]=i+1,e[n+2]=i+2,e[n+3]=i,e[n+4]=i+2,e[n+5]=i+3;return e}var Xt={M:0,L:1,Q:2,C:3,Z:4},Ki=[2,2,4,6,0],Lo={M:0,L:1,Q:2,C:3,Z:4};function Ln(t,e){if(t.length>=e)return t;const s=new Float64Array(Math.max(e,t.length*2,16));return s.set(t),s}var Hs=new Map;function No(t){var e,s;if(typeof t!="string")return t;let n=Hs.get(t);if(n)return n;n=[];const i=(e=t.match(/[MLQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi))!=null?e:[];let a=-1;for(let o=0;o<i.length;){const r=i[o],h=Lo[r.toUpperCase()];if(h!==void 0){a=h,o++,h===Xt.Z&&n.push(Xt.Z);continue}if(a<0||a===Xt.Z){o++;continue}const l=Ki[a];n.push(a);for(let c=0;c<l;c++)n.push(Number((s=i[o+c])!=null?s:0));o+=l,a===Xt.M&&(a=Xt.L)}return Hs.size>256&&Hs.clear(),Hs.set(t,n),n}var we={subs:[],count:0},Nn=null,_e=null;function Gs(t,e){var s;let n=_e;n||(n=(s=we.subs[we.count])!=null?s:null,n||we.subs.push(n={pts:new Float64Array(64),n:0,closed:!1}),n.n=0,n.closed=!1,we.count++,_e=n);const i=n.n*2;i+2>n.pts.length&&(n.pts=Ln(n.pts,i+2));const a=Nn;a?(n.pts[i]=a[0]*t+a[2]*e+a[4],n.pts[i+1]=a[1]*t+a[3]*e+a[5]):(n.pts[i]=t,n.pts[i+1]=e),n.n++}function In(t,e=null,s=1,n=6){const i=No(t);we.count=0,_e=null,Nn=e;let a=0,o=0,r=0,h=0;const l=s/n;for(let c=0;c<i.length;){const f=i[c++],u=i;if(f===Xt.M)_e=null,a=r=u[c],o=h=u[c+1],Gs(a,o);else if(f===Xt.L)a=u[c],o=u[c+1],Gs(a,o);else if(f===Xt.Q){const y=u[c],d=u[c+1],b=u[c+2],m=u[c+3],x=Zi((he(y-a,d-o)+he(b-y,m-d))*l);for(let g=1;g<=x;g++){const v=g/x,_=1-v;Gs(_*_*a+2*_*v*y+v*v*b,_*_*o+2*_*v*d+v*v*m)}a=b,o=m}else if(f===Xt.C){const y=u[c],d=u[c+1],b=u[c+2],m=u[c+3],x=u[c+4],g=u[c+5],v=Zi((he(y-a,d-o)+he(b-y,m-d)+he(x-b,g-m))*l);for(let _=1;_<=v;_++){const T=_/v,N=1-T,R=N*N*N,M=3*N*N*T,P=3*N*T*T,z=T*T*T;Gs(R*a+M*y+P*b+z*x,R*o+M*d+P*m+z*g)}a=x,o=g}else if(f===Xt.Z){_e&&(_e.closed=!0),_e=null,a=r,o=h;continue}else break;c+=Ki[f]}_e=null,Nn=null;for(let c=0;c<we.count;c++){const f=we.subs[c],u=f.n*2;f.closed&&f.n>=2&&Math.abs(f.pts[0]-f.pts[u-2])<1e-6&&Math.abs(f.pts[1]-f.pts[u-1])<1e-6&&f.n--}return we}var he=(t,e)=>Math.sqrt(t*t+e*e),Zi=t=>Math.min(Math.max(Math.ceil(t),2),24);function Io(t,e){let s=0;for(let n=0,i=e-1;n<e;i=n++)s+=(t[i*2]-t[n*2])*(t[i*2+1]+t[n*2+1]);return s}var Xs=new Int32Array(64),qs=(t,e,s,n,i)=>((t[n*2]-t[s*2])*(t[i*2+1]-t[s*2+1])-(t[n*2+1]-t[s*2+1])*(t[i*2]-t[s*2]))*e;function Oo(t,e,s){if(e<3)return 0;Xs.length<e&&(Xs=new Int32Array(Math.max(e,Xs.length*2)));const n=Xs;let i=e,a=0;for(let l=0;l<e;l++)n[l]=l;const o=Io(t,e)>0?1:-1;let r=e*e+8,h=0;for(;i>3&&r-- >0;){const l=n[(h+i-1)%i],c=n[h%i],f=n[(h+1)%i];let u=qs(t,o,l,c,f)>0;if(u)for(let y=0;y<i;y++){const d=n[y];if(!(d===l||d===c||d===f)&&qs(t,o,l,c,d)>=0&&qs(t,o,c,f,d)>=0&&qs(t,o,f,l,d)>=0){u=!1;break}}u?(s[a++]=l,s[a++]=c,s[a++]=f,n.copyWithin(h%i,h%i+1,i),i--,h=Math.max(h-1,0)):h=(h+1)%i}if(i===3)s[a++]=n[0],s[a++]=n[1],s[a++]=n[2];else if(i>3)for(let l=1;l+1<i;l++)s[a++]=n[0],s[a++]=n[l],s[a++]=n[l+1];return a}var zo=.85,Ws=new Float64Array(64),Ji=new Float64Array(64),$i=new Float64Array(64),ta=new Float64Array(64),ea=new Float64Array(64),sa=new Float64Array(64),na=new Uint8Array(64),js=new Float64Array(8);function Do(t,e,s,n,i,a){const o=js;if(Ws.length<e){const m=Math.max(e,Ws.length*2);Ws=new Float64Array(m),Ji=new Float64Array(m),$i=new Float64Array(m),ta=new Float64Array(m),ea=new Float64Array(m),sa=new Float64Array(m),na=new Uint8Array(m)}const r=Ws,h=Ji;let l=0;for(let m=0;m<e;m++){const x=t[m*2],g=t[m*2+1];!Number.isFinite(x)||!Number.isFinite(g)||l&&Math.abs(r[l-1]-x)<.001&&Math.abs(h[l-1]-g)<.001||(r[l]=x,h[l]=g,l++)}if(n&&l>2&&Math.abs(r[0]-r[l-1])<.001&&Math.abs(h[0]-h[l-1])<.001&&l--,l===0)return;if(l===1)return o[0]=r[0],o[1]=h[0],a();const c=n?l:l-1,f=$i,u=ta;for(let m=0;m<c;m++){const x=(m+1)%l,g=r[x]-r[m],v=h[x]-h[m],_=he(g,v)||1;f[m]=-v/_,u[m]=g/_}const y=ea,d=sa,b=na;for(let m=0;m<l;m++){const x=n?(m-1+c)%c:m-1,g=m<c?m:-1;if(b[m]=1,x<0||g<0||f[x]*f[g]+u[x]*u[g]<zo)continue;let _=f[x]+f[g],T=u[x]+u[g];const N=he(_,T)||1;_/=N,T/=N;const R=s/Math.max(_*f[g]+T*u[g],.5);y[m]=_*R,d[m]=T*R,b[m]=0}for(let m=0;m<c;m++){const x=(m+1)%l,g=b[m]?f[m]*s:y[m],v=b[m]?u[m]*s:d[m],_=b[x]?f[m]*s:y[x],T=b[x]?u[m]*s:d[x];o[0]=r[m]+g,o[1]=h[m]+v,o[2]=r[x]+_,o[3]=h[x]+T,o[4]=r[x]-_,o[5]=h[x]-T,o[6]=r[m]-g,o[7]=h[m]-v,i()}for(let m=0;m<l;m++)b[m]&&(o[0]=r[m],o[1]=h[m],a())}function ia(t,e){let s=0,n=1/0;for(let i=0;i<e.length;i++){const a=Math.abs(Math.log(Math.max(t,.5)/e[i]));a<n&&(n=a,s=i)}return s}var Vt=256,On=[{x:240,y:0,w:8,h:8,r:3},{x:224,y:0,w:16,h:16,r:7},{x:192,y:0,w:32,h:32,r:15},{x:128,y:0,w:64,h:64,r:31},{x:0,y:0,w:128,h:128,r:63}],zn=[4,8,16,32,64,128].map((t,e)=>({x:e*4,y:128,w:4,h:t,r:t/2-1})),Me={x:248,y:248,w:8,h:8},Bo=On.map(t=>t.r*2),Uo=zn.map(t=>t.r*2),aa=(t,e)=>Math.min(Math.max(t+.5-e,0),1);function Ho(){const t=new Uint8ClampedArray(Vt*Vt*4),e=(s,n,i)=>{const a=(n*Vt+s)*4;t[a]=t[a+1]=t[a+2]=255,t[a+3]=Math.round(i*255)};for(const s of On){const n=s.w/2;for(let i=0;i<s.h;i++)for(let a=0;a<s.w;a++)e(s.x+a,s.y+i,aa(s.r,Math.hypot(a+.5-n,i+.5-n)))}for(const s of zn){const n=s.h/2;for(let i=0;i<s.h;i++)for(let a=0;a<s.w;a++)e(s.x+a,s.y+i,aa(s.r,Math.abs(i+.5-n)))}for(let s=0;s<Me.h;s++)for(let n=0;n<Me.w;n++)e(Me.x+n,Me.y+s,1);return t}function Go(){const t=document.createElement("canvas");return t.width=t.height=Vt,t.getContext("2d").putImageData(new ImageData(Ho(),Vt,Vt),0,0),t}var ra=8,Dn="\n#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\n",Xo=t=>"".concat(Dn,"\nuniform sampler2D uTex[").concat(t,"];\nvarying vec2 vUv;\nvarying vec4 vColor;\nvarying float vSlot;\nvoid main() {\n vec4 c;\n ").concat(Array.from({length:t},(e,s)=>s===t-1?"c = texture2D(uTex[".concat(s,"], vUv);"):"if (vSlot < ".concat(s,".5) c = texture2D(uTex[").concat(s,"], vUv); else ")).join("\n "),"\n gl_FragColor = c * vColor;\n}"),qo="\nattribute vec2 aPos;\nattribute vec2 aUv;\nattribute vec4 aColor;\nattribute float aSlot;\nuniform vec2 uScale;\nvarying vec2 vUv;\nvarying vec4 vColor;\nvarying float vSlot;\nvoid main() {\n vUv = aUv;\n vColor = aColor;\n vSlot = aSlot;\n gl_Position = vec4(aPos * uScale + vec2(-1.0, 1.0), 0.0, 1.0);\n}",Wo="\nattribute vec4 aCorner;\nattribute vec4 aP01;\nattribute vec4 aP23;\nattribute vec4 aUvRect;\nattribute vec4 aColor;\nattribute float aSlot;\nuniform vec2 uScale;\nvarying vec2 vUv;\nvarying vec4 vColor;\nvarying float vSlot;\nvoid main() {\n vec2 p = aP01.xy * aCorner.x + aP01.zw * aCorner.y + aP23.xy * aCorner.z + aP23.zw * aCorner.w;\n vUv = vec2(mix(aUvRect.x, aUvRect.z, aCorner.y + aCorner.z), mix(aUvRect.y, aUvRect.w, aCorner.z + aCorner.w));\n vColor = aColor;\n vSlot = aSlot;\n gl_Position = vec4(p * uScale + vec2(-1.0, 1.0), 0.0, 1.0);\n}",jo={alpha:!0,premultipliedAlpha:!0,antialias:!1,depth:!1,stencil:!1,preserveDrawingBuffer:!1,powerPreference:"high-performance"},Yo=["aCorner","aP01","aP23","aUvRect","aColor","aSlot"],Qo=["aPos","aUv","aColor","aSlot"];function Vo(t,e,s={}){var n,i;const a=We(A({},jo),{failIfMajorPerformanceCaveat:s.failIfMajorPerformanceCaveat!==!1}),o=e===2?t.getContext("webgl2",a):(n=t.getContext("webgl",a))!=null?n:t.getContext("experimental-webgl",a);if(!o||o.isContextLost())return null;try{return new Ko(t,o,e,s)}catch(r){return console.warn("[engine] WebGL setup failed:",r),(i=o.getExtension("WEBGL_lose_context"))==null||i.loseContext(),null}}var Ko=class extends Yi{constructor(t,e,s,n){super(),p(this,"canvas",t),p(this,"gl",e),p(this,"opts",n),p(this,"kind"),p(this,"maxTextureSize"),p(this,"support",{filters:!0,shaders:!0}),p(this,"features",{}),p(this,"info",{}),p(this,"lost",!1),p(this,"main"),p(this,"cur"),p(this,"unit",-1),p(this,"onUnit",new Array(ra).fill(void 0)),p(this,"fbNow"),p(this,"mapped",!0),p(this,"calls",{useProgram:0,bindTexture:0,activeTexture:0,bindFramebuffer:0}),p(this,"vsrc",""),p(this,"attrs",[]),p(this,"fxr",null),p(this,"batch"),p(this,"dynamic"),p(this,"staticBuf",null),p(this,"index"),p(this,"vao",null),p(this,"inst",null),p(this,"vaoApi",null),p(this,"uScale",null),p(this,"textures",new Map),p(this,"kit"),p(this,"stats",{drawCalls:0,quads:0,filtersSkipped:0}),p(this,"lostListeners",[]),p(this,"restoredListeners",[]),p(this,"tris",new Int32Array(192)),p(this,"sU",0),p(this,"sV0",0),p(this,"sV1",0),p(this,"sColor",0),p(this,"sPacked",0),p(this,"sAlpha",0),p(this,"sHw",0),p(this,"strokeSeg",()=>{const i=this.q;i.set(js),i[8]=i[10]=this.sU,i[9]=this.sV0,i[11]=this.sV1,i[12]=this.sPacked,this.put(this.kit)}),p(this,"strokeDisc",()=>this.ellipse(js[0],js[1],this.sHw,this.sHw,0,this.sColor,this.sAlpha)),p(this,"q",new Float64Array(13)),p(this,"layers",[]),p(this,"layerTex",new Map),p(this,"bScis",!1),p(this,"bx0",0),p(this,"by0",0),p(this,"bx1",0),p(this,"by1",0),p(this,"onContextLost",i=>{i.preventDefault(),this.lost=!0;for(const a of this.lostListeners)a()}),p(this,"onContextRestored",()=>{try{this.layers=[],this.layerTex.clear(),this.fxr=null,this.resetLayers(this.scale),this.setup();for(const i of this.textures.keys())this.textures.set(i,this.upload(i.source));this.lost=!1;for(const i of this.restoredListeners)i()}catch(i){console.warn("[engine] WebGL restore failed:",i)}}),p(this,"views",new Map),this.kind=s===2?"webgl2":"webgl1",this.maxTextureSize=e.getParameter(e.MAX_TEXTURE_SIZE),this.setup(),this.kit=this.createTexture(Go()),ie.live=this,t.addEventListener("webglcontextlost",this.onContextLost,!1),t.addEventListener("webglcontextrestored",this.onContextRestored,!1)}setup(){const t=this.gl,e=this.kind==="webgl2"?t:null;if(this.inst=null,this.opts.instancing!==!1)if(e)this.inst={divisor:(l,c)=>e.vertexAttribDivisor(l,c),draw:(l,c)=>e.drawElementsInstanced(t.TRIANGLES,l,t.UNSIGNED_SHORT,0,c)};else{const l=t.getExtension("ANGLE_instanced_arrays");l&&(this.inst={divisor:(c,f)=>l.vertexAttribDivisorANGLE(c,f),draw:(c,f)=>l.drawElementsInstancedANGLE(t.TRIANGLES,c,t.UNSIGNED_SHORT,0,f)})}if(this.vaoApi=null,this.opts.vao!==!1)if(e)this.vaoApi={create:()=>e.createVertexArray(),bind:l=>e.bindVertexArray(l),remove:l=>e.deleteVertexArray(l)};else{const l=t.getExtension("OES_vertex_array_object");l&&(this.vaoApi={create:()=>l.createVertexArrayOES(),bind:c=>l.bindVertexArrayOES(c),remove:c=>l.deleteVertexArrayOES(c)})}const s=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS),n=Math.max(1,Math.min(ra,s)),i=this.inst!==null;this.vsrc=i?Wo:qo,this.attrs=i?Yo:Qo,this.main=this.cur=this.build(Xo(n));const a=this.main.p;t.useProgram(a),this.calls.useProgram++,this.unit=-1,this.onUnit.fill(void 0),this.fbNow=void 0,this.uScale=this.main.uScale,t.uniform1iv(t.getUniformLocation(a,"uTex"),Int32Array.from({length:n},(l,c)=>c)),this.batch=new Fo(i,n),this.vaoApi&&(this.vao=this.vaoApi.create(),this.vaoApi.bind(this.vao)),this.dynamic=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this.dynamic),t.bufferData(t.ARRAY_BUFFER,this.batch.f32.byteLength,t.DYNAMIC_DRAW),this.index=t.createBuffer(),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this.index),t.bufferData(t.ELEMENT_ARRAY_BUFFER,Po(i?1:Vi),t.STATIC_DRAW);const o=l=>t.getAttribLocation(a,l),r=(l,c,f,u,y,d,b)=>{const m=o(l);m<0||(t.enableVertexAttribArray(m),t.vertexAttribPointer(m,c,f,u,y,d),this.inst&&this.inst.divisor(m,b))};if(i){const l=xs*4;r("aP01",4,t.FLOAT,!1,l,0,1),r("aP23",4,t.FLOAT,!1,l,16,1),r("aUvRect",4,t.FLOAT,!1,l,32,1),r("aColor",4,t.UNSIGNED_BYTE,!0,l,48,1),r("aSlot",1,t.FLOAT,!1,l,52,1),this.staticBuf=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this.staticBuf),t.bufferData(t.ARRAY_BUFFER,Float32Array.of(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),t.STATIC_DRAW),r("aCorner",4,t.FLOAT,!1,16,0,0),t.bindBuffer(t.ARRAY_BUFFER,this.dynamic)}else{const l=es*4;r("aPos",2,t.FLOAT,!1,l,0,0),r("aUv",2,t.FLOAT,!1,l,8,0),r("aColor",4,t.UNSIGNED_BYTE,!0,l,16,0),r("aSlot",1,t.FLOAT,!1,l,20,0)}t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),t.disable(t.DEPTH_TEST),t.disable(t.CULL_FACE),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0);const h=t.getExtension("WEBGL_debug_renderer_info");this.info={version:t.getParameter(t.VERSION),renderer:h?t.getParameter(h.UNMASKED_RENDERER_WEBGL):t.getParameter(t.RENDERER),vendor:h?t.getParameter(h.UNMASKED_VENDOR_WEBGL):t.getParameter(t.VENDOR)},this.features={instancing:i,vao:this.vaoApi!==null,textureSlots:n,maxTextureSize:this.maxTextureSize}}upload(t){const e=this.gl,s=e.createTexture();return this.bindTex(s),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),s}resize(t,e){this.canvas.width!==t&&(this.canvas.width=t),this.canvas.height!==e&&(this.canvas.height=e)}createTexture(t){const e={id:Mn(),width:t.width,height:t.height,source:t};return this.textures.set(e,this.lost?null:this.upload(t)),e}updateTexture(t,e,s=0,n=0){if(this.lost)return;this.batch.has(t)&&this.flush();const i=this.gl,a=this.textures.get(t);a&&(this.bindTex(a),!e||e===t.source&&s===0&&n===0?i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,t.source):i.texSubImage2D(i.TEXTURE_2D,0,s,n,i.RGBA,i.UNSIGNED_BYTE,e))}destroyTexture(t){this.batch.has(t)&&this.flush();const e=this.textures.get(t);e&&!this.lost&&this.deleteTex(e),this.textures.delete(t)}begin(t,e,s){if(this.stats.drawCalls=this.stats.quads=this.stats.filtersSkipped=0,this.batch.reset(),this.resetLayers(s),this.bScis=!1,this.lost)return;const n=this.gl;n.disable(n.SCISSOR_TEST),this.bindFb(null),n.viewport(0,0,this.canvas.width,this.canvas.height);const i=e;n.clearColor((t>>16&255)/255*i,(t>>8&255)/255*i,(t&255)/255*i,i),n.clear(n.COLOR_BUFFER_BIT),this.use(this.main),n.uniform2f(this.uScale,2*s/this.canvas.width,-2*s/this.canvas.height),this.mapped=!0}build(t){var e;const s=this.gl,n=oa(s,s.VERTEX_SHADER,this.vsrc);let i;try{i=oa(s,s.FRAGMENT_SHADER,t)}catch(o){throw s.deleteShader(n),o}const a=s.createProgram();if(s.attachShader(a,n),s.attachShader(a,i),this.attrs.forEach((o,r)=>s.bindAttribLocation(a,r,o)),s.linkProgram(a),s.deleteShader(n),s.deleteShader(i),!s.getProgramParameter(a,s.LINK_STATUS)){const o=(e=s.getProgramInfoLog(a))!=null?e:"?";throw s.deleteProgram(a),new Error("link: ".concat(o))}return{p:a,uScale:s.getUniformLocation(a,"uScale"),locs:new Map}}u(t,e){let s=t.locs.get(e);return s===void 0&&t.locs.set(e,s=this.gl.getUniformLocation(t.p,e)),s}use(t){this.cur!==t&&(this.cur=t,this.gl.useProgram(t.p),this.calls.useProgram++)}bindTex(t,e=this.unit<0?0:this.unit){const s=this.gl;this.onUnit[e]!==t&&(this.unit!==e&&(s.activeTexture(s.TEXTURE0+e),this.calls.activeTexture++,this.unit=e),s.bindTexture(s.TEXTURE_2D,t),this.calls.bindTexture++,this.onUnit[e]=t)}deleteTex(t){this.gl.deleteTexture(t);for(let e=0;e<this.onUnit.length;e++)this.onUnit[e]===t&&(this.onUnit[e]=null)}bindFb(t){if(t)for(let s=0;s<this.onUnit.length;s++)this.onUnit[s]===t.gl&&this.bindTex(null,s);const e=t?t.fb:null;this.fbNow!==e&&(this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,e),this.calls.bindFramebuffer++,this.fbNow=e)}slotOf(t){this.batch.full&&this.flush();let e=this.batch.slot(t);return e<0&&(this.flush(),e=this.batch.slot(t)),e}quad(t,e,s,n,i,a,o,r){ft[0]=n,ft[1]=i,ft[2]=o,this.quadQ(t,e,s,a,r)}quadQ(t,e,s,n,i){const a=ft[2];if(this.lost||a<=0)return;const o=this.q,r=ft[0],h=ft[1],l=s[4],c=s[5],f=s[0]*r,u=s[1]*r,y=s[2]*h,d=s[3]*h;o[0]=l,o[1]=c,o[2]=f+l,o[3]=u+c,o[4]=f+y+l,o[5]=u+d+c,o[6]=y+l,o[7]=d+c;const b=1/t.width,m=1/t.height;o[8]=e.x*b,o[9]=e.y*m,o[10]=(e.x+e.w)*b,o[11]=(e.y+e.h)*m,o[12]=Ve(n,a,i==="add"),this.put(t)}put(t){if(this.mute)return;const e=this.q;let s=!1;const n=Math.min(e[0],e[2],e[4],e[6]),i=Math.max(e[0],e[2],e[4],e[6]),a=Math.min(e[1],e[3],e[5],e[7]),o=Math.max(e[1],e[3],e[5],e[7]);if(this.cOn){if(this.px1<=this.px0||this.py1<=this.py0)return;const h=this.scale,l=this.px0/h,c=this.py0/h,f=this.px1/h,u=this.py1/h;if(i<=l||n>=f||o<=c||a>=u)return;if(n<l||i>f||a<c||o>u){const y=e[0],d=e[1],b=e[2],m=e[5];if(d===e[3]&&b===e[4]&&m===e[7]&&e[6]===y){if(y!==b){const x=Math.min(Math.max(y,l),f),g=Math.min(Math.max(b,l),f),v=e[8],_=(e[10]-v)/(b-y);e[10]=v+(g-y)*_,e[8]=v+(x-y)*_,e[0]=e[6]=x,e[2]=e[4]=g}if(d!==m){const x=Math.min(Math.max(d,c),u),g=Math.min(Math.max(m,c),u),v=e[9],_=(e[11]-v)/(m-d);e[11]=v+(g-d)*_,e[9]=v+(x-d)*_,e[1]=e[3]=x,e[5]=e[7]=g}}else s=!0}}const r=this.bx0===this.px0&&this.by0===this.py0&&this.bx1===this.px1&&this.by1===this.py1;if(s?(!this.bScis||!r)&&(this.flush(),this.bScis=!0,this.bx0=this.px0,this.by0=this.py0,this.bx1=this.px1,this.by1=this.py1):this.bScis&&!(this.cOn&&r)&&(this.flush(),this.bScis=!1),this.real){const h=this.gq;h[0]=n,h[1]=a,h[2]=i,h[3]=o,this.growQ()}this.batch.pushQ(e,this.slotOf(t))}ellipse(t,e,s,n,i,a,o){if(this.lost||o<=0||s<=0||n<=0)return;const r=On[ia(Math.max(s,n)*2*this.scale,Bo)],h=r.w/2/r.r,l=s*h,c=n*h,f=Math.cos(i),u=Math.sin(i),y=f*l,d=u*l,b=-u*c,m=f*c,x=1/Vt,g=this.q;g[0]=t-y-b,g[1]=e-d-m,g[2]=t+y-b,g[3]=e+d-m,g[4]=t+y+b,g[5]=e+d+m,g[6]=t-y+b,g[7]=e-d+m,g[8]=r.x*x,g[9]=r.y*x,g[10]=(r.x+r.w)*x,g[11]=(r.y+r.h)*x,g[12]=Ve(a,o),this.put(this.kit)}polygon(t,e,s,n){if(this.lost||n<=0||e<3)return;this.tris.length<e*3&&(this.tris=new Int32Array(Math.max(e*3,this.tris.length*2)));const i=this.tris,a=Oo(t,e,i),o=Ve(s,n),r=(Me.x+Me.w/2)/Vt,h=(Me.y+Me.h/2)/Vt;for(let l=0;l<a;l+=3){const c=i[l]*2,f=i[l+1]*2,u=i[l+2]*2,y=this.q;y[0]=t[c],y[1]=t[c+1],y[2]=t[f],y[3]=t[f+1],y[4]=y[6]=t[u],y[5]=y[7]=t[u+1],y[8]=y[10]=r,y[9]=y[11]=h,y[12]=o,this.put(this.kit)}}stroke(t,e,s,n,i,a){if(this.lost||i<=0||s<=0||e<1)return;const o=zn[ia(s*this.scale,Uo)],r=s/2*(o.h/2/o.r);this.sPacked=Ve(n,i),this.sColor=n,this.sAlpha=i,this.sU=(o.x+o.w/2)/Vt,this.sV0=o.y/Vt,this.sV1=(o.y+o.h)/Vt,this.sHw=s/2,Do(t,e,r,a,this.strokeSeg,this.strokeDisc)}target(t,e,s,n){const i=this.gl,a=i.createTexture();this.bindTex(a),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,t,e,0,i.RGBA,i.UNSIGNED_BYTE,null);const o=n?i.LINEAR:i.NEAREST;i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,o),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,o),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),this.bindTex(null);const r=i.createFramebuffer();i.bindFramebuffer(i.FRAMEBUFFER,r),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,a,0);const h=i.checkFramebufferStatus(i.FRAMEBUFFER)===i.FRAMEBUFFER_COMPLETE;if(this.fbNow=r,this.bindFb(this.parent()),!h)return this.deleteTex(a),i.deleteFramebuffer(r),null;const l={tex:{id:Mn(),width:t,height:e,source:this.canvas},gl:a,fb:r,w:t,h:e,f:s};return this.layerTex.set(l.tex,a),l}drop(t){this.batch.has(t.tex)&&this.flush(),this.deleteTex(t.gl),this.gl.deleteFramebuffer(t.fb),this.layerTex.delete(t.tex)}parent(){return this.real>0?this.layers[this.real-1]:null}layerAt(t){var e;const s=this.canvas.width,n=this.canvas.height;let i=(e=this.layers[t])!=null?e:null;return i&&(i.w!==s||i.h!==n)&&(this.drop(i),i=this.layers[t]=null),i!=null?i:this.layers[t]=this.target(s,n,1,!1)}pushLayer(){if(this.lost)return!1;this.flush();const t=this.layerAt(this.real);if(!t)return!1;const e=this.gl;return this.bindFb(t),e.disable(e.SCISSOR_TEST),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),!0}popLayer(){return this.flush(),this.bindFb(this.parent()),this.layers[this.real].tex}filters(){var t;return this.lost||!ie.gl?null:(t=this.fxr)!=null?t:this.fxr=ie.gl(this)}composite(t,e,s,n){var i;if(n&&((i=this.filters())!=null&&i.chain(t,s,n)))return;const a=this.gl;e&&a.blendFunc(a.ZERO,a.SRC_ALPHA),this.final(this.main,t,1,s),e&&(this.flush(),a.blendFunc(a.ONE,a.ONE_MINUS_SRC_ALPHA))}final(t,e,s,n){const i=this.gl,a=this.canvas.width,o=this.canvas.height,r=this.scale;(t!==this.main||!this.mapped)&&(this.bindFb(this.parent()),i.viewport(0,0,a,o),this.use(t),i.uniform2f(t.uScale,2*r/a,-2*r/o),this.mapped=t===this.main);const h=this.rx0/r,l=this.ry0/r,c=this.rx1/r,f=this.ry1/r,u=1/(s*e.width),y=1/(s*e.height),d=this.q;d[0]=d[6]=h,d[1]=d[3]=l,d[2]=d[4]=c,d[5]=d[7]=f,d[8]=this.rx0*u,d[9]=1-this.ry0*y,d[10]=this.rx1*u,d[11]=1-this.ry1*y,d[12]=Ve(16777215,n),this.put(e),t!==this.main&&this.flush()}remap(){const t=this.gl;this.bindFb(this.parent()),t.viewport(0,0,this.canvas.width,this.canvas.height),this.use(this.main),t.uniform2f(this.uScale,2*this.scale/this.canvas.width,-2*this.scale/this.canvas.height),this.mapped=!0}upload2(t){const e=this.gl,s=t.words;if(this.kind==="webgl2")return e.bufferSubData(e.ARRAY_BUFFER,0,t.f32,0,s);let n=this.views.get(s);n||(this.views.size>=256&&this.views.clear(),this.views.set(s,n=t.f32.subarray(0,s))),e.bufferSubData(e.ARRAY_BUFFER,0,n)}flush(){var t,e;const s=this.batch;if(!s.quads||this.lost)return s.reset();const n=this.gl;this.bScis?(n.enable(n.SCISSOR_TEST),n.scissor(this.bx0,this.canvas.height-this.by1,this.bx1-this.bx0,this.by1-this.by0)):n.disable(n.SCISSOR_TEST),this.upload2(s);for(let i=0;i<s.bound;i++){const a=s.textures[i];this.bindTex((e=(t=this.textures.get(a))!=null?t:this.layerTex.get(a))!=null?e:null,i)}this.inst?this.inst.draw(6,s.quads):n.drawElements(n.TRIANGLES,s.quads*6,n.UNSIGNED_SHORT,0),this.stats.drawCalls++,this.stats.quads+=s.quads,s.reset()}end(){return this.closeLayers(),this.flush(),this.stats.filtersSkipped=this.skipped,this.stats}onLost(t){this.lostListeners.push(t)}onRestored(t){this.restoredListeners.push(t)}destroy(){var t,e;const s=this.gl;ie.live===this&&(ie.live=null),this.canvas.removeEventListener("webglcontextlost",this.onContextLost),this.canvas.removeEventListener("webglcontextrestored",this.onContextRestored);try{for(const n of this.textures.values())n&&s.deleteTexture(n);for(const n of this.layers)n&&(s.deleteTexture(n.gl),s.deleteFramebuffer(n.fb));(t=this.fxr)==null||t.destroy(),this.fxr=null,s.deleteBuffer(this.dynamic),s.deleteBuffer(this.index),this.staticBuf&&s.deleteBuffer(this.staticBuf),this.vao&&this.vaoApi&&this.vaoApi.remove(this.vao),s.deleteProgram(this.main.p),(e=s.getExtension("WEBGL_lose_context"))==null||e.loseContext()}catch(n){}this.textures.clear()}};function oa(t,e,s){var n;const i=t.createShader(e);if(t.shaderSource(i,s),t.compileShader(i),!t.getShaderParameter(i,t.COMPILE_STATUS)){const a=(n=t.getShaderInfoLog(i))!=null?n:"?";throw t.deleteShader(i),new Error(a)}return i}function la(t="auto"){switch(t){case"canvas2d":return["canvas2d"];case"webgl1":return["webgl1","canvas2d"];default:return["webgl2","webgl1","canvas2d"]}}function Bn(t,e={}){let s=t;for(const n of la(e.renderer)){const i=n==="canvas2d"?Pn(s):Vo(s,n==="webgl2"?2:1,e);if(i)return i;s=Un(s)}throw new Error("No renderer: this browser has neither WebGL nor Canvas 2D")}function Un(t){var e;const s=t.cloneNode(!1);return(e=t.parentNode)==null||e.replaceChild(s,t),s}function Zo(t=typeof location!="undefined"?location.search:""){const e=new URLSearchParams(t).get("renderer");return e==="canvas"?"canvas2d":e==="webgl2"||e==="webgl1"||e==="canvas2d"||e==="webgl"||e==="auto"?e:void 0}var Hn=class{constructor(t,e={}){p(this,"atlas",t),p(this,"tags",new Map),p(this,"count",0),p(this,"m",Qe()),p(this,"measure",null),p(this,"height"),p(this,"font");var s,n;this.height=(s=e.tagHeight)!=null?s:34,this.font=(n=e.tagFont)!=null?n:"Nunito, sans-serif"}drop(){for(const t of this.tags.values())for(const e of t.values())for(const s of e.values())this.atlas.release(s);this.tags.clear(),this.count=0}get(t,e,s){let n=this.tags.get(t);n||this.tags.set(t,n=new Map);let i=n.get(e);i||n.set(e,i=new Map);const a=i.get(s);return a&&this.atlas.valid(a)?a:this.bake(t,e,s)}bake(t,e,s){var n;const i=this.height,a="700 ".concat(Math.round(i*.65),"px ").concat(this.font),o=(n=this.measure)!=null?n:this.measure=document.createElement("canvas").getContext("2d");o.font=a;const r=Math.round(i*.4),h=Math.ceil(o.measureText(t).width)+r*2,l=this.atlas.bake((h+2)*s,(i+2)*s,u=>{u.scale(s,s),u.translate(1,1);const y=i/2;u.beginPath(),u.moveTo(y,0),u.lineTo(h-y,0),u.arc(h-y,y,y,-Math.PI/2,Math.PI/2),u.lineTo(y,i),u.arc(y,y,y,Math.PI/2,Math.PI*3/2),u.closePath(),u.fillStyle=e,u.fill(),u.fillStyle="#fff",u.font=a,u.textAlign="center",u.textBaseline="middle",u.fillText(t,h/2,i/2+1)},s,1,1,1);++this.count>64&&(this.drop(),this.count=1);let c=this.tags.get(t);c||this.tags.set(t,c=new Map);let f=c.get(e);return f||c.set(e,f=new Map),f.set(s,l),l}draw(t,e,s,n,i,a,o,r,h,l,c){const f=dn(s,i,{band:Jo(n)});if(!f)return;const u=this.height,y=this.get(a,o,h),d=y.w/y.scale-2,b=Math.min(Math.max(f.head.x-d/2,4),l-d-4),m=Math.min(Math.max(f.head.y-f.headR*2.2-u,4),c-u-4);ce(this.m,null,b-1,m-1,0,1,1),t.quad(e(y.surface),y,this.m,y.w/y.scale,y.h/y.scale,16777215,r,"normal")}},Jo=t=>t.band==="3-5"||t.band==="9-12"?t.band:"6-8",$o=(t,e=!1)=>e?Math.min(qe(2,Math.round(Math.log2(Math.max(t,8)))),256):Math.min(qe(2,Math.ceil(Math.log2(Math.max(t,8))*2)/2),512);function Gn(t,e=null){var s,n,i,a;const o={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},r=(h,l,c)=>{const f=e?e[0]*h+e[2]*l+e[4]:h,u=e?e[1]*h+e[3]*l+e[5]:l,y=e?Math.hypot(e[0],e[1]):1;o.minX=Math.min(o.minX,f-c*y),o.minY=Math.min(o.minY,u-c*y),o.maxX=Math.max(o.maxX,f+c*y),o.maxY=Math.max(o.maxY,u+c*y)};for(const h of t){const l="lw"in h&&h.stroke?((s=h.lw)!=null?s:1)/2:0;switch(h.k){case"circle":r(h.x-h.r,h.y-h.r,l),r(h.x+h.r,h.y+h.r,l),r(h.x-h.r,h.y+h.r,l),r(h.x+h.r,h.y-h.r,l);break;case"ellipse":case"rect":{const c=h.k==="ellipse"?Math.max(h.rx,h.ry):Math.hypot(h.w,h.h)/2;r(h.x-c,h.y-c,l),r(h.x+c,h.y+c,l),r(h.x-c,h.y+c,l),r(h.x+c,h.y-c,l);break}case"path":{const c=In(h.d);for(let f=0;f<c.count;f++){const u=c.subs[f];for(let y=0;y<u.n;y++)r(u.pts[y*2],u.pts[y*2+1],l)}break}case"line":for(let c=0;c+1<h.pts.length;c+=2)r(h.pts[c],h.pts[c+1],l);break;case"group":{const c=ce(Qe(),e,h.x,h.y,(n=h.rot)!=null?n:0,(i=h.s)!=null?i:1,(a=h.s)!=null?a:1),f=Gn(h.items,c);Number.isFinite(f.minX)&&(o.minX=Math.min(o.minX,f.minX),o.minY=Math.min(o.minY,f.minY),o.maxX=Math.max(o.maxX,f.maxX),o.maxY=Math.max(o.maxY,f.maxY));break}}}return o}var Xn=class{constructor(t){p(this,"atlas",t),p(this,"seen",new WeakSet),p(this,"baked",new WeakMap),p(this,"m",Qe()),p(this,"stack",[]),p(this,"local",Qe()),p(this,"pts",new Float64Array(128)),p(this,"stats",{baked:0,vector:0}),p(this,"bakeGroups",!0),p(this,"coarse",!1),p(this,"gen",0),p(this,"live",new Set)}setTier(t){const e=t==="low";if(e!==this.coarse){this.coarse=e,this.gen++;for(const s of this.live)this.atlas.release(s.frame);this.live.clear()}}draw(t,e,s,n,i,a,o){var r;const h=typeof n=="string"?(r=Is(n))!=null?r:ls:n,l=bi(s,h,i);return l.length?(a<=0||(a<1?(this.paint(t,e,l,null,t.beginLayer()?1:a,o),t.endLayer(a)):this.paint(t,e,l,null,a,o)),!0):!1}paint(t,e,s,n,i,a,o=0){var r,h,l,c,f,u,y,d,b,m,x;for(let g=0;g<s.length;g++){const v=s[g];if(v.k==="group"){const U=ce((h=(r=this.stack)[o])!=null?h:r[o]=Qe(),n,v.x,v.y,(l=v.rot)!=null?l:0,(c=v.s)!=null?c:1,(f=v.s)!=null?f:1),G=i*((u=v.alpha)!=null?u:1);if(this.bakeGroups&&this.seen.has(v.items)){const O=he(U[0],U[1])*a,X=this.bake(v.items,O);if(X){const L=X.frame,lt=this.m;lt.set(U),lt[4]=U[0]*-X.ox+U[2]*-X.oy+U[4],lt[5]=U[1]*-X.ox+U[3]*-X.oy+U[5],t.quad(e(L.surface),L,lt,L.w/X.k,L.h/X.k,16777215,G,"normal"),this.stats.baked++;continue}}this.seen.add(v.items),this.stats.vector++,this.paint(t,e,v.items,U,G,a,o+1);continue}const _=i*((y=v.alpha)!=null?y:1),T=n?he(n[0],n[1]):1,N=n?Math.atan2(n[1],n[0]):0,R=((d=v.lw)!=null?d:1)*T,M=v.stroke&&((b=v.lw)!=null?b:1)>0?ne(v.stroke):null,P=v.fill&&v.k!=="line"?ne(v.fill):null;if(v.k==="circle"||v.k==="ellipse"){const U=n?n[0]*v.x+n[2]*v.y+n[4]:v.x,G=n?n[1]*v.x+n[3]*v.y+n[5]:v.y,O=(v.k==="circle"?v.r:v.rx)*T,X=(v.k==="circle"?v.r:v.ry)*T,L=(v.k==="ellipse"&&(m=v.rot)!=null?m:0)+N;if(P&&M)t.ellipse(U,G,O+R/2,X+R/2,L,M[0],_*M[1]),t.ellipse(U,G,Math.max(O-R/2,0),Math.max(X-R/2,0),L,P[0],_*P[1]);else if(P)t.ellipse(U,G,O,X,L,P[0],_*P[1]);else if(M){const lt=Math.min(Math.max(Math.ceil(Math.max(O,X)*a*.6),12),64),yt=this.pts=Ln(this.pts,lt*2),$=Math.cos(L),w=Math.sin(L);for(let H=0;H<lt;H++){const W=H/lt*Math.PI*2,bt=Math.cos(W)*O,Z=Math.sin(W)*X;yt[H*2]=U+bt*$-Z*w,yt[H*2+1]=G+bt*w+Z*$}t.stroke(yt,lt,R,M[0],_*M[1],!0)}continue}if(v.k==="line"){if(!M)continue;const U=v.pts.length>>1,G=this.pts=Ln(this.pts,U*2);for(let O=0;O<U;O++){const X=v.pts[O*2],L=v.pts[O*2+1];G[O*2]=n?n[0]*X+n[2]*L+n[4]:X,G[O*2+1]=n?n[1]*X+n[3]*L+n[5]:L}t.stroke(G,U,R,M[0],_*M[1],!1);continue}const z=v.k==="path"?In(v.d,n,T*a):tl(v,ce(this.local,n,v.x,v.y,(x=v.rot)!=null?x:0,1,1),a*T);for(let U=0;U<z.count;U++){const G=z.subs[U],O=G.n,X=v.k==="rect"||G.closed;P&&O>=3&&(t.polygon(G.pts,O,P[0],_*P[1]),M||t.stroke(G.pts,O,1/a,P[0],_*P[1],!0)),M&&t.stroke(G.pts,O,R,M[0],_*M[1],X)}}}bake(t,e){const s=$o(e,this.coarse);let n=this.baked.get(t);const i=n==null?void 0:n.get(s);if(i&&i.gen===this.gen&&this.atlas.valid(i.frame))return i;i&&this.live.delete(i);const a=Gn(t);if(!Number.isFinite(a.minX))return null;const o=2/s,r=(a.maxX-a.minX+o*2)*s,h=(a.maxY-a.minY+o*2)*s;if(r>1024||h>1024)return null;const l=-a.minX+o,c=-a.minY+o,u={frame:this.atlas.bake(r,h,y=>{y.scale(s,s),y.translate(l,c),fn(y,t)}),k:s,ox:l,oy:c,gen:this.gen};return n||this.baked.set(t,n=new Map),n.set(s,u),this.live.add(u),u}},ss=new Array(36).fill(0),ns=0,ae=(t,e=NaN,s=NaN,n=NaN,i=NaN)=>{ss[ns++]=t,t!==Xt.Z&&(ss[ns++]=e,ss[ns++]=s,t===Xt.Q&&(ss[ns++]=n,ss[ns++]=i))};function tl(t,e,s){const n=Math.max(0,Math.min(t.r,t.w/2,t.h/2)),i=-t.w/2,a=-t.h/2,{M:o,L:r,Q:h,Z:l}=Xt;return ns=0,ae(o,i+n,a),ae(r,i+t.w-n,a),ae(h,i+t.w,a,i+t.w,a+n),ae(r,i+t.w,a+t.h-n),ae(h,i+t.w,a+t.h,i+t.w-n,a+t.h),ae(r,i+n,a+t.h),ae(h,i,a+t.h,i,a+t.h-n),ae(r,i,a+n),ae(h,i,a,i+n,a),ae(l),In(ss,e,s)}function el(t,e={}){var s,n;let i=Bn(t,e);const a=new Tn(Math.min(1024,i.maxTextureSize),2);a.onDrop=M=>{M.texture&&i.destroyTexture(M.texture),M.texture=null};const o=new Xn(a),r=()=>{const M=new Ao;return e.local&&M.setLocal(!0),M};let h=r();const l=new Map;let c=1e6;const f=e.smooth===!1?1:typeof e.smooth=="number"?Math.min(Math.max(e.smooth,.05),1):h.defaultAmount;let u=Qs(i);const y=new Hn(a,e),d={w:1,h:1};let b=1,m=0,x=!1;const g=()=>y.drop(),v=typeof document!="undefined"?document.fonts:void 0;(s=v==null?void 0:v.ready)==null||s.then(()=>{x||g()}),(n=v==null?void 0:v.addEventListener)==null||n.call(v,"loadingdone",g);const _=()=>{const M=Un(i.canvas),P=Pn(M);if(P){console.warn("[engine] avatars: WebGL context lost for good, switching to Canvas 2D"),i.destroy(),i=P;for(const z of a.pages)z.surface.texture=null;u=Qs(i),m=0}},T=()=>{if(!i.lost)return m=0,!0;const M=performance.now();return m||(m=M),M-m>3e3&&_(),!i.lost},N=()=>{var M,P;const z=i.canvas;e.units?(b=(M=e.pixelRatio)!=null?M:1,d.w=e.units.width,d.h=e.units.height):(b=(P=e.pixelRatio)!=null?P:Math.min(le.devicePixelRatio||1,2),d.w=z.clientWidth||z.width/b,d.h=z.clientHeight||z.height/b),i.resize(Math.max(1,Math.round(d.w*b)),Math.max(1,Math.round(d.h*b))),i.begin(0,0,b)},R=(M,P)=>{var z;if(M.key===void 0)return(z=M.id)!=null?z:P+1;let U=l.get(M.key);return U===void 0&&(l.size>256&&l.clear(),l.set(M.key,U=c++)),U};return{get renderer(){return i},get kind(){return i.kind},get lost(){return i.lost},get canvas(){return i.canvas},draw(M,P){var z,U,G,O;if(T()){N();for(let X=0;X<M.length;X++){const L=M[X];if(!Array.isArray(L.body))continue;const lt=R(L,X),yt=f<1||e.interpolate!==!1?h.posed(lt,L.body,f,e.interpolate!==!1):L.body,$=(U=Is((z=L.avatar)!=null?z:""))!=null?U:ls,w=(G=L.alpha)!=null?G:1;!o.draw(i,u,yt,$,P,w,b)||!L.name||y.draw(i,u,yt,$,P,L.name,(O=L.color)!=null?O:"#6FA0E0",w,b,d.w,d.h)}i.end()}},clear(){T()&&(N(),i.end())},reset(){h=r(),l.clear()},destroy(){var M;x=!0,(M=v==null?void 0:v.removeEventListener)==null||M.call(v,"loadingdone",g),i.destroy()}}}var Ys=new Map;function sl(t,e,s=Math.min(le.devicePixelRatio||1,2)){var n;const i="".concat(t,"|").concat(e,"|").concat(s);let a=Ys.get(i);if(a)return a;a=document.createElement("canvas"),a.width=a.height=Math.round(e*s);const o=a.getContext("2d");return o.scale(s,s),o.beginPath(),o.rect(0,0,e,e),o.clip(),fn(o,so((n=Is(t))!=null?n:ls,e)),Ys.size>64&&Ys.clear(),Ys.set(i,a),a}function Qs(t){return e=>{if(e.texture||(e.texture=t.createTexture(e.source),e.pending.length=0),e.pending.length){for(const[s,n,i]of e.pending)t.updateTexture(e.texture,s,n,i);e.pending.length=0}return e.texture}}var ca='Fredoka, Nunito, "Varela Round", system-ui, sans-serif',bs="rgba(10,16,30,0.75)";function ha(t,e){var s,n,i,a,o,r;const h=(s=t.size)!=null?s:40,l=t.outline?t.outline===!0?bs:t.outline:null,c=l?(n=t.outlineWidth)!=null?n:Math.max(h*.12,3):0,f=t.shadow&&e?t.shadow===!0?bs:t.shadow:null,u=f?(i=t.shadowBlur)!=null?i:h*.25:0;return{size:h,font:(a=t.font)!=null?a:ca,weight:(o=t.weight)!=null?o:700,color:(r=t.color)!=null?r:"#FBEFE3",outline:l,ow:c,shadow:f,blur:u,pad:c/2+u*1.2+2,th:h*1.25}}var fa=(t,e)=>"".concat(t.weight," ").concat(t.size*e,"px ").concat(t.font);function ua(t,e,s,n,i,a){t.scale(n,n),t.font=fa(s,1),t.textBaseline="middle",t.textAlign="left",t.lineJoin="round",s.shadow&&(t.shadowColor=s.shadow,t.shadowBlur=s.blur*n),s.outline&&(t.strokeStyle=s.outline,t.lineWidth=s.ow,t.strokeText(e,i,a),t.shadowColor="transparent"),t.fillStyle=s.color,t.fillText(e,i,a)}var gs=null;function da(t,e,s){return gs!=null||(gs=document.createElement("canvas").getContext("2d")),gs.font=fa(e,s),gs.measureText(t).width/s}var vs=class extends Ke{constructor(t,e,s={}){super(t,null),p(this,"_text"),p(this,"_style"),p(this,"dirty",!0),p(this,"bakedScale",0),p(this,"bakedFontGen",-1),p(this,"bakedEffects",!0),p(this,"capW",0),p(this,"capH",0),this._text=e;const n=s,{x:i,y:a,rotation:o,scale:r,scaleX:h,scaleY:l,alpha:c,visible:f,tint:u,blend:y,z:d,anchor:b,hitRadius:m,clip:x,mask:g,filters:v}=n,_=hn(n,["x","y","rotation","scale","scaleX","scaleY","alpha","visible","tint","blend","z","anchor","hitRadius","clip","mask","filters"]);this._style=_,this.bake(),this.set({x:i,y:a,rotation:o,scale:r,scaleX:h,scaleY:l,alpha:c,visible:f,tint:u,blend:y,z:d,hitRadius:m,clip:x,mask:g,filters:v}),b!==void 0&&(this.anchor=b)}get text(){return this._text}set text(t){const e=String(t);e!==this._text&&(this._text=e,this.dirty=!0)}get style(){return this._style}set style(t){this._style=A(A({},this._style),t),this.dirty=!0}bitmap(){const t=this._style.bitmapFont;if(!t)return null;const e=typeof t=="string"?this.kernel.bitmapFont(t):t;if(this.autoAnchor){const s=this._style.align;this.anchorX=s==="left"?0:s==="right"?1:.5,this.anchorY=.5}return e}get naturalWidth(){var t;const e=this.bitmap();return e?e.measure(this._text)*(((t=this._style.size)!=null?t:e.size)/e.size):super.naturalWidth}get naturalHeight(){var t;const e=this.bitmap();return e?e.lineHeight*(((t=this._style.size)!=null?t:e.size)/e.size):super.naturalHeight}frameNow(){return this._style.bitmapFont?null:this.bake()}draw(t,e,s){var n;const i=this.bitmap();if(!i)return super.draw(t,e,s);const a=((n=this._style.size)!=null?n:i.size)/i.size,o=i.measure(this._text)*a,r=i.lineHeight*a,h=this.width,l=this.height,c=o>0?h/o:1,f=r>0?l/r:1;i.run(this._text,t,this.world,-this.anchorX*h,-this.anchorY*l,a*c,a*f,s,e,this.blend)}destroy(){this._frame&&this.kernel.atlas.release(this._frame),super.destroy()}bake(){const t=this.kernel;if(this._style.bitmapFont)return null;const e=t.pixelScale,s=t.effects;return!this.dirty&&e===this.bakedScale&&t.fontGen===this.bakedFontGen&&s===this.bakedEffects&&t.atlas.valid(this._frame)?this._frame:this.rebake()}rebake(){var t;const e=this.kernel,s=e.pixelScale,n=e.effects;this.dirty=!1,this.bakedScale=s,this.bakedFontGen=e.fontGen,this.bakedEffects=n;const i=ha(this._style,n),{pad:a,th:o}=i,r=da(this._text,i,s),h=(r+a*2)*s,l=(o+a*2)*s,c=(t=this._style.align)!=null?t:"center",f=c==="left"?a:c==="right"?a+r:a+r/2,u=b=>ua(b,this._text,i,s,a,a+o/2),y=this._frame;let d=null;return y&&e.atlas.valid(y)&&y.scale===s&&(d=e.atlas.rebake(y,h,l,u,this.capW,this.capH),d?Object.assign(d,{ox:f,oy:a+o/2,margin:a}):e.atlas.release(y)),d||(this.capW=Math.ceil(h*1.25+16),this.capH=Math.ceil(l),d=e.atlas.bake(this.capW,this.capH,u,s,f,a+o/2,a),d.w=Math.ceil(h),d.h=Math.ceil(l)),this._frame=d,this.autoAnchor&&this.useFrameAnchor(),this._w=this._h=null,d}},Rt=(t,e=0)=>{const s=Number(t);return Number.isFinite(s)?s:e};function Vs(t){var e,s,n,i,a,o;typeof t=="string"&&/^\s*[{[]/.test(t)&&(t=JSON.parse(t));const r={size:0,lineHeight:0,base:0,pages:[],chars:[],kernings:[]},h=(l,c)=>{var f;l==="info"?r.size=Math.abs(Rt(c.size)):l==="common"?(r.lineHeight=Rt(c.lineHeight),r.base=Rt(c.base)):l==="page"?r.pages[Rt(c.id)]=String((f=c.file)!=null?f:""):l==="char"?r.chars.push({id:Rt(c.id),x:Rt(c.x),y:Rt(c.y),width:Rt(c.width),height:Rt(c.height),xoffset:Rt(c.xoffset),yoffset:Rt(c.yoffset),xadvance:Rt(c.xadvance),page:Rt(c.page)}):r.kernings.push({first:Rt(c.first),second:Rt(c.second),amount:Rt(c.amount)})};if(typeof t=="object"){const l=t;h("info",(e=l.info)!=null?e:{}),h("common",(s=l.common)!=null?s:{});for(const[c,f]of((n=l.pages)!=null?n:[]).entries())h("page",{id:c,file:f});for(const c of(i=l.chars)!=null?i:[])h("char",c);for(const c of(a=l.kernings)!=null?a:[])h("kerning",c)}else{const l=/(?:^|<)\s*(info|common|page|char|kerning)\s([^\n<>]*)/gm,c=/(\w+)=(?:"([^"]*)"|([^\s/>]+))/g;for(let f=l.exec(t);f;f=l.exec(t)){const u={};for(let y=c.exec(f[2]);y;y=c.exec(f[2]))u[y[1]]=(o=y[2])!=null?o:y[3];h(f[1],u)}}return r.size||(r.size=r.lineHeight),r}var qn=class{constructor(t,e,s,n=null,i=null){p(this,"baker",n),p(this,"host",i),p(this,"size"),p(this,"lineHeight"),p(this,"base"),p(this,"ascii",new Array(128)),p(this,"more",new Map),p(this,"kern",new Map),p(this,"bScale",0),p(this,"bFontGen",-1),p(this,"bEffects",!1),p(this,"bGen",-1),this.size=t,this.lineHeight=e,this.base=s}set(t,e){t<128?this.ascii[t]=e:this.more.set(t,e)}setKerning(t,e,s){this.kern.set(t*1114112+e,s)}prepare(){const t=this.host;if(!(!t||t.pixelScale===this.bScale&&t.fontGen===this.bFontGen&&t.effects===this.bEffects&&t.atlas.gen===this.bGen)){this.bScale=t.pixelScale,this.bFontGen=t.fontGen,this.bEffects=t.effects,this.bGen=t.atlas.gen;for(const e of this.ascii)e&&t.atlas.release(e.frame);for(const e of this.more.values())e&&t.atlas.release(e.frame);this.ascii.fill(void 0),this.more.clear()}}glyph(t){let e=t<128?this.ascii[t]:this.more.get(t);return(e===void 0||e&&this.host&&!this.host.atlas.valid(e.frame))&&(e=this.baker?this.baker(t):null,this.set(t,e)),e}kerning(t,e){var s;return this.kern.size&&(s=this.kern.get(t*1114112+e))!=null?s:0}measure(t){return this.run(t)}run(t,e,s,n=0,i=0,a=1,o=1,r=0,h=1,l="normal"){this.prepare();let c=0,f=-1;for(let u=0;u<t.length;u++){let y=t.charCodeAt(u);y>=55296&&y<56320&&u+1<t.length&&(y=t.codePointAt(u),u++),f>=0&&(c+=this.kerning(f,y)),f=y;const d=this.glyph(y);d&&(e&&d.w>0&&d.h>0&&(zs(s,n+(c+d.x)*a,i+d.y*o),e.r.quad(e.tex(d.frame.surface),d.frame,Et,d.w*a,d.h*o,r,h,l)),c+=d.advance)}return c}};function nl(t,e){const s=new qn(t.size,t.lineHeight,t.base);for(const n of t.chars){const i=e[n.page];if(!i)continue;const a={surface:i,x:n.x,y:n.y,w:n.width,h:n.height,scale:1,gen:0,ox:0,oy:0,margin:0};s.set(n.id,{frame:a,x:n.xoffset,y:n.yoffset,w:n.width,h:n.height,advance:n.xadvance})}for(const n of t.kernings)s.setKerning(n.first,n.second,n.amount);return s}function il(t,e){var s,n;const i=A({},e),a=(s=e.size)!=null?s:40,o=h=>{const l=String.fromCodePoint(h),c=t.pixelScale,f=ha(i,t.effects),u=da(l,f,c),y=t.atlas.bake((u+f.pad*2)*c,(f.th+f.pad*2)*c,d=>ua(d,l,f,c,f.pad,f.pad+f.th/2),c);return{frame:y,x:-f.pad,y:-f.pad,w:y.w/c,h:y.h/c,advance:u}},r=new qn(a,a*1.25,a,o,t);r.prepare();for(const h of(n=e.chars)!=null?n:"0123456789")r.glyph(h.codePointAt(0));return r}var al=.5;function pa(t){const e=[];for(const[s,n]of[["left",J.leftWrist],["right",J.rightWrist]]){const i=t[n*3],a=t[n*3+1],o=t[n*3+2];i!==void 0&&a!==void 0&&Number.isFinite(i)&&Number.isFinite(a)&&(o!=null?o:0)>=al&&e.push({side:s,x:i,y:a})}return e}var Ks=t=>Rs[((t-1)%Rs.length+Rs.length)%Rs.length],rl=["left","right"];function ya(t,e,s,n,i=()=>null,a={}){var o,r;const h=[];for(const l of t){const c=(o=i(l))!=null?o:l.body;if(Array.isArray(c)){if(a.orientation==="portrait"){for(const f of rl){let u=ir(c,f,{orientation:"portrait"});a.hold&&(u=a.hold.at(ii.key(l.id,f),u,(r=a.t)!=null?r:0)),u&&h.push({player:l.id,side:f,x:u.x*s,y:u.y*n,color:Ks(l.id)})}continue}for(const f of pa(c)){const u=e(f);h.push({player:l.id,side:f.side,x:u.x*s,y:u.y*n,color:Ks(l.id)})}}}return h}function Wn(t,e,s,n=0){const i=t.world,a=co(i,e,s);if(!a)return!1;const o=Math.hypot(i[0],i[1])||1,r=Math.hypot(i[2],i[3])||1,[h,l]=a;if(t.hitRadius!=null){const d=t.hitRadius+n/((o+r)/2);return h*h+l*l<=d*d}const c=-t.anchorX*t.width-n/o,f=-t.anchorY*t.height-n/r,u=(1-t.anchorX)*t.width+n/o,y=(1-t.anchorY)*t.height+n/r;return h>=c&&h<=u&&l>=f&&l<=y}function ma(t,e,s,n=0){for(const i of e)if((s===void 0||i.player===s)&&Wn(t,i.x,i.y,n))return i;return null}function ol(t){var e;switch(t.type){case"circle":case"ring":case"star":return[t.r*2,t.r*2];case"ellipse":return[t.rx*2,t.ry*2];case"roundRect":return[t.w,t.h];case"line":return[t.length,(e=t.lw)!=null?e:4];case"path":return t.r?[t.r*2,t.r*2]:[t.size,t.size]}}function ll(t){var e,s,n;const i=t.type==="line"?0:t.stroke?((e=t.lw)!=null?e:2)/2:0,a=t.shadow?t.shadow.blur*1.5+Math.max(Math.abs((s=t.shadow.x)!=null?s:0),Math.abs((n=t.shadow.y)!=null?n:0)):0;return Math.ceil(i+a+1)}var cl=(t,e)=>e||!t.shadow?t:We(A({},t),{shadow:void 0});function xa(t,e,s){const n=ll(e),i=e.type==="roundRect",[a,o]=i?[Math.min(e.w,e.r*2+4/s),Math.min(e.h,e.r*2+4/s)]:ol(e),r=(a+n*2)*s,h=(o+n*2)*s;return{frame:t.bake(r,h,c=>{c.scale(s,s),c.translate(n+a/2,n+o/2),hl(c,e,a,o)},s,n+a/2,n+o/2,n),slice:i?Math.ceil((e.r+n)*s):0,w:i?e.w:a,h:i?e.h:o}}function hl(t,e,s,n){var i,a,o,r,h,l,c;t.lineJoin="round",t.lineCap="round";const f=new Path2D;switch(e.type){case"circle":case"ring":f.arc(0,0,e.r,0,Math.PI*2);break;case"ellipse":f.ellipse(0,0,e.rx,e.ry,0,0,Math.PI*2);break;case"roundRect":f.roundRect(-s/2,-n/2,s,n,Math.min(e.r,s/2,n/2));break;case"star":{const m=(i=e.points)!=null?i:5,x=e.r*((a=e.inner)!=null?a:.5);for(let g=0;g<m*2;g++){const v=g%2?x:e.r,_=-Math.PI/2+g*Math.PI/m;g?f.lineTo(Math.cos(_)*v,Math.sin(_)*v):f.moveTo(Math.cos(_)*v,Math.sin(_)*v)}f.closePath();break}case"line":f.moveTo(-s/2+n/2,0),f.lineTo(s/2-n/2,0);break;case"path":{const m=e.r?e.r*2/e.size:1,x=new DOMMatrix([m,0,0,m,-e.size/2*m,-e.size/2*m]);f.addPath(new Path2D(e.d),x);break}}const u=e.shadow,y=()=>{var m,x;if(!u)return;const g=t.getTransform();t.shadowColor=u.color,t.shadowBlur=u.blur*g.a,t.shadowOffsetX=((m=u.x)!=null?m:0)*g.a,t.shadowOffsetY=((x=u.y)!=null?x:0)*g.a},d=()=>{t.shadowColor="transparent",t.shadowBlur=0};if(e.type==="line"){y(),t.strokeStyle=(r=(o=e.stroke)!=null?o:e.fill)!=null?r:"#fff",t.lineWidth=n,t.stroke(f);return}const b=e.type==="ring";if(e.outlineBelow&&e.fill&&e.stroke&&!b){y(),t.strokeStyle=e.stroke,t.lineWidth=(h=e.lw)!=null?h:2,t.stroke(f),d(),t.fillStyle=e.fill,t.fill(f);return}e.fill&&!b&&(y(),t.fillStyle=e.fill,t.fill(f),d()),(e.stroke||b)&&((!e.fill||b)&&y(),b&&e.fill&&(t.fillStyle=e.fill,t.fill(f)),t.strokeStyle=(l=e.stroke)!=null?l:"#fff",t.lineWidth=(c=e.lw)!=null?c:2,t.stroke(f),d())}var ba=class{constructor(){if(p(this,"ctx",null),p(this,"master",null),p(this,"buffers",new Map),p(this,"held",!1),p(this,"muted",!1),p(this,"volume",1),typeof addEventListener=="function"){const t=()=>{var e;(e=this.context())==null?void 0:e.resume().catch(()=>{})};for(const e of["pointerdown","keydown","touchstart"])addEventListener(e,t,{once:!0,capture:!0})}}context(){var t;if(this.ctx)return this.ctx;const e=(t=le.AudioContext)!=null?t:le.webkitAudioContext;if(!e)return null;try{this.ctx=new e,this.master=this.ctx.createGain(),this.master.connect(this.ctx.destination),this.held&&this.ctx.suspend()}catch(s){return null}return this.ctx}load(t,e){return je(this,null,function*(){const s=this.context();if(!s)return;const n=yield(yield fetch(e)).arrayBuffer();this.buffers.set(t,yield s.decodeAudioData(n))})}has(t){return this.buffers.has(t)}play(t,e={}){var s,n,i;const a=this.context(),o=this.buffers.get(t);if(!a||!o||!this.audible)return()=>{};const r=a.createBufferSource();r.buffer=o,r.loop=(s=e.loop)!=null?s:!1,r.playbackRate.value=(n=e.rate)!=null?n:1;const h=a.createGain();return h.gain.value=((i=e.volume)!=null?i:1)*this.volume,r.connect(h).connect(this.master),r.start(),()=>{try{r.stop()}catch(l){}}}tone(t,e=.25,s={}){var n,i;const a=this.context();if(!(!a||!this.audible))try{const o=a.createOscillator(),r=a.createGain();o.type=(n=s.type)!=null?n:"sine",o.frequency.setValueAtTime(t,a.currentTime),s.to&&o.frequency.exponentialRampToValueAtTime(s.to,a.currentTime+e),r.gain.setValueAtTime(((i=s.volume)!=null?i:.12)*this.volume,a.currentTime),r.gain.exponentialRampToValueAtTime(.001,a.currentTime+e),o.connect(r).connect(this.master),o.start(),o.stop(a.currentTime+e)}catch(o){}}get audible(){return!this.muted&&!this.held}hold(){var t;this.held=!0,(t=this.ctx)==null||t.suspend().catch(()=>{})}release(){var t;this.held=!1,(t=this.ctx)==null||t.resume().catch(()=>{})}destroy(){var t;(t=this.ctx)==null||t.close().catch(()=>{}),this.ctx=null}},fl={high:{resolution:1.5,particles:1,effects:!0,maxBlur:32},medium:{resolution:1,particles:.5,effects:!1,maxBlur:16},low:{resolution:.75,particles:.2,effects:!1,maxBlur:0}},fe=["high","medium","low"];function ze(t){const e=fl[t];return We(A({name:t},e),{scale:s=>s<=0?0:Math.max(1,Math.round(s*e.particles))})}var ul=t=>fe[Math.min(fe.indexOf(t)+1,fe.length-1)],Zs=(t,e)=>{if(!t.length)return NaN;const s=[...t].sort((n,i)=>n-i);return s[Math.min(s.length-1,Math.max(0,Math.floor(e*(s.length-1)+.5)))]},dl=12,pl=t=>Js(t,.5);function Js(t,e=.1){const s=Zs(t,e);if(!Number.isFinite(s))return 1e3/60;const n=[144,120,90,75,60,50,30];let i=60;for(const a of n)Math.abs(1e3/a-s)<Math.abs(1e3/i-s)&&(i=a);return 1e3/i}function ga(t,e){const s=e.refresh!==void 0&&Number.isFinite(e.refresh)&&e.refresh>0?e.refresh:Js(e.intervals),n=Zs(e.intervals,.5),i=Zs(e.intervals,.9),a=Zs(e.cpu,.5);if(!Number.isFinite(n))return t==="canvas2d"?"low":"medium";const o=h=>h<=s*1.25,r=h=>!Number.isFinite(a)||a<s*h;return t==="canvas2d"?o(i)&&r(.25)?"medium":"low":o(i)&&r(.5)?"high":o(n)?"medium":"low"}function yl(t,e){return t.length<30?!1:t.filter(n=>n>e*1.5).length/t.length>.5}var va="0.1.1",ml=720*3600*1e3,xl=(t,e,s)=>"fabi-play.engine-tier:".concat(va,":").concat(t,":").concat(e,":").concat(s),bl=(t,e,s)=>"fablee-engine-tier:".concat(va,":").concat(t,":").concat(e,":").concat(s);function gl(t,e,s=Date.now()){var n;try{const i=JSON.parse((n=t==null?void 0:t.getItem(e))!=null?n:"null");if(i&&fe.includes(i.tier)&&typeof i.at=="number"&&s-i.at<ml)return typeof i.refresh=="number"&&i.refresh>0?{name:i.tier,refresh:i.refresh}:{name:i.tier}}catch(i){}return null}function ka(t,e,s,n,i=Date.now()){try{t==null||t.setItem(e,JSON.stringify(n!==void 0&&Number.isFinite(n)?{tier:s,at:i,refresh:n}:{tier:s,at:i}))}catch(a){}}function vl(t=typeof location!="undefined"?location.search:""){const e=new URLSearchParams(t).get("tier");return fe.includes(e)?e:void 0}function wa(t,e){const s=e==null?void 0:e.tier;if(fe.includes(s))return t==="canvas2d"&&s==="high"?"medium":s}var _a=t=>typeof(t==null?void 0:t.hz)=="number"&&t.hz>=20&&t.hz<=240?Js([1e3/t.hz],.5):NaN,Ma=(t,e)=>fe.indexOf(t)>=fe.indexOf(e)?t:e;function kl(t,e,s){return t?{name:t,from:"forced"}:e?{name:s?Ma(e,s):e,from:"hint"}:s?{name:s,from:"cache"}:null}var wl=/^\s*(<|>|[^+\-<>=\s][^+=]*?)?\s*(?:([+-])=\s*(\d*\.?\d+))?\s*$/,Ea=class{constructor(t={}){p(this,"steps",[]),p(this,"labels",new Map),p(this,"end",0),p(this,"prevStart",0),p(this,"elapsed",0),p(this,"iter",0),p(this,"last",0),p(this,"delayLeft"),p(this,"_paused"),p(this,"done",!1),p(this,"rewinding",!1),p(this,"promise"),p(this,"resolve"),p(this,"repeat"),p(this,"yoyo"),p(this,"onComplete");var e,s;this.repeat=Math.floor((e=t.repeat)!=null?e:0),this.yoyo=!!t.yoyo,this.delayLeft=(s=t.delay)!=null?s:0,this._paused=!!t.paused,this.onComplete=t.onComplete,this.promise=new Promise(n=>this.resolve=n)}get duration(){return this.end}get time(){return this.last}get paused(){return this._paused}get finished(){return this.done}at(t){if(t===void 0)return this.end;if(typeof t=="number")return Math.max(t,0);const e=wl.exec(t);if(!e)throw new Error('[engine] timeline: bad position "'.concat(t,'"'));const[,s,n,i]=e,a=i?(n==="-"?-1:1)*Number(i):0;let o=this.end;if(s==="<")o=this.prevStart;else if(s&&s!==">"){const r=this.labels.get(s.trim());r===void 0?this.labels.set(s.trim(),this.end):o=r}return Math.max(o+a,0)}add(t){let e=this.steps.length;for(;e>0&&this.steps[e-1].start>t.start;)e--;return this.steps.splice(e,0,t),this.prevStart=t.start,this.end=Math.max(this.end,t.start+t.dur),this}to(t,e,s,n="quadOut"){var i,a;const o=typeof n=="object"?n:{ease:n},r=typeof o.ease=="function"?o.ease:fs[(i=o.ease)!=null?i:"quadOut"];return this.add({target:t,to:e,from:null,fn:null,start:this.at(o.at)+((a=o.delay)!=null?a:0),dur:Math.max(s,0),ease:r,onUpdate:o.onUpdate,p:-1})}set(t,e,s){return this.add({target:t,to:e,from:null,fn:null,start:this.at(s),dur:0,ease:fs.linear,p:-1})}call(t,e){return this.add({target:null,to:null,from:null,fn:t,start:this.at(e),dur:0,ease:fs.linear,p:-1})}label(t,e){return this.labels.set(t,this.at(e)),this}wait(t){return this.end+=Math.max(t,0),this.prevStart=this.end,this}pause(){return this._paused=!0,this}resume(){return this._paused=!1,this}stop(){this.done||(this.done=!0,this.resolve())}seek(t){const e=Math.min(typeof t=="string"&&this.labels.has(t)?this.labels.get(t):this.at(t),this.end),s=this.yoyo&&this.iter%2===1;return this.elapsed=this.iter*this.end+(s?this.end-e:e),this.render(e),this}then(t,e){return this.promise.then(t,e)}update(t){if(this._paused||this.done)return;if(this.delayLeft>0){if(this.delayLeft-=t,this.delayLeft>0)return;t=-this.delayLeft,this.delayLeft=0}const e=this.end;if(e<=0)return this.render(0),this.complete();this.elapsed+=t;const s=this.repeat<0?1/0:e*(this.repeat+1),n=Math.min(this.elapsed,s),i=n>=s?this.repeat:Math.floor(n/e);for(;this.iter<i;){const o=this.yoyo&&this.iter%2===1;this.render(o?0:e),this.iter++,this.yoyo||(this.rewinding=!0,this.render(0),this.rewinding=!1)}const a=n-i*e;this.render(this.yoyo&&i%2===1?e-a:a),n>=s&&this.complete()}complete(){var t;this.done||(this.done=!0,(t=this.onComplete)==null||t.call(this),this.resolve())}render(t){const e=this.steps;if(t>=this.last)for(let s=0;s<e.length;s++){const n=e[s];t>=n.start&&this.apply(n,t)}else for(let s=e.length-1;s>=0;s--){const n=e[s];n.p>=0&&this.apply(n,t)}this.last=t}apply(t,e){var s,n;const i=t.dur>0?Math.min(Math.max((e-t.start)/t.dur,0),1):e>t.start||e===t.start&&!this.rewinding?1:0;if(i===t.p)return;if(t.p=i,t.fn){this.rewinding||t.fn();return}const a=t.target;if(a.destroyed||a._free)return;const o=t.to;if(!t.from){t.from={};for(const h in o)t.from[h]=Number((s=a[h])!=null?s:0)}const r=t.ease(i);for(const h in o)a[h]=t.from[h]+(o[h]-t.from[h])*r;(n=t.onUpdate)==null||n.call(t,r)}},Aa=class{constructor(){p(this,"list",[]),p(this,"timelines",[])}timeline(t){const e=new Ea(t);return this.timelines.push(e),e}tween(t,e,s,n="quadOut"){var i;const a=typeof n=="object"?n:{ease:n},o=typeof a.ease=="function"?a.ease:fs[(i=a.ease)!=null?i:"quadOut"];let r;const h=new Promise(l=>{var c;const f=Object.keys(e),u=new Float64Array(f.length);f.forEach((y,d)=>u[d]=Number(e[y])),r={target:t,keys:f,to:u,from:new Float64Array(f.length),started:!1,duration:Math.max(s,0),time:0,delay:(c=a.delay)!=null?c:0,ease:o,onUpdate:a.onUpdate,done:l,dead:!1}});return this.list.push(r),Object.assign(h,{stop:()=>this.finish(r)})}stopAll(t){const e=this.list;for(let s=0;s<e.length;s++)e[s].target===t&&this.finish(e[s])}get size(){return this.list.length}update(t){if(this.timelines.length){let n=0;const i=this.timelines;for(let a=0;a<i.length;a++){const o=i[a];o.update(t),o.finished||(i[n++]=o)}i.length=n}const e=this.list;if(!e.length)return;let s=0;for(let n=0;n<e.length;n++){const i=e[n];i.dead||this.step(i,t),i.dead||(e[s++]=i)}s!==e.length&&(e.length=s)}step(t,e){var s,n;if(t.target.destroyed)return this.finish(t);let i=e;if(t.delay>0){if(t.delay-=e,t.delay>0)return;i=-t.delay}const a=t.keys;if(!t.started){t.started=!0;for(let h=0;h<a.length;h++)t.from[h]=Number((s=t.target[a[h]])!=null?s:0)}t.time+=i;const o=t.duration>0?Math.min(t.time/t.duration,1):1,r=t.ease(o);for(let h=0;h<a.length;h++)t.target[a[h]]=t.from[h]+(t.to[h]-t.from[h])*r;(n=t.onUpdate)==null||n.call(t,r),o>=1&&this.finish(t)}finish(t){t.dead||(t.dead=!0,t.done())}clear(){for(const t of this.list)this.finish(t);this.list.length=0;for(const t of this.timelines)t.stop();this.timelines=[]}},Ft=720,Sa=class extends Ne{constructor(t,e){super(t),p(this,"paintAll",e)}draw(t,e){this.paintAll(t,e)}},_l=class extends Ne{constructor(t,e){super(t),p(this,"paintAll",e)}draw(t,e){this.paintAll(t,e)}},ue=()=>performance.now(),Ta=t=>{const e=lr(t);return e&&Object.freeze(e)};function Ml(){return je(this,arguments,function*(t={}){var e,s,n,i,a,o,r,h,l,c,f;const u=(e=t.play)!=null?e:null;let y=(s=t.canvas)!=null?s:null;y||(y=document.createElement("canvas"),y.style.cssText="position:fixed;top:0;left:0;width:100%;height:100%;display:block;touch-action:none",document.body.appendChild(y));let d=Bn(y,{renderer:(n=t.renderer)!=null?n:Zo(),failIfMajorPerformanceCaveat:t.failIfMajorPerformanceCaveat,instancing:t.instancing});y=d.canvas;const b=new Set,m=new Tn(Math.min(2048,d.maxTextureSize),4);m.onPage=k=>b.add(k),m.onDrop=k=>{b.delete(k),k.texture&&d.destroyTexture(k.texture),k.texture=null};let x=Qs(d);const g=new Aa,v=new ba,_=new Xn(m),T=new Map,N=new Map,R=new Map,M=new Map,P=new Map,z=new Set;let U=0;const G=(i=t.tier)!=null?i:vl(),O=String((a=d.info.renderer)!=null?a:""),X=(()=>{var k;try{return(k=le.localStorage)!=null?k:null}catch(S){return null}})(),L=typeof screen!="undefined"?"".concat(screen.width,"x").concat(screen.height):"",lt=xl(d.kind,O,L);pr(X,lt,bl(d.kind,O,L));const yt=gl(X,lt),$=kl(G,wa(d.kind,u==null?void 0:u.device),yt==null?void 0:yt.name);let w=(o=$==null?void 0:$.name)!=null?o:"medium",H=ze(w);_.setTier(w);let W=($==null?void 0:$.from)==="hint",bt=yt==null?void 0:yt.name,Z=(r=yt==null?void 0:yt.refresh)!=null?r:_a(u==null?void 0:u.device),j=1,se=1,Ae=1;const At={atlas:m,get pixelScale(){return j},get fontGen(){return U},get effects(){return H.effects},tweens:g,frame:k=>rn.frame(k),shape:k=>{const S=H.effects,I=S?j:-j;let E=T.get(I);E||(T.size>=8&&T.clear(),T.set(I,E=new Wi(2e3)));const V=ke(k);let q=E.get(k,V);return(!q||!m.valid(q.frame))&&E.set(k,q=xa(m,cl(k,S),j),V),q},bitmapFont:k=>rn.bitmapFont(k)};let Ot=1280,Kt=null;class sn extends An{get width(){return Ot}set width(S){}get height(){return Ft}set height(S){}get safe(){const S=Math.min(Ot,Ft*16/9);return{x:(Ot-S)/2,y:0,w:S,h:Ft}}}const qt=new sn(At),K=()=>{var k;const S=d.canvas,I=S.getBoundingClientRect();se=Math.max(1,I.width||S.clientWidth||innerWidth),Ae=Math.max(1,I.height||S.clientHeight||innerHeight),Ot=Ft*se/Ae;const E=Math.min(le.devicePixelRatio||1,(k=t.maxPixelRatio)!=null?k:2);if(Ae*E/Ft<=H.resolution){const q=Math.max(1,Math.round(Ae*E));j=q/Ft,d.resize(Math.max(1,Math.round(se*E)),q)}else j=H.resolution,d.resize(Math.round(Ot*j),Math.round(Ft*j));Kt&&Kt.style.setProperty("--unit","".concat(Ae/Ft,"px"))};addEventListener("resize",K);const gt=k=>{w=k,H=ze(k),_.setTier(k),K()},mt=typeof ResizeObserver!="undefined"?new ResizeObserver(K):null;mt==null||mt.observe(y);let St=(u==null?void 0:u.backdrop)==="video"?"video":"none",et=(h=u==null?void 0:u.view)!=null?h:null,pe=(u==null?void 0:u.orientation)==="portrait"?"portrait":"landscape",it=(l=Ta(u==null?void 0:u.safeArea))!=null?l:or,De=[],ws=-1/0,Be=!1,Ue=!1;const _s=new Set,Ms=()=>{const k=St==="video"?"transparent":"";document.documentElement.style.background=k,document.body.style.background=k},Wt=(k,S)=>{const I=k==="video"?"video":"none",E=S!=null?S:null;if(!(I===St&&(E===et||E&&et&&E.x===et.x&&E.y===et.y&&E.w===et.w&&E.h===et.h))){St=I,et=E,Ms();for(const V of[..._s])V(St,et)}},jt=[];if(u){const k=E=>{Array.isArray(E)&&(De=E,ws=ue())},S=E=>{Be=E,is()},I=E=>{if(G||W)return;Number.isFinite(Z)||(Z=_a(E));const V=wa(d.kind,E);V&&(W=!0,gt(bt?Ma(V,bt):V))};jt.push(u.on("start",E=>I(E==null?void 0:E.device)),u.on("start",E=>{((E==null?void 0:E.orientation)==="portrait"||(E==null?void 0:E.orientation)==="landscape")&&(pe=E.orientation);const V=Ta(E==null?void 0:E.safeArea);V&&(it=V)}),u.on("start",E=>{typeof(E==null?void 0:E.muted)=="boolean"&&(v.muted=E.muted)}),u.on("frame",E=>k(E==null?void 0:E.players)),u.on("players",E=>k(E==null?void 0:E.players)),u.on("backdrop",E=>Wt(E==null?void 0:E.backdrop,E==null?void 0:E.view)),u.on("start",E=>{var V;return Wt(E==null?void 0:E.backdrop,(V=E==null?void 0:E.view)!=null?V:u.view)}),u.on("pause",()=>S(!0)),u.on("resume",()=>S(!1)),u.on("break-start",()=>S(!0)),u.on("break-done",()=>S(!1)),u.on("break-end",()=>S(!1))),v.muted=u.muted===!0}Ms();const is=()=>Be||Ue||document.hidden?v.hold():v.release();let C=-1,B=[],Y=0;const st=()=>ue()-ws<1e3?De:[],at=k=>u?u.toScreen(k):ni(et,k),Pt=new ii,Se=()=>{if(C===Y)return B;C=Y;const k=pe==="portrait",S=St==="video"&&!k||!(u!=null&&u.smoothedBody)?()=>null:I=>u.smoothedBody(I);return B=ya(st(),at,Ot,Ft,S,k?{orientation:pe,hold:Pt,t:ue()}:void 0),B},zt={x:0,y:0,w:1,h:1},nn=()=>(zt.x=et?et.x*Ot:0,zt.y=et?et.y*Ft:0,zt.w=et?et.w*Ot:Ot,zt.h=et?et.h*Ft:Ft,zt),Zt=k=>{var S;const I=(S=k.alpha)!=null?S:1,E=k.tags?new Hn(m,k):null;E&&z.add(E);const V=typeof k.tags=="function"?k.tags:q=>String(q);return(q,kt)=>{var Tt,wt,Dt,Te,Ce,ct;if(St==="video")return;const nt=nn();for(const rt of st()){const ot=(wt=(Tt=u==null?void 0:u.smoothedBody)==null?void 0:Tt.call(u,rt))!=null?wt:rt.body,Bt=(ct=Is((Ce=(Te=(Dt=u==null?void 0:u.avatarOf)==null?void 0:Dt.call(u,rt))!=null?Te:rt.avatar)!=null?Ce:""))!=null?ct:ls;if(!_.draw(q.r,q.tex,ot,Bt,nt,I*kt,j)||!E)continue;const Ge=V(rt.id);Ge&&E.draw(q.r,q.tex,ot,Bt,nt,Ge,Ks(rt.id),I*kt,j,Ot,Ft)}}},re=new Set,ye=new Set,Lt=new Set;let Yt=!1,me=0,Nt=0,oe=0;const xe={fps:0,cpuMs:0,drawCalls:0,quads:0,filtersSkipped:0};let He=0,Vn=0,Kn=ue();const Es=[];let an=0;const za=()=>({r:d,kernel:At,tex:x});let Da=za();const mc=()=>{if(d.lost)return;const[k,S]=St==="video"||t.background===void 0?[0,0]:ne(t.background);d.time=oe,d.maxBlur=H.maxBlur,d.begin(k,S,j),ce(qt.world,null,qt.x,qt.y,qt.rotation,qt.scaleX,qt.scaleY),Ni(Da,qt,qt.alpha,qt.tint);const I=d.end();xe.drawCalls=I.drawCalls,xe.quads=I.quads,xe.filtersSkipped=I.filtersSkipped},Ba=k=>{var S;if(!Yt)return;me=requestAnimationFrame(Ba);const I=Math.min(Math.max((k-Nt)/1e3,0),.1);Nt&&Es.push(k-Nt),Nt=k,Y++;const E=ue(),V=Be||Ue;if(!V){oe+=I,g.update(I);for(const q of Lt)q.destroyed||q.update(I);for(const q of re)q(I,oe)}for(const q of ye)q(I);qt.sweep();for(const q of Lt)q.destroyed&&Lt.delete(q);if(d.lost?(an||(an=k),k-an>3e3&&xc()):(an=0,mc()),He++,Vn+=ue()-E,E-Kn>=1e3&&(xe.fps=Math.round(He*1e3/(E-Kn)),xe.cpuMs=Math.round(Vn/Math.max(He,1)*100)/100,(S=u==null?void 0:u.reportStats)==null||S.call(u,{fps:xe.fps,renderer:d.kind,tier:w}),He=0,Vn=0,Kn=E),Es.length>=180){const q=Number.isFinite(Z)?Z:Js(Es);!G&&!V&&yl(Es,q)&&w!=="low"&&(gt(ul(w)),bt=w,ka(X,lt,w,Number.isFinite(Z)?Z:void 0),console.info("[engine] slow frames: tier ".concat(w))),Es.length=0}},xc=()=>{const k=Un(d.canvas),S=Pn(k);if(S){console.warn("[engine] WebGL context lost for good: switching to Canvas 2D"),d.destroy(),d=S;for(const I of b)I.texture=null;for(const I of m.pages)b.add(I.surface);x=Qs(d),Da=za(),mt==null||mt.disconnect(),mt==null||mt.observe(k),K()}},Ua=()=>{is(),document.hidden||(Nt=0)};document.addEventListener("visibilitychange",Ua);const Ha=()=>{U++;for(const k of z)k.drop()};if((f=(c=document.fonts)==null?void 0:c.addEventListener)==null||f.call(c,"loadingdone",Ha),K(),!$&&t.probe!==!1&&(Number.isFinite(Z)||(Z=pl(yield El(dl))),!W)){H=ze("high"),K();const k=yield Al(d,m,()=>x,()=>j,Ot,()=>W);if(k.refresh=Z,!W){const S=ga(d.kind,k);ka(X,lt,S,Z),bt=S,gt(S)}}const rn={stage:qt,get tier(){return H},get renderer(){return d},get canvas(){return d.canvas},get pixelScale(){return j},get backdrop(){return St},get view(){return et},get orientation(){return pe},get safeArea(){return it},get paused(){return Be||Ue},sound:v,stats:xe,get time(){return oe},get supports(){const k=d.support;return{filters:k.filters,blur:k.filters&&H.maxBlur>0,shaders:k.shaders,maxBlur:k.filters?H.maxBlur:0,tiers:{high:{maxBlur:ze("high").maxBlur},medium:{maxBlur:ze("medium").maxBlur},low:{maxBlur:ze("low").maxBlur}}}},sprite:(k,S)=>new Ke(At,k,S),shape:(k,S)=>new ys(At,k,S),text:(k,S)=>new vs(At,k,S),group:k=>new An(At).set(k!=null?k:{}),particles(k,S={}){const I=typeof k=="object"&&"type"in k?At.shape(k).frame:k,E=new Bi(At,I,S),V=S,{max:q,blend:kt,gravity:Tt,drag:wt}=V,Dt=hn(V,["max","blend","gravity","drag"]);return E.set(Dt),Lt.add(E),E},tween:(k,S,I,E)=>g.tween(k,S,I,E),bake(k,S,I,E,V){return R.set(k,{w:S,h:I,draw:E,origin:V}),N.delete(k),rn.frame(k)},frame(k){var S,I,E,V;const q=N.get(k);if(q&&m.valid(q)&&(q.gen===0||q.scale===j))return q;const kt=R.get(k);if(kt){const Tt=j,wt=m.bake(kt.w*Tt,kt.h*Tt,Dt=>(Dt.scale(Tt,Tt),kt.draw(Dt)),Tt,(I=(S=kt.origin)==null?void 0:S.x)!=null?I:0,(V=(E=kt.origin)==null?void 0:E.y)!=null?V:0);return N.set(k,wt),wt}if(q)return q;throw new Error('[engine] no frame "'.concat(k,'": load it or bake it first'))},load(k){return je(this,null,function*(){yield Promise.all(Object.entries(k).map(([S,I])=>gc(S,I)))})},hands:k=>k===void 0?Se():Se().filter(S=>S.player===k),touched(k,S,I={}){var E;return k.updateWorld(),ma(k,Se(),S,(E=I.padding)!=null?E:0)},hits(k,S,I,E=0){return k.updateWorld(),Wn(k,S,I,E)},avatars:(k={})=>new Sa(At,Zt(k)),handMarkers(k={}){var S,I;const E=(S=k.radius)!=null?S:36,V=(I=k.look)!=null?I:"auto",q=new Float64Array(6),kt=Math.max(E*.12,3),Tt={type:"ring",r:E,lw:kt,fill:"rgba(251,231,184,0.3)",stroke:"#ffffff"},wt={type:"ring",r:E,lw:kt*1.8,stroke:bs,shadow:{color:bs,blur:E*.2}},Dt=(nt,rt,ot,Bt,Ge,Xe)=>{const on=rt.w/rt.scale;ce(q,null,ot-on/2,Bt-on/2,0,1,1),nt.r.quad(nt.tex(rt.surface),rt,q,on,on,Ge,Xe,"normal")},Te=nt=>{let rt=null,ot=!1;return()=>(rt&&m.valid(rt.frame)&&rt.frame.scale===j&&ot===H.effects?rt:(ot=H.effects,rt=At.shape(nt))).frame},Ce=Te(Tt),ct=Te(wt);return new _l(At,(nt,rt)=>{const ot=V==="video"||V==="auto"&&St==="video",Bt=Ce(),Ge=ot?ct():null;for(const Xe of Se())Ge&&Dt(nt,Ge,Xe.x,Xe.y,16777215,rt),Dt(nt,Bt,Xe.x,Xe.y,ne(Xe.color)[0],rt)})},timeline:k=>g.timeline(k),animation(k,S){const I=typeof k=="string"?bc(k):{frames:k},E=new Oe(At,I,S);return Lt.add(E),E},bitmapFont(k,S){if(!S){const E=M.get(k);if(!E)throw new Error('[engine] no bitmap font "'.concat(k,'": load or make it first'));return E}const I="data"in S?Ga(Vs(S.data),S.pages):il(At,S);return M.set(k,I),I},players:()=>st(),onFrame(k){return re.add(k),()=>{re.delete(k)}},onRender(k){return ye.add(k),()=>{ye.delete(k)}},onBackdrop(k){return _s.add(k),()=>{_s.delete(k)}},get hud(){return Kt||(Kt=document.createElement("div"),Kt.style.cssText="position:fixed;top:0;right:0;bottom:0;left:0;pointer-events:none;overflow:hidden",document.body.appendChild(Kt),K()),Kt},random:(k=0,S=1)=>k+Math.random()*(S-k),start(){Yt||(Yt=!0,Nt=0,me=requestAnimationFrame(Ba))},pause(){Ue=!0,is()},resume(){Ue=!1,is()},destroy(){var k,S;Yt=!1,cancelAnimationFrame(me),jt.forEach(I=>I()),removeEventListener("resize",K),mt==null||mt.disconnect(),document.removeEventListener("visibilitychange",Ua),(S=(k=document.fonts)==null?void 0:k.removeEventListener)==null||S.call(k,"loadingdone",Ha),g.clear(),wo(At),v.destroy(),d.destroy(),Kt==null||Kt.remove()}};function bc(k){const S=P.get(k);if(S)return S;const I=[...new Set([...N.keys(),...R.keys()])].filter(E=>E.startsWith(k)).sort(Mo);if(!I.length)throw new Error('[engine] no animation or frames "'.concat(k,'\u2026"'));return{frames:I}}function gc(k,S){return je(this,null,function*(){var I,E;const V=S.split("?")[0].split(".").pop().toLowerCase();if(["mp3","ogg","wav","m4a","aac","webm"].includes(V))return v.load(k,S);if(["woff","woff2","ttf","otf"].includes(V)){const wt=new FontFace(k,"url(".concat(S,")"));document.fonts.add(yield wt.load()),U++;return}const q=new URL(S,location.href);if(V==="fnt")return Xa(k,Vs(yield(yield fetch(S)).text()),q);if(V==="json"){const wt=yield(yield fetch(S)).json();if(Array.isArray(wt.chars)&&!wt.frames)return Xa(k,Vs(wt),q);const Dt=yield jn(new URL((E=(I=wt.meta)==null?void 0:I.image)!=null?E:S.replace(/\.json$/,".png"),q).href);vc(k,wt,Ds(Dt));return}const kt=yield jn(S),Tt=Ds(kt);b.add(Tt),N.set(k,{surface:Tt,x:0,y:0,w:kt.width,h:kt.height,scale:1,gen:0,ox:0,oy:0,margin:0})})}function Ga(k,S){return nl(k,S.map(I=>{const E=Ds(I);return b.add(E),E}))}function Xa(k,S,I){return je(this,null,function*(){M.set(k,Ga(S,yield Promise.all(S.pages.map(E=>jn(new URL(E,I).href)))))})}function vc(k,S,I){var E,V,q,kt,Tt,wt;b.add(I);const Dt=Array.isArray(S.frames)?S.frames:Object.entries(S.frames).map(([ct,nt])=>We(A({},nt),{filename:ct})),Te=[],Ce=[];for(const ct of Dt){const nt=ct.frame,rt=ct.filename.replace(Ca,"");ct.rotated&&console.warn("[engine] ".concat(k,"/").concat(rt," is rotated: export without rotation"));const ot={surface:I,x:nt.x,y:nt.y,w:nt.w,h:nt.h,scale:1,gen:0,ox:0,oy:0,margin:0};ct.trimmed&&ct.sourceSize&&ct.spriteSourceSize&&(ot.sw=ct.sourceSize.w,ot.sh=ct.sourceSize.h,ot.tx=ct.spriteSourceSize.x,ot.ty=ct.spriteSourceSize.y);const Bt=ct.scale9Borders;Bt&&(ot.slice=[Bt.y,((E=ot.sw)!=null?E:nt.w)-Bt.x-Bt.w,((V=ot.sh)!=null?V:nt.h)-Bt.y-Bt.h,Bt.x]),N.set("".concat(k,"/").concat(rt),ot),Te.push("".concat(k,"/").concat(rt)),Ce.push(((q=ct.duration)!=null?q:0)/1e3)}for(const[ct,nt]of Object.entries((kt=S.animations)!=null?kt:{}))P.set("".concat(k,"/").concat(ct),{frames:nt.map(rt=>"".concat(k,"/").concat(rt.replace(Ca,"")))});for(const ct of(wt=(Tt=S.meta)==null?void 0:Tt.frameTags)!=null?wt:[]){const nt=[];for(let ot=ct.from;ot<=ct.to;ot++)nt.push(ot);ct.direction==="reverse"&&nt.reverse(),ct.direction==="pingpong"&&nt.push(...nt.slice(1,-1).reverse());const rt=nt.every(ot=>Ce[ot]>0);P.set("".concat(k,"/").concat(ct.name),A({frames:nt.map(ot=>Te[ot])},rt?{durations:nt.map(ot=>Ce[ot])}:{}))}}return rn})}var Ca=/\.(png|webp|jpe?g|gif|bmp)$/i;function jn(t){return new Promise((e,s)=>{const n=new Image;n.onload=()=>e(n),n.onerror=()=>s(new Error("[engine] image did not load: ".concat(t))),n.src=t})}function El(t){return new Promise(e=>{const s=[];let n=0;const i=a=>{n&&s.push(a-n),n=a,s.length<t?requestAnimationFrame(i):e(s)};requestAnimationFrame(i)})}function Al(t,e,s,n,i,a=()=>!1){return je(this,null,function*(){const o=n(),r=xa(e,{type:"star",r:30,fill:"#ffd23f",stroke:"#3a2a10",lw:3},o).frame,h=[],l=[],c=new Float64Array(6),f=.004,u=t.kind==="canvas2d"?t.canvas.getContext("2d"):null,y=ue();let d=0;return yield new Promise(b=>{const m=x=>{d&&x-y>250&&h.push(x-d),d=x;const g=ue();t.begin(0,0,o);const v=s();for(let _=0;_<300;_++){const T=x/1e3+_;ce(c,null,_*37%i,_*53%Ft,T,1,1),t.quad(v(r.surface),r,c,r.w/o,r.h/o,16777215,f,"normal")}for(let _=0;_<40;_++)t.ellipse(100+_*20,300,20,14,_,16746496,f),t.stroke([100+_*20,400,120+_*20,460,100+_*20,520],3,18,3368703,f,!1);t.end(),u==null||u.getImageData(0,0,1,1),x-y>250&&l.push(ue()-g),x-y<750&&!a()?requestAnimationFrame(m):(t.begin(0,0,o),t.end(),b())};requestAnimationFrame(m)}),{intervals:h,cpu:l}})}var Sl=64,Ra=32,Tl=0,Cl="fabi-cm-".concat(Math.random().toString(36).slice(2,7),"-"),Fa=new Set,Pa=(t,e)=>{Fa.has(t)||(Fa.add(t),console.warn(e))},Rl=t=>new Fl(t),Fl=class{constructor(t){p(this,"r",t),p(this,"css","none"),p(this,"plans",new Wi(Sl)),p(this,"buf",new Float64Array(64)),p(this,"keys",[]),p(this,"classes",new Map),p(this,"live",new Set),p(this,"svgs",new Map),p(this,"t",0),p(this,"cur",null),p(this,"svgFn",e=>this.svg(e)),p(this,"scr",[]),p(this,"flip",0)}chain(t,e){var s,n;const i=this.r;let a=this.buf;a[0]=i.scale,a[1]=i.maxBlur;let o=2;for(let b=0;b<e.length;b++){const m=e[b];if(o+22>a.length){const g=new Float64Array(a.length*2);g.set(a),a=this.buf=g}let x=this.classes.get(m.constructor);x===void 0&&this.classes.set(m.constructor,x=this.classes.size),a[o++]=x,a[o++]=m.enabled?1:0,m.params&&(o=m.params(a,o))}const r=(n=(s=this.keys)[o])!=null?n:s[o]=new Float64Array(o);for(let b=0;b<o;b++)r[b]=a[b];const h=ke(r);let l=this.plans.get(r,h);l||this.plans.set(r,l=this.plan(e),h);for(let b=0;b<l.svgs.length;b++){const m=l.svgs[b];m.used<0&&this.attach(m),m.used=this.t}i.skipped+=l.skip;let c=t;const f=i.rx0,u=i.ry0,y=i.rx1-f,d=i.ry1-u;for(let b=0;b<l.paints.length;b++)l.parts[b]&&(c=this.bake(c,l.parts[b])),e[l.paints[b]].paint2d(c.getContext("2d"),f,u,y,d);return this.css=l.parts[l.paints.length]||"none",c}tick(){const t=++this.t;if(!(t%Ra||!this.live.size))for(const e of this.live)t-e.used>Ra&&this.detach(e)}destroy(){for(const t of this.live)this.detach(t);this.plans.clear()}svg(t){if(typeof document=="undefined"||!document.body)return null;const e=Array.from({length:20},(n,i)=>{var a;return(a=t[i])!=null?a:0}).join(" ");let s=this.svgs.get(e);if(!s){const n="http://www.w3.org/2000/svg",i=document.createElementNS(n,"svg");i.setAttribute("width","0"),i.setAttribute("height","0"),i.setAttribute("aria-hidden","true"),i.style.position="absolute";const a=document.createElementNS(n,"filter"),o=Cl+ ++Tl;a.setAttribute("id",o),a.setAttribute("color-interpolation-filters","sRGB");const r=document.createElementNS(n,"feColorMatrix");r.setAttribute("type","matrix"),r.setAttribute("values",e),a.append(r),i.append(a),this.attach(s={key:e,id:o,el:i,used:this.t})}return this.cur.svgs.push(s),"url(#".concat(s.id,")")}attach(t){document.body.append(t.el),this.live.add(t),this.svgs.has(t.key)||this.svgs.set(t.key,t)}detach(t){t.el.remove(),t.used=-1,this.live.delete(t),this.svgs.get(t.key)===t&&this.svgs.delete(t.key)}plan(t){const e=this.r,s=this.cur={parts:[],paints:[],skip:0,svgs:[]};let n="";for(let i=0;i<t.length;i++){const a=t[i];if(!a.enabled)continue;if(a.kind===kn){s.skip++,Pa("shader","[engine] shader() filters are WebGL only: on Canvas 2D they are skipped (check engine.supports.shaders)");continue}const o=e.support.filters&&a.css?a.css(e.scale,e.maxBlur,this.svgFn):null;o!==null?n+=n?" ".concat(o):o:a.paint2d?(s.parts.push(n),s.paints.push(i),n=""):(s.skip++,Pa("css","[engine] this browser's Canvas 2D has no ctx.filter: colour filters, blur and shadows are skipped (tint works; check engine.supports.filters)"))}return s.parts.push(n),s}bake(t,e){const s=this.r,n=this.flip^=1;let i=this.scr[n];(!i||i.width!==s.canvas.width||i.height!==s.canvas.height)&&(i=this.scr[n]=document.createElement("canvas"),i.width=s.canvas.width,i.height=s.canvas.height);const a=i.getContext("2d"),o=s.rx0,r=s.ry0,h=s.rx1-o,l=s.ry1-r;return a.clearRect(o,r,h,l),a.filter=e,a.drawImage(t,o,r,h,l,o,r,h,l),a.filter="none",i}},Pl=64,$s=17,Ll=t=>"".concat(Dn,"\nuniform sampler2D uTexture;\nuniform mat4 uM[").concat(t,"];\nuniform vec4 uO[").concat(t,"];\nuniform int uK;\nvarying vec2 vUv;\nvarying vec4 vColor;\nvoid main() {\n vec4 c = texture2D(uTexture, vUv);\n if (c.a > 0.0) c.rgb /= c.a;\n for (int i = 0; i < ").concat(t,"; i++) {\n if (i >= uK) break;\n c = clamp(uM[i] * c + uO[i], 0.0, 1.0);\n }\n c.rgb *= c.a;\n gl_FragColor = c * vColor;\n}"),Nl=()=>"".concat(Dn,"\nuniform sampler2D uTexture;\nuniform vec2 uDir;\nuniform vec2 uOff;\nuniform vec2 uTaps[").concat($s,"];\nuniform int uN;\nuniform float uMode;\nuniform vec4 uShadow;\nvarying vec2 vUv;\nvarying vec4 vColor;\nvoid main() {\n vec2 p = vUv + uOff;\n vec4 c = texture2D(uTexture, p) * uTaps[0].y;\n for (int i = 1; i < ").concat($s,"; i++) {\n if (i >= uN) break;\n vec2 d = uDir * uTaps[i].x;\n c += (texture2D(uTexture, p + d) + texture2D(uTexture, p - d)) * uTaps[i].y;\n }\n if (uMode > 0.5) c = uShadow * c.a;\n gl_FragColor = c * vColor;\n}");function Il(t,e,s=new Float32Array(20)){for(let n=0;n<4;n++)for(let i=0;i<5;i++){let a=i===4?e[n*5+4]:0;for(let o=0;o<4;o++)a+=e[n*5+o]*t[o*5+i];s[n*5+i]=a}return t.set(s),t}var Ol=t=>new zl(t),zl=class{constructor(t){p(this,"r",t),p(this,"colorProg",null),p(this,"blurProg",null),p(this,"user",new Map),p(this,"uses",0),p(this,"userErr",new Map),p(this,"scratchT",new Map),p(this,"steps",[]),p(this,"mats",[]),p(this,"counts",[]),p(this,"colorN"),p(this,"fm",new Float32Array(20)),p(this,"fm2",new Float32Array(20)),p(this,"fm3",new Float32Array(20)),p(this,"m16"),p(this,"o4"),p(this,"taps",new Float32Array($s*2));const e=t.gl;this.colorN=Math.max(1,Math.min(8,Math.floor((e.getParameter(e.MAX_FRAGMENT_UNIFORM_VECTORS)-4)/5))),this.m16=new Float32Array(16*this.colorN),this.o4=new Float32Array(4*this.colorN)}check(t){var e;return this.r.lost?null:(this.userProg(t,!1),(e=this.userErr.get(t))!=null?e:null)}destroy(){const t=this.r.gl;for(const e of this.scratchT.values())t.deleteTexture(e.gl),t.deleteFramebuffer(e.fb);this.scratchT.clear();for(const e of[this.colorProg,this.blurProg])e&&t.deleteProgram(e.p);for(const e of this.user.values())e.p&&t.deleteProgram(e.p.p);this.user.clear()}userProg(t,e){const s=this.user,n=s.get(t);if(n)return n.t=++this.uses,n.p;if(this.r.lost)return null;if(s.size>=Pl){let a="",o=1/0;for(const[h,l]of s)l.t<o&&(o=l.t,a=h);const r=s.get(a).p;r&&this.r.gl.deleteProgram(r.p),s.delete(a),this.userErr.delete(a)}let i;try{i=this.r.build(t)}catch(a){i=null;const o=a.message;this.userErr.set(t,o),e&&console.error("[engine] a shader filter does not compile: it is skipped.\n".concat(o))}return s.set(t,{p:i,t:++this.uses}),i}scratch(t,e){var s;const n=this.r,i=Math.ceil(n.canvas.width/t),a=Math.ceil(n.canvas.height/t),o=t*8+e;let r=(s=this.scratchT.get(o))!=null?s:null;return r&&(r.w!==i||r.h!==a)&&(n.drop(r),r=null),r||(r=n.target(i,a,t,!0),r?this.scratchT.set(o,r):this.scratchT.delete(o)),r}pass(t,e,s,n,i=!1){const a=this.r,o=a.gl;a.flush(),a.mapped=!1,a.bindFb(n),o.viewport(0,0,n.w,n.h),i||(o.disable(o.SCISSOR_TEST),o.clearColor(0,0,0,0),o.clear(o.COLOR_BUFFER_BIT)),a.use(t);const r=n.f;o.uniform2f(t.uScale,2/(r*n.w),-2/(r*n.h));const h=Math.floor(a.rx0/r)*r,l=Math.floor(a.ry0/r)*r,c=Math.min(Math.ceil(a.rx1/r),n.w)*r,f=Math.min(Math.ceil(a.ry1/r),n.h)*r,u=1/(s*e.width),y=1/(s*e.height);a.bScis=!1,a.batch.push(h,l,c,l,c,f,h,f,h*u,1-l*y,c*u,1-f*y,4294967295,a.slotOf(e)),a.flush()}post(t){var e,s;return t==="color"?(e=this.colorProg)!=null?e:this.colorProg=this.r.build(Ll(this.colorN)):(s=this.blurProg)!=null?s:this.blurProg=this.r.build(Nl())}linear(t,e){var s;const n=this.r,i=n.gl;n.bindTex((s=n.layerTex.get(t))!=null?s:null,0);const a=e?i.LINEAR:i.NEAREST;i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,a),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,a)}chain(t,e,s){const n=this.r,i=this.steps,a=n.scale,o=n.maxBlur;let r=0;for(let f=0;f<s.length;f++){const u=s[f];if(u.enabled)if(u.kind===bn&&u.toMatrix){(!r||i[r-1]!==null)&&(i[r]=null,(!this.mats[r]||this.mats[r].length<20*this.colorN)&&(this.mats[r]=new Float32Array(20*this.colorN)),this.counts[r]=0,r++);const y=this.mats[r-1],d=this.counts[r-1];if(d<this.colorN)u.toMatrix(this.fm),y.set(this.fm,d*20),this.counts[r-1]=d+1;else{const b=(d-1)*20;for(let m=0;m<20;m++)this.fm2[m]=y[b+m];u.toMatrix(this.fm),Il(this.fm2,this.fm,this.fm3),y.set(this.fm2,b)}}else u.kind===kn?this.userProg(u.source,!0)?i[r++]=u:n.skipped++:u.kind===gn?Math.min(u.radius,o)*a>=.25&&(i[r++]=u):u.kind===vn?i[r++]=u:n.skipped++}if(!r)return!1;const h=n.gl;let l=t,c=-1;for(let f=0;f<r;f++){const u=f===r-1,y=c===0?1:0,d=u?null:this.scratch(1,y);if(!u&&!d)break;const b=i[f];if(b===null){const m=this.post("color");n.use(m);const x=this.mats[f],g=this.counts[f],v=this.m16,_=this.o4;for(let T=0;T<g;T++)for(let N=0;N<4;N++){for(let R=0;R<4;R++)v[T*16+R*4+N]=x[T*20+N*5+R];_[T*4+N]=x[T*20+N*5+4]}h.uniformMatrix4fv(n.u(m,"uM"),!1,v),h.uniform4fv(n.u(m,"uO"),_),h.uniform1i(n.u(m,"uK"),g),d?this.pass(m,l,1,d):n.final(m,l,1,e)}else if(b.kind===gn)this.blur(l,c<0,Math.min(b.radius,o)*a,d,e,null);else if(b.kind===vn){const m=b,x=this.scratch(1,2);if(!x)break;this.blur(l,c<0,Math.max(Math.min(m.blur,o),0)*a,x,1,m);const g=d!=null?d:e<1?this.scratch(1,y):null;g?(this.pass(n.main,x.tex,1,g),this.pass(n.main,l,1,g,!0),d||n.final(n.main,g.tex,1,e)):(n.final(n.main,x.tex,1,1),n.final(n.main,l,1,1))}else{const m=b,x=this.userProg(m.source,!0);n.use(x);const g=n.canvas.width,v=n.canvas.height;h.uniform2f(n.u(x,"uResolution"),g,v),h.uniform1f(n.u(x,"uTime"),n.time),h.uniform4f(n.u(x,"uRect"),n.rx0/g,1-n.ry1/v,n.rx1/g,1-n.ry0/v);const _=m.uniforms;for(const T in _){const N=n.u(x,T);if(!N)continue;const R=_[T];typeof R=="number"?h.uniform1f(N,R):R.length===2?h.uniform2fv(N,R):R.length===3?h.uniform3fv(N,R):R.length===4?h.uniform4fv(N,R):R.length===1&&h.uniform1fv(N,R)}d?this.pass(x,l,1,d):n.final(x,l,1,e)}d&&(l=d.tex,c=y)}return n.remap(),!0}blur(t,e,s,n,i,a){const o=this.r,r=o.gl,h=this.post("blur");let l=1;for(;l<16&&s/l>8;)l*=2;e&&this.linear(t,!0);let c=t,f=1;const u=Math.sqrt(Math.max(s*s-(l*l-1)/12,0))/l,y=s>=.25?this.tapsFor(u):this.tapsFor(0);let d=!0;if(y>1){for(let m=2;m<=l&&d;m*=2){const x=this.scratch(m,0);x?(this.pass(o.main,c,f,x),c=x.tex,f=m):d=!1}const b=d?this.scratch(l,3):null;b&&(o.use(h),r.uniform2fv(o.u(h,"uTaps"),this.taps),r.uniform1i(o.u(h,"uN"),y),r.uniform2f(o.u(h,"uDir"),1/c.width,0),r.uniform2f(o.u(h,"uOff"),0,0),r.uniform1f(o.u(h,"uMode"),0),this.pass(h,c,f,b),c=b.tex)}if(o.use(h),r.uniform2fv(o.u(h,"uTaps"),this.taps),r.uniform1i(o.u(h,"uN"),y),r.uniform2f(o.u(h,"uDir"),0,1/c.height),a){const b=a.opacity,m=a.rgb;r.uniform4f(o.u(h,"uShadow"),(m>>16&255)/255*b,(m>>8&255)/255*b,(m&255)/255*b,b),r.uniform1f(o.u(h,"uMode"),1),r.uniform2f(o.u(h,"uOff"),-a.dx*o.scale/(f*c.width),a.dy*o.scale/(f*c.height))}else r.uniform1f(o.u(h,"uMode"),0),r.uniform2f(o.u(h,"uOff"),0,0);n?this.pass(h,c,f,n):o.final(h,c,f,i),e&&this.linear(t,!1)}tapsFor(t){const e=this.taps;if(e.fill(0),e[1]=1,t<.2)return 1;const s=Math.min(Math.ceil(3*t),($s-1)*2),n=-1/(2*t*t);let i=1,a=1;for(let o=1;o<=s;o+=2){const r=Math.exp(o*o*n),h=o+1<=s?Math.exp((o+1)*(o+1)*n):0,l=r+h;e[a*2]=(o*r+(o+1)*h)/l,e[a*2+1]=l,i+=2*l,a++}for(let o=0;o<a;o++)e[o*2+1]=e[o*2+1]/i;return a}},de=t=>Math.min(Math.max(t,0),1),ee=t=>Math.max(t,0),ks=class{constructor(){p(this,"enabled",!0),ie.gl=Ol,ie.c2d=Rl}},Ee=class extends ks{constructor(t){super(),p(this,"amount",t),p(this,"kind",bn)}params(t,e){return t[e]=this.amount,e+1}};function tn(t,e,s){t.fill(0),t[0]=t[6]=t[12]=e,t[4]=t[9]=t[14]=s,t[18]=1}function en(t,e){t.fill(0);for(let s=0;s<3;s++)for(let n=0;n<3;n++)t[s*5+n]=e[s*3+n];t[18]=1}var Q=new Float64Array(9),Dl=class extends Ee{toMatrix(t){tn(t,ee(this.amount),0)}css(){return"brightness(".concat(ee(this.amount),")")}},Bl=class extends Ee{toMatrix(t){const e=ee(this.amount);tn(t,e,.5-.5*e)}css(){return"contrast(".concat(ee(this.amount),")")}},Ul=class extends Ee{toMatrix(t){const e=de(this.amount);tn(t,1-2*e,e)}css(){return"invert(".concat(de(this.amount),")")}},Hl=class extends Ee{toMatrix(t){const e=ee(this.amount);Q[0]=.213+.787*e,Q[1]=.715-.715*e,Q[2]=.072-.072*e,Q[3]=.213-.213*e,Q[4]=.715+.285*e,Q[5]=.072-.072*e,Q[6]=.213-.213*e,Q[7]=.715-.715*e,Q[8]=.072+.928*e,en(t,Q)}css(){return"saturate(".concat(ee(this.amount),")")}},Gl=class extends Ee{toMatrix(t){const e=1-de(this.amount);Q[0]=.2126+.7874*e,Q[1]=.7152-.7152*e,Q[2]=.0722-.0722*e,Q[3]=.2126-.2126*e,Q[4]=.7152+.2848*e,Q[5]=.0722-.0722*e,Q[6]=.2126-.2126*e,Q[7]=.7152-.7152*e,Q[8]=.0722+.9278*e,en(t,Q)}css(){return"grayscale(".concat(de(this.amount),")")}},Xl=class extends Ee{toMatrix(t){const e=1-de(this.amount);Q[0]=.393+.607*e,Q[1]=.769-.769*e,Q[2]=.189-.189*e,Q[3]=.349-.349*e,Q[4]=.686+.314*e,Q[5]=.168-.168*e,Q[6]=.272-.272*e,Q[7]=.534-.534*e,Q[8]=.131+.869*e,en(t,Q)}css(){return"sepia(".concat(de(this.amount),")")}},ql=class extends Ee{get angle(){return this.amount}set angle(t){this.amount=t}toMatrix(t){const e=this.amount*Math.PI/180,s=Math.cos(e),n=Math.sin(e);Q[0]=.213+s*.787-n*.213,Q[1]=.715-s*.715-n*.715,Q[2]=.072-s*.072+n*.928,Q[3]=.213-s*.213+n*.143,Q[4]=.715+s*.285+n*.14,Q[5]=.072-s*.072-n*.283,Q[6]=.213-s*.213-n*.787,Q[7]=.715-s*.715+n*.715,Q[8]=.072+s*.928+n*.072,en(t,Q)}css(){return"hue-rotate(".concat(this.amount,"deg)")}},Wl=class extends Ee{constructor(t,e){super(e),p(this,"c",16777215),p(this,"cs",""),this.color=t}get color(){return this.c}set color(t){this.c=ne(t)[0],this.cs=hs(this.c)}params(t,e){return t[e]=this.amount,t[e+1]=this.c,e+2}toMatrix(t){const e=de(this.amount);tn(t,1-e,0),t[4]=(this.c>>16&255)/255*e,t[9]=(this.c>>8&255)/255*e,t[14]=(this.c&255)/255*e}css(){return null}paint2d(t,e,s,n,i){const a=de(this.amount);a<=0||(t.save(),t.setTransform(1,0,0,1,0,0),t.globalAlpha=a,t.globalCompositeOperation="source-atop",t.fillStyle=this.cs,t.fillRect(e,s,n,i),t.restore())}},jl=class extends ks{constructor(t){if(super(),p(this,"kind",bn),p(this,"values"),t.length!==20)throw new Error("colorMatrix: 20 numbers expected (4 rows of 5), got ".concat(t.length));this.values=Array.from(t)}toMatrix(t){var e;for(let s=0;s<20;s++)t[s]=(e=this.values[s])!=null?e:0}params(t,e){var s;for(let n=0;n<20;n++)t[e+n]=(s=this.values[n])!=null?s:0;return e+20}css(t,e,s){return s?s(this.values):null}},Yl=class extends ks{constructor(t){super(),p(this,"radius",t),p(this,"kind",gn)}params(t,e){return t[e]=this.radius,e+1}pad(t){return 3*Math.min(ee(this.radius),t)}css(t,e){return"blur(".concat(Math.min(ee(this.radius),e)*t,"px)")}},Ql=class extends ks{constructor(t,e,s,n){super(),p(this,"dx",t),p(this,"dy",e),p(this,"blur",s),p(this,"kind",vn),p(this,"rgb",0),p(this,"a",1),this.color=n}get opacity(){return this.a}set opacity(t){this.a=de(t)}get color(){return this.rgb}set color(t){const[e,s]=ne(t);this.rgb=e,this.a=s}params(t,e){return t[e]=this.dx,t[e+1]=this.dy,t[e+2]=this.blur,t[e+3]=this.rgb,t[e+4]=this.a,e+5}pad(t){return 3*Math.min(ee(this.blur),t)+Math.max(Math.abs(this.dx),Math.abs(this.dy))}css(t,e){return"drop-shadow(".concat(this.dx*t,"px ").concat(this.dy*t,"px ").concat(2*Math.min(ee(this.blur),e)*t,"px ").concat(hs(this.rgb,this.opacity),")")}},Vl="#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\nuniform sampler2D uTexture;\nuniform vec2 uResolution;\nuniform float uTime;\nuniform vec4 uRect;\nvarying vec2 vUv;\nvarying vec4 vColor;\n#define main fabiUserMain\n#line 1\n",Kl=t=>"".concat(Vl).concat(t,"\n#undef main\nvoid main() {\n fabiUserMain();\n gl_FragColor *= vColor.a;\n}\n"),Zl=class extends ks{constructor(t){var e,s;super(),p(this,"kind",kn),p(this,"source"),p(this,"uniforms",{}),p(this,"padding"),this.source=Kl(t.fragment),this.padding=(e=t.padding)!=null?e:0;for(const n in(s=t.uniforms)!=null?s:{}){const i=t.uniforms[n];this.uniforms[n]=typeof i=="number"?i:Float32Array.from(i)}}pad(){return ee(this.padding)}},Jl=(t,e=1)=>new Wl(t,e),$l=t=>new Dl(t),tc=t=>new Bl(t),ec=t=>new Hl(t),sc=(t=1)=>new Gl(t),nc=(t=1)=>new Xl(t),ic=t=>new ql(t),ac=(t=1)=>new Ul(t),rc=t=>new jl(t),oc=t=>new Yl(t),lc=(t,e,s,n="rgba(0,0,0,0.5)")=>new Ql(t,e,s,n);function cc(t){var e,s;const n=new Zl(t),i=(s=(e=ie.live)==null?void 0:e.filters())==null?void 0:s.check(n.source);if(i)throw new Error("shader(): the fragment does not compile:\n".concat(i));return n}var Yn="x y rotation scaleX scaleY alpha visible blend tint z hitRadius clip mask filters".split(" "),La="frameName _frame _w _h slice autoAnchor".split(" "),hc="fps loop speed onComplete durations".split(" "),Qn=["anchorX","anchorY"],fc=[...Yn,...La,...hc,...Qn],uc=[...Yn,...La,...Qn],dc=[...Yn,...Qn],Na=t=>t instanceof Oe?fc:t instanceof Ke?uc:dc;function pc(t){const e={},s=t;for(const n of Na(t))e[n]=s[n];return t instanceof ys&&(e.spec=t.spec),t instanceof vs&&(e.text=t.text,e.style=t.style),t instanceof Oe&&(e.playing=t.playing),e}function Ia(t,e){const s=t;t instanceof ys&&t.spec!==e.spec&&(t.spec=e.spec),t instanceof vs&&(t.text=e.text,t.style!==e.style&&(s._style=e.style,s.dirty=!0)),t instanceof Oe&&t.gotoFrame(e.speed<0?t.frameCount-1:0);const n=t instanceof ys||t instanceof vs,i=Na(t);for(let a=0;a<i.length;a++){const o=i[a];(!n||o!=="_frame"&&o!=="frameName")&&(s[o]=e[o])}}var Oa=class{constructor(t,e={}){p(this,"factory",t),p(this,"opts",e),p(this,"stats",{live:0,free:0,created:0}),p(this,"free",[]),p(this,"states",new Map),p(this,"dead",!1)}get(t){if(this.dead)throw new Error("[engine] nodePool.get() after destroy()");let e=this.free.pop();if(e){this.stats.free--,e._free=!1;const s=this.states.get(e);Ia(e,s),e.visible=s.visible,e instanceof Oe&&s.playing&&e.play()}else{if(e=this.factory(),!(e instanceof Ne))throw new Error("[engine] a nodePool factory must return a node (engine.sprite, engine.shape, \u2026)");if(e._pool)throw new Error("[engine] a nodePool factory returned a node of another pool: make a new node in it");this.states.set(e,pc(e)),e._pool=this,this.stats.created++}return this.stats.live++,t&&e.set(t),e}release(t){var e,s,n;const i=this.states.get(t);if(!(!i||t.destroyed)&&!t._free){if(this.opts.max!==void 0&&this.free.length>=this.opts.max)return t.destroy();(e=t.parent)==null||e.remove(t),t.kernel.tweens.stopAll(t),this.stats.live--,Ia(t,i),t instanceof Oe&&t.stop(),t.visible=!1,t._free=!0,(n=(s=this.opts).reset)==null||n.call(s,t),this.free.push(t),this.stats.free++}}forget(t){const e=t;if(this.states.delete(e))if(e._free){const s=this.free.indexOf(e);s>=0&&(this.free[s]=this.free[this.free.length-1],this.free.pop()),this.stats.free--}else this.stats.live--}clear(){for(;this.free.length;)this.free[this.free.length-1].destroy()}destroy(){this.dead=!0;for(const t of[...this.states.keys()])t.destroy()}},yc=(t,e)=>new Oa(t,e);return Re.exports});
|